@digdir/designsystemet 0.1.0-next.31 → 1.0.0-next.33

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 (41) hide show
  1. package/dist/bin/designsystemet.js +18 -12
  2. package/dist/src/colors/theme.js +1 -1
  3. package/dist/src/init/template/default-files/design-tokens/semantic/color.json +2 -2
  4. package/dist/src/tokens/{build/index.js → build.js} +2 -2
  5. package/dist/src/tokens/create.js +100 -0
  6. package/dist/src/tokens/design-tokens/default/Figma/components.json +22 -0
  7. package/dist/src/tokens/design-tokens/default/primitives/globals.json +161 -0
  8. package/dist/src/tokens/design-tokens/default/primitives/size/default.json +175 -0
  9. package/dist/src/tokens/design-tokens/default/semantic/color.json +572 -0
  10. package/dist/src/tokens/design-tokens/default/semantic/style.json +564 -0
  11. package/dist/src/tokens/design-tokens/template/$metadata.json +17 -0
  12. package/dist/src/tokens/design-tokens/template/$themes.json +1231 -0
  13. package/dist/src/tokens/design-tokens/template/themes/theme.json +334 -0
  14. package/dist/src/tokens/template.js +66 -0
  15. package/dist/src/tokens/types.js +0 -0
  16. package/dist/src/tokens/write/generate$metadata.js +21 -0
  17. package/dist/src/tokens/write/generate$themes.js +115 -0
  18. package/dist/src/tokens/write.js +79 -0
  19. package/dist/types/src/tokens/{build/index.d.ts → build.d.ts} +1 -1
  20. package/dist/types/src/tokens/build.d.ts.map +1 -0
  21. package/dist/types/src/tokens/create.d.ts +8 -0
  22. package/dist/types/src/tokens/create.d.ts.map +1 -0
  23. package/dist/types/src/tokens/template.d.ts +2 -0
  24. package/dist/types/src/tokens/template.d.ts.map +1 -0
  25. package/dist/types/src/tokens/types.d.ts +37 -0
  26. package/dist/types/src/tokens/types.d.ts.map +1 -0
  27. package/dist/types/src/tokens/write/generate$metadata.d.ts +8 -0
  28. package/dist/types/src/tokens/write/generate$metadata.d.ts.map +1 -0
  29. package/dist/types/src/tokens/write/generate$themes.d.ts +10 -0
  30. package/dist/types/src/tokens/write/generate$themes.d.ts.map +1 -0
  31. package/dist/types/src/tokens/write.d.ts +10 -0
  32. package/dist/types/src/tokens/write.d.ts.map +1 -0
  33. package/package.json +6 -5
  34. package/dist/src/tokens/create/README.md +0 -3
  35. package/dist/src/tokens/create/index.js +0 -150
  36. package/dist/src/tokens/index.js +0 -4
  37. package/dist/types/src/tokens/build/index.d.ts.map +0 -1
  38. package/dist/types/src/tokens/create/index.d.ts +0 -64
  39. package/dist/types/src/tokens/create/index.d.ts.map +0 -1
  40. package/dist/types/src/tokens/index.d.ts +0 -2
  41. package/dist/types/src/tokens/index.d.ts.map +0 -1
@@ -4,23 +4,26 @@ import chalk from "chalk";
4
4
  import { convertToHex } from "../src/colors/index.js";
5
5
  import { createTokensPackage } from "../src/init/createTokensPackage.js";
6
6
  import migrations from "../src/migrations/index.js";
7
- import { buildTokens } from "../src/tokens/build/index.js";
8
- import { createTokens } from "../src/tokens/create//index.js";
7
+ import { buildTokens } from "../src/tokens/build.js";
8
+ import { createTokens } from "../src/tokens/create.js";
9
+ import { writeTokens } from "../src/tokens/write.js";
9
10
  program.name("Designsystemet").description("CLI for working with Designsystemet").showHelpAfterError();
10
11
  function makeTokenCommands() {
11
12
  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";
13
+ const DEFAULT_TOKENSDIR = "./design-tokens";
14
+ tokenCmd.command("build").description("Build Designsystemet tokens").option("-t, --tokens <string>", `Path to ${chalk.blue("design-tokens")}`, DEFAULT_TOKENSDIR).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) => {
15
+ const tokens = typeof opts.tokens === "string" ? opts.tokens : DEFAULT_TOKENSDIR;
14
16
  const out = typeof opts.out === "string" ? opts.out : "./dist/tokens";
15
17
  const preview = opts.preview;
16
18
  console.log(`Bulding tokens in ${chalk.green(tokens)}`);
17
19
  return buildTokens({ tokens, out, preview });
18
20
  });
19
- tokenCmd.command("create").description("Create Designsystemet tokens").option("-w, --write [string]", `Output directory for created ${chalk.blue("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 family = typeof opts.fontFamily === "string" ? opts.fontFamily : "Inter";
22
- const write2 = typeof opts.write === "boolean" ? "./design-tokens" : opts.write;
21
+ tokenCmd.command("create").description("Create Designsystemet tokens").requiredOption("-a, --accent <number>", `Accent hex color`).requiredOption("-n, --neutral <number>", `Neutral hex color`).requiredOption("-b1, --brand1 <number>", `Brand1 hex color`).requiredOption("-b2, --brand2 <number>", `Brand2 hex color`).requiredOption("-b3, --brand3 <number>", `Brand3 hex color`).option("-w, --write [string]", `Output directory for created ${chalk.blue("design-tokens")}`, DEFAULT_TOKENSDIR).option("-f, --font-family <string>", `Font family`, "Inter").option("--theme <string>", `Theme name`, "theme").action(async (opts) => {
22
+ const { theme, fontFamily } = opts;
23
+ console.log(`Creating tokens with options ${chalk.green(JSON.stringify(opts, null, 2))}`);
24
+ const write = typeof opts.write === "boolean" ? DEFAULT_TOKENSDIR : opts.write;
23
25
  const props = {
26
+ themeName: theme,
24
27
  colors: {
25
28
  accent: convertToHex(opts.accent),
26
29
  neutral: convertToHex(opts.neutral),
@@ -29,11 +32,14 @@ function makeTokenCommands() {
29
32
  brand3: convertToHex(opts.brand3)
30
33
  },
31
34
  typography: {
32
- family
33
- },
34
- write: write2
35
+ fontFamily
36
+ }
35
37
  };
36
- await createTokens(props);
38
+ const tokens = createTokens(props);
39
+ if (write) {
40
+ await writeTokens({ writeDir: write, tokens, themeName: theme });
41
+ }
42
+ return Promise.resolve();
37
43
  });
38
44
  return tokenCmd;
39
45
  }
@@ -229,7 +229,7 @@ const getBaseColor = (color) => {
229
229
  return conv.hex;
230
230
  };
231
231
  const getCssVariable = (colorType, colorNumber) => {
232
- return `--ds-${colorType}-${getColorNameFromNumber(colorNumber).toLowerCase().replace(/\s/g, "-")}`;
232
+ return `--ds-color-${colorType}-${getColorNameFromNumber(colorNumber).toLowerCase().replace(/\s/g, "-")}`;
233
233
  };
234
234
  export {
235
235
  baseColors,
@@ -551,11 +551,11 @@
551
551
  },
552
552
  "contrast-default": {
553
553
  "$type": "color",
554
- "$value": "{global.yellow.contrast-1}"
554
+ "$value": "{global.orange.contrast-1}"
555
555
  },
556
556
  "contrast-subtle": {
557
557
  "$type": "color",
558
- "$value": "{global.yellow.contrast-2}"
558
+ "$value": "{global.orange.contrast-2}"
559
559
  }
560
560
  },
561
561
  "focus": {
@@ -3,8 +3,8 @@ import path from "node:path";
3
3
  import chalk from "chalk";
4
4
  import * as R from "ramda";
5
5
  import StyleDictionary from "style-dictionary";
6
- import * as configs from "./configs.js";
7
- import { makeEntryFile } from "./utils/entryfile.js";
6
+ import * as configs from "./build/configs.js";
7
+ import { makeEntryFile } from "./build/utils/entryfile.js";
8
8
  const { permutateThemes, getConfigs } = configs;
9
9
  const sd = new StyleDictionary();
10
10
  async function buildTokens(options) {
@@ -0,0 +1,100 @@
1
+ import { baseColors, generateScaleForColor } from "../colors/index.js";
2
+ const createColorTokens = (colorArray) => {
3
+ const obj = {};
4
+ const $type = "color";
5
+ for (let i = 0; i < colorArray.length; i++) {
6
+ if (i === 13 && colorArray.length >= 14) {
7
+ obj["contrast-1"] = {
8
+ $type,
9
+ $value: colorArray[i].hex
10
+ };
11
+ } else if (i === 14 && colorArray.length >= 15) {
12
+ obj["contrast-2"] = {
13
+ $type,
14
+ $value: colorArray[i].hex
15
+ };
16
+ } else {
17
+ obj[i + 1] = { $type, $value: colorArray[i].hex };
18
+ }
19
+ }
20
+ return obj;
21
+ };
22
+ const generateTypographyTokens = (themeName, { fontFamily }) => {
23
+ return {
24
+ [themeName]: {
25
+ main: {
26
+ $type: "fontFamilies",
27
+ $value: fontFamily ?? "Inter"
28
+ },
29
+ bold: {
30
+ $type: "fontWeights",
31
+ $value: "Medium"
32
+ },
33
+ "extra-bold": {
34
+ $type: "fontWeights",
35
+ $value: "Semi bold"
36
+ },
37
+ regular: {
38
+ $type: "fontWeights",
39
+ $value: "Regular"
40
+ }
41
+ }
42
+ };
43
+ };
44
+ const generateThemeTokens = (themeName, theme, colors) => {
45
+ const accentColors = generateScaleForColor(colors.accent, theme);
46
+ const neutralColors = generateScaleForColor(colors.neutral, theme);
47
+ const brand1Colors = generateScaleForColor(colors.brand1, theme);
48
+ const brand2Colors = generateScaleForColor(colors.brand2, theme);
49
+ const brand3Colors = generateScaleForColor(colors.brand3, theme);
50
+ return {
51
+ [themeName]: {
52
+ accent: createColorTokens(accentColors),
53
+ neutral: createColorTokens(neutralColors),
54
+ brand1: createColorTokens(brand1Colors),
55
+ brand2: createColorTokens(brand2Colors),
56
+ brand3: createColorTokens(brand3Colors)
57
+ }
58
+ };
59
+ };
60
+ const generateGlobalTokens = (theme) => {
61
+ const blueScale = generateScaleForColor(baseColors.blue, theme);
62
+ const greenScale = generateScaleForColor(baseColors.green, theme);
63
+ const orangeScale = generateScaleForColor(baseColors.orange, theme);
64
+ const purpleScale = generateScaleForColor(baseColors.purple, theme);
65
+ const redScale = generateScaleForColor(baseColors.red, theme);
66
+ const yellowScale = generateScaleForColor(baseColors.yellow, theme);
67
+ return {
68
+ global: {
69
+ blue: createColorTokens(blueScale),
70
+ green: createColorTokens(greenScale),
71
+ orange: createColorTokens(orangeScale),
72
+ purple: createColorTokens(purpleScale),
73
+ red: createColorTokens(redScale),
74
+ yellow: createColorTokens(yellowScale)
75
+ }
76
+ };
77
+ };
78
+ const createTokens = (opts) => {
79
+ const { colors, typography, themeName: name } = opts;
80
+ const tokens = {
81
+ colors: {
82
+ light: {
83
+ [name]: generateThemeTokens(name, "light", colors),
84
+ global: generateGlobalTokens("light")
85
+ },
86
+ dark: { [name]: generateThemeTokens(name, "dark", colors), global: generateGlobalTokens("dark") },
87
+ contrast: {
88
+ [name]: generateThemeTokens(name, "contrast", colors),
89
+ global: generateGlobalTokens("contrast")
90
+ }
91
+ },
92
+ typography: {
93
+ primary: generateTypographyTokens(name, typography)
94
+ }
95
+ };
96
+ return tokens;
97
+ };
98
+ export {
99
+ createTokens
100
+ };
@@ -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
+ }
@@ -0,0 +1,161 @@
1
+ {
2
+ "border-width": {
3
+ "1": {
4
+ "$type": "borderWidth",
5
+ "$value": "1px"
6
+ },
7
+ "2": {
8
+ "$type": "borderWidth",
9
+ "$value": "2px"
10
+ }
11
+ },
12
+ "shadow": {
13
+ "100": {
14
+ "$type": "boxShadow",
15
+ "$value": [
16
+ {
17
+ "color": "rgba(0,0,0,0.16)",
18
+ "x": "0",
19
+ "y": "0",
20
+ "blur": "1",
21
+ "spread": "0"
22
+ },
23
+ {
24
+ "x": "0",
25
+ "y": "1",
26
+ "blur": "2",
27
+ "spread": "0",
28
+ "color": "rgba(0,0,0,0.12)"
29
+ }
30
+ ]
31
+ },
32
+ "200": {
33
+ "$type": "boxShadow",
34
+ "$value": [
35
+ {
36
+ "color": "rgba(0,0,0,0.15)",
37
+ "x": "0",
38
+ "y": "0",
39
+ "blur": "1",
40
+ "spread": "0"
41
+ },
42
+ {
43
+ "color": "rgba(0,0,0,0.12)",
44
+ "x": "0",
45
+ "y": "1",
46
+ "blur": "2",
47
+ "spread": "0"
48
+ },
49
+ {
50
+ "x": "0",
51
+ "y": "2",
52
+ "blur": "4",
53
+ "spread": "0",
54
+ "color": "rgba(0,0,0,0.1)"
55
+ }
56
+ ]
57
+ },
58
+ "300": {
59
+ "$type": "boxShadow",
60
+ "$value": [
61
+ {
62
+ "color": "rgba(0,0,0,0.14)",
63
+ "x": "0",
64
+ "y": "0",
65
+ "blur": "1",
66
+ "spread": "0"
67
+ },
68
+ {
69
+ "color": "rgba(0,0,0,0.12)",
70
+ "x": "0",
71
+ "y": "2",
72
+ "blur": "4",
73
+ "spread": "0"
74
+ },
75
+ {
76
+ "x": "0",
77
+ "y": "4",
78
+ "blur": "8",
79
+ "spread": "0",
80
+ "color": "rgba(0,0,0,0.12)"
81
+ }
82
+ ]
83
+ },
84
+ "400": {
85
+ "$type": "boxShadow",
86
+ "$value": [
87
+ {
88
+ "color": "rgba(0,0,0,0.13)",
89
+ "x": "0",
90
+ "y": "0",
91
+ "blur": "1",
92
+ "spread": "0"
93
+ },
94
+ {
95
+ "color": "rgba(0,0,0,0.13)",
96
+ "x": "0",
97
+ "y": "3",
98
+ "blur": "5",
99
+ "spread": "0"
100
+ },
101
+ {
102
+ "x": "0",
103
+ "y": "6",
104
+ "blur": "12",
105
+ "spread": "0",
106
+ "color": "rgba(0,0,0,0.14)"
107
+ }
108
+ ]
109
+ },
110
+ "500": {
111
+ "$type": "boxShadow",
112
+ "$value": [
113
+ {
114
+ "color": "rgba(0,0,0,0.12)",
115
+ "x": "0",
116
+ "y": "0",
117
+ "blur": "1",
118
+ "spread": "0"
119
+ },
120
+ {
121
+ "color": "rgba(0,0,0,0.16)",
122
+ "x": "0",
123
+ "y": "4",
124
+ "blur": "8",
125
+ "spread": "0"
126
+ },
127
+ {
128
+ "x": "0",
129
+ "y": "12",
130
+ "blur": "24",
131
+ "spread": "0",
132
+ "color": "rgba(0,0,0,0.16)"
133
+ }
134
+ ]
135
+ }
136
+ },
137
+ "border-radius": {
138
+ "base": {
139
+ "$type": "borderRadius",
140
+ "$value": "4"
141
+ }
142
+ },
143
+ "opacity": {
144
+ "30": {
145
+ "$type": "opacity",
146
+ "$value": "30%"
147
+ }
148
+ },
149
+ "sizing": {
150
+ "base": {
151
+ "$type": "sizing",
152
+ "$value": "4"
153
+ }
154
+ },
155
+ "spacing": {
156
+ "base": {
157
+ "$type": "spacing",
158
+ "$value": "4"
159
+ }
160
+ }
161
+ }
@@ -0,0 +1,175 @@
1
+ {
2
+ "line-height": {
3
+ "sm": {
4
+ "$extensions": {
5
+ "studio.tokens": {
6
+ "modify": {}
7
+ }
8
+ },
9
+ "$type": "lineHeights",
10
+ "$value": "130%"
11
+ },
12
+ "md": {
13
+ "$extensions": {
14
+ "studio.tokens": {
15
+ "modify": {}
16
+ }
17
+ },
18
+ "$type": "lineHeights",
19
+ "$value": "150%"
20
+ },
21
+ "lg": {
22
+ "$extensions": {
23
+ "studio.tokens": {
24
+ "modify": {}
25
+ }
26
+ },
27
+ "$type": "lineHeights",
28
+ "$value": "170%"
29
+ }
30
+ },
31
+ "font-size": {
32
+ "1": {
33
+ "$extensions": {
34
+ "studio.tokens": {
35
+ "modify": {}
36
+ }
37
+ },
38
+ "$type": "fontSizes",
39
+ "$value": "12"
40
+ },
41
+ "2": {
42
+ "$extensions": {
43
+ "studio.tokens": {
44
+ "modify": {}
45
+ }
46
+ },
47
+ "$type": "fontSizes",
48
+ "$value": "13"
49
+ },
50
+ "3": {
51
+ "$extensions": {
52
+ "studio.tokens": {
53
+ "modify": {}
54
+ }
55
+ },
56
+ "$type": "fontSizes",
57
+ "$value": "14"
58
+ },
59
+ "4": {
60
+ "$extensions": {
61
+ "studio.tokens": {
62
+ "modify": {}
63
+ }
64
+ },
65
+ "$type": "fontSizes",
66
+ "$value": "16"
67
+ },
68
+ "5": {
69
+ "$extensions": {
70
+ "studio.tokens": {
71
+ "modify": {}
72
+ }
73
+ },
74
+ "$type": "fontSizes",
75
+ "$value": "18"
76
+ },
77
+ "6": {
78
+ "$extensions": {
79
+ "studio.tokens": {
80
+ "modify": {}
81
+ }
82
+ },
83
+ "$type": "fontSizes",
84
+ "$value": "21"
85
+ },
86
+ "7": {
87
+ "$extensions": {
88
+ "studio.tokens": {
89
+ "modify": {}
90
+ }
91
+ },
92
+ "$type": "fontSizes",
93
+ "$value": "24"
94
+ },
95
+ "8": {
96
+ "$extensions": {
97
+ "studio.tokens": {
98
+ "modify": {}
99
+ }
100
+ },
101
+ "$type": "fontSizes",
102
+ "$value": "30"
103
+ },
104
+ "9": {
105
+ "$extensions": {
106
+ "studio.tokens": {
107
+ "modify": {}
108
+ }
109
+ },
110
+ "$type": "fontSizes",
111
+ "$value": "36"
112
+ },
113
+ "10": {
114
+ "$extensions": {
115
+ "studio.tokens": {
116
+ "modify": {}
117
+ }
118
+ },
119
+ "$type": "fontSizes",
120
+ "$value": "48"
121
+ },
122
+ "11": {
123
+ "$extensions": {
124
+ "studio.tokens": {
125
+ "modify": {}
126
+ }
127
+ },
128
+ "$type": "fontSizes",
129
+ "$value": "60"
130
+ }
131
+ },
132
+ "letter-spacing": {
133
+ "1": {
134
+ "$type": "letterSpacing",
135
+ "$value": "-1%"
136
+ },
137
+ "2": {
138
+ "$type": "letterSpacing",
139
+ "$value": "-0.5%"
140
+ },
141
+ "3": {
142
+ "$type": "letterSpacing",
143
+ "$value": "-0.25%"
144
+ },
145
+ "4": {
146
+ "$type": "letterSpacing",
147
+ "$value": "-0.15%"
148
+ },
149
+ "5": {
150
+ "$type": "letterSpacing",
151
+ "$value": "0%"
152
+ },
153
+ "6": {
154
+ "$type": "letterSpacing",
155
+ "$value": "0.15%"
156
+ },
157
+ "7": {
158
+ "$type": "letterSpacing",
159
+ "$value": "0.25%"
160
+ },
161
+ "8": {
162
+ "$type": "letterSpacing",
163
+ "$value": "0.5%"
164
+ },
165
+ "9": {
166
+ "$extensions": {
167
+ "studio.tokens": {
168
+ "modify": {}
169
+ }
170
+ },
171
+ "$type": "letterSpacing",
172
+ "$value": "1.5%"
173
+ }
174
+ }
175
+ }