style-dictionary 4.3.2 → 4.4.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 +1 -1
- package/examples/advanced/assets-base64-embed/package.json +1 -1
- package/examples/advanced/assets-base64-embed/tokens/color/font.json +3 -3
- package/examples/advanced/assets-base64-embed/tokens/size/font.json +1 -1
- package/examples/advanced/create-react-app/package.json +1 -1
- package/examples/advanced/create-react-app/style-dictionary/tokens/font.json +1 -1
- package/examples/advanced/create-react-native-app/package.json +1 -1
- package/examples/advanced/custom-parser/package.json +1 -1
- package/examples/advanced/custom-transforms/package.json +1 -1
- package/examples/advanced/flutter/style_dictionary/tokens/color/font.json +3 -3
- package/examples/advanced/font-face-rules/package.json +1 -1
- package/examples/advanced/format-helpers/package.json +1 -1
- package/examples/advanced/format-helpers/tokens/color.json +1 -1
- package/examples/advanced/matching-build-files/package.json +1 -1
- package/examples/advanced/matching-build-files/tokens/button/base.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/README.md +3 -3
- package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/tokens/globals/button.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/tokens/globals/color/base.json +5 -5
- package/examples/advanced/multi-brand-multi-platform/tokens/globals/color/font.json +4 -4
- package/examples/advanced/multi-brand-multi-platform/tokens/globals/font/index.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/tokens/globals/size/font.json +4 -4
- package/examples/advanced/node-modules-as-config-and-properties/components/button/base.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/components/button/primary.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/components/button/secondary.js +5 -5
- package/examples/advanced/node-modules-as-config-and-properties/components/index.js +1 -1
- package/examples/advanced/node-modules-as-config-and-properties/config.js +3 -3
- package/examples/advanced/node-modules-as-config-and-properties/package-lock.json +2201 -0
- package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/background.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/border.js +1 -1
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/brand.js +10 -10
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/font.js +3 -3
- package/examples/advanced/node-modules-as-config-and-properties/tokens/color/index.js +5 -5
- package/examples/advanced/node-modules-as-config-and-properties/tokens/index.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/tokens/size/font.js +2 -2
- package/examples/advanced/node-modules-as-config-and-properties/tokens/size/index.js +7 -3
- package/examples/advanced/node-modules-as-config-and-properties/tokens/size/padding.js +2 -2
- package/examples/advanced/npm-module/package.json +1 -1
- package/examples/advanced/npm-module/tokens/color/font.json +3 -3
- package/examples/advanced/npm-module/tokens/size/font.json +1 -1
- package/examples/advanced/referencing_aliasing/README.md +6 -6
- package/examples/advanced/referencing_aliasing/package.json +1 -1
- package/examples/advanced/referencing_aliasing/tokens/button/button.json +3 -3
- package/examples/advanced/referencing_aliasing/tokens/color/base.json +2 -2
- package/examples/advanced/referencing_aliasing/tokens/color/font.json +3 -3
- package/examples/advanced/referencing_aliasing/tokens/size/font.json +1 -1
- package/examples/advanced/s3/package.json +1 -1
- package/examples/advanced/s3/tokens/color/font.json +3 -3
- package/examples/advanced/s3/tokens/size/font.json +1 -1
- package/examples/advanced/tailwind-preset/package.json +1 -1
- package/examples/advanced/tokens-deprecation/package.json +1 -1
- package/examples/advanced/tokens-deprecation/tokens/color/font.json +3 -3
- package/examples/advanced/tokens-deprecation/tokens/size/font.json +4 -4
- package/examples/advanced/transitive-transforms/package.json +1 -1
- package/examples/advanced/variables-in-outputs/package.json +1 -1
- package/examples/advanced/variables-in-outputs/tokens/color/background.json +4 -4
- package/examples/advanced/yaml-tokens/package.json +1 -1
- package/examples/advanced/yaml-tokens/tokens/color/core.yaml +7 -7
- package/examples/complete/tokens/color/background.json +16 -16
- package/examples/complete/tokens/color/border.json +10 -10
- package/examples/complete/tokens/color/brand.json +10 -10
- package/examples/complete/tokens/color/chart.json +9 -9
- package/examples/complete/tokens/color/font.json +22 -22
- package/examples/complete/tokens/font.json +2 -2
- package/examples/complete/tokens/size/font.json +1 -1
- package/examples/complete/tokens/size/padding.json +1 -1
- package/lib/StyleDictionary.js +2 -2
- package/lib/common/formatHelpers/createPropertyFormatter.d.ts +1 -1
- package/lib/common/formatHelpers/createPropertyFormatter.js +4 -4
- package/lib/common/formats.js +84 -25
- package/lib/common/transforms.d.ts +3 -3
- package/lib/common/transforms.js +17 -6
- package/lib/enums/transforms.d.ts +1 -1
- package/lib/enums/transforms.js +4 -1
- package/lib/utils/convertToDTCG.js +10 -12
- package/lib/utils/preprocess.js +3 -2
- package/package.json +7 -8
|
@@ -1,33 +1,33 @@
|
|
|
1
1
|
{
|
|
2
2
|
"color": {
|
|
3
3
|
"font": {
|
|
4
|
-
"base": { "value": "{color.base.grey.900
|
|
5
|
-
"secondary": { "value": "{color.base.grey.800
|
|
6
|
-
"tertiary": { "value": "{color.base.grey.600
|
|
7
|
-
"quaternary": { "value": "{color.base.grey.400
|
|
8
|
-
"link": { "value": "{color.brand.primary.base
|
|
9
|
-
"active": { "value": "{color.brand.secondary.base
|
|
10
|
-
"error": { "value": "{color.base.red.600
|
|
11
|
-
"warning": { "value": "{color.base.orange.800
|
|
12
|
-
"success": { "value": "{color.base.green.600
|
|
13
|
-
"disabled": { "value": "{color.font.secondary
|
|
4
|
+
"base": { "value": "{color.base.grey.900}", "type": "color" },
|
|
5
|
+
"secondary": { "value": "{color.base.grey.800}", "type": "color" },
|
|
6
|
+
"tertiary": { "value": "{color.base.grey.600}", "type": "color" },
|
|
7
|
+
"quaternary": { "value": "{color.base.grey.400}", "type": "color" },
|
|
8
|
+
"link": { "value": "{color.brand.primary.base}", "type": "color" },
|
|
9
|
+
"active": { "value": "{color.brand.secondary.base}", "type": "color" },
|
|
10
|
+
"error": { "value": "{color.base.red.600}", "type": "color" },
|
|
11
|
+
"warning": { "value": "{color.base.orange.800}", "type": "color" },
|
|
12
|
+
"success": { "value": "{color.base.green.600}", "type": "color" },
|
|
13
|
+
"disabled": { "value": "{color.font.secondary}", "type": "color" },
|
|
14
14
|
|
|
15
15
|
"inverse": {
|
|
16
|
-
"base": { "value": "{color.base.white
|
|
17
|
-
"secondary": { "value": "{color.base.grey.100
|
|
18
|
-
"tertiary": { "value": "{color.base.grey.200
|
|
19
|
-
"quaternary": { "value": "{color.base.grey.400
|
|
20
|
-
"link": { "value": "{color.brand.primary.light
|
|
21
|
-
"active": { "value": "{color.brand.secondary.light
|
|
22
|
-
"error": { "value": "{color.base.red.400
|
|
23
|
-
"warning": { "value": "{color.base.orange.400
|
|
24
|
-
"success": { "value": "{color.base.green.400
|
|
25
|
-
"disabled": { "value": "{color.font.inverse.secondary
|
|
16
|
+
"base": { "value": "{color.base.white}", "type": "color" },
|
|
17
|
+
"secondary": { "value": "{color.base.grey.100}", "type": "color" },
|
|
18
|
+
"tertiary": { "value": "{color.base.grey.200}", "type": "color" },
|
|
19
|
+
"quaternary": { "value": "{color.base.grey.400}", "type": "color" },
|
|
20
|
+
"link": { "value": "{color.brand.primary.light}", "type": "color" },
|
|
21
|
+
"active": { "value": "{color.brand.secondary.light}", "type": "color" },
|
|
22
|
+
"error": { "value": "{color.base.red.400}", "type": "color" },
|
|
23
|
+
"warning": { "value": "{color.base.orange.400}", "type": "color" },
|
|
24
|
+
"success": { "value": "{color.base.green.400}", "type": "color" },
|
|
25
|
+
"disabled": { "value": "{color.font.inverse.secondary}", "type": "color" }
|
|
26
26
|
},
|
|
27
27
|
|
|
28
28
|
"button": {
|
|
29
|
-
"primary": { "value": "{color.font.inverse.base
|
|
30
|
-
"secondary": { "value": "{color.font.link
|
|
29
|
+
"primary": { "value": "{color.font.inverse.base}", "type": "color" },
|
|
30
|
+
"secondary": { "value": "{color.font.link}", "type": "color" }
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
}
|
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
"font": {
|
|
3
3
|
"family": {
|
|
4
4
|
"base": {
|
|
5
|
-
"value": "{asset.font.opensans.name
|
|
5
|
+
"value": "{asset.font.opensans.name}",
|
|
6
6
|
"type": "fontFamily"
|
|
7
7
|
},
|
|
8
8
|
"icons": {
|
|
9
|
-
"value": "{asset.font.icon.name
|
|
9
|
+
"value": "{asset.font.icon.name}",
|
|
10
10
|
"type": "fontFamily"
|
|
11
11
|
}
|
|
12
12
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"xl": { "value": "1.5", "type": "fontSize" },
|
|
9
9
|
"xxl": { "value": "2", "type": "fontSize" },
|
|
10
10
|
"xxxl": { "value": "3", "type": "fontSize" },
|
|
11
|
-
"base": { "value": "{size.font.medium
|
|
11
|
+
"base": { "value": "{size.font.medium}", "type": "fontSize" }
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
}
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
"large": { "value": "1.5", "type": "dimension" },
|
|
8
8
|
"xl": { "value": "2", "type": "dimension" },
|
|
9
9
|
"xxl": { "value": "3", "type": "dimension" },
|
|
10
|
-
"base": { "value": "{size.padding.medium
|
|
10
|
+
"base": { "value": "{size.padding.medium}", "type": "dimension" }
|
|
11
11
|
}
|
|
12
12
|
}
|
|
13
13
|
}
|
package/lib/StyleDictionary.js
CHANGED
|
@@ -80,7 +80,7 @@ export default class StyleDictionary extends Register {
|
|
|
80
80
|
// Placeholder is transformed on prepublish -> see scripts/inject-version.js
|
|
81
81
|
// Another option might be import pkg from './package.json' with { "type": "json" } which would work in both browser and node, but support is not there yet.
|
|
82
82
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
|
|
83
|
-
static VERSION = '4.
|
|
83
|
+
static VERSION = '4.4.0';
|
|
84
84
|
|
|
85
85
|
/** @returns {Config} */
|
|
86
86
|
get options() {
|
|
@@ -492,7 +492,7 @@ export default class StyleDictionary extends Register {
|
|
|
492
492
|
// }
|
|
493
493
|
//
|
|
494
494
|
// color.background.button.primary.base = {
|
|
495
|
-
// value: "{color.brand
|
|
495
|
+
// value: "{color.brand}",
|
|
496
496
|
// color: {
|
|
497
497
|
// desaturate: 0.5
|
|
498
498
|
// }
|
|
@@ -36,7 +36,7 @@ export function addComment(to_ret_token: string, comment: string, options: Forma
|
|
|
36
36
|
* @param {boolean} [options.outputReferenceFallbacks] - Whether or not to output css variable fallback values when using output references. You will want to pass this from the `options` object sent to the format function.
|
|
37
37
|
* @param {Dictionary} options.dictionary - The dictionary object sent to the format function
|
|
38
38
|
* @param {string} [options.format] - Available formats are: 'css', 'sass', 'less', and 'stylus'. If you want to customize the format and can't use one of those predefined formats, use the `formatting` option
|
|
39
|
-
* @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: `prefix`, `indentation`, `separator`, `suffix`, `lineSeparator`, `fileHeaderTimestamp`, `header`, `footer`, `commentStyle` and `commentPosition`. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${
|
|
39
|
+
* @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: `prefix`, `indentation`, `separator`, `suffix`, `lineSeparator`, `fileHeaderTimestamp`, `header`, `footer`, `commentStyle` and `commentPosition`. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${token.value}${suffix}`. The remaining formatting options are used for the fileHeader helper.
|
|
40
40
|
* @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
|
|
41
41
|
* @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
|
|
42
42
|
* @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
|
|
@@ -76,7 +76,7 @@ export function addComment(to_ret_token, comment, options) {
|
|
|
76
76
|
);
|
|
77
77
|
processedComment += `${indentation} */`;
|
|
78
78
|
} else {
|
|
79
|
-
processedComment = `${commentPosition === above ? indentation : ''}
|
|
79
|
+
processedComment = `${commentPosition === above ? indentation : ''}/** ${comment} */`;
|
|
80
80
|
}
|
|
81
81
|
break;
|
|
82
82
|
}
|
|
@@ -120,7 +120,7 @@ export function addComment(to_ret_token, comment, options) {
|
|
|
120
120
|
* @param {boolean} [options.outputReferenceFallbacks] - Whether or not to output css variable fallback values when using output references. You will want to pass this from the `options` object sent to the format function.
|
|
121
121
|
* @param {Dictionary} options.dictionary - The dictionary object sent to the format function
|
|
122
122
|
* @param {string} [options.format] - Available formats are: 'css', 'sass', 'less', and 'stylus'. If you want to customize the format and can't use one of those predefined formats, use the `formatting` option
|
|
123
|
-
* @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: `prefix`, `indentation`, `separator`, `suffix`, `lineSeparator`, `fileHeaderTimestamp`, `header`, `footer`, `commentStyle` and `commentPosition`. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${
|
|
123
|
+
* @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: `prefix`, `indentation`, `separator`, `suffix`, `lineSeparator`, `fileHeaderTimestamp`, `header`, `footer`, `commentStyle` and `commentPosition`. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${token.value}${suffix}`. The remaining formatting options are used for the fileHeader helper.
|
|
124
124
|
* @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
|
|
125
125
|
* @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
|
|
126
126
|
* @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
|
|
@@ -180,10 +180,10 @@ export default function createPropertyFormatter({
|
|
|
180
180
|
: outputReferences);
|
|
181
181
|
/**
|
|
182
182
|
* A single value can have multiple references either by interpolation:
|
|
183
|
-
* "value": "{size.border.width
|
|
183
|
+
* "value": "{size.border.width} solid {color.border.primary}"
|
|
184
184
|
* or if the value is an object:
|
|
185
185
|
* "value": {
|
|
186
|
-
* "size": "{size.border.width
|
|
186
|
+
* "size": "{size.border.width}",
|
|
187
187
|
* "style": "solid",
|
|
188
188
|
* "color": "{color.border.primary.value"}
|
|
189
189
|
* }
|
package/lib/common/formats.js
CHANGED
|
@@ -53,11 +53,13 @@ import scssMapFlatTemplate from './templates/scss/map-flat.template.js';
|
|
|
53
53
|
import macrosTemplate from './templates/ios/macros.template.js';
|
|
54
54
|
import plistTemplate from './templates/ios/plist.template.js';
|
|
55
55
|
import {
|
|
56
|
+
commentPositions,
|
|
56
57
|
commentStyles,
|
|
57
58
|
fileHeaderCommentStyles,
|
|
58
59
|
formats as fileFormats,
|
|
59
60
|
propertyFormatNames,
|
|
60
61
|
} from '../enums/index.js';
|
|
62
|
+
import { addComment } from './formatHelpers/createPropertyFormatter.js';
|
|
61
63
|
|
|
62
64
|
/**
|
|
63
65
|
* @typedef {import('../../types/Format.d.ts').Format} Format
|
|
@@ -71,6 +73,7 @@ import {
|
|
|
71
73
|
* @typedef {import('../utils/stripMeta.js').StripMetaOptions} StripMetaOptions
|
|
72
74
|
*/
|
|
73
75
|
|
|
76
|
+
const { above } = commentPositions;
|
|
74
77
|
const { none } = commentStyles;
|
|
75
78
|
const { long, short, xml } = fileHeaderCommentStyles;
|
|
76
79
|
const { css, sass, less, stylus } = propertyFormatNames;
|
|
@@ -158,7 +161,11 @@ function stripMetaProps(tokens, options) {
|
|
|
158
161
|
async function formatJS(content, ts = false) {
|
|
159
162
|
return prettier.format(content, {
|
|
160
163
|
parser: ts ? `typescript` : `babel`,
|
|
161
|
-
plugins: [
|
|
164
|
+
plugins: [
|
|
165
|
+
prettierPluginBabel,
|
|
166
|
+
/** @type {import('prettier').Plugin} */ (prettierPluginEstree),
|
|
167
|
+
prettierPluginTypescript,
|
|
168
|
+
],
|
|
162
169
|
});
|
|
163
170
|
}
|
|
164
171
|
|
|
@@ -193,25 +200,53 @@ const formats = {
|
|
|
193
200
|
* ```
|
|
194
201
|
*/
|
|
195
202
|
[cssVariables]: async function ({ dictionary, options = {}, file }) {
|
|
196
|
-
const selector =
|
|
203
|
+
const selector = Array.isArray(options.selector)
|
|
204
|
+
? options.selector
|
|
205
|
+
: options.selector
|
|
206
|
+
? [options.selector]
|
|
207
|
+
: [`:root`];
|
|
197
208
|
const { outputReferences, outputReferenceFallbacks, usesDtcg, formatting } = options;
|
|
198
209
|
const header = await fileHeader({
|
|
199
210
|
file,
|
|
200
211
|
formatting: getFormattingCloneWithoutPrefix(formatting),
|
|
201
212
|
options,
|
|
202
213
|
});
|
|
214
|
+
const indentation = formatting?.indentation || ' ';
|
|
215
|
+
|
|
216
|
+
const nestInSelector = (
|
|
217
|
+
/** @type {string} */ content,
|
|
218
|
+
/** @type {string} */ selector,
|
|
219
|
+
/** @type {string} */ indentation,
|
|
220
|
+
) => {
|
|
221
|
+
return `${indentation}${selector} {\n` + content + `\n${indentation}}`;
|
|
222
|
+
};
|
|
223
|
+
|
|
224
|
+
const variables = formattedVariables({
|
|
225
|
+
format: css,
|
|
226
|
+
dictionary,
|
|
227
|
+
outputReferences,
|
|
228
|
+
outputReferenceFallbacks,
|
|
229
|
+
formatting: {
|
|
230
|
+
...formatting,
|
|
231
|
+
indentation: indentation.repeat(selector.length),
|
|
232
|
+
},
|
|
233
|
+
usesDtcg,
|
|
234
|
+
});
|
|
235
|
+
|
|
203
236
|
return (
|
|
204
237
|
header +
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
238
|
+
selector
|
|
239
|
+
.reverse()
|
|
240
|
+
.reduce(
|
|
241
|
+
(content, currentSelector, index) =>
|
|
242
|
+
nestInSelector(
|
|
243
|
+
content,
|
|
244
|
+
currentSelector,
|
|
245
|
+
indentation.repeat(selector.length - 1 - index),
|
|
246
|
+
),
|
|
247
|
+
variables,
|
|
248
|
+
) +
|
|
249
|
+
'\n'
|
|
215
250
|
);
|
|
216
251
|
},
|
|
217
252
|
|
|
@@ -640,7 +675,13 @@ const formats = {
|
|
|
640
675
|
const comment = options.usesDtcg ? token.$description : token.comment;
|
|
641
676
|
const to_ret = `export const ${token.name} = ${value};`;
|
|
642
677
|
|
|
643
|
-
|
|
678
|
+
const format = {
|
|
679
|
+
commentStyle: short,
|
|
680
|
+
indentation: '',
|
|
681
|
+
...formatting,
|
|
682
|
+
};
|
|
683
|
+
|
|
684
|
+
return comment ? addComment(to_ret, comment, format) : to_ret;
|
|
644
685
|
}),
|
|
645
686
|
]
|
|
646
687
|
.flat()
|
|
@@ -665,7 +706,7 @@ const formats = {
|
|
|
665
706
|
* ```
|
|
666
707
|
*/
|
|
667
708
|
[javascriptEsm]: async function ({ dictionary, file, options }) {
|
|
668
|
-
const { formatting, minify = false } = options;
|
|
709
|
+
const { formatting, minify = false, flat = false } = options;
|
|
669
710
|
let { tokens } = dictionary;
|
|
670
711
|
tokens = stripMetaProps(
|
|
671
712
|
tokens,
|
|
@@ -678,11 +719,25 @@ const formats = {
|
|
|
678
719
|
options,
|
|
679
720
|
});
|
|
680
721
|
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
722
|
+
let dictionaryString;
|
|
723
|
+
if (flat) {
|
|
724
|
+
dictionaryString = JSON.stringify(
|
|
725
|
+
Object.fromEntries(
|
|
726
|
+
dictionary.allTokens.map((token) => [
|
|
727
|
+
token.name,
|
|
728
|
+
options.usesDtcg ? token.$value : token.value,
|
|
729
|
+
]),
|
|
730
|
+
),
|
|
731
|
+
null,
|
|
732
|
+
2,
|
|
733
|
+
);
|
|
734
|
+
} else {
|
|
735
|
+
dictionaryString = JSON.stringify(
|
|
736
|
+
minify ? minifyDictionary(tokens, options.usesDtcg) : tokens,
|
|
737
|
+
null,
|
|
738
|
+
2,
|
|
739
|
+
);
|
|
740
|
+
}
|
|
686
741
|
|
|
687
742
|
const content = `${header}export default ${dictionaryString};\n`;
|
|
688
743
|
return formatJS(content);
|
|
@@ -735,15 +790,19 @@ const formats = {
|
|
|
735
790
|
options,
|
|
736
791
|
);
|
|
737
792
|
const comment = options.usesDtcg ? token.$description : token.comment;
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
793
|
+
const to_ret = `export const ${token.name} : ${typescriptType};`;
|
|
794
|
+
const format = {
|
|
795
|
+
commentPosition: above,
|
|
796
|
+
commentStyle: long,
|
|
797
|
+
indentation: '',
|
|
798
|
+
...formatting,
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
return comment ? addComment(to_ret, comment, format) : to_ret;
|
|
743
802
|
}),
|
|
744
803
|
]
|
|
745
804
|
.flat()
|
|
746
|
-
.join('');
|
|
805
|
+
.join('\n');
|
|
747
806
|
return formatJS(content, true);
|
|
748
807
|
},
|
|
749
808
|
|
|
@@ -198,12 +198,12 @@ declare const _default: {
|
|
|
198
198
|
transform: (token: import("../../types/DesignToken.d.ts").TransformedToken, _: import("../../types/Config.d.ts").PlatformConfig, options: import("../../types/Config.d.ts").Config) => string;
|
|
199
199
|
};
|
|
200
200
|
/**
|
|
201
|
-
* Transforms the value into
|
|
201
|
+
* Transforms the value into a 6-digit (if alpha is undefined or 1.0) or 8-digit hex string
|
|
202
202
|
*
|
|
203
203
|
* ```js
|
|
204
204
|
* // Matches: token.type === 'color'
|
|
205
205
|
* // Returns:
|
|
206
|
-
* "#
|
|
206
|
+
* "#009688DE"
|
|
207
207
|
* ```
|
|
208
208
|
*
|
|
209
209
|
* @memberof Transforms
|
|
@@ -221,7 +221,7 @@ declare const _default: {
|
|
|
221
221
|
* // Returns:
|
|
222
222
|
* "#009688ff"
|
|
223
223
|
* ```
|
|
224
|
-
*
|
|
224
|
+
* @deprecated use colorHex ('color/hex') instead, which supports hex8 now.
|
|
225
225
|
* @memberof Transforms
|
|
226
226
|
*/
|
|
227
227
|
"color/hex8": {
|
package/lib/common/transforms.js
CHANGED
|
@@ -44,9 +44,15 @@ const camelOpts = {
|
|
|
44
44
|
* @returns {boolean}
|
|
45
45
|
*/
|
|
46
46
|
export function isColor(token, options) {
|
|
47
|
+
const val = options.usesDtcg ? token.$value : token.value;
|
|
48
|
+
const type = options.usesDtcg ? token.$type : token.type;
|
|
47
49
|
return (
|
|
48
|
-
|
|
49
|
-
Color(
|
|
50
|
+
type === 'color' &&
|
|
51
|
+
Color(val).isValid() &&
|
|
52
|
+
// exclude gradients from being color transformed
|
|
53
|
+
['linear', 'radial', 'conic']
|
|
54
|
+
.map((pre) => `${pre}-gradient`)
|
|
55
|
+
.every((pre) => !`${val}`.startsWith(pre) && !`${val}`.startsWith(`repeating-${pre}`))
|
|
50
56
|
);
|
|
51
57
|
}
|
|
52
58
|
|
|
@@ -454,12 +460,12 @@ export default {
|
|
|
454
460
|
},
|
|
455
461
|
|
|
456
462
|
/**
|
|
457
|
-
* Transforms the value into
|
|
463
|
+
* Transforms the value into a 6-digit (if alpha is undefined or 1.0) or 8-digit hex string
|
|
458
464
|
*
|
|
459
465
|
* ```js
|
|
460
466
|
* // Matches: token.type === 'color'
|
|
461
467
|
* // Returns:
|
|
462
|
-
* "#
|
|
468
|
+
* "#009688DE"
|
|
463
469
|
* ```
|
|
464
470
|
*
|
|
465
471
|
* @memberof Transforms
|
|
@@ -468,7 +474,12 @@ export default {
|
|
|
468
474
|
type: value,
|
|
469
475
|
filter: isColor,
|
|
470
476
|
transform: function (token, _, options) {
|
|
471
|
-
|
|
477
|
+
const color = Color(options.usesDtcg ? token.$value : token.value);
|
|
478
|
+
if (color.getAlpha() === 1) {
|
|
479
|
+
return color.toHexString();
|
|
480
|
+
} else {
|
|
481
|
+
return color.toHex8String();
|
|
482
|
+
}
|
|
472
483
|
},
|
|
473
484
|
},
|
|
474
485
|
|
|
@@ -480,7 +491,7 @@ export default {
|
|
|
480
491
|
* // Returns:
|
|
481
492
|
* "#009688ff"
|
|
482
493
|
* ```
|
|
483
|
-
*
|
|
494
|
+
* @deprecated use colorHex ('color/hex') instead, which supports hex8 now.
|
|
484
495
|
* @memberof Transforms
|
|
485
496
|
*/
|
|
486
497
|
[transforms.colorHex8]: {
|
|
@@ -11,7 +11,6 @@ export namespace transforms {
|
|
|
11
11
|
let colorHsl: "color/hsl";
|
|
12
12
|
let colorHsl4: "color/hsl-4";
|
|
13
13
|
let colorHex: "color/hex";
|
|
14
|
-
let colorHex8: "color/hex8";
|
|
15
14
|
let colorHex8android: "color/hex8android";
|
|
16
15
|
let colorComposeColor: "color/composeColor";
|
|
17
16
|
let colorUIColor: "color/UIColor";
|
|
@@ -54,4 +53,5 @@ export namespace transforms {
|
|
|
54
53
|
let contentFlutterLiteral: "content/flutter/literal";
|
|
55
54
|
let assetFlutterLiteral: "asset/flutter/literal";
|
|
56
55
|
let sizeFlutterRemToDouble: "size/flutter/remToDouble";
|
|
56
|
+
let colorHex8: "color/hex8";
|
|
57
57
|
}
|
package/lib/enums/transforms.js
CHANGED
|
@@ -11,7 +11,6 @@ export const transforms = {
|
|
|
11
11
|
colorHsl: /** @type {'color/hsl'} */ ('color/hsl'),
|
|
12
12
|
colorHsl4: /** @type {'color/hsl-4'} */ ('color/hsl-4'),
|
|
13
13
|
colorHex: /** @type {'color/hex'} */ ('color/hex'),
|
|
14
|
-
colorHex8: /** @type {'color/hex8'} */ ('color/hex8'),
|
|
15
14
|
colorHex8android: /** @type {'color/hex8android'} */ ('color/hex8android'),
|
|
16
15
|
colorComposeColor: /** @type {'color/composeColor'} */ ('color/composeColor'),
|
|
17
16
|
colorUIColor: /** @type {'color/UIColor'} */ ('color/UIColor'),
|
|
@@ -54,4 +53,8 @@ export const transforms = {
|
|
|
54
53
|
contentFlutterLiteral: /** @type {'content/flutter/literal'} */ ('content/flutter/literal'),
|
|
55
54
|
assetFlutterLiteral: /** @type {'asset/flutter/literal'} */ ('asset/flutter/literal'),
|
|
56
55
|
sizeFlutterRemToDouble: /** @type {'size/flutter/remToDouble'} */ ('size/flutter/remToDouble'),
|
|
56
|
+
/**
|
|
57
|
+
* @deprecated use 'color/hex instead
|
|
58
|
+
*/
|
|
59
|
+
colorHex8: /** @type {'color/hex8'} */ ('color/hex8'),
|
|
57
60
|
};
|
|
@@ -25,20 +25,18 @@ function recurse(slice, opts) {
|
|
|
25
25
|
let types = new Set();
|
|
26
26
|
|
|
27
27
|
// this slice within the dictionary is a design token
|
|
28
|
-
|
|
28
|
+
// Check for $value in case the input is already DTCG syntax
|
|
29
|
+
if (Object.hasOwn(slice, 'value') || Object.hasOwn(slice, '$value')) {
|
|
29
30
|
const token = /** @type {DesignToken} */ (slice);
|
|
30
|
-
// convert to $ prefixed properties
|
|
31
31
|
Object.keys(token).forEach((key) => {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
delete token[key];
|
|
41
|
-
// no-default
|
|
32
|
+
if (['type', '$type'].includes(key)) {
|
|
33
|
+
// track the encountered types for this layer
|
|
34
|
+
types.add(/** @type {string} */ (token[key]));
|
|
35
|
+
}
|
|
36
|
+
// convert to $ prefixed properties
|
|
37
|
+
if (['type', 'description', 'value'].includes(key)) {
|
|
38
|
+
token[`$${key}`] = token[key];
|
|
39
|
+
delete token[key];
|
|
42
40
|
}
|
|
43
41
|
});
|
|
44
42
|
return types;
|
package/lib/utils/preprocess.js
CHANGED
|
@@ -38,8 +38,9 @@ export async function preprocess(
|
|
|
38
38
|
|
|
39
39
|
const preprocessors = Object.entries(preprocessorObj);
|
|
40
40
|
if (preprocessors.length > 0) {
|
|
41
|
-
for (const
|
|
42
|
-
|
|
41
|
+
for (const key of appliedPreprocessors) {
|
|
42
|
+
const preprocessor = preprocessorObj[key];
|
|
43
|
+
if (preprocessor) {
|
|
43
44
|
processedTokens = await preprocessor(processedTokens, options);
|
|
44
45
|
}
|
|
45
46
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "style-dictionary",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.0",
|
|
4
4
|
"description": "Style once, use everywhere. A build system for creating cross-platform styles.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"style dictionary",
|
|
@@ -130,8 +130,7 @@
|
|
|
130
130
|
},
|
|
131
131
|
"devDependencies": {
|
|
132
132
|
"@astrojs/check": "^0.9.4",
|
|
133
|
-
"@astrojs/starlight": "^0.
|
|
134
|
-
"@babel/plugin-proposal-private-property-in-object": "^7.21.11",
|
|
133
|
+
"@astrojs/starlight": "^0.31.1",
|
|
135
134
|
"@changesets/cli": "^2.27.1",
|
|
136
135
|
"@commitlint/cli": "^18.4.3",
|
|
137
136
|
"@commitlint/config-conventional": "^18.4.3",
|
|
@@ -142,16 +141,16 @@
|
|
|
142
141
|
"@types/chai": "^4.3.9",
|
|
143
142
|
"@types/tinycolor2": "^1.4.6",
|
|
144
143
|
"@types/uuid": "^9.0.8",
|
|
145
|
-
"@typescript-eslint/parser": "^8.
|
|
144
|
+
"@typescript-eslint/parser": "^8.22.0",
|
|
146
145
|
"@web/test-runner": "^0.18.2",
|
|
147
146
|
"@web/test-runner-commands": "^0.9.0",
|
|
148
147
|
"@web/test-runner-playwright": "^0.11.0",
|
|
149
148
|
"acorn": "^8.11.3",
|
|
150
|
-
"astro": "^
|
|
149
|
+
"astro": "^5.2.3",
|
|
151
150
|
"chai": "^5.0.0-alpha.2",
|
|
152
|
-
"eslint": "^9.
|
|
151
|
+
"eslint": "^9.19.0",
|
|
153
152
|
"eslint-plugin-mocha": "^10.5.0",
|
|
154
|
-
"eslint-plugin-react": "^7.37.
|
|
153
|
+
"eslint-plugin-react": "^7.37.4",
|
|
155
154
|
"estree-walker": "^3.0.3",
|
|
156
155
|
"fs-extra": "^10.0.0",
|
|
157
156
|
"hanbi": "^1.0.1",
|
|
@@ -169,7 +168,7 @@
|
|
|
169
168
|
"npm-run-all": "^4.1.5",
|
|
170
169
|
"sass": "^1.69.5",
|
|
171
170
|
"sharp": "^0.32.5",
|
|
172
|
-
"starlight-links-validator": "^0.
|
|
171
|
+
"starlight-links-validator": "^0.14.2 ",
|
|
173
172
|
"stylus": "^0.56.0",
|
|
174
173
|
"typescript": "^5.7.2",
|
|
175
174
|
"unist-util-visit": "^5.0.0",
|