@koobiq/tokens-builder 4.0.0 → 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 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 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.
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
- ### Example of usage
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
- "<component-name>": {
23
- "font": {
24
- "type": "font",
25
- "<token-with-composite-token-reference>": "{typography.<typography-set>}"
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
- where `<typography-set>` is a set from `@koobiq/design-tokens/web/properties/typography.json5`
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-<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>;
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
@@ -18,6 +18,11 @@ export default {
18
18
  format: 'kbq-scss/typography',
19
19
  mapName: 'md-typography',
20
20
  filter: 'md-typography'
21
+ },
22
+ {
23
+ destination: '_palette.scss',
24
+ format: 'kbq-scss/palette',
25
+ filter: (token) => token.path[0] === 'plt'
21
26
  }
22
27
  ]
23
28
  }
@@ -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
@@ -26,5 +26,5 @@
26
26
  "default": "./*"
27
27
  }
28
28
  },
29
- "version": "4.0.0"
29
+ "version": "4.1.0"
30
30
  }