@payfit/unity-themes 2.55.22 → 2.56.0
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/dist/esm/scripts/style-dictionary-config.d.ts +14 -0
- package/package.json +14 -5
- package/skills/unity-themes/SKILL.md +45 -0
- package/src/agent-references/manifest.json +16 -0
- package/src/agent-references/tokens-catalog.json +13891 -0
- package/dist/esm/scripts/agent-references/color-reference.d.ts +0 -37
- package/src/agent-references/README.mdx +0 -25
- package/src/agent-references/primitive-colors.mdx +0 -18
- package/src/agent-references/semantic-border-colors.mdx +0 -16
- package/src/agent-references/semantic-content-colors.mdx +0 -16
- package/src/agent-references/semantic-surface-colors.mdx +0 -16
- package/src/agent-references/semantic-utility-colors.mdx +0 -16
- package/src/components/unity-theme-provider.stories.tsx +0 -532
- package/src/components/unity-theme-provider.test.tsx +0 -150
- package/src/components/unity-theme-provider.tsx +0 -72
- package/src/index.ts +0 -15
- package/src/scripts/actions/append-animations.ts +0 -73
- package/src/scripts/actions/compose-multi-theme.ts +0 -59
- package/src/scripts/agent-references/color-reference.test.ts +0 -140
- package/src/scripts/agent-references/color-reference.ts +0 -348
- package/src/scripts/build.ts +0 -420
- package/src/scripts/file-headers/unity.ts +0 -31
- package/src/scripts/formats/processors/grid-processor.test.ts +0 -378
- package/src/scripts/formats/processors/grid-processor.ts +0 -64
- package/src/scripts/formats/processors/typography-processor.test.ts +0 -111
- package/src/scripts/formats/processors/typography-processor.ts +0 -48
- package/src/scripts/formats/unity-theme.test.ts +0 -329
- package/src/scripts/formats/unity-theme.ts +0 -54
- package/src/scripts/formats/utils.test.ts +0 -264
- package/src/scripts/formats/utils.ts +0 -15
- package/src/scripts/transforms/oklch.test.ts +0 -166
- package/src/scripts/transforms/oklch.ts +0 -19
- package/src/scripts/transforms/tailwind-animation-token.test.ts +0 -108
- package/src/scripts/transforms/tailwind-animation-token.ts +0 -51
- package/src/scripts/transforms/tailwind-color-token.test.ts +0 -304
- package/src/scripts/transforms/tailwind-color-token.ts +0 -17
- package/src/scripts/transforms/tailwind-grid-token.test.ts +0 -114
- package/src/scripts/transforms/tailwind-grid-token.ts +0 -27
- package/src/scripts/transforms/tailwind-spacing-token.test.ts +0 -315
- package/src/scripts/transforms/tailwind-spacing-token.ts +0 -24
- package/src/scripts/transforms/tailwind-text-token.test.ts +0 -328
- package/src/scripts/transforms/tailwind-text-token.ts +0 -30
- package/src/scripts/transforms/tailwind-typography-token.test.ts +0 -55
- package/src/scripts/transforms/tailwind-typography-token.ts +0 -20
- package/src/scripts/types.ts +0 -30
- package/src/scripts/utils/prefix-transform.test.ts +0 -137
- package/src/scripts/utils/prefix-transform.ts +0 -16
- package/src/utils/cn.ts +0 -109
- package/src/utils/merge-config.ts +0 -194
- package/src/utils/tailwind-merge.test.ts +0 -462
- package/src/utils/tailwind-merge.ts +0 -77
- package/src/utils/tailwind-variants.ts +0 -53
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
import type { Config, Dictionary, LocalOptions } from 'style-dictionary/types'
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
|
|
5
|
-
import { processGridTokens } from './grid-processor.js'
|
|
6
|
-
|
|
7
|
-
describe('processGridTokens', () => {
|
|
8
|
-
const createMockOptions = (prefix?: string): Config & LocalOptions => ({
|
|
9
|
-
prefix,
|
|
10
|
-
platforms: {},
|
|
11
|
-
source: [],
|
|
12
|
-
include: [],
|
|
13
|
-
exclude: [],
|
|
14
|
-
files: [],
|
|
15
|
-
transform: {},
|
|
16
|
-
transformGroup: {},
|
|
17
|
-
format: {},
|
|
18
|
-
action: {},
|
|
19
|
-
fileHeader: '',
|
|
20
|
-
log: {},
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
it('should return empty string when no grid tokens are provided', () => {
|
|
24
|
-
const dictionary: Dictionary = {
|
|
25
|
-
tokens: {},
|
|
26
|
-
allTokens: [],
|
|
27
|
-
properties: {},
|
|
28
|
-
usesReference: () => false,
|
|
29
|
-
getReferences: () => [],
|
|
30
|
-
transformTokens: () => [],
|
|
31
|
-
} as unknown as Dictionary
|
|
32
|
-
|
|
33
|
-
const options = createMockOptions()
|
|
34
|
-
const result = processGridTokens(dictionary, options)
|
|
35
|
-
|
|
36
|
-
expect(result).toMatchInlineSnapshot(`""`)
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
it('should generate single grid utility with default breakpoint only', () => {
|
|
40
|
-
const dictionary: Dictionary = {
|
|
41
|
-
tokens: {
|
|
42
|
-
grid: {
|
|
43
|
-
layout: {
|
|
44
|
-
default: {
|
|
45
|
-
columns: { $value: 6 },
|
|
46
|
-
gutter: { $value: '1rem' },
|
|
47
|
-
margin: { $value: '1rem' },
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
breakpoint: {
|
|
52
|
-
md: { $value: '768px' },
|
|
53
|
-
lg: { $value: '1024px' },
|
|
54
|
-
},
|
|
55
|
-
},
|
|
56
|
-
allTokens: [],
|
|
57
|
-
properties: {},
|
|
58
|
-
usesReference: () => false,
|
|
59
|
-
getReferences: () => [],
|
|
60
|
-
transformTokens: () => [],
|
|
61
|
-
} as unknown as Dictionary
|
|
62
|
-
|
|
63
|
-
const options = createMockOptions()
|
|
64
|
-
const result = processGridTokens(dictionary, options)
|
|
65
|
-
|
|
66
|
-
expect(result).toMatchInlineSnapshot(`
|
|
67
|
-
"@utility grid-layout {
|
|
68
|
-
display: grid;
|
|
69
|
-
grid-template-columns: repeat(var(--grid-layout-columns--default), 1fr);
|
|
70
|
-
grid-gap: var(--grid-layout-gutter--default);
|
|
71
|
-
margin: 0 var(--grid-layout-margin--default);
|
|
72
|
-
}
|
|
73
|
-
"
|
|
74
|
-
`)
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
it('should generate grid utility with responsive breakpoints', () => {
|
|
78
|
-
const dictionary: Dictionary = {
|
|
79
|
-
tokens: {
|
|
80
|
-
grid: {
|
|
81
|
-
layout: {
|
|
82
|
-
default: {
|
|
83
|
-
columns: { $value: 6 },
|
|
84
|
-
gutter: { $value: '1rem' },
|
|
85
|
-
margin: { $value: '1rem' },
|
|
86
|
-
},
|
|
87
|
-
md: {
|
|
88
|
-
columns: { $value: 12 },
|
|
89
|
-
gutter: { $value: '1.5rem' },
|
|
90
|
-
margin: { $value: '2rem' },
|
|
91
|
-
},
|
|
92
|
-
lg: {
|
|
93
|
-
columns: { $value: 12 },
|
|
94
|
-
gutter: { $value: '2rem' },
|
|
95
|
-
margin: { $value: '3rem' },
|
|
96
|
-
},
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
breakpoint: {
|
|
100
|
-
md: { $value: '768px' },
|
|
101
|
-
lg: { $value: '1024px' },
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
allTokens: [],
|
|
105
|
-
properties: {},
|
|
106
|
-
usesReference: () => false,
|
|
107
|
-
getReferences: () => [],
|
|
108
|
-
transformTokens: () => [],
|
|
109
|
-
} as unknown as Dictionary
|
|
110
|
-
|
|
111
|
-
const options = createMockOptions()
|
|
112
|
-
const result = processGridTokens(dictionary, options)
|
|
113
|
-
|
|
114
|
-
expect(result).toMatchInlineSnapshot(`
|
|
115
|
-
"@utility grid-layout {
|
|
116
|
-
display: grid;
|
|
117
|
-
grid-template-columns: repeat(var(--grid-layout-columns--default), 1fr);
|
|
118
|
-
grid-gap: var(--grid-layout-gutter--default);
|
|
119
|
-
margin: 0 var(--grid-layout-margin--default);
|
|
120
|
-
@media screen and (min-width: 768px) {
|
|
121
|
-
grid-template-columns: repeat(var(--grid-layout-columns--md), 1fr);
|
|
122
|
-
grid-gap: var(--grid-layout-gutter--md);
|
|
123
|
-
margin: 0 var(--grid-layout-margin--md);
|
|
124
|
-
}
|
|
125
|
-
@media screen and (min-width: 1024px) {
|
|
126
|
-
grid-template-columns: repeat(var(--grid-layout-columns--lg), 1fr);
|
|
127
|
-
grid-gap: var(--grid-layout-gutter--lg);
|
|
128
|
-
margin: 0 var(--grid-layout-margin--lg);
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
"
|
|
132
|
-
`)
|
|
133
|
-
})
|
|
134
|
-
|
|
135
|
-
it('should generate multiple grid utilities', () => {
|
|
136
|
-
const dictionary: Dictionary = {
|
|
137
|
-
tokens: {
|
|
138
|
-
grid: {
|
|
139
|
-
layout: {
|
|
140
|
-
default: {
|
|
141
|
-
columns: { $value: 6 },
|
|
142
|
-
gutter: { $value: '1rem' },
|
|
143
|
-
margin: { $value: '1rem' },
|
|
144
|
-
},
|
|
145
|
-
md: {
|
|
146
|
-
columns: { $value: 12 },
|
|
147
|
-
gutter: { $value: '1.5rem' },
|
|
148
|
-
margin: { $value: '2rem' },
|
|
149
|
-
},
|
|
150
|
-
},
|
|
151
|
-
sidebar: {
|
|
152
|
-
default: {
|
|
153
|
-
columns: { $value: 4 },
|
|
154
|
-
gutter: { $value: '0.5rem' },
|
|
155
|
-
margin: { $value: '0.5rem' },
|
|
156
|
-
},
|
|
157
|
-
lg: {
|
|
158
|
-
columns: { $value: 6 },
|
|
159
|
-
gutter: { $value: '1rem' },
|
|
160
|
-
margin: { $value: '1rem' },
|
|
161
|
-
},
|
|
162
|
-
},
|
|
163
|
-
},
|
|
164
|
-
breakpoint: {
|
|
165
|
-
md: { $value: '768px' },
|
|
166
|
-
lg: { $value: '1024px' },
|
|
167
|
-
},
|
|
168
|
-
},
|
|
169
|
-
allTokens: [],
|
|
170
|
-
properties: {},
|
|
171
|
-
usesReference: () => false,
|
|
172
|
-
getReferences: () => [],
|
|
173
|
-
transformTokens: () => [],
|
|
174
|
-
} as unknown as Dictionary
|
|
175
|
-
|
|
176
|
-
const options = createMockOptions()
|
|
177
|
-
const result = processGridTokens(dictionary, options)
|
|
178
|
-
|
|
179
|
-
expect(result).toMatchInlineSnapshot(`
|
|
180
|
-
"@utility grid-layout {
|
|
181
|
-
display: grid;
|
|
182
|
-
grid-template-columns: repeat(var(--grid-layout-columns--default), 1fr);
|
|
183
|
-
grid-gap: var(--grid-layout-gutter--default);
|
|
184
|
-
margin: 0 var(--grid-layout-margin--default);
|
|
185
|
-
@media screen and (min-width: 768px) {
|
|
186
|
-
grid-template-columns: repeat(var(--grid-layout-columns--md), 1fr);
|
|
187
|
-
grid-gap: var(--grid-layout-gutter--md);
|
|
188
|
-
margin: 0 var(--grid-layout-margin--md);
|
|
189
|
-
}
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
@utility grid-sidebar {
|
|
193
|
-
display: grid;
|
|
194
|
-
grid-template-columns: repeat(var(--grid-sidebar-columns--default), 1fr);
|
|
195
|
-
grid-gap: var(--grid-sidebar-gutter--default);
|
|
196
|
-
margin: 0 var(--grid-sidebar-margin--default);
|
|
197
|
-
@media screen and (min-width: 1024px) {
|
|
198
|
-
grid-template-columns: repeat(var(--grid-sidebar-columns--lg), 1fr);
|
|
199
|
-
grid-gap: var(--grid-sidebar-gutter--lg);
|
|
200
|
-
margin: 0 var(--grid-sidebar-margin--lg);
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
"
|
|
204
|
-
`)
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
it('should apply prefix to variable names when provided', () => {
|
|
208
|
-
const dictionary: Dictionary = {
|
|
209
|
-
tokens: {
|
|
210
|
-
grid: {
|
|
211
|
-
layout: {
|
|
212
|
-
default: {
|
|
213
|
-
columns: { $value: 6 },
|
|
214
|
-
gutter: { $value: '1rem' },
|
|
215
|
-
margin: { $value: '1rem' },
|
|
216
|
-
},
|
|
217
|
-
md: {
|
|
218
|
-
columns: { $value: 12 },
|
|
219
|
-
gutter: { $value: '1.5rem' },
|
|
220
|
-
margin: { $value: '2rem' },
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
},
|
|
224
|
-
breakpoint: {
|
|
225
|
-
md: { $value: '768px' },
|
|
226
|
-
},
|
|
227
|
-
},
|
|
228
|
-
allTokens: [],
|
|
229
|
-
properties: {},
|
|
230
|
-
usesReference: () => false,
|
|
231
|
-
getReferences: () => [],
|
|
232
|
-
transformTokens: () => [],
|
|
233
|
-
} as unknown as Dictionary
|
|
234
|
-
|
|
235
|
-
const options = createMockOptions('uy')
|
|
236
|
-
const result = processGridTokens(dictionary, options)
|
|
237
|
-
|
|
238
|
-
expect(result).toMatchInlineSnapshot(`
|
|
239
|
-
"@utility grid-layout {
|
|
240
|
-
display: grid;
|
|
241
|
-
grid-template-columns: repeat(var(--uy-grid-layout-columns--default), 1fr);
|
|
242
|
-
grid-gap: var(--uy-grid-layout-gutter--default);
|
|
243
|
-
margin: 0 var(--uy-grid-layout-margin--default);
|
|
244
|
-
@media screen and (min-width: 768px) {
|
|
245
|
-
grid-template-columns: repeat(var(--uy-grid-layout-columns--md), 1fr);
|
|
246
|
-
grid-gap: var(--uy-grid-layout-gutter--md);
|
|
247
|
-
margin: 0 var(--uy-grid-layout-margin--md);
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
"
|
|
251
|
-
`)
|
|
252
|
-
})
|
|
253
|
-
|
|
254
|
-
it('should skip breakpoints not defined in breakpoint tokens', () => {
|
|
255
|
-
const dictionary: Dictionary = {
|
|
256
|
-
tokens: {
|
|
257
|
-
grid: {
|
|
258
|
-
layout: {
|
|
259
|
-
default: {
|
|
260
|
-
columns: { $value: 6 },
|
|
261
|
-
gutter: { $value: '1rem' },
|
|
262
|
-
margin: { $value: '1rem' },
|
|
263
|
-
},
|
|
264
|
-
custom: {
|
|
265
|
-
columns: { $value: 8 },
|
|
266
|
-
gutter: { $value: '1.2rem' },
|
|
267
|
-
margin: { $value: '1.5rem' },
|
|
268
|
-
},
|
|
269
|
-
},
|
|
270
|
-
},
|
|
271
|
-
breakpoint: {
|
|
272
|
-
md: { $value: '768px' },
|
|
273
|
-
// Note: 'custom' breakpoint is not defined here
|
|
274
|
-
},
|
|
275
|
-
},
|
|
276
|
-
allTokens: [],
|
|
277
|
-
properties: {},
|
|
278
|
-
usesReference: () => false,
|
|
279
|
-
getReferences: () => [],
|
|
280
|
-
transformTokens: () => [],
|
|
281
|
-
} as unknown as Dictionary
|
|
282
|
-
|
|
283
|
-
const options = createMockOptions()
|
|
284
|
-
const result = processGridTokens(dictionary, options)
|
|
285
|
-
|
|
286
|
-
expect(result).toMatchInlineSnapshot(`
|
|
287
|
-
"@utility grid-layout {
|
|
288
|
-
display: grid;
|
|
289
|
-
grid-template-columns: repeat(var(--grid-layout-columns--default), 1fr);
|
|
290
|
-
grid-gap: var(--grid-layout-gutter--default);
|
|
291
|
-
margin: 0 var(--grid-layout-margin--default);
|
|
292
|
-
}
|
|
293
|
-
"
|
|
294
|
-
`)
|
|
295
|
-
})
|
|
296
|
-
|
|
297
|
-
it('should handle missing breakpoint token values', () => {
|
|
298
|
-
const dictionary: Dictionary = {
|
|
299
|
-
tokens: {
|
|
300
|
-
grid: {
|
|
301
|
-
layout: {
|
|
302
|
-
default: {
|
|
303
|
-
columns: { $value: 6 },
|
|
304
|
-
gutter: { $value: '1rem' },
|
|
305
|
-
margin: { $value: '1rem' },
|
|
306
|
-
},
|
|
307
|
-
md: {
|
|
308
|
-
columns: { $value: 12 },
|
|
309
|
-
gutter: { $value: '1.5rem' },
|
|
310
|
-
margin: { $value: '2rem' },
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
},
|
|
314
|
-
breakpoint: {
|
|
315
|
-
md: {}, // Missing $value
|
|
316
|
-
},
|
|
317
|
-
},
|
|
318
|
-
allTokens: [],
|
|
319
|
-
properties: {},
|
|
320
|
-
usesReference: () => false,
|
|
321
|
-
getReferences: () => [],
|
|
322
|
-
transformTokens: () => [],
|
|
323
|
-
} as unknown as Dictionary
|
|
324
|
-
|
|
325
|
-
const options = createMockOptions()
|
|
326
|
-
const result = processGridTokens(dictionary, options)
|
|
327
|
-
|
|
328
|
-
expect(result).toMatchInlineSnapshot(`
|
|
329
|
-
"@utility grid-layout {
|
|
330
|
-
display: grid;
|
|
331
|
-
grid-template-columns: repeat(var(--grid-layout-columns--default), 1fr);
|
|
332
|
-
grid-gap: var(--grid-layout-gutter--default);
|
|
333
|
-
margin: 0 var(--grid-layout-margin--default);
|
|
334
|
-
@media screen and (min-width: undefined) {
|
|
335
|
-
grid-template-columns: repeat(var(--grid-layout-columns--md), 1fr);
|
|
336
|
-
grid-gap: var(--grid-layout-gutter--md);
|
|
337
|
-
margin: 0 var(--grid-layout-margin--md);
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
"
|
|
341
|
-
`)
|
|
342
|
-
})
|
|
343
|
-
|
|
344
|
-
it('should handle complex identifier names', () => {
|
|
345
|
-
const dictionary: Dictionary = {
|
|
346
|
-
tokens: {
|
|
347
|
-
grid: {
|
|
348
|
-
'main-content': {
|
|
349
|
-
default: {
|
|
350
|
-
columns: { $value: 8 },
|
|
351
|
-
gutter: { $value: '1rem' },
|
|
352
|
-
margin: { $value: '1rem' },
|
|
353
|
-
},
|
|
354
|
-
},
|
|
355
|
-
},
|
|
356
|
-
breakpoint: {},
|
|
357
|
-
},
|
|
358
|
-
allTokens: [],
|
|
359
|
-
properties: {},
|
|
360
|
-
usesReference: () => false,
|
|
361
|
-
getReferences: () => [],
|
|
362
|
-
transformTokens: () => [],
|
|
363
|
-
} as unknown as Dictionary
|
|
364
|
-
|
|
365
|
-
const options = createMockOptions()
|
|
366
|
-
const result = processGridTokens(dictionary, options)
|
|
367
|
-
|
|
368
|
-
expect(result).toMatchInlineSnapshot(`
|
|
369
|
-
"@utility grid-main-content {
|
|
370
|
-
display: grid;
|
|
371
|
-
grid-template-columns: repeat(var(--grid-main-content-columns--default), 1fr);
|
|
372
|
-
grid-gap: var(--grid-main-content-gutter--default);
|
|
373
|
-
margin: 0 var(--grid-main-content-margin--default);
|
|
374
|
-
}
|
|
375
|
-
"
|
|
376
|
-
`)
|
|
377
|
-
})
|
|
378
|
-
})
|
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { Config, Dictionary, LocalOptions } from 'style-dictionary/types'
|
|
2
|
-
|
|
3
|
-
/*
|
|
4
|
-
convert each grid token inside `grid` category to a tailwindcss utility. Each grid token has structure:
|
|
5
|
-
grid > {identifier} > {breakpoint} > $value
|
|
6
|
-
|
|
7
|
-
for each grid token, compile all its tokens into a single utility:
|
|
8
|
-
|
|
9
|
-
```css
|
|
10
|
-
@utility grid-{identifier} {
|
|
11
|
-
display: grid;
|
|
12
|
-
grid-template-columns: repeat(var(--grid-columns--default), 1fr);
|
|
13
|
-
grid-gap: var(--grid-gutter--default);
|
|
14
|
-
margin: 0 var(--grid-margin--default);
|
|
15
|
-
@media screen and (min-width: {breakpoint}) {
|
|
16
|
-
display: grid;
|
|
17
|
-
grid-template-columns: repeat(var(--grid-columns--{breakpoint}), 1fr);
|
|
18
|
-
grid-gap: var(--grid-gutter--{breakpoint});
|
|
19
|
-
margin: 0 var(--grid-margin--{breakpoint});
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
Append prefix to the utility name if it is provided.
|
|
24
|
-
*/
|
|
25
|
-
export function processGridTokens(
|
|
26
|
-
dictionary: Dictionary,
|
|
27
|
-
options: Config & LocalOptions,
|
|
28
|
-
): string {
|
|
29
|
-
const gridTokens = dictionary.tokens.grid ?? {}
|
|
30
|
-
const breakpointTokens = dictionary.tokens.breakpoint ?? {}
|
|
31
|
-
|
|
32
|
-
if (Object.keys(gridTokens).length === 0) {
|
|
33
|
-
return ''
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const utilities = []
|
|
37
|
-
for (const [identifier, breakpoints] of Object.entries(gridTokens)) {
|
|
38
|
-
const utilityName = `grid-${identifier}`
|
|
39
|
-
const variableBase = options.prefix
|
|
40
|
-
? `--${options.prefix}-grid-${identifier}`
|
|
41
|
-
: `--grid-${identifier}`
|
|
42
|
-
let utility = `@utility ${utilityName} {\n`
|
|
43
|
-
utility += ` display: grid;\n`
|
|
44
|
-
utility += ` grid-template-columns: repeat(var(${variableBase}-columns--default), 1fr);\n`
|
|
45
|
-
utility += ` grid-gap: var(${variableBase}-gutter--default);\n`
|
|
46
|
-
utility += ` margin: 0 var(${variableBase}-margin--default);\n`
|
|
47
|
-
|
|
48
|
-
for (const [breakpoint] of Object.entries(breakpoints)) {
|
|
49
|
-
const breakpointToken = breakpointTokens[breakpoint]
|
|
50
|
-
if (!breakpointToken || breakpoint === 'default') {
|
|
51
|
-
continue
|
|
52
|
-
}
|
|
53
|
-
utility += ` @media screen and (min-width: ${breakpointToken.$value}) {\n`
|
|
54
|
-
utility += ` grid-template-columns: repeat(var(${variableBase}-columns--${breakpoint}), 1fr);\n`
|
|
55
|
-
utility += ` grid-gap: var(${variableBase}-gutter--${breakpoint});\n`
|
|
56
|
-
utility += ` margin: 0 var(${variableBase}-margin--${breakpoint});\n`
|
|
57
|
-
utility += ` }\n`
|
|
58
|
-
}
|
|
59
|
-
utility += `}\n`
|
|
60
|
-
utilities.push(utility)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
return utilities.join('\n')
|
|
64
|
-
}
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
import type { Config, Dictionary, LocalOptions } from 'style-dictionary/types'
|
|
2
|
-
|
|
3
|
-
import type { TokenWithCTIAttrs } from '../../types.js'
|
|
4
|
-
|
|
5
|
-
import { describe, expect, it } from 'vitest'
|
|
6
|
-
|
|
7
|
-
import { processTypographyTokens } from './typography-processor.js'
|
|
8
|
-
|
|
9
|
-
describe('processTypographyTokens', () => {
|
|
10
|
-
const createMockToken = (
|
|
11
|
-
attributes: Record<string, any>,
|
|
12
|
-
type = 'typography',
|
|
13
|
-
): TokenWithCTIAttrs =>
|
|
14
|
-
({
|
|
15
|
-
$type: type,
|
|
16
|
-
attributes,
|
|
17
|
-
}) as unknown as TokenWithCTIAttrs
|
|
18
|
-
|
|
19
|
-
const createMockDictionary = (
|
|
20
|
-
tokens: TokenWithCTIAttrs[] = [],
|
|
21
|
-
breakpoints: Record<string, any> = {},
|
|
22
|
-
): Dictionary =>
|
|
23
|
-
({
|
|
24
|
-
allTokens: tokens,
|
|
25
|
-
tokens: { breakpoint: breakpoints },
|
|
26
|
-
}) as unknown as Dictionary
|
|
27
|
-
|
|
28
|
-
const createMockOptions = (): Config & LocalOptions =>
|
|
29
|
-
({}) as unknown as Config & LocalOptions
|
|
30
|
-
|
|
31
|
-
it('should generate utility with fallback to default', () => {
|
|
32
|
-
const tokens = [createMockToken({ item: 'sm' })]
|
|
33
|
-
const breakpoints = { sm: { $value: '490px' } }
|
|
34
|
-
const dictionary = createMockDictionary(tokens, breakpoints)
|
|
35
|
-
const options = createMockOptions()
|
|
36
|
-
|
|
37
|
-
const result = processTypographyTokens(dictionary, options)
|
|
38
|
-
|
|
39
|
-
expect(result).toMatchInlineSnapshot(`
|
|
40
|
-
"@utility typography-* {
|
|
41
|
-
font: --value(--typography-default-*);
|
|
42
|
-
@media screen and (min-width: 490px) {
|
|
43
|
-
font: --value(--typography-sm-*);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
"
|
|
47
|
-
`)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
it('should generate utility with multiple media queries', () => {
|
|
51
|
-
const tokens = [
|
|
52
|
-
createMockToken({ item: 'sm' }),
|
|
53
|
-
createMockToken({ item: 'md' }),
|
|
54
|
-
createMockToken({ item: 'lg' }),
|
|
55
|
-
]
|
|
56
|
-
const breakpoints = {
|
|
57
|
-
sm: { $value: '490px' },
|
|
58
|
-
md: { $value: '768px' },
|
|
59
|
-
lg: { $value: '1024px' },
|
|
60
|
-
}
|
|
61
|
-
const dictionary = createMockDictionary(tokens, breakpoints)
|
|
62
|
-
const options = createMockOptions()
|
|
63
|
-
|
|
64
|
-
const result = processTypographyTokens(dictionary, options)
|
|
65
|
-
|
|
66
|
-
expect(result).toMatchInlineSnapshot(`
|
|
67
|
-
"@utility typography-* {
|
|
68
|
-
font: --value(--typography-default-*);
|
|
69
|
-
@media screen and (min-width: 490px) {
|
|
70
|
-
font: --value(--typography-sm-*);
|
|
71
|
-
}
|
|
72
|
-
@media screen and (min-width: 768px) {
|
|
73
|
-
font: --value(--typography-md-*);
|
|
74
|
-
}
|
|
75
|
-
@media screen and (min-width: 1024px) {
|
|
76
|
-
font: --value(--typography-lg-*);
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
"
|
|
80
|
-
`)
|
|
81
|
-
})
|
|
82
|
-
|
|
83
|
-
it('should handle unordered and sparse breakpoints', () => {
|
|
84
|
-
const tokens = [
|
|
85
|
-
createMockToken({ item: 'lg' }),
|
|
86
|
-
createMockToken({ item: 'sm' }),
|
|
87
|
-
]
|
|
88
|
-
const breakpoints = {
|
|
89
|
-
sm: { $value: '490px' },
|
|
90
|
-
md: { $value: '768px' }, // This breakpoint is not in the tokens
|
|
91
|
-
lg: { $value: '1024px' },
|
|
92
|
-
}
|
|
93
|
-
const dictionary = createMockDictionary(tokens, breakpoints)
|
|
94
|
-
const options = createMockOptions()
|
|
95
|
-
|
|
96
|
-
const result = processTypographyTokens(dictionary, options)
|
|
97
|
-
|
|
98
|
-
expect(result).toMatchInlineSnapshot(`
|
|
99
|
-
"@utility typography-* {
|
|
100
|
-
font: --value(--typography-default-*);
|
|
101
|
-
@media screen and (min-width: 490px) {
|
|
102
|
-
font: --value(--typography-sm-*);
|
|
103
|
-
}
|
|
104
|
-
@media screen and (min-width: 1024px) {
|
|
105
|
-
font: --value(--typography-lg-*);
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
"
|
|
109
|
-
`)
|
|
110
|
-
})
|
|
111
|
-
})
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { Config, Dictionary, LocalOptions } from 'style-dictionary/types'
|
|
2
|
-
|
|
3
|
-
import type { BreakpointToken, TokenWithCTIAttrs } from '../../types.js'
|
|
4
|
-
|
|
5
|
-
export function processTypographyTokens(
|
|
6
|
-
dictionary: Dictionary,
|
|
7
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
8
|
-
_options: Config & LocalOptions,
|
|
9
|
-
): string {
|
|
10
|
-
const typographyTokens = dictionary.allTokens.filter(
|
|
11
|
-
token => token.$type === 'typography',
|
|
12
|
-
) as TokenWithCTIAttrs[]
|
|
13
|
-
|
|
14
|
-
const breakpoints =
|
|
15
|
-
(dictionary.tokens.breakpoint as BreakpointToken | undefined) ??
|
|
16
|
-
({} as BreakpointToken)
|
|
17
|
-
|
|
18
|
-
const availableBreakpoints = new Set<string>()
|
|
19
|
-
for (const token of typographyTokens) {
|
|
20
|
-
const item = token.attributes.item
|
|
21
|
-
if (item && item !== 'default' && breakpoints[item]) {
|
|
22
|
-
availableBreakpoints.add(item)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const sortedBreakpoints = [...availableBreakpoints].sort((a, b) => {
|
|
27
|
-
if (!breakpoints[a] || !breakpoints[b]) {
|
|
28
|
-
return 0
|
|
29
|
-
}
|
|
30
|
-
const aValue = (breakpoints[a] as unknown as BreakpointToken).$value
|
|
31
|
-
const bValue = (breakpoints[b] as unknown as BreakpointToken).$value
|
|
32
|
-
|
|
33
|
-
return parseFloat(aValue) - parseFloat(bValue)
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
let utility = '@utility typography-* {\n'
|
|
37
|
-
utility += ' font: --value(--typography-default-*);\n'
|
|
38
|
-
|
|
39
|
-
for (const breakpointName of sortedBreakpoints) {
|
|
40
|
-
const breakpointValue = breakpoints[breakpointName].$value
|
|
41
|
-
utility += ` @media screen and (min-width: ${breakpointValue}) {\n`
|
|
42
|
-
utility += ` font: --value(--typography-${breakpointName}-*);\n`
|
|
43
|
-
utility += ' }\n'
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
utility += '}\n'
|
|
47
|
-
return utility
|
|
48
|
-
}
|