@codecademy/variance 1.0.0-alpha.f43515.0 → 1.0.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 (65) hide show
  1. package/dist/core.d.ts +5 -5
  2. package/dist/core.js +152 -163
  3. package/dist/createTheme/createTheme.d.ts +7 -0
  4. package/dist/createTheme/createTheme.js +118 -150
  5. package/dist/createTheme/createTheme.test.js +50 -62
  6. package/dist/createTheme/types.d.ts +7 -7
  7. package/dist/createTheme/types.js +1 -0
  8. package/dist/getPropertyMode/getPropertyMode.d.ts +2 -0
  9. package/dist/getPropertyMode/getPropertyMode.js +3 -0
  10. package/dist/getPropertyMode/getPropertyMode.test.js +15 -0
  11. package/dist/getPropertyMode/index.d.ts +1 -0
  12. package/dist/getPropertyMode/index.js +1 -0
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.js +2 -1
  15. package/dist/scales/createScale.js +1 -3
  16. package/dist/scales/createScaleLookup.d.ts +2 -2
  17. package/dist/scales/createScaleLookup.js +9 -17
  18. package/dist/transforms/transformSize.js +9 -31
  19. package/dist/types/config.d.ts +18 -14
  20. package/dist/types/config.js +1 -0
  21. package/dist/types/properties.d.ts +14 -5
  22. package/dist/types/properties.js +1 -0
  23. package/dist/types/props.d.ts +27 -8
  24. package/dist/types/props.js +1 -0
  25. package/dist/types/theme.d.ts +6 -0
  26. package/dist/types/theme.js +1 -0
  27. package/dist/types/utils.d.ts +3 -3
  28. package/dist/types/utils.js +1 -0
  29. package/dist/utils/flattenScale.d.ts +5 -5
  30. package/dist/utils/flattenScale.js +24 -13
  31. package/dist/utils/getStaticProperties.js +3 -6
  32. package/dist/utils/propNames.js +42 -39
  33. package/dist/utils/responsive.d.ts +5 -5
  34. package/dist/utils/responsive.js +60 -69
  35. package/dist/utils/serializeTokens.d.ts +2 -2
  36. package/dist/utils/serializeTokens.js +34 -26
  37. package/package.json +19 -31
  38. package/CHANGELOG.md +0 -325
  39. package/LICENSE +0 -21
  40. package/babel.config.js +0 -5
  41. package/dist/core.js.map +0 -1
  42. package/dist/createTheme/createTheme.js.map +0 -1
  43. package/dist/createTheme/createTheme.test.d.ts +0 -1
  44. package/dist/createTheme/createTheme.test.js.map +0 -1
  45. package/dist/createTheme/index.js.map +0 -1
  46. package/dist/createTheme/types.js.map +0 -1
  47. package/dist/index.js.map +0 -1
  48. package/dist/scales/createScale.js.map +0 -1
  49. package/dist/scales/createScaleLookup.js.map +0 -1
  50. package/dist/transforms/index.js.map +0 -1
  51. package/dist/transforms/transformSize.js.map +0 -1
  52. package/dist/types/config.js.map +0 -1
  53. package/dist/types/properties.js.map +0 -1
  54. package/dist/types/props.js.map +0 -1
  55. package/dist/types/theme.js.map +0 -1
  56. package/dist/types/utils.js.map +0 -1
  57. package/dist/utils/__fixtures__/testConfig.js +0 -153
  58. package/dist/utils/__fixtures__/testConfig.js.map +0 -1
  59. package/dist/utils/flattenScale.js.map +0 -1
  60. package/dist/utils/getStaticProperties.js.map +0 -1
  61. package/dist/utils/propNames.js.map +0 -1
  62. package/dist/utils/responsive.js.map +0 -1
  63. package/dist/utils/serializeTokens.js.map +0 -1
  64. package/jest.config.js +0 -1
  65. package/tsconfig.base.json +0 -3
@@ -1,47 +1,25 @@
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
- import { isNumber } from 'lodash';
14
- export var percentageOrAbsolute = function percentageOrAbsolute(coordinate) {
1
+ import isNumber from 'lodash/isNumber';
2
+ export const percentageOrAbsolute = coordinate => {
15
3
  if (coordinate === 0) {
16
4
  return coordinate;
17
5
  }
18
-
19
6
  if (coordinate <= 1 && coordinate >= -1) {
20
- return "".concat(coordinate * 100, "%");
7
+ return `${coordinate * 100}%`;
21
8
  }
22
-
23
- return "".concat(coordinate, "px");
9
+ return `${coordinate}px`;
24
10
  };
25
- var valueWithUnit = /(-?\d*\.?\d+)(%|\w*)/;
26
- export var transformSize = function transformSize(value) {
11
+ const valueWithUnit = /(-?\d*\.?\d+)(%|\w*)/;
12
+ export const transformSize = value => {
27
13
  if (isNumber(value)) {
28
14
  return percentageOrAbsolute(value);
29
15
  }
30
-
31
16
  if (value.includes('calc')) {
32
17
  return value;
33
18
  }
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
-
19
+ const [match, number, unit] = valueWithUnit.exec(value) || [];
41
20
  if (match === undefined) {
42
21
  return value;
43
22
  }
44
-
45
- var numericValue = parseFloat(number);
46
- return !unit ? percentageOrAbsolute(numericValue) : "".concat(numericValue).concat(unit);
23
+ const numericValue = parseFloat(number);
24
+ return !unit ? percentageOrAbsolute(numericValue) : `${numericValue}${unit}`;
47
25
  };
@@ -1,18 +1,20 @@
1
1
  import { Theme } from '@emotion/react';
2
- import { DefaultCSSPropertyValue, PropertyTypes } from './properties';
2
+ import { DefaultCSSPropertyValue, DirectionalProperties, DirectionalProperty, PropertyMode, PropertyTypes } from './properties';
3
3
  import { AbstractProps, CSSObject, CSSPropMap, CSSProps, ResponsiveProp, ThemeProps } from './props';
4
4
  import { AllUnionKeys, Key, KeyFromUnion } from './utils';
5
- export declare type MapScale = Record<string | number, string | number>;
6
- export declare type ArrayScale = readonly (string | number)[] & {
5
+ export type MapScale = Record<string | number, string | number>;
6
+ export type ArrayScale = readonly (string | number)[] & {
7
7
  length: 0;
8
8
  };
9
+ export type PropertyValue = keyof PropertyTypes | DirectionalProperty;
9
10
  export interface BaseProperty {
10
- property: keyof PropertyTypes;
11
- properties?: readonly (keyof PropertyTypes)[];
11
+ property: PropertyValue;
12
+ properties?: readonly PropertyValue[] | DirectionalProperties;
12
13
  }
13
14
  export interface Prop extends BaseProperty {
14
15
  scale?: keyof Theme | MapScale | ArrayScale;
15
16
  transform?: (val: string | number, prop?: string, props?: AbstractProps) => string | number | CSSObject;
17
+ resolveProperty?: (useLogicalProperties: boolean) => PropertyMode;
16
18
  }
17
19
  export interface AbstractPropTransformer extends Prop {
18
20
  prop: string;
@@ -23,11 +25,12 @@ export interface AbstractParser {
23
25
  propNames: string[];
24
26
  config: Record<string, AbstractPropTransformer>;
25
27
  }
26
- export declare type PropertyValues<Property extends keyof PropertyTypes, All extends boolean = false> = Exclude<PropertyTypes<All extends true ? DefaultCSSPropertyValue : never>[Property], All extends true ? never : object | any[]>;
27
- export declare type ScaleValue<Config extends Prop> = Config['scale'] extends keyof Theme ? keyof Theme[Config['scale']] | PropertyValues<Config['property']> : Config['scale'] extends MapScale ? keyof Config['scale'] | PropertyValues<Config['property']> : Config['scale'] extends ArrayScale ? Config['scale'][number] | PropertyValues<Config['property']> : PropertyValues<Config['property'], true>;
28
- export declare type Scale<Config extends Prop> = ResponsiveProp<ScaleValue<Config> | ((theme: Theme) => ScaleValue<Config>)>;
28
+ export type PropertyValues<Property extends keyof PropertyTypes, All extends boolean = false> = Exclude<PropertyTypes<All extends true ? DefaultCSSPropertyValue : never>[Property], All extends true ? never : object | any[]>;
29
+ type BasePropertyKey<P> = P extends DirectionalProperty ? P['physical'] : P;
30
+ export type ScaleValue<Config extends Prop> = Config['scale'] extends keyof Theme ? keyof Theme[Config['scale']] | PropertyValues<BasePropertyKey<Config['property']>> : Config['scale'] extends MapScale ? keyof Config['scale'] | PropertyValues<BasePropertyKey<Config['property']>> : Config['scale'] extends ArrayScale ? Config['scale'][number] | PropertyValues<BasePropertyKey<Config['property']>> : PropertyValues<BasePropertyKey<Config['property']>, true>;
31
+ export type Scale<Config extends Prop> = ResponsiveProp<ScaleValue<Config> | ((theme: Theme) => ScaleValue<Config>)>;
29
32
  export interface TransformFn<P extends string, Config extends Prop> {
30
- (value: Scale<Config> | Scale<Config>, prop: P, props: ThemeProps<{
33
+ (value: Scale<Config>, prop: P, props: ThemeProps<{
31
34
  [K in P]?: Scale<Config>;
32
35
  }>): CSSObject;
33
36
  }
@@ -35,7 +38,7 @@ export interface PropTransformer<P extends string, C extends Prop> extends Abstr
35
38
  prop: P;
36
39
  styleFn: TransformFn<P, C>;
37
40
  }
38
- export declare type TransformerMap<Config extends Record<string, Prop>> = {
41
+ export type TransformerMap<Config extends Record<string, Prop>> = {
39
42
  [P in Key<keyof Config>]: PropTransformer<Key<P>, Config[P]>;
40
43
  };
41
44
  export interface Parser<Config extends Record<string, AbstractPropTransformer>> {
@@ -43,7 +46,7 @@ export interface Parser<Config extends Record<string, AbstractPropTransformer>>
43
46
  propNames: (keyof Config)[];
44
47
  config: Config;
45
48
  }
46
- export declare type Compose<Args extends AbstractParser[]> = {
49
+ export type Compose<Args extends AbstractParser[]> = {
47
50
  [K in AllUnionKeys<Args[number]['config']>]: KeyFromUnion<Args[number]['config'], K>;
48
51
  };
49
52
  export interface Variant<P extends AbstractParser> {
@@ -60,12 +63,13 @@ export interface States<P extends AbstractParser> {
60
63
  export interface CSS<P extends AbstractParser> {
61
64
  <Props extends AbstractProps>(config: CSSProps<Props, SystemProps<P>>): (props: ThemeProps) => CSSObject;
62
65
  }
63
- export declare type ParserProps<Config extends Record<string, AbstractPropTransformer>> = ThemeProps<{
66
+ export type ParserProps<Config extends Record<string, AbstractPropTransformer>> = ThemeProps<{
64
67
  [P in keyof Config]?: Parameters<Config[P]['styleFn']>[2][Config[P]['prop']];
65
68
  }>;
66
- export declare type SystemProps<P extends AbstractParser> = {
69
+ export type SystemProps<P extends AbstractParser> = {
67
70
  [K in keyof Omit<Parameters<P>[0], 'theme'>]: Omit<Parameters<P>[0], 'theme'>[K];
68
71
  };
69
- export declare type VariantProps<T extends string, V> = {
72
+ export type VariantProps<T extends string, V> = {
70
73
  [Key in T]?: V;
71
74
  };
75
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,10 +1,10 @@
1
1
  import { Globals, StandardProperties, VendorProperties } from 'csstype';
2
- declare type ColorProperties = 'color' | `${string}Color`;
3
- declare type ColorGlobals = {
2
+ type ColorProperties = 'color' | `${string}Color`;
3
+ type ColorGlobals = {
4
4
  [K in Extract<keyof StandardProperties, ColorProperties>]?: Globals | 'currentColor' | 'transparent' | (string & {});
5
5
  };
6
- declare type SizeProperties = 'left' | 'right' | 'top' | 'bottom' | 'inset' | 'width' | 'height' | `${string}${'Width' | 'Height'}`;
7
- declare type SizeGlobals = {
6
+ type SizeProperties = 'left' | 'right' | 'top' | 'bottom' | 'inset' | 'width' | 'height' | `${string}${'Width' | 'Height'}`;
7
+ type SizeGlobals = {
8
8
  [K in Extract<keyof StandardProperties, SizeProperties>]?: StandardProperties[K] | (number & {});
9
9
  };
10
10
  /** This is a placeholder type for CSS properties that may not have any specific global values (outlineOffset).
@@ -12,11 +12,20 @@ declare type SizeGlobals = {
12
12
  *
13
13
  * This ensures that autosuggestions will still work for literal types but still allow any string for certain properties.
14
14
  */
15
- export declare type DefaultCSSPropertyValue = (string & {}) | 0;
15
+ export type DefaultCSSPropertyValue = (string & {}) | 0;
16
16
  export interface PropertyTypes<Overrides = DefaultCSSPropertyValue> extends Omit<StandardProperties<Overrides>, keyof ColorGlobals | keyof SizeGlobals>, ColorGlobals, SizeGlobals {
17
17
  }
18
18
  export interface VendorPropertyTypes<Overrides = DefaultCSSPropertyValue> extends VendorProperties<Overrides> {
19
19
  }
20
20
  export interface CSSPropertyTypes<Overrides = DefaultCSSPropertyValue> extends PropertyTypes<Overrides>, VendorPropertyTypes<Overrides> {
21
21
  }
22
+ export type PropertyMode = 'logical' | 'physical';
23
+ export interface DirectionalProperty {
24
+ physical: keyof PropertyTypes;
25
+ logical: keyof PropertyTypes;
26
+ }
27
+ export interface DirectionalProperties {
28
+ physical: readonly (keyof PropertyTypes)[];
29
+ logical: readonly (keyof PropertyTypes)[];
30
+ }
22
31
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -1,28 +1,38 @@
1
1
  import { Theme } from '@emotion/react';
2
2
  import { AbstractParser, Scale } from './config';
3
3
  import { CSSPropertyTypes } from './properties';
4
- export declare type AbstractProps = ThemeProps<Record<string, unknown>>;
4
+ export type AbstractProps = ThemeProps<Record<string, unknown>>;
5
5
  interface BreakpointKeys<T = string> {
6
6
  xs: T;
7
7
  sm: T;
8
8
  md: T;
9
9
  lg: T;
10
10
  xl: T;
11
+ c_xs: T;
12
+ c_sm: T;
13
+ c_md: T;
14
+ c_lg: T;
15
+ c_xl: T;
11
16
  }
12
17
  export interface BreakpointCache {
13
18
  map: BreakpointKeys;
14
19
  array: string[];
15
20
  }
16
- export declare type ThemeProps<Props = {}> = Props & {
21
+ export type ThemeProps<Props = {}> = Props & {
17
22
  theme?: Theme;
18
23
  };
19
- export interface MediaQueryArray<T> {
24
+ export interface BreakpointArray<T> {
20
25
  0?: T;
21
26
  1?: T;
22
27
  2?: T;
23
28
  3?: T;
24
29
  4?: T;
25
30
  5?: T;
31
+ 6?: T;
32
+ 7?: T;
33
+ 8?: T;
34
+ 9?: T;
35
+ 10?: T;
26
36
  }
27
37
  export interface MediaQueryMap<T> {
28
38
  _?: T;
@@ -32,16 +42,25 @@ export interface MediaQueryMap<T> {
32
42
  lg?: T;
33
43
  xl?: T;
34
44
  }
35
- export declare type ResponsiveProp<T> = T | MediaQueryMap<T> | MediaQueryArray<T>;
45
+ export interface ContainerQueryMap<T> {
46
+ c_base?: T;
47
+ c_xs?: T;
48
+ c_sm?: T;
49
+ c_md?: T;
50
+ c_lg?: T;
51
+ c_xl?: T;
52
+ }
53
+ export type BreakpointMap<T> = ContainerQueryMap<T> & MediaQueryMap<T>;
54
+ export type ResponsiveProp<T> = T | BreakpointMap<T> | BreakpointArray<T>;
36
55
  export interface CSSObject {
37
56
  [key: string]: string | number | CSSObject | undefined;
38
57
  }
39
- export declare type CSSPropMap<Props, System> = {
58
+ export type CSSPropMap<Props, System> = {
40
59
  [K in keyof Props]?: CSSProps<Props[K], System>;
41
60
  };
42
- export declare type CSSProps<Props, System> = {
61
+ export type CSSProps<Props, System> = {
43
62
  [K in keyof Props]?: K extends keyof System ? System[K] : K extends keyof CSSPropertyTypes ? CSSPropertyTypes[K] : Omit<CSSPropertyTypes, keyof System> & Omit<System, 'theme'>;
44
63
  };
45
- export declare type StyleProps<T extends (args: AbstractProps) => CSSObject> = Parameters<T>[0];
46
- export declare type ScaleValue<P extends AbstractParser, Prop extends keyof P['config']> = Scale<P['config'][Prop]>;
64
+ export type StyleProps<T extends (args: AbstractProps) => CSSObject> = Parameters<T>[0];
65
+ export type ScaleValue<P extends AbstractParser, Prop extends keyof P['config']> = Scale<P['config'][Prop]>;
47
66
  export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -4,6 +4,12 @@ export interface Breakpoints<T = string> {
4
4
  md: T;
5
5
  lg: T;
6
6
  xl: T;
7
+ c_base: T;
8
+ c_xs: T;
9
+ c_sm: T;
10
+ c_md: T;
11
+ c_lg: T;
12
+ c_xl: T;
7
13
  }
8
14
  export interface BaseTheme {
9
15
  breakpoints: Breakpoints;
@@ -0,0 +1 @@
1
+ export {};
@@ -1,3 +1,3 @@
1
- export declare type AllUnionKeys<T> = T extends any ? keyof T : never;
2
- export declare type KeyFromUnion<T, K> = T extends any ? K extends keyof T ? T[K] : never : never;
3
- export declare type Key<T> = T extends string ? T : never;
1
+ export type AllUnionKeys<T> = T extends any ? keyof T : never;
2
+ export type KeyFromUnion<T, K> = T extends any ? K extends keyof T ? T[K] : never : never;
3
+ export type Key<T> = T extends string ? T : never;
@@ -0,0 +1 @@
1
+ export {};
@@ -2,19 +2,19 @@
2
2
  * Returns an exhaustive list of all possible paths of an object T for keys K.
3
3
  * Possibilities are returned as `k1.k2.k3`.
4
4
  */
5
- export declare type FindPath<T, K extends keyof T, D extends string = '.'> = K extends string | number ? T[K] extends Record<string | number, any> ? T[K] extends ArrayLike<any> ? K | `${K}${D}${FindPath<T[K], Exclude<keyof T[K], keyof any[]>, D>}` : K | `${K}${D}${FindPath<T[K], keyof T[K], D>}` : K : never;
5
+ export type FindPath<T, K extends keyof T, D extends string = '.'> = K extends string | number ? T[K] extends Record<string | number, any> ? T[K] extends ArrayLike<any> ? K | `${K}${D}${FindPath<T[K], Exclude<keyof T[K], keyof any[]>, D>}` : K | `${K}${D}${FindPath<T[K], keyof T[K], D>}` : K : never;
6
6
  /** Returns valid paths of object T */
7
- export declare type Path<T, D extends string = '.'> = FindPath<T, keyof T, D> | keyof T;
7
+ export type Path<T, D extends string = '.'> = FindPath<T, keyof T, D> | keyof T;
8
8
  /** Returns the value of a valid path P `k1.k2.k3` in object T */
9
- export declare type PathValue<T, P extends Path<T, D>, D extends string = '.'> = P extends `${infer K}${D}${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K], D> ? PathValue<T[K], Rest, D> : never : never : P extends keyof T ? T[P] : never;
9
+ export type PathValue<T, P extends Path<T, D>, D extends string = '.'> = P extends `${infer K}${D}${infer Rest}` ? K extends keyof T ? Rest extends Path<T[K], D> ? PathValue<T[K], Rest, D> : never : never : P extends keyof T ? T[P] : never;
10
10
  /** Check if path has a primitive end value and return only the union of end paths */
11
- export declare type PathToLiteral<T, K extends Path<T, D>, D extends string = '.', Base extends string = ''> = PathValue<T, K, D> extends string | number ? K extends string | number ? K extends `${infer BasePath}${D}${Base}` ? BasePath : K : never : never;
11
+ export type PathToLiteral<T, K extends Path<T, D>, D extends string = '.', Base extends string = ''> = PathValue<T, K, D> extends string | number ? K extends string | number ? K extends `${infer BasePath}${D}${Base}` ? BasePath : K : never : never;
12
12
  /**
13
13
  * Reduce all paths to a single map of paths with primitive values removing all extra non stateful paths
14
14
  * { path: { sub: 1 } } => { 'path-sub': 1 }
15
15
  *
16
16
  */
17
- export declare type LiteralPaths<T extends Record<string | number, any>, D extends string = '.', Base extends string = ''> = {
17
+ export type LiteralPaths<T extends Record<string | number, any>, D extends string = '.', Base extends string = ''> = {
18
18
  [K in Path<T, D> as PathToLiteral<T, K, D, Base>]: PathValue<T, PathToLiteral<T, K, D>, D>;
19
19
  };
20
20
  export declare function flattenScale<T extends Record<string | number, any>, P extends string>(object: T, path?: P): LiteralPaths<T, '-', '_'>;
@@ -1,24 +1,35 @@
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; }
1
+ import isObject from 'lodash/isObject';
2
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
- import { isObject } from 'lodash';
8
3
  /**
9
4
  * Returns an exhaustive list of all possible paths of an object T for keys K.
10
5
  * Possibilities are returned as `k1.k2.k3`.
11
6
  */
12
7
 
13
- 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];
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 */
17
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
+ 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];
18
24
  if (isObject(current)) {
19
- return _objectSpread(_objectSpread({}, carry), flattenScale(current, nextKey));
25
+ return {
26
+ ...carry,
27
+ ...flattenScale(current, nextKey)
28
+ };
20
29
  }
21
-
22
- return _objectSpread(_objectSpread({}, carry), {}, _defineProperty({}, nextKey, object[key]));
30
+ return {
31
+ ...carry,
32
+ [nextKey]: object[key]
33
+ };
23
34
  }, {});
24
35
  }
@@ -1,6 +1,3 @@
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
+ import keys from 'lodash/keys';
2
+ import pick from 'lodash/pick';
3
+ export const getStaticCss = (props, filteredKeys) => pick(props, keys(props).filter(key => !filteredKeys.includes(key)));
@@ -1,52 +1,55 @@
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 = {
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 = {
3
3
  A_BEFORE_B: -1,
4
4
  B_BEFORE_A: 1,
5
5
  EQUAL: 1
6
6
  };
7
-
8
- var compare = function compare(a, b) {
7
+ const 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
+ const isShorthand = prop => typeof prop === 'string' && SHORTHAND_PROPERTIES.includes(prop);
13
+ const getShorthandIndex = prop => typeof prop === 'string' ? SHORTHAND_PROPERTIES.indexOf(prop) : -1;
14
+ const getPropertiesCount = properties => {
15
+ if (!properties) return 0;
16
+ if (Array.isArray(properties)) return properties.length;
17
+ // DirectionalProperties object - using physical array length as representative, since the length for logical is the same
18
+ return properties.physical?.length ?? 0;
19
+ };
20
+
13
21
  /**
14
22
  * Orders all properties by the most dependent props
15
23
  * @param config
16
24
  */
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
-
32
- 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);
25
+ export const orderPropNames = config => Object.keys(config).sort((a, b) => {
26
+ const {
27
+ [a]: aConf,
28
+ [b]: bConf
29
+ } = config;
30
+ const {
31
+ property: aProp,
32
+ properties: aProperties
33
+ } = aConf;
34
+ const {
35
+ property: bProp,
36
+ properties: bProperties
37
+ } = bConf;
38
+ const aIsShorthand = isShorthand(aProp);
39
+ const bIsShorthand = isShorthand(bProp);
40
+ if (aIsShorthand && bIsShorthand) {
41
+ const aNum = getPropertiesCount(aProperties);
42
+ const bNum = getPropertiesCount(bProperties);
43
+ if (aProp !== bProp) {
44
+ return compare(getShorthandIndex(aProp), getShorthandIndex(bProp));
46
45
  }
47
-
48
- if (aIsShorthand) return SORT.A_BEFORE_B;
49
- if (bIsShorthand) return SORT.B_BEFORE_A;
50
- return SORT.EQUAL;
51
- });
52
- };
46
+ if (aProp === bProp) {
47
+ if (aNum === 0) return SORT.A_BEFORE_B;
48
+ if (bNum === 0) return SORT.B_BEFORE_A;
49
+ }
50
+ return compare(bNum, aNum);
51
+ }
52
+ if (aIsShorthand) return SORT.A_BEFORE_B;
53
+ if (bIsShorthand) return SORT.B_BEFORE_A;
54
+ return SORT.EQUAL;
55
+ });
@@ -1,16 +1,16 @@
1
1
  import { AbstractPropTransformer } from '../types/config';
2
- import { BreakpointCache, CSSObject, MediaQueryMap, ThemeProps } from '../types/props';
2
+ import { BreakpointCache, BreakpointMap, CSSObject, ThemeProps } from '../types/props';
3
3
  import { Breakpoints } from '../types/theme';
4
4
  /**
5
5
  * Destructures the themes breakpoints into an ordered structure to traverse
6
6
  */
7
- export declare const parseBreakpoints: (breakpoints?: Breakpoints | undefined) => BreakpointCache | null;
7
+ export declare const parseBreakpoints: (breakpoints?: Breakpoints) => BreakpointCache | null;
8
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)[]> {
9
+ export declare const isMediaMap: (val: object) => val is BreakpointMap<string | number>;
10
+ interface ResponsiveParser<Bp extends BreakpointMap<string | number> | (string | number)[]> {
11
11
  <C extends AbstractPropTransformer>(value: Bp, props: ThemeProps, config: C, breakpoints: Bp): CSSObject;
12
12
  }
13
- export declare const objectParser: ResponsiveParser<MediaQueryMap<string | number>>;
13
+ export declare const objectParser: ResponsiveParser<BreakpointMap<string | number>>;
14
14
  export declare const arrayParser: ResponsiveParser<(string | number)[]>;
15
15
  export declare const orderBreakpoints: (styles: CSSObject, breakpoints: string[]) => CSSObject;
16
16
  export {};