react-native-unistyles 3.0.0-beta.8 → 3.0.0-experimental-2025051401

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/README.md +32 -26
  2. package/Unistyles.podspec +1 -0
  3. package/android/src/main/cxx/NativeUnistylesModule.cpp +3 -7
  4. package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
  5. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
  6. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +2 -3
  7. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +1 -1
  8. package/android/src/main/java/com/unistyles/UnistylesModule.kt +1 -7
  9. package/components/native/ActivityIndicator/package.json +1 -0
  10. package/components/native/Animated/package.json +1 -0
  11. package/components/native/FlatList/package.json +1 -0
  12. package/components/native/Image/package.json +2 -1
  13. package/components/native/ImageBackground/package.json +1 -0
  14. package/components/native/KeyboardAvoidingView/package.json +1 -0
  15. package/components/native/NativeText/package.json +1 -0
  16. package/components/native/NativeView/package.json +1 -0
  17. package/components/native/Pressable/package.json +1 -0
  18. package/components/native/RefreshControl/package.json +1 -0
  19. package/components/native/ScrollView/package.json +1 -0
  20. package/components/native/SectionList/package.json +1 -0
  21. package/components/native/Switch/package.json +1 -0
  22. package/components/native/Text/package.json +1 -0
  23. package/components/native/TextInput/package.json +1 -0
  24. package/components/native/TouchableHighlight/package.json +1 -0
  25. package/components/native/TouchableOpacity/package.json +1 -0
  26. package/components/native/View/package.json +1 -0
  27. package/components/native/VirtualizedList/package.json +1 -0
  28. package/cxx/common/Helpers.h +4 -0
  29. package/cxx/core/HostUnistyle.cpp +14 -5
  30. package/cxx/core/StyleSheet.h +1 -1
  31. package/cxx/core/UnistyleWrapper.h +1 -1
  32. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  33. package/cxx/core/UnistylesRegistry.cpp +67 -64
  34. package/cxx/core/UnistylesRegistry.h +1 -1
  35. package/cxx/hybridObjects/HybridStyleSheet.cpp +10 -19
  36. package/cxx/hybridObjects/HybridStyleSheet.h +3 -8
  37. package/cxx/parser/Parser.cpp +161 -115
  38. package/cxx/parser/Parser.h +1 -1
  39. package/cxx/shadowTree/ShadowTrafficController.h +7 -9
  40. package/cxx/shadowTree/ShadowTreeManager.cpp +35 -33
  41. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  42. package/ios/NativePlatform+ios.swift +1 -1
  43. package/ios/NativePlatformListener+ios.swift +12 -7
  44. package/ios/UnistylesModuleOnLoad.h +1 -5
  45. package/ios/UnistylesModuleOnLoad.mm +5 -13
  46. package/lib/commonjs/components/native/Image.js +27 -1
  47. package/lib/commonjs/components/native/Image.js.map +1 -1
  48. package/lib/commonjs/components/native/Image.native.js +10 -0
  49. package/lib/commonjs/components/native/Image.native.js.map +1 -0
  50. package/lib/commonjs/components/native/ImageBackground.js +17 -28
  51. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  52. package/lib/commonjs/components/native/Pressable.native.js +7 -4
  53. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  54. package/lib/commonjs/core/createUnistylesElement.js +17 -21
  55. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  56. package/lib/commonjs/core/createUnistylesElement.native.js +6 -4
  57. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  58. package/lib/commonjs/core/createUnistylesImageBackground.js +7 -5
  59. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  60. package/lib/commonjs/core/getClassname.js +11 -5
  61. package/lib/commonjs/core/getClassname.js.map +1 -1
  62. package/lib/commonjs/core/passForwardRef.js +3 -5
  63. package/lib/commonjs/core/passForwardRef.js.map +1 -1
  64. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  65. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  66. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -1
  67. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  68. package/lib/commonjs/core/withUnistyles/withUnistyles.js +14 -5
  69. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  70. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +1 -1
  71. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  72. package/lib/commonjs/hooks/useMedia.js +4 -4
  73. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  74. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  75. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  76. package/lib/commonjs/mocks.js +203 -0
  77. package/lib/commonjs/mocks.js.map +1 -0
  78. package/lib/commonjs/mq.js +1 -23
  79. package/lib/commonjs/mq.js.map +1 -1
  80. package/lib/commonjs/reanimated/index.js +13 -0
  81. package/lib/commonjs/reanimated/index.js.map +1 -0
  82. package/lib/commonjs/reanimated/useAnimatedTheme.js +22 -0
  83. package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -0
  84. package/lib/commonjs/reanimated/useAnimatedTheme.native.js +24 -0
  85. package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -0
  86. package/lib/commonjs/server/getServerUnistyles.js +9 -4
  87. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  88. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  89. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  90. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  91. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  92. package/lib/commonjs/server/serialize.js +24 -0
  93. package/lib/commonjs/server/serialize.js.map +1 -0
  94. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  95. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  96. package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
  97. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  98. package/lib/commonjs/utils.js +23 -1
  99. package/lib/commonjs/utils.js.map +1 -1
  100. package/lib/commonjs/web/convert/index.js +4 -7
  101. package/lib/commonjs/web/convert/index.js.map +1 -1
  102. package/lib/commonjs/web/convert/object/filter.js +7 -8
  103. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  104. package/lib/commonjs/web/create.js +10 -2
  105. package/lib/commonjs/web/create.js.map +1 -1
  106. package/lib/commonjs/web/css/core.js +2 -2
  107. package/lib/commonjs/web/css/core.js.map +1 -1
  108. package/lib/commonjs/web/css/state.js +6 -3
  109. package/lib/commonjs/web/css/state.js.map +1 -1
  110. package/lib/commonjs/web/index.js +7 -12
  111. package/lib/commonjs/web/index.js.map +1 -1
  112. package/lib/commonjs/web/registry.js +11 -9
  113. package/lib/commonjs/web/registry.js.map +1 -1
  114. package/lib/commonjs/web/runtime.js +5 -1
  115. package/lib/commonjs/web/runtime.js.map +1 -1
  116. package/lib/commonjs/web/services.js +7 -2
  117. package/lib/commonjs/web/services.js.map +1 -1
  118. package/lib/commonjs/web/shadowRegistry.js +27 -10
  119. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  120. package/lib/commonjs/web/state.js +11 -2
  121. package/lib/commonjs/web/state.js.map +1 -1
  122. package/lib/commonjs/web/types.js +2 -0
  123. package/lib/commonjs/web/types.js.map +1 -1
  124. package/lib/commonjs/web/utils/createUnistylesRef.js +31 -0
  125. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -0
  126. package/lib/commonjs/web/utils/unistyle.js +40 -14
  127. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  128. package/lib/commonjs/web-only/getWebProps.js +19 -0
  129. package/lib/commonjs/web-only/getWebProps.js.map +1 -0
  130. package/lib/commonjs/web-only/index.js +13 -0
  131. package/lib/commonjs/web-only/index.js.map +1 -0
  132. package/lib/module/components/native/Image.js +26 -2
  133. package/lib/module/components/native/Image.js.map +1 -1
  134. package/lib/module/components/native/Image.native.js +6 -0
  135. package/lib/module/components/native/Image.native.js.map +1 -0
  136. package/lib/module/components/native/ImageBackground.js +18 -29
  137. package/lib/module/components/native/ImageBackground.js.map +1 -1
  138. package/lib/module/components/native/Pressable.native.js +7 -4
  139. package/lib/module/components/native/Pressable.native.js.map +1 -1
  140. package/lib/module/core/createUnistylesElement.js +17 -21
  141. package/lib/module/core/createUnistylesElement.js.map +1 -1
  142. package/lib/module/core/createUnistylesElement.native.js +6 -4
  143. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  144. package/lib/module/core/createUnistylesImageBackground.js +7 -5
  145. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  146. package/lib/module/core/getClassname.js +9 -5
  147. package/lib/module/core/getClassname.js.map +1 -1
  148. package/lib/module/core/passForwardRef.js +3 -5
  149. package/lib/module/core/passForwardRef.js.map +1 -1
  150. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  151. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  152. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -1
  153. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  154. package/lib/module/core/withUnistyles/withUnistyles.js +14 -5
  155. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  156. package/lib/module/core/withUnistyles/withUnistyles.native.js +1 -1
  157. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  158. package/lib/module/hooks/useMedia.js +1 -1
  159. package/lib/module/hooks/useMedia.js.map +1 -1
  160. package/lib/module/hooks/useMedia.native.js +1 -1
  161. package/lib/module/hooks/useMedia.native.js.map +1 -1
  162. package/lib/module/mocks.js +201 -0
  163. package/lib/module/mocks.js.map +1 -0
  164. package/lib/module/mq.js +0 -19
  165. package/lib/module/mq.js.map +1 -1
  166. package/lib/module/reanimated/index.js +4 -0
  167. package/lib/module/reanimated/index.js.map +1 -0
  168. package/lib/module/reanimated/useAnimatedTheme.js +17 -0
  169. package/lib/module/reanimated/useAnimatedTheme.js.map +1 -0
  170. package/lib/module/reanimated/useAnimatedTheme.native.js +19 -0
  171. package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -0
  172. package/lib/module/server/getServerUnistyles.js +7 -4
  173. package/lib/module/server/getServerUnistyles.js.map +1 -1
  174. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  175. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  176. package/lib/module/server/resetServerUnistyles.js +2 -2
  177. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  178. package/lib/module/server/serialize.js +19 -0
  179. package/lib/module/server/serialize.js.map +1 -0
  180. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  181. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  182. package/lib/module/specs/ShadowRegistry/index.js +2 -2
  183. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  184. package/lib/module/utils.js +19 -0
  185. package/lib/module/utils.js.map +1 -1
  186. package/lib/module/web/convert/index.js +4 -7
  187. package/lib/module/web/convert/index.js.map +1 -1
  188. package/lib/module/web/convert/object/filter.js +3 -4
  189. package/lib/module/web/convert/object/filter.js.map +1 -1
  190. package/lib/module/web/create.js +9 -3
  191. package/lib/module/web/create.js.map +1 -1
  192. package/lib/module/web/css/core.js +2 -2
  193. package/lib/module/web/css/core.js.map +1 -1
  194. package/lib/module/web/css/state.js +6 -3
  195. package/lib/module/web/css/state.js.map +1 -1
  196. package/lib/module/web/index.js +4 -10
  197. package/lib/module/web/index.js.map +1 -1
  198. package/lib/module/web/registry.js +11 -9
  199. package/lib/module/web/registry.js.map +1 -1
  200. package/lib/module/web/runtime.js +5 -1
  201. package/lib/module/web/runtime.js.map +1 -1
  202. package/lib/module/web/services.js +7 -1
  203. package/lib/module/web/services.js.map +1 -1
  204. package/lib/module/web/shadowRegistry.js +27 -10
  205. package/lib/module/web/shadowRegistry.js.map +1 -1
  206. package/lib/module/web/state.js +11 -2
  207. package/lib/module/web/state.js.map +1 -1
  208. package/lib/module/web/types.js +1 -1
  209. package/lib/module/web/types.js.map +1 -1
  210. package/lib/module/web/utils/createUnistylesRef.js +24 -0
  211. package/lib/module/web/utils/createUnistylesRef.js.map +1 -0
  212. package/lib/module/web/utils/unistyle.js +32 -10
  213. package/lib/module/web/utils/unistyle.js.map +1 -1
  214. package/lib/module/web-only/getWebProps.js +14 -0
  215. package/lib/module/web-only/getWebProps.js.map +1 -0
  216. package/lib/module/web-only/index.js +4 -0
  217. package/lib/module/web-only/index.js.map +1 -0
  218. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  219. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  220. package/lib/typescript/src/components/native/Image.native.d.ts +2 -0
  221. package/lib/typescript/src/components/native/Image.native.d.ts.map +1 -0
  222. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  223. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  224. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  225. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  226. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  227. package/lib/typescript/src/core/getClassname.d.ts +5 -5
  228. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  229. package/lib/typescript/src/core/passForwardRef.d.ts +1 -1
  230. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  231. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  232. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  233. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  234. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  235. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
  236. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  237. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
  238. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  239. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  240. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  241. package/lib/typescript/src/mocks.d.ts +2 -0
  242. package/lib/typescript/src/mocks.d.ts.map +1 -0
  243. package/lib/typescript/src/mq.d.ts +0 -8
  244. package/lib/typescript/src/mq.d.ts.map +1 -1
  245. package/lib/typescript/src/reanimated/index.d.ts +2 -0
  246. package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
  247. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts +4 -0
  248. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -0
  249. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts +4 -0
  250. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -0
  251. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  252. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  253. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  254. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  255. package/lib/typescript/src/server/serialize.d.ts +2 -0
  256. package/lib/typescript/src/server/serialize.d.ts.map +1 -0
  257. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  258. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  259. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  260. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  261. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  262. package/lib/typescript/src/types/common.d.ts +0 -1
  263. package/lib/typescript/src/types/common.d.ts.map +1 -1
  264. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  265. package/lib/typescript/src/utils.d.ts +8 -0
  266. package/lib/typescript/src/utils.d.ts.map +1 -1
  267. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  268. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  269. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  270. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  271. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  272. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  273. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  274. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  275. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  276. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  277. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  278. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  279. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  280. package/lib/typescript/src/web/create.d.ts.map +1 -1
  281. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  282. package/lib/typescript/src/web/css/state.d.ts +4 -1
  283. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  284. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  285. package/lib/typescript/src/web/index.d.ts +0 -5
  286. package/lib/typescript/src/web/index.d.ts.map +1 -1
  287. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  288. package/lib/typescript/src/web/registry.d.ts +2 -2
  289. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  290. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  291. package/lib/typescript/src/web/services.d.ts +6 -1
  292. package/lib/typescript/src/web/services.d.ts.map +1 -1
  293. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -2
  294. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  295. package/lib/typescript/src/web/state.d.ts +2 -0
  296. package/lib/typescript/src/web/state.d.ts.map +1 -1
  297. package/lib/typescript/src/web/types.d.ts +3 -0
  298. package/lib/typescript/src/web/types.d.ts.map +1 -1
  299. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  300. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +11 -0
  301. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -0
  302. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -2
  303. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  304. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  305. package/lib/typescript/src/web-only/getWebProps.d.ts +7 -0
  306. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -0
  307. package/lib/typescript/src/web-only/index.d.ts +2 -0
  308. package/lib/typescript/src/web-only/index.d.ts.map +1 -0
  309. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
  310. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  311. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  312. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  313. package/package.json +66 -32
  314. package/plugin/index.js +155 -67
  315. package/reanimated/package.json +6 -0
  316. package/server/package.json +6 -0
  317. package/src/components/native/Image.native.tsx +4 -0
  318. package/src/components/native/Image.tsx +36 -3
  319. package/src/components/native/ImageBackground.tsx +18 -33
  320. package/src/components/native/Pressable.native.tsx +12 -4
  321. package/src/core/createUnistylesElement.native.tsx +12 -6
  322. package/src/core/createUnistylesElement.tsx +26 -27
  323. package/src/core/createUnistylesImageBackground.tsx +16 -10
  324. package/src/core/getClassname.ts +16 -5
  325. package/src/core/passForwardRef.ts +5 -5
  326. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  327. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +17 -0
  328. package/src/core/withUnistyles/withUnistyles.native.tsx +3 -4
  329. package/src/core/withUnistyles/withUnistyles.tsx +23 -6
  330. package/src/hooks/useMedia.native.ts +1 -1
  331. package/src/hooks/useMedia.ts +1 -1
  332. package/src/mocks.ts +217 -0
  333. package/src/mq.ts +0 -24
  334. package/src/reanimated/index.ts +1 -0
  335. package/src/reanimated/useAnimatedTheme.native.ts +21 -0
  336. package/src/reanimated/useAnimatedTheme.ts +19 -0
  337. package/src/server/getServerUnistyles.tsx +15 -10
  338. package/src/server/hydrateServerUnistyles.ts +3 -2
  339. package/src/server/resetServerUnistyles.ts +4 -3
  340. package/src/server/serialize.ts +20 -0
  341. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  342. package/src/specs/ShadowRegistry/index.ts +1 -2
  343. package/src/types/common.ts +0 -1
  344. package/src/utils.ts +25 -0
  345. package/src/web/convert/index.ts +5 -7
  346. package/src/web/convert/object/filter.ts +4 -4
  347. package/src/web/create.ts +10 -3
  348. package/src/web/css/core.ts +2 -2
  349. package/src/web/css/state.ts +5 -3
  350. package/src/web/index.ts +4 -16
  351. package/src/web/registry.ts +20 -11
  352. package/src/web/runtime.ts +6 -2
  353. package/src/web/services.ts +14 -1
  354. package/src/web/shadowRegistry.ts +35 -13
  355. package/src/web/state.ts +14 -2
  356. package/src/web/types.ts +9 -4
  357. package/src/web/utils/createUnistylesRef.ts +33 -0
  358. package/src/web/utils/unistyle.ts +55 -23
  359. package/src/web-only/getWebProps.ts +18 -0
  360. package/src/web-only/index.ts +2 -0
  361. package/web/package.json +6 -0
  362. package/cxx/core/UnistylesCommitHook.cpp +0 -52
  363. package/cxx/core/UnistylesCommitHook.h +0 -27
  364. package/cxx/core/UnistylesMountHook.cpp +0 -28
  365. package/cxx/core/UnistylesMountHook.h +0 -24
  366. package/lib/module/package.json +0 -1
  367. /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
@@ -1,45 +1,44 @@
1
1
  import React from 'react'
2
+ import type { ViewStyle } from 'react-native'
2
3
  import type { UnistylesValues } from '../types'
3
4
  import { copyComponentProperties } from '../utils'
4
- import { UnistylesShadowRegistry } from '../web'
5
5
  import { isServer } from '../web/utils'
6
+ import { createUnistylesRef } from '../web/utils/createUnistylesRef'
6
7
  import { getClassName } from './getClassname'
7
8
  import { maybeWarnAboutMultipleUnistyles } from './warn'
8
9
 
10
+ const STYLE_PROPS = ['style', 'contentContainerStyle', 'columnWrapperStyle'] as const
11
+
9
12
  type ComponentProps = {
10
- style?: UnistylesValues | Array<UnistylesValues>
13
+ [K in typeof STYLE_PROPS[number]]?: UnistylesValues
14
+ }
15
+
16
+ const buildUnistylesProps = (Component: any, props: ComponentProps, forwardedRef: React.ForwardedRef<unknown>) => {
17
+ const componentStyleProps = STYLE_PROPS.filter(styleProp => styleProp in props)
18
+ const classNames = Object.fromEntries(componentStyleProps.map(styleProp => [styleProp, getClassName(props[styleProp])]))
19
+ const refs = componentStyleProps.map(styleProp => {
20
+ return createUnistylesRef(
21
+ classNames[styleProp],
22
+ styleProp === 'style' ? forwardedRef : undefined
23
+ )
24
+ })
25
+
26
+ componentStyleProps.forEach(styleProp => {
27
+ maybeWarnAboutMultipleUnistyles(props[styleProp] as ViewStyle, Component.displayName)
28
+ })
29
+
30
+ return {
31
+ ...classNames,
32
+ ref: isServer() ? undefined : (componentRef: any) => refs.forEach(ref => ref?.(componentRef))
33
+ }
11
34
  }
12
35
 
13
36
  export const createUnistylesElement = (Component: any) => {
14
37
  const UnistylesComponent = React.forwardRef<unknown, ComponentProps>((props, forwardedRef) => {
15
- let storedRef: HTMLElement | null = null
16
- const classNames = getClassName(props.style)
17
-
18
38
  return (
19
39
  <Component
20
40
  {...props}
21
- style={classNames}
22
- ref={isServer() ? undefined : (ref: HTMLElement | null) => {
23
- // @ts-ignore we don't know the type of the component
24
- maybeWarnAboutMultipleUnistyles(props.style, Component.displayName)
25
-
26
- if (!ref) {
27
- // @ts-expect-error hidden from TS
28
- UnistylesShadowRegistry.remove(storedRef, classNames?.hash)
29
- }
30
-
31
- storedRef = ref
32
- // @ts-expect-error hidden from TS
33
- UnistylesShadowRegistry.add(ref, classNames?.hash)
34
-
35
- if (typeof forwardedRef === 'function') {
36
- return forwardedRef(ref)
37
- }
38
-
39
- if (forwardedRef) {
40
- forwardedRef.current = ref
41
- }
42
- }}
41
+ {...buildUnistylesProps(Component, props, forwardedRef)}
43
42
  />
44
43
  )
45
44
  })
@@ -27,17 +27,23 @@ export const createUnistylesImageBackground = (Component: typeof ImageBackground
27
27
  <Component
28
28
  {...props}
29
29
  ref={ref => {
30
- passForwardedRef(props, ref, forwardedRef)
31
-
32
- return () => {
33
- // @ts-ignore
34
- UnistylesShadowRegistry.remove(ref)
35
-
36
- if (storedImageRef.current) {
37
- // @ts-ignore
38
- UnistylesShadowRegistry.remove(storedImageRef.current)
30
+ return passForwardedRef(
31
+ ref,
32
+ forwardedRef,
33
+ () => {
34
+ // @ts-expect-error - this is hidden from TS
35
+ UnistylesShadowRegistry.add(ref, props.style)
36
+ },
37
+ () => {
38
+ // @ts-expect-error - this is hidden from TS
39
+ UnistylesShadowRegistry.remove(ref)
40
+
41
+ if (storedImageRef.current) {
42
+ // @ts-expect-error - this is hidden from TS
43
+ UnistylesShadowRegistry.remove(storedImageRef.current)
44
+ }
39
45
  }
40
- }
46
+ )
41
47
  }}
42
48
  imageRef={ref => {
43
49
  if (ref) {
@@ -1,14 +1,25 @@
1
1
  import type { UnistylesValues } from '../types'
2
- import { UnistylesWeb } from '../web'
2
+ import * as unistyles from '../web/services'
3
+ import { checkForAnimated } from '../web/utils'
3
4
 
4
- export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>) => {
5
+ export const getClassName = (unistyle: UnistylesValues | undefined | Array<UnistylesValues>, forChild?: boolean) => {
5
6
  if (!unistyle) {
6
7
  return undefined
7
8
  }
8
9
 
9
- const { hash, injectedClassName } = UnistylesWeb.shadowRegistry.addStyles(
10
- Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
10
+ const flattenedStyles = Array.isArray(unistyle) ? unistyle.flat(Number.POSITIVE_INFINITY) : [unistyle]
11
+ const animatedStyles = flattenedStyles.filter(checkForAnimated)
12
+ const regularStyles = flattenedStyles.filter(style => !checkForAnimated(style))
13
+
14
+ const { hash, injectedClassName } = unistyles.services.shadowRegistry.addStyles(
15
+ regularStyles,
16
+ forChild
11
17
  )
12
18
 
13
- return hash ? { $$css: true, hash, injectedClassName } : undefined
19
+ return hash
20
+ ? [
21
+ { $$css: true, hash, injectedClassName },
22
+ animatedStyles,
23
+ ] as const
24
+ : undefined
14
25
  }
@@ -1,10 +1,10 @@
1
1
  import React from 'react'
2
- import { UnistylesShadowRegistry } from '../specs'
3
2
 
4
3
  export const passForwardedRef = <T>(
5
- props: any,
6
4
  ref: T,
7
- forwardedRef: React.ForwardedRef<T>
5
+ forwardedRef: React.ForwardedRef<T>,
6
+ onMount?: () => void,
7
+ onUnmount?: () => void
8
8
  ) => {
9
9
  const passForwardedRef = () => {
10
10
  if (typeof forwardedRef === 'function') {
@@ -19,10 +19,10 @@ export const passForwardedRef = <T>(
19
19
  }
20
20
  const forwardedRefReturnFn = passForwardedRef()
21
21
 
22
- // @ts-expect-error hidden from TS
23
- UnistylesShadowRegistry.add(ref, props.style)
22
+ onMount?.()
24
23
 
25
24
  return () => {
26
25
  forwardedRefReturnFn?.()
26
+ onUnmount?.()
27
27
  }
28
28
  }
@@ -1,10 +1,10 @@
1
1
  import { UnistyleDependency } from '../../specs'
2
- import { UnistylesWeb } from '../../web'
2
+ import * as unistyles from '../../web/services'
3
3
  import type { ListenerProps } from './types'
4
4
 
5
5
  export const listener = ({ dependencies, updateTheme, updateRuntime }: ListenerProps) => {
6
- const disposeTheme = UnistylesWeb.listener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
7
- const disposeRuntime = UnistylesWeb.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
6
+ const disposeTheme = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
7
+ const disposeRuntime = unistyles.services.listener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
8
8
 
9
9
  return () => {
10
10
  disposeTheme()
@@ -24,6 +24,7 @@ const RTDependencyMap = {
24
24
  statusBar: UnistyleDependency.StatusBar,
25
25
  pixelRatio: UnistyleDependency.PixelRatio,
26
26
  themeName: UnistyleDependency.ThemeName,
27
+ rtl: UnistyleDependency.Rtl
27
28
  } satisfies Partial<Record<keyof UnistylesMiniRuntime, UnistyleDependency>>
28
29
 
29
30
  export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
@@ -63,6 +64,22 @@ export const useProxifiedUnistyles = (forcedTheme?: UnistylesTheme) => {
63
64
  })
64
65
  const proxifiedRuntime = new Proxy(getMiniRuntime(), {
65
66
  get: (target, prop) => {
67
+ if (prop === 'insets') {
68
+ return new Proxy(target.insets, {
69
+ get: (target, prop) => {
70
+ if (prop === 'ime') {
71
+ dependencies.add(UnistyleDependency.Ime)
72
+
73
+ return target[prop as keyof typeof target]
74
+ }
75
+
76
+ dependencies.add(UnistyleDependency.Insets)
77
+
78
+ return target[prop as keyof typeof target]
79
+ }
80
+ })
81
+ }
82
+
66
83
  if (prop in RTDependencyMap) {
67
84
  dependencies.add(RTDependencyMap[prop as keyof typeof RTDependencyMap])
68
85
  }
@@ -1,11 +1,10 @@
1
1
  import React, { forwardRef, useEffect, type ComponentType, useRef } from 'react'
2
2
  import { type UnistyleDependency, UnistylesShadowRegistry } from '../../specs'
3
3
  import type { UnistylesTheme } from '../../types'
4
- import type { PartialBy } from '../../types/common'
5
4
  import { deepMergeObjects } from '../../utils'
6
5
  import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
7
6
  import { maybeWarnAboutMultipleUnistyles } from '../warn'
8
- import type { Mappings, SupportedStyleProps } from './types'
7
+ import type { Mappings } from './types'
9
8
 
10
9
  // @ts-expect-error
11
10
  type GenericComponentProps<P> = ComponentProps<P>
@@ -24,7 +23,7 @@ type MappedSecrets = {
24
23
 
25
24
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
26
25
  type TProps = GenericComponentProps<TComponent>
27
- type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
26
+ type PropsWithUnistyles = Partial<TProps> & {
28
27
  uniProps?: Mappings<TProps>
29
28
  }
30
29
  const getSecrets = (styleProps: Record<string, any> = {}): MappedSecrets => {
@@ -43,7 +42,7 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
43
42
  unistyleKey
44
43
  ? style[unistyleKey]
45
44
  : {
46
- uni__getStyles: () => styleProps,
45
+ uni__getStyles: () => style,
47
46
  uni__dependencies: [],
48
47
  }
49
48
  ])
@@ -1,11 +1,10 @@
1
1
  import React, { type ComponentType, forwardRef, type ComponentProps, type ComponentRef } from 'react'
2
2
  import type { UnistylesValues } from '../../types'
3
- import type { PartialBy } from '../../types/common'
4
3
  import { deepMergeObjects } from '../../utils'
5
4
  import { getClassName } from '../getClassname'
6
5
  import { useProxifiedUnistyles } from '../useProxifiedUnistyles'
7
6
  import { maybeWarnAboutMultipleUnistyles } from '../warn'
8
- import type { Mappings, SupportedStyleProps } from './types'
7
+ import type { Mappings } from './types'
9
8
 
10
9
  // @ts-expect-error
11
10
  type GenericComponentProps<T> = ComponentProps<T>
@@ -14,7 +13,7 @@ type GenericComponentRef<T> = ComponentRef<T>
14
13
 
15
14
  export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
16
15
  type TProps = GenericComponentProps<TComponent>
17
- type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
16
+ type PropsWithUnistyles = Partial<TProps> & {
18
17
  uniProps?: Mappings<TProps>
19
18
  }
20
19
  type UnistyleStyles = {
@@ -24,17 +23,27 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
24
23
 
25
24
  return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
26
25
  const narrowedProps = props as PropsWithUnistyles & UnistyleStyles
27
- const styleClassNames = getClassName(narrowedProps.style)
26
+ const styleClassNames = getClassName(narrowedProps.style, true)
28
27
  const contentContainerStyleClassNames = getClassName(narrowedProps.contentContainerStyle)
29
28
  const { proxifiedRuntime, proxifiedTheme } = useProxifiedUnistyles()
30
29
 
31
30
  const mappingsProps = mappings ? mappings(proxifiedTheme, proxifiedRuntime) : {}
32
31
  const unistyleProps = narrowedProps.uniProps ? narrowedProps.uniProps(proxifiedTheme, proxifiedRuntime) : {}
33
32
 
33
+
34
+ const emptyStyles = narrowedProps.style
35
+ ? Object.fromEntries(
36
+ Object.entries(Object.getOwnPropertyDescriptors(narrowedProps.style))
37
+ .filter(([key]) => !key.startsWith("unistyles") && !key.startsWith("_"))
38
+ .map(([key]) => [key, undefined])
39
+ )
40
+ : undefined
41
+
34
42
  const combinedProps = {
35
43
  ...deepMergeObjects(mappingsProps, unistyleProps, props),
36
44
  ...narrowedProps.style ? {
37
- style: styleClassNames,
45
+ // Override default component styles with undefined values to reset them
46
+ style: emptyStyles
38
47
  } : {},
39
48
  ...narrowedProps.contentContainerStyle ? {
40
49
  contentContainerStyle: contentContainerStyleClassNames,
@@ -47,7 +56,15 @@ export const withUnistyles = <TComponent, TMappings extends GenericComponentProp
47
56
  maybeWarnAboutMultipleUnistyles(narrowedProps.contentContainerStyle, `withUnistyles(${Component.displayName ?? Component.name ?? 'Unknown'})`)
48
57
 
49
58
  const NativeComponent = Component as ComponentType
59
+ const [classNames] = styleClassNames ?? []
50
60
 
51
- return <NativeComponent {...combinedProps} ref={ref} />
61
+ return (
62
+ <div
63
+ className={classNames?.hash}
64
+ style={{ display: 'contents' }}
65
+ >
66
+ <NativeComponent {...combinedProps} ref={ref} />
67
+ </div>
68
+ )
52
69
  })
53
70
  }
@@ -1,6 +1,6 @@
1
1
  import { useEffect, useLayoutEffect, useState } from 'react'
2
- import { isUnistylesMq, isValidMq, parseMq } from '../mq'
3
2
  import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
3
+ import { isUnistylesMq, isValidMq, parseMq } from '../utils'
4
4
 
5
5
  export const useMedia = (config: { mq: symbol }) => {
6
6
  const computeIsVisible = (): boolean => {
@@ -1,5 +1,5 @@
1
1
  import { useEffect, useRef, useState } from 'react'
2
- import { isUnistylesMq, isValidMq, parseMq } from '../mq'
2
+ import { isUnistylesMq, isValidMq, parseMq } from '../utils'
3
3
 
4
4
  export const useMedia = (config: { mq: symbol }) => {
5
5
  const disposeRef = useRef(() => {})
package/src/mocks.ts ADDED
@@ -0,0 +1,217 @@
1
+ import type { UnistylesBreakpoints, UnistylesThemes } from './global'
2
+ import type { UnistylesNavigationBar } from './specs/NavigtionBar'
3
+ import type { UnistylesStatusBar } from './specs/StatusBar'
4
+ import type { UnistylesConfig, UnistylesStyleSheet } from './specs/StyleSheet'
5
+ import type { UnistylesRuntimePrivate } from './specs/UnistylesRuntime'
6
+ import type { ColorScheme, Orientation } from './specs/types'
7
+ import type { IOSContentSizeCategory, UnistylesTheme } from './types'
8
+
9
+ type Registry = {
10
+ themes: UnistylesThemes
11
+ breakpoints: UnistylesBreakpoints
12
+ }
13
+
14
+ jest.mock('react-native-nitro-modules', () => ({
15
+ NitroModules: {
16
+ createHybridObject: () => ({
17
+ add: () => {},
18
+ init: () => {},
19
+ createHybridStatusBar: () => ({
20
+ setStyle: () => {},
21
+ }),
22
+ createHybridNavigationBar: () => {},
23
+ })
24
+ }
25
+ }))
26
+
27
+ jest.mock('react-native-unistyles', () => {
28
+ const React = require('react')
29
+ const _REGISTRY: Registry = {
30
+ themes: {},
31
+ breakpoints: {}
32
+ }
33
+ const miniRuntime = {
34
+ themeName: undefined,
35
+ breakpoint: undefined,
36
+ hasAdaptiveThemes: false,
37
+ colorScheme: 'unspecified' as ColorScheme,
38
+ contentSizeCategory: 'Medium' as IOSContentSizeCategory,
39
+ insets: {
40
+ top: 0,
41
+ left: 0,
42
+ right: 0,
43
+ bottom: 0,
44
+ ime: 0
45
+ },
46
+ pixelRatio: 1,
47
+ fontScale: 1,
48
+ rtl: false,
49
+ isLandscape: false,
50
+ isPortrait: true,
51
+ navigationBar: {
52
+ width: 0,
53
+ height: 0
54
+ },
55
+ screen: {
56
+ width: 0,
57
+ height: 0
58
+ },
59
+ statusBar: {
60
+ width: 0,
61
+ height: 0
62
+ }
63
+ }
64
+ const unistylesRuntime = {
65
+ colorScheme: 'unspecified' as ColorScheme,
66
+ contentSizeCategory: 'Medium' as IOSContentSizeCategory,
67
+ orientation: 'portrait' as Orientation,
68
+ breakpoints: {},
69
+ dispose: () => { },
70
+ equals: () => false,
71
+ name: 'UnistylesRuntimeMock',
72
+ miniRuntime: miniRuntime,
73
+ statusBar: {
74
+ height: 0,
75
+ width: 0,
76
+ name: 'StatusBarMock',
77
+ equals: () => false,
78
+ setHidden: () => { },
79
+ setStyle: () => { }
80
+ },
81
+ navigationBar: {
82
+ height: 0,
83
+ width: 0,
84
+ name: 'NavigationBarMock',
85
+ equals: () => false,
86
+ setHidden: () => { },
87
+ dispose: () => { }
88
+ },
89
+ fontScale: 1,
90
+ hasAdaptiveThemes: false,
91
+ pixelRatio: 0,
92
+ rtl: false,
93
+ getTheme: () => {
94
+ return {} as UnistylesTheme
95
+ },
96
+ setTheme: () => {},
97
+ updateTheme: () => {},
98
+ setRootViewBackgroundColor: () => {},
99
+ _setRootViewBackgroundColor: () => {},
100
+ createHybridStatusBar: () => {
101
+ return {} as UnistylesStatusBar
102
+ },
103
+ createHybridNavigationBar: () => {
104
+ return {} as UnistylesNavigationBar
105
+ },
106
+ setAdaptiveThemes: () => {},
107
+ setImmersiveMode: () => {},
108
+ insets: {
109
+ top: 0,
110
+ left: 0,
111
+ right: 0,
112
+ bottom: 0,
113
+ ime: 0
114
+ },
115
+ screen: {
116
+ width: 0,
117
+ height: 0
118
+ },
119
+ breakpoint: undefined
120
+ } satisfies UnistylesRuntimePrivate
121
+
122
+ return {
123
+ Hide: () => null,
124
+ Display: () => null,
125
+ ScopedTheme: () => null,
126
+ withUnistyles: <TComponent,>(Component: TComponent, mapper?: (theme: UnistylesTheme, runtime: typeof miniRuntime) => TComponent) => (props: any) =>
127
+ React.createElement(Component, {
128
+ ...mapper?.((Object.values(_REGISTRY.themes).at(0) ?? {}) as UnistylesTheme, miniRuntime),
129
+ ...props
130
+ }),
131
+ mq: {
132
+ only: {
133
+ width: () => ({
134
+ and: {
135
+ height: () => ({})
136
+ }
137
+ }),
138
+ height: () => ({
139
+ and: {
140
+ width: () => ({})
141
+ }
142
+ })
143
+ },
144
+ width: () => ({
145
+ and: {
146
+ height: () => ({})
147
+ }
148
+ }),
149
+ height: () => ({
150
+ and: {
151
+ width: () => ({})
152
+ }
153
+ })
154
+ },
155
+ useUnistyles: () => ({
156
+ theme: Object.values(_REGISTRY.themes).at(0) ?? {},
157
+ rt: unistylesRuntime
158
+ }),
159
+ StyleSheet: {
160
+ absoluteFillObject: {
161
+ position: 'absolute',
162
+ left: 0,
163
+ right: 0,
164
+ top: 0,
165
+ bottom: 0
166
+ },
167
+ absoluteFill: {
168
+ position: 'absolute',
169
+ left: 0,
170
+ right: 0,
171
+ top: 0,
172
+ bottom: 0
173
+ } as unknown as UnistylesStyleSheet['absoluteFill'],
174
+ compose: (styles: any) => {
175
+ return styles
176
+ },
177
+ flatten: (styles: any) => {
178
+ return styles
179
+ },
180
+ create: (styles: any) => {
181
+ if (typeof styles === 'function') {
182
+ return {
183
+ ...styles(Object.values(_REGISTRY.themes).at(0) ?? {}, miniRuntime),
184
+ useVariants: () => {}
185
+ }
186
+ }
187
+
188
+ return {
189
+ ...styles,
190
+ useVariants: () => {}
191
+ }
192
+ },
193
+ configure: (config: UnistylesConfig) => {
194
+ if (config.breakpoints) {
195
+ _REGISTRY.breakpoints = config.breakpoints
196
+ }
197
+
198
+ if (config.themes) {
199
+ _REGISTRY.themes = config.themes
200
+ }
201
+ },
202
+ jsMethods: {
203
+ processColor: () => null
204
+ },
205
+ hairlineWidth: 1,
206
+ unid: -1,
207
+ addChangeListener: () => () => {},
208
+ init: () => {},
209
+ name: 'StyleSheetMock',
210
+ dispose: () => {},
211
+ equals: () => false
212
+ } satisfies UnistylesStyleSheet,
213
+ UnistylesRuntime: unistylesRuntime
214
+ }
215
+ })
216
+
217
+
package/src/mq.ts CHANGED
@@ -2,10 +2,6 @@ import type { UnistylesBreakpoints } from './global'
2
2
  import { UnistylesRuntime } from './specs'
3
3
  import type { Nullable } from './types'
4
4
 
5
- const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
6
- const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
7
- const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
8
-
9
5
  type MQValue = keyof UnistylesBreakpoints | number
10
6
 
11
7
  type MQHandler = {
@@ -62,23 +58,3 @@ export const mq: MQHandler = {
62
58
  })
63
59
  }
64
60
 
65
- export const parseMq = (mq: string) => {
66
- const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
67
- const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
68
-
69
- return {
70
- minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
71
- maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
72
- minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
73
- maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
74
- }
75
- }
76
-
77
- export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
78
-
79
- export const isValidMq = (parsedMQ: ReturnType<typeof parseMq>) => {
80
- const isWidthValid = parsedMQ.minWidth === undefined || parsedMQ.maxWidth === undefined || parsedMQ.minWidth <= parsedMQ.maxWidth
81
- const isHeightValid = parsedMQ.minHeight === undefined || parsedMQ.maxHeight === undefined || parsedMQ.minHeight <= parsedMQ.maxHeight
82
-
83
- return isWidthValid && isHeightValid
84
- }
@@ -0,0 +1 @@
1
+ export { useAnimatedTheme } from './useAnimatedTheme'
@@ -0,0 +1,21 @@
1
+ import { useEffect } from 'react'
2
+ import { type SharedValue, useSharedValue } from 'react-native-reanimated'
3
+ import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
4
+ import type { UnistylesTheme } from '../types'
5
+
6
+ export const useAnimatedTheme = () => {
7
+ const theme = useSharedValue(UnistylesRuntime.getTheme())
8
+
9
+ useEffect(() => {
10
+ // @ts-ignore this is hidden from TS
11
+ const dispose = StyleSheet.addChangeListener(changedDependencies => {
12
+ if (changedDependencies.includes(UnistyleDependency.Theme)) {
13
+ theme.set(UnistylesRuntime.getTheme())
14
+ }
15
+ })
16
+
17
+ return () => dispose()
18
+ }, [])
19
+
20
+ return theme as SharedValue<UnistylesTheme>
21
+ }
@@ -0,0 +1,19 @@
1
+ import { useEffect } from 'react'
2
+ import { type SharedValue, useSharedValue } from 'react-native-reanimated'
3
+ import { UnistyleDependency, UnistylesRuntime } from '../specs'
4
+ import type { UnistylesTheme } from '../types'
5
+ import { services } from '../web/services'
6
+
7
+ export const useAnimatedTheme = () => {
8
+ const theme = useSharedValue(UnistylesRuntime.getTheme())
9
+
10
+ useEffect(() => {
11
+ const dispose = services.listener.addListeners([UnistyleDependency.Theme], () => theme.set(UnistylesRuntime.getTheme()))
12
+
13
+ return () => {
14
+ dispose()
15
+ }
16
+ }, [])
17
+
18
+ return theme as SharedValue<UnistylesTheme>
19
+ }
@@ -1,21 +1,26 @@
1
1
  import React from 'react'
2
2
  import { StyleSheet } from 'react-native'
3
- import { UnistylesWeb } from '../web'
3
+ import * as unistyles from '../web/services'
4
4
  import { error, isServer } from '../web/utils'
5
+ import { serialize } from './serialize'
5
6
  import { DefaultServerUnistylesSettings, type ServerUnistylesSettings } from './types'
6
7
 
7
8
  export const getServerUnistyles = ({ includeRNWStyles = true }: ServerUnistylesSettings = DefaultServerUnistylesSettings) => {
8
9
  if (!isServer()) {
9
10
  throw error('Server styles should only be read on the server')
10
11
  }
12
+
11
13
  // @ts-ignore
12
14
  const rnwStyle: string | null = includeRNWStyles ? (StyleSheet?.getSheet().textContent ?? '') : null
13
- const css = UnistylesWeb.registry.css.getStyles()
14
- const state = UnistylesWeb.registry.css.getState()
15
- return <>
16
- {rnwStyle && <style id='rnw-style'>{rnwStyle}</style>}
17
- <style id='unistyles-web'>{css}</style>
18
- {/* biome-ignore lint/security/noDangerouslySetInnerHtml: Needs the json quotes to be unescaped */}
19
- <script id='unistyles-script' dangerouslySetInnerHTML={{ __html: `window.__UNISTYLES_STATE__ = ${JSON.stringify(state)}`}} />
20
- </>
21
- }
15
+ const css = unistyles.services.registry.css.getStyles()
16
+ const state = unistyles.services.registry.css.getState()
17
+
18
+ return (
19
+ <>
20
+ {rnwStyle && <style id='rnw-style'>{rnwStyle}</style>}
21
+ <style id='unistyles-web'>{css}</style>
22
+ {/* biome-ignore lint/security/noDangerouslySetInnerHtml: Needs the json quotes to be unescaped */}
23
+ <script id='unistyles-script' defer dangerouslySetInnerHTML={{ __html: `window.__UNISTYLES_STATE__ = ${serialize(state)}`}} />
24
+ </>
25
+ )
26
+ }