@digdir/designsystemet 1.0.0-next.36 → 1.0.0-next.37
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/src/colors/theme.d.ts +2 -2
- package/dist/src/colors/theme.d.ts.map +1 -1
- package/dist/src/colors/theme.js +11 -11
- package/dist/src/init/createTokensPackage.js +4 -4
- package/dist/src/init/generateMetadataJson.js +2 -2
- package/dist/src/init/generateThemesJson.js +2 -2
- package/dist/src/init/nextStepsMarkdown.js +2 -2
- package/dist/src/tokens/build/configs.d.ts +1 -1
- package/dist/src/tokens/build/configs.d.ts.map +1 -1
- package/dist/src/tokens/build/configs.js +12 -12
- package/dist/src/tokens/build/formats/css.d.ts +2 -2
- package/dist/src/tokens/build/formats/css.d.ts.map +1 -1
- package/dist/src/tokens/build/formats/css.js +13 -13
- package/dist/src/tokens/build/types.d.ts +1 -1
- package/dist/src/tokens/build/types.d.ts.map +1 -1
- package/dist/src/tokens/build/utils/entryfile.js +3 -3
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +1 -1
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +24 -3
- package/dist/src/tokens/design-tokens/template/$metadata.json +4 -4
- package/dist/src/tokens/design-tokens/template/$themes.json +12 -12
- package/dist/src/tokens/write/generate$metadata.js +2 -2
- package/dist/src/tokens/write/generate$themes.js +4 -4
- package/dist/src/tokens/write.js +8 -8
- package/package.json +1 -1
|
@@ -16,9 +16,9 @@ type ThemeGenType = {
|
|
|
16
16
|
* Generates a color scale based on a base color and a mode.
|
|
17
17
|
*
|
|
18
18
|
* @param color The base color that is used to generate the color scale
|
|
19
|
-
* @param
|
|
19
|
+
* @param colorScheme The color scheme to generate a scale for
|
|
20
20
|
*/
|
|
21
|
-
export declare const generateScaleForColor: (color: CssColor,
|
|
21
|
+
export declare const generateScaleForColor: (color: CssColor, colorScheme: ColorMode, contrastMode?: "aa" | "aaa") => ColorInfo[];
|
|
22
22
|
/**
|
|
23
23
|
*
|
|
24
24
|
* Generates a color theme based on a base color. Light, Dark and Contrast scales are includes.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/colors/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAKhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG3G,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,YAAY,EAAE,QAAQ,CAOrD,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,aAAa,CAAC;AAE/D,KAAK,aAAa,GAAG;IACnB,SAAS,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC;IAC9B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AA2EF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,UACzB,QAAQ,
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/colors/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAKhE,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG3G,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,YAAY,EAAE,QAAQ,CAOrD,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,YAAY,GAAG,aAAa,CAAC;AAE/D,KAAK,aAAa,GAAG;IACnB,SAAS,CAAC,EAAE,SAAS,GAAG,KAAK,CAAC;IAC9B,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AAEF,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,YAAY,CAAC;CAC7B,CAAC;AA2EF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,UACzB,QAAQ,eACF,SAAS,iBACR,IAAI,GAAG,KAAK,KACzB,SAAS,EAuCX,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,qBAAqB,UAAW,QAAQ,iBAAgB,IAAI,GAAG,KAAK,KAAU,SAU1F,CAAC;AAEF,eAAO,MAAM,oBAAoB,qBAA6B,aAAa,KAAG,MAAM,CAAC,YAAY,EAAE,SAAS,CAgB3G,CAAC;AAEF,KAAK,mBAAmB,GAAG;IACzB,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;IACnC,OAAO,EAAE,SAAS,CAAC;CACpB,CAAC;AACF;;;;;;GAMG;AACH,eAAO,MAAM,kBAAkB,6BAAqC,YAAY,KAAG,mBAUlF,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,cAAe,QAAQ,0BAO5D,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,yBAAyB,UAAW,QAAQ,aAaxD,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,qBAAsB,QAAQ,mBAAmB,QAAQ,YAe1F,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,UAAW,QAAQ,aAAa,MAAM,aAkB1E,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,SAAU,MAAM,KAAG,WAmBrD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,sBAAsB,WAAY,WAAW,KAAG,MAmB5D,CAAC;AAEF,eAAO,MAAM,YAAY,UAAW,QAAQ,KAQvB,QACpB,CAAC;AAEF,eAAO,MAAM,cAAc,cAAe,MAAM,eAAe,WAAW,WAEzE,CAAC"}
|
package/dist/src/colors/theme.js
CHANGED
|
@@ -10,14 +10,14 @@ const baseColors = {
|
|
|
10
10
|
red: "#C01B1B",
|
|
11
11
|
yellow: "#D4B12F"
|
|
12
12
|
};
|
|
13
|
-
const generateThemeColor = (color,
|
|
13
|
+
const generateThemeColor = (color, colorScheme, contrastMode = "aa") => {
|
|
14
14
|
const leoBackgroundColor = new BackgroundColor({
|
|
15
15
|
name: "backgroundColor",
|
|
16
16
|
colorKeys: ["#ffffff"],
|
|
17
17
|
ratios: [1]
|
|
18
18
|
});
|
|
19
19
|
let colorLightness = getLightnessFromHex(color);
|
|
20
|
-
if (
|
|
20
|
+
if (colorScheme === "dark" || colorScheme === "contrast") {
|
|
21
21
|
color = getBaseColor(color);
|
|
22
22
|
colorLightness = colorLightness <= 30 ? 70 : 100 - colorLightness;
|
|
23
23
|
}
|
|
@@ -35,15 +35,15 @@ const generateThemeColor = (color, mode, contrastMode = "aa") => {
|
|
|
35
35
|
color,
|
|
36
36
|
leoBackgroundColor.colorKeys[0]
|
|
37
37
|
);
|
|
38
|
-
const textSubLightLightness = contrastMode === "aa" ?
|
|
38
|
+
const textSubLightLightness = contrastMode === "aa" ? 41 : 30;
|
|
39
39
|
const textDefLightLightness = contrastMode === "aa" ? 18 : 12;
|
|
40
|
-
const textSubDarkLightness = contrastMode === "aa" ?
|
|
40
|
+
const textSubDarkLightness = contrastMode === "aa" ? 66 : 80;
|
|
41
41
|
const textDefDarkLightness = contrastMode === "aa" ? 90 : 94;
|
|
42
42
|
let lightnessScale = [];
|
|
43
|
-
if (
|
|
44
|
-
lightnessScale = [100, 96, 90, 84, 78, 76,
|
|
45
|
-
} else if (
|
|
46
|
-
lightnessScale = [10, 14, 20, 26, 32, 35,
|
|
43
|
+
if (colorScheme === "light") {
|
|
44
|
+
lightnessScale = [100, 96, 90, 84, 78, 76, 53, 41, textSubLightLightness, textDefLightLightness];
|
|
45
|
+
} else if (colorScheme === "dark") {
|
|
46
|
+
lightnessScale = [10, 14, 20, 26, 32, 35, 52, 66, textSubDarkLightness, textDefDarkLightness];
|
|
47
47
|
} else {
|
|
48
48
|
lightnessScale = [1, 6, 14, 20, 26, 58, 70, 82, 80, 95];
|
|
49
49
|
}
|
|
@@ -62,8 +62,8 @@ const generateThemeColor = (color, mode, contrastMode = "aa") => {
|
|
|
62
62
|
]
|
|
63
63
|
});
|
|
64
64
|
};
|
|
65
|
-
const generateScaleForColor = (color,
|
|
66
|
-
const themeColor = generateThemeColor(color,
|
|
65
|
+
const generateScaleForColor = (color, colorScheme, contrastMode = "aa") => {
|
|
66
|
+
const themeColor = generateThemeColor(color, colorScheme, contrastMode);
|
|
67
67
|
const leoBackgroundColor = new BackgroundColor({
|
|
68
68
|
name: "backgroundColor",
|
|
69
69
|
colorKeys: ["#ffffff"],
|
|
@@ -92,7 +92,7 @@ const generateScaleForColor = (color, mode, contrastMode = "aa") => {
|
|
|
92
92
|
number: 15,
|
|
93
93
|
name: getColorNameFromNumber(15)
|
|
94
94
|
});
|
|
95
|
-
if (
|
|
95
|
+
if (colorScheme === "light") {
|
|
96
96
|
outputArray[8].hex = color;
|
|
97
97
|
}
|
|
98
98
|
return outputArray;
|
|
@@ -188,15 +188,15 @@ Will now create the following:
|
|
|
188
188
|
for (const theme of themes.map(normalizeTokenSetName)) {
|
|
189
189
|
for (const mode of modes.map(normalizeTokenSetName)) {
|
|
190
190
|
await fs.cp(
|
|
191
|
-
path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/
|
|
192
|
-
path.join(TOKENS_TARGET_DIR, `primitives/modes/
|
|
191
|
+
path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/color-scheme/${mode}/global.json`),
|
|
192
|
+
path.join(TOKENS_TARGET_DIR, `primitives/modes/color-scheme/${mode}/global.json`),
|
|
193
193
|
{ recursive: true }
|
|
194
194
|
);
|
|
195
195
|
const template2 = await fs.readFile(
|
|
196
|
-
path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/
|
|
196
|
+
path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/color-scheme/${mode}/theme-template.json`)
|
|
197
197
|
);
|
|
198
198
|
await fs.writeFile(
|
|
199
|
-
path.join(TOKENS_TARGET_DIR, `primitives/modes/
|
|
199
|
+
path.join(TOKENS_TARGET_DIR, `primitives/modes/color-scheme/${mode}/${theme}.json`),
|
|
200
200
|
template2.toString("utf-8").replaceAll("<theme>", theme)
|
|
201
201
|
);
|
|
202
202
|
const templatePrimaryTypo = await fs.readFile(
|
|
@@ -7,9 +7,9 @@ function generateMetadataJson(modes, themes) {
|
|
|
7
7
|
"primitives/modes/typography/primary/theme",
|
|
8
8
|
"primitives/modes/typography/secondary/theme",
|
|
9
9
|
...modes.flatMap((mode) => [
|
|
10
|
-
`primitives/modes/
|
|
10
|
+
`primitives/modes/color-scheme/${normalizeTokenSetName(mode)}/global`,
|
|
11
11
|
...themes.map(
|
|
12
|
-
(theme) => `primitives/modes/
|
|
12
|
+
(theme) => `primitives/modes/color-scheme/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`
|
|
13
13
|
)
|
|
14
14
|
]),
|
|
15
15
|
...themes.map((theme) => `themes/${normalizeTokenSetName(theme)}`),
|
|
@@ -36,10 +36,10 @@ function generateModesGroup(modes, themes) {
|
|
|
36
36
|
id: randomUUID(),
|
|
37
37
|
name: mode,
|
|
38
38
|
selectedTokenSets: Object.fromEntries([
|
|
39
|
-
[`primitives/modes/
|
|
39
|
+
[`primitives/modes/color-scheme/${normalizeTokenSetName(mode)}/global`, TokenSetStatus.ENABLED],
|
|
40
40
|
...themes.map(
|
|
41
41
|
(theme) => [
|
|
42
|
-
`primitives/modes/
|
|
42
|
+
`primitives/modes/color-scheme/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`,
|
|
43
43
|
TokenSetStatus.ENABLED
|
|
44
44
|
]
|
|
45
45
|
)
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { normalizeTokenSetName, toGeneratedCssFileName } from "./utils.js";
|
|
2
2
|
function nextStepsMarkdown(themes, modes, tokensTargetDir, packageName) {
|
|
3
3
|
const themeModeCombinations = themes.flatMap(
|
|
4
|
-
(theme) => modes.map((
|
|
4
|
+
(theme) => modes.map((colorScheme) => [theme, colorScheme])
|
|
5
5
|
);
|
|
6
6
|
const themeOrThemes = `theme${themes.length > 1 ? "s" : ""}`;
|
|
7
7
|
const isOrAre = themes.length > 1 ? "are" : "is";
|
|
@@ -24,7 +24,7 @@ function nextStepsMarkdown(themes, modes, tokensTargetDir, packageName) {
|
|
|
24
24
|
2. Press "Kopier tema"
|
|
25
25
|
3. Under "Json til Figma", copy the contents under ${modes.join(" / ")} to
|
|
26
26
|
the corresponding file under \`${tokensTargetDir}\`:
|
|
27
|
-
${themeModeCombinations.map(([theme, mode]) => ` **${theme}, ${mode}**: \`primitives/modes/
|
|
27
|
+
${themeModeCombinations.map(([theme, mode]) => ` **${theme}, ${mode}**: \`primitives/modes/color-scheme/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}.json\` `).join("\n")}
|
|
28
28
|
This can also be done in Tokens Studio for Figma.
|
|
29
29
|
4. **IMPORTANT!** In the JSON data you copied, replace \`theme\` on line 2
|
|
30
30
|
with the correct theme identifier, depending on the theme you're customizing.
|
|
@@ -10,7 +10,7 @@ export type GetStyleDictionaryConfig = (permutation: ThemePermutation, options:
|
|
|
10
10
|
permutationOverrides?: Partial<ThemePermutation>;
|
|
11
11
|
}[];
|
|
12
12
|
export declare const configs: {
|
|
13
|
-
|
|
13
|
+
colorSchemeVariables: GetStyleDictionaryConfig;
|
|
14
14
|
mainColorVariables: GetStyleDictionaryConfig;
|
|
15
15
|
supportColorVariables: GetStyleDictionaryConfig;
|
|
16
16
|
typographyVariables: GetStyleDictionaryConfig;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/configs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAoB,MAAM,wBAAwB,CAAC;AAOhG,OAAO,KAAK,EAEV,kBAAkB,EAElB,2BAA2B,EAC3B,cAAc,EACd,gBAAgB,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,oBAAoB,EAA6B,MAAM,sCAAsC,CAAC;AAQ5G,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,cAAc,KAAK,CAAC;AAwCjC,MAAM,MAAM,wBAAwB,GAAG,CACrC,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,KACE,qBAAqB,GAAG;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAAE,EAAE,CAAC;
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/configs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAoB,MAAM,wBAAwB,CAAC;AAOhG,OAAO,KAAK,EAEV,kBAAkB,EAElB,2BAA2B,EAC3B,cAAc,EACd,gBAAgB,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,oBAAoB,EAA6B,MAAM,sCAAsC,CAAC;AAQ5G,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,cAAc,KAAK,CAAC;AAwCjC,MAAM,MAAM,wBAAwB,GAAG,CACrC,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,KACE,qBAAqB,GAAG;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAAE,EAAE,CAAC;AAuPnH,eAAO,MAAM,OAAO;;;;;;;CAOnB,CAAC;AAEF,eAAO,MAAM,4BAA4B,cAC5B,wBAAwB,UAC3B,oBAAoB,EAAE,cAClB,cAAc,EAAE,WACnB,kBAAkB,KAC1B,2BAA2B,EA8B7B,CAAC"}
|
|
@@ -40,9 +40,9 @@ const outputColorReferences = (token) => {
|
|
|
40
40
|
}
|
|
41
41
|
return false;
|
|
42
42
|
};
|
|
43
|
-
const
|
|
44
|
-
const selector = `${
|
|
45
|
-
const layer = `ds.theme.color-
|
|
43
|
+
const colorSchemeVariables = ({ "color-scheme": colorScheme = "light", theme }, { outPath }) => {
|
|
44
|
+
const selector = `${colorScheme === "light" ? ":root, " : ""}[data-color-scheme="${colorScheme}"]`;
|
|
45
|
+
const layer = `ds.theme.color-scheme.${colorScheme}`;
|
|
46
46
|
return {
|
|
47
47
|
usesDtcg,
|
|
48
48
|
preprocessors: ["tokens-studio"],
|
|
@@ -50,7 +50,7 @@ const colorModeVariables = ({ mode = "light", theme }, { outPath }) => {
|
|
|
50
50
|
css: {
|
|
51
51
|
// custom
|
|
52
52
|
outPath,
|
|
53
|
-
|
|
53
|
+
colorScheme,
|
|
54
54
|
theme,
|
|
55
55
|
selector,
|
|
56
56
|
layer,
|
|
@@ -60,8 +60,8 @@ const colorModeVariables = ({ mode = "light", theme }, { outPath }) => {
|
|
|
60
60
|
transforms: dsTransformers,
|
|
61
61
|
files: [
|
|
62
62
|
{
|
|
63
|
-
destination: `color-
|
|
64
|
-
format: formats.
|
|
63
|
+
destination: `color-scheme/${colorScheme}.css`,
|
|
64
|
+
format: formats.colorScheme.name,
|
|
65
65
|
filter: (token) => !token.isSource && typeEquals("color", token)
|
|
66
66
|
}
|
|
67
67
|
],
|
|
@@ -73,7 +73,7 @@ const colorModeVariables = ({ mode = "light", theme }, { outPath }) => {
|
|
|
73
73
|
}
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
-
const colorCategoryVariables = (category) => ({
|
|
76
|
+
const colorCategoryVariables = (category) => ({ "color-scheme": colorScheme, theme, [`${category}-color`]: color }, { outPath }) => {
|
|
77
77
|
const layer = `ds.theme.color`;
|
|
78
78
|
const isDefault = color === buildOptions?.accentColor;
|
|
79
79
|
const selector = `${isDefault ? ":root, " : ""}[data-color="${color}"]`;
|
|
@@ -84,7 +84,7 @@ const colorCategoryVariables = (category) => ({ mode, theme, [`${category}-color
|
|
|
84
84
|
css: {
|
|
85
85
|
// custom
|
|
86
86
|
outPath,
|
|
87
|
-
|
|
87
|
+
colorScheme,
|
|
88
88
|
theme,
|
|
89
89
|
selector,
|
|
90
90
|
layer,
|
|
@@ -95,7 +95,7 @@ const colorCategoryVariables = (category) => ({ mode, theme, [`${category}-color
|
|
|
95
95
|
files: [
|
|
96
96
|
{
|
|
97
97
|
destination: `color/${color}.css`,
|
|
98
|
-
format: formats.
|
|
98
|
+
format: formats.colorCategory.name,
|
|
99
99
|
filter: (token) => isColorCategoryToken(token, category)
|
|
100
100
|
}
|
|
101
101
|
],
|
|
@@ -169,7 +169,7 @@ const semanticVariables = ({ theme }, { outPath }) => {
|
|
|
169
169
|
}
|
|
170
170
|
};
|
|
171
171
|
};
|
|
172
|
-
const typescriptTokens = ({
|
|
172
|
+
const typescriptTokens = ({ "color-scheme": colorScheme, theme }, { outPath }) => {
|
|
173
173
|
return {
|
|
174
174
|
usesDtcg,
|
|
175
175
|
preprocessors: ["tokens-studio"],
|
|
@@ -181,7 +181,7 @@ const typescriptTokens = ({ mode, theme }, { outPath }) => {
|
|
|
181
181
|
buildPath: `${outPath}/${theme}/`,
|
|
182
182
|
files: [
|
|
183
183
|
{
|
|
184
|
-
destination: `${
|
|
184
|
+
destination: `${colorScheme}.ts`,
|
|
185
185
|
format: jsTokens.name,
|
|
186
186
|
outputReferences: outputColorReferences,
|
|
187
187
|
filter: (token) => {
|
|
@@ -251,7 +251,7 @@ const typographyVariables = ({ theme, typography }, { outPath }) => {
|
|
|
251
251
|
};
|
|
252
252
|
};
|
|
253
253
|
const configs = {
|
|
254
|
-
|
|
254
|
+
colorSchemeVariables,
|
|
255
255
|
mainColorVariables: colorCategoryVariables("main"),
|
|
256
256
|
supportColorVariables: colorCategoryVariables("support"),
|
|
257
257
|
typographyVariables,
|
|
@@ -1 +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;
|
|
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;AA0DrD,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,YAAY;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B;CACF;AA2GD,eAAO,MAAM,OAAO;;;;;CAKc,CAAC"}
|
|
@@ -2,18 +2,18 @@ import * as R from "ramda";
|
|
|
2
2
|
import { createPropertyFormatter, fileHeader, usesReferences } from "style-dictionary/utils";
|
|
3
3
|
import { colorCategories } from "../types.js";
|
|
4
4
|
import { getValue, isColorCategoryToken, isGlobalColorToken, isSemanticToken } from "../utils/utils.js";
|
|
5
|
-
const prefersColorScheme = (
|
|
6
|
-
@media (prefers-color-scheme: ${
|
|
7
|
-
[data-
|
|
5
|
+
const prefersColorScheme = (colorScheme2, content) => `
|
|
6
|
+
@media (prefers-color-scheme: ${colorScheme2}) {
|
|
7
|
+
[data-color-scheme="auto"] ${content}
|
|
8
8
|
}
|
|
9
9
|
`;
|
|
10
|
-
const
|
|
11
|
-
name: "ds/css-
|
|
10
|
+
const colorScheme = {
|
|
11
|
+
name: "ds/css-colorscheme",
|
|
12
12
|
format: async ({ dictionary, file, options, platform }) => {
|
|
13
13
|
const { allTokens } = dictionary;
|
|
14
14
|
const { outputReferences, usesDtcg } = options;
|
|
15
|
-
const { selector,
|
|
16
|
-
const
|
|
15
|
+
const { selector, colorScheme: colorScheme2, layer } = platform;
|
|
16
|
+
const colorScheme_ = colorScheme2;
|
|
17
17
|
const header = await fileHeader({ file });
|
|
18
18
|
const format = createPropertyFormatter({
|
|
19
19
|
outputReferences,
|
|
@@ -21,8 +21,8 @@ const colormode = {
|
|
|
21
21
|
format: "css",
|
|
22
22
|
usesDtcg
|
|
23
23
|
});
|
|
24
|
-
const colorSchemeProperty =
|
|
25
|
-
color-scheme: ${
|
|
24
|
+
const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
|
|
25
|
+
color-scheme: ${colorScheme_};
|
|
26
26
|
` : "";
|
|
27
27
|
const filteredAllTokens = allTokens.filter(
|
|
28
28
|
R.allPass([
|
|
@@ -41,7 +41,7 @@ const colormode = {
|
|
|
41
41
|
${formattedTokens}
|
|
42
42
|
${colorSchemeProperty}}
|
|
43
43
|
`;
|
|
44
|
-
const autoSelectorContent = ["light", "dark"].includes(
|
|
44
|
+
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
45
45
|
const body = R.isNotNil(layer) ? `@layer ${layer} {
|
|
46
46
|
${selector} ${content} ${autoSelectorContent}
|
|
47
47
|
}
|
|
@@ -50,7 +50,7 @@ ${selector} ${content} ${autoSelectorContent}
|
|
|
50
50
|
return header + body;
|
|
51
51
|
}
|
|
52
52
|
};
|
|
53
|
-
const
|
|
53
|
+
const colorCategory = {
|
|
54
54
|
name: "ds/css-colorcategory",
|
|
55
55
|
format: async ({ dictionary, file, options, platform }) => {
|
|
56
56
|
const { outputReferences, usesDtcg, replaceCategoryWith = "" } = options;
|
|
@@ -147,8 +147,8 @@ ${content}
|
|
|
147
147
|
}
|
|
148
148
|
};
|
|
149
149
|
const formats = {
|
|
150
|
-
|
|
151
|
-
|
|
150
|
+
colorScheme,
|
|
151
|
+
colorCategory,
|
|
152
152
|
semantic,
|
|
153
153
|
typography
|
|
154
154
|
};
|
|
@@ -9,7 +9,7 @@ export type ColorCategories = keyof typeof colorCategories;
|
|
|
9
9
|
* A multi-dimensional theme is a concrete permutation of the possible theme dimensions
|
|
10
10
|
*/
|
|
11
11
|
export type ThemePermutation = {
|
|
12
|
-
|
|
12
|
+
'color-scheme': string;
|
|
13
13
|
'main-color': string;
|
|
14
14
|
'support-color': string;
|
|
15
15
|
semantic: string;
|
|
@@ -1 +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,
|
|
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,cAAc,EAAE,MAAM,CAAC;IACvB,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"}
|
|
@@ -3,11 +3,11 @@ import glob from "fast-glob";
|
|
|
3
3
|
import fs from "fs-extra";
|
|
4
4
|
import * as R from "ramda";
|
|
5
5
|
const sortOrder = [
|
|
6
|
-
"color-
|
|
6
|
+
"color-scheme/light",
|
|
7
7
|
"typography/secondary",
|
|
8
8
|
"semantic",
|
|
9
|
-
"color-
|
|
10
|
-
"color-
|
|
9
|
+
"color-scheme/dark",
|
|
10
|
+
"color-scheme/contrast",
|
|
11
11
|
"typography/primary",
|
|
12
12
|
"color/",
|
|
13
13
|
"builtin-colors"
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/tokens/build.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,KAAK,OAAO,GAAG;IACb,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,IAAI,YAAY,EAAE,OAAO,GAAG,SAAS,CAAC;AAwC7C,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/tokens/build.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,aAAa,WAAW,CAAC;AAEtC,KAAK,OAAO,GAAG;IACb,yBAAyB;IACzB,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;IACjB,4BAA4B;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,wEAAwE;IACxE,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC;AAEF,eAAO,IAAI,YAAY,EAAE,OAAO,GAAG,SAAS,CAAC;AAwC7C,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CAyEjE"}
|
package/dist/src/tokens/build.js
CHANGED
|
@@ -4,6 +4,7 @@ import chalk from "chalk";
|
|
|
4
4
|
import * as R from "ramda";
|
|
5
5
|
import StyleDictionary from "style-dictionary";
|
|
6
6
|
import { configs, getConfigsForThemeDimensions } from "./build/configs.js";
|
|
7
|
+
import { colorCategories } from "./build/types.js";
|
|
7
8
|
import { makeEntryFile } from "./build/utils/entryfile.js";
|
|
8
9
|
import { processThemeObject } from "./build/utils/getMultidimensionalThemes.js";
|
|
9
10
|
const DEFAULT_COLOR = "accent";
|
|
@@ -11,14 +12,14 @@ let buildOptions;
|
|
|
11
12
|
const sd = new StyleDictionary();
|
|
12
13
|
const buildConfigs = {
|
|
13
14
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
14
|
-
"color-
|
|
15
|
+
"color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
|
|
15
16
|
"main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
|
|
16
17
|
"support-color": { getConfig: configs.supportColorVariables, dimensions: ["support-color"] },
|
|
17
18
|
semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] },
|
|
18
19
|
storefront: {
|
|
19
20
|
name: "Storefront preview tokens",
|
|
20
21
|
getConfig: configs.typescriptTokens,
|
|
21
|
-
dimensions: ["
|
|
22
|
+
dimensions: ["color-scheme"],
|
|
22
23
|
options: { outPath: path.resolve("../../apps/storefront/tokens") },
|
|
23
24
|
enabled: () => buildOptions?.preview ?? false
|
|
24
25
|
},
|
|
@@ -72,7 +73,7 @@ async function buildTokens(options) {
|
|
|
72
73
|
console.log(`
|
|
73
74
|
\u{1F371} Building ${chalk.green(buildConfig.name ?? key)}`);
|
|
74
75
|
if (buildConfig.build) {
|
|
75
|
-
|
|
76
|
+
await buildConfig.build(sdConfigs, { outPath, tokensDir, ...buildConfig.options });
|
|
76
77
|
}
|
|
77
78
|
await Promise.all(
|
|
78
79
|
sdConfigs.map(async ({ config, permutation }) => {
|
|
@@ -90,6 +91,26 @@ async function buildTokens(options) {
|
|
|
90
91
|
}
|
|
91
92
|
throw err;
|
|
92
93
|
}
|
|
94
|
+
await writeColorTypeDeclaration($themes, outPath);
|
|
95
|
+
}
|
|
96
|
+
async function writeColorTypeDeclaration($themes, outPath) {
|
|
97
|
+
const colorsFileName = "colors.d.ts";
|
|
98
|
+
console.log(`
|
|
99
|
+
\u{1F371} Building ${chalk.green("type declarations")}`);
|
|
100
|
+
console.log(colorsFileName);
|
|
101
|
+
const mainAndSupportColors = $themes.filter(
|
|
102
|
+
(x) => x.group && [colorCategories.main, colorCategories.support].map((c) => `${c}-color`).includes(x.group)
|
|
103
|
+
).map((x) => x.name);
|
|
104
|
+
const typeDeclaration = `
|
|
105
|
+
import type { MainAndSupportColors as BaseCustomColors } from '@digdir/designsystemet-react/colors';
|
|
106
|
+
|
|
107
|
+
declare module '@digdir/designsystemet-react/colors' {
|
|
108
|
+
export interface MainAndSupportColors extends BaseCustomColors {
|
|
109
|
+
${mainAndSupportColors.map((color) => ` ${color}: never;`).join("\n")}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
`.trimStart();
|
|
113
|
+
await fs.writeFile(path.resolve(outPath, colorsFileName), typeDeclaration, "utf-8");
|
|
93
114
|
}
|
|
94
115
|
export {
|
|
95
116
|
DEFAULT_COLOR,
|
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
"primitives/size/compact",
|
|
6
6
|
"primitives/modes/typography/primary/<theme>",
|
|
7
7
|
"primitives/modes/typography/secondary/<theme>",
|
|
8
|
-
"primitives/modes/
|
|
9
|
-
"primitives/modes/
|
|
10
|
-
"primitives/modes/
|
|
11
|
-
"primitives/modes/
|
|
8
|
+
"primitives/modes/color-scheme/dark/global",
|
|
9
|
+
"primitives/modes/color-scheme/dark/<theme>",
|
|
10
|
+
"primitives/modes/color-scheme/light/global",
|
|
11
|
+
"primitives/modes/color-scheme/light/<theme>",
|
|
12
12
|
"themes/<theme>",
|
|
13
13
|
"semantic/color",
|
|
14
14
|
"semantic/modes/main-color/accent",
|
|
@@ -28,11 +28,11 @@
|
|
|
28
28
|
"name": "Light",
|
|
29
29
|
"$figmaStyleReferences": {},
|
|
30
30
|
"selectedTokenSets": {
|
|
31
|
-
"primitives/modes/
|
|
32
|
-
"primitives/modes/
|
|
33
|
-
"primitives/modes/
|
|
34
|
-
"primitives/modes/
|
|
35
|
-
"primitives/modes/
|
|
31
|
+
"primitives/modes/color-scheme/light/global": "enabled",
|
|
32
|
+
"primitives/modes/color-scheme/light/theme": "enabled",
|
|
33
|
+
"primitives/modes/color-scheme/light/theme2": "enabled",
|
|
34
|
+
"primitives/modes/color-scheme/light/theme3": "enabled",
|
|
35
|
+
"primitives/modes/color-scheme/light/theme4": "enabled"
|
|
36
36
|
},
|
|
37
37
|
"$figmaCollectionId": "VariableCollectionId:34811:5472",
|
|
38
38
|
"$figmaModeId": "34811:0",
|
|
@@ -428,18 +428,18 @@
|
|
|
428
428
|
"theme4.brand3.contrast-1": "61ffa3f921c9c346bc22448c458ba59a585be1cb",
|
|
429
429
|
"theme4.brand3.contrast-2": "dcdfe1ec7245c3ee88fe149188d299456324b7a6"
|
|
430
430
|
},
|
|
431
|
-
"group": "
|
|
431
|
+
"group": "Color scheme"
|
|
432
432
|
},
|
|
433
433
|
{
|
|
434
434
|
"id": "9ebd8aed52afbffc17e2666e8b4653a53498b257",
|
|
435
435
|
"name": "Dark",
|
|
436
436
|
"$figmaStyleReferences": {},
|
|
437
437
|
"selectedTokenSets": {
|
|
438
|
-
"primitives/modes/
|
|
439
|
-
"primitives/modes/
|
|
440
|
-
"primitives/modes/
|
|
441
|
-
"primitives/modes/
|
|
442
|
-
"primitives/modes/
|
|
438
|
+
"primitives/modes/color-scheme/dark/global": "enabled",
|
|
439
|
+
"primitives/modes/color-scheme/dark/theme": "enabled",
|
|
440
|
+
"primitives/modes/color-scheme/dark/theme2": "enabled",
|
|
441
|
+
"primitives/modes/color-scheme/dark/theme3": "enabled",
|
|
442
|
+
"primitives/modes/color-scheme/dark/theme4": "enabled"
|
|
443
443
|
},
|
|
444
444
|
"$figmaCollectionId": "VariableCollectionId:34811:5472",
|
|
445
445
|
"$figmaModeId": "34811:1",
|
|
@@ -835,7 +835,7 @@
|
|
|
835
835
|
"theme4.brand3.contrast-1": "61ffa3f921c9c346bc22448c458ba59a585be1cb",
|
|
836
836
|
"theme4.brand3.contrast-2": "dcdfe1ec7245c3ee88fe149188d299456324b7a6"
|
|
837
837
|
},
|
|
838
|
-
"group": "
|
|
838
|
+
"group": "Color scheme"
|
|
839
839
|
},
|
|
840
840
|
{
|
|
841
841
|
"id": "368d753fcac4455f289500eaa42e70dc0a03522f",
|
|
@@ -6,8 +6,8 @@ function generateMetadataJson(modes, themes, colors) {
|
|
|
6
6
|
...themes.map((theme) => `primitives/modes/typography/primary/${theme}`),
|
|
7
7
|
...themes.map((theme) => `primitives/modes/typography/secondary/${theme}`),
|
|
8
8
|
...modes.flatMap((mode) => [
|
|
9
|
-
`primitives/modes/
|
|
10
|
-
...themes.map((theme) => `primitives/modes/
|
|
9
|
+
`primitives/modes/color-scheme/${mode}/global`,
|
|
10
|
+
...themes.map((theme) => `primitives/modes/color-scheme/${mode}/${theme}`)
|
|
11
11
|
]),
|
|
12
12
|
...themes.map((theme) => `themes/${theme}`),
|
|
13
13
|
"semantic/color",
|
|
@@ -26,7 +26,7 @@ function generateSizeGroup() {
|
|
|
26
26
|
}
|
|
27
27
|
];
|
|
28
28
|
}
|
|
29
|
-
const
|
|
29
|
+
const colorSchemeDefaults = {
|
|
30
30
|
light: {
|
|
31
31
|
name: "Light",
|
|
32
32
|
selectedTokenSets: {},
|
|
@@ -52,10 +52,10 @@ const modeDefaults = {
|
|
|
52
52
|
function generateModesGroup(modes, themes) {
|
|
53
53
|
return modes.map(
|
|
54
54
|
(mode) => ({
|
|
55
|
-
...
|
|
55
|
+
...colorSchemeDefaults[mode],
|
|
56
56
|
selectedTokenSets: Object.fromEntries([
|
|
57
|
-
[`primitives/modes/
|
|
58
|
-
...themes.map((theme) => [`primitives/modes/
|
|
57
|
+
[`primitives/modes/color-scheme/${mode}/global`, TokenSetStatus.ENABLED],
|
|
58
|
+
...themes.map((theme) => [`primitives/modes/color-scheme/${mode}/${theme}`, TokenSetStatus.ENABLED])
|
|
59
59
|
]),
|
|
60
60
|
group: "Mode"
|
|
61
61
|
})
|
package/dist/src/tokens/write.js
CHANGED
|
@@ -13,8 +13,8 @@ const DIRNAME = import.meta.dirname || __dirname;
|
|
|
13
13
|
const DEFAULT_FILES_PATH = path.join(DIRNAME, "./design-tokens/default");
|
|
14
14
|
const TEMPLATE_FILES_PATH = path.join(DIRNAME, "./design-tokens/template/");
|
|
15
15
|
const stringify = (data) => JSON.stringify(data, null, 2);
|
|
16
|
-
const
|
|
17
|
-
const path2 = `${outPath}/primitives/modes/
|
|
16
|
+
const generateColorSchemeFile = (folder, name, tokens, outPath) => {
|
|
17
|
+
const path2 = `${outPath}/primitives/modes/color-scheme/${folder}`;
|
|
18
18
|
return {
|
|
19
19
|
data: stringify(tokens),
|
|
20
20
|
path: path2,
|
|
@@ -142,12 +142,12 @@ const writeTokens = async (options) => {
|
|
|
142
142
|
)
|
|
143
143
|
);
|
|
144
144
|
const files = [
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
145
|
+
generateColorSchemeFile("light", themeName, tokens.colors.light[themeName], targetDir),
|
|
146
|
+
generateColorSchemeFile("light", "global", tokens.colors.light.global, targetDir),
|
|
147
|
+
generateColorSchemeFile("dark", themeName, tokens.colors.dark[themeName], targetDir),
|
|
148
|
+
generateColorSchemeFile("dark", "global", tokens.colors.dark.global, targetDir),
|
|
149
|
+
generateColorSchemeFile("contrast", themeName, tokens.colors.contrast[themeName], targetDir),
|
|
150
|
+
generateColorSchemeFile("contrast", "global", tokens.colors.contrast.global, targetDir),
|
|
151
151
|
generateTypographyFile("primary", themeName, tokens.typography.primary, targetDir),
|
|
152
152
|
generateTypographyFile("secondary", themeName, tokens.typography.primary, targetDir)
|
|
153
153
|
];
|