@codecademy/variance 0.20.6-alpha.edcdf7.0 → 0.21.0

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,23 +1,15 @@
1
1
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
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."); }
4
-
5
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); }
6
-
7
4
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
5
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
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; }
12
-
13
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; }
14
-
15
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; }
16
-
17
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
18
-
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); }
19
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); }
20
-
21
13
  import { get, identity, isArray, isObject, isUndefined, merge } from 'lodash';
22
14
  import { createScaleLookup } from './scales/createScaleLookup';
23
15
  import { getStaticCss } from './utils/getStaticProperties';
@@ -28,49 +20,41 @@ export var variance = {
28
20
  createParser: function createParser(config) {
29
21
  var propNames = orderPropNames(config);
30
22
  var breakpoints;
31
-
32
23
  var parser = function parser(props) {
33
24
  var styles = {};
34
25
  var theme = props.theme; // Attempt to cache the breakpoints if we have not yet or if theme has become available.
35
-
36
26
  if (breakpoints === undefined || breakpoints === null && theme !== null && theme !== void 0 && theme.breakpoints) {
37
27
  // Save the breakpoints if we can
38
28
  breakpoints = parseBreakpoints(theme === null || theme === void 0 ? void 0 : theme.breakpoints);
39
- } // Loops over all prop names on the configured config to check for configured styles
40
-
29
+ }
41
30
 
31
+ // Loops over all prop names on the configured config to check for configured styles
42
32
  propNames.forEach(function (prop) {
43
33
  var property = config[prop];
44
34
  var value = get(props, prop);
45
-
46
35
  switch (_typeof(value)) {
47
36
  case 'string':
48
37
  case 'number':
49
38
  case 'function':
50
39
  return Object.assign(styles, property.styleFn(value, prop, props));
51
40
  // handle any props configured with the responsive notation
52
-
53
41
  case 'object':
54
42
  if (!breakpoints) {
55
43
  return;
56
- } // If it is an array the order of values is smallest to largest: [_, xs, ...]
57
-
58
-
44
+ }
45
+ // If it is an array the order of values is smallest to largest: [_, xs, ...]
59
46
  if (isMediaArray(value)) {
60
47
  return merge(styles, arrayParser(value, props, property, breakpoints.array));
61
- } // Check to see if value is an object matching the responsive syntax and generate the styles.
62
-
63
-
48
+ }
49
+ // Check to see if value is an object matching the responsive syntax and generate the styles.
64
50
  if (isMediaMap(value)) {
65
51
  return merge(styles, objectParser(value, props, property, breakpoints.map));
66
52
  }
67
-
68
53
  }
69
54
  });
70
55
  return breakpoints ? orderBreakpoints(styles, breakpoints.array) : styles;
71
- }; // return the parser function with the resulting meta information for further composition
72
-
73
-
56
+ };
57
+ // return the parser function with the resulting meta information for further composition
74
58
  return Object.assign(parser, {
75
59
  propNames: propNames,
76
60
  config: config
@@ -80,28 +64,24 @@ export var variance = {
80
64
  // that traverses the properties the function is responsible for.
81
65
  createTransform: function createTransform(prop, config) {
82
66
  var _config$transform = config.transform,
83
- transform = _config$transform === void 0 ? identity : _config$transform,
84
- property = config.property,
85
- _config$properties = config.properties,
86
- properties = _config$properties === void 0 ? [property] : _config$properties,
87
- scale = config.scale;
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;
88
72
  var getScaleValue = createScaleLookup(scale);
89
73
  var alwaysTransform = scale === undefined || isArray(scale);
90
74
  return _objectSpread(_objectSpread({}, config), {}, {
91
75
  prop: prop,
92
76
  styleFn: function styleFn(value, prop, props) {
93
77
  var _scaleValue;
94
-
95
78
  var styles = {};
96
-
97
79
  if (isUndefined(value)) {
98
80
  return styles;
99
81
  }
100
-
101
82
  var useTransform = false;
102
83
  var intermediateValue;
103
84
  var scaleValue;
104
-
105
85
  switch (_typeof(value)) {
106
86
  case 'number':
107
87
  case 'string':
@@ -109,39 +89,32 @@ export var variance = {
109
89
  useTransform = scaleValue !== undefined || alwaysTransform;
110
90
  intermediateValue = (_scaleValue = scaleValue) !== null && _scaleValue !== void 0 ? _scaleValue : value;
111
91
  break;
112
-
113
92
  case 'function':
114
93
  if (props.theme) {
115
94
  intermediateValue = value(props.theme);
116
95
  }
117
-
118
96
  break;
119
-
120
97
  default:
121
98
  return styles;
122
- } // for each property look up the scale value from theme if passed and apply any
123
- // final transforms to the value
124
-
99
+ }
125
100
 
101
+ // for each property look up the scale value from theme if passed and apply any
102
+ // final transforms to the value
126
103
  properties.forEach(function (property) {
127
104
  var styleValue = intermediateValue;
128
-
129
105
  if (useTransform && !isUndefined(styleValue)) {
130
106
  styleValue = transform(styleValue, property, props);
131
107
  }
132
-
133
108
  switch (_typeof(styleValue)) {
134
109
  case 'number':
135
110
  case 'string':
136
111
  return styles[property] = styleValue;
137
-
138
112
  case 'object':
139
113
  return Object.assign(styles, styleValue);
140
-
141
114
  default:
142
115
  }
143
- }); // return the resulting styles object
144
-
116
+ });
117
+ // return the resulting styles object
145
118
  return styles;
146
119
  }
147
120
  });
@@ -150,7 +123,6 @@ export var variance = {
150
123
  for (var _len = arguments.length, parsers = new Array(_len), _key = 0; _key < _len; _key++) {
151
124
  parsers[_key] = arguments[_key];
152
125
  }
153
-
154
126
  return this.createParser(parsers.reduce(function (carry, parser) {
155
127
  return _objectSpread(_objectSpread({}, carry), parser.config);
156
128
  }, {}));
@@ -161,13 +133,13 @@ export var variance = {
161
133
  return function (cssProps) {
162
134
  var cache;
163
135
  var allKeys = Object.keys(cssProps);
164
- /** Any key of the CSSProps that is not a System Prop or a Static CSS Property is treated as a nested selector */
165
136
 
137
+ /** Any key of the CSSProps that is not a System Prop or a Static CSS Property is treated as a nested selector */
166
138
  var selectors = allKeys.filter(function (key) {
167
139
  return !filteredProps.includes(key) && isObject(cssProps[key]);
168
140
  });
169
- /** Static CSS Properties get extracted if they match neither syntax */
170
141
 
142
+ /** Static CSS Properties get extracted if they match neither syntax */
171
143
  var staticCss = getStaticCss(cssProps, ['theme'].concat(_toConsumableArray(selectors), _toConsumableArray(filteredProps)));
172
144
  return function (_ref) {
173
145
  var theme = _ref.theme;
@@ -177,14 +149,13 @@ export var variance = {
177
149
  }));
178
150
  selectors.forEach(function (selector) {
179
151
  var _cssProps$selector;
180
-
181
152
  var selectorConfig = (_cssProps$selector = cssProps[selector]) !== null && _cssProps$selector !== void 0 ? _cssProps$selector : {};
182
153
  css[selector] = _objectSpread(_objectSpread({}, getStaticCss(selectorConfig, filteredProps)), parser(_objectSpread(_objectSpread({}, selectorConfig), {}, {
183
154
  theme: theme
184
155
  })));
185
156
  });
186
- /** Merge the static and generated css and save it to the cache */
187
157
 
158
+ /** Merge the static and generated css and save it to the cache */
188
159
  cache = _objectSpread(_objectSpread({}, staticCss), css);
189
160
  return cache;
190
161
  };
@@ -194,11 +165,11 @@ export var variance = {
194
165
  var css = this.createCss(config);
195
166
  return function (_ref2) {
196
167
  var _ref2$prop = _ref2.prop,
197
- prop = _ref2$prop === void 0 ? 'variant' : _ref2$prop,
198
- defaultVariant = _ref2.defaultVariant,
199
- _ref2$base = _ref2.base,
200
- base = _ref2$base === void 0 ? {} : _ref2$base,
201
- variants = _ref2.variants;
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;
202
173
  var baseFn = css(base);
203
174
  var variantFns = {};
204
175
  Object.keys(variants).forEach(function (key) {
@@ -208,9 +179,8 @@ export var variance = {
208
179
  });
209
180
  return function (props) {
210
181
  var _variantFns;
211
-
212
182
  var _props$prop = props[prop],
213
- selected = _props$prop === void 0 ? defaultVariant : _props$prop;
183
+ selected = _props$prop === void 0 ? defaultVariant : _props$prop;
214
184
  var styles = {};
215
185
  if (!selected) return styles;
216
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));
@@ -237,15 +207,16 @@ export var variance = {
237
207
  };
238
208
  },
239
209
  create: function create(config) {
240
- var transforms = {}; // Create a transform function for each of the props
210
+ var transforms = {};
241
211
 
212
+ // Create a transform function for each of the props
242
213
  for (var prop in config) {
243
214
  if (typeof prop === 'string') {
244
215
  transforms[prop] = this.createTransform(prop, config[prop]);
245
216
  }
246
- } // Create a parser that handles all the props within the config
247
-
217
+ }
248
218
 
219
+ // Create a parser that handles all the props within the config
249
220
  return this.createParser(transforms);
250
221
  }
251
222
  };
@@ -1,36 +1,26 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
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
3
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
4
-
5
- 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, descriptor.key, descriptor); } }
6
-
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); } }
7
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; }
8
-
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); }
9
8
  function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
10
-
11
9
  function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
12
-
13
10
  function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
14
-
15
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); }
16
-
17
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; } }
18
-
19
13
  import { mapValues, merge } from 'lodash';
20
14
  import { flattenScale } from '../utils/flattenScale';
21
15
  import { serializeTokens } from '../utils/serializeTokens';
22
-
23
16
  var _theme = new WeakMap();
24
-
25
17
  var ThemeBuilder = /*#__PURE__*/function () {
26
18
  function ThemeBuilder(baseTheme) {
27
19
  _classCallCheck(this, ThemeBuilder);
28
-
29
20
  _theme.set(this, {
30
21
  writable: true,
31
22
  value: {}
32
23
  });
33
-
34
24
  _classPrivateFieldSet(this, _theme, baseTheme);
35
25
  }
36
26
  /**
@@ -38,38 +28,31 @@ var ThemeBuilder = /*#__PURE__*/function () {
38
28
  * @param key A key of the current theme to transform into CSS Variables and Variable References
39
29
  * @example .createScaleVariables('fontSize')
40
30
  */
41
-
42
-
43
31
  _createClass(ThemeBuilder, [{
44
32
  key: "createScaleVariables",
45
33
  value: function createScaleVariables(key) {
46
34
  var _merge;
47
-
48
35
  var _serializeTokens = serializeTokens(_classPrivateFieldGet(this, _theme)[key], key, _classPrivateFieldGet(this, _theme)),
49
- variables = _serializeTokens.variables,
50
- tokens = _serializeTokens.tokens;
51
-
36
+ variables = _serializeTokens.variables,
37
+ tokens = _serializeTokens.tokens;
52
38
  _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), (_merge = {}, _defineProperty(_merge, key, tokens), _defineProperty(_merge, "_variables", {
53
39
  root: variables
54
40
  }), _defineProperty(_merge, "_tokens", _defineProperty({}, key, _classPrivateFieldGet(this, _theme)[key])), _merge)));
55
-
56
41
  return this;
57
42
  }
43
+
58
44
  /**
59
45
  *
60
46
  * @param colors A map of color tokens to add to the theme. These tokens are immediately converted to CSS Variables `--color-${key}`.
61
47
  * @example .addColors({ navy: 'navy', hyper: 'purple' })
62
48
  */
63
-
64
49
  }, {
65
50
  key: "addColors",
66
51
  value: function addColors(colors) {
67
52
  var flatColors = flattenScale(colors);
68
-
69
53
  var _serializeTokens2 = serializeTokens(flatColors, 'color', _classPrivateFieldGet(this, _theme)),
70
- variables = _serializeTokens2.variables,
71
- tokens = _serializeTokens2.tokens;
72
-
54
+ variables = _serializeTokens2.variables,
55
+ tokens = _serializeTokens2.tokens;
73
56
  _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
74
57
  colors: tokens,
75
58
  _variables: {
@@ -79,38 +62,32 @@ var ThemeBuilder = /*#__PURE__*/function () {
79
62
  colors: flatColors
80
63
  }
81
64
  }));
82
-
83
65
  return this;
84
66
  }
67
+
85
68
  /**
86
69
  *
87
70
  * @param initialMode A key of the object passed for modes. This sets the default state for the theme and transforms the correct variables.
88
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`
89
72
  * @example .addColorModes('light', { light: { primary: 'hyper' }, { dark: { primary: 'navy' } } })
90
73
  */
91
-
92
74
  }, {
93
75
  key: "addColorModes",
94
76
  value: function addColorModes(initialMode, modeConfig) {
95
77
  var _classPrivateFieldGet2,
96
- _this = this;
97
-
78
+ _this = this;
98
79
  var modes = mapValues(modeConfig, function (mode) {
99
80
  return flattenScale(mode);
100
81
  });
101
-
102
82
  var _serializeTokens3 = serializeTokens(mapValues(merge({}, (_classPrivateFieldGet2 = _classPrivateFieldGet(this, _theme).modes) === null || _classPrivateFieldGet2 === void 0 ? void 0 : _classPrivateFieldGet2[initialMode], modes[initialMode]), function (color) {
103
- return _classPrivateFieldGet(_this, _theme).colors[color];
104
- }), 'color', _classPrivateFieldGet(this, _theme)),
105
- colors = _serializeTokens3.tokens,
106
- variables = _serializeTokens3.variables;
107
-
83
+ return _classPrivateFieldGet(_this, _theme).colors[color];
84
+ }), 'color', _classPrivateFieldGet(this, _theme)),
85
+ colors = _serializeTokens3.tokens,
86
+ variables = _serializeTokens3.variables;
108
87
  var getColorValue = function getColorValue(color) {
109
88
  var _classPrivateFieldGet3, _classPrivateFieldGet4;
110
-
111
89
  return (_classPrivateFieldGet3 = _classPrivateFieldGet(_this, _theme)._tokens) === null || _classPrivateFieldGet3 === void 0 ? void 0 : (_classPrivateFieldGet4 = _classPrivateFieldGet3.colors) === null || _classPrivateFieldGet4 === void 0 ? void 0 : _classPrivateFieldGet4[color];
112
90
  };
113
-
114
91
  _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), {
115
92
  colors: colors,
116
93
  modes: modes,
@@ -125,41 +102,38 @@ var ThemeBuilder = /*#__PURE__*/function () {
125
102
  })
126
103
  }
127
104
  }));
128
-
129
105
  return this;
130
106
  }
107
+
131
108
  /**
132
109
  *
133
110
  * @param key A new key of theme
134
111
  * @param createScale A function that accepts the current theme and returns a new object of scale values.
135
112
  * @example .addScale('fonts', () => ({ basic: 'Gotham', cool: 'Wingdings' }))
136
113
  */
137
-
138
114
  }, {
139
115
  key: "addScale",
140
116
  value: function addScale(key, createScale) {
141
117
  _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, flattenScale(createScale(_classPrivateFieldGet(this, _theme))))));
142
-
143
118
  return this;
144
119
  }
120
+
145
121
  /**
146
122
  *
147
123
  * @param key A current key of theme to be updated with new or computed values
148
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.
149
125
  * @example .updateScale('fonts', ({ basic }) => ({ basicFallback: `{basic}, Montserrat` }))
150
126
  */
151
-
152
127
  }, {
153
128
  key: "updateScale",
154
129
  value: function updateScale(key, updateFn) {
155
130
  _classPrivateFieldSet(this, _theme, merge({}, _classPrivateFieldGet(this, _theme), _defineProperty({}, key, updateFn(_classPrivateFieldGet(this, _theme)[key]))));
156
-
157
131
  return this;
158
132
  }
133
+
159
134
  /**
160
135
  * This finalizes the theme build and returns the final theme and variables to be provided.
161
136
  */
162
-
163
137
  }, {
164
138
  key: "build",
165
139
  value: function build() {
@@ -169,10 +143,8 @@ var ThemeBuilder = /*#__PURE__*/function () {
169
143
  });
170
144
  }
171
145
  }]);
172
-
173
146
  return ThemeBuilder;
174
147
  }();
175
-
176
148
  export function createTheme(base) {
177
149
  return new ThemeBuilder(base);
178
150
  }
@@ -1,9 +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); }
1
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; }
2
-
3
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
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
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); }
7
7
  import { mapValues } from 'lodash';
8
8
  import { createTheme } from './createTheme';
9
9
  describe('createTheme', function () {
@@ -5,19 +5,16 @@ export var createScaleLookup = function createScaleLookup(scale) {
5
5
  return get(props, ['theme', scale, val]);
6
6
  };
7
7
  }
8
-
9
8
  if (isArray(scale)) {
10
9
  return function (val) {
11
10
  return val;
12
11
  };
13
12
  }
14
-
15
13
  if (isObject(scale)) {
16
14
  return function (val) {
17
15
  return get(scale, val);
18
16
  };
19
17
  }
20
-
21
18
  return function () {
22
19
  return undefined;
23
20
  };
@@ -1,25 +1,17 @@
1
1
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
-
3
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."); }
4
-
5
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); }
6
-
7
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; }
8
-
9
- function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
10
-
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; } }
11
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
7
  import { isNumber } from 'lodash';
14
8
  export var percentageOrAbsolute = function percentageOrAbsolute(coordinate) {
15
9
  if (coordinate === 0) {
16
10
  return coordinate;
17
11
  }
18
-
19
12
  if (coordinate <= 1 && coordinate >= -1) {
20
13
  return "".concat(coordinate * 100, "%");
21
14
  }
22
-
23
15
  return "".concat(coordinate, "px");
24
16
  };
25
17
  var valueWithUnit = /(-?\d*\.?\d+)(%|\w*)/;
@@ -27,21 +19,17 @@ export var transformSize = function transformSize(value) {
27
19
  if (isNumber(value)) {
28
20
  return percentageOrAbsolute(value);
29
21
  }
30
-
31
22
  if (value.includes('calc')) {
32
23
  return value;
33
24
  }
34
-
35
25
  var _ref = valueWithUnit.exec(value) || [],
36
- _ref2 = _slicedToArray(_ref, 3),
37
- match = _ref2[0],
38
- number = _ref2[1],
39
- unit = _ref2[2];
40
-
26
+ _ref2 = _slicedToArray(_ref, 3),
27
+ match = _ref2[0],
28
+ number = _ref2[1],
29
+ unit = _ref2[2];
41
30
  if (match === undefined) {
42
31
  return value;
43
32
  }
44
-
45
33
  var numericValue = parseFloat(number);
46
34
  return !unit ? percentageOrAbsolute(numericValue) : "".concat(numericValue).concat(unit);
47
35
  };
@@ -1,10 +1,11 @@
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); }
1
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; }
2
-
3
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
-
5
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
6
-
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); }
7
7
  import { isObject } from 'lodash';
8
+
8
9
  /**
9
10
  * Returns an exhaustive list of all possible paths of an object T for keys K.
10
11
  * Possibilities are returned as `k1.k2.k3`.
@@ -14,11 +15,9 @@ export function flattenScale(object, path) {
14
15
  return Object.keys(object).reduce(function (carry, key) {
15
16
  var nextKey = path ? "".concat(path).concat(key === '_' ? '' : "-".concat(key)) : key;
16
17
  var current = object[key];
17
-
18
18
  if (isObject(current)) {
19
19
  return _objectSpread(_objectSpread({}, carry), flattenScale(current, nextKey));
20
20
  }
21
-
22
21
  return _objectSpread(_objectSpread({}, carry), {}, _defineProperty({}, nextKey, object[key]));
23
22
  }, {});
24
23
  }
@@ -4,47 +4,40 @@ var SORT = {
4
4
  B_BEFORE_A: 1,
5
5
  EQUAL: 1
6
6
  };
7
-
8
7
  var compare = function compare(a, b) {
9
8
  if (a < b) return SORT.A_BEFORE_B;
10
9
  if (b < a) return SORT.B_BEFORE_A;
11
10
  return SORT.EQUAL;
12
11
  };
12
+
13
13
  /**
14
14
  * Orders all properties by the most dependent props
15
15
  * @param config
16
16
  */
17
-
18
-
19
17
  export var orderPropNames = function orderPropNames(config) {
20
18
  return Object.keys(config).sort(function (a, b) {
21
19
  var aConf = config[a],
22
- bConf = config[b];
20
+ bConf = config[b];
23
21
  var aProp = aConf.property,
24
- _aConf$properties = aConf.properties,
25
- aProperties = _aConf$properties === void 0 ? [] : _aConf$properties;
22
+ _aConf$properties = aConf.properties,
23
+ aProperties = _aConf$properties === void 0 ? [] : _aConf$properties;
26
24
  var bProp = bConf.property,
27
- _bConf$properties = bConf.properties,
28
- bProperties = _bConf$properties === void 0 ? [] : _bConf$properties;
25
+ _bConf$properties = bConf.properties,
26
+ bProperties = _bConf$properties === void 0 ? [] : _bConf$properties;
29
27
  var aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
30
28
  var bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
31
-
32
29
  if (aIsShorthand && bIsShorthand) {
33
30
  var aNum = aProperties.length;
34
31
  var bNum = bProperties.length;
35
-
36
32
  if (aProp !== bProp) {
37
33
  return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
38
34
  }
39
-
40
35
  if (aProp === bProp) {
41
36
  if (aNum === 0) return SORT.A_BEFORE_B;
42
37
  if (bNum === 0) return SORT.B_BEFORE_A;
43
38
  }
44
-
45
39
  return compare(bNum, aNum);
46
40
  }
47
-
48
41
  if (aIsShorthand) return SORT.A_BEFORE_B;
49
42
  if (bIsShorthand) return SORT.B_BEFORE_A;
50
43
  return SORT.EQUAL;
@@ -1,38 +1,29 @@
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); }
1
2
  function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
2
-
3
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
-
5
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); }
6
-
7
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; }
8
-
9
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
-
11
7
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
-
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); }
15
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; }
16
-
17
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; }
18
-
19
13
  import { intersection, omit } from 'lodash';
20
14
  var BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
15
+
21
16
  /**
22
17
  * Destructures the themes breakpoints into an ordered structure to traverse
23
18
  */
24
-
25
19
  export var parseBreakpoints = function parseBreakpoints(breakpoints) {
26
20
  if (breakpoints === undefined) return null;
27
-
28
21
  var _ref = breakpoints !== null && breakpoints !== void 0 ? breakpoints : {},
29
- xs = _ref.xs,
30
- sm = _ref.sm,
31
- md = _ref.md,
32
- lg = _ref.lg,
33
- xl = _ref.xl; // Ensure order for mapping
34
-
35
-
22
+ xs = _ref.xs,
23
+ sm = _ref.sm,
24
+ md = _ref.md,
25
+ lg = _ref.lg,
26
+ xl = _ref.xl; // Ensure order for mapping
36
27
  return {
37
28
  map: breakpoints,
38
29
  array: [xs, sm, md, lg, xl]
@@ -47,15 +38,13 @@ export var isMediaMap = function isMediaMap(val) {
47
38
  export var objectParser = function objectParser(value, props, config, breakpoints) {
48
39
  var styles = {};
49
40
  var styleFn = config.styleFn,
50
- prop = config.prop;
51
-
41
+ prop = config.prop;
52
42
  var _ = value._,
53
- rest = _objectWithoutProperties(value, ["_"]); // the keyof 'base' is base styles
43
+ rest = _objectWithoutProperties(value, ["_"]); // the keyof 'base' is base styles
44
+ if (_) Object.assign(styles, styleFn(_, prop, props));
54
45
 
55
-
56
- if (_) Object.assign(styles, styleFn(_, prop, props)); // Map over remaining keys and merge the corresponding breakpoint styles
46
+ // Map over remaining keys and merge the corresponding breakpoint styles
57
47
  // for that property.
58
-
59
48
  Object.keys(breakpoints).forEach(function (breakpointKey) {
60
49
  var bpStyles = rest[breakpointKey];
61
50
  if (typeof bpStyles === 'undefined') return;
@@ -66,16 +55,14 @@ export var objectParser = function objectParser(value, props, config, breakpoint
66
55
  export var arrayParser = function arrayParser(value, props, config, breakpoints) {
67
56
  var styles = {};
68
57
  var styleFn = config.styleFn,
69
- prop = config.prop;
70
-
58
+ prop = config.prop;
71
59
  var _value = _toArray(value),
72
- _ = _value[0],
73
- rest = _value.slice(1); // the first index is base styles
60
+ _ = _value[0],
61
+ rest = _value.slice(1); // the first index is base styles
62
+ if (_) Object.assign(styles, styleFn(_, prop, props));
74
63
 
75
-
76
- if (_) Object.assign(styles, styleFn(_, prop, props)); // Map over each value in the array and merge the corresponding breakpoint styles
64
+ // Map over each value in the array and merge the corresponding breakpoint styles
77
65
  // for that property.
78
-
79
66
  rest.forEach(function (val, i) {
80
67
  var breakpointKey = breakpoints[i];
81
68
  if (!breakpointKey || typeof val === 'undefined') return;
@@ -1,32 +1,26 @@
1
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
2
-
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); }
3
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; }
4
-
5
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; }
6
-
7
7
  import { isObject, merge } from 'lodash';
8
-
9
8
  var templateBreakpoints = function templateBreakpoints(value, alias, theme) {
10
9
  if (isObject(value)) {
11
10
  var _ = value._,
12
- base = value.base,
13
- rest = _objectWithoutProperties(value, ["_", "base"]);
14
-
11
+ base = value.base,
12
+ rest = _objectWithoutProperties(value, ["_", "base"]);
15
13
  var css = _defineProperty({}, alias, _ !== null && _ !== void 0 ? _ : base);
16
-
17
14
  if (theme) {
18
15
  var breakpoints = theme.breakpoints;
19
16
  Object.keys(breakpoints).forEach(function (key) {
20
17
  css[breakpoints[key]] = _defineProperty({}, alias, rest[key]);
21
18
  });
22
19
  }
23
-
24
20
  return css;
25
21
  }
26
-
27
22
  return _defineProperty({}, alias, value);
28
23
  };
29
-
30
24
  export var serializeTokens = function serializeTokens(tokens, prefix, theme) {
31
25
  var tokenReferences = {};
32
26
  var tokenVariables = {};
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.20.6-alpha.edcdf7.0",
4
+ "version": "0.21.0",
5
5
  "keywords": [
6
6
  "emotion",
7
7
  "css",
@@ -38,9 +38,9 @@
38
38
  "devDependencies": {
39
39
  "@emotion/jest": "^11.3.0",
40
40
  "@emotion/styled": "^11.3.0",
41
- "@types/react-test-renderer": "^18.0.0",
42
- "react": "18.2.0",
43
- "react-test-renderer": "18.2.0"
41
+ "@types/react-test-renderer": "^17.0.2",
42
+ "react": "^17.0.2",
43
+ "react-test-renderer": "^17.0.2"
44
44
  },
45
- "gitHead": "43a434fd656f26e2c7cb6ec586626bc402dddf21"
45
+ "gitHead": "1a7d4bea5b266c92db94b6e901f000960c5c0fa5"
46
46
  }