@reqvire-org/ads 0.3.48 → 0.3.49

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.
@@ -27,6 +27,8 @@ export const findingRules = Object.freeze({
27
27
  // light-dark() picks by color scheme, so it cannot tell two themes of one scheme apart.
28
28
  "theme-light-dark": "error",
29
29
  "token-contrast": "error", "token-rhythm": "error",
30
+ // A contrast pair color ADS cannot resolve statically (currentColor, relative color syntax).
31
+ "token-contrast-unresolved": "info",
30
32
  // Equal values do not prove equal purpose.
31
33
  "token-overlap-review": "review",
32
34
  });
@@ -48,8 +48,11 @@ function substitute(values, text, seen) {
48
48
  return parsed.toString();
49
49
  }
50
50
 
51
- /** One token in one context: { color: [r, g, b, a] }, { unresolved: reason, value } or null. */
52
- function resolveToken(values, name, scheme) {
51
+ /** One token in one context (contextValues() of that theme and brand, and the theme's color
52
+ * scheme): { color: [r, g, b, a] } in sRGB 0–255 clipped as a canvas draws it,
53
+ * { unresolved: reason, value, invalid? }, { other: true, value } for a value that is not a
54
+ * color, or null when the token is not set. token-contrast resolves its pairs through this. */
55
+ export function resolveColorToken(values, name, scheme) {
53
56
  const own = values.get(name);
54
57
  if (!own) return null;
55
58
  let text;
@@ -84,7 +87,7 @@ export function resolvePalette(tokens, config) {
84
87
  const results = new Map(names.map(name => [name, []]));
85
88
  for (const context of contexts) {
86
89
  const values = contextValues(tokens, { theme: context.theme.name, brand: context.brand, themes });
87
- for (const name of names) results.get(name).push(resolveToken(values, name, context.theme.scheme));
90
+ for (const name of names) results.get(name).push(resolveColorToken(values, name, context.theme.scheme));
88
91
  }
89
92
  const palette = Object.fromEntries(contexts.map(context => [context.key, {}])), unresolved = [], included = [];
90
93
  for (const name of names) {
@@ -92,7 +92,7 @@ keeps independent component token definitions valid.
92
92
 
93
93
  ## Accessibility and rhythm checks
94
94
 
95
- `ads check` checks token values in every theme and brand. Each finding below is an error:
95
+ `ads check` checks token values in every theme and brand. Each finding below is an error unless marked info:
96
96
 
97
97
  - `token-contrast`: the roles that meet on screen fall below WCAG 2.2 AA: `--text-strong`,
98
98
  `--text-body`, `--text-muted`, `--text-link` and `--accent-text` on `--bg-canvas`,
@@ -100,6 +100,13 @@ keeps independent component token definitions valid.
100
100
  status's `-fg` on its solid and `-text` on its `-bg` (4.5:1); `--border-focus` and
101
101
  `--border-strong` on the canvas and surface (3:1). Fix it by choosing a different ramp
102
102
  step for the role, in the theme the message names, never with a one-off color.
103
+ Any CSS color is evaluated (hex, named, `rgb()`, `hsl()`, `hwb()`, `lab()`, `lch()`,
104
+ `oklab()`, `oklch()`, `color()`, `color-mix()`, `light-dark()`), through halves and
105
+ aliases. A translucent background counts as composited over `--bg-canvas`, a translucent
106
+ foreground as composited over its background.
107
+ - `token-contrast-unresolved` (info): a pair color ADS cannot resolve statically
108
+ (`currentColor`, relative color syntax, a system color), so that pair is not checked. Give
109
+ the role a color or a ramp step, or check the pages that use it with `ads audit`.
103
110
  - `token-rhythm`: a numbered spacing step leaves the scale `--space-N` = N × 2 px.
104
111
  - `control-padding`: pad a control with the token for its size. A block sized with
105
112
  `--control-height-<size>` pads its sides with `--control-padding-<size>`; the small gap
@@ -10,7 +10,7 @@ Each message names its WCAG criterion.
10
10
 
11
11
  | Rule | What it reviews | WCAG |
12
12
  |---|---|---|
13
- | `token-contrast` | Text, link, accent and status text on their backgrounds (4.5:1); focus and control borders on canvas and surface (3:1); in every theme and brand | 1.4.3, 1.4.11 |
13
+ | `token-contrast` | Text, link, accent and status text on their backgrounds (4.5:1); focus and control borders on canvas and surface (3:1); in every theme and brand, for any CSS color syntax, with translucent colors composited over their background and the canvas. A pair color that cannot be resolved statically (`currentColor`, relative color syntax) is a `token-contrast-unresolved` info item | 1.4.3, 1.4.11 |
14
14
  | `a11y-target-size` | `--control-height-*` of at least 24 px (44 px where touch is common) | 2.5.8 |
15
15
  | `a11y-focus` | `--focus-w` of at least 2 px, and a `:focus-visible` indicator in `base.css` | 2.4.7, 2.4.13 |
16
16
  | `a11y-text-resize` | Font-size tokens in `rem`, so text follows the reader's browser font size | 1.4.4 |
@@ -92,7 +92,7 @@ keeps independent component token definitions valid.
92
92
 
93
93
  ## Accessibility and rhythm checks
94
94
 
95
- `ads check` checks token values in every theme and brand. Each finding below is an error:
95
+ `ads check` checks token values in every theme and brand. Each finding below is an error unless marked info:
96
96
 
97
97
  - `token-contrast`: the roles that meet on screen fall below WCAG 2.2 AA: `--text-strong`,
98
98
  `--text-body`, `--text-muted`, `--text-link` and `--accent-text` on `--bg-canvas`,
@@ -100,6 +100,13 @@ keeps independent component token definitions valid.
100
100
  status's `-fg` on its solid and `-text` on its `-bg` (4.5:1); `--border-focus` and
101
101
  `--border-strong` on the canvas and surface (3:1). Fix it by choosing a different ramp
102
102
  step for the role, in the theme the message names, never with a one-off color.
103
+ Any CSS color is evaluated (hex, named, `rgb()`, `hsl()`, `hwb()`, `lab()`, `lch()`,
104
+ `oklab()`, `oklch()`, `color()`, `color-mix()`, `light-dark()`), through halves and
105
+ aliases. A translucent background counts as composited over `--bg-canvas`, a translucent
106
+ foreground as composited over its background.
107
+ - `token-contrast-unresolved` (info): a pair color ADS cannot resolve statically
108
+ (`currentColor`, relative color syntax, a system color), so that pair is not checked. Give
109
+ the role a color or a ramp step, or check the pages that use it with `ads audit`.
103
110
  - `token-rhythm`: a numbered spacing step leaves the scale `--space-N` = N × 2 px.
104
111
  - `control-padding`: pad a control with the token for its size. A block sized with
105
112
  `--control-height-<size>` pads its sides with `--control-padding-<size>`; the small gap
@@ -92,7 +92,7 @@ keeps independent component token definitions valid.
92
92
 
93
93
  ## Accessibility and rhythm checks
94
94
 
95
- `ads check` checks token values in every theme and brand. Each finding below is an error:
95
+ `ads check` checks token values in every theme and brand. Each finding below is an error unless marked info:
96
96
 
97
97
  - `token-contrast`: the roles that meet on screen fall below WCAG 2.2 AA: `--text-strong`,
98
98
  `--text-body`, `--text-muted`, `--text-link` and `--accent-text` on `--bg-canvas`,
@@ -100,6 +100,13 @@ keeps independent component token definitions valid.
100
100
  status's `-fg` on its solid and `-text` on its `-bg` (4.5:1); `--border-focus` and
101
101
  `--border-strong` on the canvas and surface (3:1). Fix it by choosing a different ramp
102
102
  step for the role, in the theme the message names, never with a one-off color.
103
+ Any CSS color is evaluated (hex, named, `rgb()`, `hsl()`, `hwb()`, `lab()`, `lch()`,
104
+ `oklab()`, `oklch()`, `color()`, `color-mix()`, `light-dark()`), through halves and
105
+ aliases. A translucent background counts as composited over `--bg-canvas`, a translucent
106
+ foreground as composited over its background.
107
+ - `token-contrast-unresolved` (info): a pair color ADS cannot resolve statically
108
+ (`currentColor`, relative color syntax, a system color), so that pair is not checked. Give
109
+ the role a color or a ramp step, or check the pages that use it with `ads audit`.
103
110
  - `token-rhythm`: a numbered spacing step leaves the scale `--space-N` = N × 2 px.
104
111
  - `control-padding`: pad a control with the token for its size. A block sized with
105
112
  `--control-height-<size>` pads its sides with `--control-padding-<size>`; the small gap
@@ -92,7 +92,7 @@ keeps independent component token definitions valid.
92
92
 
93
93
  ## Accessibility and rhythm checks
94
94
 
95
- `ads check` checks token values in every theme and brand. Each finding below is an error:
95
+ `ads check` checks token values in every theme and brand. Each finding below is an error unless marked info:
96
96
 
97
97
  - `token-contrast`: the roles that meet on screen fall below WCAG 2.2 AA: `--text-strong`,
98
98
  `--text-body`, `--text-muted`, `--text-link` and `--accent-text` on `--bg-canvas`,
@@ -100,6 +100,13 @@ keeps independent component token definitions valid.
100
100
  status's `-fg` on its solid and `-text` on its `-bg` (4.5:1); `--border-focus` and
101
101
  `--border-strong` on the canvas and surface (3:1). Fix it by choosing a different ramp
102
102
  step for the role, in the theme the message names, never with a one-off color.
103
+ Any CSS color is evaluated (hex, named, `rgb()`, `hsl()`, `hwb()`, `lab()`, `lch()`,
104
+ `oklab()`, `oklch()`, `color()`, `color-mix()`, `light-dark()`), through halves and
105
+ aliases. A translucent background counts as composited over `--bg-canvas`, a translucent
106
+ foreground as composited over its background.
107
+ - `token-contrast-unresolved` (info): a pair color ADS cannot resolve statically
108
+ (`currentColor`, relative color syntax, a system color), so that pair is not checked. Give
109
+ the role a color or a ramp step, or check the pages that use it with `ads audit`.
103
110
  - `token-rhythm`: a numbered spacing step leaves the scale `--space-N` = N × 2 px.
104
111
  - `control-padding`: pad a control with the token for its size. A block sized with
105
112
  `--control-height-<size>` pads its sides with `--control-padding-<size>`; the small gap
@@ -92,7 +92,7 @@ keeps independent component token definitions valid.
92
92
 
93
93
  ## Accessibility and rhythm checks
94
94
 
95
- `ads check` checks token values in every theme and brand. Each finding below is an error:
95
+ `ads check` checks token values in every theme and brand. Each finding below is an error unless marked info:
96
96
 
97
97
  - `token-contrast`: the roles that meet on screen fall below WCAG 2.2 AA: `--text-strong`,
98
98
  `--text-body`, `--text-muted`, `--text-link` and `--accent-text` on `--bg-canvas`,
@@ -100,6 +100,13 @@ keeps independent component token definitions valid.
100
100
  status's `-fg` on its solid and `-text` on its `-bg` (4.5:1); `--border-focus` and
101
101
  `--border-strong` on the canvas and surface (3:1). Fix it by choosing a different ramp
102
102
  step for the role, in the theme the message names, never with a one-off color.
103
+ Any CSS color is evaluated (hex, named, `rgb()`, `hsl()`, `hwb()`, `lab()`, `lch()`,
104
+ `oklab()`, `oklch()`, `color()`, `color-mix()`, `light-dark()`), through halves and
105
+ aliases. A translucent background counts as composited over `--bg-canvas`, a translucent
106
+ foreground as composited over its background.
107
+ - `token-contrast-unresolved` (info): a pair color ADS cannot resolve statically
108
+ (`currentColor`, relative color syntax, a system color), so that pair is not checked. Give
109
+ the role a color or a ramp step, or check the pages that use it with `ads audit`.
103
110
  - `token-rhythm`: a numbered spacing step leaves the scale `--space-N` = N × 2 px.
104
111
  - `control-padding`: pad a control with the token for its size. A block sized with
105
112
  `--control-height-<size>` pads its sides with `--control-padding-<size>`; the small gap
@@ -1,8 +1,10 @@
1
- import { contextValues, defaultThemes, resolveValue } from "./themes.mjs";
1
+ import { contextValues, defaultThemes } from "./themes.mjs";
2
+ import { paletteContexts, resolveColorToken } from "./palette-generated.mjs";
2
3
  import { findingSeverity } from "./finding-rules.mjs";
3
4
 
4
5
  /** Accessibility and rhythm reviews of token values: WCAG contrast between the roles that
5
- * meet on screen, in every theme, and spacing steps on the 2 px grid. Both are errors. */
6
+ * meet on screen, in every theme and brand, and spacing steps on the 2 px grid. Both are
7
+ * errors; a contrast pair ADS cannot resolve statically is an info item. */
6
8
 
7
9
  const named = { white: [255, 255, 255, 1], black: [0, 0, 0, 1] };
8
10
 
@@ -57,32 +59,57 @@ function contrastPairs(names) {
57
59
  return pairs.filter(([foreground, background]) => names.has(foreground) && names.has(background));
58
60
  }
59
61
 
62
+ const label = ({ theme, brand }) => brand === undefined ? `the ${theme.name} theme` : `the ${theme.name} theme of brand "${brand}"`;
63
+ const sameEntry = (first, second) => first?.color && second?.color ? first.color.every((value, index) => value === second.color[index]) : !first?.color && !second?.color && first?.value === second?.value;
64
+
65
+ /** WCAG contrast of every role pair in every theme of every brand. Colors resolve the way the
66
+ * generated palette resolves them (resolveColorToken: the per-theme halves, aliases and var()
67
+ * fallbacks, light-dark() by the theme's scheme, every CSS color syntax and color-mix(), clipped
68
+ * to sRGB). WCAG compares opaque colors, so alpha is composited as the page paints it: a
69
+ * translucent background over --bg-canvas (the canvas itself over white), then a translucent
70
+ * foreground over that background. A brand other than the default reports only the pairs whose
71
+ * colors it changes. A pair color that cannot be resolved statically (currentColor, relative
72
+ * color syntax, a system color, a non-color value) is reported once per token and value as a
73
+ * token-contrast-unresolved info item instead of being checked. */
60
74
  export function tokenContrastAdvisories(tokens, themes = defaultThemes, brands = []) {
61
75
  const names = new Set(tokens.map(token => token.name));
62
- const advisories = [];
76
+ const advisories = [], unresolved = new Map();
63
77
  const pairs = contrastPairs(names);
64
- // Every brand in every theme; a brand other than the default reports only the pairs it changes.
65
- for (const { name: scope } of themes) {
66
- const defaults = contextValues(tokens, { theme: scope, themes });
67
- for (const brand of brands.length ? brands.map(item => item.name) : [undefined]) {
68
- const own = brand === undefined || brand === brands[0].name;
69
- const values = own ? defaults : contextValues(tokens, { theme: scope, brand, themes });
70
- for (const [foreground, background, minimum] of pairs) {
71
- const fore = resolveValue(values, foreground), backValue = resolveValue(values, background);
72
- const front = parseColor(fore ?? ""), back = parseColor(backValue ?? "");
73
- if (!front || !back) continue;
74
- if (!own && fore === resolveValue(defaults, foreground) && backValue === resolveValue(defaults, background)) continue;
75
- const ratio = contrastRatio(front, back[3] < 1 ? over(back, [255, 255, 255, 1]) : back);
76
- if (ratio + 1e-9 >= minimum) continue;
77
- const at = values.get(foreground);
78
- if (!at) continue;
79
- const { file, line, column } = at;
80
- const where = own ? `the ${scope} theme` : `the ${scope} theme of brand "${brand}"`;
81
- advisories.push({ rule: "token-contrast", severity: findingSeverity("token-contrast"), file, line, column, tokens: [foreground, background], guidanceUri: "ads://guides/tokens",
82
- message: `${foreground} on ${background} is ${ratio.toFixed(2)}:1 in ${where}; ${minimum === 4.5 ? "text needs 4.5:1 (WCAG 1.4.3)" : "focus indicators and control borders need 3:1 (WCAG 1.4.11)"}.` });
78
+ const defaults = new Map(themes.map(theme => [theme.name, contextValues(tokens, { theme: theme.name, themes })]));
79
+ for (const context of paletteContexts({ themes, brands })) {
80
+ const { theme, brand } = context, scheme = theme.scheme;
81
+ const own = brand === undefined;
82
+ const values = own ? defaults.get(theme.name) : contextValues(tokens, { theme: theme.name, brand, themes });
83
+ const resolved = new Map(), base = new Map();
84
+ const color = (name, from = values, cache = resolved) => { if (!cache.has(name)) cache.set(name, resolveColorToken(from, name, scheme)); return cache.get(name); };
85
+ const canvasEntry = color("--bg-canvas");
86
+ const canvas = canvasEntry?.color ? over(canvasEntry.color, [255, 255, 255, 1]) : [255, 255, 255, 1];
87
+ for (const [foreground, background, minimum] of pairs) {
88
+ const front = color(foreground), back = color(background);
89
+ if (!front || !back) continue;
90
+ if (!own && sameEntry(front, color(foreground, defaults.get(theme.name), base)) && sameEntry(back, color(background, defaults.get(theme.name), base))) continue;
91
+ const missing = [[foreground, front, background], [background, back, foreground]].filter(([, entry]) => !entry.color);
92
+ for (const [name, entry, partner] of missing) {
93
+ const key = `${name}\u0000${entry.value}`;
94
+ const item = unresolved.get(key) ?? { name, value: entry.value, reason: entry.unresolved ?? "not a color", at: values.get(name), contexts: new Set(), partners: new Set() };
95
+ item.contexts.add(label(context)); item.partners.add(partner);
96
+ unresolved.set(key, item);
83
97
  }
98
+ if (missing.length) continue;
99
+ const opaqueBack = back.color[3] < 1 ? over(back.color, background === "--bg-canvas" ? [255, 255, 255, 1] : canvas) : back.color;
100
+ const ratio = contrastRatio(front.color, opaqueBack);
101
+ if (ratio + 1e-9 >= minimum) continue;
102
+ const at = values.get(foreground);
103
+ if (!at) continue;
104
+ const { file, line, column } = at;
105
+ advisories.push({ rule: "token-contrast", severity: findingSeverity("token-contrast"), file, line, column, tokens: [foreground, background], guidanceUri: "ads://guides/tokens",
106
+ message: `${foreground} on ${background} is ${ratio.toFixed(2)}:1 in ${label(context)}; ${minimum === 4.5 ? "text needs 4.5:1 (WCAG 1.4.3)" : "focus indicators and control borders need 3:1 (WCAG 1.4.11)"}.` });
84
107
  }
85
108
  }
109
+ for (const { name, value, reason, at, contexts, partners } of unresolved.values()) {
110
+ advisories.push({ rule: "token-contrast-unresolved", severity: findingSeverity("token-contrast-unresolved"), ...(at ? { file: at.file, line: at.line, column: at.column } : {}), tokens: [name, ...partners], guidanceUri: "ads://guides/tokens",
111
+ message: `${name} is ${value} in ${[...contexts].join(", ")}, which ADS cannot resolve to a color statically (${reason}), so its contrast with ${[...partners].join(", ")} is not checked. Set it to a color or a ramp step, or check the pages that use it with ads audit.` });
112
+ }
86
113
  return advisories;
87
114
  }
88
115
 
package/docs/CHANGELOG.md CHANGED
@@ -1,34 +1,53 @@
1
1
  # Changelog
2
2
 
3
- ## 0.3.48
3
+ ## 0.3.49
4
4
 
5
5
  <!-- ads-local-tests:start -->
6
- Local verification: **708/708 passed** with `ADS_TEST_BUN=1 npm test`.
7
- Tested commit: `93a657387e39ce23fd85dd3ce54000b4e456dd8d`; Node v24.13.0, Bun 1.4.1.
8
- Completed 2026-10-31T12:27:52.387Z (1286 seconds).
6
+ Local verification: **712/712 passed** with `ADS_TEST_BUN=1 npm test`.
7
+ Tested commit: `c199b06fd9762cd7f3e8d05a6fe5058d1388f756`; Node v24.13.0, Bun 1.4.1.
8
+ Completed 2026-10-31T13:25:26.100Z (1140 seconds).
9
9
 
10
10
  <!-- ads-local-test-proof
11
11
  {
12
12
  "schema": 1,
13
- "version": "0.3.48",
14
- "commit": "93a657387e39ce23fd85dd3ce54000b4e456dd8d",
15
- "sourceSha256": "08f2191456ab4f4d47ae8e9fcb7327125091f736b6c5230ae6c8dbe24ca0b838",
13
+ "version": "0.3.49",
14
+ "commit": "c199b06fd9762cd7f3e8d05a6fe5058d1388f756",
15
+ "sourceSha256": "c4652f12ffca20ad8601857818923564305c0c805f9965d149d38682a858af10",
16
16
  "command": "ADS_TEST_BUN=1 npm test",
17
17
  "result": "pass",
18
- "tests": 708,
19
- "pass": 708,
18
+ "tests": 712,
19
+ "pass": 712,
20
20
  "fail": 0,
21
21
  "cancelled": 0,
22
22
  "skipped": 0,
23
23
  "node": "v24.13.0",
24
24
  "bun": "1.4.1",
25
- "completedAt": "2026-10-31T12:27:52.387Z",
26
- "durationMs": 1286115,
27
- "logSha256": "71f4f100114ac074c9445cb2ee0421783304484061b5d82289134a1b8582aa9e"
25
+ "completedAt": "2026-10-31T13:25:26.100Z",
26
+ "durationMs": 1140159,
27
+ "logSha256": "26b47125ed0f4cfdff35c87187f5ad40c9af5a231b06654cb466719a7eb19ce7"
28
28
  }
29
29
  -->
30
30
  <!-- ads-local-tests:end -->
31
31
 
32
+ - **`token-contrast` checks every CSS color syntax.** It used to read only hex, `rgb()` and
33
+ `hsl()` and skipped every other value without a word, so projects whose ramps are `oklch()`
34
+ got no static contrast checking. It now resolves each pair the way the generated palette
35
+ (`themes.generated.ts`) does, through one shared resolver: per-theme halves, aliases and
36
+ `var()` fallbacks, `light-dark()` by the theme's scheme, named colors, `rgb()`/`hsl()`/`hwb()`,
37
+ `lab()`/`lch()`/`oklab()`/`oklch()`, `color()` spaces and `color-mix()`, clipped to sRGB as a
38
+ canvas draws it, in every theme of every brand. Projects with such ramps can see new
39
+ `token-contrast` errors; fix each by choosing another ramp step for the role in the theme the
40
+ message names.
41
+ - **Alpha is composited as the page paints it.** A translucent background is composited over
42
+ `--bg-canvas` (the canvas itself over white), then a translucent foreground over that
43
+ background, and the ratio is taken between the opaque results.
44
+ - **Unresolvable pair colors are reported.** A pair color ADS cannot resolve statically
45
+ (`currentColor`, relative color syntax, a system color, a value that is not a color) is a
46
+ `token-contrast-unresolved` info item naming the token, its value, the themes and brands,
47
+ and the pairs that go unchecked, instead of being skipped.
48
+
49
+ ## 0.3.48
50
+
32
51
  - **MCP acceptance runs the browser accessibility audit.** When the acceptance policy sets
33
52
  `browserAudit: true`, `ads_accept`, `ads_apply_patch` and `ads_apply_transaction` run the
34
53
  axe-core audit on the candidate before writing any source, in every declared brand and
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reqvire-org/ads",
3
- "version": "0.3.48",
3
+ "version": "0.3.49",
4
4
  "type": "module",
5
5
  "description": "A design system your agent can see and shape. Your components. Your look. Your code.",
6
6
  "repository": {