react-native-unistyles 1.2.0 → 2.0.0-alpha.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (253) hide show
  1. package/cxx/UnistylesRuntime.cpp +255 -0
  2. package/cxx/UnistylesRuntime.h +60 -0
  3. package/ios/UnistylesHelpers.h +4 -0
  4. package/ios/UnistylesHelpers.mm +20 -0
  5. package/ios/UnistylesModule.h +10 -0
  6. package/ios/UnistylesModule.mm +158 -0
  7. package/lib/commonjs/common.js +26 -0
  8. package/lib/commonjs/common.js.map +1 -0
  9. package/lib/commonjs/core/UnistyleRegistry.js +38 -0
  10. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
  11. package/lib/commonjs/core/Unistyles.js +31 -0
  12. package/lib/commonjs/core/Unistyles.js.map +1 -0
  13. package/lib/commonjs/core/UnistylesModule.js +9 -0
  14. package/lib/commonjs/core/UnistylesModule.js.map +1 -0
  15. package/lib/commonjs/core/UnistylesRuntime.js +66 -0
  16. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
  17. package/lib/commonjs/core/index.js +13 -0
  18. package/lib/commonjs/core/index.js.map +1 -0
  19. package/lib/commonjs/createStyleSheet.js +14 -0
  20. package/lib/commonjs/createStyleSheet.js.map +1 -0
  21. package/lib/commonjs/global.js +2 -0
  22. package/lib/commonjs/global.js.map +1 -0
  23. package/lib/commonjs/hooks/index.js +10 -3
  24. package/lib/commonjs/hooks/index.js.map +1 -1
  25. package/lib/commonjs/hooks/useInitialTheme.js +17 -0
  26. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
  27. package/lib/commonjs/hooks/useUnistyles.js +54 -0
  28. package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
  29. package/lib/commonjs/index.js +35 -6
  30. package/lib/commonjs/index.js.map +1 -1
  31. package/lib/commonjs/types/common.js +2 -0
  32. package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
  33. package/lib/commonjs/types/index.js +11 -0
  34. package/lib/commonjs/types/index.js.map +1 -1
  35. package/lib/commonjs/types/mq.js +6 -0
  36. package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
  37. package/lib/commonjs/types/unistyles.js +6 -0
  38. package/lib/commonjs/types/unistyles.js.map +1 -0
  39. package/lib/commonjs/useStyles.js +49 -0
  40. package/lib/commonjs/useStyles.js.map +1 -0
  41. package/lib/commonjs/utils/breakpoints.js +44 -82
  42. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  43. package/lib/commonjs/utils/common.js +6 -1
  44. package/lib/commonjs/utils/common.js.map +1 -1
  45. package/lib/commonjs/utils/index.js +25 -30
  46. package/lib/commonjs/utils/index.js.map +1 -1
  47. package/lib/commonjs/utils/mq.js +89 -0
  48. package/lib/commonjs/utils/mq.js.map +1 -0
  49. package/lib/commonjs/utils/mqParser.js +86 -0
  50. package/lib/commonjs/utils/mqParser.js.map +1 -0
  51. package/lib/commonjs/utils/styles.js +6 -53
  52. package/lib/commonjs/utils/styles.js.map +1 -1
  53. package/lib/commonjs/utils/variants.js +20 -0
  54. package/lib/commonjs/utils/variants.js.map +1 -0
  55. package/lib/module/common.js +22 -0
  56. package/lib/module/common.js.map +1 -0
  57. package/lib/module/core/UnistyleRegistry.js +31 -0
  58. package/lib/module/core/UnistyleRegistry.js.map +1 -0
  59. package/lib/module/core/Unistyles.js +25 -0
  60. package/lib/module/core/Unistyles.js.map +1 -0
  61. package/lib/module/core/UnistylesModule.js +3 -0
  62. package/lib/module/core/UnistylesModule.js.map +1 -0
  63. package/lib/module/core/UnistylesRuntime.js +59 -0
  64. package/lib/module/core/UnistylesRuntime.js.map +1 -0
  65. package/lib/module/core/index.js +2 -0
  66. package/lib/module/core/index.js.map +1 -0
  67. package/lib/module/createStyleSheet.js +7 -0
  68. package/lib/module/createStyleSheet.js.map +1 -0
  69. package/lib/module/global.js +2 -0
  70. package/lib/module/global.js.map +1 -0
  71. package/lib/module/hooks/index.js +2 -1
  72. package/lib/module/hooks/index.js.map +1 -1
  73. package/lib/module/hooks/useInitialTheme.js +10 -0
  74. package/lib/module/hooks/useInitialTheme.js.map +1 -0
  75. package/lib/module/hooks/useUnistyles.js +47 -0
  76. package/lib/module/hooks/useUnistyles.js.map +1 -0
  77. package/lib/module/index.js +13 -2
  78. package/lib/module/index.js.map +1 -1
  79. package/lib/module/types/common.js +2 -0
  80. package/lib/module/types/common.js.map +1 -0
  81. package/lib/module/types/index.js +1 -0
  82. package/lib/module/types/index.js.map +1 -1
  83. package/lib/module/types/mq.js +2 -0
  84. package/lib/module/types/mq.js.map +1 -0
  85. package/lib/module/types/unistyles.js +2 -0
  86. package/lib/module/types/unistyles.js.map +1 -0
  87. package/lib/module/useStyles.js +42 -0
  88. package/lib/module/useStyles.js.map +1 -0
  89. package/lib/module/utils/breakpoints.js +43 -82
  90. package/lib/module/utils/breakpoints.js.map +1 -1
  91. package/lib/module/utils/common.js +5 -0
  92. package/lib/module/utils/common.js.map +1 -1
  93. package/lib/module/utils/index.js +5 -3
  94. package/lib/module/utils/index.js.map +1 -1
  95. package/lib/module/utils/mq.js +83 -0
  96. package/lib/module/utils/mq.js.map +1 -0
  97. package/lib/module/utils/mqParser.js +79 -0
  98. package/lib/module/utils/mqParser.js.map +1 -0
  99. package/lib/module/utils/styles.js +7 -55
  100. package/lib/module/utils/styles.js.map +1 -1
  101. package/lib/module/utils/variants.js +13 -0
  102. package/lib/module/utils/variants.js.map +1 -0
  103. package/lib/typescript/src/common.d.ts +17 -0
  104. package/lib/typescript/src/common.d.ts.map +1 -0
  105. package/lib/typescript/src/core/UnistyleRegistry.d.ts +15 -0
  106. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
  107. package/lib/typescript/src/core/Unistyles.d.ts +13 -0
  108. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
  109. package/lib/typescript/src/core/UnistylesModule.d.ts +6 -0
  110. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
  111. package/lib/typescript/src/core/UnistylesRuntime.d.ts +24 -0
  112. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
  113. package/lib/typescript/src/core/index.d.ts +2 -0
  114. package/lib/typescript/src/core/index.d.ts.map +1 -0
  115. package/lib/typescript/src/createStyleSheet.d.ts +3 -0
  116. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
  117. package/lib/typescript/src/global.d.ts +7 -0
  118. package/lib/typescript/src/global.d.ts.map +1 -0
  119. package/lib/typescript/src/hooks/index.d.ts +2 -1
  120. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  121. package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
  122. package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
  123. package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
  124. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
  125. package/lib/typescript/src/index.d.ts +14 -2
  126. package/lib/typescript/src/index.d.ts.map +1 -1
  127. package/lib/typescript/src/types/breakpoints.d.ts +12 -13
  128. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  129. package/lib/typescript/src/types/common.d.ts +3 -0
  130. package/lib/typescript/src/types/common.d.ts.map +1 -0
  131. package/lib/typescript/src/types/core.d.ts +34 -18
  132. package/lib/typescript/src/types/core.d.ts.map +1 -1
  133. package/lib/typescript/src/types/index.d.ts +5 -2
  134. package/lib/typescript/src/types/index.d.ts.map +1 -1
  135. package/lib/typescript/src/types/mq.d.ts +3 -0
  136. package/lib/typescript/src/types/mq.d.ts.map +1 -0
  137. package/lib/typescript/src/types/unistyles.d.ts +37 -0
  138. package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
  139. package/lib/typescript/src/useStyles.d.ts +10 -0
  140. package/lib/typescript/src/useStyles.d.ts.map +1 -0
  141. package/lib/typescript/src/utils/breakpoints.d.ts +5 -62
  142. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  143. package/lib/typescript/src/utils/common.d.ts +5 -0
  144. package/lib/typescript/src/utils/common.d.ts.map +1 -1
  145. package/lib/typescript/src/utils/index.d.ts +5 -3
  146. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  147. package/lib/typescript/src/utils/mq.d.ts +21 -0
  148. package/lib/typescript/src/utils/mq.d.ts.map +1 -0
  149. package/lib/typescript/src/utils/mqParser.d.ts +3 -0
  150. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
  151. package/lib/typescript/src/utils/styles.d.ts +4 -49
  152. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  153. package/lib/typescript/src/utils/variants.d.ts +3 -0
  154. package/lib/typescript/src/utils/variants.d.ts.map +1 -0
  155. package/package.json +30 -19
  156. package/react-native-unistyles.podspec +22 -0
  157. package/src/common.ts +19 -0
  158. package/src/core/UnistyleRegistry.ts +41 -0
  159. package/src/core/Unistyles.ts +34 -0
  160. package/src/core/UnistylesModule.ts +7 -0
  161. package/src/core/UnistylesRuntime.ts +73 -0
  162. package/src/core/index.ts +1 -0
  163. package/src/createStyleSheet.ts +9 -0
  164. package/src/global.ts +5 -0
  165. package/src/hooks/index.ts +2 -1
  166. package/src/hooks/useInitialTheme.ts +11 -0
  167. package/src/hooks/useUnistyles.ts +55 -0
  168. package/src/index.ts +30 -2
  169. package/src/types/breakpoints.ts +16 -19
  170. package/src/types/common.ts +2 -0
  171. package/src/types/core.ts +42 -24
  172. package/src/types/index.ts +5 -9
  173. package/src/types/mq.ts +3 -0
  174. package/src/types/unistyles.ts +45 -0
  175. package/src/useStyles.ts +56 -0
  176. package/src/utils/breakpoints.ts +57 -88
  177. package/src/utils/common.ts +6 -0
  178. package/src/utils/index.ts +5 -10
  179. package/src/utils/mq.ts +106 -0
  180. package/src/utils/mqParser.ts +99 -0
  181. package/src/utils/styles.ts +17 -64
  182. package/src/utils/variants.ts +17 -0
  183. package/lib/commonjs/UnistylesTheme.js +0 -21
  184. package/lib/commonjs/UnistylesTheme.js.map +0 -1
  185. package/lib/commonjs/createUnistyles.js +0 -57
  186. package/lib/commonjs/createUnistyles.js.map +0 -1
  187. package/lib/commonjs/hooks/useDimensions.js +0 -10
  188. package/lib/commonjs/hooks/useDimensions.js.map +0 -1
  189. package/lib/commonjs/hooks/useDimensions.web.js +0 -34
  190. package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
  191. package/lib/commonjs/types/mediaQueries.js +0 -2
  192. package/lib/commonjs/utils/mediaQueries.js +0 -189
  193. package/lib/commonjs/utils/mediaQueries.js.map +0 -1
  194. package/lib/module/UnistylesTheme.js +0 -12
  195. package/lib/module/UnistylesTheme.js.map +0 -1
  196. package/lib/module/createUnistyles.js +0 -50
  197. package/lib/module/createUnistyles.js.map +0 -1
  198. package/lib/module/hooks/useDimensions.js +0 -3
  199. package/lib/module/hooks/useDimensions.js.map +0 -1
  200. package/lib/module/hooks/useDimensions.web.js +0 -27
  201. package/lib/module/hooks/useDimensions.web.js.map +0 -1
  202. package/lib/module/types/mediaQueries.js +0 -2
  203. package/lib/module/utils/mediaQueries.js +0 -176
  204. package/lib/module/utils/mediaQueries.js.map +0 -1
  205. package/lib/typescript/examples/expo/src/App.d.ts +0 -3
  206. package/lib/typescript/examples/expo/src/App.d.ts.map +0 -1
  207. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts +0 -3
  208. package/lib/typescript/examples/expo/src/examples/Breakpoints.d.ts.map +0 -1
  209. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts +0 -3
  210. package/lib/typescript/examples/expo/src/examples/EmptyStyles.d.ts.map +0 -1
  211. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts +0 -7
  212. package/lib/typescript/examples/expo/src/examples/Extreme.d.ts.map +0 -1
  213. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts +0 -3
  214. package/lib/typescript/examples/expo/src/examples/MediaQueries.d.ts.map +0 -1
  215. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts +0 -3
  216. package/lib/typescript/examples/expo/src/examples/Memoization.d.ts.map +0 -1
  217. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts +0 -3
  218. package/lib/typescript/examples/expo/src/examples/Minimal.d.ts.map +0 -1
  219. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts +0 -3
  220. package/lib/typescript/examples/expo/src/examples/MinimalWithCreateStyleSheet.d.ts.map +0 -1
  221. package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts +0 -3
  222. package/lib/typescript/examples/expo/src/examples/PlatformColors.d.ts.map +0 -1
  223. package/lib/typescript/examples/expo/src/examples/Theme.d.ts +0 -3
  224. package/lib/typescript/examples/expo/src/examples/Theme.d.ts.map +0 -1
  225. package/lib/typescript/examples/expo/src/examples/index.d.ts +0 -9
  226. package/lib/typescript/examples/expo/src/examples/index.d.ts.map +0 -1
  227. package/lib/typescript/examples/expo/src/index.d.ts +0 -2
  228. package/lib/typescript/examples/expo/src/index.d.ts.map +0 -1
  229. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts +0 -8
  230. package/lib/typescript/examples/expo/src/styles/breakpoints.d.ts.map +0 -1
  231. package/lib/typescript/examples/expo/src/styles/index.d.ts +0 -46
  232. package/lib/typescript/examples/expo/src/styles/index.d.ts.map +0 -1
  233. package/lib/typescript/examples/expo/src/styles/theme.d.ts +0 -24
  234. package/lib/typescript/examples/expo/src/styles/theme.d.ts.map +0 -1
  235. package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
  236. package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
  237. package/lib/typescript/src/createUnistyles.d.ts +0 -10
  238. package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
  239. package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
  240. package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
  241. package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
  242. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
  243. package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
  244. package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
  245. package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
  246. package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
  247. package/src/UnistylesTheme.tsx +0 -17
  248. package/src/__tests__/createUnistyles.spec.tsx +0 -192
  249. package/src/createUnistyles.ts +0 -70
  250. package/src/hooks/useDimensions.ts +0 -4
  251. package/src/hooks/useDimensions.web.ts +0 -34
  252. package/src/types/mediaQueries.ts +0 -10
  253. package/src/utils/mediaQueries.ts +0 -201
@@ -0,0 +1,10 @@
1
+ import { useMemo } from 'react';
2
+ import { unistyles } from '../core';
3
+ export const useInitialTheme = forName => {
4
+ useMemo(() => {
5
+ if (!unistyles.runtime.themeName) {
6
+ unistyles.runtime.setTheme(forName);
7
+ }
8
+ }, []);
9
+ };
10
+ //# sourceMappingURL=useInitialTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","unistyles","useInitialTheme","forName","runtime","themeName","setTheme"],"sourceRoot":"../../../src","sources":["hooks/useInitialTheme.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,SAAS,QAAQ,SAAS;AAGnC,OAAO,MAAMC,eAAe,GAAIC,OAA8B,IAAK;EAC/DH,OAAO,CAAC,MAAM;IACV,IAAI,CAACC,SAAS,CAACG,OAAO,CAACC,SAAS,EAAE;MAC9BJ,SAAS,CAACG,OAAO,CAACE,QAAQ,CAACH,OAAO,CAAC;IACvC;EACJ,CAAC,EAAE,EAAE,CAAC;AACV,CAAC"}
@@ -0,0 +1,47 @@
1
+ import { NativeEventEmitter, NativeModules } from 'react-native';
2
+ import { useEffect, useState } from 'react';
3
+ import { unistyles } from '../core';
4
+ import { CxxUnistylesEventTypes } from '../common';
5
+ const unistylesEvents = new NativeEventEmitter(NativeModules.Unistyles);
6
+ export const useUnistyles = () => {
7
+ const [theme, setTheme] = useState(unistyles.runtime.getTheme(unistyles.runtime.themeName));
8
+ const [layout, setLayout] = useState({
9
+ breakpoint: unistyles.runtime.breakpoint,
10
+ orientation: unistyles.runtime.orientation,
11
+ screenSize: {
12
+ width: unistyles.runtime.screen.width,
13
+ height: unistyles.runtime.screen.height
14
+ }
15
+ });
16
+ useEffect(() => {
17
+ const subscription = unistylesEvents.addListener('onChange', event => {
18
+ switch (event.type) {
19
+ case CxxUnistylesEventTypes.Theme:
20
+ {
21
+ const themeEvent = event;
22
+ return setTheme(unistyles.runtime.getTheme(themeEvent.payload.themeName));
23
+ }
24
+ case CxxUnistylesEventTypes.Layout:
25
+ {
26
+ const layoutEvent = event;
27
+ return setLayout({
28
+ breakpoint: layoutEvent.payload.breakpoint,
29
+ orientation: layoutEvent.payload.orientation,
30
+ screenSize: {
31
+ width: layoutEvent.payload.screen.width,
32
+ height: layoutEvent.payload.screen.height
33
+ }
34
+ });
35
+ }
36
+ default:
37
+ return;
38
+ }
39
+ });
40
+ return subscription.remove;
41
+ }, []);
42
+ return {
43
+ theme,
44
+ layout
45
+ };
46
+ };
47
+ //# sourceMappingURL=useUnistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["NativeEventEmitter","NativeModules","useEffect","useState","unistyles","CxxUnistylesEventTypes","unistylesEvents","Unistyles","useUnistyles","theme","setTheme","runtime","getTheme","themeName","layout","setLayout","breakpoint","orientation","screenSize","width","screen","height","subscription","addListener","event","type","Theme","themeEvent","payload","Layout","layoutEvent","remove"],"sourceRoot":"../../../src","sources":["hooks/useUnistyles.ts"],"mappings":"AAAA,SAASA,kBAAkB,EAAEC,aAAa,QAAQ,cAAc;AAChE,SAASC,SAAS,EAAEC,QAAQ,QAAQ,OAAO;AAC3C,SAASC,SAAS,QAAQ,SAAS;AACnC,SAASC,sBAAsB,QAAQ,WAAW;AAGlD,MAAMC,eAAe,GAAG,IAAIN,kBAAkB,CAACC,aAAa,CAACM,SAAS,CAAC;AAEvE,OAAO,MAAMC,YAAY,GAAGA,CAAA,KAAM;EAC9B,MAAM,CAACC,KAAK,EAAEC,QAAQ,CAAC,GAAGP,QAAQ,CAACC,SAAS,CAACO,OAAO,CAACC,QA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}
@@ -1,3 +1,14 @@
1
- export { UnistylesTheme } from './UnistylesTheme';
2
- export { createUnistyles } from './createUnistyles';
1
+ import { unistyles } from './core';
2
+ import { mq } from './utils';
3
+ import { useInitialTheme } from './hooks';
4
+ import { ScreenOrientation } from './common';
5
+ import { useStyles } from './useStyles';
6
+ import { createStyleSheet } from './createStyleSheet';
7
+ const UnistylesRegistry = {
8
+ addThemes: unistyles.registry.addThemes,
9
+ addBreakpoints: unistyles.registry.addBreakpoints,
10
+ addConfig: unistyles.registry.addConfig
11
+ };
12
+ const UnistylesRuntime = unistyles.runtime;
13
+ export { mq, useStyles, useInitialTheme, createStyleSheet, ScreenOrientation, UnistylesRegistry, UnistylesRuntime };
3
14
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["UnistylesTheme","createUnistyles"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,cAAc,QAAQ,kBAAkB;AACjD,SAASC,eAAe,QAAQ,mBAAmB"}
1
+ {"version":3,"names":["unistyles","mq","useInitialTheme","ScreenOrientation","useStyles","createStyleSheet","UnistylesRegistry","addThemes","registry","addBreakpoints","addConfig","UnistylesRuntime","runtime"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,QAAQ;AAClC,SAASC,EAAE,QAAQ,SAAS;AAC5B,SAASC,eAAe,QAAQ,SAAS;AAEzC,SAASC,iBAAiB,QAAQ,UAAU;AAC5C,SAASC,SAAS,QAAQ,aAAa;AACvC,SAASC,gBAAgB,QAAQ,oBAAoB;AAErD,MAAMC,iBAAiB,GAAG;EACtBC,SAAS,EAAEP,SAAS,CAACQ,QAAQ,CAACD,SAAS;EACvCE,cAAc,EAAET,SAAS,CAACQ,QAAQ,CAACC,cAAc;EACjDC,SAAS,EAAEV,SAAS,CAACQ,QAAQ,CAACE;AAClC,CAAC;AAED,MAAMC,gBAAgB,GAAGX,SAAS,CAACY,OAAO;AAE1C,SACIX,EAAE,EACFG,SAAS,EACTF,eAAe,EACfG,gBAAgB,EAChBF,iBAAiB,EACjBG,iBAAiB,EACjBK,gBAAgB"}
@@ -0,0 +1,2 @@
1
+
2
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/common.ts"],"mappings":""}
@@ -1,2 +1,3 @@
1
1
  export * from './normalizer';
2
+ export * from './unistyles';
2
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"AAAA,cAAc,cAAc"}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":"AAAA,cAAc,cAAc;AAC5B,cAAc,aAAa"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=mq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mq.ts"],"mappings":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=unistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/unistyles.ts"],"mappings":""}
@@ -0,0 +1,42 @@
1
+ import { useMemo } from 'react';
2
+ import { StyleSheet } from 'react-native';
3
+ import { parseStyle, proxifyFunction } from './utils';
4
+ import { useUnistyles } from './hooks';
5
+ export const useStyles = (stylesheet, variant) => {
6
+ const {
7
+ theme,
8
+ layout
9
+ } = useUnistyles();
10
+ const {
11
+ screenSize,
12
+ breakpoint
13
+ } = layout;
14
+ if (!stylesheet) {
15
+ return {
16
+ theme,
17
+ breakpoint,
18
+ styles: {}
19
+ };
20
+ }
21
+ const parsedStyles = useMemo(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
22
+ const dynamicStyleSheet = useMemo(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
23
+ let [key, value] = _ref;
24
+ const style = value;
25
+ if (typeof value === 'function') {
26
+ return {
27
+ ...acc,
28
+ [key]: proxifyFunction(value, breakpoint, screenSize, variant)
29
+ };
30
+ }
31
+ return StyleSheet.create({
32
+ ...acc,
33
+ [key]: parseStyle(style, breakpoint, screenSize, variant)
34
+ });
35
+ }, {}), [breakpoint, screenSize, parsedStyles, variant]);
36
+ return {
37
+ theme,
38
+ breakpoint,
39
+ styles: dynamicStyleSheet
40
+ };
41
+ };
42
+ //# sourceMappingURL=useStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","StyleSheet","parseStyle","proxifyFunction","useUnistyles","useStyles","stylesheet","variant","theme","layout","screenSize","breakpoint","styles","parsedStyles","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","create"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":"AAAA,SAASA,OAAO,QAAQ,OAAO;AAC/B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,UAAU,EAAEC,eAAe,QAAQ,SAAS;AAErD,SAASC,YAAY,QAAQ,SAAS;AAStC,OAAO,MAAMC,SAAS,GAAGA,CACrBC,UAAyD,EACzDC,OAAgB,KACO;EACvB,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAGL,YAAY,CAAC,CAAC;EACxC,MAAM;IAAEM,UAAU;IAAEC;EAAW,CAAC,GAAGF,MAAM;EAEzC,IAAI,CAACH,UAAU,EAAE;IACb,OAAO;MACHE,KAAK;MACLG,UAAU;MACVC,MAAM,EAAE,CAAC;IACb,CAAC;EACL;EAEA,MAAMC,YAAY,GAAGb,OAAO,CAAC,MAAM,OAAOM,UAAU,KAAK,UAAU,GAC7DA,UAAU,CAACE,KAAK,CAAC,GACjBF,UAAU,EAAE,CAACE,KAAK,EAAEF,UAAU,CAAC,CAAC;EAEtC,MAAMQ,iBAAiB,GAAGd,OAAO,CAAC,MAAMe,MAAM,CACzCC,OAAO,CAACH,YAAY,CAAC,CACrBI,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACtB,MAAMG,KAAK,GAAGD,KAA8B;IAE5C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MAC7B,OAAO;QACH,GAAGH,GAAG;QACN,CAACE,GAAG,GAAGjB,eAAe,CAACkB,KAAK,EAAEV,UAAU,EAAED,UAAU,EAAEH,OAAO;MACjE,CAAC;IACL;IAEA,OAAON,UAAU,CAACsB,MAAM,CAAC;MACrB,GAAGL,GAAG;MACN,CAACE,GAAG,GAAGlB,UAAU,CAAKoB,KAAK,EAAEX,UAAU,EAAED,UAAU,EAAEH,OAAO;IAChE,CAAC,CAAC;EACN,CAAC,EAAE,CAAC,CAAO,CAAC,EAAE,CAACI,UAAU,EAAED,UAAU,EAAEG,YAAY,EAAEN,OAAO,CAAC,CAA8B;EAE/F,OAAO;IACHC,KAAK;IACLG,UAAU;IACVC,MAAM,EAAEE;EACZ,CAAC;AACL,CAAC"}
@@ -1,25 +1,8 @@
1
- import { throwError } from './common';
2
- import { getKeyForCustomMediaQuery, isMediaQuery } from './mediaQueries';
3
-
4
- /**
5
- * Sorts the breakpoints object based on its numeric values in ascending order and validates them.
6
- *
7
- * This function takes an object where keys represent breakpoint names and values are numeric.
8
- * It returns a new object with the same keys but sorted based on their corresponding numeric values.
9
- * Additionally, it validates that:
10
- * 1. The first breakpoint starts with a value of 0.
11
- * 2. No duplicate breakpoint values exist.
12
- *
13
- * If the validation fails, appropriate error messages are logged to the console.
14
- *
15
- * @template B - An object type where keys are strings and values are numbers.
16
- * @param {B} breakpoints - The breakpoints object to be sorted and validated.
17
- * @returns {B} A new object with sorted and validated breakpoints.
18
- *
19
- * @example
20
- * const input = { md: 768, lg: 1024, sm: 0 }
21
- * sortAndValidateBreakpoints(input) // returns { sm: 0, md: 768, lg: 1024 }
22
- */
1
+ import { unistyles } from '../core';
2
+ import { isMobile, Orientation, throwError } from './common';
3
+ import { ScreenOrientation } from '../common';
4
+ import { getKeyForUnistylesMediaQuery } from './mqParser';
5
+ import { getKeyForVariant } from './variants';
23
6
  export const sortAndValidateBreakpoints = breakpoints => {
24
7
  const sortedPairs = Object.entries(breakpoints).sort((breakpoint1, breakpoint2) => {
25
8
  const [, value1] = breakpoint1;
@@ -37,22 +20,6 @@ export const sortAndValidateBreakpoints = breakpoints => {
37
20
  }
38
21
  return sortedBreakpoints;
39
22
  };
40
-
41
- /**
42
- * Determines the appropriate breakpoint key for a given screen width based on provided breakpoints.
43
- *
44
- * This function takes a screen width and an object of breakpoints. It returns the key of the breakpoint
45
- * that the screen width falls into. The breakpoints are assumed to be sorted in ascending order.
46
- *
47
- * @template B - An object type where keys are strings and values are numbers representing screen widths.
48
- * @param {number} width - The screen width to determine the breakpoint for.
49
- * @param breakpointEntries - sorted pairs of breakpoints
50
- * @returns {keyof B & string} The key of the breakpoint that the screen width falls into.
51
- *
52
- * @example
53
- * const breakpoints = { sm: 0, md: 768, lg: 1024 }
54
- * getBreakpointFromScreenWidth(800, breakpoints) // returns 'md'
55
- */
56
23
  export const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
57
24
  const [key] = breakpointEntries.find((_ref, index, otherBreakpoints) => {
58
25
  let [, value] = _ref;
@@ -66,60 +33,54 @@ export const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
66
33
  return key;
67
34
  };
68
35
 
69
- /**
70
- * Retrieves the value associated with a given breakpoint or custom media query based on the provided screen size.
71
- *
72
- * The function first checks for custom media queries. If a matching custom media query is found, its associated value is returned.
73
- * If no custom media query matches, the function then checks for a direct breakpoint match.
74
- * If there's no direct breakpoint match, the function simulates CSS cascading to find the closest matching breakpoint.
75
- *
76
- * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
77
- *
78
- * @param {Record<keyof B & string, string | number>} value - An object containing values associated with breakpoints or custom media queries.
79
- * @param {keyof B & string} breakpoint - The breakpoint name to check against.
80
- * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
81
- * @param breakpointPairs - sorted pairs of breakpoints
82
- *
83
- * @returns {string | number | undefined} Returns the value associated with the matching breakpoint or custom media query, or `undefined` if no match is found.
84
- *
85
- * @example
86
- *
87
- * const values = { ':w[200]': 'value1', sm: 'value2', md: 'value3' }
88
- * const screenSize = { width: 250, height: 400 }
89
- * const breakpoints = { sm: 300, md: 600, lg: 900 }
90
- *
91
- * getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
92
- */
93
- export const getValueForBreakpoint = (value, breakpoint, screenSize, breakpointPairs) => {
94
- // the highest priority is for custom media queries
95
- const customMediaQueries = Object.entries(value).filter(_ref2 => {
96
- let [key] = _ref2;
97
- return isMediaQuery(key);
98
- });
99
- const customMediaQueryKey = getKeyForCustomMediaQuery(customMediaQueries, screenSize);
100
- if (customMediaQueryKey && customMediaQueryKey in value) {
36
+ // todo move it to different file
37
+ export const getValueForNestedStyle = (value, variant) => {
38
+ // the highest priority is for variants
39
+ const variantKey = getKeyForVariant(value, variant);
40
+ if (variantKey) {
41
+ return value.variants[variantKey];
42
+ }
43
+
44
+ // then custom media queries
45
+ const customMediaQueryKey = getKeyForUnistylesMediaQuery(Object.entries(value), unistyles.runtime.screen);
46
+ if (customMediaQueryKey) {
101
47
  return value[customMediaQueryKey];
102
48
  }
103
49
 
104
- // if no custom media query, or didn't match, proceed with defined breakpoints
105
- const unifiedKey = breakpoint;
106
- const directBreakpoint = value[unifiedKey];
50
+ // at this point user didn't use custom media queries (:w, :h)
51
+ // check if user defined any breakpoints
52
+ const hasBreakpoints = unistyles.runtime.sortedBreakpoints.length > 0;
53
+
54
+ // if not then we can fall back to horizontal and portrait (mobile only)
55
+ if (!hasBreakpoints && isMobile && (Orientation.Landscape in value || Orientation.Portrait in value)) {
56
+ return value[unistyles.runtime.orientation === ScreenOrientation.Portrait ? Orientation.Portrait : Orientation.Landscape];
57
+ }
58
+
59
+ // let's get the current breakpoint
60
+ const breakpoint = unistyles.runtime.breakpoint;
61
+ if (!breakpoint) {
62
+ return undefined;
63
+ }
64
+
65
+ // if user defined breakpoints, then we look for the valid one
66
+ const directBreakpoint = value[breakpoint];
107
67
 
108
68
  // if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
109
- if (directBreakpoint || unifiedKey in value) {
69
+ if (directBreakpoint || breakpoint in value) {
110
70
  return directBreakpoint;
111
71
  }
112
72
 
113
- // there is no direct hit for breakpoint nor media-query, so let's simulate CSS cascading
114
- const currentBreakpoint = breakpointPairs.findIndex(_ref3 => {
115
- let [key] = _ref3;
116
- return key === unifiedKey;
73
+ // there is no direct hit for breakpoint nor media-query, let's simulate CSS cascading
74
+ const breakpointPairs = unistyles.runtime.sortedBreakpoints;
75
+ const currentBreakpoint = breakpointPairs.findIndex(_ref2 => {
76
+ let [key] = _ref2;
77
+ return key === breakpoint;
117
78
  });
118
- const availableBreakpoints = breakpointPairs.filter((_ref4, index) => {
119
- let [key] = _ref4;
79
+ const availableBreakpoints = breakpointPairs.filter((_ref3, index) => {
80
+ let [key] = _ref3;
120
81
  return index < currentBreakpoint && key && key in value;
121
- }).map(_ref5 => {
122
- let [key] = _ref5;
82
+ }).map(_ref4 => {
83
+ let [key] = _ref4;
123
84
  return key;
124
85
  });
125
86
  return breakpointPairs.length > 0 ? value[availableBreakpoints[availableBreakpoints.length - 1]] : undefined;
@@ -1 +1 @@
1
- {"version":3,"names":["throwError","getKeyForCustomMediaQuery","isMediaQuery","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","length","Set","size","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","breakpoint","screenSize","breakpointPairs","customMediaQueries","filter","_ref2","customMediaQueryKey","unifiedKey","directBreakpoint","currentBreakpoint","findIndex","_ref3","availableBreakpoints","_ref4","map","_ref5","undefined"],"sourceRoot":"../../../src","sources":["utils/breakpoints.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AA,EAAC;EAE7C,MAAMK,oBAAoB,GAAGV,eAAe,CACvCE,MAAM,CAAC,CAAAS,KAAA,EAAQnB,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAAsB,KAAA;IAAA,OAAYnB,KAAK,GAAGe,iBAAiB,IAAIlB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1EkB,GAAG,CAACC,KAAA;IAAA,IAAC,CAACxB,GAAG,CAAC,GAAAwB,KAAA;IAAA,OAAKxB,GAAG;EAAA,EAAC;EAExB,OAAOW,eAAe,CAACjB,MAAM,GAAG,CAAC,GAC3BW,KAAK,CAACgB,oBAAoB,CAACA,oBAAoB,CAAC3B,MAAM,GAAG,CAAC,CAAC,CAAqB,GAChF+B,SAAS;AACnB,CAAC"}
1
+ {"version":3,"names":["unistyles","isMobile","Orientation","throwError","ScreenOrientation","getKeyForUnistylesMediaQuery","getKeyForVariant","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","length","Set","size","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForNestedStyle","variant","variantKey","variants","customMediaQueryKey","runtime","screen","hasBreakpoints","Landscape","Portrait","orientation","breakpoint","undefined","directBreakpoint","breakpointPairs","currentBreakpoint","findIndex","_ref2","availableBreakpoints","filter","_ref3","map","_ref4"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":"AAAA,SAASA,SAAS,QAAQ,SAAS;AACnC,SAASC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,QAAQ,UAAU;AAG5D,SAASC,iBAAiB,QAAQ,WAAW;AAC7C,SAASC,4BAA4B,QAAQ,YAAY;AACzD,SAASC,gBAAgB,QAAQ,YAAY;AAE7C,OAAO,MAAMC,0BAA0B,GAAIC,WAAiC,IAA2B;EACnG,MAAMC,WAAW,GAAG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A,IAAC,CAACzB,GAAG,CAAC,GAAAyB,KAAA;IAAA,OAAKzB,GAAG,KAAKmB,UAAU;EAAA,EAAC;EAE7C,MAAMO,oBAAoB,GAAGJ,eAAe,CACvCK,MAAM,CAAC,CAAAC,KAAA,EAAQzB,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAA4B,KAAA;IAAA,OAAYzB,KAAK,GAAGoB,iBAAiB,IAAIvB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1EwB,GAAG,CAACC,KAAA;IAAA,IAAC,CAAC9B,GAAG,CAAC,GAAA8B,KAAA;IAAA,OAAK9B,GAAG;EAAA,EAAC;EAExB,OAAOsB,eAAe,CAAC5B,MAAM,GAAG,CAAC,GAC3BW,KAAK,CAACqB,oBAAoB,CAACA,oBAAoB,CAAChC,MAAM,GAAG,CAAC,CAAC,CAAwC,GACnG0B,SAAS;AACnB,CAAC"}
@@ -5,8 +5,13 @@ export const throwError = message => {
5
5
  export const warn = message => {
6
6
  console.warn(`🦄 [react-native-unistyles]: ${message}`);
7
7
  };
8
+ export const isMobile = Platform.OS === 'android' || Platform.OS === 'ios';
8
9
  export const isWeb = Platform.OS === 'web';
9
10
  export const isIOS = Platform.OS === 'ios';
10
11
  export const isAndroid = Platform.OS === 'android';
11
12
  export const isServer = typeof window === 'undefined';
13
+ export const Orientation = {
14
+ Landscape: 'landscape',
15
+ Portrait: 'portrait'
16
+ };
12
17
  //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["Platform","throwError","message","Error","warn","console","isWeb","OS","isIOS","isAndroid","isServer","window"],"sourceRoot":"../../../src","sources":["utils/common.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,UAAU,GAAIC,OAAe,IAAK;EAC3C,MAAM,IAAIC,KAAK,CAAE,gCAA+BD,OAAQ,EAAC,CAAC;AAC9D,CAAC;AAED,OAAO,MAAME,IAAI,GAAIF,OAAe,IAAK;EACrCG,OAAO,CAACD,IAAI,CAAE,gCAA+BF,OAAQ,EAAC,CAAC;AAC3D,CAAC;AAED,OAAO,MAAMI,KAAK,GAAGN,QAAQ,CAACO,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAMC,KAAK,GAAGR,QAAQ,CAACO,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAME,SAAS,GAAGT,QAAQ,CAACO,EAAE,KAAK,SAAS;AAClD,OAAO,MAAMG,QAAQ,GAAG,OAAOC,MAAM,KAAK,WAAW"}
1
+ {"version":3,"names":["Platform","throwError","message","Error","warn","console","isMobile","OS","isWeb","isIOS","isAndroid","isServer","window","Orientation","Landscape","Portrait"],"sourceRoot":"../../../src","sources":["utils/common.ts"],"mappings":"AAAA,SAASA,QAAQ,QAAQ,cAAc;AAEvC,OAAO,MAAMC,UAAU,GAAIC,OAAe,IAAK;EAC3C,MAAM,IAAIC,KAAK,CAAE,gCAA+BD,OAAQ,EAAC,CAAC;AAC9D,CAAC;AAED,OAAO,MAAME,IAAI,GAAIF,OAAe,IAAK;EACrCG,OAAO,CAACD,IAAI,CAAE,gCAA+BF,OAAQ,EAAC,CAAC;AAC3D,CAAC;AAED,OAAO,MAAMI,QAAQ,GAAGN,QAAQ,CAACO,EAAE,KAAK,SAAS,IAAIP,QAAQ,CAACO,EAAE,KAAK,KAAK;AAC1E,OAAO,MAAMC,KAAK,GAAGR,QAAQ,CAACO,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAME,KAAK,GAAGT,QAAQ,CAACO,EAAE,KAAK,KAAK;AAC1C,OAAO,MAAMG,SAAS,GAAGV,QAAQ,CAACO,EAAE,KAAK,SAAS;AAClD,OAAO,MAAMI,QAAQ,GAAG,OAAOC,MAAM,KAAK,WAAW;AAErD,OAAO,MAAMC,WAAW,GAAG;EACvBC,SAAS,EAAE,WAAW;EACtBC,QAAQ,EAAE;AACd,CAAU"}
@@ -1,7 +1,9 @@
1
1
  export { normalizeStyles } from './normalizeStyles';
2
2
  export * from './normalizer';
3
- export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForBreakpoint } from './breakpoints';
3
+ export { mq, MQSymbol } from './mq';
4
+ export { getKeyForVariant } from './variants';
5
+ export { getKeyForUnistylesMediaQuery } from './mqParser';
6
+ export { getBreakpointFromScreenWidth, sortAndValidateBreakpoints, getValueForNestedStyle } from './breakpoints';
4
7
  export { proxifyFunction, parseStyle } from './styles';
5
- export { isServer } from './common';
6
- export { extractValues, getKeyForCustomMediaQuery, isMediaQuery, isWithinTheHeight, isWithinTheWidth, isWithinTheWidthAndHeight } from './mediaQueries';
8
+ export { isServer, Orientation } from './common';
7
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["normalizeStyles","getBreakpointFromScreenWidth","sortAndValidateBreakpoints","getValueForBreakpoint","proxifyFunction","parseStyle","isServer","extractValues","getKeyForCustomMediaQuery","isMediaQuery","isWithinTheHeight","isWithinTheWidth","isWithinTheWidthAndHeight"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,cAAc,cAAc;AAC5B,SAASC,4BAA4B,EAAEC,0BAA0B,EAAEC,qBAAqB,QAAQ,eAAe;AAC/G,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SAASC,QAAQ,QAAQ,UAAU;AACnC,SACIC,aAAa,EACbC,yBAAyB,EACzBC,YAAY,EACZC,iBAAiB,EACjBC,gBAAgB,EAChBC,yBAAyB,QACtB,gBAAgB"}
1
+ {"version":3,"names":["normalizeStyles","mq","MQSymbol","getKeyForVariant","getKeyForUnistylesMediaQuery","getBreakpointFromScreenWidth","sortAndValidateBreakpoints","getValueForNestedStyle","proxifyFunction","parseStyle","isServer","Orientation"],"sourceRoot":"../../../src","sources":["utils/index.ts"],"mappings":"AAAA,SAASA,eAAe,QAAQ,mBAAmB;AACnD,cAAc,cAAc;AAC5B,SAASC,EAAE,EAAEC,QAAQ,QAAQ,MAAM;AACnC,SAASC,gBAAgB,QAAQ,YAAY;AAC7C,SAASC,4BAA4B,QAAQ,YAAY;AACzD,SAASC,4BAA4B,EAAEC,0BAA0B,EAAEC,sBAAsB,QAAQ,eAAe;AAChH,SAASC,eAAe,EAAEC,UAAU,QAAQ,UAAU;AACtD,SAASC,QAAQ,EAAEC,WAAW,QAAQ,UAAU"}
@@ -0,0 +1,83 @@
1
+ import { unistyles } from '../core';
2
+ export const MQSymbol = Symbol('unistyles-mq');
3
+ var MQProp = /*#__PURE__*/function (MQProp) {
4
+ MQProp["toString"] = "toString";
5
+ MQProp["width"] = "width";
6
+ MQProp["height"] = "height";
7
+ MQProp["shortW"] = "w";
8
+ MQProp["shortH"] = "h";
9
+ return MQProp;
10
+ }(MQProp || {});
11
+ const getMQValue = value => {
12
+ if (typeof value === 'number') {
13
+ return value;
14
+ }
15
+ if (value === null) {
16
+ return 0;
17
+ }
18
+ return unistyles.registry.breakpoints[value] ?? 0;
19
+ };
20
+ const widthHandler = function () {
21
+ let hMin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
22
+ let hMax = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
23
+ return new Proxy({}, {
24
+ get: (target, prop, receiver) => {
25
+ if (prop === Symbol.toPrimitive || prop === MQProp.toString) {
26
+ return () => `:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`;
27
+ }
28
+ if (prop === MQProp.width || prop === MQProp.shortW) {
29
+ return function () {
30
+ let wMin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
31
+ let wMax = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
32
+ return new Proxy({}, {
33
+ get: (target, prop, receiver) => {
34
+ if (prop === Symbol.toPrimitive || prop === MQProp.toString) {
35
+ return () => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`;
36
+ }
37
+ return Reflect.get(target, prop, receiver);
38
+ }
39
+ });
40
+ };
41
+ }
42
+ return Reflect.get(target, prop, receiver);
43
+ }
44
+ });
45
+ };
46
+ const heightHandler = function () {
47
+ let wMin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
48
+ let wMax = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
49
+ return new Proxy({}, {
50
+ get: (target, prop, receiver) => {
51
+ if (prop === Symbol.toPrimitive || prop === MQProp.toString) {
52
+ return () => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]`;
53
+ }
54
+ if (prop === MQProp.height || prop === MQProp.shortH) {
55
+ return function () {
56
+ let hMin = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
57
+ let hMax = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : Infinity;
58
+ return new Proxy({}, {
59
+ get: (target, prop, receiver) => {
60
+ if (prop === Symbol.toPrimitive || MQProp.toString) {
61
+ return () => `:w[${getMQValue(wMin)}, ${getMQValue(wMax)}]:h[${getMQValue(hMin)}, ${getMQValue(hMax)}]`;
62
+ }
63
+ return Reflect.get(target, prop, receiver);
64
+ }
65
+ });
66
+ };
67
+ }
68
+ return Reflect.get(target, prop, receiver);
69
+ }
70
+ });
71
+ };
72
+ export const mq = new Proxy({}, {
73
+ get: (target, prop, receiver) => {
74
+ if (prop === MQProp.shortW || prop === MQProp.width) {
75
+ return heightHandler;
76
+ }
77
+ if (prop === MQProp.shortH || prop === MQProp.height) {
78
+ return widthHandler;
79
+ }
80
+ return Reflect.get(target, prop, receiver);
81
+ }
82
+ });
83
+ //# sourceMappingURL=mq.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["unistyles","MQSymbol","Symbol","MQProp","getMQValue","value","registry","breakpoints","widthHandler","hMin","arguments","length","undefined","hMax","Infinity","Proxy","get","target","prop","receiver","toPrimitive","toString","width","shortW","wMin","wMax","Reflect","heightHandler","height","shortH","mq"],"sourceRoot":"../../../src","sources":["utils/mq.ts"],"mappings":"AAEA,SAASA,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pB,YAAY;IACvB;IAEA,OAAOkB,OAAO,CAACV,GAAG,CAACC,MAAM,EAAEC,IAAI,EAAEC,QAAQ,CAAC;EAC9C;AACJ,CAAC,CAAC"}
@@ -0,0 +1,79 @@
1
+ const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/;
2
+ const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
3
+ const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/;
4
+ const parseMq = mq => {
5
+ const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || [];
6
+ const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || [];
7
+ return {
8
+ width: width ? {
9
+ from: Number(fromW),
10
+ to: Number(toW)
11
+ } : undefined,
12
+ height: height ? {
13
+ from: Number(fromH),
14
+ to: Number(toH)
15
+ } : undefined
16
+ };
17
+ };
18
+ const isUnistylesMq = mq => IS_UNISTYLES_REGEX.test(mq);
19
+ const isValidMq = parsedMq => {
20
+ const {
21
+ width,
22
+ height
23
+ } = parsedMq;
24
+ if (width && height) {
25
+ return width.from <= width.to && height.from <= height.to;
26
+ }
27
+ if (width) {
28
+ return width.from <= width.to;
29
+ }
30
+ if (height) {
31
+ return height.from <= height.to;
32
+ }
33
+ return false;
34
+ };
35
+ const isWithinTheWidthAndHeight = (parsedMq, screenSize) => {
36
+ const {
37
+ width,
38
+ height
39
+ } = parsedMq;
40
+ if (width && height) {
41
+ return isWithinTheWidth(width, screenSize.width) && isWithinTheHeight(height, screenSize.height);
42
+ }
43
+ if (width) {
44
+ return isWithinTheWidth(width, screenSize.width);
45
+ }
46
+ if (height) {
47
+ return isWithinTheHeight(height, screenSize.height);
48
+ }
49
+ return false;
50
+ };
51
+ const isWithinTheWidth = (width, screenWidth) => {
52
+ const {
53
+ from,
54
+ to
55
+ } = width;
56
+ return screenWidth >= from && screenWidth <= to;
57
+ };
58
+ const isWithinTheHeight = (height, screenHeight) => {
59
+ const {
60
+ from,
61
+ to
62
+ } = height;
63
+ return screenHeight >= from && screenHeight <= to;
64
+ };
65
+ export const getKeyForUnistylesMediaQuery = (mediaQueries, screenSize) => {
66
+ const mq = mediaQueries.find(_ref => {
67
+ let [key] = _ref;
68
+ if (!isUnistylesMq(key)) {
69
+ return false;
70
+ }
71
+ const parsedMq = parseMq(key);
72
+ if (!isValidMq(parsedMq)) {
73
+ return false;
74
+ }
75
+ return isWithinTheWidthAndHeight(parsedMq, screenSize);
76
+ });
77
+ return mq?.at(0);
78
+ };
79
+ //# sourceMappingURL=mqParser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["IS_UNISTYLES_REGEX","UNISTYLES_WIDTH_REGEX","UNISTYLES_HEIGHT_REGEX","parseMq","mq","width","fromW","toW","exec","height","fromH","toH","from","Number","to","undefined","isUnistylesMq","test","isValidMq","parsedMq","isWithinTheWidthAndHeight","screenSize","isWithinTheWidth","isWithinTheHeight","screenWidth","screenHeight","getKeyForUnistylesMediaQuery","mediaQueries","find","_ref","key","at"],"sourceRoot":"../../../src","sources":["utils/mqParser.ts"],"mappings":"AAEA,MAAMA,kBAAkB,GAAG,wCAAwC;AACnE,MAAMC,qBAAqB,GAAG,qCAAqC;AACnE,MAAMC,sBAAsB,GAAG,qCAAqC;AAYpE,MAAMC,OAAO,GAAIC,EAAU,IAAwB;EAC/C,MAAM,GAAGC,KAAK,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGN,qBAAqB,CAACO,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAClE,MAAM,GAAGK,MAAM,EAAEC,KAAK,EAAEC,GAAG,CAAC,GAAGT,sBAAsB,CAACM,IAAI,CAACJ,EAAE,CAAC,IAAI,EAAE;EAEpE,OAAO;IACHC,KAAK,EAAEA,KAAK,GAAG;MACXO,IAAI,EAAEC,MAAM,CAACP,KAAK,CAAC;MACnBQ,EAAE,EAAED,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