You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Create Design Tokens by going through CSS to find colors, font-sizes, gradients etcetera and turn them into a spec-compliant token format.
3
+
Create Design Tokens by going through CSS to find colors, font-sizes, gradients etcetera and turn them into a [Design Tokens spec](https://tr.designtokens.org/)-compliant token format.
let analysis =analyze(`.my-design-system { color: green; }`, {
24
-
useLocations:true//MUST be true
33
+
useLocations:true//may be `true` or `false`, it works either way
25
34
})
26
35
let tokens =analysis_to_tokens(analysis)
27
36
```
28
37
38
+
### Stable unique token ID's
39
+
40
+
All tokens have a stabe unique ID using a very simple hashing algorithm. This is helpful when you run analysis multiple times over your project and lets you identify removed or added tokens easily.
41
+
42
+
```ts
43
+
let { color } =css_to_tokens(
44
+
`.my-design-system {
45
+
color: green;
46
+
color: rgb(100 100 100 / 20%);
47
+
}`
48
+
)
49
+
50
+
// {
51
+
// 'green-5e0cf03': {
52
+
// $type: 'color',
53
+
// ...
54
+
// },
55
+
// 'grey-8139d9b': {
56
+
// $type: 'color',
57
+
// ...
58
+
// }
59
+
// }
60
+
```
61
+
62
+
### Getting authored values
63
+
64
+
The tokens output parses most CSS into Design Tokens but in most cases it also provides a way to get the authored CSS via the `$extensions` property. The custom identifier for this project is `com.projectwallace` and the authored values can be found with `com.projectwallace.css-authored-as` on the `$extensions` object.
65
+
66
+
```ts
67
+
let { color } =css_to_tokens(`.my-design-system { color: green; }`)
68
+
69
+
// {
70
+
// 'green-5e0cf03': {
71
+
// ...
72
+
// $extensions: {
73
+
// 'com.projectwallace.css-authored-as': 'green'
74
+
// }
75
+
// },
76
+
// }
77
+
78
+
let authored_green =color['green-5e0cf03']['$extensions']['com.projectwallace.css-authored-as']
79
+
80
+
// 'green'
81
+
```
82
+
29
83
## Acknowledgements
30
84
31
85
-[CSSTree](https://github.com/csstree/csstree) does all the heavy lifting of parsing CSS
32
-
-[ColorJS.io](https://colorjs.io/) powers all color conversions necessary for grouping and sorting
86
+
-[ColorJS.io](https://colorjs.io/) powers all color conversions necessary for grouping and sorting and converting into Color tokens
33
87
34
88
## Related projects
35
89
90
+
-[Design Tokens analyzer](https://www.projectwallace.com/design-tokens) - Online CSS to Design Tokens convernter, uses this package
36
91
-[CSS Analyzer](https://github.com/projectwallace/css-analyzer) - The best CSS analyzer that powers all analysis on [projectwallace.com](https://www.projectwallace.com?utm_source=github&utm_medium=wallace_format_css_related_projects)
0 commit comments