Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
mcnuttandrew committed Jan 12, 2024
1 parent d0013f7 commit 23d12ee
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 4 additions & 16 deletions src/lib/Color.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,32 +81,20 @@ 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, "")
.replace(/,/g, " ")
.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 {
Expand Down

0 comments on commit 23d12ee

Please sign in to comment.