From 57ad5c468ae4a53197880b650d664a2820805cf0 Mon Sep 17 00:00:00 2001 From: Andrew Michael McNutt Date: Sun, 10 Mar 2024 20:56:16 -0700 Subject: [PATCH] all the type errors cleared, bugs --- src/components/ColorChannelPicker.svelte | 2 -- src/components/KeyboardHooks.svelte | 32 +++++++++++++------ src/components/MiniPalPreview.svelte | 2 +- src/components/PalDiff.svelte | 6 ++-- src/components/PalPreview.svelte | 11 ++++--- src/content-modules/ComparePal.svelte | 2 +- src/content-modules/Controls.svelte | 15 ++++++--- src/controls/AddColor.svelte | 10 ++++-- src/controls/AdjustColor.svelte | 7 ++-- src/controls/AlignSelection.svelte | 9 ++++-- src/controls/ColorTagger.svelte | 28 ++++++++-------- src/controls/Config.svelte | 2 +- src/controls/DistributePoints.svelte | 14 ++++---- src/controls/InterpolatePoints.svelte | 13 +++++--- src/controls/NewPal.svelte | 14 +++++--- src/controls/Rotate.svelte | 10 +++--- src/controls/Sort.svelte | 4 +-- src/controls/SuggestColorPal.svelte | 8 ++--- .../SuggestionModificationToSelection.svelte | 19 +++++++---- src/example/Example.svelte | 11 +++++-- src/example/Swatches.svelte | 26 +++++++++------ src/lib/CustomLint.ts | 4 +-- src/lib/api-calls.ts | 4 +-- src/lib/lint-language/lint-language.ts | 2 +- src/lib/linter-tools/lint-fixer.ts | 7 ++-- src/lib/lints/background-contrast.ts | 15 +++++---- src/lib/lints/diverging-order.ts | 16 ++++++---- src/lib/lints/in-gamut.ts | 7 ++-- src/lib/lints/name-discrim.ts | 6 ++-- src/lib/lints/sequential-order.ts | 2 +- src/lib/utils.ts | 8 +++-- src/linting/EvalColorColumn.svelte | 19 ++++++----- src/linting/ExplanationViewer.svelte | 2 +- src/linting/LintCustomizationPreview.svelte | 25 +++++++++------ .../ColorScatterPlotPolarGuide.svelte | 4 +-- .../ColorScatterPlotXYGuides.svelte | 2 +- src/stores/lint-store.ts | 15 +++++++-- 37 files changed, 237 insertions(+), 146 deletions(-) diff --git a/src/components/ColorChannelPicker.svelte b/src/components/ColorChannelPicker.svelte index b0809b52..f2fddb1a 100644 --- a/src/components/ColorChannelPicker.svelte +++ b/src/components/ColorChannelPicker.svelte @@ -1,6 +1,4 @@ @@ -30,20 +31,20 @@ class:w-8={highlightSelected && focusSet.has(idx)} class:h-8={highlightSelected && focusSet.has(idx)} class:mb-5={highlightSelected && !focusSet.has(idx)} - style="background-color: {color.toDisplay()}" + style="background-color: {color.color.toDisplay()}" > {:else}
{/if} {#if showTags} -
- {#each pal.colorSemantics[idx].tags as tag} - {tag} +
+ {#each color.tags as tag, idx} +
{tag}
{/each}
{/if} diff --git a/src/content-modules/ComparePal.svelte b/src/content-modules/ComparePal.svelte index 17b7e845..654e2fac 100644 --- a/src/content-modules/ComparePal.svelte +++ b/src/content-modules/ComparePal.svelte @@ -84,7 +84,7 @@ startDragging={() => {}} stopDragging={() => {}} blindColors={(showDiff - ? currentPal.colors.map((x) => x.toColorSpace(colorSpace)) + ? currentPal.colors.map((x) => x.color.toColorSpace(colorSpace)) : [] ).slice( 0, diff --git a/src/content-modules/Controls.svelte b/src/content-modules/Controls.svelte index 6b74b830..c2949e69 100644 --- a/src/content-modules/Controls.svelte +++ b/src/content-modules/Controls.svelte @@ -29,18 +29,22 @@
{ const updatedColors = [...colors]; - updatedColors[focusedColors[0]] = Color.colorFromString( + const newColor = Color.colorFromString( e.currentTarget.value, colorSpace ); + updatedColors[focusedColors[0]] = { + ...updatedColors[focusedColors[0]], + color: newColor, + }; colorStore.setCurrentPalColors(updatedColors); }} /> { // @ts-ignore @@ -48,7 +52,10 @@ }} onColorChange={(color) => { const updatedColors = [...colors]; - updatedColors[focusedColors[0]] = color.toColorSpace(colorSpace); + updatedColors[focusedColors[0]] = { + ...updatedColors[focusedColors[0]], + color: color.toColorSpace(colorSpace), + }; colorStore.setCurrentPalColors(updatedColors); }} /> diff --git a/src/controls/AddColor.svelte b/src/controls/AddColor.svelte index 5a747f88..ff7514ca 100644 --- a/src/controls/AddColor.svelte +++ b/src/controls/AddColor.svelte @@ -5,7 +5,7 @@ import { suggestAdditionsToPalette } from "../lib/api-calls"; import ColorButton from "../components/ColorButton.svelte"; import AutocompleteOrSearch from "../components/AutocompleteOrSearch.svelte"; - import { webColors } from "../lib/utils"; + import { webColors, wrapInBlankSemantics } from "../lib/utils"; $: currentPal = $colorStore.palettes[$colorStore.currentPal]; $: colors = currentPal.colors; @@ -51,7 +51,9 @@ { console.log("x", x); - const newColor = Color.colorFromString(x, colorSpace); + const newColor = wrapInBlankSemantics( + Color.colorFromString(x, colorSpace) + ); const newColors = [...colors, newColor]; colorStore.setCurrentPalColors(newColors); }} @@ -77,7 +79,9 @@ { - const newColor = Color.colorFromString(color, colorSpace); + const newColor = wrapInBlankSemantics( + Color.colorFromString(color, colorSpace) + ); const newColors = [...colors, newColor]; colorStore.setCurrentPalColors(newColors); interpretations = interpretations.filter((x) => x !== color); diff --git a/src/controls/AdjustColor.svelte b/src/controls/AdjustColor.svelte index 6ab702de..859900cc 100644 --- a/src/controls/AdjustColor.svelte +++ b/src/controls/AdjustColor.svelte @@ -15,8 +15,11 @@ function actionOnColor(focusedColors: number[], action: ColorEffect) { const newColors = [...colors]; focusedColors.forEach((idx) => { - const channels = action(colors[idx]); - newColors[idx] = Color.colorFromChannels(channels, colorSpace); + const channels = action(colors[idx].color); + newColors[idx] = { + ...colors[idx], + color: Color.colorFromChannels(channels, colorSpace), + }; }); colorStore.setCurrentPalColors(newColors); } diff --git a/src/controls/AlignSelection.svelte b/src/controls/AlignSelection.svelte index d802d67f..7dc688c9 100644 --- a/src/controls/AlignSelection.svelte +++ b/src/controls/AlignSelection.svelte @@ -60,12 +60,12 @@ on:click={() => { const newCoordinate = op( ...colors - .map((x) => x.toChannels()) + .map((x) => x.color.toChannels()) .filter((_, idx) => focusSet.has(idx)) .map((x) => x[pos]) ); const newColors = colors - .map((x) => x.toChannels()) + .map((x) => x.color.toChannels()) .map((x, idx) => { let y = x; if (focusSet.has(idx)) { @@ -73,7 +73,10 @@ } return y; }) - .map((x) => Color.colorFromChannels(x, colorSpace)); + .map((x, idx) => ({ + ...colors[idx], + color: Color.colorFromChannels(x, colorSpace), + })); colorStore.setCurrentPalColors(newColors); }} diff --git a/src/controls/ColorTagger.svelte b/src/controls/ColorTagger.svelte index eefc0d3b..724dac26 100644 --- a/src/controls/ColorTagger.svelte +++ b/src/controls/ColorTagger.svelte @@ -7,20 +7,20 @@ $: currentPalette = $colorStore.palettes[$colorStore.currentPal]; // guaranteed to be a single value by usage context $: focusedColorIdx = $focusStore.focusedColors[0]; - $: semantics = currentPalette.colorSemantics[focusedColorIdx]; + $: currentColor = currentPalette.colors[focusedColorIdx]; - const updateTags = (updatedTags: string[]) => - updateSemantics({ ...semantics, tags: updatedTags }); - const updateSize = (size: (typeof sizes)[number]) => - updateSemantics({ ...semantics, size }); + // const updateTags = (updatedTags: string[]) => + // updateSemantics({ ...semantics, tags: updatedTags }); + // const updateSize = (size: (typeof sizes)[number]) => + // updateSemantics({ ...semantics, size }); - const updateMarkType = (markType: (typeof markTypes)[number]) => - updateSemantics({ ...semantics, markType }); - function updateSemantics(updatedSemantics: typeof semantics) { - const newSemantics = [...currentPalette.colorSemantics]; - newSemantics[focusedColorIdx] = updatedSemantics; - colorStore.updateColorSemantics(newSemantics); - } + // const updateMarkType = (markType: (typeof markTypes)[number]) => + // updateSemantics({ ...semantics, markType }); + // function updateSemantics(updatedSemantics: typeof semantics) { + // const newSemantics = [...currentPalette.colorSemantics]; + // newSemantics[focusedColorIdx] = updatedSemantics; + // colorStore.updateColorSemantics(newSemantics); + // } let tagInput = ""; const sizes = [undefined, "small", "medium", "large"] as const; const markTypes = [ @@ -39,7 +39,7 @@ These to mark properties like color, brand, and so on
-
{ updateTags([...semantics.tags, tagInput]); tagInput = ""; @@ -85,4 +85,4 @@ {#each sizes as option} {/each} - + --> diff --git a/src/controls/Config.svelte b/src/controls/Config.svelte index 05534461..fc105779 100644 --- a/src/controls/Config.svelte +++ b/src/controls/Config.svelte @@ -88,7 +88,7 @@ return { background: background.toHex(), colorSpace, - colors: colors.map((c) => c.toHex()), + colors: colors.map((c) => c.color.toHex()), name, type, }; diff --git a/src/controls/DistributePoints.svelte b/src/controls/DistributePoints.svelte index 47a5bda9..b17a1de6 100644 --- a/src/controls/DistributePoints.svelte +++ b/src/controls/DistributePoints.svelte @@ -19,20 +19,20 @@ let sortedIndexes = focusedColors.sort((a, b) => { const modeToIdx = { horizontal: 1, vertical: 2, "in z space": 0 }; const idx = modeToIdx[dir.direction] || 0; - const pointA = colors[a].toChannels()[idx]; - const pointB = colors[b].toChannels()[idx]; + const pointA = colors[a].color.toChannels()[idx]; + const pointB = colors[b].color.toChannels()[idx]; return pointA - pointB; }); type Channels = [number, number, number]; - const minPoint = colors[sortedIndexes[0]].toChannels() as Channels; + const minPoint = colors[sortedIndexes[0]].color.toChannels() as Channels; const maxPoint = colors[ sortedIndexes[sortedIndexes.length - 1] - ].toChannels() as Channels; + ].color.toChannels() as Channels; const numPoints = sortedIndexes.length - 1; let newPoints = sortedIndexes.map((colorIdx, arrIdx) => { const t = arrIdx / numPoints; - const newPoint = colors.at(colorIdx)!.toChannels() as Channels; + const newPoint = colors.at(colorIdx)!.color.toChannels() as Channels; const xIdx = config.xChannelIndex; const yIdx = config.yChannelIndex; const zIdx = config.zChannelIndex; @@ -51,7 +51,9 @@ const newColors = [...colors].map((color, idx) => { const point = pointsByIndex[idx]; - return point ? Color.colorFromChannels(point, colorSpace) : color; + return point + ? { ...color, color: Color.colorFromChannels(point, colorSpace) } + : color; }); colorStore.setCurrentPalColors(newColors); diff --git a/src/controls/InterpolatePoints.svelte b/src/controls/InterpolatePoints.svelte index 4571a352..252284b7 100644 --- a/src/controls/InterpolatePoints.svelte +++ b/src/controls/InterpolatePoints.svelte @@ -1,10 +1,12 @@
diff --git a/src/example/Swatches.svelte b/src/example/Swatches.svelte index f489f718..1ebdcbc8 100644 --- a/src/example/Swatches.svelte +++ b/src/example/Swatches.svelte @@ -1,4 +1,5 @@