@digdir/designsystemet 0.1.0-alpha.14 → 0.1.0-alpha.15

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 (67) hide show
  1. package/dist/bin/designsystemet.js +32 -3439
  2. package/dist/src/colors/colorUtils.js +301 -343
  3. package/dist/src/colors/index.js +3 -607
  4. package/dist/src/colors/themeUtils.js +319 -348
  5. package/dist/src/colors/types.js +1 -1
  6. package/dist/src/init/createTokensPackage.js +230 -0
  7. package/dist/src/init/generateMetadataJson.js +16 -0
  8. package/dist/src/init/generateThemesJson.js +50 -0
  9. package/dist/src/init/index.js +7 -0
  10. package/dist/src/init/nextStepsMarkdown.js +90 -0
  11. package/dist/src/init/template/default-files/README.md +10 -0
  12. package/dist/src/init/template/default-files/design-tokens/README.md +3 -0
  13. package/dist/src/init/template/default-files/design-tokens/primitives/globals.json +197 -0
  14. package/dist/src/init/template/default-files/design-tokens/primitives/typography/default.json +86 -0
  15. package/dist/src/init/template/default-files/design-tokens/semantic/color.json +562 -0
  16. package/dist/src/init/template/default-files/design-tokens/semantic/style.json +543 -0
  17. package/dist/src/init/template/prettier.config.js +7 -0
  18. package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/global.json +376 -0
  19. package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/theme-template.json +314 -0
  20. package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/global.json +376 -0
  21. package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/theme-template.json +314 -0
  22. package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/global.json +376 -0
  23. package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/theme-template.json +314 -0
  24. package/dist/src/init/template/template-files/design-tokens/themes/theme-template.json +314 -0
  25. package/dist/src/init/template/template-files/package.json +23 -0
  26. package/dist/src/init/utils.js +11 -0
  27. package/dist/src/migrations/beta-to-v1.js +341 -407
  28. package/dist/src/migrations/codemods/css/plugins.js +36 -42
  29. package/dist/src/migrations/codemods/css/run.js +20 -17
  30. package/dist/src/migrations/codemods/jsx/classname-prefix.js +63 -59
  31. package/dist/src/migrations/codemods/jsx/run.js +20 -20
  32. package/dist/src/migrations/index.js +5 -436
  33. package/dist/src/migrations/react-beta-to-v1.js +4 -27
  34. package/dist/src/test/a.css +39 -0
  35. package/dist/src/test/jsx-test.js +12 -0
  36. package/dist/src/tokens/actions.js +23 -2176
  37. package/dist/src/tokens/build.js +54 -2974
  38. package/dist/src/tokens/configs.js +234 -2874
  39. package/dist/src/tokens/formats/css.js +153 -2632
  40. package/dist/src/tokens/formats/js-tokens.js +28 -42
  41. package/dist/src/tokens/transformers.js +44 -82
  42. package/dist/src/tokens/utils/noCase.js +26 -28
  43. package/dist/src/tokens/utils/permutateThemes.js +65 -217
  44. package/dist/src/tokens/utils/utils.js +25 -14
  45. package/package.json +9 -18
  46. package/LICENSE +0 -7
  47. package/dist/bin/designsystemet.js.map +0 -1
  48. package/dist/src/colors/colorUtils.js.map +0 -1
  49. package/dist/src/colors/index.js.map +0 -1
  50. package/dist/src/colors/themeUtils.js.map +0 -1
  51. package/dist/src/colors/types.js.map +0 -1
  52. package/dist/src/migrations/beta-to-v1.js.map +0 -1
  53. package/dist/src/migrations/codemods/css/plugins.js.map +0 -1
  54. package/dist/src/migrations/codemods/css/run.js.map +0 -1
  55. package/dist/src/migrations/codemods/jsx/classname-prefix.js.map +0 -1
  56. package/dist/src/migrations/codemods/jsx/run.js.map +0 -1
  57. package/dist/src/migrations/index.js.map +0 -1
  58. package/dist/src/migrations/react-beta-to-v1.js.map +0 -1
  59. package/dist/src/tokens/actions.js.map +0 -1
  60. package/dist/src/tokens/build.js.map +0 -1
  61. package/dist/src/tokens/configs.js.map +0 -1
  62. package/dist/src/tokens/formats/css.js.map +0 -1
  63. package/dist/src/tokens/formats/js-tokens.js.map +0 -1
  64. package/dist/src/tokens/transformers.js.map +0 -1
  65. package/dist/src/tokens/utils/noCase.js.map +0 -1
  66. package/dist/src/tokens/utils/permutateThemes.js.map +0 -1
  67. package/dist/src/tokens/utils/utils.js.map +0 -1
@@ -1,44 +1,30 @@
1
- // src/tokens/formats/js-tokens.ts
2
- import * as R2 from "ramda";
3
- import { fileHeader, createPropertyFormatter } from "style-dictionary/utils";
4
-
5
- // src/tokens/utils/utils.ts
6
1
  import * as R from "ramda";
7
- var getType = (token) => (token.$type ?? token.type) || "";
8
- var typeEquals = R.curry((types, token) => {
9
- if (R.isNil(token)) {
10
- return false;
11
- }
12
- return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
13
- });
14
-
15
- // src/tokens/formats/js-tokens.ts
16
- var groupByType = R2.groupBy((token) => getType(token));
17
- var removeUnwatedTokens = R2.filter(
18
- (token) => !["fds-base_spacing", "fds-base_sizing"].includes(token.name)
19
- );
20
- var toCssVarName = R2.pipe(R2.split(":"), R2.head, R2.trim);
21
- var jsTokens = {
22
- name: "ds/js-tokens",
23
- format: async function({ dictionary, file }) {
24
- const format = createPropertyFormatter({
25
- dictionary,
26
- format: "css"
27
- });
28
- const formatTokens = R2.map((token) => ({
29
- ...token,
30
- name: toCssVarName(format(token))
31
- }));
32
- const processTokens = R2.pipe(removeUnwatedTokens, formatTokens, groupByType);
33
- const tokens = processTokens(dictionary.allTokens);
34
- const content = Object.entries(tokens).map(
35
- ([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
36
- `
37
- ).join("\n");
38
- return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
39
- }
40
- };
41
- export {
42
- jsTokens
2
+ import { fileHeader, createPropertyFormatter } from "style-dictionary/utils";
3
+ import { getType } from "../utils/utils.js";
4
+ const groupByType = R.groupBy((token)=>getType(token));
5
+ /** Add token name with prefix to list for removal */ const removeUnwatedTokens = R.filter((token)=>![
6
+ 'fds-base_spacing',
7
+ 'fds-base_sizing'
8
+ ].includes(token.name));
9
+ const toCssVarName = R.pipe(R.split(':'), R.head, R.trim);
10
+ /**
11
+ * Format for displaying tokens in storefront
12
+ */ export const jsTokens = {
13
+ name: 'ds/js-tokens',
14
+ format: async function({ dictionary, file }) {
15
+ const format = createPropertyFormatter({
16
+ dictionary,
17
+ format: 'css'
18
+ });
19
+ const formatTokens = R.map((token)=>({
20
+ ...token,
21
+ name: toCssVarName(format(token))
22
+ }));
23
+ const processTokens = R.pipe(removeUnwatedTokens, formatTokens, groupByType);
24
+ const tokens = processTokens(dictionary.allTokens);
25
+ const content = Object.entries(tokens).map(([name, token])=>`export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, '$1:')} \n`).join('\n');
26
+ return fileHeader({
27
+ file
28
+ }).then((fileHeaderText)=>fileHeaderText + content);
29
+ }
43
30
  };
44
- //# sourceMappingURL=js-tokens.js.map
@@ -1,87 +1,49 @@
1
- // src/tokens/transformers.ts
2
- import * as R2 from "ramda";
3
-
4
- // src/tokens/utils/noCase.ts
5
- var lowerCase = (text = "") => text.toLowerCase();
6
- var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
7
- var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
8
- function noCase(input, options = {}) {
9
- const {
10
- splitRegexp = DEFAULT_SPLIT_REGEXP,
11
- stripRegexp = DEFAULT_STRIP_REGEXP,
12
- transform = lowerCase,
13
- delimiter = " "
14
- } = options;
15
- const result = replace(
16
- replace(input, splitRegexp, "$1\0$2"),
17
- stripRegexp,
18
- "\0"
19
- );
20
- let start = 0;
21
- let end = result.length;
22
- while (result.charAt(start) === "\0") start++;
23
- while (result.charAt(end - 1) === "\0") end--;
24
- return result.slice(start, end).split("\0").map(transform).join(delimiter);
25
- }
26
- function replace(input, re, value) {
27
- if (re instanceof RegExp) return input.replace(re, value);
28
- return re.reduce((input2, re2) => input2.replace(re2, value), input);
29
- }
30
-
31
- // src/tokens/utils/utils.ts
32
1
  import * as R from "ramda";
33
- var getType = (token) => (token.$type ?? token.type) || "";
34
- var getValue = (token) => token.$value ?? token.value;
35
- var typeEquals = R.curry((types, token) => {
36
- if (R.isNil(token)) {
37
- return false;
38
- }
39
- return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
40
- });
41
-
42
- // src/tokens/transformers.ts
43
- var isPx = R2.test(/\b\d+px\b/g);
44
- var sizeRem = {
45
- name: "ds/size/toRem",
46
- type: "value",
47
- transitive: true,
48
- filter: (token) => typeEquals(["sizing", "spacing", "borderRadius", "fontsizes"], token),
49
- transform: (token, config) => {
50
- const value = getValue(token);
51
- if (isPx(value)) {
52
- const baseFont = config.basePxFontSize || 16;
53
- const size = parseInt(value);
54
- if (size === 0) {
55
- return "0";
56
- }
57
- return `${size / baseFont}rem`;
2
+ import { noCase } from "./utils/noCase.js";
3
+ import { getValue, typeEquals } from "./utils/utils.js";
4
+ const isPx = R.test(/\b\d+px\b/g);
5
+ export const sizeRem = {
6
+ name: 'ds/size/toRem',
7
+ type: 'value',
8
+ transitive: true,
9
+ filter: (token)=>typeEquals([
10
+ 'sizing',
11
+ 'spacing',
12
+ 'borderRadius',
13
+ 'fontsizes'
14
+ ], token),
15
+ transform: (token, config)=>{
16
+ const value = getValue(token);
17
+ if (isPx(value)) {
18
+ const baseFont = config.basePxFontSize || 16;
19
+ const size = parseInt(value);
20
+ if (size === 0) {
21
+ return '0';
22
+ }
23
+ return `${size / baseFont}rem`;
24
+ }
25
+ return value;
58
26
  }
59
- return value;
60
- }
61
27
  };
62
- var nameKebab = {
63
- name: "name/cti/hierarchical-kebab",
64
- type: "name",
65
- transform: (token, options) => {
66
- return noCase([options?.prefix].concat(token.path).join("-"), {
67
- delimiter: "-",
68
- stripRegexp: /[^A-Z0-9_]+/gi
69
- });
70
- }
71
- };
72
- var typographyShorthand = {
73
- name: "typography/shorthand",
74
- type: "value",
75
- transitive: true,
76
- filter: (token) => token.type === "typography",
77
- transform: (token) => {
78
- const typography = getValue(token);
79
- return `${typography.fontWeight} ${typography.fontSize}/${typography.lineHeight} '${typography.fontFamily}'`;
80
- }
28
+ export const nameKebab = {
29
+ name: 'name/cti/hierarchical-kebab',
30
+ type: 'name',
31
+ transform: (token, options)=>{
32
+ return noCase([
33
+ options?.prefix
34
+ ].concat(token.path).join('-'), {
35
+ delimiter: '-',
36
+ stripRegexp: /[^A-Z0-9_]+/gi
37
+ });
38
+ }
81
39
  };
82
- export {
83
- nameKebab,
84
- sizeRem,
85
- typographyShorthand
40
+ export const typographyShorthand = {
41
+ name: 'typography/shorthand',
42
+ type: 'value',
43
+ transitive: true,
44
+ filter: (token)=>token.type === 'typography',
45
+ transform: (token)=>{
46
+ const typography = getValue(token);
47
+ return `${typography.fontWeight} ${typography.fontSize}/${typography.lineHeight} '${typography.fontFamily}'`;
48
+ }
86
49
  };
87
- //# sourceMappingURL=transformers.js.map
@@ -1,30 +1,28 @@
1
- // src/tokens/utils/noCase.ts
2
- var lowerCase = (text = "") => text.toLowerCase();
3
- var DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
4
- var DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
5
- function noCase(input, options = {}) {
6
- const {
7
- splitRegexp = DEFAULT_SPLIT_REGEXP,
8
- stripRegexp = DEFAULT_STRIP_REGEXP,
9
- transform = lowerCase,
10
- delimiter = " "
11
- } = options;
12
- const result = replace(
13
- replace(input, splitRegexp, "$1\0$2"),
14
- stripRegexp,
15
- "\0"
16
- );
17
- let start = 0;
18
- let end = result.length;
19
- while (result.charAt(start) === "\0") start++;
20
- while (result.charAt(end - 1) === "\0") end--;
21
- return result.slice(start, end).split("\0").map(transform).join(delimiter);
1
+ // Copied from https://github.com/blakeembrey/change-case/blob/change-case%404.1.2/packages/no-case/src/index.ts
2
+ const lowerCase = (text = '')=>text.toLowerCase();
3
+ // Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
4
+ const DEFAULT_SPLIT_REGEXP = [
5
+ /([a-z0-9])([A-Z])/g,
6
+ /([A-Z])([A-Z][a-z])/g
7
+ ];
8
+ // Remove all non-word characters.
9
+ const DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
10
+ /**
11
+ * Normalize the string into something other libraries can manipulate easier.
12
+ */ export function noCase(input, options = {}) {
13
+ const { splitRegexp = DEFAULT_SPLIT_REGEXP, stripRegexp = DEFAULT_STRIP_REGEXP, transform = lowerCase, delimiter = ' ' } = options;
14
+ const result = replace(replace(input, splitRegexp, '$1\0$2'), stripRegexp, '\0');
15
+ let start = 0;
16
+ let end = result.length;
17
+ // Trim the delimiter from around the output string.
18
+ while(result.charAt(start) === '\0')start++;
19
+ while(result.charAt(end - 1) === '\0')end--;
20
+ // Transform each token independently.
21
+ return result.slice(start, end).split('\0').map(transform).join(delimiter);
22
22
  }
23
- function replace(input, re, value) {
24
- if (re instanceof RegExp) return input.replace(re, value);
25
- return re.reduce((input2, re2) => input2.replace(re2, value), input);
23
+ /**
24
+ * Replace `re` in the input string with the replacement value.
25
+ */ function replace(input, re, value) {
26
+ if (re instanceof RegExp) return input.replace(re, value);
27
+ return re.reduce((input, re)=>input.replace(re, value), input);
26
28
  }
27
- export {
28
- noCase
29
- };
30
- //# sourceMappingURL=noCase.js.map
@@ -1,229 +1,77 @@
1
- // src/tokens/utils/permutateThemes.ts
2
1
  import * as R from "ramda";
3
-
4
- // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
5
- var BoxShadowTypes;
6
- (function(BoxShadowTypes2) {
7
- BoxShadowTypes2["DROP_SHADOW"] = "dropShadow";
8
- BoxShadowTypes2["INNER_SHADOW"] = "innerShadow";
9
- })(BoxShadowTypes || (BoxShadowTypes = {}));
10
-
11
- // ../../node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
12
- var ColorModifierTypes;
13
- (function(ColorModifierTypes2) {
14
- ColorModifierTypes2["LIGHTEN"] = "lighten";
15
- ColorModifierTypes2["DARKEN"] = "darken";
16
- ColorModifierTypes2["MIX"] = "mix";
17
- ColorModifierTypes2["ALPHA"] = "alpha";
18
- })(ColorModifierTypes || (ColorModifierTypes = {}));
19
-
20
- // ../../node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
21
- var ColorSpaceTypes;
22
- (function(ColorSpaceTypes2) {
23
- ColorSpaceTypes2["LCH"] = "lch";
24
- ColorSpaceTypes2["SRGB"] = "srgb";
25
- ColorSpaceTypes2["P3"] = "p3";
26
- ColorSpaceTypes2["HSL"] = "hsl";
27
- })(ColorSpaceTypes || (ColorSpaceTypes = {}));
28
-
29
- // ../../node_modules/@tokens-studio/types/dist/constants/Properties.js
30
- var Properties;
31
- (function(Properties2) {
32
- Properties2["sizing"] = "sizing";
33
- Properties2["height"] = "height";
34
- Properties2["width"] = "width";
35
- Properties2["spacing"] = "spacing";
36
- Properties2["verticalPadding"] = "verticalPadding";
37
- Properties2["horizontalPadding"] = "horizontalPadding";
38
- Properties2["paddingTop"] = "paddingTop";
39
- Properties2["paddingRight"] = "paddingRight";
40
- Properties2["paddingBottom"] = "paddingBottom";
41
- Properties2["paddingLeft"] = "paddingLeft";
42
- Properties2["itemSpacing"] = "itemSpacing";
43
- Properties2["fill"] = "fill";
44
- Properties2["backgroundBlur"] = "backgroundBlur";
45
- Properties2["border"] = "border";
46
- Properties2["borderTop"] = "borderTop";
47
- Properties2["borderRight"] = "borderRight";
48
- Properties2["borderBottom"] = "borderBottom";
49
- Properties2["borderLeft"] = "borderLeft";
50
- Properties2["borderColor"] = "borderColor";
51
- Properties2["borderRadius"] = "borderRadius";
52
- Properties2["borderRadiusTopLeft"] = "borderRadiusTopLeft";
53
- Properties2["borderRadiusTopRight"] = "borderRadiusTopRight";
54
- Properties2["borderRadiusBottomRight"] = "borderRadiusBottomRight";
55
- Properties2["borderRadiusBottomLeft"] = "borderRadiusBottomLeft";
56
- Properties2["borderWidth"] = "borderWidth";
57
- Properties2["borderWidthTop"] = "borderWidthTop";
58
- Properties2["borderWidthRight"] = "borderWidthRight";
59
- Properties2["borderWidthBottom"] = "borderWidthBottom";
60
- Properties2["borderWidthLeft"] = "borderWidthLeft";
61
- Properties2["boxShadow"] = "boxShadow";
62
- Properties2["opacity"] = "opacity";
63
- Properties2["fontFamilies"] = "fontFamilies";
64
- Properties2["fontWeights"] = "fontWeights";
65
- Properties2["fontSizes"] = "fontSizes";
66
- Properties2["lineHeights"] = "lineHeights";
67
- Properties2["typography"] = "typography";
68
- Properties2["composition"] = "composition";
69
- Properties2["letterSpacing"] = "letterSpacing";
70
- Properties2["paragraphSpacing"] = "paragraphSpacing";
71
- Properties2["textCase"] = "textCase";
72
- Properties2["dimension"] = "dimension";
73
- Properties2["textDecoration"] = "textDecoration";
74
- Properties2["asset"] = "asset";
75
- Properties2["tokenValue"] = "tokenValue";
76
- Properties2["value"] = "value";
77
- Properties2["tokenName"] = "tokenName";
78
- Properties2["description"] = "description";
79
- })(Properties || (Properties = {}));
80
-
81
- // ../../node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
82
- var TokenSetStatus;
83
- (function(TokenSetStatus2) {
84
- TokenSetStatus2["DISABLED"] = "disabled";
85
- TokenSetStatus2["SOURCE"] = "source";
86
- TokenSetStatus2["ENABLED"] = "enabled";
87
- })(TokenSetStatus || (TokenSetStatus = {}));
88
-
89
- // ../../node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
90
- var TokenTypes;
91
- (function(TokenTypes2) {
92
- TokenTypes2["OTHER"] = "other";
93
- TokenTypes2["COLOR"] = "color";
94
- TokenTypes2["BORDER_RADIUS"] = "borderRadius";
95
- TokenTypes2["SIZING"] = "sizing";
96
- TokenTypes2["SPACING"] = "spacing";
97
- TokenTypes2["TEXT"] = "text";
98
- TokenTypes2["TYPOGRAPHY"] = "typography";
99
- TokenTypes2["OPACITY"] = "opacity";
100
- TokenTypes2["BORDER_WIDTH"] = "borderWidth";
101
- TokenTypes2["STROKE_STYLE"] = "strokeStyle";
102
- TokenTypes2["BOX_SHADOW"] = "boxShadow";
103
- TokenTypes2["FONT_FAMILIES"] = "fontFamilies";
104
- TokenTypes2["FONT_WEIGHTS"] = "fontWeights";
105
- TokenTypes2["LINE_HEIGHTS"] = "lineHeights";
106
- TokenTypes2["FONT_SIZES"] = "fontSizes";
107
- TokenTypes2["LETTER_SPACING"] = "letterSpacing";
108
- TokenTypes2["PARAGRAPH_SPACING"] = "paragraphSpacing";
109
- TokenTypes2["PARAGRAPH_INDENT"] = "paragraphIndent";
110
- TokenTypes2["TEXT_DECORATION"] = "textDecoration";
111
- TokenTypes2["TEXT_CASE"] = "textCase";
112
- TokenTypes2["COMPOSITION"] = "composition";
113
- TokenTypes2["DIMENSION"] = "dimension";
114
- TokenTypes2["BORDER"] = "border";
115
- TokenTypes2["ASSET"] = "asset";
116
- TokenTypes2["BOOLEAN"] = "boolean";
117
- TokenTypes2["NUMBER"] = "number";
118
- })(TokenTypes || (TokenTypes = {}));
119
-
120
- // ../../node_modules/@tokens-studio/types/dist/constants/BorderValues.js
121
- var BorderValues;
122
- (function(BorderValues2) {
123
- BorderValues2["BORDER_COLOR"] = "color";
124
- BorderValues2["BORDER_WIDTH"] = "width";
125
- BorderValues2["BORDER_STYLE"] = "style";
126
- })(BorderValues || (BorderValues = {}));
127
-
128
- // ../../node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
129
- var StrokeStyleValues;
130
- (function(StrokeStyleValues2) {
131
- StrokeStyleValues2["SOLID"] = "solid";
132
- StrokeStyleValues2["DASHED"] = "dashed";
133
- StrokeStyleValues2["DOTTED"] = "dotted";
134
- StrokeStyleValues2["DOUBLE"] = "double";
135
- StrokeStyleValues2["GROOVE"] = "groove";
136
- StrokeStyleValues2["RIDGE"] = "ridge";
137
- StrokeStyleValues2["OUTSET"] = "outset";
138
- StrokeStyleValues2["INSET"] = "inset";
139
- })(StrokeStyleValues || (StrokeStyleValues = {}));
140
-
141
- // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
142
- var BoxShadowValues;
143
- (function(BoxShadowValues2) {
144
- BoxShadowValues2["TYPE"] = "type";
145
- BoxShadowValues2["COLOR"] = "color";
146
- BoxShadowValues2["X"] = "x";
147
- BoxShadowValues2["Y"] = "y";
148
- BoxShadowValues2["BLUR"] = "blur";
149
- BoxShadowValues2["SPREAD"] = "spread";
150
- BoxShadowValues2["BLEND_MODE"] = "blendMode";
151
- })(BoxShadowValues || (BoxShadowValues = {}));
152
-
153
- // ../../node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
154
- var TypographyValues;
155
- (function(TypographyValues2) {
156
- TypographyValues2["FONT_FAMILY"] = "fontFamily";
157
- TypographyValues2["FONT_WEIGHT"] = "fontWeight";
158
- TypographyValues2["LINE_HEIGHT"] = "lineHeight";
159
- TypographyValues2["FONT_SIZE"] = "fontSize";
160
- TypographyValues2["LETTER_SPACING"] = "letterSpacing";
161
- TypographyValues2["PARAGRAPH_SPACING"] = "paragraphSpacing";
162
- TypographyValues2["PARAGRAPH_INDENT"] = "paragraphIndent";
163
- TypographyValues2["TEXT_DECORATION"] = "textDecoration";
164
- TypographyValues2["TEXT_CASE"] = "textCase";
165
- })(TypographyValues || (TypographyValues = {}));
166
-
167
- // src/tokens/utils/permutateThemes.ts
2
+ import { TokenSetStatus } from "@tokens-studio/types";
168
3
  function mapThemesToSetsObject(themes) {
169
- return themes.map((theme) => ({ name: theme.name, selectedTokenSets: filterTokenSets(theme.selectedTokenSets) }));
4
+ return themes.map((theme)=>({
5
+ name: theme.name,
6
+ selectedTokenSets: filterTokenSets(theme.selectedTokenSets)
7
+ }));
170
8
  }
171
- function permutateThemes(themes, { separator = "-" } = {}) {
172
- if (!themes.some((theme) => theme.group)) {
173
- return mapThemesToSetsObject(themes);
174
- }
175
- const groups = {};
176
- themes.forEach((theme) => {
177
- if (theme.group) {
178
- groups[theme.group] = [...groups[theme.group] ?? [], theme];
179
- } else {
180
- throw new Error(
181
- `Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`
182
- );
9
+ export function permutateThemes(themes, { separator = '-' } = {}) {
10
+ if (!themes.some((theme)=>theme.group)) {
11
+ return mapThemesToSetsObject(themes);
183
12
  }
184
- });
185
- if (Object.keys(groups).length <= 1) {
186
- return mapThemesToSetsObject(themes);
187
- }
188
- const permutations = cartesian(Object.values(groups));
189
- const permutatedThemes = permutations.map((perm) => {
190
- const permutatedTheme = perm.reduce(
191
- (acc, theme) => {
192
- const { group, name, selectedTokenSets } = theme;
193
- let updatedPermutatedTheme = acc;
194
- if (group) {
195
- const groupProp = R.lensProp(group.toLowerCase());
196
- updatedPermutatedTheme = R.set(groupProp, name.toLowerCase(), updatedPermutatedTheme);
13
+ // Sort themes by groups
14
+ const groups = {};
15
+ themes.forEach((theme)=>{
16
+ if (theme.group) {
17
+ groups[theme.group] = [
18
+ ...groups[theme.group] ?? [],
19
+ theme
20
+ ];
21
+ } else {
22
+ throw new Error(`Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`);
197
23
  }
198
- const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
199
- const sets = [...updatedPermutatedTheme.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
24
+ });
25
+ if (Object.keys(groups).length <= 1) {
26
+ return mapThemesToSetsObject(themes);
27
+ }
28
+ // Create theme permutations
29
+ const permutations = cartesian(Object.values(groups));
30
+ const permutatedThemes = permutations.map((perm)=>{
31
+ const permutatedTheme = perm.reduce((acc, theme)=>{
32
+ const { group, name, selectedTokenSets } = theme;
33
+ let updatedPermutatedTheme = acc;
34
+ if (group) {
35
+ const groupProp = R.lensProp(group.toLowerCase());
36
+ updatedPermutatedTheme = R.set(groupProp, name.toLowerCase(), updatedPermutatedTheme);
37
+ }
38
+ const updatedName = `${String(acc.name)}${acc ? separator : ''}${name}`;
39
+ const sets = [
40
+ ...updatedPermutatedTheme.selectedTokenSets,
41
+ ...filterTokenSets(selectedTokenSets)
42
+ ];
43
+ return {
44
+ ...updatedPermutatedTheme,
45
+ name: updatedName,
46
+ selectedTokenSets: sets
47
+ };
48
+ }, {
49
+ name: '',
50
+ selectedTokenSets: []
51
+ });
52
+ const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
200
53
  return {
201
- ...updatedPermutatedTheme,
202
- name: updatedName,
203
- selectedTokenSets: sets
54
+ ...permutatedTheme,
55
+ selectedTokenSets: Array.from(uniqueTokenSets)
204
56
  };
205
- },
206
- { name: "", selectedTokenSets: [] }
207
- );
208
- const uniqueTokenSets = new Set(permutatedTheme.selectedTokenSets);
209
- return { ...permutatedTheme, selectedTokenSets: Array.from(uniqueTokenSets) };
210
- });
211
- return permutatedThemes;
57
+ });
58
+ return permutatedThemes;
212
59
  }
213
60
  function filterTokenSets(tokensets) {
214
- return Object.entries(tokensets).filter(([, val]) => val !== TokenSetStatus.DISABLED).sort((a, b) => {
215
- if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
216
- return -1;
217
- } else if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
218
- return 1;
219
- }
220
- return 0;
221
- }).map((entry) => entry[0]);
61
+ return Object.entries(tokensets).filter(([, val])=>val !== TokenSetStatus.DISABLED)// ensure source type sets are always ordered before enabled type sets
62
+ .sort((a, b)=>{
63
+ if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
64
+ return -1;
65
+ } else if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
66
+ return 1;
67
+ }
68
+ return 0;
69
+ }).map((entry)=>entry[0]);
222
70
  }
71
+ // cartesian permutations: [[1,2], [3,4]] -> [[1,3], [1,4], [2,3], [2,4]]
223
72
  function cartesian(a) {
224
- return a.reduce((a2, b) => a2.flatMap((d) => b.map((e) => [d, e].flat())));
73
+ return a.reduce((a, b)=>a.flatMap((d)=>b.map((e)=>[
74
+ d,
75
+ e
76
+ ].flat())));
225
77
  }
226
- export {
227
- permutateThemes
228
- };
229
- //# sourceMappingURL=permutateThemes.js.map
@@ -1,16 +1,27 @@
1
- // src/tokens/utils/utils.ts
2
1
  import * as R from "ramda";
3
- var getType = (token) => (token.$type ?? token.type) || "";
4
- var getValue = (token) => token.$value ?? token.value;
5
- var typeEquals = R.curry((types, token) => {
6
- if (R.isNil(token)) {
7
- return false;
8
- }
9
- return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
2
+ /**
3
+ * Returns type based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
4
+ * @param token Transformed token
5
+ * @returns type
6
+ */ export const getType = (token)=>(token.$type ?? token.type) || '';
7
+ /**
8
+ * Returns value based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
9
+ *
10
+ * Use generic (`<T>`) to define return value type
11
+ * @param token Transformed or Design token
12
+ * @returns value
13
+ */ export const getValue = (token)=>token.$value ?? token.value;
14
+ /**
15
+ * Check if token type matches provided type
16
+ * This function is curried
17
+ * @param types Type or array of types to check against
18
+ * @param token Transformed token
19
+ * @returns boolean
20
+ */ export const typeEquals = R.curry((types, token)=>{
21
+ if (R.isNil(token)) {
22
+ return false;
23
+ }
24
+ return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [
25
+ types
26
+ ]));
10
27
  });
11
- export {
12
- getType,
13
- getValue,
14
- typeEquals
15
- };
16
- //# sourceMappingURL=utils.js.map