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

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 (79) hide show
  1. package/dist/bin/designsystemet.js +3 -3
  2. package/dist/src/colors/colorUtils.js +33 -21
  3. package/dist/src/colors/themeUtils.js +2 -1
  4. package/dist/src/init/createTokensPackage.js +3 -3
  5. package/dist/src/init/generateMetadataJson.js +1 -3
  6. package/dist/src/init/generateThemesJson.js +2 -9
  7. package/dist/src/migrations/codemods/css/plugins.js +15 -16
  8. package/dist/src/migrations/codemods/css/run.js +2 -2
  9. package/dist/src/migrations/codemods/jsx/classname-prefix.js +8 -7
  10. package/dist/src/migrations/codemods/jsx/run.js +1 -1
  11. package/dist/src/tokens/actions.js +4 -4
  12. package/dist/src/tokens/build.js +30 -19
  13. package/dist/src/tokens/configs.js +24 -20
  14. package/dist/src/tokens/formats/css.js +40 -27
  15. package/dist/src/tokens/formats/js-tokens.js +9 -5
  16. package/dist/src/tokens/transformers.js +7 -3
  17. package/dist/src/tokens/utils/entryfile.js +31 -0
  18. package/dist/src/tokens/utils/noCase.js +1 -5
  19. package/dist/src/tokens/utils/permutateThemes.js +5 -4
  20. package/dist/src/tokens/utils/utils.js +11 -0
  21. package/dist/types/bin/designsystemet.d.ts +3 -0
  22. package/dist/types/bin/designsystemet.d.ts.map +1 -0
  23. package/dist/types/src/colors/colorUtils.d.ts +126 -0
  24. package/dist/types/src/colors/colorUtils.d.ts.map +1 -0
  25. package/dist/types/src/colors/index.d.ts +4 -0
  26. package/dist/types/src/colors/index.d.ts.map +1 -0
  27. package/dist/types/src/colors/themeUtils.d.ts +102 -0
  28. package/dist/types/src/colors/themeUtils.d.ts.map +1 -0
  29. package/dist/types/src/colors/types.d.ts +16 -0
  30. package/dist/types/src/colors/types.d.ts.map +1 -0
  31. package/dist/types/src/init/createTokensPackage.d.ts +5 -0
  32. package/dist/types/src/init/createTokensPackage.d.ts.map +1 -0
  33. package/dist/types/src/init/generateMetadataJson.d.ts +6 -0
  34. package/dist/types/src/init/generateMetadataJson.d.ts.map +1 -0
  35. package/dist/types/src/init/generateThemesJson.d.ts +3 -0
  36. package/dist/types/src/init/generateThemesJson.d.ts.map +1 -0
  37. package/dist/types/src/init/index.d.ts +3 -0
  38. package/dist/types/src/init/index.d.ts.map +1 -0
  39. package/dist/types/src/init/nextStepsMarkdown.d.ts +3 -0
  40. package/dist/types/src/init/nextStepsMarkdown.d.ts.map +1 -0
  41. package/dist/types/src/init/template/prettier.config.d.mts +9 -0
  42. package/dist/types/src/init/template/prettier.config.d.mts.map +1 -0
  43. package/dist/types/src/init/utils.d.ts +4 -0
  44. package/dist/types/src/init/utils.d.ts.map +1 -0
  45. package/dist/types/src/migrations/beta-to-v1.d.ts +3 -0
  46. package/dist/types/src/migrations/beta-to-v1.d.ts.map +1 -0
  47. package/dist/types/src/migrations/codemods/css/plugins.d.ts +6 -0
  48. package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +1 -0
  49. package/dist/types/src/migrations/codemods/css/run.d.ts +8 -0
  50. package/dist/types/src/migrations/codemods/css/run.d.ts.map +1 -0
  51. package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts +10 -0
  52. package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +1 -0
  53. package/dist/types/src/migrations/codemods/jsx/run.d.ts +7 -0
  54. package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +1 -0
  55. package/dist/types/src/migrations/index.d.ts +6 -0
  56. package/dist/types/src/migrations/index.d.ts.map +1 -0
  57. package/dist/types/src/migrations/react-beta-to-v1.d.ts +3 -0
  58. package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +1 -0
  59. package/dist/types/src/tokens/actions.d.ts +6 -0
  60. package/dist/types/src/tokens/actions.d.ts.map +1 -0
  61. package/dist/types/src/tokens/build.d.ts +11 -0
  62. package/dist/types/src/tokens/build.d.ts.map +1 -0
  63. package/dist/types/src/tokens/configs.d.ts +31 -0
  64. package/dist/types/src/tokens/configs.d.ts.map +1 -0
  65. package/dist/types/src/tokens/formats/css.d.ts +5 -0
  66. package/dist/types/src/tokens/formats/css.d.ts.map +1 -0
  67. package/dist/types/src/tokens/formats/js-tokens.d.ts +6 -0
  68. package/dist/types/src/tokens/formats/js-tokens.d.ts.map +1 -0
  69. package/dist/types/src/tokens/transformers.d.ts +5 -0
  70. package/dist/types/src/tokens/transformers.d.ts.map +1 -0
  71. package/dist/types/src/tokens/utils/entryfile.d.ts +11 -0
  72. package/dist/types/src/tokens/utils/entryfile.d.ts.map +1 -0
  73. package/dist/types/src/tokens/utils/noCase.d.ts +11 -0
  74. package/dist/types/src/tokens/utils/noCase.d.ts.map +1 -0
  75. package/dist/types/src/tokens/utils/permutateThemes.d.ts +17 -0
  76. package/dist/types/src/tokens/utils/permutateThemes.d.ts.map +1 -0
  77. package/dist/types/src/tokens/utils/utils.d.ts +25 -0
  78. package/dist/types/src/tokens/utils/utils.d.ts.map +1 -0
  79. package/package.json +26 -30
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env node
2
2
  import { Argument, Command, program } from "@commander-js/extra-typings";
3
3
  import chalk from "chalk";
4
+ import { makeInitCommand } from "../src/init/index.js";
4
5
  import migrations from "../src/migrations/index.js";
5
6
  import { run } from "../src/tokens/build.js";
6
- import { makeInitCommand } from "../src/init/index.js";
7
7
  program.name("Designsystemet").description("CLI for working with Designsystemet");
8
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
9
  const tokens = typeof opts.tokens === "string" ? opts.tokens : "./design-tokens";
@@ -15,9 +15,9 @@ program.command("tokens").showHelpAfterError().description("run Designsystemet t
15
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) => {
16
16
  const { glob, list } = opts;
17
17
  if (list) {
18
- Object.keys(migrations).forEach((key) => {
18
+ for (const key of Object.keys(migrations)) {
19
19
  console.log(key);
20
- });
20
+ }
21
21
  } else if (migrationKey) {
22
22
  const migration = migrations[migrationKey];
23
23
  if (!migration) {
@@ -1,6 +1,6 @@
1
- import { Hsluv } from "hsluv";
2
- import chroma from "chroma-js";
3
1
  import { APCAcontrast, sRGBtoY } from "apca-w3";
2
+ import chroma from "chroma-js";
3
+ import { Hsluv } from "hsluv";
4
4
  const hexToCssHsl = (hex, valuesOnly = false) => {
5
5
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
6
6
  let r = 0;
@@ -12,9 +12,14 @@ const hexToCssHsl = (hex, valuesOnly = false) => {
12
12
  g = parseInt(result[2], 16);
13
13
  b = parseInt(result[3], 16);
14
14
  }
15
- r /= 255, g /= 255, b /= 255;
16
- const max = Math.max(r, g, b), min = Math.min(r, g, b);
17
- let h, s, l = (max + min) / 2;
15
+ r /= 255;
16
+ g /= 255;
17
+ b /= 255;
18
+ const max = Math.max(r, g, b);
19
+ const min = Math.min(r, g, b);
20
+ let h = 0;
21
+ let s = 0;
22
+ let l = (max + min) / 2;
18
23
  if (max == min) {
19
24
  h = s = 0;
20
25
  } else {
@@ -40,7 +45,9 @@ const hexToCssHsl = (hex, valuesOnly = false) => {
40
45
  return cssString;
41
46
  };
42
47
  const hexToHSL = (H) => {
43
- let r = 0, g = 0, b = 0;
48
+ let r = 0;
49
+ let g = 0;
50
+ let b = 0;
44
51
  if (H.length == 4) {
45
52
  r = parseInt("0x" + H[1] + H[1]);
46
53
  g = parseInt("0x" + H[2] + H[2]);
@@ -53,8 +60,12 @@ const hexToHSL = (H) => {
53
60
  r /= 255;
54
61
  g /= 255;
55
62
  b /= 255;
56
- let h = 0, s = 0, l = 0;
57
- const cmin = Math.min(r, g, b), cmax = Math.max(r, g, b), delta = cmax - cmin;
63
+ let h = 0;
64
+ let s = 0;
65
+ let l = 0;
66
+ const cmin = Math.min(r, g, b);
67
+ const cmax = Math.max(r, g, b);
68
+ const delta = cmax - cmin;
58
69
  if (delta == 0) h = 0;
59
70
  else if (cmax == r) h = (g - b) / delta % 6;
60
71
  else if (cmax == g) h = (b - r) / delta + 2;
@@ -79,8 +90,12 @@ const hslArrToCss = (HSL) => {
79
90
  const HSLToHex = (h, s, l) => {
80
91
  s /= 100;
81
92
  l /= 100;
82
- let r = 0, g = 0, b = 0;
83
- const c = (1 - Math.abs(2 * l - 1)) * s, x = c * (1 - Math.abs(h / 60 % 2 - 1)), m = l - c / 2;
93
+ let r = 0;
94
+ let g = 0;
95
+ let b = 0;
96
+ const c = (1 - Math.abs(2 * l - 1)) * s;
97
+ const x = c * (1 - Math.abs(h / 60 % 2 - 1));
98
+ const m = l - c / 2;
84
99
  if (0 <= h && h < 60) {
85
100
  r = c;
86
101
  g = x;
@@ -116,9 +131,7 @@ const HSLToHex = (h, s, l) => {
116
131
  };
117
132
  const hexToRgb = (hex) => {
118
133
  const shorthandRegex = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
119
- hex = hex.replace(shorthandRegex, function(m, r, g, b) {
120
- return r + r + g + g + b + b;
121
- });
134
+ hex = hex.replace(shorthandRegex, (m, r, g, b) => r + r + g + g + b + b);
122
135
  const result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
123
136
  return result ? {
124
137
  r: parseInt(result[1], 16),
@@ -127,9 +140,9 @@ const hexToRgb = (hex) => {
127
140
  } : null;
128
141
  };
129
142
  const luminanceFromRgb = (r, g, b) => {
130
- const a = [Number(r), Number(g), Number(b)].map(function(v) {
143
+ const a = [Number(r), Number(g), Number(b)].map((v) => {
131
144
  v /= 255;
132
- return v <= 0.03928 ? v / 12.92 : Math.pow((v + 0.055) / 1.055, 2.4);
145
+ return v <= 0.03928 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
133
146
  });
134
147
  return a[0] * 0.2126 + a[1] * 0.7152 + a[2] * 0.0722;
135
148
  };
@@ -146,9 +159,8 @@ const luminanceFromHex = (hex) => {
146
159
  const getRatioFromLum = (lum1, lum2) => {
147
160
  if (lum1 !== null && lum2 !== null) {
148
161
  return (Math.max(lum1, lum2) + 0.05) / (Math.min(lum1, lum2) + 0.05);
149
- } else {
150
- return -1;
151
162
  }
163
+ return -1;
152
164
  };
153
165
  const getHslLightessFromHex = (hex) => {
154
166
  return chroma(hex).hsl()[2];
@@ -187,11 +199,11 @@ const areColorsContrasting = (color1, color2, type = "aa") => {
187
199
  if (contrast !== null) {
188
200
  if (type === "aaa") {
189
201
  return contrast >= 7;
190
- } else if (type === "aa") {
202
+ }
203
+ if (type === "aa") {
191
204
  return contrast >= 4.5;
192
- } else {
193
- return contrast >= 3;
194
205
  }
206
+ return contrast >= 3;
195
207
  }
196
208
  return false;
197
209
  };
@@ -207,7 +219,7 @@ const getApcaContrastLc = (textColor, backgroundColor) => {
207
219
  return 0;
208
220
  };
209
221
  const isHexColor = (hex) => {
210
- return typeof hex === "string" && hex.length === 6 && !isNaN(Number("0x" + hex));
222
+ return typeof hex === "string" && hex.length === 6 && !Number.isNaN(Number("0x" + hex));
211
223
  };
212
224
  export {
213
225
  HSLToHex,
@@ -155,7 +155,8 @@ const canTextBeUsedOnColors = (baseDefaultColor, baseActiveColor) => {
155
155
  const activeAgainstBlack = getContrastFromHex(baseActiveColor, "#000000");
156
156
  if (defaultAgainstWhite >= 4.5 && activeAgainstWhite >= 4.5) {
157
157
  return true;
158
- } else if (defaultAgainstBlack >= 4.5 && activeAgainstBlack >= 4.5) {
158
+ }
159
+ if (defaultAgainstBlack >= 4.5 && activeAgainstBlack >= 4.5) {
159
160
  return true;
160
161
  }
161
162
  return false;
@@ -1,12 +1,12 @@
1
- import path from "node:path";
2
1
  import fs from "node:fs/promises";
2
+ import path from "node:path";
3
3
  import chalk from "chalk";
4
4
  import prompts from "prompts";
5
- import packageJsonTemplate from "./template/template-files/package.json" with { type: "json" };
6
5
  import generateMetadata from "./generateMetadataJson.js";
7
6
  import generateThemes from "./generateThemesJson.js";
8
- import { toGeneratedCssFileName, normalizeTokenSetName, toValidPackageName } from "./utils.js";
9
7
  import { nextStepsMarkdown } from "./nextStepsMarkdown.js";
8
+ import packageJsonTemplate from "./template/template-files/package.json" with { type: "json" };
9
+ import { normalizeTokenSetName, toGeneratedCssFileName, toValidPackageName } from "./utils.js";
10
10
  const MODES = ["Light", "Dark", "Contrast"];
11
11
  const promptOptions = {
12
12
  onCancel: () => {
@@ -6,9 +6,7 @@ function generateMetadataJson(modes, themes) {
6
6
  "primitives/typography/default",
7
7
  ...modes.flatMap((mode) => [
8
8
  `primitives/colors/${normalizeTokenSetName(mode)}/global`,
9
- ...themes.map(
10
- (theme) => `primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`
11
- )
9
+ ...themes.map((theme) => `primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`)
12
10
  ]),
13
11
  ...themes.map((theme) => `themes/${normalizeTokenSetName(theme)}`),
14
12
  "semantic/color",
@@ -2,11 +2,7 @@ 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 [
6
- ...generateModesGroup(modes, themes),
7
- ...generateThemesGroup(themes),
8
- generateSemanticGroup()
9
- ];
5
+ return [...generateModesGroup(modes, themes), ...generateThemesGroup(themes), generateSemanticGroup()];
10
6
  }
11
7
  function generateModesGroup(modes, themes) {
12
8
  return modes.map(
@@ -14,10 +10,7 @@ function generateModesGroup(modes, themes) {
14
10
  id: randomUUID(),
15
11
  name: mode,
16
12
  selectedTokenSets: Object.fromEntries([
17
- [
18
- `primitives/colors/${normalizeTokenSetName(mode)}/global`,
19
- TokenSetStatus.ENABLED
20
- ],
13
+ [`primitives/colors/${normalizeTokenSetName(mode)}/global`, TokenSetStatus.ENABLED],
21
14
  ...themes.map(
22
15
  (theme) => [
23
16
  `primitives/colors/${normalizeTokenSetName(mode)}/${normalizeTokenSetName(theme)}`,
@@ -1,6 +1,6 @@
1
- import * as R from "ramda";
2
1
  import chalk from "chalk";
3
2
  import hash from "object-hash";
3
+ import * as R from "ramda";
4
4
  const printDelete = (text) => console.log(`${chalk.red("Deleted:")} ${text}`.replace(/"|'/g, ""));
5
5
  const deleteMsg = (decl, from) => `${chalk.yellow(from)} @ ${chalk.gray(`${JSON.stringify(decl.source?.input.file)}:${decl.source?.start?.line}:${decl.source?.start?.column}`)}`;
6
6
  const cssClassRename = (dictionary) => ({
@@ -8,11 +8,11 @@ const cssClassRename = (dictionary) => ({
8
8
  Rule(rule) {
9
9
  const selector = rule.selector;
10
10
  if (!selector) return;
11
- Object.entries(dictionary).forEach(([from, to]) => {
11
+ for (const [from, to] of Object.entries(dictionary)) {
12
12
  if (!selector.includes(from)) return;
13
13
  const newSelector = selector.replace(new RegExp(from, "g"), to);
14
14
  rule.selector = newSelector;
15
- });
15
+ }
16
16
  }
17
17
  });
18
18
  const cssVarRename = (dictionary) => ({
@@ -20,22 +20,21 @@ const cssVarRename = (dictionary) => ({
20
20
  Declaration(decl) {
21
21
  const { value, prop } = decl;
22
22
  const deleted = /* @__PURE__ */ new Set();
23
- Object.entries(dictionary).forEach(([from, to]) => {
23
+ for (const [from, to] of Object.entries(dictionary)) {
24
24
  if (!R.isEmpty(to)) {
25
- switch (true) {
26
- case R.includes(from, value):
27
- to === "[delete]" && deleted.add(deleteMsg(decl, from));
28
- decl.value = value.replace(from, to);
29
- break;
30
- case R.includes(from, prop):
31
- if (decl.variable) {
32
- to === "[delete]" && deleted.add(deleteMsg(decl, from));
33
- decl.prop = prop.replace(from, to);
34
- break;
35
- }
25
+ if (R.includes(from, value)) {
26
+ if (to === "[delete]") {
27
+ deleted.add(deleteMsg(decl, from));
28
+ }
29
+ decl.value = value.replace(from, to);
30
+ } else if (R.includes(from, prop) && decl.variable) {
31
+ if (to === "[delete]") {
32
+ deleted.add(deleteMsg(decl, from));
33
+ }
34
+ decl.prop = prop.replace(from, to);
36
35
  }
37
36
  }
38
- });
37
+ }
39
38
  if (deleted.size > 0) {
40
39
  Array.from(deleted).forEach(printDelete);
41
40
  }
@@ -1,6 +1,6 @@
1
- import fs from "fs";
2
- import postcss from "postcss";
1
+ import fs from "node:fs";
3
2
  import glob from "fast-glob";
3
+ import postcss from "postcss";
4
4
  const runCssCodemod = async ({ plugins = [], globPattern = "./**/*.css" }) => {
5
5
  const processor = postcss(plugins);
6
6
  const transform = async () => {
@@ -5,11 +5,11 @@ const replaceInLiteral = (node) => {
5
5
  return node;
6
6
  };
7
7
  const replaceInTemplateLiteral = (node) => {
8
- node.forEach((element) => {
8
+ for (const element of node) {
9
9
  const value = element.value.raw;
10
- if (typeof value !== "string") return;
10
+ if (typeof value !== "string") continue;
11
11
  element.value.raw = replaceInLiteral(value);
12
- });
12
+ }
13
13
  };
14
14
  const processNode = (node) => {
15
15
  if (!node) return;
@@ -46,11 +46,12 @@ const processNode = (node) => {
46
46
  function replaceClassNamePrefix(file, api) {
47
47
  const j = api.jscodeshift;
48
48
  const root = j(file.source);
49
- root.find(j.JSXElement).forEach((path) => {
50
- j(path).find(j.JSXAttribute, { name: { name: "className" } }).forEach((nodePath) => {
49
+ for (const path of root.find(j.JSXElement).paths()) {
50
+ const nodes = j(path).find(j.JSXAttribute, { name: { name: "className" } });
51
+ for (const nodePath of nodes.paths()) {
51
52
  processNode(nodePath.value.value);
52
- });
53
- });
53
+ }
54
+ }
54
55
  return root.toSource({
55
56
  quote: "single",
56
57
  reuseWhitespace: true,
@@ -1,6 +1,6 @@
1
+ import chalk from "chalk";
1
2
  import glob from "fast-glob";
2
3
  import { run as jscodeshift } from "jscodeshift/src/Runner.js";
3
- import chalk from "chalk";
4
4
  const transformer = `${import.meta.dirname}/classname-prefix.ts`;
5
5
  const runJSXCodemod = async ({ globPattern = "./**/*.tsx", dry }) => {
6
6
  const options = {
@@ -1,6 +1,6 @@
1
- import fs from "fs-extra";
2
- import glob from "fast-glob";
3
1
  import chalk from "chalk";
2
+ import glob from "fast-glob";
3
+ import fs from "fs-extra";
4
4
  import * as R from "ramda";
5
5
  const sortLightmodeFirst = R.sortWith([R.descend(R.includes("light")), R.descend(R.includes("secondary"))]);
6
6
  const header = `@charset "UTF-8";
@@ -10,7 +10,7 @@ const header = `@charset "UTF-8";
10
10
  `;
11
11
  const makeEntryFile = {
12
12
  name: "make_entryfile",
13
- do: async function(dictionary, platform) {
13
+ do: async (dictionary, platform) => {
14
14
  const { outPath, theme, log } = platform;
15
15
  const writePath = `${outPath}/${theme}.css`;
16
16
  if (log?.verbosity !== "silent") {
@@ -18,7 +18,7 @@ const makeEntryFile = {
18
18
  }
19
19
  const generateImportUrls = R.pipe(
20
20
  sortLightmodeFirst,
21
- R.map((file) => `@import url('./${theme}/${file.toString()}');`),
21
+ R.map((file) => `@import url('${theme}/${file.toString()}');`),
22
22
  R.join("\n")
23
23
  );
24
24
  const files = await glob(`**/*`, { cwd: platform.buildPath });
@@ -1,15 +1,16 @@
1
- import path from "path";
2
- import fs from "fs";
3
- import StyleDictionary from "style-dictionary";
4
- import * as R from "ramda";
1
+ import fs from "node:fs";
2
+ import path from "node:path";
5
3
  import chalk from "chalk";
4
+ import * as R from "ramda";
5
+ import StyleDictionary from "style-dictionary";
6
6
  import * as configs from "./configs.js";
7
+ import { makeEntryFile } from "./utils/entryfile.js";
7
8
  const { permutateThemes, getConfigs } = configs;
8
9
  const sd = new StyleDictionary();
9
10
  async function run(options) {
10
11
  const tokensDir = options.tokens;
11
12
  const storefrontOutDir = path.resolve("../../apps/storefront/tokens");
12
- const tokensOutDir = path.resolve(options.out);
13
+ const outPath = path.resolve(options.out);
13
14
  const $themes = JSON.parse(fs.readFileSync(path.resolve(`${tokensDir}/$themes.json`), "utf-8"));
14
15
  const relevant$themes = $themes.filter((theme) => {
15
16
  const group = R.toLower(R.defaultTo("")(theme.group));
@@ -20,9 +21,9 @@ async function run(options) {
20
21
  const typographyThemes = R.filter((val) => val.mode === "light", themes);
21
22
  const colormodeThemes = R.filter((val) => val.typography === "primary", themes);
22
23
  const semanticThemes = R.filter((val) => val.mode === "light" && val.typography === "primary", themes);
23
- const colorModeConfigs = getConfigs(configs.colorModeVariables, tokensOutDir, tokensDir, colormodeThemes);
24
- const semanticConfigs = getConfigs(configs.semanticVariables, tokensOutDir, tokensDir, semanticThemes);
25
- const typographyConfigs = getConfigs(configs.typographyCSS, tokensOutDir, tokensDir, typographyThemes);
24
+ const colorModeConfigs = getConfigs(configs.colorModeVariables, outPath, tokensDir, colormodeThemes);
25
+ const semanticConfigs = getConfigs(configs.semanticVariables, outPath, tokensDir, semanticThemes);
26
+ const typographyConfigs = getConfigs(configs.typographyCSS, outPath, tokensDir, typographyThemes);
26
27
  const storefrontConfigs = getConfigs(configs.typescriptTokens, storefrontOutDir, tokensDir, colormodeThemes);
27
28
  if (typographyConfigs.length > 0) {
28
29
  console.log(`
@@ -35,17 +36,6 @@ async function run(options) {
35
36
  })
36
37
  );
37
38
  }
38
- if (semanticConfigs.length > 0) {
39
- console.log(`
40
- \u{1F371} Building ${chalk.green("semantic")}`);
41
- await Promise.all(
42
- semanticConfigs.map(async ({ theme, config, semantic }) => {
43
- console.log(`\u{1F477} ${theme} - ${semantic}`);
44
- const typographyClasses = await sd.extend(config);
45
- return typographyClasses.buildAllPlatforms();
46
- })
47
- );
48
- }
49
39
  if (colorModeConfigs.length > 0) {
50
40
  console.log(`
51
41
  \u{1F371} Building ${chalk.green("color-mode")}`);
@@ -57,6 +47,17 @@ async function run(options) {
57
47
  })
58
48
  );
59
49
  }
50
+ if (semanticConfigs.length > 0) {
51
+ console.log(`
52
+ \u{1F371} Building ${chalk.green("semantic")}`);
53
+ await Promise.all(
54
+ semanticConfigs.map(async ({ theme, config, semantic }) => {
55
+ console.log(`\u{1F477} ${theme} - ${semantic}`);
56
+ const typographyClasses = await sd.extend(config);
57
+ return typographyClasses.buildAllPlatforms();
58
+ })
59
+ );
60
+ }
60
61
  if (storefrontConfigs.length > 0 && options.preview) {
61
62
  console.log(`
62
63
  \u{1F371} Building ${chalk.green("Storefront preview tokens")}`);
@@ -68,6 +69,16 @@ async function run(options) {
68
69
  })
69
70
  );
70
71
  }
72
+ if (semanticConfigs.length > 0) {
73
+ console.log(`
74
+ \u{1F371} Building ${chalk.green("CSS file")}`);
75
+ await Promise.all(
76
+ semanticConfigs.map(async ({ theme }) => {
77
+ console.log(`\u{1F477} ${theme}.css`);
78
+ return makeEntryFile({ theme, outPath, buildPath: path.resolve(`${outPath}/${theme}`) });
79
+ })
80
+ );
81
+ }
71
82
  }
72
83
  export {
73
84
  run
@@ -1,14 +1,14 @@
1
- import * as tokenStudio from "@tokens-studio/sd-transforms";
1
+ import { register } from "@tokens-studio/sd-transforms";
2
+ import * as R from "ramda";
2
3
  import StyleDictionary from "style-dictionary";
3
4
  import { outputReferencesFilter } from "style-dictionary/utils";
4
- import * as R from "ramda";
5
- import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
6
- import { nameKebab, typographyShorthand, sizeRem } from "./transformers.js";
7
- import { jsTokens } from "./formats/js-tokens.js";
8
5
  import * as formats from "./formats/css.js";
9
- import { makeEntryFile } from "./actions.js";
10
- import { typeEquals } from "./utils/utils.js";
11
- void tokenStudio.registerTransforms(StyleDictionary);
6
+ import { jsTokens } from "./formats/js-tokens.js";
7
+ import { nameKebab, sizeRem, typographyShorthand } from "./transformers.js";
8
+ import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
9
+ import { pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
10
+ void register(StyleDictionary, { withSDBuiltins: false });
11
+ const usesDtcg = true;
12
12
  const prefix = "ds";
13
13
  const basePxFontSize = 16;
14
14
  const separator = "_";
@@ -20,7 +20,6 @@ StyleDictionary.registerFormat(jsTokens);
20
20
  StyleDictionary.registerFormat(formats.colormode);
21
21
  StyleDictionary.registerFormat(formats.semantic);
22
22
  StyleDictionary.registerFormat(formats.typography);
23
- StyleDictionary.registerAction(makeEntryFile);
24
23
  const dsTransformers = [
25
24
  nameKebab.name,
26
25
  `ts/resolveMath`,
@@ -31,7 +30,7 @@ const dsTransformers = [
31
30
  "ts/color/modifiers",
32
31
  "ts/color/css/hexrgba",
33
32
  "ts/size/lineheight",
34
- "ts/shadow/css/shorthand"
33
+ "shadow/css/shorthand"
35
34
  ];
36
35
  const paritionPrimitives = R.partition(R.test(/(?!.*global\.json).*primitives.*/));
37
36
  const hasUnknownProps = R.pipe(R.values, R.none(R.equals("unknown")), R.not);
@@ -48,6 +47,7 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
48
47
  const selector = `${mode === "light" ? ":root, " : ""}[data-ds-color-mode="${mode}"]`;
49
48
  const layer = `ds.theme.color-mode.${mode}`;
50
49
  return {
50
+ usesDtcg,
51
51
  log: { verbosity: "silent" },
52
52
  preprocessors: ["tokens-studio"],
53
53
  platforms: {
@@ -62,7 +62,6 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
62
62
  prefix,
63
63
  buildPath: `${outPath}/${theme}/`,
64
64
  transforms: dsTransformers,
65
- actions: [makeEntryFile.name],
66
65
  files: [
67
66
  {
68
67
  destination: `color-mode/${mode}.css`,
@@ -81,8 +80,9 @@ const colorModeVariables = ({ mode = "light", outPath, theme }) => {
81
80
  const semanticVariables = ({ outPath, theme }) => {
82
81
  const selector = `:root`;
83
82
  const layer = `ds.theme.semantic`;
84
- const isCalculatedToken = (token) => typeEquals(["spacing", "sizing", "borderRadius"], token);
83
+ const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing", "border-radius"], token);
85
84
  return {
85
+ usesDtcg,
86
86
  log: { verbosity: "silent" },
87
87
  preprocessors: ["tokens-studio"],
88
88
  platforms: {
@@ -98,12 +98,11 @@ const semanticVariables = ({ outPath, theme }) => {
98
98
  prefix,
99
99
  buildPath: `${outPath}/${theme}/`,
100
100
  transforms: dsTransformers,
101
- actions: [makeEntryFile.name],
102
101
  files: [
103
102
  {
104
103
  destination: `semantic.css`,
105
104
  format: formats.semantic.name,
106
- filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeights", "fontFamilies"], token)
105
+ filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily"], token)
107
106
  }
108
107
  ],
109
108
  options: {
@@ -116,6 +115,7 @@ const semanticVariables = ({ outPath, theme }) => {
116
115
  };
117
116
  const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
118
117
  return {
118
+ usesDtcg,
119
119
  log: { verbosity: "silent" },
120
120
  preprocessors: ["tokens-studio"],
121
121
  platforms: {
@@ -130,9 +130,8 @@ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
130
130
  format: jsTokens.name,
131
131
  outputReferences: outputColorReferences,
132
132
  filter: (token) => {
133
- if (R.test(/primitives\/modes|\/themes/, token.filePath)) {
134
- return false;
135
- }
133
+ if (R.test(/primitives\/modes|\/themes/, token.filePath)) return false;
134
+ if (pathStartsWithOneOf(["border-width"], token)) return false;
136
135
  if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) || R.includes("semantic", token.filePath)) {
137
136
  return true;
138
137
  }
@@ -151,6 +150,7 @@ const typographyCSS = ({ outPath, theme, typography }) => {
151
150
  const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
152
151
  const layer = `ds.theme.typography.${typography}`;
153
152
  return {
153
+ usesDtcg: true,
154
154
  log: { verbosity: "silent" },
155
155
  preprocessors: ["tokens-studio"],
156
156
  platforms: {
@@ -167,10 +167,14 @@ const typographyCSS = ({ outPath, theme, typography }) => {
167
167
  destination: `typography/${typography}.css`,
168
168
  format: formats.typography.name,
169
169
  filter: (token) => {
170
- return typeEquals(
171
- ["typography", "fontweights", "fontfamilies", "lineheights", "fontsizes", "letterSpacing"],
170
+ const included = typeEquals(
171
+ ["typography", "fontweight", "fontFamily", "lineheight", "fontsize", "dimension", "font"],
172
+ token
173
+ );
174
+ return included && !pathStartsWithOneOf(
175
+ ["spacing", "sizing", "border-width", "border-radius", "theme", "theme2", "theme3", "theme4"],
172
176
  token
173
- ) && !(token.path[0] || "").startsWith("theme");
177
+ );
174
178
  }
175
179
  }
176
180
  ],