@digdir/designsystemet 1.13.2 → 1.13.3

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