@designtools/tokens 0.6.0 → 0.7.1
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 +37 -0
- package/README.md +50 -23
- package/dist/{chunk-UW2HXSV4.js → chunk-L73RTEAG.js} +301 -158
- package/dist/cli.js +169 -14
- package/dist/index.d.ts +135 -13
- package/dist/index.js +5 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
SHADE_PRESETS,
|
|
7
7
|
TOKEN_SECTIONS,
|
|
8
8
|
VALID_SHADES,
|
|
9
|
+
bridgeShade,
|
|
9
10
|
checkRampChroma,
|
|
10
11
|
checkSemanticContrast,
|
|
11
12
|
checkSemanticContrastAPCA,
|
|
@@ -27,10 +28,12 @@ import {
|
|
|
27
28
|
ringBridgeShade,
|
|
28
29
|
seedFingerprint,
|
|
29
30
|
selectTokenSections,
|
|
31
|
+
serialiseUsage,
|
|
30
32
|
snapShade,
|
|
31
33
|
tokenFamilies,
|
|
34
|
+
usageReport,
|
|
32
35
|
withJsonProvenance
|
|
33
|
-
} from "./chunk-
|
|
36
|
+
} from "./chunk-L73RTEAG.js";
|
|
34
37
|
|
|
35
38
|
// src/cli.ts
|
|
36
39
|
import { parseArgs } from "util";
|
|
@@ -50,6 +53,24 @@ Seeds:
|
|
|
50
53
|
Additional brand colour scale. Repeatable. Append
|
|
51
54
|
@<shade> to anchor its seed on that step, as
|
|
52
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.
|
|
53
74
|
--seed <file.json> Replay a saved configuration (the shape the web tool
|
|
54
75
|
persists). Any flag given alongside it wins, so a seed
|
|
55
76
|
file is a set of defaults rather than a lock.
|
|
@@ -58,6 +79,12 @@ Generation options:
|
|
|
58
79
|
--contrast <wcag|apca> Contrast algorithm for foreground selection. Default: wcag
|
|
59
80
|
--target <aa-large|aa|aaa> Contrast target level. Default: aa
|
|
60
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.
|
|
61
88
|
--seed-shade <25..950> Which step the primary seed lands on. Default: 500.
|
|
62
89
|
Brand colours arrive as whatever they are; a deep
|
|
63
90
|
navy or a pale tint forced onto 500 leaves no
|
|
@@ -182,9 +209,17 @@ try {
|
|
|
182
209
|
primary: { type: "string" },
|
|
183
210
|
neutral: { type: "string" },
|
|
184
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" },
|
|
185
218
|
contrast: { type: "string" },
|
|
186
219
|
target: { type: "string" },
|
|
187
220
|
lightness: { type: "string" },
|
|
221
|
+
foreground: { type: "string" },
|
|
222
|
+
"no-wcag-floor": { type: "boolean" },
|
|
188
223
|
gamut: { type: "string" },
|
|
189
224
|
"seed-shade": { type: "string" },
|
|
190
225
|
"neutral-seed-shade": { type: "string" },
|
|
@@ -255,7 +290,9 @@ var neutral = validateColor(
|
|
|
255
290
|
);
|
|
256
291
|
var additionalColors = {};
|
|
257
292
|
var additionalAnchors = {};
|
|
258
|
-
|
|
293
|
+
var decorative = /* @__PURE__ */ new Set();
|
|
294
|
+
for (const { name, color, seedShade: anchor, decorative: d } of seed.additionalColors ?? []) {
|
|
295
|
+
if (d) decorative.add(name);
|
|
259
296
|
additionalColors[name] = validateColor(`seed colour ${name}`, color);
|
|
260
297
|
if (anchor !== void 0) additionalAnchors[name] = { flag: `seed (additionalColors ${name})`, raw: anchor };
|
|
261
298
|
}
|
|
@@ -276,10 +313,41 @@ for (const entry of values.color ?? []) {
|
|
|
276
313
|
}
|
|
277
314
|
additionalColors[name] = validateColor(`color ${name}`, colour);
|
|
278
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
|
+
}
|
|
279
322
|
var contrastAlgorithm = validateChoice("contrast", values.contrast ?? seed.contrastAlgorithm, ["wcag", "apca"], "wcag");
|
|
280
323
|
if (contrastAlgorithm === "apca" && !isAPCAAvailable()) fail(new APCAUnavailableError().message);
|
|
281
324
|
var contrastTarget = validateChoice("target", values.target ?? seed.contrastTarget, ["aa-large", "aa", "aaa"], "aa");
|
|
282
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;
|
|
283
351
|
var gamut = validateChoice("gamut", values.gamut ?? seed.gamut, ["srgb", "p3"], "srgb");
|
|
284
352
|
var format = validateChoice(
|
|
285
353
|
"format",
|
|
@@ -365,8 +433,13 @@ var options = {
|
|
|
365
433
|
contrastAlgorithm,
|
|
366
434
|
contrastTarget,
|
|
367
435
|
lightnessStrategy,
|
|
436
|
+
...foreground !== "balanced" ? { foreground } : {},
|
|
437
|
+
...!wcagFloor ? { wcagFloor } : {},
|
|
438
|
+
...hasSurfaceColors ? { surfaceColors } : {},
|
|
439
|
+
...Object.keys(backgrounds).length ? { backgrounds } : {},
|
|
368
440
|
seedShade,
|
|
369
441
|
...Object.keys(seedShades).length > 0 ? { seedShades } : {},
|
|
442
|
+
...decorative.size > 0 ? { decorative: [...decorative].sort() } : {},
|
|
370
443
|
shades,
|
|
371
444
|
shadeOverrides: overrides.shadeOverrides ?? {},
|
|
372
445
|
surfaceShadeOverrides: overrides.surfaceShadeOverrides,
|
|
@@ -419,7 +492,7 @@ if (families.length > 0) {
|
|
|
419
492
|
}
|
|
420
493
|
if (shades) {
|
|
421
494
|
const named = [
|
|
422
|
-
["muted (light)",
|
|
495
|
+
["muted (light)", 100],
|
|
423
496
|
["muted-foreground (light)", 500],
|
|
424
497
|
["muted (dark)", 800],
|
|
425
498
|
["muted-foreground (dark)", 200],
|
|
@@ -427,14 +500,10 @@ if (shades) {
|
|
|
427
500
|
["canvas (dark)", 950],
|
|
428
501
|
["semantic DEFAULT (light)", 500],
|
|
429
502
|
["semantic subdued (light)", 50],
|
|
430
|
-
["semantic highlight (light)", 700],
|
|
431
503
|
["semantic DEFAULT (dark)", 600],
|
|
432
|
-
["semantic subdued (dark)",
|
|
433
|
-
["
|
|
434
|
-
["border
|
|
435
|
-
["ring (light)", 400],
|
|
436
|
-
["border/input (dark)", 800],
|
|
437
|
-
["ring (dark)", 700],
|
|
504
|
+
["semantic subdued (dark)", 900],
|
|
505
|
+
["border (light)", 200],
|
|
506
|
+
["border (dark)", 800],
|
|
438
507
|
["shadow", 950]
|
|
439
508
|
];
|
|
440
509
|
const moved = named.map(([label, want]) => [label, want, snapShade(want, shades)]).filter(([, want, got]) => want !== got);
|
|
@@ -454,12 +523,17 @@ var resolvedSeed = {
|
|
|
454
523
|
additionalColors: Object.entries(additionalColors).map(([name, color]) => ({
|
|
455
524
|
name,
|
|
456
525
|
color,
|
|
457
|
-
seedShade: seedShades[name]
|
|
526
|
+
seedShade: seedShades[name],
|
|
527
|
+
...decorative.has(name) ? { decorative: true } : {}
|
|
458
528
|
})),
|
|
459
529
|
colorFormat,
|
|
460
530
|
contrastAlgorithm,
|
|
461
531
|
contrastTarget,
|
|
462
532
|
lightnessStrategy,
|
|
533
|
+
...foreground !== "balanced" ? { foreground } : {},
|
|
534
|
+
...!wcagFloor ? { wcagFloor } : {},
|
|
535
|
+
...hasSurfaceColors ? { surfaceColors } : {},
|
|
536
|
+
...Object.keys(backgrounds).length ? { backgrounds } : {},
|
|
463
537
|
seedShade,
|
|
464
538
|
neutralSeedShade,
|
|
465
539
|
shades,
|
|
@@ -537,6 +611,9 @@ function check(fmt, target) {
|
|
|
537
611
|
}
|
|
538
612
|
return false;
|
|
539
613
|
}
|
|
614
|
+
function familySeedShadeOf(name) {
|
|
615
|
+
return name === "primary" ? options.seedShade : options.seedShades?.[name] ?? void 0;
|
|
616
|
+
}
|
|
540
617
|
function reportBridge() {
|
|
541
618
|
const active = resolveShades(shades);
|
|
542
619
|
const anchored = Object.entries(seedShades);
|
|
@@ -545,10 +622,40 @@ function reportBridge() {
|
|
|
545
622
|
semantic bridge for primary, anchored at ${options.seedShade ?? 500} (${anchored.map(([n, a]) => `${n} at ${a}; `).join("")}other families at 500)
|
|
546
623
|
`
|
|
547
624
|
);
|
|
625
|
+
const moved = [];
|
|
548
626
|
for (const mode of ["light", "dark"]) {
|
|
549
627
|
const e = extendedBridgeShades(mode, options.seedShade, active);
|
|
628
|
+
const p = tokens.semantic[mode].primary._shades ?? e;
|
|
550
629
|
process.stderr.write(
|
|
551
|
-
` ${mode.padEnd(6)} default ${String(
|
|
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)}
|
|
552
659
|
`
|
|
553
660
|
);
|
|
554
661
|
}
|
|
@@ -598,10 +705,33 @@ ${mode} surfaces and utilities${label} (wcag, not counted in the score)
|
|
|
598
705
|
}
|
|
599
706
|
}
|
|
600
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
|
+
}
|
|
601
730
|
function report() {
|
|
602
731
|
const width = 34;
|
|
603
732
|
reportBridge();
|
|
604
733
|
reportChroma();
|
|
734
|
+
reportPage();
|
|
605
735
|
for (const { gamut: g, label, tiers } of reportGamuts()) {
|
|
606
736
|
for (const mode of ["light", "dark"]) {
|
|
607
737
|
const semantic = tiers.semantic[mode];
|
|
@@ -679,13 +809,33 @@ function checkSlice(target, slice) {
|
|
|
679
809
|
}
|
|
680
810
|
return false;
|
|
681
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
|
+
}
|
|
682
832
|
if (values.check) {
|
|
683
833
|
const out = values.out;
|
|
684
834
|
if (isSlice) {
|
|
685
|
-
process.exit(checkSlice(targetPath(format, out), serialise(format)) ? 0 : 1);
|
|
835
|
+
process.exit(checkSlice(targetPath(format, out), serialise(format)) && checkUsage() ? 0 : 1);
|
|
686
836
|
}
|
|
687
837
|
const ok = formats.map((fmt) => check(fmt, format === "all" ? join(out, FILE_NAMES[fmt]) : targetPath(fmt, out)));
|
|
688
|
-
process.exit(ok.every(Boolean) ? 0 : 1);
|
|
838
|
+
process.exit(ok.every(Boolean) && checkUsage() ? 0 : 1);
|
|
689
839
|
} else if (values.merge) {
|
|
690
840
|
const target = targetPath(format, values.out);
|
|
691
841
|
let existing;
|
|
@@ -728,3 +878,8 @@ if (values.check) {
|
|
|
728
878
|
}
|
|
729
879
|
if (isSlice && SECTIONED_FORMATS.includes(format)) reportExternalReferences(output);
|
|
730
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
|
-
|
|
38
|
-
|
|
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
|
-
|
|
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
|
|
541
|
-
/**
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
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
|
|
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 (
|
|
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
|
|
@@ -832,4 +923,35 @@ declare class APCAUnavailableError extends Error {
|
|
|
832
923
|
/** Whether apca-w3 is installed, so APCA contrast can be measured. */
|
|
833
924
|
declare function isAPCAAvailable(): boolean;
|
|
834
925
|
|
|
835
|
-
|
|
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
|
@@ -59,12 +59,14 @@ import {
|
|
|
59
59
|
resolveShades,
|
|
60
60
|
seedFingerprint,
|
|
61
61
|
selectTokenSections,
|
|
62
|
+
serialiseUsage,
|
|
62
63
|
simulateCVD,
|
|
63
64
|
snapShade,
|
|
64
65
|
stableStringify,
|
|
65
66
|
tokenFamilies,
|
|
67
|
+
usageReport,
|
|
66
68
|
withJsonProvenance
|
|
67
|
-
} from "./chunk-
|
|
69
|
+
} from "./chunk-L73RTEAG.js";
|
|
68
70
|
export {
|
|
69
71
|
ALIAS_PAIRS,
|
|
70
72
|
APCAUnavailableError,
|
|
@@ -126,9 +128,11 @@ export {
|
|
|
126
128
|
resolveShades,
|
|
127
129
|
seedFingerprint,
|
|
128
130
|
selectTokenSections,
|
|
131
|
+
serialiseUsage,
|
|
129
132
|
simulateCVD,
|
|
130
133
|
snapShade,
|
|
131
134
|
stableStringify,
|
|
132
135
|
tokenFamilies,
|
|
136
|
+
usageReport,
|
|
133
137
|
withJsonProvenance
|
|
134
138
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@designtools/tokens",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.1",
|
|
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",
|