style-dictionary 3.7.3-rc.1 → 3.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -4
- 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/common/formats.js +35 -21
- package/lib/common/templates/flutter/class.dart.template +1 -1
- package/lib/common/transforms.js +15 -15
- package/lib/register/action.js +6 -6
- package/lib/register/filter.js +4 -4
- package/lib/register/format.js +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -280,11 +280,11 @@ const StyleDictionary = require('style-dictionary').extend('config.json');
|
|
|
280
280
|
StyleDictionary.registerTransform({
|
|
281
281
|
name: 'time/seconds',
|
|
282
282
|
type: 'value',
|
|
283
|
-
matcher: function(
|
|
284
|
-
return
|
|
283
|
+
matcher: function(token) {
|
|
284
|
+
return token.attributes.category === 'time';
|
|
285
285
|
},
|
|
286
|
-
transformer: function(
|
|
287
|
-
return (parseInt(
|
|
286
|
+
transformer: function(token) {
|
|
287
|
+
return (parseInt(token.original.value) / 1000).toString() + 's';
|
|
288
288
|
}
|
|
289
289
|
});
|
|
290
290
|
|
package/lib/common/formats.js
CHANGED
|
@@ -15,7 +15,18 @@ const fs = require('fs');
|
|
|
15
15
|
const path = require('path');
|
|
16
16
|
const _template = require('lodash/template');
|
|
17
17
|
const GroupMessages = require('../utils/groupMessages');
|
|
18
|
-
const {
|
|
18
|
+
const {
|
|
19
|
+
fileHeader,
|
|
20
|
+
formattedVariables,
|
|
21
|
+
getTypeScriptType,
|
|
22
|
+
iconsWithPrefix,
|
|
23
|
+
minifyDictionary,
|
|
24
|
+
sortByReference,
|
|
25
|
+
createPropertyFormatter,
|
|
26
|
+
sortByName,
|
|
27
|
+
setSwiftFileProperties,
|
|
28
|
+
setComposeObjectProperties
|
|
29
|
+
} = require('./formatHelpers');
|
|
19
30
|
|
|
20
31
|
const SASS_MAP_FORMAT_DEPRECATION_WARNINGS = GroupMessages.GROUP.SassMapFormatDeprecationWarnings;
|
|
21
32
|
|
|
@@ -140,7 +151,7 @@ module.exports = {
|
|
|
140
151
|
'scss/variables': function({dictionary, options, file}) {
|
|
141
152
|
const { outputReferences, themeable = false } = options;
|
|
142
153
|
return fileHeader({file, commentStyle: 'short'}) +
|
|
143
|
-
formattedVariables({format: 'sass', dictionary, outputReferences, themeable});
|
|
154
|
+
formattedVariables({format: 'sass', dictionary, outputReferences, themeable}) + '\n';
|
|
144
155
|
},
|
|
145
156
|
|
|
146
157
|
/**
|
|
@@ -175,7 +186,7 @@ module.exports = {
|
|
|
175
186
|
'less/variables': function({dictionary, options, file}) {
|
|
176
187
|
const { outputReferences } = options;
|
|
177
188
|
return fileHeader({file, commentStyle: 'short'}) +
|
|
178
|
-
formattedVariables({format: 'less', dictionary, outputReferences});
|
|
189
|
+
formattedVariables({format: 'less', dictionary, outputReferences}) + '\n';
|
|
179
190
|
},
|
|
180
191
|
|
|
181
192
|
/**
|
|
@@ -207,7 +218,7 @@ module.exports = {
|
|
|
207
218
|
'stylus/variables': function({dictionary, options, file}) {
|
|
208
219
|
const { outputReferences } = options;
|
|
209
220
|
return fileHeader({file, commentStyle: 'short'}) +
|
|
210
|
-
formattedVariables({format: 'stylus', dictionary, outputReferences});
|
|
221
|
+
formattedVariables({format: 'stylus', dictionary, outputReferences}) + '\n';
|
|
211
222
|
},
|
|
212
223
|
|
|
213
224
|
/**
|
|
@@ -231,7 +242,7 @@ module.exports = {
|
|
|
231
242
|
'javascript/module': function({dictionary, file}) {
|
|
232
243
|
return fileHeader({file}) +
|
|
233
244
|
'module.exports = ' +
|
|
234
|
-
JSON.stringify(dictionary.tokens, null, 2) + '
|
|
245
|
+
JSON.stringify(dictionary.tokens, null, 2) + ';\n';
|
|
235
246
|
},
|
|
236
247
|
|
|
237
248
|
/**
|
|
@@ -248,8 +259,9 @@ module.exports = {
|
|
|
248
259
|
*/
|
|
249
260
|
'javascript/module-flat': function({dictionary, file}) {
|
|
250
261
|
return fileHeader({file}) +
|
|
251
|
-
'module.exports = ' +
|
|
252
|
-
|
|
262
|
+
'module.exports = ' + '{\n' + dictionary.allTokens.map(function(token) {
|
|
263
|
+
return ` "${token.name}": ${JSON.stringify(token.value)}`;
|
|
264
|
+
}).join(',\n') + '\n}' + ';\n';
|
|
253
265
|
},
|
|
254
266
|
|
|
255
267
|
/**
|
|
@@ -277,7 +289,7 @@ module.exports = {
|
|
|
277
289
|
(file.name || '_styleDictionary') +
|
|
278
290
|
' = ' +
|
|
279
291
|
JSON.stringify(dictionary.tokens, null, 2) +
|
|
280
|
-
'
|
|
292
|
+
';\n';
|
|
281
293
|
},
|
|
282
294
|
|
|
283
295
|
/**
|
|
@@ -367,7 +379,7 @@ module.exports = {
|
|
|
367
379
|
if (token.comment)
|
|
368
380
|
to_ret = to_ret.concat(' // ' + token.comment);
|
|
369
381
|
return to_ret;
|
|
370
|
-
}).join('\n');
|
|
382
|
+
}).join('\n') + '\n';
|
|
371
383
|
},
|
|
372
384
|
|
|
373
385
|
// TypeScript declarations
|
|
@@ -407,11 +419,12 @@ module.exports = {
|
|
|
407
419
|
'typescript/es6-declarations': function({dictionary, file, options}) {
|
|
408
420
|
return fileHeader({file}) +
|
|
409
421
|
dictionary.allProperties.map(function(prop) {
|
|
410
|
-
|
|
422
|
+
let to_ret_prop = '';
|
|
411
423
|
if (prop.comment)
|
|
412
|
-
to_ret_prop
|
|
424
|
+
to_ret_prop += '/** ' + prop.comment + ' */\n';
|
|
425
|
+
to_ret_prop += 'export const ' + prop.name + ' : ' + getTypeScriptType(prop.value, options) + ';';
|
|
413
426
|
return to_ret_prop;
|
|
414
|
-
}).join('\n');
|
|
427
|
+
}).join('\n') + '\n';
|
|
415
428
|
},
|
|
416
429
|
|
|
417
430
|
/**
|
|
@@ -504,7 +517,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
504
517
|
|
|
505
518
|
// JSON stringify will quote strings, because this is a type we need
|
|
506
519
|
// it unquoted.
|
|
507
|
-
return output.replace(/"DesignToken"/g,'DesignToken');
|
|
520
|
+
return output.replace(/"DesignToken"/g, 'DesignToken') + '\n';
|
|
508
521
|
},
|
|
509
522
|
|
|
510
523
|
// Android templates
|
|
@@ -708,7 +721,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
708
721
|
* @param {String} className The name of the generated Kotlin object
|
|
709
722
|
* @param {String} packageName The package for the generated Kotlin object
|
|
710
723
|
* @param {Object} options
|
|
711
|
-
*
|
|
724
|
+
* @param {String[]} [options.import=['androidx.compose.ui.graphics.Color', 'androidx.compose.ui.unit.*']] - Modules to import. Can be a string or array of strings
|
|
712
725
|
* @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date
|
|
713
726
|
* @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
|
|
714
727
|
* @example
|
|
@@ -914,7 +927,8 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
914
927
|
* @kind member
|
|
915
928
|
* @param {Object} options
|
|
916
929
|
* @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object
|
|
917
|
-
* @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of
|
|
930
|
+
* @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of strings
|
|
931
|
+
* @param {String} [options.className] - The name of the generated Swift class
|
|
918
932
|
* @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date
|
|
919
933
|
* @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
|
|
920
934
|
* @example
|
|
@@ -955,7 +969,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
955
969
|
* @kind member
|
|
956
970
|
* @param {Object} options
|
|
957
971
|
* @param {String} [options.accessControl=public] - Level of [access](https://docs.swift.org/swift-book/LanguageGuide/AccessControl.html) of the generated swift object
|
|
958
|
-
* @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of
|
|
972
|
+
* @param {String[]} [options.import=UIKit] - Modules to import. Can be a string or array of strings
|
|
959
973
|
* @param {Boolean} [options.showFileHeader=true] - Whether or not to include a comment that has the build date
|
|
960
974
|
* @param {Boolean} [options.outputReferences=false] - Whether or not to keep [references](/#/formats?id=references-in-output-files) (a -> b -> c) in the output.
|
|
961
975
|
* @example
|
|
@@ -1073,7 +1087,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1073
1087
|
* ```
|
|
1074
1088
|
*/
|
|
1075
1089
|
'json': function({dictionary}) {
|
|
1076
|
-
return JSON.stringify(dictionary.tokens, null, 2);
|
|
1090
|
+
return JSON.stringify(dictionary.tokens, null, 2) + '\n';
|
|
1077
1091
|
},
|
|
1078
1092
|
|
|
1079
1093
|
/**
|
|
@@ -1115,7 +1129,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1115
1129
|
* ```
|
|
1116
1130
|
*/
|
|
1117
1131
|
'json/nested': function({dictionary}) {
|
|
1118
|
-
return JSON.stringify(minifyDictionary(dictionary.tokens), null, 2);
|
|
1132
|
+
return JSON.stringify(minifyDictionary(dictionary.tokens), null, 2) + '\n';
|
|
1119
1133
|
},
|
|
1120
1134
|
|
|
1121
1135
|
/**
|
|
@@ -1133,7 +1147,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1133
1147
|
'json/flat': function({dictionary}) {
|
|
1134
1148
|
return '{\n' + dictionary.allTokens.map(function(token) {
|
|
1135
1149
|
return ` "${token.name}": ${JSON.stringify(token.value)}`;
|
|
1136
|
-
|
|
1150
|
+
}).join(',\n') + '\n}' + '\n';
|
|
1137
1151
|
},
|
|
1138
1152
|
|
|
1139
1153
|
/**
|
|
@@ -1166,7 +1180,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1166
1180
|
.map(function(token) {
|
|
1167
1181
|
return token.value;
|
|
1168
1182
|
});
|
|
1169
|
-
return JSON.stringify(to_ret, null, 2);
|
|
1183
|
+
return JSON.stringify(to_ret, null, 2) + '\n';
|
|
1170
1184
|
},
|
|
1171
1185
|
|
|
1172
1186
|
/**
|
|
@@ -1200,7 +1214,7 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
|
|
|
1200
1214
|
}, token.value)
|
|
1201
1215
|
})
|
|
1202
1216
|
};
|
|
1203
|
-
return JSON.stringify(to_ret, null, 2);
|
|
1217
|
+
return JSON.stringify(to_ret, null, 2) + '\n';
|
|
1204
1218
|
},
|
|
1205
1219
|
|
|
1206
1220
|
|
package/lib/common/transforms.js
CHANGED
|
@@ -412,7 +412,7 @@ module.exports = {
|
|
|
412
412
|
* Transforms the value into a Color class for Compose
|
|
413
413
|
*
|
|
414
414
|
* ```kotlin
|
|
415
|
-
* // Matches:
|
|
415
|
+
* // Matches: token.attributes.category === 'color'
|
|
416
416
|
* // Returns:
|
|
417
417
|
* Color(0xFF009688)
|
|
418
418
|
* ```
|
|
@@ -422,8 +422,8 @@ module.exports = {
|
|
|
422
422
|
'color/composeColor': {
|
|
423
423
|
type: 'value',
|
|
424
424
|
matcher: isColor,
|
|
425
|
-
transformer: function (
|
|
426
|
-
var str = Color(
|
|
425
|
+
transformer: function (token) {
|
|
426
|
+
var str = Color(token.value).toHex8();
|
|
427
427
|
return 'Color(0x' + str.slice(6) + str.slice(0,6) + ')'
|
|
428
428
|
}
|
|
429
429
|
},
|
|
@@ -742,7 +742,7 @@ module.exports = {
|
|
|
742
742
|
* Transforms the value from a REM size on web into a scale-independent pixel (sp) value for font sizes in Compose. It WILL scale the number by a factor of 16 (or the value of 'basePxFontSize' on the platform in your config).
|
|
743
743
|
*
|
|
744
744
|
* ```kotlin
|
|
745
|
-
* // Matches:
|
|
745
|
+
* // Matches: token.attributes.category === 'size' && token.attributes.type === 'font'
|
|
746
746
|
* // Returns:
|
|
747
747
|
* "16.0.sp"
|
|
748
748
|
* ```
|
|
@@ -752,10 +752,10 @@ module.exports = {
|
|
|
752
752
|
'size/compose/remToSp': {
|
|
753
753
|
type: 'value',
|
|
754
754
|
matcher: isFontSize,
|
|
755
|
-
transformer: function(
|
|
756
|
-
const val = parseFloat(
|
|
755
|
+
transformer: function(token, options) {
|
|
756
|
+
const val = parseFloat(token.value);
|
|
757
757
|
const baseFont = getBasePxFontSize(options);
|
|
758
|
-
if (isNaN(val)) throwSizeError(
|
|
758
|
+
if (isNaN(val)) throwSizeError(token.name, token.value, 'sp');
|
|
759
759
|
return (val * baseFont).toFixed(2) + '.sp';
|
|
760
760
|
}
|
|
761
761
|
},
|
|
@@ -765,7 +765,7 @@ module.exports = {
|
|
|
765
765
|
* Transforms the value from a REM size on web into a density-independent pixel (dp) value for font sizes in Compose. It WILL scale the number by a factor of 16 (or the value of 'basePxFontSize' on the platform in your config).
|
|
766
766
|
*
|
|
767
767
|
* ```kotlin
|
|
768
|
-
* // Matches:
|
|
768
|
+
* // Matches: token.attributes.category === 'size' && token.attributes.type !== 'font'
|
|
769
769
|
* // Returns:
|
|
770
770
|
* "16.0.dp"
|
|
771
771
|
* ```
|
|
@@ -775,10 +775,10 @@ module.exports = {
|
|
|
775
775
|
'size/compose/remToDp': {
|
|
776
776
|
type: 'value',
|
|
777
777
|
matcher: isNotFontSize,
|
|
778
|
-
transformer: function(
|
|
779
|
-
const val = parseFloat(
|
|
778
|
+
transformer: function(token, options) {
|
|
779
|
+
const val = parseFloat(token.value);
|
|
780
780
|
const baseFont = getBasePxFontSize(options);
|
|
781
|
-
if (isNaN(val)) throwSizeError(
|
|
781
|
+
if (isNaN(val)) throwSizeError(token.name, token.value, 'dp');
|
|
782
782
|
return (val * baseFont).toFixed(2) + '.dp';
|
|
783
783
|
}
|
|
784
784
|
},
|
|
@@ -787,7 +787,7 @@ module.exports = {
|
|
|
787
787
|
* Adds the .em Compose extension to the end of a number. Does not scale the value
|
|
788
788
|
*
|
|
789
789
|
* ```kotlin
|
|
790
|
-
* // Matches:
|
|
790
|
+
* // Matches: token.attributes.category === 'size' && token.attributes.type === 'font'
|
|
791
791
|
* // Returns:
|
|
792
792
|
* "16.0em"
|
|
793
793
|
* ```
|
|
@@ -797,9 +797,9 @@ module.exports = {
|
|
|
797
797
|
'size/compose/em': {
|
|
798
798
|
type: 'value',
|
|
799
799
|
matcher: isFontSize,
|
|
800
|
-
transformer: function(
|
|
801
|
-
const val = parseFloat(
|
|
802
|
-
if (isNaN(val)) throwSizeError(
|
|
800
|
+
transformer: function(token) {
|
|
801
|
+
const val = parseFloat(token.value);
|
|
802
|
+
if (isNaN(val)) throwSizeError(token.name, token.value, 'em');
|
|
803
803
|
return val + '.em';
|
|
804
804
|
}
|
|
805
805
|
},
|
package/lib/register/action.js
CHANGED
|
@@ -46,15 +46,15 @@
|
|
|
46
46
|
* });
|
|
47
47
|
* ```
|
|
48
48
|
*/
|
|
49
|
-
function registerAction(
|
|
50
|
-
if (typeof
|
|
49
|
+
function registerAction(action) {
|
|
50
|
+
if (typeof action.name !== 'string')
|
|
51
51
|
throw new Error('name must be a string');
|
|
52
|
-
if (typeof
|
|
52
|
+
if (typeof action.do !== 'function')
|
|
53
53
|
throw new Error('do must be a function');
|
|
54
54
|
|
|
55
|
-
this.action[
|
|
56
|
-
do:
|
|
57
|
-
undo:
|
|
55
|
+
this.action[action.name] = {
|
|
56
|
+
do: action.do,
|
|
57
|
+
undo: action.undo
|
|
58
58
|
};
|
|
59
59
|
|
|
60
60
|
return this;
|
package/lib/register/filter.js
CHANGED
|
@@ -29,13 +29,13 @@
|
|
|
29
29
|
* })
|
|
30
30
|
* ```
|
|
31
31
|
*/
|
|
32
|
-
function registerFilter(
|
|
33
|
-
if (typeof
|
|
32
|
+
function registerFilter(filter) {
|
|
33
|
+
if (typeof filter.name !== 'string')
|
|
34
34
|
throw new Error('Can\'t register filter; filter.name must be a string');
|
|
35
|
-
if (typeof
|
|
35
|
+
if (typeof filter.matcher !== 'function')
|
|
36
36
|
throw new Error('Can\'t register filter; filter.matcher must be a function');
|
|
37
37
|
|
|
38
|
-
this.filter[
|
|
38
|
+
this.filter[filter.name] = filter.matcher;
|
|
39
39
|
|
|
40
40
|
return this;
|
|
41
41
|
}
|
package/lib/register/format.js
CHANGED
|
@@ -60,13 +60,13 @@
|
|
|
60
60
|
* })
|
|
61
61
|
* ```
|
|
62
62
|
*/
|
|
63
|
-
function registerFormat(
|
|
64
|
-
if (typeof
|
|
63
|
+
function registerFormat(format) {
|
|
64
|
+
if (typeof format.name !== 'string')
|
|
65
65
|
throw new Error('Can\'t register format; format.name must be a string');
|
|
66
|
-
if (typeof
|
|
66
|
+
if (typeof format.formatter !== 'function')
|
|
67
67
|
throw new Error('Can\'t register format; format.formatter must be a function');
|
|
68
68
|
|
|
69
|
-
this.format[
|
|
69
|
+
this.format[format.name] = format.formatter;
|
|
70
70
|
|
|
71
71
|
return this;
|
|
72
72
|
}
|