@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,3344 +1,3 @@
1
- // src/tokens/create/generators/primitives/color-scheme.ts
2
- import * as R4 from "ramda";
3
-
4
- // src/colors/colorMetadata.ts
5
- import * as R from "ramda";
6
- var baseColors = {
7
- info: "#0A71C0",
8
- success: "#068718",
9
- warning: "#EA9B1B",
10
- danger: "#C01B1B"
11
- };
12
- var dsLinkColor = "#663299";
13
- var colorMetadata = {
14
- "background-default": {
15
- number: 1,
16
- name: "background-default",
17
- group: "background",
18
- displayName: "Background Default",
19
- description: {
20
- long: "Background Default er den mest n\xF8ytrale bakgrunnsfargen.",
21
- short: "Standard bakgrunnsfarge."
22
- },
23
- luminance: {
24
- light: 1,
25
- dark: 9e-3,
26
- contrast: 1e-3
27
- }
28
- },
29
- "background-tinted": {
30
- number: 2,
31
- name: "background-tinted",
32
- group: "background",
33
- displayName: "Background Tinted",
34
- description: {
35
- long: "Background Tinted er en bakgrunnsfarge som har et hint av farge i seg.",
36
- short: "Bakgrunn med et hint av farge i seg."
37
- },
38
- luminance: {
39
- light: 0.9,
40
- dark: 0.014,
41
- contrast: 65e-4
42
- }
43
- },
44
- "surface-default": {
45
- number: 3,
46
- name: "surface-default",
47
- group: "surface",
48
- displayName: "Surface Default",
49
- description: {
50
- long: "Surface Default brukes p\xE5 flater som ligger opp\xE5 bakgrunnsfargene. Dette er den mest n\xF8ytrale surface fargen.",
51
- short: "Standardfarge for overflater / komponenter."
52
- },
53
- luminance: {
54
- light: 1,
55
- dark: 0.021,
56
- contrast: 0.015
57
- }
58
- },
59
- "surface-tinted": {
60
- number: 4,
61
- name: "surface-tinted",
62
- group: "surface",
63
- displayName: "Surface Tinted",
64
- description: {
65
- long: "Surface Tinted brukes p\xE5 flater som ligger opp\xE5 bakgrunnsfargene. Denne har et hint av farge i seg.",
66
- short: "Overflater / komponenter med et hint av farge i seg."
67
- },
68
- luminance: {
69
- light: 0.81,
70
- dark: 0.027,
71
- contrast: 0.015
72
- }
73
- },
74
- "surface-hover": {
75
- number: 5,
76
- name: "surface-hover",
77
- group: "surface",
78
- displayName: "Surface Hover",
79
- description: {
80
- long: "Surface Hover brukes p\xE5 interaktive flater som ligger opp\xE5 bakgrunnsfargene i en hover state.",
81
- short: "Hover-farge til overflater / komponenter."
82
- },
83
- luminance: {
84
- light: 0.7,
85
- dark: 0.036,
86
- contrast: 0.028
87
- }
88
- },
89
- "surface-active": {
90
- number: 6,
91
- name: "surface-active",
92
- group: "surface",
93
- displayName: "Surface Active",
94
- description: {
95
- long: "Surface Active brukes p\xE5 interaktive flater som ligger opp\xE5 bakgrunnsfargene i en active state.",
96
- short: "Active-farge til overflater / komponenter."
97
- },
98
- luminance: {
99
- light: 0.59,
100
- dark: 0.056,
101
- contrast: 0.045
102
- }
103
- },
104
- "border-subtle": {
105
- number: 7,
106
- name: "border-subtle",
107
- group: "border",
108
- displayName: "Border Subtle",
109
- description: {
110
- long: "Border Subtle er den lyseste border-fargen og brukes for \xE5 skille elementer fra hverandre.",
111
- short: "Border-farge med lav kontrast til dekorativ bruk (skillelinjer)."
112
- },
113
- luminance: {
114
- light: 0.5,
115
- dark: 0.08,
116
- contrast: 0.26
117
- }
118
- },
119
- "border-default": {
120
- number: 8,
121
- name: "border-default",
122
- group: "border",
123
- displayName: "Border Default",
124
- description: {
125
- long: "Border Default er en border-farge som brukes n\xE5r man \xF8nsker god kontrast mot bakgrunnsfargene.",
126
- short: "Standard border-farge til skjemakomponenter og meningsb\xE6rende elementer."
127
- },
128
- luminance: {
129
- light: 0.19,
130
- dark: 0.22,
131
- contrast: 0.4
132
- }
133
- },
134
- "border-strong": {
135
- number: 9,
136
- name: "border-strong",
137
- group: "border",
138
- displayName: "Border Strong",
139
- description: {
140
- long: "Border Strong er den m\xF8rkeste border-fargen og brukes n\xE5r man \xF8nsker en veldig tydelig og sterk border.",
141
- short: "Border-farge med h\xF8y kontrast for ekstra synlighet."
142
- },
143
- luminance: {
144
- light: 0.11,
145
- dark: 0.39,
146
- contrast: 0.6
147
- }
148
- },
149
- "text-subtle": {
150
- number: 10,
151
- name: "text-subtle",
152
- group: "text",
153
- displayName: "Text Subtle",
154
- description: {
155
- long: "Text Subtle er den lyseste tekstfargen og brukes p\xE5 tekst som skal v\xE6re litt mindre synlig eller for \xE5 skape variasjon i typografien.",
156
- short: "Tekst- og ikonfarge med lavere kontrast."
157
- },
158
- luminance: {
159
- light: 0.11,
160
- dark: 0.39,
161
- contrast: 0.57
162
- }
163
- },
164
- "text-default": {
165
- number: 11,
166
- name: "text-default",
167
- group: "text",
168
- displayName: "Text Default",
169
- description: {
170
- long: "Text Default er den m\xF8rkeste tekstfargen og brukes p\xE5 tekst som skal v\xE6re mest synlig. Denne fargen b\xF8r brukes p\xE5 mesteparten av teksten p\xE5 en side.",
171
- short: "Tekst- og ikonfarge med h\xF8y kontrast og god synlighet."
172
- },
173
- luminance: {
174
- light: 0.0245,
175
- dark: 0.84,
176
- contrast: 0.86
177
- }
178
- },
179
- "base-default": {
180
- number: 12,
181
- name: "base-default",
182
- group: "base",
183
- displayName: "Base Default",
184
- description: {
185
- long: "Base Default fargen f\xE5r den samme hex koden som fargen som er valgt i verkt\xF8yet. Brukes ofte som farge p\xE5 viktige elementer og p\xE5 flater som skal fange brukerens oppmerksomhet.",
186
- short: "Standardfarge for solide bakgrunner."
187
- },
188
- luminance: {
189
- light: 1,
190
- dark: 1,
191
- contrast: 1
192
- }
193
- },
194
- "base-hover": {
195
- number: 13,
196
- name: "base-hover",
197
- group: "base",
198
- displayName: "Base Hover",
199
- description: {
200
- long: "Base Hover brukes som hover farge p\xE5 elementer som bruker Base Default fargen.",
201
- short: "Hover-farge for solide bakgrunner."
202
- },
203
- luminance: {
204
- light: 1,
205
- dark: 1,
206
- contrast: 1
207
- }
208
- },
209
- "base-active": {
210
- number: 14,
211
- name: "base-active",
212
- group: "base",
213
- displayName: "Base Active",
214
- description: {
215
- long: "Base Active brukes som active farge p\xE5 elementer som bruker Base Default fargen.",
216
- short: "Active-farge for solide bakgrunner."
217
- },
218
- luminance: {
219
- light: 1,
220
- dark: 1,
221
- contrast: 1
222
- }
223
- },
224
- "base-contrast-subtle": {
225
- number: 15,
226
- name: "base-contrast-subtle",
227
- group: "base",
228
- displayName: "Contrast Subtle",
229
- description: {
230
- long: "Contrast Subtle brukes som en viktig meningsb\xE6rende farge opp\xE5 Base Default fargen.",
231
- short: "Farge med god kontrast mot Base-default."
232
- },
233
- luminance: {
234
- light: 1,
235
- dark: 1,
236
- contrast: 1
237
- }
238
- },
239
- "base-contrast-default": {
240
- number: 16,
241
- name: "base-contrast-default",
242
- group: "base",
243
- displayName: "Contrast Default",
244
- description: {
245
- long: "Contrast Default brukes som en viktig meningsb\xE6rende farge opp\xE5 alle Base fargane.",
246
- short: "Farge med god kontrast mot Base-default og Base-hover."
247
- },
248
- luminance: {
249
- light: 1,
250
- dark: 1,
251
- contrast: 1
252
- }
253
- }
254
- };
255
- var colorMetadataByNumber = R.indexBy((metadata) => metadata.number, Object.values(colorMetadata));
256
- var colorNames = Object.keys(colorMetadata);
257
- var baseColorNames = Object.keys(baseColors);
258
-
259
- // src/colors/theme.ts
260
- import chroma2 from "chroma-js";
261
- import * as R2 from "ramda";
262
-
263
- // src/colors/utils.ts
264
- import chroma from "chroma-js";
265
- import Colorjs from "colorjs.io";
266
- import { Hsluv } from "hsluv";
267
- var getLuminanceFromLightness = (lightness) => {
268
- const conv = new Hsluv();
269
- conv.hsluv_l = lightness;
270
- conv.hsluvToHex();
271
- return chroma(conv.hex).luminance();
272
- };
273
- var getLightnessFromHex = (hex) => {
274
- const conv = new Hsluv();
275
- conv.hex = hex;
276
- conv.hexToHsluv();
277
- return conv.hsluv_l;
278
- };
279
-
280
- // src/colors/theme.ts
281
- var generateColorScale = (color, colorScheme2) => {
282
- let interpolationColor = color;
283
- if (colorScheme2 === "dark") {
284
- const [L, C, H] = chroma2(color).oklch();
285
- const chromaModifier = 0.7;
286
- interpolationColor = chroma2(L, C * chromaModifier, H, "oklch").hex();
287
- }
288
- const colors = R2.mapObjIndexed((colorData) => {
289
- const luminance = colorData.luminance[colorScheme2];
290
- return {
291
- ...colorData,
292
- hex: chroma2(interpolationColor).luminance(luminance).hex()
293
- };
294
- }, colorMetadata);
295
- const baseColors2 = generateBaseColors(color, colorScheme2);
296
- colors["base-default"] = { ...colors["base-default"], hex: baseColors2.default };
297
- colors["base-hover"] = { ...colors["base-hover"], hex: baseColors2.hover };
298
- colors["base-active"] = { ...colors["base-active"], hex: baseColors2.active };
299
- colors["base-contrast-subtle"] = {
300
- ...colors["base-contrast-subtle"],
301
- hex: generateColorContrast(baseColors2.default, "subtle")
302
- };
303
- colors["base-contrast-default"] = {
304
- ...colors["base-contrast-default"],
305
- hex: generateColorContrast(baseColors2.default, "default")
306
- };
307
- return Object.values(colors);
308
- };
309
- var generateBaseColors = (color, colorScheme2) => {
310
- let colorLightness = getLightnessFromHex(color);
311
- if (colorScheme2 !== "light") {
312
- colorLightness = colorLightness <= 30 ? 70 : 100 - colorLightness;
313
- }
314
- const modifier = colorLightness <= 30 || colorLightness >= 49 && colorLightness <= 65 ? -8 : 8;
315
- const calculateLightness = (base, mod) => base - mod;
316
- return {
317
- default: colorScheme2 === "light" ? color : chroma2(color).luminance(getLuminanceFromLightness(colorLightness)).hex(),
318
- hover: chroma2(color).luminance(getLuminanceFromLightness(calculateLightness(colorLightness, modifier))).hex(),
319
- active: chroma2(color).luminance(getLuminanceFromLightness(calculateLightness(colorLightness, modifier * 2))).hex()
320
- };
321
- };
322
- var generateColorContrast = (color, type) => {
323
- if (type === "default") {
324
- return chroma2.contrast(color, "#ffffff") >= chroma2.contrast(color, "#000000") ? "#ffffff" : "#000000";
325
- }
326
- if (type === "subtle") {
327
- const contrastWhite = chroma2.contrast(color, "#ffffff");
328
- const contrastBlack = chroma2.contrast(color, "#000000");
329
- const lightness = getLightnessFromHex(color);
330
- const modifier = lightness <= 40 || lightness >= 60 ? 60 : 50;
331
- const targetLightness = contrastWhite >= contrastBlack ? lightness + modifier : lightness - modifier;
332
- return chroma2(color).luminance(getLuminanceFromLightness(targetLightness)).hex();
333
- }
334
- return color;
335
- };
336
-
337
- // src/colors/types.ts
338
- import * as R3 from "ramda";
339
- var semanticColorMap = {
340
- "background-default": 1,
341
- "background-tinted": 2,
342
- "surface-default": 3,
343
- "surface-tinted": 4,
344
- "surface-hover": 5,
345
- "surface-active": 6,
346
- "border-subtle": 7,
347
- "border-default": 8,
348
- "border-strong": 9,
349
- "text-subtle": 10,
350
- "text-default": 11,
351
- "base-default": 12,
352
- "base-hover": 13,
353
- "base-active": 14,
354
- "base-contrast-subtle": 15,
355
- "base-contrast-default": 16
356
- };
357
- var semanticColorNames = R3.keys(semanticColorMap);
358
- var semanticColorNumbers = R3.values(semanticColorMap);
359
-
360
- // src/tokens/create/generators/primitives/color-scheme.ts
361
- var generateColor = (colorArray, overrides) => {
362
- const obj = {};
363
- const $type = "color";
364
- for (const index in colorArray) {
365
- const position = Number(index) + 1;
366
- const overrideValue = overrides?.[position];
367
- obj[position] = {
368
- $type,
369
- $value: overrideValue || colorArray[index].hex
370
- };
371
- }
372
- return obj;
373
- };
374
- var generateColorScheme = (themeName, colorScheme2, colors, overrides) => {
375
- const createColorOverrides = (colorName) => {
376
- if (!overrides?.colors || !(colorName in overrides.colors)) {
377
- return void 0;
378
- }
379
- const colorOverrides = overrides.colors[colorName];
380
- const positionOverrides = {};
381
- Object.entries(colorOverrides).forEach(([semanticTokenName, modeOverrides]) => {
382
- const position = colorMetadata[semanticTokenName].number;
383
- if (position) {
384
- let overrideValue;
385
- if (colorScheme2 === "light" && modeOverrides.light) {
386
- overrideValue = modeOverrides.light;
387
- } else if (colorScheme2 === "dark" && modeOverrides.dark) {
388
- overrideValue = modeOverrides.dark;
389
- }
390
- if (overrideValue) {
391
- positionOverrides[position] = overrideValue;
392
- }
393
- }
394
- });
395
- return Object.keys(positionOverrides).length > 0 ? positionOverrides : void 0;
396
- };
397
- const main = R4.mapObjIndexed(
398
- (color, colorName) => generateColor(generateColorScale(color, colorScheme2), createColorOverrides(colorName)),
399
- colors.main
400
- );
401
- const support = R4.mapObjIndexed(
402
- (color, colorName) => generateColor(generateColorScale(color, colorScheme2), createColorOverrides(colorName)),
403
- colors.support
404
- );
405
- const neutralColorScale = generateColorScale(colors.neutral, colorScheme2);
406
- const neutral = generateColor(neutralColorScale, createColorOverrides("neutral"));
407
- const baseColorsWithOverrides = {
408
- ...baseColors,
409
- ...overrides?.severity
410
- };
411
- const globalColors = R4.mapObjIndexed(
412
- (color, colorName) => generateColor(generateColorScale(color, colorScheme2), createColorOverrides(colorName)),
413
- baseColorsWithOverrides
414
- );
415
- const linkColor = generateColor(generateColorScale(dsLinkColor, colorScheme2));
416
- const defaultLinkVisited = linkColor[12];
417
- const linkOverride = overrides?.linkVisited?.[colorScheme2] ? { $type: "color", $value: overrides.linkVisited[colorScheme2] } : void 0;
418
- const defaultFocusInner = neutralColorScale[0].hex;
419
- const defaultFocusOuter = neutralColorScale[10].hex;
420
- const focusInnerOverride = overrides?.focus?.inner?.[colorScheme2];
421
- const focusOuterOverride = overrides?.focus?.outer?.[colorScheme2];
422
- return {
423
- [themeName]: {
424
- ...main,
425
- ...support,
426
- neutral,
427
- ...globalColors,
428
- link: {
429
- visited: linkOverride || defaultLinkVisited
430
- },
431
- focus: {
432
- inner: {
433
- $type: "color",
434
- $value: focusInnerOverride || defaultFocusInner
435
- },
436
- outer: {
437
- $type: "color",
438
- $value: focusOuterOverride || defaultFocusOuter
439
- }
440
- }
441
- }
442
- };
443
- };
444
-
445
- // src/tokens/create/generators/primitives/globals.ts
446
- var globals = {
447
- "border-width": {
448
- "1": {
449
- $type: "borderWidth",
450
- $value: "1px"
451
- },
452
- "3": {
453
- $type: "borderWidth",
454
- $value: "3px"
455
- }
456
- },
457
- shadow: {
458
- "100": {
459
- $type: "boxShadow",
460
- $value: [
461
- {
462
- color: "rgba(0,0,0,0.16)",
463
- x: "0",
464
- y: "0",
465
- blur: "1",
466
- spread: "0"
467
- },
468
- {
469
- x: "0",
470
- y: "1",
471
- blur: "2",
472
- spread: "0",
473
- color: "rgba(0,0,0,0.12)"
474
- }
475
- ]
476
- },
477
- "200": {
478
- $type: "boxShadow",
479
- $value: [
480
- {
481
- color: "rgba(0,0,0,0.15)",
482
- x: "0",
483
- y: "0",
484
- blur: "1",
485
- spread: "0"
486
- },
487
- {
488
- color: "rgba(0,0,0,0.12)",
489
- x: "0",
490
- y: "1",
491
- blur: "2",
492
- spread: "0"
493
- },
494
- {
495
- x: "0",
496
- y: "2",
497
- blur: "4",
498
- spread: "0",
499
- color: "rgba(0,0,0,0.1)"
500
- }
501
- ]
502
- },
503
- "300": {
504
- $type: "boxShadow",
505
- $value: [
506
- {
507
- color: "rgba(0,0,0,0.14)",
508
- x: "0",
509
- y: "0",
510
- blur: "1",
511
- spread: "0"
512
- },
513
- {
514
- color: "rgba(0,0,0,0.12)",
515
- x: "0",
516
- y: "2",
517
- blur: "4",
518
- spread: "0"
519
- },
520
- {
521
- x: "0",
522
- y: "4",
523
- blur: "8",
524
- spread: "0",
525
- color: "rgba(0,0,0,0.12)"
526
- }
527
- ]
528
- },
529
- "400": {
530
- $type: "boxShadow",
531
- $value: [
532
- {
533
- color: "rgba(0,0,0,0.13)",
534
- x: "0",
535
- y: "0",
536
- blur: "1",
537
- spread: "0"
538
- },
539
- {
540
- color: "rgba(0,0,0,0.13)",
541
- x: "0",
542
- y: "3",
543
- blur: "5",
544
- spread: "0"
545
- },
546
- {
547
- x: "0",
548
- y: "6",
549
- blur: "12",
550
- spread: "0",
551
- color: "rgba(0,0,0,0.14)"
552
- }
553
- ]
554
- },
555
- "500": {
556
- $type: "boxShadow",
557
- $value: [
558
- {
559
- color: "rgba(0,0,0,0.12)",
560
- x: "0",
561
- y: "0",
562
- blur: "1",
563
- spread: "0"
564
- },
565
- {
566
- color: "rgba(0,0,0,0.16)",
567
- x: "0",
568
- y: "4",
569
- blur: "8",
570
- spread: "0"
571
- },
572
- {
573
- x: "0",
574
- y: "12",
575
- blur: "24",
576
- spread: "0",
577
- color: "rgba(0,0,0,0.16)"
578
- }
579
- ]
580
- }
581
- },
582
- opacity: {
583
- "30": {
584
- $type: "opacity",
585
- $value: "30%"
586
- }
587
- }
588
- };
589
- var generateGlobals = () => globals;
590
-
591
- // src/tokens/create/generators/primitives/size.ts
592
- var global = {
593
- _size: {
594
- "0": {
595
- $type: "dimension",
596
- $value: "floor({_size.unit} * 0)"
597
- },
598
- "1": {
599
- $type: "dimension",
600
- $value: "floor({_size.unit} * 1)"
601
- },
602
- "2": {
603
- $type: "dimension",
604
- $value: "floor({_size.unit} * 2)"
605
- },
606
- "3": {
607
- $type: "dimension",
608
- $value: "floor({_size.unit} * 3)"
609
- },
610
- "4": {
611
- $type: "dimension",
612
- $value: "floor({_size.unit} * 4)"
613
- },
614
- "5": {
615
- $type: "dimension",
616
- $value: "floor({_size.unit} * 5)"
617
- },
618
- "6": {
619
- $type: "dimension",
620
- $value: "floor({_size.unit} * 6)"
621
- },
622
- "7": {
623
- $type: "dimension",
624
- $value: "floor({_size.unit} * 7)"
625
- },
626
- "8": {
627
- $type: "dimension",
628
- $value: "floor({_size.unit} * 8)"
629
- },
630
- "9": {
631
- $type: "dimension",
632
- $value: "floor({_size.unit} * 9)"
633
- },
634
- "10": {
635
- $type: "dimension",
636
- $value: "floor({_size.unit} * 10)"
637
- },
638
- "11": {
639
- $type: "dimension",
640
- $value: "floor({_size.unit} * 11)"
641
- },
642
- "12": {
643
- $type: "dimension",
644
- $value: "floor({_size.unit} * 12)"
645
- },
646
- "13": {
647
- $type: "dimension",
648
- $value: "floor({_size.unit} * 13)"
649
- },
650
- "14": {
651
- $type: "dimension",
652
- $value: "floor({_size.unit} * 14)"
653
- },
654
- "15": {
655
- $type: "dimension",
656
- $value: "floor({_size.unit} * 15)"
657
- },
658
- "18": {
659
- $type: "dimension",
660
- $value: "floor({_size.unit} * 18)"
661
- },
662
- "22": {
663
- $type: "dimension",
664
- $value: "floor({_size.unit} * 22)"
665
- },
666
- "26": {
667
- $type: "dimension",
668
- $value: "floor({_size.unit} * 26)"
669
- },
670
- "30": {
671
- $type: "dimension",
672
- $value: "floor({_size.unit} * 30)"
673
- },
674
- "mode-font-size": {
675
- $type: "number",
676
- $value: "{size._mode-font-size}"
677
- },
678
- base: {
679
- $type: "number",
680
- $value: "{size._base}"
681
- },
682
- step: {
683
- $type: "number",
684
- $value: "{size._step}"
685
- },
686
- unit: {
687
- $type: "number",
688
- $value: "{_size.step} / {_size.base} * {_size.mode-font-size}"
689
- }
690
- }
691
- };
692
- var sizeModes = {
693
- large: {
694
- size: {
695
- "_mode-font-size": {
696
- $type: "dimension",
697
- $value: "21"
698
- },
699
- _base: {
700
- $type: "dimension",
701
- $value: "18"
702
- },
703
- _step: {
704
- $type: "dimension",
705
- $value: "4"
706
- }
707
- }
708
- },
709
- medium: {
710
- size: {
711
- "_mode-font-size": {
712
- $type: "dimension",
713
- $value: "18"
714
- },
715
- _base: {
716
- $type: "dimension",
717
- $value: "18"
718
- },
719
- _step: {
720
- $type: "dimension",
721
- $value: "4"
722
- }
723
- }
724
- },
725
- small: {
726
- size: {
727
- "_mode-font-size": {
728
- $type: "dimension",
729
- $value: "16"
730
- },
731
- _base: {
732
- $type: "dimension",
733
- $value: "18"
734
- },
735
- _step: {
736
- $type: "dimension",
737
- $value: "4"
738
- }
739
- }
740
- }
741
- };
742
- var generateSize = (size2) => sizeModes[size2];
743
- var generateSizeGlobal = () => global;
744
-
745
- // src/tokens/create/generators/primitives/typography.ts
746
- var generateTypography = (themeName, { fontFamily }) => ({
747
- [themeName]: {
748
- "font-family": {
749
- $type: "fontFamilies",
750
- $value: fontFamily
751
- },
752
- "font-weight": {
753
- medium: {
754
- $type: "fontWeights",
755
- $value: "Medium"
756
- },
757
- semibold: {
758
- $type: "fontWeights",
759
- $value: "Semi bold"
760
- },
761
- regular: {
762
- $type: "fontWeights",
763
- $value: "Regular"
764
- }
765
- }
766
- }
767
- });
768
- var generateFontSizes = (size2) => fontSizes[size2];
769
- var lineHeights = {
770
- sm: {
771
- $type: "lineHeights",
772
- $value: "130%"
773
- },
774
- md: {
775
- $type: "lineHeights",
776
- $value: "150%"
777
- },
778
- lg: {
779
- $type: "lineHeights",
780
- $value: "170%"
781
- }
782
- };
783
- var letterSpacings = {
784
- "1": {
785
- $type: "letterSpacing",
786
- $value: "-1%"
787
- },
788
- "2": {
789
- $type: "letterSpacing",
790
- $value: "-0.5%"
791
- },
792
- "3": {
793
- $type: "letterSpacing",
794
- $value: "-0.25%"
795
- },
796
- "4": {
797
- $type: "letterSpacing",
798
- $value: "-0.15%"
799
- },
800
- "5": {
801
- $type: "letterSpacing",
802
- $value: "0%"
803
- },
804
- "6": {
805
- $type: "letterSpacing",
806
- $value: "0.15%"
807
- },
808
- "7": {
809
- $type: "letterSpacing",
810
- $value: "0.25%"
811
- },
812
- "8": {
813
- $type: "letterSpacing",
814
- $value: "0.5%"
815
- },
816
- "9": {
817
- $type: "letterSpacing",
818
- $value: "1.5%"
819
- }
820
- };
821
- var fontSizes = {
822
- large: {
823
- "line-height": lineHeights,
824
- "font-size": {
825
- "1": {
826
- $type: "fontSizes",
827
- $value: "13"
828
- },
829
- "2": {
830
- $type: "fontSizes",
831
- $value: "16"
832
- },
833
- "3": {
834
- $type: "fontSizes",
835
- $value: "18"
836
- },
837
- "4": {
838
- $type: "fontSizes",
839
- $value: "21"
840
- },
841
- "5": {
842
- $type: "fontSizes",
843
- $value: "24"
844
- },
845
- "6": {
846
- $type: "fontSizes",
847
- $value: "30"
848
- },
849
- "7": {
850
- $type: "fontSizes",
851
- $value: "36"
852
- },
853
- "8": {
854
- $type: "fontSizes",
855
- $value: "48"
856
- },
857
- "9": {
858
- $type: "fontSizes",
859
- $value: "60"
860
- },
861
- "10": {
862
- $type: "fontSizes",
863
- $value: "72"
864
- }
865
- },
866
- "letter-spacing": letterSpacings
867
- },
868
- medium: {
869
- "line-height": lineHeights,
870
- "font-size": {
871
- "1": {
872
- $type: "fontSizes",
873
- $value: "12"
874
- },
875
- "2": {
876
- $type: "fontSizes",
877
- $value: "14"
878
- },
879
- "3": {
880
- $type: "fontSizes",
881
- $value: "16"
882
- },
883
- "4": {
884
- $type: "fontSizes",
885
- $value: "18"
886
- },
887
- "5": {
888
- $type: "fontSizes",
889
- $value: "21"
890
- },
891
- "6": {
892
- $type: "fontSizes",
893
- $value: "24"
894
- },
895
- "7": {
896
- $type: "fontSizes",
897
- $value: "30"
898
- },
899
- "8": {
900
- $type: "fontSizes",
901
- $value: "36"
902
- },
903
- "9": {
904
- $type: "fontSizes",
905
- $value: "48"
906
- },
907
- "10": {
908
- $type: "fontSizes",
909
- $value: "60"
910
- }
911
- },
912
- "letter-spacing": letterSpacings
913
- },
914
- small: {
915
- "line-height": lineHeights,
916
- "font-size": {
917
- "1": {
918
- $type: "fontSizes",
919
- $value: "11"
920
- },
921
- "2": {
922
- $type: "fontSizes",
923
- $value: "13"
924
- },
925
- "3": {
926
- $type: "fontSizes",
927
- $value: "14"
928
- },
929
- "4": {
930
- $type: "fontSizes",
931
- $value: "16"
932
- },
933
- "5": {
934
- $type: "fontSizes",
935
- $value: "18"
936
- },
937
- "6": {
938
- $type: "fontSizes",
939
- $value: "21"
940
- },
941
- "7": {
942
- $type: "fontSizes",
943
- $value: "24"
944
- },
945
- "8": {
946
- $type: "fontSizes",
947
- $value: "30"
948
- },
949
- "9": {
950
- $type: "fontSizes",
951
- $value: "36"
952
- },
953
- "10": {
954
- $type: "fontSizes",
955
- $value: "48"
956
- }
957
- },
958
- "letter-spacing": letterSpacings
959
- }
960
- };
961
-
962
- // src/tokens/create/generators/semantic/color.ts
963
- import * as R5 from "ramda";
964
- var generateSemanticColors = (colors, _themeName) => {
965
- const mainColorNames = Object.keys(colors.main);
966
- const supportColorNames = Object.keys(colors.support);
967
- const customColors = [...mainColorNames, "neutral", ...supportColorNames];
968
- const allColors = [...customColors, ...baseColorNames];
969
- const semanticColorTokens = allColors.map((colorName) => [colorName, generateColorScaleTokens(colorName)]);
970
- return {
971
- ...baseColorTemplate,
972
- color: {
973
- ...Object.fromEntries(semanticColorTokens),
974
- ...baseColorTemplate.color
975
- }
976
- };
977
- };
978
- var baseColorTemplate = {
979
- color: {
980
- focus: {
981
- inner: {
982
- $type: "color",
983
- $value: "{color.focus.inner-color}"
984
- },
985
- outer: {
986
- $type: "color",
987
- $value: "{color.focus.outer-color}"
988
- }
989
- }
990
- },
991
- link: {
992
- color: {
993
- visited: {
994
- $type: "color",
995
- $value: "{color.link.visited}"
996
- }
997
- }
998
- }
999
- };
1000
- var generateColorScaleTokens = (colorName) => {
1001
- const colorScale = {};
1002
- for (const [colorSemantic, colorNumber] of R5.toPairs(semanticColorMap)) {
1003
- colorScale[colorSemantic] = {
1004
- $type: "color",
1005
- $value: `{color.${colorName}.${colorNumber}}`
1006
- };
1007
- }
1008
- return colorScale;
1009
- };
1010
-
1011
- // src/tokens/create/generators/semantic/color-modes.ts
1012
- var generateColorModes = (colors, _themeName) => {
1013
- const mainColorNames = Object.keys(colors.main);
1014
- const supportColorNames = Object.keys(colors.support);
1015
- const modes = {
1016
- "main-color": {},
1017
- "support-color": {}
1018
- };
1019
- const categories = [
1020
- ["main-color", mainColorNames],
1021
- ["support-color", supportColorNames]
1022
- ];
1023
- for (const [colorCategory2, colorNames2] of categories) {
1024
- for (const colorName of colorNames2) {
1025
- const category = colorCategory2.replace("-color", "");
1026
- const customColorTokens = {
1027
- color: {
1028
- [category]: generateColorScaleTokens2(colorName)
1029
- }
1030
- };
1031
- modes[colorCategory2][colorName] = customColorTokens;
1032
- }
1033
- }
1034
- return modes;
1035
- };
1036
- var generateColorScaleTokens2 = (colorName) => {
1037
- const colorScale = {};
1038
- for (const colorSemantic of semanticColorNames) {
1039
- colorScale[colorSemantic] = {
1040
- $type: "color",
1041
- $value: `{color.${colorName}.${colorSemantic}}`
1042
- };
1043
- }
1044
- return colorScale;
1045
- };
1046
-
1047
- // src/tokens/create/generators/semantic/style.ts
1048
- function generateSemanticStyle() {
1049
- return {
1050
- typography: {
1051
- heading: {
1052
- "2xl": {
1053
- $type: "typography",
1054
- $value: {
1055
- fontFamily: "{font-family}",
1056
- fontWeight: "{font-weight.medium}",
1057
- lineHeight: "{line-height.sm}",
1058
- fontSize: "{font-size.10}",
1059
- letterSpacing: "{letter-spacing.1}"
1060
- }
1061
- },
1062
- xl: {
1063
- $type: "typography",
1064
- $value: {
1065
- fontFamily: "{font-family}",
1066
- fontWeight: "{font-weight.medium}",
1067
- lineHeight: "{line-height.sm}",
1068
- fontSize: "{font-size.9}",
1069
- letterSpacing: "{letter-spacing.1}"
1070
- }
1071
- },
1072
- lg: {
1073
- $type: "typography",
1074
- $value: {
1075
- fontFamily: "{font-family}",
1076
- fontWeight: "{font-weight.medium}",
1077
- lineHeight: "{line-height.sm}",
1078
- fontSize: "{font-size.8}",
1079
- letterSpacing: "{letter-spacing.2}"
1080
- }
1081
- },
1082
- md: {
1083
- $type: "typography",
1084
- $value: {
1085
- fontFamily: "{font-family}",
1086
- fontWeight: "{font-weight.medium}",
1087
- lineHeight: "{line-height.sm}",
1088
- fontSize: "{font-size.7}",
1089
- letterSpacing: "{letter-spacing.3}"
1090
- }
1091
- },
1092
- sm: {
1093
- $type: "typography",
1094
- $value: {
1095
- fontFamily: "{font-family}",
1096
- fontWeight: "{font-weight.medium}",
1097
- lineHeight: "{line-height.sm}",
1098
- fontSize: "{font-size.6}",
1099
- letterSpacing: "{letter-spacing.5}"
1100
- }
1101
- },
1102
- xs: {
1103
- $type: "typography",
1104
- $value: {
1105
- fontFamily: "{font-family}",
1106
- fontWeight: "{font-weight.medium}",
1107
- lineHeight: "{line-height.sm}",
1108
- fontSize: "{font-size.5}",
1109
- letterSpacing: "{letter-spacing.6}"
1110
- }
1111
- },
1112
- "2xs": {
1113
- $type: "typography",
1114
- $value: {
1115
- fontFamily: "{font-family}",
1116
- fontWeight: "{font-weight.medium}",
1117
- lineHeight: "{line-height.sm}",
1118
- fontSize: "{font-size.4}",
1119
- letterSpacing: "{letter-spacing.6}"
1120
- }
1121
- }
1122
- },
1123
- body: {
1124
- xl: {
1125
- $type: "typography",
1126
- $value: {
1127
- fontFamily: "{font-family}",
1128
- fontWeight: "{font-weight.regular}",
1129
- lineHeight: "{line-height.md}",
1130
- fontSize: "{font-size.6}",
1131
- letterSpacing: "{letter-spacing.8}"
1132
- }
1133
- },
1134
- lg: {
1135
- $type: "typography",
1136
- $value: {
1137
- fontFamily: "{font-family}",
1138
- fontWeight: "{font-weight.regular}",
1139
- lineHeight: "{line-height.md}",
1140
- fontSize: "{font-size.5}",
1141
- letterSpacing: "{letter-spacing.8}"
1142
- }
1143
- },
1144
- md: {
1145
- $type: "typography",
1146
- $value: {
1147
- fontFamily: "{font-family}",
1148
- fontWeight: "{font-weight.regular}",
1149
- lineHeight: "{line-height.md}",
1150
- fontSize: "{font-size.4}",
1151
- letterSpacing: "{letter-spacing.8}"
1152
- }
1153
- },
1154
- sm: {
1155
- $type: "typography",
1156
- $value: {
1157
- fontFamily: "{font-family}",
1158
- fontWeight: "{font-weight.regular}",
1159
- lineHeight: "{line-height.md}",
1160
- fontSize: "{font-size.3}",
1161
- letterSpacing: "{letter-spacing.7}"
1162
- }
1163
- },
1164
- xs: {
1165
- $type: "typography",
1166
- $value: {
1167
- fontFamily: "{font-family}",
1168
- fontWeight: "{font-weight.regular}",
1169
- lineHeight: "{line-height.md}",
1170
- fontSize: "{font-size.2}",
1171
- letterSpacing: "{letter-spacing.6}"
1172
- }
1173
- },
1174
- short: {
1175
- xl: {
1176
- $type: "typography",
1177
- $value: {
1178
- fontFamily: "{font-family}",
1179
- fontWeight: "{font-weight.regular}",
1180
- lineHeight: "{line-height.sm}",
1181
- fontSize: "{font-size.6}",
1182
- letterSpacing: "{letter-spacing.8}"
1183
- }
1184
- },
1185
- lg: {
1186
- $type: "typography",
1187
- $value: {
1188
- fontFamily: "{font-family}",
1189
- fontWeight: "{font-weight.regular}",
1190
- lineHeight: "{line-height.sm}",
1191
- fontSize: "{font-size.5}",
1192
- letterSpacing: "{letter-spacing.8}"
1193
- }
1194
- },
1195
- md: {
1196
- $type: "typography",
1197
- $value: {
1198
- fontFamily: "{font-family}",
1199
- fontWeight: "{font-weight.regular}",
1200
- lineHeight: "{line-height.sm}",
1201
- fontSize: "{font-size.4}",
1202
- letterSpacing: "{letter-spacing.8}"
1203
- }
1204
- },
1205
- sm: {
1206
- $type: "typography",
1207
- $value: {
1208
- fontFamily: "{font-family}",
1209
- fontWeight: "{font-weight.regular}",
1210
- lineHeight: "{line-height.sm}",
1211
- fontSize: "{font-size.3}",
1212
- letterSpacing: "{letter-spacing.7}"
1213
- }
1214
- },
1215
- xs: {
1216
- $type: "typography",
1217
- $value: {
1218
- fontFamily: "{font-family}",
1219
- fontWeight: "{font-weight.regular}",
1220
- lineHeight: "{line-height.sm}",
1221
- fontSize: "{font-size.2}",
1222
- letterSpacing: "{letter-spacing.6}"
1223
- }
1224
- }
1225
- },
1226
- long: {
1227
- xl: {
1228
- $type: "typography",
1229
- $value: {
1230
- fontFamily: "{font-family}",
1231
- fontWeight: "{font-weight.regular}",
1232
- lineHeight: "{line-height.lg}",
1233
- fontSize: "{font-size.6}",
1234
- letterSpacing: "{letter-spacing.8}"
1235
- }
1236
- },
1237
- lg: {
1238
- $type: "typography",
1239
- $value: {
1240
- fontFamily: "{font-family}",
1241
- fontWeight: "{font-weight.regular}",
1242
- lineHeight: "{line-height.lg}",
1243
- fontSize: "{font-size.5}",
1244
- letterSpacing: "{letter-spacing.8}"
1245
- }
1246
- },
1247
- md: {
1248
- $type: "typography",
1249
- $value: {
1250
- fontFamily: "{font-family}",
1251
- fontWeight: "{font-weight.regular}",
1252
- lineHeight: "{line-height.lg}",
1253
- fontSize: "{font-size.4}",
1254
- letterSpacing: "{letter-spacing.8}"
1255
- }
1256
- },
1257
- sm: {
1258
- $type: "typography",
1259
- $value: {
1260
- fontFamily: "{font-family}",
1261
- fontWeight: "{font-weight.regular}",
1262
- lineHeight: "{line-height.lg}",
1263
- fontSize: "{font-size.3}",
1264
- letterSpacing: "{letter-spacing.7}"
1265
- }
1266
- },
1267
- xs: {
1268
- $type: "typography",
1269
- $value: {
1270
- fontFamily: "{font-family}",
1271
- fontWeight: "{font-weight.regular}",
1272
- lineHeight: "{line-height.lg}",
1273
- fontSize: "{font-size.2}",
1274
- letterSpacing: "{letter-spacing.6}"
1275
- }
1276
- }
1277
- }
1278
- }
1279
- },
1280
- opacity: {
1281
- disabled: {
1282
- $type: "opacity",
1283
- $value: "{opacity.30}"
1284
- }
1285
- },
1286
- "border-width": {
1287
- default: {
1288
- $type: "borderWidth",
1289
- $value: "{border-width.1}"
1290
- },
1291
- focus: {
1292
- $type: "borderWidth",
1293
- $value: "{border-width.3}"
1294
- }
1295
- },
1296
- shadow: {
1297
- xs: {
1298
- $type: "boxShadow",
1299
- $value: "{shadow.100}"
1300
- },
1301
- sm: {
1302
- $type: "boxShadow",
1303
- $value: "{shadow.200}"
1304
- },
1305
- md: {
1306
- $type: "boxShadow",
1307
- $value: "{shadow.300}"
1308
- },
1309
- lg: {
1310
- $type: "boxShadow",
1311
- $value: "{shadow.400}"
1312
- },
1313
- xl: {
1314
- $type: "boxShadow",
1315
- $value: "{shadow.500}"
1316
- }
1317
- },
1318
- "border-radius": {
1319
- sm: {
1320
- $type: "dimension",
1321
- $value: "{border-radius.1}"
1322
- },
1323
- md: {
1324
- $type: "dimension",
1325
- $value: "{border-radius.2}"
1326
- },
1327
- lg: {
1328
- $type: "dimension",
1329
- $value: "{border-radius.3}"
1330
- },
1331
- xl: {
1332
- $type: "dimension",
1333
- $value: "{border-radius.4}"
1334
- },
1335
- default: {
1336
- $type: "dimension",
1337
- $value: "{border-radius.5}"
1338
- },
1339
- full: {
1340
- $type: "dimension",
1341
- $value: "{border-radius.6}"
1342
- }
1343
- },
1344
- size: {
1345
- "0": {
1346
- $type: "dimension",
1347
- $value: "{_size.0}"
1348
- },
1349
- "1": {
1350
- $type: "dimension",
1351
- $value: "{_size.1}"
1352
- },
1353
- "2": {
1354
- $type: "dimension",
1355
- $value: "{_size.2}"
1356
- },
1357
- "3": {
1358
- $type: "dimension",
1359
- $value: "{_size.3}"
1360
- },
1361
- "4": {
1362
- $type: "dimension",
1363
- $value: "{_size.4}"
1364
- },
1365
- "5": {
1366
- $type: "dimension",
1367
- $value: "{_size.5}"
1368
- },
1369
- "6": {
1370
- $type: "dimension",
1371
- $value: "{_size.6}"
1372
- },
1373
- "7": {
1374
- $type: "dimension",
1375
- $value: "{_size.7}"
1376
- },
1377
- "8": {
1378
- $type: "dimension",
1379
- $value: "{_size.8}"
1380
- },
1381
- "9": {
1382
- $type: "dimension",
1383
- $value: "{_size.9}"
1384
- },
1385
- "10": {
1386
- $type: "dimension",
1387
- $value: "{_size.10}"
1388
- },
1389
- "11": {
1390
- $type: "dimension",
1391
- $value: "{_size.11}"
1392
- },
1393
- "12": {
1394
- $type: "dimension",
1395
- $value: "{_size.12}"
1396
- },
1397
- "13": {
1398
- $type: "dimension",
1399
- $value: "{_size.13}"
1400
- },
1401
- "14": {
1402
- $type: "dimension",
1403
- $value: "{_size.14}"
1404
- },
1405
- "15": {
1406
- $type: "dimension",
1407
- $value: "{_size.15}"
1408
- },
1409
- "18": {
1410
- $type: "dimension",
1411
- $value: "{_size.18}"
1412
- },
1413
- "22": {
1414
- $type: "dimension",
1415
- $value: "{_size.22}"
1416
- },
1417
- "26": {
1418
- $type: "dimension",
1419
- $value: "{_size.26}"
1420
- },
1421
- "30": {
1422
- $type: "dimension",
1423
- $value: "{_size.30}"
1424
- }
1425
- }
1426
- };
1427
- }
1428
-
1429
- // src/tokens/create/generators/themes/theme.ts
1430
- import * as R6 from "ramda";
1431
- var generateTheme = (colors, themeName, borderRadius) => {
1432
- const mainColorNames = Object.keys(colors.main);
1433
- const supportColorNames = Object.keys(colors.support);
1434
- const customColors = [...mainColorNames, "neutral", ...supportColorNames, ...baseColorNames];
1435
- const themeColorTokens = Object.fromEntries(
1436
- customColors.map((colorName) => [colorName, generateColorScaleTokens3(colorName, themeName)])
1437
- );
1438
- const { color: themeBaseFileColor, ...remainingThemeFile } = generateBase(themeName);
1439
- const themeFile = {
1440
- color: {
1441
- ...themeColorTokens,
1442
- ...themeBaseFileColor,
1443
- link: {
1444
- visited: {
1445
- $type: "color",
1446
- $value: `{${themeName}.link.visited}`
1447
- }
1448
- },
1449
- focus: {
1450
- "inner-color": {
1451
- $type: "color",
1452
- $value: `{${themeName}.focus.inner}`
1453
- },
1454
- "outer-color": {
1455
- $type: "color",
1456
- $value: `{${themeName}.focus.outer}`
1457
- }
1458
- }
1459
- },
1460
- ...remainingThemeFile
1461
- };
1462
- const baseBorderRadius = R6.lensPath(["border-radius", "base", "$value"]);
1463
- const updatedThemeFile = R6.set(baseBorderRadius, String(borderRadius), themeFile);
1464
- const token = JSON.parse(
1465
- JSON.stringify(
1466
- updatedThemeFile,
1467
- (key, value) => {
1468
- if (key === "$value") {
1469
- return value.replace("<theme>", themeName);
1470
- }
1471
- return value;
1472
- },
1473
- 2
1474
- )
1475
- );
1476
- return token;
1477
- };
1478
- var generateBase = (themeName) => ({
1479
- color: {},
1480
- "font-family": {
1481
- $type: "fontFamilies",
1482
- $value: `{${themeName}.font-family}`
1483
- },
1484
- "font-weight": {
1485
- medium: {
1486
- $type: "fontWeights",
1487
- $value: `{${themeName}.font-weight.medium}`
1488
- },
1489
- semibold: {
1490
- $type: "fontWeights",
1491
- $value: `{${themeName}.font-weight.semibold}`
1492
- },
1493
- regular: {
1494
- $type: "fontWeights",
1495
- $value: `{${themeName}.font-weight.regular}`
1496
- }
1497
- },
1498
- "border-radius": {
1499
- "1": {
1500
- $type: "dimension",
1501
- $value: "min({border-radius.base}*0.5,{border-radius.scale})"
1502
- },
1503
- "2": {
1504
- $type: "dimension",
1505
- $value: "min({border-radius.base},{border-radius.scale}*2)"
1506
- },
1507
- "3": {
1508
- $type: "dimension",
1509
- $value: "min({border-radius.base}*2,{border-radius.scale}*5)"
1510
- },
1511
- "4": {
1512
- $type: "dimension",
1513
- $value: "min({border-radius.base}*3,{border-radius.scale}*7)"
1514
- },
1515
- "5": {
1516
- $type: "dimension",
1517
- $value: "{border-radius.base}"
1518
- },
1519
- "6": {
1520
- $type: "dimension",
1521
- $value: "9999"
1522
- },
1523
- base: {
1524
- $type: "dimension",
1525
- $value: "4"
1526
- },
1527
- scale: {
1528
- $type: "dimension",
1529
- $value: "4"
1530
- }
1531
- }
1532
- });
1533
- var generateColorScaleTokens3 = (colorName, themeName) => {
1534
- const colorScale = {};
1535
- for (const [_, colorNumber] of R6.toPairs(semanticColorMap)) {
1536
- colorScale[colorNumber] = {
1537
- $type: "color",
1538
- $value: `{${themeName}.${colorName}.${colorNumber}}`
1539
- };
1540
- }
1541
- return colorScale;
1542
- };
1543
-
1544
- // src/tokens/create.ts
1545
- var cliOptions = {
1546
- outDir: "out-dir",
1547
- clean: "clean",
1548
- tailwind: "tailwind",
1549
- theme: {
1550
- colors: {
1551
- main: "main-colors",
1552
- support: "support-colors",
1553
- neutral: "neutral-color"
1554
- },
1555
- typography: {
1556
- fontFamily: "font-family"
1557
- },
1558
- borderRadius: "border-radius"
1559
- }
1560
- };
1561
- var createTokens = async (theme) => {
1562
- const { colors, typography: typography2, name, borderRadius, overrides } = theme;
1563
- const colorSchemes = ["light", "dark"];
1564
- const sizeModes2 = ["small", "medium", "large"];
1565
- const tokenSets = new Map([
1566
- ["primitives/globals", generateGlobals()],
1567
- ...sizeModes2.map((size2) => [`primitives/modes/size/${size2}`, generateSize(size2)]),
1568
- ["primitives/modes/size/global", generateSizeGlobal()],
1569
- ...sizeModes2.map((size2) => [
1570
- `primitives/modes/typography/size/${size2}`,
1571
- generateFontSizes(size2)
1572
- ]),
1573
- [`primitives/modes/typography/primary/${name}`, generateTypography(name, typography2)],
1574
- [`primitives/modes/typography/secondary/${name}`, generateTypography(name, typography2)],
1575
- ...colorSchemes.flatMap((scheme) => [
1576
- [`primitives/modes/color-scheme/${scheme}/${name}`, generateColorScheme(name, scheme, colors, overrides)]
1577
- ]),
1578
- [`themes/${name}`, generateTheme(colors, name, borderRadius)],
1579
- ["semantic/color", generateSemanticColors(colors, name)],
1580
- // maps out semantic modes, ieg 'semantic/modes/main-color/accent', and 'semantic/modes/support-color/brand1'
1581
- ...Object.entries(generateColorModes(colors, name)).flatMap(
1582
- ([mode, colors2]) => Object.entries(colors2).map(([key, colorSet]) => [`semantic/modes/${mode}/${key}`, colorSet])
1583
- ),
1584
- [`semantic/style`, generateSemanticStyle()]
1585
- ]);
1586
- return { tokenSets };
1587
- };
1588
-
1589
- // src/tokens/format.ts
1590
- import * as R23 from "ramda";
1591
-
1592
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
1593
- var BoxShadowTypes;
1594
- (function(BoxShadowTypes2) {
1595
- BoxShadowTypes2["DROP_SHADOW"] = "dropShadow";
1596
- BoxShadowTypes2["INNER_SHADOW"] = "innerShadow";
1597
- })(BoxShadowTypes || (BoxShadowTypes = {}));
1598
-
1599
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
1600
- var ColorModifierTypes;
1601
- (function(ColorModifierTypes2) {
1602
- ColorModifierTypes2["LIGHTEN"] = "lighten";
1603
- ColorModifierTypes2["DARKEN"] = "darken";
1604
- ColorModifierTypes2["MIX"] = "mix";
1605
- ColorModifierTypes2["ALPHA"] = "alpha";
1606
- })(ColorModifierTypes || (ColorModifierTypes = {}));
1607
-
1608
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
1609
- var ColorSpaceTypes;
1610
- (function(ColorSpaceTypes2) {
1611
- ColorSpaceTypes2["LCH"] = "lch";
1612
- ColorSpaceTypes2["SRGB"] = "srgb";
1613
- ColorSpaceTypes2["P3"] = "p3";
1614
- ColorSpaceTypes2["HSL"] = "hsl";
1615
- })(ColorSpaceTypes || (ColorSpaceTypes = {}));
1616
-
1617
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js
1618
- var Properties;
1619
- (function(Properties2) {
1620
- Properties2["sizing"] = "sizing";
1621
- Properties2["height"] = "height";
1622
- Properties2["width"] = "width";
1623
- Properties2["spacing"] = "spacing";
1624
- Properties2["verticalPadding"] = "verticalPadding";
1625
- Properties2["horizontalPadding"] = "horizontalPadding";
1626
- Properties2["paddingTop"] = "paddingTop";
1627
- Properties2["paddingRight"] = "paddingRight";
1628
- Properties2["paddingBottom"] = "paddingBottom";
1629
- Properties2["paddingLeft"] = "paddingLeft";
1630
- Properties2["itemSpacing"] = "itemSpacing";
1631
- Properties2["fill"] = "fill";
1632
- Properties2["backgroundBlur"] = "backgroundBlur";
1633
- Properties2["border"] = "border";
1634
- Properties2["borderTop"] = "borderTop";
1635
- Properties2["borderRight"] = "borderRight";
1636
- Properties2["borderBottom"] = "borderBottom";
1637
- Properties2["borderLeft"] = "borderLeft";
1638
- Properties2["borderColor"] = "borderColor";
1639
- Properties2["borderRadius"] = "borderRadius";
1640
- Properties2["borderRadiusTopLeft"] = "borderRadiusTopLeft";
1641
- Properties2["borderRadiusTopRight"] = "borderRadiusTopRight";
1642
- Properties2["borderRadiusBottomRight"] = "borderRadiusBottomRight";
1643
- Properties2["borderRadiusBottomLeft"] = "borderRadiusBottomLeft";
1644
- Properties2["borderWidth"] = "borderWidth";
1645
- Properties2["borderWidthTop"] = "borderWidthTop";
1646
- Properties2["borderWidthRight"] = "borderWidthRight";
1647
- Properties2["borderWidthBottom"] = "borderWidthBottom";
1648
- Properties2["borderWidthLeft"] = "borderWidthLeft";
1649
- Properties2["boxShadow"] = "boxShadow";
1650
- Properties2["opacity"] = "opacity";
1651
- Properties2["fontFamilies"] = "fontFamilies";
1652
- Properties2["fontWeights"] = "fontWeights";
1653
- Properties2["fontSizes"] = "fontSizes";
1654
- Properties2["lineHeights"] = "lineHeights";
1655
- Properties2["typography"] = "typography";
1656
- Properties2["composition"] = "composition";
1657
- Properties2["letterSpacing"] = "letterSpacing";
1658
- Properties2["paragraphSpacing"] = "paragraphSpacing";
1659
- Properties2["textCase"] = "textCase";
1660
- Properties2["dimension"] = "dimension";
1661
- Properties2["textDecoration"] = "textDecoration";
1662
- Properties2["asset"] = "asset";
1663
- Properties2["tokenValue"] = "tokenValue";
1664
- Properties2["value"] = "value";
1665
- Properties2["tokenName"] = "tokenName";
1666
- Properties2["description"] = "description";
1667
- })(Properties || (Properties = {}));
1668
-
1669
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
1670
- var TokenSetStatus;
1671
- (function(TokenSetStatus2) {
1672
- TokenSetStatus2["DISABLED"] = "disabled";
1673
- TokenSetStatus2["SOURCE"] = "source";
1674
- TokenSetStatus2["ENABLED"] = "enabled";
1675
- })(TokenSetStatus || (TokenSetStatus = {}));
1676
-
1677
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
1678
- var TokenTypes;
1679
- (function(TokenTypes2) {
1680
- TokenTypes2["OTHER"] = "other";
1681
- TokenTypes2["COLOR"] = "color";
1682
- TokenTypes2["BORDER_RADIUS"] = "borderRadius";
1683
- TokenTypes2["SIZING"] = "sizing";
1684
- TokenTypes2["SPACING"] = "spacing";
1685
- TokenTypes2["TEXT"] = "text";
1686
- TokenTypes2["TYPOGRAPHY"] = "typography";
1687
- TokenTypes2["OPACITY"] = "opacity";
1688
- TokenTypes2["BORDER_WIDTH"] = "borderWidth";
1689
- TokenTypes2["STROKE_STYLE"] = "strokeStyle";
1690
- TokenTypes2["BOX_SHADOW"] = "boxShadow";
1691
- TokenTypes2["FONT_FAMILIES"] = "fontFamilies";
1692
- TokenTypes2["FONT_WEIGHTS"] = "fontWeights";
1693
- TokenTypes2["LINE_HEIGHTS"] = "lineHeights";
1694
- TokenTypes2["FONT_SIZES"] = "fontSizes";
1695
- TokenTypes2["LETTER_SPACING"] = "letterSpacing";
1696
- TokenTypes2["PARAGRAPH_SPACING"] = "paragraphSpacing";
1697
- TokenTypes2["PARAGRAPH_INDENT"] = "paragraphIndent";
1698
- TokenTypes2["TEXT_DECORATION"] = "textDecoration";
1699
- TokenTypes2["TEXT_CASE"] = "textCase";
1700
- TokenTypes2["COMPOSITION"] = "composition";
1701
- TokenTypes2["DIMENSION"] = "dimension";
1702
- TokenTypes2["BORDER"] = "border";
1703
- TokenTypes2["ASSET"] = "asset";
1704
- TokenTypes2["BOOLEAN"] = "boolean";
1705
- TokenTypes2["NUMBER"] = "number";
1706
- })(TokenTypes || (TokenTypes = {}));
1707
-
1708
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js
1709
- var BorderValues;
1710
- (function(BorderValues2) {
1711
- BorderValues2["BORDER_COLOR"] = "color";
1712
- BorderValues2["BORDER_WIDTH"] = "width";
1713
- BorderValues2["BORDER_STYLE"] = "style";
1714
- })(BorderValues || (BorderValues = {}));
1715
-
1716
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
1717
- var StrokeStyleValues;
1718
- (function(StrokeStyleValues2) {
1719
- StrokeStyleValues2["SOLID"] = "solid";
1720
- StrokeStyleValues2["DASHED"] = "dashed";
1721
- StrokeStyleValues2["DOTTED"] = "dotted";
1722
- StrokeStyleValues2["DOUBLE"] = "double";
1723
- StrokeStyleValues2["GROOVE"] = "groove";
1724
- StrokeStyleValues2["RIDGE"] = "ridge";
1725
- StrokeStyleValues2["OUTSET"] = "outset";
1726
- StrokeStyleValues2["INSET"] = "inset";
1727
- })(StrokeStyleValues || (StrokeStyleValues = {}));
1728
-
1729
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
1730
- var BoxShadowValues;
1731
- (function(BoxShadowValues2) {
1732
- BoxShadowValues2["TYPE"] = "type";
1733
- BoxShadowValues2["COLOR"] = "color";
1734
- BoxShadowValues2["X"] = "x";
1735
- BoxShadowValues2["Y"] = "y";
1736
- BoxShadowValues2["BLUR"] = "blur";
1737
- BoxShadowValues2["SPREAD"] = "spread";
1738
- BoxShadowValues2["BLEND_MODE"] = "blendMode";
1739
- })(BoxShadowValues || (BoxShadowValues = {}));
1740
-
1741
- // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
1742
- var TypographyValues;
1743
- (function(TypographyValues2) {
1744
- TypographyValues2["FONT_FAMILY"] = "fontFamily";
1745
- TypographyValues2["FONT_WEIGHT"] = "fontWeight";
1746
- TypographyValues2["LINE_HEIGHT"] = "lineHeight";
1747
- TypographyValues2["FONT_SIZE"] = "fontSize";
1748
- TypographyValues2["LETTER_SPACING"] = "letterSpacing";
1749
- TypographyValues2["PARAGRAPH_SPACING"] = "paragraphSpacing";
1750
- TypographyValues2["PARAGRAPH_INDENT"] = "paragraphIndent";
1751
- TypographyValues2["TEXT_DECORATION"] = "textDecoration";
1752
- TypographyValues2["TEXT_CASE"] = "textCase";
1753
- })(TypographyValues || (TypographyValues = {}));
1754
-
1755
- // src/tokens/create/generators/$themes.ts
1756
- var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
1757
- async function createHash(text, algo = "SHA-1") {
1758
- const crypto = globalThis.crypto;
1759
- return Array.from(
1760
- new Uint8Array(await crypto.subtle.digest(algo, new TextEncoder().encode(text))),
1761
- (byte) => byte.toString(16).padStart(2, "0")
1762
- ).join("");
1763
- }
1764
- async function generate$Themes(colorSchemes, themes, colors, sizeModes2) {
1765
- return [
1766
- ...generateSizeGroup(sizeModes2),
1767
- ...await generateThemesGroup(themes),
1768
- ...generateTypographyGroup(themes),
1769
- ...generateColorSchemesGroup(colorSchemes, themes),
1770
- generateSemanticGroup(),
1771
- ...await generateColorGroup("main", colors),
1772
- ...await generateColorGroup("support", colors)
1773
- ];
1774
- }
1775
- function generateSizeGroup(_sizes) {
1776
- return [
1777
- {
1778
- id: "8b2c8cc86611a34b135cb22948666779361fd729",
1779
- name: "medium",
1780
- $figmaStyleReferences: {},
1781
- selectedTokenSets: {
1782
- "primitives/modes/size/medium": TokenSetStatus.SOURCE,
1783
- "primitives/modes/size/global": TokenSetStatus.ENABLED,
1784
- "primitives/modes/typography/size/medium": TokenSetStatus.ENABLED
1785
- },
1786
- $figmaCollectionId: "VariableCollectionId:36248:20757",
1787
- $figmaModeId: "41630:1",
1788
- group: "Size"
1789
- },
1790
- {
1791
- id: "d49b9eebeb48a4f165a74b7261733d0a73370f0e",
1792
- name: "large",
1793
- $figmaStyleReferences: {},
1794
- selectedTokenSets: {
1795
- "primitives/modes/size/large": TokenSetStatus.SOURCE,
1796
- "primitives/modes/size/global": TokenSetStatus.ENABLED,
1797
- "primitives/modes/typography/size/large": TokenSetStatus.ENABLED
1798
- },
1799
- $figmaCollectionId: "VariableCollectionId:36248:20757",
1800
- $figmaModeId: "41630:2",
1801
- group: "Size"
1802
- },
1803
- {
1804
- id: "fb11567729c298ca37c9da4e3a27716a23480824",
1805
- name: "small",
1806
- $figmaStyleReferences: {},
1807
- selectedTokenSets: {
1808
- "primitives/modes/size/small": TokenSetStatus.SOURCE,
1809
- "primitives/modes/size/global": TokenSetStatus.ENABLED,
1810
- "primitives/modes/typography/size/small": TokenSetStatus.ENABLED
1811
- },
1812
- $figmaCollectionId: "VariableCollectionId:36248:20757",
1813
- $figmaModeId: "41630:3",
1814
- group: "Size"
1815
- }
1816
- ];
1817
- }
1818
- var colorSchemeDefaults = {
1819
- light: {
1820
- name: "Light",
1821
- selectedTokenSets: {},
1822
- id: "0daa3ca0b427b9349da7e7dc00101b5668972926",
1823
- $figmaCollectionId: "VariableCollectionId:34811:5472",
1824
- $figmaModeId: "34811:0"
1825
- },
1826
- dark: {
1827
- name: "Dark",
1828
- selectedTokenSets: {},
1829
- id: "9ebd8aed52afbffc17e2666e8b4653a53498b257",
1830
- $figmaCollectionId: "VariableCollectionId:34811:5472",
1831
- $figmaModeId: "34811:1"
1832
- },
1833
- contrast: {
1834
- name: "Contrast",
1835
- selectedTokenSets: {},
1836
- id: "9ebd8aed52afbffc17e2666e8b4653a53498b123",
1837
- $figmaCollectionId: "VariableCollectionId:34811:5472",
1838
- $figmaModeId: "34811:2"
1839
- }
1840
- };
1841
- function generateColorSchemesGroup(colorSchemes, themes) {
1842
- return colorSchemes.map(
1843
- (scheme) => ({
1844
- ...colorSchemeDefaults[scheme],
1845
- selectedTokenSets: Object.fromEntries([
1846
- ...themes.map((theme) => [`primitives/modes/color-scheme/${scheme}/${theme}`, TokenSetStatus.ENABLED])
1847
- ]),
1848
- group: "Color scheme"
1849
- })
1850
- );
1851
- }
1852
- async function generateThemesGroup(themes) {
1853
- return Promise.all(
1854
- themes.map(
1855
- async (theme, index) => ({
1856
- id: await createHash(theme),
1857
- $figmaCollectionId: "VariableCollectionId:36528:61712",
1858
- $figmaModeId: `40960:${index + 6}`,
1859
- // Start on 6 in Token Studio and Community file for some reason
1860
- name: theme,
1861
- selectedTokenSets: {
1862
- [`themes/${theme}`]: TokenSetStatus.ENABLED
1863
- },
1864
- group: "Theme"
1865
- })
1866
- )
1867
- );
1868
- }
1869
- function generateSemanticGroup() {
1870
- return {
1871
- id: "541629445ef90ad5363f9e88f52a1ccb617e6f84",
1872
- name: "Semantic",
1873
- selectedTokenSets: {
1874
- "semantic/style": TokenSetStatus.ENABLED,
1875
- "semantic/color": TokenSetStatus.ENABLED,
1876
- "primitives/globals": TokenSetStatus.SOURCE
1877
- },
1878
- $figmaCollectionId: "VariableCollectionId:34811:5976",
1879
- $figmaModeId: "34811:5",
1880
- group: "Semantic"
1881
- };
1882
- }
1883
- async function generateColorGroup(group, colors) {
1884
- return Promise.all(
1885
- Object.entries(colors[group]).map(
1886
- async ([color]) => ({
1887
- id: await createHash(`${group}-${color}`),
1888
- name: color,
1889
- selectedTokenSets: {
1890
- [`semantic/modes/${group}-color/${color}`]: TokenSetStatus.ENABLED
1891
- },
1892
- group: `${capitalize(group)} color`
1893
- })
1894
- )
1895
- );
1896
- }
1897
- function generateTypographyGroup(themes) {
1898
- return [
1899
- {
1900
- id: "368d753fcac4455f289500eaa42e70dc0a03522f",
1901
- $figmaCollectionId: "VariableCollectionId:36248:20769",
1902
- $figmaModeId: "36248:2",
1903
- name: "Primary",
1904
- selectedTokenSets: Object.fromEntries(
1905
- themes.map((theme) => [`primitives/modes/typography/primary/${theme}`, TokenSetStatus.ENABLED])
1906
- ),
1907
- group: "Typography"
1908
- },
1909
- {
1910
- id: "264b8bd1d40b364e1ea3acf09e49795ddd4c513c",
1911
- $figmaCollectionId: "VariableCollectionId:36248:20769",
1912
- $figmaModeId: "36248:3",
1913
- name: "Secondary",
1914
- selectedTokenSets: Object.fromEntries(
1915
- themes.map((theme) => [`primitives/modes/typography/secondary/${theme}`, TokenSetStatus.ENABLED])
1916
- ),
1917
- group: "Typography"
1918
- }
1919
- ];
1920
- }
1921
-
1922
- // src/tokens/process/output/theme.ts
1923
- import pc from "picocolors";
1924
- import * as R8 from "ramda";
1925
-
1926
- // package.json
1927
- var package_default = {
1928
- name: "@digdir/designsystemet",
1929
- version: "1.13.2",
1930
- description: "CLI for Designsystemet",
1931
- author: "Designsystemet team",
1932
- engines: {
1933
- node: ">=20.20.2"
1934
- },
1935
- repository: {
1936
- type: "git",
1937
- url: "git+https://github.com/digdir/designsystemet.git"
1938
- },
1939
- homepage: "https://github.com/digdir/designsystemet/tree/main/packages/cli",
1940
- license: "MIT",
1941
- type: "module",
1942
- main: "./dist/src/index.js",
1943
- files: [
1944
- "./dist/**",
1945
- "./configs/**"
1946
- ],
1947
- bin: "dist/bin/designsystemet.js",
1948
- exports: {
1949
- ".": {
1950
- import: "./dist/src/index.js"
1951
- },
1952
- "./color": {
1953
- import: "./dist/src/colors/index.js"
1954
- },
1955
- "./tokens": {
1956
- import: "./dist/src/tokens/index.js"
1957
- },
1958
- "./types": {
1959
- import: "./dist/src/types.js"
1960
- }
1961
- },
1962
- publishConfig: {
1963
- access: "public"
1964
- },
1965
- scripts: {
1966
- designsystemet: "tsx ./bin/designsystemet.ts",
1967
- "designsystemet:inspect": "tsx --inspect-brk ./bin/designsystemet.ts",
1968
- build: "tsup && pnpm build:types && pnpm build:json-schema",
1969
- "build:types": "tsc --emitDeclarationOnly --declaration",
1970
- "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
1971
- types: "tsc --noEmit",
1972
- "test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
1973
- "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
1974
- "test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
1975
- "test:tokens-build-tailwind": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean --experimental-tailwind",
1976
- "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
1977
- "test:tokens-build-config:inspect": "pnpm run designsystemet:inspect tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
1978
- "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
1979
- "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
1980
- "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
1981
- "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../design-tokens --dry",
1982
- test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
1983
- "update:preview-tokens": "tsx ./src/scripts/update-preview-tokens.ts",
1984
- verify: "pnpm test && pnpm update:template && pnpm --filter @internal/digdir update:theme-digdir"
1985
- },
1986
- dependencies: {
1987
- "@commander-js/extra-typings": "^14.0.0",
1988
- "@digdir/designsystemet-types": "workspace:",
1989
- "@tokens-studio/sd-transforms": "2.0.3",
1990
- "chroma-js": "^3.2.0",
1991
- "colorjs.io": "^0.6.1",
1992
- commander: "^14.0.3",
1993
- "fast-glob": "^3.3.3",
1994
- hsluv: "^1.0.1",
1995
- "object-hash": "^3.0.0",
1996
- picocolors: "^1.1.1",
1997
- postcss: "^8.5.8",
1998
- ramda: "^0.32.0",
1999
- "style-dictionary": "^5.4.0",
2000
- zod: "^4.3.6",
2001
- "zod-validation-error": "^5.0.0"
2002
- },
2003
- devDependencies: {
2004
- "@tokens-studio/types": "0.5.2",
2005
- "@types/chroma-js": "3.1.2",
2006
- "@types/node": "24.12.2",
2007
- "@types/object-hash": "3.0.6",
2008
- "@types/ramda": "0.31.1",
2009
- tsup: "8.5.1",
2010
- tsx: "4.21.0",
2011
- typescript: "5.9.3"
2012
- }
2013
- };
2014
-
2015
- // src/tokens/utils.ts
2016
- import * as R7 from "ramda";
2017
-
2018
- // src/tokens/types.ts
2019
- var colorCategories = {
2020
- main: "main",
2021
- support: "support"
2022
- };
2023
-
2024
- // src/tokens/utils.ts
2025
- var mapToLowerCase = R7.map(R7.toLower);
2026
- var hasAnyTruth = R7.any(R7.equals(true));
2027
- var getType = (token) => (token.$type ?? token.type) || "";
2028
- var getValue = (token) => token.$value ?? token.value;
2029
- var typeEquals = R7.curry(
2030
- (types, token) => {
2031
- if (R7.isNil(token)) {
2032
- return false;
2033
- }
2034
- return R7.includes(R7.toLower(getType(token)), R7.map(R7.toLower, Array.isArray(types) ? types : [types]));
2035
- }
2036
- );
2037
- var pathStartsWithOneOf = R7.curry(
2038
- (paths, token) => {
2039
- if (R7.isNil(token)) {
2040
- return false;
2041
- }
2042
- const tokenPath = mapToLowerCase(token.path);
2043
- const matchPathsStartingWith = R7.map((pathOrString) => {
2044
- const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
2045
- return R7.startsWith(mapToLowerCase(path), tokenPath);
2046
- }, paths);
2047
- return hasAnyTruth(matchPathsStartingWith);
2048
- }
2049
- );
2050
- function isSemanticToken(token) {
2051
- return token.filePath.includes("semantic/");
2052
- }
2053
- function isSemanticColorToken(token, color) {
2054
- return token.filePath.includes("semantic/") && R7.startsWith(["color", color], token.path);
2055
- }
2056
- function isGlobalColorToken(token) {
2057
- return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
2058
- }
2059
- function isColorCategoryToken(token, category) {
2060
- if (!category) {
2061
- return Object.keys(colorCategories).some(
2062
- (colorCategory2) => isColorCategoryToken(token, colorCategory2)
2063
- );
2064
- }
2065
- return R7.startsWith(["color", category], token.path);
2066
- }
2067
- var isDigit = (s) => /^\d+$/.test(s);
2068
- function traverseObj(obj, fn) {
2069
- for (const key in obj) {
2070
- const prop3 = obj[key];
2071
- if (prop3 != null) {
2072
- fn.apply(null, [obj, key, prop3]);
2073
- if (typeof prop3 === "object") {
2074
- traverseObj(prop3, fn);
2075
- }
2076
- }
2077
- }
2078
- return obj;
2079
- }
2080
- function inlineTokens(shouldInline, tokens) {
2081
- const [inlineableTokens, otherTokens] = R7.partition(shouldInline, tokens);
2082
- return otherTokens.map((token) => {
2083
- let transformed = getValue(token.original);
2084
- for (const ref of inlineableTokens) {
2085
- const refName = ref.path.join(".");
2086
- if (typeof transformed === "string") {
2087
- transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
2088
- }
2089
- }
2090
- const tokenWithInlinedRefs = R7.set(R7.lensPath(["original", "$value"]), transformed, token);
2091
- return tokenWithInlinedRefs;
2092
- });
2093
- }
2094
- var sizeMap = {
2095
- xsmall: "xs",
2096
- small: "sm",
2097
- medium: "md",
2098
- large: "lg",
2099
- xlarge: "xl"
2100
- };
2101
- function shortSizeName(size2) {
2102
- return sizeMap[size2] ?? size2;
2103
- }
2104
- var sizeComparator = (size2) => {
2105
- const sortIndex = Object.entries(sizeMap).findIndex(([key, val]) => key === size2 || val === size2);
2106
- return sortIndex ?? 0;
2107
- };
2108
- function orderBySize(sizes) {
2109
- return R7.sortBy(sizeComparator, sizes);
2110
- }
2111
-
2112
- // src/tokens/process/output/theme.ts
2113
- var defaultFileHeader = `build: v${package_default.version}`;
2114
- var getFileNameWithoutExtension = (path) => {
2115
- const pathSegments = path.split("/");
2116
- return pathSegments[pathSegments.length - 1].split(".").slice(0, -1).join(".");
2117
- };
2118
- var createThemeCSSFiles = ({
2119
- processedBuilds,
2120
- fileHeader = defaultFileHeader
2121
- }) => {
2122
- const groupedByTheme = {};
2123
- for (const [_, buildResults] of Object.entries(processedBuilds)) {
2124
- for (const buildResult of buildResults) {
2125
- const themeName = buildResult.permutation.theme;
2126
- const newOutputs = buildResult.formatted;
2127
- if (R8.isNotEmpty(newOutputs)) {
2128
- const currentOutputs = groupedByTheme[themeName] ?? [];
2129
- groupedByTheme[themeName] = R8.concat(currentOutputs, newOutputs);
2130
- }
2131
- }
2132
- }
2133
- const sortOrder = [
2134
- "size-mode/",
2135
- "type-scale",
2136
- "color-scheme/light",
2137
- "typography/secondary",
2138
- "size",
2139
- "semantic",
2140
- "color-scheme/dark",
2141
- "color-scheme/contrast",
2142
- "typography/primary",
2143
- "color/"
2144
- ];
2145
- const sortByDefinedOrder = R8.sortBy((file) => {
2146
- const filePath = file.destination || "";
2147
- const sortIndex = sortOrder.findIndex((sortElement) => {
2148
- if (sortElement.endsWith("/")) {
2149
- return filePath.includes(sortElement);
2150
- }
2151
- return filePath.includes(`${sortElement}.css`);
2152
- });
2153
- if (sortIndex === -1) {
2154
- console.error(
2155
- pc.yellow(`WARNING: CSS section does not have a defined sort order: ${filePath.replace(".css", "")}`)
2156
- );
2157
- console.log(
2158
- pc.dim(
2159
- `
2160
- The section will currently be added to the end of the entry file, but the exact
2161
- order may change due to nondeterminism.`.trim()
2162
- )
2163
- );
2164
- return Infinity;
2165
- }
2166
- return sortIndex;
2167
- });
2168
- const header = `@charset "UTF-8";
2169
- /*
2170
- ${fileHeader}
2171
- */
2172
-
2173
- `;
2174
- const sortAlphabetically = R8.sort(R8.ascend((x) => x.destination || ""));
2175
- const sortBySize = R8.sortBy(
2176
- R8.pipe((s) => getFileNameWithoutExtension(s.destination ?? ""), sizeComparator)
2177
- );
2178
- const pickOutputs = R8.map(R8.view(R8.lensProp("output")));
2179
- const themeCSSFile = R8.pipe(
2180
- sortAlphabetically,
2181
- sortBySize,
2182
- sortByDefinedOrder,
2183
- pickOutputs,
2184
- R8.join("\n"),
2185
- (content) => header + content
2186
- );
2187
- const themeCSSFiles = Object.entries(groupedByTheme).map(([theme, files]) => ({
2188
- destination: `${theme}.css`,
2189
- output: themeCSSFile(files)
2190
- }));
2191
- return themeCSSFiles;
2192
- };
2193
-
2194
- // src/tokens/process/platform.ts
2195
- import pc3 from "picocolors";
2196
- import * as R22 from "ramda";
2197
- import StyleDictionary2 from "style-dictionary";
2198
-
2199
- // src/tokens/process/configs.ts
2200
- import { register } from "@tokens-studio/sd-transforms";
2201
- import * as R21 from "ramda";
2202
- import StyleDictionary from "style-dictionary";
2203
-
2204
- // src/tokens/process/configs/color.ts
2205
- import * as R16 from "ramda";
2206
-
2207
- // src/tokens/process/formats/css/color.ts
2208
- import * as R9 from "ramda";
2209
- import { createPropertyFormatter } from "style-dictionary/utils";
2210
- var prefersColorScheme = (colorScheme2, content) => `
2211
- @media (prefers-color-scheme: ${colorScheme2}) {
2212
- [data-color-scheme="auto"] ${content}
2213
- }
2214
- `;
2215
- var colorScheme = {
2216
- name: "ds/css-colorscheme",
2217
- format: async ({ dictionary, options, platform }) => {
2218
- const { allTokens } = dictionary;
2219
- const { outputReferences, usesDtcg } = options;
2220
- const { selector, colorScheme: colorScheme2, layer } = platform;
2221
- const colorScheme_ = colorScheme2;
2222
- const format = createPropertyFormatter({
2223
- outputReferences,
2224
- dictionary,
2225
- format: "css",
2226
- usesDtcg
2227
- });
2228
- const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
2229
- color-scheme: ${colorScheme_};
2230
- ` : "";
2231
- const filteredAllTokens = allTokens.filter(
2232
- R9.allPass([
2233
- R9.anyPass([
2234
- // Include semantic tokens in the output
2235
- isSemanticToken,
2236
- // Include global color tokens
2237
- isGlobalColorToken
2238
- ]),
2239
- // Don't include color category tokens -- they are exported separately
2240
- (t) => !isColorCategoryToken(t)
2241
- ])
2242
- );
2243
- const formattedMap = filteredAllTokens.map((token) => ({
2244
- token,
2245
- formatted: format(token)
2246
- }));
2247
- const formattedTokens = formattedMap.map(R9.view(R9.lensProp("formatted"))).join("\n");
2248
- const content = `{
2249
- ${formattedTokens}
2250
- ${colorSchemeProperty}}
2251
- `;
2252
- const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
2253
- const body = R9.isNotNil(layer) ? `@layer ${layer} {
2254
- ${selector} ${content} ${autoSelectorContent}
2255
- }
2256
- ` : `${selector} ${content} ${autoSelectorContent}
2257
- `;
2258
- return body;
2259
- }
2260
- };
2261
- var colorCategory = {
2262
- name: "ds/css-colorcategory",
2263
- format: async ({ dictionary, file, options, platform }) => {
2264
- const { outputReferences, usesDtcg } = options;
2265
- const { selector, layer } = platform;
2266
- const destination = file.destination;
2267
- const format = R9.compose(
2268
- createPropertyFormatter({
2269
- outputReferences,
2270
- dictionary,
2271
- format: "css",
2272
- usesDtcg
2273
- }),
2274
- (token) => ({
2275
- ...token,
2276
- name: token.name.replace(/color-\w+-/, "color-"),
2277
- original: {
2278
- ...token.original,
2279
- $value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
2280
- }
2281
- })
2282
- );
2283
- const formattedMap = dictionary.allTokens.map((token) => ({
2284
- token,
2285
- formatted: format(token)
2286
- }));
2287
- buildOptions.buildTokenFormats[destination] = formattedMap;
2288
- const formattedTokens = formattedMap.map(R9.view(R9.lensProp("formatted"))).join("\n");
2289
- const content = `{
2290
- ${formattedTokens}
2291
- }
2292
- `;
2293
- const body = R9.isNotNil(layer) ? `@layer ${layer} {
2294
- ${selector} ${content}
2295
- }
2296
- ` : `${selector} ${content}
2297
- `;
2298
- return body;
2299
- }
2300
- };
2301
-
2302
- // src/tokens/process/formats/css/semantic.ts
2303
- import * as R11 from "ramda";
2304
- import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
2305
-
2306
- // src/tokens/process/formats/css/size.ts
2307
- import * as R10 from "ramda";
2308
- import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
2309
- var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
2310
- var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
2311
- var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
2312
- var isInlineTokens = R10.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
2313
- var overrideSizingFormula = (format, token) => {
2314
- const [name, value] = format(token).replace(/;$/, "").split(": ");
2315
- let calc;
2316
- let round;
2317
- if (token.path[1] === "unit") {
2318
- calc = `calc(1rem * ${value})`;
2319
- } else if (value.startsWith("floor")) {
2320
- calc = value.replace(/^floor\((.*)\)$/, "calc($1)");
2321
- round = `round(down, ${calc}, 1px)`;
2322
- } else {
2323
- calc = value.includes("*") ? `calc(${value})` : value;
2324
- }
2325
- return {
2326
- name,
2327
- round: round ?? calc,
2328
- calc
2329
- };
2330
- };
2331
- var formatSizingTokens = (format, tokens) => R10.reduce(
2332
- (acc, token) => {
2333
- const { round, calc, name } = overrideSizingFormula(format, token);
2334
- return {
2335
- tokens: [...acc.tokens, token],
2336
- round: [...acc.round, `${name}: ${round};`],
2337
- calc: [...acc.calc, `${name}: ${calc};`]
2338
- };
2339
- },
2340
- { tokens: [], round: [], calc: [] },
2341
- tokens
2342
- );
2343
- var sizingTemplate = ({ round, calc }) => {
2344
- const usesRounding = round.filter((val, i) => val !== calc[i]);
2345
- return `
2346
- ${calc.join("\n")}
2347
-
2348
- @supports (width: round(down, .1em, 1px)) {
2349
- ${usesRounding.join("\n ")}
2350
- }`;
2351
- };
2352
- var size = {
2353
- name: "ds/css-size",
2354
- format: async ({ dictionary, file, options, platform }) => {
2355
- const { outputReferences, usesDtcg } = options;
2356
- const { selector, layer } = platform;
2357
- const destination = file.destination;
2358
- const format = createPropertyFormatter2({
2359
- outputReferences,
2360
- dictionary,
2361
- format: "css",
2362
- usesDtcg
2363
- });
2364
- const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
2365
- const filteredTokens = R10.reject((token) => R10.equals(["_size", "mode-font-size"], token.path), tokens);
2366
- const [sizingTokens, restTokens] = R10.partition(
2367
- (t) => pathStartsWithOneOf(["_size"], t) && (isDigit(t.path[1]) || t.path[1] === "unit"),
2368
- filteredTokens
2369
- );
2370
- const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
2371
- const formattedMap = restTokens.map((token) => ({
2372
- token,
2373
- formatted: format(token)
2374
- }));
2375
- const formattedSizingMap = formattedSizingTokens.round.map((t, i) => ({
2376
- token: formattedSizingTokens.tokens[i],
2377
- formatted: t
2378
- }));
2379
- buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
2380
- const formattedTokens = [formattedMap.map(R10.prop("formatted")).join("\n"), sizingTemplate(formattedSizingTokens)];
2381
- const content = `${selector} {
2382
- ${formattedTokens.join("\n")}
2383
- }
2384
- `;
2385
- const body = R10.isNotNil(layer) ? `@layer ${layer} {
2386
- ${content}
2387
- }
2388
- ` : `${content}
2389
- `;
2390
- return body;
2391
- }
2392
- };
2393
-
2394
- // src/tokens/process/formats/css/semantic.ts
2395
- var semantic = {
2396
- name: "ds/css-semantic",
2397
- format: async ({ dictionary, file, options, platform }) => {
2398
- const { outputReferences, usesDtcg } = options;
2399
- const { selector, layer } = platform;
2400
- const destination = file.destination;
2401
- const format = createPropertyFormatter3({
2402
- outputReferences,
2403
- dictionary,
2404
- format: "css",
2405
- usesDtcg
2406
- });
2407
- const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
2408
- const formattedMap = tokens.map((token) => ({
2409
- token,
2410
- formatted: format(token)
2411
- }));
2412
- buildOptions.buildTokenFormats[destination] = formattedMap;
2413
- const formattedTokens = formattedMap.map(R11.prop("formatted")).join("\n");
2414
- const content = `${selector} {
2415
- ${formattedTokens}
2416
- }
2417
- `;
2418
- const body = R11.isNotNil(layer) ? `@layer ${layer} {
2419
- ${content}
2420
- }
2421
- ` : `${content}
2422
- `;
2423
- return body;
2424
- }
2425
- };
2426
-
2427
- // src/tokens/process/formats/css/size-mode.ts
2428
- import * as R13 from "ramda";
2429
- import { createPropertyFormatter as createPropertyFormatter4 } from "style-dictionary/utils";
2430
-
2431
- // src/tokens/process/transformers.ts
2432
- import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
2433
- import * as R12 from "ramda";
2434
- var isPx = R12.test(/\b\d+px\b/g);
2435
- var sizeRem = {
2436
- name: "ds/size/toRem",
2437
- type: "value",
2438
- transitive: true,
2439
- filter: (token) => {
2440
- const hasWantedType = typeEquals(["dimension", "fontsize"], token);
2441
- const hasWantedPath = pathStartsWithOneOf([
2442
- "border-radius",
2443
- "font-size"
2444
- /*, ['_size', 'mode-font-size']*/
2445
- ], token);
2446
- return hasWantedType && hasWantedPath;
2447
- },
2448
- transform: (token, config) => {
2449
- const value = getValue(token);
2450
- if (isPx(value)) {
2451
- const baseFont = config.basePxFontSize || 16;
2452
- const size2 = parseInt(value, 10);
2453
- if (size2 === 0) {
2454
- return "0";
2455
- }
2456
- return `${size2 / baseFont}rem`;
2457
- }
2458
- return value;
2459
- }
2460
- };
2461
- var typographyName = {
2462
- name: "name/typography",
2463
- type: "name",
2464
- transitive: true,
2465
- // expanded tokens have different type so we match on path instead
2466
- filter: (token) => pathStartsWithOneOf(["typography"], token),
2467
- transform: (token) => {
2468
- return token.name.replace("-typography", "");
2469
- }
2470
- };
2471
- var resolveMath = {
2472
- name: "ds/resolveMath",
2473
- type: "value",
2474
- transitive: true,
2475
- filter: (token) => {
2476
- const isValidValue = ["string", "object"].includes(typeof getValue(token));
2477
- const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
2478
- return isValidValue && isTokenOfInterest;
2479
- },
2480
- transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
2481
- };
2482
- var unitless = {
2483
- name: "ds/unitless",
2484
- type: "value",
2485
- transitive: true,
2486
- filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
2487
- transform: (token) => parseInt(getValue(token), 10)
2488
- };
2489
-
2490
- // src/tokens/process/configs/shared.ts
2491
- var prefix = "ds";
2492
- var basePxFontSize = 16;
2493
- var dsTransformers = [
2494
- "name/kebab",
2495
- resolveMath.name,
2496
- "ts/size/px",
2497
- sizeRem.name,
2498
- unitless.name,
2499
- "ts/typography/fontWeight",
2500
- typographyName.name,
2501
- "ts/color/modifiers",
2502
- "ts/color/css/hexrgba",
2503
- "ts/size/lineheight",
2504
- "shadow/css/shorthand"
2505
- ];
2506
-
2507
- // src/tokens/process/formats/css/size-mode.ts
2508
- var formatBaseSizeToken = (size2) => (token) => ({
2509
- ...token,
2510
- originalName: token.name,
2511
- name: `${token.name}--${shortSizeName(size2)}`,
2512
- $value: token.$value / basePxFontSize
2513
- });
2514
- var sizeMode = {
2515
- name: "ds/css-size-mode",
2516
- format: async ({ dictionary, file, options, platform }) => {
2517
- const { outputReferences, usesDtcg } = options;
2518
- const { selector, layer, size: size2 } = platform;
2519
- const destination = file.destination;
2520
- const format = createPropertyFormatter4({
2521
- outputReferences,
2522
- dictionary,
2523
- format: "css",
2524
- usesDtcg
2525
- });
2526
- const sizeSpecificTokens = dictionary.allTokens.map(formatBaseSizeToken(size2));
2527
- const sizeSpecificVariables = sizeSpecificTokens.map(format).join("\n");
2528
- const formattedMap = sizeSpecificTokens.map((token) => ({
2529
- token,
2530
- formatted: format({
2531
- ...token,
2532
- // Remove the `--<size>` suffix for the token listing, since that is the only token we actually use
2533
- name: token.originalName
2534
- })
2535
- }));
2536
- buildOptions.buildTokenFormats[destination] = formattedMap;
2537
- const content = `${selector} /* ${size2} */ {
2538
- ${sizeSpecificVariables}
2539
- }`;
2540
- const body = wrapInLayer(content, layer);
2541
- const sizes = orderBySize(buildOptions?.sizeModes ?? []).map(shortSizeName);
2542
- const defaultSize = shortSizeName(buildOptions?.defaultSize ?? "");
2543
- const sizingToggles = `:root, [data-size] {
2544
- --ds-size: var(--ds-size--${defaultSize});
2545
- ${sizes.map((size3) => ` --ds-size--${size3}: var(--ds-size,);`).join("\n")}
2546
- --ds-size-mode-font-size:
2547
- ${sizes.map((size3) => ` var(--ds-size--${size3}, var(--ds-size-mode-font-size--${size3}))`).join("\n")};
2548
- }`;
2549
- const sizingHelpers = sizes.map((size3) => `[data-size='${size3}'] { --ds-size: var(--ds-size--${size3}); }`).join("\n");
2550
- const sharedContent = `${sizingToggles}
2551
-
2552
- ${sizingHelpers}`;
2553
- const sharedBody = shortSizeName(size2) === R13.last(sizes) ? `
2554
- ${wrapInLayer(sharedContent, layer)}` : "";
2555
- return body + sharedBody;
2556
- }
2557
- };
2558
- function wrapInLayer(content, layer) {
2559
- return R13.isNotNil(layer) ? `@layer ${layer} {
2560
- ${content}
2561
- }
2562
- ` : `${content}
2563
- `;
2564
- }
2565
-
2566
- // src/tokens/process/formats/css/typography.ts
2567
- import * as R14 from "ramda";
2568
- import { createPropertyFormatter as createPropertyFormatter5 } from "style-dictionary/utils";
2569
- var typographyFontFamilyPredicate = R14.allPass([
2570
- R14.pathSatisfies(R14.includes("typography"), ["path"]),
2571
- R14.pathSatisfies(R14.includes("fontFamily"), ["path"])
2572
- ]);
2573
- var typography = {
2574
- name: "ds/css-typography",
2575
- format: async ({ dictionary, file, options, platform }) => {
2576
- const { outputReferences, usesDtcg } = options;
2577
- const { selector, layer } = platform;
2578
- const destination = file.destination;
2579
- const format = createPropertyFormatter5({
2580
- outputReferences,
2581
- dictionary,
2582
- format: "css",
2583
- usesDtcg
2584
- });
2585
- const filteredTokens = R14.reject(typographyFontFamilyPredicate, dictionary.allTokens);
2586
- const formattedMap = filteredTokens.map((token) => ({
2587
- token,
2588
- formatted: format(token)
2589
- }));
2590
- buildOptions.buildTokenFormats[destination] = formattedMap;
2591
- const formattedTokens = formattedMap.map(R14.view(R14.lensProp("formatted"))).join("\n");
2592
- const content = selector ? `${selector} {
2593
- ${formattedTokens}
2594
- }` : formattedTokens;
2595
- const body = R14.isNotNil(layer) ? `@layer ${layer} {
2596
- ${content}
2597
- }` : content;
2598
- return body;
2599
- }
2600
- };
2601
-
2602
- // src/tokens/process/formats/css/type-scale.ts
2603
- import * as R15 from "ramda";
2604
- import { createPropertyFormatter as createPropertyFormatter6 } from "style-dictionary/utils";
2605
- var isTypographyFontFamilyToken = R15.allPass([
2606
- R15.pathSatisfies(R15.includes("typography"), ["path"]),
2607
- R15.pathSatisfies(R15.includes("fontFamily"), ["path"])
2608
- ]);
2609
- var formatTypographySizeToken = (format, token) => {
2610
- const [name, value] = format(token).replace(/;$/, "").split(": ");
2611
- let calc;
2612
- let round;
2613
- if (R15.startsWith(["font-size"], token.path)) {
2614
- calc = `calc(${value} * var(--_ds-font-size-factor))`;
2615
- round = `round(${calc}, 1px)`;
2616
- } else {
2617
- calc = value;
2618
- }
2619
- return { name, calc, round: round ?? calc };
2620
- };
2621
- var formatTypographySizeTokens = (format, tokens) => R15.reduce(
2622
- (acc, token) => {
2623
- const { name, calc, round } = formatTypographySizeToken(format, token);
2624
- acc.tokens.push(token);
2625
- acc.calc.push(`${name}: ${calc};`);
2626
- acc.round.push(`${name}: ${round};`);
2627
- return acc;
2628
- },
2629
- { tokens: [], calc: [], round: [] },
2630
- tokens
2631
- );
2632
- var typeScale = {
2633
- name: "ds/css-type-scale",
2634
- format: async ({ dictionary, file, options, platform }) => {
2635
- const { outputReferences, usesDtcg } = options;
2636
- const { selector, layer } = platform;
2637
- const destination = file.destination;
2638
- const format = createPropertyFormatter6({
2639
- outputReferences,
2640
- dictionary,
2641
- format: "css",
2642
- usesDtcg
2643
- });
2644
- const filteredTokens = R15.reject(R15.anyPass([isTypographyFontFamilyToken]), dictionary.allTokens);
2645
- const formattedTokens = formatTypographySizeTokens(format, filteredTokens);
2646
- const formattedMap = formattedTokens.round.map((t, i) => ({
2647
- token: formattedTokens.tokens[i],
2648
- formatted: t
2649
- }));
2650
- buildOptions.buildTokenFormats[destination] = formattedMap;
2651
- const sizeFactor = ` --_ds-font-size-factor: calc(var(--ds-size-mode-font-size) / (var(--ds-size-base) / ${basePxFontSize}));`;
2652
- const content = `${selector} {
2653
- ${sizeFactor}${sizingTemplate(formattedTokens)}
2654
- }`;
2655
- const body = R15.isNotNil(layer) ? `@layer ${layer} {
2656
- ${content}
2657
- }` : content;
2658
- return body;
2659
- }
2660
- };
2661
-
2662
- // src/tokens/process/formats/css.ts
2663
- var formats = {
2664
- colorScheme,
2665
- colorCategory,
2666
- semantic,
2667
- sizeMode,
2668
- size,
2669
- typography,
2670
- typeScale
2671
- };
2672
-
2673
- // src/tokens/process/configs/color.ts
2674
- var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) => {
2675
- const selector = `${colorScheme2 === "light" ? ":root, " : ""}[data-color-scheme="${colorScheme2}"]`;
2676
- const layer = `ds.theme.color-scheme.${colorScheme2}`;
2677
- return {
2678
- preprocessors: ["tokens-studio"],
2679
- platforms: {
2680
- css: {
2681
- // custom
2682
- colorScheme: colorScheme2,
2683
- theme,
2684
- selector,
2685
- layer,
2686
- //
2687
- prefix,
2688
- buildPath: `${theme}/`,
2689
- transforms: dsTransformers,
2690
- files: [
2691
- {
2692
- destination: `color-scheme/${colorScheme2}.css`,
2693
- format: formats.colorScheme.name,
2694
- filter: (token) => typeEquals("color", token) && !R16.startsWith(["global"], token.path)
2695
- }
2696
- ],
2697
- options: {
2698
- outputReferences: false
2699
- }
2700
- }
2701
- }
2702
- };
2703
- };
2704
- var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, ...permutation }) => {
2705
- const category = opts.category;
2706
- const color = category === "builtin" ? opts.color : permutation[`${category}-color`];
2707
- if (!color) {
2708
- throw new Error(
2709
- category === "builtin" ? `Missing color for built-in color ${opts.color}` : `Missing color for category ${category}`
2710
- );
2711
- }
2712
- const layer = `ds.theme.color`;
2713
- const isRootColor = color === buildOptions?.defaultColor;
2714
- const selector = isRootColor ? `:root, [data-color-scheme], [data-color="${color}"]` : `[data-color="${color}"], [data-color-scheme][data-color="${color}"]`;
2715
- const config = {
2716
- preprocessors: ["tokens-studio"],
2717
- platforms: {
2718
- css: {
2719
- // custom
2720
- colorScheme: colorScheme2,
2721
- theme,
2722
- selector,
2723
- layer,
2724
- //
2725
- prefix,
2726
- buildPath: `${theme}/`,
2727
- transforms: dsTransformers,
2728
- files: [
2729
- {
2730
- destination: `color/${color}.css`,
2731
- format: formats.colorCategory.name,
2732
- filter: (token) => category === "builtin" ? isSemanticColorToken(token, color) : isColorCategoryToken(token, category)
2733
- }
2734
- ],
2735
- options: {
2736
- outputReferences: true
2737
- }
2738
- }
2739
- }
2740
- };
2741
- return config;
2742
- };
2743
-
2744
- // src/tokens/process/configs/semantic.ts
2745
- import * as R17 from "ramda";
2746
- import { outputReferencesFilter } from "style-dictionary/utils";
2747
- var semanticVariables = ({ theme }) => {
2748
- const selector = `:root`;
2749
- const layer = `ds.theme.semantic`;
2750
- return {
2751
- preprocessors: ["tokens-studio"],
2752
- platforms: {
2753
- css: {
2754
- // custom
2755
- theme,
2756
- basePxFontSize,
2757
- selector,
2758
- layer,
2759
- //
2760
- prefix,
2761
- buildPath: `${theme}/`,
2762
- transforms: dsTransformers,
2763
- files: [
2764
- {
2765
- destination: `semantic.css`,
2766
- format: formats.semantic.name,
2767
- filter: (token) => {
2768
- const isUwantedToken = R17.anyPass([R17.includes("primitives/global")])(token.filePath);
2769
- const isPrivateToken = R17.includes("_", token.path);
2770
- const unwantedPaths = pathStartsWithOneOf(
2771
- ["size", "_size", "font-size", "line-height", "letter-spacing"],
2772
- token
2773
- );
2774
- const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
2775
- const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
2776
- return unwantedTokens;
2777
- }
2778
- }
2779
- ],
2780
- options: {
2781
- outputReferences: (token, options) => {
2782
- const include = pathStartsWithOneOf(["border-radius"], token);
2783
- return include && outputReferencesFilter(token, options);
2784
- }
2785
- }
2786
- }
2787
- }
2788
- };
2789
- };
2790
-
2791
- // src/tokens/process/configs/size.ts
2792
- import * as R18 from "ramda";
2793
- import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
2794
- var sizeVariables = ({ theme }) => {
2795
- const selector = `:root, [data-size]`;
2796
- const layer = `ds.theme.size`;
2797
- return {
2798
- preprocessors: ["tokens-studio"],
2799
- platforms: {
2800
- css: {
2801
- // custom
2802
- theme,
2803
- basePxFontSize,
2804
- selector,
2805
- layer,
2806
- //
2807
- prefix,
2808
- buildPath: `${theme}/`,
2809
- transforms: dsTransformers,
2810
- files: [
2811
- {
2812
- destination: `size.css`,
2813
- format: formats.size.name,
2814
- filter: (token) => {
2815
- const isUwantedToken = R18.anyPass([R18.includes("primitives/global")])(token.filePath);
2816
- const isPrivateToken = R18.includes("_", token.path);
2817
- return pathStartsWithOneOf(["size", "_size"], token) && !(isUwantedToken || isPrivateToken);
2818
- }
2819
- }
2820
- ],
2821
- options: {
2822
- outputReferences: (token, options) => {
2823
- const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && (isDigit(token.path[1]) || token.path[1] === "unit");
2824
- return isWantedSize && outputReferencesFilter2(token, options);
2825
- }
2826
- }
2827
- }
2828
- }
2829
- };
2830
- };
2831
-
2832
- // src/tokens/process/configs/size-mode.ts
2833
- import * as R19 from "ramda";
2834
- var sizeModeVariables = ({ theme, size: size2 }) => {
2835
- const selector = `:root`;
2836
- const layer = `ds.theme.size-mode`;
2837
- return {
2838
- preprocessors: ["tokens-studio"],
2839
- platforms: {
2840
- css: {
2841
- // custom
2842
- size: size2,
2843
- theme,
2844
- basePxFontSize,
2845
- selector,
2846
- layer,
2847
- //
2848
- prefix,
2849
- buildPath: `${theme}/`,
2850
- transforms: dsTransformers,
2851
- files: [
2852
- {
2853
- destination: `size-mode/${size2}.css`,
2854
- format: formats.sizeMode.name,
2855
- filter: (token) => {
2856
- return R19.equals(["_size", "mode-font-size"], token.path);
2857
- }
2858
- }
2859
- ]
2860
- }
2861
- }
2862
- };
2863
- };
2864
-
2865
- // src/tokens/process/configs/type-scale.ts
2866
- var typeScaleVariables = ({ theme }) => {
2867
- const selector = ":root, [data-size]";
2868
- const layer = `ds.theme.type-scale`;
2869
- return {
2870
- usesDtcg: true,
2871
- preprocessors: ["tokens-studio"],
2872
- expand: {
2873
- include: ["typography"]
2874
- },
2875
- platforms: {
2876
- css: {
2877
- prefix,
2878
- selector,
2879
- layer,
2880
- buildPath: `${theme}/`,
2881
- basePxFontSize,
2882
- transforms: [
2883
- "name/kebab",
2884
- "ts/size/px",
2885
- sizeRem.name,
2886
- "ts/size/lineheight",
2887
- "ts/typography/fontWeight",
2888
- typographyName.name
2889
- ],
2890
- files: [
2891
- {
2892
- destination: `type-scale.css`,
2893
- format: formats.typeScale.name,
2894
- filter: (token) => {
2895
- const included = typeEquals(["typography", "dimension", "fontsize"], token);
2896
- if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
2897
- return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "border-width", "border-radius"], token) && (pathStartsWithOneOf(["font-size"], token) || token.path.includes("fontSize"));
2898
- }
2899
- }
2900
- ],
2901
- options: {
2902
- outputReferences: (token) => pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize")
2903
- }
2904
- }
2905
- }
2906
- };
2907
- };
2908
-
2909
- // src/tokens/process/configs/typography.ts
2910
- import { expandTypesMap } from "@tokens-studio/sd-transforms";
2911
- var typographyVariables = ({ theme, typography: typography2 }) => {
2912
- const selector = `${typography2 === "primary" ? ":root, " : ""}[data-typography="${typography2}"]`;
2913
- const layer = `ds.theme.typography.${typography2}`;
2914
- return {
2915
- usesDtcg: true,
2916
- preprocessors: ["tokens-studio"],
2917
- expand: {
2918
- include: ["typography"],
2919
- typesMap: { ...expandTypesMap, typography: { ...expandTypesMap.typography, letterSpacing: "dimension" } }
2920
- },
2921
- platforms: {
2922
- css: {
2923
- prefix,
2924
- typography: typography2,
2925
- selector,
2926
- layer,
2927
- buildPath: `${theme}/`,
2928
- basePxFontSize,
2929
- transforms: [
2930
- "name/kebab",
2931
- "ts/size/px",
2932
- sizeRem.name,
2933
- "ts/size/lineheight",
2934
- "ts/typography/fontWeight",
2935
- "ts/size/css/letterspacing",
2936
- typographyName.name
2937
- ],
2938
- files: [
2939
- {
2940
- destination: `typography/${typography2}.css`,
2941
- format: formats.typography.name,
2942
- filter: (token) => {
2943
- const included = typeEquals(["fontweight", "fontFamily", "lineHeight", "dimension"], token);
2944
- if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
2945
- return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token) && !(pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize"));
2946
- }
2947
- }
2948
- ]
2949
- }
2950
- }
2951
- };
2952
- };
2953
-
2954
- // src/tokens/process/utils/getMultidimensionalThemes.ts
2955
- import pc2 from "picocolors";
2956
- import * as R20 from "ramda";
2957
-
2958
- // src/tokens/process/utils/kebab-case.ts
2959
- function kebabCase(str) {
2960
- return str.replace(/([a-z])([A-Z])/g, "$1-$2").replace(/[\s_]+/g, "-").toLowerCase();
2961
- }
2962
-
2963
- // src/tokens/process/utils/getMultidimensionalThemes.ts
2964
- var getMultidimensionalThemes = (processed$themes, dimensions) => {
2965
- const verboseLogging = buildOptions?.verbose;
2966
- const grouped$themes = groupThemes(processed$themes);
2967
- const permutations = permutateThemes(grouped$themes);
2968
- const ALL_DEPENDENT_ON = ["theme"];
2969
- const keys3 = R20.keys(grouped$themes);
2970
- const nonDependentKeys = keys3.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
2971
- if (verboseLogging) {
2972
- console.log(pc2.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
2973
- console.log(pc2.cyan(` (ignoring permutations for ${nonDependentKeys})`));
2974
- }
2975
- return permutations.filter((val) => {
2976
- const filters = nonDependentKeys.map((x) => val.permutation[x] === grouped$themes[x][0].name);
2977
- return filters.every((x) => x);
2978
- });
2979
- };
2980
- var processed = /* @__PURE__ */ Symbol("Type brand for ProcessedThemeObject");
2981
- function isProcessed(theme) {
2982
- return Boolean(theme[processed]);
2983
- }
2984
- function processThemeObject(theme) {
2985
- if (isProcessed(theme)) {
2986
- return theme;
2987
- }
2988
- const result = { ...theme, [processed]: true };
2989
- if (result.group) {
2990
- result.group = kebabCase(result.group);
2991
- }
2992
- result.name = kebabCase(result.name);
2993
- return result;
2994
- }
2995
- function groupThemes(themes) {
2996
- const groups = {};
2997
- for (const theme of themes) {
2998
- if (theme.group) {
2999
- const groupKey = theme.group;
3000
- groups[groupKey] = [...groups[groupKey] ?? [], theme];
3001
- } else {
3002
- throw new Error(
3003
- `Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
3004
- );
3005
- }
3006
- }
3007
- return groups;
3008
- }
3009
- var hasUnknownProps = R20.pipe(R20.values, R20.none(R20.equals("unknown")), R20.not);
3010
- function permutateThemes(groups) {
3011
- const separator = "_";
3012
- const permutations = cartesian(Object.values(groups));
3013
- const permutatedThemes = permutations.map((perm) => {
3014
- const permutatedTheme = perm.reduce(
3015
- (acc, theme) => {
3016
- const { group, name, selectedTokenSets } = theme;
3017
- let updatedPermutation = acc.permutation;
3018
- if (group) {
3019
- const groupProp = R20.lensProp(group);
3020
- updatedPermutation = R20.set(groupProp, name, updatedPermutation);
3021
- }
3022
- const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
3023
- const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
3024
- return {
3025
- permutation: updatedPermutation,
3026
- name: updatedName,
3027
- selectedTokenSets: sets
3028
- };
3029
- },
3030
- {
3031
- name: "",
3032
- selectedTokenSets: [],
3033
- permutation: {
3034
- "color-scheme": "unknown",
3035
- "main-color": "unknown",
3036
- "support-color": "unknown",
3037
- theme: "unknown",
3038
- semantic: "unknown",
3039
- size: "unknown",
3040
- typography: "unknown"
3041
- }
3042
- }
3043
- );
3044
- if (hasUnknownProps(permutatedTheme)) {
3045
- throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
3046
- }
3047
- const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
3048
- return { ...permutatedTheme, selectedTokenSets: Array.from(uniqueTokenSets) };
3049
- });
3050
- return permutatedThemes;
3051
- }
3052
- function filterTokenSets(tokensets) {
3053
- return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
3054
- if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
3055
- return -1;
3056
- }
3057
- if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
3058
- return 1;
3059
- }
3060
- return 0;
3061
- }).map((entry) => entry[0]);
3062
- }
3063
- function cartesian(a) {
3064
- return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e].flat())));
3065
- }
3066
- var getCustomColors = (processed$themes, colorGroups) => processed$themes.filter((x) => {
3067
- if (!x.group) {
3068
- return false;
3069
- }
3070
- return colorGroups.includes(x.group);
3071
- }).map((x) => x.name);
3072
-
3073
- // src/tokens/process/configs.ts
3074
- void register(StyleDictionary, { withSDBuiltins: false });
3075
- StyleDictionary.registerTransform(sizeRem);
3076
- StyleDictionary.registerTransform(typographyName);
3077
- StyleDictionary.registerTransform(resolveMath);
3078
- StyleDictionary.registerTransform(unitless);
3079
- for (const format of Object.values(formats)) {
3080
- StyleDictionary.registerFormat(format);
3081
- }
3082
- var configs = {
3083
- colorSchemeVariables,
3084
- mainColorVariables: colorCategoryVariables({ category: "main" }),
3085
- supportColorVariables: colorCategoryVariables({ category: "support" }),
3086
- neutralColorVariables: colorCategoryVariables({ category: "builtin", color: "neutral" }),
3087
- successColorVariables: colorCategoryVariables({ category: "builtin", color: "success" }),
3088
- dangerColorVariables: colorCategoryVariables({ category: "builtin", color: "danger" }),
3089
- warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
3090
- infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
3091
- sizeModeVariables,
3092
- sizeVariables,
3093
- typographyVariables,
3094
- typeScaleVariables,
3095
- semanticVariables
3096
- };
3097
- var getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, options) => {
3098
- const { tokensDir, tokenSets } = options;
3099
- const permutations = getMultidimensionalThemes(processed$themes, dimensions);
3100
- return permutations.flatMap(({ selectedTokenSets, permutation }) => {
3101
- const tokenSource = { source: void 0, tokens: {} };
3102
- if (tokenSets) {
3103
- for (const tokenSet of selectedTokenSets) {
3104
- const tokens = tokenSets.get(tokenSet);
3105
- if (tokens) {
3106
- const tokensWithFilePath = traverseObj(tokens, (obj) => {
3107
- if (Object.hasOwn(obj, `$value`) && !obj.filePath) {
3108
- obj.filePath = tokenSet;
3109
- }
3110
- });
3111
- tokenSource.tokens = R21.mergeDeepRight(tokenSource.tokens, tokensWithFilePath);
3112
- }
3113
- }
3114
- } else {
3115
- tokenSource.source = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
3116
- }
3117
- const configOrConfigs = getConfig(permutation);
3118
- const configs_ = Array.isArray(configOrConfigs) ? configOrConfigs : [{ config: configOrConfigs }];
3119
- const configs2 = configs_.map(({ config, permutationOverrides }) => {
3120
- return {
3121
- permutation: { ...permutation, ...permutationOverrides },
3122
- config: {
3123
- ...config,
3124
- /** Use official W3C design token format
3125
- @see https://v4.styledictionary.com/info/dtcg/
3126
- @see https://design-tokens.github.io/community-group/format/ */
3127
- usesDtcg: true,
3128
- log: {
3129
- ...config?.log,
3130
- verbosity: buildOptions?.verbose ? "verbose" : "silent"
3131
- },
3132
- ...tokenSource
3133
- }
3134
- };
3135
- });
3136
- return configs2;
3137
- }).sort();
3138
- };
3139
-
3140
- // src/tokens/process/platform.ts
3141
- var initResult = {
3142
- formatted: [],
3143
- tokens: [],
3144
- permutation: {
3145
- "color-scheme": "",
3146
- "main-color": "",
3147
- "support-color": "",
3148
- semantic: "",
3149
- size: "",
3150
- theme: "",
3151
- typography: ""
3152
- }
3153
- };
3154
- var buildOptions = {
3155
- verbose: false,
3156
- processed$themes: [],
3157
- buildTokenFormats: {}
3158
- };
3159
- var sd = new StyleDictionary2();
3160
- var buildConfigs = {
3161
- typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
3162
- sizeMode: { getConfig: configs.sizeModeVariables, dimensions: ["size"] },
3163
- size: { getConfig: configs.sizeVariables, dimensions: ["semantic"] },
3164
- typeScale: { getConfig: configs.typeScaleVariables, dimensions: ["semantic"] },
3165
- "color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
3166
- "main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
3167
- "support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
3168
- "neutral-color": {
3169
- getConfig: configs.neutralColorVariables,
3170
- dimensions: ["semantic"],
3171
- log: ({ permutation: { theme } }) => `${theme} - neutral`
3172
- },
3173
- "success-color": {
3174
- getConfig: configs.successColorVariables,
3175
- dimensions: ["semantic"],
3176
- log: ({ permutation: { theme } }) => `${theme} - success`
3177
- },
3178
- "danger-color": {
3179
- getConfig: configs.dangerColorVariables,
3180
- dimensions: ["semantic"],
3181
- log: ({ permutation: { theme } }) => `${theme} - danger`
3182
- },
3183
- "warning-color": {
3184
- getConfig: configs.warningColorVariables,
3185
- dimensions: ["semantic"],
3186
- log: ({ permutation: { theme } }) => `${theme} - warning`
3187
- },
3188
- "info-color": {
3189
- getConfig: configs.infoColorVariables,
3190
- dimensions: ["semantic"],
3191
- log: ({ permutation: { theme } }) => `${theme} - info`
3192
- },
3193
- semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] }
3194
- };
3195
- async function processPlatform(options) {
3196
- const { type, processed$themes } = options;
3197
- const platform = "css";
3198
- const tokenSets = type === "format" ? options.tokenSets : void 0;
3199
- const tokensDir = type === "build" ? options.tokensDir : void 0;
3200
- const UNSAFE_DEFAULT_COLOR = process.env.UNSAFE_DEFAULT_COLOR ?? "";
3201
- if (UNSAFE_DEFAULT_COLOR) {
3202
- console.warn(
3203
- pc3.yellow(
3204
- `
3205
- \u26A0\uFE0F UNSAFE_DEFAULT_COLOR is set to ${pc3.blue(UNSAFE_DEFAULT_COLOR)}. This will override the default color.`
3206
- )
3207
- );
3208
- }
3209
- const UNSAFE_COLOR_GROUPS = Array.from(process.env.UNSAFE_COLOR_GROUPS?.split(",") ?? []);
3210
- if (UNSAFE_COLOR_GROUPS.length > 0) {
3211
- console.warn(
3212
- pc3.yellow(
3213
- `
3214
- \u26A0\uFE0F UNSAFE_COLOR_GROUPS is set to ${pc3.blue(`[${UNSAFE_COLOR_GROUPS.join(", ")}]`)}. This will override the default color groups.`
3215
- )
3216
- );
3217
- }
3218
- const colorGroups = UNSAFE_COLOR_GROUPS.length > 0 ? UNSAFE_COLOR_GROUPS : [colorCategories.main, colorCategories.support].map((c) => `${c}-color`);
3219
- buildOptions = options;
3220
- buildOptions.defaultColor = UNSAFE_DEFAULT_COLOR;
3221
- buildOptions.colorGroups = colorGroups;
3222
- if (!buildOptions.defaultColor) {
3223
- const customColors = getCustomColors(processed$themes, colorGroups);
3224
- const firstMainColor = R22.head(customColors);
3225
- buildOptions.defaultColor = firstMainColor;
3226
- }
3227
- if (buildOptions.defaultColor) {
3228
- console.log(`
3229
- \u{1F3A8} Using ${pc3.blue(buildOptions.defaultColor)} as default color`);
3230
- }
3231
- const sizeModes2 = processed$themes.filter((x) => x.group === "size").map((x) => x.name);
3232
- buildOptions.sizeModes = sizeModes2;
3233
- if (!buildOptions.defaultSize) {
3234
- const defaultSize = R22.head(sizeModes2);
3235
- buildOptions.defaultSize = defaultSize;
3236
- }
3237
- if (buildOptions.defaultSize) {
3238
- console.log(`
3239
- \u{1F4CF} Using ${pc3.blue(buildOptions.defaultSize)} as default size`);
3240
- }
3241
- const buildAndSdConfigs = R22.map((buildConfig) => {
3242
- const sdConfigs = getConfigsForThemeDimensions(buildConfig.getConfig, processed$themes, buildConfig.dimensions, {
3243
- tokensDir,
3244
- tokenSets
3245
- });
3246
- const unknownConfigs = buildConfig.dimensions.map(
3247
- (dimension) => sdConfigs.filter((x) => x.permutation[dimension] === "unknown")
3248
- );
3249
- for (const unknowns of unknownConfigs) {
3250
- if (unknowns.length === sdConfigs.length) {
3251
- buildConfig.enabled = () => false;
3252
- }
3253
- }
3254
- return {
3255
- buildConfig,
3256
- sdConfigs
3257
- };
3258
- }, buildConfigs);
3259
- const processedBuilds = {
3260
- "color-scheme": [initResult],
3261
- "main-color": [initResult],
3262
- "support-color": [initResult],
3263
- "neutral-color": [initResult],
3264
- "success-color": [initResult],
3265
- "danger-color": [initResult],
3266
- "warning-color": [initResult],
3267
- "info-color": [initResult],
3268
- semantic: [initResult],
3269
- typography: [initResult],
3270
- sizeMode: [initResult],
3271
- size: [initResult],
3272
- typeScale: [initResult]
3273
- };
3274
- try {
3275
- for (const [buildName, { buildConfig, sdConfigs }] of R22.toPairs(buildAndSdConfigs)) {
3276
- if (!(buildConfig.enabled?.() ?? true)) {
3277
- continue;
3278
- }
3279
- if (sdConfigs.length > 0) {
3280
- console.log(`
3281
- \u{1F371} Building ${pc3.green(buildConfig.name ?? buildName)}`);
3282
- const results = await Promise.all(
3283
- sdConfigs.map(async (sdConfig) => {
3284
- const { config, permutation } = sdConfig;
3285
- const modes = ["theme", ...buildConfig.dimensions];
3286
- const modeMessage = modes.map((x) => permutation[x]).join(" - ");
3287
- const logMessage = R22.isNil(buildConfig.log) ? modeMessage : buildConfig?.log(sdConfig);
3288
- console.log(logMessage);
3289
- const sdOptions = { cache: true };
3290
- const sdExtended = await sd.extend(config);
3291
- const formatted = await sdExtended.formatPlatform(platform, sdOptions);
3292
- const tokens = (await sdExtended.getPlatformTokens(platform, sdOptions)).allTokens;
3293
- const result = {
3294
- permutation,
3295
- formatted,
3296
- tokens
3297
- };
3298
- return Promise.resolve(result);
3299
- })
3300
- );
3301
- processedBuilds[buildName] = results;
3302
- }
3303
- }
3304
- } catch (err) {
3305
- if (err instanceof Error) {
3306
- err.message = err.message.replace('log.verbosity "verbose" or use ', "");
3307
- }
3308
- throw err;
3309
- }
3310
- return processedBuilds;
3311
- }
3312
-
3313
- // src/tokens/format.ts
3314
- var formatTokens = async (options) => {
3315
- const processedBuilds = await processPlatform({
3316
- type: "format",
3317
- buildTokenFormats: {},
3318
- ...options
3319
- });
3320
- return processedBuilds;
3321
- };
3322
- var formatTheme = async (themeConfig) => {
3323
- const { tokenSets } = await createTokens(themeConfig);
3324
- const sizeModes2 = ["small", "medium", "large"];
3325
- const $themes = await generate$Themes(["dark", "light"], [themeConfig.name], themeConfig.colors, sizeModes2);
3326
- const processed$themes = $themes.map(processThemeObject);
3327
- const processedBuilds = await formatTokens({
3328
- tokenSets,
3329
- processed$themes,
3330
- verbose: false
3331
- });
3332
- return processedBuilds;
3333
- };
3334
- var formatThemeCSS = async (themeConfig) => {
3335
- const processedBuilds = await formatTheme(themeConfig);
3336
- const themeCSSFiles = createThemeCSSFiles({ processedBuilds });
3337
- return R23.head(themeCSSFiles)?.output ?? "";
3338
- };
3339
- export {
3340
- cliOptions,
3341
- createTokens,
3342
- formatThemeCSS,
3343
- formatTokens
3344
- };
1
+ import { cliOptions, createTokens } from "./create.js";
2
+ import { formatThemeCSS, formatTokens } from "./format.js";
3
+ export { cliOptions, createTokens, formatThemeCSS, formatTokens };