@codecademy/variance 1.0.0-alpha.f6cb5a.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.
- package/dist/core.d.ts +5 -5
- package/dist/core.js +152 -163
- package/dist/createTheme/createTheme.d.ts +7 -0
- package/dist/createTheme/createTheme.js +118 -150
- package/dist/createTheme/createTheme.test.js +50 -62
- package/dist/createTheme/types.d.ts +7 -7
- package/dist/createTheme/types.js +1 -0
- package/dist/getPropertyMode/getPropertyMode.d.ts +2 -0
- package/dist/getPropertyMode/getPropertyMode.js +3 -0
- package/dist/getPropertyMode/getPropertyMode.test.js +15 -0
- package/dist/getPropertyMode/index.d.ts +1 -0
- package/dist/getPropertyMode/index.js +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -1
- package/dist/scales/createScale.js +1 -3
- package/dist/scales/createScaleLookup.d.ts +2 -2
- package/dist/scales/createScaleLookup.js +9 -17
- package/dist/transforms/transformSize.js +9 -31
- package/dist/types/config.d.ts +18 -14
- package/dist/types/config.js +1 -0
- package/dist/types/properties.d.ts +14 -5
- package/dist/types/properties.js +1 -0
- package/dist/types/props.d.ts +27 -8
- package/dist/types/props.js +1 -0
- package/dist/types/theme.d.ts +6 -0
- package/dist/types/theme.js +1 -0
- package/dist/types/utils.d.ts +3 -3
- package/dist/types/utils.js +1 -0
- package/dist/utils/flattenScale.d.ts +5 -5
- package/dist/utils/flattenScale.js +24 -13
- package/dist/utils/getStaticProperties.js +3 -6
- package/dist/utils/propNames.js +42 -39
- package/dist/utils/responsive.d.ts +5 -5
- package/dist/utils/responsive.js +60 -69
- package/dist/utils/serializeTokens.d.ts +2 -2
- package/dist/utils/serializeTokens.js +34 -26
- package/package.json +19 -31
- package/CHANGELOG.md +0 -325
- package/LICENSE +0 -21
- package/babel.config.js +0 -5
- package/dist/core.js.map +0 -1
- package/dist/createTheme/createTheme.js.map +0 -1
- package/dist/createTheme/createTheme.test.d.ts +0 -1
- package/dist/createTheme/createTheme.test.js.map +0 -1
- package/dist/createTheme/index.js.map +0 -1
- package/dist/createTheme/types.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/scales/createScale.js.map +0 -1
- package/dist/scales/createScaleLookup.js.map +0 -1
- package/dist/transforms/index.js.map +0 -1
- package/dist/transforms/transformSize.js.map +0 -1
- package/dist/types/config.js.map +0 -1
- package/dist/types/properties.js.map +0 -1
- package/dist/types/props.js.map +0 -1
- package/dist/types/theme.js.map +0 -1
- package/dist/types/utils.js.map +0 -1
- package/dist/utils/__fixtures__/testConfig.js +0 -153
- package/dist/utils/__fixtures__/testConfig.js.map +0 -1
- package/dist/utils/flattenScale.js.map +0 -1
- package/dist/utils/getStaticProperties.js.map +0 -1
- package/dist/utils/propNames.js.map +0 -1
- package/dist/utils/responsive.js.map +0 -1
- package/dist/utils/serializeTokens.js.map +0 -1
- package/jest.config.js +0 -1
- package/tsconfig.base.json +0 -3
|
@@ -1,47 +1,25 @@
|
|
|
1
|
-
|
|
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
|
|
7
|
+
return `${coordinate * 100}%`;
|
|
21
8
|
}
|
|
22
|
-
|
|
23
|
-
return "".concat(coordinate, "px");
|
|
9
|
+
return `${coordinate}px`;
|
|
24
10
|
};
|
|
25
|
-
|
|
26
|
-
export
|
|
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
|
-
|
|
46
|
-
return !unit ? percentageOrAbsolute(numericValue) : "".concat(numericValue).concat(unit);
|
|
23
|
+
const numericValue = parseFloat(number);
|
|
24
|
+
return !unit ? percentageOrAbsolute(numericValue) : `${numericValue}${unit}`;
|
|
47
25
|
};
|
package/dist/types/config.d.ts
CHANGED
|
@@ -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
|
|
6
|
-
export
|
|
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:
|
|
11
|
-
properties?: readonly
|
|
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
|
|
27
|
-
|
|
28
|
-
export
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
72
|
+
export type VariantProps<T extends string, V> = {
|
|
70
73
|
[Key in T]?: V;
|
|
71
74
|
};
|
|
75
|
+
export {};
|
package/dist/types/config.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { Globals, StandardProperties, VendorProperties } from 'csstype';
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
type ColorProperties = 'color' | `${string}Color`;
|
|
3
|
+
type ColorGlobals = {
|
|
4
4
|
[K in Extract<keyof StandardProperties, ColorProperties>]?: Globals | 'currentColor' | 'transparent' | (string & {});
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
|
|
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
|
|
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 {};
|
package/dist/types/properties.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/props.d.ts
CHANGED
|
@@ -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
|
|
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
|
|
21
|
+
export type ThemeProps<Props = {}> = Props & {
|
|
17
22
|
theme?: Theme;
|
|
18
23
|
};
|
|
19
|
-
export interface
|
|
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
|
|
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
|
|
58
|
+
export type CSSPropMap<Props, System> = {
|
|
40
59
|
[K in keyof Props]?: CSSProps<Props[K], System>;
|
|
41
60
|
};
|
|
42
|
-
export
|
|
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
|
|
46
|
-
export
|
|
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 {};
|
package/dist/types/props.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/theme.d.ts
CHANGED
package/dist/types/theme.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/types/utils.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export
|
|
2
|
-
export
|
|
3
|
-
export
|
|
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;
|
package/dist/types/utils.js
CHANGED
|
@@ -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
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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
|
|
25
|
+
return {
|
|
26
|
+
...carry,
|
|
27
|
+
...flattenScale(current, nextKey)
|
|
28
|
+
};
|
|
20
29
|
}
|
|
21
|
-
|
|
22
|
-
|
|
30
|
+
return {
|
|
31
|
+
...carry,
|
|
32
|
+
[nextKey]: object[key]
|
|
33
|
+
};
|
|
23
34
|
}, {});
|
|
24
35
|
}
|
|
@@ -1,6 +1,3 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
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)));
|
package/dist/utils/propNames.js
CHANGED
|
@@ -1,52 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
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
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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,
|
|
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
|
|
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
|
|
10
|
-
interface ResponsiveParser<Bp extends
|
|
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<
|
|
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 {};
|