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