@projectwallace/css-design-tokens 0.3.2 → 0.4.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/css-design-tokens.js +852 -9051
- package/dist/index.d.ts +15 -29
- package/dist/keyword-set.d.ts +1 -1
- package/dist/types.d.ts +6 -1
- package/package.json +3 -3
- package/readme.md +62 -6
package/dist/index.d.ts
CHANGED
|
@@ -1,30 +1,16 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
duration: Record<string, DurationToken | UnparsedToken>;
|
|
15
|
-
easing: Record<string, UnparsedToken | CubicBezierToken>;
|
|
16
|
-
};
|
|
17
|
-
export declare function analysis_to_tokens(analysis: CssAnalysis): {
|
|
18
|
-
color: Record<string, UnparsedToken | ColorToken>;
|
|
19
|
-
font_size: Record<string, UnparsedToken | DimensionToken>;
|
|
20
|
-
font_family: Record<string, FontFamilyToken>;
|
|
21
|
-
line_height: Record<string, UnparsedToken | DimensionToken | NumberToken>;
|
|
22
|
-
gradient: Record<string, UnparsedToken>;
|
|
23
|
-
box_shadow: Record<string, UnparsedToken | (BaseToken & {
|
|
24
|
-
$type: "shadow";
|
|
25
|
-
$value: DestructuredShadow | DestructuredShadow[];
|
|
26
|
-
})>;
|
|
27
|
-
radius: Record<string, UnparsedToken>;
|
|
28
|
-
duration: Record<string, DurationToken | UnparsedToken>;
|
|
29
|
-
easing: Record<string, UnparsedToken | CubicBezierToken>;
|
|
1
|
+
import { CubicBezierToken, DimensionToken, DurationToken, FontFamilyToken, NumberToken, UnparsedToken, ColorToken, CssAnalysis, ShadowToken } from './types.js';
|
|
2
|
+
export declare function css_to_tokens(css: string): Tokens;
|
|
3
|
+
type TokenID = string;
|
|
4
|
+
type Tokens = {
|
|
5
|
+
color: Record<TokenID, ColorToken | UnparsedToken>;
|
|
6
|
+
font_size: Record<TokenID, UnparsedToken | DimensionToken>;
|
|
7
|
+
font_family: Record<TokenID, FontFamilyToken>;
|
|
8
|
+
line_height: Record<TokenID, UnparsedToken | DimensionToken | NumberToken>;
|
|
9
|
+
gradient: Record<TokenID, UnparsedToken>;
|
|
10
|
+
box_shadow: Record<TokenID, ShadowToken | UnparsedToken>;
|
|
11
|
+
radius: Record<TokenID, UnparsedToken>;
|
|
12
|
+
duration: Record<TokenID, DurationToken | UnparsedToken>;
|
|
13
|
+
easing: Record<TokenID, UnparsedToken | CubicBezierToken>;
|
|
30
14
|
};
|
|
15
|
+
export declare function analysis_to_tokens(analysis: CssAnalysis): Tokens;
|
|
16
|
+
export {};
|
package/dist/keyword-set.d.ts
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { analyze } from '@projectwallace/css-analyzer';
|
|
2
|
+
import { DestructuredShadow } from './destructure-box-shadow';
|
|
2
3
|
export type CssAnalysis = ReturnType<typeof analyze>;
|
|
3
4
|
export declare const EXTENSION_AUTHORED_AS = "com.projectwallace.css-authored-as";
|
|
4
5
|
export type Easing = [number, number, number, number];
|
|
5
6
|
export type BaseToken = {
|
|
6
7
|
$extensions?: {
|
|
7
|
-
[EXTENSION_AUTHORED_AS]
|
|
8
|
+
[EXTENSION_AUTHORED_AS]: string;
|
|
8
9
|
};
|
|
9
10
|
};
|
|
10
11
|
export type DurationToken = BaseToken & {
|
|
@@ -52,4 +53,8 @@ export type FontFamilyToken = BaseToken & {
|
|
|
52
53
|
$type: 'fontFamily';
|
|
53
54
|
$value: string[] | string;
|
|
54
55
|
};
|
|
56
|
+
export type ShadowToken = BaseToken & {
|
|
57
|
+
$type: 'shadow';
|
|
58
|
+
$value: DestructuredShadow | DestructuredShadow[];
|
|
59
|
+
};
|
|
55
60
|
export {};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@projectwallace/css-design-tokens",
|
|
3
3
|
"description": "Generate spec-compliant Design Tokens from CSS.",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.4.1",
|
|
5
5
|
"license": "EUPL-1.2",
|
|
6
6
|
"author": "Bart Veneman <bart@projectwallace.com>",
|
|
7
7
|
"repository": {
|
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"check": "tsc --noEmit"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@projectwallace/css-analyzer": "^7.5.
|
|
37
|
+
"@projectwallace/css-analyzer": "^7.5.1",
|
|
38
38
|
"color-sorter": "^7.0.0",
|
|
39
39
|
"colorjs.io": "^0.6.0-alpha.1",
|
|
40
40
|
"css-time-sort": "^3.0.0",
|
|
@@ -42,7 +42,7 @@
|
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
44
|
"@types/css-tree": "^2.3.10",
|
|
45
|
-
"vite": "^7.0.
|
|
45
|
+
"vite": "^7.0.4",
|
|
46
46
|
"vite-plugin-dts": "^4.5.4",
|
|
47
47
|
"vitest": "^3.2.4"
|
|
48
48
|
}
|
package/readme.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# css-design-tokens
|
|
2
2
|
|
|
3
|
-
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.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -13,26 +13,82 @@ npm install @projectwallace/css-design-tokens
|
|
|
13
13
|
```js
|
|
14
14
|
import { css_to_tokens } from '@projectwallace/css-design-tokens'
|
|
15
15
|
|
|
16
|
-
let
|
|
16
|
+
let {
|
|
17
|
+
color,
|
|
18
|
+
font_size,
|
|
19
|
+
font_family,
|
|
20
|
+
line_height,
|
|
21
|
+
gradient,
|
|
22
|
+
box_shadow,
|
|
23
|
+
radius,
|
|
24
|
+
duration,
|
|
25
|
+
easing,
|
|
26
|
+
} = css_to_tokens(`.my-design-system { color: green; }`)
|
|
17
27
|
|
|
18
|
-
// Or if you already have done CSS analysis with @projectwallace/css-analyzer
|
|
19
|
-
// NOTE: it is important that `useLocations` is true
|
|
28
|
+
// Or if you already have done CSS analysis with @projectwallace/css-analyzer
|
|
20
29
|
import { analyze } from '@projectwallace/css-analyzer'
|
|
21
30
|
import { analysis_to_tokens } from '@projectwallace/css-design-tokens'
|
|
22
31
|
|
|
23
32
|
let analysis = analyze(`.my-design-system { color: green; }`, {
|
|
24
|
-
useLocations: 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)
|
|
37
92
|
- [Color Sorter](https://github.com/projectwallace/color-sorter) - Sort CSS colors
|
|
38
93
|
by hue, saturation, lightness and opacity
|
|
94
|
+
- [CSS Time Sort](https://github.com/projectwallace/css-time-sort) - Sort an array of `<time>` values
|