@digdir/designsystemet 0.1.0-alpha.12 → 0.1.0-alpha.14
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/LICENSE +7 -0
- package/dist/bin/designsystemet.js +178 -121
- package/dist/bin/designsystemet.js.map +1 -1
- package/dist/src/colors/colorUtils.js +156 -2
- package/dist/src/colors/colorUtils.js.map +1 -1
- package/dist/src/colors/index.js +166 -10
- package/dist/src/colors/index.js.map +1 -1
- package/dist/src/colors/themeUtils.js +62 -8
- package/dist/src/colors/themeUtils.js.map +1 -1
- package/dist/src/tokens/actions.js +7 -1
- package/dist/src/tokens/actions.js.map +1 -1
- package/dist/src/tokens/build.js +178 -121
- package/dist/src/tokens/build.js.map +1 -1
- package/dist/src/tokens/configs.js +163 -102
- package/dist/src/tokens/configs.js.map +1 -1
- package/dist/src/tokens/formats/{css-classes.js → css.js} +123 -89
- package/dist/src/tokens/formats/css.js.map +1 -0
- package/dist/src/tokens/formats/js-tokens.js +6 -0
- package/dist/src/tokens/formats/js-tokens.js.map +1 -1
- package/dist/src/tokens/transformers.js +2 -2
- package/dist/src/tokens/transformers.js.map +1 -1
- package/dist/src/tokens/utils/permutateThemes.js +41 -29
- package/dist/src/tokens/utils/permutateThemes.js.map +1 -1
- package/dist/src/tokens/utils/utils.js +2 -2
- package/dist/src/tokens/utils/utils.js.map +1 -1
- package/package.json +10 -7
- package/dist/src/tokens/formats/css-classes.js.map +0 -1
- package/dist/src/tokens/formats/css-variables.js +0 -50
- package/dist/src/tokens/formats/css-variables.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
Copyright 2024 Digitaliseringsdirektoratet (Digdir)
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
4
|
+
|
|
5
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
6
|
+
|
|
7
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -2616,6 +2616,9 @@ import StyleDictionary from "style-dictionary";
|
|
|
2616
2616
|
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
2617
2617
|
import * as R8 from "ramda";
|
|
2618
2618
|
|
|
2619
|
+
// src/tokens/utils/permutateThemes.ts
|
|
2620
|
+
import * as R2 from "ramda";
|
|
2621
|
+
|
|
2619
2622
|
// ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
|
|
2620
2623
|
var BoxShadowTypes;
|
|
2621
2624
|
(function(BoxShadowTypes2) {
|
|
@@ -2781,40 +2784,49 @@ var TypographyValues;
|
|
|
2781
2784
|
|
|
2782
2785
|
// src/tokens/utils/permutateThemes.ts
|
|
2783
2786
|
function mapThemesToSetsObject(themes) {
|
|
2784
|
-
return
|
|
2787
|
+
return themes.map((theme) => ({ name: theme.name, selectedTokenSets: filterTokenSets(theme.selectedTokenSets) }));
|
|
2785
2788
|
}
|
|
2786
2789
|
function permutateThemes(themes, { separator: separator2 = "-" } = {}) {
|
|
2787
|
-
if (themes.some((theme) => theme.group)) {
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
const permutations = cartesian(Object.values(groups));
|
|
2802
|
-
return Object.fromEntries(
|
|
2803
|
-
permutations.map((perm) => {
|
|
2804
|
-
const reduced = perm.reduce(
|
|
2805
|
-
(acc, curr) => [
|
|
2806
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
2807
|
-
`${acc[0]}${acc[0] ? separator2 : ""}${curr.name}`,
|
|
2808
|
-
[...acc[1], ...filterTokenSets(curr.selectedTokenSets)]
|
|
2809
|
-
],
|
|
2810
|
-
["", []]
|
|
2811
|
-
);
|
|
2812
|
-
return [reduced[0], [...new Set(reduced[1])]];
|
|
2813
|
-
})
|
|
2814
|
-
);
|
|
2815
|
-
} else {
|
|
2790
|
+
if (!themes.some((theme) => theme.group)) {
|
|
2791
|
+
return mapThemesToSetsObject(themes);
|
|
2792
|
+
}
|
|
2793
|
+
const groups = {};
|
|
2794
|
+
themes.forEach((theme) => {
|
|
2795
|
+
if (theme.group) {
|
|
2796
|
+
groups[theme.group] = [...groups[theme.group] ?? [], theme];
|
|
2797
|
+
} else {
|
|
2798
|
+
throw new Error(
|
|
2799
|
+
`Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
|
|
2800
|
+
);
|
|
2801
|
+
}
|
|
2802
|
+
});
|
|
2803
|
+
if (Object.keys(groups).length <= 1) {
|
|
2816
2804
|
return mapThemesToSetsObject(themes);
|
|
2817
2805
|
}
|
|
2806
|
+
const permutations = cartesian(Object.values(groups));
|
|
2807
|
+
const permutatedThemes = permutations.map((perm) => {
|
|
2808
|
+
const permutatedTheme = perm.reduce(
|
|
2809
|
+
(acc, theme) => {
|
|
2810
|
+
const { group, name, selectedTokenSets } = theme;
|
|
2811
|
+
let updatedPermutatedTheme = acc;
|
|
2812
|
+
if (group) {
|
|
2813
|
+
const groupProp = R2.lensProp(group.toLowerCase());
|
|
2814
|
+
updatedPermutatedTheme = R2.set(groupProp, name.toLowerCase(), updatedPermutatedTheme);
|
|
2815
|
+
}
|
|
2816
|
+
const updatedName = `${String(acc.name)}${acc ? separator2 : ""}${name}`;
|
|
2817
|
+
const sets = [...updatedPermutatedTheme.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
|
|
2818
|
+
return {
|
|
2819
|
+
...updatedPermutatedTheme,
|
|
2820
|
+
name: updatedName,
|
|
2821
|
+
selectedTokenSets: sets
|
|
2822
|
+
};
|
|
2823
|
+
},
|
|
2824
|
+
{ name: "", selectedTokenSets: [] }
|
|
2825
|
+
);
|
|
2826
|
+
const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
|
|
2827
|
+
return { ...permutatedTheme, selectedTokenSets: Array.from(uniqueTokenSets) };
|
|
2828
|
+
});
|
|
2829
|
+
return permutatedThemes;
|
|
2818
2830
|
}
|
|
2819
2831
|
function filterTokenSets(tokensets) {
|
|
2820
2832
|
return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
|
|
@@ -2831,7 +2843,7 @@ function cartesian(a) {
|
|
|
2831
2843
|
}
|
|
2832
2844
|
|
|
2833
2845
|
// src/tokens/transformers.ts
|
|
2834
|
-
import * as
|
|
2846
|
+
import * as R4 from "ramda";
|
|
2835
2847
|
|
|
2836
2848
|
// src/tokens/utils/noCase.ts
|
|
2837
2849
|
var lowerCase = (text = "") => text.toLowerCase();
|
|
@@ -2861,18 +2873,18 @@ function replace(input, re, value) {
|
|
|
2861
2873
|
}
|
|
2862
2874
|
|
|
2863
2875
|
// src/tokens/utils/utils.ts
|
|
2864
|
-
import * as
|
|
2876
|
+
import * as R3 from "ramda";
|
|
2865
2877
|
var getType = (token) => (token.$type ?? token.type) || "";
|
|
2866
2878
|
var getValue = (token) => token.$value ?? token.value;
|
|
2867
|
-
var typeEquals = (types, token) => {
|
|
2868
|
-
if (
|
|
2879
|
+
var typeEquals = R3.curry((types, token) => {
|
|
2880
|
+
if (R3.isNil(token)) {
|
|
2869
2881
|
return false;
|
|
2870
2882
|
}
|
|
2871
|
-
return
|
|
2872
|
-
};
|
|
2883
|
+
return R3.includes(R3.toLower(getType(token)), R3.map(R3.toLower, Array.isArray(types) ? types : [types]));
|
|
2884
|
+
});
|
|
2873
2885
|
|
|
2874
2886
|
// src/tokens/transformers.ts
|
|
2875
|
-
var isPx =
|
|
2887
|
+
var isPx = R4.test(/\b\d+px\b/g);
|
|
2876
2888
|
var sizeRem = {
|
|
2877
2889
|
name: "ds/size/toRem",
|
|
2878
2890
|
type: "value",
|
|
@@ -2907,19 +2919,19 @@ var typographyShorthand = {
|
|
|
2907
2919
|
transitive: true,
|
|
2908
2920
|
filter: (token) => token.type === "typography",
|
|
2909
2921
|
transform: (token) => {
|
|
2910
|
-
const
|
|
2911
|
-
return `${
|
|
2922
|
+
const typography2 = getValue(token);
|
|
2923
|
+
return `${typography2.fontWeight} ${typography2.fontSize}/${typography2.lineHeight} '${typography2.fontFamily}'`;
|
|
2912
2924
|
}
|
|
2913
2925
|
};
|
|
2914
2926
|
|
|
2915
2927
|
// src/tokens/formats/js-tokens.ts
|
|
2916
|
-
import * as
|
|
2928
|
+
import * as R5 from "ramda";
|
|
2917
2929
|
import { fileHeader, createPropertyFormatter } from "style-dictionary/utils";
|
|
2918
|
-
var groupByType =
|
|
2919
|
-
var removeUnwatedTokens =
|
|
2930
|
+
var groupByType = R5.groupBy((token) => getType(token));
|
|
2931
|
+
var removeUnwatedTokens = R5.filter(
|
|
2920
2932
|
(token) => !["fds-base_spacing", "fds-base_sizing"].includes(token.name)
|
|
2921
2933
|
);
|
|
2922
|
-
var toCssVarName =
|
|
2934
|
+
var toCssVarName = R5.pipe(R5.split(":"), R5.head, R5.trim);
|
|
2923
2935
|
var jsTokens = {
|
|
2924
2936
|
name: "ds/js-tokens",
|
|
2925
2937
|
format: async function({ dictionary, file }) {
|
|
@@ -2927,11 +2939,11 @@ var jsTokens = {
|
|
|
2927
2939
|
dictionary,
|
|
2928
2940
|
format: "css"
|
|
2929
2941
|
});
|
|
2930
|
-
const formatTokens =
|
|
2942
|
+
const formatTokens = R5.map((token) => ({
|
|
2931
2943
|
...token,
|
|
2932
2944
|
name: toCssVarName(format(token))
|
|
2933
2945
|
}));
|
|
2934
|
-
const processTokens =
|
|
2946
|
+
const processTokens = R5.pipe(removeUnwatedTokens, formatTokens, groupByType);
|
|
2935
2947
|
const tokens = processTokens(dictionary.allTokens);
|
|
2936
2948
|
const content = Object.entries(tokens).map(
|
|
2937
2949
|
([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
|
|
@@ -2941,21 +2953,20 @@ var jsTokens = {
|
|
|
2941
2953
|
}
|
|
2942
2954
|
};
|
|
2943
2955
|
|
|
2944
|
-
// src/tokens/formats/css
|
|
2945
|
-
import * as
|
|
2946
|
-
import { fileHeader as fileHeader2, createPropertyFormatter as createPropertyFormatter2, usesReferences } from "style-dictionary/utils";
|
|
2947
|
-
var calculatedVariable = R5.pipe(R5.split(/:(.*?);/g), (split5) => `${split5[0]}: calc(${R5.trim(split5[1])});`);
|
|
2956
|
+
// src/tokens/formats/css.ts
|
|
2957
|
+
import * as R6 from "ramda";
|
|
2958
|
+
import { fileHeader as fileHeader2, createPropertyFormatter as createPropertyFormatter2, usesReferences, getReferences } from "style-dictionary/utils";
|
|
2948
2959
|
var prefersColorScheme = (mode, content) => `
|
|
2949
2960
|
@media (prefers-color-scheme: ${mode}) {
|
|
2950
2961
|
[data-ds-color-mode="auto"] ${content}
|
|
2951
2962
|
}
|
|
2952
2963
|
`;
|
|
2953
|
-
var
|
|
2954
|
-
name: "ds/css-
|
|
2964
|
+
var colormode = {
|
|
2965
|
+
name: "ds/css-colormode",
|
|
2955
2966
|
format: async function({ dictionary, file, options, platform }) {
|
|
2956
2967
|
const { allTokens } = dictionary;
|
|
2957
2968
|
const { outputReferences } = options;
|
|
2958
|
-
const { selector,
|
|
2969
|
+
const { selector, mode, layer } = platform;
|
|
2959
2970
|
const mode_ = mode;
|
|
2960
2971
|
const header = await fileHeader2({ file });
|
|
2961
2972
|
const format = createPropertyFormatter2({
|
|
@@ -2963,7 +2974,31 @@ var cssVariables = {
|
|
|
2963
2974
|
dictionary,
|
|
2964
2975
|
format: "css"
|
|
2965
2976
|
});
|
|
2966
|
-
const
|
|
2977
|
+
const content = `{
|
|
2978
|
+
${allTokens.map(format).join("\n")}
|
|
2979
|
+
}
|
|
2980
|
+
`;
|
|
2981
|
+
const autoSelectorContent = ["light", "dark"].includes(mode_) ? prefersColorScheme(mode_, content) : "";
|
|
2982
|
+
return header + `@layer ${layer} {
|
|
2983
|
+
${selector} ${content} ${autoSelectorContent}
|
|
2984
|
+
}
|
|
2985
|
+
`;
|
|
2986
|
+
}
|
|
2987
|
+
};
|
|
2988
|
+
var calculatedVariable = R6.pipe(R6.split(/:(.*?);/g), (split3) => `${split3[0]}: calc(${R6.trim(split3[1])});`);
|
|
2989
|
+
var semantic = {
|
|
2990
|
+
name: "ds/css-semantic",
|
|
2991
|
+
format: async function({ dictionary, file, options, platform }) {
|
|
2992
|
+
const { allTokens } = dictionary;
|
|
2993
|
+
const { outputReferences } = options;
|
|
2994
|
+
const { selector, isCalculatedToken, layer } = platform;
|
|
2995
|
+
const header = await fileHeader2({ file });
|
|
2996
|
+
const format = createPropertyFormatter2({
|
|
2997
|
+
outputReferences,
|
|
2998
|
+
dictionary,
|
|
2999
|
+
format: "css"
|
|
3000
|
+
});
|
|
3001
|
+
const formatTokens = R6.map((token) => {
|
|
2967
3002
|
const originalValue = getValue(token.original);
|
|
2968
3003
|
if (usesReferences(originalValue) && typeof outputReferences === "function" && outputReferences?.(token, { dictionary })) {
|
|
2969
3004
|
if (isCalculatedToken?.(token, options)) {
|
|
@@ -2977,14 +3012,12 @@ var cssVariables = {
|
|
|
2977
3012
|
${formattedVariables.join("\n")}
|
|
2978
3013
|
}
|
|
2979
3014
|
`;
|
|
2980
|
-
|
|
2981
|
-
|
|
3015
|
+
return header + `@layer ${layer} {
|
|
3016
|
+
${selector} ${content}
|
|
3017
|
+
}
|
|
3018
|
+
`;
|
|
2982
3019
|
}
|
|
2983
3020
|
};
|
|
2984
|
-
|
|
2985
|
-
// src/tokens/formats/css-classes.ts
|
|
2986
|
-
import * as R6 from "ramda";
|
|
2987
|
-
import { fileHeader as fileHeader3, createPropertyFormatter as createPropertyFormatter3, getReferences } from "style-dictionary/utils";
|
|
2988
3021
|
var sortByType = R6.sortBy((token) => token?.type === "typography");
|
|
2989
3022
|
var getVariableName = R6.pipe(
|
|
2990
3023
|
R6.split(":"),
|
|
@@ -2998,21 +3031,23 @@ var bemify = R6.pipe(
|
|
|
2998
3031
|
const filteredPath = path2.filter((p) => p !== "typography");
|
|
2999
3032
|
const withPrefix = R6.concat([prefix], R6.remove(0, 0, filteredPath));
|
|
3000
3033
|
const [rest, last] = R6.splitAt(-1, withPrefix);
|
|
3001
|
-
|
|
3034
|
+
const className = `${rest.join("-")}--${R6.head(last)}`;
|
|
3035
|
+
return className;
|
|
3002
3036
|
},
|
|
3003
3037
|
R6.trim,
|
|
3004
3038
|
R6.toLower
|
|
3005
3039
|
);
|
|
3006
3040
|
var classSelector = R6.pipe(R6.prop("path"), bemify);
|
|
3007
|
-
var
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3041
|
+
var sortTypographyLast = R6.sortWith([
|
|
3042
|
+
R6.ascend((token) => typeEquals("typography")(token) ? 1 : 0)
|
|
3043
|
+
]);
|
|
3044
|
+
var typography = {
|
|
3045
|
+
name: "ds/css-typography",
|
|
3011
3046
|
format: async function({ dictionary, file, options, platform }) {
|
|
3012
3047
|
const { outputReferences } = options;
|
|
3013
|
-
const { selector } = platform;
|
|
3014
|
-
const header = await
|
|
3015
|
-
const format =
|
|
3048
|
+
const { selector, layer } = platform;
|
|
3049
|
+
const header = await fileHeader2({ file });
|
|
3050
|
+
const format = createPropertyFormatter2({
|
|
3016
3051
|
outputReferences,
|
|
3017
3052
|
dictionary,
|
|
3018
3053
|
format: "css"
|
|
@@ -3046,17 +3081,20 @@ var cssClassesTypography = {
|
|
|
3046
3081
|
}
|
|
3047
3082
|
if (typeEquals("typography", token)) {
|
|
3048
3083
|
const references = getReferences(getValue(token.original), dictionary.tokens);
|
|
3049
|
-
const fontweight = R6.find(
|
|
3050
|
-
const lineheight = R6.find(
|
|
3051
|
-
const fontsize = R6.find(
|
|
3084
|
+
const fontweight = R6.find(typeEquals(["fontweights"]))(references);
|
|
3085
|
+
const lineheight = R6.find(typeEquals(["lineheights"]))(references);
|
|
3086
|
+
const fontsize = R6.find(typeEquals(["fontsizes"]))(references);
|
|
3087
|
+
const letterSpacing = R6.find(typeEquals(["letterSpacing"]))(references);
|
|
3052
3088
|
const fontSizeVar = fontsize ? getVariableName(format(fontsize)) : null;
|
|
3053
3089
|
const fontWeightVar = fontweight ? getVariableName(format(fontweight)) : null;
|
|
3054
3090
|
const lineheightVar = lineheight ? getVariableName(format(lineheight)) : null;
|
|
3091
|
+
const letterSpacingVar = letterSpacing ? getVariableName(format(letterSpacing)) : null;
|
|
3055
3092
|
const className = `
|
|
3056
3093
|
.${classSelector(token)} {
|
|
3057
3094
|
${fontSizeVar && `font-size: ${fontSizeVar};`}
|
|
3058
3095
|
${lineheightVar && `line-height: ${lineheightVar};`}
|
|
3059
3096
|
${fontWeightVar && `font-weight: ${fontWeightVar};`}
|
|
3097
|
+
${letterSpacingVar && `letter-spacing: ${letterSpacingVar};`}
|
|
3060
3098
|
}`;
|
|
3061
3099
|
return { ...acc, classes: [className, ...acc.classes] };
|
|
3062
3100
|
}
|
|
@@ -3067,15 +3105,11 @@ var cssClassesTypography = {
|
|
|
3067
3105
|
)(sortedTokens);
|
|
3068
3106
|
const classes = formattedTokens.classes.join("\n");
|
|
3069
3107
|
const variables = formattedTokens.variables.join("\n");
|
|
3070
|
-
const variables_ = `:root {
|
|
3071
|
-
${variables}
|
|
3072
|
-
}
|
|
3073
|
-
`;
|
|
3074
3108
|
const content = selector ? `${selector} {
|
|
3109
|
+
${variables}
|
|
3075
3110
|
${classes}
|
|
3076
3111
|
}` : classes;
|
|
3077
|
-
return header + `@layer
|
|
3078
|
-
${variables_}
|
|
3112
|
+
return header + `@layer ${layer} {
|
|
3079
3113
|
${content}
|
|
3080
3114
|
}
|
|
3081
3115
|
`;
|
|
@@ -3087,6 +3121,7 @@ var import_fs_extra = __toESM(require_lib(), 1);
|
|
|
3087
3121
|
import glob3 from "fast-glob";
|
|
3088
3122
|
import chalk3 from "chalk";
|
|
3089
3123
|
import * as R7 from "ramda";
|
|
3124
|
+
var sortLightmodeFirst = R7.sortWith([R7.descend(R7.includes("light")), R7.descend(R7.includes("secondary"))]);
|
|
3090
3125
|
var makeEntryFile = {
|
|
3091
3126
|
name: "make_entryfile",
|
|
3092
3127
|
do: async function(dictionary, platform) {
|
|
@@ -3095,8 +3130,13 @@ var makeEntryFile = {
|
|
|
3095
3130
|
if (log?.verbosity !== "silent") {
|
|
3096
3131
|
console.log(chalk3.green(`Creating entry file: ${writePath}`));
|
|
3097
3132
|
}
|
|
3133
|
+
const generateImportUrls = R7.pipe(
|
|
3134
|
+
sortLightmodeFirst,
|
|
3135
|
+
R7.map((file) => `@import url('./${theme}/${file.toString()}');`),
|
|
3136
|
+
R7.join("\n")
|
|
3137
|
+
);
|
|
3098
3138
|
const files = await glob3(`**/*`, { cwd: platform.buildPath });
|
|
3099
|
-
const content =
|
|
3139
|
+
const content = generateImportUrls(files);
|
|
3100
3140
|
await import_fs_extra.default.writeFile(writePath, content);
|
|
3101
3141
|
},
|
|
3102
3142
|
undo: async function noOp() {
|
|
@@ -3108,13 +3148,14 @@ void tokenStudio.registerTransforms(StyleDictionary);
|
|
|
3108
3148
|
var prefix = "ds";
|
|
3109
3149
|
var basePxFontSize = 16;
|
|
3110
3150
|
var separator = "_";
|
|
3111
|
-
var
|
|
3151
|
+
var fileHeader3 = () => [`These files are generated from design tokens defind using Token Studio`];
|
|
3112
3152
|
StyleDictionary.registerTransform(sizeRem);
|
|
3113
3153
|
StyleDictionary.registerTransform(nameKebab);
|
|
3114
3154
|
StyleDictionary.registerTransform(typographyShorthand);
|
|
3115
3155
|
StyleDictionary.registerFormat(jsTokens);
|
|
3116
|
-
StyleDictionary.registerFormat(
|
|
3117
|
-
StyleDictionary.registerFormat(
|
|
3156
|
+
StyleDictionary.registerFormat(colormode);
|
|
3157
|
+
StyleDictionary.registerFormat(semantic);
|
|
3158
|
+
StyleDictionary.registerFormat(typography);
|
|
3118
3159
|
StyleDictionary.registerAction(makeEntryFile);
|
|
3119
3160
|
var dsTransformers = [
|
|
3120
3161
|
nameKebab.name,
|
|
@@ -3128,7 +3169,8 @@ var dsTransformers = [
|
|
|
3128
3169
|
"ts/size/lineheight",
|
|
3129
3170
|
"ts/shadow/css/shorthand"
|
|
3130
3171
|
];
|
|
3131
|
-
var
|
|
3172
|
+
var paritionPrimitives = R8.partition(R8.test(/(?!.*global\.json).*primitives.*/));
|
|
3173
|
+
var hasUnknownProps = R8.pipe(R8.values, R8.none(R8.equals("unknown")), R8.not);
|
|
3132
3174
|
var outputColorReferences = (token) => {
|
|
3133
3175
|
if (R8.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) && R8.includes("semantic/color", token.filePath)) {
|
|
3134
3176
|
return true;
|
|
@@ -3140,6 +3182,7 @@ var permutateThemes2 = ($themes) => permutateThemes($themes, {
|
|
|
3140
3182
|
});
|
|
3141
3183
|
var colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
3142
3184
|
const selector = `${mode === "light" ? ":root, " : ""}[data-ds-color-mode="${mode}"]`;
|
|
3185
|
+
const layer = `ds.theme.color-mode.${mode}`;
|
|
3143
3186
|
return {
|
|
3144
3187
|
log: { verbosity: "silent" },
|
|
3145
3188
|
preprocessors: ["tokens-studio"],
|
|
@@ -3150,6 +3193,7 @@ var colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
3150
3193
|
mode,
|
|
3151
3194
|
theme,
|
|
3152
3195
|
selector,
|
|
3196
|
+
layer,
|
|
3153
3197
|
//
|
|
3154
3198
|
prefix,
|
|
3155
3199
|
buildPath: `${outPath}/${theme}/`,
|
|
@@ -3158,12 +3202,12 @@ var colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
3158
3202
|
files: [
|
|
3159
3203
|
{
|
|
3160
3204
|
destination: `color-mode/${mode}.css`,
|
|
3161
|
-
format:
|
|
3205
|
+
format: colormode.name,
|
|
3162
3206
|
filter: (token) => !token.isSource && typeEquals("color", token)
|
|
3163
3207
|
}
|
|
3164
3208
|
],
|
|
3165
3209
|
options: {
|
|
3166
|
-
fileHeader:
|
|
3210
|
+
fileHeader: fileHeader3,
|
|
3167
3211
|
outputReferences: (token, options) => outputColorReferences(token) && outputReferencesFilter(token, options)
|
|
3168
3212
|
}
|
|
3169
3213
|
}
|
|
@@ -3172,6 +3216,7 @@ var colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
3172
3216
|
};
|
|
3173
3217
|
var semanticVariables = ({ outPath, theme }) => {
|
|
3174
3218
|
const selector = `:root`;
|
|
3219
|
+
const layer = `ds.theme.semantic`;
|
|
3175
3220
|
const isCalculatedToken = (token) => typeEquals(["spacing", "sizing", "borderRadius"], token);
|
|
3176
3221
|
return {
|
|
3177
3222
|
log: { verbosity: "silent" },
|
|
@@ -3184,6 +3229,7 @@ var semanticVariables = ({ outPath, theme }) => {
|
|
|
3184
3229
|
basePxFontSize,
|
|
3185
3230
|
isCalculatedToken,
|
|
3186
3231
|
selector,
|
|
3232
|
+
layer,
|
|
3187
3233
|
//
|
|
3188
3234
|
prefix,
|
|
3189
3235
|
buildPath: `${outPath}/${theme}/`,
|
|
@@ -3192,12 +3238,12 @@ var semanticVariables = ({ outPath, theme }) => {
|
|
|
3192
3238
|
files: [
|
|
3193
3239
|
{
|
|
3194
3240
|
destination: `semantic.css`,
|
|
3195
|
-
format:
|
|
3241
|
+
format: semantic.name,
|
|
3196
3242
|
filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeights", "fontFamilies"], token)
|
|
3197
3243
|
}
|
|
3198
3244
|
],
|
|
3199
3245
|
options: {
|
|
3200
|
-
fileHeader:
|
|
3246
|
+
fileHeader: fileHeader3,
|
|
3201
3247
|
outputReferences: (token, options) => isCalculatedToken(token) && outputReferencesFilter(token, options)
|
|
3202
3248
|
}
|
|
3203
3249
|
}
|
|
@@ -3231,59 +3277,74 @@ var typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
|
|
|
3231
3277
|
}
|
|
3232
3278
|
],
|
|
3233
3279
|
options: {
|
|
3234
|
-
fileHeader:
|
|
3280
|
+
fileHeader: fileHeader3
|
|
3235
3281
|
}
|
|
3236
3282
|
}
|
|
3237
3283
|
}
|
|
3238
3284
|
};
|
|
3239
3285
|
};
|
|
3240
|
-
var typographyCSS = ({ outPath, theme, typography }) => {
|
|
3286
|
+
var typographyCSS = ({ outPath, theme, typography: typography2 }) => {
|
|
3287
|
+
const selector = `${typography2 === "primary" ? ":root, " : ""}[data-ds-typography="${typography2}"]`;
|
|
3288
|
+
const layer = `ds.theme.typography.${typography2}`;
|
|
3241
3289
|
return {
|
|
3242
3290
|
log: { verbosity: "silent" },
|
|
3243
3291
|
preprocessors: ["tokens-studio"],
|
|
3244
3292
|
platforms: {
|
|
3245
3293
|
css: {
|
|
3246
3294
|
prefix,
|
|
3247
|
-
typography,
|
|
3248
|
-
|
|
3295
|
+
typography: typography2,
|
|
3296
|
+
selector,
|
|
3297
|
+
layer,
|
|
3249
3298
|
buildPath: `${outPath}/${theme}/`,
|
|
3250
3299
|
basePxFontSize,
|
|
3251
3300
|
transforms: [nameKebab.name, "ts/size/px", sizeRem.name, "ts/size/lineheight", "ts/typography/fontWeight"],
|
|
3252
3301
|
files: [
|
|
3253
3302
|
{
|
|
3254
|
-
destination: `typography.css`,
|
|
3255
|
-
format:
|
|
3303
|
+
destination: `typography/${typography2}.css`,
|
|
3304
|
+
format: typography.name,
|
|
3256
3305
|
filter: (token) => {
|
|
3257
|
-
return typeEquals(
|
|
3306
|
+
return typeEquals(
|
|
3307
|
+
["typography", "fontweights", "fontfamilies", "lineheights", "fontsizes", "letterSpacing"],
|
|
3308
|
+
token
|
|
3309
|
+
) && !(token.path[0] || "").startsWith("theme");
|
|
3258
3310
|
}
|
|
3259
3311
|
}
|
|
3260
3312
|
],
|
|
3261
3313
|
options: {
|
|
3262
|
-
fileHeader:
|
|
3314
|
+
fileHeader: fileHeader3
|
|
3263
3315
|
}
|
|
3264
3316
|
}
|
|
3265
3317
|
}
|
|
3266
3318
|
};
|
|
3267
3319
|
};
|
|
3268
|
-
var getConfigs = (getConfig, outPath, tokensDir,
|
|
3269
|
-
const
|
|
3270
|
-
|
|
3271
|
-
|
|
3272
|
-
|
|
3320
|
+
var getConfigs = (getConfig, outPath, tokensDir, permutatedThemes) => permutatedThemes.map((permutatedTheme) => {
|
|
3321
|
+
const {
|
|
3322
|
+
selectedTokenSets = [],
|
|
3323
|
+
mode = "unknown",
|
|
3324
|
+
theme = "unknown",
|
|
3325
|
+
semantic: semantic2 = "unknown",
|
|
3326
|
+
size = "unknown",
|
|
3327
|
+
typography: typography2 = "unknown"
|
|
3328
|
+
} = permutatedTheme;
|
|
3329
|
+
if (hasUnknownProps(permutatedTheme)) {
|
|
3330
|
+
throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
|
|
3331
|
+
}
|
|
3332
|
+
const setsWithPaths = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
|
|
3333
|
+
const [source, include] = paritionPrimitives(setsWithPaths);
|
|
3273
3334
|
const config_ = getConfig({
|
|
3274
3335
|
outPath,
|
|
3275
3336
|
theme,
|
|
3276
3337
|
mode,
|
|
3277
|
-
semantic,
|
|
3278
|
-
|
|
3279
|
-
typography
|
|
3338
|
+
semantic: semantic2,
|
|
3339
|
+
size,
|
|
3340
|
+
typography: typography2
|
|
3280
3341
|
});
|
|
3281
3342
|
const config = {
|
|
3282
3343
|
...config_,
|
|
3283
3344
|
source,
|
|
3284
3345
|
include
|
|
3285
3346
|
};
|
|
3286
|
-
return {
|
|
3347
|
+
return { mode, theme, semantic: semantic2, size, typography: typography2, config };
|
|
3287
3348
|
}).sort();
|
|
3288
3349
|
|
|
3289
3350
|
// src/tokens/build.ts
|
|
@@ -3296,26 +3357,23 @@ async function run(options) {
|
|
|
3296
3357
|
const $themes = JSON.parse(fs3.readFileSync(path.resolve(`${tokensDir}/$themes.json`), "utf-8"));
|
|
3297
3358
|
const relevant$themes = $themes.filter((theme) => {
|
|
3298
3359
|
const group = R9.toLower(R9.defaultTo("")(theme.group));
|
|
3299
|
-
if (group === "typography" && theme.name !== "default") return false;
|
|
3300
3360
|
if (group === "size" && theme.name !== "default") return false;
|
|
3301
3361
|
return true;
|
|
3302
3362
|
});
|
|
3303
3363
|
const themes = permutateThemes3(relevant$themes);
|
|
3304
|
-
const
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
);
|
|
3308
|
-
const colorModeConfigs = getConfigs2(colorModeVariables, tokensOutDir, tokensDir, themes);
|
|
3364
|
+
const typographyThemes = R9.filter((val) => val.mode === "light", themes);
|
|
3365
|
+
const colormodeThemes = R9.filter((val) => val.typography === "primary", themes);
|
|
3366
|
+
const semanticThemes = R9.filter((val) => val.mode === "light" && val.typography === "primary", themes);
|
|
3367
|
+
const colorModeConfigs = getConfigs2(colorModeVariables, tokensOutDir, tokensDir, colormodeThemes);
|
|
3309
3368
|
const semanticConfigs = getConfigs2(semanticVariables, tokensOutDir, tokensDir, semanticThemes);
|
|
3310
|
-
const
|
|
3311
|
-
const
|
|
3369
|
+
const typographyConfigs = getConfigs2(typographyCSS, tokensOutDir, tokensDir, typographyThemes);
|
|
3370
|
+
const storefrontConfigs = getConfigs2(typescriptTokens, storefrontOutDir, tokensDir, colormodeThemes);
|
|
3312
3371
|
if (typographyConfigs.length > 0) {
|
|
3313
3372
|
console.log(`
|
|
3314
3373
|
\u{1F371} Building ${chalk4.green("typography")}`);
|
|
3315
3374
|
await Promise.all(
|
|
3316
|
-
typographyConfigs.map(async ({
|
|
3317
|
-
|
|
3318
|
-
console.log(`\u{1F477} Processing: ${typographyTheme}`);
|
|
3375
|
+
typographyConfigs.map(async ({ theme, typography: typography2, config }) => {
|
|
3376
|
+
console.log(`\u{1F477} ${theme} - ${typography2}`);
|
|
3319
3377
|
const typographyClasses = await sd.extend(config);
|
|
3320
3378
|
return typographyClasses.buildAllPlatforms();
|
|
3321
3379
|
})
|
|
@@ -3325,9 +3383,8 @@ async function run(options) {
|
|
|
3325
3383
|
console.log(`
|
|
3326
3384
|
\u{1F371} Building ${chalk4.green("semantic")}`);
|
|
3327
3385
|
await Promise.all(
|
|
3328
|
-
semanticConfigs.map(async ({
|
|
3329
|
-
|
|
3330
|
-
console.log(`\u{1F477} Processing: ${typographyTheme}`);
|
|
3386
|
+
semanticConfigs.map(async ({ theme, config, semantic: semantic2 }) => {
|
|
3387
|
+
console.log(`\u{1F477} ${theme} - ${semantic2}`);
|
|
3331
3388
|
const typographyClasses = await sd.extend(config);
|
|
3332
3389
|
return typographyClasses.buildAllPlatforms();
|
|
3333
3390
|
})
|
|
@@ -3337,8 +3394,8 @@ async function run(options) {
|
|
|
3337
3394
|
console.log(`
|
|
3338
3395
|
\u{1F371} Building ${chalk4.green("color-mode")}`);
|
|
3339
3396
|
await Promise.all(
|
|
3340
|
-
colorModeConfigs.map(async ({
|
|
3341
|
-
console.log(`\u{1F477}
|
|
3397
|
+
colorModeConfigs.map(async ({ theme, mode, config }) => {
|
|
3398
|
+
console.log(`\u{1F477} ${theme} - ${mode}`);
|
|
3342
3399
|
const themeVariablesSD = await sd.extend(config);
|
|
3343
3400
|
return themeVariablesSD.buildAllPlatforms();
|
|
3344
3401
|
})
|
|
@@ -3346,10 +3403,10 @@ async function run(options) {
|
|
|
3346
3403
|
}
|
|
3347
3404
|
if (storefrontConfigs.length > 0 && options.preview) {
|
|
3348
3405
|
console.log(`
|
|
3349
|
-
\u{1F371} Building ${chalk4.
|
|
3406
|
+
\u{1F371} Building ${chalk4.green("Storefront preview tokens")}`);
|
|
3350
3407
|
await Promise.all(
|
|
3351
|
-
storefrontConfigs.map(async ({
|
|
3352
|
-
console.log(`\u{1F477}
|
|
3408
|
+
storefrontConfigs.map(async ({ theme, mode, config }) => {
|
|
3409
|
+
console.log(`\u{1F477} ${theme} - ${mode}`);
|
|
3353
3410
|
const storefrontSD = await sd.extend(config);
|
|
3354
3411
|
return storefrontSD.buildAllPlatforms();
|
|
3355
3412
|
})
|