@designtools/tokens 0.5.0 → 0.7.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 +40 -0
- package/LICENSE +21 -0
- package/README.md +90 -32
- package/dist/{chunk-D6675UF5.js → chunk-43GMBZQK.js} +328 -159
- package/dist/cli.js +172 -14
- package/dist/index.d.ts +142 -14
- package/dist/index.js +9 -1
- package/package.json +27 -15
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,46 @@
|
|
|
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.7.0
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- 3da728f: The focus ring, an input's edge and muted text are now searched to their contrast floor rather than fixed to a step: `ring` and `input` reach 3:1 against the canvas and the surface (WCAG 1.4.11), and `muted-foreground` reaches 4.5:1 on `muted` (7:1 with `--target aaa`). Each starts at its old step and moves away from the background until it clears; `border` keeps its fixed step. The chosen steps are recorded on the tokens (`utility[mode]._steps`, `muted._shades`), the CSS exports reference them, and `utilityShadeOverrides` now reaches the exports too, which it silently did not before. `--report` prints where each landed. Expect `--input`, `--ring` and `--muted-foreground` to move on regeneration; input edges in particular get noticeably darker.
|
|
10
|
+
- 3da728f: `--decorative <name>` (and `decorative` in the options, `"decorative": true` on a seed file's colour) gives an added colour its ramp and nothing else: no `--<name>`, `-foreground`, `-subdued` or `-highlight`, so no `bg-<name>` or `text-<name>-foreground`. An accent the brand forbids as text or an action is then decorative by construction, as `mxa-frontend-standards` describes. Without the flag, added colours keep their semantic slots as before.
|
|
11
|
+
|
|
12
|
+
- Light `muted` sits on neutral 100, a step off the canvas (25), so a muted panel or skeleton on the page is visible; it was the canvas colour.
|
|
13
|
+
- When no ramp step meets the contrast floor as a foreground, pure white or black is tried before a failing step is kept. A mid-tone grey seed (`#7A7468`) had its palest step at 4.27:1 where white passes at 4.63:1. Pairs that already passed are unchanged.
|
|
14
|
+
|
|
15
|
+
- Labels are chosen by what they sit on. On a fill: white or black, whichever contrasts more, or a tint off the ramp keeping at least 90% of that (`--foreground max` for none). Before, every label aimed for the step nearest 5.5:1, which dulled labels on dark fills (light blue on navy at 5.6:1 where white gives 10.4:1). On a subdued tint: the same hue, among steps keeping 80% of the ramp's peak chroma, aiming a level above the target (7:1 at AA in light mode, 9.5:1 in dark under WCAG, where WCAG 2 overstates light text on dark).
|
|
16
|
+
- When no label can reach the floor on a colour, the best available is kept, where a weaker ramp step was before.
|
|
17
|
+
- A status fill no label passes on both WCAG 2 and APCA moves up to two steps until one does: darker so white passes, or lighter when black is much nearer. A mid green now takes white at 6:1 and Lc 81, where it had black at Lc 49. The primary's own fill never moves.
|
|
18
|
+
- Dark mode keeps a light colour's own step (a pale yellow under a black label) instead of darkening it into khaki. Dark `subdued` is a dark tint (900 from a 500 seed) with a light same-hue label, not a pale 200 chip, and `subdued` stays near the ends of the ramp wherever the seed is anchored.
|
|
19
|
+
- `--contrast apca` holds every pairing to the WCAG 2 floor for the same target (`wcagFloor`, default true); `--no-wcag-floor` chooses by APCA alone. On eleven brands at AA, APCA alone failed 4.5:1 on a quarter of its pairings.
|
|
20
|
+
- Fills record the steps they settled on (`_shades`), the CSS exports reference them, and `--report` prints the chosen steps and every fill that moved, with its reason.
|
|
21
|
+
- The sRGB and P3 tiers judge a subdued label's hue the same way, so they pick the same step.
|
|
22
|
+
- The README no longer advises anchoring an extreme brand colour near the end of the ramp: the fill, highlight and subdued steps are placed relative to the anchor, so it pushed most of the palette to one side.
|
|
23
|
+
|
|
24
|
+
- **`highlight` is removed** (breaking). It sat two steps from the fill and read as a pressed state, not hover, and the industry's hover is a small change: a component thins its fill on hover and press (`hover:bg-primary/90`), keeping the label it was measured against. Each colour is now a fill and a subdued tint, each with its label.
|
|
25
|
+
- **Backgrounds.** `--canvas`, `--surface` and `--overlay` take exact colours per mode (`--canvas "#F2F2F0/#12171D"`; `surfaceColors` in the options), in place of the neutral steps they default to, and the text on each is measured. A brand's other section backgrounds come in by name (`--background stone=#E8E8DB`; `backgrounds`) as `--surface-<name>` with measured `-foreground`.
|
|
26
|
+
- **Every colour against every background.** `pageContrast` records each semantic fill and muted text against the canvas, surface, overlay and each named background, per mode, and `--report` prints the grid marked as fine for text, fine as a shape, or neither. Labels were checked only on their own fills, so red text on a dark page (2.4:1 for every brand tested) went unseen.
|
|
27
|
+
|
|
28
|
+
- Warning is an orange (hue 60°, from 75°). An amber's darker steps (a chip's label, text on the page) read as mustard and brown; an orange's stay burnt orange, clear of red at 25°.
|
|
29
|
+
- In light mode a warm colour (orange to yellow, warning or a yellow brand) carries its hue in a stronger tint (step 200) with a near-black label, because a label dark enough to read on a pale warm tint reads as brown or olive.
|
|
30
|
+
- A status colour's subdued label is guaranteed as text on every background of its mode (canvas, surface, overlay and each named background on the same side of mid-grey), so `-subdued-foreground` is the status text tone for the page. A named background of the other polarity (a dark section on a light page) is that mode scoped with `data-theme`, and is measured but not bound. The ring and an input's edge are searched against the same set.
|
|
31
|
+
|
|
32
|
+
- Hover and press are generated: `--<name>-hover` and `--<name>-active` move the fill 0.09 and 0.15 in lightness away from its label, so the state is plain and the label reads better on it. The 90% opacity hover was barely visible and dropped 26 of 90 labels under 4.5:1.
|
|
33
|
+
- `--usage <file>` (and `usageReport`) writes where each colour can go: every fill, status text tone and muted text on every background, per mode, as text, shape or neither. `@designtools/manifest` reads it as measured usage rules.
|
|
34
|
+
|
|
35
|
+
## 0.6.0
|
|
36
|
+
|
|
37
|
+
### Minor Changes
|
|
38
|
+
|
|
39
|
+
- 620b0a1: MIT licensed, maintained in madebymany/designtools, and APCA is now optional. Output is unchanged from 0.5.0.
|
|
40
|
+
|
|
41
|
+
`apca-w3` moves from a dependency to an optional peer dependency, because its licence is not MIT. It permits contrast checking of web content under WCAG and puts any other use under AGPL v3. A default install no longer includes it. `--contrast apca`, and the library's APCA functions, need it installed alongside: `npm install apca-w3`, or `npx -p apca-w3 -p @designtools/tokens generate-tokens --contrast apca`. Without it they fail with a message saying what to install. `isAPCAAvailable()` and `APCAUnavailableError` are exported so code can check first.
|
|
42
|
+
|
|
43
|
+
`--check` reports the version change until a project regenerates. Only the provenance header differs.
|
|
44
|
+
|
|
5
45
|
## 0.4.0
|
|
6
46
|
|
|
7
47
|
Partial regeneration, and the bug that made it necessary.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Made by Many Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -10,7 +10,7 @@ Not a palette generator with extra steps. Most tools rotate hue and step lightne
|
|
|
10
10
|
|
|
11
11
|
This one works in **OKLCH**, so equal steps are equal *perceptual* steps and the ramps stay balanced without hand-tweaking. Lightness is a fraction of the headroom either side of your colour rather than a fixed position, so a pale tint and a near-black both get a usable scale. Chroma follows its own easing curve, so light tints stay clean instead of going muddy while the interactive range stays saturated.
|
|
12
12
|
|
|
13
|
-
And **every foreground is measured, not assumed.** For each background it generates, it
|
|
13
|
+
And **every foreground is measured, not assumed.** For each background it generates, it measures real contrast, WCAG or APCA, and picks the label by what the background is: the most contrast on a fill, the same hue a level above your target on a pale tint. `--report` prints what it achieved, so accessibility is something you can assert in CI rather than hope for:
|
|
14
14
|
|
|
15
15
|
```
|
|
16
16
|
light mode (wcag, target aa)
|
|
@@ -33,17 +33,22 @@ From a single seed colour:
|
|
|
33
33
|
--color-primary-950: oklch(17.50% 0.0766 215.79);
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
**Semantic intents** — what you actually write in components. Each of `primary`, `neutral`, `success`, `destructive`, `warning` gets
|
|
36
|
+
**Semantic intents** — what you actually write in components. Each of `primary`, `neutral`, `success`, `destructive`, `warning` gets a fill and a subdued tint, each with its label, plus a `muted` pair:
|
|
37
37
|
|
|
38
38
|
```css
|
|
39
39
|
--primary --primary-foreground
|
|
40
40
|
--primary-subdued --primary-subdued-foreground
|
|
41
|
-
--primary-highlight --primary-highlight-foreground
|
|
42
41
|
```
|
|
43
42
|
|
|
44
|
-
Every `-foreground` is chosen by
|
|
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.
|
|
45
44
|
|
|
46
|
-
**Surfaces and utilities** — `--canvas`, `--surface`, `--overlay` with paired foregrounds, plus `--border`, `--input`, `--ring`, `--shadow`.
|
|
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.
|
|
46
|
+
|
|
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
|
+
|
|
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
|
+
|
|
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.
|
|
47
52
|
|
|
48
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:
|
|
49
54
|
|
|
@@ -106,16 +111,22 @@ Contrast is measured on the colour that is displayed, too. A browser maps an out
|
|
|
106
111
|
|
|
107
112
|
For wide-gamut displays there is [`--gamut p3`](#--gamut--which-displays).
|
|
108
113
|
|
|
109
|
-
### Foregrounds are
|
|
114
|
+
### Foregrounds are chosen by what they sit on
|
|
115
|
+
|
|
116
|
+
- **On a fill** (`DEFAULT`): the fill carries the hue, so the label's job is to be read. It is white or black, whichever contrasts more; a tint off the colour's ramp or the neutral may stand in only if it keeps at least 90% of that contrast, so the label is warmed towards the brand, never dulled. `--foreground max` allows no tint.
|
|
117
|
+
- **On a subdued tint**: the label carries the hue (green for paid, red for overdue), so it stays on its own ramp, among steps that keep at least 80% of the ramp's peak chroma, and aims a level above the target: 7:1 at AA and 9:1 at AAA in light mode, 9.5:1 at AA in dark mode under WCAG, because WCAG 2 overstates light text on a dark ground (Lc 75 and 90 under APCA). Keeping the hue never costs more than half the way from the floor to the aim.
|
|
118
|
+
- **When no label can reach the floor** on a colour, the best available is kept and `--report` shows the failure: only a different fill can do better.
|
|
110
119
|
|
|
111
|
-
|
|
120
|
+
Before 0.7.0 every label aimed for the shade nearest a comfort target (5.5:1 at AA), which dulled labels on dark fills: light blue on navy at 5.6:1, where white gives 10.4:1.
|
|
121
|
+
|
|
122
|
+
**A fill no label can pass on both measures moves.** On a mid-tone fill WCAG 2 and APCA disagree: on a mid green (luminance 31%) black scores 7.2:1 but Lc 49, and white Lc 60 but 2.9:1. A status fill like that (any but the primary's own, which is the brand colour) moves up to two steps until a label passes both: darker until white does, or lighter until black does when black is much nearer. The thresholds are fill luminance, measured from APCA once, so the result is the same whether or not APCA is installed. `--report` lists every fill that moved and why.
|
|
112
123
|
|
|
113
124
|
- **WCAG 2.x** (default) — `(L₁ + 0.05) / (L₂ + 0.05)`, with floors of 3:1 (`--target aa-large`), 4.5:1 (`aa`) and 7:1 (`aaa`). Widely adopted and legally referenced, but it treats dark-on-light and light-on-dark identically and has no concept of text size.
|
|
114
|
-
- **APCA** (`--contrast apca`) — models how contrast is actually perceived, so the same two colours score differently depending on which one is the text. Bands at Lc 45 (large text), Lc 60 (larger content), Lc 75 (body text), Lc 90 (fluent reading).
|
|
125
|
+
- **APCA** (`--contrast apca`) — models how contrast is actually perceived, so the same two colours score differently depending on which one is the text. Bands at Lc 45 (large text), Lc 60 (larger content), Lc 75 (body text), Lc 90 (fluent reading). Needs [`apca-w3`](#apca-is-optional) installed. Every pairing it picks must also pass the WCAG 2 floor for the same target, which is what audits measure: on eleven brands at AA, APCA alone failed 4.5:1 on a quarter of its pairings. `--no-wcag-floor` drops the floor.
|
|
115
126
|
|
|
116
127
|
### Dark mode is derived, not inverted
|
|
117
128
|
|
|
118
|
-
Both modes come from the same ramps via different shade mappings, and the contrast search re-runs for each — so a dark foreground is chosen against dark backgrounds rather than inherited from a flipped light palette.
|
|
129
|
+
Both modes come from the same ramps via different shade mappings, and the contrast search re-runs for each — so a dark foreground is chosen against dark backgrounds rather than inherited from a flipped light palette. A dark-mode fill steps one darker than light mode's, so a white label gains contrast; a light colour under a black label (a pale yellow) keeps its own step, because darker would only weaken the label and muddy the colour. Dark `subdued` is a dark tint with a light label in the same hue, not a pale chip.
|
|
119
130
|
|
|
120
131
|
### Status colours belong to your palette
|
|
121
132
|
|
|
@@ -212,6 +223,15 @@ So an agent's contract is *scope, merge, verify* — and a bad merge is caught r
|
|
|
212
223
|
|
|
213
224
|
`destructive`/`red`, `success`/`green` and `warning`/`yellow` are two names for one scale, so overriding either moves both. Without that, `--color destructive=…` would leave `bg-red-500` on the old colour and the two names would silently disagree inside the same file.
|
|
214
225
|
|
|
226
|
+
## Upgrading to 0.6.0
|
|
227
|
+
|
|
228
|
+
0.6.0 generates the same output as 0.5.0. Two things change around it:
|
|
229
|
+
|
|
230
|
+
- **It is MIT licensed**, and now lives in [madebymany/designtools](https://github.com/madebymany/designtools).
|
|
231
|
+
- **APCA is optional.** `apca-w3` is no longer installed with the package. If you use `--contrast apca`, or call the APCA functions from code, install it yourself: see [APCA is optional](#apca-is-optional). Without it, those calls fail with a message saying what to install. WCAG, the default, needs nothing extra.
|
|
232
|
+
|
|
233
|
+
The provenance header records the generator version, so `--check` reports the version change until you regenerate. Only that header line differs.
|
|
234
|
+
|
|
215
235
|
## Upgrading to 0.5.0
|
|
216
236
|
|
|
217
237
|
0.5.0 changes output for any saturated seed, so `--check` will report the version change until you regenerate. What moves:
|
|
@@ -243,6 +263,8 @@ const tokens = generateTokens(
|
|
|
243
263
|
const css = exportTokens(tokens, "css", { colorFormat: "oklch", ...anchors });
|
|
244
264
|
```
|
|
245
265
|
|
|
266
|
+
`isAPCAAvailable()` says whether APCA contrast can be measured. When it cannot, anything that measures APCA throws an `APCAUnavailableError`.
|
|
267
|
+
|
|
246
268
|
With `gamut: "p3"`, the wide-gamut tiers are on `tokens.p3`, and the checks take the gamut to measure on: `checkSemanticContrast(tokens.p3.semantic.light, "p3")`.
|
|
247
269
|
|
|
248
270
|
## Output formats
|
|
@@ -268,6 +290,7 @@ With `gamut: "p3"`, the wide-gamut tiers are on `tokens.p3`, and the checks take
|
|
|
268
290
|
| `--primary <colour>` | — | Your brand colour. Required unless `--seed` supplies it. |
|
|
269
291
|
| `--neutral <colour>` | `#747474` | Neutral seed. Drives greys, surfaces, borders. |
|
|
270
292
|
| `--color <name>=<colour>[@<shade>]` | — | An extra named scale. Repeatable. `@<shade>` anchors its seed on that step. |
|
|
293
|
+
| `--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. |
|
|
271
294
|
| `--seed <file.json>` | — | Replay a saved configuration. Flags given alongside it win, so a seed is defaults rather than a lock. |
|
|
272
295
|
| `--stdin` | off | Read that same JSON from standard input. |
|
|
273
296
|
|
|
@@ -294,9 +317,14 @@ A seed file:
|
|
|
294
317
|
|
|
295
318
|
| Flag | Values | Default | What it does |
|
|
296
319
|
|---|---|---|---|
|
|
297
|
-
| `--contrast` | `wcag` · `apca` | `wcag` | Which algorithm picks foregrounds. |
|
|
320
|
+
| `--contrast` | `wcag` · `apca` | `wcag` | Which algorithm picks foregrounds. `apca` needs [`apca-w3`](#apca-is-optional) installed. |
|
|
298
321
|
| `--target` | `aa-large` · `aa` · `aaa` | `aa` | Minimum the foreground search must clear. |
|
|
299
322
|
| `--lightness` | `fixed` · `perceptual` | `fixed` | How lightness is spread across the steps. |
|
|
323
|
+
| `--foreground` | `balanced` · `max` | `balanced` | Labels on a fill: white or black, or a tint keeping 90% of that (`balanced`); never a tint (`max`). |
|
|
324
|
+
| `--no-wcag-floor` | — | — | With `--contrast apca`, choose by APCA alone, without holding pairings to the WCAG 2 floor. |
|
|
325
|
+
| `--canvas`, `--surface`, `--overlay` | `<colour>[/<dark>]` | neutral steps | The page, card and overlay as exact colours, light then dark; text on each is measured. |
|
|
326
|
+
| `--background` | `<name>=<colour>[/<dark>]` | — | A brand section background, emitted as `--surface-<name>` with measured text. Repeatable. |
|
|
327
|
+
| `--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. |
|
|
300
328
|
| `--seed-shade` | `25`…`950` | `500` | Which step your primary lands on. |
|
|
301
329
|
| `--neutral-seed-shade` | `25`…`950` | `500` | Which step your neutral lands on. |
|
|
302
330
|
| `--gamut` | `srgb` · `p3` | `srgb` | Which displays to generate for. |
|
|
@@ -305,11 +333,10 @@ A seed file:
|
|
|
305
333
|
|
|
306
334
|
#### `--seed-shade` — where your brand colour sits
|
|
307
335
|
|
|
308
|
-
Everything is derived from the headroom above and below the seed, so where it sits matters.
|
|
336
|
+
Everything is derived from the headroom above and below the seed, so where it sits matters, but leave it on 500 unless a step you use looks wrong. The fill, subdued and ring steps are all placed relative to the anchor: anchor a pale yellow at 50 and everything darker than it, which the dark-mode fill and any tint labels draw on, is khaki; anchor a deep purple at 800 and its mid tones go grey. On 500 an extreme seed looks lopsided at one end (a pale yellow's 25 to 400 are near-identical creams), which costs little, because those steps are only read for subdued tints. When a used step is wrong, a nudge within 400 to 600 or a shade override for that one slot is the better fix.
|
|
309
337
|
|
|
310
338
|
```bash
|
|
311
|
-
generate-tokens --primary "#1e3a5f" --seed-shade
|
|
312
|
-
generate-tokens --primary "#fde68a" --seed-shade 200 # pale amber belongs near the top
|
|
339
|
+
generate-tokens --primary "#1e3a5f" --seed-shade 600 # a deep navy, one step down for more headroom
|
|
313
340
|
```
|
|
314
341
|
|
|
315
342
|
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.
|
|
@@ -324,16 +351,18 @@ generate-tokens --primary "#fde68a" --seed-shade 200 \
|
|
|
324
351
|
|
|
325
352
|
Before 0.5.0, `--seed-shade` moved every family. A pale brand colour anchored at 200 dragged the neutral to 200 with it, so `#CECECE` became `neutral-200` and the whole grey ramp darkened. A pale brand does not imply a pale grey.
|
|
326
353
|
|
|
327
|
-
**The semantics follow the anchor too.** `--primary`, its subdued
|
|
354
|
+
**The semantics follow the anchor too.** `--primary`, its subdued tint, and where `--ring` starts are positions relative to the seed, not fixed steps, and every other family's semantics are relative to that family's own anchor — so `bg-primary` is your brand colour wherever you anchor it. Before 0.4.0 they were pinned to 500, which meant anchoring a deep navy at 800 left `--primary` pointing at a pale mid-tone the brand never chose, with no way to reach the real one through `bg-primary` at all.
|
|
328
355
|
|
|
329
356
|
`muted`, `border`, `input` and `shadow` stay where they are: they read the neutral ramp, not your brand, and re-anchoring the whole UI's greys is a different thing from placing a brand colour.
|
|
330
357
|
|
|
358
|
+
**Three tokens are searched to a contrast floor.** The focus ring and an input's edge are non-text UI that WCAG 1.4.11 holds to 3:1, and muted text is text. A fixed step meets those for some colours and not others, so each starts at its usual step and moves away from the background (darker in light mode, lighter in dark) until it clears its floor against the canvas and the surface: 3:1 for `ring` and `input`, 4.5:1 for `muted-foreground` (7:1 with `--target aaa`). `border` keeps its fixed step, because round a card it is decoration. An override in `utilityShadeOverrides` still wins. Before 0.7.0 these were fixed, and a teal brand on a warm grey shipped a 2.7:1 ring, a 1.6:1 input edge and 4.3:1 muted text.
|
|
359
|
+
|
|
331
360
|
`--report` prints where the bridge landed, so you can check rather than infer:
|
|
332
361
|
|
|
333
362
|
```
|
|
334
|
-
semantic bridge for primary, anchored at
|
|
335
|
-
light default
|
|
336
|
-
dark default
|
|
363
|
+
semantic bridge for primary, anchored at 600 (other families at 500)
|
|
364
|
+
light default 600 subdued 100
|
|
365
|
+
dark default 700 subdued 950
|
|
337
366
|
```
|
|
338
367
|
|
|
339
368
|
#### `--shades` — which steps exist
|
|
@@ -345,11 +374,10 @@ generate-tokens --primary "#4e9caf" --shades tailwind # 50–950
|
|
|
345
374
|
generate-tokens --primary "#4e9caf" --shades 100,500,900 # a coarse three-step ramp
|
|
346
375
|
```
|
|
347
376
|
|
|
348
|
-
Some tokens name specific steps
|
|
377
|
+
Some tokens name specific steps (light `canvas` sits on 25), so dropping a step could leave a `var()` pointing at nothing. References snap to the nearest emitted step instead, and every substitution is reported, because snapping quietly changes a design decision:
|
|
349
378
|
|
|
350
379
|
```
|
|
351
380
|
--shades 50,100,…,950 drops steps some tokens name; snapped to nearest:
|
|
352
|
-
muted (light): 25 -> 50
|
|
353
381
|
canvas (light): 25 -> 50
|
|
354
382
|
```
|
|
355
383
|
|
|
@@ -424,14 +452,24 @@ Supported by `css`, `tailwind-v4` and `json`; other formats reject it rather tha
|
|
|
424
452
|
| Flag | What it does |
|
|
425
453
|
|---|---|
|
|
426
454
|
| `--check` | Compare against what is already at `--out`. Writes nothing; exits non-zero on drift. With `--ramps` or `--merge`, only the declarations this run generates are compared. |
|
|
427
|
-
| `--report` | Print where the semantic bridge landed, peak chroma per ramp, and measured contrast for every pairing — semantic, surface and utility — with a score. Stderr only; never changes the exit code. |
|
|
455
|
+
| `--report` | Print where the semantic bridge landed, where the searched tokens landed, peak chroma per ramp, and measured contrast for every pairing — semantic, surface and utility — with a score. Stderr only; never changes the exit code. |
|
|
428
456
|
|
|
429
457
|
```
|
|
430
458
|
$ generate-tokens --primary "#4e9caf" --report --out tokens.css
|
|
431
459
|
|
|
432
|
-
semantic bridge
|
|
433
|
-
|
|
434
|
-
|
|
460
|
+
semantic bridge for primary, anchored at 500 (other families at 500)
|
|
461
|
+
semantic bridge for primary, anchored at 500 (other families at 500)
|
|
462
|
+
light default 500 subdued 50
|
|
463
|
+
|
|
464
|
+
fills moved from the offset table
|
|
465
|
+
light success fill 500 -> 600 (no label passed both WCAG 2 and APCA)
|
|
466
|
+
light warning fill 500 -> 400 (no label passed both WCAG 2 and APCA)
|
|
467
|
+
dark primary fill 600 -> 500 (a light colour under a black label keeps its own step)
|
|
468
|
+
...
|
|
469
|
+
|
|
470
|
+
searched to their contrast floor (ring and input 3:1 on canvas and surface; muted text on muted)
|
|
471
|
+
light ring primary-600 (from 400) input neutral-500 (from 200) muted-foreground neutral-600 (from 500)
|
|
472
|
+
dark ring primary-600 (from 700) input neutral-500 (from 800) muted-foreground neutral-200
|
|
435
473
|
|
|
436
474
|
ramp chroma (peak C per family)
|
|
437
475
|
primary 0.0815 at 500
|
|
@@ -446,7 +484,7 @@ light mode (wcag, target aa)
|
|
|
446
484
|
|
|
447
485
|
light surfaces and utilities (wcag, not counted in the score)
|
|
448
486
|
AAA canvas/foreground 13.05:1
|
|
449
|
-
|
|
487
|
+
3:1 ring/canvas 4.33:1 (non-text, 1.4.11)
|
|
450
488
|
border/canvas 1.29:1 (advisory: 3:1 only where it bounds a control)
|
|
451
489
|
```
|
|
452
490
|
|
|
@@ -524,19 +562,39 @@ If you find yourself hand-writing a colour beside the generated file, that is th
|
|
|
524
562
|
- **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.)
|
|
525
563
|
- **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.
|
|
526
564
|
- **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.
|
|
527
|
-
- **
|
|
565
|
+
- **One dependency**, pure JS: `culori` (colour maths). APCA contrast uses the optional `apca-w3`.
|
|
528
566
|
- **ESM**, Node 18+.
|
|
529
567
|
|
|
568
|
+
## APCA is optional
|
|
569
|
+
|
|
570
|
+
APCA contrast comes from [`apca-w3`](https://github.com/Myndex/apca-w3), which is an optional peer dependency rather than a dependency, because it is not MIT licensed. Its licence permits contrast checking of web content under WCAG, and puts any other use under AGPL v3 with further restrictions. Read it before you install it: [LICENSE.md](https://github.com/Myndex/apca-w3/blob/master/LICENSE.md).
|
|
571
|
+
|
|
572
|
+
A default install never loads it. To use `--contrast apca`, install it beside the package:
|
|
573
|
+
|
|
574
|
+
```bash
|
|
575
|
+
npm install @designtools/tokens apca-w3
|
|
576
|
+
```
|
|
577
|
+
|
|
578
|
+
or name both packages with npx:
|
|
579
|
+
|
|
580
|
+
```bash
|
|
581
|
+
npx -p apca-w3 -p @designtools/tokens generate-tokens --primary "#4e9caf" --contrast apca
|
|
582
|
+
```
|
|
583
|
+
|
|
584
|
+
`--lightness perceptual` is tuned for APCA but does not call it, so it works without `apca-w3`.
|
|
585
|
+
|
|
586
|
+
If you bundle the library for a browser without `apca-w3`, mark it as external, since the bundler will otherwise fail to resolve the optional import.
|
|
587
|
+
|
|
530
588
|
## Development
|
|
531
589
|
|
|
532
|
-
Part of the [designtools](https://github.com/
|
|
590
|
+
Part of the [designtools](https://github.com/madebymany/designtools) monorepo. From the repo root:
|
|
533
591
|
|
|
534
592
|
```bash
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
593
|
+
pnpm --filter @designtools/tokens cli --primary "#4e9caf" # run from source
|
|
594
|
+
pnpm --filter @designtools/tokens build # tsup -> dist
|
|
595
|
+
pnpm --filter @designtools/tokens typecheck
|
|
596
|
+
pnpm --filter @designtools/tokens fixtures # regenerate goldens
|
|
597
|
+
pnpm --filter @designtools/tokens test # vitest
|
|
540
598
|
```
|
|
541
599
|
|
|
542
600
|
```
|
|
@@ -550,4 +608,4 @@ test/ fixture parity, export invariants, shade behaviour, gamut, public API
|
|
|
550
608
|
|
|
551
609
|
## Licence
|
|
552
610
|
|
|
553
|
-
CC-BY-NC-4.0
|
|
611
|
+
[MIT](LICENSE), © Made by Many Ltd. Versions up to and including 0.5.0 were published under CC-BY-NC-4.0.
|