style-dictionary 4.0.0-prerelease.13 → 4.0.0-prerelease.14
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/auto-rebuild-watcher/package.json +1 -1
- package/examples/advanced/component-cti/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-file-header/package.json +1 -1
- package/examples/advanced/custom-filters/package.json +1 -1
- package/examples/advanced/custom-formats-with-templates/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/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 +45 -11
- package/lib/buildFile.d.ts +4 -1
- package/lib/buildFile.js +6 -3
- package/lib/buildFiles.d.ts +7 -4
- package/lib/buildFiles.js +6 -4
- package/lib/cleanActions.d.ts +7 -4
- package/lib/cleanActions.js +6 -4
- package/lib/common/actions.js +2 -2
- package/lib/common/formatHelpers/createPropertyFormatter.d.ts +3 -1
- package/lib/common/formatHelpers/createPropertyFormatter.js +7 -8
- package/lib/common/formatHelpers/formattedVariables.d.ts +3 -1
- package/lib/common/formatHelpers/formattedVariables.js +3 -0
- package/lib/common/formatHelpers/getTypeScriptType.d.ts +4 -2
- package/lib/common/formatHelpers/getTypeScriptType.js +3 -2
- package/lib/common/formatHelpers/iconsWithPrefix.d.ts +4 -1
- package/lib/common/formatHelpers/iconsWithPrefix.js +6 -3
- package/lib/common/formatHelpers/minifyDictionary.d.ts +2 -1
- package/lib/common/formatHelpers/minifyDictionary.js +5 -4
- package/lib/common/formatHelpers/sortByReference.js +3 -3
- package/lib/common/formats.js +48 -41
- package/lib/common/templates/android/colors.template.d.ts +1 -1
- package/lib/common/templates/android/colors.template.js +1 -1
- package/lib/common/templates/android/dimens.template.d.ts +1 -1
- package/lib/common/templates/android/dimens.template.js +1 -1
- package/lib/common/templates/android/fontDimens.template.d.ts +1 -1
- package/lib/common/templates/android/fontDimens.template.js +1 -1
- package/lib/common/templates/android/integers.template.d.ts +1 -1
- package/lib/common/templates/android/integers.template.js +1 -1
- package/lib/common/templates/android/resources.template.d.ts +2 -0
- package/lib/common/templates/android/resources.template.js +4 -2
- package/lib/common/templates/android/strings.template.d.ts +1 -1
- package/lib/common/templates/android/strings.template.js +1 -1
- package/lib/common/templates/ios/colors.m.template.d.ts +1 -1
- package/lib/common/templates/ios/colors.m.template.js +1 -1
- package/lib/common/templates/ios/macros.template.d.ts +1 -1
- package/lib/common/templates/ios/macros.template.js +1 -1
- package/lib/common/templates/ios/plist.template.d.ts +1 -1
- package/lib/common/templates/ios/plist.template.js +5 -5
- package/lib/common/templates/ios/singleton.m.template.d.ts +1 -1
- package/lib/common/templates/ios/singleton.m.template.js +2 -2
- package/lib/common/templates/ios/static.m.template.d.ts +1 -1
- package/lib/common/templates/ios/static.m.template.js +1 -1
- package/lib/common/templates/ios/strings.m.template.d.ts +1 -1
- package/lib/common/templates/ios/strings.m.template.js +2 -2
- package/lib/common/templates/scss/map-deep.template.d.ts +1 -1
- package/lib/common/templates/scss/map-deep.template.js +1 -1
- package/lib/common/templates/scss/map-flat.template.d.ts +1 -1
- package/lib/common/templates/scss/map-flat.template.js +1 -1
- package/lib/common/templates/static-style-guide/index.html.template.d.ts +1 -1
- package/lib/common/templates/static-style-guide/index.html.template.js +2 -2
- package/lib/common/transforms.d.ts +2 -1
- package/lib/common/transforms.js +125 -119
- package/lib/filterTokens.d.ts +3 -1
- package/lib/filterTokens.js +8 -5
- package/lib/fs.js +1 -0
- package/lib/performActions.d.ts +7 -4
- package/lib/performActions.js +6 -4
- package/lib/transform/object.d.ts +5 -2
- package/lib/transform/object.js +8 -4
- package/lib/transform/token.d.ts +5 -2
- package/lib/transform/token.js +14 -12
- package/lib/utils/combineJSON.d.ts +6 -2
- package/lib/utils/combineJSON.js +9 -3
- package/lib/utils/createFormatArgs.d.ts +5 -1
- package/lib/utils/createFormatArgs.js +9 -4
- package/lib/utils/detectDtcgSyntax.d.ts +8 -0
- package/lib/utils/detectDtcgSyntax.js +26 -0
- package/lib/utils/flattenTokens.d.ts +2 -7
- package/lib/utils/flattenTokens.js +21 -14
- package/lib/utils/index.d.ts +2 -2
- package/lib/utils/index.js +2 -2
- package/lib/utils/preprocess.d.ts +3 -1
- package/lib/utils/preprocess.js +17 -15
- package/lib/utils/references/getReferences.d.ts +7 -9
- package/lib/utils/references/getReferences.js +6 -5
- package/lib/utils/references/resolveReferences.d.ts +6 -6
- package/lib/utils/references/resolveReferences.js +10 -11
- package/package.json +1 -1
- package/types/Action.d.ts +3 -3
- package/types/Config.d.ts +9 -2
- package/types/Format.d.ts +2 -2
- package/types/Transform.d.ts +2 -2
package/lib/StyleDictionary.js
CHANGED
|
@@ -25,6 +25,8 @@ import deepExtend from './utils/deepExtend.js';
|
|
|
25
25
|
import resolveObject from './utils/resolveObject.js';
|
|
26
26
|
import getName from './utils/references/getName.js';
|
|
27
27
|
import GroupMessages from './utils/groupMessages.js';
|
|
28
|
+
import flattenTokens from './utils/flattenTokens.js';
|
|
29
|
+
import { detectDtcgSyntax } from './utils/detectDtcgSyntax.js';
|
|
28
30
|
import { preprocess } from './utils/preprocess.js';
|
|
29
31
|
|
|
30
32
|
import transformObject from './transform/object.js';
|
|
@@ -34,7 +36,6 @@ import buildFiles from './buildFiles.js';
|
|
|
34
36
|
import cleanFiles from './cleanFiles.js';
|
|
35
37
|
import cleanDirs from './cleanDirs.js';
|
|
36
38
|
import cleanActions from './cleanActions.js';
|
|
37
|
-
import flattenTokens from './utils/flattenTokens.js';
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* @typedef {import('../types/Config.d.ts').Config} Config
|
|
@@ -65,7 +66,7 @@ export default class StyleDictionary extends Register {
|
|
|
65
66
|
// Placeholder is transformed on prepublish -> see scripts/inject-version.js
|
|
66
67
|
// 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.
|
|
67
68
|
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#browser_compatibility
|
|
68
|
-
static VERSION = '4.0.0-prerelease.
|
|
69
|
+
static VERSION = '4.0.0-prerelease.14';
|
|
69
70
|
static formatHelpers = formatHelpers;
|
|
70
71
|
|
|
71
72
|
/** @returns {Config} */
|
|
@@ -147,6 +148,7 @@ export default class StyleDictionary extends Register {
|
|
|
147
148
|
let includeTokens = {};
|
|
148
149
|
/** @type {Tokens} */
|
|
149
150
|
let sourceTokens = {};
|
|
151
|
+
|
|
150
152
|
// Overloaded method, can accept a string as a path that points to a JS or
|
|
151
153
|
// JSON file or a plain object. Potentially refactor.
|
|
152
154
|
if (typeof config === 'string') {
|
|
@@ -176,9 +178,12 @@ export default class StyleDictionary extends Register {
|
|
|
176
178
|
});
|
|
177
179
|
this.options = options;
|
|
178
180
|
|
|
179
|
-
|
|
180
|
-
// Also keeping an options object in case
|
|
181
|
+
let { usesDtcg } = this.options;
|
|
181
182
|
|
|
183
|
+
// Try to detect DTCG if not specified by user in options
|
|
184
|
+
if (Object.entries(this.tokens).length > 0 && usesDtcg === undefined) {
|
|
185
|
+
usesDtcg = detectDtcgSyntax(this.tokens);
|
|
186
|
+
}
|
|
182
187
|
// grab the inline tokens, ones either defined in the configuration object
|
|
183
188
|
// or that already exist from extending another style dictionary instance
|
|
184
189
|
// with `tokens` keys
|
|
@@ -188,14 +193,28 @@ export default class StyleDictionary extends Register {
|
|
|
188
193
|
if (this.options.include) {
|
|
189
194
|
if (!Array.isArray(this.options.include)) throw new Error('include must be an array');
|
|
190
195
|
|
|
191
|
-
|
|
196
|
+
const result = await combineJSON(
|
|
197
|
+
this.options.include,
|
|
198
|
+
true,
|
|
199
|
+
undefined,
|
|
200
|
+
false,
|
|
201
|
+
this.parsers,
|
|
202
|
+
this.options.usesDtcg,
|
|
203
|
+
);
|
|
204
|
+
|
|
205
|
+
includeTokens = result.tokens;
|
|
206
|
+
// If it wasn't known yet whether DTCG is used, combineJSON util will have auto-detected it
|
|
207
|
+
if (usesDtcg === undefined) {
|
|
208
|
+
usesDtcg = result.usesDtcg;
|
|
209
|
+
}
|
|
192
210
|
}
|
|
193
211
|
|
|
194
212
|
// Update tokens with current package's source
|
|
195
213
|
// These highest precedence
|
|
196
214
|
if (this.options.source) {
|
|
197
215
|
if (!Array.isArray(this.options.source)) throw new Error('source must be an array');
|
|
198
|
-
|
|
216
|
+
|
|
217
|
+
const result = await combineJSON(
|
|
199
218
|
this.options.source,
|
|
200
219
|
true,
|
|
201
220
|
/** @param {Token} prop */
|
|
@@ -209,8 +228,15 @@ export default class StyleDictionary extends Register {
|
|
|
209
228
|
},
|
|
210
229
|
true,
|
|
211
230
|
this.parsers,
|
|
231
|
+
this.options.usesDtcg,
|
|
212
232
|
);
|
|
213
233
|
|
|
234
|
+
sourceTokens = result.tokens;
|
|
235
|
+
// If it wasn't known yet whether DTCG is used, combineJSON util will have auto-detected it
|
|
236
|
+
if (usesDtcg === undefined) {
|
|
237
|
+
usesDtcg = result.usesDtcg;
|
|
238
|
+
}
|
|
239
|
+
|
|
214
240
|
if (GroupMessages.count(PROPERTY_VALUE_COLLISIONS) > 0) {
|
|
215
241
|
const collisions = GroupMessages.flush(PROPERTY_VALUE_COLLISIONS).join('\n');
|
|
216
242
|
const warn = `\n${PROPERTY_VALUE_COLLISIONS}:\n${collisions}\n\n`;
|
|
@@ -226,6 +252,7 @@ export default class StyleDictionary extends Register {
|
|
|
226
252
|
// Merge inline, include, and source tokens
|
|
227
253
|
const unprocessedTokens = deepExtend([{}, inlineTokens, includeTokens, sourceTokens]);
|
|
228
254
|
this.tokens = await preprocess(unprocessedTokens, this.preprocessors);
|
|
255
|
+
this.options = { ...this.options, usesDtcg };
|
|
229
256
|
this.hasInitializedResolve(null);
|
|
230
257
|
|
|
231
258
|
// For chaining
|
|
@@ -306,7 +333,12 @@ export default class StyleDictionary extends Register {
|
|
|
306
333
|
// values like "1px solid {color.border.base}" we want to
|
|
307
334
|
// transform the original value (color.border.base) before
|
|
308
335
|
// replacing that value in the string.
|
|
309
|
-
const transformed = transformObject(
|
|
336
|
+
const transformed = transformObject(
|
|
337
|
+
exportableResult,
|
|
338
|
+
platformConfig,
|
|
339
|
+
this.options,
|
|
340
|
+
transformationContext,
|
|
341
|
+
);
|
|
310
342
|
|
|
311
343
|
// referenced values, that have not (yet) been transformed should be excluded from resolving
|
|
312
344
|
const ignorePathsToResolve = deferredPropValueTransforms.map((p) => getName([p, 'value']));
|
|
@@ -365,7 +397,9 @@ export default class StyleDictionary extends Register {
|
|
|
365
397
|
// transform the original value (color.border.base) before
|
|
366
398
|
// replacing that value in the string.
|
|
367
399
|
const tokens = await this.exportPlatform(platform);
|
|
368
|
-
this.allTokens = /** @type {TransformedToken[]} */ (
|
|
400
|
+
this.allTokens = /** @type {TransformedToken[]} */ (
|
|
401
|
+
flattenTokens(tokens, this.options.usesDtcg)
|
|
402
|
+
);
|
|
369
403
|
// This is the dictionary object we pass to the file
|
|
370
404
|
// building and action methods.
|
|
371
405
|
return { dictionary: { tokens, allTokens: this.allTokens }, platformConfig };
|
|
@@ -377,8 +411,8 @@ export default class StyleDictionary extends Register {
|
|
|
377
411
|
*/
|
|
378
412
|
async buildPlatform(platform) {
|
|
379
413
|
const { dictionary, platformConfig } = await this.getPlatform(platform);
|
|
380
|
-
buildFiles(dictionary, platformConfig);
|
|
381
|
-
performActions(dictionary, platformConfig);
|
|
414
|
+
buildFiles(dictionary, platformConfig, this.options);
|
|
415
|
+
performActions(dictionary, platformConfig, this.options);
|
|
382
416
|
// For chaining
|
|
383
417
|
return this;
|
|
384
418
|
}
|
|
@@ -400,7 +434,7 @@ export default class StyleDictionary extends Register {
|
|
|
400
434
|
const { dictionary, platformConfig } = await this.getPlatform(platform);
|
|
401
435
|
// We clean files first, then actions, ...and then directories?
|
|
402
436
|
cleanFiles(platformConfig);
|
|
403
|
-
cleanActions(dictionary, platformConfig);
|
|
437
|
+
cleanActions(dictionary, platformConfig, this.options);
|
|
404
438
|
cleanDirs(platformConfig);
|
|
405
439
|
// For chaining
|
|
406
440
|
return this;
|
package/lib/buildFile.d.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
3
3
|
* @typedef {import('../types/DesignToken.d.ts').TransformedToken} TransformedToken
|
|
4
4
|
* @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
5
|
+
* @typedef {import('../types/Config.d.ts').Config} Config
|
|
5
6
|
* @typedef {import('../types/File.d.ts').File} File
|
|
6
7
|
*/
|
|
7
8
|
/**
|
|
@@ -11,9 +12,11 @@
|
|
|
11
12
|
* @param {File} file
|
|
12
13
|
* @param {PlatformConfig} platform
|
|
13
14
|
* @param {Dictionary} dictionary
|
|
15
|
+
* @param {Config} options
|
|
14
16
|
*/
|
|
15
|
-
export default function buildFile(file: File, platform: import("../types/Config.d.ts").PlatformConfig | undefined, dictionary: Dictionary): null | undefined;
|
|
17
|
+
export default function buildFile(file: File, platform: import("../types/Config.d.ts").PlatformConfig | undefined, dictionary: Dictionary, options: Config): null | undefined;
|
|
16
18
|
export type Dictionary = import('../types/DesignToken.d.ts').Dictionary;
|
|
17
19
|
export type TransformedToken = import('../types/DesignToken.d.ts').TransformedToken;
|
|
18
20
|
export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
|
|
21
|
+
export type Config = import('../types/Config.d.ts').Config;
|
|
19
22
|
export type File = import('../types/File.d.ts').File;
|
package/lib/buildFile.js
CHANGED
|
@@ -23,6 +23,7 @@ import createFormatArgs from './utils/createFormatArgs.js';
|
|
|
23
23
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
24
24
|
* @typedef {import('../types/DesignToken.d.ts').TransformedToken} TransformedToken
|
|
25
25
|
* @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
26
|
+
* @typedef {import('../types/Config.d.ts').Config} Config
|
|
26
27
|
* @typedef {import('../types/File.d.ts').File} File
|
|
27
28
|
*/
|
|
28
29
|
|
|
@@ -33,8 +34,9 @@ import createFormatArgs from './utils/createFormatArgs.js';
|
|
|
33
34
|
* @param {File} file
|
|
34
35
|
* @param {PlatformConfig} platform
|
|
35
36
|
* @param {Dictionary} dictionary
|
|
37
|
+
* @param {Config} options
|
|
36
38
|
*/
|
|
37
|
-
export default function buildFile(file, platform = {}, dictionary) {
|
|
39
|
+
export default function buildFile(file, platform = {}, dictionary, options) {
|
|
38
40
|
const { destination, filter } = file || {};
|
|
39
41
|
let { format } = file || {};
|
|
40
42
|
|
|
@@ -56,7 +58,7 @@ export default function buildFile(file, platform = {}, dictionary) {
|
|
|
56
58
|
const dir = dirname(fullDestination);
|
|
57
59
|
if (!fs.existsSync(dir)) fs.mkdirSync(dir, { recursive: true });
|
|
58
60
|
|
|
59
|
-
const filteredTokens = filterTokens(dictionary, filter);
|
|
61
|
+
const filteredTokens = filterTokens(dictionary, filter, options);
|
|
60
62
|
const filteredDictionary = Object.assign({}, dictionary, {
|
|
61
63
|
tokens: filteredTokens.tokens,
|
|
62
64
|
allTokens: filteredTokens.allTokens,
|
|
@@ -98,7 +100,7 @@ export default function buildFile(file, platform = {}, dictionary) {
|
|
|
98
100
|
let collisions = nameCollisionObj[tokenName]
|
|
99
101
|
.map((token) => {
|
|
100
102
|
let tokenPathText = chalk.rgb(255, 69, 0)(token.path.join('.'));
|
|
101
|
-
let valueText = chalk.rgb(255, 140, 0)(token.$value
|
|
103
|
+
let valueText = chalk.rgb(255, 140, 0)(options.usesDtcg ? token.$value : token.value);
|
|
102
104
|
return tokenPathText + ' ' + valueText;
|
|
103
105
|
})
|
|
104
106
|
.join('\n ');
|
|
@@ -118,6 +120,7 @@ export default function buildFile(file, platform = {}, dictionary) {
|
|
|
118
120
|
createFormatArgs({
|
|
119
121
|
dictionary: filteredDictionary,
|
|
120
122
|
platform,
|
|
123
|
+
options,
|
|
121
124
|
file,
|
|
122
125
|
}),
|
|
123
126
|
),
|
package/lib/buildFiles.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
3
|
-
* @typedef {import('../types/Config.d.ts').PlatformConfig}
|
|
3
|
+
* @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
4
|
+
* @typedef {import('../types/Config.d.ts').Config} Config
|
|
4
5
|
*/
|
|
5
6
|
/**
|
|
6
7
|
* Takes a platform config object and a dictionary
|
|
@@ -9,8 +10,10 @@
|
|
|
9
10
|
* point.
|
|
10
11
|
* @memberOf StyleDictionary
|
|
11
12
|
* @param {Dictionary} dictionary
|
|
12
|
-
* @param {
|
|
13
|
+
* @param {PlatformConfig} platform
|
|
14
|
+
* @param {Config} options
|
|
13
15
|
*/
|
|
14
|
-
export default function buildFiles(dictionary: Dictionary, platform: Config): void;
|
|
16
|
+
export default function buildFiles(dictionary: Dictionary, platform: PlatformConfig, options: Config): void;
|
|
15
17
|
export type Dictionary = import('../types/DesignToken.d.ts').Dictionary;
|
|
16
|
-
export type
|
|
18
|
+
export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
|
|
19
|
+
export type Config = import('../types/Config.d.ts').Config;
|
package/lib/buildFiles.js
CHANGED
|
@@ -15,7 +15,8 @@ import buildFile from './buildFile.js';
|
|
|
15
15
|
|
|
16
16
|
/**
|
|
17
17
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
18
|
-
* @typedef {import('../types/Config.d.ts').PlatformConfig}
|
|
18
|
+
* @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
19
|
+
* @typedef {import('../types/Config.d.ts').Config} Config
|
|
19
20
|
*/
|
|
20
21
|
|
|
21
22
|
/**
|
|
@@ -25,9 +26,10 @@ import buildFile from './buildFile.js';
|
|
|
25
26
|
* point.
|
|
26
27
|
* @memberOf StyleDictionary
|
|
27
28
|
* @param {Dictionary} dictionary
|
|
28
|
-
* @param {
|
|
29
|
+
* @param {PlatformConfig} platform
|
|
30
|
+
* @param {Config} options
|
|
29
31
|
*/
|
|
30
|
-
export default function buildFiles(dictionary, platform) {
|
|
32
|
+
export default function buildFiles(dictionary, platform, options) {
|
|
31
33
|
if (
|
|
32
34
|
platform.buildPath &&
|
|
33
35
|
platform.buildPath.slice(-1) !== '/' &&
|
|
@@ -38,7 +40,7 @@ export default function buildFiles(dictionary, platform) {
|
|
|
38
40
|
|
|
39
41
|
platform.files?.forEach(function (file) {
|
|
40
42
|
if (file.format) {
|
|
41
|
-
buildFile(file, platform, dictionary);
|
|
43
|
+
buildFile(file, platform, dictionary, options);
|
|
42
44
|
} else {
|
|
43
45
|
throw new Error('Please supply a format');
|
|
44
46
|
}
|
package/lib/cleanActions.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
3
|
-
* @typedef {import('../types/Config.d.ts').PlatformConfig}
|
|
3
|
+
* @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
4
|
+
* @typedef {import('../types/Config.d.ts').Config} Config
|
|
4
5
|
*/
|
|
5
6
|
/**
|
|
6
7
|
* Performs the undo of any actions defined in a platform. Pretty
|
|
@@ -10,8 +11,10 @@
|
|
|
10
11
|
* @private
|
|
11
12
|
* @memberof module:style-dictionary
|
|
12
13
|
* @param {Dictionary} dictionary
|
|
13
|
-
* @param {
|
|
14
|
+
* @param {PlatformConfig} platform
|
|
15
|
+
* @param {Config} options
|
|
14
16
|
*/
|
|
15
|
-
export default function cleanActions(dictionary: Dictionary, platform: Config): void;
|
|
17
|
+
export default function cleanActions(dictionary: Dictionary, platform: PlatformConfig, options: Config): void;
|
|
16
18
|
export type Dictionary = import('../types/DesignToken.d.ts').Dictionary;
|
|
17
|
-
export type
|
|
19
|
+
export type PlatformConfig = import('../types/Config.d.ts').PlatformConfig;
|
|
20
|
+
export type Config = import('../types/Config.d.ts').Config;
|
package/lib/cleanActions.js
CHANGED
|
@@ -13,7 +13,8 @@
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {import('../types/DesignToken.d.ts').Dictionary} Dictionary
|
|
16
|
-
* @typedef {import('../types/Config.d.ts').PlatformConfig}
|
|
16
|
+
* @typedef {import('../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
17
|
+
* @typedef {import('../types/Config.d.ts').Config} Config
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -24,14 +25,15 @@
|
|
|
24
25
|
* @private
|
|
25
26
|
* @memberof module:style-dictionary
|
|
26
27
|
* @param {Dictionary} dictionary
|
|
27
|
-
* @param {
|
|
28
|
+
* @param {PlatformConfig} platform
|
|
29
|
+
* @param {Config} options
|
|
28
30
|
*/
|
|
29
|
-
export default function cleanActions(dictionary, platform) {
|
|
31
|
+
export default function cleanActions(dictionary, platform, options) {
|
|
30
32
|
if (platform.actions) {
|
|
31
33
|
platform.actions.forEach(function (action) {
|
|
32
34
|
// ensure we've augmented action with the do/undo functions and that undo exists
|
|
33
35
|
if (typeof action !== 'string' && typeof action.undo === 'function') {
|
|
34
|
-
action.undo(dictionary, platform);
|
|
36
|
+
action.undo(dictionary, platform, options);
|
|
35
37
|
}
|
|
36
38
|
});
|
|
37
39
|
}
|
package/lib/common/actions.js
CHANGED
|
@@ -31,7 +31,7 @@ export default {
|
|
|
31
31
|
* @memberof Actions
|
|
32
32
|
*/
|
|
33
33
|
'android/copyImages': {
|
|
34
|
-
do: function (dictionary, config) {
|
|
34
|
+
do: function (dictionary, config, options) {
|
|
35
35
|
const imagesDir = `${config.buildPath}android/main/res/drawable-`;
|
|
36
36
|
/**
|
|
37
37
|
* @param {Token} token
|
|
@@ -42,7 +42,7 @@ export default {
|
|
|
42
42
|
const dir = `${imagesDir}${token.attributes.state}`;
|
|
43
43
|
const path = `${dir}/${name}.png`;
|
|
44
44
|
fs.mkdirSync(dir, { recursive: true });
|
|
45
|
-
fs.copyFileSync(token.$value
|
|
45
|
+
fs.copyFileSync(options.usesDtcg ? token.$value : token.value, path);
|
|
46
46
|
}
|
|
47
47
|
});
|
|
48
48
|
},
|
|
@@ -27,15 +27,17 @@
|
|
|
27
27
|
* @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
|
|
28
28
|
* @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: prefix, indentation, separator, suffix, and commentStyle. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${token.value}${suffix}`
|
|
29
29
|
* @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
|
|
30
|
+
* @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
|
|
30
31
|
* @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
|
|
31
32
|
*/
|
|
32
|
-
export default function createPropertyFormatter({ outputReferences, outputReferenceFallbacks, dictionary, format, formatting, themeable, }: {
|
|
33
|
+
export default function createPropertyFormatter({ outputReferences, outputReferenceFallbacks, dictionary, format, formatting, themeable, usesDtcg, }: {
|
|
33
34
|
outputReferences?: boolean | undefined;
|
|
34
35
|
outputReferenceFallbacks?: boolean | undefined;
|
|
35
36
|
dictionary: Dictionary;
|
|
36
37
|
format?: string | undefined;
|
|
37
38
|
formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
|
|
38
39
|
themeable?: boolean | undefined;
|
|
40
|
+
usesDtcg?: boolean | undefined;
|
|
39
41
|
}): (token: import('../../../types/DesignToken.d.ts').TransformedToken) => string;
|
|
40
42
|
export type Dictionary = import('../../../types/DesignToken.d.ts').Dictionary;
|
|
41
43
|
export type Formatting = import('../../../types/File.d.ts').FormattingOptions;
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
|
|
11
11
|
* and limitations under the License.
|
|
12
12
|
*/
|
|
13
|
-
import
|
|
13
|
+
import { _getReferences } from '../../utils/references/getReferences.js';
|
|
14
14
|
import usesReferences from '../../utils/references/usesReferences.js';
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -113,6 +113,7 @@ function addComment(to_ret_token, comment, options) {
|
|
|
113
113
|
* @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
|
|
114
114
|
* @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: prefix, indentation, separator, suffix, and commentStyle. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${token.value}${suffix}`
|
|
115
115
|
* @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
|
|
116
|
+
* @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
|
|
116
117
|
* @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
|
|
117
118
|
*/
|
|
118
119
|
export default function createPropertyFormatter({
|
|
@@ -122,6 +123,7 @@ export default function createPropertyFormatter({
|
|
|
122
123
|
format,
|
|
123
124
|
formatting = {},
|
|
124
125
|
themeable = false,
|
|
126
|
+
usesDtcg = false,
|
|
125
127
|
}) {
|
|
126
128
|
/** @type {Formatting} */
|
|
127
129
|
const formatDefaults = {};
|
|
@@ -159,7 +161,7 @@ export default function createPropertyFormatter({
|
|
|
159
161
|
const { tokens, unfilteredTokens } = dictionary;
|
|
160
162
|
return function (token) {
|
|
161
163
|
let to_ret_token = `${indentation}${prefix}${token.name}${separator} `;
|
|
162
|
-
let value = token.$value
|
|
164
|
+
let value = usesDtcg ? token.$value : token.value;
|
|
163
165
|
|
|
164
166
|
/**
|
|
165
167
|
* A single value can have multiple references either by interpolation:
|
|
@@ -176,7 +178,7 @@ export default function createPropertyFormatter({
|
|
|
176
178
|
if (outputReferences && usesReferences(token.original.value)) {
|
|
177
179
|
// Formats that use this function expect `value` to be a string
|
|
178
180
|
// or else you will get '[object Object]' in the output
|
|
179
|
-
const refs =
|
|
181
|
+
const refs = _getReferences(token.original.value, tokens, { unfilteredTokens }, []);
|
|
180
182
|
|
|
181
183
|
// original can either be an object value, which requires transitive value transformation in web CSS formats
|
|
182
184
|
// or a different (primitive) type, meaning it can be stringified.
|
|
@@ -198,11 +200,8 @@ export default function createPropertyFormatter({
|
|
|
198
200
|
// because Style Dictionary resolved this in the resolution step.
|
|
199
201
|
// Here we are undoing that by replacing the value with
|
|
200
202
|
// the reference's name
|
|
201
|
-
if (
|
|
202
|
-
|
|
203
|
-
Object.hasOwn(ref, 'name')
|
|
204
|
-
) {
|
|
205
|
-
const refVal = ref.$value ?? ref.value;
|
|
203
|
+
if (Object.hasOwn(ref, `${usesDtcg ? '$' : ''}value`) && Object.hasOwn(ref, 'name')) {
|
|
204
|
+
const refVal = usesDtcg ? ref.$value : ref.value;
|
|
206
205
|
const replaceFunc = function () {
|
|
207
206
|
if (format === 'css') {
|
|
208
207
|
if (outputReferenceFallbacks) {
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
* @param {Boolean} [options.outputReferences] - Whether or not to output references
|
|
10
10
|
* @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. This will get passed to `formatHelpers.createPropertyFormatter` and used for the `lineSeparator` between lines of code.
|
|
11
11
|
* @param {Boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
|
|
12
|
+
* @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
|
|
12
13
|
* @returns {String}
|
|
13
14
|
* @example
|
|
14
15
|
* ```js
|
|
@@ -24,12 +25,13 @@
|
|
|
24
25
|
* });
|
|
25
26
|
* ```
|
|
26
27
|
*/
|
|
27
|
-
export default function formattedVariables({ format, dictionary, outputReferences, formatting, themeable, }: {
|
|
28
|
+
export default function formattedVariables({ format, dictionary, outputReferences, formatting, themeable, usesDtcg, }: {
|
|
28
29
|
format: string;
|
|
29
30
|
dictionary: Dictionary;
|
|
30
31
|
outputReferences?: boolean | undefined;
|
|
31
32
|
formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
|
|
32
33
|
themeable?: boolean | undefined;
|
|
34
|
+
usesDtcg?: boolean | undefined;
|
|
33
35
|
}): string;
|
|
34
36
|
export type Token = import('../../../types/DesignToken.d.ts').TransformedToken;
|
|
35
37
|
export type Tokens = import('../../../types/DesignToken.d.ts').TransformedTokens;
|