@animus-ui/theming 0.1.1-beta.11 → 0.1.1-beta.15
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +32 -0
- package/dist/index.js +372 -0
- package/package.json +5 -5
- package/dist/index.cjs.js +0 -1
- package/dist/index.esm.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
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.15](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.14...@animus-ui/theming@0.1.1-beta.15) (2022-01-26)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @animus-ui/theming
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [0.1.1-beta.14](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.13...@animus-ui/theming@0.1.1-beta.14) (2022-01-24)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @animus-ui/theming
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
## [0.1.1-beta.13](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.12...@animus-ui/theming@0.1.1-beta.13) (2022-01-24)
|
|
23
|
+
|
|
24
|
+
**Note:** Version bump only for package @animus-ui/theming
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## [0.1.1-beta.12](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.11...@animus-ui/theming@0.1.1-beta.12) (2022-01-24)
|
|
31
|
+
|
|
32
|
+
**Note:** Version bump only for package @animus-ui/theming
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
## [0.1.1-beta.11](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.10...@animus-ui/theming@0.1.1-beta.11) (2022-01-24)
|
|
7
39
|
|
|
8
40
|
**Note:** Version bump only for package @animus-ui/theming
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,372 @@
|
|
|
1
|
+
import { isObject, merge, mapValues } from 'lodash';
|
|
2
|
+
|
|
3
|
+
function ownKeys(object, enumerableOnly) {
|
|
4
|
+
var keys = Object.keys(object);
|
|
5
|
+
|
|
6
|
+
if (Object.getOwnPropertySymbols) {
|
|
7
|
+
var symbols = Object.getOwnPropertySymbols(object);
|
|
8
|
+
enumerableOnly && (symbols = symbols.filter(function (sym) {
|
|
9
|
+
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
10
|
+
})), keys.push.apply(keys, symbols);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
return keys;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function _objectSpread2(target) {
|
|
17
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
18
|
+
var source = null != arguments[i] ? arguments[i] : {};
|
|
19
|
+
i % 2 ? ownKeys(Object(source), !0).forEach(function (key) {
|
|
20
|
+
_defineProperty(target, key, source[key]);
|
|
21
|
+
}) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) {
|
|
22
|
+
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return target;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function _classCallCheck(instance, Constructor) {
|
|
30
|
+
if (!(instance instanceof Constructor)) {
|
|
31
|
+
throw new TypeError("Cannot call a class as a function");
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function _defineProperties(target, props) {
|
|
36
|
+
for (var i = 0; i < props.length; i++) {
|
|
37
|
+
var descriptor = props[i];
|
|
38
|
+
descriptor.enumerable = descriptor.enumerable || false;
|
|
39
|
+
descriptor.configurable = true;
|
|
40
|
+
if ("value" in descriptor) descriptor.writable = true;
|
|
41
|
+
Object.defineProperty(target, descriptor.key, descriptor);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function _createClass(Constructor, protoProps, staticProps) {
|
|
46
|
+
if (protoProps) _defineProperties(Constructor.prototype, protoProps);
|
|
47
|
+
if (staticProps) _defineProperties(Constructor, staticProps);
|
|
48
|
+
Object.defineProperty(Constructor, "prototype", {
|
|
49
|
+
writable: false
|
|
50
|
+
});
|
|
51
|
+
return Constructor;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _defineProperty(obj, key, value) {
|
|
55
|
+
if (key in obj) {
|
|
56
|
+
Object.defineProperty(obj, key, {
|
|
57
|
+
value: value,
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true,
|
|
60
|
+
writable: true
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
obj[key] = value;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return obj;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
70
|
+
if (source == null) return {};
|
|
71
|
+
var target = {};
|
|
72
|
+
var sourceKeys = Object.keys(source);
|
|
73
|
+
var key, i;
|
|
74
|
+
|
|
75
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
76
|
+
key = sourceKeys[i];
|
|
77
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
78
|
+
target[key] = source[key];
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return target;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
function _objectWithoutProperties(source, excluded) {
|
|
85
|
+
if (source == null) return {};
|
|
86
|
+
|
|
87
|
+
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
88
|
+
|
|
89
|
+
var key, i;
|
|
90
|
+
|
|
91
|
+
if (Object.getOwnPropertySymbols) {
|
|
92
|
+
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
93
|
+
|
|
94
|
+
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
95
|
+
key = sourceSymbolKeys[i];
|
|
96
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
97
|
+
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
98
|
+
target[key] = source[key];
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return target;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
function _classPrivateFieldGet(receiver, privateMap) {
|
|
106
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get");
|
|
107
|
+
|
|
108
|
+
return _classApplyDescriptorGet(receiver, descriptor);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
function _classPrivateFieldSet(receiver, privateMap, value) {
|
|
112
|
+
var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set");
|
|
113
|
+
|
|
114
|
+
_classApplyDescriptorSet(receiver, descriptor, value);
|
|
115
|
+
|
|
116
|
+
return value;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function _classExtractFieldDescriptor(receiver, privateMap, action) {
|
|
120
|
+
if (!privateMap.has(receiver)) {
|
|
121
|
+
throw new TypeError("attempted to " + action + " private field on non-instance");
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
return privateMap.get(receiver);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
function _classApplyDescriptorGet(receiver, descriptor) {
|
|
128
|
+
if (descriptor.get) {
|
|
129
|
+
return descriptor.get.call(receiver);
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return descriptor.value;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function _classApplyDescriptorSet(receiver, descriptor, value) {
|
|
136
|
+
if (descriptor.set) {
|
|
137
|
+
descriptor.set.call(receiver, value);
|
|
138
|
+
} else {
|
|
139
|
+
if (!descriptor.writable) {
|
|
140
|
+
throw new TypeError("attempted to set read only private field");
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
descriptor.value = value;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
function _checkPrivateRedeclaration(obj, privateCollection) {
|
|
148
|
+
if (privateCollection.has(obj)) {
|
|
149
|
+
throw new TypeError("Cannot initialize the same private elements twice on an object");
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
function _classPrivateFieldInitSpec(obj, privateMap, value) {
|
|
154
|
+
_checkPrivateRedeclaration(obj, privateMap);
|
|
155
|
+
|
|
156
|
+
privateMap.set(obj, value);
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
function flattenScale(object, path) {
|
|
160
|
+
return Object.keys(object).reduce(function (carry, key) {
|
|
161
|
+
var nextKey = path ? "".concat(path).concat(key === '_' ? '' : "-".concat(key)) : key;
|
|
162
|
+
var current = object[key];
|
|
163
|
+
|
|
164
|
+
if (isObject(current)) {
|
|
165
|
+
return _objectSpread2(_objectSpread2({}, carry), flattenScale(current, nextKey));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return _objectSpread2(_objectSpread2({}, carry), {}, _defineProperty({}, nextKey, object[key]));
|
|
169
|
+
}, {});
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
var _excluded = ["_", "base"];
|
|
173
|
+
|
|
174
|
+
var templateBreakpoints = function templateBreakpoints(value, alias, theme) {
|
|
175
|
+
if (isObject(value)) {
|
|
176
|
+
var _ = value._,
|
|
177
|
+
base = value.base,
|
|
178
|
+
rest = _objectWithoutProperties(value, _excluded);
|
|
179
|
+
|
|
180
|
+
var css = _defineProperty({}, alias, _ !== null && _ !== void 0 ? _ : base);
|
|
181
|
+
|
|
182
|
+
if (theme) {
|
|
183
|
+
var breakpoints = theme.breakpoints;
|
|
184
|
+
Object.keys(breakpoints).forEach(function (key) {
|
|
185
|
+
css[breakpoints[key]] = _defineProperty({}, alias, rest[key]);
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
return css;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
return _defineProperty({}, alias, value);
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
var serializeTokens = function serializeTokens(tokens, prefix, theme) {
|
|
196
|
+
var tokenReferences = {};
|
|
197
|
+
var tokenVariables = {};
|
|
198
|
+
Object.keys(tokens).forEach(function (key) {
|
|
199
|
+
var varName = "--".concat(prefix, "-").concat(key);
|
|
200
|
+
tokenReferences[key] = "var(".concat(varName, ")");
|
|
201
|
+
merge(tokenVariables, templateBreakpoints(tokens[key], varName, theme));
|
|
202
|
+
});
|
|
203
|
+
return {
|
|
204
|
+
tokens: tokenReferences,
|
|
205
|
+
variables: tokenVariables
|
|
206
|
+
};
|
|
207
|
+
};
|
|
208
|
+
|
|
209
|
+
var _theme = /*#__PURE__*/new WeakMap();
|
|
210
|
+
|
|
211
|
+
var ThemeBuilder = /*#__PURE__*/function () {
|
|
212
|
+
function ThemeBuilder(baseTheme) {
|
|
213
|
+
_classCallCheck(this, ThemeBuilder);
|
|
214
|
+
|
|
215
|
+
_classPrivateFieldInitSpec(this, _theme, {
|
|
216
|
+
writable: true,
|
|
217
|
+
value: {}
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
_classPrivateFieldSet(this, _theme, baseTheme);
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
*
|
|
224
|
+
* @param key A key of the current theme to transform into CSS Variables and Variable References
|
|
225
|
+
* @example .createScaleVariables('fontSize')
|
|
226
|
+
*/
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
_createClass(ThemeBuilder, [{
|
|
230
|
+
key: "createScaleVariables",
|
|
231
|
+
value: function createScaleVariables(key) {
|
|
232
|
+
var _merge;
|
|
233
|
+
|
|
234
|
+
var _serializeTokens = serializeTokens(_classPrivateFieldGet(this, _theme)[key], key, _classPrivateFieldGet(this, _theme)),
|
|
235
|
+
variables = _serializeTokens.variables,
|
|
236
|
+
tokens = _serializeTokens.tokens;
|
|
237
|
+
|
|
238
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), (_merge = {}, _defineProperty(_merge, key, tokens), _defineProperty(_merge, "_variables", {
|
|
239
|
+
root: variables
|
|
240
|
+
}), _defineProperty(_merge, "_tokens", _defineProperty({}, key, _classPrivateFieldGet(this, _theme)[key])), _merge)));
|
|
241
|
+
|
|
242
|
+
return this;
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
*
|
|
246
|
+
* @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
|
|
247
|
+
* @example .addColors({ navy: 'navy', hyper: 'purple' })
|
|
248
|
+
*/
|
|
249
|
+
|
|
250
|
+
}, {
|
|
251
|
+
key: "addColors",
|
|
252
|
+
value: function addColors(colors) {
|
|
253
|
+
var flatColors = flattenScale(colors);
|
|
254
|
+
|
|
255
|
+
var _serializeTokens2 = serializeTokens(flatColors, 'color', _classPrivateFieldGet(this, _theme)),
|
|
256
|
+
variables = _serializeTokens2.variables,
|
|
257
|
+
tokens = _serializeTokens2.tokens;
|
|
258
|
+
|
|
259
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
|
|
260
|
+
colors: tokens,
|
|
261
|
+
_variables: {
|
|
262
|
+
root: variables
|
|
263
|
+
},
|
|
264
|
+
_tokens: {
|
|
265
|
+
colors: flatColors
|
|
266
|
+
}
|
|
267
|
+
}));
|
|
268
|
+
|
|
269
|
+
return this;
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
*
|
|
273
|
+
* @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
|
|
274
|
+
* @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`
|
|
275
|
+
* @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
|
|
276
|
+
*/
|
|
277
|
+
|
|
278
|
+
}, {
|
|
279
|
+
key: "addColorModes",
|
|
280
|
+
value: function addColorModes(initialMode, modeConfig) {
|
|
281
|
+
var _classPrivateFieldGet2,
|
|
282
|
+
_this = this;
|
|
283
|
+
|
|
284
|
+
var modes = mapValues(modeConfig, function (mode) {
|
|
285
|
+
return flattenScale(mode);
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
var _serializeTokens3 = serializeTokens(mapValues(merge({}, (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _theme).modes) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2[initialMode], modes[initialMode]), function (color) {
|
|
289
|
+
return _classPrivateFieldGet(_this, _theme).colors[color];
|
|
290
|
+
}), 'color', _classPrivateFieldGet(this, _theme)),
|
|
291
|
+
colors = _serializeTokens3.tokens,
|
|
292
|
+
variables = _serializeTokens3.variables;
|
|
293
|
+
|
|
294
|
+
var getColorValue = function getColorValue(color) {
|
|
295
|
+
var _classPrivateFieldGet3, _classPrivateFieldGet4;
|
|
296
|
+
|
|
297
|
+
return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _theme)._tokens) === null || _classPrivateFieldGet3 === void 0 ? void 0 : (_classPrivateFieldGet4 = _classPrivateFieldGet3.colors) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4[color];
|
|
298
|
+
};
|
|
299
|
+
|
|
300
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
|
|
301
|
+
colors: colors,
|
|
302
|
+
modes: modes,
|
|
303
|
+
mode: initialMode,
|
|
304
|
+
_getColorValue: getColorValue,
|
|
305
|
+
_variables: {
|
|
306
|
+
mode: variables
|
|
307
|
+
},
|
|
308
|
+
_tokens: {
|
|
309
|
+
modes: mapValues(modes, function (mode) {
|
|
310
|
+
return mapValues(mode, getColorValue);
|
|
311
|
+
})
|
|
312
|
+
}
|
|
313
|
+
}));
|
|
314
|
+
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
/**
|
|
318
|
+
*
|
|
319
|
+
* @param key A new key of theme
|
|
320
|
+
* @param createScale A function that accepts the current theme and returns a new object of scale values.
|
|
321
|
+
* @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
|
|
322
|
+
*/
|
|
323
|
+
|
|
324
|
+
}, {
|
|
325
|
+
key: "addScale",
|
|
326
|
+
value: function addScale(key, createScale) {
|
|
327
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, flattenScale(createScale(_classPrivateFieldGet(this, _theme))))));
|
|
328
|
+
|
|
329
|
+
return this;
|
|
330
|
+
}
|
|
331
|
+
/**
|
|
332
|
+
*
|
|
333
|
+
* @param key A current key of theme to be updated with new or computed values
|
|
334
|
+
* @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.
|
|
335
|
+
* @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
|
|
336
|
+
*/
|
|
337
|
+
|
|
338
|
+
}, {
|
|
339
|
+
key: "updateScale",
|
|
340
|
+
value: function updateScale(key, updateFn) {
|
|
341
|
+
_classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, updateFn(_classPrivateFieldGet(this, _theme)[key]))));
|
|
342
|
+
|
|
343
|
+
return this;
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* This finalizes the theme build and returns the final theme and variables to be provided.
|
|
347
|
+
*/
|
|
348
|
+
|
|
349
|
+
}, {
|
|
350
|
+
key: "build",
|
|
351
|
+
value: function build() {
|
|
352
|
+
var _serializeTokens4 = serializeTokens(mapValues(_classPrivateFieldGet(this, _theme).breakpoints, function (val) {
|
|
353
|
+
return "".concat(val, "px");
|
|
354
|
+
}), 'breakpoint', _classPrivateFieldGet(this, _theme)),
|
|
355
|
+
variables = _serializeTokens4.variables;
|
|
356
|
+
|
|
357
|
+
return merge({}, _classPrivateFieldGet(this, _theme), {
|
|
358
|
+
_variables: {
|
|
359
|
+
breakpoints: variables
|
|
360
|
+
},
|
|
361
|
+
_tokens: {}
|
|
362
|
+
});
|
|
363
|
+
}
|
|
364
|
+
}]);
|
|
365
|
+
|
|
366
|
+
return ThemeBuilder;
|
|
367
|
+
}();
|
|
368
|
+
function createTheme(base) {
|
|
369
|
+
return new ThemeBuilder(base);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
export { ThemeBuilder, createTheme, flattenScale, serializeTokens };
|
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@animus-ui/theming",
|
|
3
|
-
"version": "0.1.1-beta.
|
|
3
|
+
"version": "0.1.1-beta.15",
|
|
4
4
|
"description": "Theming Utilities",
|
|
5
5
|
"author": "Aaron Robb <airrobb@gmail.com>",
|
|
6
6
|
"homepage": "https://github.com/codecaaron/animus#readme",
|
|
7
7
|
"license": "MIT",
|
|
8
|
-
"module": "./dist/index.
|
|
9
|
-
"main": "./dist/index.
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
10
|
"types": "dist/index.d.ts",
|
|
11
11
|
"publishConfig": {
|
|
12
12
|
"access": "public"
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"url": "https://github.com/codecaaron/animus/issues"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@animus-ui/core": "^0.1.1-beta.
|
|
28
|
+
"@animus-ui/core": "^0.1.1-beta.15"
|
|
29
29
|
},
|
|
30
30
|
"peerDependencies": {
|
|
31
31
|
"@emotion/react": ">=11.0.0",
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"lodash": "*",
|
|
34
34
|
"typescript": ">=4.3.5"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "8563b18650d797788e8e766ff4f1c090e98fb9ea"
|
|
37
37
|
}
|
package/dist/index.cjs.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("lodash");function t(s,r){return Object.keys(s).reduce(((o,h)=>{const i=r?`${r}${"_"===h?"":`-${h}`}`:h,a=s[h];return e.isObject(a)?{...o,...t(a,i)}:{...o,[i]:s[h]}}),{})}const s=(t,s,r)=>{const o={},h={};return Object.keys(t).forEach((i=>{const a=`--${s}-${i}`;o[i]=`var(${a})`,e.merge(h,((t,s,r)=>{if(e.isObject(t)){const{_:e,base:o,...h}=t,i={[s]:e??o};if(r){const{breakpoints:e}=r;Object.keys(e).forEach((t=>{i[e[t]]={[s]:h[t]}}))}return i}return{[s]:t}})(t[i],a,r))})),{tokens:o,variables:h}};class r{#e={};constructor(e){this.#e=e}createScaleVariables(t){const{variables:r,tokens:o}=s(this.#e[t],t,this.#e);return this.#e=e.merge({},this.#e,{[t]:o,_variables:{root:r},_tokens:{[t]:this.#e[t]}}),this}addColors(r){const o=t(r),{variables:h,tokens:i}=s(o,"color",this.#e);return this.#e=e.merge({},this.#e,{colors:i,_variables:{root:h},_tokens:{colors:o}}),this}addColorModes(r,o){const h=e.mapValues(o,(e=>t(e))),{tokens:i,variables:a}=s(e.mapValues(e.merge({},this.#e.modes?.[r],h[r]),(e=>this.#e.colors[e])),"color",this.#e),m=e=>this.#e._tokens?.colors?.[e];return this.#e=e.merge({},this.#e,{colors:i,modes:h,mode:r,_getColorValue:m,_variables:{mode:a},_tokens:{modes:e.mapValues(h,(t=>e.mapValues(t,m)))}}),this}addScale(s,r){return this.#e=e.merge({},this.#e,{[s]:t(r(this.#e))}),this}updateScale(t,s){return this.#e=e.merge({},this.#e,{[t]:s(this.#e[t])}),this}build(){const{variables:t}=s(e.mapValues(this.#e.breakpoints,(e=>`${e}px`)),"breakpoint",this.#e);return e.merge({},this.#e,{_variables:{breakpoints:t},_tokens:{}})}}exports.ThemeBuilder=r,exports.createTheme=function(e){return new r(e)},exports.flattenScale=t,exports.serializeTokens=s;
|
package/dist/index.esm.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{isObject as e,merge as t,mapValues as s}from"lodash";function o(t,s){return Object.keys(t).reduce(((r,h)=>{const i=s?`${s}${"_"===h?"":`-${h}`}`:h,n=t[h];return e(n)?{...r,...o(n,i)}:{...r,[i]:t[h]}}),{})}const r=(s,o,r)=>{const h={},i={};return Object.keys(s).forEach((n=>{const a=`--${o}-${n}`;h[n]=`var(${a})`,t(i,((t,s,o)=>{if(e(t)){const{_:e,base:r,...h}=t,i={[s]:e??r};if(o){const{breakpoints:e}=o;Object.keys(e).forEach((t=>{i[e[t]]={[s]:h[t]}}))}return i}return{[s]:t}})(s[n],a,r))})),{tokens:h,variables:i}};class h{#e={};constructor(e){this.#e=e}createScaleVariables(e){const{variables:s,tokens:o}=r(this.#e[e],e,this.#e);return this.#e=t({},this.#e,{[e]:o,_variables:{root:s},_tokens:{[e]:this.#e[e]}}),this}addColors(e){const s=o(e),{variables:h,tokens:i}=r(s,"color",this.#e);return this.#e=t({},this.#e,{colors:i,_variables:{root:h},_tokens:{colors:s}}),this}addColorModes(e,h){const i=s(h,(e=>o(e))),{tokens:n,variables:a}=r(s(t({},this.#e.modes?.[e],i[e]),(e=>this.#e.colors[e])),"color",this.#e),c=e=>this.#e._tokens?.colors?.[e];return this.#e=t({},this.#e,{colors:n,modes:i,mode:e,_getColorValue:c,_variables:{mode:a},_tokens:{modes:s(i,(e=>s(e,c)))}}),this}addScale(e,s){return this.#e=t({},this.#e,{[e]:o(s(this.#e))}),this}updateScale(e,s){return this.#e=t({},this.#e,{[e]:s(this.#e[e])}),this}build(){const{variables:e}=r(s(this.#e.breakpoints,(e=>`${e}px`)),"breakpoint",this.#e);return t({},this.#e,{_variables:{breakpoints:e},_tokens:{}})}}function i(e){return new h(e)}export{h as ThemeBuilder,i as createTheme,o as flattenScale,r as serializeTokens};
|