@koobiq/tokens-builder 3.20.1 → 4.0.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/index.js CHANGED
@@ -1,8 +1,7 @@
1
- const { join } = require('path');
2
- const scssConfig = require('./scss');
3
- const jsConfig = require('./js');
4
- const cssConfig = require('./css');
5
- const cssNewConfig = require('./css-new');
1
+ import { join } from 'node:path';
2
+ import scssConfig from './scss.js';
3
+ import jsConfig from './js.js';
4
+ import cssConfig from './css.js';
6
5
 
7
6
  const filterObj = {
8
7
  options: {
@@ -44,15 +43,29 @@ function getConfigs(theme) {
44
43
  scssConfig.scss.buildPath = theme.outputPath;
45
44
  jsConfig.js.buildPath = theme.outputPath;
46
45
  cssConfig.css.buildPath = theme.outputPath;
47
- // @TODO: remove when updated to v4 (#DS-3002)
48
- cssNewConfig.css.buildPath = theme.outputPath;
49
46
 
50
- return filterOptions([scssConfig, jsConfig, theme?.type === 'new' ? cssNewConfig : cssConfig]);
47
+ return filterOptions([scssConfig, jsConfig, cssConfig]);
51
48
  }
52
49
 
53
- module.exports = (theme) => {
50
+ export default (theme) => {
54
51
  return {
55
52
  source: [...getSources(theme)],
56
- platforms: getConfigs(theme)
53
+ platforms: getConfigs(theme),
54
+ // Typography presets are authored as DTCG `typography` composites, but every output
55
+ // here is flat (--kbq-typography-headline-font-size, $typography-headline-font-size),
56
+ // so they get expanded back into one token per sub-property. See the preprocessor for
57
+ // why this isn't Style Dictionary's built-in `expand` option.
58
+ // Shadows stay composite — `shadow/css/shorthand` renders them as one box-shadow.
59
+ preprocessors: ['kbq/expand-typography'],
60
+ // Fail the build on transform errors instead of printing them. Without this a transform
61
+ // that throws on a value (say a dimension transform meeting `letter-spacing: normal`)
62
+ // is caught by Style Dictionary, quietly falls back to the untransformed value and only
63
+ // logs — so the output would be silently wrong.
64
+ //
65
+ // This switch is read from two places: transform errors use the top-level `log`, while
66
+ // the per-file "filtered out token references" warning uses `platform.log`. The css
67
+ // platform overrides it to `disabled` (see configs/css.js) because those cross-file
68
+ // references are deliberate.
69
+ log: { warnings: 'error' }
57
70
  };
58
71
  };
package/configs/js.js CHANGED
@@ -1,18 +1,25 @@
1
- module.exports = {
1
+ import { hasValue } from '../filters/has-value.js';
2
+
3
+ export default {
2
4
  js: {
3
5
  transformGroup: 'kbq/ts',
6
+ // Tokens with a null value are deliberately unstyled; the TypeScript declaration
7
+ // format throws on them, and they would be noise in the other two.
4
8
  files: [
5
9
  {
6
10
  destination: 'js/index.mjs',
7
- format: 'javascript/es6'
11
+ format: 'javascript/es6',
12
+ filter: hasValue
8
13
  },
9
14
  {
10
15
  destination: 'js/index.js',
11
- format: 'javascript/module-flat'
16
+ format: 'javascript/module-flat',
17
+ filter: hasValue
12
18
  },
13
19
  {
14
20
  destination: 'js/index.d.ts',
15
- format: 'typescript/es6-declarations'
21
+ format: 'typescript/es6-declarations',
22
+ filter: hasValue
16
23
  }
17
24
  ]
18
25
  }
package/configs/scss.js CHANGED
@@ -1,16 +1,11 @@
1
- module.exports = {
1
+ export default {
2
2
  scss: {
3
3
  transformGroup: 'kbq/scss',
4
4
  files: [
5
5
  {
6
6
  destination: '_variables.scss',
7
7
  format: 'scss/variables',
8
- filter: 'color'
9
- },
10
- {
11
- destination: '_palette.scss',
12
- format: 'kbq-scss/palette',
13
- filter: 'palette'
8
+ filter: (token) => !token.attributes.typography && !token.attributes['md-typography']
14
9
  },
15
10
  {
16
11
  destination: '_typography.scss',
@@ -0,0 +1,24 @@
1
+ /**
2
+ * True unless the token's value is `null`.
3
+ *
4
+ * A null value is not a missing value — it says the name is part of the system's vocabulary but
5
+ * is deliberately unstyled. `koobiq/angular-components` says the same thing with `null` in
6
+ * code-block-tokens.scss, where Sass simply omits the declaration.
7
+ *
8
+ * Which platforms can carry that meaning differs, so the filter is applied per platform rather
9
+ * than globally:
10
+ *
11
+ * - **CSS** cannot express it. `--kbq-x: ;` parses, but a declared-empty property suppresses a
12
+ * consumer's `var(--kbq-x, fallback)` and then resolves to nothing — worse than not shipping
13
+ * the variable at all. Skipped.
14
+ * - **JS** has no use for it, and `typescript/es6-declarations` throws outright, calling
15
+ * `Object.entries()` on the null. Skipped.
16
+ * - **SCSS** keeps them: `null` is exactly what Sass means, and it drops the declaration itself.
17
+ */
18
+ export const hasValue = (token) => {
19
+ // Not `token.$value ?? token.value`: `??` treats null as absent and would fall through to
20
+ // the undefined non-DTCG key, so every null token would look like it had a value.
21
+ const value = '$value' in token ? token.$value : token.value;
22
+
23
+ return value !== null && value !== undefined;
24
+ };
@@ -1,6 +1,6 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerFilter({
3
3
  name: 'md-typography',
4
- matcher: (prop) => prop.attributes['md-typography']
4
+ filter: (token) => token.attributes['md-typography']
5
5
  });
6
6
  };
@@ -1,6 +1,6 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerFilter({
3
3
  name: 'typography',
4
- matcher: (prop) => prop.attributes.typography
4
+ filter: (token) => token.attributes.typography
5
5
  });
6
6
  };
@@ -0,0 +1,57 @@
1
+ import { fileHeader, formattedVariables } from 'style-dictionary/utils';
2
+ import { stripThemeFromNames } from './strip-theme.js';
3
+
4
+ /**
5
+ * The selector each slice of a component's tokens belongs under, in write order.
6
+ *
7
+ * `:root` holds whatever is theme-independent (scrollbar sizes, for instance); the other two
8
+ * hold the light and dark colours.
9
+ */
10
+ const THEMES = [
11
+ { selector: ':root', belongs: (token) => !token.attributes.light && !token.attributes.dark },
12
+ { selector: '.kbq-light', belongs: (token) => token.attributes.light },
13
+ { selector: '.kbq-dark', belongs: (token) => token.attributes.dark }
14
+ ];
15
+
16
+ /**
17
+ * One self-contained stylesheet per component.
18
+ *
19
+ * Unlike `kbq-css/variables`, which writes a single selector per file, this writes every selector
20
+ * a component needs into one file — so importing a component's tokens is one import rather than
21
+ * three. That matters because these files are opt-in: code-block alone accounts for 214 of the
22
+ * 248 component variables, and a consumer who does not render code blocks should not have to
23
+ * carry them.
24
+ *
25
+ * Selectors with nothing in them are skipped, so a component that has no theme-independent
26
+ * tokens does not ship an empty `:root {}`.
27
+ */
28
+ export default (StyleDictionary) => {
29
+ StyleDictionary.registerFormat({
30
+ name: 'kbq-css/component',
31
+ format: async function ({ dictionary, options = {}, file }) {
32
+ const { outputReferences, usesDtcg } = options;
33
+
34
+ stripThemeFromNames(dictionary.allTokens);
35
+
36
+ const blocks = THEMES.map(({ selector, belongs }) => {
37
+ const allTokens = dictionary.allTokens.filter(belongs);
38
+
39
+ if (allTokens.length === 0) return null;
40
+
41
+ // References are resolved against the full dictionary, so a component token
42
+ // pointing at `{semantic.*}` still emits a var() even though that token is not
43
+ // part of this file.
44
+ const body = formattedVariables({
45
+ format: 'css',
46
+ dictionary: { ...dictionary, allTokens },
47
+ outputReferences,
48
+ usesDtcg
49
+ });
50
+
51
+ return `${selector} {\n${body}\n}\n`;
52
+ }).filter(Boolean);
53
+
54
+ return (await fileHeader({ file })) + blocks.join('\n');
55
+ }
56
+ });
57
+ };
@@ -0,0 +1,28 @@
1
+ const renamed = new WeakSet();
2
+
3
+ /**
4
+ * Drops the theme segment from a token's variable name.
5
+ *
6
+ * Theme-scoped tokens are written under a `.kbq-light` / `.kbq-dark` selector, so repeating the
7
+ * theme in the name would be redundant: `shadow.light.card` becomes `--kbq-shadow-card`. The
8
+ * palette layers are global and keep their names untouched.
9
+ *
10
+ * Token objects are shared between the files of one platform — a light colour is written to both
11
+ * `css/light/semantic-colors.css` and `css-tokens-light.css`, and a component colour to both
12
+ * `css/components/code-block.css` and `component-tokens-light.css` — while formats run once per
13
+ * file. The rename therefore has to be idempotent, or a second pass would eat another `light-`
14
+ * further along the name.
15
+ *
16
+ * The theme has to be a whole name segment. Matching `light-` anywhere in the string also finds it
17
+ * inside a word: `states.background.highlight-current` became
18
+ * `--kbq-states-background-highcurrent`, which is what v3 shipped.
19
+ */
20
+ export const stripThemeFromNames = (tokens) => {
21
+ for (const token of tokens) {
22
+ if (['plt', 'semantic'].includes(token.attributes.category)) continue;
23
+ if (renamed.has(token)) continue;
24
+
25
+ renamed.add(token);
26
+ token.name = token.name.replace(/(^|-)(?:light|dark)-/, '$1');
27
+ }
28
+ };
@@ -1,34 +1,12 @@
1
- module.exports = (StyleDictionary) => {
2
- StyleDictionary.registerFormat({
3
- name: 'kbq-scss/typography',
4
- formatter: function (dictionary) {
5
- let string;
6
-
7
- string = dictionary.allProperties
8
- .map((prop) => {
9
- let output = '';
10
-
11
- const value = prop.attributes.category === 'asset' ? `"${prop.value}"` : prop.value;
12
-
13
- output += `$${prop.name}: ${value};`;
14
-
15
- if (prop.comment) {
16
- output += ` // ${prop.comment}`;
17
- }
18
-
19
- return output + '\n';
20
- })
21
- .join('');
22
-
23
- return string + `\n$${this.mapName || 'tokens'}: ${processJsonNode(dictionary.properties, 0)};\n`;
24
- }
25
- });
26
- };
1
+ // Composite sub-properties are camelCase per the DTCG spec (fontSize, lineHeight …), but the
2
+ // Sass map is a public API that has always been kebab-case — and matches the CSS variables.
3
+ const toKebab = (key) => key.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
27
4
 
28
- function processJsonNode(obj, depth) {
5
+ function processJsonNode(obj, depth, usesDtcg) {
29
6
  let output = '';
7
+ const valueKey = usesDtcg ? '$value' : 'value';
30
8
 
31
- if (obj.hasOwnProperty('value')) {
9
+ if (Object.hasOwn(obj, valueKey)) {
32
10
  output += `$${obj.name}`;
33
11
  } else {
34
12
  output += '(\n';
@@ -37,7 +15,7 @@ function processJsonNode(obj, depth) {
37
15
  const newProp = obj[newKey];
38
16
  const indent = ' '.repeat(depth + 1);
39
17
 
40
- return `${indent}'${newKey}': ${processJsonNode(newProp, depth + 1)}`;
18
+ return `${indent}'${toKebab(newKey)}': ${processJsonNode(newProp, depth + 1, usesDtcg)}`;
41
19
  })
42
20
  .join(',\n');
43
21
 
@@ -46,3 +24,24 @@ function processJsonNode(obj, depth) {
46
24
 
47
25
  return output;
48
26
  }
27
+
28
+ export default (StyleDictionary) => {
29
+ StyleDictionary.registerFormat({
30
+ name: 'kbq-scss/typography',
31
+ format: function ({ dictionary, file, options = {} }) {
32
+ const { usesDtcg } = options;
33
+
34
+ const string = dictionary.allTokens
35
+ .map((token) => {
36
+ const raw = usesDtcg ? token.$value : token.value;
37
+ const value = token.attributes.category === 'asset' ? `"${raw}"` : raw;
38
+ const comment = usesDtcg ? (token.$description ?? token.comment) : token.comment;
39
+
40
+ return `$${token.name}: ${value};${comment ? ` // ${comment}` : ''}\n`;
41
+ })
42
+ .join('');
43
+
44
+ return string + `\n$${file.mapName || 'tokens'}: ${processJsonNode(dictionary.tokens, 0, usesDtcg)};\n`;
45
+ }
46
+ });
47
+ };
@@ -1,56 +1,18 @@
1
- const { formatHelpers } = require('style-dictionary');
2
- const { unwrapObjectTransformer } = require('../formats/utils');
1
+ import { fileHeader, formattedVariables } from 'style-dictionary/utils';
2
+ import { stripThemeFromNames } from './strip-theme.js';
3
3
 
4
- module.exports = (StyleDictionary) => {
4
+ export default (StyleDictionary) => {
5
5
  StyleDictionary.registerFormat({
6
6
  name: 'kbq-css/variables',
7
- formatter: function ({ dictionary, options = {}, file }) {
8
- const { outputReferences, selector = ':root' } = options;
7
+ format: async function ({ dictionary, options = {}, file }) {
8
+ const { outputReferences, selector = ':root', usesDtcg } = options;
9
9
 
10
- // apply custom transformations for tokens
11
- dictionary.allProperties = dictionary.allTokens = dictionary.allTokens.flatMap((token) => {
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
- if (['plt', 'semantic'].includes(token.attributes.category)) return;
20
- token.name = token.name.replace(/(light|dark)-/, '');
21
- });
22
-
23
- return (
24
- formatHelpers.fileHeader({ file }) +
25
- `${selector} {\n` +
26
- formatHelpers.formattedVariables({ format: 'css', dictionary, outputReferences }) +
27
- `\n}\n`
28
- );
29
- }
30
- });
31
-
32
- StyleDictionary.registerFormat({
33
- name: 'kbq-css/palette',
34
- formatter: function ({ dictionary, options = {}, file }) {
35
- const { outputReferences, selector = ':root' } = options;
36
-
37
- dictionary.allProperties = dictionary.allTokens = dictionary.allTokens.flatMap((token) => {
38
- if (typeof token.value === 'object') {
39
- return unwrapObjectTransformer(token);
40
- }
41
- return token;
42
- });
43
-
44
- dictionary.allTokens.forEach((token) => {
45
- if (['plt', 'semantic'].includes(token.attributes.category)) return;
46
- token.name = token.name.replace(/(light|dark)-/, '');
47
- token.name = token.name.replace(/"/g, '');
48
- });
10
+ stripThemeFromNames(dictionary.allTokens);
49
11
 
50
12
  return (
51
- formatHelpers.fileHeader({ file }) +
13
+ (await fileHeader({ file })) +
52
14
  `${selector} {\n` +
53
- formatHelpers.formattedVariables({ format: 'css', dictionary, outputReferences }) +
15
+ formattedVariables({ format: 'css', dictionary, outputReferences, usesDtcg }) +
54
16
  `\n}\n`
55
17
  );
56
18
  }
package/package.json CHANGED
@@ -3,11 +3,18 @@
3
3
  "description": "Design tokens",
4
4
  "author": "",
5
5
  "license": "MIT",
6
+ "type": "module",
6
7
  "keywords": [
7
8
  "tokens",
8
9
  "design",
9
10
  "system"
10
11
  ],
12
+ "engines": {
13
+ "node": ">=22.0.0"
14
+ },
15
+ "peerDependencies": {
16
+ "style-dictionary": "^5.0.0"
17
+ },
11
18
  "publishConfig": {
12
19
  "access": "public"
13
20
  },
@@ -19,5 +26,5 @@
19
26
  "default": "./*"
20
27
  }
21
28
  },
22
- "version": "3.20.1"
29
+ "version": "4.0.1"
23
30
  }
@@ -0,0 +1,114 @@
1
+ // DTCG sub-property → DTCG type, mirroring Style Dictionary's own DTCGTypesMap.typography.
2
+ // Anything not listed keeps its own name as the type (fontFamily, fontWeight are real DTCG
3
+ // types; textTransform / fontFeatureSettings are our documented extension).
4
+ const SUBTYPES = {
5
+ fontSize: 'dimension',
6
+ letterSpacing: 'dimension',
7
+ lineHeight: 'number'
8
+ };
9
+
10
+ /** A `$value` that is nothing but a reference, e.g. `{typography.title}`. */
11
+ const ALIAS = /^\{([^{}]+)\}$/;
12
+
13
+ const isPlainObject = (value) => value !== null && typeof value === 'object' && !Array.isArray(value);
14
+
15
+ /** A node is a token once it carries a `$value`; anything else is a group. */
16
+ const isToken = (node) => isPlainObject(node) && '$value' in node;
17
+
18
+ const aliasTarget = (node) => (typeof node.$value === 'string' ? ALIAS.exec(node.$value)?.[1] : undefined);
19
+
20
+ const at = (root, path) => path.split('.').reduce((node, key) => (isPlainObject(node) ? node[key] : undefined), root);
21
+
22
+ /**
23
+ * Sub-property names of the composite `path` points at, following alias hops.
24
+ *
25
+ * Only the *names* come from the end of the chain — the references we emit stay pointed at the
26
+ * direct target, so an A → B → C alias chain survives into the CSS as one `var()` per hop.
27
+ */
28
+ const subProperties = (root, path) => {
29
+ const seen = new Set();
30
+
31
+ for (let target = path; target && !seen.has(target);) {
32
+ seen.add(target);
33
+
34
+ const node = at(root, target);
35
+
36
+ if (!isToken(node)) return undefined;
37
+ if (isPlainObject(node.$value)) return Object.keys(node.$value);
38
+
39
+ target = aliasTarget(node);
40
+ }
41
+
42
+ return undefined;
43
+ };
44
+
45
+ /**
46
+ * Expands `typography` composites into a group of one token per sub-property.
47
+ *
48
+ * Style Dictionary's built-in `expand` option does the same thing, but it first runs a
49
+ * trial `resolveMap()` over the *unexpanded* tree. At that point `{typography.title.fontSize}`
50
+ * does not exist yet — md-typography references a preset's individual sub-properties — so
51
+ * every such reference is recorded as a broken-reference warning in a module-level message
52
+ * store, and the first platform to export then throws on the accumulated count. The
53
+ * references themselves resolve perfectly well once expansion has happened; only the
54
+ * bookkeeping is wrong.
55
+ *
56
+ * Doing the expansion in a preprocessor sidesteps that: by the time Style Dictionary looks
57
+ * at references, the sub-property tokens are already real tokens.
58
+ *
59
+ * A composite may also be aliased whole — `$value: '{typography.display-compact}'` — which is
60
+ * what the spec means by a composite being a single token. Those expand into one reference per
61
+ * sub-property of the target, so `md-h1` says "it is display-compact" once instead of repeating
62
+ * the same preset name seven times. The expansion is mechanical, so the emitted CSS is identical
63
+ * to spelling every sub-property out by hand.
64
+ *
65
+ * Sub-properties stay camelCase (as the spec requires). `name/custom-kebab` turns them back
66
+ * into `font-size` etc., so CSS variable names are unchanged.
67
+ */
68
+ export default (StyleDictionary) => {
69
+ StyleDictionary.registerPreprocessor({
70
+ name: 'kbq/expand-typography',
71
+ preprocessor: (tokens) => {
72
+ const expand = (node, entries) => {
73
+ // $type is dropped here: each sub-property gets its own type below.
74
+ const { $value: _value, $type: _type, ...meta } = node;
75
+
76
+ return Object.fromEntries(
77
+ entries.map(([prop, value]) => [prop, { ...meta, $value: value, $type: SUBTYPES[prop] ?? prop }])
78
+ );
79
+ };
80
+
81
+ // `inherited` carries the nearest ancestor group's $type, which DTCG lets a token
82
+ // omit. Style Dictionary applies that inheritance itself, but only after
83
+ // preprocessors have run, so it has to be tracked here too.
84
+ const walk = (node, inherited) => {
85
+ if (!isPlainObject(node)) return node;
86
+
87
+ const type = node.$type ?? inherited;
88
+
89
+ if (type === 'typography' && isToken(node)) {
90
+ if (isPlainObject(node.$value)) return expand(node, Object.entries(node.$value));
91
+
92
+ const target = aliasTarget(node);
93
+ const props = target && subProperties(tokens, target);
94
+
95
+ if (!props) {
96
+ throw new Error(
97
+ `Typography token has $value "${node.$value}", which is neither an object ` +
98
+ `nor a reference to another typography composite.`
99
+ );
100
+ }
101
+
102
+ return expand(
103
+ node,
104
+ props.map((prop) => [prop, `{${target}.${prop}}`])
105
+ );
106
+ }
107
+
108
+ return Object.fromEntries(Object.entries(node).map(([key, value]) => [key, walk(value, type)]));
109
+ };
110
+
111
+ return walk(tokens, undefined);
112
+ }
113
+ });
114
+ };
@@ -1,30 +1,18 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerTransformGroup({
3
3
  name: 'kbq/css',
4
+ // No `color/css` here on purpose. Its v4+ filter is `$type === 'color'` plus "tinycolor2
5
+ // can parse this value", so now that the sources carry DTCG types it starts firing. The
6
+ // OKLch palette is safe (tinycolor2 does not parse `oklch()`), but `transparent` and
7
+ // `#00000000` do parse, and it rewrites all 24 of them to `rgba(0, 0, 0, 0)`. Our values
8
+ // are already valid CSS, so there is nothing to gain from the churn.
4
9
  transforms: [
5
10
  'attribute/cti',
6
- 'kbq-attribute/palette',
7
11
  'kbq-attribute/font',
8
12
  'kbq-attribute/light',
9
13
  'kbq-attribute/dark',
14
+ 'shadow/css/shorthand',
10
15
  'name/custom-kebab',
11
- 'color/css',
12
- 'kbq/prefix',
13
- 'kbq-attribute/comment'
14
- ]
15
- });
16
-
17
- StyleDictionary.registerTransformGroup({
18
- name: 'kbq/css-new',
19
- transforms: [
20
- 'attribute/cti',
21
- 'kbq-attribute/palette',
22
- 'kbq-attribute/font',
23
- 'kbq-attribute/light',
24
- 'kbq-attribute/dark',
25
- 'name/custom-kebab-strip-theme',
26
- 'color/css',
27
- 'kbq/prefix',
28
16
  'kbq-attribute/comment'
29
17
  ]
30
18
  });
@@ -1,12 +1,12 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerTransformGroup({
3
3
  name: 'kbq/scss',
4
4
  transforms: [
5
5
  'attribute/cti',
6
- 'kbq-attribute/palette',
7
6
  'kbq-attribute/typography',
8
7
  'kbq-attribute/md-typography',
9
- 'name/cti/kebab',
8
+ 'name/kebab',
9
+ 'shadow/css/shorthand',
10
10
  'kbq-scss/value',
11
11
  'kbq-attribute/comment'
12
12
  ]
@@ -1,13 +1,13 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerTransformGroup({
3
3
  name: 'kbq/ts',
4
- transforms: [
5
- 'attribute/cti',
6
- 'name/cti/pascal',
7
- 'kbq-attribute/palette',
8
- 'size/px',
9
- 'color/hex',
10
- 'kbq-attribute/comment'
11
- ]
4
+ // `color/hex` and `size/px` are deliberately absent. Both used to match on
5
+ // `attributes.category` and never fired here; in v4+ they match on `$type`:
6
+ // - `size/px` now matches every `dimension`, including `letter-spacing: normal`,
7
+ // where parseFloat gives NaN. That is 25 hard transform errors.
8
+ // - `color/hex` leaves OKLch alone (tinycolor2 cannot parse it) but rewrites
9
+ // `transparent` / `#00000000`.
10
+ // Values already carry their units and are valid CSS as authored.
11
+ transforms: ['attribute/cti', 'name/pascal', 'shadow/css/shorthand', 'kbq-attribute/comment']
12
12
  });
13
13
  };
@@ -1,12 +1,21 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerTransform({
3
3
  name: 'kbq-attribute/comment',
4
4
  type: 'attribute',
5
- transformer: (token) => {
6
- if (!token.deprecated) return;
5
+ transform: (token, _platform, options) => {
6
+ const deprecated = token.$deprecated ?? token.deprecated;
7
7
 
8
- const notice = `DEPRECATED: ${token.deprecated}`;
9
- token.comment = token.comment ? `${notice} | ${token.comment}` : notice;
8
+ if (!deprecated) return;
9
+
10
+ const notice = `DEPRECATED: ${deprecated}`;
11
+
12
+ // v5 renders `token.$description ?? token.comment` as the declaration comment, so in
13
+ // DTCG mode the notice has to land on $description or it would be shadowed.
14
+ if (options?.usesDtcg) {
15
+ token.$description = token.$description ? `${notice} | ${token.$description}` : notice;
16
+ } else {
17
+ token.comment = token.comment ? `${notice} | ${token.comment}` : notice;
18
+ }
10
19
  }
11
20
  });
12
21
  };
@@ -1,10 +1,10 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerTransform({
3
3
  name: 'kbq-attribute/font',
4
4
  type: 'attribute',
5
- matcher: ({ attributes }) => {
5
+ filter: ({ attributes }) => {
6
6
  return (attributes.category === 'markdown' && attributes.item === 'font') || attributes.type === 'font';
7
7
  },
8
- transformer: () => ({ font: true })
8
+ transform: () => ({ font: true })
9
9
  });
10
10
  };
@@ -1,8 +1,8 @@
1
- module.exports = (StyleDictionary) => {
1
+ export default (StyleDictionary) => {
2
2
  StyleDictionary.registerTransform({
3
3
  name: 'kbq-attribute/md-typography',
4
4
  type: 'attribute',
5
- matcher: (prop) => prop.attributes.category === 'md-typography',
6
- transformer: () => ({ 'md-typography': true })
5
+ filter: (token) => token.attributes.category === 'md-typography',
6
+ transform: () => ({ 'md-typography': true })
7
7
  });
8
8
  };