@designtools/tokens 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cli.js CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
+ APCAUnavailableError,
3
4
  DEFAULT_NEUTRAL_COLOR,
4
5
  SECTIONED_FORMATS,
5
6
  SHADE_PRESETS,
6
7
  TOKEN_SECTIONS,
7
8
  VALID_SHADES,
9
+ bridgeShade,
8
10
  checkRampChroma,
9
11
  checkSemanticContrast,
10
12
  checkSemanticContrastAPCA,
@@ -15,6 +17,7 @@ import {
15
17
  extendedBridgeShades,
16
18
  externalReferences,
17
19
  generateTokens,
20
+ isAPCAAvailable,
18
21
  isInGamut,
19
22
  mergeSlice,
20
23
  overrideContract,
@@ -25,10 +28,12 @@ import {
25
28
  ringBridgeShade,
26
29
  seedFingerprint,
27
30
  selectTokenSections,
31
+ serialiseUsage,
28
32
  snapShade,
29
33
  tokenFamilies,
34
+ usageReport,
30
35
  withJsonProvenance
31
- } from "./chunk-D6675UF5.js";
36
+ } from "./chunk-43GMBZQK.js";
32
37
 
33
38
  // src/cli.ts
34
39
  import { parseArgs } from "util";
@@ -48,6 +53,24 @@ Seeds:
48
53
  Additional brand colour scale. Repeatable. Append
49
54
  @<shade> to anchor its seed on that step, as
50
55
  --seed-shade does for the primary: accent=#fde68a@200.
56
+ --decorative <name> Give an added colour its ramp only, with no semantic
57
+ slots (no --<name>, no bg-<name>), for an accent that
58
+ must never be text or an action. Repeatable.
59
+ --canvas <colour>[/<dark>]
60
+ --surface <colour>[/<dark>]
61
+ --overlay <colour>[/<dark>]
62
+ The page, card and overlay backgrounds as exact colours
63
+ (light, then dark after a slash), in place of the
64
+ neutral steps they default to. Text on each is measured.
65
+ --background <name>=<colour>[/<dark>]
66
+ A brand background a section is painted with, as
67
+ --surface-<name> with measured text. Repeatable. Every
68
+ semantic colour is measured against it (--report).
69
+ --usage <file.json> Also write where each colour can go: every fill, status
70
+ text tone and muted text on every background, per mode,
71
+ as text, shape or neither. @designtools/manifest reads it
72
+ (manifest.usage) and writes the failures as usage rules.
73
+ --check compares it too.
51
74
  --seed <file.json> Replay a saved configuration (the shape the web tool
52
75
  persists). Any flag given alongside it wins, so a seed
53
76
  file is a set of defaults rather than a lock.
@@ -56,6 +79,12 @@ Generation options:
56
79
  --contrast <wcag|apca> Contrast algorithm for foreground selection. Default: wcag
57
80
  --target <aa-large|aa|aaa> Contrast target level. Default: aa
58
81
  --lightness <fixed|perceptual> Lightness distribution strategy. Default: fixed
82
+ --foreground <balanced|max> Labels on a fill: white or black, or a tint keeping
83
+ at least 90% of that contrast (balanced, default);
84
+ max allows no tint.
85
+ --no-wcag-floor With --contrast apca, choose by APCA alone. By default
86
+ every pairing must also pass WCAG 2 at the same target,
87
+ which is what audits measure.
59
88
  --seed-shade <25..950> Which step the primary seed lands on. Default: 500.
60
89
  Brand colours arrive as whatever they are; a deep
61
90
  navy or a pale tint forced onto 500 leaves no
@@ -180,9 +209,17 @@ try {
180
209
  primary: { type: "string" },
181
210
  neutral: { type: "string" },
182
211
  color: { type: "string", multiple: true },
212
+ decorative: { type: "string", multiple: true },
213
+ canvas: { type: "string" },
214
+ surface: { type: "string" },
215
+ overlay: { type: "string" },
216
+ background: { type: "string", multiple: true },
217
+ usage: { type: "string" },
183
218
  contrast: { type: "string" },
184
219
  target: { type: "string" },
185
220
  lightness: { type: "string" },
221
+ foreground: { type: "string" },
222
+ "no-wcag-floor": { type: "boolean" },
186
223
  gamut: { type: "string" },
187
224
  "seed-shade": { type: "string" },
188
225
  "neutral-seed-shade": { type: "string" },
@@ -253,7 +290,9 @@ var neutral = validateColor(
253
290
  );
254
291
  var additionalColors = {};
255
292
  var additionalAnchors = {};
256
- for (const { name, color, seedShade: anchor } of seed.additionalColors ?? []) {
293
+ var decorative = /* @__PURE__ */ new Set();
294
+ for (const { name, color, seedShade: anchor, decorative: d } of seed.additionalColors ?? []) {
295
+ if (d) decorative.add(name);
257
296
  additionalColors[name] = validateColor(`seed colour ${name}`, color);
258
297
  if (anchor !== void 0) additionalAnchors[name] = { flag: `seed (additionalColors ${name})`, raw: anchor };
259
298
  }
@@ -274,9 +313,41 @@ for (const entry of values.color ?? []) {
274
313
  }
275
314
  additionalColors[name] = validateColor(`color ${name}`, colour);
276
315
  }
316
+ for (const name of values.decorative ?? []) {
317
+ if (!(name in additionalColors)) {
318
+ fail(`--decorative names no added colour: ${name} (added: ${Object.keys(additionalColors).join(", ") || "none"})`);
319
+ }
320
+ decorative.add(name);
321
+ }
277
322
  var contrastAlgorithm = validateChoice("contrast", values.contrast ?? seed.contrastAlgorithm, ["wcag", "apca"], "wcag");
323
+ if (contrastAlgorithm === "apca" && !isAPCAAvailable()) fail(new APCAUnavailableError().message);
278
324
  var contrastTarget = validateChoice("target", values.target ?? seed.contrastTarget, ["aa-large", "aa", "aaa"], "aa");
279
325
  var lightnessStrategy = validateChoice("lightness", values.lightness ?? seed.lightnessStrategy, ["fixed", "perceptual"], "fixed");
326
+ var foreground = validateChoice("foreground", values.foreground ?? seed.foreground, ["balanced", "max"], "balanced");
327
+ var wcagFloor = values["no-wcag-floor"] === true ? false : seed.wcagFloor ?? true;
328
+ function lightDark(flag, raw) {
329
+ const [light, dark] = raw.split("/").map((s) => s.trim());
330
+ return { light: validateColor(flag, light), ...dark ? { dark: validateColor(flag, dark) } : {} };
331
+ }
332
+ var surfaceColors = {
333
+ light: { ...seed.surfaceColors?.light ?? {} },
334
+ dark: { ...seed.surfaceColors?.dark ?? {} }
335
+ };
336
+ for (const key of ["canvas", "surface", "overlay"]) {
337
+ if (!values[key]) continue;
338
+ const { light, dark } = lightDark(`--${key}`, values[key]);
339
+ surfaceColors.light[key] = light;
340
+ if (dark) surfaceColors.dark[key] = dark;
341
+ }
342
+ var backgrounds = { ...seed.backgrounds ?? {} };
343
+ for (const entry of values.background ?? []) {
344
+ const eq = entry.indexOf("=");
345
+ if (eq === -1) fail(`--background expects name=colour (got "${entry}")`);
346
+ const name = entry.slice(0, eq).trim();
347
+ if (!/^[a-z][a-z0-9-]*$/.test(name) || name === "foreground") fail(`--background name must be lower-case kebab-case, and not "foreground" (got "${name}")`);
348
+ backgrounds[name] = lightDark(`--background ${name}`, entry.slice(eq + 1));
349
+ }
350
+ var hasSurfaceColors = Object.keys(surfaceColors.light).length + Object.keys(surfaceColors.dark).length > 0;
280
351
  var gamut = validateChoice("gamut", values.gamut ?? seed.gamut, ["srgb", "p3"], "srgb");
281
352
  var format = validateChoice(
282
353
  "format",
@@ -362,8 +433,13 @@ var options = {
362
433
  contrastAlgorithm,
363
434
  contrastTarget,
364
435
  lightnessStrategy,
436
+ ...foreground !== "balanced" ? { foreground } : {},
437
+ ...!wcagFloor ? { wcagFloor } : {},
438
+ ...hasSurfaceColors ? { surfaceColors } : {},
439
+ ...Object.keys(backgrounds).length ? { backgrounds } : {},
365
440
  seedShade,
366
441
  ...Object.keys(seedShades).length > 0 ? { seedShades } : {},
442
+ ...decorative.size > 0 ? { decorative: [...decorative].sort() } : {},
367
443
  shades,
368
444
  shadeOverrides: overrides.shadeOverrides ?? {},
369
445
  surfaceShadeOverrides: overrides.surfaceShadeOverrides,
@@ -416,7 +492,7 @@ if (families.length > 0) {
416
492
  }
417
493
  if (shades) {
418
494
  const named = [
419
- ["muted (light)", 25],
495
+ ["muted (light)", 100],
420
496
  ["muted-foreground (light)", 500],
421
497
  ["muted (dark)", 800],
422
498
  ["muted-foreground (dark)", 200],
@@ -424,14 +500,10 @@ if (shades) {
424
500
  ["canvas (dark)", 950],
425
501
  ["semantic DEFAULT (light)", 500],
426
502
  ["semantic subdued (light)", 50],
427
- ["semantic highlight (light)", 700],
428
503
  ["semantic DEFAULT (dark)", 600],
429
- ["semantic subdued (dark)", 200],
430
- ["semantic highlight (dark)", 400],
431
- ["border/input (light)", 200],
432
- ["ring (light)", 400],
433
- ["border/input (dark)", 800],
434
- ["ring (dark)", 700],
504
+ ["semantic subdued (dark)", 900],
505
+ ["border (light)", 200],
506
+ ["border (dark)", 800],
435
507
  ["shadow", 950]
436
508
  ];
437
509
  const moved = named.map(([label, want]) => [label, want, snapShade(want, shades)]).filter(([, want, got]) => want !== got);
@@ -451,12 +523,17 @@ var resolvedSeed = {
451
523
  additionalColors: Object.entries(additionalColors).map(([name, color]) => ({
452
524
  name,
453
525
  color,
454
- seedShade: seedShades[name]
526
+ seedShade: seedShades[name],
527
+ ...decorative.has(name) ? { decorative: true } : {}
455
528
  })),
456
529
  colorFormat,
457
530
  contrastAlgorithm,
458
531
  contrastTarget,
459
532
  lightnessStrategy,
533
+ ...foreground !== "balanced" ? { foreground } : {},
534
+ ...!wcagFloor ? { wcagFloor } : {},
535
+ ...hasSurfaceColors ? { surfaceColors } : {},
536
+ ...Object.keys(backgrounds).length ? { backgrounds } : {},
460
537
  seedShade,
461
538
  neutralSeedShade,
462
539
  shades,
@@ -534,6 +611,9 @@ function check(fmt, target) {
534
611
  }
535
612
  return false;
536
613
  }
614
+ function familySeedShadeOf(name) {
615
+ return name === "primary" ? options.seedShade : options.seedShades?.[name] ?? void 0;
616
+ }
537
617
  function reportBridge() {
538
618
  const active = resolveShades(shades);
539
619
  const anchored = Object.entries(seedShades);
@@ -542,10 +622,40 @@ function reportBridge() {
542
622
  semantic bridge for primary, anchored at ${options.seedShade ?? 500} (${anchored.map(([n, a]) => `${n} at ${a}; `).join("")}other families at 500)
543
623
  `
544
624
  );
625
+ const moved = [];
545
626
  for (const mode of ["light", "dark"]) {
546
627
  const e = extendedBridgeShades(mode, options.seedShade, active);
628
+ const p = tokens.semantic[mode].primary._shades ?? e;
547
629
  process.stderr.write(
548
- ` ${mode.padEnd(6)} default ${String(e.DEFAULT).padStart(3)} subdued ${String(e.subdued).padStart(3)} highlight ${String(e.highlight).padStart(3)} ring ${String(ringBridgeShade(mode, options.seedShade, active)).padStart(3)}
630
+ ` ${mode.padEnd(6)} default ${String(p.DEFAULT).padStart(3)} subdued ${String(p.subdued).padStart(3)}
631
+ `
632
+ );
633
+ for (const [name, colour] of Object.entries(tokens.semantic[mode])) {
634
+ const shades2 = colour._shades;
635
+ if (!shades2 || !("subdued" in shades2)) continue;
636
+ const offset = extendedBridgeShades(mode, familySeedShadeOf(name), active);
637
+ for (const slot of ["DEFAULT"]) {
638
+ if (shades2[slot] === offset[slot]) continue;
639
+ const why = mode === "dark" && slot === "DEFAULT" && shades2.DEFAULT === bridgeShade(0, familySeedShadeOf(name), active) ? "a light colour under a black label keeps its own step" : "no label passed both WCAG 2 and APCA";
640
+ moved.push(` ${mode.padEnd(6)} ${`${name} fill`.padEnd(24)} ${offset[slot]} -> ${shades2[slot]} (${why})`);
641
+ }
642
+ }
643
+ }
644
+ if (moved.length) process.stderr.write(`
645
+ fills moved from the offset table
646
+ ${moved.join("\n")}
647
+ `);
648
+ process.stderr.write(`
649
+ searched to their contrast floor (ring and input 3:1 on canvas and surface; muted text on muted)
650
+ `);
651
+ for (const mode of ["light", "dark"]) {
652
+ const steps = tokens.utility[mode]._steps;
653
+ const muted = tokens.semantic[mode].muted._shades;
654
+ if (!steps || !muted) continue;
655
+ const start = ringBridgeShade(mode, options.seedShade, active);
656
+ const moved2 = (from, to) => from === to ? `${to}` : `${to} (from ${from})`;
657
+ process.stderr.write(
658
+ ` ${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)}
549
659
  `
550
660
  );
551
661
  }
@@ -595,10 +705,33 @@ ${mode} surfaces and utilities${label} (wcag, not counted in the score)
595
705
  }
596
706
  }
597
707
  }
708
+ function reportPage() {
709
+ const floor = contrastTarget === "aaa" ? 7 : contrastTarget === "aa-large" ? 3 : 4.5;
710
+ for (const mode of ["light", "dark"]) {
711
+ const grid = tokens.pageContrast?.[mode];
712
+ if (!grid) continue;
713
+ const grounds = Object.keys(Object.values(grid)[0] ?? {});
714
+ process.stderr.write(`
715
+ ${mode} mode: each colour on each background (T text ${floor}:1, S shape 3:1, - neither)
716
+ `);
717
+ process.stderr.write(` ${"".padEnd(18)}${grounds.map((g) => g.padStart(16)).join("")}
718
+ `);
719
+ for (const [colour, row] of Object.entries(grid)) {
720
+ const cells = grounds.map((g) => {
721
+ const r = row[g];
722
+ const mark = r >= floor ? "T" : r >= 3 ? "S" : "-";
723
+ return `${r.toFixed(2)} ${mark}`.padStart(16);
724
+ });
725
+ process.stderr.write(` ${colour.padEnd(18)}${cells.join("")}
726
+ `);
727
+ }
728
+ }
729
+ }
598
730
  function report() {
599
731
  const width = 34;
600
732
  reportBridge();
601
733
  reportChroma();
734
+ reportPage();
602
735
  for (const { gamut: g, label, tiers } of reportGamuts()) {
603
736
  for (const mode of ["light", "dark"]) {
604
737
  const semantic = tiers.semantic[mode];
@@ -676,13 +809,33 @@ function checkSlice(target, slice) {
676
809
  }
677
810
  return false;
678
811
  }
812
+ var usageText = values.usage ? serialiseUsage(usageReport(tokens, contrastTarget)) : void 0;
813
+ function checkUsage() {
814
+ if (!values.usage) return true;
815
+ let existing = "";
816
+ try {
817
+ existing = readFileSync(values.usage, "utf8");
818
+ } catch {
819
+ process.stderr.write(`check: ${values.usage} is missing
820
+ `);
821
+ return false;
822
+ }
823
+ if (existing === usageText) {
824
+ process.stderr.write(`check: ${values.usage} up to date
825
+ `);
826
+ return true;
827
+ }
828
+ process.stderr.write(`check: ${values.usage} is out of date; regenerate with --usage
829
+ `);
830
+ return false;
831
+ }
679
832
  if (values.check) {
680
833
  const out = values.out;
681
834
  if (isSlice) {
682
- process.exit(checkSlice(targetPath(format, out), serialise(format)) ? 0 : 1);
835
+ process.exit(checkSlice(targetPath(format, out), serialise(format)) && checkUsage() ? 0 : 1);
683
836
  }
684
837
  const ok = formats.map((fmt) => check(fmt, format === "all" ? join(out, FILE_NAMES[fmt]) : targetPath(fmt, out)));
685
- process.exit(ok.every(Boolean) ? 0 : 1);
838
+ process.exit(ok.every(Boolean) && checkUsage() ? 0 : 1);
686
839
  } else if (values.merge) {
687
840
  const target = targetPath(format, values.out);
688
841
  let existing;
@@ -725,3 +878,8 @@ if (values.check) {
725
878
  }
726
879
  if (isSlice && SECTIONED_FORMATS.includes(format)) reportExternalReferences(output);
727
880
  }
881
+ if (values.usage && !values.check) {
882
+ writeFileSync(values.usage, usageText);
883
+ process.stderr.write(`wrote ${values.usage}
884
+ `);
885
+ }
package/dist/index.d.ts CHANGED
@@ -34,18 +34,32 @@ interface ExtendedSemanticColor {
34
34
  foreground: string;
35
35
  subdued: string;
36
36
  "subdued-foreground": string;
37
- highlight: string;
38
- "highlight-foreground": string;
37
+ /**
38
+ * The fill on hover and press: moved away from its label (darker under a white label, lighter
39
+ * under a black one), so the state is plain to see and the label reads better, never worse.
40
+ * Values, not ramp steps; the label is the fill's own `foreground`.
41
+ */
42
+ hover: string;
43
+ active: string;
39
44
  /** Primitive references for foreground values (used by export layer) */
40
45
  _refs?: {
41
46
  foreground: ForegroundRef;
42
47
  "subdued-foreground": ForegroundRef;
43
- "highlight-foreground": ForegroundRef;
48
+ };
49
+ /** The ramp steps the fills settled on, which can differ from the bridge's (see settleFill) */
50
+ _shades?: {
51
+ DEFAULT: ShadeNumber;
52
+ subdued: ShadeNumber;
44
53
  };
45
54
  }
46
55
  interface SemanticColorPair {
47
56
  DEFAULT: string;
48
57
  foreground: string;
58
+ /** The neutral steps chosen, so an export can reference them rather than restate them */
59
+ _shades?: {
60
+ DEFAULT: ShadeNumber;
61
+ foreground: ShadeNumber;
62
+ };
49
63
  }
50
64
  /** Tracks which neutral primitive a surface value references */
51
65
  type SurfaceRef = {
@@ -55,7 +69,23 @@ type SurfaceRef = {
55
69
  type: "white";
56
70
  } | {
57
71
  type: "black";
72
+ }
73
+ /** A colour passed in as it is (a brand background), emitted as a literal */
74
+ | {
75
+ type: "value";
76
+ value: string;
58
77
  };
78
+ /** A named brand background passed in, with the text measured on it */
79
+ interface NamedBackground {
80
+ DEFAULT: string;
81
+ foreground: string;
82
+ _refs: {
83
+ DEFAULT: SurfaceRef;
84
+ foreground: SurfaceRef;
85
+ };
86
+ }
87
+ /** Each colour's WCAG ratio against each background, by mode: what can sit on the page, and where */
88
+ type PageContrast = Record<string, Record<string, number>>;
59
89
  interface SurfaceTokens {
60
90
  canvas: string;
61
91
  "canvas-foreground": string;
@@ -72,12 +102,21 @@ interface SurfaceTokens {
72
102
  overlay: SurfaceRef;
73
103
  "overlay-foreground": SurfaceRef;
74
104
  };
105
+ /** Brand backgrounds passed in by name (`--background stone=#E8E8DB`), each with measured text */
106
+ backgrounds?: Record<string, NamedBackground>;
75
107
  }
76
108
  interface UtilityTokens {
77
109
  border: string;
78
110
  ring: string;
79
111
  input: string;
80
112
  shadow: string;
113
+ /** The ramp steps chosen (ring off primary, the rest off neutral), so an export references the same ones */
114
+ _steps?: {
115
+ border: ShadeNumber;
116
+ input: ShadeNumber;
117
+ ring: ShadeNumber;
118
+ shadow: ShadeNumber;
119
+ };
81
120
  }
82
121
  /**
83
122
  * The colour tiers of a token system, resolved against one gamut's ramps.
@@ -111,6 +150,15 @@ interface TokenSystem {
111
150
  light: UtilityTokens;
112
151
  dark: UtilityTokens;
113
152
  };
153
+ /**
154
+ * Every semantic fill, and muted text, measured as WCAG ratios against every background
155
+ * (canvas, surface, overlay and each named one), per mode. Labels are checked against
156
+ * their own fills; this is the rest: red text on the page, a button on a dark section.
157
+ */
158
+ pageContrast?: {
159
+ light: PageContrast;
160
+ dark: PageContrast;
161
+ };
114
162
  spacing: Record<string, string>;
115
163
  typography: {
116
164
  fontSize: Record<string, string>;
@@ -158,10 +206,8 @@ type ForegroundRef = {
158
206
  interface VariantShadeOverrides {
159
207
  DEFAULT?: ShadeNumber;
160
208
  subdued?: ShadeNumber;
161
- highlight?: ShadeNumber;
162
209
  "on-DEFAULT"?: ShadeNumber;
163
210
  "on-subdued"?: ShadeNumber;
164
- "on-highlight"?: ShadeNumber;
165
211
  }
166
212
  /**
167
213
  * Per-semantic-color shade overrides.
@@ -210,6 +256,42 @@ interface GenerationOptions {
210
256
  * An alias pair (`destructive`/`red`) is one ramp, so naming either anchors both.
211
257
  */
212
258
  seedShades?: Record<string, ShadeNumber>;
259
+ /**
260
+ * Additional colours that get their ramp and nothing else: no `--<name>`,
261
+ * no `-foreground`, no `bg-<name>` semantic. An accent that may never be text
262
+ * or an action is decorative by construction this way, reachable only as
263
+ * `--color-<name>-500` and the like.
264
+ */
265
+ decorative?: string[];
266
+ /**
267
+ * How a label on a filled colour is chosen. `balanced` (default): white or black,
268
+ * whichever contrasts more, or a tint off the ramp when it keeps at least 90% of
269
+ * that. `max`: white or black, never a tint. Subdued labels keep their hue either way.
270
+ */
271
+ foreground?: "balanced" | "max";
272
+ /**
273
+ * Under `contrastAlgorithm: "apca"`, also hold every pairing to the WCAG 2 floor
274
+ * for the same target (4.5:1 at AA), so APCA chooses and nothing fails an audit.
275
+ * Default true; false is APCA alone.
276
+ */
277
+ wcagFloor?: boolean;
278
+ /**
279
+ * Exact colours for the page, the card and the overlay, per mode, in place of the
280
+ * neutral steps they default to. The text on each is then measured, not assumed.
281
+ */
282
+ surfaceColors?: {
283
+ light?: Partial<Record<"canvas" | "surface" | "overlay", string>>;
284
+ dark?: Partial<Record<"canvas" | "surface" | "overlay", string>>;
285
+ };
286
+ /**
287
+ * More backgrounds a brand paints sections with, by name: `{ stone: { light: "#E8E8DB" } }`.
288
+ * Each becomes `--surface-<name>` with a measured `-foreground`; `dark` defaults to `light`.
289
+ * Every semantic colour is measured against each of them (see `pageContrast`).
290
+ */
291
+ backgrounds?: Record<string, {
292
+ light: string;
293
+ dark?: string;
294
+ }>;
213
295
  /**
214
296
  * Which steps to emit. Default: all twelve (25–950).
215
297
  * Tokens naming a dropped step are snapped to the nearest emitted one.
@@ -258,11 +340,16 @@ interface SavedConfig {
258
340
  name: string;
259
341
  color: string;
260
342
  seedShade?: ShadeNumber;
343
+ decorative?: boolean;
261
344
  }[];
262
345
  colorFormat: ColorFormat;
263
346
  contrastAlgorithm: ContrastAlgorithm;
264
347
  contrastTarget: ContrastTarget;
265
348
  lightnessStrategy: LightnessStrategy;
349
+ foreground?: GenerationOptions["foreground"];
350
+ wcagFloor?: boolean;
351
+ surfaceColors?: GenerationOptions["surfaceColors"];
352
+ backgrounds?: GenerationOptions["backgrounds"];
266
353
  shadeOverrides: SemanticShadeOverrides;
267
354
  surfaceShadeOverrides?: GenerationOptions["surfaceShadeOverrides"];
268
355
  utilityShadeOverrides?: GenerationOptions["utilityShadeOverrides"];
@@ -537,15 +624,19 @@ interface SemanticGamuts {
537
624
  * to pass on both. The worse of two contrasts does not depend on which run is
538
625
  * asking, so both pick the same steps.
539
626
  */
540
- declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light" | "dark", options?: Partial<GenerationOptions>, gamuts?: SemanticGamuts): SemanticTokens;
541
- /**
542
- * Generate surface tokens (canvas / surface / overlay depth system) from neutral palette
543
- */
544
- declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<SurfaceShadeOverrides>, shades?: readonly ShadeNumber[]): SurfaceTokens;
627
+ declare function generateSemanticTokens(palette: PrimitivePalette, mode: "light" | "dark", options?: Partial<GenerationOptions>, gamuts?: SemanticGamuts,
628
+ /** The backgrounds this mode paints (canvas, surface, overlay, named): status text must read on all */
629
+ pageGrounds?: readonly string[]): SemanticTokens;
630
+ declare function generateSurfaceTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<SurfaceShadeOverrides>, shades?: readonly ShadeNumber[], colors?: Partial<Record<"canvas" | "surface" | "overlay", string>>, backgrounds?: Record<string, {
631
+ light: string;
632
+ dark?: string;
633
+ }>): SurfaceTokens;
545
634
  /**
546
635
  * Generate utility tokens for borders, rings, inputs, shadow
547
636
  */
548
- declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[], seedShade?: ShadeNumber): UtilityTokens;
637
+ declare function generateUtilityTokens(palette: PrimitivePalette, mode: "light" | "dark", overrides?: Partial<UtilityShadeOverrides>, shades?: readonly ShadeNumber[], seedShade?: ShadeNumber,
638
+ /** The canvas and surface this mode paints, which the ring and input edges must stand out from */
639
+ grounds?: string[]): UtilityTokens;
549
640
  /**
550
641
  * Check contrast compliance for all semantic colors, as a display of `gamut`
551
642
  * shows them. Pass `TokenSystem.p3.semantic` with `"p3"` to check wide-gamut output.
@@ -752,7 +843,7 @@ declare function resolveShades(requested?: readonly ShadeNumber[]): ShadeNumber[
752
843
  /**
753
844
  * Nearest emitted shade to the one a token asked for.
754
845
  *
755
- * Semantic, surface and utility tokens name specific steps (muted sits on 25,
846
+ * Semantic, surface and utility tokens name specific steps (light canvas sits on 25,
756
847
  * borders on neutral-200). When --shades drops one of those, the reference has
757
848
  * to move somewhere real or the output ships a var() pointing at nothing.
758
849
  * Distance is measured in ramp positions, not shade numbers, so the steps count
@@ -794,7 +885,7 @@ declare function chromaShadeFor(index: number, seedShade: ShadeNumber): ShadeNum
794
885
  * hand-edited the output".
795
886
  *
796
887
  * No imports on purpose: this stays usable in a browser alongside the rest of
797
- * the library, and the dependency list stays culori + apca-w3.
888
+ * the library, and the dependency list stays culori (plus the optional apca-w3).
798
889
  */
799
890
 
800
891
  declare const GENERATOR_NAME = "@designtools/tokens";
@@ -826,4 +917,41 @@ declare function parseProvenance(text: string): Provenance | null;
826
917
  /** Attach provenance to a JSON document as a `$designtools` key */
827
918
  declare function withJsonProvenance(json: string, p: Provenance): string;
828
919
 
829
- export { ALIAS_PAIRS, type APCAContrastResult, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, GENERATOR_NAME, type Gamut, type GamutTokens, type GenerationOptions, type LightnessStrategy, type MergeResult, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleOptions, 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 UtilityShadeOverrides, type UtilityTokens, VALID_SHADES, type VariantShadeOverrides, type WCAGContrastResult, WIDE_GAMUT_QUERY, adjustChroma, adjustLightness, aliasOf, checkRampChroma, checkSemanticContrast, checkSemanticContrastAPCA, checkSurfaceContrast, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, diffSlice, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, externalReferences, familySeedShade, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, formatOklchInGamut, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, isInGamut, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, oklchToHex, parseProvenance, parseToOklch, provenanceComment, readDeclarations, reanchorFactors, resolveShades, seedFingerprint, selectTokenSections, simulateCVD, snapShade, stableStringify, tokenFamilies, withJsonProvenance };
920
+ declare class APCAUnavailableError extends Error {
921
+ constructor();
922
+ }
923
+ /** Whether apca-w3 is installed, so APCA contrast can be measured. */
924
+ declare function isAPCAAvailable(): boolean;
925
+
926
+ /**
927
+ * Where each colour can go: every semantic fill, status text tone and muted text measured
928
+ * against every background a mode paints, with a verdict. Written beside the CSS with
929
+ * `--usage <file>` for @designtools/manifest, which turns the failures into usage rules a
930
+ * person reads on the rules page and an agent reads in rules.json. Deterministic: the same
931
+ * tokens write the same bytes.
932
+ */
933
+
934
+ type UsageVerdict = "text" | "shape" | "none";
935
+ interface UsageReport {
936
+ schema: "designtools.usage/1";
937
+ target: ContrastTarget;
938
+ /** Text needs `text` (4.5:1 at AA); a shape that carries meaning on its own needs 3:1 (WCAG 1.4.11). */
939
+ floors: {
940
+ text: number;
941
+ shape: number;
942
+ };
943
+ /** colour → background → ratio and verdict, per mode */
944
+ light: Record<string, Record<string, {
945
+ ratio: number;
946
+ use: UsageVerdict;
947
+ }>>;
948
+ dark: Record<string, Record<string, {
949
+ ratio: number;
950
+ use: UsageVerdict;
951
+ }>>;
952
+ }
953
+ declare function usageReport(tokens: TokenSystem, target?: ContrastTarget): UsageReport;
954
+ /** Two-space JSON with a trailing newline, keys in the order built (already sorted) */
955
+ declare function serialiseUsage(report: UsageReport): string;
956
+
957
+ export { ALIAS_PAIRS, type APCAContrastResult, APCAUnavailableError, type BrandColors, type CVDType, type ColorFormat, type ColorScale, type ContrastAlgorithm, type ContrastTarget, DEFAULT_NEUTRAL_COLOR, DEFAULT_SEED_SHADE, type Declaration, type ExportFormat, type ExportOptions, type ExtendedSemanticColor, type ForegroundRef, GENERATOR_NAME, type Gamut, type GamutTokens, type GenerationOptions, type LightnessStrategy, type MergeResult, type NamedBackground, type PageContrast, type PaletteOptions, type PrimitivePalette, type Provenance, SECTIONED_FORMATS, SHADE_PRESETS, type SavedConfig, type ScaleOptions, 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, checkRampChroma, checkSemanticContrast, checkSemanticContrastAPCA, checkSurfaceContrast, chromaShadeFor, classifyAPCALevel, computeAccessibilityScore, diffSlice, exportToCss, exportToDtcg, exportToTailwindV3, exportToTailwindV4, exportTokens, externalReferences, familySeedShade, findContrastingColorAPCA, fingerprint, formatColorAs, formatColorShort, formatOklchInGamut, generateColorScale, generateColorScaleAPCA, generatePrimitivePalette, generateSemanticTokens, generateSurfaceTokens, generateTokens, generateUtilityTokens, getAPCAContrast, getContrastRatio, getOklchString, getRelativeLuminance, getShade, isAPCAAvailable, isInGamut, meetsWCAG_AA, meetsWCAG_AAA, mergeSlice, oklchToHex, parseProvenance, parseToOklch, provenanceComment, readDeclarations, reanchorFactors, resolveShades, seedFingerprint, selectTokenSections, serialiseUsage, simulateCVD, snapShade, stableStringify, tokenFamilies, usageReport, withJsonProvenance };
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ALIAS_PAIRS,
3
+ APCAUnavailableError,
3
4
  DEFAULT_NEUTRAL_COLOR,
4
5
  DEFAULT_SEED_SHADE,
5
6
  GENERATOR_NAME,
@@ -44,6 +45,7 @@ import {
44
45
  getOklchString,
45
46
  getRelativeLuminance,
46
47
  getShade,
48
+ isAPCAAvailable,
47
49
  isInGamut,
48
50
  meetsWCAG_AA,
49
51
  meetsWCAG_AAA,
@@ -57,14 +59,17 @@ import {
57
59
  resolveShades,
58
60
  seedFingerprint,
59
61
  selectTokenSections,
62
+ serialiseUsage,
60
63
  simulateCVD,
61
64
  snapShade,
62
65
  stableStringify,
63
66
  tokenFamilies,
67
+ usageReport,
64
68
  withJsonProvenance
65
- } from "./chunk-D6675UF5.js";
69
+ } from "./chunk-43GMBZQK.js";
66
70
  export {
67
71
  ALIAS_PAIRS,
72
+ APCAUnavailableError,
68
73
  DEFAULT_NEUTRAL_COLOR,
69
74
  DEFAULT_SEED_SHADE,
70
75
  GENERATOR_NAME,
@@ -109,6 +114,7 @@ export {
109
114
  getOklchString,
110
115
  getRelativeLuminance,
111
116
  getShade,
117
+ isAPCAAvailable,
112
118
  isInGamut,
113
119
  meetsWCAG_AA,
114
120
  meetsWCAG_AAA,
@@ -122,9 +128,11 @@ export {
122
128
  resolveShades,
123
129
  seedFingerprint,
124
130
  selectTokenSections,
131
+ serialiseUsage,
125
132
  simulateCVD,
126
133
  snapShade,
127
134
  stableStringify,
128
135
  tokenFamilies,
136
+ usageReport,
129
137
  withJsonProvenance
130
138
  };