@animus-ui/theming 0.1.1-beta.12 → 0.1.1-beta.16

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 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.16](https://github.com/codecaaron/animus/compare/@animus-ui/theming@0.1.1-beta.15...@animus-ui/theming@0.1.1-beta.16) (2022-02-02)
7
+
8
+ **Note:** Version bump only for package @animus-ui/theming
9
+
10
+
11
+
12
+
13
+
14
+ ## [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)
15
+
16
+ **Note:** Version bump only for package @animus-ui/theming
17
+
18
+
19
+
20
+
21
+
22
+ ## [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)
23
+
24
+ **Note:** Version bump only for package @animus-ui/theming
25
+
26
+
27
+
28
+
29
+
30
+ ## [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)
31
+
32
+ **Note:** Version bump only for package @animus-ui/theming
33
+
34
+
35
+
36
+
37
+
6
38
  ## [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)
7
39
 
8
40
  **Note:** Version bump only for package @animus-ui/theming
package/dist/index.js CHANGED
@@ -1,147 +1,372 @@
1
1
  import { isObject, merge, mapValues } from 'lodash';
2
2
 
3
- function flattenScale(object, path) {
4
- return Object.keys(object).reduce((carry, key) => {
5
- const nextKey = path ? `${path}${key === '_' ? '' : `-${key}`}` : key;
6
- const current = object[key];
7
- if (isObject(current)) {
8
- return {
9
- ...carry,
10
- ...flattenScale(current, nextKey),
11
- };
12
- }
13
- return {
14
- ...carry,
15
- [nextKey]: object[key],
16
- };
17
- }, {});
18
- }
19
-
20
- const templateBreakpoints = (value, alias, theme) => {
21
- if (isObject(value)) {
22
- const { _, base, ...rest } = value;
23
- const css = {
24
- [alias]: _ ?? base,
25
- };
26
- if (theme) {
27
- const { breakpoints } = theme;
28
- Object.keys(breakpoints).forEach((key) => {
29
- css[breakpoints[key]] = {
30
- [alias]: rest[key],
31
- };
32
- });
33
- }
34
- return css;
35
- }
36
- return { [alias]: value };
37
- };
38
- const serializeTokens = (tokens, prefix, theme) => {
39
- const tokenReferences = {};
40
- const tokenVariables = {};
41
- Object.keys(tokens).forEach((key) => {
42
- const varName = `--${prefix}-${key}`;
43
- tokenReferences[key] = `var(${varName})`;
44
- merge(tokenVariables, templateBreakpoints(tokens[key], varName, theme));
45
- });
46
- return {
47
- tokens: tokenReferences,
48
- variables: tokenVariables,
49
- };
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);
50
193
  };
51
194
 
52
- class ThemeBuilder {
53
- #theme = {};
54
- constructor(baseTheme) {
55
- this.#theme = baseTheme;
56
- }
57
- /**
58
- *
59
- * @param key A key of the current theme to transform into CSS Variables and Variable References
60
- * @example .createScaleVariables('fontSize')
61
- */
62
- createScaleVariables(key) {
63
- const { variables, tokens } = serializeTokens(this.#theme[key], key, this.#theme);
64
- this.#theme = merge({}, this.#theme, {
65
- [key]: tokens,
66
- _variables: { root: variables },
67
- _tokens: {
68
- [key]: this.#theme[key],
69
- },
70
- });
71
- return this;
72
- }
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
+ }
73
244
  /**
74
245
  *
75
246
  * @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
76
247
  * @example .addColors({ navy: 'navy', hyper: 'purple' })
77
- */
78
- addColors(colors) {
79
- const flatColors = flattenScale(colors);
80
- const { variables, tokens } = serializeTokens(flatColors, 'color', this.#theme);
81
- this.#theme = merge({}, this.#theme, {
82
- colors: tokens,
83
- _variables: { root: variables },
84
- _tokens: { colors: flatColors },
85
- });
86
- return this;
87
- }
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
+ }
88
271
  /**
89
272
  *
90
273
  * @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
91
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`
92
275
  * @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
93
- */
94
- addColorModes(initialMode, modeConfig) {
95
- const modes = mapValues(modeConfig, (mode) => flattenScale(mode));
96
- const { tokens: colors, variables } = serializeTokens(mapValues(merge({}, this.#theme.modes?.[initialMode], modes[initialMode]), (color) => this.#theme.colors[color]), 'color', this.#theme);
97
- const getColorValue = (color) => this.#theme._tokens?.colors?.[color];
98
- this.#theme = merge({}, this.#theme, {
99
- colors,
100
- modes,
101
- mode: initialMode,
102
- _getColorValue: getColorValue,
103
- _variables: { mode: variables },
104
- _tokens: {
105
- modes: mapValues(modes, (mode) => mapValues(mode, getColorValue)),
106
- },
107
- });
108
- return this;
109
- }
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
+ }
110
317
  /**
111
318
  *
112
319
  * @param key A new key of theme
113
320
  * @param createScale A function that accepts the current theme and returns a new object of scale values.
114
321
  * @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
115
- */
116
- addScale(key, createScale) {
117
- this.#theme = merge({}, this.#theme, {
118
- [key]: flattenScale(createScale(this.#theme)),
119
- });
120
- return this;
121
- }
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
+ }
122
331
  /**
123
332
  *
124
333
  * @param key A current key of theme to be updated with new or computed values
125
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.
126
335
  * @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
127
- */
128
- updateScale(key, updateFn) {
129
- this.#theme = merge({}, this.#theme, { [key]: updateFn(this.#theme[key]) });
130
- return this;
131
- }
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
+ }
132
345
  /**
133
346
  * This finalizes the theme build and returns the final theme and variables to be provided.
134
- */
135
- build() {
136
- const { variables } = serializeTokens(mapValues(this.#theme.breakpoints, (val) => `${val}px`), 'breakpoint', this.#theme);
137
- return merge({}, this.#theme, {
138
- _variables: { breakpoints: variables },
139
- _tokens: {},
140
- });
141
- }
142
- }
143
- function createTheme(base) {
144
- return new ThemeBuilder(base);
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);
145
370
  }
146
371
 
147
372
  export { ThemeBuilder, createTheme, flattenScale, serializeTokens };
@@ -1,4 +1,4 @@
1
- import { CSSObject, AbstractTheme } from '@animus-ui/core';
1
+ import { AbstractTheme, CSSObject } from '@animus-ui/core';
2
2
  import { LiteralPaths } from './flattenScale';
3
3
  import { KeyAsVariable } from './serializeTokens';
4
4
  import { ColorModeConfig, Merge, MergeTheme, PrivateThemeKeys } from './types';
@@ -1,5 +1,5 @@
1
- import { Theme } from '@emotion/react';
2
1
  import { CSSObject } from '@animus-ui/core';
2
+ import { Theme } from '@emotion/react';
3
3
  /**
4
4
  * Returns an type of any object with { key: 'var(--key) }
5
5
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@animus-ui/theming",
3
- "version": "0.1.1-beta.12",
3
+ "version": "0.1.1-beta.16",
4
4
  "description": "Theming Utilities",
5
5
  "author": "Aaron Robb <airrobb@gmail.com>",
6
6
  "homepage": "https://github.com/codecaaron/animus#readme",
@@ -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.12"
28
+ "@animus-ui/core": "^0.1.1-beta.16"
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": "5642ca93c52aec07326da5d2a466c9ce54d0e8c8"
36
+ "gitHead": "7359d0512fd5a905fa96149c982bd00ee8245598"
37
37
  }
package/tsconfig.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "extends": "../../tsconfig.json",
3
3
  "compilerOptions": {
4
- // "emitDeclarationOnly": true,
4
+ "skipLibCheck": false,
5
5
  "outDir": "./dist"
6
6
  },
7
7
  "include": ["../../typings/*.d.ts", "./src/**/*.ts", "./src/**/*.tsx"],