react-native-unistyles 2.0.0-alpha.10 → 2.0.0-alpha.11
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/types/variants.js +2 -0
- package/lib/commonjs/types/variants.js.map +1 -0
- package/lib/commonjs/useStyles.js.map +1 -1
- package/lib/commonjs/utils/breakpoints.js +4 -13
- package/lib/commonjs/utils/breakpoints.js.map +1 -1
- package/lib/commonjs/utils/index.js +3 -3
- package/lib/commonjs/utils/styles.js +14 -3
- package/lib/commonjs/utils/styles.js.map +1 -1
- package/lib/commonjs/utils/variants.js +2 -5
- package/lib/commonjs/utils/variants.js.map +1 -1
- package/lib/module/types/variants.js +2 -0
- package/lib/module/types/variants.js.map +1 -0
- package/lib/module/useStyles.js.map +1 -1
- package/lib/module/utils/breakpoints.js +2 -11
- package/lib/module/utils/breakpoints.js.map +1 -1
- package/lib/module/utils/index.js +1 -1
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/utils/styles.js +15 -4
- package/lib/module/utils/styles.js.map +1 -1
- package/lib/module/utils/variants.js +2 -5
- package/lib/module/utils/variants.js.map +1 -1
- package/lib/typescript/src/types/breakpoints.d.ts +3 -4
- package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/types/core.d.ts +3 -9
- package/lib/typescript/src/types/core.d.ts.map +1 -1
- package/lib/typescript/src/types/index.d.ts +1 -0
- package/lib/typescript/src/types/index.d.ts.map +1 -1
- package/lib/typescript/src/types/variants.d.ts +8 -0
- package/lib/typescript/src/types/variants.d.ts.map +1 -0
- package/lib/typescript/src/useStyles.d.ts +2 -2
- package/lib/typescript/src/useStyles.d.ts.map +1 -1
- package/lib/typescript/src/utils/breakpoints.d.ts +1 -1
- package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
- package/lib/typescript/src/utils/index.d.ts +1 -1
- package/lib/typescript/src/utils/index.d.ts.map +1 -1
- package/lib/typescript/src/utils/styles.d.ts.map +1 -1
- package/lib/typescript/src/utils/variants.d.ts +1 -1
- package/lib/typescript/src/utils/variants.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/types/breakpoints.ts +5 -4
- package/src/types/core.ts +4 -10
- package/src/types/index.ts +1 -0
- package/src/types/variants.ts +11 -0
- package/src/useStyles.ts +8 -2
- package/src/utils/breakpoints.ts +2 -11
- package/src/utils/index.ts +1 -1
- package/src/utils/styles.ts +24 -9
- package/src/utils/variants.ts +5 -9
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/variants.ts"],"mappings":""}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_reactNative","_utils","_hooks","useStyles","stylesheet","variant","theme","layout","useUnistyles","screenSize","breakpoint","styles","parsedStyles","useMemo","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","proxifyFunction","StyleSheet","create","parseStyle","exports"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;
|
1
|
+
{"version":3,"names":["_react","require","_reactNative","_utils","_hooks","useStyles","stylesheet","variant","theme","layout","useUnistyles","screenSize","breakpoint","styles","parsedStyles","useMemo","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","proxifyFunction","StyleSheet","create","parseStyle","exports"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAQA,IAAAG,MAAA,GAAAH,OAAA;AASO,MAAMI,SAAS,GAAGA,CACrBC,UAAyD,EACzDC,OAAyD,KAClC;EACvB,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAG,IAAAC,mBAAY,EAAC,CAAC;EACxC,MAAM;IAAEC,UAAU;IAAEC;EAAW,CAAC,GAAGH,MAAM;EAEzC,IAAI,CAACH,UAAU,EAAE;IACb,OAAO;MACHE,KAAK;MACLI,UAAU;MACVC,MAAM,EAAE,CAAC;IACb,CAAC;EACL;EAEA,MAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC,MAAM,OAAOT,UAAU,KAAK,UAAU,GAC7DA,UAAU,CAACE,KAAK,CAAC,GACjBF,UAAU,EAAE,CAACE,KAAK,EAAEF,UAAU,CAAC,CAAC;EAEtC,MAAMU,iBAAiB,GAAG,IAAAD,cAAO,EAAC,MAAME,MAAM,CACzCC,OAAO,CAACJ,YAAY,CAAC,CACrBK,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACtB,MAAMG,KAAK,GAAGD,KAA8B;IAE5C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MAC7B,OAAO;QACH,GAAGH,GAAG;QACN,CAACE,GAAG,GAAG,IAAAG,sBAAe,EAACF,KAAK,EAAEX,UAAU,EAAED,UAAU,EAAEJ,OAAO;MACjE,CAAC;IACL;IAEA,OAAOmB,uBAAU,CAACC,MAAM,CAAC;MACrB,GAAGP,GAAG;MACN,CAACE,GAAG,GAAG,IAAAM,iBAAU,EAAKJ,KAAK,EAAEZ,UAAU,EAAED,UAAU,EAAEJ,OAAO;IAChE,CAAC,CAAC;EACN,CAAC,EAAE,CAAC,CAAO,CAAC,EAAE,CAACK,UAAU,EAAED,UAAU,EAAEG,YAAY,EAAEP,OAAO,CAAC,CAA8B;EAE/F,OAAO;IACHC,KAAK;IACLI,UAAU;IACVC,MAAM,EAAEG;EACZ,CAAC;AACL,CAAC;AAAAa,OAAA,CAAAxB,SAAA,GAAAA,SAAA"}
|
@@ -3,12 +3,11 @@
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
4
4
|
value: true
|
5
5
|
});
|
6
|
-
exports.sortAndValidateBreakpoints = exports.
|
6
|
+
exports.sortAndValidateBreakpoints = exports.getValueForBreakpoint = exports.getBreakpointFromScreenWidth = void 0;
|
7
7
|
var _core = require("../core");
|
8
8
|
var _common = require("./common");
|
9
9
|
var _common2 = require("../common");
|
10
10
|
var _mqParser = require("./mqParser");
|
11
|
-
var _variants = require("./variants");
|
12
11
|
const sortAndValidateBreakpoints = breakpoints => {
|
13
12
|
const sortedPairs = Object.entries(breakpoints).sort((breakpoint1, breakpoint2) => {
|
14
13
|
const [, value1] = breakpoint1;
|
@@ -39,17 +38,9 @@ const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
|
|
39
38
|
});
|
40
39
|
return key;
|
41
40
|
};
|
42
|
-
|
43
|
-
// todo move it to different file
|
44
41
|
exports.getBreakpointFromScreenWidth = getBreakpointFromScreenWidth;
|
45
|
-
const
|
46
|
-
// the highest priority is for
|
47
|
-
const variantKey = (0, _variants.getKeyForVariant)(value, variant);
|
48
|
-
if (variantKey) {
|
49
|
-
return value.variants[variantKey];
|
50
|
-
}
|
51
|
-
|
52
|
-
// then custom media queries
|
42
|
+
const getValueForBreakpoint = value => {
|
43
|
+
// the highest priority is for custom media queries
|
53
44
|
const customMediaQueryKey = (0, _mqParser.getKeyForUnistylesMediaQuery)(Object.entries(value), _core.unistyles.runtime.screen);
|
54
45
|
if (customMediaQueryKey) {
|
55
46
|
return value[customMediaQueryKey];
|
@@ -93,5 +84,5 @@ const getValueForNestedStyle = (value, variant) => {
|
|
93
84
|
});
|
94
85
|
return breakpointPairs.length > 0 ? value[availableBreakpoints[availableBreakpoints.length - 1]] : undefined;
|
95
86
|
};
|
96
|
-
exports.
|
87
|
+
exports.getValueForBreakpoint = getValueForBreakpoint;
|
97
88
|
//# sourceMappingURL=breakpoints.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_core","require","_common","_common2","_mqParser","
|
1
|
+
{"version":3,"names":["_core","require","_common","_common2","_mqParser","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","throwError","length","Set","size","exports","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","customMediaQueryKey","getKeyForUnistylesMediaQuery","unistyles","runtime","screen","hasBreakpoints","isMobile","Orientation","Landscape","Portrait","orientation","ScreenOrientation","breakpoint","undefined","directBreakpoint","breakpointPairs","currentBreakpoint","findIndex","_ref2","availableBreakpoints","filter","_ref3","map","_ref4"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEO,MAAMI,0BAA0B,GAAIC,WAAiC,IAA2B;EACnG,MAAMC,WAAW,GAAGC,MAAM,CACrBC,OAAO,CAACH,WAAW,CAAC,CACpBI,IAAI,CAAC,CAACC,WAAW,EAAEC,WAAW,KAAK;IAChC,MAAM,GAAGC,MAAM,CAAC,GAAGF,WAAW;IAC9B,MAAM,GAAGG,MAAM,CAAC,GAAGF,WAAW;IAE9B,OAAQC,MAAM,GAAeC,MAAiB;EAClD,CAAC,CAAC;EAEN,MAAMC,iBAAiB,GAAIP,MAAM,CAACQ,MAAM,CAACR,MAAM,CAACS,WAAW,CAACV,WAAW,CAAC,CAAyB;EACjG,MAAMW,gBAAgB,GAAGV,MAAM,CAACW,MAAM,CAACJ,iBAAiB,CAAC;EACzD,MAAM,CAACK,eAAe,CAAC,GAAGF,gBAAgB;EAE1C,IAAIE,eAAe,KAAK,CAAC,EAAE;IACvB,IAAAC,kBAAU,EAAC,oCAAoC,CAAC;EACpD;EAEA,IAAIH,gBAAgB,CAACI,MAAM,KAAK,IAAIC,GAAG,CAACL,gBAAgB,CAAC,CAACM,IAAI,EAAE;IAC5D,IAAAH,kBAAU,EAAC,kCAAkC,CAAC;EAClD;EAEA,OA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BAAW,CAACC,SAAS,CAC9B;EACL;;EAEA;EACA,MAAMI,UAAU,GAAGV,eAAS,CAACC,OAAO,CAACS,UAAU;EAE/C,IAAI,CAACA,UAAU,EAAE;IACb,OAAOC,SAAS;EACpB;;EAEA;EACA,MAAMC,gBAAgB,GAAGlB,KAAK,CAACgB,UAAU,CAAC;;EAE1C;EACA,IAAIE,gBAAgB,IAAKF,UAAU,IAAIhB,KAAM,EAAE;IAC3C,OAAOkB,gBAAgB;EAC3B;;EAEA;EACA,MAAMC,eAAe,GAAGb,eAAS,CAACC,OAAO,CAAC1B,iBAAiB;EAC3D,MAAMuC,iBAAiB,GAAGD,eAAe,CACpCE,SAAS,CAACC,KAAA;IAAA,IAAC,CAAC3B,GAAG,CAAC,GAAA2B,KAAA;IAAA,OAAK3B,GAAG,KAAKqB,UAAU;EAAA,EAAC;EAE7C,MAAMO,oBAAoB,GAAGJ,eAAe,CACvCK,MAAM,CAAC,CAAAC,KAAA,EAAQ3B,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAA8B,KAAA;IAAA,OAAY3B,KAAK,GAAGsB,iBAAiB,IAAIzB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1E0B,GAAG,CAACC,KAAA;IAAA,IAAC,CAAChC,GAAG,CAAC,GAAAgC,KAAA;IAAA,OAAKhC,GAAG;EAAA,EAAC;EAExB,OAAOwB,eAAe,CAAC/B,MAAM,GAAG,CAAC,GAC3BY,KAAK,CAACuB,oBAAoB,CAACA,oBAAoB,CAACnC,MAAM,GAAG,CAAC,CAAC,CAAwC,GACnG6B,SAAS;AACnB,CAAC;AAAA1B,OAAA,CAAAY,qBAAA,GAAAA,qBAAA"}
|
@@ -11,7 +11,7 @@ var _exportNames = {
|
|
11
11
|
getKeyForUnistylesMediaQuery: true,
|
12
12
|
getBreakpointFromScreenWidth: true,
|
13
13
|
sortAndValidateBreakpoints: true,
|
14
|
-
|
14
|
+
getValueForBreakpoint: true,
|
15
15
|
proxifyFunction: true,
|
16
16
|
parseStyle: true,
|
17
17
|
isServer: true,
|
@@ -47,10 +47,10 @@ Object.defineProperty(exports, "getKeyForVariant", {
|
|
47
47
|
return _variants.getKeyForVariant;
|
48
48
|
}
|
49
49
|
});
|
50
|
-
Object.defineProperty(exports, "
|
50
|
+
Object.defineProperty(exports, "getValueForBreakpoint", {
|
51
51
|
enumerable: true,
|
52
52
|
get: function () {
|
53
|
-
return _breakpoints.
|
53
|
+
return _breakpoints.getValueForBreakpoint;
|
54
54
|
}
|
55
55
|
});
|
56
56
|
Object.defineProperty(exports, "isServer", {
|
@@ -7,6 +7,7 @@ exports.proxifyFunction = exports.parseStyle = exports.isPlatformColor = void 0;
|
|
7
7
|
var _breakpoints = require("./breakpoints");
|
8
8
|
var _normalizeStyles = require("./normalizeStyles");
|
9
9
|
var _common = require("./common");
|
10
|
+
var _variants = require("./variants");
|
10
11
|
const proxifyFunction = (fn, breakpoint, screenSize, variant) => new Proxy(fn, {
|
11
12
|
apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, variant)
|
12
13
|
});
|
@@ -19,9 +20,19 @@ const isPlatformColor = value => {
|
|
19
20
|
};
|
20
21
|
exports.isPlatformColor = isPlatformColor;
|
21
22
|
const parseStyle = (style, breakpoint, screenSize, variant) => {
|
22
|
-
const entries = Object.entries(style || {})
|
23
|
-
const parsedStyles = Object.fromEntries(entries.map(_ref => {
|
23
|
+
const entries = Object.entries(style || {}).map(_ref => {
|
24
24
|
let [key, value] = _ref;
|
25
|
+
if (key !== 'variants') {
|
26
|
+
return [key, value];
|
27
|
+
}
|
28
|
+
const variantKey = (0, _variants.getKeyForVariant)(value, variant);
|
29
|
+
if (!variantKey) {
|
30
|
+
return undefined;
|
31
|
+
}
|
32
|
+
return Object.entries(value[variantKey]).flat();
|
33
|
+
}).filter(Boolean);
|
34
|
+
const parsedStyles = Object.fromEntries(entries.map(_ref2 => {
|
35
|
+
let [key, value] = _ref2;
|
25
36
|
const hasNestedProperties = key === 'shadowOffset' || key === 'textShadowOffset';
|
26
37
|
if (hasNestedProperties) {
|
27
38
|
return [key, parseStyle(value, breakpoint, screenSize, variant)];
|
@@ -35,7 +46,7 @@ const parseStyle = (style, breakpoint, screenSize, variant) => {
|
|
35
46
|
if (isDynamicFunction || isValidStyle) {
|
36
47
|
return [key, value];
|
37
48
|
}
|
38
|
-
return [key, (0, _breakpoints.
|
49
|
+
return [key, (0, _breakpoints.getValueForBreakpoint)(value)];
|
39
50
|
}));
|
40
51
|
return _common.isWeb ? (0, _normalizeStyles.normalizeStyles)(parsedStyles) : parsedStyles;
|
41
52
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_breakpoints","require","_normalizeStyles","_common","proxifyFunction","fn","breakpoint","screenSize","variant","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","isPlatformColor","value","isIOS","semantic","isAndroid","resource_paths","style","entries","Object","
|
1
|
+
{"version":3,"names":["_breakpoints","require","_normalizeStyles","_common","_variants","proxifyFunction","fn","breakpoint","screenSize","variant","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","isPlatformColor","value","isIOS","semantic","isAndroid","resource_paths","style","entries","Object","map","_ref","key","variantKey","getKeyForVariant","undefined","flat","filter","Boolean","parsedStyles","fromEntries","_ref2","hasNestedProperties","isTransform","Array","isArray","isDynamicFunction","isValidStyle","getValueForBreakpoint","isWeb","normalizeStyles"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAAE,OAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA+C,EAC7DC,UAAsB,EACtBC,OAAgB,KACL,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO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GAAAmB,KAAA;IACd,MAAMC,mBAAmB,GAAGV,GAAG,KAAK,cAAc,IAAIA,GAAG,KAAK,kBAAkB;IAEhF,IAAIU,mBAAmB,EAAE;MACrB,OAAO,CACHV,GAAG,EACHb,UAAU,CAACG,KAAK,EAA0BX,UAAU,EAAEC,UAAU,EAAEC,OAAO,CAAC,CAC7E;IACL;IAEA,MAAM8B,WAAW,GAAGX,GAAG,KAAK,WAAW;IAEvC,IAAIW,WAAW,IAAIC,KAAK,CAACC,OAAO,CAACvB,KAAK,CAAC,EAAE;MACrC,OAAO,CACHU,GAAG,EACHV,KAAK,CAACQ,GAAG,CAACR,KAAK,IAAIH,UAAU,CAACG,KAAK,EAAEX,UAAU,EAAEC,UAAU,EAAEC,OAAO,CAAC,CAAC,CACzE;IACL;IAEA,MAAMiC,iBAAiB,GAAG,OAAOxB,KAAK,KAAK,UAAU;IACrD,MAAMyB,YAAY,GAAG,OAAOzB,KAAK,KAAK,QAAQ,IAAID,eAAe,CAACC,KAAK,CAAC;IAExE,IAAIwB,iBAAiB,IAAIC,YAAY,EAAE;MACnC,OAAO,CAACf,GAAG,EAAEV,KAAK,CAAC;IACvB;IAEA,OAAO,CACHU,GAAG,EACH,IAAAgB,kCAAqB,EAAC1B,KAAoB,CAAC,CAC9C;EACL,CAAC,CACL,CAAC;EAEL,OAAO2B,aAAK,GACN,IAAAC,gCAAe,EAACX,YAAY,CAAC,GAC7BA,YAAY;AACtB,CAAC;AAAAnB,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
|
@@ -5,13 +5,10 @@ Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
});
|
6
6
|
exports.getKeyForVariant = void 0;
|
7
7
|
const getKeyForVariant = (value, variant) => {
|
8
|
-
if (
|
9
|
-
return undefined;
|
10
|
-
}
|
11
|
-
if (variant && variant in value.variants) {
|
8
|
+
if (variant && variant in value) {
|
12
9
|
return variant;
|
13
10
|
}
|
14
|
-
if ('default' in value
|
11
|
+
if ('default' in value) {
|
15
12
|
return 'default';
|
16
13
|
}
|
17
14
|
return undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["getKeyForVariant","value","variant","
|
1
|
+
{"version":3,"names":["getKeyForVariant","value","variant","undefined","exports"],"sourceRoot":"../../../src","sources":["utils/variants.ts"],"mappings":";;;;;;AAEO,MAAMA,gBAAgB,GAAGA,CAACC,KAAkB,EAAEC,OAAgB,KAAuB;EACxF,IAAIA,OAAO,IAAIA,OAAO,IAAID,KAAK,EAAE;IAC7B,OAAOC,OAAO;EAClB;EAEA,IAAI,SAAS,IAAID,KAAK,EAAE;IACpB,OAAO,SAAS;EACpB;EAEA,OAAOE,SAAS;AACpB,CAAC;AAAAC,OAAA,CAAAJ,gBAAA,GAAAA,gBAAA"}
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/variants.ts"],"mappings":""}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","useUnistyles","useStyles","stylesheet","variant","theme","layout","screenSize","breakpoint","styles","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","create"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,EAAEC,eAAe,QAAQ,SAAS;
|
1
|
+
{"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","useUnistyles","useStyles","stylesheet","variant","theme","layout","screenSize","breakpoint","styles","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","create"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,EAAEC,eAAe,QAAQ,SAAS;AAQrD,SAASC,YAAY,QAAQ,SAAS;AAStC,OAAO,M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core';
|
|
2
2
|
import { isMobile, Orientation, throwError } from './common';
|
3
3
|
import { ScreenOrientation } from '../common';
|
4
4
|
import { getKeyForUnistylesMediaQuery } from './mqParser';
|
5
|
-
import { getKeyForVariant } from './variants';
|
6
5
|
export const sortAndValidateBreakpoints = breakpoints => {
|
7
6
|
const sortedPairs = Object.entries(breakpoints).sort((breakpoint1, breakpoint2) => {
|
8
7
|
const [, value1] = breakpoint1;
|
@@ -32,16 +31,8 @@ export const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
|
|
32
31
|
});
|
33
32
|
return key;
|
34
33
|
};
|
35
|
-
|
36
|
-
//
|
37
|
-
export const getValueForNestedStyle = (value, variant) => {
|
38
|
-
// the highest priority is for variants
|
39
|
-
const variantKey = getKeyForVariant(value, variant);
|
40
|
-
if (variantKey) {
|
41
|
-
return value.variants[variantKey];
|
42
|
-
}
|
43
|
-
|
44
|
-
// then custom media queries
|
34
|
+
export const getValueForBreakpoint = value => {
|
35
|
+
// the highest priority is for custom media queries
|
45
36
|
const customMediaQueryKey = getKeyForUnistylesMediaQuery(Object.entries(value), unistyles.runtime.screen);
|
46
37
|
if (customMediaQueryKey) {
|
47
38
|
return value[customMediaQueryKey];
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["unistyles","isMobile","Orientation","throwError","ScreenOrientation","getKeyForUnistylesMediaQuery","
|
1
|
+
{"version":3,"names":["unistyles","isMobile","Orientation","throwError","ScreenOrientation","getKeyForUnistylesMediaQuery","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","length","Set","size","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","customMediaQueryKey","runtime","screen","hasBreakpoints","Landscape","Portrait","orientation","breakpoint","undefined","directBreakpoint","breakpointPairs","currentBreakpoint","findIndex","_ref2","availableBreakpoints","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AAS,CAACsC,OAAO,CAACtB,iBAAiB;EAC3D,MAAMgC,iBAAiB,GAAGD,eAAe,CACpCE,SAAS,CAACC,KAAA;IAAA,IAAC,CAACtB,GAAG,CAAC,GAAAsB,KAAA;IAAA,OAAKtB,GAAG,KAAKgB,UAAU;EAAA,EAAC;EAE7C,MAAMO,oBAAoB,GAAGJ,eAAe,CACvCK,MAAM,CAAC,CAAAC,KAAA,EAAQtB,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAAyB,KAAA;IAAA,OAAYtB,KAAK,GAAGiB,iBAAiB,IAAIpB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1EqB,GAAG,CAACC,KAAA;IAAA,IAAC,CAAC3B,GAAG,CAAC,GAAA2B,KAAA;IAAA,OAAK3B,GAAG;EAAA,EAAC;EAExB,OAAOmB,eAAe,CAACzB,MAAM,GAAG,CAAC,GAC3BW,KAAK,CAACkB,oBAAoB,CAACA,oBAAoB,CAAC7B,MAAM,GAAG,CAAC,CAAC,CAAwC,GACnGuB,SAAS;AACnB,CAAC"}
|
@@ -3,7 +3,7 @@ export * from './normalizer';
|
|
3
3
|
export { mq, MQSymbol } from './mq';
|
4
4
|
export { getKeyForVariant } from './variants';
|
5
5
|
export { getKeyForUnistylesMediaQuery } from './mqParser';
|
6
|
-
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints,
|
6
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
|
7
7
|
export { proxifyFunction, parseStyle } from './styles';
|
8
8
|
export { isServer, Orientation } from './common';
|
9
9
|
//# sourceMappingURL=index.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["normalizeStyles","mq","MQSymbol","getKeyForVariant","getKeyForUnistylesMediaQuery","getBreakpointFromScreenWidth","sortAndValidateBreakpoints","
|
1
|
+
{"version":3,"names":["normalizeStyles","mq","MQSymbol","getKeyForVariant","getKeyForUnistylesMediaQuery","getBreakpointFromScreenWidth","sortAndValidateBreakpoints","getValueForBreakpoint","proxifyFunction","parseStyle","isServer","Orientation"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,cAAc,cAAc;AAC5B,SAASC,EAAE,EAAEC,QAAQ,QAAQ,MAAM;AACnC,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,4BAA4B,QAAQ,YAAY;AACzD,SAASC,4BAA4B,EAAEC,0BAA0B,EAAEC,qBAAqB,QAAQ,eAAe;AAC/G,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SAASC,QAAQ,EAAEC,WAAW,QAAQ,UAAU"}
|
@@ -1,6 +1,7 @@
|
|
1
|
-
import {
|
1
|
+
import { getValueForBreakpoint } from './breakpoints';
|
2
2
|
import { normalizeStyles } from './normalizeStyles';
|
3
3
|
import { isAndroid, isIOS, isWeb } from './common';
|
4
|
+
import { getKeyForVariant } from './variants';
|
4
5
|
export const proxifyFunction = (fn, breakpoint, screenSize, variant) => new Proxy(fn, {
|
5
6
|
apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, variant)
|
6
7
|
});
|
@@ -11,9 +12,19 @@ export const isPlatformColor = value => {
|
|
11
12
|
return isAndroid && 'resource_paths' in value && typeof value.resource_paths === 'object';
|
12
13
|
};
|
13
14
|
export const parseStyle = (style, breakpoint, screenSize, variant) => {
|
14
|
-
const entries = Object.entries(style || {})
|
15
|
-
const parsedStyles = Object.fromEntries(entries.map(_ref => {
|
15
|
+
const entries = Object.entries(style || {}).map(_ref => {
|
16
16
|
let [key, value] = _ref;
|
17
|
+
if (key !== 'variants') {
|
18
|
+
return [key, value];
|
19
|
+
}
|
20
|
+
const variantKey = getKeyForVariant(value, variant);
|
21
|
+
if (!variantKey) {
|
22
|
+
return undefined;
|
23
|
+
}
|
24
|
+
return Object.entries(value[variantKey]).flat();
|
25
|
+
}).filter(Boolean);
|
26
|
+
const parsedStyles = Object.fromEntries(entries.map(_ref2 => {
|
27
|
+
let [key, value] = _ref2;
|
17
28
|
const hasNestedProperties = key === 'shadowOffset' || key === 'textShadowOffset';
|
18
29
|
if (hasNestedProperties) {
|
19
30
|
return [key, parseStyle(value, breakpoint, screenSize, variant)];
|
@@ -27,7 +38,7 @@ export const parseStyle = (style, breakpoint, screenSize, variant) => {
|
|
27
38
|
if (isDynamicFunction || isValidStyle) {
|
28
39
|
return [key, value];
|
29
40
|
}
|
30
|
-
return [key,
|
41
|
+
return [key, getValueForBreakpoint(value)];
|
31
42
|
}));
|
32
43
|
return isWeb ? normalizeStyles(parsedStyles) : parsedStyles;
|
33
44
|
};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["
|
1
|
+
{"version":3,"names":["getValueForBreakpoint","normalizeStyles","isAndroid","isIOS","isWeb","getKeyForVariant","proxifyFunction","fn","breakpoint","screenSize","variant","Proxy","apply","target","thisArg","argumentsList","parseStyle","isPlatformColor","value","semantic","resource_paths","style","entries","Object","map","_ref","key","variantKey","undefined","flat","filter","Boolean","parsedStyles","fromEntries","_ref2","hasNestedProperties","isTransform","Array","isArray","isDynamicFunction","isValidStyle"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":"AACA,SAASA,qBAAqB,QAAQ,eAAe;AACrD,SAASC,eAAe,QAAQ,mBAAmB;AAEnD,SAASC,SAAS,EAAEC,KAAK,EAAEC,KAAK,QAAQ,UAAU;AAClD,SAASC,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA+C,EAC7DC,UAAsB,EACtBC,OAAgB,KACL,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEP,UAAU,EAAEC,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U,EAAEC,UAAU,EAAEC,OAAO,CAAC,CAC7E;IACL;IAEA,MAAM0B,WAAW,GAAGV,GAAG,KAAK,WAAW;IAEvC,IAAIU,WAAW,IAAIC,KAAK,CAACC,OAAO,CAACpB,KAAK,CAAC,EAAE;MACrC,OAAO,CACHQ,GAAG,EACHR,KAAK,CAACM,GAAG,CAACN,KAAK,IAAIF,UAAU,CAACE,KAAK,EAAEV,UAAU,EAAEC,UAAU,EAAEC,OAAO,CAAC,CAAC,CACzE;IACL;IAEA,MAAM6B,iBAAiB,GAAG,OAAOrB,KAAK,KAAK,UAAU;IACrD,MAAMsB,YAAY,GAAG,OAAOtB,KAAK,KAAK,QAAQ,IAAID,eAAe,CAACC,KAAK,CAAC;IAExE,IAAIqB,iBAAiB,IAAIC,YAAY,EAAE;MACnC,OAAO,CAACd,GAAG,EAAER,KAAK,CAAC;IACvB;IAEA,OAAO,CACHQ,GAAG,EACH1B,qBAAqB,CAACkB,KAAoB,CAAC,CAC9C;EACL,CAAC,CACL,CAAC;EAEL,OAAOd,KAAK,GACNH,eAAe,CAAC+B,YAAY,CAAC,GAC7BA,YAAY;AACtB,CAAC"}
|
@@ -1,11 +1,8 @@
|
|
1
1
|
export const getKeyForVariant = (value, variant) => {
|
2
|
-
if (
|
3
|
-
return undefined;
|
4
|
-
}
|
5
|
-
if (variant && variant in value.variants) {
|
2
|
+
if (variant && variant in value) {
|
6
3
|
return variant;
|
7
4
|
}
|
8
|
-
if ('default' in value
|
5
|
+
if ('default' in value) {
|
9
6
|
return 'default';
|
10
7
|
}
|
11
8
|
return undefined;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["getKeyForVariant","value","variant","
|
1
|
+
{"version":3,"names":["getKeyForVariant","value","variant","undefined"],"sourceRoot":"../../../src","sources":["utils/variants.ts"],"mappings":"AAEA,OAAO,MAAMA,gBAAgB,GAAGA,CAACC,KAAkB,EAAEC,OAAgB,KAAuB;EACxF,IAAIA,OAAO,IAAIA,OAAO,IAAID,KAAK,EAAE;IAC7B,OAAOC,OAAO;EAClB;EAEA,IAAI,SAAS,IAAID,KAAK,EAAE;IACpB,OAAO,SAAS;EACpB;EAEA,OAAOE,SAAS;AACpB,CAAC"}
|
@@ -1,15 +1,14 @@
|
|
1
1
|
import type { OpaqueColorValue } from 'react-native';
|
2
2
|
import type { UnistylesBreakpoints } from '../global';
|
3
3
|
import type { MediaQuery } from './mq';
|
4
|
-
import type { VariantValue } from './core';
|
5
4
|
type WithEmptyObject<V> = keyof V extends never ? {} : V;
|
6
5
|
type ExtractBreakpoints<T> = T extends Partial<Record<keyof UnistylesBreakpoints & string, infer V>> ? WithEmptyObject<V> : T extends (...args: infer A) => infer R ? (...args: A) => ExtractBreakpoints<R> : {
|
7
6
|
[K in keyof T]: T[K] extends (...args: infer A) => infer R ? (...args: A) => ExtractBreakpoints<R> : T[K] extends object ? ExtractBreakpoints<T[K]> : T[K];
|
8
7
|
};
|
9
|
-
type
|
8
|
+
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never;
|
10
9
|
type RemoveKeysWithPrefix<T> = T extends (...args: Array<any>) => infer R ? (...args: Parameters<T>) => RemoveKeysWithPrefix<R> : T extends object ? T extends OpaqueColorValue ? string : T extends Record<string, infer _V> ? T extends {
|
11
|
-
variants:
|
12
|
-
} ?
|
10
|
+
variants: infer _V;
|
11
|
+
} ? Omit<T, 'variants'> & UnionToIntersection<_V[keyof _V]> : {
|
13
12
|
[K in keyof T as K extends MediaQuery ? keyof UnistylesBreakpoints & string : K]: RemoveKeysWithPrefix<T[K]>;
|
14
13
|
} : {
|
15
14
|
[K in keyof T]: RemoveKeysWithPrefix<T[K]>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/types/breakpoints.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AACpD,OAAO,KAAK,EAAE,oB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AI,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;AAEvF,KAAK,oBAAoB,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,KAAK,CAAC,GAAG,CAAC,KAAK,MAAM,CAAC,GACnE,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,oBAAoB,CAAC,CAAC,CAAC,GACnD,CAAC,SAAS,MAAM,GACZ,CAAC,SAAS,gBAAgB,GACtB,MAAM,GACN,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,GAC9B,CAAC,SAAS;IAAE,QAAQ,EAAE,MAAM,EAAE,CAAA;CAAE,GAC5B,IAAI,CAAC,CAAC,EAAE,UAAU,CAAC,GAAG,mBAAmB,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,CAAC,GACvD;KAAG,CAAC,IAAI,MAAM,CAAC,IAAI,CAAC,SAAS,UAAU,GAAG,MAAM,oBAAoB,GAAG,MAAM,GAAG,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACpH;KAAG,CAAC,IAAI,MAAM,CAAC,GAAG,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAAE,GACtD,CAAC,CAAA;AAEX,MAAM,MAAM,qBAAqB,CAAC,CAAC,IAAI,kBAAkB,CAAC,oBAAoB,CAAC,CAAC,CAAC,CAAC,CAAA"}
|
@@ -15,15 +15,12 @@ type UnistyleNested = {
|
|
15
15
|
shadowOffset?: DeepUniStyle<ShadowOffset>;
|
16
16
|
textShadowOffset?: DeepUniStyle<ShadowOffset>;
|
17
17
|
transform?: Array<DeepUniStyle<TransformStyles>>;
|
18
|
+
variants?: Record<string, UnistyleView | UnistyleText | UnistyleImage & Omit<UnistyleNested, 'variants'>>;
|
18
19
|
};
|
19
20
|
type UniStyle<V> = {
|
20
21
|
[innerKey in keyof UnistylesBreakpoints]?: V;
|
21
22
|
} | {
|
22
23
|
[innerKey in MediaQuery]: V;
|
23
|
-
} | {
|
24
|
-
[innerKey in 'variants']?: {
|
25
|
-
[variant: string]: V;
|
26
|
-
};
|
27
24
|
};
|
28
25
|
type DeepUniStyle<T> = {
|
29
26
|
[K in keyof T]?: UniStyle<T[K]> | T[K];
|
@@ -37,11 +34,8 @@ export type CustomNamedStyles<T> = {
|
|
37
34
|
[K in keyof T]: T[K] extends (...args: infer A) => StaticStyles ? (...args: A) => StaticStyles : StaticStyles;
|
38
35
|
};
|
39
36
|
export type RNValue = number | string | undefined;
|
40
|
-
export type
|
41
|
-
export type
|
42
|
-
variants: VariantValue;
|
43
|
-
};
|
44
|
-
export type NestedStylePairs = Array<[keyof UnistylesBreakpoints | MediaQuery | 'variants', RNValue | VariantValue]>;
|
37
|
+
export type NestedStyle = Record<keyof UnistylesBreakpoints | MediaQuery, RNValue>;
|
38
|
+
export type NestedStylePairs = Array<[keyof UnistylesBreakpoints | MediaQuery, RNValue]>;
|
45
39
|
export type UnistylesTheme = UnistylesThemes[keyof UnistylesThemes];
|
46
40
|
export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST;
|
47
41
|
export {};
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../src/types/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,mDAAmD,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEtC,KAAK,YAAY,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,KAAK,eAAe,GACd,mBAAmB,GACnB,eAAe,GACf,gBAAgB,GAChB,gBAAgB,GAChB,gBAAgB,GAChB,cAAc,GACd,eAAe,GACf,eAAe,GACf,mBAAmB,GACnB,mBAAmB,GACnB,cAAc,GACd,cAAc,GACd,eAAe,CAAA;AAErB,KAAK,cAAc,GAAG;IAClB,YAAY,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAC1C,gBAAgB,CAAC,EAAE,YAAY,CAAC,YAAY,CAAC,CAAC;IAC9C,SAAS,CAAC,EAAE,KAAK,CAAC,YAAY,CAAC,eAAe,CAAC,CAAC,CAAA;
|
1
|
+
{"version":3,"file":"core.d.ts","sourceRoot":"","sources":["../../../../src/types/core.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACR,eAAe,EACf,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,gBAAgB,EAChB,gBAAgB,EAChB,cAAc,EACd,eAAe,EACf,eAAe,EACf,cAAc,EACd,cAAc,EACd,mBAAmB,EACnB,mBAAmB,EACtB,MAAM,mDAAmD,CAAA;AAC1D,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAA;AACpE,OAAO,KAAK,EAAE,oBAAoB,EAAE,eAAe,EAAE,MAAM,WAAW,CAAA;AACtE,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AAEtC,KAAK,YAAY,GAAG;IAChB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAA;CACjB,CAAA;AAED,MAAM,MAAM,UAAU,GAAG;IACrB,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAA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AY,GAClB,YAAY,GACZ,YAAY,GACZ,aAAa,GACb,cAAc,CAAA;AAEpB,MAAM,MAAM,iBAAiB,CAAC,CAAC,IAAI;KAC9B,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,MAAM,CAAC,KAAK,YAAY,GACzD,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,YAAY,GAC5B,YAAY;CACrB,CAAA;AAED,MAAM,MAAM,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAA;AACjD,MAAM,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,oBAAoB,GAAG,UAAU,EAAE,OAAO,CAAC,CAAA;AAClF,MAAM,MAAM,gBAAgB,GAAG,KAAK,CAAC,CAAC,MAAM,oBAAoB,GAAG,UAAU,EAAE,OAAO,CAAC,CAAC,CAAA;AACxF,MAAM,MAAM,cAAc,GAAG,eAAe,CAAC,MAAM,eAAe,CAAC,CAAA;AACnE,MAAM,MAAM,mBAAmB,CAAC,EAAE,EAAE,KAAK,IAAI,CAAC,KAAK,EAAE,KAAK,KAAK,EAAE,CAAA"}
|
@@ -4,4 +4,5 @@ export type { Optional, Nullable } from './common';
|
|
4
4
|
export type { MediaQuery } from './mq';
|
5
5
|
export type { CustomNamedStyles, NestedStylePairs, UnistylesTheme, CreateStylesFactory, ScreenSize, NestedStyle, RNValue } from './core';
|
6
6
|
export type { ReactNativeStyleSheet } from './breakpoints';
|
7
|
+
export type { ExtractVariantNames } from './variants';
|
7
8
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAClD,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACtC,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,mBAAmB,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACxI,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/types/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,YAAY,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAA;AAClD,YAAY,EAAE,UAAU,EAAE,MAAM,MAAM,CAAA;AACtC,YAAY,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,cAAc,EAAE,mBAAmB,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AACxI,YAAY,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC1D,YAAY,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAA"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
export type ExtractVariantNames<T> = T extends object ? {
|
2
|
+
[K in keyof T]: T[K] extends {
|
3
|
+
variants: infer V;
|
4
|
+
} ? V extends object ? {
|
5
|
+
[VK in keyof V]: VK extends 'default' ? never : VK;
|
6
|
+
}[keyof V] | ExtractVariantNames<V> : never : ExtractVariantNames<T[K]>;
|
7
|
+
}[keyof T] : never;
|
8
|
+
//# sourceMappingURL=variants.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/types/variants.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,mBAAmB,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GAC/C;KACG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS;QAAE,QAAQ,EAAE,MAAM,CAAC,CAAA;KAAE,GAC5C,CAAC,SAAS,MAAM,GACX;SAAG,EAAE,IAAI,MAAM,CAAC,GAAG,EAAE,SAAS,SAAS,GACpC,KAAK,GAAG,EAAE;KAAE,CAAC,MAAM,CAAC,CAAC,GAAG,mBAAmB,CAAC,CAAC,CAAC,GAClD,KAAK,GACT,mBAAmB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAClC,CAAC,MAAM,CAAC,CAAC,GACR,KAAK,CAAA"}
|
@@ -1,10 +1,10 @@
|
|
1
|
-
import type { CreateStylesFactory, CustomNamedStyles, ReactNativeStyleSheet, UnistylesTheme } from './types';
|
1
|
+
import type { CreateStylesFactory, CustomNamedStyles, ExtractVariantNames, ReactNativeStyleSheet, UnistylesTheme } from './types';
|
2
2
|
import type { UnistylesBreakpoints } from './global';
|
3
3
|
type ParsedStylesheet<ST extends CustomNamedStyles<ST>> = {
|
4
4
|
theme: UnistylesTheme;
|
5
5
|
breakpoint: keyof UnistylesBreakpoints;
|
6
6
|
styles: ReactNativeStyleSheet<ST>;
|
7
7
|
};
|
8
|
-
export declare const useStyles: <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, never> | undefined, variant?: string) => ParsedStylesheet<ST>;
|
8
|
+
export declare const useStyles: <ST extends CustomNamedStyles<ST>>(stylesheet?: ST | CreateStylesFactory<ST, never> | undefined, variant?: (ExtractVariantNames<ST> & string) | undefined) => ParsedStylesheet<ST>;
|
9
9
|
export {};
|
10
10
|
//# sourceMappingURL=useStyles.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,
|
1
|
+
{"version":3,"file":"useStyles.d.ts","sourceRoot":"","sources":["../../../src/useStyles.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACR,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,EACnB,qBAAqB,EACrB,cAAc,EACjB,MAAM,SAAS,CAAA;AAEhB,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,UAAU,CAAA;AAEpD,KAAK,gBAAgB,CAAC,EAAE,SAAS,iBAAiB,CAAC,EAAE,CAAC,IAAI;IACtD,KAAK,EAAE,cAAc,CAAC;IACtB,UAAU,EAAE,MAAM,oBAAoB,CAAC;IACvC,MAAM,EAAE,qBAAqB,CAAC,EAAE,CAAC,CAAA;CACpC,CAAA;AAED,eAAO,MAAM,SAAS,oLA0CrB,CAAA"}
|
@@ -2,5 +2,5 @@ import type { NestedStyle, RNValue } from '../types';
|
|
2
2
|
import type { UnistylesBreakpoints } from '../global';
|
3
3
|
export declare const sortAndValidateBreakpoints: (breakpoints: UnistylesBreakpoints) => UnistylesBreakpoints;
|
4
4
|
export declare const getBreakpointFromScreenWidth: (width: number, breakpointEntries: Array<[keyof UnistylesBreakpoints, UnistylesBreakpoints[keyof UnistylesBreakpoints]]>) => keyof UnistylesBreakpoints & string;
|
5
|
-
export declare const
|
5
|
+
export declare const getValueForBreakpoint: (value: NestedStyle) => RNValue;
|
6
6
|
//# sourceMappingURL=breakpoints.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAoB,OAAO,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;
|
1
|
+
{"version":3,"file":"breakpoints.d.ts","sourceRoot":"","sources":["../../../../src/utils/breakpoints.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAoB,OAAO,EAAE,MAAM,UAAU,CAAA;AACtE,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAIrD,eAAO,MAAM,0BAA0B,gBAAiB,oBAAoB,KAAG,oBAuB9E,CAAA;AAED,eAAO,MAAM,4BAA4B,UAAW,MAAM,qBAAqB,MAAM,CAAC,MAAM,oBAAoB,EAAE,oBAAoB,CAAC,MAAM,oBAAoB,CAAC,CAAC,CAAC,KAAG,MAAM,oBAAoB,GAAG,MAcnM,CAAA;AAED,eAAO,MAAM,qBAAqB,UAAW,WAAW,KAAG,OAmD1D,CAAA"}
|
@@ -3,7 +3,7 @@ export * from './normalizer';
|
|
3
3
|
export { mq, MQSymbol } from './mq';
|
4
4
|
export { getKeyForVariant } from './variants';
|
5
5
|
export { getKeyForUnistylesMediaQuery } from './mqParser';
|
6
|
-
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints,
|
6
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
|
7
7
|
export { proxifyFunction, parseStyle } from './styles';
|
8
8
|
export { isServer, Orientation } from './common';
|
9
9
|
//# sourceMappingURL=index.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACnD,cAAc,cAAc,CAAA;AAC5B,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAE,MAAM,MAAM,CAAA;AACnC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAA;AAC7C,OAAO,EAAE,4BAA4B,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,4BAA4B,EAAE,0BAA0B,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAA;AAC/G,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AACtD,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAe,MAAM,UAAU,CAAA;AAG1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;
|
1
|
+
{"version":3,"file":"styles.d.ts","sourceRoot":"","sources":["../../../../src/utils/styles.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,UAAU,EAAe,MAAM,UAAU,CAAA;AAG1E,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAIrD,eAAO,MAAM,eAAe,OACpB,QAAQ,cAAc,MAAM,oBAAoB,GAAG,MAAM,cACjD,UAAU,YACZ,MAAM,KACjB,QAGD,CAAA;AAEF,eAAO,MAAM,eAAe,8BAA6B,OAMxD,CAAA;AAED,eAAO,MAAM,UAAU,+CAEP,MAAM,oBAAoB,GAAG,MAAM,cACnC,UAAU,YACZ,MAAM,MA8DnB,CAAA"}
|
@@ -1,3 +1,3 @@
|
|
1
1
|
import type { Optional, NestedStyle } from '../types';
|
2
|
-
export declare const getKeyForVariant: (value: NestedStyle, variant?: string) => Optional<
|
2
|
+
export declare const getKeyForVariant: (value: NestedStyle, variant?: string) => Optional<string>;
|
3
3
|
//# sourceMappingURL=variants.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/utils/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAErD,eAAO,MAAM,gBAAgB,UAAW,WAAW,YAAY,MAAM,
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/utils/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,UAAU,CAAA;AAErD,eAAO,MAAM,gBAAgB,UAAW,WAAW,YAAY,MAAM,KAAG,SAAS,MAAM,CAUtF,CAAA"}
|
package/package.json
CHANGED
package/src/types/breakpoints.ts
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import type { OpaqueColorValue } from 'react-native'
|
2
2
|
import type { UnistylesBreakpoints } from '../global'
|
3
3
|
import type { MediaQuery } from './mq'
|
4
|
-
import type { VariantValue } from './core'
|
5
4
|
|
6
5
|
type WithEmptyObject<V> = keyof V extends never ? {} : V
|
7
6
|
|
@@ -17,15 +16,17 @@ type ExtractBreakpoints<T> = T extends Partial<Record<keyof UnistylesBreakpoints
|
|
17
16
|
: T[K]
|
18
17
|
}
|
19
18
|
|
20
|
-
type
|
19
|
+
type UnionToIntersection<U> =
|
20
|
+
(U extends any ? (k: U) => void : never) extends ((k: infer I) => void) ? I : never
|
21
|
+
|
21
22
|
type RemoveKeysWithPrefix<T> = T extends (...args: Array<any>) => infer R
|
22
23
|
? (...args: Parameters<T>) => RemoveKeysWithPrefix<R>
|
23
24
|
: T extends object
|
24
25
|
? T extends OpaqueColorValue
|
25
26
|
? string
|
26
27
|
: T extends Record<string, infer _V>
|
27
|
-
? T extends { variants:
|
28
|
-
?
|
28
|
+
? T extends { variants: infer _V }
|
29
|
+
? Omit<T, 'variants'> & UnionToIntersection<_V[keyof _V]>
|
29
30
|
: { [K in keyof T as K extends MediaQuery ? keyof UnistylesBreakpoints & string : K]: RemoveKeysWithPrefix<T[K]> }
|
30
31
|
: { [K in keyof T]: RemoveKeysWithPrefix<T[K]> }
|
31
32
|
: T
|
package/src/types/core.ts
CHANGED
@@ -45,17 +45,14 @@ type TransformStyles =
|
|
45
45
|
type UnistyleNested = {
|
46
46
|
shadowOffset?: DeepUniStyle<ShadowOffset>,
|
47
47
|
textShadowOffset?: DeepUniStyle<ShadowOffset>,
|
48
|
-
transform?: Array<DeepUniStyle<TransformStyles
|
48
|
+
transform?: Array<DeepUniStyle<TransformStyles>>,
|
49
|
+
variants?: Record<string, UnistyleView | UnistyleText | UnistyleImage & Omit<UnistyleNested, 'variants'>>
|
49
50
|
}
|
50
51
|
|
51
52
|
type UniStyle<V> = {
|
52
53
|
[innerKey in keyof UnistylesBreakpoints]?: V
|
53
54
|
} | {
|
54
55
|
[innerKey in MediaQuery]: V
|
55
|
-
} | {
|
56
|
-
[innerKey in 'variants']?: {
|
57
|
-
[variant: string]: V
|
58
|
-
}
|
59
56
|
}
|
60
57
|
|
61
58
|
type DeepUniStyle<T> = {
|
@@ -82,10 +79,7 @@ export type CustomNamedStyles<T> = {
|
|
82
79
|
}
|
83
80
|
|
84
81
|
export type RNValue = number | string | undefined
|
85
|
-
export type
|
86
|
-
export type
|
87
|
-
variants: VariantValue
|
88
|
-
}
|
89
|
-
export type NestedStylePairs = Array<[keyof UnistylesBreakpoints | MediaQuery | 'variants', RNValue | VariantValue]>
|
82
|
+
export type NestedStyle = Record<keyof UnistylesBreakpoints | MediaQuery, RNValue>
|
83
|
+
export type NestedStylePairs = Array<[keyof UnistylesBreakpoints | MediaQuery, RNValue]>
|
90
84
|
export type UnistylesTheme = UnistylesThemes[keyof UnistylesThemes]
|
91
85
|
export type CreateStylesFactory<ST, Theme> = (theme: Theme) => ST
|
package/src/types/index.ts
CHANGED
@@ -4,3 +4,4 @@ export type { Optional, Nullable } from './common'
|
|
4
4
|
export type { MediaQuery } from './mq'
|
5
5
|
export type { CustomNamedStyles, NestedStylePairs, UnistylesTheme, CreateStylesFactory, ScreenSize, NestedStyle, RNValue } from './core'
|
6
6
|
export type { ReactNativeStyleSheet } from './breakpoints'
|
7
|
+
export type { ExtractVariantNames } from './variants'
|
@@ -0,0 +1,11 @@
|
|
1
|
+
export type ExtractVariantNames<T> = T extends object
|
2
|
+
? {
|
3
|
+
[K in keyof T]: T[K] extends { variants: infer V }
|
4
|
+
? V extends object
|
5
|
+
? { [VK in keyof V]: VK extends 'default'
|
6
|
+
? never : VK }[keyof V] | ExtractVariantNames<V>
|
7
|
+
: never
|
8
|
+
: ExtractVariantNames<T[K]>
|
9
|
+
}[keyof T]
|
10
|
+
: never
|
11
|
+
|
package/src/useStyles.ts
CHANGED
@@ -1,7 +1,13 @@
|
|
1
1
|
import { useMemo } from 'react'
|
2
2
|
import { StyleSheet } from 'react-native'
|
3
3
|
import { parseStyle, proxifyFunction } from './utils'
|
4
|
-
import type {
|
4
|
+
import type {
|
5
|
+
CreateStylesFactory,
|
6
|
+
CustomNamedStyles,
|
7
|
+
ExtractVariantNames,
|
8
|
+
ReactNativeStyleSheet,
|
9
|
+
UnistylesTheme
|
10
|
+
} from './types'
|
5
11
|
import { useUnistyles } from './hooks'
|
6
12
|
import type { UnistylesBreakpoints } from './global'
|
7
13
|
|
@@ -13,7 +19,7 @@ type ParsedStylesheet<ST extends CustomNamedStyles<ST>> = {
|
|
13
19
|
|
14
20
|
export const useStyles = <ST extends CustomNamedStyles<ST>>(
|
15
21
|
stylesheet?: ST | CreateStylesFactory<ST, UnistylesTheme>,
|
16
|
-
variant?: string
|
22
|
+
variant?: ExtractVariantNames<typeof stylesheet> & string
|
17
23
|
): ParsedStylesheet<ST> => {
|
18
24
|
const { theme, layout } = useUnistyles()
|
19
25
|
const { screenSize, breakpoint } = layout
|
package/src/utils/breakpoints.ts
CHANGED
@@ -4,7 +4,6 @@ import type { NestedStyle, NestedStylePairs, RNValue } from '../types'
|
|
4
4
|
import type { UnistylesBreakpoints } from '../global'
|
5
5
|
import { ScreenOrientation } from '../common'
|
6
6
|
import { getKeyForUnistylesMediaQuery } from './mqParser'
|
7
|
-
import { getKeyForVariant } from './variants'
|
8
7
|
|
9
8
|
export const sortAndValidateBreakpoints = (breakpoints: UnistylesBreakpoints): UnistylesBreakpoints => {
|
10
9
|
const sortedPairs = Object
|
@@ -47,16 +46,8 @@ export const getBreakpointFromScreenWidth = (width: number, breakpointEntries: A
|
|
47
46
|
return key
|
48
47
|
}
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
// the highest priority is for variants
|
53
|
-
const variantKey = getKeyForVariant(value, variant)
|
54
|
-
|
55
|
-
if (variantKey) {
|
56
|
-
return value.variants[variantKey as string]
|
57
|
-
}
|
58
|
-
|
59
|
-
// then custom media queries
|
49
|
+
export const getValueForBreakpoint = (value: NestedStyle): RNValue => {
|
50
|
+
// the highest priority is for custom media queries
|
60
51
|
const customMediaQueryKey = getKeyForUnistylesMediaQuery(
|
61
52
|
Object.entries(value) as NestedStylePairs,
|
62
53
|
unistyles.runtime.screen
|
package/src/utils/index.ts
CHANGED
@@ -3,6 +3,6 @@ export * from './normalizer'
|
|
3
3
|
export { mq, MQSymbol } from './mq'
|
4
4
|
export { getKeyForVariant } from './variants'
|
5
5
|
export { getKeyForUnistylesMediaQuery } from './mqParser'
|
6
|
-
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints,
|
6
|
+
export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints'
|
7
7
|
export { proxifyFunction, parseStyle } from './styles'
|
8
8
|
export { isServer, Orientation } from './common'
|
package/src/utils/styles.ts
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
import type { CustomNamedStyles, ScreenSize, NestedStyle } from '../types'
|
2
|
-
import {
|
2
|
+
import { getValueForBreakpoint } from './breakpoints'
|
3
3
|
import { normalizeStyles } from './normalizeStyles'
|
4
4
|
import type { UnistylesBreakpoints } from '../global'
|
5
5
|
import { isAndroid, isIOS, isWeb } from './common'
|
6
|
+
import { getKeyForVariant } from './variants'
|
6
7
|
|
7
8
|
export const proxifyFunction = (
|
8
9
|
fn: Function, breakpoint: keyof UnistylesBreakpoints & string,
|
@@ -27,10 +28,27 @@ export const parseStyle = <T>(
|
|
27
28
|
screenSize: ScreenSize,
|
28
29
|
variant?: string
|
29
30
|
): T => {
|
30
|
-
const entries = Object
|
31
|
-
keyof T,
|
32
|
-
|
33
|
-
|
31
|
+
const entries = (Object
|
32
|
+
.entries(style || {}) as Array<[keyof T, CustomNamedStyles<T> | NestedStyle]>)
|
33
|
+
.map(([key, value]) => {
|
34
|
+
if (key !== 'variants') {
|
35
|
+
return [key, value]
|
36
|
+
}
|
37
|
+
|
38
|
+
const variantKey = getKeyForVariant(
|
39
|
+
value as NestedStyle,
|
40
|
+
variant
|
41
|
+
)
|
42
|
+
|
43
|
+
if (!variantKey) {
|
44
|
+
return undefined
|
45
|
+
}
|
46
|
+
|
47
|
+
return Object
|
48
|
+
.entries(value[variantKey as keyof typeof value] as NestedStyle)
|
49
|
+
.flat()
|
50
|
+
})
|
51
|
+
.filter(Boolean) as Array<[keyof T, CustomNamedStyles<T> | NestedStyle]>
|
34
52
|
|
35
53
|
const parsedStyles = Object
|
36
54
|
.fromEntries(entries
|
@@ -62,10 +80,7 @@ export const parseStyle = <T>(
|
|
62
80
|
|
63
81
|
return [
|
64
82
|
key,
|
65
|
-
|
66
|
-
value as NestedStyle,
|
67
|
-
variant
|
68
|
-
)
|
83
|
+
getValueForBreakpoint(value as NestedStyle)
|
69
84
|
]
|
70
85
|
})
|
71
86
|
)
|
package/src/utils/variants.ts
CHANGED
@@ -1,16 +1,12 @@
|
|
1
1
|
import type { Optional, NestedStyle } from '../types'
|
2
2
|
|
3
|
-
export const getKeyForVariant = (value: NestedStyle, variant?: string): Optional<
|
4
|
-
if (
|
5
|
-
return
|
3
|
+
export const getKeyForVariant = (value: NestedStyle, variant?: string): Optional<string> => {
|
4
|
+
if (variant && variant in value) {
|
5
|
+
return variant
|
6
6
|
}
|
7
7
|
|
8
|
-
if (
|
9
|
-
return
|
10
|
-
}
|
11
|
-
|
12
|
-
if ('default' in value.variants) {
|
13
|
-
return 'default' as keyof typeof value
|
8
|
+
if ('default' in value) {
|
9
|
+
return 'default'
|
14
10
|
}
|
15
11
|
|
16
12
|
return undefined
|