react-native-unistyles 3.0.0-alpha.42 → 3.0.0-alpha.43
Sign up to get free protection for your applications and to get access to all the features.
- package/lib/commonjs/components/Pressable.js +23 -5
- package/lib/commonjs/components/Pressable.js.map +1 -1
- package/lib/commonjs/web/create.js +6 -1
- package/lib/commonjs/web/create.js.map +1 -1
- package/lib/commonjs/web/shadowRegistry.js +1 -1
- package/lib/commonjs/web/shadowRegistry.js.map +1 -1
- package/lib/commonjs/web/{variants/getVariants.js → variants.js} +2 -2
- package/lib/commonjs/web/variants.js.map +1 -0
- package/lib/module/components/Pressable.js +23 -5
- package/lib/module/components/Pressable.js.map +1 -1
- package/lib/module/web/create.js +7 -2
- package/lib/module/web/create.js.map +1 -1
- package/lib/module/web/shadowRegistry.js +1 -1
- package/lib/module/web/shadowRegistry.js.map +1 -1
- package/lib/module/web/{variants/getVariants.js → variants.js} +2 -2
- package/lib/module/web/variants.js.map +1 -0
- package/lib/typescript/src/components/Pressable.d.ts.map +1 -1
- package/lib/typescript/src/web/create.d.ts.map +1 -1
- package/lib/typescript/src/web/{variants/getVariants.d.ts → variants.d.ts} +2 -2
- package/lib/typescript/src/web/variants.d.ts.map +1 -0
- package/package.json +1 -1
- package/plugin/ref.js +1 -1
- package/plugin/style.js +204 -95
- package/src/components/Pressable.tsx +34 -5
- package/src/web/create.ts +7 -2
- package/src/web/shadowRegistry.ts +1 -1
- package/src/web/{variants/getVariants.ts → variants.ts} +2 -2
- package/lib/commonjs/web/variants/getVariants.js.map +0 -1
- package/lib/commonjs/web/variants/index.js +0 -28
- package/lib/commonjs/web/variants/index.js.map +0 -1
- package/lib/commonjs/web/variants/useVariants.js +0 -59
- package/lib/commonjs/web/variants/useVariants.js.map +0 -1
- package/lib/module/web/variants/getVariants.js.map +0 -1
- package/lib/module/web/variants/index.js +0 -5
- package/lib/module/web/variants/index.js.map +0 -1
- package/lib/module/web/variants/useVariants.js +0 -54
- package/lib/module/web/variants/useVariants.js.map +0 -1
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +0 -1
- package/lib/typescript/src/web/variants/index.d.ts +0 -3
- package/lib/typescript/src/web/variants/index.d.ts.map +0 -1
- package/lib/typescript/src/web/variants/useVariants.d.ts +0 -3
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +0 -1
- package/src/web/variants/index.ts +0 -2
- package/src/web/variants/useVariants.ts +0 -65
@@ -27,14 +27,22 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
27
27
|
}) : style;
|
28
28
|
const fnArgs = typeof styleResult === 'function'
|
29
29
|
// @ts-expect-error - this is hidden from TS
|
30
|
-
? styleResult.getBoundArgs() :
|
30
|
+
? styleResult.getBoundArgs() : Array.isArray(styleResult) ? styleResult
|
31
|
+
// @ts-expect-error - this is hidden from TS
|
32
|
+
.map(style => typeof style === 'function' ? style.getBoundArgs() : []) : [];
|
31
33
|
if (typeof passedRef === 'object' && passedRef !== null) {
|
32
34
|
passedRef.current = ref;
|
33
35
|
}
|
34
36
|
const returnFn = typeof passedRef === 'function' ? passedRef(ref) : () => {};
|
37
|
+
const unistyles = (rawStyle ?? []).map((style, index) => {
|
38
|
+
if (fnArgs[index]) {
|
39
|
+
return style;
|
40
|
+
}
|
41
|
+
return undefined;
|
42
|
+
}).filter(Boolean);
|
35
43
|
|
36
44
|
// @ts-expect-error - this is hidden from TS
|
37
|
-
_specs.UnistylesShadowRegistry.add(ref,
|
45
|
+
_specs.UnistylesShadowRegistry.add(ref, unistyles, variants, [...fnArgs]);
|
38
46
|
return () => {
|
39
47
|
// @ts-expect-error - this is hidden from TS
|
40
48
|
_specs.UnistylesShadowRegistry.remove(ref);
|
@@ -47,17 +55,27 @@ const Pressable = exports.Pressable = /*#__PURE__*/(0, _react.forwardRef)(({
|
|
47
55
|
const styleResult = typeof style === 'function' ? style(state) : style;
|
48
56
|
const fnArgs = typeof styleResult === 'function'
|
49
57
|
// @ts-expect-error - this is hidden from TS
|
50
|
-
? styleResult.getBoundArgs() :
|
58
|
+
? styleResult.getBoundArgs() : Array.isArray(styleResult) ? styleResult
|
59
|
+
// @ts-expect-error - this is hidden from TS
|
60
|
+
.map(style => typeof style === 'function' ? style.getBoundArgs() : []) : [];
|
51
61
|
const pressId = (0, _core.getId)();
|
62
|
+
const unistyles = (rawStyle ?? []).map((style, index) => {
|
63
|
+
if (fnArgs[index]) {
|
64
|
+
return style;
|
65
|
+
}
|
66
|
+
return undefined;
|
67
|
+
}).filter(Boolean);
|
52
68
|
if (storedRef.current) {
|
53
69
|
// @ts-expect-error - this is hidden from TS
|
54
70
|
_specs.UnistylesShadowRegistry.remove(storedRef.current);
|
55
71
|
// @ts-expect-error - this is hidden from TS
|
56
|
-
_specs.UnistylesShadowRegistry.add(storedRef.current,
|
72
|
+
_specs.UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, [...fnArgs], pressId);
|
57
73
|
}
|
58
74
|
return typeof styleResult === 'function'
|
59
75
|
// @ts-expect-error - this is hidden from TS
|
60
|
-
? styleResult(pressId) : styleResult
|
76
|
+
? styleResult(pressId) : Array.isArray(styleResult)
|
77
|
+
// @ts-expect-error - this is hidden from TS
|
78
|
+
? styleResult.map(style => typeof style === 'function' ? style(pressId) : style) : styleResult;
|
61
79
|
}
|
62
80
|
});
|
63
81
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_core","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Pressable","exports","forwardRef","variants","style","rawStyle","props","passedRef","storedRef","useRef","jsx","ref","current","styleResult","pressed","fnArgs","getBoundArgs","returnFn","UnistylesShadowRegistry","add","remove","state","pressId","getId"],"sourceRoot":"../../../src","sources":["components/Pressable.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,M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B,CAAC;EAAEC,QAAQ;EAAEC,KAAK;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,SAAS,KAAK;EAC9G,MAAMC,SAAS,GAAG,IAAAC,aAAM,EAAc,CAAC;EAEvC,oBACI,IAAA9B,WAAA,CAAA+B,GAAA,EAAClC,YAAA,CAAAwB,SAA0B;IAAA,GACnBM,KAAK;IACTK,GAAG,EAAEA,GAAG,IAAI;MACRH,SAAS,CAACI,OAAO,GAAGD,GAAG;MACvB,MAAME,WAAW,GAAG,OAAOT,KAAK,KAAK,UAAU,GACzCA,KAAK,CAAC;QAAEU,OAAO,EAAE;MAAM,CAAC,CAAC,GACzBV,KAAK;MACX,MAAMW,MAAM,GAAG,OAAOF,WAAW,KAAK;MAClC;MAAA,EACEA,WAAW,CAACG,YAAY,CAAC,CAAC,
|
1
|
+
{"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_specs","_core","_jsxRuntime","_getRequireWildcardCache","e","WeakMap","r","t","__esModule","default","has","get","n","__proto__","a","Object","defineProperty","getOwnPropertyDescriptor","u","hasOwnProperty","call","i","set","Pressable","exports","forwardRef","variants","style","rawStyle","props","passedRef","storedRef","useRef","jsx","ref","current","styleResult","pressed","fnArgs","getBoundArgs","Array","isArray","map","returnFn","unistyles","index","undefined","filter","Boolean","UnistylesShadowRegistry","add","remove","state","pressId","getId"],"sourceRoot":"../../../src","sources":["components/Pressable.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,KAAA,GAAAH,OAAA;AAA+B,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAK,yBAAAC,CAAA,6BAAAC,OAAA,mBAAAC,CAAA,OAAAD,OAAA,IAAAE,CAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,CAAA,WAAAA,CAAA,GAAAG,CAAA,G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]}
|
@@ -45,7 +45,12 @@ const create = (stylesheet, id) => {
|
|
45
45
|
});
|
46
46
|
|
47
47
|
// Inject useVariants hook to styles
|
48
|
-
|
48
|
+
Object.defineProperty(styles, 'useVariants', {
|
49
|
+
value: variants => {
|
50
|
+
Object.entries(variants).forEach(([key, value]) => selectedVariants.set(key, value));
|
51
|
+
},
|
52
|
+
configurable: false
|
53
|
+
});
|
49
54
|
return styles;
|
50
55
|
};
|
51
56
|
exports.create = create;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_utils","require","_utils2","_runtime","_variants","create","stylesheet","id","error","computedStylesheet","UnistylesRuntime","theme","miniRuntime","selectedVariants","Map","copyVariants","Object","fromEntries","entries","addSecrets","value","key","args","assignSecrets","__uni__key","__uni__refs","Set","__uni__stylesheet","__uni__args","__uni__variants","styles","reduceObject","_key","String","dynamicStyle","result","variants","getVariants","resultWithVariants","deepMergeObjects","getStyles","
|
1
|
+
{"version":3,"names":["_utils","require","_utils2","_runtime","_variants","create","stylesheet","id","error","computedStylesheet","UnistylesRuntime","theme","miniRuntime","selectedVariants","Map","copyVariants","Object","fromEntries","entries","addSecrets","value","key","args","assignSecrets","__uni__key","__uni__refs","Set","__uni__stylesheet","__uni__args","__uni__variants","styles","reduceObject","_key","String","dynamicStyle","result","variants","getVariants","resultWithVariants","deepMergeObjects","getStyles","defineProperty","forEach","set","configurable","exports"],"sourceRoot":"../../../src","sources":["web/create.ts"],"mappings":";;;;;;AAEA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AACA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEO,MAAMI,MAAM,GAAGA,CAACC,UAAiD,EAAEC,EAAW,KAAK;EACtF,IAAI,CAACA,EAAE,EAAE;IACL,MAAM,IAAAC,YAAK,EAAC,uFAAuF,CAAC;EACxG;EAEA,MAAMC,kBAAkB,GAAG,OAAOH,UAAU,KAAK,UAAU,GACrD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AACe,YAAY,EAAEb,GAAG,CAAC;IACxC;;IAEA;IACA,OAAOF,UAAU,CAAC,IAAAqB,gBAAS,EAACpB,KAAK,CAAC,EAAEC,GAAG,CAAC;EAC5C,CAAC,CAAsC;;EAEvC;EACAL,MAAM,CAACyB,cAAc,CAACX,MAAM,EAAE,aAAa,EAAE;IACzCV,KAAK,EAAGgB,QAA0C,IAAK;MACnDpB,MAAM,CAACE,OAAO,CAACkB,QAAQ,CAAC,CAACM,OAAO,CAAC,CAAC,CAACrB,GAAG,EAAED,KAAK,CAAC,KAAKP,gBAAgB,CAAC8B,GAAG,CAACtB,GAAG,EAAED,KAAK,CAAC,CAAC;IACxF,CAAC;IACDwB,YAAY,EAAE;EAClB,CAAC,CAAC;EAEF,OAAOd,MAAM;AACjB,CAAC;AAAAe,OAAA,CAAAxC,MAAA,GAAAA,MAAA","ignoreList":[]}
|
@@ -70,7 +70,7 @@ class UnistylesShadowRegistryBuilder {
|
|
70
70
|
const newComputedStylesheet = _registry.UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
|
71
71
|
const style = newComputedStylesheet[__uni__key];
|
72
72
|
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants;
|
73
|
-
const args = _args[styleIndex] ? _args[styleIndex] : __uni__args;
|
73
|
+
const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args;
|
74
74
|
const result = typeof style === 'function' ? style(...args) : style;
|
75
75
|
const {
|
76
76
|
variantsResult
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["_convert","require","_listener","_registry","_utils","_utils2","_variants2","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","Map","hashMap","classNamesMap","add","ref","_style","_variants","_args","secrets","extractSecrets","forEach","__uni__refs","isInDocument","oldResult","get","delete","UnistylesRegistry","remove","HTMLElement","styles","filter","style","Object","keys","some","key","startsWith","length","parsedStyles","flatMap","styleIndex","map","secret","__uni__key","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","variants","args","result","variantsResult","fromEntries","getVariants","resultWithVariants","deepMergeObjects","dependencies","extractUnistyleDependencies","addDependenciesToStylesheet","UnistylesListener","addListeners","hash","newComputedStyleSheet","newValue","applyStyles","convertUnistyles","combinedStyles","oldStyles","equal","oldClassNames","className","classList","set","existingHash","injectedClassNames","_web","_classNames","newClassNames","Array","isArray","concat","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAIA,MAAMM,8BAA8B,CAAC;EACjC;EACAC,IAAI,GAAG,yBAAyB;EAChCC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAGA,CAAA,KAAM,IAAI;EACnBC,QAAQ,GAAGA,CAAA,KAAM,yBAAyB;EAC1CC,OAAO,GAAGA,CAAA,KAAM,CAAC,CAAC;EAClB;;EAEQC,UAAU,GAAG,IAAIC,GAAG,CAA+B,CAAC;EACpDC,OAAO,GAAG,IAAID,GAAG,CAAsB,CAAC;EACxCE,aAAa,GAAG,IAAIF,GAAG,CAA6B,CAAC;EAE7DG,GAAG,GAAGA,CAACC,GAAQ,EAAEC,MAAoB,EAAEC,SAA0C,EAAEC,KAAwB,KAAK;IAC5G;IACA,IAAI,CAACF,MAAM,EAAE;MACT;IACJ;;IAEA;IACA,IAAID,GAAG,KAAK,IAAI,EAAE;MACd,MAAMI,OAAO,GAAG,IAAAC,sBAAc,EAACJ,MAAM,CAAC;MAEtCG,OAAO,CAACE,OAAO,CAAC,CAAC;QAAEC;MAAY,CAAC,KAAK;QACjCA,WAAW,CAACD,OAAO,CAACN,GAAG,IAAI;UACvB,IAAI,IAAAQ,oBAA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GAAGjC,KAAK,CAACuB,UAAU,CAAC,
|
1
|
+
{"version":3,"names":["_convert","require","_listener","_registry","_utils","_utils2","_variants2","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","Map","hashMap","classNamesMap","add","ref","_style","_variants","_args","secrets","extractSecrets","forEach","__uni__refs","isInDocument","oldResult","get","delete","UnistylesRegistry","remove","HTMLElement","styles","filter","style","Object","keys","some","key","startsWith","length","parsedStyles","flatMap","styleIndex","map","secret","__uni__key","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","variants","args","result","variantsResult","fromEntries","getVariants","resultWithVariants","deepMergeObjects","dependencies","extractUnistyleDependencies","addDependenciesToStylesheet","UnistylesListener","addListeners","hash","newComputedStyleSheet","newValue","applyStyles","convertUnistyles","combinedStyles","oldStyles","equal","oldClassNames","className","classList","set","existingHash","injectedClassNames","_web","_classNames","newClassNames","Array","isArray","concat","UnistylesShadowRegistry","exports"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;;;;;AACA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AACA,IAAAE,SAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AACA,IAAAI,OAAA,GAAAJ,OAAA;AACA,IAAAK,UAAA,GAAAL,OAAA;AAIA,MAAMM,8BAA8B,CAAC;EACjC;EACAC,IAAI,GAAG,yBAAyB;EAChCC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAGA,CAAA,KAAM,IAAI;EACnBC,QAAQ,GAAGA,CAAA,KAAM,yBAAyB;EAC1CC,OAAO,GAAGA,CAAA,KAAM,CAAC,CAAC;EAClB;;EAEQC,UAAU,GAAG,IAAIC,GAAG,CAA+B,CAAC;EACpDC,OAAO,GAAG,IAAID,GAAG,CAAsB,CAAC;EACxCE,aAAa,GAAG,IAAIF,GAAG,CAA6B,CAAC;EAE7DG,GAAG,GAAGA,CAACC,GAAQ,EAA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,GAAG,EAAEqD,cAAc,CAAC;IAExC,MAAM;MAAEL,IAAI;MAAEY;IAAa,CAAC,GAAGhD,2BAAiB,CAACb,GAAG,CAACsD,cAAc,CAAC;IACpE,MAAMQ,kBAAkB,GAAGR,cAAc,EAAES,IAAI,EAAEC,WAAW,IAAI,EAAE;IAClE,MAAMC,aAAa,GAAG,CAACC,KAAK,CAACC,OAAO,CAACL,kBAAkB,CAAC,GAAGA,kBAAkB,GAAG,CAACA,kBAAkB,CAAC,EAAEM,MAAM,CAACnB,IAAI,CAAC;IAElH,IAAI,CAAClD,aAAa,CAAC6D,GAAG,CAAC3D,GAAG,EAAEgE,aAAa,CAAC;IAC1C;IACAhE,GAAG,CAAC0D,SAAS,CAAC3D,GAAG,CAAC,GAAGiE,aAAa,CAAC;;IAEnC;IACA,IAAI,CAACJ,YAAY,EAAE;MACf,IAAI,CAAC/D,OAAO,CAAC8D,GAAG,CAAC3D,GAAG,EAAEgD,IAAI,CAAC;IAC/B;IAEA,OAAOgB,aAAa;EACxB,CAAC;EAEDnD,MAAM,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB;AAEO,MAAMuD,uBAAuB,GAAAC,OAAA,CAAAD,uBAAA,GAAG,IAAI/E,8BAA8B,CAAC,CAAC","ignoreList":[]}
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
5
5
|
});
|
6
6
|
exports.getVariants = void 0;
|
7
|
-
var _utils = require("
|
7
|
+
var _utils = require("../utils");
|
8
8
|
const hasVariants = value => 'variants' in value[1];
|
9
9
|
const getVariants = (styles, selectedVariants) => {
|
10
10
|
return Object.entries(styles).filter(hasVariants).filter(([_key, {
|
@@ -36,4 +36,4 @@ const getVariants = (styles, selectedVariants) => {
|
|
36
36
|
});
|
37
37
|
};
|
38
38
|
exports.getVariants = getVariants;
|
39
|
-
//# sourceMappingURL=
|
39
|
+
//# sourceMappingURL=variants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["_utils","require","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","default","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles","deepMergeObjects","exports"],"sourceRoot":"../../../src","sources":["web/variants.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAQA,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAExH,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EAAEC,gBAAqC,KAAK;EAC7G,OAAOC,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CACxBI,MAAM,CAACP,WAAW,CAAC,CACnBO,MAAM,CAAC,CAAC,CAACC,IAAI,EAAE;IAAEC;EAAS,CAAC,CAAC,KAAKJ,MAAM,CAACK,IAAI,CAACD,QAAQ,CAAC,CAACE,IAAI,CAACC,OAAO,IAAIA,OAAO,IAAIH,QAAQ,CAAC,CAAC,CAC5FI,GAAG,CAAC,CAAC,CAACC,GAAG,EAAE;IAAEL,QAAQ;IAAEM,gBAAgB,GAAG;EAAG,CAAC,CAAC,KAAK;IACjD,MAAMC,aAAa,GAAGX,MAAM,CAACC,OAAO,CAACG,QAAQ,CAAC,CAACQ,OAAO,CAAC,CAAC,CAACL,OAAO,EAAET,MAAM,CAAC,KAAK;MAC1E,MAAMe,eAAe,GAAGd,gBAAgB,CAACQ,OAAO,CAAC;MACjD,MAAMO,qBAAqB,GAAGhB,MAAM,CAACe,eAAe,CAAC,IAAIf,MAAM,CAACiB,OAAO;MAEvE,IAAI,CAACD,qBAAqB,EAAE;QACxB,OAAO,EAAE;MACb;MAEA,OAAOA,qBAAqB;IAChC,CAAC,CAAC;IAEF,MAAME,qBAAqB,GAAGN,gBAAgB,CAACE,OAAO,CAACK,eAAe,IAAI;MACtE,MAAM;QAAEnB,MAAM;QAAE,GAAGoB;MAAW,CAAC,GAAGD,eAAe;MAEjD,IAAIjB,MAAM,CAACC,OAAO,CAACiB,UAAU,CAAC,CAACZ,IAAI,CAAC,CAAC,CAACC,OAAO,EAAEX,KAAK,CAAC,KAAKuB,MAAM,CAACpB,gBAAgB,CAACQ,OAAO,CAAC,CAAC,KAAKY,MAAM,CAACvB,KAAK,CAAC,CAAC,EAAE;QAC5G,OAAO,EAAE;MACb;MAEA,OAAOE,MAAM;IACjB,CAAC,CAAC;IAEF,MAAMsB,mBAAmB,GAAG,IAAAC,uBAAgB,EAAC,GAAGV,aAAa,EAAE,GAAGK,qBAAqB,CAAC;IAExF,OAAO,CAACP,GAAG,EAAEW,mBAAmB,CAAC;EACrC,CAAC,CAAC;AACV,CAAC;AAAAE,OAAA,CAAAzB,WAAA,GAAAA,WAAA","ignoreList":[]}
|
@@ -21,14 +21,22 @@ export const Pressable = /*#__PURE__*/forwardRef(({
|
|
21
21
|
}) : style;
|
22
22
|
const fnArgs = typeof styleResult === 'function'
|
23
23
|
// @ts-expect-error - this is hidden from TS
|
24
|
-
? styleResult.getBoundArgs() :
|
24
|
+
? styleResult.getBoundArgs() : Array.isArray(styleResult) ? styleResult
|
25
|
+
// @ts-expect-error - this is hidden from TS
|
26
|
+
.map(style => typeof style === 'function' ? style.getBoundArgs() : []) : [];
|
25
27
|
if (typeof passedRef === 'object' && passedRef !== null) {
|
26
28
|
passedRef.current = ref;
|
27
29
|
}
|
28
30
|
const returnFn = typeof passedRef === 'function' ? passedRef(ref) : () => {};
|
31
|
+
const unistyles = (rawStyle ?? []).map((style, index) => {
|
32
|
+
if (fnArgs[index]) {
|
33
|
+
return style;
|
34
|
+
}
|
35
|
+
return undefined;
|
36
|
+
}).filter(Boolean);
|
29
37
|
|
30
38
|
// @ts-expect-error - this is hidden from TS
|
31
|
-
UnistylesShadowRegistry.add(ref,
|
39
|
+
UnistylesShadowRegistry.add(ref, unistyles, variants, [...fnArgs]);
|
32
40
|
return () => {
|
33
41
|
// @ts-expect-error - this is hidden from TS
|
34
42
|
UnistylesShadowRegistry.remove(ref);
|
@@ -41,17 +49,27 @@ export const Pressable = /*#__PURE__*/forwardRef(({
|
|
41
49
|
const styleResult = typeof style === 'function' ? style(state) : style;
|
42
50
|
const fnArgs = typeof styleResult === 'function'
|
43
51
|
// @ts-expect-error - this is hidden from TS
|
44
|
-
? styleResult.getBoundArgs() :
|
52
|
+
? styleResult.getBoundArgs() : Array.isArray(styleResult) ? styleResult
|
53
|
+
// @ts-expect-error - this is hidden from TS
|
54
|
+
.map(style => typeof style === 'function' ? style.getBoundArgs() : []) : [];
|
45
55
|
const pressId = getId();
|
56
|
+
const unistyles = (rawStyle ?? []).map((style, index) => {
|
57
|
+
if (fnArgs[index]) {
|
58
|
+
return style;
|
59
|
+
}
|
60
|
+
return undefined;
|
61
|
+
}).filter(Boolean);
|
46
62
|
if (storedRef.current) {
|
47
63
|
// @ts-expect-error - this is hidden from TS
|
48
64
|
UnistylesShadowRegistry.remove(storedRef.current);
|
49
65
|
// @ts-expect-error - this is hidden from TS
|
50
|
-
UnistylesShadowRegistry.add(storedRef.current,
|
66
|
+
UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, [...fnArgs], pressId);
|
51
67
|
}
|
52
68
|
return typeof styleResult === 'function'
|
53
69
|
// @ts-expect-error - this is hidden from TS
|
54
|
-
? styleResult(pressId) : styleResult
|
70
|
+
? styleResult(pressId) : Array.isArray(styleResult)
|
71
|
+
// @ts-expect-error - this is hidden from TS
|
72
|
+
? styleResult.map(style => typeof style === 'function' ? style(pressId) : style) : styleResult;
|
55
73
|
}
|
56
74
|
});
|
57
75
|
});
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["React","forwardRef","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","getId","jsx","_jsx","variants","style","rawStyle","props","passedRef","storedRef","ref","current","styleResult","pressed","fnArgs","getBoundArgs","returnFn","add","remove","state","pressId"],"sourceRoot":"../../../src","sources":["components/Pressable.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AACjD,SAASC,SAAS,IAAIC,0BAA0B,QAAQ,cAAc;AAEtE,SAASC,uBAAuB,QAAQ,UAAU;AAClD,SAASC,KAAK,QAAQ,SAAS;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAO/B,OAAO,MAAML,SAAS,gBAAGF,UAAU,CAAuB,CAAC;EAAEQ,QAAQ;EAAEC,KAAK;EAAEC,QAAQ;EAAE,GAAGC;AAAM,CAAC,EAAEC,SAAS,KAAK;EAC9G,MAAMC,SAAS,GAAGZ,MAAM,CAAc,CAAC;EAEvC,oBACIM,IAAA,CAACJ,0BAA0B;IAAA,GACnBQ,KAAK;IACTG,GAAG,EAAEA,GAAG,IAAI;MACRD,SAAS,CAACE,OAAO,GAAGD,GAAG;MACvB,MAAME,WAAW,GAAG,OAAOP,KAAK,KAAK,UAAU,GACzCA,KAAK,CAAC;QAAEQ,OAAO,EAAE;MAAM,CAAC,CAAC,GACzBR,KAAK;MACX,MAAMS,MAAM,GAAG,OAAOF,WAAW,KAAK;MAClC;MAAA,EACEA,WAAW,CAACG,YAAY,CAAC,CAAC,
|
1
|
+
{"version":3,"names":["React","forwardRef","useRef","Pressable","NativePressableReactNative","UnistylesShadowRegistry","getId","jsx","_jsx","variants","style","rawStyle","props","passedRef","storedRef","ref","current","styleResult","pressed","fnArgs","getBoundArgs","Array","isArray","map","returnFn","unistyles","index","undefined","filter","Boolean","add","remove","state","pressId"],"sourceRoot":"../../../src","sources":["components/Pressable.tsx"],"mappings":";;AAAA,OAAOA,KAAK,IAAIC,UAAU,EAAEC,MAAM,QAAQ,OAAO;AACjD,SAASC,SAAS,IAAIC,0BAA0B,QAAQ,cAAc;AAEtE,SAASC,uBAAuB,QAAQ,UAAU;AAClD,SAASC,KAAK,QAAQ,SAAS;AAAA,SAAAC,GAAA,IAAAC,IAAA;AAO/B,OAAO,MAAML,SAAS,gBAAGF,UAAU,CAAuB,CAAC;EA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vB;MAAA,EACEA,WAAW,CAACM,GAAG,CAACb,KAAK,IAAI,OAAOA,KAAK,KAAK,UAAU,GAAGA,KAAK,CAACuB,OAAO,CAAC,GAAGvB,KAAK,CAAC,GAC9EO,WAAW;IACzB;EAAE,CACL,CAAC;AAEV,CAAC,CAAC","ignoreList":[]}
|
package/lib/module/web/create.js
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
import { assignSecrets, reduceObject, getStyles, error } from './utils';
|
4
4
|
import { deepMergeObjects } from '../utils';
|
5
5
|
import { UnistylesRuntime } from './runtime';
|
6
|
-
import {
|
6
|
+
import { getVariants } from './variants';
|
7
7
|
export const create = (stylesheet, id) => {
|
8
8
|
if (!id) {
|
9
9
|
throw error('Unistyles is not initialized correctly. Please add babel plugin to your babel config.');
|
@@ -41,7 +41,12 @@ export const create = (stylesheet, id) => {
|
|
41
41
|
});
|
42
42
|
|
43
43
|
// Inject useVariants hook to styles
|
44
|
-
|
44
|
+
Object.defineProperty(styles, 'useVariants', {
|
45
|
+
value: variants => {
|
46
|
+
Object.entries(variants).forEach(([key, value]) => selectedVariants.set(key, value));
|
47
|
+
},
|
48
|
+
configurable: false
|
49
|
+
});
|
45
50
|
return styles;
|
46
51
|
};
|
47
52
|
//# sourceMappingURL=create.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["assignSecrets","reduceObject","getStyles","error","deepMergeObjects","UnistylesRuntime","
|
1
|
+
{"version":3,"names":["assignSecrets","reduceObject","getStyles","error","deepMergeObjects","UnistylesRuntime","getVariants","create","stylesheet","id","computedStylesheet","theme","miniRuntime","selectedVariants","Map","copyVariants","Object","fromEntries","entries","addSecrets","value","key","args","__uni__key","__uni__refs","Set","__uni__stylesheet","__uni__args","__uni__variants","styles","_key","String","dynamicStyle","result","variants","resultWithVariants","defineProperty","forEach","set","configurable"],"sourceRoot":"../../../src","sources":["web/create.ts"],"mappings":";;AAEA,SAASA,aAAa,EAAEC,YAAY,EAAEC,SAAS,EAAEC,KA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AAuClB,YAAY,CAAC,CAAC,CAAC,CAAC;QACxH,MAAMoB,kBAAkB,GAAG/B,gBAAgB,CAAC6B,MAAM,EAAEC,QAAQ,CAACb,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC;;QAExE;QACA,OAAOF,UAAU,CAACjB,SAAS,CAACiC,kBAAkB,CAAC,EAAEd,GAAG,EAAEC,IAAI,CAAC;MAC/D,CAAC;;MAED;MACA,OAAOH,UAAU,CAACa,YAAY,EAAEX,GAAG,CAAC;IACxC;;IAEA;IACA,OAAOF,UAAU,CAACjB,SAAS,CAACkB,KAAK,CAAC,EAAEC,GAAG,CAAC;EAC5C,CAAC,CAAsC;;EAEvC;EACAL,MAAM,CAACoB,cAAc,CAACP,MAAM,EAAE,aAAa,EAAE;IACzCT,KAAK,EAAGc,QAA0C,IAAK;MACnDlB,MAAM,CAACE,OAAO,CAACgB,QAAQ,CAAC,CAACG,OAAO,CAAC,CAAC,CAAChB,GAAG,EAAED,KAAK,CAAC,KAAKP,gBAAgB,CAACyB,GAAG,CAACjB,GAAG,EAAED,KAAK,CAAC,CAAC;IACxF,CAAC;IACDmB,YAAY,EAAE;EAClB,CAAC,CAAC;EAEF,OAAOV,MAAM;AACjB,CAAC","ignoreList":[]}
|
@@ -66,7 +66,7 @@ class UnistylesShadowRegistryBuilder {
|
|
66
66
|
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
|
67
67
|
const style = newComputedStylesheet[__uni__key];
|
68
68
|
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants;
|
69
|
-
const args = _args[styleIndex] ? _args[styleIndex] : __uni__args;
|
69
|
+
const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args;
|
70
70
|
const result = typeof style === 'function' ? style(...args) : style;
|
71
71
|
const {
|
72
72
|
variantsResult
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"names":["convertUnistyles","UnistylesListener","UnistylesRegistry","deepMergeObjects","equal","extractSecrets","extractUnistyleDependencies","isInDocument","getVariants","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","Map","hashMap","classNamesMap","add","ref","_style","_variants","_args","secrets","forEach","__uni__refs","oldResult","get","delete","remove","HTMLElement","styles","filter","style","Object","keys","some","key","startsWith","length","parsedStyles","flatMap","styleIndex","map","secret","__uni__key","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","variants","args","result","variantsResult","fromEntries","resultWithVariants","dependencies","addDependenciesToStylesheet","addListeners","hash","newComputedStyleSheet","newValue","applyStyles","combinedStyles","oldStyles","oldClassNames","className","classList","set","existingHash","injectedClassNames","_web","_classNames","newClassNames","Array","isArray","concat","UnistylesShadowRegistry"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;AACA,SAASA,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,gBAAgB,QAAQ,UAAU;AAC3C,SAASC,KAAK,EAAEC,cAAc,EAAEC,2BAA2B,EAAEC,YAAY,QAAQ,SAAS;AAC1F,SAASC,WAAW,QAAQ,YAAY;AAIxC,MAAMC,8BAA8B,CAAC;EACjC;EACAC,IAAI,GAAG,yBAAyB;EAChCC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAGA,CAAA,KAAM,IAAI;EACnBC,QAAQ,GAAGA,CAAA,KAAM,yBAAyB;EAC1CC,OAAO,GAAGA,CAAA,KAAM,CAAC,CAAC;EAClB;;EAEQC,UAAU,GAAG,IAAIC,GAAG,CAA+B,CAAC;EACpDC,OAAO,GAAG,IAAID,GAAG,CAAsB,CAAC;EACxCE,aAAa,GAAG,IAAIF,GAAG,CAA6B,CAAC;EAE7DG,GAAG,GAAGA,CAACC,GAAQ,EAAEC,MAAoB,EAAEC,SAA0C,EAAEC,KAAwB,KAAK;IAC5G;IACA,IAAI,CAACF,MAAM,EAAE;MACT;I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iB,CAAC;MACxF,MAAMb,KAAK,GAAGgB,qBAAqB,CAACJ,UAAU,CAA4D;MAC1G,MAAMM,QAAQ,GAAG9B,SAAS,IAAIa,MAAM,CAACC,IAAI,CAACd,SAAS,CAAC,CAACkB,MAAM,GAAG,CAAC,GAAGlB,SAAS,GAAG0B,eAAe;MAC7F,MAAMK,IAAI,GAAG9B,KAAK,CAACoB,UAAU,CAAC,
|
1
|
+
{"version":3,"names":["convertUnistyles","UnistylesListener","UnistylesRegistry","deepMergeObjects","equal","extractSecrets","extractUnistyleDependencies","isInDocument","getVariants","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","Map","hashMap","classNamesMap","add","ref","_style","_variants","_args","secrets","forEach","__uni__refs","oldResult","get","delete","remove","HTMLElement","styles","filter","style","Object","keys","some","key","startsWith","length","parsedStyles","flatMap","styleIndex","map","secret","__uni__key","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","variants","args","result","variantsResult","fromEntries","resultWithVariants","dependencies","addDependenciesToStylesheet","addListeners","hash","newComputedStyleSheet","newValue","applyStyles","combinedStyles","oldStyles","oldClassNames","className","classList","set","existingHash","injectedClassNames","_web","_classNames","newClassNames","Array","isArray","concat","UnistylesShadowRegistry"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;AACA,SAASA,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,gBAAgB,QAAQ,UAAU;AAC3C,SAASC,KAAK,EAAEC,cAAc,EAAEC,2BAA2B,EAAEC,YAAY,QAAQ,SAAS;AAC1F,SAASC,WAAW,QAAQ,YAAY;AAIxC,MAAMC,8BAA8B,CAAC;EACjC;EACAC,IAAI,GAAG,yBAAyB;EAChCC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAGA,CAAA,KAAM,IAAI;EACnBC,QAAQ,GAAGA,CAAA,KAAM,y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C,SAAS,CAAC;IACvC;;IAEA;IACAC,aAAa,EAAE1C,OAAO,CAAC2C,SAAS,IAAIhD,GAAG,CAACiD,SAAS,CAACvC,MAAM,CAACsC,SAAS,CAAC,CAAC;IACpE,IAAI,CAACrD,UAAU,CAACuD,GAAG,CAAClD,GAAG,EAAE6C,cAAc,CAAC;IAExC,MAAM;MAAEJ,IAAI;MAAEU;IAAa,CAAC,GAAGrE,iBAAiB,CAACiB,GAAG,CAAC8C,cAAc,CAAC;IACpE,MAAMO,kBAAkB,GAAGP,cAAc,EAAEQ,IAAI,EAAEC,WAAW,IAAI,EAAE;IAClE,MAAMC,aAAa,GAAG,CAACC,KAAK,CAACC,OAAO,CAACL,kBAAkB,CAAC,GAAGA,kBAAkB,GAAG,CAACA,kBAAkB,CAAC,EAAEM,MAAM,CAACjB,IAAI,CAAC;IAElH,IAAI,CAAC3C,aAAa,CAACoD,GAAG,CAAClD,GAAG,EAAEuD,aAAa,CAAC;IAC1C;IACAvD,GAAG,CAACiD,SAAS,CAAClD,GAAG,CAAC,GAAGwD,aAAa,CAAC;;IAEnC;IACA,IAAI,CAACJ,YAAY,EAAE;MACf,IAAI,CAACtD,OAAO,CAACqD,GAAG,CAAClD,GAAG,EAAEyC,IAAI,CAAC;IAC/B;IAEA,OAAOc,aAAa;EACxB,CAAC;EAED7C,MAAM,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB;AAEA,OAAO,MAAMiD,uBAAuB,GAAG,IAAItE,8BAA8B,CAAC,CAAC","ignoreList":[]}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
-
import { deepMergeObjects } from '
|
3
|
+
import { deepMergeObjects } from '../utils';
|
4
4
|
const hasVariants = value => 'variants' in value[1];
|
5
5
|
export const getVariants = (styles, selectedVariants) => {
|
6
6
|
return Object.entries(styles).filter(hasVariants).filter(([_key, {
|
@@ -31,4 +31,4 @@ export const getVariants = (styles, selectedVariants) => {
|
|
31
31
|
return [key, mergedVariantStyles];
|
32
32
|
});
|
33
33
|
};
|
34
|
-
//# sourceMappingURL=
|
34
|
+
//# sourceMappingURL=variants.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"names":["deepMergeObjects","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","default","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles"],"sourceRoot":"../../../src","sources":["web/variants.ts"],"mappings":";;AACA,SAASA,gBAAgB,QAAQ,UAAU;AAQ3C,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAE/H,OAAO,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EAAEC,gBAAqC,KAAK;EAC7G,OAAOC,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CACxBI,MAAM,CAACP,WAAW,CAAC,CACnBO,MAAM,CAAC,CAAC,CAACC,IAAI,EAAE;IAAEC;EAAS,CAAC,CAAC,KAAKJ,MAAM,CAACK,IAAI,CAACD,QAAQ,CAAC,CAACE,IAAI,CAACC,OAAO,IAAIA,OAAO,IAAIH,QAAQ,CAAC,CAAC,CAC5FI,GAAG,CAAC,CAAC,CAACC,GAAG,EAAE;IAAEL,QAAQ;IAAEM,gBAAgB,GAAG;EAAG,CAAC,CAAC,KAAK;IACjD,MAAMC,aAAa,GAAGX,MAAM,CAACC,OAAO,CAACG,QAAQ,CAAC,CAACQ,OAAO,CAAC,CAAC,CAACL,OAAO,EAAET,MAAM,CAAC,KAAK;MAC1E,MAAMe,eAAe,GAAGd,gBAAgB,CAACQ,OAAO,CAAC;MACjD,MAAMO,qBAAqB,GAAGhB,MAAM,CAACe,eAAe,CAAC,IAAIf,MAAM,CAACiB,OAAO;MAEvE,IAAI,CAACD,qBAAqB,EAAE;QACxB,OAAO,EAAE;MACb;MAEA,OAAOA,qBAAqB;IAChC,CAAC,CAAC;IAEF,MAAME,qBAAqB,GAAGN,gBAAgB,CAACE,OAAO,CAACK,eAAe,IAAI;MACtE,MAAM;QAAEnB,MAAM;QAAE,GAAGoB;MAAW,CAAC,GAAGD,eAAe;MAEjD,IAAIjB,MAAM,CAACC,OAAO,CAACiB,UAAU,CAAC,CAACZ,IAAI,CAAC,CAAC,CAACC,OAAO,EAAEX,KAAK,CAAC,KAAKuB,MAAM,CAACpB,gBAAgB,CAACQ,OAAO,CAAC,CAAC,KAAKY,MAAM,CAACvB,KAAK,CAAC,CAAC,EAAE;QAC5G,OAAO,EAAE;MACb;MAEA,OAAOE,MAAM;IACjB,CAAC,CAAC;IAEF,MAAMsB,mBAAmB,GAAG1B,gBAAgB,CAAC,GAAGiB,aAAa,EAAE,GAAGK,qBAAqB,CAAC;IAExF,OAAO,CAACP,GAAG,EAAEW,mBAAmB,CAAC;EACrC,CAAC,CAAC;AACV,CAAC","ignoreList":[]}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../../../src/components/Pressable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAA;AAEjD,OAAO,KAAK,EAAE,cAAc,IAAI,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AASjE,eAAO,MAAM,SAAS;eAJP,KAAK,CAAC,GAAG,CAAC;eACV,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;
|
1
|
+
{"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../../../src/components/Pressable.tsx"],"names":[],"mappings":"AAAA,OAAO,KAA6B,MAAM,OAAO,CAAA;AAEjD,OAAO,KAAK,EAAE,cAAc,IAAI,KAAK,EAAE,IAAI,EAAE,MAAM,cAAc,CAAA;AASjE,eAAO,MAAM,SAAS;eAJP,KAAK,CAAC,GAAG,CAAC;eACV,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC;8BA4F7C,CAAA"}
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAiDpF,CAAA"}
|
@@ -1,3 +1,3 @@
|
|
1
|
-
import type { ReactNativeStyleSheet, StyleSheet } from '
|
1
|
+
import type { ReactNativeStyleSheet, StyleSheet } from '../types';
|
2
2
|
export declare const getVariants: (styles: ReactNativeStyleSheet<StyleSheet>, selectedVariants: Record<string, any>) => (readonly [string, any])[];
|
3
|
-
//# sourceMappingURL=
|
3
|
+
//# sourceMappingURL=variants.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"variants.d.ts","sourceRoot":"","sources":["../../../../src/web/variants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAWjE,eAAO,MAAM,WAAW,WAAY,qBAAqB,CAAC,UAAU,CAAC,oBAAoB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,+BA8B3G,CAAA"}
|
package/package.json
CHANGED
package/plugin/ref.js
CHANGED
@@ -19,7 +19,7 @@ function arrayExpressionFromMetadata(t, metadata) {
|
|
19
19
|
.map(meta => {
|
20
20
|
// possible for inline styles
|
21
21
|
if (meta.members.length === 0) {
|
22
|
-
return meta.inlineStyle || meta.conditionalExpression
|
22
|
+
return meta.inlineStyle || meta.conditionalExpression || meta.logicalExpression
|
23
23
|
}
|
24
24
|
|
25
25
|
const [base, ...members] = meta.members
|
package/plugin/style.js
CHANGED
@@ -10,7 +10,8 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
|
|
10
10
|
members: members.filter(Boolean),
|
11
11
|
inlineStyle: undefined,
|
12
12
|
dynamicFunction,
|
13
|
-
conditionalExpression: undefined
|
13
|
+
conditionalExpression: undefined,
|
14
|
+
logicalExpression: undefined
|
14
15
|
}
|
15
16
|
]
|
16
17
|
}
|
@@ -36,7 +37,8 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
|
|
36
37
|
members: [],
|
37
38
|
inlineStyle: t.objectExpression([prop]),
|
38
39
|
dynamicFunction: undefined,
|
39
|
-
conditionalExpression: undefined
|
40
|
+
conditionalExpression: undefined,
|
41
|
+
logicalExpression: undefined
|
40
42
|
}]
|
41
43
|
}
|
42
44
|
|
@@ -55,7 +57,8 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
|
|
55
57
|
members: [node.name],
|
56
58
|
inlineStyle: undefined,
|
57
59
|
dynamicFunction: undefined,
|
58
|
-
conditionalExpression: undefined
|
60
|
+
conditionalExpression: undefined,
|
61
|
+
logicalExpression: undefined
|
59
62
|
}]
|
60
63
|
}
|
61
64
|
|
@@ -64,7 +67,8 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
|
|
64
67
|
members: [],
|
65
68
|
inlineStyle: undefined,
|
66
69
|
dynamicFunction: undefined,
|
67
|
-
conditionalExpression: node
|
70
|
+
conditionalExpression: node,
|
71
|
+
logicalExpression: undefined
|
68
72
|
}]
|
69
73
|
}
|
70
74
|
|
@@ -72,6 +76,17 @@ function getStyleMetadata(t, node, dynamicFunction = null) {
|
|
72
76
|
return getStyleMetadata(t, node.body, node)
|
73
77
|
}
|
74
78
|
|
79
|
+
// {condition && styles.container}
|
80
|
+
if (t.isLogicalExpression(node)) {
|
81
|
+
return [{
|
82
|
+
members: [],
|
83
|
+
inlineStyle: undefined,
|
84
|
+
dynamicFunction: undefined,
|
85
|
+
conditionalExpression: undefined,
|
86
|
+
logicalExpression: node
|
87
|
+
}]
|
88
|
+
}
|
89
|
+
|
75
90
|
return []
|
76
91
|
}
|
77
92
|
|
@@ -117,72 +132,188 @@ function styleAttributeToArray(t, path) {
|
|
117
132
|
styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
|
118
133
|
}
|
119
134
|
|
120
|
-
function
|
121
|
-
|
122
|
-
const variants = t.jsxAttribute(
|
123
|
-
t.jsxIdentifier('variants'),
|
124
|
-
t.jsxExpressionContainer(t.identifier('__uni__variants'))
|
125
|
-
)
|
135
|
+
function metadataToRawStyle(t, metadata) {
|
136
|
+
const expressions = []
|
126
137
|
|
127
|
-
|
128
|
-
|
138
|
+
metadata.forEach(meta => {
|
139
|
+
if (meta.inlineStyle) {
|
140
|
+
return meta.inlineStyle.properties.forEach(prop => {
|
141
|
+
if (t.isObjectProperty(prop)) {
|
142
|
+
expressions.push(t.objectExpression([prop]))
|
143
|
+
}
|
144
|
+
})
|
145
|
+
}
|
129
146
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
147
|
+
if (meta.members.length > 0) {
|
148
|
+
return expressions.push(t.memberExpression(...meta.members.map(member => t.identifier(member))))
|
149
|
+
}
|
150
|
+
|
151
|
+
if (meta.logicalExpression) {
|
152
|
+
if (t.isIdentifier(meta.logicalExpression.left)) {
|
153
|
+
if (t.isMemberExpression(meta.logicalExpression.right)) {
|
154
|
+
return expressions.push(meta.logicalExpression.right)
|
155
|
+
}
|
135
156
|
|
136
|
-
|
157
|
+
expressions.push(meta.logicalExpression.right.callee)
|
158
|
+
}
|
159
|
+
}
|
160
|
+
})
|
161
|
+
|
162
|
+
return t.jsxAttribute(
|
137
163
|
t.jsxIdentifier('rawStyle'),
|
138
164
|
t.jsxExpressionContainer(t.arrayExpression([
|
139
|
-
...
|
165
|
+
...expressions
|
140
166
|
]))
|
141
167
|
)
|
168
|
+
}
|
142
169
|
|
143
|
-
|
170
|
+
function wrapInGetBoundArgs(t, toWrap, extraArgs) {
|
171
|
+
const expression = t.callExpression(
|
172
|
+
t.identifier('getBoundArgs'),
|
173
|
+
[toWrap]
|
174
|
+
)
|
144
175
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
176
|
+
return t.callExpression(
|
177
|
+
t.memberExpression(expression, t.identifier('bind')),
|
178
|
+
[t.identifier('undefined'), ...extraArgs].filter(Boolean)
|
179
|
+
)
|
180
|
+
}
|
150
181
|
|
151
|
-
|
152
|
-
|
153
|
-
}
|
182
|
+
function handlePressableFromMemberExpression(t, path, metadata, wrapInArrowFunction) {
|
183
|
+
let expression = undefined
|
154
184
|
|
155
|
-
|
185
|
+
const members = metadata.at(0).members
|
186
|
+
|
187
|
+
if (members) {
|
188
|
+
expression = members.slice(1).reduce(
|
156
189
|
(acc, property) => t.memberExpression(acc, t.identifier(property)),
|
157
|
-
t.identifier(members[0])
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
190
|
+
t.identifier(members[0]))
|
191
|
+
}
|
192
|
+
|
193
|
+
if (t.isMemberExpression(metadata.at(0))) {
|
194
|
+
expression = metadata.at(0)
|
195
|
+
}
|
196
|
+
|
197
|
+
if (!expression) {
|
198
|
+
return
|
199
|
+
}
|
200
|
+
|
201
|
+
const bindCall = wrapInGetBoundArgs(t , expression, wrapInArrowFunction ? [t.identifier("state")] : [])
|
202
|
+
|
203
|
+
if (!wrapInArrowFunction) {
|
204
|
+
return t.conditionalExpression(
|
205
|
+
t.binaryExpression(
|
206
|
+
"===",
|
207
|
+
t.unaryExpression(
|
208
|
+
"typeof",
|
209
|
+
expression
|
210
|
+
),
|
211
|
+
t.stringLiteral("function")
|
212
|
+
),
|
213
|
+
bindCall,
|
214
|
+
expression
|
166
215
|
)
|
216
|
+
}
|
167
217
|
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
),
|
180
|
-
t.stringLiteral("function")
|
218
|
+
// state => typeof style.pressable === 'function'
|
219
|
+
// ? getBoundArgs(style.pressable).bind(undefined, state)
|
220
|
+
// : style.pressable
|
221
|
+
return t.arrowFunctionExpression(
|
222
|
+
[t.identifier("state")],
|
223
|
+
t.conditionalExpression(
|
224
|
+
t.binaryExpression(
|
225
|
+
"===",
|
226
|
+
t.unaryExpression(
|
227
|
+
"typeof",
|
228
|
+
expression
|
181
229
|
),
|
182
|
-
|
183
|
-
|
184
|
-
|
230
|
+
t.stringLiteral("function")
|
231
|
+
),
|
232
|
+
bindCall,
|
233
|
+
expression
|
185
234
|
)
|
235
|
+
)
|
236
|
+
}
|
237
|
+
|
238
|
+
function handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index) {
|
239
|
+
if (t.isObjectExpression(wrapper)) {
|
240
|
+
return
|
241
|
+
}
|
242
|
+
|
243
|
+
if (t.isMemberExpression(wrapper)) {
|
244
|
+
parentWrapper.elements[index] = handlePressableFromMemberExpression(t, path, [metadata[index]])
|
245
|
+
|
246
|
+
return
|
247
|
+
}
|
248
|
+
|
249
|
+
if (t.isLogicalExpression(wrapper)) {
|
250
|
+
if (t.isIdentifier(wrapper.left) && t.isMemberExpression(wrapper.right)) {
|
251
|
+
parentWrapper.elements[index].right = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].right])
|
252
|
+
|
253
|
+
return
|
254
|
+
}
|
255
|
+
|
256
|
+
return
|
257
|
+
}
|
258
|
+
|
259
|
+
if (t.isConditionalExpression(wrapper)) {
|
260
|
+
if (t.isMemberExpression(wrapper.alternate)) {
|
261
|
+
parentWrapper.elements[index].alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].alternate])
|
262
|
+
}
|
263
|
+
|
264
|
+
if (t.isMemberExpression(wrapper.consequent)) {
|
265
|
+
parentWrapper.elements[index].consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].consequent])
|
266
|
+
}
|
267
|
+
|
268
|
+
return
|
269
|
+
}
|
270
|
+
|
271
|
+
const pressableArgs = t.isCallExpression(wrapper)
|
272
|
+
? wrapper.arguments
|
273
|
+
: wrapper.argument.arguments
|
274
|
+
const callee = t.isCallExpression(wrapper)
|
275
|
+
? wrapper.callee
|
276
|
+
: wrapper.argument.callee
|
277
|
+
|
278
|
+
const getBoundArgsCall = t.callExpression(
|
279
|
+
t.identifier('getBoundArgs'),
|
280
|
+
[callee]
|
281
|
+
)
|
282
|
+
const bindCall = t.callExpression(
|
283
|
+
t.memberExpression(getBoundArgsCall, t.identifier('bind')),
|
284
|
+
[t.identifier('undefined'), ...pressableArgs]
|
285
|
+
)
|
286
|
+
|
287
|
+
if (t.isCallExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
|
288
|
+
parentWrapper.elements[index] = bindCall
|
289
|
+
|
290
|
+
return
|
291
|
+
}
|
292
|
+
|
293
|
+
if (t.isCallExpression(wrapper)) {
|
294
|
+
styleExpression.body = bindCall
|
295
|
+
}
|
296
|
+
}
|
297
|
+
|
298
|
+
function handlePressable(t, path, styleAttr, metadata, state) {
|
299
|
+
// add variants
|
300
|
+
if (state.file.hasVariants) {
|
301
|
+
const variants = t.jsxAttribute(
|
302
|
+
t.jsxIdentifier('variants'),
|
303
|
+
t.jsxExpressionContainer(t.identifier('__uni__variants'))
|
304
|
+
)
|
305
|
+
|
306
|
+
path.node.openingElement.attributes.push(variants)
|
307
|
+
}
|
308
|
+
|
309
|
+
// add raw C++ style as prop to be bound
|
310
|
+
path.node.openingElement.attributes.push(metadataToRawStyle(t, metadata))
|
311
|
+
|
312
|
+
const styleExpression = styleAttr.value.expression
|
313
|
+
|
314
|
+
// {style.pressable}
|
315
|
+
if (t.isMemberExpression(styleExpression)) {
|
316
|
+
styleAttr.value.expression = handlePressableFromMemberExpression(t, path, metadata, true)
|
186
317
|
|
187
318
|
return
|
188
319
|
}
|
@@ -212,20 +343,24 @@ function handlePressable(t, path, styleAttr, metadata, state) {
|
|
212
343
|
|
213
344
|
// {() => style.pressable(1, 2)}
|
214
345
|
if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 0) {
|
215
|
-
const
|
346
|
+
const parentWrapper = t.isBlockStatement(styleExpression.body)
|
216
347
|
? styleExpression.body.body.find(node => t.isReturnStatement(node))
|
217
348
|
: styleExpression.body
|
218
349
|
|
219
|
-
if (t.isMemberExpression(
|
350
|
+
if (t.isMemberExpression(parentWrapper)) {
|
220
351
|
return
|
221
352
|
}
|
222
353
|
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
354
|
+
if (t.isArrayExpression(parentWrapper)) {
|
355
|
+
return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
|
356
|
+
}
|
357
|
+
|
358
|
+
const pressableArgs = t.isCallExpression(parentWrapper)
|
359
|
+
? parentWrapper.arguments
|
360
|
+
: parentWrapper.argument.arguments
|
361
|
+
const callee = t.isCallExpression(parentWrapper)
|
362
|
+
? parentWrapper.callee
|
363
|
+
: parentWrapper.argument.callee
|
229
364
|
const getBoundArgsCall = t.callExpression(
|
230
365
|
t.identifier('getBoundArgs'),
|
231
366
|
[callee]
|
@@ -235,14 +370,14 @@ function handlePressable(t, path, styleAttr, metadata, state) {
|
|
235
370
|
[t.identifier('undefined'), ...pressableArgs]
|
236
371
|
)
|
237
372
|
|
238
|
-
if (t.isCallExpression(
|
373
|
+
if (t.isCallExpression(parentWrapper)) {
|
239
374
|
styleExpression.body = bindCall
|
240
375
|
|
241
376
|
return
|
242
377
|
}
|
243
378
|
|
244
|
-
if (
|
245
|
-
|
379
|
+
if (parentWrapper) {
|
380
|
+
parentWrapper.argument = bindCall
|
246
381
|
}
|
247
382
|
|
248
383
|
return
|
@@ -252,41 +387,15 @@ function handlePressable(t, path, styleAttr, metadata, state) {
|
|
252
387
|
if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length > 0) {
|
253
388
|
// user used state with custom args we need to getBoundArgs
|
254
389
|
// detect between arrow function with body and arrow function
|
255
|
-
const
|
390
|
+
const parentWrapper = t.isBlockStatement(styleExpression.body)
|
256
391
|
? styleExpression.body.body.find(node => t.isReturnStatement(node))
|
257
392
|
: styleExpression.body
|
258
393
|
|
259
|
-
if (t.
|
260
|
-
return
|
261
|
-
}
|
262
|
-
|
263
|
-
const pressableArgs = t.isCallExpression(wrapper)
|
264
|
-
? wrapper.arguments
|
265
|
-
: wrapper.argument.arguments
|
266
|
-
const callee = t.isCallExpression(wrapper)
|
267
|
-
? wrapper.callee
|
268
|
-
: wrapper.argument.callee
|
269
|
-
|
270
|
-
const getBoundArgsCall = t.callExpression(
|
271
|
-
t.identifier('getBoundArgs'),
|
272
|
-
[callee]
|
273
|
-
)
|
274
|
-
const bindCall = t.callExpression(
|
275
|
-
t.memberExpression(getBoundArgsCall, t.identifier('bind')),
|
276
|
-
[t.identifier('undefined'), ...pressableArgs]
|
277
|
-
)
|
278
|
-
|
279
|
-
// arrow function
|
280
|
-
if (t.isCallExpression(wrapper)) {
|
281
|
-
styleExpression.body = bindCall
|
282
|
-
|
283
|
-
return
|
394
|
+
if (t.isArrayExpression(parentWrapper)) {
|
395
|
+
return parentWrapper.elements.forEach((wrapper, index) =>handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
|
284
396
|
}
|
285
397
|
|
286
|
-
|
287
|
-
if (wrapper) {
|
288
|
-
wrapper.argument = bindCall
|
289
|
-
}
|
398
|
+
handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
|
290
399
|
}
|
291
400
|
}
|
292
401
|
|
@@ -23,7 +23,11 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
|
|
23
23
|
const fnArgs = typeof styleResult === 'function'
|
24
24
|
// @ts-expect-error - this is hidden from TS
|
25
25
|
? styleResult.getBoundArgs()
|
26
|
-
:
|
26
|
+
: Array.isArray(styleResult)
|
27
|
+
? styleResult
|
28
|
+
// @ts-expect-error - this is hidden from TS
|
29
|
+
.map(style => typeof style === 'function' ? style.getBoundArgs() : [])
|
30
|
+
: []
|
27
31
|
|
28
32
|
if (typeof passedRef === 'object' && passedRef !== null) {
|
29
33
|
passedRef.current = ref
|
@@ -32,9 +36,18 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
|
|
32
36
|
const returnFn = typeof passedRef === 'function'
|
33
37
|
? passedRef(ref)
|
34
38
|
: () => {}
|
39
|
+
const unistyles = (rawStyle ?? [])
|
40
|
+
.map((style, index) => {
|
41
|
+
if (fnArgs[index]) {
|
42
|
+
return style
|
43
|
+
}
|
44
|
+
|
45
|
+
return undefined
|
46
|
+
})
|
47
|
+
.filter(Boolean)
|
35
48
|
|
36
49
|
// @ts-expect-error - this is hidden from TS
|
37
|
-
UnistylesShadowRegistry.add(ref,
|
50
|
+
UnistylesShadowRegistry.add(ref, unistyles, variants, [...fnArgs])
|
38
51
|
|
39
52
|
return () => {
|
40
53
|
// @ts-expect-error - this is hidden from TS
|
@@ -52,20 +65,36 @@ export const Pressable = forwardRef<View, PressableProps>(({ variants, style, ra
|
|
52
65
|
const fnArgs = typeof styleResult === 'function'
|
53
66
|
// @ts-expect-error - this is hidden from TS
|
54
67
|
? styleResult.getBoundArgs()
|
55
|
-
:
|
68
|
+
: Array.isArray(styleResult)
|
69
|
+
? styleResult
|
70
|
+
// @ts-expect-error - this is hidden from TS
|
71
|
+
.map(style => typeof style === 'function' ? style.getBoundArgs() : [])
|
72
|
+
: []
|
56
73
|
const pressId = getId()
|
74
|
+
const unistyles = (rawStyle ?? [])
|
75
|
+
.map((style, index) => {
|
76
|
+
if (fnArgs[index]) {
|
77
|
+
return style
|
78
|
+
}
|
79
|
+
|
80
|
+
return undefined
|
81
|
+
})
|
82
|
+
.filter(Boolean)
|
57
83
|
|
58
84
|
if (storedRef.current) {
|
59
85
|
// @ts-expect-error - this is hidden from TS
|
60
86
|
UnistylesShadowRegistry.remove(storedRef.current)
|
61
87
|
// @ts-expect-error - this is hidden from TS
|
62
|
-
UnistylesShadowRegistry.add(storedRef.current,
|
88
|
+
UnistylesShadowRegistry.add(storedRef.current, unistyles, variants, [...fnArgs], pressId)
|
63
89
|
}
|
64
90
|
|
65
91
|
return typeof styleResult === 'function'
|
66
92
|
// @ts-expect-error - this is hidden from TS
|
67
93
|
? styleResult(pressId)
|
68
|
-
: styleResult
|
94
|
+
: Array.isArray(styleResult)
|
95
|
+
// @ts-expect-error - this is hidden from TS
|
96
|
+
? styleResult.map(style => typeof style === 'function' ? style(pressId) : style)
|
97
|
+
: styleResult
|
69
98
|
}}
|
70
99
|
/>
|
71
100
|
)
|
package/src/web/create.ts
CHANGED
@@ -3,7 +3,7 @@ import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
|
|
3
3
|
import { assignSecrets, reduceObject, getStyles, error } from './utils'
|
4
4
|
import { deepMergeObjects } from '../utils'
|
5
5
|
import { UnistylesRuntime } from './runtime'
|
6
|
-
import {
|
6
|
+
import { getVariants } from './variants'
|
7
7
|
|
8
8
|
export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: string) => {
|
9
9
|
if (!id) {
|
@@ -46,7 +46,12 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
|
|
46
46
|
}) as ReactNativeStyleSheet<StyleSheet>
|
47
47
|
|
48
48
|
// Inject useVariants hook to styles
|
49
|
-
|
49
|
+
Object.defineProperty(styles, 'useVariants', {
|
50
|
+
value: (variants: Record<string, string | boolean>) => {
|
51
|
+
Object.entries(variants).forEach(([key, value]) => selectedVariants.set(key, value))
|
52
|
+
},
|
53
|
+
configurable: false,
|
54
|
+
})
|
50
55
|
|
51
56
|
return styles
|
52
57
|
}
|
@@ -67,7 +67,7 @@ class UnistylesShadowRegistryBuilder {
|
|
67
67
|
const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
|
68
68
|
const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
|
69
69
|
const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants
|
70
|
-
const args = _args[styleIndex] ? _args[styleIndex] : __uni__args
|
70
|
+
const args = _args[styleIndex] && _args[styleIndex].length > 0 ? _args[styleIndex] : __uni__args
|
71
71
|
const result = typeof style === 'function'
|
72
72
|
? style(...args)
|
73
73
|
: style
|
@@ -1,5 +1,5 @@
|
|
1
|
-
import type { ReactNativeStyleSheet, StyleSheet } from '
|
2
|
-
import { deepMergeObjects } from '
|
1
|
+
import type { ReactNativeStyleSheet, StyleSheet } from '../types'
|
2
|
+
import { deepMergeObjects } from '../utils'
|
3
3
|
|
4
4
|
type StylesWithVariants = {
|
5
5
|
variants: Record<string, any>,
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_utils","require","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","default","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles","deepMergeObjects","exports"],"sourceRoot":"../../../../src","sources":["web/variants/getVariants.ts"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,OAAA;AAQA,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAExH,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EAAEC,gBAAqC,KAAK;EAC7G,OAAOC,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CACxBI,MAAM,CAACP,WAAW,CAAC,CACnBO,MAAM,CAAC,CAAC,CAACC,IAAI,EAAE;IAAEC;EAAS,CAAC,CAAC,KAAKJ,MAAM,CAACK,IAAI,CAACD,QAAQ,CAAC,CAACE,IAAI,CAACC,OAAO,IAAIA,OAAO,IAAIH,QAAQ,CAAC,CAAC,CAC5FI,GAAG,CAAC,CAAC,CAACC,GAAG,EAAE;IAAEL,QAAQ;IAAEM,gBAAgB,GAAG;EAAG,CAAC,CAAC,KAAK;IACjD,MAAMC,aAAa,GAAGX,MAAM,CAACC,OAAO,CAACG,QAAQ,CAAC,CAACQ,OAAO,CAAC,CAAC,CAACL,OAAO,EAAET,MAAM,CAAC,KAAK;MAC1E,MAAMe,eAAe,GAAGd,gBAAgB,CAACQ,OAAO,CAAC;MACjD,MAAMO,qBAAqB,GAAGhB,MAAM,CAACe,eAAe,CAAC,IAAIf,MAAM,CAACiB,OAAO;MAEvE,IAAI,CAACD,qBAAqB,EAAE;QACxB,OAAO,EAAE;MACb;MAEA,OAAOA,qBAAqB;IAChC,CAAC,CAAC;IAEF,MAAME,qBAAqB,GAAGN,gBAAgB,CAACE,OAAO,CAACK,eAAe,IAAI;MACtE,MAAM;QAAEnB,MAAM;QAAE,GAAGoB;MAAW,CAAC,GAAGD,eAAe;MAEjD,IAAIjB,MAAM,CAACC,OAAO,CAACiB,UAAU,CAAC,CAACZ,IAAI,CAAC,CAAC,CAACC,OAAO,EAAEX,KAAK,CAAC,KAAKuB,MAAM,CAACpB,gBAAgB,CAACQ,OAAO,CAAC,CAAC,KAAKY,MAAM,CAACvB,KAAK,CAAC,CAAC,EAAE;QAC5G,OAAO,EAAE;MACb;MAEA,OAAOE,MAAM;IACjB,CAAC,CAAC;IAEF,MAAMsB,mBAAmB,GAAG,IAAAC,uBAAgB,EAAC,GAAGV,aAAa,EAAE,GAAGK,qBAAqB,CAAC;IAExF,OAAO,CAACP,GAAG,EAAEW,mBAAmB,CAAC;EACrC,CAAC,CAAC;AACV,CAAC;AAAAE,OAAA,CAAAzB,WAAA,GAAAA,WAAA","ignoreList":[]}
|
@@ -1,28 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
var _useVariants = require("./useVariants");
|
7
|
-
Object.keys(_useVariants).forEach(function (key) {
|
8
|
-
if (key === "default" || key === "__esModule") return;
|
9
|
-
if (key in exports && exports[key] === _useVariants[key]) return;
|
10
|
-
Object.defineProperty(exports, key, {
|
11
|
-
enumerable: true,
|
12
|
-
get: function () {
|
13
|
-
return _useVariants[key];
|
14
|
-
}
|
15
|
-
});
|
16
|
-
});
|
17
|
-
var _getVariants = require("./getVariants");
|
18
|
-
Object.keys(_getVariants).forEach(function (key) {
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
20
|
-
if (key in exports && exports[key] === _getVariants[key]) return;
|
21
|
-
Object.defineProperty(exports, key, {
|
22
|
-
enumerable: true,
|
23
|
-
get: function () {
|
24
|
-
return _getVariants[key];
|
25
|
-
}
|
26
|
-
});
|
27
|
-
});
|
28
|
-
//# sourceMappingURL=index.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_useVariants","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_getVariants"],"sourceRoot":"../../../../src","sources":["web/variants/index.ts"],"mappings":";;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,YAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,YAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,YAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,YAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,YAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,YAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,YAAA,CAAAL,GAAA;IAAA;EAAA;AAAA","ignoreList":[]}
|
@@ -1,59 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
4
|
-
value: true
|
5
|
-
});
|
6
|
-
exports.createUseVariants = void 0;
|
7
|
-
var _react = require("react");
|
8
|
-
var _utils = require("../utils");
|
9
|
-
var _getVariants = require("./getVariants");
|
10
|
-
const createUseVariants = (styles, setSelectedVariants) => {
|
11
|
-
const useVariants = selectedVariants => {
|
12
|
-
const [selectedVariantStylesMap] = (0, _react.useState)(() => new Map());
|
13
|
-
const lastSelectedVariantsRef = (0, _react.useRef)();
|
14
|
-
// Variable that determines if variants have changed, and we need to recalculate styles
|
15
|
-
const variantsChanged = !(0, _utils.equal)(lastSelectedVariantsRef.current, selectedVariants);
|
16
|
-
if (variantsChanged) {
|
17
|
-
lastSelectedVariantsRef.current = selectedVariants;
|
18
|
-
setSelectedVariants(selectedVariants);
|
19
|
-
}
|
20
|
-
const combinedVariantStyles = (0, _react.useMemo)(() => {
|
21
|
-
const result = (0, _getVariants.getVariants)(styles, selectedVariants);
|
22
|
-
result.forEach(([key, value]) => {
|
23
|
-
selectedVariantStylesMap.set(key, value);
|
24
|
-
});
|
25
|
-
return result;
|
26
|
-
}, [lastSelectedVariantsRef.current]);
|
27
|
-
combinedVariantStyles.forEach(([key]) => {
|
28
|
-
const styleEntry = styles[key];
|
29
|
-
if (!styleEntry) {
|
30
|
-
return;
|
31
|
-
}
|
32
|
-
const selectedVariantStyles = selectedVariantStylesMap.get(key);
|
33
|
-
Object.defineProperties(styleEntry, (0, _utils.reduceObject)(selectedVariantStyles ?? {}, value => ({
|
34
|
-
value,
|
35
|
-
enumerable: false,
|
36
|
-
configurable: true
|
37
|
-
})));
|
38
|
-
|
39
|
-
// Add __uni__variants to static styles
|
40
|
-
Object.keys(styleEntry).forEach(key => {
|
41
|
-
if (!key.startsWith('__uni__secrets__')) {
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
const secret = (0, _utils.keyInObject)(styleEntry, key) ? styleEntry[key] : undefined;
|
45
|
-
if (!secret) {
|
46
|
-
return;
|
47
|
-
}
|
48
|
-
Object.defineProperty(secret, '__uni__variants', {
|
49
|
-
value: selectedVariants
|
50
|
-
});
|
51
|
-
});
|
52
|
-
});
|
53
|
-
};
|
54
|
-
Object.defineProperty(styles, 'useVariants', {
|
55
|
-
value: useVariants
|
56
|
-
});
|
57
|
-
};
|
58
|
-
exports.createUseVariants = createUseVariants;
|
59
|
-
//# sourceMappingURL=useVariants.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["_react","require","_utils","_getVariants","createUseVariants","styles","setSelectedVariants","useVariants","selectedVariants","selectedVariantStylesMap","useState","Map","lastSelectedVariantsRef","useRef","variantsChanged","equal","current","combinedVariantStyles","useMemo","result","getVariants","forEach","key","value","set","styleEntry","selectedVariantStyles","get","Object","defineProperties","reduceObject","enumerable","configurable","keys","startsWith","secret","keyInObject","undefined","defineProperty","exports"],"sourceRoot":"../../../../src","sources":["web/variants/useVariants.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,YAAA,GAAAF,OAAA;AAEO,MAAMG,iBAAiB,GAAGA,CAACC,MAAyC,EAAEC,mBAA4D,KAAK;EAC1I,MAAMC,WAAW,GAAIC,gBAAqC,IAAK;IAC3D,MAAM,CAACC,wBAAwB,CAAC,GAAG,IAAAC,eAAQ,EAAC,MAAM,IAAIC,GAAG,CAA8B,CAAC,CAAC;IACzF,MAAMC,uBAAuB,GAAG,IAAAC,aAAM,EAAsB,CAAC;IAC7D;IACA,MAAMC,eAAe,GAAG,CAAC,IAAAC,YAAK,EAACH,uBAAuB,CAACI,OAAO,EAAER,gBAAgB,CAAC;IAEjF,IAAIM,eAAe,EAAE;MACjBF,uBAAuB,CAACI,OAAO,GAAGR,gBAAgB;MAClDF,mBAAmB,CAACE,gBAAgB,CAAC;IACzC;IAEA,MAAMS,qBAAqB,GAAG,IAAAC,cAAO,EAAC,MAAM;MACxC,MAAMC,MAAM,GAAG,IAAAC,wBAAW,EAACf,MAAM,EA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,CAAC;AACN,CAAC;AAAAgC,OAAA,CAAAnC,iBAAA,GAAAA,iBAAA","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["deepMergeObjects","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","default","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles"],"sourceRoot":"../../../../src","sources":["web/variants/getVariants.ts"],"mappings":";;AACA,SAASA,gBAAgB,QAAQ,aAAa;AAQ9C,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAE/H,OAAO,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EAAEC,gBAAqC,KAAK;EAC7G,OAAOC,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CACxBI,MAAM,CAACP,WAAW,CAAC,CACnBO,MAAM,CAAC,CAAC,CAACC,IAAI,EAAE;IAAEC;EAAS,CAAC,CAAC,KAAKJ,MAAM,CAACK,IAAI,CAACD,QAAQ,CAAC,CAACE,IAAI,CAACC,OAAO,IAAIA,OAAO,IAAIH,QAAQ,CAAC,CAAC,CAC5FI,GAAG,CAAC,CAAC,CAACC,GAAG,EAAE;IAAEL,QAAQ;IAAEM,gBAAgB,GAAG;EAAG,CAAC,CAAC,KAAK;IACjD,MAAMC,aAAa,GAAGX,MAAM,CAACC,OAAO,CAACG,QAAQ,CAAC,CAACQ,OAAO,CAAC,CAAC,CAACL,OAAO,EAAET,MAAM,CAAC,KAAK;MAC1E,MAAMe,eAAe,GAAGd,gBAAgB,CAACQ,OAAO,CAAC;MACjD,MAAMO,qBAAqB,GAAGhB,MAAM,CAACe,eAAe,CAAC,IAAIf,MAAM,CAACiB,OAAO;MAEvE,IAAI,CAACD,qBAAqB,EAAE;QACxB,OAAO,EAAE;MACb;MAEA,OAAOA,qBAAqB;IAChC,CAAC,CAAC;IAEF,MAAME,qBAAqB,GAAGN,gBAAgB,CAACE,OAAO,CAACK,eAAe,IAAI;MACtE,MAAM;QAAEnB,MAAM;QAAE,GAAGoB;MAAW,CAAC,GAAGD,eAAe;MAEjD,IAAIjB,MAAM,CAACC,OAAO,CAACiB,UAAU,CAAC,CAACZ,IAAI,CAAC,CAAC,CAACC,OAAO,EAAEX,KAAK,CAAC,KAAKuB,MAAM,CAACpB,gBAAgB,CAACQ,OAAO,CAAC,CAAC,KAAKY,MAAM,CAACvB,KAAK,CAAC,CAAC,EAAE;QAC5G,OAAO,EAAE;MACb;MAEA,OAAOE,MAAM;IACjB,CAAC,CAAC;IAEF,MAAMsB,mBAAmB,GAAG1B,gBAAgB,CAAC,GAAGiB,aAAa,EAAE,GAAGK,qBAAqB,CAAC;IAExF,OAAO,CAACP,GAAG,EAAEW,mBAAmB,CAAC;EACrC,CAAC,CAAC;AACV,CAAC","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":[],"sourceRoot":"../../../../src","sources":["web/variants/index.ts"],"mappings":";;AAAA,cAAc,eAAe;AAC7B,cAAc,eAAe","ignoreList":[]}
|
@@ -1,54 +0,0 @@
|
|
1
|
-
"use strict";
|
2
|
-
|
3
|
-
import { useMemo, useRef, useState } from 'react';
|
4
|
-
import { equal, keyInObject, reduceObject } from '../utils';
|
5
|
-
import { getVariants } from './getVariants';
|
6
|
-
export const createUseVariants = (styles, setSelectedVariants) => {
|
7
|
-
const useVariants = selectedVariants => {
|
8
|
-
const [selectedVariantStylesMap] = useState(() => new Map());
|
9
|
-
const lastSelectedVariantsRef = useRef();
|
10
|
-
// Variable that determines if variants have changed, and we need to recalculate styles
|
11
|
-
const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants);
|
12
|
-
if (variantsChanged) {
|
13
|
-
lastSelectedVariantsRef.current = selectedVariants;
|
14
|
-
setSelectedVariants(selectedVariants);
|
15
|
-
}
|
16
|
-
const combinedVariantStyles = useMemo(() => {
|
17
|
-
const result = getVariants(styles, selectedVariants);
|
18
|
-
result.forEach(([key, value]) => {
|
19
|
-
selectedVariantStylesMap.set(key, value);
|
20
|
-
});
|
21
|
-
return result;
|
22
|
-
}, [lastSelectedVariantsRef.current]);
|
23
|
-
combinedVariantStyles.forEach(([key]) => {
|
24
|
-
const styleEntry = styles[key];
|
25
|
-
if (!styleEntry) {
|
26
|
-
return;
|
27
|
-
}
|
28
|
-
const selectedVariantStyles = selectedVariantStylesMap.get(key);
|
29
|
-
Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
|
30
|
-
value,
|
31
|
-
enumerable: false,
|
32
|
-
configurable: true
|
33
|
-
})));
|
34
|
-
|
35
|
-
// Add __uni__variants to static styles
|
36
|
-
Object.keys(styleEntry).forEach(key => {
|
37
|
-
if (!key.startsWith('__uni__secrets__')) {
|
38
|
-
return;
|
39
|
-
}
|
40
|
-
const secret = keyInObject(styleEntry, key) ? styleEntry[key] : undefined;
|
41
|
-
if (!secret) {
|
42
|
-
return;
|
43
|
-
}
|
44
|
-
Object.defineProperty(secret, '__uni__variants', {
|
45
|
-
value: selectedVariants
|
46
|
-
});
|
47
|
-
});
|
48
|
-
});
|
49
|
-
};
|
50
|
-
Object.defineProperty(styles, 'useVariants', {
|
51
|
-
value: useVariants
|
52
|
-
});
|
53
|
-
};
|
54
|
-
//# sourceMappingURL=useVariants.js.map
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"names":["useMemo","useRef","useState","equal","keyInObject","reduceObject","getVariants","createUseVariants","styles","setSelectedVariants","useVariants","selectedVariants","selectedVariantStylesMap","Map","lastSelectedVariantsRef","variantsChanged","current","combinedVariantStyles","result","forEach","key","value","set","styleEntry","selectedVariantStyles","get","Object","defineProperties","enumerable","configurable","keys","startsWith","secret","undefined","defineProperty"],"sourceRoot":"../../../../src","sources":["web/variants/useVariants.ts"],"mappings":";;AAAA,SAASA,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;A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pFA,KAAK;QACLO,UAAU,EAAE,KAAK;QACjBC,YAAY,EAAE;MAClB,CAAC,CAAC,CAAC,CAAC;;MAEJ;MACAH,MAAM,CAACI,IAAI,CAACP,UAAU,CAAC,CAACJ,OAAO,CAACC,GAAG,IAAI;QACnC,IAAI,CAACA,GAAG,CAACW,UAAU,CAAC,kBAAkB,CAAC,EAAE;UACrC;QACJ;QAEA,MAAMC,MAAM,GAAG5B,WAAW,CAACmB,UAAU,EAAEH,GAAG,CAAC,GAAGG,UAAU,CAACH,GAAG,CAAC,GAAGa,SAAS;QAEzE,IAAI,CAACD,MAAM,EAAE;UACT;QACJ;QAEAN,MAAM,CAACQ,cAAc,CAACF,MAAM,EAAE,iBAAiB,EAAE;UAC7CX,KAAK,EAAEV;QACX,CAAC,CAAC;MACN,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC;EAEDe,MAAM,CAACQ,cAAc,CAAC1B,MAAM,EAAE,aAAa,EAAE;IACzCa,KAAK,EAAEX;EACX,CAAC,CAAC;AACN,CAAC","ignoreList":[]}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"getVariants.d.ts","sourceRoot":"","sources":["../../../../../src/web/variants/getVariants.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAWpE,eAAO,MAAM,WAAW,WAAY,qBAAqB,CAAC,UAAU,CAAC,oBAAoB,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,+BA8B3G,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/web/variants/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,eAAe,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"useVariants.d.ts","sourceRoot":"","sources":["../../../../../src/web/variants/useVariants.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,qBAAqB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AAIpE,eAAO,MAAM,iBAAiB,WAAY,qBAAqB,CAAC,UAAU,CAAC,uBAAuB,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,IAAI,SA2DxI,CAAA"}
|
@@ -1,65 +0,0 @@
|
|
1
|
-
import { useMemo, useRef, useState } from 'react'
|
2
|
-
import type { ReactNativeStyleSheet, StyleSheet } from '../../types'
|
3
|
-
import { equal, keyInObject, reduceObject } from '../utils'
|
4
|
-
import { getVariants } from './getVariants'
|
5
|
-
|
6
|
-
export const createUseVariants = (styles: ReactNativeStyleSheet<StyleSheet>, setSelectedVariants: (variants: Record<string, any>) => void) => {
|
7
|
-
const useVariants = (selectedVariants: Record<string, any>) => {
|
8
|
-
const [selectedVariantStylesMap] = useState(() => new Map<string, Record<string, any>>())
|
9
|
-
const lastSelectedVariantsRef = useRef<Record<string, any>>()
|
10
|
-
// Variable that determines if variants have changed, and we need to recalculate styles
|
11
|
-
const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants)
|
12
|
-
|
13
|
-
if (variantsChanged) {
|
14
|
-
lastSelectedVariantsRef.current = selectedVariants
|
15
|
-
setSelectedVariants(selectedVariants)
|
16
|
-
}
|
17
|
-
|
18
|
-
const combinedVariantStyles = useMemo(() => {
|
19
|
-
const result = getVariants(styles, selectedVariants)
|
20
|
-
|
21
|
-
result.forEach(([key, value]) => {
|
22
|
-
selectedVariantStylesMap.set(key, value)
|
23
|
-
})
|
24
|
-
|
25
|
-
return result
|
26
|
-
}, [lastSelectedVariantsRef.current])
|
27
|
-
|
28
|
-
combinedVariantStyles.forEach(([key]) => {
|
29
|
-
const styleEntry = styles[key]
|
30
|
-
|
31
|
-
if (!styleEntry) {
|
32
|
-
return
|
33
|
-
}
|
34
|
-
|
35
|
-
const selectedVariantStyles = selectedVariantStylesMap.get(key)
|
36
|
-
|
37
|
-
Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
|
38
|
-
value,
|
39
|
-
enumerable: false,
|
40
|
-
configurable: true
|
41
|
-
})))
|
42
|
-
|
43
|
-
// Add __uni__variants to static styles
|
44
|
-
Object.keys(styleEntry).forEach(key => {
|
45
|
-
if (!key.startsWith('__uni__secrets__')) {
|
46
|
-
return
|
47
|
-
}
|
48
|
-
|
49
|
-
const secret = keyInObject(styleEntry, key) ? styleEntry[key] : undefined
|
50
|
-
|
51
|
-
if (!secret) {
|
52
|
-
return
|
53
|
-
}
|
54
|
-
|
55
|
-
Object.defineProperty(secret, '__uni__variants', {
|
56
|
-
value: selectedVariants
|
57
|
-
})
|
58
|
-
})
|
59
|
-
})
|
60
|
-
}
|
61
|
-
|
62
|
-
Object.defineProperty(styles, 'useVariants', {
|
63
|
-
value: useVariants
|
64
|
-
})
|
65
|
-
}
|