@designtools/tokens 0.10.0 → 0.11.1

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,24 @@
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.11.1
6
+
7
+ ### Patch Changes
8
+
9
+ - 7074755: `--merge` lists only the tokens the merged file is missing. Refreshing grounds into a full file (`--only grounds --merge`) printed about 50 tokens as "defined elsewhere", every one of them already in the file, which read as a failure when nothing was wrong. After a merge, the slice's references are now checked against the merged file, and the warning names the file: `slice references 1 token that tokens.css does not define`. `externalReferences(css, against?)` takes the target's CSS as an optional second argument to do the same in code. A slice written to stdout or `--out` without `--merge` still lists everything it leans on, since there is no target to check against.
10
+
11
+ ## 0.11.0
12
+
13
+ ### Minor Changes
14
+
15
+ - 07b2b90: **Grounds: content on coloured backgrounds.** A ground is a background content sits on, with every token content needs on it searched again against that background: `--canvas` and `--canvas-foreground` (the ground and its text), `--muted` and `--muted-foreground`, `--border`, `--input`, `--ring`, and for every semantic colour its fill, `-foreground`, `-hover`, `-active`, `-subdued` and `-subdued-foreground`. Mark an element `data-surface="<ground>"` and components inside need no change. On a coloured ground everything without a meaning of its own takes the ground's colour: in a success banner the button, ring, chips, panels and borders are green and the secondary button is a tonal green, while a delete button stays red; on an indigo band `bg-primary` turns white with an indigo label. Every pairing is contrast-checked on the ground. The grounds are `canvas` and `surface` (the page's own values, to reset a card inside a band), `success-subdued`, `warning-subdued` and `destructive-subdued` (banners and alerts), and every `--background`. Neutral grounds keep the page's tokens wherever they work. `--report` lists what each ground changed and anything it couldn't reach. `--grounds text` (`"grounds": "text"` in a seed) makes a ground its background and text only, everything else staying the page's; `--grounds none` leaves grounds out.
16
+
17
+ Emitted as `--on-<ground>-<token>` in each mode block, only where a ground differs from the page, and one `[data-surface]` scope per ground after the mode blocks; `tailwind-v4` re-binds its `--color-*` aliases inside each scope, and DTCG carries them as `<mode>.ground.<name>`. `--only grounds` selects them; a family-scoped run (`--ramps`) leaves them alone, as it does surfaces. `TokenSystem.grounds` carries them in code. Existing output is unchanged; grounds are added to it, so a default CSS file grows from about 270 lines to about 900 (about 330 with `--grounds text`).
18
+
19
+ A `--background` name a token or ground already uses (`canvas`, `primary`, `warning-subdued`, …) is now refused, unless `--grounds none`. The README explains the three ways to add a colour: `--color` (a ramp and semantic tokens), `--color` with `--decorative` (a ramp only), and `--background` (a section colour and its ground).
20
+
21
+ Fix: `--merge` with an `--only` slice that has no primitives (`--only semantic`, `--only grounds`) reported its blocks as missing, because braces quoted in the file's header comment were read as a block.
22
+
5
23
  ## 0.10.0
6
24
 
7
25
  ### Minor Changes
package/README.md CHANGED
@@ -42,13 +42,13 @@ From a single seed colour:
42
42
 
43
43
  Every `-foreground` is chosen by rule and measured, not a fixed mapping (see [Foregrounds](#foregrounds-are-chosen-by-what-they-sit-on)). Hover and press are `--primary-hover` and `--primary-active` (see below). `highlight`, which sat two steps from the fill and read as pressed rather than hover, was removed in 0.7.0.
44
44
 
45
- **Surfaces and utilities** — `--canvas`, `--surface`, `--overlay` with paired foregrounds, plus `--border`, `--input`, `--ring`, `--shadow`. The three backgrounds default to neutral steps and take exact colours per mode (`--canvas "#F2F2F0/#12171D"`); a brand's other section backgrounds come in by name (`--background stone=#E8E8DB`) as `--surface-stone` with measured text.
45
+ **Surfaces and utilities** — `--canvas`, `--surface`, `--overlay` with paired foregrounds, plus `--border`, `--input`, `--ring`, `--shadow`. The three backgrounds default to neutral steps and take exact colours per mode (`--canvas "#F2F2F0/#12171D"`); a brand's other section backgrounds come in by name (`--background stone=#E8E8DB`) as `--surface-stone` with measured text, and as a [ground](#grounds-content-on-coloured-backgrounds).
46
46
 
47
47
  **Hover and press are generated.** Each fill gets `--<name>-hover` and `--<name>-active`: the fill moved 0.09 and 0.15 in lightness away from its label (darker under a white label, lighter under a black one), so the change is plain to see and the label reads better on it, never worse. The 90% opacity they replace was barely visible (median ΔE 4.7) and dropped 26 of 90 labels under 4.5:1 by letting the page show through.
48
48
 
49
49
  **Status text on the page is the subdued label.** `--success-subdued-foreground` and its siblings are guaranteed to read as text on every background of their mode, so an error message is `text-destructive-subdued-foreground`, not `text-destructive` (the fill, measured only against its own label). A warning on the page is neutral text with an icon: warning is an orange, and orange dark enough to be text reads as brown. In light mode warning, and any yellow or orange brand colour, carries its hue in a stronger tint (step 200) with a near-black label for the same reason.
50
50
 
51
- **Every colour against every background.** A label is checked on its own fill; `pageContrast` (and `--report`) measures the rest: each semantic fill and muted text against the canvas, surface, overlay and each named background, per mode, so red text on a dark page (2.4:1 for every brand tested) or a deep purple button on a dark canvas (1.2:1) shows up before it ships. Read it as text (4.5:1 at AA) or as a shape (3:1, WCAG 1.4.11): a button's own label makes its outline optional, a meter fill or a switch has no label to lean on.
51
+ **Every colour against every background.** A label is checked on its own fill; `pageContrast` (and `--report`) measures the rest: each semantic fill and muted text against the canvas, surface, overlay and each named background, per mode, so red text on a dark page (2.4:1 for every brand tested) or a deep purple button on a dark canvas (1.2:1) shows up before it ships. Read it as text (4.5:1 at AA) or as a shape (3:1, WCAG 1.4.11): a button's own label makes its outline optional, a meter fill or a switch has no label to lean on. This measures the page's tokens where they land; inside `data-surface` a [ground](#grounds-content-on-coloured-backgrounds) gives content tokens chosen for that background instead.
52
52
 
53
53
  **Light and dark**, derived independently from the same ramps rather than one being a transform of the other, with contrast re-checked per mode. Output is keyed on `[data-theme]` with a `prefers-color-scheme` fallback, so it works with or without a theme toggle:
54
54
 
@@ -59,6 +59,93 @@ Every `-foreground` is chosen by rule and measured, not a fixed mapping (see [Fo
59
59
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { … } }
60
60
  ```
61
61
 
62
+ ## Adding colours: three flags, three jobs
63
+
64
+ Beyond the primary and the neutral, a colour comes in one of three ways. They do different jobs; pick by what the colour is for, not by what it looks like.
65
+
66
+ | You have | Flag | You get | Use it for |
67
+ |---|---|---|---|
68
+ | A colour things are made **in**: a second brand colour, a category colour | `--color teal=#14b8a6` | A ramp (`--color-teal-25` … `-950`) **and** semantic tokens: `--teal`, `-foreground`, `-subdued`, `-subdued-foreground`, `-hover`, `-active`, each label contrast-checked | Buttons, badges, tags, text in that colour |
69
+ | A colour that must **never** be text or an action: an illustration tint, a chart accent | `--color sand=#e8d5b0 --decorative sand` | The ramp only. No `--sand`, no `bg-sand`, so it cannot end up as a label or a button by accident | Decoration, data viz, artwork |
70
+ | A colour a whole **section** is painted with: a band on a marketing page | `--background brand=#4f46e5` | One exact colour, `--surface-brand`, with measured text, **and a ground**: inside `data-surface="brand"` every token is searched again against it ([below](#grounds-content-on-coloured-backgrounds)) | Page sections, hero bands, footers |
71
+
72
+ `--background` takes the colour exactly as given and makes no ramp from it; if you also want a scale in that colour, add it with `--color` as well. A background name can't be one a token or ground already uses (`canvas`, `surface`, `primary`, `warning-subdued`, …): each one becomes a `data-surface` value and a token prefix, so a clash would put two things under one name. The generator refuses it and says which names are taken.
73
+
74
+ ## Grounds: content on coloured backgrounds
75
+
76
+ The page tokens are searched against the canvas, the surface and the overlay. Content sits on other backgrounds too: a warning banner with a button in it, an indigo band on a marketing page with a caption and a call to action. On those, the page's tokens were only ever measured, never chosen, and a primary button on a primary band is 1:1.
77
+
78
+ A **ground** is a background content sits on, with every token content needs on it searched again against that background. Mark the element once and components inside need no change:
79
+
80
+ ```html
81
+ <section data-surface="brand">
82
+ <h2>Book your first session</h2>
83
+ <p class="text-muted-foreground">Readable on the band, quieter than the heading</p>
84
+ <button class="bg-primary text-primary-foreground">Get started</button> <!-- turns white, label indigo -->
85
+ <div class="bg-surface" data-surface="surface">A card resets to the page's own tokens</div>
86
+ </section>
87
+
88
+ <div data-surface="success-subdued">A banner: <button class="bg-primary …">this button is green here</button></div>
89
+ ```
90
+
91
+ **Which grounds there are**
92
+
93
+ | Ground | From | Its tokens |
94
+ |---|---|---|
95
+ | `canvas`, `surface` | Always | The page's own, exactly. Use them to reset inside another ground: a card in a band is `data-surface="surface"` |
96
+ | `success-subdued`, `warning-subdued`, `destructive-subdued` | Always | Searched against the status tint: banners, alerts, inline messages |
97
+ | `<name>` | Each `--background <name>=…` | Searched against that colour |
98
+
99
+ **What each ground carries.** The same names everywhere, so a component reads the same tokens on any ground:
100
+
101
+ | Token inside the ground | For | Must reach |
102
+ |---|---|---|
103
+ | `--canvas`, `--canvas-foreground` | The ground and its body text | the ground's own text (a status tint's label, a band's measured text) |
104
+ | `--muted`, `--muted-foreground` | Panels, captions, supporting copy | text at 4.5:1 (7:1 at AAA) on the ground and on a muted panel, and quieter than the body text |
105
+ | `--border` | Dividers | the separation the border has on the page |
106
+ | `--input`, `--ring` | A field's edge, the focus ring | 3:1 (WCAG 1.4.11) |
107
+ | `--<colour>`, `-foreground`, `-hover`, `-active` | Buttons, for every semantic colour | the fill stands out from the ground at 3:1; its label reads on it |
108
+ | `--<colour>-subdued`, `-subdued-foreground` | Chips, and that colour's text on the ground (an error under a field) | the label reads on the tint and on the ground |
109
+
110
+ **The rule: everything takes the ground's colour, except what carries a meaning.** On a coloured ground (a status tint, or a band with real colour) the primary button, the focus ring, chips, links, panels, borders, input edges and secondary text all come from the ground's own ramp, and the neutral button becomes a tonal one in that hue: in a success banner the button and ring are green, on an indigo band indigo. Status colours keep their meaning, so a delete button is still red in a success banner. Each value is the ground's page token where that reads on the ground (a success banner's button is `--success`), and searched along the ramp where it doesn't. On its own colour a button turns over: on the brand band the primary button is the ramp's palest step with the brand colour in its label. A neutral ground (the canvas, the surface, a stone or near-grey band) keeps the page's tokens wherever they work.
111
+
112
+ **What it can't do, it says.** `--report` lists what each ground changed from the page and anything its search couldn't reach. Two you will see:
113
+
114
+ - On a light success or destructive banner the body text is already the tint's label at about 6:1, so no quieter step still reads at 4.5:1, and the muted text is the body colour.
115
+ - On a saturated band, status text has to be near white to read, so red text on an indigo band is a very pale red. Let the icon carry the meaning.
116
+
117
+ **Not part of a ground:** `--surface`, `--overlay` and their foregrounds (a card is still a card, on any band), `--shadow`, and the ramps.
118
+
119
+ **How it's emitted.** Each ground's tokens sit in the mode blocks as `--on-<ground>-<token>` (`--on-brand-primary`, `--on-warning-subdued-muted-foreground`), only where they differ from the page; the rest read the page's copy, `--on-canvas-<token>`. After the mode blocks, one scope per ground re-points the everyday names and paints the ground:
120
+
121
+ ```css
122
+ [data-surface="brand"] {
123
+ --primary: var(--on-brand-primary);
124
+ --muted-foreground: var(--on-brand-muted-foreground);
125
+ /* … every token the ground carries … */
126
+ background-color: var(--canvas);
127
+ color: var(--canvas-foreground);
128
+ }
129
+ ```
130
+
131
+ Because the values live in the mode blocks, a ground follows `data-theme` and `prefers-color-scheme` like everything else, and a ground nested in another (a banner inside a band) reads its own values, not its parent's. The `tailwind-v4` format re-binds each `--color-*` alias inside the scope too, for [the reason the mode blocks do](#tailwind-v4), so `bg-primary` follows the ground.
132
+
133
+ **Changing one token on one ground** is ordinary CSS after the generated file, unlayered (see [Overriding](#overriding-what-it-generates)). It applies in both modes, because the scope reads the mode's value:
134
+
135
+ ```css
136
+ [data-surface="brand"] { --neutral: transparent; --neutral-foreground: var(--color-white); }
137
+ ```
138
+
139
+ **How much a ground carries: `--grounds`.**
140
+
141
+ | `--grounds` | Inside `data-surface` | Default CSS file |
142
+ |---|---|---|
143
+ | `full` *(default)* | Every token above, tinted to the ground and contrast-checked on it | about 900 lines, plus about 150 per `--background` |
144
+ | `text` | The background and its text only; buttons, borders, the ring and the rest stay the page's | about 330 lines |
145
+ | `none` | No grounds: no `data-surface`, no `--on-*`. Each `--background` is `--surface-<name>` and its text, painted with classes | about 270 lines, as before grounds |
146
+
147
+ With `text`, the page's tokens are not checked against the ground: a blue button in a dark green banner can fall under 3:1, and `--report` still measures it. To keep `full` but put one token back to the page's, read the page's copy: `[data-surface="success-subdued"] { --primary: var(--on-canvas-primary); }`.
148
+
62
149
  ## Try it
63
150
 
64
151
  ```bash
@@ -242,6 +329,13 @@ generate-tokens --primary "#4e9caf" --color accent=#8b5cf6 \
242
329
  --ramps accent --out tokens.css --merge
243
330
  ```
244
331
 
332
+ A family-scoped run leaves surfaces, utilities and [grounds](#grounds-content-on-coloured-backgrounds) alone: they read every family, so no one colour owns them. After regenerating a family a ground draws on, refresh the grounds the same way:
333
+
334
+ ```bash
335
+ generate-tokens --primary "#4e9caf" --color destructive=#ff0000 \
336
+ --only grounds --out tokens.css --merge
337
+ ```
338
+
245
339
  ### Why a family, and why merge
246
340
 
247
341
  A family is the right unit because **the contrast search runs inside it**. Change the ramp and the foregrounds change with it — they are chosen *against* those values. Regenerate `destructive` and this happens:
@@ -328,7 +422,7 @@ With `gamut: "p3"`, the wide-gamut tiers are on `tokens.p3`, and the checks take
328
422
  | `css` *(default)* | `tokens.css` | CSS custom properties. The lead format — works in any project. Mode blocks carry both `[data-theme]` attributes and `.dark`/`.light` classes, matching `tailwind-v4`. |
329
423
  | `tailwind-v4` | `tailwind.css` | A complete `@theme static` block. See [Tailwind v4](#tailwind-v4). |
330
424
  | `tailwind-v3` | `tailwind.config.js` | `theme.extend.colors` config. |
331
- | `dtcg` | `tokens.dtcg.json` | W3C Design Token Community Group JSON. |
425
+ | `dtcg` | `tokens.dtcg.json` | W3C Design Token Community Group JSON. Grounds sit under each mode as `light.ground.<name>.<token>`. |
332
426
  | `json` | `tokens.json` | The raw `TokenSystem`, for downstream tooling. |
333
427
 
334
428
  `--color-format` controls how literal values are printed: `oklch` (default), `hex`, `rgb`, `hsl`.
@@ -343,7 +437,7 @@ With `gamut: "p3"`, the wide-gamut tiers are on `tokens.p3`, and the checks take
343
437
  |---|---|---|
344
438
  | `--primary <colour>` | — | Your brand colour. Required unless `--seed` supplies it. |
345
439
  | `--neutral <colour>` | `#747474` | Neutral seed. Drives greys, surfaces, borders. |
346
- | `--color <name>=<colour>[@<shade>]` | — | An extra named scale. Repeatable. `@<shade>` anchors its seed on that step. |
440
+ | `--color <name>=<colour>[@<shade>]` | — | An extra named colour: a ramp and semantic tokens. Repeatable. `@<shade>` anchors its seed on that step. See [Adding colours](#adding-colours-three-flags-three-jobs). |
347
441
  | `--decorative <name>` | — | Give an added colour its ramp only, with no semantic slots (`--<name>`, `-foreground`, `bg-<name>`), so an accent that must never be text or an action cannot be used as one. Repeatable. In a seed file, `"decorative": true` on the colour. |
348
442
  | `--seed <file.json>` | — | Replay a saved configuration. Flags given alongside it win, so a seed is defaults rather than a lock. |
349
443
  | `--stdin` | off | Read that same JSON from standard input. |
@@ -377,7 +471,8 @@ A seed file:
377
471
  | `--foreground` | `balanced` · `max` | `balanced` | Labels on a fill: white or black, or a tint keeping 90% of that (`balanced`); never a tint (`max`). |
378
472
  | `--no-wcag-floor` | — | — | With `--contrast apca`, choose by APCA alone, without holding pairings to the WCAG 2 floor. |
379
473
  | `--canvas`, `--surface`, `--overlay` | `<colour>[/<dark>]` | neutral steps | The page, card and overlay as exact colours, light then dark; text on each is measured. |
380
- | `--background` | `<name>=<colour>[/<dark>]` | — | A brand section background, emitted as `--surface-<name>` with measured text. Repeatable. |
474
+ | `--grounds` | `full` · `text` · `none` | `full` | What `data-surface` gives each [ground](#grounds-content-on-coloured-backgrounds): every token tinted to it, its background and text only, or no grounds. |
475
+ | `--background` | `<name>=<colour>[/<dark>]` | — | A colour a section is painted with, emitted as `--surface-<name>` with measured text and as a [ground](#grounds-content-on-coloured-backgrounds): inside `data-surface="<name>"` every token is searched again against it. Repeatable. Names a token or ground uses are refused. Not a ramp: use `--color` for that. |
381
476
  | `--usage <file.json>` | — | — | Also write where each colour can go: every fill, status text tone and muted 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. |
382
477
  | `--seed-shade` | `25`…`950` | `500` | Which step your primary lands on. |
383
478
  | `--neutral-seed-shade` | `25`…`950` | `500` | Which step your neutral lands on. |
@@ -477,7 +572,7 @@ A seed outside sRGB is reported on stderr, since its step will not be the colour
477
572
 
478
573
  | Flag | Values | What it does |
479
574
  |---|---|---|
480
- | `--only <sections>` | `ramp` · `primitives` · `semantic` · `surface` · `utility` | Emit only these tiers. Comma-separated or repeated. |
575
+ | `--only <sections>` | `ramp` · `primitives` · `semantic` · `surface` · `utility` · `grounds` | Emit only these tiers. Comma-separated or repeated. |
481
576
  | `--ramps <names>` | any colour family | Emit only these colour families. See [Regenerating part of a token file](#regenerating-part-of-a-token-file). |
482
577
 
483
578
  - **`ramp`** — the colour ramps alone. This is "hand me a colour, hand me back scales".
@@ -485,6 +580,7 @@ A seed outside sRGB is reported on stderr, since its step will not be the colour
485
580
  - **`semantic`** — `--primary`, `--destructive-subdued-foreground`, `--muted`, …
486
581
  - **`surface`** — `--canvas`, `--surface`, `--overlay` and their foregrounds.
487
582
  - **`utility`** — `--border`, `--input`, `--ring`, `--shadow`.
583
+ - **`grounds`** — `--on-<ground>-*` in each mode block and the `[data-surface]` scopes.
488
584
 
489
585
  Beyond convenience, this keeps generated colour separable from files a project hand-tunes, so re-theming does not clobber them:
490
586
 
@@ -575,7 +671,7 @@ On Tailwind v4 a token only becomes a usable class if it sits inside a `@theme`
575
671
  }
576
672
  ```
577
673
 
578
- You get `bg-primary`, `text-primary-foreground`, `bg-canvas`, `border-border` **and** `bg-primary-500`, in both modes.
674
+ You get `bg-primary`, `text-primary-foreground`, `bg-canvas`, `border-border` **and** `bg-primary-500`, in both modes, and on every [ground](#grounds-content-on-coloured-backgrounds): each `[data-surface]` scope re-binds the aliases it re-points, for the same reason the mode blocks do.
579
675
 
580
676
  Three details carry the weight, each verified against a real Tailwind compile:
581
677
 
@@ -615,6 +711,8 @@ Two consequences, both of which have cost real projects real time:
615
711
 
616
712
  Then check **both** colour schemes, not whichever your tool defaults to.
617
713
 
714
+ **A token on one ground** is overridden on its scope, `[data-surface="brand"] { --neutral: transparent; }`, after the generated file and unlayered. One selector covers both modes, because the scope reads each mode's `--on-brand-*` value; to change a ground in one mode only, override `--on-brand-neutral` in that mode's selector instead.
715
+
618
716
  **Change a ramp step through its seed, not by overriding it.** Tailwind v4 utilities do read ramp steps through `var()` (checked against a Tailwind 4.3 compile), which is what lets the `--gamut p3` layer work. The one exception is an opacity modifier: `bg-primary-500/50` also emits the step's literal value as a fallback for browsers without `color-mix()`, and an override cannot reach that. But a hand-overridden step is a fork of the palette that the contrast search never saw and `--check` cannot detect. If you need a ramp step to change, change the seed and regenerate, or point the call sites at a token you do own.
619
717
 
620
718
  Generated files carry this contract in their own header, built from the selectors that file actually emitted.
@@ -625,6 +723,7 @@ If you find yourself hand-writing a colour beside the generated file, that is th
625
723
 
626
724
  - **Deterministic.** Same inputs and version produce byte-identical output. No randomness, clocks, or environment reads. (A grey has no meaningful hue, so `hsl` output prints it as 0 rather than float noise that differs across engines.)
627
725
  - **Displayable.** Every value is inside sRGB, so the colour in the file is the colour on the page, and contrast is measured on the colour a browser paints. With `--gamut p3`, the wide layer is inside Display P3.
726
+ - **Every ground reads.** Inside each `data-surface`, every button fill stands out from the ground at 3:1 with a label that reads on it, the input edge and focus ring reach 3:1, and muted and status text read at the text floor, or `--report` names what couldn't. A token that already worked keeps the page's value.
628
727
  - **Two test tiers.** Golden fixtures pin the bytes; structural invariants pin what a fixture cannot — chiefly that every `var(--x)` an export emits resolves to a `--x:` the same output defines. Bytes can be stable and still be incoherent CSS.
629
728
  - **One dependency**, pure JS: `culori` (colour maths). APCA contrast uses the optional `apca-w3`.
630
729
  - **ESM**, Node 18+.