@digdir/designsystemet 1.13.2 → 1.13.3

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.
Files changed (74) hide show
  1. package/dist/bin/config.js +50 -658
  2. package/dist/bin/designsystemet.js +131 -4623
  3. package/dist/bin/options.js +22 -14
  4. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +9 -0
  5. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +8 -0
  6. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +13 -0
  7. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +10 -0
  8. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +10 -0
  9. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +53 -0
  10. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +14 -0
  11. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +9 -0
  12. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +32 -0
  13. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +15 -0
  14. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/index.js +11 -0
  15. package/dist/package.js +5 -0
  16. package/dist/src/colors/colorMetadata.js +255 -261
  17. package/dist/src/colors/index.js +5 -522
  18. package/dist/src/colors/theme.js +104 -343
  19. package/dist/src/colors/types.js +22 -25
  20. package/dist/src/colors/utils.js +241 -154
  21. package/dist/src/config.js +103 -444
  22. package/dist/src/index.js +10 -3588
  23. package/dist/src/migrations/beta-to-v1.js +339 -537
  24. package/dist/src/migrations/codemods/css/plugins.js +31 -42
  25. package/dist/src/migrations/codemods/css/run.js +20 -151
  26. package/dist/src/migrations/color-rename-next49.js +44 -220
  27. package/dist/src/migrations/index.js +7 -577
  28. package/dist/src/tokens/build.js +39 -1816
  29. package/dist/src/tokens/create/files.js +43 -602
  30. package/dist/src/tokens/create/generators/$designsystemet.js +8 -97
  31. package/dist/src/tokens/create/generators/$metadata.js +17 -20
  32. package/dist/src/tokens/create/generators/$themes.js +137 -311
  33. package/dist/src/tokens/create/generators/primitives/color-scheme.js +68 -443
  34. package/dist/src/tokens/create/generators/primitives/globals.js +141 -147
  35. package/dist/src/tokens/create/generators/primitives/size.js +146 -156
  36. package/dist/src/tokens/create/generators/primitives/typography.js +213 -217
  37. package/dist/src/tokens/create/generators/semantic/color-modes.js +24 -59
  38. package/dist/src/tokens/create/generators/semantic/color.js +42 -326
  39. package/dist/src/tokens/create/generators/semantic/style.js +379 -382
  40. package/dist/src/tokens/create/generators/themes/theme.js +108 -392
  41. package/dist/src/tokens/create.js +47 -1591
  42. package/dist/src/tokens/format.js +38 -3324
  43. package/dist/src/tokens/generate-config.js +155 -298
  44. package/dist/src/tokens/index.js +3 -3344
  45. package/dist/src/tokens/process/configs/color.js +50 -1085
  46. package/dist/src/tokens/process/configs/semantic.js +45 -1083
  47. package/dist/src/tokens/process/configs/shared.js +18 -109
  48. package/dist/src/tokens/process/configs/size-mode.js +27 -1082
  49. package/dist/src/tokens/process/configs/size.js +32 -1083
  50. package/dist/src/tokens/process/configs/type-scale.js +49 -1083
  51. package/dist/src/tokens/process/configs/typography.js +63 -1084
  52. package/dist/src/tokens/process/configs.js +88 -1224
  53. package/dist/src/tokens/process/formats/css/color.js +58 -1079
  54. package/dist/src/tokens/process/formats/css/semantic.js +27 -1081
  55. package/dist/src/tokens/process/formats/css/size-mode.js +43 -1077
  56. package/dist/src/tokens/process/formats/css/size.js +86 -1079
  57. package/dist/src/tokens/process/formats/css/type-scale.js +53 -1083
  58. package/dist/src/tokens/process/formats/css/typography.js +27 -1081
  59. package/dist/src/tokens/process/formats/css.js +18 -1081
  60. package/dist/src/tokens/process/output/declarations.js +18 -1201
  61. package/dist/src/tokens/process/output/tailwind.js +26 -40
  62. package/dist/src/tokens/process/output/theme.js +73 -206
  63. package/dist/src/tokens/process/platform.js +165 -1355
  64. package/dist/src/tokens/process/transformers.js +49 -89
  65. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +100 -1183
  66. package/dist/src/tokens/process/utils/kebab-case.js +7 -5
  67. package/dist/src/tokens/types.js +6 -7
  68. package/dist/src/tokens/utils.js +102 -93
  69. package/dist/src/types.js +1 -5
  70. package/dist/src/utils/filesystem.js +112 -124
  71. package/package.json +10 -13
  72. package/configs/test-tokens.config.json +0 -82
  73. package/dist/src/scripts/createJsonSchema.js +0 -409
  74. package/dist/src/scripts/update-preview-tokens.js +0 -3353
@@ -1,37 +1,28 @@
1
- // src/tokens/process/output/tailwind.ts
2
- var createTailwindCSSFiles = (cssFiles) => {
3
- console.log("\n\u{1F371} Creating Tailwind Config");
4
- return cssFiles.map((file) => {
5
- if (file.destination) {
6
- const tailwindConfig = generateTailwind(file.output);
7
- const tailwindFile = {
8
- destination: file.destination.replace(".css", ".tailwind.css"),
9
- output: tailwindConfig
10
- };
11
- return tailwindFile;
12
- }
13
- return void 0;
14
- }).filter((item) => item !== void 0);
1
+ //#region src/tokens/process/output/tailwind.ts
2
+ const createTailwindCSSFiles = (cssFiles) => {
3
+ console.log("\n🍱 Creating Tailwind Config");
4
+ return cssFiles.map((file) => {
5
+ if (file.destination) {
6
+ const tailwindConfig = generateTailwind(file.output);
7
+ return {
8
+ destination: file.destination.replace(".css", ".tailwind.css"),
9
+ output: tailwindConfig
10
+ };
11
+ }
12
+ }).filter((item) => item !== void 0);
15
13
  };
16
- var generateTailwind = (css) => {
17
- const tailwind = ["--font-sans: var(--ds-font-family)"];
18
- const tokens = Array.from(new Set(css.match(/--ds-[^:)]+/g)), (m) => m).sort(
19
- (a, b) => a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" })
20
- );
21
- for (const token of tokens) {
22
- if (token.startsWith("--ds-color-") && !token.startsWith("--ds-color-focus")) {
23
- tailwind.push(`--color-${token.replace("--ds-color-", "")}: var(${token})`);
24
- } else if (token.startsWith("--ds-font-weight-")) {
25
- tailwind.push(`--font-weight-${token.replace("--ds-font-weight-", "")}: var(${token})`);
26
- } else if (token.match(/--ds-border-radius-(sm|md|lg|xl)/)) {
27
- tailwind.push(`--radius-${token.replace("--ds-border-radius-", "")}: var(${token})`);
28
- } else if (token.match(/--ds-body-(sm|mg|lg)-body-font-size/)) {
29
- tailwind.push(`--text-${token.replace("--ds-body-", "").replace("-font-size", "")}: var(${token})`);
30
- } else if (token.match(/^--ds-size-\d+$/)) {
31
- tailwind.push(`--spacing-${token.replace("--ds-size-", "")}: var(${token})`);
32
- }
33
- }
34
- const dynamicColors = `[data-color] {
14
+ const generateTailwind = (css) => {
15
+ const tailwind = ["--font-sans: var(--ds-font-family)"];
16
+ const tokens = Array.from(new Set(css.match(/--ds-[^:)]+/g)), (m) => m).sort((a, b) => a.localeCompare(b, void 0, {
17
+ numeric: true,
18
+ sensitivity: "base"
19
+ }));
20
+ for (const token of tokens) if (token.startsWith("--ds-color-") && !token.startsWith("--ds-color-focus")) tailwind.push(`--color-${token.replace("--ds-color-", "")}: var(${token})`);
21
+ else if (token.startsWith("--ds-font-weight-")) tailwind.push(`--font-weight-${token.replace("--ds-font-weight-", "")}: var(${token})`);
22
+ else if (token.match(/--ds-border-radius-(sm|md|lg|xl)/)) tailwind.push(`--radius-${token.replace("--ds-border-radius-", "")}: var(${token})`);
23
+ else if (token.match(/--ds-body-(sm|mg|lg)-body-font-size/)) tailwind.push(`--text-${token.replace("--ds-body-", "").replace("-font-size", "")}: var(${token})`);
24
+ else if (token.match(/^--ds-size-\d+$/)) tailwind.push(`--spacing-${token.replace("--ds-size-", "")}: var(${token})`);
25
+ return `@theme {${tailwind.map((str) => `\n ${str};`).join("")}\n}\n[data-color] {
35
26
  --color-background-default: var(--ds-color-background-default);
36
27
  --color-background-tinted: var(--ds-color-background-tinted);
37
28
  --color-surface-default: var(--ds-color-surface-default);
@@ -49,11 +40,6 @@ var generateTailwind = (css) => {
49
40
  --color-base-contrast-subtle: var(--ds-color-base-contrast-subtle);
50
41
  --color-base-contrast-default: var(--ds-color-base-contrast-default);
51
42
  }`;
52
- return `@theme {${tailwind.map((str) => `
53
- ${str};`).join("")}
54
- }
55
- ${dynamicColors}`;
56
- };
57
- export {
58
- createTailwindCSSFiles
59
43
  };
44
+ //#endregion
45
+ export { createTailwindCSSFiles };
@@ -1,216 +1,83 @@
1
- // src/tokens/process/output/theme.ts
1
+ import { version } from "../../../../package.js";
2
+ import { sizeComparator } from "../../utils.js";
2
3
  import pc from "picocolors";
3
- import * as R2 from "ramda";
4
-
5
- // package.json
6
- var package_default = {
7
- name: "@digdir/designsystemet",
8
- version: "1.13.2",
9
- description: "CLI for Designsystemet",
10
- author: "Designsystemet team",
11
- engines: {
12
- node: ">=20.20.2"
13
- },
14
- repository: {
15
- type: "git",
16
- url: "git+https://github.com/digdir/designsystemet.git"
17
- },
18
- homepage: "https://github.com/digdir/designsystemet/tree/main/packages/cli",
19
- license: "MIT",
20
- type: "module",
21
- main: "./dist/src/index.js",
22
- files: [
23
- "./dist/**",
24
- "./configs/**"
25
- ],
26
- bin: "dist/bin/designsystemet.js",
27
- exports: {
28
- ".": {
29
- import: "./dist/src/index.js"
30
- },
31
- "./color": {
32
- import: "./dist/src/colors/index.js"
33
- },
34
- "./tokens": {
35
- import: "./dist/src/tokens/index.js"
36
- },
37
- "./types": {
38
- import: "./dist/src/types.js"
39
- }
40
- },
41
- publishConfig: {
42
- access: "public"
43
- },
44
- scripts: {
45
- designsystemet: "tsx ./bin/designsystemet.ts",
46
- "designsystemet:inspect": "tsx --inspect-brk ./bin/designsystemet.ts",
47
- build: "tsup && pnpm build:types && pnpm build:json-schema",
48
- "build:types": "tsc --emitDeclarationOnly --declaration",
49
- "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
50
- types: "tsc --noEmit",
51
- "test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
52
- "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
53
- "test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
54
- "test:tokens-build-tailwind": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean --experimental-tailwind",
55
- "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
56
- "test:tokens-build-config:inspect": "pnpm run designsystemet:inspect tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
57
- "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
58
- "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
59
- "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
60
- "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../design-tokens --dry",
61
- test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
62
- "update:preview-tokens": "tsx ./src/scripts/update-preview-tokens.ts",
63
- verify: "pnpm test && pnpm update:template && pnpm --filter @internal/digdir update:theme-digdir"
64
- },
65
- dependencies: {
66
- "@commander-js/extra-typings": "^14.0.0",
67
- "@digdir/designsystemet-types": "workspace:",
68
- "@tokens-studio/sd-transforms": "2.0.3",
69
- "chroma-js": "^3.2.0",
70
- "colorjs.io": "^0.6.1",
71
- commander: "^14.0.3",
72
- "fast-glob": "^3.3.3",
73
- hsluv: "^1.0.1",
74
- "object-hash": "^3.0.0",
75
- picocolors: "^1.1.1",
76
- postcss: "^8.5.8",
77
- ramda: "^0.32.0",
78
- "style-dictionary": "^5.4.0",
79
- zod: "^4.3.6",
80
- "zod-validation-error": "^5.0.0"
81
- },
82
- devDependencies: {
83
- "@tokens-studio/types": "0.5.2",
84
- "@types/chroma-js": "3.1.2",
85
- "@types/node": "24.12.2",
86
- "@types/object-hash": "3.0.6",
87
- "@types/ramda": "0.31.1",
88
- tsup: "8.5.1",
89
- tsx: "4.21.0",
90
- typescript: "5.9.3"
91
- }
92
- };
93
-
94
- // src/tokens/utils.ts
95
4
  import * as R from "ramda";
96
- var mapToLowerCase = R.map(R.toLower);
97
- var hasAnyTruth = R.any(R.equals(true));
98
- var getType = (token) => (token.$type ?? token.type) || "";
99
- var typeEquals = R.curry(
100
- (types, token) => {
101
- if (R.isNil(token)) {
102
- return false;
103
- }
104
- return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
105
- }
106
- );
107
- var pathStartsWithOneOf = R.curry(
108
- (paths, token) => {
109
- if (R.isNil(token)) {
110
- return false;
111
- }
112
- const tokenPath = mapToLowerCase(token.path);
113
- const matchPathsStartingWith = R.map((pathOrString) => {
114
- const path = typeof pathOrString === "string" ? [pathOrString] : pathOrString;
115
- return R.startsWith(mapToLowerCase(path), tokenPath);
116
- }, paths);
117
- return hasAnyTruth(matchPathsStartingWith);
118
- }
119
- );
120
- var sizeMap = {
121
- xsmall: "xs",
122
- small: "sm",
123
- medium: "md",
124
- large: "lg",
125
- xlarge: "xl"
126
- };
127
- var sizeComparator = (size) => {
128
- const sortIndex = Object.entries(sizeMap).findIndex(([key, val]) => key === size || val === size);
129
- return sortIndex ?? 0;
5
+ //#region src/tokens/process/output/theme.ts
6
+ const defaultFileHeader = `build: v${version}`;
7
+ const getFileNameWithoutExtension = (path) => {
8
+ const pathSegments = path.split("/");
9
+ return pathSegments[pathSegments.length - 1].split(".").slice(0, -1).join(".");
130
10
  };
131
-
132
- // src/tokens/process/output/theme.ts
133
- var defaultFileHeader = `build: v${package_default.version}`;
134
- var getFileNameWithoutExtension = (path) => {
135
- const pathSegments = path.split("/");
136
- return pathSegments[pathSegments.length - 1].split(".").slice(0, -1).join(".");
137
- };
138
- var createThemeCSSFiles = ({
139
- processedBuilds,
140
- fileHeader = defaultFileHeader
141
- }) => {
142
- const groupedByTheme = {};
143
- for (const [_, buildResults] of Object.entries(processedBuilds)) {
144
- for (const buildResult of buildResults) {
145
- const themeName = buildResult.permutation.theme;
146
- const newOutputs = buildResult.formatted;
147
- if (R2.isNotEmpty(newOutputs)) {
148
- const currentOutputs = groupedByTheme[themeName] ?? [];
149
- groupedByTheme[themeName] = R2.concat(currentOutputs, newOutputs);
150
- }
151
- }
152
- }
153
- const sortOrder = [
154
- "size-mode/",
155
- "type-scale",
156
- "color-scheme/light",
157
- "typography/secondary",
158
- "size",
159
- "semantic",
160
- "color-scheme/dark",
161
- "color-scheme/contrast",
162
- "typography/primary",
163
- "color/"
164
- ];
165
- const sortByDefinedOrder = R2.sortBy((file) => {
166
- const filePath = file.destination || "";
167
- const sortIndex = sortOrder.findIndex((sortElement) => {
168
- if (sortElement.endsWith("/")) {
169
- return filePath.includes(sortElement);
170
- }
171
- return filePath.includes(`${sortElement}.css`);
172
- });
173
- if (sortIndex === -1) {
174
- console.error(
175
- pc.yellow(`WARNING: CSS section does not have a defined sort order: ${filePath.replace(".css", "")}`)
176
- );
177
- console.log(
178
- pc.dim(
179
- `
11
+ /**
12
+ * Generates theme-specific CSS files from Style Dictionary build results.
13
+ *
14
+ * @param processedBuilds - The processed build results containing formatted CSS outputs
15
+ * grouped by themes and other permutations.
16
+ * @param fileHeader - Optional header to be included in the generated CSS files.
17
+ * @returns An array of `OutputFile` objects, each representing a theme-specific CSS file
18
+ * with its destination and content.
19
+ *
20
+ * @remarks
21
+ * - The function groups the build results by theme and ensures a deterministic order
22
+ * for the sections of the entry CSS file using a predefined sort order.
23
+ * - If a CSS section does not have a defined sort order the section is added to the end of the entry file.
24
+ * - The generated CSS files include a header with metadata and layer definitions.
25
+ */
26
+ const createThemeCSSFiles = ({ processedBuilds, fileHeader = defaultFileHeader }) => {
27
+ const groupedByTheme = {};
28
+ for (const [_, buildResults] of Object.entries(processedBuilds)) for (const buildResult of buildResults) {
29
+ const themeName = buildResult.permutation.theme;
30
+ const newOutputs = buildResult.formatted;
31
+ if (R.isNotEmpty(newOutputs)) {
32
+ const currentOutputs = groupedByTheme[themeName] ?? [];
33
+ groupedByTheme[themeName] = R.concat(currentOutputs, newOutputs);
34
+ }
35
+ }
36
+ /**
37
+ * Defines a sort order for the sections of the entry CSS file.
38
+ * This ensures a deterministic order, whereas earlier this was nondeterministic
39
+ */
40
+ const sortOrder = [
41
+ "size-mode/",
42
+ "type-scale",
43
+ "color-scheme/light",
44
+ "typography/secondary",
45
+ "size",
46
+ "semantic",
47
+ "color-scheme/dark",
48
+ "color-scheme/contrast",
49
+ "typography/primary",
50
+ "color/"
51
+ ];
52
+ const sortByDefinedOrder = R.sortBy((file) => {
53
+ const filePath = file.destination || "";
54
+ const sortIndex = sortOrder.findIndex((sortElement) => {
55
+ if (sortElement.endsWith("/")) return filePath.includes(sortElement);
56
+ return filePath.includes(`${sortElement}.css`);
57
+ });
58
+ if (sortIndex === -1) {
59
+ console.error(pc.yellow(`WARNING: CSS section does not have a defined sort order: ${filePath.replace(".css", "")}`));
60
+ console.log(pc.dim(`
180
61
  The section will currently be added to the end of the entry file, but the exact
181
- order may change due to nondeterminism.`.trim()
182
- )
183
- );
184
- return Infinity;
185
- }
186
- return sortIndex;
187
- });
188
- const header = `@charset "UTF-8";
62
+ order may change due to nondeterminism.`.trim()));
63
+ return Infinity;
64
+ }
65
+ return sortIndex;
66
+ });
67
+ const header = `@charset "UTF-8";
189
68
  /*
190
69
  ${fileHeader}
191
70
  */
192
71
 
193
72
  `;
194
- const sortAlphabetically = R2.sort(R2.ascend((x) => x.destination || ""));
195
- const sortBySize = R2.sortBy(
196
- R2.pipe((s) => getFileNameWithoutExtension(s.destination ?? ""), sizeComparator)
197
- );
198
- const pickOutputs = R2.map(R2.view(R2.lensProp("output")));
199
- const themeCSSFile = R2.pipe(
200
- sortAlphabetically,
201
- sortBySize,
202
- sortByDefinedOrder,
203
- pickOutputs,
204
- R2.join("\n"),
205
- (content) => header + content
206
- );
207
- const themeCSSFiles = Object.entries(groupedByTheme).map(([theme, files]) => ({
208
- destination: `${theme}.css`,
209
- output: themeCSSFile(files)
210
- }));
211
- return themeCSSFiles;
212
- };
213
- export {
214
- createThemeCSSFiles,
215
- defaultFileHeader
73
+ const sortAlphabetically = R.sort(R.ascend((x) => x.destination || ""));
74
+ const sortBySize = R.sortBy(R.pipe((s) => getFileNameWithoutExtension(s.destination ?? ""), sizeComparator));
75
+ const pickOutputs = R.map(R.view(R.lensProp("output")));
76
+ const themeCSSFile = R.pipe(sortAlphabetically, sortBySize, sortByDefinedOrder, pickOutputs, R.join("\n"), (content) => header + content);
77
+ return Object.entries(groupedByTheme).map(([theme, files]) => ({
78
+ destination: `${theme}.css`,
79
+ output: themeCSSFile(files)
80
+ }));
216
81
  };
82
+ //#endregion
83
+ export { createThemeCSSFiles, defaultFileHeader };