@multiplatform.one/theme 9.1.0 → 9.3.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.
Files changed (145) hide show
  1. package/README.md +23 -0
  2. package/dist/cjs/index.gnome.cjs +9 -0
  3. package/dist/cjs/index.gnome.native.js +9 -0
  4. package/dist/cjs/index.gnome.native.js.map +1 -1
  5. package/dist/cjs/menuRow.cjs +4 -0
  6. package/dist/cjs/menuRow.native.js +4 -0
  7. package/dist/cjs/menuRow.native.js.map +1 -1
  8. package/dist/cjs/theme/accentHue.cjs +71 -0
  9. package/dist/cjs/theme/accentHue.native.js +82 -0
  10. package/dist/cjs/theme/accentHue.native.js.map +1 -0
  11. package/dist/cjs/theme/chartPalette.cjs +50 -29
  12. package/dist/cjs/theme/chartPalette.native.js +60 -33
  13. package/dist/cjs/theme/chartPalette.native.js.map +1 -1
  14. package/dist/cjs/theme/createDefaultThemeConfig.cjs +14 -1
  15. package/dist/cjs/theme/createDefaultThemeConfig.native.js +14 -1
  16. package/dist/cjs/theme/createDefaultThemeConfig.native.js.map +1 -1
  17. package/dist/cjs/theme/createThemes.cjs +84 -40
  18. package/dist/cjs/theme/createThemes.native.js +112 -39
  19. package/dist/cjs/theme/createThemes.native.js.map +1 -1
  20. package/dist/cjs/theme/defaults/builderOptions.cjs +30 -5
  21. package/dist/cjs/theme/defaults/builderOptions.native.js +34 -6
  22. package/dist/cjs/theme/defaults/builderOptions.native.js.map +1 -1
  23. package/dist/cjs/theme/index.cjs +1 -0
  24. package/dist/cjs/theme/index.native.js +1 -0
  25. package/dist/cjs/theme/index.native.js.map +1 -1
  26. package/dist/cjs/theme/overlaySurfaces.cjs +53 -4
  27. package/dist/cjs/theme/overlaySurfaces.native.js +53 -4
  28. package/dist/cjs/theme/overlaySurfaces.native.js.map +1 -1
  29. package/dist/cjs/theme/pageGutter.cjs +27 -2
  30. package/dist/cjs/theme/pageGutter.native.js +52 -2
  31. package/dist/cjs/theme/pageGutter.native.js.map +1 -1
  32. package/dist/cjs/theme/resolveKnobs.cjs +12 -0
  33. package/dist/cjs/theme/resolveKnobs.native.js +12 -0
  34. package/dist/cjs/theme/resolveKnobs.native.js.map +1 -1
  35. package/dist/cjs/theme/tintHues.cjs +8 -2
  36. package/dist/cjs/theme/tintHues.native.js +7 -1
  37. package/dist/cjs/theme/tintHues.native.js.map +1 -1
  38. package/dist/cjs/theme/v3TokenRoles.cjs +2 -2
  39. package/dist/cjs/theme/v3TokenRoles.native.js +2 -2
  40. package/dist/cjs/theme/v3TokenRoles.native.js.map +1 -1
  41. package/dist/esm/index.gnome.mjs +4 -4
  42. package/dist/esm/index.gnome.mjs.map +1 -1
  43. package/dist/esm/index.gnome.native.js +4 -4
  44. package/dist/esm/index.gnome.native.js.map +1 -1
  45. package/dist/esm/menuRow.mjs +4 -1
  46. package/dist/esm/menuRow.mjs.map +1 -1
  47. package/dist/esm/menuRow.native.js +4 -1
  48. package/dist/esm/menuRow.native.js.map +1 -1
  49. package/dist/esm/theme/accentHue.mjs +42 -0
  50. package/dist/esm/theme/accentHue.mjs.map +1 -0
  51. package/dist/esm/theme/accentHue.native.js +50 -0
  52. package/dist/esm/theme/accentHue.native.js.map +1 -0
  53. package/dist/esm/theme/chartPalette.mjs +51 -30
  54. package/dist/esm/theme/chartPalette.mjs.map +1 -1
  55. package/dist/esm/theme/chartPalette.native.js +61 -34
  56. package/dist/esm/theme/chartPalette.native.js.map +1 -1
  57. package/dist/esm/theme/createDefaultThemeConfig.mjs +14 -1
  58. package/dist/esm/theme/createDefaultThemeConfig.mjs.map +1 -1
  59. package/dist/esm/theme/createDefaultThemeConfig.native.js +14 -1
  60. package/dist/esm/theme/createDefaultThemeConfig.native.js.map +1 -1
  61. package/dist/esm/theme/createThemes.mjs +85 -42
  62. package/dist/esm/theme/createThemes.mjs.map +1 -1
  63. package/dist/esm/theme/createThemes.native.js +113 -41
  64. package/dist/esm/theme/createThemes.native.js.map +1 -1
  65. package/dist/esm/theme/defaults/builderOptions.mjs +31 -6
  66. package/dist/esm/theme/defaults/builderOptions.mjs.map +1 -1
  67. package/dist/esm/theme/defaults/builderOptions.native.js +35 -7
  68. package/dist/esm/theme/defaults/builderOptions.native.js.map +1 -1
  69. package/dist/esm/theme/index.mjs +1 -0
  70. package/dist/esm/theme/index.mjs.map +1 -1
  71. package/dist/esm/theme/index.native.js +1 -0
  72. package/dist/esm/theme/index.native.js.map +1 -1
  73. package/dist/esm/theme/overlaySurfaces.mjs +47 -4
  74. package/dist/esm/theme/overlaySurfaces.mjs.map +1 -1
  75. package/dist/esm/theme/overlaySurfaces.native.js +47 -4
  76. package/dist/esm/theme/overlaySurfaces.native.js.map +1 -1
  77. package/dist/esm/theme/pageGutter.mjs +27 -4
  78. package/dist/esm/theme/pageGutter.mjs.map +1 -1
  79. package/dist/esm/theme/pageGutter.native.js +52 -4
  80. package/dist/esm/theme/pageGutter.native.js.map +1 -1
  81. package/dist/esm/theme/resolveKnobs.mjs +12 -0
  82. package/dist/esm/theme/resolveKnobs.mjs.map +1 -1
  83. package/dist/esm/theme/resolveKnobs.native.js +12 -0
  84. package/dist/esm/theme/resolveKnobs.native.js.map +1 -1
  85. package/dist/esm/theme/tintHues.mjs +6 -1
  86. package/dist/esm/theme/tintHues.mjs.map +1 -1
  87. package/dist/esm/theme/tintHues.native.js +6 -1
  88. package/dist/esm/theme/tintHues.native.js.map +1 -1
  89. package/dist/esm/theme/v3TokenRoles.mjs +2 -2
  90. package/dist/esm/theme/v3TokenRoles.native.js +2 -2
  91. package/package.json +5 -5
  92. package/src/figma/figmaTokens.spec.ts +2 -2
  93. package/src/index.gnome.ts +9 -0
  94. package/src/menuRow.palette.spec.ts +26 -1
  95. package/src/menuRow.spec.ts +17 -1
  96. package/src/menuRow.ts +12 -0
  97. package/src/theme/accentHue.spec.ts +252 -0
  98. package/src/theme/accentHue.ts +73 -0
  99. package/src/theme/chartCategoricalSeverity.spec.ts +190 -0
  100. package/src/theme/chartPalette.spec.ts +37 -34
  101. package/src/theme/chartPalette.ts +90 -39
  102. package/src/theme/colorRules.spec.ts +3 -3
  103. package/src/theme/createDefaultThemeConfig.spec.ts +71 -2
  104. package/src/theme/createDefaultThemeConfig.ts +47 -5
  105. package/src/theme/createThemes.ts +167 -59
  106. package/src/theme/defaults/builderOptions.ts +41 -9
  107. package/src/theme/defaults/secondaryInk.spec.ts +71 -0
  108. package/src/theme/index.ts +1 -0
  109. package/src/theme/intentFill.spec.ts +8 -3
  110. package/src/theme/overlaySurfaces.tsx +75 -6
  111. package/src/theme/pageGutter.spec.tsx +2 -2
  112. package/src/theme/pageGutter.tsx +55 -2
  113. package/src/theme/rampRoles.spec.ts +60 -0
  114. package/src/theme/recipes.ts +2 -0
  115. package/src/theme/resolveKnobs.spec.ts +17 -0
  116. package/src/theme/resolveKnobs.ts +12 -0
  117. package/src/theme/severityChannel.spec.ts +202 -0
  118. package/src/theme/sheetHandle.spec.ts +54 -0
  119. package/src/theme/tintHues.ts +10 -0
  120. package/src/theme/v3TokenRoles.ts +2 -2
  121. package/types/index.gnome.d.ts +3 -3
  122. package/types/index.gnome.d.ts.map +1 -1
  123. package/types/menuRow.d.ts +9 -0
  124. package/types/menuRow.d.ts.map +1 -1
  125. package/types/theme/accentHue.d.ts +20 -0
  126. package/types/theme/accentHue.d.ts.map +1 -0
  127. package/types/theme/chartPalette.d.ts +2 -2
  128. package/types/theme/chartPalette.d.ts.map +1 -1
  129. package/types/theme/createDefaultThemeConfig.d.ts +12 -10
  130. package/types/theme/createDefaultThemeConfig.d.ts.map +1 -1
  131. package/types/theme/createThemes.d.ts +17 -2
  132. package/types/theme/createThemes.d.ts.map +1 -1
  133. package/types/theme/defaults/builderOptions.d.ts.map +1 -1
  134. package/types/theme/index.d.ts +1 -0
  135. package/types/theme/index.d.ts.map +1 -1
  136. package/types/theme/overlaySurfaces.d.ts +61 -3
  137. package/types/theme/overlaySurfaces.d.ts.map +1 -1
  138. package/types/theme/pageGutter.d.ts +26 -1
  139. package/types/theme/pageGutter.d.ts.map +1 -1
  140. package/types/theme/recipes.d.ts +4 -0
  141. package/types/theme/recipes.d.ts.map +1 -1
  142. package/types/theme/resolveKnobs.d.ts.map +1 -1
  143. package/types/theme/tintHues.d.ts +5 -0
  144. package/types/theme/tintHues.d.ts.map +1 -1
  145. package/types/theme/v3TokenRoles.d.ts +2 -2
@@ -25,8 +25,9 @@ import {
25
25
  import { darkHairlineContrast, pickSecondaryInk } from "./defaults/builderOptions";
26
26
  import { themeRampHues } from "./ramps";
27
27
  import { pageSurfaces, pickIdentityInk, withAccentOnSurface, withIdentityInk } from "./accentInk";
28
+ import type { AccentHue } from "./accentHue";
28
29
  import { resolveThemeThroughParents } from "./dedupeInherited";
29
- import { tintHueNames } from "./tintHues";
30
+ import { tintHueNames, tintThemeScheme } from "./tintHues";
30
31
 
31
32
  export { tintHueNames };
32
33
 
@@ -38,9 +39,9 @@ export { tintHueNames };
38
39
  * stock within one degree of its hue, then checked against the built theme.
39
40
  * Only light step 11 changes; the base ramp stays stock v5.
40
41
  */
41
- const intentInkFloor = {
42
- /** Stored hsla(41, 99%, 30%, 1); 4.54:1 on $color2, dE76 2.54. */
43
- warning: "#986801",
42
+ export const intentInkFloor = {
43
+ /** Stored hsla(35, 98%, 32%, 1); amber at OKLCH hue 64, 4.70:1 on $color2 (LC-288). */
44
+ warning: "#a25f02",
44
45
  /** Stored hsla(154, 63%, 31%, 1); 4.53:1 on $color2, dE76 0.82. */
45
46
  success: "#1d8156",
46
47
  } as const;
@@ -58,6 +59,66 @@ function withIntentInkFloor(palette: string[], ink: string): string[] {
58
59
  return stepped;
59
60
  }
60
61
 
62
+ /** The warning scope's ramps (LC-288): amber, with light step 11 held at the ink floor. */
63
+ const warningPalette = {
64
+ dark: Object.values(Colors.amberDark),
65
+ light: withIntentInkFloor(Object.values(Colors.amber), intentInkFloor.warning),
66
+ };
67
+
68
+ /**
69
+ * LC-288: a status mark, wash or ink outside a `<Theme name="warning">`
70
+ * (a StatusDot, a log level, an Avatar pip, the console's `$warning`) reads
71
+ * the warning scope through these root keys, never a `$yellow` ramp token,
72
+ * which stays a data colour. They copy the built scope's steps 3, 9 and 11.
73
+ *
74
+ * `warningFill`, `errorFill` and `successFill` are a bar on a track (a
75
+ * Meter's zone). Each is the first of the severity's steps 9 to 11 that
76
+ * clears WCAG 1.4.11's 3:1 against the `$color4` track of the scheme root
77
+ * and every hue theme in it (the inverted accent scope is no track). Light
78
+ * amber 9 and 10 sit near 1.2:1 on a light track, so light warning lands on
79
+ * step 11.
80
+ */
81
+ const severityFillContrast = 3;
82
+
83
+ function pickSeverityFill(
84
+ themes: Record<string, Record<string, unknown>>,
85
+ scheme: "light" | "dark",
86
+ severity: "warning" | "error" | "success",
87
+ ): unknown {
88
+ const scope = themes[`${scheme}_${severity}`];
89
+ if (!scope) return undefined;
90
+ const tracks = Object.keys(themes)
91
+ .filter((name) => new RegExp(`^${scheme}(_[a-z]+)?$`).test(name))
92
+ .filter((name) => !/_(warning|error|success|accent)$/.test(name))
93
+ .map((name) => luminanceOf(themes[name]?.color4 as string | undefined))
94
+ .filter((value): value is number => value != null);
95
+ for (const step of [9, 10, 11]) {
96
+ const fill = luminanceOf(scope[`color${step}`] as string | undefined);
97
+ if (fill == null) continue;
98
+ if (tracks.every((track) => contrastRatio(fill, track) >= severityFillContrast)) {
99
+ return scope[`color${step}`];
100
+ }
101
+ }
102
+ return scope.color11;
103
+ }
104
+
105
+ function holdWarningRoleKeys<T extends Record<string, Record<string, unknown>>>(themes: T): T {
106
+ for (const scheme of ["light", "dark"] as const) {
107
+ const root = themes[scheme];
108
+ const warning = themes[`${scheme}_warning`];
109
+ if (!root || !warning) continue;
110
+ Object.assign(root, {
111
+ warningSoft: warning.color3,
112
+ warningMark: warning.color9,
113
+ warningInk: warning.color11,
114
+ warningFill: pickSeverityFill(themes, scheme, "warning"),
115
+ errorFill: pickSeverityFill(themes, scheme, "error"),
116
+ successFill: pickSeverityFill(themes, scheme, "success"),
117
+ });
118
+ }
119
+ return themes;
120
+ }
121
+
61
122
  /**
62
123
  * LC-151 SURFACE-LADDER. Cards, list items and fields sit on the grey page as
63
124
  * the white `$color1` step in light, the inset-grouped ladder. v5's surface1
@@ -243,18 +304,16 @@ const tintNeutralTextKeys = [
243
304
  * Rebuild tint sub-themes (light_purple, dark_red_active, ...) so their
244
305
  * text tiers come from the neutral base scheme while backgrounds, borders
245
306
  * and solid steps (1-10) keep the hue. Only keys the tint theme already
246
- * defines are replaced; returns new objects, never mutates inputs.
307
+ * defines are replaced, except `textMuted`, which is filled only where the
308
+ * getTheme left it unset; returns new objects, never mutates inputs.
247
309
  */
248
310
  function neutralizeTintText(
249
311
  themes: Record<string, Record<string, string>>,
250
312
  ): Record<string, Record<string, string>> {
251
313
  const out: Record<string, Record<string, string>> = { ...themes };
252
314
  for (const [name, theme] of Object.entries(themes)) {
253
- const parts = name.split("_");
254
- if (parts.length < 2) continue;
255
- const scheme = parts[0];
256
- if (scheme !== "light" && scheme !== "dark") continue;
257
- if (!tintHueNames.has(parts[1])) continue;
315
+ const scheme = tintThemeScheme(name);
316
+ if (!scheme) continue;
258
317
  const base = themes[scheme];
259
318
  if (!base) continue;
260
319
  const patched: Record<string, string> = { ...theme };
@@ -265,7 +324,8 @@ function neutralizeTintText(
265
324
  // that clears 7:1 on this tint's own surfaces. The hue's step, picked on
266
325
  // its palette, measured 4:1 on light tints; the scheme's own pick, 6.6:1
267
326
  // on dark_blue.
268
- if ("textMuted" in patched) patched.textMuted = pickSecondaryInk(patched, base);
327
+ if (!("textMuted" in patched) && patched.color5 != null && base.textMuted != null)
328
+ patched.textMuted = pickSecondaryInk(patched, base);
269
329
  out[name] = patched;
270
330
  }
271
331
  return out;
@@ -1225,28 +1285,63 @@ function isFullRamp(steps: (string | undefined)[]): steps is string[] {
1225
1285
  return !steps.includes(undefined);
1226
1286
  }
1227
1287
 
1288
+ /**
1289
+ * FZ-11155. How far a selected tint stands off the root's page and card, the
1290
+ * weaker of the two. A hue scope picks its selected tint against its own
1291
+ * tinted `$color4`, so on the neutral root it can vanish (purple's dark tint
1292
+ * measured 1.00:1 on the grey card).
1293
+ */
1294
+ function selectedStandOff(base: Record<string, string>, tint: string | undefined): number {
1295
+ const tintLum = luminanceOf(tint);
1296
+ const grounds = [base.color1, base.color4].map(luminanceOf);
1297
+ if (tintLum === null || grounds.includes(null)) return 0;
1298
+ return Math.min(...grounds.map((ground) => contrastRatio(tintLum, ground as number)));
1299
+ }
1300
+
1301
+ /**
1302
+ * FZ-11155. The root's selected pair: the hue scope's when it stands off the
1303
+ * root's page and card as far as the house blue's does, so the default build
1304
+ * keeps blue's approved pair byte for byte. Otherwise the pair is picked from
1305
+ * the hue ramp on the root's own grounds.
1306
+ */
1307
+ function rootSelectedPair(
1308
+ base: Record<string, string>,
1309
+ scope: Record<string, string>,
1310
+ ramp: string[],
1311
+ accentColor: string,
1312
+ houseStandOff: number,
1313
+ ): { selectedBackground: string; selectedColor: string } {
1314
+ const scopePair = {
1315
+ selectedBackground: scope.selectedBackground,
1316
+ selectedColor: scope.selectedColor,
1317
+ };
1318
+ if (selectedStandOff(base, scope.selectedBackground) >= houseStandOff) return scopePair;
1319
+ return selectedPaint(base, ramp, accentColor) ?? scopePair;
1320
+ }
1321
+
1228
1322
  function houseAccentOf(
1229
1323
  base: Record<string, string>,
1230
- blue: Record<string, string>,
1324
+ scope: Record<string, string>,
1325
+ hue: AccentHue,
1326
+ houseStandOff: number,
1231
1327
  ): HouseAccent | null {
1232
1328
  const steps = Array.from({ length: 12 }, (_, index) => base[`accent${index + 1}`]);
1233
1329
  if (!isAchromaticRamp(steps)) return null;
1234
1330
  const ramp: (string | undefined)[] = Array.from(
1235
1331
  { length: 12 },
1236
- (_, index) => base[`blue${index + 1}`] || undefined,
1332
+ (_, index) => base[`${hue}${index + 1}`] || undefined,
1237
1333
  );
1238
1334
  const surfaces = [base.color1, base.color2, base.color3, base.color4].map(luminanceOf);
1239
1335
  if (!isFullRamp(ramp) || surfaces.includes(null)) return null;
1240
1336
  const holdsInk = (lum: number) =>
1241
1337
  surfaces.every((surface) => contrastRatio(lum, surface as number) >= aaTextContrastRatio);
1338
+ const accentColor =
1339
+ walkToHoldingInk(ramp[10], ramp[11], holdsInk) ?? nearestHoldingStep(ramp[10], ramp, holdsInk);
1242
1340
  return {
1243
1341
  accent: {
1244
- accentBackground: blue.accentBackground,
1245
- accentColor:
1246
- walkToHoldingInk(ramp[10], ramp[11], holdsInk) ??
1247
- nearestHoldingStep(ramp[10], ramp, holdsInk),
1248
- selectedBackground: blue.selectedBackground,
1249
- selectedColor: blue.selectedColor,
1342
+ accentBackground: scope.accentBackground,
1343
+ accentColor,
1344
+ ...rootSelectedPair(base, scope, ramp, accentColor, houseStandOff),
1250
1345
  },
1251
1346
  accentSteps: Object.fromEntries(ramp.map((step, index) => [`accent${index + 1}`, step])),
1252
1347
  };
@@ -1274,23 +1369,26 @@ function heldTheme(
1274
1369
  * FZ-10073 (Clay, rv_4ef347aae208f200: "Neutral gray"). The house look is the
1275
1370
  * scheme root: v5's grey page and white cards (LC-151) under Apple's system
1276
1371
  * tint (LC-172). A root whose accent ramp is grey, the stock inverse, takes
1277
- * the blue colour theme's accent and keeps its neutral ground: the blue ramp
1278
- * as its accent steps, blue's fill and selected pair, accent ink held on the
1279
- * root's own surfaces, and blue's solid for `theme="accent"` and every
1372
+ * the `accentHue` colour theme's accent (blue unless the app names another)
1373
+ * and keeps its neutral ground: that ramp as its accent steps, its fill and
1374
+ * selected pair, accent ink held on the root's own surfaces, and its solid
1375
+ * for `theme="accent"` and every
1280
1376
  * `<scheme>_accent_<Component>` under it. Themes that carried the grey pair
1281
1377
  * (the intents) follow the root. A consumer's own accent palette is left as
1282
1378
  * it is.
1283
1379
  */
1284
1380
  function holdHouseAccent(
1285
1381
  themes: Record<string, Record<string, string>>,
1382
+ hue: AccentHue,
1286
1383
  ): Record<string, Record<string, string>> {
1287
1384
  const out: Record<string, Record<string, string>> = { ...themes };
1288
1385
  for (const scheme of ["light", "dark"] as const) {
1289
1386
  const base = themes[scheme];
1290
- const blue = themes[`${scheme}_blue`];
1291
- const solid = themes[`${scheme}_blue_accent`];
1292
- if (!base || !blue || !solid) continue;
1293
- const house = houseAccentOf(base, blue);
1387
+ const scope = themes[`${scheme}_${hue}`];
1388
+ const solid = themes[`${scheme}_${hue}_accent`];
1389
+ if (!base || !scope || !solid) continue;
1390
+ const houseStandOff = selectedStandOff(base, themes[`${scheme}_blue`]?.selectedBackground);
1391
+ const house = houseAccentOf(base, scope, hue, houseStandOff);
1294
1392
  if (!house) continue;
1295
1393
  for (const [name, theme] of Object.entries(themes)) {
1296
1394
  const held = heldTheme(name, theme, scheme, base, solid, house);
@@ -1302,49 +1400,51 @@ function holdHouseAccent(
1302
1400
 
1303
1401
  /**
1304
1402
  * FZ-10073 with FZ-8400's dark overlay. The house root's identity ink is the
1305
- * blue colour theme's. Judged on the neutral page alone, dark house picked
1403
+ * `accentHue` colour theme's. Judged on the neutral page alone, dark house picked
1306
1404
  * blue10 #3b9eff, which fails AA on blue's own `$color5` overlay, where blue
1307
1405
  * picks blue11 #70b8ff. A house theme (the scheme root, its components and
1308
- * the intents that followed it) takes blue's ink when that ink also holds AA
1309
- * on its own page surfaces, so the bar glyph is one blue in either scope.
1406
+ * the intents that followed it) takes that scope's ink when that ink also holds AA
1407
+ * on its own page surfaces, so the bar glyph is one ink in either scope.
1310
1408
  */
1311
1409
  function holdHouseIdentityInk(
1312
1410
  themes: Record<string, Record<string, string>>,
1411
+ hue: AccentHue,
1313
1412
  ): Record<string, Record<string, string>> {
1314
1413
  const out: Record<string, Record<string, string>> = { ...themes };
1315
1414
  for (const scheme of ["light", "dark"] as const) {
1316
1415
  const base = themes[scheme];
1317
- const blueInk = themes[`${scheme}_blue`]?.identityInk;
1318
- if (!base?.identityInk || !blueInk || base.identityInk === blueInk) continue;
1319
- if (!accentIsBlue(base)) continue;
1416
+ const hueInk = themes[`${scheme}_${hue}`]?.identityInk;
1417
+ if (!base?.identityInk || !hueInk || base.identityInk === hueInk) continue;
1418
+ if (!accentIsHue(base, hue)) continue;
1320
1419
  for (const [name, theme] of Object.entries(themes)) {
1321
- if (takesBlueInk(themes, scheme, name, theme, base, blueInk))
1322
- out[name] = { ...theme, identityInk: blueInk };
1420
+ if (takesHueInk(themes, scheme, name, theme, base, hueInk))
1421
+ out[name] = { ...theme, identityInk: hueInk };
1323
1422
  }
1324
1423
  }
1325
1424
  return out;
1326
1425
  }
1327
1426
 
1328
- function accentIsBlue(base: Record<string, string>): boolean {
1427
+ function accentIsHue(base: Record<string, string>, hue: AccentHue): boolean {
1329
1428
  return Array.from({ length: 12 }, (_, index) => index + 1).every(
1330
- (step) => base[`accent${step}`] !== undefined && base[`accent${step}`] === base[`blue${step}`],
1429
+ (step) =>
1430
+ base[`accent${step}`] !== undefined && base[`accent${step}`] === base[`${hue}${step}`],
1331
1431
  );
1332
1432
  }
1333
1433
 
1334
- function takesBlueInk(
1434
+ function takesHueInk(
1335
1435
  themes: Record<string, Record<string, string>>,
1336
1436
  scheme: "light" | "dark",
1337
1437
  name: string,
1338
1438
  theme: Record<string, string>,
1339
1439
  base: Record<string, string>,
1340
- blueInk: string,
1440
+ hueInk: string,
1341
1441
  ): boolean {
1342
1442
  if (name !== scheme && !name.startsWith(`${scheme}_`)) return false;
1343
1443
  const scope = name.split("_")[1];
1344
1444
  if (scope === "accent" || (childrenHues as readonly string[]).includes(scope)) return false;
1345
1445
  if (theme.identityInk !== base.identityInk) return false;
1346
1446
  const values = resolveThemeThroughParents(themes, name);
1347
- return pickIdentityInk([blueInk], pageSurfaces(name, values)) === blueInk;
1447
+ return pickIdentityInk([hueInk], pageSurfaces(name, values)) === hueInk;
1348
1448
  }
1349
1449
 
1350
1450
  const defaultLightShadows: Shadows = {
@@ -1379,12 +1479,13 @@ const childrenHues = [
1379
1479
  /**
1380
1480
  * FZ-7944 round 2, LC-71: the keyboard ring is the accent, never a white or
1381
1481
  * black neutral. A hue scope rings in its own accent ink. The roots ring in
1382
- * their own accent ink, or in the blue scope's when theirs is grey, the
1482
+ * their own accent ink, or in the `accentHue` scope's when theirs is grey, the
1383
1483
  * default accent on Apple platforms. Solid accent sub-themes keep the on-fill
1384
1484
  * ring they paint for content inside the fill.
1385
1485
  */
1386
1486
  function holdFocusRingAccent(
1387
1487
  themes: Record<string, Record<string, string>>,
1488
+ hue: AccentHue,
1388
1489
  ): Record<string, Record<string, string>> {
1389
1490
  const out: Record<string, Record<string, string>> = { ...themes };
1390
1491
  for (const scheme of ["light", "dark"] as const) {
@@ -1400,7 +1501,7 @@ function holdFocusRingAccent(
1400
1501
  grounds.every((ground) => contrastRatio(lum, ground as number) >= minContrastRatio)
1401
1502
  );
1402
1503
  };
1403
- const rootRing = [base.accentColor, themes[`${scheme}_blue`]?.accentColor].find(holds);
1504
+ const rootRing = [base.accentColor, themes[`${scheme}_${hue}`]?.accentColor].find(holds);
1404
1505
  for (const [name, theme] of Object.entries(themes)) {
1405
1506
  if (name !== scheme && !name.startsWith(`${scheme}_`)) continue;
1406
1507
  if (theme.outlineColor === undefined) continue;
@@ -1437,19 +1538,26 @@ export const postPassThemeKeys = [
1437
1538
  "borderColorField",
1438
1539
  "borderColorFieldHover",
1439
1540
  "borderColorHairline",
1541
+ "errorFill",
1440
1542
  "identityInk",
1441
1543
  "selectedBackground",
1442
1544
  "selectedColor",
1545
+ "successFill",
1443
1546
  "switchTrackOff",
1444
1547
  "switchTrackOffBorder",
1445
1548
  "switchTrackOffHover",
1446
1549
  "switchTrackOffPress",
1550
+ "warningFill",
1551
+ "warningInk",
1552
+ "warningMark",
1553
+ "warningSoft",
1447
1554
  ] as const;
1448
1555
 
1449
1556
  export function createThemesBuilder(
1450
1557
  baseTheme: BaseThemeBuilderDefinition,
1451
1558
  accentTheme: ThemeBuilderDefinition,
1452
1559
  options?: CreateThemesBuilderOptions,
1560
+ accentHue: AccentHue = "blue",
1453
1561
  ) {
1454
1562
  const getTheme = options?.getTheme ? sanitizeGetTheme(options.getTheme) : undefined;
1455
1563
  const base = {
@@ -1477,12 +1585,7 @@ export function createThemesBuilder(
1477
1585
  return [name, { palette: { light: Object.values(light), dark: Object.values(dark) } }];
1478
1586
  }),
1479
1587
  ),
1480
- warning: {
1481
- palette: {
1482
- dark: Object.values(Colors.yellowDark),
1483
- light: withIntentInkFloor(Object.values(Colors.yellow), intentInkFloor.warning),
1484
- },
1485
- },
1588
+ warning: { palette: warningPalette },
1486
1589
  error: {
1487
1590
  palette: {
1488
1591
  dark: Object.values(Colors.redDark),
@@ -1518,18 +1621,20 @@ export function createThemesBuilder(
1518
1621
  const themes = holdHouseIdentityInk(
1519
1622
  withIdentityInk(
1520
1623
  withAccentOnSurface(
1521
- holdFocusRingAccent(
1522
- holdControlEdges(
1523
- holdHouseAccent(
1524
- holdColorThemeAccent(
1525
- holdSwitchTrack(
1526
- holdSyntaxFloor(
1527
- holdNamedInkFloor(
1528
- holdSelectedState(
1529
- holdAccentFloor(
1530
- holdDarkEdges(
1531
- holdSelectionSurface(
1532
- neutralizeSemanticEntryText(neutralizeTintText(initialTheme)),
1624
+ holdWarningRoleKeys(
1625
+ holdFocusRingAccent(
1626
+ holdControlEdges(
1627
+ holdHouseAccent(
1628
+ holdColorThemeAccent(
1629
+ holdSwitchTrack(
1630
+ holdSyntaxFloor(
1631
+ holdNamedInkFloor(
1632
+ holdSelectedState(
1633
+ holdAccentFloor(
1634
+ holdDarkEdges(
1635
+ holdSelectionSurface(
1636
+ neutralizeSemanticEntryText(neutralizeTintText(initialTheme)),
1637
+ ),
1533
1638
  ),
1534
1639
  ),
1535
1640
  ),
@@ -1537,12 +1642,15 @@ export function createThemesBuilder(
1537
1642
  ),
1538
1643
  ),
1539
1644
  ),
1645
+ accentHue,
1540
1646
  ),
1541
1647
  ),
1648
+ accentHue,
1542
1649
  ),
1543
1650
  ),
1544
1651
  ),
1545
1652
  ),
1653
+ accentHue,
1546
1654
  );
1547
1655
  return {
1548
1656
  themes() {
@@ -1,11 +1,13 @@
1
1
  import type { CreateThemesBuilderOptions, GetThemeProps } from "../createThemes";
2
2
  import {
3
+ apcaContrast,
3
4
  contrastRatio,
4
5
  isLightGround,
5
6
  minContrastRatio,
6
7
  normalizeToHex,
7
8
  relativeLuminance,
8
9
  } from "../colorRules";
10
+ import { tintThemeScheme } from "../tintHues";
9
11
 
10
12
  /**
11
13
  * DG-A11Y-01 / DF-03. The external focus ring must clear 3:1 against both page
@@ -112,21 +114,28 @@ export function pickSecondaryInk(
112
114
  ramp: Record<string, string> = theme,
113
115
  ): string {
114
116
  const fallback = ramp.color11 ?? ramp.color12 ?? "transparent";
117
+ const primary = normalizeToHex(theme.color ?? "");
115
118
  const tiers = [theme.background, theme.color1, theme.color2, theme.color3];
116
119
  // Dark cards and fields sit on `$color4` (FZ-8400).
117
120
  if (theme.background && !isLightGround(theme.background)) tiers.push(theme.color4);
118
121
  const surfaces = tiers.map((raw) => normalizeToHex(raw ?? ""));
119
122
  if (surfaces.some((hex) => !hex)) return fallback;
120
123
  const luminances = surfaces.map((hex) => relativeLuminance(hex!));
124
+ let best: string | undefined;
125
+ let bestMin = 0;
121
126
  for (const key of [8, 9, 10, 11]) {
122
127
  const raw = ramp[`color${key}`];
123
128
  const hex = raw ? normalizeToHex(raw) : null;
124
- if (!raw || !hex) continue;
129
+ if (!raw || !hex || hex === primary) continue;
125
130
  const luminance = relativeLuminance(hex);
126
131
  const minC = Math.min(...luminances.map((surface) => contrastRatio(luminance, surface)));
127
132
  if (minC >= secondaryInkContrast) return raw;
133
+ if (minC > bestMin) {
134
+ bestMin = minC;
135
+ best = raw;
136
+ }
128
137
  }
129
- return fallback;
138
+ return best ?? fallback;
130
139
  }
131
140
 
132
141
  function getBaseTheme(theme: Record<string, string>) {
@@ -190,6 +199,23 @@ function clampBgForReadableText(bgRaw: string, fgRaw: string): string {
190
199
  return `hsl(${h}, ${s}%, ${l}%)`;
191
200
  }
192
201
 
202
+ /**
203
+ * A solid takes its dark anchor when that ink reads better on step 9 than
204
+ * the pale one (higher APCA Lc) and clears WCAG AA and Lc 60 with the fill
205
+ * and both of its darkened states unchanged.
206
+ */
207
+ function darkInkFits(solid: string, pale: string, dark: string): boolean {
208
+ const darkLc = Math.abs(apcaContrast(dark, solid));
209
+ if (darkLc <= Math.abs(apcaContrast(pale, solid)) || darkLc < 60) return false;
210
+ const darkHex = normalizeToHex(dark);
211
+ if (!darkHex) return false;
212
+ const ink = relativeLuminance(darkHex);
213
+ return [0, 4, 8].every((points) => {
214
+ const fill = normalizeToHex(lowerLightness(solid, points));
215
+ return !!fill && contrastRatio(ink, relativeLuminance(fill)) >= 4.5;
216
+ });
217
+ }
218
+
193
219
  export const defaultBuilderOptions: CreateThemesBuilderOptions = {
194
220
  getTheme: ({ name, theme, palette }: GetThemeProps): Record<string, string> => {
195
221
  // Surface templates carry their own borders and states, but no colorN ramp.
@@ -202,16 +228,20 @@ export const defaultBuilderOptions: CreateThemesBuilderOptions = {
202
228
 
203
229
  // Solid semantic-intent Buttons pair Radix 9 with the hue's pale anchor
204
230
  // at a 4.5:1 floor. Hover and press darken that fill in both schemes so
205
- // inherited labels and icons keep the same readable foreground.
231
+ // inherited labels and icons keep the same readable foreground. A bright
232
+ // step 9 (amber, LC-288) takes the hue's dark anchor instead, as Radix
233
+ // does: whitening it would mean darkening the fill to brown.
206
234
  const parts = name.split("_");
207
235
  if (parts[parts.length - 1] === "Button" && solidIntentParents.has(parts[parts.length - 2])) {
208
236
  const firstHex = normalizeToHex(step(0));
209
237
  const lastHex = normalizeToHex(step(11));
210
- const fg =
211
- firstHex && lastHex && relativeLuminance(lastHex) > relativeLuminance(firstHex)
212
- ? step(11)
213
- : step(0);
214
- const bg = clampBgForReadableText(step(8), fg);
238
+ const lastIsPale =
239
+ firstHex && lastHex && relativeLuminance(lastHex) > relativeLuminance(firstHex);
240
+ const pale = lastIsPale ? step(11) : step(0);
241
+ const dark = lastIsPale ? step(0) : step(11);
242
+ const darkFits = darkInkFits(step(8), pale, dark);
243
+ const fg = darkFits ? dark : pale;
244
+ const bg = darkFits ? step(8) : clampBgForReadableText(step(8), fg);
215
245
  const hover = lowerLightness(bg, 4);
216
246
  const press = lowerLightness(bg, 8);
217
247
  return {
@@ -235,6 +265,8 @@ export const defaultBuilderOptions: CreateThemesBuilderOptions = {
235
265
  outlineColor,
236
266
  };
237
267
  }
238
- return getBaseTheme(theme);
268
+ const baseTheme = getBaseTheme(theme);
269
+ if (!tintThemeScheme(name)) return baseTheme;
270
+ return Object.fromEntries(Object.entries(baseTheme).filter(([key]) => key !== "textMuted"));
239
271
  },
240
272
  };
@@ -79,3 +79,74 @@ describe("LC-152 secondary ink", () => {
79
79
  expect(tints).toBeGreaterThan(0);
80
80
  });
81
81
  });
82
+
83
+ describe("LC-152 secondary ink when no ramp step clears 7:1 (FZ-11178)", () => {
84
+ // Drover's dark purple: page #19121c, card #3d224e, and a neutral ramp whose
85
+ // $color11 is already the primary ink, so $color8-$color10 all miss 7:1.
86
+ const darkPurple: Record<string, string> = {
87
+ background: "#19121c",
88
+ color: "#ffffff",
89
+ color1: "#19121c",
90
+ color2: "#19121c",
91
+ color3: "#19121c",
92
+ color4: "#3d224e",
93
+ color8: "#8a8a8a",
94
+ color9: "#959595",
95
+ color10: "#b4b4b4",
96
+ color11: "#ffffff",
97
+ color12: "#ffffff",
98
+ };
99
+ const lightPurple: Record<string, string> = {
100
+ background: "#ffffff",
101
+ color: "#111111",
102
+ color1: "#ffffff",
103
+ color2: "#fbf7fe",
104
+ color3: "#f2e1fc",
105
+ color4: "#ead5f9",
106
+ color8: "#9a9a9a",
107
+ color9: "#8a8a8a",
108
+ color10: "#7a7a7a",
109
+ color11: "#111111",
110
+ color12: "#111111",
111
+ };
112
+
113
+ for (const [scheme, theme] of [
114
+ ["dark", darkPurple],
115
+ ["light", lightPurple],
116
+ ] as const) {
117
+ it(`${scheme}: never returns the theme's primary ink`, () => {
118
+ const ink = pickSecondaryInk(theme);
119
+ expect(normalizeToHex(ink)).not.toBe(normalizeToHex(theme.color!));
120
+ expect(normalizeToHex(ink)).not.toBe(normalizeToHex(theme.color12!));
121
+ });
122
+
123
+ it(`${scheme}: falls back to the candidate with the most contrast it measured`, () => {
124
+ const ink = pickSecondaryInk(theme);
125
+ const candidates = ["color8", "color9", "color10"].map((key) => theme[key]!);
126
+ const best = Math.max(...candidates.map((candidate) => minContrast(theme, candidate)));
127
+ expect(minContrast(theme, ink)).toBe(best);
128
+ expect(best).toBeLessThan(secondaryInkContrast);
129
+ });
130
+
131
+ it(`${scheme}: a tint picking from this ramp keeps the fallback off the primary ink`, () => {
132
+ const tint = { ...theme, color: theme.color12! };
133
+ expect(normalizeToHex(pickSecondaryInk(tint, theme))).not.toBe(
134
+ normalizeToHex(theme.color12!),
135
+ );
136
+ });
137
+ }
138
+
139
+ it("Drover's dark card takes #b4b4b4 at 6.59:1, not #ffffff", () => {
140
+ const ink = pickSecondaryInk(darkPurple);
141
+ expect(ink).toBe("#b4b4b4");
142
+ const onCard = contrastRatio(luminance(ink), luminance("#3d224e"));
143
+ expect(onCard).toBeCloseTo(6.59, 2);
144
+ expect(minContrast(darkPurple, ink)).toBeCloseTo(6.59, 2);
145
+ });
146
+
147
+ it("light takes $color10 #7a7a7a at the best ratio it measured on its own surfaces", () => {
148
+ const ink = pickSecondaryInk(lightPurple);
149
+ expect(ink).toBe("#7a7a7a");
150
+ expect(minContrast(lightPurple, ink)).toBeCloseTo(3.46, 2);
151
+ });
152
+ });
@@ -1,3 +1,4 @@
1
+ export * from "./accentHue";
1
2
  export * from "./activateThemeConfig";
2
3
  export * from "./animations/index";
3
4
  export * from "./chartPalette";
@@ -24,13 +24,18 @@ const lightness = (raw: string) => {
24
24
  return ((Math.max(...channels) + Math.min(...channels)) / (2 * 255)) * 100;
25
25
  };
26
26
 
27
- describe("FZ-7158 WP-b5: semantic Button fills hold their pale ink", () => {
27
+ describe("FZ-7158 WP-b5: semantic Button fills hold their label ink", () => {
28
28
  for (const scheme of ["light", "dark"] as const) {
29
29
  for (const intent of ["error", "warning", "success"] as const) {
30
30
  it(`${scheme}_${intent}_Button darkens from its resting fill in both interaction states`, () => {
31
31
  const theme = themes[`${scheme}_${intent}_Button`];
32
- expect(lightness(theme.background)).toBeLessThan(60);
33
- expect(luminance(theme.color)).toBeGreaterThan(0.5);
32
+ if (intent === "warning") {
33
+ // LC-288: amber step 9 is bright, so it keeps its fill under the dark anchor.
34
+ expect(luminance(theme.color)).toBeLessThan(luminance(theme.background));
35
+ } else {
36
+ expect(lightness(theme.background)).toBeLessThan(60);
37
+ expect(luminance(theme.color)).toBeGreaterThan(0.5);
38
+ }
34
39
  for (const fill of [theme.background, theme.backgroundHover, theme.backgroundPress]) {
35
40
  expect(ratio(theme.color, fill)).toBeGreaterThanOrEqual(4.5);
36
41
  }