@projectwallace/css-design-tokens 0.10.0 → 0.11.1
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/index.d.ts +101 -17
- package/dist/index.js +618 -0
- package/package.json +35 -27
- package/readme.md +223 -242
- package/dist/colors.d.ts +0 -2
- package/dist/css-design-tokens.js +0 -486
- package/dist/destructure-box-shadow.d.ts +0 -14
- package/dist/destructure-box-shadow.test.d.ts +0 -1
- package/dist/destructure-easing.d.ts +0 -2
- package/dist/destructure-easing.test.d.ts +0 -1
- package/dist/destructure-font-family.d.ts +0 -2
- package/dist/destructure-font-family.test.d.ts +0 -1
- package/dist/destructure-line-height.d.ts +0 -10
- package/dist/destructure-line-height.test.d.ts +0 -1
- package/dist/group-colors.d.ts +0 -4
- package/dist/hash.d.ts +0 -1
- package/dist/hash.test.d.ts +0 -1
- package/dist/index.test.d.ts +0 -1
- package/dist/parse-length.d.ts +0 -13
- package/dist/parse-length.test.d.ts +0 -1
- package/dist/types.d.ts +0 -70
- package/dist/unquote.d.ts +0 -1
- package/dist/unquote.test.d.ts +0 -1
package/readme.md
CHANGED
|
@@ -30,24 +30,15 @@ npm install @projectwallace/css-design-tokens
|
|
|
30
30
|
```js
|
|
31
31
|
import { css_to_tokens } from '@projectwallace/css-design-tokens'
|
|
32
32
|
|
|
33
|
-
let {
|
|
34
|
-
|
|
35
|
-
font_size,
|
|
36
|
-
font_family,
|
|
37
|
-
line_height,
|
|
38
|
-
gradient,
|
|
39
|
-
box_shadow,
|
|
40
|
-
radius,
|
|
41
|
-
duration,
|
|
42
|
-
easing,
|
|
43
|
-
} = css_to_tokens(`.my-design-system { color: green; }`)
|
|
33
|
+
let { color, font_size, font_family, line_height, gradient, box_shadow, radius, duration, easing } =
|
|
34
|
+
css_to_tokens(`.my-design-system { color: green; }`)
|
|
44
35
|
|
|
45
36
|
// Or if you already have done CSS analysis with @projectwallace/css-analyzer
|
|
46
37
|
import { analyze } from '@projectwallace/css-analyzer'
|
|
47
38
|
import { analysis_to_tokens } from '@projectwallace/css-design-tokens'
|
|
48
39
|
|
|
49
40
|
let analysis = analyze(`.my-design-system { color: green; }`, {
|
|
50
|
-
|
|
41
|
+
useLocations: true, // may be `true` or `false`, it works either way
|
|
51
42
|
})
|
|
52
43
|
let tokens = analysis_to_tokens(analysis)
|
|
53
44
|
```
|
|
@@ -58,10 +49,10 @@ All tokens have a stabe unique ID using a very simple hashing algorithm. This is
|
|
|
58
49
|
|
|
59
50
|
```ts
|
|
60
51
|
let { color } = css_to_tokens(
|
|
61
|
-
|
|
52
|
+
`.my-design-system {
|
|
62
53
|
color: green;
|
|
63
54
|
color: rgb(100 100 100 / 20%);
|
|
64
|
-
}
|
|
55
|
+
}`,
|
|
65
56
|
)
|
|
66
57
|
|
|
67
58
|
// {
|
|
@@ -92,19 +83,19 @@ Only fully compliant colors are listed. Colors that can't be parsed by [colorjs.
|
|
|
92
83
|
let { color } = css_to_tokens(`.my-design-system { color: green; }`)
|
|
93
84
|
|
|
94
85
|
let color = {
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
86
|
+
'green-5e0cf03': {
|
|
87
|
+
$type: 'color',
|
|
88
|
+
$value: {
|
|
89
|
+
colorSpace: 'srgb',
|
|
90
|
+
components: [0, 0.5019607843137255, 0],
|
|
91
|
+
alpha: 1,
|
|
92
|
+
},
|
|
93
|
+
$extensions: {
|
|
94
|
+
'com.projectwallace.css-authored-as': 'green',
|
|
95
|
+
'com.projectwallace.usage-count': 2,
|
|
96
|
+
'com.projectwallace.css-properties': ['color', 'border-color'],
|
|
97
|
+
},
|
|
98
|
+
},
|
|
108
99
|
}
|
|
109
100
|
```
|
|
110
101
|
|
|
@@ -124,24 +115,24 @@ let { font_size } = css_to_tokens(`.my-design-system {
|
|
|
124
115
|
}`)
|
|
125
116
|
|
|
126
117
|
let font_size = {
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
118
|
+
'fontSize-171eed': {
|
|
119
|
+
$type: 'dimension',
|
|
120
|
+
$value: {
|
|
121
|
+
value: 16,
|
|
122
|
+
unit: 'px',
|
|
123
|
+
},
|
|
124
|
+
$extensions: {
|
|
125
|
+
'com.projectwallace.css-authored-as': '16px',
|
|
126
|
+
'com.projectwallace.usage-count': 1,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
'fontSize-582e015a': {
|
|
130
|
+
$value: '20vmin',
|
|
131
|
+
$extensions: {
|
|
132
|
+
'com.projectwallace.css-authored-as': '20vmin',
|
|
133
|
+
'com.projectwallace.usage-count': 1,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
145
136
|
}
|
|
146
137
|
```
|
|
147
138
|
|
|
@@ -160,22 +151,22 @@ let { font_family } = css_to_tokens(`.my-design-system {
|
|
|
160
151
|
}`)
|
|
161
152
|
|
|
162
153
|
let font_family = {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
154
|
+
'fontFamily-3375cf09': {
|
|
155
|
+
$type: 'fontFamily',
|
|
156
|
+
$value: ["'Inter'"],
|
|
157
|
+
$extensions: {
|
|
158
|
+
'com.projectwallace.css-authored-as': "'Inter'",
|
|
159
|
+
'com.projectwallace.usage-count': 1,
|
|
160
|
+
},
|
|
161
|
+
},
|
|
162
|
+
'fontFamily-582e015a': {
|
|
163
|
+
$type: 'fontFamily',
|
|
164
|
+
$value: ['Arial Black', 'sans-serif'],
|
|
165
|
+
$extensions: {
|
|
166
|
+
'com.projectwallace.css-authored-as': 'Arial Black, sans-serif',
|
|
167
|
+
'com.projectwallace.usage-count': 1,
|
|
168
|
+
},
|
|
169
|
+
},
|
|
179
170
|
}
|
|
180
171
|
```
|
|
181
172
|
|
|
@@ -193,32 +184,32 @@ let { line_height } = css_to_tokens(`
|
|
|
193
184
|
`)
|
|
194
185
|
|
|
195
186
|
let line_height = {
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
187
|
+
'lineHeight-563f7fe2': {
|
|
188
|
+
$type: 'dimension',
|
|
189
|
+
$value: {
|
|
190
|
+
value: 1.5,
|
|
191
|
+
unit: 'rem',
|
|
192
|
+
},
|
|
193
|
+
$extensions: {
|
|
194
|
+
'com.projectwallace.css-authored-as': '1.5rem',
|
|
195
|
+
'com.projectwallace.usage-count': 1,
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
'lineHeight-bdb8': {
|
|
199
|
+
$type: 'number',
|
|
200
|
+
$value: 1.5,
|
|
201
|
+
$extensions: {
|
|
202
|
+
'com.projectwallace.css-authored-as': '1.5',
|
|
203
|
+
'com.projectwallace.usage-count': 1,
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
'lineHeight-582e015a': {
|
|
207
|
+
$value: '20vmin',
|
|
208
|
+
$extensions: {
|
|
209
|
+
'com.projectwallace.css-authored-as': '20vmin',
|
|
210
|
+
'com.projectwallace.usage-count': 1,
|
|
211
|
+
},
|
|
212
|
+
},
|
|
222
213
|
}
|
|
223
214
|
```
|
|
224
215
|
|
|
@@ -234,13 +225,13 @@ let { gradient } = css_to_tokens(`
|
|
|
234
225
|
`)
|
|
235
226
|
|
|
236
227
|
let gradient = {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
228
|
+
'gradient-2aec04e5': {
|
|
229
|
+
$value: 'linear-gradient(to right, red, blue)',
|
|
230
|
+
$extensions: {
|
|
231
|
+
'com.projectwallace.css-authored-as': 'linear-gradient(to right, red, blue)',
|
|
232
|
+
'com.projectwallace.usage-count': 1,
|
|
233
|
+
},
|
|
234
|
+
},
|
|
244
235
|
}
|
|
245
236
|
```
|
|
246
237
|
|
|
@@ -261,101 +252,102 @@ let { box_shadow } = css_to_tokens(`
|
|
|
261
252
|
`)
|
|
262
253
|
|
|
263
254
|
let box_shadow = {
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
255
|
+
'boxShadow-6f90da6b': {
|
|
256
|
+
$type: 'shadow',
|
|
257
|
+
$value: {
|
|
258
|
+
offsetX: {
|
|
259
|
+
value: 0,
|
|
260
|
+
unit: 'px',
|
|
261
|
+
},
|
|
262
|
+
offsetY: {
|
|
263
|
+
value: 0,
|
|
264
|
+
unit: 'px',
|
|
265
|
+
},
|
|
266
|
+
blur: {
|
|
267
|
+
value: 10,
|
|
268
|
+
unit: 'px',
|
|
269
|
+
},
|
|
270
|
+
spread: {
|
|
271
|
+
value: 0,
|
|
272
|
+
unit: 'px',
|
|
273
|
+
},
|
|
274
|
+
inset: false,
|
|
275
|
+
color: {
|
|
276
|
+
colorSpace: 'srgb',
|
|
277
|
+
components: [0, 0, 0],
|
|
278
|
+
alpha: 0.5,
|
|
279
|
+
},
|
|
280
|
+
},
|
|
281
|
+
$extensions: {
|
|
282
|
+
'com.projectwallace.css-authored-as': '0 0 10px 0 rgba(0, 0, 0, 0.5)',
|
|
283
|
+
'com.projectwwallace.usage-count': 1,
|
|
284
|
+
},
|
|
285
|
+
},
|
|
286
|
+
'boxShadow-be2751ac': {
|
|
287
|
+
$type: 'shadow',
|
|
288
|
+
$value: [
|
|
289
|
+
{
|
|
290
|
+
offsetX: {
|
|
291
|
+
value: 0,
|
|
292
|
+
unit: 'px',
|
|
293
|
+
},
|
|
294
|
+
offsetY: {
|
|
295
|
+
value: 0,
|
|
296
|
+
unit: 'px',
|
|
297
|
+
},
|
|
298
|
+
blur: {
|
|
299
|
+
value: 10,
|
|
300
|
+
unit: 'px',
|
|
301
|
+
},
|
|
302
|
+
spread: {
|
|
303
|
+
value: 0,
|
|
304
|
+
unit: 'px',
|
|
305
|
+
},
|
|
306
|
+
inset: false,
|
|
307
|
+
color: {
|
|
308
|
+
colorSpace: 'srgb',
|
|
309
|
+
components: [0, 0, 0],
|
|
310
|
+
alpha: 0.5,
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
offsetX: {
|
|
315
|
+
value: 0,
|
|
316
|
+
unit: 'px',
|
|
317
|
+
},
|
|
318
|
+
offsetY: {
|
|
319
|
+
value: 0,
|
|
320
|
+
unit: 'px',
|
|
321
|
+
},
|
|
322
|
+
blur: {
|
|
323
|
+
value: 10,
|
|
324
|
+
unit: 'px',
|
|
325
|
+
},
|
|
326
|
+
spread: {
|
|
327
|
+
value: 0,
|
|
328
|
+
unit: 'px',
|
|
329
|
+
},
|
|
330
|
+
inset: false,
|
|
331
|
+
color: {
|
|
332
|
+
colorSpace: 'srgb',
|
|
333
|
+
components: [0, 0, 0],
|
|
334
|
+
alpha: 0.5,
|
|
335
|
+
},
|
|
336
|
+
},
|
|
337
|
+
],
|
|
338
|
+
$extensions: {
|
|
339
|
+
'com.projectwwallace.css-authored-as':
|
|
340
|
+
'0 0 10px 0 rgba(0, 0, 0, 0.5), 0 0 10px 0 rgba(0, 0, 0, 0.5)',
|
|
341
|
+
'com.projectwwallace.usage-count': 1,
|
|
342
|
+
},
|
|
343
|
+
},
|
|
344
|
+
'boxShadow-j4h5gas5h': {
|
|
345
|
+
$value: '0 0 0 0 var(--red)',
|
|
346
|
+
$extensions: {
|
|
347
|
+
'com.projectwwallace.css-authored-as': '0 0 0 0 var(--red)',
|
|
348
|
+
'com.projectwwallace.usage-count': 1,
|
|
349
|
+
},
|
|
350
|
+
},
|
|
359
351
|
}
|
|
360
352
|
```
|
|
361
353
|
|
|
@@ -371,13 +363,13 @@ let { radius } = css_to_tokens(`
|
|
|
371
363
|
`)
|
|
372
364
|
|
|
373
365
|
let radius = {
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
366
|
+
'radius-170867': {
|
|
367
|
+
$value: '10px',
|
|
368
|
+
$extensions: {
|
|
369
|
+
'com.projectwwallace.css-authored-as': '10px',
|
|
370
|
+
'com.projectwwallace.usage-count': 1,
|
|
371
|
+
},
|
|
372
|
+
},
|
|
381
373
|
}
|
|
382
374
|
```
|
|
383
375
|
|
|
@@ -395,17 +387,17 @@ let { duration } = css_to_tokens(`
|
|
|
395
387
|
`)
|
|
396
388
|
|
|
397
389
|
let duration = {
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
390
|
+
'duration-17005f': {
|
|
391
|
+
$type: 'duration',
|
|
392
|
+
$value: {
|
|
393
|
+
value: 1000,
|
|
394
|
+
unit: 'ms',
|
|
395
|
+
},
|
|
396
|
+
$extensions: {
|
|
397
|
+
'com.projectwwallace.css-authored-as': '1s',
|
|
398
|
+
'com.projectwwallace.usage-count': 1,
|
|
399
|
+
},
|
|
400
|
+
},
|
|
409
401
|
}
|
|
410
402
|
```
|
|
411
403
|
|
|
@@ -425,39 +417,29 @@ let actual = css_to_tokens(`
|
|
|
425
417
|
`)
|
|
426
418
|
|
|
427
419
|
let easing = {
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
'com.projectwwallace.usage-count': 1,
|
|
452
|
-
}
|
|
453
|
-
},
|
|
454
|
-
'easing-12bb7f36': {
|
|
455
|
-
$value: 'var(--test)',
|
|
456
|
-
$extensions: {
|
|
457
|
-
'com.projectwwallace.css-authored-as': 'var(--test)',
|
|
458
|
-
'com.projectwwallace.usage-count': 1,
|
|
459
|
-
}
|
|
460
|
-
}
|
|
420
|
+
'easing-ea6c7565': {
|
|
421
|
+
$type: 'cubicBezier',
|
|
422
|
+
$value: [0.42, 0, 0.58, 1],
|
|
423
|
+
$extensions: {
|
|
424
|
+
'com.projectwwallace.css-authored-as': 'ease-in-out',
|
|
425
|
+
'com.projectwwallace.usage-count': 1,
|
|
426
|
+
},
|
|
427
|
+
},
|
|
428
|
+
'easing-90111eba': {
|
|
429
|
+
$type: 'cubicBezier',
|
|
430
|
+
$value: [0, 0, 0.5, 0.8],
|
|
431
|
+
$extensions: {
|
|
432
|
+
'com.projectwwallace.css-authored-as': 'cubic-bezier(0, 0, 0.5, .8)',
|
|
433
|
+
'com.projectwwallace.usage-count': 1,
|
|
434
|
+
},
|
|
435
|
+
},
|
|
436
|
+
'easing-12bb7f36': {
|
|
437
|
+
$value: 'var(--test)',
|
|
438
|
+
$extensions: {
|
|
439
|
+
'com.projectwwallace.css-authored-as': 'var(--test)',
|
|
440
|
+
'com.projectwwallace.usage-count': 1,
|
|
441
|
+
},
|
|
442
|
+
},
|
|
461
443
|
}
|
|
462
444
|
```
|
|
463
445
|
|
|
@@ -509,7 +491,7 @@ let green_count = color['green-5e0cf03']['$extensions']['com.projectwallace.usag
|
|
|
509
491
|
|
|
510
492
|
### CSS property usage
|
|
511
493
|
|
|
512
|
-
|
|
494
|
+
**For color tokens only**
|
|
513
495
|
|
|
514
496
|
You can read the `$extensions['com.projectwallace.css-properties']` property to see for which CSS properties a color was used:
|
|
515
497
|
|
|
@@ -532,7 +514,6 @@ let properties = color['green-5e0cf03']['$extensions']['com.projectwallace.css-p
|
|
|
532
514
|
|
|
533
515
|
## Acknowledgements
|
|
534
516
|
|
|
535
|
-
- [CSSTree](https://github.com/csstree/csstree) does all the heavy lifting of parsing CSS
|
|
536
517
|
- [ColorJS.io](https://colorjs.io/) powers all color conversions necessary for grouping and sorting and converting into Color tokens
|
|
537
518
|
|
|
538
519
|
## Related projects
|
package/dist/colors.d.ts
DELETED