@codecademy/variance 0.21.4-alpha.ff844f.0 → 0.21.4

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/dist/core.js CHANGED
@@ -1,3 +1,15 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
7
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
8
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
9
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
10
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
11
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
12
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
1
13
  import get from 'lodash/get';
2
14
  import identity from 'lodash/identity';
3
15
  import isArray from 'lodash/isArray';
@@ -8,27 +20,24 @@ import { createScaleLookup } from './scales/createScaleLookup';
8
20
  import { getStaticCss } from './utils/getStaticProperties';
9
21
  import { orderPropNames } from './utils/propNames';
10
22
  import { arrayParser, isMediaArray, isMediaMap, objectParser, orderBreakpoints, parseBreakpoints } from './utils/responsive';
11
- export const variance = {
23
+ export var variance = {
12
24
  // Parser to handle any set of configured props
13
- createParser(config) {
14
- const propNames = orderPropNames(config);
15
- let breakpoints;
16
- const parser = props => {
17
- const styles = {};
18
- const {
19
- theme
20
- } = props;
21
- // Attempt to cache the breakpoints if we have not yet or if theme has become available.
22
- if (breakpoints === undefined || breakpoints === null && theme?.breakpoints) {
25
+ createParser: function createParser(config) {
26
+ var propNames = orderPropNames(config);
27
+ var breakpoints;
28
+ var parser = function parser(props) {
29
+ var styles = {};
30
+ var theme = props.theme; // Attempt to cache the breakpoints if we have not yet or if theme has become available.
31
+ if (breakpoints === undefined || breakpoints === null && theme !== null && theme !== void 0 && theme.breakpoints) {
23
32
  // Save the breakpoints if we can
24
- breakpoints = parseBreakpoints(theme?.breakpoints);
33
+ breakpoints = parseBreakpoints(theme === null || theme === void 0 ? void 0 : theme.breakpoints);
25
34
  }
26
35
 
27
36
  // Loops over all prop names on the configured config to check for configured styles
28
- propNames.forEach(prop => {
29
- const property = config[prop];
30
- const value = get(props, prop);
31
- switch (typeof value) {
37
+ propNames.forEach(function (prop) {
38
+ var property = config[prop];
39
+ var value = get(props, prop);
40
+ switch (_typeof(value)) {
32
41
  case 'string':
33
42
  case 'number':
34
43
  case 'function':
@@ -52,38 +61,38 @@ export const variance = {
52
61
  };
53
62
  // return the parser function with the resulting meta information for further composition
54
63
  return Object.assign(parser, {
55
- propNames,
56
- config
64
+ propNames: propNames,
65
+ config: config
57
66
  });
58
67
  },
59
68
  // Given a single property configuration enrich the config with a transform function
60
69
  // that traverses the properties the function is responsible for.
61
- createTransform(prop, config) {
62
- const {
63
- transform = identity,
64
- property,
65
- properties = [property],
66
- scale
67
- } = config;
68
- const getScaleValue = createScaleLookup(scale);
69
- const alwaysTransform = scale === undefined || isArray(scale);
70
- return {
71
- ...config,
72
- prop,
73
- styleFn: (value, prop, props) => {
74
- const styles = {};
70
+ createTransform: function createTransform(prop, config) {
71
+ var _config$transform = config.transform,
72
+ transform = _config$transform === void 0 ? identity : _config$transform,
73
+ property = config.property,
74
+ _config$properties = config.properties,
75
+ properties = _config$properties === void 0 ? [property] : _config$properties,
76
+ scale = config.scale;
77
+ var getScaleValue = createScaleLookup(scale);
78
+ var alwaysTransform = scale === undefined || isArray(scale);
79
+ return _objectSpread(_objectSpread({}, config), {}, {
80
+ prop: prop,
81
+ styleFn: function styleFn(value, prop, props) {
82
+ var _scaleValue;
83
+ var styles = {};
75
84
  if (isUndefined(value)) {
76
85
  return styles;
77
86
  }
78
- let useTransform = false;
79
- let intermediateValue;
80
- let scaleValue;
81
- switch (typeof value) {
87
+ var useTransform = false;
88
+ var intermediateValue;
89
+ var scaleValue;
90
+ switch (_typeof(value)) {
82
91
  case 'number':
83
92
  case 'string':
84
93
  scaleValue = getScaleValue(value, props);
85
94
  useTransform = scaleValue !== undefined || alwaysTransform;
86
- intermediateValue = scaleValue ?? value;
95
+ intermediateValue = (_scaleValue = scaleValue) !== null && _scaleValue !== void 0 ? _scaleValue : value;
87
96
  break;
88
97
  case 'function':
89
98
  if (props.theme) {
@@ -96,12 +105,12 @@ export const variance = {
96
105
 
97
106
  // for each property look up the scale value from theme if passed and apply any
98
107
  // final transforms to the value
99
- properties.forEach(property => {
100
- let styleValue = intermediateValue;
108
+ properties.forEach(function (property) {
109
+ var styleValue = intermediateValue;
101
110
  if (useTransform && !isUndefined(styleValue)) {
102
111
  styleValue = transform(styleValue, property, props);
103
112
  }
104
- switch (typeof styleValue) {
113
+ switch (_typeof(styleValue)) {
105
114
  case 'number':
106
115
  case 'string':
107
116
  return styles[property] = styleValue;
@@ -113,110 +122,100 @@ export const variance = {
113
122
  // return the resulting styles object
114
123
  return styles;
115
124
  }
116
- };
125
+ });
117
126
  },
118
- compose() {
127
+ compose: function compose() {
119
128
  for (var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++) {
120
129
  parsers[_key] = arguments[_key];
121
130
  }
122
- return this.createParser(parsers.reduce((carry, parser) => ({
123
- ...carry,
124
- ...parser.config
125
- }), {}));
131
+ return this.createParser(parsers.reduce(function (carry, parser) {
132
+ return _objectSpread(_objectSpread({}, carry), parser.config);
133
+ }, {}));
126
134
  },
127
- createCss(config) {
128
- const parser = this.create(config);
129
- const filteredProps = parser.propNames;
130
- return cssProps => {
131
- let cache;
132
- const allKeys = Object.keys(cssProps);
135
+ createCss: function createCss(config) {
136
+ var parser = this.create(config);
137
+ var filteredProps = parser.propNames;
138
+ return function (cssProps) {
139
+ var cache;
140
+ var allKeys = Object.keys(cssProps);
133
141
 
134
142
  /** Any key of the CSSProps that is not a System Prop or a Static CSS Property is treated as a nested selector */
135
- const selectors = allKeys.filter(key => !filteredProps.includes(key) && isObject(cssProps[key]));
143
+ var selectors = allKeys.filter(function (key) {
144
+ return !filteredProps.includes(key) && isObject(cssProps[key]);
145
+ });
136
146
 
137
147
  /** Static CSS Properties get extracted if they match neither syntax */
138
- const staticCss = getStaticCss(cssProps, ['theme',
139
- // Just in case this gets passed somehow
140
- ...selectors, ...filteredProps]);
141
- return _ref => {
142
- let {
143
- theme
144
- } = _ref;
148
+ var staticCss = getStaticCss(cssProps, ['theme'].concat(_toConsumableArray(selectors), _toConsumableArray(filteredProps)));
149
+ return function (_ref) {
150
+ var theme = _ref.theme;
145
151
  if (cache) return cache;
146
- const css = parser({
147
- ...cssProps,
148
- theme
149
- });
150
- selectors.forEach(selector => {
151
- const selectorConfig = cssProps[selector] ?? {};
152
- css[selector] = {
153
- ...getStaticCss(selectorConfig, filteredProps),
154
- ...parser({
155
- ...selectorConfig,
156
- theme
157
- })
158
- };
152
+ var css = parser(_objectSpread(_objectSpread({}, cssProps), {}, {
153
+ theme: theme
154
+ }));
155
+ selectors.forEach(function (selector) {
156
+ var _cssProps$selector;
157
+ var selectorConfig = (_cssProps$selector = cssProps[selector]) !== null && _cssProps$selector !== void 0 ? _cssProps$selector : {};
158
+ css[selector] = _objectSpread(_objectSpread({}, getStaticCss(selectorConfig, filteredProps)), parser(_objectSpread(_objectSpread({}, selectorConfig), {}, {
159
+ theme: theme
160
+ })));
159
161
  });
160
162
 
161
163
  /** Merge the static and generated css and save it to the cache */
162
- cache = {
163
- ...staticCss,
164
- ...css
165
- };
164
+ cache = _objectSpread(_objectSpread({}, staticCss), css);
166
165
  return cache;
167
166
  };
168
167
  };
169
168
  },
170
- createVariant(config) {
171
- const css = this.createCss(config);
172
- return _ref2 => {
173
- let {
174
- prop = 'variant',
175
- defaultVariant,
176
- base = {},
177
- variants
178
- } = _ref2;
179
- const baseFn = css(base);
180
- const variantFns = {};
181
- Object.keys(variants).forEach(key => {
182
- const variantKey = key;
183
- const cssProps = variants[variantKey];
169
+ createVariant: function createVariant(config) {
170
+ var css = this.createCss(config);
171
+ return function (_ref2) {
172
+ var _ref2$prop = _ref2.prop,
173
+ prop = _ref2$prop === void 0 ? 'variant' : _ref2$prop,
174
+ defaultVariant = _ref2.defaultVariant,
175
+ _ref2$base = _ref2.base,
176
+ base = _ref2$base === void 0 ? {} : _ref2$base,
177
+ variants = _ref2.variants;
178
+ var baseFn = css(base);
179
+ var variantFns = {};
180
+ Object.keys(variants).forEach(function (key) {
181
+ var variantKey = key;
182
+ var cssProps = variants[variantKey];
184
183
  variantFns[variantKey] = css(cssProps);
185
184
  });
186
- return props => {
187
- const {
188
- [prop]: selected = defaultVariant
189
- } = props;
190
- const styles = {};
185
+ return function (props) {
186
+ var _variantFns;
187
+ var _props$prop = props[prop],
188
+ selected = _props$prop === void 0 ? defaultVariant : _props$prop;
189
+ var styles = {};
191
190
  if (!selected) return styles;
192
- return merge(styles, baseFn(props), variantFns?.[selected]?.(props));
191
+ return merge(styles, baseFn(props), variantFns === null || variantFns === void 0 ? void 0 : (_variantFns = variantFns[selected]) === null || _variantFns === void 0 ? void 0 : _variantFns.call(variantFns, props));
193
192
  };
194
193
  };
195
194
  },
196
- createStates(config) {
197
- const css = this.createCss(config);
198
- return states => {
199
- const orderedStates = Object.keys(states);
200
- const stateFns = {};
201
- orderedStates.forEach(key => {
202
- const stateKey = key;
203
- const cssProps = states[stateKey];
195
+ createStates: function createStates(config) {
196
+ var css = this.createCss(config);
197
+ return function (states) {
198
+ var orderedStates = Object.keys(states);
199
+ var stateFns = {};
200
+ orderedStates.forEach(function (key) {
201
+ var stateKey = key;
202
+ var cssProps = states[stateKey];
204
203
  stateFns[stateKey] = css(cssProps);
205
204
  });
206
- return props => {
207
- const styles = {};
208
- orderedStates.forEach(state => {
205
+ return function (props) {
206
+ var styles = {};
207
+ orderedStates.forEach(function (state) {
209
208
  merge(styles, props[state] && stateFns[state](props));
210
209
  });
211
210
  return styles;
212
211
  };
213
212
  };
214
213
  },
215
- create(config) {
216
- const transforms = {};
214
+ create: function create(config) {
215
+ var transforms = {};
217
216
 
218
217
  // Create a transform function for each of the props
219
- for (const prop in config) {
218
+ for (var prop in config) {
220
219
  if (typeof prop === 'string') {
221
220
  transforms[prop] = this.createTransform(prop, config[prop]);
222
221
  }
@@ -1,121 +1,151 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
5
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
6
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
7
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
8
+ function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
9
+ function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
10
+ function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
11
+ function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
12
+ function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
1
13
  import mapValues from 'lodash/mapValues';
2
14
  import merge from 'lodash/merge';
3
15
  import { flattenScale } from '../utils/flattenScale';
4
16
  import { serializeTokens } from '../utils/serializeTokens';
5
- class ThemeBuilder {
6
- #theme = (() => ({}))();
7
- constructor(baseTheme) {
8
- this.#theme = baseTheme;
17
+ var _theme = new WeakMap();
18
+ var ThemeBuilder = /*#__PURE__*/function () {
19
+ function ThemeBuilder(baseTheme) {
20
+ _classCallCheck(this, ThemeBuilder);
21
+ _theme.set(this, {
22
+ writable: true,
23
+ value: {}
24
+ });
25
+ _classPrivateFieldSet(this, _theme, baseTheme);
9
26
  }
10
27
  /**
11
28
  *
12
29
  * @param key A key of the current theme to transform into CSS Variables and Variable References
13
30
  * @example .createScaleVariables('fontSize')
14
31
  */
15
- createScaleVariables(key) {
16
- const {
17
- variables,
18
- tokens
19
- } = serializeTokens(this.#theme[key], key, this.#theme);
20
- this.#theme = merge({}, this.#theme, {
21
- [key]: tokens,
22
- _variables: {
32
+ _createClass(ThemeBuilder, [{
33
+ key: "createScaleVariables",
34
+ value: function createScaleVariables(key) {
35
+ var _merge;
36
+ var _serializeTokens = serializeTokens(_classPrivateFieldGet(this, _theme)[key], key, _classPrivateFieldGet(this, _theme)),
37
+ variables = _serializeTokens.variables,
38
+ tokens = _serializeTokens.tokens;
39
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), (_merge = {}, _defineProperty(_merge, key, tokens), _defineProperty(_merge, "_variables", {
23
40
  root: variables
24
- },
25
- _tokens: {
26
- [key]: this.#theme[key]
27
- }
28
- });
29
- return this;
30
- }
41
+ }), _defineProperty(_merge, "_tokens", _defineProperty({}, key, _classPrivateFieldGet(this, _theme)[key])), _merge)));
42
+ return this;
43
+ }
31
44
 
32
- /**
33
- *
34
- * @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
35
- * @example .addColors({ navy: 'navy', hyper: 'purple' })
36
- */
37
- addColors(colors) {
38
- const flatColors = flattenScale(colors);
39
- const {
40
- variables,
41
- tokens
42
- } = serializeTokens(flatColors, 'color', this.#theme);
43
- this.#theme = merge({}, this.#theme, {
44
- colors: tokens,
45
- _variables: {
46
- root: variables
47
- },
48
- _tokens: {
49
- colors: flatColors
50
- }
51
- });
52
- return this;
53
- }
45
+ /**
46
+ *
47
+ * @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
48
+ * @example .addColors({ navy: 'navy', hyper: 'purple' })
49
+ */
50
+ }, {
51
+ key: "addColors",
52
+ value: function addColors(colors) {
53
+ var flatColors = flattenScale(colors);
54
+ var _serializeTokens2 = serializeTokens(flatColors, 'color', _classPrivateFieldGet(this, _theme)),
55
+ variables = _serializeTokens2.variables,
56
+ tokens = _serializeTokens2.tokens;
57
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
58
+ colors: tokens,
59
+ _variables: {
60
+ root: variables
61
+ },
62
+ _tokens: {
63
+ colors: flatColors
64
+ }
65
+ }));
66
+ return this;
67
+ }
54
68
 
55
- /**
56
- *
57
- * @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
58
- * @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`
59
- * @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
60
- */
61
- addColorModes(initialMode, modeConfig) {
62
- const modes = mapValues(modeConfig, mode => flattenScale(mode));
63
- const {
64
- tokens: colors,
65
- variables
66
- } = serializeTokens(mapValues(merge({}, this.#theme.modes?.[initialMode], modes[initialMode]), color => this.#theme.colors[color]), 'color', this.#theme);
67
- const getColorValue = color => this.#theme._tokens?.colors?.[color];
68
- this.#theme = merge({}, this.#theme, {
69
- colors,
70
- modes,
71
- mode: initialMode,
72
- _getColorValue: getColorValue,
73
- _variables: {
74
- mode: variables
75
- },
76
- _tokens: {
77
- modes: mapValues(modes, mode => mapValues(mode, getColorValue))
78
- }
79
- });
80
- return this;
81
- }
69
+ /**
70
+ *
71
+ * @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
72
+ * @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`
73
+ * @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
74
+ */
75
+ }, {
76
+ key: "addColorModes",
77
+ value: function addColorModes(initialMode, modeConfig) {
78
+ var _classPrivateFieldGet2,
79
+ _this = this;
80
+ var modes = mapValues(modeConfig, function (mode) {
81
+ return flattenScale(mode);
82
+ });
83
+ var _serializeTokens3 = serializeTokens(mapValues(merge({}, (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _theme).modes) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2[initialMode], modes[initialMode]), function (color) {
84
+ return _classPrivateFieldGet(_this, _theme).colors[color];
85
+ }), 'color', _classPrivateFieldGet(this, _theme)),
86
+ colors = _serializeTokens3.tokens,
87
+ variables = _serializeTokens3.variables;
88
+ var getColorValue = function getColorValue(color) {
89
+ var _classPrivateFieldGet3, _classPrivateFieldGet4;
90
+ return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _theme)._tokens) === null || _classPrivateFieldGet3 === void 0 ? void 0 : (_classPrivateFieldGet4 = _classPrivateFieldGet3.colors) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4[color];
91
+ };
92
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
93
+ colors: colors,
94
+ modes: modes,
95
+ mode: initialMode,
96
+ _getColorValue: getColorValue,
97
+ _variables: {
98
+ mode: variables
99
+ },
100
+ _tokens: {
101
+ modes: mapValues(modes, function (mode) {
102
+ return mapValues(mode, getColorValue);
103
+ })
104
+ }
105
+ }));
106
+ return this;
107
+ }
82
108
 
83
- /**
84
- *
85
- * @param key A new key of theme
86
- * @param createScale A function that accepts the current theme and returns a new object of scale values.
87
- * @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
88
- */
89
- addScale(key, createScale) {
90
- this.#theme = merge({}, this.#theme, {
91
- [key]: flattenScale(createScale(this.#theme))
92
- });
93
- return this;
94
- }
109
+ /**
110
+ *
111
+ * @param key A new key of theme
112
+ * @param createScale A function that accepts the current theme and returns a new object of scale values.
113
+ * @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
114
+ */
115
+ }, {
116
+ key: "addScale",
117
+ value: function addScale(key, createScale) {
118
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, flattenScale(createScale(_classPrivateFieldGet(this, _theme))))));
119
+ return this;
120
+ }
95
121
 
96
- /**
97
- *
98
- * @param key A current key of theme to be updated with new or computed values
99
- * @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.
100
- * @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
101
- */
102
- updateScale(key, updateFn) {
103
- this.#theme = merge({}, this.#theme, {
104
- [key]: updateFn(this.#theme[key])
105
- });
106
- return this;
107
- }
122
+ /**
123
+ *
124
+ * @param key A current key of theme to be updated with new or computed values
125
+ * @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
+ * @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
127
+ */
128
+ }, {
129
+ key: "updateScale",
130
+ value: function updateScale(key, updateFn) {
131
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, updateFn(_classPrivateFieldGet(this, _theme)[key]))));
132
+ return this;
133
+ }
108
134
 
109
- /**
110
- * This finalizes the theme build and returns the final theme and variables to be provided.
111
- */
112
- build() {
113
- return merge({}, this.#theme, {
114
- _variables: {},
115
- _tokens: {}
116
- });
117
- }
118
- }
135
+ /**
136
+ * This finalizes the theme build and returns the final theme and variables to be provided.
137
+ */
138
+ }, {
139
+ key: "build",
140
+ value: function build() {
141
+ return merge({}, _classPrivateFieldGet(this, _theme), {
142
+ _variables: {},
143
+ _tokens: {}
144
+ });
145
+ }
146
+ }]);
147
+ return ThemeBuilder;
148
+ }();
119
149
  export function createTheme(base) {
120
150
  return new ThemeBuilder(base);
121
151
  }
@@ -1,7 +1,13 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1
7
  import mapValues from 'lodash/mapValues';
2
8
  import { createTheme } from './createTheme';
3
- describe('createTheme', () => {
4
- const base = {
9
+ describe('createTheme', function () {
10
+ var base = {
5
11
  breakpoints: {
6
12
  xs: '1',
7
13
  sm: '2',
@@ -10,46 +16,53 @@ describe('createTheme', () => {
10
16
  xl: '5'
11
17
  }
12
18
  };
13
- it('works', () => {
14
- expect(createTheme(base).build()).toEqual({
15
- ...base,
19
+ it('works', function () {
20
+ expect(createTheme(base).build()).toEqual(_objectSpread(_objectSpread({}, base), {}, {
16
21
  _variables: {},
17
22
  _tokens: {}
18
- });
23
+ }));
19
24
  });
20
- it('adds a scale', () => {
21
- const theme = createTheme(base).addScale('test', () => ({
22
- test: 1,
23
- test2: 2
24
- })).build();
25
+ it('adds a scale', function () {
26
+ var theme = createTheme(base).addScale('test', function () {
27
+ return {
28
+ test: 1,
29
+ test2: 2
30
+ };
31
+ }).build();
25
32
  expect(theme.test).toEqual({
26
33
  test: 1,
27
34
  test2: 2
28
35
  });
29
36
  });
30
- it('updates a scale', () => {
31
- const builder = createTheme(base).addScale('test', () => ({
32
- test: 1,
33
- test2: 2
34
- }));
37
+ it('updates a scale', function () {
38
+ var builder = createTheme(base).addScale('test', function () {
39
+ return {
40
+ test: 1,
41
+ test2: 2
42
+ };
43
+ });
35
44
  expect(builder.build().test).toEqual({
36
45
  test: 1,
37
46
  test2: 2
38
47
  });
39
- builder.updateScale('test', () => ({
40
- test3: 3
41
- }));
48
+ builder.updateScale('test', function () {
49
+ return {
50
+ test3: 3
51
+ };
52
+ });
42
53
  expect(builder.build().test).toEqual({
43
54
  test: 1,
44
55
  test2: 2,
45
56
  test3: 3
46
57
  });
47
58
  });
48
- it('serializes variables', () => {
49
- const theme = createTheme(base).addScale('test', () => ({
50
- test: 1,
51
- test2: 2
52
- })).createScaleVariables('test').build();
59
+ it('serializes variables', function () {
60
+ var theme = createTheme(base).addScale('test', function () {
61
+ return {
62
+ test: 1,
63
+ test2: 2
64
+ };
65
+ }).createScaleVariables('test').build();
53
66
  expect(theme.test).toEqual({
54
67
  test: 'var(--test-test)',
55
68
  test2: 'var(--test-test2)'
@@ -59,22 +72,24 @@ describe('createTheme', () => {
59
72
  '--test-test2': 2
60
73
  });
61
74
  });
62
- describe('colors', () => {
63
- const staticColors = {
75
+ describe('colors', function () {
76
+ var staticColors = {
64
77
  white: 'white',
65
78
  black: 'black',
66
79
  blue: 'blue',
67
80
  green: 'green',
68
81
  red: 'red'
69
82
  };
70
- const cssVariableReferences = mapValues(staticColors, val => `var(--color-${val})`);
71
- const builder = createTheme(base);
72
- it('creates color variables', () => {
73
- const theme = builder.addColors(staticColors).build();
83
+ var cssVariableReferences = mapValues(staticColors, function (val) {
84
+ return "var(--color-".concat(val, ")");
85
+ });
86
+ var builder = createTheme(base);
87
+ it('creates color variables', function () {
88
+ var theme = builder.addColors(staticColors).build();
74
89
  expect(theme.colors).toEqual(cssVariableReferences);
75
90
  });
76
- it('adds colorModes', () => {
77
- const theme = builder.addColors(staticColors).addColorModes('light', {
91
+ it('adds colorModes', function () {
92
+ var theme = builder.addColors(staticColors).addColorModes('light', {
78
93
  light: {
79
94
  primary: 'red'
80
95
  },
@@ -82,16 +97,17 @@ describe('createTheme', () => {
82
97
  primary: 'blue'
83
98
  }
84
99
  }).build();
85
- expect(theme.colors).toEqual({
86
- ...mapValues(staticColors, val => `var(--color-${val})`),
100
+ expect(theme.colors).toEqual(_objectSpread(_objectSpread({}, mapValues(staticColors, function (val) {
101
+ return "var(--color-".concat(val, ")");
102
+ })), {}, {
87
103
  primary: 'var(--color-primary)'
88
- });
104
+ }));
89
105
  expect(theme._variables.mode).toEqual({
90
106
  '--color-primary': 'var(--color-red)'
91
107
  });
92
108
  });
93
- it('returns value checker for colors', () => {
94
- const theme = builder.addColors({
109
+ it('returns value checker for colors', function () {
110
+ var theme = builder.addColors({
95
111
  black: '#000000',
96
112
  white: '#FFFFFF'
97
113
  }).addColorModes('light', {
@@ -105,8 +121,8 @@ describe('createTheme', () => {
105
121
  expect(theme._getColorValue('white')).toEqual('#FFFFFF');
106
122
  expect(theme._getColorValue(theme.modes.light.primary)).toEqual('#000000');
107
123
  });
108
- it('returns value checker for colors with deep values', () => {
109
- const theme = builder.addColors({
124
+ it('returns value checker for colors with deep values', function () {
125
+ var theme = builder.addColors({
110
126
  black: '#000000',
111
127
  white: '#FFFFFF',
112
128
  gray: {
@@ -116,7 +132,7 @@ describe('createTheme', () => {
116
132
  }).addColorModes('light', {
117
133
  light: {
118
134
  primary: {
119
- default: 'gray-200',
135
+ "default": 'gray-200',
120
136
  cool: {
121
137
  _: 'gray-300',
122
138
  town: 'black'
@@ -127,8 +143,8 @@ describe('createTheme', () => {
127
143
  expect(theme._getColorValue('gray-300')).toEqual('#666666');
128
144
  expect(theme._getColorValue(theme.modes.light['primary-default'])).toEqual('#eeeeee');
129
145
  });
130
- it('merges color mode configurations when overriden', () => {
131
- const theme = builder.addColors({
146
+ it('merges color mode configurations when overriden', function () {
147
+ var theme = builder.addColors({
132
148
  black: '#000000',
133
149
  white: '#FFFFFF'
134
150
  }).addColorModes('light', {
@@ -139,7 +155,7 @@ describe('createTheme', () => {
139
155
  }
140
156
  }
141
157
  }).build();
142
- const override = createTheme(theme).addColorModes('light', {
158
+ var override = createTheme(theme).addColorModes('light', {
143
159
  light: {
144
160
  primary: {
145
161
  _: 'white',
@@ -149,8 +165,8 @@ describe('createTheme', () => {
149
165
  }).build();
150
166
  expect(override.modes.light.primary).toEqual('white');
151
167
  });
152
- it('returns the raw values of color mode colors on the tokens object', () => {
153
- const theme = createTheme(base).addColors({
168
+ it('returns the raw values of color mode colors on the tokens object', function () {
169
+ var theme = createTheme(base).addColors({
154
170
  black: '#000000',
155
171
  gray: {
156
172
  300: '#666666'
@@ -1 +1,3 @@
1
- export const createScale = () => [];
1
+ export var createScale = function createScale() {
2
+ return [];
3
+ };
@@ -2,15 +2,23 @@ import get from 'lodash/get';
2
2
  import isArray from 'lodash/isArray';
3
3
  import isObject from 'lodash/isObject';
4
4
  import isString from 'lodash/isString';
5
- export const createScaleLookup = scale => {
5
+ export var createScaleLookup = function createScaleLookup(scale) {
6
6
  if (isString(scale)) {
7
- return (val, props) => get(props, ['theme', scale, val]);
7
+ return function (val, props) {
8
+ return get(props, ['theme', scale, val]);
9
+ };
8
10
  }
9
11
  if (isArray(scale)) {
10
- return val => val;
12
+ return function (val) {
13
+ return val;
14
+ };
11
15
  }
12
16
  if (isObject(scale)) {
13
- return val => get(scale, val);
17
+ return function (val) {
18
+ return get(scale, val);
19
+ };
14
20
  }
15
- return () => undefined;
21
+ return function () {
22
+ return undefined;
23
+ };
16
24
  };
@@ -1,25 +1,35 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
5
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0) { ; } } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i["return"] && (_r = _i["return"](), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
6
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
1
7
  import isNumber from 'lodash/isNumber';
2
- export const percentageOrAbsolute = coordinate => {
8
+ export var percentageOrAbsolute = function percentageOrAbsolute(coordinate) {
3
9
  if (coordinate === 0) {
4
10
  return coordinate;
5
11
  }
6
12
  if (coordinate <= 1 && coordinate >= -1) {
7
- return `${coordinate * 100}%`;
13
+ return "".concat(coordinate * 100, "%");
8
14
  }
9
- return `${coordinate}px`;
15
+ return "".concat(coordinate, "px");
10
16
  };
11
- const valueWithUnit = /(-?\d*\.?\d+)(%|\w*)/;
12
- export const transformSize = value => {
17
+ var valueWithUnit = /(-?\d*\.?\d+)(%|\w*)/;
18
+ export var transformSize = function transformSize(value) {
13
19
  if (isNumber(value)) {
14
20
  return percentageOrAbsolute(value);
15
21
  }
16
22
  if (value.includes('calc')) {
17
23
  return value;
18
24
  }
19
- const [match, number, unit] = valueWithUnit.exec(value) || [];
25
+ var _ref = valueWithUnit.exec(value) || [],
26
+ _ref2 = _slicedToArray(_ref, 3),
27
+ match = _ref2[0],
28
+ number = _ref2[1],
29
+ unit = _ref2[2];
20
30
  if (match === undefined) {
21
31
  return value;
22
32
  }
23
- const numericValue = parseFloat(number);
24
- return !unit ? percentageOrAbsolute(numericValue) : `${numericValue}${unit}`;
33
+ var numericValue = parseFloat(number);
34
+ return !unit ? percentageOrAbsolute(numericValue) : "".concat(numericValue).concat(unit);
25
35
  };
@@ -1,3 +1,9 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
3
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
1
7
  import isObject from 'lodash/isObject';
2
8
 
3
9
  /**
@@ -5,31 +11,13 @@ import isObject from 'lodash/isObject';
5
11
  * Possibilities are returned as `k1.k2.k3`.
6
12
  */
7
13
 
8
- /** Returns valid paths of object T */
9
-
10
- /** Returns the value of a valid path P `k1.k2.k3` in object T */
11
-
12
- /** Check if path has a primitive end value and return only the union of end paths */
13
-
14
- /**
15
- * Reduce all paths to a single map of paths with primitive values removing all extra non stateful paths
16
- * { path: { sub: 1 } } => { 'path-sub': 1 }
17
- *
18
- */
19
-
20
14
  export function flattenScale(object, path) {
21
- return Object.keys(object).reduce((carry, key) => {
22
- const nextKey = path ? `${path}${key === '_' ? '' : `-${key}`}` : key;
23
- const current = object[key];
15
+ return Object.keys(object).reduce(function (carry, key) {
16
+ var nextKey = path ? "".concat(path).concat(key === '_' ? '' : "-".concat(key)) : key;
17
+ var current = object[key];
24
18
  if (isObject(current)) {
25
- return {
26
- ...carry,
27
- ...flattenScale(current, nextKey)
28
- };
19
+ return _objectSpread(_objectSpread({}, carry), flattenScale(current, nextKey));
29
20
  }
30
- return {
31
- ...carry,
32
- [nextKey]: object[key]
33
- };
21
+ return _objectSpread(_objectSpread({}, carry), {}, _defineProperty({}, nextKey, object[key]));
34
22
  }, {});
35
23
  }
@@ -1,3 +1,7 @@
1
1
  import keys from 'lodash/keys';
2
2
  import pick from 'lodash/pick';
3
- export const getStaticCss = (props, filteredKeys) => pick(props, keys(props).filter(key => !filteredKeys.includes(key)));
3
+ export var getStaticCss = function getStaticCss(props, filteredKeys) {
4
+ return pick(props, keys(props).filter(function (key) {
5
+ return !filteredKeys.includes(key);
6
+ }));
7
+ };
@@ -1,10 +1,10 @@
1
- const SHORTHAND_PROPERTIES = ['border', 'borderTop', 'borderBottom', 'borderLeft', 'borderRight', 'borderWidth', 'borderStyle', 'borderColor', 'background', 'flex', 'margin', 'padding', 'transition', 'gap', 'grid', 'gridArea', 'gridColumn', 'gridRow', 'gridTemplate', 'overflow', 'transition'];
2
- const SORT = {
1
+ var SHORTHAND_PROPERTIES = ['border', 'borderTop', 'borderBottom', 'borderLeft', 'borderRight', 'borderWidth', 'borderStyle', 'borderColor', 'background', 'flex', 'margin', 'padding', 'transition', 'gap', 'grid', 'gridArea', 'gridColumn', 'gridRow', 'gridTemplate', 'overflow', 'transition'];
2
+ var SORT = {
3
3
  A_BEFORE_B: -1,
4
4
  B_BEFORE_A: 1,
5
5
  EQUAL: 1
6
6
  };
7
- const compare = (a, b) => {
7
+ var compare = function compare(a, b) {
8
8
  if (a < b) return SORT.A_BEFORE_B;
9
9
  if (b < a) return SORT.B_BEFORE_A;
10
10
  return SORT.EQUAL;
@@ -14,34 +14,32 @@ const compare = (a, b) => {
14
14
  * Orders all properties by the most dependent props
15
15
  * @param config
16
16
  */
17
- export const orderPropNames = config => Object.keys(config).sort((a, b) => {
18
- const {
19
- [a]: aConf,
20
- [b]: bConf
21
- } = config;
22
- const {
23
- property: aProp,
24
- properties: aProperties = []
25
- } = aConf;
26
- const {
27
- property: bProp,
28
- properties: bProperties = []
29
- } = bConf;
30
- const aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
31
- const bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
32
- if (aIsShorthand && bIsShorthand) {
33
- const aNum = aProperties.length;
34
- const bNum = bProperties.length;
35
- if (aProp !== bProp) {
36
- return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
17
+ export var orderPropNames = function orderPropNames(config) {
18
+ return Object.keys(config).sort(function (a, b) {
19
+ var aConf = config[a],
20
+ bConf = config[b];
21
+ var aProp = aConf.property,
22
+ _aConf$properties = aConf.properties,
23
+ aProperties = _aConf$properties === void 0 ? [] : _aConf$properties;
24
+ var bProp = bConf.property,
25
+ _bConf$properties = bConf.properties,
26
+ bProperties = _bConf$properties === void 0 ? [] : _bConf$properties;
27
+ var aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
28
+ var bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
29
+ if (aIsShorthand && bIsShorthand) {
30
+ var aNum = aProperties.length;
31
+ var bNum = bProperties.length;
32
+ if (aProp !== bProp) {
33
+ return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
34
+ }
35
+ if (aProp === bProp) {
36
+ if (aNum === 0) return SORT.A_BEFORE_B;
37
+ if (bNum === 0) return SORT.B_BEFORE_A;
38
+ }
39
+ return compare(bNum, aNum);
37
40
  }
38
- if (aProp === bProp) {
39
- if (aNum === 0) return SORT.A_BEFORE_B;
40
- if (bNum === 0) return SORT.B_BEFORE_A;
41
- }
42
- return compare(bNum, aNum);
43
- }
44
- if (aIsShorthand) return SORT.A_BEFORE_B;
45
- if (bIsShorthand) return SORT.B_BEFORE_A;
46
- return SORT.EQUAL;
47
- });
41
+ if (aIsShorthand) return SORT.A_BEFORE_B;
42
+ if (bIsShorthand) return SORT.B_BEFORE_A;
43
+ return SORT.EQUAL;
44
+ });
45
+ };
@@ -1,76 +1,79 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
3
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
5
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
6
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
8
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
9
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
10
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
11
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
12
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
1
13
  import intersection from 'lodash/intersection';
2
14
  import omit from 'lodash/omit';
3
- const BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
15
+ var BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
4
16
 
5
17
  /**
6
18
  * Destructures the themes breakpoints into an ordered structure to traverse
7
19
  */
8
- export const parseBreakpoints = breakpoints => {
20
+ export var parseBreakpoints = function parseBreakpoints(breakpoints) {
9
21
  if (breakpoints === undefined) return null;
10
- const {
11
- xs,
12
- sm,
13
- md,
14
- lg,
15
- xl
16
- } = breakpoints ?? {};
17
-
18
- // Ensure order for mapping
22
+ var _ref = breakpoints !== null && breakpoints !== void 0 ? breakpoints : {},
23
+ xs = _ref.xs,
24
+ sm = _ref.sm,
25
+ md = _ref.md,
26
+ lg = _ref.lg,
27
+ xl = _ref.xl; // Ensure order for mapping
19
28
  return {
20
29
  map: breakpoints,
21
30
  array: [xs, sm, md, lg, xl]
22
31
  };
23
32
  };
24
- export const isMediaArray = val => Array.isArray(val);
25
- export const isMediaMap = val => intersection(Object.keys(val), BREAKPOINT_KEYS).length > 0;
26
- export const objectParser = (value, props, config, breakpoints) => {
27
- const styles = {};
28
- const {
29
- styleFn,
30
- prop
31
- } = config;
32
- const {
33
- _,
34
- ...rest
35
- } = value;
36
- // the keyof 'base' is base styles
33
+ export var isMediaArray = function isMediaArray(val) {
34
+ return Array.isArray(val);
35
+ };
36
+ export var isMediaMap = function isMediaMap(val) {
37
+ return intersection(Object.keys(val), BREAKPOINT_KEYS).length > 0;
38
+ };
39
+ export var objectParser = function objectParser(value, props, config, breakpoints) {
40
+ var styles = {};
41
+ var styleFn = config.styleFn,
42
+ prop = config.prop;
43
+ var _ = value._,
44
+ rest = _objectWithoutProperties(value, ["_"]); // the keyof 'base' is base styles
37
45
  if (_) Object.assign(styles, styleFn(_, prop, props));
38
46
 
39
47
  // Map over remaining keys and merge the corresponding breakpoint styles
40
48
  // for that property.
41
- Object.keys(breakpoints).forEach(breakpointKey => {
42
- const bpStyles = rest[breakpointKey];
49
+ Object.keys(breakpoints).forEach(function (breakpointKey) {
50
+ var bpStyles = rest[breakpointKey];
43
51
  if (typeof bpStyles === 'undefined') return;
44
- Object.assign(styles, {
45
- [breakpoints[breakpointKey]]: styleFn(bpStyles, prop, props)
46
- });
52
+ Object.assign(styles, _defineProperty({}, breakpoints[breakpointKey], styleFn(bpStyles, prop, props)));
47
53
  });
48
54
  return styles;
49
55
  };
50
- export const arrayParser = (value, props, config, breakpoints) => {
51
- const styles = {};
52
- const {
53
- styleFn,
54
- prop
55
- } = config;
56
- const [_, ...rest] = value;
57
- // the first index is base styles
56
+ export var arrayParser = function arrayParser(value, props, config, breakpoints) {
57
+ var styles = {};
58
+ var styleFn = config.styleFn,
59
+ prop = config.prop;
60
+ var _value = _toArray(value),
61
+ _ = _value[0],
62
+ rest = _value.slice(1); // the first index is base styles
58
63
  if (_) Object.assign(styles, styleFn(_, prop, props));
59
64
 
60
65
  // Map over each value in the array and merge the corresponding breakpoint styles
61
66
  // for that property.
62
- rest.forEach((val, i) => {
63
- const breakpointKey = breakpoints[i];
67
+ rest.forEach(function (val, i) {
68
+ var breakpointKey = breakpoints[i];
64
69
  if (!breakpointKey || typeof val === 'undefined') return;
65
- Object.assign(styles, {
66
- [breakpointKey]: styleFn(val, prop, props)
67
- });
70
+ Object.assign(styles, _defineProperty({}, breakpointKey, styleFn(val, prop, props)));
68
71
  });
69
72
  return styles;
70
73
  };
71
- export const orderBreakpoints = (styles, breakpoints) => {
72
- const orderedStyles = omit(styles, breakpoints);
73
- breakpoints.forEach(bp => {
74
+ export var orderBreakpoints = function orderBreakpoints(styles, breakpoints) {
75
+ var orderedStyles = omit(styles, breakpoints);
76
+ breakpoints.forEach(function (bp) {
74
77
  if (styles[bp]) {
75
78
  orderedStyles[bp] = styles[bp];
76
79
  }
@@ -1,42 +1,33 @@
1
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
2
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
3
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
4
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
5
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
6
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
1
7
  import isObject from 'lodash/isObject';
2
8
  import merge from 'lodash/merge';
3
-
4
- /**
5
- * Returns an type of any object with { key: 'var(--key) }
6
- */
7
-
8
- const templateBreakpoints = (value, alias, theme) => {
9
+ var templateBreakpoints = function templateBreakpoints(value, alias, theme) {
9
10
  if (isObject(value)) {
10
- const {
11
- _,
12
- base,
13
- ...rest
14
- } = value;
15
- const css = {
16
- [alias]: _ ?? base
17
- };
11
+ var _ = value._,
12
+ base = value.base,
13
+ rest = _objectWithoutProperties(value, ["_", "base"]);
14
+ var css = _defineProperty({}, alias, _ !== null && _ !== void 0 ? _ : base);
18
15
  if (theme) {
19
- const {
20
- breakpoints
21
- } = theme;
22
- Object.keys(breakpoints).forEach(key => {
23
- css[breakpoints[key]] = {
24
- [alias]: rest[key]
25
- };
16
+ var breakpoints = theme.breakpoints;
17
+ Object.keys(breakpoints).forEach(function (key) {
18
+ css[breakpoints[key]] = _defineProperty({}, alias, rest[key]);
26
19
  });
27
20
  }
28
21
  return css;
29
22
  }
30
- return {
31
- [alias]: value
32
- };
23
+ return _defineProperty({}, alias, value);
33
24
  };
34
- export const serializeTokens = (tokens, prefix, theme) => {
35
- const tokenReferences = {};
36
- const tokenVariables = {};
37
- Object.keys(tokens).forEach(key => {
38
- const varName = `--${prefix}-${key}`;
39
- tokenReferences[key] = `var(${varName})`;
25
+ export var serializeTokens = function serializeTokens(tokens, prefix, theme) {
26
+ var tokenReferences = {};
27
+ var tokenVariables = {};
28
+ Object.keys(tokens).forEach(function (key) {
29
+ var varName = "--".concat(prefix, "-").concat(key);
30
+ tokenReferences[key] = "var(".concat(varName, ")");
40
31
  merge(tokenVariables, templateBreakpoints(tokens[key], varName, theme));
41
32
  });
42
33
  return {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@codecademy/variance",
3
3
  "description": "Constraint based CSS in JS for building scalable design systems",
4
- "version": "0.21.4-alpha.ff844f.0",
4
+ "version": "0.21.4",
5
5
  "author": "codecaaron <aaron@codecademy.com>",
6
6
  "dependencies": {
7
7
  "csstype": "^3.0.7",
@@ -32,5 +32,5 @@
32
32
  "build": "nx build @codecademy/variance"
33
33
  },
34
34
  "types": "dist/index.d.ts",
35
- "gitHead": "d56c4883987ddc512a2026b4882b17400ffbbfcb"
35
+ "gitHead": "a668807575304a6b738d5b328cbb5b1b108f3bd3"
36
36
  }