@kaizen/design-tokens 10.5.2 → 10.6.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 (108) hide show
  1. package/css/variables.css +1 -1
  2. package/dist/cjs/index.cjs +18 -0
  3. package/dist/cjs/js/tokens.cjs +319 -0
  4. package/dist/cjs/legacy/ThemeManager.cjs +92 -0
  5. package/dist/cjs/legacy/ThemeProvider.cjs +82 -0
  6. package/dist/cjs/legacy/makeCssVariableDefinitionsMap.cjs +54 -0
  7. package/dist/{legacy/makeCssVariableTheme.js → cjs/legacy/makeCssVariableTheme.cjs} +27 -23
  8. package/dist/cjs/legacy/mapLeafsOfObject.cjs +46 -0
  9. package/dist/cjs/legacy/themes/heart.cjs +14 -0
  10. package/dist/cjs/legacy/themes/index.cjs +12 -0
  11. package/dist/cjs/lib/addExtraThemeEntries.cjs +52 -0
  12. package/dist/{lib/cssVariables.js → cjs/lib/cssVariables.cjs} +15 -11
  13. package/dist/cjs/lib/makeCssVariableDefinitionsMap.cjs +51 -0
  14. package/dist/cjs/lib/mapLeafsOfObject.cjs +43 -0
  15. package/dist/esm/index.mjs +7 -0
  16. package/dist/esm/js/tokens.mjs +317 -0
  17. package/dist/esm/legacy/ThemeManager.mjs +90 -0
  18. package/dist/esm/legacy/ThemeProvider.mjs +72 -0
  19. package/dist/esm/legacy/makeCssVariableDefinitionsMap.mjs +52 -0
  20. package/dist/esm/legacy/makeCssVariableTheme.mjs +62 -0
  21. package/dist/esm/legacy/mapLeafsOfObject.mjs +44 -0
  22. package/dist/esm/legacy/themes/heart.mjs +12 -0
  23. package/dist/esm/legacy/themes/index.mjs +9 -0
  24. package/dist/esm/lib/addExtraThemeEntries.mjs +44 -0
  25. package/dist/esm/lib/cssVariables.mjs +29 -0
  26. package/dist/esm/lib/makeCssVariableDefinitionsMap.mjs +49 -0
  27. package/dist/esm/lib/mapLeafsOfObject.mjs +41 -0
  28. package/dist/{index.d.ts → types/index.d.ts} +0 -1
  29. package/dist/types/js/index.d.ts +1 -0
  30. package/dist/{js → types/js}/tokens.d.ts +0 -1
  31. package/dist/{legacy → types/legacy}/ThemeManager.d.ts +0 -1
  32. package/dist/{legacy → types/legacy}/ThemeProvider.d.ts +2 -2
  33. package/dist/{legacy → types/legacy}/makeCssVariableDefinitionsMap.d.ts +0 -1
  34. package/dist/{legacy → types/legacy}/makeCssVariableTheme.d.ts +0 -1
  35. package/dist/{legacy → types/legacy}/mapLeafsOfObject.d.ts +0 -1
  36. package/dist/{legacy → types/legacy}/themes/heart.d.ts +0 -1
  37. package/dist/{legacy → types/legacy}/themes/index.d.ts +0 -1
  38. package/dist/{legacy → types/legacy}/types.d.ts +0 -1
  39. package/dist/{lib → types/lib}/__tests__/themeForTesting.d.ts +0 -1
  40. package/dist/{lib → types/lib}/addExtraThemeEntries.d.ts +0 -1
  41. package/dist/{lib → types/lib}/cssVariables.d.ts +0 -1
  42. package/dist/{lib → types/lib}/makeCssVariableDefinitionsMap.d.ts +0 -1
  43. package/dist/{lib → types/lib}/makeCssVariableTheme.d.ts +0 -1
  44. package/dist/{lib → types/lib}/mapLeafsOfObject.d.ts +0 -1
  45. package/dist/{lib → types/lib}/patterns.d.ts +0 -1
  46. package/dist/{types.d.ts → types/types.d.ts} +2 -1
  47. package/js/package.json +3 -2
  48. package/less/color.less +4 -0
  49. package/less/spacing.less +2 -0
  50. package/package.json +20 -12
  51. package/sass/color.scss +4 -0
  52. package/sass/spacing.scss +2 -0
  53. package/dist/index.d.ts.map +0 -1
  54. package/dist/index.js +0 -31
  55. package/dist/index.js.map +0 -1
  56. package/dist/js/index.d.ts +0 -2
  57. package/dist/js/index.d.ts.map +0 -1
  58. package/dist/js/index.js +0 -18
  59. package/dist/js/index.js.map +0 -1
  60. package/dist/js/tokens.d.ts.map +0 -1
  61. package/dist/js/tokens.js +0 -318
  62. package/dist/js/tokens.js.map +0 -1
  63. package/dist/legacy/ThemeManager.d.ts.map +0 -1
  64. package/dist/legacy/ThemeManager.js +0 -80
  65. package/dist/legacy/ThemeManager.js.map +0 -1
  66. package/dist/legacy/ThemeProvider.d.ts.map +0 -1
  67. package/dist/legacy/ThemeProvider.js +0 -77
  68. package/dist/legacy/ThemeProvider.js.map +0 -1
  69. package/dist/legacy/makeCssVariableDefinitionsMap.d.ts.map +0 -1
  70. package/dist/legacy/makeCssVariableDefinitionsMap.js +0 -60
  71. package/dist/legacy/makeCssVariableDefinitionsMap.js.map +0 -1
  72. package/dist/legacy/makeCssVariableTheme.d.ts.map +0 -1
  73. package/dist/legacy/makeCssVariableTheme.js.map +0 -1
  74. package/dist/legacy/mapLeafsOfObject.d.ts.map +0 -1
  75. package/dist/legacy/mapLeafsOfObject.js +0 -64
  76. package/dist/legacy/mapLeafsOfObject.js.map +0 -1
  77. package/dist/legacy/themes/heart.d.ts.map +0 -1
  78. package/dist/legacy/themes/heart.js +0 -22
  79. package/dist/legacy/themes/heart.js.map +0 -1
  80. package/dist/legacy/themes/index.d.ts.map +0 -1
  81. package/dist/legacy/themes/index.js +0 -13
  82. package/dist/legacy/themes/index.js.map +0 -1
  83. package/dist/legacy/types.d.ts.map +0 -1
  84. package/dist/legacy/types.js +0 -3
  85. package/dist/legacy/types.js.map +0 -1
  86. package/dist/lib/__tests__/themeForTesting.d.ts.map +0 -1
  87. package/dist/lib/__tests__/themeForTesting.js +0 -21
  88. package/dist/lib/__tests__/themeForTesting.js.map +0 -1
  89. package/dist/lib/addExtraThemeEntries.d.ts.map +0 -1
  90. package/dist/lib/addExtraThemeEntries.js +0 -60
  91. package/dist/lib/addExtraThemeEntries.js.map +0 -1
  92. package/dist/lib/cssVariables.d.ts.map +0 -1
  93. package/dist/lib/cssVariables.js.map +0 -1
  94. package/dist/lib/makeCssVariableDefinitionsMap.d.ts.map +0 -1
  95. package/dist/lib/makeCssVariableDefinitionsMap.js +0 -57
  96. package/dist/lib/makeCssVariableDefinitionsMap.js.map +0 -1
  97. package/dist/lib/makeCssVariableTheme.d.ts.map +0 -1
  98. package/dist/lib/makeCssVariableTheme.js +0 -57
  99. package/dist/lib/makeCssVariableTheme.js.map +0 -1
  100. package/dist/lib/mapLeafsOfObject.d.ts.map +0 -1
  101. package/dist/lib/mapLeafsOfObject.js +0 -61
  102. package/dist/lib/mapLeafsOfObject.js.map +0 -1
  103. package/dist/lib/patterns.d.ts.map +0 -1
  104. package/dist/lib/patterns.js +0 -6
  105. package/dist/lib/patterns.js.map +0 -1
  106. package/dist/types.d.ts.map +0 -1
  107. package/dist/types.js +0 -3
  108. package/dist/types.js.map +0 -1
@@ -0,0 +1,90 @@
1
+ import { makeCssVariableDefinitionsMap } from '../lib/makeCssVariableDefinitionsMap.mjs';
2
+
3
+ /**
4
+ * Use this class to set and apply themes, and to access or subscribe to the currently active one.
5
+ * This class fulfills the idea of theming and runtime theme switching by relying on CSS variables,
6
+ * and the ability to update them in JavaScript - a framework agnostic method.
7
+ *
8
+ * It works by converting a Theme interface to a flattened map of CSS variable keys and values, then calling `document.documentElement.style.setProperty(key, value)`.
9
+ */
10
+ /**
11
+ * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
12
+ *
13
+ * {@link https://cultureamp.design/?path=/docs/guides-app-starter--docs Check App Starter guidance}
14
+ */
15
+ var ThemeManager = /** @class */function () {
16
+ function ThemeManager(theme, rootElementId, /* This allows you to stop the class from applying the theme automatically during construction. Defaults to true */
17
+ apply) {
18
+ if (rootElementId === void 0) {
19
+ rootElementId = "";
20
+ }
21
+ if (apply === void 0) {
22
+ apply = true;
23
+ }
24
+ var _this = this;
25
+ this.themeChangeListeners = [];
26
+ this.rootElement = null;
27
+ this.getRootElement = function () {
28
+ return _this.rootElement;
29
+ };
30
+ this.getRootElementId = function () {
31
+ return _this.rootElementId;
32
+ };
33
+ this.getCurrentTheme = function () {
34
+ return _this.theme;
35
+ };
36
+ this.setRootElement = function (element) {
37
+ _this.rootElement = element;
38
+ };
39
+ this.setRootElementId = function (rootElementId) {
40
+ return _this.rootElementId = rootElementId;
41
+ };
42
+ this.setAndApplyTheme = function (theme, force) {
43
+ if (!force) {
44
+ if (_this.theme === theme) return;
45
+ }
46
+ _this.theme = theme;
47
+ _this.applyCurrentTheme();
48
+ _this.notifyThemeChangeListeners(theme);
49
+ };
50
+ this.addThemeChangeListener = function (listener) {
51
+ _this.themeChangeListeners.push(listener);
52
+ };
53
+ this.removeThemeChangeListener = function (listener) {
54
+ _this.themeChangeListeners = _this.themeChangeListeners.filter(function (l) {
55
+ return l !== listener;
56
+ });
57
+ };
58
+ this.applyCurrentTheme = function () {
59
+ var _a;
60
+ if (typeof window !== "undefined") {
61
+ _this.setRootElement((_a = document.getElementById(_this.rootElementId)) !== null && _a !== void 0 ? _a : document.documentElement);
62
+ var cssVariableDefinitions = makeCssVariableDefinitionsMap(_this.theme);
63
+ Object.entries(cssVariableDefinitions).forEach(function (_a) {
64
+ var _b;
65
+ var key = _a[0],
66
+ value = _a[1];
67
+ (_b = _this.rootElement) === null || _b === void 0 ? void 0 : _b.style.setProperty(key, value);
68
+ });
69
+ }
70
+ };
71
+ this.notifyThemeChangeListeners = function (theme) {
72
+ _this.themeChangeListeners.forEach(function (listener) {
73
+ return listener(theme);
74
+ });
75
+ };
76
+ /*
77
+ For some reason, storybook likes this way of defining class properties better.
78
+ If you use `constructor( private theme: Theme, ...)` - theme becomes undefined within the class's methods.
79
+ */
80
+ this.theme = theme;
81
+ this.rootElementId = rootElementId;
82
+ if (apply) this.applyCurrentTheme();
83
+ }
84
+ return ThemeManager;
85
+ }();
86
+ // I would like to expose this, but instantiating ThemeManager in some situations or runtimes (such as nodejs) cause exceptions.
87
+ // For now it is not exposed, but we might come back to it, as it makes sense to have a singleton ThemeManager in almost all cases
88
+ /* export const defaultThemeManager = new ThemeManager(defaultTheme) */
89
+
90
+ export { ThemeManager };
@@ -0,0 +1,72 @@
1
+ import { __rest } from 'tslib';
2
+ import React, { useState } from 'react';
3
+ import { ThemeManager } from './ThemeManager.mjs';
4
+ import { defaultTheme } from './themes/index.mjs';
5
+ var ThemeContext = /*#__PURE__*/React.createContext(defaultTheme);
6
+ /**
7
+ * Wrap your application in this provider using a ThemeManager, to synchronise it with a react context.
8
+ * This allows child react elements to more easily use theme variables, using the {@link useTheme} hook.
9
+ */
10
+ /**
11
+ * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
12
+ *
13
+ * {@link https://cultureamp.design/?path=/docs/guides-app-starter--docs Check App Starter guidance}
14
+ */
15
+ var ThemeProvider = function (_a) {
16
+ var themeManager = _a.themeManager,
17
+ props = __rest(_a, ["themeManager"]);
18
+ var themeManagerInstance = useState(function () {
19
+ return themeManager || new ThemeManager(defaultTheme);
20
+ })[0];
21
+ var _b = React.useState(themeManagerInstance.getCurrentTheme()),
22
+ theme = _b[0],
23
+ setTheme = _b[1];
24
+ React.useEffect(function () {
25
+ var cancelled = false;
26
+ var listener = function (newTheme) {
27
+ if (!cancelled) setTheme(newTheme);
28
+ };
29
+ themeManagerInstance.addThemeChangeListener(listener);
30
+ return function () {
31
+ cancelled = true;
32
+ themeManagerInstance.removeThemeChangeListener(listener);
33
+ };
34
+ }, []);
35
+ return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ThemeContext.Provider, {
36
+ value: theme
37
+ }, props.children), /*#__PURE__*/React.createElement("link", {
38
+ rel: "preload",
39
+ href: "https://d1e7r7b0lb8p4d.cloudfront.net/fonts/inter/inter-bold.woff2",
40
+ as: "font",
41
+ type: "font/woff2",
42
+ crossOrigin: "anonymous"
43
+ }), /*#__PURE__*/React.createElement("link", {
44
+ rel: "preload",
45
+ href: "https://d1e7r7b0lb8p4d.cloudfront.net/fonts/inter/inter-demi-bold.woff2",
46
+ as: "font",
47
+ type: "font/woff2",
48
+ crossOrigin: "anonymous"
49
+ }), /*#__PURE__*/React.createElement("link", {
50
+ rel: "preload",
51
+ href: "https://d1e7r7b0lb8p4d.cloudfront.net/fonts/inter/inter-medium.woff2",
52
+ as: "font",
53
+ type: "font/woff2",
54
+ crossOrigin: "anonymous"
55
+ }), /*#__PURE__*/React.createElement("link", {
56
+ rel: "preload",
57
+ href: "https://d1e7r7b0lb8p4d.cloudfront.net/fonts/inter/inter-regular.woff2",
58
+ as: "font",
59
+ type: "font/woff2",
60
+ crossOrigin: "anonymous"
61
+ }), /*#__PURE__*/React.createElement("link", {
62
+ rel: "preload",
63
+ href: "https://d1e7r7b0lb8p4d.cloudfront.net/fonts/tiempos/tiempos-headline-bold.woff2",
64
+ as: "font",
65
+ type: "font/woff2",
66
+ crossOrigin: "anonymous"
67
+ }));
68
+ };
69
+ var useTheme = function () {
70
+ return React.useContext(ThemeContext);
71
+ };
72
+ export { ThemeContext, ThemeProvider, useTheme };
@@ -0,0 +1,52 @@
1
+ import { __assign } from 'tslib';
2
+ import { addExtraThemeEntries } from '../lib/addExtraThemeEntries.mjs';
3
+ import { objectPathToCssVarIdentifier } from '../lib/cssVariables.mjs';
4
+ import { mapLeafsOfObject } from './mapLeafsOfObject.mjs';
5
+
6
+ /**
7
+
8
+ * Make a map of CSS variables -> values in a consistent way.
9
+ * Use this to, for example, create a CSS file that declares each theme variable on the `:root` pseudo element.
10
+ * Or for example when you're defining CSS variables using `rootElement.style.setProperty` within ThemeManager.
11
+ *
12
+ * It is paramount that this function defines every variable that {@link makeCssVariableTheme} expects to be defined.
13
+ * Otherwise, it's possible that a CSS variable token (something that looks like var(--color-purple-100-rgb)) won't have a matching defined
14
+ * CSS variable like `--color-purple-100-rgb: 123, 123, 123;`
15
+ *
16
+ *
17
+ * For example:
18
+ * Input:
19
+ * ```
20
+ * {
21
+ * color: {
22
+ * whatever: {
23
+ * 100: "#ff0022"
24
+ * }
25
+ * }
26
+ * }
27
+ * ```
28
+ * Output:
29
+ * ```
30
+ * {
31
+ * "--color-whatever-100": "#ff0022"
32
+ * }
33
+ */
34
+ /**
35
+ * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
36
+ */
37
+ function makeCssVariableDefinitionsMap(theme) {
38
+ var accumulatedCssVariables = {};
39
+ // Shamelessly using a map function like a forEach
40
+ mapLeafsOfObject(theme, function (path, value) {
41
+ // Key will be `--color-blah`
42
+ var key = objectPathToCssVarIdentifier(path);
43
+ var nextCssVariables = addExtraThemeEntries(path, key, value, function (_, v) {
44
+ return "".concat(v);
45
+ }, {
46
+ augmentWithId: false
47
+ });
48
+ accumulatedCssVariables = __assign(__assign({}, accumulatedCssVariables), nextCssVariables);
49
+ });
50
+ return accumulatedCssVariables;
51
+ }
52
+ export { makeCssVariableDefinitionsMap };
@@ -0,0 +1,62 @@
1
+ import { addExtraThemeEntries } from '../lib/addExtraThemeEntries.mjs';
2
+ import { objectPathToCssVarFunction } from '../lib/cssVariables.mjs';
3
+ import { mapLeafsOfObject } from '../lib/mapLeafsOfObject.mjs';
4
+
5
+ /**
6
+ * This function could use a new name during a breaking change
7
+ *
8
+ * 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
9
+ * 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.
10
+ *
11
+ * Example:
12
+ * ```
13
+ * {
14
+ * color: {
15
+ * purple: {
16
+ * 100: "#f0f1f4"
17
+ * }
18
+ * }
19
+ * }
20
+ * ```
21
+ * Transforms into:
22
+ * ```
23
+ * {
24
+ * color: {
25
+ * purple: {
26
+ * 100: "var(--color-purple-100, "#f0f1f4")",
27
+ * "100-rgb": "var(--color-purple-100-rgb, 240, 241, 244)",
28
+ * "100-id": "--color-purple-100",
29
+ * "100-rgb-id": "--color-purple-100-rgb"
30
+ * }
31
+ * }
32
+ * }
33
+ * ```
34
+ *
35
+ * See {@link addExtraThemeEntries} for how these extra entries are added.
36
+ */
37
+ /**
38
+ * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
39
+ */
40
+ function makeCSSVariableTheme(theme, printValue) {
41
+ if (printValue === void 0) {
42
+ printValue = objectPathToCssVarFunction;
43
+ }
44
+ var augmentedTheme = {};
45
+ var mapper = function (leafPath, value) {
46
+ var leafKey = leafPath[leafPath.length - 1];
47
+ var pathWithoutLast = leafPath.slice(0, leafPath.length - 1);
48
+ var leafObject = pathWithoutLast.reduce(function (child, segment) {
49
+ return child[segment] || (child[segment] = {});
50
+ }, augmentedTheme);
51
+ if (!leafKey) {
52
+ throw new Error("leafKey is undefined");
53
+ }
54
+ var cssVariablesOfToken = addExtraThemeEntries(leafPath, leafKey, value, printValue, {
55
+ augmentWithId: true
56
+ });
57
+ Object.assign(leafObject, cssVariablesOfToken);
58
+ };
59
+ mapLeafsOfObject(theme, mapper);
60
+ return augmentedTheme;
61
+ }
62
+ export { makeCSSVariableTheme };
@@ -0,0 +1,44 @@
1
+ import { __assign, __spreadArray } from 'tslib';
2
+
3
+ /**
4
+ * 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.
5
+ * This function was build to support mapping theme values to their respective CSS variable identifiers.
6
+ * For example:
7
+ * ```ts
8
+ * mapLeafsOfObject({
9
+ * one: {
10
+ * two: 4
11
+ * }
12
+ * }, (path, value) => value + 7)
13
+ * ```
14
+ * Results in:
15
+ * ```
16
+ * {
17
+ * one: {
18
+ * two: 11
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ /**
24
+ * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
25
+ */
26
+ function mapLeafsOfObject(object, mapper) {
27
+ var recurser = function (currentPath, obj) {
28
+ var handleEntry = function (key, value) {
29
+ var pathToKey = __spreadArray(__spreadArray([], currentPath, true), [key], false);
30
+ if (typeof value === "object" && value !== null && value !== undefined) {
31
+ return recurser(pathToKey, value);
32
+ }
33
+ return mapper(pathToKey, value);
34
+ };
35
+ return Object.entries(obj).reduce(function (acc, _a) {
36
+ var _b;
37
+ var nextKey = _a[0],
38
+ nextValue = _a[1];
39
+ return __assign(__assign({}, acc), (_b = {}, _b[nextKey] = handleEntry(nextKey, nextValue), _b));
40
+ }, {});
41
+ };
42
+ return recurser([], object);
43
+ }
44
+ export { mapLeafsOfObject };
@@ -0,0 +1,12 @@
1
+ import { __assign } from 'tslib';
2
+ import { tokens } from '../../js/tokens.mjs';
3
+
4
+ /**
5
+ * @deprecated
6
+ * - Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
7
+ * - If you require direct usage of these tokens in js you can `import { tokens } from "@kaizen/design-tokens/js"`
8
+ */
9
+ var heartTheme = __assign({
10
+ themeKey: "heart"
11
+ }, tokens);
12
+ export { heartTheme };
@@ -0,0 +1,9 @@
1
+ import { heartTheme } from './heart.mjs';
2
+
3
+ /**
4
+ * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
5
+ *
6
+ * {@link https://cultureamp.design/?path=/docs/guides-app-starter--docs Check App Starter guidance}
7
+ */
8
+ var defaultTheme = heartTheme;
9
+ export { defaultTheme, heartTheme };
@@ -0,0 +1,44 @@
1
+ import { __spreadArray } from 'tslib';
2
+ import colorString from 'color-string';
3
+ import { objectPathToCssVarIdentifier } from './cssVariables.mjs';
4
+
5
+ /**
6
+ * Use this to generate an object containing `${key}: value`, `${key}-rgb: r, g, b`, and/or `${key}-id: --color-blah-XXX`.
7
+ * This is for adding extra neighbouring properties to a theme.
8
+ * For example:
9
+ * Input:
10
+ * path: [color, purple, 100]
11
+ * key: 100
12
+ * value: #f0f1f4
13
+ * printValue: (path, v) => `var(--some-key, ${v})`
14
+ * options: {augmentWithId: true}
15
+ *
16
+ * Output: {
17
+ * "100": "var(--some-key, #f0f1f4)",
18
+ * "100-rgb": "var(--some-key, 240, 241, 244)",
19
+ * "100-id": "--color-purple-100"
20
+ * "100-rgb-id": "--color-purple-100-rgb"
21
+ * }
22
+ */
23
+ var addExtraThemeEntries = function (path, key, value, printValue, _a) {
24
+ var _b;
25
+ var augmentWithId = _a.augmentWithId;
26
+ var colorRgb = typeof value === "string" ? colorString.get.rgb(value) : null;
27
+ var result = (_b = {}, _b[key] = printValue(path, value), _b);
28
+ // Add the -rgb key containing the RGB triple of the color (if it is a color)
29
+ if (colorRgb) {
30
+ // If the value is a color, always convert to lowercase
31
+ result[key] = printValue(path, value).toLowerCase();
32
+ var rgbPath = __spreadArray(__spreadArray([], path, true), ["rgb"], false);
33
+ var rgbTriple = printValue(rgbPath, colorRgb.slice(0, 3).join(", "));
34
+ result["".concat(key, "-rgb")] = rgbTriple;
35
+ if (augmentWithId) {
36
+ result["".concat(key, "-rgb-id")] = objectPathToCssVarIdentifier(rgbPath);
37
+ }
38
+ }
39
+ if (augmentWithId) {
40
+ result["".concat(key, "-id")] = objectPathToCssVarIdentifier(path);
41
+ }
42
+ return result;
43
+ };
44
+ export { addExtraThemeEntries };
@@ -0,0 +1,29 @@
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
+ var objectPathToCssVarFunction = function (path, value) {
16
+ return "var(".concat(objectPathToCssVarIdentifier(path), ", ").concat(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
+ var objectPathToCssVarIdentifier = function (path) {
27
+ return "--".concat(path.map(kebab).join("-"));
28
+ };
29
+ export { objectPathToCssVarFunction, objectPathToCssVarIdentifier };
@@ -0,0 +1,49 @@
1
+ import { __assign } from 'tslib';
2
+ import { addExtraThemeEntries } from './addExtraThemeEntries.mjs';
3
+ import { objectPathToCssVarIdentifier } from './cssVariables.mjs';
4
+ import { mapLeafsOfObject } from './mapLeafsOfObject.mjs';
5
+
6
+ /**
7
+
8
+ * Make a map of CSS variables -> values in a consistent way.
9
+ * Use this to, for example, create a CSS file that declares each theme variable on the `:root` pseudo element.
10
+ * Or for example when you're defining CSS variables using `rootElement.style.setProperty` within ThemeManager.
11
+ *
12
+ * It is paramount that this function defines every variable that {@link makeCssVariableTheme} expects to be defined.
13
+ * Otherwise, it's possible that a CSS variable token (something that looks like var(--color-purple-100-rgb)) won't have a matching defined
14
+ * CSS variable like `--color-purple-100-rgb: 123, 123, 123;`
15
+ *
16
+ *
17
+ * For example:
18
+ * Input:
19
+ * ```
20
+ * {
21
+ * color: {
22
+ * whatever: {
23
+ * 100: "#ff0022"
24
+ * }
25
+ * }
26
+ * }
27
+ * ```
28
+ * Output:
29
+ * ```
30
+ * {
31
+ * "--color-whatever-100": "#ff0022"
32
+ * }
33
+ */
34
+ function makeCssVariableDefinitionsMap(theme) {
35
+ var accumulatedCssVariables = {};
36
+ // Shamelessly using a map function like a forEach
37
+ mapLeafsOfObject(theme, function (path, value) {
38
+ // Key will be `--color-blah`
39
+ var key = objectPathToCssVarIdentifier(path);
40
+ var nextCssVariables = addExtraThemeEntries(path, key, value, function (_, v) {
41
+ return "".concat(v);
42
+ }, {
43
+ augmentWithId: false
44
+ });
45
+ accumulatedCssVariables = __assign(__assign({}, accumulatedCssVariables), nextCssVariables);
46
+ });
47
+ return accumulatedCssVariables;
48
+ }
49
+ export { makeCssVariableDefinitionsMap };
@@ -0,0 +1,41 @@
1
+ import { __assign, __spreadArray } from 'tslib';
2
+
3
+ /**
4
+ * 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.
5
+ * This function was build to support mapping theme values to their respective CSS variable identifiers.
6
+ * For example:
7
+ * ```ts
8
+ * mapLeafsOfObject({
9
+ * one: {
10
+ * two: 4
11
+ * }
12
+ * }, (path, value) => value + 7)
13
+ * ```
14
+ * Results in:
15
+ * ```
16
+ * {
17
+ * one: {
18
+ * two: 11
19
+ * }
20
+ * }
21
+ * ```
22
+ */
23
+ function mapLeafsOfObject(object, mapper) {
24
+ var recurser = function (currentPath, obj) {
25
+ var handleEntry = function (key, value) {
26
+ var pathToKey = __spreadArray(__spreadArray([], currentPath, true), [key], false);
27
+ if (typeof value === "object" && value !== null && value !== undefined) {
28
+ return recurser(pathToKey, value);
29
+ }
30
+ return mapper(pathToKey, value);
31
+ };
32
+ return Object.entries(obj).reduce(function (acc, _a) {
33
+ var _b;
34
+ var nextKey = _a[0],
35
+ nextValue = _a[1];
36
+ return __assign(__assign({}, acc), (_b = {}, _b[nextKey] = handleEntry(nextKey, nextValue), _b));
37
+ }, {});
38
+ };
39
+ return recurser([], object);
40
+ }
41
+ export { mapLeafsOfObject };
@@ -5,4 +5,3 @@ export * from "./legacy/ThemeProvider";
5
5
  export { makeCssVariableDefinitionsMap } from "./legacy/makeCssVariableDefinitionsMap";
6
6
  export { makeCSSVariableTheme } from "./legacy/makeCssVariableTheme";
7
7
  export { mapLeafsOfObject } from "./legacy/mapLeafsOfObject";
8
- //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ export * from "./tokens";
@@ -1,3 +1,2 @@
1
1
  import { TokenStructure } from "../types";
2
2
  export declare const tokens: TokenStructure;
3
- //# sourceMappingURL=tokens.d.ts.map
@@ -28,4 +28,3 @@ export declare class ThemeManager<Theme extends BaseTheme = BaseTheme> {
28
28
  applyCurrentTheme: () => void;
29
29
  private notifyThemeChangeListeners;
30
30
  }
31
- //# sourceMappingURL=ThemeManager.d.ts.map
@@ -1,5 +1,6 @@
1
1
  import React from "react";
2
- import { ThemeManager, Theme } from "..";
2
+ import { ThemeManager } from "./ThemeManager";
3
+ import { Theme } from "./types";
3
4
  export declare const ThemeContext: React.Context<Theme>;
4
5
  /**
5
6
  * Wrap your application in this provider using a ThemeManager, to synchronise it with a react context.
@@ -15,4 +16,3 @@ export declare const ThemeProvider: ({ themeManager, ...props }: {
15
16
  children: React.ReactNode;
16
17
  }) => JSX.Element;
17
18
  export declare const useTheme: () => Theme;
18
- //# sourceMappingURL=ThemeProvider.d.ts.map
@@ -30,4 +30,3 @@
30
30
  * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
31
31
  */
32
32
  export declare function makeCssVariableDefinitionsMap(theme: Record<string | number, unknown>): Record<string, string>;
33
- //# sourceMappingURL=makeCssVariableDefinitionsMap.d.ts.map
@@ -35,4 +35,3 @@ import { DeepMapObjectLeafs } from "../types";
35
35
  * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
36
36
  */
37
37
  export declare function makeCSSVariableTheme<ThemeType extends Record<string | number, unknown>>(theme: ThemeType, printValue?: (path: string[], value: unknown) => string): DeepMapObjectLeafs<ThemeType, string>;
38
- //# sourceMappingURL=makeCssVariableTheme.d.ts.map
@@ -23,4 +23,3 @@ import { DeepMapObjectLeafs } from "../types";
23
23
  * @deprecated Not needed if you are using `KaizenProvider` from `@kaizen/components` or `defaultPreset` from next-services.
24
24
  */
25
25
  export declare function mapLeafsOfObject<Obj extends Record<string | number, unknown>, Value>(object: Obj, mapper: (pathToLeaf: string[], value: unknown) => Value): DeepMapObjectLeafs<Obj, Value>;
26
- //# sourceMappingURL=mapLeafsOfObject.d.ts.map
@@ -5,4 +5,3 @@ import { Theme } from "../types";
5
5
  * - If you require direct usage of these tokens in js you can `import { tokens } from "@kaizen/design-tokens/js"`
6
6
  */
7
7
  export declare const heartTheme: Theme;
8
- //# sourceMappingURL=heart.d.ts.map
@@ -5,4 +5,3 @@ export { heartTheme } from "./heart";
5
5
  * {@link https://cultureamp.design/?path=/docs/guides-app-starter--docs Check App Starter guidance}
6
6
  */
7
7
  export declare const defaultTheme: import("../types").Theme;
8
- //# sourceMappingURL=index.d.ts.map
@@ -239,4 +239,3 @@ export type DeepMapObjectLeafs<T, LeafType> = T extends string | number | bigint
239
239
  */
240
240
  export type CSSVariableTheme = DeepMapObjectLeafs<Theme, string>;
241
241
  export {};
242
- //# sourceMappingURL=types.d.ts.map
@@ -36,4 +36,3 @@ export declare const themeForTesting: {
36
36
  };
37
37
  };
38
38
  };
39
- //# sourceMappingURL=themeForTesting.d.ts.map
@@ -20,4 +20,3 @@ export declare const addExtraThemeEntries: (path: string[], key: string, value:
20
20
  /** Setting this to true will add `${key}-id` and ${key}-rgb-id` */
21
21
  augmentWithId: boolean;
22
22
  }) => Record<string, string>;
23
- //# sourceMappingURL=addExtraThemeEntries.d.ts.map
@@ -20,4 +20,3 @@ export declare const objectPathToCssVarFunction: (path: string[], value: unknown
20
20
  * Output: "--color-wisteria-100"
21
21
  */
22
22
  export declare const objectPathToCssVarIdentifier: (path: string[]) => string;
23
- //# sourceMappingURL=cssVariables.d.ts.map
@@ -27,4 +27,3 @@
27
27
  * }
28
28
  */
29
29
  export declare function makeCssVariableDefinitionsMap(theme: Record<string | number, unknown>): Record<string, string>;
30
- //# sourceMappingURL=makeCssVariableDefinitionsMap.d.ts.map
@@ -32,4 +32,3 @@ import { DeepMapObjectLeafs } from "../legacy/types";
32
32
  * See {@link addExtraThemeEntries} for how these extra entries are added.
33
33
  */
34
34
  export declare function makeCSSVariableTheme<ThemeType extends Record<string | number, unknown>>(theme: ThemeType, printValue?: (path: string[], value: unknown) => string): DeepMapObjectLeafs<ThemeType, string>;
35
- //# sourceMappingURL=makeCssVariableTheme.d.ts.map
@@ -20,4 +20,3 @@ import { DeepMapObjectLeafs } from "../legacy/types";
20
20
  * ```
21
21
  */
22
22
  export declare function mapLeafsOfObject<Obj extends Record<string | number, unknown>, Value>(object: Obj, mapper: (pathToLeaf: string[], value: unknown) => Value): DeepMapObjectLeafs<Obj, Value>;
23
- //# sourceMappingURL=mapLeafsOfObject.d.ts.map
@@ -1,3 +1,2 @@
1
1
  export declare const zenColorNamePattern: RegExp;
2
2
  export declare const heartColorNamePattern: RegExp;
3
- //# sourceMappingURL=patterns.d.ts.map
@@ -135,6 +135,7 @@ export type TokenStructure = {
135
135
  "600": Hex;
136
136
  };
137
137
  white: Hex;
138
+ black: Hex;
138
139
  };
139
140
  dataViz: {
140
141
  favorable: Hex;
@@ -177,6 +178,7 @@ export type TokenStructure = {
177
178
  8: string;
178
179
  12: string;
179
180
  16: string;
181
+ 20: string;
180
182
  24: string;
181
183
  32: string;
182
184
  40: string;
@@ -229,4 +231,3 @@ export type DeepMapObjectLeafs<T, LeafType> = T extends string | number | bigint
229
231
  */
230
232
  export type CSSVariableTheme = DeepMapObjectLeafs<TokenStructure, string>;
231
233
  export {};
232
- //# sourceMappingURL=types.d.ts.map
package/js/package.json CHANGED
@@ -1,4 +1,5 @@
1
1
  {
2
- "main": "../dist/js/index.js",
3
- "types": "../dist/js/index.d.ts"
2
+ "main": "../dist/cjs/js/tokens.cjs",
3
+ "module": "../dist/esm/js/tokens.mjs",
4
+ "types": "../dist/types/js/index.d.ts"
4
5
  }