@reqvire-org/ads 0.3.46 → 0.3.47

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 (110) hide show
  1. package/README.md +21 -11
  2. package/dist/a11y.mjs +4 -2
  3. package/dist/assets.mjs +20 -15
  4. package/dist/atomic-composition.mjs +3 -2
  5. package/dist/brand-assets.mjs +48 -11
  6. package/dist/brands.mjs +82 -0
  7. package/dist/browser-audit/worker.mjs +45 -0
  8. package/dist/browser-audit.mjs +117 -0
  9. package/dist/capture/worker.mjs +1 -0
  10. package/dist/capture-store.mjs +2 -0
  11. package/dist/capture.mjs +7 -4
  12. package/dist/check.mjs +38 -8
  13. package/dist/cli.mjs +45 -10
  14. package/dist/color-values.mjs +325 -0
  15. package/dist/config.mjs +16 -2
  16. package/dist/control-padding.mjs +93 -0
  17. package/dist/design-values.mjs +3 -2
  18. package/dist/finding-rules.mjs +61 -0
  19. package/dist/foundation.mjs +17 -4
  20. package/dist/icons.mjs +107 -0
  21. package/dist/init.mjs +3 -0
  22. package/dist/mcp/apps.mjs +9 -6
  23. package/dist/mcp/drafts.mjs +3 -0
  24. package/dist/mcp/mutations.mjs +17 -1
  25. package/dist/mcp/preview-widget.bundle.js +36 -36
  26. package/dist/mcp/project-widget.bundle.js +12 -12
  27. package/dist/mcp/server.mjs +21 -9
  28. package/dist/mcp/widget.bundle.js +17 -17
  29. package/dist/palette-generated.mjs +180 -0
  30. package/dist/preview-resources.mjs +12 -3
  31. package/dist/render-color-probe.mjs +148 -0
  32. package/dist/runtime-contracts.mjs +14 -4
  33. package/dist/scenarios.mjs +1 -1
  34. package/dist/showcase/client.bundle.js +28 -28
  35. package/dist/showcase/icons.js +146 -0
  36. package/dist/showcase/index.html +2 -1
  37. package/dist/showcase/style.css +19 -2
  38. package/dist/skills/README.md +2 -1
  39. package/dist/skills/ads-break-ui/SKILL.md +6 -5
  40. package/dist/skills/ads-break-ui/references/atomic-styles.md +12 -12
  41. package/dist/skills/ads-break-ui/references/contracts.md +13 -10
  42. package/dist/skills/ads-break-ui/references/design-data.md +137 -29
  43. package/dist/skills/ads-break-ui/references/validation.md +8 -4
  44. package/dist/skills/ads-designer/SKILL.md +23 -16
  45. package/dist/skills/ads-designer/references/accessibility.md +39 -5
  46. package/dist/skills/ads-designer/references/atomic-styles.md +12 -12
  47. package/dist/skills/ads-designer/references/branding.md +37 -10
  48. package/dist/skills/ads-designer/references/cli.md +8 -2
  49. package/dist/skills/ads-designer/references/contracts.md +13 -10
  50. package/dist/skills/ads-designer/references/design-data.md +137 -29
  51. package/dist/skills/ads-designer/references/validation.md +8 -4
  52. package/dist/skills/ads-import/SKILL.md +9 -8
  53. package/dist/skills/ads-import/references/atomic-styles.md +12 -12
  54. package/dist/skills/ads-import/references/cli.md +8 -2
  55. package/dist/skills/ads-import/references/contracts.md +13 -10
  56. package/dist/skills/ads-import/references/design-data.md +137 -29
  57. package/dist/skills/ads-import/references/tokens.md +7 -3
  58. package/dist/skills/ads-import/references/validation.md +8 -4
  59. package/dist/skills/ads-motion/SKILL.md +6 -5
  60. package/dist/skills/ads-motion/references/atomic-styles.md +12 -12
  61. package/dist/skills/ads-motion/references/contracts.md +13 -10
  62. package/dist/skills/ads-motion/references/design-data.md +137 -29
  63. package/dist/skills/ads-motion/references/validation.md +8 -4
  64. package/dist/skills/ads-port/SKILL.md +6 -5
  65. package/dist/skills/ads-port/references/atomic-styles.md +12 -12
  66. package/dist/skills/ads-port/references/cli.md +8 -2
  67. package/dist/skills/ads-port/references/contracts.md +13 -10
  68. package/dist/skills/ads-port/references/design-data.md +137 -29
  69. package/dist/skills/ads-port/references/validation.md +8 -4
  70. package/dist/starters/preact/design-system/review/token-preview/TokenPreview.tsx +11 -2
  71. package/dist/starters/react/ADS.md +43 -10
  72. package/dist/starters/react/README.md +14 -9
  73. package/dist/starters/react/design-system/assets/brand/README.md +8 -3
  74. package/dist/starters/react/design-system/assets/glyphs/README.md +4 -1
  75. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.fixture.ts +6 -1
  76. package/dist/starters/react/design-system/components/Content/Icon/Icon.ads.scenario.tsx +3 -2
  77. package/dist/starters/react/design-system/components/Content/Icon/README.md +2 -1
  78. package/dist/starters/react/design-system/components/Content/Logo/Logo.tsx +3 -9
  79. package/dist/starters/react/design-system/components/Content/Logo/README.md +4 -2
  80. package/dist/starters/react/design-system/controllers/Palette/Palette.ts +164 -0
  81. package/dist/starters/react/design-system/index.ts +3 -0
  82. package/dist/starters/react/design-system/review/brand-preview/BrandPreview.tsx +2 -5
  83. package/dist/starters/react/design-system/review/token-preview/TokenPreview.tsx +11 -2
  84. package/dist/starters/react/design-system/styles.css +1 -0
  85. package/dist/starters/react/design-system/tokens/base.css +8 -5
  86. package/dist/starters/react/design-system/tokens/colors.css +167 -175
  87. package/dist/starters/react/design-system/tokens/elevation.css +14 -21
  88. package/dist/starters/react/design-system/tokens/themes.generated.css +142 -0
  89. package/dist/starters/react/design-system/tokens/themes.generated.ts +402 -0
  90. package/dist/style-boundaries.mjs +2 -1
  91. package/dist/themes-generated.mjs +150 -0
  92. package/dist/themes-watch.mjs +42 -0
  93. package/dist/themes.mjs +214 -63
  94. package/dist/token-export.mjs +22 -11
  95. package/dist/token-policy.mjs +2 -1
  96. package/dist/token-quality.mjs +28 -25
  97. package/dist/tokens.mjs +27 -32
  98. package/dist/validation.mjs +18 -1
  99. package/dist/verification/browser.mjs +14 -3
  100. package/docs/ADS.md +41 -27
  101. package/docs/ARCHITECTURE.md +49 -22
  102. package/docs/CACHING.md +2 -3
  103. package/docs/CHANGELOG.md +97 -13
  104. package/docs/CONTRACTS.md +13 -10
  105. package/docs/GUIDE.md +89 -21
  106. package/docs/MCP.md +35 -25
  107. package/docs/benchmarks/bun-previews.md +5 -5
  108. package/docs/benchmarks/{gidi-preview-memory.md → preview-memory.md} +14 -12
  109. package/docs/benchmarks/turbo-poc.md +24 -6
  110. package/package.json +2 -1
@@ -60,7 +60,16 @@ const sampleStyle = css`
60
60
  &[data-ads-property="font-size"] { font-size: var(--ux-token-preview-value); }
61
61
  &[data-ads-property="font-weight"] { font-weight: var(--ux-token-preview-value); font-size: calc(var(--text-base) * 2); line-height: 1; }
62
62
  &[data-ads-property="line-height"] { line-height: var(--ux-token-preview-value); }
63
- &[data-ads-property="column-count"] { column-count: var(--ux-token-preview-value); column-gap: var(--space-2); column-rule: var(--border-w) solid var(--border-strong); }
63
+ /* Column counts draw that many columns: stripes with a gap, filling the tile. */
64
+ &[data-ads-property="column-count"] {
65
+ column-count: var(--ux-token-preview-value);
66
+ height: calc(var(--space-8) * 3);
67
+ background: repeating-linear-gradient(
68
+ to right,
69
+ var(--accent) 0 calc((100% + var(--space-2)) / var(--ux-token-preview-value) - var(--space-2)),
70
+ transparent 0 calc((100% + var(--space-2)) / var(--ux-token-preview-value))
71
+ );
72
+ }
64
73
  &[data-ads-property="letter-spacing"] { letter-spacing: var(--ux-token-preview-value); font-size: calc(var(--text-base) * 1.5); }
65
74
  &[data-ads-property="height"] {
66
75
  height: var(--ux-token-preview-value);
@@ -109,7 +118,7 @@ function TokenTile({ sample, text }: { sample: TokenSample; text: string }) {
109
118
  return (
110
119
  <article className={cx("ux-token-preview__item", tile)}>
111
120
  <span ref={ref} className={cx("ux-token-preview__sample", sampleStyle)} data-ads-token={sample.token} data-ads-property={sample.property}>
112
- {["background-color", "width", "height", "border-radius", "box-shadow", "animation-duration", "animation-timing-function"].includes(sample.property) ? "" : text}
121
+ {["background-color", "width", "height", "border-radius", "box-shadow", "column-count", "animation-duration", "animation-timing-function"].includes(sample.property) ? "" : text}
113
122
  </span>
114
123
  <code className={cx("ux-token-preview__name", label)}>{sample.token}</code>
115
124
  <small className={label}>{value}</small>
@@ -24,8 +24,9 @@ The starter declares React in `ds.config.json`. Keep that choice, JSX, runtime
24
24
  dependencies and the preview mount adapter consistent. Init records a choice for
25
25
  an unconfigured project; it does not convert copied React source to Preact.
26
26
 
27
- The starter has one example of each layer (Button, Logo, TextField, SearchBar,
28
- SearchPage) and placeholder brand artwork. Rename, restyle or replace them; add only what the product needs.
27
+ The starter has examples of each layer (Button, IconButton, Icon, Logo, TextField and
28
+ Grid; the SearchBar pattern; the SearchPage composition), a shared `controllers/Palette`
29
+ and placeholder brand artwork. Rename, restyle or replace them; add only what the product needs.
29
30
  Keep the ADS in root `design-system/`, beside application `src/`.
30
31
  Keep public exports in `design-system/index.ts`; consumers use its `@ds` alias.
31
32
  `styles.css` is the foundation CSS entry and contains token imports only.
@@ -34,7 +35,7 @@ Keep public exports in `design-system/index.ts`; consumers use its `@ds` alias.
34
35
 
35
36
  Use semantic CSS tokens for visual values. Raw values belong in the token files.
36
37
  Projects sharing this ADS use the same token names, meanings, and value types;
37
- their concrete values and theme overrides can differ. Reuse existing local values
38
+ their concrete values and per-theme halves can differ. Reuse existing local values
38
39
  when importing components/patterns. Existing font, text, spacing and other roles
39
40
  take precedence over divergent upstream constants. Add genuinely missing shared
40
41
  decisions, and import source token values only when adopting that theme is requested.
@@ -48,7 +49,8 @@ variables. Every shared token needs a real sample in a shared token scenario.
48
49
 
49
50
  Foundation roles are enforced by `foundation-role`, `foundation-selector` and
50
51
  `foundation-import`, alongside the regular token checks. Shared definitions
51
- belong on the document root or explicit root themes; ordinary declarations belong
52
+ belong on the document root (per-theme values as halves, such as `--x-light` and
53
+ `--x-dark`) or a brand's `[data-brand]`; ordinary declarations belong
52
54
  in `base.css`, and font-face descriptors in optional `fonts.css`. The entry imports
53
55
  canonical sheets; those sheets cannot import another styling layer. Component
54
56
  classes, IDs, data/ARIA hooks, contextual selectors, keyframes and scoped UI rules
@@ -59,7 +61,9 @@ font-face metadata keeps its separate asset role.
59
61
  `base.css` has three closed roles:
60
62
 
61
63
  - Document defaults: root/body typography, canvas colors and theme behavior,
62
- global text selection and document scrollbars.
64
+ global text selection and document scrollbars (the starter keeps the scrollbar's space
65
+ with `scrollbar-gutter: stable` and locks page scrolling while a modal `<dialog>` is
66
+ open with `html:has(:modal)`).
63
67
  - Native resets: permitted normalization properties and values, such as zero
64
68
  spacing, inherited control typography, list resets and responsive replaced media.
65
69
  - Global accessibility: universal `:focus-visible` outline rules, and reduced-motion
@@ -88,8 +92,29 @@ geometry exceptions if a component needs them.
88
92
 
89
93
  Use semantic HTML and test relevant keyboard/focus behavior. Motion should
90
94
  consume duration/easing tokens and respect reduced motion. Brand changes belong
91
- in tokens or documented component hooks. The starter uses system fonts and has
92
- no icon component; add a shared icon primitive when it is needed.
95
+ in tokens or documented component hooks. The starter uses system fonts; icons go
96
+ through `Icon` (its glyph set in `assets/glyphs/`) and icon-only actions through
97
+ `IconButton`.
98
+
99
+ Themes: a token that differs per theme has one half per declared theme on `:root`
100
+ (`--color-accent-9-light`, `--color-accent-9-dark`); a half refers to halves
101
+ (`var(--slate-11-dark)`), never to a token that follows the theme. Never set token values
102
+ under `[data-theme]` or `prefers-color-scheme`. ADS writes `tokens/themes.generated.css`
103
+ and `tokens/themes.generated.ts` (`ads assets`, the showcase or the MCP server); commit
104
+ them and do not edit them. Set `data-theme="<name>"` on `<html>` or
105
+ on a section, or set `"followSystemTheme": true` to follow the OS. Show theme-specific
106
+ content with `display: var(--display-dark, block)`; never style by a `[data-theme]` or
107
+ `[data-brand]` selector. A Canvas, WebGL or SVG renderer takes its colors from
108
+ `paletteFor(element)` (`controllers/Palette`, generated `tokens/themes.generated.ts`) once
109
+ per render and redraws from `observePalette`. A per-theme value from data at runtime
110
+ uses `themed()` or `themedByScheme()` from `tokens/themes.generated.ts`, never
111
+ `light-dark()`.
112
+
113
+ The starter has one brand. For several (white label, a product family, a partner
114
+ section), declare `brands` in `ds.config.json`; the first is the default. A brand sets
115
+ only its own values on `[data-brand="<name>"]`, with every half of a themed token it
116
+ changes. `ads check` fails on old theme selectors, missing halves and `brand-*` errors; the
117
+ token guide (`ads://guides/tokens`) has the details.
93
118
 
94
119
  ## Showcase
95
120
 
@@ -109,7 +134,9 @@ runtime, CSS and fonts, through MCP resources. App presentation comes from the
109
134
  selected compiled scenario; reusable review layouts live in development-only `review/` through its separate public entry. Do not recreate
110
135
  production widgets inside the client or scenario.
111
136
 
112
- There are four sections: Tokens, Components, Patterns and Composition. There are
137
+ There are five sections: Brand (first, shown only when the project has scenarios in
138
+ `brand/`), Tokens, Components, Patterns and Composition, plus an Icons tab after Tokens
139
+ for the glyph set. There are
113
140
  no required `TokensPage`/`ComponentsPage`/`PatternsPage`/`CompositionPage` files.
114
141
  Legacy custom browsing pages remain checked when present, but new projects use
115
142
  the built-in client. Its tooling CSS is separate from the project style contract.
@@ -214,10 +241,16 @@ preview builds; review meaningful states in both themes and sizes.
214
241
  ## Branding
215
242
 
216
243
  Keep original artwork, variants, usage, credits, and licenses in
217
- `design-system/assets/brand/`. This starter has only guidance there, no artwork.
244
+ `design-system/assets/brand/`. This starter has placeholder artwork there (`logo.svg`,
245
+ `logo.dark.svg`, `app-icon.svg`) with its README; replace it with the product's own.
246
+ Other products' logos are not brand artwork or glyphs: keep them, in their own
247
+ colors and under their owners' trademark and usage terms, in `assets/logos/` and
248
+ show them as images (a CSS mask over `currentColor` for a muted use); ADS generates
249
+ and checks nothing there.
218
250
  Font assets belong in `assets/fonts/`; add optional `tokens/fonts.css` first in
219
251
  the import-only foundation entry. The fixed import order is fonts (when
220
- present), colors, typography, spacing, elevation, base.
252
+ present), colors, typography, spacing, elevation, base, then the generated
253
+ `themes.generated.css`.
221
254
 
222
255
  Select an SVG with `assets.iconSource` in `ds.config.json`, relative to the ADS
223
256
  folder. Initialized builds run checks and Oxlint, then `ads assets`, then existing
@@ -9,7 +9,9 @@ components in four groups (`components/Actions/Button`, `components/Actions/Icon
9
9
  `components/Content/Icon/glyphs.ts`, one pattern
10
10
  (`patterns/Search/SearchBar`) and one composition (`composition/Search/SearchPage`),
11
11
  plus placeholder brand artwork in `assets/brand/` (a logo with its dark-theme
12
- variant, and the app icon that `assets.iconSource` names). Rename, restyle or
12
+ variant, and the app icon that `assets.iconSource` names), and a shared
13
+ `controllers/Palette` that gives Canvas, WebGL and SVG renderers their colors. Rename,
14
+ restyle or
13
15
  replace them as the product's own; it has no fonts. The minimal showcase shell and MCP client
14
16
  come from ADS tooling.
15
17
 
@@ -34,7 +36,7 @@ npm run dev:showcase
34
36
  For unreleased tooling, create from the real local package:
35
37
 
36
38
  ```sh
37
- ads_tool_package="/absolute/path/to/reqvire-org-ads-0.3.45.tgz"
39
+ ads_tool_package="/absolute/path/to/reqvire-org-ads-0.3.47.tgz"
38
40
  npx --yes --package "$ads_tool_package" ads create my-design-system --framework react --tool-package "$ads_tool_package"
39
41
  ```
40
42
 
@@ -68,8 +70,8 @@ The foundation meets WCAG 2.2 AA:
68
70
 
69
71
  - **Color** (`colors.css`): six 12-step ramps (`--slate-*`, `--color-accent-*`,
70
72
  `--color-green|amber|red|blue-*`); each step has one job: 1–2 backgrounds, 3–5 component
71
- rest/hover/pressed, 6–8 borders, 9–10 solid fills, 11–12 text. The dark theme redefines
72
- the ramps under the same names. Semantic roles (`--bg-*`, `--text-*`, `--border-*`,
73
+ rest/hover/pressed, 6–8 borders, 9–10 solid fills, 11–12 text. Each step has a light and a
74
+ dark half (`--slate-9-light`, `--slate-9-dark`). Semantic roles (`--bg-*`, `--text-*`, `--border-*`,
73
75
  `--accent*`, `--success|warning|danger|info*`) alias ramp steps; text pairs reach 4.5:1
74
76
  and focus and strong borders 3:1 in both themes. Layers go canvas → surface → raised,
75
77
  each a step lighter in dark; inputs use `--bg-field`; `--bg-overlay` is the modal scrim and
@@ -87,10 +89,13 @@ The foundation meets WCAG 2.2 AA:
87
89
  - **Shape & elevation**: radius `--radius-xs`…`--radius-2xl` and `--radius-full`, border
88
90
  and focus widths, layered shadows `--shadow-xs`…`--shadow-xl` (stronger in dark), and
89
91
  fixed stacking layers `--z-*`.
90
- - **Themes**: light (default) and dark, declared in `ds.config.json`. Light ramps sit on
91
- `:root, [data-theme="light"]`, roles on `:root, [data-theme]` and dark ramps on
92
- `[data-theme="dark"]`, so `data-theme` themes the page on `<html>` or one section on any
93
- element.
92
+ - **Themes**: light (default) and dark, declared in `ds.config.json`. Every themed token is
93
+ written as halves on `:root`; ADS generates `tokens/themes.generated.css` (switches and
94
+ resolvers) and `tokens/themes.generated.ts` (the renderer palette and `themed()`), so
95
+ `data-theme` themes the page on `<html>` or one section on any element, following the
96
+ nearest one. `--display-light`/`--display-dark` show theme-specific content. Runtime
97
+ per-theme values use `themed()` or `themedByScheme()` from `themes.generated.ts`; a
98
+ renderer reads its colors with `paletteFor(element)` from `controllers/Palette`.
94
99
  - **Motion** (`elevation.css`): durations 70/110/150/240/400/700 ms, easing for moving between
95
100
  places (standard), entering and leaving, each with a `-strong` variant for rare important
96
101
  moments; all durations are 0 under reduced motion.
@@ -104,7 +109,7 @@ The foundation meets WCAG 2.2 AA:
104
109
  so it fits any pane. The showcase's grid button draws the project's grid over every
105
110
  preview to check alignment.
106
111
 
107
- `ads check` warns when a text or control pair falls below WCAG AA in any theme
112
+ `ads check` fails when a text or control pair falls below WCAG AA in any theme or brand
108
113
  (`token-contrast`) and when a spacing step leaves the 2 px rhythm (`token-rhythm`).
109
114
  `ads tokens --format dtcg` exports the tokens as W3C Design Tokens JSON for design tools.
110
115
 
@@ -1,8 +1,9 @@
1
1
  # Project branding
2
2
 
3
3
  The starter's placeholder artwork. Replace each file with the product's own and keep this
4
- table current: `ads check` warns about artwork that is undescribed, unlicensed, unused or
5
- missing from the Brand previews (`brand/Identity/Logo`, `brand/Icons/AppIcon`).
4
+ table current: `ads check` fails on artwork that is undescribed, unlicensed or missing from
5
+ the Brand previews (`brand/Identity/Logo`, `brand/Icons/AppIcon`), and lists unused
6
+ artwork for review.
6
7
 
7
8
  | File | Use | Backgrounds |
8
9
  |---|---|---|
@@ -21,8 +22,12 @@ patterns and development review helpers own `--ux-*`; the showcase owns
21
22
  `--showcase-*`. Do not introduce a brand-prefixed token vocabulary or override
22
23
  component state variables.
23
24
 
25
+ This folder holds the product's own artwork only. Other products' logos belong in
26
+ `assets/logos/`, shown as images under their owners' trademark and usage terms.
27
+
24
28
  Name a dark-theme variant `<name>.dark.svg`; the component showing the artwork renders
25
- both and the theme picks one. Fixed colors belong inside the artwork only.
29
+ both and shows each with its display switch (`display: var(--display-dark, block)`), so a
30
+ section shows the variant of its nearest theme. Fixed colors belong inside the artwork only.
26
31
 
27
32
  Put licensed font files in `assets/fonts/` and their declarations in
28
33
  `tokens/fonts.css`. Keep that optional import first in `styles.css`.
@@ -7,6 +7,9 @@ takes the color of the text beside it. `ads assets` turns them into
7
7
  gives extra names to existing glyphs.
8
8
 
9
9
  Keep every glyph on the same 24 × 24 `viewBox` and never set a fill or stroke color in the
10
- file: `ads check` warns about both (`glyph-viewbox`, `glyph-color`).
10
+ file: `ads check` fails on both (`glyph-viewbox`, `glyph-color`). Review the set in the
11
+ showcase's Icons tab. Another product's logo
12
+ that keeps its own colors is not a glyph: it belongs in `assets/logos/`, shown as an image,
13
+ under its owner's trademark and usage terms.
11
14
 
12
15
  License: drawn for the ADS starter, free to use, change or remove (MIT, like ADS).
@@ -1 +1,6 @@
1
- export const fixture = { title: "Icons", sizes: ["sm", "md", "lg", "xl"] } as const;
1
+ export const fixture = {
2
+ title: "Icon",
3
+ sizes: ["sm", "md", "lg", "xl"],
4
+ // Decorative icons beside their text; the showcase's Icons tab lists the whole glyph set.
5
+ examples: [{ name: "search", text: "Search" }, { name: "info", text: "Details" }, { name: "warning", text: "Needs attention" }],
6
+ } as const;
@@ -1,4 +1,4 @@
1
- import { Icon, iconNames } from "@ds";
1
+ import { Icon } from "@ds";
2
2
  import { DemoFrame } from "@ds/review";
3
3
  import { fixture } from "./Icon.ads.fixture";
4
4
  export const scenario = { title: fixture.title, covers: ["Icon"] };
@@ -7,7 +7,8 @@ export default function Scenario() {
7
7
  <>
8
8
  {fixture.sizes.map(size => (
9
9
  <DemoFrame key={size}>
10
- {iconNames.map(name => <Icon key={name} name={name} size={size} label={name} />)}
10
+ {fixture.examples.map(example => <span key={example.name}><Icon name={example.name} size={size} /> {example.text}</span>)}
11
+ <Icon name="add" size={size} label="Add" />
11
12
  </DemoFrame>
12
13
  ))}
13
14
  </>
@@ -7,7 +7,8 @@ beside it. Sizes pair with text: `sm` (16 px) beside sm/base text, `md` (20 px)
7
7
 
8
8
  Without `label` the icon is decorative and hidden from assistive technology; pass `label`
9
9
  when the icon alone carries meaning. Icons have no states of their own: interactive icons
10
- live in an `IconButton`, whose background changes.
10
+ live in an `IconButton`, whose background changes. Review the whole glyph set in the
11
+ showcase's Icons tab; the Icon scenario shows the component in use.
11
12
 
12
13
  | Prop | Type | Default |
13
14
  |---|---|---|
@@ -17,18 +17,12 @@ const sizes = {
17
17
  large: css`height: calc(var(--space-16) * 2);`,
18
18
  };
19
19
  const image = css`
20
- display: block;
21
20
  height: 100%;
22
21
  width: auto;
23
22
  `;
24
- // Both variants are in the page; the theme shows one, so switching needs no script.
25
- const light = css`
26
- :root[data-theme="dark"] & { display: none; }
27
- `;
28
- const dark = css`
29
- display: none;
30
- :root[data-theme="dark"] & { display: block; }
31
- `;
23
+ // Both variants are in the page; the nearest theme shows one, so switching needs no script.
24
+ const light = css`display: var(--display-light, block);`;
25
+ const dark = css`display: var(--display-dark, block);`;
32
26
 
33
27
  /** The product logo, in its light- or dark-theme artwork. */
34
28
  export function Logo({ label, size = "small" }: LogoProps) {
@@ -1,8 +1,10 @@
1
1
  # Logo
2
2
 
3
3
  The product logo from `assets/brand/`: `logo.svg` in the light theme and `logo.dark.svg`
4
- in the dark theme. Both images are in the page and the theme shows one, so switching
5
- themes needs no script. `label` is the accessible name.
4
+ in the dark theme. Both images are in the page and each shows only under its display
5
+ switch (`display: var(--display-light, block)`, `display: var(--display-dark, block)`), so
6
+ the logo follows the nearest `data-theme` and switching themes needs no script. `label` is
7
+ the accessible name.
6
8
 
7
9
  | Prop | Type | Default |
8
10
  |---|---|---|
@@ -0,0 +1,164 @@
1
+ // Renderer colors for Canvas, WebGL and SVG drawing. Read a palette once per render or
2
+ // context change with paletteFor(element), look colors up inside per-item loops, and
3
+ // redraw from observePalette(element, callback). Nothing here inserts DOM nodes.
4
+ import {
5
+ brands,
6
+ contexts,
7
+ defaultContext,
8
+ palette,
9
+ systemThemes,
10
+ themes,
11
+ type ColorToken,
12
+ type Palette,
13
+ type PaletteColor,
14
+ type PaletteContext,
15
+ } from "../../tokens/themes.generated";
16
+
17
+ export type { ColorToken, Palette, PaletteColor, PaletteContext };
18
+
19
+ const themeSelector = themes.map((name) => `[data-theme="${name}"]`).join(", ");
20
+ const brandSelector = brands.map((name) => `[data-brand="${name}"]`).join(", ");
21
+ const darkScheme = "(prefers-color-scheme: dark)";
22
+
23
+ /** The nearest ancestor (or the element itself) matching a selector, crossing shadow roots. */
24
+ function closest(element: Element, selector: string): Element | null {
25
+ let node: Element | null = element;
26
+ while (node) {
27
+ const found = node.closest(selector);
28
+ if (found) return found;
29
+ const root = node.getRootNode();
30
+ node = typeof ShadowRoot !== "undefined" && root instanceof ShadowRoot ? root.host : null;
31
+ }
32
+ return null;
33
+ }
34
+
35
+ function systemTheme(): string | null {
36
+ // Like the generated sheet, the OS scheme applies only to a root without data-theme.
37
+ if (!systemThemes || typeof matchMedia !== "function" || document.documentElement.hasAttribute("data-theme")) return null;
38
+ return matchMedia(darkScheme).matches ? systemThemes.dark : systemThemes.light;
39
+ }
40
+
41
+ /** The palette context an element renders in: its nearest declared data-theme and data-brand,
42
+ * else the OS color scheme (with followSystemTheme) or the default theme and brand. */
43
+ export function paletteContext(element: Element): PaletteContext {
44
+ const theme = closest(element, themeSelector)?.getAttribute("data-theme") ?? systemTheme() ?? themes[0];
45
+ const brand = brandSelector ? closest(element, brandSelector)?.getAttribute("data-brand") : null;
46
+ const key = brand && brand !== (brands as readonly string[])[0] ? `${brand}/${theme}` : theme;
47
+ return (contexts as readonly string[]).includes(key) ? (key as PaletteContext) : defaultContext;
48
+ }
49
+
50
+ /** Every color token resolved for the element's context. Read it once per render, outside
51
+ * per-node and per-edge loops; it is a static object, so lookups cost nothing. */
52
+ export function paletteFor(element: Element): Palette {
53
+ return palette[paletteContext(element)];
54
+ }
55
+
56
+ // Colors outside the palette, normalized once by one offscreen 2D context.
57
+ const cacheSize = 256;
58
+ const colors = new Map<string, PaletteColor | null>();
59
+ let context2d: OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null | undefined;
60
+
61
+ type Subscriber = { element: Element; callback: (palette: Palette, context: PaletteContext) => void; context: PaletteContext };
62
+ const subscribers = new Set<Subscriber>();
63
+ let observer: MutationObserver | null = null;
64
+ let media: MediaQueryList | null = null;
65
+
66
+ function refresh(records?: MutationRecord[]) {
67
+ let changed = false;
68
+ for (const subscriber of subscribers) {
69
+ if (!subscribers.has(subscriber)) continue; // unsubscribed by an earlier callback
70
+ // Only an attribute change on the element or an ancestor can change its context.
71
+ if (records && subscriber.element.getRootNode() === document && !records.some((record) => record.target === subscriber.element || record.target.contains(subscriber.element))) continue;
72
+ const context = paletteContext(subscriber.element);
73
+ if (context === subscriber.context) continue;
74
+ subscriber.context = context;
75
+ changed = true;
76
+ subscriber.callback(palette[context], context);
77
+ }
78
+ if (changed) colors.clear();
79
+ }
80
+ const onMedia = () => refresh();
81
+
82
+ /** Calls back with the new palette whenever the element's effective context changes: a
83
+ * data-theme or data-brand change on it or an ancestor, or the OS color scheme with
84
+ * followSystemTheme. Returns the unsubscribe function. One shared observer serves all. */
85
+ export function observePalette(element: Element, callback: (palette: Palette, context: PaletteContext) => void): () => void {
86
+ const subscriber: Subscriber = { element, callback, context: paletteContext(element) };
87
+ subscribers.add(subscriber);
88
+ if (!observer && typeof MutationObserver === "function") {
89
+ observer = new MutationObserver((records) => refresh(records));
90
+ observer.observe(document.documentElement, { subtree: true, attributes: true, attributeFilter: ["data-theme", "data-brand"] });
91
+ }
92
+ if (!media && systemThemes && typeof matchMedia === "function") {
93
+ media = matchMedia(darkScheme);
94
+ media.addEventListener("change", onMedia);
95
+ }
96
+ return () => {
97
+ subscribers.delete(subscriber);
98
+ if (subscribers.size) return;
99
+ observer?.disconnect();
100
+ observer = null;
101
+ media?.removeEventListener("change", onMedia);
102
+ media = null;
103
+ };
104
+ }
105
+
106
+ function canvas2d() {
107
+ if (context2d !== undefined) return context2d;
108
+ const canvas = typeof OffscreenCanvas === "function" ? new OffscreenCanvas(1, 1) : typeof document !== "undefined" ? Object.assign(document.createElement("canvas"), { width: 1, height: 1 }) : null;
109
+ context2d = (canvas?.getContext("2d", { willReadFrequently: true }) as OffscreenCanvasRenderingContext2D | CanvasRenderingContext2D | null | undefined) ?? null;
110
+ return context2d;
111
+ }
112
+
113
+ const hex = (value: number) => value.toString(16).padStart(2, "0");
114
+ function fromChannels(r: number, g: number, b: number, a: number): PaletteColor {
115
+ const alpha = Math.round(a * 10000) / 10000;
116
+ return { css: alpha >= 1 ? `#${hex(r)}${hex(g)}${hex(b)}` : `rgba(${r}, ${g}, ${b}, ${alpha})`, rgba: [r, g, b, alpha] };
117
+ }
118
+
119
+ function normalize(value: string): PaletteColor | null {
120
+ const ctx = canvas2d();
121
+ if (!ctx) return null;
122
+ // An invalid color leaves fillStyle unchanged; two sentinels tell it apart from a valid one.
123
+ ctx.fillStyle = "#000000";
124
+ ctx.fillStyle = value;
125
+ const first = String(ctx.fillStyle);
126
+ ctx.fillStyle = "#ffffff";
127
+ ctx.fillStyle = value;
128
+ if (first !== String(ctx.fillStyle)) return null;
129
+ const legacy = first.match(/^#([\da-f]{6})$/i) ?? first.match(/^rgba\((\d+), (\d+), (\d+), ([\d.]+)\)$/);
130
+ if (legacy) return legacy.length === 2 ? fromChannels(parseInt(legacy[1].slice(0, 2), 16), parseInt(legacy[1].slice(2, 4), 16), parseInt(legacy[1].slice(4), 16), 1) : fromChannels(Number(legacy[1]), Number(legacy[2]), Number(legacy[3]), Number(legacy[4]));
131
+ // Wider color syntax: draw one pixel; the canvas clips to sRGB.
132
+ ctx.clearRect(0, 0, 1, 1);
133
+ ctx.fillRect(0, 0, 1, 1);
134
+ const [r, g, b, a] = ctx.getImageData(0, 0, 1, 1).data;
135
+ return fromChannels(r, g, b, a / 255);
136
+ }
137
+
138
+ /** A color for a value outside the palette: a palette token (--name or var(--name)) from the
139
+ * element's context, currentColor or another token from the element's computed style, or any
140
+ * absolute CSS color. Absolute strings are normalized once by an offscreen canvas and kept in a
141
+ * bounded cache; the cache clears when an observed context changes. Null when not a color. */
142
+ export function resolveColor(element: Element, value: string): PaletteColor | null {
143
+ let text = value.trim();
144
+ const token = text.match(/^var\(\s*(--[\w-]+)\s*\)$/)?.[1] ?? (text.startsWith("--") ? text : null);
145
+ if (token) {
146
+ const own = (paletteFor(element) as Record<string, PaletteColor | undefined>)[token];
147
+ if (own) return own;
148
+ text = getComputedStyle(element).getPropertyValue(token).trim();
149
+ } else if (/^currentcolor$/i.test(text) || text.includes("var(")) {
150
+ const style = getComputedStyle(element);
151
+ text = /^currentcolor$/i.test(text) ? style.color : text.replace(/var\(\s*(--[\w-]+)\s*\)/g, (_match, name: string) => style.getPropertyValue(name).trim());
152
+ }
153
+ if (!text) return null;
154
+ if (colors.has(text)) {
155
+ const cached = colors.get(text) ?? null;
156
+ colors.delete(text);
157
+ colors.set(text, cached);
158
+ return cached;
159
+ }
160
+ const color = normalize(text);
161
+ colors.set(text, color);
162
+ if (colors.size > cacheSize) colors.delete(colors.keys().next().value as string);
163
+ return color;
164
+ }
@@ -9,3 +9,6 @@ export { Logo, type LogoProps } from "./components/Content/Logo/Logo";
9
9
  export { TextField, type TextFieldProps } from "./components/Forms/TextField/TextField";
10
10
  export { Grid, GridItem, type GridProps, type GridItemProps } from "./components/Layout/Grid/Grid";
11
11
  export { SearchBar, type SearchBarProps } from "./patterns/Search/SearchBar/SearchBar";
12
+
13
+ // Renderer colors for Canvas, WebGL and SVG drawing, from the generated tokens/themes.generated.ts.
14
+ export { observePalette, paletteContext, paletteFor, resolveColor, type ColorToken, type Palette, type PaletteColor, type PaletteContext } from "./controllers/Palette/Palette";
@@ -57,11 +57,8 @@ const label = css`
57
57
  overflow-wrap: anywhere;
58
58
  `;
59
59
  // Paired artwork shows the variant of the current theme, as the UI does.
60
- const light = css`:root[data-theme="dark"] & { display: none; }`;
61
- const dark = css`
62
- display: none;
63
- :root[data-theme="dark"] & { display: block; }
64
- `;
60
+ const light = css`display: var(--display-light, block);`;
61
+ const dark = css`display: var(--display-dark, block);`;
65
62
  const icons = css`
66
63
  display: flex;
67
64
  flex-wrap: wrap;
@@ -60,7 +60,16 @@ const sampleStyle = css`
60
60
  &[data-ads-property="font-size"] { font-size: var(--ux-token-preview-value); }
61
61
  &[data-ads-property="font-weight"] { font-weight: var(--ux-token-preview-value); font-size: calc(var(--text-base) * 2); line-height: 1; }
62
62
  &[data-ads-property="line-height"] { line-height: var(--ux-token-preview-value); }
63
- &[data-ads-property="column-count"] { column-count: var(--ux-token-preview-value); column-gap: var(--space-2); column-rule: var(--border-w) solid var(--border-strong); }
63
+ /* Column counts draw that many columns: stripes with a gap, filling the tile. */
64
+ &[data-ads-property="column-count"] {
65
+ column-count: var(--ux-token-preview-value);
66
+ height: calc(var(--space-8) * 3);
67
+ background: repeating-linear-gradient(
68
+ to right,
69
+ var(--accent) 0 calc((100% + var(--space-2)) / var(--ux-token-preview-value) - var(--space-2)),
70
+ transparent 0 calc((100% + var(--space-2)) / var(--ux-token-preview-value))
71
+ );
72
+ }
64
73
  &[data-ads-property="letter-spacing"] { letter-spacing: var(--ux-token-preview-value); font-size: calc(var(--text-base) * 1.5); }
65
74
  &[data-ads-property="height"] {
66
75
  height: var(--ux-token-preview-value);
@@ -109,7 +118,7 @@ function TokenTile({ sample, text }: { sample: TokenSample; text: string }) {
109
118
  return (
110
119
  <article className={cx("ux-token-preview__item", tile)}>
111
120
  <span ref={ref} className={cx("ux-token-preview__sample", sampleStyle)} data-ads-token={sample.token} data-ads-property={sample.property}>
112
- {["background-color", "width", "height", "border-radius", "box-shadow", "animation-duration", "animation-timing-function"].includes(sample.property) ? "" : text}
121
+ {["background-color", "width", "height", "border-radius", "box-shadow", "column-count", "animation-duration", "animation-timing-function"].includes(sample.property) ? "" : text}
113
122
  </span>
114
123
  <code className={cx("ux-token-preview__name", label)}>{sample.token}</code>
115
124
  <small className={label}>{value}</small>
@@ -3,3 +3,4 @@
3
3
  @import "./tokens/spacing.css";
4
4
  @import "./tokens/elevation.css";
5
5
  @import "./tokens/base.css";
6
+ @import "./tokens/themes.generated.css";
@@ -1,8 +1,11 @@
1
- /* Themes: the page (on <html>) or one section (any element) with data-theme. A themed section
2
- paints its own canvas and text, since inherited colors were resolved in the outer theme. */
3
- :root, [data-theme="light"] { color-scheme: light; }
4
- [data-theme="dark"] { color-scheme: dark; }
5
- [data-theme] { background: var(--bg-canvas); color: var(--text-body); }
1
+ /* Themes and brands: the page (on <html>) or one section (any element) with data-theme or
2
+ data-brand. A themed or branded section paints its own canvas and text, since inherited
3
+ colors were resolved outside it. themes.generated.css sets each theme's color-scheme. */
4
+ [data-theme], [data-brand] { background: var(--bg-canvas); color: var(--text-body); }
5
+
6
+ /* A modal dialog locks the page behind it; the scrollbar's space stays so nothing shifts. */
7
+ html { scrollbar-gutter: stable; }
8
+ html:has(:modal) { overflow: hidden; }
6
9
 
7
10
  *,
8
11
  *::before,