@digdir/designsystemet 0.1.0-next.22 → 0.1.0-next.24

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 (91) hide show
  1. package/dist/bin/designsystemet.js +41 -13
  2. package/dist/src/colors/index.js +2 -2
  3. package/dist/src/colors/{themeUtils.js → theme.js} +16 -13
  4. package/dist/src/colors/{colorUtils.js → utils.js} +20 -10
  5. package/dist/src/init/createTokensPackage.js +27 -4
  6. package/dist/src/init/generateMetadataJson.js +10 -5
  7. package/dist/src/init/generateThemesJson.js +56 -5
  8. package/dist/src/init/nextStepsMarkdown.js +2 -2
  9. package/dist/src/init/template/default-files/design-tokens/Figma/components.json +22 -0
  10. package/dist/src/init/template/default-files/design-tokens/primitives/globals.json +32 -68
  11. package/dist/src/init/template/default-files/design-tokens/primitives/size/default.json +175 -0
  12. package/dist/src/init/template/default-files/design-tokens/semantic/color.json +280 -270
  13. package/dist/src/init/template/default-files/design-tokens/semantic/style.json +307 -286
  14. package/dist/src/init/template/default-files/design-tokens/themes/theme.json +334 -0
  15. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/contrast/theme-template.json +314 -0
  16. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/global.json +376 -0
  17. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/theme-template.json +314 -0
  18. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/global.json +376 -0
  19. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/theme-template.json +314 -0
  20. package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/primary/theme-template.json +30 -0
  21. package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/secondary/theme-template.json +30 -0
  22. package/dist/src/init/template/template-files/design-tokens/themes/theme-template.json +170 -150
  23. package/dist/src/init/template/template-files/package.json +1 -1
  24. package/dist/src/tokens/{formats → build/formats}/css.js +6 -8
  25. package/dist/src/tokens/{build.js → build/index.js} +2 -2
  26. package/dist/src/tokens/create/README.md +3 -0
  27. package/dist/src/tokens/create/index.js +153 -0
  28. package/dist/src/tokens/index.js +4 -0
  29. package/dist/types/src/colors/index.d.ts +2 -2
  30. package/dist/types/src/colors/index.d.ts.map +1 -1
  31. package/dist/types/src/colors/{themeUtils.d.ts → theme.d.ts} +10 -27
  32. package/dist/types/src/colors/theme.d.ts.map +1 -0
  33. package/dist/types/src/colors/types.d.ts +3 -2
  34. package/dist/types/src/colors/types.d.ts.map +1 -1
  35. package/dist/types/src/colors/{colorUtils.d.ts → utils.d.ts} +14 -8
  36. package/dist/types/src/colors/utils.d.ts.map +1 -0
  37. package/dist/types/src/init/createTokensPackage.d.ts.map +1 -1
  38. package/dist/types/src/init/generateMetadataJson.d.ts.map +1 -1
  39. package/dist/types/src/init/generateThemesJson.d.ts.map +1 -1
  40. package/dist/types/src/tokens/build/actions.d.ts.map +1 -0
  41. package/dist/types/src/tokens/build/configs.d.ts.map +1 -0
  42. package/dist/types/src/tokens/build/formats/css.d.ts.map +1 -0
  43. package/dist/types/src/tokens/build/formats/js-tokens.d.ts.map +1 -0
  44. package/dist/types/src/tokens/{build.d.ts → build/index.d.ts} +2 -2
  45. package/dist/types/src/tokens/build/index.d.ts.map +1 -0
  46. package/dist/types/src/tokens/build/transformers.d.ts.map +1 -0
  47. package/dist/types/src/tokens/build/utils/entryfile.d.ts.map +1 -0
  48. package/dist/types/src/tokens/build/utils/noCase.d.ts.map +1 -0
  49. package/dist/types/src/tokens/build/utils/permutateThemes.d.ts.map +1 -0
  50. package/dist/types/src/tokens/build/utils/utils.d.ts.map +1 -0
  51. package/dist/types/src/tokens/create/index.d.ts +64 -0
  52. package/dist/types/src/tokens/create/index.d.ts.map +1 -0
  53. package/dist/types/src/tokens/index.d.ts +2 -0
  54. package/dist/types/src/tokens/index.d.ts.map +1 -0
  55. package/package.json +7 -3
  56. package/dist/src/init/template/default-files/design-tokens/primitives/typography/default.json +0 -86
  57. package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/theme-template.json +0 -314
  58. package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/global.json +0 -376
  59. package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/theme-template.json +0 -314
  60. package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/global.json +0 -376
  61. package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/theme-template.json +0 -314
  62. package/dist/types/src/colors/colorUtils.d.ts.map +0 -1
  63. package/dist/types/src/colors/themeUtils.d.ts.map +0 -1
  64. package/dist/types/src/tokens/actions.d.ts.map +0 -1
  65. package/dist/types/src/tokens/build.d.ts.map +0 -1
  66. package/dist/types/src/tokens/configs.d.ts.map +0 -1
  67. package/dist/types/src/tokens/formats/css.d.ts.map +0 -1
  68. package/dist/types/src/tokens/formats/js-tokens.d.ts.map +0 -1
  69. package/dist/types/src/tokens/transformers.d.ts.map +0 -1
  70. package/dist/types/src/tokens/utils/entryfile.d.ts.map +0 -1
  71. package/dist/types/src/tokens/utils/noCase.d.ts.map +0 -1
  72. package/dist/types/src/tokens/utils/permutateThemes.d.ts.map +0 -1
  73. package/dist/types/src/tokens/utils/utils.d.ts.map +0 -1
  74. /package/dist/src/init/template/template-files/design-tokens/primitives/{colors → modes/colors}/contrast/global.json +0 -0
  75. /package/dist/src/tokens/{actions.js → build/actions.js} +0 -0
  76. /package/dist/src/tokens/{configs.js → build/configs.js} +0 -0
  77. /package/dist/src/tokens/{formats → build/formats}/js-tokens.js +0 -0
  78. /package/dist/src/tokens/{transformers.js → build/transformers.js} +0 -0
  79. /package/dist/src/tokens/{utils → build/utils}/entryfile.js +0 -0
  80. /package/dist/src/tokens/{utils → build/utils}/noCase.js +0 -0
  81. /package/dist/src/tokens/{utils → build/utils}/permutateThemes.js +0 -0
  82. /package/dist/src/tokens/{utils → build/utils}/utils.js +0 -0
  83. /package/dist/types/src/tokens/{actions.d.ts → build/actions.d.ts} +0 -0
  84. /package/dist/types/src/tokens/{configs.d.ts → build/configs.d.ts} +0 -0
  85. /package/dist/types/src/tokens/{formats → build/formats}/css.d.ts +0 -0
  86. /package/dist/types/src/tokens/{formats → build/formats}/js-tokens.d.ts +0 -0
  87. /package/dist/types/src/tokens/{transformers.d.ts → build/transformers.d.ts} +0 -0
  88. /package/dist/types/src/tokens/{utils → build/utils}/entryfile.d.ts +0 -0
  89. /package/dist/types/src/tokens/{utils → build/utils}/noCase.d.ts +0 -0
  90. /package/dist/types/src/tokens/{utils → build/utils}/permutateThemes.d.ts +0 -0
  91. /package/dist/types/src/tokens/{utils → build/utils}/utils.d.ts +0 -0
@@ -1,18 +1,44 @@
1
1
  #!/usr/bin/env node
2
- import { Argument, Command, program } from "@commander-js/extra-typings";
2
+ import { Argument, createCommand, program } from "@commander-js/extra-typings";
3
3
  import chalk from "chalk";
4
- import { makeInitCommand } from "../src/init/index.js";
4
+ import { convertToHex } from "../src/colors";
5
+ import { createTokensPackage } from "../src/init/createTokensPackage.js";
5
6
  import migrations from "../src/migrations/index.js";
6
- import { run } from "../src/tokens/build.js";
7
- program.name("Designsystemet").description("CLI for working with Designsystemet");
8
- program.command("tokens").showHelpAfterError().description("run Designsystemet token builder").option("-t, --tokens [string]", `Path to ${chalk.blue("design-tokens")}`, "./design-tokens").option("-o, --out [string]", `Output directory for built ${chalk.blue("design-tokens")}`, "./dist/tokens").option("-p, --preview", "Generate preview token.ts files", false).action((opts) => {
9
- const tokens = typeof opts.tokens === "string" ? opts.tokens : "./design-tokens";
10
- const out = typeof opts.out === "string" ? opts.out : "./dist/tokens";
11
- const preview = opts.preview;
12
- console.log(`Bulding tokens in ${chalk.green(tokens)}`);
13
- return run({ tokens, out, preview });
14
- });
15
- program.command("migrate").showHelpAfterError().description("run a Designsystemet migration").addArgument(new Argument("[migration]", "Available migrations").choices(Object.keys(migrations))).option("-l --list", "List available migrations").option("-g --glob <glob>", "Glob for files upon which to apply the migration", "./**/*.(tsx|css)").action((migrationKey, opts) => {
7
+ import { buildTokens } from "../src/tokens/build/index.js";
8
+ import { createTokens } from "../src/tokens/create//index.js";
9
+ program.name("Designsystemet").description("CLI for working with Designsystemet").showHelpAfterError();
10
+ function makeTokenCommands() {
11
+ const tokenCmd = createCommand("tokens");
12
+ tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${chalk.blue("design-tokens")}`, "./design-tokens").option("-o, --out <string>", `Output directory for built ${chalk.blue("design-tokens")}`, "./dist/tokens").option("-p, --preview", "Generate preview token.ts files", false).action((opts) => {
13
+ const tokens = typeof opts.tokens === "string" ? opts.tokens : "./design-tokens";
14
+ const out = typeof opts.out === "string" ? opts.out : "./dist/tokens";
15
+ const preview = opts.preview;
16
+ console.log(`Bulding tokens in ${chalk.green(tokens)}`);
17
+ return buildTokens({ tokens, out, preview });
18
+ });
19
+ tokenCmd.command("create").description("Create Designsystemet tokens").option("-w, --write [string]", `Output directory for created ${chalk.blue("design-tokens")}`, "./design-tokens").option("-a, --accent <number>", `Accent hex color`).option("-n, --neutral <number>", `Neutral hex color`).option("-b1, --brand1 <number>", `Brand1 hex color`).option("-b2, --brand2 <number>", `Brand2 hex color`).option("-b3, --brand3 <number>", `Brand3 hex color`).option("-f, --font-family <string>", `Font family`).action(async (opts) => {
20
+ console.log(`Creating tokens with options ${chalk.green(JSON.stringify(opts))}`);
21
+ const outPath = typeof opts.write === "string" ? opts.write : "./design-tokens";
22
+ const family = typeof opts.fontFamily === "string" ? opts.fontFamily : "Inter";
23
+ const props = {
24
+ colors: {
25
+ accent: convertToHex(opts.accent),
26
+ neutral: convertToHex(opts.neutral),
27
+ brand1: convertToHex(opts.brand1),
28
+ brand2: convertToHex(opts.brand2),
29
+ brand3: convertToHex(opts.brand3)
30
+ },
31
+ typography: {
32
+ family
33
+ },
34
+ outPath
35
+ };
36
+ await createTokens(props);
37
+ });
38
+ return tokenCmd;
39
+ }
40
+ program.addCommand(makeTokenCommands());
41
+ program.command("migrate").description("run a Designsystemet migration").addArgument(new Argument("[migration]", "Available migrations").choices(Object.keys(migrations))).option("-l --list", "List available migrations").option("-g --glob <glob>", "Glob for files upon which to apply the migration", "./**/*.(tsx|css)").action((migrationKey, opts) => {
16
42
  const { glob, list } = opts;
17
43
  if (list) {
18
44
  for (const key of Object.keys(migrations)) {
@@ -30,5 +56,7 @@ program.command("migrate").showHelpAfterError().description("run a Designsysteme
30
56
  console.log("Migrate: please specify a migration name or --list");
31
57
  }
32
58
  });
33
- program.addCommand(makeInitCommand(new Command("init")));
59
+ program.command("init").description("create an initial token structure for Designsystemet").addArgument(new Argument("<targetDir>", "Target directory for the generated code")).action(async (targetDir) => {
60
+ await createTokensPackage(targetDir);
61
+ });
34
62
  await program.parseAsync(process.argv);
@@ -1,3 +1,3 @@
1
- export * from "./colorUtils";
2
- export * from "./themeUtils";
1
+ export * from "./utils";
2
+ export * from "./theme";
3
3
  export * from "./types";
@@ -1,12 +1,14 @@
1
1
  import { BackgroundColor, Color, Theme } from "@adobe/leonardo-contrast-colors";
2
2
  import { Hsluv } from "hsluv";
3
- import { getContrastFromHex, getContrastFromLightness, getLightnessFromHex } from "./colorUtils";
4
- const blueBaseColor = "#0A71C0";
5
- const greenBaseColor = "#078D19";
6
- const orangeBaseColor = "#CA5C21";
7
- const purpleBaseColor = "#663299";
8
- const redBaseColor = "#C01B1B";
9
- const yellowBaseColor = "#EABF28";
3
+ import { getContrastFromHex, getContrastFromLightness, getLightnessFromHex } from "./utils";
4
+ const baseColors = {
5
+ blue: "#0A71C0",
6
+ green: "#078D19",
7
+ orange: "#CA5C21",
8
+ purple: "#663299",
9
+ red: "#C01B1B",
10
+ yellow: "#EABF28"
11
+ };
10
12
  const generateThemeColor = (color, mode, contrastMode = "aa") => {
11
13
  const leoBackgroundColor = new BackgroundColor({
12
14
  name: "backgroundColor",
@@ -103,12 +105,12 @@ const generateThemeForColor = (color, contrastMode = "aa") => {
103
105
  };
104
106
  };
105
107
  const generateGlobalColors = ({ contrastMode = "aa" }) => {
106
- const blueTheme = generateThemeForColor(blueBaseColor, contrastMode);
107
- const greenTheme = generateThemeForColor(greenBaseColor, contrastMode);
108
- const orangeTheme = generateThemeForColor(orangeBaseColor, contrastMode);
109
- const purpleTheme = generateThemeForColor(purpleBaseColor, contrastMode);
110
- const redTheme = generateThemeForColor(redBaseColor, contrastMode);
111
- const yellowTheme = generateThemeForColor(yellowBaseColor, contrastMode);
108
+ const blueTheme = generateThemeForColor(baseColors.blue, contrastMode);
109
+ const greenTheme = generateThemeForColor(baseColors.green, contrastMode);
110
+ const orangeTheme = generateThemeForColor(baseColors.orange, contrastMode);
111
+ const purpleTheme = generateThemeForColor(baseColors.purple, contrastMode);
112
+ const redTheme = generateThemeForColor(baseColors.red, contrastMode);
113
+ const yellowTheme = generateThemeForColor(baseColors.yellow, contrastMode);
112
114
  return {
113
115
  blue: blueTheme,
114
116
  green: greenTheme,
@@ -230,6 +232,7 @@ const getCssVariable = (colorType, colorNumber) => {
230
232
  return `--ds-${colorType}-${getColorNameFromNumber(colorNumber).toLowerCase().replace(/\s/g, "-")}`;
231
233
  };
232
234
  export {
235
+ baseColors,
233
236
  calculateContrastOneColor,
234
237
  calculateContrastTwoColor,
235
238
  canTextBeUsedOnColors,
@@ -20,7 +20,7 @@ const hexToCssHsl = (hex, valuesOnly = false) => {
20
20
  let h = 0;
21
21
  let s = 0;
22
22
  let l = (max + min) / 2;
23
- if (max == min) {
23
+ if (max === min) {
24
24
  h = s = 0;
25
25
  } else {
26
26
  const d = max - min;
@@ -48,11 +48,11 @@ const hexToHSL = (H) => {
48
48
  let r = 0;
49
49
  let g = 0;
50
50
  let b = 0;
51
- if (H.length == 4) {
51
+ if (H.length === 4) {
52
52
  r = parseInt("0x" + H[1] + H[1]);
53
53
  g = parseInt("0x" + H[2] + H[2]);
54
54
  b = parseInt("0x" + H[3] + H[3]);
55
- } else if (H.length == 7) {
55
+ } else if (H.length === 7) {
56
56
  r = parseInt("0x" + H[1] + H[2]);
57
57
  g = parseInt("0x" + H[3] + H[4]);
58
58
  b = parseInt("0x" + H[5] + H[6]);
@@ -66,14 +66,14 @@ const hexToHSL = (H) => {
66
66
  const cmin = Math.min(r, g, b);
67
67
  const cmax = Math.max(r, g, b);
68
68
  const delta = cmax - cmin;
69
- if (delta == 0) h = 0;
70
- else if (cmax == r) h = (g - b) / delta % 6;
71
- else if (cmax == g) h = (b - r) / delta + 2;
69
+ if (delta === 0) h = 0;
70
+ else if (cmax === r) h = (g - b) / delta % 6;
71
+ else if (cmax === g) h = (b - r) / delta + 2;
72
72
  else h = (r - g) / delta + 4;
73
73
  h = Math.round(h * 60);
74
74
  if (h < 0) h += 360;
75
75
  l = (cmax + cmin) / 2;
76
- s = delta == 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
76
+ s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
77
77
  s = +(s * 100).toFixed(1);
78
78
  l = +(l * 100).toFixed(1);
79
79
  return [h, s, l];
@@ -124,9 +124,9 @@ const HSLToHex = (h, s, l) => {
124
124
  r = parseInt(Math.round((r + m) * 255).toString(16), 16);
125
125
  g = parseInt(Math.round((g + m) * 255).toString(16), 16);
126
126
  b = parseInt(Math.round((b + m) * 255).toString(16), 16);
127
- if (r.toString().length == 1) r = parseInt("0" + r.toString(), 10);
128
- if (g.toString().length == 1) g = parseInt("0" + g.toString(), 10);
129
- if (b.toString().length == 1) b = parseInt("0" + b.toString(), 10);
127
+ if (r.toString().length === 1) r = parseInt("0" + r.toString(), 10);
128
+ if (g.toString().length === 1) g = parseInt("0" + g.toString(), 10);
129
+ if (b.toString().length === 1) b = parseInt("0" + b.toString(), 10);
130
130
  return "#" + r + g + b;
131
131
  };
132
132
  const hexToRgb = (hex) => {
@@ -221,9 +221,19 @@ const getApcaContrastLc = (textColor, backgroundColor) => {
221
221
  const isHexColor = (hex) => {
222
222
  return typeof hex === "string" && hex.length === 6 && !Number.isNaN(Number("0x" + hex));
223
223
  };
224
+ const convertToHex = (color) => {
225
+ if (!color) {
226
+ return "#000000";
227
+ }
228
+ if (color.startsWith("#")) {
229
+ return color;
230
+ }
231
+ return chroma(color).hex();
232
+ };
224
233
  export {
225
234
  HSLToHex,
226
235
  areColorsContrasting,
236
+ convertToHex,
227
237
  getApcaContrastLc,
228
238
  getContrastFromHex,
229
239
  getContrastFromLightness,
@@ -176,20 +176,43 @@ Will now create the following:
176
176
  await fs.mkdir(path.join(TOKENS_TARGET_DIR, "themes"));
177
177
  } catch {
178
178
  }
179
+ try {
180
+ await fs.mkdir(path.join(TOKENS_TARGET_DIR, "themes"));
181
+ } catch {
182
+ }
183
+ try {
184
+ await fs.mkdir(path.join(TOKENS_TARGET_DIR, "primitives/modes/typography/primary"), { recursive: true });
185
+ await fs.mkdir(path.join(TOKENS_TARGET_DIR, "primitives/modes/typography/secondary"), { recursive: true });
186
+ } catch {
187
+ }
179
188
  for (const theme of themes.map(normalizeTokenSetName)) {
180
189
  for (const mode of modes.map(normalizeTokenSetName)) {
181
190
  await fs.cp(
182
- path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/colors/${mode}/global.json`),
183
- path.join(TOKENS_TARGET_DIR, `primitives/colors/${mode}/global.json`),
191
+ path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/colors/${mode}/global.json`),
192
+ path.join(TOKENS_TARGET_DIR, `primitives/modes/colors/${mode}/global.json`),
184
193
  { recursive: true }
185
194
  );
186
195
  const template2 = await fs.readFile(
187
- path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/colors/${mode}/theme-template.json`)
196
+ path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/colors/${mode}/theme-template.json`)
188
197
  );
189
198
  await fs.writeFile(
190
- path.join(TOKENS_TARGET_DIR, `primitives/colors/${mode}/${theme}.json`),
199
+ path.join(TOKENS_TARGET_DIR, `primitives/modes/colors/${mode}/${theme}.json`),
191
200
  template2.toString("utf-8").replaceAll("<theme>", theme)
192
201
  );
202
+ const templatePrimaryTypo = await fs.readFile(
203
+ path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/typography/primary/theme-template.json`)
204
+ );
205
+ await fs.writeFile(
206
+ path.join(TOKENS_TARGET_DIR, `primitives/modes/typography/primary/${theme}.json`),
207
+ templatePrimaryTypo.toString("utf-8").replaceAll("<theme>", theme)
208
+ );
209
+ const templateSecondaryTypo = await fs.readFile(
210
+ path.join(TOKEN_TEMPLATE_FILES_PATH, `primitives/modes/typography/secondary/theme-template.json`)
211
+ );
212
+ await fs.writeFile(
213
+ path.join(TOKENS_TARGET_DIR, `primitives/modes/typography/secondary/${theme}.json`),
214
+ templateSecondaryTypo.toString("utf-8").replaceAll("<theme>", theme)
215
+ );
193
216
  }
194
217
  const template = await fs.readFile(path.join(TOKEN_TEMPLATE_FILES_PATH, `themes/theme-template.json`));
195
218
  await fs.writeFile(
@@ -2,15 +2,20 @@ import { normalizeTokenSetName } from "./utils.js";
2
2
  function generateMetadataJson(modes, themes) {
3
3
  return {
4
4
  tokenSetOrder: [
5
- "primitives/globals",
6
- "primitives/typography/default",
5
+ "primitives/modes/globals",
6
+ "primitives/size/default",
7
+ "primitives/modes/typography/primary/theme",
8
+ "primitives/modes/typography/secondary/theme",
7
9
  ...modes.flatMap((mode) => [
8
- `primitives/colors/${normalizeTokenSetName(mode)}/global`,
9
- ...themes.map((theme) => `primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`)
10
+ `primitives/modes/colors/${normalizeTokenSetName(mode)}/global`,
11
+ ...themes.map(
12
+ (theme) => `primitives/modes/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`
13
+ )
10
14
  ]),
11
15
  ...themes.map((theme) => `themes/${normalizeTokenSetName(theme)}`),
12
16
  "semantic/color",
13
- "semantic/style"
17
+ "semantic/style",
18
+ "Figma/components"
14
19
  ]
15
20
  };
16
21
  }
@@ -2,7 +2,33 @@ import { randomUUID } from "node:crypto";
2
2
  import { TokenSetStatus } from "@tokens-studio/types";
3
3
  import { normalizeTokenSetName } from "./utils.js";
4
4
  function generateThemesJson(modes, themes) {
5
- return [...generateModesGroup(modes, themes), ...generateThemesGroup(themes), generateSemanticGroup()];
5
+ return [
6
+ ...generateSizeGroup(),
7
+ ...generateThemesGroup(themes),
8
+ ...generateTypographyGroup(themes),
9
+ ...generateModesGroup(modes, themes),
10
+ generateSemanticGroup()
11
+ ];
12
+ }
13
+ function generateSizeGroup() {
14
+ return [
15
+ {
16
+ id: randomUUID(),
17
+ name: "default",
18
+ selectedTokenSets: {
19
+ "primitives/size/default": TokenSetStatus.ENABLED
20
+ },
21
+ group: "Size"
22
+ }
23
+ // {
24
+ // id: randomUUID(),
25
+ // name: 'compact',
26
+ // selectedTokenSets: {
27
+ // 'primitives/size/compact': TokenSetStatus.ENABLED,
28
+ // },
29
+ // group: 'Size',
30
+ // },
31
+ ];
6
32
  }
7
33
  function generateModesGroup(modes, themes) {
8
34
  return modes.map(
@@ -10,10 +36,10 @@ function generateModesGroup(modes, themes) {
10
36
  id: randomUUID(),
11
37
  name: mode,
12
38
  selectedTokenSets: Object.fromEntries([
13
- [`primitives/colors/${normalizeTokenSetName(mode)}/global`, TokenSetStatus.ENABLED],
39
+ [`primitives/modes/colors/${normalizeTokenSetName(mode)}/global`, TokenSetStatus.ENABLED],
14
40
  ...themes.map(
15
41
  (theme) => [
16
- `primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`,
42
+ `primitives/modes/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`,
17
43
  TokenSetStatus.ENABLED
18
44
  ]
19
45
  )
@@ -41,12 +67,37 @@ function generateSemanticGroup() {
41
67
  selectedTokenSets: {
42
68
  "semantic/style": TokenSetStatus.ENABLED,
43
69
  "semantic/color": TokenSetStatus.ENABLED,
44
- "primitives/globals": TokenSetStatus.SOURCE,
45
- "primitives/typography/default": TokenSetStatus.SOURCE
70
+ "primitives/globals": TokenSetStatus.SOURCE
46
71
  },
47
72
  group: "Semantic"
48
73
  };
49
74
  }
75
+ function generateTypographyGroup(themes) {
76
+ return [
77
+ {
78
+ id: randomUUID(),
79
+ name: "primary",
80
+ selectedTokenSets: Object.fromEntries(
81
+ themes.map((theme) => [
82
+ `primitives/modes/typography/primary/${normalizeTokenSetName(theme)}`,
83
+ TokenSetStatus.ENABLED
84
+ ])
85
+ ),
86
+ group: "Typography"
87
+ },
88
+ {
89
+ id: randomUUID(),
90
+ name: "secondary",
91
+ selectedTokenSets: Object.fromEntries(
92
+ themes.map((theme) => [
93
+ `primitives/modes/typography/secondary/${normalizeTokenSetName(theme)}`,
94
+ TokenSetStatus.ENABLED
95
+ ])
96
+ ),
97
+ group: "Typography"
98
+ }
99
+ ];
100
+ }
50
101
  export {
51
102
  generateThemesJson as default
52
103
  };
@@ -23,8 +23,8 @@ function nextStepsMarkdown(themes, modes, tokensTargetDir, packageName) {
23
23
  1. Go to https://theme.designsystemet.no and set up a color theme
24
24
  2. Press "Kopier tema"
25
25
  3. Under "Json til Figma", copy the contents under ${modes.join(" / ")} to
26
- the corresponding file under \`${tokensTargetDir}\`:
27
- ${themeModeCombinations.map(([theme, mode]) => ` **${theme}, ${mode}**: \`primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}.json\` `).join("\n")}
26
+ the corresponding file under \`${tokensTargetDir}\`:
27
+ ${themeModeCombinations.map(([theme, mode]) => ` **${theme}, ${mode}**: \`primitives/modes/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}.json\` `).join("\n")}
28
28
  This can also be done in Tokens Studio for Figma.
29
29
  4. **IMPORTANT!** In the JSON data you copied, replace \`theme\` on line 2
30
30
  with the correct theme identifier, depending on the theme you're customizing.
@@ -0,0 +1,22 @@
1
+ {
2
+ "switch": {
3
+ "circle": {
4
+ "small": {
5
+ "$type": "sizing",
6
+ "$value": "{sizing.5} - {switch.border}"
7
+ },
8
+ "medium": {
9
+ "$type": "sizing",
10
+ "$value": "{sizing.6} - {switch.border}"
11
+ },
12
+ "large": {
13
+ "$type": "sizing",
14
+ "$value": "{sizing.7} - {switch.border}"
15
+ }
16
+ },
17
+ "border": {
18
+ "$type": "sizing",
19
+ "$value": "4"
20
+ }
21
+ }
22
+ }
@@ -1,21 +1,20 @@
1
1
  {
2
2
  "border-width": {
3
3
  "1": {
4
- "type": "borderWidth",
5
- "value": "1px"
4
+ "$type": "borderWidth",
5
+ "$value": "1px"
6
6
  },
7
7
  "2": {
8
- "type": "borderWidth",
9
- "value": "2px"
8
+ "$type": "borderWidth",
9
+ "$value": "2px"
10
10
  }
11
11
  },
12
12
  "shadow": {
13
13
  "100": {
14
- "type": "boxShadow",
15
- "value": [
14
+ "$type": "boxShadow",
15
+ "$value": [
16
16
  {
17
17
  "color": "rgba(0,0,0,0.16)",
18
- "type": "dropShadow",
19
18
  "x": "0",
20
19
  "y": "0",
21
20
  "blur": "1",
@@ -26,17 +25,15 @@
26
25
  "y": "1",
27
26
  "blur": "2",
28
27
  "spread": "0",
29
- "color": "rgba(0,0,0,0.12)",
30
- "type": "dropShadow"
28
+ "color": "rgba(0,0,0,0.12)"
31
29
  }
32
30
  ]
33
31
  },
34
32
  "200": {
35
- "type": "boxShadow",
36
- "value": [
33
+ "$type": "boxShadow",
34
+ "$value": [
37
35
  {
38
36
  "color": "rgba(0,0,0,0.15)",
39
- "type": "dropShadow",
40
37
  "x": "0",
41
38
  "y": "0",
42
39
  "blur": "1",
@@ -44,7 +41,6 @@
44
41
  },
45
42
  {
46
43
  "color": "rgba(0,0,0,0.12)",
47
- "type": "dropShadow",
48
44
  "x": "0",
49
45
  "y": "1",
50
46
  "blur": "2",
@@ -55,17 +51,15 @@
55
51
  "y": "2",
56
52
  "blur": "4",
57
53
  "spread": "0",
58
- "color": "rgba(0,0,0,0.1)",
59
- "type": "dropShadow"
54
+ "color": "rgba(0,0,0,0.1)"
60
55
  }
61
56
  ]
62
57
  },
63
58
  "300": {
64
- "type": "boxShadow",
65
- "value": [
59
+ "$type": "boxShadow",
60
+ "$value": [
66
61
  {
67
62
  "color": "rgba(0,0,0,0.14)",
68
- "type": "dropShadow",
69
63
  "x": "0",
70
64
  "y": "0",
71
65
  "blur": "1",
@@ -73,7 +67,6 @@
73
67
  },
74
68
  {
75
69
  "color": "rgba(0,0,0,0.12)",
76
- "type": "dropShadow",
77
70
  "x": "0",
78
71
  "y": "2",
79
72
  "blur": "4",
@@ -84,17 +77,15 @@
84
77
  "y": "4",
85
78
  "blur": "8",
86
79
  "spread": "0",
87
- "color": "rgba(0,0,0,0.12)",
88
- "type": "dropShadow"
80
+ "color": "rgba(0,0,0,0.12)"
89
81
  }
90
82
  ]
91
83
  },
92
84
  "400": {
93
- "type": "boxShadow",
94
- "value": [
85
+ "$type": "boxShadow",
86
+ "$value": [
95
87
  {
96
88
  "color": "rgba(0,0,0,0.13)",
97
- "type": "dropShadow",
98
89
  "x": "0",
99
90
  "y": "0",
100
91
  "blur": "1",
@@ -102,7 +93,6 @@
102
93
  },
103
94
  {
104
95
  "color": "rgba(0,0,0,0.13)",
105
- "type": "dropShadow",
106
96
  "x": "0",
107
97
  "y": "3",
108
98
  "blur": "5",
@@ -113,17 +103,15 @@
113
103
  "y": "6",
114
104
  "blur": "12",
115
105
  "spread": "0",
116
- "color": "rgba(0,0,0,0.14)",
117
- "type": "dropShadow"
106
+ "color": "rgba(0,0,0,0.14)"
118
107
  }
119
108
  ]
120
109
  },
121
110
  "500": {
122
- "type": "boxShadow",
123
- "value": [
111
+ "$type": "boxShadow",
112
+ "$value": [
124
113
  {
125
114
  "color": "rgba(0,0,0,0.12)",
126
- "type": "dropShadow",
127
115
  "x": "0",
128
116
  "y": "0",
129
117
  "blur": "1",
@@ -131,7 +119,6 @@
131
119
  },
132
120
  {
133
121
  "color": "rgba(0,0,0,0.16)",
134
- "type": "dropShadow",
135
122
  "x": "0",
136
123
  "y": "4",
137
124
  "blur": "8",
@@ -142,56 +129,33 @@
142
129
  "y": "12",
143
130
  "blur": "24",
144
131
  "spread": "0",
145
- "color": "rgba(0,0,0,0.16)",
146
- "type": "dropShadow"
132
+ "color": "rgba(0,0,0,0.16)"
147
133
  }
148
134
  ]
149
135
  }
150
136
  },
151
137
  "border-radius": {
152
- "2": {
153
- "type": "borderRadius",
154
- "value": "2"
155
- },
156
- "4": {
157
- "type": "borderRadius",
158
- "value": "4"
159
- },
160
- "8": {
161
- "type": "borderRadius",
162
- "value": "8"
163
- },
164
- "12": {
165
- "type": "borderRadius",
166
- "value": "12"
167
- },
168
- "16": {
169
- "type": "borderRadius",
170
- "value": "16"
171
- },
172
- "24": {
173
- "type": "borderRadius",
174
- "value": "24"
175
- },
176
- "32": {
177
- "type": "borderRadius",
178
- "value": "32"
179
- },
180
- "9999": {
181
- "type": "borderRadius",
182
- "value": "9999"
138
+ "base": {
139
+ "$type": "borderRadius",
140
+ "$value": "4"
183
141
  }
184
142
  },
185
143
  "opacity": {
186
144
  "30": {
187
- "type": "opacity",
188
- "value": "30%"
145
+ "$type": "opacity",
146
+ "$value": "30%"
189
147
  }
190
148
  },
191
149
  "sizing": {
192
150
  "base": {
193
- "type": "sizing",
194
- "value": "4"
151
+ "$type": "sizing",
152
+ "$value": "4"
153
+ }
154
+ },
155
+ "spacing": {
156
+ "base": {
157
+ "$type": "spacing",
158
+ "$value": "4"
195
159
  }
196
160
  }
197
161
  }