@atom63/styles 0.1.0-beta.1 → 0.1.0-beta.10
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 +23201 -0
- package/generated/atom63.tokens.json +19625 -8406
- 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 +275 -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 +151 -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/color-mix-space.browser.test.ts +101 -0
- package/src/tokens/contrast.browser.test.ts +257 -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 +656 -39
- package/src/tokens/semantics.resolver.json +1606 -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
package/src/tokens/brand.css
CHANGED
|
@@ -1,148 +1,8 @@
|
|
|
1
1
|
/*
|
|
2
|
-
* Brand personalization axis
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* plus any soft/hover/border tints). [data-a63-brand="b1".."b6"] remaps the
|
|
7
|
-
* ENTIRE ramp to one of the six brand palettes at runtime — one switch recolors
|
|
8
|
-
* the whole primary family coherently. Only the brand ramp changes; status
|
|
9
|
-
* colors (danger, etc.) stay semantic.
|
|
10
|
-
*
|
|
11
|
-
* The base (:root, and explicit b1) is the default blue ramp, so components work
|
|
12
|
-
* with no [data-a63-brand] set. Brand is meant to be set at a root/personalization
|
|
13
|
-
* scope and inherited; a subtree can override by setting [data-a63-brand] again.
|
|
2
|
+
* Brand personalization axis. Both parts are generated from DTCG resolvers:
|
|
3
|
+
* the ramp (--a63-brand-50..950 per [data-a63-brand]) from brand-ramp.resolver.json,
|
|
4
|
+
* and the primary action derived from it from brand-action.resolver.json. This
|
|
5
|
+
* file stays the one entry point for the brand axis.
|
|
14
6
|
*/
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
[data-a63-brand='b1'] {
|
|
18
|
-
--a63-brand-50: var(--color-b1-50);
|
|
19
|
-
--a63-brand-100: var(--color-b1-100);
|
|
20
|
-
--a63-brand-200: var(--color-b1-200);
|
|
21
|
-
--a63-brand-300: var(--color-b1-300);
|
|
22
|
-
--a63-brand-400: var(--color-b1-400);
|
|
23
|
-
--a63-brand-500: var(--color-b1-500);
|
|
24
|
-
--a63-brand-600: var(--color-b1-600);
|
|
25
|
-
--a63-brand-700: var(--color-b1-700);
|
|
26
|
-
--a63-brand-800: var(--color-b1-800);
|
|
27
|
-
--a63-brand-900: var(--color-b1-900);
|
|
28
|
-
--a63-brand-950: var(--color-b1-950);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
[data-a63-brand='b2'] {
|
|
32
|
-
--a63-brand-50: var(--color-b2-50);
|
|
33
|
-
--a63-brand-100: var(--color-b2-100);
|
|
34
|
-
--a63-brand-200: var(--color-b2-200);
|
|
35
|
-
--a63-brand-300: var(--color-b2-300);
|
|
36
|
-
--a63-brand-400: var(--color-b2-400);
|
|
37
|
-
--a63-brand-500: var(--color-b2-500);
|
|
38
|
-
--a63-brand-600: var(--color-b2-600);
|
|
39
|
-
--a63-brand-700: var(--color-b2-700);
|
|
40
|
-
--a63-brand-800: var(--color-b2-800);
|
|
41
|
-
--a63-brand-900: var(--color-b2-900);
|
|
42
|
-
--a63-brand-950: var(--color-b2-950);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
[data-a63-brand='b3'] {
|
|
46
|
-
--a63-brand-50: var(--color-b3-50);
|
|
47
|
-
--a63-brand-100: var(--color-b3-100);
|
|
48
|
-
--a63-brand-200: var(--color-b3-200);
|
|
49
|
-
--a63-brand-300: var(--color-b3-300);
|
|
50
|
-
--a63-brand-400: var(--color-b3-400);
|
|
51
|
-
--a63-brand-500: var(--color-b3-500);
|
|
52
|
-
--a63-brand-600: var(--color-b3-600);
|
|
53
|
-
--a63-brand-700: var(--color-b3-700);
|
|
54
|
-
--a63-brand-800: var(--color-b3-800);
|
|
55
|
-
--a63-brand-900: var(--color-b3-900);
|
|
56
|
-
--a63-brand-950: var(--color-b3-950);
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
[data-a63-brand='b4'] {
|
|
60
|
-
--a63-brand-50: var(--color-b4-50);
|
|
61
|
-
--a63-brand-100: var(--color-b4-100);
|
|
62
|
-
--a63-brand-200: var(--color-b4-200);
|
|
63
|
-
--a63-brand-300: var(--color-b4-300);
|
|
64
|
-
--a63-brand-400: var(--color-b4-400);
|
|
65
|
-
--a63-brand-500: var(--color-b4-500);
|
|
66
|
-
--a63-brand-600: var(--color-b4-600);
|
|
67
|
-
--a63-brand-700: var(--color-b4-700);
|
|
68
|
-
--a63-brand-800: var(--color-b4-800);
|
|
69
|
-
--a63-brand-900: var(--color-b4-900);
|
|
70
|
-
--a63-brand-950: var(--color-b4-950);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
[data-a63-brand='b5'] {
|
|
74
|
-
--a63-brand-50: var(--color-b5-50);
|
|
75
|
-
--a63-brand-100: var(--color-b5-100);
|
|
76
|
-
--a63-brand-200: var(--color-b5-200);
|
|
77
|
-
--a63-brand-300: var(--color-b5-300);
|
|
78
|
-
--a63-brand-400: var(--color-b5-400);
|
|
79
|
-
--a63-brand-500: var(--color-b5-500);
|
|
80
|
-
--a63-brand-600: var(--color-b5-600);
|
|
81
|
-
--a63-brand-700: var(--color-b5-700);
|
|
82
|
-
--a63-brand-800: var(--color-b5-800);
|
|
83
|
-
--a63-brand-900: var(--color-b5-900);
|
|
84
|
-
--a63-brand-950: var(--color-b5-950);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
[data-a63-brand='b6'] {
|
|
88
|
-
--a63-brand-50: var(--color-b6-50);
|
|
89
|
-
--a63-brand-100: var(--color-b6-100);
|
|
90
|
-
--a63-brand-200: var(--color-b6-200);
|
|
91
|
-
--a63-brand-300: var(--color-b6-300);
|
|
92
|
-
--a63-brand-400: var(--color-b6-400);
|
|
93
|
-
--a63-brand-500: var(--color-b6-500);
|
|
94
|
-
--a63-brand-600: var(--color-b6-600);
|
|
95
|
-
--a63-brand-700: var(--color-b6-700);
|
|
96
|
-
--a63-brand-800: var(--color-b6-800);
|
|
97
|
-
--a63-brand-900: var(--color-b6-900);
|
|
98
|
-
--a63-brand-950: var(--color-b6-950);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
/*
|
|
102
|
-
* Auto brand — the ramp is derived at runtime from the active wallpaper; the
|
|
103
|
-
* controller writes --color-auto-50..950 inline. Here we map the brand ramp onto
|
|
104
|
-
* those values, with a b1-blue fallback so `auto` is coherent before extraction
|
|
105
|
-
* (or if it fails).
|
|
106
|
-
*/
|
|
107
|
-
[data-a63-brand='auto'] {
|
|
108
|
-
--a63-brand-50: var(--color-auto-50, var(--color-b1-50));
|
|
109
|
-
--a63-brand-100: var(--color-auto-100, var(--color-b1-100));
|
|
110
|
-
--a63-brand-200: var(--color-auto-200, var(--color-b1-200));
|
|
111
|
-
--a63-brand-300: var(--color-auto-300, var(--color-b1-300));
|
|
112
|
-
--a63-brand-400: var(--color-auto-400, var(--color-b1-400));
|
|
113
|
-
--a63-brand-500: var(--color-auto-500, var(--color-b1-500));
|
|
114
|
-
--a63-brand-600: var(--color-auto-600, var(--color-b1-600));
|
|
115
|
-
--a63-brand-700: var(--color-auto-700, var(--color-b1-700));
|
|
116
|
-
--a63-brand-800: var(--color-auto-800, var(--color-b1-800));
|
|
117
|
-
--a63-brand-900: var(--color-auto-900, var(--color-b1-900));
|
|
118
|
-
--a63-brand-950: var(--color-auto-950, var(--color-b1-950));
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
/*
|
|
122
|
-
* Primary action derived from the brand ramp.
|
|
123
|
-
*
|
|
124
|
-
* These MUST be declared on the same scope that remaps the ramp (:root and every
|
|
125
|
-
* [data-a63-brand]) — a var() inside a custom property resolves on the element
|
|
126
|
-
* where the property is DECLARED, then inherits as a resolved value. Declaring
|
|
127
|
-
* only on :root would freeze primary to the base ramp regardless of a downstream
|
|
128
|
-
* [data-a63-brand] override.
|
|
129
|
-
*/
|
|
130
|
-
:root,
|
|
131
|
-
[data-a63-brand] {
|
|
132
|
-
--a63-action-primary: var(--a63-brand-500);
|
|
133
|
-
--a63-action-primary-hover: var(--a63-brand-600);
|
|
134
|
-
/* Auto-contrast foreground: near-white on dark primaries, near-black on bright
|
|
135
|
-
ones (light brand picks / wallpaper golds). oklch `l` is the proxy; the steep
|
|
136
|
-
clamp is a light/dark STEP at l≈0.665 — aligned to WCAG *large-text* white
|
|
137
|
-
3:1 (Y≈0.30), not the old 0.70 / JS 0.36 pair which left mid-golds (mustard
|
|
138
|
-
~L 0.69, Y≈0.33) on light text at ~2.8:1. Default blue (~L 0.62) stays light;
|
|
139
|
-
green/orange brand 500s that fail white 3:1 flip to dark. Chroma ×0.06 keeps
|
|
140
|
-
a faint brand tint. Supersedes JS --color-auto-foreground for components. */
|
|
141
|
-
--a63-action-primary-foreground: oklch(
|
|
142
|
-
from var(--a63-action-primary) clamp(0.15, (0.665 - l) * 1000, 0.985) calc(c * 0.06) h
|
|
143
|
-
);
|
|
144
|
-
/* Subtle depth shadow under text on the primary (theme lever; Aqua sets a gel
|
|
145
|
-
tint). Default none so flat themes stay crisp. */
|
|
146
|
-
--a63-action-primary-text-shadow: none;
|
|
147
|
-
--a63-focus-ring: color-mix(in oklch, var(--a63-brand-500) 30%, transparent);
|
|
148
|
-
}
|
|
7
|
+
@import './brand-ramp.css';
|
|
8
|
+
@import './brand-action.css';
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import manifest from '../../generated/atom63.tokens.json'
|
|
3
|
+
import { resetRoot, root } from '../test/apply-styles'
|
|
4
|
+
|
|
5
|
+
/*
|
|
6
|
+
* An oklch color-mix() interpolates hue. When one operand is a slightly tinted
|
|
7
|
+
* neutral (the n2–n6 surface palettes), engines disagree on that operand's hue:
|
|
8
|
+
* Chromium treats a hue this close to gray as powerless and takes the other
|
|
9
|
+
* operand's hue, while Firefox and WebKit interpolate from it, so the same mix
|
|
10
|
+
* renders a different color per browser (up to 170/255 apart on a theme). oklab
|
|
11
|
+
* has no hue, so every engine agrees. CSS Color 4 makes an oklch hue powerless
|
|
12
|
+
* only at C <= 0.000004, so Firefox and WebKit follow the spec and Chromium's
|
|
13
|
+
* wider threshold is the bug. The rule: an oklch mix may not take an operand
|
|
14
|
+
* whose chroma is above that epsilon but low (a tinted neutral) under any
|
|
15
|
+
* surface or mode; mix those in oklab. Exact grays, black and white fall under
|
|
16
|
+
* the epsilon, have no hue in any engine, and are fine.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
const lowChroma = { min: 0.000004, max: 0.04 }
|
|
20
|
+
|
|
21
|
+
type Entry = { cssVar: string; type: string; value: string; scope: string }
|
|
22
|
+
|
|
23
|
+
/* A nested brand or surface scope declares a mode role as
|
|
24
|
+
`var(--a63-if-light, <light>) var(--a63-if-dark, <dark>)`; only one branch
|
|
25
|
+
applies, so each is checked as its own value. */
|
|
26
|
+
function branches(entry: Entry): Entry[] {
|
|
27
|
+
const found: Entry[] = []
|
|
28
|
+
for (const mode of ['light', 'dark']) {
|
|
29
|
+
const start = entry.value.search(new RegExp(`var\\(\\s*--a63-if-${mode}\\s*,`))
|
|
30
|
+
if (start === -1) continue
|
|
31
|
+
let depth = 0
|
|
32
|
+
let end = start
|
|
33
|
+
for (; end < entry.value.length; end++) {
|
|
34
|
+
if (entry.value[end] === '(') depth++
|
|
35
|
+
if (entry.value[end] === ')' && --depth === 0) break
|
|
36
|
+
}
|
|
37
|
+
const value = entry.value.slice(entry.value.indexOf(',', start) + 1, end)
|
|
38
|
+
found.push({ ...entry, value, scope: `${entry.scope} (${mode})` })
|
|
39
|
+
}
|
|
40
|
+
return found.length > 0 ? found : [entry]
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
const mixes = (manifest as { entries: Entry[] }).entries
|
|
44
|
+
.flatMap(branches)
|
|
45
|
+
.filter(entry => entry.type === 'color' && /color-mix\(\s*in oklch/.test(entry.value))
|
|
46
|
+
|
|
47
|
+
const probe = document.createElement('div')
|
|
48
|
+
document.body.append(probe)
|
|
49
|
+
|
|
50
|
+
/** oklch chroma of a CSS color, or null when it does not parse. */
|
|
51
|
+
function chroma(color: string): number | null {
|
|
52
|
+
probe.style.color = ''
|
|
53
|
+
probe.style.color = `oklch(from ${color} l c h)`
|
|
54
|
+
if (!probe.style.color) return null
|
|
55
|
+
const match = /^oklch\(([-\d.e]+) ([-\d.e]+)/.exec(getComputedStyle(probe).color)
|
|
56
|
+
return match ? Number(match[2]) : null
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** The var() operands of a color-mix(), in order. */
|
|
60
|
+
function operands(value: string): string[] {
|
|
61
|
+
return [...value.matchAll(/var\((--[\w-]+)\)/g)].map(match => match[1])
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
afterEach(() => {
|
|
65
|
+
resetRoot()
|
|
66
|
+
for (const attribute of ['data-a63-theme', 'data-a63-surface', 'data-a63-mode'])
|
|
67
|
+
root().removeAttribute(attribute)
|
|
68
|
+
root().classList.remove('light', 'dark')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
describe('color-mix interpolation space', () => {
|
|
72
|
+
it('finds the oklch mixes', () => {
|
|
73
|
+
expect(mixes.length).toBeGreaterThan(0)
|
|
74
|
+
})
|
|
75
|
+
|
|
76
|
+
it('never mixes a tinted neutral in oklch', () => {
|
|
77
|
+
const violations = new Set<string>()
|
|
78
|
+
for (const theme of ['modern', 'aqua', 'retro', 'terminal'])
|
|
79
|
+
for (const surface of ['n1', 'n2', 'n3', 'n4', 'n5', 'n6'])
|
|
80
|
+
for (const mode of ['light', 'dark']) {
|
|
81
|
+
const element = root()
|
|
82
|
+
element.setAttribute('data-a63-theme', theme)
|
|
83
|
+
element.setAttribute('data-a63-surface', surface)
|
|
84
|
+
element.setAttribute('data-a63-mode', mode)
|
|
85
|
+
element.classList.remove('light', 'dark')
|
|
86
|
+
element.classList.add(mode)
|
|
87
|
+
const styles = getComputedStyle(element)
|
|
88
|
+
for (const entry of mixes) {
|
|
89
|
+
for (const operand of operands(entry.value)) {
|
|
90
|
+
const value = styles.getPropertyValue(operand).trim()
|
|
91
|
+
const c = value && chroma(value)
|
|
92
|
+
if (typeof c === 'number' && c >= lowChroma.min && c < lowChroma.max)
|
|
93
|
+
violations.add(
|
|
94
|
+
`${entry.cssVar} [${entry.scope.replace(/\s+/g, ' ')}] via ${operand}`
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
expect([...violations].sort()).toEqual([])
|
|
100
|
+
})
|
|
101
|
+
})
|
|
@@ -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,196 @@ 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
|
+
})
|
|
140
392
|
})
|