@koobiq/tokens-builder 4.0.1 → 4.1.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 +21 -16
- package/build.js +2 -0
- package/configs/scss.js +5 -0
- package/formats/palette.js +36 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,32 +12,37 @@ various output formats like SCSS, CSS, and TypeScript.
|
|
|
12
12
|
|
|
13
13
|
## Typography composite tokens
|
|
14
14
|
|
|
15
|
-
Tokens builder supports
|
|
16
|
-
|
|
15
|
+
Tokens builder supports [composite tokens](https://www.w3.org/community/reports/design-tokens/CG-FINAL-format-20251028/#composite-design-token) for the CSS platform.
|
|
16
|
+
Currently, the `typography` composite type is supported.
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Typography presets are authored as DTCG `typography` composites — one token whose `$value` is an object of sub-properties:
|
|
19
19
|
|
|
20
20
|
```json
|
|
21
21
|
{
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"type": "
|
|
25
|
-
"
|
|
22
|
+
"typography": {
|
|
23
|
+
"text-normal": {
|
|
24
|
+
"$type": "typography",
|
|
25
|
+
"$value": {
|
|
26
|
+
"fontSize": "16px",
|
|
27
|
+
"lineHeight": "24px",
|
|
28
|
+
"fontWeight": 400,
|
|
29
|
+
"fontFamily": "{font.family.mono}",
|
|
30
|
+
"letterSpacing": "normal"
|
|
31
|
+
}
|
|
26
32
|
}
|
|
27
33
|
}
|
|
28
34
|
}
|
|
29
35
|
```
|
|
30
36
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
"type": "font" property is **required.**
|
|
34
|
-
|
|
35
|
-
output:
|
|
37
|
+
Sub-properties are camelCase, as the [`typography` type](https://www.w3.org/community/reports/design-tokens/CG-FINAL-format-20251028/#typography) requires.
|
|
38
|
+
The `kbq/expand-typography` preprocessor expands each composite back into one token per sub-property before Style Dictionary resolves references:
|
|
36
39
|
|
|
37
40
|
```
|
|
38
|
-
--kbq
|
|
39
|
-
--kbq
|
|
40
|
-
--kbq
|
|
41
|
-
--kbq
|
|
41
|
+
--kbq-typography-text-normal-font-size: 16px;
|
|
42
|
+
--kbq-typography-text-normal-line-height: 24px;
|
|
43
|
+
--kbq-typography-text-normal-font-weight: 400;
|
|
44
|
+
--kbq-typography-text-normal-font-family: var(--kbq-font-family-mono);
|
|
42
45
|
// ...etc
|
|
43
46
|
```
|
|
47
|
+
|
|
48
|
+
A composite can also be aliased whole — `"$value": "{typography.text-normal}"` — which the preprocessor expands into one reference per sub-property.
|
package/build.js
CHANGED
|
@@ -26,6 +26,7 @@ import registerTsGroup from './transformGroups/ts.js';
|
|
|
26
26
|
import registerTypographyFormat from './formats/typography.js';
|
|
27
27
|
import registerVariablesFormat from './formats/variables.js';
|
|
28
28
|
import registerComponentFormat from './formats/component.js';
|
|
29
|
+
import registerPaletteFormat from './formats/palette.js';
|
|
29
30
|
|
|
30
31
|
// ==== Include custom actions ====
|
|
31
32
|
import registerCssIndex from './actions/css-index.js';
|
|
@@ -50,6 +51,7 @@ registerTsGroup(StyleDictionary);
|
|
|
50
51
|
registerTypographyFormat(StyleDictionary);
|
|
51
52
|
registerVariablesFormat(StyleDictionary);
|
|
52
53
|
registerComponentFormat(StyleDictionary);
|
|
54
|
+
registerPaletteFormat(StyleDictionary);
|
|
53
55
|
|
|
54
56
|
registerCssIndex(StyleDictionary);
|
|
55
57
|
|
package/configs/scss.js
CHANGED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One Sass variable per top-level `plt.*` family — a map of its steps for a numbered ramp
|
|
3
|
+
* (`$plt-blue: (1: oklch(…), 2: oklch(…), …)`), or a plain variable for a single-value family
|
|
4
|
+
* (`$plt-white: oklch(…)`). Mirrors the shape v3's `_palette.scss` had for the HSL palette, so
|
|
5
|
+
* code written against `@each $step, $color in $plt-blue` keeps working across the v4 upgrade —
|
|
6
|
+
* only the values (and the step range, 1–20 instead of 0–100) changed.
|
|
7
|
+
*/
|
|
8
|
+
const toKebab = (key) => key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
|
9
|
+
|
|
10
|
+
export default (StyleDictionary) => {
|
|
11
|
+
StyleDictionary.registerFormat({
|
|
12
|
+
name: 'kbq-scss/palette',
|
|
13
|
+
format: function ({ dictionary, options = {} }) {
|
|
14
|
+
const { usesDtcg } = options;
|
|
15
|
+
const valueKey = usesDtcg ? '$value' : 'value';
|
|
16
|
+
const families = dictionary.tokens.plt ?? {};
|
|
17
|
+
|
|
18
|
+
return Object.keys(families)
|
|
19
|
+
.map((family) => {
|
|
20
|
+
const node = families[family];
|
|
21
|
+
const name = `plt-${toKebab(family)}`;
|
|
22
|
+
|
|
23
|
+
if (Object.hasOwn(node, valueKey)) {
|
|
24
|
+
return `$${name}: ${node[valueKey]};\n`;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const steps = Object.keys(node)
|
|
28
|
+
.map((step) => ` ${step}: ${node[step][valueKey]},\n`)
|
|
29
|
+
.join('');
|
|
30
|
+
|
|
31
|
+
return `$${name}: (\n${steps});\n`;
|
|
32
|
+
})
|
|
33
|
+
.join('\n');
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
};
|
package/package.json
CHANGED