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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/README.md +16 -10
  2. package/generated/atom63.figma-sync.json +12897 -6323
  3. package/generated/atom63.tokens.json +8778 -3550
  4. package/package.json +8 -7
  5. package/src/compat/a63-from-shadcn.css +10 -0
  6. package/src/compat/shadcn.browser.test.ts +23 -0
  7. package/src/compat/shadcn.css +118 -16
  8. package/src/contracts/action.css +4 -3
  9. package/src/contracts/action.native.css +11 -0
  10. package/src/contracts/action.tokens.json +66 -0
  11. package/src/contracts/badge.css +83 -58
  12. package/src/contracts/badge.resolver.json +449 -0
  13. package/src/contracts/choice.css +4 -1
  14. package/src/contracts/choice.native.css +9 -0
  15. package/src/contracts/choice.tokens.json +66 -0
  16. package/src/contracts/control.css +43 -52
  17. package/src/contracts/control.native.css +13 -0
  18. package/src/contracts/control.tokens.json +245 -0
  19. package/src/contracts/environment.css +45 -49
  20. package/src/contracts/environment.native.css +23 -0
  21. package/src/contracts/environment.resolver.json +569 -0
  22. package/src/contracts/field.css +3 -1
  23. package/src/contracts/field.tokens.json +40 -0
  24. package/src/contracts/marker.css +6 -4
  25. package/src/contracts/marker.tokens.json +15 -0
  26. package/src/contracts/menu.css +25 -61
  27. package/src/contracts/menu.native.css +10 -0
  28. package/src/contracts/menu.resolver.json +122 -0
  29. package/src/contracts/overlay.css +11 -13
  30. package/src/contracts/overlay.native.css +13 -0
  31. package/src/contracts/overlay.tokens.json +103 -0
  32. package/src/contracts/segment.css +22 -68
  33. package/src/contracts/segment.tokens.json +19 -0
  34. package/src/contracts/selection.css +3 -1
  35. package/src/contracts/selection.tokens.json +37 -0
  36. package/src/contracts/skeleton.css +3 -0
  37. package/src/contracts/skeleton.resolver.json +66 -0
  38. package/src/contracts/surface.css +13 -24
  39. package/src/contracts/surface.native.css +17 -0
  40. package/src/contracts/surface.tokens.json +97 -0
  41. package/src/contracts/toggle.css +3 -1
  42. package/src/contracts/toggle.tokens.json +49 -0
  43. package/src/contracts/track.css +3 -1
  44. package/src/contracts/track.tokens.json +39 -0
  45. package/src/contracts/trigger.css +5 -2
  46. package/src/contracts/trigger.native.css +9 -0
  47. package/src/contracts/trigger.tokens.json +58 -0
  48. package/src/contracts/widget.css +41 -51
  49. package/src/contracts/widget.native.css +23 -0
  50. package/src/contracts/widget.resolver.json +1104 -0
  51. package/src/tailwind/roles.json +172 -0
  52. package/src/tailwind/theme.css +107 -23
  53. package/src/themes/aqua.css +24 -89
  54. package/src/themes/aqua.native.css +80 -0
  55. package/src/themes/aqua.resolver.json +1292 -0
  56. package/src/themes/modern.css +10 -14
  57. package/src/themes/modern.native.css +16 -0
  58. package/src/themes/modern.resolver.json +350 -0
  59. package/src/themes/retro.css +21 -26
  60. package/src/themes/retro.native.css +16 -0
  61. package/src/themes/retro.resolver.json +788 -0
  62. package/src/themes/terminal.css +34 -41
  63. package/src/themes/terminal.native.css +22 -0
  64. package/src/themes/terminal.resolver.json +517 -0
  65. package/src/tokens/brand-action.css +61 -0
  66. package/src/tokens/brand-action.resolver.json +137 -0
  67. package/src/tokens/brand-ramp.css +108 -0
  68. package/src/tokens/brand-ramp.resolver.json +418 -0
  69. package/src/tokens/brand.css +6 -146
  70. package/src/tokens/color-mix-space.browser.test.ts +79 -0
  71. package/src/tokens/contrast.browser.test.ts +82 -3
  72. package/src/tokens/figma-parity.browser.test.ts +270 -0
  73. package/src/tokens/font.css +6 -0
  74. package/src/tokens/font.resolver.json +107 -0
  75. package/src/tokens/foundation/effects.css +13 -13
  76. package/src/tokens/foundation/effects.resolver.json +433 -0
  77. package/src/tokens/foundation/fonts.css +3 -1
  78. package/src/tokens/foundation/fonts.tokens.json +6 -1
  79. package/src/tokens/foundation/radius.css +6 -9
  80. package/src/tokens/foundation/radius.tokens.json +100 -0
  81. package/src/tokens/foundation/typography.css +25 -12
  82. package/src/tokens/foundation/typography.native.css +11 -0
  83. package/src/tokens/foundation/typography.resolver.json +936 -0
  84. package/src/tokens/foundation.css +0 -1
  85. package/src/tokens/motion.css +3 -1
  86. package/src/tokens/motion.resolver.json +135 -0
  87. package/src/tokens/native-values.json +38 -0
  88. package/src/tokens/personalization-axes.browser.test.ts +5 -3
  89. package/src/tokens/radius.css +12 -8
  90. package/src/tokens/radius.resolver.json +138 -0
  91. package/src/tokens/semantics.css +211 -47
  92. package/src/tokens/semantics.resolver.json +1296 -0
  93. package/src/tokens/space.css +8 -6
  94. package/src/tokens/space.tokens.json +78 -0
  95. package/src/tokens/swift-parity.browser.test.ts +141 -0
  96. package/src/tokens/type-scale.css +6 -0
  97. package/src/tokens/type-scale.resolver.json +67 -0
  98. package/generated/atom63.figma-tokens.json +0 -21661
  99. package/src/tokens/foundation/aliases.css +0 -32
  100. package/src/tokens/foundation/aliases.tokens.json +0 -105
@@ -1,148 +1,8 @@
1
1
  /*
2
- * Brand personalization axis (semantic ramp indirection).
3
- *
4
- * --a63-brand-50..950 is the primary/brand tonal scale the whole system derives
5
- * from (--a63-action-primary = --a63-brand-500, foreground = --a63-brand-50,
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
- :root,
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,79 @@
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
+ const mixes = (
22
+ manifest as { entries: { cssVar: string; type: string; value: string; scope: string }[] }
23
+ ).entries.filter(entry => entry.type === 'color' && /color-mix\(\s*in oklch/.test(entry.value))
24
+
25
+ const probe = document.createElement('div')
26
+ document.body.append(probe)
27
+
28
+ /** oklch chroma of a CSS color, or null when it does not parse. */
29
+ function chroma(color: string): number | null {
30
+ probe.style.color = ''
31
+ probe.style.color = `oklch(from ${color} l c h)`
32
+ if (!probe.style.color) return null
33
+ const match = /^oklch\(([-\d.e]+) ([-\d.e]+)/.exec(getComputedStyle(probe).color)
34
+ return match ? Number(match[2]) : null
35
+ }
36
+
37
+ /** The var() operands of a color-mix(), in order. */
38
+ function operands(value: string): string[] {
39
+ return [...value.matchAll(/var\((--[\w-]+)\)/g)].map(match => match[1])
40
+ }
41
+
42
+ afterEach(() => {
43
+ resetRoot()
44
+ for (const attribute of ['data-a63-theme', 'data-a63-surface', 'data-a63-mode'])
45
+ root().removeAttribute(attribute)
46
+ root().classList.remove('light', 'dark')
47
+ })
48
+
49
+ describe('color-mix interpolation space', () => {
50
+ it('finds the oklch mixes', () => {
51
+ expect(mixes.length).toBeGreaterThan(0)
52
+ })
53
+
54
+ it('never mixes a tinted neutral in oklch', () => {
55
+ const violations = new Set<string>()
56
+ for (const theme of ['modern', 'aqua', 'retro', 'terminal'])
57
+ for (const surface of ['n1', 'n2', 'n3', 'n4', 'n5', 'n6'])
58
+ for (const mode of ['light', 'dark']) {
59
+ const element = root()
60
+ element.setAttribute('data-a63-theme', theme)
61
+ element.setAttribute('data-a63-surface', surface)
62
+ element.setAttribute('data-a63-mode', mode)
63
+ element.classList.remove('light', 'dark')
64
+ element.classList.add(mode)
65
+ const styles = getComputedStyle(element)
66
+ for (const entry of mixes) {
67
+ for (const operand of operands(entry.value)) {
68
+ const value = styles.getPropertyValue(operand).trim()
69
+ const c = value && chroma(value)
70
+ if (typeof c === 'number' && c >= lowChroma.min && c < lowChroma.max)
71
+ violations.add(
72
+ `${entry.cssVar} [${entry.scope.replace(/\s+/g, ' ')}] via ${operand}`
73
+ )
74
+ }
75
+ }
76
+ }
77
+ expect([...violations].sort()).toEqual([])
78
+ })
79
+ })
@@ -13,15 +13,26 @@ 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
15
  { fg: '--a63-text-primary', bg: '--a63-surface-panel', min: AA_TEXT },
16
+ { fg: '--a63-text-accent', bg: '--a63-surface-page', min: AA_TEXT },
17
+ { fg: '--a63-text-accent', bg: '--a63-surface-panel', min: AA_TEXT },
16
18
  ] as const
17
19
 
18
20
  const actionPairs = [
19
- { fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_UI },
21
+ // Button labels are normal-size text, so the primary pair meets AA text, not 3:1.
22
+ { fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
20
23
  { fg: '--a63-action-neutral-foreground', bg: '--a63-action-neutral', min: AA_UI },
21
24
  { fg: '--a63-action-danger-foreground', bg: '--a63-action-danger', min: AA_UI },
22
25
  ] as const
23
26
 
24
- const pairs = [...textPairs, ...actionPairs] as const
27
+ // Status accents paint icons and borders (alerts, copy check, load more), so
28
+ // they meet WCAG's 3:1 for graphics against the page.
29
+ const statusPairs = [
30
+ { fg: '--a63-status-info', bg: '--a63-surface-page', min: AA_UI },
31
+ { fg: '--a63-status-success', bg: '--a63-surface-page', min: AA_UI },
32
+ { fg: '--a63-status-warning', bg: '--a63-surface-page', min: AA_UI },
33
+ ] as const
34
+
35
+ const pairs = [...textPairs, ...actionPairs, ...statusPairs] as const
25
36
 
26
37
  afterEach(() => {
27
38
  document.documentElement.removeAttribute('data-a63-theme')
@@ -105,7 +116,7 @@ function applyThemeMode(theme: (typeof themes)[number], mode: (typeof modes)[num
105
116
  }
106
117
 
107
118
  describe('core semantic contrast (WCAG AA)', () => {
108
- it('meets AA text 4.5:1 on surfaces and UI 3:1 on action fills', () => {
119
+ it('meets AA text 4.5:1 on surfaces and the primary fill, and 3:1 on other action fills', () => {
109
120
  const failures: string[] = []
110
121
 
111
122
  for (const theme of themes) {
@@ -138,3 +149,71 @@ describe('core semantic contrast (WCAG AA)', () => {
138
149
  expect(failures, failures.join('\n')).toEqual([])
139
150
  })
140
151
  })
152
+
153
+ const brands = ['b1', 'b2', 'b3', 'b4', 'b5', 'b6'] as const
154
+ const brandPairs = [
155
+ { fg: '--a63-action-primary-foreground', bg: '--a63-action-primary', min: AA_TEXT },
156
+ { fg: '--a63-text-accent', bg: '--a63-surface-page', min: AA_TEXT },
157
+ // WCAG 1.4.11: a focus ring is the graphic that shows focus, so it reaches 3:1
158
+ // against the field it surrounds and the page around it.
159
+ { fg: '--a63-focus-ring', bg: '--a63-surface-page', min: AA_UI },
160
+ { fg: '--a63-focus-ring', bg: '--a63-surface-panel', min: AA_UI },
161
+ { fg: '--a63-focus-ring', bg: '--a63-surface-control', min: AA_UI },
162
+ ] as const
163
+
164
+ describe('brand contrast (WCAG AA)', () => {
165
+ afterEach(() => root().removeAttribute('data-a63-brand'))
166
+
167
+ it('keeps the primary action and brand text readable on every brand ramp', () => {
168
+ const failures: string[] = []
169
+ for (const brand of brands) {
170
+ root().setAttribute('data-a63-brand', brand)
171
+ for (const theme of themes) {
172
+ for (const mode of modes) {
173
+ applyThemeMode(theme, mode)
174
+ for (const { fg, bg, min } of brandPairs) {
175
+ const fgCss = resolvePaintedColor(fg, 'color')
176
+ const bgCss = resolvePaintedColor(bg, 'background')
177
+ const ratio = contrastRatio(parseCssColor(fgCss), parseCssColor(bgCss))
178
+ if (ratio < min) {
179
+ failures.push(
180
+ `${brand} ${theme}/${mode} ${fg} on ${bg}: ${ratio.toFixed(2)}:1 < ${min}:1 (fg=${fgCss}, bg=${bgCss})`
181
+ )
182
+ }
183
+ }
184
+ }
185
+ }
186
+ }
187
+ expect(failures, failures.join('\n')).toEqual([])
188
+ })
189
+
190
+ it('keeps a selected item readable on every brand ramp', () => {
191
+ const failures: string[] = []
192
+ for (const brand of brands) {
193
+ root().setAttribute('data-a63-brand', brand)
194
+ for (const theme of themes) {
195
+ for (const mode of modes) {
196
+ applyThemeMode(theme, mode)
197
+ // The selected wash is translucent: paint it over the page first.
198
+ const page = parseCssColor(resolvePaintedColor('--a63-surface-page', 'background'))
199
+ const washCss = resolvePaintedColor('--a63-selected-background', 'background')
200
+ const wash = parseCssColor(washCss)
201
+ const fill: Rgb = {
202
+ r: wash.r * wash.a + page.r * (1 - wash.a),
203
+ g: wash.g * wash.a + page.g * (1 - wash.a),
204
+ b: wash.b * wash.a + page.b * (1 - wash.a),
205
+ a: 1,
206
+ }
207
+ const fgCss = resolvePaintedColor('--a63-selected-foreground', 'color')
208
+ const ratio = contrastRatio(parseCssColor(fgCss), fill)
209
+ if (ratio < AA_TEXT) {
210
+ failures.push(
211
+ `${brand} ${theme}/${mode} selected: ${ratio.toFixed(2)}:1 < ${AA_TEXT}:1 (fg=${fgCss}, bg=${washCss})`
212
+ )
213
+ }
214
+ }
215
+ }
216
+ }
217
+ expect(failures, failures.join('\n')).toEqual([])
218
+ })
219
+ })
@@ -0,0 +1,270 @@
1
+ import { afterEach, beforeAll, describe, expect, it } from 'vitest'
2
+ import { page } from 'vitest/browser'
3
+ import model from '../../generated/atom63.figma-sync.json'
4
+ import { resetRoot, root } from '../test/apply-styles'
5
+
6
+ /*
7
+ * Figma/web parity across every axis. Each Figma variable is resolved through
8
+ * the sync model the way Figma resolves it (follow aliases; a collection takes
9
+ * its mode from the active context) and compared with what the browser computes
10
+ * for the token under the same data-a63-* attributes. The Swift parity test
11
+ * checks the default context only; this one checks every mode of every axis,
12
+ * and every theme × brand × surface × mode combination for colors, because
13
+ * those four interact.
14
+ *
15
+ * Variables the model lists as `computed` vary on more axes than one Figma
16
+ * collection can hold; Figma shows their default and renderers evaluate their
17
+ * expression, so they are left out here, and so is any variable whose alias
18
+ * chain reaches one of them in the context being checked. The viewport matches the generator's
19
+ * page (1280 × 720), because viewport units and media queries resolve against it.
20
+ */
21
+
22
+ type Rgba = { r: number; g: number; b: number; a: number }
23
+ type Value = {
24
+ alias?: string
25
+ composed?: { alias: string; opacity: number }
26
+ value?: Rgba | number | string
27
+ }
28
+ interface Variable {
29
+ name: string
30
+ token: string
31
+ type: 'COLOR' | 'FLOAT' | 'STRING'
32
+ values: Record<string, Value>
33
+ }
34
+ interface Collection {
35
+ name: string
36
+ modes: string[]
37
+ variables: Variable[]
38
+ }
39
+
40
+ const { collections, computed } = model as {
41
+ collections: Collection[]
42
+ computed: { token: string }[]
43
+ }
44
+ const computedTokens = new Set(computed.map(entry => entry.token))
45
+ const byToken = new Map<string, { collection: Collection; variable: Variable }>()
46
+ for (const collection of collections)
47
+ for (const variable of collection.variables) byToken.set(variable.token, { collection, variable })
48
+
49
+ // Context keys and the attribute each one sets on the root.
50
+ const attributes = {
51
+ theme: 'data-a63-theme',
52
+ mode: 'data-a63-mode',
53
+ brand: 'data-a63-brand',
54
+ surface: 'data-a63-surface',
55
+ designLanguage: 'data-a63-design-language',
56
+ input: 'data-a63-input',
57
+ density: 'data-a63-density',
58
+ radius: 'data-a63-radius',
59
+ typeScale: 'data-a63-type-scale',
60
+ font: 'data-a63-font',
61
+ windowSize: 'data-window-size',
62
+ } as const
63
+ type Context = Record<keyof typeof attributes, string>
64
+
65
+ const defaults: Context = {
66
+ theme: 'modern',
67
+ mode: 'light',
68
+ brand: 'b1',
69
+ surface: 'n1',
70
+ designLanguage: 'web',
71
+ input: 'pointer',
72
+ density: 'comfortable',
73
+ radius: 'default',
74
+ typeScale: 'normal',
75
+ font: 'sans',
76
+ windowSize: 'md',
77
+ }
78
+
79
+ // Which context key picks the mode of each axis collection.
80
+ const collectionAxis: Record<string, keyof Context> = {
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',
91
+ }
92
+
93
+ function modeOf(collection: Collection, context: Context): string {
94
+ if (collection.name === 'Theme') return `${context.theme}-${context.mode}`
95
+ const axis = collectionAxis[collection.name]
96
+ return axis ? context[axis] : collection.modes[0]
97
+ }
98
+
99
+ /**
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.
103
+ */
104
+ function resolveInModel(
105
+ token: string,
106
+ context: Context,
107
+ seen: string[] = []
108
+ ): { value: Value['value']; approximate: boolean } {
109
+ const found = byToken.get(token)
110
+ if (!found) throw new Error(`${token} is not in the Figma sync model`)
111
+ if (seen.includes(token)) throw new Error(`alias cycle: ${[...seen, token].join(' -> ')}`)
112
+ const entry = found.variable.values[modeOf(found.collection, context)]
113
+ if (entry?.alias) {
114
+ const target = resolveInModel(entry.alias, context, [...seen, token])
115
+ return { ...target, approximate: target.approximate || computedTokens.has(token) }
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
+ }
125
+ return { value: entry?.value, approximate: computedTokens.has(token) }
126
+ }
127
+
128
+ function applyContext(context: Context) {
129
+ const element = root()
130
+ for (const [key, attribute] of Object.entries(attributes))
131
+ element.setAttribute(attribute, context[key as keyof Context])
132
+ element.classList.remove('light', 'dark')
133
+ element.classList.add(context.mode)
134
+ }
135
+
136
+ const probe = document.createElement('div')
137
+ document.body.append(probe)
138
+
139
+ /** Float sRGB, like the generator reads it: no 8-bit rounding. */
140
+ function browserColor(value: string): Rgba | null {
141
+ probe.style.color = ''
142
+ probe.style.color = `color(from ${value} srgb r g b / alpha)`
143
+ if (!probe.style.color) return null
144
+ const match = /^color\(srgb ([-\d.e]+) ([-\d.e]+) ([-\d.e]+)(?: \/ ([-\d.e]+))?\)$/.exec(
145
+ getComputedStyle(probe).color
146
+ )
147
+ if (!match) return null
148
+ const channel = (text: string) => Math.min(1, Math.max(0, Number(text)))
149
+ return {
150
+ r: channel(match[1]),
151
+ g: channel(match[2]),
152
+ b: channel(match[3]),
153
+ a: channel(match[4] ?? '1'),
154
+ }
155
+ }
156
+
157
+ function browserNumber(value: string): number | null {
158
+ const trimmed = value.trim()
159
+ const percent = /^(-?[\d.]+)%$/.exec(trimmed)
160
+ if (percent) return Number(percent[1])
161
+ if (/^-?[\d.]+$/.test(trimmed)) return Number(trimmed)
162
+ const time = /^(-?[\d.]+)(ms|s)$/.exec(trimmed)
163
+ if (time) return Number(time[1]) * (time[2] === 's' ? 1000 : 1)
164
+ probe.style.width = ''
165
+ probe.style.width = trimmed
166
+ if (probe.style.width) return Number.parseFloat(getComputedStyle(probe).width)
167
+ return null
168
+ }
169
+
170
+ const normalize = (text: string) => text.replace(/\s+/g, ' ').trim()
171
+
172
+ /** Differences between the model and the browser for these tokens in one context. */
173
+ function compare(context: Context, variables: Variable[]): string[] {
174
+ applyContext(context)
175
+ const styles = getComputedStyle(root())
176
+ const label = `${context.theme}-${context.mode} ${Object.entries(context)
177
+ .filter(
178
+ ([key, value]) =>
179
+ key !== 'theme' && key !== 'mode' && value !== defaults[key as keyof Context]
180
+ )
181
+ .map(([key, value]) => `${key}=${value}`)
182
+ .join(' ')}`.trim()
183
+ const differences: string[] = []
184
+ for (const variable of variables) {
185
+ const raw = styles.getPropertyValue(variable.token)
186
+ const { value: expected, approximate } = resolveInModel(variable.token, context)
187
+ if (approximate) continue
188
+ if (variable.type === 'COLOR') {
189
+ const web = browserColor(raw)
190
+ const figma = expected as Rgba
191
+ if (!web) continue
192
+ const drift = Math.max(
193
+ Math.abs(web.r - figma.r),
194
+ Math.abs(web.g - figma.g),
195
+ Math.abs(web.b - figma.b),
196
+ Math.abs(web.a - figma.a)
197
+ )
198
+ if (drift > 1.5 / 255) differences.push(`${variable.token} @ ${label}`)
199
+ } else if (variable.type === 'FLOAT') {
200
+ const web = browserNumber(raw)
201
+ if (web === null) continue
202
+ if (Math.abs(web - (expected as number)) > 0.01)
203
+ differences.push(`${variable.token} @ ${label}`)
204
+ } else if (normalize(raw) !== normalize(String(expected))) {
205
+ differences.push(`${variable.token} @ ${label}`)
206
+ }
207
+ }
208
+ return differences
209
+ }
210
+
211
+ const allVariables = collections
212
+ .flatMap(collection => collection.variables)
213
+ .filter(variable => !computedTokens.has(variable.token))
214
+ const colorVariables = allVariables.filter(variable => variable.type === 'COLOR')
215
+
216
+ // Every mode of every axis on its own, and every theme × mode.
217
+ const axisContexts: Context[] = [defaults]
218
+ for (const collection of collections) {
219
+ const axis = collectionAxis[collection.name]
220
+ if (!axis) continue
221
+ for (const mode of collection.modes)
222
+ if (mode !== defaults[axis]) axisContexts.push({ ...defaults, [axis]: mode })
223
+ }
224
+ for (const theme of ['modern', 'aqua', 'retro', 'terminal'])
225
+ for (const mode of ['light', 'dark']) axisContexts.push({ ...defaults, theme, mode })
226
+
227
+ // Colors: every theme × brand × surface × mode.
228
+ const colorContexts: Context[] = []
229
+ for (const theme of ['modern', 'aqua', 'retro', 'terminal'])
230
+ for (const brand of ['b1', 'b2', 'b3', 'b4', 'b5', 'b6'])
231
+ for (const surface of ['n1', 'n2', 'n3', 'n4', 'n5', 'n6'])
232
+ for (const mode of ['light', 'dark'])
233
+ colorContexts.push({ ...defaults, theme, brand, surface, mode })
234
+
235
+ beforeAll(async () => {
236
+ await page.viewport(1280, 720)
237
+ })
238
+
239
+ afterEach(() => {
240
+ resetRoot()
241
+ for (const attribute of Object.values(attributes)) root().removeAttribute(attribute)
242
+ root().classList.remove('light', 'dark')
243
+ })
244
+
245
+ /** Groups differences by token, listing the contexts where each one differs. */
246
+ function summarize(differences: string[]) {
247
+ const byTokenName = new Map<string, string[]>()
248
+ for (const difference of differences) {
249
+ const [token, context] = difference.split(' @ ')
250
+ byTokenName.set(token, [...(byTokenName.get(token) ?? []), context])
251
+ }
252
+ return Object.fromEntries(
253
+ [...byTokenName].map(([token, contexts]) => [
254
+ token,
255
+ `${contexts.length}: ${contexts.slice(0, 3).join(' | ')}`,
256
+ ])
257
+ )
258
+ }
259
+
260
+ describe('Figma/web parity', () => {
261
+ it('matches every variable on every axis', () => {
262
+ const differences = axisContexts.flatMap(context => compare(context, allVariables))
263
+ expect(summarize(differences)).toEqual({})
264
+ })
265
+
266
+ it('matches every color across theme × brand × surface × mode', () => {
267
+ const differences = colorContexts.flatMap(context => compare(context, colorVariables))
268
+ expect(summarize(differences)).toEqual({})
269
+ })
270
+ })
@@ -1,4 +1,7 @@
1
1
  /*
2
+ * Generated from src/tokens/font.resolver.json by scripts/build-css-from-dtcg.mjs. Do not edit;
3
+ * change the DTCG source and run `pnpm --filter @atom63/styles generate:tokens`.
4
+ *
2
5
  * Font personalization axis.
3
6
  *
4
7
  * --a63-font-app is the active application font stack; a consumer applies it on
@@ -14,12 +17,15 @@
14
17
  [data-a63-font='sans'] {
15
18
  --a63-font-app: var(--font-family-sans);
16
19
  }
20
+
17
21
  [data-a63-font='serif'] {
18
22
  --a63-font-app: var(--font-family-serif);
19
23
  }
24
+
20
25
  [data-a63-font='mono'] {
21
26
  --a63-font-app: var(--font-family-mono);
22
27
  }
28
+
23
29
  [data-a63-font='pixel'] {
24
30
  --a63-font-app: var(--font-family-pixel);
25
31
  }