style-dictionary 5.4.3 → 5.5.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/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.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 +3 -1
- package/lib/common/transforms.d.ts +2 -2
- package/lib/common/transforms.js +10 -4
- package/lib/utils/convertTokenData.js +4 -0
- package/package.json +8 -4
- package/types/Config.d.ts +1 -0
- package/types/File.d.ts +1 -0
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.
|
|
70
|
+
static VERSION = '5.5.0';
|
|
71
71
|
|
|
72
72
|
/** @returns {Config} */
|
|
73
73
|
get options() {
|
|
@@ -646,6 +646,7 @@ export default class StyleDictionary extends Register {
|
|
|
646
646
|
const { destination } = file || {};
|
|
647
647
|
const filter = /** @type {Filter['filter']|undefined} */ (file.filter);
|
|
648
648
|
let { format } = file || {};
|
|
649
|
+
const emitEmptyFiles = file.emitEmptyFiles ?? platform.emitEmptyFiles ?? false;
|
|
649
650
|
|
|
650
651
|
if (typeof format !== 'function') throw new Error('Please enter a valid file format');
|
|
651
652
|
if (destination !== undefined && typeof destination !== 'string')
|
|
@@ -677,6 +678,7 @@ export default class StyleDictionary extends Register {
|
|
|
677
678
|
|
|
678
679
|
// if tokens object is empty, return without creating a file
|
|
679
680
|
if (
|
|
681
|
+
!emitEmptyFiles &&
|
|
680
682
|
Object.hasOwn(filteredTokens, 'tokens') &&
|
|
681
683
|
Object.keys(filteredTokens.tokens).length === 0 &&
|
|
682
684
|
filteredTokens.tokens.constructor === Object
|
|
@@ -38,13 +38,13 @@ export function isColor(token: Token, options: Config): boolean;
|
|
|
38
38
|
* Note: the result could contain a unitless dimension
|
|
39
39
|
* Historically in Style Dictionary, number tokens were defined as unitless dimension tokens
|
|
40
40
|
* We can `deprecated` this and remove that in a breaking change, forcing users to change them to number tokens
|
|
41
|
-
* @param {Token['value']}
|
|
41
|
+
* @param {Token['value']} _val
|
|
42
42
|
*
|
|
43
43
|
* unit can be undefined for this utility method as well to support old dimension token values
|
|
44
44
|
* which can be defined as unitless dimension tokens or numbers
|
|
45
45
|
* @returns {{ value: string | number; unit: TokenTypeDimensionUnit | undefined }}
|
|
46
46
|
*/
|
|
47
|
-
export function getTokenDimensionValue(
|
|
47
|
+
export function getTokenDimensionValue(_val: Token["value"]): {
|
|
48
48
|
value: string | number;
|
|
49
49
|
unit: TokenTypeDimensionUnit | undefined;
|
|
50
50
|
};
|
package/lib/common/transforms.js
CHANGED
|
@@ -381,13 +381,14 @@ function transformCubicBezierCSS(token, options) {
|
|
|
381
381
|
* Note: the result could contain a unitless dimension
|
|
382
382
|
* Historically in Style Dictionary, number tokens were defined as unitless dimension tokens
|
|
383
383
|
* We can `deprecated` this and remove that in a breaking change, forcing users to change them to number tokens
|
|
384
|
-
* @param {Token['value']}
|
|
384
|
+
* @param {Token['value']} _val
|
|
385
385
|
*
|
|
386
386
|
* unit can be undefined for this utility method as well to support old dimension token values
|
|
387
387
|
* which can be defined as unitless dimension tokens or numbers
|
|
388
388
|
* @returns {{ value: string | number; unit: TokenTypeDimensionUnit | undefined }}
|
|
389
389
|
*/
|
|
390
|
-
export function getTokenDimensionValue(
|
|
390
|
+
export function getTokenDimensionValue(_val) {
|
|
391
|
+
let val = _val;
|
|
391
392
|
/** @type {TokenTypeDimensionUnit | undefined} */
|
|
392
393
|
let unit;
|
|
393
394
|
const valueObj = typeof val === 'object' && !Array.isArray(val) && val !== null;
|
|
@@ -396,9 +397,14 @@ export function getTokenDimensionValue(val) {
|
|
|
396
397
|
if (!valueObj) {
|
|
397
398
|
// if it contains a unit -> split it into unit and val
|
|
398
399
|
const unitMatch = `${val}`.match(/[^0-9.-]+$/);
|
|
399
|
-
|
|
400
|
+
|
|
401
|
+
// try to get the value already without unit
|
|
402
|
+
const valWithoutUnit = `${val}`.replace(unitMatch?.[0] ?? '', '');
|
|
403
|
+
|
|
404
|
+
// guard that we can actually parse the value as a number
|
|
405
|
+
if (unitMatch && !Number.isNaN(parseFloat(valWithoutUnit))) {
|
|
400
406
|
unit = /** @type {TokenTypeDimensionUnit} */ (unitMatch[0]);
|
|
401
|
-
val =
|
|
407
|
+
val = valWithoutUnit;
|
|
402
408
|
}
|
|
403
409
|
}
|
|
404
410
|
|
|
@@ -33,6 +33,10 @@ function convertToTokenObject(tokenArray) {
|
|
|
33
33
|
const obj = /** @type {Tokens} */ ({});
|
|
34
34
|
tokenArray.forEach((token) => {
|
|
35
35
|
const { key } = token;
|
|
36
|
+
// prototype pollution guard -> move to next token if key is malicious
|
|
37
|
+
if (key?.includes('__proto__')) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
36
40
|
const keyArr = /** @type {string} */ (key).replace('{', '').replace('}', '').split('.');
|
|
37
41
|
let slice = obj;
|
|
38
42
|
keyArr.forEach((k, i, arr) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "style-dictionary",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.5.0",
|
|
4
4
|
"description": "Style once, use everywhere. A build system for creating cross-platform styles.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"style dictionary",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
"scripts": {
|
|
46
46
|
"build": "node scripts/inject-version.js && tsc --emitDeclarationOnly",
|
|
47
47
|
"docs:start": "astro dev --root ./docs",
|
|
48
|
-
"docs:build": "astro check
|
|
48
|
+
"docs:build": "astro check --root ./docs && astro build --root ./docs",
|
|
49
49
|
"docs:preview": "astro preview --root ./docs",
|
|
50
50
|
"format": "run-p format:*",
|
|
51
51
|
"format:eslint": "eslint --fix \"**/*.js\"",
|
|
@@ -112,7 +112,11 @@
|
|
|
112
112
|
],
|
|
113
113
|
"homepage": "https://styledictionary.com",
|
|
114
114
|
"overrides": {
|
|
115
|
-
"
|
|
115
|
+
"esbuild": "^0.28.1",
|
|
116
|
+
"js-yaml": "^4.2.0",
|
|
117
|
+
"lodash": "^4.17.23",
|
|
118
|
+
"volar-service-yaml": "0.0.71",
|
|
119
|
+
"ws": "^8.21.0"
|
|
116
120
|
},
|
|
117
121
|
"dependencies": {
|
|
118
122
|
"@bundled-es-modules/deepmerge": "^4.3.2",
|
|
@@ -148,7 +152,7 @@
|
|
|
148
152
|
"@web/test-runner-commands": "^0.9.0",
|
|
149
153
|
"@web/test-runner-playwright": "^0.11.0",
|
|
150
154
|
"acorn": "^8.11.3",
|
|
151
|
-
"astro": "^6.
|
|
155
|
+
"astro": "^6.4.8",
|
|
152
156
|
"chai": "^6.2.2",
|
|
153
157
|
"eslint": "^9.19.0",
|
|
154
158
|
"eslint-plugin-mocha": "^10.5.0",
|
package/types/Config.d.ts
CHANGED