From 7708ea5cd8c05d12e0c39229af9214f068b8589c Mon Sep 17 00:00:00 2001 From: Claude Date: Sun, 19 Jul 2026 17:17:56 +0000 Subject: [PATCH 1/3] feat(configurator): auto-convert pasted colours to the token's canonical space MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Colour fields accepted only the token's own format, so a designer with a brand hex had to pre-convert to OKLCH by hand. Now any CSS colour the browser understands — hex (3/4/6/8), rgb(a), hsl(a), named, hwb, lab/lch, color(), even oklab — is normalised into the field's target space on commit, using the live preview iframe's colour engine via relative-colour syntax so the result matches exactly what gets painted. - New lib/colorConvert.ts: colorSpaceOf() classifies a value; convertColor() resolves oklch(from l c h) / oklab(from …) through the probe and reformats to the compact convention (alpha preserved); normalizeColorInput() is the commit helper — var() refs and already-canonical values pass through, foreign colours convert, unparseable text is kept verbatim. - OklchColorDesk Raw field and ColorInput (text commit + native picker output) route through it. The desk's L/C/H sliders now populate from a pasted hex. Configurator-only; no framework tokens or version touched. Co-Authored-By: Claude Opus 4.8 Claude-Session: https://claude.ai/code/session_013BRVgKfEYocPCHz9KU96FN --- CHANGELOG.md | 3 + .../src/components/inputs/ColorInput.svelte | 20 +++- .../components/inputs/OklchColorDesk.svelte | 25 +++-- configurator/src/lib/colorConvert.ts | 100 ++++++++++++++++++ configurator/tests/colorConvert.test.ts | 49 +++++++++ 5 files changed, 182 insertions(+), 15 deletions(-) create mode 100644 configurator/src/lib/colorConvert.ts create mode 100644 configurator/tests/colorConvert.test.ts diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fd782d9..734aee19 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), ## Unreleased +### Features +- **configurator:** colour fields now accept any CSS colour format — paste a hex, `rgb()`, `hsl()`, a named colour, `lab()`/`lch()`, `color()`, etc. and it is converted automatically into the token's canonical space (OKLCH, or OKLAB where that is the field's default). Conversion uses the browser's own colour engine, so it matches exactly what gets painted; `var()` references and already-canonical values pass through untouched. + ## [0.7.24] - 2026-07-19 ### Features diff --git a/configurator/src/components/inputs/ColorInput.svelte b/configurator/src/components/inputs/ColorInput.svelte index ffa66e25..6a309ded 100644 --- a/configurator/src/components/inputs/ColorInput.svelte +++ b/configurator/src/components/inputs/ColorInput.svelte @@ -1,6 +1,7 @@
@@ -134,23 +145,15 @@ type="text" value={localRaw || value} oninput={(e) => { localRaw = (e.target as HTMLInputElement).value; }} - onblur={() => { - if (localRaw.trim()) { - onChange(localRaw.trim()); - localRaw = ""; - } - }} + onblur={commitRaw} onkeydown={(e) => { if (e.key === "Enter") { - if (localRaw.trim()) { - onChange(localRaw.trim()); - localRaw = ""; - } + commitRaw(); (e.currentTarget as HTMLInputElement).blur(); } }} class="flex-1 bg-black/5 dark:bg-white/5 border border-black/10 dark:border-white/10 rounded-lg px-2 py-1.5 text-[10px] font-mono text-slate-800 dark:text-slate-200 focus:outline-none focus:border-indigo-500" - placeholder="oklch(0.6 0.15 264)" + placeholder="oklch(…) · paste #hex, rgb(), hsl()…" /> {#if overridden}