@digdir/designsystemet 1.4.0 → 1.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/designsystemet.js +484 -162
- package/dist/global-Y35YADVH.json +100 -0
- package/dist/src/index.js +523 -199
- package/dist/src/scripts/update-preview-tokens.js +429 -118
- package/dist/src/tokens/build.js +425 -107
- package/dist/src/tokens/create/defaults.js +27 -23
- package/dist/src/tokens/create/generators/$designsystemet.js +2 -2
- package/dist/src/tokens/create/write.js +2 -2
- package/dist/src/tokens/create.js +27 -23
- package/dist/src/tokens/format.js +523 -199
- package/dist/src/tokens/index.js +523 -199
- package/dist/src/tokens/process/configs/color.js +366 -66
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/semantic.js +368 -68
- package/dist/src/tokens/process/configs/shared.js +9 -2
- package/dist/src/tokens/process/configs/size-mode.d.ts +3 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size-mode.js +1067 -0
- package/dist/src/tokens/process/configs/size.d.ts +3 -0
- package/dist/src/tokens/process/configs/size.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size.js +1069 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts +3 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/type-scale.js +1067 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/typography.js +364 -64
- package/dist/src/tokens/process/configs.d.ts +3 -0
- package/dist/src/tokens/process/configs.d.ts.map +1 -1
- package/dist/src/tokens/process/configs.js +373 -71
- package/dist/src/tokens/process/formats/css/color.js +381 -79
- package/dist/src/tokens/process/formats/css/semantic.d.ts +0 -14
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -1
- package/dist/src/tokens/process/formats/css/semantic.js +407 -109
- package/dist/src/tokens/process/formats/css/size-mode.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size-mode.js +1068 -0
- package/dist/src/tokens/process/formats/css/size.d.ts +17 -0
- package/dist/src/tokens/process/formats/css/size.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size.js +1069 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/type-scale.js +1069 -0
- package/dist/src/tokens/process/formats/css/typography.js +365 -63
- package/dist/src/tokens/process/formats/css.d.ts +3 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -1
- package/dist/src/tokens/process/formats/css.js +364 -64
- package/dist/src/tokens/process/output/declarations.js +372 -70
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -1
- package/dist/src/tokens/process/output/theme.js +59 -10
- package/dist/src/tokens/process/platform.d.ts +16 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/process/platform.js +402 -95
- package/dist/src/tokens/process/transformers.js +9 -2
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +373 -71
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +1 -1
- package/dist/src/tokens/utils.d.ts +4 -1
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/dist/src/tokens/utils.js +24 -1
- package/package.json +2 -2
- package/dist/global-XVXVBKM6.json +0 -96
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/tokens/process/configs/color.ts
|
|
2
|
-
import * as
|
|
2
|
+
import * as R15 from "ramda";
|
|
3
3
|
|
|
4
4
|
// src/tokens/utils.ts
|
|
5
5
|
import * as R from "ramda";
|
|
@@ -29,7 +29,10 @@ var pathStartsWithOneOf = R.curry(
|
|
|
29
29
|
return false;
|
|
30
30
|
}
|
|
31
31
|
const tokenPath = mapToLowerCase(token.path);
|
|
32
|
-
const matchPathsStartingWith = R.map((
|
|
32
|
+
const matchPathsStartingWith = R.map((pathOrString) => {
|
|
33
|
+
const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
|
|
34
|
+
return R.startsWith(mapToLowerCase(path), tokenPath);
|
|
35
|
+
}, paths);
|
|
33
36
|
return hasAnyTruth(matchPathsStartingWith);
|
|
34
37
|
}
|
|
35
38
|
);
|
|
@@ -65,19 +68,36 @@ function inlineTokens(shouldInline, tokens) {
|
|
|
65
68
|
return tokenWithInlinedRefs;
|
|
66
69
|
});
|
|
67
70
|
}
|
|
71
|
+
var sizeMap = {
|
|
72
|
+
xsmall: "xs",
|
|
73
|
+
small: "sm",
|
|
74
|
+
medium: "md",
|
|
75
|
+
large: "lg",
|
|
76
|
+
xlarge: "xl"
|
|
77
|
+
};
|
|
78
|
+
function shortSizeName(size2) {
|
|
79
|
+
return sizeMap[size2] ?? size2;
|
|
80
|
+
}
|
|
81
|
+
var sizeComparator = (size2) => {
|
|
82
|
+
const sortIndex = Object.entries(sizeMap).findIndex(([key, val]) => key === size2 || val === size2);
|
|
83
|
+
return sortIndex ?? 0;
|
|
84
|
+
};
|
|
85
|
+
function orderBySize(sizes) {
|
|
86
|
+
return R.sortBy(sizeComparator, sizes);
|
|
87
|
+
}
|
|
68
88
|
|
|
69
89
|
// src/tokens/process/formats/css/color.ts
|
|
70
|
-
import * as
|
|
90
|
+
import * as R9 from "ramda";
|
|
71
91
|
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
72
92
|
|
|
73
93
|
// src/tokens/process/platform.ts
|
|
74
94
|
import pc2 from "picocolors";
|
|
75
|
-
import * as
|
|
95
|
+
import * as R8 from "ramda";
|
|
76
96
|
import StyleDictionary2 from "style-dictionary";
|
|
77
97
|
|
|
78
98
|
// src/tokens/process/configs.ts
|
|
79
99
|
import { register } from "@tokens-studio/sd-transforms";
|
|
80
|
-
import * as
|
|
100
|
+
import * as R7 from "ramda";
|
|
81
101
|
import StyleDictionary from "style-dictionary";
|
|
82
102
|
|
|
83
103
|
// src/tokens/process/configs/semantic.ts
|
|
@@ -94,18 +114,22 @@ var sizeRem = {
|
|
|
94
114
|
transitive: true,
|
|
95
115
|
filter: (token) => {
|
|
96
116
|
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
97
|
-
const hasWantedPath = pathStartsWithOneOf([
|
|
117
|
+
const hasWantedPath = pathStartsWithOneOf([
|
|
118
|
+
"border-radius",
|
|
119
|
+
"font-size"
|
|
120
|
+
/*, ['_size', 'mode-font-size']*/
|
|
121
|
+
], token);
|
|
98
122
|
return hasWantedType && hasWantedPath;
|
|
99
123
|
},
|
|
100
124
|
transform: (token, config) => {
|
|
101
125
|
const value = getValue(token);
|
|
102
126
|
if (isPx(value)) {
|
|
103
127
|
const baseFont = config.basePxFontSize || 16;
|
|
104
|
-
const
|
|
105
|
-
if (
|
|
128
|
+
const size2 = parseInt(value, 10);
|
|
129
|
+
if (size2 === 0) {
|
|
106
130
|
return "0";
|
|
107
131
|
}
|
|
108
|
-
return `${
|
|
132
|
+
return `${size2 / baseFont}rem`;
|
|
109
133
|
}
|
|
110
134
|
return value;
|
|
111
135
|
}
|
|
@@ -180,7 +204,10 @@ var semanticVariables = ({ theme }) => {
|
|
|
180
204
|
filter: (token) => {
|
|
181
205
|
const isUwantedToken = R3.anyPass([R3.includes("primitives/global")])(token.filePath);
|
|
182
206
|
const isPrivateToken = R3.includes("_", token.path);
|
|
183
|
-
const unwantedPaths = pathStartsWithOneOf(
|
|
207
|
+
const unwantedPaths = pathStartsWithOneOf(
|
|
208
|
+
["size", "_size", "font-size", "line-height", "letter-spacing"],
|
|
209
|
+
token
|
|
210
|
+
);
|
|
184
211
|
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
185
212
|
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
186
213
|
return unwantedTokens;
|
|
@@ -190,8 +217,7 @@ var semanticVariables = ({ theme }) => {
|
|
|
190
217
|
options: {
|
|
191
218
|
outputReferences: (token, options) => {
|
|
192
219
|
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
193
|
-
|
|
194
|
-
return (include || isWantedSize) && outputReferencesFilter(token, options);
|
|
220
|
+
return include && outputReferencesFilter(token, options);
|
|
195
221
|
}
|
|
196
222
|
}
|
|
197
223
|
}
|
|
@@ -199,6 +225,124 @@ var semanticVariables = ({ theme }) => {
|
|
|
199
225
|
};
|
|
200
226
|
};
|
|
201
227
|
|
|
228
|
+
// src/tokens/process/configs/size.ts
|
|
229
|
+
import * as R4 from "ramda";
|
|
230
|
+
import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
|
|
231
|
+
var sizeVariables = ({ theme }) => {
|
|
232
|
+
const selector = `:root, [data-size]`;
|
|
233
|
+
const layer = `ds.theme.size`;
|
|
234
|
+
return {
|
|
235
|
+
preprocessors: ["tokens-studio"],
|
|
236
|
+
platforms: {
|
|
237
|
+
css: {
|
|
238
|
+
// custom
|
|
239
|
+
theme,
|
|
240
|
+
basePxFontSize,
|
|
241
|
+
selector,
|
|
242
|
+
layer,
|
|
243
|
+
//
|
|
244
|
+
prefix,
|
|
245
|
+
buildPath: `${theme}/`,
|
|
246
|
+
transforms: dsTransformers,
|
|
247
|
+
files: [
|
|
248
|
+
{
|
|
249
|
+
destination: `size.css`,
|
|
250
|
+
format: formats.size.name,
|
|
251
|
+
filter: (token) => {
|
|
252
|
+
const isUwantedToken = R4.anyPass([R4.includes("primitives/global")])(token.filePath);
|
|
253
|
+
const isPrivateToken = R4.includes("_", token.path);
|
|
254
|
+
return pathStartsWithOneOf(["size", "_size"], token) && !(isUwantedToken || isPrivateToken);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
],
|
|
258
|
+
options: {
|
|
259
|
+
outputReferences: (token, options) => {
|
|
260
|
+
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && (isDigit(token.path[1]) || token.path[1] === "unit");
|
|
261
|
+
return isWantedSize && outputReferencesFilter2(token, options);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
};
|
|
268
|
+
|
|
269
|
+
// src/tokens/process/configs/size-mode.ts
|
|
270
|
+
import * as R5 from "ramda";
|
|
271
|
+
var sizeModeVariables = ({ theme, size: size2 }) => {
|
|
272
|
+
const selector = `:root`;
|
|
273
|
+
const layer = `ds.theme.size-mode`;
|
|
274
|
+
return {
|
|
275
|
+
preprocessors: ["tokens-studio"],
|
|
276
|
+
platforms: {
|
|
277
|
+
css: {
|
|
278
|
+
// custom
|
|
279
|
+
size: size2,
|
|
280
|
+
theme,
|
|
281
|
+
basePxFontSize,
|
|
282
|
+
selector,
|
|
283
|
+
layer,
|
|
284
|
+
//
|
|
285
|
+
prefix,
|
|
286
|
+
buildPath: `${theme}/`,
|
|
287
|
+
transforms: dsTransformers,
|
|
288
|
+
files: [
|
|
289
|
+
{
|
|
290
|
+
destination: `size-mode/${size2}.css`,
|
|
291
|
+
format: formats.sizeMode.name,
|
|
292
|
+
filter: (token) => {
|
|
293
|
+
return R5.equals(["_size", "mode-font-size"], token.path);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
]
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
};
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// src/tokens/process/configs/type-scale.ts
|
|
303
|
+
var typeScaleVariables = ({ theme, size: size2 }) => {
|
|
304
|
+
const selector = ":root, [data-size]";
|
|
305
|
+
const layer = `ds.theme.type-scale`;
|
|
306
|
+
return {
|
|
307
|
+
usesDtcg: true,
|
|
308
|
+
preprocessors: ["tokens-studio"],
|
|
309
|
+
expand: {
|
|
310
|
+
include: ["typography"]
|
|
311
|
+
},
|
|
312
|
+
platforms: {
|
|
313
|
+
css: {
|
|
314
|
+
prefix,
|
|
315
|
+
selector,
|
|
316
|
+
layer,
|
|
317
|
+
buildPath: `${theme}/`,
|
|
318
|
+
basePxFontSize,
|
|
319
|
+
transforms: [
|
|
320
|
+
"name/kebab",
|
|
321
|
+
"ts/size/px",
|
|
322
|
+
sizeRem.name,
|
|
323
|
+
"ts/size/lineheight",
|
|
324
|
+
"ts/typography/fontWeight",
|
|
325
|
+
typographyName.name
|
|
326
|
+
],
|
|
327
|
+
files: [
|
|
328
|
+
{
|
|
329
|
+
destination: `type-scale.css`,
|
|
330
|
+
format: formats.typeScale.name,
|
|
331
|
+
filter: (token) => {
|
|
332
|
+
const included = typeEquals(["typography", "dimension", "fontsize"], token);
|
|
333
|
+
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
334
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "border-width", "border-radius"], token) && (pathStartsWithOneOf(["font-size"], token) || token.path.includes("fontSize"));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
],
|
|
338
|
+
options: {
|
|
339
|
+
outputReferences: (token) => pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize")
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
};
|
|
345
|
+
|
|
202
346
|
// src/tokens/process/configs/typography.ts
|
|
203
347
|
import { expandTypesMap } from "@tokens-studio/sd-transforms";
|
|
204
348
|
var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
@@ -233,12 +377,9 @@ var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
|
233
377
|
destination: `typography/${typography2}.css`,
|
|
234
378
|
format: formats.typography.name,
|
|
235
379
|
filter: (token) => {
|
|
236
|
-
const included = typeEquals(
|
|
237
|
-
["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
|
|
238
|
-
token
|
|
239
|
-
);
|
|
380
|
+
const included = typeEquals(["fontweight", "fontFamily", "lineHeight", "dimension"], token);
|
|
240
381
|
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
241
|
-
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token);
|
|
382
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token) && !(pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize"));
|
|
242
383
|
}
|
|
243
384
|
}
|
|
244
385
|
]
|
|
@@ -413,9 +554,9 @@ var TypographyValues;
|
|
|
413
554
|
// src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
414
555
|
import { kebabCase } from "change-case";
|
|
415
556
|
import pc from "picocolors";
|
|
416
|
-
import * as
|
|
557
|
+
import * as R6 from "ramda";
|
|
417
558
|
var processed = Symbol("Type brand for ProcessedThemeObject");
|
|
418
|
-
var hasUnknownProps =
|
|
559
|
+
var hasUnknownProps = R6.pipe(R6.values, R6.none(R6.equals("unknown")), R6.not);
|
|
419
560
|
|
|
420
561
|
// src/tokens/process/configs.ts
|
|
421
562
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
@@ -435,7 +576,10 @@ var configs = {
|
|
|
435
576
|
dangerColorVariables: colorCategoryVariables({ category: "builtin", color: "danger" }),
|
|
436
577
|
warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
|
|
437
578
|
infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
|
|
579
|
+
sizeModeVariables,
|
|
580
|
+
sizeVariables,
|
|
438
581
|
typographyVariables,
|
|
582
|
+
typeScaleVariables,
|
|
439
583
|
semanticVariables
|
|
440
584
|
};
|
|
441
585
|
|
|
@@ -448,6 +592,9 @@ var buildOptions = {
|
|
|
448
592
|
var sd = new StyleDictionary2();
|
|
449
593
|
var buildConfigs = {
|
|
450
594
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
595
|
+
sizeMode: { getConfig: configs.sizeModeVariables, dimensions: ["size"] },
|
|
596
|
+
size: { getConfig: configs.sizeVariables, dimensions: ["semantic"] },
|
|
597
|
+
typeScale: { getConfig: configs.typeScaleVariables, dimensions: ["semantic"] },
|
|
451
598
|
"color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
|
|
452
599
|
"main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
|
|
453
600
|
"support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
|
|
@@ -502,8 +649,8 @@ var colorScheme = {
|
|
|
502
649
|
color-scheme: ${colorScheme_};
|
|
503
650
|
` : "";
|
|
504
651
|
const filteredAllTokens = allTokens.filter(
|
|
505
|
-
|
|
506
|
-
|
|
652
|
+
R9.allPass([
|
|
653
|
+
R9.anyPass([
|
|
507
654
|
// Include semantic tokens in the output
|
|
508
655
|
isSemanticToken,
|
|
509
656
|
// Include global color tokens
|
|
@@ -517,13 +664,13 @@ var colorScheme = {
|
|
|
517
664
|
token,
|
|
518
665
|
formatted: format(token)
|
|
519
666
|
}));
|
|
520
|
-
const formattedTokens = formattedMap.map(
|
|
667
|
+
const formattedTokens = formattedMap.map(R9.view(R9.lensProp("formatted"))).join("\n");
|
|
521
668
|
const content = `{
|
|
522
669
|
${formattedTokens}
|
|
523
670
|
${colorSchemeProperty}}
|
|
524
671
|
`;
|
|
525
672
|
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
526
|
-
const body =
|
|
673
|
+
const body = R9.isNotNil(layer) ? `@layer ${layer} {
|
|
527
674
|
${selector} ${content} ${autoSelectorContent}
|
|
528
675
|
}
|
|
529
676
|
` : `${selector} ${content} ${autoSelectorContent}
|
|
@@ -533,11 +680,11 @@ ${selector} ${content} ${autoSelectorContent}
|
|
|
533
680
|
};
|
|
534
681
|
var colorCategory = {
|
|
535
682
|
name: "ds/css-colorcategory",
|
|
536
|
-
format: async ({ dictionary, options, platform }) => {
|
|
683
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
537
684
|
const { outputReferences, usesDtcg } = options;
|
|
538
|
-
const { selector, layer
|
|
539
|
-
const destination =
|
|
540
|
-
const format =
|
|
685
|
+
const { selector, layer } = platform;
|
|
686
|
+
const destination = file.destination;
|
|
687
|
+
const format = R9.compose(
|
|
541
688
|
createPropertyFormatter({
|
|
542
689
|
outputReferences,
|
|
543
690
|
dictionary,
|
|
@@ -558,12 +705,12 @@ var colorCategory = {
|
|
|
558
705
|
formatted: format(token)
|
|
559
706
|
}));
|
|
560
707
|
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
561
|
-
const formattedTokens = formattedMap.map(
|
|
708
|
+
const formattedTokens = formattedMap.map(R9.view(R9.lensProp("formatted"))).join("\n");
|
|
562
709
|
const content = `{
|
|
563
710
|
${formattedTokens}
|
|
564
711
|
}
|
|
565
712
|
`;
|
|
566
|
-
const body =
|
|
713
|
+
const body = R9.isNotNil(layer) ? `@layer ${layer} {
|
|
567
714
|
${selector} ${content}
|
|
568
715
|
}
|
|
569
716
|
` : `${selector} ${content}
|
|
@@ -573,23 +720,35 @@ ${selector} ${content}
|
|
|
573
720
|
};
|
|
574
721
|
|
|
575
722
|
// src/tokens/process/formats/css/semantic.ts
|
|
576
|
-
import * as
|
|
723
|
+
import * as R11 from "ramda";
|
|
724
|
+
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
725
|
+
|
|
726
|
+
// src/tokens/process/formats/css/size.ts
|
|
727
|
+
import * as R10 from "ramda";
|
|
577
728
|
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
578
729
|
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
579
730
|
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
580
731
|
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
581
|
-
var isInlineTokens =
|
|
732
|
+
var isInlineTokens = R10.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
582
733
|
var overrideSizingFormula = (format, token) => {
|
|
583
|
-
const [name, value] = format(token).split(":");
|
|
584
|
-
|
|
585
|
-
|
|
734
|
+
const [name, value] = format(token).replace(/;$/, "").split(": ");
|
|
735
|
+
let calc;
|
|
736
|
+
let round;
|
|
737
|
+
if (token.path[1] === "unit") {
|
|
738
|
+
calc = `calc(1rem * ${value})`;
|
|
739
|
+
} else if (value.startsWith("floor")) {
|
|
740
|
+
calc = value.replace(/^floor\((.*)\)$/, "calc($1)");
|
|
741
|
+
round = `round(down, ${calc}, 1px)`;
|
|
742
|
+
} else {
|
|
743
|
+
calc = value.includes("*") ? `calc(${value})` : value;
|
|
744
|
+
}
|
|
586
745
|
return {
|
|
587
746
|
name,
|
|
588
|
-
round,
|
|
747
|
+
round: round ?? calc,
|
|
589
748
|
calc
|
|
590
749
|
};
|
|
591
750
|
};
|
|
592
|
-
var formatSizingTokens = (format, tokens) =>
|
|
751
|
+
var formatSizingTokens = (format, tokens) => R10.reduce(
|
|
593
752
|
(acc, token) => {
|
|
594
753
|
const { round, calc, name } = overrideSizingFormula(format, token);
|
|
595
754
|
return {
|
|
@@ -601,18 +760,21 @@ var formatSizingTokens = (format, tokens) => R8.reduce(
|
|
|
601
760
|
{ tokens: [], round: [], calc: [] },
|
|
602
761
|
tokens
|
|
603
762
|
);
|
|
604
|
-
var sizingTemplate = ({ round, calc }) =>
|
|
763
|
+
var sizingTemplate = ({ round, calc }) => {
|
|
764
|
+
const usesRounding = round.filter((val, i) => val !== calc[i]);
|
|
765
|
+
return `
|
|
605
766
|
${calc.join("\n")}
|
|
606
767
|
|
|
607
768
|
@supports (width: round(down, .1em, 1px)) {
|
|
608
|
-
${
|
|
769
|
+
${usesRounding.join("\n ")}
|
|
609
770
|
}`;
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
771
|
+
};
|
|
772
|
+
var size = {
|
|
773
|
+
name: "ds/css-size",
|
|
774
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
613
775
|
const { outputReferences, usesDtcg } = options;
|
|
614
|
-
const { selector, layer
|
|
615
|
-
const destination =
|
|
776
|
+
const { selector, layer } = platform;
|
|
777
|
+
const destination = file.destination;
|
|
616
778
|
const format = createPropertyFormatter2({
|
|
617
779
|
outputReferences,
|
|
618
780
|
dictionary,
|
|
@@ -620,9 +782,9 @@ var semantic = {
|
|
|
620
782
|
usesDtcg
|
|
621
783
|
});
|
|
622
784
|
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
623
|
-
const filteredTokens =
|
|
624
|
-
const [sizingTokens, restTokens] =
|
|
625
|
-
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
785
|
+
const filteredTokens = R10.reject((token) => R10.equals(["_size", "mode-font-size"], token.path), tokens);
|
|
786
|
+
const [sizingTokens, restTokens] = R10.partition(
|
|
787
|
+
(t) => pathStartsWithOneOf(["_size"], t) && (isDigit(t.path[1]) || t.path[1] === "unit"),
|
|
626
788
|
filteredTokens
|
|
627
789
|
);
|
|
628
790
|
const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
|
|
@@ -635,51 +797,186 @@ var semantic = {
|
|
|
635
797
|
formatted: t
|
|
636
798
|
}));
|
|
637
799
|
buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
|
|
638
|
-
const
|
|
639
|
-
const
|
|
640
|
-
const content = `{
|
|
800
|
+
const formattedTokens = [formattedMap.map(R10.prop("formatted")).join("\n"), sizingTemplate(formattedSizingTokens)];
|
|
801
|
+
const content = `${selector} {
|
|
641
802
|
${formattedTokens.join("\n")}
|
|
642
803
|
}
|
|
643
804
|
`;
|
|
644
|
-
const body =
|
|
645
|
-
${
|
|
805
|
+
const body = R10.isNotNil(layer) ? `@layer ${layer} {
|
|
806
|
+
${content}
|
|
646
807
|
}
|
|
647
|
-
` : `${
|
|
808
|
+
` : `${content}
|
|
809
|
+
`;
|
|
810
|
+
return body;
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
// src/tokens/process/formats/css/semantic.ts
|
|
815
|
+
var semantic = {
|
|
816
|
+
name: "ds/css-semantic",
|
|
817
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
818
|
+
const { outputReferences, usesDtcg } = options;
|
|
819
|
+
const { selector, layer } = platform;
|
|
820
|
+
const destination = file.destination;
|
|
821
|
+
const format = createPropertyFormatter3({
|
|
822
|
+
outputReferences,
|
|
823
|
+
dictionary,
|
|
824
|
+
format: "css",
|
|
825
|
+
usesDtcg
|
|
826
|
+
});
|
|
827
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
828
|
+
const formattedMap = tokens.map((token) => ({
|
|
829
|
+
token,
|
|
830
|
+
formatted: format(token)
|
|
831
|
+
}));
|
|
832
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
833
|
+
const formattedTokens = formattedMap.map(R11.prop("formatted")).join("\n");
|
|
834
|
+
const content = `${selector} {
|
|
835
|
+
${formattedTokens}
|
|
836
|
+
}
|
|
837
|
+
`;
|
|
838
|
+
const body = R11.isNotNil(layer) ? `@layer ${layer} {
|
|
839
|
+
${content}
|
|
840
|
+
}
|
|
841
|
+
` : `${content}
|
|
648
842
|
`;
|
|
649
843
|
return body;
|
|
650
844
|
}
|
|
651
845
|
};
|
|
652
846
|
|
|
847
|
+
// src/tokens/process/formats/css/size-mode.ts
|
|
848
|
+
import * as R12 from "ramda";
|
|
849
|
+
import { createPropertyFormatter as createPropertyFormatter4 } from "style-dictionary/utils";
|
|
850
|
+
var formatBaseSizeToken = (size2) => (token) => ({
|
|
851
|
+
...token,
|
|
852
|
+
originalName: token.name,
|
|
853
|
+
name: `${token.name}--${shortSizeName(size2)}`,
|
|
854
|
+
$value: token.$value / basePxFontSize
|
|
855
|
+
});
|
|
856
|
+
var sizeMode = {
|
|
857
|
+
name: "ds/css-size-mode",
|
|
858
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
859
|
+
const { outputReferences, usesDtcg } = options;
|
|
860
|
+
const { selector, layer, size: size2 } = platform;
|
|
861
|
+
const destination = file.destination;
|
|
862
|
+
const format = createPropertyFormatter4({
|
|
863
|
+
outputReferences,
|
|
864
|
+
dictionary,
|
|
865
|
+
format: "css",
|
|
866
|
+
usesDtcg
|
|
867
|
+
});
|
|
868
|
+
const sizeSpecificTokens = dictionary.allTokens.map(formatBaseSizeToken(size2));
|
|
869
|
+
const sizeSpecificVariables = sizeSpecificTokens.map(format).join("\n");
|
|
870
|
+
const formattedMap = sizeSpecificTokens.map((token) => ({
|
|
871
|
+
token,
|
|
872
|
+
formatted: format({
|
|
873
|
+
...token,
|
|
874
|
+
// Remove the `--<size>` suffix for the token listing, since that is the only token we actually use
|
|
875
|
+
name: token.originalName
|
|
876
|
+
})
|
|
877
|
+
}));
|
|
878
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
879
|
+
const content = `${selector} /* ${size2} */ {
|
|
880
|
+
${sizeSpecificVariables}
|
|
881
|
+
}`;
|
|
882
|
+
const body = wrapInLayer(content, layer);
|
|
883
|
+
const sizes = orderBySize(buildOptions?.sizeModes ?? []).map(shortSizeName);
|
|
884
|
+
const defaultSize = shortSizeName(buildOptions?.defaultSize ?? "");
|
|
885
|
+
const sizingToggles = `:root, [data-size] {
|
|
886
|
+
--ds-size: var(--ds-size--${defaultSize});
|
|
887
|
+
${sizes.map((size3) => ` --ds-size--${size3}: var(--ds-size,);`).join("\n")}
|
|
888
|
+
--ds-size-mode-font-size:
|
|
889
|
+
${sizes.map((size3) => ` var(--ds-size--${size3}, var(--ds-size-mode-font-size--${size3}))`).join("\n")};
|
|
890
|
+
}`;
|
|
891
|
+
const sizingHelpers = sizes.map((size3) => `[data-size='${size3}'] { --ds-size: var(--ds-size--${size3}); }`).join("\n");
|
|
892
|
+
const sharedContent = `${sizingToggles}
|
|
893
|
+
|
|
894
|
+
${sizingHelpers}`;
|
|
895
|
+
const sharedBody = shortSizeName(size2) === R12.last(sizes) ? `
|
|
896
|
+
${wrapInLayer(sharedContent, layer)}` : "";
|
|
897
|
+
return body + sharedBody;
|
|
898
|
+
}
|
|
899
|
+
};
|
|
900
|
+
function wrapInLayer(content, layer) {
|
|
901
|
+
return R12.isNotNil(layer) ? `@layer ${layer} {
|
|
902
|
+
${content}
|
|
903
|
+
}
|
|
904
|
+
` : `${content}
|
|
905
|
+
`;
|
|
906
|
+
}
|
|
907
|
+
|
|
653
908
|
// src/tokens/process/formats/css/typography.ts
|
|
654
|
-
import * as
|
|
655
|
-
import { createPropertyFormatter as
|
|
656
|
-
var typographyFontFamilyPredicate =
|
|
657
|
-
|
|
658
|
-
|
|
909
|
+
import * as R13 from "ramda";
|
|
910
|
+
import { createPropertyFormatter as createPropertyFormatter5 } from "style-dictionary/utils";
|
|
911
|
+
var typographyFontFamilyPredicate = R13.allPass([
|
|
912
|
+
R13.pathSatisfies(R13.includes("typography"), ["path"]),
|
|
913
|
+
R13.pathSatisfies(R13.includes("fontFamily"), ["path"])
|
|
659
914
|
]);
|
|
660
915
|
var typography = {
|
|
661
916
|
name: "ds/css-typography",
|
|
662
|
-
format: async ({ dictionary, options, platform }) => {
|
|
917
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
663
918
|
const { outputReferences, usesDtcg } = options;
|
|
664
|
-
const { selector, layer
|
|
665
|
-
const destination =
|
|
666
|
-
const format =
|
|
919
|
+
const { selector, layer } = platform;
|
|
920
|
+
const destination = file.destination;
|
|
921
|
+
const format = createPropertyFormatter5({
|
|
667
922
|
outputReferences,
|
|
668
923
|
dictionary,
|
|
669
924
|
format: "css",
|
|
670
925
|
usesDtcg
|
|
671
926
|
});
|
|
672
|
-
const filteredTokens =
|
|
927
|
+
const filteredTokens = R13.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
673
928
|
const formattedMap = filteredTokens.map((token) => ({
|
|
674
929
|
token,
|
|
675
930
|
formatted: format(token)
|
|
676
931
|
}));
|
|
677
932
|
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
678
|
-
const formattedTokens = formattedMap.map(
|
|
933
|
+
const formattedTokens = formattedMap.map(R13.view(R13.lensProp("formatted"))).join("\n");
|
|
679
934
|
const content = selector ? `${selector} {
|
|
680
935
|
${formattedTokens}
|
|
681
936
|
}` : formattedTokens;
|
|
682
|
-
const body =
|
|
937
|
+
const body = R13.isNotNil(layer) ? `@layer ${layer} {
|
|
938
|
+
${content}
|
|
939
|
+
}` : content;
|
|
940
|
+
return body;
|
|
941
|
+
}
|
|
942
|
+
};
|
|
943
|
+
|
|
944
|
+
// src/tokens/process/formats/css/type-scale.ts
|
|
945
|
+
import * as R14 from "ramda";
|
|
946
|
+
import { createPropertyFormatter as createPropertyFormatter6 } from "style-dictionary/utils";
|
|
947
|
+
var typographyFontFamilyPredicate2 = R14.allPass([
|
|
948
|
+
R14.pathSatisfies(R14.includes("typography"), ["path"]),
|
|
949
|
+
R14.pathSatisfies(R14.includes("fontFamily"), ["path"])
|
|
950
|
+
]);
|
|
951
|
+
function formatTypographySizeToken(token) {
|
|
952
|
+
return { ...token, $value: `calc(${token.$value} * var(--_ds-font-size-factor))` };
|
|
953
|
+
}
|
|
954
|
+
var typeScale = {
|
|
955
|
+
name: "ds/css-type-scale",
|
|
956
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
957
|
+
const { outputReferences, usesDtcg } = options;
|
|
958
|
+
const { selector, layer } = platform;
|
|
959
|
+
const destination = file.destination;
|
|
960
|
+
const format = createPropertyFormatter6({
|
|
961
|
+
outputReferences,
|
|
962
|
+
dictionary,
|
|
963
|
+
format: "css",
|
|
964
|
+
usesDtcg
|
|
965
|
+
});
|
|
966
|
+
const filteredTokens = R14.reject(typographyFontFamilyPredicate2, dictionary.allTokens);
|
|
967
|
+
const tokens = R14.map(formatTypographySizeToken, filteredTokens);
|
|
968
|
+
const formattedMap = tokens.map((token) => ({
|
|
969
|
+
token,
|
|
970
|
+
formatted: format(token)
|
|
971
|
+
}));
|
|
972
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
973
|
+
const formattedTokens = formattedMap.map(R14.prop("formatted")).join("\n");
|
|
974
|
+
const sizeFactor = ` --_ds-font-size-factor: calc(var(--ds-size-mode-font-size) / (var(--ds-size-base) / ${basePxFontSize}));`;
|
|
975
|
+
const content = `${selector} {
|
|
976
|
+
${sizeFactor}
|
|
977
|
+
${formattedTokens}
|
|
978
|
+
}`;
|
|
979
|
+
const body = R14.isNotNil(layer) ? `@layer ${layer} {
|
|
683
980
|
${content}
|
|
684
981
|
}` : content;
|
|
685
982
|
return body;
|
|
@@ -691,7 +988,10 @@ var formats = {
|
|
|
691
988
|
colorScheme,
|
|
692
989
|
colorCategory,
|
|
693
990
|
semantic,
|
|
694
|
-
|
|
991
|
+
sizeMode,
|
|
992
|
+
size,
|
|
993
|
+
typography,
|
|
994
|
+
typeScale
|
|
695
995
|
};
|
|
696
996
|
|
|
697
997
|
// src/tokens/process/configs/color.ts
|
|
@@ -715,7 +1015,7 @@ var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) =
|
|
|
715
1015
|
{
|
|
716
1016
|
destination: `color-scheme/${colorScheme2}.css`,
|
|
717
1017
|
format: formats.colorScheme.name,
|
|
718
|
-
filter: (token) => typeEquals("color", token) && !
|
|
1018
|
+
filter: (token) => typeEquals("color", token) && !R15.startsWith(["global"], token.path)
|
|
719
1019
|
}
|
|
720
1020
|
],
|
|
721
1021
|
options: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/semantic.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkC,KAAK,wBAAwB,EAAU,MAAM,aAAa,CAAC;AAEpG,eAAO,MAAM,iBAAiB,EAAE,
|
|
1
|
+
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/semantic.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkC,KAAK,wBAAwB,EAAU,MAAM,aAAa,CAAC;AAEpG,eAAO,MAAM,iBAAiB,EAAE,wBA4C/B,CAAC"}
|