@animus-ui/theming 0.1.1-beta.25 → 0.1.1-beta.26
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 +4 -0
- package/dist/core/ThemeBuilder.d.ts +34 -34
- package/dist/index.d.ts +1 -1
- package/dist/index.js +110 -141
- package/dist/utils/createTheme.d.ts +53 -53
- package/dist/utils/flattenScale.d.ts +20 -20
- package/dist/utils/index.d.ts +3 -3
- package/dist/utils/serializeTokens.d.ts +19 -19
- package/dist/utils/types.d.ts +41 -41
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [0.1.1-beta.26](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.25...@animus-ui/theming@0.1.1-beta.26) (2025-05-29)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @animus-ui/theming
|
|
9
|
+
|
|
6
10
|
## [0.1.1-beta.25](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.24...@animus-ui/theming@0.1.1-beta.25) (2023-03-15)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @animus-ui/theming
|
|
@@ -1,34 +1,34 @@
|
|
|
1
|
-
import { Breakpoints } from '@animus-ui/core';
|
|
2
|
-
/**
|
|
3
|
-
* 1. Breakpoints
|
|
4
|
-
* 2. Scales
|
|
5
|
-
* 3. Tokens
|
|
6
|
-
* 4. Variables
|
|
7
|
-
* 5. Colors
|
|
8
|
-
* 6. Color Modes
|
|
9
|
-
*/
|
|
10
|
-
export declare class ThemeWithAll<Bps, Scales, Tokens, Vars> {
|
|
11
|
-
breakpoints: Bps;
|
|
12
|
-
scales: Scales;
|
|
13
|
-
tokens: Tokens;
|
|
14
|
-
variables: Vars;
|
|
15
|
-
constructor(breakpoints: Bps, scales: Scales, tokens: Tokens, vars: Vars);
|
|
16
|
-
addScale(): ThemeWithAll<Bps, Scales, Tokens, Vars>;
|
|
17
|
-
build(): {
|
|
18
|
-
breakpoints: Bps;
|
|
19
|
-
} & Scales & {
|
|
20
|
-
_tokens: Tokens;
|
|
21
|
-
_variables: Vars;
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export declare class ThemeWithRawColors<Bps extends Breakpoints, Scales, Tokens, Vars> extends ThemeWithAll<Bps, Scales, Tokens, Vars> {
|
|
25
|
-
constructor(breakpoints: Bps, scales: Scales, tokens: Tokens, vars: Vars);
|
|
26
|
-
addColorModes(): ThemeWithAll<Bps, Scales, Tokens, Vars>;
|
|
27
|
-
}
|
|
28
|
-
export declare class ThemeWithBreakpoints<Bps extends Breakpoints> extends ThemeWithAll<Bps, {}, {}, {}> {
|
|
29
|
-
constructor(breakpoints: Bps);
|
|
30
|
-
addColors(): ThemeWithRawColors<Bps, {}, {}, {}>;
|
|
31
|
-
}
|
|
32
|
-
export declare class ThemeUnitialized {
|
|
33
|
-
addBreakpoints<Bps extends Breakpoints>(breakpoints: Bps): ThemeWithBreakpoints<Bps>;
|
|
34
|
-
}
|
|
1
|
+
import { Breakpoints } from '@animus-ui/core';
|
|
2
|
+
/**
|
|
3
|
+
* 1. Breakpoints
|
|
4
|
+
* 2. Scales
|
|
5
|
+
* 3. Tokens
|
|
6
|
+
* 4. Variables
|
|
7
|
+
* 5. Colors
|
|
8
|
+
* 6. Color Modes
|
|
9
|
+
*/
|
|
10
|
+
export declare class ThemeWithAll<Bps, Scales, Tokens, Vars> {
|
|
11
|
+
breakpoints: Bps;
|
|
12
|
+
scales: Scales;
|
|
13
|
+
tokens: Tokens;
|
|
14
|
+
variables: Vars;
|
|
15
|
+
constructor(breakpoints: Bps, scales: Scales, tokens: Tokens, vars: Vars);
|
|
16
|
+
addScale(): ThemeWithAll<Bps, Scales, Tokens, Vars>;
|
|
17
|
+
build(): {
|
|
18
|
+
breakpoints: Bps;
|
|
19
|
+
} & Scales & {
|
|
20
|
+
_tokens: Tokens;
|
|
21
|
+
_variables: Vars;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare class ThemeWithRawColors<Bps extends Breakpoints, Scales, Tokens, Vars> extends ThemeWithAll<Bps, Scales, Tokens, Vars> {
|
|
25
|
+
constructor(breakpoints: Bps, scales: Scales, tokens: Tokens, vars: Vars);
|
|
26
|
+
addColorModes(): ThemeWithAll<Bps, Scales, Tokens, Vars>;
|
|
27
|
+
}
|
|
28
|
+
export declare class ThemeWithBreakpoints<Bps extends Breakpoints> extends ThemeWithAll<Bps, {}, {}, {}> {
|
|
29
|
+
constructor(breakpoints: Bps);
|
|
30
|
+
addColors(): ThemeWithRawColors<Bps, {}, {}, {}>;
|
|
31
|
+
}
|
|
32
|
+
export declare class ThemeUnitialized {
|
|
33
|
+
addBreakpoints<Bps extends Breakpoints>(breakpoints: Bps): ThemeWithBreakpoints<Bps>;
|
|
34
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export * from './utils';
|
|
1
|
+
export * from './utils';
|
package/dist/index.js
CHANGED
|
@@ -1,142 +1,111 @@
|
|
|
1
1
|
import { isObject, merge, mapValues } from 'lodash';
|
|
2
2
|
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
7
|
-
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
8
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
9
|
-
})), keys.push.apply(keys, symbols);
|
|
10
|
-
}
|
|
11
|
-
return keys;
|
|
3
|
+
function _assertClassBrand(e, t, n) {
|
|
4
|
+
if ("function" == typeof e ? e === t : e.has(t)) return arguments.length < 3 ? t : n;
|
|
5
|
+
throw new TypeError("Private element is not present on this object");
|
|
12
6
|
}
|
|
13
|
-
function
|
|
14
|
-
|
|
15
|
-
var source = null != arguments[i] ? arguments[i] : {};
|
|
16
|
-
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
17
|
-
_defineProperty(target, key, source[key]);
|
|
18
|
-
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
19
|
-
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
return target;
|
|
7
|
+
function _checkPrivateRedeclaration(e, t) {
|
|
8
|
+
if (t.has(e)) throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
23
9
|
}
|
|
24
|
-
function _classCallCheck(
|
|
25
|
-
if (!(
|
|
26
|
-
throw new TypeError("Cannot call a class as a function");
|
|
27
|
-
}
|
|
10
|
+
function _classCallCheck(a, n) {
|
|
11
|
+
if (!(a instanceof n)) throw new TypeError("Cannot call a class as a function");
|
|
28
12
|
}
|
|
29
|
-
function
|
|
30
|
-
|
|
31
|
-
var descriptor = props[i];
|
|
32
|
-
descriptor.enumerable = descriptor.enumerable || false;
|
|
33
|
-
descriptor.configurable = true;
|
|
34
|
-
if ("value" in descriptor) descriptor.writable = true;
|
|
35
|
-
Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor);
|
|
36
|
-
}
|
|
13
|
+
function _classPrivateFieldGet2(s, a) {
|
|
14
|
+
return s.get(_assertClassBrand(s, a));
|
|
37
15
|
}
|
|
38
|
-
function
|
|
39
|
-
|
|
40
|
-
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
41
|
-
Object.defineProperty(Constructor, "prototype", {
|
|
42
|
-
writable: false
|
|
43
|
-
});
|
|
44
|
-
return Constructor;
|
|
16
|
+
function _classPrivateFieldInitSpec(e, t, a) {
|
|
17
|
+
_checkPrivateRedeclaration(e, t), t.set(e, a);
|
|
45
18
|
}
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
Object.defineProperty(
|
|
50
|
-
value: value,
|
|
51
|
-
enumerable: true,
|
|
52
|
-
configurable: true,
|
|
53
|
-
writable: true
|
|
54
|
-
});
|
|
55
|
-
} else {
|
|
56
|
-
obj[key] = value;
|
|
19
|
+
function _defineProperties(e, r) {
|
|
20
|
+
for (var t = 0; t < r.length; t++) {
|
|
21
|
+
var o = r[t];
|
|
22
|
+
o.enumerable = o.enumerable || !1, o.configurable = !0, "value" in o && (o.writable = !0), Object.defineProperty(e, _toPropertyKey(o.key), o);
|
|
57
23
|
}
|
|
58
|
-
return obj;
|
|
59
24
|
}
|
|
60
|
-
function
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var key, i;
|
|
65
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
66
|
-
key = sourceKeys[i];
|
|
67
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
68
|
-
target[key] = source[key];
|
|
69
|
-
}
|
|
70
|
-
return target;
|
|
25
|
+
function _createClass(e, r, t) {
|
|
26
|
+
return r && _defineProperties(e.prototype, r), t && _defineProperties(e, t), Object.defineProperty(e, "prototype", {
|
|
27
|
+
writable: !1
|
|
28
|
+
}), e;
|
|
71
29
|
}
|
|
72
|
-
function
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
30
|
+
function _defineProperty(e, r, t) {
|
|
31
|
+
return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
|
|
32
|
+
value: t,
|
|
33
|
+
enumerable: !0,
|
|
34
|
+
configurable: !0,
|
|
35
|
+
writable: !0
|
|
36
|
+
}) : e[r] = t, e;
|
|
37
|
+
}
|
|
38
|
+
function ownKeys(e, r) {
|
|
39
|
+
var t = Object.keys(e);
|
|
76
40
|
if (Object.getOwnPropertySymbols) {
|
|
77
|
-
var
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
82
|
-
target[key] = source[key];
|
|
83
|
-
}
|
|
41
|
+
var o = Object.getOwnPropertySymbols(e);
|
|
42
|
+
r && (o = o.filter(function (r) {
|
|
43
|
+
return Object.getOwnPropertyDescriptor(e, r).enumerable;
|
|
44
|
+
})), t.push.apply(t, o);
|
|
84
45
|
}
|
|
85
|
-
return
|
|
46
|
+
return t;
|
|
86
47
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
48
|
+
function _objectSpread2(e) {
|
|
49
|
+
for (var r = 1; r < arguments.length; r++) {
|
|
50
|
+
var t = null != arguments[r] ? arguments[r] : {};
|
|
51
|
+
r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
|
|
52
|
+
_defineProperty(e, r, t[r]);
|
|
53
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
|
|
54
|
+
Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
|
|
55
|
+
});
|
|
94
56
|
}
|
|
95
|
-
return
|
|
96
|
-
}
|
|
97
|
-
function _toPropertyKey(arg) {
|
|
98
|
-
var key = _toPrimitive(arg, "string");
|
|
99
|
-
return typeof key === "symbol" ? key : String(key);
|
|
57
|
+
return e;
|
|
100
58
|
}
|
|
101
|
-
function
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
111
|
-
if (!privateMap.has(receiver)) {
|
|
112
|
-
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
59
|
+
function _objectWithoutProperties(e, t) {
|
|
60
|
+
if (null == e) return {};
|
|
61
|
+
var o,
|
|
62
|
+
r,
|
|
63
|
+
i = _objectWithoutPropertiesLoose(e, t);
|
|
64
|
+
if (Object.getOwnPropertySymbols) {
|
|
65
|
+
var n = Object.getOwnPropertySymbols(e);
|
|
66
|
+
for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
|
|
113
67
|
}
|
|
114
|
-
return
|
|
68
|
+
return i;
|
|
115
69
|
}
|
|
116
|
-
function
|
|
117
|
-
if (
|
|
118
|
-
|
|
70
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
71
|
+
if (null == r) return {};
|
|
72
|
+
var t = {};
|
|
73
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
74
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
75
|
+
t[n] = r[n];
|
|
119
76
|
}
|
|
120
|
-
return
|
|
77
|
+
return t;
|
|
121
78
|
}
|
|
122
|
-
function
|
|
123
|
-
if (
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
descriptor.value = value;
|
|
79
|
+
function _toPrimitive(t, r) {
|
|
80
|
+
if ("object" != typeof t || !t) return t;
|
|
81
|
+
var e = t[Symbol.toPrimitive];
|
|
82
|
+
if (void 0 !== e) {
|
|
83
|
+
var i = e.call(t, r || "default");
|
|
84
|
+
if ("object" != typeof i) return i;
|
|
85
|
+
throw new TypeError("@@toPrimitive must return a primitive value.");
|
|
130
86
|
}
|
|
87
|
+
return ("string" === r ? String : Number)(t);
|
|
88
|
+
}
|
|
89
|
+
function _toPropertyKey(t) {
|
|
90
|
+
var i = _toPrimitive(t, "string");
|
|
91
|
+
return "symbol" == typeof i ? i : i + "";
|
|
131
92
|
}
|
|
132
|
-
function
|
|
133
|
-
|
|
134
|
-
|
|
93
|
+
function _classApplyDescriptorGet(e, t) {
|
|
94
|
+
return t.get ? t.get.call(e) : t.value;
|
|
95
|
+
}
|
|
96
|
+
function _classApplyDescriptorSet(e, t, l) {
|
|
97
|
+
if (t.set) t.set.call(e, l);else {
|
|
98
|
+
if (!t.writable) throw new TypeError("attempted to set read only private field");
|
|
99
|
+
t.value = l;
|
|
135
100
|
}
|
|
136
101
|
}
|
|
137
|
-
function
|
|
138
|
-
|
|
139
|
-
|
|
102
|
+
function _classPrivateFieldGet(e, t) {
|
|
103
|
+
var r = _classPrivateFieldGet2(t, e);
|
|
104
|
+
return _classApplyDescriptorGet(e, r);
|
|
105
|
+
}
|
|
106
|
+
function _classPrivateFieldSet(e, t, r) {
|
|
107
|
+
var s = _classPrivateFieldGet2(t, e);
|
|
108
|
+
return _classApplyDescriptorSet(e, s, r), r;
|
|
140
109
|
}
|
|
141
110
|
|
|
142
111
|
function flattenScale(object, path) {
|
|
@@ -192,10 +161,10 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
192
161
|
});
|
|
193
162
|
_classPrivateFieldSet(this, _theme, baseTheme);
|
|
194
163
|
}
|
|
195
|
-
/**
|
|
196
|
-
*
|
|
197
|
-
* @param key A key of the current theme to transform into CSS Variables and Variable References
|
|
198
|
-
* @example .createScaleVariables('fontSize')
|
|
164
|
+
/**
|
|
165
|
+
*
|
|
166
|
+
* @param key A key of the current theme to transform into CSS Variables and Variable References
|
|
167
|
+
* @example .createScaleVariables('fontSize')
|
|
199
168
|
*/
|
|
200
169
|
_createClass(ThemeBuilder, [{
|
|
201
170
|
key: "createScaleVariables",
|
|
@@ -207,10 +176,10 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
207
176
|
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), (_merge = {}, _defineProperty(_merge, key, tokens), _defineProperty(_merge, "_variables", _defineProperty({}, key, variables)), _defineProperty(_merge, "_tokens", _defineProperty({}, key, _classPrivateFieldGet(this, _theme)[key])), _merge)));
|
|
208
177
|
return this;
|
|
209
178
|
}
|
|
210
|
-
/**
|
|
211
|
-
*
|
|
212
|
-
* @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
|
|
213
|
-
* @example .addColors({ navy: 'navy', hyper: 'purple' })
|
|
179
|
+
/**
|
|
180
|
+
*
|
|
181
|
+
* @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
|
|
182
|
+
* @example .addColors({ navy: 'navy', hyper: 'purple' })
|
|
214
183
|
*/
|
|
215
184
|
}, {
|
|
216
185
|
key: "addColors",
|
|
@@ -230,11 +199,11 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
230
199
|
}));
|
|
231
200
|
return this;
|
|
232
201
|
}
|
|
233
|
-
/**
|
|
234
|
-
*
|
|
235
|
-
* @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
|
|
236
|
-
* @param modes A map of color modes with keys of each possible mode with a value of alias to color keys. This must be called after `addColors`
|
|
237
|
-
* @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
|
|
202
|
+
/**
|
|
203
|
+
*
|
|
204
|
+
* @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
|
|
205
|
+
* @param modes A map of color modes with keys of each possible mode with a value of alias to color keys. This must be called after `addColors`
|
|
206
|
+
* @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
|
|
238
207
|
*/
|
|
239
208
|
}, {
|
|
240
209
|
key: "addColorModes",
|
|
@@ -269,11 +238,11 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
269
238
|
}));
|
|
270
239
|
return this;
|
|
271
240
|
}
|
|
272
|
-
/**
|
|
273
|
-
*
|
|
274
|
-
* @param key A new key of theme
|
|
275
|
-
* @param createScale A function that accepts the current theme and returns a new object of scale values.
|
|
276
|
-
* @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
|
|
241
|
+
/**
|
|
242
|
+
*
|
|
243
|
+
* @param key A new key of theme
|
|
244
|
+
* @param createScale A function that accepts the current theme and returns a new object of scale values.
|
|
245
|
+
* @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
|
|
277
246
|
*/
|
|
278
247
|
}, {
|
|
279
248
|
key: "addScale",
|
|
@@ -281,11 +250,11 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
281
250
|
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, flattenScale(createScale(_classPrivateFieldGet(this, _theme))))));
|
|
282
251
|
return this;
|
|
283
252
|
}
|
|
284
|
-
/**
|
|
285
|
-
*
|
|
286
|
-
* @param key A current key of theme to be updated with new or computed values
|
|
287
|
-
* @param updateFn A function that accepts an argument of the current values at the specified keys an returns a map of new values to merge.
|
|
288
|
-
* @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
|
|
253
|
+
/**
|
|
254
|
+
*
|
|
255
|
+
* @param key A current key of theme to be updated with new or computed values
|
|
256
|
+
* @param updateFn A function that accepts an argument of the current values at the specified keys an returns a map of new values to merge.
|
|
257
|
+
* @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
|
|
289
258
|
*/
|
|
290
259
|
}, {
|
|
291
260
|
key: "updateScale",
|
|
@@ -293,8 +262,8 @@ var ThemeBuilder = /*#__PURE__*/function () {
|
|
|
293
262
|
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, updateFn(_classPrivateFieldGet(this, _theme)[key]))));
|
|
294
263
|
return this;
|
|
295
264
|
}
|
|
296
|
-
/**
|
|
297
|
-
* This finalizes the theme build and returns the final theme and variables to be provided.
|
|
265
|
+
/**
|
|
266
|
+
* This finalizes the theme build and returns the final theme and variables to be provided.
|
|
298
267
|
*/
|
|
299
268
|
}, {
|
|
300
269
|
key: "build",
|
|
@@ -1,53 +1,53 @@
|
|
|
1
|
-
import { AbstractTheme, CSSObject } from '@animus-ui/core';
|
|
2
|
-
import { LiteralPaths } from './flattenScale';
|
|
3
|
-
import { KeyAsVariable } from './serializeTokens';
|
|
4
|
-
import { ColorModeConfig, Merge, MergeTheme, PrivateThemeKeys } from './types';
|
|
5
|
-
export declare class ThemeBuilder<T extends AbstractTheme> {
|
|
6
|
-
#private;
|
|
7
|
-
constructor(baseTheme: T);
|
|
8
|
-
/**
|
|
9
|
-
*
|
|
10
|
-
* @param key A key of the current theme to transform into CSS Variables and Variable References
|
|
11
|
-
* @example .createScaleVariables('fontSize')
|
|
12
|
-
*/
|
|
13
|
-
createScaleVariables<Key extends keyof Omit<T, 'breakpoints'> & string>(key: Key): ThemeBuilder<MergeTheme<T, PrivateThemeKeys, Record<Key, Record<Key, KeyAsVariable<T[Key], Key>>>>>;
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
* @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
|
|
17
|
-
* @example .addColors({ navy: 'navy', hyper: 'purple' })
|
|
18
|
-
*/
|
|
19
|
-
addColors<Colors extends Record<string, string | number | CSSObject>, NextColors extends LiteralPaths<Colors, '-'>>(colors: Colors): ThemeBuilder<MergeTheme<T & PrivateThemeKeys, Record<'colors', KeyAsVariable<NextColors, 'color'>>>>;
|
|
20
|
-
/**
|
|
21
|
-
*
|
|
22
|
-
* @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
|
|
23
|
-
* @param modes A map of color modes with keys of each possible mode with a value of alias to color keys. This must be called after `addColors`
|
|
24
|
-
* @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
|
|
25
|
-
*/
|
|
26
|
-
addColorModes<Modes extends string, InitialMode extends keyof Config, Colors extends keyof T['colors'], ModeColors extends ColorModeConfig<Colors>, Config extends Record<Modes, ModeColors>, ColorAliases extends {
|
|
27
|
-
[K in keyof Config]: LiteralPaths<Config[K], '-', '_'>;
|
|
28
|
-
}>(initialMode: InitialMode, modeConfig: Config): ThemeBuilder<MergeTheme<T & PrivateThemeKeys, {
|
|
29
|
-
colors: KeyAsVariable<LiteralPaths<Config[keyof Config], '-', '_'>, 'colors'> & T['colors'];
|
|
30
|
-
modes: Merge<T['modes'], ColorAliases>;
|
|
31
|
-
mode: keyof Config;
|
|
32
|
-
_getColorValue: (color: keyof T['colors']) => string;
|
|
33
|
-
}>>;
|
|
34
|
-
/**
|
|
35
|
-
*
|
|
36
|
-
* @param key A new key of theme
|
|
37
|
-
* @param createScale A function that accepts the current theme and returns a new object of scale values.
|
|
38
|
-
* @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
|
|
39
|
-
*/
|
|
40
|
-
addScale<Key extends string, Fn extends (theme: T) => Record<string | number, string | number | Record<string, string | number>>, NewScale extends LiteralPaths<ReturnType<Fn>, '-'>>(key: Key, createScale: Fn): ThemeBuilder<MergeTheme<T, Record<Key, NewScale>>>;
|
|
41
|
-
/**
|
|
42
|
-
*
|
|
43
|
-
* @param key A current key of theme to be updated with new or computed values
|
|
44
|
-
* @param updateFn A function that accepts an argument of the current values at the specified keys an returns a map of new values to merge.
|
|
45
|
-
* @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
|
|
46
|
-
*/
|
|
47
|
-
updateScale<Key extends keyof T, Fn extends (tokens: T[Key]) => Record<string | number, unknown>>(key: Key, updateFn: Fn): ThemeBuilder<T & Record<Key, T[Key] & ReturnType<Fn>>>;
|
|
48
|
-
/**
|
|
49
|
-
* This finalizes the theme build and returns the final theme and variables to be provided.
|
|
50
|
-
*/
|
|
51
|
-
build(): T & PrivateThemeKeys;
|
|
52
|
-
}
|
|
53
|
-
export declare function createTheme<T extends AbstractTheme>(base: T): ThemeBuilder<T>;
|
|
1
|
+
import { AbstractTheme, CSSObject } from '@animus-ui/core';
|
|
2
|
+
import { LiteralPaths } from './flattenScale';
|
|
3
|
+
import { KeyAsVariable } from './serializeTokens';
|
|
4
|
+
import { ColorModeConfig, Merge, MergeTheme, PrivateThemeKeys } from './types';
|
|
5
|
+
export declare class ThemeBuilder<T extends AbstractTheme> {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(baseTheme: T);
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @param key A key of the current theme to transform into CSS Variables and Variable References
|
|
11
|
+
* @example .createScaleVariables('fontSize')
|
|
12
|
+
*/
|
|
13
|
+
createScaleVariables<Key extends keyof Omit<T, 'breakpoints'> & string>(key: Key): ThemeBuilder<MergeTheme<T, PrivateThemeKeys, Record<Key, Record<Key, KeyAsVariable<T[Key], Key>>>>>;
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
|
|
17
|
+
* @example .addColors({ navy: 'navy', hyper: 'purple' })
|
|
18
|
+
*/
|
|
19
|
+
addColors<Colors extends Record<string, string | number | CSSObject>, NextColors extends LiteralPaths<Colors, '-'>>(colors: Colors): ThemeBuilder<MergeTheme<T & PrivateThemeKeys, Record<'colors', KeyAsVariable<NextColors, 'color'>>>>;
|
|
20
|
+
/**
|
|
21
|
+
*
|
|
22
|
+
* @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
|
|
23
|
+
* @param modes A map of color modes with keys of each possible mode with a value of alias to color keys. This must be called after `addColors`
|
|
24
|
+
* @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
|
|
25
|
+
*/
|
|
26
|
+
addColorModes<Modes extends string, InitialMode extends keyof Config, Colors extends keyof T['colors'], ModeColors extends ColorModeConfig<Colors>, Config extends Record<Modes, ModeColors>, ColorAliases extends {
|
|
27
|
+
[K in keyof Config]: LiteralPaths<Config[K], '-', '_'>;
|
|
28
|
+
}>(initialMode: InitialMode, modeConfig: Config): ThemeBuilder<MergeTheme<T & PrivateThemeKeys, {
|
|
29
|
+
colors: KeyAsVariable<LiteralPaths<Config[keyof Config], '-', '_'>, 'colors'> & T['colors'];
|
|
30
|
+
modes: Merge<T['modes'], ColorAliases>;
|
|
31
|
+
mode: keyof Config;
|
|
32
|
+
_getColorValue: (color: keyof T['colors']) => string;
|
|
33
|
+
}>>;
|
|
34
|
+
/**
|
|
35
|
+
*
|
|
36
|
+
* @param key A new key of theme
|
|
37
|
+
* @param createScale A function that accepts the current theme and returns a new object of scale values.
|
|
38
|
+
* @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
|
|
39
|
+
*/
|
|
40
|
+
addScale<Key extends string, Fn extends (theme: T) => Record<string | number, string | number | Record<string, string | number>>, NewScale extends LiteralPaths<ReturnType<Fn>, '-'>>(key: Key, createScale: Fn): ThemeBuilder<MergeTheme<T, Record<Key, NewScale>>>;
|
|
41
|
+
/**
|
|
42
|
+
*
|
|
43
|
+
* @param key A current key of theme to be updated with new or computed values
|
|
44
|
+
* @param updateFn A function that accepts an argument of the current values at the specified keys an returns a map of new values to merge.
|
|
45
|
+
* @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
|
|
46
|
+
*/
|
|
47
|
+
updateScale<Key extends keyof T, Fn extends (tokens: T[Key]) => Record<string | number, unknown>>(key: Key, updateFn: Fn): ThemeBuilder<T & Record<Key, T[Key] & ReturnType<Fn>>>;
|
|
48
|
+
/**
|
|
49
|
+
* This finalizes the theme build and returns the final theme and variables to be provided.
|
|
50
|
+
*/
|
|
51
|
+
build(): T & PrivateThemeKeys;
|
|
52
|
+
}
|
|
53
|
+
export declare function createTheme<T extends AbstractTheme>(base: T): ThemeBuilder<T>;
|
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns an exhaustive list of all possible paths of an object T for keys K.
|
|
3
|
-
* Possibilities are returned as `k1.k2.k3`.
|
|
4
|
-
*/
|
|
5
|
-
export type FindPath<T, K extends keyof T, D extends string = '.'> = K extends string | number ? T[K] extends Record<string | number, any> ? T[K] extends ArrayLike<any> ? K | `${K}${D}${FindPath<T[K], Exclude<keyof T[K], keyof any[]>, D>}` : K | `${K}${D}${FindPath<T[K], keyof T[K], D>}` : K : never;
|
|
6
|
-
/** Returns valid paths of object T */
|
|
7
|
-
export type Path<T, D extends string = '.'> = FindPath<T, keyof T, D> | keyof T;
|
|
8
|
-
/** Returns the value of a valid path P `k1.k2.k3` in object T */
|
|
9
|
-
export type PathValue<T, P extends Path<T, D>, D extends string = '.'> = P extends `${infer K}${D}${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K], D> ? PathValue<T[K], Rest, D> : never : never : P extends keyof T ? T[P] : never;
|
|
10
|
-
/** Check if path has a primitive end value and return only the union of end paths */
|
|
11
|
-
export type PathToLiteral<T, K extends Path<T, D>, D extends string = '.', Base extends string = ''> = PathValue<T, K, D> extends string | number ? K extends string | number ? K extends `${infer BasePath}${D}${Base}` ? BasePath : K : never : never;
|
|
12
|
-
/**
|
|
13
|
-
* Reduce all paths to a single map of paths with primitive values removing all extra non stateful paths
|
|
14
|
-
* { path: { sub: 1 } } => { 'path-sub': 1 }
|
|
15
|
-
*
|
|
16
|
-
*/
|
|
17
|
-
export type LiteralPaths<T extends Record<string | number, any>, D extends string = '.', Base extends string = ''> = {
|
|
18
|
-
[K in Path<T, D> as PathToLiteral<T, K, D, Base>]: PathValue<T, PathToLiteral<T, K, D>, D>;
|
|
19
|
-
};
|
|
20
|
-
export declare function flattenScale<T extends Record<string | number, unknown>, P extends string>(object: T, path?: P): LiteralPaths<T, '-', '_'>;
|
|
1
|
+
/**
|
|
2
|
+
* Returns an exhaustive list of all possible paths of an object T for keys K.
|
|
3
|
+
* Possibilities are returned as `k1.k2.k3`.
|
|
4
|
+
*/
|
|
5
|
+
export type FindPath<T, K extends keyof T, D extends string = '.'> = K extends string | number ? T[K] extends Record<string | number, any> ? T[K] extends ArrayLike<any> ? K | `${K}${D}${FindPath<T[K], Exclude<keyof T[K], keyof any[]>, D>}` : K | `${K}${D}${FindPath<T[K], keyof T[K], D>}` : K : never;
|
|
6
|
+
/** Returns valid paths of object T */
|
|
7
|
+
export type Path<T, D extends string = '.'> = FindPath<T, keyof T, D> | keyof T;
|
|
8
|
+
/** Returns the value of a valid path P `k1.k2.k3` in object T */
|
|
9
|
+
export type PathValue<T, P extends Path<T, D>, D extends string = '.'> = P extends `${infer K}${D}${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K], D> ? PathValue<T[K], Rest, D> : never : never : P extends keyof T ? T[P] : never;
|
|
10
|
+
/** Check if path has a primitive end value and return only the union of end paths */
|
|
11
|
+
export type PathToLiteral<T, K extends Path<T, D>, D extends string = '.', Base extends string = ''> = PathValue<T, K, D> extends string | number ? K extends string | number ? K extends `${infer BasePath}${D}${Base}` ? BasePath : K : never : never;
|
|
12
|
+
/**
|
|
13
|
+
* Reduce all paths to a single map of paths with primitive values removing all extra non stateful paths
|
|
14
|
+
* { path: { sub: 1 } } => { 'path-sub': 1 }
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export type LiteralPaths<T extends Record<string | number, any>, D extends string = '.', Base extends string = ''> = {
|
|
18
|
+
[K in Path<T, D> as PathToLiteral<T, K, D, Base>]: PathValue<T, PathToLiteral<T, K, D>, D>;
|
|
19
|
+
};
|
|
20
|
+
export declare function flattenScale<T extends Record<string | number, unknown>, P extends string>(object: T, path?: P): LiteralPaths<T, '-', '_'>;
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export * from './createTheme';
|
|
2
|
-
export * from './serializeTokens';
|
|
3
|
-
export * from './flattenScale';
|
|
1
|
+
export * from './createTheme';
|
|
2
|
+
export * from './serializeTokens';
|
|
3
|
+
export * from './flattenScale';
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import { CSSObject } from '@animus-ui/core';
|
|
2
|
-
import { Theme } from '@emotion/react';
|
|
3
|
-
/**
|
|
4
|
-
* Returns an type of any object with { key: 'var(--key) }
|
|
5
|
-
*/
|
|
6
|
-
export type KeyAsVariable<T extends Record<string, any>, Prefix extends string> = {
|
|
7
|
-
[V in keyof T]: `var(--${Prefix}-${SanitizeKey<Extract<V, string>>})`;
|
|
8
|
-
};
|
|
9
|
-
export type SanitizeKey<T extends string> = T extends `${'$'}${infer Y}` ? Y : T;
|
|
10
|
-
type SerializedTokensInput = Record<string, string | number | CSSObject | SerializedTokensInputRecursive>;
|
|
11
|
-
interface SerializedTokensInputRecursive {
|
|
12
|
-
[i: number]: SerializedTokensInput;
|
|
13
|
-
[i: string]: SerializedTokensInput;
|
|
14
|
-
}
|
|
15
|
-
export declare const serializeTokens: <T extends SerializedTokensInput, Prefix extends string>(tokens: T, prefix: Prefix, theme: Theme | undefined) => {
|
|
16
|
-
tokens: KeyAsVariable<T, Prefix>;
|
|
17
|
-
variables: CSSObject;
|
|
18
|
-
};
|
|
19
|
-
export {};
|
|
1
|
+
import { CSSObject } from '@animus-ui/core';
|
|
2
|
+
import { Theme } from '@emotion/react';
|
|
3
|
+
/**
|
|
4
|
+
* Returns an type of any object with { key: 'var(--key) }
|
|
5
|
+
*/
|
|
6
|
+
export type KeyAsVariable<T extends Record<string, any>, Prefix extends string> = {
|
|
7
|
+
[V in keyof T]: `var(--${Prefix}-${SanitizeKey<Extract<V, string>>})`;
|
|
8
|
+
};
|
|
9
|
+
export type SanitizeKey<T extends string> = T extends `${'$'}${infer Y}` ? Y : T;
|
|
10
|
+
type SerializedTokensInput = Record<string, string | number | CSSObject | SerializedTokensInputRecursive>;
|
|
11
|
+
interface SerializedTokensInputRecursive {
|
|
12
|
+
[i: number]: SerializedTokensInput;
|
|
13
|
+
[i: string]: SerializedTokensInput;
|
|
14
|
+
}
|
|
15
|
+
export declare const serializeTokens: <T extends SerializedTokensInput, Prefix extends string>(tokens: T, prefix: Prefix, theme: Theme | undefined) => {
|
|
16
|
+
tokens: KeyAsVariable<T, Prefix>;
|
|
17
|
+
variables: CSSObject;
|
|
18
|
+
};
|
|
19
|
+
export {};
|
package/dist/utils/types.d.ts
CHANGED
|
@@ -1,41 +1,41 @@
|
|
|
1
|
-
import { AbstractTheme, CSSObject } from '@animus-ui/core';
|
|
2
|
-
/**
|
|
3
|
-
* This is a custom generic that ensures the safety of adding additional values to a theme object without accidentally wiping out
|
|
4
|
-
* required keys like `breakpoints`. It works by creating a new mapped type and merging the values of the union of Base & Next:
|
|
5
|
-
* 1. If the key exists on both Base and Next return the intersection of both values
|
|
6
|
-
* 2. If the key exists on next use the value on next.
|
|
7
|
-
* 3. If the key exists on base but nothing else use the value on base.
|
|
8
|
-
*
|
|
9
|
-
* The resulting type is then rejoined with keys that cannot be mutated (breakpoints) as the next version of Theme
|
|
10
|
-
*/
|
|
11
|
-
export type MergeTheme<Base extends AbstractTheme, Next, Unmergable = Record<'breakpoints', Base['breakpoints']>> = Unmergable & Merge<Base, Next>;
|
|
12
|
-
/** This merges at 2 levels of depth */
|
|
13
|
-
export type Merge<A, B> = {
|
|
14
|
-
[K in keyof (A & B)]: K extends keyof B ? K extends keyof A ? AssignValueIfUnmergable<A[K], B[K]> : B[K] : K extends keyof A ? A[K] : never;
|
|
15
|
-
};
|
|
16
|
-
/** Extract mergable objects */
|
|
17
|
-
export type Mergable<T> = Exclude<T, ((...args: any) => any) | string | boolean | symbol | number | any[]>;
|
|
18
|
-
/** Return B if either A or B is unmergable */
|
|
19
|
-
export type AssignValueIfUnmergable<A, B> = Mergable<A> extends never ? B : Mergable<B> extends never ? B : Assign<A, B>;
|
|
20
|
-
/** Prefer all values from B */
|
|
21
|
-
export type Assign<A, B> = {
|
|
22
|
-
[K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
|
|
23
|
-
};
|
|
24
|
-
/** These are keys that are consistent for all theme builds - they are loosely typed as they are not meant to be accessed directly */
|
|
25
|
-
export type PrivateThemeKeys = {
|
|
26
|
-
_variables: Record<string, CSSObject>;
|
|
27
|
-
_tokens: Record<string | number, any>;
|
|
28
|
-
};
|
|
29
|
-
/** This allows 3 layers of color aliases to be constructed when adding colorModes
|
|
30
|
-
* @example
|
|
31
|
-
* {
|
|
32
|
-
* button: {
|
|
33
|
-
* bg: {
|
|
34
|
-
* hover: 'someAlias'
|
|
35
|
-
* }
|
|
36
|
-
* }
|
|
37
|
-
* }
|
|
38
|
-
*
|
|
39
|
-
* `button-bg-hover`
|
|
40
|
-
* */
|
|
41
|
-
export type ColorModeConfig<Colors> = Record<string, Colors | Record<string, Colors> | Record<string, Colors | Record<string, Colors>>>;
|
|
1
|
+
import { AbstractTheme, CSSObject } from '@animus-ui/core';
|
|
2
|
+
/**
|
|
3
|
+
* This is a custom generic that ensures the safety of adding additional values to a theme object without accidentally wiping out
|
|
4
|
+
* required keys like `breakpoints`. It works by creating a new mapped type and merging the values of the union of Base & Next:
|
|
5
|
+
* 1. If the key exists on both Base and Next return the intersection of both values
|
|
6
|
+
* 2. If the key exists on next use the value on next.
|
|
7
|
+
* 3. If the key exists on base but nothing else use the value on base.
|
|
8
|
+
*
|
|
9
|
+
* The resulting type is then rejoined with keys that cannot be mutated (breakpoints) as the next version of Theme
|
|
10
|
+
*/
|
|
11
|
+
export type MergeTheme<Base extends AbstractTheme, Next, Unmergable = Record<'breakpoints', Base['breakpoints']>> = Unmergable & Merge<Base, Next>;
|
|
12
|
+
/** This merges at 2 levels of depth */
|
|
13
|
+
export type Merge<A, B> = {
|
|
14
|
+
[K in keyof (A & B)]: K extends keyof B ? K extends keyof A ? AssignValueIfUnmergable<A[K], B[K]> : B[K] : K extends keyof A ? A[K] : never;
|
|
15
|
+
};
|
|
16
|
+
/** Extract mergable objects */
|
|
17
|
+
export type Mergable<T> = Exclude<T, ((...args: any) => any) | string | boolean | symbol | number | any[]>;
|
|
18
|
+
/** Return B if either A or B is unmergable */
|
|
19
|
+
export type AssignValueIfUnmergable<A, B> = Mergable<A> extends never ? B : Mergable<B> extends never ? B : Assign<A, B>;
|
|
20
|
+
/** Prefer all values from B */
|
|
21
|
+
export type Assign<A, B> = {
|
|
22
|
+
[K in keyof A | keyof B]: K extends keyof B ? B[K] : K extends keyof A ? A[K] : never;
|
|
23
|
+
};
|
|
24
|
+
/** These are keys that are consistent for all theme builds - they are loosely typed as they are not meant to be accessed directly */
|
|
25
|
+
export type PrivateThemeKeys = {
|
|
26
|
+
_variables: Record<string, CSSObject>;
|
|
27
|
+
_tokens: Record<string | number, any>;
|
|
28
|
+
};
|
|
29
|
+
/** This allows 3 layers of color aliases to be constructed when adding colorModes
|
|
30
|
+
* @example
|
|
31
|
+
* {
|
|
32
|
+
* button: {
|
|
33
|
+
* bg: {
|
|
34
|
+
* hover: 'someAlias'
|
|
35
|
+
* }
|
|
36
|
+
* }
|
|
37
|
+
* }
|
|
38
|
+
*
|
|
39
|
+
* `button-bg-hover`
|
|
40
|
+
* */
|
|
41
|
+
export type ColorModeConfig<Colors> = Record<string, Colors | Record<string, Colors> | Record<string, Colors | Record<string, Colors>>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animus-ui/theming",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.26",
|
|
4
4
|
"description": "Theming Utilities",
|
|
5
5
|
"author": "Aaron Robb <airrobb@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/codecaaron/animus#readme",
|
|
@@ -25,13 +25,13 @@
|
|
|
25
25
|
"url": "https://github.com/codecaaron/animus/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@animus-ui/core": "^0.1.1-beta.
|
|
29
|
-
"@emotion/react": "^11.
|
|
30
|
-
"@emotion/styled": "^11.
|
|
28
|
+
"@animus-ui/core": "^0.1.1-beta.25",
|
|
29
|
+
"@emotion/react": "^11.14.0",
|
|
30
|
+
"@emotion/styled": "^11.14.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"lodash": "*",
|
|
34
34
|
"typescript": ">=4.3.5"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "60452a65a6679aaadb95075b8d7f12771164d8fb"
|
|
37
37
|
}
|