react-native-unistyles 1.0.0-beta.1 → 1.0.0-beta.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (40) hide show
  1. package/README.md +81 -1
  2. package/lib/commonjs/createUnistyles.js +2 -2
  3. package/lib/commonjs/createUnistyles.js.map +1 -1
  4. package/lib/commonjs/hooks/index.js +13 -0
  5. package/lib/commonjs/hooks/index.js.map +1 -0
  6. package/lib/commonjs/hooks/useDimensions.js +19 -0
  7. package/lib/commonjs/hooks/useDimensions.js.map +1 -0
  8. package/lib/commonjs/hooks/useDimensions.web.js +31 -0
  9. package/lib/commonjs/hooks/useDimensions.web.js.map +1 -0
  10. package/lib/commonjs/utils/styles.js +25 -26
  11. package/lib/commonjs/utils/styles.js.map +1 -1
  12. package/lib/commonjs/utils/styles.spec.js +66 -0
  13. package/lib/commonjs/utils/styles.spec.js.map +1 -1
  14. package/lib/module/createUnistyles.js +2 -2
  15. package/lib/module/createUnistyles.js.map +1 -1
  16. package/lib/module/hooks/index.js +2 -0
  17. package/lib/module/hooks/index.js.map +1 -0
  18. package/lib/module/hooks/useDimensions.js +12 -0
  19. package/lib/module/hooks/useDimensions.js.map +1 -0
  20. package/lib/module/hooks/useDimensions.web.js +24 -0
  21. package/lib/module/hooks/useDimensions.web.js.map +1 -0
  22. package/lib/module/utils/styles.js +25 -26
  23. package/lib/module/utils/styles.js.map +1 -1
  24. package/lib/module/utils/styles.spec.js +66 -0
  25. package/lib/module/utils/styles.spec.js.map +1 -1
  26. package/lib/typescript/src/createUnistyles.d.ts.map +1 -1
  27. package/lib/typescript/src/hooks/index.d.ts +2 -0
  28. package/lib/typescript/src/hooks/index.d.ts.map +1 -0
  29. package/lib/typescript/src/hooks/useDimensions.d.ts +3 -0
  30. package/lib/typescript/src/hooks/useDimensions.d.ts.map +1 -0
  31. package/lib/typescript/src/hooks/useDimensions.web.d.ts +3 -0
  32. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +1 -0
  33. package/lib/typescript/src/utils/styles.d.ts +2 -8
  34. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  35. package/package.json +1 -1
  36. package/src/createUnistyles.ts +2 -2
  37. package/src/hooks/index.ts +1 -0
  38. package/src/hooks/useDimensions.ts +11 -0
  39. package/src/hooks/useDimensions.web.ts +30 -0
  40. package/src/utils/styles.ts +39 -34
package/README.md CHANGED
@@ -7,7 +7,7 @@
7
7
  </picture>
8
8
 
9
9
  ## Features
10
- - ⚡ Blazing fast, adds around ~5ms on top of StyleSheet*
10
+ - ⚡ Blazing fast, adds around ~3ms on top of StyleSheet*
11
11
  - 🎳 Share up to 100% of your styles across platforms in monorepo
12
12
  - 🎯 Doesn't introduce new components
13
13
  - 🖥️ Supports custom breakpoints and css-like media queries
@@ -230,6 +230,86 @@ const stylesheet = createStyles(theme => ({
230
230
  }))
231
231
  ```
232
232
 
233
+ ## Dynamic functions
234
+
235
+ Every style can be transformed to dynamic function to take additional parameters from JSX:
236
+
237
+ ```tsx
238
+ export const ExampleUnistyles = () => {
239
+ const { styles } = useStyles(stylesheet)
240
+
241
+ return (
242
+ <ScrollView contentContainerStyle={styles.scrollContainer}>
243
+ {posts.map((post, index) => (
244
+ <View
245
+ key={post.key}
246
+ // call it as regular function
247
+ style={styles.post(index)}
248
+ >
249
+ <Text>
250
+ {post.title}
251
+ </Text>
252
+ </View>
253
+ ))}
254
+ </ScrollView>
255
+ )
256
+ }
257
+
258
+ const stylesheet = createStyles({
259
+ scrollContainer: {
260
+ flex: 1,
261
+ justifyContent: 'center',
262
+ alignItems: 'center',
263
+ },
264
+ // dynamic function
265
+ post: (index: number) => ({
266
+ backgroundColor: index % 2 === 0 ? 'gold' : 'silver',
267
+ })
268
+ })
269
+ ```
270
+
271
+ ## Migrate from StyleSheet
272
+
273
+ `react-native-unistyles` embraces the simplicity of `StyleSheet`, making it easy to integrate into your project.
274
+
275
+ You can replace `StyleSheet.create` with `createStyles` and it will work exactly the same:
276
+
277
+ ```diff
278
+ -const styles = StyleSheet.create({
279
+ +const styles = createStyles({
280
+ scrollContainer: {
281
+ flex: 1,
282
+ justifyContent: 'center',
283
+ alignItems: 'center',
284
+ }
285
+ })
286
+ ```
287
+
288
+ If you need additional functionalities such as `breakpoints`, `media-queries` or `theme` you can incrementally pass `style(sheet)` into the `useStyles` hook:
289
+
290
+ ```ts
291
+ export const ExampleUnistyles = () => {
292
+ const { styles } = useStyles(stylesheet)
293
+ // ... your component code
294
+ }
295
+ ```
296
+
297
+ With the hook in place, you can now use `breakpoints` and `media-queries`.
298
+
299
+ Additionally, to access the `theme` use a function instead of an `object`:
300
+
301
+ ```diff
302
+ -const stylesheet = createStyles({
303
+ +const stylesheet = createStyles(theme => ({
304
+ scrollContainer: {
305
+ flex: 1,
306
+ justifyContent: 'center',
307
+ alignItems: 'center',
308
+ backgroundColor: theme.colors.background
309
+ }
310
+ }))
311
+ ```
312
+
233
313
  ## Example
234
314
 
235
315
  In order to check out working example go to [example/](./example).
@@ -5,16 +5,16 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.createUnistyles = void 0;
7
7
  var _react = require("react");
8
- var _reactNative = require("react-native");
9
8
  var _UnistylesTheme = require("./UnistylesTheme");
10
9
  var _utils = require("./utils");
10
+ var _hooks = require("./hooks");
11
11
  const createUnistyles = breakpoints => {
12
12
  const sortedBreakpoints = (0, _utils.sortAndValidateBreakpoints)(breakpoints);
13
13
  return {
14
14
  createStyles: styles => styles,
15
15
  useStyles: stylesheet => {
16
16
  const theme = (0, _react.useContext)(_UnistylesTheme.UnistylesContext);
17
- const dimensions = (0, _reactNative.useWindowDimensions)();
17
+ const dimensions = (0, _hooks.useDimensions)();
18
18
  const breakpoint = (0, _utils.getBreakpointFromScreenWidth)(dimensions.width, sortedBreakpoints);
19
19
  const screenSize = {
20
20
  width: dimensions.width,
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_reactNative","_UnistylesTheme","_utils","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","createStyles","styles","useStyles","stylesheet","theme","useContext","UnistylesContext","dimensions","useWindowDimensions","breakpoint","getBreakpointFromScreenWidth","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x","proxifyFunction","parseStyle","exports"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAEA,IAAAE,eAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAG,IAAAC,iCAA0B,EAACF,WAAW,CAAM;EAEtE,OAAO;IACHG,YAAY,EAAsCC,MAAqC,IAAKA,MAAW;IACvGC,SAAS,EAAwCC,UAA4C,IAAK;MAC9F,MAAMC,KAAK,GAAG,IAAAC,iBAAU,EAACC,gCAAgB,CAAM;MAC/C,MAAMC,UAAU,GAAG,IAAAC,gCAAmB,EAAC,CAAC;MACxC,MAAMC,UAAU,GAAG,IAAAC,mCAA4B,EAAIH,UAAU,CAACI,KAAK,EAAEb,iBAAiB,CAAC;MACvF,MAAMc,UAAsB,GAAG;QAC3BD,KAAK,EAAEJ,UAAU,CAACI,KAAK;QACvBE,MAAM,EAAEN,UAAU,CAACM;MACvB,CAAC;MAED,IAAI,CAACV,UAAU,EAAE;QACb,OAAO;UACHC,KAAK;UACLH,MAAM,EAAE,CAAC;QACb,CAAC;MACL;MAEA,MAAMa,YAAY,GAAG,OAAOX,UAAU,KAAK,UAAU,GAC/CA,UAAU,CAACC,KAAK,CAAC,GACjBD,UAAU;MAEhB,MAAMY,iBAAiB,GAAGC,MAAM,CAC3BC,OAAO,CAACH,YAAY,CAAC,CACrBI,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;QAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;QACtB,MAAMG,CAAC,GAAGD,KAAiC;QAE3C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;UAC7B,OAAO;YACH,GAAGH,GAAG;YACN,CAACE,GAAG,GAAG,IAAAG,sBAAe,EAAIF,KAAK,EAAEb,UAAU,EAAEG,UAAU,EAAEd,iBAAiB;UAC9E,CAAC;QACL;QAEA,OAAO;UACH,GAAGqB,GAAG;UACN,CAACE,GAAG,GAAG,IAAAI,iBAAU,EAAQF,CAAC,EAAEd,UAAU,EAAEG,UAAU,EAAEd,iBAAiB;QACzE,CAAC;MACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHM,KAAK;QACLH,MAAM,EAAEc;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC;AAAAW,OAAA,CAAA9B,eAAA,GAAAA,eAAA"}
1
+ {"version":3,"names":["_react","require","_UnistylesTheme","_utils","_hooks","createUnistyles","breakpoints","sortedBreakpoints","sortAndValidateBreakpoints","createStyles","styles","useStyles","stylesheet","theme","useContext","UnistylesContext","dimensions","useDimensions","breakpoint","getBreakpointFromScreenWidth","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x","proxifyFunction","parseStyle","exports"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,eAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AACA,IAAAG,MAAA,GAAAH,OAAA;AAEO,MAAMI,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAG,IAAAC,iCAA0B,EAACF,WAAW,CAAM;EAEtE,OAAO;IACHG,YAAY,EAAsCC,MAAqC,IAAKA,MAAW;IACvGC,SAAS,EAAwCC,UAA4C,IAAK;MAC9F,MAAMC,KAAK,GAAG,IAAAC,iBAAU,EAACC,gCAAgB,CAAM;MAC/C,MAAMC,UAAU,GAAG,IAAAC,oBAAa,EAAC,CAAC;MAClC,MAAMC,UAAU,GAAG,IAAAC,mCAA4B,EAAIH,UAAU,CAACI,KAAK,EAAEb,iBAAiB,CAAC;MACvF,MAAMc,UAAsB,GAAG;QAC3BD,KAAK,EAAEJ,UAAU,CAACI,KAAK;QACvBE,MAAM,EAAEN,UAAU,CAACM;MACvB,CAAC;MAED,IAAI,CAACV,UAAU,EAAE;QACb,OAAO;UACHC,KAAK;UACLH,MAAM,EAAE,CAAC;QACb,CAAC;MACL;MAEA,MAAMa,YAAY,GAAG,OAAOX,UAAU,KAAK,UAAU,GAC/CA,UAAU,CAACC,KAAK,CAAC,GACjBD,UAAU;MAEhB,MAAMY,iBAAiB,GAAGC,MAAM,CAC3BC,OAAO,CAACH,YAAY,CAAC,CACrBI,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;QAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;QACtB,MAAMG,CAAC,GAAGD,KAAiC;QAE3C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;UAC7B,OAAO;YACH,GAAGH,GAAG;YACN,CAACE,GAAG,GAAG,IAAAG,sBAAe,EAAIF,KAAK,EAAEb,UAAU,EAAEG,UAAU,EAAEd,iBAAiB;UAC9E,CAAC;QACL;QAEA,OAAO;UACH,GAAGqB,GAAG;UACN,CAACE,GAAG,GAAG,IAAAI,iBAAU,EAAQF,CAAC,EAAEd,UAAU,EAAEG,UAAU,EAAEd,iBAAiB;QACzE,CAAC;MACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHM,KAAK;QACLH,MAAM,EAAEc;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC;AAAAW,OAAA,CAAA9B,eAAA,GAAAA,eAAA"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "useDimensions", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _useDimensions.useDimensions;
10
+ }
11
+ });
12
+ var _useDimensions = require("./useDimensions");
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_useDimensions","require"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA"}
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useDimensions = void 0;
7
+ var _reactNative = require("react-native");
8
+ const useDimensions = () => {
9
+ const {
10
+ width,
11
+ height
12
+ } = (0, _reactNative.useWindowDimensions)();
13
+ return {
14
+ width,
15
+ height
16
+ };
17
+ };
18
+ exports.useDimensions = useDimensions;
19
+ //# sourceMappingURL=useDimensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","useDimensions","width","height","useWindowDimensions","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAG,IAAAC,gCAAmB,EAAC,CAAC;EAE/C,OAAO;IACHF,KAAK;IACLC;EACJ,CAAC;AACL,CAAC;AAAAE,OAAA,CAAAJ,aAAA,GAAAA,aAAA"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useDimensions = void 0;
7
+ var _react = require("react");
8
+ const useDimensions = () => {
9
+ const timerRef = (0, _react.useRef)();
10
+ const [screenSize, setScreenSize] = (0, _react.useState)({
11
+ width: window.innerWidth,
12
+ height: window.innerHeight
13
+ });
14
+ (0, _react.useEffect)(() => {
15
+ const handleResize = () => {
16
+ clearTimeout(timerRef.current);
17
+ timerRef.current = setTimeout(() => setScreenSize({
18
+ width: window.innerWidth,
19
+ height: window.innerHeight
20
+ }), 100);
21
+ };
22
+ window.addEventListener('resize', handleResize);
23
+ return () => {
24
+ window.removeEventListener('resize', handleResize);
25
+ clearTimeout(timerRef.current);
26
+ };
27
+ }, []);
28
+ return screenSize;
29
+ };
30
+ exports.useDimensions = useDimensions;
31
+ //# sourceMappingURL=useDimensions.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","useDimensions","timerRef","useRef","screenSize","setScreenSize","useState","width","window","innerWidth","height","innerHeight","useEffect","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener","exports"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAGO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAG,IAAAC,aAAM,EAAgC,CAAC;EACxD,MAAM,CAACC,UAAU,EAAEC,aAAa,CAAC,GAAG,IAAAC,eAAQ,EAAa;IACrDC,KAAK,EAAEC,MAAM,CAACC,UAAU;IACxBC,MAAM,EAAEF,MAAM,CAACG;EACnB,CAAC,CAAC;EAEF,IAAAC,gBAAS,EAAC,MAAM;IACZ,MAAMC,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;MAE9Bb,QAAQ,CAACa,OAAO,GAAGC,UAAU,CAAC,MAAMX,aAAa,CAAC;QAC9CE,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACS,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTL,MAAM,CAACU,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACZ,QAAQ,CAACa,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOX,UAAU;AACrB,CAAC;AAAAe,OAAA,CAAAlB,aAAA,GAAAA,aAAA"}
@@ -8,10 +8,6 @@ var _breakpoints = require("./breakpoints");
8
8
  /**
9
9
  * Proxies a function to parse its return value for custom media queries or breakpoints.
10
10
  *
11
- * If the function's string representation contains a custom media query or a defined breakpoint,
12
- * the returned function will be proxied to parse its return value based on the provided screen size and breakpoints.
13
- * If neither is found, the original function is returned.
14
- *
15
11
  * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
16
12
  *
17
13
  * @param {Function} fn - The function to be proxified.
@@ -19,7 +15,7 @@ var _breakpoints = require("./breakpoints");
19
15
  * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
20
16
  * @param {B} breakpoints - An object representing the defined breakpoints.
21
17
  *
22
- * @returns {Function} Returns the proxified function or the original function if no custom media query or breakpoint is found in its string representation.
18
+ * @returns {Function} Returns the proxified function
23
19
  *
24
20
  * @example
25
21
  *
@@ -30,17 +26,9 @@ var _breakpoints = require("./breakpoints");
30
26
  * const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
31
27
  * proxifiedFunction() // parsed style based on screenSize and breakpoints
32
28
  */
33
- const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => {
34
- const stringifiedFunction = fn.toString();
35
- const hasCustomMediaQuery = stringifiedFunction.includes(':w[') || stringifiedFunction.includes(':h[');
36
- const hasBreakpoint = Object.keys(breakpoints).some(bp => stringifiedFunction.includes(bp));
37
- if (!hasCustomMediaQuery && !hasBreakpoint) {
38
- return fn;
39
- }
40
- return new Proxy(fn, {
41
- apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpoints)
42
- });
43
- };
29
+ const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => new Proxy(fn, {
30
+ apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpoints)
31
+ });
44
32
 
45
33
  /**
46
34
  * Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
@@ -68,15 +56,26 @@ const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => {
68
56
  * // { fontSize: '12px' }
69
57
  */
70
58
  exports.proxifyFunction = proxifyFunction;
71
- const parseStyle = (style, breakpoint, screenSize, breakpoints) => Object.fromEntries(Object.entries(style).map(_ref => {
72
- let [key, value] = _ref;
73
- const isDynamicFunction = typeof value === 'function';
74
- const isValidStyle = typeof value !== 'object' || key === 'transform';
75
- if (isDynamicFunction || isValidStyle) {
76
- return [key, value];
77
- }
78
- const valueWithBreakpoint = value;
79
- return [key, (0, _breakpoints.getValueForBreakpoint)(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
80
- }));
59
+ const parseStyle = (style, breakpoint, screenSize, breakpoints) => {
60
+ const entries = Object.entries(style);
61
+ return Object.fromEntries(entries.map(_ref => {
62
+ let [key, value] = _ref;
63
+ const isNestedStyle = key === 'shadowOffset';
64
+ if (isNestedStyle) {
65
+ return [key, parseStyle(value, breakpoint, screenSize, breakpoints)];
66
+ }
67
+ const isTransform = key === 'transform';
68
+ if (isTransform && Array.isArray(value)) {
69
+ return [key, value.map(value => parseStyle(value, breakpoint, screenSize, breakpoints))];
70
+ }
71
+ const isDynamicFunction = typeof value === 'function';
72
+ const isValidStyle = typeof value !== 'object';
73
+ if (isDynamicFunction || isValidStyle) {
74
+ return [key, value];
75
+ }
76
+ const valueWithBreakpoint = value;
77
+ return [key, (0, _breakpoints.getValueForBreakpoint)(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
78
+ }));
79
+ };
81
80
  exports.parseStyle = parseStyle;
82
81
  //# sourceMappingURL=styles.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","stringifiedFunction","toString","hasCustomMediaQuery","includes","hasBreakpoint","Object","keys","some","bp","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","fromEntries","entries","map","_ref","key","value","isDynamicFunction","isValidStyle","valueWithBreakpoint","getValueForBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,WAAc,KACH;EACX,MAAMC,mBAAmB,GAAGJ,EAAE,CAACK,QAAQ,CAAC,CAAC;EACzC,MAAMC,mBAAmB,GAAGF,mBAAmB,CAACG,QAAQ,CAAC,KAAK,CAAC,IAAIH,mBAAmB,CAACG,QAAQ,CAAC,KAAK,CAAC;EACtG,MAAMC,aAAa,GAAGC,MAAM,CACvBC,IAAI,CAACP,WAAW,CAAC,CACjBQ,IAAI,CAACC,EAAE,IAAIR,mBAAmB,CAACG,QAAQ,CAACK,EAAE,CAAC,CAAC;EAEjD,IAAI,CAACN,mBAAmB,IAAI,CAACE,aAAa,EAAE;IACxC,OAAOR,EAAE;EACb;EAEA,OAAO,IAAIa,KAAK,CAACb,EAAE,EAAE;IACjBc,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAAa,CAAC,EAAEhB,UAAU,EAAEC,UAAU,EAAEC,WAAW;EAC5F,CAAC,CAAC;AACN,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAxBAgB,OAAA,CAAApB,eAAA,GAAAA,eAAA;AAyBO,MAAMmB,UAAU,GAAGA,CACtBE,KAA8B,EAC9BnB,UAA4B,EAC5BC,UAAsB,EACtBC,WAAc,KACbM,MAAM,CACNY,WAAW,CAACZ,MAAM,CACda,OAAO,CAACF,KAAK,CAAC,CACdG,GAAG,CAACC,IAAA,IAAkB;EAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;EACd,MAAMG,iBAAiB,GAAG,OAAOD,KAAK,KAAK,UAAU;EACrD,MAAME,YAAY,GAAG,OAAOF,KAAK,KAAK,QAAQ,IAAID,GAAG,KAAK,WAAW;EAErE,IAAIE,iBAAiB,IAAIC,YAAY,EAAE;IACnC,OAAO,CAACH,GAAG,EAAEC,KAAK,CAAC;EACvB;EAEA,MAAMG,mBAAmB,GAAGH,KAAkD;EAE9E,OAAO,CAACD,GAAG,EAAE,IAAAK,kCAAqB,EAAID,mBAAmB,EAAE5B,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CAAC;AACpG,CAAC,CACL,CAAC;AAAAgB,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
1
+ {"version":3,"names":["_breakpoints","require","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","exports","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle","valueWithBreakpoint","getValueForBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":";;;;;;AACA,IAAAA,YAAA,GAAAC,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,WAAc,KACH,IAAIC,KAAK,CAACJ,EAAE,EAAE;EACzBK,KAAK,EAAEA,CAACC,MAAM,EAAEC,OAAO,EAAEC,aAAa,KAClCC,UAAU,CAACH,MAAM,CAACD,KAAK,CAACE,OAAO,EAAEC,aAA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kCAAqB,EAAID,mBAAmB,EAAExB,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CAAC;EACpG,CAAC,CACL,CAAC;AACT,CAAC;AAAAO,OAAA,CAAAD,UAAA,GAAAA,UAAA"}
@@ -93,6 +93,72 @@ describe('styles', () => {
93
93
  fontWeight: 'bold'
94
94
  });
95
95
  });
96
+ it('should correctly parse transform styles', () => {
97
+ const screenSize = {
98
+ width: 400,
99
+ height: 800
100
+ };
101
+ const breakpoint = 'sm';
102
+ const breakpoints = {
103
+ xs: 0,
104
+ sm: 400,
105
+ md: 800
106
+ };
107
+ const style = {
108
+ transform: [{
109
+ translateX: {
110
+ sm: 120,
111
+ md: 200
112
+ },
113
+ translateY: 200
114
+ }]
115
+ };
116
+ expect((0, _styles.parseStyle)(style, breakpoint, screenSize, breakpoints)).toEqual({
117
+ transform: [{
118
+ translateX: 120,
119
+ translateY: 200
120
+ }]
121
+ });
122
+ });
123
+ it('should correctly parse shadowOffset styles', () => {
124
+ const screenSize = {
125
+ width: 400,
126
+ height: 800
127
+ };
128
+ const breakpoint = 'sm';
129
+ const breakpoints = {
130
+ xs: 0,
131
+ sm: 400,
132
+ md: 800
133
+ };
134
+ const style = {
135
+ shadowOffset: {
136
+ width: 0,
137
+ height: 4
138
+ }
139
+ };
140
+ const styleWithBreakpoints = {
141
+ shadowOffset: {
142
+ width: 0,
143
+ height: {
144
+ sm: 10,
145
+ md: 20
146
+ }
147
+ }
148
+ };
149
+ expect((0, _styles.parseStyle)(style, breakpoint, screenSize, breakpoints)).toEqual({
150
+ shadowOffset: {
151
+ width: 0,
152
+ height: 4
153
+ }
154
+ });
155
+ expect((0, _styles.parseStyle)(styleWithBreakpoints, breakpoint, screenSize, breakpoints)).toEqual({
156
+ shadowOffset: {
157
+ width: 0,
158
+ height: 10
159
+ }
160
+ });
161
+ });
96
162
  });
97
163
  });
98
164
  //# sourceMappingURL=styles.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_styles","require","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","proxifyFunction","toEqual","style","fontSize","fontWeight","parseStyle"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":";;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGAC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACbJ,EAAE,EAAEG,MAAM,GACJ,OAAO,GACP,KAAK;UACXF,EAAE,EAAEE,MAAM,GACJ,QAAQ,GACR;QACV;MACJ,CAAC,CAAC;MAEFE,MAAM,CAAC,IAAAC,uBAAe,EAACJ,eAAe,EAAEL,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAACS,OAAO,CAAC;QACxFH,eAAe,EAAE;MACrB,CAAC,CAAC;IACN,CAAC,CAAC;IAEFX,EAAE,CAAC,yDAAyD,EAAE,MAAM;MAChE,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACb,UAAU,EAAED,MAAM,GACZ,OAAO,GACP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bL,EAAE,EAAE,MAAM;UACVE,EAAE,EAAE;QACR,CAAC;QACDS,UAAU,EAAE;MAChB,CAAC;MAEDL,MAAM,CAAC,IAAAM,kBAAU,EAACH,KAAK,EAAyDX,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACS,OAAO,CAAC;QAC1HE,QAAQ,EAAE,EAAE;QACZL,eAAe,EAAE,MAAM;QACvBM,UAAU,EAAE;MAChB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
1
+ {"version":3,"names":["_styles","require","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","proxifyFunction","toEqual","style","fontSize","fontWeight","parseStyle","transform","translateX","translateY","shadowOffset","styleWithBreakpoints"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":";;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAGAC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACbJ,EAAE,EAAEG,MAAM,GACJ,OAAO,GACP,KAAK;UACXF,EAAE,EAAEE,MAAM,GACJ,QAAQ,GACR;QACV;MACJ,CAAC,CAAC;MAEFE,MAAM,CAAC,IAAAC,uBAAe,EAACJ,eAAe,EAAEL,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAACS,OAAO,CAAC;QAC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O,CAAC;QAC1HK,SAAS,EAAE,CACP;UACIC,UAAU,EAAE,GAAG;UACfC,UAAU,EAAE;QAChB,CAAC;MAET,CAAC,CAAC;IACN,CAAC,CAAC;IAEFrB,EAAE,CAAC,4CAA4C,EAAE,MAAM;MACnD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMO,KAAK,GAAG;QACVO,YAAY,EAAE;UACVpB,KAAK,EAAE,CAAC;UACRC,MAAM,EAAE;QACZ;MACJ,CAAC;MACD,MAAMoB,oBAAoB,GAAG;QACzBD,YAAY,EAAE;UACVpB,KAAK,EAAE,CAAC;UACRC,MAAM,EAAE;YACJI,EAAE,EAAE,EAAE;YACNC,EAAE,EAAE;UACR;QACJ;MACJ,CAAC;MAEDI,MAAM,CAAC,IAAAM,kBAAU,EAACH,KAAK,EAAyDX,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACS,OAAO,CAAC;QAC1HQ,YAAY,EAAE;UACVpB,KAAK,EAAE,CAAC;UACRC,MAAM,EAAE;QACZ;MACJ,CAAC,CAAC;MACFS,MAAM,CAAC,IAAAM,kBAAU,EAACK,oBAAoB,EAAyDnB,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACS,OAAO,CAAC;QACzIQ,YAAY,EAAE;UACVpB,KAAK,EAAE,CAAC;UACRC,MAAM,EAAE;QACZ;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
@@ -1,14 +1,14 @@
1
1
  import { useContext } from 'react';
2
- import { useWindowDimensions } from 'react-native';
3
2
  import { UnistylesContext } from './UnistylesTheme';
4
3
  import { getBreakpointFromScreenWidth, proxifyFunction, parseStyle, sortAndValidateBreakpoints } from './utils';
4
+ import { useDimensions } from './hooks';
5
5
  export const createUnistyles = breakpoints => {
6
6
  const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints);
7
7
  return {
8
8
  createStyles: styles => styles,
9
9
  useStyles: stylesheet => {
10
10
  const theme = useContext(UnistylesContext);
11
- const dimensions = useWindowDimensions();
11
+ const dimensions = useDimensions();
12
12
  const breakpoint = getBreakpointFromScreenWidth(dimensions.width, sortedBreakpoints);
13
13
  const screenSize = {
14
14
  width: dimensions.width,
@@ -1 +1 @@
1
- {"version":3,"names":["useContext","useWindowDimensions","UnistylesContext","getBreakpointFromScreenWidth","proxifyFunction","parseStyle","sortAndValidateBreakpoints","createUnistyles","breakpoints","sortedBreakpoints","createStyles","styles","useStyles","stylesheet","theme","dimensions","breakpoint","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAClC,SAASC,mBAAmB,QAAQ,cAAc;AAElD,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,SAASC,4BAA4B,EAAEC,eAAe,EAAEC,UAAU,EAAEC,0BAA0B,QAAQ,SAAS;AAE/G,OAAO,MAAMC,eAAe,GAA8CC,WAAc,IAAK;EACzF,MAAMC,iBAAiB,GAAGH,0BAA0B,CAACE,WAAW,CAAM;EAEtE,OAAO;IACHE,YAAY,EAAsCC,MAAqC,IAAKA,MAAW;IACvGC,SAAS,EAAwCC,UAA4C,IAAK;MAC9F,MAAMC,KAAK,GAAGd,UAAU,CAACE,gBAAgB,CAAM;MAC/C,MAAMa,UAAU,GAAGd,mBAAmB,CAAC,CAAC;MACxC,MAAMe,UAAU,GAAGb,4BAA4B,CAAIY,UAAU,CAACE,KAAK,EAAER,iBAAiB,CAAC;MACvF,MAAMS,UAAsB,GAAG;QAC3BD,KAAK,EAAEF,UAAU,CAACE,KAAK;QACvBE,MAAM,EAAEJ,UAAU,CAACI;MACvB,CAAC;MAED,IAAI,CAACN,UAAU,EAAE;QACb,OAAO;UACHC,KAAK;UACLH,MAAM,EAAE,CAAC;QACb,CAAC;MACL;MAEA,MAAMS,YAAY,GAAG,OAAOP,UAAU,KAAK,UAAU,GAC/CA,UAAU,CAACC,KAAK,CAAC,GACjBD,UAAU;MAEhB,MAAMQ,iBAAiB,GAAGC,MAAM,CAC3BC,OAAO,CAACH,YAAY,CAAC,CACrBI,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;QAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;QACtB,MAAMG,CAAC,GAAGD,KAAiC;QAE3C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;UAC7B,OAAO;YACH,GAAGH,GAAG;YACN,CAACE,GAAG,GAAGvB,eAAe,CAAIwB,KAAK,EAAEZ,UAAU,EAAEE,UAAU,EAAET,iBAAiB;UAC9E,CAAC;QACL;QAEA,OAAO;UACH,GAAGgB,GAAG;UACN,CAACE,GAAG,GAAGtB,UAAU,CAAQwB,CAAC,EAAEb,UAAU,EAAEE,UAAU,EAAET,iBAAiB;QACzE,CAAC;MACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHK,KAAK;QACLH,MAAM,EAAEU;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC"}
1
+ {"version":3,"names":["useContext","UnistylesContext","getBreakpointFromScreenWidth","proxifyFunction","parseStyle","sortAndValidateBreakpoints","useDimensions","createUnistyles","breakpoints","sortedBreakpoints","createStyles","styles","useStyles","stylesheet","theme","dimensions","breakpoint","width","screenSize","height","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","x"],"sourceRoot":"../../src","sources":["createUnistyles.ts"],"mappings":"AAAA,SAASA,UAAU,QAAQ,OAAO;AAElC,SAASC,gBAAgB,QAAQ,kBAAkB;AACnD,SAASC,4BAA4B,EA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AEb,UAAU,EAAEE,UAAU,EAAET,iBAAiB;QACzE,CAAC;MACL,CAAC,EAAE,CAAC,CAAO,CAAC;MAEhB,OAAO;QACHK,KAAK;QACLH,MAAM,EAAEU;MACZ,CAAC;IACL;EACJ,CAAC;AACL,CAAC"}
@@ -0,0 +1,2 @@
1
+ export { useDimensions } from './useDimensions';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useDimensions"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":"AAAA,SAASA,aAAa,QAAQ,iBAAiB"}
@@ -0,0 +1,12 @@
1
+ import { useWindowDimensions } from 'react-native';
2
+ export const useDimensions = () => {
3
+ const {
4
+ width,
5
+ height
6
+ } = useWindowDimensions();
7
+ return {
8
+ width,
9
+ height
10
+ };
11
+ };
12
+ //# sourceMappingURL=useDimensions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useWindowDimensions","useDimensions","width","height"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.ts"],"mappings":"AAAA,SAASA,mBAAmB,QAAQ,cAAc;AAGlD,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGH,mBAAmB,CAAC,CAAC;EAE/C,OAAO;IACHE,KAAK;IACLC;EACJ,CAAC;AACL,CAAC"}
@@ -0,0 +1,24 @@
1
+ import { useEffect, useRef, useState } from 'react';
2
+ export const useDimensions = () => {
3
+ const timerRef = useRef();
4
+ const [screenSize, setScreenSize] = useState({
5
+ width: window.innerWidth,
6
+ height: window.innerHeight
7
+ });
8
+ useEffect(() => {
9
+ const handleResize = () => {
10
+ clearTimeout(timerRef.current);
11
+ timerRef.current = setTimeout(() => setScreenSize({
12
+ width: window.innerWidth,
13
+ height: window.innerHeight
14
+ }), 100);
15
+ };
16
+ window.addEventListener('resize', handleResize);
17
+ return () => {
18
+ window.removeEventListener('resize', handleResize);
19
+ clearTimeout(timerRef.current);
20
+ };
21
+ }, []);
22
+ return screenSize;
23
+ };
24
+ //# sourceMappingURL=useDimensions.web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useEffect","useRef","useState","useDimensions","timerRef","screenSize","setScreenSize","width","window","innerWidth","height","innerHeight","handleResize","clearTimeout","current","setTimeout","addEventListener","removeEventListener"],"sourceRoot":"../../../src","sources":["hooks/useDimensions.web.ts"],"mappings":"AAAA,SAASA,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAGnD,OAAO,MAAMC,aAAa,GAAGA,CAAA,KAAkB;EAC3C,MAAMC,QAAQ,GAAGH,MAAM,CAAgC,CAAC;EACxD,MAAM,CAACI,UAAU,EAAEC,aAAa,CAAC,GAAGJ,QAAQ,CAAa;IACrDK,KAAK,EAAEC,MAAM,CAACC,UAAU;IACxBC,MAAM,EAAEF,MAAM,CAACG;EACnB,CAAC,CAAC;EAEFX,SAAS,CAAC,MAAM;IACZ,MAAMY,YAAY,GAAGA,CAAA,KAAM;MACvBC,YAAY,CAACT,QAAQ,CAACU,OAAO,CAAC;MAE9BV,QAAQ,CAACU,OAAO,GAAGC,UAAU,CAAC,MAAMT,aAAa,CAAC;QAC9CC,KAAK,EAAEC,MAAM,CAACC,UAAU;QACxBC,MAAM,EAAEF,MAAM,CAACG;MACnB,CAAC,CAAC,EAAE,GAAG,CAAC;IACZ,CAAC;IAEDH,MAAM,CAACQ,gBAAgB,CAAC,QAAQ,EAAEJ,YAAY,CAAC;IAE/C,OAAO,MAAM;MACTJ,MAAM,CAACS,mBAAmB,CAAC,QAAQ,EAAEL,YAAY,CAAC;MAClDC,YAAY,CAACT,QAAQ,CAACU,OAAO,CAAC;IAClC,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,OAAOT,UAAU;AACrB,CAAC"}
@@ -3,10 +3,6 @@ import { getValueForBreakpoint } from './breakpoints';
3
3
  /**
4
4
  * Proxies a function to parse its return value for custom media queries or breakpoints.
5
5
  *
6
- * If the function's string representation contains a custom media query or a defined breakpoint,
7
- * the returned function will be proxied to parse its return value based on the provided screen size and breakpoints.
8
- * If neither is found, the original function is returned.
9
- *
10
6
  * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
11
7
  *
12
8
  * @param {Function} fn - The function to be proxified.
@@ -14,7 +10,7 @@ import { getValueForBreakpoint } from './breakpoints';
14
10
  * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
15
11
  * @param {B} breakpoints - An object representing the defined breakpoints.
16
12
  *
17
- * @returns {Function} Returns the proxified function or the original function if no custom media query or breakpoint is found in its string representation.
13
+ * @returns {Function} Returns the proxified function
18
14
  *
19
15
  * @example
20
16
  *
@@ -25,17 +21,9 @@ import { getValueForBreakpoint } from './breakpoints';
25
21
  * const proxifiedFunction = proxifyFunction(myFunction, 'sm', screenSize, breakpoints)
26
22
  * proxifiedFunction() // parsed style based on screenSize and breakpoints
27
23
  */
28
- export const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => {
29
- const stringifiedFunction = fn.toString();
30
- const hasCustomMediaQuery = stringifiedFunction.includes(':w[') || stringifiedFunction.includes(':h[');
31
- const hasBreakpoint = Object.keys(breakpoints).some(bp => stringifiedFunction.includes(bp));
32
- if (!hasCustomMediaQuery && !hasBreakpoint) {
33
- return fn;
34
- }
35
- return new Proxy(fn, {
36
- apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpoints)
37
- });
38
- };
24
+ export const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => new Proxy(fn, {
25
+ apply: (target, thisArg, argumentsList) => parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpoints)
26
+ });
39
27
 
40
28
  /**
41
29
  * Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
@@ -62,14 +50,25 @@ export const proxifyFunction = (fn, breakpoint, screenSize, breakpoints) => {
62
50
  * const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
63
51
  * // { fontSize: '12px' }
64
52
  */
65
- export const parseStyle = (style, breakpoint, screenSize, breakpoints) => Object.fromEntries(Object.entries(style).map(_ref => {
66
- let [key, value] = _ref;
67
- const isDynamicFunction = typeof value === 'function';
68
- const isValidStyle = typeof value !== 'object' || key === 'transform';
69
- if (isDynamicFunction || isValidStyle) {
70
- return [key, value];
71
- }
72
- const valueWithBreakpoint = value;
73
- return [key, getValueForBreakpoint(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
74
- }));
53
+ export const parseStyle = (style, breakpoint, screenSize, breakpoints) => {
54
+ const entries = Object.entries(style);
55
+ return Object.fromEntries(entries.map(_ref => {
56
+ let [key, value] = _ref;
57
+ const isNestedStyle = key === 'shadowOffset';
58
+ if (isNestedStyle) {
59
+ return [key, parseStyle(value, breakpoint, screenSize, breakpoints)];
60
+ }
61
+ const isTransform = key === 'transform';
62
+ if (isTransform && Array.isArray(value)) {
63
+ return [key, value.map(value => parseStyle(value, breakpoint, screenSize, breakpoints))];
64
+ }
65
+ const isDynamicFunction = typeof value === 'function';
66
+ const isValidStyle = typeof value !== 'object';
67
+ if (isDynamicFunction || isValidStyle) {
68
+ return [key, value];
69
+ }
70
+ const valueWithBreakpoint = value;
71
+ return [key, getValueForBreakpoint(valueWithBreakpoint, breakpoint, screenSize, breakpoints)];
72
+ }));
73
+ };
75
74
  //# sourceMappingURL=styles.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["getValueForBreakpoint","proxifyFunction","fn","breakpoint","screenSize","breakpoints","stringifiedFunction","toString","hasCustomMediaQuery","includes","hasBreakpoint","Object","keys","some","bp","Proxy","apply","target","thisArg","argumentsList","parseStyle","style","fromEntries","entries","map","_ref","key","value","isDynamicFunction","isValidStyle","valueWithBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":"AACA,SAASA,qBAAqB,QAAQ,eAAe;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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K,KAAK,QAAQ,IAAID,GAAG,KAAK,WAAW;EAErE,IAAIE,iBAAiB,IAAIC,YAAY,EAAE;IACnC,OAAO,CAACH,GAAG,EAAEC,KAAK,CAAC;EACvB;EAEA,MAAMG,mBAAmB,GAAGH,KAAkD;EAE9E,OAAO,CAACD,GAAG,EAAE1B,qBAAqB,CAAI8B,mBAAmB,EAAE3B,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CAAC;AACpG,CAAC,CACL,CAAC"}
1
+ {"version":3,"names":["getValueForBreakpoint","proxifyFunction","fn","breakpoint","screenSize","breakpoints","Proxy","apply","target","thisArg","argumentsList","parseStyle","style","entries","Object","fromEntries","map","_ref","key","value","isNestedStyle","isTransform","Array","isArray","isDynamicFunction","isValidStyle","valueWithBreakpoint"],"sourceRoot":"../../../src","sources":["utils/styles.ts"],"mappings":"AACA,SAASA,qBAAqB,QAAQ,eAAe;;AAErD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,eAAe,GAAGA,CAC3BC,EAAY,EAAEC,UAA4B,EAC1CC,UAAsB,EACtBC,WAAc,KACH,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,UAAU,EAAEC,WAAW;AAC5F,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMM,UAAU,GAAGA,CACtBC,KAA8B,EAC9BT,UAA4B,EAC5BC,UAAsB,EACtBC,WAAc,KACV;EACJ,MAAMQ,OAAO,GAAGC,MAAM,CAACD,OAAO,CAACD,KAAK,CAAyC;EAE7E,OAAOE,MAAM,CACRC,WAAW,CAACF,OAAO,CACfG,GAAG,CAACC,IAAA,IAAkB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACd,MAAMG,aAAa,GAAGF,GAAG,KAAK,cAAc;IAE5C,IAAIE,aAAa,EAAE;MACf,OAAO,CACHF,GAAG,EACHP,UAAU,CAACQ,KAAK,EAAEhB,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CACzD;IACL;IAEA,MAAMgB,WAAW,GAAGH,GAAG,KAAK,WAAW;IAEvC,IAAIG,WAAW,IAAIC,KAAK,CAACC,OAAO,CAACJ,KAAK,CAAC,EAAE;MACrC,OAAO,CACHD,GAAG,EACHC,KAAK,CAACH,GAAG,CAACG,KAAK,IAAIR,UAAU,CAACQ,KAAK,EAAEhB,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CAAC,CAC7E;IACL;IAEA,MAAMmB,iBAAiB,GAAG,OAAOL,KAAK,KAAK,UAAU;IACrD,MAAMM,YAAY,GAAG,OAAON,KAAK,KAAK,QAAQ;IAE9C,IAAIK,iBAAiB,IAAIC,YAAY,EAAE;MACnC,OAAO,CAACP,GAAG,EAAEC,KAAK,CAAC;IACvB;IAEA,MAAMO,mBAAmB,GAAGP,KAAkD;IAE9E,OAAO,CAACD,GAAG,EAAElB,qBAAqB,CAAI0B,mBAAmB,EAAEvB,UAAU,EAAEC,UAAU,EAAEC,WAAW,CAAC,CAAC;EACpG,CAAC,CACL,CAAC;AACT,CAAC"}
@@ -91,6 +91,72 @@ describe('styles', () => {
91
91
  fontWeight: 'bold'
92
92
  });
93
93
  });
94
+ it('should correctly parse transform styles', () => {
95
+ const screenSize = {
96
+ width: 400,
97
+ height: 800
98
+ };
99
+ const breakpoint = 'sm';
100
+ const breakpoints = {
101
+ xs: 0,
102
+ sm: 400,
103
+ md: 800
104
+ };
105
+ const style = {
106
+ transform: [{
107
+ translateX: {
108
+ sm: 120,
109
+ md: 200
110
+ },
111
+ translateY: 200
112
+ }]
113
+ };
114
+ expect(parseStyle(style, breakpoint, screenSize, breakpoints)).toEqual({
115
+ transform: [{
116
+ translateX: 120,
117
+ translateY: 200
118
+ }]
119
+ });
120
+ });
121
+ it('should correctly parse shadowOffset styles', () => {
122
+ const screenSize = {
123
+ width: 400,
124
+ height: 800
125
+ };
126
+ const breakpoint = 'sm';
127
+ const breakpoints = {
128
+ xs: 0,
129
+ sm: 400,
130
+ md: 800
131
+ };
132
+ const style = {
133
+ shadowOffset: {
134
+ width: 0,
135
+ height: 4
136
+ }
137
+ };
138
+ const styleWithBreakpoints = {
139
+ shadowOffset: {
140
+ width: 0,
141
+ height: {
142
+ sm: 10,
143
+ md: 20
144
+ }
145
+ }
146
+ };
147
+ expect(parseStyle(style, breakpoint, screenSize, breakpoints)).toEqual({
148
+ shadowOffset: {
149
+ width: 0,
150
+ height: 4
151
+ }
152
+ });
153
+ expect(parseStyle(styleWithBreakpoints, breakpoint, screenSize, breakpoints)).toEqual({
154
+ shadowOffset: {
155
+ width: 0,
156
+ height: 10
157
+ }
158
+ });
159
+ });
94
160
  });
95
161
  });
96
162
  //# sourceMappingURL=styles.spec.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["parseStyle","proxifyFunction","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","toEqual","style","fontSize","fontWeight"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":"AAAA,SAASA,UAAU,EAAEC,eAAe,QAAQ,UAAU;AAGtDC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,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;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAED,MAAM,GACjB,MAAM,GACN;MACV,CAAC,CAAC;MAEFE,MAAM,CAACd,eAAe,CAACW,eAAe,EAAEL,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,CAACQ,OAAO,CAAC;QACzFF,eAAe,EAAE;MACrB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;EAEFZ,QAAQ,CAAC,YAAY,EAAE,MAAM;IACzBC,EAAE,CAAC,+BAA+B,EAAE,MAAM;MACtC,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMM,KAAK,GAAG;QACVC,QAAQ,EAAE;UACNR,EAAE,EAAE,EAAE;UACNC,EAAE,EAAE;QACR,CAAC;QACDG,eAAe,EAAE;UACbL,EAAE,EAAE,MAAM;UACVE,EAAE,EAAE;QACR,CAAC;QACDQ,UAAU,EAAE;MAChB,CAAC;MAEDJ,MAAM,CAACf,UAAU,CAACiB,KAAK,EAAyDV,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACQ,OAAO,CAAC;QAC1HE,QAAQ,EAAE,EAAE;QACZJ,eAAe,EAAE,MAAM;QACvBK,UAAU,EAAE;MAChB,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
1
+ {"version":3,"names":["parseStyle","proxifyFunction","describe","it","screenSize","width","height","breakpoint","breakpoints","xs","sm","md","dynamicFunction","isEven","backgroundColor","expect","toEqual","style","fontSize","fontWeight","transform","translateX","translateY","shadowOffset","styleWithBreakpoints"],"sourceRoot":"../../../src","sources":["utils/styles.spec.ts"],"mappings":"AAAA,SAASA,UAAU,EAAEC,eAAe,QAAQ,UAAU;AAGtDC,QAAQ,CAAC,QAAQ,EAAE,MAAM;EACrBA,QAAQ,CAAC,iBAAiB,EAAE,MAAM;IAC9BC,EAAE,CAAC,yCAAyC,EAAE,MAAM;MAChD,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACbJ,EAAE,EAAEG,MAAM,GACJ,OAAO,GACP,KAAK;UACXF,EAAE,EAAEE,MAAM,GACJ,QAAQ,GACR;QACV;MACJ,CAAC,CAAC;MAEFE,MAAM,CAACd,eAAe,CAACW,eAAe,EAAEL,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC,CAACQ,OAAO,CAAC;QACxFF,eAAe,EAAE;MACrB,CAAC,CAAC;IACN,CAAC,CAAC;IAEFX,EAAE,CAAC,yDAAyD,EAAE,MAAM;MAChE,MAAMC,UAAsB,GAAG;QAC3BC,KAAK,EAAE,GAAG;QACVC,MAAM,EAAE;MACZ,CAAC;MACD,MAAMC,UAAU,GAAG,IAAI;MACvB,MAAMC,WAAW,GAAG;QAChBC,EAAE,EAAE,CAAC;QACLC,EAAE,EAAE,GAAG;QACPC,EAAE,EAAE;MACR,CAAC;MACD,MAAMC,eAAe,GAAIC,MAAe,KAAM;QAC1CC,eAAe,EAAE;UACb,UAAU,EAAED,MAAM,GACZ,OAAO,GACP,KAAK;UACX,SAAS,EAAEA,MAAM,GACX,QAAQ,GACR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CAAC;MACD,MAAMkB,oBAAoB,GAAG;QACzBD,YAAY,EAAE;UACVlB,KAAK,EAAE,CAAC;UACRC,MAAM,EAAE;YACJI,EAAE,EAAE,EAAE;YACNC,EAAE,EAAE;UACR;QACJ;MACJ,CAAC;MAEDI,MAAM,CAACf,UAAU,CAACiB,KAAK,EAAyDV,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACQ,OAAO,CAAC;QAC1HO,YAAY,EAAE;UACVlB,KAAK,EAAE,CAAC;UACRC,MAAM,EAAE;QACZ;MACJ,CAAC,CAAC;MACFS,MAAM,CAACf,UAAU,CAACwB,oBAAoB,EAAyDjB,UAAU,EAAEH,UAAU,EAAEI,WAAW,CAAC,CAAC,CAACQ,OAAO,CAAC;QACzIO,YAAY,EAAE;UACVlB,KAAK,EAAE,CAAC;UACRC,MAAM,EAAE;QACZ;MACJ,CAAC,CAAC;IACN,CAAC,CAAC;EACN,CAAC,CAAC;AACN,CAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAc,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAI3H,eAAO,MAAM,eAAe;;;;;;CAiD3B,CAAA"}
1
+ {"version":3,"file":"createUnistyles.d.ts","sourceRoot":"","sources":["../../../src/createUnistyles.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,mBAAmB,EAAE,iBAAiB,EAAc,kBAAkB,EAAE,oBAAoB,EAAE,MAAM,SAAS,CAAA;AAK3H,eAAO,MAAM,eAAe;;;;;;CAiD3B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { useDimensions } from './useDimensions';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ScreenSize } from '../types';
2
+ export declare const useDimensions: () => ScreenSize;
3
+ //# sourceMappingURL=useDimensions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDimensions.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,aAAa,QAAO,UAOhC,CAAA"}
@@ -0,0 +1,3 @@
1
+ import type { ScreenSize } from '../types';
2
+ export declare const useDimensions: () => ScreenSize;
3
+ //# sourceMappingURL=useDimensions.web.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useDimensions.web.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useDimensions.web.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,UAAU,CAAA;AAE1C,eAAO,MAAM,aAAa,QAAO,UA0BhC,CAAA"}
@@ -2,10 +2,6 @@ import type { CustomNamedStyles, ScreenSize } from '../types';
2
2
  /**
3
3
  * Proxies a function to parse its return value for custom media queries or breakpoints.
4
4
  *
5
- * If the function's string representation contains a custom media query or a defined breakpoint,
6
- * the returned function will be proxied to parse its return value based on the provided screen size and breakpoints.
7
- * If neither is found, the original function is returned.
8
- *
9
5
  * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
10
6
  *
11
7
  * @param {Function} fn - The function to be proxified.
@@ -13,7 +9,7 @@ import type { CustomNamedStyles, ScreenSize } from '../types';
13
9
  * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
14
10
  * @param {B} breakpoints - An object representing the defined breakpoints.
15
11
  *
16
- * @returns {Function} Returns the proxified function or the original function if no custom media query or breakpoint is found in its string representation.
12
+ * @returns {Function} Returns the proxified function
17
13
  *
18
14
  * @example
19
15
  *
@@ -50,7 +46,5 @@ export declare const proxifyFunction: <B extends Record<string, number>>(fn: Fun
50
46
  * const parsedStyle = parseStyle(style, 'sm', screenSize, breakpoints)
51
47
  * // { fontSize: '12px' }
52
48
  */
53
- export declare const parseStyle: <T, B extends Record<string, number>>(style: CustomNamedStyles<T, B>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpoints: B) => {
54
- [k: string]: unknown;
55
- };
49
+ export declare const parseStyle: <T, B extends Record<string, number>>(style: CustomNamedStyles<T, B>, breakpoint: keyof B & string, screenSize: ScreenSize, breakpoints: B) => T;
56
50
  //# sourceMappingURL=styles.d.ts.map
@@ -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;AAG7D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,eAAe,yCACpB,QAAQ,4CACA,UAAU,qBAEvB,QAeF,CAAA;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,kHAGP,UAAU;;CAiBrB,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;AAG7D;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,eAAO,MAAM,eAAe,yCACpB,QAAQ,4CACA,UAAU,qBAEvB,QAGD,CAAA;AAEF;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,eAAO,MAAM,UAAU,kHAGP,UAAU,sBAsCzB,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "1.0.0-beta.1",
3
+ "version": "1.0.0-beta.3",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
6
  "test": "jest",
@@ -1,8 +1,8 @@
1
1
  import { useContext } from 'react'
2
- import { useWindowDimensions } from 'react-native'
3
2
  import type { CreateStylesFactory, CustomNamedStyles, ScreenSize, ExtractBreakpoints, RemoveKeysWithPrefix } from './types'
4
3
  import { UnistylesContext } from './UnistylesTheme'
5
4
  import { getBreakpointFromScreenWidth, proxifyFunction, parseStyle, sortAndValidateBreakpoints } from './utils'
5
+ import { useDimensions } from './hooks'
6
6
 
7
7
  export const createUnistyles = <B extends Record<string, number>, T = {}>(breakpoints: B) => {
8
8
  const sortedBreakpoints = sortAndValidateBreakpoints(breakpoints) as B
@@ -11,7 +11,7 @@ export const createUnistyles = <B extends Record<string, number>, T = {}>(breakp
11
11
  createStyles: <S extends CustomNamedStyles<S, B>>(styles: S | CreateStylesFactory<S, T>) => styles as S,
12
12
  useStyles: <ST extends CustomNamedStyles<ST, B>>(stylesheet?: ST | CreateStylesFactory<ST, T>) => {
13
13
  const theme = useContext(UnistylesContext) as T
14
- const dimensions = useWindowDimensions()
14
+ const dimensions = useDimensions()
15
15
  const breakpoint = getBreakpointFromScreenWidth<B>(dimensions.width, sortedBreakpoints)
16
16
  const screenSize: ScreenSize = {
17
17
  width: dimensions.width,
@@ -0,0 +1 @@
1
+ export { useDimensions } from './useDimensions'
@@ -0,0 +1,11 @@
1
+ import { useWindowDimensions } from 'react-native'
2
+ import type { ScreenSize } from '../types'
3
+
4
+ export const useDimensions = (): ScreenSize => {
5
+ const { width, height } = useWindowDimensions()
6
+
7
+ return {
8
+ width,
9
+ height
10
+ }
11
+ }
@@ -0,0 +1,30 @@
1
+ import { useEffect, useRef, useState } from 'react'
2
+ import type { ScreenSize } from '../types'
3
+
4
+ export const useDimensions = (): ScreenSize => {
5
+ const timerRef = useRef<ReturnType<typeof setTimeout>>()
6
+ const [screenSize, setScreenSize] = useState<ScreenSize>({
7
+ width: window.innerWidth,
8
+ height: window.innerHeight
9
+ })
10
+
11
+ useEffect(() => {
12
+ const handleResize = () => {
13
+ clearTimeout(timerRef.current)
14
+
15
+ timerRef.current = setTimeout(() => setScreenSize({
16
+ width: window.innerWidth,
17
+ height: window.innerHeight
18
+ }), 100)
19
+ }
20
+
21
+ window.addEventListener('resize', handleResize)
22
+
23
+ return () => {
24
+ window.removeEventListener('resize', handleResize)
25
+ clearTimeout(timerRef.current)
26
+ }
27
+ }, [])
28
+
29
+ return screenSize
30
+ }
@@ -4,10 +4,6 @@ import { getValueForBreakpoint } from './breakpoints'
4
4
  /**
5
5
  * Proxies a function to parse its return value for custom media queries or breakpoints.
6
6
  *
7
- * If the function's string representation contains a custom media query or a defined breakpoint,
8
- * the returned function will be proxied to parse its return value based on the provided screen size and breakpoints.
9
- * If neither is found, the original function is returned.
10
- *
11
7
  * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
12
8
  *
13
9
  * @param {Function} fn - The function to be proxified.
@@ -15,7 +11,7 @@ import { getValueForBreakpoint } from './breakpoints'
15
11
  * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
16
12
  * @param {B} breakpoints - An object representing the defined breakpoints.
17
13
  *
18
- * @returns {Function} Returns the proxified function or the original function if no custom media query or breakpoint is found in its string representation.
14
+ * @returns {Function} Returns the proxified function
19
15
  *
20
16
  * @example
21
17
  *
@@ -30,22 +26,10 @@ export const proxifyFunction = <B extends Record<string, number>>(
30
26
  fn: Function, breakpoint: keyof B & string,
31
27
  screenSize: ScreenSize,
32
28
  breakpoints: B
33
- ): Function => {
34
- const stringifiedFunction = fn.toString()
35
- const hasCustomMediaQuery = stringifiedFunction.includes(':w[') || stringifiedFunction.includes(':h[')
36
- const hasBreakpoint = Object
37
- .keys(breakpoints)
38
- .some(bp => stringifiedFunction.includes(bp))
39
-
40
- if (!hasCustomMediaQuery && !hasBreakpoint) {
41
- return fn
42
- }
43
-
44
- return new Proxy(fn, {
45
- apply: (target, thisArg, argumentsList) =>
46
- parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpoints)
47
- })
48
- }
29
+ ): Function => new Proxy(fn, {
30
+ apply: (target, thisArg, argumentsList) =>
31
+ parseStyle(target.apply(thisArg, argumentsList), breakpoint, screenSize, breakpoints)
32
+ })
49
33
 
50
34
  /**
51
35
  * Parses a style object to resolve custom media queries or breakpoints based on the provided screen size and breakpoints.
@@ -77,19 +61,40 @@ export const parseStyle = <T, B extends Record<string, number>>(
77
61
  breakpoint: keyof B & string,
78
62
  screenSize: ScreenSize,
79
63
  breakpoints: B
80
- ) => Object
81
- .fromEntries(Object
82
- .entries(style)
83
- .map(([key, value]) => {
84
- const isDynamicFunction = typeof value === 'function'
85
- const isValidStyle = typeof value !== 'object' || key === 'transform'
64
+ ): T => {
65
+ const entries = Object.entries(style) as [[keyof T, CustomNamedStyles<T, B>]]
66
+
67
+ return Object
68
+ .fromEntries(entries
69
+ .map(([key, value]) => {
70
+ const isNestedStyle = key === 'shadowOffset'
86
71
 
87
- if (isDynamicFunction || isValidStyle) {
88
- return [key, value]
89
- }
72
+ if (isNestedStyle) {
73
+ return [
74
+ key,
75
+ parseStyle(value, breakpoint, screenSize, breakpoints)
76
+ ]
77
+ }
90
78
 
91
- const valueWithBreakpoint = value as Record<keyof B & string, string | number>
79
+ const isTransform = key === 'transform'
92
80
 
93
- return [key, getValueForBreakpoint<B>(valueWithBreakpoint, breakpoint, screenSize, breakpoints)]
94
- })
95
- )
81
+ if (isTransform && Array.isArray(value)) {
82
+ return [
83
+ key,
84
+ value.map(value => parseStyle(value, breakpoint, screenSize, breakpoints))
85
+ ]
86
+ }
87
+
88
+ const isDynamicFunction = typeof value === 'function'
89
+ const isValidStyle = typeof value !== 'object'
90
+
91
+ if (isDynamicFunction || isValidStyle) {
92
+ return [key, value]
93
+ }
94
+
95
+ const valueWithBreakpoint = value as Record<keyof B & string, string | number>
96
+
97
+ return [key, getValueForBreakpoint<B>(valueWithBreakpoint, breakpoint, screenSize, breakpoints)]
98
+ })
99
+ )
100
+ }