@digdir/designsystemet 0.1.0-alpha.18 → 0.1.0-alpha.19

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 (91) hide show
  1. package/LICENSE +7 -0
  2. package/dist/bin/designsystemet.js +24 -28
  3. package/dist/src/colors/colorUtils.js +223 -315
  4. package/dist/src/colors/index.js +3 -3
  5. package/dist/src/colors/themeUtils.js +227 -319
  6. package/dist/src/colors/types.js +0 -1
  7. package/dist/src/init/createTokensPackage.js +223 -203
  8. package/dist/src/init/generateMetadataJson.js +19 -14
  9. package/dist/src/init/generateThemesJson.js +49 -40
  10. package/dist/src/init/index.js +7 -4
  11. package/dist/src/init/nextStepsMarkdown.js +15 -13
  12. package/dist/src/init/template/prettier.config.js +5 -7
  13. package/dist/src/init/template/template-files/package.json +1 -0
  14. package/dist/src/init/utils.js +11 -7
  15. package/dist/src/migrations/beta-to-v1.js +342 -339
  16. package/dist/src/migrations/codemods/css/plugins.js +40 -36
  17. package/dist/src/migrations/codemods/css/run.js +15 -20
  18. package/dist/src/migrations/codemods/jsx/classname-prefix.js +57 -63
  19. package/dist/src/migrations/codemods/jsx/run.js +17 -19
  20. package/dist/src/migrations/index.js +6 -3
  21. package/dist/src/migrations/react-beta-to-v1.js +4 -3
  22. package/dist/src/tokens/actions.js +25 -23
  23. package/dist/src/tokens/build.js +65 -51
  24. package/dist/src/tokens/configs.js +188 -223
  25. package/dist/src/tokens/formats/css.js +143 -150
  26. package/dist/src/tokens/formats/js-tokens.js +27 -26
  27. package/dist/src/tokens/transformers.js +39 -41
  28. package/dist/src/tokens/utils/noCase.js +25 -25
  29. package/dist/src/tokens/utils/permutateThemes.js +50 -64
  30. package/dist/src/tokens/utils/utils.js +12 -25
  31. package/package.json +8 -3
  32. package/dist/src/test/a.css +0 -39
  33. package/dist/src/test/jsx-test.js +0 -12
  34. package/dist/types/bin/designsystemet.d.ts +0 -3
  35. package/dist/types/bin/designsystemet.d.ts.map +0 -1
  36. package/dist/types/src/colors/colorUtils.d.ts +0 -126
  37. package/dist/types/src/colors/colorUtils.d.ts.map +0 -1
  38. package/dist/types/src/colors/index.d.ts +0 -4
  39. package/dist/types/src/colors/index.d.ts.map +0 -1
  40. package/dist/types/src/colors/themeUtils.d.ts +0 -102
  41. package/dist/types/src/colors/themeUtils.d.ts.map +0 -1
  42. package/dist/types/src/colors/types.d.ts +0 -16
  43. package/dist/types/src/colors/types.d.ts.map +0 -1
  44. package/dist/types/src/init/createTokensPackage.d.ts +0 -5
  45. package/dist/types/src/init/createTokensPackage.d.ts.map +0 -1
  46. package/dist/types/src/init/generateMetadataJson.d.ts +0 -6
  47. package/dist/types/src/init/generateMetadataJson.d.ts.map +0 -1
  48. package/dist/types/src/init/generateThemesJson.d.ts +0 -3
  49. package/dist/types/src/init/generateThemesJson.d.ts.map +0 -1
  50. package/dist/types/src/init/index.d.ts +0 -3
  51. package/dist/types/src/init/index.d.ts.map +0 -1
  52. package/dist/types/src/init/nextStepsMarkdown.d.ts +0 -3
  53. package/dist/types/src/init/nextStepsMarkdown.d.ts.map +0 -1
  54. package/dist/types/src/init/template/prettier.config.d.mts +0 -9
  55. package/dist/types/src/init/template/prettier.config.d.mts.map +0 -1
  56. package/dist/types/src/init/utils.d.ts +0 -4
  57. package/dist/types/src/init/utils.d.ts.map +0 -1
  58. package/dist/types/src/migrations/beta-to-v1.d.ts +0 -3
  59. package/dist/types/src/migrations/beta-to-v1.d.ts.map +0 -1
  60. package/dist/types/src/migrations/codemods/css/plugins.d.ts +0 -6
  61. package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +0 -1
  62. package/dist/types/src/migrations/codemods/css/run.d.ts +0 -8
  63. package/dist/types/src/migrations/codemods/css/run.d.ts.map +0 -1
  64. package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
  65. package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
  66. package/dist/types/src/migrations/codemods/jsx/run.d.ts +0 -7
  67. package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +0 -1
  68. package/dist/types/src/migrations/index.d.ts +0 -6
  69. package/dist/types/src/migrations/index.d.ts.map +0 -1
  70. package/dist/types/src/migrations/react-beta-to-v1.d.ts +0 -3
  71. package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +0 -1
  72. package/dist/types/src/test/jsx-test.d.ts +0 -4
  73. package/dist/types/src/test/jsx-test.d.ts.map +0 -1
  74. package/dist/types/src/tokens/actions.d.ts +0 -6
  75. package/dist/types/src/tokens/actions.d.ts.map +0 -1
  76. package/dist/types/src/tokens/build.d.ts +0 -11
  77. package/dist/types/src/tokens/build.d.ts.map +0 -1
  78. package/dist/types/src/tokens/configs.d.ts +0 -31
  79. package/dist/types/src/tokens/configs.d.ts.map +0 -1
  80. package/dist/types/src/tokens/formats/css.d.ts +0 -5
  81. package/dist/types/src/tokens/formats/css.d.ts.map +0 -1
  82. package/dist/types/src/tokens/formats/js-tokens.d.ts +0 -6
  83. package/dist/types/src/tokens/formats/js-tokens.d.ts.map +0 -1
  84. package/dist/types/src/tokens/transformers.d.ts +0 -5
  85. package/dist/types/src/tokens/transformers.d.ts.map +0 -1
  86. package/dist/types/src/tokens/utils/noCase.d.ts +0 -11
  87. package/dist/types/src/tokens/utils/noCase.d.ts.map +0 -1
  88. package/dist/types/src/tokens/utils/permutateThemes.d.ts +0 -17
  89. package/dist/types/src/tokens/utils/permutateThemes.d.ts.map +0 -1
  90. package/dist/types/src/tokens/utils/utils.d.ts +0 -24
  91. package/dist/types/src/tokens/utils/utils.d.ts.map +0 -1
@@ -9,12 +9,10 @@ import * as formats from "./formats/css.js";
9
9
  import { makeEntryFile } from "./actions.js";
10
10
  import { typeEquals } from "./utils/utils.js";
11
11
  void tokenStudio.registerTransforms(StyleDictionary);
12
- export const prefix = 'ds';
13
- export const basePxFontSize = 16;
14
- export const separator = '_';
15
- const fileHeader = ()=>[
16
- `These files are generated from design tokens defind using Token Studio`
17
- ];
12
+ const prefix = "ds";
13
+ const basePxFontSize = 16;
14
+ const separator = "_";
15
+ const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
18
16
  StyleDictionary.registerTransform(sizeRem);
19
17
  StyleDictionary.registerTransform(nameKebab);
20
18
  StyleDictionary.registerTransform(typographyShorthand);
@@ -24,235 +22,202 @@ StyleDictionary.registerFormat(formats.semantic);
24
22
  StyleDictionary.registerFormat(formats.typography);
25
23
  StyleDictionary.registerAction(makeEntryFile);
26
24
  const dsTransformers = [
27
- nameKebab.name,
28
- `ts/resolveMath`,
29
- 'ts/size/px',
30
- sizeRem.name,
31
- 'ts/typography/fontWeight',
32
- typographyShorthand.name,
33
- 'ts/color/modifiers',
34
- 'ts/color/css/hexrgba',
35
- 'ts/size/lineheight',
36
- 'ts/shadow/css/shorthand'
25
+ nameKebab.name,
26
+ `ts/resolveMath`,
27
+ "ts/size/px",
28
+ sizeRem.name,
29
+ "ts/typography/fontWeight",
30
+ typographyShorthand.name,
31
+ "ts/color/modifiers",
32
+ "ts/color/css/hexrgba",
33
+ "ts/size/lineheight",
34
+ "ts/shadow/css/shorthand"
37
35
  ];
38
36
  const paritionPrimitives = R.partition(R.test(/(?!.*global\.json).*primitives.*/));
39
- const hasUnknownProps = R.pipe(R.values, R.none(R.equals('unknown')), R.not);
40
- const outputColorReferences = (token)=>{
41
- if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) && R.includes('semantic/color', token.filePath)) {
42
- return true;
43
- }
44
- return false;
37
+ const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
38
+ const outputColorReferences = (token) => {
39
+ if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) && R.includes("semantic/color", token.filePath)) {
40
+ return true;
41
+ }
42
+ return false;
45
43
  };
46
- export const permutateThemes = ($themes)=>permutateThemes_($themes, {
47
- separator
48
- });
49
- export const colorModeVariables = ({ mode = 'light', outPath, theme })=>{
50
- const selector = `${mode === 'light' ? ':root, ' : ''}[data-ds-color-mode="${mode}"]`;
51
- const layer = `ds.theme.color-mode.${mode}`;
52
- return {
53
- log: {
54
- verbosity: 'silent'
55
- },
56
- preprocessors: [
57
- 'tokens-studio'
44
+ const permutateThemes = ($themes) => permutateThemes_($themes, {
45
+ separator
46
+ });
47
+ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
48
+ const selector = `${mode === "light" ? ":root, " : ""}[data-ds-color-mode="${mode}"]`;
49
+ const layer = `ds.theme.color-mode.${mode}`;
50
+ return {
51
+ log: { verbosity: "silent" },
52
+ preprocessors: ["tokens-studio"],
53
+ platforms: {
54
+ css: {
55
+ // custom
56
+ outPath,
57
+ mode,
58
+ theme,
59
+ selector,
60
+ layer,
61
+ //
62
+ prefix,
63
+ buildPath: `${outPath}/${theme}/`,
64
+ transforms: dsTransformers,
65
+ actions: [makeEntryFile.name],
66
+ files: [
67
+ {
68
+ destination: `color-mode/${mode}.css`,
69
+ format: formats.colormode.name,
70
+ filter: (token) => !token.isSource && typeEquals("color", token)
71
+ }
58
72
  ],
59
- platforms: {
60
- css: {
61
- // custom
62
- outPath,
63
- mode,
64
- theme,
65
- selector,
66
- layer,
67
- //
68
- prefix,
69
- buildPath: `${outPath}/${theme}/`,
70
- transforms: dsTransformers,
71
- actions: [
72
- makeEntryFile.name
73
- ],
74
- files: [
75
- {
76
- destination: `color-mode/${mode}.css`,
77
- format: formats.colormode.name,
78
- filter: (token)=>!token.isSource && typeEquals('color', token)
79
- }
80
- ],
81
- options: {
82
- fileHeader,
83
- outputReferences: (token, options)=>outputColorReferences(token) && outputReferencesFilter(token, options)
84
- }
85
- }
73
+ options: {
74
+ fileHeader,
75
+ outputReferences: (token, options) => outputColorReferences(token) && outputReferencesFilter(token, options)
86
76
  }
87
- };
77
+ }
78
+ }
79
+ };
88
80
  };
89
- export const semanticVariables = ({ outPath, theme })=>{
90
- const selector = `:root`;
91
- const layer = `ds.theme.semantic`;
92
- /**
93
- * This is a workaround for our formatters to support transative transformers while retaining outputReference.
94
- *
95
- * This function will wrap formatted token in `calc()`
96
- *
97
- * @example --ds-spacing-1: var(--ds-spacing-base)*1; -> --ds-spacing-0: calc(var(--ds-spacing-base)*1);
98
- */ const isCalculatedToken = (token)=>typeEquals([
99
- 'spacing',
100
- 'sizing',
101
- 'borderRadius'
102
- ], token);
103
- return {
104
- log: {
105
- verbosity: 'silent'
106
- },
107
- preprocessors: [
108
- 'tokens-studio'
81
+ const semanticVariables = ({ outPath, theme }) => {
82
+ const selector = `:root`;
83
+ const layer = `ds.theme.semantic`;
84
+ const isCalculatedToken = (token) => typeEquals(["spacing", "sizing", "borderRadius"], token);
85
+ return {
86
+ log: { verbosity: "silent" },
87
+ preprocessors: ["tokens-studio"],
88
+ platforms: {
89
+ css: {
90
+ // custom
91
+ outPath,
92
+ theme,
93
+ basePxFontSize,
94
+ isCalculatedToken,
95
+ selector,
96
+ layer,
97
+ //
98
+ prefix,
99
+ buildPath: `${outPath}/${theme}/`,
100
+ transforms: dsTransformers,
101
+ actions: [makeEntryFile.name],
102
+ files: [
103
+ {
104
+ destination: `semantic.css`,
105
+ format: formats.semantic.name,
106
+ filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeights", "fontFamilies"], token)
107
+ }
109
108
  ],
110
- platforms: {
111
- css: {
112
- // custom
113
- outPath,
114
- theme,
115
- basePxFontSize,
116
- isCalculatedToken,
117
- selector,
118
- layer,
119
- //
120
- prefix,
121
- buildPath: `${outPath}/${theme}/`,
122
- transforms: dsTransformers,
123
- actions: [
124
- makeEntryFile.name
125
- ],
126
- files: [
127
- {
128
- destination: `semantic.css`,
129
- format: formats.semantic.name,
130
- filter: (token)=>(!token.isSource || isCalculatedToken(token)) && !typeEquals([
131
- 'color',
132
- 'fontWeights',
133
- 'fontFamilies'
134
- ], token)
135
- }
136
- ],
137
- options: {
138
- fileHeader,
139
- outputReferences: (token, options)=>isCalculatedToken(token) && outputReferencesFilter(token, options)
140
- }
141
- }
109
+ options: {
110
+ fileHeader,
111
+ outputReferences: (token, options) => isCalculatedToken(token) && outputReferencesFilter(token, options)
142
112
  }
143
- };
113
+ }
114
+ }
115
+ };
144
116
  };
145
- export const typescriptTokens = ({ mode = 'unknown', outPath, theme })=>{
146
- return {
147
- log: {
148
- verbosity: 'silent'
149
- },
150
- preprocessors: [
151
- 'tokens-studio'
152
- ],
153
- platforms: {
154
- ts: {
155
- prefix,
156
- basePxFontSize,
157
- transforms: dsTransformers,
158
- buildPath: `${outPath}/${theme}/`,
159
- files: [
160
- {
161
- destination: `${mode}.ts`,
162
- format: jsTokens.name,
163
- outputReferences: outputColorReferences,
164
- filter: (token)=>{
165
- if (R.test(/primitives\/modes|\/themes/, token.filePath)) {
166
- return false;
167
- }
168
- if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) || R.includes('semantic', token.filePath)) {
169
- return true;
170
- }
171
- return false;
172
- }
173
- }
174
- ],
175
- options: {
176
- fileHeader
177
- }
117
+ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
118
+ return {
119
+ log: { verbosity: "silent" },
120
+ preprocessors: ["tokens-studio"],
121
+ platforms: {
122
+ ts: {
123
+ prefix,
124
+ basePxFontSize,
125
+ transforms: dsTransformers,
126
+ buildPath: `${outPath}/${theme}/`,
127
+ files: [
128
+ {
129
+ destination: `${mode}.ts`,
130
+ format: jsTokens.name,
131
+ outputReferences: outputColorReferences,
132
+ filter: (token) => {
133
+ if (R.test(/primitives\/modes|\/themes/, token.filePath)) {
134
+ return false;
135
+ }
136
+ if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) || R.includes("semantic", token.filePath)) {
137
+ return true;
138
+ }
139
+ return false;
178
140
  }
141
+ }
142
+ ],
143
+ options: {
144
+ fileHeader
179
145
  }
180
- };
146
+ }
147
+ }
148
+ };
181
149
  };
182
- export const typographyCSS = ({ outPath, theme, typography })=>{
183
- const selector = `${typography === 'primary' ? ':root, ' : ''}[data-ds-typography="${typography}"]`;
184
- const layer = `ds.theme.typography.${typography}`;
185
- return {
186
- log: {
187
- verbosity: 'silent'
188
- },
189
- preprocessors: [
190
- 'tokens-studio'
191
- ],
192
- platforms: {
193
- css: {
194
- prefix,
195
- typography,
196
- selector,
197
- layer,
198
- buildPath: `${outPath}/${theme}/`,
199
- basePxFontSize,
200
- transforms: [
201
- nameKebab.name,
202
- 'ts/size/px',
203
- sizeRem.name,
204
- 'ts/size/lineheight',
205
- 'ts/typography/fontWeight'
206
- ],
207
- files: [
208
- {
209
- destination: `typography/${typography}.css`,
210
- format: formats.typography.name,
211
- filter: (token)=>{
212
- return typeEquals([
213
- 'typography',
214
- 'fontweights',
215
- 'fontfamilies',
216
- 'lineheights',
217
- 'fontsizes',
218
- 'letterSpacing'
219
- ], token) && !(token.path[0] || '').startsWith('theme');
220
- }
221
- }
222
- ],
223
- options: {
224
- fileHeader
225
- }
150
+ const typographyCSS = ({ outPath, theme, typography }) => {
151
+ const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
152
+ const layer = `ds.theme.typography.${typography}`;
153
+ return {
154
+ log: { verbosity: "silent" },
155
+ preprocessors: ["tokens-studio"],
156
+ platforms: {
157
+ css: {
158
+ prefix,
159
+ typography,
160
+ selector,
161
+ layer,
162
+ buildPath: `${outPath}/${theme}/`,
163
+ basePxFontSize,
164
+ transforms: [nameKebab.name, "ts/size/px", sizeRem.name, "ts/size/lineheight", "ts/typography/fontWeight"],
165
+ files: [
166
+ {
167
+ destination: `typography/${typography}.css`,
168
+ format: formats.typography.name,
169
+ filter: (token) => {
170
+ return typeEquals(
171
+ ["typography", "fontweights", "fontfamilies", "lineheights", "fontsizes", "letterSpacing"],
172
+ token
173
+ ) && !(token.path[0] || "").startsWith("theme");
226
174
  }
175
+ }
176
+ ],
177
+ options: {
178
+ fileHeader
227
179
  }
228
- };
180
+ }
181
+ }
182
+ };
183
+ };
184
+ const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes) => permutatedThemes.map((permutatedTheme) => {
185
+ const {
186
+ selectedTokenSets = [],
187
+ mode = "unknown",
188
+ theme = "unknown",
189
+ semantic = "unknown",
190
+ size = "unknown",
191
+ typography = "unknown"
192
+ } = permutatedTheme;
193
+ if (hasUnknownProps(permutatedTheme)) {
194
+ throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
195
+ }
196
+ const setsWithPaths = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
197
+ const [source, include] = paritionPrimitives(setsWithPaths);
198
+ const config_ = getConfig({
199
+ outPath,
200
+ theme,
201
+ mode,
202
+ semantic,
203
+ size,
204
+ typography
205
+ });
206
+ const config = {
207
+ ...config_,
208
+ source,
209
+ include
210
+ };
211
+ return { mode, theme, semantic, size, typography, config };
212
+ }).sort();
213
+ export {
214
+ basePxFontSize,
215
+ colorModeVariables,
216
+ getConfigs,
217
+ permutateThemes,
218
+ prefix,
219
+ semanticVariables,
220
+ separator,
221
+ typescriptTokens,
222
+ typographyCSS
229
223
  };
230
- export const getConfigs = (getConfig, outPath, tokensDir, permutatedThemes)=>permutatedThemes.map((permutatedTheme)=>{
231
- const { selectedTokenSets = [], mode = 'unknown', theme = 'unknown', semantic = 'unknown', size = 'unknown', typography = 'unknown' } = permutatedTheme;
232
- if (hasUnknownProps(permutatedTheme)) {
233
- throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
234
- }
235
- const setsWithPaths = selectedTokenSets.map((x)=>`${tokensDir}/${x}.json`);
236
- const [source, include] = paritionPrimitives(setsWithPaths);
237
- const config_ = getConfig({
238
- outPath,
239
- theme,
240
- mode,
241
- semantic,
242
- size,
243
- typography
244
- });
245
- const config = {
246
- ...config_,
247
- source,
248
- include
249
- };
250
- return {
251
- mode,
252
- theme,
253
- semantic,
254
- size,
255
- typography,
256
- config
257
- };
258
- }).sort();