@digdir/designsystemet 1.16.0 → 1.17.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 (96) hide show
  1. package/README.md +2 -15
  2. package/dist/bin/config.d.ts +2 -4
  3. package/dist/bin/config.d.ts.map +1 -1
  4. package/dist/bin/config.js +6 -8
  5. package/dist/bin/designsystemet.d.ts +1 -1
  6. package/dist/bin/designsystemet.d.ts.map +1 -1
  7. package/dist/bin/designsystemet.js +12 -13
  8. package/dist/config.schema.json +5 -33
  9. package/dist/package.js +1 -1
  10. package/dist/src/automigrate.d.ts +2 -0
  11. package/dist/src/automigrate.d.ts.map +1 -0
  12. package/dist/src/automigrate.js +33 -0
  13. package/dist/src/colors/types.d.ts +1 -1
  14. package/dist/src/index.d.ts +1 -1
  15. package/dist/src/index.d.ts.map +1 -1
  16. package/dist/src/index.js +4 -3
  17. package/dist/src/migrations/flatten-color-categories.d.ts +10 -0
  18. package/dist/src/migrations/flatten-color-categories.d.ts.map +1 -0
  19. package/dist/src/migrations/flatten-color-categories.js +51 -0
  20. package/dist/src/migrations/index.d.ts +9 -0
  21. package/dist/src/migrations/index.d.ts.map +1 -1
  22. package/dist/src/migrations/index.js +3 -1
  23. package/dist/src/schemas/helpers.d.ts +29 -0
  24. package/dist/src/schemas/helpers.d.ts.map +1 -0
  25. package/dist/src/schemas/helpers.js +71 -0
  26. package/dist/src/{config.d.ts → schemas/v1/schema.d.ts} +1 -12
  27. package/dist/src/schemas/v1/schema.d.ts.map +1 -0
  28. package/dist/src/{config.js → schemas/v1/schema.js} +6 -61
  29. package/dist/src/schemas/v1.1/schema.d.ts +162 -0
  30. package/dist/src/schemas/v1.1/schema.d.ts.map +1 -0
  31. package/dist/src/schemas/v1.1/schema.js +54 -0
  32. package/dist/src/tokens/build.js +1 -1
  33. package/dist/src/tokens/create/files.d.ts +2 -2
  34. package/dist/src/tokens/create/files.d.ts.map +1 -1
  35. package/dist/src/tokens/create/files.js +3 -3
  36. package/dist/src/tokens/create/generators/$metadata.d.ts +2 -2
  37. package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -1
  38. package/dist/src/tokens/create/generators/$metadata.js +2 -4
  39. package/dist/src/tokens/create/generators/$themes.d.ts +2 -2
  40. package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -1
  41. package/dist/src/tokens/create/generators/$themes.js +7 -10
  42. package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts +4 -4
  43. package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts.map +1 -1
  44. package/dist/src/tokens/create/generators/primitives/color-scheme.js +9 -11
  45. package/dist/src/tokens/create/generators/semantic/color.d.ts +2 -4
  46. package/dist/src/tokens/create/generators/semantic/color.d.ts.map +1 -1
  47. package/dist/src/tokens/create/generators/semantic/color.js +9 -38
  48. package/dist/src/tokens/create/generators/semantic/style.d.ts +1 -1
  49. package/dist/src/tokens/create/generators/semantic/style.d.ts.map +1 -1
  50. package/dist/src/tokens/create/generators/semantic/style.js +78 -41
  51. package/dist/src/tokens/create/generators/themes/theme.d.ts +2 -2
  52. package/dist/src/tokens/create/generators/themes/theme.d.ts.map +1 -1
  53. package/dist/src/tokens/create/generators/themes/theme.js +2 -11
  54. package/dist/src/tokens/create.d.ts +0 -16
  55. package/dist/src/tokens/create.d.ts.map +1 -1
  56. package/dist/src/tokens/create.js +10 -22
  57. package/dist/src/tokens/format.js +6 -4
  58. package/dist/src/tokens/generate-config.d.ts +3 -2
  59. package/dist/src/tokens/generate-config.d.ts.map +1 -1
  60. package/dist/src/tokens/generate-config.js +10 -36
  61. package/dist/src/tokens/index.d.ts +2 -1
  62. package/dist/src/tokens/index.d.ts.map +1 -1
  63. package/dist/src/tokens/index.js +3 -2
  64. package/dist/src/tokens/process/configs/color.d.ts +1 -9
  65. package/dist/src/tokens/process/configs/color.d.ts.map +1 -1
  66. package/dist/src/tokens/process/configs/color.js +6 -9
  67. package/dist/src/tokens/process/configs.d.ts +1 -7
  68. package/dist/src/tokens/process/configs.d.ts.map +1 -1
  69. package/dist/src/tokens/process/configs.js +3 -24
  70. package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -1
  71. package/dist/src/tokens/process/formats/css/color.js +3 -4
  72. package/dist/src/tokens/process/formats/css/size-mode.d.ts +0 -1
  73. package/dist/src/tokens/process/formats/css/size-mode.d.ts.map +1 -1
  74. package/dist/src/tokens/process/formats/css/size-mode.js +1 -1
  75. package/dist/src/tokens/process/formats/css/size.d.ts +0 -12
  76. package/dist/src/tokens/process/formats/css/size.d.ts.map +1 -1
  77. package/dist/src/tokens/process/formats/css/size.js +1 -1
  78. package/dist/src/tokens/process/output/declarations.d.ts.map +1 -1
  79. package/dist/src/tokens/process/output/declarations.js +6 -8
  80. package/dist/src/tokens/process/platform.d.ts +4 -36
  81. package/dist/src/tokens/process/platform.d.ts.map +1 -1
  82. package/dist/src/tokens/process/platform.js +8 -50
  83. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +2 -3
  84. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -1
  85. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +4 -8
  86. package/dist/src/tokens/types.d.ts +3 -11
  87. package/dist/src/tokens/types.d.ts.map +1 -1
  88. package/dist/src/tokens/types.js +1 -7
  89. package/dist/src/tokens/utils.d.ts +5 -11
  90. package/dist/src/tokens/utils.d.ts.map +1 -1
  91. package/dist/src/tokens/utils.js +8 -13
  92. package/package.json +11 -7
  93. package/dist/src/config.d.ts.map +0 -1
  94. package/dist/src/tokens/create/generators/semantic/color-modes.d.ts +0 -8
  95. package/dist/src/tokens/create/generators/semantic/color-modes.d.ts.map +0 -1
  96. package/dist/src/tokens/create/generators/semantic/color-modes.js +0 -26
@@ -1,6 +1,49 @@
1
+ import { semanticColorMap } from "../../../../colors/types.js";
2
+ import * as R from "ramda";
1
3
  //#region src/tokens/create/generators/semantic/style.ts
2
- function generateSemanticStyle() {
4
+ function generateSemanticStyle(colorNames) {
3
5
  return {
6
+ ...generateColors(colorNames),
7
+ "border-width": {
8
+ default: {
9
+ $type: "borderWidth",
10
+ $value: "{border-width.1}"
11
+ },
12
+ focus: {
13
+ $type: "borderWidth",
14
+ $value: "{border-width.3}"
15
+ }
16
+ },
17
+ "border-radius": {
18
+ sm: {
19
+ $type: "dimension",
20
+ $value: "{border-radius.1}"
21
+ },
22
+ md: {
23
+ $type: "dimension",
24
+ $value: "{border-radius.2}"
25
+ },
26
+ lg: {
27
+ $type: "dimension",
28
+ $value: "{border-radius.3}"
29
+ },
30
+ xl: {
31
+ $type: "dimension",
32
+ $value: "{border-radius.4}"
33
+ },
34
+ default: {
35
+ $type: "dimension",
36
+ $value: "{border-radius.5}"
37
+ },
38
+ full: {
39
+ $type: "dimension",
40
+ $value: "{border-radius.6}"
41
+ }
42
+ },
43
+ opacity: { disabled: {
44
+ $type: "opacity",
45
+ $value: "{opacity.30}"
46
+ } },
4
47
  typography: {
5
48
  heading: {
6
49
  "2xl": {
@@ -231,20 +274,6 @@ function generateSemanticStyle() {
231
274
  }
232
275
  }
233
276
  },
234
- opacity: { disabled: {
235
- $type: "opacity",
236
- $value: "{opacity.30}"
237
- } },
238
- "border-width": {
239
- default: {
240
- $type: "borderWidth",
241
- $value: "{border-width.1}"
242
- },
243
- focus: {
244
- $type: "borderWidth",
245
- $value: "{border-width.3}"
246
- }
247
- },
248
277
  shadow: {
249
278
  xs: {
250
279
  $type: "boxShadow",
@@ -267,32 +296,6 @@ function generateSemanticStyle() {
267
296
  $value: "{shadow.500}"
268
297
  }
269
298
  },
270
- "border-radius": {
271
- sm: {
272
- $type: "dimension",
273
- $value: "{border-radius.1}"
274
- },
275
- md: {
276
- $type: "dimension",
277
- $value: "{border-radius.2}"
278
- },
279
- lg: {
280
- $type: "dimension",
281
- $value: "{border-radius.3}"
282
- },
283
- xl: {
284
- $type: "dimension",
285
- $value: "{border-radius.4}"
286
- },
287
- default: {
288
- $type: "dimension",
289
- $value: "{border-radius.5}"
290
- },
291
- full: {
292
- $type: "dimension",
293
- $value: "{border-radius.6}"
294
- }
295
- },
296
299
  size: {
297
300
  "0": {
298
301
  $type: "dimension",
@@ -377,5 +380,39 @@ function generateSemanticStyle() {
377
380
  }
378
381
  };
379
382
  }
383
+ const generateColors = (colorNames) => {
384
+ const semanticColorTokens = colorNames.map((colorName) => [colorName, generateColorScaleTokens(colorName)]);
385
+ return {
386
+ ...baseColorTemplate,
387
+ color: {
388
+ ...Object.fromEntries(semanticColorTokens),
389
+ ...baseColorTemplate.color
390
+ }
391
+ };
392
+ };
393
+ const baseColorTemplate = {
394
+ color: { focus: {
395
+ inner: {
396
+ $type: "color",
397
+ $value: "{color.focus.inner-color}"
398
+ },
399
+ outer: {
400
+ $type: "color",
401
+ $value: "{color.focus.outer-color}"
402
+ }
403
+ } },
404
+ link: { color: { visited: {
405
+ $type: "color",
406
+ $value: "{color.link.visited}"
407
+ } } }
408
+ };
409
+ const generateColorScaleTokens = (colorName) => {
410
+ const colorScale = {};
411
+ for (const [colorSemantic, colorNumber] of R.toPairs(semanticColorMap)) colorScale[colorSemantic] = {
412
+ $type: "color",
413
+ $value: `{color.${colorName}.${colorNumber}}`
414
+ };
415
+ return colorScale;
416
+ };
380
417
  //#endregion
381
418
  export { generateSemanticStyle };
@@ -1,3 +1,3 @@
1
- import type { Colors, TokenSet } from '../../../types.js';
2
- export declare const generateTheme: (colors: Colors, themeName: string, borderRadius: number) => TokenSet;
1
+ import type { TokenSet } from '../../../types.js';
2
+ export declare const generateTheme: (colorNames: string[], themeName: string, borderRadius: number) => TokenSet;
3
3
  //# sourceMappingURL=theme.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/create/generators/themes/theme.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAS,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEjE,eAAO,MAAM,aAAa,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,EAAE,cAAc,MAAM,aAmDpF,CAAC"}
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/create/generators/themes/theme.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAS,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAEzD,eAAO,MAAM,aAAa,GAAI,YAAY,MAAM,EAAE,EAAE,WAAW,MAAM,EAAE,cAAc,MAAM,aA+C1F,CAAC"}
@@ -1,17 +1,8 @@
1
- import { baseColorNames } from "../../../../colors/colorMetadata.js";
2
1
  import { semanticColorMap } from "../../../../colors/types.js";
3
2
  import * as R from "ramda";
4
3
  //#region src/tokens/create/generators/themes/theme.ts
5
- const generateTheme = (colors, themeName, borderRadius) => {
6
- const mainColorNames = Object.keys(colors.main);
7
- const supportColorNames = Object.keys(colors.support);
8
- const customColors = [
9
- ...mainColorNames,
10
- "neutral",
11
- ...supportColorNames,
12
- ...baseColorNames
13
- ];
14
- const themeColorTokens = Object.fromEntries(customColors.map((colorName) => [colorName, generateColorScaleTokens(colorName, themeName)]));
4
+ const generateTheme = (colorNames, themeName, borderRadius) => {
5
+ const themeColorTokens = Object.fromEntries(colorNames.map((colorName) => [colorName, generateColorScaleTokens(colorName, themeName)]));
15
6
  const { color: themeBaseFileColor, ...remainingThemeFile } = generateBase(themeName);
16
7
  const themeFile = {
17
8
  color: {
@@ -1,21 +1,5 @@
1
1
  import type { Theme, TokenSetDimensions, TokenSets } from './types.js';
2
2
  export declare const tokenSetDimensions: TokenSetDimensions;
3
- export declare const cliOptions: {
4
- readonly outDir: "out-dir";
5
- readonly clean: "clean";
6
- readonly tailwind: "tailwind";
7
- readonly theme: {
8
- readonly colors: {
9
- readonly main: "main-colors";
10
- readonly support: "support-colors";
11
- readonly neutral: "neutral-color";
12
- };
13
- readonly typography: {
14
- readonly fontFamily: "font-family";
15
- };
16
- readonly borderRadius: "border-radius";
17
- };
18
- };
19
3
  export declare const createTokens: (theme: Theme) => Promise<{
20
4
  tokenSets: TokenSets;
21
5
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,KAAK,EAAY,kBAAkB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAEjF,eAAO,MAAM,kBAAkB,EAAE,kBAGhC,CAAC;AAEF,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;CAeb,CAAC;AAEX,eAAO,MAAM,YAAY,GAAU,OAAO,KAAK;;EA2B9C,CAAC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAY,kBAAkB,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAGjF,eAAO,MAAM,kBAAkB,EAAE,kBAGhC,CAAC;AAEF,eAAO,MAAM,YAAY,GAAU,OAAO,KAAK;;EA8B9C,CAAC"}
@@ -1,9 +1,9 @@
1
+ import { addSeverityColors, toColorNames } from "./utils.js";
1
2
  import { generateColorScheme } from "./create/generators/primitives/color-scheme.js";
2
3
  import { generateGlobals } from "./create/generators/primitives/globals.js";
3
4
  import { generateSize, generateSizeGlobal } from "./create/generators/primitives/size.js";
4
5
  import { generateFontSizes, generateTypography } from "./create/generators/primitives/typography.js";
5
- import { generateSemanticColors } from "./create/generators/semantic/color.js";
6
- import { generateColorModes } from "./create/generators/semantic/color-modes.js";
6
+ import { generateColorTokens } from "./create/generators/semantic/color.js";
7
7
  import { generateSemanticStyle } from "./create/generators/semantic/style.js";
8
8
  import { generateTheme } from "./create/generators/themes/theme.js";
9
9
  //#region src/tokens/create.ts
@@ -15,23 +15,12 @@ const tokenSetDimensions = {
15
15
  "large"
16
16
  ]
17
17
  };
18
- const cliOptions = {
19
- outDir: "out-dir",
20
- clean: "clean",
21
- tailwind: "tailwind",
22
- theme: {
23
- colors: {
24
- main: "main-colors",
25
- support: "support-colors",
26
- neutral: "neutral-color"
27
- },
28
- typography: { fontFamily: "font-family" },
29
- borderRadius: "border-radius"
30
- }
31
- };
32
18
  const createTokens = async (theme) => {
33
- const { colors, typography, name, borderRadius, overrides } = theme;
19
+ const { typography, name, borderRadius, overrides } = theme;
34
20
  const { colorSchemes, sizeModes } = tokenSetDimensions;
21
+ const colors = addSeverityColors(theme.colors);
22
+ const colorNames = toColorNames(colors);
23
+ const colorTokens = Object.entries(generateColorTokens(colorNames, name));
35
24
  return { tokenSets: new Map([
36
25
  ["primitives/globals", generateGlobals()],
37
26
  ...sizeModes.map((size) => [`primitives/modes/size/${size}`, generateSize(size)]),
@@ -40,11 +29,10 @@ const createTokens = async (theme) => {
40
29
  [`primitives/modes/typography/primary/${name}`, generateTypography(name, typography)],
41
30
  [`primitives/modes/typography/secondary/${name}`, generateTypography(name, typography)],
42
31
  ...colorSchemes.flatMap((scheme) => [[`primitives/modes/color-scheme/${scheme}/${name}`, generateColorScheme(name, scheme, colors, overrides)]]),
43
- [`themes/${name}`, generateTheme(colors, name, borderRadius)],
44
- ["semantic/color", generateSemanticColors(colors, name)],
45
- ...Object.entries(generateColorModes(colors, name)).flatMap(([mode, colors]) => Object.entries(colors).map(([key, colorSet]) => [`semantic/modes/${mode}/${key}`, colorSet])),
46
- [`semantic/style`, generateSemanticStyle()]
32
+ [`themes/${name}`, generateTheme(colorNames, name, borderRadius)],
33
+ ...colorTokens.map(([colorName, colorSetTokens]) => [`semantic/color/${colorName}`, colorSetTokens]),
34
+ [`semantic/style`, generateSemanticStyle(colorNames)]
47
35
  ]) };
48
36
  };
49
37
  //#endregion
50
- export { cliOptions, createTokens, tokenSetDimensions };
38
+ export { createTokens, tokenSetDimensions };
@@ -1,9 +1,9 @@
1
- import { createTokens, tokenSetDimensions } from "./create.js";
2
- import { colorNamesByCategory } from "./utils.js";
3
- import { processThemeObject } from "./process/utils/getMultidimensionalThemes.js";
1
+ import { toColorNames } from "./utils.js";
4
2
  import { processPlatform } from "./process/platform.js";
3
+ import { processThemeObject } from "./process/utils/getMultidimensionalThemes.js";
5
4
  import { createThemeCSSFiles } from "./process/output/theme.js";
6
5
  import { generate$Themes } from "./create/generators/$themes.js";
6
+ import { createTokens, tokenSetDimensions } from "./create.js";
7
7
  import * as R from "ramda";
8
8
  //#region src/tokens/format.ts
9
9
  const formatTokens = async (options) => {
@@ -14,10 +14,12 @@ const formatTokens = async (options) => {
14
14
  });
15
15
  };
16
16
  const formatTheme = async (themeConfig) => {
17
+ const themeNames = [themeConfig.name];
18
+ const colorNames = toColorNames(themeConfig.colors);
17
19
  const { tokenSets } = await createTokens(themeConfig);
18
20
  return await formatTokens({
19
21
  tokenSets,
20
- processed$themes: (await generate$Themes(tokenSetDimensions, [themeConfig.name], colorNamesByCategory(themeConfig.colors))).map(processThemeObject),
22
+ processed$themes: (await generate$Themes(tokenSetDimensions, themeNames, colorNames)).map(processThemeObject),
21
23
  verbose: false
22
24
  });
23
25
  };
@@ -1,5 +1,5 @@
1
- import type { CreateConfigSchema } from '../config.js';
2
- export type GenerateConfigOptions = {
1
+ import type { CreateConfigSchema } from '../schemas/v1.1/schema.js';
2
+ type GenerateConfigOptions = {
3
3
  tokensDir: string;
4
4
  outFile?: string;
5
5
  };
@@ -7,4 +7,5 @@ export type GenerateConfigOptions = {
7
7
  * Generates a config file from existing design tokens
8
8
  */
9
9
  export declare function generateConfigFromTokens(options: GenerateConfigOptions): Promise<CreateConfigSchema>;
10
+ export {};
10
11
  //# sourceMappingURL=generate-config.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"generate-config.d.ts","sourceRoot":"","sources":["../../../src/tokens/generate-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AA6MvD,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA6E1G"}
1
+ {"version":3,"file":"generate-config.d.ts","sourceRoot":"","sources":["../../../src/tokens/generate-config.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAC;AA0LpE,KAAK,qBAAqB,GAAG;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;GAEG;AACH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CA8D1G"}
@@ -96,40 +96,21 @@ function extractFontFamilyFromPrimitives(typographyConfig, themeName) {
96
96
  if (typeof fontFamily === "object" && "$value" in fontFamily) return fontFamily.$value;
97
97
  }
98
98
  /**
99
- * Categorizes colors into main, support, and neutral based on color names
99
+ * Extracts colors from the theme tokens, excluding reserved colors and extracting base colors from color scales.
100
100
  */
101
- function categorizeColors(themeTokens, themeName) {
102
- const main = {};
103
- const support = {};
104
- let neutral = null;
105
- const builtInColors = [
106
- "neutral",
107
- "info",
108
- "success",
109
- "warning",
110
- "danger"
111
- ];
101
+ function extractColors(themeTokens, themeName) {
102
+ const colors = {};
112
103
  const specialKeys = ["link"];
113
104
  const themeColors = themeTokens[themeName];
114
- if (!themeColors) return {
115
- main,
116
- support,
117
- neutral
118
- };
105
+ if (!themeColors) return colors;
119
106
  for (const [colorName, colorValue] of Object.entries(themeColors)) {
120
107
  if (specialKeys.includes(colorName)) continue;
121
108
  if (typeof colorValue === "object" && !("$value" in colorValue)) {
122
109
  const baseColor = extractBaseColor(colorValue);
123
- if (baseColor) if (colorName === "neutral") neutral = baseColor;
124
- else if (builtInColors.includes(colorName)) {} else if (colorName === "accent") main[colorName] = baseColor;
125
- else support[colorName] = baseColor;
110
+ if (baseColor) colors[colorName] = baseColor;
126
111
  }
127
112
  }
128
- return {
129
- main,
130
- support,
131
- neutral
132
- };
113
+ return colors;
133
114
  }
134
115
  /**
135
116
  * Generates a config file from existing design tokens
@@ -149,26 +130,19 @@ async function generateConfigFromTokens(options) {
149
130
  const themeTokens = await readThemeTokens(tokensDir, themeName);
150
131
  const themeConfig = await readThemeConfig(tokensDir, themeName);
151
132
  const typographyConfig = await readTypographyConfig(tokensDir, themeName);
152
- const { main, support, neutral } = categorizeColors(themeTokens, themeName);
153
- if (Object.keys(main).length === 0) console.warn(pc.yellow(`\nWarning: No main colors found for theme ${themeName}`));
154
- if (!neutral) {
133
+ const colors = extractColors(themeTokens, themeName);
134
+ if (!colors.neutral) {
155
135
  console.warn(pc.yellow(`\nWarning: No neutral color found for theme ${themeName}`));
156
136
  continue;
157
137
  }
158
138
  const borderRadius = extractBorderRadius(themeConfig);
159
139
  const fontFamily = extractFontFamily(themeConfig) ?? extractFontFamilyFromPrimitives(typographyConfig, themeName);
160
140
  config.themes[themeName] = {
161
- colors: {
162
- main,
163
- support,
164
- neutral
165
- },
141
+ colors,
166
142
  borderRadius,
167
143
  typography: fontFamily ? { fontFamily } : void 0
168
144
  };
169
- console.log(`\n✅ Main colors: ${Object.keys(main).map((c) => pc.cyan(c)).join(", ") || pc.dim("none")}`);
170
- console.log(`\n✅ Support colors: ${Object.keys(support).map((c) => pc.cyan(c)).join(", ") || pc.dim("none")}`);
171
- console.log(`\n✅ Neutral: ${pc.cyan(neutral)}`);
145
+ console.log(`\n✅ Colors: ${Object.keys(colors).map((c) => pc.cyan(c)).join(", ") || pc.dim("none")}`);
172
146
  if (borderRadius !== void 0) console.log(`\n✅ Border radius: ${pc.cyan(String(borderRadius))}`);
173
147
  if (fontFamily) console.log(`\n✅ Font family: ${pc.cyan(fontFamily)}`);
174
148
  }
@@ -1,4 +1,5 @@
1
- export { cliOptions, createTokens } from './create.js';
1
+ export { deprecatedCLIOptions as cliOptions } from '../schemas/helpers.js';
2
+ export { createTokens } from './create.js';
2
3
  export { formatThemeCSS, formatTokens } from './format.js';
3
4
  export type { Theme as CreateTokensOptions } from './types.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AACvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,KAAK,IAAI,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,IAAI,UAAU,EAAE,MAAM,uBAAuB,CAAC;AAC3E,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3D,YAAY,EAAE,KAAK,IAAI,mBAAmB,EAAE,MAAM,YAAY,CAAC"}
@@ -1,3 +1,4 @@
1
- import { cliOptions, createTokens } from "./create.js";
1
+ import { deprecatedCLIOptions } from "../schemas/helpers.js";
2
+ import { createTokens } from "./create.js";
2
3
  import { formatThemeCSS, formatTokens } from "./format.js";
3
- export { cliOptions, createTokens, formatThemeCSS, formatTokens };
4
+ export { deprecatedCLIOptions as cliOptions, createTokens, formatThemeCSS, formatTokens };
@@ -1,12 +1,4 @@
1
- import type { BuiltInColors, ColorCategories } from '../../types.js';
2
1
  import { type GetStyleDictionaryConfig } from './shared.js';
3
2
  export declare const colorSchemeVariables: GetStyleDictionaryConfig;
4
- type ColorCategoryOpts = {
5
- category: ColorCategories;
6
- } | {
7
- category: 'builtin';
8
- color: BuiltInColors;
9
- };
10
- export declare const colorCategoryVariables: (opts: ColorCategoryOpts) => GetStyleDictionaryConfig;
11
- export {};
3
+ export declare const colorVariables: GetStyleDictionaryConfig;
12
4
  //# sourceMappingURL=color.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/color.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAKrE,OAAO,EAAkB,KAAK,wBAAwB,EAAU,MAAM,aAAa,CAAC;AAEpF,eAAO,MAAM,oBAAoB,EAAE,wBA8BlC,CAAC;AAEF,KAAK,iBAAiB,GAAG;IAAE,QAAQ,EAAE,eAAe,CAAA;CAAE,GAAG;IAAE,QAAQ,EAAE,SAAS,CAAC;IAAC,KAAK,EAAE,aAAa,CAAA;CAAE,CAAC;AAEvG,eAAO,MAAM,sBAAsB,GAChC,MAAM,iBAAiB,KAAG,wBAgD1B,CAAC"}
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/color.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,wBAAwB,EAAU,MAAM,aAAa,CAAC;AAEpF,eAAO,MAAM,oBAAoB,EAAE,wBA8BlC,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,wBAqC5B,CAAC"}
@@ -1,8 +1,7 @@
1
- import { isColorCategoryToken, isSemanticColorToken, typeEquals } from "../../utils.js";
1
+ import { isSemanticColorToken, pathStartsWithOneOf } from "../../utils.js";
2
2
  import { dsTransformers } from "./shared.js";
3
3
  import { formats } from "../formats/css.js";
4
4
  import { buildOptions } from "../platform.js";
5
- import * as R from "ramda";
6
5
  //#region src/tokens/process/configs/color.ts
7
6
  const colorSchemeVariables = ({ "color-scheme": colorScheme = "light", theme }) => {
8
7
  return {
@@ -18,16 +17,14 @@ const colorSchemeVariables = ({ "color-scheme": colorScheme = "light", theme })
18
17
  files: [{
19
18
  destination: `color-scheme/${colorScheme}.css`,
20
19
  format: formats.colorScheme.name,
21
- filter: (token) => typeEquals("color", token) && !R.startsWith(["global"], token.path)
20
+ filter: (token) => pathStartsWithOneOf(["color"], token) || token.path[1] === "color"
22
21
  }],
23
22
  options: { outputReferences: false }
24
23
  } }
25
24
  };
26
25
  };
27
- const colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme, theme, ...permutation }) => {
28
- const category = opts.category;
29
- const color = category === "builtin" ? opts.color : permutation[`${category}-color`];
30
- if (!color) throw new Error(category === "builtin" ? `Missing color for built-in color ${opts.color}` : `Missing color for category ${category}`);
26
+ const colorVariables = ({ "color-scheme": colorScheme, theme, ...permutation }) => {
27
+ const color = permutation.color;
31
28
  return {
32
29
  preprocessors: ["tokens-studio"],
33
30
  platforms: { css: {
@@ -41,11 +38,11 @@ const colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme, theme,
41
38
  files: [{
42
39
  destination: `color/${color}.css`,
43
40
  format: formats.colorCategory.name,
44
- filter: (token) => category === "builtin" ? isSemanticColorToken(token, color) : isColorCategoryToken(token, category)
41
+ filter: (token) => isSemanticColorToken(token, color)
45
42
  }],
46
43
  options: { outputReferences: true }
47
44
  } }
48
45
  };
49
46
  };
50
47
  //#endregion
51
- export { colorCategoryVariables, colorSchemeVariables };
48
+ export { colorSchemeVariables, colorVariables };
@@ -3,13 +3,7 @@ import type { GetStyleDictionaryConfig } from './configs/shared.js';
3
3
  import { type ProcessedThemeObject } from './utils/getMultidimensionalThemes.js';
4
4
  export declare const configs: {
5
5
  colorSchemeVariables: GetStyleDictionaryConfig;
6
- mainColorVariables: GetStyleDictionaryConfig;
7
- supportColorVariables: GetStyleDictionaryConfig;
8
- neutralColorVariables: GetStyleDictionaryConfig;
9
- successColorVariables: GetStyleDictionaryConfig;
10
- dangerColorVariables: GetStyleDictionaryConfig;
11
- warningColorVariables: GetStyleDictionaryConfig;
12
- infoColorVariables: GetStyleDictionaryConfig;
6
+ colorVariables: GetStyleDictionaryConfig;
13
7
  sizeModeVariables: GetStyleDictionaryConfig;
14
8
  sizeVariables: GetStyleDictionaryConfig;
15
9
  typographyVariables: GetStyleDictionaryConfig;
@@ -1 +1 @@
1
- {"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/process/configs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAInG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAQpE,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAa5G,eAAO,MAAM,OAAO;;;;;;;;;;;;;;CAcnB,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,WAAW,wBAAwB,EACnC,kBAAkB,oBAAoB,EAAE,EACxC,YAAY,cAAc,EAAE,EAC5B,SAAS,kBAAkB,KAC1B,2BAA2B,EAoD7B,CAAC"}
1
+ {"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/process/configs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAInG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAQpE,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAa5G,eAAO,MAAM,OAAO;;;;;;;;CAQnB,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,WAAW,wBAAwB,EACnC,kBAAkB,oBAAoB,EAAE,EACxC,YAAY,cAAc,EAAE,EAC5B,SAAS,kBAAkB,KAC1B,2BAA2B,EAoD7B,CAAC"}
@@ -1,14 +1,14 @@
1
1
  import { traverseObj } from "../utils.js";
2
2
  import { resolveMath, sizeRem, typographyName, unitless } from "./transformers.js";
3
3
  import { formats } from "./formats/css.js";
4
- import { colorCategoryVariables, colorSchemeVariables } from "./configs/color.js";
4
+ import { colorSchemeVariables, colorVariables } from "./configs/color.js";
5
5
  import { semanticVariables } from "./configs/semantic.js";
6
6
  import { sizeVariables } from "./configs/size.js";
7
7
  import { sizeModeVariables } from "./configs/size-mode.js";
8
8
  import { typeScaleVariables } from "./configs/type-scale.js";
9
9
  import { typographyVariables } from "./configs/typography.js";
10
- import { getMultidimensionalThemes } from "./utils/getMultidimensionalThemes.js";
11
10
  import { buildOptions } from "./platform.js";
11
+ import { getMultidimensionalThemes } from "./utils/getMultidimensionalThemes.js";
12
12
  import * as R from "ramda";
13
13
  import StyleDictionary from "style-dictionary";
14
14
  import { register } from "@tokens-studio/sd-transforms";
@@ -21,28 +21,7 @@ StyleDictionary.registerTransform(unitless);
21
21
  for (const format of Object.values(formats)) StyleDictionary.registerFormat(format);
22
22
  const configs = {
23
23
  colorSchemeVariables,
24
- mainColorVariables: colorCategoryVariables({ category: "main" }),
25
- supportColorVariables: colorCategoryVariables({ category: "support" }),
26
- neutralColorVariables: colorCategoryVariables({
27
- category: "builtin",
28
- color: "neutral"
29
- }),
30
- successColorVariables: colorCategoryVariables({
31
- category: "builtin",
32
- color: "success"
33
- }),
34
- dangerColorVariables: colorCategoryVariables({
35
- category: "builtin",
36
- color: "danger"
37
- }),
38
- warningColorVariables: colorCategoryVariables({
39
- category: "builtin",
40
- color: "warning"
41
- }),
42
- infoColorVariables: colorCategoryVariables({
43
- category: "builtin",
44
- color: "info"
45
- }),
24
+ colorVariables,
46
25
  sizeModeVariables,
47
26
  sizeVariables,
48
27
  typographyVariables,
@@ -1 +1 @@
1
- {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/color.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAarD,eAAO,MAAM,WAAW,EAAE,MAgDzB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAwC3B,CAAC"}
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/color.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAYrD,eAAO,MAAM,WAAW,EAAE,MA2CzB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAqC3B,CAAC"}
@@ -1,5 +1,4 @@
1
- import { colorCategories } from "../../../types.js";
2
- import { isColorCategoryToken, isGlobalColorToken, isSemanticToken } from "../../../utils.js";
1
+ import { isSemanticToken } from "../../../utils.js";
3
2
  import { buildOptions } from "../../platform.js";
4
3
  import * as R from "ramda";
5
4
  import { createPropertyFormatter } from "style-dictionary/utils";
@@ -23,7 +22,7 @@ const colorScheme = {
23
22
  usesDtcg
24
23
  });
25
24
  const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `\n color-scheme: ${colorScheme_};\n` : "";
26
- const content = `{\n${allTokens.filter(R.allPass([R.anyPass([isSemanticToken, isGlobalColorToken]), (t) => !isColorCategoryToken(t)])).map((token) => ({
25
+ const content = `{\n${allTokens.filter(R.allPass([R.anyPass([isSemanticToken])])).map((token) => ({
27
26
  token,
28
27
  formatted: format(token)
29
28
  })).map(R.view(R.lensProp("formatted"))).join("\n")}\n${colorSchemeProperty}}\n`;
@@ -47,7 +46,7 @@ const colorCategory = {
47
46
  name: token.name.replace(/color-\w+-/, "color-"),
48
47
  original: {
49
48
  ...token.original,
50
- $value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
49
+ $value: `{${token.path.join(".")}}`
51
50
  }
52
51
  }));
53
52
  const formattedMap = dictionary.allTokens.map((token) => ({
@@ -1,4 +1,3 @@
1
1
  import type { Format } from 'style-dictionary/types';
2
2
  export declare const sizeMode: Format;
3
- export declare function wrapInLayer(content: string, layer?: string): string;
4
3
  //# sourceMappingURL=size-mode.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"size-mode.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/size-mode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAerD,eAAO,MAAM,QAAQ,EAAE,MAsDtB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,UAE1D"}
1
+ {"version":3,"file":"size-mode.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/size-mode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAerD,eAAO,MAAM,QAAQ,EAAE,MAsDtB,CAAC"}
@@ -47,4 +47,4 @@ function wrapInLayer(content, layer) {
47
47
  return R.isNotNil(layer) ? `@layer ${layer} {\n${content}\n}\n` : `${content}\n`;
48
48
  }
49
49
  //#endregion
50
- export { sizeMode, wrapInLayer };
50
+ export { sizeMode };
@@ -1,18 +1,6 @@
1
1
  import type { TransformedToken } from 'style-dictionary';
2
2
  import type { Format } from 'style-dictionary/types';
3
3
  export declare const isInlineTokens: (t: TransformedToken) => boolean;
4
- /**
5
- * Overrides the default sizing formula with a custom one that supports [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.
6
- *
7
- * @param format - Function to format a token into a CSS property string.
8
- * @param tokens - Array of transformed tokens to format.
9
- * @returns Object with formatted CSS strings for calc and round.
10
- */
11
- export declare const overrideSizingFormula: (format: (t: TransformedToken) => string, token: TransformedToken) => {
12
- name: string;
13
- round: string;
14
- calc: string;
15
- };
16
4
  export declare const sizingTemplate: ({ round, calc }: {
17
5
  round: string[];
18
6
  calc: string[];
@@ -1 +1 @@
1
- {"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/size.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AASrD,eAAO,MAAM,cAAc,MAJY,gBAAgB,YAI+C,CAAC;AAEvG;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,EAAE,gBAAgB,KAAK,MAAM,EAAE,OAAO,gBAAgB;;;;CAmBrG,CAAC;AAwBF,eAAO,MAAM,cAAc,GAAI,iBAAiB;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,WAOlF,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAyClB,CAAC"}
1
+ {"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/size.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AASrD,eAAO,MAAM,cAAc,MAJY,gBAAgB,YAI+C,CAAC;AAoDvG,eAAO,MAAM,cAAc,GAAI,iBAAiB;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,WAOlF,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAyClB,CAAC"}
@@ -90,4 +90,4 @@ const size = {
90
90
  }
91
91
  };
92
92
  //#endregion
93
- export { isInlineTokens, overrideSizingFormula, size, sizingTemplate };
93
+ export { isInlineTokens, size, sizingTemplate };
@@ -1 +1 @@
1
- {"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/output/declarations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAEnG,eAAO,MAAM,iBAAiB,QAA2B,CAAC;AAE1D,eAAO,MAAM,0BAA0B,GAAI,kBAAkB,oBAAoB,EAAE,KAAG,UAAU,EAe/F,CAAC"}
1
+ {"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/output/declarations.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjD,OAAO,EAAkB,KAAK,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAElG,eAAO,MAAM,iBAAiB,QAA2B,CAAC;AAE1D,eAAO,MAAM,0BAA0B,GAAI,kBAAkB,oBAAoB,EAAE,KAAG,UAAU,EAa/F,CAAC"}