@codecademy/variance 0.21.2-alpha.cd6532.0 → 0.21.2

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,29 +1,38 @@
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, identity, isArray, isObject, isUndefined, merge } from 'lodash';
2
14
  import { createScaleLookup } from './scales/createScaleLookup';
3
15
  import { getStaticCss } from './utils/getStaticProperties';
4
16
  import { orderPropNames } from './utils/propNames';
5
17
  import { arrayParser, isMediaArray, isMediaMap, objectParser, orderBreakpoints, parseBreakpoints } from './utils/responsive';
6
- export const variance = {
18
+ export var variance = {
7
19
  // Parser to handle any set of configured props
8
- createParser(config) {
9
- const propNames = orderPropNames(config);
10
- let breakpoints;
11
- const parser = props => {
12
- const styles = {};
13
- const {
14
- theme
15
- } = props;
16
- // Attempt to cache the breakpoints if we have not yet or if theme has become available.
17
- if (breakpoints === undefined || breakpoints === null && theme?.breakpoints) {
20
+ createParser: function createParser(config) {
21
+ var propNames = orderPropNames(config);
22
+ var breakpoints;
23
+ var parser = function parser(props) {
24
+ var styles = {};
25
+ var theme = props.theme; // Attempt to cache the breakpoints if we have not yet or if theme has become available.
26
+ if (breakpoints === undefined || breakpoints === null && theme !== null && theme !== void 0 && theme.breakpoints) {
18
27
  // Save the breakpoints if we can
19
- breakpoints = parseBreakpoints(theme?.breakpoints);
28
+ breakpoints = parseBreakpoints(theme === null || theme === void 0 ? void 0 : theme.breakpoints);
20
29
  }
21
30
 
22
31
  // Loops over all prop names on the configured config to check for configured styles
23
- propNames.forEach(prop => {
24
- const property = config[prop];
25
- const value = get(props, prop);
26
- switch (typeof value) {
32
+ propNames.forEach(function (prop) {
33
+ var property = config[prop];
34
+ var value = get(props, prop);
35
+ switch (_typeof(value)) {
27
36
  case 'string':
28
37
  case 'number':
29
38
  case 'function':
@@ -47,38 +56,38 @@ export const variance = {
47
56
  };
48
57
  // return the parser function with the resulting meta information for further composition
49
58
  return Object.assign(parser, {
50
- propNames,
51
- config
59
+ propNames: propNames,
60
+ config: config
52
61
  });
53
62
  },
54
63
  // Given a single property configuration enrich the config with a transform function
55
64
  // that traverses the properties the function is responsible for.
56
- createTransform(prop, config) {
57
- const {
58
- transform = identity,
59
- property,
60
- properties = [property],
61
- scale
62
- } = config;
63
- const getScaleValue = createScaleLookup(scale);
64
- const alwaysTransform = scale === undefined || isArray(scale);
65
- return {
66
- ...config,
67
- prop,
68
- styleFn: (value, prop, props) => {
69
- const styles = {};
65
+ createTransform: function createTransform(prop, config) {
66
+ var _config$transform = config.transform,
67
+ transform = _config$transform === void 0 ? identity : _config$transform,
68
+ property = config.property,
69
+ _config$properties = config.properties,
70
+ properties = _config$properties === void 0 ? [property] : _config$properties,
71
+ scale = config.scale;
72
+ var getScaleValue = createScaleLookup(scale);
73
+ var alwaysTransform = scale === undefined || isArray(scale);
74
+ return _objectSpread(_objectSpread({}, config), {}, {
75
+ prop: prop,
76
+ styleFn: function styleFn(value, prop, props) {
77
+ var _scaleValue;
78
+ var styles = {};
70
79
  if (isUndefined(value)) {
71
80
  return styles;
72
81
  }
73
- let useTransform = false;
74
- let intermediateValue;
75
- let scaleValue;
76
- switch (typeof value) {
82
+ var useTransform = false;
83
+ var intermediateValue;
84
+ var scaleValue;
85
+ switch (_typeof(value)) {
77
86
  case 'number':
78
87
  case 'string':
79
88
  scaleValue = getScaleValue(value, props);
80
89
  useTransform = scaleValue !== undefined || alwaysTransform;
81
- intermediateValue = scaleValue ?? value;
90
+ intermediateValue = (_scaleValue = scaleValue) !== null && _scaleValue !== void 0 ? _scaleValue : value;
82
91
  break;
83
92
  case 'function':
84
93
  if (props.theme) {
@@ -91,12 +100,12 @@ export const variance = {
91
100
 
92
101
  // for each property look up the scale value from theme if passed and apply any
93
102
  // final transforms to the value
94
- properties.forEach(property => {
95
- let styleValue = intermediateValue;
103
+ properties.forEach(function (property) {
104
+ var styleValue = intermediateValue;
96
105
  if (useTransform && !isUndefined(styleValue)) {
97
106
  styleValue = transform(styleValue, property, props);
98
107
  }
99
- switch (typeof styleValue) {
108
+ switch (_typeof(styleValue)) {
100
109
  case 'number':
101
110
  case 'string':
102
111
  return styles[property] = styleValue;
@@ -108,110 +117,100 @@ export const variance = {
108
117
  // return the resulting styles object
109
118
  return styles;
110
119
  }
111
- };
120
+ });
112
121
  },
113
- compose() {
122
+ compose: function compose() {
114
123
  for (var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++) {
115
124
  parsers[_key] = arguments[_key];
116
125
  }
117
- return this.createParser(parsers.reduce((carry, parser) => ({
118
- ...carry,
119
- ...parser.config
120
- }), {}));
126
+ return this.createParser(parsers.reduce(function (carry, parser) {
127
+ return _objectSpread(_objectSpread({}, carry), parser.config);
128
+ }, {}));
121
129
  },
122
- createCss(config) {
123
- const parser = this.create(config);
124
- const filteredProps = parser.propNames;
125
- return cssProps => {
126
- let cache;
127
- const allKeys = Object.keys(cssProps);
130
+ createCss: function createCss(config) {
131
+ var parser = this.create(config);
132
+ var filteredProps = parser.propNames;
133
+ return function (cssProps) {
134
+ var cache;
135
+ var allKeys = Object.keys(cssProps);
128
136
 
129
137
  /** Any key of the CSSProps that is not a System Prop or a Static CSS Property is treated as a nested selector */
130
- const selectors = allKeys.filter(key => !filteredProps.includes(key) && isObject(cssProps[key]));
138
+ var selectors = allKeys.filter(function (key) {
139
+ return !filteredProps.includes(key) && isObject(cssProps[key]);
140
+ });
131
141
 
132
142
  /** Static CSS Properties get extracted if they match neither syntax */
133
- const staticCss = getStaticCss(cssProps, ['theme',
134
- // Just in case this gets passed somehow
135
- ...selectors, ...filteredProps]);
136
- return _ref => {
137
- let {
138
- theme
139
- } = _ref;
143
+ var staticCss = getStaticCss(cssProps, ['theme'].concat(_toConsumableArray(selectors), _toConsumableArray(filteredProps)));
144
+ return function (_ref) {
145
+ var theme = _ref.theme;
140
146
  if (cache) return cache;
141
- const css = parser({
142
- ...cssProps,
143
- theme
144
- });
145
- selectors.forEach(selector => {
146
- const selectorConfig = cssProps[selector] ?? {};
147
- css[selector] = {
148
- ...getStaticCss(selectorConfig, filteredProps),
149
- ...parser({
150
- ...selectorConfig,
151
- theme
152
- })
153
- };
147
+ var css = parser(_objectSpread(_objectSpread({}, cssProps), {}, {
148
+ theme: theme
149
+ }));
150
+ selectors.forEach(function (selector) {
151
+ var _cssProps$selector;
152
+ var selectorConfig = (_cssProps$selector = cssProps[selector]) !== null && _cssProps$selector !== void 0 ? _cssProps$selector : {};
153
+ css[selector] = _objectSpread(_objectSpread({}, getStaticCss(selectorConfig, filteredProps)), parser(_objectSpread(_objectSpread({}, selectorConfig), {}, {
154
+ theme: theme
155
+ })));
154
156
  });
155
157
 
156
158
  /** Merge the static and generated css and save it to the cache */
157
- cache = {
158
- ...staticCss,
159
- ...css
160
- };
159
+ cache = _objectSpread(_objectSpread({}, staticCss), css);
161
160
  return cache;
162
161
  };
163
162
  };
164
163
  },
165
- createVariant(config) {
166
- const css = this.createCss(config);
167
- return _ref2 => {
168
- let {
169
- prop = 'variant',
170
- defaultVariant,
171
- base = {},
172
- variants
173
- } = _ref2;
174
- const baseFn = css(base);
175
- const variantFns = {};
176
- Object.keys(variants).forEach(key => {
177
- const variantKey = key;
178
- const cssProps = variants[variantKey];
164
+ createVariant: function createVariant(config) {
165
+ var css = this.createCss(config);
166
+ return function (_ref2) {
167
+ var _ref2$prop = _ref2.prop,
168
+ prop = _ref2$prop === void 0 ? 'variant' : _ref2$prop,
169
+ defaultVariant = _ref2.defaultVariant,
170
+ _ref2$base = _ref2.base,
171
+ base = _ref2$base === void 0 ? {} : _ref2$base,
172
+ variants = _ref2.variants;
173
+ var baseFn = css(base);
174
+ var variantFns = {};
175
+ Object.keys(variants).forEach(function (key) {
176
+ var variantKey = key;
177
+ var cssProps = variants[variantKey];
179
178
  variantFns[variantKey] = css(cssProps);
180
179
  });
181
- return props => {
182
- const {
183
- [prop]: selected = defaultVariant
184
- } = props;
185
- const styles = {};
180
+ return function (props) {
181
+ var _variantFns;
182
+ var _props$prop = props[prop],
183
+ selected = _props$prop === void 0 ? defaultVariant : _props$prop;
184
+ var styles = {};
186
185
  if (!selected) return styles;
187
- return merge(styles, baseFn(props), variantFns?.[selected]?.(props));
186
+ 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));
188
187
  };
189
188
  };
190
189
  },
191
- createStates(config) {
192
- const css = this.createCss(config);
193
- return states => {
194
- const orderedStates = Object.keys(states);
195
- const stateFns = {};
196
- orderedStates.forEach(key => {
197
- const stateKey = key;
198
- const cssProps = states[stateKey];
190
+ createStates: function createStates(config) {
191
+ var css = this.createCss(config);
192
+ return function (states) {
193
+ var orderedStates = Object.keys(states);
194
+ var stateFns = {};
195
+ orderedStates.forEach(function (key) {
196
+ var stateKey = key;
197
+ var cssProps = states[stateKey];
199
198
  stateFns[stateKey] = css(cssProps);
200
199
  });
201
- return props => {
202
- const styles = {};
203
- orderedStates.forEach(state => {
200
+ return function (props) {
201
+ var styles = {};
202
+ orderedStates.forEach(function (state) {
204
203
  merge(styles, props[state] && stateFns[state](props));
205
204
  });
206
205
  return styles;
207
206
  };
208
207
  };
209
208
  },
210
- create(config) {
211
- const transforms = {};
209
+ create: function create(config) {
210
+ var transforms = {};
212
211
 
213
212
  // Create a transform function for each of the props
214
- for (const prop in config) {
213
+ for (var prop in config) {
215
214
  if (typeof prop === 'string') {
216
215
  transforms[prop] = this.createTransform(prop, config[prop]);
217
216
  }
@@ -1,120 +1,150 @@
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, merge } from 'lodash';
2
14
  import { flattenScale } from '../utils/flattenScale';
3
15
  import { serializeTokens } from '../utils/serializeTokens';
4
- class ThemeBuilder {
5
- #theme = {};
6
- constructor(baseTheme) {
7
- this.#theme = baseTheme;
16
+ var _theme = new WeakMap();
17
+ var ThemeBuilder = /*#__PURE__*/function () {
18
+ function ThemeBuilder(baseTheme) {
19
+ _classCallCheck(this, ThemeBuilder);
20
+ _theme.set(this, {
21
+ writable: true,
22
+ value: {}
23
+ });
24
+ _classPrivateFieldSet(this, _theme, baseTheme);
8
25
  }
9
26
  /**
10
27
  *
11
28
  * @param key A key of the current theme to transform into CSS Variables and Variable References
12
29
  * @example .createScaleVariables('fontSize')
13
30
  */
14
- createScaleVariables(key) {
15
- const {
16
- variables,
17
- tokens
18
- } = serializeTokens(this.#theme[key], key, this.#theme);
19
- this.#theme = merge({}, this.#theme, {
20
- [key]: tokens,
21
- _variables: {
31
+ _createClass(ThemeBuilder, [{
32
+ key: "createScaleVariables",
33
+ value: function createScaleVariables(key) {
34
+ var _merge;
35
+ var _serializeTokens = serializeTokens(_classPrivateFieldGet(this, _theme)[key], key, _classPrivateFieldGet(this, _theme)),
36
+ variables = _serializeTokens.variables,
37
+ tokens = _serializeTokens.tokens;
38
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), (_merge = {}, _defineProperty(_merge, key, tokens), _defineProperty(_merge, "_variables", {
22
39
  root: variables
23
- },
24
- _tokens: {
25
- [key]: this.#theme[key]
26
- }
27
- });
28
- return this;
29
- }
40
+ }), _defineProperty(_merge, "_tokens", _defineProperty({}, key, _classPrivateFieldGet(this, _theme)[key])), _merge)));
41
+ return this;
42
+ }
30
43
 
31
- /**
32
- *
33
- * @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
34
- * @example .addColors({ navy: 'navy', hyper: 'purple' })
35
- */
36
- addColors(colors) {
37
- const flatColors = flattenScale(colors);
38
- const {
39
- variables,
40
- tokens
41
- } = serializeTokens(flatColors, 'color', this.#theme);
42
- this.#theme = merge({}, this.#theme, {
43
- colors: tokens,
44
- _variables: {
45
- root: variables
46
- },
47
- _tokens: {
48
- colors: flatColors
49
- }
50
- });
51
- return this;
52
- }
44
+ /**
45
+ *
46
+ * @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
47
+ * @example .addColors({ navy: 'navy', hyper: 'purple' })
48
+ */
49
+ }, {
50
+ key: "addColors",
51
+ value: function addColors(colors) {
52
+ var flatColors = flattenScale(colors);
53
+ var _serializeTokens2 = serializeTokens(flatColors, 'color', _classPrivateFieldGet(this, _theme)),
54
+ variables = _serializeTokens2.variables,
55
+ tokens = _serializeTokens2.tokens;
56
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
57
+ colors: tokens,
58
+ _variables: {
59
+ root: variables
60
+ },
61
+ _tokens: {
62
+ colors: flatColors
63
+ }
64
+ }));
65
+ return this;
66
+ }
53
67
 
54
- /**
55
- *
56
- * @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
57
- * @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`
58
- * @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
59
- */
60
- addColorModes(initialMode, modeConfig) {
61
- const modes = mapValues(modeConfig, mode => flattenScale(mode));
62
- const {
63
- tokens: colors,
64
- variables
65
- } = serializeTokens(mapValues(merge({}, this.#theme.modes?.[initialMode], modes[initialMode]), color => this.#theme.colors[color]), 'color', this.#theme);
66
- const getColorValue = color => this.#theme._tokens?.colors?.[color];
67
- this.#theme = merge({}, this.#theme, {
68
- colors,
69
- modes,
70
- mode: initialMode,
71
- _getColorValue: getColorValue,
72
- _variables: {
73
- mode: variables
74
- },
75
- _tokens: {
76
- modes: mapValues(modes, mode => mapValues(mode, getColorValue))
77
- }
78
- });
79
- return this;
80
- }
68
+ /**
69
+ *
70
+ * @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
71
+ * @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`
72
+ * @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
73
+ */
74
+ }, {
75
+ key: "addColorModes",
76
+ value: function addColorModes(initialMode, modeConfig) {
77
+ var _classPrivateFieldGet2,
78
+ _this = this;
79
+ var modes = mapValues(modeConfig, function (mode) {
80
+ return flattenScale(mode);
81
+ });
82
+ var _serializeTokens3 = serializeTokens(mapValues(merge({}, (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _theme).modes) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2[initialMode], modes[initialMode]), function (color) {
83
+ return _classPrivateFieldGet(_this, _theme).colors[color];
84
+ }), 'color', _classPrivateFieldGet(this, _theme)),
85
+ colors = _serializeTokens3.tokens,
86
+ variables = _serializeTokens3.variables;
87
+ var getColorValue = function getColorValue(color) {
88
+ var _classPrivateFieldGet3, _classPrivateFieldGet4;
89
+ return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _theme)._tokens) === null || _classPrivateFieldGet3 === void 0 ? void 0 : (_classPrivateFieldGet4 = _classPrivateFieldGet3.colors) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4[color];
90
+ };
91
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
92
+ colors: colors,
93
+ modes: modes,
94
+ mode: initialMode,
95
+ _getColorValue: getColorValue,
96
+ _variables: {
97
+ mode: variables
98
+ },
99
+ _tokens: {
100
+ modes: mapValues(modes, function (mode) {
101
+ return mapValues(mode, getColorValue);
102
+ })
103
+ }
104
+ }));
105
+ return this;
106
+ }
81
107
 
82
- /**
83
- *
84
- * @param key A new key of theme
85
- * @param createScale A function that accepts the current theme and returns a new object of scale values.
86
- * @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
87
- */
88
- addScale(key, createScale) {
89
- this.#theme = merge({}, this.#theme, {
90
- [key]: flattenScale(createScale(this.#theme))
91
- });
92
- return this;
93
- }
108
+ /**
109
+ *
110
+ * @param key A new key of theme
111
+ * @param createScale A function that accepts the current theme and returns a new object of scale values.
112
+ * @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
113
+ */
114
+ }, {
115
+ key: "addScale",
116
+ value: function addScale(key, createScale) {
117
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, flattenScale(createScale(_classPrivateFieldGet(this, _theme))))));
118
+ return this;
119
+ }
94
120
 
95
- /**
96
- *
97
- * @param key A current key of theme to be updated with new or computed values
98
- * @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.
99
- * @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
100
- */
101
- updateScale(key, updateFn) {
102
- this.#theme = merge({}, this.#theme, {
103
- [key]: updateFn(this.#theme[key])
104
- });
105
- return this;
106
- }
121
+ /**
122
+ *
123
+ * @param key A current key of theme to be updated with new or computed values
124
+ * @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.
125
+ * @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
126
+ */
127
+ }, {
128
+ key: "updateScale",
129
+ value: function updateScale(key, updateFn) {
130
+ _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, updateFn(_classPrivateFieldGet(this, _theme)[key]))));
131
+ return this;
132
+ }
107
133
 
108
- /**
109
- * This finalizes the theme build and returns the final theme and variables to be provided.
110
- */
111
- build() {
112
- return merge({}, this.#theme, {
113
- _variables: {},
114
- _tokens: {}
115
- });
116
- }
117
- }
134
+ /**
135
+ * This finalizes the theme build and returns the final theme and variables to be provided.
136
+ */
137
+ }, {
138
+ key: "build",
139
+ value: function build() {
140
+ return merge({}, _classPrivateFieldGet(this, _theme), {
141
+ _variables: {},
142
+ _tokens: {}
143
+ });
144
+ }
145
+ }]);
146
+ return ThemeBuilder;
147
+ }();
118
148
  export function createTheme(base) {
119
149
  return new ThemeBuilder(base);
120
150
  }
@@ -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';
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
+ };
@@ -1,13 +1,21 @@
1
1
  import { get, isArray, isObject, isString } from 'lodash';
2
- export const createScaleLookup = scale => {
2
+ export var createScaleLookup = function createScaleLookup(scale) {
3
3
  if (isString(scale)) {
4
- return (val, props) => get(props, ['theme', scale, val]);
4
+ return function (val, props) {
5
+ return get(props, ['theme', scale, val]);
6
+ };
5
7
  }
6
8
  if (isArray(scale)) {
7
- return val => val;
9
+ return function (val) {
10
+ return val;
11
+ };
8
12
  }
9
13
  if (isObject(scale)) {
10
- return val => get(scale, val);
14
+ return function (val) {
15
+ return get(scale, val);
16
+ };
11
17
  }
12
- return () => undefined;
18
+ return function () {
19
+ return undefined;
20
+ };
13
21
  };
@@ -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';
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';
2
8
 
3
9
  /**
@@ -5,31 +11,13 @@ import { isObject } from 'lodash';
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,2 +1,6 @@
1
1
  import { keys, pick } from 'lodash';
2
- export const getStaticCss = (props, filteredKeys) => pick(props, keys(props).filter(key => !filteredKeys.includes(key)));
2
+ export var getStaticCss = function getStaticCss(props, filteredKeys) {
3
+ return pick(props, keys(props).filter(function (key) {
4
+ return !filteredKeys.includes(key);
5
+ }));
6
+ };
@@ -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,75 +1,78 @@
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, omit } from 'lodash';
2
- const BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
14
+ var BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
3
15
 
4
16
  /**
5
17
  * Destructures the themes breakpoints into an ordered structure to traverse
6
18
  */
7
- export const parseBreakpoints = breakpoints => {
19
+ export var parseBreakpoints = function parseBreakpoints(breakpoints) {
8
20
  if (breakpoints === undefined) return null;
9
- const {
10
- xs,
11
- sm,
12
- md,
13
- lg,
14
- xl
15
- } = breakpoints ?? {};
16
-
17
- // Ensure order for mapping
21
+ var _ref = breakpoints !== null && breakpoints !== void 0 ? breakpoints : {},
22
+ xs = _ref.xs,
23
+ sm = _ref.sm,
24
+ md = _ref.md,
25
+ lg = _ref.lg,
26
+ xl = _ref.xl; // Ensure order for mapping
18
27
  return {
19
28
  map: breakpoints,
20
29
  array: [xs, sm, md, lg, xl]
21
30
  };
22
31
  };
23
- export const isMediaArray = val => Array.isArray(val);
24
- export const isMediaMap = val => intersection(Object.keys(val), BREAKPOINT_KEYS).length > 0;
25
- export const objectParser = (value, props, config, breakpoints) => {
26
- const styles = {};
27
- const {
28
- styleFn,
29
- prop
30
- } = config;
31
- const {
32
- _,
33
- ...rest
34
- } = value;
35
- // the keyof 'base' is base styles
32
+ export var isMediaArray = function isMediaArray(val) {
33
+ return Array.isArray(val);
34
+ };
35
+ export var isMediaMap = function isMediaMap(val) {
36
+ return intersection(Object.keys(val), BREAKPOINT_KEYS).length > 0;
37
+ };
38
+ export var objectParser = function objectParser(value, props, config, breakpoints) {
39
+ var styles = {};
40
+ var styleFn = config.styleFn,
41
+ prop = config.prop;
42
+ var _ = value._,
43
+ rest = _objectWithoutProperties(value, ["_"]); // the keyof 'base' is base styles
36
44
  if (_) Object.assign(styles, styleFn(_, prop, props));
37
45
 
38
46
  // Map over remaining keys and merge the corresponding breakpoint styles
39
47
  // for that property.
40
- Object.keys(breakpoints).forEach(breakpointKey => {
41
- const bpStyles = rest[breakpointKey];
48
+ Object.keys(breakpoints).forEach(function (breakpointKey) {
49
+ var bpStyles = rest[breakpointKey];
42
50
  if (typeof bpStyles === 'undefined') return;
43
- Object.assign(styles, {
44
- [breakpoints[breakpointKey]]: styleFn(bpStyles, prop, props)
45
- });
51
+ Object.assign(styles, _defineProperty({}, breakpoints[breakpointKey], styleFn(bpStyles, prop, props)));
46
52
  });
47
53
  return styles;
48
54
  };
49
- export const arrayParser = (value, props, config, breakpoints) => {
50
- const styles = {};
51
- const {
52
- styleFn,
53
- prop
54
- } = config;
55
- const [_, ...rest] = value;
56
- // the first index is base styles
55
+ export var arrayParser = function arrayParser(value, props, config, breakpoints) {
56
+ var styles = {};
57
+ var styleFn = config.styleFn,
58
+ prop = config.prop;
59
+ var _value = _toArray(value),
60
+ _ = _value[0],
61
+ rest = _value.slice(1); // the first index is base styles
57
62
  if (_) Object.assign(styles, styleFn(_, prop, props));
58
63
 
59
64
  // Map over each value in the array and merge the corresponding breakpoint styles
60
65
  // for that property.
61
- rest.forEach((val, i) => {
62
- const breakpointKey = breakpoints[i];
66
+ rest.forEach(function (val, i) {
67
+ var breakpointKey = breakpoints[i];
63
68
  if (!breakpointKey || typeof val === 'undefined') return;
64
- Object.assign(styles, {
65
- [breakpointKey]: styleFn(val, prop, props)
66
- });
69
+ Object.assign(styles, _defineProperty({}, breakpointKey, styleFn(val, prop, props)));
67
70
  });
68
71
  return styles;
69
72
  };
70
- export const orderBreakpoints = (styles, breakpoints) => {
71
- const orderedStyles = omit(styles, breakpoints);
72
- breakpoints.forEach(bp => {
73
+ export var orderBreakpoints = function orderBreakpoints(styles, breakpoints) {
74
+ var orderedStyles = omit(styles, breakpoints);
75
+ breakpoints.forEach(function (bp) {
73
76
  if (styles[bp]) {
74
77
  orderedStyles[bp] = styles[bp];
75
78
  }
@@ -1,41 +1,32 @@
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, merge } from 'lodash';
2
-
3
- /**
4
- * Returns an type of any object with { key: 'var(--key) }
5
- */
6
-
7
- const templateBreakpoints = (value, alias, theme) => {
8
+ var templateBreakpoints = function templateBreakpoints(value, alias, theme) {
8
9
  if (isObject(value)) {
9
- const {
10
- _,
11
- base,
12
- ...rest
13
- } = value;
14
- const css = {
15
- [alias]: _ ?? base
16
- };
10
+ var _ = value._,
11
+ base = value.base,
12
+ rest = _objectWithoutProperties(value, ["_", "base"]);
13
+ var css = _defineProperty({}, alias, _ !== null && _ !== void 0 ? _ : base);
17
14
  if (theme) {
18
- const {
19
- breakpoints
20
- } = theme;
21
- Object.keys(breakpoints).forEach(key => {
22
- css[breakpoints[key]] = {
23
- [alias]: rest[key]
24
- };
15
+ var breakpoints = theme.breakpoints;
16
+ Object.keys(breakpoints).forEach(function (key) {
17
+ css[breakpoints[key]] = _defineProperty({}, alias, rest[key]);
25
18
  });
26
19
  }
27
20
  return css;
28
21
  }
29
- return {
30
- [alias]: value
31
- };
22
+ return _defineProperty({}, alias, value);
32
23
  };
33
- export const serializeTokens = (tokens, prefix, theme) => {
34
- const tokenReferences = {};
35
- const tokenVariables = {};
36
- Object.keys(tokens).forEach(key => {
37
- const varName = `--${prefix}-${key}`;
38
- tokenReferences[key] = `var(${varName})`;
24
+ export var serializeTokens = function serializeTokens(tokens, prefix, theme) {
25
+ var tokenReferences = {};
26
+ var tokenVariables = {};
27
+ Object.keys(tokens).forEach(function (key) {
28
+ var varName = "--".concat(prefix, "-").concat(key);
29
+ tokenReferences[key] = "var(".concat(varName, ")");
39
30
  merge(tokenVariables, templateBreakpoints(tokens[key], varName, theme));
40
31
  });
41
32
  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.2-alpha.cd6532.0",
4
+ "version": "0.21.2",
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": "ed4335a5a592f5210d2ff84f14dc50c897c2a355"
35
+ "gitHead": "211364c302abe4d75af11ecabd79c9507284abdc"
36
36
  }