@digdir/designsystemet 1.0.3 → 1.0.5
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 +4287 -45
- package/dist/bin/options.js +5 -4
- package/dist/src/colors/colorMetadata.js +5 -4
- package/dist/src/colors/index.js +470 -4
- package/dist/src/colors/theme.js +286 -20
- package/dist/src/colors/utils.js +16 -15
- package/dist/{bin → src}/config.d.ts +46 -1
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +377 -0
- package/dist/src/index.js +3682 -2
- package/dist/src/migrations/beta-to-v1.js +85 -4
- package/dist/src/migrations/codemods/css/plugins.js +5 -4
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
- package/dist/src/migrations/codemods/css/run.js +18 -4
- package/dist/src/migrations/color-rename-next49.js +77 -6
- package/dist/src/migrations/index.d.ts +0 -1
- package/dist/src/migrations/index.d.ts.map +1 -1
- package/dist/src/migrations/index.js +461 -6
- package/dist/src/scripts/createJsonSchema.js +1608 -4
- package/dist/src/scripts/update-design-tokens.d.ts +2 -0
- package/dist/src/scripts/update-design-tokens.d.ts.map +1 -0
- package/dist/src/scripts/update-design-tokens.js +37 -0
- package/dist/src/{tokens/template.d.ts → scripts/update-template.d.ts} +1 -1
- package/dist/src/scripts/update-template.d.ts.map +1 -0
- package/dist/src/scripts/update-template.js +1200 -0
- package/dist/src/tokens/build.d.ts +2 -19
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +1268 -70
- package/dist/src/tokens/create/defaults.d.ts +7 -0
- package/dist/src/tokens/create/defaults.d.ts.map +1 -0
- package/dist/src/tokens/create/defaults.js +994 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.js +101 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
- package/dist/src/tokens/{write/generate$metadata.js → create/generators/$metadata.js} +3 -2
- package/dist/src/tokens/create/generators/$themes.d.ts +12 -0
- package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$themes.js +333 -0
- package/dist/src/tokens/create/generators/color.d.ts +5 -0
- package/dist/src/tokens/create/generators/color.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/color.js +374 -0
- package/dist/src/tokens/create/generators/semantic.d.ts +296 -0
- package/dist/src/tokens/create/generators/semantic.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic.js +483 -0
- package/dist/src/tokens/create/generators/theme.d.ts +3 -0
- package/dist/src/tokens/create/generators/theme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/theme.js +168 -0
- package/dist/src/tokens/create/generators/typography.d.ts +3 -0
- package/dist/src/tokens/create/generators/typography.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/typography.js +33 -0
- package/dist/src/tokens/{write.d.ts → create/write.d.ts} +2 -2
- package/dist/src/tokens/create/write.d.ts.map +1 -0
- package/dist/src/tokens/create/write.js +547 -0
- package/dist/src/tokens/create.d.ts +4 -2
- package/dist/src/tokens/create.d.ts.map +1 -1
- package/dist/src/tokens/create.js +2049 -59
- package/dist/src/tokens/format.d.ts +15 -0
- package/dist/src/tokens/format.d.ts.map +1 -0
- package/dist/src/tokens/format.js +3529 -0
- package/dist/src/tokens/index.d.ts +1 -0
- package/dist/src/tokens/index.d.ts.map +1 -1
- package/dist/src/tokens/index.js +3542 -2
- package/dist/src/tokens/process/configs/color.d.ts +12 -0
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/color.js +823 -0
- package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/semantic.js +367 -0
- package/dist/src/tokens/process/configs/shared.d.ts +10 -0
- package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/shared.js +99 -0
- package/dist/src/tokens/process/configs/storefront.d.ts +3 -0
- package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/storefront.js +220 -0
- package/dist/src/tokens/process/configs/typography.d.ts +3 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/typography.js +369 -0
- package/dist/src/tokens/{build → process}/configs.d.ts +3 -11
- package/dist/src/tokens/process/configs.d.ts.map +1 -0
- package/dist/src/tokens/process/configs.js +976 -0
- package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/color.js +128 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts +17 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.js +109 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.js +32 -0
- package/dist/src/tokens/process/formats/css.d.ts +8 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/{build → process}/formats/css.js +94 -57
- package/dist/src/tokens/process/formats/js-tokens.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/js-tokens.js +109 -0
- package/dist/src/tokens/process/platform.d.ts +87 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -0
- package/dist/src/tokens/process/platform.js +1090 -0
- package/dist/src/tokens/process/theme.d.ts +27 -0
- package/dist/src/tokens/process/theme.d.ts.map +1 -0
- package/dist/src/tokens/process/theme.js +172 -0
- package/dist/src/tokens/process/transformers.d.ts.map +1 -0
- package/dist/src/tokens/{build → process}/transformers.js +29 -6
- package/dist/src/tokens/{build → process}/utils/getMultidimensionalThemes.d.ts +3 -3
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +922 -0
- package/dist/src/tokens/template/design-tokens/primitives/globals.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/large.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/medium.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/size/small.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/large.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/medium.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/small.js +5 -0
- package/dist/src/tokens/template/design-tokens/primitives/modes/typography/typography.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/color.base.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/color.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/modes/color.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/semantic/style.js +5 -0
- package/dist/src/tokens/template/design-tokens/themes/theme.base.template.js +5 -0
- package/dist/src/tokens/template/design-tokens/themes/theme.template.js +5 -0
- package/dist/src/tokens/types.d.ts +58 -38
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/tokens/types.js +8 -0
- package/dist/src/tokens/utils.d.ts +30 -5
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/dist/src/tokens/utils.js +36 -50
- package/dist/src/utils.d.ts +18 -0
- package/dist/src/utils.d.ts.map +1 -0
- package/dist/src/utils.js +63 -0
- package/dist/typography.template-4N5YLH7F.json +22 -0
- package/package.json +22 -20
- package/dist/bin/config.d.ts.map +0 -1
- package/dist/bin/config.js +0 -71
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
- package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
- package/dist/src/migrations/codemods/jsx/classname-prefix.js +0 -64
- package/dist/src/migrations/codemods/jsx/run.d.ts +0 -7
- package/dist/src/migrations/codemods/jsx/run.d.ts.map +0 -1
- package/dist/src/migrations/codemods/jsx/run.js +0 -22
- package/dist/src/migrations/react-beta-to-v1.d.ts +0 -3
- package/dist/src/migrations/react-beta-to-v1.d.ts.map +0 -1
- package/dist/src/migrations/react-beta-to-v1.js +0 -5
- package/dist/src/scripts/copy-internal-tokens.d.ts +0 -2
- package/dist/src/scripts/copy-internal-tokens.d.ts.map +0 -1
- package/dist/src/scripts/copy-internal-tokens.js +0 -28
- package/dist/src/tokens/build/configs.d.ts.map +0 -1
- package/dist/src/tokens/build/configs.js +0 -280
- package/dist/src/tokens/build/formats/css.d.ts +0 -53
- package/dist/src/tokens/build/formats/css.d.ts.map +0 -1
- package/dist/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
- package/dist/src/tokens/build/formats/js-tokens.js +0 -48
- package/dist/src/tokens/build/transformers.d.ts.map +0 -1
- package/dist/src/tokens/build/types.d.ts +0 -48
- package/dist/src/tokens/build/types.d.ts.map +0 -1
- package/dist/src/tokens/build/types.js +0 -7
- package/dist/src/tokens/build/utils/entryfile.d.ts +0 -12
- package/dist/src/tokens/build/utils/entryfile.d.ts.map +0 -1
- package/dist/src/tokens/build/utils/entryfile.js +0 -67
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +0 -1
- package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +0 -112
- package/dist/src/tokens/design-tokens/template/$metadata.json +0 -25
- package/dist/src/tokens/design-tokens/template/$themes.json +0 -1498
- package/dist/src/tokens/template.d.ts.map +0 -1
- package/dist/src/tokens/template.js +0 -99
- package/dist/src/tokens/write/generate$metadata.d.ts +0 -9
- package/dist/src/tokens/write/generate$metadata.d.ts.map +0 -1
- package/dist/src/tokens/write/generate$themes.d.ts +0 -12
- package/dist/src/tokens/write/generate$themes.d.ts.map +0 -1
- package/dist/src/tokens/write/generate$themes.js +0 -161
- package/dist/src/tokens/write.d.ts.map +0 -1
- package/dist/src/tokens/write.js +0 -177
- /package/dist/{src/tokens/design-tokens/template/semantic/color-base-file.json → color.base.template-M7BHS4OV.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json → color.template-LMPUQ72A.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/semantic/semantic-color-template.json → color.template-XQNSHLTU.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/global.json → global-XVXVBKM6.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/globals.json → globals-76VAFMDF.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/large.json → large-CIIHO7AY.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/large.json → large-UUOZ6DYI.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/medium.json → medium-OQ7S7P4P.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json → medium-VSB2S4X3.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/small.json → small-AEXJ6U7Z.json} +0 -0
- /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/small.json → small-ZY4KOJWX.json} +0 -0
- /package/dist/src/tokens/{build → process}/formats/js-tokens.d.ts +0 -0
- /package/dist/src/tokens/{build → process}/transformers.d.ts +0 -0
- /package/dist/{src/tokens/design-tokens/default/semantic/style.json → style-FP5XVCUD.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/themes/theme-base-file.json → theme.base.template-Y4RMFBQY.json} +0 -0
- /package/dist/{src/tokens/design-tokens/template/themes/theme-color-template.json → theme.template-CTQRNOMO.json} +0 -0
package/dist/src/tokens/build.js
CHANGED
|
@@ -1,18 +1,1166 @@
|
|
|
1
|
-
|
|
1
|
+
// src/tokens/build.ts
|
|
2
2
|
import path from "node:path";
|
|
3
|
+
import chalk5 from "chalk";
|
|
4
|
+
import * as R14 from "ramda";
|
|
5
|
+
|
|
6
|
+
// src/utils.ts
|
|
7
|
+
import fs from "node:fs/promises";
|
|
3
8
|
import chalk from "chalk";
|
|
9
|
+
var mkdir = async (dir, dry) => {
|
|
10
|
+
if (dry) {
|
|
11
|
+
console.log(`${chalk.blue("mkdir")} ${dir}`);
|
|
12
|
+
return Promise.resolve();
|
|
13
|
+
}
|
|
14
|
+
const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
|
|
15
|
+
if (exists) {
|
|
16
|
+
return Promise.resolve();
|
|
17
|
+
}
|
|
18
|
+
return fs.mkdir(dir, { recursive: true });
|
|
19
|
+
};
|
|
20
|
+
var writeFile = async (path2, data, dry) => {
|
|
21
|
+
if (dry) {
|
|
22
|
+
console.log(`${chalk.blue("writeFile")} ${path2}`);
|
|
23
|
+
return Promise.resolve();
|
|
24
|
+
}
|
|
25
|
+
return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
|
|
26
|
+
console.error(chalk.red(`Error writing file: ${path2}`));
|
|
27
|
+
console.error(chalk.red(error));
|
|
28
|
+
throw error;
|
|
29
|
+
});
|
|
30
|
+
};
|
|
31
|
+
var cleanDir = async (dir, dry) => {
|
|
32
|
+
if (dry) {
|
|
33
|
+
console.log(`${chalk.blue("cleanDir")} ${dir}`);
|
|
34
|
+
return Promise.resolve();
|
|
35
|
+
}
|
|
36
|
+
console.log(`
|
|
37
|
+
\u{1F525} Cleaning dir ${chalk.red(`${dir.trim()}`)} `);
|
|
38
|
+
return fs.rm(dir, { recursive: true, force: true });
|
|
39
|
+
};
|
|
40
|
+
var readFile = async (path2, dry) => {
|
|
41
|
+
if (dry) {
|
|
42
|
+
console.log(`${chalk.blue("readFile")} ${path2}`);
|
|
43
|
+
return Promise.resolve("");
|
|
44
|
+
}
|
|
45
|
+
return fs.readFile(path2, "utf-8");
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
// src/tokens/process/theme.ts
|
|
4
49
|
import * as R from "ramda";
|
|
50
|
+
import chalk2 from "chalk";
|
|
51
|
+
|
|
52
|
+
// package.json
|
|
53
|
+
var package_default = {
|
|
54
|
+
name: "@digdir/designsystemet",
|
|
55
|
+
version: "1.0.5",
|
|
56
|
+
description: "CLI for Designsystemet",
|
|
57
|
+
author: "Designsystemet team",
|
|
58
|
+
engines: {
|
|
59
|
+
node: ">=22.14.0"
|
|
60
|
+
},
|
|
61
|
+
repository: {
|
|
62
|
+
type: "git",
|
|
63
|
+
url: "git+https://github.com/digdir/designsystemet.git"
|
|
64
|
+
},
|
|
65
|
+
homepage: "https://github.com/digdir/designsystemet/tree/main/scripts/cli",
|
|
66
|
+
license: "MIT",
|
|
67
|
+
type: "module",
|
|
68
|
+
main: "./dist/src/index.js",
|
|
69
|
+
files: [
|
|
70
|
+
"./dist/**"
|
|
71
|
+
],
|
|
72
|
+
bin: "dist/bin/designsystemet.js",
|
|
73
|
+
exports: {
|
|
74
|
+
".": {
|
|
75
|
+
import: "./dist/src/index.js"
|
|
76
|
+
},
|
|
77
|
+
"./color": {
|
|
78
|
+
import: "./dist/src/colors/index.js"
|
|
79
|
+
},
|
|
80
|
+
"./tokens": {
|
|
81
|
+
import: "./dist/src/tokens/index.js"
|
|
82
|
+
}
|
|
83
|
+
},
|
|
84
|
+
publishConfig: {
|
|
85
|
+
access: "public"
|
|
86
|
+
},
|
|
87
|
+
scripts: {
|
|
88
|
+
designsystemet: "tsx ./bin/designsystemet.ts",
|
|
89
|
+
"build:tokens": "yarn designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
|
|
90
|
+
"build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
|
|
91
|
+
build: "tsup && yarn build:types && yarn build:json-schema",
|
|
92
|
+
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
93
|
+
"build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
|
|
94
|
+
types: "tsc --noEmit",
|
|
95
|
+
"test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 -n #003333 -b 99 -o ./test-tokens/options --theme options --clean",
|
|
96
|
+
"test:tokens-create-config": "yarn designsystemet tokens create --config ./test/test-tokens.config.json",
|
|
97
|
+
"test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens/options -o ./test-tokens/options-build --clean",
|
|
98
|
+
"test:tokens-build-config": "yarn designsystemet tokens build -t ./test-tokens/config -o ./test-tokens/config-build --clean",
|
|
99
|
+
"test:tokens-create-and-build-options": "yarn test:tokens-create-options && yarn test:tokens-build",
|
|
100
|
+
"test:tokens-create-and-build-config": "yarn test:tokens-create-config && yarn test:tokens-build-config",
|
|
101
|
+
test: "yarn test:tokens-create-and-build-options && yarn test:tokens-create-and-build-config",
|
|
102
|
+
"internal:tokens-create": "yarn designsystemet tokens create --config ./internal.config.json",
|
|
103
|
+
"update:template": "tsx ./src/scripts/update-template.ts",
|
|
104
|
+
"update:design-tokens": "yarn internal:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
|
|
105
|
+
verify: "yarn test && yarn update:template && yarn update:design-tokens"
|
|
106
|
+
},
|
|
107
|
+
dependencies: {
|
|
108
|
+
"@commander-js/extra-typings": "^13.1.0",
|
|
109
|
+
"@tokens-studio/sd-transforms": "1.2.12",
|
|
110
|
+
"apca-w3": "^0.1.9",
|
|
111
|
+
chalk: "^5.4.1",
|
|
112
|
+
"change-case": "^5.4.4",
|
|
113
|
+
"chroma-js": "^3.1.2",
|
|
114
|
+
commander: "^13.1.0",
|
|
115
|
+
"fast-glob": "^3.3.3",
|
|
116
|
+
hsluv: "^1.0.1",
|
|
117
|
+
"object-hash": "^3.0.0",
|
|
118
|
+
postcss: "^8.5.3",
|
|
119
|
+
ramda: "^0.30.1",
|
|
120
|
+
"style-dictionary": "^4.3.3",
|
|
121
|
+
zod: "^3.24.2",
|
|
122
|
+
"zod-validation-error": "^3.4.0"
|
|
123
|
+
},
|
|
124
|
+
devDependencies: {
|
|
125
|
+
"@types/apca-w3": "^0.1.3",
|
|
126
|
+
"@types/chroma-js": "^3.1.1",
|
|
127
|
+
"@types/fs-extra": "^11.0.4",
|
|
128
|
+
"@types/glob": "^8.1.0",
|
|
129
|
+
"@types/jscodeshift": "^0.12.0",
|
|
130
|
+
"@types/node": "^22.14.0",
|
|
131
|
+
"@types/object-hash": "^3.0.6",
|
|
132
|
+
"@types/ramda": "^0.30.2",
|
|
133
|
+
"fs-extra": "^11.3.0",
|
|
134
|
+
"ts-toolbelt": "^9.6.0",
|
|
135
|
+
tslib: "^2.8.1",
|
|
136
|
+
tsup: "^8.4.0",
|
|
137
|
+
tsx: "^4.19.3",
|
|
138
|
+
typescript: "^5.8.2",
|
|
139
|
+
"zod-to-json-schema": "^3.24.5"
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
// src/tokens/process/theme.ts
|
|
144
|
+
var defaultFileHeader = `build: v${package_default.version}`;
|
|
145
|
+
var createThemeCSSFiles = ({
|
|
146
|
+
processedBuilds,
|
|
147
|
+
fileHeader: fileHeader2 = defaultFileHeader
|
|
148
|
+
}) => {
|
|
149
|
+
const groupedByTheme = {};
|
|
150
|
+
for (const [_, buildResults] of Object.entries(R.dissoc("types", processedBuilds))) {
|
|
151
|
+
for (const buildResult of buildResults) {
|
|
152
|
+
const themeName = buildResult.permutation.theme;
|
|
153
|
+
const newOutputs = buildResult.formatted;
|
|
154
|
+
if (R.isNotEmpty(newOutputs)) {
|
|
155
|
+
const currentOutputs = groupedByTheme[themeName] ?? [];
|
|
156
|
+
groupedByTheme[themeName] = R.concat(currentOutputs, newOutputs);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const sortOrder = [
|
|
161
|
+
"color-scheme/light",
|
|
162
|
+
"typography/secondary",
|
|
163
|
+
"semantic",
|
|
164
|
+
"color-scheme/dark",
|
|
165
|
+
"color-scheme/contrast",
|
|
166
|
+
"typography/primary",
|
|
167
|
+
"color/"
|
|
168
|
+
];
|
|
169
|
+
const sortByDefinedOrder = R.sortBy((file) => {
|
|
170
|
+
const filePath = file.destination || "";
|
|
171
|
+
const sortIndex = sortOrder.findIndex((sortElement) => {
|
|
172
|
+
if (sortElement.endsWith("/")) {
|
|
173
|
+
return filePath.includes(sortElement);
|
|
174
|
+
}
|
|
175
|
+
return filePath.includes(`${sortElement}.css`);
|
|
176
|
+
});
|
|
177
|
+
if (sortIndex === -1) {
|
|
178
|
+
console.error(
|
|
179
|
+
chalk2.yellow("WARNING: CSS section does not have a defined sort order:", filePath.replace(".css", ""))
|
|
180
|
+
);
|
|
181
|
+
console.log(
|
|
182
|
+
chalk2.dim(
|
|
183
|
+
`
|
|
184
|
+
The section will currently be added to the end of the entry file, but the exact
|
|
185
|
+
order may change due to nondeterminism.`.trim()
|
|
186
|
+
)
|
|
187
|
+
);
|
|
188
|
+
return Infinity;
|
|
189
|
+
}
|
|
190
|
+
return sortIndex;
|
|
191
|
+
});
|
|
192
|
+
const header = `@charset "UTF-8";
|
|
193
|
+
|
|
194
|
+
@layer ds.theme, ds.base, ds.utilities, ds.components;
|
|
195
|
+
|
|
196
|
+
/*
|
|
197
|
+
${fileHeader2}
|
|
198
|
+
*/
|
|
199
|
+
|
|
200
|
+
`;
|
|
201
|
+
const sortAlphabetically = R.sort(R.ascend((x) => x.destination || ""));
|
|
202
|
+
const pickOutputs = R.map(R.view(R.lensProp("output")));
|
|
203
|
+
const themeCSSFile = R.pipe(
|
|
204
|
+
sortAlphabetically,
|
|
205
|
+
sortByDefinedOrder,
|
|
206
|
+
pickOutputs,
|
|
207
|
+
R.join("\n"),
|
|
208
|
+
(content) => header + content
|
|
209
|
+
);
|
|
210
|
+
const themeCSSFiles = Object.entries(groupedByTheme).map(([theme, files]) => ({
|
|
211
|
+
destination: `${theme}.css`,
|
|
212
|
+
output: themeCSSFile(files)
|
|
213
|
+
}));
|
|
214
|
+
return themeCSSFiles;
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
// src/tokens/process/platform.ts
|
|
218
|
+
import chalk4 from "chalk";
|
|
219
|
+
import * as R13 from "ramda";
|
|
220
|
+
import StyleDictionary2 from "style-dictionary";
|
|
221
|
+
|
|
222
|
+
// src/tokens/types.ts
|
|
223
|
+
var colorCategories = {
|
|
224
|
+
main: "main",
|
|
225
|
+
support: "support"
|
|
226
|
+
};
|
|
227
|
+
|
|
228
|
+
// src/tokens/process/configs.ts
|
|
229
|
+
import { register } from "@tokens-studio/sd-transforms";
|
|
230
|
+
import * as R12 from "ramda";
|
|
5
231
|
import StyleDictionary from "style-dictionary";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
232
|
+
|
|
233
|
+
// src/tokens/utils.ts
|
|
234
|
+
import * as R2 from "ramda";
|
|
235
|
+
var mapToLowerCase = R2.map(R2.toLower);
|
|
236
|
+
var hasAnyTruth = R2.any(R2.equals(true));
|
|
237
|
+
var getType = (token) => (token.$type ?? token.type) || "";
|
|
238
|
+
var getValue = (token) => token.$value ?? token.value;
|
|
239
|
+
var typeEquals = R2.curry((types, token) => {
|
|
240
|
+
if (R2.isNil(token)) {
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
return R2.includes(R2.toLower(getType(token)), R2.map(R2.toLower, Array.isArray(types) ? types : [types]));
|
|
244
|
+
});
|
|
245
|
+
var pathStartsWithOneOf = R2.curry((paths, token) => {
|
|
246
|
+
if (R2.isNil(token)) {
|
|
247
|
+
return false;
|
|
248
|
+
}
|
|
249
|
+
const tokenPath = mapToLowerCase(token.path);
|
|
250
|
+
const matchPathsStartingWith = R2.map((path2) => R2.startsWith([path2], tokenPath), mapToLowerCase(paths));
|
|
251
|
+
return hasAnyTruth(matchPathsStartingWith);
|
|
252
|
+
});
|
|
253
|
+
function isSemanticToken(token) {
|
|
254
|
+
return token.filePath.includes("semantic/");
|
|
255
|
+
}
|
|
256
|
+
function isSemanticColorToken(token, color) {
|
|
257
|
+
return token.filePath.includes("semantic/") && R2.startsWith(["color", color], token.path);
|
|
258
|
+
}
|
|
259
|
+
function isGlobalColorToken(token) {
|
|
260
|
+
return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
|
|
261
|
+
}
|
|
262
|
+
function isColorCategoryToken(token, category) {
|
|
263
|
+
if (!category) {
|
|
264
|
+
return ["main", "support"].some((c) => isColorCategoryToken(token, c));
|
|
265
|
+
}
|
|
266
|
+
return R2.startsWith(["color", category], token.path);
|
|
267
|
+
}
|
|
268
|
+
var isDigit = (s) => /^\d+$/.test(s);
|
|
269
|
+
function traverseObj(obj, fn) {
|
|
270
|
+
for (const key in obj) {
|
|
271
|
+
const prop = obj[key];
|
|
272
|
+
if (prop != null) {
|
|
273
|
+
fn.apply(null, [obj, key, prop]);
|
|
274
|
+
if (typeof prop === "object") {
|
|
275
|
+
traverseObj(prop, fn);
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
return obj;
|
|
280
|
+
}
|
|
281
|
+
function inlineTokens(shouldInline, tokens) {
|
|
282
|
+
const [inlineableTokens, otherTokens] = R2.partition(shouldInline, tokens);
|
|
283
|
+
return otherTokens.map((token) => {
|
|
284
|
+
let transformed = getValue(token.original);
|
|
285
|
+
for (const ref of inlineableTokens) {
|
|
286
|
+
const refName = ref.path.join(".");
|
|
287
|
+
if (typeof transformed === "string") {
|
|
288
|
+
transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
const tokenWithInlinedRefs = R2.set(R2.lensPath(["original", "$value"]), transformed, token);
|
|
292
|
+
return tokenWithInlinedRefs;
|
|
293
|
+
});
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
// src/tokens/process/configs/color.ts
|
|
297
|
+
import * as R7 from "ramda";
|
|
298
|
+
|
|
299
|
+
// src/tokens/process/formats/css/color.ts
|
|
300
|
+
import * as R3 from "ramda";
|
|
301
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
302
|
+
var prefersColorScheme = (colorScheme2, content) => `
|
|
303
|
+
@media (prefers-color-scheme: ${colorScheme2}) {
|
|
304
|
+
[data-color-scheme="auto"] ${content}
|
|
305
|
+
}
|
|
306
|
+
`;
|
|
307
|
+
var colorScheme = {
|
|
308
|
+
name: "ds/css-colorscheme",
|
|
309
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
310
|
+
const { allTokens } = dictionary;
|
|
311
|
+
const { outputReferences, usesDtcg } = options;
|
|
312
|
+
const { selector, colorScheme: colorScheme2, layer } = platform;
|
|
313
|
+
const colorScheme_ = colorScheme2;
|
|
314
|
+
const format = createPropertyFormatter({
|
|
315
|
+
outputReferences,
|
|
316
|
+
dictionary,
|
|
317
|
+
format: "css",
|
|
318
|
+
usesDtcg
|
|
319
|
+
});
|
|
320
|
+
const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
|
|
321
|
+
color-scheme: ${colorScheme_};
|
|
322
|
+
` : "";
|
|
323
|
+
const filteredAllTokens = allTokens.filter(
|
|
324
|
+
R3.allPass([
|
|
325
|
+
R3.anyPass([
|
|
326
|
+
// Include semantic tokens in the output
|
|
327
|
+
isSemanticToken,
|
|
328
|
+
// Include global color tokens
|
|
329
|
+
isGlobalColorToken
|
|
330
|
+
]),
|
|
331
|
+
// Don't include color category tokens -- they are exported separately
|
|
332
|
+
(t) => !isColorCategoryToken(t)
|
|
333
|
+
])
|
|
334
|
+
);
|
|
335
|
+
const formattedTokens = filteredAllTokens.map(format).join("\n");
|
|
336
|
+
const content = `{
|
|
337
|
+
${formattedTokens}
|
|
338
|
+
${colorSchemeProperty}}
|
|
339
|
+
`;
|
|
340
|
+
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
341
|
+
const body = R3.isNotNil(layer) ? `@layer ${layer} {
|
|
342
|
+
${selector} ${content} ${autoSelectorContent}
|
|
343
|
+
}
|
|
344
|
+
` : `${selector} ${content} ${autoSelectorContent}
|
|
345
|
+
`;
|
|
346
|
+
return body;
|
|
347
|
+
}
|
|
348
|
+
};
|
|
349
|
+
var colorCategory = {
|
|
350
|
+
name: "ds/css-colorcategory",
|
|
351
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
352
|
+
const { outputReferences, usesDtcg } = options;
|
|
353
|
+
const { selector, layer } = platform;
|
|
354
|
+
const format = R3.compose(
|
|
355
|
+
createPropertyFormatter({
|
|
356
|
+
outputReferences,
|
|
357
|
+
dictionary,
|
|
358
|
+
format: "css",
|
|
359
|
+
usesDtcg
|
|
360
|
+
}),
|
|
361
|
+
(token) => ({
|
|
362
|
+
...token,
|
|
363
|
+
name: token.name.replace(/color-\w+-/, "color-"),
|
|
364
|
+
original: {
|
|
365
|
+
...token.original,
|
|
366
|
+
$value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
|
|
367
|
+
}
|
|
368
|
+
})
|
|
369
|
+
);
|
|
370
|
+
const formattedTokens = dictionary.allTokens.map(format).join("\n");
|
|
371
|
+
const content = `{
|
|
372
|
+
${formattedTokens}
|
|
373
|
+
}
|
|
374
|
+
`;
|
|
375
|
+
const body = R3.isNotNil(layer) ? `@layer ${layer} {
|
|
376
|
+
${selector} ${content}
|
|
377
|
+
}
|
|
378
|
+
` : `${selector} ${content}
|
|
379
|
+
`;
|
|
380
|
+
return body;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
|
|
384
|
+
// src/tokens/process/formats/css/semantic.ts
|
|
385
|
+
import * as R4 from "ramda";
|
|
386
|
+
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
387
|
+
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
388
|
+
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
389
|
+
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
390
|
+
var isInlineTokens = R4.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
391
|
+
var overrideSizingFormula = (format, token) => {
|
|
392
|
+
const [name, value] = format(token).split(":");
|
|
393
|
+
const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
|
|
394
|
+
const round = `round(down, ${calc}, 0.0625rem)`;
|
|
395
|
+
return {
|
|
396
|
+
name,
|
|
397
|
+
round,
|
|
398
|
+
calc
|
|
399
|
+
};
|
|
400
|
+
};
|
|
401
|
+
var formatSizingTokens = (format, tokens) => {
|
|
402
|
+
const { round, calc } = R4.reduce(
|
|
403
|
+
(acc, token) => {
|
|
404
|
+
const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
|
|
405
|
+
return {
|
|
406
|
+
round: [...acc.round, `${name}: ${round2};`],
|
|
407
|
+
calc: [...acc.calc, `${name}: ${calc2};`]
|
|
408
|
+
};
|
|
409
|
+
},
|
|
410
|
+
{ round: [], calc: [] },
|
|
411
|
+
tokens
|
|
412
|
+
);
|
|
413
|
+
return `
|
|
414
|
+
${calc.join("\n")}
|
|
415
|
+
|
|
416
|
+
@supports (width: round(down, .1em, 1px)) {
|
|
417
|
+
${round.join("\n")}
|
|
418
|
+
}`;
|
|
419
|
+
};
|
|
420
|
+
var semantic = {
|
|
421
|
+
name: "ds/css-semantic",
|
|
422
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
423
|
+
const { outputReferences, usesDtcg } = options;
|
|
424
|
+
const { selector, layer } = platform;
|
|
425
|
+
const format = createPropertyFormatter2({
|
|
426
|
+
outputReferences,
|
|
427
|
+
dictionary,
|
|
428
|
+
format: "css",
|
|
429
|
+
usesDtcg
|
|
430
|
+
});
|
|
431
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
432
|
+
const filteredTokens = R4.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
|
|
433
|
+
const [sizingTokens, restTokens] = R4.partition(
|
|
434
|
+
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
435
|
+
filteredTokens
|
|
436
|
+
);
|
|
437
|
+
const formattedTokens = [R4.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
|
|
438
|
+
const content = `{
|
|
439
|
+
${formattedTokens.join("\n")}
|
|
440
|
+
}
|
|
441
|
+
`;
|
|
442
|
+
const body = R4.isNotNil(layer) ? `@layer ${layer} {
|
|
443
|
+
${selector} ${content}
|
|
444
|
+
}
|
|
445
|
+
` : `${selector} ${content}
|
|
446
|
+
`;
|
|
447
|
+
return body;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
|
|
451
|
+
// src/tokens/process/formats/css/typography.ts
|
|
452
|
+
import * as R5 from "ramda";
|
|
453
|
+
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
454
|
+
var typographyFontFamilyPredicate = R5.allPass([
|
|
455
|
+
R5.pathSatisfies(R5.includes("typography"), ["path"]),
|
|
456
|
+
R5.pathSatisfies(R5.includes("fontFamily"), ["path"])
|
|
457
|
+
]);
|
|
458
|
+
var typography = {
|
|
459
|
+
name: "ds/css-typography",
|
|
460
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
461
|
+
const { outputReferences, usesDtcg } = options;
|
|
462
|
+
const { selector, layer } = platform;
|
|
463
|
+
const format = createPropertyFormatter3({
|
|
464
|
+
outputReferences,
|
|
465
|
+
dictionary,
|
|
466
|
+
format: "css",
|
|
467
|
+
usesDtcg
|
|
468
|
+
});
|
|
469
|
+
const filteredTokens = R5.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
470
|
+
const formattedTokens = R5.pipe(R5.map(format), R5.join("\n"))(filteredTokens);
|
|
471
|
+
const content = selector ? `${selector} {
|
|
472
|
+
${formattedTokens}
|
|
473
|
+
}` : formattedTokens;
|
|
474
|
+
const body = R5.isNotNil(layer) ? `@layer ${layer} {
|
|
475
|
+
${content}
|
|
476
|
+
}` : content;
|
|
477
|
+
return body;
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
|
|
481
|
+
// src/tokens/process/formats/css.ts
|
|
482
|
+
var formats = {
|
|
483
|
+
colorScheme,
|
|
484
|
+
colorCategory,
|
|
485
|
+
semantic,
|
|
486
|
+
typography
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
// src/tokens/process/transformers.ts
|
|
490
|
+
import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
|
|
491
|
+
import * as R6 from "ramda";
|
|
492
|
+
var isPx = R6.test(/\b\d+px\b/g);
|
|
493
|
+
var sizeRem = {
|
|
494
|
+
name: "ds/size/toRem",
|
|
495
|
+
type: "value",
|
|
496
|
+
transitive: true,
|
|
497
|
+
filter: (token) => {
|
|
498
|
+
const hasWantedType = typeEquals(["dimension", "fontsize"], token);
|
|
499
|
+
const hasWantedPath = pathStartsWithOneOf(["spacing", "sizing", "border-radius", "font-size"], token);
|
|
500
|
+
return hasWantedType && hasWantedPath;
|
|
501
|
+
},
|
|
502
|
+
transform: (token, config) => {
|
|
503
|
+
const value = getValue(token);
|
|
504
|
+
if (isPx(value)) {
|
|
505
|
+
const baseFont = config.basePxFontSize || 16;
|
|
506
|
+
const size = parseInt(value);
|
|
507
|
+
if (size === 0) {
|
|
508
|
+
return "0";
|
|
509
|
+
}
|
|
510
|
+
return `${size / baseFont}rem`;
|
|
511
|
+
}
|
|
512
|
+
return value;
|
|
513
|
+
}
|
|
514
|
+
};
|
|
515
|
+
var typographyName = {
|
|
516
|
+
name: "name/typography",
|
|
517
|
+
type: "name",
|
|
518
|
+
transitive: true,
|
|
519
|
+
// expanded tokens have different type so we match on path instead
|
|
520
|
+
filter: (token) => pathStartsWithOneOf(["typography"], token),
|
|
521
|
+
transform: (token) => {
|
|
522
|
+
return token.name.replace("-typography", "");
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
var resolveMath = {
|
|
526
|
+
name: "ds/resolveMath",
|
|
527
|
+
type: "value",
|
|
528
|
+
transitive: true,
|
|
529
|
+
filter: (token) => {
|
|
530
|
+
const isValidValue = ["string", "object"].includes(typeof getValue(token));
|
|
531
|
+
const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
|
|
532
|
+
return isValidValue && isTokenOfInterest;
|
|
533
|
+
},
|
|
534
|
+
transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
|
|
535
|
+
};
|
|
536
|
+
var unitless = {
|
|
537
|
+
name: "ds/unitless",
|
|
538
|
+
type: "value",
|
|
539
|
+
transitive: true,
|
|
540
|
+
filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
|
|
541
|
+
transform: (token) => parseInt(getValue(token))
|
|
542
|
+
};
|
|
543
|
+
|
|
544
|
+
// src/tokens/process/configs/shared.ts
|
|
545
|
+
var prefix = "ds";
|
|
546
|
+
var basePxFontSize = 16;
|
|
547
|
+
var dsTransformers = [
|
|
548
|
+
"name/kebab",
|
|
549
|
+
resolveMath.name,
|
|
550
|
+
"ts/size/px",
|
|
551
|
+
sizeRem.name,
|
|
552
|
+
unitless.name,
|
|
553
|
+
"ts/typography/fontWeight",
|
|
554
|
+
typographyName.name,
|
|
555
|
+
"ts/color/modifiers",
|
|
556
|
+
"ts/color/css/hexrgba",
|
|
557
|
+
"ts/size/lineheight",
|
|
558
|
+
"shadow/css/shorthand"
|
|
559
|
+
];
|
|
560
|
+
|
|
561
|
+
// src/tokens/process/configs/color.ts
|
|
562
|
+
var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) => {
|
|
563
|
+
const selector = `${colorScheme2 === "light" ? ":root, " : ""}[data-color-scheme="${colorScheme2}"]`;
|
|
564
|
+
const layer = `ds.theme.color-scheme.${colorScheme2}`;
|
|
565
|
+
return {
|
|
566
|
+
preprocessors: ["tokens-studio"],
|
|
567
|
+
platforms: {
|
|
568
|
+
css: {
|
|
569
|
+
// custom
|
|
570
|
+
colorScheme: colorScheme2,
|
|
571
|
+
theme,
|
|
572
|
+
selector,
|
|
573
|
+
layer,
|
|
574
|
+
//
|
|
575
|
+
prefix,
|
|
576
|
+
buildPath: `${theme}/`,
|
|
577
|
+
transforms: dsTransformers,
|
|
578
|
+
files: [
|
|
579
|
+
{
|
|
580
|
+
destination: `color-scheme/${colorScheme2}.css`,
|
|
581
|
+
format: formats.colorScheme.name,
|
|
582
|
+
filter: (token) => typeEquals("color", token) && !R7.startsWith(["global"], token.path)
|
|
583
|
+
}
|
|
584
|
+
],
|
|
585
|
+
options: {
|
|
586
|
+
outputReferences: false
|
|
587
|
+
}
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
};
|
|
591
|
+
};
|
|
592
|
+
var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, ...permutation }) => {
|
|
593
|
+
const category = opts.category;
|
|
594
|
+
const color = category === "builtin" ? opts.color : permutation[`${category}-color`];
|
|
595
|
+
if (!color) {
|
|
596
|
+
throw new Error(
|
|
597
|
+
category === "builtin" ? `Missing color for built-in color ${opts.color}` : `Missing color for category ${category}`
|
|
598
|
+
);
|
|
599
|
+
}
|
|
600
|
+
const layer = `ds.theme.color`;
|
|
601
|
+
const isRootColor = color === buildOptions?.rootColor;
|
|
602
|
+
const selector = isRootColor ? `:root, [data-color-scheme], [data-color="${color}"]` : `[data-color="${color}"], [data-color-scheme][data-color="${color}"]`;
|
|
603
|
+
const config = {
|
|
604
|
+
preprocessors: ["tokens-studio"],
|
|
605
|
+
platforms: {
|
|
606
|
+
css: {
|
|
607
|
+
// custom
|
|
608
|
+
colorScheme: colorScheme2,
|
|
609
|
+
theme,
|
|
610
|
+
selector,
|
|
611
|
+
layer,
|
|
612
|
+
//
|
|
613
|
+
prefix,
|
|
614
|
+
buildPath: `${theme}/`,
|
|
615
|
+
transforms: dsTransformers,
|
|
616
|
+
files: [
|
|
617
|
+
{
|
|
618
|
+
destination: `color/${color}.css`,
|
|
619
|
+
format: formats.colorCategory.name,
|
|
620
|
+
filter: (token) => category === "builtin" ? isSemanticColorToken(token, color) : isColorCategoryToken(token, category)
|
|
621
|
+
}
|
|
622
|
+
],
|
|
623
|
+
options: {
|
|
624
|
+
outputReferences: true
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
};
|
|
629
|
+
return config;
|
|
630
|
+
};
|
|
631
|
+
|
|
632
|
+
// src/tokens/process/configs/semantic.ts
|
|
633
|
+
import * as R8 from "ramda";
|
|
634
|
+
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
635
|
+
var semanticVariables = ({ theme }) => {
|
|
636
|
+
const selector = `:root`;
|
|
637
|
+
const layer = `ds.theme.semantic`;
|
|
638
|
+
return {
|
|
639
|
+
preprocessors: ["tokens-studio"],
|
|
640
|
+
platforms: {
|
|
641
|
+
css: {
|
|
642
|
+
// custom
|
|
643
|
+
theme,
|
|
644
|
+
basePxFontSize,
|
|
645
|
+
selector,
|
|
646
|
+
layer,
|
|
647
|
+
//
|
|
648
|
+
prefix,
|
|
649
|
+
buildPath: `${theme}/`,
|
|
650
|
+
transforms: dsTransformers,
|
|
651
|
+
files: [
|
|
652
|
+
{
|
|
653
|
+
destination: `semantic.css`,
|
|
654
|
+
format: formats.semantic.name,
|
|
655
|
+
filter: (token) => {
|
|
656
|
+
const isUwantedToken = R8.anyPass([R8.includes("primitives/global")])(token.filePath);
|
|
657
|
+
const isPrivateToken = R8.includes("_", token.path);
|
|
658
|
+
const unwantedPaths = pathStartsWithOneOf(["font-size", "line-height", "letter-spacing"], token);
|
|
659
|
+
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
660
|
+
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
661
|
+
return unwantedTokens;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
],
|
|
665
|
+
options: {
|
|
666
|
+
outputReferences: (token, options) => {
|
|
667
|
+
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
668
|
+
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
|
|
669
|
+
return (include || isWantedSize) && outputReferencesFilter(token, options);
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
};
|
|
675
|
+
};
|
|
676
|
+
|
|
677
|
+
// src/tokens/process/configs/storefront.ts
|
|
678
|
+
import * as R10 from "ramda";
|
|
679
|
+
import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
|
|
680
|
+
|
|
681
|
+
// src/tokens/process/formats/js-tokens.ts
|
|
682
|
+
import * as R9 from "ramda";
|
|
683
|
+
import { createPropertyFormatter as createPropertyFormatter4, fileHeader } from "style-dictionary/utils";
|
|
684
|
+
var groupByType = R9.groupBy((token) => getType(token));
|
|
685
|
+
var removeUnwatedTokens = R9.pipe(
|
|
686
|
+
R9.reject((token) => isColorCategoryToken(token)),
|
|
687
|
+
R9.reject((token) => R9.any((path2) => path2.startsWith("_"))(token.path))
|
|
688
|
+
);
|
|
689
|
+
var dissocExtensions = R9.pipe(R9.dissoc("$extensions"), R9.dissocPath(["original", "$extensions"]));
|
|
690
|
+
var removeUnwatedProps = R9.map((token) => dissocExtensions(token));
|
|
691
|
+
var toCssVarName = R9.pipe(R9.split(":"), R9.head, R9.trim);
|
|
692
|
+
var jsTokens = {
|
|
693
|
+
name: "ds/js-tokens",
|
|
694
|
+
format: async ({ dictionary, file, options }) => {
|
|
695
|
+
const { usesDtcg, outputReferences } = options;
|
|
696
|
+
const format = createPropertyFormatter4({
|
|
697
|
+
outputReferences,
|
|
698
|
+
dictionary,
|
|
699
|
+
format: "css",
|
|
700
|
+
usesDtcg
|
|
701
|
+
});
|
|
702
|
+
const formatTokens = R9.map((token) => {
|
|
703
|
+
if (pathStartsWithOneOf(["size", "_size"], token)) {
|
|
704
|
+
const { calc, name } = overrideSizingFormula(format, token);
|
|
705
|
+
return {
|
|
706
|
+
...token,
|
|
707
|
+
name: name.trim(),
|
|
708
|
+
$value: calc.trim()
|
|
709
|
+
};
|
|
710
|
+
}
|
|
711
|
+
return {
|
|
712
|
+
...token,
|
|
713
|
+
name: toCssVarName(format(token))
|
|
714
|
+
};
|
|
715
|
+
});
|
|
716
|
+
const processTokens = R9.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
|
|
717
|
+
const tokens = processTokens(inlineTokens(isInlineTokens, dictionary.allTokens));
|
|
718
|
+
const content = Object.entries(tokens).map(
|
|
719
|
+
([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
|
|
720
|
+
`
|
|
721
|
+
).join("\n");
|
|
722
|
+
return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
|
|
723
|
+
}
|
|
724
|
+
};
|
|
725
|
+
|
|
726
|
+
// src/tokens/process/configs/storefront.ts
|
|
727
|
+
var typescriptTokens = ({ "color-scheme": colorScheme2, theme }) => {
|
|
728
|
+
return {
|
|
729
|
+
preprocessors: ["tokens-studio"],
|
|
730
|
+
platforms: {
|
|
731
|
+
ts: {
|
|
732
|
+
prefix,
|
|
733
|
+
basePxFontSize,
|
|
734
|
+
transforms: dsTransformers,
|
|
735
|
+
buildPath: `${theme}/`,
|
|
736
|
+
files: [
|
|
737
|
+
{
|
|
738
|
+
destination: `${colorScheme2}.ts`,
|
|
739
|
+
format: jsTokens.name,
|
|
740
|
+
filter: (token) => {
|
|
741
|
+
if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R10.includes("semantic", token.filePath))
|
|
742
|
+
return false;
|
|
743
|
+
const isSemanticColor = R10.includes("semantic", token.filePath) && typeEquals(["color"], token);
|
|
744
|
+
const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
|
|
745
|
+
return isSemanticColor || wantedTypes;
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
],
|
|
749
|
+
options: {
|
|
750
|
+
outputReferences: (token, options) => {
|
|
751
|
+
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
752
|
+
const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
|
|
753
|
+
return (include || isWantedSize) && outputReferencesFilter2(token, options);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
}
|
|
758
|
+
};
|
|
759
|
+
};
|
|
760
|
+
|
|
761
|
+
// src/tokens/process/configs/typography.ts
|
|
762
|
+
import { expandTypesMap } from "@tokens-studio/sd-transforms";
|
|
763
|
+
var typographyVariables = ({ theme, typography: typography2 }) => {
|
|
764
|
+
const selector = `${typography2 === "primary" ? ":root, " : ""}[data-typography="${typography2}"]`;
|
|
765
|
+
const layer = `ds.theme.typography.${typography2}`;
|
|
766
|
+
return {
|
|
767
|
+
usesDtcg: true,
|
|
768
|
+
preprocessors: ["tokens-studio"],
|
|
769
|
+
expand: {
|
|
770
|
+
include: ["typography"],
|
|
771
|
+
typesMap: { ...expandTypesMap, typography: { ...expandTypesMap.typography, letterSpacing: "dimension" } }
|
|
772
|
+
},
|
|
773
|
+
platforms: {
|
|
774
|
+
css: {
|
|
775
|
+
prefix,
|
|
776
|
+
typography: typography2,
|
|
777
|
+
selector,
|
|
778
|
+
layer,
|
|
779
|
+
buildPath: `${theme}/`,
|
|
780
|
+
basePxFontSize,
|
|
781
|
+
transforms: [
|
|
782
|
+
"name/kebab",
|
|
783
|
+
"ts/size/px",
|
|
784
|
+
sizeRem.name,
|
|
785
|
+
"ts/size/lineheight",
|
|
786
|
+
"ts/typography/fontWeight",
|
|
787
|
+
typographyName.name
|
|
788
|
+
],
|
|
789
|
+
files: [
|
|
790
|
+
{
|
|
791
|
+
destination: `typography/${typography2}.css`,
|
|
792
|
+
format: formats.typography.name,
|
|
793
|
+
filter: (token) => {
|
|
794
|
+
const included = typeEquals(
|
|
795
|
+
["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
|
|
796
|
+
token
|
|
797
|
+
);
|
|
798
|
+
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
799
|
+
return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token);
|
|
800
|
+
}
|
|
801
|
+
}
|
|
802
|
+
]
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
};
|
|
806
|
+
};
|
|
807
|
+
|
|
808
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
|
|
809
|
+
var BoxShadowTypes;
|
|
810
|
+
(function(BoxShadowTypes2) {
|
|
811
|
+
BoxShadowTypes2["DROP_SHADOW"] = "dropShadow";
|
|
812
|
+
BoxShadowTypes2["INNER_SHADOW"] = "innerShadow";
|
|
813
|
+
})(BoxShadowTypes || (BoxShadowTypes = {}));
|
|
814
|
+
|
|
815
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
|
|
816
|
+
var ColorModifierTypes;
|
|
817
|
+
(function(ColorModifierTypes2) {
|
|
818
|
+
ColorModifierTypes2["LIGHTEN"] = "lighten";
|
|
819
|
+
ColorModifierTypes2["DARKEN"] = "darken";
|
|
820
|
+
ColorModifierTypes2["MIX"] = "mix";
|
|
821
|
+
ColorModifierTypes2["ALPHA"] = "alpha";
|
|
822
|
+
})(ColorModifierTypes || (ColorModifierTypes = {}));
|
|
823
|
+
|
|
824
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
|
|
825
|
+
var ColorSpaceTypes;
|
|
826
|
+
(function(ColorSpaceTypes2) {
|
|
827
|
+
ColorSpaceTypes2["LCH"] = "lch";
|
|
828
|
+
ColorSpaceTypes2["SRGB"] = "srgb";
|
|
829
|
+
ColorSpaceTypes2["P3"] = "p3";
|
|
830
|
+
ColorSpaceTypes2["HSL"] = "hsl";
|
|
831
|
+
})(ColorSpaceTypes || (ColorSpaceTypes = {}));
|
|
832
|
+
|
|
833
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/Properties.js
|
|
834
|
+
var Properties;
|
|
835
|
+
(function(Properties2) {
|
|
836
|
+
Properties2["sizing"] = "sizing";
|
|
837
|
+
Properties2["height"] = "height";
|
|
838
|
+
Properties2["width"] = "width";
|
|
839
|
+
Properties2["spacing"] = "spacing";
|
|
840
|
+
Properties2["verticalPadding"] = "verticalPadding";
|
|
841
|
+
Properties2["horizontalPadding"] = "horizontalPadding";
|
|
842
|
+
Properties2["paddingTop"] = "paddingTop";
|
|
843
|
+
Properties2["paddingRight"] = "paddingRight";
|
|
844
|
+
Properties2["paddingBottom"] = "paddingBottom";
|
|
845
|
+
Properties2["paddingLeft"] = "paddingLeft";
|
|
846
|
+
Properties2["itemSpacing"] = "itemSpacing";
|
|
847
|
+
Properties2["fill"] = "fill";
|
|
848
|
+
Properties2["backgroundBlur"] = "backgroundBlur";
|
|
849
|
+
Properties2["border"] = "border";
|
|
850
|
+
Properties2["borderTop"] = "borderTop";
|
|
851
|
+
Properties2["borderRight"] = "borderRight";
|
|
852
|
+
Properties2["borderBottom"] = "borderBottom";
|
|
853
|
+
Properties2["borderLeft"] = "borderLeft";
|
|
854
|
+
Properties2["borderColor"] = "borderColor";
|
|
855
|
+
Properties2["borderRadius"] = "borderRadius";
|
|
856
|
+
Properties2["borderRadiusTopLeft"] = "borderRadiusTopLeft";
|
|
857
|
+
Properties2["borderRadiusTopRight"] = "borderRadiusTopRight";
|
|
858
|
+
Properties2["borderRadiusBottomRight"] = "borderRadiusBottomRight";
|
|
859
|
+
Properties2["borderRadiusBottomLeft"] = "borderRadiusBottomLeft";
|
|
860
|
+
Properties2["borderWidth"] = "borderWidth";
|
|
861
|
+
Properties2["borderWidthTop"] = "borderWidthTop";
|
|
862
|
+
Properties2["borderWidthRight"] = "borderWidthRight";
|
|
863
|
+
Properties2["borderWidthBottom"] = "borderWidthBottom";
|
|
864
|
+
Properties2["borderWidthLeft"] = "borderWidthLeft";
|
|
865
|
+
Properties2["boxShadow"] = "boxShadow";
|
|
866
|
+
Properties2["opacity"] = "opacity";
|
|
867
|
+
Properties2["fontFamilies"] = "fontFamilies";
|
|
868
|
+
Properties2["fontWeights"] = "fontWeights";
|
|
869
|
+
Properties2["fontSizes"] = "fontSizes";
|
|
870
|
+
Properties2["lineHeights"] = "lineHeights";
|
|
871
|
+
Properties2["typography"] = "typography";
|
|
872
|
+
Properties2["composition"] = "composition";
|
|
873
|
+
Properties2["letterSpacing"] = "letterSpacing";
|
|
874
|
+
Properties2["paragraphSpacing"] = "paragraphSpacing";
|
|
875
|
+
Properties2["textCase"] = "textCase";
|
|
876
|
+
Properties2["dimension"] = "dimension";
|
|
877
|
+
Properties2["textDecoration"] = "textDecoration";
|
|
878
|
+
Properties2["asset"] = "asset";
|
|
879
|
+
Properties2["tokenValue"] = "tokenValue";
|
|
880
|
+
Properties2["value"] = "value";
|
|
881
|
+
Properties2["tokenName"] = "tokenName";
|
|
882
|
+
Properties2["description"] = "description";
|
|
883
|
+
})(Properties || (Properties = {}));
|
|
884
|
+
|
|
885
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
|
|
886
|
+
var TokenSetStatus;
|
|
887
|
+
(function(TokenSetStatus2) {
|
|
888
|
+
TokenSetStatus2["DISABLED"] = "disabled";
|
|
889
|
+
TokenSetStatus2["SOURCE"] = "source";
|
|
890
|
+
TokenSetStatus2["ENABLED"] = "enabled";
|
|
891
|
+
})(TokenSetStatus || (TokenSetStatus = {}));
|
|
892
|
+
|
|
893
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
|
|
894
|
+
var TokenTypes;
|
|
895
|
+
(function(TokenTypes2) {
|
|
896
|
+
TokenTypes2["OTHER"] = "other";
|
|
897
|
+
TokenTypes2["COLOR"] = "color";
|
|
898
|
+
TokenTypes2["BORDER_RADIUS"] = "borderRadius";
|
|
899
|
+
TokenTypes2["SIZING"] = "sizing";
|
|
900
|
+
TokenTypes2["SPACING"] = "spacing";
|
|
901
|
+
TokenTypes2["TEXT"] = "text";
|
|
902
|
+
TokenTypes2["TYPOGRAPHY"] = "typography";
|
|
903
|
+
TokenTypes2["OPACITY"] = "opacity";
|
|
904
|
+
TokenTypes2["BORDER_WIDTH"] = "borderWidth";
|
|
905
|
+
TokenTypes2["STROKE_STYLE"] = "strokeStyle";
|
|
906
|
+
TokenTypes2["BOX_SHADOW"] = "boxShadow";
|
|
907
|
+
TokenTypes2["FONT_FAMILIES"] = "fontFamilies";
|
|
908
|
+
TokenTypes2["FONT_WEIGHTS"] = "fontWeights";
|
|
909
|
+
TokenTypes2["LINE_HEIGHTS"] = "lineHeights";
|
|
910
|
+
TokenTypes2["FONT_SIZES"] = "fontSizes";
|
|
911
|
+
TokenTypes2["LETTER_SPACING"] = "letterSpacing";
|
|
912
|
+
TokenTypes2["PARAGRAPH_SPACING"] = "paragraphSpacing";
|
|
913
|
+
TokenTypes2["PARAGRAPH_INDENT"] = "paragraphIndent";
|
|
914
|
+
TokenTypes2["TEXT_DECORATION"] = "textDecoration";
|
|
915
|
+
TokenTypes2["TEXT_CASE"] = "textCase";
|
|
916
|
+
TokenTypes2["COMPOSITION"] = "composition";
|
|
917
|
+
TokenTypes2["DIMENSION"] = "dimension";
|
|
918
|
+
TokenTypes2["BORDER"] = "border";
|
|
919
|
+
TokenTypes2["ASSET"] = "asset";
|
|
920
|
+
TokenTypes2["BOOLEAN"] = "boolean";
|
|
921
|
+
TokenTypes2["NUMBER"] = "number";
|
|
922
|
+
})(TokenTypes || (TokenTypes = {}));
|
|
923
|
+
|
|
924
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/BorderValues.js
|
|
925
|
+
var BorderValues;
|
|
926
|
+
(function(BorderValues2) {
|
|
927
|
+
BorderValues2["BORDER_COLOR"] = "color";
|
|
928
|
+
BorderValues2["BORDER_WIDTH"] = "width";
|
|
929
|
+
BorderValues2["BORDER_STYLE"] = "style";
|
|
930
|
+
})(BorderValues || (BorderValues = {}));
|
|
931
|
+
|
|
932
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
|
|
933
|
+
var StrokeStyleValues;
|
|
934
|
+
(function(StrokeStyleValues2) {
|
|
935
|
+
StrokeStyleValues2["SOLID"] = "solid";
|
|
936
|
+
StrokeStyleValues2["DASHED"] = "dashed";
|
|
937
|
+
StrokeStyleValues2["DOTTED"] = "dotted";
|
|
938
|
+
StrokeStyleValues2["DOUBLE"] = "double";
|
|
939
|
+
StrokeStyleValues2["GROOVE"] = "groove";
|
|
940
|
+
StrokeStyleValues2["RIDGE"] = "ridge";
|
|
941
|
+
StrokeStyleValues2["OUTSET"] = "outset";
|
|
942
|
+
StrokeStyleValues2["INSET"] = "inset";
|
|
943
|
+
})(StrokeStyleValues || (StrokeStyleValues = {}));
|
|
944
|
+
|
|
945
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
|
|
946
|
+
var BoxShadowValues;
|
|
947
|
+
(function(BoxShadowValues2) {
|
|
948
|
+
BoxShadowValues2["TYPE"] = "type";
|
|
949
|
+
BoxShadowValues2["COLOR"] = "color";
|
|
950
|
+
BoxShadowValues2["X"] = "x";
|
|
951
|
+
BoxShadowValues2["Y"] = "y";
|
|
952
|
+
BoxShadowValues2["BLUR"] = "blur";
|
|
953
|
+
BoxShadowValues2["SPREAD"] = "spread";
|
|
954
|
+
BoxShadowValues2["BLEND_MODE"] = "blendMode";
|
|
955
|
+
})(BoxShadowValues || (BoxShadowValues = {}));
|
|
956
|
+
|
|
957
|
+
// ../../node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
|
|
958
|
+
var TypographyValues;
|
|
959
|
+
(function(TypographyValues2) {
|
|
960
|
+
TypographyValues2["FONT_FAMILY"] = "fontFamily";
|
|
961
|
+
TypographyValues2["FONT_WEIGHT"] = "fontWeight";
|
|
962
|
+
TypographyValues2["LINE_HEIGHT"] = "lineHeight";
|
|
963
|
+
TypographyValues2["FONT_SIZE"] = "fontSize";
|
|
964
|
+
TypographyValues2["LETTER_SPACING"] = "letterSpacing";
|
|
965
|
+
TypographyValues2["PARAGRAPH_SPACING"] = "paragraphSpacing";
|
|
966
|
+
TypographyValues2["PARAGRAPH_INDENT"] = "paragraphIndent";
|
|
967
|
+
TypographyValues2["TEXT_DECORATION"] = "textDecoration";
|
|
968
|
+
TypographyValues2["TEXT_CASE"] = "textCase";
|
|
969
|
+
})(TypographyValues || (TypographyValues = {}));
|
|
970
|
+
|
|
971
|
+
// src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
972
|
+
import chalk3 from "chalk";
|
|
973
|
+
import { kebabCase } from "change-case";
|
|
974
|
+
import * as R11 from "ramda";
|
|
975
|
+
var getMultidimensionalThemes = (processed$themes, dimensions) => {
|
|
976
|
+
const verboseLogging = buildOptions?.verbose;
|
|
977
|
+
const grouped$themes = groupThemes(processed$themes);
|
|
978
|
+
const permutations = permutateThemes(grouped$themes);
|
|
979
|
+
const ALL_DEPENDENT_ON = ["theme"];
|
|
980
|
+
const keys2 = R11.keys(grouped$themes);
|
|
981
|
+
const nonDependentKeys = keys2.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
|
|
982
|
+
if (verboseLogging) {
|
|
983
|
+
console.log(chalk3.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
|
|
984
|
+
console.log(chalk3.cyan(` (ignoring permutations for ${nonDependentKeys})`));
|
|
985
|
+
}
|
|
986
|
+
return permutations.filter((val) => {
|
|
987
|
+
const filters = nonDependentKeys.map((x) => val.permutation[x] === grouped$themes[x][0].name);
|
|
988
|
+
return filters.every((x) => x);
|
|
989
|
+
});
|
|
990
|
+
};
|
|
991
|
+
var processed = Symbol("Type brand for ProcessedThemeObject");
|
|
992
|
+
function isProcessed(theme) {
|
|
993
|
+
return Boolean(theme[processed]);
|
|
994
|
+
}
|
|
995
|
+
function processThemeObject(theme) {
|
|
996
|
+
if (isProcessed(theme)) {
|
|
997
|
+
return theme;
|
|
998
|
+
}
|
|
999
|
+
const result = { ...theme, [processed]: true };
|
|
1000
|
+
if (result.group) {
|
|
1001
|
+
result.group = kebabCase(result.group);
|
|
1002
|
+
}
|
|
1003
|
+
result.name = kebabCase(result.name);
|
|
1004
|
+
return result;
|
|
1005
|
+
}
|
|
1006
|
+
function groupThemes(themes) {
|
|
1007
|
+
const groups = {};
|
|
1008
|
+
for (const rawTheme of themes) {
|
|
1009
|
+
const theme = processThemeObject(rawTheme);
|
|
1010
|
+
if (theme.group) {
|
|
1011
|
+
const groupKey = theme.group;
|
|
1012
|
+
groups[groupKey] = [...groups[groupKey] ?? [], theme];
|
|
1013
|
+
} else {
|
|
1014
|
+
throw new Error(
|
|
1015
|
+
`Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
return groups;
|
|
1020
|
+
}
|
|
1021
|
+
var hasUnknownProps = R11.pipe(R11.values, R11.none(R11.equals("unknown")), R11.not);
|
|
1022
|
+
function permutateThemes(groups) {
|
|
1023
|
+
const separator = "_";
|
|
1024
|
+
const permutations = cartesian(Object.values(groups));
|
|
1025
|
+
const permutatedThemes = permutations.map((perm) => {
|
|
1026
|
+
const permutatedTheme = perm.reduce(
|
|
1027
|
+
(acc, theme) => {
|
|
1028
|
+
const { group, name, selectedTokenSets } = theme;
|
|
1029
|
+
let updatedPermutation = acc.permutation;
|
|
1030
|
+
if (group) {
|
|
1031
|
+
const groupProp = R11.lensProp(group);
|
|
1032
|
+
updatedPermutation = R11.set(groupProp, name, updatedPermutation);
|
|
1033
|
+
}
|
|
1034
|
+
const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
|
|
1035
|
+
const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
|
|
1036
|
+
return {
|
|
1037
|
+
permutation: updatedPermutation,
|
|
1038
|
+
name: updatedName,
|
|
1039
|
+
selectedTokenSets: sets
|
|
1040
|
+
};
|
|
1041
|
+
},
|
|
1042
|
+
{
|
|
1043
|
+
name: "",
|
|
1044
|
+
selectedTokenSets: [],
|
|
1045
|
+
permutation: {
|
|
1046
|
+
"color-scheme": "unknown",
|
|
1047
|
+
"main-color": "unknown",
|
|
1048
|
+
"support-color": "unknown",
|
|
1049
|
+
theme: "unknown",
|
|
1050
|
+
semantic: "unknown",
|
|
1051
|
+
size: "unknown",
|
|
1052
|
+
typography: "unknown"
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
);
|
|
1056
|
+
if (hasUnknownProps(permutatedTheme)) {
|
|
1057
|
+
throw Error(`Theme ${permutatedTheme.name} has unknown props: ${JSON.stringify(permutatedTheme)}`);
|
|
1058
|
+
}
|
|
1059
|
+
const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
|
|
1060
|
+
return { ...permutatedTheme, selectedTokenSets: Array.from(uniqueTokenSets) };
|
|
1061
|
+
});
|
|
1062
|
+
return permutatedThemes;
|
|
1063
|
+
}
|
|
1064
|
+
function filterTokenSets(tokensets) {
|
|
1065
|
+
return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
|
|
1066
|
+
if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
|
|
1067
|
+
return -1;
|
|
1068
|
+
}
|
|
1069
|
+
if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
|
|
1070
|
+
return 1;
|
|
1071
|
+
}
|
|
1072
|
+
return 0;
|
|
1073
|
+
}).map((entry) => entry[0]);
|
|
1074
|
+
}
|
|
1075
|
+
function cartesian(a) {
|
|
1076
|
+
return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e].flat())));
|
|
1077
|
+
}
|
|
1078
|
+
|
|
1079
|
+
// src/tokens/process/configs.ts
|
|
1080
|
+
void register(StyleDictionary, { withSDBuiltins: false });
|
|
1081
|
+
StyleDictionary.registerTransform(sizeRem);
|
|
1082
|
+
StyleDictionary.registerTransform(typographyName);
|
|
1083
|
+
StyleDictionary.registerTransform(resolveMath);
|
|
1084
|
+
StyleDictionary.registerTransform(unitless);
|
|
1085
|
+
StyleDictionary.registerFormat(jsTokens);
|
|
1086
|
+
for (const format of Object.values(formats)) {
|
|
1087
|
+
StyleDictionary.registerFormat(format);
|
|
1088
|
+
}
|
|
1089
|
+
var configs = {
|
|
1090
|
+
colorSchemeVariables,
|
|
1091
|
+
mainColorVariables: colorCategoryVariables({ category: "main" }),
|
|
1092
|
+
supportColorVariables: colorCategoryVariables({ category: "support" }),
|
|
1093
|
+
neutralColorVariables: colorCategoryVariables({ category: "builtin", color: "neutral" }),
|
|
1094
|
+
successColorVariables: colorCategoryVariables({ category: "builtin", color: "success" }),
|
|
1095
|
+
dangerColorVariables: colorCategoryVariables({ category: "builtin", color: "danger" }),
|
|
1096
|
+
warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
|
|
1097
|
+
infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
|
|
1098
|
+
typographyVariables,
|
|
1099
|
+
semanticVariables,
|
|
1100
|
+
typescriptTokens
|
|
1101
|
+
};
|
|
1102
|
+
var getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, options) => {
|
|
1103
|
+
const { tokensDir, tokenSets } = options;
|
|
1104
|
+
const permutations = getMultidimensionalThemes(processed$themes, dimensions);
|
|
1105
|
+
return permutations.flatMap(({ selectedTokenSets, permutation }) => {
|
|
1106
|
+
const tokenSource = { source: void 0, tokens: {} };
|
|
1107
|
+
if (tokenSets) {
|
|
1108
|
+
for (const tokenSet of selectedTokenSets) {
|
|
1109
|
+
const tokens = tokenSets.get(tokenSet);
|
|
1110
|
+
if (tokens) {
|
|
1111
|
+
const tokensWithFilePath = traverseObj(tokens, (obj) => {
|
|
1112
|
+
if (Object.hasOwn(obj, `$value`) && !obj.filePath) {
|
|
1113
|
+
obj.filePath = tokenSet;
|
|
1114
|
+
}
|
|
1115
|
+
});
|
|
1116
|
+
tokenSource.tokens = R12.mergeDeepRight(tokenSource.tokens, tokensWithFilePath);
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
} else {
|
|
1120
|
+
tokenSource.source = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
|
|
1121
|
+
}
|
|
1122
|
+
const configOrConfigs = getConfig(permutation);
|
|
1123
|
+
const configs_ = Array.isArray(configOrConfigs) ? configOrConfigs : [{ config: configOrConfigs }];
|
|
1124
|
+
const configs2 = configs_.map(({ config, permutationOverrides }) => {
|
|
1125
|
+
return {
|
|
1126
|
+
permutation: { ...permutation, ...permutationOverrides },
|
|
1127
|
+
config: {
|
|
1128
|
+
...config,
|
|
1129
|
+
/** Use official W3C design token format
|
|
1130
|
+
@see https://v4.styledictionary.com/info/dtcg/
|
|
1131
|
+
@see https://design-tokens.github.io/community-group/format/ */
|
|
1132
|
+
usesDtcg: true,
|
|
1133
|
+
log: {
|
|
1134
|
+
...config?.log,
|
|
1135
|
+
verbosity: buildOptions?.verbose ? "verbose" : "silent"
|
|
1136
|
+
},
|
|
1137
|
+
...tokenSource
|
|
1138
|
+
}
|
|
1139
|
+
};
|
|
1140
|
+
});
|
|
1141
|
+
return configs2;
|
|
1142
|
+
}).sort();
|
|
1143
|
+
};
|
|
1144
|
+
|
|
1145
|
+
// src/tokens/process/platform.ts
|
|
1146
|
+
var initResult = {
|
|
1147
|
+
formatted: [],
|
|
1148
|
+
permutation: {
|
|
1149
|
+
"color-scheme": "",
|
|
1150
|
+
"main-color": "",
|
|
1151
|
+
"support-color": "",
|
|
1152
|
+
semantic: "",
|
|
1153
|
+
size: "",
|
|
1154
|
+
theme: "",
|
|
1155
|
+
typography: ""
|
|
1156
|
+
}
|
|
1157
|
+
};
|
|
1158
|
+
var buildOptions;
|
|
1159
|
+
var sd = new StyleDictionary2();
|
|
1160
|
+
var getCustomColors = (processed$themes) => processed$themes.filter(
|
|
1161
|
+
(x) => x.group && [colorCategories.main, colorCategories.support].map((c) => `${c}-color`).includes(x.group)
|
|
1162
|
+
).map((x) => x.name);
|
|
1163
|
+
var buildConfigs = {
|
|
16
1164
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
17
1165
|
"color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
|
|
18
1166
|
"main-color": { getConfig: configs.mainColorVariables, dimensions: ["main-color"] },
|
|
@@ -42,45 +1190,32 @@ const buildConfigs = {
|
|
|
42
1190
|
dimensions: ["semantic"],
|
|
43
1191
|
log: ({ permutation: { theme } }) => `${theme} - info`
|
|
44
1192
|
},
|
|
45
|
-
semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] }
|
|
46
|
-
storefront: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
},
|
|
53
|
-
entryFiles: {
|
|
54
|
-
name: "Concatenated CSS file",
|
|
55
|
-
getConfig: configs.semanticVariables,
|
|
56
|
-
dimensions: ["semantic"],
|
|
57
|
-
log: ({ permutation: { theme } }) => `${theme}.css`,
|
|
58
|
-
build: async (sdConfigs, { outPath, dry }) => {
|
|
59
|
-
await Promise.all(
|
|
60
|
-
sdConfigs.map(async ({ permutation: { theme } }) => {
|
|
61
|
-
return makeEntryFile({ theme, outPath, buildPath: path.resolve(outPath, theme), dry });
|
|
62
|
-
})
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
1193
|
+
semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] }
|
|
1194
|
+
// storefront: {
|
|
1195
|
+
// name: 'Storefront preview tokens',
|
|
1196
|
+
// getConfig: configs.typescriptTokens,
|
|
1197
|
+
// dimensions: ['color-scheme'],
|
|
1198
|
+
// options: { outPath: path.resolve('../../apps/storefront/tokens') },
|
|
1199
|
+
// enabled: () => buildOptions?.preview ?? false,
|
|
1200
|
+
// },
|
|
66
1201
|
};
|
|
67
|
-
async function
|
|
68
|
-
const {
|
|
69
|
-
const
|
|
70
|
-
const
|
|
1202
|
+
async function processPlatform(options) {
|
|
1203
|
+
const { process, $themes } = options;
|
|
1204
|
+
const platform = "css";
|
|
1205
|
+
const tokenSets = process === "format" ? options.tokenSets : void 0;
|
|
1206
|
+
const tokensDir = process === "build" ? options.tokensDir : void 0;
|
|
71
1207
|
buildOptions = options;
|
|
72
|
-
const $themes =
|
|
73
|
-
const
|
|
1208
|
+
const processed$themes = $themes.map(processThemeObject).filter((theme) => R13.not(theme.group === "size" && theme.name !== "medium"));
|
|
1209
|
+
const customColors = getCustomColors(processed$themes);
|
|
74
1210
|
if (!buildOptions.rootColor) {
|
|
75
|
-
const firstMainColor =
|
|
76
|
-
buildOptions.rootColor = firstMainColor
|
|
77
|
-
console.log(`Using first main color; ${
|
|
1211
|
+
const firstMainColor = R13.head(customColors);
|
|
1212
|
+
buildOptions.rootColor = firstMainColor;
|
|
1213
|
+
console.log(`Using first main color; ${chalk4.blue(firstMainColor)}, as ${chalk4.green(`":root"`)} color`);
|
|
78
1214
|
}
|
|
79
|
-
const buildAndSdConfigs =
|
|
80
|
-
const sdConfigs = getConfigsForThemeDimensions(buildConfig.getConfig,
|
|
81
|
-
outPath: targetDir,
|
|
1215
|
+
const buildAndSdConfigs = R13.map((buildConfig) => {
|
|
1216
|
+
const sdConfigs = getConfigsForThemeDimensions(buildConfig.getConfig, processed$themes, buildConfig.dimensions, {
|
|
82
1217
|
tokensDir,
|
|
83
|
-
|
|
1218
|
+
tokenSets
|
|
84
1219
|
});
|
|
85
1220
|
const unknownConfigs = buildConfig.dimensions.map(
|
|
86
1221
|
(dimension) => sdConfigs.filter((x) => x.permutation[dimension] === "unknown")
|
|
@@ -95,33 +1230,44 @@ async function buildTokens(options) {
|
|
|
95
1230
|
sdConfigs
|
|
96
1231
|
};
|
|
97
1232
|
}, buildConfigs);
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
1233
|
+
const processedBuilds = {
|
|
1234
|
+
"color-scheme": [initResult],
|
|
1235
|
+
"main-color": [initResult],
|
|
1236
|
+
"support-color": [initResult],
|
|
1237
|
+
"neutral-color": [initResult],
|
|
1238
|
+
"success-color": [initResult],
|
|
1239
|
+
"danger-color": [initResult],
|
|
1240
|
+
"warning-color": [initResult],
|
|
1241
|
+
"info-color": [initResult],
|
|
1242
|
+
semantic: [initResult],
|
|
1243
|
+
typography: [initResult],
|
|
1244
|
+
types: [initResult]
|
|
1245
|
+
};
|
|
101
1246
|
try {
|
|
102
|
-
for (const [
|
|
1247
|
+
for (const [buildName, { buildConfig, sdConfigs }] of R13.toPairs(buildAndSdConfigs)) {
|
|
103
1248
|
if (!(buildConfig.enabled?.() ?? true)) {
|
|
104
1249
|
continue;
|
|
105
1250
|
}
|
|
106
1251
|
if (sdConfigs.length > 0) {
|
|
107
1252
|
console.log(`
|
|
108
|
-
\u{1F371} Building ${
|
|
109
|
-
|
|
110
|
-
await buildConfig.build(sdConfigs, { outPath: targetDir, tokensDir, ...buildConfig.options, dry });
|
|
111
|
-
}
|
|
112
|
-
await Promise.all(
|
|
1253
|
+
\u{1F371} Building ${chalk4.green(buildConfig.name ?? buildName)}`);
|
|
1254
|
+
const results = await Promise.all(
|
|
113
1255
|
sdConfigs.map(async (sdConfig) => {
|
|
114
1256
|
const { config, permutation } = sdConfig;
|
|
115
1257
|
const modes = ["theme", ...buildConfig.dimensions];
|
|
116
1258
|
const modeMessage = modes.map((x) => permutation[x]).join(" - ");
|
|
117
|
-
const logMessage =
|
|
1259
|
+
const logMessage = R13.isNil(buildConfig.log) ? modeMessage : buildConfig?.log(sdConfig);
|
|
118
1260
|
console.log(logMessage);
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
1261
|
+
const sdOptions = { cache: true };
|
|
1262
|
+
const sdExtended = await sd.extend(config);
|
|
1263
|
+
const result = {
|
|
1264
|
+
permutation,
|
|
1265
|
+
formatted: await sdExtended.formatPlatform(platform, sdOptions)
|
|
1266
|
+
};
|
|
1267
|
+
return Promise.resolve(result);
|
|
123
1268
|
})
|
|
124
1269
|
);
|
|
1270
|
+
processedBuilds[buildName] = results;
|
|
125
1271
|
}
|
|
126
1272
|
}
|
|
127
1273
|
} catch (err) {
|
|
@@ -130,28 +1276,80 @@ async function buildTokens(options) {
|
|
|
130
1276
|
}
|
|
131
1277
|
throw err;
|
|
132
1278
|
}
|
|
133
|
-
await writeColorTypeDeclaration($themes, targetDir, dry);
|
|
134
|
-
}
|
|
135
|
-
async function writeColorTypeDeclaration($themes, outPath, dry) {
|
|
136
1279
|
const colorsFileName = "colors.d.ts";
|
|
1280
|
+
const reactColorTypes = await createColorTypeDeclaration(customColors);
|
|
1281
|
+
processedBuilds.types = [
|
|
1282
|
+
{
|
|
1283
|
+
...initResult,
|
|
1284
|
+
formatted: [{ output: reactColorTypes, destination: colorsFileName }]
|
|
1285
|
+
}
|
|
1286
|
+
];
|
|
1287
|
+
return processedBuilds;
|
|
1288
|
+
}
|
|
1289
|
+
async function createColorTypeDeclaration(colors) {
|
|
137
1290
|
console.log(`
|
|
138
|
-
\u{1F371} Building ${
|
|
139
|
-
console.log(colorsFileName);
|
|
140
|
-
const mainAndSupportColors = $themes.filter(
|
|
141
|
-
(x) => x.group && [colorCategories.main, colorCategories.support].map((c) => `${c}-color`).includes(x.group)
|
|
142
|
-
).map((x) => x.name);
|
|
1291
|
+
\u{1F371} Building ${chalk4.green("type declarations")}`);
|
|
143
1292
|
const typeDeclaration = `
|
|
144
1293
|
import type {} from '@digdir/designsystemet-react/colors';
|
|
145
1294
|
|
|
146
1295
|
declare module '@digdir/designsystemet-react/colors' {
|
|
147
1296
|
export interface MainAndSupportColors {
|
|
148
|
-
${
|
|
1297
|
+
${colors.map((color) => ` ${color}: never;`).join("\n")}
|
|
149
1298
|
}
|
|
150
1299
|
}
|
|
151
1300
|
`.trimStart();
|
|
152
|
-
|
|
1301
|
+
return typeDeclaration;
|
|
153
1302
|
}
|
|
1303
|
+
|
|
1304
|
+
// src/tokens/build.ts
|
|
1305
|
+
async function write(files, outDir, dry) {
|
|
1306
|
+
for (const { destination, output } of files) {
|
|
1307
|
+
if (destination) {
|
|
1308
|
+
const filePath = path.join(outDir, destination);
|
|
1309
|
+
const fileDir = path.dirname(filePath);
|
|
1310
|
+
console.log(destination);
|
|
1311
|
+
await mkdir(fileDir, dry);
|
|
1312
|
+
await writeFile(filePath, output, dry);
|
|
1313
|
+
}
|
|
1314
|
+
}
|
|
1315
|
+
}
|
|
1316
|
+
var buildTokens = async (options) => {
|
|
1317
|
+
const outDir = path.resolve(options.outDir);
|
|
1318
|
+
const tokensDir = path.resolve(options.tokensDir);
|
|
1319
|
+
const $themes = JSON.parse(await readFile(`${tokensDir}/$themes.json`));
|
|
1320
|
+
let $designsystemet;
|
|
1321
|
+
try {
|
|
1322
|
+
const $designsystemetContent = await readFile(`${tokensDir}/$designsystemet.json`);
|
|
1323
|
+
$designsystemet = JSON.parse($designsystemetContent);
|
|
1324
|
+
} catch (error) {
|
|
1325
|
+
}
|
|
1326
|
+
console.log(`
|
|
1327
|
+
\u{1F3D7}\uFE0F Start building tokens in ${chalk5.green(tokensDir)}`);
|
|
1328
|
+
const processedBuilds = await processPlatform({
|
|
1329
|
+
...options,
|
|
1330
|
+
outDir,
|
|
1331
|
+
tokensDir,
|
|
1332
|
+
process: "build",
|
|
1333
|
+
$themes
|
|
1334
|
+
});
|
|
1335
|
+
if (options.clean) {
|
|
1336
|
+
await cleanDir(outDir, options.dry);
|
|
1337
|
+
}
|
|
1338
|
+
console.log(`
|
|
1339
|
+
\u{1F4BE} Writing build to ${chalk5.green(outDir)}`);
|
|
1340
|
+
for (const { formatted } of processedBuilds.types) {
|
|
1341
|
+
await write(formatted, outDir, options.dry);
|
|
1342
|
+
}
|
|
1343
|
+
const fileHeader2 = R14.join("")([
|
|
1344
|
+
defaultFileHeader,
|
|
1345
|
+
$designsystemet ? `
|
|
1346
|
+
design-tokens: v${$designsystemet.version} ` : ""
|
|
1347
|
+
]);
|
|
1348
|
+
await write(createThemeCSSFiles({ processedBuilds, fileHeader: fileHeader2 }), outDir, options.dry);
|
|
1349
|
+
console.log(`
|
|
1350
|
+
\u2705 Finished building tokens!`);
|
|
1351
|
+
return processedBuilds;
|
|
1352
|
+
};
|
|
154
1353
|
export {
|
|
155
|
-
buildOptions,
|
|
156
1354
|
buildTokens
|
|
157
1355
|
};
|