@digdir/designsystemet 1.0.0-next.35 → 1.0.0-next.36
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/README.md +16 -0
- package/dist/{types/bin → bin}/designsystemet.d.ts.map +1 -1
- package/dist/bin/designsystemet.js +14 -15
- package/dist/src/colors/index.d.ts.map +1 -0
- package/dist/{types/src → src}/colors/theme.d.ts +8 -3
- package/dist/src/colors/theme.d.ts.map +1 -0
- package/dist/src/colors/theme.js +17 -18
- package/dist/{types/src → src}/colors/types.d.ts +0 -1
- package/dist/src/colors/types.d.ts.map +1 -0
- package/dist/{types/src → src}/colors/utils.d.ts +7 -1
- package/dist/src/colors/utils.d.ts.map +1 -0
- package/dist/src/colors/utils.js +13 -6
- package/dist/src/index.d.ts +3 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +2 -0
- package/dist/src/init/createTokensPackage.d.ts.map +1 -0
- package/dist/src/init/generateMetadataJson.d.ts.map +1 -0
- package/dist/src/init/generateThemesJson.d.ts.map +1 -0
- package/dist/src/init/index.d.ts.map +1 -0
- package/dist/src/init/nextStepsMarkdown.d.ts.map +1 -0
- package/dist/src/init/utils.d.ts.map +1 -0
- package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
- package/dist/src/migrations/beta-to-v1.js +4 -4
- package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +1 -0
- package/dist/src/migrations/codemods/jsx/run.d.ts.map +1 -0
- package/dist/src/migrations/index.d.ts.map +1 -0
- package/dist/src/migrations/react-beta-to-v1.d.ts.map +1 -0
- package/dist/src/tokens/build/actions.d.ts.map +1 -0
- package/dist/src/tokens/build/builtin-colors.css +87 -0
- package/dist/src/tokens/build/configs.d.ts +21 -0
- package/dist/src/tokens/build/configs.d.ts.map +1 -0
- package/dist/src/tokens/build/configs.js +114 -61
- package/dist/src/tokens/build/formats/css.d.ts +13 -0
- package/dist/src/tokens/build/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/build/formats/css.js +55 -3
- package/dist/src/tokens/build/formats/js-tokens.d.ts.map +1 -0
- package/dist/src/tokens/build/formats/js-tokens.js +2 -2
- package/dist/{types/src → src}/tokens/build/transformers.d.ts +1 -0
- package/dist/src/tokens/build/transformers.d.ts.map +1 -0
- package/dist/src/tokens/build/transformers.js +13 -0
- package/dist/src/tokens/build/types.d.ts +44 -0
- package/dist/src/tokens/build/types.d.ts.map +1 -0
- package/dist/src/tokens/build/types.js +7 -0
- package/dist/src/tokens/build/utils/entryfile.d.ts.map +1 -0
- package/dist/src/tokens/build/utils/entryfile.js +11 -3
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts +35 -0
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +112 -0
- package/dist/src/tokens/build/utils/noCase.d.ts.map +1 -0
- package/dist/{types/src → src}/tokens/build/utils/utils.d.ts +3 -0
- package/dist/src/tokens/build/utils/utils.d.ts.map +1 -0
- package/dist/src/tokens/build/utils/utils.js +15 -0
- package/dist/src/tokens/build.d.ts +17 -0
- package/dist/src/tokens/build.d.ts.map +1 -0
- package/dist/src/tokens/build.js +76 -77
- package/dist/{types/src → src}/tokens/create.d.ts +5 -0
- package/dist/src/tokens/create.d.ts.map +1 -0
- package/dist/src/tokens/create.js +13 -10
- package/dist/src/tokens/design-tokens/default/primitives/globals.json +2 -8
- package/dist/src/tokens/design-tokens/default/semantic/style.json +86 -182
- package/dist/src/tokens/design-tokens/template/$metadata.json +4 -0
- package/dist/src/tokens/design-tokens/template/$themes.json +129 -13
- package/dist/src/tokens/design-tokens/template/semantic/color-base-file.json +262 -0
- package/dist/src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json +62 -0
- package/dist/src/tokens/design-tokens/template/semantic/semantic-color-template.json +62 -0
- package/dist/src/tokens/design-tokens/template/themes/theme-base-file.json +53 -0
- package/dist/src/tokens/design-tokens/template/themes/theme-color-template.json +62 -0
- package/dist/src/tokens/index.d.ts +2 -0
- package/dist/src/tokens/index.d.ts.map +1 -0
- package/dist/src/tokens/index.js +5 -0
- package/dist/src/tokens/template.d.ts.map +1 -0
- package/dist/src/tokens/template.js +36 -4
- package/dist/{types/src → src}/tokens/types.d.ts +5 -2
- package/dist/src/tokens/types.d.ts.map +1 -0
- package/dist/{types/src → src}/tokens/write/generate$metadata.d.ts +2 -1
- package/dist/src/tokens/write/generate$metadata.d.ts.map +1 -0
- package/dist/src/tokens/write/generate$metadata.js +3 -1
- package/dist/{types/src → src}/tokens/write/generate$themes.d.ts +2 -1
- package/dist/src/tokens/write/generate$themes.d.ts.map +1 -0
- package/dist/src/tokens/write/generate$themes.js +16 -2
- package/dist/{types/src → src}/tokens/write.d.ts +2 -1
- package/dist/src/tokens/write.d.ts.map +1 -0
- package/dist/src/tokens/write.js +93 -5
- package/package.json +9 -8
- package/dist/src/init/template/prettier.config.js +0 -5
- package/dist/src/tokens/build/utils/permutateThemes.js +0 -64
- package/dist/src/tokens/design-tokens/default/semantic/color.json +0 -572
- package/dist/src/tokens/design-tokens/template/themes/theme.json +0 -334
- package/dist/types/src/colors/index.d.ts.map +0 -1
- package/dist/types/src/colors/theme.d.ts.map +0 -1
- package/dist/types/src/colors/types.d.ts.map +0 -1
- package/dist/types/src/colors/utils.d.ts.map +0 -1
- package/dist/types/src/init/createTokensPackage.d.ts.map +0 -1
- package/dist/types/src/init/generateMetadataJson.d.ts.map +0 -1
- package/dist/types/src/init/generateThemesJson.d.ts.map +0 -1
- package/dist/types/src/init/index.d.ts.map +0 -1
- package/dist/types/src/init/nextStepsMarkdown.d.ts.map +0 -1
- package/dist/types/src/init/template/prettier.config.d.mts +0 -9
- package/dist/types/src/init/template/prettier.config.d.mts.map +0 -1
- package/dist/types/src/init/utils.d.ts.map +0 -1
- package/dist/types/src/migrations/beta-to-v1.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/css/run.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +0 -1
- package/dist/types/src/migrations/index.d.ts.map +0 -1
- package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +0 -1
- package/dist/types/src/tokens/build/actions.d.ts.map +0 -1
- package/dist/types/src/tokens/build/configs.d.ts +0 -31
- package/dist/types/src/tokens/build/configs.d.ts.map +0 -1
- package/dist/types/src/tokens/build/formats/css.d.ts +0 -5
- package/dist/types/src/tokens/build/formats/css.d.ts.map +0 -1
- package/dist/types/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
- package/dist/types/src/tokens/build/transformers.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/entryfile.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/noCase.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/permutateThemes.d.ts +0 -17
- package/dist/types/src/tokens/build/utils/permutateThemes.d.ts.map +0 -1
- package/dist/types/src/tokens/build/utils/utils.d.ts.map +0 -1
- package/dist/types/src/tokens/build.d.ts +0 -13
- package/dist/types/src/tokens/build.d.ts.map +0 -1
- package/dist/types/src/tokens/create.d.ts.map +0 -1
- package/dist/types/src/tokens/template.d.ts.map +0 -1
- package/dist/types/src/tokens/types.d.ts.map +0 -1
- package/dist/types/src/tokens/write/generate$metadata.d.ts.map +0 -1
- package/dist/types/src/tokens/write/generate$themes.d.ts.map +0 -1
- package/dist/types/src/tokens/write.d.ts.map +0 -1
- /package/dist/{types/bin → bin}/designsystemet.d.ts +0 -0
- /package/dist/{types/src → src}/colors/index.d.ts +0 -0
- /package/dist/{types/src → src}/init/createTokensPackage.d.ts +0 -0
- /package/dist/{types/src → src}/init/generateMetadataJson.d.ts +0 -0
- /package/dist/{types/src → src}/init/generateThemesJson.d.ts +0 -0
- /package/dist/{types/src → src}/init/index.d.ts +0 -0
- /package/dist/{types/src → src}/init/nextStepsMarkdown.d.ts +0 -0
- /package/dist/{types/src → src}/init/utils.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/beta-to-v1.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/css/plugins.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/css/run.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/jsx/classname-prefix.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/codemods/jsx/run.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/index.d.ts +0 -0
- /package/dist/{types/src → src}/migrations/react-beta-to-v1.d.ts +0 -0
- /package/dist/{types/src → src}/tokens/build/actions.d.ts +0 -0
- /package/dist/{types/src → src}/tokens/build/formats/js-tokens.d.ts +0 -0
- /package/dist/{types/src → src}/tokens/build/utils/entryfile.d.ts +0 -0
- /package/dist/{types/src → src}/tokens/build/utils/noCase.d.ts +0 -0
- /package/dist/{types/src → src}/tokens/template.d.ts +0 -0
|
@@ -2,27 +2,28 @@ import { expandTypesMap, register } from "@tokens-studio/sd-transforms";
|
|
|
2
2
|
import * as R from "ramda";
|
|
3
3
|
import StyleDictionary from "style-dictionary";
|
|
4
4
|
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
5
|
-
import
|
|
5
|
+
import { DEFAULT_COLOR, buildOptions } from "../build.js";
|
|
6
|
+
import { formats } from "./formats/css.js";
|
|
6
7
|
import { jsTokens } from "./formats/js-tokens.js";
|
|
7
|
-
import { nameKebab, sizeRem, typographyName } from "./transformers.js";
|
|
8
|
-
import {
|
|
9
|
-
import { pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
|
|
8
|
+
import { nameKebab, resolveMath, sizeRem, typographyName } from "./transformers.js";
|
|
9
|
+
import { getMultidimensionalThemes } from "./utils/getMultidimensionalThemes.js";
|
|
10
|
+
import { isColorCategoryToken, pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
|
|
10
11
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
11
12
|
const usesDtcg = true;
|
|
12
13
|
const prefix = "ds";
|
|
13
14
|
const basePxFontSize = 16;
|
|
14
|
-
const separator = "_";
|
|
15
15
|
const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
|
|
16
16
|
StyleDictionary.registerTransform(sizeRem);
|
|
17
17
|
StyleDictionary.registerTransform(nameKebab);
|
|
18
18
|
StyleDictionary.registerTransform(typographyName);
|
|
19
|
+
StyleDictionary.registerTransform(resolveMath);
|
|
19
20
|
StyleDictionary.registerFormat(jsTokens);
|
|
20
|
-
|
|
21
|
-
StyleDictionary.registerFormat(
|
|
22
|
-
|
|
21
|
+
for (const format of Object.values(formats)) {
|
|
22
|
+
StyleDictionary.registerFormat(format);
|
|
23
|
+
}
|
|
23
24
|
const dsTransformers = [
|
|
24
25
|
nameKebab.name,
|
|
25
|
-
|
|
26
|
+
resolveMath.name,
|
|
26
27
|
"ts/size/px",
|
|
27
28
|
sizeRem.name,
|
|
28
29
|
"ts/typography/fontWeight",
|
|
@@ -33,17 +34,13 @@ const dsTransformers = [
|
|
|
33
34
|
"shadow/css/shorthand"
|
|
34
35
|
];
|
|
35
36
|
const paritionPrimitives = R.partition(R.test(/(?!.*global\.json).*primitives.*/));
|
|
36
|
-
const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
|
|
37
37
|
const outputColorReferences = (token) => {
|
|
38
38
|
if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) && R.includes("semantic/color", token.filePath)) {
|
|
39
39
|
return true;
|
|
40
40
|
}
|
|
41
41
|
return false;
|
|
42
42
|
};
|
|
43
|
-
const
|
|
44
|
-
separator
|
|
45
|
-
});
|
|
46
|
-
const colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
43
|
+
const colorModeVariables = ({ mode = "light", theme }, { outPath }) => {
|
|
47
44
|
const selector = `${mode === "light" ? ":root, " : ""}[data-ds-color-mode="${mode}"]`;
|
|
48
45
|
const layer = `ds.theme.color-mode.${mode}`;
|
|
49
46
|
return {
|
|
@@ -70,16 +67,74 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
70
67
|
],
|
|
71
68
|
options: {
|
|
72
69
|
fileHeader,
|
|
73
|
-
outputReferences:
|
|
70
|
+
outputReferences: false
|
|
74
71
|
}
|
|
75
72
|
}
|
|
76
73
|
}
|
|
77
74
|
};
|
|
78
75
|
};
|
|
79
|
-
const
|
|
76
|
+
const colorCategoryVariables = (category) => ({ mode, theme, [`${category}-color`]: color }, { outPath }) => {
|
|
77
|
+
const layer = `ds.theme.color`;
|
|
78
|
+
const isDefault = color === buildOptions?.accentColor;
|
|
79
|
+
const selector = `${isDefault ? ":root, " : ""}[data-color="${color}"]`;
|
|
80
|
+
const config = {
|
|
81
|
+
usesDtcg,
|
|
82
|
+
preprocessors: ["tokens-studio"],
|
|
83
|
+
platforms: {
|
|
84
|
+
css: {
|
|
85
|
+
// custom
|
|
86
|
+
outPath,
|
|
87
|
+
mode,
|
|
88
|
+
theme,
|
|
89
|
+
selector,
|
|
90
|
+
layer,
|
|
91
|
+
//
|
|
92
|
+
prefix,
|
|
93
|
+
buildPath: `${outPath}/${theme}/`,
|
|
94
|
+
transforms: dsTransformers,
|
|
95
|
+
files: [
|
|
96
|
+
{
|
|
97
|
+
destination: `color/${color}.css`,
|
|
98
|
+
format: formats.colorcategory.name,
|
|
99
|
+
filter: (token) => isColorCategoryToken(token, category)
|
|
100
|
+
}
|
|
101
|
+
],
|
|
102
|
+
options: {
|
|
103
|
+
fileHeader,
|
|
104
|
+
outputReferences: true
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
if (isDefault && color !== DEFAULT_COLOR) {
|
|
110
|
+
console.log(
|
|
111
|
+
`Creating "${DEFAULT_COLOR}" color variables pointing to "${color}", since a color named "${DEFAULT_COLOR}" is not defined`
|
|
112
|
+
);
|
|
113
|
+
const defaultColorConfig = R.mergeDeepRight(config, {
|
|
114
|
+
platforms: {
|
|
115
|
+
css: {
|
|
116
|
+
selector: ":root",
|
|
117
|
+
files: [
|
|
118
|
+
{
|
|
119
|
+
...config.platforms?.css?.files?.[0],
|
|
120
|
+
destination: `color/${DEFAULT_COLOR}.css`
|
|
121
|
+
}
|
|
122
|
+
],
|
|
123
|
+
options: { replaceCategoryWith: DEFAULT_COLOR }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
return [
|
|
128
|
+
{ config },
|
|
129
|
+
{ config: defaultColorConfig, permutationOverrides: { "main-color": `${DEFAULT_COLOR} \u2192 ${color}` } }
|
|
130
|
+
];
|
|
131
|
+
}
|
|
132
|
+
return config;
|
|
133
|
+
};
|
|
134
|
+
const semanticVariables = ({ theme }, { outPath }) => {
|
|
80
135
|
const selector = `:root`;
|
|
81
136
|
const layer = `ds.theme.semantic`;
|
|
82
|
-
const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing"
|
|
137
|
+
const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing"], token);
|
|
83
138
|
return {
|
|
84
139
|
usesDtcg,
|
|
85
140
|
preprocessors: ["tokens-studio"],
|
|
@@ -105,13 +160,16 @@ const semanticVariables = ({ outPath, theme }) => {
|
|
|
105
160
|
],
|
|
106
161
|
options: {
|
|
107
162
|
fileHeader,
|
|
108
|
-
outputReferences: (token, options) =>
|
|
163
|
+
outputReferences: (token, options) => {
|
|
164
|
+
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
165
|
+
return (include || isCalculatedToken(token)) && outputReferencesFilter(token, options);
|
|
166
|
+
}
|
|
109
167
|
}
|
|
110
168
|
}
|
|
111
169
|
}
|
|
112
170
|
};
|
|
113
171
|
};
|
|
114
|
-
const typescriptTokens = ({ mode
|
|
172
|
+
const typescriptTokens = ({ mode, theme }, { outPath }) => {
|
|
115
173
|
return {
|
|
116
174
|
usesDtcg,
|
|
117
175
|
preprocessors: ["tokens-studio"],
|
|
@@ -143,7 +201,7 @@ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
|
|
|
143
201
|
}
|
|
144
202
|
};
|
|
145
203
|
};
|
|
146
|
-
const typographyVariables = ({
|
|
204
|
+
const typographyVariables = ({ theme, typography }, { outPath }) => {
|
|
147
205
|
const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
|
|
148
206
|
const layer = `ds.theme.typography.${typography}`;
|
|
149
207
|
return {
|
|
@@ -192,47 +250,42 @@ const typographyVariables = ({ outPath, theme, typography }) => {
|
|
|
192
250
|
}
|
|
193
251
|
};
|
|
194
252
|
};
|
|
195
|
-
const
|
|
196
|
-
const {
|
|
197
|
-
selectedTokenSets = [],
|
|
198
|
-
mode = "unknown",
|
|
199
|
-
theme = "unknown",
|
|
200
|
-
semantic = "unknown",
|
|
201
|
-
size = "unknown",
|
|
202
|
-
typography = "unknown"
|
|
203
|
-
} = permutatedTheme;
|
|
204
|
-
if (hasUnknownProps(permutatedTheme)) {
|
|
205
|
-
throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
|
|
206
|
-
}
|
|
207
|
-
const setsWithPaths = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
|
|
208
|
-
const [source, include] = paritionPrimitives(setsWithPaths);
|
|
209
|
-
const config_ = getConfig({
|
|
210
|
-
outPath,
|
|
211
|
-
theme,
|
|
212
|
-
mode,
|
|
213
|
-
semantic,
|
|
214
|
-
size,
|
|
215
|
-
typography
|
|
216
|
-
});
|
|
217
|
-
const config = {
|
|
218
|
-
...config_,
|
|
219
|
-
log: {
|
|
220
|
-
...config_?.log,
|
|
221
|
-
verbosity: logVerbosity
|
|
222
|
-
},
|
|
223
|
-
source,
|
|
224
|
-
include
|
|
225
|
-
};
|
|
226
|
-
return { mode, theme, semantic, size, typography, config };
|
|
227
|
-
}).sort();
|
|
228
|
-
export {
|
|
229
|
-
basePxFontSize,
|
|
253
|
+
const configs = {
|
|
230
254
|
colorModeVariables,
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
255
|
+
mainColorVariables: colorCategoryVariables("main"),
|
|
256
|
+
supportColorVariables: colorCategoryVariables("support"),
|
|
257
|
+
typographyVariables,
|
|
234
258
|
semanticVariables,
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
259
|
+
typescriptTokens
|
|
260
|
+
};
|
|
261
|
+
const getConfigsForThemeDimensions = (getConfig, themes, dimensions, options) => {
|
|
262
|
+
const { outPath, tokensDir } = options;
|
|
263
|
+
const permutations = getMultidimensionalThemes(themes, dimensions);
|
|
264
|
+
return permutations.flatMap(({ selectedTokenSets, permutation }) => {
|
|
265
|
+
const setsWithPaths = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
|
|
266
|
+
const [source, include] = paritionPrimitives(setsWithPaths);
|
|
267
|
+
const configOrConfigs = getConfig(permutation, { outPath });
|
|
268
|
+
const configs_ = Array.isArray(configOrConfigs) ? configOrConfigs : [{ config: configOrConfigs }];
|
|
269
|
+
const configs2 = configs_.map(({ config, permutationOverrides }) => {
|
|
270
|
+
return {
|
|
271
|
+
permutation: { ...permutation, ...permutationOverrides },
|
|
272
|
+
config: {
|
|
273
|
+
...config,
|
|
274
|
+
log: {
|
|
275
|
+
...config?.log,
|
|
276
|
+
verbosity: buildOptions?.verbose ? "verbose" : "silent"
|
|
277
|
+
},
|
|
278
|
+
source,
|
|
279
|
+
include
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
});
|
|
283
|
+
return configs2;
|
|
284
|
+
}).sort();
|
|
285
|
+
};
|
|
286
|
+
export {
|
|
287
|
+
basePxFontSize,
|
|
288
|
+
configs,
|
|
289
|
+
getConfigsForThemeDimensions,
|
|
290
|
+
prefix
|
|
238
291
|
};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Format } from 'style-dictionary/types';
|
|
2
|
+
declare module 'style-dictionary/types' {
|
|
3
|
+
interface LocalOptions {
|
|
4
|
+
replaceCategoryWith?: string;
|
|
5
|
+
}
|
|
6
|
+
}
|
|
7
|
+
export declare const formats: {
|
|
8
|
+
colormode: Format;
|
|
9
|
+
colorcategory: Format;
|
|
10
|
+
semantic: Format;
|
|
11
|
+
typography: Format;
|
|
12
|
+
};
|
|
13
|
+
//# sourceMappingURL=css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/css.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAuDrD,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,YAAY;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B;CACF;AA2GD,eAAO,MAAM,OAAO;;;;;CAKc,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { createPropertyFormatter, fileHeader, usesReferences } from "style-dictionary/utils";
|
|
3
|
-
import {
|
|
3
|
+
import { colorCategories } from "../types.js";
|
|
4
|
+
import { getValue, isColorCategoryToken, isGlobalColorToken, isSemanticToken } from "../utils/utils.js";
|
|
4
5
|
const prefersColorScheme = (mode, content) => `
|
|
5
6
|
@media (prefers-color-scheme: ${mode}) {
|
|
6
7
|
[data-ds-color-mode="auto"] ${content}
|
|
@@ -23,7 +24,19 @@ const colormode = {
|
|
|
23
24
|
const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `
|
|
24
25
|
color-scheme: ${mode_};
|
|
25
26
|
` : "";
|
|
26
|
-
const
|
|
27
|
+
const filteredAllTokens = allTokens.filter(
|
|
28
|
+
R.allPass([
|
|
29
|
+
R.anyPass([
|
|
30
|
+
// Include semantic tokens in the output
|
|
31
|
+
isSemanticToken,
|
|
32
|
+
// Include global color tokens
|
|
33
|
+
isGlobalColorToken
|
|
34
|
+
]),
|
|
35
|
+
// Don't include color category tokens -- they are exported separately
|
|
36
|
+
(t) => !isColorCategoryToken(t)
|
|
37
|
+
])
|
|
38
|
+
);
|
|
39
|
+
const formattedTokens = filteredAllTokens.map(format).join("\n");
|
|
27
40
|
const content = `{
|
|
28
41
|
${formattedTokens}
|
|
29
42
|
${colorSchemeProperty}}
|
|
@@ -37,6 +50,40 @@ ${selector} ${content} ${autoSelectorContent}
|
|
|
37
50
|
return header + body;
|
|
38
51
|
}
|
|
39
52
|
};
|
|
53
|
+
const colorcategory = {
|
|
54
|
+
name: "ds/css-colorcategory",
|
|
55
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
56
|
+
const { outputReferences, usesDtcg, replaceCategoryWith = "" } = options;
|
|
57
|
+
const { selector, layer } = platform;
|
|
58
|
+
const header = await fileHeader({ file });
|
|
59
|
+
const format = R.compose(
|
|
60
|
+
createPropertyFormatter({
|
|
61
|
+
outputReferences,
|
|
62
|
+
dictionary,
|
|
63
|
+
format: "css",
|
|
64
|
+
usesDtcg
|
|
65
|
+
}),
|
|
66
|
+
(token) => ({
|
|
67
|
+
...token,
|
|
68
|
+
name: token.name.replace(
|
|
69
|
+
new RegExp(`-(${colorCategories.main}|${colorCategories.support})-`),
|
|
70
|
+
replaceCategoryWith ? `-${replaceCategoryWith}-` : "-"
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
);
|
|
74
|
+
const formattedTokens = dictionary.allTokens.map(format).join("\n");
|
|
75
|
+
const content = `{
|
|
76
|
+
${formattedTokens}
|
|
77
|
+
}
|
|
78
|
+
`;
|
|
79
|
+
const body = R.isNotNil(layer) ? `@layer ${layer} {
|
|
80
|
+
${selector} ${content}
|
|
81
|
+
}
|
|
82
|
+
` : `${selector} ${content}
|
|
83
|
+
`;
|
|
84
|
+
return header + body;
|
|
85
|
+
}
|
|
86
|
+
};
|
|
40
87
|
const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}: calc(${R.trim(split[1])});`);
|
|
41
88
|
const semantic = {
|
|
42
89
|
name: "ds/css-semantic",
|
|
@@ -56,6 +103,7 @@ const semantic = {
|
|
|
56
103
|
if (isCalculatedToken?.(token, options)) {
|
|
57
104
|
return calculatedVariable(format(token));
|
|
58
105
|
}
|
|
106
|
+
return format(token);
|
|
59
107
|
}
|
|
60
108
|
return format(token);
|
|
61
109
|
}, dictionary.allTokens);
|
|
@@ -98,8 +146,12 @@ ${content}
|
|
|
98
146
|
return header + body;
|
|
99
147
|
}
|
|
100
148
|
};
|
|
101
|
-
|
|
149
|
+
const formats = {
|
|
102
150
|
colormode,
|
|
151
|
+
colorcategory,
|
|
103
152
|
semantic,
|
|
104
153
|
typography
|
|
105
154
|
};
|
|
155
|
+
export {
|
|
156
|
+
formats
|
|
157
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"js-tokens.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/js-tokens.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;AAmBvE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MA2BtB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
|
|
3
|
-
import { getType } from "../utils/utils.js";
|
|
3
|
+
import { getType, isColorCategoryToken } from "../utils/utils.js";
|
|
4
4
|
const groupByType = R.groupBy((token) => getType(token));
|
|
5
5
|
const removeUnwatedTokens = R.filter(
|
|
6
|
-
(token) => !["ds-base-spacing", "ds-base-sizing"].includes(token.name)
|
|
6
|
+
(token) => !["ds-base-spacing", "ds-base-sizing"].includes(token.name) && !isColorCategoryToken(token)
|
|
7
7
|
);
|
|
8
8
|
const dissocExtensions = R.pipe(R.dissoc("$extensions"), R.dissocPath(["original", "$extensions"]));
|
|
9
9
|
const removeUnwatedProps = R.map((token) => dissocExtensions(token));
|
|
@@ -2,4 +2,5 @@ import type { Transform } from 'style-dictionary/types';
|
|
|
2
2
|
export declare const sizeRem: Transform;
|
|
3
3
|
export declare const nameKebab: Transform;
|
|
4
4
|
export declare const typographyName: Transform;
|
|
5
|
+
export declare const resolveMath: Transform;
|
|
5
6
|
//# sourceMappingURL=transformers.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD,eAAO,MAAM,OAAO,EAAE,SAyBrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,SASvB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,SAS5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,SAWzB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
|
|
1
2
|
import * as R from "ramda";
|
|
2
3
|
import { noCase } from "./utils/noCase.js";
|
|
3
4
|
import { getValue, pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
|
|
@@ -44,8 +45,20 @@ const typographyName = {
|
|
|
44
45
|
return token.name.replace("-typography", "");
|
|
45
46
|
}
|
|
46
47
|
};
|
|
48
|
+
const resolveMath = {
|
|
49
|
+
name: "ds/resolveMath",
|
|
50
|
+
type: "value",
|
|
51
|
+
transitive: true,
|
|
52
|
+
filter: (token) => {
|
|
53
|
+
const isValidValue = ["string", "object"].includes(typeof (token.$value ?? token.value));
|
|
54
|
+
const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
|
|
55
|
+
return isValidValue && isTokenOfInterest;
|
|
56
|
+
},
|
|
57
|
+
transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
|
|
58
|
+
};
|
|
47
59
|
export {
|
|
48
60
|
nameKebab,
|
|
61
|
+
resolveMath,
|
|
49
62
|
sizeRem,
|
|
50
63
|
typographyName
|
|
51
64
|
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { Config as StyleDictionaryConfig, TransformedToken } from 'style-dictionary/types';
|
|
2
|
+
import type { GetStyleDictionaryConfig } from './configs';
|
|
3
|
+
export declare const colorCategories: {
|
|
4
|
+
readonly main: "main";
|
|
5
|
+
readonly support: "support";
|
|
6
|
+
};
|
|
7
|
+
export type ColorCategories = keyof typeof colorCategories;
|
|
8
|
+
/**
|
|
9
|
+
* A multi-dimensional theme is a concrete permutation of the possible theme dimensions
|
|
10
|
+
*/
|
|
11
|
+
export type ThemePermutation = {
|
|
12
|
+
mode: string;
|
|
13
|
+
'main-color': string;
|
|
14
|
+
'support-color': string;
|
|
15
|
+
semantic: string;
|
|
16
|
+
size: string;
|
|
17
|
+
theme: string;
|
|
18
|
+
typography: string;
|
|
19
|
+
};
|
|
20
|
+
export type ThemeDimension = keyof ThemePermutation;
|
|
21
|
+
export type IsCalculatedToken = (token: TransformedToken, options?: StyleDictionaryConfig) => boolean;
|
|
22
|
+
export type GetSdConfigOptions = {
|
|
23
|
+
outPath: string;
|
|
24
|
+
tokensDir: string;
|
|
25
|
+
};
|
|
26
|
+
export type BuildConfig = {
|
|
27
|
+
/** Optional name of the build config - only used in the console output */
|
|
28
|
+
name?: string;
|
|
29
|
+
/** Style Dictionary configuration creator */
|
|
30
|
+
getConfig: GetStyleDictionaryConfig;
|
|
31
|
+
/** Which theme dimensions to include. `theme` (e.g. digdir/altinn) is always included. */
|
|
32
|
+
dimensions: ThemeDimension[];
|
|
33
|
+
/** Custom options used when creating Style Dictionary configs. If not supplied, the default is used */
|
|
34
|
+
options?: Partial<GetSdConfigOptions>;
|
|
35
|
+
/** Custom build function. If not supplied, the default is used. */
|
|
36
|
+
build?: (sdConfigs: SDConfigForThemePermutation[], options: GetSdConfigOptions) => Promise<void>;
|
|
37
|
+
/** Whether the build config is enabled. @default () => true */
|
|
38
|
+
enabled?: () => boolean;
|
|
39
|
+
};
|
|
40
|
+
export type SDConfigForThemePermutation = {
|
|
41
|
+
permutation: ThemePermutation;
|
|
42
|
+
config: StyleDictionaryConfig;
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAChG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,WAAW,CAAC;AAE1D,eAAO,MAAM,eAAe;;;CAGlB,CAAC;AACX,MAAM,MAAM,eAAe,GAAG,MAAM,OAAO,eAAe,CAAC;AAE3D;;GAEG;AACH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,YAAY,EAAE,MAAM,CAAC;IACrB,eAAe,EAAE,MAAM,CAAC;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG,MAAM,gBAAgB,CAAC;AAEpD,MAAM,MAAM,iBAAiB,GAAG,CAAC,KAAK,EAAE,gBAAgB,EAAE,OAAO,CAAC,EAAE,qBAAqB,KAAK,OAAO,CAAC;AAEtG,MAAM,MAAM,kBAAkB,GAAG;IAC/B,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,0EAA0E;IAC1E,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,6CAA6C;IAC7C,SAAS,EAAE,wBAAwB,CAAC;IACpC,0FAA0F;IAC1F,UAAU,EAAE,cAAc,EAAE,CAAC;IAC7B,uGAAuG;IACvG,OAAO,CAAC,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACtC,mEAAmE;IACnE,KAAK,CAAC,EAAE,CAAC,SAAS,EAAE,2BAA2B,EAAE,EAAE,OAAO,EAAE,kBAAkB,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACjG,+DAA+D;IAC/D,OAAO,CAAC,EAAE,MAAM,OAAO,CAAC;CACzB,CAAC;AAEF,MAAM,MAAM,2BAA2B,GAAG;IAAE,WAAW,EAAE,gBAAgB,CAAC;IAAC,MAAM,EAAE,qBAAqB,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entryfile.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/utils/entryfile.ts"],"names":[],"mappings":"AAkEA,KAAK,SAAS,GAAG,CAAC,OAAO,EAAE;IACzB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,CAAC;IAClB,KAAK,EAAE,MAAM,CAAC;CACf,KAAK,OAAO,CAAC,SAAS,CAAC,CAAC;AAEzB;;GAEG;AACH,eAAO,MAAM,aAAa,EAAE,SAS3B,CAAC"}
|
|
@@ -8,10 +8,17 @@ const sortOrder = [
|
|
|
8
8
|
"semantic",
|
|
9
9
|
"color-mode/dark",
|
|
10
10
|
"color-mode/contrast",
|
|
11
|
-
"typography/primary"
|
|
11
|
+
"typography/primary",
|
|
12
|
+
"color/",
|
|
13
|
+
"builtin-colors"
|
|
12
14
|
];
|
|
13
15
|
const sortByDefinedOrder = R.sortBy((fileName) => {
|
|
14
|
-
const sortIndex = sortOrder.findIndex((sortElement) =>
|
|
16
|
+
const sortIndex = sortOrder.findIndex((sortElement) => {
|
|
17
|
+
if (sortElement.endsWith("/")) {
|
|
18
|
+
return fileName.includes(sortElement);
|
|
19
|
+
}
|
|
20
|
+
return fileName.includes(`${sortElement}.css`);
|
|
21
|
+
});
|
|
15
22
|
if (sortIndex === -1) {
|
|
16
23
|
console.error(
|
|
17
24
|
chalk.yellow("WARNING: CSS section does not have a defined sort order:", fileName.replace(".css", ""))
|
|
@@ -49,7 +56,8 @@ const concat = R.pipe(
|
|
|
49
56
|
const makeEntryFile = async ({ outPath, buildPath, theme }) => {
|
|
50
57
|
const writePath = `${outPath}/${theme}.css`;
|
|
51
58
|
const files = await glob(`**/*`, { cwd: buildPath });
|
|
52
|
-
const
|
|
59
|
+
const sortAlphabetically = R.sort(R.ascend((x) => x));
|
|
60
|
+
const sortedFileNames = R.pipe(sortAlphabetically, sortByDefinedOrder)(files);
|
|
53
61
|
const content = header + concat(sortedFileNames.map((file) => `${buildPath}/${file}`));
|
|
54
62
|
await fs.writeFile(writePath, content);
|
|
55
63
|
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { ThemeObject } from '@tokens-studio/types';
|
|
2
|
+
import type { ThemeDimension, ThemePermutation } from '../types';
|
|
3
|
+
/**
|
|
4
|
+
* Find the theme permutations that are relevant for the given theme dimensions.
|
|
5
|
+
*
|
|
6
|
+
* Technically, for the given dimensions all permutations are included, while for other
|
|
7
|
+
* dimensions the first permutation is used.
|
|
8
|
+
*
|
|
9
|
+
* @param themes Theme objects from $themes.json (Tokens Studio)
|
|
10
|
+
* @param dimensions Which theme dimensions to return permutations for.
|
|
11
|
+
* 'theme' (e.g. altinn/digdir/uutilsynet) is always implicitly included.
|
|
12
|
+
* @returns the relevant theme permutations
|
|
13
|
+
*/
|
|
14
|
+
export declare const getMultidimensionalThemes: (themes: ProcessedThemeObject[], dimensions: ThemeDimension[]) => PermutatedTheme[];
|
|
15
|
+
export type PermutatedTheme = {
|
|
16
|
+
name: string;
|
|
17
|
+
selectedTokenSets: string[];
|
|
18
|
+
permutation: ThemePermutation;
|
|
19
|
+
};
|
|
20
|
+
declare const processed: unique symbol;
|
|
21
|
+
/**
|
|
22
|
+
* A Tokens Studio {@link ThemeObject} which has been processed for easier use in code
|
|
23
|
+
*/
|
|
24
|
+
export type ProcessedThemeObject = ThemeObject & {
|
|
25
|
+
[processed]: true;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* Normalise theme names and theme group names for easier use in code
|
|
29
|
+
* @param theme A theme object from $themes.json
|
|
30
|
+
* @returns Processed theme object
|
|
31
|
+
*/
|
|
32
|
+
export declare function processThemeObject(theme: ThemeObject | ProcessedThemeObject): ProcessedThemeObject;
|
|
33
|
+
export type GroupedThemes = Record<keyof ThemePermutation, ProcessedThemeObject[]>;
|
|
34
|
+
export {};
|
|
35
|
+
//# sourceMappingURL=getMultidimensionalThemes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMultidimensionalThemes.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/utils/getMultidimensionalThemes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAMxD,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAEjE;;;;;;;;;;GAUG;AACH,eAAO,MAAM,yBAAyB,WAAY,oBAAoB,EAAE,cAAc,cAAc,EAAE,sBAerG,CAAC;AAEF,MAAM,MAAM,eAAe,GAAG;IAC5B,IAAI,EAAE,MAAM,CAAC;IACb,iBAAiB,EAAE,MAAM,EAAE,CAAC;IAC5B,WAAW,EAAE,gBAAgB,CAAC;CAC/B,CAAC;AAEF,QAAA,MAAM,SAAS,EAAE,OAAO,MAAsD,CAAC;AAC/E;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,WAAW,GAAG;IAAE,CAAC,SAAS,CAAC,EAAE,IAAI,CAAA;CAAE,CAAC;AAMvE;;;;GAIG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,WAAW,GAAG,oBAAoB,GAAG,oBAAoB,CAUlG;AAED,MAAM,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,gBAAgB,EAAE,oBAAoB,EAAE,CAAC,CAAC"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { TokenSetStatus } from "@tokens-studio/types";
|
|
2
|
+
import chalk from "chalk";
|
|
3
|
+
import { kebabCase } from "change-case";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
import { buildOptions } from "../../build.js";
|
|
6
|
+
const getMultidimensionalThemes = (themes, dimensions) => {
|
|
7
|
+
const verboseLogging = buildOptions?.verbose;
|
|
8
|
+
const grouped$themes = groupThemes(themes);
|
|
9
|
+
const permutations = permutateThemes(grouped$themes);
|
|
10
|
+
const ALL_DEPENDENT_ON = ["theme"];
|
|
11
|
+
const keys = R.keys(grouped$themes);
|
|
12
|
+
const nonDependentKeys = keys.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
|
|
13
|
+
if (verboseLogging) {
|
|
14
|
+
console.log(chalk.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
|
|
15
|
+
console.log(chalk.cyan(` (ignoring permutations for ${nonDependentKeys})`));
|
|
16
|
+
}
|
|
17
|
+
return permutations.filter((val) => {
|
|
18
|
+
const filters = nonDependentKeys.map((x) => val.permutation[x] === grouped$themes[x][0].name);
|
|
19
|
+
return filters.every((x) => x);
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
const processed = Symbol("Type brand for ProcessedThemeObject");
|
|
23
|
+
function isProcessed(theme) {
|
|
24
|
+
return Boolean(theme[processed]);
|
|
25
|
+
}
|
|
26
|
+
function processThemeObject(theme) {
|
|
27
|
+
if (isProcessed(theme)) {
|
|
28
|
+
return theme;
|
|
29
|
+
}
|
|
30
|
+
const result = { ...theme, [processed]: true };
|
|
31
|
+
if (result.group) {
|
|
32
|
+
result.group = kebabCase(result.group);
|
|
33
|
+
}
|
|
34
|
+
result.name = kebabCase(result.name);
|
|
35
|
+
return result;
|
|
36
|
+
}
|
|
37
|
+
function groupThemes(themes) {
|
|
38
|
+
const groups = {};
|
|
39
|
+
for (const rawTheme of themes) {
|
|
40
|
+
const theme = processThemeObject(rawTheme);
|
|
41
|
+
if (theme.group) {
|
|
42
|
+
const groupKey = theme.group;
|
|
43
|
+
groups[groupKey] = [...groups[groupKey] ?? [], theme];
|
|
44
|
+
} else {
|
|
45
|
+
throw new Error(
|
|
46
|
+
`Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
|
|
47
|
+
);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return groups;
|
|
51
|
+
}
|
|
52
|
+
const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
|
|
53
|
+
function permutateThemes(groups) {
|
|
54
|
+
const separator = "_";
|
|
55
|
+
const permutations = cartesian(Object.values(groups));
|
|
56
|
+
const permutatedThemes = permutations.map((perm) => {
|
|
57
|
+
const permutatedTheme = perm.reduce(
|
|
58
|
+
(acc, theme) => {
|
|
59
|
+
const { group, name, selectedTokenSets } = theme;
|
|
60
|
+
let updatedPermutation = acc.permutation;
|
|
61
|
+
if (group) {
|
|
62
|
+
const groupProp = R.lensProp(group);
|
|
63
|
+
updatedPermutation = R.set(groupProp, name, updatedPermutation);
|
|
64
|
+
}
|
|
65
|
+
const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
|
|
66
|
+
const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
|
|
67
|
+
return {
|
|
68
|
+
permutation: updatedPermutation,
|
|
69
|
+
name: updatedName,
|
|
70
|
+
selectedTokenSets: sets
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
name: "",
|
|
75
|
+
selectedTokenSets: [],
|
|
76
|
+
permutation: {
|
|
77
|
+
mode: "unknown",
|
|
78
|
+
"main-color": "unknown",
|
|
79
|
+
"support-color": "unknown",
|
|
80
|
+
theme: "unknown",
|
|
81
|
+
semantic: "unknown",
|
|
82
|
+
size: "unknown",
|
|
83
|
+
typography: "unknown"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
);
|
|
87
|
+
if (hasUnknownProps(permutatedTheme)) {
|
|
88
|
+
throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
|
|
89
|
+
}
|
|
90
|
+
const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
|
|
91
|
+
return { ...permutatedTheme, selectedTokenSets: Array.from(uniqueTokenSets) };
|
|
92
|
+
});
|
|
93
|
+
return permutatedThemes;
|
|
94
|
+
}
|
|
95
|
+
function filterTokenSets(tokensets) {
|
|
96
|
+
return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
|
|
97
|
+
if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
|
|
98
|
+
return -1;
|
|
99
|
+
}
|
|
100
|
+
if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
return 0;
|
|
104
|
+
}).map((entry) => entry[0]);
|
|
105
|
+
}
|
|
106
|
+
function cartesian(a) {
|
|
107
|
+
return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e].flat())));
|
|
108
|
+
}
|
|
109
|
+
export {
|
|
110
|
+
getMultidimensionalThemes,
|
|
111
|
+
processThemeObject
|
|
112
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"noCase.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/utils/noCase.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,OAAO;IACtB,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,MAAM,CAAC;CACtE;AAQD;;GAEG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,GAAE,OAAY,UAkB1D"}
|
|
@@ -22,4 +22,7 @@ export declare const getValue: <T>(token: TransformedToken | DesignToken) => T;
|
|
|
22
22
|
*/
|
|
23
23
|
export declare const typeEquals: import("ts-toolbelt/out/Function/Curry").Curry<(types: string[] | string, token: TransformedToken) => boolean>;
|
|
24
24
|
export declare const pathStartsWithOneOf: import("ts-toolbelt/out/Function/Curry").Curry<(paths: string[], token: TransformedToken) => boolean>;
|
|
25
|
+
export declare function isSemanticToken(token: TransformedToken): boolean;
|
|
26
|
+
export declare function isGlobalColorToken(token: TransformedToken): boolean;
|
|
27
|
+
export declare function isColorCategoryToken(token: TransformedToken, category?: 'main' | 'support'): boolean;
|
|
25
28
|
//# sourceMappingURL=utils.d.ts.map
|