@koobiq/tokens-builder 3.14.0 → 3.15.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/configs/css.js +191 -0
- package/formats/utils.js +2 -2
- package/formats/variables.js +26 -0
- package/package.json +1 -1
package/configs/css.js
CHANGED
|
@@ -1,7 +1,198 @@
|
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
|
|
4
|
+
const paletteColors = ['black', 'blue', 'cyan', 'green', 'grey', 'orange', 'purple', 'red', 'white', 'yellow'];
|
|
5
|
+
const semanticPaletteColors = ['theme', 'success', 'warning', 'error', 'contrast', 'white', 'black', 'purple'];
|
|
6
|
+
|
|
7
|
+
// resolve components path if script used externally
|
|
8
|
+
const componentsPath = fs.existsSync(path.join('node_modules', '@koobiq/design-tokens', 'web', 'components'))
|
|
9
|
+
? path.join('node_modules', '@koobiq/design-tokens', 'web', 'components')
|
|
10
|
+
: path.join('packages', 'design-tokens', 'web', 'components');
|
|
11
|
+
|
|
12
|
+
const componentTokens = fs
|
|
13
|
+
.readdirSync(componentsPath)
|
|
14
|
+
.filter((fileName) => fileName.endsWith('.json5'))
|
|
15
|
+
.map((fileName) => fileName.replace('.json5', ''));
|
|
16
|
+
|
|
17
|
+
const componentTokensBase = componentTokens.map((fileName) => ({
|
|
18
|
+
destination: `deprecated/css/components/${fileName}/${fileName}.css`,
|
|
19
|
+
format: 'kbq-css/variables',
|
|
20
|
+
filter: (token) => token.filePath.includes(fileName) && !token.attributes.light && !token.attributes.dark,
|
|
21
|
+
prefix: 'kbq',
|
|
22
|
+
options: {
|
|
23
|
+
outputReferences: true
|
|
24
|
+
}
|
|
25
|
+
}));
|
|
26
|
+
|
|
27
|
+
const componentTokensLight = componentTokens.map((fileName) => ({
|
|
28
|
+
destination: `deprecated/css/components/${fileName}/${fileName}-light.css`,
|
|
29
|
+
format: 'kbq-css/variables',
|
|
30
|
+
filter: (token) => token.filePath.includes(fileName) && token.attributes.light,
|
|
31
|
+
prefix: 'kbq',
|
|
32
|
+
options: {
|
|
33
|
+
selector: '.kbq-light'
|
|
34
|
+
}
|
|
35
|
+
}));
|
|
36
|
+
|
|
37
|
+
const componentTokensDark = componentTokens.map((fileName) => ({
|
|
38
|
+
destination: `deprecated/css/components/${fileName}/${fileName}-dark.css`,
|
|
39
|
+
format: 'kbq-css/variables',
|
|
40
|
+
filter: (token) => token.filePath.includes(fileName) && token.attributes.dark,
|
|
41
|
+
prefix: 'kbq',
|
|
42
|
+
options: {
|
|
43
|
+
selector: '.kbq-dark'
|
|
44
|
+
}
|
|
45
|
+
}));
|
|
46
|
+
|
|
47
|
+
const paletteByColorsConfig = paletteColors.map((color) => ({
|
|
48
|
+
destination: `css/palette/${color}.css`,
|
|
49
|
+
format: 'kbq-css/variables',
|
|
50
|
+
filter: (token) => token.attributes.category === 'palette' && token.attributes.type === color,
|
|
51
|
+
prefix: 'kbq'
|
|
52
|
+
}));
|
|
53
|
+
|
|
54
|
+
const semanticPaletteConfig = semanticPaletteColors.map((color) => ({
|
|
55
|
+
destination: `css/semantic-palette/${color}.css`,
|
|
56
|
+
format: 'kbq-css/palette',
|
|
57
|
+
filter: (token) =>
|
|
58
|
+
token.filePath.includes('colors.json5') &&
|
|
59
|
+
token.attributes.light &&
|
|
60
|
+
token.attributes.type === color &&
|
|
61
|
+
(token.attributes.palette || token.name.includes('default')),
|
|
62
|
+
prefix: 'kbq'
|
|
63
|
+
}));
|
|
64
|
+
|
|
1
65
|
module.exports = {
|
|
2
66
|
css: {
|
|
3
67
|
transformGroup: 'kbq/css',
|
|
4
68
|
files: [
|
|
69
|
+
...semanticPaletteConfig,
|
|
70
|
+
{
|
|
71
|
+
destination: 'css/light/semantic-palette.css',
|
|
72
|
+
format: 'kbq-css/palette',
|
|
73
|
+
filter: (token) =>
|
|
74
|
+
token.attributes.light &&
|
|
75
|
+
token.filePath.includes('colors.json5') &&
|
|
76
|
+
(token.attributes.palette || token.name.includes('default')),
|
|
77
|
+
prefix: 'kbq',
|
|
78
|
+
options: {
|
|
79
|
+
selector: '.kbq-light'
|
|
80
|
+
}
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
destination: 'css/dark/semantic-palette.css',
|
|
84
|
+
format: 'kbq-css/palette',
|
|
85
|
+
filter: (token) =>
|
|
86
|
+
token.attributes.dark &&
|
|
87
|
+
token.filePath.includes('colors.json5') &&
|
|
88
|
+
(token.attributes.palette || token.name.includes('default')),
|
|
89
|
+
prefix: 'kbq',
|
|
90
|
+
options: {
|
|
91
|
+
selector: '.kbq-dark'
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
destination: 'css/light/semantic-colors.css',
|
|
96
|
+
format: 'kbq-css/palette',
|
|
97
|
+
filter: (token) =>
|
|
98
|
+
token.attributes.light &&
|
|
99
|
+
token.filePath.includes('colors.json5') &&
|
|
100
|
+
!semanticPaletteColors.includes(token.attributes.type),
|
|
101
|
+
prefix: 'kbq',
|
|
102
|
+
options: {
|
|
103
|
+
selector: '.kbq-light'
|
|
104
|
+
}
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
destination: 'css/dark/semantic-colors.css',
|
|
108
|
+
format: 'kbq-css/palette',
|
|
109
|
+
filter: (token) =>
|
|
110
|
+
token.attributes.dark &&
|
|
111
|
+
token.filePath.includes('colors.json5') &&
|
|
112
|
+
!semanticPaletteColors.includes(token.attributes.type),
|
|
113
|
+
prefix: 'kbq',
|
|
114
|
+
options: {
|
|
115
|
+
selector: '.kbq-dark'
|
|
116
|
+
}
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
destination: 'css/font.css',
|
|
120
|
+
format: 'css/variables',
|
|
121
|
+
filter: (token) => token.attributes.category === 'font',
|
|
122
|
+
prefix: 'kbq'
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
destination: 'css/size.css',
|
|
126
|
+
format: 'css/variables',
|
|
127
|
+
filter: (token) => token.attributes.category === 'size',
|
|
128
|
+
prefix: 'kbq'
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
destination: 'css/md-typography.css',
|
|
132
|
+
format: 'css/variables',
|
|
133
|
+
filter: (token) => token.attributes.category === 'md-typography',
|
|
134
|
+
prefix: 'kbq',
|
|
135
|
+
options: {
|
|
136
|
+
outputReferences: true
|
|
137
|
+
}
|
|
138
|
+
},
|
|
139
|
+
...paletteByColorsConfig,
|
|
140
|
+
{
|
|
141
|
+
destination: 'css/palette.css',
|
|
142
|
+
format: 'kbq-css/variables',
|
|
143
|
+
filter: (token) => token.attributes.category === 'palette',
|
|
144
|
+
prefix: 'kbq'
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
destination: 'css/light/shadows.css',
|
|
148
|
+
format: 'kbq-css/variables',
|
|
149
|
+
filter: (token) => token.attributes.light && token.attributes.category === 'shadow',
|
|
150
|
+
prefix: 'kbq',
|
|
151
|
+
options: {
|
|
152
|
+
selector: '.kbq-light'
|
|
153
|
+
}
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
destination: 'css/dark/shadows.css',
|
|
157
|
+
format: 'kbq-css/variables',
|
|
158
|
+
filter: (token) => token.attributes.dark && token.attributes.category === 'shadow',
|
|
159
|
+
prefix: 'kbq',
|
|
160
|
+
options: {
|
|
161
|
+
selector: '.kbq-dark'
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
destination: 'css/typography.css',
|
|
166
|
+
format: 'css/variables',
|
|
167
|
+
filter: (token) => token.attributes.category === 'typography',
|
|
168
|
+
prefix: 'kbq',
|
|
169
|
+
options: {
|
|
170
|
+
outputReferences: true
|
|
171
|
+
}
|
|
172
|
+
},
|
|
173
|
+
...componentTokensBase,
|
|
174
|
+
...componentTokensLight,
|
|
175
|
+
...componentTokensDark,
|
|
176
|
+
{
|
|
177
|
+
destination: 'deprecated/css/components-light.css',
|
|
178
|
+
format: 'kbq-css/variables',
|
|
179
|
+
filter: (token) =>
|
|
180
|
+
token.attributes.light && !token.attributes.palette && token.filePath.includes('components'),
|
|
181
|
+
prefix: 'kbq',
|
|
182
|
+
options: {
|
|
183
|
+
selector: '.kbq-light'
|
|
184
|
+
}
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
destination: 'deprecated/css/components-dark.css',
|
|
188
|
+
format: 'kbq-css/variables',
|
|
189
|
+
filter: (token) =>
|
|
190
|
+
token.attributes.dark && !token.attributes.palette && token.filePath.includes('components'),
|
|
191
|
+
prefix: 'kbq',
|
|
192
|
+
options: {
|
|
193
|
+
selector: '.kbq-dark'
|
|
194
|
+
}
|
|
195
|
+
},
|
|
5
196
|
{
|
|
6
197
|
destination: 'css-tokens.css',
|
|
7
198
|
format: 'css/variables',
|
package/formats/utils.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const transform = require('style-dictionary/lib/common/transforms');
|
|
2
2
|
|
|
3
|
-
const unwrapObjectTransformer = (token) => {
|
|
3
|
+
const unwrapObjectTransformer = (token, additionalAttrs = {}) => {
|
|
4
4
|
return Object.keys(token.value).map((key) => {
|
|
5
5
|
const subToken = token.value[key];
|
|
6
6
|
const res = {
|
|
@@ -10,7 +10,7 @@ const unwrapObjectTransformer = (token) => {
|
|
|
10
10
|
name: `kbq-${[...token.path, key].join('-')}`,
|
|
11
11
|
original: { value: subToken }
|
|
12
12
|
};
|
|
13
|
-
res.attributes = { ...transform['attribute/cti'].transformer(res),
|
|
13
|
+
res.attributes = { ...transform['attribute/cti'].transformer(res), ...additionalAttrs };
|
|
14
14
|
return res;
|
|
15
15
|
}, {});
|
|
16
16
|
};
|
package/formats/variables.js
CHANGED
|
@@ -10,6 +10,31 @@ module.exports = (StyleDictionary) => {
|
|
|
10
10
|
// apply custom transformations for tokens
|
|
11
11
|
dictionary.allProperties = dictionary.allTokens = dictionary.allTokens.flatMap((token) => {
|
|
12
12
|
if (typeof token.value === 'object' && token.type === 'font') {
|
|
13
|
+
return unwrapObjectTransformer(token, { font: true });
|
|
14
|
+
}
|
|
15
|
+
return token;
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
dictionary.allTokens.forEach((token) => {
|
|
19
|
+
token.name = token.name.replace(/(light|dark)-/, '');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
formatHelpers.fileHeader({ file }) +
|
|
24
|
+
`${selector} {\n` +
|
|
25
|
+
formatHelpers.formattedVariables({ format: 'css', dictionary, outputReferences }) +
|
|
26
|
+
`\n}\n`
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
StyleDictionary.registerFormat({
|
|
32
|
+
name: 'kbq-css/palette',
|
|
33
|
+
formatter: function ({ dictionary, options = {}, file }) {
|
|
34
|
+
const { outputReferences, selector = ':root' } = options;
|
|
35
|
+
|
|
36
|
+
dictionary.allProperties = dictionary.allTokens = dictionary.allTokens.flatMap((token) => {
|
|
37
|
+
if (typeof token.value === 'object') {
|
|
13
38
|
return unwrapObjectTransformer(token);
|
|
14
39
|
}
|
|
15
40
|
return token;
|
|
@@ -17,6 +42,7 @@ module.exports = (StyleDictionary) => {
|
|
|
17
42
|
|
|
18
43
|
dictionary.allTokens.forEach((token) => {
|
|
19
44
|
token.name = token.name.replace(/(light|dark)-/, '');
|
|
45
|
+
token.name = token.name.replace(/"/g, '');
|
|
20
46
|
});
|
|
21
47
|
|
|
22
48
|
return (
|
package/package.json
CHANGED