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
package/README.md CHANGED
@@ -8,10 +8,9 @@
8
8
 
9
9
  ![GitHub package.json version](https://img.shields.io/github/package-json/v/jpudysz/react-native-unistyles?style=for-the-badge)
10
10
  [![npm downloads](https://img.shields.io/npm/dm/react-native-unistyles.svg?style=for-the-badge)](https://www.npmjs.com/package/react-native-unistyles)
11
- ![Platform - Android and iOS](https://img.shields.io/badge/platform-Android%20%7C%20iOS%20%7C%20RNWeb-blue.svg?style=for-the-badge)
11
+ ![Platform - Android and iOS](https://img.shields.io/badge/platform-Android%20%7C%20IOS%20%7C%20SSR%20%7C%20Web-blue.svg?style=for-the-badge)
12
12
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg?style=for-the-badge)](https://opensource.org/licenses/MIT)
13
13
 
14
-
15
14
  ## Features
16
15
  - ⚡ Blazing fast, adds around ~3ms on top of StyleSheet*
17
16
  - 🎳 Share up to 100% of your styles across platforms in monorepo
@@ -19,7 +18,8 @@
19
18
  - 🖥️ Supports custom breakpoints and css-like media queries
20
19
  - 🎨 Access theme in your StyleSheets and components
21
20
  - 🪄 Supports dynamic functions to access values from JSX
22
- - 🥳 Compatible with Expo, Expo Go, Bare React Native and React Native Web
21
+ - 🥳 Compatible with Expo, Expo Go, Bare React Native, React Native Web and SSR
22
+ - 🛡️ ~99% Test coverage
23
23
  - ⚔️ No 3rd party dependencies
24
24
 
25
25
  *-based on this [benchmark](https://github.com/efstathiosntonas/react-native-style-libraries-benchmark)
@@ -41,7 +41,7 @@ There is ongoing work on branch [2.0](https://github.com/jpudysz/react-native-un
41
41
 
42
42
  ---
43
43
 
44
- Join early testers and discussion [here](https://github.com/jpudysz/react-native-unistyles/discussions/41)
44
+ Join early testers and discussion [here](https://github.com/jpudysz/react-native-unistyles/discussions/41).
45
45
 
46
46
  ```cmd
47
47
  yarn add react-native-unistyles@next
@@ -0,0 +1,255 @@
1
+ #include "UnistylesRuntime.h"
2
+
3
+ #include <string>
4
+ #include <vector>
5
+
6
+ #pragma region HostObject
7
+
8
+ std::vector<jsi::PropNameID> UnistylesRuntime::getPropertyNames(jsi::Runtime& runtime) {
9
+ std::vector<jsi::PropNameID> properties;
10
+
11
+ // getters
12
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("screenWidth")));
13
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("screenHeight")));
14
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("hasAdaptiveThemes")));
15
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("themeName")));
16
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("breakpoint")));
17
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("colorScheme")));
18
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("sortedBreakpointPairs")));
19
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("useBreakpoints")));
20
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("useTheme")));
21
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("useAdaptiveThemes")));
22
+
23
+ // setters
24
+ properties.push_back(jsi::PropNameID::forUtf8(runtime, std::string("themes")));
25
+
26
+ return properties;
27
+ }
28
+
29
+
30
+ jsi::Value UnistylesRuntime::get(jsi::Runtime& runtime, const jsi::PropNameID& propNameId) {
31
+ std::string propName = propNameId.utf8(runtime);
32
+
33
+ if (propName == "screenWidth") {
34
+ return jsi::Value(this->screenWidth);
35
+ }
36
+
37
+ if (propName == "screenHeight") {
38
+ return jsi::Value(this->screenHeight);
39
+ }
40
+
41
+ if (propName == "hasAdaptiveThemes") {
42
+ return jsi::Value(this->hasAdaptiveThemes);
43
+ }
44
+
45
+ if (propName == "themeName") {
46
+ return !this->themeName.empty()
47
+ ? jsi::Value(jsi::String::createFromUtf8(runtime, this->themeName))
48
+ : this->getThemeOrFail(runtime);
49
+ }
50
+
51
+ if (propName == "breakpoint") {
52
+ return !this->breakpoint.empty()
53
+ ? jsi::Value(jsi::String::createFromUtf8(runtime, this->breakpoint))
54
+ : jsi::Value::undefined();
55
+ }
56
+
57
+ if (propName == "colorScheme") {
58
+ return jsi::Value(jsi::String::createFromUtf8(runtime, this->colorScheme));
59
+ }
60
+
61
+ if (propName == "sortedBreakpointPairs") {
62
+ std::unique_ptr<jsi::Array> sortedBreakpointEntriesArray = std::make_unique<jsi::Array>(runtime, this->sortedBreakpointPairs.size());
63
+
64
+ for (size_t i = 0; i < this->sortedBreakpointPairs.size(); ++i) {
65
+ std::unique_ptr<jsi::Array> pairArray = std::make_unique<jsi::Array>(runtime, 2);
66
+ jsi::String nameValue = jsi::String::createFromUtf8(runtime, this->sortedBreakpointPairs[i].first);
67
+
68
+ pairArray->setValueAtIndex(runtime, 0, nameValue);
69
+ pairArray->setValueAtIndex(runtime, 1, jsi::Value(this->sortedBreakpointPairs[i].second));
70
+ sortedBreakpointEntriesArray->setValueAtIndex(runtime, i, *pairArray);
71
+ }
72
+
73
+ return jsi::Value(runtime, *sortedBreakpointEntriesArray);
74
+ }
75
+
76
+ if (propName == "useBreakpoints") {
77
+ return jsi::Function::createFromHostFunction(
78
+ runtime,
79
+ jsi::PropNameID::forAscii(runtime, "useBreakpoints"),
80
+ 1,
81
+ [this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
82
+ jsi::Object breakpointsObj = arguments[0].asObject(runtime);
83
+ jsi::Array propertyNames = breakpointsObj.getPropertyNames(runtime);
84
+ std::vector<std::pair<std::string, double>> sortedBreakpointEntriesVec;
85
+
86
+ for (size_t i = 0; i < propertyNames.size(runtime); ++i) {
87
+ jsi::Value propNameValue = propertyNames.getValueAtIndex(runtime, i);
88
+ std::string name = propNameValue.asString(runtime).utf8(runtime);
89
+ jsi::PropNameID propNameID = jsi::PropNameID::forUtf8(runtime, name);
90
+ jsi::Value value = breakpointsObj.getProperty(runtime, propNameID);
91
+
92
+ if (value.isNumber()) {
93
+ double breakpointValue = value.asNumber();
94
+ sortedBreakpointEntriesVec.push_back(std::make_pair(name, breakpointValue));
95
+ }
96
+ }
97
+
98
+ std::sort(sortedBreakpointEntriesVec.begin(), sortedBreakpointEntriesVec.end(), [](const std::pair<std::string, double>& a, const std::pair<std::string, double>& b) {
99
+ return a.second < b.second;
100
+ });
101
+
102
+ if (sortedBreakpointEntriesVec.size() == 0) {
103
+ throw jsi::JSError(runtime, UnistylesErrorBreakpointsCannotBeEmpty);
104
+ }
105
+
106
+ if (sortedBreakpointEntriesVec.at(0).second != 0) {
107
+ throw jsi::JSError(runtime, UnistylesErrorBreakpointsMustStartFromZero);
108
+ }
109
+
110
+ this->sortedBreakpointPairs = sortedBreakpointEntriesVec;
111
+
112
+ std::string breakpoint = this->getBreakpointFromScreenWidth(this->screenWidth, sortedBreakpointEntriesVec);
113
+
114
+ this->breakpoint = breakpoint;
115
+
116
+ return jsi::Value::undefined();
117
+ }
118
+ );
119
+ }
120
+
121
+ if (propName == "useTheme") {
122
+ return jsi::Function::createFromHostFunction(runtime,
123
+ jsi::PropNameID::forAscii(runtime, "useTheme"),
124
+ 1,
125
+ [this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
126
+ std::string themeName = arguments[0].asString(runtime).utf8(runtime);
127
+
128
+ if (this->themeName != themeName) {
129
+ this->themeName = themeName;
130
+ this->onThemeChangeCallback(themeName);
131
+ }
132
+
133
+ return jsi::Value::undefined();
134
+ }
135
+ );
136
+ }
137
+
138
+ if (propName == "useAdaptiveThemes") {
139
+ return jsi::Function::createFromHostFunction(runtime,
140
+ jsi::PropNameID::forAscii(runtime, "useAdaptiveThemes"),
141
+ 1,
142
+ [this](jsi::Runtime &runtime, const jsi::Value &thisVal, const jsi::Value *arguments, size_t count) -> jsi::Value {
143
+ bool enableAdaptiveThemes = arguments[0].asBool();
144
+
145
+ this->hasAdaptiveThemes = enableAdaptiveThemes;
146
+
147
+ if (!enableAdaptiveThemes || !this->supportsAutomaticColorScheme) {
148
+ return jsi::Value::undefined();
149
+ }
150
+
151
+ if (this->themeName != this->colorScheme) {
152
+ this->themeName = this->colorScheme;
153
+ this->onThemeChangeCallback(this->themeName);
154
+ }
155
+
156
+ return jsi::Value::undefined();
157
+ }
158
+ );
159
+ }
160
+
161
+ return jsi::Value::undefined();
162
+ }
163
+
164
+ void UnistylesRuntime::set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) {
165
+ std::string propName = propNameId.utf8(runtime);
166
+
167
+ if (propName == "themes" && value.isObject()) {
168
+ jsi::Array themes = value.asObject(runtime).asArray(runtime);
169
+ std::vector<std::string> themesVector;
170
+ size_t length = themes.size(runtime);
171
+
172
+ for (size_t i = 0; i < length; ++i) {
173
+ jsi::Value element = themes.getValueAtIndex(runtime, i);
174
+
175
+ if (element.isString()) {
176
+ std::string theme = element.asString(runtime).utf8(runtime);
177
+ themesVector.push_back(theme);
178
+ }
179
+ }
180
+
181
+ if (themesVector.size() == 0) {
182
+ throw jsi::JSError(runtime, UnistylesErrorThemesCannotBeEmpty);
183
+ }
184
+
185
+ this->themes = themesVector;
186
+ this->themeName = "";
187
+
188
+ bool hasLightTheme = std::find(themesVector.begin(), themesVector.end(), "light") != themesVector.end();
189
+ bool hasDarkTheme = std::find(themesVector.begin(), themesVector.end(), "dark") != themesVector.end();
190
+
191
+ this->supportsAutomaticColorScheme = hasLightTheme && hasDarkTheme;
192
+
193
+ return;
194
+ }
195
+ }
196
+
197
+ #pragma endregion
198
+ #pragma region Helpers
199
+
200
+ std::string UnistylesRuntime::getBreakpointFromScreenWidth(int width, const std::vector<std::pair<std::string, double>>& sortedBreakpointPairs) {
201
+ for (size_t i = 0; i < sortedBreakpointPairs.size(); ++i) {
202
+ const auto& [key, value] = sortedBreakpointPairs[i];
203
+ const double maxVal = (i + 1 < sortedBreakpointPairs.size()) ? sortedBreakpointPairs[i + 1].second : std::numeric_limits<double>::infinity();
204
+
205
+ if (width >= value && width < maxVal) {
206
+ return key;
207
+ }
208
+ }
209
+
210
+ return sortedBreakpointPairs.empty() ? "" : sortedBreakpointPairs.back().first;
211
+ }
212
+
213
+ void UnistylesRuntime::handleScreenSizeChange(int width, int height) {
214
+ std::string breakpoint = this->getBreakpointFromScreenWidth(width, this->sortedBreakpointPairs);
215
+ bool shouldNotify = this->breakpoint != breakpoint || this->screenWidth != width || this->screenHeight != height;
216
+
217
+ this->breakpoint = breakpoint;
218
+ this->screenWidth = width;
219
+ this->screenHeight = height;
220
+
221
+ int orientation = width > height
222
+ ? UnistylesOrientationLandscape
223
+ : UnistylesOrientationPortrait;
224
+
225
+ if (shouldNotify) {
226
+ this->onLayoutChangeCallback(breakpoint, orientation, width, height);
227
+ }
228
+ }
229
+
230
+ void UnistylesRuntime::handleAppearanceChange(std::string colorScheme) {
231
+ this->colorScheme = colorScheme;
232
+
233
+ if (!this->supportsAutomaticColorScheme || !this->hasAdaptiveThemes) {
234
+ return;
235
+ }
236
+
237
+ if (this->themeName != this->colorScheme) {
238
+ this->onThemeChangeCallback(this->colorScheme);
239
+ this->themeName = this->colorScheme;
240
+ }
241
+ }
242
+
243
+ jsi::Value UnistylesRuntime::getThemeOrFail(jsi::Runtime& runtime) {
244
+ if (this->themes.size() == 1) {
245
+ std::string themeName = this->themes.at(0);
246
+
247
+ this->themeName = themeName;
248
+
249
+ return jsi::String::createFromUtf8(runtime, themeName);
250
+ }
251
+
252
+ return jsi::Value().undefined();
253
+ }
254
+
255
+ #pragma endregion
@@ -0,0 +1,60 @@
1
+ #pragma once
2
+
3
+ #include <jsi/jsi.h>
4
+ #include <vector>
5
+
6
+ using namespace facebook;
7
+
8
+ const int UnistylesOrientationPortrait = 1;
9
+ const int UnistylesOrientationLandscape = 2;
10
+
11
+ const std::string UnistylesDarkScheme = "dark";
12
+ const std::string UnistylesLightScheme = "light";
13
+ const std::string UnistylesUnspecifiedScheme = "unspecified";
14
+
15
+ const std::string UnistylesErrorBreakpointsCannotBeEmpty = "UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY'";
16
+ const std::string UnistylesErrorBreakpointsMustStartFromZero = "UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZER0";
17
+ const std::string UnistylesErrorThemesCannotBeEmpty = "UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY";
18
+
19
+ class JSI_EXPORT UnistylesRuntime : public jsi::HostObject {
20
+ private:
21
+ std::function<void(std::string)> onThemeChangeCallback;
22
+ std::function<void(std::string breakpoint, int layout, int screenWidth, int screenHeight)> onLayoutChangeCallback;
23
+
24
+ int screenWidth;
25
+ int screenHeight;
26
+ std::string colorScheme;
27
+
28
+ public:
29
+ UnistylesRuntime(
30
+ int screenWidth,
31
+ int screenHeight,
32
+ std::string colorScheme
33
+ ): screenWidth(screenWidth), screenHeight(screenHeight), colorScheme(colorScheme) {}
34
+
35
+ bool hasAdaptiveThemes;
36
+ bool supportsAutomaticColorScheme;
37
+
38
+ std::string themeName;
39
+ std::string breakpoint;
40
+ std::vector<std::string> themes;
41
+ std::vector<std::pair<std::string, double>> sortedBreakpointPairs;
42
+
43
+ void onThemeChange(std::function<void(std::string)> callback) {
44
+ this->onThemeChangeCallback = callback;
45
+ }
46
+
47
+ void onLayoutChange(std::function<void(std::string breakpoint, int layout, int screenWidth, int screenHeight)> callback) {
48
+ this->onLayoutChangeCallback = callback;
49
+ }
50
+
51
+ jsi::Value get(jsi::Runtime&, const jsi::PropNameID& name) override;
52
+ void set(jsi::Runtime& runtime, const jsi::PropNameID& propNameId, const jsi::Value& value) override;
53
+ std::vector<jsi::PropNameID> getPropertyNames(jsi::Runtime& runtime) override;
54
+
55
+ void handleScreenSizeChange(int width, int height);
56
+ void handleAppearanceChange(std::string colorScheme);
57
+
58
+ jsi::Value getThemeOrFail(jsi::Runtime&);
59
+ std::string getBreakpointFromScreenWidth(int width, const std::vector<std::pair<std::string, double>>& sortedBreakpointEntries);
60
+ };
@@ -0,0 +1,4 @@
1
+ #include <string>
2
+
3
+ std::string getColorScheme();
4
+ NSString* cxxStringToNSString(std::string);
@@ -0,0 +1,20 @@
1
+ #import "UnistylesHelpers.h"
2
+ #import "UnistylesRuntime.h"
3
+
4
+ std::string getColorScheme() {
5
+ UIUserInterfaceStyle colorScheme = [UIScreen mainScreen].traitCollection.userInterfaceStyle;
6
+
7
+ switch (colorScheme) {
8
+ case UIUserInterfaceStyleLight:
9
+ return UnistylesLightScheme;
10
+ case UIUserInterfaceStyleDark:
11
+ return UnistylesDarkScheme;
12
+ case UIUserInterfaceStyleUnspecified:
13
+ default:
14
+ return UnistylesUnspecifiedScheme;
15
+ }
16
+ }
17
+
18
+ NSString* cxxStringToNSString(std::string cxxString) {
19
+ return [NSString stringWithUTF8String:cxxString.c_str()];
20
+ }
@@ -0,0 +1,10 @@
1
+ #import <React/RCTBridgeModule.h>
2
+ #import <React/RCTEventEmitter.h>
3
+ #import <string>
4
+
5
+ @interface UnistylesModule : RCTEventEmitter<RCTBridgeModule>
6
+
7
+ @property (nonatomic, assign) BOOL hasListeners;
8
+ @property (nonatomic, assign) void* unistylesRuntime;
9
+
10
+ @end
@@ -0,0 +1,158 @@
1
+ #import "UnistylesModule.h"
2
+ #import "UnistylesHelpers.h"
3
+ #import "UnistylesRuntime.h"
4
+
5
+ #import <React/RCTAppearance.h>
6
+ #import <React/RCTBridge+Private.h>
7
+ #import <jsi/jsi.h>
8
+
9
+ using namespace facebook;
10
+
11
+ @implementation UnistylesModule
12
+
13
+ RCT_EXPORT_MODULE(Unistyles)
14
+
15
+ #pragma mark - Lifecycle
16
+
17
+ - (instancetype)init {
18
+ if ((self = [super init])) {
19
+ [[NSNotificationCenter defaultCenter] addObserver:self
20
+ selector:@selector(handleOrientationChange:)
21
+ name:UIDeviceOrientationDidChangeNotification
22
+ object:nil];
23
+ [[NSNotificationCenter defaultCenter] addObserver:self
24
+ selector:@selector(appearanceChanged:)
25
+ name:RCTUserInterfaceStyleDidChangeNotification
26
+ object:nil];
27
+ }
28
+
29
+ return self;
30
+ }
31
+
32
+ - (void)dealloc {
33
+ if (self.unistylesRuntime != nullptr) {
34
+ self.unistylesRuntime = nullptr;
35
+ }
36
+
37
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
38
+ }
39
+
40
+
41
+ + (BOOL)requiresMainQueueSetup {
42
+ return YES;
43
+ }
44
+
45
+ #pragma mark - Event handlers
46
+
47
+ - (void)handleOrientationChange:(NSNotification *)notification {
48
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
49
+ CGFloat screenWidth = [UIScreen mainScreen].bounds.size.width;
50
+ CGFloat screenHeight = [UIScreen mainScreen].bounds.size.height;
51
+
52
+ if (self.unistylesRuntime != nullptr) {
53
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleScreenSizeChange((int)screenWidth, (int)screenHeight);
54
+ }
55
+ });
56
+ }
57
+
58
+ - (void)appearanceChanged:(NSNotification *)notification {
59
+ std::string colorScheme = getColorScheme();
60
+
61
+ if (self.unistylesRuntime != nullptr) {
62
+ ((UnistylesRuntime*)self.unistylesRuntime)->handleAppearanceChange(colorScheme);
63
+ }
64
+ }
65
+
66
+ #pragma mark - Event emitter
67
+ - (NSArray<NSString *> *)supportedEvents {
68
+ return @[@"onChange"];
69
+ }
70
+
71
+ - (void)startObserving {
72
+ self.hasListeners = YES;
73
+ }
74
+
75
+ - (void)stopObserving {
76
+ self.hasListeners = NO;
77
+ }
78
+
79
+ - (void)emitEvent:(NSString *)eventName withBody:(NSDictionary *)body {
80
+ if (self.hasListeners) {
81
+ [self sendEventWithName:@"onChange" body:body];
82
+ }
83
+ }
84
+
85
+ #pragma mark - Core
86
+
87
+ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(install) {
88
+ RCTBridge* bridge = [RCTBridge currentBridge];
89
+ RCTCxxBridge* cxxBridge = (RCTCxxBridge*)bridge;
90
+
91
+ if (cxxBridge == nil) {
92
+ return @false;
93
+ }
94
+
95
+ auto jsiRuntime = (jsi::Runtime*)cxxBridge.runtime;
96
+
97
+ if (jsiRuntime == nil) {
98
+ return @false;
99
+ }
100
+
101
+ auto& runtime = *jsiRuntime;
102
+ UnistylesModule *__weak weakSelf = self;
103
+
104
+ registerUnistylesHostObject(runtime, weakSelf);
105
+
106
+ NSLog(@"Installed Unistyles 🦄!");
107
+
108
+ return @true;
109
+ }
110
+
111
+ void registerUnistylesHostObject(jsi::Runtime &runtime, UnistylesModule* weakSelf) {
112
+ CGFloat initialScreenWidth = [UIScreen mainScreen].bounds.size.width;
113
+ CGFloat initialScreenHeight = [UIScreen mainScreen].bounds.size.height;
114
+ std::string initialColorScheme = getColorScheme();
115
+
116
+ auto unistylesRuntime = std::make_shared<UnistylesRuntime>(
117
+ (int)initialScreenWidth,
118
+ (int)initialScreenHeight,
119
+ initialColorScheme
120
+ );
121
+
122
+ unistylesRuntime.get()->onThemeChange([=](std::string theme) {
123
+ NSDictionary *body = @{
124
+ @"type": @"theme",
125
+ @"payload": @{
126
+ @"themeName": cxxStringToNSString(theme)
127
+ }
128
+ };
129
+
130
+ [weakSelf emitEvent:@"onChange" withBody:body];
131
+ });
132
+
133
+ unistylesRuntime.get()->onLayoutChange([=](std::string breakpoint, int orientation, int width, int height) {
134
+ NSDictionary *body = @{
135
+ @"type": @"layout",
136
+ @"payload": @{
137
+ @"breakpoint": cxxStringToNSString(breakpoint),
138
+ @"orientation": @(orientation),
139
+ @"screen": @{
140
+ @"width": @(width),
141
+ @"height": @(height)
142
+ }
143
+ }
144
+ };
145
+
146
+ [weakSelf emitEvent:@"onChange" withBody:body];
147
+ });
148
+
149
+ weakSelf.unistylesRuntime = unistylesRuntime.get();
150
+
151
+ auto hostObject = jsi::Object::createFromHostObject(runtime, unistylesRuntime);
152
+
153
+ runtime.global().setProperty(runtime, "__UNISTYLES__", std::move(hostObject));
154
+ }
155
+
156
+ @end
157
+
158
+ #pragma mark - End
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UnistylesError = exports.ScreenOrientation = exports.CxxUnistylesEventTypes = void 0;
7
+ let CxxUnistylesEventTypes = exports.CxxUnistylesEventTypes = /*#__PURE__*/function (CxxUnistylesEventTypes) {
8
+ CxxUnistylesEventTypes["Theme"] = "theme";
9
+ CxxUnistylesEventTypes["Layout"] = "layout";
10
+ return CxxUnistylesEventTypes;
11
+ }({});
12
+ let UnistylesError = exports.UnistylesError = /*#__PURE__*/function (UnistylesError) {
13
+ UnistylesError["RuntimeUnavailable"] = "UNISTYLES_ERROR_RUNTIME_UNAVAILABLE";
14
+ UnistylesError["ThemeNotFound"] = "UNISTYLES_ERROR_THEME_NOT_FOUND";
15
+ UnistylesError["ThemeNotRegistered"] = "UNISTYLES_ERROR_THEME_NOT_REGISTERED";
16
+ UnistylesError["ThemesCannotBeEmpty"] = "UNISTYLES_ERROR_THEMES_CANNOT_BE_EMPTY";
17
+ UnistylesError["BreakpointsCannotBeEmpty"] = "UNISTYLES_ERROR_BREAKPOINTS_CANNOT_BE_EMPTY";
18
+ UnistylesError["BreakpointsMustStartFromZero"] = "UNISTYLES_ERROR_BREAKPOINTS_MUST_START_FROM_ZERO";
19
+ return UnistylesError;
20
+ }({}); // todo to string?
21
+ let ScreenOrientation = exports.ScreenOrientation = /*#__PURE__*/function (ScreenOrientation) {
22
+ ScreenOrientation[ScreenOrientation["Portrait"] = 1] = "Portrait";
23
+ ScreenOrientation[ScreenOrientation["Landscape"] = 2] = "Landscape";
24
+ return ScreenOrientation;
25
+ }({});
26
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["CxxUnistylesEventTypes","exports","UnistylesError","ScreenOrientation"],"sourceRoot":"../../src","sources":["common.ts"],"mappings":";;;;;;IAAYA,sBAAsB,GAAAC,OAAA,CAAAD,sBAAA,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAAA,IAKtBE,cAAc,GAAAD,OAAA,CAAAC,cAAA,0BAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAdA,cAAc;EAAA,OAAdA,cAAc;AAAA,OAS1B;AAAA,IACYC,iBAAiB,GAAAF,OAAA,CAAAE,iBAAA,0BAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAjBA,iBAAiB,CAAjBA,iBAAiB;EAAA,OAAjBA,iBAAiB;AAAA"}
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UnistyleRegistry = void 0;
7
+ class UnistyleRegistry {
8
+ config = {};
9
+ themeNames = [];
10
+ themes = {};
11
+ breakpoints = {};
12
+ sortedBreakpointPairs = [];
13
+ constructor(unistylesBridge) {
14
+ this.unistylesBridge = unistylesBridge;
15
+ }
16
+ addThemes = themes => {
17
+ this.themes = themes;
18
+ const keys = Object.keys(themes);
19
+ this.unistylesBridge.themes = keys;
20
+ this.themeNames = keys;
21
+ return this;
22
+ };
23
+ addBreakpoints = breakpoints => {
24
+ this.breakpoints = breakpoints;
25
+ this.unistylesBridge.useBreakpoints(breakpoints);
26
+ this.sortedBreakpointPairs = this.unistylesBridge.sortedBreakpointPairs;
27
+ return this;
28
+ };
29
+ addConfig = config => {
30
+ this.config = config;
31
+ if (config.adaptiveThemes) {
32
+ this.unistylesBridge.useAdaptiveThemes(config.adaptiveThemes);
33
+ }
34
+ return this;
35
+ };
36
+ }
37
+ exports.UnistyleRegistry = UnistyleRegistry;
38
+ //# sourceMappingURL=UnistyleRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistyleRegistry","config","themeNames","themes","breakpoints","sortedBreakpointPairs","constructor","unistylesBridge","addThemes","keys","Object","addBreakpoints","useBreakpoints","addConfig","adaptiveThemes","useAdaptiveThemes","exports"],"sourceRoot":"../../../src","sources":["core/UnistyleRegistry.ts"],"mappings":";;;;;;AAGO,MAAMA,gBAAgB,CAAC;EACnBC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,UAAU,GAAiC,EAAE;EAC7CC,MAAM,GAAoB,CAAC,CAAC;EAC5BC,WAAW,GAAyB,CAAC,CAAC;EACtCC,qBAAqB,GAA0F,EAAE;EAExHC,WAAWA,CAASC,eAAgC,EAAE;IAAA,KAAlCA,eAAgC,GAAhCA,eAAgC;EAAG;EAEhDC,SAAS,GAAIL,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,MAAMM,IAAI,GAAGC,MAAM,CAACD,IAAI,CAACN,MAAM,CAAiC;IAEhE,IAAI,CAACI,eAAe,CAACJ,MAAM,GAAGM,IAAI;IAClC,IAAI,CAACP,UAAU,GAAGO,IAAI;IAEtB,OAAO,IAAI;EACf,CAAC;EAEME,cAAc,GAAIP,WAAiC,IAAK;IAC3D,IAAI,CAACA,WAAW,GAAGA,WAAW;IAC9B,IAAI,CAACG,eAAe,CAACK,cAAc,CAACR,WAAW,CAAC;IAChD,IAAI,CAACC,qBAAqB,GAAG,IAAI,CAACE,eAAe,CAACF,qBAAqB;IAEvE,OAAO,IAAI;EACf,CAAC;EAEMQ,SAAS,GAAIZ,MAAuB,IAAK;IAC5C,IAAI,CAACA,MAAM,GAAGA,MAAM;IAEpB,IAAIA,MAAM,CAACa,cAAc,EAAE;MACvB,IAAI,CAACP,eAAe,CAACQ,iBAAiB,CAACd,MAAM,CAACa,cAAc,CAAC;IACjE;IAEA,OAAO,IAAI;EACf,CAAC;AACL;AAACE,OAAA,CAAAhB,gBAAA,GAAAA,gBAAA"}
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.unistyles = void 0;
7
+ var _UnistylesModule = require("./UnistylesModule");
8
+ var _UnistylesRuntime = require("./UnistylesRuntime");
9
+ var _UnistyleRegistry = require("./UnistyleRegistry");
10
+ var _common = require("../common");
11
+ class Unistyles {
12
+ constructor() {
13
+ const isInstalled = _UnistylesModule.UnistylesModule?.install() ?? false;
14
+ if (!isInstalled) {
15
+ throw new Error(_common.UnistylesError.RuntimeUnavailable);
16
+ }
17
+
18
+ // @ts-ignore
19
+ this._bridge = global.__UNISTYLES__;
20
+ this._registry = new _UnistyleRegistry.UnistyleRegistry(this._bridge);
21
+ this._runtime = new _UnistylesRuntime.UnistylesRuntime(this._bridge, this._registry);
22
+ }
23
+ get registry() {
24
+ return this._registry;
25
+ }
26
+ get runtime() {
27
+ return this._runtime;
28
+ }
29
+ }
30
+ const unistyles = exports.unistyles = new Unistyles();
31
+ //# sourceMappingURL=Unistyles.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_UnistylesModule","require","_UnistylesRuntime","_UnistyleRegistry","_common","Unistyles","constructor","isInstalled","UnistylesModule","install","Error","UnistylesError","RuntimeUnavailable","_bridge","global","__UNISTYLES__","_registry","UnistyleRegistry","_runtime","UnistylesRuntime","registry","runtime","unistyles","exports"],"sourceRoot":"../../../src","sources":["core/Unistyles.ts"],"mappings":";;;;;;AAAA,IAAAA,gBAAA,GAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAH,OAAA;AAEA,MAAMI,SAAS,CAAC;EAKZC,WAAWA,CAAA,EAAG;IACV,MAAMC,WAAW,GAAGC,gCAAe,EAAEC,OAAO,CAAC,CAAC,IAAI,KAAK;IAEvD,IAAI,CAACF,WAAW,EAAE;MACd,MAAM,IAAIG,KAAK,CAACC,sBAAc,CAACC,kBAAkB,CAAC;IACtD;;IAEA;IACA,IAAI,CAACC,OAAO,GAAGC,MAAM,CAACC,aAAgC;IACtD,IAAI,CAACC,SAAS,GAAG,IAAIC,kCAAgB,CAAC,IAAI,CAACJ,OAAO,CAAC;IACnD,IAAI,CAACK,QAAQ,GAAG,IAAIC,kCAAgB,CAAC,IAAI,CAACN,OAAO,EAAE,IAAI,CAACG,SAAS,CAAC;EACtE;EAEA,IAAWI,QAAQA,CAAA,EAAG;IAClB,OAAO,IAAI,CAACJ,SAAS;EACzB;EAEA,IAAWK,OAAOA,CAAA,EAAG;IACjB,OAAO,IAAI,CAACH,QAAQ;EACxB;AACJ;AAEO,MAAMI,SAAS,GAAAC,OAAA,CAAAD,SAAA,GAAG,IAAIjB,SAAS,CAAC,CAAC"}
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.UnistylesModule = void 0;
7
+ var _reactNative = require("react-native");
8
+ const UnistylesModule = exports.UnistylesModule = _reactNative.NativeModules?.Unistyles;
9
+ //# sourceMappingURL=UnistylesModule.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","UnistylesModule","exports","NativeModules","Unistyles"],"sourceRoot":"../../../src","sources":["core/UnistylesModule.ts"],"mappings":";;;;;;AAAA,IAAAA,YAAA,GAAAC,OAAA;AAMO,MAAMC,eAAe,GAAAC,OAAA,CAAAD,eAAA,GAAGE,0BAAa,EAAEC,SAAkC"}