@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/CHANGELOG.md +40 -0
- package/LICENSE +21 -0
- package/README.md +90 -32
- package/dist/{chunk-D6675UF5.js → chunk-43GMBZQK.js} +328 -159
- package/dist/cli.js +172 -14
- package/dist/index.d.ts +142 -14
- package/dist/index.js +9 -1
- package/package.json +27 -15
|
@@ -1,3 +1,31 @@
|
|
|
1
|
+
// src/apca.ts
|
|
2
|
+
var APCA_PACKAGE = "apca-w3";
|
|
3
|
+
var APCAUnavailableError = class extends Error {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(
|
|
6
|
+
`APCA contrast needs the ${APCA_PACKAGE} package, which is not installed. Install it beside @designtools/tokens (npm install ${APCA_PACKAGE}), or with npx: npx -p ${APCA_PACKAGE} -p @designtools/tokens generate-tokens --contrast apca \u2026. ${APCA_PACKAGE} has its own licence, which permits WCAG contrast checking of web content only: https://github.com/Myndex/apca-w3/blob/master/LICENSE.md`
|
|
7
|
+
);
|
|
8
|
+
this.name = "APCAUnavailableError";
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
function isMissing(error) {
|
|
12
|
+
const { code, message } = error ?? {};
|
|
13
|
+
return code === "ERR_MODULE_NOT_FOUND" && typeof message === "string" && message.includes(APCA_PACKAGE);
|
|
14
|
+
}
|
|
15
|
+
var apca = null;
|
|
16
|
+
try {
|
|
17
|
+
apca = await import("apca-w3");
|
|
18
|
+
} catch (error) {
|
|
19
|
+
if (!isMissing(error)) throw error;
|
|
20
|
+
}
|
|
21
|
+
function isAPCAAvailable() {
|
|
22
|
+
return apca !== null;
|
|
23
|
+
}
|
|
24
|
+
function requireAPCA() {
|
|
25
|
+
if (!apca) throw new APCAUnavailableError();
|
|
26
|
+
return apca;
|
|
27
|
+
}
|
|
28
|
+
|
|
1
29
|
// src/types.ts
|
|
2
30
|
var VALID_SHADES = [25, 50, 100, 200, 300, 400, 500, 600, 700, 800, 900, 950];
|
|
3
31
|
|
|
@@ -73,7 +101,6 @@ import {
|
|
|
73
101
|
inGamut,
|
|
74
102
|
clampChroma
|
|
75
103
|
} from "culori";
|
|
76
|
-
import { APCAcontrast, sRGBtoY, displayP3toY } from "apca-w3";
|
|
77
104
|
var toOklch = converter("oklch");
|
|
78
105
|
var toHslConverter = converter("hsl");
|
|
79
106
|
var GAMUT_SPACE = { srgb: "rgb", p3: "p3" };
|
|
@@ -250,6 +277,7 @@ function meetsWCAG_AAA(ratio, isLargeText = false) {
|
|
|
250
277
|
return isLargeText ? ratio >= 4.5 : ratio >= 7;
|
|
251
278
|
}
|
|
252
279
|
function getAPCAContrast(foreground, background, gamut = "srgb") {
|
|
280
|
+
const { APCAcontrast, sRGBtoY, displayP3toY } = requireAPCA();
|
|
253
281
|
const fg = displayed(foreground, gamut);
|
|
254
282
|
const bg = displayed(background, gamut);
|
|
255
283
|
const toY = (c) => gamut === "p3" ? displayP3toY([c.r, c.g, c.b]) : sRGBtoY([c.r * 255, c.g * 255, c.b * 255]);
|
|
@@ -385,7 +413,7 @@ function deriveWarningColor(primaryColor) {
|
|
|
385
413
|
mode: "oklch",
|
|
386
414
|
l: clamp(0.7 + pC * 0.3, 0.72, 0.82),
|
|
387
415
|
c: clamp(pC * 1, 0.1, 0.17),
|
|
388
|
-
h:
|
|
416
|
+
h: 60
|
|
389
417
|
};
|
|
390
418
|
return oklchToHex(warning);
|
|
391
419
|
}
|
|
@@ -434,11 +462,12 @@ function getShade(palette, colorName, shade) {
|
|
|
434
462
|
// src/bridge.ts
|
|
435
463
|
var BRIDGE_OFFSETS = {
|
|
436
464
|
light: {
|
|
437
|
-
extended: { DEFAULT: 0, subdued: -5
|
|
465
|
+
extended: { DEFAULT: 0, subdued: -5 },
|
|
438
466
|
ring: -1
|
|
439
467
|
},
|
|
440
468
|
dark: {
|
|
441
|
-
|
|
469
|
+
// subdued is a dark tint on a dark canvas (900 from a 500 seed), not a pale chip
|
|
470
|
+
extended: { DEFAULT: 1, subdued: 4 },
|
|
442
471
|
ring: 2
|
|
443
472
|
}
|
|
444
473
|
};
|
|
@@ -451,15 +480,29 @@ function extendedBridgeShades(mode, seedShade, active, overrides) {
|
|
|
451
480
|
const offsets = BRIDGE_OFFSETS[mode].extended;
|
|
452
481
|
const at = (offset) => bridgeShade(offset, seedShade, active);
|
|
453
482
|
const snap = (shade) => snapShade(shade, active);
|
|
483
|
+
const offsetSubdued = at(offsets.subdued);
|
|
484
|
+
const subdued = mode === "light" ? snap(Math.min(offsetSubdued, 100)) : snap(Math.max(offsetSubdued, 800));
|
|
454
485
|
return {
|
|
455
486
|
DEFAULT: overrides?.DEFAULT ? snap(overrides.DEFAULT) : at(offsets.DEFAULT),
|
|
456
|
-
subdued: overrides?.subdued ? snap(overrides.subdued) :
|
|
457
|
-
highlight: overrides?.highlight ? snap(overrides.highlight) : at(offsets.highlight)
|
|
487
|
+
subdued: overrides?.subdued ? snap(overrides.subdued) : subdued
|
|
458
488
|
};
|
|
459
489
|
}
|
|
460
490
|
function ringBridgeShade(mode, seedShade, active) {
|
|
461
491
|
return bridgeShade(BRIDGE_OFFSETS[mode].ring, seedShade, active);
|
|
462
492
|
}
|
|
493
|
+
function accessibleStep(scale, start, mode, grounds, floor, active) {
|
|
494
|
+
const steps = active.filter((s) => scale[s] !== void 0);
|
|
495
|
+
const from = steps.indexOf(snapShade(start, active));
|
|
496
|
+
const direction = mode === "light" ? 1 : -1;
|
|
497
|
+
const worst = (step) => Math.min(...grounds.map((g) => getContrastRatio(scale[step], g)));
|
|
498
|
+
let best = steps[from];
|
|
499
|
+
for (let i = from; i >= 0 && i < steps.length; i += direction) {
|
|
500
|
+
const ratio = worst(steps[i]);
|
|
501
|
+
if (ratio >= floor) return steps[i];
|
|
502
|
+
if (ratio > worst(best)) best = steps[i];
|
|
503
|
+
}
|
|
504
|
+
return best;
|
|
505
|
+
}
|
|
463
506
|
|
|
464
507
|
// src/semantic.ts
|
|
465
508
|
function shadeKeys(shades) {
|
|
@@ -486,64 +529,92 @@ function getContrastThresholds(algorithm, target) {
|
|
|
486
529
|
}
|
|
487
530
|
}
|
|
488
531
|
}
|
|
489
|
-
|
|
490
|
-
|
|
532
|
+
var FILL_TINT_SHARE = 0.9;
|
|
533
|
+
var TINT_HUE_SHARE = 0.8;
|
|
534
|
+
var APCA_WHITE_MAX_Y = { "aa-large": 0.4564, aa: 0.314, aaa: 0.1946 };
|
|
535
|
+
var APCA_BLACK_MIN_Y = { "aa-large": 0.2831, aa: 0.4233, aaa: 0.5906 };
|
|
536
|
+
var WCAG_FLOOR = { "aa-large": 3, aa: 4.5, aaa: 7 };
|
|
537
|
+
function settleFill(scale, shade, target, active, views) {
|
|
538
|
+
const lum = (s) => views.map((v) => getContrastRatio(v.scale[s], "#000000", v.gamut) * 0.05 - 0.05);
|
|
539
|
+
const whiteMax = Math.min(1.05 / WCAG_FLOOR[target] - 0.05, APCA_WHITE_MAX_Y[target]);
|
|
540
|
+
const blackMin = Math.max(WCAG_FLOOR[target] * 0.05 - 0.05, APCA_BLACK_MIN_Y[target]);
|
|
541
|
+
const ok = (s) => lum(s).every((y2) => y2 <= whiteMax) || lum(s).every((y2) => y2 >= blackMin);
|
|
542
|
+
if (ok(shade)) return shade;
|
|
543
|
+
const y = Math.max(...lum(shade));
|
|
544
|
+
const darkerFirst = y - whiteMax <= 2 * (blackMin - y);
|
|
545
|
+
const at = active.indexOf(shade);
|
|
546
|
+
const darker = [at + 1, at + 2], lighter = [at - 1, at - 2];
|
|
547
|
+
for (const i of darkerFirst ? [...darker, ...lighter] : [...lighter, ...darker]) {
|
|
548
|
+
if (i >= 0 && i < active.length && scale[active[i]] && ok(active[i])) return active[i];
|
|
549
|
+
}
|
|
550
|
+
return shade;
|
|
551
|
+
}
|
|
552
|
+
var HOVER_SHIFT = 0.09;
|
|
553
|
+
var ACTIVE_SHIFT = 0.15;
|
|
554
|
+
function stateOf(fill, label, shift, gamut) {
|
|
555
|
+
const f = parseToOklch(fill);
|
|
556
|
+
const labelIsLight = getContrastRatio(label, "#000000") > getContrastRatio(label, "#ffffff");
|
|
557
|
+
const l = Math.min(1, Math.max(0, f.l + (labelIsLight ? -shift : shift)));
|
|
558
|
+
return formatOklchInGamut(l, f.c ?? 0, f.h ?? 0, gamut);
|
|
559
|
+
}
|
|
560
|
+
function chromaOf(color) {
|
|
561
|
+
return parseToOklch(color).c;
|
|
562
|
+
}
|
|
563
|
+
function tintTarget(algorithm, target, mode) {
|
|
564
|
+
if (algorithm === "apca") return { "aa-large": 60, aa: 75, aaa: 90 }[target];
|
|
565
|
+
if (mode === "dark") return { "aa-large": 7, aa: 9.5, aaa: 11 }[target];
|
|
566
|
+
return { "aa-large": 4.5, aa: 7, aaa: 9 }[target];
|
|
567
|
+
}
|
|
568
|
+
function findBestForeground(views, white, black, algorithm, contrastTarget, colorName, activeShades, role = "fill", preference = "balanced", mode = "light", wcagFloor = true, pageGrounds = []) {
|
|
569
|
+
const { floor } = getContrastThresholds(algorithm, contrastTarget);
|
|
570
|
+
const wcagMin = algorithm === "apca" && wcagFloor ? getContrastThresholds("wcag", contrastTarget).floor : 0;
|
|
571
|
+
const getWcag = (fgOf) => Math.min(...views.map((view) => getContrastRatio(view.background, fgOf(view), view.gamut)));
|
|
491
572
|
const getContrast = (fgOf) => Math.min(
|
|
492
573
|
...views.map(
|
|
493
574
|
(view) => algorithm === "apca" ? getAPCAContrast(fgOf(view), view.background, view.gamut) : getContrastRatio(view.background, fgOf(view), view.gamut)
|
|
494
575
|
)
|
|
495
576
|
);
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
}
|
|
536
|
-
if (neutralResult) {
|
|
537
|
-
return { value: neutralResult.value, ref: neutralResult.ref };
|
|
538
|
-
}
|
|
539
|
-
const whiteC = getContrast(() => white);
|
|
540
|
-
const blackC = getContrast(() => black);
|
|
541
|
-
if (whiteC >= blackC) return { value: white, ref: { type: "white" } };
|
|
542
|
-
return { value: black, ref: { type: "black" } };
|
|
543
|
-
}
|
|
544
|
-
function createExtendedSemanticColor(scale, neutral, white, black, mode, contrastAlgorithm = "wcag", contrastTarget = "aa", overrides, colorName = "primary", shades, seedShade, gamuts = { own: "srgb" }) {
|
|
577
|
+
const ends = [
|
|
578
|
+
{ value: white, ref: { type: "white" }, contrast: getContrast(() => white), wcag: wcagMin ? getWcag(() => white) : Infinity },
|
|
579
|
+
{ value: black, ref: { type: "black" }, contrast: getContrast(() => black), wcag: wcagMin ? getWcag(() => black) : Infinity }
|
|
580
|
+
].sort((a, b) => Number(b.wcag >= wcagMin) - Number(a.wcag >= wcagMin) || b.contrast - a.contrast);
|
|
581
|
+
const extreme = { value: ends[0].value, ref: ends[0].ref };
|
|
582
|
+
const best = ends[0].contrast;
|
|
583
|
+
const steps = (which, refName) => activeShades.map((shade) => ({
|
|
584
|
+
value: views[0][which][shade],
|
|
585
|
+
ref: { type: "shade", colorName: refName, shade },
|
|
586
|
+
contrast: getContrast((view) => view[which][shade]),
|
|
587
|
+
wcag: wcagMin ? getWcag((view) => view[which][shade]) : Infinity,
|
|
588
|
+
// the least chroma any view shows, so the sRGB and P3 tiers judge the hue alike and pick the same step
|
|
589
|
+
chroma: Math.min(...views.map((view) => chromaOf(view[which][shade]))),
|
|
590
|
+
own: which === "scale"
|
|
591
|
+
}));
|
|
592
|
+
const own = steps("scale", colorName);
|
|
593
|
+
if (role === "tint") {
|
|
594
|
+
const peak = Math.max(...own.map((c) => c.chroma));
|
|
595
|
+
const aim = tintTarget(algorithm, contrastTarget, mode);
|
|
596
|
+
const closest = (list) => [...list].sort((a, b) => Math.abs(a.contrast - aim) - Math.abs(b.contrast - aim) || b.contrast - a.contrast)[0];
|
|
597
|
+
const textFloor = getContrastThresholds("wcag", contrastTarget).floor;
|
|
598
|
+
const onPage = (c) => pageGrounds.every((g) => getContrastRatio(c.value, g) >= textFloor);
|
|
599
|
+
const allPassing = own.filter((c) => c.contrast >= floor && c.wcag >= wcagMin);
|
|
600
|
+
const onPagePassing = allPassing.filter(onPage);
|
|
601
|
+
const passing = onPagePassing.length ? onPagePassing : allPassing;
|
|
602
|
+
const enough = floor + (aim - floor) / 2;
|
|
603
|
+
const keepsHue = passing.filter((c) => c.chroma >= peak * TINT_HUE_SHARE && c.contrast >= enough);
|
|
604
|
+
const pick = closest(keepsHue) ?? closest(passing);
|
|
605
|
+
if (pick) return { value: pick.value, ref: pick.ref };
|
|
606
|
+
return extreme;
|
|
607
|
+
}
|
|
608
|
+
if (preference === "balanced" && best >= floor) {
|
|
609
|
+
const tints = [...own, ...steps("neutral", "neutral")].filter((c) => c.contrast >= floor && c.wcag >= wcagMin && c.contrast >= best * FILL_TINT_SHARE);
|
|
610
|
+
tints.sort((a, b) => a.contrast - b.contrast || Number(b.own) - Number(a.own));
|
|
611
|
+
if (tints[0]) return { value: tints[0].value, ref: tints[0].ref };
|
|
612
|
+
}
|
|
613
|
+
return extreme;
|
|
614
|
+
}
|
|
615
|
+
function createExtendedSemanticColor(scale, neutral, white, black, mode, contrastAlgorithm = "wcag", contrastTarget = "aa", overrides, colorName = "primary", shades, seedShade, gamuts = { own: "srgb" }, preference = "balanced", wcagFloor = true, pageGrounds = []) {
|
|
545
616
|
const activeShades = shadeKeys(shades);
|
|
546
|
-
const findFg = (bgShade) => {
|
|
617
|
+
const findFg = (bgShade, role, grounds = []) => {
|
|
547
618
|
const views = [
|
|
548
619
|
{ background: scale[bgShade], scale, neutral, gamut: gamuts.own }
|
|
549
620
|
];
|
|
@@ -551,30 +622,36 @@ function createExtendedSemanticColor(scale, neutral, white, black, mode, contras
|
|
|
551
622
|
const o = gamuts.other;
|
|
552
623
|
views.push({ background: o.scale[bgShade], scale: o.scale, neutral: o.neutral, gamut: o.gamut });
|
|
553
624
|
}
|
|
554
|
-
return findBestForeground(views, white, black, contrastAlgorithm, contrastTarget, colorName, activeShades);
|
|
625
|
+
return findBestForeground(views, white, black, contrastAlgorithm, contrastTarget, colorName, activeShades, role, preference, mode, wcagFloor, grounds);
|
|
555
626
|
};
|
|
556
|
-
const { DEFAULT:
|
|
627
|
+
const { DEFAULT: offsetDefault, subdued: offsetSubdued } = extendedBridgeShades(mode, seedShade, activeShades, overrides);
|
|
628
|
+
const seedColour = parseToOklch(scale[bridgeShade(0, seedShade, activeShades)]);
|
|
629
|
+
const warm = mode === "light" && seedColour.c >= 0.05 && (seedColour.h ?? 0) >= 40 && (seedColour.h ?? 0) <= 115;
|
|
630
|
+
const subduedShade = warm && !overrides?.subdued ? snapShade(200, activeShades) : offsetSubdued;
|
|
631
|
+
const seedStep = bridgeShade(0, seedShade, activeShades);
|
|
632
|
+
const blackLabel = (shade) => getContrastRatio(scale[shade], black) > getContrastRatio(scale[shade], white);
|
|
633
|
+
const bridgeDefault = mode === "dark" && !overrides?.DEFAULT && offsetDefault !== seedStep && blackLabel(seedStep) ? seedStep : offsetDefault;
|
|
634
|
+
const fillViews = [{ scale, gamut: gamuts.own }, ...gamuts.other ? [{ scale: gamuts.other.scale, gamut: gamuts.other.gamut }] : []];
|
|
635
|
+
const defaultShade = colorName === "primary" || overrides?.DEFAULT ? bridgeDefault : settleFill(scale, bridgeDefault, contrastTarget, activeShades, fillViews);
|
|
557
636
|
const DEFAULT = scale[defaultShade];
|
|
558
637
|
const subdued = scale[subduedShade];
|
|
559
|
-
const
|
|
560
|
-
const
|
|
561
|
-
const sfgResult = overrides?.["on-subdued"] ? { value: scale[overrides["on-subdued"]], ref: { type: "shade", colorName, shade: overrides["on-subdued"] } } : findFg(subduedShade);
|
|
562
|
-
const hfgResult = overrides?.["on-highlight"] ? { value: scale[overrides["on-highlight"]], ref: { type: "shade", colorName, shade: overrides["on-highlight"] } } : findFg(highlightShade);
|
|
638
|
+
const fgResult = overrides?.["on-DEFAULT"] ? { value: scale[overrides["on-DEFAULT"]], ref: { type: "shade", colorName, shade: overrides["on-DEFAULT"] } } : findFg(defaultShade, "fill");
|
|
639
|
+
const sfgResult = overrides?.["on-subdued"] ? { value: scale[overrides["on-subdued"]], ref: { type: "shade", colorName, shade: overrides["on-subdued"] } } : warm ? findFg(subduedShade, "fill") : findFg(subduedShade, "tint", ["success", "warning", "destructive"].includes(colorName) ? pageGrounds : []);
|
|
563
640
|
return {
|
|
564
641
|
DEFAULT,
|
|
565
642
|
foreground: fgResult.value,
|
|
566
643
|
subdued,
|
|
567
644
|
"subdued-foreground": sfgResult.value,
|
|
568
|
-
|
|
569
|
-
|
|
645
|
+
hover: stateOf(DEFAULT, fgResult.value, HOVER_SHIFT, gamuts.own),
|
|
646
|
+
active: stateOf(DEFAULT, fgResult.value, ACTIVE_SHIFT, gamuts.own),
|
|
570
647
|
_refs: {
|
|
571
648
|
foreground: fgResult.ref,
|
|
572
|
-
"subdued-foreground": sfgResult.ref
|
|
573
|
-
|
|
574
|
-
}
|
|
649
|
+
"subdued-foreground": sfgResult.ref
|
|
650
|
+
},
|
|
651
|
+
_shades: { DEFAULT: defaultShade, subdued: subduedShade }
|
|
575
652
|
};
|
|
576
653
|
}
|
|
577
|
-
function generateSemanticTokens(palette, mode, options, gamuts = { own: "srgb" }) {
|
|
654
|
+
function generateSemanticTokens(palette, mode, options, gamuts = { own: "srgb" }, pageGrounds = []) {
|
|
578
655
|
const contrastAlgorithm = options?.contrastAlgorithm ?? "wcag";
|
|
579
656
|
const contrastTarget = options?.contrastTarget ?? "aa";
|
|
580
657
|
const shadeOverrides = options?.shadeOverrides ?? {};
|
|
@@ -604,19 +681,26 @@ function generateSemanticTokens(palette, mode, options, gamuts = { own: "srgb" }
|
|
|
604
681
|
}
|
|
605
682
|
} : {}
|
|
606
683
|
});
|
|
607
|
-
const
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
684
|
+
const mutedBg = snapShade(mode === "light" ? 100 : 800, activeShades);
|
|
685
|
+
const mutedFg = accessibleStep(
|
|
686
|
+
neutral,
|
|
687
|
+
mode === "light" ? 500 : 200,
|
|
688
|
+
mode,
|
|
689
|
+
[neutral[mutedBg]],
|
|
690
|
+
contrastTarget === "aaa" ? 7 : 4.5,
|
|
691
|
+
activeShades
|
|
692
|
+
);
|
|
693
|
+
const muted = {
|
|
694
|
+
DEFAULT: neutral[mutedBg],
|
|
695
|
+
foreground: neutral[mutedFg],
|
|
696
|
+
_shades: { DEFAULT: mutedBg, foreground: mutedFg }
|
|
613
697
|
};
|
|
614
698
|
const tokens = {
|
|
615
|
-
primary: createExtendedSemanticColor(primary, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.primary?.[mode], "primary", activeShades, anchor("primary"), gamutsFor("primary")),
|
|
616
|
-
neutral: createExtendedSemanticColor(neutral, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.neutral?.[mode], "neutral", activeShades, anchor("neutral"), gamutsFor("neutral")),
|
|
617
|
-
success: createExtendedSemanticColor(success, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.success?.[mode], "success", activeShades, anchor("success"), gamutsFor("success")),
|
|
618
|
-
destructive: createExtendedSemanticColor(destructive, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.destructive?.[mode], "destructive", activeShades, anchor("destructive"), gamutsFor("destructive")),
|
|
619
|
-
warning: createExtendedSemanticColor(warning, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.warning?.[mode], "warning", activeShades, anchor("warning"), gamutsFor("warning")),
|
|
699
|
+
primary: createExtendedSemanticColor(primary, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.primary?.[mode], "primary", activeShades, anchor("primary"), gamutsFor("primary"), options?.foreground, options?.wcagFloor, pageGrounds),
|
|
700
|
+
neutral: createExtendedSemanticColor(neutral, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.neutral?.[mode], "neutral", activeShades, anchor("neutral"), gamutsFor("neutral"), options?.foreground, options?.wcagFloor, pageGrounds),
|
|
701
|
+
success: createExtendedSemanticColor(success, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.success?.[mode], "success", activeShades, anchor("success"), gamutsFor("success"), options?.foreground, options?.wcagFloor, pageGrounds),
|
|
702
|
+
destructive: createExtendedSemanticColor(destructive, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.destructive?.[mode], "destructive", activeShades, anchor("destructive"), gamutsFor("destructive"), options?.foreground, options?.wcagFloor, pageGrounds),
|
|
703
|
+
warning: createExtendedSemanticColor(warning, neutral, white, black, mode, contrastAlgorithm, contrastTarget, shadeOverrides.warning?.[mode], "warning", activeShades, anchor("warning"), gamutsFor("warning"), options?.foreground, options?.wcagFloor, pageGrounds),
|
|
620
704
|
muted
|
|
621
705
|
};
|
|
622
706
|
const coreColors = [
|
|
@@ -632,7 +716,7 @@ function generateSemanticTokens(palette, mode, options, gamuts = { own: "srgb" }
|
|
|
632
716
|
"yellow"
|
|
633
717
|
];
|
|
634
718
|
for (const [colorName, colorValue] of Object.entries(palette)) {
|
|
635
|
-
if (!coreColors.includes(colorName) && typeof colorValue !== "string" && colorValue) {
|
|
719
|
+
if (!coreColors.includes(colorName) && !options?.decorative?.includes(colorName) && typeof colorValue !== "string" && colorValue) {
|
|
636
720
|
tokens[colorName] = createExtendedSemanticColor(
|
|
637
721
|
colorValue,
|
|
638
722
|
neutral,
|
|
@@ -645,13 +729,23 @@ function generateSemanticTokens(palette, mode, options, gamuts = { own: "srgb" }
|
|
|
645
729
|
colorName,
|
|
646
730
|
activeShades,
|
|
647
731
|
anchor(colorName),
|
|
648
|
-
gamutsFor(colorName)
|
|
732
|
+
gamutsFor(colorName),
|
|
733
|
+
options?.foreground,
|
|
734
|
+
options?.wcagFloor,
|
|
735
|
+
pageGrounds
|
|
649
736
|
);
|
|
650
737
|
}
|
|
651
738
|
}
|
|
652
739
|
return tokens;
|
|
653
740
|
}
|
|
654
|
-
function
|
|
741
|
+
function textOn(bg, neutral, white, black, active) {
|
|
742
|
+
const light = getContrastRatio(bg, black) > getContrastRatio(bg, white);
|
|
743
|
+
if (!light) return { value: white, ref: { type: "white" } };
|
|
744
|
+
const step = accessibleStep(neutral, snapShade(800, active), "light", [bg], 7, active);
|
|
745
|
+
if (getContrastRatio(bg, neutral[step]) >= 4.5) return { value: neutral[step], ref: { type: "shade", shade: step } };
|
|
746
|
+
return { value: black, ref: { type: "black" } };
|
|
747
|
+
}
|
|
748
|
+
function generateSurfaceTokens(palette, mode, overrides, shades, colors, backgrounds) {
|
|
655
749
|
const activeShades = shadeKeys(shades);
|
|
656
750
|
const snap = (shade) => snapShade(shade, activeShades);
|
|
657
751
|
const neutral = palette.neutral;
|
|
@@ -668,12 +762,22 @@ function generateSurfaceTokens(palette, mode, overrides, shades) {
|
|
|
668
762
|
const val = snap(raw);
|
|
669
763
|
return { value: neutral[val], ref: { type: "shade", shade: val } };
|
|
670
764
|
}
|
|
671
|
-
const
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
765
|
+
const ground = (key) => {
|
|
766
|
+
const given = colors?.[key];
|
|
767
|
+
if (!given) return { bg: resolve(key), fg: resolve(`${key}-foreground`) };
|
|
768
|
+
const bg = { value: given, ref: { type: "value", value: given } };
|
|
769
|
+
return { bg, fg: overrides?.[`${key}-foreground`] ? resolve(`${key}-foreground`) : textOn(given, neutral, white, black, activeShades) };
|
|
770
|
+
};
|
|
771
|
+
const { bg: canvas, fg: canvasFg } = ground("canvas");
|
|
772
|
+
const { bg: surface, fg: surfaceFg } = ground("surface");
|
|
773
|
+
const { bg: overlay, fg: overlayFg } = ground("overlay");
|
|
774
|
+
const named = {};
|
|
775
|
+
for (const name of Object.keys(backgrounds ?? {}).sort()) {
|
|
776
|
+
const def = backgrounds[name];
|
|
777
|
+
const value = mode === "dark" ? def.dark ?? def.light : def.light;
|
|
778
|
+
const fg = textOn(value, neutral, white, black, activeShades);
|
|
779
|
+
named[name] = { DEFAULT: value, foreground: fg.value, _refs: { DEFAULT: { type: "value", value }, foreground: fg.ref } };
|
|
780
|
+
}
|
|
677
781
|
return {
|
|
678
782
|
canvas: canvas.value,
|
|
679
783
|
"canvas-foreground": canvasFg.value,
|
|
@@ -688,10 +792,11 @@ function generateSurfaceTokens(palette, mode, overrides, shades) {
|
|
|
688
792
|
"surface-foreground": surfaceFg.ref,
|
|
689
793
|
overlay: overlay.ref,
|
|
690
794
|
"overlay-foreground": overlayFg.ref
|
|
691
|
-
}
|
|
795
|
+
},
|
|
796
|
+
...Object.keys(named).length ? { backgrounds: named } : {}
|
|
692
797
|
};
|
|
693
798
|
}
|
|
694
|
-
function generateUtilityTokens(palette, mode, overrides, shades, seedShade) {
|
|
799
|
+
function generateUtilityTokens(palette, mode, overrides, shades, seedShade, grounds) {
|
|
695
800
|
const activeShades = shadeKeys(shades);
|
|
696
801
|
const snap = (shade) => snapShade(shade, activeShades);
|
|
697
802
|
const neutral = palette.neutral;
|
|
@@ -699,13 +804,23 @@ function generateUtilityTokens(palette, mode, overrides, shades, seedShade) {
|
|
|
699
804
|
if (!neutral || !primary) {
|
|
700
805
|
throw new Error("Required palettes not found");
|
|
701
806
|
}
|
|
702
|
-
const
|
|
703
|
-
const
|
|
807
|
+
const NON_TEXT = 3;
|
|
808
|
+
const ring = grounds ? accessibleStep(primary, ringBridgeShade(mode, seedShade, activeShades), mode, grounds, NON_TEXT, activeShades) : ringBridgeShade(mode, seedShade, activeShades);
|
|
809
|
+
const inputStart = snap(mode === "light" ? 200 : 800);
|
|
810
|
+
const input = grounds ? accessibleStep(neutral, inputStart, mode, grounds, NON_TEXT, activeShades) : inputStart;
|
|
811
|
+
const defaults = mode === "light" ? { border: snap(200), input, ring, shadow: snap(950) } : { border: snap(800), input, ring, shadow: snap(950) };
|
|
812
|
+
const steps = {
|
|
813
|
+
border: overrides?.border ? snap(overrides.border) : defaults.border,
|
|
814
|
+
input: overrides?.input ? snap(overrides.input) : defaults.input,
|
|
815
|
+
ring: overrides?.ring ? snap(overrides.ring) : defaults.ring,
|
|
816
|
+
shadow: overrides?.shadow ? snap(overrides.shadow) : defaults.shadow
|
|
817
|
+
};
|
|
704
818
|
return {
|
|
705
|
-
border: neutral[
|
|
706
|
-
input: neutral[
|
|
707
|
-
ring: primary[
|
|
708
|
-
shadow: neutral[
|
|
819
|
+
border: neutral[steps.border],
|
|
820
|
+
input: neutral[steps.input],
|
|
821
|
+
ring: primary[steps.ring],
|
|
822
|
+
shadow: neutral[steps.shadow],
|
|
823
|
+
_steps: steps
|
|
709
824
|
};
|
|
710
825
|
}
|
|
711
826
|
function checkSemanticContrast(tokens, gamut = "srgb") {
|
|
@@ -735,16 +850,6 @@ function checkSemanticContrast(tokens, gamut = "srgb") {
|
|
|
735
850
|
passesAA: meetsWCAG_AA(subduedRatio),
|
|
736
851
|
passesAAA: subduedRatio >= 7
|
|
737
852
|
};
|
|
738
|
-
const highlightRatio = getContrastRatio(
|
|
739
|
-
extendedColor.highlight,
|
|
740
|
-
extendedColor["highlight-foreground"],
|
|
741
|
-
gamut
|
|
742
|
-
);
|
|
743
|
-
results[`${name}/highlight`] = {
|
|
744
|
-
ratio: Math.round(highlightRatio * 100) / 100,
|
|
745
|
-
passesAA: meetsWCAG_AA(highlightRatio),
|
|
746
|
-
passesAAA: highlightRatio >= 7
|
|
747
|
-
};
|
|
748
853
|
}
|
|
749
854
|
const mutedRatio = getContrastRatio(
|
|
750
855
|
tokens.muted.DEFAULT,
|
|
@@ -775,11 +880,6 @@ function checkSemanticContrastAPCA(tokens, gamut = "srgb") {
|
|
|
775
880
|
lcValue: Math.round(subduedLc * 10) / 10,
|
|
776
881
|
level: classifyAPCALevel(subduedLc)
|
|
777
882
|
};
|
|
778
|
-
const highlightLc = getAPCAContrast(ext["highlight-foreground"], ext.highlight, gamut);
|
|
779
|
-
results[`${name}/highlight`] = {
|
|
780
|
-
lcValue: Math.round(highlightLc * 10) / 10,
|
|
781
|
-
level: classifyAPCALevel(highlightLc)
|
|
782
|
-
};
|
|
783
883
|
}
|
|
784
884
|
const mutedLc = getAPCAContrast(tokens.muted.foreground, tokens.muted.DEFAULT, gamut);
|
|
785
885
|
results["muted"] = {
|
|
@@ -944,26 +1044,35 @@ function generateTokens(brandColors, options) {
|
|
|
944
1044
|
};
|
|
945
1045
|
const primitives = generatePrimitivePalette(brandColors, strategy, { ...scaleOptions, gamut: "srgb" });
|
|
946
1046
|
const wide = options?.gamut === "p3" ? generatePrimitivePalette(brandColors, strategy, { ...scaleOptions, gamut: "p3" }) : void 0;
|
|
1047
|
+
const grounds = (palette, mode) => {
|
|
1048
|
+
const surface = generateSurfaceTokens(palette, mode, options?.surfaceShadeOverrides?.[mode], options?.shades, options?.surfaceColors?.[mode], options?.backgrounds);
|
|
1049
|
+
const light = (c) => getContrastRatio(c, "#000000") > getContrastRatio(c, "#ffffff");
|
|
1050
|
+
const pageIsLight = light(surface.canvas);
|
|
1051
|
+
const named = Object.values(surface.backgrounds ?? {}).map((b) => b.DEFAULT).filter((c) => light(c) === pageIsLight);
|
|
1052
|
+
return [surface.canvas, surface.surface, surface.overlay, ...named];
|
|
1053
|
+
};
|
|
947
1054
|
const colourTiers = (palette, gamuts) => ({
|
|
948
1055
|
primitives: palette,
|
|
949
1056
|
semantic: {
|
|
950
|
-
light: generateSemanticTokens(palette, "light", options, gamuts),
|
|
951
|
-
dark: generateSemanticTokens(palette, "dark", options, gamuts)
|
|
1057
|
+
light: generateSemanticTokens(palette, "light", options, gamuts, grounds(palette, "light")),
|
|
1058
|
+
dark: generateSemanticTokens(palette, "dark", options, gamuts, grounds(palette, "dark"))
|
|
952
1059
|
},
|
|
953
1060
|
surface: {
|
|
954
|
-
light: generateSurfaceTokens(palette, "light", options?.surfaceShadeOverrides?.light, options?.shades),
|
|
955
|
-
dark: generateSurfaceTokens(palette, "dark", options?.surfaceShadeOverrides?.dark, options?.shades)
|
|
1061
|
+
light: generateSurfaceTokens(palette, "light", options?.surfaceShadeOverrides?.light, options?.shades, options?.surfaceColors?.light, options?.backgrounds),
|
|
1062
|
+
dark: generateSurfaceTokens(palette, "dark", options?.surfaceShadeOverrides?.dark, options?.shades, options?.surfaceColors?.dark, options?.backgrounds)
|
|
956
1063
|
},
|
|
957
1064
|
utility: {
|
|
958
|
-
light: generateUtilityTokens(palette, "light", options?.utilityShadeOverrides?.light, options?.shades, options?.seedShade),
|
|
959
|
-
dark: generateUtilityTokens(palette, "dark", options?.utilityShadeOverrides?.dark, options?.shades, options?.seedShade)
|
|
1065
|
+
light: generateUtilityTokens(palette, "light", options?.utilityShadeOverrides?.light, options?.shades, options?.seedShade, grounds(palette, "light")),
|
|
1066
|
+
dark: generateUtilityTokens(palette, "dark", options?.utilityShadeOverrides?.dark, options?.shades, options?.seedShade, grounds(palette, "dark"))
|
|
960
1067
|
}
|
|
961
1068
|
});
|
|
1069
|
+
const tiers = colourTiers(primitives, {
|
|
1070
|
+
own: "srgb",
|
|
1071
|
+
...wide ? { other: { gamut: "p3", palette: wide } } : {}
|
|
1072
|
+
});
|
|
962
1073
|
return {
|
|
963
|
-
...
|
|
964
|
-
|
|
965
|
-
...wide ? { other: { gamut: "p3", palette: wide } } : {}
|
|
966
|
-
}),
|
|
1074
|
+
...tiers,
|
|
1075
|
+
pageContrast: { light: pageContrast(tiers, "light"), dark: pageContrast(tiers, "dark") },
|
|
967
1076
|
spacing: {},
|
|
968
1077
|
typography: defaultTypography,
|
|
969
1078
|
radii: defaultRadii,
|
|
@@ -971,6 +1080,57 @@ function generateTokens(brandColors, options) {
|
|
|
971
1080
|
...wide ? { p3: colourTiers(wide, { own: "p3", other: { gamut: "srgb", palette: primitives } }) } : {}
|
|
972
1081
|
};
|
|
973
1082
|
}
|
|
1083
|
+
function pageContrast(tiers, mode) {
|
|
1084
|
+
const surface = tiers.surface[mode];
|
|
1085
|
+
const grounds = { canvas: surface.canvas, surface: surface.surface, overlay: surface.overlay };
|
|
1086
|
+
for (const [name, bg] of Object.entries(surface.backgrounds ?? {})) grounds[`surface-${name}`] = bg.DEFAULT;
|
|
1087
|
+
const colours = {};
|
|
1088
|
+
for (const [name, colour] of Object.entries(tiers.semantic[mode])) {
|
|
1089
|
+
colours[name === "muted" ? "muted-foreground" : name] = name === "muted" ? colour.foreground : colour.DEFAULT;
|
|
1090
|
+
}
|
|
1091
|
+
const out = {};
|
|
1092
|
+
for (const name of Object.keys(colours).sort()) {
|
|
1093
|
+
out[name] = {};
|
|
1094
|
+
for (const ground of Object.keys(grounds)) {
|
|
1095
|
+
out[name][ground] = Math.round(getContrastRatio(colours[name], grounds[ground]) * 100) / 100;
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
return out;
|
|
1099
|
+
}
|
|
1100
|
+
|
|
1101
|
+
// src/usage.ts
|
|
1102
|
+
var TEXT_FLOOR = { "aa-large": 3, aa: 4.5, aaa: 7 };
|
|
1103
|
+
function usageReport(tokens, target = "aa") {
|
|
1104
|
+
const floors = { text: TEXT_FLOOR[target], shape: 3 };
|
|
1105
|
+
const verdict = (r) => r >= floors.text ? "text" : r >= floors.shape ? "shape" : "none";
|
|
1106
|
+
const mode = (m) => {
|
|
1107
|
+
const surface = tokens.surface[m];
|
|
1108
|
+
const grounds = { canvas: surface.canvas, surface: surface.surface, overlay: surface.overlay };
|
|
1109
|
+
for (const [name, bg] of Object.entries(surface.backgrounds ?? {})) grounds[`surface-${name}`] = bg.DEFAULT;
|
|
1110
|
+
const colours = {};
|
|
1111
|
+
for (const [name, colour] of Object.entries(tokens.semantic[m])) {
|
|
1112
|
+
if (name === "muted") {
|
|
1113
|
+
colours["muted-foreground"] = colour.foreground;
|
|
1114
|
+
continue;
|
|
1115
|
+
}
|
|
1116
|
+
colours[name] = colour.DEFAULT;
|
|
1117
|
+
colours[`${name}-subdued-foreground`] = colour["subdued-foreground"];
|
|
1118
|
+
}
|
|
1119
|
+
const out = {};
|
|
1120
|
+
for (const name of Object.keys(colours).sort()) {
|
|
1121
|
+
out[name] = {};
|
|
1122
|
+
for (const g of Object.keys(grounds).sort()) {
|
|
1123
|
+
const ratio = Math.round(getContrastRatio(colours[name], grounds[g]) * 100) / 100;
|
|
1124
|
+
out[name][g] = { ratio, use: verdict(ratio) };
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
return out;
|
|
1128
|
+
};
|
|
1129
|
+
return { schema: "designtools.usage/1", target, floors, light: mode("light"), dark: mode("dark") };
|
|
1130
|
+
}
|
|
1131
|
+
function serialiseUsage(report) {
|
|
1132
|
+
return JSON.stringify(report, null, 2) + "\n";
|
|
1133
|
+
}
|
|
974
1134
|
|
|
975
1135
|
// src/export.ts
|
|
976
1136
|
function formatColor(color, format) {
|
|
@@ -1020,7 +1180,7 @@ function getExtendedMappings(mode, colorName, overrides, active, anchors) {
|
|
|
1020
1180
|
return extendedBridgeShades(mode, seedShade, active, overrides?.[colorName]?.[mode]);
|
|
1021
1181
|
}
|
|
1022
1182
|
var MUTED_SHADE_MAPPINGS = {
|
|
1023
|
-
light: { DEFAULT:
|
|
1183
|
+
light: { DEFAULT: 100, foreground: 500 },
|
|
1024
1184
|
dark: { DEFAULT: 800, foreground: 200 }
|
|
1025
1185
|
};
|
|
1026
1186
|
var UTILITY_SHADE_MAPPINGS = {
|
|
@@ -1048,7 +1208,7 @@ function refToVar(ref) {
|
|
|
1048
1208
|
return `var(--color-${ref.colorName}-${ref.shade})`;
|
|
1049
1209
|
}
|
|
1050
1210
|
}
|
|
1051
|
-
function surfaceRefToVar(ref) {
|
|
1211
|
+
function surfaceRefToVar(ref, colorFormat) {
|
|
1052
1212
|
switch (ref.type) {
|
|
1053
1213
|
case "white":
|
|
1054
1214
|
return "var(--color-white)";
|
|
@@ -1056,25 +1216,25 @@ function surfaceRefToVar(ref) {
|
|
|
1056
1216
|
return "var(--color-black)";
|
|
1057
1217
|
case "shade":
|
|
1058
1218
|
return `var(--color-neutral-${ref.shade})`;
|
|
1219
|
+
// a background passed in as a colour is not on any ramp, so it is written as it is
|
|
1220
|
+
case "value":
|
|
1221
|
+
return formatColor(ref.value, colorFormat);
|
|
1059
1222
|
}
|
|
1060
1223
|
}
|
|
1061
1224
|
function emitSurfaceVars(surface, colorFormat, indent) {
|
|
1062
1225
|
const lines = [];
|
|
1063
|
-
const keys = [
|
|
1064
|
-
"canvas",
|
|
1065
|
-
"canvas-foreground",
|
|
1066
|
-
"surface",
|
|
1067
|
-
"surface-foreground",
|
|
1068
|
-
"overlay",
|
|
1069
|
-
"overlay-foreground"
|
|
1070
|
-
];
|
|
1226
|
+
const keys = ["canvas", "canvas-foreground", "surface", "surface-foreground", "overlay", "overlay-foreground"];
|
|
1071
1227
|
for (const key of keys) {
|
|
1072
1228
|
if (surface._refs) {
|
|
1073
|
-
lines.push(`${indent}--${key}: ${surfaceRefToVar(surface._refs[key])};`);
|
|
1229
|
+
lines.push(`${indent}--${key}: ${surfaceRefToVar(surface._refs[key], colorFormat)};`);
|
|
1074
1230
|
} else {
|
|
1075
1231
|
lines.push(`${indent}--${key}: ${formatColor(surface[key], colorFormat)};`);
|
|
1076
1232
|
}
|
|
1077
1233
|
}
|
|
1234
|
+
for (const [name, bg] of Object.entries(surface.backgrounds ?? {})) {
|
|
1235
|
+
lines.push(`${indent}--surface-${name}: ${surfaceRefToVar(bg._refs.DEFAULT, colorFormat)};`);
|
|
1236
|
+
lines.push(`${indent}--surface-${name}-foreground: ${surfaceRefToVar(bg._refs.foreground, colorFormat)};`);
|
|
1237
|
+
}
|
|
1078
1238
|
return lines;
|
|
1079
1239
|
}
|
|
1080
1240
|
function emitSemanticVars(tokens, mode, colorFormat, shadeOverrides, indent, active, inFamily, scoped, anchors) {
|
|
@@ -1083,36 +1243,41 @@ function emitSemanticVars(tokens, mode, colorFormat, shadeOverrides, indent, act
|
|
|
1083
1243
|
for (const name of extendedSemanticNames) {
|
|
1084
1244
|
if (!inFamily(name)) continue;
|
|
1085
1245
|
const color = tokens.semantic[mode][name];
|
|
1086
|
-
const mappings = getExtendedMappings(mode, name, shadeOverrides, active, anchors);
|
|
1246
|
+
const mappings = color._shades ?? getExtendedMappings(mode, name, shadeOverrides, active, anchors);
|
|
1087
1247
|
lines.push(`${indent}--${name}: var(--color-${name}-${mappings.DEFAULT});`);
|
|
1088
1248
|
lines.push(`${indent}--${name}-foreground: ${color._refs ? refToVar(color._refs.foreground) : formatColor(color.foreground, colorFormat)};`);
|
|
1089
1249
|
lines.push(`${indent}--${name}-subdued: var(--color-${name}-${mappings.subdued});`);
|
|
1090
1250
|
lines.push(`${indent}--${name}-subdued-foreground: ${color._refs ? refToVar(color._refs["subdued-foreground"]) : formatColor(color["subdued-foreground"], colorFormat)};`);
|
|
1091
|
-
lines.push(`${indent}--${name}-
|
|
1092
|
-
lines.push(`${indent}--${name}-
|
|
1251
|
+
lines.push(`${indent}--${name}-hover: ${formatColor(color.hover, colorFormat)};`);
|
|
1252
|
+
lines.push(`${indent}--${name}-active: ${formatColor(color.active, colorFormat)};`);
|
|
1093
1253
|
}
|
|
1094
1254
|
for (const [name, color] of Object.entries(tokens.semantic[mode])) {
|
|
1095
1255
|
if (!extendedSemanticNames.includes(name) && name !== "muted" && inFamily(name)) {
|
|
1096
1256
|
const ext = color;
|
|
1097
|
-
const mappings = getExtendedMappings(mode, name, shadeOverrides, active, anchors);
|
|
1257
|
+
const mappings = ext._shades ?? getExtendedMappings(mode, name, shadeOverrides, active, anchors);
|
|
1098
1258
|
lines.push(`${indent}--${name}: var(--color-${name}-${mappings.DEFAULT});`);
|
|
1099
1259
|
lines.push(`${indent}--${name}-foreground: ${ext._refs ? refToVar(ext._refs.foreground) : formatColor(ext.foreground, colorFormat)};`);
|
|
1100
1260
|
lines.push(`${indent}--${name}-subdued: var(--color-${name}-${mappings.subdued});`);
|
|
1101
1261
|
lines.push(`${indent}--${name}-subdued-foreground: ${ext._refs ? refToVar(ext._refs["subdued-foreground"]) : formatColor(ext["subdued-foreground"], colorFormat)};`);
|
|
1102
|
-
lines.push(`${indent}--${name}-
|
|
1103
|
-
lines.push(`${indent}--${name}-
|
|
1262
|
+
lines.push(`${indent}--${name}-hover: ${formatColor(ext.hover, colorFormat)};`);
|
|
1263
|
+
lines.push(`${indent}--${name}-active: ${formatColor(ext.active, colorFormat)};`);
|
|
1104
1264
|
}
|
|
1105
1265
|
}
|
|
1106
1266
|
if (!scoped || inFamily("neutral")) {
|
|
1107
|
-
const muted = MUTED_SHADE_MAPPINGS[mode];
|
|
1267
|
+
const muted = tokens.semantic[mode].muted._shades ?? MUTED_SHADE_MAPPINGS[mode];
|
|
1108
1268
|
lines.push(`${indent}--muted: var(--color-neutral-${snapShade(muted.DEFAULT, active)});`);
|
|
1109
1269
|
lines.push(`${indent}--muted-foreground: var(--color-neutral-${snapShade(muted.foreground, active)});`);
|
|
1110
1270
|
}
|
|
1111
1271
|
return lines;
|
|
1112
1272
|
}
|
|
1113
|
-
function emitUtilityVars(mode, indent, active, seedShade) {
|
|
1273
|
+
function emitUtilityVars(mode, indent, active, seedShade, steps) {
|
|
1114
1274
|
const fixed = UTILITY_SHADE_MAPPINGS[mode];
|
|
1115
|
-
const refs = [
|
|
1275
|
+
const refs = steps ? [
|
|
1276
|
+
["border", `neutral-${steps.border}`],
|
|
1277
|
+
["input", `neutral-${steps.input}`],
|
|
1278
|
+
["ring", `primary-${steps.ring}`],
|
|
1279
|
+
["shadow", `neutral-${steps.shadow}`]
|
|
1280
|
+
] : [
|
|
1116
1281
|
["border", fixed.border],
|
|
1117
1282
|
["input", fixed.input],
|
|
1118
1283
|
["ring", `primary-${ringBridgeShade(mode, seedShade, active)}`],
|
|
@@ -1144,7 +1309,7 @@ function exportToCss(tokens, colorFormat = "hex", shadeOverrides, sections, shad
|
|
|
1144
1309
|
}
|
|
1145
1310
|
if (want.has("utility") && !scoped) {
|
|
1146
1311
|
if (withComments) body.push(`${indent}/* Utility */`);
|
|
1147
|
-
body.push(...emitUtilityVars(mode, indent, active, seedShade));
|
|
1312
|
+
body.push(...emitUtilityVars(mode, indent, active, seedShade, tokens.utility[mode]._steps));
|
|
1148
1313
|
if (withComments) body.push("");
|
|
1149
1314
|
}
|
|
1150
1315
|
if (want.has("semantic")) {
|
|
@@ -1242,8 +1407,8 @@ function semanticAliasNames(tokens, sections, families) {
|
|
|
1242
1407
|
`${n}-foreground`,
|
|
1243
1408
|
`${n}-subdued`,
|
|
1244
1409
|
`${n}-subdued-foreground`,
|
|
1245
|
-
`${n}-
|
|
1246
|
-
`${n}-
|
|
1410
|
+
`${n}-hover`,
|
|
1411
|
+
`${n}-active`
|
|
1247
1412
|
);
|
|
1248
1413
|
};
|
|
1249
1414
|
if (want.has("semantic")) {
|
|
@@ -1262,6 +1427,9 @@ function semanticAliasNames(tokens, sections, families) {
|
|
|
1262
1427
|
"overlay",
|
|
1263
1428
|
"overlay-foreground"
|
|
1264
1429
|
);
|
|
1430
|
+
for (const name of Object.keys(tokens.surface.light.backgrounds ?? {})) {
|
|
1431
|
+
names.push(`surface-${name}`, `surface-${name}-foreground`);
|
|
1432
|
+
}
|
|
1265
1433
|
}
|
|
1266
1434
|
if (want.has("utility") && !scoped) {
|
|
1267
1435
|
names.push("border", "input", "ring", "shadow");
|
|
@@ -1287,7 +1455,7 @@ function emitTailwindV4Mode(tokens, mode, colorFormat, shadeOverrides, aliases,
|
|
|
1287
1455
|
}
|
|
1288
1456
|
if (want.has("utility") && !scoped) {
|
|
1289
1457
|
lines.push(`${indent}/* Utility */`);
|
|
1290
|
-
lines.push(...emitUtilityVars(mode, indent, active, seedShade));
|
|
1458
|
+
lines.push(...emitUtilityVars(mode, indent, active, seedShade, tokens.utility[mode]._steps));
|
|
1291
1459
|
lines.push("");
|
|
1292
1460
|
}
|
|
1293
1461
|
if (want.has("semantic")) {
|
|
@@ -1376,8 +1544,8 @@ function exportToTailwindV3(tokens, colorFormat = "hex") {
|
|
|
1376
1544
|
foreground: `var(--${name}-foreground)`,
|
|
1377
1545
|
subdued: `var(--${name}-subdued)`,
|
|
1378
1546
|
"subdued-foreground": `var(--${name}-subdued-foreground)`,
|
|
1379
|
-
|
|
1380
|
-
|
|
1547
|
+
hover: `var(--${name}-hover)`,
|
|
1548
|
+
active: `var(--${name}-active)`
|
|
1381
1549
|
};
|
|
1382
1550
|
if (primitiveScale && typeof primitiveScale !== "string") {
|
|
1383
1551
|
for (const [shade, color] of Object.entries(primitiveScale)) {
|
|
@@ -1394,8 +1562,8 @@ function exportToTailwindV3(tokens, colorFormat = "hex") {
|
|
|
1394
1562
|
foreground: `var(--${name}-foreground)`,
|
|
1395
1563
|
subdued: `var(--${name}-subdued)`,
|
|
1396
1564
|
"subdued-foreground": `var(--${name}-subdued-foreground)`,
|
|
1397
|
-
|
|
1398
|
-
|
|
1565
|
+
hover: `var(--${name}-hover)`,
|
|
1566
|
+
active: `var(--${name}-active)`
|
|
1399
1567
|
};
|
|
1400
1568
|
if (primitiveScale && typeof primitiveScale !== "string") {
|
|
1401
1569
|
for (const [shade, color] of Object.entries(primitiveScale)) {
|
|
@@ -1459,10 +1627,8 @@ function exportToDtcg(tokens) {
|
|
|
1459
1627
|
"subdued-foreground": {
|
|
1460
1628
|
$value: formatColorAs(color["subdued-foreground"], "hex")
|
|
1461
1629
|
},
|
|
1462
|
-
|
|
1463
|
-
"
|
|
1464
|
-
$value: formatColorAs(color["highlight-foreground"], "hex")
|
|
1465
|
-
}
|
|
1630
|
+
hover: { $value: formatColorAs(color.hover, "hex") },
|
|
1631
|
+
active: { $value: formatColorAs(color.active, "hex") }
|
|
1466
1632
|
};
|
|
1467
1633
|
}
|
|
1468
1634
|
for (const [colorName, color] of Object.entries(tokens.semantic[mode])) {
|
|
@@ -1476,10 +1642,8 @@ function exportToDtcg(tokens) {
|
|
|
1476
1642
|
"subdued-foreground": {
|
|
1477
1643
|
$value: formatColorAs(ext["subdued-foreground"], "hex")
|
|
1478
1644
|
},
|
|
1479
|
-
|
|
1480
|
-
"
|
|
1481
|
-
$value: formatColorAs(ext["highlight-foreground"], "hex")
|
|
1482
|
-
}
|
|
1645
|
+
hover: { $value: formatColorAs(ext.hover, "hex") },
|
|
1646
|
+
active: { $value: formatColorAs(ext.active, "hex") }
|
|
1483
1647
|
};
|
|
1484
1648
|
}
|
|
1485
1649
|
}
|
|
@@ -1764,6 +1928,8 @@ function withJsonProvenance(json, p) {
|
|
|
1764
1928
|
}
|
|
1765
1929
|
|
|
1766
1930
|
export {
|
|
1931
|
+
APCAUnavailableError,
|
|
1932
|
+
isAPCAAvailable,
|
|
1767
1933
|
VALID_SHADES,
|
|
1768
1934
|
DEFAULT_SEED_SHADE,
|
|
1769
1935
|
TAILWIND_SHADES,
|
|
@@ -1797,6 +1963,7 @@ export {
|
|
|
1797
1963
|
familySeedShade,
|
|
1798
1964
|
generatePrimitivePalette,
|
|
1799
1965
|
getShade,
|
|
1966
|
+
bridgeShade,
|
|
1800
1967
|
extendedBridgeShades,
|
|
1801
1968
|
ringBridgeShade,
|
|
1802
1969
|
generateSemanticTokens,
|
|
@@ -1808,6 +1975,8 @@ export {
|
|
|
1808
1975
|
checkRampChroma,
|
|
1809
1976
|
computeAccessibilityScore,
|
|
1810
1977
|
generateTokens,
|
|
1978
|
+
usageReport,
|
|
1979
|
+
serialiseUsage,
|
|
1811
1980
|
WIDE_GAMUT_QUERY,
|
|
1812
1981
|
exportToCss,
|
|
1813
1982
|
overrideContract,
|