@designtools/tokens 0.13.0 → 0.15.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/CHANGELOG.md CHANGED
@@ -2,6 +2,25 @@
2
2
 
3
3
  Notable changes to `@designtools/tokens`. Dates are release dates; versions follow semver, with breaking changes in the minor slot while the package is pre-1.0.
4
4
 
5
+ ## 0.15.0
6
+
7
+ ### Minor Changes
8
+
9
+ - 41dd086: The scale is written once and owned by the project; the colour has one checked place for overrides; one command sets a project up.
10
+
11
+ - **`generate-tokens scale --init`** writes the non-colour scale once, with a header marking it the project's own, then refuses to write over it (`--force` rewrites, after listing what changes). Nothing regenerates it and no overrides file tracks it. **`scale --verify <file>`** checks its names against the contract: every default name kept, every added name inside a tier's namespace; values are never compared. Regenerating without `--init`, and `scale --check`, still work and warn. Exported: `verifyScale`, `isOwnedScale`, `ownedScaleHeader`, `OWNED_SCALE_MARK`.
12
+ - **`--local <file>`**: the project's colour overrides (`tokens.local.css`), checked on every run. Only the generator's selectors, only its token names (never a `--color-*` alias, ramp step or new name), and values that point at the system (`var()`, or a ramp step nudged with relative colour), never a literal colour. Every override is listed as pinned by hand, and each pair it touches is re-checked for contrast at `--target`. Exit 1 on any problem. Exported: `checkLocalOverrides`.
13
+ - **`generate-tokens init`** writes `tokens.css`, an empty `tokens.local.css` and the owned `scale.css` in `--dir` (default `app/styles`), and with `--entry` adds their imports to a stylesheet, in order. Run again, it keeps the scale and the overrides and regenerates the colour.
14
+ - **`designtools-manifest check`** holds an owned scale to the same contract, so it is checked on every commit. A project without one is told how to make one, not failed.
15
+ - `--help`: the `--only grounds` line names the `[data-surface]` scopes it writes, not the `--on-*` tokens 0.12 stopped writing.
16
+
17
+ ## 0.14.0
18
+
19
+ ### Minor Changes
20
+
21
+ - 7cb5385: Grounds choose their panels apart from their lines: `--ground-panels` (or `panels` on a ground, `groundPanels` in a seed) sets where the card (`--surface`) and the quiet panel (`--neutral-subdued`) come from: `own`, `page`, or one colour. Unset, panels follow the lines as before, so generated output is unchanged. The studio's "Lines and panels" control is now two, Lines and Panels.
22
+ - ea9c73d: A colour seeded away from 500 keeps the spacing a typical ramp has around its step. Before, the 500 curve was stretched over the new steps, so the step next to a deep seed always sat 38% of the way to white: `#0e2436` at 900 had an 800 at lightness 53 against its own 25. Now its 800 is 35. Ramps seeded on 500 are unchanged; every other ramp shifts on regeneration, most near the seed, and the palest and deepest steps still reach the lightness range.
23
+
5
24
  ## 0.13.0
6
25
 
7
26
  ### Minor Changes
package/README.md CHANGED
@@ -59,6 +59,7 @@ Two pairs of words look alike and aren't:
59
59
  | a success, warning or error banner | the page's `-subdued` tokens (`bg-success-subdued text-success-subdued-foreground`); no ground |
60
60
  | white lines, edges and focus ring on a dark band, text as usual | a ground with `--ground-tint white` (text on a dark ground is white anyway) |
61
61
  | lines and panels in a band's own hue, text in the page's | a ground, as it comes (`tint own`, `text page`) |
62
+ | the page's white cards on a coloured band, its lines in the band's hue | `--ground-panels <name>=page` |
62
63
  | the page's pale brand button kept as it is on a band | `--ground-action <name>=page` |
63
64
  | a band's button in another colour (ink on a yellow band) | `--ground-action <name>=neutral-950`, its label after a slash if you name it |
64
65
  | a card inside a band that reads as the page again | `data-surface="canvas"` on the card |
@@ -184,15 +185,15 @@ A **ground** is a section painted one step of a ramp: a deep green band, a lime
184
185
  }
185
186
  ```
186
187
 
187
- **Two choices per ground say where its tokens come from**, one for its text and one for everything else, its tint:
188
+ **Three choices per ground say where its tokens come from**: its text, its lines (its tint, which the buttons follow) and its panels:
188
189
 
189
- | Value | Text (`--ground-text`: body and secondary text) | Tint (`--ground-tint`: lines, panels, card, input, ring, buttons) |
190
- | --- | --- | --- |
191
- | `page` | the page's text wherever it reads on the ground; white or black where it doesn't. Muted text the page's, or the neutral's nearest that reads | the page's own lines, panels, input and ring |
192
- | `own` | steps from the ground's ramp, searched to the text floors | steps from the ground's ramp, each searched to its floor: a deeper green line on green |
193
- | one colour: `white`, `black`, or a step (`sage-100`) | that colour for body and secondary text both (the report says secondary text is then no quieter) | as `own`, with that colour for every line, edge and ring: white lines on deep green, its panels and card still green |
190
+ | Value | Text (`--ground-text`: body and secondary text) | Lines (`--ground-tint`: border, input edge, ring, buttons) | Panels (`--ground-panels`: the card, `--surface`, and the quiet panel, `--neutral-subdued`) |
191
+ | --- | --- | --- | --- |
192
+ | `page` | the page's text wherever it reads on the ground; white or black where it doesn't. Muted text the page's, or the neutral's nearest that reads | the page's own lines, input and ring | the page's card and quiet panel |
193
+ | `own` | steps from the ground's ramp, searched to the text floors | steps from the ground's ramp, each searched to its floor: a deeper green line on green | a step off the ground on its ramp, as far from it as the page's card is from the page: a lighter green card on deep green |
194
+ | one colour: `white`, `black`, or a step (`sage-100`) | that colour for body and secondary text both (the report says secondary text is then no quieter) | as `own`, with that colour for every line, edge and ring: white lines on deep green | that colour for the card and the quiet panel, their text the ground's where it reads and white or black where it doesn't. The report notes a card that doesn't draw against the ground |
194
195
 
195
- Defaults: `text page`, `tint own`. So text is one standard set across a site, and lines and panels take each ground's hue. A bare value sets every ground; `<name>=<value>` sets one and wins: `--ground-tint own --ground-tint pine=white`. In a seed: `"grounds": { "pine": { "ramp": "pine", "step": 800, "tint": "white" } }`, `"groundTint"`, `"groundText"`.
196
+ Defaults: `text page`, `tint own`, and panels unset, which follow the lines: the page's under `tint page`, the ground's own otherwise. So text is one standard set across a site, and lines and panels take each ground's hue. A bare value sets every ground; `<name>=<value>` sets one and wins: `--ground-tint own --ground-tint pine=white`. In a seed: `"grounds": { "pine": { "ramp": "pine", "step": 800, "tint": "white", "panels": "page" } }`, `"groundTint"`, `"groundPanels"`, `"groundText"`.
196
197
 
197
198
  **Buttons and other colours keep the page's value unless it fails.** The primary and secondary buttons, accent, success, error and warning are the page's wherever they stand out from the ground (3:1 for a fill, with a label that reads on it). One that doesn't is searched along its own ramp: a navy button on deep green moves to a step that shows. Under `tint own` (and one colour) the primary button is drawn from the ground's ramp (on its own colour it turns over: the deepest step with the ground's colour in its label), and the secondary button is tonal: a tint of the ground's hue whose label carries it.
198
199
 
@@ -307,6 +308,8 @@ This is deliberately a **dumb, deterministic tool** — no model, no network, no
307
308
  - **`--ramps` + `--merge` for partial regeneration.** Change one colour in a file a human has also edited, without rewriting their work. See [Regenerating part of a token file](#regenerating-part-of-a-token-file).
308
309
  - **`--only` for tier-level slicing.** Keep generated colour in a different file from anything hand-tuned.
309
310
  - **`--seed` / `--stdin`** to replay a whole configuration from JSON instead of assembling flags.
311
+ - **`--local` for overrides.** The one place for a colour a flag can't say, checked against the system and against contrast on every run. See [Overriding the colour](#overriding-the-colour).
312
+ - **`init` for a new project.** The colour, the override file and the scale, wired in, in one step. See [Setting a project up](#setting-a-project-up).
310
313
 
311
314
  Generated files carry a provenance header naming the version and a hash of the inputs, so an agent can tell "the generator was upgraded" apart from "a human edited this":
312
315
 
@@ -326,14 +329,54 @@ check: tokens.css differs — same generator and seed, so the file was edited by
326
329
  check: tokens.css differs — generated by v0.4.0, running v0.5.0. Expected after a generator upgrade.
327
330
  ```
328
331
 
332
+ ## Setting a project up
333
+
334
+ One command sets a project's tokens up, so none starts without the scale or invents its own way of overriding the colour:
335
+
336
+ ```bash
337
+ npx @designtools/tokens init --primary "#4e9caf" --dir app/styles --entry app/styles/globals.css
338
+ ```
339
+
340
+ It writes three files in `--dir` (default `app/styles`) and, with `--entry`, adds their imports to a stylesheet after Tailwind's own, in the order they cascade:
341
+
342
+ | File | What it is | Who changes it |
343
+ | --- | --- | --- |
344
+ | `tokens.css` | The colour, generated from the flags | The generator, every run; `--check` in CI |
345
+ | `tokens.local.css` | The project's overrides of that colour, empty to start | The project, held to the system's terms; checked every run |
346
+ | `scale.css` | Everything that isn't colour, written once | The project, by hand; the names checked by `designtools-manifest check` |
347
+
348
+ Every other flag goes to the colour run, as it would without `init`. Run again, `init` keeps the scale and the override file (they are the project's) and regenerates the colour.
349
+
350
+ ## Overriding the colour
351
+
352
+ Most changes are an input: a flag, the seed, shade overrides. For the few a flag can't say, there is one place, `tokens.local.css`, loaded straight after `tokens.css`, and the generator holds it to the system's own terms on every run (`--local <file>`; `init` passes it for you):
353
+
354
+ - **Selectors are the generator's own:** `:root`, `[data-theme="light"]`, `[data-theme="dark"]`, `.dark` and `[data-surface="<ground>"]`, alone or in a list. No at-rules.
355
+ - **Names are tokens the generator writes:** never a `--color-*` alias or ramp step (move a step with shade overrides; set a token by its own name), and never a new name. A name of the project's own belongs in its own stylesheet.
356
+ - **Values point at the system:** `var()` references, or a ramp step nudged with relative colour, never a literal colour.
357
+
358
+ ```css
359
+ /* tokens.local.css */
360
+ [data-surface="navy"] {
361
+ --surface: oklch(from var(--color-navy-800) calc(l + 0.07) c h);
362
+ }
363
+ ```
364
+
365
+ Each override is listed as pinned by hand, and every pair it touches (a surface and the text set on it) is re-checked for contrast at `--target`, so a pinned card can't quietly fail its text. Any problem exits 1:
366
+
367
+ ```
368
+ local: pinned by hand: --surface in [data-surface="navy"]
369
+ local: tokens.local.css keeps to the system (1 pinned)
370
+ local: tokens.local.css: --surface-foreground-secondary on --surface in [data-surface="lime"]: 4.24:1, under 4.5:1
371
+ ```
372
+
329
373
  ## The scale: everything that isn't colour
330
374
 
331
- Colour comes from a seed; the rest of a system has none, so `generate-tokens scale` writes a set of defaults, in the same formats, for a project to retune with overrides:
375
+ Colour comes from a seed; the rest of a system has none, and its values are art direction. So the scale is written once, as defaults to start from, and from then on it is the project's own file: edited by hand, never regenerated, and tracked by no overrides file.
332
376
 
333
377
  ```bash
334
- npx @designtools/tokens scale --format tailwind-v4 --overrides scale.overrides.json --out app/styles/scale.css
335
- npx @designtools/tokens scale --format css --out src/styles/scale.css
336
- npx @designtools/tokens scale --format all --out ./tokens # css, tailwind-v3, dtcg, json
378
+ npx @designtools/tokens scale --init --format tailwind-v4 --out app/styles/scale.css
379
+ npx @designtools/tokens scale --verify app/styles/scale.css
337
380
  ```
338
381
 
339
382
  | Tier | Tokens | What it is |
@@ -347,15 +390,11 @@ npx @designtools/tokens scale --format all --out ./tokens # css, tailwind-v3,
347
390
  | Screen sizes | `--breakpoint-sm` … `--breakpoint-2xl` | Where a page can change shape, from each size up |
348
391
  | Widths | `--container-3xs` … `--container-7xl` | The widths content is set to |
349
392
 
350
- The names are the contract and the values are art direction: override values, keep the names. The names are Tailwind v4's theme namespaces, so on Tailwind each is a utility as well, and on any other stack a plain custom property. Screen sizes are the one tier a variable can't carry, since CSS can't read one in `@media`: `--format css` writes them as `@custom-media` too (compiled by Lightning CSS or postcss-preset-env), and DTCG, JSON and Tailwind v3 carry them as values. A page's grid is composed from these, widths, screen sizes and space, rather than named as tokens of its own.
393
+ The values are the project's; **the names are the contract.** Keep every name, and add new ones only inside a tier's namespace (a section step is `--spacing-section`, a page width `--container-measure`), never a system of their own beside it. `--verify`, and `designtools-manifest check` on every commit, hold a project to that and never compare values. The names are Tailwind v4's theme namespaces, so on Tailwind each is a utility as well, and on any other stack a plain custom property. Screen sizes are the one tier a variable can't carry, since CSS can't read one in `@media`: `--format css` writes them as `@custom-media` too (compiled by Lightning CSS or postcss-preset-env), and DTCG, JSON and Tailwind v3 carry them as values.
351
394
 
352
- `--overrides` is JSON by token name: a value, a value with its description, or `null` to remove one. A new name joins the tier its prefix belongs to, and a name in no tier is an error.
353
-
354
- ```json
355
- { "--radius-md": "0.5rem", "--text-5xl": { "value": "3rem", "description": "48px: page titles" }, "--text-5xl--line-height": "var(--leading-none)", "--leading-relaxed": null }
356
- ```
395
+ `--init` refuses to write over a scale that is already there; `--force` writes over it after listing what changes, for the rare deliberate reset. `--overrides` (JSON by token name: a value, or a value with its description) starts `--init` from other values than the defaults. `--format all` writes css, tailwind-v3, dtcg and json.
357
396
 
358
- `--check` compares against the file at `--out` and exits 1 when it differs, as the colour does.
397
+ **Adopting the owned scale (from 0.13 and before).** A project that regenerates its scale from an overrides file moves once: run `scale --init --force` with its overrides, so the file keeps every value, then delete the overrides file and drop `scale --check` from CI. Regenerating without `--init`, and `--check`, still work, and warn.
359
398
 
360
399
  ## Trying scales live: the studio
361
400
 
@@ -599,7 +638,8 @@ A seed file:
599
638
  | `--canvas`, `--surface`, `--overlay` | `<colour>[/<dark>]` | neutral steps | The page, card and overlay as exact colours, light then dark; text on each is measured. |
600
639
  | `--page-surface` | `<name>=<ramp>@<step>[/<ramp>@<step>]`, or colours | — | Another [page surface](#page-surfaces) beside canvas, surface and overlay, which follows the mode. Dark defaults to the light step's mirror. Repeatable. |
601
640
  | `--ground` | `<name>=<ramp>@<step>` | — | A [ground](#grounds): a section painted that step, the same in both modes, with tokens that work on it inside `data-surface="<name>"`. Repeatable. |
602
- | `--ground-tint` | `own` · `page` · `white` · `black` · `<ramp>-<step>`, or `<name>=<value>` | `own` | Where a ground's lines, panels, card, input, ring and buttons come from. Repeatable; a named value wins. |
641
+ | `--ground-tint` | `own` · `page` · `white` · `black` · `<ramp>-<step>`, or `<name>=<value>` | `own` | Where a ground's lines (border, input edge, ring) and buttons come from. Repeatable; a named value wins. |
642
+ | `--ground-panels` | as `--ground-tint` | unset: follows the lines | Where a ground's card (`--surface`) and quiet panel (`--neutral-subdued`) come from. Repeatable; a named value wins. |
603
643
  | `--ground-text` | as `--ground-tint` | `page` | Where a ground's body and secondary text come from. Repeatable; a named value wins. |
604
644
  | `--ground-action` | `page` · `own` · `white` · `black` · `<ramp>-<step>`, optionally `/<label>`, or `<name>=<value>` | unset: follows the tint | Where a ground's main button and its label come from. Repeatable; a named value wins. |
605
645
  | `--usage <file.json>` | — | — | Also write where each colour can go: every fill, status text tone and secondary text on every background, per mode, as text, shape or neither (`designtools.usage/1`). `@designtools/manifest` turns the failures into measured usage rules. `--check` compares it too. |
@@ -627,7 +667,7 @@ Everything is derived from the headroom above and below the seed, so where it si
627
667
  generate-tokens --primary "#1e3a5f" --seed-shade 600 # a deep navy, one step down for more headroom
628
668
  ```
629
669
 
630
- Your colour is still reproduced exactly, just at the step you name. The ramp keeps its shape — gentle at the light end, larger jumps at the dark end for text contrast — and peak chroma follows the seed.
670
+ Your colour is still reproduced exactly, just at the step you name. The steps either side keep the spacing a typical ramp has around that step: a deep navy at 900 gets an 800 about ten points lighter, as a 900's neighbour is, rather than a 500's 400, a third of the way to white. A seed on 500 makes the same ramp it always did, and peak chroma follows the seed. Before 0.14.0 the 500 curve was stretched over the new steps, so the step next to a deep seed jumped about 28 points whichever step it was on.
631
671
 
632
672
  **Each colour has its own anchor.** `--seed-shade` moves the primary only. The neutral takes `--neutral-seed-shade`, an added colour takes `@<shade>` on `--color`, and the derived status colours, which are built at mid lightness, stay on 500:
633
673
 
@@ -64,27 +64,17 @@ function snapShade(shade2, active) {
64
64
  }
65
65
  return best;
66
66
  }
67
- function sampleCurve(curve, t2) {
68
- if (curve.length === 1) return curve[0];
69
- const pos = t2 * (curve.length - 1);
70
- const i = Math.min(Math.floor(pos), curve.length - 2);
71
- return curve[i] + (curve[i + 1] - curve[i]) * (pos - i);
72
- }
67
+ var TYPICAL = { seed: 0.55, light: 0.98, dark: 0.15 };
73
68
  function reanchorFactors(base, seedShade) {
74
69
  const anchor = VALID_SHADES.indexOf(seedShade);
75
70
  if (anchor === DEFAULT_ANCHOR_INDEX) return [...base];
76
- const lighter = base.slice(0, DEFAULT_ANCHOR_INDEX);
77
- const darker = base.slice(DEFAULT_ANCHOR_INDEX + 1);
78
- const out = new Array(base.length).fill(0);
79
- for (let i = 0; i < anchor; i++) {
80
- out[i] = sampleCurve(lighter, anchor > 1 ? i / (anchor - 1) : 0);
81
- }
82
- out[anchor] = 0;
83
- const below = base.length - 1 - anchor;
84
- for (let j = 0; j < below; j++) {
85
- out[anchor + 1 + j] = sampleCurve(darker, below > 1 ? j / (below - 1) : 1);
86
- }
87
- return out;
71
+ const { seed, light, dark } = TYPICAL;
72
+ const typical = base.map((f) => f >= 0 ? seed + (light - seed) * f : seed + (seed - dark) * f);
73
+ const last = base.length - 1;
74
+ return typical.map((l, i) => {
75
+ if (i === anchor) return 0;
76
+ return i < anchor ? base[0] * ((l - typical[anchor]) / (typical[0] - typical[anchor])) : base[last] * ((typical[anchor] - l) / (typical[anchor] - typical[last]));
77
+ });
88
78
  }
89
79
  function chromaShadeFor(index, seedShade) {
90
80
  const anchor = VALID_SHADES.indexOf(seedShade);
@@ -872,7 +862,7 @@ function generateSurfaceTokens(palette, mode, overrides, shades, colors, pageSur
872
862
  const black = palette.black;
873
863
  const white = palette.white;
874
864
  const defaults = mode === "light" ? { canvas: snap(25), "canvas-foreground": snap(800), surface: "white", "surface-foreground": snap(800), overlay: "white", "overlay-foreground": snap(800) } : { canvas: snap(950), "canvas-foreground": "white", surface: "black", "surface-foreground": "white", overlay: "black", "overlay-foreground": "white" };
875
- function resolve2(key) {
865
+ function resolve3(key) {
876
866
  const raw = overrides?.[key] ?? defaults[key];
877
867
  if (raw === "white") return { value: white, ref: { type: "white" } };
878
868
  if (raw === "black") return { value: black, ref: { type: "black" } };
@@ -881,9 +871,9 @@ function generateSurfaceTokens(palette, mode, overrides, shades, colors, pageSur
881
871
  }
882
872
  const ground = (key) => {
883
873
  const given = colors?.[key];
884
- if (!given) return { bg: resolve2(key), fg: resolve2(`${key}-foreground`) };
874
+ if (!given) return { bg: resolve3(key), fg: resolve3(`${key}-foreground`) };
885
875
  const bg = { value: given, ref: { type: "value", value: given } };
886
- return { bg, fg: overrides?.[`${key}-foreground`] ? resolve2(`${key}-foreground`) : textOn(given, neutral, white, black, activeShades) };
876
+ return { bg, fg: overrides?.[`${key}-foreground`] ? resolve3(`${key}-foreground`) : textOn(given, neutral, white, black, activeShades) };
887
877
  };
888
878
  const { bg: canvas, fg: canvasFg } = ground("canvas");
889
879
  const { bg: surface, fg: surfaceFg } = ground("surface");
@@ -1384,6 +1374,7 @@ function buildGround(name, given, tiers, views, options) {
1384
1374
  const light = cr(ground, { type: "black" }) > cr(ground, { type: "white" });
1385
1375
  const polarity = light ? "light" : "dark";
1386
1376
  const tint = given.tint ?? options?.groundTint ?? "own";
1377
+ const panels = given.panels ?? options?.groundPanels ?? (tint === "page" ? "page" : "own");
1387
1378
  const text = given.text ?? options?.groundText ?? "page";
1388
1379
  const action = given.action ?? options?.groundAction;
1389
1380
  const notes = [];
@@ -1403,8 +1394,8 @@ function buildGround(name, given, tiers, views, options) {
1403
1394
  body = fillRef(text, srgb);
1404
1395
  }
1405
1396
  if (cr(body, ground) < textFloor) notes.push(`canvas-foreground: ${cr(body, ground).toFixed(2)}:1, under ${textFloor}:1`);
1406
- const searched = searchGround(
1407
- { name, canvas: ground, foreground: body, family: tint === "page" ? "neutral" : given.ramp, textFamily: text === "own" ? given.ramp : "neutral", ramp: given.ramp, ...action ? { action } : {} },
1397
+ const search = (family) => searchGround(
1398
+ { name, canvas: ground, foreground: body, family, textFamily: text === "own" ? given.ramp : "neutral", ramp: given.ramp, ...action ? { action } : {} },
1408
1399
  base,
1409
1400
  page.canvas,
1410
1401
  colors,
@@ -1413,10 +1404,11 @@ function buildGround(name, given, tiers, views, options) {
1413
1404
  options,
1414
1405
  active
1415
1406
  );
1407
+ const searched = search(tint === "page" ? "neutral" : given.ramp);
1416
1408
  const refs = searched.refs;
1417
1409
  notes.push(...searched.notes);
1418
1410
  if (tint === "page") {
1419
- for (const token of ["neutral-subdued", "neutral-subdued-foreground", "border", "input", "ring"]) refs[token] = page[token];
1411
+ for (const token of ["border", "input", "ring"]) refs[token] = page[token];
1420
1412
  } else if (tint !== "own") {
1421
1413
  const one = fillRef(tint, srgb);
1422
1414
  refs.border = one;
@@ -1428,15 +1420,30 @@ function buildGround(name, given, tiers, views, options) {
1428
1420
  if (cr(refs[token], ground) < FILL_FLOOR) notes.push(`${token}: ${cr(refs[token], ground).toFixed(2)}:1, under ${FILL_FLOOR}:1`);
1429
1421
  }
1430
1422
  }
1423
+ if (panels === "page") {
1424
+ for (const token of ["neutral-subdued", "neutral-subdued-foreground"]) refs[token] = page[token];
1425
+ } else if (panels === "own") {
1426
+ if (tint === "page") {
1427
+ const own = search(given.ramp).refs;
1428
+ for (const token of ["neutral-subdued", "neutral-subdued-foreground"]) refs[token] = own[token];
1429
+ }
1430
+ } else {
1431
+ const one = fillRef(panels, srgb);
1432
+ refs["neutral-subdued"] = one;
1433
+ refs["neutral-subdued-foreground"] = cr(body, one) >= textFloor ? body : bestEnd(one);
1434
+ }
1431
1435
  const pageCardVis = Math.max(cr(page.surface, page.canvas), PANEL_FLOOR);
1432
- if (tint !== "page") {
1436
+ if (panels === "own") {
1433
1437
  const groundL = parseToOklch(valueOf(ground, srgb)).l;
1434
1438
  const lighter = (r) => parseToOklch(valueOf(r, srgb)).l > groundL;
1435
1439
  const cards = rampSteps.filter((r) => cr(r, ground) >= PANEL_FLOOR);
1436
1440
  const byVis = (a, b) => Math.abs(cr(a, ground) - pageCardVis) - Math.abs(cr(b, ground) - pageCardVis);
1437
1441
  refs.surface = [...cards.filter(lighter).sort(byVis), ...cards.filter((r) => !lighter(r)).sort(byVis)][0] ?? page.surface;
1438
- } else {
1442
+ } else if (panels === "page") {
1439
1443
  refs.surface = page.surface;
1444
+ } else {
1445
+ refs.surface = fillRef(panels, srgb);
1446
+ if (cr(refs.surface, ground) < PANEL_FLOOR) notes.push(`surface: ${cr(refs.surface, ground).toFixed(2)}:1 against the ground, so the card doesn't draw`);
1440
1447
  }
1441
1448
  refs.canvas = ground;
1442
1449
  refs["canvas-foreground"] = body;
@@ -1478,6 +1485,7 @@ function buildGround(name, given, tiers, views, options) {
1478
1485
  step,
1479
1486
  polarity,
1480
1487
  tint,
1488
+ panels,
1481
1489
  text,
1482
1490
  ...action ? { action } : {},
1483
1491
  tokens: Object.fromEntries(order.map((k) => [k, valueOf(_refs[k], srgb)])),
@@ -2511,6 +2519,192 @@ function diffSlice(target, slice) {
2511
2519
  return { matches: differing.length === 0 && missing.length === 0, differing, missing };
2512
2520
  }
2513
2521
 
2522
+ // src/local.ts
2523
+ function blocks(css) {
2524
+ const out = [];
2525
+ const text = css.replace(/\/\*[\s\S]*?\*\//g, "");
2526
+ let i = 0;
2527
+ let prelude = "";
2528
+ const stack = [];
2529
+ let body = "";
2530
+ while (i < text.length) {
2531
+ const ch = text[i];
2532
+ if (ch === "{") {
2533
+ stack.push(prelude.trim());
2534
+ prelude = "";
2535
+ body = "";
2536
+ } else if (ch === "}") {
2537
+ const selector = stack.pop() ?? "";
2538
+ if (body.trim()) {
2539
+ const at = stack.filter((s) => s.startsWith("@")).join(" ");
2540
+ out.push({ selector: at ? `${at} ${selector}` : selector, decls: decls(body) });
2541
+ }
2542
+ body = "";
2543
+ prelude = "";
2544
+ } else if (stack.length) {
2545
+ body += ch;
2546
+ if (ch === ";") prelude = "";
2547
+ else prelude += ch;
2548
+ } else {
2549
+ prelude += ch;
2550
+ }
2551
+ i++;
2552
+ }
2553
+ return out;
2554
+ }
2555
+ function decls(body) {
2556
+ return [...body.matchAll(/(--[\w-]+)\s*:\s*([^;]+);?/g)].map((m) => [m[1], m[2].trim()]);
2557
+ }
2558
+ function scopesOf(selector) {
2559
+ const scopes = [];
2560
+ for (const part of selector.split(",").map((s) => s.trim())) {
2561
+ if (part === ":root" || part === '[data-theme="light"]' || part === '[data-surface="canvas"]') scopes.push("light");
2562
+ else if (part === '[data-theme="dark"]' || part === ".dark") scopes.push("dark");
2563
+ else {
2564
+ const m = /^\[data-surface="([\w-]+)"\]$/.exec(part);
2565
+ if (!m) return void 0;
2566
+ scopes.push(m[1]);
2567
+ }
2568
+ }
2569
+ return scopes;
2570
+ }
2571
+ var LITERAL = [/#[0-9a-f]{3,8}\b/i, /\b(?:rgba?|hsla?|hwb|lab|lch|oklab|color)\(/i, /\boklch\((?!\s*from\b)/i];
2572
+ function scopesFrom(generated) {
2573
+ const all = blocks(generated).filter((b) => !b.selector.startsWith("@media"));
2574
+ const ramps = /* @__PURE__ */ new Map();
2575
+ const names = /* @__PURE__ */ new Set();
2576
+ for (const b of all) for (const [n, v] of b.decls) {
2577
+ names.add(n);
2578
+ if (/^--color-/.test(n) && !v.startsWith("var(")) ramps.set(n, v);
2579
+ }
2580
+ const light = all.find((b) => b.selector.includes('[data-theme="light"]'));
2581
+ const dark = all.find((b) => b.selector.startsWith('[data-theme="dark"]'));
2582
+ const groundBlocks = /* @__PURE__ */ new Map();
2583
+ for (const b of all) {
2584
+ const m = /^\[data-surface="([\w-]+)"\]$/.exec(b.selector);
2585
+ if (m) groundBlocks.set(m[1], b);
2586
+ }
2587
+ const grounds = /* @__PURE__ */ new Set([...groundBlocks.keys(), "canvas"]);
2588
+ const scope = (name) => {
2589
+ const map = new Map(ramps);
2590
+ const isDark = name === "dark" || name !== "light" && Boolean(dark?.selector.includes(`[data-surface="${name}"]`));
2591
+ for (const [n, v] of (isDark ? dark : light)?.decls ?? []) map.set(n, v);
2592
+ for (const [n, v] of groundBlocks.get(name)?.decls ?? []) map.set(n, v);
2593
+ return map;
2594
+ };
2595
+ return { ramps, scope, grounds, names };
2596
+ }
2597
+ function resolve(value, scope, depth = 0) {
2598
+ if (depth > 20) return void 0;
2599
+ const v = value.trim();
2600
+ const ref = /^var\(\s*(--[\w-]+)\s*(?:,\s*(.+))?\)$/.exec(v);
2601
+ if (ref) {
2602
+ const next = scope.get(ref[1]) ?? ref[2];
2603
+ return next === void 0 ? void 0 : resolve(next, scope, depth + 1);
2604
+ }
2605
+ const rel = /^oklch\(\s*from\s+(var\([^)]*\)|\S+)\s+(.+)\)$/.exec(v);
2606
+ if (rel) {
2607
+ const base = resolve(rel[1], scope, depth + 1);
2608
+ if (!base) return void 0;
2609
+ const from = parseToOklch(base);
2610
+ const parts = rel[2].match(/calc\([^)]*\)|\S+/g) ?? [];
2611
+ if (parts.length < 3) return void 0;
2612
+ const channel = (expr, own2) => {
2613
+ const body = expr.replace(/^calc\(|\)$/g, "").replace(/\b([lch])\b/g, (_, k) => String(own2[k]));
2614
+ if (!/^[\d\s.+\-*/()]+$/.test(body)) return Number.NaN;
2615
+ return Function(`"use strict"; return (${body});`)();
2616
+ };
2617
+ const own = { l: from.l, c: from.c, h: from.h ?? 0 };
2618
+ const [l, c, h] = parts.slice(0, 3).map((p) => channel(p, own));
2619
+ if ([l, c, h].some(Number.isNaN)) return void 0;
2620
+ return oklchToHex({ mode: "oklch", l, c, h });
2621
+ }
2622
+ if (v.startsWith("color-mix(")) return void 0;
2623
+ return v;
2624
+ }
2625
+ var TARGETS = { "aa-large": 3, aa: 4.5, aaa: 7 };
2626
+ function checkLocalOverrides(generated, local, target = "aa") {
2627
+ const problems = [];
2628
+ const overrides = [];
2629
+ const { scope, grounds, names } = scopesFrom(generated);
2630
+ const floor = TARGETS[target];
2631
+ if ((local.match(/{/g) ?? []).length !== (local.match(/}/g) ?? []).length) {
2632
+ return { overrides, problems: [{ kind: "syntax", message: "the braces don't balance" }] };
2633
+ }
2634
+ const touched = /* @__PURE__ */ new Map();
2635
+ for (const b of blocks(local)) {
2636
+ if (b.selector.startsWith("@")) {
2637
+ problems.push({ kind: "selector", message: `${b.selector}: no at-rules; set a mode with [data-theme="dark"]` });
2638
+ continue;
2639
+ }
2640
+ const reached = scopesOf(b.selector);
2641
+ if (!reached) {
2642
+ problems.push({ kind: "selector", message: `${b.selector}: only the generator's own selectors (:root, [data-theme], .dark, [data-surface="\u2026"])` });
2643
+ continue;
2644
+ }
2645
+ for (const s of reached) {
2646
+ if (s !== "light" && s !== "dark" && !grounds.has(s)) {
2647
+ problems.push({ kind: "selector", message: `[data-surface="${s}"]: not a ground the generator makes` });
2648
+ }
2649
+ }
2650
+ for (const [name, value] of b.decls) {
2651
+ overrides.push({ selector: b.selector, name, value });
2652
+ if (name.startsWith("--color-")) {
2653
+ problems.push({
2654
+ kind: "name",
2655
+ message: `${name} in ${b.selector}: set the token, not its --color- alias or a ramp step (move a step with shade overrides)`
2656
+ });
2657
+ } else if (!names.has(name)) {
2658
+ problems.push({ kind: "name", message: `${name} in ${b.selector}: not a token the generator writes; a new name belongs in the project's own stylesheet` });
2659
+ }
2660
+ if (LITERAL.some((re) => re.test(value))) {
2661
+ problems.push({ kind: "value", message: `${name} in ${b.selector}: a literal colour; point at a ramp step (var(--color-\u2026)) or nudge one with oklch(from \u2026)` });
2662
+ }
2663
+ for (const s of reached) {
2664
+ if (!touched.has(s)) touched.set(s, /* @__PURE__ */ new Set());
2665
+ touched.get(s)?.add(name);
2666
+ }
2667
+ }
2668
+ }
2669
+ const localBlocks = blocks(local).filter((b) => !b.selector.startsWith("@"));
2670
+ for (const [s, touchedNames] of touched) {
2671
+ const map = scope(s);
2672
+ for (const b of localBlocks) {
2673
+ if (scopesOf(b.selector)?.includes(s)) for (const [n, v] of b.decls) map.set(n, v);
2674
+ }
2675
+ const bases = /* @__PURE__ */ new Set();
2676
+ for (const name of touchedNames) {
2677
+ if (name.startsWith("--color-")) continue;
2678
+ const base = name.replace(/-foreground(-secondary)?$/, "");
2679
+ if (map.has(`${base}-foreground`)) bases.add(base);
2680
+ }
2681
+ for (const base of bases) {
2682
+ const ground = resolve(`var(${base})`, map);
2683
+ for (const text of [`${base}-foreground`, `${base}-foreground-secondary`]) {
2684
+ if (!map.has(text)) continue;
2685
+ const ink = resolve(`var(${text})`, map);
2686
+ if (!ground || !ink) continue;
2687
+ const ratio = getContrastRatio(ink, ground);
2688
+ if (ratio < floor) {
2689
+ problems.push({
2690
+ kind: "contrast",
2691
+ message: `${text} on ${base} in ${s === "light" || s === "dark" ? `the ${s} page` : `[data-surface="${s}"]`}: ${ratio.toFixed(2)}:1, under ${floor}:1`
2692
+ });
2693
+ }
2694
+ }
2695
+ }
2696
+ }
2697
+ return { overrides, problems };
2698
+ }
2699
+ var LOCAL_TEMPLATE = `/* tokens.local.css: the project's overrides of the generated colour, loaded after tokens.css.
2700
+ Most changes are an input instead (a flag, the seed, shade overrides): use this only for a value
2701
+ the generator can't say. generate-tokens --local checks it against the system:
2702
+ - selectors: :root, [data-theme="light"], [data-theme="dark"], .dark, [data-surface="<ground>"];
2703
+ - names: tokens the generator writes (never a --color- alias or ramp step, never a new name);
2704
+ - values: var() references, or a ramp step nudged with oklch(from var(--color-\u2026) \u2026); never a literal colour.
2705
+ Each override is reported as pinned by hand, and the pairs it touches are re-checked for contrast. */
2706
+ `;
2707
+
2514
2708
  // src/scale.ts
2515
2709
  var t = (name, value, description) => ({ name, value, description });
2516
2710
  var textStep = (step, size, px, leading, tracking, use) => [
@@ -2729,19 +2923,19 @@ function toTailwindV4(tiers) {
2729
2923
  const plain = tiers.filter((x) => !x.themed && x.tokens.length);
2730
2924
  return ["@theme static {", ...block(themed, " "), "}", ...plain.length ? ["", "/* Tailwind has no namespace for these: use them as h-(--size-xl), duration-(--duration-base) */", "@layer base {", " :root {", ...block(plain, " "), " }", "}"] : []].join("\n");
2731
2925
  }
2732
- function resolve(value, all, depth = 0) {
2733
- return depth > 5 ? value : value.replace(/var\((--[\w-]+)\)/g, (m, name) => all.has(name) && !/--shadow$/.test(name) ? resolve(all.get(name), all, depth + 1) : m);
2926
+ function resolve2(value, all, depth = 0) {
2927
+ return depth > 5 ? value : value.replace(/var\((--[\w-]+)\)/g, (m, name) => all.has(name) && !/--shadow$/.test(name) ? resolve2(all.get(name), all, depth + 1) : m);
2734
2928
  }
2735
2929
  function toTailwindV3(tiers) {
2736
2930
  const all = new Map(tiers.flatMap((x) => x.tokens.map((tok) => [tok.name, tok.value])));
2737
- const of = (id, prefix) => Object.fromEntries((tiers.find((x) => x.id === id)?.tokens ?? []).filter((tok) => !tok.name.includes("--", 2)).map((tok) => [tok.name.slice(prefix.length), resolve(tok.value, all)]));
2931
+ const of = (id, prefix) => Object.fromEntries((tiers.find((x) => x.id === id)?.tokens ?? []).filter((tok) => !tok.name.includes("--", 2)).map((tok) => [tok.name.slice(prefix.length), resolve2(tok.value, all)]));
2738
2932
  const base = Number.parseFloat(all.get("--spacing") ?? "0.25");
2739
2933
  const steps = [0.5, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32];
2740
2934
  const text = Object.fromEntries(
2741
2935
  (tiers.find((x) => x.id === "text")?.tokens ?? []).filter((tok) => !tok.name.includes("--", 2)).map((tok) => {
2742
2936
  const lh = all.get(`${tok.name}--line-height`);
2743
2937
  const ls = all.get(`${tok.name}--letter-spacing`);
2744
- const extra = { ...lh ? { lineHeight: resolve(lh, all) } : {}, ...ls ? { letterSpacing: resolve(ls, all) } : {} };
2938
+ const extra = { ...lh ? { lineHeight: resolve2(lh, all) } : {}, ...ls ? { letterSpacing: resolve2(ls, all) } : {} };
2745
2939
  return [tok.name.slice("--text-".length), Object.keys(extra).length ? [tok.value, extra] : tok.value];
2746
2940
  })
2747
2941
  );
@@ -2823,6 +3017,45 @@ function exportScale(tiers, format, header) {
2823
3017
  ${body}
2824
3018
  `;
2825
3019
  }
3020
+ var OWNED_SCALE_MARK = "@designtools/tokens scale";
3021
+ function ownedScaleHeader(version) {
3022
+ return [
3023
+ `/* ${OWNED_SCALE_MARK} v${version}: scaffolded once, now this project's own.`,
3024
+ " Retune any value here by hand: nothing regenerates this file. The names are the contract:",
3025
+ " keep every one, and add new ones only inside a tier's namespace (--spacing-*, --text-*, \u2026),",
3026
+ " which designtools-manifest check verifies. */"
3027
+ ].join("\n");
3028
+ }
3029
+ function isOwnedScale(css) {
3030
+ return css.includes(OWNED_SCALE_MARK);
3031
+ }
3032
+ var TIER_PREFIX = {
3033
+ spacing: "--spacing",
3034
+ size: "--size-",
3035
+ text: "--text-",
3036
+ leading: "--leading-",
3037
+ tracking: "--tracking-",
3038
+ "font-weight": "--font-weight-",
3039
+ radius: "--radius-",
3040
+ shadow: "--shadow-",
3041
+ duration: "--duration-",
3042
+ ease: "--ease-",
3043
+ breakpoint: "--breakpoint-",
3044
+ container: "--container-"
3045
+ };
3046
+ function verifyScale(css) {
3047
+ const declared = new Set([...css.matchAll(/(?:^|[;{\s])(--[\w-]+)\s*:/g)].map((m) => m[1]));
3048
+ const tiers = defaultScale();
3049
+ const names = new Set(tiers.flatMap((tier) => tier.tokens.map((tok) => tok.name)));
3050
+ const inTier = (name) => Object.values(TIER_PREFIX).some((prefix) => name === prefix || name.startsWith(prefix.endsWith("-") ? prefix : `${prefix}-`));
3051
+ const missing = [...names].filter((name) => !declared.has(name));
3052
+ const added = [...declared].filter((name) => !names.has(name));
3053
+ return {
3054
+ missing,
3055
+ strays: added.filter((name) => !inTier(name)),
3056
+ own: added.filter(inTier)
3057
+ };
3058
+ }
2826
3059
 
2827
3060
  // src/contract.ts
2828
3061
  var ALIASES = new Set(ALIAS_PAIRS.map(([, alias]) => alias));
@@ -2979,9 +3212,15 @@ export {
2979
3212
  readDeclarations,
2980
3213
  mergeSlice,
2981
3214
  diffSlice,
3215
+ checkLocalOverrides,
3216
+ LOCAL_TEMPLATE,
2982
3217
  defaultScale,
2983
3218
  applyScaleOverrides,
2984
3219
  exportScale,
3220
+ OWNED_SCALE_MARK,
3221
+ ownedScaleHeader,
3222
+ isOwnedScale,
3223
+ verifyScale,
2985
3224
  stepContract,
2986
3225
  GENERATOR_NAME,
2987
3226
  stableStringify,