@digdir/designsystemet 1.13.2 → 1.14.0

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