@digdir/designsystemet 1.0.7 → 1.1.0

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 (71) hide show
  1. package/dist/bin/config.d.ts +12 -0
  2. package/dist/bin/config.d.ts.map +1 -0
  3. package/dist/bin/config.js +517 -0
  4. package/dist/bin/designsystemet.js +3699 -3572
  5. package/dist/config.schema.json +1 -0
  6. package/dist/src/colors/index.d.ts +2 -2
  7. package/dist/src/colors/index.d.ts.map +1 -1
  8. package/dist/src/colors/index.js +143 -143
  9. package/dist/src/colors/theme.d.ts +1 -2
  10. package/dist/src/colors/theme.d.ts.map +1 -1
  11. package/dist/src/config.d.ts +25 -14
  12. package/dist/src/config.d.ts.map +1 -1
  13. package/dist/src/config.js +68 -24
  14. package/dist/src/index.js +431 -404
  15. package/dist/src/migrations/beta-to-v1.js +9 -2
  16. package/dist/src/migrations/codemods/css/run.js +9 -2
  17. package/dist/src/migrations/color-rename-next49.js +9 -2
  18. package/dist/src/migrations/index.js +9 -2
  19. package/dist/src/scripts/createJsonSchema.js +28 -23
  20. package/dist/src/scripts/update-template.d.ts.map +1 -1
  21. package/dist/src/scripts/update-template.js +9 -2
  22. package/dist/src/tokens/build.d.ts +1 -1
  23. package/dist/src/tokens/build.d.ts.map +1 -1
  24. package/dist/src/tokens/build.js +140 -57
  25. package/dist/src/tokens/create/generators/$designsystemet.js +13 -14
  26. package/dist/src/tokens/create/generators/color.js +21 -21
  27. package/dist/src/tokens/create/write.js +23 -17
  28. package/dist/src/tokens/create.d.ts +1 -0
  29. package/dist/src/tokens/create.d.ts.map +1 -1
  30. package/dist/src/tokens/create.js +22 -21
  31. package/dist/src/tokens/format.d.ts +1 -1
  32. package/dist/src/tokens/format.d.ts.map +1 -1
  33. package/dist/src/tokens/format.js +916 -890
  34. package/dist/src/tokens/index.d.ts +2 -2
  35. package/dist/src/tokens/index.d.ts.map +1 -1
  36. package/dist/src/tokens/index.js +308 -281
  37. package/dist/src/tokens/process/configs/color.d.ts.map +1 -1
  38. package/dist/src/tokens/process/configs/color.js +17 -15
  39. package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -1
  40. package/dist/src/tokens/process/configs/semantic.js +16 -14
  41. package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -1
  42. package/dist/src/tokens/process/configs/storefront.js +12 -2
  43. package/dist/src/tokens/process/configs/typography.d.ts.map +1 -1
  44. package/dist/src/tokens/process/configs/typography.js +16 -14
  45. package/dist/src/tokens/process/configs.d.ts.map +1 -1
  46. package/dist/src/tokens/process/configs.js +18 -31
  47. package/dist/src/tokens/process/formats/css/color.js +5 -3
  48. package/dist/src/tokens/process/formats/css/semantic.js +2 -2
  49. package/dist/src/tokens/process/formats/css/typography.js +1 -1
  50. package/dist/src/tokens/process/formats/css.js +8 -6
  51. package/dist/src/tokens/process/formats/js-tokens.js +12 -2
  52. package/dist/src/tokens/process/output/tailwind.d.ts +3 -0
  53. package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
  54. package/dist/src/tokens/process/output/tailwind.js +59 -0
  55. package/dist/src/tokens/process/{theme.d.ts → output/theme.d.ts} +2 -2
  56. package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
  57. package/dist/src/tokens/process/{theme.js → output/theme.js} +16 -17
  58. package/dist/src/tokens/process/platform.d.ts +6 -6
  59. package/dist/src/tokens/process/platform.d.ts.map +1 -1
  60. package/dist/src/tokens/process/platform.js +46 -19
  61. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +10 -9
  62. package/dist/src/tokens/types.d.ts +3 -3
  63. package/dist/src/tokens/types.d.ts.map +1 -1
  64. package/dist/src/tokens/utils.d.ts +2 -2
  65. package/dist/src/tokens/utils.d.ts.map +1 -1
  66. package/dist/src/tokens/utils.js +11 -1
  67. package/dist/src/utils.d.ts +1 -1
  68. package/dist/src/utils.d.ts.map +1 -1
  69. package/dist/src/utils.js +9 -2
  70. package/package.json +13 -14
  71. package/dist/src/tokens/process/theme.d.ts.map +0 -1
@@ -49,12 +49,19 @@ import postcss from "postcss";
49
49
  // src/utils.ts
50
50
  import fs from "fs/promises";
51
51
  import chalk2 from "chalk";
52
- var readFile = async (path, dry) => {
52
+ var readFile = async (path, dry, allowFileNotFound) => {
53
53
  if (dry) {
54
54
  console.log(`${chalk2.blue("readFile")} ${path}`);
55
55
  return Promise.resolve("");
56
56
  }
57
- return fs.readFile(path, "utf-8");
57
+ try {
58
+ return await fs.readFile(path, "utf-8");
59
+ } catch (error) {
60
+ if (allowFileNotFound && error.code === "ENOENT") {
61
+ return "";
62
+ }
63
+ throw error;
64
+ }
58
65
  };
59
66
 
60
67
  // src/migrations/codemods/css/run.ts
@@ -6,12 +6,19 @@ import postcss from "postcss";
6
6
  // src/utils.ts
7
7
  import fs from "fs/promises";
8
8
  import chalk from "chalk";
9
- var readFile = async (path, dry) => {
9
+ var readFile = async (path, dry, allowFileNotFound) => {
10
10
  if (dry) {
11
11
  console.log(`${chalk.blue("readFile")} ${path}`);
12
12
  return Promise.resolve("");
13
13
  }
14
- return fs.readFile(path, "utf-8");
14
+ try {
15
+ return await fs.readFile(path, "utf-8");
16
+ } catch (error) {
17
+ if (allowFileNotFound && error.code === "ENOENT") {
18
+ return "";
19
+ }
20
+ throw error;
21
+ }
15
22
  };
16
23
 
17
24
  // src/migrations/codemods/css/run.ts
@@ -40,12 +40,19 @@ import postcss from "postcss";
40
40
  // src/utils.ts
41
41
  import fs from "fs/promises";
42
42
  import chalk2 from "chalk";
43
- var readFile = async (path, dry) => {
43
+ var readFile = async (path, dry, allowFileNotFound) => {
44
44
  if (dry) {
45
45
  console.log(`${chalk2.blue("readFile")} ${path}`);
46
46
  return Promise.resolve("");
47
47
  }
48
- return fs.readFile(path, "utf-8");
48
+ try {
49
+ return await fs.readFile(path, "utf-8");
50
+ } catch (error) {
51
+ if (allowFileNotFound && error.code === "ENOENT") {
52
+ return "";
53
+ }
54
+ throw error;
55
+ }
49
56
  };
50
57
 
51
58
  // src/migrations/codemods/css/run.ts
@@ -49,12 +49,19 @@ import postcss from "postcss";
49
49
  // src/utils.ts
50
50
  import fs from "fs/promises";
51
51
  import chalk2 from "chalk";
52
- var readFile = async (path, dry) => {
52
+ var readFile = async (path, dry, allowFileNotFound) => {
53
53
  if (dry) {
54
54
  console.log(`${chalk2.blue("readFile")} ${path}`);
55
55
  return Promise.resolve("");
56
56
  }
57
- return fs.readFile(path, "utf-8");
57
+ try {
58
+ return await fs.readFile(path, "utf-8");
59
+ } catch (error) {
60
+ if (allowFileNotFound && error.code === "ENOENT") {
61
+ return "";
62
+ }
63
+ throw error;
64
+ }
58
65
  };
59
66
 
60
67
  // src/migrations/codemods/css/run.ts
@@ -4,26 +4,10 @@ import { resolve } from "path";
4
4
  import { z as z2 } from "zod/v4";
5
5
 
6
6
  // src/config.ts
7
+ import chalk from "chalk";
7
8
  import * as R7 from "ramda";
8
9
  import { z } from "zod/v4";
9
-
10
- // src/colors/utils.ts
11
- import chroma from "chroma-js";
12
- import Colorjs from "colorjs.io";
13
- import { Hsluv } from "hsluv";
14
- var convertToHex = (color) => {
15
- if (!color) {
16
- return "#000000";
17
- }
18
- if (/^#[0-9A-Fa-f]{6}$/.test(color)) {
19
- return color;
20
- }
21
- return chroma(color).hex();
22
- };
23
-
24
- // src/colors/theme.ts
25
- import chroma2 from "chroma-js";
26
- import * as R2 from "ramda";
10
+ import { fromError } from "zod-validation-error";
27
11
 
28
12
  // src/colors/colorMetadata.ts
29
13
  import * as R from "ramda";
@@ -271,6 +255,24 @@ var colorMetadata = {
271
255
  };
272
256
  var colorMetadataByNumber = R.indexBy((metadata) => metadata.number, Object.values(colorMetadata));
273
257
 
258
+ // src/colors/theme.ts
259
+ import chroma2 from "chroma-js";
260
+ import * as R2 from "ramda";
261
+
262
+ // src/colors/utils.ts
263
+ import chroma from "chroma-js";
264
+ import Colorjs from "colorjs.io";
265
+ import { Hsluv } from "hsluv";
266
+ var convertToHex = (color) => {
267
+ if (!color) {
268
+ return "#000000";
269
+ }
270
+ if (/^#[0-9A-Fa-f]{6}$/.test(color)) {
271
+ return color;
272
+ }
273
+ return chroma(color).hex();
274
+ };
275
+
274
276
  // src/colors/theme.ts
275
277
  var RESERVED_COLORS = [
276
278
  "neutral",
@@ -332,19 +334,22 @@ var themeSchema = z.object({
332
334
  }).describe("Defines the typography for a given theme").optional(),
333
335
  borderRadius: z.number().meta({ description: "Defines the border-radius for this theme" }).optional()
334
336
  }).meta({ description: "An object defining a theme. The property name holding the object becomes the theme name." });
335
- var configFileSchema = z.object({
336
- outDir: z.string().meta({ description: "Path to the output directory for the created design tokens" }).optional(),
337
+ var configFileBuildSchema = z.object({
338
+ clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional()
339
+ });
340
+ var configFileCreateSchema = z.object({
341
+ outDir: z.string().meta({ description: "Path to the output directory for the created design tokens" }),
337
342
  clean: z.boolean().meta({ description: "Delete the output directory before building or creating tokens" }).optional(),
338
343
  themes: z.record(z.string(), themeSchema).meta({
339
344
  description: "An object with one or more themes. Each property defines a theme, and the property name is used as the theme name."
340
345
  })
341
- });
342
- var combinedConfigSchema = configFileSchema.required();
346
+ }).required();
347
+ var combinedConfigSchema = configFileCreateSchema.extend(configFileBuildSchema.shape);
343
348
 
344
349
  // src/scripts/createJsonSchema.ts
345
350
  var schema = z2.object({
346
351
  $schema: z2.string().optional()
347
- }).extend(configFileSchema.shape);
352
+ }).extend(combinedConfigSchema.shape);
348
353
  writeFile(
349
354
  resolve(import.meta.dirname, "../../dist/config.schema.json"),
350
355
  JSON.stringify(
@@ -1 +1 @@
1
- {"version":3,"file":"update-template.d.ts","sourceRoot":"","sources":["../../../src/scripts/update-template.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,eAAe,qBA+E3B,CAAC"}
1
+ {"version":3,"file":"update-template.d.ts","sourceRoot":"","sources":["../../../src/scripts/update-template.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,eAAe,qBA+E3B,CAAC"}
@@ -1122,12 +1122,19 @@ var cleanDir = async (dir, dry) => {
1122
1122
  \u{1F525} Cleaning dir ${chalk.red(`${dir.trim()}`)} `);
1123
1123
  return fs.rm(dir, { recursive: true, force: true });
1124
1124
  };
1125
- var readFile = async (path2, dry) => {
1125
+ var readFile = async (path2, dry, allowFileNotFound) => {
1126
1126
  if (dry) {
1127
1127
  console.log(`${chalk.blue("readFile")} ${path2}`);
1128
1128
  return Promise.resolve("");
1129
1129
  }
1130
- return fs.readFile(path2, "utf-8");
1130
+ try {
1131
+ return await fs.readFile(path2, "utf-8");
1132
+ } catch (error) {
1133
+ if (allowFileNotFound && error.code === "ENOENT") {
1134
+ return "";
1135
+ }
1136
+ throw error;
1137
+ }
1131
1138
  };
1132
1139
 
1133
1140
  // src/scripts/update-template.ts
@@ -1,3 +1,3 @@
1
1
  import { type BuildOptions } from './process/platform.js';
2
- export declare const buildTokens: (options: Omit<BuildOptions, "process" | "$themes">) => Promise<import("./process/platform.js").ProcessReturn>;
2
+ export declare const buildTokens: (options: Omit<BuildOptions, "type" | "$themes">) => Promise<import("./process/platform.js").ProcessReturn>;
3
3
  //# sourceMappingURL=build.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/tokens/build.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,uBAAuB,CAAC;AAiB3E,eAAO,MAAM,WAAW,GAAU,SAAS,IAAI,CAAC,YAAY,EAAE,SAAS,GAAG,SAAS,CAAC,2DAiDnF,CAAC"}
1
+ {"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../../../src/tokens/build.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,YAAY,EAAmB,MAAM,uBAAuB,CAAC;AAiB3E,eAAO,MAAM,WAAW,GAAU,SAAS,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,SAAS,CAAC,2DAqDhF,CAAC"}
@@ -28,31 +28,86 @@ var writeFile = async (path2, data, dry) => {
28
28
  throw error;
29
29
  });
30
30
  };
31
- var cleanDir = async (dir, dry) => {
32
- if (dry) {
33
- console.log(`${chalk.blue("cleanDir")} ${dir}`);
34
- return Promise.resolve();
35
- }
36
- console.log(`
37
- \u{1F525} Cleaning dir ${chalk.red(`${dir.trim()}`)} `);
38
- return fs.rm(dir, { recursive: true, force: true });
39
- };
40
- var readFile = async (path2, dry) => {
31
+ var readFile = async (path2, dry, allowFileNotFound) => {
41
32
  if (dry) {
42
33
  console.log(`${chalk.blue("readFile")} ${path2}`);
43
34
  return Promise.resolve("");
44
35
  }
45
- return fs.readFile(path2, "utf-8");
36
+ try {
37
+ return await fs.readFile(path2, "utf-8");
38
+ } catch (error) {
39
+ if (allowFileNotFound && error.code === "ENOENT") {
40
+ return "";
41
+ }
42
+ throw error;
43
+ }
46
44
  };
47
45
 
48
- // src/tokens/process/theme.ts
49
- import * as R from "ramda";
46
+ // src/tokens/process/output/tailwind.ts
47
+ var createTailwindCSSFiles = (cssFiles) => {
48
+ console.log("\n\u{1F371} Creating Tailwind Config");
49
+ return cssFiles.map((file) => {
50
+ if (file.destination) {
51
+ const tailwindConfig = generateTailwind(file.output);
52
+ const tailwindFile = {
53
+ destination: file.destination.replace(".css", ".tailwind.css"),
54
+ output: tailwindConfig
55
+ };
56
+ return tailwindFile;
57
+ }
58
+ return void 0;
59
+ }).filter((item) => item !== void 0);
60
+ };
61
+ var generateTailwind = (css) => {
62
+ const tailwind = ["--font-sans: var(--ds-font-family)"];
63
+ const tokens = Array.from(new Set(css.match(/--ds-[^:)]+/g)), (m) => m).sort(
64
+ (a, b) => a.localeCompare(b, void 0, { numeric: true, sensitivity: "base" })
65
+ );
66
+ for (const token of tokens) {
67
+ if (token.startsWith("--ds-color-") && !token.startsWith("--ds-color-focus")) {
68
+ tailwind.push(`--color-${token.replace("--ds-color-", "")}: var(${token})`);
69
+ } else if (token.startsWith("--ds-font-weight-")) {
70
+ tailwind.push(`--font-weight-${token.replace("--ds-font-weight-", "")}: var(${token})`);
71
+ } else if (token.match(/--ds-border-radius-(sm|md|lg|xl)/)) {
72
+ tailwind.push(`--radius-${token.replace("--ds-border-radius-", "")}: var(${token})`);
73
+ } else if (token.match(/--ds-body-(sm|mg|lg)-body-font-size/)) {
74
+ tailwind.push(`--text-${token.replace("--ds-body-", "").replace("-font-size", "")}: var(${token})`);
75
+ } else if (token.match(/^--ds-size-\d+$/)) {
76
+ tailwind.push(`--spacing-${token.replace("--ds-size-", "")}: var(${token})`);
77
+ }
78
+ }
79
+ const dynamicColors = `[data-color] {
80
+ --color-background-default: var(--ds-color-background-default);
81
+ --color-background-tinted: var(--ds-color-background-tinted);
82
+ --color-surface-default: var(--ds-color-surface-default);
83
+ --color-surface-tinted: var(--ds-color-surface-tinted);
84
+ --color-surface-hover: var(--ds-color-surface-hover);
85
+ --color-surface-active: var(--ds-color-surface-active);
86
+ --color-border-subtle: var(--ds-color-border-subtle);
87
+ --color-border-default: var(--ds-color-border-default);
88
+ --color-border-strong: var(--ds-color-border-strong);
89
+ --color-text-subtle: var(--ds-color-text-subtle);
90
+ --color-text-default: var(--ds-color-text-default);
91
+ --color-base-default: var(--ds-color-base-default);
92
+ --color-base-hover: var(--ds-color-base-hover);
93
+ --color-base-active: var(--ds-color-base-active);
94
+ --color-base-contrast-subtle: var(--ds-color-base-contrast-subtle);
95
+ --color-base-contrast-default: var(--ds-color-base-contrast-default);
96
+ }`;
97
+ return `@theme {${tailwind.map((str) => `
98
+ ${str};`).join("")}
99
+ }
100
+ ${dynamicColors}`;
101
+ };
102
+
103
+ // src/tokens/process/output/theme.ts
50
104
  import chalk2 from "chalk";
105
+ import * as R from "ramda";
51
106
 
52
107
  // package.json
53
108
  var package_default = {
54
109
  name: "@digdir/designsystemet",
55
- version: "1.0.7",
110
+ version: "1.1.0",
56
111
  description: "CLI for Designsystemet",
57
112
  author: "Designsystemet team",
58
113
  engines: {
@@ -62,7 +117,7 @@ var package_default = {
62
117
  type: "git",
63
118
  url: "git+https://github.com/digdir/designsystemet.git"
64
119
  },
65
- homepage: "https://github.com/digdir/designsystemet/tree/main/scripts/cli",
120
+ homepage: "https://github.com/digdir/designsystemet/tree/main/packages/cli",
66
121
  license: "MIT",
67
122
  type: "module",
68
123
  main: "./dist/src/index.js",
@@ -87,8 +142,6 @@ var package_default = {
87
142
  },
88
143
  scripts: {
89
144
  designsystemet: "tsx ./bin/designsystemet.ts",
90
- "build:tokens": "pnpm run designsystemet tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
91
- "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
92
145
  build: "tsup && pnpm build:types && pnpm build:json-schema",
93
146
  "build:types": "tsc --emitDeclarationOnly --declaration",
94
147
  "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
@@ -96,17 +149,20 @@ var package_default = {
96
149
  "test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
97
150
  "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
98
151
  "test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
152
+ "test:tokens-build-tailwind": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean --experimental-tailwind",
99
153
  "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
154
+ "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
100
155
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
101
156
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
102
157
  test: "pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
158
+ "digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
103
159
  "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
104
160
  "update:template": "tsx ./src/scripts/update-template.ts",
105
- "update:design-tokens": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
106
- verify: "pnpm test && pnpm update:template && pnpm update:design-tokens"
161
+ "update:theme-digdir": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts && pnpm digdir:tokens-build",
162
+ verify: "pnpm test && pnpm update:template && pnpm update:theme-digdir && pnpm build:tokens"
107
163
  },
108
164
  dependencies: {
109
- "@commander-js/extra-typings": "^13.1.0",
165
+ "@commander-js/extra-typings": "^14.0.0",
110
166
  "@tokens-studio/sd-transforms": "1.3.0",
111
167
  "apca-w3": "^0.1.9",
112
168
  chalk: "^5.4.1",
@@ -117,11 +173,11 @@ var package_default = {
117
173
  "fast-glob": "^3.3.3",
118
174
  hsluv: "^1.0.1",
119
175
  "object-hash": "^3.0.0",
120
- postcss: "^8.5.3",
176
+ postcss: "^8.5.5",
121
177
  ramda: "^0.30.1",
122
178
  "style-dictionary": "^4.4.0",
123
- zod: "^3.25.30",
124
- "zod-validation-error": "^3.4.1"
179
+ zod: "^3.25.64",
180
+ "zod-validation-error": "^3.5.0"
125
181
  },
126
182
  devDependencies: {
127
183
  "@tokens-studio/types": "0.5.2",
@@ -129,20 +185,18 @@ var package_default = {
129
185
  "@types/chroma-js": "^3.1.1",
130
186
  "@types/fs-extra": "^11.0.4",
131
187
  "@types/glob": "^8.1.0",
132
- "@types/jscodeshift": "^0.12.0",
133
- "@types/node": "^22.15.21",
188
+ "@types/node": "^22.15.31",
134
189
  "@types/object-hash": "^3.0.6",
135
190
  "@types/ramda": "^0.30.2",
136
191
  "fs-extra": "^11.3.0",
137
- "ts-toolbelt": "^9.6.0",
138
192
  tslib: "^2.8.1",
139
193
  tsup: "^8.5.0",
140
- tsx: "^4.19.4",
194
+ tsx: "^4.20.3",
141
195
  typescript: "^5.8.3"
142
196
  }
143
197
  };
144
198
 
145
- // src/tokens/process/theme.ts
199
+ // src/tokens/process/output/theme.ts
146
200
  var defaultFileHeader = `build: v${package_default.version}`;
147
201
  var createThemeCSSFiles = ({
148
202
  processedBuilds,
@@ -264,7 +318,9 @@ function isGlobalColorToken(token) {
264
318
  }
265
319
  function isColorCategoryToken(token, category) {
266
320
  if (!category) {
267
- return ["main", "support"].some((c) => isColorCategoryToken(token, c));
321
+ return Object.keys(colorCategories).some(
322
+ (colorCategory2) => isColorCategoryToken(token, colorCategory2)
323
+ );
268
324
  }
269
325
  return R2.startsWith(["color", category], token.path);
270
326
  }
@@ -309,7 +365,7 @@ var prefersColorScheme = (colorScheme2, content) => `
309
365
  `;
310
366
  var colorScheme = {
311
367
  name: "ds/css-colorscheme",
312
- format: async ({ dictionary, file, options, platform }) => {
368
+ format: async ({ dictionary, options, platform }) => {
313
369
  const { allTokens } = dictionary;
314
370
  const { outputReferences, usesDtcg } = options;
315
371
  const { selector, colorScheme: colorScheme2, layer } = platform;
@@ -351,7 +407,7 @@ ${selector} ${content} ${autoSelectorContent}
351
407
  };
352
408
  var colorCategory = {
353
409
  name: "ds/css-colorcategory",
354
- format: async ({ dictionary, file, options, platform }) => {
410
+ format: async ({ dictionary, options, platform }) => {
355
411
  const { outputReferences, usesDtcg } = options;
356
412
  const { selector, layer } = platform;
357
413
  const format = R3.compose(
@@ -394,7 +450,7 @@ var isInlineTokens = R4.anyPass([isNumericBorderRadiusToken, isNumericSizeToken,
394
450
  var overrideSizingFormula = (format, token) => {
395
451
  const [name, value] = format(token).split(":");
396
452
  const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
397
- const round = `round(down, ${calc}, 0.0625rem)`;
453
+ const round = `round(down, ${calc}, 1px)`;
398
454
  return {
399
455
  name,
400
456
  round,
@@ -422,7 +478,7 @@ ${round.join("\n")}
422
478
  };
423
479
  var semantic = {
424
480
  name: "ds/css-semantic",
425
- format: async ({ dictionary, file, options, platform }) => {
481
+ format: async ({ dictionary, options, platform }) => {
426
482
  const { outputReferences, usesDtcg } = options;
427
483
  const { selector, layer } = platform;
428
484
  const format = createPropertyFormatter2({
@@ -460,7 +516,7 @@ var typographyFontFamilyPredicate = R5.allPass([
460
516
  ]);
461
517
  var typography = {
462
518
  name: "ds/css-typography",
463
- format: async ({ dictionary, file, options, platform }) => {
519
+ format: async ({ dictionary, options, platform }) => {
464
520
  const { outputReferences, usesDtcg } = options;
465
521
  const { selector, layer } = platform;
466
522
  const format = createPropertyFormatter3({
@@ -601,7 +657,7 @@ var colorCategoryVariables = (opts) => ({ "color-scheme": colorScheme2, theme, .
601
657
  );
602
658
  }
603
659
  const layer = `ds.theme.color`;
604
- const isRootColor = color === buildOptions?.rootColor;
660
+ const isRootColor = color === buildOptions?.defaultColor;
605
661
  const selector = isRootColor ? `:root, [data-color-scheme], [data-color="${color}"]` : `[data-color="${color}"], [data-color-scheme][data-color="${color}"]`;
606
662
  const config = {
607
663
  preprocessors: ["tokens-studio"],
@@ -1008,8 +1064,7 @@ function processThemeObject(theme) {
1008
1064
  }
1009
1065
  function groupThemes(themes) {
1010
1066
  const groups = {};
1011
- for (const rawTheme of themes) {
1012
- const theme = processThemeObject(rawTheme);
1067
+ for (const theme of themes) {
1013
1068
  if (theme.group) {
1014
1069
  const groupKey = theme.group;
1015
1070
  groups[groupKey] = [...groups[groupKey] ?? [], theme];
@@ -1160,9 +1215,12 @@ var initResult = {
1160
1215
  };
1161
1216
  var buildOptions;
1162
1217
  var sd = new StyleDictionary2();
1163
- var getCustomColors = (processed$themes) => processed$themes.filter(
1164
- (x) => x.group && [colorCategories.main, colorCategories.support].map((c) => `${c}-color`).includes(x.group)
1165
- ).map((x) => x.name);
1218
+ var getCustomColors = (processed$themes, colorGroups) => processed$themes.filter((x) => {
1219
+ if (!x.group) {
1220
+ return false;
1221
+ }
1222
+ return colorGroups.includes(x.group);
1223
+ }).map((x) => x.name);
1166
1224
  var buildConfigs = {
1167
1225
  typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
1168
1226
  "color-scheme": { getConfig: configs.colorSchemeVariables, dimensions: ["color-scheme"] },
@@ -1203,17 +1261,40 @@ var buildConfigs = {
1203
1261
  // },
1204
1262
  };
1205
1263
  async function processPlatform(options) {
1206
- const { process, $themes } = options;
1264
+ const { type, $themes } = options;
1207
1265
  const platform = "css";
1208
- const tokenSets = process === "format" ? options.tokenSets : void 0;
1209
- const tokensDir = process === "build" ? options.tokensDir : void 0;
1266
+ const tokenSets = type === "format" ? options.tokenSets : void 0;
1267
+ const tokensDir = type === "build" ? options.tokensDir : void 0;
1268
+ const UNSAFE_DEFAULT_COLOR = process.env.UNSAFE_DEFAULT_COLOR ?? "";
1269
+ if (UNSAFE_DEFAULT_COLOR) {
1270
+ console.warn(
1271
+ chalk4.yellow(
1272
+ `
1273
+ \u26A0\uFE0F UNSAFE_DEFAULT_COLOR is set to ${chalk4.blue(UNSAFE_DEFAULT_COLOR)}. This will override the default color.`
1274
+ )
1275
+ );
1276
+ }
1277
+ const UNSAFE_COLOR_GROUPS = Array.from(process.env.UNSAFE_COLOR_GROUPS?.split(",") ?? []);
1278
+ if (UNSAFE_COLOR_GROUPS.length > 0) {
1279
+ console.warn(
1280
+ chalk4.yellow(
1281
+ `
1282
+ \u26A0\uFE0F UNSAFE_COLOR_GROUPS is set to ${chalk4.blue(`[${UNSAFE_COLOR_GROUPS.join(", ")}]`)}. This will override the default color groups.`
1283
+ )
1284
+ );
1285
+ }
1286
+ const colorGroups = UNSAFE_COLOR_GROUPS.length > 0 ? UNSAFE_COLOR_GROUPS : [colorCategories.main, colorCategories.support].map((c) => `${c}-color`);
1210
1287
  buildOptions = options;
1288
+ buildOptions.defaultColor = UNSAFE_DEFAULT_COLOR;
1211
1289
  const processed$themes = $themes.map(processThemeObject).filter((theme) => R13.not(theme.group === "size" && theme.name !== "medium"));
1212
- const customColors = getCustomColors(processed$themes);
1213
- if (!buildOptions.rootColor) {
1290
+ const customColors = getCustomColors(processed$themes, colorGroups);
1291
+ if (!buildOptions.defaultColor) {
1214
1292
  const firstMainColor = R13.head(customColors);
1215
- buildOptions.rootColor = firstMainColor;
1216
- console.log(`Using first main color; ${chalk4.blue(firstMainColor)}, as ${chalk4.green(`":root"`)} color`);
1293
+ buildOptions.defaultColor = firstMainColor;
1294
+ }
1295
+ if (buildOptions.defaultColor) {
1296
+ console.log(`
1297
+ \u{1F3A8} Using ${chalk4.blue(buildOptions.defaultColor)} as default color`);
1217
1298
  }
1218
1299
  const buildAndSdConfigs = R13.map((buildConfig) => {
1219
1300
  const sdConfigs = getConfigsForThemeDimensions(buildConfig.getConfig, processed$themes, buildConfig.dimensions, {
@@ -1324,7 +1405,7 @@ var buildTokens = async (options) => {
1324
1405
  try {
1325
1406
  const $designsystemetContent = await readFile(`${tokensDir}/$designsystemet.json`);
1326
1407
  $designsystemet = JSON.parse($designsystemetContent);
1327
- } catch (error) {
1408
+ } catch (_error) {
1328
1409
  }
1329
1410
  console.log(`
1330
1411
  \u{1F3D7}\uFE0F Start building tokens in ${chalk5.green(tokensDir)}`);
@@ -1332,23 +1413,25 @@ var buildTokens = async (options) => {
1332
1413
  ...options,
1333
1414
  outDir,
1334
1415
  tokensDir,
1335
- process: "build",
1416
+ type: "build",
1336
1417
  $themes
1337
1418
  });
1338
- if (options.clean) {
1339
- await cleanDir(outDir, options.dry);
1419
+ const fileHeader2 = R14.join("")([
1420
+ defaultFileHeader,
1421
+ $designsystemet ? `
1422
+ design-tokens: v${$designsystemet.version}` : ""
1423
+ ]);
1424
+ let cssFiles = createThemeCSSFiles({ processedBuilds, fileHeader: fileHeader2 });
1425
+ if (options.tailwind) {
1426
+ const tailwindFiles = createTailwindCSSFiles(cssFiles);
1427
+ cssFiles = cssFiles.concat(tailwindFiles.filter(Boolean));
1340
1428
  }
1341
1429
  console.log(`
1342
1430
  \u{1F4BE} Writing build to ${chalk5.green(outDir)}`);
1343
1431
  for (const { formatted } of processedBuilds.types) {
1344
1432
  await write(formatted, outDir, options.dry);
1345
1433
  }
1346
- const fileHeader2 = R14.join("")([
1347
- defaultFileHeader,
1348
- $designsystemet ? `
1349
- design-tokens: v${$designsystemet.version}` : ""
1350
- ]);
1351
- await write(createThemeCSSFiles({ processedBuilds, fileHeader: fileHeader2 }), outDir, options.dry);
1434
+ await write(cssFiles, outDir, options.dry);
1352
1435
  console.log(`
1353
1436
  \u2705 Finished building tokens!`);
1354
1437
  return processedBuilds;
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@digdir/designsystemet",
4
- version: "1.0.7",
4
+ version: "1.1.0",
5
5
  description: "CLI for Designsystemet",
6
6
  author: "Designsystemet team",
7
7
  engines: {
@@ -11,7 +11,7 @@ var package_default = {
11
11
  type: "git",
12
12
  url: "git+https://github.com/digdir/designsystemet.git"
13
13
  },
14
- homepage: "https://github.com/digdir/designsystemet/tree/main/scripts/cli",
14
+ homepage: "https://github.com/digdir/designsystemet/tree/main/packages/cli",
15
15
  license: "MIT",
16
16
  type: "module",
17
17
  main: "./dist/src/index.js",
@@ -36,8 +36,6 @@ var package_default = {
36
36
  },
37
37
  scripts: {
38
38
  designsystemet: "tsx ./bin/designsystemet.ts",
39
- "build:tokens": "pnpm run designsystemet tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
40
- "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
41
39
  build: "tsup && pnpm build:types && pnpm build:json-schema",
42
40
  "build:types": "tsc --emitDeclarationOnly --declaration",
43
41
  "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
@@ -45,17 +43,20 @@ var package_default = {
45
43
  "test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
46
44
  "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
47
45
  "test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
46
+ "test:tokens-build-tailwind": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean --experimental-tailwind",
48
47
  "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
48
+ "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
49
49
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
50
50
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
51
51
  test: "pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
52
+ "digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
52
53
  "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
53
54
  "update:template": "tsx ./src/scripts/update-template.ts",
54
- "update:design-tokens": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
55
- verify: "pnpm test && pnpm update:template && pnpm update:design-tokens"
55
+ "update:theme-digdir": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts && pnpm digdir:tokens-build",
56
+ verify: "pnpm test && pnpm update:template && pnpm update:theme-digdir && pnpm build:tokens"
56
57
  },
57
58
  dependencies: {
58
- "@commander-js/extra-typings": "^13.1.0",
59
+ "@commander-js/extra-typings": "^14.0.0",
59
60
  "@tokens-studio/sd-transforms": "1.3.0",
60
61
  "apca-w3": "^0.1.9",
61
62
  chalk: "^5.4.1",
@@ -66,11 +67,11 @@ var package_default = {
66
67
  "fast-glob": "^3.3.3",
67
68
  hsluv: "^1.0.1",
68
69
  "object-hash": "^3.0.0",
69
- postcss: "^8.5.3",
70
+ postcss: "^8.5.5",
70
71
  ramda: "^0.30.1",
71
72
  "style-dictionary": "^4.4.0",
72
- zod: "^3.25.30",
73
- "zod-validation-error": "^3.4.1"
73
+ zod: "^3.25.64",
74
+ "zod-validation-error": "^3.5.0"
74
75
  },
75
76
  devDependencies: {
76
77
  "@tokens-studio/types": "0.5.2",
@@ -78,15 +79,13 @@ var package_default = {
78
79
  "@types/chroma-js": "^3.1.1",
79
80
  "@types/fs-extra": "^11.0.4",
80
81
  "@types/glob": "^8.1.0",
81
- "@types/jscodeshift": "^0.12.0",
82
- "@types/node": "^22.15.21",
82
+ "@types/node": "^22.15.31",
83
83
  "@types/object-hash": "^3.0.6",
84
84
  "@types/ramda": "^0.30.2",
85
85
  "fs-extra": "^11.3.0",
86
- "ts-toolbelt": "^9.6.0",
87
86
  tslib: "^2.8.1",
88
87
  tsup: "^8.5.0",
89
- tsx: "^4.19.4",
88
+ tsx: "^4.20.3",
90
89
  typescript: "^5.8.3"
91
90
  }
92
91
  };