@atom63/styles 0.1.0-beta.6 → 0.1.0-beta.8
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.
- package/README.md +7 -4
- package/generated/atom63.figma-sync.json +10559 -5138
- package/generated/atom63.tokens.json +13034 -7792
- package/package.json +6 -4
- package/src/compat/a63-from-shadcn.css +5 -1
- package/src/compat/shadcn.browser.test.ts +23 -0
- package/src/compat/shadcn.css +133 -17
- package/src/contracts/badge.css +81 -65
- package/src/contracts/badge.resolver.json +145 -62
- package/src/contracts/choice.css +1 -1
- package/src/contracts/choice.tokens.json +1 -1
- package/src/contracts/control.css +14 -8
- package/src/contracts/control.tokens.json +57 -8
- package/src/contracts/environment.css +134 -12
- package/src/contracts/environment.resolver.json +664 -23
- package/src/contracts/field.css +1 -1
- package/src/contracts/field.tokens.json +1 -1
- package/src/contracts/selection.css +2 -0
- package/src/contracts/selection.tokens.json +5 -0
- package/src/contracts/surface.css +4 -0
- package/src/contracts/surface.tokens.json +57 -0
- package/src/tailwind/roles.json +189 -0
- package/src/tailwind/theme.css +210 -22
- package/src/tailwind/utilities.css +17 -0
- package/src/themes/aqua.css +1 -0
- package/src/themes/aqua.resolver.json +6 -0
- package/src/themes/retro.css +1 -0
- package/src/themes/retro.resolver.json +6 -0
- package/src/themes/terminal.css +8 -0
- package/src/themes/terminal.resolver.json +37 -0
- package/src/tokens/brand-action.css +16 -1
- package/src/tokens/brand-action.resolver.json +42 -5
- package/src/tokens/contrast.browser.test.ts +59 -0
- package/src/tokens/density.browser.test.ts +167 -0
- package/src/tokens/figma-parity.browser.test.ts +27 -14
- package/src/tokens/form-factor.browser.test.ts +129 -0
- package/src/tokens/foundation/primitives.css +0 -30
- package/src/tokens/foundation/primitives.tokens.json +0 -212
- package/src/tokens/foundation/radius.css +5 -0
- package/src/tokens/foundation/radius.tokens.json +8 -0
- package/src/tokens/foundation/typography.css +24 -0
- package/src/tokens/foundation/typography.native.css +12 -2
- package/src/tokens/foundation/typography.resolver.json +72 -0
- package/src/tokens/index.css +1 -0
- package/src/tokens/personalization-axes.browser.test.ts +13 -0
- package/src/tokens/semantics.css +251 -4
- package/src/tokens/semantics.resolver.json +1148 -12
- package/src/tokens/surface.css +8 -0
- package/src/tokens/surface.resolver.json +49 -0
- package/src/tokens/swift-parity.browser.test.ts +4 -0
- package/src/tokens/type-roles.css +75 -0
- package/src/tokens/type-roles.resolver.json +366 -0
package/src/themes/terminal.css
CHANGED
|
@@ -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%,
|
|
@@ -146,7 +151,10 @@
|
|
|
146
151
|
--a63-text-primary: color-mix(in oklch, var(--a63-action-primary) 62%, white);
|
|
147
152
|
/* Text mixes read the brand-as-text token; the primary fill is too dark here. */
|
|
148
153
|
--a63-text-secondary: color-mix(in oklab, var(--a63-text-accent) 48%, var(--surface-dark-11));
|
|
154
|
+
/* Placeholders and meta: a dimmer phosphor than secondary, still AA 4.5:1. */
|
|
155
|
+
--a63-text-tertiary: color-mix(in oklab, var(--a63-text-accent) 40%, var(--surface-dark-10));
|
|
149
156
|
--a63-border-control: color-mix(in oklch, var(--a63-action-primary) 42%, transparent);
|
|
157
|
+
--a63-border-input: color-mix(in oklch, var(--a63-text-accent) 60%, transparent);
|
|
150
158
|
--a63-border-subtle: color-mix(in oklch, var(--a63-action-primary) 22%, transparent);
|
|
151
159
|
--a63-surface-page: color-mix(in oklab, var(--surface-dark-1) 92%, var(--a63-action-primary));
|
|
152
160
|
--a63-surface-panel: color-mix(in oklab, var(--surface-dark-2) 92%, var(--a63-action-primary));
|
|
@@ -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}",
|
|
@@ -378,6 +400,14 @@
|
|
|
378
400
|
"io.atom63.derive": "color-mix(in oklab, {a63.text.accent} 48%, {surface.dark.11})"
|
|
379
401
|
},
|
|
380
402
|
"$description": "Text mixes read the brand-as-text token; the primary fill is too dark here."
|
|
403
|
+
},
|
|
404
|
+
"tertiary": {
|
|
405
|
+
"$type": "color",
|
|
406
|
+
"$value": "{a63.text.accent}",
|
|
407
|
+
"$extensions": {
|
|
408
|
+
"io.atom63.derive": "color-mix(in oklab, {a63.text.accent} 40%, {surface.dark.10})"
|
|
409
|
+
},
|
|
410
|
+
"$description": "Placeholders and meta: a dimmer phosphor than secondary, still AA 4.5:1."
|
|
381
411
|
}
|
|
382
412
|
},
|
|
383
413
|
"border": {
|
|
@@ -388,6 +418,13 @@
|
|
|
388
418
|
"io.atom63.derive": "color-mix(in oklch, {a63.action.primary} 42%, transparent)"
|
|
389
419
|
}
|
|
390
420
|
},
|
|
421
|
+
"input": {
|
|
422
|
+
"$type": "color",
|
|
423
|
+
"$value": "{a63.text.accent}",
|
|
424
|
+
"$extensions": {
|
|
425
|
+
"io.atom63.derive": "color-mix(in oklch, {a63.text.accent} 60%, transparent)"
|
|
426
|
+
}
|
|
427
|
+
},
|
|
391
428
|
"subtle": {
|
|
392
429
|
"$type": "color",
|
|
393
430
|
"$value": "{a63.action.primary}",
|
|
@@ -32,7 +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
|
-
|
|
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));
|
|
36
39
|
}
|
|
37
40
|
|
|
38
41
|
[data-a63-brand='b3'] {
|
|
@@ -48,3 +51,15 @@
|
|
|
48
51
|
text on the lightly tinted Aqua page is just under 4.5:1. */
|
|
49
52
|
--a63-brand-text: var(--a63-brand-700);
|
|
50
53
|
}
|
|
54
|
+
|
|
55
|
+
[data-a63-brand='b4'] {
|
|
56
|
+
/* Pink (b4) keeps 600 for fills, but its 600 as text on the selected wash over
|
|
57
|
+
the Aqua page sits at 4.5:1 exactly. */
|
|
58
|
+
--a63-brand-text: var(--a63-brand-700);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
[data-a63-brand='b6'] {
|
|
62
|
+
/* Red (b6) keeps 600 for fills, but its 600 as text on the selected wash is
|
|
63
|
+
about 4.1–4.5:1 in light mode. */
|
|
64
|
+
--a63-brand-text: var(--a63-brand-700);
|
|
65
|
+
}
|
|
@@ -39,11 +39,22 @@
|
|
|
39
39
|
"$description": "The brand as text on light surfaces (semantics.css --a63-text-accent)."
|
|
40
40
|
}
|
|
41
41
|
},
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
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
|
+
}
|
|
47
58
|
}
|
|
48
59
|
}
|
|
49
60
|
}
|
|
@@ -98,6 +109,32 @@
|
|
|
98
109
|
}
|
|
99
110
|
}
|
|
100
111
|
}
|
|
112
|
+
],
|
|
113
|
+
"b4": [
|
|
114
|
+
{
|
|
115
|
+
"a63": {
|
|
116
|
+
"brand": {
|
|
117
|
+
"text": {
|
|
118
|
+
"$type": "color",
|
|
119
|
+
"$value": "{a63.brand.700}",
|
|
120
|
+
"$description": "Pink (b4) keeps 600 for fills, but its 600 as text on the selected wash over\nthe Aqua page sits at 4.5:1 exactly."
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
],
|
|
126
|
+
"b6": [
|
|
127
|
+
{
|
|
128
|
+
"a63": {
|
|
129
|
+
"brand": {
|
|
130
|
+
"text": {
|
|
131
|
+
"$type": "color",
|
|
132
|
+
"$value": "{a63.brand.700}",
|
|
133
|
+
"$description": "Red (b6) keeps 600 for fills, but its 600 as text on the selected wash is\nabout 4.1–4.5:1 in light mode."
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
}
|
|
101
138
|
]
|
|
102
139
|
}
|
|
103
140
|
}
|
|
@@ -12,6 +12,12 @@ 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 },
|
|
@@ -22,6 +28,8 @@ const actionPairs = [
|
|
|
22
28
|
{ fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
|
|
23
29
|
{ fg: '--a63-action-neutral-foreground', bg: '--a63-action-neutral', min: AA_UI },
|
|
24
30
|
{ fg: '--a63-action-danger-foreground', bg: '--a63-action-danger', min: AA_UI },
|
|
31
|
+
// WCAG exempts disabled controls from 4.5:1, but the muted label stays legible.
|
|
32
|
+
{ fg: '--a63-action-disabled-foreground', bg: '--a63-action-disabled-background', min: 2.5 },
|
|
25
33
|
] as const
|
|
26
34
|
|
|
27
35
|
// Status accents paint icons and borders (alerts, copy check, load more), so
|
|
@@ -153,7 +161,21 @@ describe('core semantic contrast (WCAG AA)', () => {
|
|
|
153
161
|
const brands = ['b1', 'b2', 'b3', 'b4', 'b5', 'b6'] as const
|
|
154
162
|
const brandPairs = [
|
|
155
163
|
{ fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
|
|
164
|
+
// On-media labels in the dark zone of --a63-gradient-brand-fade: its lightest
|
|
165
|
+
// color there is brand 700, the stop at the end of the zone.
|
|
166
|
+
{ fg: '--a63-on-media-foreground', bg: '--a63-brand-800', min: AA_TEXT },
|
|
167
|
+
{ fg: '--a63-on-media-foreground', bg: '--a63-brand-700', min: AA_TEXT },
|
|
156
168
|
{ fg: '--a63-text-accent', bg: '--a63-surface-page', min: AA_TEXT },
|
|
169
|
+
// WCAG 1.4.11: a focus ring is the graphic that shows focus, so it reaches 3:1
|
|
170
|
+
// against the field it surrounds and the page around it.
|
|
171
|
+
{ fg: '--a63-focus-ring', bg: '--a63-surface-page', min: AA_UI },
|
|
172
|
+
{ fg: '--a63-focus-ring', bg: '--a63-surface-panel', min: AA_UI },
|
|
173
|
+
{ fg: '--a63-focus-ring', bg: '--a63-surface-control', min: AA_UI },
|
|
174
|
+
// WCAG 1.4.11: a form control's border is how a person finds the control, so it
|
|
175
|
+
// reaches 3:1 against the page, the panel and the field fill.
|
|
176
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-page', min: AA_UI },
|
|
177
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-panel', min: AA_UI },
|
|
178
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-control', min: AA_UI },
|
|
157
179
|
] as const
|
|
158
180
|
|
|
159
181
|
describe('brand contrast (WCAG AA)', () => {
|
|
@@ -181,4 +203,41 @@ describe('brand contrast (WCAG AA)', () => {
|
|
|
181
203
|
}
|
|
182
204
|
expect(failures, failures.join('\n')).toEqual([])
|
|
183
205
|
})
|
|
206
|
+
|
|
207
|
+
it('keeps a selected item readable on every brand ramp', () => {
|
|
208
|
+
const failures: string[] = []
|
|
209
|
+
// The neutral selection (the default) and the opt-in accent selection.
|
|
210
|
+
const pairs = [
|
|
211
|
+
['selected', '--a63-selected-background', '--a63-selected-foreground'],
|
|
212
|
+
['selected-accent', '--a63-selected-accent-background', '--a63-selected-accent-foreground'],
|
|
213
|
+
] as const
|
|
214
|
+
for (const brand of brands) {
|
|
215
|
+
root().setAttribute('data-a63-brand', brand)
|
|
216
|
+
for (const theme of themes) {
|
|
217
|
+
for (const mode of modes) {
|
|
218
|
+
applyThemeMode(theme, mode)
|
|
219
|
+
for (const [label, bgVar, fgVar] of pairs) {
|
|
220
|
+
// A selection wash may be translucent: paint it over the page first.
|
|
221
|
+
const page = parseCssColor(resolvePaintedColor('--a63-surface-page', 'background'))
|
|
222
|
+
const washCss = resolvePaintedColor(bgVar, 'background')
|
|
223
|
+
const wash = parseCssColor(washCss)
|
|
224
|
+
const fill: Rgb = {
|
|
225
|
+
r: wash.r * wash.a + page.r * (1 - wash.a),
|
|
226
|
+
g: wash.g * wash.a + page.g * (1 - wash.a),
|
|
227
|
+
b: wash.b * wash.a + page.b * (1 - wash.a),
|
|
228
|
+
a: 1,
|
|
229
|
+
}
|
|
230
|
+
const fgCss = resolvePaintedColor(fgVar, 'color')
|
|
231
|
+
const ratio = contrastRatio(parseCssColor(fgCss), fill)
|
|
232
|
+
if (ratio < AA_TEXT) {
|
|
233
|
+
failures.push(
|
|
234
|
+
`${brand} ${theme}/${mode} ${label}: ${ratio.toFixed(2)}:1 < ${AA_TEXT}:1 (fg=${fgCss}, bg=${washCss})`
|
|
235
|
+
)
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
expect(failures, failures.join('\n')).toEqual([])
|
|
242
|
+
})
|
|
184
243
|
})
|
|
@@ -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
|
+
})
|
|
@@ -20,7 +20,11 @@ import { resetRoot, root } from '../test/apply-styles'
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
type Rgba = { r: number; g: number; b: number; a: number }
|
|
23
|
-
type Value = {
|
|
23
|
+
type Value = {
|
|
24
|
+
alias?: string
|
|
25
|
+
composed?: { alias: string; opacity: number }
|
|
26
|
+
value?: Rgba | number | string
|
|
27
|
+
}
|
|
24
28
|
interface Variable {
|
|
25
29
|
name: string
|
|
26
30
|
token: string
|
|
@@ -74,27 +78,28 @@ const defaults: Context = {
|
|
|
74
78
|
|
|
75
79
|
// Which context key picks the mode of each axis collection.
|
|
76
80
|
const collectionAxis: Record<string, keyof Context> = {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
'
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
'
|
|
85
|
-
|
|
86
|
-
'
|
|
81
|
+
Mode: 'mode',
|
|
82
|
+
Brand: 'brand',
|
|
83
|
+
Surface: 'surface',
|
|
84
|
+
'Design Language': 'designLanguage',
|
|
85
|
+
Input: 'input',
|
|
86
|
+
Density: 'density',
|
|
87
|
+
Radius: 'radius',
|
|
88
|
+
'Type Scale': 'typeScale',
|
|
89
|
+
Font: 'font',
|
|
90
|
+
'Window Size': 'windowSize',
|
|
87
91
|
}
|
|
88
92
|
|
|
89
93
|
function modeOf(collection: Collection, context: Context): string {
|
|
90
|
-
if (collection.name === '
|
|
94
|
+
if (collection.name === 'Theme') return `${context.theme}-${context.mode}`
|
|
91
95
|
const axis = collectionAxis[collection.name]
|
|
92
96
|
return axis ? context[axis] : collection.modes[0]
|
|
93
97
|
}
|
|
94
98
|
|
|
95
99
|
/**
|
|
96
|
-
* The value Figma shows for a token in a context, following aliases
|
|
97
|
-
* whether the chain passed through a
|
|
100
|
+
* The value Figma shows for a token in a context, following aliases (a composed
|
|
101
|
+
* color is its alias at an opacity), and whether the chain passed through a
|
|
102
|
+
* `computed` variable.
|
|
98
103
|
*/
|
|
99
104
|
function resolveInModel(
|
|
100
105
|
token: string,
|
|
@@ -109,6 +114,14 @@ function resolveInModel(
|
|
|
109
114
|
const target = resolveInModel(entry.alias, context, [...seen, token])
|
|
110
115
|
return { ...target, approximate: target.approximate || computedTokens.has(token) }
|
|
111
116
|
}
|
|
117
|
+
if (entry?.composed) {
|
|
118
|
+
const target = resolveInModel(entry.composed.alias, context, [...seen, token])
|
|
119
|
+
const color = target.value as Rgba
|
|
120
|
+
return {
|
|
121
|
+
value: { ...color, a: (color.a * entry.composed.opacity) / 100 },
|
|
122
|
+
approximate: target.approximate || computedTokens.has(token),
|
|
123
|
+
}
|
|
124
|
+
}
|
|
112
125
|
return { value: entry?.value, approximate: computedTokens.has(token) }
|
|
113
126
|
}
|
|
114
127
|
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { resetRoot, root } from '../test/apply-styles'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* [data-a63-form-factor='phone'] (contracts/environment.css) gives a subtree
|
|
6
|
+
* the type steps and control sizing of a phone screen. Custom properties that
|
|
7
|
+
* read other custom properties resolve where they are declared, so these
|
|
8
|
+
* probes check the values a nested element actually renders with.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
const scopes: HTMLElement[] = []
|
|
12
|
+
|
|
13
|
+
afterEach(() => {
|
|
14
|
+
for (const scope of scopes.splice(0)) scope.remove()
|
|
15
|
+
resetRoot()
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
function scope(attributes: Record<string, string> = {}): HTMLElement {
|
|
19
|
+
const element = document.createElement('div')
|
|
20
|
+
for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value)
|
|
21
|
+
document.body.appendChild(element)
|
|
22
|
+
scopes.push(element)
|
|
23
|
+
return element
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The px a nested element renders `font-size: var(<name>)` at. */
|
|
27
|
+
function fontSize(parent: HTMLElement, name: string): string {
|
|
28
|
+
const probe = document.createElement('span')
|
|
29
|
+
probe.style.fontSize = `var(${name})`
|
|
30
|
+
parent.appendChild(probe)
|
|
31
|
+
return getComputedStyle(probe).fontSize
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The px a nested element renders `height: var(<name>)` at. */
|
|
35
|
+
function height(parent: HTMLElement, name: string): string {
|
|
36
|
+
const probe = document.createElement('div')
|
|
37
|
+
probe.style.height = `var(${name})`
|
|
38
|
+
parent.appendChild(probe)
|
|
39
|
+
return getComputedStyle(probe).height
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/** The px a nested element renders `width: <expression>` at. */
|
|
43
|
+
function width(parent: HTMLElement, expression: string): string {
|
|
44
|
+
const probe = document.createElement('div')
|
|
45
|
+
probe.style.width = expression
|
|
46
|
+
parent.appendChild(probe)
|
|
47
|
+
return getComputedStyle(probe).width
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
describe('phone form factor', () => {
|
|
51
|
+
it('sets the iOS text sizes on the type steps', () => {
|
|
52
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
53
|
+
expect(fontSize(phone, '--typography-base-font-size')).toBe('17px')
|
|
54
|
+
expect(fontSize(phone, '--typography-sm-font-size')).toBe('15px')
|
|
55
|
+
expect(fontSize(phone, '--typography-xs-font-size')).toBe('13px')
|
|
56
|
+
expect(fontSize(phone, '--typography-2xs-font-size')).toBe('11px')
|
|
57
|
+
expect(fontSize(phone, '--typography-6xl-font-size')).toBe('34px')
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
it('redeclares the text roles, so they follow the phone steps', () => {
|
|
61
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
62
|
+
expect(fontSize(phone, '--a63-type-body-font-size')).toBe('17px')
|
|
63
|
+
expect(fontSize(phone, '--a63-type-headline-font-size')).toBe('17px')
|
|
64
|
+
expect(fontSize(phone, '--a63-type-subhead-font-size')).toBe('15px')
|
|
65
|
+
expect(fontSize(phone, '--a63-type-footnote-font-size')).toBe('13px')
|
|
66
|
+
expect(fontSize(phone, '--a63-type-title-2-font-size')).toBe('22px')
|
|
67
|
+
expect(fontSize(phone, '--a63-type-large-title-font-size')).toBe('34px')
|
|
68
|
+
expect(fontSize(phone, '--a63-type-display-font-size')).toBe('40px')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('sets control labels at body size and the iOS height ramp', () => {
|
|
72
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
73
|
+
expect(fontSize(phone, '--a63-control-font-size-xs')).toBe('13px')
|
|
74
|
+
expect(fontSize(phone, '--a63-control-font-size-sm')).toBe('17px')
|
|
75
|
+
expect(fontSize(phone, '--a63-control-font-size-md')).toBe('17px')
|
|
76
|
+
expect(height(phone, '--a63-control-height-sm')).toBe('40px')
|
|
77
|
+
expect(height(phone, '--a63-control-height-md')).toBe('44px')
|
|
78
|
+
})
|
|
79
|
+
|
|
80
|
+
it('keeps a secondary line below its title: subheadline size on a phone, sm elsewhere', () => {
|
|
81
|
+
const secondary = '--a63-control-font-size-secondary, var(--a63-control-font-size-sm)'
|
|
82
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
83
|
+
expect(fontSize(phone, secondary)).toBe('15px')
|
|
84
|
+
expect(fontSize(phone, '--a63-control-font-size-sm')).toBe('17px')
|
|
85
|
+
expect(fontSize(scope(), secondary)).toBe('12px')
|
|
86
|
+
})
|
|
87
|
+
|
|
88
|
+
it('gives the switch the iOS 26 proportions: a wide pill knob on a 63 by 28 track', () => {
|
|
89
|
+
// The Switch recipe's track: thumb × (1 + aspect) + 6px wide, thumb + 6px tall.
|
|
90
|
+
const track = 'calc(var(--a63-switch-thumb-size) * (1 + var(--a63-switch-thumb-aspect)) + 6px)'
|
|
91
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
92
|
+
expect(height(phone, '--a63-switch-thumb-size')).toBe('22px')
|
|
93
|
+
expect(Number.parseFloat(width(phone, track))).toBeCloseTo(63.2, 1)
|
|
94
|
+
const web = scope()
|
|
95
|
+
expect(height(web, '--a63-switch-thumb-size')).toBe('16px')
|
|
96
|
+
expect(width(web, track)).toBe('38px')
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
it('gives a grouped list the iOS row height and a rounder card, on a phone only', () => {
|
|
100
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
101
|
+
expect(height(phone, '--a63-inset-row-min-size')).toBe('52px')
|
|
102
|
+
expect(height(phone, '--a63-inset-group-radius')).toBe('18px')
|
|
103
|
+
// Outside a phone neither is declared, so the Item recipe takes its fallbacks.
|
|
104
|
+
const web = getComputedStyle(scope())
|
|
105
|
+
expect(web.getPropertyValue('--a63-inset-row-min-size')).toBe('')
|
|
106
|
+
expect(web.getPropertyValue('--a63-inset-group-radius')).toBe('')
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
it('leaves the page outside the phone scope on the web sizes', () => {
|
|
110
|
+
const web = scope()
|
|
111
|
+
expect(fontSize(web, '--typography-base-font-size')).toBe('15px')
|
|
112
|
+
expect(fontSize(web, '--a63-type-body-font-size')).toBe('15px')
|
|
113
|
+
expect(fontSize(web, '--a63-control-font-size-md')).toBe('13px')
|
|
114
|
+
expect(height(web, '--a63-control-height-md')).toBe('32px')
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
it('keeps the type scale preference on top of the phone steps', () => {
|
|
118
|
+
root().setAttribute('data-a63-type-scale', 'large')
|
|
119
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
120
|
+
// 17px × 1.2
|
|
121
|
+
expect(fontSize(phone, '--a63-type-body-font-size')).toBe('20.4px')
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
it('wins over the design language on the same element', () => {
|
|
125
|
+
const phone = scope({ 'data-a63-design-language': 'ios', 'data-a63-form-factor': 'phone' })
|
|
126
|
+
expect(fontSize(phone, '--a63-control-font-size-sm')).toBe('17px')
|
|
127
|
+
expect(height(phone, '--a63-control-height-md')).toBe('44px')
|
|
128
|
+
})
|
|
129
|
+
})
|