@designtools/tokens 0.11.0 → 0.12.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/dist/cli.js CHANGED
@@ -6,13 +6,16 @@ import {
6
6
  SHADE_PRESETS,
7
7
  TOKEN_SECTIONS,
8
8
  VALID_SHADES,
9
+ applyScaleOverrides,
9
10
  bridgeShade,
10
11
  checkRampChroma,
11
12
  checkSemanticContrast,
12
13
  checkSemanticContrastAPCA,
13
14
  checkSurfaceContrast,
14
15
  computeAccessibilityScore,
16
+ defaultScale,
15
17
  diffSlice,
18
+ exportScale,
16
19
  exportTokens,
17
20
  extendedBridgeShades,
18
21
  externalReferences,
@@ -33,16 +36,127 @@ import {
33
36
  serialiseUsage,
34
37
  snapShade,
35
38
  stepContract,
39
+ suggestStep,
36
40
  tokenFamilies,
37
41
  usageReport,
38
42
  withJsonProvenance
39
- } from "./chunk-RQGC7LES.js";
43
+ } from "./chunk-TRGCDLOM.js";
40
44
 
41
45
  // src/cli.ts
42
- import { parseArgs } from "util";
43
- import { mkdirSync, writeFileSync, readFileSync, statSync } from "fs";
44
- import { join, dirname } from "path";
46
+ import { parseArgs as parseArgs2 } from "util";
47
+ import { mkdirSync as mkdirSync2, writeFileSync as writeFileSync2, readFileSync as readFileSync2, statSync } from "fs";
48
+ import { join as join2, dirname } from "path";
45
49
  import { fileURLToPath } from "url";
50
+
51
+ // src/scale-cli.ts
52
+ import { mkdirSync, readFileSync, writeFileSync } from "fs";
53
+ import { join } from "path";
54
+ import { parseArgs } from "util";
55
+ var FORMATS = ["css", "tailwind-v4", "tailwind-v3", "dtcg", "json"];
56
+ var FILE_NAMES = {
57
+ css: "scale.css",
58
+ "tailwind-v4": "scale.css",
59
+ "tailwind-v3": "tailwind.scale.js",
60
+ dtcg: "scale.dtcg.json",
61
+ json: "scale.json"
62
+ };
63
+ var SCALE_HELP = `generate-tokens scale: the non-colour scale, from defaults and your overrides
64
+
65
+ generate-tokens scale --format tailwind-v4 --out app/styles/scale.css
66
+ generate-tokens scale --format css --overrides scale.overrides.json --out src/scale.css
67
+ generate-tokens scale --format all --out ./tokens
68
+
69
+ Space (--spacing), size (--size-*), type sizes with their line height and tracking (--text-*,
70
+ --leading-*, --tracking-*, --font-weight-*), corners (--radius-*), elevation (--shadow-*),
71
+ 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
+
74
+ --format <fmt> css | tailwind-v4 | tailwind-v3 | dtcg | json | all. Default: css.
75
+ css writes screen sizes as @custom-media too, since a variable can't go in @media.
76
+ --overrides <file> JSON, by token name: { "--radius-md": "0.5rem", "--text-5xl": { "value":
77
+ "3rem", "description": "48px: page titles" }, "--leading-relaxed": null }.
78
+ A new name joins the tier its prefix belongs to; null removes a token.
79
+ --out <path> File to write, or a directory with --format all. Default: stdout.
80
+ --check Compare against the file at --out instead of writing it. Exit 1 if it differs.
81
+ --no-provenance Leave out the "Generated by" header.
82
+ `;
83
+ function runScale(argv, version) {
84
+ const fail2 = (message) => {
85
+ process.stderr.write(`generate-tokens scale: ${message}
86
+ `);
87
+ return 1;
88
+ };
89
+ let values2;
90
+ try {
91
+ ({ values: values2 } = parseArgs({
92
+ args: argv,
93
+ options: {
94
+ format: { type: "string" },
95
+ overrides: { type: "string" },
96
+ out: { type: "string" },
97
+ check: { type: "boolean" },
98
+ "no-provenance": { type: "boolean" },
99
+ help: { type: "boolean", short: "h" }
100
+ }
101
+ }));
102
+ } catch (err) {
103
+ return fail2(err instanceof Error ? err.message : String(err));
104
+ }
105
+ if (values2.help) {
106
+ process.stdout.write(SCALE_HELP);
107
+ return 0;
108
+ }
109
+ const format2 = values2.format ?? "css";
110
+ if (format2 !== "all" && !FORMATS.includes(format2)) return fail2(`--format must be one of ${[...FORMATS, "all"].join(", ")}`);
111
+ if (values2.check && !values2.out) return fail2("--check needs --out to compare against");
112
+ let overrides2 = {};
113
+ if (values2.overrides) {
114
+ try {
115
+ overrides2 = JSON.parse(readFileSync(values2.overrides, "utf8"));
116
+ } catch (err) {
117
+ return fail2(`can't read --overrides ${values2.overrides}: ${err instanceof Error ? err.message : String(err)}`);
118
+ }
119
+ }
120
+ let tiers;
121
+ try {
122
+ tiers = applyScaleOverrides(defaultScale(), overrides2);
123
+ } catch (err) {
124
+ return fail2(err instanceof Error ? err.message : String(err));
125
+ }
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 */`;
127
+ const formats2 = format2 === "all" ? FORMATS.filter((f) => f !== "tailwind-v4") : [format2];
128
+ const target = (f) => format2 === "all" ? join(values2.out ?? ".", FILE_NAMES[f]) : values2.out;
129
+ if (values2.check) {
130
+ let ok = true;
131
+ for (const f of formats2) {
132
+ const want = exportScale(tiers, f, header);
133
+ let have = "";
134
+ try {
135
+ have = readFileSync(target(f), "utf8");
136
+ } catch {
137
+ }
138
+ const same = have === want;
139
+ process.stderr.write(same ? `check: ${target(f)} up to date
140
+ ` : `check: ${target(f)} differs from the scale and its overrides; regenerate it
141
+ `);
142
+ ok &&= same;
143
+ }
144
+ return ok ? 0 : 1;
145
+ }
146
+ if (!values2.out) {
147
+ process.stdout.write(exportScale(tiers, formats2[0], header));
148
+ return 0;
149
+ }
150
+ if (format2 === "all") mkdirSync(values2.out, { recursive: true });
151
+ for (const f of formats2) {
152
+ writeFileSync(target(f), exportScale(tiers, f, header));
153
+ process.stderr.write(`wrote ${target(f)}
154
+ `);
155
+ }
156
+ return 0;
157
+ }
158
+
159
+ // src/cli.ts
46
160
  var HELP = `generate-tokens \u2014 brand colour in, design tokens out
47
161
 
48
162
  Usage:
@@ -68,22 +182,34 @@ Seeds:
68
182
  The page, card and overlay backgrounds as exact colours
69
183
  (light, then dark after a slash), in place of the
70
184
  neutral steps they default to. Text on each is measured.
71
- --background <name>=<colour>[/<dark>]
72
- A colour a whole section is painted with (a band on a
73
- marketing page), not a ramp: --surface-<name> with
74
- measured text, and a ground. Inside data-surface="<name>"
75
- every token (buttons, muted text, borders, inputs, the
76
- ring, status text) is searched again against it, so
77
- components need no change. Repeatable. A name a token or
78
- ground already uses (canvas, primary, warning-subdued\u2026)
79
- is refused.
80
- --grounds <full|text|none>
81
- What data-surface gives each ground. full (default):
82
- every token, tinted to the ground and contrast-checked
83
- on it. text: the background and its text only; buttons,
84
- borders and the rest keep the page's. none: no grounds.
185
+ --page-surface <name>=<ramp>@<step>[/<ramp>@<step>]
186
+ Another page surface beside canvas, surface and overlay:
187
+ a sunken well, a raised panel, an alternate section. A
188
+ step for light, then dark (default: the light step's
189
+ mirror, 100 to 800). Follows the mode. Emitted as
190
+ --<name> with measured --<name>-foreground, and every
191
+ page token is searched to work on it. Repeatable.
192
+ --ground <name>=<ramp>@<step>
193
+ A section painted one step of a ramp (a --color, often
194
+ --decorative, or primary for a brand band), the same in
195
+ light and dark mode. Inside data-surface="<name>",
196
+ content reads tokens that work on it: the page's of the
197
+ ground's polarity, and what --ground-tint and
198
+ --ground-text change. Repeatable.
199
+ --ground-tint <fill> or <name>=<fill>
200
+ Where a ground's lines, panels, card, input edge, ring
201
+ and buttons come from. own (default): steps on its
202
+ ramp, each searched to its floor. page: the page's.
203
+ Or one colour for every line, edge and ring: white,
204
+ black, or a step (sage-100). A bare value sets every
205
+ ground; name=value one, and wins. Repeatable.
206
+ --ground-text <fill> or <name>=<fill>
207
+ Where a ground's body and secondary text come from. page
208
+ (default): the page's, where it reads; white or black
209
+ where it doesn't. own: steps on its ramp. Or one
210
+ colour for both. Repeatable, as --ground-tint.
85
211
  --usage <file.json> Also write where each colour can go: every fill, status
86
- text tone and muted text on every background, per mode,
212
+ text tone and secondary text on every background, per mode,
87
213
  as text, shape or neither. @designtools/manifest reads it
88
214
  (manifest.usage) and writes the failures as usage rules.
89
215
  --check compares it too.
@@ -163,8 +289,8 @@ Selection:
163
289
  --only <sections> Emit only these slices, comma-separated or repeated:
164
290
  ramp the twelve-step colour ramps alone
165
291
  primitives the ramps plus black and white
166
- semantic intent tokens (primary, destructive, muted, \u2026)
167
- surface canvas / surface / overlay
292
+ semantic intent tokens (primary, destructive, \u2026)
293
+ surface canvas / surface / overlay, each with its text and secondary text
168
294
  utility border / input / ring / shadow
169
295
  grounds --on-<ground>-* and the data-surface scopes
170
296
  Keeps generated colour separable from hand-tuned files,
@@ -210,9 +336,9 @@ Verification:
210
336
  With --ramps or --merge, only the declarations this run
211
337
  generates are compared, so hand-edited regions elsewhere
212
338
  in the file are not reported as drift.
213
- --no-aliases Emit each status ramp once, as success, destructive and
214
- warning, without green, red and yellow beside them as
215
- the same ramps.
339
+ --aliases Also emit green, red and yellow beside success,
340
+ destructive and warning, as the same ramps, so
341
+ bg-red-500 matches. Off by default from 0.12.
216
342
  --contract Print the step contract: each step that carries text on
217
343
  white (or black) in some colours and not others, so
218
344
  "the 700" means the same everywhere. Measured, not
@@ -228,7 +354,7 @@ Input:
228
354
 
229
355
  --help Show this help.
230
356
  `;
231
- var FILE_NAMES = {
357
+ var FILE_NAMES2 = {
232
358
  css: "tokens.css",
233
359
  "tailwind-v4": "tailwind.css",
234
360
  "tailwind-v3": "tailwind.config.js",
@@ -238,11 +364,12 @@ var FILE_NAMES = {
238
364
  var VERSION = (() => {
239
365
  try {
240
366
  const here = dirname(fileURLToPath(import.meta.url));
241
- return JSON.parse(readFileSync(join(here, "../package.json"), "utf8")).version;
367
+ return JSON.parse(readFileSync2(join2(here, "../package.json"), "utf8")).version;
242
368
  } catch {
243
369
  return "0.0.0";
244
370
  }
245
371
  })();
372
+ if (process.argv[2] === "scale") process.exit(runScale(process.argv.slice(3), VERSION));
246
373
  function fail(message) {
247
374
  process.stderr.write(`generate-tokens: ${message}
248
375
  `);
@@ -250,7 +377,7 @@ function fail(message) {
250
377
  }
251
378
  var values;
252
379
  try {
253
- ({ values } = parseArgs({
380
+ ({ values } = parseArgs2({
254
381
  options: {
255
382
  primary: { type: "string" },
256
383
  neutral: { type: "string" },
@@ -267,6 +394,10 @@ try {
267
394
  foreground: { type: "string" },
268
395
  "no-wcag-floor": { type: "boolean" },
269
396
  grounds: { type: "string" },
397
+ ground: { type: "string", multiple: true },
398
+ "page-surface": { type: "string", multiple: true },
399
+ "ground-tint": { type: "string", multiple: true },
400
+ "ground-text": { type: "string", multiple: true },
270
401
  gamut: { type: "string" },
271
402
  "seed-shade": { type: "string" },
272
403
  "neutral-seed-shade": { type: "string" },
@@ -279,6 +410,7 @@ try {
279
410
  "hue-drift": { type: "string" },
280
411
  pin: { type: "string", multiple: true },
281
412
  "no-aliases": { type: "boolean" },
413
+ aliases: { type: "boolean" },
282
414
  shades: { type: "string" },
283
415
  overrides: { type: "string" },
284
416
  only: { type: "string", multiple: true },
@@ -309,14 +441,14 @@ if (values.help) {
309
441
  var seed = {};
310
442
  if (values.stdin) {
311
443
  try {
312
- seed = JSON.parse(readFileSync(0, "utf8"));
444
+ seed = JSON.parse(readFileSync2(0, "utf8"));
313
445
  } catch (err) {
314
446
  fail(`could not read seed from stdin: ${err instanceof Error ? err.message : String(err)}`);
315
447
  }
316
448
  }
317
449
  if (values.seed) {
318
450
  try {
319
- seed = JSON.parse(readFileSync(values.seed, "utf8"));
451
+ seed = JSON.parse(readFileSync2(values.seed, "utf8"));
320
452
  } catch (err) {
321
453
  fail(`could not read --seed file: ${err instanceof Error ? err.message : String(err)}`);
322
454
  }
@@ -382,7 +514,9 @@ var contrastTarget = validateChoice("target", values.target ?? seed.contrastTarg
382
514
  var lightnessStrategy = validateChoice("lightness", values.lightness ?? seed.lightnessStrategy, ["fixed", "perceptual"], "fixed");
383
515
  var foreground = validateChoice("foreground", values.foreground ?? seed.foreground, ["balanced", "max"], "balanced");
384
516
  var wcagFloor = values["no-wcag-floor"] === true ? false : seed.wcagFloor ?? true;
385
- var grounds = validateChoice("grounds", values.grounds ?? seed.grounds, ["full", "text", "none"], "full");
517
+ if (values.grounds !== void 0 || typeof seed.grounds === "string") {
518
+ fail(`--grounds is gone from 0.12: grounds are declared with --ground <name>=<ramp>@<step>, and a project without one has none. --grounds text is --ground-tint page.`);
519
+ }
386
520
  function lightDark(flag, raw) {
387
521
  const [light, dark] = raw.split("/").map((s) => s.trim());
388
522
  return { light: validateColor(flag, light), ...dark ? { dark: validateColor(flag, dark) } : {} };
@@ -397,14 +531,71 @@ for (const key of ["canvas", "surface", "overlay"]) {
397
531
  surfaceColors.light[key] = light;
398
532
  if (dark) surfaceColors.dark[key] = dark;
399
533
  }
400
- var backgrounds = { ...seed.backgrounds ?? {} };
401
- for (const entry of values.background ?? []) {
534
+ var oldBackgrounds = [
535
+ ...(values.background ?? []).map((entry) => {
536
+ const [light, dark] = entry.slice(entry.indexOf("=") + 1).split("/").map((x) => x.trim());
537
+ return [entry.slice(0, entry.indexOf("=")).trim(), light, dark];
538
+ }),
539
+ ...Object.entries(seed.backgrounds ?? {}).map(
540
+ ([name, bg]) => [name, bg.light, bg.dark]
541
+ )
542
+ ];
543
+ if (oldBackgrounds.length) {
544
+ const lines = oldBackgrounds.map(([name, light, dark]) => {
545
+ if (dark && dark !== light) return ` --page-surface "${name}=${light}/${dark}"`;
546
+ const step = suggestStep(validateColor(`--background ${name}`, light));
547
+ return ` --color "${name}=${light}@${step}" --decorative ${name} --ground "${name}=${name}@${step}"`;
548
+ });
549
+ fail(`--background is gone from 0.12. A section that changes with the mode is a page surface; one painted the same in both is a ground on a ramp. In its place:
550
+ ${lines.join("\n")}`);
551
+ }
552
+ function validateFill(flag, raw) {
553
+ const v = raw.trim();
554
+ if (v === "page" || v === "own" || v === "white" || v === "black" || /^[a-z][a-z0-9-]*-\d+$/.test(v)) return v;
555
+ fail(`--${flag} must be page, own, white, black or a step such as sage-100 (got "${raw}")`);
556
+ }
557
+ function rampStep(flag, raw) {
558
+ const m = /^([a-z][a-z0-9-]*)@(\d+)$/.exec(raw.trim());
559
+ if (!m || !VALID_SHADES.includes(Number(m[2]))) fail(`${flag} expects <ramp>@<step>, with a step of ${VALID_SHADES.join(", ")} (got "${raw}")`);
560
+ return { ramp: m[1], step: Number(m[2]) };
561
+ }
562
+ var pageSurfaces = { ...seed.pageSurfaces ?? {} };
563
+ for (const entry of values["page-surface"] ?? []) {
402
564
  const eq = entry.indexOf("=");
403
- if (eq === -1) fail(`--background expects name=colour (got "${entry}")`);
565
+ if (eq === -1) fail(`--page-surface expects name=<ramp>@<step>[/<ramp>@<step>] (got "${entry}")`);
404
566
  const name = entry.slice(0, eq).trim();
405
- if (!/^[a-z][a-z0-9-]*$/.test(name) || name === "foreground") fail(`--background name must be lower-case kebab-case, and not "foreground" (got "${name}")`);
406
- backgrounds[name] = lightDark(`--background ${name}`, entry.slice(eq + 1));
567
+ if (!/^[a-z][a-z0-9-]*$/.test(name)) fail(`--page-surface name must be lower-case kebab-case (got "${name}")`);
568
+ const [light, dark] = entry.slice(eq + 1).split("/").map((x) => x.trim());
569
+ const check2 = (v) => v.includes("@") ? rampStep(`--page-surface ${name}`, v) : validateColor(`--page-surface ${name}`, v);
570
+ check2(light);
571
+ if (dark) check2(dark);
572
+ pageSurfaces[name] = { light, ...dark ? { dark } : {} };
573
+ }
574
+ var grounds = { ...seed.grounds ?? {} };
575
+ for (const entry of values.ground ?? []) {
576
+ const eq = entry.indexOf("=");
577
+ if (eq === -1) fail(`--ground expects name=<ramp>@<step> (got "${entry}")`);
578
+ const name = entry.slice(0, eq).trim();
579
+ if (!/^[a-z][a-z0-9-]*$/.test(name) || name === "canvas") fail(`--ground name must be lower-case kebab-case, and not "canvas" (got "${name}")`);
580
+ const { tint, text } = grounds[name] ?? {};
581
+ grounds[name] = { ...rampStep(`--ground ${name}`, entry.slice(eq + 1)), ...tint ? { tint } : {}, ...text ? { text } : {} };
582
+ }
583
+ function fills(flag, key, seeded, fallback) {
584
+ let all = seeded ?? fallback;
585
+ for (const entry of values[flag] ?? []) {
586
+ const eq = entry.indexOf("=");
587
+ if (eq === -1) {
588
+ all = validateFill(flag, entry);
589
+ continue;
590
+ }
591
+ const name = entry.slice(0, eq).trim();
592
+ if (!grounds[name]) fail(`--${flag} names no ground: ${name} (grounds: ${Object.keys(grounds).join(", ") || "none"})`);
593
+ grounds[name] = { ...grounds[name], [key]: validateFill(`${flag} ${name}`, entry.slice(eq + 1)) };
594
+ }
595
+ return all;
407
596
  }
597
+ var groundTint = fills("ground-tint", "tint", seed.groundTint, "own");
598
+ var groundText = fills("ground-text", "text", seed.groundText, "page");
408
599
  var hasSurfaceColors = Object.keys(surfaceColors.light).length + Object.keys(surfaceColors.dark).length > 0;
409
600
  var gamut = validateChoice("gamut", values.gamut ?? seed.gamut, ["srgb", "p3"], "srgb");
410
601
  var format = validateChoice(
@@ -478,7 +669,7 @@ for (const raw of values.pin ?? []) {
478
669
  }
479
670
  }
480
671
  var hasPins = Object.keys(pins).length > 0;
481
- var aliases = values["no-aliases"] === true ? false : seed.aliases ?? true;
672
+ var aliases = values.aliases === true ? true : values["no-aliases"] === true ? false : seed.aliases ?? false;
482
673
  var seedShades = {};
483
674
  if (neutralSeedShade !== void 0) seedShades.neutral = neutralSeedShade;
484
675
  for (const [name, { flag, raw }] of Object.entries(additionalAnchors)) {
@@ -526,7 +717,7 @@ var overrides = {
526
717
  };
527
718
  if (values.overrides) {
528
719
  try {
529
- overrides = JSON.parse(readFileSync(values.overrides, "utf8"));
720
+ overrides = JSON.parse(readFileSync2(values.overrides, "utf8"));
530
721
  } catch (err) {
531
722
  fail(`could not read --overrides file: ${err instanceof Error ? err.message : String(err)}`);
532
723
  }
@@ -543,8 +734,10 @@ var options = {
543
734
  ...foreground !== "balanced" ? { foreground } : {},
544
735
  ...!wcagFloor ? { wcagFloor } : {},
545
736
  ...hasSurfaceColors ? { surfaceColors } : {},
546
- ...Object.keys(backgrounds).length ? { backgrounds } : {},
547
- ...grounds !== "full" ? { grounds } : {},
737
+ ...Object.keys(pageSurfaces).length ? { pageSurfaces } : {},
738
+ ...Object.keys(grounds).length ? { grounds } : {},
739
+ ...groundTint !== "own" ? { groundTint } : {},
740
+ ...groundText !== "page" ? { groundText } : {},
548
741
  seedShade,
549
742
  ...Object.keys(seedShades).length > 0 ? { seedShades } : {},
550
743
  ...lightnessRange ? { lightnessRange: { ...lightnessRange.light !== void 0 ? { light: lightnessRange.light / 100 } : {}, ...lightnessRange.dark !== void 0 ? { dark: lightnessRange.dark / 100 } : {} } } : {},
@@ -553,7 +746,7 @@ var options = {
553
746
  ...hueDrift !== void 0 ? { hueDrift } : {},
554
747
  ...familyShapes ? { families: familiesOf({ families: familyShapes }) } : {},
555
748
  ...hasPins ? { pins } : {},
556
- ...aliases ? {} : { aliases: false },
749
+ ...aliases ? { aliases: true } : {},
557
750
  ...decorative.size > 0 ? { decorative: [...decorative].sort() } : {},
558
751
  shades,
559
752
  shadeOverrides: overrides.shadeOverrides ?? {},
@@ -613,10 +806,10 @@ if (families.length > 0) {
613
806
  }
614
807
  if (shades) {
615
808
  const named = [
616
- ["muted (light)", 100],
617
- ["muted-foreground (light)", 500],
618
- ["muted (dark)", 800],
619
- ["muted-foreground (dark)", 200],
809
+ ["neutral subdued (light)", 100],
810
+ ["secondary text (light)", 500],
811
+ ["neutral subdued (dark)", 800],
812
+ ["secondary text (dark)", 200],
620
813
  ["canvas (light)", 25],
621
814
  ["canvas (dark)", 950],
622
815
  ["semantic DEFAULT (light)", 500],
@@ -654,9 +847,11 @@ var resolvedSeed = {
654
847
  ...foreground !== "balanced" ? { foreground } : {},
655
848
  ...!wcagFloor ? { wcagFloor } : {},
656
849
  ...hasSurfaceColors ? { surfaceColors } : {},
657
- ...Object.keys(backgrounds).length ? { backgrounds } : {},
658
- // left out at the default, so a seed from before grounds keeps its fingerprint
659
- ...grounds !== "full" ? { grounds } : {},
850
+ // left out when unset, so a seed without them keeps its fingerprint
851
+ ...Object.keys(pageSurfaces).length ? { pageSurfaces } : {},
852
+ ...Object.keys(grounds).length ? { grounds } : {},
853
+ ...groundTint !== "own" ? { groundTint } : {},
854
+ ...groundText !== "page" ? { groundText } : {},
660
855
  seedShade,
661
856
  neutralSeedShade,
662
857
  // left out when unset, so a seed without them keeps the fingerprint it always had
@@ -667,7 +862,7 @@ var resolvedSeed = {
667
862
  ...familyShapes ? { families: familyShapes } : {},
668
863
  ...hasPins ? { pins } : {},
669
864
  // left out when on, the default, so existing seeds keep their fingerprint
670
- ...aliases ? {} : { aliases: false },
865
+ ...aliases ? { aliases: true } : {},
671
866
  shades,
672
867
  shadeOverrides: options.shadeOverrides ?? {},
673
868
  surfaceShadeOverrides: options.surfaceShadeOverrides,
@@ -704,7 +899,7 @@ ${body}`;
704
899
  }
705
900
  function targetPath(fmt, out) {
706
901
  try {
707
- if (statSync(out).isDirectory()) return join(out, FILE_NAMES[fmt]);
902
+ if (statSync(out).isDirectory()) return join2(out, FILE_NAMES2[fmt]);
708
903
  } catch {
709
904
  }
710
905
  return out;
@@ -712,7 +907,7 @@ function targetPath(fmt, out) {
712
907
  function check(fmt, target) {
713
908
  let existing;
714
909
  try {
715
- existing = readFileSync(target, "utf8");
910
+ existing = readFileSync2(target, "utf8");
716
911
  } catch {
717
912
  process.stderr.write(`check: ${target} does not exist
718
913
  `);
@@ -778,16 +973,20 @@ fills moved from the offset table
778
973
  ${moved.join("\n")}
779
974
  `);
780
975
  process.stderr.write(`
781
- searched to their contrast floor (ring and input 3:1 on canvas and surface; muted text on muted)
976
+ searched to their contrast floor (ring and input 3:1 on canvas and surface; secondary text on its surface)
782
977
  `);
783
978
  for (const mode of ["light", "dark"]) {
784
979
  const steps = tokens.utility[mode]._steps;
785
- const muted = tokens.semantic[mode].muted._shades;
786
- if (!steps || !muted) continue;
980
+ const refs = tokens.surface[mode]._refs;
981
+ if (!steps || !refs) continue;
787
982
  const start = ringBridgeShade(mode, options.seedShade, active);
788
983
  const moved2 = (from, to) => from === to ? `${to}` : `${to} (from ${from})`;
984
+ const quiet = (key) => {
985
+ const ref = refs[`${key}-foreground-secondary`];
986
+ return ref.type === "shade" ? `${key} neutral-${moved2(snapShade(mode === "light" ? 500 : 200, active), ref.shade)}` : `${key} ${ref.type}`;
987
+ };
789
988
  process.stderr.write(
790
- ` ${mode.padEnd(6)} ring primary-${moved2(start, steps.ring)} input neutral-${moved2(snapShade(mode === "light" ? 200 : 800, active), steps.input)} muted-foreground neutral-${moved2(snapShade(mode === "light" ? 500 : 200, active), muted.foreground)}
989
+ ` ${mode.padEnd(6)} ring primary-${moved2(start, steps.ring)} input neutral-${moved2(snapShade(mode === "light" ? 200 : 800, active), steps.input)} secondary text: ${quiet("canvas")}, ${quiet("surface")}, ${quiet("overlay")}
791
990
  `
792
991
  );
793
992
  }
@@ -898,30 +1097,42 @@ ${mode} mode${label} (${contrastAlgorithm}, target ${contrastTarget})
898
1097
  reportGrounds();
899
1098
  }
900
1099
  function reportGrounds() {
901
- const grounds2 = tokens.grounds;
902
- if (!grounds2) return;
903
1100
  const step = (ref) => ref.type === "shade" ? `${ref.colorName}-${ref.shade}` : ref.type === "value" ? "computed" : ref.type;
904
- process.stderr.write(`
905
- grounds: what data-surface="<ground>" changes from the page (ratio against the ground; a label's against its fill)
1101
+ const under = (token) => token.startsWith("surface-foreground") ? "surface" : token.startsWith("canvas-foreground") ? "canvas" : token.endsWith("-foreground") ? token.slice(0, -"-foreground".length) : "canvas";
1102
+ const grounds2 = Object.entries(tokens.grounds ?? {});
1103
+ if (grounds2.length) {
1104
+ process.stderr.write(`
1105
+ grounds: what data-surface="<ground>" writes (ratio against the ground; a label's against its fill)
906
1106
  `);
907
- const under = (token) => token.endsWith("-foreground") && token !== "canvas-foreground" && token !== "muted-foreground" ? token.slice(0, -"-foreground".length) : "canvas";
908
- for (const mode of ["light", "dark"]) {
909
- for (const [name, g] of Object.entries(grounds2[mode])) {
910
- if (g.kind === "base") continue;
911
- const shown = g.changed.filter((t) => !t.endsWith("-hover") && !t.endsWith("-active"));
912
- const head = ` ${mode.padEnd(6)}${name.padEnd(22)}`;
913
- if (!shown.length) {
914
- process.stderr.write(`${head}the page's tokens already work here
1107
+ for (const [name, g] of grounds2) {
1108
+ process.stderr.write(` ${name.padEnd(14)}${g.ramp}@${g.step}, ${g.polarity}, text ${g.text}, tint ${g.tint}
915
1109
  `);
916
- } else {
917
- const items = shown.map((t) => `${t} ${step(g._refs[t])} ${getContrastRatio(g.tokens[t], g.tokens[under(t)]).toFixed(1)}`);
918
- process.stderr.write(`${head}${items.join(", ")}
1110
+ const shown = g.own.filter((t) => t !== "canvas" && !t.endsWith("-hover") && !t.endsWith("-active"));
1111
+ const items = shown.map((t) => `${t} ${step(g._refs[t])} ${getContrastRatio(g.tokens[t], g.tokens[under(t)]).toFixed(1)}`);
1112
+ process.stderr.write(` ${"".padEnd(14)}${items.length ? items.join(", ") : "the page's tokens work here as they are"}
919
1113
  `);
920
- }
921
- for (const note of g.notes) process.stderr.write(` ${"".padEnd(28)}! ${note}
1114
+ for (const note of g.notes) process.stderr.write(` ${"".padEnd(14)}! ${note}
922
1115
  `);
923
1116
  }
924
1117
  }
1118
+ const advice = [];
1119
+ for (const mode of ["light", "dark"]) {
1120
+ const semantic = tokens.semantic[mode];
1121
+ for (const status of ["success", "warning", "destructive"]) {
1122
+ const tint = semantic[status].subdued;
1123
+ for (const fill of ["primary", "neutral"]) {
1124
+ const ratio = getContrastRatio(semantic[fill].DEFAULT, tint);
1125
+ if (ratio < 3) advice.push(`${mode} ${fill} on ${status}-subdued ${ratio.toFixed(1)}:1`);
1126
+ }
1127
+ }
1128
+ }
1129
+ if (advice.length) {
1130
+ process.stderr.write(`
1131
+ banners (the -subdued tints): a filled button that blends in; use the outline button there
1132
+ `);
1133
+ process.stderr.write(` ${advice.join(", ")}
1134
+ `);
1135
+ }
925
1136
  }
926
1137
  if (values.report) report();
927
1138
  if (values.contract) {
@@ -935,13 +1146,15 @@ step contract (does a step mean the same in every colour?)
935
1146
  `);
936
1147
  }
937
1148
  }
938
- var formats = format === "all" ? Object.keys(FILE_NAMES) : [format];
1149
+ var formats = format === "all" ? Object.keys(FILE_NAMES2) : [format];
939
1150
  var isSlice = families.length > 0 || sections.length > 0;
940
- function reportExternalReferences(css) {
941
- const external = externalReferences(css);
1151
+ function reportExternalReferences(css, merged) {
1152
+ const external = externalReferences(css, merged?.css);
942
1153
  if (external.length === 0) return;
1154
+ const count = `${external.length} token${external.length === 1 ? "" : "s"}`;
943
1155
  process.stderr.write(
944
- `slice references ${external.length} token${external.length === 1 ? "" : "s"} defined elsewhere:
1156
+ merged ? `slice references ${count} that ${merged.target} does not define:
1157
+ ` : `slice references ${count} defined elsewhere:
945
1158
  `
946
1159
  );
947
1160
  for (const name of external) process.stderr.write(` ${name}
@@ -950,7 +1163,7 @@ function reportExternalReferences(css) {
950
1163
  function checkSlice(target, slice) {
951
1164
  let existing;
952
1165
  try {
953
- existing = readFileSync(target, "utf8");
1166
+ existing = readFileSync2(target, "utf8");
954
1167
  } catch {
955
1168
  process.stderr.write(`check: ${target} does not exist
956
1169
  `);
@@ -984,7 +1197,7 @@ function checkUsage() {
984
1197
  if (!values.usage) return true;
985
1198
  let existing = "";
986
1199
  try {
987
- existing = readFileSync(values.usage, "utf8");
1200
+ existing = readFileSync2(values.usage, "utf8");
988
1201
  } catch {
989
1202
  process.stderr.write(`check: ${values.usage} is missing
990
1203
  `);
@@ -1004,13 +1217,13 @@ if (values.check) {
1004
1217
  if (isSlice) {
1005
1218
  process.exit(checkSlice(targetPath(format, out), serialise(format)) && checkUsage() ? 0 : 1);
1006
1219
  }
1007
- const ok = formats.map((fmt) => check(fmt, format === "all" ? join(out, FILE_NAMES[fmt]) : targetPath(fmt, out)));
1220
+ const ok = formats.map((fmt) => check(fmt, format === "all" ? join2(out, FILE_NAMES2[fmt]) : targetPath(fmt, out)));
1008
1221
  process.exit(ok.every(Boolean) && checkUsage() ? 0 : 1);
1009
1222
  } else if (values.merge) {
1010
1223
  const target = targetPath(format, values.out);
1011
1224
  let existing;
1012
1225
  try {
1013
- existing = readFileSync(target, "utf8");
1226
+ existing = readFileSync2(target, "utf8");
1014
1227
  } catch (err) {
1015
1228
  fail(`--merge needs an existing file at ${target}: ${err instanceof Error ? err.message : String(err)}`);
1016
1229
  }
@@ -1021,18 +1234,18 @@ if (values.check) {
1021
1234
  `--merge cannot place ${result.missingBlocks.length} block(s) absent from ${target}: ` + result.missingBlocks.join(", ")
1022
1235
  );
1023
1236
  }
1024
- writeFileSync(target, result.css);
1237
+ writeFileSync2(target, result.css);
1025
1238
  process.stderr.write(
1026
1239
  `merged into ${target}: ${result.updated.length} updated, ${result.added.length} added, ${result.unchanged.length} already current
1027
1240
  `
1028
1241
  );
1029
- reportExternalReferences(slice);
1242
+ reportExternalReferences(slice, { target, css: result.css });
1030
1243
  } else if (format === "all") {
1031
1244
  const dir = values.out ?? ".";
1032
- mkdirSync(dir, { recursive: true });
1245
+ mkdirSync2(dir, { recursive: true });
1033
1246
  for (const fmt of formats) {
1034
- const target = join(dir, FILE_NAMES[fmt]);
1035
- writeFileSync(target, serialise(fmt) + "\n");
1247
+ const target = join2(dir, FILE_NAMES2[fmt]);
1248
+ writeFileSync2(target, serialise(fmt) + "\n");
1036
1249
  process.stderr.write(`wrote ${target}
1037
1250
  `);
1038
1251
  }
@@ -1040,7 +1253,7 @@ if (values.check) {
1040
1253
  const output = serialise(format) + "\n";
1041
1254
  if (values.out) {
1042
1255
  const target = targetPath(format, values.out);
1043
- writeFileSync(target, output);
1256
+ writeFileSync2(target, output);
1044
1257
  process.stderr.write(`wrote ${target}
1045
1258
  `);
1046
1259
  } else {
@@ -1049,7 +1262,7 @@ if (values.check) {
1049
1262
  if (isSlice && SECTIONED_FORMATS.includes(format)) reportExternalReferences(output);
1050
1263
  }
1051
1264
  if (values.usage && !values.check) {
1052
- writeFileSync(values.usage, usageText);
1265
+ writeFileSync2(values.usage, usageText);
1053
1266
  process.stderr.write(`wrote ${values.usage}
1054
1267
  `);
1055
1268
  }