@weasel-js/theme 1.9.3 → 1.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -48,6 +48,13 @@ const acme = defineTheme({
48
48
  applyTheme(document.documentElement, acme, { mode: 'light' });
49
49
  ```
50
50
 
51
+ `applyTheme` returns a release. Applying to the same element again replaces
52
+ what it held, so a page restyling its root never calls it; call it when a
53
+ themed subtree goes away, and its rule leaves the stylesheet once nothing
54
+ else holds it. The rule goes into the document or shadow root the element
55
+ lives in, so a popout window and a shadow tree are themed like any other.
56
+
57
+
51
58
  `extends` defaults to the built-in theme, so a partial theme can never be
52
59
  accidentally incomplete. Overriding a primitive rebases every alias that
53
60
  references it — set `accent-base` and `--wzl-accent`, `--wzl-accent-hover`,
@@ -69,6 +76,38 @@ beside it. The resolved record carries that CSS as is, because a canvas has no
69
76
  `currentColor`; flatten it with `resolveCurrentColor(value, resolved['--wzl-fg'])`,
70
77
  passing the color of the text it is drawn beside.
71
78
 
79
+ ## Desktop themes
80
+
81
+ Each is a pins-only theme over the built-in one, on its own entry so an app
82
+ that never asks for it never loads it:
83
+
84
+ ```ts
85
+ import { applyTheme } from '@weasel-js/theme';
86
+ import { win9xTheme } from '@weasel-js/theme/themes/win9x';
87
+
88
+ applyTheme(document.documentElement, win9xTheme); // opens in light mode
89
+ ```
90
+
91
+ - `win9xTheme`: Windows 95 and 98. Gray faces in two-pixel bevels, square
92
+ corners, a navy-to-blue title strip, and the system sans at 11, 12, or 14px
93
+ by density.
94
+ - `platinumTheme`, from `@weasel-js/theme/themes/platinum`: Mac OS 8 and 9's
95
+ Platinum. Light gray faces with a black outline and a soft two-tone edge,
96
+ rounded buttons, white fields, and pinstriped window titles centered on the
97
+ strip. The same entry exports `classicMacTheme`, which it extends: the faces,
98
+ sizes, and geometry every classic Mac OS look shares, with no color of its
99
+ own. A System 7 theme is `defineTheme({ name, extends: classicMacTheme, pins })`
100
+ with that era's colors and edges.
101
+
102
+ They open in light mode, the only one the originals had; the dark mode is the
103
+ theme's own. The system faces are named first in the font stacks and are not
104
+ bundled, so a machine without them draws the next face in the stack. The
105
+ bevels and flat button faces are override hooks the theme pins (see below),
106
+ which the controls in `@weasel-js/ui` read wherever they draw a raised face, a
107
+ well, or a button that stays down; the description of each hook lists them.
108
+ To title every group as a window, wrap the app in
109
+ `<DefaultMotif motif={motifs.titlebar()}>` from `@weasel-js/ui`.
110
+
72
111
  ## The engine
73
112
 
74
113
  `@weasel-js/theme/engine` is for authoring layered theme definitions: seeds,
@@ -150,10 +189,11 @@ names the token bare (`"ref": "gray-800"`).
150
189
 
151
190
  ## Override hooks
152
191
 
153
- Ten custom properties resize kit components and **no theme declares them**:
154
- `--wzl-swatch-size`, `--wzl-timeline-label-w`, `--wzl-number-field-width` and
155
- the rest. Kit CSS reads each one with a fallback, so setting it on any
156
- container is what changes it, and leaving it alone takes the fallback:
192
+ Some custom properties restyle kit components and **the built-in theme does
193
+ not declare them**: `--wzl-swatch-size`, `--wzl-timeline-label-w`,
194
+ `--wzl-number-field-width` and the rest. Kit CSS reads each one with a
195
+ fallback, so setting it on any container is what changes it, and leaving it
196
+ alone takes the fallback:
157
197
 
158
198
  ```css
159
199
  .dense-panel { --wzl-swatch-size: 20px; --wzl-number-field-width: 6ch; }
@@ -168,6 +208,13 @@ import { TOKEN_MANIFEST } from '@weasel-js/theme';
168
208
  const hooks = TOKEN_MANIFEST.filter((t) => t.hook);
169
209
  ```
170
210
 
211
+ A theme built with `defineTheme` can pin one too, which is how a theme changes
212
+ what a token cannot say: `--wzl-bevel-raised`, `--wzl-bevel-sunken` and
213
+ `--wzl-bevel-pressed` are the box shadows of a raised face, a well and a pressed
214
+ button, and the `--wzl-button-*` hooks replace a Button's glass with a flat
215
+ face. A pin's value is fixed where the theme is applied, so one written with
216
+ `var()` does not follow a token a container overrides further down.
217
+
171
218
  They stay out of `tokens.css` on purpose. A `:root` value would outrank the
172
219
  fallback written beside every read, so the two would have to agree forever, and
173
220
  `npm run check:token-reads` would stop requiring that the fallback be there at
@@ -1,53 +1,5 @@
1
- import { hexToOklchDeg, oklchDegToHex, srgbU8ToOklab } from '@weasel-js/paint';
2
-
3
- // src/axes.ts
4
- function isByAxis(v) {
5
- return typeof v === "object" && v !== null && !Array.isArray(v) && typeof v.by === "string";
6
- }
7
- function fullSelection(axes, selection = {}) {
8
- const out = {};
9
- for (const [name, def] of Object.entries(axes)) {
10
- const v = selection[name];
11
- out[name] = v !== void 0 && v in def.values ? v : def.default;
12
- }
13
- return out;
14
- }
15
- function mergeAxes(parent, child) {
16
- const out = { ...parent };
17
- for (const [name, def] of Object.entries(child)) {
18
- out[name] = { ...def, values: { ...parent[name]?.values, ...def.values } };
19
- }
20
- return out;
21
- }
22
- function enumerateSelections(axes) {
23
- let out = [{}];
24
- for (const [name, def] of Object.entries(axes)) {
25
- out = out.flatMap((s) => Object.keys(def.values).map((v) => ({ ...s, [name]: v })));
26
- }
27
- return out;
28
- }
29
- function selectionKey(axes, selection) {
30
- const full = fullSelection(axes, selection);
31
- return Object.keys(axes).map((a) => `${a}=${full[a]}`).join(",");
32
- }
33
- function pick(v, selection) {
34
- let cur = v;
35
- while (isByAxis(cur)) {
36
- const axis = cur.by;
37
- const value = selection[axis];
38
- if (value === void 0 || value === "by" || !(value in cur)) return { ok: false, axis, value: value ?? "" };
39
- cur = cur[value];
40
- }
41
- return { ok: true, value: cur };
42
- }
43
- function pickAll(record, selection) {
44
- const out = {};
45
- for (const [name, v] of Object.entries(record)) {
46
- const picked = pick(v, selection);
47
- if (picked.ok) out[name] = picked.value;
48
- }
49
- return out;
50
- }
1
+ import { pick, mergeAxes, fullSelection } from './chunk-P5F3GZV6.js';
2
+ import { hexToOklchDeg, oklchDegToHex, hexToRgbBytes, parseHexBytes, srgbU8ToOklab } from '@weasel-js/paint';
51
3
 
52
4
  // src/dtcg/value.ts
53
5
  function fontStack(value) {
@@ -76,13 +28,44 @@ function parseTokenValue(type, text) {
76
28
  return raw;
77
29
  }
78
30
 
79
- // src/dtcg/color.ts
31
+ // src/chainTokens.ts
32
+ function localSelections(chain, selection) {
33
+ let axes = {};
34
+ return chain.map((link) => {
35
+ axes = mergeAxes(axes, link.axes);
36
+ return { ...selection, ...fullSelection(axes, selection) };
37
+ });
38
+ }
39
+ function tokenAt(chain, name, selection) {
40
+ const local = localSelections(chain, selection);
41
+ for (let i = chain.length - 1; i >= 0; i--) {
42
+ const { tokens } = chain[i];
43
+ if (!Object.hasOwn(tokens, name)) continue;
44
+ const picked = pick(tokens[name], local[i]);
45
+ if (picked.ok) return picked.value;
46
+ }
47
+ return void 0;
48
+ }
49
+ function tokensAt(chain, selection) {
50
+ const local = localSelections(chain, selection);
51
+ const out = {};
52
+ chain.forEach((link, i) => {
53
+ for (const [name, v] of Object.entries(link.tokens)) {
54
+ const picked = pick(v, local[i]);
55
+ if (picked.ok) out[name] = picked.value;
56
+ }
57
+ });
58
+ return out;
59
+ }
80
60
  function withAlpha(color, alpha) {
81
61
  const rgba = parseRgba(color.trim());
82
- if (!rgba) return `color-mix(in srgb, ${color.trim()} ${round(alpha * 100, 4)}%, transparent)`;
62
+ if (!rgba) return mixAlpha(color.trim(), alpha);
83
63
  const [r, g, b, a] = rgba;
84
64
  return `rgba(${r}, ${g}, ${b}, ${round(a * alpha, 3)})`;
85
65
  }
66
+ function mixAlpha(color, alpha) {
67
+ return `color-mix(in srgb, ${color} ${round(alpha * 100, 4)}%, transparent)`;
68
+ }
86
69
  function atAlpha(color, alpha) {
87
70
  const rgba = parseRgba(color.trim());
88
71
  if (!rgba) return `rgb(from ${color.trim()} r g b / ${alpha})`;
@@ -97,12 +80,8 @@ function parseRgba(s) {
97
80
  return parseHex(s) ?? parseRgbFn(s);
98
81
  }
99
82
  function parseHex(s) {
100
- const m = /^#([0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.exec(s);
101
- if (!m) return null;
102
- const body = m[1];
103
- const full = body.length <= 4 ? body.replace(/./g, (c) => c + c) : body;
104
- const byte = (i) => Number.parseInt(full.slice(i, i + 2), 16);
105
- return [byte(0), byte(2), byte(4), full.length === 8 ? byte(6) / 255 : 1];
83
+ const bytes = parseHexBytes(s);
84
+ return bytes && [bytes[0], bytes[1], bytes[2], bytes[3] / 255];
106
85
  }
107
86
  function parseRgbFn(s) {
108
87
  const m = /^rgba?\(([^()]*)\)$/i.exec(s);
@@ -171,16 +150,11 @@ function themeAxes(theme) {
171
150
  }
172
151
  function resolveTheme(theme, selection = {}) {
173
152
  const sel = fullSelection(themeAxes(theme), selection);
174
- let merged = {};
175
- for (const t of themeChain(theme)) merged = { ...merged, ...pickAll(t.tokens, sel) };
176
153
  const out = {};
177
- for (const [name, value] of Object.entries(resolveTokens(merged))) out[`--wzl-${name}`] = value;
154
+ for (const [name, value] of Object.entries(resolveTokens(tokensAt(themeChain(theme), sel)))) out[`--wzl-${name}`] = value;
178
155
  return out;
179
156
  }
180
- function hexToRgb(hex) {
181
- const n = Number.parseInt(hex.slice(1), 16);
182
- return [n >> 16 & 255, n >> 8 & 255, n & 255];
183
- }
157
+ var hexToRgb = hexToRgbBytes;
184
158
  var toHex = oklchDegToHex;
185
159
  var toLch = hexToOklchDeg;
186
160
  function chromaCap(L, H) {
@@ -314,7 +288,6 @@ function searchHues(c) {
314
288
  const anchorHexes = c.anchors.map(toHexPreview);
315
289
  const freeCount = c.count - c.anchors.length;
316
290
  if (freeCount < 0) return null;
317
- if (freeCount === 0) return [];
318
291
  const weighted = (hex) => {
319
292
  const [L, a, b] = toLab(hex);
320
293
  return [L, CHROMA_WEIGHT * a, CHROMA_WEIGHT * b];
@@ -388,6 +361,7 @@ function searchHues(c) {
388
361
  const m = metaFor(free);
389
362
  return m.reduce((sum, x) => sum + x.chroma, 0) / m.length;
390
363
  };
364
+ if (freeCount === 0) return penalty([]) > 0 ? null : [];
391
365
  const seeds = [];
392
366
  const seedStep = Math.max(6, Math.round(freeCount * 1.6));
393
367
  for (let start = 0; start < 360; start += seedStep) {
@@ -558,6 +532,6 @@ function anchorFromHex(hex, name) {
558
532
  };
559
533
  }
560
534
 
561
- export { CHROMA_WEIGHT, DEFAULT_CONSTRAINTS, anchorFromHex, atAlpha, chromaCap, contrast, deltaE, enumerateSelections, floorDegrees, fullSelection, generate, hexToRgb, hueGap, hueName, isByAxis, luminance, mergeAxes, parseTokenValue, pick, pickAll, resolveTheme, resolveTokens, selectionKey, serializeTokenValue, themeAxes, themeChain, toHex, toHexPreview, toLab, toLch, vividAt, withAlpha };
562
- //# sourceMappingURL=chunk-NUILKH2Z.js.map
563
- //# sourceMappingURL=chunk-NUILKH2Z.js.map
535
+ export { CHROMA_WEIGHT, DEFAULT_CONSTRAINTS, anchorFromHex, atAlpha, chromaCap, contrast, deltaE, floorDegrees, generate, hexToRgb, hueGap, hueName, luminance, mixAlpha, parseTokenValue, resolveTheme, resolveTokens, serializeTokenValue, themeAxes, themeChain, toHex, toHexPreview, toLab, toLch, tokenAt, tokensAt, vividAt, withAlpha };
536
+ //# sourceMappingURL=chunk-2PY2YTDY.js.map
537
+ //# sourceMappingURL=chunk-2PY2YTDY.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/dtcg/value.ts","../src/chainTokens.ts","../src/dtcg/color.ts","../src/dtcg/resolve.ts","../src/resolveTheme.ts","../src/engine/color/oklch.ts","../src/engine/color/generate.ts"],"names":[],"mappings":";;;;AAOA,SAAS,UAAU,KAAA,EAA6C;AAC9D,EAAA,OAAO,MAAM,GAAA,CAAI,CAAC,MAAO,OAAO,CAAA,KAAM,YAAY,IAAA,CAAK,IAAA,CAAK,CAAC,CAAA,GAAI,CAAA,CAAA,EAAI,CAAC,CAAA,CAAA,CAAA,GAAM,MAAA,CAAO,CAAC,CAAE,CAAA,CAAE,KAAK,IAAI,CAAA;AACnG;AAOO,SAAS,mBAAA,CAAoB,MAAc,KAAA,EAA2B;AAC3E,EAAA,IAAI,KAAA,CAAM,OAAA,CAAQ,KAAK,CAAA,EAAG;AACx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AAS;AACrE;AAGO,IAAM,mBAAA,GAAmC;AAAA,EAC9C,KAAA,EAAO,EAAA;AAAA,EACP,QAAA,EAAU,GAAA;AAAA,EACV,WAAA,EAAa,CAAA;AAAA,EACb,OAAA,EAAS,SAAA;AAAA,EACT,eAAA,EAAiB,IAAA;AAAA,EACjB,aAAA,EAAe,GAAA;AAAA,EACf,cAAA,EAAgB,IAAA;AAAA,EAChB,QAAA,EAAU,CAAA;AAAA,EACV,kBAAA,EAAoB,IAAA;AAAA,EACpB,WAAA,EAAa,IAAA;AAAA,EACb,SAAS,EAAC;AAAA,EACV,KAAA,EAAO;AACT;AAGO,SAAS,aAAa,CAAA,EAAyD;AACpF,EAAA,MAAM,GAAA,GAAM,SAAA,CAAU,CAAA,CAAE,SAAA,EAAW,EAAE,GAAG,CAAA;AACxC,EAAA,OAAO,KAAA,CAAM,CAAA,CAAE,SAAA,EAAW,CAAA,CAAE,WAAW,MAAA,GAAY,GAAA,GAAM,IAAA,CAAK,GAAA,CAAI,CAAA,CAAE,MAAA,EAAQ,GAAG,CAAA,EAAG,EAAE,GAAG,CAAA;AACzF;AAQO,SAAS,aAAA,CAAc,KAAa,IAAA,EAAuB;AAChE,EAAA,MAAM,EAAE,CAAA,EAAG,CAAA,EAAG,CAAA,EAAE,GAAI,MAAM,GAAG,CAAA;AAC7B,EAAA,OAAO;AAAA,IACL,IAAA,EAAM,IAAA,IAAQ,OAAA,CAAQ,CAAC,CAAA;AAAA,IACvB,GAAA,EAAK,IAAA,CAAK,KAAA,CAAM,CAAC,CAAA;AAAA,IACjB,SAAA,EAAW,MAAA,CAAO,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAC,CAAA;AAAA,IAC9B,MAAA,EAAQ,MAAA,CAAO,CAAA,CAAE,OAAA,CAAQ,CAAC,CAAC;AAAA,GAC7B;AACF","file":"chunk-2PY2YTDY.js","sourcesContent":["import type { TokenValue } from './types.ts';\n\n/**\n * Quote family names containing whitespace; leave everything else bare.\n * Generic keywords (`sans-serif`) and hyphen-prefixed identifiers\n * (`-apple-system`) break if quoted, and neither contains a space.\n */\nfunction fontStack(value: readonly (string | number)[]): string {\n return value.map((f) => (typeof f === 'string' && /\\s/.test(f) ? `'${f}'` : String(f))).join(', ');\n}\n\n/**\n * A token's value as CSS renders it. A DTCG value is not always a string: a\n * `fontFamily` is a list of names and a `cubicBezier` is four numbers, and both\n * have a spelling that belongs in a stylesheet rather than in JSON.\n */\nexport function serializeTokenValue(type: string, value: TokenValue): string {\n if (Array.isArray(value)) {\n if (type === 'cubicBezier') return `cubic-bezier(${value.join(', ')})`;\n if (type === 'fontFamily') return fontStack(value);\n return value.join(', ');\n }\n return String(value);\n}\n\nconst BEZIER = /^cubic-bezier\\(\\s*([^)]*)\\)$/i;\n\n/**\n * The inverse of {@link serializeTokenValue}: text a person edited, back in the\n * shape a definition stores. Text that does not parse for its type is kept as\n * text rather than thrown away, so a half-typed value stays editable.\n */\nexport function parseTokenValue(type: string, text: string): TokenValue {\n const raw = text.trim();\n if (type === 'cubicBezier') {\n const inner = BEZIER.exec(raw)?.[1] ?? raw;\n const parts = inner.split(',').map((p) => Number(p.trim()));\n return parts.length === 4 && parts.every((n) => Number.isFinite(n)) ? parts : raw;\n }\n if (type === 'fontFamily') {\n const families = raw\n .split(',')\n .map((f) => f.trim().replace(/^['\"]|['\"]$/g, '').trim())\n .filter((f) => f !== '');\n return families.length > 0 ? families : raw;\n }\n return raw;\n}\n","import { fullSelection, mergeAxes, pick, type AxisDefs, type Selection, type Varying } from './axes.ts';\nimport type { FlatTokens, RawToken } from './dtcg/types.ts';\n\n/** One theme of an `extends` chain, as far as choosing its tokens goes. */\nexport interface ChainLink {\n readonly axes: AxisDefs;\n readonly tokens: Readonly<Record<string, Varying<RawToken>>>;\n}\n\n/**\n * The selection each theme of a root-first chain reads its own tokens at. An axis value a theme and\n * everything it extends never declared (one a descendant added) becomes that theme's default for the\n * axis, which is what the stylesheet's cascade gives it: no block of the ancestor matches the new\n * value, so its default declarations show through.\n */\nfunction localSelections(chain: readonly ChainLink[], selection: Selection): Selection[] {\n let axes: AxisDefs = {};\n return chain.map((link) => {\n axes = mergeAxes(axes, link.axes);\n return { ...selection, ...fullSelection(axes, selection) };\n });\n}\n\n/** `name` from the nearest theme of a root-first chain that has it at `selection`. */\nexport function tokenAt(chain: readonly ChainLink[], name: string, selection: Selection): RawToken | undefined {\n const local = localSelections(chain, selection);\n for (let i = chain.length - 1; i >= 0; i--) {\n const { tokens } = chain[i];\n if (!Object.hasOwn(tokens, name)) continue;\n const picked = pick(tokens[name], local[i]);\n if (picked.ok) return picked.value;\n }\n return undefined;\n}\n\n/** Every token of a root-first chain at `selection`, each from the nearest theme that has it there. */\nexport function tokensAt(chain: readonly ChainLink[], selection: Selection): FlatTokens {\n const local = localSelections(chain, selection);\n const out: Record<string, RawToken> = {};\n chain.forEach((link, i) => {\n for (const [name, v] of Object.entries(link.tokens)) {\n const picked = pick(v, local[i]);\n if (picked.ok) out[name] = picked.value;\n }\n });\n return out;\n}\n","import { parseHexBytes } from '@weasel-js/paint';\n\n/**\n * A resolved color at `alpha`, multiplied into any alpha it already carries. The\n * JS side of the alpha extension; the CSS side emits `color-mix()` instead so DOM\n * chrome keeps tracking a downstream override of the referenced token.\n *\n * Hex and `rgb()`/`rgba()` become an `rgba()` literal. Anything else — a named\n * color, `hsl()`, `oklch()`, a `var()` — becomes the same `color-mix()` the CSS\n * side writes, which the browser resolves.\n */\nexport function withAlpha(color: string, alpha: number): string {\n const rgba = parseRgba(color.trim());\n if (!rgba) return mixAlpha(color.trim(), alpha);\n const [r, g, b, a] = rgba;\n return `rgba(${r}, ${g}, ${b}, ${round(a * alpha, 3)})`;\n}\n\n/** `color` at `alpha` as a `color-mix()` with transparent, for a color only the browser can resolve. */\nexport function mixAlpha(color: string, alpha: number): string {\n return `color-mix(in srgb, ${color} ${round(alpha * 100, 4)}%, transparent)`;\n}\n\n/** A resolved color with its alpha replaced by `alpha`, as `rgb(from c r g b / alpha)` computes it. */\nexport function atAlpha(color: string, alpha: number): string {\n const rgba = parseRgba(color.trim());\n if (!rgba) return `rgb(from ${color.trim()} r g b / ${alpha})`;\n const [r, g, b] = rgba;\n return `rgba(${r}, ${g}, ${b}, ${round(alpha, 3)})`;\n}\n\ntype Rgba = [number, number, number, number];\n\nfunction round(n: number, places: number): number {\n return Number(n.toFixed(places));\n}\n\nfunction parseRgba(s: string): Rgba | null {\n if (s.toLowerCase() === 'transparent') return [0, 0, 0, 0];\n return parseHex(s) ?? parseRgbFn(s);\n}\n\nfunction parseHex(s: string): Rgba | null {\n const bytes = parseHexBytes(s);\n return bytes && [bytes[0], bytes[1], bytes[2], bytes[3] / 255];\n}\n\nfunction parseRgbFn(s: string): Rgba | null {\n const m = /^rgba?\\(([^()]*)\\)$/i.exec(s);\n if (!m) return null;\n const [channels, alphaPart, extra] = m[1].split('/');\n if (extra !== undefined) return null;\n const parts = channels.trim().split(/\\s*,\\s*|\\s+/);\n if (alphaPart !== undefined) parts.push(alphaPart.trim());\n if (parts.length !== 3 && parts.length !== 4) return null;\n\n const channel = (p: string) => (p.endsWith('%') ? (Number.parseFloat(p) / 100) * 255 : Number(p));\n const alpha = (p: string) => (p.endsWith('%') ? Number.parseFloat(p) / 100 : Number(p));\n const [r, g, b] = parts.slice(0, 3).map(channel);\n const a = parts[3] === undefined ? 1 : alpha(parts[3]);\n if (![r, g, b, a].every(Number.isFinite)) return null;\n return [Math.round(r), Math.round(g), Math.round(b), a];\n}\n","import { withAlpha } from './color.ts';\nimport type { FlatTokens, ResolvedTokenMap, TokenValue } from './types.ts';\nimport { serializeTokenValue } from './value.ts';\n\n/** `{color.gray-100}` → `gray-100`. The type group is dropped, per the naming rule. */\nconst REF = /^\\{([^}]+)\\}$/;\n\nfunction refTarget(value: TokenValue): string | null {\n if (typeof value !== 'string') return null;\n const m = REF.exec(value.trim());\n if (!m) return null;\n const path = m[1];\n const dot = path.indexOf('.');\n return dot === -1 ? path : path.slice(dot + 1);\n}\n\n/**\n * Resolve flat tokens to final CSS-ready strings.\n *\n * Merge modes before calling: this function has no notion of modes, only of a\n * complete token set.\n */\nexport function resolveTokens(tokens: FlatTokens): ResolvedTokenMap {\n const out: ResolvedTokenMap = {};\n const inProgress = new Set<string>();\n\n const resolveOne = (name: string): string => {\n const cached = out[name];\n if (cached !== undefined) return cached;\n\n const token = tokens[name];\n if (!token) throw new Error(`Unknown token \"${name}\"`);\n\n if (inProgress.has(name)) {\n throw new Error(`Reference cycle at token \"${name}\" (${[...inProgress].join(' → ')})`);\n }\n inProgress.add(name);\n\n const target = refTarget(token.value);\n let value: string;\n if (target === null) {\n value = serializeTokenValue(token.type, token.value);\n } else if (!tokens[target]) {\n throw new Error(`Token \"${name}\" references \"${target}\", which is not defined`);\n } else {\n value = resolveOne(target);\n }\n\n if (token.alpha !== undefined) value = withAlpha(value, token.alpha);\n\n inProgress.delete(name);\n out[name] = value;\n return value;\n };\n\n for (const name of Object.keys(tokens)) resolveOne(name);\n return out;\n}\n\n/** Merge a mode's tokens over the mode-invariant set. Later wins. */\nexport function mergeTokens(base: FlatTokens, mode: FlatTokens): FlatTokens {\n return { ...base, ...mode };\n}\n","import { fullSelection, mergeAxes, type AxisDefs, type Selection } from './axes.ts';\nimport { tokensAt } from './chainTokens.ts';\nimport { resolveTokens } from './dtcg/resolve.ts';\nimport type { TokenName } from './generated/themes.ts';\nimport type { Theme } from './theme.ts';\n\n/** The output of `resolveTheme`: every token of a theme, for one selection, keyed\n * by CSS custom-property name and flattened to a final CSS value. */\nexport type ResolvedTheme = Readonly<Record<TokenName, string>>;\n\n/** Root-first, so the leaf theme's tokens land last. */\nexport function themeChain(theme: Theme): Theme[] {\n const out: Theme[] = [];\n for (let t: Theme | null = theme; t; t = t.extends) out.unshift(t);\n return out;\n}\n\n/** Every axis the chain declares. An axis declared more than once keeps every value; a descendant's value entries and default win. */\nexport function themeAxes(theme: Theme): AxisDefs {\n return themeChain(theme).reduce<AxisDefs>((axes, t) => mergeAxes(axes, t.axes), {});\n}\n\n/**\n * Merge the extends chain at a selection, resolve every alias, and key the\n * result by CSS custom-property name. A missing or unknown axis value takes the\n * axis default, and a theme in the chain reads a value it never declared at its\n * own default for that axis.\n *\n * Pure — no DOM. An unresolvable reference throws rather than falling back.\n */\nexport function resolveTheme(theme: Theme, selection: Selection = {}): ResolvedTheme {\n const sel = fullSelection(themeAxes(theme), selection);\n const out: Record<string, string> = {};\n for (const [name, value] of Object.entries(resolveTokens(tokensAt(themeChain(theme), sel)))) out[`--wzl-${name}`] = value;\n return out as ResolvedTheme;\n}\n","import { hexToOklchDeg, hexToRgbBytes, oklchDegToHex, srgbU8ToOklab, type OklchDeg } from '@weasel-js/paint';\n\n/** A color in OKLCH: lightness 0–1, chroma, hue in degrees. paint's own type,\n * under the name this engine has always called it. */\nexport type Lch = OklchDeg;\n\n/** A hex color to 0–255 channels, its alpha dropped. Throws on anything else. */\nexport const hexToRgb: (hex: string) => [number, number, number] = hexToRgbBytes;\n\n/** OKLCH (lightness 0–1, chroma, hue in degrees) to `#rrggbb`. Chroma past the gamut is clipped at constant lightness. */\nexport const toHex = oklchDegToHex;\n/** `#rrggbb` to OKLCH, hue in 0–360. */\nexport const toLch: (hex: string) => Lch = hexToOklchDeg;\n\n/** The most chroma this hue can carry at this lightness, inside sRGB. */\nexport function chromaCap(L: number, H: number): number {\n return toLch(toHex(L, 0.5, H)).C;\n}\n\n/** WCAG relative luminance. */\nexport function luminance(hex: string): number {\n const [r, g, b] = hexToRgb(hex).map((v) => v / 255);\n const f = (u: number) => (u <= 0.04045 ? u / 12.92 : ((u + 0.055) / 1.055) ** 2.4);\n return 0.2126 * f(r) + 0.7152 * f(g) + 0.0722 * f(b);\n}\n\n/** WCAG contrast ratio between two hex colors, 1–21, in either order. */\nexport function contrast(a: string, b: string): number {\n const [hi, lo] = [luminance(a), luminance(b)].sort((p, q) => q - p);\n return (hi + 0.05) / (lo + 0.05);\n}\n\n/** Shortest angular distance between two hues, in degrees. */\nexport function hueGap(a: number, b: number): number {\n const d = Math.abs(a - b) % 360;\n return Math.min(d, 360 - d);\n}\n\n/** OKLab coordinates, for distance work. */\nexport function toLab(hex: string): [number, number, number] {\n const [r, g, b] = hexToRgb(hex);\n return srgbU8ToOklab(r, g, b);\n}\n\n/**\n * How far apart two colors look, with chroma weighted up.\n *\n * Two things this is not. It is not WCAG contrast, which reads lightness only\n * and so scores a vivid yellow on white at 1.2:1 and calls it illegible when\n * what separates them is chroma. And it is not plain euclidean OKLab distance:\n * OKLab's chroma range is small beside its lightness range, so an unweighted\n * distance is almost all lightness, and it ranks a mid-gray as further from\n * white than a pale blue is.\n *\n * `CHROMA_WEIGHT` restores CIELAB's ordering. It is a weight, not a unit\n * conversion, so these numbers do not transfer to or from CIELAB dE.\n *\n * Rough calibration in the weighted space: 0.17 is a pale wash against paper,\n * 0.25 is a real color, 0.5 is unmistakable.\n */\nexport const CHROMA_WEIGHT = 3;\n\n/** Perceptual distance between two hex colors: OKLab with chroma weighted by {@link CHROMA_WEIGHT}. */\nexport function deltaE(a: string, b: string): number {\n const [l1, a1, b1] = toLab(a);\n const [l2, a2, b2] = toLab(b);\n return Math.hypot(l1 - l2, CHROMA_WEIGHT * (a1 - a2), CHROMA_WEIGHT * (b1 - b2));\n}\n\n/** The most chroma this hue can carry at this lightness, as a hex. */\nexport function vividAt(L: number, H: number): string {\n return toHex(L, chromaCap(L, H), H);\n}\n","import {\n chromaCap,\n contrast,\n CHROMA_WEIGHT,\n deltaE,\n hueGap,\n toHex,\n toLab,\n toLch,\n type Lch,\n} from './oklch.ts';\n\n/**\n * A hue pinned into the palette with its own lightness.\n *\n * Anchors exist because the lightness law excludes some colors entirely. Yellow\n * is the case that forces it: its chroma peaks at L 0.95 — higher than any other\n * hue — so a law that picks lightness for legibility silently yields gold, then\n * olive, and never reports that yellow was dropped.\n */\nexport interface Anchor {\n readonly name: string;\n readonly hue: number;\n readonly lightness: number;\n /**\n * Absolute chroma. Omitted means \"as much as the gamut allows here\", which is\n * what a bright color wants. A muted color has to say so: hue and lightness\n * alone can only describe vivid colors, so a tan asked for at max chroma\n * comes back as an amber.\n */\n readonly chroma?: number;\n}\n\n/** Every constraint the generator honors. A zero disables the ones that gate. */\nexport interface Constraints {\n readonly count: number;\n /**\n * Minimum hue separation, as a share of the even `360 / count` spacing an\n * ideal set would have. 0 disables the check.\n *\n * A share rather than degrees, because absolute degrees mean different things\n * at different cardinalities: 30 degrees is generous for 8 colors and\n * impossible for 16, so a floor in degrees silently becomes unsatisfiable as\n * the set grows.\n */\n readonly hueFloor: number;\n /** Minimum WCAG contrast every swatch must clear against `surface`. 0 disables. */\n readonly minContrast: number;\n /**\n * Minimum perceptual distance from `surface`. 0 disables.\n *\n * The gate WCAG contrast cannot express. Contrast reads only lightness, so it\n * scores a vivid yellow on white at 1.2:1 and calls it illegible, when what\n * separates them is chroma. Gate on this instead of on lightness and a yellow\n * can be a yellow; gate on contrast alone and the search quietly returns gold.\n */\n readonly minSurfaceDistance: number;\n /** Minimum perceptual distance between any two swatches. 0 disables. */\n readonly minDistance: number;\n readonly surface: string;\n /** Where `lightnessPull` drags each hue, away from its own chroma peak. */\n readonly lightnessTarget: number;\n /** 0 leaves every hue at its chroma peak; 1 puts them all at the target. */\n readonly lightnessPull: number;\n /** Fraction of the in-gamut chroma ceiling to take. */\n readonly chromaFraction: number;\n /** 0 leaves chroma alone; 1 pulls every hue to the set mean. */\n readonly equalize: number;\n readonly anchors: readonly Anchor[];\n readonly order: 'hue' | 'farthest';\n}\n\n/** One color of a generated {@link Palette}. */\nexport interface Swatch {\n readonly name: string;\n readonly hex: string;\n readonly lch: Lch;\n /** Came from one of the constraints' anchors. */\n readonly anchored: boolean;\n /** WCAG contrast against the constraints' `surface`. */\n readonly contrast: number;\n}\n\n/** Measurements of a generated palette as a whole: the minimums are over every swatch, or every pair. */\nexport interface Stats {\n readonly meanChroma: number;\n readonly chromaSpread: number;\n readonly lightnessSpread: number;\n readonly minHueGap: number;\n /** The realized floor as a share of even spacing, comparable across sizes. */\n readonly hueFloorShare: number;\n readonly minContrast: number;\n readonly minSurfaceDistance: number;\n readonly minDistance: number;\n}\n\n/** What {@link generate} returns. */\nexport interface Palette {\n readonly swatches: readonly Swatch[];\n readonly stats: Stats;\n /** False when no hue arrangement satisfied the gates; `swatches` is then the\n * best unconstrained attempt, so the lab still has something to draw. */\n readonly feasible: boolean;\n}\n\n/** Lightness at which a hue reaches its highest chroma. */\nfunction peakLightness(H: number): number {\n let bestL = 0.5;\n let bestC = -1;\n for (let L = 0.32; L <= 0.96; L += 0.01) {\n const c = chromaCap(L, H);\n if (c > bestC) {\n bestC = c;\n bestL = L;\n }\n }\n return bestL;\n}\n\nconst PEAK: number[] = [];\nfor (let H = 0; H < 360; H += 1) PEAK.push(peakLightness(H));\nconst peakAt = (H: number) => PEAK[((Math.round(H) % 360) + 360) % 360];\n\n/** The default law: sit near this hue's chroma peak, pulled toward the target. */\nfunction place(H: number, c: Constraints): string {\n const L = peakAt(H) + (c.lightnessTarget - peakAt(H)) * c.lightnessPull;\n return toHex(L, chromaCap(L, H) * c.chromaFraction, H);\n}\n\nconst HUE_NAMES: readonly (readonly [number, string])[] = [\n [15, 'rose'], [45, 'red'], [62, 'orange'], [85, 'amber'], [100, 'gold'],\n [122, 'yellow'], [138, 'lime'], [165, 'green'], [195, 'teal'], [218, 'cyan'],\n [245, 'sky'], [275, 'blue'], [310, 'violet'], [345, 'fuchsia'],\n];\n/** A plain color name for a hue in degrees: `red`, `teal`, `violet`. */\nexport function hueName(H: number): string {\n for (const [ceil, name] of HUE_NAMES) if (H < ceil) return name;\n return 'rose';\n}\n\n/** Disambiguate repeats: two hues can land in one name's band. */\nfunction uniqueNames(hues: number[]): string[] {\n const seen = new Map<string, number>();\n return hues.map((h) => {\n const base = hueName(h);\n const n = (seen.get(base) ?? 0) + 1;\n seen.set(base, n);\n return n === 1 ? base : `${base}-${n}`;\n });\n}\n\n/**\n * Pull each chroma toward the set mean.\n *\n * Raising a chroma is not always possible in place — the weak hues sit on the\n * gamut ceiling already — so this walks lightness to where the target chroma\n * exists, choosing the nearest such lightness. Anchors keep theirs and are\n * only ever desaturated. That asymmetry is why equalizing moves the lightness\n * spread as well.\n */\nfunction equalizeChroma(hexes: string[], k: number, anchored: boolean[]): string[] {\n if (k <= 0) return hexes;\n const lch = hexes.map(toLch);\n const target = lch.reduce((sum, x) => sum + x.C, 0) / lch.length;\n\n return lch.map((x, i) => {\n const wanted = x.C + (target - x.C) * k;\n if (anchored[i]) return toHex(x.L, Math.min(wanted, chromaCap(x.L, x.H)), x.H);\n if (chromaCap(x.L, x.H) >= wanted) return toHex(x.L, wanted, x.H);\n\n let bestL = x.L;\n let bestDistance = Infinity;\n for (let L = 0.30; L <= 0.96; L += 0.005) {\n if (chromaCap(L, x.H) >= wanted) {\n const d = Math.abs(L - x.L);\n if (d < bestDistance) {\n bestDistance = d;\n bestL = L;\n }\n }\n }\n if (bestDistance === Infinity) {\n const pk = peakAt(x.H);\n return toHex(pk, chromaCap(pk, x.H), x.H);\n }\n return toHex(bestL, wanted, x.H);\n });\n}\n\n/**\n * Reorder so every prefix stays as separated as a set that size can be.\n * A consumer taking the first three of ten should get three colors 87° apart,\n * not three neighbors.\n */\nfunction farthestFirst(hues: number[]): number[] {\n const order = [0];\n while (order.length < hues.length) {\n let best = -1;\n let bestGap = -1;\n for (let i = 0; i < hues.length; i += 1) {\n if (order.includes(i)) continue;\n const gap = Math.min(...order.map((j) => hueGap(hues[i], hues[j])));\n if (gap > bestGap) {\n bestGap = gap;\n best = i;\n }\n }\n order.push(best);\n }\n return order;\n}\n\n/**\n * Search hue positions that maximize mean chroma subject to the gates.\n *\n * Seeds matter: a uniform 360/n ring can never open a `2 * minHueGap` hole\n * around a pinned hue, so with anchors the seeds spread across the arc the\n * anchors leave free instead.\n */\n/** The share-of-even floor, in degrees, for a set of this size. */\nexport function floorDegrees(c: Pick<Constraints, 'hueFloor' | 'count'>): number {\n return c.hueFloor <= 0 ? 0 : (c.hueFloor * 360) / Math.max(1, c.count);\n}\n\nfunction searchHues(c: Constraints): number[] | null {\n const minGapDeg = floorDegrees(c);\n const anchorHues = c.anchors.map((a) => a.hue);\n const anchorHexes = c.anchors.map(toHexPreview);\n const freeCount = c.count - c.anchors.length;\n if (freeCount < 0) return null;\n\n // Hue is an integer 0-359 and the constraints are fixed for one call, so the\n // placed color, its realized hue and its contrast are each computed once.\n interface Placed {\n hex: string;\n hue: number;\n contrast: number;\n chroma: number;\n surfaceDistance: number;\n /** OKLab coordinates, chroma pre-weighted, so a pairwise distance in the\n * search is three subtractions rather than two color conversions. */\n lab: readonly [number, number, number];\n }\n const weighted = (hex: string): readonly [number, number, number] => {\n const [L, a, b] = toLab(hex);\n return [L, CHROMA_WEIGHT * a, CHROMA_WEIGHT * b];\n };\n const between = (p: readonly [number, number, number], q: readonly [number, number, number]) =>\n Math.hypot(p[0] - q[0], p[1] - q[1], p[2] - q[2]);\n const placed = new Map<number, Placed>();\n const at = (H: number) => {\n const key = ((Math.round(H) % 360) + 360) % 360;\n let v = placed.get(key);\n if (!v) {\n const hex = place(key, c);\n const lch = toLch(hex);\n v = {\n hex,\n hue: lch.H,\n contrast: contrast(hex, c.surface),\n chroma: lch.C,\n surfaceDistance: deltaE(hex, c.surface),\n lab: weighted(hex),\n };\n placed.set(key, v);\n }\n return v;\n };\n const anchorMeta = anchorHexes.map((hex) => {\n const lch = toLch(hex);\n return {\n hex,\n hue: lch.H,\n contrast: contrast(hex, c.surface),\n chroma: lch.C,\n surfaceDistance: deltaE(hex, c.surface),\n lab: weighted(hex),\n };\n });\n const metaFor = (free: number[]) => [...anchorMeta, ...free.map(at)];\n\n /**\n * How far a set is from legal, in one number: degrees of hue crowding plus\n * contrast shortfall. Zero means feasible. The search descends this first and\n * only then maximizes chroma, because a seed ring is often illegal and the\n * legal region may not be reachable by chroma-improving moves alone.\n */\n const penalty = (free: number[]): number => {\n const m = metaFor(free);\n let p = 0;\n if (minGapDeg > 0) {\n for (let i = 0; i < m.length; i += 1) {\n for (let j = i + 1; j < m.length; j += 1) {\n const short = minGapDeg - hueGap(m[i].hue, m[j].hue);\n if (short > 0) p += short;\n }\n }\n }\n if (c.minContrast > 0) {\n for (const x of m) {\n const short = c.minContrast - x.contrast;\n if (short > 0) p += short * 40;\n }\n }\n // Distances are small numbers in OKLab (0.10 already reads as two colors),\n // so they are weighted up to sit on the same scale as degrees of crowding.\n if (c.minSurfaceDistance > 0) {\n for (const x of m) {\n const short = c.minSurfaceDistance - x.surfaceDistance;\n if (short > 0) p += short * 400;\n }\n }\n if (c.minDistance > 0) {\n for (let i = 0; i < m.length; i += 1) {\n for (let j = i + 1; j < m.length; j += 1) {\n const short = c.minDistance - between(m[i].lab, m[j].lab);\n if (short > 0) p += short * 400;\n }\n }\n }\n return p;\n };\n const score = (free: number[]) => {\n const m = metaFor(free);\n return m.reduce((sum, x) => sum + x.chroma, 0) / m.length;\n };\n if (freeCount === 0) return penalty([]) > 0 ? null : [];\n\n const seeds: number[][] = [];\n const seedStep = Math.max(6, Math.round(freeCount * 1.6));\n for (let start = 0; start < 360; start += seedStep) {\n seeds.push(Array.from({ length: freeCount }, (_, i) => Math.round((start + (i * 360) / freeCount) % 360)));\n }\n if (anchorHues.length > 0) {\n // A uniform ring can never open a 2 * minHueGap hole around a pinned hue,\n // so also seed across the arc the anchors leave free.\n const base = anchorHues[0];\n const span = 360 - 2 * Math.max(minGapDeg, 1);\n for (let jitter = -8; jitter <= 8; jitter += 2) {\n for (const divisor of [Math.max(1, freeCount - 1), freeCount]) {\n seeds.push(\n Array.from({ length: freeCount }, (_, i) =>\n Math.round((((base + minGapDeg + jitter + (i * span) / divisor) % 360) + 360) % 360),\n ),\n );\n }\n }\n }\n\n const STEPS = [-16, -8, -4, -2, -1, 1, 2, 4, 8, 16];\n\n /**\n * Everything one position contributes to the penalty: its own shortfalls plus\n * the pairs it takes part in.\n *\n * `descend` moves exactly one hue at a time, so recomputing the whole set for\n * each candidate costs O(n^2) to learn about O(n) changed terms. Scoring the\n * moved position alone is what keeps the count slider live at 16 colors.\n */\n const penaltyAt = (m: readonly Placed[], i: number): number => {\n let p = 0;\n const x = m[i];\n if (c.minContrast > 0) {\n const short = c.minContrast - x.contrast;\n if (short > 0) p += short * 40;\n }\n if (c.minSurfaceDistance > 0) {\n const short = c.minSurfaceDistance - x.surfaceDistance;\n if (short > 0) p += short * 400;\n }\n for (let j = 0; j < m.length; j += 1) {\n if (j === i) continue;\n if (minGapDeg > 0) {\n const short = minGapDeg - hueGap(x.hue, m[j].hue);\n if (short > 0) p += short;\n }\n if (c.minDistance > 0) {\n const short = c.minDistance - between(x.lab, m[j].lab);\n if (short > 0) p += short * 400;\n }\n }\n return p;\n };\n\n const descend = (hues: number[], useChroma: boolean, keepLegal: boolean) => {\n const current = [...hues];\n let meta = metaFor(current);\n const offset = anchorMeta.length;\n for (let iteration = 0; iteration < 120; iteration += 1) {\n let improved = false;\n for (let i = 0; i < freeCount; i += 1) {\n const slot = offset + i;\n const beforeP = penaltyAt(meta, slot);\n const beforeC = meta[slot].chroma;\n for (const delta of STEPS) {\n const next = (((current[i] + delta) % 360) + 360) % 360;\n if (next === current[i]) continue;\n const candidate = at(next);\n const trialMeta = meta.slice();\n trialMeta[slot] = candidate;\n const afterP = penaltyAt(trialMeta, slot);\n const better = useChroma\n ? (keepLegal ? afterP <= beforeP : true) && candidate.chroma > beforeC\n : afterP < beforeP;\n if (!better) continue;\n if (keepLegal && afterP > beforeP) continue;\n current[i] = next;\n meta = trialMeta;\n improved = true;\n break;\n }\n }\n if (!improved) break;\n }\n return current;\n };\n\n let best: number[] | null = null;\n let bestScore = -1;\n for (const seed of seeds) {\n const repaired = penalty(seed) > 0 ? descend(seed, false, false) : seed;\n if (penalty(repaired) > 0) continue;\n const tuned = descend(repaired, true, true);\n if (penalty(tuned) > 0) continue;\n const s = score(tuned);\n if (s > bestScore) {\n bestScore = s;\n best = tuned;\n }\n }\n return best;\n}\n\n/** Closest any two colors in the set look. */\nfunction pairwiseMin(hexes: string[]): number {\n if (hexes.length < 2) return 1;\n let min = Infinity;\n for (let i = 0; i < hexes.length; i += 1) {\n for (let j = i + 1; j < hexes.length; j += 1) min = Math.min(min, deltaE(hexes[i], hexes[j]));\n }\n return min;\n}\n\nfunction summarize(swatches: Swatch[], surface: string): Stats {\n const cs = swatches.map((s) => s.lch.C);\n const ls = swatches.map((s) => s.lch.L);\n let gap = 360;\n for (let i = 0; i < swatches.length; i += 1) {\n for (let j = i + 1; j < swatches.length; j += 1) {\n gap = Math.min(gap, hueGap(swatches[i].lch.H, swatches[j].lch.H));\n }\n }\n return {\n meanChroma: cs.reduce((a, b) => a + b, 0) / (cs.length || 1),\n chromaSpread: Math.max(...cs) - Math.min(...cs),\n lightnessSpread: Math.max(...ls) - Math.min(...ls),\n minHueGap: swatches.length > 1 ? gap : 360,\n hueFloorShare: swatches.length > 1 ? (gap * swatches.length) / 360 : 1,\n minContrast: Math.min(...swatches.map((s) => contrast(s.hex, surface))),\n minSurfaceDistance: Math.min(...swatches.map((s) => deltaE(s.hex, surface))),\n minDistance: pairwiseMin(swatches.map((s) => s.hex)),\n };\n}\n\n/**\n * A categorical palette of `count` swatches, anchors included, satisfying the gates. When no hue arrangement\n * satisfies them the result is still a full palette, with `feasible` false.\n */\nexport function generate(c: Constraints): Palette {\n const found = searchHues(c);\n const feasible = found !== null;\n // An infeasible gate still has to draw something, so fall back to an even ring.\n const free =\n found ??\n Array.from({ length: Math.max(0, c.count - c.anchors.length) }, (_, i) =>\n Math.round((i * 360) / Math.max(1, c.count - c.anchors.length)),\n );\n\n const hues = [...c.anchors.map((a) => a.hue), ...free];\n const anchoredFlags = [...c.anchors.map(() => true), ...free.map(() => false)];\n const raw = [\n ...c.anchors.map(toHexPreview),\n ...free.map((h) => place(h, c)),\n ];\n const hexes = equalizeChroma(raw, c.equalize, anchoredFlags);\n\n const order =\n c.order === 'farthest'\n ? farthestFirst(hues)\n : [...hues.keys()].sort((a, b) => hues[a] - hues[b]);\n\n const names = uniqueNames(order.map((i) => toLch(hexes[i]).H));\n const swatches: Swatch[] = order.map((i, position) => ({\n name: c.anchors[i]?.name ?? names[position],\n hex: hexes[i],\n lch: toLch(hexes[i]),\n anchored: anchoredFlags[i],\n contrast: contrast(hexes[i], c.surface),\n }));\n\n return { swatches, stats: summarize(swatches, c.surface), feasible };\n}\n\n/** What the lab opens with: the set this palette work landed on. */\nexport const DEFAULT_CONSTRAINTS: Constraints = {\n count: 10,\n hueFloor: 0.9,\n minContrast: 4,\n surface: '#181a1e',\n lightnessTarget: 0.72,\n lightnessPull: 0.4,\n chromaFraction: 0.95,\n equalize: 0,\n minSurfaceDistance: 0.25,\n minDistance: 0.22,\n anchors: [],\n order: 'farthest',\n};\n\n/** The color an anchor will actually contribute, for a swatch beside its controls. */\nexport function toHexPreview(a: Pick<Anchor, 'hue' | 'lightness' | 'chroma'>): string {\n const cap = chromaCap(a.lightness, a.hue);\n return toHex(a.lightness, a.chroma === undefined ? cap : Math.min(a.chroma, cap), a.hue);\n}\n\n/**\n * An anchor taken from an existing color — a brand hex, or a color lifted from\n * somewhere else in the theme. Lightness comes along with the hue, which is the\n * point: the reason to pin a color is usually that the lightness law would not\n * have chosen its lightness. `name` defaults to the hue's {@link hueName}.\n */\nexport function anchorFromHex(hex: string, name?: string): Anchor {\n const { L, C, H } = toLch(hex);\n return {\n name: name ?? hueName(H),\n hue: Math.round(H),\n lightness: Number(L.toFixed(3)),\n chroma: Number(C.toFixed(4)),\n };\n}\n\n"]}
@@ -0,0 +1,245 @@
1
+ import { themeAxes, resolveTheme, atAlpha, withAlpha, themeChain, generate, DEFAULT_CONSTRAINTS } from './chunk-2PY2YTDY.js';
2
+ import { weaselTheme } from './chunk-JX2OC444.js';
3
+ import { fullSelection } from './chunk-P5F3GZV6.js';
4
+ import { resolvePaletteColor, colorLiteralToCss, cssColorLiteral } from '@weasel-js/paint';
5
+
6
+ // src/themeSheet.ts
7
+ var STYLE_ID = "wzl-themes";
8
+ var sheets = /* @__PURE__ */ new WeakMap();
9
+ function styleRootOf(el) {
10
+ const root = el.getRootNode();
11
+ return root instanceof (el.ownerDocument.defaultView?.ShadowRoot ?? ShadowRoot) ? root : el.ownerDocument;
12
+ }
13
+ var documentOf = (root) => "host" in root ? root.ownerDocument : root;
14
+ var only = (id) => id === 0 ? "" : `:where([data-wzl-variant='${id}'])`;
15
+ function write(root, held) {
16
+ const css = [...held.rules].flatMap(([selector, variants]) => (
17
+ // The bare rule first: it matches a variant's elements too, and the variant's has to win the tie.
18
+ [...variants].sort((a, b) => a.id - b.id).map((v) => `${selector}${only(v.id)} { ${v.body} }`)
19
+ )).join("\n");
20
+ const win = documentOf(root).defaultView;
21
+ const Sheet = win?.CSSStyleSheet;
22
+ if (Sheet && "replaceSync" in Sheet.prototype && Array.isArray(root.adoptedStyleSheets)) {
23
+ if (!held.sheet) {
24
+ held.sheet = new Sheet();
25
+ root.adoptedStyleSheets = [...root.adoptedStyleSheets, held.sheet];
26
+ }
27
+ held.sheet.replaceSync(css);
28
+ return;
29
+ }
30
+ if (!held.styleEl) {
31
+ held.styleEl = documentOf(root).createElement("style");
32
+ held.styleEl.id = STYLE_ID;
33
+ ("host" in root ? root : root.head).appendChild(held.styleEl);
34
+ }
35
+ held.styleEl.textContent = css;
36
+ }
37
+ function holdRule(root, selector, body) {
38
+ let held = sheets.get(root);
39
+ if (!held) sheets.set(root, held = { rules: /* @__PURE__ */ new Map(), sheet: null, styleEl: null });
40
+ const variants = held.rules.get(selector) ?? [];
41
+ let variant = variants.find((v) => v.body === body);
42
+ if (variant) {
43
+ variant.holds++;
44
+ } else {
45
+ let id = 0;
46
+ while (variants.some((v) => v.id === id)) id++;
47
+ variant = { id, body, holds: 1 };
48
+ held.rules.set(selector, [...variants, variant]);
49
+ write(root, held);
50
+ }
51
+ const mine = variant;
52
+ const sheet = held;
53
+ let released = false;
54
+ return {
55
+ variant: mine.id,
56
+ release: () => {
57
+ if (released) return;
58
+ released = true;
59
+ if (--mine.holds > 0) return;
60
+ const left = (sheet.rules.get(selector) ?? []).filter((v) => v !== mine);
61
+ if (left.length > 0) sheet.rules.set(selector, left);
62
+ else sheet.rules.delete(selector);
63
+ write(root, sheet);
64
+ }
65
+ };
66
+ }
67
+
68
+ // src/applyTheme.ts
69
+ var holds = /* @__PURE__ */ new WeakMap();
70
+ function applyTheme(el, theme, selection = {}) {
71
+ if (typeof document === "undefined") return () => {
72
+ };
73
+ const axes = themeAxes(theme);
74
+ const sel = fullSelection(axes, selection);
75
+ const body = Object.entries(resolveTheme(theme, sel)).map(([name, value]) => `${name}: ${value};`).join(" ");
76
+ const names = Object.keys(axes);
77
+ const selector = `[data-wzl-theme='${theme.name}']${names.map((a) => `[data-wzl-${a}='${sel[a]}']`).join("")}`;
78
+ const { variant, release: releaseRule } = holdRule(styleRootOf(el), selector, body);
79
+ holds.get(el)?.();
80
+ el.setAttribute("data-wzl-theme", theme.name);
81
+ for (const a of names) el.setAttribute(`data-wzl-${a}`, sel[a]);
82
+ if (variant === 0) el.removeAttribute("data-wzl-variant");
83
+ else el.setAttribute("data-wzl-variant", String(variant));
84
+ const letGo = () => {
85
+ holds.delete(el);
86
+ releaseRule();
87
+ };
88
+ holds.set(el, letGo);
89
+ return () => {
90
+ if (holds.get(el) !== letGo) return;
91
+ letGo();
92
+ for (const a of ["theme", "variant", ...names]) el.removeAttribute(`data-wzl-${a}`);
93
+ };
94
+ }
95
+
96
+ // src/currentColor.ts
97
+ var NUMBER = String.raw`(\d*\.?\d+)(%?)`;
98
+ var RELATIVE = new RegExp(String.raw`^rgb\(\s*from\s+currentcolor\s+r\s+g\s+b\s*/\s*${NUMBER}\s*\)$`, "i");
99
+ var MIX = new RegExp(String.raw`^color-mix\(\s*in\s+[\w-]+\s*,\s*currentcolor\s+${NUMBER}\s*,\s*transparent\s*\)$`, "i");
100
+ var fraction = (n, pct) => Number(n) / (pct ? 100 : 1);
101
+ function resolveCurrentColor(value, current) {
102
+ const v = value.trim();
103
+ if (!/currentcolor/i.test(v)) return value;
104
+ if (/^currentcolor$/i.test(v)) return current;
105
+ const rel = RELATIVE.exec(v);
106
+ if (rel) return atAlpha(current, fraction(rel[1], rel[2]));
107
+ const mix = MIX.exec(v);
108
+ if (mix && mix[2] === "%") return withAlpha(current, fraction(mix[1], mix[2]));
109
+ throw new Error(`resolveCurrentColor: cannot flatten "${value}"`);
110
+ }
111
+
112
+ // src/colorMode.ts
113
+ function isColorModePreference(v) {
114
+ return v === "auto" || v === "light" || v === "dark";
115
+ }
116
+
117
+ // src/colorListItems.ts
118
+ var wrap = (i, n) => (Math.trunc(i) % n + n) % n;
119
+ var generated = /* @__PURE__ */ new Map();
120
+ function generatedColors({ generate: g }) {
121
+ const key = JSON.stringify([g.count, g.gates ?? {}]);
122
+ let colors = generated.get(key);
123
+ if (!colors) {
124
+ const palette = generate({ ...DEFAULT_CONSTRAINTS, ...g.gates, count: g.count, anchors: [] });
125
+ colors = palette.swatches.map((s) => s.hex.toLowerCase());
126
+ generated.set(key, colors);
127
+ }
128
+ return colors;
129
+ }
130
+ function findRampSteps(theme, ramp) {
131
+ for (const t of themeChain(theme).reverse()) {
132
+ const steps = t.ramps?.[ramp];
133
+ if (steps) return steps;
134
+ }
135
+ return void 0;
136
+ }
137
+ function rampSteps(theme, ramp) {
138
+ const steps = findRampSteps(theme, ramp);
139
+ if (!steps) throw new Error(`Theme "${theme.name}" has no ramp "${ramp}"`);
140
+ return steps;
141
+ }
142
+ function themeTones(theme) {
143
+ for (const t of themeChain(theme).reverse()) if (t.tones) return t.tones;
144
+ return { ramp: "swatch" };
145
+ }
146
+ var fallback;
147
+ var defaultContext = () => fallback ??= { theme: weaselTheme, resolved: resolveTheme(weaselTheme) };
148
+ var pickStep = (list, i, theme) => {
149
+ const steps = rampSteps(theme, list.ramp);
150
+ return steps[wrap(i, steps.length)];
151
+ };
152
+ var rampProperty = (list, i, theme) => `--wzl-${list.ramp}-${pickStep(list, i, theme)}`;
153
+ var isRamp = (list) => typeof list !== "function" && "ramp" in list;
154
+ function colorItemAt(list, i) {
155
+ if (typeof list === "function") return list(i);
156
+ const colors = "generate" in list ? generatedColors(list) : list;
157
+ if (colors.length === 0) throw new Error("colorAt: empty color list");
158
+ return colors[wrap(i, colors.length)];
159
+ }
160
+ function colorCount(list, ctx = defaultContext()) {
161
+ if (typeof list === "function") return void 0;
162
+ if ("ramp" in list) return rampSteps(ctx.theme, list.ramp).length;
163
+ return "generate" in list ? list.generate.count : list.length;
164
+ }
165
+ var TONE_REF = "tone";
166
+ var NO_PALETTE = { entries: [] };
167
+ var tonesOf = (ctx) => ctx.tones ?? themeTones(ctx.theme);
168
+ function parsed(css) {
169
+ try {
170
+ return cssColorLiteral(css);
171
+ } catch {
172
+ return null;
173
+ }
174
+ }
175
+ function propertyOf(ref, ctx) {
176
+ if (ref.ref.startsWith("--")) return ref.index === void 0 ? ref.ref : null;
177
+ if (ref.index === void 0) return `--wzl-${ref.ref}`;
178
+ const step = findRampSteps(ctx.theme, ref.ref)?.[ref.index];
179
+ return step === void 0 ? null : `--wzl-${ref.ref}-${step}`;
180
+ }
181
+ function tokenLiteral(property, ctx) {
182
+ const value = ctx.resolved[property];
183
+ if (value === void 0) return null;
184
+ try {
185
+ return parsed(resolveCurrentColor(value, ctx.resolved["--wzl-fg"]));
186
+ } catch {
187
+ return null;
188
+ }
189
+ }
190
+ var isRef = (source) => typeof source !== "function" && "ref" in source;
191
+ function toneSource(index, ctx) {
192
+ const tones = tonesOf(ctx);
193
+ if (isRamp(tones)) return tokenLiteral(rampProperty(tones, index, ctx.theme), ctx);
194
+ const item = colorItemAt(tones, index);
195
+ return typeof item === "string" ? parsed(item) : item;
196
+ }
197
+ function themeSource(ref, ctx) {
198
+ if (ref.ref === TONE_REF) return toneSource(ref.index ?? 0, ctx);
199
+ const property = propertyOf(ref, ctx);
200
+ return property === null ? null : tokenLiteral(property, ctx);
201
+ }
202
+ function colorSourceLiteral(source, ctx = defaultContext()) {
203
+ return resolvePaletteColor(ctx.palette ?? NO_PALETTE, source, (ref) => themeSource(ref, ctx));
204
+ }
205
+ function literalCss(source, ctx) {
206
+ const literal = colorSourceLiteral(source, ctx);
207
+ return literal && colorLiteralToCss(literal);
208
+ }
209
+ function toneCss(source, ctx) {
210
+ const tones = tonesOf(ctx);
211
+ const index = source.index ?? 0;
212
+ if (isRamp(tones)) return `var(${rampProperty(tones, index, ctx.theme)})`;
213
+ const item = colorItemAt(tones, index);
214
+ if (typeof item === "string") return item;
215
+ return isRef(item) && item.ref !== TONE_REF ? colorSourceCss(item, ctx) : literalCss(source, ctx);
216
+ }
217
+ function colorSourceCss(source, ctx = defaultContext()) {
218
+ if (isRef(source) && !ctx.palette?.entries.some((e) => e.name === source.ref)) {
219
+ if (source.ref === TONE_REF) return toneCss(source, ctx);
220
+ const property = propertyOf(source, ctx);
221
+ if (property === null) return null;
222
+ return source.ref.startsWith("--") || tokenLiteral(property, ctx) ? `var(${property})` : null;
223
+ }
224
+ return literalCss(source, ctx);
225
+ }
226
+ function answered(css, i) {
227
+ if (css === null) throw new Error(`colorAt: nothing answers item ${i} of the color list`);
228
+ return css;
229
+ }
230
+ function colorAt(list, i, ctx = defaultContext()) {
231
+ if (isRamp(list)) return ctx.resolved[rampProperty(list, i, ctx.theme)];
232
+ const item = colorItemAt(list, i);
233
+ if (typeof item === "string") return item;
234
+ const literal = colorSourceLiteral(item, ctx);
235
+ return answered(literal && colorLiteralToCss(literal), i);
236
+ }
237
+ function colorCssAt(list, i, ctx = defaultContext()) {
238
+ if (isRamp(list)) return `var(${rampProperty(list, i, ctx.theme)})`;
239
+ const item = colorItemAt(list, i);
240
+ return typeof item === "string" ? item : answered(colorSourceCss(item, ctx), i);
241
+ }
242
+
243
+ export { TONE_REF, applyTheme, colorAt, colorCount, colorCssAt, colorSourceCss, colorSourceLiteral, isColorModePreference, rampSteps, resolveCurrentColor, themeTones };
244
+ //# sourceMappingURL=chunk-3NIEJ77B.js.map
245
+ //# sourceMappingURL=chunk-3NIEJ77B.js.map