From bb5e321509a25814f4afccf3919e03857c3aec00 Mon Sep 17 00:00:00 2001 From: Andrew McNutt Date: Fri, 12 Jan 2024 10:03:19 -0800 Subject: [PATCH] Rework color storage (#5) * Rework color storage * clean up * . --- README.md | 1 + src/components/KeyboardHooks.svelte | 2 +- src/content-modules/Background.svelte | 2 +- src/content-modules/SetColorSpace.svelte | 13 ++--- .../SwatchTooltipContent.svelte | 2 +- .../context-free-tools/AddFamiliarPal.svelte | 4 +- .../GetColorsFromString.svelte | 2 +- .../context-free-tools/SuggestColorPal.svelte | 3 +- .../contextual-tools/AddColor.svelte | 2 +- .../contextual-tools/AdjustColor.svelte | 2 +- .../contextual-tools/AlignSelection.svelte | 2 +- .../contextual-tools/DistributePoints.svelte | 2 +- .../contextual-tools/Rotate.svelte | 2 +- .../SuggestionModificationToSelection.svelte | 3 +- src/lib/Color.test.ts | 22 +++++++ src/lib/Color.ts | 36 ++++++++---- src/lib/ColorLint.test.ts | 1 + src/lib/lints/background-differentiability.ts | 3 +- src/stores/color-store.ts | 58 ++++++++++++------- 19 files changed, 108 insertions(+), 54 deletions(-) create mode 100644 src/lib/Color.test.ts 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/components/KeyboardHooks.svelte b/src/components/KeyboardHooks.svelte index 709da97d..d8c7c165 100644 --- a/src/components/KeyboardHooks.svelte +++ b/src/components/KeyboardHooks.svelte @@ -4,7 +4,7 @@ import focusStore from "../stores/focus-store"; $: focusedSet = new Set($focusStore.focusedColors); $: copiedData = [] as Color[]; - $: colorSpace = $colorStore.currentPal.colors[0].spaceName; + $: colorSpace = $colorStore.currentPal.colorSpace; $: [_zStep, xStep, yStep] = stepSize[colorSpace]; function onKeyDown(e: any) { if (e.target.tagName.toLowerCase() === "input") { diff --git a/src/content-modules/Background.svelte b/src/content-modules/Background.svelte index f4c0d33b..9c8f7928 100644 --- a/src/content-modules/Background.svelte +++ b/src/content-modules/Background.svelte @@ -5,7 +5,7 @@ import ColorChannelPicker from "../components/ColorChannelPicker.svelte"; import Tooltip from "../components/Tooltip.svelte"; $: bg = $colorStore.currentPal.background; - $: colorSpace = $colorStore.currentPal.colors[0].spaceName || "lab"; + $: colorSpace = $colorStore.currentPal.colorSpace; function onChange(color: Color) { colorStore.setBackground(color); } diff --git a/src/content-modules/SetColorSpace.svelte b/src/content-modules/SetColorSpace.svelte index dac41406..c0f8d0be 100644 --- a/src/content-modules/SetColorSpace.svelte +++ b/src/content-modules/SetColorSpace.svelte @@ -1,7 +1,7 @@ @@ -9,13 +9,10 @@