react-native-unistyles 2.0.0-alpha.1 → 2.0.0-alpha.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (257) hide show
  1. package/README.md +4 -4
  2. package/cxx/UnistylesRuntime.cpp +255 -0
  3. package/cxx/UnistylesRuntime.h +60 -0
  4. package/ios/UnistylesHelpers.h +4 -0
  5. package/ios/UnistylesHelpers.mm +20 -0
  6. package/ios/UnistylesModule.h +10 -0
  7. package/ios/UnistylesModule.mm +158 -0
  8. package/lib/commonjs/common.js +26 -0
  9. package/lib/commonjs/common.js.map +1 -0
  10. package/lib/commonjs/core/UnistyleRegistry.js +38 -0
  11. package/lib/commonjs/core/UnistyleRegistry.js.map +1 -0
  12. package/lib/commonjs/core/Unistyles.js +31 -0
  13. package/lib/commonjs/core/Unistyles.js.map +1 -0
  14. package/lib/commonjs/core/UnistylesModule.js +9 -0
  15. package/lib/commonjs/core/UnistylesModule.js.map +1 -0
  16. package/lib/commonjs/core/UnistylesRuntime.js +66 -0
  17. package/lib/commonjs/core/UnistylesRuntime.js.map +1 -0
  18. package/lib/commonjs/core/index.js +13 -0
  19. package/lib/commonjs/core/index.js.map +1 -0
  20. package/lib/commonjs/createStyleSheet.js +14 -0
  21. package/lib/commonjs/createStyleSheet.js.map +1 -0
  22. package/lib/commonjs/global.js +2 -0
  23. package/lib/commonjs/global.js.map +1 -0
  24. package/lib/commonjs/hooks/index.js +10 -3
  25. package/lib/commonjs/hooks/index.js.map +1 -1
  26. package/lib/commonjs/hooks/useInitialTheme.js +17 -0
  27. package/lib/commonjs/hooks/useInitialTheme.js.map +1 -0
  28. package/lib/commonjs/hooks/useUnistyles.js +54 -0
  29. package/lib/commonjs/hooks/useUnistyles.js.map +1 -0
  30. package/lib/commonjs/index.js +35 -6
  31. package/lib/commonjs/index.js.map +1 -1
  32. package/lib/commonjs/types/common.js +2 -0
  33. package/lib/commonjs/types/{mediaQueries.js.map → common.js.map} +1 -1
  34. package/lib/commonjs/types/index.js +26 -0
  35. package/lib/commonjs/types/index.js.map +1 -1
  36. package/lib/commonjs/types/mq.js +6 -0
  37. package/lib/{module/types/mediaQueries.js.map → commonjs/types/mq.js.map} +1 -1
  38. package/lib/commonjs/types/normalizer.js +6 -0
  39. package/lib/commonjs/types/normalizer.js.map +1 -0
  40. package/lib/commonjs/types/unistyles.js +6 -0
  41. package/lib/commonjs/types/unistyles.js.map +1 -0
  42. package/lib/commonjs/types/variants.js +2 -0
  43. package/lib/commonjs/types/variants.js.map +1 -0
  44. package/lib/commonjs/useStyles.js +49 -0
  45. package/lib/commonjs/useStyles.js.map +1 -0
  46. package/lib/commonjs/utils/breakpoints.js +33 -80
  47. package/lib/commonjs/utils/breakpoints.js.map +1 -1
  48. package/lib/commonjs/utils/common.js +10 -3
  49. package/lib/commonjs/utils/common.js.map +1 -1
  50. package/lib/commonjs/utils/index.js +46 -17
  51. package/lib/commonjs/utils/index.js.map +1 -1
  52. package/lib/commonjs/utils/module.d.js +2 -0
  53. package/lib/commonjs/utils/module.d.js.map +1 -0
  54. package/lib/commonjs/utils/mq.js +89 -0
  55. package/lib/commonjs/utils/mq.js.map +1 -0
  56. package/lib/commonjs/utils/mqParser.js +86 -0
  57. package/lib/commonjs/utils/mqParser.js.map +1 -0
  58. package/lib/commonjs/utils/normalizeStyles.web.js +13 -13
  59. package/lib/commonjs/utils/normalizeStyles.web.js.map +1 -1
  60. package/lib/commonjs/utils/normalizer.js +89 -0
  61. package/lib/commonjs/utils/normalizer.js.map +1 -0
  62. package/lib/commonjs/utils/styles.js +29 -58
  63. package/lib/commonjs/utils/styles.js.map +1 -1
  64. package/lib/commonjs/utils/variants.js +17 -0
  65. package/lib/commonjs/utils/variants.js.map +1 -0
  66. package/lib/module/common.js +22 -0
  67. package/lib/module/common.js.map +1 -0
  68. package/lib/module/core/UnistyleRegistry.js +31 -0
  69. package/lib/module/core/UnistyleRegistry.js.map +1 -0
  70. package/lib/module/core/Unistyles.js +25 -0
  71. package/lib/module/core/Unistyles.js.map +1 -0
  72. package/lib/module/core/UnistylesModule.js +3 -0
  73. package/lib/module/core/UnistylesModule.js.map +1 -0
  74. package/lib/module/core/UnistylesRuntime.js +59 -0
  75. package/lib/module/core/UnistylesRuntime.js.map +1 -0
  76. package/lib/module/core/index.js +2 -0
  77. package/lib/module/core/index.js.map +1 -0
  78. package/lib/module/createStyleSheet.js +7 -0
  79. package/lib/module/createStyleSheet.js.map +1 -0
  80. package/lib/module/global.js +2 -0
  81. package/lib/module/global.js.map +1 -0
  82. package/lib/module/hooks/index.js +2 -1
  83. package/lib/module/hooks/index.js.map +1 -1
  84. package/lib/module/hooks/useInitialTheme.js +10 -0
  85. package/lib/module/hooks/useInitialTheme.js.map +1 -0
  86. package/lib/module/hooks/useUnistyles.js +47 -0
  87. package/lib/module/hooks/useUnistyles.js.map +1 -0
  88. package/lib/module/index.js +13 -2
  89. package/lib/module/index.js.map +1 -1
  90. package/lib/module/types/common.js +2 -0
  91. package/lib/module/types/common.js.map +1 -0
  92. package/lib/module/types/index.js +2 -1
  93. package/lib/module/types/index.js.map +1 -1
  94. package/lib/module/types/mq.js +2 -0
  95. package/lib/module/types/mq.js.map +1 -0
  96. package/lib/module/types/normalizer.js +2 -0
  97. package/lib/module/types/normalizer.js.map +1 -0
  98. package/lib/module/types/unistyles.js +2 -0
  99. package/lib/module/types/unistyles.js.map +1 -0
  100. package/lib/module/types/variants.js +2 -0
  101. package/lib/module/types/variants.js.map +1 -0
  102. package/lib/module/useStyles.js +42 -0
  103. package/lib/module/useStyles.js.map +1 -0
  104. package/lib/module/utils/breakpoints.js +34 -82
  105. package/lib/module/utils/breakpoints.js.map +1 -1
  106. package/lib/module/utils/common.js +9 -1
  107. package/lib/module/utils/common.js.map +1 -1
  108. package/lib/module/utils/index.js +5 -1
  109. package/lib/module/utils/index.js.map +1 -1
  110. package/lib/module/utils/module.d.js +2 -0
  111. package/lib/module/utils/module.d.js.map +1 -0
  112. package/lib/module/utils/mq.js +83 -0
  113. package/lib/module/utils/mq.js.map +1 -0
  114. package/lib/module/utils/mqParser.js +79 -0
  115. package/lib/module/utils/mqParser.js.map +1 -0
  116. package/lib/module/utils/normalizeStyles.web.js +13 -13
  117. package/lib/module/utils/normalizeStyles.web.js.map +1 -1
  118. package/lib/module/utils/normalizer.js +79 -0
  119. package/lib/module/utils/normalizer.js.map +1 -0
  120. package/lib/module/utils/styles.js +28 -59
  121. package/lib/module/utils/styles.js.map +1 -1
  122. package/lib/module/utils/variants.js +10 -0
  123. package/lib/module/utils/variants.js.map +1 -0
  124. package/lib/typescript/src/common.d.ts +17 -0
  125. package/lib/typescript/src/common.d.ts.map +1 -0
  126. package/lib/typescript/src/core/UnistyleRegistry.d.ts +15 -0
  127. package/lib/typescript/src/core/UnistyleRegistry.d.ts.map +1 -0
  128. package/lib/typescript/src/core/Unistyles.d.ts +13 -0
  129. package/lib/typescript/src/core/Unistyles.d.ts.map +1 -0
  130. package/lib/typescript/src/core/UnistylesModule.d.ts +6 -0
  131. package/lib/typescript/src/core/UnistylesModule.d.ts.map +1 -0
  132. package/lib/typescript/src/core/UnistylesRuntime.d.ts +24 -0
  133. package/lib/typescript/src/core/UnistylesRuntime.d.ts.map +1 -0
  134. package/lib/typescript/src/core/index.d.ts +2 -0
  135. package/lib/typescript/src/core/index.d.ts.map +1 -0
  136. package/lib/typescript/src/createStyleSheet.d.ts +3 -0
  137. package/lib/typescript/src/createStyleSheet.d.ts.map +1 -0
  138. package/lib/typescript/src/global.d.ts +7 -0
  139. package/lib/typescript/src/global.d.ts.map +1 -0
  140. package/lib/typescript/src/hooks/index.d.ts +2 -1
  141. package/lib/typescript/src/hooks/index.d.ts.map +1 -1
  142. package/lib/typescript/src/hooks/useInitialTheme.d.ts +3 -0
  143. package/lib/typescript/src/hooks/useInitialTheme.d.ts.map +1 -0
  144. package/lib/typescript/src/hooks/useUnistyles.d.ts +12 -0
  145. package/lib/typescript/src/hooks/useUnistyles.d.ts.map +1 -0
  146. package/lib/typescript/src/index.d.ts +14 -2
  147. package/lib/typescript/src/index.d.ts.map +1 -1
  148. package/lib/typescript/src/types/breakpoints.d.ts +12 -13
  149. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  150. package/lib/typescript/src/types/common.d.ts +3 -0
  151. package/lib/typescript/src/types/common.d.ts.map +1 -0
  152. package/lib/typescript/src/types/core.d.ts +28 -18
  153. package/lib/typescript/src/types/core.d.ts.map +1 -1
  154. package/lib/typescript/src/types/index.d.ts +7 -2
  155. package/lib/typescript/src/types/index.d.ts.map +1 -1
  156. package/lib/typescript/src/types/mq.d.ts +3 -0
  157. package/lib/typescript/src/types/mq.d.ts.map +1 -0
  158. package/lib/typescript/src/types/normalizer.d.ts +20 -0
  159. package/lib/typescript/src/types/normalizer.d.ts.map +1 -0
  160. package/lib/typescript/src/types/unistyles.d.ts +37 -0
  161. package/lib/typescript/src/types/unistyles.d.ts.map +1 -0
  162. package/lib/typescript/src/types/variants.d.ts +8 -0
  163. package/lib/typescript/src/types/variants.d.ts.map +1 -0
  164. package/lib/typescript/src/useStyles.d.ts +10 -0
  165. package/lib/typescript/src/useStyles.d.ts.map +1 -0
  166. package/lib/typescript/src/utils/breakpoints.d.ts +5 -62
  167. package/lib/typescript/src/utils/breakpoints.d.ts.map +1 -1
  168. package/lib/typescript/src/utils/common.d.ts +9 -1
  169. package/lib/typescript/src/utils/common.d.ts.map +1 -1
  170. package/lib/typescript/src/utils/index.d.ts +5 -1
  171. package/lib/typescript/src/utils/index.d.ts.map +1 -1
  172. package/lib/typescript/src/utils/mq.d.ts +21 -0
  173. package/lib/typescript/src/utils/mq.d.ts.map +1 -0
  174. package/lib/typescript/src/utils/mqParser.d.ts +3 -0
  175. package/lib/typescript/src/utils/mqParser.d.ts.map +1 -0
  176. package/lib/typescript/src/utils/normalizeStyles.web.d.ts +4 -1
  177. package/lib/typescript/src/utils/normalizeStyles.web.d.ts.map +1 -1
  178. package/lib/typescript/src/utils/normalizer.d.ts +11 -0
  179. package/lib/typescript/src/utils/normalizer.d.ts.map +1 -0
  180. package/lib/typescript/src/utils/styles.d.ts +5 -49
  181. package/lib/typescript/src/utils/styles.d.ts.map +1 -1
  182. package/lib/typescript/src/utils/variants.d.ts +3 -0
  183. package/lib/typescript/src/utils/variants.d.ts.map +1 -0
  184. package/package.json +33 -15
  185. package/react-native-unistyles.podspec +22 -0
  186. package/src/common.ts +19 -0
  187. package/src/core/UnistyleRegistry.ts +41 -0
  188. package/src/core/Unistyles.ts +34 -0
  189. package/src/core/UnistylesModule.ts +7 -0
  190. package/src/core/UnistylesRuntime.ts +73 -0
  191. package/src/core/index.ts +1 -0
  192. package/src/createStyleSheet.ts +9 -0
  193. package/src/global.ts +5 -0
  194. package/src/hooks/index.ts +2 -1
  195. package/src/hooks/useInitialTheme.ts +11 -0
  196. package/src/hooks/useUnistyles.ts +55 -0
  197. package/src/index.ts +30 -2
  198. package/src/types/breakpoints.ts +21 -20
  199. package/src/types/common.ts +2 -0
  200. package/src/types/core.ts +36 -24
  201. package/src/types/index.ts +7 -9
  202. package/src/types/mq.ts +3 -0
  203. package/src/types/normalizer.ts +29 -0
  204. package/src/types/unistyles.ts +45 -0
  205. package/src/types/variants.ts +11 -0
  206. package/src/useStyles.ts +62 -0
  207. package/src/utils/breakpoints.ts +46 -86
  208. package/src/utils/common.ts +10 -1
  209. package/src/utils/index.ts +5 -8
  210. package/src/utils/module.d.ts +3 -0
  211. package/src/utils/mq.ts +106 -0
  212. package/src/utils/mqParser.ts +99 -0
  213. package/src/utils/normalizeStyles.web.ts +21 -42
  214. package/src/utils/normalizer.ts +99 -0
  215. package/src/utils/styles.ts +46 -70
  216. package/src/utils/variants.ts +13 -0
  217. package/lib/commonjs/UnistylesTheme.js +0 -21
  218. package/lib/commonjs/UnistylesTheme.js.map +0 -1
  219. package/lib/commonjs/createUnistyles.js +0 -57
  220. package/lib/commonjs/createUnistyles.js.map +0 -1
  221. package/lib/commonjs/hooks/useDimensions.js +0 -10
  222. package/lib/commonjs/hooks/useDimensions.js.map +0 -1
  223. package/lib/commonjs/hooks/useDimensions.web.js +0 -31
  224. package/lib/commonjs/hooks/useDimensions.web.js.map +0 -1
  225. package/lib/commonjs/types/mediaQueries.js +0 -2
  226. package/lib/commonjs/utils/mediaQueries.js +0 -189
  227. package/lib/commonjs/utils/mediaQueries.js.map +0 -1
  228. package/lib/module/UnistylesTheme.js +0 -12
  229. package/lib/module/UnistylesTheme.js.map +0 -1
  230. package/lib/module/createUnistyles.js +0 -50
  231. package/lib/module/createUnistyles.js.map +0 -1
  232. package/lib/module/hooks/useDimensions.js +0 -3
  233. package/lib/module/hooks/useDimensions.js.map +0 -1
  234. package/lib/module/hooks/useDimensions.web.js +0 -24
  235. package/lib/module/hooks/useDimensions.web.js.map +0 -1
  236. package/lib/module/types/mediaQueries.js +0 -2
  237. package/lib/module/utils/mediaQueries.js +0 -176
  238. package/lib/module/utils/mediaQueries.js.map +0 -1
  239. package/lib/typescript/src/UnistylesTheme.d.ts +0 -9
  240. package/lib/typescript/src/UnistylesTheme.d.ts.map +0 -1
  241. package/lib/typescript/src/createUnistyles.d.ts +0 -10
  242. package/lib/typescript/src/createUnistyles.d.ts.map +0 -1
  243. package/lib/typescript/src/hooks/useDimensions.d.ts +0 -3
  244. package/lib/typescript/src/hooks/useDimensions.d.ts.map +0 -1
  245. package/lib/typescript/src/hooks/useDimensions.web.d.ts +0 -3
  246. package/lib/typescript/src/hooks/useDimensions.web.d.ts.map +0 -1
  247. package/lib/typescript/src/types/mediaQueries.d.ts +0 -8
  248. package/lib/typescript/src/types/mediaQueries.d.ts.map +0 -1
  249. package/lib/typescript/src/utils/mediaQueries.d.ts +0 -130
  250. package/lib/typescript/src/utils/mediaQueries.d.ts.map +0 -1
  251. package/src/UnistylesTheme.tsx +0 -17
  252. package/src/__tests__/createUnistyles.spec.tsx +0 -192
  253. package/src/createUnistyles.ts +0 -70
  254. package/src/hooks/useDimensions.ts +0 -4
  255. package/src/hooks/useDimensions.web.ts +0 -30
  256. package/src/types/mediaQueries.ts +0 -10
  257. package/src/utils/mediaQueries.ts +0 -201
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UnistylesRuntime = void 0;
7
+ var _common = require("../common");
8
+ class UnistylesRuntime {
9
+ constructor(unistylesBridge, registry) {
10
+ this.unistylesBridge = unistylesBridge;
11
+ this.registry = registry;
12
+ }
13
+ get colorScheme() {
14
+ return this.unistylesBridge.colorScheme;
15
+ }
16
+ get hasAdaptiveThemes() {
17
+ return this.unistylesBridge.hasAdaptiveThemes;
18
+ }
19
+ get sortedBreakpoints() {
20
+ return this.registry.sortedBreakpointPairs;
21
+ }
22
+ get themeName() {
23
+ return this.unistylesBridge.themeName;
24
+ }
25
+ get breakpoint() {
26
+ return this.unistylesBridge.breakpoint;
27
+ }
28
+ get screen() {
29
+ return {
30
+ width: this.unistylesBridge.screenWidth,
31
+ height: this.unistylesBridge.screenHeight
32
+ };
33
+ }
34
+ get orientation() {
35
+ const {
36
+ width,
37
+ height
38
+ } = this.screen;
39
+ if (width > height) {
40
+ return _common.ScreenOrientation.Landscape;
41
+ }
42
+ return _common.ScreenOrientation.Portrait;
43
+ }
44
+ setTheme = name => {
45
+ if (this.hasTheme(name)) {
46
+ this.unistylesBridge.useTheme(name);
47
+ return true;
48
+ }
49
+ throw new Error(_common.UnistylesError.ThemeNotRegistered);
50
+ };
51
+ getTheme = forName => {
52
+ if (this.registry.themeNames.length === 0) {
53
+ return {};
54
+ }
55
+ if (!this.hasTheme(forName)) {
56
+ throw new Error(_common.UnistylesError.ThemeNotFound);
57
+ }
58
+ return this.registry.themes[forName];
59
+ };
60
+ setAdaptiveThemes = enable => {
61
+ this.unistylesBridge.useAdaptiveThemes(enable);
62
+ };
63
+ hasTheme = name => name in this.registry.themes;
64
+ }
65
+ exports.UnistylesRuntime = UnistylesRuntime;
66
+ //# sourceMappingURL=UnistylesRuntime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_common","require","UnistylesRuntime","constructor","unistylesBridge","registry","colorScheme","hasAdaptiveThemes","sortedBreakpoints","sortedBreakpointPairs","themeName","breakpoint","screen","width","screenWidth","height","screenHeight","orientation","ScreenOrientation","Landscape","Portrait","setTheme","name","hasTheme","useTheme","Error","UnistylesError","ThemeNotRegistered","getTheme","forName","themeNames","length","ThemeNotFound","themes","setAdaptiveThemes","enable","useAdaptiveThemes","exports"],"sourceRoot":"../../../src","sources":["core/UnistylesRuntime.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAKO,MAAMC,gBAAgB,CAAC;EAC1BC,WAAWA,CAASC,eAAgC,EAAUC,QAA0B,EAAE;IAAA,KAAtED,eAAgC,GAAhCA,eAAgC;IAAA,KAAUC,QAA0B,GAA1BA,QAA0B;EAAG;EAE3F,IAAWC,WAAWA,CAAA,EAAG;IACrB,OAAO,IAAI,CAACF,eAAe,CAACE,WAAW;EAC3C;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,eAAe,CAACG,iBAAiB;EACjD;EAEA,IAAWC,iBAAiBA,CAAA,EAAG;IAC3B,OAAO,IAAI,CAACH,QAAQ,CAACI,qBAAqB;EAC9C;EAEA,IAAWC,SAASA,CAAA,EAAG;IACnB,OAAO,IAAI,CAACN,eAAe,CAACM,SAAS;EACzC;EAEA,IAAWC,UAAUA,CAAA,EAAG;IACpB,OAAO,IAAI,CAACP,eAAe,CAACO,UAAU;EAC1C;EAEA,IAAWC,MAAMA,CAAA,EAAG;IAChB,OAAO;MACHC,KAAK,EAAE,IAAI,CAACT,eAAe,CAACU,WAAW;MACvCC,MAAM,EAAE,IAAI,CAACX,eAAe,CAACY;IACjC,CAAC;EACL;EAEA,IAAWC,WAAWA,CAAA,EAAG;IACrB,MAAM;MAAEJ,KAAK;MAAEE;IAAO,CAAC,GAAG,IAAI,CAACH,MAAM;IAErC,IAAIC,KAAK,GAAGE,MAAM,EAAE;MAChB,OAAOG,yBAAiB,CAACC,SAAS;IACtC;IAEA,OAAOD,yBAAiB,CAACE,QAAQ;EACrC;EAEOC,QAAQ,GAAIC,IAA2B,IAAK;IAC/C,IAAI,IAAI,CAACC,QAAQ,CAACD,IAAI,CAAC,EAAE;MACrB,IAAI,CAAClB,eAAe,CAACoB,QAAQ,CAACF,IAAI,CAAC;MAEnC,OAAO,IAAI;IACf;IAEA,MAAM,IAAIG,KAAK,CAACC,sBAAc,CAACC,kBAAkB,CAAC;EACtD,CAAC;EAEMC,QAAQ,GAAIC,OAA8B,IAAK;IAClD,IAAI,IAAI,CAACxB,QAAQ,CAACyB,UAAU,CAACC,MAAM,KAAK,CAAC,EAAE;MACvC,OAAO,CAAC,CAAC;IACb;IAEA,IAAI,CAAC,IAAI,CAACR,QAAQ,CAACM,OAAO,CAAC,EAAE;MACzB,MAAM,IAAIJ,KAAK,CAACC,sBAAc,CAACM,aAAa,CAAC;IACjD;IAEA,OAAO,IAAI,CAAC3B,QAAQ,CAAC4B,MAAM,CAACJ,OAAO,CAAC;EACxC,CAAC;EAEMK,iBAAiB,GAAIC,MAAe,IAAK;IAC5C,IAAI,CAAC/B,eAAe,CAACgC,iBAAiB,CAACD,MAAM,CAAC;EAClD,CAAC;EAEOZ,QAAQ,GAAID,IAA2B,IAAKA,IAAI,IAAI,IAAI,CAACjB,QAAQ,CAAC4B,MAAM;AACpF;AAACI,OAAA,CAAAnC,gBAAA,GAAAA,gBAAA"}
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "unistyles", {
7
+ enumerable: true,
8
+ get: function () {
9
+ return _Unistyles.unistyles;
10
+ }
11
+ });
12
+ var _Unistyles = require("./Unistyles");
13
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_Unistyles","require"],"sourceRoot":"../../../src","sources":["core/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,UAAA,GAAAC,OAAA"}
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.createStyleSheet = void 0;
7
+ const createStyleSheet = styles => {
8
+ if (typeof styles === 'function') {
9
+ return styles;
10
+ }
11
+ return styles;
12
+ };
13
+ exports.createStyleSheet = createStyleSheet;
14
+ //# sourceMappingURL=createStyleSheet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createStyleSheet","styles","exports"],"sourceRoot":"../../src","sources":["createStyleSheet.ts"],"mappings":";;;;;;AAEO,MAAMA,gBAAgB,GAAUC,MAA4F,IAAY;EAC3I,IAAI,OAAOA,MAAM,KAAK,UAAU,EAAE;IAC9B,OAAOA,MAAM;EACjB;EAEA,OAAOA,MAAM;AACjB,CAAC;AAAAC,OAAA,CAAAF,gBAAA,GAAAA,gBAAA"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=global.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../src","sources":["global.ts"],"mappings":""}
@@ -3,11 +3,18 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "useDimensions", {
6
+ Object.defineProperty(exports, "useInitialTheme", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _useDimensions.useDimensions;
9
+ return _useInitialTheme.useInitialTheme;
10
10
  }
11
11
  });
12
- var _useDimensions = require("./useDimensions");
12
+ Object.defineProperty(exports, "useUnistyles", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _useUnistyles.useUnistyles;
16
+ }
17
+ });
18
+ var _useInitialTheme = require("./useInitialTheme");
19
+ var _useUnistyles = require("./useUnistyles");
13
20
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_useDimensions","require"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;AAAA,IAAAA,cAAA,GAAAC,OAAA"}
1
+ {"version":3,"names":["_useInitialTheme","require","_useUnistyles"],"sourceRoot":"../../../src","sources":["hooks/index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,aAAA,GAAAD,OAAA"}
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useInitialTheme = void 0;
7
+ var _react = require("react");
8
+ var _core = require("../core");
9
+ const useInitialTheme = forName => {
10
+ (0, _react.useMemo)(() => {
11
+ if (!_core.unistyles.runtime.themeName) {
12
+ _core.unistyles.runtime.setTheme(forName);
13
+ }
14
+ }, []);
15
+ };
16
+ exports.useInitialTheme = useInitialTheme;
17
+ //# sourceMappingURL=useInitialTheme.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_core","useInitialTheme","forName","useMemo","unistyles","runtime","themeName","setTheme","exports"],"sourceRoot":"../../../src","sources":["hooks/useInitialTheme.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,KAAA,GAAAD,OAAA;AAGO,MAAME,eAAe,GAAIC,OAA8B,IAAK;EAC/D,IAAAC,cAAO,EAAC,MAAM;IACV,IAAI,CAACC,eAAS,CAACC,OAAO,CAACC,SAAS,EAAE;MAC9BF,eAAS,CAACC,OAAO,CAACE,QAAQ,CAACL,OAAO,CAAC;IACvC;EACJ,CAAC,EAAE,EAAE,CAAC;AACV,CAAC;AAAAM,OAAA,CAAAP,eAAA,GAAAA,eAAA"}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useUnistyles = void 0;
7
+ var _reactNative = require("react-native");
8
+ var _react = require("react");
9
+ var _core = require("../core");
10
+ var _common = require("../common");
11
+ const unistylesEvents = new _reactNative.NativeEventEmitter(_reactNative.NativeModules.Unistyles);
12
+ const useUnistyles = () => {
13
+ const [theme, setTheme] = (0, _react.useState)(_core.unistyles.runtime.getTheme(_core.unistyles.runtime.themeName));
14
+ const [layout, setLayout] = (0, _react.useState)({
15
+ breakpoint: _core.unistyles.runtime.breakpoint,
16
+ orientation: _core.unistyles.runtime.orientation,
17
+ screenSize: {
18
+ width: _core.unistyles.runtime.screen.width,
19
+ height: _core.unistyles.runtime.screen.height
20
+ }
21
+ });
22
+ (0, _react.useEffect)(() => {
23
+ const subscription = unistylesEvents.addListener('onChange', event => {
24
+ switch (event.type) {
25
+ case _common.CxxUnistylesEventTypes.Theme:
26
+ {
27
+ const themeEvent = event;
28
+ return setTheme(_core.unistyles.runtime.getTheme(themeEvent.payload.themeName));
29
+ }
30
+ case _common.CxxUnistylesEventTypes.Layout:
31
+ {
32
+ const layoutEvent = event;
33
+ return setLayout({
34
+ breakpoint: layoutEvent.payload.breakpoint,
35
+ orientation: layoutEvent.payload.orientation,
36
+ screenSize: {
37
+ width: layoutEvent.payload.screen.width,
38
+ height: layoutEvent.payload.screen.height
39
+ }
40
+ });
41
+ }
42
+ default:
43
+ return;
44
+ }
45
+ });
46
+ return subscription.remove;
47
+ }, []);
48
+ return {
49
+ theme,
50
+ layout
51
+ };
52
+ };
53
+ exports.useUnistyles = useUnistyles;
54
+ //# sourceMappingURL=useUnistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_react","_core","_common","unistylesEvents","NativeEventEmitter","NativeModules","Unistyles","useUnistyles","theme","setTheme","useState","unistyles","runtime","getTheme","themeName","layout","setLayout","breakpoint","orientation","screenSize","width","screen","height","useEffect","subscription","addListener","event","type","CxxUnistylesEventTypes","Theme","themeEvent","payload","Layout","layoutEvent","remove","exports"],"sourceRoot":"../../../src","sources":["hooks/useUnistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,OAAA,GAAAH,OAAA;AAGA,MAA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W,CAACF,OAAO,CAACV,MAAM,CAACC;cACvC;YACJ,CAAC,CAAC;UACN;QACA;UACI;MACR;IACJ,CACJ,CAAC;IAED,OAAOE,YAAY,CAACU,MAAM;EAC9B,CAAC,EAAE,EAAE,CAAC;EAEN,OAAO;IACH1B,KAAK;IACLO;EACJ,CAAC;AACL,CAAC;AAAAoB,OAAA,CAAA5B,YAAA,GAAAA,YAAA"}
@@ -3,18 +3,47 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- Object.defineProperty(exports, "UnistylesTheme", {
6
+ Object.defineProperty(exports, "ScreenOrientation", {
7
7
  enumerable: true,
8
8
  get: function () {
9
- return _UnistylesTheme.UnistylesTheme;
9
+ return _common.ScreenOrientation;
10
10
  }
11
11
  });
12
- Object.defineProperty(exports, "createUnistyles", {
12
+ exports.UnistylesRuntime = exports.UnistylesRegistry = void 0;
13
+ Object.defineProperty(exports, "createStyleSheet", {
13
14
  enumerable: true,
14
15
  get: function () {
15
- return _createUnistyles.createUnistyles;
16
+ return _createStyleSheet.createStyleSheet;
16
17
  }
17
18
  });
18
- var _UnistylesTheme = require("./UnistylesTheme");
19
- var _createUnistyles = require("./createUnistyles");
19
+ Object.defineProperty(exports, "mq", {
20
+ enumerable: true,
21
+ get: function () {
22
+ return _utils.mq;
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "useInitialTheme", {
26
+ enumerable: true,
27
+ get: function () {
28
+ return _hooks.useInitialTheme;
29
+ }
30
+ });
31
+ Object.defineProperty(exports, "useStyles", {
32
+ enumerable: true,
33
+ get: function () {
34
+ return _useStyles.useStyles;
35
+ }
36
+ });
37
+ var _core = require("./core");
38
+ var _utils = require("./utils");
39
+ var _hooks = require("./hooks");
40
+ var _common = require("./common");
41
+ var _useStyles = require("./useStyles");
42
+ var _createStyleSheet = require("./createStyleSheet");
43
+ const UnistylesRegistry = exports.UnistylesRegistry = {
44
+ addThemes: _core.unistyles.registry.addThemes,
45
+ addBreakpoints: _core.unistyles.registry.addBreakpoints,
46
+ addConfig: _core.unistyles.registry.addConfig
47
+ };
48
+ const UnistylesRuntime = exports.UnistylesRuntime = _core.unistyles.runtime;
20
49
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_UnistylesTheme","require","_createUnistyles"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;AAAA,IAAAA,eAAA,GAAAC,OAAA;AACA,IAAAC,gBAAA,GAAAD,OAAA"}
1
+ {"version":3,"names":["_core","require","_utils","_hooks","_common","_useStyles","_createStyleSheet","UnistylesRegistry","exports","addThemes","unistyles","registry","addBreakpoints","addConfig","UnistylesRuntime","runtime"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AACA,IAAAI,UAAA,GAAAJ,OAAA;AACA,IAAAK,iBAAA,GAAAL,OAAA;AAEA,MAAMM,iBAAiB,GAAAC,OAAA,CAAAD,iBAAA,GAAG;EACtBE,SAAS,EAAEC,eAAS,CAACC,QAAQ,CAACF,SAAS;EACvCG,cAAc,EAAEF,eAAS,CAACC,QAAQ,CAACC,cAAc;EACjDC,SAAS,EAAEH,eAAS,CAACC,QAAQ,CAACE;AAClC,CAAC;AAED,MAAMC,gBAAgB,GAAAN,OAAA,CAAAM,gBAAA,GAAGJ,eAAS,CAACK,OAAO"}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=common.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mediaQueries.ts"],"mappings":""}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/common.ts"],"mappings":""}
@@ -1,2 +1,28 @@
1
1
  "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ var _normalizer = require("./normalizer");
7
+ Object.keys(_normalizer).forEach(function (key) {
8
+ if (key === "default" || key === "__esModule") return;
9
+ if (key in exports && exports[key] === _normalizer[key]) return;
10
+ Object.defineProperty(exports, key, {
11
+ enumerable: true,
12
+ get: function () {
13
+ return _normalizer[key];
14
+ }
15
+ });
16
+ });
17
+ var _unistyles = require("./unistyles");
18
+ Object.keys(_unistyles).forEach(function (key) {
19
+ if (key === "default" || key === "__esModule") return;
20
+ if (key in exports && exports[key] === _unistyles[key]) return;
21
+ Object.defineProperty(exports, key, {
22
+ enumerable: true,
23
+ get: function () {
24
+ return _unistyles[key];
25
+ }
26
+ });
27
+ });
2
28
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":""}
1
+ {"version":3,"names":["_normalizer","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_unistyles"],"sourceRoot":"../../../src","sources":["types/index.ts"],"mappings":";;;;;AAAA,IAAAA,WAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,WAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,WAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAT,WAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,UAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,UAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,UAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAC,UAAA,CAAAL,GAAA;IAAA;EAAA;AAAA"}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=mq.js.map
@@ -1 +1 @@
1
- {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mediaQueries.ts"],"mappings":""}
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/mq.ts"],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=normalizer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/normalizer.ts"],"mappings":""}
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ //# sourceMappingURL=unistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/unistyles.ts"],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=variants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../src","sources":["types/variants.ts"],"mappings":""}
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.useStyles = void 0;
7
+ var _react = require("react");
8
+ var _reactNative = require("react-native");
9
+ var _utils = require("./utils");
10
+ var _hooks = require("./hooks");
11
+ const useStyles = (stylesheet, variant) => {
12
+ const {
13
+ theme,
14
+ layout
15
+ } = (0, _hooks.useUnistyles)();
16
+ const {
17
+ screenSize,
18
+ breakpoint
19
+ } = layout;
20
+ if (!stylesheet) {
21
+ return {
22
+ theme,
23
+ breakpoint,
24
+ styles: {}
25
+ };
26
+ }
27
+ const parsedStyles = (0, _react.useMemo)(() => typeof stylesheet === 'function' ? stylesheet(theme) : stylesheet, [theme, stylesheet]);
28
+ const dynamicStyleSheet = (0, _react.useMemo)(() => Object.entries(parsedStyles).reduce((acc, _ref) => {
29
+ let [key, value] = _ref;
30
+ const style = value;
31
+ if (typeof value === 'function') {
32
+ return {
33
+ ...acc,
34
+ [key]: (0, _utils.proxifyFunction)(value, breakpoint, screenSize, variant)
35
+ };
36
+ }
37
+ return _reactNative.StyleSheet.create({
38
+ ...acc,
39
+ [key]: (0, _utils.parseStyle)(style, breakpoint, screenSize, variant)
40
+ });
41
+ }, {}), [breakpoint, screenSize, parsedStyles, variant]);
42
+ return {
43
+ theme,
44
+ breakpoint,
45
+ styles: dynamicStyleSheet
46
+ };
47
+ };
48
+ exports.useStyles = useStyles;
49
+ //# sourceMappingURL=useStyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","require","_reactNative","_utils","_hooks","useStyles","stylesheet","variant","theme","layout","useUnistyles","screenSize","breakpoint","styles","parsedStyles","useMemo","dynamicStyleSheet","Object","entries","reduce","acc","_ref","key","value","style","proxifyFunction","StyleSheet","create","parseStyle","exports"],"sourceRoot":"../../src","sources":["useStyles.ts"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAQA,IAAAG,MAAA,GAAAH,OAAA;AASO,MAAMI,SAAS,GAAGA,CACrBC,UAAyD,EACzDC,OAAyD,KAClC;EACvB,MAAM;IAAEC,KAAK;IAAEC;EAAO,CAAC,GAAG,IAAAC,mBAAY,EAAC,CAAC;EACxC,MAAM;IAAEC,UAAU;IAAEC;EAAW,CAAC,GAAGH,MAAM;EAEzC,IAAI,CAACH,UAAU,EAAE;IACb,OAAO;MACHE,KAAK;MACLI,UAAU;MACVC,MAAM,EAAE,CAAC;IACb,CAAC;EACL;EAEA,MAAMC,YAAY,GAAG,IAAAC,cAAO,EAAC,MAAM,OAAOT,UAAU,KAAK,UAAU,GAC7DA,UAAU,CAACE,KAAK,CAAC,GACjBF,UAAU,EAAE,CAACE,KAAK,EAAEF,UAAU,CAAC,CAAC;EAEtC,MAAMU,iBAAiB,GAAG,IAAAD,cAAO,EAAC,MAAME,MAAM,CACzCC,OAAO,CAACJ,YAAY,CAAC,CACrBK,MAAM,CAAC,CAACC,GAAG,EAAAC,IAAA,KAAmB;IAAA,IAAjB,CAACC,GAAG,EAAEC,KAAK,CAAC,GAAAF,IAAA;IACtB,MAAMG,KAAK,GAAGD,KAA8B;IAE5C,IAAI,OAAOA,KAAK,KAAK,UAAU,EAAE;MAC7B,OAAO;QACH,GAAGH,GAAG;QACN,CAACE,GAAG,GAAG,IAAAG,sBAAe,EAACF,KAAK,EAAEX,UAAU,EAAED,UAAU,EAAEJ,OAAO;MACjE,CAAC;IACL;IAEA,OAAOmB,uBAAU,CAACC,MAAM,CAAC;MACrB,GAAGP,GAAG;MACN,CAACE,GAAG,GAAG,IAAAM,iBAAU,EAAKJ,KAAK,EAAEZ,UAAU,EAAED,UAAU,EAAEJ,OAAO;IAChE,CAAC,CAAC;EACN,CAAC,EAAE,CAAC,CAAO,CAAC,EAAE,CAACK,UAAU,EAAED,UAAU,EAAEG,YAAY,EAAEP,OAAO,CAAC,CAA8B;EAE/F,OAAO;IACHC,KAAK;IACLI,UAAU;IACVC,MAAM,EAAEG;EACZ,CAAC;AACL,CAAC;AAAAa,OAAA,CAAAxB,SAAA,GAAAA,SAAA"}
@@ -4,27 +4,10 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.sortAndValidateBreakpoints = exports.getValueForBreakpoint = exports.getBreakpointFromScreenWidth = void 0;
7
+ var _core = require("../core");
7
8
  var _common = require("./common");
8
- var _mediaQueries = require("./mediaQueries");
9
- /**
10
- * Sorts the breakpoints object based on its numeric values in ascending order and validates them.
11
- *
12
- * This function takes an object where keys represent breakpoint names and values are numeric.
13
- * It returns a new object with the same keys but sorted based on their corresponding numeric values.
14
- * Additionally, it validates that:
15
- * 1. The first breakpoint starts with a value of 0.
16
- * 2. No duplicate breakpoint values exist.
17
- *
18
- * If the validation fails, appropriate error messages are logged to the console.
19
- *
20
- * @template B - An object type where keys are strings and values are numbers.
21
- * @param {B} breakpoints - The breakpoints object to be sorted and validated.
22
- * @returns {B} A new object with sorted and validated breakpoints.
23
- *
24
- * @example
25
- * const input = { md: 768, lg: 1024, sm: 0 }
26
- * sortAndValidateBreakpoints(input) // returns { sm: 0, md: 768, lg: 1024 }
27
- */
9
+ var _common2 = require("../common");
10
+ var _mqParser = require("./mqParser");
28
11
  const sortAndValidateBreakpoints = breakpoints => {
29
12
  const sortedPairs = Object.entries(breakpoints).sort((breakpoint1, breakpoint2) => {
30
13
  const [, value1] = breakpoint1;
@@ -42,22 +25,6 @@ const sortAndValidateBreakpoints = breakpoints => {
42
25
  }
43
26
  return sortedBreakpoints;
44
27
  };
45
-
46
- /**
47
- * Determines the appropriate breakpoint key for a given screen width based on provided breakpoints.
48
- *
49
- * This function takes a screen width and an object of breakpoints. It returns the key of the breakpoint
50
- * that the screen width falls into. The breakpoints are assumed to be sorted in ascending order.
51
- *
52
- * @template B - An object type where keys are strings and values are numbers representing screen widths.
53
- * @param {number} width - The screen width to determine the breakpoint for.
54
- * @param breakpointEntries - sorted pairs of breakpoints
55
- * @returns {keyof B & string} The key of the breakpoint that the screen width falls into.
56
- *
57
- * @example
58
- * const breakpoints = { sm: 0, md: 768, lg: 1024 }
59
- * getBreakpointFromScreenWidth(800, breakpoints) // returns 'md'
60
- */
61
28
  exports.sortAndValidateBreakpoints = sortAndValidateBreakpoints;
62
29
  const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
63
30
  const [key] = breakpointEntries.find((_ref, index, otherBreakpoints) => {
@@ -71,62 +38,48 @@ const getBreakpointFromScreenWidth = (width, breakpointEntries) => {
71
38
  });
72
39
  return key;
73
40
  };
74
-
75
- /**
76
- * Retrieves the value associated with a given breakpoint or custom media query based on the provided screen size.
77
- *
78
- * The function first checks for custom media queries. If a matching custom media query is found, its associated value is returned.
79
- * If no custom media query matches, the function then checks for a direct breakpoint match.
80
- * If there's no direct breakpoint match, the function simulates CSS cascading to find the closest matching breakpoint.
81
- *
82
- * @template B - An object type where keys represent breakpoint names and values represent breakpoint values.
83
- *
84
- * @param {Record<keyof B & string, string | number>} value - An object containing values associated with breakpoints or custom media queries.
85
- * @param {keyof B & string} breakpoint - The breakpoint name to check against.
86
- * @param {ScreenSize} screenSize - An object representing the screen size to be checked against the media queries.
87
- * @param breakpointPairs - sorted pairs of breakpoints
88
- *
89
- * @returns {string | number | undefined} Returns the value associated with the matching breakpoint or custom media query, or `undefined` if no match is found.
90
- *
91
- * @example
92
- *
93
- * const values = { ':w[200]': 'value1', sm: 'value2', md: 'value3' }
94
- * const screenSize = { width: 250, height: 400 }
95
- * const breakpoints = { sm: 300, md: 600, lg: 900 }
96
- *
97
- * getValueForBreakpoint(values, 'sm', screenSize, breakpoints); // 'value1'
98
- */
99
41
  exports.getBreakpointFromScreenWidth = getBreakpointFromScreenWidth;
100
- const getValueForBreakpoint = (value, breakpoint, screenSize, breakpointPairs) => {
42
+ const getValueForBreakpoint = value => {
101
43
  // the highest priority is for custom media queries
102
- const customMediaQueries = Object.entries(value).filter(_ref2 => {
103
- let [key] = _ref2;
104
- return (0, _mediaQueries.isMediaQuery)(key);
105
- });
106
- const customMediaQueryKey = (0, _mediaQueries.getKeyForCustomMediaQuery)(customMediaQueries, screenSize);
107
- if (customMediaQueryKey && customMediaQueryKey in value) {
44
+ const customMediaQueryKey = (0, _mqParser.getKeyForUnistylesMediaQuery)(Object.entries(value), _core.unistyles.runtime.screen);
45
+ if (customMediaQueryKey) {
108
46
  return value[customMediaQueryKey];
109
47
  }
110
48
 
111
- // if no custom media query, or didn't match, proceed with defined breakpoints
112
- const unifiedKey = breakpoint.toLowerCase();
113
- const directBreakpoint = value[unifiedKey];
49
+ // at this point user didn't use custom media queries (:w, :h)
50
+ // check if user defined any breakpoints
51
+ const hasBreakpoints = _core.unistyles.runtime.sortedBreakpoints.length > 0;
52
+
53
+ // if not then we can fall back to horizontal and portrait (mobile only)
54
+ if (!hasBreakpoints && _common.isMobile && (_common.Orientation.Landscape in value || _common.Orientation.Portrait in value)) {
55
+ return value[_core.unistyles.runtime.orientation === _common2.ScreenOrientation.Portrait ? _common.Orientation.Portrait : _common.Orientation.Landscape];
56
+ }
57
+
58
+ // let's get the current breakpoint
59
+ const breakpoint = _core.unistyles.runtime.breakpoint;
60
+ if (!breakpoint) {
61
+ return undefined;
62
+ }
63
+
64
+ // if user defined breakpoints, then we look for the valid one
65
+ const directBreakpoint = value[breakpoint];
114
66
 
115
67
  // if there is a direct key like 'sm' or 'md', or value for this key exists but its undefined
116
- if (directBreakpoint || unifiedKey in value) {
68
+ if (directBreakpoint || breakpoint in value) {
117
69
  return directBreakpoint;
118
70
  }
119
71
 
120
- // there is no direct hit for breakpoint nor media-query, so let's simulate CSS cascading
121
- const currentBreakpoint = breakpointPairs.findIndex(_ref3 => {
122
- let [key] = _ref3;
123
- return key === unifiedKey;
72
+ // there is no direct hit for breakpoint nor media-query, let's simulate CSS cascading
73
+ const breakpointPairs = _core.unistyles.runtime.sortedBreakpoints;
74
+ const currentBreakpoint = breakpointPairs.findIndex(_ref2 => {
75
+ let [key] = _ref2;
76
+ return key === breakpoint;
124
77
  });
125
- const availableBreakpoints = breakpointPairs.filter((_ref4, index) => {
126
- let [key] = _ref4;
78
+ const availableBreakpoints = breakpointPairs.filter((_ref3, index) => {
79
+ let [key] = _ref3;
127
80
  return index < currentBreakpoint && key && key in value;
128
- }).map(_ref5 => {
129
- let [key] = _ref5;
81
+ }).map(_ref4 => {
82
+ let [key] = _ref4;
130
83
  return key;
131
84
  });
132
85
  return breakpointPairs.length > 0 ? value[availableBreakpoints[availableBreakpoints.length - 1]] : undefined;
@@ -1 +1 @@
1
- {"version":3,"names":["_common","require","_mediaQueries","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","throwError","length","Set","size","exports","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","breakpoint","screenSize","breakpointPairs","customMediaQueries","filter","_ref2","isMediaQuery","customMediaQueryKey","getKeyForCustomMediaQuery","unifiedKey","toLowerCase","directBreakpoint","currentBreakpoint","findIndex","_ref3","availableBreakpoints","_ref4","map","_ref5","undefined"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":";;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,aAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAME,0BAA0B,GAA2BC,WAAc,IAAQ;EACpF,MAAMC,WAAW,GAAGC,MAAM,CACrBC,OAAO,CAACH,WAAW,CAAC,CACpBI,IAAI,CAAC,CAACC,WAAW,EAAEC,WAAW,KAAK;IAChC,MAAM,GAAGC,MAAM,CAAC,GAAGF,WAAW;IAC9B,MAAM,GAAGG,MAAM,CAAC,GAAGF,WAAW;IAE9B,OAAOC,MAAM,GAAGC,MAAM;EAC1B,CAAC,CAAC;EAEN,MAAMC,iBAAiB,GAAIP,MAAM,CAACQ,MAAM,CAACR,MAAM,CAACS,WAAW,CAACV,WAAW,CAAC,CAAM;EAC9E,MAAMW,gBAAgB,GAAGV,MAAM,CAACW,MAAM,CAACJ,iBAAiB,CAAC;EACzD,MAAM,CAACK,eAAe,CAAC,GAAGF,gBAAgB;EAE1C,IAAIE,eAAe,KAAK,CAAC,EAAE;IACvB,IAAAC,kBAAU,EAAC,oCAAoC,CA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,EAACf,GAAG,CAAC;EAAA,EAAC;EACzC,MAAMgB,mBAAmB,GAAG,IAAAC,uCAAyB,EAACL,kBAAkB,EAAEF,UAAU,CAAC;EAErF,IAAIM,mBAAmB,IAAIA,mBAAmB,IAAIX,KAAK,EAAE;IACrD,OAAOA,KAAK,CAACW,mBAAmB,CAAC;EACrC;;EAEA;EACA,MAAME,UAAU,GAAGT,UAAU,CAACU,WAAW,CAAC,CAAC;EAC3C,MAAMC,gBAAgB,GAAGf,KAAK,CAACa,UAAU,CAAC;;EAE1C;EACA,IAAIE,gBAAgB,IAAKF,UAAU,IAAIb,KAAM,EAAE;IAC3C,OAAOe,gBAAgB;EAC3B;;EAEA;EACA,MAAMC,iBAAiB,GAAGV,eAAe,CACpCW,SAAS,CAACC,KAAA;IAAA,IAAC,CAACvB,GAAG,CAAC,GAAAuB,KAAA;IAAA,OAAKvB,GAAG,KAAKkB,UAAU;EAAA,EAAC;EAE7C,MAAMM,oBAAoB,GAAGb,eAAe,CACvCE,MAAM,CAAC,CAAAY,KAAA,EAAQtB,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAAyB,KAAA;IAAA,OAAYtB,KAAK,GAAGkB,iBAAiB,IAAIrB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1EqB,GAAG,CAACC,KAAA;IAAA,IAAC,CAAC3B,GAAG,CAAC,GAAA2B,KAAA;IAAA,OAAK3B,GAAG;EAAA,EAAC;EAExB,OAAOW,eAAe,CAAClB,MAAM,GAAG,CAAC,GAC3BY,KAAK,CAACmB,oBAAoB,CAACA,oBAAoB,CAAC/B,MAAM,GAAG,CAAC,CAAC,CAAqB,GAChFmC,SAAS;AACnB,CAAC;AAAAhC,OAAA,CAAAY,qBAAA,GAAAA,qBAAA"}
1
+ {"version":3,"names":["_core","require","_common","_common2","_mqParser","sortAndValidateBreakpoints","breakpoints","sortedPairs","Object","entries","sort","breakpoint1","breakpoint2","value1","value2","sortedBreakpoints","freeze","fromEntries","breakpointValues","values","firstBreakpoint","throwError","length","Set","size","exports","getBreakpointFromScreenWidth","width","breakpointEntries","key","find","_ref","index","otherBreakpoints","value","minVal","maxVal","getValueForBreakpoint","customMediaQueryKey","getKeyForUnistylesMediaQuery","unistyles","runtime","screen","hasBreakpoints","isMobile","Orientation","Landscape","Portrait","orientation","ScreenOrientation","breakpoint","undefined","directBreakpoint","breakpointPairs","currentBreakpoint","findIndex","_ref2","availableBreakpoints","filter","_ref3","map","_ref4"],"sourceRoot":"../../../src","sources":["utils/breakpoints.ts"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AACA,IAAAC,OAAA,GAAAD,OAAA;AAGA,IAAAE,QAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAEO,MAAMI,0BAA0B,GAAIC,WAAiC,IAA2B;EACnG,MAAMC,WAAW,GAAGC,MAAM,CACrBC,OAAO,CAACH,WAAW,CAAC,CACpBI,IAAI,CAAC,CAACC,WAAW,EAAEC,WAAW,KAAK;IAChC,MAAM,GAAGC,MAAM,CAAC,GAAGF,WAAW;IAC9B,MAAM,GAAGG,MAAM,CAAC,GAAGF,WAAW;IAE9B,OAAQC,MAAM,GAAeC,MAAiB;EAClD,CAAC,CAAC;EAEN,MAAMC,iBAAiB,GAAIP,MAAM,CAACQ,MAAM,CAACR,MAAM,CAACS,WAAW,CAACV,WAAW,CAAC,CAAyB;EACjG,MAAMW,gBAAgB,GAAGV,MAAM,CAACW,MAAM,CAACJ,iBAAiB,CAAC;EACzD,MAAM,CAACK,eAAe,CAAC,GAAGF,gBAAgB;EAE1C,IAAIE,eAAe,KAAK,CAAC,EAAE;IACvB,IAAAC,kBAAU,EAAC,oCAAoC,CAAC;EACpD;EAEA,IAAIH,gBAAgB,CAACI,MAAM,KAAK,IAAIC,GAAG,CAACL,gBAAgB,CAAC,CAACM,IAAI,EAAE;IAC5D,IAAAH,kBAAU,EAAC,kCAAkC,CAAC;EAClD;EAEA,OAAON,iB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CAACC,SAAS,CAC9B;EACL;;EAEA;EACA,MAAMI,UAAU,GAAGV,eAAS,CAACC,OAAO,CAACS,UAAU;EAE/C,IAAI,CAACA,UAAU,EAAE;IACb,OAAOC,SAAS;EACpB;;EAEA;EACA,MAAMC,gBAAgB,GAAGlB,KAAK,CAACgB,UAAU,CAAC;;EAE1C;EACA,IAAIE,gBAAgB,IAAKF,UAAU,IAAIhB,KAAM,EAAE;IAC3C,OAAOkB,gBAAgB;EAC3B;;EAEA;EACA,MAAMC,eAAe,GAAGb,eAAS,CAACC,OAAO,CAAC1B,iBAAiB;EAC3D,MAAMuC,iBAAiB,GAAGD,eAAe,CACpCE,SAAS,CAACC,KAAA;IAAA,IAAC,CAAC3B,GAAG,CAAC,GAAA2B,KAAA;IAAA,OAAK3B,GAAG,KAAKqB,UAAU;EAAA,EAAC;EAE7C,MAAMO,oBAAoB,GAAGJ,eAAe,CACvCK,MAAM,CAAC,CAAAC,KAAA,EAAQ3B,KAAK;IAAA,IAAZ,CAACH,GAAG,CAAC,GAAA8B,KAAA;IAAA,OAAY3B,KAAK,GAAGsB,iBAAiB,IAAIzB,GAAG,IAAIA,GAAG,IAAIK,KAAK;EAAA,EAAC,CAC1E0B,GAAG,CAACC,KAAA;IAAA,IAAC,CAAChC,GAAG,CAAC,GAAAgC,KAAA;IAAA,OAAKhC,GAAG;EAAA,EAAC;EAExB,OAAOwB,eAAe,CAAC/B,MAAM,GAAG,CAAC,GAC3BY,KAAK,CAACuB,oBAAoB,CAACA,oBAAoB,CAACnC,MAAM,GAAG,CAAC,CAAC,CAAwC,GACnG6B,SAAS;AACnB,CAAC;AAAA1B,OAAA,CAAAY,qBAAA,GAAAA,qBAAA"}
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.warn = exports.throwError = exports.isWeb = void 0;
6
+ exports.warn = exports.throwError = exports.isWeb = exports.isServer = exports.isMobile = exports.isIOS = exports.isAndroid = exports.Orientation = void 0;
7
7
  var _reactNative = require("react-native");
8
8
  const throwError = message => {
9
9
  throw new Error(`🦄 [react-native-unistyles]: ${message}`);
@@ -13,6 +13,13 @@ const warn = message => {
13
13
  console.warn(`🦄 [react-native-unistyles]: ${message}`);
14
14
  };
15
15
  exports.warn = warn;
16
- const isWeb = () => _reactNative.Platform.OS === 'web';
17
- exports.isWeb = isWeb;
16
+ const isMobile = exports.isMobile = _reactNative.Platform.OS === 'android' || _reactNative.Platform.OS === 'ios';
17
+ const isWeb = exports.isWeb = _reactNative.Platform.OS === 'web';
18
+ const isIOS = exports.isIOS = _reactNative.Platform.OS === 'ios';
19
+ const isAndroid = exports.isAndroid = _reactNative.Platform.OS === 'android';
20
+ const isServer = exports.isServer = typeof window === 'undefined';
21
+ const Orientation = exports.Orientation = {
22
+ Landscape: 'landscape',
23
+ Portrait: 'portrait'
24
+ };
18
25
  //# sourceMappingURL=common.js.map