@digdir/designsystemet 1.0.3 → 1.0.5

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 (189) hide show
  1. package/dist/bin/designsystemet.js +4287 -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 +3682 -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 +37 -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 +1268 -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 +101 -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 +547 -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 +15 -0
  60. package/dist/src/tokens/format.d.ts.map +1 -0
  61. package/dist/src/tokens/format.js +3529 -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 +3542 -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/theme.d.ts +27 -0
  101. package/dist/src/tokens/process/theme.d.ts.map +1 -0
  102. package/dist/src/tokens/process/theme.js +172 -0
  103. package/dist/src/tokens/process/transformers.d.ts.map +1 -0
  104. package/dist/src/tokens/{build → process}/transformers.js +29 -6
  105. package/dist/src/tokens/{build → process}/utils/getMultidimensionalThemes.d.ts +3 -3
  106. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
  107. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +922 -0
  108. package/dist/src/tokens/template/design-tokens/primitives/globals.js +5 -0
  109. package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +5 -0
  110. package/dist/src/tokens/template/design-tokens/primitives/modes/size/large.js +5 -0
  111. package/dist/src/tokens/template/design-tokens/primitives/modes/size/medium.js +5 -0
  112. package/dist/src/tokens/template/design-tokens/primitives/modes/size/small.js +5 -0
  113. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/large.js +5 -0
  114. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/medium.js +5 -0
  115. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/small.js +5 -0
  116. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/typography.template.js +5 -0
  117. package/dist/src/tokens/template/design-tokens/semantic/color.base.template.js +5 -0
  118. package/dist/src/tokens/template/design-tokens/semantic/color.template.js +5 -0
  119. package/dist/src/tokens/template/design-tokens/semantic/modes/color.template.js +5 -0
  120. package/dist/src/tokens/template/design-tokens/semantic/style.js +5 -0
  121. package/dist/src/tokens/template/design-tokens/themes/theme.base.template.js +5 -0
  122. package/dist/src/tokens/template/design-tokens/themes/theme.template.js +5 -0
  123. package/dist/src/tokens/types.d.ts +58 -38
  124. package/dist/src/tokens/types.d.ts.map +1 -1
  125. package/dist/src/tokens/types.js +8 -0
  126. package/dist/src/tokens/utils.d.ts +30 -5
  127. package/dist/src/tokens/utils.d.ts.map +1 -1
  128. package/dist/src/tokens/utils.js +36 -50
  129. package/dist/src/utils.d.ts +18 -0
  130. package/dist/src/utils.d.ts.map +1 -0
  131. package/dist/src/utils.js +63 -0
  132. package/dist/typography.template-4N5YLH7F.json +22 -0
  133. package/package.json +22 -20
  134. package/dist/bin/config.d.ts.map +0 -1
  135. package/dist/bin/config.js +0 -71
  136. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
  137. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
  138. package/dist/src/migrations/codemods/jsx/classname-prefix.js +0 -64
  139. package/dist/src/migrations/codemods/jsx/run.d.ts +0 -7
  140. package/dist/src/migrations/codemods/jsx/run.d.ts.map +0 -1
  141. package/dist/src/migrations/codemods/jsx/run.js +0 -22
  142. package/dist/src/migrations/react-beta-to-v1.d.ts +0 -3
  143. package/dist/src/migrations/react-beta-to-v1.d.ts.map +0 -1
  144. package/dist/src/migrations/react-beta-to-v1.js +0 -5
  145. package/dist/src/scripts/copy-internal-tokens.d.ts +0 -2
  146. package/dist/src/scripts/copy-internal-tokens.d.ts.map +0 -1
  147. package/dist/src/scripts/copy-internal-tokens.js +0 -28
  148. package/dist/src/tokens/build/configs.d.ts.map +0 -1
  149. package/dist/src/tokens/build/configs.js +0 -280
  150. package/dist/src/tokens/build/formats/css.d.ts +0 -53
  151. package/dist/src/tokens/build/formats/css.d.ts.map +0 -1
  152. package/dist/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
  153. package/dist/src/tokens/build/formats/js-tokens.js +0 -48
  154. package/dist/src/tokens/build/transformers.d.ts.map +0 -1
  155. package/dist/src/tokens/build/types.d.ts +0 -48
  156. package/dist/src/tokens/build/types.d.ts.map +0 -1
  157. package/dist/src/tokens/build/types.js +0 -7
  158. package/dist/src/tokens/build/utils/entryfile.d.ts +0 -12
  159. package/dist/src/tokens/build/utils/entryfile.d.ts.map +0 -1
  160. package/dist/src/tokens/build/utils/entryfile.js +0 -67
  161. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +0 -1
  162. package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +0 -112
  163. package/dist/src/tokens/design-tokens/template/$metadata.json +0 -25
  164. package/dist/src/tokens/design-tokens/template/$themes.json +0 -1498
  165. package/dist/src/tokens/template.d.ts.map +0 -1
  166. package/dist/src/tokens/template.js +0 -99
  167. package/dist/src/tokens/write/generate$metadata.d.ts +0 -9
  168. package/dist/src/tokens/write/generate$metadata.d.ts.map +0 -1
  169. package/dist/src/tokens/write/generate$themes.d.ts +0 -12
  170. package/dist/src/tokens/write/generate$themes.d.ts.map +0 -1
  171. package/dist/src/tokens/write/generate$themes.js +0 -161
  172. package/dist/src/tokens/write.d.ts.map +0 -1
  173. package/dist/src/tokens/write.js +0 -177
  174. /package/dist/{src/tokens/design-tokens/template/semantic/color-base-file.json → color.base.template-M7BHS4OV.json} +0 -0
  175. /package/dist/{src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json → color.template-LMPUQ72A.json} +0 -0
  176. /package/dist/{src/tokens/design-tokens/template/semantic/semantic-color-template.json → color.template-XQNSHLTU.json} +0 -0
  177. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/global.json → global-XVXVBKM6.json} +0 -0
  178. /package/dist/{src/tokens/design-tokens/default/primitives/globals.json → globals-76VAFMDF.json} +0 -0
  179. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/large.json → large-CIIHO7AY.json} +0 -0
  180. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/large.json → large-UUOZ6DYI.json} +0 -0
  181. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/medium.json → medium-OQ7S7P4P.json} +0 -0
  182. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json → medium-VSB2S4X3.json} +0 -0
  183. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/small.json → small-AEXJ6U7Z.json} +0 -0
  184. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/small.json → small-ZY4KOJWX.json} +0 -0
  185. /package/dist/src/tokens/{build → process}/formats/js-tokens.d.ts +0 -0
  186. /package/dist/src/tokens/{build → process}/transformers.d.ts +0 -0
  187. /package/dist/{src/tokens/design-tokens/default/semantic/style.json → style-FP5XVCUD.json} +0 -0
  188. /package/dist/{src/tokens/design-tokens/template/themes/theme-base-file.json → theme.base.template-Y4RMFBQY.json} +0 -0
  189. /package/dist/{src/tokens/design-tokens/template/themes/theme-color-template.json → theme.template-CTQRNOMO.json} +0 -0
@@ -1 +0,0 @@
1
- {"version":3,"file":"template.d.ts","sourceRoot":"","sources":["../../../src/tokens/template.ts"],"names":[],"mappings":"AA2BA,eAAO,MAAM,eAAe,qBAyG3B,CAAC"}
@@ -1,99 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import * as R from "ramda";
4
- import originalColorJson from "../../../../design-tokens/semantic/color.json" with { type: "json" };
5
- import originalColorCategoryJson from "../../../../design-tokens/semantic/modes/main-color/accent.json" with { type: "json" };
6
- import originalThemeJson from "../../../../design-tokens/themes/digdir.json" with { type: "json" };
7
- import { stringify } from "./write.js";
8
- const DIRNAME = import.meta.dirname || __dirname;
9
- const SOURCE_FILES_PATH = path.join(DIRNAME, "../../../../design-tokens");
10
- const DEFAULT_FILES_PATH = path.join(DIRNAME, "./design-tokens/default");
11
- const TEMPLATE_FILES_PATH = path.join(DIRNAME, "./design-tokens/template");
12
- const argsFromToPaths = (path_) => [
13
- path.join(SOURCE_FILES_PATH, path_),
14
- path.join(DEFAULT_FILES_PATH, path_)
15
- ];
16
- const options = { recursive: true };
17
- const endsWithOneOf = (suffixes, str) => R.any((suffix) => R.endsWith(suffix, str), suffixes);
18
- const updateTemplates = async () => {
19
- await fs.cp(...argsFromToPaths("primitives/globals.json"), options);
20
- await fs.cp(...argsFromToPaths("primitives/modes/size"), options);
21
- await fs.cp(...argsFromToPaths("primitives/modes/typography/size"), options);
22
- await fs.cp(...argsFromToPaths("semantic/style.json"), options);
23
- const categoryColorTemplate = originalColorCategoryJson.color.main;
24
- const categoryDir = path.join(TEMPLATE_FILES_PATH, "semantic/modes/category-color");
25
- await fs.mkdir(categoryDir, options);
26
- await fs.writeFile(
27
- path.join(categoryDir, "category-color-template.json"),
28
- JSON.stringify(categoryColorTemplate, null, 2).replaceAll("color.accent", "color.<color>")
29
- );
30
- const colorBaseFile = {
31
- ...originalColorJson,
32
- color: R.omit(["accent", "neutral", "brand1", "brand2", "brand3"], originalColorJson.color)
33
- };
34
- await fs.writeFile(
35
- path.join(TEMPLATE_FILES_PATH, `semantic/color-base-file.json`),
36
- JSON.stringify(colorBaseFile, null, 2).replaceAll("color.accent", "color.<accent-color>")
37
- );
38
- const semanticColorTemplate = originalColorJson.color.accent;
39
- await fs.writeFile(
40
- path.join(TEMPLATE_FILES_PATH, `semantic/semantic-color-template.json`),
41
- JSON.stringify(semanticColorTemplate, null, 2).replaceAll("color.accent", "color.<color>")
42
- );
43
- const themeBaseFile = {
44
- color: {},
45
- ...R.omit(["color"], originalThemeJson)
46
- };
47
- await fs.mkdir(path.join(TEMPLATE_FILES_PATH, "themes"), options);
48
- await fs.writeFile(
49
- path.join(TEMPLATE_FILES_PATH, `themes/theme-base-file.json`),
50
- JSON.stringify(themeBaseFile, null, 2).replaceAll("digdir", "<theme>")
51
- );
52
- const themeColorTemplate = originalThemeJson.color.accent;
53
- await fs.writeFile(
54
- path.join(TEMPLATE_FILES_PATH, `themes/theme-color-template.json`),
55
- JSON.stringify(themeColorTemplate, null, 2).replaceAll("digdir.accent", "<theme>.<color>")
56
- );
57
- const themesFile = await fs.readFile(path.join(SOURCE_FILES_PATH, "$themes.json"), "utf-8");
58
- const themesTemplate = JSON.parse(themesFile).filter((themeobj) => {
59
- if (R.toLower(themeobj.name) === "compact" && R.toLower(themeobj.group || "") === "size") {
60
- return false;
61
- }
62
- if (R.toLower(themeobj.name) !== "digdir" && R.toLower(themeobj.group || "") === "theme") {
63
- return false;
64
- }
65
- return true;
66
- }).map((themeobj) => {
67
- if (R.toLower(themeobj.name) === "digdir") {
68
- return {
69
- ...themeobj,
70
- name: "<theme>",
71
- selectedTokenSets: {
72
- "themes/<theme>": "enabled"
73
- }
74
- };
75
- }
76
- return themeobj;
77
- });
78
- await fs.writeFile(path.join(TEMPLATE_FILES_PATH, `$themes.json`), stringify(themesTemplate));
79
- const metadataFile = await fs.readFile(path.join(SOURCE_FILES_PATH, "$metadata.json"), "utf-8");
80
- const tokenSetOrderTemplate = JSON.parse(metadataFile).tokenSetOrder.filter((tokenSet) => {
81
- if (endsWithOneOf(["altinn", "portal", "uutilsynet"], tokenSet)) {
82
- return false;
83
- }
84
- return true;
85
- }).map((tokenSet) => {
86
- if (endsWithOneOf(["digdir"], tokenSet)) {
87
- return tokenSet.replace("/digdir", "/<theme>");
88
- }
89
- return tokenSet;
90
- });
91
- await fs.writeFile(
92
- path.join(TEMPLATE_FILES_PATH, `$metadata.json`),
93
- stringify({ tokenSetOrder: tokenSetOrderTemplate })
94
- );
95
- };
96
- updateTemplates();
97
- export {
98
- updateTemplates
99
- };
@@ -1,9 +0,0 @@
1
- import type { ColorScheme } from '../../colors/types.js';
2
- import type { Colors } from '../types.js';
3
- type ColorSchemes = Array<ColorScheme>;
4
- type Metadata = {
5
- tokenSetOrder: string[];
6
- };
7
- export declare function generateMetadataJson(schemes: ColorSchemes, themes: string[], colors: Colors): Metadata;
8
- export {};
9
- //# sourceMappingURL=generate$metadata.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate$metadata.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAE1C,KAAK,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAEvC,KAAK,QAAQ,GAAG;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,QAAQ,CAwBtG"}
@@ -1,12 +0,0 @@
1
- import { type ThemeObject } from '@tokens-studio/types';
2
- import type { ColorScheme } from '../../colors/types.js';
3
- import type { Colors } from '../types.js';
4
- type ColorSchemes = Array<ColorScheme>;
5
- type ThemeObject_ = ThemeObject & {
6
- $figmaCollectionId?: string;
7
- $figmaModeId?: string;
8
- $figmaVariableReferences?: Record<string, string>;
9
- };
10
- export declare function generateThemesJson(colorSchemes: ColorSchemes, themes: string[], colors: Colors): ThemeObject_[];
11
- export {};
12
- //# sourceMappingURL=generate$themes.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"generate$themes.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write/generate$themes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAExE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAM1C,KAAK,YAAY,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC;AAEvC,KAAK,YAAY,GAAG,WAAW,GAAG;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,wBAAwB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CACnD,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,YAAY,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,GAAG,YAAY,EAAE,CAU/G"}
@@ -1,161 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { TokenSetStatus } from "@tokens-studio/types";
3
- const capitalize = (word) => word.charAt(0).toUpperCase() + word.slice(1);
4
- const createHash = (text) => crypto.hash("sha1", text);
5
- function generateThemesJson(colorSchemes, themes, colors) {
6
- return [
7
- ...generateSizeGroup(),
8
- ...generateThemesGroup(themes),
9
- ...generateTypographyGroup(themes),
10
- ...generateColorSchemesGroup(colorSchemes, themes),
11
- generateSemanticGroup(),
12
- ...generateColorGroup("main", colors),
13
- ...generateColorGroup("support", colors)
14
- ];
15
- }
16
- function generateSizeGroup() {
17
- return [
18
- {
19
- id: "8b2c8cc86611a34b135cb22948666779361fd729",
20
- name: "medium",
21
- $figmaStyleReferences: {},
22
- selectedTokenSets: {
23
- "primitives/modes/size/medium": TokenSetStatus.SOURCE,
24
- "primitives/modes/size/global": TokenSetStatus.ENABLED,
25
- "primitives/modes/typography/size/medium": TokenSetStatus.ENABLED
26
- },
27
- $figmaCollectionId: "VariableCollectionId:36248:20757",
28
- $figmaModeId: "41630:1",
29
- group: "Size"
30
- },
31
- {
32
- id: "d49b9eebeb48a4f165a74b7261733d0a73370f0e",
33
- name: "large",
34
- $figmaStyleReferences: {},
35
- selectedTokenSets: {
36
- "primitives/modes/size/large": TokenSetStatus.SOURCE,
37
- "primitives/modes/size/global": TokenSetStatus.ENABLED,
38
- "primitives/modes/typography/size/large": TokenSetStatus.ENABLED
39
- },
40
- $figmaCollectionId: "VariableCollectionId:36248:20757",
41
- $figmaModeId: "41630:2",
42
- group: "Size"
43
- },
44
- {
45
- id: "fb11567729c298ca37c9da4e3a27716a23480824",
46
- name: "small",
47
- $figmaStyleReferences: {},
48
- selectedTokenSets: {
49
- "primitives/modes/size/small": TokenSetStatus.SOURCE,
50
- "primitives/modes/size/global": TokenSetStatus.ENABLED,
51
- "primitives/modes/typography/size/small": TokenSetStatus.ENABLED
52
- },
53
- $figmaCollectionId: "VariableCollectionId:36248:20757",
54
- $figmaModeId: "41630:3",
55
- group: "Size"
56
- }
57
- ];
58
- }
59
- const colorSchemeDefaults = {
60
- light: {
61
- name: "Light",
62
- selectedTokenSets: {},
63
- id: "0daa3ca0b427b9349da7e7dc00101b5668972926",
64
- $figmaCollectionId: "VariableCollectionId:34811:5472",
65
- $figmaModeId: "34811:0"
66
- },
67
- dark: {
68
- name: "Dark",
69
- selectedTokenSets: {},
70
- id: "9ebd8aed52afbffc17e2666e8b4653a53498b257",
71
- $figmaCollectionId: "VariableCollectionId:34811:5472",
72
- $figmaModeId: "34811:1"
73
- },
74
- contrast: {
75
- name: "Contrast",
76
- selectedTokenSets: {},
77
- id: "9ebd8aed52afbffc17e2666e8b4653a53498b123",
78
- $figmaCollectionId: "VariableCollectionId:34811:5472",
79
- $figmaModeId: "34811:2"
80
- }
81
- };
82
- function generateColorSchemesGroup(colorSchemes, themes) {
83
- return colorSchemes.map(
84
- (scheme) => ({
85
- ...colorSchemeDefaults[scheme],
86
- selectedTokenSets: Object.fromEntries([
87
- [`primitives/modes/color-scheme/${scheme}/global`, TokenSetStatus.ENABLED],
88
- ...themes.map((theme) => [`primitives/modes/color-scheme/${scheme}/${theme}`, TokenSetStatus.ENABLED])
89
- ]),
90
- group: "Color scheme"
91
- })
92
- );
93
- }
94
- function generateThemesGroup(themes) {
95
- return themes.map(
96
- (theme, index) => ({
97
- id: createHash(theme),
98
- $figmaCollectionId: "VariableCollectionId:36528:61712",
99
- $figmaModeId: `40960:${index + 6}`,
100
- // Start on 6 in Token Studio and Community file for some reason
101
- name: theme,
102
- selectedTokenSets: {
103
- [`themes/${theme}`]: TokenSetStatus.ENABLED
104
- },
105
- group: "Theme"
106
- })
107
- );
108
- }
109
- function generateSemanticGroup() {
110
- return {
111
- id: "541629445ef90ad5363f9e88f52a1ccb617e6f84",
112
- name: "Semantic",
113
- selectedTokenSets: {
114
- "semantic/style": TokenSetStatus.ENABLED,
115
- "semantic/color": TokenSetStatus.ENABLED,
116
- "primitives/globals": TokenSetStatus.SOURCE
117
- },
118
- $figmaCollectionId: "VariableCollectionId:34811:5976",
119
- $figmaModeId: "34811:5",
120
- group: "Semantic"
121
- };
122
- }
123
- function generateColorGroup(group, colors) {
124
- return Object.entries(colors[group]).map(
125
- ([color]) => ({
126
- id: createHash(`${group}-${color}`),
127
- name: color,
128
- selectedTokenSets: {
129
- [`semantic/modes/${group}-color/${color}`]: TokenSetStatus.ENABLED
130
- },
131
- group: `${capitalize(group)} color`
132
- })
133
- );
134
- }
135
- function generateTypographyGroup(themes) {
136
- return [
137
- {
138
- id: "368d753fcac4455f289500eaa42e70dc0a03522f",
139
- $figmaCollectionId: "VariableCollectionId:36248:20769",
140
- $figmaModeId: "36248:2",
141
- name: "Primary",
142
- selectedTokenSets: Object.fromEntries(
143
- themes.map((theme) => [`primitives/modes/typography/primary/${theme}`, TokenSetStatus.ENABLED])
144
- ),
145
- group: "Typography"
146
- },
147
- {
148
- id: "264b8bd1d40b364e1ea3acf09e49795ddd4c513c",
149
- $figmaCollectionId: "VariableCollectionId:36248:20769",
150
- $figmaModeId: "36248:3",
151
- name: "Secondary",
152
- selectedTokenSets: Object.fromEntries(
153
- themes.map((theme) => [`primitives/modes/typography/secondary/${theme}`, TokenSetStatus.ENABLED])
154
- ),
155
- group: "Typography"
156
- }
157
- ];
158
- }
159
- export {
160
- generateThemesJson
161
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../src/tokens/write.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAoB,KAAK,EAAE,MAAM,EAA8B,MAAM,YAAY,CAAC;AAS9F,eAAO,MAAM,SAAS,GAAI,MAAM,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,KAAK,CAAC;IACb,wCAAwC;IACxC,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF,eAAO,MAAM,WAAW,GAAU,SAAS,kBAAkB,kBA6K5D,CAAC"}
@@ -1,177 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import chalk from "chalk";
4
- import * as R from "ramda";
5
- import semanticColorBaseFile from "./design-tokens/template/semantic/color-base-file.json" with { type: "json" };
6
- import customColorTemplate from "./design-tokens/template/semantic/modes/category-color/category-color-template.json" with { type: "json" };
7
- import semanticColorTemplate from "./design-tokens/template/semantic/semantic-color-template.json" with { type: "json" };
8
- import themeBaseFile from "./design-tokens/template/themes/theme-base-file.json" with { type: "json" };
9
- import themeColorTemplate from "./design-tokens/template/themes/theme-color-template.json" with { type: "json" };
10
- import { cp, mkdir, writeFile } from "./utils.js";
11
- import { generateMetadataJson } from "./write/generate$metadata.js";
12
- import { generateThemesJson } from "./write/generate$themes.js";
13
- const DIRNAME = import.meta.dirname || __dirname;
14
- const DEFAULT_FILES_PATH = path.join(DIRNAME, "./design-tokens/default");
15
- const TEMPLATE_FILES_PATH = path.join(DIRNAME, "./design-tokens/template/");
16
- const stringify = (data) => JSON.stringify(data, null, 2);
17
- const generateColorSchemeFile = (scheme, name, tokens, outPath) => {
18
- const path2 = `${outPath}/primitives/modes/color-scheme/${scheme}`;
19
- return {
20
- data: stringify(tokens),
21
- path: path2,
22
- filePath: `${path2}/${name}.json`
23
- };
24
- };
25
- const generateTypographyFile = (folder, name, tokens, outPath) => {
26
- const path2 = `${outPath}/primitives/modes/typography/${folder}`;
27
- return {
28
- data: stringify(tokens),
29
- path: path2,
30
- filePath: `${path2}/${name}.json`
31
- };
32
- };
33
- const writeTokens = async (options) => {
34
- const {
35
- outDir,
36
- tokens,
37
- theme: { name: themeName, colors, borderRadius },
38
- dry
39
- } = options;
40
- const targetDir = path.resolve(process.cwd(), String(outDir));
41
- const $themesPath = path.join(targetDir, "$themes.json");
42
- const $metadataPath = path.join(targetDir, "$metadata.json");
43
- let themes = [themeName];
44
- await mkdir(targetDir, dry);
45
- try {
46
- const $themes = await fs.readFile($themesPath, "utf-8");
47
- const themeObjects = JSON.parse($themes) || [];
48
- themes = R.pipe(
49
- R.filter((obj) => R.toLower(obj.group || "") === "theme"),
50
- R.map(R.prop("name")),
51
- R.append(themeName),
52
- R.uniq
53
- )(themeObjects);
54
- } catch (error) {
55
- }
56
- console.log(`Themes: ${chalk.blue(themes.join(", "))}`);
57
- const $theme = generateThemesJson(["dark", "light"], themes, colors);
58
- const $metadata = generateMetadataJson(["dark", "light"], themes, colors);
59
- await writeFile($themesPath, stringify($theme), dry);
60
- await writeFile($metadataPath, stringify($metadata), dry);
61
- await cp(DEFAULT_FILES_PATH, targetDir, dry);
62
- const mainColorNames = Object.keys(colors.main);
63
- const supportColorNames = Object.keys(colors.support);
64
- const customColors = [...mainColorNames, "neutral", ...supportColorNames];
65
- const defaultAccentColor = mainColorNames[0];
66
- for (const [colorCategory, colorNames] of [
67
- ["main", mainColorNames],
68
- ["support", supportColorNames]
69
- ]) {
70
- const colorCategoryPath = path.join(targetDir, "semantic", "modes", `${colorCategory}-color`);
71
- await mkdir(colorCategoryPath, dry);
72
- for (const colorName of colorNames) {
73
- const customColorFile = {
74
- color: {
75
- [colorCategory]: customColorTemplate
76
- }
77
- };
78
- await writeFile(
79
- path.join(colorCategoryPath, `${colorName}.json`),
80
- JSON.stringify(
81
- customColorFile,
82
- (key, value) => {
83
- if (key === "$value") {
84
- return value.replace("<color>", colorName);
85
- }
86
- return value;
87
- },
88
- 2
89
- ),
90
- dry
91
- );
92
- }
93
- }
94
- const semanticColorTokens = customColors.map(
95
- (colorName) => [
96
- colorName,
97
- R.map((x) => ({ ...x, $value: x.$value.replace("<color>", colorName) }), semanticColorTemplate)
98
- ]
99
- );
100
- const semanticColors = {
101
- ...semanticColorBaseFile,
102
- color: {
103
- ...Object.fromEntries(semanticColorTokens),
104
- ...semanticColorBaseFile.color
105
- }
106
- };
107
- await writeFile(
108
- path.join(targetDir, `semantic/color.json`),
109
- JSON.stringify(
110
- semanticColors,
111
- (key, value) => {
112
- if (key === "$value") {
113
- return value.replace("<accent-color>", defaultAccentColor);
114
- }
115
- return value;
116
- },
117
- 2
118
- ),
119
- dry
120
- );
121
- await mkdir(path.join(targetDir, "themes"), dry);
122
- const themeColorTokens = Object.fromEntries(
123
- customColors.map(
124
- (colorName) => [
125
- colorName,
126
- R.map((x) => ({ ...x, $value: x.$value.replace("<color>", colorName) }), themeColorTemplate)
127
- ]
128
- )
129
- );
130
- const { color: themeBaseFileColor, ...remainingThemeFile } = themeBaseFile;
131
- const themeFile = {
132
- color: {
133
- ...themeColorTokens,
134
- ...themeBaseFileColor
135
- },
136
- ...remainingThemeFile
137
- };
138
- const baseBorderRadius = R.lensPath(["border-radius", "base", "$value"]);
139
- const updatedThemeFile = R.set(baseBorderRadius, String(borderRadius), themeFile);
140
- await writeFile(
141
- path.join(targetDir, `themes/${themeName}.json`),
142
- JSON.stringify(
143
- updatedThemeFile,
144
- (key, value) => {
145
- if (key === "$value") {
146
- return value.replace("<theme>", themeName);
147
- }
148
- return value;
149
- },
150
- 2
151
- ),
152
- dry
153
- );
154
- const files = [
155
- generateColorSchemeFile("light", themeName, tokens.colors.light[themeName], targetDir),
156
- generateColorSchemeFile("light", "global", tokens.colors.light.global, targetDir),
157
- generateColorSchemeFile("dark", themeName, tokens.colors.dark[themeName], targetDir),
158
- generateColorSchemeFile("dark", "global", tokens.colors.dark.global, targetDir),
159
- // generateColorSchemeFile('contrast', themeName, tokens.colors.contrast[themeName], targetDir),
160
- // generateColorSchemeFile('contrast', 'global', tokens.colors.contrast.global, targetDir),
161
- generateTypographyFile("primary", themeName, tokens.typography.primary, targetDir),
162
- generateTypographyFile("secondary", themeName, tokens.typography.primary, targetDir)
163
- ];
164
- for (const file of files) {
165
- const dirPath = path.resolve(file.path);
166
- const filePath = path.resolve(file.filePath);
167
- await mkdir(dirPath, dry);
168
- await writeFile(filePath, file.data, dry);
169
- }
170
- console.log(
171
- `Finished creating Designsystem design tokens in ${chalk.green(outDir)} for theme ${chalk.blue(themeName)}`
172
- );
173
- };
174
- export {
175
- stringify,
176
- writeTokens
177
- };