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
|
@@ -36,6 +36,7 @@ const defaultFormatting = {
|
|
|
36
36
|
* @param {Boolean} [options.outputReferences] - Whether or not to output references
|
|
37
37
|
* @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.
|
|
38
38
|
* @param {Boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
|
|
39
|
+
* @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
|
|
39
40
|
* @returns {String}
|
|
40
41
|
* @example
|
|
41
42
|
* ```js
|
|
@@ -57,6 +58,7 @@ export default function formattedVariables({
|
|
|
57
58
|
outputReferences = false,
|
|
58
59
|
formatting = {},
|
|
59
60
|
themeable = false,
|
|
61
|
+
usesDtcg = false,
|
|
60
62
|
}) {
|
|
61
63
|
// typecast, we know that by know the tokens have been transformed
|
|
62
64
|
let allTokens = /** @type {Token[]} */ (dictionary.allTokens);
|
|
@@ -87,6 +89,7 @@ export default function formattedVariables({
|
|
|
87
89
|
format,
|
|
88
90
|
formatting,
|
|
89
91
|
themeable,
|
|
92
|
+
usesDtcg,
|
|
90
93
|
}),
|
|
91
94
|
)
|
|
92
95
|
.filter(function (strVal) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
|
|
3
|
+
* @typedef {import('../../../types/Config.d.ts').Config} Config
|
|
3
4
|
*/
|
|
4
5
|
/**
|
|
5
6
|
* Given some value, returns a basic valid TypeScript type for that value.
|
|
@@ -22,11 +23,12 @@
|
|
|
22
23
|
* });
|
|
23
24
|
*```
|
|
24
25
|
* @param {any} value A value to check the type of.
|
|
25
|
-
* @param {Options & {outputStringLiterals?: boolean}} [options]
|
|
26
|
+
* @param {Options & Config & {outputStringLiterals?: boolean}} [options]
|
|
26
27
|
* @return {String} A valid name for a TypeScript type.
|
|
27
28
|
*
|
|
28
29
|
*/
|
|
29
|
-
export default function getTypeScriptType(value: any, options?: (import("../../../types/Config.d.ts").LocalOptions & {
|
|
30
|
+
export default function getTypeScriptType(value: any, options?: (import("../../../types/Config.d.ts").LocalOptions & import("../../../types/Config.d.ts").Config & {
|
|
30
31
|
outputStringLiterals?: boolean | undefined;
|
|
31
32
|
}) | undefined): string;
|
|
32
33
|
export type Options = import('../../../types/Config.d.ts').LocalOptions;
|
|
34
|
+
export type Config = import('../../../types/Config.d.ts').Config;
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
|
|
16
|
+
* @typedef {import('../../../types/Config.d.ts').Config} Config
|
|
16
17
|
*/
|
|
17
18
|
|
|
18
19
|
/**
|
|
@@ -36,7 +37,7 @@
|
|
|
36
37
|
* });
|
|
37
38
|
*```
|
|
38
39
|
* @param {any} value A value to check the type of.
|
|
39
|
-
* @param {Options & {outputStringLiterals?: boolean}} [options]
|
|
40
|
+
* @param {Options & Config & {outputStringLiterals?: boolean}} [options]
|
|
40
41
|
* @return {String} A valid name for a TypeScript type.
|
|
41
42
|
*
|
|
42
43
|
*/
|
|
@@ -45,7 +46,7 @@ export default function getTypeScriptType(value, options = {}) {
|
|
|
45
46
|
|
|
46
47
|
if (Array.isArray(value)) return getArrayType(value);
|
|
47
48
|
if (typeof value === 'object') return getObjectType(value);
|
|
48
|
-
if (outputStringLiterals && typeof value === 'string') return `"${value}"`;
|
|
49
|
+
if (outputStringLiterals && typeof value === 'string') return `"${value.replace(/"/g, '\\"')}"`;
|
|
49
50
|
if (['string', 'number', 'boolean'].includes(typeof value)) return typeof value;
|
|
50
51
|
|
|
51
52
|
return 'any';
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
|
|
3
3
|
* @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
|
|
4
|
+
* @typedef {import('../../../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
4
5
|
*/
|
|
5
6
|
/**
|
|
6
7
|
*
|
|
@@ -13,6 +14,7 @@
|
|
|
13
14
|
* @param {String} prefix - Character to prefix variable names, like '$' for Sass
|
|
14
15
|
* @param {Token[]} allTokens - allTokens array on the dictionary object passed to the formatter function.
|
|
15
16
|
* @param {Options} options - options object passed to the formatter function.
|
|
17
|
+
* @param {PlatformConfig} platform - platform specific options
|
|
16
18
|
* @returns {String}
|
|
17
19
|
* @example
|
|
18
20
|
* ```js
|
|
@@ -24,6 +26,7 @@
|
|
|
24
26
|
* });
|
|
25
27
|
* ```
|
|
26
28
|
*/
|
|
27
|
-
export default function iconsWithPrefix(prefix: string, allTokens: Token[], options: Options): string;
|
|
29
|
+
export default function iconsWithPrefix(prefix: string, allTokens: Token[], options: Options, platform: PlatformConfig): string;
|
|
28
30
|
export type Token = import('../../../types/DesignToken.d.ts').TransformedToken;
|
|
29
31
|
export type Options = import('../../../types/Config.d.ts').LocalOptions;
|
|
32
|
+
export type PlatformConfig = import('../../../types/Config.d.ts').PlatformConfig;
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
/**
|
|
15
15
|
* @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
|
|
16
16
|
* @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
|
|
17
|
+
* @typedef {import('../../../types/Config.d.ts').PlatformConfig} PlatformConfig
|
|
17
18
|
*/
|
|
18
19
|
|
|
19
20
|
/**
|
|
@@ -27,6 +28,7 @@
|
|
|
27
28
|
* @param {String} prefix - Character to prefix variable names, like '$' for Sass
|
|
28
29
|
* @param {Token[]} allTokens - allTokens array on the dictionary object passed to the formatter function.
|
|
29
30
|
* @param {Options} options - options object passed to the formatter function.
|
|
31
|
+
* @param {PlatformConfig} platform - platform specific options
|
|
30
32
|
* @returns {String}
|
|
31
33
|
* @example
|
|
32
34
|
* ```js
|
|
@@ -38,14 +40,15 @@
|
|
|
38
40
|
* });
|
|
39
41
|
* ```
|
|
40
42
|
*/
|
|
41
|
-
export default function iconsWithPrefix(prefix, allTokens, options) {
|
|
43
|
+
export default function iconsWithPrefix(prefix, allTokens, options, platform) {
|
|
42
44
|
return allTokens
|
|
43
45
|
.filter(function (token) {
|
|
44
46
|
return token.attributes?.category === 'content' && token.attributes.type === 'icon';
|
|
45
47
|
})
|
|
46
48
|
.map(function (token) {
|
|
47
|
-
const varName =
|
|
48
|
-
|
|
49
|
+
const varName =
|
|
50
|
+
prefix + token.name + ': ' + (options.usesDtcg ? token.$value : token.value) + ';';
|
|
51
|
+
const className = '.' + platform.prefix + '-icon.' + token.attributes?.item + ':before ';
|
|
49
52
|
const declaration = '{ content: ' + prefix + token.name + '; }';
|
|
50
53
|
return varName + '\n' + className + declaration;
|
|
51
54
|
})
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* @memberof module:formatHelpers
|
|
7
7
|
* @name minifyDictionary
|
|
8
8
|
* @param {Tokens} obj - The object to minify. You will most likely pass `dictionary.tokens` to it.
|
|
9
|
+
* @param {boolean} [usesDtcg] - Whether or not tokens are using DTCG syntax.
|
|
9
10
|
* @returns {Tokens}
|
|
10
11
|
* @example
|
|
11
12
|
* ```js
|
|
@@ -17,5 +18,5 @@
|
|
|
17
18
|
* });
|
|
18
19
|
* ```
|
|
19
20
|
*/
|
|
20
|
-
export default function minifyDictionary(obj: Tokens): Tokens;
|
|
21
|
+
export default function minifyDictionary(obj: Tokens, usesDtcg?: boolean | undefined): Tokens;
|
|
21
22
|
export type Tokens = import('../../../types/DesignToken.d.ts').TransformedTokens;
|
|
@@ -20,6 +20,7 @@
|
|
|
20
20
|
* @memberof module:formatHelpers
|
|
21
21
|
* @name minifyDictionary
|
|
22
22
|
* @param {Tokens} obj - The object to minify. You will most likely pass `dictionary.tokens` to it.
|
|
23
|
+
* @param {boolean} [usesDtcg] - Whether or not tokens are using DTCG syntax.
|
|
23
24
|
* @returns {Tokens}
|
|
24
25
|
* @example
|
|
25
26
|
* ```js
|
|
@@ -31,7 +32,7 @@
|
|
|
31
32
|
* });
|
|
32
33
|
* ```
|
|
33
34
|
*/
|
|
34
|
-
export default function minifyDictionary(obj) {
|
|
35
|
+
export default function minifyDictionary(obj, usesDtcg = false) {
|
|
35
36
|
if (typeof obj !== 'object' || Array.isArray(obj)) {
|
|
36
37
|
return obj;
|
|
37
38
|
}
|
|
@@ -39,12 +40,12 @@ export default function minifyDictionary(obj) {
|
|
|
39
40
|
/** @type {Tokens} */
|
|
40
41
|
const toRet = {};
|
|
41
42
|
|
|
42
|
-
if (Object.hasOwn(obj, '$
|
|
43
|
-
return obj.$value
|
|
43
|
+
if (Object.hasOwn(obj, `${usesDtcg ? '$' : ''}value`)) {
|
|
44
|
+
return usesDtcg ? obj.$value : obj.value;
|
|
44
45
|
} else {
|
|
45
46
|
for (const name in obj) {
|
|
46
47
|
if (Object.hasOwn(obj, name)) {
|
|
47
|
-
toRet[name] = minifyDictionary(obj[name]);
|
|
48
|
+
toRet[name] = minifyDictionary(obj[name], usesDtcg);
|
|
48
49
|
}
|
|
49
50
|
}
|
|
50
51
|
}
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
|
|
14
14
|
import usesReferences from '../../utils/references/usesReferences.js';
|
|
15
|
-
import
|
|
15
|
+
import { _getReferences } from '../../utils/references/getReferences.js';
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* @typedef {import('../../../types/DesignToken.d.ts').TransformedTokens} Tokens
|
|
@@ -57,10 +57,10 @@ export default function sortByReference(tokens, opts) {
|
|
|
57
57
|
if (a.original && usesReferences(a.original.value)) {
|
|
58
58
|
// Both a and b have references, we need to see if they reference each other
|
|
59
59
|
if (b.original && usesReferences(b.original.value)) {
|
|
60
|
-
const aRefs =
|
|
60
|
+
const aRefs = _getReferences(a.original.value, tokens, {
|
|
61
61
|
unfilteredTokens: opts?.unfilteredTokens,
|
|
62
62
|
});
|
|
63
|
-
const bRefs =
|
|
63
|
+
const bRefs = _getReferences(b.original.value, tokens, {
|
|
64
64
|
unfilteredTokens: opts?.unfilteredTokens,
|
|
65
65
|
});
|
|
66
66
|
|
package/lib/common/formats.js
CHANGED
|
@@ -83,11 +83,11 @@ const formats = {
|
|
|
83
83
|
*/
|
|
84
84
|
'css/variables': function ({ dictionary, options = {}, file }) {
|
|
85
85
|
const selector = options.selector ? options.selector : `:root`;
|
|
86
|
-
const { outputReferences } = options;
|
|
86
|
+
const { outputReferences, usesDtcg } = options;
|
|
87
87
|
return (
|
|
88
88
|
fileHeader({ file }) +
|
|
89
89
|
`${selector} {\n` +
|
|
90
|
-
formattedVariables({ format: 'css', dictionary, outputReferences }) +
|
|
90
|
+
formattedVariables({ format: 'css', dictionary, outputReferences, usesDtcg }) +
|
|
91
91
|
`\n}\n`
|
|
92
92
|
);
|
|
93
93
|
},
|
|
@@ -144,13 +144,13 @@ const formats = {
|
|
|
144
144
|
const mapTemplate = _template(scssMapDeep);
|
|
145
145
|
|
|
146
146
|
// Default the "themeable" option to true for backward compatibility.
|
|
147
|
-
const { outputReferences, themeable = true } = options;
|
|
147
|
+
const { outputReferences, themeable = true, usesDtcg } = options;
|
|
148
148
|
return (
|
|
149
149
|
'\n' +
|
|
150
150
|
fileHeader({ file, commentStyle: 'long' }) +
|
|
151
|
-
formattedVariables({ format: 'sass', dictionary, outputReferences, themeable }) +
|
|
151
|
+
formattedVariables({ format: 'sass', dictionary, outputReferences, themeable, usesDtcg }) +
|
|
152
152
|
'\n' +
|
|
153
|
-
mapTemplate({ dictionary, file })
|
|
153
|
+
mapTemplate({ dictionary, file, options })
|
|
154
154
|
);
|
|
155
155
|
},
|
|
156
156
|
|
|
@@ -173,10 +173,10 @@ const formats = {
|
|
|
173
173
|
* ```
|
|
174
174
|
*/
|
|
175
175
|
'scss/variables': function ({ dictionary, options, file }) {
|
|
176
|
-
const { outputReferences, themeable = false } = options;
|
|
176
|
+
const { outputReferences, themeable = false, usesDtcg } = options;
|
|
177
177
|
return (
|
|
178
178
|
fileHeader({ file, commentStyle: 'short' }) +
|
|
179
|
-
formattedVariables({ format: 'sass', dictionary, outputReferences, themeable }) +
|
|
179
|
+
formattedVariables({ format: 'sass', dictionary, outputReferences, themeable, usesDtcg }) +
|
|
180
180
|
'\n'
|
|
181
181
|
);
|
|
182
182
|
},
|
|
@@ -193,10 +193,10 @@ const formats = {
|
|
|
193
193
|
* .icon.email:before { content:$content-icon-email; }
|
|
194
194
|
* ```
|
|
195
195
|
*/
|
|
196
|
-
'scss/icons': function ({ dictionary, options, file }) {
|
|
196
|
+
'scss/icons': function ({ dictionary, options, file, platform }) {
|
|
197
197
|
return (
|
|
198
198
|
fileHeader({ file, commentStyle: 'short' }) +
|
|
199
|
-
iconsWithPrefix('$', dictionary.allTokens, options)
|
|
199
|
+
iconsWithPrefix('$', dictionary.allTokens, options, platform)
|
|
200
200
|
);
|
|
201
201
|
},
|
|
202
202
|
|
|
@@ -216,10 +216,10 @@ const formats = {
|
|
|
216
216
|
* ```
|
|
217
217
|
*/
|
|
218
218
|
'less/variables': function ({ dictionary, options, file }) {
|
|
219
|
-
const { outputReferences } = options;
|
|
219
|
+
const { outputReferences, usesDtcg } = options;
|
|
220
220
|
return (
|
|
221
221
|
fileHeader({ file, commentStyle: 'short' }) +
|
|
222
|
-
formattedVariables({ format: 'less', dictionary, outputReferences }) +
|
|
222
|
+
formattedVariables({ format: 'less', dictionary, outputReferences, usesDtcg }) +
|
|
223
223
|
'\n'
|
|
224
224
|
);
|
|
225
225
|
},
|
|
@@ -236,10 +236,10 @@ const formats = {
|
|
|
236
236
|
* .icon.email:before { content:\@content-icon-email; }
|
|
237
237
|
* ```
|
|
238
238
|
*/
|
|
239
|
-
'less/icons': function ({ dictionary, options, file }) {
|
|
239
|
+
'less/icons': function ({ dictionary, options, file, platform }) {
|
|
240
240
|
return (
|
|
241
241
|
fileHeader({ file, commentStyle: 'short' }) +
|
|
242
|
-
iconsWithPrefix('@', dictionary.allTokens, options)
|
|
242
|
+
iconsWithPrefix('@', dictionary.allTokens, options, platform)
|
|
243
243
|
);
|
|
244
244
|
},
|
|
245
245
|
|
|
@@ -256,10 +256,10 @@ const formats = {
|
|
|
256
256
|
* ```
|
|
257
257
|
*/
|
|
258
258
|
'stylus/variables': function ({ dictionary, options, file }) {
|
|
259
|
-
const { outputReferences } = options;
|
|
259
|
+
const { outputReferences, usesDtcg } = options;
|
|
260
260
|
return (
|
|
261
261
|
fileHeader({ file, commentStyle: 'short' }) +
|
|
262
|
-
formattedVariables({ format: 'stylus', dictionary, outputReferences }) +
|
|
262
|
+
formattedVariables({ format: 'stylus', dictionary, outputReferences, usesDtcg }) +
|
|
263
263
|
'\n'
|
|
264
264
|
);
|
|
265
265
|
},
|
|
@@ -305,14 +305,16 @@ const formats = {
|
|
|
305
305
|
*}
|
|
306
306
|
*```
|
|
307
307
|
*/
|
|
308
|
-
'javascript/module-flat': function ({ dictionary, file }) {
|
|
308
|
+
'javascript/module-flat': function ({ dictionary, file, options }) {
|
|
309
309
|
return (
|
|
310
310
|
fileHeader({ file }) +
|
|
311
311
|
'module.exports = ' +
|
|
312
312
|
'{\n' +
|
|
313
313
|
dictionary.allTokens
|
|
314
314
|
.map(function (token) {
|
|
315
|
-
return ` "${token.name}": ${JSON.stringify(
|
|
315
|
+
return ` "${token.name}": ${JSON.stringify(
|
|
316
|
+
options.usesDtcg ? token.$value : token.value,
|
|
317
|
+
)}`;
|
|
316
318
|
})
|
|
317
319
|
.join(',\n') +
|
|
318
320
|
'\n}' +
|
|
@@ -441,7 +443,7 @@ const formats = {
|
|
|
441
443
|
* export const ColorBackgroundAlt = '#fcfcfcfc';
|
|
442
444
|
* ```
|
|
443
445
|
*/
|
|
444
|
-
'javascript/es6': function ({ dictionary, file }) {
|
|
446
|
+
'javascript/es6': function ({ dictionary, file, options }) {
|
|
445
447
|
return (
|
|
446
448
|
fileHeader({ file }) +
|
|
447
449
|
dictionary.allTokens
|
|
@@ -450,7 +452,7 @@ const formats = {
|
|
|
450
452
|
'export const ' +
|
|
451
453
|
token.name +
|
|
452
454
|
' = ' +
|
|
453
|
-
JSON.stringify(token.$value
|
|
455
|
+
JSON.stringify(options.usesDtcg ? token.$value : token.value) +
|
|
454
456
|
';';
|
|
455
457
|
if (token.comment) to_ret = to_ret.concat(' // ' + token.comment);
|
|
456
458
|
return to_ret;
|
|
@@ -486,9 +488,7 @@ const formats = {
|
|
|
486
488
|
*
|
|
487
489
|
* @memberof Formats
|
|
488
490
|
* @kind member
|
|
489
|
-
* @
|
|
490
|
-
* @property {Boolean} [options.outputStringLiterals=false] - Whether or not to output literal types for string values
|
|
491
|
-
* @param {FormatOpts & { options?: typescriptEs6DeclarationsOpts }} options
|
|
491
|
+
* @param {FormatOpts} options
|
|
492
492
|
* @example
|
|
493
493
|
* ```typescript
|
|
494
494
|
* export const ColorBackgroundBase : string;
|
|
@@ -506,7 +506,7 @@ const formats = {
|
|
|
506
506
|
'export const ' +
|
|
507
507
|
token.name +
|
|
508
508
|
' : ' +
|
|
509
|
-
getTypeScriptType(token.$value
|
|
509
|
+
getTypeScriptType(options.usesDtcg ? token.$value : token.value, options) +
|
|
510
510
|
';';
|
|
511
511
|
return to_ret_token;
|
|
512
512
|
})
|
|
@@ -577,7 +577,8 @@ const formats = {
|
|
|
577
577
|
*/
|
|
578
578
|
function treeWalker(obj) {
|
|
579
579
|
let type = Object.create(null);
|
|
580
|
-
|
|
580
|
+
const propToCheck = options.usesDtcg ? '$value' : 'value';
|
|
581
|
+
if (Object.hasOwn(obj, propToCheck)) {
|
|
581
582
|
type = 'DesignToken';
|
|
582
583
|
} else {
|
|
583
584
|
for (let k in obj)
|
|
@@ -593,8 +594,7 @@ const formats = {
|
|
|
593
594
|
|
|
594
595
|
// TODO: find a browser+node compatible way to read from '../../types/DesignToken.d.ts'
|
|
595
596
|
const designTokenInterface = `interface DesignToken {
|
|
596
|
-
value?: any;
|
|
597
|
-
$value?: any;
|
|
597
|
+
${options.usesDtcg ? '$' : ''}value?: any;
|
|
598
598
|
name?: string;
|
|
599
599
|
comment?: string;
|
|
600
600
|
themeable?: boolean;
|
|
@@ -650,8 +650,8 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
650
650
|
* <dimen name="size_font_base">14sp</color>
|
|
651
651
|
* ```
|
|
652
652
|
*/
|
|
653
|
-
'android/resources': function ({ dictionary, file }) {
|
|
654
|
-
return androidResources({ dictionary, file, fileHeader });
|
|
653
|
+
'android/resources': function ({ dictionary, file, options }) {
|
|
654
|
+
return androidResources({ dictionary, file, fileHeader, options });
|
|
655
655
|
},
|
|
656
656
|
|
|
657
657
|
/**
|
|
@@ -834,7 +834,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
834
834
|
'compose/object': function ({ dictionary, options, file }) {
|
|
835
835
|
const { allTokens, tokens, unfilteredTokens } = dictionary;
|
|
836
836
|
const template = _template(composeObject);
|
|
837
|
-
const { outputReferences } = options;
|
|
837
|
+
const { outputReferences, usesDtcg } = options;
|
|
838
838
|
const formatProperty = createPropertyFormatter({
|
|
839
839
|
outputReferences,
|
|
840
840
|
dictionary,
|
|
@@ -842,6 +842,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
842
842
|
suffix: '',
|
|
843
843
|
commentStyle: 'none', // We will add the comment in the format template
|
|
844
844
|
},
|
|
845
|
+
usesDtcg,
|
|
845
846
|
});
|
|
846
847
|
|
|
847
848
|
let sortedTokens;
|
|
@@ -1027,7 +1028,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1027
1028
|
'ios-swift/class.swift': function ({ dictionary, options, file, platform }) {
|
|
1028
1029
|
const { allTokens, tokens, unfilteredTokens } = dictionary;
|
|
1029
1030
|
const template = _template(iosSwiftAny);
|
|
1030
|
-
const { outputReferences } = options;
|
|
1031
|
+
const { outputReferences, usesDtcg } = options;
|
|
1031
1032
|
options = setSwiftFileProperties(options, 'class', platform.transformGroup);
|
|
1032
1033
|
const formatProperty = createPropertyFormatter({
|
|
1033
1034
|
outputReferences,
|
|
@@ -1035,6 +1036,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1035
1036
|
formatting: {
|
|
1036
1037
|
suffix: '',
|
|
1037
1038
|
},
|
|
1039
|
+
usesDtcg,
|
|
1038
1040
|
});
|
|
1039
1041
|
|
|
1040
1042
|
let sortedTokens;
|
|
@@ -1068,7 +1070,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1068
1070
|
'ios-swift/enum.swift': function ({ dictionary, options, file, platform }) {
|
|
1069
1071
|
const { allTokens, tokens, unfilteredTokens } = dictionary;
|
|
1070
1072
|
const template = _template(iosSwiftAny);
|
|
1071
|
-
const { outputReferences } = options;
|
|
1073
|
+
const { outputReferences, usesDtcg } = options;
|
|
1072
1074
|
options = setSwiftFileProperties(options, 'enum', platform.transformGroup);
|
|
1073
1075
|
const formatProperty = createPropertyFormatter({
|
|
1074
1076
|
outputReferences,
|
|
@@ -1076,6 +1078,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1076
1078
|
formatting: {
|
|
1077
1079
|
suffix: '',
|
|
1078
1080
|
},
|
|
1081
|
+
usesDtcg,
|
|
1079
1082
|
});
|
|
1080
1083
|
|
|
1081
1084
|
let sortedTokens;
|
|
@@ -1119,7 +1122,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1119
1122
|
'ios-swift/any.swift': function ({ dictionary, options, file, platform }) {
|
|
1120
1123
|
const { allTokens, tokens, unfilteredTokens } = dictionary;
|
|
1121
1124
|
const template = _template(iosSwiftAny);
|
|
1122
|
-
const { outputReferences } = options;
|
|
1125
|
+
const { outputReferences, usesDtcg } = options;
|
|
1123
1126
|
options = setSwiftFileProperties(options, options.objectType, platform.transformGroup);
|
|
1124
1127
|
const formatProperty = createPropertyFormatter({
|
|
1125
1128
|
outputReferences,
|
|
@@ -1127,6 +1130,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1127
1130
|
formatting: {
|
|
1128
1131
|
suffix: '',
|
|
1129
1132
|
},
|
|
1133
|
+
usesDtcg,
|
|
1130
1134
|
});
|
|
1131
1135
|
|
|
1132
1136
|
let sortedTokens;
|
|
@@ -1214,8 +1218,8 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1214
1218
|
* }
|
|
1215
1219
|
* ```
|
|
1216
1220
|
*/
|
|
1217
|
-
'json/nested': function ({ dictionary }) {
|
|
1218
|
-
return JSON.stringify(minifyDictionary(dictionary.tokens), null, 2) + '\n';
|
|
1221
|
+
'json/nested': function ({ dictionary, options }) {
|
|
1222
|
+
return JSON.stringify(minifyDictionary(dictionary.tokens, options.usesDtcg), null, 2) + '\n';
|
|
1219
1223
|
},
|
|
1220
1224
|
|
|
1221
1225
|
/**
|
|
@@ -1231,12 +1235,14 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1231
1235
|
* }
|
|
1232
1236
|
* ```
|
|
1233
1237
|
*/
|
|
1234
|
-
'json/flat': function ({ dictionary }) {
|
|
1238
|
+
'json/flat': function ({ dictionary, options }) {
|
|
1235
1239
|
return (
|
|
1236
1240
|
'{\n' +
|
|
1237
1241
|
dictionary.allTokens
|
|
1238
1242
|
.map(function (token) {
|
|
1239
|
-
return ` "${token.name}": ${JSON.stringify(
|
|
1243
|
+
return ` "${token.name}": ${JSON.stringify(
|
|
1244
|
+
options.usesDtcg ? token.$value : token.value,
|
|
1245
|
+
)}`;
|
|
1240
1246
|
})
|
|
1241
1247
|
.join(',\n') +
|
|
1242
1248
|
'\n}' +
|
|
@@ -1263,7 +1269,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1263
1269
|
* }
|
|
1264
1270
|
* ```
|
|
1265
1271
|
*/
|
|
1266
|
-
'sketch/palette': function ({ dictionary }) {
|
|
1272
|
+
'sketch/palette': function ({ dictionary, options }) {
|
|
1267
1273
|
const to_ret = {
|
|
1268
1274
|
compatibleVersion: '1.0',
|
|
1269
1275
|
pluginVersion: '1.1',
|
|
@@ -1275,7 +1281,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1275
1281
|
return token.attributes?.category === 'color' && token.attributes.type === 'base';
|
|
1276
1282
|
})
|
|
1277
1283
|
.map(function (token) {
|
|
1278
|
-
return token.$value
|
|
1284
|
+
return options.usesDtcg ? token.$value : token.value;
|
|
1279
1285
|
});
|
|
1280
1286
|
return JSON.stringify(to_ret, null, 2) + '\n';
|
|
1281
1287
|
},
|
|
@@ -1301,7 +1307,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1301
1307
|
* }
|
|
1302
1308
|
* ```
|
|
1303
1309
|
*/
|
|
1304
|
-
'sketch/palette/v2': function ({ dictionary }) {
|
|
1310
|
+
'sketch/palette/v2': function ({ dictionary, options }) {
|
|
1305
1311
|
const to_ret = {
|
|
1306
1312
|
compatibleVersion: '2.0',
|
|
1307
1313
|
pluginVersion: '2.2',
|
|
@@ -1311,7 +1317,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1311
1317
|
{
|
|
1312
1318
|
name: token.name,
|
|
1313
1319
|
},
|
|
1314
|
-
token.$value
|
|
1320
|
+
options.usesDtcg ? token.$value : token.value,
|
|
1315
1321
|
);
|
|
1316
1322
|
}),
|
|
1317
1323
|
};
|
|
@@ -1343,10 +1349,11 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1343
1349
|
'flutter/class.dart': function ({ dictionary, options, file }) {
|
|
1344
1350
|
const { allTokens, tokens, unfilteredTokens } = dictionary;
|
|
1345
1351
|
const template = _template(flutterClassDart);
|
|
1346
|
-
const { outputReferences } = options;
|
|
1352
|
+
const { outputReferences, usesDtcg } = options;
|
|
1347
1353
|
const formatProperty = createPropertyFormatter({
|
|
1348
1354
|
outputReferences,
|
|
1349
1355
|
dictionary,
|
|
1356
|
+
usesDtcg,
|
|
1350
1357
|
});
|
|
1351
1358
|
|
|
1352
1359
|
let sortedTokens;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nconst tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'color';\n});\n%>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><color name=\"<%= token.name %>\"><%= token.$value
|
|
1
|
+
declare const _default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nconst tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'color';\n});\n%>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><color name=\"<%= token.name %>\"><%= options.usesDtcg ? token.$value : token.value %></color><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>\n <% }); %>\n</resources>";
|
|
2
2
|
export default _default;
|
|
@@ -21,6 +21,6 @@ const tokens = dictionary.allTokens.filter(function(token) {
|
|
|
21
21
|
<%= fileHeader({file, commentStyle: 'xml'}) %>
|
|
22
22
|
<resources>
|
|
23
23
|
<% tokens.forEach(function(token) {
|
|
24
|
-
%><color name="<%= token.name %>"><%= token.$value
|
|
24
|
+
%><color name="<%= token.name %>"><%= options.usesDtcg ? token.$value : token.value %></color><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>
|
|
25
25
|
<% }); %>
|
|
26
26
|
</resources>`;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nconst tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'size' && token.attributes.type !== 'font'\n}); %>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><dimen name=\"<%= token.name %>\"><%= token.$value
|
|
1
|
+
declare const _default: "xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nconst tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'size' && token.attributes.type !== 'font'\n}); %>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><dimen name=\"<%= token.name %>\"><%= options.usesDtcg ? token.$value : token.value %></dimen><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>\n <% }); %>\n</resources>";
|
|
2
2
|
export default _default;
|
|
@@ -20,6 +20,6 @@ const tokens = dictionary.allTokens.filter(function(token) {
|
|
|
20
20
|
<%= fileHeader({file, commentStyle: 'xml'}) %>
|
|
21
21
|
<resources>
|
|
22
22
|
<% tokens.forEach(function(token) {
|
|
23
|
-
%><dimen name="<%= token.name %>"><%= token.$value
|
|
23
|
+
%><dimen name="<%= token.name %>"><%= options.usesDtcg ? token.$value : token.value %></dimen><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>
|
|
24
24
|
<% }); %>
|
|
25
25
|
</resources>`;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nconst tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'size' && token.attributes.type === 'font';\n}); %>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><dimen name=\"<%= token.name %>\"><%= token.$value
|
|
1
|
+
declare const _default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nconst tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'size' && token.attributes.type === 'font';\n}); %>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><dimen name=\"<%= token.name %>\"><%= options.usesDtcg ? token.$value : token.value %></dimen><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>\n <% }); %>\n</resources>";
|
|
2
2
|
export default _default;
|
|
@@ -20,6 +20,6 @@ const tokens = dictionary.allTokens.filter(function(token) {
|
|
|
20
20
|
<%= fileHeader({file, commentStyle: 'xml'}) %>
|
|
21
21
|
<resources>
|
|
22
22
|
<% tokens.forEach(function(token) {
|
|
23
|
-
%><dimen name="<%= token.name %>"><%= token.$value
|
|
23
|
+
%><dimen name="<%= token.name %>"><%= options.usesDtcg ? token.$value : token.value %></dimen><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>
|
|
24
24
|
<% }); %>
|
|
25
25
|
</resources>`;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nvar tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'time';\n}); %>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><integer name=\"<%= token.name %>\"><%= token.$value
|
|
1
|
+
declare const _default: "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n<%\n//\n// Copyright 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.\n//\n// Licensed under the Apache License, Version 2.0 (the \"License\").\n// You may not use this file except in compliance with the License.\n// A copy of the License is located at\n//\n// http://www.apache.org/licenses/LICENSE-2.0\n//\n// or in the \"license\" file accompanying this file. This file is distributed\n// on an \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either\n// express or implied. See the License for the specific language governing\n// permissions and limitations under the License.\n\nvar tokens = dictionary.allTokens.filter(function(token) {\n return token.attributes.category === 'time';\n}); %>\n<%= fileHeader({file, commentStyle: 'xml'}) %>\n<resources>\n <% tokens.forEach(function(token) {\n %><integer name=\"<%= token.name %>\"><%= options.usesDtcg ? token.$value : token.value %></integer><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>\n <% }); %>\n</resources>";
|
|
2
2
|
export default _default;
|
|
@@ -20,6 +20,6 @@ var tokens = dictionary.allTokens.filter(function(token) {
|
|
|
20
20
|
<%= fileHeader({file, commentStyle: 'xml'}) %>
|
|
21
21
|
<resources>
|
|
22
22
|
<% tokens.forEach(function(token) {
|
|
23
|
-
%><integer name="<%= token.name %>"><%= token.$value
|
|
23
|
+
%><integer name="<%= token.name %>"><%= options.usesDtcg ? token.$value : token.value %></integer><% if (token.comment) { %><!-- <%= token.comment %> --><% } %>
|
|
24
24
|
<% }); %>
|
|
25
25
|
</resources>`;
|
|
@@ -2,10 +2,12 @@ declare function _default(opts: {
|
|
|
2
2
|
dictionary: Dictionary;
|
|
3
3
|
file?: File;
|
|
4
4
|
fileHeader?: FileHeader;
|
|
5
|
+
options: Config;
|
|
5
6
|
}): string;
|
|
6
7
|
export default _default;
|
|
7
8
|
export type Dictionary = import('../../../../types/DesignToken.d.ts').Dictionary;
|
|
8
9
|
export type Token = import('../../../../types/DesignToken.d.ts').TransformedToken;
|
|
9
10
|
export type Tokens = import('../../../../types/DesignToken.d.ts').TransformedTokens;
|
|
10
11
|
export type File = import('../../../../types/File.d.ts').File;
|
|
12
|
+
export type Config = import('../../../../types/Config.d.ts').Config;
|
|
11
13
|
export type FileHeader = typeof import("../../formatHelpers/fileHeader.js").default;
|
|
@@ -18,6 +18,7 @@ import { usesReferences, getReferences } from 'style-dictionary/utils';
|
|
|
18
18
|
* @typedef {import('../../../../types/DesignToken.d.ts').TransformedToken} Token
|
|
19
19
|
* @typedef {import('../../../../types/DesignToken.d.ts').TransformedTokens} Tokens
|
|
20
20
|
* @typedef {import('../../../../types/File.d.ts').File} File
|
|
21
|
+
* @typedef {import('../../../../types/Config.d.ts').Config} Config
|
|
21
22
|
* @typedef {import('../../formatHelpers/fileHeader.js').default} FileHeader
|
|
22
23
|
*/
|
|
23
24
|
|
|
@@ -26,10 +27,11 @@ import { usesReferences, getReferences } from 'style-dictionary/utils';
|
|
|
26
27
|
* dictionary: Dictionary;
|
|
27
28
|
* file?: File;
|
|
28
29
|
* fileHeader?: FileHeader;
|
|
30
|
+
* options: Config
|
|
29
31
|
* }} opts
|
|
30
32
|
*/
|
|
31
33
|
export default (opts) => {
|
|
32
|
-
const { file, fileHeader, dictionary } = opts;
|
|
34
|
+
const { file, fileHeader, dictionary, options } = opts;
|
|
33
35
|
|
|
34
36
|
const resourceType = file?.resourceType || null;
|
|
35
37
|
|
|
@@ -65,7 +67,7 @@ export default (opts) => {
|
|
|
65
67
|
if (file?.options && file.options.outputReferences && usesReferences(token.original.value)) {
|
|
66
68
|
return `@${tokenToType(token)}/${getReferences(token.original.value, tokens)[0].name}`;
|
|
67
69
|
} else {
|
|
68
|
-
return token.$value
|
|
70
|
+
return options.usesDtcg ? token.$value : token.value;
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
73
|
|