diff options
author | bobzel <zzzman@gmail.com> | 2021-09-24 01:21:38 -0400 |
---|---|---|
committer | bobzel <zzzman@gmail.com> | 2021-09-24 01:21:38 -0400 |
commit | 643df77e6366b7164307ffe195ed9de83b68e5ae (patch) | |
tree | edf5ce846fbbdb84ccd015b18b07314cb24c76b8 /src/Utils.ts | |
parent | 815899626d82972ae56918487ee3ece11446d5a6 (diff) |
wrapped Color() calls in DashColor() to catch exceptions for color strings no found
Diffstat (limited to 'src/Utils.ts')
-rw-r--r-- | src/Utils.ts | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/Utils.ts b/src/Utils.ts index db33875ea..7ec4f69f3 100644 --- a/src/Utils.ts +++ b/src/Utils.ts @@ -573,10 +573,19 @@ export function simulateMouseClick(element: Element | null | undefined, x: numbe } } +export function DashColor(color: string) { + try { + return Color(color.toLowerCase()); + } catch (e) { + console.log("COLOR error:", e); + return Color("red"); + } +} + export function lightOrDark(color: any) { const nonAlphaColor = color.startsWith("#") ? (color as string).substring(0, 7) : color.startsWith("rgba") ? color.replace(/,.[^,]*\)/, ")").replace("rgba", "rgb") : color; - const col = Color(nonAlphaColor.toLowerCase()).rgb(); + const col = DashColor(nonAlphaColor).rgb(); const colsum = (col.red() + col.green() + col.blue()); if (colsum / col.alpha() > 400 || col.alpha() < 0.25) return Colors.DARK_GRAY; else return Colors.WHITE; |