@atom63/styles 0.1.0-beta.1 → 0.1.0-beta.11
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/LICENSE +21 -0
- package/README.md +22 -13
- package/generated/atom63.figma-sync.json +23277 -0
- package/generated/atom63.tokens.json +19650 -8403
- package/generated/z-layers.d.ts +33 -0
- package/generated/z-layers.js +31 -0
- package/package.json +29 -15
- package/src/compat/a63-from-shadcn.css +281 -0
- package/src/compat/shadcn.browser.test.ts +23 -0
- package/src/compat/shadcn.css +133 -17
- package/src/contracts/action.css +4 -3
- package/src/contracts/action.native.css +11 -0
- package/src/contracts/action.tokens.json +66 -0
- package/src/contracts/badge.css +128 -58
- package/src/contracts/badge.resolver.json +454 -0
- package/src/contracts/choice.css +5 -2
- package/src/contracts/choice.native.css +9 -0
- package/src/contracts/choice.tokens.json +66 -0
- package/src/contracts/control.css +54 -57
- package/src/contracts/control.native.css +13 -0
- package/src/contracts/control.tokens.json +294 -0
- package/src/contracts/environment.css +178 -60
- package/src/contracts/environment.native.css +23 -0
- package/src/contracts/environment.resolver.json +1210 -0
- package/src/contracts/field.css +4 -2
- package/src/contracts/field.tokens.json +40 -0
- package/src/contracts/marker.css +6 -4
- package/src/contracts/marker.tokens.json +15 -0
- package/src/contracts/menu.css +25 -61
- package/src/contracts/menu.native.css +10 -0
- package/src/contracts/menu.resolver.json +122 -0
- package/src/contracts/overlay.css +11 -13
- package/src/contracts/overlay.native.css +13 -0
- package/src/contracts/overlay.tokens.json +103 -0
- package/src/contracts/segment.css +22 -68
- package/src/contracts/segment.tokens.json +19 -0
- package/src/contracts/selection.css +5 -1
- package/src/contracts/selection.tokens.json +42 -0
- package/src/contracts/skeleton.css +18 -2
- package/src/contracts/skeleton.resolver.json +62 -0
- package/src/contracts/surface.css +17 -24
- package/src/contracts/surface.native.css +17 -0
- package/src/contracts/surface.tokens.json +154 -0
- package/src/contracts/toggle.css +27 -3
- package/src/contracts/toggle.resolver.json +129 -0
- package/src/contracts/track.css +3 -1
- package/src/contracts/track.tokens.json +39 -0
- package/src/contracts/trigger.css +5 -2
- package/src/contracts/trigger.native.css +9 -0
- package/src/contracts/trigger.tokens.json +58 -0
- package/src/contracts/widget.css +76 -51
- package/src/contracts/widget.native.css +23 -0
- package/src/contracts/widget.resolver.json +1110 -0
- package/src/tailwind/roles.json +189 -0
- package/src/tailwind/theme.css +216 -24
- package/src/tailwind/utilities.css +17 -0
- package/src/themes/aqua.css +126 -89
- package/src/themes/aqua.native.css +80 -0
- package/src/themes/aqua.resolver.json +1304 -0
- package/src/themes/modern.css +10 -14
- package/src/themes/modern.native.css +16 -0
- package/src/themes/modern.resolver.json +350 -0
- package/src/themes/retro.css +22 -26
- package/src/themes/retro.native.css +16 -0
- package/src/themes/retro.resolver.json +794 -0
- package/src/themes/terminal.css +164 -41
- package/src/themes/terminal.native.css +22 -0
- package/src/themes/terminal.resolver.json +585 -0
- package/src/tokens/brand-action.css +65 -0
- package/src/tokens/brand-action.resolver.json +155 -0
- package/src/tokens/brand-ramp.css +108 -0
- package/src/tokens/brand-ramp.resolver.json +418 -0
- package/src/tokens/brand.css +6 -146
- package/src/tokens/chart-palette.browser.test.ts +188 -0
- package/src/tokens/color-mix-space.browser.test.ts +101 -0
- package/src/tokens/contrast.browser.test.ts +303 -5
- package/src/tokens/density.browser.test.ts +167 -0
- package/src/tokens/figma-parity.browser.test.ts +270 -0
- package/src/tokens/font.css +12 -0
- package/src/tokens/font.resolver.json +128 -0
- package/src/tokens/form-factor.browser.test.ts +129 -0
- package/src/tokens/foundation/effects.css +13 -13
- package/src/tokens/foundation/effects.resolver.json +433 -0
- package/src/tokens/foundation/fonts.css +11 -5
- package/src/tokens/foundation/fonts.tokens.json +45 -0
- package/src/tokens/foundation/motion.css +3 -0
- package/src/tokens/foundation/motion.tokens.json +53 -0
- package/src/tokens/foundation/palette.css +3 -0
- package/src/tokens/foundation/palette.tokens.json +1743 -0
- package/src/tokens/foundation/primitives.css +20 -43
- package/src/tokens/foundation/primitives.tokens.json +3258 -0
- package/src/tokens/foundation/radius.css +11 -9
- package/src/tokens/foundation/radius.tokens.json +108 -0
- package/src/tokens/foundation/typography.css +49 -12
- package/src/tokens/foundation/typography.native.css +21 -0
- package/src/tokens/foundation/typography.resolver.json +1008 -0
- package/src/tokens/foundation.css +0 -1
- package/src/tokens/index.css +1 -0
- package/src/tokens/motion.css +3 -1
- package/src/tokens/motion.resolver.json +135 -0
- package/src/tokens/native-values.json +38 -0
- package/src/tokens/personalization-axes.browser.test.ts +18 -3
- package/src/tokens/plate-scope.browser.test.ts +73 -0
- package/src/tokens/radius.css +12 -8
- package/src/tokens/radius.resolver.json +138 -0
- package/src/tokens/semantics.css +716 -41
- package/src/tokens/semantics.resolver.json +1639 -0
- package/src/tokens/space.css +8 -6
- package/src/tokens/space.tokens.json +78 -0
- package/src/tokens/surface.css +13 -19
- package/src/tokens/surface.resolver.json +706 -0
- package/src/tokens/swift-parity.browser.test.ts +141 -0
- package/src/tokens/type-roles.css +88 -0
- package/src/tokens/type-roles.resolver.json +419 -0
- package/src/tokens/type-scale.css +6 -0
- package/src/tokens/type-scale.resolver.json +67 -0
- package/generated/atom63.figma-tokens.json +0 -21664
- package/src/tokens/foundation/aliases.css +0 -28
- package/src/z-layers.ts +0 -40
|
@@ -12,16 +12,72 @@ 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 },
|
|
22
|
+
{ fg: '--a63-text-accent', bg: '--a63-surface-page', min: AA_TEXT },
|
|
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 },
|
|
16
34
|
] as const
|
|
17
35
|
|
|
18
36
|
const actionPairs = [
|
|
19
|
-
|
|
37
|
+
// Button labels are normal-size text, so the primary pair meets AA text, not 3:1.
|
|
38
|
+
{ fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
|
|
20
39
|
{ fg: '--a63-action-neutral-foreground', bg: '--a63-action-neutral', min: AA_UI },
|
|
21
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 },
|
|
22
48
|
] as const
|
|
23
49
|
|
|
24
|
-
|
|
50
|
+
// Status accents paint icons and borders (alerts, copy check, load more), so
|
|
51
|
+
// they meet WCAG's 3:1 for graphics against the page.
|
|
52
|
+
const statusPairs = [
|
|
53
|
+
{ fg: '--a63-status-info', bg: '--a63-surface-page', min: AA_UI },
|
|
54
|
+
{ fg: '--a63-status-success', bg: '--a63-surface-page', min: AA_UI },
|
|
55
|
+
{ fg: '--a63-status-warning', bg: '--a63-surface-page', min: AA_UI },
|
|
56
|
+
{ fg: '--a63-status-danger', bg: '--a63-surface-page', min: AA_UI },
|
|
57
|
+
// The danger accent also draws a focused invalid field's border and ring, and
|
|
58
|
+
// the error icon on a panel (LoadMoreTrigger, FeedbackState).
|
|
59
|
+
{ fg: '--a63-status-danger', bg: '--a63-surface-panel', min: AA_UI },
|
|
60
|
+
{ fg: '--a63-status-danger', bg: '--a63-surface-control', min: AA_UI },
|
|
61
|
+
] as const
|
|
62
|
+
|
|
63
|
+
// WCAG 1.4.11: an invalid control's border is how a person finds the error, so it
|
|
64
|
+
// reaches 3:1 against the page, the panel and the field fill in both modes.
|
|
65
|
+
const edgePairs = [
|
|
66
|
+
{ fg: '--a63-border-danger', bg: '--a63-surface-page', min: AA_UI },
|
|
67
|
+
{ fg: '--a63-border-danger', bg: '--a63-surface-panel', min: AA_UI },
|
|
68
|
+
{ fg: '--a63-border-danger', bg: '--a63-surface-control', min: AA_UI },
|
|
69
|
+
] as const
|
|
70
|
+
|
|
71
|
+
// Rating stars (rating.css) carry the score as graphics: an on star is filled in
|
|
72
|
+
// the warning accent, an off star is an outline in the input border colour.
|
|
73
|
+
// Both reach 3:1 against the page and the panel they sit on.
|
|
74
|
+
const ratingPairs = [
|
|
75
|
+
{ fg: '--a63-status-warning', bg: '--a63-surface-panel', min: AA_UI },
|
|
76
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-page', min: AA_UI },
|
|
77
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-panel', min: AA_UI },
|
|
78
|
+
] as const
|
|
79
|
+
|
|
80
|
+
const pairs = [...textPairs, ...actionPairs, ...statusPairs, ...edgePairs, ...ratingPairs] as const
|
|
25
81
|
|
|
26
82
|
afterEach(() => {
|
|
27
83
|
document.documentElement.removeAttribute('data-a63-theme')
|
|
@@ -83,14 +139,18 @@ function contrastRatio(fg: Rgb, bg: Rgb): number {
|
|
|
83
139
|
return (lighter + 0.05) / (darker + 0.05)
|
|
84
140
|
}
|
|
85
141
|
|
|
86
|
-
function resolvePaintedColor(
|
|
142
|
+
function resolvePaintedColor(
|
|
143
|
+
cssVar: string,
|
|
144
|
+
as: 'color' | 'background',
|
|
145
|
+
parent: HTMLElement = document.body
|
|
146
|
+
): string {
|
|
87
147
|
const probe = document.createElement('div')
|
|
88
148
|
if (as === 'color') {
|
|
89
149
|
probe.style.color = `var(${cssVar})`
|
|
90
150
|
} else {
|
|
91
151
|
probe.style.backgroundColor = `var(${cssVar})`
|
|
92
152
|
}
|
|
93
|
-
|
|
153
|
+
parent.appendChild(probe)
|
|
94
154
|
const style = getComputedStyle(probe)
|
|
95
155
|
const value = as === 'color' ? style.color : style.backgroundColor
|
|
96
156
|
probe.remove()
|
|
@@ -105,7 +165,7 @@ function applyThemeMode(theme: (typeof themes)[number], mode: (typeof modes)[num
|
|
|
105
165
|
}
|
|
106
166
|
|
|
107
167
|
describe('core semantic contrast (WCAG AA)', () => {
|
|
108
|
-
it('meets AA text 4.5:1 on surfaces and
|
|
168
|
+
it('meets AA text 4.5:1 on surfaces and the primary fill, and 3:1 on other action fills', () => {
|
|
109
169
|
const failures: string[] = []
|
|
110
170
|
|
|
111
171
|
for (const theme of themes) {
|
|
@@ -137,4 +197,242 @@ describe('core semantic contrast (WCAG AA)', () => {
|
|
|
137
197
|
|
|
138
198
|
expect(failures, failures.join('\n')).toEqual([])
|
|
139
199
|
})
|
|
200
|
+
|
|
201
|
+
/* A custom property resolves its var() reads on the element that declares it,
|
|
202
|
+
and descendants inherit the result. A UIProvider sets theme and mode on a
|
|
203
|
+
nested element, so a token declared only on :root would keep the root's
|
|
204
|
+
mode there. Resolve every pair inside such a scope, under a light root. */
|
|
205
|
+
it('holds the same pairs inside a nested theme and mode scope', () => {
|
|
206
|
+
const failures: string[] = []
|
|
207
|
+
|
|
208
|
+
for (const theme of themes) {
|
|
209
|
+
for (const mode of modes) {
|
|
210
|
+
const scope = document.createElement('div')
|
|
211
|
+
scope.setAttribute('data-a63-theme', theme)
|
|
212
|
+
scope.setAttribute('data-a63-mode', mode)
|
|
213
|
+
document.body.replaceChildren(scope)
|
|
214
|
+
|
|
215
|
+
for (const { fg, bg, min } of pairs) {
|
|
216
|
+
const fgCss = resolvePaintedColor(fg, 'color', scope)
|
|
217
|
+
const bgCss = resolvePaintedColor(bg, 'background', scope)
|
|
218
|
+
const ratio = contrastRatio(parseCssColor(fgCss), parseCssColor(bgCss))
|
|
219
|
+
if (ratio < min) {
|
|
220
|
+
failures.push(
|
|
221
|
+
`${theme}/${mode} (nested) ${fg} on ${bg}: ${ratio.toFixed(2)}:1 < ${min}:1`
|
|
222
|
+
)
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
expect(failures, failures.join('\n')).toEqual([])
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
const brands = ['b1', 'b2', 'b3', 'b4', 'b5', 'b6'] as const
|
|
233
|
+
const brandPairs = [
|
|
234
|
+
{ fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
|
|
235
|
+
// On-media labels in the dark zone of --a63-gradient-brand-fade: its lightest
|
|
236
|
+
// color there is brand 700, the stop at the end of the zone.
|
|
237
|
+
{ fg: '--a63-on-media-foreground', bg: '--a63-brand-800', min: AA_TEXT },
|
|
238
|
+
{ fg: '--a63-on-media-foreground', bg: '--a63-brand-700', min: AA_TEXT },
|
|
239
|
+
{ fg: '--a63-text-accent', bg: '--a63-surface-page', min: AA_TEXT },
|
|
240
|
+
// WCAG 1.4.11: a focus ring is the graphic that shows focus, so it reaches 3:1
|
|
241
|
+
// against the field it surrounds and the page around it.
|
|
242
|
+
{ fg: '--a63-focus-ring', bg: '--a63-surface-page', min: AA_UI },
|
|
243
|
+
{ fg: '--a63-focus-ring', bg: '--a63-surface-panel', min: AA_UI },
|
|
244
|
+
{ fg: '--a63-focus-ring', bg: '--a63-surface-control', min: AA_UI },
|
|
245
|
+
// WCAG 1.4.11: a form control's border is how a person finds the control, so it
|
|
246
|
+
// reaches 3:1 against the page, the panel and the field fill.
|
|
247
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-page', min: AA_UI },
|
|
248
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-panel', min: AA_UI },
|
|
249
|
+
{ fg: '--a63-border-input', bg: '--a63-surface-control', min: AA_UI },
|
|
250
|
+
] as const
|
|
251
|
+
|
|
252
|
+
describe('brand contrast (WCAG AA)', () => {
|
|
253
|
+
afterEach(() => root().removeAttribute('data-a63-brand'))
|
|
254
|
+
|
|
255
|
+
it('keeps the primary action and brand text readable on every brand ramp', () => {
|
|
256
|
+
const failures: string[] = []
|
|
257
|
+
for (const brand of brands) {
|
|
258
|
+
root().setAttribute('data-a63-brand', brand)
|
|
259
|
+
for (const theme of themes) {
|
|
260
|
+
for (const mode of modes) {
|
|
261
|
+
applyThemeMode(theme, mode)
|
|
262
|
+
for (const { fg, bg, min } of brandPairs) {
|
|
263
|
+
const fgCss = resolvePaintedColor(fg, 'color')
|
|
264
|
+
const bgCss = resolvePaintedColor(bg, 'background')
|
|
265
|
+
const ratio = contrastRatio(parseCssColor(fgCss), parseCssColor(bgCss))
|
|
266
|
+
if (ratio < min) {
|
|
267
|
+
failures.push(
|
|
268
|
+
`${brand} ${theme}/${mode} ${fg} on ${bg}: ${ratio.toFixed(2)}:1 < ${min}:1 (fg=${fgCss}, bg=${bgCss})`
|
|
269
|
+
)
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
expect(failures, failures.join('\n')).toEqual([])
|
|
276
|
+
})
|
|
277
|
+
|
|
278
|
+
it('keeps a selected item readable on every brand ramp', () => {
|
|
279
|
+
const failures: string[] = []
|
|
280
|
+
// The neutral selection (the default) and the opt-in accent selection.
|
|
281
|
+
const pairs = [
|
|
282
|
+
['selected', '--a63-selected-background', '--a63-selected-foreground'],
|
|
283
|
+
['selected-accent', '--a63-selected-accent-background', '--a63-selected-accent-foreground'],
|
|
284
|
+
] as const
|
|
285
|
+
for (const brand of brands) {
|
|
286
|
+
root().setAttribute('data-a63-brand', brand)
|
|
287
|
+
for (const theme of themes) {
|
|
288
|
+
for (const mode of modes) {
|
|
289
|
+
applyThemeMode(theme, mode)
|
|
290
|
+
for (const [label, bgVar, fgVar] of pairs) {
|
|
291
|
+
// A selection wash may be translucent: paint it over the page first.
|
|
292
|
+
const page = parseCssColor(resolvePaintedColor('--a63-surface-page', 'background'))
|
|
293
|
+
const washCss = resolvePaintedColor(bgVar, 'background')
|
|
294
|
+
const wash = parseCssColor(washCss)
|
|
295
|
+
const fill: Rgb = {
|
|
296
|
+
r: wash.r * wash.a + page.r * (1 - wash.a),
|
|
297
|
+
g: wash.g * wash.a + page.g * (1 - wash.a),
|
|
298
|
+
b: wash.b * wash.a + page.b * (1 - wash.a),
|
|
299
|
+
a: 1,
|
|
300
|
+
}
|
|
301
|
+
const fgCss = resolvePaintedColor(fgVar, 'color')
|
|
302
|
+
const ratio = contrastRatio(parseCssColor(fgCss), fill)
|
|
303
|
+
if (ratio < AA_TEXT) {
|
|
304
|
+
failures.push(
|
|
305
|
+
`${brand} ${theme}/${mode} ${label}: ${ratio.toFixed(2)}:1 < ${AA_TEXT}:1 (fg=${fgCss}, bg=${washCss})`
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
expect(failures, failures.join('\n')).toEqual([])
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
/* A UIProvider that passes only `brand` or only `surface` stamps that one
|
|
317
|
+
attribute, under a mode set further up. Every role that reads the brand ramp or
|
|
318
|
+
the neutral ramp must resolve there as it does on a scope that also sets the
|
|
319
|
+
mode, and keep its contrast. */
|
|
320
|
+
const scopedRoles = [
|
|
321
|
+
'--a63-text-accent',
|
|
322
|
+
'--a63-focus-ring',
|
|
323
|
+
'--a63-selected-accent-background',
|
|
324
|
+
'--a63-choice-card-checked-border',
|
|
325
|
+
'--a63-choice-card-checked-background',
|
|
326
|
+
'--a63-surface-page',
|
|
327
|
+
'--a63-surface-panel',
|
|
328
|
+
'--a63-surface-control',
|
|
329
|
+
'--a63-text-primary',
|
|
330
|
+
'--a63-text-secondary',
|
|
331
|
+
'--a63-border-subtle',
|
|
332
|
+
'--a63-border-input',
|
|
333
|
+
] as const
|
|
334
|
+
const nestedAxes = [
|
|
335
|
+
['data-a63-brand', 'b3'],
|
|
336
|
+
['data-a63-surface', 'n3'],
|
|
337
|
+
] as const
|
|
338
|
+
|
|
339
|
+
describe('nested brand-only and surface-only scopes', () => {
|
|
340
|
+
it('resolve the brand and neutral roles as a scope that also sets the mode', () => {
|
|
341
|
+
const failures: string[] = []
|
|
342
|
+
for (const theme of themes) {
|
|
343
|
+
for (const mode of modes) {
|
|
344
|
+
applyThemeMode(theme, mode)
|
|
345
|
+
for (const [attribute, value] of nestedAxes) {
|
|
346
|
+
const nested = document.createElement('div')
|
|
347
|
+
nested.setAttribute(attribute, value)
|
|
348
|
+
const reference = document.createElement('div')
|
|
349
|
+
reference.setAttribute(attribute, value)
|
|
350
|
+
reference.setAttribute('data-a63-theme', theme)
|
|
351
|
+
reference.setAttribute('data-a63-mode', mode)
|
|
352
|
+
document.body.replaceChildren(nested, reference)
|
|
353
|
+
for (const role of scopedRoles) {
|
|
354
|
+
const got = resolvePaintedColor(role, 'color', nested)
|
|
355
|
+
const want = resolvePaintedColor(role, 'color', reference)
|
|
356
|
+
if (got !== want) {
|
|
357
|
+
failures.push(
|
|
358
|
+
`${theme}/${mode} [${attribute}=${value}] ${role}: ${got}, want ${want}`
|
|
359
|
+
)
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
expect(failures, failures.join('\n')).toEqual([])
|
|
366
|
+
})
|
|
367
|
+
|
|
368
|
+
it('hold the core pairs inside a nested brand-only and surface-only scope', () => {
|
|
369
|
+
const failures: string[] = []
|
|
370
|
+
for (const theme of themes) {
|
|
371
|
+
for (const mode of modes) {
|
|
372
|
+
applyThemeMode(theme, mode)
|
|
373
|
+
for (const [attribute, value] of nestedAxes) {
|
|
374
|
+
const scope = document.createElement('div')
|
|
375
|
+
scope.setAttribute(attribute, value)
|
|
376
|
+
document.body.replaceChildren(scope)
|
|
377
|
+
for (const { fg, bg, min } of [...pairs, ...brandPairs]) {
|
|
378
|
+
const fgCss = resolvePaintedColor(fg, 'color', scope)
|
|
379
|
+
const bgCss = resolvePaintedColor(bg, 'background', scope)
|
|
380
|
+
const ratio = contrastRatio(parseCssColor(fgCss), parseCssColor(bgCss))
|
|
381
|
+
if (ratio < min) {
|
|
382
|
+
failures.push(
|
|
383
|
+
`${theme}/${mode} [${attribute}=${value}] ${fg} on ${bg}: ${ratio.toFixed(2)}:1 < ${min}:1`
|
|
384
|
+
)
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
expect(failures, failures.join('\n')).toEqual([])
|
|
391
|
+
})
|
|
392
|
+
})
|
|
393
|
+
|
|
394
|
+
/* The surface-tint slider (0-100%) bends the page, panel and muted surfaces toward
|
|
395
|
+
the brand. The second and third text greys keep 4.5:1 on all three at every
|
|
396
|
+
tint, on every brand, theme and mode. */
|
|
397
|
+
const tints = ['0%', '50%', '100%'] as const
|
|
398
|
+
const tintTextPairs = [
|
|
399
|
+
['--a63-text-secondary', '--a63-surface-page'],
|
|
400
|
+
['--a63-text-secondary', '--a63-surface-panel'],
|
|
401
|
+
['--a63-text-secondary', '--a63-surface-muted'],
|
|
402
|
+
['--a63-text-tertiary', '--a63-surface-page'],
|
|
403
|
+
['--a63-text-tertiary', '--a63-surface-panel'],
|
|
404
|
+
['--a63-text-tertiary', '--a63-surface-muted'],
|
|
405
|
+
] as const
|
|
406
|
+
|
|
407
|
+
describe('surface tint contrast (WCAG AA)', () => {
|
|
408
|
+
afterEach(() => {
|
|
409
|
+
root().removeAttribute('data-a63-brand')
|
|
410
|
+
root().style.removeProperty('--a63-surface-tint')
|
|
411
|
+
})
|
|
412
|
+
|
|
413
|
+
it('keeps the secondary and tertiary text at 4.5:1 on tinted surfaces', () => {
|
|
414
|
+
const failures: string[] = []
|
|
415
|
+
for (const tint of tints) {
|
|
416
|
+
root().style.setProperty('--a63-surface-tint', tint)
|
|
417
|
+
for (const brand of brands) {
|
|
418
|
+
root().setAttribute('data-a63-brand', brand)
|
|
419
|
+
for (const theme of themes) {
|
|
420
|
+
for (const mode of modes) {
|
|
421
|
+
applyThemeMode(theme, mode)
|
|
422
|
+
for (const [fg, bg] of tintTextPairs) {
|
|
423
|
+
const fgCss = resolvePaintedColor(fg, 'color')
|
|
424
|
+
const bgCss = resolvePaintedColor(bg, 'background')
|
|
425
|
+
const ratio = contrastRatio(parseCssColor(fgCss), parseCssColor(bgCss))
|
|
426
|
+
if (ratio < AA_TEXT) {
|
|
427
|
+
failures.push(
|
|
428
|
+
`tint ${tint} ${brand} ${theme}/${mode} ${fg} on ${bg}: ${ratio.toFixed(2)}:1 < ${AA_TEXT}:1`
|
|
429
|
+
)
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
expect(failures, failures.join('\n')).toEqual([])
|
|
437
|
+
})
|
|
140
438
|
})
|
|
@@ -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
|
+
})
|