@digdir/designsystemet 1.0.2 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/designsystemet.js +4264 -45
- package/dist/bin/options.js +5 -4
- package/dist/src/colors/colorMetadata.d.ts.map +1 -1
- package/dist/src/colors/colorMetadata.js +84 -35
- package/dist/src/colors/index.js +470 -4
- package/dist/src/colors/theme.d.ts.map +1 -1
- package/dist/src/colors/theme.js +290 -18
- package/dist/src/colors/types.d.ts +4 -1
- package/dist/src/colors/types.d.ts.map +1 -1
- package/dist/src/colors/utils.js +16 -15
- package/dist/{bin → src}/config.d.ts +46 -1
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +377 -0
- package/dist/src/index.js +3666 -2
- package/dist/src/migrations/beta-to-v1.js +85 -4
- package/dist/src/migrations/codemods/css/plugins.js +5 -4
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
- package/dist/src/migrations/codemods/css/run.js +18 -4
- package/dist/src/migrations/color-rename-next49.js +77 -6
- package/dist/src/migrations/index.d.ts +0 -1
- package/dist/src/migrations/index.d.ts.map +1 -1
- package/dist/src/migrations/index.js +461 -6
- package/dist/src/scripts/createJsonSchema.js +1608 -4
- package/dist/src/scripts/update-design-tokens.d.ts +2 -0
- package/dist/src/scripts/update-design-tokens.d.ts.map +1 -0
- package/dist/src/scripts/update-design-tokens.js +36 -0
- package/dist/src/{tokens/template.d.ts → scripts/update-template.d.ts} +1 -1
- package/dist/src/scripts/update-template.d.ts.map +1 -0
- package/dist/src/scripts/update-template.js +1200 -0
- package/dist/src/tokens/build.d.ts +2 -19
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +1511 -70
- package/dist/src/tokens/create/defaults.d.ts +7 -0
- package/dist/src/tokens/create/defaults.d.ts.map +1 -0
- package/dist/src/tokens/create/defaults.js +994 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.js +100 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
- package/dist/src/tokens/{write/generate$metadata.js → create/generators/$metadata.js} +3 -2
- package/dist/src/tokens/create/generators/$themes.d.ts +12 -0
- package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$themes.js +333 -0
- package/dist/src/tokens/create/generators/color.d.ts +5 -0
- package/dist/src/tokens/create/generators/color.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/color.js +374 -0
- package/dist/src/tokens/create/generators/semantic.d.ts +296 -0
- package/dist/src/tokens/create/generators/semantic.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic.js +483 -0
- package/dist/src/tokens/create/generators/theme.d.ts +3 -0
- package/dist/src/tokens/create/generators/theme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/theme.js +168 -0
- package/dist/src/tokens/create/generators/typography.d.ts +3 -0
- package/dist/src/tokens/create/generators/typography.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/typography.js +33 -0
- package/dist/src/tokens/{write.d.ts → create/write.d.ts} +2 -2
- package/dist/src/tokens/create/write.d.ts.map +1 -0
- package/dist/src/tokens/create/write.js +546 -0
- package/dist/src/tokens/create.d.ts +4 -2
- package/dist/src/tokens/create.d.ts.map +1 -1
- package/dist/src/tokens/create.js +2049 -59
- package/dist/src/tokens/format.d.ts +16 -0
- package/dist/src/tokens/format.d.ts.map +1 -0
- package/dist/src/tokens/format.js +3514 -0
- package/dist/src/tokens/index.d.ts +1 -0
- package/dist/src/tokens/index.d.ts.map +1 -1
- package/dist/src/tokens/index.js +3526 -2
- package/dist/src/tokens/process/configs/color.d.ts +12 -0
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/color.js +823 -0
- package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/semantic.js +367 -0
- package/dist/src/tokens/process/configs/shared.d.ts +10 -0
- package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/shared.js +99 -0
- package/dist/src/tokens/process/configs/storefront.d.ts +3 -0
- package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/storefront.js +220 -0
- package/dist/src/tokens/process/configs/typography.d.ts +3 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/typography.js +369 -0
- package/dist/src/tokens/{build → process}/configs.d.ts +3 -11
- package/dist/src/tokens/process/configs.d.ts.map +1 -0
- package/dist/src/tokens/process/configs.js +976 -0
- package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/color.js +128 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts +17 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.js +109 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.js +32 -0
- package/dist/src/tokens/process/formats/css.d.ts +8 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/{build → process}/formats/css.js +94 -57
- package/dist/src/tokens/process/formats/js-tokens.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/js-tokens.js +109 -0
- package/dist/src/tokens/process/platform.d.ts +87 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -0
- package/dist/src/tokens/process/platform.js +1090 -0
- package/dist/src/tokens/process/transformers.d.ts.map +1 -0
- package/dist/src/tokens/{build → process}/transformers.js +29 -6
- package/dist/src/tokens/{build → process}/utils/getMultidimensionalThemes.d.ts +3 -3
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +922 -0
- package/dist/src/tokens/template/design-tokens/primitives/globals.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/large.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/medium.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/small.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/large.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/medium.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/small.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/typography.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/color.base.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/color.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/modes/color.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/style.js +5 -0
- package/dist/src/tokens/template/design-tokens/themes/theme.base.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/themes/theme.template.js +5 -0
- package/dist/src/tokens/types.d.ts +54 -38
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/tokens/types.js +8 -0
- package/dist/src/tokens/utils.d.ts +30 -5
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/dist/src/tokens/utils.js +36 -50
- package/dist/src/utils.d.ts +18 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +63 -0
- package/dist/typography.template-4N5YLH7F.json +22 -0
- package/package.json +17 -16
- package/dist/bin/config.d.ts.map +0 -1
- package/dist/bin/config.js +0 -71
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
- package/dist/src/migrations/codemods/jsx/classname-prefix.js +0 -64
- package/dist/src/migrations/codemods/jsx/run.d.ts +0 -7
- package/dist/src/migrations/codemods/jsx/run.d.ts.map +0 -1
- package/dist/src/migrations/codemods/jsx/run.js +0 -22
- package/dist/src/migrations/react-beta-to-v1.d.ts +0 -3
- package/dist/src/migrations/react-beta-to-v1.d.ts.map +0 -1
- package/dist/src/migrations/react-beta-to-v1.js +0 -5
- package/dist/src/scripts/copy-internal-tokens.d.ts +0 -2
- package/dist/src/scripts/copy-internal-tokens.d.ts.map +0 -1
- package/dist/src/scripts/copy-internal-tokens.js +0 -28
- package/dist/src/tokens/build/configs.d.ts.map +0 -1
- package/dist/src/tokens/build/configs.js +0 -280
- package/dist/src/tokens/build/formats/css.d.ts +0 -53
- package/dist/src/tokens/build/formats/css.d.ts.map +0 -1
- package/dist/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
- package/dist/src/tokens/build/formats/js-tokens.js +0 -48
- package/dist/src/tokens/build/transformers.d.ts.map +0 -1
- package/dist/src/tokens/build/types.d.ts +0 -48
- package/dist/src/tokens/build/types.d.ts.map +0 -1
- package/dist/src/tokens/build/types.js +0 -7
- package/dist/src/tokens/build/utils/entryfile.d.ts +0 -12
- package/dist/src/tokens/build/utils/entryfile.d.ts.map +0 -1
- package/dist/src/tokens/build/utils/entryfile.js +0 -67
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +0 -1
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +0 -112
- package/dist/src/tokens/design-tokens/template/$metadata.json +0 -25
- package/dist/src/tokens/design-tokens/template/$themes.json +0 -1498
- package/dist/src/tokens/template.d.ts.map +0 -1
- package/dist/src/tokens/template.js +0 -99
- package/dist/src/tokens/write/generate$metadata.d.ts +0 -9
- package/dist/src/tokens/write/generate$metadata.d.ts.map +0 -1
- package/dist/src/tokens/write/generate$themes.d.ts +0 -12
- package/dist/src/tokens/write/generate$themes.d.ts.map +0 -1
- package/dist/src/tokens/write/generate$themes.js +0 -161
- package/dist/src/tokens/write.d.ts.map +0 -1
- package/dist/src/tokens/write.js +0 -177
- /package/dist/{src/tokens/design-tokens/template/semantic/color-base-file.json → color.base.template-M7BHS4OV.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json → color.template-LMPUQ72A.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/semantic/semantic-color-template.json → color.template-XQNSHLTU.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/global.json → global-XVXVBKM6.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/globals.json → globals-76VAFMDF.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/large.json → large-CIIHO7AY.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/large.json → large-UUOZ6DYI.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/medium.json → medium-OQ7S7P4P.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json → medium-VSB2S4X3.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/small.json → small-AEXJ6U7Z.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/small.json → small-ZY4KOJWX.json} +0 -0
- /package/dist/src/tokens/{build → process}/formats/js-tokens.d.ts +0 -0
- /package/dist/src/tokens/{build → process}/transformers.d.ts +0 -0
- /package/dist/{src/tokens/design-tokens/default/semantic/style.json → style-FP5XVCUD.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/themes/theme-base-file.json → theme.base.template-Y4RMFBQY.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/themes/theme-color-template.json → theme.template-CTQRNOMO.json} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/semantic.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,wBAAwB,EAA0C,MAAM,aAAa,CAAC;AAEpG,eAAO,MAAM,iBAAiB,EAAE,wBA0C/B,CAAC"}
|
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
// src/tokens/process/configs/semantic.ts
|
|
2
|
+
import * as R6 from "ramda";
|
|
3
|
+
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
4
|
+
|
|
5
|
+
// src/tokens/utils.ts
|
|
6
|
+
import * as R from "ramda";
|
|
7
|
+
var mapToLowerCase = R.map(R.toLower);
|
|
8
|
+
var hasAnyTruth = R.any(R.equals(true));
|
|
9
|
+
var getType = (token) => (token.$type ?? token.type) || "";
|
|
10
|
+
var getValue = (token) => token.$value ?? token.value;
|
|
11
|
+
var typeEquals = R.curry((types, token) => {
|
|
12
|
+
if (R.isNil(token)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
|
|
16
|
+
});
|
|
17
|
+
var pathStartsWithOneOf = R.curry((paths, token) => {
|
|
18
|
+
if (R.isNil(token)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const tokenPath = mapToLowerCase(token.path);
|
|
22
|
+
const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
|
|
23
|
+
return hasAnyTruth(matchPathsStartingWith);
|
|
24
|
+
});
|
|
25
|
+
function isSemanticToken(token) {
|
|
26
|
+
return token.filePath.includes("semantic/");
|
|
27
|
+
}
|
|
28
|
+
function isGlobalColorToken(token) {
|
|
29
|
+
return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
|
|
30
|
+
}
|
|
31
|
+
function isColorCategoryToken(token, category) {
|
|
32
|
+
if (!category) {
|
|
33
|
+
return ["main", "support"].some((c) => isColorCategoryToken(token, c));
|
|
34
|
+
}
|
|
35
|
+
return R.startsWith(["color", category], token.path);
|
|
36
|
+
}
|
|
37
|
+
var isDigit = (s) => /^\d+$/.test(s);
|
|
38
|
+
function inlineTokens(shouldInline, tokens) {
|
|
39
|
+
const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
|
|
40
|
+
return otherTokens.map((token) => {
|
|
41
|
+
let transformed = getValue(token.original);
|
|
42
|
+
for (const ref of inlineableTokens) {
|
|
43
|
+
const refName = ref.path.join(".");
|
|
44
|
+
if (typeof transformed === "string") {
|
|
45
|
+
transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
const tokenWithInlinedRefs = R.set(R.lensPath(["original", "$value"]), transformed, token);
|
|
49
|
+
return tokenWithInlinedRefs;
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// src/tokens/process/formats/css/color.ts
|
|
54
|
+
import * as R2 from "ramda";
|
|
55
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
56
|
+
|
|
57
|
+
// src/tokens/types.ts
|
|
58
|
+
var colorCategories = {
|
|
59
|
+
main: "main",
|
|
60
|
+
support: "support"
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
// src/tokens/process/formats/css/color.ts
|
|
64
|
+
var prefersColorScheme = (colorScheme2, content) => `
|
|
65
|
+
@media (prefers-color-scheme: ${colorScheme2}) {
|
|
66
|
+
[data-color-scheme="auto"] ${content}
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
var colorScheme = {
|
|
70
|
+
name: "ds/css-colorscheme",
|
|
71
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
72
|
+
const { allTokens } = dictionary;
|
|
73
|
+
const { outputReferences, usesDtcg } = options;
|
|
74
|
+
const { selector, colorScheme: colorScheme2, layer } = platform;
|
|
75
|
+
const colorScheme_ = colorScheme2;
|
|
76
|
+
const format = createPropertyFormatter({
|
|
77
|
+
outputReferences,
|
|
78
|
+
dictionary,
|
|
79
|
+
format: "css",
|
|
80
|
+
usesDtcg
|
|
81
|
+
});
|
|
82
|
+
const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
|
|
83
|
+
color-scheme: ${colorScheme_};
|
|
84
|
+
` : "";
|
|
85
|
+
const filteredAllTokens = allTokens.filter(
|
|
86
|
+
R2.allPass([
|
|
87
|
+
R2.anyPass([
|
|
88
|
+
// Include semantic tokens in the output
|
|
89
|
+
isSemanticToken,
|
|
90
|
+
// Include global color tokens
|
|
91
|
+
isGlobalColorToken
|
|
92
|
+
]),
|
|
93
|
+
// Don't include color category tokens -- they are exported separately
|
|
94
|
+
(t) => !isColorCategoryToken(t)
|
|
95
|
+
])
|
|
96
|
+
);
|
|
97
|
+
const formattedTokens = filteredAllTokens.map(format).join("\n");
|
|
98
|
+
const content = `{
|
|
99
|
+
${formattedTokens}
|
|
100
|
+
${colorSchemeProperty}}
|
|
101
|
+
`;
|
|
102
|
+
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
103
|
+
const body = R2.isNotNil(layer) ? `@layer ${layer} {
|
|
104
|
+
${selector} ${content} ${autoSelectorContent}
|
|
105
|
+
}
|
|
106
|
+
` : `${selector} ${content} ${autoSelectorContent}
|
|
107
|
+
`;
|
|
108
|
+
return body;
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
var colorCategory = {
|
|
112
|
+
name: "ds/css-colorcategory",
|
|
113
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
114
|
+
const { outputReferences, usesDtcg } = options;
|
|
115
|
+
const { selector, layer } = platform;
|
|
116
|
+
const format = R2.compose(
|
|
117
|
+
createPropertyFormatter({
|
|
118
|
+
outputReferences,
|
|
119
|
+
dictionary,
|
|
120
|
+
format: "css",
|
|
121
|
+
usesDtcg
|
|
122
|
+
}),
|
|
123
|
+
(token) => ({
|
|
124
|
+
...token,
|
|
125
|
+
name: token.name.replace(/color-\w+-/, "color-"),
|
|
126
|
+
original: {
|
|
127
|
+
...token.original,
|
|
128
|
+
$value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
|
|
129
|
+
}
|
|
130
|
+
})
|
|
131
|
+
);
|
|
132
|
+
const formattedTokens = dictionary.allTokens.map(format).join("\n");
|
|
133
|
+
const content = `{
|
|
134
|
+
${formattedTokens}
|
|
135
|
+
}
|
|
136
|
+
`;
|
|
137
|
+
const body = R2.isNotNil(layer) ? `@layer ${layer} {
|
|
138
|
+
${selector} ${content}
|
|
139
|
+
}
|
|
140
|
+
` : `${selector} ${content}
|
|
141
|
+
`;
|
|
142
|
+
return body;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// src/tokens/process/formats/css/semantic.ts
|
|
147
|
+
import * as R3 from "ramda";
|
|
148
|
+
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
149
|
+
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
150
|
+
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
151
|
+
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
152
|
+
var isInlineTokens = R3.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
153
|
+
var overrideSizingFormula = (format, token) => {
|
|
154
|
+
const [name, value] = format(token).split(":");
|
|
155
|
+
const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
|
|
156
|
+
const round = `round(down, ${calc}, 0.0625rem)`;
|
|
157
|
+
return {
|
|
158
|
+
name,
|
|
159
|
+
round,
|
|
160
|
+
calc
|
|
161
|
+
};
|
|
162
|
+
};
|
|
163
|
+
var formatSizingTokens = (format, tokens) => {
|
|
164
|
+
const { round, calc } = R3.reduce(
|
|
165
|
+
(acc, token) => {
|
|
166
|
+
const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
|
|
167
|
+
return {
|
|
168
|
+
round: [...acc.round, `${name}: ${round2};`],
|
|
169
|
+
calc: [...acc.calc, `${name}: ${calc2};`]
|
|
170
|
+
};
|
|
171
|
+
},
|
|
172
|
+
{ round: [], calc: [] },
|
|
173
|
+
tokens
|
|
174
|
+
);
|
|
175
|
+
return `
|
|
176
|
+
${calc.join("\n")}
|
|
177
|
+
|
|
178
|
+
@supports (width: round(down, .1em, 1px)) {
|
|
179
|
+
${round.join("\n")}
|
|
180
|
+
}`;
|
|
181
|
+
};
|
|
182
|
+
var semantic = {
|
|
183
|
+
name: "ds/css-semantic",
|
|
184
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
185
|
+
const { outputReferences, usesDtcg } = options;
|
|
186
|
+
const { selector, layer } = platform;
|
|
187
|
+
const format = createPropertyFormatter2({
|
|
188
|
+
outputReferences,
|
|
189
|
+
dictionary,
|
|
190
|
+
format: "css",
|
|
191
|
+
usesDtcg
|
|
192
|
+
});
|
|
193
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
194
|
+
const filteredTokens = R3.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
|
|
195
|
+
const [sizingTokens, restTokens] = R3.partition(
|
|
196
|
+
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
197
|
+
filteredTokens
|
|
198
|
+
);
|
|
199
|
+
const formattedTokens = [R3.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
|
|
200
|
+
const content = `{
|
|
201
|
+
${formattedTokens.join("\n")}
|
|
202
|
+
}
|
|
203
|
+
`;
|
|
204
|
+
const body = R3.isNotNil(layer) ? `@layer ${layer} {
|
|
205
|
+
${selector} ${content}
|
|
206
|
+
}
|
|
207
|
+
` : `${selector} ${content}
|
|
208
|
+
`;
|
|
209
|
+
return body;
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// src/tokens/process/formats/css/typography.ts
|
|
214
|
+
import * as R4 from "ramda";
|
|
215
|
+
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
216
|
+
var typographyFontFamilyPredicate = R4.allPass([
|
|
217
|
+
R4.pathSatisfies(R4.includes("typography"), ["path"]),
|
|
218
|
+
R4.pathSatisfies(R4.includes("fontFamily"), ["path"])
|
|
219
|
+
]);
|
|
220
|
+
var typography = {
|
|
221
|
+
name: "ds/css-typography",
|
|
222
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
223
|
+
const { outputReferences, usesDtcg } = options;
|
|
224
|
+
const { selector, layer } = platform;
|
|
225
|
+
const format = createPropertyFormatter3({
|
|
226
|
+
outputReferences,
|
|
227
|
+
dictionary,
|
|
228
|
+
format: "css",
|
|
229
|
+
usesDtcg
|
|
230
|
+
});
|
|
231
|
+
const filteredTokens = R4.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
232
|
+
const formattedTokens = R4.pipe(R4.map(format), R4.join("\n"))(filteredTokens);
|
|
233
|
+
const content = selector ? `${selector} {
|
|
234
|
+
${formattedTokens}
|
|
235
|
+
}` : formattedTokens;
|
|
236
|
+
const body = R4.isNotNil(layer) ? `@layer ${layer} {
|
|
237
|
+
${content}
|
|
238
|
+
}` : content;
|
|
239
|
+
return body;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/tokens/process/formats/css.ts
|
|
244
|
+
var formats = {
|
|
245
|
+
colorScheme,
|
|
246
|
+
colorCategory,
|
|
247
|
+
semantic,
|
|
248
|
+
typography
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
// src/tokens/process/transformers.ts
|
|
252
|
+
import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
|
|
253
|
+
import * as R5 from "ramda";
|
|
254
|
+
var isPx = R5.test(/\b\d+px\b/g);
|
|
255
|
+
var sizeRem = {
|
|
256
|
+
name: "ds/size/toRem",
|
|
257
|
+
type: "value",
|
|
258
|
+
transitive: true,
|
|
259
|
+
filter: (token) => {
|
|
260
|
+
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
261
|
+
const hasWantedPath = pathStartsWithOneOf(["spacing", "sizing", "border-radius", "font-size"], token);
|
|
262
|
+
return hasWantedType && hasWantedPath;
|
|
263
|
+
},
|
|
264
|
+
transform: (token, config) => {
|
|
265
|
+
const value = getValue(token);
|
|
266
|
+
if (isPx(value)) {
|
|
267
|
+
const baseFont = config.basePxFontSize || 16;
|
|
268
|
+
const size = parseInt(value);
|
|
269
|
+
if (size === 0) {
|
|
270
|
+
return "0";
|
|
271
|
+
}
|
|
272
|
+
return `${size / baseFont}rem`;
|
|
273
|
+
}
|
|
274
|
+
return value;
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
var typographyName = {
|
|
278
|
+
name: "name/typography",
|
|
279
|
+
type: "name",
|
|
280
|
+
transitive: true,
|
|
281
|
+
// expanded tokens have different type so we match on path instead
|
|
282
|
+
filter: (token) => pathStartsWithOneOf(["typography"], token),
|
|
283
|
+
transform: (token) => {
|
|
284
|
+
return token.name.replace("-typography", "");
|
|
285
|
+
}
|
|
286
|
+
};
|
|
287
|
+
var resolveMath = {
|
|
288
|
+
name: "ds/resolveMath",
|
|
289
|
+
type: "value",
|
|
290
|
+
transitive: true,
|
|
291
|
+
filter: (token) => {
|
|
292
|
+
const isValidValue = ["string", "object"].includes(typeof getValue(token));
|
|
293
|
+
const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
|
|
294
|
+
return isValidValue && isTokenOfInterest;
|
|
295
|
+
},
|
|
296
|
+
transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
|
|
297
|
+
};
|
|
298
|
+
var unitless = {
|
|
299
|
+
name: "ds/unitless",
|
|
300
|
+
type: "value",
|
|
301
|
+
transitive: true,
|
|
302
|
+
filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
|
|
303
|
+
transform: (token) => parseInt(getValue(token))
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
// src/tokens/process/configs/shared.ts
|
|
307
|
+
var prefix = "ds";
|
|
308
|
+
var basePxFontSize = 16;
|
|
309
|
+
var dsTransformers = [
|
|
310
|
+
"name/kebab",
|
|
311
|
+
resolveMath.name,
|
|
312
|
+
"ts/size/px",
|
|
313
|
+
sizeRem.name,
|
|
314
|
+
unitless.name,
|
|
315
|
+
"ts/typography/fontWeight",
|
|
316
|
+
typographyName.name,
|
|
317
|
+
"ts/color/modifiers",
|
|
318
|
+
"ts/color/css/hexrgba",
|
|
319
|
+
"ts/size/lineheight",
|
|
320
|
+
"shadow/css/shorthand"
|
|
321
|
+
];
|
|
322
|
+
|
|
323
|
+
// src/tokens/process/configs/semantic.ts
|
|
324
|
+
var semanticVariables = ({ theme }) => {
|
|
325
|
+
const selector = `:root`;
|
|
326
|
+
const layer = `ds.theme.semantic`;
|
|
327
|
+
return {
|
|
328
|
+
preprocessors: ["tokens-studio"],
|
|
329
|
+
platforms: {
|
|
330
|
+
css: {
|
|
331
|
+
// custom
|
|
332
|
+
theme,
|
|
333
|
+
basePxFontSize,
|
|
334
|
+
selector,
|
|
335
|
+
layer,
|
|
336
|
+
//
|
|
337
|
+
prefix,
|
|
338
|
+
buildPath: `${theme}/`,
|
|
339
|
+
transforms: dsTransformers,
|
|
340
|
+
files: [
|
|
341
|
+
{
|
|
342
|
+
destination: `semantic.css`,
|
|
343
|
+
format: formats.semantic.name,
|
|
344
|
+
filter: (token) => {
|
|
345
|
+
const isUwantedToken = R6.anyPass([R6.includes("primitives/global")])(token.filePath);
|
|
346
|
+
const isPrivateToken = R6.includes("_", token.path);
|
|
347
|
+
const unwantedPaths = pathStartsWithOneOf(["font-size", "line-height", "letter-spacing"], token);
|
|
348
|
+
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
349
|
+
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
350
|
+
return unwantedTokens;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
],
|
|
354
|
+
options: {
|
|
355
|
+
outputReferences: (token, options) => {
|
|
356
|
+
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
357
|
+
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
|
|
358
|
+
return (include || isWantedSize) && outputReferencesFilter(token, options);
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
export {
|
|
366
|
+
semanticVariables
|
|
367
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Config as StyleDictionaryConfig } from 'style-dictionary/types';
|
|
2
|
+
import type { ThemePermutation } from '../../types.js';
|
|
3
|
+
export type GetStyleDictionaryConfig = (permutation: ThemePermutation) => StyleDictionaryConfig | {
|
|
4
|
+
config: StyleDictionaryConfig;
|
|
5
|
+
permutationOverrides?: Partial<ThemePermutation>;
|
|
6
|
+
}[];
|
|
7
|
+
export declare const prefix = "ds";
|
|
8
|
+
export declare const basePxFontSize = 16;
|
|
9
|
+
export declare const dsTransformers: string[];
|
|
10
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAC9E,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAGvD,MAAM,MAAM,wBAAwB,GAAG,CACrC,WAAW,EAAE,gBAAgB,KAC1B,qBAAqB,GAAG;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAAE,EAAE,CAAC;AAEnH,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,cAAc,KAAK,CAAC;AAEjC,eAAO,MAAM,cAAc,UAY1B,CAAC"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
// src/tokens/process/transformers.ts
|
|
2
|
+
import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
|
|
3
|
+
import * as R2 from "ramda";
|
|
4
|
+
|
|
5
|
+
// src/tokens/utils.ts
|
|
6
|
+
import * as R from "ramda";
|
|
7
|
+
var mapToLowerCase = R.map(R.toLower);
|
|
8
|
+
var hasAnyTruth = R.any(R.equals(true));
|
|
9
|
+
var getType = (token) => (token.$type ?? token.type) || "";
|
|
10
|
+
var getValue = (token) => token.$value ?? token.value;
|
|
11
|
+
var typeEquals = R.curry((types, token) => {
|
|
12
|
+
if (R.isNil(token)) {
|
|
13
|
+
return false;
|
|
14
|
+
}
|
|
15
|
+
return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
|
|
16
|
+
});
|
|
17
|
+
var pathStartsWithOneOf = R.curry((paths, token) => {
|
|
18
|
+
if (R.isNil(token)) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
const tokenPath = mapToLowerCase(token.path);
|
|
22
|
+
const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
|
|
23
|
+
return hasAnyTruth(matchPathsStartingWith);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// src/tokens/process/transformers.ts
|
|
27
|
+
var isPx = R2.test(/\b\d+px\b/g);
|
|
28
|
+
var sizeRem = {
|
|
29
|
+
name: "ds/size/toRem",
|
|
30
|
+
type: "value",
|
|
31
|
+
transitive: true,
|
|
32
|
+
filter: (token) => {
|
|
33
|
+
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
34
|
+
const hasWantedPath = pathStartsWithOneOf(["spacing", "sizing", "border-radius", "font-size"], token);
|
|
35
|
+
return hasWantedType && hasWantedPath;
|
|
36
|
+
},
|
|
37
|
+
transform: (token, config) => {
|
|
38
|
+
const value = getValue(token);
|
|
39
|
+
if (isPx(value)) {
|
|
40
|
+
const baseFont = config.basePxFontSize || 16;
|
|
41
|
+
const size = parseInt(value);
|
|
42
|
+
if (size === 0) {
|
|
43
|
+
return "0";
|
|
44
|
+
}
|
|
45
|
+
return `${size / baseFont}rem`;
|
|
46
|
+
}
|
|
47
|
+
return value;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
var typographyName = {
|
|
51
|
+
name: "name/typography",
|
|
52
|
+
type: "name",
|
|
53
|
+
transitive: true,
|
|
54
|
+
// expanded tokens have different type so we match on path instead
|
|
55
|
+
filter: (token) => pathStartsWithOneOf(["typography"], token),
|
|
56
|
+
transform: (token) => {
|
|
57
|
+
return token.name.replace("-typography", "");
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
var resolveMath = {
|
|
61
|
+
name: "ds/resolveMath",
|
|
62
|
+
type: "value",
|
|
63
|
+
transitive: true,
|
|
64
|
+
filter: (token) => {
|
|
65
|
+
const isValidValue = ["string", "object"].includes(typeof getValue(token));
|
|
66
|
+
const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
|
|
67
|
+
return isValidValue && isTokenOfInterest;
|
|
68
|
+
},
|
|
69
|
+
transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
|
|
70
|
+
};
|
|
71
|
+
var unitless = {
|
|
72
|
+
name: "ds/unitless",
|
|
73
|
+
type: "value",
|
|
74
|
+
transitive: true,
|
|
75
|
+
filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
|
|
76
|
+
transform: (token) => parseInt(getValue(token))
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
// src/tokens/process/configs/shared.ts
|
|
80
|
+
var prefix = "ds";
|
|
81
|
+
var basePxFontSize = 16;
|
|
82
|
+
var dsTransformers = [
|
|
83
|
+
"name/kebab",
|
|
84
|
+
resolveMath.name,
|
|
85
|
+
"ts/size/px",
|
|
86
|
+
sizeRem.name,
|
|
87
|
+
unitless.name,
|
|
88
|
+
"ts/typography/fontWeight",
|
|
89
|
+
typographyName.name,
|
|
90
|
+
"ts/color/modifiers",
|
|
91
|
+
"ts/color/css/hexrgba",
|
|
92
|
+
"ts/size/lineheight",
|
|
93
|
+
"shadow/css/shorthand"
|
|
94
|
+
];
|
|
95
|
+
export {
|
|
96
|
+
basePxFontSize,
|
|
97
|
+
dsTransformers,
|
|
98
|
+
prefix
|
|
99
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"storefront.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/storefront.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,wBAAwB,EAA0C,MAAM,aAAa,CAAC;AAEpG,eAAO,MAAM,gBAAgB,EAAE,wBAqC9B,CAAC"}
|