@atlaskit/tokens 1.36.0 → 1.37.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/CHANGELOG.md +6 -0
- package/codemods/css-to-design-tokens/__tests__/css-to-design-tokens.test.tsx +489 -0
- package/codemods/css-to-design-tokens/__tests__/utils.test.tsx +145 -0
- package/codemods/css-to-design-tokens/lib/colors.tsx +71 -0
- package/codemods/css-to-design-tokens/lib/declaration.tsx +43 -0
- package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +336 -0
- package/codemods/css-to-design-tokens/lib/meta.tsx +173 -0
- package/codemods/css-to-design-tokens/lib/tokens.tsx +54 -0
- package/codemods/css-to-design-tokens/lib/value.tsx +85 -0
- package/codemods/css-to-design-tokens/transform.tsx +99 -0
- package/codemods/hypermod.config.tsx +9 -0
- package/codemods/theme-to-design-tokens/__tests__/theme-to-design-tokens.test.tsx +1104 -0
- package/codemods/theme-to-design-tokens/transform.tsx +628 -0
- package/codemods/theme-to-design-tokens/utils/ast-meta.tsx +159 -0
- package/codemods/theme-to-design-tokens/utils/ast.tsx +46 -0
- package/codemods/theme-to-design-tokens/utils/color.tsx +45 -0
- package/codemods/theme-to-design-tokens/utils/css-utils.tsx +38 -0
- package/codemods/theme-to-design-tokens/utils/fuzzy-search.tsx +326 -0
- package/codemods/theme-to-design-tokens/utils/legacy-colors.tsx +232 -0
- package/codemods/theme-to-design-tokens/utils/named-colors.tsx +150 -0
- package/codemods/theme-to-design-tokens/utils/string-utils.tsx +22 -0
- package/codemods/utils/tokens.tsx +376 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/package.json +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/tokens
|
|
2
2
|
|
|
3
|
+
## 1.37.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#71146](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/71146) [`3e20d00d3d46`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3e20d00d3d46) - Moves tokens codemods into the tokens package.
|
|
8
|
+
|
|
3
9
|
## 1.36.0
|
|
4
10
|
|
|
5
11
|
### Minor Changes
|
|
@@ -0,0 +1,489 @@
|
|
|
1
|
+
import { Parser } from 'jscodeshift';
|
|
2
|
+
|
|
3
|
+
import __noop from '@atlaskit/ds-lib/noop';
|
|
4
|
+
|
|
5
|
+
import transformer from '../transform';
|
|
6
|
+
|
|
7
|
+
/* eslint-disable no-console */
|
|
8
|
+
export async function withMockedConsoleWarn(fn: any) {
|
|
9
|
+
const originalWarn = console.warn;
|
|
10
|
+
const warn = jest.fn();
|
|
11
|
+
console.warn = warn;
|
|
12
|
+
|
|
13
|
+
await fn(warn);
|
|
14
|
+
|
|
15
|
+
console.warn = originalWarn;
|
|
16
|
+
}
|
|
17
|
+
/* eslint-enable no-console */
|
|
18
|
+
|
|
19
|
+
async function applyTransform(
|
|
20
|
+
transform: any,
|
|
21
|
+
input: string,
|
|
22
|
+
options: {
|
|
23
|
+
parser: string | Parser;
|
|
24
|
+
} = {
|
|
25
|
+
parser: 'babel',
|
|
26
|
+
},
|
|
27
|
+
) {
|
|
28
|
+
// Handle ES6 modules using default export for the transform
|
|
29
|
+
const transformer = transform.default ? transform.default : transform;
|
|
30
|
+
const output = await transformer(
|
|
31
|
+
{ source: input },
|
|
32
|
+
{
|
|
33
|
+
jscodeshift: __noop,
|
|
34
|
+
stats: __noop,
|
|
35
|
+
},
|
|
36
|
+
options || {},
|
|
37
|
+
);
|
|
38
|
+
|
|
39
|
+
return (output || '').trim();
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
describe('PostCSS Transform', () => {
|
|
43
|
+
it(`standard CSS`, async () => {
|
|
44
|
+
const input = `
|
|
45
|
+
.normal {
|
|
46
|
+
color: #eeeeee;
|
|
47
|
+
}
|
|
48
|
+
.normal-selected {
|
|
49
|
+
color: #eeeeee;
|
|
50
|
+
}
|
|
51
|
+
`;
|
|
52
|
+
const result = await applyTransform(transformer, input);
|
|
53
|
+
expect(result).toMatchInlineSnapshot(`
|
|
54
|
+
".normal {
|
|
55
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
56
|
+
}
|
|
57
|
+
.normal-selected {
|
|
58
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
59
|
+
}"
|
|
60
|
+
`);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it(`standard LESS`, async () => {
|
|
64
|
+
const input = `
|
|
65
|
+
.container {
|
|
66
|
+
.mixin-1();
|
|
67
|
+
.mixin-2;
|
|
68
|
+
.mixin-3 (@width: 100px) {
|
|
69
|
+
color: #eeeeee;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
`;
|
|
73
|
+
const result = await applyTransform(transformer, input);
|
|
74
|
+
expect(result).toMatchInlineSnapshot(`
|
|
75
|
+
".container {
|
|
76
|
+
.mixin-1();
|
|
77
|
+
.mixin-2;
|
|
78
|
+
.mixin-3 (@width: 100px) {
|
|
79
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
80
|
+
}
|
|
81
|
+
}"
|
|
82
|
+
`);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it(`box-shadows`, async () => {
|
|
86
|
+
const input = `.container { box-shadow: 0px 1px 5px 0px var(--adg3-color-N40); }`;
|
|
87
|
+
const result = await applyTransform(transformer, input);
|
|
88
|
+
expect(result).toMatchInlineSnapshot(
|
|
89
|
+
`".container { box-shadow: var(MISSING_TOKEN, 0px 1px 5px 0px var(--adg3-color-N40)); }"`,
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it(`should not transform value with 'url()'`, async () => {
|
|
94
|
+
const input = `.user-time-icon { background: url(@spriteUrl) no-repeat; }`;
|
|
95
|
+
const result = await applyTransform(transformer, input);
|
|
96
|
+
expect(result).toMatchInlineSnapshot(
|
|
97
|
+
`".user-time-icon { background: url(@spriteUrl) no-repeat; }"`,
|
|
98
|
+
);
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
it(`should not transform value with less functions`, async () => {
|
|
102
|
+
await withMockedConsoleWarn(async (warn: any) => {
|
|
103
|
+
const input = `.user-time-icon { background: lighten(@spriteUrl) no-repeat; }`;
|
|
104
|
+
const result = await applyTransform(transformer, input);
|
|
105
|
+
expect(result).toMatchInlineSnapshot(
|
|
106
|
+
`".user-time-icon { background: lighten(@spriteUrl) no-repeat; }"`,
|
|
107
|
+
);
|
|
108
|
+
expect(warn).toHaveBeenCalledTimes(1);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it(`should not transform box-shadow: none`, async () => {
|
|
113
|
+
const input = `.container { box-shadow: none; }`;
|
|
114
|
+
const result = await applyTransform(transformer, input);
|
|
115
|
+
expect(result).toMatchInlineSnapshot(`".container { box-shadow: none; }"`);
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it(`should not transform border radius`, async () => {
|
|
119
|
+
const input = `.container { border-radius: 3px; }`;
|
|
120
|
+
const result = await applyTransform(transformer, input);
|
|
121
|
+
expect(result).toMatchInlineSnapshot(
|
|
122
|
+
`".container { border-radius: 3px; }"`,
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it(`chained selectors`, async () => {
|
|
127
|
+
const input = `
|
|
128
|
+
h1,h2,h3 {
|
|
129
|
+
color: #eeeeee;
|
|
130
|
+
}
|
|
131
|
+
`;
|
|
132
|
+
const result = await applyTransform(transformer, input);
|
|
133
|
+
expect(result).toMatchInlineSnapshot(`
|
|
134
|
+
"h1,h2,h3 {
|
|
135
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
136
|
+
}"
|
|
137
|
+
`);
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it(`does not transform CSS var declarations`, async () => {
|
|
141
|
+
const input = `--adg3-color-R50: #ffebe6;`;
|
|
142
|
+
const result = await applyTransform(transformer, input);
|
|
143
|
+
expect(result).toMatchInlineSnapshot(`"--adg3-color-R50: #ffebe6;"`);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it(`standard CSS with ADG3 variables`, async () => {
|
|
147
|
+
const input = `
|
|
148
|
+
.normal {
|
|
149
|
+
color: var(--adg3-color-N800);
|
|
150
|
+
color: var(--adg3-color-T400);
|
|
151
|
+
color: var(--adg3-color-B400);
|
|
152
|
+
}
|
|
153
|
+
`;
|
|
154
|
+
const result = await applyTransform(transformer, input);
|
|
155
|
+
expect(result).toMatchInlineSnapshot(`
|
|
156
|
+
".normal {
|
|
157
|
+
color: var(--ds-text, var(--adg3-color-N800));
|
|
158
|
+
color: var(--ds-text-accent-teal, var(--adg3-color-T400));
|
|
159
|
+
color: var(--ds-text-brand, var(--adg3-color-B400));
|
|
160
|
+
}"
|
|
161
|
+
`);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it(`deeply nested CSS`, async () => {
|
|
165
|
+
const input = `
|
|
166
|
+
.normal {
|
|
167
|
+
color: #eeeeee;
|
|
168
|
+
.deep {
|
|
169
|
+
color: #eeeeee;
|
|
170
|
+
.deeper {
|
|
171
|
+
color: #eeeeee;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
`;
|
|
176
|
+
const result = await applyTransform(transformer, input);
|
|
177
|
+
expect(result).toMatchInlineSnapshot(`
|
|
178
|
+
".normal {
|
|
179
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
180
|
+
.deep {
|
|
181
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
182
|
+
.deeper {
|
|
183
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}"
|
|
187
|
+
`);
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it(`interaction states CSS`, async () => {
|
|
191
|
+
const input = `
|
|
192
|
+
.normal {
|
|
193
|
+
color: #eeeeee;
|
|
194
|
+
}
|
|
195
|
+
.normal:hover {
|
|
196
|
+
color: #eeeeee;
|
|
197
|
+
}
|
|
198
|
+
.normal:active {
|
|
199
|
+
color: #eeeeee;
|
|
200
|
+
}
|
|
201
|
+
`;
|
|
202
|
+
const result = await applyTransform(transformer, input);
|
|
203
|
+
expect(result).toMatchInlineSnapshot(`
|
|
204
|
+
".normal {
|
|
205
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
206
|
+
}
|
|
207
|
+
.normal:hover {
|
|
208
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
209
|
+
}
|
|
210
|
+
.normal:active {
|
|
211
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
212
|
+
}"
|
|
213
|
+
`);
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it(`nested interaction states CSS`, async () => {
|
|
217
|
+
const input = `
|
|
218
|
+
.normal {
|
|
219
|
+
color: #eeeeee;
|
|
220
|
+
&:hover {
|
|
221
|
+
color: #eeeeee;
|
|
222
|
+
}
|
|
223
|
+
&:active {
|
|
224
|
+
color: #eeeeee;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
`;
|
|
228
|
+
const result = await applyTransform(transformer, input);
|
|
229
|
+
expect(result).toMatchInlineSnapshot(`
|
|
230
|
+
".normal {
|
|
231
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
232
|
+
&:hover {
|
|
233
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
234
|
+
}
|
|
235
|
+
&:active {
|
|
236
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
237
|
+
}
|
|
238
|
+
}"
|
|
239
|
+
`);
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it(`nested CSS`, async () => {
|
|
243
|
+
const input = `
|
|
244
|
+
.normal {
|
|
245
|
+
color: #000000;
|
|
246
|
+
width: var(--gutter-size);
|
|
247
|
+
.nested {
|
|
248
|
+
color: #000000;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
`;
|
|
252
|
+
const result = await applyTransform(transformer, input);
|
|
253
|
+
expect(result).toMatchInlineSnapshot(`
|
|
254
|
+
".normal {
|
|
255
|
+
color: var(--ds-text, #000000);
|
|
256
|
+
width: var(--gutter-size);
|
|
257
|
+
.nested {
|
|
258
|
+
color: var(--ds-text, #000000);
|
|
259
|
+
}
|
|
260
|
+
}"
|
|
261
|
+
`);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
it(`avoids already converted colors`, async () => {
|
|
265
|
+
const input = `
|
|
266
|
+
.normal {
|
|
267
|
+
color: var(--ds-text, #000000);
|
|
268
|
+
}
|
|
269
|
+
`;
|
|
270
|
+
const result = await applyTransform(transformer, input);
|
|
271
|
+
expect(result).toMatchInlineSnapshot(`
|
|
272
|
+
".normal {
|
|
273
|
+
color: var(--ds-text, #000000);
|
|
274
|
+
}"
|
|
275
|
+
`);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it(`aliased adg-3 colors`, async () => {
|
|
279
|
+
const input = `
|
|
280
|
+
.container {
|
|
281
|
+
box-shadow: 0px 1px 5px 0px var(--adg3-color-N40);
|
|
282
|
+
border: 1px solid var(--adg3-color-N40);
|
|
283
|
+
}
|
|
284
|
+
`;
|
|
285
|
+
const result = await applyTransform(transformer, input);
|
|
286
|
+
expect(result).toMatchInlineSnapshot(`
|
|
287
|
+
".container {
|
|
288
|
+
box-shadow: var(MISSING_TOKEN, 0px 1px 5px 0px var(--adg3-color-N40));
|
|
289
|
+
border: 1px solid var(--ds-border, var(--adg3-color-N40));
|
|
290
|
+
}"
|
|
291
|
+
`);
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it(`should transform border properties`, async () => {
|
|
295
|
+
const input = `
|
|
296
|
+
.normal {
|
|
297
|
+
border-top: 1px solid #eee;
|
|
298
|
+
border-bottom: 1px solid #eee;
|
|
299
|
+
}
|
|
300
|
+
`;
|
|
301
|
+
const result = await applyTransform(transformer, input);
|
|
302
|
+
expect(result).toMatchInlineSnapshot(`
|
|
303
|
+
".normal {
|
|
304
|
+
border-top: 1px solid var(--ds-surface-sunken, #eee);
|
|
305
|
+
border-bottom: 1px solid var(--ds-surface-sunken, #eee);
|
|
306
|
+
}"
|
|
307
|
+
`);
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it(`named colors`, async () => {
|
|
311
|
+
const input = `
|
|
312
|
+
.normal {
|
|
313
|
+
color: red;
|
|
314
|
+
color: crimson;
|
|
315
|
+
color: cyan;
|
|
316
|
+
color: darkblue;
|
|
317
|
+
color: darkcyan;
|
|
318
|
+
color: fuchsia;
|
|
319
|
+
color: lightgreen;
|
|
320
|
+
color: lightskyblue;
|
|
321
|
+
background-color: red;
|
|
322
|
+
background-color: crimson;
|
|
323
|
+
background-color: cyan;
|
|
324
|
+
background-color: darkblue;
|
|
325
|
+
background-color: darkcyan;
|
|
326
|
+
background-color: fuchsia;
|
|
327
|
+
background-color: lightgreen;
|
|
328
|
+
background-color: lightskyblue;
|
|
329
|
+
border-color: red;
|
|
330
|
+
border-color: crimson;
|
|
331
|
+
border-color: cyan;
|
|
332
|
+
border-color: darkblue;
|
|
333
|
+
border-color: darkcyan;
|
|
334
|
+
border-color: fuchsia;
|
|
335
|
+
border-color: lightgreen;
|
|
336
|
+
border-color: lightskyblue;
|
|
337
|
+
}
|
|
338
|
+
`;
|
|
339
|
+
const result = await applyTransform(transformer, input);
|
|
340
|
+
expect(result).toMatchInlineSnapshot(`
|
|
341
|
+
".normal {
|
|
342
|
+
color: var(--ds-text-accent-orange, red);
|
|
343
|
+
color: var(--ds-text-danger, crimson);
|
|
344
|
+
color: var(--ds-text-accent-teal, cyan);
|
|
345
|
+
color: var(--ds-text-accent-blue-bolder, darkblue);
|
|
346
|
+
color: var(--ds-text-accent-teal-bolder, darkcyan);
|
|
347
|
+
color: var(--ds-text-subtle, fuchsia);
|
|
348
|
+
color: var(--ds-text-accent-green, lightgreen);
|
|
349
|
+
color: var(--ds-text-accent-blue, lightskyblue);
|
|
350
|
+
background-color: var(--ds-background-danger, red);
|
|
351
|
+
background-color: var(--ds-background-danger, crimson);
|
|
352
|
+
background-color: var(--ds-background-accent-teal-subtle, cyan);
|
|
353
|
+
background-color: var(--ds-background-accent-blue-bolder, darkblue);
|
|
354
|
+
background-color: var(--ds-background-accent-teal-bolder, darkcyan);
|
|
355
|
+
background-color: var(--ds-background-accent-magenta-subtle, fuchsia);
|
|
356
|
+
background-color: var(--ds-background-accent-green-subtle, lightgreen);
|
|
357
|
+
background-color: var(--ds-background-accent-blue-subtle, lightskyblue);
|
|
358
|
+
border-color: var(--ds-border-accent-orange, red);
|
|
359
|
+
border-color: var(--ds-border-danger, crimson);
|
|
360
|
+
border-color: var(--ds-border-accent-teal, cyan);
|
|
361
|
+
border-color: var(--ds-border-accent-blue, darkblue);
|
|
362
|
+
border-color: var(--ds-border-accent-teal, darkcyan);
|
|
363
|
+
border-color: var(--ds-border-accent-magenta, fuchsia);
|
|
364
|
+
border-color: var(--ds-border-accent-green, lightgreen);
|
|
365
|
+
border-color: var(--ds-border-accent-blue, lightskyblue);
|
|
366
|
+
}"
|
|
367
|
+
`);
|
|
368
|
+
});
|
|
369
|
+
|
|
370
|
+
it(`raw colors`, async () => {
|
|
371
|
+
const input = `
|
|
372
|
+
.normal {
|
|
373
|
+
color: #ffffff;
|
|
374
|
+
color: #fff;
|
|
375
|
+
color: #000000;
|
|
376
|
+
color: #f0f0f0;
|
|
377
|
+
color: #eeeeee;
|
|
378
|
+
color: #cccccc;
|
|
379
|
+
color: #292929;
|
|
380
|
+
color: #003366;
|
|
381
|
+
background-color: #ffffff;
|
|
382
|
+
background-color: #fff;
|
|
383
|
+
background-color: #000000;
|
|
384
|
+
background-color: #f0f0f0;
|
|
385
|
+
background-color: #eeeeee;
|
|
386
|
+
background-color: #cccccc;
|
|
387
|
+
background-color: #292929;
|
|
388
|
+
background-color: #003366;
|
|
389
|
+
border-color: #ffffff;
|
|
390
|
+
border-color: #fff;
|
|
391
|
+
border-color: #000000;
|
|
392
|
+
border-color: #f0f0f0;
|
|
393
|
+
border-color: #eeeeee;
|
|
394
|
+
border-color: #cccccc;
|
|
395
|
+
border-color: #292929;
|
|
396
|
+
border-color: #003366;
|
|
397
|
+
}
|
|
398
|
+
`;
|
|
399
|
+
const result = await applyTransform(transformer, input);
|
|
400
|
+
expect(result).toMatchInlineSnapshot(`
|
|
401
|
+
".normal {
|
|
402
|
+
color: var(--ds-surface, #ffffff);
|
|
403
|
+
color: var(--ds-surface, #fff);
|
|
404
|
+
color: var(--ds-text, #000000);
|
|
405
|
+
color: var(--ds-surface, #f0f0f0);
|
|
406
|
+
color: var(--ds-surface-sunken, #eeeeee);
|
|
407
|
+
color: var(--ds-text-accent-gray, #cccccc);
|
|
408
|
+
color: var(--ds-text, #292929);
|
|
409
|
+
color: var(--ds-text, #003366);
|
|
410
|
+
background-color: var(--ds-surface, #ffffff);
|
|
411
|
+
background-color: var(--ds-surface, #fff);
|
|
412
|
+
background-color: var(--ds-background-input, #000000);
|
|
413
|
+
background-color: var(--ds-surface, #f0f0f0);
|
|
414
|
+
background-color: var(--ds-surface-sunken, #eeeeee);
|
|
415
|
+
background-color: var(--ds-background-accent-gray-subtle, #cccccc);
|
|
416
|
+
background-color: var(--ds-background-input, #292929);
|
|
417
|
+
background-color: var(--ds-background-input, #003366);
|
|
418
|
+
border-color: var(--ds-surface, #ffffff);
|
|
419
|
+
border-color: var(--ds-surface, #fff);
|
|
420
|
+
border-color: var(--ds-border, #000000);
|
|
421
|
+
border-color: var(--ds-surface, #f0f0f0);
|
|
422
|
+
border-color: var(--ds-surface-sunken, #eeeeee);
|
|
423
|
+
border-color: var(--ds-border-accent-gray, #cccccc);
|
|
424
|
+
border-color: var(--ds-border, #292929);
|
|
425
|
+
border-color: var(--ds-border, #003366);
|
|
426
|
+
}"
|
|
427
|
+
`);
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
it(`omits less variable use`, async () => {
|
|
431
|
+
const input = `.normal { border-bottom: @grid/2 solid @gh-background-color-column; }`;
|
|
432
|
+
const result = await applyTransform(transformer, input);
|
|
433
|
+
expect(result).toMatchInlineSnapshot(
|
|
434
|
+
`".normal { border-bottom: @grid/2 solid @gh-background-color-column; }"`,
|
|
435
|
+
);
|
|
436
|
+
});
|
|
437
|
+
|
|
438
|
+
it(`gradients`, async () => {
|
|
439
|
+
const input = `
|
|
440
|
+
.container {
|
|
441
|
+
background: linear-gradient(red, blue);
|
|
442
|
+
background: radial-gradient(red, blue);
|
|
443
|
+
background: conic-gradient(red, orange, yellow, green, blue);
|
|
444
|
+
}
|
|
445
|
+
`;
|
|
446
|
+
const result = await applyTransform(transformer, input);
|
|
447
|
+
expect(result).toMatchInlineSnapshot(`
|
|
448
|
+
".container {
|
|
449
|
+
background: linear-gradient(var(--ds-background-danger, red), var(--ds-background-accent-blue-subtle, blue));
|
|
450
|
+
background: radial-gradient(var(--ds-background-danger, red), var(--ds-background-accent-blue-subtle, blue));
|
|
451
|
+
background: conic-gradient(var(--ds-background-danger, red), var(--ds-background-input, orange), var(--ds-background-accent-yellow-subtle, yellow), var(--ds-background-accent-green-subtle, green), var(--ds-background-accent-blue-subtle, blue));
|
|
452
|
+
}"
|
|
453
|
+
`);
|
|
454
|
+
});
|
|
455
|
+
|
|
456
|
+
it(`border color`, async () => {
|
|
457
|
+
const input = `
|
|
458
|
+
.some-div {
|
|
459
|
+
border-color: red yellow green hsla(60, 90%, 50%, .8);
|
|
460
|
+
}
|
|
461
|
+
`;
|
|
462
|
+
const result = await applyTransform(transformer, input);
|
|
463
|
+
expect(result).toMatchInlineSnapshot(`
|
|
464
|
+
".some-div {
|
|
465
|
+
border-color: var(--ds-border-accent-orange, red) var(--ds-border-accent-yellow, yellow) var(--ds-border-accent-green, green) var(--ds-border, hsla(60, 90%, 50%, .8));
|
|
466
|
+
}"
|
|
467
|
+
`);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it(`other color properties`, async () => {
|
|
471
|
+
const input = `
|
|
472
|
+
.properties {
|
|
473
|
+
accent-color: darkred;
|
|
474
|
+
caret-color: red;
|
|
475
|
+
text-stroke: 4px navy;
|
|
476
|
+
scrollbar-color: rebeccapurple green;
|
|
477
|
+
}
|
|
478
|
+
`;
|
|
479
|
+
const result = await applyTransform(transformer, input);
|
|
480
|
+
expect(result).toMatchInlineSnapshot(`
|
|
481
|
+
".properties {
|
|
482
|
+
accent-color: var(--ds-background-accent-orange-bolder-hovered, darkred);
|
|
483
|
+
caret-color: var(--ds-background-accent-orange-subtler-hovered, red);
|
|
484
|
+
text-stroke: 4px var(--ds-text-accent-blue-bolder, navy);
|
|
485
|
+
scrollbar-color: var(--ds-text-accent-purple, rebeccapurple) var(--ds-text-accent-green, green);
|
|
486
|
+
}"
|
|
487
|
+
`);
|
|
488
|
+
});
|
|
489
|
+
});
|
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { isRawColor } from '../lib/colors';
|
|
2
|
+
import { splitCssValue } from '../lib/declaration';
|
|
3
|
+
|
|
4
|
+
describe('Utils', () => {
|
|
5
|
+
describe('splitCssValue', () => {
|
|
6
|
+
describe('Handling simple CSS values', () => {
|
|
7
|
+
it('should split a simple CSS value correctly', () => {
|
|
8
|
+
const result = splitCssValue('red blue');
|
|
9
|
+
expect(result).toEqual(['red', 'blue']);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should handle multiple spaces correctly', () => {
|
|
13
|
+
const result = splitCssValue('red blue');
|
|
14
|
+
expect(result).toEqual(['red', 'blue']);
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
it('should handle CSS values with special characters correctly', () => {
|
|
18
|
+
const result = splitCssValue('1px solid #000');
|
|
19
|
+
expect(result).toEqual(['1px', 'solid', '#000']);
|
|
20
|
+
});
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
describe('Handling CSS functions', () => {
|
|
24
|
+
it('should split a CSS value with a function correctly', () => {
|
|
25
|
+
const result = splitCssValue('linear-gradient(red, blue)');
|
|
26
|
+
expect(result).toEqual(['linear-gradient(red, blue)']);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('should handle CSS values with commas correctly', () => {
|
|
30
|
+
const result = splitCssValue('rgba(255, 255, 255, 0.6)');
|
|
31
|
+
expect(result).toEqual(['rgba(255, 255, 255, 0.6)']);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('should handle CSS values with multiple functions correctly', () => {
|
|
35
|
+
const result = splitCssValue('linear-gradient(red, blue) no-repeat');
|
|
36
|
+
expect(result).toEqual(['linear-gradient(red, blue)', 'no-repeat']);
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it('should handle less functions correctly', () => {
|
|
40
|
+
const result = splitCssValue('darken(#000, 10%)');
|
|
41
|
+
expect(result).toEqual(['darken(#000, 10%)']);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('should handle CSS url() function correctly', () => {
|
|
45
|
+
const result = splitCssValue('url(http://example.com/image.jpg)');
|
|
46
|
+
expect(result).toEqual(['url(http://example.com/image.jpg)']);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it('should handle multiple CSS functions correctly', () => {
|
|
50
|
+
const result = splitCssValue(
|
|
51
|
+
'linear-gradient(red, blue) url(http://example.com/image.jpg)',
|
|
52
|
+
);
|
|
53
|
+
expect(result).toEqual([
|
|
54
|
+
'linear-gradient(red, blue)',
|
|
55
|
+
'url(http://example.com/image.jpg)',
|
|
56
|
+
]);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should handle CSS functions with nested functions correctly', () => {
|
|
60
|
+
const result = splitCssValue(
|
|
61
|
+
'linear-gradient(to right, rgba(255, 0, 0, 0.5), rgba(0, 255, 0, 0.5))',
|
|
62
|
+
);
|
|
63
|
+
expect(result).toEqual([
|
|
64
|
+
'linear-gradient(to right, rgba(255, 0, 0, 0.5), rgba(0, 255, 0, 0.5))',
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
describe('Handling edge cases', () => {
|
|
70
|
+
it('should return null for an empty string', () => {
|
|
71
|
+
const result = splitCssValue('');
|
|
72
|
+
expect(result).toBeNull();
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('should handle no spaces between commas correctly', () => {
|
|
76
|
+
const result = splitCssValue('rgba(255,255,255,0.6)');
|
|
77
|
+
expect(result).toEqual(['rgba(255,255,255,0.6)']);
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it('should handle extra spaces around commas correctly', () => {
|
|
81
|
+
const result = splitCssValue('rgba(255 , 255 , 255 , 0.6)');
|
|
82
|
+
expect(result).toEqual(['rgba(255 , 255 , 255 , 0.6)']);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('should handle other whitespace characters correctly', () => {
|
|
86
|
+
const result = splitCssValue('red\tblue\nblack');
|
|
87
|
+
expect(result).toEqual(['red', 'blue', 'black']);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
it('should handle CSS values with exclamation mark correctly', () => {
|
|
91
|
+
const result = splitCssValue('color: red !important');
|
|
92
|
+
expect(result).toEqual(['color:', 'red', '!important']);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it('should ignore leading and trailing spaces', () => {
|
|
96
|
+
const result = splitCssValue(' red blue ');
|
|
97
|
+
expect(result).toEqual(['red', 'blue']);
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('isRawColor', () => {
|
|
103
|
+
it('should return true for valid raw color values', () => {
|
|
104
|
+
expect(isRawColor('#fff')).toBe(true);
|
|
105
|
+
expect(isRawColor('#ffffff')).toBe(true);
|
|
106
|
+
expect(isRawColor('rgb(255, 255, 255)')).toBe(true);
|
|
107
|
+
expect(isRawColor('rgba(255, 255, 255, 1)')).toBe(true);
|
|
108
|
+
expect(isRawColor('hsl(120, 100%, 50%)')).toBe(true);
|
|
109
|
+
expect(isRawColor('hsla(120, 100%, 50%, 0.3)')).toBe(true);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('should return false for invalid raw color values', () => {
|
|
113
|
+
expect(isRawColor('#ggg')).toBe(false);
|
|
114
|
+
expect(isRawColor('rgb(255, 255)')).toBe(false);
|
|
115
|
+
expect(isRawColor('rgba(255, 255, 255)')).toBe(false);
|
|
116
|
+
expect(isRawColor('hsl(120, 100%)')).toBe(false);
|
|
117
|
+
expect(isRawColor('hsla(120, 100%, 50%)')).toBe(false);
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('should return false for CSS variables', () => {
|
|
121
|
+
expect(isRawColor('var(--main-color)')).toBe(false);
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it('should return true for valid raw color values with leading spaces', () => {
|
|
125
|
+
expect(isRawColor(' #fff')).toBe(true);
|
|
126
|
+
expect(isRawColor(' rgba(255, 255, 255, 1)')).toBe(true);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it('should return true for valid raw color values with multiple spaces', () => {
|
|
130
|
+
expect(isRawColor('rgb(255, 255, 255)')).toBe(true);
|
|
131
|
+
expect(isRawColor('rgba(255, 255, 255, 1)')).toBe(true);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
it('should return true for valid raw color values with any number for the alpha channel', () => {
|
|
135
|
+
expect(isRawColor('rgba(255, 255, 255, 5)')).toBe(true);
|
|
136
|
+
expect(isRawColor('rgba(255, 255, 255, -1)')).toBe(true);
|
|
137
|
+
});
|
|
138
|
+
|
|
139
|
+
it('should return true for less often used color formats', () => {
|
|
140
|
+
expect(isRawColor('lab(50% 0 0)')).toBe(true);
|
|
141
|
+
expect(isRawColor('lch(50% 0 0)')).toBe(true);
|
|
142
|
+
expect(isRawColor('hwb(0 0% 0%)')).toBe(true);
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
});
|