@projectwallace/css-design-tokens 0.11.0 → 0.11.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/readme.md 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
- color,
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
- useLocations: true // may be `true` or `false`, it works either way
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
- `.my-design-system {
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
- 'green-5e0cf03': {
96
- $type: 'color',
97
- $value: {
98
- colorSpace: 'srgb',
99
- components: [0, 0.5019607843137255, 0],
100
- alpha: 1,
101
- },
102
- $extensions: {
103
- 'com.projectwallace.css-authored-as': 'green',
104
- 'com.projectwallace.usage-count': 2,
105
- 'com.projectwallace.css-properties': ['color', 'border-color'],
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
- 'fontSize-171eed': {
128
- $type: 'dimension',
129
- $value: {
130
- value: 16,
131
- unit: 'px'
132
- },
133
- $extensions: {
134
- 'com.projectwallace.css-authored-as': '16px',
135
- 'com.projectwallace.usage-count': 1,
136
- }
137
- },
138
- 'fontSize-582e015a': {
139
- $value: '20vmin',
140
- $extensions: {
141
- 'com.projectwallace.css-authored-as': '20vmin',
142
- 'com.projectwallace.usage-count': 1,
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
- 'fontFamily-3375cf09': {
164
- $type: 'fontFamily',
165
- $value: ['\'Inter\''],
166
- $extensions: {
167
- 'com.projectwallace.css-authored-as': '\'Inter\'',
168
- 'com.projectwallace.usage-count': 1,
169
- }
170
- },
171
- 'fontFamily-582e015a': {
172
- $type: 'fontFamily',
173
- $value: ['Arial Black', 'sans-serif'],
174
- $extensions: {
175
- 'com.projectwallace.css-authored-as': 'Arial Black, sans-serif',
176
- 'com.projectwallace.usage-count': 1,
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
- 'lineHeight-563f7fe2': {
197
- $type: 'dimension',
198
- $value: {
199
- value: 1.5,
200
- unit: 'rem'
201
- },
202
- $extensions: {
203
- 'com.projectwallace.css-authored-as': '1.5rem',
204
- 'com.projectwallace.usage-count': 1,
205
- }
206
- },
207
- 'lineHeight-bdb8': {
208
- $type: 'number',
209
- $value: 1.5,
210
- $extensions: {
211
- 'com.projectwallace.css-authored-as': '1.5',
212
- 'com.projectwallace.usage-count': 1,
213
- }
214
- },
215
- 'lineHeight-582e015a': {
216
- $value: '20vmin',
217
- $extensions: {
218
- 'com.projectwallace.css-authored-as': '20vmin',
219
- 'com.projectwallace.usage-count': 1,
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
- 'gradient-2aec04e5': {
238
- $value: 'linear-gradient(to right, red, blue)',
239
- $extensions: {
240
- 'com.projectwallace.css-authored-as': 'linear-gradient(to right, red, blue)',
241
- 'com.projectwallace.usage-count': 1,
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
- 'boxShadow-6f90da6b': {
265
- $type: 'shadow',
266
- $value: {
267
- offsetX: {
268
- value: 0,
269
- unit: 'px'
270
- },
271
- offsetY: {
272
- value: 0,
273
- unit: 'px'
274
- },
275
- blur: {
276
- value: 10,
277
- unit: 'px'
278
- },
279
- spread: {
280
- value: 0,
281
- unit: 'px'
282
- },
283
- inset: false,
284
- color: {
285
- colorSpace: 'srgb',
286
- components: [0, 0, 0],
287
- alpha: 0.5,
288
- },
289
- },
290
- $extensions: {
291
- 'com.projectwallace.css-authored-as': '0 0 10px 0 rgba(0, 0, 0, 0.5)',
292
- 'com.projectwwallace.usage-count': 1,
293
- }
294
- },
295
- 'boxShadow-be2751ac': {
296
- $type: 'shadow',
297
- $value: [
298
- {
299
- offsetX: {
300
- value: 0,
301
- unit: 'px'
302
- },
303
- offsetY: {
304
- value: 0,
305
- unit: 'px'
306
- },
307
- blur: {
308
- value: 10,
309
- unit: 'px'
310
- },
311
- spread: {
312
- value: 0,
313
- unit: 'px'
314
- },
315
- inset: false,
316
- color: {
317
- colorSpace: 'srgb',
318
- components: [0, 0, 0],
319
- alpha: 0.5,
320
- },
321
- },
322
- {
323
- offsetX: {
324
- value: 0,
325
- unit: 'px'
326
- },
327
- offsetY: {
328
- value: 0,
329
- unit: 'px'
330
- },
331
- blur: {
332
- value: 10,
333
- unit: 'px'
334
- },
335
- spread: {
336
- value: 0,
337
- unit: 'px'
338
- },
339
- inset: false,
340
- color: {
341
- colorSpace: 'srgb',
342
- components: [0, 0, 0],
343
- alpha: 0.5,
344
- },
345
- }
346
- ],
347
- $extensions: {
348
- 'com.projectwwallace.css-authored-as': '0 0 10px 0 rgba(0, 0, 0, 0.5), 0 0 10px 0 rgba(0, 0, 0, 0.5)',
349
- 'com.projectwwallace.usage-count': 1,
350
- }
351
- },
352
- 'boxShadow-j4h5gas5h': {
353
- $value: '0 0 0 0 var(--red)',
354
- $extensions: {
355
- 'com.projectwwallace.css-authored-as': '0 0 0 0 var(--red)',
356
- 'com.projectwwallace.usage-count': 1,
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
- 'radius-170867': {
375
- $value: '10px',
376
- $extensions: {
377
- 'com.projectwwallace.css-authored-as': '10px',
378
- 'com.projectwwallace.usage-count': 1,
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
- 'duration-17005f': {
399
- $type: 'duration',
400
- $value: {
401
- value: 1000,
402
- unit: 'ms'
403
- },
404
- $extensions: {
405
- 'com.projectwwallace.css-authored-as': '1s',
406
- 'com.projectwwallace.usage-count': 1,
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
- 'easing-ea6c7565': {
429
- $type: 'cubicBezier',
430
- $value: [
431
- 0.42,
432
- 0,
433
- 0.58,
434
- 1
435
- ],
436
- $extensions: {
437
- 'com.projectwwallace.css-authored-as': 'ease-in-out',
438
- 'com.projectwwallace.usage-count': 1,
439
- }
440
- },
441
- 'easing-90111eba': {
442
- $type: 'cubicBezier',
443
- $value: [
444
- 0,
445
- 0,
446
- 0.5,
447
- 0.8
448
- ],
449
- $extensions: {
450
- 'com.projectwwallace.css-authored-as': 'cubic-bezier(0, 0, 0.5, .8)',
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
- __For color tokens only__
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
@@ -1,2 +0,0 @@
1
- import { ColorValue } from './types.js';
2
- export declare function color_to_token(color: string): ColorValue | null;