@kaizen/design-tokens 3.1.0

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 (129) hide show
  1. package/CHANGELOG.md +773 -0
  2. package/LICENSE +21 -0
  3. package/README.md +66 -0
  4. package/dist/index.d.ts +8 -0
  5. package/dist/index.d.ts.map +1 -0
  6. package/dist/index.js +23 -0
  7. package/dist/react/ThemeProvider.d.ts +13 -0
  8. package/dist/react/ThemeProvider.d.ts.map +1 -0
  9. package/dist/react/ThemeProvider.js +42 -0
  10. package/dist/react/index.d.ts +2 -0
  11. package/dist/react/index.d.ts.map +1 -0
  12. package/dist/react/index.js +13 -0
  13. package/dist/src/ThemeManager.d.ts +23 -0
  14. package/dist/src/ThemeManager.d.ts.map +1 -0
  15. package/dist/src/ThemeManager.js +70 -0
  16. package/dist/src/lib/addExtraThemeEntries.d.ts +25 -0
  17. package/dist/src/lib/addExtraThemeEntries.d.ts.map +1 -0
  18. package/dist/src/lib/addExtraThemeEntries.js +56 -0
  19. package/dist/src/lib/cssVariables.d.ts +23 -0
  20. package/dist/src/lib/cssVariables.d.ts.map +1 -0
  21. package/dist/src/lib/cssVariables.js +33 -0
  22. package/dist/src/lib/makeCssVariableDefinitionsMap.d.ts +30 -0
  23. package/dist/src/lib/makeCssVariableDefinitionsMap.d.ts.map +1 -0
  24. package/dist/src/lib/makeCssVariableDefinitionsMap.js +57 -0
  25. package/dist/src/lib/makeCssVariableTheme.d.ts +35 -0
  26. package/dist/src/lib/makeCssVariableTheme.d.ts.map +1 -0
  27. package/dist/src/lib/makeCssVariableTheme.js +54 -0
  28. package/dist/src/lib/mapLeafsOfObject.d.ts +23 -0
  29. package/dist/src/lib/mapLeafsOfObject.d.ts.map +1 -0
  30. package/dist/src/lib/mapLeafsOfObject.js +59 -0
  31. package/dist/src/themes/heart.d.ts +3 -0
  32. package/dist/src/themes/heart.d.ts.map +1 -0
  33. package/dist/src/themes/heart.js +286 -0
  34. package/dist/src/themes/index.d.ts +4 -0
  35. package/dist/src/themes/index.d.ts.map +1 -0
  36. package/dist/src/themes/index.js +9 -0
  37. package/dist/src/themes/zen.d.ts +3 -0
  38. package/dist/src/themes/zen.d.ts.map +1 -0
  39. package/dist/src/themes/zen.js +293 -0
  40. package/dist/src/types.d.ts +205 -0
  41. package/dist/src/types.d.ts.map +1 -0
  42. package/dist/src/types.js +2 -0
  43. package/elm/Kaizen/Theme.elm +29 -0
  44. package/index.ts +9 -0
  45. package/less/animation.less +49 -0
  46. package/less/border.less +47 -0
  47. package/less/color.less +210 -0
  48. package/less/layout.less +8 -0
  49. package/less/shadow.less +12 -0
  50. package/less/spacing.less +20 -0
  51. package/less/typography.less +526 -0
  52. package/package.json +63 -0
  53. package/react/ThemeProvider.d.ts +12 -0
  54. package/react/ThemeProvider.js +43 -0
  55. package/react/ThemeProvider.js.map +1 -0
  56. package/react/ThemeProvider.tsx +39 -0
  57. package/react/index.d.ts +1 -0
  58. package/react/index.js +14 -0
  59. package/react/index.js.map +1 -0
  60. package/react/index.tsx +1 -0
  61. package/sass/animation.scss +49 -0
  62. package/sass/border.scss +47 -0
  63. package/sass/color.scss +210 -0
  64. package/sass/layout.scss +8 -0
  65. package/sass/shadow.scss +12 -0
  66. package/sass/spacing.scss +20 -0
  67. package/sass/typography.scss +526 -0
  68. package/src/ThemeManager.d.ts +22 -0
  69. package/src/ThemeManager.js +71 -0
  70. package/src/ThemeManager.js.map +1 -0
  71. package/src/ThemeManager.ts +70 -0
  72. package/src/lib/__tests__/themeForTesting.d.ts +38 -0
  73. package/src/lib/__tests__/themeForTesting.js +21 -0
  74. package/src/lib/__tests__/themeForTesting.js.map +1 -0
  75. package/src/lib/__tests__/themeForTesting.ts +17 -0
  76. package/src/lib/addExtraThemeEntries.d.ts +24 -0
  77. package/src/lib/addExtraThemeEntries.js +57 -0
  78. package/src/lib/addExtraThemeEntries.js.map +1 -0
  79. package/src/lib/addExtraThemeEntries.ts +56 -0
  80. package/src/lib/cssVariables.d.ts +22 -0
  81. package/src/lib/cssVariables.js +34 -0
  82. package/src/lib/cssVariables.js.map +1 -0
  83. package/src/lib/cssVariables.ts +27 -0
  84. package/src/lib/makeCssVariableDefinitionsMap.d.ts +29 -0
  85. package/src/lib/makeCssVariableDefinitionsMap.js +58 -0
  86. package/src/lib/makeCssVariableDefinitionsMap.js.map +1 -0
  87. package/src/lib/makeCssVariableDefinitionsMap.ts +55 -0
  88. package/src/lib/makeCssVariableTheme.d.ts +34 -0
  89. package/src/lib/makeCssVariableTheme.js +55 -0
  90. package/src/lib/makeCssVariableTheme.js.map +1 -0
  91. package/src/lib/makeCssVariableTheme.ts +63 -0
  92. package/src/lib/mapLeafsOfObject.d.ts +22 -0
  93. package/src/lib/mapLeafsOfObject.js +60 -0
  94. package/src/lib/mapLeafsOfObject.js.map +1 -0
  95. package/src/lib/mapLeafsOfObject.ts +50 -0
  96. package/src/lib/patterns.d.ts +2 -0
  97. package/src/lib/patterns.js +6 -0
  98. package/src/lib/patterns.js.map +1 -0
  99. package/src/lib/patterns.ts +2 -0
  100. package/src/themes/heart.d.ts +2 -0
  101. package/src/themes/heart.js +287 -0
  102. package/src/themes/heart.js.map +1 -0
  103. package/src/themes/heart.ts +285 -0
  104. package/src/themes/index.d.ts +3 -0
  105. package/src/themes/index.js +17 -0
  106. package/src/themes/index.js.map +1 -0
  107. package/src/themes/index.ts +4 -0
  108. package/src/themes/zen.d.ts +2 -0
  109. package/src/themes/zen.js +294 -0
  110. package/src/themes/zen.js.map +1 -0
  111. package/src/themes/zen.ts +292 -0
  112. package/src/types.d.ts +204 -0
  113. package/src/types.js +3 -0
  114. package/src/types.js.map +1 -0
  115. package/src/types.ts +225 -0
  116. package/tokens/animation.json +34 -0
  117. package/tokens/animation.json.d.ts +12 -0
  118. package/tokens/border.json +44 -0
  119. package/tokens/border.json.d.ts +12 -0
  120. package/tokens/color.json +228 -0
  121. package/tokens/color.json.d.ts +12 -0
  122. package/tokens/layout.json +9 -0
  123. package/tokens/layout.json.d.ts +12 -0
  124. package/tokens/shadow.json +12 -0
  125. package/tokens/shadow.json.d.ts +12 -0
  126. package/tokens/spacing.json +22 -0
  127. package/tokens/spacing.json.d.ts +12 -0
  128. package/tokens/typography.json +236 -0
  129. package/tokens/typography.json.d.ts +12 -0
@@ -0,0 +1,38 @@
1
+ export declare const themeForTesting: {
2
+ readonly border: {
3
+ readonly dashed: {
4
+ readonly borderWidth: "2px";
5
+ readonly red: "red";
6
+ };
7
+ };
8
+ readonly color: {
9
+ readonly gray: {
10
+ readonly 100: "#eee";
11
+ readonly 200: "#ccc";
12
+ };
13
+ readonly purple: {
14
+ readonly 100: "#eee";
15
+ readonly 200: "#ccc";
16
+ };
17
+ readonly blue: {
18
+ readonly 100: "#eee";
19
+ readonly 200: "#ccc";
20
+ };
21
+ readonly red: {
22
+ readonly 100: "#eee";
23
+ readonly 200: "#ccc";
24
+ };
25
+ readonly yellow: {
26
+ readonly 100: "#eee";
27
+ readonly 200: "#ccc";
28
+ };
29
+ readonly orange: {
30
+ readonly 100: "#eee";
31
+ readonly 200: "#ccc";
32
+ };
33
+ readonly green: {
34
+ readonly 100: "#eee";
35
+ readonly 200: "#ccc";
36
+ };
37
+ };
38
+ };
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.themeForTesting = void 0;
4
+ exports.themeForTesting = {
5
+ border: {
6
+ dashed: {
7
+ borderWidth: "2px",
8
+ red: "red"
9
+ }
10
+ },
11
+ color: {
12
+ gray: { 100: "#eee", 200: "#ccc" },
13
+ purple: { 100: "#eee", 200: "#ccc" },
14
+ blue: { 100: "#eee", 200: "#ccc" },
15
+ red: { 100: "#eee", 200: "#ccc" },
16
+ yellow: { 100: "#eee", 200: "#ccc" },
17
+ orange: { 100: "#eee", 200: "#ccc" },
18
+ green: { 100: "#eee", 200: "#ccc" }
19
+ }
20
+ };
21
+ //# sourceMappingURL=themeForTesting.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"themeForTesting.js","sourceRoot":"","sources":["themeForTesting.ts"],"names":[],"mappings":";;;AAAa,QAAA,eAAe,GAAG;IAC7B,MAAM,EAAE;QACN,MAAM,EAAE;YACN,WAAW,EAAE,KAAK;YAClB,GAAG,EAAE,KAAK;SACX;KACF;IACD,KAAK,EAAE;QACL,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;QAClC,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;QACpC,IAAI,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;QAClC,GAAG,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;QACjC,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;QACpC,MAAM,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;QACpC,KAAK,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE;KACpC;CACO,CAAA"}
@@ -0,0 +1,17 @@
1
+ export const themeForTesting = {
2
+ border: {
3
+ dashed: {
4
+ borderWidth: "2px",
5
+ red: "red",
6
+ },
7
+ },
8
+ color: {
9
+ gray: { 100: "#eee", 200: "#ccc" },
10
+ purple: { 100: "#eee", 200: "#ccc" },
11
+ blue: { 100: "#eee", 200: "#ccc" },
12
+ red: { 100: "#eee", 200: "#ccc" },
13
+ yellow: { 100: "#eee", 200: "#ccc" },
14
+ orange: { 100: "#eee", 200: "#ccc" },
15
+ green: { 100: "#eee", 200: "#ccc" },
16
+ },
17
+ } as const
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Use this to generate an object containing `${key}: value`, `${key}-rgb: r, g, b`, and/or `${key}-id: --color-blah-XXX`.
3
+ * This is for adding extra neighbouring properties to a theme.
4
+ * For example:
5
+ * Input:
6
+ * path: [color, purple, 100]
7
+ * key: 100
8
+ * value: #f0f1f4
9
+ * printValue: (path, v) => `var(--some-key, ${v})`
10
+ * options: {augmentWithId: true}
11
+ *
12
+ * Output: {
13
+ * "100": "var(--some-key, #f0f1f4)",
14
+ * "100-rgb": "var(--some-key, 240, 241, 244)",
15
+ * "100-id": "--color-purple-100"
16
+ * "100-rgb-id": "--color-purple-100-rgb"
17
+ * }
18
+ */
19
+ export declare const addExtraThemeEntries: (path: string[], key: string, value: unknown, printValue: <I>(path: string[], value: I) => string, { augmentWithId, }: {
20
+ /** Setting this to true will add `${key}-id` and ${key}-rgb-id` */
21
+ augmentWithId: boolean;
22
+ }) => {
23
+ [x: string]: string;
24
+ };
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ var __spreadArrays = (this && this.__spreadArrays) || function () {
3
+ for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
4
+ for (var r = Array(s), k = 0, i = 0; i < il; i++)
5
+ for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
6
+ r[k] = a[j];
7
+ return r;
8
+ };
9
+ var __importDefault = (this && this.__importDefault) || function (mod) {
10
+ return (mod && mod.__esModule) ? mod : { "default": mod };
11
+ };
12
+ exports.__esModule = true;
13
+ exports.addExtraThemeEntries = void 0;
14
+ var color_string_1 = __importDefault(require("color-string"));
15
+ var cssVariables_1 = require("./cssVariables");
16
+ /**
17
+ * Use this to generate an object containing `${key}: value`, `${key}-rgb: r, g, b`, and/or `${key}-id: --color-blah-XXX`.
18
+ * This is for adding extra neighbouring properties to a theme.
19
+ * For example:
20
+ * Input:
21
+ * path: [color, purple, 100]
22
+ * key: 100
23
+ * value: #f0f1f4
24
+ * printValue: (path, v) => `var(--some-key, ${v})`
25
+ * options: {augmentWithId: true}
26
+ *
27
+ * Output: {
28
+ * "100": "var(--some-key, #f0f1f4)",
29
+ * "100-rgb": "var(--some-key, 240, 241, 244)",
30
+ * "100-id": "--color-purple-100"
31
+ * "100-rgb-id": "--color-purple-100-rgb"
32
+ * }
33
+ */
34
+ exports.addExtraThemeEntries = function (path, key, value, printValue, _a) {
35
+ var _b;
36
+ var augmentWithId = _a.augmentWithId;
37
+ var colorRgb = typeof value === "string" ? color_string_1["default"].get.rgb(value) : null;
38
+ var result = (_b = {},
39
+ _b[key] = printValue(path, value),
40
+ _b);
41
+ // Add the -rgb key containing the RGB triple of the color (if it is a color)
42
+ if (colorRgb) {
43
+ // If the value is a color, always convert to lowercase
44
+ result[key] = printValue(path, value).toLowerCase();
45
+ var rgbPath = __spreadArrays(path, ["rgb"]);
46
+ var rgbTriple = printValue(rgbPath, colorRgb.slice(0, 3).join(", "));
47
+ result[key + "-rgb"] = rgbTriple;
48
+ if (augmentWithId) {
49
+ result[key + "-rgb-id"] = cssVariables_1.objectPathToCssVarIdentifier(rgbPath);
50
+ }
51
+ }
52
+ if (augmentWithId) {
53
+ result[key + "-id"] = cssVariables_1.objectPathToCssVarIdentifier(path);
54
+ }
55
+ return result;
56
+ };
57
+ //# sourceMappingURL=addExtraThemeEntries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addExtraThemeEntries.js","sourceRoot":"","sources":["addExtraThemeEntries.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAAA,8DAAsC;AACtC,+CAA6D;AAE7D;;;;;;;;;;;;;;;;;GAiBG;AACU,QAAA,oBAAoB,GAAG,UAClC,IAAc,EACd,GAAW,EACX,KAAc,EACd,UAAmD,EACnD,EAKC;;QAJC,aAAa,mBAAA;IAMf,IAAM,QAAQ,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,yBAAW,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,IAAI,CAAA;IAC9E,IAAM,MAAM;QACV,GAAC,GAAG,IAAG,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC;WAC/B,CAAA;IAED,6EAA6E;IAC7E,IAAI,QAAQ,EAAE;QACZ,uDAAuD;QACvD,MAAM,CAAC,GAAG,CAAC,GAAG,UAAU,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAA;QAEnD,IAAM,OAAO,kBAAO,IAAI,GAAE,KAAK,EAAC,CAAA;QAChC,IAAM,SAAS,GAAG,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAA;QACtE,MAAM,CAAI,GAAG,SAAM,CAAC,GAAG,SAAS,CAAA;QAChC,IAAI,aAAa,EAAE;YACjB,MAAM,CAAI,GAAG,YAAS,CAAC,GAAG,2CAA4B,CAAC,OAAO,CAAC,CAAA;SAChE;KACF;IACD,IAAI,aAAa,EAAE;QACjB,MAAM,CAAI,GAAG,QAAK,CAAC,GAAG,2CAA4B,CAAC,IAAI,CAAC,CAAA;KACzD;IAED,OAAO,MAAM,CAAA;AACf,CAAC,CAAA"}
@@ -0,0 +1,56 @@
1
+ import colorString from "color-string"
2
+ import { objectPathToCssVarIdentifier } from "./cssVariables"
3
+
4
+ /**
5
+ * Use this to generate an object containing `${key}: value`, `${key}-rgb: r, g, b`, and/or `${key}-id: --color-blah-XXX`.
6
+ * This is for adding extra neighbouring properties to a theme.
7
+ * For example:
8
+ * Input:
9
+ * path: [color, purple, 100]
10
+ * key: 100
11
+ * value: #f0f1f4
12
+ * printValue: (path, v) => `var(--some-key, ${v})`
13
+ * options: {augmentWithId: true}
14
+ *
15
+ * Output: {
16
+ * "100": "var(--some-key, #f0f1f4)",
17
+ * "100-rgb": "var(--some-key, 240, 241, 244)",
18
+ * "100-id": "--color-purple-100"
19
+ * "100-rgb-id": "--color-purple-100-rgb"
20
+ * }
21
+ */
22
+ export const addExtraThemeEntries = (
23
+ path: string[],
24
+ key: string,
25
+ value: unknown,
26
+ printValue: <I>(path: string[], value: I) => string,
27
+ {
28
+ augmentWithId,
29
+ }: {
30
+ /** Setting this to true will add `${key}-id` and ${key}-rgb-id` */
31
+ augmentWithId: boolean
32
+ }
33
+ ) => {
34
+ const colorRgb = typeof value === "string" ? colorString.get.rgb(value) : null
35
+ const result = {
36
+ [key]: printValue(path, value),
37
+ }
38
+
39
+ // Add the -rgb key containing the RGB triple of the color (if it is a color)
40
+ if (colorRgb) {
41
+ // If the value is a color, always convert to lowercase
42
+ result[key] = printValue(path, value).toLowerCase()
43
+
44
+ const rgbPath = [...path, "rgb"]
45
+ const rgbTriple = printValue(rgbPath, colorRgb.slice(0, 3).join(", "))
46
+ result[`${key}-rgb`] = rgbTriple
47
+ if (augmentWithId) {
48
+ result[`${key}-rgb-id`] = objectPathToCssVarIdentifier(rgbPath)
49
+ }
50
+ }
51
+ if (augmentWithId) {
52
+ result[`${key}-id`] = objectPathToCssVarIdentifier(path)
53
+ }
54
+
55
+ return result
56
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Given an object path (an array of strings) and a value, return a CSS var() function that represents it.
3
+ *
4
+ * Example:
5
+ * Input:
6
+ * path: [color, wisteria, 100]
7
+ * value: #f0f1f4
8
+ *
9
+ * Output:
10
+ * "var(--color-wisteria-100, #f0f1f4)"
11
+ *
12
+ */
13
+ export declare const objectPathToCssVarFunction: (path: string[], value: unknown) => string;
14
+ /**
15
+ * Given an object path (an array of strings), return a CSS variable identifier.
16
+ *
17
+ * Example:
18
+ * Input: [color, wisteria, 100]
19
+ *
20
+ * Output: "--color-wisteria-100"
21
+ */
22
+ export declare const objectPathToCssVarIdentifier: (path: string[]) => string;
@@ -0,0 +1,34 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ exports.__esModule = true;
6
+ exports.objectPathToCssVarIdentifier = exports.objectPathToCssVarFunction = void 0;
7
+ var lodash_kebabcase_1 = __importDefault(require("lodash.kebabcase"));
8
+ /**
9
+ * Given an object path (an array of strings) and a value, return a CSS var() function that represents it.
10
+ *
11
+ * Example:
12
+ * Input:
13
+ * path: [color, wisteria, 100]
14
+ * value: #f0f1f4
15
+ *
16
+ * Output:
17
+ * "var(--color-wisteria-100, #f0f1f4)"
18
+ *
19
+ */
20
+ exports.objectPathToCssVarFunction = function (path, value) {
21
+ return "var(" + exports.objectPathToCssVarIdentifier(path) + ", " + value + ")";
22
+ };
23
+ /**
24
+ * Given an object path (an array of strings), return a CSS variable identifier.
25
+ *
26
+ * Example:
27
+ * Input: [color, wisteria, 100]
28
+ *
29
+ * Output: "--color-wisteria-100"
30
+ */
31
+ exports.objectPathToCssVarIdentifier = function (path) {
32
+ return "--" + path.map(lodash_kebabcase_1["default"]).join("-");
33
+ };
34
+ //# sourceMappingURL=cssVariables.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cssVariables.js","sourceRoot":"","sources":["cssVariables.ts"],"names":[],"mappings":";;;;;;AAAA,sEAAoC;AAEpC;;;;;;;;;;;GAWG;AACU,QAAA,0BAA0B,GAAG,UAAC,IAAc,EAAE,KAAc;IACvE,OAAA,SAAO,oCAA4B,CAAC,IAAI,CAAC,UAAK,KAAK,MAAG;AAAtD,CAAsD,CAAA;AAExD;;;;;;;GAOG;AACU,QAAA,4BAA4B,GAAG,UAAC,IAAc;IACzD,OAAA,OAAK,IAAI,CAAC,GAAG,CAAC,6BAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAG;AAAhC,CAAgC,CAAA"}
@@ -0,0 +1,27 @@
1
+ import kebab from "lodash.kebabcase"
2
+
3
+ /**
4
+ * Given an object path (an array of strings) and a value, return a CSS var() function that represents it.
5
+ *
6
+ * Example:
7
+ * Input:
8
+ * path: [color, wisteria, 100]
9
+ * value: #f0f1f4
10
+ *
11
+ * Output:
12
+ * "var(--color-wisteria-100, #f0f1f4)"
13
+ *
14
+ */
15
+ export const objectPathToCssVarFunction = (path: string[], value: unknown) =>
16
+ `var(${objectPathToCssVarIdentifier(path)}, ${value})`
17
+
18
+ /**
19
+ * Given an object path (an array of strings), return a CSS variable identifier.
20
+ *
21
+ * Example:
22
+ * Input: [color, wisteria, 100]
23
+ *
24
+ * Output: "--color-wisteria-100"
25
+ */
26
+ export const objectPathToCssVarIdentifier = (path: string[]) =>
27
+ `--${path.map(kebab).join("-")}`
@@ -0,0 +1,29 @@
1
+ /**
2
+
3
+ * Make a map of CSS variables -> values in a consistent way.
4
+ * Use this to, for example, create a CSS file that declares each theme variable on the `:root` pseudo element.
5
+ * Or for example when you're defining CSS variables using `rootElement.style.setProperty` within ThemeManager.
6
+ *
7
+ * It is paramount that this function defines every variable that {@link makeCssVariableTheme} expects to be defined.
8
+ * Otherwise, it's possible that a CSS variable token (something that looks like var(--color-purple-100-rgb)) won't have a matching defined
9
+ * CSS variable like `--color-purple-100-rgb: 123, 123, 123;`
10
+ *
11
+ *
12
+ * For example:
13
+ * Input:
14
+ * ```
15
+ * {
16
+ * color: {
17
+ * whatever: {
18
+ * 100: "#ff0022"
19
+ * }
20
+ * }
21
+ * }
22
+ * ```
23
+ * Output:
24
+ * ```
25
+ * {
26
+ * "--color-whatever-100": "#ff0022"
27
+ * }
28
+ */
29
+ export declare function makeCssVariableDefinitionsMap(theme: Record<string | number, unknown>): Record<string, string>;
@@ -0,0 +1,58 @@
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ exports.__esModule = true;
14
+ exports.makeCssVariableDefinitionsMap = void 0;
15
+ var addExtraThemeEntries_1 = require("./addExtraThemeEntries");
16
+ var cssVariables_1 = require("./cssVariables");
17
+ var mapLeafsOfObject_1 = require("./mapLeafsOfObject");
18
+ /**
19
+
20
+ * Make a map of CSS variables -> values in a consistent way.
21
+ * Use this to, for example, create a CSS file that declares each theme variable on the `:root` pseudo element.
22
+ * Or for example when you're defining CSS variables using `rootElement.style.setProperty` within ThemeManager.
23
+ *
24
+ * It is paramount that this function defines every variable that {@link makeCssVariableTheme} expects to be defined.
25
+ * Otherwise, it's possible that a CSS variable token (something that looks like var(--color-purple-100-rgb)) won't have a matching defined
26
+ * CSS variable like `--color-purple-100-rgb: 123, 123, 123;`
27
+ *
28
+ *
29
+ * For example:
30
+ * Input:
31
+ * ```
32
+ * {
33
+ * color: {
34
+ * whatever: {
35
+ * 100: "#ff0022"
36
+ * }
37
+ * }
38
+ * }
39
+ * ```
40
+ * Output:
41
+ * ```
42
+ * {
43
+ * "--color-whatever-100": "#ff0022"
44
+ * }
45
+ */
46
+ function makeCssVariableDefinitionsMap(theme) {
47
+ var accumulatedCssVariables = {};
48
+ // Shamelessly using a map function like a forEach
49
+ mapLeafsOfObject_1.mapLeafsOfObject(theme, function (path, value) {
50
+ // Key will be `--color-blah`
51
+ var key = cssVariables_1.objectPathToCssVarIdentifier(path);
52
+ var nextCssVariables = addExtraThemeEntries_1.addExtraThemeEntries(path, key, value, function (_, v) { return "" + v; }, { augmentWithId: false });
53
+ accumulatedCssVariables = __assign(__assign({}, accumulatedCssVariables), nextCssVariables);
54
+ });
55
+ return accumulatedCssVariables;
56
+ }
57
+ exports.makeCssVariableDefinitionsMap = makeCssVariableDefinitionsMap;
58
+ //# sourceMappingURL=makeCssVariableDefinitionsMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeCssVariableDefinitionsMap.js","sourceRoot":"","sources":["makeCssVariableDefinitionsMap.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+DAA6D;AAC7D,+CAA6D;AAC7D,uDAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,SAAgB,6BAA6B,CAC3C,KAAuC;IAEvC,IAAI,uBAAuB,GAAG,EAA4B,CAAA;IAE1D,kDAAkD;IAClD,mCAAgB,CAAC,KAAK,EAAE,UAAC,IAAI,EAAE,KAAK;QAClC,6BAA6B;QAC7B,IAAM,GAAG,GAAG,2CAA4B,CAAC,IAAI,CAAC,CAAA;QAC9C,IAAM,gBAAgB,GAAG,2CAAoB,CAC3C,IAAI,EACJ,GAAG,EACH,KAAK,EACL,UAAC,CAAC,EAAE,CAAC,IAAK,OAAA,KAAG,CAAG,EAAN,CAAM,EAChB,EAAE,aAAa,EAAE,KAAK,EAAE,CACzB,CAAA;QACD,uBAAuB,yBAClB,uBAAuB,GACvB,gBAAgB,CACpB,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,uBAAuB,CAAA;AAChC,CAAC;AAtBD,sEAsBC"}
@@ -0,0 +1,55 @@
1
+ import { addExtraThemeEntries } from "./addExtraThemeEntries"
2
+ import { objectPathToCssVarIdentifier } from "./cssVariables"
3
+ import { mapLeafsOfObject } from "./mapLeafsOfObject"
4
+
5
+ /**
6
+
7
+ * Make a map of CSS variables -> values in a consistent way.
8
+ * Use this to, for example, create a CSS file that declares each theme variable on the `:root` pseudo element.
9
+ * Or for example when you're defining CSS variables using `rootElement.style.setProperty` within ThemeManager.
10
+ *
11
+ * It is paramount that this function defines every variable that {@link makeCssVariableTheme} expects to be defined.
12
+ * Otherwise, it's possible that a CSS variable token (something that looks like var(--color-purple-100-rgb)) won't have a matching defined
13
+ * CSS variable like `--color-purple-100-rgb: 123, 123, 123;`
14
+ *
15
+ *
16
+ * For example:
17
+ * Input:
18
+ * ```
19
+ * {
20
+ * color: {
21
+ * whatever: {
22
+ * 100: "#ff0022"
23
+ * }
24
+ * }
25
+ * }
26
+ * ```
27
+ * Output:
28
+ * ```
29
+ * {
30
+ * "--color-whatever-100": "#ff0022"
31
+ * }
32
+ */
33
+ export function makeCssVariableDefinitionsMap(
34
+ theme: Record<string | number, unknown>
35
+ ) {
36
+ let accumulatedCssVariables = {} as Record<string, string>
37
+
38
+ // Shamelessly using a map function like a forEach
39
+ mapLeafsOfObject(theme, (path, value) => {
40
+ // Key will be `--color-blah`
41
+ const key = objectPathToCssVarIdentifier(path)
42
+ const nextCssVariables = addExtraThemeEntries(
43
+ path,
44
+ key,
45
+ value,
46
+ (_, v) => `${v}`,
47
+ { augmentWithId: false }
48
+ )
49
+ accumulatedCssVariables = {
50
+ ...accumulatedCssVariables,
51
+ ...nextCssVariables,
52
+ }
53
+ })
54
+ return accumulatedCssVariables
55
+ }
@@ -0,0 +1,34 @@
1
+ import { DeepMapObjectLeafs } from "../types";
2
+ /**
3
+ * This function could use a new name during a breaking change
4
+ *
5
+ * Given a Theme (which is the source of truth and doesn't contain any computed properties), add extra necessary properties to the tree such as `-rgb` suffixed keys with R, G, B triple values, and
6
+ * convert the leaf values of a theme to a value like `var(--parent1key-parent2key-leafkey)` - a CSS variable with an identifier that represents it's hierarchy.
7
+ *
8
+ * Example:
9
+ * ```
10
+ * {
11
+ * color: {
12
+ * purple: {
13
+ * 100: "#f0f1f4"
14
+ * }
15
+ * }
16
+ * }
17
+ * ```
18
+ * Transforms into:
19
+ * ```
20
+ * {
21
+ * color: {
22
+ * purple: {
23
+ * 100: "var(--color-purple-100, "#f0f1f4")",
24
+ * "100-rgb": "var(--color-purple-100-rgb, 240, 241, 244)",
25
+ * "100-id": "--color-purple-100",
26
+ * "100-rgb-id": "--color-purple-100-rgb"
27
+ * }
28
+ * }
29
+ * }
30
+ * ```
31
+ *
32
+ * See {@link addExtraThemeEntries} for how these extra entries are added.
33
+ */
34
+ export declare function makeCSSVariableTheme<ThemeType extends Record<string | number, unknown>>(theme: ThemeType, printValue?: (path: string[], value: unknown) => string): DeepMapObjectLeafs<ThemeType, string>;
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ exports.__esModule = true;
3
+ exports.makeCSSVariableTheme = void 0;
4
+ var addExtraThemeEntries_1 = require("./addExtraThemeEntries");
5
+ var cssVariables_1 = require("./cssVariables");
6
+ var mapLeafsOfObject_1 = require("./mapLeafsOfObject");
7
+ /**
8
+ * This function could use a new name during a breaking change
9
+ *
10
+ * Given a Theme (which is the source of truth and doesn't contain any computed properties), add extra necessary properties to the tree such as `-rgb` suffixed keys with R, G, B triple values, and
11
+ * convert the leaf values of a theme to a value like `var(--parent1key-parent2key-leafkey)` - a CSS variable with an identifier that represents it's hierarchy.
12
+ *
13
+ * Example:
14
+ * ```
15
+ * {
16
+ * color: {
17
+ * purple: {
18
+ * 100: "#f0f1f4"
19
+ * }
20
+ * }
21
+ * }
22
+ * ```
23
+ * Transforms into:
24
+ * ```
25
+ * {
26
+ * color: {
27
+ * purple: {
28
+ * 100: "var(--color-purple-100, "#f0f1f4")",
29
+ * "100-rgb": "var(--color-purple-100-rgb, 240, 241, 244)",
30
+ * "100-id": "--color-purple-100",
31
+ * "100-rgb-id": "--color-purple-100-rgb"
32
+ * }
33
+ * }
34
+ * }
35
+ * ```
36
+ *
37
+ * See {@link addExtraThemeEntries} for how these extra entries are added.
38
+ */
39
+ function makeCSSVariableTheme(theme, printValue) {
40
+ if (printValue === void 0) { printValue = cssVariables_1.objectPathToCssVarFunction; }
41
+ var augmentedTheme = {};
42
+ var mapper = function (leafPath, value) {
43
+ var leafKey = leafPath[leafPath.length - 1];
44
+ var pathWithoutLast = leafPath.slice(0, leafPath.length - 1);
45
+ var leafObject = pathWithoutLast.reduce(function (child, segment) {
46
+ return (child[segment] || (child[segment] = {}));
47
+ }, augmentedTheme);
48
+ var cssVariablesOfToken = addExtraThemeEntries_1.addExtraThemeEntries(leafPath, leafKey, value, printValue, { augmentWithId: true });
49
+ Object.assign(leafObject, cssVariablesOfToken);
50
+ };
51
+ mapLeafsOfObject_1.mapLeafsOfObject(theme, mapper);
52
+ return augmentedTheme;
53
+ }
54
+ exports.makeCSSVariableTheme = makeCSSVariableTheme;
55
+ //# sourceMappingURL=makeCssVariableTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"makeCssVariableTheme.js","sourceRoot":"","sources":["makeCssVariableTheme.ts"],"names":[],"mappings":";;;AACA,+DAA6D;AAC7D,+CAA2D;AAC3D,uDAAqD;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,SAAgB,oBAAoB,CAElC,KAAgB,EAAE,UAAuC;IAAvC,2BAAA,EAAA,aAAa,yCAA0B;IACzD,IAAM,cAAc,GAA4B,EAAE,CAAA;IAClD,IAAM,MAAM,GAAG,UAAC,QAAkB,EAAE,KAAc;QAChD,IAAM,OAAO,GAAG,QAAQ,CAAC,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC7C,IAAM,eAAe,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,GAAG,CAAC,CAAC,CAAA;QAC9D,IAAM,UAAU,GAAG,eAAe,CAAC,MAAM,CACvC,UAAC,KAAK,EAAE,OAAO;YACb,OAAA,CAAC,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAA4B;QAApE,CAAoE,EACtE,cAAyC,CAC1C,CAAA;QACD,IAAM,mBAAmB,GAAG,2CAAoB,CAC9C,QAAQ,EACR,OAAO,EACP,KAAK,EACL,UAAU,EACV,EAAE,aAAa,EAAE,IAAI,EAAE,CACxB,CAAA;QACD,MAAM,CAAC,MAAM,CAAC,UAAU,EAAE,mBAAmB,CAAC,CAAA;IAChD,CAAC,CAAA;IAED,mCAAgB,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA;IAE/B,OAAO,cAAuD,CAAA;AAChE,CAAC;AAzBD,oDAyBC"}
@@ -0,0 +1,63 @@
1
+ import { DeepMapObjectLeafs } from "../types"
2
+ import { addExtraThemeEntries } from "./addExtraThemeEntries"
3
+ import { objectPathToCssVarFunction } from "./cssVariables"
4
+ import { mapLeafsOfObject } from "./mapLeafsOfObject"
5
+
6
+ /**
7
+ * This function could use a new name during a breaking change
8
+ *
9
+ * Given a Theme (which is the source of truth and doesn't contain any computed properties), add extra necessary properties to the tree such as `-rgb` suffixed keys with R, G, B triple values, and
10
+ * convert the leaf values of a theme to a value like `var(--parent1key-parent2key-leafkey)` - a CSS variable with an identifier that represents it's hierarchy.
11
+ *
12
+ * Example:
13
+ * ```
14
+ * {
15
+ * color: {
16
+ * purple: {
17
+ * 100: "#f0f1f4"
18
+ * }
19
+ * }
20
+ * }
21
+ * ```
22
+ * Transforms into:
23
+ * ```
24
+ * {
25
+ * color: {
26
+ * purple: {
27
+ * 100: "var(--color-purple-100, "#f0f1f4")",
28
+ * "100-rgb": "var(--color-purple-100-rgb, 240, 241, 244)",
29
+ * "100-id": "--color-purple-100",
30
+ * "100-rgb-id": "--color-purple-100-rgb"
31
+ * }
32
+ * }
33
+ * }
34
+ * ```
35
+ *
36
+ * See {@link addExtraThemeEntries} for how these extra entries are added.
37
+ */
38
+ export function makeCSSVariableTheme<
39
+ ThemeType extends Record<string | number, unknown>
40
+ >(theme: ThemeType, printValue = objectPathToCssVarFunction) {
41
+ const augmentedTheme: Record<string, unknown> = {}
42
+ const mapper = (leafPath: string[], value: unknown) => {
43
+ const leafKey = leafPath[leafPath.length - 1]
44
+ const pathWithoutLast = leafPath.slice(0, leafPath.length - 1)
45
+ const leafObject = pathWithoutLast.reduce(
46
+ (child, segment) =>
47
+ (child[segment] || (child[segment] = {})) as Record<string, unknown>,
48
+ augmentedTheme as Record<string, unknown>
49
+ )
50
+ const cssVariablesOfToken = addExtraThemeEntries(
51
+ leafPath,
52
+ leafKey,
53
+ value,
54
+ printValue,
55
+ { augmentWithId: true }
56
+ )
57
+ Object.assign(leafObject, cssVariablesOfToken)
58
+ }
59
+
60
+ mapLeafsOfObject(theme, mapper)
61
+
62
+ return augmentedTheme as DeepMapObjectLeafs<ThemeType, string>
63
+ }
@@ -0,0 +1,22 @@
1
+ import { DeepMapObjectLeafs } from "../types";
2
+ /**
3
+ * This allows you to map the leaf nodes of an object, and you're provided the path to that leaf as well as the value as parameters to your mapper function.
4
+ * This function was build to support mapping theme values to their respective CSS variable identifiers.
5
+ * For example:
6
+ * ```ts
7
+ * mapLeafsOfObject({
8
+ * one: {
9
+ * two: 4
10
+ * }
11
+ * }, (path, value) => value + 7)
12
+ * ```
13
+ * Results in:
14
+ * ```
15
+ * {
16
+ * one: {
17
+ * two: 11
18
+ * }
19
+ * }
20
+ * ```
21
+ */
22
+ export declare function mapLeafsOfObject<Obj extends Record<string | number, unknown>, Value>(object: Obj, mapper: (pathToLeaf: string[], value: unknown) => Value): DeepMapObjectLeafs<Obj, Value>;