@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
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { afterEach, describe, expect, it } from 'vitest'
|
|
2
|
+
import { resetRoot, root } from '../test/apply-styles'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* [data-a63-density] (contracts/environment.css) sets --a63-space-unit. The
|
|
6
|
+
* space steps, control heights, paddings and gaps are built on it at :root, and
|
|
7
|
+
* a custom property that reads another resolves where it is declared, so the
|
|
8
|
+
* density scope declares them again. These probes check what a nested element
|
|
9
|
+
* renders with, on <html> and on a nested scope (UIProvider density="compact").
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const scopes: HTMLElement[] = []
|
|
13
|
+
|
|
14
|
+
afterEach(() => {
|
|
15
|
+
for (const scope of scopes.splice(0)) scope.remove()
|
|
16
|
+
root().removeAttribute('data-a63-density')
|
|
17
|
+
resetRoot()
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
function scope(attributes: Record<string, string> = {}, parent: HTMLElement = document.body) {
|
|
21
|
+
const element = document.createElement('div')
|
|
22
|
+
for (const [name, value] of Object.entries(attributes)) element.setAttribute(name, value)
|
|
23
|
+
parent.appendChild(element)
|
|
24
|
+
if (parent === document.body) scopes.push(element)
|
|
25
|
+
return element
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** The px a nested element renders `height: <expression>` at. */
|
|
29
|
+
function height(parent: HTMLElement, expression: string): string {
|
|
30
|
+
const probe = document.createElement('div')
|
|
31
|
+
probe.style.height = expression
|
|
32
|
+
parent.appendChild(probe)
|
|
33
|
+
return getComputedStyle(probe).height
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const token = (name: string) => `var(${name})`
|
|
37
|
+
/** The height a control recipe draws a size at (button.css, input.css and the rest). */
|
|
38
|
+
const controlHeight = (size: string) =>
|
|
39
|
+
`max(calc(var(--a63-control-height-${size}) * var(--a63-density-scale, 1)), var(--a63-control-min-size))`
|
|
40
|
+
|
|
41
|
+
/** What compact density renders at: the 4px unit becomes 3.5px, once. */
|
|
42
|
+
function expectCompact(element: HTMLElement) {
|
|
43
|
+
expect(height(element, token('--a63-space-unit'))).toBe('3.5px')
|
|
44
|
+
expect(height(element, token('--a63-space-4'))).toBe('14px')
|
|
45
|
+
expect(height(element, token('--a63-space-1_5'))).toBe('5.25px')
|
|
46
|
+
expect(height(element, token('--a63-control-height-md'))).toBe('28px')
|
|
47
|
+
expect(height(element, controlHeight('md'))).toBe('28px')
|
|
48
|
+
expect(height(element, controlHeight('lg'))).toBe('32px')
|
|
49
|
+
// xs is 21px, so the 24px pointer floor holds it.
|
|
50
|
+
expect(height(element, controlHeight('xs'))).toBe('24px')
|
|
51
|
+
expect(height(element, token('--a63-control-padding-inline-md'))).toBe('10.5px')
|
|
52
|
+
expect(height(element, token('--a63-control-gap'))).toBe('7px')
|
|
53
|
+
expect(height(element, token('--a63-trigger-gap'))).toBe('7px')
|
|
54
|
+
expect(height(element, token('--a63-row-padding-block-sm'))).toBe('11px')
|
|
55
|
+
expect(height(element, token('--a63-menu-item-padding-inline'))).toBe('7px')
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
function expectComfortable(element: HTMLElement) {
|
|
59
|
+
expect(height(element, token('--a63-space-4'))).toBe('16px')
|
|
60
|
+
expect(height(element, controlHeight('md'))).toBe('32px')
|
|
61
|
+
expect(height(element, token('--a63-control-padding-inline-md'))).toBe('12px')
|
|
62
|
+
expect(height(element, token('--a63-row-padding-block-sm'))).toBe('12px')
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
describe('density', () => {
|
|
66
|
+
it('leaves the default sizes alone', () => {
|
|
67
|
+
expectComfortable(scope())
|
|
68
|
+
})
|
|
69
|
+
|
|
70
|
+
it('compact on <html> scales spacing and control heights once', () => {
|
|
71
|
+
root().setAttribute('data-a63-density', 'compact')
|
|
72
|
+
expectCompact(scope())
|
|
73
|
+
})
|
|
74
|
+
|
|
75
|
+
it('compact on a nested scope scales spacing and control heights the same way', () => {
|
|
76
|
+
expectCompact(scope({ 'data-a63-density': 'compact' }))
|
|
77
|
+
// The legacy attribute name works too.
|
|
78
|
+
expectCompact(scope({ 'data-density': 'compact' }))
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it('a nested comfortable scope restores the default sizes under a compact root', () => {
|
|
82
|
+
root().setAttribute('data-a63-density', 'compact')
|
|
83
|
+
expectComfortable(scope({ 'data-a63-density': 'comfortable' }))
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('keeps the iOS height ramp in a compact scope inside the iOS design language', () => {
|
|
87
|
+
const ios = scope({ 'data-a63-design-language': 'ios' })
|
|
88
|
+
const compact = scope({ 'data-a63-density': 'compact' }, ios)
|
|
89
|
+
// iOS md is 11 units: 44px, and 38.5px at the compact unit, rounded to 39px.
|
|
90
|
+
expect(height(ios, controlHeight('md'))).toBe('44px')
|
|
91
|
+
expect(height(compact, controlHeight('md'))).toBe('39px')
|
|
92
|
+
expect(height(compact, token('--a63-control-padding-inline-md'))).toBe('14px')
|
|
93
|
+
// On the same element.
|
|
94
|
+
const both = scope({ 'data-a63-design-language': 'ios', 'data-a63-density': 'compact' })
|
|
95
|
+
expect(height(both, controlHeight('md'))).toBe('39px')
|
|
96
|
+
})
|
|
97
|
+
|
|
98
|
+
it('keeps the phone sizes in a compact scope inside a phone screen', () => {
|
|
99
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
100
|
+
const compact = scope({ 'data-a63-density': 'compact' }, phone)
|
|
101
|
+
expect(height(compact, controlHeight('md'))).toBe('39px')
|
|
102
|
+
expect(height(compact, token('--a63-inset-row-min-size'))).toBe('46px')
|
|
103
|
+
expect(getComputedStyle(compact).getPropertyValue('--a63-control-font-size-md').trim()).toBe(
|
|
104
|
+
getComputedStyle(phone).getPropertyValue('--a63-control-font-size-md').trim()
|
|
105
|
+
)
|
|
106
|
+
})
|
|
107
|
+
|
|
108
|
+
it('lands every control height and row padding on whole pixels in every density', () => {
|
|
109
|
+
const sizes = ['xs', 'sm', 'md', 'lg', 'xl']
|
|
110
|
+
const tokens = [
|
|
111
|
+
...sizes.map(size => token(`--a63-control-height-${size}`)),
|
|
112
|
+
...sizes.map(controlHeight),
|
|
113
|
+
...['xs', 'sm', 'md'].map(size => token(`--a63-row-padding-block-${size}`)),
|
|
114
|
+
]
|
|
115
|
+
for (const density of ['compact', 'comfortable', undefined]) {
|
|
116
|
+
for (const scopeAttributes of [
|
|
117
|
+
{},
|
|
118
|
+
{ 'data-a63-design-language': 'ios' },
|
|
119
|
+
{ 'data-a63-form-factor': 'phone' },
|
|
120
|
+
]) {
|
|
121
|
+
const element = scope({
|
|
122
|
+
...scopeAttributes,
|
|
123
|
+
...(density ? { 'data-a63-density': density } : {}),
|
|
124
|
+
})
|
|
125
|
+
for (const expression of [
|
|
126
|
+
...tokens,
|
|
127
|
+
...(scopeAttributes['data-a63-form-factor' as keyof typeof scopeAttributes]
|
|
128
|
+
? [token('--a63-inset-row-min-size')]
|
|
129
|
+
: []),
|
|
130
|
+
]) {
|
|
131
|
+
const px = Number.parseFloat(height(element, expression))
|
|
132
|
+
expect(
|
|
133
|
+
Number.isInteger(px),
|
|
134
|
+
`${expression} in ${density} ${JSON.stringify(scopeAttributes)}: ${px}`
|
|
135
|
+
).toBe(true)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
})
|
|
140
|
+
|
|
141
|
+
it('does not change text sizes', () => {
|
|
142
|
+
const compact = scope({ 'data-a63-density': 'compact' })
|
|
143
|
+
const probe = document.createElement('span')
|
|
144
|
+
probe.style.fontSize = 'var(--a63-control-font-size-md)'
|
|
145
|
+
compact.appendChild(probe)
|
|
146
|
+
expect(getComputedStyle(probe).fontSize).toBe('13px')
|
|
147
|
+
})
|
|
148
|
+
})
|
|
149
|
+
|
|
150
|
+
describe('root text', () => {
|
|
151
|
+
it('sets text without a size class to the body role, and keeps 1rem at 16px', () => {
|
|
152
|
+
const text = document.createElement('p')
|
|
153
|
+
document.body.appendChild(text)
|
|
154
|
+
expect(getComputedStyle(text).fontSize).toBe('15px')
|
|
155
|
+
expect(getComputedStyle(text).lineHeight).toBe('23px')
|
|
156
|
+
expect(getComputedStyle(document.documentElement).fontSize).toBe('16px')
|
|
157
|
+
text.remove()
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('sets the phone body role inside a phone screen', () => {
|
|
161
|
+
const phone = scope({ 'data-a63-form-factor': 'phone' })
|
|
162
|
+
const text = document.createElement('p')
|
|
163
|
+
phone.appendChild(text)
|
|
164
|
+
expect(getComputedStyle(text).fontSize).toBe('17px')
|
|
165
|
+
expect(getComputedStyle(text).lineHeight).toBe('22px')
|
|
166
|
+
})
|
|
167
|
+
})
|
|
@@ -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
|
+
})
|
package/src/tokens/font.css
CHANGED
|
@@ -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
|
+
}
|