@codecademy/variance 0.19.1-alpha.a809e8.0 → 0.20.1-alpha.447c4d.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/.turbo/turbo-build.log +6 -0
- package/CHANGELOG.md +14 -1
- package/dist/core.d.ts +10 -0
- package/dist/core.js +189 -0
- package/dist/core.js.map +1 -0
- package/dist/createTheme/createTheme.d.ts +55 -0
- package/dist/createTheme/createTheme.js +94 -0
- package/dist/createTheme/createTheme.js.map +1 -0
- package/dist/createTheme/createTheme.test.d.ts +1 -0
- package/dist/createTheme/createTheme.test.js +167 -0
- package/dist/createTheme/createTheme.test.js.map +1 -0
- package/dist/createTheme/index.d.ts +3 -0
- package/dist/createTheme/index.js +4 -0
- package/dist/createTheme/index.js.map +1 -0
- package/dist/createTheme/types.d.ts +42 -0
- package/dist/createTheme/types.js +2 -0
- package/dist/createTheme/types.js.map +1 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +6 -0
- package/dist/index.js.map +1 -0
- package/dist/scales/createScale.d.ts +3 -0
- package/dist/scales/createScale.js +2 -0
- package/dist/scales/createScale.js.map +1 -0
- package/dist/scales/createScaleLookup.d.ts +5 -0
- package/dist/scales/createScaleLookup.js +14 -0
- package/dist/scales/createScaleLookup.js.map +1 -0
- package/dist/src/core.d.ts +10 -0
- package/dist/src/core.js +189 -0
- package/dist/src/core.js.map +1 -0
- package/dist/src/createTheme/createTheme.test.d.ts +1 -0
- package/dist/src/createTheme/createTheme.test.js +167 -0
- package/dist/src/createTheme/createTheme.test.js.map +1 -0
- package/dist/src/index.d.ts +5 -0
- package/dist/src/index.js +6 -0
- package/dist/src/index.js.map +1 -0
- package/dist/src/utils/__fixtures__/testConfig.d.ts +153 -0
- package/dist/src/utils/__fixtures__/testConfig.js +94 -0
- package/dist/src/utils/__fixtures__/testConfig.js.map +1 -0
- package/dist/transforms/index.d.ts +1 -0
- package/dist/transforms/index.js +2 -0
- package/dist/transforms/index.js.map +1 -0
- package/dist/transforms/transformSize.d.ts +2 -0
- package/dist/transforms/transformSize.js +26 -0
- package/dist/transforms/transformSize.js.map +1 -0
- package/dist/types/config.d.ts +71 -0
- package/dist/types/config.js +2 -0
- package/dist/types/config.js.map +1 -0
- package/dist/types/properties.d.ts +22 -0
- package/dist/types/properties.js +2 -0
- package/dist/types/properties.js.map +1 -0
- package/dist/types/props.d.ts +47 -0
- package/dist/types/props.js +2 -0
- package/dist/types/props.js.map +1 -0
- package/dist/types/theme.d.ts +17 -0
- package/dist/types/theme.js +2 -0
- package/dist/types/theme.js.map +1 -0
- package/dist/types/utils.d.ts +3 -0
- package/dist/types/utils.js +2 -0
- package/dist/types/utils.js.map +1 -0
- package/dist/utils/__fixtures__/testConfig.d.ts +153 -0
- package/dist/utils/__fixtures__/testConfig.js +94 -0
- package/dist/utils/__fixtures__/testConfig.js.map +1 -0
- package/dist/utils/flattenScale.d.ts +20 -0
- package/dist/utils/flattenScale.js +18 -0
- package/dist/utils/flattenScale.js.map +1 -0
- package/dist/utils/getStaticProperties.d.ts +1 -0
- package/dist/utils/getStaticProperties.js +3 -0
- package/dist/utils/getStaticProperties.js.map +1 -0
- package/dist/utils/propNames.d.ts +6 -0
- package/dist/utils/propNames.js +66 -0
- package/dist/utils/propNames.js.map +1 -0
- package/dist/utils/responsive.d.ts +16 -0
- package/dist/utils/responsive.js +65 -0
- package/dist/utils/responsive.js.map +1 -0
- package/dist/utils/serializeTokens.d.ts +18 -0
- package/dist/utils/serializeTokens.js +33 -0
- package/dist/utils/serializeTokens.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,94 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":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UAAU,EAAE,CAAC,YAAY,EAAE,eAAe,CAAC;QAC3C,KAAK,EAAE,SAAS;KACjB;IACD,EAAE,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE;IAC9B,EAAE,EAAE,EAAE,QAAQ,EAAE,eAAe,EAAE;IACjC,EAAE,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE;IAChC,EAAE,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE;IAC/B,CAAC,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE;IACzB,EAAE,EAAE;QACF,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,CAAC,YAAY,EAAE,aAAa,CAAC;QACzC,KAAK,EAAE,SAAS;KACjB;IACD,EAAE,EAAE;QACF,QAAQ,EAAE,QAAQ;QAClB,UAAU,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC;QACzC,KAAK,EAAE,SAAS;KACjB;IACD,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE;IAC7B,EAAE,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE;IAChC,EAAE,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE;IAC/B,EAAE,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE;CACtB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './transformSize';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/transforms/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { isNumber } from 'lodash';
|
|
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`;
|
|
10
|
+
};
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"transformSize.js","sourceRoot":"","sources":["../../src/transforms/transformSize.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAElC,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,UAAkB,EAAE,EAAE;IACzD,IAAI,UAAU,KAAK,CAAC,EAAE;QACpB,OAAO,UAAU,CAAC;KACnB;IACD,IAAI,UAAU,IAAI,CAAC,IAAI,UAAU,IAAI,CAAC,CAAC,EAAE;QACvC,OAAO,GAAG,UAAU,GAAG,GAAG,GAAG,CAAC;KAC/B;IACD,OAAO,GAAG,UAAU,IAAI,CAAC;AAC3B,CAAC,CAAC;AAEF,MAAM,aAAa,GAAG,sBAAsB,CAAC;AAE7C,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,KAAsB,EAAE,EAAE;IACtD,IAAI,QAAQ,CAAC,KAAK,CAAC,EAAE;QACnB,OAAO,oBAAoB,CAAC,KAAK,CAAC,CAAC;KACpC;IAED,IAAI,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAC1B,OAAO,KAAK,CAAC;KACd;IAED,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,CAAC,GAAG,aAAa,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,EAAE,CAAC;IAE9D,IAAI,KAAK,KAAK,SAAS,EAAE;QACvB,OAAO,KAAK,CAAC;KACd;IAED,MAAM,YAAY,GAAG,UAAU,CAAC,MAAM,CAAC,CAAC;IAExC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,IAAI,EAAE,CAAC;AAC/E,CAAC,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { Theme } from '@emotion/react';
|
|
2
|
+
import { DefaultCSSPropertyValue, PropertyTypes } from './properties';
|
|
3
|
+
import { AbstractProps, CSSObject, CSSPropMap, CSSProps, ResponsiveProp, ThemeProps } from './props';
|
|
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)[] & {
|
|
7
|
+
length: 0;
|
|
8
|
+
};
|
|
9
|
+
export interface BaseProperty {
|
|
10
|
+
property: keyof PropertyTypes;
|
|
11
|
+
properties?: readonly (keyof PropertyTypes)[];
|
|
12
|
+
}
|
|
13
|
+
export interface Prop extends BaseProperty {
|
|
14
|
+
scale?: keyof Theme | MapScale | ArrayScale;
|
|
15
|
+
transform?: (val: string | number, prop?: string, props?: AbstractProps) => string | number | CSSObject;
|
|
16
|
+
}
|
|
17
|
+
export interface AbstractPropTransformer extends Prop {
|
|
18
|
+
prop: string;
|
|
19
|
+
styleFn: (value: unknown, prop: string, props: AbstractProps) => CSSObject;
|
|
20
|
+
}
|
|
21
|
+
export interface AbstractParser {
|
|
22
|
+
(props: AbstractProps): CSSObject;
|
|
23
|
+
propNames: string[];
|
|
24
|
+
config: Record<string, AbstractPropTransformer>;
|
|
25
|
+
}
|
|
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>)>;
|
|
29
|
+
export interface TransformFn<P extends string, Config extends Prop> {
|
|
30
|
+
(value: Scale<Config> | Scale<Config>, prop: P, props: ThemeProps<{
|
|
31
|
+
[K in P]?: Scale<Config>;
|
|
32
|
+
}>): CSSObject;
|
|
33
|
+
}
|
|
34
|
+
export interface PropTransformer<P extends string, C extends Prop> extends AbstractPropTransformer, Prop {
|
|
35
|
+
prop: P;
|
|
36
|
+
styleFn: TransformFn<P, C>;
|
|
37
|
+
}
|
|
38
|
+
export declare type TransformerMap<Config extends Record<string, Prop>> = {
|
|
39
|
+
[P in Key<keyof Config>]: PropTransformer<Key<P>, Config[P]>;
|
|
40
|
+
};
|
|
41
|
+
export interface Parser<Config extends Record<string, AbstractPropTransformer>> {
|
|
42
|
+
(props: ParserProps<Config>): CSSObject;
|
|
43
|
+
propNames: (keyof Config)[];
|
|
44
|
+
config: Config;
|
|
45
|
+
}
|
|
46
|
+
export declare type Compose<Args extends AbstractParser[]> = {
|
|
47
|
+
[K in AllUnionKeys<Args[number]['config']>]: KeyFromUnion<Args[number]['config'], K>;
|
|
48
|
+
};
|
|
49
|
+
export interface Variant<P extends AbstractParser> {
|
|
50
|
+
<Keys extends keyof Props, Base extends AbstractProps, Props extends Record<Keys, AbstractProps>, PropKey extends Readonly<string> = 'variant'>(options: {
|
|
51
|
+
prop?: PropKey;
|
|
52
|
+
defaultVariant?: keyof Props;
|
|
53
|
+
base?: CSSProps<Base, SystemProps<P>>;
|
|
54
|
+
variants: CSSPropMap<Props, SystemProps<P>>;
|
|
55
|
+
}): (props: VariantProps<PropKey, Keys | false> & ThemeProps) => CSSObject;
|
|
56
|
+
}
|
|
57
|
+
export interface States<P extends AbstractParser> {
|
|
58
|
+
<Props extends Record<string, AbstractProps>>(states: CSSPropMap<Props, SystemProps<P>>): (props: Partial<Record<keyof Props, boolean>> & ThemeProps) => CSSObject;
|
|
59
|
+
}
|
|
60
|
+
export interface CSS<P extends AbstractParser> {
|
|
61
|
+
<Props extends AbstractProps>(config: CSSProps<Props, SystemProps<P>>): (props: ThemeProps) => CSSObject;
|
|
62
|
+
}
|
|
63
|
+
export declare type ParserProps<Config extends Record<string, AbstractPropTransformer>> = ThemeProps<{
|
|
64
|
+
[P in keyof Config]?: Parameters<Config[P]['styleFn']>[2][Config[P]['prop']];
|
|
65
|
+
}>;
|
|
66
|
+
export declare type SystemProps<P extends AbstractParser> = {
|
|
67
|
+
[K in keyof Omit<Parameters<P>[0], 'theme'>]: Omit<Parameters<P>[0], 'theme'>[K];
|
|
68
|
+
};
|
|
69
|
+
export declare type VariantProps<T extends string, V> = {
|
|
70
|
+
[Key in T]?: V;
|
|
71
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/types/config.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Globals, StandardProperties, VendorProperties } from 'csstype';
|
|
2
|
+
declare type ColorProperties = 'color' | `${string}Color`;
|
|
3
|
+
declare type ColorGlobals = {
|
|
4
|
+
[K in Extract<keyof StandardProperties, ColorProperties>]?: Globals | 'currentColor' | 'transparent' | (string & {});
|
|
5
|
+
};
|
|
6
|
+
declare type SizeProperties = 'left' | 'right' | 'top' | 'bottom' | 'inset' | 'width' | 'height' | `${string}${'Width' | 'Height'}`;
|
|
7
|
+
declare type SizeGlobals = {
|
|
8
|
+
[K in Extract<keyof StandardProperties, SizeProperties>]?: StandardProperties[K] | (number & {});
|
|
9
|
+
};
|
|
10
|
+
/** This is a placeholder type for CSS properties that may not have any specific global values (outlineOffset).
|
|
11
|
+
* (string & {}) will allow strings but not generalize the union type to just a string if other string literals exist in the union.
|
|
12
|
+
*
|
|
13
|
+
* This ensures that autosuggestions will still work for literal types but still allow any string for certain properties.
|
|
14
|
+
*/
|
|
15
|
+
export declare type DefaultCSSPropertyValue = (string & {}) | 0;
|
|
16
|
+
export interface PropertyTypes<Overrides = DefaultCSSPropertyValue> extends Omit<StandardProperties<Overrides>, keyof ColorGlobals | keyof SizeGlobals>, ColorGlobals, SizeGlobals {
|
|
17
|
+
}
|
|
18
|
+
export interface VendorPropertyTypes<Overrides = DefaultCSSPropertyValue> extends VendorProperties<Overrides> {
|
|
19
|
+
}
|
|
20
|
+
export interface CSSPropertyTypes<Overrides = DefaultCSSPropertyValue> extends PropertyTypes<Overrides>, VendorPropertyTypes<Overrides> {
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"properties.js","sourceRoot":"","sources":["../../src/types/properties.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Theme } from '@emotion/react';
|
|
2
|
+
import { AbstractParser, Scale } from './config';
|
|
3
|
+
import { CSSPropertyTypes } from './properties';
|
|
4
|
+
export declare type AbstractProps = ThemeProps<Record<string, unknown>>;
|
|
5
|
+
interface BreakpointKeys<T = string> {
|
|
6
|
+
xs: T;
|
|
7
|
+
sm: T;
|
|
8
|
+
md: T;
|
|
9
|
+
lg: T;
|
|
10
|
+
xl: T;
|
|
11
|
+
}
|
|
12
|
+
export interface BreakpointCache {
|
|
13
|
+
map: BreakpointKeys;
|
|
14
|
+
array: string[];
|
|
15
|
+
}
|
|
16
|
+
export declare type ThemeProps<Props = {}> = Props & {
|
|
17
|
+
theme?: Theme;
|
|
18
|
+
};
|
|
19
|
+
export interface MediaQueryArray<T> {
|
|
20
|
+
0?: T;
|
|
21
|
+
1?: T;
|
|
22
|
+
2?: T;
|
|
23
|
+
3?: T;
|
|
24
|
+
4?: T;
|
|
25
|
+
5?: T;
|
|
26
|
+
}
|
|
27
|
+
export interface MediaQueryMap<T> {
|
|
28
|
+
_?: T;
|
|
29
|
+
xs?: T;
|
|
30
|
+
sm?: T;
|
|
31
|
+
md?: T;
|
|
32
|
+
lg?: T;
|
|
33
|
+
xl?: T;
|
|
34
|
+
}
|
|
35
|
+
export declare type ResponsiveProp<T> = T | MediaQueryMap<T> | MediaQueryArray<T>;
|
|
36
|
+
export interface CSSObject {
|
|
37
|
+
[key: string]: string | number | CSSObject | undefined;
|
|
38
|
+
}
|
|
39
|
+
export declare type CSSPropMap<Props, System> = {
|
|
40
|
+
[K in keyof Props]?: CSSProps<Props[K], System>;
|
|
41
|
+
};
|
|
42
|
+
export declare type CSSProps<Props, System> = {
|
|
43
|
+
[K in keyof Props]?: K extends keyof System ? System[K] : K extends keyof CSSPropertyTypes ? CSSPropertyTypes[K] : Omit<CSSPropertyTypes, keyof System> & Omit<System, 'theme'>;
|
|
44
|
+
};
|
|
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]>;
|
|
47
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/types/props.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface Breakpoints<T = string> {
|
|
2
|
+
xs: T;
|
|
3
|
+
sm: T;
|
|
4
|
+
md: T;
|
|
5
|
+
lg: T;
|
|
6
|
+
xl: T;
|
|
7
|
+
}
|
|
8
|
+
export interface BaseTheme {
|
|
9
|
+
breakpoints: Breakpoints;
|
|
10
|
+
}
|
|
11
|
+
export interface AbstractTheme extends BaseTheme {
|
|
12
|
+
readonly [key: string]: any;
|
|
13
|
+
}
|
|
14
|
+
declare module '@emotion/react' {
|
|
15
|
+
interface Theme extends BaseTheme {
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../../src/types/theme.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/types/utils.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
export declare const testConfig: {
|
|
2
|
+
readonly textColor: {
|
|
3
|
+
readonly property: "color";
|
|
4
|
+
};
|
|
5
|
+
readonly bg: {
|
|
6
|
+
readonly property: "backgroundColor";
|
|
7
|
+
};
|
|
8
|
+
readonly borderColor: {
|
|
9
|
+
readonly property: "borderColor";
|
|
10
|
+
};
|
|
11
|
+
readonly borderColorX: {
|
|
12
|
+
readonly property: "borderColor";
|
|
13
|
+
readonly properties: readonly ["borderLeftColor", "borderRightColor"];
|
|
14
|
+
readonly scale: "colors";
|
|
15
|
+
};
|
|
16
|
+
readonly borderColorY: {
|
|
17
|
+
readonly property: "borderColor";
|
|
18
|
+
readonly properties: readonly ["borderTopColor", "borderBottomColor"];
|
|
19
|
+
readonly scale: "colors";
|
|
20
|
+
};
|
|
21
|
+
readonly borderColorLeft: {
|
|
22
|
+
readonly property: "borderLeftColor";
|
|
23
|
+
};
|
|
24
|
+
readonly borderColorRight: {
|
|
25
|
+
readonly property: "borderRightColor";
|
|
26
|
+
};
|
|
27
|
+
readonly borderColorTop: {
|
|
28
|
+
readonly property: "borderTopColor";
|
|
29
|
+
};
|
|
30
|
+
readonly borderColorBottom: {
|
|
31
|
+
readonly property: "borderBottomColor";
|
|
32
|
+
};
|
|
33
|
+
readonly border: {
|
|
34
|
+
readonly property: "border";
|
|
35
|
+
};
|
|
36
|
+
readonly borderX: {
|
|
37
|
+
readonly property: "border";
|
|
38
|
+
readonly properties: readonly ["borderLeft", "borderRight"];
|
|
39
|
+
};
|
|
40
|
+
readonly borderY: {
|
|
41
|
+
readonly property: "border";
|
|
42
|
+
readonly properties: readonly ["borderTop", "borderBottom"];
|
|
43
|
+
};
|
|
44
|
+
readonly borderTop: {
|
|
45
|
+
readonly property: "borderTop";
|
|
46
|
+
};
|
|
47
|
+
readonly borderRight: {
|
|
48
|
+
readonly property: "borderRight";
|
|
49
|
+
};
|
|
50
|
+
readonly borderBottom: {
|
|
51
|
+
readonly property: "borderBottom";
|
|
52
|
+
};
|
|
53
|
+
readonly borderLeft: {
|
|
54
|
+
readonly property: "borderLeft";
|
|
55
|
+
};
|
|
56
|
+
readonly borderWidth: {
|
|
57
|
+
readonly property: "borderWidth";
|
|
58
|
+
};
|
|
59
|
+
readonly borderWidthX: {
|
|
60
|
+
readonly property: "borderWidth";
|
|
61
|
+
readonly properties: readonly ["borderLeftWidth", "borderRightWidth"];
|
|
62
|
+
};
|
|
63
|
+
readonly borderWidthY: {
|
|
64
|
+
readonly property: "borderWidth";
|
|
65
|
+
readonly properties: readonly ["borderTopWidth", "borderBottomWidth"];
|
|
66
|
+
};
|
|
67
|
+
readonly borderRadius: {
|
|
68
|
+
readonly property: "borderRadius";
|
|
69
|
+
};
|
|
70
|
+
readonly borderRadiusLeft: {
|
|
71
|
+
readonly property: "borderRadius";
|
|
72
|
+
readonly properties: readonly ["borderTopLeftRadius", "borderBottomLeftRadius"];
|
|
73
|
+
};
|
|
74
|
+
readonly borderRadiusTop: {
|
|
75
|
+
readonly property: "borderRadius";
|
|
76
|
+
readonly properties: readonly ["borderTopLeftRadius", "borderTopRightRadius"];
|
|
77
|
+
};
|
|
78
|
+
readonly borderRadiusBottom: {
|
|
79
|
+
readonly property: "borderRadius";
|
|
80
|
+
readonly properties: readonly ["borderBottomLeftRadius", "borderBottomRightRadius"];
|
|
81
|
+
};
|
|
82
|
+
readonly borderRadiusRight: {
|
|
83
|
+
readonly property: "borderRadius";
|
|
84
|
+
readonly properties: readonly ["borderTopRightRadius", "borderBottomRightRadius"];
|
|
85
|
+
};
|
|
86
|
+
readonly borderStyle: {
|
|
87
|
+
readonly property: "borderStyle";
|
|
88
|
+
};
|
|
89
|
+
readonly borderStyleX: {
|
|
90
|
+
readonly property: "borderStyle";
|
|
91
|
+
readonly properties: readonly ["borderLeftStyle", "borderRightStyle"];
|
|
92
|
+
};
|
|
93
|
+
readonly borderStyleY: {
|
|
94
|
+
readonly property: "borderStyle";
|
|
95
|
+
readonly properties: readonly ["borderTopStyle", "borderBottomStyle"];
|
|
96
|
+
};
|
|
97
|
+
readonly flex: {
|
|
98
|
+
readonly property: "flex";
|
|
99
|
+
};
|
|
100
|
+
readonly flexBasis: {
|
|
101
|
+
readonly property: "flexBasis";
|
|
102
|
+
};
|
|
103
|
+
readonly p: {
|
|
104
|
+
readonly property: "padding";
|
|
105
|
+
};
|
|
106
|
+
readonly px: {
|
|
107
|
+
readonly property: "padding";
|
|
108
|
+
readonly properties: readonly ["paddingLeft", "paddingRight"];
|
|
109
|
+
readonly scale: "spacing";
|
|
110
|
+
};
|
|
111
|
+
readonly py: {
|
|
112
|
+
readonly property: "padding";
|
|
113
|
+
readonly properties: readonly ["paddingTop", "paddingBottom"];
|
|
114
|
+
readonly scale: "spacing";
|
|
115
|
+
};
|
|
116
|
+
readonly pt: {
|
|
117
|
+
readonly property: "paddingTop";
|
|
118
|
+
};
|
|
119
|
+
readonly pb: {
|
|
120
|
+
readonly property: "paddingBottom";
|
|
121
|
+
};
|
|
122
|
+
readonly pr: {
|
|
123
|
+
readonly property: "paddingRight";
|
|
124
|
+
};
|
|
125
|
+
readonly pl: {
|
|
126
|
+
readonly property: "paddingLeft";
|
|
127
|
+
};
|
|
128
|
+
readonly m: {
|
|
129
|
+
readonly property: "margin";
|
|
130
|
+
};
|
|
131
|
+
readonly mx: {
|
|
132
|
+
readonly property: "margin";
|
|
133
|
+
readonly properties: readonly ["marginLeft", "marginRight"];
|
|
134
|
+
readonly scale: "spacing";
|
|
135
|
+
};
|
|
136
|
+
readonly my: {
|
|
137
|
+
readonly property: "margin";
|
|
138
|
+
readonly properties: readonly ["marginTop", "marginBottom"];
|
|
139
|
+
readonly scale: "spacing";
|
|
140
|
+
};
|
|
141
|
+
readonly mt: {
|
|
142
|
+
readonly property: "marginTop";
|
|
143
|
+
};
|
|
144
|
+
readonly mb: {
|
|
145
|
+
readonly property: "marginBottom";
|
|
146
|
+
};
|
|
147
|
+
readonly mr: {
|
|
148
|
+
readonly property: "marginRight";
|
|
149
|
+
};
|
|
150
|
+
readonly ml: {
|
|
151
|
+
readonly property: "marginLeft";
|
|
152
|
+
};
|
|
153
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testConfig.js","sourceRoot":"","sources":["../../../src/utils/__fixtures__/testConfig.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,SAAS,EAAE,EAAE,QAAQ,EAAE,OAAO,EAAE;IAChC,EAAE,EAAE,EAAE,QAAQ,EAAE,iBAAiB,EAAE;IACnC,WAAW,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE;IACxC,YAAY,EAAE;QACZ,QAAQ,EAAE,aAAa;QACvB,UAAU,EAAE,CAAC,iBAAiB,EAAE,kBAAkB,CAAC;QACnD,KAAK,EAAE,QAAQ;KAChB;IACD,YAAY,EAAE;QACZ,QAAQ,EAAE,aAAa;QACvB,UAAU,EAAE,CAAC,gBAAgB,EAAE,mBAAmB,CAAC;QACnD,KAAK,EAAE,QAAQ;KAChB;IACD,eAAe,EAAE,EAAE,QAAQ,EAAE,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,SAAS;KACjB;IACD,EAAE,EAAE,EAAE,QAAQ,EAAE,WAAW,EAAE;IAC7B,EAAE,EAAE,EAAE,QAAQ,EAAE,cAAc,EAAE;IAChC,EAAE,EAAE,EAAE,QAAQ,EAAE,aAAa,EAAE;IAC/B,EAAE,EAAE,EAAE,QAAQ,EAAE,YAAY,EAAE;CACtB,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an exhaustive list of all possible paths of an object T for keys K.
|
|
3
|
+
* Possibilities are returned as `k1.k2.k3`.
|
|
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;
|
|
6
|
+
/** Returns valid paths of object T */
|
|
7
|
+
export declare type Path<T, D extends string = '.'> = FindPath<T, keyof T, D> | keyof T;
|
|
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;
|
|
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;
|
|
12
|
+
/**
|
|
13
|
+
* Reduce all paths to a single map of paths with primitive values removing all extra non stateful paths
|
|
14
|
+
* { path: { sub: 1 } } => { 'path-sub': 1 }
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export declare type LiteralPaths<T extends Record<string | number, any>, D extends string = '.', Base extends string = ''> = {
|
|
18
|
+
[K in Path<T, D> as PathToLiteral<T, K, D, Base>]: PathValue<T, PathToLiteral<T, K, D>, D>;
|
|
19
|
+
};
|
|
20
|
+
export declare function flattenScale<T extends Record<string | number, any>, P extends string>(object: T, path?: P): LiteralPaths<T, '-', '_'>;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { isObject } from 'lodash';
|
|
2
|
+
export function flattenScale(object, path) {
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flattenScale.js","sourceRoot":"","sources":["../../src/utils/flattenScale.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,QAAQ,CAAC;AAiElC,MAAM,UAAU,YAAY,CAG1B,MAAS,EAAE,IAAQ;IACnB,OAAO,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,GAAG,EAAE,EAAE;QAC/C,MAAM,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;QACtE,MAAM,OAAO,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5B,IAAI,QAAQ,CAAC,OAAO,CAAC,EAAE;YACrB,OAAO;gBACL,GAAG,KAAK;gBACR,GAAG,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC;aAClC,CAAC;SACH;QACD,OAAO;YACL,GAAG,KAAK;YACR,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,GAAG,CAAC;SACvB,CAAC;IACJ,CAAC,EAAE,EAA+B,CAAC,CAAC;AACtC,CAAC"}
|