@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.
Files changed (119) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +22 -13
  3. package/generated/atom63.figma-sync.json +23277 -0
  4. package/generated/atom63.tokens.json +19650 -8403
  5. package/generated/z-layers.d.ts +33 -0
  6. package/generated/z-layers.js +31 -0
  7. package/package.json +29 -15
  8. package/src/compat/a63-from-shadcn.css +281 -0
  9. package/src/compat/shadcn.browser.test.ts +23 -0
  10. package/src/compat/shadcn.css +133 -17
  11. package/src/contracts/action.css +4 -3
  12. package/src/contracts/action.native.css +11 -0
  13. package/src/contracts/action.tokens.json +66 -0
  14. package/src/contracts/badge.css +128 -58
  15. package/src/contracts/badge.resolver.json +454 -0
  16. package/src/contracts/choice.css +5 -2
  17. package/src/contracts/choice.native.css +9 -0
  18. package/src/contracts/choice.tokens.json +66 -0
  19. package/src/contracts/control.css +54 -57
  20. package/src/contracts/control.native.css +13 -0
  21. package/src/contracts/control.tokens.json +294 -0
  22. package/src/contracts/environment.css +178 -60
  23. package/src/contracts/environment.native.css +23 -0
  24. package/src/contracts/environment.resolver.json +1210 -0
  25. package/src/contracts/field.css +4 -2
  26. package/src/contracts/field.tokens.json +40 -0
  27. package/src/contracts/marker.css +6 -4
  28. package/src/contracts/marker.tokens.json +15 -0
  29. package/src/contracts/menu.css +25 -61
  30. package/src/contracts/menu.native.css +10 -0
  31. package/src/contracts/menu.resolver.json +122 -0
  32. package/src/contracts/overlay.css +11 -13
  33. package/src/contracts/overlay.native.css +13 -0
  34. package/src/contracts/overlay.tokens.json +103 -0
  35. package/src/contracts/segment.css +22 -68
  36. package/src/contracts/segment.tokens.json +19 -0
  37. package/src/contracts/selection.css +5 -1
  38. package/src/contracts/selection.tokens.json +42 -0
  39. package/src/contracts/skeleton.css +18 -2
  40. package/src/contracts/skeleton.resolver.json +62 -0
  41. package/src/contracts/surface.css +17 -24
  42. package/src/contracts/surface.native.css +17 -0
  43. package/src/contracts/surface.tokens.json +154 -0
  44. package/src/contracts/toggle.css +27 -3
  45. package/src/contracts/toggle.resolver.json +129 -0
  46. package/src/contracts/track.css +3 -1
  47. package/src/contracts/track.tokens.json +39 -0
  48. package/src/contracts/trigger.css +5 -2
  49. package/src/contracts/trigger.native.css +9 -0
  50. package/src/contracts/trigger.tokens.json +58 -0
  51. package/src/contracts/widget.css +76 -51
  52. package/src/contracts/widget.native.css +23 -0
  53. package/src/contracts/widget.resolver.json +1110 -0
  54. package/src/tailwind/roles.json +189 -0
  55. package/src/tailwind/theme.css +216 -24
  56. package/src/tailwind/utilities.css +17 -0
  57. package/src/themes/aqua.css +126 -89
  58. package/src/themes/aqua.native.css +80 -0
  59. package/src/themes/aqua.resolver.json +1304 -0
  60. package/src/themes/modern.css +10 -14
  61. package/src/themes/modern.native.css +16 -0
  62. package/src/themes/modern.resolver.json +350 -0
  63. package/src/themes/retro.css +22 -26
  64. package/src/themes/retro.native.css +16 -0
  65. package/src/themes/retro.resolver.json +794 -0
  66. package/src/themes/terminal.css +164 -41
  67. package/src/themes/terminal.native.css +22 -0
  68. package/src/themes/terminal.resolver.json +585 -0
  69. package/src/tokens/brand-action.css +65 -0
  70. package/src/tokens/brand-action.resolver.json +155 -0
  71. package/src/tokens/brand-ramp.css +108 -0
  72. package/src/tokens/brand-ramp.resolver.json +418 -0
  73. package/src/tokens/brand.css +6 -146
  74. package/src/tokens/chart-palette.browser.test.ts +188 -0
  75. package/src/tokens/color-mix-space.browser.test.ts +101 -0
  76. package/src/tokens/contrast.browser.test.ts +303 -5
  77. package/src/tokens/density.browser.test.ts +167 -0
  78. package/src/tokens/figma-parity.browser.test.ts +270 -0
  79. package/src/tokens/font.css +12 -0
  80. package/src/tokens/font.resolver.json +128 -0
  81. package/src/tokens/form-factor.browser.test.ts +129 -0
  82. package/src/tokens/foundation/effects.css +13 -13
  83. package/src/tokens/foundation/effects.resolver.json +433 -0
  84. package/src/tokens/foundation/fonts.css +11 -5
  85. package/src/tokens/foundation/fonts.tokens.json +45 -0
  86. package/src/tokens/foundation/motion.css +3 -0
  87. package/src/tokens/foundation/motion.tokens.json +53 -0
  88. package/src/tokens/foundation/palette.css +3 -0
  89. package/src/tokens/foundation/palette.tokens.json +1743 -0
  90. package/src/tokens/foundation/primitives.css +20 -43
  91. package/src/tokens/foundation/primitives.tokens.json +3258 -0
  92. package/src/tokens/foundation/radius.css +11 -9
  93. package/src/tokens/foundation/radius.tokens.json +108 -0
  94. package/src/tokens/foundation/typography.css +49 -12
  95. package/src/tokens/foundation/typography.native.css +21 -0
  96. package/src/tokens/foundation/typography.resolver.json +1008 -0
  97. package/src/tokens/foundation.css +0 -1
  98. package/src/tokens/index.css +1 -0
  99. package/src/tokens/motion.css +3 -1
  100. package/src/tokens/motion.resolver.json +135 -0
  101. package/src/tokens/native-values.json +38 -0
  102. package/src/tokens/personalization-axes.browser.test.ts +18 -3
  103. package/src/tokens/plate-scope.browser.test.ts +73 -0
  104. package/src/tokens/radius.css +12 -8
  105. package/src/tokens/radius.resolver.json +138 -0
  106. package/src/tokens/semantics.css +716 -41
  107. package/src/tokens/semantics.resolver.json +1639 -0
  108. package/src/tokens/space.css +8 -6
  109. package/src/tokens/space.tokens.json +78 -0
  110. package/src/tokens/surface.css +13 -19
  111. package/src/tokens/surface.resolver.json +706 -0
  112. package/src/tokens/swift-parity.browser.test.ts +141 -0
  113. package/src/tokens/type-roles.css +88 -0
  114. package/src/tokens/type-roles.resolver.json +419 -0
  115. package/src/tokens/type-scale.css +6 -0
  116. package/src/tokens/type-scale.resolver.json +67 -0
  117. package/generated/atom63.figma-tokens.json +0 -21664
  118. package/src/tokens/foundation/aliases.css +0 -28
  119. package/src/z-layers.ts +0 -40
@@ -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
@@ -8,18 +11,27 @@
8
11
  */
9
12
  :root {
10
13
  --a63-font-app: var(--font-family-sans);
14
+ /* Headline font role. Defaults to the app font; a page or a plate scope can set it to the serif stack while the UI stays sans. */
15
+ --a63-font-display: var(--a63-font-app);
11
16
  --font-weight-medium: 500;
12
17
  }
13
18
 
14
19
  [data-a63-font='sans'] {
15
20
  --a63-font-app: var(--font-family-sans);
21
+ --a63-font-display: var(--a63-font-app);
16
22
  }
23
+
17
24
  [data-a63-font='serif'] {
18
25
  --a63-font-app: var(--font-family-serif);
26
+ --a63-font-display: var(--a63-font-app);
19
27
  }
28
+
20
29
  [data-a63-font='mono'] {
21
30
  --a63-font-app: var(--font-family-mono);
31
+ --a63-font-display: var(--a63-font-app);
22
32
  }
33
+
23
34
  [data-a63-font='pixel'] {
24
35
  --a63-font-app: var(--font-family-pixel);
36
+ --a63-font-display: var(--a63-font-app);
25
37
  }
@@ -0,0 +1,128 @@
1
+ {
2
+ "version": "2025.10",
3
+ "description": "Font personalization axis.\n\n--a63-font-app is the active application font stack; a consumer applies it on\nthe app root (e.g. `font-family: var(--a63-font-app)` on body). [data-a63-font]\nremaps it to one of the four foundation family stacks (foundation/fonts.css).\nDefaults to the sans stack.",
4
+ "sets": {
5
+ "base": {
6
+ "sources": [
7
+ {
8
+ "a63": {
9
+ "font": {
10
+ "app": {
11
+ "$type": "fontFamily",
12
+ "$value": "{font.family.sans}"
13
+ },
14
+ "display": {
15
+ "$type": "fontFamily",
16
+ "$value": "{a63.font.app}",
17
+ "$description": "Headline font role. Defaults to the app font; a page or a plate scope can set it to the serif stack while the UI stays sans."
18
+ }
19
+ }
20
+ },
21
+ "font": {
22
+ "weight": {
23
+ "medium": {
24
+ "$type": "fontWeight",
25
+ "$value": 500
26
+ }
27
+ }
28
+ }
29
+ }
30
+ ],
31
+ "$extensions": {
32
+ "io.atom63.css": {
33
+ "selector": ":root"
34
+ }
35
+ }
36
+ }
37
+ },
38
+ "modifiers": {
39
+ "font": {
40
+ "default": "sans",
41
+ "contexts": {
42
+ "sans": [
43
+ {
44
+ "a63": {
45
+ "font": {
46
+ "app": {
47
+ "$type": "fontFamily",
48
+ "$value": "{font.family.sans}"
49
+ },
50
+ "display": {
51
+ "$type": "fontFamily",
52
+ "$value": "{a63.font.app}"
53
+ }
54
+ }
55
+ }
56
+ }
57
+ ],
58
+ "serif": [
59
+ {
60
+ "a63": {
61
+ "font": {
62
+ "app": {
63
+ "$type": "fontFamily",
64
+ "$value": "{font.family.serif}"
65
+ },
66
+ "display": {
67
+ "$type": "fontFamily",
68
+ "$value": "{a63.font.app}"
69
+ }
70
+ }
71
+ }
72
+ }
73
+ ],
74
+ "mono": [
75
+ {
76
+ "a63": {
77
+ "font": {
78
+ "app": {
79
+ "$type": "fontFamily",
80
+ "$value": "{font.family.mono}"
81
+ },
82
+ "display": {
83
+ "$type": "fontFamily",
84
+ "$value": "{a63.font.app}"
85
+ }
86
+ }
87
+ }
88
+ }
89
+ ],
90
+ "pixel": [
91
+ {
92
+ "a63": {
93
+ "font": {
94
+ "app": {
95
+ "$type": "fontFamily",
96
+ "$value": "{font.family.pixel}"
97
+ },
98
+ "display": {
99
+ "$type": "fontFamily",
100
+ "$value": "{a63.font.app}"
101
+ }
102
+ }
103
+ }
104
+ }
105
+ ]
106
+ }
107
+ }
108
+ },
109
+ "resolutionOrder": [
110
+ {
111
+ "$ref": "#/sets/base"
112
+ },
113
+ {
114
+ "$ref": "#/modifiers/font"
115
+ }
116
+ ],
117
+ "$extensions": {
118
+ "io.atom63.css": {
119
+ "attribute": "data-a63-font",
120
+ "selectors": {
121
+ "sans": "[data-a63-font='sans']",
122
+ "serif": "[data-a63-font='serif']",
123
+ "mono": "[data-a63-font='mono']",
124
+ "pixel": "[data-a63-font='pixel']"
125
+ }
126
+ }
127
+ }
128
+ }
@@ -0,0 +1,129 @@
1
+ import { afterEach, describe, expect, it } from 'vitest'
2
+ import { resetRoot, root } from '../test/apply-styles'
3
+
4
+ /*
5
+ * [data-a63-form-factor='phone'] (contracts/environment.css) gives a subtree
6
+ * the type steps and control sizing of a phone screen. Custom properties that
7
+ * read other custom properties resolve where they are declared, so these
8
+ * probes check the values a nested element actually renders with.
9
+ */
10
+
11
+ const scopes: HTMLElement[] = []
12
+
13
+ afterEach(() => {
14
+ for (const scope of scopes.splice(0)) scope.remove()
15
+ resetRoot()
16
+ })
17
+
18
+ function scope(attributes: Record<string, string> = {}): HTMLElement {
19
+ const element = document.createElement('div')
20
+ for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value)
21
+ document.body.appendChild(element)
22
+ scopes.push(element)
23
+ return element
24
+ }
25
+
26
+ /** The px a nested element renders `font-size: var(<name>)` at. */
27
+ function fontSize(parent: HTMLElement, name: string): string {
28
+ const probe = document.createElement('span')
29
+ probe.style.fontSize = `var(${name})`
30
+ parent.appendChild(probe)
31
+ return getComputedStyle(probe).fontSize
32
+ }
33
+
34
+ /** The px a nested element renders `height: var(<name>)` at. */
35
+ function height(parent: HTMLElement, name: string): string {
36
+ const probe = document.createElement('div')
37
+ probe.style.height = `var(${name})`
38
+ parent.appendChild(probe)
39
+ return getComputedStyle(probe).height
40
+ }
41
+
42
+ /** The px a nested element renders `width: <expression>` at. */
43
+ function width(parent: HTMLElement, expression: string): string {
44
+ const probe = document.createElement('div')
45
+ probe.style.width = expression
46
+ parent.appendChild(probe)
47
+ return getComputedStyle(probe).width
48
+ }
49
+
50
+ describe('phone form factor', () => {
51
+ it('sets the iOS text sizes on the type steps', () => {
52
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
53
+ expect(fontSize(phone, '--typography-base-font-size')).toBe('17px')
54
+ expect(fontSize(phone, '--typography-sm-font-size')).toBe('15px')
55
+ expect(fontSize(phone, '--typography-xs-font-size')).toBe('13px')
56
+ expect(fontSize(phone, '--typography-2xs-font-size')).toBe('11px')
57
+ expect(fontSize(phone, '--typography-6xl-font-size')).toBe('34px')
58
+ })
59
+
60
+ it('redeclares the text roles, so they follow the phone steps', () => {
61
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
62
+ expect(fontSize(phone, '--a63-type-body-font-size')).toBe('17px')
63
+ expect(fontSize(phone, '--a63-type-headline-font-size')).toBe('17px')
64
+ expect(fontSize(phone, '--a63-type-subhead-font-size')).toBe('15px')
65
+ expect(fontSize(phone, '--a63-type-footnote-font-size')).toBe('13px')
66
+ expect(fontSize(phone, '--a63-type-title-2-font-size')).toBe('22px')
67
+ expect(fontSize(phone, '--a63-type-large-title-font-size')).toBe('34px')
68
+ expect(fontSize(phone, '--a63-type-display-font-size')).toBe('40px')
69
+ })
70
+
71
+ it('sets control labels at body size and the iOS height ramp', () => {
72
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
73
+ expect(fontSize(phone, '--a63-control-font-size-xs')).toBe('13px')
74
+ expect(fontSize(phone, '--a63-control-font-size-sm')).toBe('17px')
75
+ expect(fontSize(phone, '--a63-control-font-size-md')).toBe('17px')
76
+ expect(height(phone, '--a63-control-height-sm')).toBe('40px')
77
+ expect(height(phone, '--a63-control-height-md')).toBe('44px')
78
+ })
79
+
80
+ it('keeps a secondary line below its title: subheadline size on a phone, sm elsewhere', () => {
81
+ const secondary = '--a63-control-font-size-secondary, var(--a63-control-font-size-sm)'
82
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
83
+ expect(fontSize(phone, secondary)).toBe('15px')
84
+ expect(fontSize(phone, '--a63-control-font-size-sm')).toBe('17px')
85
+ expect(fontSize(scope(), secondary)).toBe('12px')
86
+ })
87
+
88
+ it('gives the switch the iOS 26 proportions: a wide pill knob on a 63 by 28 track', () => {
89
+ // The Switch recipe's track: thumb × (1 + aspect) + 6px wide, thumb + 6px tall.
90
+ const track = 'calc(var(--a63-switch-thumb-size) * (1 + var(--a63-switch-thumb-aspect)) + 6px)'
91
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
92
+ expect(height(phone, '--a63-switch-thumb-size')).toBe('22px')
93
+ expect(Number.parseFloat(width(phone, track))).toBeCloseTo(63.2, 1)
94
+ const web = scope()
95
+ expect(height(web, '--a63-switch-thumb-size')).toBe('16px')
96
+ expect(width(web, track)).toBe('38px')
97
+ })
98
+
99
+ it('gives a grouped list the iOS row height and a rounder card, on a phone only', () => {
100
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
101
+ expect(height(phone, '--a63-inset-row-min-size')).toBe('52px')
102
+ expect(height(phone, '--a63-inset-group-radius')).toBe('18px')
103
+ // Outside a phone neither is declared, so the Item recipe takes its fallbacks.
104
+ const web = getComputedStyle(scope())
105
+ expect(web.getPropertyValue('--a63-inset-row-min-size')).toBe('')
106
+ expect(web.getPropertyValue('--a63-inset-group-radius')).toBe('')
107
+ })
108
+
109
+ it('leaves the page outside the phone scope on the web sizes', () => {
110
+ const web = scope()
111
+ expect(fontSize(web, '--typography-base-font-size')).toBe('15px')
112
+ expect(fontSize(web, '--a63-type-body-font-size')).toBe('15px')
113
+ expect(fontSize(web, '--a63-control-font-size-md')).toBe('13px')
114
+ expect(height(web, '--a63-control-height-md')).toBe('32px')
115
+ })
116
+
117
+ it('keeps the type scale preference on top of the phone steps', () => {
118
+ root().setAttribute('data-a63-type-scale', 'large')
119
+ const phone = scope({ 'data-a63-form-factor': 'phone' })
120
+ // 17px × 1.2
121
+ expect(fontSize(phone, '--a63-type-body-font-size')).toBe('20.4px')
122
+ })
123
+
124
+ it('wins over the design language on the same element', () => {
125
+ const phone = scope({ 'data-a63-design-language': 'ios', 'data-a63-form-factor': 'phone' })
126
+ expect(fontSize(phone, '--a63-control-font-size-sm')).toBe('17px')
127
+ expect(height(phone, '--a63-control-height-md')).toBe('44px')
128
+ })
129
+ })
@@ -1,9 +1,16 @@
1
- /* Effects — shared shadow + blur scales */
2
- /* Shadows override Tailwind's defaults so values match Figma tokens */
3
- /* Usage: shadow-md → var(--shadow-md) → var(--effect-shadow-md) */
4
-
5
- /* Shadow utilities read effect aliases at runtime so generated themes can swap
6
- visual depth without rebuilding Tailwind classes. */
1
+ /*
2
+ * Generated from src/tokens/foundation/effects.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
+ *
5
+ * Effects — shared shadow + blur scales
6
+ *
7
+ * Shadows override Tailwind's defaults so values match Figma tokens
8
+ *
9
+ * Usage: shadow-md → var(--shadow-md) → var(--effect-shadow-md)
10
+ *
11
+ * Shadow utilities read effect aliases at runtime so generated themes can swap
12
+ * visual depth without rebuilding Tailwind classes.
13
+ */
7
14
  :root,
8
15
  .light {
9
16
  --effect-shadow-2xs: 0px 1px 1px 0px rgb(0 0 0 / 0.04);
@@ -13,7 +20,6 @@
13
20
  --effect-shadow-lg: 0px 8px 14px -4px rgb(0 0 0 / 0.07), 0px 18px 32px -12px rgb(0 0 0 / 0.1);
14
21
  --effect-shadow-xl: 0px 14px 22px -6px rgb(0 0 0 / 0.08), 0px 34px 64px -16px rgb(0 0 0 / 0.13);
15
22
  --effect-shadow-2xl: 0px 20px 32px -8px rgb(0 0 0 / 0.1), 0px 52px 96px -18px rgb(0 0 0 / 0.14);
16
-
17
23
  /* Blur scale — canonical shared steps; Tailwind adapter re-references. */
18
24
  --blur-xs: 4px;
19
25
  --blur-sm: 8px;
@@ -23,9 +29,3 @@
23
29
  --blur-2xl: 40px;
24
30
  --blur-3xl: 64px;
25
31
  }
26
-
27
- /*
28
- * Theme-private material (gel stacks, bevels, CRT glows, skin-only blur stops)
29
- * lives under `[data-a63-theme]` in themes/*.css — not here. Promote into this
30
- * file only when a second theme or an adapter needs the same stop.
31
- */