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