@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.
- package/CHANGELOG.md +773 -0
- package/LICENSE +21 -0
- package/README.md +66 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +23 -0
- package/dist/react/ThemeProvider.d.ts +13 -0
- package/dist/react/ThemeProvider.d.ts.map +1 -0
- package/dist/react/ThemeProvider.js +42 -0
- package/dist/react/index.d.ts +2 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +13 -0
- package/dist/src/ThemeManager.d.ts +23 -0
- package/dist/src/ThemeManager.d.ts.map +1 -0
- package/dist/src/ThemeManager.js +70 -0
- package/dist/src/lib/addExtraThemeEntries.d.ts +25 -0
- package/dist/src/lib/addExtraThemeEntries.d.ts.map +1 -0
- package/dist/src/lib/addExtraThemeEntries.js +56 -0
- package/dist/src/lib/cssVariables.d.ts +23 -0
- package/dist/src/lib/cssVariables.d.ts.map +1 -0
- package/dist/src/lib/cssVariables.js +33 -0
- package/dist/src/lib/makeCssVariableDefinitionsMap.d.ts +30 -0
- package/dist/src/lib/makeCssVariableDefinitionsMap.d.ts.map +1 -0
- package/dist/src/lib/makeCssVariableDefinitionsMap.js +57 -0
- package/dist/src/lib/makeCssVariableTheme.d.ts +35 -0
- package/dist/src/lib/makeCssVariableTheme.d.ts.map +1 -0
- package/dist/src/lib/makeCssVariableTheme.js +54 -0
- package/dist/src/lib/mapLeafsOfObject.d.ts +23 -0
- package/dist/src/lib/mapLeafsOfObject.d.ts.map +1 -0
- package/dist/src/lib/mapLeafsOfObject.js +59 -0
- package/dist/src/themes/heart.d.ts +3 -0
- package/dist/src/themes/heart.d.ts.map +1 -0
- package/dist/src/themes/heart.js +286 -0
- package/dist/src/themes/index.d.ts +4 -0
- package/dist/src/themes/index.d.ts.map +1 -0
- package/dist/src/themes/index.js +9 -0
- package/dist/src/themes/zen.d.ts +3 -0
- package/dist/src/themes/zen.d.ts.map +1 -0
- package/dist/src/themes/zen.js +293 -0
- package/dist/src/types.d.ts +205 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/elm/Kaizen/Theme.elm +29 -0
- package/index.ts +9 -0
- package/less/animation.less +49 -0
- package/less/border.less +47 -0
- package/less/color.less +210 -0
- package/less/layout.less +8 -0
- package/less/shadow.less +12 -0
- package/less/spacing.less +20 -0
- package/less/typography.less +526 -0
- package/package.json +63 -0
- package/react/ThemeProvider.d.ts +12 -0
- package/react/ThemeProvider.js +43 -0
- package/react/ThemeProvider.js.map +1 -0
- package/react/ThemeProvider.tsx +39 -0
- package/react/index.d.ts +1 -0
- package/react/index.js +14 -0
- package/react/index.js.map +1 -0
- package/react/index.tsx +1 -0
- package/sass/animation.scss +49 -0
- package/sass/border.scss +47 -0
- package/sass/color.scss +210 -0
- package/sass/layout.scss +8 -0
- package/sass/shadow.scss +12 -0
- package/sass/spacing.scss +20 -0
- package/sass/typography.scss +526 -0
- package/src/ThemeManager.d.ts +22 -0
- package/src/ThemeManager.js +71 -0
- package/src/ThemeManager.js.map +1 -0
- package/src/ThemeManager.ts +70 -0
- package/src/lib/__tests__/themeForTesting.d.ts +38 -0
- package/src/lib/__tests__/themeForTesting.js +21 -0
- package/src/lib/__tests__/themeForTesting.js.map +1 -0
- package/src/lib/__tests__/themeForTesting.ts +17 -0
- package/src/lib/addExtraThemeEntries.d.ts +24 -0
- package/src/lib/addExtraThemeEntries.js +57 -0
- package/src/lib/addExtraThemeEntries.js.map +1 -0
- package/src/lib/addExtraThemeEntries.ts +56 -0
- package/src/lib/cssVariables.d.ts +22 -0
- package/src/lib/cssVariables.js +34 -0
- package/src/lib/cssVariables.js.map +1 -0
- package/src/lib/cssVariables.ts +27 -0
- package/src/lib/makeCssVariableDefinitionsMap.d.ts +29 -0
- package/src/lib/makeCssVariableDefinitionsMap.js +58 -0
- package/src/lib/makeCssVariableDefinitionsMap.js.map +1 -0
- package/src/lib/makeCssVariableDefinitionsMap.ts +55 -0
- package/src/lib/makeCssVariableTheme.d.ts +34 -0
- package/src/lib/makeCssVariableTheme.js +55 -0
- package/src/lib/makeCssVariableTheme.js.map +1 -0
- package/src/lib/makeCssVariableTheme.ts +63 -0
- package/src/lib/mapLeafsOfObject.d.ts +22 -0
- package/src/lib/mapLeafsOfObject.js +60 -0
- package/src/lib/mapLeafsOfObject.js.map +1 -0
- package/src/lib/mapLeafsOfObject.ts +50 -0
- package/src/lib/patterns.d.ts +2 -0
- package/src/lib/patterns.js +6 -0
- package/src/lib/patterns.js.map +1 -0
- package/src/lib/patterns.ts +2 -0
- package/src/themes/heart.d.ts +2 -0
- package/src/themes/heart.js +287 -0
- package/src/themes/heart.js.map +1 -0
- package/src/themes/heart.ts +285 -0
- package/src/themes/index.d.ts +3 -0
- package/src/themes/index.js +17 -0
- package/src/themes/index.js.map +1 -0
- package/src/themes/index.ts +4 -0
- package/src/themes/zen.d.ts +2 -0
- package/src/themes/zen.js +294 -0
- package/src/themes/zen.js.map +1 -0
- package/src/themes/zen.ts +292 -0
- package/src/types.d.ts +204 -0
- package/src/types.js +3 -0
- package/src/types.js.map +1 -0
- package/src/types.ts +225 -0
- package/tokens/animation.json +34 -0
- package/tokens/animation.json.d.ts +12 -0
- package/tokens/border.json +44 -0
- package/tokens/border.json.d.ts +12 -0
- package/tokens/color.json +228 -0
- package/tokens/color.json.d.ts +12 -0
- package/tokens/layout.json +9 -0
- package/tokens/layout.json.d.ts +12 -0
- package/tokens/shadow.json +12 -0
- package/tokens/shadow.json.d.ts +12 -0
- package/tokens/spacing.json +22 -0
- package/tokens/spacing.json.d.ts +12 -0
- package/tokens/typography.json +236 -0
- package/tokens/typography.json.d.ts +12 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Culture Amp Pty Ltd
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Kaizen Tokens
|
|
2
|
+
|
|
3
|
+
Design tokens for all platforms.
|
|
4
|
+
|
|
5
|
+
## About
|
|
6
|
+
|
|
7
|
+
Design tokens are named and stored visual design traits, including colors, typography, and animation timings. Design Tokens are the heart of every Design System.
|
|
8
|
+
|
|
9
|
+
The tokens represented here are platform-agnostic (JSON), as this will help us contribute to & facilitate the maintenance of living style guides. This package defines all the option tokens in Kaizen.
|
|
10
|
+
|
|
11
|
+
- **Option tokens** offer options. For example, `$color-purple-500: #898ba9;` is one color option available.
|
|
12
|
+
- **Decision tokens** communicate decisions about when to apply an option token to a context. For example, the color used for text is a decision.
|
|
13
|
+
|
|
14
|
+
In its current state this package supports Sass and Less variables, generated from a JSON tokens file.
|
|
15
|
+
|
|
16
|
+
**Please note** that the helpers in this package are specifically for accessing and using these design tokens. Component-specific helpers are best suited for kaizen-component-library.
|
|
17
|
+
|
|
18
|
+
As of V3, design tokens are also **themable**; they are intended to be used as if they can be **switched at runtime**. Because of this, we employ [CSS Variables](https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties)
|
|
19
|
+
to support this feature, so when consuming tokens in SASS/LESS you should assume they will contain values such as `var(--color-...)`, rather than concrete values such as `1.5rem` or `#fff`.
|
|
20
|
+
These values are supplied by the ThemeManager.
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```sh
|
|
27
|
+
yarn add @kaizen/design-tokens
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Usage
|
|
31
|
+
|
|
32
|
+
### Sass
|
|
33
|
+
|
|
34
|
+
```scss
|
|
35
|
+
## Note helper functions are provided
|
|
36
|
+
@import "~@kaizen/design-tokens/sass/[color/depth/layout/spacing/typography/helpers]";
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
### Less
|
|
40
|
+
|
|
41
|
+
```
|
|
42
|
+
## Note helper functions are provided
|
|
43
|
+
@import "~@kaizen/design-tokens/less/[color/depth/layout/spacing/typography/helpers]";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
### JavaScript
|
|
47
|
+
|
|
48
|
+
```
|
|
49
|
+
import * as tokens from @kaizen/design-tokens/tokens/[color/depth/layout/spacing/typography]
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Where possible, we keep things unitless.
|
|
53
|
+
|
|
54
|
+
When adding support for another target the transformation should add the appropriate unit to the artefact. For example, converting typography sizes to Sass/Less should add REM.
|
|
55
|
+
|
|
56
|
+
### Web
|
|
57
|
+
|
|
58
|
+
All values in tokens are represented as rem, em or px.
|
|
59
|
+
|
|
60
|
+
* Use REMs for sizes and spacing (grid).
|
|
61
|
+
* Use EMs for media queries.
|
|
62
|
+
* Use px for borders.
|
|
63
|
+
|
|
64
|
+
## Contributing
|
|
65
|
+
|
|
66
|
+
See [CONTRIBUTING.md](https://github.com/cultureamp/kaizen-design-system/blob/master/packages/design-tokens/CONTRIBUTING.md)
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export * from "./src/themes";
|
|
2
|
+
export * from "./src/types";
|
|
3
|
+
export * from "./src/ThemeManager";
|
|
4
|
+
export * from "./react";
|
|
5
|
+
export { makeCssVariableDefinitionsMap } from "./src/lib/makeCssVariableDefinitionsMap";
|
|
6
|
+
export { makeCSSVariableTheme } from "./src/lib/makeCssVariableTheme";
|
|
7
|
+
export { mapLeafsOfObject } from "./src/lib/mapLeafsOfObject";
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AACA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,oBAAoB,CAAA;AAClC,cAAc,SAAS,CAAA;AAEvB,OAAO,EAAE,6BAA6B,EAAE,MAAM,yCAAyC,CAAA;AACvF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gCAAgC,CAAA;AACrE,OAAO,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
// These are exposed at the top level because it seems like they are the most useful and relevent to usage of design tokens.
|
|
14
|
+
__exportStar(require("./src/themes"), exports);
|
|
15
|
+
__exportStar(require("./src/types"), exports);
|
|
16
|
+
__exportStar(require("./src/ThemeManager"), exports);
|
|
17
|
+
__exportStar(require("./react"), exports);
|
|
18
|
+
var makeCssVariableDefinitionsMap_1 = require("./src/lib/makeCssVariableDefinitionsMap");
|
|
19
|
+
Object.defineProperty(exports, "makeCssVariableDefinitionsMap", { enumerable: true, get: function () { return makeCssVariableDefinitionsMap_1.makeCssVariableDefinitionsMap; } });
|
|
20
|
+
var makeCssVariableTheme_1 = require("./src/lib/makeCssVariableTheme");
|
|
21
|
+
Object.defineProperty(exports, "makeCSSVariableTheme", { enumerable: true, get: function () { return makeCssVariableTheme_1.makeCSSVariableTheme; } });
|
|
22
|
+
var mapLeafsOfObject_1 = require("./src/lib/mapLeafsOfObject");
|
|
23
|
+
Object.defineProperty(exports, "mapLeafsOfObject", { enumerable: true, get: function () { return mapLeafsOfObject_1.mapLeafsOfObject; } });
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { ThemeManager, Theme } from "../";
|
|
3
|
+
export declare const ThemeContext: React.Context<Theme>;
|
|
4
|
+
/**
|
|
5
|
+
* Wrap your application in this provider using a ThemeManager, to synchronise it with a react context.
|
|
6
|
+
* This allows child react elements to more easily use theme variables, using the {@link useTheme} hook.
|
|
7
|
+
*/
|
|
8
|
+
export declare const ThemeProvider: ({ themeManager, ...props }: {
|
|
9
|
+
themeManager: ThemeManager;
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
}) => JSX.Element;
|
|
12
|
+
export declare const useTheme: () => Theme;
|
|
13
|
+
//# sourceMappingURL=ThemeProvider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeProvider.d.ts","sourceRoot":"","sources":["../../react/ThemeProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,EAAE,YAAY,EAAgB,KAAK,EAAE,MAAM,KAAK,CAAA;AAEvD,eAAO,MAAM,YAAY,sBAA2C,CAAA;AAEpE;;;GAGG;AACH,eAAO,MAAM,aAAa;kBAIV,YAAY;cAChB,KAAK,CAAC,SAAS;iBAsB1B,CAAA;AAED,eAAO,MAAM,QAAQ,aAAuC,CAAA"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
14
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.useTheme = exports.ThemeProvider = exports.ThemeContext = void 0;
|
|
18
|
+
var react_1 = __importDefault(require("react"));
|
|
19
|
+
var __1 = require("../");
|
|
20
|
+
exports.ThemeContext = react_1.default.createContext(__1.defaultTheme);
|
|
21
|
+
/**
|
|
22
|
+
* Wrap your application in this provider using a ThemeManager, to synchronise it with a react context.
|
|
23
|
+
* This allows child react elements to more easily use theme variables, using the {@link useTheme} hook.
|
|
24
|
+
*/
|
|
25
|
+
exports.ThemeProvider = function (_a) {
|
|
26
|
+
var themeManager = _a.themeManager, props = __rest(_a, ["themeManager"]);
|
|
27
|
+
var _b = react_1.default.useState(themeManager.getCurrentTheme()), theme = _b[0], setTheme = _b[1];
|
|
28
|
+
react_1.default.useEffect(function () {
|
|
29
|
+
var cancelled = false;
|
|
30
|
+
var listener = function (newTheme) {
|
|
31
|
+
if (!cancelled)
|
|
32
|
+
setTheme(newTheme);
|
|
33
|
+
};
|
|
34
|
+
themeManager.addThemeChangeListener(listener);
|
|
35
|
+
return function () {
|
|
36
|
+
cancelled = true;
|
|
37
|
+
themeManager.removeThemeChangeListener(listener);
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
return (react_1.default.createElement(exports.ThemeContext.Provider, { value: theme }, props.children));
|
|
41
|
+
};
|
|
42
|
+
exports.useTheme = function () { return react_1.default.useContext(exports.ThemeContext); };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../react/index.tsx"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./ThemeProvider"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Theme as BaseTheme } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Use this class to set and apply themes, and to access or subscribe to the currently active one.
|
|
4
|
+
* This class fulfills the idea of theming and runtime theme switching by relying on CSS variables,
|
|
5
|
+
* and the ability to update them in JavaScript - a framework agnostic method.
|
|
6
|
+
*
|
|
7
|
+
* 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)`.
|
|
8
|
+
*/
|
|
9
|
+
export declare class ThemeManager<Theme extends BaseTheme = BaseTheme> {
|
|
10
|
+
private themeChangeListeners;
|
|
11
|
+
private theme;
|
|
12
|
+
private rootElement;
|
|
13
|
+
constructor(theme: Theme, rootElement?: HTMLElement, apply?: boolean);
|
|
14
|
+
getRootElement: () => HTMLElement;
|
|
15
|
+
getCurrentTheme: () => Theme;
|
|
16
|
+
setRootElement: (element: HTMLElement) => void;
|
|
17
|
+
setAndApplyTheme: (theme: Theme, force?: boolean | undefined) => void;
|
|
18
|
+
addThemeChangeListener: (listener: (theme: Theme) => void) => void;
|
|
19
|
+
removeThemeChangeListener: (listener: (theme: Theme) => void) => void;
|
|
20
|
+
applyCurrentTheme: () => void;
|
|
21
|
+
private notifyThemeChangeListeners;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=ThemeManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ThemeManager.d.ts","sourceRoot":"","sources":["../../src/ThemeManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,IAAI,SAAS,EAAE,MAAM,SAAS,CAAA;AAE5C;;;;;;GAMG;AACH,qBAAa,YAAY,CAAC,KAAK,SAAS,SAAS,GAAG,SAAS;IAC3D,OAAO,CAAC,oBAAoB,CAAsC;IAClE,OAAO,CAAC,KAAK,CAAO;IACpB,OAAO,CAAC,WAAW,CAA2B;gBAE5C,KAAK,EAAE,KAAK,EACZ,WAAW,cAA2B,EAEtC,KAAK,GAAE,OAAc;IAWhB,cAAc,oBAAyB;IACvC,eAAe,cAAmB;IAElC,cAAc,YAAa,WAAW,UAE5C;IACM,gBAAgB,UAAW,KAAK,uCAOtC;IAEM,sBAAsB,qBAAsB,KAAK,KAAK,IAAI,UAEhE;IACM,yBAAyB,qBAAsB,KAAK,KAAK,IAAI,UAInE;IACM,iBAAiB,aASvB;IAED,OAAO,CAAC,0BAA0B,CAEjC;CACF"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ThemeManager = void 0;
|
|
4
|
+
var makeCssVariableDefinitionsMap_1 = require("./lib/makeCssVariableDefinitionsMap");
|
|
5
|
+
/**
|
|
6
|
+
* Use this class to set and apply themes, and to access or subscribe to the currently active one.
|
|
7
|
+
* This class fulfills the idea of theming and runtime theme switching by relying on CSS variables,
|
|
8
|
+
* and the ability to update them in JavaScript - a framework agnostic method.
|
|
9
|
+
*
|
|
10
|
+
* 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)`.
|
|
11
|
+
*/
|
|
12
|
+
var ThemeManager = /** @class */ (function () {
|
|
13
|
+
function ThemeManager(theme, rootElement,
|
|
14
|
+
/* This allows you to stop the class from applying the theme automatically during construction. Defaults to true */
|
|
15
|
+
apply) {
|
|
16
|
+
var _this = this;
|
|
17
|
+
if (rootElement === void 0) { rootElement = document.documentElement; }
|
|
18
|
+
if (apply === void 0) { apply = true; }
|
|
19
|
+
this.themeChangeListeners = [];
|
|
20
|
+
this.rootElement = document.documentElement;
|
|
21
|
+
this.getRootElement = function () { return _this.rootElement; };
|
|
22
|
+
this.getCurrentTheme = function () { return _this.theme; };
|
|
23
|
+
this.setRootElement = function (element) {
|
|
24
|
+
_this.rootElement = element;
|
|
25
|
+
};
|
|
26
|
+
this.setAndApplyTheme = function (theme, force) {
|
|
27
|
+
if (!force) {
|
|
28
|
+
if (_this.theme === theme)
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
_this.theme = theme;
|
|
32
|
+
_this.applyCurrentTheme();
|
|
33
|
+
_this.notifyThemeChangeListeners(theme);
|
|
34
|
+
};
|
|
35
|
+
this.addThemeChangeListener = function (listener) {
|
|
36
|
+
_this.themeChangeListeners.push(listener);
|
|
37
|
+
};
|
|
38
|
+
this.removeThemeChangeListener = function (listener) {
|
|
39
|
+
_this.themeChangeListeners = _this.themeChangeListeners.filter(function (l) { return l !== listener; });
|
|
40
|
+
};
|
|
41
|
+
this.applyCurrentTheme = function () {
|
|
42
|
+
var cssVariableDefinitions = makeCssVariableDefinitionsMap_1.makeCssVariableDefinitionsMap(_this.theme);
|
|
43
|
+
Object.entries(cssVariableDefinitions).forEach(function (_a) {
|
|
44
|
+
var key = _a[0], value = _a[1];
|
|
45
|
+
if (_this.theme.themeKey === "zen") {
|
|
46
|
+
_this.rootElement.style.removeProperty(key);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
_this.rootElement.style.setProperty(key, value);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
};
|
|
53
|
+
this.notifyThemeChangeListeners = function (theme) {
|
|
54
|
+
_this.themeChangeListeners.forEach(function (listener) { return listener(theme); });
|
|
55
|
+
};
|
|
56
|
+
/*
|
|
57
|
+
For some reason, storybook likes this way of defining class properties better.
|
|
58
|
+
If you use `constructor( private theme: Theme, ...)` - theme becomes undefined within the class's methods.
|
|
59
|
+
*/
|
|
60
|
+
this.theme = theme;
|
|
61
|
+
this.rootElement = rootElement;
|
|
62
|
+
if (apply)
|
|
63
|
+
this.applyCurrentTheme();
|
|
64
|
+
}
|
|
65
|
+
return ThemeManager;
|
|
66
|
+
}());
|
|
67
|
+
exports.ThemeManager = ThemeManager;
|
|
68
|
+
// I would like to expose this, but instantiating ThemeManager in some situations or runtimes (such as nodejs) cause exceptions.
|
|
69
|
+
// 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
|
|
70
|
+
/* export const defaultThemeManager = new ThemeManager(defaultTheme) */
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
};
|
|
25
|
+
//# sourceMappingURL=addExtraThemeEntries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"addExtraThemeEntries.d.ts","sourceRoot":"","sources":["../../../src/lib/addExtraThemeEntries.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,oBAAoB,SACzB,MAAM,EAAE,OACT,MAAM,SACJ,OAAO,wBACQ,MAAM,EAAE,eAAe,MAAM;IAIjD,mEAAmE;mBACpD,OAAO;;;CAyBzB,CAAA"}
|
|
@@ -0,0 +1,56 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: 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
|
+
};
|
|
@@ -0,0 +1,23 @@
|
|
|
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;
|
|
23
|
+
//# sourceMappingURL=cssVariables.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cssVariables.d.ts","sourceRoot":"","sources":["../../../src/lib/cssVariables.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,0BAA0B,SAAU,MAAM,EAAE,SAAS,OAAO,WACjB,CAAA;AAExD;;;;;;;GAOG;AACH,eAAO,MAAM,4BAA4B,SAAU,MAAM,EAAE,WACzB,CAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: 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
|
+
};
|
|
@@ -0,0 +1,30 @@
|
|
|
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>;
|
|
30
|
+
//# sourceMappingURL=makeCssVariableDefinitionsMap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeCssVariableDefinitionsMap.d.ts","sourceRoot":"","sources":["../../../src/lib/makeCssVariableDefinitionsMap.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,wBAAgB,6BAA6B,CAC3C,KAAK,EAAE,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,0BAqBxC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
+
Object.defineProperty(exports, "__esModule", { value: 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;
|
|
@@ -0,0 +1,35 @@
|
|
|
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>;
|
|
35
|
+
//# sourceMappingURL=makeCssVariableTheme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"makeCssVariableTheme.d.ts","sourceRoot":"","sources":["../../../src/lib/makeCssVariableTheme.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,UAAU,CAAA;AAK7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,wBAAgB,oBAAoB,CAClC,SAAS,SAAS,MAAM,CAAC,MAAM,GAAG,MAAM,EAAE,OAAO,CAAC,EAClD,KAAK,EAAE,SAAS,EAAE,UAAU,6CAA6B,yCAuB1D"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: 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;
|