@digdir/designsystemet 1.0.3 → 1.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (186) hide show
  1. package/dist/bin/designsystemet.js +4264 -45
  2. package/dist/bin/options.js +5 -4
  3. package/dist/src/colors/colorMetadata.js +5 -4
  4. package/dist/src/colors/index.js +470 -4
  5. package/dist/src/colors/theme.js +286 -20
  6. package/dist/src/colors/utils.js +16 -15
  7. package/dist/{bin → src}/config.d.ts +46 -1
  8. package/dist/src/config.d.ts.map +1 -0
  9. package/dist/src/config.js +377 -0
  10. package/dist/src/index.js +3666 -2
  11. package/dist/src/migrations/beta-to-v1.js +85 -4
  12. package/dist/src/migrations/codemods/css/plugins.js +5 -4
  13. package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
  14. package/dist/src/migrations/codemods/css/run.js +18 -4
  15. package/dist/src/migrations/color-rename-next49.js +77 -6
  16. package/dist/src/migrations/index.d.ts +0 -1
  17. package/dist/src/migrations/index.d.ts.map +1 -1
  18. package/dist/src/migrations/index.js +461 -6
  19. package/dist/src/scripts/createJsonSchema.js +1608 -4
  20. package/dist/src/scripts/update-design-tokens.d.ts +2 -0
  21. package/dist/src/scripts/update-design-tokens.d.ts.map +1 -0
  22. package/dist/src/scripts/update-design-tokens.js +36 -0
  23. package/dist/src/{tokens/template.d.ts → scripts/update-template.d.ts} +1 -1
  24. package/dist/src/scripts/update-template.d.ts.map +1 -0
  25. package/dist/src/scripts/update-template.js +1200 -0
  26. package/dist/src/tokens/build.d.ts +2 -19
  27. package/dist/src/tokens/build.d.ts.map +1 -1
  28. package/dist/src/tokens/build.js +1511 -70
  29. package/dist/src/tokens/create/defaults.d.ts +7 -0
  30. package/dist/src/tokens/create/defaults.d.ts.map +1 -0
  31. package/dist/src/tokens/create/defaults.js +994 -0
  32. package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
  33. package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
  34. package/dist/src/tokens/create/generators/$designsystemet.js +100 -0
  35. package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
  36. package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
  37. package/dist/src/tokens/{write/generate$metadata.js → create/generators/$metadata.js} +3 -2
  38. package/dist/src/tokens/create/generators/$themes.d.ts +12 -0
  39. package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
  40. package/dist/src/tokens/create/generators/$themes.js +333 -0
  41. package/dist/src/tokens/create/generators/color.d.ts +5 -0
  42. package/dist/src/tokens/create/generators/color.d.ts.map +1 -0
  43. package/dist/src/tokens/create/generators/color.js +374 -0
  44. package/dist/src/tokens/create/generators/semantic.d.ts +296 -0
  45. package/dist/src/tokens/create/generators/semantic.d.ts.map +1 -0
  46. package/dist/src/tokens/create/generators/semantic.js +483 -0
  47. package/dist/src/tokens/create/generators/theme.d.ts +3 -0
  48. package/dist/src/tokens/create/generators/theme.d.ts.map +1 -0
  49. package/dist/src/tokens/create/generators/theme.js +168 -0
  50. package/dist/src/tokens/create/generators/typography.d.ts +3 -0
  51. package/dist/src/tokens/create/generators/typography.d.ts.map +1 -0
  52. package/dist/src/tokens/create/generators/typography.js +33 -0
  53. package/dist/src/tokens/{write.d.ts → create/write.d.ts} +2 -2
  54. package/dist/src/tokens/create/write.d.ts.map +1 -0
  55. package/dist/src/tokens/create/write.js +546 -0
  56. package/dist/src/tokens/create.d.ts +4 -2
  57. package/dist/src/tokens/create.d.ts.map +1 -1
  58. package/dist/src/tokens/create.js +2049 -59
  59. package/dist/src/tokens/format.d.ts +16 -0
  60. package/dist/src/tokens/format.d.ts.map +1 -0
  61. package/dist/src/tokens/format.js +3514 -0
  62. package/dist/src/tokens/index.d.ts +1 -0
  63. package/dist/src/tokens/index.d.ts.map +1 -1
  64. package/dist/src/tokens/index.js +3526 -2
  65. package/dist/src/tokens/process/configs/color.d.ts +12 -0
  66. package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
  67. package/dist/src/tokens/process/configs/color.js +823 -0
  68. package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
  69. package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
  70. package/dist/src/tokens/process/configs/semantic.js +367 -0
  71. package/dist/src/tokens/process/configs/shared.d.ts +10 -0
  72. package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
  73. package/dist/src/tokens/process/configs/shared.js +99 -0
  74. package/dist/src/tokens/process/configs/storefront.d.ts +3 -0
  75. package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -0
  76. package/dist/src/tokens/process/configs/storefront.js +220 -0
  77. package/dist/src/tokens/process/configs/typography.d.ts +3 -0
  78. package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
  79. package/dist/src/tokens/process/configs/typography.js +369 -0
  80. package/dist/src/tokens/{build → process}/configs.d.ts +3 -11
  81. package/dist/src/tokens/process/configs.d.ts.map +1 -0
  82. package/dist/src/tokens/process/configs.js +976 -0
  83. package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
  84. package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
  85. package/dist/src/tokens/process/formats/css/color.js +128 -0
  86. package/dist/src/tokens/process/formats/css/semantic.d.ts +17 -0
  87. package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
  88. package/dist/src/tokens/process/formats/css/semantic.js +109 -0
  89. package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
  90. package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
  91. package/dist/src/tokens/process/formats/css/typography.js +32 -0
  92. package/dist/src/tokens/process/formats/css.d.ts +8 -0
  93. package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
  94. package/dist/src/tokens/{build → process}/formats/css.js +94 -57
  95. package/dist/src/tokens/process/formats/js-tokens.d.ts.map +1 -0
  96. package/dist/src/tokens/process/formats/js-tokens.js +109 -0
  97. package/dist/src/tokens/process/platform.d.ts +87 -0
  98. package/dist/src/tokens/process/platform.d.ts.map +1 -0
  99. package/dist/src/tokens/process/platform.js +1090 -0
  100. package/dist/src/tokens/process/transformers.d.ts.map +1 -0
  101. package/dist/src/tokens/{build → process}/transformers.js +29 -6
  102. package/dist/src/tokens/{build → process}/utils/getMultidimensionalThemes.d.ts +3 -3
  103. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
  104. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +922 -0
  105. package/dist/src/tokens/template/design-tokens/primitives/globals.js +5 -0
  106. package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +5 -0
  107. package/dist/src/tokens/template/design-tokens/primitives/modes/size/large.js +5 -0
  108. package/dist/src/tokens/template/design-tokens/primitives/modes/size/medium.js +5 -0
  109. package/dist/src/tokens/template/design-tokens/primitives/modes/size/small.js +5 -0
  110. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/large.js +5 -0
  111. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/medium.js +5 -0
  112. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/small.js +5 -0
  113. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/typography.template.js +5 -0
  114. package/dist/src/tokens/template/design-tokens/semantic/color.base.template.js +5 -0
  115. package/dist/src/tokens/template/design-tokens/semantic/color.template.js +5 -0
  116. package/dist/src/tokens/template/design-tokens/semantic/modes/color.template.js +5 -0
  117. package/dist/src/tokens/template/design-tokens/semantic/style.js +5 -0
  118. package/dist/src/tokens/template/design-tokens/themes/theme.base.template.js +5 -0
  119. package/dist/src/tokens/template/design-tokens/themes/theme.template.js +5 -0
  120. package/dist/src/tokens/types.d.ts +54 -38
  121. package/dist/src/tokens/types.d.ts.map +1 -1
  122. package/dist/src/tokens/types.js +8 -0
  123. package/dist/src/tokens/utils.d.ts +30 -5
  124. package/dist/src/tokens/utils.d.ts.map +1 -1
  125. package/dist/src/tokens/utils.js +36 -50
  126. package/dist/src/utils.d.ts +18 -0
  127. package/dist/src/utils.d.ts.map +1 -0
  128. package/dist/src/utils.js +63 -0
  129. package/dist/typography.template-4N5YLH7F.json +22 -0
  130. package/package.json +17 -16
  131. package/dist/bin/config.d.ts.map +0 -1
  132. package/dist/bin/config.js +0 -71
  133. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
  134. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
  135. package/dist/src/migrations/codemods/jsx/classname-prefix.js +0 -64
  136. package/dist/src/migrations/codemods/jsx/run.d.ts +0 -7
  137. package/dist/src/migrations/codemods/jsx/run.d.ts.map +0 -1
  138. package/dist/src/migrations/codemods/jsx/run.js +0 -22
  139. package/dist/src/migrations/react-beta-to-v1.d.ts +0 -3
  140. package/dist/src/migrations/react-beta-to-v1.d.ts.map +0 -1
  141. package/dist/src/migrations/react-beta-to-v1.js +0 -5
  142. package/dist/src/scripts/copy-internal-tokens.d.ts +0 -2
  143. package/dist/src/scripts/copy-internal-tokens.d.ts.map +0 -1
  144. package/dist/src/scripts/copy-internal-tokens.js +0 -28
  145. package/dist/src/tokens/build/configs.d.ts.map +0 -1
  146. package/dist/src/tokens/build/configs.js +0 -280
  147. package/dist/src/tokens/build/formats/css.d.ts +0 -53
  148. package/dist/src/tokens/build/formats/css.d.ts.map +0 -1
  149. package/dist/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
  150. package/dist/src/tokens/build/formats/js-tokens.js +0 -48
  151. package/dist/src/tokens/build/transformers.d.ts.map +0 -1
  152. package/dist/src/tokens/build/types.d.ts +0 -48
  153. package/dist/src/tokens/build/types.d.ts.map +0 -1
  154. package/dist/src/tokens/build/types.js +0 -7
  155. package/dist/src/tokens/build/utils/entryfile.d.ts +0 -12
  156. package/dist/src/tokens/build/utils/entryfile.d.ts.map +0 -1
  157. package/dist/src/tokens/build/utils/entryfile.js +0 -67
  158. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +0 -1
  159. package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +0 -112
  160. package/dist/src/tokens/design-tokens/template/$metadata.json +0 -25
  161. package/dist/src/tokens/design-tokens/template/$themes.json +0 -1498
  162. package/dist/src/tokens/template.d.ts.map +0 -1
  163. package/dist/src/tokens/template.js +0 -99
  164. package/dist/src/tokens/write/generate$metadata.d.ts +0 -9
  165. package/dist/src/tokens/write/generate$metadata.d.ts.map +0 -1
  166. package/dist/src/tokens/write/generate$themes.d.ts +0 -12
  167. package/dist/src/tokens/write/generate$themes.d.ts.map +0 -1
  168. package/dist/src/tokens/write/generate$themes.js +0 -161
  169. package/dist/src/tokens/write.d.ts.map +0 -1
  170. package/dist/src/tokens/write.js +0 -177
  171. /package/dist/{src/tokens/design-tokens/template/semantic/color-base-file.json → color.base.template-M7BHS4OV.json} +0 -0
  172. /package/dist/{src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json → color.template-LMPUQ72A.json} +0 -0
  173. /package/dist/{src/tokens/design-tokens/template/semantic/semantic-color-template.json → color.template-XQNSHLTU.json} +0 -0
  174. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/global.json → global-XVXVBKM6.json} +0 -0
  175. /package/dist/{src/tokens/design-tokens/default/primitives/globals.json → globals-76VAFMDF.json} +0 -0
  176. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/large.json → large-CIIHO7AY.json} +0 -0
  177. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/large.json → large-UUOZ6DYI.json} +0 -0
  178. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/medium.json → medium-OQ7S7P4P.json} +0 -0
  179. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json → medium-VSB2S4X3.json} +0 -0
  180. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/small.json → small-AEXJ6U7Z.json} +0 -0
  181. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/small.json → small-ZY4KOJWX.json} +0 -0
  182. /package/dist/src/tokens/{build → process}/formats/js-tokens.d.ts +0 -0
  183. /package/dist/src/tokens/{build → process}/transformers.d.ts +0 -0
  184. /package/dist/{src/tokens/design-tokens/default/semantic/style.json → style-FP5XVCUD.json} +0 -0
  185. /package/dist/{src/tokens/design-tokens/template/themes/theme-base-file.json → theme.base.template-Y4RMFBQY.json} +0 -0
  186. /package/dist/{src/tokens/design-tokens/template/themes/theme-color-template.json → theme.template-CTQRNOMO.json} +0 -0
@@ -1,11 +1,11 @@
1
- import type { Theme, Tokens } from './types.js';
1
+ import type { Theme, TokenSets } from '../types.js';
2
2
  export declare const stringify: (data: unknown) => string;
3
3
  type WriteTokensOptions = {
4
4
  outDir: string;
5
- tokens: Tokens;
6
5
  theme: Theme;
7
6
  /** Dry run, no files will be written */
8
7
  dry?: boolean;
8
+ tokenSets: TokenSets;
9
9
  };
10
10
  export declare const writeTokens: (options: WriteTokensOptions) => Promise<void>;
11
11
  export {};
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../../src/tokens/create/write.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAKpD,eAAO,MAAM,SAAS,GAAI,MAAM,OAAO,WAAkC,CAAC;AAE1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAC;IACd,SAAS,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,SAAS,kBAAkB,kBAwD5D,CAAC"}
@@ -0,0 +1,546 @@
1
+ // src/tokens/create/write.ts
2
+ import path from "node:path";
3
+ import chalk2 from "chalk";
4
+ import * as R from "ramda";
5
+
6
+ // src/utils.ts
7
+ import fs from "node:fs/promises";
8
+ import chalk from "chalk";
9
+ var mkdir = async (dir, dry) => {
10
+ if (dry) {
11
+ console.log(`${chalk.blue("mkdir")} ${dir}`);
12
+ return Promise.resolve();
13
+ }
14
+ const exists = await fs.access(dir, fs.constants.F_OK).then(() => true).catch(() => false);
15
+ if (exists) {
16
+ return Promise.resolve();
17
+ }
18
+ return fs.mkdir(dir, { recursive: true });
19
+ };
20
+ var writeFile = async (path2, data, dry) => {
21
+ if (dry) {
22
+ console.log(`${chalk.blue("writeFile")} ${path2}`);
23
+ return Promise.resolve();
24
+ }
25
+ return fs.writeFile(path2, data, { encoding: "utf-8" }).catch((error) => {
26
+ console.error(chalk.red(`Error writing file: ${path2}`));
27
+ console.error(chalk.red(error));
28
+ throw error;
29
+ });
30
+ };
31
+ var readFile = async (path2, dry) => {
32
+ if (dry) {
33
+ console.log(`${chalk.blue("readFile")} ${path2}`);
34
+ return Promise.resolve("");
35
+ }
36
+ return fs.readFile(path2, "utf-8");
37
+ };
38
+
39
+ // package.json
40
+ var package_default = {
41
+ name: "@digdir/designsystemet",
42
+ version: "1.0.4",
43
+ description: "CLI for Designsystemet",
44
+ author: "Designsystemet team",
45
+ engines: {
46
+ node: ">=22.14.0"
47
+ },
48
+ repository: {
49
+ type: "git",
50
+ url: "git+https://github.com/digdir/designsystemet.git"
51
+ },
52
+ homepage: "https://github.com/digdir/designsystemet/tree/main/scripts/cli",
53
+ license: "MIT",
54
+ type: "module",
55
+ main: "./dist/src/index.js",
56
+ files: [
57
+ "./dist/**"
58
+ ],
59
+ bin: "dist/bin/designsystemet.js",
60
+ exports: {
61
+ ".": {
62
+ import: "./dist/src/index.js"
63
+ },
64
+ "./color": {
65
+ import: "./dist/src/colors/index.js"
66
+ },
67
+ "./tokens": {
68
+ import: "./dist/src/tokens/index.js"
69
+ }
70
+ },
71
+ publishConfig: {
72
+ access: "public"
73
+ },
74
+ scripts: {
75
+ designsystemet: "tsx ./bin/designsystemet.ts",
76
+ "build:tokens": "yarn designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
77
+ "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
78
+ build: "tsup && yarn build:types && yarn build:json-schema",
79
+ "build:types": "tsc --emitDeclarationOnly --declaration",
80
+ "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
81
+ types: "tsc --noEmit",
82
+ "test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 -n #003333 -b 99 -o ./test-tokens-create --theme options-test --clean",
83
+ "test:tokens-create-config": "yarn designsystemet tokens create --config ./test-tokens-create-complex.config.json",
84
+ "test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens-create -o ./test-tokens-build --clean",
85
+ "test:tokens-create-and-build-options": "yarn test:tokens-create-options && yarn test:tokens-build",
86
+ "test:tokens-create-and-build-config": "yarn test:tokens-create-config && yarn test:tokens-build",
87
+ test: "yarn test:tokens-create-and-build-options && yarn test:tokens-create-and-build-config",
88
+ "internal:tokens-create": "yarn designsystemet tokens create --config ./internal.config.json",
89
+ "update:template": "tsx ./src/scripts/update-template.ts",
90
+ "update:design-tokens": "yarn internal:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
91
+ verify: "yarn test && yarn update:template && yarn update:design-tokens"
92
+ },
93
+ dependencies: {
94
+ "@commander-js/extra-typings": "^13.1.0",
95
+ "@tokens-studio/sd-transforms": "1.2.12",
96
+ "apca-w3": "^0.1.9",
97
+ chalk: "^5.4.1",
98
+ "change-case": "^5.4.4",
99
+ "chroma-js": "^3.1.2",
100
+ commander: "^13.1.0",
101
+ "fast-glob": "^3.3.3",
102
+ hsluv: "^1.0.1",
103
+ "object-hash": "^3.0.0",
104
+ postcss: "^8.5.3",
105
+ ramda: "^0.30.1",
106
+ "style-dictionary": "^4.3.3",
107
+ zod: "^3.24.2",
108
+ "zod-validation-error": "^3.4.0"
109
+ },
110
+ devDependencies: {
111
+ "@types/apca-w3": "^0.1.3",
112
+ "@types/chroma-js": "^3.1.1",
113
+ "@types/fs-extra": "^11.0.4",
114
+ "@types/glob": "^8.1.0",
115
+ "@types/jscodeshift": "^0.12.0",
116
+ "@types/node": "^22.14.0",
117
+ "@types/object-hash": "^3.0.6",
118
+ "@types/ramda": "^0.30.2",
119
+ "fs-extra": "^11.3.0",
120
+ "ts-toolbelt": "^9.6.0",
121
+ tslib: "^2.8.1",
122
+ tsup: "^8.4.0",
123
+ tsx: "^4.19.3",
124
+ typescript: "^5.8.2",
125
+ "zod-to-json-schema": "^3.24.5"
126
+ }
127
+ };
128
+
129
+ // src/tokens/create/generators/$designsystemet.ts
130
+ function generate$Designsystemet() {
131
+ return {
132
+ name: package_default.name,
133
+ version: package_default.version
134
+ };
135
+ }
136
+
137
+ // src/tokens/create/generators/$metadata.ts
138
+ function generate$Metadata(schemes, themes, colors) {
139
+ return {
140
+ tokenSetOrder: [
141
+ "primitives/globals",
142
+ "primitives/modes/size/small",
143
+ "primitives/modes/size/medium",
144
+ "primitives/modes/size/large",
145
+ "primitives/modes/size/global",
146
+ "primitives/modes/typography/size/small",
147
+ "primitives/modes/typography/size/medium",
148
+ "primitives/modes/typography/size/large",
149
+ ...themes.map((theme) => `primitives/modes/typography/primary/${theme}`),
150
+ ...themes.map((theme) => `primitives/modes/typography/secondary/${theme}`),
151
+ ...schemes.flatMap((scheme) => [
152
+ `primitives/modes/color-scheme/${scheme}/global`,
153
+ ...themes.map((theme) => `primitives/modes/color-scheme/${scheme}/${theme}`)
154
+ ]),
155
+ ...themes.map((theme) => `themes/${theme}`),
156
+ "semantic/color",
157
+ ...Object.entries(colors.main).map(([color]) => `semantic/modes/main-color/${color}`),
158
+ ...Object.entries(colors.support).map(([color]) => `semantic/modes/support-color/${color}`),
159
+ "semantic/style"
160
+ ]
161
+ };
162
+ }
163
+
164
+ // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
165
+ var BoxShadowTypes;
166
+ (function(BoxShadowTypes2) {
167
+ BoxShadowTypes2["DROP_SHADOW"] = "dropShadow";
168
+ BoxShadowTypes2["INNER_SHADOW"] = "innerShadow";
169
+ })(BoxShadowTypes || (BoxShadowTypes = {}));
170
+
171
+ // ../../node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
172
+ var ColorModifierTypes;
173
+ (function(ColorModifierTypes2) {
174
+ ColorModifierTypes2["LIGHTEN"] = "lighten";
175
+ ColorModifierTypes2["DARKEN"] = "darken";
176
+ ColorModifierTypes2["MIX"] = "mix";
177
+ ColorModifierTypes2["ALPHA"] = "alpha";
178
+ })(ColorModifierTypes || (ColorModifierTypes = {}));
179
+
180
+ // ../../node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
181
+ var ColorSpaceTypes;
182
+ (function(ColorSpaceTypes2) {
183
+ ColorSpaceTypes2["LCH"] = "lch";
184
+ ColorSpaceTypes2["SRGB"] = "srgb";
185
+ ColorSpaceTypes2["P3"] = "p3";
186
+ ColorSpaceTypes2["HSL"] = "hsl";
187
+ })(ColorSpaceTypes || (ColorSpaceTypes = {}));
188
+
189
+ // ../../node_modules/@tokens-studio/types/dist/constants/Properties.js
190
+ var Properties;
191
+ (function(Properties2) {
192
+ Properties2["sizing"] = "sizing";
193
+ Properties2["height"] = "height";
194
+ Properties2["width"] = "width";
195
+ Properties2["spacing"] = "spacing";
196
+ Properties2["verticalPadding"] = "verticalPadding";
197
+ Properties2["horizontalPadding"] = "horizontalPadding";
198
+ Properties2["paddingTop"] = "paddingTop";
199
+ Properties2["paddingRight"] = "paddingRight";
200
+ Properties2["paddingBottom"] = "paddingBottom";
201
+ Properties2["paddingLeft"] = "paddingLeft";
202
+ Properties2["itemSpacing"] = "itemSpacing";
203
+ Properties2["fill"] = "fill";
204
+ Properties2["backgroundBlur"] = "backgroundBlur";
205
+ Properties2["border"] = "border";
206
+ Properties2["borderTop"] = "borderTop";
207
+ Properties2["borderRight"] = "borderRight";
208
+ Properties2["borderBottom"] = "borderBottom";
209
+ Properties2["borderLeft"] = "borderLeft";
210
+ Properties2["borderColor"] = "borderColor";
211
+ Properties2["borderRadius"] = "borderRadius";
212
+ Properties2["borderRadiusTopLeft"] = "borderRadiusTopLeft";
213
+ Properties2["borderRadiusTopRight"] = "borderRadiusTopRight";
214
+ Properties2["borderRadiusBottomRight"] = "borderRadiusBottomRight";
215
+ Properties2["borderRadiusBottomLeft"] = "borderRadiusBottomLeft";
216
+ Properties2["borderWidth"] = "borderWidth";
217
+ Properties2["borderWidthTop"] = "borderWidthTop";
218
+ Properties2["borderWidthRight"] = "borderWidthRight";
219
+ Properties2["borderWidthBottom"] = "borderWidthBottom";
220
+ Properties2["borderWidthLeft"] = "borderWidthLeft";
221
+ Properties2["boxShadow"] = "boxShadow";
222
+ Properties2["opacity"] = "opacity";
223
+ Properties2["fontFamilies"] = "fontFamilies";
224
+ Properties2["fontWeights"] = "fontWeights";
225
+ Properties2["fontSizes"] = "fontSizes";
226
+ Properties2["lineHeights"] = "lineHeights";
227
+ Properties2["typography"] = "typography";
228
+ Properties2["composition"] = "composition";
229
+ Properties2["letterSpacing"] = "letterSpacing";
230
+ Properties2["paragraphSpacing"] = "paragraphSpacing";
231
+ Properties2["textCase"] = "textCase";
232
+ Properties2["dimension"] = "dimension";
233
+ Properties2["textDecoration"] = "textDecoration";
234
+ Properties2["asset"] = "asset";
235
+ Properties2["tokenValue"] = "tokenValue";
236
+ Properties2["value"] = "value";
237
+ Properties2["tokenName"] = "tokenName";
238
+ Properties2["description"] = "description";
239
+ })(Properties || (Properties = {}));
240
+
241
+ // ../../node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
242
+ var TokenSetStatus;
243
+ (function(TokenSetStatus2) {
244
+ TokenSetStatus2["DISABLED"] = "disabled";
245
+ TokenSetStatus2["SOURCE"] = "source";
246
+ TokenSetStatus2["ENABLED"] = "enabled";
247
+ })(TokenSetStatus || (TokenSetStatus = {}));
248
+
249
+ // ../../node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
250
+ var TokenTypes;
251
+ (function(TokenTypes2) {
252
+ TokenTypes2["OTHER"] = "other";
253
+ TokenTypes2["COLOR"] = "color";
254
+ TokenTypes2["BORDER_RADIUS"] = "borderRadius";
255
+ TokenTypes2["SIZING"] = "sizing";
256
+ TokenTypes2["SPACING"] = "spacing";
257
+ TokenTypes2["TEXT"] = "text";
258
+ TokenTypes2["TYPOGRAPHY"] = "typography";
259
+ TokenTypes2["OPACITY"] = "opacity";
260
+ TokenTypes2["BORDER_WIDTH"] = "borderWidth";
261
+ TokenTypes2["STROKE_STYLE"] = "strokeStyle";
262
+ TokenTypes2["BOX_SHADOW"] = "boxShadow";
263
+ TokenTypes2["FONT_FAMILIES"] = "fontFamilies";
264
+ TokenTypes2["FONT_WEIGHTS"] = "fontWeights";
265
+ TokenTypes2["LINE_HEIGHTS"] = "lineHeights";
266
+ TokenTypes2["FONT_SIZES"] = "fontSizes";
267
+ TokenTypes2["LETTER_SPACING"] = "letterSpacing";
268
+ TokenTypes2["PARAGRAPH_SPACING"] = "paragraphSpacing";
269
+ TokenTypes2["PARAGRAPH_INDENT"] = "paragraphIndent";
270
+ TokenTypes2["TEXT_DECORATION"] = "textDecoration";
271
+ TokenTypes2["TEXT_CASE"] = "textCase";
272
+ TokenTypes2["COMPOSITION"] = "composition";
273
+ TokenTypes2["DIMENSION"] = "dimension";
274
+ TokenTypes2["BORDER"] = "border";
275
+ TokenTypes2["ASSET"] = "asset";
276
+ TokenTypes2["BOOLEAN"] = "boolean";
277
+ TokenTypes2["NUMBER"] = "number";
278
+ })(TokenTypes || (TokenTypes = {}));
279
+
280
+ // ../../node_modules/@tokens-studio/types/dist/constants/BorderValues.js
281
+ var BorderValues;
282
+ (function(BorderValues2) {
283
+ BorderValues2["BORDER_COLOR"] = "color";
284
+ BorderValues2["BORDER_WIDTH"] = "width";
285
+ BorderValues2["BORDER_STYLE"] = "style";
286
+ })(BorderValues || (BorderValues = {}));
287
+
288
+ // ../../node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
289
+ var StrokeStyleValues;
290
+ (function(StrokeStyleValues2) {
291
+ StrokeStyleValues2["SOLID"] = "solid";
292
+ StrokeStyleValues2["DASHED"] = "dashed";
293
+ StrokeStyleValues2["DOTTED"] = "dotted";
294
+ StrokeStyleValues2["DOUBLE"] = "double";
295
+ StrokeStyleValues2["GROOVE"] = "groove";
296
+ StrokeStyleValues2["RIDGE"] = "ridge";
297
+ StrokeStyleValues2["OUTSET"] = "outset";
298
+ StrokeStyleValues2["INSET"] = "inset";
299
+ })(StrokeStyleValues || (StrokeStyleValues = {}));
300
+
301
+ // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
302
+ var BoxShadowValues;
303
+ (function(BoxShadowValues2) {
304
+ BoxShadowValues2["TYPE"] = "type";
305
+ BoxShadowValues2["COLOR"] = "color";
306
+ BoxShadowValues2["X"] = "x";
307
+ BoxShadowValues2["Y"] = "y";
308
+ BoxShadowValues2["BLUR"] = "blur";
309
+ BoxShadowValues2["SPREAD"] = "spread";
310
+ BoxShadowValues2["BLEND_MODE"] = "blendMode";
311
+ })(BoxShadowValues || (BoxShadowValues = {}));
312
+
313
+ // ../../node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
314
+ var TypographyValues;
315
+ (function(TypographyValues2) {
316
+ TypographyValues2["FONT_FAMILY"] = "fontFamily";
317
+ TypographyValues2["FONT_WEIGHT"] = "fontWeight";
318
+ TypographyValues2["LINE_HEIGHT"] = "lineHeight";
319
+ TypographyValues2["FONT_SIZE"] = "fontSize";
320
+ TypographyValues2["LETTER_SPACING"] = "letterSpacing";
321
+ TypographyValues2["PARAGRAPH_SPACING"] = "paragraphSpacing";
322
+ TypographyValues2["PARAGRAPH_INDENT"] = "paragraphIndent";
323
+ TypographyValues2["TEXT_DECORATION"] = "textDecoration";
324
+ TypographyValues2["TEXT_CASE"] = "textCase";
325
+ })(TypographyValues || (TypographyValues = {}));
326
+
327
+ // src/tokens/create/generators/$themes.ts
328
+ var capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
329
+ async function createHash(text, algo = "SHA-1") {
330
+ const crypto = globalThis.crypto;
331
+ return Array.from(
332
+ new Uint8Array(await crypto.subtle.digest(algo, new TextEncoder().encode(text))),
333
+ (byte) => byte.toString(16).padStart(2, "0")
334
+ ).join("");
335
+ }
336
+ async function generate$Themes(colorSchemes, themes, colors) {
337
+ return [
338
+ ...generateSizeGroup(),
339
+ ...await generateThemesGroup(themes),
340
+ ...generateTypographyGroup(themes),
341
+ ...generateColorSchemesGroup(colorSchemes, themes),
342
+ generateSemanticGroup(),
343
+ ...await generateColorGroup("main", colors),
344
+ ...await generateColorGroup("support", colors)
345
+ ];
346
+ }
347
+ function generateSizeGroup() {
348
+ return [
349
+ {
350
+ id: "8b2c8cc86611a34b135cb22948666779361fd729",
351
+ name: "medium",
352
+ $figmaStyleReferences: {},
353
+ selectedTokenSets: {
354
+ "primitives/modes/size/medium": TokenSetStatus.SOURCE,
355
+ "primitives/modes/size/global": TokenSetStatus.ENABLED,
356
+ "primitives/modes/typography/size/medium": TokenSetStatus.ENABLED
357
+ },
358
+ $figmaCollectionId: "VariableCollectionId:36248:20757",
359
+ $figmaModeId: "41630:1",
360
+ group: "Size"
361
+ },
362
+ {
363
+ id: "d49b9eebeb48a4f165a74b7261733d0a73370f0e",
364
+ name: "large",
365
+ $figmaStyleReferences: {},
366
+ selectedTokenSets: {
367
+ "primitives/modes/size/large": TokenSetStatus.SOURCE,
368
+ "primitives/modes/size/global": TokenSetStatus.ENABLED,
369
+ "primitives/modes/typography/size/large": TokenSetStatus.ENABLED
370
+ },
371
+ $figmaCollectionId: "VariableCollectionId:36248:20757",
372
+ $figmaModeId: "41630:2",
373
+ group: "Size"
374
+ },
375
+ {
376
+ id: "fb11567729c298ca37c9da4e3a27716a23480824",
377
+ name: "small",
378
+ $figmaStyleReferences: {},
379
+ selectedTokenSets: {
380
+ "primitives/modes/size/small": TokenSetStatus.SOURCE,
381
+ "primitives/modes/size/global": TokenSetStatus.ENABLED,
382
+ "primitives/modes/typography/size/small": TokenSetStatus.ENABLED
383
+ },
384
+ $figmaCollectionId: "VariableCollectionId:36248:20757",
385
+ $figmaModeId: "41630:3",
386
+ group: "Size"
387
+ }
388
+ ];
389
+ }
390
+ var colorSchemeDefaults = {
391
+ light: {
392
+ name: "Light",
393
+ selectedTokenSets: {},
394
+ id: "0daa3ca0b427b9349da7e7dc00101b5668972926",
395
+ $figmaCollectionId: "VariableCollectionId:34811:5472",
396
+ $figmaModeId: "34811:0"
397
+ },
398
+ dark: {
399
+ name: "Dark",
400
+ selectedTokenSets: {},
401
+ id: "9ebd8aed52afbffc17e2666e8b4653a53498b257",
402
+ $figmaCollectionId: "VariableCollectionId:34811:5472",
403
+ $figmaModeId: "34811:1"
404
+ },
405
+ contrast: {
406
+ name: "Contrast",
407
+ selectedTokenSets: {},
408
+ id: "9ebd8aed52afbffc17e2666e8b4653a53498b123",
409
+ $figmaCollectionId: "VariableCollectionId:34811:5472",
410
+ $figmaModeId: "34811:2"
411
+ }
412
+ };
413
+ function generateColorSchemesGroup(colorSchemes, themes) {
414
+ return colorSchemes.map(
415
+ (scheme) => ({
416
+ ...colorSchemeDefaults[scheme],
417
+ selectedTokenSets: Object.fromEntries([
418
+ [`primitives/modes/color-scheme/${scheme}/global`, TokenSetStatus.ENABLED],
419
+ ...themes.map((theme) => [`primitives/modes/color-scheme/${scheme}/${theme}`, TokenSetStatus.ENABLED])
420
+ ]),
421
+ group: "Color scheme"
422
+ })
423
+ );
424
+ }
425
+ async function generateThemesGroup(themes) {
426
+ return Promise.all(
427
+ themes.map(
428
+ async (theme, index) => ({
429
+ id: await createHash(theme),
430
+ $figmaCollectionId: "VariableCollectionId:36528:61712",
431
+ $figmaModeId: `40960:${index + 6}`,
432
+ // Start on 6 in Token Studio and Community file for some reason
433
+ name: theme,
434
+ selectedTokenSets: {
435
+ [`themes/${theme}`]: TokenSetStatus.ENABLED
436
+ },
437
+ group: "Theme"
438
+ })
439
+ )
440
+ );
441
+ }
442
+ function generateSemanticGroup() {
443
+ return {
444
+ id: "541629445ef90ad5363f9e88f52a1ccb617e6f84",
445
+ name: "Semantic",
446
+ selectedTokenSets: {
447
+ "semantic/style": TokenSetStatus.ENABLED,
448
+ "semantic/color": TokenSetStatus.ENABLED,
449
+ "primitives/globals": TokenSetStatus.SOURCE
450
+ },
451
+ $figmaCollectionId: "VariableCollectionId:34811:5976",
452
+ $figmaModeId: "34811:5",
453
+ group: "Semantic"
454
+ };
455
+ }
456
+ async function generateColorGroup(group, colors) {
457
+ return Promise.all(
458
+ Object.entries(colors[group]).map(
459
+ async ([color]) => ({
460
+ id: await createHash(`${group}-${color}`),
461
+ name: color,
462
+ selectedTokenSets: {
463
+ [`semantic/modes/${group}-color/${color}`]: TokenSetStatus.ENABLED
464
+ },
465
+ group: `${capitalize(group)} color`
466
+ })
467
+ )
468
+ );
469
+ }
470
+ function generateTypographyGroup(themes) {
471
+ return [
472
+ {
473
+ id: "368d753fcac4455f289500eaa42e70dc0a03522f",
474
+ $figmaCollectionId: "VariableCollectionId:36248:20769",
475
+ $figmaModeId: "36248:2",
476
+ name: "Primary",
477
+ selectedTokenSets: Object.fromEntries(
478
+ themes.map((theme) => [`primitives/modes/typography/primary/${theme}`, TokenSetStatus.ENABLED])
479
+ ),
480
+ group: "Typography"
481
+ },
482
+ {
483
+ id: "264b8bd1d40b364e1ea3acf09e49795ddd4c513c",
484
+ $figmaCollectionId: "VariableCollectionId:36248:20769",
485
+ $figmaModeId: "36248:3",
486
+ name: "Secondary",
487
+ selectedTokenSets: Object.fromEntries(
488
+ themes.map((theme) => [`primitives/modes/typography/secondary/${theme}`, TokenSetStatus.ENABLED])
489
+ ),
490
+ group: "Typography"
491
+ }
492
+ ];
493
+ }
494
+
495
+ // src/tokens/create/write.ts
496
+ var stringify = (data) => JSON.stringify(data, null, 2);
497
+ var writeTokens = async (options) => {
498
+ const {
499
+ outDir,
500
+ tokenSets,
501
+ theme: { name: themeName, colors },
502
+ dry
503
+ } = options;
504
+ const targetDir = path.resolve(process.cwd(), String(outDir));
505
+ const $themesPath = path.join(targetDir, "$themes.json");
506
+ const $metadataPath = path.join(targetDir, "$metadata.json");
507
+ const $designsystemetPath = path.join(targetDir, "$designsystemet.json");
508
+ let themeObjects = [];
509
+ await mkdir(targetDir, dry);
510
+ try {
511
+ const $themes2 = await readFile($themesPath);
512
+ if ($themes2) {
513
+ themeObjects = JSON.parse($themes2);
514
+ }
515
+ } catch (error) {
516
+ }
517
+ const concatThemeNames = R.pipe(
518
+ R.filter((obj) => R.toLower(obj.group || "") === "theme"),
519
+ R.map(R.prop("name")),
520
+ // New theme is added to the end of the list so we keep the same order from config and Token Studio
521
+ R.append(themeName),
522
+ R.uniq
523
+ );
524
+ const themes = concatThemeNames(themeObjects);
525
+ console.log(`
526
+ Themes: ${chalk2.blue(themes.join(", "))}`);
527
+ const $themes = await generate$Themes(["dark", "light"], themes, colors);
528
+ const $metadata = generate$Metadata(["dark", "light"], themes, colors);
529
+ const $designsystemet = generate$Designsystemet();
530
+ await writeFile($themesPath, stringify($themes), dry);
531
+ await writeFile($metadataPath, stringify($metadata), dry);
532
+ await writeFile($designsystemetPath, stringify($designsystemet), dry);
533
+ for (const [set, tokens] of tokenSets) {
534
+ const fileDir = path.join(targetDir, path.dirname(set));
535
+ await mkdir(fileDir, dry);
536
+ const filePath = path.join(targetDir, `${set}.json`);
537
+ await writeFile(filePath, stringify(tokens), dry);
538
+ }
539
+ console.log(
540
+ `Finished creating Designsystem design tokens in ${chalk2.green(outDir)} for theme ${chalk2.blue(themeName)}`
541
+ );
542
+ };
543
+ export {
544
+ stringify,
545
+ writeTokens
546
+ };
@@ -1,4 +1,4 @@
1
- import type { Theme, Tokens } from './types.js';
1
+ import type { Theme, TokenSets } from './types.js';
2
2
  export declare const cliOptions: {
3
3
  readonly outDir: "out-dir";
4
4
  readonly clean: "clean";
@@ -14,5 +14,7 @@ export declare const cliOptions: {
14
14
  readonly borderRadius: "border-radius";
15
15
  };
16
16
  };
17
- export declare const createTokens: (opts: Theme) => Tokens;
17
+ export declare const createTokens: (opts: Theme) => Promise<{
18
+ tokenSets: TokenSets;
19
+ }>;
18
20
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,EAAyB,MAAM,YAAY,CAAC;AAE/E,eAAO,MAAM,UAAU;;;;;;;;;;;;;;CAcb,CAAC;AAoEX,eAAO,MAAM,YAAY,GAAI,MAAM,KAAK,WAqBvC,CAAC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,KAAK,EAAY,SAAS,EAAE,MAAM,YAAY,CAAC;AAE7D,eAAO,MAAM,UAAU;;;;;;;;;;;;;;CAcb,CAAC;AAEX,eAAO,MAAM,YAAY,GAAU,MAAM,KAAK;;EAiC7C,CAAC"}