@digdir/designsystemet 1.1.3 → 1.1.4
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/designsystemet.js +130 -186
- package/dist/src/index.js +88 -145
- package/dist/src/scripts/update-preview-tokens.d.ts +3 -0
- package/dist/src/scripts/update-preview-tokens.d.ts.map +1 -0
- package/dist/src/scripts/update-preview-tokens.js +3446 -0
- package/dist/src/tokens/build.d.ts +1 -1
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +98 -154
- package/dist/src/tokens/create/generators/$designsystemet.js +6 -6
- package/dist/src/tokens/create/write.js +6 -6
- package/dist/src/tokens/format.d.ts +1 -1
- package/dist/src/tokens/format.d.ts.map +1 -1
- package/dist/src/tokens/format.js +88 -145
- package/dist/src/tokens/index.js +88 -145
- package/dist/src/tokens/process/configs/color.js +234 -293
- package/dist/src/tokens/process/configs/semantic.js +509 -113
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/typography.js +504 -110
- package/dist/src/tokens/process/configs.d.ts +0 -1
- package/dist/src/tokens/process/configs.d.ts.map +1 -1
- package/dist/src/tokens/process/configs.js +231 -290
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -1
- package/dist/src/tokens/process/formats/css/color.js +644 -12
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -1
- package/dist/src/tokens/process/formats/css/semantic.js +679 -23
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -1
- package/dist/src/tokens/process/formats/css/typography.js +741 -8
- package/dist/src/tokens/process/formats/css.js +549 -38
- package/dist/src/tokens/process/output/declarations.js +60 -121
- package/dist/src/tokens/process/output/theme.js +6 -6
- package/dist/src/tokens/process/platform.d.ts +9 -4
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/process/platform.js +76 -133
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +62 -123
- package/package.json +6 -6
- package/dist/src/tokens/process/configs/storefront.d.ts +0 -3
- package/dist/src/tokens/process/configs/storefront.d.ts.map +0 -1
- package/dist/src/tokens/process/configs/storefront.js +0 -234
- package/dist/src/tokens/process/formats/js-tokens.d.ts +0 -6
- package/dist/src/tokens/process/formats/js-tokens.d.ts.map +0 -1
- package/dist/src/tokens/process/formats/js-tokens.js +0 -123
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/tokens/process/configs/color.ts
|
|
2
|
-
import * as
|
|
2
|
+
import * as R10 from "ramda";
|
|
3
3
|
|
|
4
4
|
// src/tokens/utils.ts
|
|
5
5
|
import * as R from "ramda";
|
|
@@ -67,213 +67,27 @@ function inlineTokens(shouldInline, tokens) {
|
|
|
67
67
|
}
|
|
68
68
|
|
|
69
69
|
// src/tokens/process/formats/css/color.ts
|
|
70
|
-
import * as
|
|
70
|
+
import * as R7 from "ramda";
|
|
71
71
|
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
72
|
-
var prefersColorScheme = (colorScheme2, content) => `
|
|
73
|
-
@media (prefers-color-scheme: ${colorScheme2}) {
|
|
74
|
-
[data-color-scheme="auto"] ${content}
|
|
75
|
-
}
|
|
76
|
-
`;
|
|
77
|
-
var colorScheme = {
|
|
78
|
-
name: "ds/css-colorscheme",
|
|
79
|
-
format: async ({ dictionary, options, platform }) => {
|
|
80
|
-
const { allTokens } = dictionary;
|
|
81
|
-
const { outputReferences, usesDtcg } = options;
|
|
82
|
-
const { selector, colorScheme: colorScheme2, layer } = platform;
|
|
83
|
-
const colorScheme_ = colorScheme2;
|
|
84
|
-
const format = createPropertyFormatter({
|
|
85
|
-
outputReferences,
|
|
86
|
-
dictionary,
|
|
87
|
-
format: "css",
|
|
88
|
-
usesDtcg
|
|
89
|
-
});
|
|
90
|
-
const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
|
|
91
|
-
color-scheme: ${colorScheme_};
|
|
92
|
-
` : "";
|
|
93
|
-
const filteredAllTokens = allTokens.filter(
|
|
94
|
-
R2.allPass([
|
|
95
|
-
R2.anyPass([
|
|
96
|
-
// Include semantic tokens in the output
|
|
97
|
-
isSemanticToken,
|
|
98
|
-
// Include global color tokens
|
|
99
|
-
isGlobalColorToken
|
|
100
|
-
]),
|
|
101
|
-
// Don't include color category tokens -- they are exported separately
|
|
102
|
-
(t) => !isColorCategoryToken(t)
|
|
103
|
-
])
|
|
104
|
-
);
|
|
105
|
-
const formattedTokens = filteredAllTokens.map(format).join("\n");
|
|
106
|
-
const content = `{
|
|
107
|
-
${formattedTokens}
|
|
108
|
-
${colorSchemeProperty}}
|
|
109
|
-
`;
|
|
110
|
-
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
111
|
-
const body = R2.isNotNil(layer) ? `@layer ${layer} {
|
|
112
|
-
${selector} ${content} ${autoSelectorContent}
|
|
113
|
-
}
|
|
114
|
-
` : `${selector} ${content} ${autoSelectorContent}
|
|
115
|
-
`;
|
|
116
|
-
return body;
|
|
117
|
-
}
|
|
118
|
-
};
|
|
119
|
-
var colorCategory = {
|
|
120
|
-
name: "ds/css-colorcategory",
|
|
121
|
-
format: async ({ dictionary, options, platform }) => {
|
|
122
|
-
const { outputReferences, usesDtcg } = options;
|
|
123
|
-
const { selector, layer } = platform;
|
|
124
|
-
const format = R2.compose(
|
|
125
|
-
createPropertyFormatter({
|
|
126
|
-
outputReferences,
|
|
127
|
-
dictionary,
|
|
128
|
-
format: "css",
|
|
129
|
-
usesDtcg
|
|
130
|
-
}),
|
|
131
|
-
(token) => ({
|
|
132
|
-
...token,
|
|
133
|
-
name: token.name.replace(/color-\w+-/, "color-"),
|
|
134
|
-
original: {
|
|
135
|
-
...token.original,
|
|
136
|
-
$value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
|
|
137
|
-
}
|
|
138
|
-
})
|
|
139
|
-
);
|
|
140
|
-
const formattedTokens = dictionary.allTokens.map(format).join("\n");
|
|
141
|
-
const content = `{
|
|
142
|
-
${formattedTokens}
|
|
143
|
-
}
|
|
144
|
-
`;
|
|
145
|
-
const body = R2.isNotNil(layer) ? `@layer ${layer} {
|
|
146
|
-
${selector} ${content}
|
|
147
|
-
}
|
|
148
|
-
` : `${selector} ${content}
|
|
149
|
-
`;
|
|
150
|
-
return body;
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
// src/tokens/process/formats/css/semantic.ts
|
|
155
|
-
import * as R3 from "ramda";
|
|
156
|
-
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
157
|
-
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
158
|
-
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
159
|
-
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
160
|
-
var isInlineTokens = R3.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
161
|
-
var overrideSizingFormula = (format, token) => {
|
|
162
|
-
const [name, value] = format(token).split(":");
|
|
163
|
-
const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
|
|
164
|
-
const round = `round(down, ${calc}, 1px)`;
|
|
165
|
-
return {
|
|
166
|
-
name,
|
|
167
|
-
round,
|
|
168
|
-
calc
|
|
169
|
-
};
|
|
170
|
-
};
|
|
171
|
-
var formatSizingTokens = (format, tokens) => {
|
|
172
|
-
const { round, calc } = R3.reduce(
|
|
173
|
-
(acc, token) => {
|
|
174
|
-
const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
|
|
175
|
-
return {
|
|
176
|
-
round: [...acc.round, `${name}: ${round2};`],
|
|
177
|
-
calc: [...acc.calc, `${name}: ${calc2};`]
|
|
178
|
-
};
|
|
179
|
-
},
|
|
180
|
-
{ round: [], calc: [] },
|
|
181
|
-
tokens
|
|
182
|
-
);
|
|
183
|
-
return `
|
|
184
|
-
${calc.join("\n")}
|
|
185
|
-
|
|
186
|
-
@supports (width: round(down, .1em, 1px)) {
|
|
187
|
-
${round.join("\n")}
|
|
188
|
-
}`;
|
|
189
|
-
};
|
|
190
|
-
var semantic = {
|
|
191
|
-
name: "ds/css-semantic",
|
|
192
|
-
format: async ({ dictionary, options, platform }) => {
|
|
193
|
-
const { outputReferences, usesDtcg } = options;
|
|
194
|
-
const { selector, layer } = platform;
|
|
195
|
-
const format = createPropertyFormatter2({
|
|
196
|
-
outputReferences,
|
|
197
|
-
dictionary,
|
|
198
|
-
format: "css",
|
|
199
|
-
usesDtcg
|
|
200
|
-
});
|
|
201
|
-
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
202
|
-
const filteredTokens = R3.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
|
|
203
|
-
const [sizingTokens, restTokens] = R3.partition(
|
|
204
|
-
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
205
|
-
filteredTokens
|
|
206
|
-
);
|
|
207
|
-
const formattedTokens = [R3.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
|
|
208
|
-
const content = `{
|
|
209
|
-
${formattedTokens.join("\n")}
|
|
210
|
-
}
|
|
211
|
-
`;
|
|
212
|
-
const body = R3.isNotNil(layer) ? `@layer ${layer} {
|
|
213
|
-
${selector} ${content}
|
|
214
|
-
}
|
|
215
|
-
` : `${selector} ${content}
|
|
216
|
-
`;
|
|
217
|
-
return body;
|
|
218
|
-
}
|
|
219
|
-
};
|
|
220
|
-
|
|
221
|
-
// src/tokens/process/formats/css/typography.ts
|
|
222
|
-
import * as R4 from "ramda";
|
|
223
|
-
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
224
|
-
var typographyFontFamilyPredicate = R4.allPass([
|
|
225
|
-
R4.pathSatisfies(R4.includes("typography"), ["path"]),
|
|
226
|
-
R4.pathSatisfies(R4.includes("fontFamily"), ["path"])
|
|
227
|
-
]);
|
|
228
|
-
var typography = {
|
|
229
|
-
name: "ds/css-typography",
|
|
230
|
-
format: async ({ dictionary, options, platform }) => {
|
|
231
|
-
const { outputReferences, usesDtcg } = options;
|
|
232
|
-
const { selector, layer } = platform;
|
|
233
|
-
const format = createPropertyFormatter3({
|
|
234
|
-
outputReferences,
|
|
235
|
-
dictionary,
|
|
236
|
-
format: "css",
|
|
237
|
-
usesDtcg
|
|
238
|
-
});
|
|
239
|
-
const filteredTokens = R4.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
240
|
-
const formattedTokens = R4.pipe(R4.map(format), R4.join("\n"))(filteredTokens);
|
|
241
|
-
const content = selector ? `${selector} {
|
|
242
|
-
${formattedTokens}
|
|
243
|
-
}` : formattedTokens;
|
|
244
|
-
const body = R4.isNotNil(layer) ? `@layer ${layer} {
|
|
245
|
-
${content}
|
|
246
|
-
}` : content;
|
|
247
|
-
return body;
|
|
248
|
-
}
|
|
249
|
-
};
|
|
250
|
-
|
|
251
|
-
// src/tokens/process/formats/css.ts
|
|
252
|
-
var formats = {
|
|
253
|
-
colorScheme,
|
|
254
|
-
colorCategory,
|
|
255
|
-
semantic,
|
|
256
|
-
typography
|
|
257
|
-
};
|
|
258
72
|
|
|
259
73
|
// src/tokens/process/platform.ts
|
|
260
74
|
import chalk2 from "chalk";
|
|
261
|
-
import * as
|
|
75
|
+
import * as R6 from "ramda";
|
|
262
76
|
import StyleDictionary2 from "style-dictionary";
|
|
263
77
|
|
|
264
78
|
// src/tokens/process/configs.ts
|
|
265
79
|
import { register } from "@tokens-studio/sd-transforms";
|
|
266
|
-
import * as
|
|
80
|
+
import * as R5 from "ramda";
|
|
267
81
|
import StyleDictionary from "style-dictionary";
|
|
268
82
|
|
|
269
83
|
// src/tokens/process/configs/semantic.ts
|
|
270
|
-
import * as
|
|
84
|
+
import * as R3 from "ramda";
|
|
271
85
|
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
272
86
|
|
|
273
87
|
// src/tokens/process/transformers.ts
|
|
274
88
|
import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
|
|
275
|
-
import * as
|
|
276
|
-
var isPx =
|
|
89
|
+
import * as R2 from "ramda";
|
|
90
|
+
var isPx = R2.test(/\b\d+px\b/g);
|
|
277
91
|
var sizeRem = {
|
|
278
92
|
name: "ds/size/toRem",
|
|
279
93
|
type: "value",
|
|
@@ -364,8 +178,8 @@ var semanticVariables = ({ theme }) => {
|
|
|
364
178
|
destination: `semantic.css`,
|
|
365
179
|
format: formats.semantic.name,
|
|
366
180
|
filter: (token) => {
|
|
367
|
-
const isUwantedToken =
|
|
368
|
-
const isPrivateToken =
|
|
181
|
+
const isUwantedToken = R3.anyPass([R3.includes("primitives/global")])(token.filePath);
|
|
182
|
+
const isPrivateToken = R3.includes("_", token.path);
|
|
369
183
|
const unwantedPaths = pathStartsWithOneOf(["font-size", "line-height", "letter-spacing"], token);
|
|
370
184
|
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
371
185
|
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
@@ -385,90 +199,6 @@ var semanticVariables = ({ theme }) => {
|
|
|
385
199
|
};
|
|
386
200
|
};
|
|
387
201
|
|
|
388
|
-
// src/tokens/process/configs/storefront.ts
|
|
389
|
-
import * as R8 from "ramda";
|
|
390
|
-
import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
|
|
391
|
-
|
|
392
|
-
// src/tokens/process/formats/js-tokens.ts
|
|
393
|
-
import * as R7 from "ramda";
|
|
394
|
-
import { createPropertyFormatter as createPropertyFormatter4, fileHeader } from "style-dictionary/utils";
|
|
395
|
-
var groupByType = R7.groupBy((token) => getType(token));
|
|
396
|
-
var removeUnwatedTokens = R7.pipe(
|
|
397
|
-
R7.reject((token) => isColorCategoryToken(token)),
|
|
398
|
-
R7.reject((token) => R7.any((path) => path.startsWith("_"))(token.path))
|
|
399
|
-
);
|
|
400
|
-
var dissocExtensions = R7.pipe(R7.dissoc("$extensions"), R7.dissocPath(["original", "$extensions"]));
|
|
401
|
-
var removeUnwatedProps = R7.map((token) => dissocExtensions(token));
|
|
402
|
-
var toCssVarName = R7.pipe(R7.split(":"), R7.head, R7.trim);
|
|
403
|
-
var jsTokens = {
|
|
404
|
-
name: "ds/js-tokens",
|
|
405
|
-
format: async ({ dictionary, file, options }) => {
|
|
406
|
-
const { usesDtcg, outputReferences } = options;
|
|
407
|
-
const format = createPropertyFormatter4({
|
|
408
|
-
outputReferences,
|
|
409
|
-
dictionary,
|
|
410
|
-
format: "css",
|
|
411
|
-
usesDtcg
|
|
412
|
-
});
|
|
413
|
-
const formatTokens = R7.map((token) => {
|
|
414
|
-
if (pathStartsWithOneOf(["size", "_size"], token)) {
|
|
415
|
-
const { calc, name } = overrideSizingFormula(format, token);
|
|
416
|
-
return {
|
|
417
|
-
...token,
|
|
418
|
-
name: name.trim(),
|
|
419
|
-
$value: calc.trim()
|
|
420
|
-
};
|
|
421
|
-
}
|
|
422
|
-
return {
|
|
423
|
-
...token,
|
|
424
|
-
name: toCssVarName(format(token))
|
|
425
|
-
};
|
|
426
|
-
});
|
|
427
|
-
const processTokens = R7.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
|
|
428
|
-
const tokens = processTokens(inlineTokens(isInlineTokens, dictionary.allTokens));
|
|
429
|
-
const content = Object.entries(tokens).map(
|
|
430
|
-
([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
|
|
431
|
-
`
|
|
432
|
-
).join("\n");
|
|
433
|
-
return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
|
|
434
|
-
}
|
|
435
|
-
};
|
|
436
|
-
|
|
437
|
-
// src/tokens/process/configs/storefront.ts
|
|
438
|
-
var typescriptTokens = ({ "color-scheme": colorScheme2, theme }) => {
|
|
439
|
-
return {
|
|
440
|
-
preprocessors: ["tokens-studio"],
|
|
441
|
-
platforms: {
|
|
442
|
-
ts: {
|
|
443
|
-
prefix,
|
|
444
|
-
basePxFontSize,
|
|
445
|
-
transforms: dsTransformers,
|
|
446
|
-
buildPath: `${theme}/`,
|
|
447
|
-
files: [
|
|
448
|
-
{
|
|
449
|
-
destination: `${colorScheme2}.ts`,
|
|
450
|
-
format: jsTokens.name,
|
|
451
|
-
filter: (token) => {
|
|
452
|
-
if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R8.includes("semantic", token.filePath))
|
|
453
|
-
return false;
|
|
454
|
-
const isSemanticColor = R8.includes("semantic", token.filePath) && typeEquals(["color"], token);
|
|
455
|
-
const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
|
|
456
|
-
return isSemanticColor || wantedTypes;
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
],
|
|
460
|
-
options: {
|
|
461
|
-
outputReferences: (token, options) => {
|
|
462
|
-
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
463
|
-
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
|
|
464
|
-
return (include || isWantedSize) && outputReferencesFilter2(token, options);
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
};
|
|
471
|
-
|
|
472
202
|
// src/tokens/process/configs/typography.ts
|
|
473
203
|
import { expandTypesMap } from "@tokens-studio/sd-transforms";
|
|
474
204
|
var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
@@ -495,6 +225,7 @@ var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
|
495
225
|
sizeRem.name,
|
|
496
226
|
"ts/size/lineheight",
|
|
497
227
|
"ts/typography/fontWeight",
|
|
228
|
+
"ts/size/css/letterspacing",
|
|
498
229
|
typographyName.name
|
|
499
230
|
],
|
|
500
231
|
files: [
|
|
@@ -682,9 +413,9 @@ var TypographyValues;
|
|
|
682
413
|
// src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
683
414
|
import chalk from "chalk";
|
|
684
415
|
import { kebabCase } from "change-case";
|
|
685
|
-
import * as
|
|
416
|
+
import * as R4 from "ramda";
|
|
686
417
|
var processed = Symbol("Type brand for ProcessedThemeObject");
|
|
687
|
-
var hasUnknownProps =
|
|
418
|
+
var hasUnknownProps = R4.pipe(R4.values, R4.none(R4.equals("unknown")), R4.not);
|
|
688
419
|
|
|
689
420
|
// src/tokens/process/configs.ts
|
|
690
421
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
@@ -692,7 +423,6 @@ StyleDictionary.registerTransform(sizeRem);
|
|
|
692
423
|
StyleDictionary.registerTransform(typographyName);
|
|
693
424
|
StyleDictionary.registerTransform(resolveMath);
|
|
694
425
|
StyleDictionary.registerTransform(unitless);
|
|
695
|
-
StyleDictionary.registerFormat(jsTokens);
|
|
696
426
|
for (const format of Object.values(formats)) {
|
|
697
427
|
StyleDictionary.registerFormat(format);
|
|
698
428
|
}
|
|
@@ -706,12 +436,15 @@ var configs = {
|
|
|
706
436
|
warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
|
|
707
437
|
infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
|
|
708
438
|
typographyVariables,
|
|
709
|
-
semanticVariables
|
|
710
|
-
typescriptTokens
|
|
439
|
+
semanticVariables
|
|
711
440
|
};
|
|
712
441
|
|
|
713
442
|
// src/tokens/process/platform.ts
|
|
714
|
-
var buildOptions
|
|
443
|
+
var buildOptions = {
|
|
444
|
+
verbose: false,
|
|
445
|
+
processed$themes: [],
|
|
446
|
+
buildTokenFormats: {}
|
|
447
|
+
};
|
|
715
448
|
var sd = new StyleDictionary2();
|
|
716
449
|
var buildConfigs = {
|
|
717
450
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
@@ -744,13 +477,221 @@ var buildConfigs = {
|
|
|
744
477
|
log: ({ permutation: { theme } }) => `${theme} - info`
|
|
745
478
|
},
|
|
746
479
|
semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] }
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
480
|
+
};
|
|
481
|
+
|
|
482
|
+
// src/tokens/process/formats/css/color.ts
|
|
483
|
+
var prefersColorScheme = (colorScheme2, content) => `
|
|
484
|
+
@media (prefers-color-scheme: ${colorScheme2}) {
|
|
485
|
+
[data-color-scheme="auto"] ${content}
|
|
486
|
+
}
|
|
487
|
+
`;
|
|
488
|
+
var colorScheme = {
|
|
489
|
+
name: "ds/css-colorscheme",
|
|
490
|
+
format: async ({ dictionary, options, platform }) => {
|
|
491
|
+
const { allTokens } = dictionary;
|
|
492
|
+
const { outputReferences, usesDtcg } = options;
|
|
493
|
+
const { selector, colorScheme: colorScheme2, layer } = platform;
|
|
494
|
+
const colorScheme_ = colorScheme2;
|
|
495
|
+
const format = createPropertyFormatter({
|
|
496
|
+
outputReferences,
|
|
497
|
+
dictionary,
|
|
498
|
+
format: "css",
|
|
499
|
+
usesDtcg
|
|
500
|
+
});
|
|
501
|
+
const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
|
|
502
|
+
color-scheme: ${colorScheme_};
|
|
503
|
+
` : "";
|
|
504
|
+
const filteredAllTokens = allTokens.filter(
|
|
505
|
+
R7.allPass([
|
|
506
|
+
R7.anyPass([
|
|
507
|
+
// Include semantic tokens in the output
|
|
508
|
+
isSemanticToken,
|
|
509
|
+
// Include global color tokens
|
|
510
|
+
isGlobalColorToken
|
|
511
|
+
]),
|
|
512
|
+
// Don't include color category tokens -- they are exported separately
|
|
513
|
+
(t) => !isColorCategoryToken(t)
|
|
514
|
+
])
|
|
515
|
+
);
|
|
516
|
+
const formattedMap = filteredAllTokens.map((token) => ({
|
|
517
|
+
token,
|
|
518
|
+
formatted: format(token)
|
|
519
|
+
}));
|
|
520
|
+
const formattedTokens = formattedMap.map(R7.view(R7.lensProp("formatted"))).join("\n");
|
|
521
|
+
const content = `{
|
|
522
|
+
${formattedTokens}
|
|
523
|
+
${colorSchemeProperty}}
|
|
524
|
+
`;
|
|
525
|
+
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
526
|
+
const body = R7.isNotNil(layer) ? `@layer ${layer} {
|
|
527
|
+
${selector} ${content} ${autoSelectorContent}
|
|
528
|
+
}
|
|
529
|
+
` : `${selector} ${content} ${autoSelectorContent}
|
|
530
|
+
`;
|
|
531
|
+
return body;
|
|
532
|
+
}
|
|
533
|
+
};
|
|
534
|
+
var colorCategory = {
|
|
535
|
+
name: "ds/css-colorcategory",
|
|
536
|
+
format: async ({ dictionary, options, platform }) => {
|
|
537
|
+
const { outputReferences, usesDtcg } = options;
|
|
538
|
+
const { selector, layer, files } = platform;
|
|
539
|
+
const destination = files?.[0]?.destination;
|
|
540
|
+
const format = R7.compose(
|
|
541
|
+
createPropertyFormatter({
|
|
542
|
+
outputReferences,
|
|
543
|
+
dictionary,
|
|
544
|
+
format: "css",
|
|
545
|
+
usesDtcg
|
|
546
|
+
}),
|
|
547
|
+
(token) => ({
|
|
548
|
+
...token,
|
|
549
|
+
name: token.name.replace(/color-\w+-/, "color-"),
|
|
550
|
+
original: {
|
|
551
|
+
...token.original,
|
|
552
|
+
$value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
|
|
553
|
+
}
|
|
554
|
+
})
|
|
555
|
+
);
|
|
556
|
+
const formattedMap = dictionary.allTokens.map((token) => ({
|
|
557
|
+
token,
|
|
558
|
+
formatted: format(token)
|
|
559
|
+
}));
|
|
560
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
561
|
+
const formattedTokens = formattedMap.map(R7.view(R7.lensProp("formatted"))).join("\n");
|
|
562
|
+
const content = `{
|
|
563
|
+
${formattedTokens}
|
|
564
|
+
}
|
|
565
|
+
`;
|
|
566
|
+
const body = R7.isNotNil(layer) ? `@layer ${layer} {
|
|
567
|
+
${selector} ${content}
|
|
568
|
+
}
|
|
569
|
+
` : `${selector} ${content}
|
|
570
|
+
`;
|
|
571
|
+
return body;
|
|
572
|
+
}
|
|
573
|
+
};
|
|
574
|
+
|
|
575
|
+
// src/tokens/process/formats/css/semantic.ts
|
|
576
|
+
import * as R8 from "ramda";
|
|
577
|
+
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
578
|
+
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
579
|
+
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
580
|
+
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
581
|
+
var isInlineTokens = R8.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
582
|
+
var overrideSizingFormula = (format, token) => {
|
|
583
|
+
const [name, value] = format(token).split(":");
|
|
584
|
+
const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
|
|
585
|
+
const round = `round(down, ${calc}, 1px)`;
|
|
586
|
+
return {
|
|
587
|
+
name,
|
|
588
|
+
round,
|
|
589
|
+
calc
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
var formatSizingTokens = (format, tokens) => R8.reduce(
|
|
593
|
+
(acc, token) => {
|
|
594
|
+
const { round, calc, name } = overrideSizingFormula(format, token);
|
|
595
|
+
return {
|
|
596
|
+
tokens: [...acc.tokens, token],
|
|
597
|
+
round: [...acc.round, `${name}: ${round};`],
|
|
598
|
+
calc: [...acc.calc, `${name}: ${calc};`]
|
|
599
|
+
};
|
|
600
|
+
},
|
|
601
|
+
{ tokens: [], round: [], calc: [] },
|
|
602
|
+
tokens
|
|
603
|
+
);
|
|
604
|
+
var sizingTemplate = ({ round, calc }) => `
|
|
605
|
+
${calc.join("\n")}
|
|
606
|
+
|
|
607
|
+
@supports (width: round(down, .1em, 1px)) {
|
|
608
|
+
${round.join("\n")}
|
|
609
|
+
}`;
|
|
610
|
+
var semantic = {
|
|
611
|
+
name: "ds/css-semantic",
|
|
612
|
+
format: async ({ dictionary, options, platform }) => {
|
|
613
|
+
const { outputReferences, usesDtcg } = options;
|
|
614
|
+
const { selector, layer, files } = platform;
|
|
615
|
+
const destination = files?.[0]?.destination;
|
|
616
|
+
const format = createPropertyFormatter2({
|
|
617
|
+
outputReferences,
|
|
618
|
+
dictionary,
|
|
619
|
+
format: "css",
|
|
620
|
+
usesDtcg
|
|
621
|
+
});
|
|
622
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
623
|
+
const filteredTokens = R8.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
|
|
624
|
+
const [sizingTokens, restTokens] = R8.partition(
|
|
625
|
+
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
626
|
+
filteredTokens
|
|
627
|
+
);
|
|
628
|
+
const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
|
|
629
|
+
const formattedMap = restTokens.map((token) => ({
|
|
630
|
+
token,
|
|
631
|
+
formatted: format(token)
|
|
632
|
+
}));
|
|
633
|
+
const formattedSizingMap = formattedSizingTokens.round.map((t, i) => ({
|
|
634
|
+
token: formattedSizingTokens.tokens[i],
|
|
635
|
+
formatted: t
|
|
636
|
+
}));
|
|
637
|
+
buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
|
|
638
|
+
const sizingSnippet = sizingTemplate(formattedSizingTokens);
|
|
639
|
+
const formattedTokens = formattedMap.map(R8.view(R8.lensProp("formatted"))).concat(sizingSnippet);
|
|
640
|
+
const content = `{
|
|
641
|
+
${formattedTokens.join("\n")}
|
|
642
|
+
}
|
|
643
|
+
`;
|
|
644
|
+
const body = R8.isNotNil(layer) ? `@layer ${layer} {
|
|
645
|
+
${selector} ${content}
|
|
646
|
+
}
|
|
647
|
+
` : `${selector} ${content}
|
|
648
|
+
`;
|
|
649
|
+
return body;
|
|
650
|
+
}
|
|
651
|
+
};
|
|
652
|
+
|
|
653
|
+
// src/tokens/process/formats/css/typography.ts
|
|
654
|
+
import * as R9 from "ramda";
|
|
655
|
+
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
656
|
+
var typographyFontFamilyPredicate = R9.allPass([
|
|
657
|
+
R9.pathSatisfies(R9.includes("typography"), ["path"]),
|
|
658
|
+
R9.pathSatisfies(R9.includes("fontFamily"), ["path"])
|
|
659
|
+
]);
|
|
660
|
+
var typography = {
|
|
661
|
+
name: "ds/css-typography",
|
|
662
|
+
format: async ({ dictionary, options, platform }) => {
|
|
663
|
+
const { outputReferences, usesDtcg } = options;
|
|
664
|
+
const { selector, layer, files } = platform;
|
|
665
|
+
const destination = files?.[0]?.destination;
|
|
666
|
+
const format = createPropertyFormatter3({
|
|
667
|
+
outputReferences,
|
|
668
|
+
dictionary,
|
|
669
|
+
format: "css",
|
|
670
|
+
usesDtcg
|
|
671
|
+
});
|
|
672
|
+
const filteredTokens = R9.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
673
|
+
const formattedMap = filteredTokens.map((token) => ({
|
|
674
|
+
token,
|
|
675
|
+
formatted: format(token)
|
|
676
|
+
}));
|
|
677
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
678
|
+
const formattedTokens = formattedMap.map(R9.view(R9.lensProp("formatted"))).join("\n");
|
|
679
|
+
const content = selector ? `${selector} {
|
|
680
|
+
${formattedTokens}
|
|
681
|
+
}` : formattedTokens;
|
|
682
|
+
const body = R9.isNotNil(layer) ? `@layer ${layer} {
|
|
683
|
+
${content}
|
|
684
|
+
}` : content;
|
|
685
|
+
return body;
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
// src/tokens/process/formats/css.ts
|
|
690
|
+
var formats = {
|
|
691
|
+
colorScheme,
|
|
692
|
+
colorCategory,
|
|
693
|
+
semantic,
|
|
694
|
+
typography
|
|
754
695
|
};
|
|
755
696
|
|
|
756
697
|
// src/tokens/process/configs/color.ts
|
|
@@ -774,7 +715,7 @@ var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) =
|
|
|
774
715
|
{
|
|
775
716
|
destination: `color-scheme/${colorScheme2}.css`,
|
|
776
717
|
format: formats.colorScheme.name,
|
|
777
|
-
filter: (token) => typeEquals("color", token) && !
|
|
718
|
+
filter: (token) => typeEquals("color", token) && !R10.startsWith(["global"], token.path)
|
|
778
719
|
}
|
|
779
720
|
],
|
|
780
721
|
options: {
|