style-dictionary 4.1.3 → 4.2.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.
Files changed (175) hide show
  1. package/examples/advanced/assets-base64-embed/package.json +1 -1
  2. package/examples/advanced/create-react-app/package.json +1 -1
  3. package/examples/advanced/create-react-native-app/package.json +1 -1
  4. package/examples/advanced/custom-parser/package.json +1 -1
  5. package/examples/advanced/custom-transforms/package.json +1 -1
  6. package/examples/advanced/font-face-rules/package.json +1 -1
  7. package/examples/advanced/format-helpers/package.json +1 -1
  8. package/examples/advanced/matching-build-files/package.json +1 -1
  9. package/examples/advanced/multi-brand-multi-platform/package.json +1 -1
  10. package/examples/advanced/node-modules-as-config-and-properties/package.json +1 -1
  11. package/examples/advanced/npm-module/package.json +1 -1
  12. package/examples/advanced/referencing_aliasing/package.json +1 -1
  13. package/examples/advanced/s3/package.json +1 -1
  14. package/examples/advanced/tokens-deprecation/package.json +1 -1
  15. package/examples/advanced/transitive-transforms/package.json +1 -1
  16. package/examples/advanced/variables-in-outputs/package.json +1 -1
  17. package/examples/advanced/yaml-tokens/package.json +1 -1
  18. package/lib/Register.d.ts +12 -12
  19. package/lib/Register.js +8 -8
  20. package/lib/StyleDictionary.d.ts +24 -24
  21. package/lib/StyleDictionary.js +18 -16
  22. package/lib/cleanActions.d.ts +9 -9
  23. package/lib/cleanActions.js +4 -4
  24. package/lib/cleanDir.d.ts +7 -7
  25. package/lib/cleanDir.js +3 -3
  26. package/lib/cleanDirs.d.ts +5 -5
  27. package/lib/cleanDirs.js +2 -2
  28. package/lib/cleanFile.d.ts +7 -7
  29. package/lib/cleanFile.js +3 -3
  30. package/lib/cleanFiles.d.ts +5 -5
  31. package/lib/cleanFiles.js +2 -2
  32. package/lib/common/actions.d.ts +3 -3
  33. package/lib/common/actions.js +3 -3
  34. package/lib/common/filters.d.ts +1 -1
  35. package/lib/common/filters.js +1 -1
  36. package/lib/common/formatHelpers/createPropertyFormatter.d.ts +8 -8
  37. package/lib/common/formatHelpers/createPropertyFormatter.js +5 -5
  38. package/lib/common/formatHelpers/fileHeader.d.ts +7 -7
  39. package/lib/common/formatHelpers/fileHeader.js +4 -4
  40. package/lib/common/formatHelpers/formattedVariables.d.ts +7 -7
  41. package/lib/common/formatHelpers/formattedVariables.js +5 -5
  42. package/lib/common/formatHelpers/getTypeScriptType.d.ts +5 -5
  43. package/lib/common/formatHelpers/getTypeScriptType.js +2 -2
  44. package/lib/common/formatHelpers/iconsWithPrefix.d.ts +6 -6
  45. package/lib/common/formatHelpers/iconsWithPrefix.js +3 -3
  46. package/lib/common/formatHelpers/minifyDictionary.d.ts +2 -2
  47. package/lib/common/formatHelpers/minifyDictionary.js +1 -1
  48. package/lib/common/formatHelpers/setComposeObjectProperties.d.ts +2 -2
  49. package/lib/common/formatHelpers/setComposeObjectProperties.js +1 -1
  50. package/lib/common/formatHelpers/setSwiftFileProperties.d.ts +2 -2
  51. package/lib/common/formatHelpers/setSwiftFileProperties.js +1 -1
  52. package/lib/common/formatHelpers/sortByReference.d.ts +2 -2
  53. package/lib/common/formatHelpers/sortByReference.js +9 -4
  54. package/lib/common/formats.d.ts +9 -6
  55. package/lib/common/formats.js +121 -26
  56. package/lib/common/templates/android/colors.template.d.ts +3 -3
  57. package/lib/common/templates/android/colors.template.js +3 -3
  58. package/lib/common/templates/android/dimens.template.d.ts +3 -3
  59. package/lib/common/templates/android/dimens.template.js +3 -3
  60. package/lib/common/templates/android/fontDimens.template.d.ts +3 -3
  61. package/lib/common/templates/android/fontDimens.template.js +3 -3
  62. package/lib/common/templates/android/integers.template.d.ts +3 -3
  63. package/lib/common/templates/android/integers.template.js +3 -3
  64. package/lib/common/templates/android/resources.template.d.ts +6 -6
  65. package/lib/common/templates/android/resources.template.js +6 -6
  66. package/lib/common/templates/android/strings.template.d.ts +3 -3
  67. package/lib/common/templates/android/strings.template.js +3 -3
  68. package/lib/common/templates/compose/object.kt.template.d.ts +3 -3
  69. package/lib/common/templates/compose/object.kt.template.js +3 -3
  70. package/lib/common/templates/css/fonts.css.template.d.ts +1 -1
  71. package/lib/common/templates/css/fonts.css.template.js +1 -1
  72. package/lib/common/templates/flutter/class.dart.template.d.ts +4 -4
  73. package/lib/common/templates/flutter/class.dart.template.js +4 -4
  74. package/lib/common/templates/ios/colors.h.template.d.ts +4 -4
  75. package/lib/common/templates/ios/colors.h.template.js +4 -4
  76. package/lib/common/templates/ios/colors.m.template.d.ts +4 -4
  77. package/lib/common/templates/ios/colors.m.template.js +4 -4
  78. package/lib/common/templates/ios/macros.template.d.ts +4 -4
  79. package/lib/common/templates/ios/macros.template.js +4 -4
  80. package/lib/common/templates/ios/plist.template.d.ts +4 -4
  81. package/lib/common/templates/ios/plist.template.js +4 -4
  82. package/lib/common/templates/ios/singleton.h.template.d.ts +3 -3
  83. package/lib/common/templates/ios/singleton.h.template.js +3 -3
  84. package/lib/common/templates/ios/singleton.m.template.d.ts +6 -6
  85. package/lib/common/templates/ios/singleton.m.template.js +6 -6
  86. package/lib/common/templates/ios/static.h.template.d.ts +4 -4
  87. package/lib/common/templates/ios/static.h.template.js +4 -4
  88. package/lib/common/templates/ios/static.m.template.d.ts +4 -4
  89. package/lib/common/templates/ios/static.m.template.js +4 -4
  90. package/lib/common/templates/ios/strings.h.template.d.ts +4 -4
  91. package/lib/common/templates/ios/strings.h.template.js +4 -4
  92. package/lib/common/templates/ios/strings.m.template.d.ts +5 -5
  93. package/lib/common/templates/ios/strings.m.template.js +5 -5
  94. package/lib/common/templates/ios-swift/any.swift.template.d.ts +4 -4
  95. package/lib/common/templates/ios-swift/any.swift.template.js +4 -4
  96. package/lib/common/templates/scss/map-deep.template.d.ts +4 -4
  97. package/lib/common/templates/scss/map-deep.template.js +4 -4
  98. package/lib/common/templates/scss/map-flat.template.d.ts +3 -3
  99. package/lib/common/templates/scss/map-flat.template.js +3 -3
  100. package/lib/common/transformGroups.js +2 -2
  101. package/lib/common/transforms.d.ts +4 -4
  102. package/lib/common/transforms.js +4 -4
  103. package/lib/filterTokens.d.ts +6 -6
  104. package/lib/filterTokens.js +5 -5
  105. package/lib/fs-node.d.ts +2 -2
  106. package/lib/fs-node.js +1 -1
  107. package/lib/fs.d.ts +2 -2
  108. package/lib/fs.js +1 -1
  109. package/lib/performActions.d.ts +9 -9
  110. package/lib/performActions.js +4 -4
  111. package/lib/resolve.js +2 -1
  112. package/lib/transform/config.d.ts +4 -4
  113. package/lib/transform/config.js +4 -4
  114. package/lib/transform/object.d.ts +15 -15
  115. package/lib/transform/object.js +7 -7
  116. package/lib/transform/token.d.ts +13 -13
  117. package/lib/transform/token.js +6 -6
  118. package/lib/transform/tokenSetup.d.ts +4 -4
  119. package/lib/transform/tokenSetup.js +2 -2
  120. package/lib/utils/cleanActions.d.ts +23 -0
  121. package/lib/utils/cleanActions.js +44 -0
  122. package/lib/utils/combineJSON.d.ts +5 -5
  123. package/lib/utils/combineJSON.js +7 -6
  124. package/lib/utils/convertToBase64.d.ts +5 -5
  125. package/lib/utils/convertToBase64.js +32 -9
  126. package/lib/utils/convertToDTCG.d.ts +3 -3
  127. package/lib/utils/convertToDTCG.js +2 -2
  128. package/lib/utils/createFormatArgs.d.ts +8 -8
  129. package/lib/utils/createFormatArgs.js +4 -4
  130. package/lib/utils/deepExtend.d.ts +4 -4
  131. package/lib/utils/deepExtend.js +2 -2
  132. package/lib/utils/expandObjectTokens.d.ts +9 -9
  133. package/lib/utils/expandObjectTokens.js +7 -7
  134. package/lib/utils/flattenTokens.d.ts +2 -2
  135. package/lib/utils/flattenTokens.js +2 -2
  136. package/lib/utils/index.d.ts +2 -1
  137. package/lib/utils/index.js +2 -0
  138. package/lib/utils/isNode.d.ts +1 -0
  139. package/lib/utils/isNode.js +1 -0
  140. package/lib/utils/preprocess.d.ts +10 -8
  141. package/lib/utils/preprocess.js +5 -4
  142. package/lib/utils/references/createReferenceRegex.d.ts +2 -2
  143. package/lib/utils/references/createReferenceRegex.js +1 -1
  144. package/lib/utils/references/defaults.d.ts +1 -1
  145. package/lib/utils/references/defaults.js +1 -1
  146. package/lib/utils/references/getName.d.ts +3 -3
  147. package/lib/utils/references/getName.js +1 -1
  148. package/lib/utils/references/getReferences.d.ts +7 -7
  149. package/lib/utils/references/getReferences.js +3 -3
  150. package/lib/utils/references/getValueByPath.d.ts +4 -4
  151. package/lib/utils/references/getValueByPath.js +2 -2
  152. package/lib/utils/references/outputReferencesFilter.d.ts +4 -4
  153. package/lib/utils/references/outputReferencesFilter.js +2 -2
  154. package/lib/utils/references/outputReferencesTransformed.d.ts +4 -4
  155. package/lib/utils/references/outputReferencesTransformed.js +2 -2
  156. package/lib/utils/references/resolveReferences.d.ts +10 -10
  157. package/lib/utils/references/resolveReferences.js +4 -4
  158. package/lib/utils/references/usesReferences.d.ts +3 -3
  159. package/lib/utils/references/usesReferences.js +1 -1
  160. package/lib/utils/resolveObject.d.ts +4 -4
  161. package/lib/utils/resolveObject.js +3 -3
  162. package/lib/utils/stripMeta.d.ts +20 -0
  163. package/lib/utils/stripMeta.js +51 -0
  164. package/lib/utils/typeDtcgDelegate.d.ts +6 -6
  165. package/lib/utils/typeDtcgDelegate.js +3 -3
  166. package/package.json +5 -2
  167. package/types/Action.d.ts +3 -3
  168. package/types/Config.d.ts +8 -8
  169. package/types/File.d.ts +4 -4
  170. package/types/Filter.d.ts +2 -2
  171. package/types/Format.d.ts +3 -3
  172. package/types/Parser.d.ts +1 -1
  173. package/types/Preprocessor.d.ts +3 -3
  174. package/types/Transform.d.ts +4 -4
  175. package/types/index.d.ts +10 -10
@@ -37,18 +37,18 @@ export function addComment(to_ret_token: string, comment: string, options: Forma
37
37
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: `prefix`, `indentation`, `separator`, `suffix`, `lineSeparator`, `fileHeaderTimestamp`, `header`, `footer`, `commentStyle` and `commentPosition`. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${prop.value}${suffix}`. The remaining formatting options are used for the fileHeader helper.
38
38
  * @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
39
39
  * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
40
- * @returns {(token: import('../../../types/DesignToken.ts').TransformedToken) => string}
40
+ * @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
41
41
  */
42
42
  export default function createPropertyFormatter({ outputReferences, outputReferenceFallbacks, dictionary, format, formatting, themeable, usesDtcg, }: {
43
- outputReferences?: import("../../../types/Format.ts").OutputReferences | undefined;
43
+ outputReferences?: import("../../../types/Format.d.ts").OutputReferences | undefined;
44
44
  outputReferenceFallbacks?: boolean | undefined;
45
45
  dictionary: Dictionary;
46
46
  format?: string | undefined;
47
- formatting?: import("../../../types/File.ts").FormattingOptions | undefined;
47
+ formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
48
48
  themeable?: boolean | undefined;
49
49
  usesDtcg?: boolean | undefined;
50
- }): (token: import("../../../types/DesignToken.ts").TransformedToken) => string;
51
- export type TransformedToken = import("../../../types/DesignToken.ts").TransformedToken;
52
- export type Dictionary = import("../../../types/DesignToken.ts").Dictionary;
53
- export type Formatting = import("../../../types/File.ts").FormattingOptions;
54
- export type OutputReferences = import("../../../types/Format.ts").OutputReferences;
50
+ }): (token: import("../../../types/DesignToken.d.ts").TransformedToken) => string;
51
+ export type TransformedToken = import("../../../types/DesignToken.d.ts").TransformedToken;
52
+ export type Dictionary = import("../../../types/DesignToken.d.ts").Dictionary;
53
+ export type Formatting = import("../../../types/File.d.ts").FormattingOptions;
54
+ export type OutputReferences = import("../../../types/Format.d.ts").OutputReferences;
@@ -14,10 +14,10 @@ import { getReferences } from '../../utils/references/getReferences.js';
14
14
  import usesReferences from '../../utils/references/usesReferences.js';
15
15
 
16
16
  /**
17
- * @typedef {import('../../../types/DesignToken.ts').TransformedToken} TransformedToken
18
- * @typedef {import('../../../types/DesignToken.ts').Dictionary} Dictionary
19
- * @typedef {import('../../../types/File.ts').FormattingOptions} Formatting
20
- * @typedef {import('../../../types/Format.ts').OutputReferences} OutputReferences
17
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} TransformedToken
18
+ * @typedef {import('../../../types/DesignToken.d.ts').Dictionary} Dictionary
19
+ * @typedef {import('../../../types/File.d.ts').FormattingOptions} Formatting
20
+ * @typedef {import('../../../types/Format.d.ts').OutputReferences} OutputReferences
21
21
  */
22
22
 
23
23
  /**
@@ -116,7 +116,7 @@ export function addComment(to_ret_token, comment, options) {
116
116
  * @param {Formatting} [options.formatting] - Custom formatting properties that define parts of a declaration line in code. The configurable strings are: `prefix`, `indentation`, `separator`, `suffix`, `lineSeparator`, `fileHeaderTimestamp`, `header`, `footer`, `commentStyle` and `commentPosition`. Those are used to generate a line like this: `${indentation}${prefix}${token.name}${separator} ${prop.value}${suffix}`. The remaining formatting options are used for the fileHeader helper.
117
117
  * @param {boolean} [options.themeable] [false] - Whether tokens should default to being themeable.
118
118
  * @param {boolean} [options.usesDtcg] [false] - Whether DTCG token syntax should be uses.
119
- * @returns {(token: import('../../../types/DesignToken.ts').TransformedToken) => string}
119
+ * @returns {(token: import('../../../types/DesignToken.d.ts').TransformedToken) => string}
120
120
  */
121
121
  export default function createPropertyFormatter({
122
122
  outputReferences = false,
@@ -24,12 +24,12 @@
24
24
  * ```
25
25
  */
26
26
  export default function fileHeader({ file, commentStyle, formatting, options }: {
27
- file?: import("../../../types/File.ts").File | undefined;
27
+ file?: import("../../../types/File.d.ts").File | undefined;
28
28
  commentStyle?: "short" | "long" | "xml" | undefined;
29
- formatting?: import("../../../types/File.ts").FormattingOptions | undefined;
30
- options?: import("../../../types/Config.ts").Config | undefined;
29
+ formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
30
+ options?: import("../../../types/Config.d.ts").Config | undefined;
31
31
  }): Promise<string>;
32
- export type File = import("../../../types/File.ts").File;
33
- export type FileHeader = import("../../../types/File.ts").FileHeader;
34
- export type Formatting = import("../../../types/File.ts").FormattingOptions;
35
- export type Config = import("../../../types/Config.ts").Config;
32
+ export type File = import("../../../types/File.d.ts").File;
33
+ export type FileHeader = import("../../../types/File.d.ts").FileHeader;
34
+ export type Formatting = import("../../../types/File.d.ts").FormattingOptions;
35
+ export type Config = import("../../../types/Config.d.ts").Config;
@@ -13,10 +13,10 @@
13
13
 
14
14
  /**
15
15
  *
16
- * @typedef {import('../../../types/File.ts').File} File
17
- * @typedef {import('../../../types/File.ts').FileHeader} FileHeader
18
- * @typedef {import('../../../types/File.ts').FormattingOptions} Formatting
19
- * @typedef {import('../../../types/Config.ts').Config} Config
16
+ * @typedef {import('../../../types/File.d.ts').File} File
17
+ * @typedef {import('../../../types/File.d.ts').FileHeader} FileHeader
18
+ * @typedef {import('../../../types/File.d.ts').FormattingOptions} Formatting
19
+ * @typedef {import('../../../types/Config.d.ts').Config} Config
20
20
  */
21
21
 
22
22
  const lineSeparator = `\n`;
@@ -29,14 +29,14 @@
29
29
  export default function formattedVariables({ format, dictionary, outputReferences, outputReferenceFallbacks, formatting, themeable, usesDtcg, }: {
30
30
  format: string;
31
31
  dictionary: Dictionary;
32
- outputReferences?: import("../../../types/Format").OutputReferences | undefined;
32
+ outputReferences?: import("../../../types/Format.d.ts").OutputReferences | undefined;
33
33
  outputReferenceFallbacks?: boolean | undefined;
34
- formatting?: import("../../../types/File.ts").FormattingOptions | undefined;
34
+ formatting?: import("../../../types/File.d.ts").FormattingOptions | undefined;
35
35
  themeable?: boolean | undefined;
36
36
  usesDtcg?: boolean | undefined;
37
37
  }): string;
38
- export type Token = import("../../../types/DesignToken.ts").TransformedToken;
39
- export type Tokens = import("../../../types/DesignToken.ts").TransformedTokens;
40
- export type Formatting = import("../../../types/File.ts").FormattingOptions;
41
- export type OutputReferences = import("../../../types/Format").OutputReferences;
42
- export type Dictionary = import("../../../types/DesignToken.ts").Dictionary;
38
+ export type Token = import("../../../types/DesignToken.d.ts").TransformedToken;
39
+ export type Tokens = import("../../../types/DesignToken.d.ts").TransformedTokens;
40
+ export type Formatting = import("../../../types/File.d.ts").FormattingOptions;
41
+ export type OutputReferences = import("../../../types/Format.d.ts").OutputReferences;
42
+ export type Dictionary = import("../../../types/DesignToken.d.ts").Dictionary;
@@ -15,11 +15,11 @@ import createPropertyFormatter from './createPropertyFormatter.js';
15
15
  import sortByReference from './sortByReference.js';
16
16
 
17
17
  /**
18
- * @typedef {import('../../../types/DesignToken.ts').TransformedToken} Token
19
- * @typedef {import('../../../types/DesignToken.ts').TransformedTokens} Tokens
20
- * @typedef {import('../../../types/File.ts').FormattingOptions} Formatting
21
- * @typedef {import('../../../types/Format').OutputReferences} OutputReferences
22
- * @typedef {import('../../../types/DesignToken.ts').Dictionary} Dictionary
18
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
19
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedTokens} Tokens
20
+ * @typedef {import('../../../types/File.d.ts').FormattingOptions} Formatting
21
+ * @typedef {import('../../../types/Format.d.ts').OutputReferences} OutputReferences
22
+ * @typedef {import('../../../types/DesignToken.d.ts').Dictionary} Dictionary
23
23
  */
24
24
 
25
25
  const defaultFormatting = {
@@ -1,6 +1,6 @@
1
1
  /**
2
- * @typedef {import('../../../types/Config.ts').LocalOptions} Options
3
- * @typedef {import('../../../types/Config.ts').Config} Config
2
+ * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
3
+ * @typedef {import('../../../types/Config.d.ts').Config} Config
4
4
  */
5
5
  /**
6
6
  * Given some value, returns a basic valid TypeScript type for that value.
@@ -27,8 +27,8 @@
27
27
  * @return {String} A valid name for a TypeScript type.
28
28
  *
29
29
  */
30
- export default function getTypeScriptType(value: any, options?: (import("../../../types/Config.ts").Config & {
30
+ export default function getTypeScriptType(value: any, options?: (import("../../../types/Config.d.ts").Config & {
31
31
  outputStringLiterals?: boolean;
32
32
  }) | undefined): string;
33
- export type Options = import("../../../types/Config.ts").LocalOptions;
34
- export type Config = import("../../../types/Config.ts").Config;
33
+ export type Options = import("../../../types/Config.d.ts").LocalOptions;
34
+ export type Config = import("../../../types/Config.d.ts").Config;
@@ -12,8 +12,8 @@
12
12
  */
13
13
 
14
14
  /**
15
- * @typedef {import('../../../types/Config.ts').LocalOptions} Options
16
- * @typedef {import('../../../types/Config.ts').Config} Config
15
+ * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
16
+ * @typedef {import('../../../types/Config.d.ts').Config} Config
17
17
  */
18
18
 
19
19
  /**
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @typedef {import('../../../types/DesignToken.ts').TransformedToken} Token
3
- * @typedef {import('../../../types/Config.ts').Config} Options
4
- * @typedef {import('../../../types/Config.ts').PlatformConfig} PlatformConfig
2
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
3
+ * @typedef {import('../../../types/Config.d.ts').Config} Options
4
+ * @typedef {import('../../../types/Config.d.ts').PlatformConfig} PlatformConfig
5
5
  */
6
6
  /**
7
7
  *
@@ -27,6 +27,6 @@
27
27
  * ```
28
28
  */
29
29
  export default function iconsWithPrefix(prefix: string, allTokens: Token[], options: Options, platform: PlatformConfig): string;
30
- export type Token = import("../../../types/DesignToken.ts").TransformedToken;
31
- export type Options = import("../../../types/Config.ts").Config;
32
- export type PlatformConfig = import("../../../types/Config.ts").PlatformConfig;
30
+ export type Token = import("../../../types/DesignToken.d.ts").TransformedToken;
31
+ export type Options = import("../../../types/Config.d.ts").Config;
32
+ export type PlatformConfig = import("../../../types/Config.d.ts").PlatformConfig;
@@ -12,9 +12,9 @@
12
12
  */
13
13
 
14
14
  /**
15
- * @typedef {import('../../../types/DesignToken.ts').TransformedToken} Token
16
- * @typedef {import('../../../types/Config.ts').Config} Options
17
- * @typedef {import('../../../types/Config.ts').PlatformConfig} PlatformConfig
15
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
16
+ * @typedef {import('../../../types/Config.d.ts').Config} Options
17
+ * @typedef {import('../../../types/Config.d.ts').PlatformConfig} PlatformConfig
18
18
  */
19
19
 
20
20
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {import('../../../types/DesignToken.ts').TransformedTokens} Tokens
2
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedTokens} Tokens
3
3
  */
4
4
  /**
5
5
  * Outputs an object stripping out everything except values
@@ -19,4 +19,4 @@
19
19
  * ```
20
20
  */
21
21
  export default function minifyDictionary(obj: Tokens, usesDtcg?: boolean | undefined): Tokens;
22
- export type Tokens = import("../../../types/DesignToken.ts").TransformedTokens;
22
+ export type Tokens = import("../../../types/DesignToken.d.ts").TransformedTokens;
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  /**
15
- * @typedef {import('../../../types/DesignToken.ts').TransformedTokens} Tokens
15
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedTokens} Tokens
16
16
  */
17
17
 
18
18
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {import('../../../types/Config.ts').LocalOptions} Options
2
+ * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
3
3
  */
4
4
  /**
5
5
  * Outputs an object for compose format configurations. Sets import.
@@ -11,4 +11,4 @@
11
11
  export default function setComposeObjectProperties(options?: {
12
12
  import?: string[];
13
13
  } | undefined): Object;
14
- export type Options = import("../../../types/Config.ts").LocalOptions;
14
+ export type Options = import("../../../types/Config.d.ts").LocalOptions;
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  /**
15
- * @typedef {import('../../../types/Config.ts').LocalOptions} Options
15
+ * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
16
16
  */
17
17
 
18
18
  /**
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @typedef {import('../../../types/Config.ts').LocalOptions} Options
2
+ * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
3
3
  */
4
4
  /**
5
5
  * Outputs an object with swift format configurations. Sets import, object type and access control.
@@ -18,4 +18,4 @@ export default function setSwiftFileProperties(options: {
18
18
  import?: string[];
19
19
  accessControl?: string;
20
20
  };
21
- export type Options = import("../../../types/Config.ts").LocalOptions;
21
+ export type Options = import("../../../types/Config.d.ts").LocalOptions;
@@ -12,7 +12,7 @@
12
12
  */
13
13
 
14
14
  /**
15
- * @typedef {import('../../../types/Config.ts').LocalOptions} Options
15
+ * @typedef {import('../../../types/Config.d.ts').LocalOptions} Options
16
16
  */
17
17
 
18
18
  /**
@@ -17,5 +17,5 @@ export default function sortByReference(tokens: Tokens, { unfilteredTokens, uses
17
17
  unfilteredTokens?: Tokens;
18
18
  usesDtcg?: boolean;
19
19
  } | undefined): (a: Token, b: Token) => number;
20
- export type Tokens = import("../../../types/DesignToken.ts").TransformedTokens;
21
- export type Token = import("../../../types/DesignToken.ts").TransformedToken;
20
+ export type Tokens = import("../../../types/DesignToken.d.ts").TransformedTokens;
21
+ export type Token = import("../../../types/DesignToken.d.ts").TransformedToken;
@@ -15,8 +15,8 @@ import usesReferences from '../../utils/references/usesReferences.js';
15
15
  import { getReferences } from '../../utils/references/getReferences.js';
16
16
 
17
17
  /**
18
- * @typedef {import('../../../types/DesignToken.ts').TransformedTokens} Tokens
19
- * @typedef {import('../../../types/DesignToken.ts').TransformedToken} Token
18
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedTokens} Tokens
19
+ * @typedef {import('../../../types/DesignToken.d.ts').TransformedToken} Token
20
20
  */
21
21
 
22
22
  const A_COMES_FIRST = -1;
@@ -88,8 +88,13 @@ export default function sortByReference(tokens, { unfilteredTokens, usesDtcg } =
88
88
  return B_COMES_FIRST;
89
89
  }
90
90
 
91
- // 'a' doesn't reference. It should come first regardless of 'b'
92
- return A_COMES_FIRST;
91
+ // 'b' references, 'a' doesn't -> 'a' should come first
92
+ if (bUsesRefs) {
93
+ return A_COMES_FIRST;
94
+ }
95
+
96
+ // no references, keep existing order
97
+ return 0;
93
98
  }
94
99
 
95
100
  return sorter;
@@ -1,10 +1,13 @@
1
1
  export default formats;
2
- export type Format = import("../../types/Format.ts").Format;
3
- export type FormatArgs = import("../../types/Format.ts").FormatFnArguments;
4
- export type FormattingOverrides = import("../../types/File").FormattingOverrides;
5
- export type OutputReferences = import("../../types/Format.ts").OutputReferences;
6
- export type Token = import("../../types/DesignToken.ts").TransformedToken;
7
- export type Tokens = import("../../types/DesignToken.ts").TransformedTokens;
2
+ export type Format = import("../../types/Format.d.ts").Format;
3
+ export type FormatArgs = import("../../types/Format.d.ts").FormatFnArguments;
4
+ export type FormattingOverrides = import("../../types/File.d.ts").FormattingOverrides;
5
+ export type OutputReferences = import("../../types/Format.d.ts").OutputReferences;
6
+ export type Token = import("../../types/DesignToken.d.ts").TransformedToken;
7
+ export type Tokens = import("../../types/DesignToken.d.ts").TransformedTokens;
8
+ export type Config = import("../../types/Config.d.ts").Config;
9
+ export type LocalOptions = import("../../types/Config.d.ts").LocalOptions;
10
+ export type StripMetaOptions = import("../utils/stripMeta.js").StripMetaOptions;
8
11
  /**
9
12
  * @type {Record<string, Format['format']>}
10
13
  */
@@ -10,6 +10,11 @@
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 * as prettier from 'prettier/standalone';
14
+ import prettierPluginBabel from 'prettier/plugins/babel';
15
+ import prettierPluginEstree from 'prettier/plugins/estree';
16
+ import prettierPluginTypescript from 'prettier/plugins/typescript';
17
+
13
18
  import {
14
19
  fileHeader,
15
20
  formattedVariables,
@@ -23,6 +28,8 @@ import {
23
28
  setComposeObjectProperties,
24
29
  } from './formatHelpers/index.js';
25
30
 
31
+ import { stripMeta as stripMetaUtil } from '../utils/stripMeta.js';
32
+
26
33
  import androidColors from './templates/android/colors.template.js';
27
34
  import androidDimens from './templates/android/dimens.template.js';
28
35
  import androidFontDimens from './templates/android/fontDimens.template.js';
@@ -47,18 +54,58 @@ import macrosTemplate from './templates/ios/macros.template.js';
47
54
  import plistTemplate from './templates/ios/plist.template.js';
48
55
 
49
56
  /**
50
- * @typedef {import('../../types/Format.ts').Format} Format
51
- * @typedef {import('../../types/Format.ts').FormatFnArguments} FormatArgs
52
- * @typedef {import('../../types/File').FormattingOverrides} FormattingOverrides
53
- * @typedef {import('../../types/Format.ts').OutputReferences} OutputReferences
54
- * @typedef {import('../../types/DesignToken.ts').TransformedToken} Token
55
- * @typedef {import('../../types/DesignToken.ts').TransformedTokens} Tokens
57
+ * @typedef {import('../../types/Format.d.ts').Format} Format
58
+ * @typedef {import('../../types/Format.d.ts').FormatFnArguments} FormatArgs
59
+ * @typedef {import('../../types/File.d.ts').FormattingOverrides} FormattingOverrides
60
+ * @typedef {import('../../types/Format.d.ts').OutputReferences} OutputReferences
61
+ * @typedef {import('../../types/DesignToken.d.ts').TransformedToken} Token
62
+ * @typedef {import('../../types/DesignToken.d.ts').TransformedTokens} Tokens
63
+ * @typedef {import('../../types/Config.d.ts').Config} Config
64
+ * @typedef {import('../../types/Config.d.ts').LocalOptions} LocalOptions
65
+ * @typedef {import('../utils/stripMeta.js').StripMetaOptions} StripMetaOptions
56
66
  */
57
67
 
58
68
  /**
59
69
  * @namespace Formats
60
70
  */
61
71
 
72
+ /**
73
+ * Strip meta properties from tokens object
74
+ *
75
+ * @param {Tokens} tokens
76
+ * @param {Config & LocalOptions & { stripMeta: boolean | StripMetaOptions}} options
77
+ */
78
+ function stripMetaProps(tokens, options) {
79
+ const sdMetaProps = ['attributes', 'filePath', 'name', 'path', 'comment'];
80
+ const { stripMeta, usesDtcg } = options;
81
+ let opts = /** @type {StripMetaOptions} */ ({ usesDtcg });
82
+
83
+ if (stripMeta) {
84
+ if (stripMeta === true) {
85
+ opts.strip = sdMetaProps;
86
+ } else {
87
+ opts = {
88
+ usesDtcg: usesDtcg ?? false,
89
+ ...stripMeta,
90
+ };
91
+ }
92
+ tokens = stripMetaUtil(tokens, opts);
93
+ }
94
+ return tokens;
95
+ }
96
+
97
+ /**
98
+ * Prettier format JS contents
99
+ * @param {string} content
100
+ * @param {boolean} [ts] whether or not to use typescript
101
+ */
102
+ async function formatJS(content, ts = false) {
103
+ return prettier.format(content, {
104
+ parser: ts ? `typescript` : `babel`,
105
+ plugins: [prettierPluginBabel, prettierPluginEstree, prettierPluginTypescript],
106
+ });
107
+ }
108
+
62
109
  /**
63
110
  * Remove prefix because the prefix option for createPropertyFormatter
64
111
  * is not the same as the prefix inside header comment
@@ -343,7 +390,9 @@ const formats = {
343
390
  formatting: getFormattingCloneWithoutPrefix(formatting),
344
391
  options,
345
392
  });
346
- return header + 'module.exports = ' + JSON.stringify(dictionary.tokens, null, 2) + ';\n';
393
+ const content =
394
+ header + 'module.exports = ' + JSON.stringify(dictionary.tokens, null, 2) + ';\n';
395
+ return formatJS(content);
347
396
  },
348
397
 
349
398
  /**
@@ -365,7 +414,7 @@ const formats = {
365
414
  formatting: getFormattingCloneWithoutPrefix(formatting),
366
415
  options,
367
416
  });
368
- return (
417
+ const content =
369
418
  header +
370
419
  'module.exports = ' +
371
420
  '{\n' +
@@ -377,8 +426,8 @@ const formats = {
377
426
  })
378
427
  .join(',\n') +
379
428
  '\n}' +
380
- ';\n'
381
- );
429
+ ';\n';
430
+ return formatJS(content);
382
431
  },
383
432
 
384
433
  /**
@@ -407,14 +456,14 @@ const formats = {
407
456
  formatting: getFormattingCloneWithoutPrefix(formatting),
408
457
  options,
409
458
  });
410
- return (
459
+ const content =
411
460
  header +
412
461
  'var ' +
413
462
  (file.options?.name || '_styleDictionary') +
414
463
  ' = ' +
415
464
  JSON.stringify(dictionary.tokens, null, 2) +
416
- ';\n'
417
- );
465
+ ';\n';
466
+ return formatJS(content);
418
467
  },
419
468
 
420
469
  /**
@@ -455,7 +504,7 @@ const formats = {
455
504
  formatting: getFormattingCloneWithoutPrefix(formatting),
456
505
  options,
457
506
  });
458
- return (
507
+ const content =
459
508
  header +
460
509
  '(function(root, factory) {\n' +
461
510
  ' if (typeof module === "object" && module.exports) {\n' +
@@ -475,8 +524,8 @@ const formats = {
475
524
  ' return ' +
476
525
  JSON.stringify(dictionary.tokens, null, 2) +
477
526
  ';\n' +
478
- '}))\n'
479
- );
527
+ '}))\n';
528
+ return formatJS(content);
480
529
  },
481
530
 
482
531
  /**
@@ -516,7 +565,7 @@ const formats = {
516
565
  formatting: getFormattingCloneWithoutPrefix(formatting),
517
566
  options,
518
567
  });
519
- return (
568
+ const content =
520
569
  header +
521
570
  dictionary.allTokens
522
571
  .map(function (token) {
@@ -530,8 +579,48 @@ const formats = {
530
579
  return to_ret;
531
580
  })
532
581
  .join('\n') +
533
- '\n'
582
+ '\n';
583
+ return formatJS(content);
584
+ },
585
+
586
+ /**
587
+ * Creates a ES6 module with the whole style dictionary
588
+ *
589
+ * @memberof Formats
590
+ * @kind member
591
+ * @example
592
+ * ```js
593
+ * export default {
594
+ * "color": {
595
+ * "base": {
596
+ * "red": "#ff0000"
597
+ * }
598
+ * }
599
+ * }
600
+ * ```
601
+ */
602
+ 'javascript/esm': async function ({ dictionary, file, options }) {
603
+ const { formatting, minify = false } = options;
604
+ let { tokens } = dictionary;
605
+ tokens = stripMetaProps(
606
+ tokens,
607
+ /** @type {LocalOptions & Config & { stripMeta: boolean | StripMetaOptions}} */ (options),
608
+ );
609
+
610
+ const header = await fileHeader({
611
+ file,
612
+ formatting: getFormattingCloneWithoutPrefix(formatting),
613
+ options,
614
+ });
615
+
616
+ const dictionaryString = JSON.stringify(
617
+ minify ? minifyDictionary(tokens, options.usesDtcg) : tokens,
618
+ null,
619
+ 2,
534
620
  );
621
+
622
+ const content = `${header}export default ${dictionaryString};\n`;
623
+ return formatJS(content);
535
624
  },
536
625
 
537
626
  // TypeScript declarations
@@ -573,7 +662,7 @@ const formats = {
573
662
  formatting: getFormattingCloneWithoutPrefix(formatting),
574
663
  options,
575
664
  });
576
- return (
665
+ const content =
577
666
  header +
578
667
  dictionary.allTokens
579
668
  .map(function (token) {
@@ -588,8 +677,8 @@ const formats = {
588
677
  return to_ret_token;
589
678
  })
590
679
  .join('\n') +
591
- '\n'
592
- );
680
+ '\n';
681
+ return formatJS(content, true);
593
682
  },
594
683
 
595
684
  /**
@@ -668,7 +757,7 @@ const formats = {
668
757
  return type;
669
758
  }
670
759
 
671
- // TODO: find a browser+node compatible way to read from '../../types/DesignToken.ts'
760
+ // TODO: find a browser+node compatible way to read from '../../types/DesignToken.d.ts'
672
761
  const designTokenInterface = `interface DesignToken {
673
762
  ${options.usesDtcg ? '$' : ''}value?: any;
674
763
  ${options.usesDtcg ? '$' : ''}type?: string;
@@ -695,7 +784,8 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
695
784
 
696
785
  // JSON stringify will quote strings, because this is a type we need
697
786
  // it unquoted.
698
- return output.replace(/"DesignToken"/g, 'DesignToken') + '\n';
787
+ const content = output.replace(/"DesignToken"/g, 'DesignToken') + '\n';
788
+ return formatJS(content, true);
699
789
  },
700
790
 
701
791
  // Android templates
@@ -1341,8 +1431,13 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
1341
1431
  * }
1342
1432
  * ```
1343
1433
  */
1344
- json: function ({ dictionary }) {
1345
- return JSON.stringify(dictionary.tokens, null, 2) + '\n';
1434
+ json: function ({ dictionary, options }) {
1435
+ let { tokens } = dictionary;
1436
+ tokens = stripMetaProps(
1437
+ tokens,
1438
+ /** @type {LocalOptions & Config & { stripMeta: boolean | StripMetaOptions}} */ (options),
1439
+ );
1440
+ return JSON.stringify(tokens, null, 2) + '\n';
1346
1441
  },
1347
1442
 
1348
1443
  /**
@@ -1369,7 +1464,6 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
1369
1464
 
1370
1465
  /**
1371
1466
  * Creates a JSON nested file of the style dictionary.
1372
- *
1373
1467
  * @memberof Formats
1374
1468
  * @kind member
1375
1469
  * @example
@@ -1538,5 +1632,6 @@ declare const ${moduleName}: ${JSON.stringify(treeWalker(dictionary.tokens), nul
1538
1632
  formats['json/nested'].nested = true;
1539
1633
  formats['javascript/module'].nested = true;
1540
1634
  formats['javascript/object'].nested = true;
1635
+ formats['javascript/esm'].nested = true;
1541
1636
 
1542
1637
  export default formats;
@@ -4,6 +4,6 @@ declare function _default({ dictionary, options, header }: {
4
4
  header: string;
5
5
  }): string;
6
6
  export default _default;
7
- export type Dictionary = import("../../../../types/DesignToken.ts").Dictionary;
8
- export type Config = import("../../../../types/Config.ts").Config;
9
- export type LocalOptions = import("../../../../types/Config.ts").LocalOptions;
7
+ export type Dictionary = import("../../../../types/DesignToken.d.ts").Dictionary;
8
+ export type Config = import("../../../../types/Config.d.ts").Config;
9
+ export type LocalOptions = import("../../../../types/Config.d.ts").LocalOptions;
@@ -1,7 +1,7 @@
1
1
  /**
2
- * @typedef {import('../../../../types/DesignToken.ts').Dictionary} Dictionary
3
- * @typedef {import('../../../../types/Config.ts').Config} Config
4
- * @typedef {import('../../../../types/Config.ts').LocalOptions} LocalOptions
2
+ * @typedef {import('../../../../types/DesignToken.d.ts').Dictionary} Dictionary
3
+ * @typedef {import('../../../../types/Config.d.ts').Config} Config
4
+ * @typedef {import('../../../../types/Config.d.ts').LocalOptions} LocalOptions
5
5
  */
6
6
 
7
7
  /**
@@ -4,6 +4,6 @@ declare function _default({ dictionary, options, header }: {
4
4
  header: string;
5
5
  }): string;
6
6
  export default _default;
7
- export type Dictionary = import("../../../../types/DesignToken.ts").Dictionary;
8
- export type Config = import("../../../../types/Config.ts").Config;
9
- export type LocalOptions = import("../../../../types/Config.ts").LocalOptions;
7
+ export type Dictionary = import("../../../../types/DesignToken.d.ts").Dictionary;
8
+ export type Config = import("../../../../types/Config.d.ts").Config;
9
+ export type LocalOptions = import("../../../../types/Config.d.ts").LocalOptions;