@digdir/designsystemet 1.0.0-next.32 → 1.0.0-next.34

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 (48) hide show
  1. package/dist/bin/designsystemet.js +18 -12
  2. package/dist/src/colors/theme.js +1 -1
  3. package/dist/src/tokens/build/configs.js +19 -8
  4. package/dist/src/tokens/build/formats/css.js +17 -92
  5. package/dist/src/tokens/build/transformers.js +7 -7
  6. package/dist/src/tokens/{build/index.js → build.js} +3 -3
  7. package/dist/src/tokens/create.js +100 -0
  8. package/dist/src/tokens/design-tokens/default/Figma/components.json +22 -0
  9. package/dist/src/tokens/design-tokens/default/primitives/globals.json +161 -0
  10. package/dist/src/tokens/design-tokens/default/primitives/size/default.json +175 -0
  11. package/dist/src/tokens/design-tokens/default/semantic/color.json +572 -0
  12. package/dist/src/tokens/design-tokens/default/semantic/style.json +564 -0
  13. package/dist/src/tokens/design-tokens/template/$metadata.json +17 -0
  14. package/dist/src/tokens/design-tokens/template/$themes.json +1231 -0
  15. package/dist/src/tokens/design-tokens/template/themes/theme.json +334 -0
  16. package/dist/src/tokens/template.js +66 -0
  17. package/dist/src/tokens/types.js +0 -0
  18. package/dist/src/tokens/write/generate$metadata.js +21 -0
  19. package/dist/src/tokens/write/generate$themes.js +115 -0
  20. package/dist/src/tokens/write.js +79 -0
  21. package/dist/types/src/tokens/build/configs.d.ts +1 -1
  22. package/dist/types/src/tokens/build/configs.d.ts.map +1 -1
  23. package/dist/types/src/tokens/build/formats/css.d.ts.map +1 -1
  24. package/dist/types/src/tokens/build/transformers.d.ts +1 -1
  25. package/dist/types/src/tokens/build/transformers.d.ts.map +1 -1
  26. package/dist/types/src/tokens/{build/index.d.ts → build.d.ts} +1 -1
  27. package/dist/types/src/tokens/build.d.ts.map +1 -0
  28. package/dist/types/src/tokens/create.d.ts +8 -0
  29. package/dist/types/src/tokens/create.d.ts.map +1 -0
  30. package/dist/types/src/tokens/template.d.ts +2 -0
  31. package/dist/types/src/tokens/template.d.ts.map +1 -0
  32. package/dist/types/src/tokens/types.d.ts +37 -0
  33. package/dist/types/src/tokens/types.d.ts.map +1 -0
  34. package/dist/types/src/tokens/write/generate$metadata.d.ts +8 -0
  35. package/dist/types/src/tokens/write/generate$metadata.d.ts.map +1 -0
  36. package/dist/types/src/tokens/write/generate$themes.d.ts +10 -0
  37. package/dist/types/src/tokens/write/generate$themes.d.ts.map +1 -0
  38. package/dist/types/src/tokens/write.d.ts +10 -0
  39. package/dist/types/src/tokens/write.d.ts.map +1 -0
  40. package/package.json +6 -5
  41. package/dist/src/tokens/create/README.md +0 -3
  42. package/dist/src/tokens/create/index.js +0 -150
  43. package/dist/src/tokens/index.js +0 -4
  44. package/dist/types/src/tokens/build/index.d.ts.map +0 -1
  45. package/dist/types/src/tokens/create/index.d.ts +0 -64
  46. package/dist/types/src/tokens/create/index.d.ts.map +0 -1
  47. package/dist/types/src/tokens/index.d.ts +0 -2
  48. 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,
@@ -1,10 +1,10 @@
1
- import { register } from "@tokens-studio/sd-transforms";
1
+ import { expandTypesMap, register } from "@tokens-studio/sd-transforms";
2
2
  import * as R from "ramda";
3
3
  import StyleDictionary from "style-dictionary";
4
4
  import { outputReferencesFilter } from "style-dictionary/utils";
5
5
  import * as formats from "./formats/css.js";
6
6
  import { jsTokens } from "./formats/js-tokens.js";
7
- import { nameKebab, sizeRem, typographyShorthand } from "./transformers.js";
7
+ import { nameKebab, sizeRem, typographyName } from "./transformers.js";
8
8
  import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
9
9
  import { pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
10
10
  void register(StyleDictionary, { withSDBuiltins: false });
@@ -15,7 +15,7 @@ const separator = "_";
15
15
  const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
16
16
  StyleDictionary.registerTransform(sizeRem);
17
17
  StyleDictionary.registerTransform(nameKebab);
18
- StyleDictionary.registerTransform(typographyShorthand);
18
+ StyleDictionary.registerTransform(typographyName);
19
19
  StyleDictionary.registerFormat(jsTokens);
20
20
  StyleDictionary.registerFormat(formats.colormode);
21
21
  StyleDictionary.registerFormat(formats.semantic);
@@ -26,7 +26,7 @@ const dsTransformers = [
26
26
  "ts/size/px",
27
27
  sizeRem.name,
28
28
  "ts/typography/fontWeight",
29
- typographyShorthand.name,
29
+ typographyName.name,
30
30
  "ts/color/modifiers",
31
31
  "ts/color/css/hexrgba",
32
32
  "ts/size/lineheight",
@@ -102,7 +102,7 @@ const semanticVariables = ({ outPath, theme }) => {
102
102
  {
103
103
  destination: `semantic.css`,
104
104
  format: formats.semantic.name,
105
- filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily"], token)
105
+ filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily", "typography"], token)
106
106
  }
107
107
  ],
108
108
  options: {
@@ -146,13 +146,17 @@ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
146
146
  }
147
147
  };
148
148
  };
149
- const typographyCSS = ({ outPath, theme, typography }) => {
149
+ const typographyVariables = ({ outPath, theme, typography }) => {
150
150
  const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
151
151
  const layer = `ds.theme.typography.${typography}`;
152
152
  return {
153
153
  usesDtcg: true,
154
154
  log: { verbosity: "silent" },
155
155
  preprocessors: ["tokens-studio"],
156
+ expand: {
157
+ include: ["typography"],
158
+ typesMap: { ...expandTypesMap, typography: { ...expandTypesMap.typography, letterSpacing: "dimension" } }
159
+ },
156
160
  platforms: {
157
161
  css: {
158
162
  prefix,
@@ -161,7 +165,14 @@ const typographyCSS = ({ outPath, theme, typography }) => {
161
165
  layer,
162
166
  buildPath: `${outPath}/${theme}/`,
163
167
  basePxFontSize,
164
- transforms: [nameKebab.name, "ts/size/px", sizeRem.name, "ts/size/lineheight", "ts/typography/fontWeight"],
168
+ transforms: [
169
+ nameKebab.name,
170
+ "ts/size/px",
171
+ sizeRem.name,
172
+ "ts/size/lineheight",
173
+ "ts/typography/fontWeight",
174
+ typographyName.name
175
+ ],
165
176
  files: [
166
177
  {
167
178
  destination: `typography/${typography}.css`,
@@ -223,5 +234,5 @@ export {
223
234
  semanticVariables,
224
235
  separator,
225
236
  typescriptTokens,
226
- typographyCSS
237
+ typographyVariables
227
238
  };
@@ -1,7 +1,6 @@
1
1
  import * as R from "ramda";
2
- import { createPropertyFormatter, fileHeader, getReferences, usesReferences } from "style-dictionary/utils";
3
- import { prefix } from "../configs.js";
4
- import { getValue, typeEquals } from "../utils/utils.js";
2
+ import { createPropertyFormatter, fileHeader, usesReferences } from "style-dictionary/utils";
3
+ import { getValue } from "../utils/utils.js";
5
4
  const prefersColorScheme = (mode, content) => `
6
5
  @media (prefers-color-scheme: ${mode}) {
7
6
  [data-ds-color-mode="auto"] ${content}
@@ -21,10 +20,12 @@ const colormode = {
21
20
  format: "css",
22
21
  usesDtcg
23
22
  });
24
- const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `color-scheme: ${mode_};
23
+ const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `
24
+ color-scheme: ${mode_};
25
25
  ` : "";
26
+ const formattedTokens = dictionary.allTokens.map(format).join("\n");
26
27
  const content = `{
27
- ${allTokens.map(format).join("\n")}
28
+ ${formattedTokens}
28
29
  ${colorSchemeProperty}}
29
30
  `;
30
31
  const autoSelectorContent = ["light", "dark"].includes(mode_) ? prefersColorScheme(mode_, content) : "";
@@ -40,7 +41,6 @@ const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}:
40
41
  const semantic = {
41
42
  name: "ds/css-semantic",
42
43
  format: async ({ dictionary, file, options, platform }) => {
43
- const { allTokens } = dictionary;
44
44
  const { outputReferences, usesDtcg } = options;
45
45
  const { selector, isCalculatedToken, layer } = platform;
46
46
  const header = await fileHeader({ file });
@@ -50,7 +50,7 @@ const semantic = {
50
50
  format: "css",
51
51
  usesDtcg
52
52
  });
53
- const formatTokens = R.map((token) => {
53
+ const formattedTokens = R.map((token) => {
54
54
  const originalValue = getValue(token.original);
55
55
  if (usesReferences(originalValue) && typeof outputReferences === "function" && outputReferences?.(token, { dictionary })) {
56
56
  if (isCalculatedToken?.(token, options)) {
@@ -58,10 +58,9 @@ const semantic = {
58
58
  }
59
59
  }
60
60
  return format(token);
61
- });
62
- const formattedVariables = formatTokens(allTokens);
61
+ }, dictionary.allTokens);
63
62
  const content = `{
64
- ${formattedVariables.join("\n")}
63
+ ${formattedTokens.join("\n")}
65
64
  }
66
65
  `;
67
66
  const body = R.isNotNil(layer) ? `@layer ${layer} {
@@ -72,28 +71,9 @@ ${selector} ${content}
72
71
  return header + body;
73
72
  }
74
73
  };
75
- const sortByType = R.sortBy((token) => token?.$type === "typography");
76
- const getVariableName = R.pipe(
77
- R.split(":"),
78
- R.head,
79
- R.defaultTo(""),
80
- R.trim,
81
- (name) => `var(${name})`
82
- );
83
- const bemify = R.pipe(
84
- (path) => {
85
- const filteredPath = path.filter((p) => p !== "typography");
86
- const withPrefix = R.concat([prefix], R.remove(0, 0, filteredPath));
87
- const [rest, last] = R.splitAt(-1, withPrefix);
88
- const className = `${rest.join("-")}--${R.head(last)}`;
89
- return className;
90
- },
91
- R.trim,
92
- R.toLower
93
- );
94
- const classSelector = R.pipe(R.prop("path"), bemify);
95
- const sortTypographyLast = R.sortWith([
96
- R.ascend((token) => typeEquals("typography")(token) ? 1 : 0)
74
+ const typographyFontFamilyPredicate = R.allPass([
75
+ R.pathSatisfies(R.includes("typography"), ["path"]),
76
+ R.pathSatisfies(R.includes("fontFamily"), ["path"])
97
77
  ]);
98
78
  const typography = {
99
79
  name: "ds/css-typography",
@@ -107,67 +87,12 @@ const typography = {
107
87
  format: "css",
108
88
  usesDtcg
109
89
  });
110
- const sortedTokens = sortTypographyLast(dictionary.allTokens);
111
- const formattedTokens = R.pipe(
112
- sortByType,
113
- R.reduce(
114
- (acc, token) => {
115
- if (typeEquals("fontweight", token)) {
116
- const className = `
117
- .${classSelector(token)} {
118
- font-weight: ${getValue(token)};
119
- }`;
120
- return Object.assign(acc, {
121
- variables: [...acc.variables, format(token)],
122
- classes: [...acc.classes, className]
123
- });
124
- }
125
- if (typeEquals("lineheight", token)) {
126
- const className = `
127
- .${classSelector(token)} {
128
- line-height: ${getValue(token)};
129
- }`;
130
- return Object.assign(acc, {
131
- variables: [...acc.variables, format(token)],
132
- classes: [...acc.classes, className]
133
- });
134
- }
135
- if (typeEquals("typography", token)) {
136
- let references = [];
137
- try {
138
- references = getReferences(getValue(token.original), dictionary.tokens);
139
- } catch (error) {
140
- console.error("Error getting references", error);
141
- throw new Error(JSON.stringify(token, null, 2));
142
- }
143
- const fontweight = R.find(typeEquals(["fontweight"]))(references);
144
- const lineheight = R.find(typeEquals(["lineheight"]))(references);
145
- const fontsize = R.find(typeEquals(["fontsize"]))(references);
146
- const letterSpacing = R.find(typeEquals(["dimension"]))(references);
147
- const fontSizeVar = fontsize ? getVariableName(format(fontsize)) : null;
148
- const fontWeightVar = fontweight ? getVariableName(format(fontweight)) : null;
149
- const lineheightVar = lineheight ? getVariableName(format(lineheight)) : null;
150
- const letterSpacingVar = letterSpacing ? getVariableName(format(letterSpacing)) : null;
151
- const className = `
152
- .${classSelector(token)} {
153
- ${fontSizeVar ? `font-size: ${fontSizeVar};` : ""}
154
- ${lineheightVar ? `line-height: ${lineheightVar};` : ""}
155
- ${fontWeightVar ? `font-weight: ${fontWeightVar};` : ""}
156
- ${letterSpacingVar ? `letter-spacing: ${letterSpacingVar};` : ""}
157
- }`;
158
- return Object.assign(acc, { classes: [className, ...acc.classes] });
159
- }
160
- return Object.assign(acc, { variables: [...acc.variables, format(token)] });
161
- },
162
- { variables: [], classes: [] }
163
- )
164
- )(sortedTokens);
165
- const classes = formattedTokens.classes.join("\n");
166
- const variables = formattedTokens.variables.join("\n");
90
+ console.log("dictionary.allTokens", dictionary.allTokens);
91
+ const filteredTokens = R.reject(typographyFontFamilyPredicate, dictionary.allTokens);
92
+ const formattedTokens = R.pipe(R.map(format), R.join("\n"))(filteredTokens);
167
93
  const content = selector ? `${selector} {
168
- ${variables}
169
- ${classes}
170
- }` : classes;
94
+ ${formattedTokens}
95
+ }` : formattedTokens;
171
96
  const body = R.isNotNil(layer) ? `@layer ${layer} {
172
97
  ${content}
173
98
  }` : content;
@@ -34,18 +34,18 @@ const nameKebab = {
34
34
  });
35
35
  }
36
36
  };
37
- const typographyShorthand = {
38
- name: "typography/shorthand",
39
- type: "value",
37
+ const typographyName = {
38
+ name: "name/typography",
39
+ type: "name",
40
40
  transitive: true,
41
- filter: (token) => typeEquals("typography", token),
41
+ // expanded tokens have different type so we match on path instead
42
+ filter: (token) => pathStartsWithOneOf(["typography"], token),
42
43
  transform: (token) => {
43
- const typography = getValue(token);
44
- return `${typography.fontWeight} ${typography.fontSize}/${typography.lineHeight} '${typography.fontFamily}'`;
44
+ return token.name.replace("-typography", "");
45
45
  }
46
46
  };
47
47
  export {
48
48
  nameKebab,
49
49
  sizeRem,
50
- typographyShorthand
50
+ typographyName
51
51
  };
@@ -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) {
@@ -23,7 +23,7 @@ async function buildTokens(options) {
23
23
  const semanticThemes = R.filter((val) => val.mode === "light" && val.typography === "primary", themes);
24
24
  const colorModeConfigs = getConfigs(configs.colorModeVariables, outPath, tokensDir, colormodeThemes);
25
25
  const semanticConfigs = getConfigs(configs.semanticVariables, outPath, tokensDir, semanticThemes);
26
- const typographyConfigs = getConfigs(configs.typographyCSS, outPath, tokensDir, typographyThemes);
26
+ const typographyConfigs = getConfigs(configs.typographyVariables, outPath, tokensDir, typographyThemes);
27
27
  const storefrontConfigs = getConfigs(configs.typescriptTokens, storefrontOutDir, tokensDir, colormodeThemes);
28
28
  if (typographyConfigs.length > 0) {
29
29
  console.log(`
@@ -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
+ }