@digdir/designsystemet 1.3.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/configs/digdir.config.json +4 -0
- package/dist/bin/designsystemet.js +488 -166
- package/dist/global-Y35YADVH.json +100 -0
- package/dist/src/index.js +527 -203
- package/dist/src/scripts/update-preview-tokens.js +478 -128
- package/dist/src/tokens/build.js +429 -111
- package/dist/src/tokens/create/defaults.js +27 -23
- package/dist/src/tokens/create/generators/$designsystemet.js +6 -6
- package/dist/src/tokens/create/write.js +6 -6
- package/dist/src/tokens/create.js +27 -23
- package/dist/src/tokens/format.js +527 -203
- package/dist/src/tokens/index.js +527 -203
- 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 +376 -74
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -1
- package/dist/src/tokens/process/output/theme.js +63 -14
- 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 +6 -6
- package/dist/global-XVXVBKM6.json +0 -96
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// src/tokens/process/configs/semantic.ts
|
|
2
|
-
import * as
|
|
3
|
-
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
2
|
+
import * as R15 from "ramda";
|
|
3
|
+
import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
|
|
4
4
|
|
|
5
5
|
// src/tokens/utils.ts
|
|
6
6
|
import * as R from "ramda";
|
|
@@ -30,7 +30,10 @@ var pathStartsWithOneOf = R.curry(
|
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
32
|
const tokenPath = mapToLowerCase(token.path);
|
|
33
|
-
const matchPathsStartingWith = R.map((
|
|
33
|
+
const matchPathsStartingWith = R.map((pathOrString) => {
|
|
34
|
+
const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
|
|
35
|
+
return R.startsWith(mapToLowerCase(path), tokenPath);
|
|
36
|
+
}, paths);
|
|
34
37
|
return hasAnyTruth(matchPathsStartingWith);
|
|
35
38
|
}
|
|
36
39
|
);
|
|
@@ -66,19 +69,36 @@ function inlineTokens(shouldInline, tokens) {
|
|
|
66
69
|
return tokenWithInlinedRefs;
|
|
67
70
|
});
|
|
68
71
|
}
|
|
72
|
+
var sizeMap = {
|
|
73
|
+
xsmall: "xs",
|
|
74
|
+
small: "sm",
|
|
75
|
+
medium: "md",
|
|
76
|
+
large: "lg",
|
|
77
|
+
xlarge: "xl"
|
|
78
|
+
};
|
|
79
|
+
function shortSizeName(size2) {
|
|
80
|
+
return sizeMap[size2] ?? size2;
|
|
81
|
+
}
|
|
82
|
+
var sizeComparator = (size2) => {
|
|
83
|
+
const sortIndex = Object.entries(sizeMap).findIndex(([key, val]) => key === size2 || val === size2);
|
|
84
|
+
return sortIndex ?? 0;
|
|
85
|
+
};
|
|
86
|
+
function orderBySize(sizes) {
|
|
87
|
+
return R.sortBy(sizeComparator, sizes);
|
|
88
|
+
}
|
|
69
89
|
|
|
70
90
|
// src/tokens/process/formats/css/color.ts
|
|
71
|
-
import * as
|
|
91
|
+
import * as R9 from "ramda";
|
|
72
92
|
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
73
93
|
|
|
74
94
|
// src/tokens/process/platform.ts
|
|
75
95
|
import pc2 from "picocolors";
|
|
76
|
-
import * as
|
|
96
|
+
import * as R8 from "ramda";
|
|
77
97
|
import StyleDictionary2 from "style-dictionary";
|
|
78
98
|
|
|
79
99
|
// src/tokens/process/configs.ts
|
|
80
100
|
import { register } from "@tokens-studio/sd-transforms";
|
|
81
|
-
import * as
|
|
101
|
+
import * as R7 from "ramda";
|
|
82
102
|
import StyleDictionary from "style-dictionary";
|
|
83
103
|
|
|
84
104
|
// src/tokens/process/configs/color.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
|
}
|
|
@@ -227,6 +251,124 @@ var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, .
|
|
|
227
251
|
return config;
|
|
228
252
|
};
|
|
229
253
|
|
|
254
|
+
// src/tokens/process/configs/size.ts
|
|
255
|
+
import * as R4 from "ramda";
|
|
256
|
+
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
257
|
+
var sizeVariables = ({ theme }) => {
|
|
258
|
+
const selector = `:root, [data-size]`;
|
|
259
|
+
const layer = `ds.theme.size`;
|
|
260
|
+
return {
|
|
261
|
+
preprocessors: ["tokens-studio"],
|
|
262
|
+
platforms: {
|
|
263
|
+
css: {
|
|
264
|
+
// custom
|
|
265
|
+
theme,
|
|
266
|
+
basePxFontSize,
|
|
267
|
+
selector,
|
|
268
|
+
layer,
|
|
269
|
+
//
|
|
270
|
+
prefix,
|
|
271
|
+
buildPath: `${theme}/`,
|
|
272
|
+
transforms: dsTransformers,
|
|
273
|
+
files: [
|
|
274
|
+
{
|
|
275
|
+
destination: `size.css`,
|
|
276
|
+
format: formats.size.name,
|
|
277
|
+
filter: (token) => {
|
|
278
|
+
const isUwantedToken = R4.anyPass([R4.includes("primitives/global")])(token.filePath);
|
|
279
|
+
const isPrivateToken = R4.includes("_", token.path);
|
|
280
|
+
return pathStartsWithOneOf(["size", "_size"], token) && !(isUwantedToken || isPrivateToken);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
],
|
|
284
|
+
options: {
|
|
285
|
+
outputReferences: (token, options) => {
|
|
286
|
+
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && (isDigit(token.path[1]) || token.path[1] === "unit");
|
|
287
|
+
return isWantedSize && outputReferencesFilter(token, options);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/tokens/process/configs/size-mode.ts
|
|
296
|
+
import * as R5 from "ramda";
|
|
297
|
+
var sizeModeVariables = ({ theme, size: size2 }) => {
|
|
298
|
+
const selector = `:root`;
|
|
299
|
+
const layer = `ds.theme.size-mode`;
|
|
300
|
+
return {
|
|
301
|
+
preprocessors: ["tokens-studio"],
|
|
302
|
+
platforms: {
|
|
303
|
+
css: {
|
|
304
|
+
// custom
|
|
305
|
+
size: size2,
|
|
306
|
+
theme,
|
|
307
|
+
basePxFontSize,
|
|
308
|
+
selector,
|
|
309
|
+
layer,
|
|
310
|
+
//
|
|
311
|
+
prefix,
|
|
312
|
+
buildPath: `${theme}/`,
|
|
313
|
+
transforms: dsTransformers,
|
|
314
|
+
files: [
|
|
315
|
+
{
|
|
316
|
+
destination: `size-mode/${size2}.css`,
|
|
317
|
+
format: formats.sizeMode.name,
|
|
318
|
+
filter: (token) => {
|
|
319
|
+
return R5.equals(["_size", "mode-font-size"], token.path);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
]
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
// src/tokens/process/configs/type-scale.ts
|
|
329
|
+
var typeScaleVariables = ({ theme, size: size2 }) => {
|
|
330
|
+
const selector = ":root, [data-size]";
|
|
331
|
+
const layer = `ds.theme.type-scale`;
|
|
332
|
+
return {
|
|
333
|
+
usesDtcg: true,
|
|
334
|
+
preprocessors: ["tokens-studio"],
|
|
335
|
+
expand: {
|
|
336
|
+
include: ["typography"]
|
|
337
|
+
},
|
|
338
|
+
platforms: {
|
|
339
|
+
css: {
|
|
340
|
+
prefix,
|
|
341
|
+
selector,
|
|
342
|
+
layer,
|
|
343
|
+
buildPath: `${theme}/`,
|
|
344
|
+
basePxFontSize,
|
|
345
|
+
transforms: [
|
|
346
|
+
"name/kebab",
|
|
347
|
+
"ts/size/px",
|
|
348
|
+
sizeRem.name,
|
|
349
|
+
"ts/size/lineheight",
|
|
350
|
+
"ts/typography/fontWeight",
|
|
351
|
+
typographyName.name
|
|
352
|
+
],
|
|
353
|
+
files: [
|
|
354
|
+
{
|
|
355
|
+
destination: `type-scale.css`,
|
|
356
|
+
format: formats.typeScale.name,
|
|
357
|
+
filter: (token) => {
|
|
358
|
+
const included = typeEquals(["typography", "dimension", "fontsize"], token);
|
|
359
|
+
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
360
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "border-width", "border-radius"], token) && (pathStartsWithOneOf(["font-size"], token) || token.path.includes("fontSize"));
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
],
|
|
364
|
+
options: {
|
|
365
|
+
outputReferences: (token) => pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize")
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
};
|
|
370
|
+
};
|
|
371
|
+
|
|
230
372
|
// src/tokens/process/configs/typography.ts
|
|
231
373
|
import { expandTypesMap } from "@tokens-studio/sd-transforms";
|
|
232
374
|
var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
@@ -261,12 +403,9 @@ var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
|
261
403
|
destination: `typography/${typography2}.css`,
|
|
262
404
|
format: formats.typography.name,
|
|
263
405
|
filter: (token) => {
|
|
264
|
-
const included = typeEquals(
|
|
265
|
-
["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
|
|
266
|
-
token
|
|
267
|
-
);
|
|
406
|
+
const included = typeEquals(["fontweight", "fontFamily", "lineHeight", "dimension"], token);
|
|
268
407
|
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
269
|
-
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token);
|
|
408
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token) && !(pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize"));
|
|
270
409
|
}
|
|
271
410
|
}
|
|
272
411
|
]
|
|
@@ -441,9 +580,9 @@ var TypographyValues;
|
|
|
441
580
|
// src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
442
581
|
import { kebabCase } from "change-case";
|
|
443
582
|
import pc from "picocolors";
|
|
444
|
-
import * as
|
|
583
|
+
import * as R6 from "ramda";
|
|
445
584
|
var processed = Symbol("Type brand for ProcessedThemeObject");
|
|
446
|
-
var hasUnknownProps =
|
|
585
|
+
var hasUnknownProps = R6.pipe(R6.values, R6.none(R6.equals("unknown")), R6.not);
|
|
447
586
|
|
|
448
587
|
// src/tokens/process/configs.ts
|
|
449
588
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
@@ -463,7 +602,10 @@ var configs = {
|
|
|
463
602
|
dangerColorVariables: colorCategoryVariables({ category: "builtin", color: "danger" }),
|
|
464
603
|
warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
|
|
465
604
|
infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
|
|
605
|
+
sizeModeVariables,
|
|
606
|
+
sizeVariables,
|
|
466
607
|
typographyVariables,
|
|
608
|
+
typeScaleVariables,
|
|
467
609
|
semanticVariables
|
|
468
610
|
};
|
|
469
611
|
|
|
@@ -476,6 +618,9 @@ var buildOptions = {
|
|
|
476
618
|
var sd = new StyleDictionary2();
|
|
477
619
|
var buildConfigs = {
|
|
478
620
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
621
|
+
sizeMode: { getConfig: configs.sizeModeVariables, dimensions: ["size"] },
|
|
622
|
+
size: { getConfig: configs.sizeVariables, dimensions: ["semantic"] },
|
|
623
|
+
typeScale: { getConfig: configs.typeScaleVariables, dimensions: ["semantic"] },
|
|
479
624
|
"color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
|
|
480
625
|
"main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
|
|
481
626
|
"support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
|
|
@@ -530,8 +675,8 @@ var colorScheme = {
|
|
|
530
675
|
color-scheme: ${colorScheme_};
|
|
531
676
|
` : "";
|
|
532
677
|
const filteredAllTokens = allTokens.filter(
|
|
533
|
-
|
|
534
|
-
|
|
678
|
+
R9.allPass([
|
|
679
|
+
R9.anyPass([
|
|
535
680
|
// Include semantic tokens in the output
|
|
536
681
|
isSemanticToken,
|
|
537
682
|
// Include global color tokens
|
|
@@ -545,13 +690,13 @@ var colorScheme = {
|
|
|
545
690
|
token,
|
|
546
691
|
formatted: format(token)
|
|
547
692
|
}));
|
|
548
|
-
const formattedTokens = formattedMap.map(
|
|
693
|
+
const formattedTokens = formattedMap.map(R9.view(R9.lensProp("formatted"))).join("\n");
|
|
549
694
|
const content = `{
|
|
550
695
|
${formattedTokens}
|
|
551
696
|
${colorSchemeProperty}}
|
|
552
697
|
`;
|
|
553
698
|
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
554
|
-
const body =
|
|
699
|
+
const body = R9.isNotNil(layer) ? `@layer ${layer} {
|
|
555
700
|
${selector} ${content} ${autoSelectorContent}
|
|
556
701
|
}
|
|
557
702
|
` : `${selector} ${content} ${autoSelectorContent}
|
|
@@ -561,11 +706,11 @@ ${selector} ${content} ${autoSelectorContent}
|
|
|
561
706
|
};
|
|
562
707
|
var colorCategory = {
|
|
563
708
|
name: "ds/css-colorcategory",
|
|
564
|
-
format: async ({ dictionary, options, platform }) => {
|
|
709
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
565
710
|
const { outputReferences, usesDtcg } = options;
|
|
566
|
-
const { selector, layer
|
|
567
|
-
const destination =
|
|
568
|
-
const format =
|
|
711
|
+
const { selector, layer } = platform;
|
|
712
|
+
const destination = file.destination;
|
|
713
|
+
const format = R9.compose(
|
|
569
714
|
createPropertyFormatter({
|
|
570
715
|
outputReferences,
|
|
571
716
|
dictionary,
|
|
@@ -586,12 +731,12 @@ var colorCategory = {
|
|
|
586
731
|
formatted: format(token)
|
|
587
732
|
}));
|
|
588
733
|
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
589
|
-
const formattedTokens = formattedMap.map(
|
|
734
|
+
const formattedTokens = formattedMap.map(R9.view(R9.lensProp("formatted"))).join("\n");
|
|
590
735
|
const content = `{
|
|
591
736
|
${formattedTokens}
|
|
592
737
|
}
|
|
593
738
|
`;
|
|
594
|
-
const body =
|
|
739
|
+
const body = R9.isNotNil(layer) ? `@layer ${layer} {
|
|
595
740
|
${selector} ${content}
|
|
596
741
|
}
|
|
597
742
|
` : `${selector} ${content}
|
|
@@ -601,23 +746,35 @@ ${selector} ${content}
|
|
|
601
746
|
};
|
|
602
747
|
|
|
603
748
|
// src/tokens/process/formats/css/semantic.ts
|
|
604
|
-
import * as
|
|
749
|
+
import * as R11 from "ramda";
|
|
750
|
+
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
751
|
+
|
|
752
|
+
// src/tokens/process/formats/css/size.ts
|
|
753
|
+
import * as R10 from "ramda";
|
|
605
754
|
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
606
755
|
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
607
756
|
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
608
757
|
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
609
|
-
var isInlineTokens =
|
|
758
|
+
var isInlineTokens = R10.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
610
759
|
var overrideSizingFormula = (format, token) => {
|
|
611
|
-
const [name, value] = format(token).split(":");
|
|
612
|
-
|
|
613
|
-
|
|
760
|
+
const [name, value] = format(token).replace(/;$/, "").split(": ");
|
|
761
|
+
let calc;
|
|
762
|
+
let round;
|
|
763
|
+
if (token.path[1] === "unit") {
|
|
764
|
+
calc = `calc(1rem * ${value})`;
|
|
765
|
+
} else if (value.startsWith("floor")) {
|
|
766
|
+
calc = value.replace(/^floor\((.*)\)$/, "calc($1)");
|
|
767
|
+
round = `round(down, ${calc}, 1px)`;
|
|
768
|
+
} else {
|
|
769
|
+
calc = value.includes("*") ? `calc(${value})` : value;
|
|
770
|
+
}
|
|
614
771
|
return {
|
|
615
772
|
name,
|
|
616
|
-
round,
|
|
773
|
+
round: round ?? calc,
|
|
617
774
|
calc
|
|
618
775
|
};
|
|
619
776
|
};
|
|
620
|
-
var formatSizingTokens = (format, tokens) =>
|
|
777
|
+
var formatSizingTokens = (format, tokens) => R10.reduce(
|
|
621
778
|
(acc, token) => {
|
|
622
779
|
const { round, calc, name } = overrideSizingFormula(format, token);
|
|
623
780
|
return {
|
|
@@ -629,18 +786,21 @@ var formatSizingTokens = (format, tokens) => R8.reduce(
|
|
|
629
786
|
{ tokens: [], round: [], calc: [] },
|
|
630
787
|
tokens
|
|
631
788
|
);
|
|
632
|
-
var sizingTemplate = ({ round, calc }) =>
|
|
789
|
+
var sizingTemplate = ({ round, calc }) => {
|
|
790
|
+
const usesRounding = round.filter((val, i) => val !== calc[i]);
|
|
791
|
+
return `
|
|
633
792
|
${calc.join("\n")}
|
|
634
793
|
|
|
635
794
|
@supports (width: round(down, .1em, 1px)) {
|
|
636
|
-
${
|
|
795
|
+
${usesRounding.join("\n ")}
|
|
637
796
|
}`;
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
797
|
+
};
|
|
798
|
+
var size = {
|
|
799
|
+
name: "ds/css-size",
|
|
800
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
641
801
|
const { outputReferences, usesDtcg } = options;
|
|
642
|
-
const { selector, layer
|
|
643
|
-
const destination =
|
|
802
|
+
const { selector, layer } = platform;
|
|
803
|
+
const destination = file.destination;
|
|
644
804
|
const format = createPropertyFormatter2({
|
|
645
805
|
outputReferences,
|
|
646
806
|
dictionary,
|
|
@@ -648,9 +808,9 @@ var semantic = {
|
|
|
648
808
|
usesDtcg
|
|
649
809
|
});
|
|
650
810
|
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
651
|
-
const filteredTokens =
|
|
652
|
-
const [sizingTokens, restTokens] =
|
|
653
|
-
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
811
|
+
const filteredTokens = R10.reject((token) => R10.equals(["_size", "mode-font-size"], token.path), tokens);
|
|
812
|
+
const [sizingTokens, restTokens] = R10.partition(
|
|
813
|
+
(t) => pathStartsWithOneOf(["_size"], t) && (isDigit(t.path[1]) || t.path[1] === "unit"),
|
|
654
814
|
filteredTokens
|
|
655
815
|
);
|
|
656
816
|
const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
|
|
@@ -663,51 +823,186 @@ var semantic = {
|
|
|
663
823
|
formatted: t
|
|
664
824
|
}));
|
|
665
825
|
buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
|
|
666
|
-
const
|
|
667
|
-
const
|
|
668
|
-
const content = `{
|
|
826
|
+
const formattedTokens = [formattedMap.map(R10.prop("formatted")).join("\n"), sizingTemplate(formattedSizingTokens)];
|
|
827
|
+
const content = `${selector} {
|
|
669
828
|
${formattedTokens.join("\n")}
|
|
670
829
|
}
|
|
671
830
|
`;
|
|
672
|
-
const body =
|
|
673
|
-
${
|
|
831
|
+
const body = R10.isNotNil(layer) ? `@layer ${layer} {
|
|
832
|
+
${content}
|
|
674
833
|
}
|
|
675
|
-
` : `${
|
|
834
|
+
` : `${content}
|
|
676
835
|
`;
|
|
677
836
|
return body;
|
|
678
837
|
}
|
|
679
838
|
};
|
|
680
839
|
|
|
840
|
+
// src/tokens/process/formats/css/semantic.ts
|
|
841
|
+
var semantic = {
|
|
842
|
+
name: "ds/css-semantic",
|
|
843
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
844
|
+
const { outputReferences, usesDtcg } = options;
|
|
845
|
+
const { selector, layer } = platform;
|
|
846
|
+
const destination = file.destination;
|
|
847
|
+
const format = createPropertyFormatter3({
|
|
848
|
+
outputReferences,
|
|
849
|
+
dictionary,
|
|
850
|
+
format: "css",
|
|
851
|
+
usesDtcg
|
|
852
|
+
});
|
|
853
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
854
|
+
const formattedMap = tokens.map((token) => ({
|
|
855
|
+
token,
|
|
856
|
+
formatted: format(token)
|
|
857
|
+
}));
|
|
858
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
859
|
+
const formattedTokens = formattedMap.map(R11.prop("formatted")).join("\n");
|
|
860
|
+
const content = `${selector} {
|
|
861
|
+
${formattedTokens}
|
|
862
|
+
}
|
|
863
|
+
`;
|
|
864
|
+
const body = R11.isNotNil(layer) ? `@layer ${layer} {
|
|
865
|
+
${content}
|
|
866
|
+
}
|
|
867
|
+
` : `${content}
|
|
868
|
+
`;
|
|
869
|
+
return body;
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
|
|
873
|
+
// src/tokens/process/formats/css/size-mode.ts
|
|
874
|
+
import * as R12 from "ramda";
|
|
875
|
+
import { createPropertyFormatter as createPropertyFormatter4 } from "style-dictionary/utils";
|
|
876
|
+
var formatBaseSizeToken = (size2) => (token) => ({
|
|
877
|
+
...token,
|
|
878
|
+
originalName: token.name,
|
|
879
|
+
name: `${token.name}--${shortSizeName(size2)}`,
|
|
880
|
+
$value: token.$value / basePxFontSize
|
|
881
|
+
});
|
|
882
|
+
var sizeMode = {
|
|
883
|
+
name: "ds/css-size-mode",
|
|
884
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
885
|
+
const { outputReferences, usesDtcg } = options;
|
|
886
|
+
const { selector, layer, size: size2 } = platform;
|
|
887
|
+
const destination = file.destination;
|
|
888
|
+
const format = createPropertyFormatter4({
|
|
889
|
+
outputReferences,
|
|
890
|
+
dictionary,
|
|
891
|
+
format: "css",
|
|
892
|
+
usesDtcg
|
|
893
|
+
});
|
|
894
|
+
const sizeSpecificTokens = dictionary.allTokens.map(formatBaseSizeToken(size2));
|
|
895
|
+
const sizeSpecificVariables = sizeSpecificTokens.map(format).join("\n");
|
|
896
|
+
const formattedMap = sizeSpecificTokens.map((token) => ({
|
|
897
|
+
token,
|
|
898
|
+
formatted: format({
|
|
899
|
+
...token,
|
|
900
|
+
// Remove the `--<size>` suffix for the token listing, since that is the only token we actually use
|
|
901
|
+
name: token.originalName
|
|
902
|
+
})
|
|
903
|
+
}));
|
|
904
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
905
|
+
const content = `${selector} /* ${size2} */ {
|
|
906
|
+
${sizeSpecificVariables}
|
|
907
|
+
}`;
|
|
908
|
+
const body = wrapInLayer(content, layer);
|
|
909
|
+
const sizes = orderBySize(buildOptions?.sizeModes ?? []).map(shortSizeName);
|
|
910
|
+
const defaultSize = shortSizeName(buildOptions?.defaultSize ?? "");
|
|
911
|
+
const sizingToggles = `:root, [data-size] {
|
|
912
|
+
--ds-size: var(--ds-size--${defaultSize});
|
|
913
|
+
${sizes.map((size3) => ` --ds-size--${size3}: var(--ds-size,);`).join("\n")}
|
|
914
|
+
--ds-size-mode-font-size:
|
|
915
|
+
${sizes.map((size3) => ` var(--ds-size--${size3}, var(--ds-size-mode-font-size--${size3}))`).join("\n")};
|
|
916
|
+
}`;
|
|
917
|
+
const sizingHelpers = sizes.map((size3) => `[data-size='${size3}'] { --ds-size: var(--ds-size--${size3}); }`).join("\n");
|
|
918
|
+
const sharedContent = `${sizingToggles}
|
|
919
|
+
|
|
920
|
+
${sizingHelpers}`;
|
|
921
|
+
const sharedBody = shortSizeName(size2) === R12.last(sizes) ? `
|
|
922
|
+
${wrapInLayer(sharedContent, layer)}` : "";
|
|
923
|
+
return body + sharedBody;
|
|
924
|
+
}
|
|
925
|
+
};
|
|
926
|
+
function wrapInLayer(content, layer) {
|
|
927
|
+
return R12.isNotNil(layer) ? `@layer ${layer} {
|
|
928
|
+
${content}
|
|
929
|
+
}
|
|
930
|
+
` : `${content}
|
|
931
|
+
`;
|
|
932
|
+
}
|
|
933
|
+
|
|
681
934
|
// src/tokens/process/formats/css/typography.ts
|
|
682
|
-
import * as
|
|
683
|
-
import { createPropertyFormatter as
|
|
684
|
-
var typographyFontFamilyPredicate =
|
|
685
|
-
|
|
686
|
-
|
|
935
|
+
import * as R13 from "ramda";
|
|
936
|
+
import { createPropertyFormatter as createPropertyFormatter5 } from "style-dictionary/utils";
|
|
937
|
+
var typographyFontFamilyPredicate = R13.allPass([
|
|
938
|
+
R13.pathSatisfies(R13.includes("typography"), ["path"]),
|
|
939
|
+
R13.pathSatisfies(R13.includes("fontFamily"), ["path"])
|
|
687
940
|
]);
|
|
688
941
|
var typography = {
|
|
689
942
|
name: "ds/css-typography",
|
|
690
|
-
format: async ({ dictionary, options, platform }) => {
|
|
943
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
691
944
|
const { outputReferences, usesDtcg } = options;
|
|
692
|
-
const { selector, layer
|
|
693
|
-
const destination =
|
|
694
|
-
const format =
|
|
945
|
+
const { selector, layer } = platform;
|
|
946
|
+
const destination = file.destination;
|
|
947
|
+
const format = createPropertyFormatter5({
|
|
695
948
|
outputReferences,
|
|
696
949
|
dictionary,
|
|
697
950
|
format: "css",
|
|
698
951
|
usesDtcg
|
|
699
952
|
});
|
|
700
|
-
const filteredTokens =
|
|
953
|
+
const filteredTokens = R13.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
701
954
|
const formattedMap = filteredTokens.map((token) => ({
|
|
702
955
|
token,
|
|
703
956
|
formatted: format(token)
|
|
704
957
|
}));
|
|
705
958
|
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
706
|
-
const formattedTokens = formattedMap.map(
|
|
959
|
+
const formattedTokens = formattedMap.map(R13.view(R13.lensProp("formatted"))).join("\n");
|
|
707
960
|
const content = selector ? `${selector} {
|
|
708
961
|
${formattedTokens}
|
|
709
962
|
}` : formattedTokens;
|
|
710
|
-
const body =
|
|
963
|
+
const body = R13.isNotNil(layer) ? `@layer ${layer} {
|
|
964
|
+
${content}
|
|
965
|
+
}` : content;
|
|
966
|
+
return body;
|
|
967
|
+
}
|
|
968
|
+
};
|
|
969
|
+
|
|
970
|
+
// src/tokens/process/formats/css/type-scale.ts
|
|
971
|
+
import * as R14 from "ramda";
|
|
972
|
+
import { createPropertyFormatter as createPropertyFormatter6 } from "style-dictionary/utils";
|
|
973
|
+
var typographyFontFamilyPredicate2 = R14.allPass([
|
|
974
|
+
R14.pathSatisfies(R14.includes("typography"), ["path"]),
|
|
975
|
+
R14.pathSatisfies(R14.includes("fontFamily"), ["path"])
|
|
976
|
+
]);
|
|
977
|
+
function formatTypographySizeToken(token) {
|
|
978
|
+
return { ...token, $value: `calc(${token.$value} * var(--_ds-font-size-factor))` };
|
|
979
|
+
}
|
|
980
|
+
var typeScale = {
|
|
981
|
+
name: "ds/css-type-scale",
|
|
982
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
983
|
+
const { outputReferences, usesDtcg } = options;
|
|
984
|
+
const { selector, layer } = platform;
|
|
985
|
+
const destination = file.destination;
|
|
986
|
+
const format = createPropertyFormatter6({
|
|
987
|
+
outputReferences,
|
|
988
|
+
dictionary,
|
|
989
|
+
format: "css",
|
|
990
|
+
usesDtcg
|
|
991
|
+
});
|
|
992
|
+
const filteredTokens = R14.reject(typographyFontFamilyPredicate2, dictionary.allTokens);
|
|
993
|
+
const tokens = R14.map(formatTypographySizeToken, filteredTokens);
|
|
994
|
+
const formattedMap = tokens.map((token) => ({
|
|
995
|
+
token,
|
|
996
|
+
formatted: format(token)
|
|
997
|
+
}));
|
|
998
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
999
|
+
const formattedTokens = formattedMap.map(R14.prop("formatted")).join("\n");
|
|
1000
|
+
const sizeFactor = ` --_ds-font-size-factor: calc(var(--ds-size-mode-font-size) / (var(--ds-size-base) / ${basePxFontSize}));`;
|
|
1001
|
+
const content = `${selector} {
|
|
1002
|
+
${sizeFactor}
|
|
1003
|
+
${formattedTokens}
|
|
1004
|
+
}`;
|
|
1005
|
+
const body = R14.isNotNil(layer) ? `@layer ${layer} {
|
|
711
1006
|
${content}
|
|
712
1007
|
}` : content;
|
|
713
1008
|
return body;
|
|
@@ -719,7 +1014,10 @@ var formats = {
|
|
|
719
1014
|
colorScheme,
|
|
720
1015
|
colorCategory,
|
|
721
1016
|
semantic,
|
|
722
|
-
|
|
1017
|
+
sizeMode,
|
|
1018
|
+
size,
|
|
1019
|
+
typography,
|
|
1020
|
+
typeScale
|
|
723
1021
|
};
|
|
724
1022
|
|
|
725
1023
|
// src/tokens/process/configs/semantic.ts
|
|
@@ -744,9 +1042,12 @@ var semanticVariables = ({ theme }) => {
|
|
|
744
1042
|
destination: `semantic.css`,
|
|
745
1043
|
format: formats.semantic.name,
|
|
746
1044
|
filter: (token) => {
|
|
747
|
-
const isUwantedToken =
|
|
748
|
-
const isPrivateToken =
|
|
749
|
-
const unwantedPaths = pathStartsWithOneOf(
|
|
1045
|
+
const isUwantedToken = R15.anyPass([R15.includes("primitives/global")])(token.filePath);
|
|
1046
|
+
const isPrivateToken = R15.includes("_", token.path);
|
|
1047
|
+
const unwantedPaths = pathStartsWithOneOf(
|
|
1048
|
+
["size", "_size", "font-size", "line-height", "letter-spacing"],
|
|
1049
|
+
token
|
|
1050
|
+
);
|
|
750
1051
|
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
751
1052
|
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
752
1053
|
return unwantedTokens;
|
|
@@ -756,8 +1057,7 @@ var semanticVariables = ({ theme }) => {
|
|
|
756
1057
|
options: {
|
|
757
1058
|
outputReferences: (token, options) => {
|
|
758
1059
|
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
759
|
-
|
|
760
|
-
return (include || isWantedSize) && outputReferencesFilter(token, options);
|
|
1060
|
+
return include && outputReferencesFilter2(token, options);
|
|
761
1061
|
}
|
|
762
1062
|
}
|
|
763
1063
|
}
|
|
@@ -22,7 +22,10 @@ var pathStartsWithOneOf = R.curry(
|
|
|
22
22
|
return false;
|
|
23
23
|
}
|
|
24
24
|
const tokenPath = mapToLowerCase(token.path);
|
|
25
|
-
const matchPathsStartingWith = R.map((
|
|
25
|
+
const matchPathsStartingWith = R.map((pathOrString) => {
|
|
26
|
+
const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
|
|
27
|
+
return R.startsWith(mapToLowerCase(path), tokenPath);
|
|
28
|
+
}, paths);
|
|
26
29
|
return hasAnyTruth(matchPathsStartingWith);
|
|
27
30
|
}
|
|
28
31
|
);
|
|
@@ -35,7 +38,11 @@ var sizeRem = {
|
|
|
35
38
|
transitive: true,
|
|
36
39
|
filter: (token) => {
|
|
37
40
|
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
38
|
-
const hasWantedPath = pathStartsWithOneOf([
|
|
41
|
+
const hasWantedPath = pathStartsWithOneOf([
|
|
42
|
+
"border-radius",
|
|
43
|
+
"font-size"
|
|
44
|
+
/*, ['_size', 'mode-font-size']*/
|
|
45
|
+
], token);
|
|
39
46
|
return hasWantedType && hasWantedPath;
|
|
40
47
|
},
|
|
41
48
|
transform: (token, config) => {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size-mode.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/size-mode.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkC,KAAK,wBAAwB,EAAU,MAAM,aAAa,CAAC;AAEpG,eAAO,MAAM,iBAAiB,EAAE,wBA8B/B,CAAC"}
|