@designtools/tokens 0.14.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 +12 -0
- package/README.md +49 -11
- package/dist/{chunk-7PQDEFU6.js → chunk-FY6LQL2A.js} +238 -7
- package/dist/cli.js +233 -36
- package/dist/index.d.ts +66 -1
- package/dist/index.js +13 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,18 @@
|
|
|
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
|
+
|
|
5
17
|
## 0.14.0
|
|
6
18
|
|
|
7
19
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -308,6 +308,8 @@ This is deliberately a **dumb, deterministic tool** — no model, no network, no
|
|
|
308
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).
|
|
309
309
|
- **`--only` for tier-level slicing.** Keep generated colour in a different file from anything hand-tuned.
|
|
310
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).
|
|
311
313
|
|
|
312
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":
|
|
313
315
|
|
|
@@ -327,14 +329,54 @@ check: tokens.css differs — same generator and seed, so the file was edited by
|
|
|
327
329
|
check: tokens.css differs — generated by v0.4.0, running v0.5.0. Expected after a generator upgrade.
|
|
328
330
|
```
|
|
329
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
|
+
|
|
330
373
|
## The scale: everything that isn't colour
|
|
331
374
|
|
|
332
|
-
Colour comes from a seed; the rest of a system has none,
|
|
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.
|
|
333
376
|
|
|
334
377
|
```bash
|
|
335
|
-
npx @designtools/tokens scale --format tailwind-v4 --
|
|
336
|
-
npx @designtools/tokens scale --
|
|
337
|
-
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
|
|
338
380
|
```
|
|
339
381
|
|
|
340
382
|
| Tier | Tokens | What it is |
|
|
@@ -348,15 +390,11 @@ npx @designtools/tokens scale --format all --out ./tokens # css, tailwind-v3,
|
|
|
348
390
|
| Screen sizes | `--breakpoint-sm` … `--breakpoint-2xl` | Where a page can change shape, from each size up |
|
|
349
391
|
| Widths | `--container-3xs` … `--container-7xl` | The widths content is set to |
|
|
350
392
|
|
|
351
|
-
The names are the contract and
|
|
352
|
-
|
|
353
|
-
`--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.
|
|
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.
|
|
354
394
|
|
|
355
|
-
|
|
356
|
-
{ "--radius-md": "0.5rem", "--text-5xl": { "value": "3rem", "description": "48px: page titles" }, "--text-5xl--line-height": "var(--leading-none)", "--leading-relaxed": null }
|
|
357
|
-
```
|
|
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.
|
|
358
396
|
|
|
359
|
-
|
|
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.
|
|
360
398
|
|
|
361
399
|
## Trying scales live: the studio
|
|
362
400
|
|
|
@@ -862,7 +862,7 @@ function generateSurfaceTokens(palette, mode, overrides, shades, colors, pageSur
|
|
|
862
862
|
const black = palette.black;
|
|
863
863
|
const white = palette.white;
|
|
864
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" };
|
|
865
|
-
function
|
|
865
|
+
function resolve3(key) {
|
|
866
866
|
const raw = overrides?.[key] ?? defaults[key];
|
|
867
867
|
if (raw === "white") return { value: white, ref: { type: "white" } };
|
|
868
868
|
if (raw === "black") return { value: black, ref: { type: "black" } };
|
|
@@ -871,9 +871,9 @@ function generateSurfaceTokens(palette, mode, overrides, shades, colors, pageSur
|
|
|
871
871
|
}
|
|
872
872
|
const ground = (key) => {
|
|
873
873
|
const given = colors?.[key];
|
|
874
|
-
if (!given) return { bg:
|
|
874
|
+
if (!given) return { bg: resolve3(key), fg: resolve3(`${key}-foreground`) };
|
|
875
875
|
const bg = { value: given, ref: { type: "value", value: given } };
|
|
876
|
-
return { bg, fg: overrides?.[`${key}-foreground`] ?
|
|
876
|
+
return { bg, fg: overrides?.[`${key}-foreground`] ? resolve3(`${key}-foreground`) : textOn(given, neutral, white, black, activeShades) };
|
|
877
877
|
};
|
|
878
878
|
const { bg: canvas, fg: canvasFg } = ground("canvas");
|
|
879
879
|
const { bg: surface, fg: surfaceFg } = ground("surface");
|
|
@@ -2519,6 +2519,192 @@ function diffSlice(target, slice) {
|
|
|
2519
2519
|
return { matches: differing.length === 0 && missing.length === 0, differing, missing };
|
|
2520
2520
|
}
|
|
2521
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
|
+
|
|
2522
2708
|
// src/scale.ts
|
|
2523
2709
|
var t = (name, value, description) => ({ name, value, description });
|
|
2524
2710
|
var textStep = (step, size, px, leading, tracking, use) => [
|
|
@@ -2737,19 +2923,19 @@ function toTailwindV4(tiers) {
|
|
|
2737
2923
|
const plain = tiers.filter((x) => !x.themed && x.tokens.length);
|
|
2738
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");
|
|
2739
2925
|
}
|
|
2740
|
-
function
|
|
2741
|
-
return depth > 5 ? value : value.replace(/var\((--[\w-]+)\)/g, (m, name) => all.has(name) && !/--shadow$/.test(name) ?
|
|
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);
|
|
2742
2928
|
}
|
|
2743
2929
|
function toTailwindV3(tiers) {
|
|
2744
2930
|
const all = new Map(tiers.flatMap((x) => x.tokens.map((tok) => [tok.name, tok.value])));
|
|
2745
|
-
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),
|
|
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)]));
|
|
2746
2932
|
const base = Number.parseFloat(all.get("--spacing") ?? "0.25");
|
|
2747
2933
|
const steps = [0.5, 1, 2, 3, 4, 5, 6, 8, 10, 12, 16, 20, 24, 32];
|
|
2748
2934
|
const text = Object.fromEntries(
|
|
2749
2935
|
(tiers.find((x) => x.id === "text")?.tokens ?? []).filter((tok) => !tok.name.includes("--", 2)).map((tok) => {
|
|
2750
2936
|
const lh = all.get(`${tok.name}--line-height`);
|
|
2751
2937
|
const ls = all.get(`${tok.name}--letter-spacing`);
|
|
2752
|
-
const extra = { ...lh ? { lineHeight:
|
|
2938
|
+
const extra = { ...lh ? { lineHeight: resolve2(lh, all) } : {}, ...ls ? { letterSpacing: resolve2(ls, all) } : {} };
|
|
2753
2939
|
return [tok.name.slice("--text-".length), Object.keys(extra).length ? [tok.value, extra] : tok.value];
|
|
2754
2940
|
})
|
|
2755
2941
|
);
|
|
@@ -2831,6 +3017,45 @@ function exportScale(tiers, format, header) {
|
|
|
2831
3017
|
${body}
|
|
2832
3018
|
`;
|
|
2833
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
|
+
}
|
|
2834
3059
|
|
|
2835
3060
|
// src/contract.ts
|
|
2836
3061
|
var ALIASES = new Set(ALIAS_PAIRS.map(([, alias]) => alias));
|
|
@@ -2987,9 +3212,15 @@ export {
|
|
|
2987
3212
|
readDeclarations,
|
|
2988
3213
|
mergeSlice,
|
|
2989
3214
|
diffSlice,
|
|
3215
|
+
checkLocalOverrides,
|
|
3216
|
+
LOCAL_TEMPLATE,
|
|
2990
3217
|
defaultScale,
|
|
2991
3218
|
applyScaleOverrides,
|
|
2992
3219
|
exportScale,
|
|
3220
|
+
OWNED_SCALE_MARK,
|
|
3221
|
+
ownedScaleHeader,
|
|
3222
|
+
isOwnedScale,
|
|
3223
|
+
verifyScale,
|
|
2993
3224
|
stepContract,
|
|
2994
3225
|
GENERATOR_NAME,
|
|
2995
3226
|
stableStringify,
|
package/dist/cli.js
CHANGED
|
@@ -2,12 +2,14 @@
|
|
|
2
2
|
import {
|
|
3
3
|
APCAUnavailableError,
|
|
4
4
|
DEFAULT_NEUTRAL_COLOR,
|
|
5
|
+
LOCAL_TEMPLATE,
|
|
5
6
|
SECTIONED_FORMATS,
|
|
6
7
|
SHADE_PRESETS,
|
|
7
8
|
TOKEN_SECTIONS,
|
|
8
9
|
VALID_SHADES,
|
|
9
10
|
applyScaleOverrides,
|
|
10
11
|
bridgeShade,
|
|
12
|
+
checkLocalOverrides,
|
|
11
13
|
checkRampChroma,
|
|
12
14
|
checkSemanticContrast,
|
|
13
15
|
checkSemanticContrastAPCA,
|
|
@@ -24,8 +26,10 @@ import {
|
|
|
24
26
|
getContrastRatio,
|
|
25
27
|
isAPCAAvailable,
|
|
26
28
|
isInGamut,
|
|
29
|
+
isOwnedScale,
|
|
27
30
|
mergeSlice,
|
|
28
31
|
overrideContract,
|
|
32
|
+
ownedScaleHeader,
|
|
29
33
|
parseProvenance,
|
|
30
34
|
parseToOklch,
|
|
31
35
|
provenanceComment,
|
|
@@ -39,17 +43,22 @@ import {
|
|
|
39
43
|
suggestStep,
|
|
40
44
|
tokenFamilies,
|
|
41
45
|
usageReport,
|
|
46
|
+
verifyScale,
|
|
42
47
|
withJsonProvenance
|
|
43
|
-
} from "./chunk-
|
|
48
|
+
} from "./chunk-FY6LQL2A.js";
|
|
44
49
|
|
|
45
50
|
// src/cli.ts
|
|
46
51
|
import { parseArgs as parseArgs2 } from "util";
|
|
47
|
-
import { mkdirSync as
|
|
48
|
-
import { join as
|
|
52
|
+
import { mkdirSync as mkdirSync3, writeFileSync as writeFileSync3, readFileSync as readFileSync3, statSync } from "fs";
|
|
53
|
+
import { join as join3, dirname as dirname2 } from "path";
|
|
49
54
|
import { fileURLToPath } from "url";
|
|
50
55
|
|
|
56
|
+
// src/init.ts
|
|
57
|
+
import { existsSync as existsSync2, mkdirSync as mkdirSync2, readFileSync as readFileSync2, writeFileSync as writeFileSync2 } from "fs";
|
|
58
|
+
import { dirname, join as join2, relative } from "path";
|
|
59
|
+
|
|
51
60
|
// src/scale-cli.ts
|
|
52
|
-
import { mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
61
|
+
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
53
62
|
import { join } from "path";
|
|
54
63
|
import { parseArgs } from "util";
|
|
55
64
|
var FORMATS = ["css", "tailwind-v4", "tailwind-v3", "dtcg", "json"];
|
|
@@ -60,26 +69,70 @@ var FILE_NAMES = {
|
|
|
60
69
|
dtcg: "scale.dtcg.json",
|
|
61
70
|
json: "scale.json"
|
|
62
71
|
};
|
|
63
|
-
var SCALE_HELP = `generate-tokens scale: the non-colour scale,
|
|
72
|
+
var SCALE_HELP = `generate-tokens scale: the non-colour scale, scaffolded once and then the project's own
|
|
64
73
|
|
|
65
|
-
generate-tokens scale --format tailwind-v4 --out app/styles/scale.css
|
|
66
|
-
generate-tokens scale --
|
|
67
|
-
generate-tokens scale --format all --out ./tokens
|
|
74
|
+
generate-tokens scale --init --format tailwind-v4 --out app/styles/scale.css
|
|
75
|
+
generate-tokens scale --verify app/styles/scale.css
|
|
68
76
|
|
|
69
77
|
Space (--spacing), size (--size-*), type sizes with their line height and tracking (--text-*,
|
|
70
78
|
--leading-*, --tracking-*, --font-weight-*), corners (--radius-*), elevation (--shadow-*),
|
|
71
79
|
motion (--duration-*, --ease-*), screen sizes (--breakpoint-*) and widths (--container-*).
|
|
72
|
-
The names are the contract; retune the values with --overrides, never by editing the file.
|
|
73
80
|
|
|
81
|
+
The scale is art direction, so it is written once and then edited by hand: nothing regenerates
|
|
82
|
+
it, and no overrides file tracks it. The names are the contract. Keep every one, and add new
|
|
83
|
+
ones only inside a tier's namespace; --verify (and designtools-manifest check) holds you to it.
|
|
84
|
+
|
|
85
|
+
--init Write the scale once. Refuses if the file exists: it is the project's.
|
|
86
|
+
--force With --init, write over an existing scale, after showing what changes.
|
|
87
|
+
--verify <file> Check a scale file's names against the contract. Exit 1 on a missing name,
|
|
88
|
+
or on one outside every tier. Values are never compared.
|
|
74
89
|
--format <fmt> css | tailwind-v4 | tailwind-v3 | dtcg | json | all. Default: css.
|
|
75
90
|
css writes screen sizes as @custom-media too, since a variable can't go in @media.
|
|
76
|
-
--overrides <file> JSON, by token name
|
|
77
|
-
"
|
|
78
|
-
A new name joins the tier its prefix belongs to
|
|
91
|
+
--overrides <file> JSON, by token name, to start --init from other values than the defaults:
|
|
92
|
+
{ "--radius-md": "0.5rem", "--text-5xl": { "value": "3rem", "description":
|
|
93
|
+
"48px: page titles" } }. A new name joins the tier its prefix belongs to.
|
|
79
94
|
--out <path> File to write, or a directory with --format all. Default: stdout.
|
|
80
|
-
|
|
81
|
-
|
|
95
|
+
|
|
96
|
+
Without --init, writing over a scale and --check still work, for projects that adopted the
|
|
97
|
+
scale before 0.14; both warn. Move to an owned scale: run --init --force once, delete the
|
|
98
|
+
overrides file, and drop the check.
|
|
82
99
|
`;
|
|
100
|
+
function valuesOf(css) {
|
|
101
|
+
return new Map([...css.matchAll(/(?:^|[;{\s])(--[\w-]+)\s*:\s*([^;]+);/g)].map((m) => [m[1], m[2].trim()]));
|
|
102
|
+
}
|
|
103
|
+
function describeChange(before, after) {
|
|
104
|
+
const was = valuesOf(before);
|
|
105
|
+
const now = valuesOf(after);
|
|
106
|
+
const lines = [];
|
|
107
|
+
for (const [name, value] of now) {
|
|
108
|
+
const old = was.get(name);
|
|
109
|
+
if (old === void 0) lines.push(` + ${name}: ${value}`);
|
|
110
|
+
else if (old !== value) lines.push(` ~ ${name}: ${old} -> ${value}`);
|
|
111
|
+
}
|
|
112
|
+
for (const name of was.keys()) if (!now.has(name)) lines.push(` - ${name}`);
|
|
113
|
+
return lines;
|
|
114
|
+
}
|
|
115
|
+
function verify(file, fail2) {
|
|
116
|
+
let css;
|
|
117
|
+
try {
|
|
118
|
+
css = readFileSync(file, "utf8");
|
|
119
|
+
} catch {
|
|
120
|
+
return fail2(`can't read ${file}`);
|
|
121
|
+
}
|
|
122
|
+
const { missing, strays, own } = verifyScale(css);
|
|
123
|
+
if (!isOwnedScale(css)) {
|
|
124
|
+
process.stderr.write(`verify: ${file} is not an owned scale yet; run generate-tokens scale --init --force once to adopt it
|
|
125
|
+
`);
|
|
126
|
+
}
|
|
127
|
+
for (const name of missing) process.stderr.write(`verify: ${file} is missing ${name}, a name the scale promises
|
|
128
|
+
`);
|
|
129
|
+
for (const name of strays) process.stderr.write(`verify: ${file} declares ${name}, which belongs to no tier of the scale
|
|
130
|
+
`);
|
|
131
|
+
if (missing.length || strays.length) return 1;
|
|
132
|
+
process.stderr.write(`verify: ${file} keeps the scale's names${own.length ? `, with ${own.length} of its own inside the tiers` : ""}
|
|
133
|
+
`);
|
|
134
|
+
return 0;
|
|
135
|
+
}
|
|
83
136
|
function runScale(argv, version) {
|
|
84
137
|
const fail2 = (message) => {
|
|
85
138
|
process.stderr.write(`generate-tokens scale: ${message}
|
|
@@ -95,6 +148,9 @@ function runScale(argv, version) {
|
|
|
95
148
|
overrides: { type: "string" },
|
|
96
149
|
out: { type: "string" },
|
|
97
150
|
check: { type: "boolean" },
|
|
151
|
+
init: { type: "boolean" },
|
|
152
|
+
force: { type: "boolean" },
|
|
153
|
+
verify: { type: "string" },
|
|
98
154
|
"no-provenance": { type: "boolean" },
|
|
99
155
|
help: { type: "boolean", short: "h" }
|
|
100
156
|
}
|
|
@@ -106,9 +162,12 @@ function runScale(argv, version) {
|
|
|
106
162
|
process.stdout.write(SCALE_HELP);
|
|
107
163
|
return 0;
|
|
108
164
|
}
|
|
165
|
+
if (values2.verify) return verify(values2.verify, fail2);
|
|
109
166
|
const format2 = values2.format ?? "css";
|
|
110
167
|
if (format2 !== "all" && !FORMATS.includes(format2)) return fail2(`--format must be one of ${[...FORMATS, "all"].join(", ")}`);
|
|
111
168
|
if (values2.check && !values2.out) return fail2("--check needs --out to compare against");
|
|
169
|
+
if (values2.force && !values2.init) return fail2("--force goes with --init");
|
|
170
|
+
if (values2.init && values2.check) return fail2("an owned scale has nothing to check against; use --verify");
|
|
112
171
|
let overrides2 = {};
|
|
113
172
|
if (values2.overrides) {
|
|
114
173
|
try {
|
|
@@ -123,10 +182,14 @@ function runScale(argv, version) {
|
|
|
123
182
|
} catch (err) {
|
|
124
183
|
return fail2(err instanceof Error ? err.message : String(err));
|
|
125
184
|
}
|
|
126
|
-
const header = values2["no-provenance"] ? void 0 : `/* Generated by @designtools/tokens v${version} (scale${values2.overrides ? `, overrides ${values2.overrides}` : ""}) - retune with --overrides, do not edit by hand */`;
|
|
185
|
+
const header = values2["no-provenance"] ? void 0 : values2.init ? ownedScaleHeader(version) : `/* Generated by @designtools/tokens v${version} (scale${values2.overrides ? `, overrides ${values2.overrides}` : ""}) - retune with --overrides, do not edit by hand */`;
|
|
127
186
|
const formats2 = format2 === "all" ? FORMATS.filter((f) => f !== "tailwind-v4") : [format2];
|
|
128
187
|
const target = (f) => format2 === "all" ? join(values2.out ?? ".", FILE_NAMES[f]) : values2.out;
|
|
188
|
+
const legacy = () => process.stderr.write(
|
|
189
|
+
"generate-tokens scale: regenerating the scale is deprecated; scaffold it once with --init and own the file (see --help)\n"
|
|
190
|
+
);
|
|
129
191
|
if (values2.check) {
|
|
192
|
+
legacy();
|
|
130
193
|
let ok = true;
|
|
131
194
|
for (const f of formats2) {
|
|
132
195
|
const want = exportScale(tiers, f, header);
|
|
@@ -147,20 +210,107 @@ function runScale(argv, version) {
|
|
|
147
210
|
process.stdout.write(exportScale(tiers, formats2[0], header));
|
|
148
211
|
return 0;
|
|
149
212
|
}
|
|
213
|
+
if (values2.init) {
|
|
214
|
+
for (const f of formats2) {
|
|
215
|
+
const path = target(f);
|
|
216
|
+
if (!existsSync(path)) continue;
|
|
217
|
+
const existing = readFileSync(path, "utf8");
|
|
218
|
+
if (!values2.force) {
|
|
219
|
+
return fail2(`${path} exists and is the project's own: edit it by hand, or pass --force to write over it`);
|
|
220
|
+
}
|
|
221
|
+
const changes = describeChange(existing, exportScale(tiers, f, header));
|
|
222
|
+
process.stderr.write(
|
|
223
|
+
changes.length ? `rewriting ${path}:
|
|
224
|
+
${changes.join("\n")}
|
|
225
|
+
` : `rewriting ${path}: the same names and values, now an owned scale
|
|
226
|
+
`
|
|
227
|
+
);
|
|
228
|
+
}
|
|
229
|
+
} else {
|
|
230
|
+
legacy();
|
|
231
|
+
}
|
|
150
232
|
if (format2 === "all") mkdirSync(values2.out, { recursive: true });
|
|
151
233
|
for (const f of formats2) {
|
|
152
234
|
writeFileSync(target(f), exportScale(tiers, f, header));
|
|
153
|
-
process.stderr.write(`wrote ${target(f)}
|
|
235
|
+
process.stderr.write(`wrote ${target(f)}${values2.init ? " (the project's now: edit it by hand)" : ""}
|
|
154
236
|
`);
|
|
155
237
|
}
|
|
156
238
|
return 0;
|
|
157
239
|
}
|
|
158
240
|
|
|
241
|
+
// src/init.ts
|
|
242
|
+
function take(args, flag) {
|
|
243
|
+
const i = args.findIndex((a) => a === flag || a.startsWith(`${flag}=`));
|
|
244
|
+
if (i === -1) return void 0;
|
|
245
|
+
const [arg] = args.splice(i, 1);
|
|
246
|
+
if (arg.includes("=")) return arg.slice(flag.length + 1);
|
|
247
|
+
return args.splice(i, 1)[0];
|
|
248
|
+
}
|
|
249
|
+
var ORDER = ["tokens.css", "tokens.local.css", "scale.css"];
|
|
250
|
+
function wire(entry, dir) {
|
|
251
|
+
const rel = (file) => {
|
|
252
|
+
const path = relative(dirname(entry), join2(dir, file)).replace(/\\/g, "/");
|
|
253
|
+
return path.startsWith(".") ? path : `./${path}`;
|
|
254
|
+
};
|
|
255
|
+
const imports = ORDER.map((file) => `@import "${rel(file)}";`);
|
|
256
|
+
let css = existsSync2(entry) ? readFileSync2(entry, "utf8") : '@import "tailwindcss";\n';
|
|
257
|
+
const missing = imports.filter((line) => !css.includes(line.slice(0, -1)));
|
|
258
|
+
if (!missing.length) {
|
|
259
|
+
process.stderr.write(`init: ${entry} already imports the tokens
|
|
260
|
+
`);
|
|
261
|
+
return;
|
|
262
|
+
}
|
|
263
|
+
const tailwind = /^@import\s+["']tailwindcss["'][^;\n]*;/m.exec(css);
|
|
264
|
+
const at = tailwind ? tailwind.index + tailwind[0].length : 0;
|
|
265
|
+
const rest = css.slice(at).replace(/^\n+/, "");
|
|
266
|
+
css = `${css.slice(0, at)}${at ? "\n\n" : ""}${missing.join("\n")}
|
|
267
|
+
${rest ? `
|
|
268
|
+
${rest}` : ""}`;
|
|
269
|
+
mkdirSync2(dirname(entry), { recursive: true });
|
|
270
|
+
writeFileSync2(entry, css);
|
|
271
|
+
process.stderr.write(`init: added ${missing.length} import${missing.length === 1 ? "" : "s"} to ${entry}
|
|
272
|
+
`);
|
|
273
|
+
}
|
|
274
|
+
function prepareInit(argv, version) {
|
|
275
|
+
const args = [...argv];
|
|
276
|
+
const dir = take(args, "--dir") ?? "app/styles";
|
|
277
|
+
const entry = take(args, "--entry");
|
|
278
|
+
mkdirSync2(dir, { recursive: true });
|
|
279
|
+
const scale = join2(dir, "scale.css");
|
|
280
|
+
if (existsSync2(scale)) {
|
|
281
|
+
process.stderr.write(`init: kept ${scale}: the scale is the project's own once written
|
|
282
|
+
`);
|
|
283
|
+
} else if (runScale(["--init", "--format", "tailwind-v4", "--out", scale], version) !== 0) {
|
|
284
|
+
return void 0;
|
|
285
|
+
}
|
|
286
|
+
const local = join2(dir, "tokens.local.css");
|
|
287
|
+
if (existsSync2(local)) process.stderr.write(`init: kept ${local}
|
|
288
|
+
`);
|
|
289
|
+
else {
|
|
290
|
+
writeFileSync2(local, LOCAL_TEMPLATE);
|
|
291
|
+
process.stderr.write(`wrote ${local} (empty: the overrides go here, checked on every run)
|
|
292
|
+
`);
|
|
293
|
+
}
|
|
294
|
+
if (entry) wire(entry, dir);
|
|
295
|
+
const has = (flag) => args.some((a) => a === flag || a.startsWith(`${flag}=`));
|
|
296
|
+
if (!has("--format")) args.push("--format", "tailwind-v4");
|
|
297
|
+
if (!has("--out")) args.push("--out", join2(dir, "tokens.css"));
|
|
298
|
+
if (!has("--local")) args.push("--local", local);
|
|
299
|
+
return args;
|
|
300
|
+
}
|
|
301
|
+
|
|
159
302
|
// src/cli.ts
|
|
160
303
|
var HELP = `generate-tokens \u2014 brand colour in, design tokens out
|
|
161
304
|
|
|
162
305
|
Usage:
|
|
163
306
|
generate-tokens --primary <colour> [options]
|
|
307
|
+
generate-tokens init --primary <colour> [options] [--dir <dir>] [--entry <stylesheet>]
|
|
308
|
+
Set a project up: the colour in tokens.css, the scale in
|
|
309
|
+
scale.css (written once, then the project's own) and an
|
|
310
|
+
empty tokens.local.css, in --dir (default app/styles).
|
|
311
|
+
--entry adds the three imports, in order, to a stylesheet.
|
|
312
|
+
generate-tokens scale --help
|
|
313
|
+
The non-colour scale.
|
|
164
314
|
|
|
165
315
|
Seeds:
|
|
166
316
|
--primary <colour> Brand colour (hex, rgb(), hsl(), oklch(), named). Required
|
|
@@ -306,7 +456,7 @@ Selection:
|
|
|
306
456
|
semantic intent tokens (primary, destructive, \u2026)
|
|
307
457
|
surface canvas / surface / overlay, each with its text and secondary text
|
|
308
458
|
utility border / input / ring / shadow
|
|
309
|
-
grounds
|
|
459
|
+
grounds the [data-surface] scopes
|
|
310
460
|
Keeps generated colour separable from hand-tuned files,
|
|
311
461
|
so a re-theme does not clobber them. Supported by the
|
|
312
462
|
css, tailwind-v4 and json formats.
|
|
@@ -342,6 +492,19 @@ Output:
|
|
|
342
492
|
makes --check able to distinguish a generator upgrade
|
|
343
493
|
from a hand edit, so dropping it costs you that.
|
|
344
494
|
|
|
495
|
+
Overrides:
|
|
496
|
+
--local <file> The project's overrides of the generated colour, loaded
|
|
497
|
+
after tokens.css: the one place for a value no flag or the
|
|
498
|
+
seed can say. Checked on every run, with or without
|
|
499
|
+
--check: only the generator's selectors (:root,
|
|
500
|
+
[data-theme], .dark, [data-surface="<ground>"]), only its
|
|
501
|
+
token names (never a --color- alias or a ramp step), and
|
|
502
|
+
values that point at the system (var(), or a ramp step
|
|
503
|
+
nudged with oklch(from \u2026)), never a literal colour. Each
|
|
504
|
+
override is listed as pinned by hand, and each pair it
|
|
505
|
+
touches is re-checked for contrast at --target. Exit 1 on
|
|
506
|
+
any problem.
|
|
507
|
+
|
|
345
508
|
Verification:
|
|
346
509
|
--check Regenerate in memory and compare against what is already
|
|
347
510
|
at --out. Writes nothing. Exit 0 if identical, 1 if it
|
|
@@ -377,13 +540,18 @@ var FILE_NAMES2 = {
|
|
|
377
540
|
};
|
|
378
541
|
var VERSION = (() => {
|
|
379
542
|
try {
|
|
380
|
-
const here =
|
|
381
|
-
return JSON.parse(
|
|
543
|
+
const here = dirname2(fileURLToPath(import.meta.url));
|
|
544
|
+
return JSON.parse(readFileSync3(join3(here, "../package.json"), "utf8")).version;
|
|
382
545
|
} catch {
|
|
383
546
|
return "0.0.0";
|
|
384
547
|
}
|
|
385
548
|
})();
|
|
386
549
|
if (process.argv[2] === "scale") process.exit(runScale(process.argv.slice(3), VERSION));
|
|
550
|
+
if (process.argv[2] === "init") {
|
|
551
|
+
const colour = prepareInit(process.argv.slice(3), VERSION);
|
|
552
|
+
if (colour === void 0) process.exit(1);
|
|
553
|
+
process.argv.splice(2, process.argv.length - 2, ...colour);
|
|
554
|
+
}
|
|
387
555
|
function fail(message) {
|
|
388
556
|
process.stderr.write(`generate-tokens: ${message}
|
|
389
557
|
`);
|
|
@@ -402,6 +570,7 @@ try {
|
|
|
402
570
|
overlay: { type: "string" },
|
|
403
571
|
background: { type: "string", multiple: true },
|
|
404
572
|
usage: { type: "string" },
|
|
573
|
+
local: { type: "string" },
|
|
405
574
|
contrast: { type: "string" },
|
|
406
575
|
target: { type: "string" },
|
|
407
576
|
lightness: { type: "string" },
|
|
@@ -457,14 +626,14 @@ if (values.help) {
|
|
|
457
626
|
var seed = {};
|
|
458
627
|
if (values.stdin) {
|
|
459
628
|
try {
|
|
460
|
-
seed = JSON.parse(
|
|
629
|
+
seed = JSON.parse(readFileSync3(0, "utf8"));
|
|
461
630
|
} catch (err) {
|
|
462
631
|
fail(`could not read seed from stdin: ${err instanceof Error ? err.message : String(err)}`);
|
|
463
632
|
}
|
|
464
633
|
}
|
|
465
634
|
if (values.seed) {
|
|
466
635
|
try {
|
|
467
|
-
seed = JSON.parse(
|
|
636
|
+
seed = JSON.parse(readFileSync3(values.seed, "utf8"));
|
|
468
637
|
} catch (err) {
|
|
469
638
|
fail(`could not read --seed file: ${err instanceof Error ? err.message : String(err)}`);
|
|
470
639
|
}
|
|
@@ -752,7 +921,7 @@ var overrides = {
|
|
|
752
921
|
};
|
|
753
922
|
if (values.overrides) {
|
|
754
923
|
try {
|
|
755
|
-
overrides = JSON.parse(
|
|
924
|
+
overrides = JSON.parse(readFileSync3(values.overrides, "utf8"));
|
|
756
925
|
} catch (err) {
|
|
757
926
|
fail(`could not read --overrides file: ${err instanceof Error ? err.message : String(err)}`);
|
|
758
927
|
}
|
|
@@ -938,7 +1107,7 @@ ${body}`;
|
|
|
938
1107
|
}
|
|
939
1108
|
function targetPath(fmt, out) {
|
|
940
1109
|
try {
|
|
941
|
-
if (statSync(out).isDirectory()) return
|
|
1110
|
+
if (statSync(out).isDirectory()) return join3(out, FILE_NAMES2[fmt]);
|
|
942
1111
|
} catch {
|
|
943
1112
|
}
|
|
944
1113
|
return out;
|
|
@@ -946,7 +1115,7 @@ function targetPath(fmt, out) {
|
|
|
946
1115
|
function check(fmt, target) {
|
|
947
1116
|
let existing;
|
|
948
1117
|
try {
|
|
949
|
-
existing =
|
|
1118
|
+
existing = readFileSync3(target, "utf8");
|
|
950
1119
|
} catch {
|
|
951
1120
|
process.stderr.write(`check: ${target} does not exist
|
|
952
1121
|
`);
|
|
@@ -1202,7 +1371,7 @@ function reportExternalReferences(css, merged) {
|
|
|
1202
1371
|
function checkSlice(target, slice) {
|
|
1203
1372
|
let existing;
|
|
1204
1373
|
try {
|
|
1205
|
-
existing =
|
|
1374
|
+
existing = readFileSync3(target, "utf8");
|
|
1206
1375
|
} catch {
|
|
1207
1376
|
process.stderr.write(`check: ${target} does not exist
|
|
1208
1377
|
`);
|
|
@@ -1236,7 +1405,7 @@ function checkUsage() {
|
|
|
1236
1405
|
if (!values.usage) return true;
|
|
1237
1406
|
let existing = "";
|
|
1238
1407
|
try {
|
|
1239
|
-
existing =
|
|
1408
|
+
existing = readFileSync3(values.usage, "utf8");
|
|
1240
1409
|
} catch {
|
|
1241
1410
|
process.stderr.write(`check: ${values.usage} is missing
|
|
1242
1411
|
`);
|
|
@@ -1251,18 +1420,45 @@ function checkUsage() {
|
|
|
1251
1420
|
`);
|
|
1252
1421
|
return false;
|
|
1253
1422
|
}
|
|
1423
|
+
function checkLocal() {
|
|
1424
|
+
if (!values.local) return true;
|
|
1425
|
+
if (isSlice) {
|
|
1426
|
+
process.stderr.write(`local: ${values.local} is checked on a full run, not a partial one
|
|
1427
|
+
`);
|
|
1428
|
+
return true;
|
|
1429
|
+
}
|
|
1430
|
+
let local = "";
|
|
1431
|
+
try {
|
|
1432
|
+
local = readFileSync3(values.local, "utf8");
|
|
1433
|
+
} catch {
|
|
1434
|
+
process.stderr.write(`local: ${values.local} is missing
|
|
1435
|
+
`);
|
|
1436
|
+
return false;
|
|
1437
|
+
}
|
|
1438
|
+
const generated = serialise(SECTIONED_FORMATS.includes(format) ? format : "css");
|
|
1439
|
+
const { overrides: overrides2, problems } = checkLocalOverrides(generated, local, contrastTarget);
|
|
1440
|
+
for (const o of overrides2) process.stderr.write(`local: pinned by hand: ${o.name} in ${o.selector}
|
|
1441
|
+
`);
|
|
1442
|
+
for (const p of problems) process.stderr.write(`local: ${values.local}: ${p.message}
|
|
1443
|
+
`);
|
|
1444
|
+
if (!problems.length) process.stderr.write(`local: ${values.local} keeps to the system (${overrides2.length} pinned)
|
|
1445
|
+
`);
|
|
1446
|
+
return problems.length === 0;
|
|
1447
|
+
}
|
|
1254
1448
|
if (values.check) {
|
|
1255
1449
|
const out = values.out;
|
|
1256
1450
|
if (isSlice) {
|
|
1257
|
-
process.exit(
|
|
1451
|
+
process.exit(
|
|
1452
|
+
checkSlice(targetPath(format, out), serialise(format)) && checkUsage() && checkLocal() ? 0 : 1
|
|
1453
|
+
);
|
|
1258
1454
|
}
|
|
1259
|
-
const ok = formats.map((fmt) => check(fmt, format === "all" ?
|
|
1260
|
-
process.exit(ok.every(Boolean) && checkUsage() ? 0 : 1);
|
|
1455
|
+
const ok = formats.map((fmt) => check(fmt, format === "all" ? join3(out, FILE_NAMES2[fmt]) : targetPath(fmt, out)));
|
|
1456
|
+
process.exit(ok.every(Boolean) && checkUsage() && checkLocal() ? 0 : 1);
|
|
1261
1457
|
} else if (values.merge) {
|
|
1262
1458
|
const target = targetPath(format, values.out);
|
|
1263
1459
|
let existing;
|
|
1264
1460
|
try {
|
|
1265
|
-
existing =
|
|
1461
|
+
existing = readFileSync3(target, "utf8");
|
|
1266
1462
|
} catch (err) {
|
|
1267
1463
|
fail(`--merge needs an existing file at ${target}: ${err instanceof Error ? err.message : String(err)}`);
|
|
1268
1464
|
}
|
|
@@ -1273,7 +1469,7 @@ if (values.check) {
|
|
|
1273
1469
|
`--merge cannot place ${result.missingBlocks.length} block(s) absent from ${target}: ` + result.missingBlocks.join(", ")
|
|
1274
1470
|
);
|
|
1275
1471
|
}
|
|
1276
|
-
|
|
1472
|
+
writeFileSync3(target, result.css);
|
|
1277
1473
|
process.stderr.write(
|
|
1278
1474
|
`merged into ${target}: ${result.updated.length} updated, ${result.added.length} added, ${result.unchanged.length} already current
|
|
1279
1475
|
`
|
|
@@ -1281,10 +1477,10 @@ if (values.check) {
|
|
|
1281
1477
|
reportExternalReferences(slice, { target, css: result.css });
|
|
1282
1478
|
} else if (format === "all") {
|
|
1283
1479
|
const dir = values.out ?? ".";
|
|
1284
|
-
|
|
1480
|
+
mkdirSync3(dir, { recursive: true });
|
|
1285
1481
|
for (const fmt of formats) {
|
|
1286
|
-
const target =
|
|
1287
|
-
|
|
1482
|
+
const target = join3(dir, FILE_NAMES2[fmt]);
|
|
1483
|
+
writeFileSync3(target, serialise(fmt) + "\n");
|
|
1288
1484
|
process.stderr.write(`wrote ${target}
|
|
1289
1485
|
`);
|
|
1290
1486
|
}
|
|
@@ -1292,7 +1488,7 @@ if (values.check) {
|
|
|
1292
1488
|
const output = serialise(format) + "\n";
|
|
1293
1489
|
if (values.out) {
|
|
1294
1490
|
const target = targetPath(format, values.out);
|
|
1295
|
-
|
|
1491
|
+
writeFileSync3(target, output);
|
|
1296
1492
|
process.stderr.write(`wrote ${target}
|
|
1297
1493
|
`);
|
|
1298
1494
|
} else {
|
|
@@ -1301,7 +1497,8 @@ if (values.check) {
|
|
|
1301
1497
|
if (isSlice && SECTIONED_FORMATS.includes(format)) reportExternalReferences(output);
|
|
1302
1498
|
}
|
|
1303
1499
|
if (values.usage && !values.check) {
|
|
1304
|
-
|
|
1500
|
+
writeFileSync3(values.usage, usageText);
|
|
1305
1501
|
process.stderr.write(`wrote ${values.usage}
|
|
1306
1502
|
`);
|
|
1307
1503
|
}
|
|
1504
|
+
if (!values.check && !checkLocal()) process.exit(1);
|
package/dist/index.d.ts
CHANGED
|
@@ -1264,6 +1264,47 @@ interface ContractBreak {
|
|
|
1264
1264
|
/** Every step whose promise differs between colours, light to dark. Empty when every step means the same everywhere. */
|
|
1265
1265
|
declare function stepContract(palette: PrimitivePalette): ContractBreak[];
|
|
1266
1266
|
|
|
1267
|
+
/**
|
|
1268
|
+
* The one sanctioned place to override the generated colour: a project's `tokens.local.css`, loaded
|
|
1269
|
+
* straight after `tokens.css`. It exists for the few values a flag or the seed can't say, and it is held
|
|
1270
|
+
* to the system's own terms, so every project overrides the same way:
|
|
1271
|
+
*
|
|
1272
|
+
* - selectors are the generator's own: `:root`, `[data-theme="light"]`, `[data-theme="dark"]`, `.dark`,
|
|
1273
|
+
* and `[data-surface="<ground>"]` (or `"canvas"`, the page), alone or in a list; no at-rules;
|
|
1274
|
+
* - names are tokens the generator writes; never a `--color-*` alias or ramp step (a ramp step is moved
|
|
1275
|
+
* with shade overrides, a token by setting the token itself), and never a new name;
|
|
1276
|
+
* - values point at the system: `var()` references, a ramp step nudged with relative colour
|
|
1277
|
+
* (`oklch(from var(--color-…) …)`) or mixed (`color-mix()`); never a literal colour.
|
|
1278
|
+
*
|
|
1279
|
+
* `checkLocalOverrides` reports every override as pinned by hand and re-checks contrast for each pair an
|
|
1280
|
+
* override touches, so a pinned surface can't quietly fail its text.
|
|
1281
|
+
*/
|
|
1282
|
+
interface LocalOverride {
|
|
1283
|
+
selector: string;
|
|
1284
|
+
name: string;
|
|
1285
|
+
value: string;
|
|
1286
|
+
}
|
|
1287
|
+
interface LocalProblem {
|
|
1288
|
+
kind: "selector" | "name" | "value" | "contrast" | "syntax";
|
|
1289
|
+
message: string;
|
|
1290
|
+
}
|
|
1291
|
+
interface LocalReport {
|
|
1292
|
+
overrides: LocalOverride[];
|
|
1293
|
+
problems: LocalProblem[];
|
|
1294
|
+
}
|
|
1295
|
+
declare const TARGETS: {
|
|
1296
|
+
readonly "aa-large": 3;
|
|
1297
|
+
readonly aa: 4.5;
|
|
1298
|
+
readonly aaa: 7;
|
|
1299
|
+
};
|
|
1300
|
+
/**
|
|
1301
|
+
* Check a project's overrides against the system and against contrast. `generated` is the tokens file
|
|
1302
|
+
* the generator writes (css or tailwind-v4); `local` is the override file.
|
|
1303
|
+
*/
|
|
1304
|
+
declare function checkLocalOverrides(generated: string, local: string, target?: keyof typeof TARGETS): LocalReport;
|
|
1305
|
+
/** The file `init` writes: empty, with its rules at the head. */
|
|
1306
|
+
declare const LOCAL_TEMPLATE = "/* tokens.local.css: the project's overrides of the generated colour, loaded after tokens.css.\n Most changes are an input instead (a flag, the seed, shade overrides): use this only for a value\n the generator can't say. generate-tokens --local checks it against the system:\n - selectors: :root, [data-theme=\"light\"], [data-theme=\"dark\"], .dark, [data-surface=\"<ground>\"];\n - names: tokens the generator writes (never a --color- alias or ramp step, never a new name);\n - values: var() references, or a ramp step nudged with oklch(from var(--color-\u2026) \u2026); never a literal colour.\n Each override is reported as pinned by hand, and the pairs it touches are re-checked for contrast. */\n";
|
|
1307
|
+
|
|
1267
1308
|
/**
|
|
1268
1309
|
* The non-colour scale: space, size, type, radius, shadow, motion, screen sizes and widths. The colour
|
|
1269
1310
|
* generator works a palette out from a seed; the scale has no seed, so this is a set of defaults, written
|
|
@@ -1305,5 +1346,29 @@ type ScaleOverride = string | {
|
|
|
1305
1346
|
declare function applyScaleOverrides(tiers: ScaleTier[], overrides: Record<string, ScaleOverride>): ScaleTier[];
|
|
1306
1347
|
type ScaleFormat = "css" | "tailwind-v4" | "tailwind-v3" | "dtcg" | "json";
|
|
1307
1348
|
declare function exportScale(tiers: ScaleTier[], format: ScaleFormat, header?: string): string;
|
|
1349
|
+
/**
|
|
1350
|
+
* The mark an owned scale carries: written once by `generate-tokens scale --init` (or `init`), then the
|
|
1351
|
+
* project's file, edited by hand and never regenerated. The values are the project's; the names are the
|
|
1352
|
+
* contract, which `verifyScale` checks.
|
|
1353
|
+
*/
|
|
1354
|
+
declare const OWNED_SCALE_MARK = "@designtools/tokens scale";
|
|
1355
|
+
/** The header an owned scale opens with. */
|
|
1356
|
+
declare function ownedScaleHeader(version: string): string;
|
|
1357
|
+
/** Whether a stylesheet is an owned scale. */
|
|
1358
|
+
declare function isOwnedScale(css: string): boolean;
|
|
1359
|
+
interface ScaleVerdict {
|
|
1360
|
+
/** Names the scale promises that the file no longer has. */
|
|
1361
|
+
missing: string[];
|
|
1362
|
+
/** Names that belong to no tier: a second system beside the scale. */
|
|
1363
|
+
strays: string[];
|
|
1364
|
+
/** Names the project added inside a tier: its own steps, which are fine. */
|
|
1365
|
+
own: string[];
|
|
1366
|
+
}
|
|
1367
|
+
/**
|
|
1368
|
+
* Check a scale file's names against the contract: every default name is still there, and every
|
|
1369
|
+
* name the project added sits inside a tier's namespace. Values are never compared; they are the
|
|
1370
|
+
* project's. Reads the custom properties declared anywhere in the file.
|
|
1371
|
+
*/
|
|
1372
|
+
declare function verifyScale(css: string): ScaleVerdict;
|
|
1308
1373
|
|
|
1309
|
-
export { ALIAS_PAIRS, type APCAContrastResult, APCAUnavailableError, type BrandColors, type CVDType, type ChromaProfile, type ChromaShape, type ColorFormat, type ColorScale, type ContractBreak, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type FamilyShape, type ForegroundRef, GENERATOR_NAME, GROUND_BASE_TOKENS, GROUND_COLOR_PARTS, GROUND_SELECTOR, type Gamut, type GamutTokens, type GenerationOptions, type GroundAction, type GroundColour, type GroundFill, type GroundRef, type GroundSpec, type GroundTokens, type HueDrift, type LightnessStrategy, type MergeResult, type PageContrast, type PageSurface, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleFormat, type ScaleOptions, type ScaleOverride, type ScaleTier, type ScaleTierId, type ScaleToken, type SeedFile, type SelectedTokens, type SemanticColorPair, type SemanticGamuts, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SliceDiff, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, TAILWIND_SHADES, TOKEN_SECTIONS, type TokenSection, type TokenSystem, type UsageReport, type UsageVerdict, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, WIDE_GAMUT_QUERY, adjustChroma, adjustLightness, aliasOf, applyScaleOverrides, checkRampChroma, checkSemanticContrast, checkSemanticContrastAPCA, checkSurfaceContrast, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, defaultScale, diffSlice, exportScale, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, externalReferences, familiesOf, familySeedShade, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, formatOklchInGamut, generateColorScale, generateColorScaleAPCA, generateGroundTokens, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, groundTokenNames, isAPCAAvailable, isInGamut, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, modeSelectors, oklchToHex, parseProvenance, parseToOklch, provenanceComment, rangeOf, readDeclarations, reanchorFactors, reservedSurfaceNames, resolveShades, seedFingerprint, selectTokenSections, serialiseUsage, simulateCVD, snapShade, stableStringify, stepContract, suggestStep, tokenFamilies, usageReport, withJsonProvenance };
|
|
1374
|
+
export { ALIAS_PAIRS, type APCAContrastResult, APCAUnavailableError, type BrandColors, type CVDType, type ChromaProfile, type ChromaShape, type ColorFormat, type ColorScale, type ContractBreak, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type FamilyShape, type ForegroundRef, GENERATOR_NAME, GROUND_BASE_TOKENS, GROUND_COLOR_PARTS, GROUND_SELECTOR, type Gamut, type GamutTokens, type GenerationOptions, type GroundAction, type GroundColour, type GroundFill, type GroundRef, type GroundSpec, type GroundTokens, type HueDrift, LOCAL_TEMPLATE, type LightnessStrategy, type LocalOverride, type LocalProblem, type LocalReport, type MergeResult, OWNED_SCALE_MARK, type PageContrast, type PageSurface, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleFormat, type ScaleOptions, type ScaleOverride, type ScaleTier, type ScaleTierId, type ScaleToken, type ScaleVerdict, type SeedFile, type SelectedTokens, type SemanticColorPair, type SemanticGamuts, type SemanticShadeOverrides, type SemanticTokens, type ShadeNumber, type SliceDiff, type SurfaceRef, type SurfaceShadeOverrides, type SurfaceTokens, TAILWIND_SHADES, TOKEN_SECTIONS, type TokenSection, type TokenSystem, type UsageReport, type UsageVerdict, type UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, WIDE_GAMUT_QUERY, adjustChroma, adjustLightness, aliasOf, applyScaleOverrides, checkLocalOverrides, checkRampChroma, checkSemanticContrast, checkSemanticContrastAPCA, checkSurfaceContrast, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, defaultScale, diffSlice, exportScale, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, externalReferences, familiesOf, familySeedShade, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, formatOklchInGamut, generateColorScale, generateColorScaleAPCA, generateGroundTokens, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, groundTokenNames, isAPCAAvailable, isInGamut, isOwnedScale, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, modeSelectors, oklchToHex, ownedScaleHeader, parseProvenance, parseToOklch, provenanceComment, rangeOf, readDeclarations, reanchorFactors, reservedSurfaceNames, resolveShades, seedFingerprint, selectTokenSections, serialiseUsage, simulateCVD, snapShade, stableStringify, stepContract, suggestStep, tokenFamilies, usageReport, verifyScale, withJsonProvenance };
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
GROUND_BASE_TOKENS,
|
|
8
8
|
GROUND_COLOR_PARTS,
|
|
9
9
|
GROUND_SELECTOR,
|
|
10
|
+
LOCAL_TEMPLATE,
|
|
11
|
+
OWNED_SCALE_MARK,
|
|
10
12
|
SECTIONED_FORMATS,
|
|
11
13
|
SHADE_PRESETS,
|
|
12
14
|
TAILWIND_SHADES,
|
|
@@ -17,6 +19,7 @@ import {
|
|
|
17
19
|
adjustLightness,
|
|
18
20
|
aliasOf,
|
|
19
21
|
applyScaleOverrides,
|
|
22
|
+
checkLocalOverrides,
|
|
20
23
|
checkRampChroma,
|
|
21
24
|
checkSemanticContrast,
|
|
22
25
|
checkSemanticContrastAPCA,
|
|
@@ -56,11 +59,13 @@ import {
|
|
|
56
59
|
groundTokenNames,
|
|
57
60
|
isAPCAAvailable,
|
|
58
61
|
isInGamut,
|
|
62
|
+
isOwnedScale,
|
|
59
63
|
meetsWCAG_AA,
|
|
60
64
|
meetsWCAG_AAA,
|
|
61
65
|
mergeSlice,
|
|
62
66
|
modeSelectors,
|
|
63
67
|
oklchToHex,
|
|
68
|
+
ownedScaleHeader,
|
|
64
69
|
parseProvenance,
|
|
65
70
|
parseToOklch,
|
|
66
71
|
provenanceComment,
|
|
@@ -79,8 +84,9 @@ import {
|
|
|
79
84
|
suggestStep,
|
|
80
85
|
tokenFamilies,
|
|
81
86
|
usageReport,
|
|
87
|
+
verifyScale,
|
|
82
88
|
withJsonProvenance
|
|
83
|
-
} from "./chunk-
|
|
89
|
+
} from "./chunk-FY6LQL2A.js";
|
|
84
90
|
export {
|
|
85
91
|
ALIAS_PAIRS,
|
|
86
92
|
APCAUnavailableError,
|
|
@@ -90,6 +96,8 @@ export {
|
|
|
90
96
|
GROUND_BASE_TOKENS,
|
|
91
97
|
GROUND_COLOR_PARTS,
|
|
92
98
|
GROUND_SELECTOR,
|
|
99
|
+
LOCAL_TEMPLATE,
|
|
100
|
+
OWNED_SCALE_MARK,
|
|
93
101
|
SECTIONED_FORMATS,
|
|
94
102
|
SHADE_PRESETS,
|
|
95
103
|
TAILWIND_SHADES,
|
|
@@ -100,6 +108,7 @@ export {
|
|
|
100
108
|
adjustLightness,
|
|
101
109
|
aliasOf,
|
|
102
110
|
applyScaleOverrides,
|
|
111
|
+
checkLocalOverrides,
|
|
103
112
|
checkRampChroma,
|
|
104
113
|
checkSemanticContrast,
|
|
105
114
|
checkSemanticContrastAPCA,
|
|
@@ -139,11 +148,13 @@ export {
|
|
|
139
148
|
groundTokenNames,
|
|
140
149
|
isAPCAAvailable,
|
|
141
150
|
isInGamut,
|
|
151
|
+
isOwnedScale,
|
|
142
152
|
meetsWCAG_AA,
|
|
143
153
|
meetsWCAG_AAA,
|
|
144
154
|
mergeSlice,
|
|
145
155
|
modeSelectors,
|
|
146
156
|
oklchToHex,
|
|
157
|
+
ownedScaleHeader,
|
|
147
158
|
parseProvenance,
|
|
148
159
|
parseToOklch,
|
|
149
160
|
provenanceComment,
|
|
@@ -162,5 +173,6 @@ export {
|
|
|
162
173
|
suggestStep,
|
|
163
174
|
tokenFamilies,
|
|
164
175
|
usageReport,
|
|
176
|
+
verifyScale,
|
|
165
177
|
withJsonProvenance
|
|
166
178
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@designtools/tokens",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.15.0",
|
|
4
4
|
"description": "Turn one brand colour into a complete design-token system: perceptual OKLCH ramps, contrast-checked semantic tokens (WCAG or APCA), light and dark, as CSS custom properties, Tailwind v4/v3 or DTCG. Deterministic CLI, safe for agents.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|