@codecademy/variance 0.21.0 → 0.21.1-alpha.187436.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 (42) hide show
  1. package/package.json +2 -9
  2. package/dist/core.d.ts +0 -10
  3. package/dist/core.js +0 -222
  4. package/dist/createTheme/createTheme.d.ts +0 -55
  5. package/dist/createTheme/createTheme.js +0 -150
  6. package/dist/createTheme/createTheme.test.js +0 -192
  7. package/dist/createTheme/index.d.ts +0 -3
  8. package/dist/createTheme/index.js +0 -3
  9. package/dist/createTheme/types.d.ts +0 -42
  10. package/dist/createTheme/types.js +0 -1
  11. package/dist/index.d.ts +0 -5
  12. package/dist/index.js +0 -5
  13. package/dist/scales/createScale.d.ts +0 -3
  14. package/dist/scales/createScale.js +0 -3
  15. package/dist/scales/createScaleLookup.d.ts +0 -5
  16. package/dist/scales/createScaleLookup.js +0 -21
  17. package/dist/transforms/index.d.ts +0 -1
  18. package/dist/transforms/index.js +0 -1
  19. package/dist/transforms/transformSize.d.ts +0 -2
  20. package/dist/transforms/transformSize.js +0 -35
  21. package/dist/types/config.d.ts +0 -71
  22. package/dist/types/config.js +0 -1
  23. package/dist/types/properties.d.ts +0 -22
  24. package/dist/types/properties.js +0 -1
  25. package/dist/types/props.d.ts +0 -47
  26. package/dist/types/props.js +0 -1
  27. package/dist/types/theme.d.ts +0 -17
  28. package/dist/types/theme.js +0 -1
  29. package/dist/types/utils.d.ts +0 -3
  30. package/dist/types/utils.js +0 -1
  31. package/dist/utils/__fixtures__/testConfig.d.ts +0 -153
  32. package/dist/utils/__fixtures__/testConfig.js +0 -153
  33. package/dist/utils/flattenScale.d.ts +0 -20
  34. package/dist/utils/flattenScale.js +0 -23
  35. package/dist/utils/getStaticProperties.d.ts +0 -1
  36. package/dist/utils/getStaticProperties.js +0 -6
  37. package/dist/utils/propNames.d.ts +0 -6
  38. package/dist/utils/propNames.js +0 -45
  39. package/dist/utils/responsive.d.ts +0 -16
  40. package/dist/utils/responsive.js +0 -81
  41. package/dist/utils/serializeTokens.d.ts +0 -18
  42. package/dist/utils/serializeTokens.js +0 -36
@@ -1,23 +0,0 @@
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); }
7
- import { isObject } from 'lodash';
8
-
9
- /**
10
- * Returns an exhaustive list of all possible paths of an object T for keys K.
11
- * Possibilities are returned as `k1.k2.k3`.
12
- */
13
-
14
- export function flattenScale(object, path) {
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];
18
- if (isObject(current)) {
19
- return _objectSpread(_objectSpread({}, carry), flattenScale(current, nextKey));
20
- }
21
- return _objectSpread(_objectSpread({}, carry), {}, _defineProperty({}, nextKey, object[key]));
22
- }, {});
23
- }
@@ -1 +0,0 @@
1
- export declare const getStaticCss: (props: Record<string, any>, filteredKeys: string[]) => Pick<Record<string, any>, string>;
@@ -1,6 +0,0 @@
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
- };
@@ -1,6 +0,0 @@
1
- import { BaseProperty } from '../types/config';
2
- /**
3
- * Orders all properties by the most dependent props
4
- * @param config
5
- */
6
- export declare const orderPropNames: (config: Record<string, BaseProperty>) => string[];
@@ -1,45 +0,0 @@
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
6
- };
7
- var compare = function compare(a, b) {
8
- if (a < b) return SORT.A_BEFORE_B;
9
- if (b < a) return SORT.B_BEFORE_A;
10
- return SORT.EQUAL;
11
- };
12
-
13
- /**
14
- * Orders all properties by the most dependent props
15
- * @param config
16
- */
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);
40
- }
41
- if (aIsShorthand) return SORT.A_BEFORE_B;
42
- if (bIsShorthand) return SORT.B_BEFORE_A;
43
- return SORT.EQUAL;
44
- });
45
- };
@@ -1,16 +0,0 @@
1
- import { AbstractPropTransformer } from '../types/config';
2
- import { BreakpointCache, CSSObject, MediaQueryMap, ThemeProps } from '../types/props';
3
- import { Breakpoints } from '../types/theme';
4
- /**
5
- * Destructures the themes breakpoints into an ordered structure to traverse
6
- */
7
- export declare const parseBreakpoints: (breakpoints?: Breakpoints | undefined) => BreakpointCache | null;
8
- export declare const isMediaArray: (val: unknown) => val is (string | number)[];
9
- export declare const isMediaMap: (val: object) => val is MediaQueryMap<string | number>;
10
- interface ResponsiveParser<Bp extends MediaQueryMap<string | number> | (string | number)[]> {
11
- <C extends AbstractPropTransformer>(value: Bp, props: ThemeProps, config: C, breakpoints: Bp): CSSObject;
12
- }
13
- export declare const objectParser: ResponsiveParser<MediaQueryMap<string | number>>;
14
- export declare const arrayParser: ResponsiveParser<(string | number)[]>;
15
- export declare const orderBreakpoints: (styles: CSSObject, breakpoints: string[]) => CSSObject;
16
- export {};
@@ -1,81 +0,0 @@
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; }
13
- import { intersection, omit } from 'lodash';
14
- var BREAKPOINT_KEYS = ['_', 'xs', 'sm', 'md', 'lg', 'xl'];
15
-
16
- /**
17
- * Destructures the themes breakpoints into an ordered structure to traverse
18
- */
19
- export var parseBreakpoints = function parseBreakpoints(breakpoints) {
20
- if (breakpoints === undefined) return null;
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
27
- return {
28
- map: breakpoints,
29
- array: [xs, sm, md, lg, xl]
30
- };
31
- };
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
44
- if (_) Object.assign(styles, styleFn(_, prop, props));
45
-
46
- // Map over remaining keys and merge the corresponding breakpoint styles
47
- // for that property.
48
- Object.keys(breakpoints).forEach(function (breakpointKey) {
49
- var bpStyles = rest[breakpointKey];
50
- if (typeof bpStyles === 'undefined') return;
51
- Object.assign(styles, _defineProperty({}, breakpoints[breakpointKey], styleFn(bpStyles, prop, props)));
52
- });
53
- return styles;
54
- };
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
62
- if (_) Object.assign(styles, styleFn(_, prop, props));
63
-
64
- // Map over each value in the array and merge the corresponding breakpoint styles
65
- // for that property.
66
- rest.forEach(function (val, i) {
67
- var breakpointKey = breakpoints[i];
68
- if (!breakpointKey || typeof val === 'undefined') return;
69
- Object.assign(styles, _defineProperty({}, breakpointKey, styleFn(val, prop, props)));
70
- });
71
- return styles;
72
- };
73
- export var orderBreakpoints = function orderBreakpoints(styles, breakpoints) {
74
- var orderedStyles = omit(styles, breakpoints);
75
- breakpoints.forEach(function (bp) {
76
- if (styles[bp]) {
77
- orderedStyles[bp] = styles[bp];
78
- }
79
- });
80
- return orderedStyles;
81
- };
@@ -1,18 +0,0 @@
1
- import { Theme } from '@emotion/react';
2
- import { CSSObject } from '../types/props';
3
- /**
4
- * Returns an type of any object with { key: 'var(--key) }
5
- */
6
- export declare type KeyAsVariable<T extends Record<string, any>, Prefix extends string> = {
7
- [V in keyof T]: `var(--${Prefix}-${Extract<V, string>})`;
8
- };
9
- declare type SerializedTokensInput = Record<string, string | number | CSSObject | SerializedTokensInputRecursive>;
10
- interface SerializedTokensInputRecursive {
11
- [i: number]: SerializedTokensInput;
12
- [i: string]: SerializedTokensInput;
13
- }
14
- export declare const serializeTokens: <T extends SerializedTokensInput, Prefix extends string>(tokens: T, prefix: Prefix, theme: Theme | undefined) => {
15
- tokens: KeyAsVariable<T, Prefix>;
16
- variables: CSSObject;
17
- };
18
- export {};
@@ -1,36 +0,0 @@
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; }
7
- import { isObject, merge } from 'lodash';
8
- var templateBreakpoints = function templateBreakpoints(value, alias, theme) {
9
- if (isObject(value)) {
10
- var _ = value._,
11
- base = value.base,
12
- rest = _objectWithoutProperties(value, ["_", "base"]);
13
- var css = _defineProperty({}, alias, _ !== null && _ !== void 0 ? _ : base);
14
- if (theme) {
15
- var breakpoints = theme.breakpoints;
16
- Object.keys(breakpoints).forEach(function (key) {
17
- css[breakpoints[key]] = _defineProperty({}, alias, rest[key]);
18
- });
19
- }
20
- return css;
21
- }
22
- return _defineProperty({}, alias, value);
23
- };
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, ")");
30
- merge(tokenVariables, templateBreakpoints(tokens[key], varName, theme));
31
- });
32
- return {
33
- tokens: tokenReferences,
34
- variables: tokenVariables
35
- };
36
- };