diff options
| author | Craig Jennings <c@cjennings.net> | 2026-06-19 10:19:59 -0400 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2026-06-19 10:19:59 -0400 |
| commit | 2c8ef2798f324528acf9a16845d2ce456e56a5c3 (patch) | |
| tree | 860213d7cd7fec4216dfa6e9d1ae5f82c16fc206 /scripts/theme-studio/palette-generator-core.js | |
| parent | 1b51342aa2fcc698c3486e336364dad0b22900ed (diff) | |
| download | dotemacs-2c8ef2798f324528acf9a16845d2ce456e56a5c3.tar.gz dotemacs-2c8ef2798f324528acf9a16845d2ce456e56a5c3.zip | |
refactor(theme-studio): share oklchOf and isPureEndpointHex from colormath
oklchOf and isPureEndpointHex were each defined identically in app-core.js and palette-generator-core.js, and hueOfHex inlined oklchOf's body a third time. I moved both helpers into colormath.js, which already owns the primitives they call, and had the two consumers import them. hueOfHex now calls oklchOf instead of re-deriving it.
Diffstat (limited to 'scripts/theme-studio/palette-generator-core.js')
| -rw-r--r-- | scripts/theme-studio/palette-generator-core.js | 6 |
1 files changed, 2 insertions, 4 deletions
diff --git a/scripts/theme-studio/palette-generator-core.js b/scripts/theme-studio/palette-generator-core.js index 6bce0d59a..94ed38011 100644 --- a/scripts/theme-studio/palette-generator-core.js +++ b/scripts/theme-studio/palette-generator-core.js @@ -2,11 +2,9 @@ // from app-core.js, but owns candidate hue selection, naming, contrast filtering, // and conversion from preview columns to palette entries. import { normHex } from './app-util.js'; -import { oklch2hex, srgb2oklab, oklab2oklch, contrast, deltaE } from './colormath.js'; +import { oklch2hex, contrast, deltaE, oklchOf, isPureEndpointHex } from './colormath.js'; import { columnsFromPalette } from './app-core.js'; -function oklchOf(hex){return oklab2oklch(srgb2oklab(hex));} -function isPureEndpointHex(hex){const h=(hex||'').toLowerCase();return h==='#ffffff'||h==='#000000';} function generatedExistingNames(palette){ return new Set((palette||[]).map(p=>(p&&p[1]||'').toLowerCase()).filter(Boolean)); } @@ -27,7 +25,7 @@ function uniqueGeneratedName(base,used){ function hueOfHex(hex,fallback){ const h=typeof hex==='string'?normHex(hex):null; if(!h)return fallback; - const lch=oklab2oklch(srgb2oklab(h)); + const lch=oklchOf(h); return Number.isFinite(lch.H)?lch.H:fallback; } function generatorSourceHue(palette,ground,cfg){ |
