@digdir/designsystemet 1.13.1 → 1.13.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/config.js +50 -658
- package/dist/bin/designsystemet.js +131 -4623
- package/dist/bin/options.js +22 -14
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +9 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +8 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +13 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +53 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +14 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +9 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +32 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +15 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/index.js +11 -0
- package/dist/package.js +5 -0
- package/dist/src/colors/colorMetadata.js +255 -261
- package/dist/src/colors/index.js +5 -522
- package/dist/src/colors/theme.js +104 -343
- package/dist/src/colors/types.js +22 -25
- package/dist/src/colors/utils.js +241 -154
- package/dist/src/config.js +103 -444
- package/dist/src/index.js +10 -3588
- package/dist/src/migrations/beta-to-v1.js +339 -537
- package/dist/src/migrations/codemods/css/plugins.js +31 -42
- package/dist/src/migrations/codemods/css/run.js +20 -151
- package/dist/src/migrations/color-rename-next49.js +44 -220
- package/dist/src/migrations/index.js +7 -577
- package/dist/src/tokens/build.js +39 -1816
- package/dist/src/tokens/create/files.js +43 -602
- package/dist/src/tokens/create/generators/$designsystemet.js +8 -97
- package/dist/src/tokens/create/generators/$metadata.js +17 -20
- package/dist/src/tokens/create/generators/$themes.js +137 -311
- package/dist/src/tokens/create/generators/primitives/color-scheme.js +68 -443
- package/dist/src/tokens/create/generators/primitives/globals.js +141 -147
- package/dist/src/tokens/create/generators/primitives/size.js +146 -156
- package/dist/src/tokens/create/generators/primitives/typography.js +213 -217
- package/dist/src/tokens/create/generators/semantic/color-modes.js +24 -59
- package/dist/src/tokens/create/generators/semantic/color.js +42 -326
- package/dist/src/tokens/create/generators/semantic/style.js +379 -382
- package/dist/src/tokens/create/generators/themes/theme.js +108 -392
- package/dist/src/tokens/create.js +47 -1591
- package/dist/src/tokens/format.js +38 -3324
- package/dist/src/tokens/generate-config.js +155 -298
- package/dist/src/tokens/index.js +3 -3344
- package/dist/src/tokens/process/configs/color.js +50 -1086
- package/dist/src/tokens/process/configs/semantic.js +45 -1084
- package/dist/src/tokens/process/configs/shared.js +18 -109
- package/dist/src/tokens/process/configs/size-mode.js +27 -1083
- package/dist/src/tokens/process/configs/size.js +32 -1084
- package/dist/src/tokens/process/configs/type-scale.js +49 -1084
- package/dist/src/tokens/process/configs/typography.js +63 -1085
- package/dist/src/tokens/process/configs.js +88 -1225
- package/dist/src/tokens/process/formats/css/color.js +58 -1080
- package/dist/src/tokens/process/formats/css/semantic.js +27 -1082
- package/dist/src/tokens/process/formats/css/size-mode.js +43 -1078
- package/dist/src/tokens/process/formats/css/size.js +86 -1080
- package/dist/src/tokens/process/formats/css/type-scale.js +53 -1084
- package/dist/src/tokens/process/formats/css/typography.js +27 -1082
- package/dist/src/tokens/process/formats/css.js +18 -1082
- package/dist/src/tokens/process/output/declarations.js +18 -1202
- package/dist/src/tokens/process/output/tailwind.js +26 -40
- package/dist/src/tokens/process/output/theme.js +73 -206
- package/dist/src/tokens/process/platform.js +165 -1356
- package/dist/src/tokens/process/transformers.js +49 -89
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +100 -1183
- package/dist/src/tokens/process/utils/kebab-case.js +7 -5
- package/dist/src/tokens/types.js +6 -7
- package/dist/src/tokens/utils.js +102 -93
- package/dist/src/types.js +1 -5
- package/dist/src/utils/filesystem.js +112 -124
- package/package.json +18 -21
- package/configs/test-tokens.config.json +0 -82
- package/dist/src/scripts/createJsonSchema.js +0 -409
- package/dist/src/scripts/update-preview-tokens.js +0 -3353
package/dist/src/config.js
CHANGED
|
@@ -1,459 +1,118 @@
|
|
|
1
|
-
|
|
1
|
+
import { baseColorNames, colorNames } from "./colors/colorMetadata.js";
|
|
2
|
+
import { convertToHex } from "./colors/utils.js";
|
|
3
|
+
import { RESERVED_COLORS } from "./colors/theme.js";
|
|
4
|
+
import "./colors/index.js";
|
|
5
|
+
import { cliOptions } from "./tokens/create.js";
|
|
2
6
|
import pc from "picocolors";
|
|
3
|
-
import * as
|
|
7
|
+
import * as R from "ramda";
|
|
4
8
|
import { z } from "zod";
|
|
5
9
|
import { fromError } from "zod-validation-error";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
warning: "#EA9B1B",
|
|
13
|
-
danger: "#C01B1B"
|
|
14
|
-
};
|
|
15
|
-
var colorMetadata = {
|
|
16
|
-
"background-default": {
|
|
17
|
-
number: 1,
|
|
18
|
-
name: "background-default",
|
|
19
|
-
group: "background",
|
|
20
|
-
displayName: "Background Default",
|
|
21
|
-
description: {
|
|
22
|
-
long: "Background Default er den mest n\xF8ytrale bakgrunnsfargen.",
|
|
23
|
-
short: "Standard bakgrunnsfarge."
|
|
24
|
-
},
|
|
25
|
-
luminance: {
|
|
26
|
-
light: 1,
|
|
27
|
-
dark: 9e-3,
|
|
28
|
-
contrast: 1e-3
|
|
29
|
-
}
|
|
30
|
-
},
|
|
31
|
-
"background-tinted": {
|
|
32
|
-
number: 2,
|
|
33
|
-
name: "background-tinted",
|
|
34
|
-
group: "background",
|
|
35
|
-
displayName: "Background Tinted",
|
|
36
|
-
description: {
|
|
37
|
-
long: "Background Tinted er en bakgrunnsfarge som har et hint av farge i seg.",
|
|
38
|
-
short: "Bakgrunn med et hint av farge i seg."
|
|
39
|
-
},
|
|
40
|
-
luminance: {
|
|
41
|
-
light: 0.9,
|
|
42
|
-
dark: 0.014,
|
|
43
|
-
contrast: 65e-4
|
|
44
|
-
}
|
|
45
|
-
},
|
|
46
|
-
"surface-default": {
|
|
47
|
-
number: 3,
|
|
48
|
-
name: "surface-default",
|
|
49
|
-
group: "surface",
|
|
50
|
-
displayName: "Surface Default",
|
|
51
|
-
description: {
|
|
52
|
-
long: "Surface Default brukes p\xE5 flater som ligger opp\xE5 bakgrunnsfargene. Dette er den mest n\xF8ytrale surface fargen.",
|
|
53
|
-
short: "Standardfarge for overflater / komponenter."
|
|
54
|
-
},
|
|
55
|
-
luminance: {
|
|
56
|
-
light: 1,
|
|
57
|
-
dark: 0.021,
|
|
58
|
-
contrast: 0.015
|
|
59
|
-
}
|
|
60
|
-
},
|
|
61
|
-
"surface-tinted": {
|
|
62
|
-
number: 4,
|
|
63
|
-
name: "surface-tinted",
|
|
64
|
-
group: "surface",
|
|
65
|
-
displayName: "Surface Tinted",
|
|
66
|
-
description: {
|
|
67
|
-
long: "Surface Tinted brukes p\xE5 flater som ligger opp\xE5 bakgrunnsfargene. Denne har et hint av farge i seg.",
|
|
68
|
-
short: "Overflater / komponenter med et hint av farge i seg."
|
|
69
|
-
},
|
|
70
|
-
luminance: {
|
|
71
|
-
light: 0.81,
|
|
72
|
-
dark: 0.027,
|
|
73
|
-
contrast: 0.015
|
|
74
|
-
}
|
|
75
|
-
},
|
|
76
|
-
"surface-hover": {
|
|
77
|
-
number: 5,
|
|
78
|
-
name: "surface-hover",
|
|
79
|
-
group: "surface",
|
|
80
|
-
displayName: "Surface Hover",
|
|
81
|
-
description: {
|
|
82
|
-
long: "Surface Hover brukes p\xE5 interaktive flater som ligger opp\xE5 bakgrunnsfargene i en hover state.",
|
|
83
|
-
short: "Hover-farge til overflater / komponenter."
|
|
84
|
-
},
|
|
85
|
-
luminance: {
|
|
86
|
-
light: 0.7,
|
|
87
|
-
dark: 0.036,
|
|
88
|
-
contrast: 0.028
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
"surface-active": {
|
|
92
|
-
number: 6,
|
|
93
|
-
name: "surface-active",
|
|
94
|
-
group: "surface",
|
|
95
|
-
displayName: "Surface Active",
|
|
96
|
-
description: {
|
|
97
|
-
long: "Surface Active brukes p\xE5 interaktive flater som ligger opp\xE5 bakgrunnsfargene i en active state.",
|
|
98
|
-
short: "Active-farge til overflater / komponenter."
|
|
99
|
-
},
|
|
100
|
-
luminance: {
|
|
101
|
-
light: 0.59,
|
|
102
|
-
dark: 0.056,
|
|
103
|
-
contrast: 0.045
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
"border-subtle": {
|
|
107
|
-
number: 7,
|
|
108
|
-
name: "border-subtle",
|
|
109
|
-
group: "border",
|
|
110
|
-
displayName: "Border Subtle",
|
|
111
|
-
description: {
|
|
112
|
-
long: "Border Subtle er den lyseste border-fargen og brukes for \xE5 skille elementer fra hverandre.",
|
|
113
|
-
short: "Border-farge med lav kontrast til dekorativ bruk (skillelinjer)."
|
|
114
|
-
},
|
|
115
|
-
luminance: {
|
|
116
|
-
light: 0.5,
|
|
117
|
-
dark: 0.08,
|
|
118
|
-
contrast: 0.26
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
"border-default": {
|
|
122
|
-
number: 8,
|
|
123
|
-
name: "border-default",
|
|
124
|
-
group: "border",
|
|
125
|
-
displayName: "Border Default",
|
|
126
|
-
description: {
|
|
127
|
-
long: "Border Default er en border-farge som brukes n\xE5r man \xF8nsker god kontrast mot bakgrunnsfargene.",
|
|
128
|
-
short: "Standard border-farge til skjemakomponenter og meningsb\xE6rende elementer."
|
|
129
|
-
},
|
|
130
|
-
luminance: {
|
|
131
|
-
light: 0.19,
|
|
132
|
-
dark: 0.22,
|
|
133
|
-
contrast: 0.4
|
|
134
|
-
}
|
|
135
|
-
},
|
|
136
|
-
"border-strong": {
|
|
137
|
-
number: 9,
|
|
138
|
-
name: "border-strong",
|
|
139
|
-
group: "border",
|
|
140
|
-
displayName: "Border Strong",
|
|
141
|
-
description: {
|
|
142
|
-
long: "Border Strong er den m\xF8rkeste border-fargen og brukes n\xE5r man \xF8nsker en veldig tydelig og sterk border.",
|
|
143
|
-
short: "Border-farge med h\xF8y kontrast for ekstra synlighet."
|
|
144
|
-
},
|
|
145
|
-
luminance: {
|
|
146
|
-
light: 0.11,
|
|
147
|
-
dark: 0.39,
|
|
148
|
-
contrast: 0.6
|
|
149
|
-
}
|
|
150
|
-
},
|
|
151
|
-
"text-subtle": {
|
|
152
|
-
number: 10,
|
|
153
|
-
name: "text-subtle",
|
|
154
|
-
group: "text",
|
|
155
|
-
displayName: "Text Subtle",
|
|
156
|
-
description: {
|
|
157
|
-
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.",
|
|
158
|
-
short: "Tekst- og ikonfarge med lavere kontrast."
|
|
159
|
-
},
|
|
160
|
-
luminance: {
|
|
161
|
-
light: 0.11,
|
|
162
|
-
dark: 0.39,
|
|
163
|
-
contrast: 0.57
|
|
164
|
-
}
|
|
165
|
-
},
|
|
166
|
-
"text-default": {
|
|
167
|
-
number: 11,
|
|
168
|
-
name: "text-default",
|
|
169
|
-
group: "text",
|
|
170
|
-
displayName: "Text Default",
|
|
171
|
-
description: {
|
|
172
|
-
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.",
|
|
173
|
-
short: "Tekst- og ikonfarge med h\xF8y kontrast og god synlighet."
|
|
174
|
-
},
|
|
175
|
-
luminance: {
|
|
176
|
-
light: 0.0245,
|
|
177
|
-
dark: 0.84,
|
|
178
|
-
contrast: 0.86
|
|
179
|
-
}
|
|
180
|
-
},
|
|
181
|
-
"base-default": {
|
|
182
|
-
number: 12,
|
|
183
|
-
name: "base-default",
|
|
184
|
-
group: "base",
|
|
185
|
-
displayName: "Base Default",
|
|
186
|
-
description: {
|
|
187
|
-
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.",
|
|
188
|
-
short: "Standardfarge for solide bakgrunner."
|
|
189
|
-
},
|
|
190
|
-
luminance: {
|
|
191
|
-
light: 1,
|
|
192
|
-
dark: 1,
|
|
193
|
-
contrast: 1
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
"base-hover": {
|
|
197
|
-
number: 13,
|
|
198
|
-
name: "base-hover",
|
|
199
|
-
group: "base",
|
|
200
|
-
displayName: "Base Hover",
|
|
201
|
-
description: {
|
|
202
|
-
long: "Base Hover brukes som hover farge p\xE5 elementer som bruker Base Default fargen.",
|
|
203
|
-
short: "Hover-farge for solide bakgrunner."
|
|
204
|
-
},
|
|
205
|
-
luminance: {
|
|
206
|
-
light: 1,
|
|
207
|
-
dark: 1,
|
|
208
|
-
contrast: 1
|
|
209
|
-
}
|
|
210
|
-
},
|
|
211
|
-
"base-active": {
|
|
212
|
-
number: 14,
|
|
213
|
-
name: "base-active",
|
|
214
|
-
group: "base",
|
|
215
|
-
displayName: "Base Active",
|
|
216
|
-
description: {
|
|
217
|
-
long: "Base Active brukes som active farge p\xE5 elementer som bruker Base Default fargen.",
|
|
218
|
-
short: "Active-farge for solide bakgrunner."
|
|
219
|
-
},
|
|
220
|
-
luminance: {
|
|
221
|
-
light: 1,
|
|
222
|
-
dark: 1,
|
|
223
|
-
contrast: 1
|
|
224
|
-
}
|
|
225
|
-
},
|
|
226
|
-
"base-contrast-subtle": {
|
|
227
|
-
number: 15,
|
|
228
|
-
name: "base-contrast-subtle",
|
|
229
|
-
group: "base",
|
|
230
|
-
displayName: "Contrast Subtle",
|
|
231
|
-
description: {
|
|
232
|
-
long: "Contrast Subtle brukes som en viktig meningsb\xE6rende farge opp\xE5 Base Default fargen.",
|
|
233
|
-
short: "Farge med god kontrast mot Base-default."
|
|
234
|
-
},
|
|
235
|
-
luminance: {
|
|
236
|
-
light: 1,
|
|
237
|
-
dark: 1,
|
|
238
|
-
contrast: 1
|
|
239
|
-
}
|
|
240
|
-
},
|
|
241
|
-
"base-contrast-default": {
|
|
242
|
-
number: 16,
|
|
243
|
-
name: "base-contrast-default",
|
|
244
|
-
group: "base",
|
|
245
|
-
displayName: "Contrast Default",
|
|
246
|
-
description: {
|
|
247
|
-
long: "Contrast Default brukes som en viktig meningsb\xE6rende farge opp\xE5 alle Base fargane.",
|
|
248
|
-
short: "Farge med god kontrast mot Base-default og Base-hover."
|
|
249
|
-
},
|
|
250
|
-
luminance: {
|
|
251
|
-
light: 1,
|
|
252
|
-
dark: 1,
|
|
253
|
-
contrast: 1
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
};
|
|
257
|
-
var colorMetadataByNumber = R.indexBy((metadata) => metadata.number, Object.values(colorMetadata));
|
|
258
|
-
var colorNames = Object.keys(colorMetadata);
|
|
259
|
-
var baseColorNames = Object.keys(baseColors);
|
|
260
|
-
|
|
261
|
-
// src/colors/theme.ts
|
|
262
|
-
import chroma2 from "chroma-js";
|
|
263
|
-
import * as R2 from "ramda";
|
|
264
|
-
|
|
265
|
-
// src/colors/utils.ts
|
|
266
|
-
import chroma from "chroma-js";
|
|
267
|
-
import Colorjs from "colorjs.io";
|
|
268
|
-
import { Hsluv } from "hsluv";
|
|
269
|
-
var convertToHex = (color) => {
|
|
270
|
-
if (!color) {
|
|
271
|
-
return "#000000";
|
|
272
|
-
}
|
|
273
|
-
if (/^#[0-9A-Fa-f]{6}$/.test(color)) {
|
|
274
|
-
return color;
|
|
275
|
-
}
|
|
276
|
-
return chroma(color).hex();
|
|
277
|
-
};
|
|
278
|
-
|
|
279
|
-
// src/colors/theme.ts
|
|
280
|
-
var RESERVED_COLORS = ["neutral", "success", "warning", "danger", "info"];
|
|
281
|
-
|
|
282
|
-
// src/colors/types.ts
|
|
283
|
-
import * as R3 from "ramda";
|
|
284
|
-
var semanticColorMap = {
|
|
285
|
-
"background-default": 1,
|
|
286
|
-
"background-tinted": 2,
|
|
287
|
-
"surface-default": 3,
|
|
288
|
-
"surface-tinted": 4,
|
|
289
|
-
"surface-hover": 5,
|
|
290
|
-
"surface-active": 6,
|
|
291
|
-
"border-subtle": 7,
|
|
292
|
-
"border-default": 8,
|
|
293
|
-
"border-strong": 9,
|
|
294
|
-
"text-subtle": 10,
|
|
295
|
-
"text-default": 11,
|
|
296
|
-
"base-default": 12,
|
|
297
|
-
"base-hover": 13,
|
|
298
|
-
"base-active": 14,
|
|
299
|
-
"base-contrast-subtle": 15,
|
|
300
|
-
"base-contrast-default": 16
|
|
301
|
-
};
|
|
302
|
-
var semanticColorNames = R3.keys(semanticColorMap);
|
|
303
|
-
var semanticColorNumbers = R3.values(semanticColorMap);
|
|
304
|
-
|
|
305
|
-
// src/tokens/create/generators/primitives/color-scheme.ts
|
|
306
|
-
import * as R4 from "ramda";
|
|
307
|
-
|
|
308
|
-
// src/tokens/create/generators/semantic/color.ts
|
|
309
|
-
import * as R5 from "ramda";
|
|
310
|
-
|
|
311
|
-
// src/tokens/create/generators/themes/theme.ts
|
|
312
|
-
import * as R6 from "ramda";
|
|
313
|
-
|
|
314
|
-
// src/tokens/create.ts
|
|
315
|
-
var cliOptions = {
|
|
316
|
-
outDir: "out-dir",
|
|
317
|
-
clean: "clean",
|
|
318
|
-
tailwind: "tailwind",
|
|
319
|
-
theme: {
|
|
320
|
-
colors: {
|
|
321
|
-
main: "main-colors",
|
|
322
|
-
support: "support-colors",
|
|
323
|
-
neutral: "neutral-color"
|
|
324
|
-
},
|
|
325
|
-
typography: {
|
|
326
|
-
fontFamily: "font-family"
|
|
327
|
-
},
|
|
328
|
-
borderRadius: "border-radius"
|
|
329
|
-
}
|
|
330
|
-
};
|
|
331
|
-
|
|
332
|
-
// src/config.ts
|
|
333
|
-
function mapPathToOptionName(path2) {
|
|
334
|
-
const normalisedPath = path2[0] === "themes" ? ["theme", ...R7.drop(2, path2)] : path2;
|
|
335
|
-
const option = R7.path(normalisedPath, cliOptions);
|
|
336
|
-
if (typeof option !== "string") {
|
|
337
|
-
return;
|
|
338
|
-
}
|
|
339
|
-
return option;
|
|
10
|
+
//#region src/config.ts
|
|
11
|
+
function mapPathToOptionName(path) {
|
|
12
|
+
const normalisedPath = path[0] === "themes" ? ["theme", ...R.drop(2, path)] : path;
|
|
13
|
+
const option = R.path(normalisedPath, cliOptions);
|
|
14
|
+
if (typeof option !== "string") return;
|
|
15
|
+
return option;
|
|
340
16
|
}
|
|
341
17
|
function makeFriendlyError(err) {
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
return ` - Error in JSON value ${pc.red(issuePath)}${optionMessage}:
|
|
18
|
+
try {
|
|
19
|
+
return fromError(err, { messageBuilder: (issues) => issues.map((issue) => {
|
|
20
|
+
const issuePath = issue.path.join(".");
|
|
21
|
+
const optionName = mapPathToOptionName(issue.path);
|
|
22
|
+
const errorCode = `(error code: ${issue.code})`;
|
|
23
|
+
const optionMessage = optionName ? ` or CLI option --${optionName}` : "";
|
|
24
|
+
return ` - Error in JSON value ${pc.red(issuePath)}${optionMessage}:
|
|
350
25
|
${issue.message} ${pc.dim(errorCode)}`;
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
}
|
|
26
|
+
}).join("\n") });
|
|
27
|
+
} catch (_err2) {
|
|
28
|
+
console.error(pc.red(err instanceof Error ? err.message : "Unknown error occurred while parsing config file"));
|
|
29
|
+
console.error(err instanceof Error ? err.stack : "No stack trace available");
|
|
30
|
+
}
|
|
357
31
|
}
|
|
32
|
+
/**
|
|
33
|
+
* Validates a configuration object against a provided Zod schema.
|
|
34
|
+
*
|
|
35
|
+
* @template T - The expected type of the validated configuration.
|
|
36
|
+
* @param schema - A Zod schema used to validate the configuration object.
|
|
37
|
+
* @param unvalidatedConfig - The configuration object to validate.
|
|
38
|
+
* @returns The validated configuration object, typed as T.
|
|
39
|
+
* @throws Exits the process with code 1 if validation fails, after logging a friendly error message.
|
|
40
|
+
*/
|
|
358
41
|
function validateConfig(schema, unvalidatedConfig, configFilePath) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
42
|
+
try {
|
|
43
|
+
return schema.parse(unvalidatedConfig);
|
|
44
|
+
} catch (err) {
|
|
45
|
+
console.error(pc.redBright(`Invalid config file at ${pc.red(configFilePath)}`));
|
|
46
|
+
const validationError = makeFriendlyError(err);
|
|
47
|
+
console.error(validationError?.toString());
|
|
48
|
+
process.exit(1);
|
|
49
|
+
}
|
|
367
50
|
}
|
|
368
51
|
function parseConfig(configFile, configFilePath) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
process.exit(1);
|
|
379
|
-
}
|
|
52
|
+
if (!configFile) return {};
|
|
53
|
+
try {
|
|
54
|
+
return JSON.parse(configFile);
|
|
55
|
+
} catch (err) {
|
|
56
|
+
console.error(pc.redBright(`Failed parsing config file at ${pc.red(configFilePath)}`));
|
|
57
|
+
const validationError = makeFriendlyError(err);
|
|
58
|
+
console.error(validationError?.toString());
|
|
59
|
+
process.exit(1);
|
|
60
|
+
}
|
|
380
61
|
}
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
`#[0-9a-fA-F]{8}`
|
|
62
|
+
const hexPatterns = [
|
|
63
|
+
`#[0-9a-fA-F]{3}`,
|
|
64
|
+
`#[0-9a-fA-F]{4}`,
|
|
65
|
+
`#[0-9a-fA-F]{6}`,
|
|
66
|
+
`#[0-9a-fA-F]{8}`
|
|
387
67
|
];
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
}).describe(
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
light: colorSchema.optional().describe("A hex color that overrides light mode"),
|
|
413
|
-
dark: colorSchema.optional().describe("A hex color that overrides dark mode")
|
|
414
|
-
}).describe('Overrides for the "link-visited" color');
|
|
415
|
-
var focusOverrideSchema = z.object({
|
|
416
|
-
inner: z.object({
|
|
417
|
-
light: colorSchema.optional().describe("A hex color that overrides light mode"),
|
|
418
|
-
dark: colorSchema.optional().describe("A hex color that overrides dark mode")
|
|
419
|
-
}).optional().describe('Overrides for the "focus-inner" color'),
|
|
420
|
-
outer: z.object({
|
|
421
|
-
light: colorSchema.optional().describe("A hex color that overrides light mode"),
|
|
422
|
-
dark: colorSchema.optional().describe("A hex color that overrides dark mode")
|
|
423
|
-
}).optional().describe('Overrides for the "focus-outer" color')
|
|
68
|
+
const reservedColorsPattern = `^(?!(?:${RESERVED_COLORS.join("|")})$)`;
|
|
69
|
+
const colorRegex = new RegExp(`^${hexPatterns.join("|")}$`);
|
|
70
|
+
const colorSchema = z.string().regex(colorRegex).transform(convertToHex).describe(`A hex color, which is used for creating a color scale. Invalid color names: ${RESERVED_COLORS.join(", ")}`);
|
|
71
|
+
const colorCategorySchema = z.record(z.string().regex(new RegExp(reservedColorsPattern, "i"), { error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}` }), colorSchema, { error: "Color definitions must be hex color values" }).refine((colors) => !Object.keys(colors).some((key) => RESERVED_COLORS.includes(key.toLowerCase())), { error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}` }).describe("An object with one or more color definitions. The property name is used as the color name.");
|
|
72
|
+
const colorModeOverrideSchema = z.object({
|
|
73
|
+
light: colorSchema.optional().describe("A hex color that overrides light mode"),
|
|
74
|
+
dark: colorSchema.optional().describe("A hex color that overrides dark mode")
|
|
75
|
+
}).describe("Override values for semantic color tokens like \"background-subtle\", \"border-default\", etc.");
|
|
76
|
+
const colorWeightOverrideSchema = z.partialRecord(z.enum([...colorNames]), colorModeOverrideSchema).describe("The name of the color to add overrides for, e.g. \"accent\"");
|
|
77
|
+
const semanticColorOverrideSchema = z.record(z.string(), colorWeightOverrideSchema).describe("An object with color names as keys");
|
|
78
|
+
const severityColorOverrideSchema = z.partialRecord(z.enum(baseColorNames), colorSchema.describe("A hex color, which is used for creating a color scale")).optional().describe("An object with severity color names as keys");
|
|
79
|
+
const linkVisitedOverrideSchema = z.object({
|
|
80
|
+
light: colorSchema.optional().describe("A hex color that overrides light mode"),
|
|
81
|
+
dark: colorSchema.optional().describe("A hex color that overrides dark mode")
|
|
82
|
+
}).describe("Overrides for the \"link-visited\" color");
|
|
83
|
+
const focusOverrideSchema = z.object({
|
|
84
|
+
inner: z.object({
|
|
85
|
+
light: colorSchema.optional().describe("A hex color that overrides light mode"),
|
|
86
|
+
dark: colorSchema.optional().describe("A hex color that overrides dark mode")
|
|
87
|
+
}).optional().describe("Overrides for the \"focus-inner\" color"),
|
|
88
|
+
outer: z.object({
|
|
89
|
+
light: colorSchema.optional().describe("A hex color that overrides light mode"),
|
|
90
|
+
dark: colorSchema.optional().describe("A hex color that overrides dark mode")
|
|
91
|
+
}).optional().describe("Overrides for the \"focus-outer\" color")
|
|
424
92
|
}).describe("Overrides for the focus colors");
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
93
|
+
const overridesSchema = z.object({
|
|
94
|
+
colors: semanticColorOverrideSchema.optional(),
|
|
95
|
+
severity: severityColorOverrideSchema.optional(),
|
|
96
|
+
linkVisited: linkVisitedOverrideSchema.optional(),
|
|
97
|
+
focus: focusOverrideSchema.optional()
|
|
430
98
|
}).describe("Overrides for generated design tokens. Currently only supports colors defined in your theme").optional();
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional(),
|
|
441
|
-
overrides: overridesSchema
|
|
99
|
+
const themeSchema = z.object({
|
|
100
|
+
colors: z.object({
|
|
101
|
+
main: colorCategorySchema,
|
|
102
|
+
support: colorCategorySchema.optional().default({}),
|
|
103
|
+
neutral: colorSchema.describe("A hex color, which is used for creating a color scale.")
|
|
104
|
+
}).meta({ description: "Defines the colors for this theme" }),
|
|
105
|
+
typography: z.object({ fontFamily: z.string().meta({ description: "Sets the font-family for this theme" }) }).describe("Defines the typography for a given theme").optional(),
|
|
106
|
+
borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional(),
|
|
107
|
+
overrides: overridesSchema
|
|
442
108
|
}).meta({ description: "An object defining a theme. The property name holding the object becomes the theme name." });
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
export {
|
|
454
|
-
colorRegex,
|
|
455
|
-
commonConfig,
|
|
456
|
-
configFileCreateSchema,
|
|
457
|
-
parseConfig,
|
|
458
|
-
validateConfig
|
|
459
|
-
};
|
|
109
|
+
const commonConfig = z.object({ clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional() });
|
|
110
|
+
/**
|
|
111
|
+
* This defines the structure of the final configuration file
|
|
112
|
+
*/
|
|
113
|
+
const configFileCreateSchema = z.object({
|
|
114
|
+
outDir: z.string().meta({ description: "Path to the output directory for the created design tokens" }),
|
|
115
|
+
themes: z.record(z.string(), themeSchema).meta({ description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name." })
|
|
116
|
+
}).required().extend(commonConfig.shape);
|
|
117
|
+
//#endregion
|
|
118
|
+
export { colorRegex, commonConfig, configFileCreateSchema, parseConfig, validateConfig };
|