@designtools/tokens 0.4.0 → 0.6.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 +95 -0
- package/LICENSE +21 -0
- package/README.md +125 -25
- package/dist/{chunk-MCLZSLHE.js → chunk-UW2HXSV4.js} +272 -129
- package/dist/cli.js +143 -46
- package/dist/index.d.ts +204 -21
- package/dist/index.js +17 -1
- package/package.json +28 -15
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
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
|
+
|
|
5
|
+
## 0.6.0
|
|
6
|
+
|
|
7
|
+
### Minor Changes
|
|
8
|
+
|
|
9
|
+
- 620b0a1: MIT licensed, maintained in madebymany/designtools, and APCA is now optional. Output is unchanged from 0.5.0.
|
|
10
|
+
|
|
11
|
+
`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.
|
|
12
|
+
|
|
13
|
+
`--check` reports the version change until a project regenerates. Only the provenance header differs.
|
|
14
|
+
|
|
15
|
+
## 0.4.0
|
|
16
|
+
|
|
17
|
+
Partial regeneration, and the bug that made it necessary.
|
|
18
|
+
|
|
19
|
+
### Fixed
|
|
20
|
+
|
|
21
|
+
- **The semantic bridge now follows `--seed-shade`.** Re-anchoring the ramp left the bridge on its hardcoded steps, so a brand colour anchored at 700 sat on `--color-primary-700` while `--primary` still pointed at 500 — the brand colour unreachable through `bg-primary`, with nothing in the output to say so. Mappings are now offsets from the anchor, resolved at emit time and clamped to the ends of the ramp. `--ring` moves with them, being primary-derived; `muted`, `border`, `input` and `shadow` do not, being neutral-derived.
|
|
22
|
+
- **Alias pairs no longer drift apart.** `destructive`/`red`, `success`/`green` and `warning`/`yellow` are two names for one scale, but `--color` moved only the name you typed, so `bg-red-500` and `bg-destructive-500` could silently differ in the same file. Overriding either now moves both.
|
|
23
|
+
- **The plain `css` format emits `.dark` and `.light` hooks.** Without them a project driving dark mode off a class — how Tailwind's own dark variant works — got no dark mode at all, and nothing in the build to say why.
|
|
24
|
+
- **The bridge constants had two copies**, one emitting `var()` references and one computing the values `--report` measures, so the CSS could disagree with its own contrast report. Now a single source in `bridge.ts`.
|
|
25
|
+
- **The parity harness and the fixture generator both dropped `seedShade`** on the way into `exportTokens` — the same desync in test form. The `seed-shade` fixture had been pinning the wrong value as faithfully as it would have pinned the right one.
|
|
26
|
+
|
|
27
|
+
### Added
|
|
28
|
+
|
|
29
|
+
- **`--ramps <names>`** — scope output to colour families. A family is one colour plus everything computed against it: its ramp, its alias ramp, and its semantic tokens. That is the safe unit to regenerate alone, because the contrast search that picks its foregrounds runs inside it.
|
|
30
|
+
- **`--merge`** — rewrite only the declarations a run generates into the file at `--out`, preserving every other line byte for byte. A family spans four blocks (`:root`, light, dark, and the `prefers-color-scheme` fallback); the media copy is the one a hand-splice forgets, leaving system-dark on the old colour.
|
|
31
|
+
- **`--check` honours `--ramps` and `--merge`.** A full check on a part-hand-edited file reports drift forever and cannot tell a wanted edit from a mistake; a scoped check compares only what the run generates.
|
|
32
|
+
- **The output states its own override contract**, built from the selectors each file actually emitted: the blocks are unlayered, here is the specificity to match, check both colour schemes, and a `--color-*` ramp step cannot be intercepted this way at all because Tailwind inlines its literal value into every utility.
|
|
33
|
+
- **`--report` covers what a palette can be silently wrong about** — where the semantics landed against their anchor, peak chroma per ramp (a seed can be chromatic by the numbers and still read as grey), and surface and utility contrast, which nothing had measured before. Ring is judged against 1.4.11's 3:1 rather than the body-text bar; border is reported without a verdict, since the generator cannot tell a decorative rule from a control boundary. These are reported but not scored, so the number stays comparable with earlier versions.
|
|
34
|
+
- npm metadata: keywords (there were none), homepage, bugs, and `repository.directory`.
|
|
35
|
+
|
|
36
|
+
### Changed
|
|
37
|
+
|
|
38
|
+
- `--vanilla` and `--replace-palette` warn instead of being silently ignored. For an agent a silent no-op is worse than an error: it leaves a false belief about the output.
|
|
39
|
+
|
|
40
|
+
### Notes
|
|
41
|
+
|
|
42
|
+
- **Default output is effectively unchanged.** Across all five formats the only differences in the entire release are two selector lines and a comment block — every colour value in every default fixture is byte-identical. Only a non-default `--seed-shade` moves, which is the bug being fixed.
|
|
43
|
+
- **`--merge` against a file generated before 0.4.0** will refuse: the old file carries the previous dark selectors, so a new slice cannot place its blocks. It leaves the file untouched rather than half-applying. Regenerate once, then `--merge`.
|
|
44
|
+
- On the default seed, `--report` shows the focus ring clearing neither mode against the canvas (1.82:1 light, 2.71:1 dark). Left as-is because changing it shifts every palette; it is at least visible now.
|
|
45
|
+
|
|
46
|
+
## 0.3.0
|
|
47
|
+
|
|
48
|
+
### Changed
|
|
49
|
+
|
|
50
|
+
- **`tailwind-v4` clears Tailwind's stock palette by default** (`--color-*: initial`), so a colour class the file does not define fails to compile rather than rendering off-brand. If a project does not own `--color-slate-900`, `bg-slate-900` yields Tailwind's stock slate — off-brand, compiles cleanly, reads as deliberate in review, and survives a re-theme. Better a build error.
|
|
51
|
+
- `--no-replace-palette` opts out, for an existing Tailwind codebase still using stock hues. `--replace-palette` becomes a no-op.
|
|
52
|
+
|
|
53
|
+
Tailwind's `transparent`, `current` and `inherit` are not part of the `--color-*` namespace and are unaffected.
|
|
54
|
+
|
|
55
|
+
## 0.2.1
|
|
56
|
+
|
|
57
|
+
### Fixed
|
|
58
|
+
|
|
59
|
+
- The 0.2 API was missing from the package barrel. `selectTokenSections`, the section and shade helpers and the provenance functions all worked from the CLI — which imports modules directly — while being unreachable to programmatic callers. Added a test asserting every CLI capability is exported.
|
|
60
|
+
|
|
61
|
+
## 0.2.0
|
|
62
|
+
|
|
63
|
+
Made the Tailwind v4 output usable, and gave the CLI a verification story.
|
|
64
|
+
|
|
65
|
+
### Fixed
|
|
66
|
+
|
|
67
|
+
- **`@theme static`, not plain `@theme`.** Tailwind tree-shakes a plain theme block down to the tokens some utility references, silently and with no build error. Measured on a default palette that dropped **47 of 140** colour tokens, including every `red`/`green`/`yellow` ramp, so `bg-red-500` fell back to Tailwind's stock red.
|
|
68
|
+
- **Semantic aliases are re-bound in every mode block.** Custom properties inherit their *computed* value, so `--color-primary: var(--primary)` declared only in `@theme` captured the light value and did not re-resolve inside a scoped `[data-theme="dark"]` subtree — a dark card on a light page kept the light colour. `<html class="dark">` happened to work either way, being the same element, which is why it went unnoticed.
|
|
69
|
+
- **`tailwind-v4` mode selectors match the `css` export** — `[data-theme="dark"], .dark` rather than `.dark` alone — and it gained the `prefers-color-scheme` fallback it had never had.
|
|
70
|
+
- **Primitive naming converged on `--color-*` across formats**, so `css` and `tailwind-v4` are interchangeable. Previously each was internally consistent but they could not be mixed.
|
|
71
|
+
- **A seed outside 15–98% lightness no longer inverts the ramp.** It was reproduced exactly at its anchor while its neighbours were clamped, so `#0a0a0a` gave shade 500 lighter than 600. Pre-existing; reproduces at the default anchor on 0.1.6.
|
|
72
|
+
|
|
73
|
+
### Added
|
|
74
|
+
|
|
75
|
+
- **`--seed-shade <25..950>`** — place the brand colour somewhere other than 500. Brand colours arrive as whatever they are, and a deep navy or pale tint pinned to the middle leaves no headroom on one side. Each side's easing curve is resampled onto its new step count and the chroma envelope follows the anchor.
|
|
76
|
+
- **`--shades <tailwind|full|list>`** — choose which steps exist. Tokens naming a dropped step snap to the nearest emitted one, and every substitution is reported, because snapping changes a design decision.
|
|
77
|
+
- **`--only <ramp|primitives|semantic|surface|utility>`** — slice by tier, to keep generated colour separable from hand-tuned files.
|
|
78
|
+
- **`--seed <file.json>` / `--stdin`** — replay a saved configuration; flags still win over it.
|
|
79
|
+
- **`--check`** — regenerate in memory and compare against `--out`, exiting non-zero on drift. Reads a provenance header, so it distinguishes a generator upgrade from a hand edit.
|
|
80
|
+
- **`--report`** — the measured contrast of every semantic pairing, with a score.
|
|
81
|
+
- **`--replace-palette`** — clear Tailwind's stock palette (default from 0.3.0).
|
|
82
|
+
- A provenance header naming the version and a fingerprint of the inputs.
|
|
83
|
+
- Structural invariant tests, covering what a golden fixture cannot: bytes can be stable and still be incoherent CSS. Chief among them, every `var(--x)` an export emits must resolve to a `--x:` the same output defines.
|
|
84
|
+
|
|
85
|
+
### Removed
|
|
86
|
+
|
|
87
|
+
- **shadcn/ui compatibility aliases** (`--background`, `--card`, `--secondary`, `--sidebar-*`, `--chart-*`) and the **`lovable` format**, which was a shadcn-shaped `globals.css`. `exportToLovable` and `ExportOptions.compat` are gone.
|
|
88
|
+
|
|
89
|
+
### Deprecated
|
|
90
|
+
|
|
91
|
+
- `--vanilla` — the aliases it switched off no longer exist, so it is the only behaviour.
|
|
92
|
+
|
|
93
|
+
## 0.1.7 — do not use
|
|
94
|
+
|
|
95
|
+
Published by mistake: this is the breaking 0.2.0 payload under a patch version, so a caretted `^0.1.6` resolves to it and picks up breaking changes with no version signal. Use `0.1.6` for the old behaviour or `0.2.1`+ for the new.
|
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
|
@@ -14,7 +14,7 @@ And **every foreground is measured, not assumed.** For each background it genera
|
|
|
14
14
|
|
|
15
15
|
```
|
|
16
16
|
light mode (wcag, target aa)
|
|
17
|
-
AA primary/default 5.
|
|
17
|
+
AA primary/default 5.19:1
|
|
18
18
|
- neutral/default 4.30:1
|
|
19
19
|
score: 93% (14/15 pairings)
|
|
20
20
|
```
|
|
@@ -96,12 +96,22 @@ Held near-neutral at the light end so tints stay clean, at full strength through
|
|
|
96
96
|
|
|
97
97
|
Hue is held constant across the whole scale — no Bezold–Brücke correction, no artistic rotation — so shade 900 is unmistakably the same colour as shade 100.
|
|
98
98
|
|
|
99
|
+
### Every colour is one a screen can show
|
|
100
|
+
|
|
101
|
+
OKLCH can describe colours more saturated than any screen displays, and near white and near black a screen can show very little chroma at all. A saturated seed held at full chroma down its ramp goes out of gamut at both ends: in 0.4.0, `#2f6fed` produced 36 of 48 primitives across its primary and status ramps that no browser renders as written.
|
|
102
|
+
|
|
103
|
+
So each step's chroma is capped at the most sRGB holds at that step's lightness and hue. Lightness and hue never move, only chroma, so a step keeps its place in the ramp. The value in the file is the colour on the page, in every browser.
|
|
104
|
+
|
|
105
|
+
Contrast is measured on the colour that is displayed, too. A browser maps an out-of-gamut colour into the screen's gamut when it paints (the CSS Color 4 algorithm), and the checks measure that same mapped colour, so a value that arrives out of gamut, such as a seed or a hand-edited token, is scored as it will be seen. Before 0.5.0, APCA scored such pairings Lc 0 and the foreground search chose blind.
|
|
106
|
+
|
|
107
|
+
For wide-gamut displays there is [`--gamut p3`](#--gamut--which-displays).
|
|
108
|
+
|
|
99
109
|
### Foregrounds are searched, not mapped
|
|
100
110
|
|
|
101
111
|
For every background it generates, the tool computes real contrast against each candidate shade and picks the one **closest to a comfortable target among those clearing your floor** — not the first that scrapes past, which would hand you the least legible passing option every time. If nothing in the colour's own scale qualifies it falls back to the neutral scale, then to black or white.
|
|
102
112
|
|
|
103
113
|
- **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.
|
|
104
|
-
- **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).
|
|
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). Needs [`apca-w3`](#apca-is-optional) installed.
|
|
105
115
|
|
|
106
116
|
### Dark mode is derived, not inverted
|
|
107
117
|
|
|
@@ -202,6 +212,24 @@ So an agent's contract is *scope, merge, verify* — and a bad merge is caught r
|
|
|
202
212
|
|
|
203
213
|
`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.
|
|
204
214
|
|
|
215
|
+
## Upgrading to 0.6.0
|
|
216
|
+
|
|
217
|
+
0.6.0 generates the same output as 0.5.0. Two things change around it:
|
|
218
|
+
|
|
219
|
+
- **It is MIT licensed**, and now lives in [madebymany/designtools](https://github.com/madebymany/designtools).
|
|
220
|
+
- **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.
|
|
221
|
+
|
|
222
|
+
The provenance header records the generator version, so `--check` reports the version change until you regenerate. Only that header line differs.
|
|
223
|
+
|
|
224
|
+
## Upgrading to 0.5.0
|
|
225
|
+
|
|
226
|
+
0.5.0 changes output for any saturated seed, so `--check` will report the version change until you regenerate. What moves:
|
|
227
|
+
|
|
228
|
+
- **Ramp steps that were outside sRGB** have their chroma capped to fit. Lightness and hue are unchanged, and a step that was already displayable is byte-identical. Pale and muted seeds are often untouched.
|
|
229
|
+
- **hex, rgb and hsl output of those steps** is the gamut-mapped colour a browser paints, not a channel-by-channel clip that shifted hue.
|
|
230
|
+
- **Some foregrounds**, where the search can now measure a background it could not before.
|
|
231
|
+
- **`--seed-shade` moves the primary only.** If you relied on it moving the neutral or status colours, anchor them explicitly with `--neutral-seed-shade` and `--color name=colour@shade`.
|
|
232
|
+
|
|
205
233
|
## Programmatic use
|
|
206
234
|
|
|
207
235
|
```ts
|
|
@@ -213,14 +241,21 @@ const css = exportTokens(tokens, "css", { colorFormat: "oklch" });
|
|
|
213
241
|
|
|
214
242
|
`generateTokens` returns a structured `TokenSystem`; `exportTokens` serialises it. Everything the CLI does is available here. No browser, DOM, or React — it runs anywhere.
|
|
215
243
|
|
|
216
|
-
|
|
244
|
+
The anchors have to be passed to both: **`seedShade`** (the primary's) and **`seedShades`** (every other family's, by name). The semantic bridge is expressed as offsets from each anchor, so an export that does not know where the seeds sit emits `var()` references the resolved values in `tokens` disagree with. Pass the same values to each, as the CLI does:
|
|
217
245
|
|
|
218
246
|
```ts
|
|
219
|
-
const
|
|
220
|
-
const tokens = generateTokens(
|
|
221
|
-
|
|
247
|
+
const anchors = { seedShade: 800, seedShades: { neutral: 200, accent: 300 } } as const;
|
|
248
|
+
const tokens = generateTokens(
|
|
249
|
+
{ primary: "#1e3a5f", neutral: "#e7e5e4", additionalColors: { accent: "#fde68a" } },
|
|
250
|
+
anchors
|
|
251
|
+
);
|
|
252
|
+
const css = exportTokens(tokens, "css", { colorFormat: "oklch", ...anchors });
|
|
222
253
|
```
|
|
223
254
|
|
|
255
|
+
`isAPCAAvailable()` says whether APCA contrast can be measured. When it cannot, anything that measures APCA throws an `APCAUnavailableError`.
|
|
256
|
+
|
|
257
|
+
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")`.
|
|
258
|
+
|
|
224
259
|
## Output formats
|
|
225
260
|
|
|
226
261
|
| `--format` | File under `--format all` | What it is |
|
|
@@ -243,7 +278,7 @@ const css = exportTokens(tokens, "css", { colorFormat: "oklch", seedShade });
|
|
|
243
278
|
|---|---|---|
|
|
244
279
|
| `--primary <colour>` | — | Your brand colour. Required unless `--seed` supplies it. |
|
|
245
280
|
| `--neutral <colour>` | `#747474` | Neutral seed. Drives greys, surfaces, borders. |
|
|
246
|
-
| `--color <name>=<colour
|
|
281
|
+
| `--color <name>=<colour>[@<shade>]` | — | An extra named scale. Repeatable. `@<shade>` anchors its seed on that step. |
|
|
247
282
|
| `--seed <file.json>` | — | Replay a saved configuration. Flags given alongside it win, so a seed is defaults rather than a lock. |
|
|
248
283
|
| `--stdin` | off | Read that same JSON from standard input. |
|
|
249
284
|
|
|
@@ -253,12 +288,14 @@ A seed file:
|
|
|
253
288
|
{
|
|
254
289
|
"primaryColor": "#7c3aed",
|
|
255
290
|
"neutralColor": "#747474",
|
|
256
|
-
"additionalColors": [{ "name": "accent", "color": "#f59e0b" }],
|
|
291
|
+
"additionalColors": [{ "name": "accent", "color": "#f59e0b", "seedShade": 500 }],
|
|
257
292
|
"colorFormat": "hex",
|
|
258
293
|
"contrastAlgorithm": "apca",
|
|
259
294
|
"contrastTarget": "aaa",
|
|
260
295
|
"lightnessStrategy": "perceptual",
|
|
261
296
|
"seedShade": 500,
|
|
297
|
+
"neutralSeedShade": 500,
|
|
298
|
+
"gamut": "srgb",
|
|
262
299
|
"shades": [25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950],
|
|
263
300
|
"shadeOverrides": {}
|
|
264
301
|
}
|
|
@@ -268,10 +305,12 @@ A seed file:
|
|
|
268
305
|
|
|
269
306
|
| Flag | Values | Default | What it does |
|
|
270
307
|
|---|---|---|---|
|
|
271
|
-
| `--contrast` | `wcag` · `apca` | `wcag` | Which algorithm picks foregrounds. |
|
|
308
|
+
| `--contrast` | `wcag` · `apca` | `wcag` | Which algorithm picks foregrounds. `apca` needs [`apca-w3`](#apca-is-optional) installed. |
|
|
272
309
|
| `--target` | `aa-large` · `aa` · `aaa` | `aa` | Minimum the foreground search must clear. |
|
|
273
310
|
| `--lightness` | `fixed` · `perceptual` | `fixed` | How lightness is spread across the steps. |
|
|
274
|
-
| `--seed-shade` | `25`…`950` | `500` | Which step your
|
|
311
|
+
| `--seed-shade` | `25`…`950` | `500` | Which step your primary lands on. |
|
|
312
|
+
| `--neutral-seed-shade` | `25`…`950` | `500` | Which step your neutral lands on. |
|
|
313
|
+
| `--gamut` | `srgb` · `p3` | `srgb` | Which displays to generate for. |
|
|
275
314
|
| `--shades` | `tailwind` · `full` · a list | `full` | Which steps to emit. |
|
|
276
315
|
| `--overrides <file.json>` | — | — | Per-token shade overrides. |
|
|
277
316
|
|
|
@@ -286,14 +325,24 @@ generate-tokens --primary "#fde68a" --seed-shade 200 # pale amber belongs nea
|
|
|
286
325
|
|
|
287
326
|
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.
|
|
288
327
|
|
|
289
|
-
**
|
|
328
|
+
**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:
|
|
329
|
+
|
|
330
|
+
```bash
|
|
331
|
+
generate-tokens --primary "#fde68a" --seed-shade 200 \
|
|
332
|
+
--neutral "#e7e5e4" --neutral-seed-shade 100 \
|
|
333
|
+
--color accent=#1e3a5f@800
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
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.
|
|
337
|
+
|
|
338
|
+
**The semantics follow the anchor too.** `--primary`, its subdued and highlight variants, and `--ring` 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.
|
|
290
339
|
|
|
291
340
|
`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.
|
|
292
341
|
|
|
293
342
|
`--report` prints where the bridge landed, so you can check rather than infer:
|
|
294
343
|
|
|
295
344
|
```
|
|
296
|
-
semantic bridge
|
|
345
|
+
semantic bridge for primary, anchored at 800 (neutral at 200; other families at 500)
|
|
297
346
|
light default 800 subdued 300 highlight 950 ring 700
|
|
298
347
|
dark default 900 subdued 500 highlight 700 ring 950
|
|
299
348
|
```
|
|
@@ -315,7 +364,33 @@ Some tokens name specific steps — `muted` and light `canvas` both sit on 25
|
|
|
315
364
|
canvas (light): 25 -> 50
|
|
316
365
|
```
|
|
317
366
|
|
|
318
|
-
A shade set needs at least three steps, and `--seed-shade
|
|
367
|
+
A shade set needs at least three steps, and every anchor (`--seed-shade`, `--neutral-seed-shade`, `@<shade>`) must be one of them.
|
|
368
|
+
|
|
369
|
+
#### `--gamut` — which displays
|
|
370
|
+
|
|
371
|
+
By default every colour is inside sRGB, the gamut every screen shows. Most phones and Macs can show more: Display P3 holds noticeably more chroma, most of all near white and near black, which is exactly where sRGB caps a vivid ramp hardest.
|
|
372
|
+
|
|
373
|
+
`--gamut p3` keeps the sRGB output exactly as it is and adds a wide-gamut layer after it. For `#2f6fed`:
|
|
374
|
+
|
|
375
|
+
```css
|
|
376
|
+
:root {
|
|
377
|
+
--color-primary-50: oklch(95.16% 0.0229 262.00); /* sRGB: every screen */
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
@media (color-gamut: p3) {
|
|
381
|
+
:root {
|
|
382
|
+
--color-primary-50: oklch(95.16% 0.0252 262.00); /* P3 screens */
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
```
|
|
386
|
+
|
|
387
|
+
Only the ramps are re-declared: semantic, surface and utility tokens are `var()` references to ramp steps, so they follow, and Tailwind v4 utilities read `var(--color-*)` too. Every ramp step is re-declared, not just those that differ, so a `--merge` after a re-seed cannot leave a stale value behind that only P3 screens would show.
|
|
388
|
+
|
|
389
|
+
**Every foreground is chosen to pass on both.** The search scores each candidate on sRGB and on P3 and keeps the worse, so the step it picks clears the floor on either kind of screen, and both tiers read the same steps. Where no step clears it on both, it takes the one with the best worst case, as it does when no step clears it at all. `--report` measures both.
|
|
390
|
+
|
|
391
|
+
Values in the layer are always printed as `oklch`, since `hex`, `rgb()` and `hsl()` can only hold sRGB. `tailwind-v3` and `dtcg` cannot carry the layer and say so on stderr; `json` carries it as `p3`.
|
|
392
|
+
|
|
393
|
+
A seed outside sRGB is reported on stderr, since its step will not be the colour as given: its chroma is reduced to fit, keeping lightness and hue. With `--gamut p3` the wide layer keeps it as given if P3 can show it.
|
|
319
394
|
|
|
320
395
|
### Selection
|
|
321
396
|
|
|
@@ -413,7 +488,7 @@ You get `bg-primary`, `text-primary-foreground`, `bg-canvas`, `border-border` **
|
|
|
413
488
|
|
|
414
489
|
Three details carry the weight, each verified against a real Tailwind compile:
|
|
415
490
|
|
|
416
|
-
**`@theme static`, never plain `@theme`.** Tailwind tree-shakes a plain theme block down to only the tokens some utility references — silently, with no build error. On a default palette that drops **
|
|
491
|
+
**`@theme static`, never plain `@theme`.** Tailwind tree-shakes a plain theme block down to only the tokens some utility references — silently, with no build error. On a default palette that drops **47 of 140** colour tokens, including every `red`/`green`/`yellow` ramp, so `bg-red-500` quietly falls back to Tailwind's stock red.
|
|
417
492
|
|
|
418
493
|
**Semantic aliases appear in the theme block *and* every mode block.** The `@theme` entry registers the name so the utility exists. But custom properties inherit their *computed* value, so an alias declared only on `:root` captures the light value and will not re-resolve inside a scoped `[data-theme="dark"]` subtree — a dark card on a light page would keep the light colour. (`<html class="dark">` works either way, being the same element, which is why this is easy to miss.)
|
|
419
494
|
|
|
@@ -449,7 +524,7 @@ Two consequences, both of which have cost real projects real time:
|
|
|
449
524
|
|
|
450
525
|
Then check **both** colour schemes, not whichever your tool defaults to.
|
|
451
526
|
|
|
452
|
-
**
|
|
527
|
+
**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.
|
|
453
528
|
|
|
454
529
|
Generated files carry this contract in their own header, built from the selectors that file actually emitted.
|
|
455
530
|
|
|
@@ -457,28 +532,53 @@ If you find yourself hand-writing a colour beside the generated file, that is th
|
|
|
457
532
|
|
|
458
533
|
## Guarantees
|
|
459
534
|
|
|
460
|
-
- **Deterministic.** Same inputs and version produce byte-identical output. No randomness, clocks, or environment reads. (
|
|
535
|
+
- **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.)
|
|
536
|
+
- **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.
|
|
461
537
|
- **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.
|
|
462
|
-
- **
|
|
538
|
+
- **One dependency**, pure JS: `culori` (colour maths). APCA contrast uses the optional `apca-w3`.
|
|
463
539
|
- **ESM**, Node 18+.
|
|
464
540
|
|
|
541
|
+
## APCA is optional
|
|
542
|
+
|
|
543
|
+
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).
|
|
544
|
+
|
|
545
|
+
A default install never loads it. To use `--contrast apca`, install it beside the package:
|
|
546
|
+
|
|
547
|
+
```bash
|
|
548
|
+
npm install @designtools/tokens apca-w3
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
or name both packages with npx:
|
|
552
|
+
|
|
553
|
+
```bash
|
|
554
|
+
npx -p apca-w3 -p @designtools/tokens generate-tokens --primary "#4e9caf" --contrast apca
|
|
555
|
+
```
|
|
556
|
+
|
|
557
|
+
`--lightness perceptual` is tuned for APCA but does not call it, so it works without `apca-w3`.
|
|
558
|
+
|
|
559
|
+
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.
|
|
560
|
+
|
|
465
561
|
## Development
|
|
466
562
|
|
|
467
|
-
Part of the [designtools](https://github.com/
|
|
563
|
+
Part of the [designtools](https://github.com/madebymany/designtools) monorepo. From the repo root:
|
|
468
564
|
|
|
469
565
|
```bash
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
566
|
+
pnpm --filter @designtools/tokens cli --primary "#4e9caf" # run from source
|
|
567
|
+
pnpm --filter @designtools/tokens build # tsup -> dist
|
|
568
|
+
pnpm --filter @designtools/tokens typecheck
|
|
569
|
+
pnpm --filter @designtools/tokens fixtures # regenerate goldens
|
|
570
|
+
pnpm --filter @designtools/tokens test # vitest
|
|
475
571
|
```
|
|
476
572
|
|
|
477
573
|
```
|
|
478
574
|
src/ types, oklch, primitives, semantic, generate, export, seed, shades, index, cli
|
|
479
|
-
test/ fixture parity, export invariants, shade behaviour, public API
|
|
575
|
+
test/ fixture parity, export invariants, shade behaviour, gamut, public API
|
|
480
576
|
```
|
|
481
577
|
|
|
578
|
+
## Changelog
|
|
579
|
+
|
|
580
|
+
[CHANGELOG.md](CHANGELOG.md) — what changed in each release, and why.
|
|
581
|
+
|
|
482
582
|
## Licence
|
|
483
583
|
|
|
484
|
-
CC-BY-NC-4.0
|
|
584
|
+
[MIT](LICENSE), © Made by Many Ltd. Versions up to and including 0.5.0 were published under CC-BY-NC-4.0.
|