@atom63/styles 0.1.0-beta.7 → 0.1.0-beta.9

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 (52) hide show
  1. package/README.md +6 -3
  2. package/generated/atom63.figma-sync.json +5506 -3844
  3. package/generated/atom63.tokens.json +7536 -4284
  4. package/package.json +6 -6
  5. package/src/compat/a63-from-shadcn.css +265 -1
  6. package/src/compat/shadcn.css +15 -1
  7. package/src/contracts/choice.css +1 -1
  8. package/src/contracts/choice.tokens.json +1 -1
  9. package/src/contracts/control.css +14 -8
  10. package/src/contracts/control.tokens.json +57 -8
  11. package/src/contracts/environment.css +134 -12
  12. package/src/contracts/environment.resolver.json +664 -23
  13. package/src/contracts/field.css +1 -1
  14. package/src/contracts/field.tokens.json +1 -1
  15. package/src/contracts/selection.css +2 -0
  16. package/src/contracts/selection.tokens.json +5 -0
  17. package/src/contracts/skeleton.css +7 -2
  18. package/src/contracts/skeleton.resolver.json +21 -30
  19. package/src/contracts/surface.css +4 -0
  20. package/src/contracts/surface.tokens.json +57 -0
  21. package/src/contracts/toggle.css +18 -3
  22. package/src/contracts/toggle.resolver.json +123 -0
  23. package/src/tailwind/roles.json +19 -2
  24. package/src/tailwind/theme.css +104 -2
  25. package/src/tailwind/utilities.css +17 -0
  26. package/src/themes/aqua.css +1 -0
  27. package/src/themes/aqua.resolver.json +6 -0
  28. package/src/themes/retro.css +1 -0
  29. package/src/themes/retro.resolver.json +6 -0
  30. package/src/themes/terminal.css +13 -0
  31. package/src/themes/terminal.resolver.json +62 -0
  32. package/src/tokens/brand-action.css +4 -0
  33. package/src/tokens/brand-action.resolver.json +18 -0
  34. package/src/tokens/contrast.browser.test.ts +92 -18
  35. package/src/tokens/density.browser.test.ts +167 -0
  36. package/src/tokens/form-factor.browser.test.ts +129 -0
  37. package/src/tokens/foundation/primitives.css +0 -30
  38. package/src/tokens/foundation/primitives.tokens.json +0 -212
  39. package/src/tokens/foundation/radius.css +5 -0
  40. package/src/tokens/foundation/radius.tokens.json +8 -0
  41. package/src/tokens/foundation/typography.css +24 -0
  42. package/src/tokens/foundation/typography.native.css +12 -2
  43. package/src/tokens/foundation/typography.resolver.json +72 -0
  44. package/src/tokens/index.css +1 -0
  45. package/src/tokens/personalization-axes.browser.test.ts +13 -0
  46. package/src/tokens/semantics.css +120 -6
  47. package/src/tokens/semantics.resolver.json +301 -12
  48. package/src/tokens/surface.css +8 -0
  49. package/src/tokens/surface.resolver.json +49 -0
  50. package/src/tokens/type-roles.css +75 -0
  51. package/src/tokens/type-roles.resolver.json +366 -0
  52. package/src/contracts/toggle.tokens.json +0 -49
@@ -61,6 +61,7 @@
61
61
  transparent 1px,
62
62
  transparent 3px
63
63
  );
64
+ --a63-surface-raised-shadow: var(--a63-surface-shadow);
64
65
  --a63-track-shadow: inset 0 0 4px -1px
65
66
  color-mix(in oklch, var(--a63-action-primary) 22%, transparent);
66
67
  --a63-choice-box-shadow: inset 0 0 5px -2px
@@ -94,11 +95,15 @@
94
95
  /* Darker phosphor ink on paper — pure brand-500 fails AA on near-white page. */
95
96
  --a63-text-primary: color-mix(in oklch, var(--a63-action-primary) 70%, black);
96
97
  --a63-text-secondary: color-mix(in oklch, var(--a63-action-primary) 52%, black);
98
+ /* Placeholders and meta: a lighter phosphor ink on paper, still AA 4.5:1. */
99
+ --a63-text-tertiary: color-mix(in oklch, var(--a63-action-primary) 80%, black);
97
100
  --a63-border-control: color-mix(
98
101
  in oklab,
99
102
  var(--a63-action-primary) 26%,
100
103
  color-mix(in oklab, var(--surface-light-5) 60%, white)
101
104
  );
105
+ /* Phosphor form-control border: 3:1 against the tinted page, panel and field fill. */
106
+ --a63-border-input: color-mix(in oklab, var(--a63-action-primary) 70%, var(--surface-light-10));
102
107
  --a63-border-subtle: color-mix(
103
108
  in oklab,
104
109
  var(--a63-action-primary) 16%,
@@ -138,6 +143,9 @@
138
143
  --a63-weather-divider-color: color-mix(in oklch, var(--a63-action-primary) 38%, transparent);
139
144
  --a63-weather-text-shadow: 0 0 10px
140
145
  color-mix(in oklch, var(--a63-action-primary) 22%, transparent);
146
+ /* A pressed toggle is reverse video: phosphor ink fill with page-coloured text. The neutral solid sits too close to the page in both modes. */
147
+ --a63-toggle-on-background: var(--a63-text-primary);
148
+ --a63-toggle-on-foreground: var(--a63-surface-page);
141
149
  }
142
150
 
143
151
  [data-a63-theme='terminal']:is(.dark, [data-a63-mode='dark']),
@@ -146,7 +154,10 @@
146
154
  --a63-text-primary: color-mix(in oklch, var(--a63-action-primary) 62%, white);
147
155
  /* Text mixes read the brand-as-text token; the primary fill is too dark here. */
148
156
  --a63-text-secondary: color-mix(in oklab, var(--a63-text-accent) 48%, var(--surface-dark-11));
157
+ /* Placeholders and meta: a dimmer phosphor than secondary, still AA 4.5:1. */
158
+ --a63-text-tertiary: color-mix(in oklab, var(--a63-text-accent) 40%, var(--surface-dark-10));
149
159
  --a63-border-control: color-mix(in oklch, var(--a63-action-primary) 42%, transparent);
160
+ --a63-border-input: color-mix(in oklch, var(--a63-text-accent) 60%, transparent);
150
161
  --a63-border-subtle: color-mix(in oklch, var(--a63-action-primary) 22%, transparent);
151
162
  --a63-surface-page: color-mix(in oklab, var(--surface-dark-1) 92%, var(--a63-action-primary));
152
163
  --a63-surface-panel: color-mix(in oklab, var(--surface-dark-2) 92%, var(--a63-action-primary));
@@ -169,4 +180,6 @@
169
180
  --a63-weather-muted-foreground: color-mix(in oklch, var(--a63-text-accent) 54%, white 46%);
170
181
  --a63-weather-divider-color: color-mix(in oklch, var(--a63-action-primary) 36%, transparent);
171
182
  --a63-weather-text-shadow: 0 0 8px color-mix(in oklch, var(--a63-action-primary) 38%, transparent);
183
+ --a63-toggle-on-background: var(--a63-text-primary);
184
+ --a63-toggle-on-foreground: var(--a63-surface-page);
172
185
  }
@@ -111,6 +111,12 @@
111
111
  },
112
112
  "$description": "Terminal surfaces/overlays get a faint CRT scanline texture. Square look\n comes from the radius personalization axis, not hardcoded radii here."
113
113
  }
114
+ },
115
+ "raised": {
116
+ "shadow": {
117
+ "$type": "shadow",
118
+ "$value": "{a63.surface.shadow}"
119
+ }
114
120
  }
115
121
  },
116
122
  "track": {
@@ -236,6 +242,14 @@
236
242
  "$extensions": {
237
243
  "io.atom63.derive": "color-mix(in oklch, {a63.action.primary} 52%, black)"
238
244
  }
245
+ },
246
+ "tertiary": {
247
+ "$type": "color",
248
+ "$value": "{a63.action.primary}",
249
+ "$extensions": {
250
+ "io.atom63.derive": "color-mix(in oklch, {a63.action.primary} 80%, black)"
251
+ },
252
+ "$description": "Placeholders and meta: a lighter phosphor ink on paper, still AA 4.5:1."
239
253
  }
240
254
  },
241
255
  "border": {
@@ -246,6 +260,14 @@
246
260
  "io.atom63.derive": "color-mix( in oklab, {a63.action.primary} 26%, color-mix(in oklab, {surface.light.5} 60%, white) )"
247
261
  }
248
262
  },
263
+ "input": {
264
+ "$type": "color",
265
+ "$value": "{a63.action.primary}",
266
+ "$extensions": {
267
+ "io.atom63.derive": "color-mix( in oklab, {a63.action.primary} 70%, {surface.light.10} )"
268
+ },
269
+ "$description": "Phosphor form-control border: 3:1 against the tinted page, panel and field fill."
270
+ },
249
271
  "subtle": {
250
272
  "$type": "color",
251
273
  "$value": "{a63.action.primary}",
@@ -348,6 +370,19 @@
348
370
  }
349
371
  }
350
372
  }
373
+ },
374
+ "toggle": {
375
+ "on": {
376
+ "background": {
377
+ "$type": "color",
378
+ "$value": "{a63.text.primary}",
379
+ "$description": "A pressed toggle is reverse video: phosphor ink fill with page-coloured text. The neutral solid sits too close to the page in both modes."
380
+ },
381
+ "foreground": {
382
+ "$type": "color",
383
+ "$value": "{a63.surface.page}"
384
+ }
385
+ }
351
386
  }
352
387
  }
353
388
  }
@@ -378,6 +413,14 @@
378
413
  "io.atom63.derive": "color-mix(in oklab, {a63.text.accent} 48%, {surface.dark.11})"
379
414
  },
380
415
  "$description": "Text mixes read the brand-as-text token; the primary fill is too dark here."
416
+ },
417
+ "tertiary": {
418
+ "$type": "color",
419
+ "$value": "{a63.text.accent}",
420
+ "$extensions": {
421
+ "io.atom63.derive": "color-mix(in oklab, {a63.text.accent} 40%, {surface.dark.10})"
422
+ },
423
+ "$description": "Placeholders and meta: a dimmer phosphor than secondary, still AA 4.5:1."
381
424
  }
382
425
  },
383
426
  "border": {
@@ -388,6 +431,13 @@
388
431
  "io.atom63.derive": "color-mix(in oklch, {a63.action.primary} 42%, transparent)"
389
432
  }
390
433
  },
434
+ "input": {
435
+ "$type": "color",
436
+ "$value": "{a63.text.accent}",
437
+ "$extensions": {
438
+ "io.atom63.derive": "color-mix(in oklch, {a63.text.accent} 60%, transparent)"
439
+ }
440
+ },
391
441
  "subtle": {
392
442
  "$type": "color",
393
443
  "$value": "{a63.action.primary}",
@@ -487,6 +537,18 @@
487
537
  }
488
538
  }
489
539
  }
540
+ },
541
+ "toggle": {
542
+ "on": {
543
+ "background": {
544
+ "$type": "color",
545
+ "$value": "{a63.text.primary}"
546
+ },
547
+ "foreground": {
548
+ "$type": "color",
549
+ "$value": "{a63.surface.page}"
550
+ }
551
+ }
490
552
  }
491
553
  }
492
554
  }
@@ -32,6 +32,10 @@
32
32
  --a63-action-primary-text-shadow: none;
33
33
  /* The brand as text on light surfaces (semantics.css --a63-text-accent). */
34
34
  --a63-brand-text: var(--a63-brand-600);
35
+ /* The brand as a gradient for heroes and banners: ramp 500 to 700 at 135deg. Declared with the ramp so a nested brand gets its own. */
36
+ --a63-gradient-brand: linear-gradient(135deg, var(--a63-brand-500), var(--a63-brand-700));
37
+ /* A quiet brand gradient for illustration backgrounds and cards: ramp 50 to 100 at 135deg. */
38
+ --a63-gradient-brand-subtle: linear-gradient(135deg, var(--a63-brand-50), var(--a63-brand-100));
35
39
  }
36
40
 
37
41
  [data-a63-brand='b3'] {
@@ -38,6 +38,24 @@
38
38
  "$value": "{a63.brand.600}",
39
39
  "$description": "The brand as text on light surfaces (semantics.css --a63-text-accent)."
40
40
  }
41
+ },
42
+ "gradient": {
43
+ "brand": {
44
+ "$type": "color",
45
+ "$value": "{a63.brand.500}",
46
+ "$description": "The brand as a gradient for heroes and banners: ramp 500 to 700 at 135deg. Declared with the ramp so a nested brand gets its own.",
47
+ "$extensions": {
48
+ "io.atom63.derive": "linear-gradient(135deg, {a63.brand.500}, {a63.brand.700})"
49
+ }
50
+ },
51
+ "brand-subtle": {
52
+ "$type": "color",
53
+ "$value": "{a63.brand.50}",
54
+ "$description": "A quiet brand gradient for illustration backgrounds and cards: ramp 50 to 100 at 135deg.",
55
+ "$extensions": {
56
+ "io.atom63.derive": "linear-gradient(135deg, {a63.brand.50}, {a63.brand.100})"
57
+ }
58
+ }
41
59
  }
42
60
  }
43
61
  }
@@ -12,9 +12,25 @@ const modes = ['light', 'dark'] as const
12
12
  const textPairs = [
13
13
  { fg: '--a63-text-primary', bg: '--a63-surface-page', min: AA_TEXT },
14
14
  { fg: '--a63-text-secondary', bg: '--a63-surface-page', min: AA_TEXT },
15
+ // The third grey paints placeholders, meta and timestamps: on the page and the
16
+ // panel, in a field (the control fill) and in a filled field (the muted fill).
17
+ { fg: '--a63-text-tertiary', bg: '--a63-surface-page', min: AA_TEXT },
18
+ { fg: '--a63-text-tertiary', bg: '--a63-surface-panel', min: AA_TEXT },
19
+ { fg: '--a63-text-tertiary', bg: '--a63-surface-control', min: AA_TEXT },
20
+ { fg: '--a63-text-tertiary', bg: '--a63-surface-muted', min: AA_TEXT },
15
21
  { fg: '--a63-text-primary', bg: '--a63-surface-panel', min: AA_TEXT },
16
22
  { fg: '--a63-text-accent', bg: '--a63-surface-page', min: AA_TEXT },
17
23
  { fg: '--a63-text-accent', bg: '--a63-surface-panel', min: AA_TEXT },
24
+ { fg: '--a63-text-danger', bg: '--a63-surface-page', min: AA_TEXT },
25
+ { fg: '--a63-text-danger', bg: '--a63-surface-panel', min: AA_TEXT },
26
+ // Status text (Alert action labels, tinted badges) uses the -subtle-foreground
27
+ // step, not the 3:1 status accent.
28
+ { fg: '--a63-status-info-subtle-foreground', bg: '--a63-surface-page', min: AA_TEXT },
29
+ { fg: '--a63-status-info-subtle-foreground', bg: '--a63-surface-panel', min: AA_TEXT },
30
+ { fg: '--a63-status-success-subtle-foreground', bg: '--a63-surface-page', min: AA_TEXT },
31
+ { fg: '--a63-status-success-subtle-foreground', bg: '--a63-surface-panel', min: AA_TEXT },
32
+ { fg: '--a63-status-warning-subtle-foreground', bg: '--a63-surface-page', min: AA_TEXT },
33
+ { fg: '--a63-status-warning-subtle-foreground', bg: '--a63-surface-panel', min: AA_TEXT },
18
34
  ] as const
19
35
 
20
36
  const actionPairs = [
@@ -22,6 +38,13 @@ const actionPairs = [
22
38
  { fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
23
39
  { fg: '--a63-action-neutral-foreground', bg: '--a63-action-neutral', min: AA_UI },
24
40
  { fg: '--a63-action-danger-foreground', bg: '--a63-action-danger', min: AA_UI },
41
+ // A pressed toggle carries its state in its fill (WCAG 1.4.11), so the fill
42
+ // reaches 3:1 against the page and the panel, and its label stays legible.
43
+ { fg: '--a63-toggle-on-background', bg: '--a63-surface-page', min: AA_UI },
44
+ { fg: '--a63-toggle-on-background', bg: '--a63-surface-panel', min: AA_UI },
45
+ { fg: '--a63-toggle-on-foreground', bg: '--a63-toggle-on-background', min: AA_TEXT },
46
+ // WCAG exempts disabled controls from 4.5:1, but the muted label stays legible.
47
+ { fg: '--a63-action-disabled-foreground', bg: '--a63-action-disabled-background', min: 2.5 },
25
48
  ] as const
26
49
 
27
50
  // Status accents paint icons and borders (alerts, copy check, load more), so
@@ -30,6 +53,7 @@ const statusPairs = [
30
53
  { fg: '--a63-status-info', bg: '--a63-surface-page', min: AA_UI },
31
54
  { fg: '--a63-status-success', bg: '--a63-surface-page', min: AA_UI },
32
55
  { fg: '--a63-status-warning', bg: '--a63-surface-page', min: AA_UI },
56
+ { fg: '--a63-status-danger', bg: '--a63-surface-page', min: AA_UI },
33
57
  ] as const
34
58
 
35
59
  const pairs = [...textPairs, ...actionPairs, ...statusPairs] as const
@@ -94,14 +118,18 @@ function contrastRatio(fg: Rgb, bg: Rgb): number {
94
118
  return (lighter + 0.05) / (darker + 0.05)
95
119
  }
96
120
 
97
- function resolvePaintedColor(cssVar: string, as: 'color' | 'background'): string {
121
+ function resolvePaintedColor(
122
+ cssVar: string,
123
+ as: 'color' | 'background',
124
+ parent: HTMLElement = document.body
125
+ ): string {
98
126
  const probe = document.createElement('div')
99
127
  if (as === 'color') {
100
128
  probe.style.color = `var(${cssVar})`
101
129
  } else {
102
130
  probe.style.backgroundColor = `var(${cssVar})`
103
131
  }
104
- document.body.appendChild(probe)
132
+ parent.appendChild(probe)
105
133
  const style = getComputedStyle(probe)
106
134
  const value = as === 'color' ? style.color : style.backgroundColor
107
135
  probe.remove()
@@ -148,17 +176,56 @@ describe('core semantic contrast (WCAG AA)', () => {
148
176
 
149
177
  expect(failures, failures.join('\n')).toEqual([])
150
178
  })
179
+
180
+ /* A custom property resolves its var() reads on the element that declares it,
181
+ and descendants inherit the result. A UIProvider sets theme and mode on a
182
+ nested element, so a token declared only on :root would keep the root's
183
+ mode there. Resolve every pair inside such a scope, under a light root. */
184
+ it('holds the same pairs inside a nested theme and mode scope', () => {
185
+ const failures: string[] = []
186
+
187
+ for (const theme of themes) {
188
+ for (const mode of modes) {
189
+ const scope = document.createElement('div')
190
+ scope.setAttribute('data-a63-theme', theme)
191
+ scope.setAttribute('data-a63-mode', mode)
192
+ document.body.replaceChildren(scope)
193
+
194
+ for (const { fg, bg, min } of pairs) {
195
+ const fgCss = resolvePaintedColor(fg, 'color', scope)
196
+ const bgCss = resolvePaintedColor(bg, 'background', scope)
197
+ const ratio = contrastRatio(parseCssColor(fgCss), parseCssColor(bgCss))
198
+ if (ratio < min) {
199
+ failures.push(
200
+ `${theme}/${mode} (nested) ${fg} on ${bg}: ${ratio.toFixed(2)}:1 < ${min}:1`
201
+ )
202
+ }
203
+ }
204
+ }
205
+ }
206
+
207
+ expect(failures, failures.join('\n')).toEqual([])
208
+ })
151
209
  })
152
210
 
153
211
  const brands = ['b1', 'b2', 'b3', 'b4', 'b5', 'b6'] as const
154
212
  const brandPairs = [
155
213
  { fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
214
+ // On-media labels in the dark zone of --a63-gradient-brand-fade: its lightest
215
+ // color there is brand 700, the stop at the end of the zone.
216
+ { fg: '--a63-on-media-foreground', bg: '--a63-brand-800', min: AA_TEXT },
217
+ { fg: '--a63-on-media-foreground', bg: '--a63-brand-700', min: AA_TEXT },
156
218
  { fg: '--a63-text-accent', bg: '--a63-surface-page', min: AA_TEXT },
157
219
  // WCAG 1.4.11: a focus ring is the graphic that shows focus, so it reaches 3:1
158
220
  // against the field it surrounds and the page around it.
159
221
  { fg: '--a63-focus-ring', bg: '--a63-surface-page', min: AA_UI },
160
222
  { fg: '--a63-focus-ring', bg: '--a63-surface-panel', min: AA_UI },
161
223
  { fg: '--a63-focus-ring', bg: '--a63-surface-control', min: AA_UI },
224
+ // WCAG 1.4.11: a form control's border is how a person finds the control, so it
225
+ // reaches 3:1 against the page, the panel and the field fill.
226
+ { fg: '--a63-border-input', bg: '--a63-surface-page', min: AA_UI },
227
+ { fg: '--a63-border-input', bg: '--a63-surface-panel', min: AA_UI },
228
+ { fg: '--a63-border-input', bg: '--a63-surface-control', min: AA_UI },
162
229
  ] as const
163
230
 
164
231
  describe('brand contrast (WCAG AA)', () => {
@@ -189,27 +256,34 @@ describe('brand contrast (WCAG AA)', () => {
189
256
 
190
257
  it('keeps a selected item readable on every brand ramp', () => {
191
258
  const failures: string[] = []
259
+ // The neutral selection (the default) and the opt-in accent selection.
260
+ const pairs = [
261
+ ['selected', '--a63-selected-background', '--a63-selected-foreground'],
262
+ ['selected-accent', '--a63-selected-accent-background', '--a63-selected-accent-foreground'],
263
+ ] as const
192
264
  for (const brand of brands) {
193
265
  root().setAttribute('data-a63-brand', brand)
194
266
  for (const theme of themes) {
195
267
  for (const mode of modes) {
196
268
  applyThemeMode(theme, mode)
197
- // The selected wash is translucent: paint it over the page first.
198
- const page = parseCssColor(resolvePaintedColor('--a63-surface-page', 'background'))
199
- const washCss = resolvePaintedColor('--a63-selected-background', 'background')
200
- const wash = parseCssColor(washCss)
201
- const fill: Rgb = {
202
- r: wash.r * wash.a + page.r * (1 - wash.a),
203
- g: wash.g * wash.a + page.g * (1 - wash.a),
204
- b: wash.b * wash.a + page.b * (1 - wash.a),
205
- a: 1,
206
- }
207
- const fgCss = resolvePaintedColor('--a63-selected-foreground', 'color')
208
- const ratio = contrastRatio(parseCssColor(fgCss), fill)
209
- if (ratio < AA_TEXT) {
210
- failures.push(
211
- `${brand} ${theme}/${mode} selected: ${ratio.toFixed(2)}:1 < ${AA_TEXT}:1 (fg=${fgCss}, bg=${washCss})`
212
- )
269
+ for (const [label, bgVar, fgVar] of pairs) {
270
+ // A selection wash may be translucent: paint it over the page first.
271
+ const page = parseCssColor(resolvePaintedColor('--a63-surface-page', 'background'))
272
+ const washCss = resolvePaintedColor(bgVar, 'background')
273
+ const wash = parseCssColor(washCss)
274
+ const fill: Rgb = {
275
+ r: wash.r * wash.a + page.r * (1 - wash.a),
276
+ g: wash.g * wash.a + page.g * (1 - wash.a),
277
+ b: wash.b * wash.a + page.b * (1 - wash.a),
278
+ a: 1,
279
+ }
280
+ const fgCss = resolvePaintedColor(fgVar, 'color')
281
+ const ratio = contrastRatio(parseCssColor(fgCss), fill)
282
+ if (ratio < AA_TEXT) {
283
+ failures.push(
284
+ `${brand} ${theme}/${mode} ${label}: ${ratio.toFixed(2)}:1 < ${AA_TEXT}:1 (fg=${fgCss}, bg=${washCss})`
285
+ )
286
+ }
213
287
  }
214
288
  }
215
289
  }
@@ -0,0 +1,167 @@
1
+ import { afterEach, describe, expect, it } from 'vitest'
2
+ import { resetRoot, root } from '../test/apply-styles'
3
+
4
+ /*
5
+ * [data-a63-density] (contracts/environment.css) sets --a63-space-unit. The
6
+ * space steps, control heights, paddings and gaps are built on it at :root, and
7
+ * a custom property that reads another resolves where it is declared, so the
8
+ * density scope declares them again. These probes check what a nested element
9
+ * renders with, on <html> and on a nested scope (UIProvider density="compact").
10
+ */
11
+
12
+ const scopes: HTMLElement[] = []
13
+
14
+ afterEach(() => {
15
+ for (const scope of scopes.splice(0)) scope.remove()
16
+ root().removeAttribute('data-a63-density')
17
+ resetRoot()
18
+ })
19
+
20
+ function scope(attributes: Record<string, string> = {}, parent: HTMLElement = document.body) {
21
+ const element = document.createElement('div')
22
+ for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value)
23
+ parent.appendChild(element)
24
+ if (parent === document.body) scopes.push(element)
25
+ return element
26
+ }
27
+
28
+ /** The px a nested element renders `height: <expression>` at. */
29
+ function height(parent: HTMLElement, expression: string): string {
30
+ const probe = document.createElement('div')
31
+ probe.style.height = expression
32
+ parent.appendChild(probe)
33
+ return getComputedStyle(probe).height
34
+ }
35
+
36
+ const token = (name: string) => `var(${name})`
37
+ /** The height a control recipe draws a size at (button.css, input.css and the rest). */
38
+ const controlHeight = (size: string) =>
39
+ `max(calc(var(--a63-control-height-${size}) * var(--a63-density-scale, 1)), var(--a63-control-min-size))`
40
+
41
+ /** What compact density renders at: the 4px unit becomes 3.5px, once. */
42
+ function expectCompact(element: HTMLElement) {
43
+ expect(height(element, token('--a63-space-unit'))).toBe('3.5px')
44
+ expect(height(element, token('--a63-space-4'))).toBe('14px')
45
+ expect(height(element, token('--a63-space-1_5'))).toBe('5.25px')
46
+ expect(height(element, token('--a63-control-height-md'))).toBe('28px')
47
+ expect(height(element, controlHeight('md'))).toBe('28px')
48
+ expect(height(element, controlHeight('lg'))).toBe('32px')
49
+ // xs is 21px, so the 24px pointer floor holds it.
50
+ expect(height(element, controlHeight('xs'))).toBe('24px')
51
+ expect(height(element, token('--a63-control-padding-inline-md'))).toBe('10.5px')
52
+ expect(height(element, token('--a63-control-gap'))).toBe('7px')
53
+ expect(height(element, token('--a63-trigger-gap'))).toBe('7px')
54
+ expect(height(element, token('--a63-row-padding-block-sm'))).toBe('11px')
55
+ expect(height(element, token('--a63-menu-item-padding-inline'))).toBe('7px')
56
+ }
57
+
58
+ function expectComfortable(element: HTMLElement) {
59
+ expect(height(element, token('--a63-space-4'))).toBe('16px')
60
+ expect(height(element, controlHeight('md'))).toBe('32px')
61
+ expect(height(element, token('--a63-control-padding-inline-md'))).toBe('12px')
62
+ expect(height(element, token('--a63-row-padding-block-sm'))).toBe('12px')
63
+ }
64
+
65
+ describe('density', () => {
66
+ it('leaves the default sizes alone', () => {
67
+ expectComfortable(scope())
68
+ })
69
+
70
+ it('compact on <html> scales spacing and control heights once', () => {
71
+ root().setAttribute('data-a63-density', 'compact')
72
+ expectCompact(scope())
73
+ })
74
+
75
+ it('compact on a nested scope scales spacing and control heights the same way', () => {
76
+ expectCompact(scope({ 'data-a63-density': 'compact' }))
77
+ // The legacy attribute name works too.
78
+ expectCompact(scope({ 'data-density': 'compact' }))
79
+ })
80
+
81
+ it('a nested comfortable scope restores the default sizes under a compact root', () => {
82
+ root().setAttribute('data-a63-density', 'compact')
83
+ expectComfortable(scope({ 'data-a63-density': 'comfortable' }))
84
+ })
85
+
86
+ it('keeps the iOS height ramp in a compact scope inside the iOS design language', () => {
87
+ const ios = scope({ 'data-a63-design-language': 'ios' })
88
+ const compact = scope({ 'data-a63-density': 'compact' }, ios)
89
+ // iOS md is 11 units: 44px, and 38.5px at the compact unit, rounded to 39px.
90
+ expect(height(ios, controlHeight('md'))).toBe('44px')
91
+ expect(height(compact, controlHeight('md'))).toBe('39px')
92
+ expect(height(compact, token('--a63-control-padding-inline-md'))).toBe('14px')
93
+ // On the same element.
94
+ const both = scope({ 'data-a63-design-language': 'ios', 'data-a63-density': 'compact' })
95
+ expect(height(both, controlHeight('md'))).toBe('39px')
96
+ })
97
+
98
+ it('keeps the phone sizes in a compact scope inside a phone screen', () => {
99
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
100
+ const compact = scope({ 'data-a63-density': 'compact' }, phone)
101
+ expect(height(compact, controlHeight('md'))).toBe('39px')
102
+ expect(height(compact, token('--a63-inset-row-min-size'))).toBe('46px')
103
+ expect(getComputedStyle(compact).getPropertyValue('--a63-control-font-size-md').trim()).toBe(
104
+ getComputedStyle(phone).getPropertyValue('--a63-control-font-size-md').trim()
105
+ )
106
+ })
107
+
108
+ it('lands every control height and row padding on whole pixels in every density', () => {
109
+ const sizes = ['xs', 'sm', 'md', 'lg', 'xl']
110
+ const tokens = [
111
+ ...sizes.map(size => token(`--a63-control-height-${size}`)),
112
+ ...sizes.map(controlHeight),
113
+ ...['xs', 'sm', 'md'].map(size => token(`--a63-row-padding-block-${size}`)),
114
+ ]
115
+ for (const density of ['compact', 'comfortable', undefined]) {
116
+ for (const scopeAttributes of [
117
+ {},
118
+ { 'data-a63-design-language': 'ios' },
119
+ { 'data-a63-form-factor': 'phone' },
120
+ ]) {
121
+ const element = scope({
122
+ ...scopeAttributes,
123
+ ...(density ? { 'data-a63-density': density } : {}),
124
+ })
125
+ for (const expression of [
126
+ ...tokens,
127
+ ...(scopeAttributes['data-a63-form-factor' as keyof typeof scopeAttributes]
128
+ ? [token('--a63-inset-row-min-size')]
129
+ : []),
130
+ ]) {
131
+ const px = Number.parseFloat(height(element, expression))
132
+ expect(
133
+ Number.isInteger(px),
134
+ `${expression} in ${density} ${JSON.stringify(scopeAttributes)}: ${px}`
135
+ ).toBe(true)
136
+ }
137
+ }
138
+ }
139
+ })
140
+
141
+ it('does not change text sizes', () => {
142
+ const compact = scope({ 'data-a63-density': 'compact' })
143
+ const probe = document.createElement('span')
144
+ probe.style.fontSize = 'var(--a63-control-font-size-md)'
145
+ compact.appendChild(probe)
146
+ expect(getComputedStyle(probe).fontSize).toBe('13px')
147
+ })
148
+ })
149
+
150
+ describe('root text', () => {
151
+ it('sets text without a size class to the body role, and keeps 1rem at 16px', () => {
152
+ const text = document.createElement('p')
153
+ document.body.appendChild(text)
154
+ expect(getComputedStyle(text).fontSize).toBe('15px')
155
+ expect(getComputedStyle(text).lineHeight).toBe('23px')
156
+ expect(getComputedStyle(document.documentElement).fontSize).toBe('16px')
157
+ text.remove()
158
+ })
159
+
160
+ it('sets the phone body role inside a phone screen', () => {
161
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
162
+ const text = document.createElement('p')
163
+ phone.appendChild(text)
164
+ expect(getComputedStyle(text).fontSize).toBe('17px')
165
+ expect(getComputedStyle(text).lineHeight).toBe('22px')
166
+ })
167
+ })