@multiplatform.one/theme 9.2.0 → 9.4.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 (74) hide show
  1. package/dist/cjs/index.gnome.cjs +4 -0
  2. package/dist/cjs/index.gnome.native.js +4 -0
  3. package/dist/cjs/index.gnome.native.js.map +1 -1
  4. package/dist/cjs/menuRow.cjs +4 -0
  5. package/dist/cjs/menuRow.native.js +4 -0
  6. package/dist/cjs/menuRow.native.js.map +1 -1
  7. package/dist/cjs/theme/createThemes.cjs +77 -10
  8. package/dist/cjs/theme/createThemes.native.js +123 -11
  9. package/dist/cjs/theme/createThemes.native.js.map +1 -1
  10. package/dist/cjs/theme/defaults/base.cjs +8 -0
  11. package/dist/cjs/theme/defaults/base.native.js +8 -0
  12. package/dist/cjs/theme/defaults/base.native.js.map +1 -1
  13. package/dist/cjs/theme/motion.cjs +12 -3
  14. package/dist/cjs/theme/motion.native.js +12 -3
  15. package/dist/cjs/theme/motion.native.js.map +1 -1
  16. package/dist/cjs/theme/overlaySurfaces.cjs +10 -5
  17. package/dist/cjs/theme/overlaySurfaces.native.js +10 -5
  18. package/dist/cjs/theme/overlaySurfaces.native.js.map +1 -1
  19. package/dist/cjs/theme/v3TokenRoles.cjs +2 -2
  20. package/dist/cjs/theme/v3TokenRoles.native.js +2 -2
  21. package/dist/cjs/theme/v3TokenRoles.native.js.map +1 -1
  22. package/dist/esm/index.gnome.mjs +4 -4
  23. package/dist/esm/index.gnome.mjs.map +1 -1
  24. package/dist/esm/index.gnome.native.js +4 -4
  25. package/dist/esm/index.gnome.native.js.map +1 -1
  26. package/dist/esm/menuRow.mjs +4 -1
  27. package/dist/esm/menuRow.mjs.map +1 -1
  28. package/dist/esm/menuRow.native.js +4 -1
  29. package/dist/esm/menuRow.native.js.map +1 -1
  30. package/dist/esm/theme/createThemes.mjs +77 -10
  31. package/dist/esm/theme/createThemes.mjs.map +1 -1
  32. package/dist/esm/theme/createThemes.native.js +123 -11
  33. package/dist/esm/theme/createThemes.native.js.map +1 -1
  34. package/dist/esm/theme/defaults/base.mjs +8 -0
  35. package/dist/esm/theme/defaults/base.mjs.map +1 -1
  36. package/dist/esm/theme/defaults/base.native.js +8 -0
  37. package/dist/esm/theme/defaults/base.native.js.map +1 -1
  38. package/dist/esm/theme/motion.mjs +11 -3
  39. package/dist/esm/theme/motion.mjs.map +1 -1
  40. package/dist/esm/theme/motion.native.js +11 -3
  41. package/dist/esm/theme/motion.native.js.map +1 -1
  42. package/dist/esm/theme/overlaySurfaces.mjs +9 -6
  43. package/dist/esm/theme/overlaySurfaces.mjs.map +1 -1
  44. package/dist/esm/theme/overlaySurfaces.native.js +9 -6
  45. package/dist/esm/theme/overlaySurfaces.native.js.map +1 -1
  46. package/dist/esm/theme/v3TokenRoles.mjs +2 -2
  47. package/dist/esm/theme/v3TokenRoles.native.js +2 -2
  48. package/package.json +5 -5
  49. package/src/index.gnome.ts +4 -0
  50. package/src/menuRow.palette.spec.ts +26 -1
  51. package/src/menuRow.spec.ts +17 -1
  52. package/src/menuRow.ts +12 -0
  53. package/src/theme/createThemes.ts +150 -29
  54. package/src/theme/defaults/base.ts +2 -0
  55. package/src/theme/motion.spec.ts +18 -2
  56. package/src/theme/motion.ts +11 -2
  57. package/src/theme/overlaySurfaces.focus.spec.tsx +18 -14
  58. package/src/theme/overlaySurfaces.tsx +11 -11
  59. package/src/theme/resolveKnobs.spec.ts +1 -1
  60. package/src/theme/scrimTokens.spec.ts +109 -0
  61. package/src/theme/severityChannel.spec.ts +21 -0
  62. package/src/theme/v3TokenRoles.ts +2 -2
  63. package/types/index.gnome.d.ts +3 -3
  64. package/types/index.gnome.d.ts.map +1 -1
  65. package/types/menuRow.d.ts +9 -0
  66. package/types/menuRow.d.ts.map +1 -1
  67. package/types/theme/createThemes.d.ts +7 -1
  68. package/types/theme/createThemes.d.ts.map +1 -1
  69. package/types/theme/defaults/base.d.ts.map +1 -1
  70. package/types/theme/motion.d.ts +1 -0
  71. package/types/theme/motion.d.ts.map +1 -1
  72. package/types/theme/overlaySurfaces.d.ts +4 -7
  73. package/types/theme/overlaySurfaces.d.ts.map +1 -1
  74. package/types/theme/v3TokenRoles.d.ts +2 -2
@@ -22,6 +22,7 @@ import {
22
22
  systemFillHex,
23
23
  systemFillLuminance,
24
24
  } from "./colorRules";
25
+ import { defaultBaseTheme } from "./defaults/base";
25
26
  import { darkHairlineContrast, pickSecondaryInk } from "./defaults/builderOptions";
26
27
  import { themeRampHues } from "./ramps";
27
28
  import { pageSurfaces, pickIdentityInk, withAccentOnSurface, withIdentityInk } from "./accentInk";
@@ -59,6 +60,66 @@ function withIntentInkFloor(palette: string[], ink: string): string[] {
59
60
  return stepped;
60
61
  }
61
62
 
63
+ /** The warning scope's ramps (LC-288): amber, with light step 11 held at the ink floor. */
64
+ const warningPalette = {
65
+ dark: Object.values(Colors.amberDark),
66
+ light: withIntentInkFloor(Object.values(Colors.amber), intentInkFloor.warning),
67
+ };
68
+
69
+ /**
70
+ * LC-288: a status mark, wash or ink outside a `<Theme name="warning">`
71
+ * (a StatusDot, a log level, an Avatar pip, the console's `$warning`) reads
72
+ * the warning scope through these root keys, never a `$yellow` ramp token,
73
+ * which stays a data colour. They copy the built scope's steps 3, 9 and 11.
74
+ *
75
+ * `warningFill`, `errorFill` and `successFill` are a bar on a track (a
76
+ * Meter's zone). Each is the first of the severity's steps 9 to 11 that
77
+ * clears WCAG 1.4.11's 3:1 against the `$color4` track of the scheme root
78
+ * and every hue theme in it (the inverted accent scope is no track). Light
79
+ * amber 9 and 10 sit near 1.2:1 on a light track, so light warning lands on
80
+ * step 11.
81
+ */
82
+ const severityFillContrast = 3;
83
+
84
+ function pickSeverityFill(
85
+ themes: Record<string, Record<string, unknown>>,
86
+ scheme: "light" | "dark",
87
+ severity: "warning" | "error" | "success",
88
+ ): unknown {
89
+ const scope = themes[`${scheme}_${severity}`];
90
+ if (!scope) return undefined;
91
+ const tracks = Object.keys(themes)
92
+ .filter((name) => new RegExp(`^${scheme}(_[a-z]+)?$`).test(name))
93
+ .filter((name) => !/_(warning|error|success|accent)$/.test(name))
94
+ .map((name) => luminanceOf(themes[name]?.color4 as string | undefined))
95
+ .filter((value): value is number => value != null);
96
+ for (const step of [9, 10, 11]) {
97
+ const fill = luminanceOf(scope[`color${step}`] as string | undefined);
98
+ if (fill == null) continue;
99
+ if (tracks.every((track) => contrastRatio(fill, track) >= severityFillContrast)) {
100
+ return scope[`color${step}`];
101
+ }
102
+ }
103
+ return scope.color11;
104
+ }
105
+
106
+ function holdWarningRoleKeys<T extends Record<string, Record<string, unknown>>>(themes: T): T {
107
+ for (const scheme of ["light", "dark"] as const) {
108
+ const root = themes[scheme];
109
+ const warning = themes[`${scheme}_warning`];
110
+ if (!root || !warning) continue;
111
+ Object.assign(root, {
112
+ warningSoft: warning.color3,
113
+ warningMark: warning.color9,
114
+ warningInk: warning.color11,
115
+ warningFill: pickSeverityFill(themes, scheme, "warning"),
116
+ errorFill: pickSeverityFill(themes, scheme, "error"),
117
+ successFill: pickSeverityFill(themes, scheme, "success"),
118
+ });
119
+ }
120
+ return themes;
121
+ }
122
+
62
123
  /**
63
124
  * LC-151 SURFACE-LADDER. Cards, list items and fields sit on the grey page as
64
125
  * the white `$color1` step in light, the inset-grouped ladder. v5's surface1
@@ -173,6 +234,11 @@ export interface Shadows {
173
234
  shadow6: string;
174
235
  }
175
236
 
237
+ export interface ScrimAlphas {
238
+ dialog: number;
239
+ sheet: number;
240
+ }
241
+
176
242
  export interface ThemeBuilderDefinition<
177
243
  DarkPalette extends string[] = string[],
178
244
  LightPalette extends string[] = string[],
@@ -189,6 +255,8 @@ export interface BaseThemeBuilderDefinition<
189
255
  > extends ThemeBuilderDefinition<DarkPalette, LightPalette> {
190
256
  darkShadows?: DarkShadows;
191
257
  lightShadows?: LightShadows;
258
+ darkScrims?: ScrimAlphas;
259
+ lightScrims?: ScrimAlphas;
192
260
  }
193
261
 
194
262
  export interface GetThemeProps {
@@ -1466,6 +1534,40 @@ function isChromatic(color: string | undefined): boolean {
1466
1534
  return Math.max(...channels) - Math.min(...channels) >= 24;
1467
1535
  }
1468
1536
 
1537
+ function withAlpha(color: string, alpha: number): string | undefined {
1538
+ const hsla = color.match(/^hsla?\(([^,]+),\s*([^,]+),\s*([^,)]+)/);
1539
+ if (hsla) return `hsla(${hsla[1].trim()}, ${hsla[2].trim()}, ${hsla[3].trim()}, ${alpha})`;
1540
+ const hex = normalizeToHex(color);
1541
+ if (!hex) return undefined;
1542
+ const [r, g, b] = [1, 3, 5].map((index) => Number.parseInt(hex.slice(index, index + 2), 16));
1543
+ return `rgba(${r}, ${g}, ${b}, ${alpha})`;
1544
+ }
1545
+
1546
+ function holdScrims(
1547
+ themes: Record<string, Record<string, string>>,
1548
+ alphas: Record<"light" | "dark", ScrimAlphas>,
1549
+ ): Record<string, Record<string, string>> {
1550
+ const out: Record<string, Record<string, string>> = { ...themes };
1551
+ for (const [name, theme] of Object.entries(themes)) {
1552
+ const [scheme, hue, ...rest] = name.split("_");
1553
+ if (scheme !== "light" && scheme !== "dark") continue;
1554
+ if (
1555
+ rest.length > 0 ||
1556
+ (hue !== undefined && !(childrenHues as readonly string[]).includes(hue))
1557
+ )
1558
+ continue;
1559
+ const scrimDialog = theme.background
1560
+ ? withAlpha(theme.background, alphas[scheme].dialog)
1561
+ : undefined;
1562
+ out[name] = {
1563
+ ...theme,
1564
+ ...(scrimDialog ? { scrimDialog } : {}),
1565
+ scrimSheet: `rgba(0, 0, 0, ${alphas[scheme].sheet})`,
1566
+ };
1567
+ }
1568
+ return out;
1569
+ }
1570
+
1469
1571
  /**
1470
1572
  * Theme keys that only the post-passes in {@link createThemesBuilder} write
1471
1573
  * (the hold* passes, withAccentOnSurface, withIdentityInk). The `$token` lint
@@ -1478,13 +1580,21 @@ export const postPassThemeKeys = [
1478
1580
  "borderColorField",
1479
1581
  "borderColorFieldHover",
1480
1582
  "borderColorHairline",
1583
+ "errorFill",
1481
1584
  "identityInk",
1585
+ "scrimDialog",
1586
+ "scrimSheet",
1482
1587
  "selectedBackground",
1483
1588
  "selectedColor",
1589
+ "successFill",
1484
1590
  "switchTrackOff",
1485
1591
  "switchTrackOffBorder",
1486
1592
  "switchTrackOffHover",
1487
1593
  "switchTrackOffPress",
1594
+ "warningFill",
1595
+ "warningInk",
1596
+ "warningMark",
1597
+ "warningSoft",
1488
1598
  ] as const;
1489
1599
 
1490
1600
  export function createThemesBuilder(
@@ -1519,12 +1629,7 @@ export function createThemesBuilder(
1519
1629
  return [name, { palette: { light: Object.values(light), dark: Object.values(dark) } }];
1520
1630
  }),
1521
1631
  ),
1522
- warning: {
1523
- palette: {
1524
- dark: Object.values(Colors.amberDark),
1525
- light: withIntentInkFloor(Object.values(Colors.amber), intentInkFloor.warning),
1526
- },
1527
- },
1632
+ warning: { palette: warningPalette },
1528
1633
  error: {
1529
1634
  palette: {
1530
1635
  dark: Object.values(Colors.redDark),
@@ -1557,37 +1662,46 @@ export function createThemesBuilder(
1557
1662
  const initialTheme = tamaguiCreateThemes(
1558
1663
  createThemesProps as Parameters<typeof tamaguiCreateThemes>[0],
1559
1664
  );
1560
- const themes = holdHouseIdentityInk(
1561
- withIdentityInk(
1562
- withAccentOnSurface(
1563
- holdFocusRingAccent(
1564
- holdControlEdges(
1565
- holdHouseAccent(
1566
- holdColorThemeAccent(
1567
- holdSwitchTrack(
1568
- holdSyntaxFloor(
1569
- holdNamedInkFloor(
1570
- holdSelectedState(
1571
- holdAccentFloor(
1572
- holdDarkEdges(
1573
- holdSelectionSurface(
1574
- neutralizeSemanticEntryText(neutralizeTintText(initialTheme)),
1665
+ const scrimAlphas = {
1666
+ light: baseTheme.lightScrims ?? (defaultBaseTheme.lightScrims as ScrimAlphas),
1667
+ dark: baseTheme.darkScrims ?? (defaultBaseTheme.darkScrims as ScrimAlphas),
1668
+ };
1669
+ const themes = holdScrims(
1670
+ holdHouseIdentityInk(
1671
+ withIdentityInk(
1672
+ withAccentOnSurface(
1673
+ holdWarningRoleKeys(
1674
+ holdFocusRingAccent(
1675
+ holdControlEdges(
1676
+ holdHouseAccent(
1677
+ holdColorThemeAccent(
1678
+ holdSwitchTrack(
1679
+ holdSyntaxFloor(
1680
+ holdNamedInkFloor(
1681
+ holdSelectedState(
1682
+ holdAccentFloor(
1683
+ holdDarkEdges(
1684
+ holdSelectionSurface(
1685
+ neutralizeSemanticEntryText(neutralizeTintText(initialTheme)),
1686
+ ),
1687
+ ),
1575
1688
  ),
1576
1689
  ),
1577
1690
  ),
1578
1691
  ),
1579
1692
  ),
1580
1693
  ),
1694
+ accentHue,
1581
1695
  ),
1582
1696
  ),
1583
1697
  accentHue,
1584
1698
  ),
1585
1699
  ),
1586
- accentHue,
1587
1700
  ),
1588
1701
  ),
1702
+ accentHue,
1589
1703
  ),
1590
- accentHue,
1704
+ scrimAlphas,
1591
1705
  );
1592
1706
  return {
1593
1707
  themes() {
@@ -1613,12 +1727,19 @@ export function createThemesBuilder(
1613
1727
  const createdTheme = tamaguiCreateThemes(
1614
1728
  addThemeProps as Parameters<typeof tamaguiCreateThemes>[0],
1615
1729
  );
1616
- return withIdentityInk(
1617
- withAccentOnSurface({
1618
- [`dark_${name}`]: createdTheme.dark_accent,
1619
- [`light_${name}`]: createdTheme.light_accent,
1620
- } as Record<string, Record<string, string>>),
1621
- ) as Record<`dark_${K}` | `light_${K}`, typeof createdTheme.dark_accent>;
1730
+ const held = holdScrims(
1731
+ withIdentityInk(
1732
+ withAccentOnSurface({
1733
+ dark: createdTheme.dark_accent,
1734
+ light: createdTheme.light_accent,
1735
+ } as Record<string, Record<string, string>>),
1736
+ ),
1737
+ scrimAlphas,
1738
+ );
1739
+ return {
1740
+ [`dark_${name}`]: held.dark,
1741
+ [`light_${name}`]: held.light,
1742
+ } as Record<`dark_${K}` | `light_${K}`, typeof createdTheme.dark_accent>;
1622
1743
  },
1623
1744
  };
1624
1745
  }
@@ -21,4 +21,6 @@ export const defaultBaseTheme: BaseThemeBuilderDefinition = {
21
21
  shadow5: "rgba(0,0,0,0.65)",
22
22
  shadow6: "rgba(0,0,0,0.8)",
23
23
  },
24
+ lightScrims: { dialog: 0.5, sheet: 0.22 },
25
+ darkScrims: { dialog: 0.58, sheet: 0.45 },
24
26
  };
@@ -13,6 +13,7 @@ import {
13
13
  motionSettleMs,
14
14
  motionHideDelayMs,
15
15
  motionRoleProperties,
16
+ scrimFor,
16
17
  } from "./motion";
17
18
 
18
19
  describe("motion roles", () => {
@@ -24,7 +25,7 @@ describe("motion roles", () => {
24
25
  ).toEqual({
25
26
  control: "quick",
26
27
  overlay: "quicker",
27
- scrim: "slow",
28
+ scrim: "medium",
28
29
  reveal: "medium",
29
30
  slide: "medium",
30
31
  });
@@ -44,7 +45,6 @@ describe("motion roles", () => {
44
45
  expect(roles.control.transition).toBe(stop);
45
46
  for (const [name, factor] of [
46
47
  ["overlay", 0.8],
47
- ["scrim", 3],
48
48
  ["reveal", 2],
49
49
  ["slide", 2],
50
50
  ] as const) {
@@ -60,6 +60,22 @@ describe("motion roles", () => {
60
60
  }
61
61
  expect(motionFor("quickestLessBouncy").reveal.transition).toBe("quicker");
62
62
  });
63
+ it("fades a scrim on its own surface's enter and exit, never a fixed duration (Axiom 4)", () => {
64
+ for (const stop of [...motionStops, "none"] as const) {
65
+ const roles = motionFor(stop);
66
+ expect([roles.scrim.transition, roles.scrim.exit]).toEqual([
67
+ roles.slide.transition,
68
+ roles.slide.exit,
69
+ ]);
70
+ expect(roles.scrim.animateOnly).toEqual(["opacity"]);
71
+ const dialog = scrimFor(roles.overlay);
72
+ expect([dialog.transition, dialog.exit]).toEqual([
73
+ roles.overlay.transition,
74
+ roles.overlay.exit,
75
+ ]);
76
+ expect(dialog.animateOnly).toEqual(["opacity"]);
77
+ }
78
+ });
63
79
  it("limits properties to each role's anatomy", () => {
64
80
  expect(motionRoleProperties).toEqual({
65
81
  control: ["backgroundColor", "borderColor", "color", "opacity", "transform"],
@@ -40,6 +40,14 @@ function exitStop(enter: MotionStop): MotionStop {
40
40
  return shorter.length === 0 ? enter : nearestStop(enterMs * motionExitFactor, shorter);
41
41
  }
42
42
 
43
+ export function scrimFor(surface: MotionRole): MotionRole {
44
+ return {
45
+ transition: surface.transition,
46
+ exit: surface.exit,
47
+ animateOnly: motionRoleProperties.scrim,
48
+ };
49
+ }
50
+
43
51
  export function motionFor(stop: Animation): Record<MotionRoleName, MotionRole> {
44
52
  const transition = stop === "none" ? undefined : stop;
45
53
  const duration = motionDurationMs(transition);
@@ -56,11 +64,12 @@ export function motionFor(stop: Animation): Record<MotionRoleName, MotionRole> {
56
64
  animateOnly: motionRoleProperties[name],
57
65
  };
58
66
  };
67
+ const slide = role("slide", 2);
59
68
  return {
60
69
  control: role("control", 1),
61
70
  overlay: role("overlay", 0.8),
62
- scrim: role("scrim", 3),
71
+ scrim: scrimFor(slide),
63
72
  reveal: role("reveal", 2),
64
- slide: role("slide", 2),
73
+ slide,
65
74
  };
66
75
  }
@@ -26,17 +26,21 @@ vi.mock("tamagui", async () => {
26
26
  };
27
27
  });
28
28
  vi.mock("./Surface", () => ({ Surface: ({ children }: { children?: unknown }) => children }));
29
- vi.mock("./useResolvedKnobs", () => ({
30
- useResolvedKnobs: () => ({
31
- knobProps: {
32
- elevatedSurface: {},
33
- containerRadius: {},
34
- panelPadding: {},
35
- gap: {},
36
- motion: { overlay: undefined, scrim: undefined },
37
- },
38
- }),
39
- }));
29
+ vi.mock("./useResolvedKnobs", async () => {
30
+ const { motionFor } = await import("./motion");
31
+ const motion = motionFor("none");
32
+ return {
33
+ useResolvedKnobs: () => ({
34
+ knobProps: {
35
+ elevatedSurface: {},
36
+ containerRadius: {},
37
+ panelPadding: {},
38
+ gap: {},
39
+ motion,
40
+ },
41
+ }),
42
+ };
43
+ });
40
44
  vi.mock("./resolveKnobs", () => ({ panelPaddingPx: () => 16 }));
41
45
 
42
46
  const {
@@ -46,7 +50,7 @@ const {
46
50
  DialogOverlay,
47
51
  DialogShowFocus,
48
52
  PopoverContent,
49
- overlayScrim,
53
+ dialogScrim,
50
54
  useIsInDialogRegion,
51
55
  } = await import("./overlaySurfaces");
52
56
 
@@ -244,8 +248,8 @@ describe("dialog frames", () => {
244
248
  <AlertDialogOverlay />
245
249
  </>,
246
250
  );
247
- expect(seen.props["Dialog.Overlay"].backgroundColor).toBe(overlayScrim);
248
- expect(seen.props["AlertDialog.Overlay"].backgroundColor).toBe(overlayScrim);
251
+ expect(seen.props["Dialog.Overlay"].backgroundColor).toBe(dialogScrim);
252
+ expect(seen.props["AlertDialog.Overlay"].backgroundColor).toBe(dialogScrim);
249
253
  expect(seen.props["Dialog.Overlay"].enterStyle).toEqual({ opacity: 0 });
250
254
  });
251
255
  });
@@ -1,4 +1,5 @@
1
1
  import { focusOnOpen, wasKeyboardFocus } from "../keyboardFocusRing";
2
+ import { scrimFor } from "./motion";
2
3
  import { transitionProps } from "./transitionProps";
3
4
  import { Surface } from "./Surface";
4
5
  import { useResolvedKnobs } from "./useResolvedKnobs";
@@ -20,13 +21,12 @@ import {
20
21
  type ViewProps,
21
22
  } from "tamagui";
22
23
 
23
- /**
24
- * The scrim under every modal surface: dialogs, alerts and sheets (FZ-8557).
25
- * `$shadow4` is the SHC console's `backgroundScrim` weight (light 0.26, dark
26
- * 0.58 there; 0.22 and 0.45 here), the dim an iOS sheet lays over its page.
27
- * `$shadow6` read as a heavy grey wash in light.
28
- */
29
- export const overlayScrim = "$shadow4" as const;
24
+ export const dialogScrim = "$scrimDialog" as const;
25
+
26
+ export const sheetScrim = "$scrimSheet" as const;
27
+
28
+ /** @deprecated Use `dialogScrim` under a dialog or `sheetScrim` under a sheet. Removed in 8.0.0. */
29
+ export const overlayScrim = dialogScrim;
30
30
 
31
31
  /**
32
32
  * A floating panel's grabber (HIG, FZ-8557, FZ-8648): a 36×5 capsule 5pt inside the
@@ -388,8 +388,8 @@ export const DialogOverlay = forwardRef<
388
388
  return (
389
389
  <Dialog.Overlay
390
390
  ref={ref}
391
- backgroundColor={overlayScrim}
392
- {...transitionProps(knobProps.motion.scrim)}
391
+ backgroundColor={dialogScrim}
392
+ {...transitionProps(scrimFor(knobProps.motion.overlay))}
393
393
  enterStyle={scrimFade}
394
394
  exitStyle={scrimFade}
395
395
  {...props}
@@ -454,8 +454,8 @@ export const AlertDialogOverlay = forwardRef<
454
454
  return (
455
455
  <AlertDialog.Overlay
456
456
  ref={ref}
457
- backgroundColor={overlayScrim}
458
- {...transitionProps(knobProps.motion.scrim)}
457
+ backgroundColor={dialogScrim}
458
+ {...transitionProps(scrimFor(knobProps.motion.overlay))}
459
459
  enterStyle={scrimFade}
460
460
  exitStyle={scrimFade}
461
461
  {...props}
@@ -1368,7 +1368,7 @@ describe("resolveKnobs", () => {
1368
1368
  const { knobProps } = resolveKnobs(knobsWith({ animation: "quick" }));
1369
1369
  expect(knobProps.motion.control.transition).toBe("quick");
1370
1370
  expect(knobProps.motion.overlay.transition).toBe("quicker");
1371
- expect(knobProps.motion.scrim.transition).toBe("slow");
1371
+ expect(knobProps.motion.scrim.transition).toBe("medium");
1372
1372
  expect(knobProps.motion.reveal.transition).toBe("medium");
1373
1373
  expect(knobProps.motion.slide.transition).toBe("medium");
1374
1374
  for (const role of Object.values(
@@ -0,0 +1,109 @@
1
+ import { readFileSync, readdirSync, statSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { describe, expect, it } from "vitest";
4
+ import { createThemesBuilder } from "./createThemes";
5
+ import { defaultAccentTheme } from "./defaults/accent";
6
+ import { defaultBaseTheme } from "./defaults/base";
7
+ import { defaultBuilderOptions } from "./defaults/builderOptions";
8
+ import { dialogScrim, overlayScrim, sheetScrim } from "./overlaySurfaces";
9
+
10
+ const themes = createThemesBuilder(
11
+ defaultBaseTheme,
12
+ defaultAccentTheme,
13
+ defaultBuilderOptions,
14
+ ).themes() as Record<string, Record<string, string>>;
15
+
16
+ const scopes = ["", "_blue", "_green", "_orange", "_pink", "_purple", "_gray"];
17
+
18
+ function alphaOf(raw: string | undefined): number {
19
+ const match = raw?.match(/^(?:rgba|hsla)\((?:[^,]+,){3}\s*([\d.]+)\)$/);
20
+ if (!match) throw new Error(`not a translucent scrim: ${raw}`);
21
+ return Number(match[1]);
22
+ }
23
+
24
+ const opaque = (raw: string | undefined) => raw?.replace(/,\s*[\d.]+\)$/, "");
25
+
26
+ describe("Axiom 4: dialog and sheet scrims are two theme tokens", () => {
27
+ it("names the tokens for their role", () => {
28
+ expect(dialogScrim).toBe("$scrimDialog");
29
+ expect(sheetScrim).toBe("$scrimSheet");
30
+ });
31
+
32
+ it("keeps overlayScrim as a deprecated alias of dialogScrim until 8.0.0", () => {
33
+ expect(overlayScrim).toBe(dialogScrim);
34
+ expect(readFileSync(path.join(__dirname, "overlaySurfaces.tsx"), "utf8")).toMatch(
35
+ /@deprecated[^\n]*Removed in 8\.0\.0\. \*\/\nexport const overlayScrim = dialogScrim;/,
36
+ );
37
+ });
38
+
39
+ for (const scope of scopes) {
40
+ it(`light${scope} and dark${scope} resolve both scrims, each scheme on its own alpha`, () => {
41
+ const light = themes[`light${scope}`];
42
+ const dark = themes[`dark${scope}`];
43
+ expect(light && dark).toBeTruthy();
44
+ for (const token of ["scrimDialog", "scrimSheet"] as const) {
45
+ const lightAlpha = alphaOf(light[token]);
46
+ const darkAlpha = alphaOf(dark[token]);
47
+ expect(lightAlpha).toBeGreaterThan(0);
48
+ expect(lightAlpha).toBeLessThan(1);
49
+ expect(darkAlpha).toBeGreaterThan(lightAlpha);
50
+ }
51
+ expect(light.scrimDialog).not.toBe(light.scrimSheet);
52
+ expect(dark.scrimDialog).not.toBe(dark.scrimSheet);
53
+ });
54
+ }
55
+
56
+ it("washes a dialog's page toward that theme's own page and dims a sheet's toward black", () => {
57
+ for (const scheme of ["light", "dark"] as const) {
58
+ for (const scope of scopes) {
59
+ const theme = themes[`${scheme}${scope}`];
60
+ expect(opaque(theme.scrimDialog)).toBe(opaque(theme.background));
61
+ expect(opaque(theme.scrimSheet)).toBe("rgba(0, 0, 0");
62
+ expect(themes[`${scheme}${scope}_Button`]?.scrimDialog).toBeUndefined();
63
+ }
64
+ }
65
+ });
66
+ });
67
+
68
+ const publicRoot = path.resolve(__dirname, "../../..");
69
+
70
+ function sources(dir: string, out: string[] = []): string[] {
71
+ for (const name of readdirSync(dir)) {
72
+ if (name === "node_modules" || name === "dist" || name === "types") continue;
73
+ const file = path.join(dir, name);
74
+ if (statSync(file).isDirectory()) sources(file, out);
75
+ else if (/\.tsx$/.test(name) && !/\.(spec|test|stories)\.tsx$/.test(name)) out.push(file);
76
+ }
77
+ return out;
78
+ }
79
+
80
+ describe("Axiom 4: no scrim literal at a use site", () => {
81
+ const files = readdirSync(publicRoot)
82
+ .map((pkg) => path.join(publicRoot, pkg, "src"))
83
+ .filter((dir) => statSync(dir, { throwIfNoEntry: false })?.isDirectory())
84
+ .flatMap((dir) => sources(dir));
85
+
86
+ it("paints every overlay scrim from dialogScrim or sheetScrim, with no opacity of its own", () => {
87
+ const offenders: string[] = [];
88
+ for (const file of files) {
89
+ const source = readFileSync(file, "utf8");
90
+ for (const match of source.matchAll(
91
+ /<(?:Sheet\.Overlay|Dialog\.Overlay|AlertDialog\.Overlay|DialogOverlay|AlertDialogOverlay)\b([^>]*?)\/?>/gs,
92
+ )) {
93
+ const props = match[1];
94
+ const background = props.match(/backgroundColor=\{?"?([^\s}"]+)/)?.[1];
95
+ if (
96
+ /\bopacity=\{/.test(props) ||
97
+ (background && !/^(dialogScrim|sheetScrim)$/.test(background))
98
+ ) {
99
+ offenders.push(`${path.relative(publicRoot, file)}: ${match[0].replace(/\s+/g, " ")}`);
100
+ }
101
+ }
102
+ if (
103
+ /\boverlayScrim\b/.test(source.replace(/^export const overlayScrim = dialogScrim;$/m, ""))
104
+ )
105
+ offenders.push(`${path.relative(publicRoot, file)}: overlayScrim`);
106
+ }
107
+ expect(offenders).toEqual([]);
108
+ });
109
+ });
@@ -162,6 +162,27 @@ describe("LC-288 SEVERITY-CHANNEL", () => {
162
162
  expect(normalizeToHex(light.semantic.warning)).toBe(ink);
163
163
  });
164
164
 
165
+ for (const severity of severities) {
166
+ it(`draws a ${severity} bar at 3:1 or more on every preset's track (WCAG 1.4.11)`, () => {
167
+ const short: string[] = [];
168
+ for (const scheme of ["light", "dark"] as const) {
169
+ const steps = [9, 10, 11].map((step) =>
170
+ text(resolved[`${scheme}_${severity}`]?.[`color${step}`]),
171
+ );
172
+ for (const [preset, theme] of Object.entries({ ...presetThemes, root: "" })) {
173
+ const scope = resolved[theme ? `${scheme}_${theme}` : scheme] ?? {};
174
+ const track = normalizeToHex(text(scope.color4) as string) as string;
175
+ const raw = text(scope[`${severity}Fill`]);
176
+ expect(steps, `${scheme} ${severity}Fill is one of steps 9 to 11`).toContain(raw);
177
+ const fill = normalizeToHex(raw as string) as string;
178
+ const ratio = contrastRatio(relativeLuminance(fill), relativeLuminance(track));
179
+ if (ratio < 3) short.push(`${scheme} ${preset} ${ratio.toFixed(2)}`);
180
+ }
181
+ }
182
+ expect(short).toEqual([]);
183
+ });
184
+ }
185
+
165
186
  it("fills a warning Button with amber step 9 under its dark ink, never a darkened brown", () => {
166
187
  for (const scheme of ["light", "dark"] as const) {
167
188
  const button = resolved[`${scheme}_warning_Button`] ?? {};
@@ -23,8 +23,8 @@ export const v3TokenRoles = {
23
23
  grabColor: "color8",
24
24
  good: "green9",
25
25
  goodSoft: "green3",
26
- warning: "yellow9",
27
- warningSoft: "yellow3",
26
+ warning: "warningMark",
27
+ warningSoft: "warningSoft",
28
28
  critical: "red9",
29
29
  criticalSoft: "red3",
30
30
  info: "blue9",
@@ -22,7 +22,7 @@ export { clampSurfaceSize, compareSizeTokens, sizeTokenBelow, sizeTokenStep, siz
22
22
  export type { SurfaceIntent, SurfaceSize } from "./theme/Surface";
23
23
  export { controlTierDisabled, controlTierPaint, controlTierWash, controlTrackFill, isDarkThemeName, } from "./theme/controlTiers";
24
24
  export type { ControlTier, ControlTierPaint } from "./theme/controlTiers";
25
- export { AlertDialogContent, AlertDialogOverlay, DialogContent, DialogOverlay, DialogRegionContext, DialogSheetFaceProvider, DialogShowFocus, overlayScrim, PopoverContent, sheetGrabber, sheetGrabberClearance, sheetGrabberZone, sheetHandle, sheetHandleTone, sheetHandleWidthRatio, sheetHandleZone, SheetBodyProvider, useDialogRegionContext, useDialogSheetFace, useIsInDialogRegion, useIsInSheetBody, } from "./theme/overlaySurfaces";
25
+ export { AlertDialogContent, AlertDialogOverlay, DialogContent, dialogScrim, DialogOverlay, DialogRegionContext, DialogSheetFaceProvider, DialogShowFocus, overlayScrim, PopoverContent, sheetGrabber, sheetGrabberClearance, sheetGrabberZone, sheetScrim, sheetHandle, sheetHandleTone, sheetHandleWidthRatio, sheetHandleZone, SheetBodyProvider, useDialogRegionContext, useDialogSheetFace, useIsInDialogRegion, useIsInSheetBody, } from "./theme/overlaySurfaces";
26
26
  export type { DialogContentProps, DialogRegionContextValue } from "./theme/overlaySurfaces";
27
27
  export { boldPreset, consolePreset, defaultPreset, densePreset, heroPreset, roomyPreset, storefrontPreset, } from "./theme/presets";
28
28
  export { IntentContext, solidButtonIntents, solidPaletteThemes, useIntentContext, useResolvedKnobs, } from "./theme/useResolvedKnobs";
@@ -42,7 +42,7 @@ export { ensureHairlineFallback, hairline, hairlineBorderWidth, hairlineFallback
42
42
  export { compositeFocusRingCss, ensureCompositeFocusRing, ensureKeyboardModalityTracking, focusOnOpen, keyboardFocusRingProps, wasKeyboardFocus, } from "./keyboardFocusRing";
43
43
  export { CLOCK_TIME, formatAbsoluteDate, formatAbsoluteDateTime, formatCalendarDate, formatDayLong, formatDayOfMonth, formatMonthYear, formatRelativeTimestamp, formatTimeOfDay, getMonthNames, getWeekdayNames, ISO_DATE_ONLY, parseCalendarDate, } from "./dates";
44
44
  export type { AbsoluteDateFormatOptions, CalendarDateShape, DateInput, DayLongFormatOptions, MonthYearFormatOptions, TimeOfDayFormatOptions, WeekdayNamesOptions, } from "./dates";
45
- export { menuRowChecked, menuRowCheckGlyph, menuRowCheckInk, menuRowFrame, menuRowIconGlyph, resolveMenuRowCheckInk, useMenuRowCheckInk, } from "./menuRow";
45
+ export { menuRowActive, menuRowChecked, menuRowCheckGlyph, menuRowCheckInk, menuRowFrame, menuRowIconGlyph, resolveMenuRowCheckInk, useMenuRowCheckInk, } from "./menuRow";
46
46
  export type { MenuRowGlyph } from "./menuRow";
47
47
  export { currencyAffix, formatCurrency, formatNumber, formatPercent, resolveCurrencyCode, } from "./numbers";
48
48
  export type { CurrencyAffix, CurrencyFormatOptions, NumberFormatOptions, NumberInput, PercentFormatOptions, } from "./numbers";
@@ -58,7 +58,7 @@ export { accentIdentityCandidates, resolveChartPalette, useChartPalette, } from
58
58
  export type { ChartPalette, ResolveChartPaletteInput } from "./theme/chartPalette";
59
59
  export { animationConfig, animationDurations, animationNames, animations, animationConfig as cssAnimationConfig, motionStops, } from "./theme/animations/css";
60
60
  export type { AnimationName, MotionStop } from "./theme/animations/css";
61
- export { motionDurationMs, motionExitFactor, motionFor, motionHideDelayMs, motionRoleProperties, motionSeconds, motionSettleMs, } from "./theme/motion";
61
+ export { motionDurationMs, motionExitFactor, motionFor, motionHideDelayMs, motionRoleProperties, motionSeconds, motionSettleMs, scrimFor, } from "./theme/motion";
62
62
  export type { MotionRole, MotionRoleName } from "./theme/motion";
63
63
  export { resolveGlyphPaint, useGlyphColor } from "./theme/glyphPaint";
64
64
  export { GLYPH_CONTRAST_FLOOR, glyphTintFallback, GlyphTintFallbackProvider, platformSystemTint, resolveGlyphTint, useGlyphTintOnSurface, } from "./theme/glyphTint";