@digdir/designsystemet 1.4.0 → 1.5.1
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 +485 -163
- package/dist/global-Y35YADVH.json +100 -0
- package/dist/src/index.js +524 -200
- package/dist/src/scripts/update-preview-tokens.js +429 -118
- package/dist/src/tokens/build.js +426 -108
- package/dist/src/tokens/create/defaults.js +27 -23
- package/dist/src/tokens/create/generators/$designsystemet.js +3 -3
- package/dist/src/tokens/create/write.js +3 -3
- package/dist/src/tokens/create.js +27 -23
- package/dist/src/tokens/format.js +524 -200
- package/dist/src/tokens/index.js +524 -200
- 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 +373 -71
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -1
- package/dist/src/tokens/process/output/theme.js +60 -11
- 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 +3 -3
- package/dist/global-XVXVBKM6.json +0 -96
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/tokens/process/formats/css/color.ts
|
|
2
|
-
import * as
|
|
2
|
+
import * as R10 from "ramda";
|
|
3
3
|
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
4
4
|
|
|
5
5
|
// src/tokens/types.ts
|
|
@@ -28,7 +28,10 @@ var pathStartsWithOneOf = R.curry(
|
|
|
28
28
|
return false;
|
|
29
29
|
}
|
|
30
30
|
const tokenPath = mapToLowerCase(token.path);
|
|
31
|
-
const matchPathsStartingWith = R.map((
|
|
31
|
+
const matchPathsStartingWith = R.map((pathOrString) => {
|
|
32
|
+
const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
|
|
33
|
+
return R.startsWith(mapToLowerCase(path), tokenPath);
|
|
34
|
+
}, paths);
|
|
32
35
|
return hasAnyTruth(matchPathsStartingWith);
|
|
33
36
|
}
|
|
34
37
|
);
|
|
@@ -64,15 +67,32 @@ function inlineTokens(shouldInline, tokens) {
|
|
|
64
67
|
return tokenWithInlinedRefs;
|
|
65
68
|
});
|
|
66
69
|
}
|
|
70
|
+
var sizeMap = {
|
|
71
|
+
xsmall: "xs",
|
|
72
|
+
small: "sm",
|
|
73
|
+
medium: "md",
|
|
74
|
+
large: "lg",
|
|
75
|
+
xlarge: "xl"
|
|
76
|
+
};
|
|
77
|
+
function shortSizeName(size2) {
|
|
78
|
+
return sizeMap[size2] ?? size2;
|
|
79
|
+
}
|
|
80
|
+
var sizeComparator = (size2) => {
|
|
81
|
+
const sortIndex = Object.entries(sizeMap).findIndex(([key, val]) => key === size2 || val === size2);
|
|
82
|
+
return sortIndex ?? 0;
|
|
83
|
+
};
|
|
84
|
+
function orderBySize(sizes) {
|
|
85
|
+
return R.sortBy(sizeComparator, sizes);
|
|
86
|
+
}
|
|
67
87
|
|
|
68
88
|
// src/tokens/process/platform.ts
|
|
69
89
|
import pc2 from "picocolors";
|
|
70
|
-
import * as
|
|
90
|
+
import * as R9 from "ramda";
|
|
71
91
|
import StyleDictionary2 from "style-dictionary";
|
|
72
92
|
|
|
73
93
|
// src/tokens/process/configs.ts
|
|
74
94
|
import { register } from "@tokens-studio/sd-transforms";
|
|
75
|
-
import * as
|
|
95
|
+
import * as R8 from "ramda";
|
|
76
96
|
import StyleDictionary from "style-dictionary";
|
|
77
97
|
|
|
78
98
|
// src/tokens/process/configs/color.ts
|
|
@@ -88,18 +108,22 @@ var sizeRem = {
|
|
|
88
108
|
transitive: true,
|
|
89
109
|
filter: (token) => {
|
|
90
110
|
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
91
|
-
const hasWantedPath = pathStartsWithOneOf([
|
|
111
|
+
const hasWantedPath = pathStartsWithOneOf([
|
|
112
|
+
"border-radius",
|
|
113
|
+
"font-size"
|
|
114
|
+
/*, ['_size', 'mode-font-size']*/
|
|
115
|
+
], token);
|
|
92
116
|
return hasWantedType && hasWantedPath;
|
|
93
117
|
},
|
|
94
118
|
transform: (token, config) => {
|
|
95
119
|
const value = getValue(token);
|
|
96
120
|
if (isPx(value)) {
|
|
97
121
|
const baseFont = config.basePxFontSize || 16;
|
|
98
|
-
const
|
|
99
|
-
if (
|
|
122
|
+
const size2 = parseInt(value, 10);
|
|
123
|
+
if (size2 === 0) {
|
|
100
124
|
return "0";
|
|
101
125
|
}
|
|
102
|
-
return `${
|
|
126
|
+
return `${size2 / baseFont}rem`;
|
|
103
127
|
}
|
|
104
128
|
return value;
|
|
105
129
|
}
|
|
@@ -247,7 +271,10 @@ var semanticVariables = ({ theme }) => {
|
|
|
247
271
|
filter: (token) => {
|
|
248
272
|
const isUwantedToken = R4.anyPass([R4.includes("primitives/global")])(token.filePath);
|
|
249
273
|
const isPrivateToken = R4.includes("_", token.path);
|
|
250
|
-
const unwantedPaths = pathStartsWithOneOf(
|
|
274
|
+
const unwantedPaths = pathStartsWithOneOf(
|
|
275
|
+
["size", "_size", "font-size", "line-height", "letter-spacing"],
|
|
276
|
+
token
|
|
277
|
+
);
|
|
251
278
|
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
252
279
|
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
253
280
|
return unwantedTokens;
|
|
@@ -257,8 +284,48 @@ var semanticVariables = ({ theme }) => {
|
|
|
257
284
|
options: {
|
|
258
285
|
outputReferences: (token, options) => {
|
|
259
286
|
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
260
|
-
|
|
261
|
-
|
|
287
|
+
return include && outputReferencesFilter(token, options);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
// src/tokens/process/configs/size.ts
|
|
296
|
+
import * as R5 from "ramda";
|
|
297
|
+
import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
|
|
298
|
+
var sizeVariables = ({ theme }) => {
|
|
299
|
+
const selector = `:root, [data-size]`;
|
|
300
|
+
const layer = `ds.theme.size`;
|
|
301
|
+
return {
|
|
302
|
+
preprocessors: ["tokens-studio"],
|
|
303
|
+
platforms: {
|
|
304
|
+
css: {
|
|
305
|
+
// custom
|
|
306
|
+
theme,
|
|
307
|
+
basePxFontSize,
|
|
308
|
+
selector,
|
|
309
|
+
layer,
|
|
310
|
+
//
|
|
311
|
+
prefix,
|
|
312
|
+
buildPath: `${theme}/`,
|
|
313
|
+
transforms: dsTransformers,
|
|
314
|
+
files: [
|
|
315
|
+
{
|
|
316
|
+
destination: `size.css`,
|
|
317
|
+
format: formats.size.name,
|
|
318
|
+
filter: (token) => {
|
|
319
|
+
const isUwantedToken = R5.anyPass([R5.includes("primitives/global")])(token.filePath);
|
|
320
|
+
const isPrivateToken = R5.includes("_", token.path);
|
|
321
|
+
return pathStartsWithOneOf(["size", "_size"], token) && !(isUwantedToken || isPrivateToken);
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
],
|
|
325
|
+
options: {
|
|
326
|
+
outputReferences: (token, options) => {
|
|
327
|
+
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && (isDigit(token.path[1]) || token.path[1] === "unit");
|
|
328
|
+
return isWantedSize && outputReferencesFilter2(token, options);
|
|
262
329
|
}
|
|
263
330
|
}
|
|
264
331
|
}
|
|
@@ -266,6 +333,83 @@ var semanticVariables = ({ theme }) => {
|
|
|
266
333
|
};
|
|
267
334
|
};
|
|
268
335
|
|
|
336
|
+
// src/tokens/process/configs/size-mode.ts
|
|
337
|
+
import * as R6 from "ramda";
|
|
338
|
+
var sizeModeVariables = ({ theme, size: size2 }) => {
|
|
339
|
+
const selector = `:root`;
|
|
340
|
+
const layer = `ds.theme.size-mode`;
|
|
341
|
+
return {
|
|
342
|
+
preprocessors: ["tokens-studio"],
|
|
343
|
+
platforms: {
|
|
344
|
+
css: {
|
|
345
|
+
// custom
|
|
346
|
+
size: size2,
|
|
347
|
+
theme,
|
|
348
|
+
basePxFontSize,
|
|
349
|
+
selector,
|
|
350
|
+
layer,
|
|
351
|
+
//
|
|
352
|
+
prefix,
|
|
353
|
+
buildPath: `${theme}/`,
|
|
354
|
+
transforms: dsTransformers,
|
|
355
|
+
files: [
|
|
356
|
+
{
|
|
357
|
+
destination: `size-mode/${size2}.css`,
|
|
358
|
+
format: formats.sizeMode.name,
|
|
359
|
+
filter: (token) => {
|
|
360
|
+
return R6.equals(["_size", "mode-font-size"], token.path);
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
]
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
};
|
|
367
|
+
};
|
|
368
|
+
|
|
369
|
+
// src/tokens/process/configs/type-scale.ts
|
|
370
|
+
var typeScaleVariables = ({ theme }) => {
|
|
371
|
+
const selector = ":root, [data-size]";
|
|
372
|
+
const layer = `ds.theme.type-scale`;
|
|
373
|
+
return {
|
|
374
|
+
usesDtcg: true,
|
|
375
|
+
preprocessors: ["tokens-studio"],
|
|
376
|
+
expand: {
|
|
377
|
+
include: ["typography"]
|
|
378
|
+
},
|
|
379
|
+
platforms: {
|
|
380
|
+
css: {
|
|
381
|
+
prefix,
|
|
382
|
+
selector,
|
|
383
|
+
layer,
|
|
384
|
+
buildPath: `${theme}/`,
|
|
385
|
+
basePxFontSize,
|
|
386
|
+
transforms: [
|
|
387
|
+
"name/kebab",
|
|
388
|
+
"ts/size/px",
|
|
389
|
+
sizeRem.name,
|
|
390
|
+
"ts/size/lineheight",
|
|
391
|
+
"ts/typography/fontWeight",
|
|
392
|
+
typographyName.name
|
|
393
|
+
],
|
|
394
|
+
files: [
|
|
395
|
+
{
|
|
396
|
+
destination: `type-scale.css`,
|
|
397
|
+
format: formats.typeScale.name,
|
|
398
|
+
filter: (token) => {
|
|
399
|
+
const included = typeEquals(["typography", "dimension", "fontsize"], token);
|
|
400
|
+
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
401
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "border-width", "border-radius"], token) && (pathStartsWithOneOf(["font-size"], token) || token.path.includes("fontSize"));
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
],
|
|
405
|
+
options: {
|
|
406
|
+
outputReferences: (token) => pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize")
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
};
|
|
412
|
+
|
|
269
413
|
// src/tokens/process/configs/typography.ts
|
|
270
414
|
import { expandTypesMap } from "@tokens-studio/sd-transforms";
|
|
271
415
|
var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
@@ -300,12 +444,9 @@ var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
|
300
444
|
destination: `typography/${typography2}.css`,
|
|
301
445
|
format: formats.typography.name,
|
|
302
446
|
filter: (token) => {
|
|
303
|
-
const included = typeEquals(
|
|
304
|
-
["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
|
|
305
|
-
token
|
|
306
|
-
);
|
|
447
|
+
const included = typeEquals(["fontweight", "fontFamily", "lineHeight", "dimension"], token);
|
|
307
448
|
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
308
|
-
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token);
|
|
449
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token) && !(pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize"));
|
|
309
450
|
}
|
|
310
451
|
}
|
|
311
452
|
]
|
|
@@ -480,9 +621,9 @@ var TypographyValues;
|
|
|
480
621
|
// src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
481
622
|
import { kebabCase } from "change-case";
|
|
482
623
|
import pc from "picocolors";
|
|
483
|
-
import * as
|
|
624
|
+
import * as R7 from "ramda";
|
|
484
625
|
var processed = Symbol("Type brand for ProcessedThemeObject");
|
|
485
|
-
var hasUnknownProps =
|
|
626
|
+
var hasUnknownProps = R7.pipe(R7.values, R7.none(R7.equals("unknown")), R7.not);
|
|
486
627
|
|
|
487
628
|
// src/tokens/process/configs.ts
|
|
488
629
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
@@ -502,7 +643,10 @@ var configs = {
|
|
|
502
643
|
dangerColorVariables: colorCategoryVariables({ category: "builtin", color: "danger" }),
|
|
503
644
|
warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
|
|
504
645
|
infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
|
|
646
|
+
sizeModeVariables,
|
|
647
|
+
sizeVariables,
|
|
505
648
|
typographyVariables,
|
|
649
|
+
typeScaleVariables,
|
|
506
650
|
semanticVariables
|
|
507
651
|
};
|
|
508
652
|
|
|
@@ -515,6 +659,9 @@ var buildOptions = {
|
|
|
515
659
|
var sd = new StyleDictionary2();
|
|
516
660
|
var buildConfigs = {
|
|
517
661
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
662
|
+
sizeMode: { getConfig: configs.sizeModeVariables, dimensions: ["size"] },
|
|
663
|
+
size: { getConfig: configs.sizeVariables, dimensions: ["semantic"] },
|
|
664
|
+
typeScale: { getConfig: configs.typeScaleVariables, dimensions: ["semantic"] },
|
|
518
665
|
"color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
|
|
519
666
|
"main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
|
|
520
667
|
"support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
|
|
@@ -569,8 +716,8 @@ var colorScheme = {
|
|
|
569
716
|
color-scheme: ${colorScheme_};
|
|
570
717
|
` : "";
|
|
571
718
|
const filteredAllTokens = allTokens.filter(
|
|
572
|
-
|
|
573
|
-
|
|
719
|
+
R10.allPass([
|
|
720
|
+
R10.anyPass([
|
|
574
721
|
// Include semantic tokens in the output
|
|
575
722
|
isSemanticToken,
|
|
576
723
|
// Include global color tokens
|
|
@@ -584,13 +731,13 @@ var colorScheme = {
|
|
|
584
731
|
token,
|
|
585
732
|
formatted: format(token)
|
|
586
733
|
}));
|
|
587
|
-
const formattedTokens = formattedMap.map(
|
|
734
|
+
const formattedTokens = formattedMap.map(R10.view(R10.lensProp("formatted"))).join("\n");
|
|
588
735
|
const content = `{
|
|
589
736
|
${formattedTokens}
|
|
590
737
|
${colorSchemeProperty}}
|
|
591
738
|
`;
|
|
592
739
|
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
593
|
-
const body =
|
|
740
|
+
const body = R10.isNotNil(layer) ? `@layer ${layer} {
|
|
594
741
|
${selector} ${content} ${autoSelectorContent}
|
|
595
742
|
}
|
|
596
743
|
` : `${selector} ${content} ${autoSelectorContent}
|
|
@@ -600,11 +747,11 @@ ${selector} ${content} ${autoSelectorContent}
|
|
|
600
747
|
};
|
|
601
748
|
var colorCategory = {
|
|
602
749
|
name: "ds/css-colorcategory",
|
|
603
|
-
format: async ({ dictionary, options, platform }) => {
|
|
750
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
604
751
|
const { outputReferences, usesDtcg } = options;
|
|
605
|
-
const { selector, layer
|
|
606
|
-
const destination =
|
|
607
|
-
const format =
|
|
752
|
+
const { selector, layer } = platform;
|
|
753
|
+
const destination = file.destination;
|
|
754
|
+
const format = R10.compose(
|
|
608
755
|
createPropertyFormatter({
|
|
609
756
|
outputReferences,
|
|
610
757
|
dictionary,
|
|
@@ -625,12 +772,12 @@ var colorCategory = {
|
|
|
625
772
|
formatted: format(token)
|
|
626
773
|
}));
|
|
627
774
|
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
628
|
-
const formattedTokens = formattedMap.map(
|
|
775
|
+
const formattedTokens = formattedMap.map(R10.view(R10.lensProp("formatted"))).join("\n");
|
|
629
776
|
const content = `{
|
|
630
777
|
${formattedTokens}
|
|
631
778
|
}
|
|
632
779
|
`;
|
|
633
|
-
const body =
|
|
780
|
+
const body = R10.isNotNil(layer) ? `@layer ${layer} {
|
|
634
781
|
${selector} ${content}
|
|
635
782
|
}
|
|
636
783
|
` : `${selector} ${content}
|
|
@@ -640,23 +787,35 @@ ${selector} ${content}
|
|
|
640
787
|
};
|
|
641
788
|
|
|
642
789
|
// src/tokens/process/formats/css/semantic.ts
|
|
643
|
-
import * as
|
|
790
|
+
import * as R12 from "ramda";
|
|
791
|
+
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
792
|
+
|
|
793
|
+
// src/tokens/process/formats/css/size.ts
|
|
794
|
+
import * as R11 from "ramda";
|
|
644
795
|
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
645
796
|
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
646
797
|
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
647
798
|
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
648
|
-
var isInlineTokens =
|
|
799
|
+
var isInlineTokens = R11.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
649
800
|
var overrideSizingFormula = (format, token) => {
|
|
650
|
-
const [name, value] = format(token).split(":");
|
|
651
|
-
|
|
652
|
-
|
|
801
|
+
const [name, value] = format(token).replace(/;$/, "").split(": ");
|
|
802
|
+
let calc;
|
|
803
|
+
let round;
|
|
804
|
+
if (token.path[1] === "unit") {
|
|
805
|
+
calc = `calc(1rem * ${value})`;
|
|
806
|
+
} else if (value.startsWith("floor")) {
|
|
807
|
+
calc = value.replace(/^floor\((.*)\)$/, "calc($1)");
|
|
808
|
+
round = `round(down, ${calc}, 1px)`;
|
|
809
|
+
} else {
|
|
810
|
+
calc = value.includes("*") ? `calc(${value})` : value;
|
|
811
|
+
}
|
|
653
812
|
return {
|
|
654
813
|
name,
|
|
655
|
-
round,
|
|
814
|
+
round: round ?? calc,
|
|
656
815
|
calc
|
|
657
816
|
};
|
|
658
817
|
};
|
|
659
|
-
var formatSizingTokens = (format, tokens) =>
|
|
818
|
+
var formatSizingTokens = (format, tokens) => R11.reduce(
|
|
660
819
|
(acc, token) => {
|
|
661
820
|
const { round, calc, name } = overrideSizingFormula(format, token);
|
|
662
821
|
return {
|
|
@@ -668,18 +827,21 @@ var formatSizingTokens = (format, tokens) => R9.reduce(
|
|
|
668
827
|
{ tokens: [], round: [], calc: [] },
|
|
669
828
|
tokens
|
|
670
829
|
);
|
|
671
|
-
var sizingTemplate = ({ round, calc }) =>
|
|
830
|
+
var sizingTemplate = ({ round, calc }) => {
|
|
831
|
+
const usesRounding = round.filter((val, i) => val !== calc[i]);
|
|
832
|
+
return `
|
|
672
833
|
${calc.join("\n")}
|
|
673
834
|
|
|
674
835
|
@supports (width: round(down, .1em, 1px)) {
|
|
675
|
-
${
|
|
836
|
+
${usesRounding.join("\n ")}
|
|
676
837
|
}`;
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
838
|
+
};
|
|
839
|
+
var size = {
|
|
840
|
+
name: "ds/css-size",
|
|
841
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
680
842
|
const { outputReferences, usesDtcg } = options;
|
|
681
|
-
const { selector, layer
|
|
682
|
-
const destination =
|
|
843
|
+
const { selector, layer } = platform;
|
|
844
|
+
const destination = file.destination;
|
|
683
845
|
const format = createPropertyFormatter2({
|
|
684
846
|
outputReferences,
|
|
685
847
|
dictionary,
|
|
@@ -687,9 +849,9 @@ var semantic = {
|
|
|
687
849
|
usesDtcg
|
|
688
850
|
});
|
|
689
851
|
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
690
|
-
const filteredTokens =
|
|
691
|
-
const [sizingTokens, restTokens] =
|
|
692
|
-
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
852
|
+
const filteredTokens = R11.reject((token) => R11.equals(["_size", "mode-font-size"], token.path), tokens);
|
|
853
|
+
const [sizingTokens, restTokens] = R11.partition(
|
|
854
|
+
(t) => pathStartsWithOneOf(["_size"], t) && (isDigit(t.path[1]) || t.path[1] === "unit"),
|
|
693
855
|
filteredTokens
|
|
694
856
|
);
|
|
695
857
|
const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
|
|
@@ -702,51 +864,186 @@ var semantic = {
|
|
|
702
864
|
formatted: t
|
|
703
865
|
}));
|
|
704
866
|
buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
|
|
705
|
-
const
|
|
706
|
-
const
|
|
707
|
-
const content = `{
|
|
867
|
+
const formattedTokens = [formattedMap.map(R11.prop("formatted")).join("\n"), sizingTemplate(formattedSizingTokens)];
|
|
868
|
+
const content = `${selector} {
|
|
708
869
|
${formattedTokens.join("\n")}
|
|
709
870
|
}
|
|
710
871
|
`;
|
|
711
|
-
const body =
|
|
712
|
-
${
|
|
872
|
+
const body = R11.isNotNil(layer) ? `@layer ${layer} {
|
|
873
|
+
${content}
|
|
713
874
|
}
|
|
714
|
-
` : `${
|
|
875
|
+
` : `${content}
|
|
715
876
|
`;
|
|
716
877
|
return body;
|
|
717
878
|
}
|
|
718
879
|
};
|
|
719
880
|
|
|
881
|
+
// src/tokens/process/formats/css/semantic.ts
|
|
882
|
+
var semantic = {
|
|
883
|
+
name: "ds/css-semantic",
|
|
884
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
885
|
+
const { outputReferences, usesDtcg } = options;
|
|
886
|
+
const { selector, layer } = platform;
|
|
887
|
+
const destination = file.destination;
|
|
888
|
+
const format = createPropertyFormatter3({
|
|
889
|
+
outputReferences,
|
|
890
|
+
dictionary,
|
|
891
|
+
format: "css",
|
|
892
|
+
usesDtcg
|
|
893
|
+
});
|
|
894
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
895
|
+
const formattedMap = tokens.map((token) => ({
|
|
896
|
+
token,
|
|
897
|
+
formatted: format(token)
|
|
898
|
+
}));
|
|
899
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
900
|
+
const formattedTokens = formattedMap.map(R12.prop("formatted")).join("\n");
|
|
901
|
+
const content = `${selector} {
|
|
902
|
+
${formattedTokens}
|
|
903
|
+
}
|
|
904
|
+
`;
|
|
905
|
+
const body = R12.isNotNil(layer) ? `@layer ${layer} {
|
|
906
|
+
${content}
|
|
907
|
+
}
|
|
908
|
+
` : `${content}
|
|
909
|
+
`;
|
|
910
|
+
return body;
|
|
911
|
+
}
|
|
912
|
+
};
|
|
913
|
+
|
|
914
|
+
// src/tokens/process/formats/css/size-mode.ts
|
|
915
|
+
import * as R13 from "ramda";
|
|
916
|
+
import { createPropertyFormatter as createPropertyFormatter4 } from "style-dictionary/utils";
|
|
917
|
+
var formatBaseSizeToken = (size2) => (token) => ({
|
|
918
|
+
...token,
|
|
919
|
+
originalName: token.name,
|
|
920
|
+
name: `${token.name}--${shortSizeName(size2)}`,
|
|
921
|
+
$value: token.$value / basePxFontSize
|
|
922
|
+
});
|
|
923
|
+
var sizeMode = {
|
|
924
|
+
name: "ds/css-size-mode",
|
|
925
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
926
|
+
const { outputReferences, usesDtcg } = options;
|
|
927
|
+
const { selector, layer, size: size2 } = platform;
|
|
928
|
+
const destination = file.destination;
|
|
929
|
+
const format = createPropertyFormatter4({
|
|
930
|
+
outputReferences,
|
|
931
|
+
dictionary,
|
|
932
|
+
format: "css",
|
|
933
|
+
usesDtcg
|
|
934
|
+
});
|
|
935
|
+
const sizeSpecificTokens = dictionary.allTokens.map(formatBaseSizeToken(size2));
|
|
936
|
+
const sizeSpecificVariables = sizeSpecificTokens.map(format).join("\n");
|
|
937
|
+
const formattedMap = sizeSpecificTokens.map((token) => ({
|
|
938
|
+
token,
|
|
939
|
+
formatted: format({
|
|
940
|
+
...token,
|
|
941
|
+
// Remove the `--<size>` suffix for the token listing, since that is the only token we actually use
|
|
942
|
+
name: token.originalName
|
|
943
|
+
})
|
|
944
|
+
}));
|
|
945
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
946
|
+
const content = `${selector} /* ${size2} */ {
|
|
947
|
+
${sizeSpecificVariables}
|
|
948
|
+
}`;
|
|
949
|
+
const body = wrapInLayer(content, layer);
|
|
950
|
+
const sizes = orderBySize(buildOptions?.sizeModes ?? []).map(shortSizeName);
|
|
951
|
+
const defaultSize = shortSizeName(buildOptions?.defaultSize ?? "");
|
|
952
|
+
const sizingToggles = `:root, [data-size] {
|
|
953
|
+
--ds-size: var(--ds-size--${defaultSize});
|
|
954
|
+
${sizes.map((size3) => ` --ds-size--${size3}: var(--ds-size,);`).join("\n")}
|
|
955
|
+
--ds-size-mode-font-size:
|
|
956
|
+
${sizes.map((size3) => ` var(--ds-size--${size3}, var(--ds-size-mode-font-size--${size3}))`).join("\n")};
|
|
957
|
+
}`;
|
|
958
|
+
const sizingHelpers = sizes.map((size3) => `[data-size='${size3}'] { --ds-size: var(--ds-size--${size3}); }`).join("\n");
|
|
959
|
+
const sharedContent = `${sizingToggles}
|
|
960
|
+
|
|
961
|
+
${sizingHelpers}`;
|
|
962
|
+
const sharedBody = shortSizeName(size2) === R13.last(sizes) ? `
|
|
963
|
+
${wrapInLayer(sharedContent, layer)}` : "";
|
|
964
|
+
return body + sharedBody;
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
function wrapInLayer(content, layer) {
|
|
968
|
+
return R13.isNotNil(layer) ? `@layer ${layer} {
|
|
969
|
+
${content}
|
|
970
|
+
}
|
|
971
|
+
` : `${content}
|
|
972
|
+
`;
|
|
973
|
+
}
|
|
974
|
+
|
|
720
975
|
// src/tokens/process/formats/css/typography.ts
|
|
721
|
-
import * as
|
|
722
|
-
import { createPropertyFormatter as
|
|
723
|
-
var typographyFontFamilyPredicate =
|
|
724
|
-
|
|
725
|
-
|
|
976
|
+
import * as R14 from "ramda";
|
|
977
|
+
import { createPropertyFormatter as createPropertyFormatter5 } from "style-dictionary/utils";
|
|
978
|
+
var typographyFontFamilyPredicate = R14.allPass([
|
|
979
|
+
R14.pathSatisfies(R14.includes("typography"), ["path"]),
|
|
980
|
+
R14.pathSatisfies(R14.includes("fontFamily"), ["path"])
|
|
726
981
|
]);
|
|
727
982
|
var typography = {
|
|
728
983
|
name: "ds/css-typography",
|
|
729
|
-
format: async ({ dictionary, options, platform }) => {
|
|
984
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
730
985
|
const { outputReferences, usesDtcg } = options;
|
|
731
|
-
const { selector, layer
|
|
732
|
-
const destination =
|
|
733
|
-
const format =
|
|
986
|
+
const { selector, layer } = platform;
|
|
987
|
+
const destination = file.destination;
|
|
988
|
+
const format = createPropertyFormatter5({
|
|
734
989
|
outputReferences,
|
|
735
990
|
dictionary,
|
|
736
991
|
format: "css",
|
|
737
992
|
usesDtcg
|
|
738
993
|
});
|
|
739
|
-
const filteredTokens =
|
|
994
|
+
const filteredTokens = R14.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
740
995
|
const formattedMap = filteredTokens.map((token) => ({
|
|
741
996
|
token,
|
|
742
997
|
formatted: format(token)
|
|
743
998
|
}));
|
|
744
999
|
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
745
|
-
const formattedTokens = formattedMap.map(
|
|
1000
|
+
const formattedTokens = formattedMap.map(R14.view(R14.lensProp("formatted"))).join("\n");
|
|
746
1001
|
const content = selector ? `${selector} {
|
|
747
1002
|
${formattedTokens}
|
|
748
1003
|
}` : formattedTokens;
|
|
749
|
-
const body =
|
|
1004
|
+
const body = R14.isNotNil(layer) ? `@layer ${layer} {
|
|
1005
|
+
${content}
|
|
1006
|
+
}` : content;
|
|
1007
|
+
return body;
|
|
1008
|
+
}
|
|
1009
|
+
};
|
|
1010
|
+
|
|
1011
|
+
// src/tokens/process/formats/css/type-scale.ts
|
|
1012
|
+
import * as R15 from "ramda";
|
|
1013
|
+
import { createPropertyFormatter as createPropertyFormatter6 } from "style-dictionary/utils";
|
|
1014
|
+
var typographyFontFamilyPredicate2 = R15.allPass([
|
|
1015
|
+
R15.pathSatisfies(R15.includes("typography"), ["path"]),
|
|
1016
|
+
R15.pathSatisfies(R15.includes("fontFamily"), ["path"])
|
|
1017
|
+
]);
|
|
1018
|
+
function formatTypographySizeToken(token) {
|
|
1019
|
+
return { ...token, $value: `calc(${token.$value} * var(--_ds-font-size-factor))` };
|
|
1020
|
+
}
|
|
1021
|
+
var typeScale = {
|
|
1022
|
+
name: "ds/css-type-scale",
|
|
1023
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
1024
|
+
const { outputReferences, usesDtcg } = options;
|
|
1025
|
+
const { selector, layer } = platform;
|
|
1026
|
+
const destination = file.destination;
|
|
1027
|
+
const format = createPropertyFormatter6({
|
|
1028
|
+
outputReferences,
|
|
1029
|
+
dictionary,
|
|
1030
|
+
format: "css",
|
|
1031
|
+
usesDtcg
|
|
1032
|
+
});
|
|
1033
|
+
const filteredTokens = R15.reject(typographyFontFamilyPredicate2, dictionary.allTokens);
|
|
1034
|
+
const tokens = R15.map(formatTypographySizeToken, filteredTokens);
|
|
1035
|
+
const formattedMap = tokens.map((token) => ({
|
|
1036
|
+
token,
|
|
1037
|
+
formatted: format(token)
|
|
1038
|
+
}));
|
|
1039
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
1040
|
+
const formattedTokens = formattedMap.map(R15.prop("formatted")).join("\n");
|
|
1041
|
+
const sizeFactor = ` --_ds-font-size-factor: calc(var(--ds-size-mode-font-size) / (var(--ds-size-base) / ${basePxFontSize}));`;
|
|
1042
|
+
const content = `${selector} {
|
|
1043
|
+
${sizeFactor}
|
|
1044
|
+
${formattedTokens}
|
|
1045
|
+
}`;
|
|
1046
|
+
const body = R15.isNotNil(layer) ? `@layer ${layer} {
|
|
750
1047
|
${content}
|
|
751
1048
|
}` : content;
|
|
752
1049
|
return body;
|
|
@@ -758,7 +1055,10 @@ var formats = {
|
|
|
758
1055
|
colorScheme,
|
|
759
1056
|
colorCategory,
|
|
760
1057
|
semantic,
|
|
761
|
-
|
|
1058
|
+
sizeMode,
|
|
1059
|
+
size,
|
|
1060
|
+
typography,
|
|
1061
|
+
typeScale
|
|
762
1062
|
};
|
|
763
1063
|
export {
|
|
764
1064
|
formats
|