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

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.
@@ -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";
@@ -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) => ({
@@ -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 () => {
@@ -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") {
@@ -1,8 +1,8 @@
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
7
  const { permutateThemes, getConfigs } = configs;
8
8
  const sd = new StyleDictionary();
@@ -1,12 +1,12 @@
1
1
  import * as tokenStudio 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
- import * as formats from "./formats/css.js";
9
5
  import { makeEntryFile } from "./actions.js";
6
+ import * as formats from "./formats/css.js";
7
+ import { jsTokens } from "./formats/js-tokens.js";
8
+ import { nameKebab, sizeRem, typographyShorthand } from "./transformers.js";
9
+ import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
10
10
  import { typeEquals } from "./utils/utils.js";
11
11
  void tokenStudio.registerTransforms(StyleDictionary);
12
12
  const prefix = "ds";
@@ -1,5 +1,5 @@
1
1
  import * as R from "ramda";
2
- import { fileHeader, createPropertyFormatter, usesReferences, getReferences } from "style-dictionary/utils";
2
+ import { createPropertyFormatter, fileHeader, getReferences, usesReferences } from "style-dictionary/utils";
3
3
  import { prefix } from "../configs.js";
4
4
  import { getValue, typeEquals } from "../utils/utils.js";
5
5
  const prefersColorScheme = (mode, content) => `
@@ -9,7 +9,7 @@ const prefersColorScheme = (mode, content) => `
9
9
  `;
10
10
  const colormode = {
11
11
  name: "ds/css-colormode",
12
- format: async function({ dictionary, file, options, platform }) {
12
+ format: async ({ dictionary, file, options, platform }) => {
13
13
  const { allTokens } = dictionary;
14
14
  const { outputReferences } = options;
15
15
  const { selector, mode, layer } = platform;
@@ -36,7 +36,7 @@ ${selector} ${content} ${autoSelectorContent}
36
36
  const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}: calc(${R.trim(split[1])});`);
37
37
  const semantic = {
38
38
  name: "ds/css-semantic",
39
- format: async function({ dictionary, file, options, platform }) {
39
+ format: async ({ dictionary, file, options, platform }) => {
40
40
  const { allTokens } = dictionary;
41
41
  const { outputReferences } = options;
42
42
  const { selector, isCalculatedToken, layer } = platform;
@@ -91,7 +91,7 @@ const sortTypographyLast = R.sortWith([
91
91
  ]);
92
92
  const typography = {
93
93
  name: "ds/css-typography",
94
- format: async function({ dictionary, file, options, platform }) {
94
+ format: async ({ dictionary, file, options, platform }) => {
95
95
  const { outputReferences } = options;
96
96
  const { selector, layer } = platform;
97
97
  const header = await fileHeader({ file });
@@ -1,5 +1,5 @@
1
1
  import * as R from "ramda";
2
- import { fileHeader, createPropertyFormatter } from "style-dictionary/utils";
2
+ import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
3
3
  import { getType } from "../utils/utils.js";
4
4
  const groupByType = R.groupBy((token) => getType(token));
5
5
  const removeUnwatedTokens = R.filter(
@@ -8,7 +8,7 @@ const removeUnwatedTokens = R.filter(
8
8
  const toCssVarName = R.pipe(R.split(":"), R.head, R.trim);
9
9
  const jsTokens = {
10
10
  name: "ds/js-tokens",
11
- format: async function({ dictionary, file }) {
11
+ format: async ({ dictionary, file }) => {
12
12
  const format = createPropertyFormatter({
13
13
  dictionary,
14
14
  format: "css"
@@ -8,11 +8,7 @@ function noCase(input, options = {}) {
8
8
  transform = lowerCase,
9
9
  delimiter = " "
10
10
  } = options;
11
- const result = replace(
12
- replace(input, splitRegexp, "$1\0$2"),
13
- stripRegexp,
14
- "\0"
15
- );
11
+ const result = replace(replace(input, splitRegexp, "$1\0$2"), stripRegexp, "\0");
16
12
  let start = 0;
17
13
  let end = result.length;
18
14
  while (result.charAt(start) === "\0") start++;
@@ -1,5 +1,5 @@
1
- import * as R from "ramda";
2
1
  import { TokenSetStatus } from "@tokens-studio/types";
2
+ import * as R from "ramda";
3
3
  function mapThemesToSetsObject(themes) {
4
4
  return themes.map((theme) => ({ name: theme.name, selectedTokenSets: filterTokenSets(theme.selectedTokenSets) }));
5
5
  }
@@ -49,7 +49,8 @@ function filterTokenSets(tokensets) {
49
49
  return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
50
50
  if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
51
51
  return -1;
52
- } else if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
52
+ }
53
+ if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
53
54
  return 1;
54
55
  }
55
56
  return 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "0.1.0-next.20",
3
+ "version": "0.1.0-next.21",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "repository": {
@@ -14,18 +14,12 @@
14
14
  "files": [
15
15
  "./dist/**"
16
16
  ],
17
+ "bin": "dist/bin/designsystemet.js",
17
18
  "exports": {
18
- "./color": "./src/colors/index.ts"
19
+ "./color": "./dist/src/colors/index.js"
19
20
  },
20
- "bin": "bin/designsystemet.js",
21
21
  "publishConfig": {
22
- "access": "public",
23
- "bin": {
24
- "designsystemet": "dist/bin/designsystemet.js"
25
- },
26
- "exports": {
27
- "./color": "./dist/src/colors/index.js"
28
- }
22
+ "access": "public"
29
23
  },
30
24
  "scripts": {
31
25
  "designsystemet": "tsx ./bin/designsystemet.ts",
@@ -63,7 +57,7 @@
63
57
  "@types/fs-extra": "^11.0.4",
64
58
  "@types/glob": "^8.1.0",
65
59
  "@types/jscodeshift": "^0.11.11",
66
- "@types/node": "^20.12.7",
60
+ "@types/node": "^20.14.12",
67
61
  "@types/object-hash": "^3",
68
62
  "@types/prompts": "^2.4.9",
69
63
  "@types/ramda": "^0.29.9",