@digdir/designsystemet 1.0.8 → 1.1.1
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/config.d.ts +3 -3
- package/dist/bin/config.d.ts.map +1 -1
- package/dist/bin/config.js +45 -45
- package/dist/bin/designsystemet.js +827 -748
- package/dist/config.schema.json +4 -4
- package/dist/src/colors/index.d.ts +2 -2
- package/dist/src/colors/index.d.ts.map +1 -1
- package/dist/src/colors/index.js +143 -143
- package/dist/src/colors/theme.d.ts +1 -2
- package/dist/src/colors/theme.d.ts.map +1 -1
- package/dist/src/config.d.ts +6 -21
- package/dist/src/config.d.ts.map +1 -1
- package/dist/src/config.js +43 -40
- package/dist/src/index.js +418 -430
- package/dist/src/scripts/createJsonSchema.js +23 -24
- package/dist/src/scripts/update-template.d.ts.map +1 -1
- package/dist/src/tokens/build.d.ts +1 -1
- package/dist/src/tokens/build.d.ts.map +1 -1
- package/dist/src/tokens/build.js +359 -280
- package/dist/src/tokens/create/generators/$designsystemet.js +16 -15
- package/dist/src/tokens/create/generators/color.js +21 -21
- package/dist/src/tokens/create/write.js +17 -16
- package/dist/src/tokens/create.d.ts +1 -0
- package/dist/src/tokens/create.d.ts.map +1 -1
- package/dist/src/tokens/create.js +22 -21
- package/dist/src/tokens/format.d.ts.map +1 -1
- package/dist/src/tokens/format.js +931 -944
- package/dist/src/tokens/index.d.ts +2 -2
- package/dist/src/tokens/index.d.ts.map +1 -1
- package/dist/src/tokens/index.js +295 -307
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/color.js +5 -5
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/semantic.js +5 -5
- package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/storefront.js +1 -1
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -1
- package/dist/src/tokens/process/configs/typography.js +5 -5
- package/dist/src/tokens/process/configs.d.ts.map +1 -1
- package/dist/src/tokens/process/configs.js +5 -5
- package/dist/src/tokens/process/formats/css/color.js +2 -2
- package/dist/src/tokens/process/formats/css/semantic.js +2 -2
- package/dist/src/tokens/process/formats/css/typography.js +1 -1
- package/dist/src/tokens/process/formats/css.js +5 -5
- package/dist/src/tokens/process/formats/js-tokens.js +1 -1
- package/dist/src/tokens/process/output/declarations.d.ts +4 -0
- package/dist/src/tokens/process/output/declarations.d.ts.map +1 -0
- package/dist/src/tokens/process/output/declarations.js +860 -0
- package/dist/src/tokens/process/output/tailwind.d.ts +3 -0
- package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
- package/dist/src/tokens/process/output/tailwind.js +59 -0
- package/dist/src/tokens/process/{theme.d.ts → output/theme.d.ts} +2 -2
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
- package/dist/src/tokens/process/{theme.js → output/theme.js} +20 -19
- package/dist/src/tokens/process/platform.d.ts +8 -4
- package/dist/src/tokens/process/platform.d.ts.map +1 -1
- package/dist/src/tokens/process/platform.js +27 -56
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -1
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +12 -5
- package/dist/src/tokens/types.d.ts +1 -1
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/tokens/utils.d.ts.map +1 -1
- package/package.json +16 -15
- package/dist/src/tokens/process/theme.d.ts.map +0 -1
|
@@ -2,39 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
// bin/designsystemet.ts
|
|
4
4
|
import { Argument, createCommand, program } from "@commander-js/extra-typings";
|
|
5
|
-
import
|
|
5
|
+
import chalk11 from "chalk";
|
|
6
6
|
import * as R26 from "ramda";
|
|
7
7
|
|
|
8
|
-
// src/colors/utils.ts
|
|
9
|
-
import chroma from "chroma-js";
|
|
10
|
-
import Colorjs from "colorjs.io";
|
|
11
|
-
import { Hsluv } from "hsluv";
|
|
12
|
-
var getLuminanceFromLightness = (lightness) => {
|
|
13
|
-
const conv = new Hsluv();
|
|
14
|
-
conv.hsluv_l = lightness;
|
|
15
|
-
conv.hsluvToHex();
|
|
16
|
-
return chroma(conv.hex).luminance();
|
|
17
|
-
};
|
|
18
|
-
var getLightnessFromHex = (hex) => {
|
|
19
|
-
const conv = new Hsluv();
|
|
20
|
-
conv.hex = hex;
|
|
21
|
-
conv.hexToHsluv();
|
|
22
|
-
return conv.hsluv_l;
|
|
23
|
-
};
|
|
24
|
-
var convertToHex = (color) => {
|
|
25
|
-
if (!color) {
|
|
26
|
-
return "#000000";
|
|
27
|
-
}
|
|
28
|
-
if (/^#[0-9A-Fa-f]{6}$/.test(color)) {
|
|
29
|
-
return color;
|
|
30
|
-
}
|
|
31
|
-
return chroma(color).hex();
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
// src/colors/theme.ts
|
|
35
|
-
import chroma2 from "chroma-js";
|
|
36
|
-
import * as R2 from "ramda";
|
|
37
|
-
|
|
38
8
|
// src/colors/colorMetadata.ts
|
|
39
9
|
import * as R from "ramda";
|
|
40
10
|
var baseColors = {
|
|
@@ -288,6 +258,36 @@ var colorMetadata = {
|
|
|
288
258
|
};
|
|
289
259
|
var colorMetadataByNumber = R.indexBy((metadata) => metadata.number, Object.values(colorMetadata));
|
|
290
260
|
|
|
261
|
+
// src/colors/theme.ts
|
|
262
|
+
import chroma2 from "chroma-js";
|
|
263
|
+
import * as R2 from "ramda";
|
|
264
|
+
|
|
265
|
+
// src/colors/utils.ts
|
|
266
|
+
import chroma from "chroma-js";
|
|
267
|
+
import Colorjs from "colorjs.io";
|
|
268
|
+
import { Hsluv } from "hsluv";
|
|
269
|
+
var getLuminanceFromLightness = (lightness) => {
|
|
270
|
+
const conv = new Hsluv();
|
|
271
|
+
conv.hsluv_l = lightness;
|
|
272
|
+
conv.hsluvToHex();
|
|
273
|
+
return chroma(conv.hex).luminance();
|
|
274
|
+
};
|
|
275
|
+
var getLightnessFromHex = (hex) => {
|
|
276
|
+
const conv = new Hsluv();
|
|
277
|
+
conv.hex = hex;
|
|
278
|
+
conv.hexToHsluv();
|
|
279
|
+
return conv.hsluv_l;
|
|
280
|
+
};
|
|
281
|
+
var convertToHex = (color) => {
|
|
282
|
+
if (!color) {
|
|
283
|
+
return "#000000";
|
|
284
|
+
}
|
|
285
|
+
if (/^#[0-9A-Fa-f]{6}$/.test(color)) {
|
|
286
|
+
return color;
|
|
287
|
+
}
|
|
288
|
+
return chroma(color).hex();
|
|
289
|
+
};
|
|
290
|
+
|
|
291
291
|
// src/colors/theme.ts
|
|
292
292
|
var RESERVED_COLORS = [
|
|
293
293
|
"neutral",
|
|
@@ -861,180 +861,15 @@ var migrations_default = {
|
|
|
861
861
|
|
|
862
862
|
// src/tokens/build.ts
|
|
863
863
|
import path from "path";
|
|
864
|
-
import
|
|
864
|
+
import chalk7 from "chalk";
|
|
865
865
|
import * as R18 from "ramda";
|
|
866
866
|
|
|
867
|
-
// src/tokens/process/
|
|
868
|
-
import
|
|
869
|
-
import chalk3 from "chalk";
|
|
870
|
-
|
|
871
|
-
// package.json
|
|
872
|
-
var package_default = {
|
|
873
|
-
name: "@digdir/designsystemet",
|
|
874
|
-
version: "1.0.8",
|
|
875
|
-
description: "CLI for Designsystemet",
|
|
876
|
-
author: "Designsystemet team",
|
|
877
|
-
engines: {
|
|
878
|
-
node: ">=22.16.0"
|
|
879
|
-
},
|
|
880
|
-
repository: {
|
|
881
|
-
type: "git",
|
|
882
|
-
url: "git+https://github.com/digdir/designsystemet.git"
|
|
883
|
-
},
|
|
884
|
-
homepage: "https://github.com/digdir/designsystemet/tree/main/scripts/cli",
|
|
885
|
-
license: "MIT",
|
|
886
|
-
type: "module",
|
|
887
|
-
main: "./dist/src/index.js",
|
|
888
|
-
files: [
|
|
889
|
-
"./dist/**",
|
|
890
|
-
"./configs/**"
|
|
891
|
-
],
|
|
892
|
-
bin: "dist/bin/designsystemet.js",
|
|
893
|
-
exports: {
|
|
894
|
-
".": {
|
|
895
|
-
import: "./dist/src/index.js"
|
|
896
|
-
},
|
|
897
|
-
"./color": {
|
|
898
|
-
import: "./dist/src/colors/index.js"
|
|
899
|
-
},
|
|
900
|
-
"./tokens": {
|
|
901
|
-
import: "./dist/src/tokens/index.js"
|
|
902
|
-
}
|
|
903
|
-
},
|
|
904
|
-
publishConfig: {
|
|
905
|
-
access: "public"
|
|
906
|
-
},
|
|
907
|
-
scripts: {
|
|
908
|
-
designsystemet: "tsx ./bin/designsystemet.ts",
|
|
909
|
-
"build:tokens": "pnpm run designsystemet tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
|
|
910
|
-
"build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
|
|
911
|
-
build: "tsup && pnpm build:types && pnpm build:json-schema",
|
|
912
|
-
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
913
|
-
"build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
|
|
914
|
-
types: "tsc --noEmit",
|
|
915
|
-
"test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
|
|
916
|
-
"test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
|
|
917
|
-
"test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
|
|
918
|
-
"test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
|
|
919
|
-
"test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
|
|
920
|
-
"test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
|
|
921
|
-
test: "pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
|
|
922
|
-
"digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
|
|
923
|
-
"update:template": "tsx ./src/scripts/update-template.ts",
|
|
924
|
-
"update:theme-digdir": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
|
|
925
|
-
verify: "pnpm test && pnpm update:template && pnpm update:theme-digdir && pnpm build:tokens"
|
|
926
|
-
},
|
|
927
|
-
dependencies: {
|
|
928
|
-
"@commander-js/extra-typings": "^13.1.0",
|
|
929
|
-
"@tokens-studio/sd-transforms": "1.3.0",
|
|
930
|
-
"apca-w3": "^0.1.9",
|
|
931
|
-
chalk: "^5.4.1",
|
|
932
|
-
"change-case": "^5.4.4",
|
|
933
|
-
"chroma-js": "^3.1.2",
|
|
934
|
-
"colorjs.io": "^0.6.0-alpha.1",
|
|
935
|
-
commander: "^13.1.0",
|
|
936
|
-
"fast-glob": "^3.3.3",
|
|
937
|
-
hsluv: "^1.0.1",
|
|
938
|
-
"object-hash": "^3.0.0",
|
|
939
|
-
postcss: "^8.5.3",
|
|
940
|
-
ramda: "^0.30.1",
|
|
941
|
-
"style-dictionary": "^4.4.0",
|
|
942
|
-
zod: "^3.25.30",
|
|
943
|
-
"zod-validation-error": "^3.4.1"
|
|
944
|
-
},
|
|
945
|
-
devDependencies: {
|
|
946
|
-
"@tokens-studio/types": "0.5.2",
|
|
947
|
-
"@types/apca-w3": "^0.1.3",
|
|
948
|
-
"@types/chroma-js": "^3.1.1",
|
|
949
|
-
"@types/fs-extra": "^11.0.4",
|
|
950
|
-
"@types/glob": "^8.1.0",
|
|
951
|
-
"@types/jscodeshift": "^0.12.0",
|
|
952
|
-
"@types/node": "^22.15.21",
|
|
953
|
-
"@types/object-hash": "^3.0.6",
|
|
954
|
-
"@types/ramda": "^0.30.2",
|
|
955
|
-
"fs-extra": "^11.3.0",
|
|
956
|
-
"ts-toolbelt": "^9.6.0",
|
|
957
|
-
tslib: "^2.8.1",
|
|
958
|
-
tsup: "^8.5.0",
|
|
959
|
-
tsx: "^4.19.4",
|
|
960
|
-
typescript: "^5.8.3"
|
|
961
|
-
}
|
|
962
|
-
};
|
|
963
|
-
|
|
964
|
-
// src/tokens/process/theme.ts
|
|
965
|
-
var defaultFileHeader = `build: v${package_default.version}`;
|
|
966
|
-
var createThemeCSSFiles = ({
|
|
967
|
-
processedBuilds,
|
|
968
|
-
fileHeader: fileHeader2 = defaultFileHeader
|
|
969
|
-
}) => {
|
|
970
|
-
const groupedByTheme = {};
|
|
971
|
-
for (const [_, buildResults] of Object.entries(R5.dissoc("types", processedBuilds))) {
|
|
972
|
-
for (const buildResult of buildResults) {
|
|
973
|
-
const themeName = buildResult.permutation.theme;
|
|
974
|
-
const newOutputs = buildResult.formatted;
|
|
975
|
-
if (R5.isNotEmpty(newOutputs)) {
|
|
976
|
-
const currentOutputs = groupedByTheme[themeName] ?? [];
|
|
977
|
-
groupedByTheme[themeName] = R5.concat(currentOutputs, newOutputs);
|
|
978
|
-
}
|
|
979
|
-
}
|
|
980
|
-
}
|
|
981
|
-
const sortOrder = [
|
|
982
|
-
"color-scheme/light",
|
|
983
|
-
"typography/secondary",
|
|
984
|
-
"semantic",
|
|
985
|
-
"color-scheme/dark",
|
|
986
|
-
"color-scheme/contrast",
|
|
987
|
-
"typography/primary",
|
|
988
|
-
"color/"
|
|
989
|
-
];
|
|
990
|
-
const sortByDefinedOrder = R5.sortBy((file) => {
|
|
991
|
-
const filePath = file.destination || "";
|
|
992
|
-
const sortIndex = sortOrder.findIndex((sortElement) => {
|
|
993
|
-
if (sortElement.endsWith("/")) {
|
|
994
|
-
return filePath.includes(sortElement);
|
|
995
|
-
}
|
|
996
|
-
return filePath.includes(`${sortElement}.css`);
|
|
997
|
-
});
|
|
998
|
-
if (sortIndex === -1) {
|
|
999
|
-
console.error(
|
|
1000
|
-
chalk3.yellow("WARNING: CSS section does not have a defined sort order:", filePath.replace(".css", ""))
|
|
1001
|
-
);
|
|
1002
|
-
console.log(
|
|
1003
|
-
chalk3.dim(
|
|
1004
|
-
`
|
|
1005
|
-
The section will currently be added to the end of the entry file, but the exact
|
|
1006
|
-
order may change due to nondeterminism.`.trim()
|
|
1007
|
-
)
|
|
1008
|
-
);
|
|
1009
|
-
return Infinity;
|
|
1010
|
-
}
|
|
1011
|
-
return sortIndex;
|
|
1012
|
-
});
|
|
1013
|
-
const header = `@charset "UTF-8";
|
|
1014
|
-
/*
|
|
1015
|
-
${fileHeader2}
|
|
1016
|
-
*/
|
|
1017
|
-
|
|
1018
|
-
`;
|
|
1019
|
-
const sortAlphabetically = R5.sort(R5.ascend((x) => x.destination || ""));
|
|
1020
|
-
const pickOutputs = R5.map(R5.view(R5.lensProp("output")));
|
|
1021
|
-
const themeCSSFile = R5.pipe(
|
|
1022
|
-
sortAlphabetically,
|
|
1023
|
-
sortByDefinedOrder,
|
|
1024
|
-
pickOutputs,
|
|
1025
|
-
R5.join("\n"),
|
|
1026
|
-
(content) => header + content
|
|
1027
|
-
);
|
|
1028
|
-
const themeCSSFiles = Object.entries(groupedByTheme).map(([theme, files]) => ({
|
|
1029
|
-
destination: `${theme}.css`,
|
|
1030
|
-
output: themeCSSFile(files)
|
|
1031
|
-
}));
|
|
1032
|
-
return themeCSSFiles;
|
|
1033
|
-
};
|
|
867
|
+
// src/tokens/process/output/declarations.ts
|
|
868
|
+
import chalk5 from "chalk";
|
|
1034
869
|
|
|
1035
870
|
// src/tokens/process/platform.ts
|
|
1036
|
-
import
|
|
1037
|
-
import * as
|
|
871
|
+
import chalk4 from "chalk";
|
|
872
|
+
import * as R16 from "ramda";
|
|
1038
873
|
import StyleDictionary2 from "style-dictionary";
|
|
1039
874
|
|
|
1040
875
|
// src/tokens/types.ts
|
|
@@ -1045,30 +880,30 @@ var colorCategories = {
|
|
|
1045
880
|
|
|
1046
881
|
// src/tokens/process/configs.ts
|
|
1047
882
|
import { register } from "@tokens-studio/sd-transforms";
|
|
1048
|
-
import * as
|
|
883
|
+
import * as R15 from "ramda";
|
|
1049
884
|
import StyleDictionary from "style-dictionary";
|
|
1050
885
|
|
|
1051
886
|
// src/tokens/utils.ts
|
|
1052
|
-
import * as
|
|
1053
|
-
var mapToLowerCase =
|
|
1054
|
-
var hasAnyTruth =
|
|
887
|
+
import * as R5 from "ramda";
|
|
888
|
+
var mapToLowerCase = R5.map(R5.toLower);
|
|
889
|
+
var hasAnyTruth = R5.any(R5.equals(true));
|
|
1055
890
|
var getType = (token) => (token.$type ?? token.type) || "";
|
|
1056
891
|
var getValue = (token) => token.$value ?? token.value;
|
|
1057
|
-
var typeEquals =
|
|
892
|
+
var typeEquals = R5.curry(
|
|
1058
893
|
(types, token) => {
|
|
1059
|
-
if (
|
|
894
|
+
if (R5.isNil(token)) {
|
|
1060
895
|
return false;
|
|
1061
896
|
}
|
|
1062
|
-
return
|
|
897
|
+
return R5.includes(R5.toLower(getType(token)), R5.map(R5.toLower, Array.isArray(types) ? types : [types]));
|
|
1063
898
|
}
|
|
1064
899
|
);
|
|
1065
|
-
var pathStartsWithOneOf =
|
|
900
|
+
var pathStartsWithOneOf = R5.curry(
|
|
1066
901
|
(paths, token) => {
|
|
1067
|
-
if (
|
|
902
|
+
if (R5.isNil(token)) {
|
|
1068
903
|
return false;
|
|
1069
904
|
}
|
|
1070
905
|
const tokenPath = mapToLowerCase(token.path);
|
|
1071
|
-
const matchPathsStartingWith =
|
|
906
|
+
const matchPathsStartingWith = R5.map((path5) => R5.startsWith([path5], tokenPath), mapToLowerCase(paths));
|
|
1072
907
|
return hasAnyTruth(matchPathsStartingWith);
|
|
1073
908
|
}
|
|
1074
909
|
);
|
|
@@ -1076,7 +911,7 @@ function isSemanticToken(token) {
|
|
|
1076
911
|
return token.filePath.includes("semantic/");
|
|
1077
912
|
}
|
|
1078
913
|
function isSemanticColorToken(token, color) {
|
|
1079
|
-
return token.filePath.includes("semantic/") &&
|
|
914
|
+
return token.filePath.includes("semantic/") && R5.startsWith(["color", color], token.path);
|
|
1080
915
|
}
|
|
1081
916
|
function isGlobalColorToken(token) {
|
|
1082
917
|
return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
|
|
@@ -1087,7 +922,7 @@ function isColorCategoryToken(token, category) {
|
|
|
1087
922
|
(colorCategory2) => isColorCategoryToken(token, colorCategory2)
|
|
1088
923
|
);
|
|
1089
924
|
}
|
|
1090
|
-
return
|
|
925
|
+
return R5.startsWith(["color", category], token.path);
|
|
1091
926
|
}
|
|
1092
927
|
var isDigit = (s) => /^\d+$/.test(s);
|
|
1093
928
|
function traverseObj(obj, fn) {
|
|
@@ -1103,7 +938,7 @@ function traverseObj(obj, fn) {
|
|
|
1103
938
|
return obj;
|
|
1104
939
|
}
|
|
1105
940
|
function inlineTokens(shouldInline, tokens) {
|
|
1106
|
-
const [inlineableTokens, otherTokens] =
|
|
941
|
+
const [inlineableTokens, otherTokens] = R5.partition(shouldInline, tokens);
|
|
1107
942
|
return otherTokens.map((token) => {
|
|
1108
943
|
let transformed = getValue(token.original);
|
|
1109
944
|
for (const ref of inlineableTokens) {
|
|
@@ -1112,16 +947,16 @@ function inlineTokens(shouldInline, tokens) {
|
|
|
1112
947
|
transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
|
|
1113
948
|
}
|
|
1114
949
|
}
|
|
1115
|
-
const tokenWithInlinedRefs =
|
|
950
|
+
const tokenWithInlinedRefs = R5.set(R5.lensPath(["original", "$value"]), transformed, token);
|
|
1116
951
|
return tokenWithInlinedRefs;
|
|
1117
952
|
});
|
|
1118
953
|
}
|
|
1119
954
|
|
|
1120
955
|
// src/tokens/process/configs/color.ts
|
|
1121
|
-
import * as
|
|
956
|
+
import * as R10 from "ramda";
|
|
1122
957
|
|
|
1123
958
|
// src/tokens/process/formats/css/color.ts
|
|
1124
|
-
import * as
|
|
959
|
+
import * as R6 from "ramda";
|
|
1125
960
|
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
1126
961
|
var prefersColorScheme = (colorScheme2, content) => `
|
|
1127
962
|
@media (prefers-color-scheme: ${colorScheme2}) {
|
|
@@ -1130,7 +965,7 @@ var prefersColorScheme = (colorScheme2, content) => `
|
|
|
1130
965
|
`;
|
|
1131
966
|
var colorScheme = {
|
|
1132
967
|
name: "ds/css-colorscheme",
|
|
1133
|
-
format: async ({ dictionary,
|
|
968
|
+
format: async ({ dictionary, options, platform }) => {
|
|
1134
969
|
const { allTokens } = dictionary;
|
|
1135
970
|
const { outputReferences, usesDtcg } = options;
|
|
1136
971
|
const { selector, colorScheme: colorScheme2, layer } = platform;
|
|
@@ -1145,8 +980,8 @@ var colorScheme = {
|
|
|
1145
980
|
color-scheme: ${colorScheme_};
|
|
1146
981
|
` : "";
|
|
1147
982
|
const filteredAllTokens = allTokens.filter(
|
|
1148
|
-
|
|
1149
|
-
|
|
983
|
+
R6.allPass([
|
|
984
|
+
R6.anyPass([
|
|
1150
985
|
// Include semantic tokens in the output
|
|
1151
986
|
isSemanticToken,
|
|
1152
987
|
// Include global color tokens
|
|
@@ -1162,7 +997,7 @@ ${formattedTokens}
|
|
|
1162
997
|
${colorSchemeProperty}}
|
|
1163
998
|
`;
|
|
1164
999
|
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
1165
|
-
const body =
|
|
1000
|
+
const body = R6.isNotNil(layer) ? `@layer ${layer} {
|
|
1166
1001
|
${selector} ${content} ${autoSelectorContent}
|
|
1167
1002
|
}
|
|
1168
1003
|
` : `${selector} ${content} ${autoSelectorContent}
|
|
@@ -1172,10 +1007,10 @@ ${selector} ${content} ${autoSelectorContent}
|
|
|
1172
1007
|
};
|
|
1173
1008
|
var colorCategory = {
|
|
1174
1009
|
name: "ds/css-colorcategory",
|
|
1175
|
-
format: async ({ dictionary,
|
|
1010
|
+
format: async ({ dictionary, options, platform }) => {
|
|
1176
1011
|
const { outputReferences, usesDtcg } = options;
|
|
1177
1012
|
const { selector, layer } = platform;
|
|
1178
|
-
const format =
|
|
1013
|
+
const format = R6.compose(
|
|
1179
1014
|
createPropertyFormatter({
|
|
1180
1015
|
outputReferences,
|
|
1181
1016
|
dictionary,
|
|
@@ -1196,7 +1031,7 @@ var colorCategory = {
|
|
|
1196
1031
|
${formattedTokens}
|
|
1197
1032
|
}
|
|
1198
1033
|
`;
|
|
1199
|
-
const body =
|
|
1034
|
+
const body = R6.isNotNil(layer) ? `@layer ${layer} {
|
|
1200
1035
|
${selector} ${content}
|
|
1201
1036
|
}
|
|
1202
1037
|
` : `${selector} ${content}
|
|
@@ -1206,16 +1041,16 @@ ${selector} ${content}
|
|
|
1206
1041
|
};
|
|
1207
1042
|
|
|
1208
1043
|
// src/tokens/process/formats/css/semantic.ts
|
|
1209
|
-
import * as
|
|
1044
|
+
import * as R7 from "ramda";
|
|
1210
1045
|
import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
|
|
1211
1046
|
var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
1212
1047
|
var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
1213
1048
|
var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
1214
|
-
var isInlineTokens =
|
|
1049
|
+
var isInlineTokens = R7.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
|
|
1215
1050
|
var overrideSizingFormula = (format, token) => {
|
|
1216
1051
|
const [name, value] = format(token).split(":");
|
|
1217
1052
|
const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
|
|
1218
|
-
const round = `round(down, ${calc},
|
|
1053
|
+
const round = `round(down, ${calc}, 1px)`;
|
|
1219
1054
|
return {
|
|
1220
1055
|
name,
|
|
1221
1056
|
round,
|
|
@@ -1223,7 +1058,7 @@ var overrideSizingFormula = (format, token) => {
|
|
|
1223
1058
|
};
|
|
1224
1059
|
};
|
|
1225
1060
|
var formatSizingTokens = (format, tokens) => {
|
|
1226
|
-
const { round, calc } =
|
|
1061
|
+
const { round, calc } = R7.reduce(
|
|
1227
1062
|
(acc, token) => {
|
|
1228
1063
|
const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
|
|
1229
1064
|
return {
|
|
@@ -1243,7 +1078,7 @@ ${round.join("\n")}
|
|
|
1243
1078
|
};
|
|
1244
1079
|
var semantic = {
|
|
1245
1080
|
name: "ds/css-semantic",
|
|
1246
|
-
format: async ({ dictionary,
|
|
1081
|
+
format: async ({ dictionary, options, platform }) => {
|
|
1247
1082
|
const { outputReferences, usesDtcg } = options;
|
|
1248
1083
|
const { selector, layer } = platform;
|
|
1249
1084
|
const format = createPropertyFormatter2({
|
|
@@ -1253,17 +1088,17 @@ var semantic = {
|
|
|
1253
1088
|
usesDtcg
|
|
1254
1089
|
});
|
|
1255
1090
|
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
1256
|
-
const filteredTokens =
|
|
1257
|
-
const [sizingTokens, restTokens] =
|
|
1091
|
+
const filteredTokens = R7.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
|
|
1092
|
+
const [sizingTokens, restTokens] = R7.partition(
|
|
1258
1093
|
(t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
|
|
1259
1094
|
filteredTokens
|
|
1260
1095
|
);
|
|
1261
|
-
const formattedTokens = [
|
|
1096
|
+
const formattedTokens = [R7.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
|
|
1262
1097
|
const content = `{
|
|
1263
1098
|
${formattedTokens.join("\n")}
|
|
1264
1099
|
}
|
|
1265
1100
|
`;
|
|
1266
|
-
const body =
|
|
1101
|
+
const body = R7.isNotNil(layer) ? `@layer ${layer} {
|
|
1267
1102
|
${selector} ${content}
|
|
1268
1103
|
}
|
|
1269
1104
|
` : `${selector} ${content}
|
|
@@ -1273,15 +1108,15 @@ ${selector} ${content}
|
|
|
1273
1108
|
};
|
|
1274
1109
|
|
|
1275
1110
|
// src/tokens/process/formats/css/typography.ts
|
|
1276
|
-
import * as
|
|
1111
|
+
import * as R8 from "ramda";
|
|
1277
1112
|
import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
|
|
1278
|
-
var typographyFontFamilyPredicate =
|
|
1279
|
-
|
|
1280
|
-
|
|
1113
|
+
var typographyFontFamilyPredicate = R8.allPass([
|
|
1114
|
+
R8.pathSatisfies(R8.includes("typography"), ["path"]),
|
|
1115
|
+
R8.pathSatisfies(R8.includes("fontFamily"), ["path"])
|
|
1281
1116
|
]);
|
|
1282
1117
|
var typography = {
|
|
1283
1118
|
name: "ds/css-typography",
|
|
1284
|
-
format: async ({ dictionary,
|
|
1119
|
+
format: async ({ dictionary, options, platform }) => {
|
|
1285
1120
|
const { outputReferences, usesDtcg } = options;
|
|
1286
1121
|
const { selector, layer } = platform;
|
|
1287
1122
|
const format = createPropertyFormatter3({
|
|
@@ -1290,12 +1125,12 @@ var typography = {
|
|
|
1290
1125
|
format: "css",
|
|
1291
1126
|
usesDtcg
|
|
1292
1127
|
});
|
|
1293
|
-
const filteredTokens =
|
|
1294
|
-
const formattedTokens =
|
|
1128
|
+
const filteredTokens = R8.reject(typographyFontFamilyPredicate, dictionary.allTokens);
|
|
1129
|
+
const formattedTokens = R8.pipe(R8.map(format), R8.join("\n"))(filteredTokens);
|
|
1295
1130
|
const content = selector ? `${selector} {
|
|
1296
1131
|
${formattedTokens}
|
|
1297
1132
|
}` : formattedTokens;
|
|
1298
|
-
const body =
|
|
1133
|
+
const body = R8.isNotNil(layer) ? `@layer ${layer} {
|
|
1299
1134
|
${content}
|
|
1300
1135
|
}` : content;
|
|
1301
1136
|
return body;
|
|
@@ -1312,8 +1147,8 @@ var formats = {
|
|
|
1312
1147
|
|
|
1313
1148
|
// src/tokens/process/transformers.ts
|
|
1314
1149
|
import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
|
|
1315
|
-
import * as
|
|
1316
|
-
var isPx =
|
|
1150
|
+
import * as R9 from "ramda";
|
|
1151
|
+
var isPx = R9.test(/\b\d+px\b/g);
|
|
1317
1152
|
var sizeRem = {
|
|
1318
1153
|
name: "ds/size/toRem",
|
|
1319
1154
|
type: "value",
|
|
@@ -1403,7 +1238,7 @@ var colorSchemeVariables = ({ "color-scheme": colorScheme2 = "light", theme }) =
|
|
|
1403
1238
|
{
|
|
1404
1239
|
destination: `color-scheme/${colorScheme2}.css`,
|
|
1405
1240
|
format: formats.colorScheme.name,
|
|
1406
|
-
filter: (token) => typeEquals("color", token) && !
|
|
1241
|
+
filter: (token) => typeEquals("color", token) && !R10.startsWith(["global"], token.path)
|
|
1407
1242
|
}
|
|
1408
1243
|
],
|
|
1409
1244
|
options: {
|
|
@@ -1454,7 +1289,7 @@ var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, .
|
|
|
1454
1289
|
};
|
|
1455
1290
|
|
|
1456
1291
|
// src/tokens/process/configs/semantic.ts
|
|
1457
|
-
import * as
|
|
1292
|
+
import * as R11 from "ramda";
|
|
1458
1293
|
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
1459
1294
|
var semanticVariables = ({ theme }) => {
|
|
1460
1295
|
const selector = `:root`;
|
|
@@ -1477,8 +1312,8 @@ var semanticVariables = ({ theme }) => {
|
|
|
1477
1312
|
destination: `semantic.css`,
|
|
1478
1313
|
format: formats.semantic.name,
|
|
1479
1314
|
filter: (token) => {
|
|
1480
|
-
const isUwantedToken =
|
|
1481
|
-
const isPrivateToken =
|
|
1315
|
+
const isUwantedToken = R11.anyPass([R11.includes("primitives/global")])(token.filePath);
|
|
1316
|
+
const isPrivateToken = R11.includes("_", token.path);
|
|
1482
1317
|
const unwantedPaths = pathStartsWithOneOf(["font-size", "line-height", "letter-spacing"], token);
|
|
1483
1318
|
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
1484
1319
|
const unwantedTokens = !(unwantedPaths || unwantedTypes || isPrivateToken || isUwantedToken);
|
|
@@ -1499,20 +1334,20 @@ var semanticVariables = ({ theme }) => {
|
|
|
1499
1334
|
};
|
|
1500
1335
|
|
|
1501
1336
|
// src/tokens/process/configs/storefront.ts
|
|
1502
|
-
import * as
|
|
1337
|
+
import * as R13 from "ramda";
|
|
1503
1338
|
import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
|
|
1504
1339
|
|
|
1505
1340
|
// src/tokens/process/formats/js-tokens.ts
|
|
1506
|
-
import * as
|
|
1341
|
+
import * as R12 from "ramda";
|
|
1507
1342
|
import { createPropertyFormatter as createPropertyFormatter4, fileHeader } from "style-dictionary/utils";
|
|
1508
|
-
var groupByType =
|
|
1509
|
-
var removeUnwatedTokens =
|
|
1510
|
-
|
|
1511
|
-
|
|
1343
|
+
var groupByType = R12.groupBy((token) => getType(token));
|
|
1344
|
+
var removeUnwatedTokens = R12.pipe(
|
|
1345
|
+
R12.reject((token) => isColorCategoryToken(token)),
|
|
1346
|
+
R12.reject((token) => R12.any((path5) => path5.startsWith("_"))(token.path))
|
|
1512
1347
|
);
|
|
1513
|
-
var dissocExtensions =
|
|
1514
|
-
var removeUnwatedProps =
|
|
1515
|
-
var toCssVarName =
|
|
1348
|
+
var dissocExtensions = R12.pipe(R12.dissoc("$extensions"), R12.dissocPath(["original", "$extensions"]));
|
|
1349
|
+
var removeUnwatedProps = R12.map((token) => dissocExtensions(token));
|
|
1350
|
+
var toCssVarName = R12.pipe(R12.split(":"), R12.head, R12.trim);
|
|
1516
1351
|
var jsTokens = {
|
|
1517
1352
|
name: "ds/js-tokens",
|
|
1518
1353
|
format: async ({ dictionary, file, options }) => {
|
|
@@ -1523,7 +1358,7 @@ var jsTokens = {
|
|
|
1523
1358
|
format: "css",
|
|
1524
1359
|
usesDtcg
|
|
1525
1360
|
});
|
|
1526
|
-
const formatTokens =
|
|
1361
|
+
const formatTokens = R12.map((token) => {
|
|
1527
1362
|
if (pathStartsWithOneOf(["size", "_size"], token)) {
|
|
1528
1363
|
const { calc, name } = overrideSizingFormula(format, token);
|
|
1529
1364
|
return {
|
|
@@ -1537,7 +1372,7 @@ var jsTokens = {
|
|
|
1537
1372
|
name: toCssVarName(format(token))
|
|
1538
1373
|
};
|
|
1539
1374
|
});
|
|
1540
|
-
const processTokens =
|
|
1375
|
+
const processTokens = R12.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
|
|
1541
1376
|
const tokens = processTokens(inlineTokens(isInlineTokens, dictionary.allTokens));
|
|
1542
1377
|
const content = Object.entries(tokens).map(
|
|
1543
1378
|
([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
|
|
@@ -1562,9 +1397,9 @@ var typescriptTokens = ({ "color-scheme": colorScheme2, theme }) => {
|
|
|
1562
1397
|
destination: `${colorScheme2}.ts`,
|
|
1563
1398
|
format: jsTokens.name,
|
|
1564
1399
|
filter: (token) => {
|
|
1565
|
-
if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !
|
|
1400
|
+
if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R13.includes("semantic", token.filePath))
|
|
1566
1401
|
return false;
|
|
1567
|
-
const isSemanticColor =
|
|
1402
|
+
const isSemanticColor = R13.includes("semantic", token.filePath) && typeEquals(["color"], token);
|
|
1568
1403
|
const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
|
|
1569
1404
|
return isSemanticColor || wantedTypes;
|
|
1570
1405
|
}
|
|
@@ -1793,19 +1628,19 @@ var TypographyValues;
|
|
|
1793
1628
|
})(TypographyValues || (TypographyValues = {}));
|
|
1794
1629
|
|
|
1795
1630
|
// src/tokens/process/utils/getMultidimensionalThemes.ts
|
|
1796
|
-
import
|
|
1631
|
+
import chalk3 from "chalk";
|
|
1797
1632
|
import { kebabCase } from "change-case";
|
|
1798
|
-
import * as
|
|
1633
|
+
import * as R14 from "ramda";
|
|
1799
1634
|
var getMultidimensionalThemes = (processed$themes, dimensions) => {
|
|
1800
1635
|
const verboseLogging = buildOptions?.verbose;
|
|
1801
1636
|
const grouped$themes = groupThemes(processed$themes);
|
|
1802
1637
|
const permutations = permutateThemes(grouped$themes);
|
|
1803
1638
|
const ALL_DEPENDENT_ON = ["theme"];
|
|
1804
|
-
const keys3 =
|
|
1639
|
+
const keys3 = R14.keys(grouped$themes);
|
|
1805
1640
|
const nonDependentKeys = keys3.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
|
|
1806
1641
|
if (verboseLogging) {
|
|
1807
|
-
console.log(
|
|
1808
|
-
console.log(
|
|
1642
|
+
console.log(chalk3.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
|
|
1643
|
+
console.log(chalk3.cyan(` (ignoring permutations for ${nonDependentKeys})`));
|
|
1809
1644
|
}
|
|
1810
1645
|
return permutations.filter((val) => {
|
|
1811
1646
|
const filters = nonDependentKeys.map((x) => val.permutation[x] === grouped$themes[x][0].name);
|
|
@@ -1841,7 +1676,7 @@ function groupThemes(themes) {
|
|
|
1841
1676
|
}
|
|
1842
1677
|
return groups;
|
|
1843
1678
|
}
|
|
1844
|
-
var hasUnknownProps =
|
|
1679
|
+
var hasUnknownProps = R14.pipe(R14.values, R14.none(R14.equals("unknown")), R14.not);
|
|
1845
1680
|
function permutateThemes(groups) {
|
|
1846
1681
|
const separator = "_";
|
|
1847
1682
|
const permutations = cartesian(Object.values(groups));
|
|
@@ -1851,8 +1686,8 @@ function permutateThemes(groups) {
|
|
|
1851
1686
|
const { group, name, selectedTokenSets } = theme;
|
|
1852
1687
|
let updatedPermutation = acc.permutation;
|
|
1853
1688
|
if (group) {
|
|
1854
|
-
const groupProp =
|
|
1855
|
-
updatedPermutation =
|
|
1689
|
+
const groupProp = R14.lensProp(group);
|
|
1690
|
+
updatedPermutation = R14.set(groupProp, name, updatedPermutation);
|
|
1856
1691
|
}
|
|
1857
1692
|
const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
|
|
1858
1693
|
const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
|
|
@@ -1898,6 +1733,12 @@ function filterTokenSets(tokensets) {
|
|
|
1898
1733
|
function cartesian(a) {
|
|
1899
1734
|
return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e].flat())));
|
|
1900
1735
|
}
|
|
1736
|
+
var getCustomColors = (processed$themes, colorGroups) => processed$themes.filter((x) => {
|
|
1737
|
+
if (!x.group) {
|
|
1738
|
+
return false;
|
|
1739
|
+
}
|
|
1740
|
+
return colorGroups.includes(x.group);
|
|
1741
|
+
}).map((x) => x.name);
|
|
1901
1742
|
|
|
1902
1743
|
// src/tokens/process/configs.ts
|
|
1903
1744
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
@@ -1936,7 +1777,7 @@ var getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, opt
|
|
|
1936
1777
|
obj.filePath = tokenSet;
|
|
1937
1778
|
}
|
|
1938
1779
|
});
|
|
1939
|
-
tokenSource.tokens =
|
|
1780
|
+
tokenSource.tokens = R15.mergeDeepRight(tokenSource.tokens, tokensWithFilePath);
|
|
1940
1781
|
}
|
|
1941
1782
|
}
|
|
1942
1783
|
} else {
|
|
@@ -1980,12 +1821,6 @@ var initResult = {
|
|
|
1980
1821
|
};
|
|
1981
1822
|
var buildOptions;
|
|
1982
1823
|
var sd = new StyleDictionary2();
|
|
1983
|
-
var getCustomColors = (processed$themes, colorGroups) => processed$themes.filter((x) => {
|
|
1984
|
-
if (!x.group) {
|
|
1985
|
-
return false;
|
|
1986
|
-
}
|
|
1987
|
-
return colorGroups.includes(x.group);
|
|
1988
|
-
}).map((x) => x.name);
|
|
1989
1824
|
var buildConfigs = {
|
|
1990
1825
|
typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
|
|
1991
1826
|
"color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
|
|
@@ -2026,46 +1861,54 @@ var buildConfigs = {
|
|
|
2026
1861
|
// },
|
|
2027
1862
|
};
|
|
2028
1863
|
async function processPlatform(options) {
|
|
2029
|
-
const { type, $themes } = options;
|
|
1864
|
+
const { type, processed$themes } = options;
|
|
2030
1865
|
const platform = "css";
|
|
2031
1866
|
const tokenSets = type === "format" ? options.tokenSets : void 0;
|
|
2032
1867
|
const tokensDir = type === "build" ? options.tokensDir : void 0;
|
|
2033
1868
|
const UNSAFE_DEFAULT_COLOR = process.env.UNSAFE_DEFAULT_COLOR ?? "";
|
|
2034
1869
|
if (UNSAFE_DEFAULT_COLOR) {
|
|
2035
1870
|
console.warn(
|
|
2036
|
-
|
|
1871
|
+
chalk4.yellow(
|
|
2037
1872
|
`
|
|
2038
|
-
\u26A0\uFE0F UNSAFE_DEFAULT_COLOR is set to ${
|
|
1873
|
+
\u26A0\uFE0F UNSAFE_DEFAULT_COLOR is set to ${chalk4.blue(UNSAFE_DEFAULT_COLOR)}. This will override the default color.`
|
|
2039
1874
|
)
|
|
2040
1875
|
);
|
|
2041
1876
|
}
|
|
2042
1877
|
const UNSAFE_COLOR_GROUPS = Array.from(process.env.UNSAFE_COLOR_GROUPS?.split(",") ?? []);
|
|
2043
1878
|
if (UNSAFE_COLOR_GROUPS.length > 0) {
|
|
2044
1879
|
console.warn(
|
|
2045
|
-
|
|
1880
|
+
chalk4.yellow(
|
|
2046
1881
|
`
|
|
2047
|
-
\u26A0\uFE0F UNSAFE_COLOR_GROUPS is set to ${
|
|
1882
|
+
\u26A0\uFE0F UNSAFE_COLOR_GROUPS is set to ${chalk4.blue(`[${UNSAFE_COLOR_GROUPS.join(", ")}]`)}. This will override the default color groups.`
|
|
2048
1883
|
)
|
|
2049
1884
|
);
|
|
2050
1885
|
}
|
|
2051
1886
|
const colorGroups = UNSAFE_COLOR_GROUPS.length > 0 ? UNSAFE_COLOR_GROUPS : [colorCategories.main, colorCategories.support].map((c) => `${c}-color`);
|
|
2052
1887
|
buildOptions = options;
|
|
2053
1888
|
buildOptions.defaultColor = UNSAFE_DEFAULT_COLOR;
|
|
2054
|
-
|
|
2055
|
-
const
|
|
1889
|
+
buildOptions.colorGroups = colorGroups;
|
|
1890
|
+
const filteredProcessed$themes = processed$themes.filter(
|
|
1891
|
+
(theme) => R16.not(theme.group === "size" && theme.name !== "medium")
|
|
1892
|
+
);
|
|
1893
|
+
const customColors = getCustomColors(filteredProcessed$themes, colorGroups);
|
|
2056
1894
|
if (!buildOptions.defaultColor) {
|
|
2057
|
-
const firstMainColor =
|
|
1895
|
+
const firstMainColor = R16.head(customColors);
|
|
2058
1896
|
buildOptions.defaultColor = firstMainColor;
|
|
2059
1897
|
}
|
|
2060
1898
|
if (buildOptions.defaultColor) {
|
|
2061
1899
|
console.log(`
|
|
2062
|
-
\u{1F3A8} Using ${
|
|
1900
|
+
\u{1F3A8} Using ${chalk4.blue(buildOptions.defaultColor)} as default color`);
|
|
2063
1901
|
}
|
|
2064
|
-
const buildAndSdConfigs =
|
|
2065
|
-
const sdConfigs = getConfigsForThemeDimensions(
|
|
2066
|
-
|
|
2067
|
-
|
|
2068
|
-
|
|
1902
|
+
const buildAndSdConfigs = R16.map((buildConfig) => {
|
|
1903
|
+
const sdConfigs = getConfigsForThemeDimensions(
|
|
1904
|
+
buildConfig.getConfig,
|
|
1905
|
+
filteredProcessed$themes,
|
|
1906
|
+
buildConfig.dimensions,
|
|
1907
|
+
{
|
|
1908
|
+
tokensDir,
|
|
1909
|
+
tokenSets
|
|
1910
|
+
}
|
|
1911
|
+
);
|
|
2069
1912
|
const unknownConfigs = buildConfig.dimensions.map(
|
|
2070
1913
|
(dimension) => sdConfigs.filter((x) => x.permutation[dimension] === "unknown")
|
|
2071
1914
|
);
|
|
@@ -2089,23 +1932,22 @@ async function processPlatform(options) {
|
|
|
2089
1932
|
"warning-color": [initResult],
|
|
2090
1933
|
"info-color": [initResult],
|
|
2091
1934
|
semantic: [initResult],
|
|
2092
|
-
typography: [initResult]
|
|
2093
|
-
types: [initResult]
|
|
1935
|
+
typography: [initResult]
|
|
2094
1936
|
};
|
|
2095
1937
|
try {
|
|
2096
|
-
for (const [buildName, { buildConfig, sdConfigs }] of
|
|
1938
|
+
for (const [buildName, { buildConfig, sdConfigs }] of R16.toPairs(buildAndSdConfigs)) {
|
|
2097
1939
|
if (!(buildConfig.enabled?.() ?? true)) {
|
|
2098
1940
|
continue;
|
|
2099
1941
|
}
|
|
2100
1942
|
if (sdConfigs.length > 0) {
|
|
2101
1943
|
console.log(`
|
|
2102
|
-
\u{1F371} Building ${
|
|
1944
|
+
\u{1F371} Building ${chalk4.green(buildConfig.name ?? buildName)}`);
|
|
2103
1945
|
const results = await Promise.all(
|
|
2104
1946
|
sdConfigs.map(async (sdConfig) => {
|
|
2105
1947
|
const { config, permutation } = sdConfig;
|
|
2106
1948
|
const modes = ["theme", ...buildConfig.dimensions];
|
|
2107
1949
|
const modeMessage = modes.map((x) => permutation[x]).join(" - ");
|
|
2108
|
-
const logMessage =
|
|
1950
|
+
const logMessage = R16.isNil(buildConfig.log) ? modeMessage : buildConfig?.log(sdConfig);
|
|
2109
1951
|
console.log(logMessage);
|
|
2110
1952
|
const sdOptions = { cache: true };
|
|
2111
1953
|
const sdExtended = await sd.extend(config);
|
|
@@ -2125,17 +1967,22 @@ async function processPlatform(options) {
|
|
|
2125
1967
|
}
|
|
2126
1968
|
throw err;
|
|
2127
1969
|
}
|
|
2128
|
-
const colorsFileName = "colors.d.ts";
|
|
2129
|
-
const reactColorTypes = await createColorTypeDeclaration(customColors);
|
|
2130
|
-
processedBuilds.types = [
|
|
2131
|
-
{
|
|
2132
|
-
...initResult,
|
|
2133
|
-
formatted: [{ output: reactColorTypes, destination: colorsFileName }]
|
|
2134
|
-
}
|
|
2135
|
-
];
|
|
2136
1970
|
return processedBuilds;
|
|
2137
1971
|
}
|
|
2138
|
-
|
|
1972
|
+
|
|
1973
|
+
// src/tokens/process/output/declarations.ts
|
|
1974
|
+
var createTypeDeclarationFiles = (processed$themes) => {
|
|
1975
|
+
const colorGroups = buildOptions?.colorGroups || [];
|
|
1976
|
+
const customColors = getCustomColors(processed$themes, colorGroups);
|
|
1977
|
+
const typeDeclaration = createColorTypeDeclaration(customColors);
|
|
1978
|
+
return [
|
|
1979
|
+
{
|
|
1980
|
+
output: typeDeclaration,
|
|
1981
|
+
destination: "colors.d.ts"
|
|
1982
|
+
}
|
|
1983
|
+
];
|
|
1984
|
+
};
|
|
1985
|
+
function createColorTypeDeclaration(colors2) {
|
|
2139
1986
|
console.log(`
|
|
2140
1987
|
\u{1F371} Building ${chalk5.green("type declarations")}`);
|
|
2141
1988
|
const typeDeclaration = `
|
|
@@ -2150,6 +1997,232 @@ ${colors2.map((color) => ` ${color}: never;`).join("\n")}
|
|
|
2150
1997
|
return typeDeclaration;
|
|
2151
1998
|
}
|
|
2152
1999
|
|
|
2000
|
+
// src/tokens/process/output/tailwind.ts
|
|
2001
|
+
var createTailwindCSSFiles = (cssFiles) => {
|
|
2002
|
+
console.log("\n\u{1F371} Creating Tailwind Config");
|
|
2003
|
+
return cssFiles.map((file) => {
|
|
2004
|
+
if (file.destination) {
|
|
2005
|
+
const tailwindConfig = generateTailwind(file.output);
|
|
2006
|
+
const tailwindFile = {
|
|
2007
|
+
destination: file.destination.replace(".css", ".tailwind.css"),
|
|
2008
|
+
output: tailwindConfig
|
|
2009
|
+
};
|
|
2010
|
+
return tailwindFile;
|
|
2011
|
+
}
|
|
2012
|
+
return void 0;
|
|
2013
|
+
}).filter((item) => item !== void 0);
|
|
2014
|
+
};
|
|
2015
|
+
var generateTailwind = (css) => {
|
|
2016
|
+
const tailwind = ["--font-sans: var(--ds-font-family)"];
|
|
2017
|
+
const tokens = Array.from(new Set(css.match(/--ds-[^:)]+/g)), (m) => m).sort(
|
|
2018
|
+
(a, b) => a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" })
|
|
2019
|
+
);
|
|
2020
|
+
for (const token of tokens) {
|
|
2021
|
+
if (token.startsWith("--ds-color-") && !token.startsWith("--ds-color-focus")) {
|
|
2022
|
+
tailwind.push(`--color-${token.replace("--ds-color-", "")}: var(${token})`);
|
|
2023
|
+
} else if (token.startsWith("--ds-font-weight-")) {
|
|
2024
|
+
tailwind.push(`--font-weight-${token.replace("--ds-font-weight-", "")}: var(${token})`);
|
|
2025
|
+
} else if (token.match(/--ds-border-radius-(sm|md|lg|xl)/)) {
|
|
2026
|
+
tailwind.push(`--radius-${token.replace("--ds-border-radius-", "")}: var(${token})`);
|
|
2027
|
+
} else if (token.match(/--ds-body-(sm|mg|lg)-body-font-size/)) {
|
|
2028
|
+
tailwind.push(`--text-${token.replace("--ds-body-", "").replace("-font-size", "")}: var(${token})`);
|
|
2029
|
+
} else if (token.match(/^--ds-size-\d+$/)) {
|
|
2030
|
+
tailwind.push(`--spacing-${token.replace("--ds-size-", "")}: var(${token})`);
|
|
2031
|
+
}
|
|
2032
|
+
}
|
|
2033
|
+
const dynamicColors = `[data-color] {
|
|
2034
|
+
--color-background-default: var(--ds-color-background-default);
|
|
2035
|
+
--color-background-tinted: var(--ds-color-background-tinted);
|
|
2036
|
+
--color-surface-default: var(--ds-color-surface-default);
|
|
2037
|
+
--color-surface-tinted: var(--ds-color-surface-tinted);
|
|
2038
|
+
--color-surface-hover: var(--ds-color-surface-hover);
|
|
2039
|
+
--color-surface-active: var(--ds-color-surface-active);
|
|
2040
|
+
--color-border-subtle: var(--ds-color-border-subtle);
|
|
2041
|
+
--color-border-default: var(--ds-color-border-default);
|
|
2042
|
+
--color-border-strong: var(--ds-color-border-strong);
|
|
2043
|
+
--color-text-subtle: var(--ds-color-text-subtle);
|
|
2044
|
+
--color-text-default: var(--ds-color-text-default);
|
|
2045
|
+
--color-base-default: var(--ds-color-base-default);
|
|
2046
|
+
--color-base-hover: var(--ds-color-base-hover);
|
|
2047
|
+
--color-base-active: var(--ds-color-base-active);
|
|
2048
|
+
--color-base-contrast-subtle: var(--ds-color-base-contrast-subtle);
|
|
2049
|
+
--color-base-contrast-default: var(--ds-color-base-contrast-default);
|
|
2050
|
+
}`;
|
|
2051
|
+
return `@theme {${tailwind.map((str) => `
|
|
2052
|
+
${str};`).join("")}
|
|
2053
|
+
}
|
|
2054
|
+
${dynamicColors}`;
|
|
2055
|
+
};
|
|
2056
|
+
|
|
2057
|
+
// src/tokens/process/output/theme.ts
|
|
2058
|
+
import chalk6 from "chalk";
|
|
2059
|
+
import * as R17 from "ramda";
|
|
2060
|
+
|
|
2061
|
+
// package.json
|
|
2062
|
+
var package_default = {
|
|
2063
|
+
name: "@digdir/designsystemet",
|
|
2064
|
+
version: "1.1.1",
|
|
2065
|
+
description: "CLI for Designsystemet",
|
|
2066
|
+
author: "Designsystemet team",
|
|
2067
|
+
engines: {
|
|
2068
|
+
node: ">=22.16.0"
|
|
2069
|
+
},
|
|
2070
|
+
repository: {
|
|
2071
|
+
type: "git",
|
|
2072
|
+
url: "git+https://github.com/digdir/designsystemet.git"
|
|
2073
|
+
},
|
|
2074
|
+
homepage: "https://github.com/digdir/designsystemet/tree/main/packages/cli",
|
|
2075
|
+
license: "MIT",
|
|
2076
|
+
type: "module",
|
|
2077
|
+
main: "./dist/src/index.js",
|
|
2078
|
+
files: [
|
|
2079
|
+
"./dist/**",
|
|
2080
|
+
"./configs/**"
|
|
2081
|
+
],
|
|
2082
|
+
bin: "dist/bin/designsystemet.js",
|
|
2083
|
+
exports: {
|
|
2084
|
+
".": {
|
|
2085
|
+
import: "./dist/src/index.js"
|
|
2086
|
+
},
|
|
2087
|
+
"./color": {
|
|
2088
|
+
import: "./dist/src/colors/index.js"
|
|
2089
|
+
},
|
|
2090
|
+
"./tokens": {
|
|
2091
|
+
import: "./dist/src/tokens/index.js"
|
|
2092
|
+
}
|
|
2093
|
+
},
|
|
2094
|
+
publishConfig: {
|
|
2095
|
+
access: "public"
|
|
2096
|
+
},
|
|
2097
|
+
scripts: {
|
|
2098
|
+
designsystemet: "tsx ./bin/designsystemet.ts",
|
|
2099
|
+
"designsystemet:inspect": "tsx --inspect-brk ./bin/designsystemet.ts",
|
|
2100
|
+
build: "tsup && pnpm build:types && pnpm build:json-schema",
|
|
2101
|
+
"build:types": "tsc --emitDeclarationOnly --declaration",
|
|
2102
|
+
"build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
|
|
2103
|
+
types: "tsc --noEmit",
|
|
2104
|
+
"test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
|
|
2105
|
+
"test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
|
|
2106
|
+
"test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
|
|
2107
|
+
"test:tokens-build-tailwind": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean --experimental-tailwind",
|
|
2108
|
+
"test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
|
|
2109
|
+
"test:tokens-build-config:inspect": "pnpm run designsystemet:inspect tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
|
|
2110
|
+
"test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
|
|
2111
|
+
"test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
|
|
2112
|
+
"test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
|
|
2113
|
+
test: "pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
|
|
2114
|
+
"digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
|
|
2115
|
+
"digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
|
|
2116
|
+
"update:template": "tsx ./src/scripts/update-template.ts",
|
|
2117
|
+
"update:theme-digdir": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts && pnpm digdir:tokens-build",
|
|
2118
|
+
verify: "pnpm test && pnpm update:template && pnpm update:theme-digdir && pnpm build:tokens"
|
|
2119
|
+
},
|
|
2120
|
+
dependencies: {
|
|
2121
|
+
"@commander-js/extra-typings": "^14.0.0",
|
|
2122
|
+
"@tokens-studio/sd-transforms": "1.3.0",
|
|
2123
|
+
"apca-w3": "^0.1.9",
|
|
2124
|
+
chalk: "^5.4.1",
|
|
2125
|
+
"change-case": "^5.4.4",
|
|
2126
|
+
"chroma-js": "^3.1.2",
|
|
2127
|
+
"colorjs.io": "^0.6.0-alpha.1",
|
|
2128
|
+
commander: "^14.0.0",
|
|
2129
|
+
"fast-glob": "^3.3.3",
|
|
2130
|
+
hsluv: "^1.0.1",
|
|
2131
|
+
"object-hash": "^3.0.0",
|
|
2132
|
+
postcss: "^8.5.6",
|
|
2133
|
+
ramda: "^0.30.1",
|
|
2134
|
+
"style-dictionary": "^5.0.0",
|
|
2135
|
+
zod: "^3.25.67",
|
|
2136
|
+
"zod-validation-error": "^3.5.2"
|
|
2137
|
+
},
|
|
2138
|
+
devDependencies: {
|
|
2139
|
+
"@tokens-studio/types": "0.5.2",
|
|
2140
|
+
"@types/apca-w3": "^0.1.3",
|
|
2141
|
+
"@types/chroma-js": "^3.1.1",
|
|
2142
|
+
"@types/fs-extra": "^11.0.4",
|
|
2143
|
+
"@types/glob": "^8.1.0",
|
|
2144
|
+
"@types/node": "^22.15.32",
|
|
2145
|
+
"@types/object-hash": "^3.0.6",
|
|
2146
|
+
"@types/ramda": "^0.30.2",
|
|
2147
|
+
"fs-extra": "^11.3.0",
|
|
2148
|
+
tslib: "^2.8.1",
|
|
2149
|
+
tsup: "^8.5.0",
|
|
2150
|
+
tsx: "^4.20.3",
|
|
2151
|
+
typescript: "^5.8.3"
|
|
2152
|
+
}
|
|
2153
|
+
};
|
|
2154
|
+
|
|
2155
|
+
// src/tokens/process/output/theme.ts
|
|
2156
|
+
var defaultFileHeader = `build: v${package_default.version}`;
|
|
2157
|
+
var createThemeCSSFiles = ({
|
|
2158
|
+
processedBuilds,
|
|
2159
|
+
fileHeader: fileHeader2 = defaultFileHeader
|
|
2160
|
+
}) => {
|
|
2161
|
+
const groupedByTheme = {};
|
|
2162
|
+
for (const [_, buildResults] of Object.entries(processedBuilds)) {
|
|
2163
|
+
for (const buildResult of buildResults) {
|
|
2164
|
+
const themeName = buildResult.permutation.theme;
|
|
2165
|
+
const newOutputs = buildResult.formatted;
|
|
2166
|
+
if (R17.isNotEmpty(newOutputs)) {
|
|
2167
|
+
const currentOutputs = groupedByTheme[themeName] ?? [];
|
|
2168
|
+
groupedByTheme[themeName] = R17.concat(currentOutputs, newOutputs);
|
|
2169
|
+
}
|
|
2170
|
+
}
|
|
2171
|
+
}
|
|
2172
|
+
const sortOrder = [
|
|
2173
|
+
"color-scheme/light",
|
|
2174
|
+
"typography/secondary",
|
|
2175
|
+
"semantic",
|
|
2176
|
+
"color-scheme/dark",
|
|
2177
|
+
"color-scheme/contrast",
|
|
2178
|
+
"typography/primary",
|
|
2179
|
+
"color/"
|
|
2180
|
+
];
|
|
2181
|
+
const sortByDefinedOrder = R17.sortBy((file) => {
|
|
2182
|
+
const filePath = file.destination || "";
|
|
2183
|
+
const sortIndex = sortOrder.findIndex((sortElement) => {
|
|
2184
|
+
if (sortElement.endsWith("/")) {
|
|
2185
|
+
return filePath.includes(sortElement);
|
|
2186
|
+
}
|
|
2187
|
+
return filePath.includes(`${sortElement}.css`);
|
|
2188
|
+
});
|
|
2189
|
+
if (sortIndex === -1) {
|
|
2190
|
+
console.error(
|
|
2191
|
+
chalk6.yellow("WARNING: CSS section does not have a defined sort order:", filePath.replace(".css", ""))
|
|
2192
|
+
);
|
|
2193
|
+
console.log(
|
|
2194
|
+
chalk6.dim(
|
|
2195
|
+
`
|
|
2196
|
+
The section will currently be added to the end of the entry file, but the exact
|
|
2197
|
+
order may change due to nondeterminism.`.trim()
|
|
2198
|
+
)
|
|
2199
|
+
);
|
|
2200
|
+
return Infinity;
|
|
2201
|
+
}
|
|
2202
|
+
return sortIndex;
|
|
2203
|
+
});
|
|
2204
|
+
const header = `@charset "UTF-8";
|
|
2205
|
+
/*
|
|
2206
|
+
${fileHeader2}
|
|
2207
|
+
*/
|
|
2208
|
+
|
|
2209
|
+
`;
|
|
2210
|
+
const sortAlphabetically = R17.sort(R17.ascend((x) => x.destination || ""));
|
|
2211
|
+
const pickOutputs = R17.map(R17.view(R17.lensProp("output")));
|
|
2212
|
+
const themeCSSFile = R17.pipe(
|
|
2213
|
+
sortAlphabetically,
|
|
2214
|
+
sortByDefinedOrder,
|
|
2215
|
+
pickOutputs,
|
|
2216
|
+
R17.join("\n"),
|
|
2217
|
+
(content) => header + content
|
|
2218
|
+
);
|
|
2219
|
+
const themeCSSFiles = Object.entries(groupedByTheme).map(([theme, files]) => ({
|
|
2220
|
+
destination: `${theme}.css`,
|
|
2221
|
+
output: themeCSSFile(files)
|
|
2222
|
+
}));
|
|
2223
|
+
return themeCSSFiles;
|
|
2224
|
+
};
|
|
2225
|
+
|
|
2153
2226
|
// src/tokens/build.ts
|
|
2154
2227
|
async function write(files, outDir, dry) {
|
|
2155
2228
|
for (const { destination, output } of files) {
|
|
@@ -2166,40 +2239,303 @@ var buildTokens = async (options) => {
|
|
|
2166
2239
|
const outDir = path.resolve(options.outDir);
|
|
2167
2240
|
const tokensDir = path.resolve(options.tokensDir);
|
|
2168
2241
|
const $themes = JSON.parse(await readFile(`${tokensDir}/$themes.json`));
|
|
2242
|
+
const processed$themes = $themes.map(processThemeObject);
|
|
2169
2243
|
let $designsystemet;
|
|
2170
2244
|
try {
|
|
2171
2245
|
const $designsystemetContent = await readFile(`${tokensDir}/$designsystemet.json`);
|
|
2172
2246
|
$designsystemet = JSON.parse($designsystemetContent);
|
|
2173
|
-
} catch (
|
|
2247
|
+
} catch (_error) {
|
|
2174
2248
|
}
|
|
2175
2249
|
console.log(`
|
|
2176
|
-
\u{1F3D7}\uFE0F Start building tokens in ${
|
|
2250
|
+
\u{1F3D7}\uFE0F Start building tokens in ${chalk7.green(tokensDir)}`);
|
|
2177
2251
|
const processedBuilds = await processPlatform({
|
|
2178
2252
|
...options,
|
|
2179
2253
|
outDir,
|
|
2180
2254
|
tokensDir,
|
|
2181
2255
|
type: "build",
|
|
2182
|
-
$themes
|
|
2256
|
+
processed$themes
|
|
2183
2257
|
});
|
|
2184
|
-
console.log(`
|
|
2185
|
-
\u{1F4BE} Writing build to ${chalk6.green(outDir)}`);
|
|
2186
|
-
for (const { formatted } of processedBuilds.types) {
|
|
2187
|
-
await write(formatted, outDir, options.dry);
|
|
2188
|
-
}
|
|
2189
2258
|
const fileHeader2 = R18.join("")([
|
|
2190
2259
|
defaultFileHeader,
|
|
2191
2260
|
$designsystemet ? `
|
|
2192
2261
|
design-tokens: v${$designsystemet.version}` : ""
|
|
2193
2262
|
]);
|
|
2194
|
-
|
|
2263
|
+
let files = [];
|
|
2264
|
+
const declarationFiles = createTypeDeclarationFiles(processed$themes);
|
|
2265
|
+
const cssFiles = createThemeCSSFiles({ processedBuilds, fileHeader: fileHeader2 });
|
|
2266
|
+
files = [...declarationFiles, ...cssFiles];
|
|
2267
|
+
if (options.tailwind) {
|
|
2268
|
+
const tailwindFiles = createTailwindCSSFiles(cssFiles);
|
|
2269
|
+
files = files.concat(tailwindFiles.filter(Boolean));
|
|
2270
|
+
}
|
|
2271
|
+
console.log(`
|
|
2272
|
+
\u{1F4BE} Writing build to ${chalk7.green(outDir)}`);
|
|
2273
|
+
await write(files, outDir, options.dry);
|
|
2195
2274
|
console.log(`
|
|
2196
2275
|
\u2705 Finished building tokens!`);
|
|
2197
2276
|
return processedBuilds;
|
|
2198
2277
|
};
|
|
2199
2278
|
|
|
2200
|
-
// src/tokens/create/
|
|
2279
|
+
// src/tokens/create/write.ts
|
|
2280
|
+
import path2 from "path";
|
|
2281
|
+
import chalk8 from "chalk";
|
|
2201
2282
|
import * as R19 from "ramda";
|
|
2202
2283
|
|
|
2284
|
+
// src/tokens/create/generators/$designsystemet.ts
|
|
2285
|
+
function generate$Designsystemet() {
|
|
2286
|
+
return {
|
|
2287
|
+
name: package_default.name,
|
|
2288
|
+
version: package_default.version
|
|
2289
|
+
};
|
|
2290
|
+
}
|
|
2291
|
+
|
|
2292
|
+
// src/tokens/create/generators/$metadata.ts
|
|
2293
|
+
function generate$Metadata(schemes, themes, colors2) {
|
|
2294
|
+
return {
|
|
2295
|
+
tokenSetOrder: [
|
|
2296
|
+
"primitives/globals",
|
|
2297
|
+
"primitives/modes/size/small",
|
|
2298
|
+
"primitives/modes/size/medium",
|
|
2299
|
+
"primitives/modes/size/large",
|
|
2300
|
+
"primitives/modes/size/global",
|
|
2301
|
+
"primitives/modes/typography/size/small",
|
|
2302
|
+
"primitives/modes/typography/size/medium",
|
|
2303
|
+
"primitives/modes/typography/size/large",
|
|
2304
|
+
...themes.map((theme) => `primitives/modes/typography/primary/${theme}`),
|
|
2305
|
+
...themes.map((theme) => `primitives/modes/typography/secondary/${theme}`),
|
|
2306
|
+
...schemes.flatMap((scheme) => [
|
|
2307
|
+
`primitives/modes/color-scheme/${scheme}/global`,
|
|
2308
|
+
...themes.map((theme) => `primitives/modes/color-scheme/${scheme}/${theme}`)
|
|
2309
|
+
]),
|
|
2310
|
+
...themes.map((theme) => `themes/${theme}`),
|
|
2311
|
+
"semantic/color",
|
|
2312
|
+
...Object.entries(colors2.main).map(([color]) => `semantic/modes/main-color/${color}`),
|
|
2313
|
+
...Object.entries(colors2.support).map(([color]) => `semantic/modes/support-color/${color}`),
|
|
2314
|
+
"semantic/style"
|
|
2315
|
+
]
|
|
2316
|
+
};
|
|
2317
|
+
}
|
|
2318
|
+
|
|
2319
|
+
// src/tokens/create/generators/$themes.ts
|
|
2320
|
+
var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
2321
|
+
async function createHash(text, algo = "SHA-1") {
|
|
2322
|
+
const crypto = globalThis.crypto;
|
|
2323
|
+
return Array.from(
|
|
2324
|
+
new Uint8Array(await crypto.subtle.digest(algo, new TextEncoder().encode(text))),
|
|
2325
|
+
(byte) => byte.toString(16).padStart(2, "0")
|
|
2326
|
+
).join("");
|
|
2327
|
+
}
|
|
2328
|
+
async function generate$Themes(colorSchemes, themes, colors2) {
|
|
2329
|
+
return [
|
|
2330
|
+
...generateSizeGroup(),
|
|
2331
|
+
...await generateThemesGroup(themes),
|
|
2332
|
+
...generateTypographyGroup(themes),
|
|
2333
|
+
...generateColorSchemesGroup(colorSchemes, themes),
|
|
2334
|
+
generateSemanticGroup(),
|
|
2335
|
+
...await generateColorGroup("main", colors2),
|
|
2336
|
+
...await generateColorGroup("support", colors2)
|
|
2337
|
+
];
|
|
2338
|
+
}
|
|
2339
|
+
function generateSizeGroup() {
|
|
2340
|
+
return [
|
|
2341
|
+
{
|
|
2342
|
+
id: "8b2c8cc86611a34b135cb22948666779361fd729",
|
|
2343
|
+
name: "medium",
|
|
2344
|
+
$figmaStyleReferences: {},
|
|
2345
|
+
selectedTokenSets: {
|
|
2346
|
+
"primitives/modes/size/medium": TokenSetStatus.SOURCE,
|
|
2347
|
+
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
2348
|
+
"primitives/modes/typography/size/medium": TokenSetStatus.ENABLED
|
|
2349
|
+
},
|
|
2350
|
+
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
2351
|
+
$figmaModeId: "41630:1",
|
|
2352
|
+
group: "Size"
|
|
2353
|
+
},
|
|
2354
|
+
{
|
|
2355
|
+
id: "d49b9eebeb48a4f165a74b7261733d0a73370f0e",
|
|
2356
|
+
name: "large",
|
|
2357
|
+
$figmaStyleReferences: {},
|
|
2358
|
+
selectedTokenSets: {
|
|
2359
|
+
"primitives/modes/size/large": TokenSetStatus.SOURCE,
|
|
2360
|
+
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
2361
|
+
"primitives/modes/typography/size/large": TokenSetStatus.ENABLED
|
|
2362
|
+
},
|
|
2363
|
+
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
2364
|
+
$figmaModeId: "41630:2",
|
|
2365
|
+
group: "Size"
|
|
2366
|
+
},
|
|
2367
|
+
{
|
|
2368
|
+
id: "fb11567729c298ca37c9da4e3a27716a23480824",
|
|
2369
|
+
name: "small",
|
|
2370
|
+
$figmaStyleReferences: {},
|
|
2371
|
+
selectedTokenSets: {
|
|
2372
|
+
"primitives/modes/size/small": TokenSetStatus.SOURCE,
|
|
2373
|
+
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
2374
|
+
"primitives/modes/typography/size/small": TokenSetStatus.ENABLED
|
|
2375
|
+
},
|
|
2376
|
+
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
2377
|
+
$figmaModeId: "41630:3",
|
|
2378
|
+
group: "Size"
|
|
2379
|
+
}
|
|
2380
|
+
];
|
|
2381
|
+
}
|
|
2382
|
+
var colorSchemeDefaults = {
|
|
2383
|
+
light: {
|
|
2384
|
+
name: "Light",
|
|
2385
|
+
selectedTokenSets: {},
|
|
2386
|
+
id: "0daa3ca0b427b9349da7e7dc00101b5668972926",
|
|
2387
|
+
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
2388
|
+
$figmaModeId: "34811:0"
|
|
2389
|
+
},
|
|
2390
|
+
dark: {
|
|
2391
|
+
name: "Dark",
|
|
2392
|
+
selectedTokenSets: {},
|
|
2393
|
+
id: "9ebd8aed52afbffc17e2666e8b4653a53498b257",
|
|
2394
|
+
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
2395
|
+
$figmaModeId: "34811:1"
|
|
2396
|
+
},
|
|
2397
|
+
contrast: {
|
|
2398
|
+
name: "Contrast",
|
|
2399
|
+
selectedTokenSets: {},
|
|
2400
|
+
id: "9ebd8aed52afbffc17e2666e8b4653a53498b123",
|
|
2401
|
+
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
2402
|
+
$figmaModeId: "34811:2"
|
|
2403
|
+
}
|
|
2404
|
+
};
|
|
2405
|
+
function generateColorSchemesGroup(colorSchemes, themes) {
|
|
2406
|
+
return colorSchemes.map(
|
|
2407
|
+
(scheme) => ({
|
|
2408
|
+
...colorSchemeDefaults[scheme],
|
|
2409
|
+
selectedTokenSets: Object.fromEntries([
|
|
2410
|
+
[`primitives/modes/color-scheme/${scheme}/global`, TokenSetStatus.ENABLED],
|
|
2411
|
+
...themes.map((theme) => [`primitives/modes/color-scheme/${scheme}/${theme}`, TokenSetStatus.ENABLED])
|
|
2412
|
+
]),
|
|
2413
|
+
group: "Color scheme"
|
|
2414
|
+
})
|
|
2415
|
+
);
|
|
2416
|
+
}
|
|
2417
|
+
async function generateThemesGroup(themes) {
|
|
2418
|
+
return Promise.all(
|
|
2419
|
+
themes.map(
|
|
2420
|
+
async (theme, index) => ({
|
|
2421
|
+
id: await createHash(theme),
|
|
2422
|
+
$figmaCollectionId: "VariableCollectionId:36528:61712",
|
|
2423
|
+
$figmaModeId: `40960:${index + 6}`,
|
|
2424
|
+
// Start on 6 in Token Studio and Community file for some reason
|
|
2425
|
+
name: theme,
|
|
2426
|
+
selectedTokenSets: {
|
|
2427
|
+
[`themes/${theme}`]: TokenSetStatus.ENABLED
|
|
2428
|
+
},
|
|
2429
|
+
group: "Theme"
|
|
2430
|
+
})
|
|
2431
|
+
)
|
|
2432
|
+
);
|
|
2433
|
+
}
|
|
2434
|
+
function generateSemanticGroup() {
|
|
2435
|
+
return {
|
|
2436
|
+
id: "541629445ef90ad5363f9e88f52a1ccb617e6f84",
|
|
2437
|
+
name: "Semantic",
|
|
2438
|
+
selectedTokenSets: {
|
|
2439
|
+
"semantic/style": TokenSetStatus.ENABLED,
|
|
2440
|
+
"semantic/color": TokenSetStatus.ENABLED,
|
|
2441
|
+
"primitives/globals": TokenSetStatus.SOURCE
|
|
2442
|
+
},
|
|
2443
|
+
$figmaCollectionId: "VariableCollectionId:34811:5976",
|
|
2444
|
+
$figmaModeId: "34811:5",
|
|
2445
|
+
group: "Semantic"
|
|
2446
|
+
};
|
|
2447
|
+
}
|
|
2448
|
+
async function generateColorGroup(group, colors2) {
|
|
2449
|
+
return Promise.all(
|
|
2450
|
+
Object.entries(colors2[group]).map(
|
|
2451
|
+
async ([color]) => ({
|
|
2452
|
+
id: await createHash(`${group}-${color}`),
|
|
2453
|
+
name: color,
|
|
2454
|
+
selectedTokenSets: {
|
|
2455
|
+
[`semantic/modes/${group}-color/${color}`]: TokenSetStatus.ENABLED
|
|
2456
|
+
},
|
|
2457
|
+
group: `${capitalize(group)} color`
|
|
2458
|
+
})
|
|
2459
|
+
)
|
|
2460
|
+
);
|
|
2461
|
+
}
|
|
2462
|
+
function generateTypographyGroup(themes) {
|
|
2463
|
+
return [
|
|
2464
|
+
{
|
|
2465
|
+
id: "368d753fcac4455f289500eaa42e70dc0a03522f",
|
|
2466
|
+
$figmaCollectionId: "VariableCollectionId:36248:20769",
|
|
2467
|
+
$figmaModeId: "36248:2",
|
|
2468
|
+
name: "Primary",
|
|
2469
|
+
selectedTokenSets: Object.fromEntries(
|
|
2470
|
+
themes.map((theme) => [`primitives/modes/typography/primary/${theme}`, TokenSetStatus.ENABLED])
|
|
2471
|
+
),
|
|
2472
|
+
group: "Typography"
|
|
2473
|
+
},
|
|
2474
|
+
{
|
|
2475
|
+
id: "264b8bd1d40b364e1ea3acf09e49795ddd4c513c",
|
|
2476
|
+
$figmaCollectionId: "VariableCollectionId:36248:20769",
|
|
2477
|
+
$figmaModeId: "36248:3",
|
|
2478
|
+
name: "Secondary",
|
|
2479
|
+
selectedTokenSets: Object.fromEntries(
|
|
2480
|
+
themes.map((theme) => [`primitives/modes/typography/secondary/${theme}`, TokenSetStatus.ENABLED])
|
|
2481
|
+
),
|
|
2482
|
+
group: "Typography"
|
|
2483
|
+
}
|
|
2484
|
+
];
|
|
2485
|
+
}
|
|
2486
|
+
|
|
2487
|
+
// src/tokens/create/write.ts
|
|
2488
|
+
var stringify = (data) => JSON.stringify(data, null, 2);
|
|
2489
|
+
var writeTokens = async (options) => {
|
|
2490
|
+
const {
|
|
2491
|
+
outDir,
|
|
2492
|
+
tokenSets,
|
|
2493
|
+
theme: { name: themeName, colors: colors2 },
|
|
2494
|
+
dry
|
|
2495
|
+
} = options;
|
|
2496
|
+
const targetDir = path2.resolve(process.cwd(), String(outDir));
|
|
2497
|
+
const $themesPath = path2.join(targetDir, "$themes.json");
|
|
2498
|
+
const $metadataPath = path2.join(targetDir, "$metadata.json");
|
|
2499
|
+
const $designsystemetPath = path2.join(targetDir, "$designsystemet.json");
|
|
2500
|
+
let themeObjects = [];
|
|
2501
|
+
await mkdir(targetDir, dry);
|
|
2502
|
+
try {
|
|
2503
|
+
const $themes2 = await readFile($themesPath);
|
|
2504
|
+
if ($themes2) {
|
|
2505
|
+
themeObjects = JSON.parse($themes2);
|
|
2506
|
+
}
|
|
2507
|
+
} catch (_error) {
|
|
2508
|
+
}
|
|
2509
|
+
const concatThemeNames = R19.pipe(
|
|
2510
|
+
R19.filter((obj) => R19.toLower(obj.group || "") === "theme"),
|
|
2511
|
+
R19.map(R19.prop("name")),
|
|
2512
|
+
// New theme is added to the end of the list so we keep the same order from config and Token Studio
|
|
2513
|
+
R19.append(themeName),
|
|
2514
|
+
R19.uniq
|
|
2515
|
+
);
|
|
2516
|
+
const themes = concatThemeNames(themeObjects);
|
|
2517
|
+
console.log(`
|
|
2518
|
+
Themes: ${chalk8.blue(themes.join(", "))}`);
|
|
2519
|
+
const $themes = await generate$Themes(["dark", "light"], themes, colors2);
|
|
2520
|
+
const $metadata = generate$Metadata(["dark", "light"], themes, colors2);
|
|
2521
|
+
const $designsystemet = generate$Designsystemet();
|
|
2522
|
+
await writeFile($themesPath, stringify($themes), dry);
|
|
2523
|
+
await writeFile($metadataPath, stringify($metadata), dry);
|
|
2524
|
+
await writeFile($designsystemetPath, stringify($designsystemet), dry);
|
|
2525
|
+
for (const [set4, tokens] of tokenSets) {
|
|
2526
|
+
const fileDir = path2.join(targetDir, path2.dirname(set4));
|
|
2527
|
+
await mkdir(fileDir, dry);
|
|
2528
|
+
const filePath = path2.join(targetDir, `${set4}.json`);
|
|
2529
|
+
await writeFile(filePath, stringify(tokens), dry);
|
|
2530
|
+
}
|
|
2531
|
+
console.log(
|
|
2532
|
+
`Finished creating Designsystem design tokens in ${chalk8.green(outDir)} for theme ${chalk8.blue(themeName)}`
|
|
2533
|
+
);
|
|
2534
|
+
};
|
|
2535
|
+
|
|
2536
|
+
// src/tokens/create/defaults.ts
|
|
2537
|
+
import * as R20 from "ramda";
|
|
2538
|
+
|
|
2203
2539
|
// src/tokens/template/design-tokens/primitives/globals.json with { type: 'json' }
|
|
2204
2540
|
var globals_default = {
|
|
2205
2541
|
"border-width": {
|
|
@@ -3183,13 +3519,13 @@ var defaultTokens = {
|
|
|
3183
3519
|
"primitives/modes/typography/size/large": large_default2,
|
|
3184
3520
|
"semantic/style": style_default
|
|
3185
3521
|
};
|
|
3186
|
-
var getDefaultTokens = (tokenSets) => Object.entries(
|
|
3522
|
+
var getDefaultTokens = (tokenSets) => Object.entries(R20.pick(tokenSets, defaultTokens));
|
|
3187
3523
|
var getDefaultToken = (tokenPath) => {
|
|
3188
3524
|
return [tokenPath, defaultTokens[tokenPath]];
|
|
3189
3525
|
};
|
|
3190
3526
|
|
|
3191
3527
|
// src/tokens/create/generators/color.ts
|
|
3192
|
-
import * as
|
|
3528
|
+
import * as R21 from "ramda";
|
|
3193
3529
|
var generateColor = (colorArray) => {
|
|
3194
3530
|
const obj = {};
|
|
3195
3531
|
const $type = "color";
|
|
@@ -3199,8 +3535,8 @@ var generateColor = (colorArray) => {
|
|
|
3199
3535
|
return obj;
|
|
3200
3536
|
};
|
|
3201
3537
|
var generateColorScheme = (themeName, colorScheme2, colors2) => {
|
|
3202
|
-
const main =
|
|
3203
|
-
const support =
|
|
3538
|
+
const main = R21.map((color) => generateColor(generateColorScale(color, colorScheme2)), colors2.main);
|
|
3539
|
+
const support = R21.map((color) => generateColor(generateColorScale(color, colorScheme2)), colors2.support);
|
|
3204
3540
|
const neutral = generateColor(generateColorScale(colors2.neutral, colorScheme2));
|
|
3205
3541
|
return {
|
|
3206
3542
|
[themeName]: {
|
|
@@ -3228,7 +3564,7 @@ var generateColorGlobal = (colorScheme2) => {
|
|
|
3228
3564
|
};
|
|
3229
3565
|
|
|
3230
3566
|
// src/tokens/create/generators/semantic.ts
|
|
3231
|
-
import * as
|
|
3567
|
+
import * as R22 from "ramda";
|
|
3232
3568
|
|
|
3233
3569
|
// src/tokens/template/design-tokens/semantic/color.base.template.json with { type: 'json' }
|
|
3234
3570
|
var color_base_template_default = {
|
|
@@ -3692,7 +4028,7 @@ var generateSemantic = (colors2) => {
|
|
|
3692
4028
|
const semanticColorTokens = customColors.map(
|
|
3693
4029
|
(colorName) => [
|
|
3694
4030
|
colorName,
|
|
3695
|
-
|
|
4031
|
+
R22.map((x) => ({ ...x, $value: x.$value.replace("<color>", colorName) }), color_template_default)
|
|
3696
4032
|
]
|
|
3697
4033
|
);
|
|
3698
4034
|
const color = {
|
|
@@ -3709,7 +4045,7 @@ var generateSemantic = (colors2) => {
|
|
|
3709
4045
|
};
|
|
3710
4046
|
|
|
3711
4047
|
// src/tokens/create/generators/theme.ts
|
|
3712
|
-
import * as
|
|
4048
|
+
import * as R23 from "ramda";
|
|
3713
4049
|
|
|
3714
4050
|
// src/tokens/template/design-tokens/themes/theme.base.template.json with { type: 'json' }
|
|
3715
4051
|
var theme_base_template_default = {
|
|
@@ -3810,416 +4146,160 @@ var theme_template_default = {
|
|
|
3810
4146
|
$type: "color",
|
|
3811
4147
|
$value: "{<theme>.<color>.10}"
|
|
3812
4148
|
},
|
|
3813
|
-
"11": {
|
|
3814
|
-
$type: "color",
|
|
3815
|
-
$value: "{<theme>.<color>.11}"
|
|
3816
|
-
},
|
|
3817
|
-
"12": {
|
|
3818
|
-
$type: "color",
|
|
3819
|
-
$value: "{<theme>.<color>.12}"
|
|
3820
|
-
},
|
|
3821
|
-
"13": {
|
|
3822
|
-
$type: "color",
|
|
3823
|
-
$value: "{<theme>.<color>.13}"
|
|
3824
|
-
},
|
|
3825
|
-
"14": {
|
|
3826
|
-
$type: "color",
|
|
3827
|
-
$value: "{<theme>.<color>.14}"
|
|
3828
|
-
},
|
|
3829
|
-
"15": {
|
|
3830
|
-
$type: "color",
|
|
3831
|
-
$value: "{<theme>.<color>.15}"
|
|
3832
|
-
},
|
|
3833
|
-
"16": {
|
|
3834
|
-
$type: "color",
|
|
3835
|
-
$value: "{<theme>.<color>.16}"
|
|
3836
|
-
}
|
|
3837
|
-
};
|
|
3838
|
-
|
|
3839
|
-
// src/tokens/create/generators/theme.ts
|
|
3840
|
-
var generateTheme = (colors2, themeName, borderRadius) => {
|
|
3841
|
-
const mainColorNames = Object.keys(colors2.main);
|
|
3842
|
-
const supportColorNames = Object.keys(colors2.support);
|
|
3843
|
-
const customColors = [...mainColorNames, "neutral", ...supportColorNames];
|
|
3844
|
-
const themeColorTokens = Object.fromEntries(
|
|
3845
|
-
customColors.map(
|
|
3846
|
-
(colorName) => [
|
|
3847
|
-
colorName,
|
|
3848
|
-
R22.map((x) => ({ ...x, $value: x.$value.replace("<color>", colorName) }), theme_template_default)
|
|
3849
|
-
]
|
|
3850
|
-
)
|
|
3851
|
-
);
|
|
3852
|
-
const { color: themeBaseFileColor, ...remainingThemeFile } = theme_base_template_default;
|
|
3853
|
-
const themeFile = {
|
|
3854
|
-
color: {
|
|
3855
|
-
...themeColorTokens,
|
|
3856
|
-
...themeBaseFileColor
|
|
3857
|
-
},
|
|
3858
|
-
...remainingThemeFile
|
|
3859
|
-
};
|
|
3860
|
-
const baseBorderRadius = R22.lensPath(["border-radius", "base", "$value"]);
|
|
3861
|
-
const updatedThemeFile = R22.set(baseBorderRadius, String(borderRadius), themeFile);
|
|
3862
|
-
const token = JSON.parse(
|
|
3863
|
-
JSON.stringify(
|
|
3864
|
-
updatedThemeFile,
|
|
3865
|
-
(key, value) => {
|
|
3866
|
-
if (key === "$value") {
|
|
3867
|
-
return value.replace("<theme>", themeName);
|
|
3868
|
-
}
|
|
3869
|
-
return value;
|
|
3870
|
-
},
|
|
3871
|
-
2
|
|
3872
|
-
)
|
|
3873
|
-
);
|
|
3874
|
-
return token;
|
|
3875
|
-
};
|
|
3876
|
-
|
|
3877
|
-
// src/tokens/template/design-tokens/primitives/modes/typography/typography.template.json with { type: 'json' }
|
|
3878
|
-
var typography_template_default = {
|
|
3879
|
-
"<theme>": {
|
|
3880
|
-
"font-family": {
|
|
3881
|
-
$type: "fontFamilies",
|
|
3882
|
-
$value: "<font-family>"
|
|
3883
|
-
},
|
|
3884
|
-
"font-weight": {
|
|
3885
|
-
medium: {
|
|
3886
|
-
$type: "fontWeights",
|
|
3887
|
-
$value: "Medium"
|
|
3888
|
-
},
|
|
3889
|
-
semibold: {
|
|
3890
|
-
$type: "fontWeights",
|
|
3891
|
-
$value: "Semi bold"
|
|
3892
|
-
},
|
|
3893
|
-
regular: {
|
|
3894
|
-
$type: "fontWeights",
|
|
3895
|
-
$value: "Regular"
|
|
3896
|
-
}
|
|
3897
|
-
}
|
|
3898
|
-
}
|
|
3899
|
-
};
|
|
3900
|
-
|
|
3901
|
-
// src/tokens/create/generators/typography.ts
|
|
3902
|
-
var generateTypography = (themeName, { fontFamily }) => {
|
|
3903
|
-
return JSON.parse(
|
|
3904
|
-
JSON.stringify(typography_template_default).replaceAll(/<font-family>/g, fontFamily).replaceAll(/<theme>/g, themeName)
|
|
3905
|
-
);
|
|
3906
|
-
};
|
|
3907
|
-
|
|
3908
|
-
// src/tokens/create.ts
|
|
3909
|
-
var cliOptions = {
|
|
3910
|
-
outDir: "out-dir",
|
|
3911
|
-
clean: "clean",
|
|
3912
|
-
theme: {
|
|
3913
|
-
colors: {
|
|
3914
|
-
main: "main-colors",
|
|
3915
|
-
support: "support-colors",
|
|
3916
|
-
neutral: "neutral-color"
|
|
3917
|
-
},
|
|
3918
|
-
typography: {
|
|
3919
|
-
fontFamily: "font-family"
|
|
3920
|
-
},
|
|
3921
|
-
borderRadius: "border-radius"
|
|
3922
|
-
}
|
|
3923
|
-
};
|
|
3924
|
-
var createTokens = async (opts) => {
|
|
3925
|
-
const { colors: colors2, typography: typography2, name, borderRadius } = opts;
|
|
3926
|
-
const colorSchemes = ["light", "dark"];
|
|
3927
|
-
const semantic2 = generateSemantic(colors2);
|
|
3928
|
-
const tokenSets = new Map([
|
|
3929
|
-
...getDefaultTokens([
|
|
3930
|
-
"primitives/globals",
|
|
3931
|
-
"primitives/modes/size/small",
|
|
3932
|
-
"primitives/modes/size/medium",
|
|
3933
|
-
"primitives/modes/size/large",
|
|
3934
|
-
"primitives/modes/size/global",
|
|
3935
|
-
"primitives/modes/typography/size/small",
|
|
3936
|
-
"primitives/modes/typography/size/medium",
|
|
3937
|
-
"primitives/modes/typography/size/large"
|
|
3938
|
-
]),
|
|
3939
|
-
[`primitives/modes/typography/primary/${name}`, generateTypography(name, typography2)],
|
|
3940
|
-
[`primitives/modes/typography/secondary/${name}`, generateTypography(name, typography2)],
|
|
3941
|
-
...colorSchemes.flatMap((scheme) => [
|
|
3942
|
-
[`primitives/modes/color-scheme/${scheme}/global`, generateColorGlobal(scheme)],
|
|
3943
|
-
[`primitives/modes/color-scheme/${scheme}/${name}`, generateColorScheme(name, scheme, colors2)]
|
|
3944
|
-
]),
|
|
3945
|
-
[`themes/${name}`, generateTheme(colors2, name, borderRadius)],
|
|
3946
|
-
["semantic/color", semantic2.color],
|
|
3947
|
-
// maps out semantic modes, ieg 'semantic/modes/main-color/accent', and 'semantic/modes/support-color/brand1'
|
|
3948
|
-
...Object.entries(semantic2.modes).flatMap(
|
|
3949
|
-
([mode, colors3]) => Object.entries(colors3).map(([key, colorSet]) => [`semantic/modes/${mode}/${key}`, colorSet])
|
|
3950
|
-
),
|
|
3951
|
-
getDefaultToken("semantic/style")
|
|
3952
|
-
]);
|
|
3953
|
-
return { tokenSets };
|
|
3954
|
-
};
|
|
3955
|
-
|
|
3956
|
-
// src/tokens/create/write.ts
|
|
3957
|
-
import path2 from "path";
|
|
3958
|
-
import chalk7 from "chalk";
|
|
3959
|
-
import * as R23 from "ramda";
|
|
3960
|
-
|
|
3961
|
-
// src/tokens/create/generators/$designsystemet.ts
|
|
3962
|
-
function generate$Designsystemet() {
|
|
3963
|
-
return {
|
|
3964
|
-
name: package_default.name,
|
|
3965
|
-
version: package_default.version
|
|
3966
|
-
};
|
|
3967
|
-
}
|
|
3968
|
-
|
|
3969
|
-
// src/tokens/create/generators/$metadata.ts
|
|
3970
|
-
function generate$Metadata(schemes, themes, colors2) {
|
|
3971
|
-
return {
|
|
3972
|
-
tokenSetOrder: [
|
|
3973
|
-
"primitives/globals",
|
|
3974
|
-
"primitives/modes/size/small",
|
|
3975
|
-
"primitives/modes/size/medium",
|
|
3976
|
-
"primitives/modes/size/large",
|
|
3977
|
-
"primitives/modes/size/global",
|
|
3978
|
-
"primitives/modes/typography/size/small",
|
|
3979
|
-
"primitives/modes/typography/size/medium",
|
|
3980
|
-
"primitives/modes/typography/size/large",
|
|
3981
|
-
...themes.map((theme) => `primitives/modes/typography/primary/${theme}`),
|
|
3982
|
-
...themes.map((theme) => `primitives/modes/typography/secondary/${theme}`),
|
|
3983
|
-
...schemes.flatMap((scheme) => [
|
|
3984
|
-
`primitives/modes/color-scheme/${scheme}/global`,
|
|
3985
|
-
...themes.map((theme) => `primitives/modes/color-scheme/${scheme}/${theme}`)
|
|
3986
|
-
]),
|
|
3987
|
-
...themes.map((theme) => `themes/${theme}`),
|
|
3988
|
-
"semantic/color",
|
|
3989
|
-
...Object.entries(colors2.main).map(([color]) => `semantic/modes/main-color/${color}`),
|
|
3990
|
-
...Object.entries(colors2.support).map(([color]) => `semantic/modes/support-color/${color}`),
|
|
3991
|
-
"semantic/style"
|
|
3992
|
-
]
|
|
3993
|
-
};
|
|
3994
|
-
}
|
|
3995
|
-
|
|
3996
|
-
// src/tokens/create/generators/$themes.ts
|
|
3997
|
-
var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
|
|
3998
|
-
async function createHash(text, algo = "SHA-1") {
|
|
3999
|
-
const crypto = globalThis.crypto;
|
|
4000
|
-
return Array.from(
|
|
4001
|
-
new Uint8Array(await crypto.subtle.digest(algo, new TextEncoder().encode(text))),
|
|
4002
|
-
(byte) => byte.toString(16).padStart(2, "0")
|
|
4003
|
-
).join("");
|
|
4004
|
-
}
|
|
4005
|
-
async function generate$Themes(colorSchemes, themes, colors2) {
|
|
4006
|
-
return [
|
|
4007
|
-
...generateSizeGroup(),
|
|
4008
|
-
...await generateThemesGroup(themes),
|
|
4009
|
-
...generateTypographyGroup(themes),
|
|
4010
|
-
...generateColorSchemesGroup(colorSchemes, themes),
|
|
4011
|
-
generateSemanticGroup(),
|
|
4012
|
-
...await generateColorGroup("main", colors2),
|
|
4013
|
-
...await generateColorGroup("support", colors2)
|
|
4014
|
-
];
|
|
4015
|
-
}
|
|
4016
|
-
function generateSizeGroup() {
|
|
4017
|
-
return [
|
|
4018
|
-
{
|
|
4019
|
-
id: "8b2c8cc86611a34b135cb22948666779361fd729",
|
|
4020
|
-
name: "medium",
|
|
4021
|
-
$figmaStyleReferences: {},
|
|
4022
|
-
selectedTokenSets: {
|
|
4023
|
-
"primitives/modes/size/medium": TokenSetStatus.SOURCE,
|
|
4024
|
-
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
4025
|
-
"primitives/modes/typography/size/medium": TokenSetStatus.ENABLED
|
|
4026
|
-
},
|
|
4027
|
-
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
4028
|
-
$figmaModeId: "41630:1",
|
|
4029
|
-
group: "Size"
|
|
4030
|
-
},
|
|
4031
|
-
{
|
|
4032
|
-
id: "d49b9eebeb48a4f165a74b7261733d0a73370f0e",
|
|
4033
|
-
name: "large",
|
|
4034
|
-
$figmaStyleReferences: {},
|
|
4035
|
-
selectedTokenSets: {
|
|
4036
|
-
"primitives/modes/size/large": TokenSetStatus.SOURCE,
|
|
4037
|
-
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
4038
|
-
"primitives/modes/typography/size/large": TokenSetStatus.ENABLED
|
|
4039
|
-
},
|
|
4040
|
-
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
4041
|
-
$figmaModeId: "41630:2",
|
|
4042
|
-
group: "Size"
|
|
4043
|
-
},
|
|
4044
|
-
{
|
|
4045
|
-
id: "fb11567729c298ca37c9da4e3a27716a23480824",
|
|
4046
|
-
name: "small",
|
|
4047
|
-
$figmaStyleReferences: {},
|
|
4048
|
-
selectedTokenSets: {
|
|
4049
|
-
"primitives/modes/size/small": TokenSetStatus.SOURCE,
|
|
4050
|
-
"primitives/modes/size/global": TokenSetStatus.ENABLED,
|
|
4051
|
-
"primitives/modes/typography/size/small": TokenSetStatus.ENABLED
|
|
4052
|
-
},
|
|
4053
|
-
$figmaCollectionId: "VariableCollectionId:36248:20757",
|
|
4054
|
-
$figmaModeId: "41630:3",
|
|
4055
|
-
group: "Size"
|
|
4056
|
-
}
|
|
4057
|
-
];
|
|
4058
|
-
}
|
|
4059
|
-
var colorSchemeDefaults = {
|
|
4060
|
-
light: {
|
|
4061
|
-
name: "Light",
|
|
4062
|
-
selectedTokenSets: {},
|
|
4063
|
-
id: "0daa3ca0b427b9349da7e7dc00101b5668972926",
|
|
4064
|
-
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
4065
|
-
$figmaModeId: "34811:0"
|
|
4066
|
-
},
|
|
4067
|
-
dark: {
|
|
4068
|
-
name: "Dark",
|
|
4069
|
-
selectedTokenSets: {},
|
|
4070
|
-
id: "9ebd8aed52afbffc17e2666e8b4653a53498b257",
|
|
4071
|
-
$figmaCollectionId: "VariableCollectionId:34811:5472",
|
|
4072
|
-
$figmaModeId: "34811:1"
|
|
4149
|
+
"11": {
|
|
4150
|
+
$type: "color",
|
|
4151
|
+
$value: "{<theme>.<color>.11}"
|
|
4073
4152
|
},
|
|
4074
|
-
|
|
4075
|
-
|
|
4076
|
-
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
$
|
|
4153
|
+
"12": {
|
|
4154
|
+
$type: "color",
|
|
4155
|
+
$value: "{<theme>.<color>.12}"
|
|
4156
|
+
},
|
|
4157
|
+
"13": {
|
|
4158
|
+
$type: "color",
|
|
4159
|
+
$value: "{<theme>.<color>.13}"
|
|
4160
|
+
},
|
|
4161
|
+
"14": {
|
|
4162
|
+
$type: "color",
|
|
4163
|
+
$value: "{<theme>.<color>.14}"
|
|
4164
|
+
},
|
|
4165
|
+
"15": {
|
|
4166
|
+
$type: "color",
|
|
4167
|
+
$value: "{<theme>.<color>.15}"
|
|
4168
|
+
},
|
|
4169
|
+
"16": {
|
|
4170
|
+
$type: "color",
|
|
4171
|
+
$value: "{<theme>.<color>.16}"
|
|
4080
4172
|
}
|
|
4081
4173
|
};
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
async function generateThemesGroup(themes) {
|
|
4095
|
-
return Promise.all(
|
|
4096
|
-
themes.map(
|
|
4097
|
-
async (theme, index) => ({
|
|
4098
|
-
id: await createHash(theme),
|
|
4099
|
-
$figmaCollectionId: "VariableCollectionId:36528:61712",
|
|
4100
|
-
$figmaModeId: `40960:${index + 6}`,
|
|
4101
|
-
// Start on 6 in Token Studio and Community file for some reason
|
|
4102
|
-
name: theme,
|
|
4103
|
-
selectedTokenSets: {
|
|
4104
|
-
[`themes/${theme}`]: TokenSetStatus.ENABLED
|
|
4105
|
-
},
|
|
4106
|
-
group: "Theme"
|
|
4107
|
-
})
|
|
4174
|
+
|
|
4175
|
+
// src/tokens/create/generators/theme.ts
|
|
4176
|
+
var generateTheme = (colors2, themeName, borderRadius) => {
|
|
4177
|
+
const mainColorNames = Object.keys(colors2.main);
|
|
4178
|
+
const supportColorNames = Object.keys(colors2.support);
|
|
4179
|
+
const customColors = [...mainColorNames, "neutral", ...supportColorNames];
|
|
4180
|
+
const themeColorTokens = Object.fromEntries(
|
|
4181
|
+
customColors.map(
|
|
4182
|
+
(colorName) => [
|
|
4183
|
+
colorName,
|
|
4184
|
+
R23.map((x) => ({ ...x, $value: x.$value.replace("<color>", colorName) }), theme_template_default)
|
|
4185
|
+
]
|
|
4108
4186
|
)
|
|
4109
4187
|
);
|
|
4110
|
-
}
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
selectedTokenSets: {
|
|
4116
|
-
"semantic/style": TokenSetStatus.ENABLED,
|
|
4117
|
-
"semantic/color": TokenSetStatus.ENABLED,
|
|
4118
|
-
"primitives/globals": TokenSetStatus.SOURCE
|
|
4188
|
+
const { color: themeBaseFileColor, ...remainingThemeFile } = theme_base_template_default;
|
|
4189
|
+
const themeFile = {
|
|
4190
|
+
color: {
|
|
4191
|
+
...themeColorTokens,
|
|
4192
|
+
...themeBaseFileColor
|
|
4119
4193
|
},
|
|
4120
|
-
|
|
4121
|
-
$figmaModeId: "34811:5",
|
|
4122
|
-
group: "Semantic"
|
|
4194
|
+
...remainingThemeFile
|
|
4123
4195
|
};
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4196
|
+
const baseBorderRadius = R23.lensPath(["border-radius", "base", "$value"]);
|
|
4197
|
+
const updatedThemeFile = R23.set(baseBorderRadius, String(borderRadius), themeFile);
|
|
4198
|
+
const token = JSON.parse(
|
|
4199
|
+
JSON.stringify(
|
|
4200
|
+
updatedThemeFile,
|
|
4201
|
+
(key, value) => {
|
|
4202
|
+
if (key === "$value") {
|
|
4203
|
+
return value.replace("<theme>", themeName);
|
|
4204
|
+
}
|
|
4205
|
+
return value;
|
|
4206
|
+
},
|
|
4207
|
+
2
|
|
4136
4208
|
)
|
|
4137
4209
|
);
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
return [
|
|
4141
|
-
{
|
|
4142
|
-
id: "368d753fcac4455f289500eaa42e70dc0a03522f",
|
|
4143
|
-
$figmaCollectionId: "VariableCollectionId:36248:20769",
|
|
4144
|
-
$figmaModeId: "36248:2",
|
|
4145
|
-
name: "Primary",
|
|
4146
|
-
selectedTokenSets: Object.fromEntries(
|
|
4147
|
-
themes.map((theme) => [`primitives/modes/typography/primary/${theme}`, TokenSetStatus.ENABLED])
|
|
4148
|
-
),
|
|
4149
|
-
group: "Typography"
|
|
4150
|
-
},
|
|
4151
|
-
{
|
|
4152
|
-
id: "264b8bd1d40b364e1ea3acf09e49795ddd4c513c",
|
|
4153
|
-
$figmaCollectionId: "VariableCollectionId:36248:20769",
|
|
4154
|
-
$figmaModeId: "36248:3",
|
|
4155
|
-
name: "Secondary",
|
|
4156
|
-
selectedTokenSets: Object.fromEntries(
|
|
4157
|
-
themes.map((theme) => [`primitives/modes/typography/secondary/${theme}`, TokenSetStatus.ENABLED])
|
|
4158
|
-
),
|
|
4159
|
-
group: "Typography"
|
|
4160
|
-
}
|
|
4161
|
-
];
|
|
4162
|
-
}
|
|
4210
|
+
return token;
|
|
4211
|
+
};
|
|
4163
4212
|
|
|
4164
|
-
// src/tokens/
|
|
4165
|
-
var
|
|
4166
|
-
|
|
4167
|
-
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4175
|
-
|
|
4176
|
-
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4213
|
+
// src/tokens/template/design-tokens/primitives/modes/typography/typography.template.json with { type: 'json' }
|
|
4214
|
+
var typography_template_default = {
|
|
4215
|
+
"<theme>": {
|
|
4216
|
+
"font-family": {
|
|
4217
|
+
$type: "fontFamilies",
|
|
4218
|
+
$value: "<font-family>"
|
|
4219
|
+
},
|
|
4220
|
+
"font-weight": {
|
|
4221
|
+
medium: {
|
|
4222
|
+
$type: "fontWeights",
|
|
4223
|
+
$value: "Medium"
|
|
4224
|
+
},
|
|
4225
|
+
semibold: {
|
|
4226
|
+
$type: "fontWeights",
|
|
4227
|
+
$value: "Semi bold"
|
|
4228
|
+
},
|
|
4229
|
+
regular: {
|
|
4230
|
+
$type: "fontWeights",
|
|
4231
|
+
$value: "Regular"
|
|
4232
|
+
}
|
|
4183
4233
|
}
|
|
4184
|
-
} catch (error) {
|
|
4185
4234
|
}
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4235
|
+
};
|
|
4236
|
+
|
|
4237
|
+
// src/tokens/create/generators/typography.ts
|
|
4238
|
+
var generateTypography = (themeName, { fontFamily }) => {
|
|
4239
|
+
return JSON.parse(
|
|
4240
|
+
JSON.stringify(typography_template_default).replaceAll(/<font-family>/g, fontFamily).replaceAll(/<theme>/g, themeName)
|
|
4192
4241
|
);
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
|
|
4205
|
-
|
|
4206
|
-
|
|
4242
|
+
};
|
|
4243
|
+
|
|
4244
|
+
// src/tokens/create.ts
|
|
4245
|
+
var cliOptions = {
|
|
4246
|
+
outDir: "out-dir",
|
|
4247
|
+
clean: "clean",
|
|
4248
|
+
tailwind: "tailwind",
|
|
4249
|
+
theme: {
|
|
4250
|
+
colors: {
|
|
4251
|
+
main: "main-colors",
|
|
4252
|
+
support: "support-colors",
|
|
4253
|
+
neutral: "neutral-color"
|
|
4254
|
+
},
|
|
4255
|
+
typography: {
|
|
4256
|
+
fontFamily: "font-family"
|
|
4257
|
+
},
|
|
4258
|
+
borderRadius: "border-radius"
|
|
4207
4259
|
}
|
|
4208
|
-
|
|
4209
|
-
|
|
4210
|
-
|
|
4260
|
+
};
|
|
4261
|
+
var createTokens = async (opts) => {
|
|
4262
|
+
const { colors: colors2, typography: typography2, name, borderRadius } = opts;
|
|
4263
|
+
const colorSchemes = ["light", "dark"];
|
|
4264
|
+
const semantic2 = generateSemantic(colors2);
|
|
4265
|
+
const tokenSets = new Map([
|
|
4266
|
+
...getDefaultTokens([
|
|
4267
|
+
"primitives/globals",
|
|
4268
|
+
"primitives/modes/size/small",
|
|
4269
|
+
"primitives/modes/size/medium",
|
|
4270
|
+
"primitives/modes/size/large",
|
|
4271
|
+
"primitives/modes/size/global",
|
|
4272
|
+
"primitives/modes/typography/size/small",
|
|
4273
|
+
"primitives/modes/typography/size/medium",
|
|
4274
|
+
"primitives/modes/typography/size/large"
|
|
4275
|
+
]),
|
|
4276
|
+
[`primitives/modes/typography/primary/${name}`, generateTypography(name, typography2)],
|
|
4277
|
+
[`primitives/modes/typography/secondary/${name}`, generateTypography(name, typography2)],
|
|
4278
|
+
...colorSchemes.flatMap((scheme) => [
|
|
4279
|
+
[`primitives/modes/color-scheme/${scheme}/global`, generateColorGlobal(scheme)],
|
|
4280
|
+
[`primitives/modes/color-scheme/${scheme}/${name}`, generateColorScheme(name, scheme, colors2)]
|
|
4281
|
+
]),
|
|
4282
|
+
[`themes/${name}`, generateTheme(colors2, name, borderRadius)],
|
|
4283
|
+
["semantic/color", semantic2.color],
|
|
4284
|
+
// maps out semantic modes, ieg 'semantic/modes/main-color/accent', and 'semantic/modes/support-color/brand1'
|
|
4285
|
+
...Object.entries(semantic2.modes).flatMap(
|
|
4286
|
+
([mode, colors3]) => Object.entries(colors3).map(([key, colorSet]) => [`semantic/modes/${mode}/${key}`, colorSet])
|
|
4287
|
+
),
|
|
4288
|
+
getDefaultToken("semantic/style")
|
|
4289
|
+
]);
|
|
4290
|
+
return { tokenSets };
|
|
4211
4291
|
};
|
|
4212
4292
|
|
|
4213
4293
|
// bin/config.ts
|
|
4214
4294
|
import path4 from "path";
|
|
4215
|
-
import
|
|
4295
|
+
import chalk10 from "chalk";
|
|
4216
4296
|
import * as R25 from "ramda";
|
|
4217
4297
|
|
|
4218
4298
|
// src/config.ts
|
|
4219
|
-
import
|
|
4299
|
+
import chalk9 from "chalk";
|
|
4220
4300
|
import * as R24 from "ramda";
|
|
4221
|
-
import { fromError } from "zod-validation-error";
|
|
4222
4301
|
import { z } from "zod/v4";
|
|
4302
|
+
import { fromError } from "zod-validation-error/v4";
|
|
4223
4303
|
function mapPathToOptionName(path5) {
|
|
4224
4304
|
const normalisedPath = path5[0] === "themes" ? ["theme", ...R24.drop(2, path5)] : path5;
|
|
4225
4305
|
const option = R24.path(normalisedPath, cliOptions);
|
|
@@ -4229,38 +4309,42 @@ function mapPathToOptionName(path5) {
|
|
|
4229
4309
|
return option;
|
|
4230
4310
|
}
|
|
4231
4311
|
function makeFriendlyError(err) {
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4312
|
+
try {
|
|
4313
|
+
return fromError(err, {
|
|
4314
|
+
messageBuilder: (issues) => issues.map((issue) => {
|
|
4315
|
+
const issuePath = issue.path.join(".");
|
|
4316
|
+
const optionName = mapPathToOptionName(issue.path);
|
|
4317
|
+
const errorCode = `(error code: ${issue.code})`;
|
|
4318
|
+
const optionMessage = optionName ? ` or CLI option --${optionName}` : "";
|
|
4319
|
+
return ` - Error in JSON value ${chalk9.red(issuePath)}${optionMessage}:
|
|
4320
|
+
${issue.message} ${chalk9.dim(errorCode)}`;
|
|
4321
|
+
}).join("\n")
|
|
4322
|
+
});
|
|
4323
|
+
} catch (_err2) {
|
|
4324
|
+
console.error(chalk9.red(err instanceof Error ? err.message : "Unknown error occurred while parsing config file"));
|
|
4325
|
+
console.error(err instanceof Error ? err.stack : "No stack trace available");
|
|
4326
|
+
}
|
|
4242
4327
|
}
|
|
4243
4328
|
function validateConfig(schema, unvalidatedConfig, configPath) {
|
|
4244
4329
|
try {
|
|
4245
4330
|
return schema.parse(unvalidatedConfig);
|
|
4246
4331
|
} catch (err) {
|
|
4247
|
-
console.error(
|
|
4332
|
+
console.error(chalk9.redBright(`Invalid config file at ${chalk9.red(configPath)}`));
|
|
4248
4333
|
const validationError = makeFriendlyError(err);
|
|
4249
|
-
console.error(validationError
|
|
4334
|
+
console.error(validationError?.toString());
|
|
4250
4335
|
process.exit(1);
|
|
4251
4336
|
}
|
|
4252
4337
|
}
|
|
4253
|
-
function parseConfig(
|
|
4338
|
+
function parseConfig(configFile, configPath) {
|
|
4254
4339
|
if (!configFile) {
|
|
4255
4340
|
return {};
|
|
4256
4341
|
}
|
|
4257
4342
|
try {
|
|
4258
|
-
|
|
4259
|
-
return schema.parse(parsedConfig);
|
|
4343
|
+
return JSON.parse(configFile);
|
|
4260
4344
|
} catch (err) {
|
|
4261
|
-
console.error(
|
|
4345
|
+
console.error(chalk9.redBright(`Failed parsing config file at ${chalk9.red(configPath)}`));
|
|
4262
4346
|
const validationError = makeFriendlyError(err);
|
|
4263
|
-
console.error(validationError
|
|
4347
|
+
console.error(validationError?.toString());
|
|
4264
4348
|
process.exit(1);
|
|
4265
4349
|
}
|
|
4266
4350
|
}
|
|
@@ -4298,17 +4382,16 @@ var themeSchema = z.object({
|
|
|
4298
4382
|
}).describe("Defines the typography for a given theme").optional(),
|
|
4299
4383
|
borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional()
|
|
4300
4384
|
}).meta({ description: "An object defining a theme. The property name holding the object becomes the theme name." });
|
|
4301
|
-
var
|
|
4385
|
+
var commonConfig = z.object({
|
|
4302
4386
|
clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional()
|
|
4303
4387
|
});
|
|
4304
|
-
var
|
|
4388
|
+
var _configFileCreateSchema = z.object({
|
|
4305
4389
|
outDir: z.string().meta({ description: "Path to the output directory for the created design tokens" }),
|
|
4306
|
-
clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional(),
|
|
4307
4390
|
themes: z.record(z.string(), themeSchema).meta({
|
|
4308
4391
|
description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
|
|
4309
4392
|
})
|
|
4310
4393
|
}).required();
|
|
4311
|
-
var
|
|
4394
|
+
var configFileCreateSchema = _configFileCreateSchema.extend(commonConfig.shape);
|
|
4312
4395
|
|
|
4313
4396
|
// bin/options.ts
|
|
4314
4397
|
var getOptionIfMatchingSource = (...sources) => (command, option) => {
|
|
@@ -4331,26 +4414,22 @@ async function readConfigFile(configPath, allowFileNotFound = true) {
|
|
|
4331
4414
|
if (allowFileNotFound) {
|
|
4332
4415
|
return "";
|
|
4333
4416
|
}
|
|
4334
|
-
console.error(
|
|
4417
|
+
console.error(chalk10.redBright(`Could not read config file at ${chalk10.blue(resolvedPath)}`));
|
|
4335
4418
|
throw err;
|
|
4336
4419
|
}
|
|
4337
4420
|
if (configFile) {
|
|
4338
|
-
console.log(`Found config file: ${
|
|
4421
|
+
console.log(`Found config file: ${chalk10.green(resolvedPath)}`);
|
|
4339
4422
|
}
|
|
4340
4423
|
return configFile;
|
|
4341
4424
|
}
|
|
4342
4425
|
async function parseCreateConfig(configFile, options) {
|
|
4343
4426
|
const { cmd, theme = "theme", configPath } = options;
|
|
4344
|
-
const configParsed = parseConfig(
|
|
4345
|
-
configFileCreateSchema,
|
|
4346
|
-
configFile,
|
|
4347
|
-
configPath
|
|
4348
|
-
);
|
|
4427
|
+
const configParsed = parseConfig(configFile, configPath);
|
|
4349
4428
|
const themeColors = Object.values(configParsed?.themes ?? {}).map(
|
|
4350
4429
|
(x) => /* @__PURE__ */ new Set([...R25.keys(x.colors.main), ...R25.keys(x.colors.support)])
|
|
4351
4430
|
);
|
|
4352
4431
|
if (!R25.all(R25.equals(R25.__, themeColors[0]), themeColors)) {
|
|
4353
|
-
console.error(
|
|
4432
|
+
console.error(chalk10.redBright(`In config, all themes must have the same custom color names, but we found:`));
|
|
4354
4433
|
const themeNames = R25.keys(configParsed.themes ?? {});
|
|
4355
4434
|
themeColors.forEach((colors2, index) => {
|
|
4356
4435
|
const colorNames = Array.from(colors2);
|
|
@@ -4391,8 +4470,8 @@ async function parseCreateConfig(configFile, options) {
|
|
|
4391
4470
|
return validateConfig(configFileCreateSchema, unvalidatedConfig, configPath);
|
|
4392
4471
|
}
|
|
4393
4472
|
async function parseBuildConfig(configFile, { configPath }) {
|
|
4394
|
-
const configParsed = parseConfig(
|
|
4395
|
-
return validateConfig(
|
|
4473
|
+
const configParsed = parseConfig(configFile, configPath);
|
|
4474
|
+
return validateConfig(commonConfig, configParsed, configPath);
|
|
4396
4475
|
}
|
|
4397
4476
|
|
|
4398
4477
|
// bin/designsystemet.ts
|
|
@@ -4404,12 +4483,12 @@ var DEFAULT_THEME_NAME = "theme";
|
|
|
4404
4483
|
var DEFAULT_CONFIG_FILE = "designsystemet.config.json";
|
|
4405
4484
|
function makeTokenCommands() {
|
|
4406
4485
|
const tokenCmd = createCommand("tokens");
|
|
4407
|
-
tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${
|
|
4486
|
+
tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${chalk11.blue("design-tokens")}`, DEFAULT_TOKENS_CREATE_DIR).option(
|
|
4408
4487
|
"-o, --out-dir <string>",
|
|
4409
|
-
`Output directory for built ${
|
|
4488
|
+
`Output directory for built ${chalk11.blue("design-tokens")}`,
|
|
4410
4489
|
DEFAULT_TOKENS_BUILD_DIR
|
|
4411
|
-
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before building tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for built ${
|
|
4412
|
-
const { preview, verbose, clean, dry } = opts;
|
|
4490
|
+
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before building tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for built ${chalk11.blue("design-tokens")}`, parseBoolean, false).option("-p, --preview", "Generate preview token.ts files", false).option("--verbose", "Enable verbose output", false).option("--config <string>", `Path to config file (default: "${DEFAULT_CONFIG_FILE}")`).option("--experimental-tailwind", "Generate Tailwind CSS classes for tokens", false).action(async (opts) => {
|
|
4491
|
+
const { preview, verbose, clean, dry, experimentalTailwind } = opts;
|
|
4413
4492
|
const tokensDir = typeof opts.tokens === "string" ? opts.tokens : DEFAULT_TOKENS_CREATE_DIR;
|
|
4414
4493
|
const outDir = typeof opts.outDir === "string" ? opts.outDir : "./dist/tokens";
|
|
4415
4494
|
const { configFile, configPath } = await getConfigFile(opts.config);
|
|
@@ -4420,14 +4499,14 @@ function makeTokenCommands() {
|
|
|
4420
4499
|
if (clean) {
|
|
4421
4500
|
await cleanDir(outDir, dry);
|
|
4422
4501
|
}
|
|
4423
|
-
await buildTokens({ tokensDir, outDir, preview, verbose, dry, ...config });
|
|
4502
|
+
await buildTokens({ tokensDir, outDir, preview, verbose, dry, tailwind: experimentalTailwind, ...config });
|
|
4424
4503
|
return Promise.resolve();
|
|
4425
4504
|
});
|
|
4426
4505
|
tokenCmd.command("create").description("Create Designsystemet tokens").option(`-m, --${cliOptions.theme.colors.main} <name:hex...>`, `Main colors`, parseColorValues).option(`-s, --${cliOptions.theme.colors.support} <name:hex...>`, `Support colors`, parseColorValues).option(`-n, --${cliOptions.theme.colors.neutral} <hex>`, `Neutral hex color`, convertToHex).option(
|
|
4427
4506
|
`-o, --${cliOptions.outDir} <string>`,
|
|
4428
|
-
`Output directory for created ${
|
|
4507
|
+
`Output directory for created ${chalk11.blue("design-tokens")}`,
|
|
4429
4508
|
DEFAULT_TOKENS_CREATE_DIR
|
|
4430
|
-
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${
|
|
4509
|
+
).option(`--${cliOptions.clean} [boolean]`, "Clean output directory before creating tokens", parseBoolean, false).option("--dry [boolean]", `Dry run for created ${chalk11.blue("design-tokens")}`, parseBoolean, false).option(`-f, --${cliOptions.theme.typography.fontFamily} <string>`, `Font family (experimental)`, DEFAULT_FONT).option(
|
|
4431
4510
|
`-b, --${cliOptions.theme.borderRadius} <number>`,
|
|
4432
4511
|
`Unitless base border-radius in px`,
|
|
4433
4512
|
(radiusAsString) => Number(radiusAsString),
|
|
@@ -4468,8 +4547,8 @@ program.command("migrate").description("run a Designsystemet migration").addArgu
|
|
|
4468
4547
|
console.error("Migration not found!");
|
|
4469
4548
|
throw "Aborting";
|
|
4470
4549
|
}
|
|
4471
|
-
console.log(`Applying migration ${
|
|
4472
|
-
migration?.(glob2).then(() => console.log(`Migration ${
|
|
4550
|
+
console.log(`Applying migration ${chalk11.blue(migrationKey)} with glob: ${chalk11.green(glob2)}`);
|
|
4551
|
+
migration?.(glob2).then(() => console.log(`Migration ${chalk11.blue(migrationKey)} finished`)).catch((error) => console.log(error));
|
|
4473
4552
|
} else {
|
|
4474
4553
|
console.log("Migrate: please specify a migration name or --list");
|
|
4475
4554
|
}
|
|
@@ -4480,7 +4559,7 @@ function parseColorValues(value, previous = {}) {
|
|
|
4480
4559
|
previous[name] = convertToHex(hex);
|
|
4481
4560
|
return previous;
|
|
4482
4561
|
}
|
|
4483
|
-
function parseBoolean(value
|
|
4562
|
+
function parseBoolean(value) {
|
|
4484
4563
|
return value === "true" || value === true;
|
|
4485
4564
|
}
|
|
4486
4565
|
async function getConfigFile(config) {
|