@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
|
@@ -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) => {
|
|
@@ -164,11 +164,11 @@ var TypographyValues;
|
|
|
164
164
|
// src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
165
165
|
import { kebabCase } from "change-case";
|
|
166
166
|
import pc2 from "picocolors";
|
|
167
|
-
import * as
|
|
167
|
+
import * as R15 from "ramda";
|
|
168
168
|
|
|
169
169
|
// src/tokens/process/platform.ts
|
|
170
170
|
import pc from "picocolors";
|
|
171
|
-
import * as
|
|
171
|
+
import * as R14 from "ramda";
|
|
172
172
|
import StyleDictionary2 from "style-dictionary";
|
|
173
173
|
|
|
174
174
|
// src/tokens/types.ts
|
|
@@ -179,7 +179,7 @@ var colorCategories = {
|
|
|
179
179
|
|
|
180
180
|
// src/tokens/process/configs.ts
|
|
181
181
|
import { register } from "@tokens-studio/sd-transforms";
|
|
182
|
-
import * as
|
|
182
|
+
import * as R13 from "ramda";
|
|
183
183
|
import StyleDictionary from "style-dictionary";
|
|
184
184
|
|
|
185
185
|
// src/tokens/utils.ts
|
|
@@ -202,7 +202,10 @@ var pathStartsWithOneOf = R.curry(
|
|
|
202
202
|
return false;
|
|
203
203
|
}
|
|
204
204
|
const tokenPath = mapToLowerCase(token.path);
|
|
205
|
-
const matchPathsStartingWith = R.map((
|
|
205
|
+
const matchPathsStartingWith = R.map((pathOrString) => {
|
|
206
|
+
const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
|
|
207
|
+
return R.startsWith(mapToLowerCase(path), tokenPath);
|
|
208
|
+
}, paths);
|
|
206
209
|
return hasAnyTruth(matchPathsStartingWith);
|
|
207
210
|
}
|
|
208
211
|
);
|
|
@@ -238,9 +241,26 @@ function inlineTokens(shouldInline, tokens) {
|
|
|
238
241
|
return tokenWithInlinedRefs;
|
|
239
242
|
});
|
|
240
243
|
}
|
|
244
|
+
var sizeMap = {
|
|
245
|
+
xsmall: "xs",
|
|
246
|
+
small: "sm",
|
|
247
|
+
medium: "md",
|
|
248
|
+
large: "lg",
|
|
249
|
+
xlarge: "xl"
|
|
250
|
+
};
|
|
251
|
+
function shortSizeName(size2) {
|
|
252
|
+
return sizeMap[size2] ?? size2;
|
|
253
|
+
}
|
|
254
|
+
var sizeComparator = (size2) => {
|
|
255
|
+
const sortIndex = Object.entries(sizeMap).findIndex(([key, val]) => key === size2 || val === size2);
|
|
256
|
+
return sortIndex ?? 0;
|
|
257
|
+
};
|
|
258
|
+
function orderBySize(sizes) {
|
|
259
|
+
return R.sortBy(sizeComparator, sizes);
|
|
260
|
+
}
|
|
241
261
|
|
|
242
262
|
// src/tokens/process/configs/color.ts
|
|
243
|
-
import * as
|
|
263
|
+
import * as R9 from "ramda";
|
|
244
264
|
|
|
245
265
|
// src/tokens/process/formats/css/color.ts
|
|
246
266
|
import * as R2 from "ramda";
|
|
@@ -298,10 +318,10 @@ ${selector} ${content} ${autoSelectorContent}
|
|
|
298
318
|
};
|
|
299
319
|
var colorCategory = {
|
|
300
320
|
name: "ds/css-colorcategory",
|
|
301
|
-
format: async ({ dictionary, options, platform }) => {
|
|
321
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
302
322
|
const { outputReferences, usesDtcg } = options;
|
|
303
|
-
const { selector, layer
|
|
304
|
-
const destination =
|
|
323
|
+
const { selector, layer } = platform;
|
|
324
|
+
const destination = file.destination;
|
|
305
325
|
const format = R2.compose(
|
|
306
326
|
createPropertyFormatter({
|
|
307
327
|
outputReferences,
|
|
@@ -338,6 +358,10 @@ ${selector} ${content}
|
|
|
338
358
|
};
|
|
339
359
|
|
|
340
360
|
// src/tokens/process/formats/css/semantic.ts
|
|
361
|
+
import * as R4 from "ramda";
|
|
362
|
+
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
363
|
+
|
|
364
|
+
// src/tokens/process/formats/css/size.ts
|
|
341
365
|
import * as R3 from "ramda";
|
|
342
366
|
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
343
367
|
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
@@ -345,12 +369,20 @@ var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.pa
|
|
|
345
369
|
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
346
370
|
var isInlineTokens = R3.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
347
371
|
var overrideSizingFormula = (format, token) => {
|
|
348
|
-
const [name, value] = format(token).split(":");
|
|
349
|
-
|
|
350
|
-
|
|
372
|
+
const [name, value] = format(token).replace(/;$/, "").split(": ");
|
|
373
|
+
let calc;
|
|
374
|
+
let round;
|
|
375
|
+
if (token.path[1] === "unit") {
|
|
376
|
+
calc = `calc(1rem * ${value})`;
|
|
377
|
+
} else if (value.startsWith("floor")) {
|
|
378
|
+
calc = value.replace(/^floor\((.*)\)$/, "calc($1)");
|
|
379
|
+
round = `round(down, ${calc}, 1px)`;
|
|
380
|
+
} else {
|
|
381
|
+
calc = value.includes("*") ? `calc(${value})` : value;
|
|
382
|
+
}
|
|
351
383
|
return {
|
|
352
384
|
name,
|
|
353
|
-
round,
|
|
385
|
+
round: round ?? calc,
|
|
354
386
|
calc
|
|
355
387
|
};
|
|
356
388
|
};
|
|
@@ -366,18 +398,21 @@ var formatSizingTokens = (format, tokens) => R3.reduce(
|
|
|
366
398
|
{ tokens: [], round: [], calc: [] },
|
|
367
399
|
tokens
|
|
368
400
|
);
|
|
369
|
-
var sizingTemplate = ({ round, calc }) =>
|
|
401
|
+
var sizingTemplate = ({ round, calc }) => {
|
|
402
|
+
const usesRounding = round.filter((val, i) => val !== calc[i]);
|
|
403
|
+
return `
|
|
370
404
|
${calc.join("\n")}
|
|
371
405
|
|
|
372
406
|
@supports (width: round(down, .1em, 1px)) {
|
|
373
|
-
${
|
|
407
|
+
${usesRounding.join("\n ")}
|
|
374
408
|
}`;
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
409
|
+
};
|
|
410
|
+
var size = {
|
|
411
|
+
name: "ds/css-size",
|
|
412
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
378
413
|
const { outputReferences, usesDtcg } = options;
|
|
379
|
-
const { selector, layer
|
|
380
|
-
const destination =
|
|
414
|
+
const { selector, layer } = platform;
|
|
415
|
+
const destination = file.destination;
|
|
381
416
|
const format = createPropertyFormatter2({
|
|
382
417
|
outputReferences,
|
|
383
418
|
dictionary,
|
|
@@ -385,9 +420,9 @@ var semantic = {
|
|
|
385
420
|
usesDtcg
|
|
386
421
|
});
|
|
387
422
|
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
388
|
-
const filteredTokens = R3.reject((token) =>
|
|
423
|
+
const filteredTokens = R3.reject((token) => R3.equals(["_size", "mode-font-size"], token.path), tokens);
|
|
389
424
|
const [sizingTokens, restTokens] = R3.partition(
|
|
390
|
-
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
425
|
+
(t) => pathStartsWithOneOf(["_size"], t) && (isDigit(t.path[1]) || t.path[1] === "unit"),
|
|
391
426
|
filteredTokens
|
|
392
427
|
);
|
|
393
428
|
const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
|
|
@@ -400,64 +435,56 @@ var semantic = {
|
|
|
400
435
|
formatted: t
|
|
401
436
|
}));
|
|
402
437
|
buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
|
|
403
|
-
const
|
|
404
|
-
const
|
|
405
|
-
const content = `{
|
|
438
|
+
const formattedTokens = [formattedMap.map(R3.prop("formatted")).join("\n"), sizingTemplate(formattedSizingTokens)];
|
|
439
|
+
const content = `${selector} {
|
|
406
440
|
${formattedTokens.join("\n")}
|
|
407
441
|
}
|
|
408
442
|
`;
|
|
409
443
|
const body = R3.isNotNil(layer) ? `@layer ${layer} {
|
|
410
|
-
${
|
|
444
|
+
${content}
|
|
411
445
|
}
|
|
412
|
-
` : `${
|
|
446
|
+
` : `${content}
|
|
413
447
|
`;
|
|
414
448
|
return body;
|
|
415
449
|
}
|
|
416
450
|
};
|
|
417
451
|
|
|
418
|
-
// src/tokens/process/formats/css/
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
R4.pathSatisfies(R4.includes("typography"), ["path"]),
|
|
423
|
-
R4.pathSatisfies(R4.includes("fontFamily"), ["path"])
|
|
424
|
-
]);
|
|
425
|
-
var typography = {
|
|
426
|
-
name: "ds/css-typography",
|
|
427
|
-
format: async ({ dictionary, options, platform }) => {
|
|
452
|
+
// src/tokens/process/formats/css/semantic.ts
|
|
453
|
+
var semantic = {
|
|
454
|
+
name: "ds/css-semantic",
|
|
455
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
428
456
|
const { outputReferences, usesDtcg } = options;
|
|
429
|
-
const { selector, layer
|
|
430
|
-
const destination =
|
|
457
|
+
const { selector, layer } = platform;
|
|
458
|
+
const destination = file.destination;
|
|
431
459
|
const format = createPropertyFormatter3({
|
|
432
460
|
outputReferences,
|
|
433
461
|
dictionary,
|
|
434
462
|
format: "css",
|
|
435
463
|
usesDtcg
|
|
436
464
|
});
|
|
437
|
-
const
|
|
438
|
-
const formattedMap =
|
|
465
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
466
|
+
const formattedMap = tokens.map((token) => ({
|
|
439
467
|
token,
|
|
440
468
|
formatted: format(token)
|
|
441
469
|
}));
|
|
442
470
|
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
443
|
-
const formattedTokens = formattedMap.map(R4.
|
|
444
|
-
const content =
|
|
471
|
+
const formattedTokens = formattedMap.map(R4.prop("formatted")).join("\n");
|
|
472
|
+
const content = `${selector} {
|
|
445
473
|
${formattedTokens}
|
|
446
|
-
}
|
|
474
|
+
}
|
|
475
|
+
`;
|
|
447
476
|
const body = R4.isNotNil(layer) ? `@layer ${layer} {
|
|
448
477
|
${content}
|
|
449
|
-
}
|
|
478
|
+
}
|
|
479
|
+
` : `${content}
|
|
480
|
+
`;
|
|
450
481
|
return body;
|
|
451
482
|
}
|
|
452
483
|
};
|
|
453
484
|
|
|
454
|
-
// src/tokens/process/formats/css.ts
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
colorCategory,
|
|
458
|
-
semantic,
|
|
459
|
-
typography
|
|
460
|
-
};
|
|
485
|
+
// src/tokens/process/formats/css/size-mode.ts
|
|
486
|
+
import * as R6 from "ramda";
|
|
487
|
+
import { createPropertyFormatter as createPropertyFormatter4 } from "style-dictionary/utils";
|
|
461
488
|
|
|
462
489
|
// src/tokens/process/transformers.ts
|
|
463
490
|
import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
|
|
@@ -469,18 +496,22 @@ var sizeRem = {
|
|
|
469
496
|
transitive: true,
|
|
470
497
|
filter: (token) => {
|
|
471
498
|
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
472
|
-
const hasWantedPath = pathStartsWithOneOf([
|
|
499
|
+
const hasWantedPath = pathStartsWithOneOf([
|
|
500
|
+
"border-radius",
|
|
501
|
+
"font-size"
|
|
502
|
+
/*, ['_size', 'mode-font-size']*/
|
|
503
|
+
], token);
|
|
473
504
|
return hasWantedType && hasWantedPath;
|
|
474
505
|
},
|
|
475
506
|
transform: (token, config) => {
|
|
476
507
|
const value = getValue(token);
|
|
477
508
|
if (isPx(value)) {
|
|
478
509
|
const baseFont = config.basePxFontSize || 16;
|
|
479
|
-
const
|
|
480
|
-
if (
|
|
510
|
+
const size2 = parseInt(value, 10);
|
|
511
|
+
if (size2 === 0) {
|
|
481
512
|
return "0";
|
|
482
513
|
}
|
|
483
|
-
return `${
|
|
514
|
+
return `${size2 / baseFont}rem`;
|
|
484
515
|
}
|
|
485
516
|
return value;
|
|
486
517
|
}
|
|
@@ -531,6 +562,154 @@ var dsTransformers = [
|
|
|
531
562
|
"shadow/css/shorthand"
|
|
532
563
|
];
|
|
533
564
|
|
|
565
|
+
// src/tokens/process/formats/css/size-mode.ts
|
|
566
|
+
var formatBaseSizeToken = (size2) => (token) => ({
|
|
567
|
+
...token,
|
|
568
|
+
originalName: token.name,
|
|
569
|
+
name: `${token.name}--${shortSizeName(size2)}`,
|
|
570
|
+
$value: token.$value / basePxFontSize
|
|
571
|
+
});
|
|
572
|
+
var sizeMode = {
|
|
573
|
+
name: "ds/css-size-mode",
|
|
574
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
575
|
+
const { outputReferences, usesDtcg } = options;
|
|
576
|
+
const { selector, layer, size: size2 } = platform;
|
|
577
|
+
const destination = file.destination;
|
|
578
|
+
const format = createPropertyFormatter4({
|
|
579
|
+
outputReferences,
|
|
580
|
+
dictionary,
|
|
581
|
+
format: "css",
|
|
582
|
+
usesDtcg
|
|
583
|
+
});
|
|
584
|
+
const sizeSpecificTokens = dictionary.allTokens.map(formatBaseSizeToken(size2));
|
|
585
|
+
const sizeSpecificVariables = sizeSpecificTokens.map(format).join("\n");
|
|
586
|
+
const formattedMap = sizeSpecificTokens.map((token) => ({
|
|
587
|
+
token,
|
|
588
|
+
formatted: format({
|
|
589
|
+
...token,
|
|
590
|
+
// Remove the `--<size>` suffix for the token listing, since that is the only token we actually use
|
|
591
|
+
name: token.originalName
|
|
592
|
+
})
|
|
593
|
+
}));
|
|
594
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
595
|
+
const content = `${selector} /* ${size2} */ {
|
|
596
|
+
${sizeSpecificVariables}
|
|
597
|
+
}`;
|
|
598
|
+
const body = wrapInLayer(content, layer);
|
|
599
|
+
const sizes = orderBySize(buildOptions?.sizeModes ?? []).map(shortSizeName);
|
|
600
|
+
const defaultSize = shortSizeName(buildOptions?.defaultSize ?? "");
|
|
601
|
+
const sizingToggles = `:root, [data-size] {
|
|
602
|
+
--ds-size: var(--ds-size--${defaultSize});
|
|
603
|
+
${sizes.map((size3) => ` --ds-size--${size3}: var(--ds-size,);`).join("\n")}
|
|
604
|
+
--ds-size-mode-font-size:
|
|
605
|
+
${sizes.map((size3) => ` var(--ds-size--${size3}, var(--ds-size-mode-font-size--${size3}))`).join("\n")};
|
|
606
|
+
}`;
|
|
607
|
+
const sizingHelpers = sizes.map((size3) => `[data-size='${size3}'] { --ds-size: var(--ds-size--${size3}); }`).join("\n");
|
|
608
|
+
const sharedContent = `${sizingToggles}
|
|
609
|
+
|
|
610
|
+
${sizingHelpers}`;
|
|
611
|
+
const sharedBody = shortSizeName(size2) === R6.last(sizes) ? `
|
|
612
|
+
${wrapInLayer(sharedContent, layer)}` : "";
|
|
613
|
+
return body + sharedBody;
|
|
614
|
+
}
|
|
615
|
+
};
|
|
616
|
+
function wrapInLayer(content, layer) {
|
|
617
|
+
return R6.isNotNil(layer) ? `@layer ${layer} {
|
|
618
|
+
${content}
|
|
619
|
+
}
|
|
620
|
+
` : `${content}
|
|
621
|
+
`;
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
// src/tokens/process/formats/css/typography.ts
|
|
625
|
+
import * as R7 from "ramda";
|
|
626
|
+
import { createPropertyFormatter as createPropertyFormatter5 } from "style-dictionary/utils";
|
|
627
|
+
var typographyFontFamilyPredicate = R7.allPass([
|
|
628
|
+
R7.pathSatisfies(R7.includes("typography"), ["path"]),
|
|
629
|
+
R7.pathSatisfies(R7.includes("fontFamily"), ["path"])
|
|
630
|
+
]);
|
|
631
|
+
var typography = {
|
|
632
|
+
name: "ds/css-typography",
|
|
633
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
634
|
+
const { outputReferences, usesDtcg } = options;
|
|
635
|
+
const { selector, layer } = platform;
|
|
636
|
+
const destination = file.destination;
|
|
637
|
+
const format = createPropertyFormatter5({
|
|
638
|
+
outputReferences,
|
|
639
|
+
dictionary,
|
|
640
|
+
format: "css",
|
|
641
|
+
usesDtcg
|
|
642
|
+
});
|
|
643
|
+
const filteredTokens = R7.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
644
|
+
const formattedMap = filteredTokens.map((token) => ({
|
|
645
|
+
token,
|
|
646
|
+
formatted: format(token)
|
|
647
|
+
}));
|
|
648
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
649
|
+
const formattedTokens = formattedMap.map(R7.view(R7.lensProp("formatted"))).join("\n");
|
|
650
|
+
const content = selector ? `${selector} {
|
|
651
|
+
${formattedTokens}
|
|
652
|
+
}` : formattedTokens;
|
|
653
|
+
const body = R7.isNotNil(layer) ? `@layer ${layer} {
|
|
654
|
+
${content}
|
|
655
|
+
}` : content;
|
|
656
|
+
return body;
|
|
657
|
+
}
|
|
658
|
+
};
|
|
659
|
+
|
|
660
|
+
// src/tokens/process/formats/css/type-scale.ts
|
|
661
|
+
import * as R8 from "ramda";
|
|
662
|
+
import { createPropertyFormatter as createPropertyFormatter6 } from "style-dictionary/utils";
|
|
663
|
+
var typographyFontFamilyPredicate2 = R8.allPass([
|
|
664
|
+
R8.pathSatisfies(R8.includes("typography"), ["path"]),
|
|
665
|
+
R8.pathSatisfies(R8.includes("fontFamily"), ["path"])
|
|
666
|
+
]);
|
|
667
|
+
function formatTypographySizeToken(token) {
|
|
668
|
+
return { ...token, $value: `calc(${token.$value} * var(--_ds-font-size-factor))` };
|
|
669
|
+
}
|
|
670
|
+
var typeScale = {
|
|
671
|
+
name: "ds/css-type-scale",
|
|
672
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
673
|
+
const { outputReferences, usesDtcg } = options;
|
|
674
|
+
const { selector, layer } = platform;
|
|
675
|
+
const destination = file.destination;
|
|
676
|
+
const format = createPropertyFormatter6({
|
|
677
|
+
outputReferences,
|
|
678
|
+
dictionary,
|
|
679
|
+
format: "css",
|
|
680
|
+
usesDtcg
|
|
681
|
+
});
|
|
682
|
+
const filteredTokens = R8.reject(typographyFontFamilyPredicate2, dictionary.allTokens);
|
|
683
|
+
const tokens = R8.map(formatTypographySizeToken, filteredTokens);
|
|
684
|
+
const formattedMap = tokens.map((token) => ({
|
|
685
|
+
token,
|
|
686
|
+
formatted: format(token)
|
|
687
|
+
}));
|
|
688
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
689
|
+
const formattedTokens = formattedMap.map(R8.prop("formatted")).join("\n");
|
|
690
|
+
const sizeFactor = ` --_ds-font-size-factor: calc(var(--ds-size-mode-font-size) / (var(--ds-size-base) / ${basePxFontSize}));`;
|
|
691
|
+
const content = `${selector} {
|
|
692
|
+
${sizeFactor}
|
|
693
|
+
${formattedTokens}
|
|
694
|
+
}`;
|
|
695
|
+
const body = R8.isNotNil(layer) ? `@layer ${layer} {
|
|
696
|
+
${content}
|
|
697
|
+
}` : content;
|
|
698
|
+
return body;
|
|
699
|
+
}
|
|
700
|
+
};
|
|
701
|
+
|
|
702
|
+
// src/tokens/process/formats/css.ts
|
|
703
|
+
var formats = {
|
|
704
|
+
colorScheme,
|
|
705
|
+
colorCategory,
|
|
706
|
+
semantic,
|
|
707
|
+
sizeMode,
|
|
708
|
+
size,
|
|
709
|
+
typography,
|
|
710
|
+
typeScale
|
|
711
|
+
};
|
|
712
|
+
|
|
534
713
|
// src/tokens/process/configs/color.ts
|
|
535
714
|
var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) => {
|
|
536
715
|
const selector = `${colorScheme2 === "light" ? ":root, " : ""}[data-color-scheme="${colorScheme2}"]`;
|
|
@@ -552,7 +731,7 @@ var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) =
|
|
|
552
731
|
{
|
|
553
732
|
destination: `color-scheme/${colorScheme2}.css`,
|
|
554
733
|
format: formats.colorScheme.name,
|
|
555
|
-
filter: (token) => typeEquals("color", token) && !
|
|
734
|
+
filter: (token) => typeEquals("color", token) && !R9.startsWith(["global"], token.path)
|
|
556
735
|
}
|
|
557
736
|
],
|
|
558
737
|
options: {
|
|
@@ -603,7 +782,7 @@ var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, .
|
|
|
603
782
|
};
|
|
604
783
|
|
|
605
784
|
// src/tokens/process/configs/semantic.ts
|
|
606
|
-
import * as
|
|
785
|
+
import * as R10 from "ramda";
|
|
607
786
|
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
608
787
|
var semanticVariables = ({ theme }) => {
|
|
609
788
|
const selector = `:root`;
|
|
@@ -626,9 +805,12 @@ var semanticVariables = ({ theme }) => {
|
|
|
626
805
|
destination: `semantic.css`,
|
|
627
806
|
format: formats.semantic.name,
|
|
628
807
|
filter: (token) => {
|
|
629
|
-
const isUwantedToken =
|
|
630
|
-
const isPrivateToken =
|
|
631
|
-
const unwantedPaths = pathStartsWithOneOf(
|
|
808
|
+
const isUwantedToken = R10.anyPass([R10.includes("primitives/global")])(token.filePath);
|
|
809
|
+
const isPrivateToken = R10.includes("_", token.path);
|
|
810
|
+
const unwantedPaths = pathStartsWithOneOf(
|
|
811
|
+
["size", "_size", "font-size", "line-height", "letter-spacing"],
|
|
812
|
+
token
|
|
813
|
+
);
|
|
632
814
|
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
633
815
|
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
634
816
|
return unwantedTokens;
|
|
@@ -638,9 +820,126 @@ var semanticVariables = ({ theme }) => {
|
|
|
638
820
|
options: {
|
|
639
821
|
outputReferences: (token, options) => {
|
|
640
822
|
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
641
|
-
|
|
642
|
-
|
|
823
|
+
return include && outputReferencesFilter(token, options);
|
|
824
|
+
}
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
};
|
|
829
|
+
};
|
|
830
|
+
|
|
831
|
+
// src/tokens/process/configs/size.ts
|
|
832
|
+
import * as R11 from "ramda";
|
|
833
|
+
import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
|
|
834
|
+
var sizeVariables = ({ theme }) => {
|
|
835
|
+
const selector = `:root, [data-size]`;
|
|
836
|
+
const layer = `ds.theme.size`;
|
|
837
|
+
return {
|
|
838
|
+
preprocessors: ["tokens-studio"],
|
|
839
|
+
platforms: {
|
|
840
|
+
css: {
|
|
841
|
+
// custom
|
|
842
|
+
theme,
|
|
843
|
+
basePxFontSize,
|
|
844
|
+
selector,
|
|
845
|
+
layer,
|
|
846
|
+
//
|
|
847
|
+
prefix,
|
|
848
|
+
buildPath: `${theme}/`,
|
|
849
|
+
transforms: dsTransformers,
|
|
850
|
+
files: [
|
|
851
|
+
{
|
|
852
|
+
destination: `size.css`,
|
|
853
|
+
format: formats.size.name,
|
|
854
|
+
filter: (token) => {
|
|
855
|
+
const isUwantedToken = R11.anyPass([R11.includes("primitives/global")])(token.filePath);
|
|
856
|
+
const isPrivateToken = R11.includes("_", token.path);
|
|
857
|
+
return pathStartsWithOneOf(["size", "_size"], token) && !(isUwantedToken || isPrivateToken);
|
|
858
|
+
}
|
|
859
|
+
}
|
|
860
|
+
],
|
|
861
|
+
options: {
|
|
862
|
+
outputReferences: (token, options) => {
|
|
863
|
+
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && (isDigit(token.path[1]) || token.path[1] === "unit");
|
|
864
|
+
return isWantedSize && outputReferencesFilter2(token, options);
|
|
865
|
+
}
|
|
866
|
+
}
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
};
|
|
870
|
+
};
|
|
871
|
+
|
|
872
|
+
// src/tokens/process/configs/size-mode.ts
|
|
873
|
+
import * as R12 from "ramda";
|
|
874
|
+
var sizeModeVariables = ({ theme, size: size2 }) => {
|
|
875
|
+
const selector = `:root`;
|
|
876
|
+
const layer = `ds.theme.size-mode`;
|
|
877
|
+
return {
|
|
878
|
+
preprocessors: ["tokens-studio"],
|
|
879
|
+
platforms: {
|
|
880
|
+
css: {
|
|
881
|
+
// custom
|
|
882
|
+
size: size2,
|
|
883
|
+
theme,
|
|
884
|
+
basePxFontSize,
|
|
885
|
+
selector,
|
|
886
|
+
layer,
|
|
887
|
+
//
|
|
888
|
+
prefix,
|
|
889
|
+
buildPath: `${theme}/`,
|
|
890
|
+
transforms: dsTransformers,
|
|
891
|
+
files: [
|
|
892
|
+
{
|
|
893
|
+
destination: `size-mode/${size2}.css`,
|
|
894
|
+
format: formats.sizeMode.name,
|
|
895
|
+
filter: (token) => {
|
|
896
|
+
return R12.equals(["_size", "mode-font-size"], token.path);
|
|
897
|
+
}
|
|
643
898
|
}
|
|
899
|
+
]
|
|
900
|
+
}
|
|
901
|
+
}
|
|
902
|
+
};
|
|
903
|
+
};
|
|
904
|
+
|
|
905
|
+
// src/tokens/process/configs/type-scale.ts
|
|
906
|
+
var typeScaleVariables = ({ theme, size: size2 }) => {
|
|
907
|
+
const selector = ":root, [data-size]";
|
|
908
|
+
const layer = `ds.theme.type-scale`;
|
|
909
|
+
return {
|
|
910
|
+
usesDtcg: true,
|
|
911
|
+
preprocessors: ["tokens-studio"],
|
|
912
|
+
expand: {
|
|
913
|
+
include: ["typography"]
|
|
914
|
+
},
|
|
915
|
+
platforms: {
|
|
916
|
+
css: {
|
|
917
|
+
prefix,
|
|
918
|
+
selector,
|
|
919
|
+
layer,
|
|
920
|
+
buildPath: `${theme}/`,
|
|
921
|
+
basePxFontSize,
|
|
922
|
+
transforms: [
|
|
923
|
+
"name/kebab",
|
|
924
|
+
"ts/size/px",
|
|
925
|
+
sizeRem.name,
|
|
926
|
+
"ts/size/lineheight",
|
|
927
|
+
"ts/typography/fontWeight",
|
|
928
|
+
typographyName.name
|
|
929
|
+
],
|
|
930
|
+
files: [
|
|
931
|
+
{
|
|
932
|
+
destination: `type-scale.css`,
|
|
933
|
+
format: formats.typeScale.name,
|
|
934
|
+
filter: (token) => {
|
|
935
|
+
const included = typeEquals(["typography", "dimension", "fontsize"], token);
|
|
936
|
+
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
937
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "border-width", "border-radius"], token) && (pathStartsWithOneOf(["font-size"], token) || token.path.includes("fontSize"));
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
],
|
|
941
|
+
options: {
|
|
942
|
+
outputReferences: (token) => pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize")
|
|
644
943
|
}
|
|
645
944
|
}
|
|
646
945
|
}
|
|
@@ -681,12 +980,9 @@ var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
|
681
980
|
destination: `typography/${typography2}.css`,
|
|
682
981
|
format: formats.typography.name,
|
|
683
982
|
filter: (token) => {
|
|
684
|
-
const included = typeEquals(
|
|
685
|
-
["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
|
|
686
|
-
token
|
|
687
|
-
);
|
|
983
|
+
const included = typeEquals(["fontweight", "fontFamily", "lineHeight", "dimension"], token);
|
|
688
984
|
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
689
|
-
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token);
|
|
985
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token) && !(pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize"));
|
|
690
986
|
}
|
|
691
987
|
}
|
|
692
988
|
]
|
|
@@ -713,7 +1009,10 @@ var configs = {
|
|
|
713
1009
|
dangerColorVariables: colorCategoryVariables({ category: "builtin", color: "danger" }),
|
|
714
1010
|
warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
|
|
715
1011
|
infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
|
|
1012
|
+
sizeModeVariables,
|
|
1013
|
+
sizeVariables,
|
|
716
1014
|
typographyVariables,
|
|
1015
|
+
typeScaleVariables,
|
|
717
1016
|
semanticVariables
|
|
718
1017
|
};
|
|
719
1018
|
|
|
@@ -726,6 +1025,9 @@ var buildOptions = {
|
|
|
726
1025
|
var sd = new StyleDictionary2();
|
|
727
1026
|
var buildConfigs = {
|
|
728
1027
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
1028
|
+
sizeMode: { getConfig: configs.sizeModeVariables, dimensions: ["size"] },
|
|
1029
|
+
size: { getConfig: configs.sizeVariables, dimensions: ["semantic"] },
|
|
1030
|
+
typeScale: { getConfig: configs.typeScaleVariables, dimensions: ["semantic"] },
|
|
729
1031
|
"color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
|
|
730
1032
|
"main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
|
|
731
1033
|
"support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
|
|
@@ -763,7 +1065,7 @@ var getMultidimensionalThemes = (processed$themes, dimensions) => {
|
|
|
763
1065
|
const grouped$themes = groupThemes(processed$themes);
|
|
764
1066
|
const permutations = permutateThemes(grouped$themes);
|
|
765
1067
|
const ALL_DEPENDENT_ON = ["theme"];
|
|
766
|
-
const keys2 =
|
|
1068
|
+
const keys2 = R15.keys(grouped$themes);
|
|
767
1069
|
const nonDependentKeys = keys2.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
|
|
768
1070
|
if (verboseLogging) {
|
|
769
1071
|
console.log(pc2.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
|
|
@@ -803,7 +1105,7 @@ function groupThemes(themes) {
|
|
|
803
1105
|
}
|
|
804
1106
|
return groups;
|
|
805
1107
|
}
|
|
806
|
-
var hasUnknownProps =
|
|
1108
|
+
var hasUnknownProps = R15.pipe(R15.values, R15.none(R15.equals("unknown")), R15.not);
|
|
807
1109
|
function permutateThemes(groups) {
|
|
808
1110
|
const separator = "_";
|
|
809
1111
|
const permutations = cartesian(Object.values(groups));
|
|
@@ -813,8 +1115,8 @@ function permutateThemes(groups) {
|
|
|
813
1115
|
const { group, name, selectedTokenSets } = theme;
|
|
814
1116
|
let updatedPermutation = acc.permutation;
|
|
815
1117
|
if (group) {
|
|
816
|
-
const groupProp =
|
|
817
|
-
updatedPermutation =
|
|
1118
|
+
const groupProp = R15.lensProp(group);
|
|
1119
|
+
updatedPermutation = R15.set(groupProp, name, updatedPermutation);
|
|
818
1120
|
}
|
|
819
1121
|
const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
|
|
820
1122
|
const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
|