@primitiv-ui/tokens 0.1.28 → 0.1.30
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/README.md +30 -2
- package/package.json +1 -1
- package/src/breakpoint.json +10 -0
- package/src/code-typography.test.ts +64 -0
- package/src/context.json +10501 -4489
- package/src/dark-mode-content.test.ts +168 -9
- package/src/dtcg.ts +1 -1
- package/src/heading-tracking.test.ts +88 -0
- package/src/intent.json +438 -22
- package/src/palette.json +534 -30
- package/src/primitives.json +8 -0
- package/src/swatch-sizing.test.ts +76 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import context from './context.json'
|
|
2
|
+
import primitives from './primitives.json'
|
|
3
|
+
|
|
4
|
+
/*
|
|
5
|
+
* `swatch.*` — the geometry of a Harmoni colour swatch.
|
|
6
|
+
*
|
|
7
|
+
* Why it needs its own family rather than borrowing one: a swatch is not a
|
|
8
|
+
* control (`framed-control.*` is a thing you click) and not a surface
|
|
9
|
+
* (`surface.*` is a thing you put content on). It is a specimen — a colour
|
|
10
|
+
* box that prints facts about itself — and its box wants to grow far past any
|
|
11
|
+
* control height at `xl` while its padding stays tight. Borrowing either
|
|
12
|
+
* family would have coupled it to a scale chosen for a different job.
|
|
13
|
+
*
|
|
14
|
+
* The two ladders below are what make the `Size` and density axes mean
|
|
15
|
+
* anything. They are asserted rather than eyeballed because a single
|
|
16
|
+
* mis-keyed alias — `{space.space-8}` where `{space.space-4}` belongs — is
|
|
17
|
+
* invisible in a 120-cell table and shows up only as one size looking wrong.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
type Mode = 'dense' | 'compact' | 'comfortable' | 'spacious'
|
|
21
|
+
type DtcgNode = { $type?: string; $value?: unknown; [key: string]: unknown }
|
|
22
|
+
|
|
23
|
+
/** Ascending by design: each mode is roomier than the one before it. */
|
|
24
|
+
const MODES: Mode[] = ['dense', 'compact', 'comfortable', 'spacious']
|
|
25
|
+
/** Ascending by design: each size is larger than the one before it. */
|
|
26
|
+
const SIZES = ['xs', 'sm', 'md', 'lg', 'xl'] as const
|
|
27
|
+
const MEMBERS = ['box', 'panel-cap', 'sample-size', 'sample-caption-size', 'min-height', 'radius', 'padding-inline', 'padding-block', 'gap'] as const
|
|
28
|
+
|
|
29
|
+
function member(mode: Mode, size: string, name: string): DtcgNode | undefined {
|
|
30
|
+
const swatch = (context as Record<Mode, DtcgNode>)[mode].swatch as DtcgNode | undefined
|
|
31
|
+
return (swatch?.[size] as DtcgNode | undefined)?.[name] as DtcgNode | undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Resolve a DTCG alias (`{space.space-8}`) against the primitive tree. */
|
|
35
|
+
function resolvePrimitive(ref: string): number {
|
|
36
|
+
const path = ref.slice(1, -1).split('.')
|
|
37
|
+
let node: DtcgNode = primitives as DtcgNode
|
|
38
|
+
for (const key of path) node = node[key] as DtcgNode
|
|
39
|
+
return node.$value as number
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function value(mode: Mode, size: string, name: string): number {
|
|
43
|
+
return resolvePrimitive(member(mode, size, name)?.$value as string)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
describe('swatch sizing', () => {
|
|
47
|
+
for (const mode of MODES) {
|
|
48
|
+
for (const size of SIZES) {
|
|
49
|
+
it(`${mode} / swatch / ${size} carries every member, aliased to a primitive`, () => {
|
|
50
|
+
for (const name of MEMBERS) {
|
|
51
|
+
const node = member(mode, size, name)
|
|
52
|
+
expect(node, `${mode}.swatch.${size}.${name} is missing`).toBeDefined()
|
|
53
|
+
expect(node?.$type).toBe('number')
|
|
54
|
+
expect(String(node?.$value)).toMatch(/^\{[a-z-]+\.[a-z0-9-]+\}$/)
|
|
55
|
+
expect(typeof resolvePrimitive(node?.$value as string)).toBe('number')
|
|
56
|
+
}
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
for (const name of MEMBERS) {
|
|
62
|
+
it(`${name} never shrinks as the size grows`, () => {
|
|
63
|
+
for (const mode of MODES) {
|
|
64
|
+
const ladder = SIZES.map((size) => value(mode, size, name))
|
|
65
|
+
expect(ladder, `${mode}.swatch.*.${name}`).toEqual([...ladder].sort((a, b) => a - b))
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
it(`${name} never shrinks as the density loosens`, () => {
|
|
70
|
+
for (const size of SIZES) {
|
|
71
|
+
const ladder = MODES.map((mode) => value(mode, size, name))
|
|
72
|
+
expect(ladder, `*.swatch.${size}.${name}`).toEqual([...ladder].sort((a, b) => a - b))
|
|
73
|
+
}
|
|
74
|
+
})
|
|
75
|
+
}
|
|
76
|
+
})
|