@designtools/tokens 0.4.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +85 -0
- package/README.md +84 -15
- package/dist/{chunk-MCLZSLHE.js → chunk-D6675UF5.js} +242 -129
- package/dist/cli.js +140 -46
- package/dist/index.d.ts +197 -20
- package/dist/index.js +13 -1
- package/package.json +3 -2
package/dist/cli.js
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
extendedBridgeShades,
|
|
16
16
|
externalReferences,
|
|
17
17
|
generateTokens,
|
|
18
|
+
isInGamut,
|
|
18
19
|
mergeSlice,
|
|
19
20
|
overrideContract,
|
|
20
21
|
parseProvenance,
|
|
@@ -27,7 +28,7 @@ import {
|
|
|
27
28
|
snapShade,
|
|
28
29
|
tokenFamilies,
|
|
29
30
|
withJsonProvenance
|
|
30
|
-
} from "./chunk-
|
|
31
|
+
} from "./chunk-D6675UF5.js";
|
|
31
32
|
|
|
32
33
|
// src/cli.ts
|
|
33
34
|
import { parseArgs } from "util";
|
|
@@ -43,7 +44,10 @@ Seeds:
|
|
|
43
44
|
--primary <colour> Brand colour (hex, rgb(), hsl(), oklch(), named). Required
|
|
44
45
|
unless supplied by --seed.
|
|
45
46
|
--neutral <colour> Neutral seed. Default: ${DEFAULT_NEUTRAL_COLOR}
|
|
46
|
-
--color <name>=<colour>
|
|
47
|
+
--color <name>=<colour>[@<shade>]
|
|
48
|
+
Additional brand colour scale. Repeatable. Append
|
|
49
|
+
@<shade> to anchor its seed on that step, as
|
|
50
|
+
--seed-shade does for the primary: accent=#fde68a@200.
|
|
47
51
|
--seed <file.json> Replay a saved configuration (the shape the web tool
|
|
48
52
|
persists). Any flag given alongside it wins, so a seed
|
|
49
53
|
file is a set of defaults rather than a lock.
|
|
@@ -52,15 +56,28 @@ Generation options:
|
|
|
52
56
|
--contrast <wcag|apca> Contrast algorithm for foreground selection. Default: wcag
|
|
53
57
|
--target <aa-large|aa|aaa> Contrast target level. Default: aa
|
|
54
58
|
--lightness <fixed|perceptual> Lightness distribution strategy. Default: fixed
|
|
55
|
-
--seed-shade <25..950> Which step the seed
|
|
59
|
+
--seed-shade <25..950> Which step the primary seed lands on. Default: 500.
|
|
56
60
|
Brand colours arrive as whatever they are; a deep
|
|
57
61
|
navy or a pale tint forced onto 500 leaves no
|
|
58
62
|
headroom on one side and wrecks the ramp.
|
|
63
|
+
Moves the primary only: neutral and the derived
|
|
64
|
+
status colours stay on 500. (Before 0.5.0 it moved
|
|
65
|
+
every family.) Anchor the others with
|
|
66
|
+
--neutral-seed-shade and --color name=colour@shade.
|
|
67
|
+
--neutral-seed-shade <25..950> Which step the neutral seed lands on. Default: 500.
|
|
59
68
|
--shades <list|preset> Which steps to emit. Default: all twelve (25-950).
|
|
60
69
|
Presets: tailwind (50-950, matching Tailwind's
|
|
61
70
|
stock ramps) and full. Or a list: 50,100,500,900.
|
|
62
71
|
Tokens naming a dropped step snap to the nearest
|
|
63
72
|
emitted one, reported on stderr.
|
|
73
|
+
--gamut <srgb|p3> Which displays to generate for. Default: srgb.
|
|
74
|
+
srgb: every colour is one every screen shows exactly,
|
|
75
|
+
so the contrast checks measure what is displayed.
|
|
76
|
+
p3: also emit richer ramps in a
|
|
77
|
+
@media (color-gamut: p3) block for displays that can
|
|
78
|
+
show them (most phones and Macs). Every foreground is
|
|
79
|
+
chosen to pass on both. css and tailwind-v4 only;
|
|
80
|
+
json carries them as "p3".
|
|
64
81
|
--overrides <file.json> JSON file with { shadeOverrides, surfaceShadeOverrides,
|
|
65
82
|
utilityShadeOverrides } (same shape as the web tool).
|
|
66
83
|
|
|
@@ -166,7 +183,9 @@ try {
|
|
|
166
183
|
contrast: { type: "string" },
|
|
167
184
|
target: { type: "string" },
|
|
168
185
|
lightness: { type: "string" },
|
|
186
|
+
gamut: { type: "string" },
|
|
169
187
|
"seed-shade": { type: "string" },
|
|
188
|
+
"neutral-seed-shade": { type: "string" },
|
|
170
189
|
shades: { type: "string" },
|
|
171
190
|
overrides: { type: "string" },
|
|
172
191
|
only: { type: "string", multiple: true },
|
|
@@ -233,22 +252,32 @@ var neutral = validateColor(
|
|
|
233
252
|
values.neutral ?? seed.neutralColor ?? DEFAULT_NEUTRAL_COLOR
|
|
234
253
|
);
|
|
235
254
|
var additionalColors = {};
|
|
236
|
-
|
|
255
|
+
var additionalAnchors = {};
|
|
256
|
+
for (const { name, color, seedShade: anchor } of seed.additionalColors ?? []) {
|
|
237
257
|
additionalColors[name] = validateColor(`seed colour ${name}`, color);
|
|
258
|
+
if (anchor !== void 0) additionalAnchors[name] = { flag: `seed (additionalColors ${name})`, raw: anchor };
|
|
238
259
|
}
|
|
239
260
|
for (const entry of values.color ?? []) {
|
|
240
261
|
const eq = entry.indexOf("=");
|
|
241
262
|
if (eq === -1) fail(`--color expects name=colour (got "${entry}")`);
|
|
242
263
|
const name = entry.slice(0, eq).trim();
|
|
243
|
-
|
|
264
|
+
let colour = entry.slice(eq + 1).trim();
|
|
244
265
|
if (!/^[a-z][a-z0-9-]*$/i.test(name)) {
|
|
245
266
|
fail(`--color name must be alphanumeric/kebab-case (got "${name}")`);
|
|
246
267
|
}
|
|
268
|
+
const at = /^(.*)@(\d+)$/.exec(colour);
|
|
269
|
+
if (at) {
|
|
270
|
+
colour = at[1].trim();
|
|
271
|
+
additionalAnchors[name] = { flag: `color ${name}@`, raw: at[2] };
|
|
272
|
+
} else {
|
|
273
|
+
delete additionalAnchors[name];
|
|
274
|
+
}
|
|
247
275
|
additionalColors[name] = validateColor(`color ${name}`, colour);
|
|
248
276
|
}
|
|
249
277
|
var contrastAlgorithm = validateChoice("contrast", values.contrast ?? seed.contrastAlgorithm, ["wcag", "apca"], "wcag");
|
|
250
278
|
var contrastTarget = validateChoice("target", values.target ?? seed.contrastTarget, ["aa-large", "aa", "aaa"], "aa");
|
|
251
279
|
var lightnessStrategy = validateChoice("lightness", values.lightness ?? seed.lightnessStrategy, ["fixed", "perceptual"], "fixed");
|
|
280
|
+
var gamut = validateChoice("gamut", values.gamut ?? seed.gamut, ["srgb", "p3"], "srgb");
|
|
252
281
|
var format = validateChoice(
|
|
253
282
|
"format",
|
|
254
283
|
values.format,
|
|
@@ -257,7 +286,7 @@ var format = validateChoice(
|
|
|
257
286
|
);
|
|
258
287
|
var colorFormat = validateChoice("color-format", values["color-format"] ?? seed.colorFormat, ["oklch", "hex", "rgb", "hsl"], "oklch");
|
|
259
288
|
function parseShade(flag, raw) {
|
|
260
|
-
const n = Number(raw.trim());
|
|
289
|
+
const n = Number(String(raw).trim());
|
|
261
290
|
if (!VALID_SHADES.includes(n)) {
|
|
262
291
|
fail(`--${flag} must be one of: ${VALID_SHADES.join(", ")} (got "${raw}")`);
|
|
263
292
|
}
|
|
@@ -271,9 +300,21 @@ if (shadesInput !== void 0) {
|
|
|
271
300
|
if (shades.length < 3) fail(`--shades needs at least 3 steps (got ${shades.length})`);
|
|
272
301
|
}
|
|
273
302
|
var seedShade = values["seed-shade"] !== void 0 ? parseShade("seed-shade", values["seed-shade"]) : seed.seedShade;
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
303
|
+
var neutralSeedShade = values["neutral-seed-shade"] !== void 0 ? parseShade("neutral-seed-shade", values["neutral-seed-shade"]) : seed.neutralSeedShade;
|
|
304
|
+
var seedShades = {};
|
|
305
|
+
if (neutralSeedShade !== void 0) seedShades.neutral = neutralSeedShade;
|
|
306
|
+
for (const [name, { flag, raw }] of Object.entries(additionalAnchors)) {
|
|
307
|
+
seedShades[name] = parseShade(flag, raw);
|
|
308
|
+
}
|
|
309
|
+
for (const [flag, anchor] of [
|
|
310
|
+
["--seed-shade", seedShade],
|
|
311
|
+
...Object.entries(seedShades).map(
|
|
312
|
+
([name, a]) => [name === "neutral" && neutralSeedShade !== void 0 ? "--neutral-seed-shade" : `--color ${name}@`, a]
|
|
313
|
+
)
|
|
314
|
+
]) {
|
|
315
|
+
if (anchor !== void 0 && shades !== void 0 && !shades.includes(anchor)) {
|
|
316
|
+
fail(`${flag} ${anchor} is not in --shades (${shades.join(", ")})`);
|
|
317
|
+
}
|
|
277
318
|
}
|
|
278
319
|
var sections = (values.only ?? []).flatMap((entry) => entry.split(",")).map((s) => s.trim()).filter((s) => s.length > 0).map((s) => {
|
|
279
320
|
if (!TOKEN_SECTIONS.includes(s)) {
|
|
@@ -322,11 +363,40 @@ var options = {
|
|
|
322
363
|
contrastTarget,
|
|
323
364
|
lightnessStrategy,
|
|
324
365
|
seedShade,
|
|
366
|
+
...Object.keys(seedShades).length > 0 ? { seedShades } : {},
|
|
325
367
|
shades,
|
|
326
368
|
shadeOverrides: overrides.shadeOverrides ?? {},
|
|
327
369
|
surfaceShadeOverrides: overrides.surfaceShadeOverrides,
|
|
328
|
-
utilityShadeOverrides: overrides.utilityShadeOverrides
|
|
370
|
+
utilityShadeOverrides: overrides.utilityShadeOverrides,
|
|
371
|
+
gamut
|
|
329
372
|
};
|
|
373
|
+
{
|
|
374
|
+
const seeds = [
|
|
375
|
+
["--primary", primary],
|
|
376
|
+
["--neutral", neutral],
|
|
377
|
+
...Object.entries(additionalColors).map(([name, c]) => [`--color ${name}`, c])
|
|
378
|
+
];
|
|
379
|
+
for (const [label, colour] of seeds) {
|
|
380
|
+
if (isInGamut(colour, "srgb")) continue;
|
|
381
|
+
const kept = gamut === "p3" && isInGamut(colour, "p3");
|
|
382
|
+
process.stderr.write(
|
|
383
|
+
`generate-tokens: ${label} ${colour} is outside sRGB; its chroma is reduced to fit, keeping lightness and hue.` + (kept ? ` The p3 layer keeps it as given.
|
|
384
|
+
` : `
|
|
385
|
+
`)
|
|
386
|
+
);
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
if (gamut === "p3") {
|
|
390
|
+
const flat = (format === "all" ? ["tailwind-v3", "dtcg"] : [format]).filter(
|
|
391
|
+
(f) => f === "tailwind-v3" || f === "dtcg"
|
|
392
|
+
);
|
|
393
|
+
for (const f of flat) {
|
|
394
|
+
process.stderr.write(
|
|
395
|
+
`generate-tokens: --format ${f} has no way to carry a wide-gamut layer; it gets the sRGB values only.
|
|
396
|
+
`
|
|
397
|
+
);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
330
400
|
for (const [flag, why] of [
|
|
331
401
|
["vanilla", "the shadcn/ui aliases it switched off no longer exist, so this is already the only behaviour"],
|
|
332
402
|
["replace-palette", "clearing Tailwind's stock palette is the default; use --no-replace-palette to opt out"]
|
|
@@ -378,16 +448,24 @@ var replacePalette = values["no-replace-palette"] !== true;
|
|
|
378
448
|
var resolvedSeed = {
|
|
379
449
|
primaryColor: primary,
|
|
380
450
|
neutralColor: neutral,
|
|
381
|
-
additionalColors: Object.entries(additionalColors).map(([name, color]) => ({
|
|
451
|
+
additionalColors: Object.entries(additionalColors).map(([name, color]) => ({
|
|
452
|
+
name,
|
|
453
|
+
color,
|
|
454
|
+
seedShade: seedShades[name]
|
|
455
|
+
})),
|
|
382
456
|
colorFormat,
|
|
383
457
|
contrastAlgorithm,
|
|
384
458
|
contrastTarget,
|
|
385
459
|
lightnessStrategy,
|
|
386
460
|
seedShade,
|
|
461
|
+
neutralSeedShade,
|
|
387
462
|
shades,
|
|
388
463
|
shadeOverrides: options.shadeOverrides ?? {},
|
|
389
464
|
surfaceShadeOverrides: options.surfaceShadeOverrides,
|
|
390
|
-
utilityShadeOverrides: options.utilityShadeOverrides
|
|
465
|
+
utilityShadeOverrides: options.utilityShadeOverrides,
|
|
466
|
+
// srgb is the default and was the only behaviour before --gamut existed, so
|
|
467
|
+
// it is left out: an sRGB seed keeps the fingerprint it always had.
|
|
468
|
+
gamut: gamut === "p3" ? gamut : void 0
|
|
391
469
|
};
|
|
392
470
|
var provenance = {
|
|
393
471
|
version: VERSION,
|
|
@@ -405,7 +483,8 @@ function serialise(fmt) {
|
|
|
405
483
|
sections: SECTIONED_FORMATS.includes(fmt) ? sections : void 0,
|
|
406
484
|
shades,
|
|
407
485
|
families: SECTIONED_FORMATS.includes(fmt) ? families : void 0,
|
|
408
|
-
seedShade: options.seedShade
|
|
486
|
+
seedShade: options.seedShade,
|
|
487
|
+
seedShades: options.seedShades
|
|
409
488
|
});
|
|
410
489
|
if (!stampProvenance) return body;
|
|
411
490
|
if (JSON_FORMATS.includes(fmt)) return withJsonProvenance(body, provenance);
|
|
@@ -456,10 +535,13 @@ function check(fmt, target) {
|
|
|
456
535
|
return false;
|
|
457
536
|
}
|
|
458
537
|
function reportBridge() {
|
|
459
|
-
process.stderr.write(`
|
|
460
|
-
semantic bridge (seed anchored at ${options.seedShade ?? 500})
|
|
461
|
-
`);
|
|
462
538
|
const active = resolveShades(shades);
|
|
539
|
+
const anchored = Object.entries(seedShades);
|
|
540
|
+
process.stderr.write(
|
|
541
|
+
`
|
|
542
|
+
semantic bridge for primary, anchored at ${options.seedShade ?? 500} (${anchored.map(([n, a]) => `${n} at ${a}; `).join("")}other families at 500)
|
|
543
|
+
`
|
|
544
|
+
);
|
|
463
545
|
for (const mode of ["light", "dark"]) {
|
|
464
546
|
const e = extendedBridgeShades(mode, options.seedShade, active);
|
|
465
547
|
process.stderr.write(
|
|
@@ -488,19 +570,28 @@ ramp chroma (peak C per family)
|
|
|
488
570
|
);
|
|
489
571
|
}
|
|
490
572
|
}
|
|
573
|
+
function reportGamuts() {
|
|
574
|
+
const out = [
|
|
575
|
+
{ gamut: "srgb", label: "", tiers: tokens }
|
|
576
|
+
];
|
|
577
|
+
if (tokens.p3) out.push({ gamut: "p3", label: " on p3 displays", tiers: tokens.p3 });
|
|
578
|
+
return out;
|
|
579
|
+
}
|
|
491
580
|
function reportSurfaces() {
|
|
492
581
|
const width = 34;
|
|
493
|
-
for (const
|
|
494
|
-
|
|
495
|
-
|
|
582
|
+
for (const { gamut: g, label, tiers } of reportGamuts()) {
|
|
583
|
+
for (const mode of ["light", "dark"]) {
|
|
584
|
+
process.stderr.write(`
|
|
585
|
+
${mode} surfaces and utilities${label} (wcag, not counted in the score)
|
|
496
586
|
`);
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
587
|
+
for (const [pair, r] of Object.entries(
|
|
588
|
+
checkSurfaceContrast(tiers.surface[mode], tiers.utility[mode], g)
|
|
589
|
+
)) {
|
|
590
|
+
const mark = r.advisory ? " " : r.nonText ? r.passes ? "3:1" : "- " : r.passesAAA ? "AAA" : r.passesAA ? "AA " : "- ";
|
|
591
|
+
const note = r.advisory ? " (advisory: 3:1 only where it bounds a control)" : r.nonText ? " (non-text, 1.4.11)" : "";
|
|
592
|
+
process.stderr.write(` ${mark} ${pair.padEnd(width)} ${r.ratio.toFixed(2)}:1${note}
|
|
503
593
|
`);
|
|
594
|
+
}
|
|
504
595
|
}
|
|
505
596
|
}
|
|
506
597
|
}
|
|
@@ -508,32 +599,35 @@ function report() {
|
|
|
508
599
|
const width = 34;
|
|
509
600
|
reportBridge();
|
|
510
601
|
reportChroma();
|
|
511
|
-
for (const
|
|
512
|
-
const
|
|
513
|
-
|
|
514
|
-
|
|
602
|
+
for (const { gamut: g, label, tiers } of reportGamuts()) {
|
|
603
|
+
for (const mode of ["light", "dark"]) {
|
|
604
|
+
const semantic = tiers.semantic[mode];
|
|
605
|
+
process.stderr.write(`
|
|
606
|
+
${mode} mode${label} (${contrastAlgorithm}, target ${contrastTarget})
|
|
515
607
|
`);
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
608
|
+
if (contrastAlgorithm === "wcag") {
|
|
609
|
+
for (const [pair, r] of Object.entries(checkSemanticContrast(semantic, g))) {
|
|
610
|
+
const mark = r.passesAAA ? "AAA" : r.passesAA ? "AA " : "- ";
|
|
611
|
+
process.stderr.write(` ${mark} ${pair.padEnd(width)} ${r.ratio.toFixed(2)}:1
|
|
520
612
|
`);
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
613
|
+
}
|
|
614
|
+
} else {
|
|
615
|
+
for (const [pair, r] of Object.entries(checkSemanticContrastAPCA(semantic, g))) {
|
|
616
|
+
process.stderr.write(
|
|
617
|
+
` ${r.level.padEnd(10)} ${pair.padEnd(width)} Lc ${r.lcValue.toFixed(1)}
|
|
526
618
|
`
|
|
527
|
-
|
|
619
|
+
);
|
|
620
|
+
}
|
|
528
621
|
}
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
622
|
+
const { score, passed, total } = computeAccessibilityScore(
|
|
623
|
+
semantic,
|
|
624
|
+
contrastAlgorithm,
|
|
625
|
+
contrastTarget,
|
|
626
|
+
g
|
|
627
|
+
);
|
|
628
|
+
process.stderr.write(` score: ${score}% (${passed}/${total} pairings)
|
|
536
629
|
`);
|
|
630
|
+
}
|
|
537
631
|
}
|
|
538
632
|
reportSurfaces();
|
|
539
633
|
}
|