From f90ce41438a037d2dec855d9dfb32a2ac0a825c0 Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Tue, 10 Dec 2024 20:50:21 +0000 Subject: [PATCH 01/20] Show gamut in sliders --- src/lib/components/colors/Sliders.svelte | 13 ++++++++++- src/lib/utils.ts | 28 +++++++++++++++++++++++- 2 files changed, 39 insertions(+), 2 deletions(-) diff --git a/src/lib/components/colors/Sliders.svelte b/src/lib/components/colors/Sliders.svelte index 25a6810..7e97070 100644 --- a/src/lib/components/colors/Sliders.svelte +++ b/src/lib/components/colors/Sliders.svelte @@ -95,6 +95,7 @@ style={`--stops: ${alphaGradient}`} value={$color.alpha} oninput={(e) => handleInput(e)} + data-channel="alpha" /> @@ -104,7 +105,17 @@ margin: 0; display: block; appearance: none; - background: linear-gradient(to right, var(--stops)); + background: linear-gradient(to right, var(--stops)), + repeating-linear-gradient( + -45deg, + white 0%, + white 1%, + #ffd0d0 1%, + #ffd0d0 2% + ); + &[data-channel='alpha'] { + background: linear-gradient(to right, var(--stops)); + } } [data-group~='sliders'] { diff --git a/src/lib/utils.ts b/src/lib/utils.ts index 148a04a..f2e32a5 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -1,6 +1,7 @@ import { clone, display, + inGamut, type PlainColorObject, serialize, set, @@ -32,9 +33,34 @@ export const sliderGradient = ( steps: 10, space: color.space, hue: 'raw', + maxDeltaE: 10, }); + let wasInGamut = false; + const inGamutSteps: string[] = []; + const stepWidth = 100 / (gradientSteps.length - 1); - return gradientSteps.map((c) => display(c)).join(', '); + if (channel === 'alpha') { + return gradientSteps.map((c) => display(c)).join(', '); + } + + gradientSteps.forEach((step, index) => { + if (inGamut(step, 'p3')) { + if (!wasInGamut) { + inGamutSteps.push(`transparent ${stepWidth * (index + 1)}%`); + } + wasInGamut = true; + inGamutSteps.push(`${display(step)} ${stepWidth * index}%`); + } else { + if (wasInGamut) { + inGamutSteps.push(`transparent ${stepWidth * (index - 1)}%`); + } + inGamutSteps.push(`transparent ${stepWidth * index}%`); + + wasInGamut = false; + } + }); + + return inGamutSteps.join(', '); }; function decodeColor(colorHash: string, format: ColorFormatId) { From 525812e3f1ef804795ca1058ab6bdea17076b1c2 Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Wed, 11 Dec 2024 17:23:00 +0000 Subject: [PATCH 02/20] Fix initial edge bug --- src/lib/utils.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index f2e32a5..f432f6e 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -35,7 +35,7 @@ export const sliderGradient = ( hue: 'raw', maxDeltaE: 10, }); - let wasInGamut = false; + let wasInGamut: boolean; const inGamutSteps: string[] = []; const stepWidth = 100 / (gradientSteps.length - 1); @@ -45,13 +45,13 @@ export const sliderGradient = ( gradientSteps.forEach((step, index) => { if (inGamut(step, 'p3')) { - if (!wasInGamut) { + if (wasInGamut === false) { inGamutSteps.push(`transparent ${stepWidth * (index + 1)}%`); } wasInGamut = true; inGamutSteps.push(`${display(step)} ${stepWidth * index}%`); } else { - if (wasInGamut) { + if (wasInGamut === true) { inGamutSteps.push(`transparent ${stepWidth * (index - 1)}%`); } inGamutSteps.push(`transparent ${stepWidth * index}%`); From 5c83b3252274c7be6e4ba8a3d41f82846caf4e2b Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Wed, 11 Dec 2024 18:57:50 +0000 Subject: [PATCH 03/20] Add gamut selector --- src/lib/components/GamutSelect.svelte | 45 ++++++++++++++++++++++++ src/lib/components/Header.svelte | 2 ++ src/lib/components/SpaceSelect.svelte | 2 +- src/lib/components/colors/Sliders.svelte | 16 +++++++-- src/lib/constants.ts | 8 +++++ src/lib/stores.ts | 4 ++- src/lib/utils.ts | 20 +++++++---- src/sass/initial/_layout.scss | 2 +- 8 files changed, 86 insertions(+), 13 deletions(-) create mode 100644 src/lib/components/GamutSelect.svelte diff --git a/src/lib/components/GamutSelect.svelte b/src/lib/components/GamutSelect.svelte new file mode 100644 index 0000000..86e31e1 --- /dev/null +++ b/src/lib/components/GamutSelect.svelte @@ -0,0 +1,45 @@ + + +
+ + +
+ + diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte index 360fff7..0bb934f 100644 --- a/src/lib/components/Header.svelte +++ b/src/lib/components/Header.svelte @@ -1,4 +1,5 @@ @@ -9,6 +10,7 @@ OddContrast + diff --git a/src/lib/components/Header.svelte b/src/lib/components/Header.svelte index 0bb934f..d4e1515 100644 --- a/src/lib/components/Header.svelte +++ b/src/lib/components/Header.svelte @@ -5,16 +5,27 @@
-

+

OddContrast

- - +
+ + +
diff --git a/src/lib/components/SpaceSelect.svelte b/src/lib/components/SpaceSelect.svelte index c922c5e..def6af7 100644 --- a/src/lib/components/SpaceSelect.svelte +++ b/src/lib/components/SpaceSelect.svelte @@ -23,7 +23,7 @@ }); -
+
- - diff --git a/src/lib/components/colors/Sliders.svelte b/src/lib/components/colors/Sliders.svelte index 0288f9c..fed71eb 100644 --- a/src/lib/components/colors/Sliders.svelte +++ b/src/lib/components/colors/Sliders.svelte @@ -123,6 +123,7 @@ display: block; appearance: none; background: linear-gradient(to right, var(--stops)); + &[data-channel='alpha'] { background: linear-gradient(to right, var(--stops)), url('data:image/svg+xml;utf8,'); diff --git a/src/sass/components/_color-settings.scss b/src/sass/components/_color-settings.scss new file mode 100644 index 0000000..38c1769 --- /dev/null +++ b/src/sass/components/_color-settings.scss @@ -0,0 +1,26 @@ +@use '../config'; + +[data-setting] { + align-items: center; + column-gap: var(--gutter); + display: grid; + grid-template: + 'format-label' auto + 'format-input' auto / 1fr; + justify-content: end; + + @include config.above('sm-page-break') { + --align-label: right; + + grid-template: 'format-label format-input' auto / 1fr auto; + } + + label { + grid-area: format-label; + text-align: var(--align-label, left); + } + + select { + grid-area: format-input; + } +} diff --git a/src/sass/components/_index.scss b/src/sass/components/_index.scss index 33703f5..57f46e5 100644 --- a/src/sass/components/_index.scss +++ b/src/sass/components/_index.scss @@ -1,4 +1,5 @@ // Components Manifest // =================== +@forward 'color-settings'; @forward 'social-nav'; diff --git a/src/sass/initial/_layout.scss b/src/sass/initial/_layout.scss index 3e1020c..b3d2236 100644 --- a/src/sass/initial/_layout.scss +++ b/src/sass/initial/_layout.scss @@ -40,7 +40,7 @@ body { display: grid; gap: var(--shim) var(--double-gutter); grid-area: header; - grid-template: 'logo colorspace gamut' auto / auto 1fr; + grid-template: 'logo settings' auto / auto 1fr; @include config.above('sm-page-break') { gap: var(--double-gutter); diff --git a/src/sass/patterns/_forms.scss b/src/sass/patterns/_forms.scss index 65dacf9..68e2275 100644 --- a/src/sass/patterns/_forms.scss +++ b/src/sass/patterns/_forms.scss @@ -61,6 +61,7 @@ select { } input[type='range'] { + border: var(--border-width) solid var(--border); border-radius: var(--range-input); box-shadow: 1px 1px var(--border-width-md) 0 var(--border-light); height: var(--range-input); From 2854bc97396979193f4dab6a03d2bc92fa38f8bc Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Tue, 4 Feb 2025 09:51:56 -0500 Subject: [PATCH 13/20] Reduce size of gradient chunks --- src/lib/utils.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/utils.ts b/src/lib/utils.ts index d3c2959..a5403b0 100644 --- a/src/lib/utils.ts +++ b/src/lib/utils.ts @@ -48,7 +48,7 @@ export const sliderGradient = ({ hue: 'raw', // Smaller values will take longer, larger will be less precise and // produce fuzzy edges. This magic number seems to balance that. - maxDeltaE: 10, + maxDeltaE: 2, }); let wasInGamut = true; const inGamutSteps: string[] = []; From c9969e9774f1d72bdd56c53983d6cf77476465c1 Mon Sep 17 00:00:00 2001 From: James Stuckey Weber Date: Tue, 4 Feb 2025 12:44:51 -0500 Subject: [PATCH 14/20] Rename selects, add warning class and icon to swatch when out of gamut --- src/lib/components/GamutSelect.svelte | 2 +- src/lib/components/SpaceSelect.svelte | 2 +- src/lib/components/colors/Header.svelte | 15 +++++++++++++-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/lib/components/GamutSelect.svelte b/src/lib/components/GamutSelect.svelte index d5e287b..70f3913 100644 --- a/src/lib/components/GamutSelect.svelte +++ b/src/lib/components/GamutSelect.svelte @@ -4,7 +4,7 @@
- + {#each spaces as space (space.id)} {#if space} diff --git a/src/lib/components/colors/Header.svelte b/src/lib/components/colors/Header.svelte index adb627e..ea9de89 100644 --- a/src/lib/components/colors/Header.svelte +++ b/src/lib/components/colors/Header.svelte @@ -1,11 +1,14 @@