style-dictionary 5.3.0 → 5.3.2
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/examples/advanced/assets-base64-embed/package.json +1 -1
- package/examples/advanced/create-react-app/package.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/font-face-rules/package.json +1 -1
- package/examples/advanced/format-helpers/package.json +1 -1
- package/examples/advanced/matching-build-files/package.json +1 -1
- package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
- package/examples/advanced/node-modules-as-config-and-properties/package-lock.json +3 -3
- package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
- package/examples/advanced/npm-module/package.json +1 -1
- package/examples/advanced/referencing_aliasing/package.json +1 -1
- package/examples/advanced/s3/package.json +1 -1
- package/examples/advanced/tailwind-preset/package.json +1 -1
- package/examples/advanced/tokens-deprecation/package.json +1 -1
- package/examples/advanced/transitive-transforms/package.json +1 -1
- package/examples/advanced/variables-in-outputs/package.json +1 -1
- package/examples/advanced/yaml-tokens/package.json +1 -1
- package/lib/StyleDictionary.js +1 -1
- package/lib/common/transforms.d.ts +7 -13
- package/lib/common/transforms.js +35 -27
- package/package.json +2 -2
|
@@ -1125,9 +1125,9 @@
|
|
|
1125
1125
|
"license": "MIT"
|
|
1126
1126
|
},
|
|
1127
1127
|
"node_modules/qs": {
|
|
1128
|
-
"version": "6.14.
|
|
1129
|
-
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.
|
|
1130
|
-
"integrity": "sha512-
|
|
1128
|
+
"version": "6.14.2",
|
|
1129
|
+
"resolved": "https://registry.npmjs.org/qs/-/qs-6.14.2.tgz",
|
|
1130
|
+
"integrity": "sha512-V/yCWTTF7VJ9hIh18Ugr2zhJMP01MY7c5kh4J870L7imm6/DIzBsNLTXzMwUA3yZ5b/KBqLx8Kp3uRvd7xSe3Q==",
|
|
1131
1131
|
"dev": true,
|
|
1132
1132
|
"license": "BSD-3-Clause",
|
|
1133
1133
|
"dependencies": {
|
package/lib/StyleDictionary.js
CHANGED
|
@@ -67,7 +67,7 @@ export default class StyleDictionary extends Register {
|
|
|
67
67
|
// Placeholder is transformed on prepublish -> see scripts/inject-version.js
|
|
68
68
|
// 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.
|
|
69
69
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
|
|
70
|
-
static VERSION = '5.3.
|
|
70
|
+
static VERSION = '5.3.2';
|
|
71
71
|
|
|
72
72
|
/** @returns {Config} */
|
|
73
73
|
get options() {
|
|
@@ -5,17 +5,12 @@
|
|
|
5
5
|
*/
|
|
6
6
|
export function isDTCGColorObject(val: unknown): val is DTCGColorValue;
|
|
7
7
|
/**
|
|
8
|
-
* Get color
|
|
9
|
-
*
|
|
10
|
-
* @param {
|
|
11
|
-
* @returns {
|
|
8
|
+
* Get a CSS compatible color string from a token value that contains a color property
|
|
9
|
+
* Used in CSS shorthand transforms for token types that can have color poperties, like border, gradient, shadow.
|
|
10
|
+
* @param {unknown} tokenValue
|
|
11
|
+
* @returns {string | undefined}
|
|
12
12
|
*/
|
|
13
|
-
export function
|
|
14
|
-
r: number;
|
|
15
|
-
g: number;
|
|
16
|
-
b: number;
|
|
17
|
-
a: number;
|
|
18
|
-
};
|
|
13
|
+
export function getColorStringFromTokenObjectValue(tokenValue: unknown): string | undefined;
|
|
19
14
|
/**
|
|
20
15
|
* Get a tinycolor2 Color instance from either legacy string format or DTCG object format
|
|
21
16
|
* This provides backward compatibility for transformers that use tinycolor2 methods
|
|
@@ -26,11 +21,10 @@ export function getColorRgb(token: Token, options: Config): {
|
|
|
26
21
|
export function getColor(token: Token, options: Config): ReturnType<typeof Color>;
|
|
27
22
|
/**
|
|
28
23
|
* Get a ColorJS Color instance from either legacy string format or DTCG object format
|
|
29
|
-
* @param {
|
|
30
|
-
* @param {Config} options
|
|
24
|
+
* @param {DTCGColorValue | string} val
|
|
31
25
|
* @returns {ColorJS}
|
|
32
26
|
*/
|
|
33
|
-
export function getColorJS(
|
|
27
|
+
export function getColorJS(val: DTCGColorValue | string): ColorJS;
|
|
34
28
|
/**
|
|
35
29
|
* @param {Token} token
|
|
36
30
|
* @param {Config} options
|
package/lib/common/transforms.js
CHANGED
|
@@ -130,20 +130,23 @@ function dtcgColorToRgb(dtcgColor) {
|
|
|
130
130
|
}
|
|
131
131
|
|
|
132
132
|
/**
|
|
133
|
-
* Get color
|
|
134
|
-
*
|
|
135
|
-
* @param {
|
|
136
|
-
* @returns {
|
|
133
|
+
* Get a CSS compatible color string from a token value that contains a color property
|
|
134
|
+
* Used in CSS shorthand transforms for token types that can have color poperties, like border, gradient, shadow.
|
|
135
|
+
* @param {unknown} tokenValue
|
|
136
|
+
* @returns {string | undefined}
|
|
137
137
|
*/
|
|
138
|
-
export function
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
if (
|
|
142
|
-
|
|
138
|
+
export function getColorStringFromTokenObjectValue(tokenValue) {
|
|
139
|
+
/** @type {string | undefined} */
|
|
140
|
+
let hex;
|
|
141
|
+
if (typeof tokenValue === 'object' && tokenValue !== null && 'color' in tokenValue) {
|
|
142
|
+
if (typeof tokenValue.color === 'string') {
|
|
143
|
+
return tokenValue.color;
|
|
144
|
+
}
|
|
145
|
+
let color = /** @type {DTCGColorValue} */ (tokenValue.color);
|
|
146
|
+
let colorJS = getColorJS(color);
|
|
147
|
+
hex = colorJS.toString();
|
|
143
148
|
}
|
|
144
|
-
|
|
145
|
-
// Legacy format - use tinycolor2
|
|
146
|
-
return Color(val).toRgb();
|
|
149
|
+
return hex;
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
/**
|
|
@@ -166,13 +169,10 @@ export function getColor(token, options) {
|
|
|
166
169
|
|
|
167
170
|
/**
|
|
168
171
|
* Get a ColorJS Color instance from either legacy string format or DTCG object format
|
|
169
|
-
* @param {
|
|
170
|
-
* @param {Config} options
|
|
172
|
+
* @param {DTCGColorValue | string} val
|
|
171
173
|
* @returns {ColorJS}
|
|
172
174
|
*/
|
|
173
|
-
export function getColorJS(
|
|
174
|
-
const val = options.usesDtcg ? token.$value : token.value;
|
|
175
|
-
|
|
175
|
+
export function getColorJS(val) {
|
|
176
176
|
if (isDTCGColorObject(val)) {
|
|
177
177
|
return dtcgToColorJS(val);
|
|
178
178
|
}
|
|
@@ -858,7 +858,8 @@ export default {
|
|
|
858
858
|
type: value,
|
|
859
859
|
filter: isColor,
|
|
860
860
|
transform: function (token, _, options) {
|
|
861
|
-
const
|
|
861
|
+
const val = options.usesDtcg ? token.$value : token.value;
|
|
862
|
+
const color = getColorJS(val).to('oklch');
|
|
862
863
|
const [l, c, h] = color.coords;
|
|
863
864
|
const alpha = isNaN(color.alpha) ? 1 : color.alpha;
|
|
864
865
|
// Format: oklch(L C H) or oklch(L C H / alpha)
|
|
@@ -889,7 +890,8 @@ export default {
|
|
|
889
890
|
type: value,
|
|
890
891
|
filter: isColor,
|
|
891
892
|
transform: function (token, _, options) {
|
|
892
|
-
const
|
|
893
|
+
const val = options.usesDtcg ? token.$value : token.value;
|
|
894
|
+
const color = getColorJS(val).to('oklab');
|
|
893
895
|
const [l, a, b] = color.coords;
|
|
894
896
|
const alpha = isNaN(color.alpha) ? 1 : color.alpha;
|
|
895
897
|
// Format: oklab(L a b) or oklab(L a b / alpha)
|
|
@@ -920,7 +922,8 @@ export default {
|
|
|
920
922
|
type: value,
|
|
921
923
|
filter: isColor,
|
|
922
924
|
transform: function (token, _, options) {
|
|
923
|
-
const
|
|
925
|
+
const val = options.usesDtcg ? token.$value : token.value;
|
|
926
|
+
const color = getColorJS(val).to('p3');
|
|
924
927
|
const [r, g, b] = color.coords;
|
|
925
928
|
const alpha = isNaN(color.alpha) ? 1 : color.alpha;
|
|
926
929
|
// Format: color(display-p3 r g b) or color(display-p3 r g b / alpha)
|
|
@@ -951,7 +954,8 @@ export default {
|
|
|
951
954
|
type: value,
|
|
952
955
|
filter: isColor,
|
|
953
956
|
transform: function (token, _, options) {
|
|
954
|
-
const
|
|
957
|
+
const val = options.usesDtcg ? token.$value : token.value;
|
|
958
|
+
const color = getColorJS(val).to('lch');
|
|
955
959
|
const [l, c, h] = color.coords;
|
|
956
960
|
const alpha = isNaN(color.alpha) ? 1 : color.alpha;
|
|
957
961
|
// Format: lch(L% C H) or lch(L% C H / alpha)
|
|
@@ -1561,16 +1565,18 @@ export default {
|
|
|
1561
1565
|
// already transformed to string
|
|
1562
1566
|
return val;
|
|
1563
1567
|
}
|
|
1564
|
-
const
|
|
1565
|
-
|
|
1568
|
+
const colorStr = getColorStringFromTokenObjectValue(val);
|
|
1569
|
+
const { width } = val;
|
|
1566
1570
|
|
|
1567
1571
|
// use fallback for style object value, since CSS does not allow
|
|
1568
1572
|
// detailed control of the dash pattern or line caps on dashed borders
|
|
1569
1573
|
// https://design-tokens.github.io/community-group/format/#example-fallback-for-object-stroke-style
|
|
1574
|
+
let { style } = val;
|
|
1570
1575
|
if (typeof style === 'object') {
|
|
1571
1576
|
style = 'dashed';
|
|
1572
1577
|
}
|
|
1573
|
-
|
|
1578
|
+
|
|
1579
|
+
return `${width ? `${width} ` : ''}${style ? `${style}` : 'none'}${colorStr ? ` ${colorStr}` : ''}`;
|
|
1574
1580
|
},
|
|
1575
1581
|
},
|
|
1576
1582
|
|
|
@@ -1693,10 +1699,12 @@ export default {
|
|
|
1693
1699
|
if (typeof val !== 'object') {
|
|
1694
1700
|
return val;
|
|
1695
1701
|
}
|
|
1696
|
-
const {
|
|
1697
|
-
|
|
1702
|
+
const { inset, type, offsetX, offsetY, blur, spread } = val;
|
|
1703
|
+
const colorStr = getColorStringFromTokenObjectValue(val);
|
|
1704
|
+
// `type` property will be deprecated (Tokens Studio compat) in the future and removed in v6
|
|
1705
|
+
return `${inset || type === 'inset' ? 'inset ' : ''}${offsetX ?? 0} ${offsetY ?? 0} ${blur ?? 0} ${
|
|
1698
1706
|
spread ? `${spread} ` : ''
|
|
1699
|
-
}${
|
|
1707
|
+
}${colorStr ?? `#000000`}`;
|
|
1700
1708
|
};
|
|
1701
1709
|
|
|
1702
1710
|
if (Array.isArray(val)) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "style-dictionary",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.2",
|
|
4
4
|
"description": "Style once, use everywhere. A build system for creating cross-platform styles.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"style dictionary",
|
|
@@ -117,7 +117,7 @@
|
|
|
117
117
|
},
|
|
118
118
|
"dependencies": {
|
|
119
119
|
"@bundled-es-modules/deepmerge": "^4.3.1",
|
|
120
|
-
"@bundled-es-modules/glob": "^13.0.
|
|
120
|
+
"@bundled-es-modules/glob": "^13.0.3",
|
|
121
121
|
"@bundled-es-modules/memfs": "^4.17.0",
|
|
122
122
|
"@zip.js/zip.js": "^2.7.44",
|
|
123
123
|
"chalk": "^5.3.0",
|