@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/tokens/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAEtD,MAAM,MAAM,KAAK,GAAG;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC;AACtD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;AAC/C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;AACpD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC;AACpE,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAE7D,MAAM,MAAM,eAAe,GAAG;IAC5B,MAAM,EAAE,SAAS,CAAC;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,SAAS,CAAC;CAC1B,CAAC;AAGF,MAAM,MAAM,gBAAgB,GAAG,SAAS,CAAC;AAGzC,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE;QACN,KAAK,EAAE,eAAe,CAAC;QACvB,IAAI,EAAE,eAAe,CAAC;QACtB,QAAQ,EAAE,eAAe,CAAC;KAC3B,CAAC;IACF,UAAU,EAAE;QACV,OAAO,EAAE,SAAS,CAAC;KACpB,CAAC;CACH,CAAC;AAEF,MAAM,MAAM,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AACnD,MAAM,MAAM,UAAU,GAAG;IAAE,UAAU,CAAC,EAAE,MAAM,CAAA;CAAE,CAAC;AACjD,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,WAAW,CAAC;AAEtD,MAAM,MAAM,IAAI,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,QAAQ,CAAC"}
@@ -0,0 +1,8 @@
1
+ import type { ColorMode } from '../../colors/types.js';
2
+ type ColorModes = Array<ColorMode>;
3
+ type Metadata = {
4
+ tokenSetOrder: string[];
5
+ };
6
+ export declare function generateMetadataJson(modes: ColorModes, themes: string[]): Metadata;
7
+ export {};
8
+ //# sourceMappingURL=generate$metadata.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate$metadata.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/write/generate$metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD,KAAK,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AAEnC,KAAK,QAAQ,GAAG;IACd,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,QAAQ,CAiBlF"}
@@ -0,0 +1,10 @@
1
+ import { type ThemeObject } from '@tokens-studio/types';
2
+ import type { ColorMode } from '../../colors/types.js';
3
+ type ColorModes = Array<ColorMode>;
4
+ type ThemeObject_ = ThemeObject & {
5
+ $figmaCollectionId?: string;
6
+ $figmaModeId?: string;
7
+ };
8
+ export declare function generateThemesJson(modes: ColorModes, themes: string[]): ThemeObject_[];
9
+ export {};
10
+ //# sourceMappingURL=generate$themes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate$themes.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/write/generate$themes.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,WAAW,EAAkB,MAAM,sBAAsB,CAAC;AAExE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAQvD,KAAK,UAAU,GAAG,KAAK,CAAC,SAAS,CAAC,CAAC;AAEnC,KAAK,YAAY,GAAG,WAAW,GAAG;IAChC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAEF,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,YAAY,EAAE,CAQtF"}
@@ -0,0 +1,10 @@
1
+ import type { Tokens } from './types.js';
2
+ export declare const stringify: (data: unknown) => string;
3
+ type WriteTokensOptions = {
4
+ writeDir: string;
5
+ tokens: Tokens;
6
+ themeName: string;
7
+ };
8
+ export declare const writeTokens: (options: WriteTokensOptions) => Promise<void>;
9
+ export {};
10
+ //# sourceMappingURL=write.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"write.d.ts","sourceRoot":"","sources":["../../../../src/tokens/write.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAoB,MAAM,EAA8B,MAAM,YAAY,CAAC;AAQvF,eAAO,MAAM,SAAS,SAAU,OAAO,WAAkC,CAAC;AAyB1E,KAAK,kBAAkB,GAAG;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,WAAW,YAAmB,kBAAkB,kBA6D5D,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "0.1.0-next.31",
3
+ "version": "1.0.0-next.33",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "repository": {
@@ -20,9 +20,9 @@
20
20
  "types": "./dist/types/src/colors/index.d.ts",
21
21
  "import": "./dist/src/colors/index.js"
22
22
  },
23
- "./tokens": {
24
- "types": "./dist/types/src/tokens/index.d.ts",
25
- "import": "./dist/src/tokens/index.js"
23
+ "./tokens/*": {
24
+ "types": "./dist/types/src/tokens/*",
25
+ "import": "./dist/src/tokens/*"
26
26
  }
27
27
  },
28
28
  "publishConfig": {
@@ -36,7 +36,8 @@
36
36
  "build:swc": "yarn clean && swc src bin --copy-files -d dist && yarn build:types",
37
37
  "build:types": "tsc --emitDeclarationOnly --declaration",
38
38
  "clean": "rimraf dist",
39
- "clean:theme": "yarn workspace @digdir/designsystemet-theme clean"
39
+ "clean:theme": "yarn workspace @digdir/designsystemet-theme clean",
40
+ "update:template": "tsx ./src/tokens/template.ts"
40
41
  },
41
42
  "dependencies": {
42
43
  "@adobe/leonardo-contrast-colors": "^1.0.0",
@@ -1,3 +0,0 @@
1
- ```sh
2
- yarn workspace @digdir/designsystemet designsystemet tokens create --accent AD00BA --neutral 749ACB --brand1 D03539 --brand2 20E53A --brand3 F2F51E --font-family Arial --write ./../../../sandbox/test-tokens-august/design-tokens
3
- ```
@@ -1,150 +0,0 @@
1
- import fs from "node:fs/promises";
2
- import path from "node:path";
3
- import * as R from "ramda";
4
- import { baseColors, generateScaleForColor } from "../../colors/index.js";
5
- import generateMetadataJson from "../../init/generateMetadataJson.js";
6
- import generateThemesJson from "../../init/generateThemesJson.js";
7
- const DIRNAME = import.meta.dirname || __dirname;
8
- const DEFAULT_FILES_PATH = path.join(DIRNAME, "../../init/template/default-files/design-tokens/");
9
- const createColorTokens = (colorArray) => {
10
- const obj = {};
11
- const $type = "color";
12
- for (let i = 0; i < colorArray.length; i++) {
13
- if (i === 13 && colorArray.length >= 14) {
14
- obj["contrast-1"] = {
15
- $type,
16
- $value: colorArray[i].hex
17
- };
18
- } else if (i === 14 && colorArray.length >= 15) {
19
- obj["contrast-2"] = {
20
- $type,
21
- $value: colorArray[i].hex
22
- };
23
- } else {
24
- obj[i + 1] = { $type, $value: colorArray[i].hex };
25
- }
26
- }
27
- return obj;
28
- };
29
- const generateTypographyTokens = ({ family }) => {
30
- return {
31
- theme: {
32
- main: {
33
- $type: "fontFamilies",
34
- $value: family
35
- },
36
- bold: {
37
- $type: "fontWeights",
38
- $value: "Medium"
39
- },
40
- "extra-bold": {
41
- $type: "fontWeights",
42
- $value: "Semi bold"
43
- },
44
- regular: {
45
- $type: "fontWeights",
46
- $value: "Regular"
47
- }
48
- }
49
- };
50
- };
51
- const generateThemeTokens = (theme, colors) => {
52
- const accentColors = generateScaleForColor(colors.accent, theme);
53
- const neutralColors = generateScaleForColor(colors.neutral, theme);
54
- const brand1Colors = generateScaleForColor(colors.brand1, theme);
55
- const brand2Colors = generateScaleForColor(colors.brand2, theme);
56
- const brand3Colors = generateScaleForColor(colors.brand3, theme);
57
- return {
58
- theme: {
59
- accent: createColorTokens(accentColors),
60
- neutral: createColorTokens(neutralColors),
61
- brand1: createColorTokens(brand1Colors),
62
- brand2: createColorTokens(brand2Colors),
63
- brand3: createColorTokens(brand3Colors)
64
- }
65
- };
66
- };
67
- const generateColorModeFile = (folder, name, tokens, outPath) => {
68
- const path2 = `${outPath}/primitives/modes/colors/${folder}`;
69
- return {
70
- data: JSON.stringify(tokens, null, 2),
71
- path: path2,
72
- filePath: `${path2}/${name}.json`
73
- };
74
- };
75
- const generateTypographyFile = (folder, name, tokens, outPath) => {
76
- const path2 = `${outPath}/primitives/modes/typography/${folder}`;
77
- return {
78
- data: JSON.stringify(tokens, null, 2),
79
- path: path2,
80
- filePath: `${path2}/${name}.json`
81
- };
82
- };
83
- const generateGlobalTokens = (theme) => {
84
- const blueScale = generateScaleForColor(baseColors.blue, theme);
85
- const greenScale = generateScaleForColor(baseColors.green, theme);
86
- const orangeScale = generateScaleForColor(baseColors.orange, theme);
87
- const purpleScale = generateScaleForColor(baseColors.purple, theme);
88
- const redScale = generateScaleForColor(baseColors.red, theme);
89
- const yellowScale = generateScaleForColor(baseColors.yellow, theme);
90
- return {
91
- global: {
92
- blue: createColorTokens(blueScale),
93
- green: createColorTokens(greenScale),
94
- orange: createColorTokens(orangeScale),
95
- purple: createColorTokens(purpleScale),
96
- red: createColorTokens(redScale),
97
- yellow: createColorTokens(yellowScale)
98
- }
99
- };
100
- };
101
- const createTokens = async (opts) => {
102
- const { colors, write, typography } = opts;
103
- const tokens = {
104
- colors: {
105
- light: {
106
- theme: generateThemeTokens("light", colors),
107
- global: generateGlobalTokens("light")
108
- },
109
- dark: { theme: generateThemeTokens("dark", colors), global: generateGlobalTokens("dark") },
110
- contrast: { theme: generateThemeTokens("contrast", colors), global: generateGlobalTokens("contrast") }
111
- },
112
- typography: {
113
- primary: generateTypographyTokens(typography)
114
- }
115
- };
116
- if (R.isNotNil(write)) {
117
- const targetDir = path.resolve(process.cwd(), String(write));
118
- await fs.mkdir(targetDir, { recursive: true });
119
- console.log("Generating metadata and themes files");
120
- const $theme = generateThemesJson(["Light", "Dark", "Contrast"], ["theme"]);
121
- const $metadata = generateMetadataJson(["Light", "Dark", "Contrast"], ["theme"]);
122
- await fs.writeFile(path.join(targetDir, "$themes.json"), JSON.stringify($theme, null, 2));
123
- await fs.writeFile(path.join(targetDir, "$metadata.json"), JSON.stringify($metadata, null, 2));
124
- console.log(`Copying default files to ${targetDir}`);
125
- await fs.cp(DEFAULT_FILES_PATH, targetDir, {
126
- recursive: true
127
- });
128
- const files = [
129
- generateColorModeFile("light", "theme", tokens.colors.light.theme, targetDir),
130
- generateColorModeFile("light", "global", tokens.colors.light.global, targetDir),
131
- generateColorModeFile("dark", "theme", tokens.colors.dark.theme, targetDir),
132
- generateColorModeFile("dark", "global", tokens.colors.dark.global, targetDir),
133
- generateColorModeFile("contrast", "theme", tokens.colors.contrast.theme, targetDir),
134
- generateColorModeFile("contrast", "global", tokens.colors.contrast.global, targetDir),
135
- generateTypographyFile("primary", "theme", tokens.typography.primary, targetDir),
136
- generateTypographyFile("secondary", "theme", tokens.typography.primary, targetDir)
137
- ];
138
- for (const file of files) {
139
- const dirPath = path.resolve(file.path);
140
- const filePath = path.resolve(file.filePath);
141
- console.log(`Writing file ${filePath}`);
142
- await fs.mkdir(dirPath, { recursive: true });
143
- await fs.writeFile(filePath, file.data, { encoding: "utf-8" });
144
- }
145
- }
146
- return tokens;
147
- };
148
- export {
149
- createTokens
150
- };
@@ -1,4 +0,0 @@
1
- import { createTokens } from "./create/index.js";
2
- export {
3
- createTokens
4
- };
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/index.ts"],"names":[],"mappings":"AAaA,KAAK,OAAO,GAAG;IACb,0BAA0B;IAC1B,MAAM,EAAE,MAAM,CAAC;IACf,wCAAwC;IACxC,GAAG,EAAE,MAAM,CAAC;IACZ,8BAA8B;IAC9B,OAAO,EAAE,OAAO,CAAC;CAClB,CAAC;AAMF,wBAAsB,WAAW,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,CA4FjE"}
@@ -1,64 +0,0 @@
1
- import type { CssColor } from '@adobe/leonardo-contrast-colors';
2
- import type { ThemeColors } from '../../colors/index.js';
3
- type Colors = Record<ThemeColors, CssColor>;
4
- type Typography = Record<string, string>;
5
- type CreateTokens = {
6
- colors: Colors;
7
- typography: Typography;
8
- write?: string;
9
- };
10
- type DesignTokens = Record<string, {
11
- $value: string;
12
- $type: string;
13
- }>;
14
- type Tokens2ary = Record<string, Record<string, DesignTokens>>;
15
- type Tokens1ary = Record<string, DesignTokens>;
16
- type Tokens = Tokens1ary | Tokens2ary;
17
- export declare const createTokens: (opts: CreateTokens) => Promise<{
18
- colors: {
19
- light: {
20
- theme: Tokens;
21
- global: {
22
- global: {
23
- blue: DesignTokens;
24
- green: DesignTokens;
25
- orange: DesignTokens;
26
- purple: DesignTokens;
27
- red: DesignTokens;
28
- yellow: DesignTokens;
29
- };
30
- };
31
- };
32
- dark: {
33
- theme: Tokens;
34
- global: {
35
- global: {
36
- blue: DesignTokens;
37
- green: DesignTokens;
38
- orange: DesignTokens;
39
- purple: DesignTokens;
40
- red: DesignTokens;
41
- yellow: DesignTokens;
42
- };
43
- };
44
- };
45
- contrast: {
46
- theme: Tokens;
47
- global: {
48
- global: {
49
- blue: DesignTokens;
50
- green: DesignTokens;
51
- orange: DesignTokens;
52
- purple: DesignTokens;
53
- red: DesignTokens;
54
- yellow: DesignTokens;
55
- };
56
- };
57
- };
58
- };
59
- typography: {
60
- primary: Tokens;
61
- };
62
- }>;
63
- export {};
64
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/create/index.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAGhE,OAAO,KAAK,EAAwB,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAI/E,KAAK,MAAM,GAAG,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;AAC5C,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAGzC,KAAK,YAAY,GAAG;IAClB,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,CAAC;AAQF,KAAK,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,KAAK,EAAE,MAAM,CAAA;CAAE,CAAC,CAAC;AACtE,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC,CAAC;AAC/D,KAAK,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,CAAC;AAC/C,KAAK,MAAM,GAAG,UAAU,GAAG,UAAU,CAAC;AA2GtC,eAAO,MAAM,YAAY,SAAgB,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAuDpD,CAAC"}
@@ -1,2 +0,0 @@
1
- export { createTokens } from './create/index.js';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/tokens/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC"}