@koobiq/tokens-builder 3.0.0 → 3.2.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/README.md +32 -0
- package/filters/css-variables.js +5 -4
- package/formats/palette.js +2 -14
- package/formats/utils.js +35 -0
- package/formats/variables.js +9 -0
- package/package.json +1 -1
- package/transforms/attribute/theme.js +10 -2
package/README.md
CHANGED
|
@@ -9,3 +9,35 @@ Overall, this script orchestrates the generation of design tokens by applying cu
|
|
|
9
9
|
filters, and formats to the specified theme configuration for multiple platforms,
|
|
10
10
|
facilitating a streamlined design token workflow compatible with
|
|
11
11
|
various output formats like SCSS, CSS, and TypeScript.
|
|
12
|
+
|
|
13
|
+
## Typography composite tokens
|
|
14
|
+
|
|
15
|
+
Tokens builder supports usage of [composite tokens](https://design-tokens.github.io/community-group/format/#composite-design-token) for CSS platform.
|
|
16
|
+
For now, typography token sets are supported.
|
|
17
|
+
|
|
18
|
+
### Example of usage
|
|
19
|
+
|
|
20
|
+
```json
|
|
21
|
+
{
|
|
22
|
+
"<component-name>": {
|
|
23
|
+
"font": {
|
|
24
|
+
"type": "font",
|
|
25
|
+
"<token-with-composite-token-reference>": "{typography.<typography-set>}"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
where `<typography-set>` is a set from `@koobiq/design-tokens/web/properties/typography.json5`
|
|
32
|
+
|
|
33
|
+
"type": "font" property is **required.**
|
|
34
|
+
|
|
35
|
+
output:
|
|
36
|
+
|
|
37
|
+
```
|
|
38
|
+
--kbq-<component-name>-font-<token-with-composite-token-reference>-font-size: <value>;
|
|
39
|
+
--kbq-<component-name>-font-<token-with-composite-token-reference>-font-weight: <value>;
|
|
40
|
+
--kbq-<component-name>-font-<token-with-composite-token-reference>-line-height: <value>;
|
|
41
|
+
--kbq-<component-name>-font-<token-with-composite-token-reference>-font-family: <value>;
|
|
42
|
+
// ...etc
|
|
43
|
+
```
|
package/filters/css-variables.js
CHANGED
|
@@ -7,23 +7,24 @@ module.exports = (StyleDictionary) => {
|
|
|
7
7
|
!prop.attributes.palette &&
|
|
8
8
|
!prop.attributes.light &&
|
|
9
9
|
!prop.attributes.dark &&
|
|
10
|
-
!prop.attributes.font
|
|
10
|
+
!prop.attributes.font &&
|
|
11
|
+
prop.type !== 'font'
|
|
11
12
|
);
|
|
12
13
|
}
|
|
13
14
|
});
|
|
14
15
|
|
|
15
16
|
StyleDictionary.registerFilter({
|
|
16
17
|
name: 'css-variables-light',
|
|
17
|
-
matcher: (prop) => prop.attributes.light
|
|
18
|
+
matcher: (prop) => prop.attributes.light && !prop.attributes.palette
|
|
18
19
|
});
|
|
19
20
|
|
|
20
21
|
StyleDictionary.registerFilter({
|
|
21
22
|
name: 'css-variables-dark',
|
|
22
|
-
matcher: (prop) => prop.attributes.dark
|
|
23
|
+
matcher: (prop) => prop.attributes.dark && !prop.attributes.palette
|
|
23
24
|
});
|
|
24
25
|
|
|
25
26
|
StyleDictionary.registerFilter({
|
|
26
27
|
name: 'css-variables-font',
|
|
27
|
-
matcher: (prop) => prop.attributes.font
|
|
28
|
+
matcher: (prop) => prop.attributes.font || prop.type === 'font'
|
|
28
29
|
});
|
|
29
30
|
};
|
package/formats/palette.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
const { getMapFromObj } = require('../formats/utils');
|
|
2
|
+
|
|
1
3
|
module.exports = (StyleDictionary) => {
|
|
2
4
|
StyleDictionary.registerFormat({
|
|
3
5
|
name: 'kbq-scss/palette',
|
|
@@ -6,17 +8,3 @@ module.exports = (StyleDictionary) => {
|
|
|
6
8
|
}
|
|
7
9
|
});
|
|
8
10
|
};
|
|
9
|
-
|
|
10
|
-
function getMapFromObj(object) {
|
|
11
|
-
const result = Object.keys(object)
|
|
12
|
-
.map((key) => {
|
|
13
|
-
if (key === 'contrast') {
|
|
14
|
-
return `${key}: ${getMapFromObj(object[key])}`;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
return `${key}: ${object[key].value},\n`;
|
|
18
|
-
})
|
|
19
|
-
.join('');
|
|
20
|
-
|
|
21
|
-
return `(\n${result}\n)`;
|
|
22
|
-
}
|
package/formats/utils.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const transform = require('style-dictionary/lib/common/transforms');
|
|
2
|
+
|
|
3
|
+
const unwrapObjectTransformer = (token) => {
|
|
4
|
+
return Object.keys(token.value).map((key) => {
|
|
5
|
+
const subToken = token.value[key];
|
|
6
|
+
const res = {
|
|
7
|
+
...subToken,
|
|
8
|
+
filePath: token.filePath,
|
|
9
|
+
path: [...token.path, key],
|
|
10
|
+
name: `kbq-${[...token.path, key].join('-')}`,
|
|
11
|
+
original: { value: subToken }
|
|
12
|
+
};
|
|
13
|
+
res.attributes = { ...transform['attribute/cti'].transformer(res), font: true };
|
|
14
|
+
return res;
|
|
15
|
+
}, {});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const getMapFromObj = (object) => {
|
|
19
|
+
const result = Object.keys(object)
|
|
20
|
+
.map((key) => {
|
|
21
|
+
if (key === 'contrast') {
|
|
22
|
+
return `${key}: ${getMapFromObj(object[key])}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return `${key}: ${object[key].value},\n`;
|
|
26
|
+
})
|
|
27
|
+
.join('');
|
|
28
|
+
|
|
29
|
+
return `(\n${result}\n)`;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
module.exports = {
|
|
33
|
+
unwrapObjectTransformer,
|
|
34
|
+
getMapFromObj
|
|
35
|
+
};
|
package/formats/variables.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const { formatHelpers } = require('style-dictionary');
|
|
2
|
+
const { unwrapObjectTransformer } = require('../formats/utils');
|
|
2
3
|
|
|
3
4
|
module.exports = (StyleDictionary) => {
|
|
4
5
|
StyleDictionary.registerFormat({
|
|
@@ -7,6 +8,14 @@ module.exports = (StyleDictionary) => {
|
|
|
7
8
|
const selector = options.selector ? options.selector : `:root`;
|
|
8
9
|
const { outputReferences } = options;
|
|
9
10
|
|
|
11
|
+
// apply custom transformations for tokens
|
|
12
|
+
dictionary.allProperties = dictionary.allTokens = dictionary.allTokens.flatMap((token) => {
|
|
13
|
+
if (typeof token.value === 'object' && token.type === 'font') {
|
|
14
|
+
return unwrapObjectTransformer(token);
|
|
15
|
+
}
|
|
16
|
+
return token;
|
|
17
|
+
});
|
|
18
|
+
|
|
10
19
|
dictionary.allTokens.forEach((token) => {
|
|
11
20
|
token.name = token.name.replace(/(light|dark)-/, '');
|
|
12
21
|
});
|
package/package.json
CHANGED
|
@@ -3,7 +3,11 @@ module.exports = (StyleDictionary) => {
|
|
|
3
3
|
name: 'kbq-attribute/light',
|
|
4
4
|
type: 'attribute',
|
|
5
5
|
matcher: ({ attributes }) => {
|
|
6
|
-
return (
|
|
6
|
+
return (
|
|
7
|
+
(attributes.category === 'markdown' && attributes.item === 'light') ||
|
|
8
|
+
attributes.type === 'light' ||
|
|
9
|
+
attributes.category === 'light'
|
|
10
|
+
);
|
|
7
11
|
},
|
|
8
12
|
transformer: () => ({ light: true })
|
|
9
13
|
});
|
|
@@ -12,7 +16,11 @@ module.exports = (StyleDictionary) => {
|
|
|
12
16
|
name: 'kbq-attribute/dark',
|
|
13
17
|
type: 'attribute',
|
|
14
18
|
matcher: ({ attributes }) => {
|
|
15
|
-
return (
|
|
19
|
+
return (
|
|
20
|
+
(attributes.category === 'markdown' && attributes.item === 'dark') ||
|
|
21
|
+
attributes.type === 'dark' ||
|
|
22
|
+
attributes.category === 'dark'
|
|
23
|
+
);
|
|
16
24
|
},
|
|
17
25
|
transformer: () => ({ dark: true })
|
|
18
26
|
});
|