@digdir/designsystemet 1.0.3 → 1.0.5

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 (189) hide show
  1. package/dist/bin/designsystemet.js +4287 -45
  2. package/dist/bin/options.js +5 -4
  3. package/dist/src/colors/colorMetadata.js +5 -4
  4. package/dist/src/colors/index.js +470 -4
  5. package/dist/src/colors/theme.js +286 -20
  6. package/dist/src/colors/utils.js +16 -15
  7. package/dist/{bin → src}/config.d.ts +46 -1
  8. package/dist/src/config.d.ts.map +1 -0
  9. package/dist/src/config.js +377 -0
  10. package/dist/src/index.js +3682 -2
  11. package/dist/src/migrations/beta-to-v1.js +85 -4
  12. package/dist/src/migrations/codemods/css/plugins.js +5 -4
  13. package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
  14. package/dist/src/migrations/codemods/css/run.js +18 -4
  15. package/dist/src/migrations/color-rename-next49.js +77 -6
  16. package/dist/src/migrations/index.d.ts +0 -1
  17. package/dist/src/migrations/index.d.ts.map +1 -1
  18. package/dist/src/migrations/index.js +461 -6
  19. package/dist/src/scripts/createJsonSchema.js +1608 -4
  20. package/dist/src/scripts/update-design-tokens.d.ts +2 -0
  21. package/dist/src/scripts/update-design-tokens.d.ts.map +1 -0
  22. package/dist/src/scripts/update-design-tokens.js +37 -0
  23. package/dist/src/{tokens/template.d.ts → scripts/update-template.d.ts} +1 -1
  24. package/dist/src/scripts/update-template.d.ts.map +1 -0
  25. package/dist/src/scripts/update-template.js +1200 -0
  26. package/dist/src/tokens/build.d.ts +2 -19
  27. package/dist/src/tokens/build.d.ts.map +1 -1
  28. package/dist/src/tokens/build.js +1268 -70
  29. package/dist/src/tokens/create/defaults.d.ts +7 -0
  30. package/dist/src/tokens/create/defaults.d.ts.map +1 -0
  31. package/dist/src/tokens/create/defaults.js +994 -0
  32. package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
  33. package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
  34. package/dist/src/tokens/create/generators/$designsystemet.js +101 -0
  35. package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
  36. package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
  37. package/dist/src/tokens/{write/generate$metadata.js → create/generators/$metadata.js} +3 -2
  38. package/dist/src/tokens/create/generators/$themes.d.ts +12 -0
  39. package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
  40. package/dist/src/tokens/create/generators/$themes.js +333 -0
  41. package/dist/src/tokens/create/generators/color.d.ts +5 -0
  42. package/dist/src/tokens/create/generators/color.d.ts.map +1 -0
  43. package/dist/src/tokens/create/generators/color.js +374 -0
  44. package/dist/src/tokens/create/generators/semantic.d.ts +296 -0
  45. package/dist/src/tokens/create/generators/semantic.d.ts.map +1 -0
  46. package/dist/src/tokens/create/generators/semantic.js +483 -0
  47. package/dist/src/tokens/create/generators/theme.d.ts +3 -0
  48. package/dist/src/tokens/create/generators/theme.d.ts.map +1 -0
  49. package/dist/src/tokens/create/generators/theme.js +168 -0
  50. package/dist/src/tokens/create/generators/typography.d.ts +3 -0
  51. package/dist/src/tokens/create/generators/typography.d.ts.map +1 -0
  52. package/dist/src/tokens/create/generators/typography.js +33 -0
  53. package/dist/src/tokens/{write.d.ts → create/write.d.ts} +2 -2
  54. package/dist/src/tokens/create/write.d.ts.map +1 -0
  55. package/dist/src/tokens/create/write.js +547 -0
  56. package/dist/src/tokens/create.d.ts +4 -2
  57. package/dist/src/tokens/create.d.ts.map +1 -1
  58. package/dist/src/tokens/create.js +2049 -59
  59. package/dist/src/tokens/format.d.ts +15 -0
  60. package/dist/src/tokens/format.d.ts.map +1 -0
  61. package/dist/src/tokens/format.js +3529 -0
  62. package/dist/src/tokens/index.d.ts +1 -0
  63. package/dist/src/tokens/index.d.ts.map +1 -1
  64. package/dist/src/tokens/index.js +3542 -2
  65. package/dist/src/tokens/process/configs/color.d.ts +12 -0
  66. package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
  67. package/dist/src/tokens/process/configs/color.js +823 -0
  68. package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
  69. package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
  70. package/dist/src/tokens/process/configs/semantic.js +367 -0
  71. package/dist/src/tokens/process/configs/shared.d.ts +10 -0
  72. package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
  73. package/dist/src/tokens/process/configs/shared.js +99 -0
  74. package/dist/src/tokens/process/configs/storefront.d.ts +3 -0
  75. package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -0
  76. package/dist/src/tokens/process/configs/storefront.js +220 -0
  77. package/dist/src/tokens/process/configs/typography.d.ts +3 -0
  78. package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
  79. package/dist/src/tokens/process/configs/typography.js +369 -0
  80. package/dist/src/tokens/{build → process}/configs.d.ts +3 -11
  81. package/dist/src/tokens/process/configs.d.ts.map +1 -0
  82. package/dist/src/tokens/process/configs.js +976 -0
  83. package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
  84. package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
  85. package/dist/src/tokens/process/formats/css/color.js +128 -0
  86. package/dist/src/tokens/process/formats/css/semantic.d.ts +17 -0
  87. package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
  88. package/dist/src/tokens/process/formats/css/semantic.js +109 -0
  89. package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
  90. package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
  91. package/dist/src/tokens/process/formats/css/typography.js +32 -0
  92. package/dist/src/tokens/process/formats/css.d.ts +8 -0
  93. package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
  94. package/dist/src/tokens/{build → process}/formats/css.js +94 -57
  95. package/dist/src/tokens/process/formats/js-tokens.d.ts.map +1 -0
  96. package/dist/src/tokens/process/formats/js-tokens.js +109 -0
  97. package/dist/src/tokens/process/platform.d.ts +87 -0
  98. package/dist/src/tokens/process/platform.d.ts.map +1 -0
  99. package/dist/src/tokens/process/platform.js +1090 -0
  100. package/dist/src/tokens/process/theme.d.ts +27 -0
  101. package/dist/src/tokens/process/theme.d.ts.map +1 -0
  102. package/dist/src/tokens/process/theme.js +172 -0
  103. package/dist/src/tokens/process/transformers.d.ts.map +1 -0
  104. package/dist/src/tokens/{build → process}/transformers.js +29 -6
  105. package/dist/src/tokens/{build → process}/utils/getMultidimensionalThemes.d.ts +3 -3
  106. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
  107. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +922 -0
  108. package/dist/src/tokens/template/design-tokens/primitives/globals.js +5 -0
  109. package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +5 -0
  110. package/dist/src/tokens/template/design-tokens/primitives/modes/size/large.js +5 -0
  111. package/dist/src/tokens/template/design-tokens/primitives/modes/size/medium.js +5 -0
  112. package/dist/src/tokens/template/design-tokens/primitives/modes/size/small.js +5 -0
  113. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/large.js +5 -0
  114. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/medium.js +5 -0
  115. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/small.js +5 -0
  116. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/typography.template.js +5 -0
  117. package/dist/src/tokens/template/design-tokens/semantic/color.base.template.js +5 -0
  118. package/dist/src/tokens/template/design-tokens/semantic/color.template.js +5 -0
  119. package/dist/src/tokens/template/design-tokens/semantic/modes/color.template.js +5 -0
  120. package/dist/src/tokens/template/design-tokens/semantic/style.js +5 -0
  121. package/dist/src/tokens/template/design-tokens/themes/theme.base.template.js +5 -0
  122. package/dist/src/tokens/template/design-tokens/themes/theme.template.js +5 -0
  123. package/dist/src/tokens/types.d.ts +58 -38
  124. package/dist/src/tokens/types.d.ts.map +1 -1
  125. package/dist/src/tokens/types.js +8 -0
  126. package/dist/src/tokens/utils.d.ts +30 -5
  127. package/dist/src/tokens/utils.d.ts.map +1 -1
  128. package/dist/src/tokens/utils.js +36 -50
  129. package/dist/src/utils.d.ts +18 -0
  130. package/dist/src/utils.d.ts.map +1 -0
  131. package/dist/src/utils.js +63 -0
  132. package/dist/typography.template-4N5YLH7F.json +22 -0
  133. package/package.json +22 -20
  134. package/dist/bin/config.d.ts.map +0 -1
  135. package/dist/bin/config.js +0 -71
  136. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
  137. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
  138. package/dist/src/migrations/codemods/jsx/classname-prefix.js +0 -64
  139. package/dist/src/migrations/codemods/jsx/run.d.ts +0 -7
  140. package/dist/src/migrations/codemods/jsx/run.d.ts.map +0 -1
  141. package/dist/src/migrations/codemods/jsx/run.js +0 -22
  142. package/dist/src/migrations/react-beta-to-v1.d.ts +0 -3
  143. package/dist/src/migrations/react-beta-to-v1.d.ts.map +0 -1
  144. package/dist/src/migrations/react-beta-to-v1.js +0 -5
  145. package/dist/src/scripts/copy-internal-tokens.d.ts +0 -2
  146. package/dist/src/scripts/copy-internal-tokens.d.ts.map +0 -1
  147. package/dist/src/scripts/copy-internal-tokens.js +0 -28
  148. package/dist/src/tokens/build/configs.d.ts.map +0 -1
  149. package/dist/src/tokens/build/configs.js +0 -280
  150. package/dist/src/tokens/build/formats/css.d.ts +0 -53
  151. package/dist/src/tokens/build/formats/css.d.ts.map +0 -1
  152. package/dist/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
  153. package/dist/src/tokens/build/formats/js-tokens.js +0 -48
  154. package/dist/src/tokens/build/transformers.d.ts.map +0 -1
  155. package/dist/src/tokens/build/types.d.ts +0 -48
  156. package/dist/src/tokens/build/types.d.ts.map +0 -1
  157. package/dist/src/tokens/build/types.js +0 -7
  158. package/dist/src/tokens/build/utils/entryfile.d.ts +0 -12
  159. package/dist/src/tokens/build/utils/entryfile.d.ts.map +0 -1
  160. package/dist/src/tokens/build/utils/entryfile.js +0 -67
  161. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +0 -1
  162. package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +0 -112
  163. package/dist/src/tokens/design-tokens/template/$metadata.json +0 -25
  164. package/dist/src/tokens/design-tokens/template/$themes.json +0 -1498
  165. package/dist/src/tokens/template.d.ts.map +0 -1
  166. package/dist/src/tokens/template.js +0 -99
  167. package/dist/src/tokens/write/generate$metadata.d.ts +0 -9
  168. package/dist/src/tokens/write/generate$metadata.d.ts.map +0 -1
  169. package/dist/src/tokens/write/generate$themes.d.ts +0 -12
  170. package/dist/src/tokens/write/generate$themes.d.ts.map +0 -1
  171. package/dist/src/tokens/write/generate$themes.js +0 -161
  172. package/dist/src/tokens/write.d.ts.map +0 -1
  173. package/dist/src/tokens/write.js +0 -177
  174. /package/dist/{src/tokens/design-tokens/template/semantic/color-base-file.json → color.base.template-M7BHS4OV.json} +0 -0
  175. /package/dist/{src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json → color.template-LMPUQ72A.json} +0 -0
  176. /package/dist/{src/tokens/design-tokens/template/semantic/semantic-color-template.json → color.template-XQNSHLTU.json} +0 -0
  177. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/global.json → global-XVXVBKM6.json} +0 -0
  178. /package/dist/{src/tokens/design-tokens/default/primitives/globals.json → globals-76VAFMDF.json} +0 -0
  179. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/large.json → large-CIIHO7AY.json} +0 -0
  180. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/large.json → large-UUOZ6DYI.json} +0 -0
  181. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/medium.json → medium-OQ7S7P4P.json} +0 -0
  182. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json → medium-VSB2S4X3.json} +0 -0
  183. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/small.json → small-AEXJ6U7Z.json} +0 -0
  184. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/small.json → small-ZY4KOJWX.json} +0 -0
  185. /package/dist/src/tokens/{build → process}/formats/js-tokens.d.ts +0 -0
  186. /package/dist/src/tokens/{build → process}/transformers.d.ts +0 -0
  187. /package/dist/{src/tokens/design-tokens/default/semantic/style.json → style-FP5XVCUD.json} +0 -0
  188. /package/dist/{src/tokens/design-tokens/template/themes/theme-base-file.json → theme.base.template-Y4RMFBQY.json} +0 -0
  189. /package/dist/{src/tokens/design-tokens/template/themes/theme-color-template.json → theme.template-CTQRNOMO.json} +0 -0
@@ -0,0 +1,1090 @@
1
+ // src/tokens/process/platform.ts
2
+ import chalk2 from "chalk";
3
+ import * as R12 from "ramda";
4
+ import StyleDictionary2 from "style-dictionary";
5
+
6
+ // src/tokens/types.ts
7
+ var colorCategories = {
8
+ main: "main",
9
+ support: "support"
10
+ };
11
+
12
+ // src/tokens/process/configs.ts
13
+ import { register } from "@tokens-studio/sd-transforms";
14
+ import * as R11 from "ramda";
15
+ import StyleDictionary from "style-dictionary";
16
+
17
+ // src/tokens/utils.ts
18
+ import * as R from "ramda";
19
+ var mapToLowerCase = R.map(R.toLower);
20
+ var hasAnyTruth = R.any(R.equals(true));
21
+ var getType = (token) => (token.$type ?? token.type) || "";
22
+ var getValue = (token) => token.$value ?? token.value;
23
+ var typeEquals = R.curry((types, token) => {
24
+ if (R.isNil(token)) {
25
+ return false;
26
+ }
27
+ return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
28
+ });
29
+ var pathStartsWithOneOf = R.curry((paths, token) => {
30
+ if (R.isNil(token)) {
31
+ return false;
32
+ }
33
+ const tokenPath = mapToLowerCase(token.path);
34
+ const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
35
+ return hasAnyTruth(matchPathsStartingWith);
36
+ });
37
+ function isSemanticToken(token) {
38
+ return token.filePath.includes("semantic/");
39
+ }
40
+ function isSemanticColorToken(token, color) {
41
+ return token.filePath.includes("semantic/") && R.startsWith(["color", color], token.path);
42
+ }
43
+ function isGlobalColorToken(token) {
44
+ return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
45
+ }
46
+ function isColorCategoryToken(token, category) {
47
+ if (!category) {
48
+ return ["main", "support"].some((c) => isColorCategoryToken(token, c));
49
+ }
50
+ return R.startsWith(["color", category], token.path);
51
+ }
52
+ var isDigit = (s) => /^\d+$/.test(s);
53
+ function traverseObj(obj, fn) {
54
+ for (const key in obj) {
55
+ const prop = obj[key];
56
+ if (prop != null) {
57
+ fn.apply(null, [obj, key, prop]);
58
+ if (typeof prop === "object") {
59
+ traverseObj(prop, fn);
60
+ }
61
+ }
62
+ }
63
+ return obj;
64
+ }
65
+ function inlineTokens(shouldInline, tokens) {
66
+ const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
67
+ return otherTokens.map((token) => {
68
+ let transformed = getValue(token.original);
69
+ for (const ref of inlineableTokens) {
70
+ const refName = ref.path.join(".");
71
+ if (typeof transformed === "string") {
72
+ transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
73
+ }
74
+ }
75
+ const tokenWithInlinedRefs = R.set(R.lensPath(["original", "$value"]), transformed, token);
76
+ return tokenWithInlinedRefs;
77
+ });
78
+ }
79
+
80
+ // src/tokens/process/configs/color.ts
81
+ import * as R6 from "ramda";
82
+
83
+ // src/tokens/process/formats/css/color.ts
84
+ import * as R2 from "ramda";
85
+ import { createPropertyFormatter } from "style-dictionary/utils";
86
+ var prefersColorScheme = (colorScheme2, content) => `
87
+ @media (prefers-color-scheme: ${colorScheme2}) {
88
+ [data-color-scheme="auto"] ${content}
89
+ }
90
+ `;
91
+ var colorScheme = {
92
+ name: "ds/css-colorscheme",
93
+ format: async ({ dictionary, file, options, platform }) => {
94
+ const { allTokens } = dictionary;
95
+ const { outputReferences, usesDtcg } = options;
96
+ const { selector, colorScheme: colorScheme2, layer } = platform;
97
+ const colorScheme_ = colorScheme2;
98
+ const format = createPropertyFormatter({
99
+ outputReferences,
100
+ dictionary,
101
+ format: "css",
102
+ usesDtcg
103
+ });
104
+ const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
105
+ color-scheme: ${colorScheme_};
106
+ ` : "";
107
+ const filteredAllTokens = allTokens.filter(
108
+ R2.allPass([
109
+ R2.anyPass([
110
+ // Include semantic tokens in the output
111
+ isSemanticToken,
112
+ // Include global color tokens
113
+ isGlobalColorToken
114
+ ]),
115
+ // Don't include color category tokens -- they are exported separately
116
+ (t) => !isColorCategoryToken(t)
117
+ ])
118
+ );
119
+ const formattedTokens = filteredAllTokens.map(format).join("\n");
120
+ const content = `{
121
+ ${formattedTokens}
122
+ ${colorSchemeProperty}}
123
+ `;
124
+ const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
125
+ const body = R2.isNotNil(layer) ? `@layer ${layer} {
126
+ ${selector} ${content} ${autoSelectorContent}
127
+ }
128
+ ` : `${selector} ${content} ${autoSelectorContent}
129
+ `;
130
+ return body;
131
+ }
132
+ };
133
+ var colorCategory = {
134
+ name: "ds/css-colorcategory",
135
+ format: async ({ dictionary, file, options, platform }) => {
136
+ const { outputReferences, usesDtcg } = options;
137
+ const { selector, layer } = platform;
138
+ const format = R2.compose(
139
+ createPropertyFormatter({
140
+ outputReferences,
141
+ dictionary,
142
+ format: "css",
143
+ usesDtcg
144
+ }),
145
+ (token) => ({
146
+ ...token,
147
+ name: token.name.replace(/color-\w+-/, "color-"),
148
+ original: {
149
+ ...token.original,
150
+ $value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
151
+ }
152
+ })
153
+ );
154
+ const formattedTokens = dictionary.allTokens.map(format).join("\n");
155
+ const content = `{
156
+ ${formattedTokens}
157
+ }
158
+ `;
159
+ const body = R2.isNotNil(layer) ? `@layer ${layer} {
160
+ ${selector} ${content}
161
+ }
162
+ ` : `${selector} ${content}
163
+ `;
164
+ return body;
165
+ }
166
+ };
167
+
168
+ // src/tokens/process/formats/css/semantic.ts
169
+ import * as R3 from "ramda";
170
+ import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
171
+ var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
172
+ var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
173
+ var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
174
+ var isInlineTokens = R3.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
175
+ var overrideSizingFormula = (format, token) => {
176
+ const [name, value] = format(token).split(":");
177
+ const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
178
+ const round = `round(down, ${calc}, 0.0625rem)`;
179
+ return {
180
+ name,
181
+ round,
182
+ calc
183
+ };
184
+ };
185
+ var formatSizingTokens = (format, tokens) => {
186
+ const { round, calc } = R3.reduce(
187
+ (acc, token) => {
188
+ const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
189
+ return {
190
+ round: [...acc.round, `${name}: ${round2};`],
191
+ calc: [...acc.calc, `${name}: ${calc2};`]
192
+ };
193
+ },
194
+ { round: [], calc: [] },
195
+ tokens
196
+ );
197
+ return `
198
+ ${calc.join("\n")}
199
+
200
+ @supports (width: round(down, .1em, 1px)) {
201
+ ${round.join("\n")}
202
+ }`;
203
+ };
204
+ var semantic = {
205
+ name: "ds/css-semantic",
206
+ format: async ({ dictionary, file, options, platform }) => {
207
+ const { outputReferences, usesDtcg } = options;
208
+ const { selector, layer } = platform;
209
+ const format = createPropertyFormatter2({
210
+ outputReferences,
211
+ dictionary,
212
+ format: "css",
213
+ usesDtcg
214
+ });
215
+ const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
216
+ const filteredTokens = R3.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
217
+ const [sizingTokens, restTokens] = R3.partition(
218
+ (t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
219
+ filteredTokens
220
+ );
221
+ const formattedTokens = [R3.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
222
+ const content = `{
223
+ ${formattedTokens.join("\n")}
224
+ }
225
+ `;
226
+ const body = R3.isNotNil(layer) ? `@layer ${layer} {
227
+ ${selector} ${content}
228
+ }
229
+ ` : `${selector} ${content}
230
+ `;
231
+ return body;
232
+ }
233
+ };
234
+
235
+ // src/tokens/process/formats/css/typography.ts
236
+ import * as R4 from "ramda";
237
+ import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
238
+ var typographyFontFamilyPredicate = R4.allPass([
239
+ R4.pathSatisfies(R4.includes("typography"), ["path"]),
240
+ R4.pathSatisfies(R4.includes("fontFamily"), ["path"])
241
+ ]);
242
+ var typography = {
243
+ name: "ds/css-typography",
244
+ format: async ({ dictionary, file, options, platform }) => {
245
+ const { outputReferences, usesDtcg } = options;
246
+ const { selector, layer } = platform;
247
+ const format = createPropertyFormatter3({
248
+ outputReferences,
249
+ dictionary,
250
+ format: "css",
251
+ usesDtcg
252
+ });
253
+ const filteredTokens = R4.reject(typographyFontFamilyPredicate, dictionary.allTokens);
254
+ const formattedTokens = R4.pipe(R4.map(format), R4.join("\n"))(filteredTokens);
255
+ const content = selector ? `${selector} {
256
+ ${formattedTokens}
257
+ }` : formattedTokens;
258
+ const body = R4.isNotNil(layer) ? `@layer ${layer} {
259
+ ${content}
260
+ }` : content;
261
+ return body;
262
+ }
263
+ };
264
+
265
+ // src/tokens/process/formats/css.ts
266
+ var formats = {
267
+ colorScheme,
268
+ colorCategory,
269
+ semantic,
270
+ typography
271
+ };
272
+
273
+ // src/tokens/process/transformers.ts
274
+ import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
275
+ import * as R5 from "ramda";
276
+ var isPx = R5.test(/\b\d+px\b/g);
277
+ var sizeRem = {
278
+ name: "ds/size/toRem",
279
+ type: "value",
280
+ transitive: true,
281
+ filter: (token) => {
282
+ const hasWantedType = typeEquals(["dimension", "fontsize"], token);
283
+ const hasWantedPath = pathStartsWithOneOf(["spacing", "sizing", "border-radius", "font-size"], token);
284
+ return hasWantedType && hasWantedPath;
285
+ },
286
+ transform: (token, config) => {
287
+ const value = getValue(token);
288
+ if (isPx(value)) {
289
+ const baseFont = config.basePxFontSize || 16;
290
+ const size = parseInt(value);
291
+ if (size === 0) {
292
+ return "0";
293
+ }
294
+ return `${size / baseFont}rem`;
295
+ }
296
+ return value;
297
+ }
298
+ };
299
+ var typographyName = {
300
+ name: "name/typography",
301
+ type: "name",
302
+ transitive: true,
303
+ // expanded tokens have different type so we match on path instead
304
+ filter: (token) => pathStartsWithOneOf(["typography"], token),
305
+ transform: (token) => {
306
+ return token.name.replace("-typography", "");
307
+ }
308
+ };
309
+ var resolveMath = {
310
+ name: "ds/resolveMath",
311
+ type: "value",
312
+ transitive: true,
313
+ filter: (token) => {
314
+ const isValidValue = ["string", "object"].includes(typeof getValue(token));
315
+ const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
316
+ return isValidValue && isTokenOfInterest;
317
+ },
318
+ transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
319
+ };
320
+ var unitless = {
321
+ name: "ds/unitless",
322
+ type: "value",
323
+ transitive: true,
324
+ filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
325
+ transform: (token) => parseInt(getValue(token))
326
+ };
327
+
328
+ // src/tokens/process/configs/shared.ts
329
+ var prefix = "ds";
330
+ var basePxFontSize = 16;
331
+ var dsTransformers = [
332
+ "name/kebab",
333
+ resolveMath.name,
334
+ "ts/size/px",
335
+ sizeRem.name,
336
+ unitless.name,
337
+ "ts/typography/fontWeight",
338
+ typographyName.name,
339
+ "ts/color/modifiers",
340
+ "ts/color/css/hexrgba",
341
+ "ts/size/lineheight",
342
+ "shadow/css/shorthand"
343
+ ];
344
+
345
+ // src/tokens/process/configs/color.ts
346
+ var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) => {
347
+ const selector = `${colorScheme2 === "light" ? ":root, " : ""}[data-color-scheme="${colorScheme2}"]`;
348
+ const layer = `ds.theme.color-scheme.${colorScheme2}`;
349
+ return {
350
+ preprocessors: ["tokens-studio"],
351
+ platforms: {
352
+ css: {
353
+ // custom
354
+ colorScheme: colorScheme2,
355
+ theme,
356
+ selector,
357
+ layer,
358
+ //
359
+ prefix,
360
+ buildPath: `${theme}/`,
361
+ transforms: dsTransformers,
362
+ files: [
363
+ {
364
+ destination: `color-scheme/${colorScheme2}.css`,
365
+ format: formats.colorScheme.name,
366
+ filter: (token) => typeEquals("color", token) && !R6.startsWith(["global"], token.path)
367
+ }
368
+ ],
369
+ options: {
370
+ outputReferences: false
371
+ }
372
+ }
373
+ }
374
+ };
375
+ };
376
+ var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, ...permutation }) => {
377
+ const category = opts.category;
378
+ const color = category === "builtin" ? opts.color : permutation[`${category}-color`];
379
+ if (!color) {
380
+ throw new Error(
381
+ category === "builtin" ? `Missing color for built-in color ${opts.color}` : `Missing color for category ${category}`
382
+ );
383
+ }
384
+ const layer = `ds.theme.color`;
385
+ const isRootColor = color === buildOptions?.rootColor;
386
+ const selector = isRootColor ? `:root, [data-color-scheme], [data-color="${color}"]` : `[data-color="${color}"], [data-color-scheme][data-color="${color}"]`;
387
+ const config = {
388
+ preprocessors: ["tokens-studio"],
389
+ platforms: {
390
+ css: {
391
+ // custom
392
+ colorScheme: colorScheme2,
393
+ theme,
394
+ selector,
395
+ layer,
396
+ //
397
+ prefix,
398
+ buildPath: `${theme}/`,
399
+ transforms: dsTransformers,
400
+ files: [
401
+ {
402
+ destination: `color/${color}.css`,
403
+ format: formats.colorCategory.name,
404
+ filter: (token) => category === "builtin" ? isSemanticColorToken(token, color) : isColorCategoryToken(token, category)
405
+ }
406
+ ],
407
+ options: {
408
+ outputReferences: true
409
+ }
410
+ }
411
+ }
412
+ };
413
+ return config;
414
+ };
415
+
416
+ // src/tokens/process/configs/semantic.ts
417
+ import * as R7 from "ramda";
418
+ import { outputReferencesFilter } from "style-dictionary/utils";
419
+ var semanticVariables = ({ theme }) => {
420
+ const selector = `:root`;
421
+ const layer = `ds.theme.semantic`;
422
+ return {
423
+ preprocessors: ["tokens-studio"],
424
+ platforms: {
425
+ css: {
426
+ // custom
427
+ theme,
428
+ basePxFontSize,
429
+ selector,
430
+ layer,
431
+ //
432
+ prefix,
433
+ buildPath: `${theme}/`,
434
+ transforms: dsTransformers,
435
+ files: [
436
+ {
437
+ destination: `semantic.css`,
438
+ format: formats.semantic.name,
439
+ filter: (token) => {
440
+ const isUwantedToken = R7.anyPass([R7.includes("primitives/global")])(token.filePath);
441
+ const isPrivateToken = R7.includes("_", token.path);
442
+ const unwantedPaths = pathStartsWithOneOf(["font-size", "line-height", "letter-spacing"], token);
443
+ const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
444
+ const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
445
+ return unwantedTokens;
446
+ }
447
+ }
448
+ ],
449
+ options: {
450
+ outputReferences: (token, options) => {
451
+ const include = pathStartsWithOneOf(["border-radius"], token);
452
+ const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
453
+ return (include || isWantedSize) && outputReferencesFilter(token, options);
454
+ }
455
+ }
456
+ }
457
+ }
458
+ };
459
+ };
460
+
461
+ // src/tokens/process/configs/storefront.ts
462
+ import * as R9 from "ramda";
463
+ import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
464
+
465
+ // src/tokens/process/formats/js-tokens.ts
466
+ import * as R8 from "ramda";
467
+ import { createPropertyFormatter as createPropertyFormatter4, fileHeader } from "style-dictionary/utils";
468
+ var groupByType = R8.groupBy((token) => getType(token));
469
+ var removeUnwatedTokens = R8.pipe(
470
+ R8.reject((token) => isColorCategoryToken(token)),
471
+ R8.reject((token) => R8.any((path) => path.startsWith("_"))(token.path))
472
+ );
473
+ var dissocExtensions = R8.pipe(R8.dissoc("$extensions"), R8.dissocPath(["original", "$extensions"]));
474
+ var removeUnwatedProps = R8.map((token) => dissocExtensions(token));
475
+ var toCssVarName = R8.pipe(R8.split(":"), R8.head, R8.trim);
476
+ var jsTokens = {
477
+ name: "ds/js-tokens",
478
+ format: async ({ dictionary, file, options }) => {
479
+ const { usesDtcg, outputReferences } = options;
480
+ const format = createPropertyFormatter4({
481
+ outputReferences,
482
+ dictionary,
483
+ format: "css",
484
+ usesDtcg
485
+ });
486
+ const formatTokens = R8.map((token) => {
487
+ if (pathStartsWithOneOf(["size", "_size"], token)) {
488
+ const { calc, name } = overrideSizingFormula(format, token);
489
+ return {
490
+ ...token,
491
+ name: name.trim(),
492
+ $value: calc.trim()
493
+ };
494
+ }
495
+ return {
496
+ ...token,
497
+ name: toCssVarName(format(token))
498
+ };
499
+ });
500
+ const processTokens = R8.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
501
+ const tokens = processTokens(inlineTokens(isInlineTokens, dictionary.allTokens));
502
+ const content = Object.entries(tokens).map(
503
+ ([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
504
+ `
505
+ ).join("\n");
506
+ return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
507
+ }
508
+ };
509
+
510
+ // src/tokens/process/configs/storefront.ts
511
+ var typescriptTokens = ({ "color-scheme": colorScheme2, theme }) => {
512
+ return {
513
+ preprocessors: ["tokens-studio"],
514
+ platforms: {
515
+ ts: {
516
+ prefix,
517
+ basePxFontSize,
518
+ transforms: dsTransformers,
519
+ buildPath: `${theme}/`,
520
+ files: [
521
+ {
522
+ destination: `${colorScheme2}.ts`,
523
+ format: jsTokens.name,
524
+ filter: (token) => {
525
+ if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R9.includes("semantic", token.filePath))
526
+ return false;
527
+ const isSemanticColor = R9.includes("semantic", token.filePath) && typeEquals(["color"], token);
528
+ const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
529
+ return isSemanticColor || wantedTypes;
530
+ }
531
+ }
532
+ ],
533
+ options: {
534
+ outputReferences: (token, options) => {
535
+ const include = pathStartsWithOneOf(["border-radius"], token);
536
+ const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
537
+ return (include || isWantedSize) && outputReferencesFilter2(token, options);
538
+ }
539
+ }
540
+ }
541
+ }
542
+ };
543
+ };
544
+
545
+ // src/tokens/process/configs/typography.ts
546
+ import { expandTypesMap } from "@tokens-studio/sd-transforms";
547
+ var typographyVariables = ({ theme, typography: typography2 }) => {
548
+ const selector = `${typography2 === "primary" ? ":root, " : ""}[data-typography="${typography2}"]`;
549
+ const layer = `ds.theme.typography.${typography2}`;
550
+ return {
551
+ usesDtcg: true,
552
+ preprocessors: ["tokens-studio"],
553
+ expand: {
554
+ include: ["typography"],
555
+ typesMap: { ...expandTypesMap, typography: { ...expandTypesMap.typography, letterSpacing: "dimension" } }
556
+ },
557
+ platforms: {
558
+ css: {
559
+ prefix,
560
+ typography: typography2,
561
+ selector,
562
+ layer,
563
+ buildPath: `${theme}/`,
564
+ basePxFontSize,
565
+ transforms: [
566
+ "name/kebab",
567
+ "ts/size/px",
568
+ sizeRem.name,
569
+ "ts/size/lineheight",
570
+ "ts/typography/fontWeight",
571
+ typographyName.name
572
+ ],
573
+ files: [
574
+ {
575
+ destination: `typography/${typography2}.css`,
576
+ format: formats.typography.name,
577
+ filter: (token) => {
578
+ const included = typeEquals(
579
+ ["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
580
+ token
581
+ );
582
+ if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
583
+ return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token);
584
+ }
585
+ }
586
+ ]
587
+ }
588
+ }
589
+ };
590
+ };
591
+
592
+ // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
593
+ var BoxShadowTypes;
594
+ (function(BoxShadowTypes2) {
595
+ BoxShadowTypes2["DROP_SHADOW"] = "dropShadow";
596
+ BoxShadowTypes2["INNER_SHADOW"] = "innerShadow";
597
+ })(BoxShadowTypes || (BoxShadowTypes = {}));
598
+
599
+ // ../../node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
600
+ var ColorModifierTypes;
601
+ (function(ColorModifierTypes2) {
602
+ ColorModifierTypes2["LIGHTEN"] = "lighten";
603
+ ColorModifierTypes2["DARKEN"] = "darken";
604
+ ColorModifierTypes2["MIX"] = "mix";
605
+ ColorModifierTypes2["ALPHA"] = "alpha";
606
+ })(ColorModifierTypes || (ColorModifierTypes = {}));
607
+
608
+ // ../../node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
609
+ var ColorSpaceTypes;
610
+ (function(ColorSpaceTypes2) {
611
+ ColorSpaceTypes2["LCH"] = "lch";
612
+ ColorSpaceTypes2["SRGB"] = "srgb";
613
+ ColorSpaceTypes2["P3"] = "p3";
614
+ ColorSpaceTypes2["HSL"] = "hsl";
615
+ })(ColorSpaceTypes || (ColorSpaceTypes = {}));
616
+
617
+ // ../../node_modules/@tokens-studio/types/dist/constants/Properties.js
618
+ var Properties;
619
+ (function(Properties2) {
620
+ Properties2["sizing"] = "sizing";
621
+ Properties2["height"] = "height";
622
+ Properties2["width"] = "width";
623
+ Properties2["spacing"] = "spacing";
624
+ Properties2["verticalPadding"] = "verticalPadding";
625
+ Properties2["horizontalPadding"] = "horizontalPadding";
626
+ Properties2["paddingTop"] = "paddingTop";
627
+ Properties2["paddingRight"] = "paddingRight";
628
+ Properties2["paddingBottom"] = "paddingBottom";
629
+ Properties2["paddingLeft"] = "paddingLeft";
630
+ Properties2["itemSpacing"] = "itemSpacing";
631
+ Properties2["fill"] = "fill";
632
+ Properties2["backgroundBlur"] = "backgroundBlur";
633
+ Properties2["border"] = "border";
634
+ Properties2["borderTop"] = "borderTop";
635
+ Properties2["borderRight"] = "borderRight";
636
+ Properties2["borderBottom"] = "borderBottom";
637
+ Properties2["borderLeft"] = "borderLeft";
638
+ Properties2["borderColor"] = "borderColor";
639
+ Properties2["borderRadius"] = "borderRadius";
640
+ Properties2["borderRadiusTopLeft"] = "borderRadiusTopLeft";
641
+ Properties2["borderRadiusTopRight"] = "borderRadiusTopRight";
642
+ Properties2["borderRadiusBottomRight"] = "borderRadiusBottomRight";
643
+ Properties2["borderRadiusBottomLeft"] = "borderRadiusBottomLeft";
644
+ Properties2["borderWidth"] = "borderWidth";
645
+ Properties2["borderWidthTop"] = "borderWidthTop";
646
+ Properties2["borderWidthRight"] = "borderWidthRight";
647
+ Properties2["borderWidthBottom"] = "borderWidthBottom";
648
+ Properties2["borderWidthLeft"] = "borderWidthLeft";
649
+ Properties2["boxShadow"] = "boxShadow";
650
+ Properties2["opacity"] = "opacity";
651
+ Properties2["fontFamilies"] = "fontFamilies";
652
+ Properties2["fontWeights"] = "fontWeights";
653
+ Properties2["fontSizes"] = "fontSizes";
654
+ Properties2["lineHeights"] = "lineHeights";
655
+ Properties2["typography"] = "typography";
656
+ Properties2["composition"] = "composition";
657
+ Properties2["letterSpacing"] = "letterSpacing";
658
+ Properties2["paragraphSpacing"] = "paragraphSpacing";
659
+ Properties2["textCase"] = "textCase";
660
+ Properties2["dimension"] = "dimension";
661
+ Properties2["textDecoration"] = "textDecoration";
662
+ Properties2["asset"] = "asset";
663
+ Properties2["tokenValue"] = "tokenValue";
664
+ Properties2["value"] = "value";
665
+ Properties2["tokenName"] = "tokenName";
666
+ Properties2["description"] = "description";
667
+ })(Properties || (Properties = {}));
668
+
669
+ // ../../node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
670
+ var TokenSetStatus;
671
+ (function(TokenSetStatus2) {
672
+ TokenSetStatus2["DISABLED"] = "disabled";
673
+ TokenSetStatus2["SOURCE"] = "source";
674
+ TokenSetStatus2["ENABLED"] = "enabled";
675
+ })(TokenSetStatus || (TokenSetStatus = {}));
676
+
677
+ // ../../node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
678
+ var TokenTypes;
679
+ (function(TokenTypes2) {
680
+ TokenTypes2["OTHER"] = "other";
681
+ TokenTypes2["COLOR"] = "color";
682
+ TokenTypes2["BORDER_RADIUS"] = "borderRadius";
683
+ TokenTypes2["SIZING"] = "sizing";
684
+ TokenTypes2["SPACING"] = "spacing";
685
+ TokenTypes2["TEXT"] = "text";
686
+ TokenTypes2["TYPOGRAPHY"] = "typography";
687
+ TokenTypes2["OPACITY"] = "opacity";
688
+ TokenTypes2["BORDER_WIDTH"] = "borderWidth";
689
+ TokenTypes2["STROKE_STYLE"] = "strokeStyle";
690
+ TokenTypes2["BOX_SHADOW"] = "boxShadow";
691
+ TokenTypes2["FONT_FAMILIES"] = "fontFamilies";
692
+ TokenTypes2["FONT_WEIGHTS"] = "fontWeights";
693
+ TokenTypes2["LINE_HEIGHTS"] = "lineHeights";
694
+ TokenTypes2["FONT_SIZES"] = "fontSizes";
695
+ TokenTypes2["LETTER_SPACING"] = "letterSpacing";
696
+ TokenTypes2["PARAGRAPH_SPACING"] = "paragraphSpacing";
697
+ TokenTypes2["PARAGRAPH_INDENT"] = "paragraphIndent";
698
+ TokenTypes2["TEXT_DECORATION"] = "textDecoration";
699
+ TokenTypes2["TEXT_CASE"] = "textCase";
700
+ TokenTypes2["COMPOSITION"] = "composition";
701
+ TokenTypes2["DIMENSION"] = "dimension";
702
+ TokenTypes2["BORDER"] = "border";
703
+ TokenTypes2["ASSET"] = "asset";
704
+ TokenTypes2["BOOLEAN"] = "boolean";
705
+ TokenTypes2["NUMBER"] = "number";
706
+ })(TokenTypes || (TokenTypes = {}));
707
+
708
+ // ../../node_modules/@tokens-studio/types/dist/constants/BorderValues.js
709
+ var BorderValues;
710
+ (function(BorderValues2) {
711
+ BorderValues2["BORDER_COLOR"] = "color";
712
+ BorderValues2["BORDER_WIDTH"] = "width";
713
+ BorderValues2["BORDER_STYLE"] = "style";
714
+ })(BorderValues || (BorderValues = {}));
715
+
716
+ // ../../node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
717
+ var StrokeStyleValues;
718
+ (function(StrokeStyleValues2) {
719
+ StrokeStyleValues2["SOLID"] = "solid";
720
+ StrokeStyleValues2["DASHED"] = "dashed";
721
+ StrokeStyleValues2["DOTTED"] = "dotted";
722
+ StrokeStyleValues2["DOUBLE"] = "double";
723
+ StrokeStyleValues2["GROOVE"] = "groove";
724
+ StrokeStyleValues2["RIDGE"] = "ridge";
725
+ StrokeStyleValues2["OUTSET"] = "outset";
726
+ StrokeStyleValues2["INSET"] = "inset";
727
+ })(StrokeStyleValues || (StrokeStyleValues = {}));
728
+
729
+ // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
730
+ var BoxShadowValues;
731
+ (function(BoxShadowValues2) {
732
+ BoxShadowValues2["TYPE"] = "type";
733
+ BoxShadowValues2["COLOR"] = "color";
734
+ BoxShadowValues2["X"] = "x";
735
+ BoxShadowValues2["Y"] = "y";
736
+ BoxShadowValues2["BLUR"] = "blur";
737
+ BoxShadowValues2["SPREAD"] = "spread";
738
+ BoxShadowValues2["BLEND_MODE"] = "blendMode";
739
+ })(BoxShadowValues || (BoxShadowValues = {}));
740
+
741
+ // ../../node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
742
+ var TypographyValues;
743
+ (function(TypographyValues2) {
744
+ TypographyValues2["FONT_FAMILY"] = "fontFamily";
745
+ TypographyValues2["FONT_WEIGHT"] = "fontWeight";
746
+ TypographyValues2["LINE_HEIGHT"] = "lineHeight";
747
+ TypographyValues2["FONT_SIZE"] = "fontSize";
748
+ TypographyValues2["LETTER_SPACING"] = "letterSpacing";
749
+ TypographyValues2["PARAGRAPH_SPACING"] = "paragraphSpacing";
750
+ TypographyValues2["PARAGRAPH_INDENT"] = "paragraphIndent";
751
+ TypographyValues2["TEXT_DECORATION"] = "textDecoration";
752
+ TypographyValues2["TEXT_CASE"] = "textCase";
753
+ })(TypographyValues || (TypographyValues = {}));
754
+
755
+ // src/tokens/process/utils/getMultidimensionalThemes.ts
756
+ import chalk from "chalk";
757
+ import { kebabCase } from "change-case";
758
+ import * as R10 from "ramda";
759
+ var getMultidimensionalThemes = (processed$themes, dimensions) => {
760
+ const verboseLogging = buildOptions?.verbose;
761
+ const grouped$themes = groupThemes(processed$themes);
762
+ const permutations = permutateThemes(grouped$themes);
763
+ const ALL_DEPENDENT_ON = ["theme"];
764
+ const keys2 = R10.keys(grouped$themes);
765
+ const nonDependentKeys = keys2.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
766
+ if (verboseLogging) {
767
+ console.log(chalk.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
768
+ console.log(chalk.cyan(` (ignoring permutations for ${nonDependentKeys})`));
769
+ }
770
+ return permutations.filter((val) => {
771
+ const filters = nonDependentKeys.map((x) => val.permutation[x] === grouped$themes[x][0].name);
772
+ return filters.every((x) => x);
773
+ });
774
+ };
775
+ var processed = Symbol("Type brand for ProcessedThemeObject");
776
+ function isProcessed(theme) {
777
+ return Boolean(theme[processed]);
778
+ }
779
+ function processThemeObject(theme) {
780
+ if (isProcessed(theme)) {
781
+ return theme;
782
+ }
783
+ const result = { ...theme, [processed]: true };
784
+ if (result.group) {
785
+ result.group = kebabCase(result.group);
786
+ }
787
+ result.name = kebabCase(result.name);
788
+ return result;
789
+ }
790
+ function groupThemes(themes) {
791
+ const groups = {};
792
+ for (const rawTheme of themes) {
793
+ const theme = processThemeObject(rawTheme);
794
+ if (theme.group) {
795
+ const groupKey = theme.group;
796
+ groups[groupKey] = [...groups[groupKey] ?? [], theme];
797
+ } else {
798
+ throw new Error(
799
+ `Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
800
+ );
801
+ }
802
+ }
803
+ return groups;
804
+ }
805
+ var hasUnknownProps = R10.pipe(R10.values, R10.none(R10.equals("unknown")), R10.not);
806
+ function permutateThemes(groups) {
807
+ const separator = "_";
808
+ const permutations = cartesian(Object.values(groups));
809
+ const permutatedThemes = permutations.map((perm) => {
810
+ const permutatedTheme = perm.reduce(
811
+ (acc, theme) => {
812
+ const { group, name, selectedTokenSets } = theme;
813
+ let updatedPermutation = acc.permutation;
814
+ if (group) {
815
+ const groupProp = R10.lensProp(group);
816
+ updatedPermutation = R10.set(groupProp, name, updatedPermutation);
817
+ }
818
+ const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
819
+ const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
820
+ return {
821
+ permutation: updatedPermutation,
822
+ name: updatedName,
823
+ selectedTokenSets: sets
824
+ };
825
+ },
826
+ {
827
+ name: "",
828
+ selectedTokenSets: [],
829
+ permutation: {
830
+ "color-scheme": "unknown",
831
+ "main-color": "unknown",
832
+ "support-color": "unknown",
833
+ theme: "unknown",
834
+ semantic: "unknown",
835
+ size: "unknown",
836
+ typography: "unknown"
837
+ }
838
+ }
839
+ );
840
+ if (hasUnknownProps(permutatedTheme)) {
841
+ throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
842
+ }
843
+ const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
844
+ return { ...permutatedTheme, selectedTokenSets: Array.from(uniqueTokenSets) };
845
+ });
846
+ return permutatedThemes;
847
+ }
848
+ function filterTokenSets(tokensets) {
849
+ return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
850
+ if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
851
+ return -1;
852
+ }
853
+ if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
854
+ return 1;
855
+ }
856
+ return 0;
857
+ }).map((entry) => entry[0]);
858
+ }
859
+ function cartesian(a) {
860
+ return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e].flat())));
861
+ }
862
+
863
+ // src/tokens/process/configs.ts
864
+ void register(StyleDictionary, { withSDBuiltins: false });
865
+ StyleDictionary.registerTransform(sizeRem);
866
+ StyleDictionary.registerTransform(typographyName);
867
+ StyleDictionary.registerTransform(resolveMath);
868
+ StyleDictionary.registerTransform(unitless);
869
+ StyleDictionary.registerFormat(jsTokens);
870
+ for (const format of Object.values(formats)) {
871
+ StyleDictionary.registerFormat(format);
872
+ }
873
+ var configs = {
874
+ colorSchemeVariables,
875
+ mainColorVariables: colorCategoryVariables({ category: "main" }),
876
+ supportColorVariables: colorCategoryVariables({ category: "support" }),
877
+ neutralColorVariables: colorCategoryVariables({ category: "builtin", color: "neutral" }),
878
+ successColorVariables: colorCategoryVariables({ category: "builtin", color: "success" }),
879
+ dangerColorVariables: colorCategoryVariables({ category: "builtin", color: "danger" }),
880
+ warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
881
+ infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
882
+ typographyVariables,
883
+ semanticVariables,
884
+ typescriptTokens
885
+ };
886
+ var getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, options) => {
887
+ const { tokensDir, tokenSets } = options;
888
+ const permutations = getMultidimensionalThemes(processed$themes, dimensions);
889
+ return permutations.flatMap(({ selectedTokenSets, permutation }) => {
890
+ const tokenSource = { source: void 0, tokens: {} };
891
+ if (tokenSets) {
892
+ for (const tokenSet of selectedTokenSets) {
893
+ const tokens = tokenSets.get(tokenSet);
894
+ if (tokens) {
895
+ const tokensWithFilePath = traverseObj(tokens, (obj) => {
896
+ if (Object.hasOwn(obj, `$value`) && !obj.filePath) {
897
+ obj.filePath = tokenSet;
898
+ }
899
+ });
900
+ tokenSource.tokens = R11.mergeDeepRight(tokenSource.tokens, tokensWithFilePath);
901
+ }
902
+ }
903
+ } else {
904
+ tokenSource.source = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
905
+ }
906
+ const configOrConfigs = getConfig(permutation);
907
+ const configs_ = Array.isArray(configOrConfigs) ? configOrConfigs : [{ config: configOrConfigs }];
908
+ const configs2 = configs_.map(({ config, permutationOverrides }) => {
909
+ return {
910
+ permutation: { ...permutation, ...permutationOverrides },
911
+ config: {
912
+ ...config,
913
+ /** Use official W3C design token format
914
+ @see https://v4.styledictionary.com/info/dtcg/
915
+ @see https://design-tokens.github.io/community-group/format/ */
916
+ usesDtcg: true,
917
+ log: {
918
+ ...config?.log,
919
+ verbosity: buildOptions?.verbose ? "verbose" : "silent"
920
+ },
921
+ ...tokenSource
922
+ }
923
+ };
924
+ });
925
+ return configs2;
926
+ }).sort();
927
+ };
928
+
929
+ // src/tokens/process/platform.ts
930
+ var initResult = {
931
+ formatted: [],
932
+ permutation: {
933
+ "color-scheme": "",
934
+ "main-color": "",
935
+ "support-color": "",
936
+ semantic: "",
937
+ size: "",
938
+ theme: "",
939
+ typography: ""
940
+ }
941
+ };
942
+ var buildOptions;
943
+ var sd = new StyleDictionary2();
944
+ var getCustomColors = (processed$themes) => processed$themes.filter(
945
+ (x) => x.group && [colorCategories.main, colorCategories.support].map((c) => `${c}-color`).includes(x.group)
946
+ ).map((x) => x.name);
947
+ var buildConfigs = {
948
+ typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
949
+ "color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
950
+ "main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
951
+ "support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
952
+ "neutral-color": {
953
+ getConfig: configs.neutralColorVariables,
954
+ dimensions: ["semantic"],
955
+ log: ({ permutation: { theme } }) => `${theme} - neutral`
956
+ },
957
+ "success-color": {
958
+ getConfig: configs.successColorVariables,
959
+ dimensions: ["semantic"],
960
+ log: ({ permutation: { theme } }) => `${theme} - success`
961
+ },
962
+ "danger-color": {
963
+ getConfig: configs.dangerColorVariables,
964
+ dimensions: ["semantic"],
965
+ log: ({ permutation: { theme } }) => `${theme} - danger`
966
+ },
967
+ "warning-color": {
968
+ getConfig: configs.warningColorVariables,
969
+ dimensions: ["semantic"],
970
+ log: ({ permutation: { theme } }) => `${theme} - warning`
971
+ },
972
+ "info-color": {
973
+ getConfig: configs.infoColorVariables,
974
+ dimensions: ["semantic"],
975
+ log: ({ permutation: { theme } }) => `${theme} - info`
976
+ },
977
+ semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] }
978
+ // storefront: {
979
+ // name: 'Storefront preview tokens',
980
+ // getConfig: configs.typescriptTokens,
981
+ // dimensions: ['color-scheme'],
982
+ // options: { outPath: path.resolve('../../apps/storefront/tokens') },
983
+ // enabled: () => buildOptions?.preview ?? false,
984
+ // },
985
+ };
986
+ async function processPlatform(options) {
987
+ const { process, $themes } = options;
988
+ const platform = "css";
989
+ const tokenSets = process === "format" ? options.tokenSets : void 0;
990
+ const tokensDir = process === "build" ? options.tokensDir : void 0;
991
+ buildOptions = options;
992
+ const processed$themes = $themes.map(processThemeObject).filter((theme) => R12.not(theme.group === "size" && theme.name !== "medium"));
993
+ const customColors = getCustomColors(processed$themes);
994
+ if (!buildOptions.rootColor) {
995
+ const firstMainColor = R12.head(customColors);
996
+ buildOptions.rootColor = firstMainColor;
997
+ console.log(`Using first main color; ${chalk2.blue(firstMainColor)}, as ${chalk2.green(`":root"`)} color`);
998
+ }
999
+ const buildAndSdConfigs = R12.map((buildConfig) => {
1000
+ const sdConfigs = getConfigsForThemeDimensions(buildConfig.getConfig, processed$themes, buildConfig.dimensions, {
1001
+ tokensDir,
1002
+ tokenSets
1003
+ });
1004
+ const unknownConfigs = buildConfig.dimensions.map(
1005
+ (dimension) => sdConfigs.filter((x) => x.permutation[dimension] === "unknown")
1006
+ );
1007
+ for (const unknowns of unknownConfigs) {
1008
+ if (unknowns.length === sdConfigs.length) {
1009
+ buildConfig.enabled = () => false;
1010
+ }
1011
+ }
1012
+ return {
1013
+ buildConfig,
1014
+ sdConfigs
1015
+ };
1016
+ }, buildConfigs);
1017
+ const processedBuilds = {
1018
+ "color-scheme": [initResult],
1019
+ "main-color": [initResult],
1020
+ "support-color": [initResult],
1021
+ "neutral-color": [initResult],
1022
+ "success-color": [initResult],
1023
+ "danger-color": [initResult],
1024
+ "warning-color": [initResult],
1025
+ "info-color": [initResult],
1026
+ semantic: [initResult],
1027
+ typography: [initResult],
1028
+ types: [initResult]
1029
+ };
1030
+ try {
1031
+ for (const [buildName, { buildConfig, sdConfigs }] of R12.toPairs(buildAndSdConfigs)) {
1032
+ if (!(buildConfig.enabled?.() ?? true)) {
1033
+ continue;
1034
+ }
1035
+ if (sdConfigs.length > 0) {
1036
+ console.log(`
1037
+ \u{1F371} Building ${chalk2.green(buildConfig.name ?? buildName)}`);
1038
+ const results = await Promise.all(
1039
+ sdConfigs.map(async (sdConfig) => {
1040
+ const { config, permutation } = sdConfig;
1041
+ const modes = ["theme", ...buildConfig.dimensions];
1042
+ const modeMessage = modes.map((x) => permutation[x]).join(" - ");
1043
+ const logMessage = R12.isNil(buildConfig.log) ? modeMessage : buildConfig?.log(sdConfig);
1044
+ console.log(logMessage);
1045
+ const sdOptions = { cache: true };
1046
+ const sdExtended = await sd.extend(config);
1047
+ const result = {
1048
+ permutation,
1049
+ formatted: await sdExtended.formatPlatform(platform, sdOptions)
1050
+ };
1051
+ return Promise.resolve(result);
1052
+ })
1053
+ );
1054
+ processedBuilds[buildName] = results;
1055
+ }
1056
+ }
1057
+ } catch (err) {
1058
+ if (err instanceof Error) {
1059
+ err.message = err.message.replace('log.verbosity "verbose" or use ', "");
1060
+ }
1061
+ throw err;
1062
+ }
1063
+ const colorsFileName = "colors.d.ts";
1064
+ const reactColorTypes = await createColorTypeDeclaration(customColors);
1065
+ processedBuilds.types = [
1066
+ {
1067
+ ...initResult,
1068
+ formatted: [{ output: reactColorTypes, destination: colorsFileName }]
1069
+ }
1070
+ ];
1071
+ return processedBuilds;
1072
+ }
1073
+ async function createColorTypeDeclaration(colors) {
1074
+ console.log(`
1075
+ \u{1F371} Building ${chalk2.green("type declarations")}`);
1076
+ const typeDeclaration = `
1077
+ import type {} from '@digdir/designsystemet-react/colors';
1078
+
1079
+ declare module '@digdir/designsystemet-react/colors' {
1080
+ export interface MainAndSupportColors {
1081
+ ${colors.map((color) => ` ${color}: never;`).join("\n")}
1082
+ }
1083
+ }
1084
+ `.trimStart();
1085
+ return typeDeclaration;
1086
+ }
1087
+ export {
1088
+ buildOptions,
1089
+ processPlatform
1090
+ };