From 23d12ee268e23e362fce33b4be40e58ff9c42d02 Mon Sep 17 00:00:00 2001 From: Andrew Michael McNutt Date: Fri, 12 Jan 2024 10:02:00 -0800 Subject: [PATCH] . --- README.md | 1 + src/lib/Color.ts | 20 ++++---------------- 2 files changed, 5 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 29390e28..19e5c2a8 100644 --- a/README.md +++ b/README.md @@ -51,6 +51,7 @@ To raise the sliders, you need to click on one of the examples that are displaye ## TODOS +- [ ] Chore: clean up the color store, many unnecessary methods. Extract some common types into a top level location (like types.ts type thing) - [ ] A (default) example showing annotated math stuff - [ ] SVG Upload - [ ] Vega/Vega-Lite Specification diff --git a/src/lib/Color.ts b/src/lib/Color.ts index 7574d52e..0fb2692f 100644 --- a/src/lib/Color.ts +++ b/src/lib/Color.ts @@ -81,10 +81,7 @@ export class Color { } export function stringToChannels(spaceName: string, str: string) { - // const regex = new RegExp( - // `${spaceName}\\((.*?)(%|,)(.*?) (.*?)(%|,) (.*?)\\)\\)` - // ); - let temp = str + let channels = str .replace(`${spaceName}(`, "") .replace(")", "") .replace(/%/g, "") @@ -92,21 +89,12 @@ export function stringToChannels(spaceName: string, str: string) { .trim() .split(" ") .filter((x) => x.length); - const allNumbers = temp.every((x) => !isNaN(+x)); + const allNumbers = channels.every((x) => !isNaN(+x)); - if (!(temp.length === 3 && allNumbers)) { + if (!(channels.length === 3 && allNumbers)) { throw new Error(`Invalid color string: ${str}`); } - return temp.map((x) => Number(x) * 1) as [number, number, number]; - // console.log(temp); - // const regex = new RegExp(/(\-?\d+(?:\.\d+)?%){3}/); - // const match = str.match(regex); - // console.log(str, match, regex); - // if (!match) { - // throw new Error(`Invalid color string: ${str}`); - // } - // const [_, ...channels] = match; - // return channels.map((x) => +x) as [number, number, number]; + return channels.map((x) => Number(x) * 1) as [number, number, number]; } export class CIELAB extends Color {