@digdir/designsystemet 0.1.0-next.21 → 0.1.0-next.23
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 +2 -2
- package/dist/src/colors/colorUtils.js +10 -10
- package/dist/src/init/createTokensPackage.js +27 -4
- package/dist/src/init/generateMetadataJson.js +6 -4
- package/dist/src/init/generateThemesJson.js +56 -5
- package/dist/src/init/nextStepsMarkdown.js +2 -2
- package/dist/src/init/template/default-files/design-tokens/primitives/globals.json +32 -68
- package/dist/src/init/template/default-files/design-tokens/primitives/size/default.json +175 -0
- package/dist/src/init/template/default-files/design-tokens/semantic/color.json +280 -270
- package/dist/src/init/template/default-files/design-tokens/semantic/style.json +307 -286
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/contrast/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/primary/theme-template.json +30 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/secondary/theme-template.json +30 -0
- package/dist/src/init/template/template-files/design-tokens/themes/theme-template.json +170 -150
- package/dist/src/init/template/template-files/package.json +1 -1
- package/dist/src/migrations/codemods/css/plugins.js +14 -15
- package/dist/src/migrations/codemods/jsx/classname-prefix.js +8 -7
- package/dist/src/tokens/actions.js +1 -1
- package/dist/src/tokens/build.js +26 -15
- package/dist/src/tokens/configs.js +20 -16
- package/dist/src/tokens/formats/css.js +42 -31
- package/dist/src/tokens/formats/js-tokens.js +8 -4
- package/dist/src/tokens/transformers.js +7 -3
- package/dist/src/tokens/utils/entryfile.js +31 -0
- package/dist/src/tokens/utils/permutateThemes.js +2 -2
- package/dist/src/tokens/utils/utils.js +11 -0
- package/dist/types/bin/designsystemet.d.ts +3 -0
- package/dist/types/bin/designsystemet.d.ts.map +1 -0
- package/dist/types/src/colors/colorUtils.d.ts +126 -0
- package/dist/types/src/colors/colorUtils.d.ts.map +1 -0
- package/dist/types/src/colors/index.d.ts +4 -0
- package/dist/types/src/colors/index.d.ts.map +1 -0
- package/dist/types/src/colors/themeUtils.d.ts +102 -0
- package/dist/types/src/colors/themeUtils.d.ts.map +1 -0
- package/dist/types/src/colors/types.d.ts +16 -0
- package/dist/types/src/colors/types.d.ts.map +1 -0
- package/dist/types/src/init/createTokensPackage.d.ts +5 -0
- package/dist/types/src/init/createTokensPackage.d.ts.map +1 -0
- package/dist/types/src/init/generateMetadataJson.d.ts +6 -0
- package/dist/types/src/init/generateMetadataJson.d.ts.map +1 -0
- package/dist/types/src/init/generateThemesJson.d.ts +3 -0
- package/dist/types/src/init/generateThemesJson.d.ts.map +1 -0
- package/dist/types/src/init/index.d.ts +3 -0
- package/dist/types/src/init/index.d.ts.map +1 -0
- package/dist/types/src/init/nextStepsMarkdown.d.ts +3 -0
- package/dist/types/src/init/nextStepsMarkdown.d.ts.map +1 -0
- package/dist/types/src/init/template/prettier.config.d.mts +9 -0
- package/dist/types/src/init/template/prettier.config.d.mts.map +1 -0
- package/dist/types/src/init/utils.d.ts +4 -0
- package/dist/types/src/init/utils.d.ts.map +1 -0
- package/dist/types/src/migrations/beta-to-v1.d.ts +3 -0
- package/dist/types/src/migrations/beta-to-v1.d.ts.map +1 -0
- package/dist/types/src/migrations/codemods/css/plugins.d.ts +6 -0
- package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/types/src/migrations/codemods/css/run.d.ts +8 -0
- package/dist/types/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts +10 -0
- package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +1 -0
- package/dist/types/src/migrations/codemods/jsx/run.d.ts +7 -0
- package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +1 -0
- package/dist/types/src/migrations/index.d.ts +6 -0
- package/dist/types/src/migrations/index.d.ts.map +1 -0
- package/dist/types/src/migrations/react-beta-to-v1.d.ts +3 -0
- package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +1 -0
- package/dist/types/src/tokens/actions.d.ts +6 -0
- package/dist/types/src/tokens/actions.d.ts.map +1 -0
- package/dist/types/src/tokens/build.d.ts +11 -0
- package/dist/types/src/tokens/build.d.ts.map +1 -0
- package/dist/types/src/tokens/configs.d.ts +31 -0
- package/dist/types/src/tokens/configs.d.ts.map +1 -0
- package/dist/types/src/tokens/formats/css.d.ts +5 -0
- package/dist/types/src/tokens/formats/css.d.ts.map +1 -0
- package/dist/types/src/tokens/formats/js-tokens.d.ts +6 -0
- package/dist/types/src/tokens/formats/js-tokens.d.ts.map +1 -0
- package/dist/types/src/tokens/transformers.d.ts +5 -0
- package/dist/types/src/tokens/transformers.d.ts.map +1 -0
- package/dist/types/src/tokens/utils/entryfile.d.ts +11 -0
- package/dist/types/src/tokens/utils/entryfile.d.ts.map +1 -0
- package/dist/types/src/tokens/utils/noCase.d.ts +11 -0
- package/dist/types/src/tokens/utils/noCase.d.ts.map +1 -0
- package/dist/types/src/tokens/utils/permutateThemes.d.ts +17 -0
- package/dist/types/src/tokens/utils/permutateThemes.d.ts.map +1 -0
- package/dist/types/src/tokens/utils/utils.d.ts +25 -0
- package/dist/types/src/tokens/utils/utils.d.ts.map +1 -0
- package/package.json +24 -22
- package/dist/src/init/template/default-files/design-tokens/primitives/typography/default.json +0 -86
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/theme-template.json +0 -314
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/global.json +0 -376
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/theme-template.json +0 -314
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/global.json +0 -376
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/theme-template.json +0 -314
- /package/dist/src/init/template/template-files/design-tokens/primitives/{colors → modes/colors}/contrast/global.json +0 -0
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { 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 { makeEntryFile } from "./actions.js";
|
|
6
5
|
import * as formats from "./formats/css.js";
|
|
7
6
|
import { jsTokens } from "./formats/js-tokens.js";
|
|
8
7
|
import { nameKebab, sizeRem, typographyShorthand } from "./transformers.js";
|
|
9
8
|
import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
|
|
10
|
-
import { typeEquals } from "./utils/utils.js";
|
|
11
|
-
void
|
|
9
|
+
import { pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
|
|
10
|
+
void register(StyleDictionary, { withSDBuiltins: false });
|
|
11
|
+
const usesDtcg = true;
|
|
12
12
|
const prefix = "ds";
|
|
13
13
|
const basePxFontSize = 16;
|
|
14
14
|
const separator = "_";
|
|
@@ -20,7 +20,6 @@ StyleDictionary.registerFormat(jsTokens);
|
|
|
20
20
|
StyleDictionary.registerFormat(formats.colormode);
|
|
21
21
|
StyleDictionary.registerFormat(formats.semantic);
|
|
22
22
|
StyleDictionary.registerFormat(formats.typography);
|
|
23
|
-
StyleDictionary.registerAction(makeEntryFile);
|
|
24
23
|
const dsTransformers = [
|
|
25
24
|
nameKebab.name,
|
|
26
25
|
`ts/resolveMath`,
|
|
@@ -31,7 +30,7 @@ const dsTransformers = [
|
|
|
31
30
|
"ts/color/modifiers",
|
|
32
31
|
"ts/color/css/hexrgba",
|
|
33
32
|
"ts/size/lineheight",
|
|
34
|
-
"
|
|
33
|
+
"shadow/css/shorthand"
|
|
35
34
|
];
|
|
36
35
|
const paritionPrimitives = R.partition(R.test(/(?!.*global\.json).*primitives.*/));
|
|
37
36
|
const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
|
|
@@ -48,6 +47,7 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
48
47
|
const selector = `${mode === "light" ? ":root, " : ""}[data-ds-color-mode="${mode}"]`;
|
|
49
48
|
const layer = `ds.theme.color-mode.${mode}`;
|
|
50
49
|
return {
|
|
50
|
+
usesDtcg,
|
|
51
51
|
log: { verbosity: "silent" },
|
|
52
52
|
preprocessors: ["tokens-studio"],
|
|
53
53
|
platforms: {
|
|
@@ -62,7 +62,6 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
62
62
|
prefix,
|
|
63
63
|
buildPath: `${outPath}/${theme}/`,
|
|
64
64
|
transforms: dsTransformers,
|
|
65
|
-
actions: [makeEntryFile.name],
|
|
66
65
|
files: [
|
|
67
66
|
{
|
|
68
67
|
destination: `color-mode/${mode}.css`,
|
|
@@ -81,8 +80,9 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
|
|
|
81
80
|
const semanticVariables = ({ outPath, theme }) => {
|
|
82
81
|
const selector = `:root`;
|
|
83
82
|
const layer = `ds.theme.semantic`;
|
|
84
|
-
const isCalculatedToken = (token) =>
|
|
83
|
+
const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing", "border-radius"], token);
|
|
85
84
|
return {
|
|
85
|
+
usesDtcg,
|
|
86
86
|
log: { verbosity: "silent" },
|
|
87
87
|
preprocessors: ["tokens-studio"],
|
|
88
88
|
platforms: {
|
|
@@ -98,12 +98,11 @@ const semanticVariables = ({ outPath, theme }) => {
|
|
|
98
98
|
prefix,
|
|
99
99
|
buildPath: `${outPath}/${theme}/`,
|
|
100
100
|
transforms: dsTransformers,
|
|
101
|
-
actions: [makeEntryFile.name],
|
|
102
101
|
files: [
|
|
103
102
|
{
|
|
104
103
|
destination: `semantic.css`,
|
|
105
104
|
format: formats.semantic.name,
|
|
106
|
-
filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "
|
|
105
|
+
filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily"], token)
|
|
107
106
|
}
|
|
108
107
|
],
|
|
109
108
|
options: {
|
|
@@ -116,6 +115,7 @@ const semanticVariables = ({ outPath, theme }) => {
|
|
|
116
115
|
};
|
|
117
116
|
const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
|
|
118
117
|
return {
|
|
118
|
+
usesDtcg,
|
|
119
119
|
log: { verbosity: "silent" },
|
|
120
120
|
preprocessors: ["tokens-studio"],
|
|
121
121
|
platforms: {
|
|
@@ -130,9 +130,8 @@ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
|
|
|
130
130
|
format: jsTokens.name,
|
|
131
131
|
outputReferences: outputColorReferences,
|
|
132
132
|
filter: (token) => {
|
|
133
|
-
if (R.test(/primitives\/modes|\/themes/, token.filePath))
|
|
134
|
-
|
|
135
|
-
}
|
|
133
|
+
if (R.test(/primitives\/modes|\/themes/, token.filePath)) return false;
|
|
134
|
+
if (pathStartsWithOneOf(["border-width"], token)) return false;
|
|
136
135
|
if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) || R.includes("semantic", token.filePath)) {
|
|
137
136
|
return true;
|
|
138
137
|
}
|
|
@@ -151,6 +150,7 @@ const typographyCSS = ({ outPath, theme, typography }) => {
|
|
|
151
150
|
const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
|
|
152
151
|
const layer = `ds.theme.typography.${typography}`;
|
|
153
152
|
return {
|
|
153
|
+
usesDtcg: true,
|
|
154
154
|
log: { verbosity: "silent" },
|
|
155
155
|
preprocessors: ["tokens-studio"],
|
|
156
156
|
platforms: {
|
|
@@ -167,10 +167,14 @@ const typographyCSS = ({ outPath, theme, typography }) => {
|
|
|
167
167
|
destination: `typography/${typography}.css`,
|
|
168
168
|
format: formats.typography.name,
|
|
169
169
|
filter: (token) => {
|
|
170
|
-
|
|
171
|
-
["typography", "
|
|
170
|
+
const included = typeEquals(
|
|
171
|
+
["typography", "fontweight", "fontFamily", "lineheight", "fontsize", "dimension", "font"],
|
|
172
|
+
token
|
|
173
|
+
);
|
|
174
|
+
return included && !pathStartsWithOneOf(
|
|
175
|
+
["spacing", "sizing", "border-width", "border-radius", "theme", "theme2", "theme3", "theme4"],
|
|
172
176
|
token
|
|
173
|
-
)
|
|
177
|
+
);
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
],
|
|
@@ -11,14 +11,15 @@ const colormode = {
|
|
|
11
11
|
name: "ds/css-colormode",
|
|
12
12
|
format: async ({ dictionary, file, options, platform }) => {
|
|
13
13
|
const { allTokens } = dictionary;
|
|
14
|
-
const { outputReferences } = options;
|
|
14
|
+
const { outputReferences, usesDtcg } = options;
|
|
15
15
|
const { selector, mode, layer } = platform;
|
|
16
16
|
const mode_ = mode;
|
|
17
17
|
const header = await fileHeader({ file });
|
|
18
18
|
const format = createPropertyFormatter({
|
|
19
19
|
outputReferences,
|
|
20
20
|
dictionary,
|
|
21
|
-
format: "css"
|
|
21
|
+
format: "css",
|
|
22
|
+
usesDtcg
|
|
22
23
|
});
|
|
23
24
|
const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `color-scheme: ${mode_};
|
|
24
25
|
` : "";
|
|
@@ -27,10 +28,12 @@ ${allTokens.map(format).join("\n")}
|
|
|
27
28
|
${colorSchemeProperty}}
|
|
28
29
|
`;
|
|
29
30
|
const autoSelectorContent = ["light", "dark"].includes(mode_) ? prefersColorScheme(mode_, content) : "";
|
|
30
|
-
|
|
31
|
+
const body = R.isNotNil(layer) ? `@layer ${layer} {
|
|
31
32
|
${selector} ${content} ${autoSelectorContent}
|
|
32
33
|
}
|
|
34
|
+
` : `${selector} ${content} ${autoSelectorContent}
|
|
33
35
|
`;
|
|
36
|
+
return header + body;
|
|
34
37
|
}
|
|
35
38
|
};
|
|
36
39
|
const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}: calc(${R.trim(split[1])});`);
|
|
@@ -38,13 +41,14 @@ const semantic = {
|
|
|
38
41
|
name: "ds/css-semantic",
|
|
39
42
|
format: async ({ dictionary, file, options, platform }) => {
|
|
40
43
|
const { allTokens } = dictionary;
|
|
41
|
-
const { outputReferences } = options;
|
|
44
|
+
const { outputReferences, usesDtcg } = options;
|
|
42
45
|
const { selector, isCalculatedToken, layer } = platform;
|
|
43
46
|
const header = await fileHeader({ file });
|
|
44
47
|
const format = createPropertyFormatter({
|
|
45
48
|
outputReferences,
|
|
46
49
|
dictionary,
|
|
47
|
-
format: "css"
|
|
50
|
+
format: "css",
|
|
51
|
+
usesDtcg
|
|
48
52
|
});
|
|
49
53
|
const formatTokens = R.map((token) => {
|
|
50
54
|
const originalValue = getValue(token.original);
|
|
@@ -60,13 +64,15 @@ const semantic = {
|
|
|
60
64
|
${formattedVariables.join("\n")}
|
|
61
65
|
}
|
|
62
66
|
`;
|
|
63
|
-
|
|
67
|
+
const body = R.isNotNil(layer) ? `@layer ${layer} {
|
|
64
68
|
${selector} ${content}
|
|
65
69
|
}
|
|
70
|
+
` : `${selector} ${content}
|
|
66
71
|
`;
|
|
72
|
+
return header + body;
|
|
67
73
|
}
|
|
68
74
|
};
|
|
69
|
-
const sortByType = R.sortBy((token) => token
|
|
75
|
+
const sortByType = R.sortBy((token) => token?.$type === "typography");
|
|
70
76
|
const getVariableName = R.pipe(
|
|
71
77
|
R.split(":"),
|
|
72
78
|
R.head,
|
|
@@ -92,61 +98,66 @@ const sortTypographyLast = R.sortWith([
|
|
|
92
98
|
const typography = {
|
|
93
99
|
name: "ds/css-typography",
|
|
94
100
|
format: async ({ dictionary, file, options, platform }) => {
|
|
95
|
-
const { outputReferences } = options;
|
|
101
|
+
const { outputReferences, usesDtcg } = options;
|
|
96
102
|
const { selector, layer } = platform;
|
|
97
103
|
const header = await fileHeader({ file });
|
|
98
104
|
const format = createPropertyFormatter({
|
|
99
105
|
outputReferences,
|
|
100
106
|
dictionary,
|
|
101
|
-
format: "css"
|
|
107
|
+
format: "css",
|
|
108
|
+
usesDtcg
|
|
102
109
|
});
|
|
103
110
|
const sortedTokens = sortTypographyLast(dictionary.allTokens);
|
|
104
111
|
const formattedTokens = R.pipe(
|
|
105
112
|
sortByType,
|
|
106
113
|
R.reduce(
|
|
107
114
|
(acc, token) => {
|
|
108
|
-
if (typeEquals("
|
|
115
|
+
if (typeEquals("fontweight", token)) {
|
|
109
116
|
const className = `
|
|
110
117
|
.${classSelector(token)} {
|
|
111
118
|
font-weight: ${getValue(token)};
|
|
112
119
|
}`;
|
|
113
|
-
return {
|
|
114
|
-
...acc,
|
|
120
|
+
return Object.assign(acc, {
|
|
115
121
|
variables: [...acc.variables, format(token)],
|
|
116
122
|
classes: [...acc.classes, className]
|
|
117
|
-
};
|
|
123
|
+
});
|
|
118
124
|
}
|
|
119
|
-
if (typeEquals("
|
|
125
|
+
if (typeEquals("lineheight", token)) {
|
|
120
126
|
const className = `
|
|
121
127
|
.${classSelector(token)} {
|
|
122
128
|
line-height: ${getValue(token)};
|
|
123
129
|
}`;
|
|
124
|
-
return {
|
|
125
|
-
...acc,
|
|
130
|
+
return Object.assign(acc, {
|
|
126
131
|
variables: [...acc.variables, format(token)],
|
|
127
132
|
classes: [...acc.classes, className]
|
|
128
|
-
};
|
|
133
|
+
});
|
|
129
134
|
}
|
|
130
135
|
if (typeEquals("typography", token)) {
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
+
let references = [];
|
|
137
|
+
try {
|
|
138
|
+
references = getReferences(getValue(token.original), dictionary.tokens);
|
|
139
|
+
} catch (error) {
|
|
140
|
+
console.error("Error getting references", error);
|
|
141
|
+
throw new Error(JSON.stringify(token, null, 2));
|
|
142
|
+
}
|
|
143
|
+
const fontweight = R.find(typeEquals(["fontweight"]))(references);
|
|
144
|
+
const lineheight = R.find(typeEquals(["lineheight"]))(references);
|
|
145
|
+
const fontsize = R.find(typeEquals(["fontsize"]))(references);
|
|
146
|
+
const letterSpacing = R.find(typeEquals(["dimension"]))(references);
|
|
136
147
|
const fontSizeVar = fontsize ? getVariableName(format(fontsize)) : null;
|
|
137
148
|
const fontWeightVar = fontweight ? getVariableName(format(fontweight)) : null;
|
|
138
149
|
const lineheightVar = lineheight ? getVariableName(format(lineheight)) : null;
|
|
139
150
|
const letterSpacingVar = letterSpacing ? getVariableName(format(letterSpacing)) : null;
|
|
140
151
|
const className = `
|
|
141
152
|
.${classSelector(token)} {
|
|
142
|
-
${fontSizeVar
|
|
143
|
-
${lineheightVar
|
|
144
|
-
${fontWeightVar
|
|
145
|
-
${letterSpacingVar
|
|
153
|
+
${fontSizeVar ? `font-size: ${fontSizeVar};` : ""}
|
|
154
|
+
${lineheightVar ? `line-height: ${lineheightVar};` : ""}
|
|
155
|
+
${fontWeightVar ? `font-weight: ${fontWeightVar};` : ""}
|
|
156
|
+
${letterSpacingVar ? `letter-spacing: ${letterSpacingVar};` : ""}
|
|
146
157
|
}`;
|
|
147
|
-
return
|
|
158
|
+
return Object.assign(acc, { classes: [className, ...acc.classes] });
|
|
148
159
|
}
|
|
149
|
-
return
|
|
160
|
+
return Object.assign(acc, { variables: [...acc.variables, format(token)] });
|
|
150
161
|
},
|
|
151
162
|
{ variables: [], classes: [] }
|
|
152
163
|
)
|
|
@@ -157,10 +168,10 @@ const typography = {
|
|
|
157
168
|
${variables}
|
|
158
169
|
${classes}
|
|
159
170
|
}` : classes;
|
|
160
|
-
|
|
171
|
+
const body = R.isNotNil(layer) ? `@layer ${layer} {
|
|
161
172
|
${content}
|
|
162
|
-
}
|
|
163
|
-
|
|
173
|
+
}` : content;
|
|
174
|
+
return header + body;
|
|
164
175
|
}
|
|
165
176
|
};
|
|
166
177
|
export {
|
|
@@ -3,21 +3,25 @@ import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
|
|
|
3
3
|
import { getType } from "../utils/utils.js";
|
|
4
4
|
const groupByType = R.groupBy((token) => getType(token));
|
|
5
5
|
const removeUnwatedTokens = R.filter(
|
|
6
|
-
(token) => !["
|
|
6
|
+
(token) => !["ds-base-spacing", "ds-base-sizing"].includes(token.name)
|
|
7
7
|
);
|
|
8
|
+
const dissocExtensions = R.pipe(R.dissoc("$extensions"), R.dissocPath(["original", "$extensions"]));
|
|
9
|
+
const removeUnwatedProps = R.map((token) => dissocExtensions(token));
|
|
8
10
|
const toCssVarName = R.pipe(R.split(":"), R.head, R.trim);
|
|
9
11
|
const jsTokens = {
|
|
10
12
|
name: "ds/js-tokens",
|
|
11
|
-
format: async ({ dictionary, file }) => {
|
|
13
|
+
format: async ({ dictionary, file, options }) => {
|
|
14
|
+
const { usesDtcg } = options;
|
|
12
15
|
const format = createPropertyFormatter({
|
|
13
16
|
dictionary,
|
|
14
|
-
format: "css"
|
|
17
|
+
format: "css",
|
|
18
|
+
usesDtcg
|
|
15
19
|
});
|
|
16
20
|
const formatTokens = R.map((token) => ({
|
|
17
21
|
...token,
|
|
18
22
|
name: toCssVarName(format(token))
|
|
19
23
|
}));
|
|
20
|
-
const processTokens = R.pipe(removeUnwatedTokens, formatTokens, groupByType);
|
|
24
|
+
const processTokens = R.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
|
|
21
25
|
const tokens = processTokens(dictionary.allTokens);
|
|
22
26
|
const content = Object.entries(tokens).map(
|
|
23
27
|
([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
|
|
@@ -1,12 +1,16 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { noCase } from "./utils/noCase.js";
|
|
3
|
-
import { getValue, typeEquals } from "./utils/utils.js";
|
|
3
|
+
import { getValue, pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
|
|
4
4
|
const isPx = R.test(/\b\d+px\b/g);
|
|
5
5
|
const sizeRem = {
|
|
6
6
|
name: "ds/size/toRem",
|
|
7
7
|
type: "value",
|
|
8
8
|
transitive: true,
|
|
9
|
-
filter: (token) =>
|
|
9
|
+
filter: (token) => {
|
|
10
|
+
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
11
|
+
const hasWantedPath = pathStartsWithOneOf(["spacing", "sizing", "border-radius", "font-size"], token);
|
|
12
|
+
return hasWantedType && hasWantedPath;
|
|
13
|
+
},
|
|
10
14
|
transform: (token, config) => {
|
|
11
15
|
const value = getValue(token);
|
|
12
16
|
if (isPx(value)) {
|
|
@@ -34,7 +38,7 @@ const typographyShorthand = {
|
|
|
34
38
|
name: "typography/shorthand",
|
|
35
39
|
type: "value",
|
|
36
40
|
transitive: true,
|
|
37
|
-
filter: (token) =>
|
|
41
|
+
filter: (token) => typeEquals("typography", token),
|
|
38
42
|
transform: (token) => {
|
|
39
43
|
const typography = getValue(token);
|
|
40
44
|
return `${typography.fontWeight} ${typography.fontSize}/${typography.lineHeight} '${typography.fontFamily}'`;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import glob from "fast-glob";
|
|
2
|
+
import fs from "fs-extra";
|
|
3
|
+
import * as R from "ramda";
|
|
4
|
+
const sortLightmodeFirst = R.sortWith([R.descend(R.includes("light")), R.descend(R.includes("secondary"))]);
|
|
5
|
+
const header = `@charset "UTF-8";
|
|
6
|
+
|
|
7
|
+
@layer ds.reset, ds.theme, ds.base, ds.utilities, ds.components;
|
|
8
|
+
|
|
9
|
+
`;
|
|
10
|
+
const sortAndConcat = R.pipe(
|
|
11
|
+
sortLightmodeFirst,
|
|
12
|
+
R.map((file) => {
|
|
13
|
+
try {
|
|
14
|
+
const content = fs.readFileSync(file, "utf-8").toString();
|
|
15
|
+
return content;
|
|
16
|
+
} catch (e) {
|
|
17
|
+
console.error(`Error reading file: ${file}`);
|
|
18
|
+
return "";
|
|
19
|
+
}
|
|
20
|
+
}),
|
|
21
|
+
R.join("\n")
|
|
22
|
+
);
|
|
23
|
+
const makeEntryFile = async ({ outPath, buildPath, theme }) => {
|
|
24
|
+
const writePath = `${outPath}/${theme}.css`;
|
|
25
|
+
const files = await glob(`**/*`, { cwd: buildPath });
|
|
26
|
+
const content = header + sortAndConcat(files.map((file) => `${buildPath}/${file}`));
|
|
27
|
+
await fs.writeFile(writePath, content);
|
|
28
|
+
};
|
|
29
|
+
export {
|
|
30
|
+
makeEntryFile
|
|
31
|
+
};
|
|
@@ -8,7 +8,7 @@ function permutateThemes(themes, { separator = "-" } = {}) {
|
|
|
8
8
|
return mapThemesToSetsObject(themes);
|
|
9
9
|
}
|
|
10
10
|
const groups = {};
|
|
11
|
-
|
|
11
|
+
for (const theme of themes) {
|
|
12
12
|
if (theme.group) {
|
|
13
13
|
groups[theme.group] = [...groups[theme.group] ?? [], theme];
|
|
14
14
|
} else {
|
|
@@ -16,7 +16,7 @@ function permutateThemes(themes, { separator = "-" } = {}) {
|
|
|
16
16
|
`Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
|
|
17
17
|
);
|
|
18
18
|
}
|
|
19
|
-
}
|
|
19
|
+
}
|
|
20
20
|
if (Object.keys(groups).length <= 1) {
|
|
21
21
|
return mapThemesToSetsObject(themes);
|
|
22
22
|
}
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
+
const mapToLowerCase = R.map(R.toLower);
|
|
3
|
+
const hasAnyTruth = R.any(R.equals(true));
|
|
2
4
|
const getType = (token) => (token.$type ?? token.type) || "";
|
|
3
5
|
const getValue = (token) => token.$value ?? token.value;
|
|
4
6
|
const typeEquals = R.curry((types, token) => {
|
|
@@ -7,8 +9,17 @@ const typeEquals = R.curry((types, token) => {
|
|
|
7
9
|
}
|
|
8
10
|
return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
|
|
9
11
|
});
|
|
12
|
+
const pathStartsWithOneOf = R.curry((paths, token) => {
|
|
13
|
+
if (R.isNil(token)) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
const tokenPath = mapToLowerCase(token.path);
|
|
17
|
+
const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
|
|
18
|
+
return hasAnyTruth(matchPathsStartingWith);
|
|
19
|
+
});
|
|
10
20
|
export {
|
|
11
21
|
getType,
|
|
12
22
|
getValue,
|
|
23
|
+
pathStartsWithOneOf,
|
|
13
24
|
typeEquals
|
|
14
25
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"designsystemet.d.ts","sourceRoot":"","sources":["../../../bin/designsystemet.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import type { CssColor } from '@adobe/leonardo-contrast-colors';
|
|
2
|
+
/**
|
|
3
|
+
* Converts a HEX color '#xxxxxx' into a CSS HSL string 'hsl(x,x,x)'
|
|
4
|
+
*
|
|
5
|
+
* @param hex A hex color string
|
|
6
|
+
* @param valuesOnly If true, only the values are returned
|
|
7
|
+
* @returns A CSS HSL string
|
|
8
|
+
*/
|
|
9
|
+
export declare const hexToCssHsl: (hex: string, valuesOnly?: boolean) => string;
|
|
10
|
+
/**
|
|
11
|
+
* Converts a HEX string '#xxxxxx' into an array of HSL values '[h,s,l]'
|
|
12
|
+
*
|
|
13
|
+
* @param H A Hex color string
|
|
14
|
+
* @returns HSL values in an array
|
|
15
|
+
*/
|
|
16
|
+
export declare const hexToHSL: (H: string) => number[];
|
|
17
|
+
/**
|
|
18
|
+
* Converts a HEX color '#xxxxxx' into an array of HSLuv values '[h,s,l]'
|
|
19
|
+
*
|
|
20
|
+
* @param hex A hex color string
|
|
21
|
+
* @returns
|
|
22
|
+
*/
|
|
23
|
+
export declare const hexToHsluv: (hex: string) => number[];
|
|
24
|
+
/**
|
|
25
|
+
* Converts a HSL number array '[h,s,l]' into HSL CSS string 'hsl(x,x,x)'
|
|
26
|
+
*
|
|
27
|
+
* @param HSL A HSL number array '[h,s,l]'
|
|
28
|
+
* @returns A hex color string
|
|
29
|
+
*/
|
|
30
|
+
export declare const hslArrToCss: (HSL: number[]) => string;
|
|
31
|
+
/**
|
|
32
|
+
* Converts a HSL CSS string 'hsl(x,x,x)' into an array of HSL values '[h,s,l]'
|
|
33
|
+
*
|
|
34
|
+
* @param h The HSL hue
|
|
35
|
+
* @param s The HSL saturation
|
|
36
|
+
* @param l The HSL lightness
|
|
37
|
+
* @returns HEX color string
|
|
38
|
+
*/
|
|
39
|
+
export declare const HSLToHex: (h: number, s: number, l: number) => string;
|
|
40
|
+
/**
|
|
41
|
+
* Converts a HEX color '#xxxxxx' into an array of RGB values '[R, G, B]'
|
|
42
|
+
*
|
|
43
|
+
* @param hex A hex color string
|
|
44
|
+
* @returns RGB values in an array
|
|
45
|
+
*/
|
|
46
|
+
export declare const hexToRgb: (hex: string) => {
|
|
47
|
+
r: number;
|
|
48
|
+
g: number;
|
|
49
|
+
b: number;
|
|
50
|
+
} | null;
|
|
51
|
+
/**
|
|
52
|
+
* Get the luminance of an RGB color
|
|
53
|
+
*
|
|
54
|
+
* @param r RGB red value
|
|
55
|
+
* @param G RGB green value
|
|
56
|
+
* @param b RGB blue value
|
|
57
|
+
* @returns
|
|
58
|
+
*/
|
|
59
|
+
export declare const luminanceFromRgb: (r: string, g: string, b: string) => number;
|
|
60
|
+
/**
|
|
61
|
+
* Get the luminance of a HEX color
|
|
62
|
+
*
|
|
63
|
+
* @param hex A hex color string
|
|
64
|
+
* @returns
|
|
65
|
+
*/
|
|
66
|
+
export declare const luminanceFromHex: (hex: CssColor) => number;
|
|
67
|
+
/**
|
|
68
|
+
* Get the contrast ratio between two luminance values
|
|
69
|
+
*
|
|
70
|
+
* @param lum1 The first luminance value
|
|
71
|
+
* @param lum2 The second luminance value
|
|
72
|
+
* @returns
|
|
73
|
+
*/
|
|
74
|
+
export declare const getRatioFromLum: (lum1: number, lum2: number) => number;
|
|
75
|
+
/**
|
|
76
|
+
* Get the HSL lightness from a HEX color
|
|
77
|
+
*
|
|
78
|
+
* @param hex A hex color string
|
|
79
|
+
* @returns
|
|
80
|
+
*/
|
|
81
|
+
export declare const getHslLightessFromHex: (hex: CssColor) => number;
|
|
82
|
+
export declare const getHslSaturationFromHex: (hex: CssColor) => number;
|
|
83
|
+
/**
|
|
84
|
+
* Get the HSLuv lightness from a HEX color
|
|
85
|
+
*
|
|
86
|
+
* @param hex A hex color string
|
|
87
|
+
* @returns
|
|
88
|
+
*/
|
|
89
|
+
export declare const getLightnessFromHex: (hex: string) => number;
|
|
90
|
+
/**
|
|
91
|
+
* Get the contrast ratio between two HEX colors
|
|
92
|
+
*
|
|
93
|
+
* @param {CssColor} color1 The first color
|
|
94
|
+
* @param {CssColor} color2 The second color
|
|
95
|
+
* @returns
|
|
96
|
+
*/
|
|
97
|
+
export declare const getContrastFromHex: (color1: CssColor, color2: CssColor) => number;
|
|
98
|
+
/**
|
|
99
|
+
* Get the contrast ratio between two colors at a specific lightness
|
|
100
|
+
*
|
|
101
|
+
* @param lightness The lightness value
|
|
102
|
+
* @param mainColor The main color
|
|
103
|
+
* @param backgroundColor The background color
|
|
104
|
+
* @returns The contrast ratio
|
|
105
|
+
*/
|
|
106
|
+
export declare const getContrastFromLightness: (lightness: number, mainColor: CssColor, backgroundColor: CssColor) => number;
|
|
107
|
+
/**
|
|
108
|
+
* Maps the numbers from [start1 - end1] to the range [start2 - end2], maintaining the proportionality between the numbers in the ranges using lineaer interpolation.
|
|
109
|
+
*/
|
|
110
|
+
/**
|
|
111
|
+
* Check if two colors have enough contrast to be used together
|
|
112
|
+
*
|
|
113
|
+
* @param {CssColor} color1 The first color
|
|
114
|
+
* @param {CssColor} color2 The second color
|
|
115
|
+
* @returns {boolean} If the colors have enough contrast
|
|
116
|
+
*/
|
|
117
|
+
export declare const areColorsContrasting: (color1: CssColor, color2: CssColor, type?: "decorative" | "aa" | "aaa") => boolean;
|
|
118
|
+
export declare const getApcaContrastLc: (textColor: CssColor, backgroundColor: CssColor) => string | number;
|
|
119
|
+
/**
|
|
120
|
+
* Check if aa string value is a HEX color
|
|
121
|
+
*
|
|
122
|
+
* @param {string} hex The string to check
|
|
123
|
+
* @returns {boolean} If the string is a HEX color
|
|
124
|
+
*/
|
|
125
|
+
export declare const isHexColor: (hex: string) => boolean;
|
|
126
|
+
//# sourceMappingURL=colorUtils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"colorUtils.d.ts","sourceRoot":"","sources":["../../../../src/colors/colorUtils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAKhE;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,QAAS,MAAM,iCA6CtC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,MAAO,MAAM,aAwCjC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,aAKrC,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,WAAW,QAAS,MAAM,EAAE,WAExC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,WA+CvD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,QAAQ,QAAS,MAAM;;;;QAYnC,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,gBAAgB,MAAO,MAAM,KAAK,MAAM,KAAK,MAAM,WAM/D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,QAAS,QAAQ,WAS7C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,SAAU,MAAM,QAAQ,MAAM,WAKzD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,QAAS,QAAQ,WAElD,CAAC;AAEF,eAAO,MAAM,uBAAuB,QAAS,QAAQ,WAEpD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,QAAS,MAAM,WAK9C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,WAAY,QAAQ,UAAU,QAAQ,WAOpE,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,wBAAwB,cAAe,MAAM,aAAa,QAAQ,mBAAmB,QAAQ,WAYzG,CAAC;AAEF;;GAEG;AAKH;;;;;;GAMG;AACH,eAAO,MAAM,oBAAoB,WAAY,QAAQ,UAAU,QAAQ,SAAQ,YAAY,GAAG,IAAI,GAAG,KAAK,YAYzG,CAAC;AAEF,eAAO,MAAM,iBAAiB,cAAe,QAAQ,mBAAmB,QAAQ,oBAW/E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,UAAU,QAAS,MAAM,YAErC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/colors/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,cAAc,CAAC;AAC7B,cAAc,SAAS,CAAC"}
|