@payfit/unity-themes 2.55.21 → 2.55.23
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 +20 -11
- package/skills/unity-themes/SKILL.md +41 -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,329 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
Dictionary,
|
|
3
|
-
FormatFnArguments,
|
|
4
|
-
TransformedToken,
|
|
5
|
-
TransformedTokens,
|
|
6
|
-
} from 'style-dictionary/types'
|
|
7
|
-
|
|
8
|
-
import { describe, expect, it } from 'vitest'
|
|
9
|
-
|
|
10
|
-
import { unityThemeFormat } from './unity-theme.js'
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Creates mock tokens. When prefix is set, token names include the prefix
|
|
14
|
-
* (matching the behavior of the updated name transforms).
|
|
15
|
-
*/
|
|
16
|
-
function createTransformedTokens(prefix?: string) {
|
|
17
|
-
const p = prefix ? `${prefix}-` : ''
|
|
18
|
-
return [
|
|
19
|
-
{
|
|
20
|
-
name: `${p}color-primary`,
|
|
21
|
-
$value: '#000000',
|
|
22
|
-
$type: 'color',
|
|
23
|
-
path: ['color', 'primary'],
|
|
24
|
-
original: { $value: '#000000' },
|
|
25
|
-
filePath: '',
|
|
26
|
-
isSource: false,
|
|
27
|
-
},
|
|
28
|
-
{
|
|
29
|
-
name: `${p}color-secondary`,
|
|
30
|
-
$value: '#555555',
|
|
31
|
-
$type: 'color',
|
|
32
|
-
path: ['color', 'secondary'],
|
|
33
|
-
original: { $value: '{color.gray}' },
|
|
34
|
-
filePath: '',
|
|
35
|
-
isSource: false,
|
|
36
|
-
},
|
|
37
|
-
{
|
|
38
|
-
name: `${p}color-gray`,
|
|
39
|
-
$value: '#555555',
|
|
40
|
-
$type: 'color',
|
|
41
|
-
path: ['color', 'gray'],
|
|
42
|
-
original: { $value: '#555555' },
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
name: `${p}spacing-1`,
|
|
46
|
-
$value: '0.25rem',
|
|
47
|
-
$type: 'spacing',
|
|
48
|
-
path: ['spacing', '1'],
|
|
49
|
-
original: { $value: '0.25rem' },
|
|
50
|
-
filePath: '',
|
|
51
|
-
isSource: false,
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
name: `${p}spacing-2`,
|
|
55
|
-
$value: '0.25rem',
|
|
56
|
-
$type: 'spacing',
|
|
57
|
-
path: ['spacing', '2'],
|
|
58
|
-
original: { $value: '{spacing.1}' },
|
|
59
|
-
filePath: '',
|
|
60
|
-
isSource: false,
|
|
61
|
-
},
|
|
62
|
-
{
|
|
63
|
-
name: `${p}grid-12-column-columns--default`,
|
|
64
|
-
$value: '12',
|
|
65
|
-
$type: 'number',
|
|
66
|
-
path: ['grid', '12-column', 'columns'],
|
|
67
|
-
original: { $value: '12' },
|
|
68
|
-
filePath: '',
|
|
69
|
-
isSource: false,
|
|
70
|
-
},
|
|
71
|
-
{
|
|
72
|
-
name: `${p}grid-12-column-gutter--default`,
|
|
73
|
-
$value: '1rem',
|
|
74
|
-
$type: 'dimension',
|
|
75
|
-
path: ['grid', '12-column', 'gutter'],
|
|
76
|
-
original: { $value: '1rem' },
|
|
77
|
-
},
|
|
78
|
-
{
|
|
79
|
-
name: `${p}grid-12-column-margin--default`,
|
|
80
|
-
$value: '0.25rem',
|
|
81
|
-
$type: 'dimension',
|
|
82
|
-
path: ['grid', '12-column', 'margin'],
|
|
83
|
-
original: { $value: '{spacing.1}' },
|
|
84
|
-
},
|
|
85
|
-
{
|
|
86
|
-
name: `${p}breakpoint-tablet`,
|
|
87
|
-
$value: '768px',
|
|
88
|
-
$type: 'breakpoint',
|
|
89
|
-
path: ['breakpoint', 'tablet'],
|
|
90
|
-
original: { $value: '768px' },
|
|
91
|
-
},
|
|
92
|
-
{
|
|
93
|
-
name: `${p}breakpoint-desktop`,
|
|
94
|
-
$value: '1024px',
|
|
95
|
-
$type: 'breakpoint',
|
|
96
|
-
path: ['breakpoint', 'desktop'],
|
|
97
|
-
original: { $value: '1024px' },
|
|
98
|
-
},
|
|
99
|
-
{
|
|
100
|
-
name: `${p}typography-default-h1`,
|
|
101
|
-
$value: 'normal 700 32px/1.104 Inter, sans-serif ',
|
|
102
|
-
$type: 'typography',
|
|
103
|
-
path: ['typography', 'h1', 'default'],
|
|
104
|
-
attributes: {
|
|
105
|
-
type: 'h1',
|
|
106
|
-
category: 'typography',
|
|
107
|
-
item: 'default',
|
|
108
|
-
},
|
|
109
|
-
original: {
|
|
110
|
-
$value: {
|
|
111
|
-
fontFamily: 'Inter, sans-serif',
|
|
112
|
-
fontSize: '32px',
|
|
113
|
-
fontWeight: 700,
|
|
114
|
-
lineHeight: 1.104,
|
|
115
|
-
},
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
{
|
|
119
|
-
name: `${p}typography-sm-h1`,
|
|
120
|
-
$value: 'normal 700 36px/1.104 Inter, sans-serif ',
|
|
121
|
-
$type: 'typography',
|
|
122
|
-
path: ['typography', 'h1', 'sm'],
|
|
123
|
-
attributes: {
|
|
124
|
-
type: 'h1',
|
|
125
|
-
category: 'typography',
|
|
126
|
-
item: 'sm',
|
|
127
|
-
},
|
|
128
|
-
original: {
|
|
129
|
-
$value: {
|
|
130
|
-
fontFamily: 'Inter, sans-serif',
|
|
131
|
-
fontSize: '36px',
|
|
132
|
-
fontWeight: 700,
|
|
133
|
-
lineHeight: 1.104,
|
|
134
|
-
},
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
{
|
|
138
|
-
name: `${p}typography-md-h2`,
|
|
139
|
-
$value: 'normal 600 24px/1.2 Inter, sans-serif ',
|
|
140
|
-
$type: 'typography',
|
|
141
|
-
path: ['typography', 'h2', 'md'],
|
|
142
|
-
attributes: {
|
|
143
|
-
type: 'h2',
|
|
144
|
-
category: 'typography',
|
|
145
|
-
item: 'md',
|
|
146
|
-
},
|
|
147
|
-
original: {
|
|
148
|
-
$value: {
|
|
149
|
-
fontFamily: 'Inter, sans-serif',
|
|
150
|
-
fontSize: '24px',
|
|
151
|
-
fontWeight: 600,
|
|
152
|
-
lineHeight: 1.2,
|
|
153
|
-
},
|
|
154
|
-
},
|
|
155
|
-
},
|
|
156
|
-
] as unknown as TransformedToken[]
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
const tokenDef = {
|
|
160
|
-
color: {
|
|
161
|
-
primary: { $value: '#000000' },
|
|
162
|
-
secondary: { $value: '{color.gray}' },
|
|
163
|
-
gray: { $value: '#555555' },
|
|
164
|
-
},
|
|
165
|
-
spacing: {
|
|
166
|
-
'1': { $value: '0.25rem' },
|
|
167
|
-
'2': { $value: '{spacing.1}' },
|
|
168
|
-
},
|
|
169
|
-
grid: {
|
|
170
|
-
'12-column': {
|
|
171
|
-
columns: { $value: 12 },
|
|
172
|
-
gutter: { $value: '1rem' },
|
|
173
|
-
margin: { $value: '{spacing.1}' },
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
typography: {
|
|
177
|
-
h1: {
|
|
178
|
-
default: {
|
|
179
|
-
fontFamily: 'Inter, sans-serif',
|
|
180
|
-
fontSize: '32px',
|
|
181
|
-
fontWeight: 700,
|
|
182
|
-
lineHeight: 1.104,
|
|
183
|
-
},
|
|
184
|
-
sm: {
|
|
185
|
-
fontFamily: 'Inter, sans-serif',
|
|
186
|
-
fontSize: '36px',
|
|
187
|
-
fontWeight: 700,
|
|
188
|
-
lineHeight: 1.104,
|
|
189
|
-
},
|
|
190
|
-
},
|
|
191
|
-
h2: {
|
|
192
|
-
md: {
|
|
193
|
-
fontFamily: 'Inter, sans-serif',
|
|
194
|
-
fontSize: '24px',
|
|
195
|
-
fontWeight: 600,
|
|
196
|
-
lineHeight: 1.2,
|
|
197
|
-
},
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
breakpoint: {
|
|
201
|
-
sm: { $value: '490px' },
|
|
202
|
-
md: { $value: '768px' },
|
|
203
|
-
tablet: { $value: '768px' },
|
|
204
|
-
desktop: { $value: '1024px' },
|
|
205
|
-
},
|
|
206
|
-
} as unknown as TransformedTokens
|
|
207
|
-
|
|
208
|
-
const createMockFormatFnArguments = (prefix?: string): FormatFnArguments =>
|
|
209
|
-
({
|
|
210
|
-
dictionary: {
|
|
211
|
-
tokens: tokenDef,
|
|
212
|
-
unfilteredTokens: tokenDef,
|
|
213
|
-
allTokens: createTransformedTokens(prefix),
|
|
214
|
-
tokenMap: new Map(),
|
|
215
|
-
} as unknown as Dictionary,
|
|
216
|
-
platform: {},
|
|
217
|
-
options: {
|
|
218
|
-
prefix,
|
|
219
|
-
selector: '@theme',
|
|
220
|
-
outputReferences: true,
|
|
221
|
-
usesDtcg: true,
|
|
222
|
-
fileHeader: '/* theme header */',
|
|
223
|
-
},
|
|
224
|
-
file: {
|
|
225
|
-
destination: 'unity.css',
|
|
226
|
-
options: {
|
|
227
|
-
prefix,
|
|
228
|
-
selector: '@theme',
|
|
229
|
-
outputReferences: true,
|
|
230
|
-
usesDtcg: true,
|
|
231
|
-
fileHeader: '/* theme header */',
|
|
232
|
-
},
|
|
233
|
-
},
|
|
234
|
-
}) as unknown as FormatFnArguments
|
|
235
|
-
|
|
236
|
-
describe('css/unity-theme Format', () => {
|
|
237
|
-
it('should output @theme with var() references when no prefix is set', async () => {
|
|
238
|
-
const args = createMockFormatFnArguments(undefined)
|
|
239
|
-
const result = await unityThemeFormat(args)
|
|
240
|
-
|
|
241
|
-
expect(result).toMatchInlineSnapshot(`
|
|
242
|
-
"@theme {
|
|
243
|
-
--color-*: initial;
|
|
244
|
-
--color-primary: var(--color-primary);
|
|
245
|
-
--color-secondary: var(--color-secondary);
|
|
246
|
-
--color-gray: var(--color-gray);
|
|
247
|
-
--spacing-1: var(--spacing-1);
|
|
248
|
-
--spacing-2: var(--spacing-2);
|
|
249
|
-
--grid-12-column-columns--default: var(--grid-12-column-columns--default);
|
|
250
|
-
--grid-12-column-gutter--default: var(--grid-12-column-gutter--default);
|
|
251
|
-
--grid-12-column-margin--default: var(--grid-12-column-margin--default);
|
|
252
|
-
--breakpoint-tablet: 768px;
|
|
253
|
-
--breakpoint-desktop: 1024px;
|
|
254
|
-
--typography-default-h1: var(--typography-default-h1);
|
|
255
|
-
--typography-sm-h1: var(--typography-sm-h1);
|
|
256
|
-
--typography-md-h2: var(--typography-md-h2);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
@utility grid-12-column {
|
|
260
|
-
display: grid;
|
|
261
|
-
grid-template-columns: repeat(var(--grid-12-column-columns--default), 1fr);
|
|
262
|
-
grid-gap: var(--grid-12-column-gutter--default);
|
|
263
|
-
margin: 0 var(--grid-12-column-margin--default);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
@utility typography-* {
|
|
267
|
-
font: --value(--typography-default-*);
|
|
268
|
-
@media screen and (min-width: 490px) {
|
|
269
|
-
font: --value(--typography-sm- *);
|
|
270
|
-
}
|
|
271
|
-
@media screen and (min-width: 768px) {
|
|
272
|
-
font: --value(--typography-md- *);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
"
|
|
276
|
-
`)
|
|
277
|
-
})
|
|
278
|
-
|
|
279
|
-
it('should strip prefix from @theme declarations but keep it in var() references', async () => {
|
|
280
|
-
const args = createMockFormatFnArguments('uy')
|
|
281
|
-
const result = await unityThemeFormat(args)
|
|
282
|
-
|
|
283
|
-
expect(result).toMatchInlineSnapshot(`
|
|
284
|
-
"@theme {
|
|
285
|
-
--color-*: initial;
|
|
286
|
-
--color-primary: var(--uy-color-primary);
|
|
287
|
-
--color-secondary: var(--uy-color-secondary);
|
|
288
|
-
--color-gray: var(--uy-color-gray);
|
|
289
|
-
--spacing-1: var(--uy-spacing-1);
|
|
290
|
-
--spacing-2: var(--uy-spacing-2);
|
|
291
|
-
--grid-12-column-columns--default: var(--uy-grid-12-column-columns--default);
|
|
292
|
-
--grid-12-column-gutter--default: var(--uy-grid-12-column-gutter--default);
|
|
293
|
-
--grid-12-column-margin--default: var(--uy-grid-12-column-margin--default);
|
|
294
|
-
--breakpoint-tablet: 768px;
|
|
295
|
-
--breakpoint-desktop: 1024px;
|
|
296
|
-
--typography-default-h1: var(--uy-typography-default-h1);
|
|
297
|
-
--typography-sm-h1: var(--uy-typography-sm-h1);
|
|
298
|
-
--typography-md-h2: var(--uy-typography-md-h2);
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
@utility grid-12-column {
|
|
302
|
-
display: grid;
|
|
303
|
-
grid-template-columns: repeat(var(--uy-grid-12-column-columns--default), 1fr);
|
|
304
|
-
grid-gap: var(--uy-grid-12-column-gutter--default);
|
|
305
|
-
margin: 0 var(--uy-grid-12-column-margin--default);
|
|
306
|
-
}
|
|
307
|
-
|
|
308
|
-
@utility typography-* {
|
|
309
|
-
font: --value(--typography-default-*);
|
|
310
|
-
@media screen and (min-width: 490px) {
|
|
311
|
-
font: --value(--typography-sm- *);
|
|
312
|
-
}
|
|
313
|
-
@media screen and (min-width: 768px) {
|
|
314
|
-
font: --value(--typography-md- *);
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
"
|
|
318
|
-
`)
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
it('should output breakpoint values as static (not var references)', async () => {
|
|
322
|
-
const args = createMockFormatFnArguments('uy')
|
|
323
|
-
const result = await unityThemeFormat(args)
|
|
324
|
-
|
|
325
|
-
expect(result).toContain('--breakpoint-tablet: 768px;')
|
|
326
|
-
expect(result).toContain('--breakpoint-desktop: 1024px;')
|
|
327
|
-
expect(result).not.toContain('var(--uy-breakpoint-')
|
|
328
|
-
})
|
|
329
|
-
})
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import type { FormatFnArguments } from 'style-dictionary/types'
|
|
2
|
-
|
|
3
|
-
import prettier from 'prettier'
|
|
4
|
-
|
|
5
|
-
import { processGridTokens } from './processors/grid-processor.js'
|
|
6
|
-
import { processTypographyTokens } from './processors/typography-processor.js'
|
|
7
|
-
import { getPrefixes } from './utils.js'
|
|
8
|
-
|
|
9
|
-
export const name = 'css/unity-theme'
|
|
10
|
-
|
|
11
|
-
export async function unityThemeFormat(args: FormatFnArguments) {
|
|
12
|
-
const { dictionary, options } = args
|
|
13
|
-
const { variablePrefix } = getPrefixes(options)
|
|
14
|
-
|
|
15
|
-
// Build @theme block directly from the dictionary.
|
|
16
|
-
// Every variable becomes a var(--uy-*) reference so the CSS cascade
|
|
17
|
-
// controls which value is active at runtime.
|
|
18
|
-
// Exception: breakpoint variables must be static pixel values because
|
|
19
|
-
// Tailwind resolves them at build time to generate @media rules.
|
|
20
|
-
const themeLines: string[] = ['--color-*: initial;']
|
|
21
|
-
|
|
22
|
-
for (const token of dictionary.allTokens) {
|
|
23
|
-
// Strip the prefix from the declaration name (Tailwind adds it)
|
|
24
|
-
const unprefixedName = token.name.replace(
|
|
25
|
-
new RegExp(`^${variablePrefix}`),
|
|
26
|
-
'',
|
|
27
|
-
)
|
|
28
|
-
|
|
29
|
-
if (
|
|
30
|
-
unprefixedName.startsWith('breakpoint-') ||
|
|
31
|
-
unprefixedName.startsWith('container-')
|
|
32
|
-
) {
|
|
33
|
-
themeLines.push(` --${unprefixedName}: ${token.$value};`)
|
|
34
|
-
} else {
|
|
35
|
-
themeLines.push(` --${unprefixedName}: var(--${token.name});`)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const themeBlock = `@theme {\n${themeLines.join('\n')}\n}`
|
|
40
|
-
|
|
41
|
-
const gridClasses = processGridTokens(dictionary, options)
|
|
42
|
-
const typographyClasses = processTypographyTokens(dictionary, options)
|
|
43
|
-
|
|
44
|
-
return prettier.format(
|
|
45
|
-
`
|
|
46
|
-
${themeBlock}
|
|
47
|
-
|
|
48
|
-
${gridClasses}
|
|
49
|
-
|
|
50
|
-
${typographyClasses}
|
|
51
|
-
`,
|
|
52
|
-
{ parser: 'css', printWidth: 120, tabWidth: 2, useTabs: false },
|
|
53
|
-
)
|
|
54
|
-
}
|
|
@@ -1,264 +0,0 @@
|
|
|
1
|
-
import type { Config, LocalOptions } from 'style-dictionary/types'
|
|
2
|
-
|
|
3
|
-
import { describe, expect, it } from 'vitest'
|
|
4
|
-
|
|
5
|
-
import { getPrefixes, processCssVariables } from './utils.js'
|
|
6
|
-
|
|
7
|
-
describe('getPrefixes', () => {
|
|
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 prefixes when no prefix is provided', () => {
|
|
24
|
-
const options = createMockOptions()
|
|
25
|
-
const result = getPrefixes(options)
|
|
26
|
-
|
|
27
|
-
expect(result).toEqual({
|
|
28
|
-
classPrefix: '',
|
|
29
|
-
variablePrefix: '',
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('should return prefixes with backslash escape for class prefix', () => {
|
|
34
|
-
const options = createMockOptions('uy')
|
|
35
|
-
const result = getPrefixes(options)
|
|
36
|
-
|
|
37
|
-
expect(result).toEqual({
|
|
38
|
-
classPrefix: 'uy\\:',
|
|
39
|
-
variablePrefix: 'uy-',
|
|
40
|
-
})
|
|
41
|
-
})
|
|
42
|
-
|
|
43
|
-
it('should handle different prefix values', () => {
|
|
44
|
-
const testCases = [
|
|
45
|
-
{
|
|
46
|
-
prefix: 'unity',
|
|
47
|
-
expected: { classPrefix: 'unity\\:', variablePrefix: 'unity-' },
|
|
48
|
-
},
|
|
49
|
-
{
|
|
50
|
-
prefix: 'custom',
|
|
51
|
-
expected: { classPrefix: 'custom\\:', variablePrefix: 'custom-' },
|
|
52
|
-
},
|
|
53
|
-
{
|
|
54
|
-
prefix: 'test-prefix',
|
|
55
|
-
expected: {
|
|
56
|
-
classPrefix: 'test-prefix\\:',
|
|
57
|
-
variablePrefix: 'test-prefix-',
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
]
|
|
61
|
-
|
|
62
|
-
testCases.forEach(({ prefix, expected }) => {
|
|
63
|
-
const options = createMockOptions(prefix)
|
|
64
|
-
const result = getPrefixes(options)
|
|
65
|
-
|
|
66
|
-
expect(result).toEqual(expected)
|
|
67
|
-
})
|
|
68
|
-
})
|
|
69
|
-
|
|
70
|
-
it('should handle empty string prefix', () => {
|
|
71
|
-
const options = createMockOptions('')
|
|
72
|
-
const result = getPrefixes(options)
|
|
73
|
-
|
|
74
|
-
expect(result).toEqual({
|
|
75
|
-
classPrefix: '',
|
|
76
|
-
variablePrefix: '',
|
|
77
|
-
})
|
|
78
|
-
})
|
|
79
|
-
})
|
|
80
|
-
|
|
81
|
-
describe('processCssVariables', () => {
|
|
82
|
-
it('should add prefix to var() references', () => {
|
|
83
|
-
const rawCssVars = `
|
|
84
|
-
--color-primary: #000000;
|
|
85
|
-
--color-secondary: var(--color-gray-500);
|
|
86
|
-
--spacing-1: 0.25rem;
|
|
87
|
-
--spacing-2: var(--spacing-1);
|
|
88
|
-
`
|
|
89
|
-
const variablePrefix = 'uy-'
|
|
90
|
-
|
|
91
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
92
|
-
|
|
93
|
-
expect(result).toMatchInlineSnapshot(`
|
|
94
|
-
"
|
|
95
|
-
--color-primary: #000000;
|
|
96
|
-
--color-secondary: var(--uy-color-gray-500);
|
|
97
|
-
--spacing-1: 0.25rem;
|
|
98
|
-
--spacing-2: var(--uy-spacing-1);
|
|
99
|
-
"
|
|
100
|
-
`)
|
|
101
|
-
})
|
|
102
|
-
|
|
103
|
-
it('should handle empty variable prefix', () => {
|
|
104
|
-
const rawCssVars = `
|
|
105
|
-
--color-primary: var(--color-gray-500);
|
|
106
|
-
--spacing-1: var(--spacing-base);
|
|
107
|
-
`
|
|
108
|
-
const variablePrefix = ''
|
|
109
|
-
|
|
110
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
111
|
-
|
|
112
|
-
expect(result).toMatchInlineSnapshot(`
|
|
113
|
-
"
|
|
114
|
-
--color-primary: var(--color-gray-500);
|
|
115
|
-
--spacing-1: var(--spacing-base);
|
|
116
|
-
"
|
|
117
|
-
`)
|
|
118
|
-
})
|
|
119
|
-
|
|
120
|
-
it('should handle complex var() references', () => {
|
|
121
|
-
const rawCssVars = `
|
|
122
|
-
--color-primary: var(--color-gray-500);
|
|
123
|
-
--color-secondary: var(--color-primary);
|
|
124
|
-
--color-tertiary: var(--color-secondary);
|
|
125
|
-
--spacing-1: var(--spacing-base);
|
|
126
|
-
--spacing-2: var(--spacing-1);
|
|
127
|
-
--spacing-3: var(--spacing-2);
|
|
128
|
-
`
|
|
129
|
-
const variablePrefix = 'custom-'
|
|
130
|
-
|
|
131
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
132
|
-
|
|
133
|
-
expect(result).toMatchInlineSnapshot(`
|
|
134
|
-
"
|
|
135
|
-
--color-primary: var(--custom-color-gray-500);
|
|
136
|
-
--color-secondary: var(--custom-color-primary);
|
|
137
|
-
--color-tertiary: var(--custom-color-secondary);
|
|
138
|
-
--spacing-1: var(--custom-spacing-base);
|
|
139
|
-
--spacing-2: var(--custom-spacing-1);
|
|
140
|
-
--spacing-3: var(--custom-spacing-2);
|
|
141
|
-
"
|
|
142
|
-
`)
|
|
143
|
-
})
|
|
144
|
-
|
|
145
|
-
it('should handle nested var() references', () => {
|
|
146
|
-
const rawCssVars = `
|
|
147
|
-
--color-primary: var(--color-gray-500);
|
|
148
|
-
--color-secondary: var(--color-primary);
|
|
149
|
-
--color-tertiary: var(--color-secondary);
|
|
150
|
-
`
|
|
151
|
-
const variablePrefix = 'nested-'
|
|
152
|
-
|
|
153
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
154
|
-
|
|
155
|
-
expect(result).toMatchInlineSnapshot(`
|
|
156
|
-
"
|
|
157
|
-
--color-primary: var(--nested-color-gray-500);
|
|
158
|
-
--color-secondary: var(--nested-color-primary);
|
|
159
|
-
--color-tertiary: var(--nested-color-secondary);
|
|
160
|
-
"
|
|
161
|
-
`)
|
|
162
|
-
})
|
|
163
|
-
|
|
164
|
-
it('should handle CSS without var() references', () => {
|
|
165
|
-
const rawCssVars = `
|
|
166
|
-
--color-primary: #000000;
|
|
167
|
-
--color-secondary: #ffffff;
|
|
168
|
-
--spacing-1: 0.25rem;
|
|
169
|
-
--spacing-2: 0.5rem;
|
|
170
|
-
`
|
|
171
|
-
const variablePrefix = 'uy-'
|
|
172
|
-
|
|
173
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
174
|
-
|
|
175
|
-
expect(result).toMatchInlineSnapshot(`
|
|
176
|
-
"
|
|
177
|
-
--color-primary: #000000;
|
|
178
|
-
--color-secondary: #ffffff;
|
|
179
|
-
--spacing-1: 0.25rem;
|
|
180
|
-
--spacing-2: 0.5rem;
|
|
181
|
-
"
|
|
182
|
-
`)
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
it('should handle empty CSS string', () => {
|
|
186
|
-
const rawCssVars = ''
|
|
187
|
-
const variablePrefix = 'uy-'
|
|
188
|
-
|
|
189
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
190
|
-
|
|
191
|
-
expect(result).toBe('')
|
|
192
|
-
})
|
|
193
|
-
|
|
194
|
-
it('should handle CSS with mixed var() and non-var() values', () => {
|
|
195
|
-
const rawCssVars = `
|
|
196
|
-
--color-primary: #000000;
|
|
197
|
-
--color-secondary: var(--color-gray-500);
|
|
198
|
-
--color-tertiary: #ffffff;
|
|
199
|
-
--spacing-1: 0.25rem;
|
|
200
|
-
--spacing-2: var(--spacing-1);
|
|
201
|
-
--spacing-3: 1rem;
|
|
202
|
-
`
|
|
203
|
-
const variablePrefix = 'mixed-'
|
|
204
|
-
|
|
205
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
206
|
-
|
|
207
|
-
expect(result).toMatchInlineSnapshot(`
|
|
208
|
-
"
|
|
209
|
-
--color-primary: #000000;
|
|
210
|
-
--color-secondary: var(--mixed-color-gray-500);
|
|
211
|
-
--color-tertiary: #ffffff;
|
|
212
|
-
--spacing-1: 0.25rem;
|
|
213
|
-
--spacing-2: var(--mixed-spacing-1);
|
|
214
|
-
--spacing-3: 1rem;
|
|
215
|
-
"
|
|
216
|
-
`)
|
|
217
|
-
})
|
|
218
|
-
|
|
219
|
-
it('should handle CSS with special characters in variable names', () => {
|
|
220
|
-
const rawCssVars = `
|
|
221
|
-
--color-primary: var(--color-gray-500);
|
|
222
|
-
--color-secondary: var(--color-primary);
|
|
223
|
-
--spacing-1: var(--spacing-base);
|
|
224
|
-
--border-radius: var(--radius-small);
|
|
225
|
-
`
|
|
226
|
-
const variablePrefix = 'special-'
|
|
227
|
-
|
|
228
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
229
|
-
|
|
230
|
-
expect(result).toMatchInlineSnapshot(`
|
|
231
|
-
"
|
|
232
|
-
--color-primary: var(--special-color-gray-500);
|
|
233
|
-
--color-secondary: var(--special-color-primary);
|
|
234
|
-
--spacing-1: var(--special-spacing-base);
|
|
235
|
-
--border-radius: var(--special-radius-small);
|
|
236
|
-
"
|
|
237
|
-
`)
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
it('should handle CSS with multiple var() references on the same line', () => {
|
|
241
|
-
const rawCssVars = `
|
|
242
|
-
--color-primary: var(--color-gray-500);
|
|
243
|
-
--color-secondary: var(--color-primary);
|
|
244
|
-
--color-tertiary: var(--color-secondary);
|
|
245
|
-
--spacing-1: var(--spacing-base);
|
|
246
|
-
--spacing-2: var(--spacing-1);
|
|
247
|
-
--spacing-3: var(--spacing-2);
|
|
248
|
-
`
|
|
249
|
-
const variablePrefix = 'multi-'
|
|
250
|
-
|
|
251
|
-
const result = processCssVariables(rawCssVars, variablePrefix)
|
|
252
|
-
|
|
253
|
-
expect(result).toMatchInlineSnapshot(`
|
|
254
|
-
"
|
|
255
|
-
--color-primary: var(--multi-color-gray-500);
|
|
256
|
-
--color-secondary: var(--multi-color-primary);
|
|
257
|
-
--color-tertiary: var(--multi-color-secondary);
|
|
258
|
-
--spacing-1: var(--multi-spacing-base);
|
|
259
|
-
--spacing-2: var(--multi-spacing-1);
|
|
260
|
-
--spacing-3: var(--multi-spacing-2);
|
|
261
|
-
"
|
|
262
|
-
`)
|
|
263
|
-
})
|
|
264
|
-
})
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import type { Prefixes, ProcessorOptions } from '../types.js'
|
|
2
|
-
|
|
3
|
-
export function getPrefixes(options: ProcessorOptions): Prefixes {
|
|
4
|
-
const classPrefix = options.prefix ? `${options.prefix}\\:` : ''
|
|
5
|
-
const variablePrefix = options.prefix ? `${options.prefix}-` : ''
|
|
6
|
-
|
|
7
|
-
return { classPrefix, variablePrefix }
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function processCssVariables(
|
|
11
|
-
rawCssVars: string,
|
|
12
|
-
variablePrefix: string,
|
|
13
|
-
): string {
|
|
14
|
-
return rawCssVars.replace(/var\(--([^)]+)\)/g, `var(--${variablePrefix}$1)`)
|
|
15
|
-
}
|