@digdir/designsystemet 1.0.0-next.34 → 1.0.0-next.36

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 (149) hide show
  1. package/README.md +16 -0
  2. package/dist/{types/bin → bin}/designsystemet.d.ts.map +1 -1
  3. package/dist/bin/designsystemet.js +16 -16
  4. package/dist/src/colors/index.d.ts.map +1 -0
  5. package/dist/{types/src → src}/colors/theme.d.ts +8 -3
  6. package/dist/src/colors/theme.d.ts.map +1 -0
  7. package/dist/src/colors/theme.js +17 -18
  8. package/dist/{types/src → src}/colors/types.d.ts +0 -1
  9. package/dist/src/colors/types.d.ts.map +1 -0
  10. package/dist/{types/src → src}/colors/utils.d.ts +7 -1
  11. package/dist/src/colors/utils.d.ts.map +1 -0
  12. package/dist/src/colors/utils.js +13 -6
  13. package/dist/src/index.d.ts +3 -0
  14. package/dist/src/index.d.ts.map +1 -0
  15. package/dist/src/index.js +2 -0
  16. package/dist/src/init/createTokensPackage.d.ts.map +1 -0
  17. package/dist/src/init/generateMetadataJson.d.ts.map +1 -0
  18. package/dist/src/init/generateThemesJson.d.ts.map +1 -0
  19. package/dist/src/init/index.d.ts.map +1 -0
  20. package/dist/src/init/nextStepsMarkdown.d.ts.map +1 -0
  21. package/dist/src/init/utils.d.ts.map +1 -0
  22. package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
  23. package/dist/src/migrations/beta-to-v1.js +4 -4
  24. package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
  25. package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
  26. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +1 -0
  27. package/dist/src/migrations/codemods/jsx/run.d.ts.map +1 -0
  28. package/dist/src/migrations/index.d.ts.map +1 -0
  29. package/dist/src/migrations/react-beta-to-v1.d.ts.map +1 -0
  30. package/dist/src/tokens/build/actions.d.ts.map +1 -0
  31. package/dist/src/tokens/build/builtin-colors.css +87 -0
  32. package/dist/src/tokens/build/configs.d.ts +21 -0
  33. package/dist/src/tokens/build/configs.d.ts.map +1 -0
  34. package/dist/src/tokens/build/configs.js +114 -61
  35. package/dist/src/tokens/build/formats/css.d.ts +13 -0
  36. package/dist/src/tokens/build/formats/css.d.ts.map +1 -0
  37. package/dist/src/tokens/build/formats/css.js +55 -4
  38. package/dist/src/tokens/build/formats/js-tokens.d.ts.map +1 -0
  39. package/dist/src/tokens/build/formats/js-tokens.js +2 -2
  40. package/dist/{types/src → src}/tokens/build/transformers.d.ts +1 -0
  41. package/dist/src/tokens/build/transformers.d.ts.map +1 -0
  42. package/dist/src/tokens/build/transformers.js +13 -0
  43. package/dist/src/tokens/build/types.d.ts +44 -0
  44. package/dist/src/tokens/build/types.d.ts.map +1 -0
  45. package/dist/src/tokens/build/types.js +7 -0
  46. package/dist/src/tokens/build/utils/entryfile.d.ts.map +1 -0
  47. package/dist/src/tokens/build/utils/entryfile.js +39 -4
  48. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts +35 -0
  49. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +1 -0
  50. package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +112 -0
  51. package/dist/src/tokens/build/utils/noCase.d.ts.map +1 -0
  52. package/dist/{types/src → src}/tokens/build/utils/utils.d.ts +3 -0
  53. package/dist/src/tokens/build/utils/utils.d.ts.map +1 -0
  54. package/dist/src/tokens/build/utils/utils.js +15 -0
  55. package/dist/src/tokens/build.d.ts +17 -0
  56. package/dist/src/tokens/build.d.ts.map +1 -0
  57. package/dist/src/tokens/build.js +81 -68
  58. package/dist/{types/src → src}/tokens/create.d.ts +5 -0
  59. package/dist/src/tokens/create.d.ts.map +1 -0
  60. package/dist/src/tokens/create.js +13 -10
  61. package/dist/src/tokens/design-tokens/default/primitives/globals.json +2 -8
  62. package/dist/src/tokens/design-tokens/default/semantic/style.json +109 -217
  63. package/dist/src/tokens/design-tokens/template/$metadata.json +4 -0
  64. package/dist/src/tokens/design-tokens/template/$themes.json +852 -728
  65. package/dist/src/tokens/design-tokens/template/semantic/color-base-file.json +262 -0
  66. package/dist/src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json +62 -0
  67. package/dist/src/tokens/design-tokens/template/semantic/semantic-color-template.json +62 -0
  68. package/dist/src/tokens/design-tokens/template/themes/theme-base-file.json +53 -0
  69. package/dist/src/tokens/design-tokens/template/themes/theme-color-template.json +62 -0
  70. package/dist/src/tokens/index.d.ts +2 -0
  71. package/dist/src/tokens/index.d.ts.map +1 -0
  72. package/dist/src/tokens/index.js +5 -0
  73. package/dist/src/tokens/template.d.ts.map +1 -0
  74. package/dist/src/tokens/template.js +36 -4
  75. package/dist/{types/src → src}/tokens/types.d.ts +5 -2
  76. package/dist/src/tokens/types.d.ts.map +1 -0
  77. package/dist/{types/src → src}/tokens/write/generate$metadata.d.ts +2 -1
  78. package/dist/src/tokens/write/generate$metadata.d.ts.map +1 -0
  79. package/dist/src/tokens/write/generate$metadata.js +3 -1
  80. package/dist/{types/src → src}/tokens/write/generate$themes.d.ts +2 -1
  81. package/dist/src/tokens/write/generate$themes.d.ts.map +1 -0
  82. package/dist/src/tokens/write/generate$themes.js +16 -2
  83. package/dist/{types/src → src}/tokens/write.d.ts +2 -1
  84. package/dist/src/tokens/write.d.ts.map +1 -0
  85. package/dist/src/tokens/write.js +93 -5
  86. package/package.json +11 -6
  87. package/dist/src/init/template/prettier.config.js +0 -5
  88. package/dist/src/tokens/build/utils/permutateThemes.js +0 -64
  89. package/dist/src/tokens/design-tokens/default/semantic/color.json +0 -572
  90. package/dist/src/tokens/design-tokens/template/themes/theme.json +0 -334
  91. package/dist/types/src/colors/index.d.ts.map +0 -1
  92. package/dist/types/src/colors/theme.d.ts.map +0 -1
  93. package/dist/types/src/colors/types.d.ts.map +0 -1
  94. package/dist/types/src/colors/utils.d.ts.map +0 -1
  95. package/dist/types/src/init/createTokensPackage.d.ts.map +0 -1
  96. package/dist/types/src/init/generateMetadataJson.d.ts.map +0 -1
  97. package/dist/types/src/init/generateThemesJson.d.ts.map +0 -1
  98. package/dist/types/src/init/index.d.ts.map +0 -1
  99. package/dist/types/src/init/nextStepsMarkdown.d.ts.map +0 -1
  100. package/dist/types/src/init/template/prettier.config.d.mts +0 -9
  101. package/dist/types/src/init/template/prettier.config.d.mts.map +0 -1
  102. package/dist/types/src/init/utils.d.ts.map +0 -1
  103. package/dist/types/src/migrations/beta-to-v1.d.ts.map +0 -1
  104. package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +0 -1
  105. package/dist/types/src/migrations/codemods/css/run.d.ts.map +0 -1
  106. package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
  107. package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +0 -1
  108. package/dist/types/src/migrations/index.d.ts.map +0 -1
  109. package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +0 -1
  110. package/dist/types/src/tokens/build/actions.d.ts.map +0 -1
  111. package/dist/types/src/tokens/build/configs.d.ts +0 -31
  112. package/dist/types/src/tokens/build/configs.d.ts.map +0 -1
  113. package/dist/types/src/tokens/build/formats/css.d.ts +0 -5
  114. package/dist/types/src/tokens/build/formats/css.d.ts.map +0 -1
  115. package/dist/types/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
  116. package/dist/types/src/tokens/build/transformers.d.ts.map +0 -1
  117. package/dist/types/src/tokens/build/utils/entryfile.d.ts.map +0 -1
  118. package/dist/types/src/tokens/build/utils/noCase.d.ts.map +0 -1
  119. package/dist/types/src/tokens/build/utils/permutateThemes.d.ts +0 -17
  120. package/dist/types/src/tokens/build/utils/permutateThemes.d.ts.map +0 -1
  121. package/dist/types/src/tokens/build/utils/utils.d.ts.map +0 -1
  122. package/dist/types/src/tokens/build.d.ts +0 -11
  123. package/dist/types/src/tokens/build.d.ts.map +0 -1
  124. package/dist/types/src/tokens/create.d.ts.map +0 -1
  125. package/dist/types/src/tokens/template.d.ts.map +0 -1
  126. package/dist/types/src/tokens/types.d.ts.map +0 -1
  127. package/dist/types/src/tokens/write/generate$metadata.d.ts.map +0 -1
  128. package/dist/types/src/tokens/write/generate$themes.d.ts.map +0 -1
  129. package/dist/types/src/tokens/write.d.ts.map +0 -1
  130. /package/dist/{types/bin → bin}/designsystemet.d.ts +0 -0
  131. /package/dist/{types/src → src}/colors/index.d.ts +0 -0
  132. /package/dist/{types/src → src}/init/createTokensPackage.d.ts +0 -0
  133. /package/dist/{types/src → src}/init/generateMetadataJson.d.ts +0 -0
  134. /package/dist/{types/src → src}/init/generateThemesJson.d.ts +0 -0
  135. /package/dist/{types/src → src}/init/index.d.ts +0 -0
  136. /package/dist/{types/src → src}/init/nextStepsMarkdown.d.ts +0 -0
  137. /package/dist/{types/src → src}/init/utils.d.ts +0 -0
  138. /package/dist/{types/src → src}/migrations/beta-to-v1.d.ts +0 -0
  139. /package/dist/{types/src → src}/migrations/codemods/css/plugins.d.ts +0 -0
  140. /package/dist/{types/src → src}/migrations/codemods/css/run.d.ts +0 -0
  141. /package/dist/{types/src → src}/migrations/codemods/jsx/classname-prefix.d.ts +0 -0
  142. /package/dist/{types/src → src}/migrations/codemods/jsx/run.d.ts +0 -0
  143. /package/dist/{types/src → src}/migrations/index.d.ts +0 -0
  144. /package/dist/{types/src → src}/migrations/react-beta-to-v1.d.ts +0 -0
  145. /package/dist/{types/src → src}/tokens/build/actions.d.ts +0 -0
  146. /package/dist/{types/src → src}/tokens/build/formats/js-tokens.d.ts +0 -0
  147. /package/dist/{types/src → src}/tokens/build/utils/entryfile.d.ts +0 -0
  148. /package/dist/{types/src → src}/tokens/build/utils/noCase.d.ts +0 -0
  149. /package/dist/{types/src → src}/tokens/template.d.ts +0 -0
@@ -2,27 +2,28 @@ import { expandTypesMap, register } from "@tokens-studio/sd-transforms";
2
2
  import * as R from "ramda";
3
3
  import StyleDictionary from "style-dictionary";
4
4
  import { outputReferencesFilter } from "style-dictionary/utils";
5
- import * as formats from "./formats/css.js";
5
+ import { DEFAULT_COLOR, buildOptions } from "../build.js";
6
+ import { formats } from "./formats/css.js";
6
7
  import { jsTokens } from "./formats/js-tokens.js";
7
- import { nameKebab, sizeRem, typographyName } from "./transformers.js";
8
- import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
9
- import { pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
8
+ import { nameKebab, resolveMath, sizeRem, typographyName } from "./transformers.js";
9
+ import { getMultidimensionalThemes } from "./utils/getMultidimensionalThemes.js";
10
+ import { isColorCategoryToken, pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
10
11
  void register(StyleDictionary, { withSDBuiltins: false });
11
12
  const usesDtcg = true;
12
13
  const prefix = "ds";
13
14
  const basePxFontSize = 16;
14
- const separator = "_";
15
15
  const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
16
16
  StyleDictionary.registerTransform(sizeRem);
17
17
  StyleDictionary.registerTransform(nameKebab);
18
18
  StyleDictionary.registerTransform(typographyName);
19
+ StyleDictionary.registerTransform(resolveMath);
19
20
  StyleDictionary.registerFormat(jsTokens);
20
- StyleDictionary.registerFormat(formats.colormode);
21
- StyleDictionary.registerFormat(formats.semantic);
22
- StyleDictionary.registerFormat(formats.typography);
21
+ for (const format of Object.values(formats)) {
22
+ StyleDictionary.registerFormat(format);
23
+ }
23
24
  const dsTransformers = [
24
25
  nameKebab.name,
25
- `ts/resolveMath`,
26
+ resolveMath.name,
26
27
  "ts/size/px",
27
28
  sizeRem.name,
28
29
  "ts/typography/fontWeight",
@@ -33,22 +34,17 @@ const dsTransformers = [
33
34
  "shadow/css/shorthand"
34
35
  ];
35
36
  const paritionPrimitives = R.partition(R.test(/(?!.*global\.json).*primitives.*/));
36
- const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
37
37
  const outputColorReferences = (token) => {
38
38
  if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) && R.includes("semantic/color", token.filePath)) {
39
39
  return true;
40
40
  }
41
41
  return false;
42
42
  };
43
- const permutateThemes = ($themes) => permutateThemes_($themes, {
44
- separator
45
- });
46
- const colorModeVariables = ({ mode = "light", outPath, theme }) => {
43
+ const colorModeVariables = ({ mode = "light", theme }, { outPath }) => {
47
44
  const selector = `${mode === "light" ? ":root, " : ""}[data-ds-color-mode="${mode}"]`;
48
45
  const layer = `ds.theme.color-mode.${mode}`;
49
46
  return {
50
47
  usesDtcg,
51
- log: { verbosity: "silent" },
52
48
  preprocessors: ["tokens-studio"],
53
49
  platforms: {
54
50
  css: {
@@ -71,19 +67,76 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
71
67
  ],
72
68
  options: {
73
69
  fileHeader,
74
- outputReferences: (token, options) => outputColorReferences(token) && outputReferencesFilter(token, options)
70
+ outputReferences: false
75
71
  }
76
72
  }
77
73
  }
78
74
  };
79
75
  };
80
- const semanticVariables = ({ outPath, theme }) => {
76
+ const colorCategoryVariables = (category) => ({ mode, theme, [`${category}-color`]: color }, { outPath }) => {
77
+ const layer = `ds.theme.color`;
78
+ const isDefault = color === buildOptions?.accentColor;
79
+ const selector = `${isDefault ? ":root, " : ""}[data-color="${color}"]`;
80
+ const config = {
81
+ usesDtcg,
82
+ preprocessors: ["tokens-studio"],
83
+ platforms: {
84
+ css: {
85
+ // custom
86
+ outPath,
87
+ mode,
88
+ theme,
89
+ selector,
90
+ layer,
91
+ //
92
+ prefix,
93
+ buildPath: `${outPath}/${theme}/`,
94
+ transforms: dsTransformers,
95
+ files: [
96
+ {
97
+ destination: `color/${color}.css`,
98
+ format: formats.colorcategory.name,
99
+ filter: (token) => isColorCategoryToken(token, category)
100
+ }
101
+ ],
102
+ options: {
103
+ fileHeader,
104
+ outputReferences: true
105
+ }
106
+ }
107
+ }
108
+ };
109
+ if (isDefault && color !== DEFAULT_COLOR) {
110
+ console.log(
111
+ `Creating "${DEFAULT_COLOR}" color variables pointing to "${color}", since a color named "${DEFAULT_COLOR}" is not defined`
112
+ );
113
+ const defaultColorConfig = R.mergeDeepRight(config, {
114
+ platforms: {
115
+ css: {
116
+ selector: ":root",
117
+ files: [
118
+ {
119
+ ...config.platforms?.css?.files?.[0],
120
+ destination: `color/${DEFAULT_COLOR}.css`
121
+ }
122
+ ],
123
+ options: { replaceCategoryWith: DEFAULT_COLOR }
124
+ }
125
+ }
126
+ });
127
+ return [
128
+ { config },
129
+ { config: defaultColorConfig, permutationOverrides: { "main-color": `${DEFAULT_COLOR} \u2192 ${color}` } }
130
+ ];
131
+ }
132
+ return config;
133
+ };
134
+ const semanticVariables = ({ theme }, { outPath }) => {
81
135
  const selector = `:root`;
82
136
  const layer = `ds.theme.semantic`;
83
- const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing", "border-radius"], token);
137
+ const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing"], token);
84
138
  return {
85
139
  usesDtcg,
86
- log: { verbosity: "silent" },
87
140
  preprocessors: ["tokens-studio"],
88
141
  platforms: {
89
142
  css: {
@@ -107,16 +160,18 @@ const semanticVariables = ({ outPath, theme }) => {
107
160
  ],
108
161
  options: {
109
162
  fileHeader,
110
- outputReferences: (token, options) => isCalculatedToken(token) && outputReferencesFilter(token, options)
163
+ outputReferences: (token, options) => {
164
+ const include = pathStartsWithOneOf(["border-radius"], token);
165
+ return (include || isCalculatedToken(token)) && outputReferencesFilter(token, options);
166
+ }
111
167
  }
112
168
  }
113
169
  }
114
170
  };
115
171
  };
116
- const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
172
+ const typescriptTokens = ({ mode, theme }, { outPath }) => {
117
173
  return {
118
174
  usesDtcg,
119
- log: { verbosity: "silent" },
120
175
  preprocessors: ["tokens-studio"],
121
176
  platforms: {
122
177
  ts: {
@@ -146,12 +201,11 @@ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
146
201
  }
147
202
  };
148
203
  };
149
- const typographyVariables = ({ outPath, theme, typography }) => {
204
+ const typographyVariables = ({ theme, typography }, { outPath }) => {
150
205
  const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
151
206
  const layer = `ds.theme.typography.${typography}`;
152
207
  return {
153
208
  usesDtcg: true,
154
- log: { verbosity: "silent" },
155
209
  preprocessors: ["tokens-studio"],
156
210
  expand: {
157
211
  include: ["typography"],
@@ -196,43 +250,42 @@ const typographyVariables = ({ outPath, theme, typography }) => {
196
250
  }
197
251
  };
198
252
  };
199
- const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes) => permutatedThemes.map((permutatedTheme) => {
200
- const {
201
- selectedTokenSets = [],
202
- mode = "unknown",
203
- theme = "unknown",
204
- semantic = "unknown",
205
- size = "unknown",
206
- typography = "unknown"
207
- } = permutatedTheme;
208
- if (hasUnknownProps(permutatedTheme)) {
209
- throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
210
- }
211
- const setsWithPaths = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
212
- const [source, include] = paritionPrimitives(setsWithPaths);
213
- const config_ = getConfig({
214
- outPath,
215
- theme,
216
- mode,
217
- semantic,
218
- size,
219
- typography
220
- });
221
- const config = {
222
- ...config_,
223
- source,
224
- include
225
- };
226
- return { mode, theme, semantic, size, typography, config };
227
- }).sort();
228
- export {
229
- basePxFontSize,
253
+ const configs = {
230
254
  colorModeVariables,
231
- getConfigs,
232
- permutateThemes,
233
- prefix,
255
+ mainColorVariables: colorCategoryVariables("main"),
256
+ supportColorVariables: colorCategoryVariables("support"),
257
+ typographyVariables,
234
258
  semanticVariables,
235
- separator,
236
- typescriptTokens,
237
- typographyVariables
259
+ typescriptTokens
260
+ };
261
+ const getConfigsForThemeDimensions = (getConfig, themes, dimensions, options) => {
262
+ const { outPath, tokensDir } = options;
263
+ const permutations = getMultidimensionalThemes(themes, dimensions);
264
+ return permutations.flatMap(({ selectedTokenSets, permutation }) => {
265
+ const setsWithPaths = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
266
+ const [source, include] = paritionPrimitives(setsWithPaths);
267
+ const configOrConfigs = getConfig(permutation, { outPath });
268
+ const configs_ = Array.isArray(configOrConfigs) ? configOrConfigs : [{ config: configOrConfigs }];
269
+ const configs2 = configs_.map(({ config, permutationOverrides }) => {
270
+ return {
271
+ permutation: { ...permutation, ...permutationOverrides },
272
+ config: {
273
+ ...config,
274
+ log: {
275
+ ...config?.log,
276
+ verbosity: buildOptions?.verbose ? "verbose" : "silent"
277
+ },
278
+ source,
279
+ include
280
+ }
281
+ };
282
+ });
283
+ return configs2;
284
+ }).sort();
285
+ };
286
+ export {
287
+ basePxFontSize,
288
+ configs,
289
+ getConfigsForThemeDimensions,
290
+ prefix
238
291
  };
@@ -0,0 +1,13 @@
1
+ import type { Format } from 'style-dictionary/types';
2
+ declare module 'style-dictionary/types' {
3
+ interface LocalOptions {
4
+ replaceCategoryWith?: string;
5
+ }
6
+ }
7
+ export declare const formats: {
8
+ colormode: Format;
9
+ colorcategory: Format;
10
+ semantic: Format;
11
+ typography: Format;
12
+ };
13
+ //# sourceMappingURL=css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/css.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAuDrD,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,YAAY;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B;CACF;AA2GD,eAAO,MAAM,OAAO;;;;;CAKc,CAAC"}
@@ -1,6 +1,7 @@
1
1
  import * as R from "ramda";
2
2
  import { createPropertyFormatter, fileHeader, usesReferences } from "style-dictionary/utils";
3
- import { getValue } from "../utils/utils.js";
3
+ import { colorCategories } from "../types.js";
4
+ import { getValue, isColorCategoryToken, isGlobalColorToken, isSemanticToken } from "../utils/utils.js";
4
5
  const prefersColorScheme = (mode, content) => `
5
6
  @media (prefers-color-scheme: ${mode}) {
6
7
  [data-ds-color-mode="auto"] ${content}
@@ -23,7 +24,19 @@ const colormode = {
23
24
  const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `
24
25
  color-scheme: ${mode_};
25
26
  ` : "";
26
- const formattedTokens = dictionary.allTokens.map(format).join("\n");
27
+ const filteredAllTokens = allTokens.filter(
28
+ R.allPass([
29
+ R.anyPass([
30
+ // Include semantic tokens in the output
31
+ isSemanticToken,
32
+ // Include global color tokens
33
+ isGlobalColorToken
34
+ ]),
35
+ // Don't include color category tokens -- they are exported separately
36
+ (t) => !isColorCategoryToken(t)
37
+ ])
38
+ );
39
+ const formattedTokens = filteredAllTokens.map(format).join("\n");
27
40
  const content = `{
28
41
  ${formattedTokens}
29
42
  ${colorSchemeProperty}}
@@ -37,6 +50,40 @@ ${selector} ${content} ${autoSelectorContent}
37
50
  return header + body;
38
51
  }
39
52
  };
53
+ const colorcategory = {
54
+ name: "ds/css-colorcategory",
55
+ format: async ({ dictionary, file, options, platform }) => {
56
+ const { outputReferences, usesDtcg, replaceCategoryWith = "" } = options;
57
+ const { selector, layer } = platform;
58
+ const header = await fileHeader({ file });
59
+ const format = R.compose(
60
+ createPropertyFormatter({
61
+ outputReferences,
62
+ dictionary,
63
+ format: "css",
64
+ usesDtcg
65
+ }),
66
+ (token) => ({
67
+ ...token,
68
+ name: token.name.replace(
69
+ new RegExp(`-(${colorCategories.main}|${colorCategories.support})-`),
70
+ replaceCategoryWith ? `-${replaceCategoryWith}-` : "-"
71
+ )
72
+ })
73
+ );
74
+ const formattedTokens = dictionary.allTokens.map(format).join("\n");
75
+ const content = `{
76
+ ${formattedTokens}
77
+ }
78
+ `;
79
+ const body = R.isNotNil(layer) ? `@layer ${layer} {
80
+ ${selector} ${content}
81
+ }
82
+ ` : `${selector} ${content}
83
+ `;
84
+ return header + body;
85
+ }
86
+ };
40
87
  const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}: calc(${R.trim(split[1])});`);
41
88
  const semantic = {
42
89
  name: "ds/css-semantic",
@@ -56,6 +103,7 @@ const semantic = {
56
103
  if (isCalculatedToken?.(token, options)) {
57
104
  return calculatedVariable(format(token));
58
105
  }
106
+ return format(token);
59
107
  }
60
108
  return format(token);
61
109
  }, dictionary.allTokens);
@@ -87,7 +135,6 @@ const typography = {
87
135
  format: "css",
88
136
  usesDtcg
89
137
  });
90
- console.log("dictionary.allTokens", dictionary.allTokens);
91
138
  const filteredTokens = R.reject(typographyFontFamilyPredicate, dictionary.allTokens);
92
139
  const formattedTokens = R.pipe(R.map(format), R.join("\n"))(filteredTokens);
93
140
  const content = selector ? `${selector} {
@@ -99,8 +146,12 @@ ${content}
99
146
  return header + body;
100
147
  }
101
148
  };
102
- export {
149
+ const formats = {
103
150
  colormode,
151
+ colorcategory,
104
152
  semantic,
105
153
  typography
106
154
  };
155
+ export {
156
+ formats
157
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"js-tokens.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/js-tokens.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;AAmBvE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MA2BtB,CAAC"}
@@ -1,9 +1,9 @@
1
1
  import * as R from "ramda";
2
2
  import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
3
- import { getType } from "../utils/utils.js";
3
+ import { getType, isColorCategoryToken } from "../utils/utils.js";
4
4
  const groupByType = R.groupBy((token) => getType(token));
5
5
  const removeUnwatedTokens = R.filter(
6
- (token) => !["ds-base-spacing", "ds-base-sizing"].includes(token.name)
6
+ (token) => !["ds-base-spacing", "ds-base-sizing"].includes(token.name) && !isColorCategoryToken(token)
7
7
  );
8
8
  const dissocExtensions = R.pipe(R.dissoc("$extensions"), R.dissocPath(["original", "$extensions"]));
9
9
  const removeUnwatedProps = R.map((token) => dissocExtensions(token));
@@ -2,4 +2,5 @@ import type { Transform } from 'style-dictionary/types';
2
2
  export declare const sizeRem: Transform;
3
3
  export declare const nameKebab: Transform;
4
4
  export declare const typographyName: Transform;
5
+ export declare const resolveMath: Transform;
5
6
  //# sourceMappingURL=transformers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD,eAAO,MAAM,OAAO,EAAE,SAyBrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,SASvB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,SAS5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,SAWzB,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
1
2
  import * as R from "ramda";
2
3
  import { noCase } from "./utils/noCase.js";
3
4
  import { getValue, pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
@@ -44,8 +45,20 @@ const typographyName = {
44
45
  return token.name.replace("-typography", "");
45
46
  }
46
47
  };
48
+ const resolveMath = {
49
+ name: "ds/resolveMath",
50
+ type: "value",
51
+ transitive: true,
52
+ filter: (token) => {
53
+ const isValidValue = ["string", "object"].includes(typeof (token.$value ?? token.value));
54
+ const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
55
+ return isValidValue && isTokenOfInterest;
56
+ },
57
+ transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
58
+ };
47
59
  export {
48
60
  nameKebab,
61
+ resolveMath,
49
62
  sizeRem,
50
63
  typographyName
51
64
  };
@@ -0,0 +1,44 @@
1
+ import type { Config as StyleDictionaryConfig, TransformedToken } from 'style-dictionary/types';
2
+ import type { GetStyleDictionaryConfig } from './configs';
3
+ export declare const colorCategories: {
4
+ readonly main: "main";
5
+ readonly support: "support";
6
+ };
7
+ export type ColorCategories = keyof typeof colorCategories;
8
+ /**
9
+ * A multi-dimensional theme is a concrete permutation of the possible theme dimensions
10
+ */
11
+ export type ThemePermutation = {
12
+ mode: string;
13
+ 'main-color': string;
14
+ 'support-color': string;
15
+ semantic: string;
16
+ size: string;
17
+ theme: string;
18
+ typography: string;
19
+ };
20
+ export type ThemeDimension = keyof ThemePermutation;
21
+ export type IsCalculatedToken = (token: TransformedToken, options?: StyleDictionaryConfig) => boolean;
22
+ export type GetSdConfigOptions = {
23
+ outPath: string;
24
+ tokensDir: string;
25
+ };
26
+ export type BuildConfig = {
27
+ /** Optional name of the build config - only used in the console output */
28
+ name?: string;
29
+ /** Style Dictionary configuration creator */
30
+ getConfig: GetStyleDictionaryConfig;
31
+ /** Which theme dimensions to include. `theme` (e.g. digdir/altinn) is always included. */
32
+ dimensions: ThemeDimension[];
33
+ /** Custom options used when creating Style Dictionary configs. If not supplied, the default is used */
34
+ options?: Partial<GetSdConfigOptions>;
35
+ /** Custom build function. If not supplied, the default is used. */
36
+ build?: (sdConfigs: SDConfigForThemePermutation[], options: GetSdConfigOptions) => Promise<void>;
37
+ /** Whether the build config is enabled. @default () => true */
38
+ enabled?: () => boolean;
39
+ };
40
+ export type SDConfigForThemePermutation = {
41
+ permutation: ThemePermutation;
42
+ config: StyleDictionaryConfig;
43
+ };
44
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,eAAO,MAAM,eAAe;;;CAGlB,CAAC;AACX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC;AAEtG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,SAAS,EAAE,wBAAwB,CAAC;IACpC,0FAA0F;IAC1F,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,uGAAuG;IACvG,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACtC,mEAAmE;IACnE,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,2BAA2B,EAAE,EAAE,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjG,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IAAE,WAAW,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,qBAAqB,CAAA;CAAE,CAAC"}
@@ -0,0 +1,7 @@
1
+ const colorCategories = {
2
+ main: "main",
3
+ support: "support"
4
+ };
5
+ export {
6
+ colorCategories
7
+ };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"entryfile.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/utils/entryfile.ts"],"names":[],"mappings":"AAkEA,KAAK,SAAS,GAAG,CAAC,OAAO,EAAE;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,SAS3B,CAAC"}
@@ -1,14 +1,47 @@
1
+ import chalk from "chalk";
1
2
  import glob from "fast-glob";
2
3
  import fs from "fs-extra";
3
4
  import * as R from "ramda";
4
- const sortLightmodeFirst = R.sortWith([R.descend(R.includes("light")), R.descend(R.includes("secondary"))]);
5
+ const sortOrder = [
6
+ "color-mode/light",
7
+ "typography/secondary",
8
+ "semantic",
9
+ "color-mode/dark",
10
+ "color-mode/contrast",
11
+ "typography/primary",
12
+ "color/",
13
+ "builtin-colors"
14
+ ];
15
+ const sortByDefinedOrder = R.sortBy((fileName) => {
16
+ const sortIndex = sortOrder.findIndex((sortElement) => {
17
+ if (sortElement.endsWith("/")) {
18
+ return fileName.includes(sortElement);
19
+ }
20
+ return fileName.includes(`${sortElement}.css`);
21
+ });
22
+ if (sortIndex === -1) {
23
+ console.error(
24
+ chalk.yellow("WARNING: CSS section does not have a defined sort order:", fileName.replace(".css", ""))
25
+ );
26
+ console.log(
27
+ chalk.dim(
28
+ `
29
+ A Digdir developer should define its order in the sortOrder array in entryfile.ts.
30
+ The section will currently be added to the end of the entry file, but the exact
31
+ order may change due to nondeterminism.`.trim()
32
+ )
33
+ );
34
+ console.log();
35
+ return Infinity;
36
+ }
37
+ return sortIndex;
38
+ });
5
39
  const header = `@charset "UTF-8";
6
40
 
7
41
  @layer ds.reset, ds.theme, ds.base, ds.utilities, ds.components;
8
42
 
9
43
  `;
10
- const sortAndConcat = R.pipe(
11
- sortLightmodeFirst,
44
+ const concat = R.pipe(
12
45
  R.map((file) => {
13
46
  try {
14
47
  const content = fs.readFileSync(file, "utf-8").toString();
@@ -23,7 +56,9 @@ const sortAndConcat = R.pipe(
23
56
  const makeEntryFile = async ({ outPath, buildPath, theme }) => {
24
57
  const writePath = `${outPath}/${theme}.css`;
25
58
  const files = await glob(`**/*`, { cwd: buildPath });
26
- const content = header + sortAndConcat(files.map((file) => `${buildPath}/${file}`));
59
+ const sortAlphabetically = R.sort(R.ascend((x) => x));
60
+ const sortedFileNames = R.pipe(sortAlphabetically, sortByDefinedOrder)(files);
61
+ const content = header + concat(sortedFileNames.map((file) => `${buildPath}/${file}`));
27
62
  await fs.writeFile(writePath, content);
28
63
  };
29
64
  export {
@@ -0,0 +1,35 @@
1
+ import type { ThemeObject } from '@tokens-studio/types';
2
+ import type { ThemeDimension, ThemePermutation } from '../types';
3
+ /**
4
+ * Find the theme permutations that are relevant for the given theme dimensions.
5
+ *
6
+ * Technically, for the given dimensions all permutations are included, while for other
7
+ * dimensions the first permutation is used.
8
+ *
9
+ * @param themes Theme objects from $themes.json (Tokens Studio)
10
+ * @param dimensions Which theme dimensions to return permutations for.
11
+ * 'theme' (e.g. altinn/digdir/uutilsynet) is always implicitly included.
12
+ * @returns the relevant theme permutations
13
+ */
14
+ export declare const getMultidimensionalThemes: (themes: ProcessedThemeObject[], dimensions: ThemeDimension[]) => PermutatedTheme[];
15
+ export type PermutatedTheme = {
16
+ name: string;
17
+ selectedTokenSets: string[];
18
+ permutation: ThemePermutation;
19
+ };
20
+ declare const processed: unique symbol;
21
+ /**
22
+ * A Tokens Studio {@link ThemeObject} which has been processed for easier use in code
23
+ */
24
+ export type ProcessedThemeObject = ThemeObject & {
25
+ [processed]: true;
26
+ };
27
+ /**
28
+ * Normalise theme names and theme group names for easier use in code
29
+ * @param theme A theme object from $themes.json
30
+ * @returns Processed theme object
31
+ */
32
+ export declare function processThemeObject(theme: ThemeObject | ProcessedThemeObject): ProcessedThemeObject;
33
+ export type GroupedThemes = Record<keyof ThemePermutation, ProcessedThemeObject[]>;
34
+ export {};
35
+ //# sourceMappingURL=getMultidimensionalThemes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getMultidimensionalThemes.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/utils/getMultidimensionalThemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMxD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,WAAY,oBAAoB,EAAE,cAAc,cAAc,EAAE,sBAerG,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,WAAW,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF,QAAA,MAAM,SAAS,EAAE,OAAO,MAAsD,CAAC;AAC/E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,CAAC,SAAS,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAMvE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,oBAAoB,GAAG,oBAAoB,CAUlG;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,gBAAgB,EAAE,oBAAoB,EAAE,CAAC,CAAC"}