@atom63/styles 0.1.0-beta.4 → 0.1.0-beta.6

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 (104) hide show
  1. package/README.md +14 -8
  2. package/generated/atom63.figma-sync.json +3764 -1109
  3. package/generated/atom63.tokens.json +3811 -831
  4. package/package.json +14 -7
  5. package/src/compat/a63-from-shadcn.css +10 -0
  6. package/src/contracts/action.css +4 -3
  7. package/src/contracts/action.native.css +11 -0
  8. package/src/contracts/action.tokens.json +66 -0
  9. package/src/contracts/badge.css +28 -19
  10. package/src/contracts/badge.resolver.json +366 -0
  11. package/src/contracts/choice.css +4 -1
  12. package/src/contracts/choice.native.css +9 -0
  13. package/src/contracts/choice.tokens.json +66 -0
  14. package/src/contracts/control.css +43 -52
  15. package/src/contracts/control.native.css +13 -0
  16. package/src/contracts/control.tokens.json +245 -0
  17. package/src/contracts/environment.css +45 -49
  18. package/src/contracts/environment.native.css +23 -0
  19. package/src/contracts/environment.resolver.json +569 -0
  20. package/src/contracts/field.css +3 -1
  21. package/src/contracts/field.tokens.json +40 -0
  22. package/src/contracts/marker.css +6 -4
  23. package/src/contracts/marker.tokens.json +15 -0
  24. package/src/contracts/menu.css +25 -61
  25. package/src/contracts/menu.native.css +10 -0
  26. package/src/contracts/menu.resolver.json +122 -0
  27. package/src/contracts/overlay.css +11 -13
  28. package/src/contracts/overlay.native.css +13 -0
  29. package/src/contracts/overlay.tokens.json +103 -0
  30. package/src/contracts/segment.css +22 -68
  31. package/src/contracts/segment.tokens.json +19 -0
  32. package/src/contracts/selection.css +3 -1
  33. package/src/contracts/selection.tokens.json +37 -0
  34. package/src/contracts/skeleton.css +3 -0
  35. package/src/contracts/skeleton.resolver.json +66 -0
  36. package/src/contracts/surface.css +13 -24
  37. package/src/contracts/surface.native.css +17 -0
  38. package/src/contracts/surface.tokens.json +97 -0
  39. package/src/contracts/toggle.css +3 -1
  40. package/src/contracts/toggle.tokens.json +49 -0
  41. package/src/contracts/track.css +3 -1
  42. package/src/contracts/track.tokens.json +39 -0
  43. package/src/contracts/trigger.css +5 -2
  44. package/src/contracts/trigger.native.css +9 -0
  45. package/src/contracts/trigger.tokens.json +58 -0
  46. package/src/contracts/widget.css +41 -51
  47. package/src/contracts/widget.native.css +23 -0
  48. package/src/contracts/widget.resolver.json +1104 -0
  49. package/src/tailwind/theme.css +0 -2
  50. package/src/themes/aqua.css +24 -89
  51. package/src/themes/aqua.native.css +80 -0
  52. package/src/themes/aqua.resolver.json +1292 -0
  53. package/src/themes/modern.css +10 -14
  54. package/src/themes/modern.native.css +16 -0
  55. package/src/themes/modern.resolver.json +350 -0
  56. package/src/themes/retro.css +21 -26
  57. package/src/themes/retro.native.css +16 -0
  58. package/src/themes/retro.resolver.json +788 -0
  59. package/src/themes/terminal.css +34 -41
  60. package/src/themes/terminal.native.css +22 -0
  61. package/src/themes/terminal.resolver.json +517 -0
  62. package/src/tokens/brand-action.css +50 -0
  63. package/src/tokens/brand-action.resolver.json +118 -0
  64. package/src/tokens/brand-ramp.css +108 -0
  65. package/src/tokens/brand-ramp.resolver.json +418 -0
  66. package/src/tokens/brand.css +6 -146
  67. package/src/tokens/color-mix-space.browser.test.ts +79 -0
  68. package/src/tokens/contrast.browser.test.ts +47 -3
  69. package/src/tokens/figma-parity.browser.test.ts +257 -0
  70. package/src/tokens/font.css +6 -0
  71. package/src/tokens/font.resolver.json +107 -0
  72. package/src/tokens/foundation/effects.css +13 -13
  73. package/src/tokens/foundation/effects.resolver.json +433 -0
  74. package/src/tokens/foundation/fonts.css +11 -5
  75. package/src/tokens/foundation/fonts.tokens.json +45 -0
  76. package/src/tokens/foundation/motion.css +3 -0
  77. package/src/tokens/foundation/motion.tokens.json +53 -0
  78. package/src/tokens/foundation/palette.css +3 -0
  79. package/src/tokens/foundation/palette.tokens.json +1743 -0
  80. package/src/tokens/foundation/primitives.css +20 -13
  81. package/src/tokens/foundation/primitives.tokens.json +3470 -0
  82. package/src/tokens/foundation/radius.css +6 -9
  83. package/src/tokens/foundation/radius.tokens.json +100 -0
  84. package/src/tokens/foundation/typography.css +25 -12
  85. package/src/tokens/foundation/typography.native.css +11 -0
  86. package/src/tokens/foundation/typography.resolver.json +936 -0
  87. package/src/tokens/foundation.css +0 -1
  88. package/src/tokens/motion.css +3 -1
  89. package/src/tokens/motion.resolver.json +135 -0
  90. package/src/tokens/native-values.json +38 -0
  91. package/src/tokens/personalization-axes.browser.test.ts +5 -3
  92. package/src/tokens/radius.css +12 -8
  93. package/src/tokens/radius.resolver.json +138 -0
  94. package/src/tokens/semantics.css +62 -34
  95. package/src/tokens/semantics.resolver.json +402 -0
  96. package/src/tokens/space.css +8 -6
  97. package/src/tokens/space.tokens.json +78 -0
  98. package/src/tokens/surface.css +5 -19
  99. package/src/tokens/surface.resolver.json +657 -0
  100. package/src/tokens/swift-parity.browser.test.ts +137 -0
  101. package/src/tokens/type-scale.css +6 -0
  102. package/src/tokens/type-scale.resolver.json +67 -0
  103. package/generated/atom63.figma-tokens.json +0 -21661
  104. package/src/tokens/foundation/aliases.css +0 -28
@@ -0,0 +1,137 @@
1
+ import { afterEach, describe, expect, it } from 'vitest'
2
+ import swiftTokens from '../../../ui-ios/Sources/Atom63UI/Generated/Atom63Tokens.generated.swift?raw'
3
+ // @ts-expect-error -- plain ESM module shared with the Swift generator, no types
4
+ import {
5
+ brands,
6
+ createResolver,
7
+ skins,
8
+ surfaces,
9
+ } from '../../../ui-ios/Scripts/lib/theme-graph.mjs'
10
+ import computedValues from '../../generated/atom63.computed-values.json'
11
+ import figmaModel from '../../generated/atom63.figma-sync.json'
12
+ import { resetRoot, root } from '../test/apply-styles'
13
+
14
+ /*
15
+ * Web/iOS parity: every color in the generated Swift tokens must equal what the
16
+ * browser paints for its token, in light and dark mode, with the defaults an
17
+ * app starts with (modern theme, brand b1, surface n1). The Swift generator
18
+ * reads the Figma sync model; this test checks that model against the real CSS
19
+ * cascade, so a drift in either shows up here.
20
+ */
21
+
22
+ interface Rgba {
23
+ r: number
24
+ g: number
25
+ b: number
26
+ a: number
27
+ }
28
+
29
+ const colorPattern =
30
+ /\/\/\/ (--[\w-]+)\n\s+public static let (\w+) = AtomDynamicColor\(light: AtomColorComponents\(red: ([\d.]+), green: ([\d.]+), blue: ([\d.]+), opacity: ([\d.]+)\), dark: AtomColorComponents\(red: ([\d.]+), green: ([\d.]+), blue: ([\d.]+), opacity: ([\d.]+)\)\)/g
31
+
32
+ const swiftColors = [...swiftTokens.matchAll(colorPattern)].map(match => {
33
+ const [, token, name, ...channels] = match
34
+ const n = channels.map(Number)
35
+ return {
36
+ token,
37
+ name,
38
+ light: { r: n[0] * 255, g: n[1] * 255, b: n[2] * 255, a: n[3] },
39
+ dark: { r: n[4] * 255, g: n[5] * 255, b: n[6] * 255, a: n[7] },
40
+ }
41
+ })
42
+
43
+ /** Paints the token on one pixel and reads it back as sRGB. */
44
+ function paint(token: string): Rgba {
45
+ const probe = document.createElement('div')
46
+ probe.style.color = `var(${token})`
47
+ document.body.append(probe)
48
+ const color = getComputedStyle(probe).color
49
+ probe.remove()
50
+ const canvas = document.createElement('canvas')
51
+ canvas.width = 1
52
+ canvas.height = 1
53
+ const context = canvas.getContext('2d', { colorSpace: 'srgb' })!
54
+ context.fillStyle = color
55
+ context.fillRect(0, 0, 1, 1)
56
+ const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data
57
+ return { r, g, b, a: a / 255 }
58
+ }
59
+
60
+ function setMode(mode: 'light' | 'dark') {
61
+ root().setAttribute('data-a63-design-language', 'ios')
62
+ root().setAttribute('data-a63-mode', mode)
63
+ root().classList.remove('light', 'dark')
64
+ root().classList.add(mode)
65
+ }
66
+
67
+ afterEach(() => {
68
+ resetRoot()
69
+ for (const attribute of ['data-a63-mode', 'data-a63-theme', 'data-a63-surface'])
70
+ root().removeAttribute(attribute)
71
+ root().classList.remove('light', 'dark')
72
+ })
73
+
74
+ describe('web/iOS color parity', () => {
75
+ it('reads the Swift colors', () => {
76
+ expect(swiftColors.length).toBeGreaterThan(20)
77
+ })
78
+
79
+ it('matches every Swift color to the browser value in light and dark mode', () => {
80
+ const failures: string[] = []
81
+ for (const mode of ['light', 'dark'] as const) {
82
+ setMode(mode)
83
+ for (const color of swiftColors) {
84
+ const web = paint(color.token)
85
+ const swift = color[mode]
86
+ // One 8-bit step for rounding; alpha is premultiplied by the canvas read.
87
+ const drift = Math.max(
88
+ Math.abs(web.r - swift.r),
89
+ Math.abs(web.g - swift.g),
90
+ Math.abs(web.b - swift.b),
91
+ Math.abs(web.a - swift.a) * 255
92
+ )
93
+ if (drift > 1.5) {
94
+ failures.push(
95
+ `${mode} ${color.name} (${color.token}): web rgba(${web.r}, ${web.g}, ${web.b}, ${web.a.toFixed(2)}), ` +
96
+ `swift rgba(${swift.r.toFixed(1)}, ${swift.g.toFixed(1)}, ${swift.b.toFixed(1)}, ${swift.a})`
97
+ )
98
+ }
99
+ }
100
+ }
101
+ expect(failures, failures.join('\n')).toEqual([])
102
+ })
103
+
104
+ /*
105
+ * AtomTheme(skin:brand:surface:) resolves through the token graph the Swift
106
+ * generator emits, with the same algorithm as Scripts/lib/theme-graph.mjs (the
107
+ * Swift tests check the port against that module). Here the module's result is
108
+ * checked against the browser for every skin, brand, surface and mode.
109
+ */
110
+ it('matches every color the Swift theme resolves, for every skin × brand × surface × mode', () => {
111
+ const resolver = createResolver(figmaModel, computedValues)
112
+ const failures: string[] = []
113
+ for (const skin of skins as string[])
114
+ for (const brand of brands as string[])
115
+ for (const surface of surfaces as string[])
116
+ for (const mode of ['light', 'dark'] as const) {
117
+ setMode(mode)
118
+ root().setAttribute('data-a63-theme', skin)
119
+ root().setAttribute('data-a63-brand', brand)
120
+ root().setAttribute('data-a63-surface', surface)
121
+ for (const color of swiftColors) {
122
+ const web = paint(color.token)
123
+ const graph = resolver.resolve(color.token, { skin, brand, surface, mode })
124
+ // Compare premultiplied, as the canvas stores it: a translucent
125
+ // color's channels are only exact to 1/255 after multiplying by alpha.
126
+ const drift = Math.max(
127
+ Math.abs(web.r * web.a - graph.r * 255 * graph.a),
128
+ Math.abs(web.g * web.a - graph.g * 255 * graph.a),
129
+ Math.abs(web.b * web.a - graph.b * 255 * graph.a),
130
+ Math.abs(web.a - graph.a) * 255
131
+ )
132
+ if (drift > 1.5) failures.push(`${skin}/${brand}/${surface}/${mode} ${color.name}`)
133
+ }
134
+ }
135
+ expect(failures.slice(0, 20), `${failures.length} differences`).toEqual([])
136
+ })
137
+ })
@@ -1,4 +1,7 @@
1
1
  /*
2
+ * Generated from src/tokens/type-scale.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
  * Typography personalization axis.
3
6
  *
4
7
  * [data-a63-type-scale] sets the multiplier the responsive type scale
@@ -9,12 +12,15 @@
9
12
  [data-a63-type-scale='compact'] {
10
13
  --typography-scale: 0.9;
11
14
  }
15
+
12
16
  [data-a63-type-scale='normal'] {
13
17
  --typography-scale: 1;
14
18
  }
19
+
15
20
  [data-a63-type-scale='comfortable'] {
16
21
  --typography-scale: 1.1;
17
22
  }
23
+
18
24
  [data-a63-type-scale='large'] {
19
25
  --typography-scale: 1.2;
20
26
  }
@@ -0,0 +1,67 @@
1
+ {
2
+ "version": "2025.10",
3
+ "description": "Typography personalization axis.\n\n[data-a63-type-scale] sets the multiplier the responsive type scale\n(foundation/typography.css) already multiplies every size + line-height by.\n`normal` = 1 restates the foundation default (--typography-scale defaults to 1\nvia its calc fallback) so a subtree can reset it.",
4
+ "modifiers": {
5
+ "type-scale": {
6
+ "default": "normal",
7
+ "contexts": {
8
+ "compact": [
9
+ {
10
+ "typography": {
11
+ "scale": {
12
+ "$type": "number",
13
+ "$value": 0.9
14
+ }
15
+ }
16
+ }
17
+ ],
18
+ "normal": [
19
+ {
20
+ "typography": {
21
+ "scale": {
22
+ "$type": "number",
23
+ "$value": 1
24
+ }
25
+ }
26
+ }
27
+ ],
28
+ "comfortable": [
29
+ {
30
+ "typography": {
31
+ "scale": {
32
+ "$type": "number",
33
+ "$value": 1.1
34
+ }
35
+ }
36
+ }
37
+ ],
38
+ "large": [
39
+ {
40
+ "typography": {
41
+ "scale": {
42
+ "$type": "number",
43
+ "$value": 1.2
44
+ }
45
+ }
46
+ }
47
+ ]
48
+ }
49
+ }
50
+ },
51
+ "resolutionOrder": [
52
+ {
53
+ "$ref": "#/modifiers/type-scale"
54
+ }
55
+ ],
56
+ "$extensions": {
57
+ "io.atom63.css": {
58
+ "attribute": "data-a63-type-scale",
59
+ "selectors": {
60
+ "compact": "[data-a63-type-scale='compact']",
61
+ "normal": "[data-a63-type-scale='normal']",
62
+ "comfortable": "[data-a63-type-scale='comfortable']",
63
+ "large": "[data-a63-type-scale='large']"
64
+ }
65
+ }
66
+ }
67
+ }