@codecademy/variance 0.20.0 → 0.20.1-alpha.32ef98.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.
Files changed (35) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/dist/core.js +183 -245
  3. package/dist/createTheme/createTheme.js +58 -132
  4. package/dist/createTheme/createTheme.test.js +159 -184
  5. package/dist/createTheme/index.js +2 -1
  6. package/dist/createTheme/types.js +2 -0
  7. package/dist/index.js +2 -1
  8. package/dist/scales/createScale.js +2 -3
  9. package/dist/scales/createScaleLookup.js +13 -23
  10. package/dist/src/core.d.ts +10 -0
  11. package/dist/src/core.js +189 -0
  12. package/dist/src/core.js.map +1 -0
  13. package/dist/src/createTheme/createTheme.test.d.ts +1 -0
  14. package/dist/src/createTheme/createTheme.test.js +167 -0
  15. package/dist/src/createTheme/createTheme.test.js.map +1 -0
  16. package/dist/src/index.d.ts +5 -0
  17. package/dist/src/index.js +6 -0
  18. package/dist/src/index.js.map +1 -0
  19. package/dist/src/utils/__fixtures__/testConfig.d.ts +153 -0
  20. package/dist/src/utils/__fixtures__/testConfig.js +94 -0
  21. package/dist/src/utils/__fixtures__/testConfig.js.map +1 -0
  22. package/dist/transforms/index.js +2 -1
  23. package/dist/transforms/transformSize.js +24 -45
  24. package/dist/types/config.js +2 -0
  25. package/dist/types/properties.js +2 -0
  26. package/dist/types/props.js +2 -0
  27. package/dist/types/theme.js +2 -0
  28. package/dist/types/utils.js +2 -0
  29. package/dist/utils/__fixtures__/testConfig.js +94 -153
  30. package/dist/utils/flattenScale.js +16 -22
  31. package/dist/utils/getStaticProperties.js +2 -5
  32. package/dist/utils/propNames.js +57 -43
  33. package/dist/utils/responsive.js +57 -86
  34. package/dist/utils/serializeTokens.js +30 -39
  35. package/package.json +3 -3
@@ -1,47 +1,26 @@
1
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
-
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
- 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
- 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 && (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
-
11
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
12
-
13
1
  import { isNumber } from 'lodash';
14
- export var percentageOrAbsolute = function percentageOrAbsolute(coordinate) {
15
- if (coordinate === 0) {
16
- return coordinate;
17
- }
18
-
19
- if (coordinate <= 1 && coordinate >= -1) {
20
- return "".concat(coordinate * 100, "%");
21
- }
22
-
23
- return "".concat(coordinate, "px");
2
+ export const percentageOrAbsolute = (coordinate) => {
3
+ if (coordinate === 0) {
4
+ return coordinate;
5
+ }
6
+ if (coordinate <= 1 && coordinate >= -1) {
7
+ return `${coordinate * 100}%`;
8
+ }
9
+ return `${coordinate}px`;
24
10
  };
25
- var valueWithUnit = /(-?\d*\.?\d+)(%|\w*)/;
26
- export var transformSize = function transformSize(value) {
27
- if (isNumber(value)) {
28
- return percentageOrAbsolute(value);
29
- }
30
-
31
- if (value.includes('calc')) {
32
- return value;
33
- }
34
-
35
- var _ref = valueWithUnit.exec(value) || [],
36
- _ref2 = _slicedToArray(_ref, 3),
37
- match = _ref2[0],
38
- number = _ref2[1],
39
- unit = _ref2[2];
40
-
41
- if (match === undefined) {
42
- return value;
43
- }
44
-
45
- var numericValue = parseFloat(number);
46
- return !unit ? percentageOrAbsolute(numericValue) : "".concat(numericValue).concat(unit);
47
- };
11
+ const valueWithUnit = /(-?\d*\.?\d+)(%|\w*)/;
12
+ export const transformSize = (value) => {
13
+ if (isNumber(value)) {
14
+ return percentageOrAbsolute(value);
15
+ }
16
+ if (value.includes('calc')) {
17
+ return value;
18
+ }
19
+ const [match, number, unit] = valueWithUnit.exec(value) || [];
20
+ if (match === undefined) {
21
+ return value;
22
+ }
23
+ const numericValue = parseFloat(number);
24
+ return !unit ? percentageOrAbsolute(numericValue) : `${numericValue}${unit}`;
25
+ };
26
+ //# sourceMappingURL=transformSize.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=properties.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=props.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=theme.js.map
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=utils.js.map
@@ -1,153 +1,94 @@
1
- export var testConfig = {
2
- textColor: {
3
- property: 'color'
4
- },
5
- bg: {
6
- property: 'backgroundColor'
7
- },
8
- borderColor: {
9
- property: 'borderColor'
10
- },
11
- borderColorX: {
12
- property: 'borderColor',
13
- properties: ['borderLeftColor', 'borderRightColor'],
14
- scale: 'colors'
15
- },
16
- borderColorY: {
17
- property: 'borderColor',
18
- properties: ['borderTopColor', 'borderBottomColor'],
19
- scale: 'colors'
20
- },
21
- borderColorLeft: {
22
- property: 'borderLeftColor'
23
- },
24
- borderColorRight: {
25
- property: 'borderRightColor'
26
- },
27
- borderColorTop: {
28
- property: 'borderTopColor'
29
- },
30
- borderColorBottom: {
31
- property: 'borderBottomColor'
32
- },
33
- border: {
34
- property: 'border'
35
- },
36
- borderX: {
37
- property: 'border',
38
- properties: ['borderLeft', 'borderRight']
39
- },
40
- borderY: {
41
- property: 'border',
42
- properties: ['borderTop', 'borderBottom']
43
- },
44
- borderTop: {
45
- property: 'borderTop'
46
- },
47
- borderRight: {
48
- property: 'borderRight'
49
- },
50
- borderBottom: {
51
- property: 'borderBottom'
52
- },
53
- borderLeft: {
54
- property: 'borderLeft'
55
- },
56
- borderWidth: {
57
- property: 'borderWidth'
58
- },
59
- borderWidthX: {
60
- property: 'borderWidth',
61
- properties: ['borderLeftWidth', 'borderRightWidth']
62
- },
63
- borderWidthY: {
64
- property: 'borderWidth',
65
- properties: ['borderTopWidth', 'borderBottomWidth']
66
- },
67
- borderRadius: {
68
- property: 'borderRadius'
69
- },
70
- borderRadiusLeft: {
71
- property: 'borderRadius',
72
- properties: ['borderTopLeftRadius', 'borderBottomLeftRadius']
73
- },
74
- borderRadiusTop: {
75
- property: 'borderRadius',
76
- properties: ['borderTopLeftRadius', 'borderTopRightRadius']
77
- },
78
- borderRadiusBottom: {
79
- property: 'borderRadius',
80
- properties: ['borderBottomLeftRadius', 'borderBottomRightRadius']
81
- },
82
- borderRadiusRight: {
83
- property: 'borderRadius',
84
- properties: ['borderTopRightRadius', 'borderBottomRightRadius']
85
- },
86
- borderStyle: {
87
- property: 'borderStyle'
88
- },
89
- borderStyleX: {
90
- property: 'borderStyle',
91
- properties: ['borderLeftStyle', 'borderRightStyle']
92
- },
93
- borderStyleY: {
94
- property: 'borderStyle',
95
- properties: ['borderTopStyle', 'borderBottomStyle']
96
- },
97
- flex: {
98
- property: 'flex'
99
- },
100
- flexBasis: {
101
- property: 'flexBasis'
102
- },
103
- p: {
104
- property: 'padding'
105
- },
106
- px: {
107
- property: 'padding',
108
- properties: ['paddingLeft', 'paddingRight'],
109
- scale: 'spacing'
110
- },
111
- py: {
112
- property: 'padding',
113
- properties: ['paddingTop', 'paddingBottom'],
114
- scale: 'spacing'
115
- },
116
- pt: {
117
- property: 'paddingTop'
118
- },
119
- pb: {
120
- property: 'paddingBottom'
121
- },
122
- pr: {
123
- property: 'paddingRight'
124
- },
125
- pl: {
126
- property: 'paddingLeft'
127
- },
128
- m: {
129
- property: 'margin'
130
- },
131
- mx: {
132
- property: 'margin',
133
- properties: ['marginLeft', 'marginRight'],
134
- scale: 'spacing'
135
- },
136
- my: {
137
- property: 'margin',
138
- properties: ['marginTop', 'marginBottom'],
139
- scale: 'spacing'
140
- },
141
- mt: {
142
- property: 'marginTop'
143
- },
144
- mb: {
145
- property: 'marginBottom'
146
- },
147
- mr: {
148
- property: 'marginRight'
149
- },
150
- ml: {
151
- property: 'marginLeft'
152
- }
153
- };
1
+ export const testConfig = {
2
+ textColor: { property: 'color' },
3
+ bg: { property: 'backgroundColor' },
4
+ borderColor: { property: 'borderColor' },
5
+ borderColorX: {
6
+ property: 'borderColor',
7
+ properties: ['borderLeftColor', 'borderRightColor'],
8
+ scale: 'colors',
9
+ },
10
+ borderColorY: {
11
+ property: 'borderColor',
12
+ properties: ['borderTopColor', 'borderBottomColor'],
13
+ scale: 'colors',
14
+ },
15
+ borderColorLeft: { property: 'borderLeftColor' },
16
+ borderColorRight: { property: 'borderRightColor' },
17
+ borderColorTop: { property: 'borderTopColor' },
18
+ borderColorBottom: { property: 'borderBottomColor' },
19
+ border: { property: 'border' },
20
+ borderX: { property: 'border', properties: ['borderLeft', 'borderRight'] },
21
+ borderY: { property: 'border', properties: ['borderTop', 'borderBottom'] },
22
+ borderTop: { property: 'borderTop' },
23
+ borderRight: { property: 'borderRight' },
24
+ borderBottom: { property: 'borderBottom' },
25
+ borderLeft: { property: 'borderLeft' },
26
+ borderWidth: { property: 'borderWidth' },
27
+ borderWidthX: {
28
+ property: 'borderWidth',
29
+ properties: ['borderLeftWidth', 'borderRightWidth'],
30
+ },
31
+ borderWidthY: {
32
+ property: 'borderWidth',
33
+ properties: ['borderTopWidth', 'borderBottomWidth'],
34
+ },
35
+ borderRadius: { property: 'borderRadius' },
36
+ borderRadiusLeft: {
37
+ property: 'borderRadius',
38
+ properties: ['borderTopLeftRadius', 'borderBottomLeftRadius'],
39
+ },
40
+ borderRadiusTop: {
41
+ property: 'borderRadius',
42
+ properties: ['borderTopLeftRadius', 'borderTopRightRadius'],
43
+ },
44
+ borderRadiusBottom: {
45
+ property: 'borderRadius',
46
+ properties: ['borderBottomLeftRadius', 'borderBottomRightRadius'],
47
+ },
48
+ borderRadiusRight: {
49
+ property: 'borderRadius',
50
+ properties: ['borderTopRightRadius', 'borderBottomRightRadius'],
51
+ },
52
+ borderStyle: { property: 'borderStyle' },
53
+ borderStyleX: {
54
+ property: 'borderStyle',
55
+ properties: ['borderLeftStyle', 'borderRightStyle'],
56
+ },
57
+ borderStyleY: {
58
+ property: 'borderStyle',
59
+ properties: ['borderTopStyle', 'borderBottomStyle'],
60
+ },
61
+ flex: { property: 'flex' },
62
+ flexBasis: { property: 'flexBasis' },
63
+ p: { property: 'padding' },
64
+ px: {
65
+ property: 'padding',
66
+ properties: ['paddingLeft', 'paddingRight'],
67
+ scale: 'spacing',
68
+ },
69
+ py: {
70
+ property: 'padding',
71
+ properties: ['paddingTop', 'paddingBottom'],
72
+ scale: 'spacing',
73
+ },
74
+ pt: { property: 'paddingTop' },
75
+ pb: { property: 'paddingBottom' },
76
+ pr: { property: 'paddingRight' },
77
+ pl: { property: 'paddingLeft' },
78
+ m: { property: 'margin' },
79
+ mx: {
80
+ property: 'margin',
81
+ properties: ['marginLeft', 'marginRight'],
82
+ scale: 'spacing',
83
+ },
84
+ my: {
85
+ property: 'margin',
86
+ properties: ['marginTop', 'marginBottom'],
87
+ scale: 'spacing',
88
+ },
89
+ mt: { property: 'marginTop' },
90
+ mb: { property: 'marginBottom' },
91
+ mr: { property: 'marginRight' },
92
+ ml: { property: 'marginLeft' },
93
+ };
94
+ //# sourceMappingURL=testConfig.js.map
@@ -1,24 +1,18 @@
1
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
2
-
3
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { 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
-
7
1
  import { isObject } from 'lodash';
8
- /**
9
- * Returns an exhaustive list of all possible paths of an object T for keys K.
10
- * Possibilities are returned as `k1.k2.k3`.
11
- */
12
-
13
2
  export function flattenScale(object, path) {
14
- return Object.keys(object).reduce(function (carry, key) {
15
- var nextKey = path ? "".concat(path).concat(key === '_' ? '' : "-".concat(key)) : key;
16
- var current = object[key];
17
-
18
- if (isObject(current)) {
19
- return _objectSpread(_objectSpread({}, carry), flattenScale(current, nextKey));
20
- }
21
-
22
- return _objectSpread(_objectSpread({}, carry), {}, _defineProperty({}, nextKey, object[key]));
23
- }, {});
24
- }
3
+ return Object.keys(object).reduce((carry, key) => {
4
+ const nextKey = path ? `${path}${key === '_' ? '' : `-${key}`}` : key;
5
+ const current = object[key];
6
+ if (isObject(current)) {
7
+ return {
8
+ ...carry,
9
+ ...flattenScale(current, nextKey),
10
+ };
11
+ }
12
+ return {
13
+ ...carry,
14
+ [nextKey]: object[key],
15
+ };
16
+ }, {});
17
+ }
18
+ //# sourceMappingURL=flattenScale.js.map
@@ -1,6 +1,3 @@
1
1
  import { keys, pick } from 'lodash';
2
- export var getStaticCss = function getStaticCss(props, filteredKeys) {
3
- return pick(props, keys(props).filter(function (key) {
4
- return !filteredKeys.includes(key);
5
- }));
6
- };
2
+ export const getStaticCss = (props, filteredKeys) => pick(props, keys(props).filter((key) => !filteredKeys.includes(key)));
3
+ //# sourceMappingURL=getStaticProperties.js.map
@@ -1,52 +1,66 @@
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
- A_BEFORE_B: -1,
4
- B_BEFORE_A: 1,
5
- EQUAL: 1
1
+ const SHORTHAND_PROPERTIES = [
2
+ 'border',
3
+ 'borderTop',
4
+ 'borderBottom',
5
+ 'borderLeft',
6
+ 'borderRight',
7
+ 'borderWidth',
8
+ 'borderStyle',
9
+ 'borderColor',
10
+ 'background',
11
+ 'flex',
12
+ 'margin',
13
+ 'padding',
14
+ 'transition',
15
+ 'gap',
16
+ 'grid',
17
+ 'gridArea',
18
+ 'gridColumn',
19
+ 'gridRow',
20
+ 'gridTemplate',
21
+ 'overflow',
22
+ 'transition',
23
+ ];
24
+ const SORT = {
25
+ A_BEFORE_B: -1,
26
+ B_BEFORE_A: 1,
27
+ EQUAL: 1,
6
28
  };
7
-
8
- var compare = function compare(a, b) {
9
- if (a < b) return SORT.A_BEFORE_B;
10
- if (b < a) return SORT.B_BEFORE_A;
11
- return SORT.EQUAL;
29
+ const compare = (a, b) => {
30
+ if (a < b)
31
+ return SORT.A_BEFORE_B;
32
+ if (b < a)
33
+ return SORT.B_BEFORE_A;
34
+ return SORT.EQUAL;
12
35
  };
13
36
  /**
14
37
  * Orders all properties by the most dependent props
15
38
  * @param config
16
39
  */
17
-
18
-
19
- export var orderPropNames = function orderPropNames(config) {
20
- return Object.keys(config).sort(function (a, b) {
21
- var aConf = config[a],
22
- bConf = config[b];
23
- var aProp = aConf.property,
24
- _aConf$properties = aConf.properties,
25
- aProperties = _aConf$properties === void 0 ? [] : _aConf$properties;
26
- var bProp = bConf.property,
27
- _bConf$properties = bConf.properties,
28
- bProperties = _bConf$properties === void 0 ? [] : _bConf$properties;
29
- var aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
30
- var bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
31
-
40
+ export const orderPropNames = (config) => Object.keys(config).sort((a, b) => {
41
+ const { [a]: aConf, [b]: bConf } = config;
42
+ const { property: aProp, properties: aProperties = [] } = aConf;
43
+ const { property: bProp, properties: bProperties = [] } = bConf;
44
+ const aIsShorthand = SHORTHAND_PROPERTIES.includes(aProp);
45
+ const bIsShorthand = SHORTHAND_PROPERTIES.includes(bProp);
32
46
  if (aIsShorthand && bIsShorthand) {
33
- var aNum = aProperties.length;
34
- var bNum = bProperties.length;
35
-
36
- if (aProp !== bProp) {
37
- return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
38
- }
39
-
40
- if (aProp === bProp) {
41
- if (aNum === 0) return SORT.A_BEFORE_B;
42
- if (bNum === 0) return SORT.B_BEFORE_A;
43
- }
44
-
45
- return compare(bNum, aNum);
47
+ const aNum = aProperties.length;
48
+ const bNum = bProperties.length;
49
+ if (aProp !== bProp) {
50
+ return compare(SHORTHAND_PROPERTIES.indexOf(aProp), SHORTHAND_PROPERTIES.indexOf(bProp));
51
+ }
52
+ if (aProp === bProp) {
53
+ if (aNum === 0)
54
+ return SORT.A_BEFORE_B;
55
+ if (bNum === 0)
56
+ return SORT.B_BEFORE_A;
57
+ }
58
+ return compare(bNum, aNum);
46
59
  }
47
-
48
- if (aIsShorthand) return SORT.A_BEFORE_B;
49
- if (bIsShorthand) return SORT.B_BEFORE_A;
60
+ if (aIsShorthand)
61
+ return SORT.A_BEFORE_B;
62
+ if (bIsShorthand)
63
+ return SORT.B_BEFORE_A;
50
64
  return SORT.EQUAL;
51
- });
52
- };
65
+ });
66
+ //# sourceMappingURL=propNames.js.map
@@ -1,94 +1,65 @@
1
- function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); }
2
-
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
- 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
- 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
10
-
11
- 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
-
15
- 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
- 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
1
  import { intersection, omit } from 'lodash';
20
- var BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
2
+ const BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
21
3
  /**
22
4
  * Destructures the themes breakpoints into an ordered structure to traverse
23
5
  */
24
-
25
- export var parseBreakpoints = function parseBreakpoints(breakpoints) {
26
- if (breakpoints === undefined) return null;
27
-
28
- 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
-
36
- return {
37
- map: breakpoints,
38
- array: [xs, sm, md, lg, xl]
39
- };
6
+ export const parseBreakpoints = (breakpoints) => {
7
+ if (breakpoints === undefined)
8
+ return null;
9
+ const { xs, sm, md, lg, xl } = breakpoints ?? {};
10
+ // Ensure order for mapping
11
+ return {
12
+ map: breakpoints,
13
+ array: [xs, sm, md, lg, xl],
14
+ };
40
15
  };
41
- export var isMediaArray = function isMediaArray(val) {
42
- return Array.isArray(val);
16
+ export const isMediaArray = (val) => Array.isArray(val);
17
+ export const isMediaMap = (val) => intersection(Object.keys(val), BREAKPOINT_KEYS).length > 0;
18
+ export const objectParser = (value, props, config, breakpoints) => {
19
+ const styles = {};
20
+ const { styleFn, prop } = config;
21
+ const { _, ...rest } = value;
22
+ // the keyof 'base' is base styles
23
+ if (_)
24
+ Object.assign(styles, styleFn(_, prop, props));
25
+ // Map over remaining keys and merge the corresponding breakpoint styles
26
+ // for that property.
27
+ Object.keys(breakpoints).forEach((breakpointKey) => {
28
+ const bpStyles = rest[breakpointKey];
29
+ if (typeof bpStyles === 'undefined')
30
+ return;
31
+ Object.assign(styles, {
32
+ [breakpoints[breakpointKey]]: styleFn(bpStyles, prop, props),
33
+ });
34
+ });
35
+ return styles;
43
36
  };
44
- export var isMediaMap = function isMediaMap(val) {
45
- return intersection(Object.keys(val), BREAKPOINT_KEYS).length > 0;
37
+ export const arrayParser = (value, props, config, breakpoints) => {
38
+ const styles = {};
39
+ const { styleFn, prop } = config;
40
+ const [_, ...rest] = value;
41
+ // the first index is base styles
42
+ if (_)
43
+ Object.assign(styles, styleFn(_, prop, props));
44
+ // Map over each value in the array and merge the corresponding breakpoint styles
45
+ // for that property.
46
+ rest.forEach((val, i) => {
47
+ const breakpointKey = breakpoints[i];
48
+ if (!breakpointKey || typeof val === 'undefined')
49
+ return;
50
+ Object.assign(styles, {
51
+ [breakpointKey]: styleFn(val, prop, props),
52
+ });
53
+ });
54
+ return styles;
46
55
  };
47
- export var objectParser = function objectParser(value, props, config, breakpoints) {
48
- var styles = {};
49
- var styleFn = config.styleFn,
50
- prop = config.prop;
51
-
52
- var _ = value._,
53
- rest = _objectWithoutProperties(value, ["_"]); // the keyof 'base' is base styles
54
-
55
-
56
- if (_) Object.assign(styles, styleFn(_, prop, props)); // Map over remaining keys and merge the corresponding breakpoint styles
57
- // for that property.
58
-
59
- Object.keys(breakpoints).forEach(function (breakpointKey) {
60
- var bpStyles = rest[breakpointKey];
61
- if (typeof bpStyles === 'undefined') return;
62
- Object.assign(styles, _defineProperty({}, breakpoints[breakpointKey], styleFn(bpStyles, prop, props)));
63
- });
64
- return styles;
56
+ export const orderBreakpoints = (styles, breakpoints) => {
57
+ const orderedStyles = omit(styles, breakpoints);
58
+ breakpoints.forEach((bp) => {
59
+ if (styles[bp]) {
60
+ orderedStyles[bp] = styles[bp];
61
+ }
62
+ });
63
+ return orderedStyles;
65
64
  };
66
- export var arrayParser = function arrayParser(value, props, config, breakpoints) {
67
- var styles = {};
68
- var styleFn = config.styleFn,
69
- prop = config.prop;
70
-
71
- var _value = _toArray(value),
72
- _ = _value[0],
73
- rest = _value.slice(1); // the first index is base styles
74
-
75
-
76
- if (_) Object.assign(styles, styleFn(_, prop, props)); // Map over each value in the array and merge the corresponding breakpoint styles
77
- // for that property.
78
-
79
- rest.forEach(function (val, i) {
80
- var breakpointKey = breakpoints[i];
81
- if (!breakpointKey || typeof val === 'undefined') return;
82
- Object.assign(styles, _defineProperty({}, breakpointKey, styleFn(val, prop, props)));
83
- });
84
- return styles;
85
- };
86
- export var orderBreakpoints = function orderBreakpoints(styles, breakpoints) {
87
- var orderedStyles = omit(styles, breakpoints);
88
- breakpoints.forEach(function (bp) {
89
- if (styles[bp]) {
90
- orderedStyles[bp] = styles[bp];
91
- }
92
- });
93
- return orderedStyles;
94
- };
65
+ //# sourceMappingURL=responsive.js.map