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,4 +1,4 @@
1
- import { UnistylesWeb } from '../web'
1
+ import * as unistyles from '../web/services'
2
2
  import { error, isServer } from '../web/utils'
3
3
 
4
4
  declare global {
@@ -12,6 +12,7 @@ export const hydrateServerUnistyles = () => {
12
12
  if (isServer()) {
13
13
  throw error('Server styles should only be hydrated on the client')
14
14
  }
15
- UnistylesWeb.registry.css.hydrate(window.__UNISTYLES_STATE__)
15
+
16
+ unistyles.services.registry.css.hydrate(window.__UNISTYLES_STATE__)
16
17
  document.querySelector('#unistyles-script')?.remove()
17
18
  }
@@ -1,9 +1,10 @@
1
- import { UnistylesWeb } from '../web'
1
+ import * as unistyles from '../web/services'
2
2
  import { error, isServer } from '../web/utils'
3
3
 
4
4
  export const resetServerUnistyles = () => {
5
5
  if (!isServer()) {
6
6
  throw error('Server styles should only be reset on the server')
7
7
  }
8
- UnistylesWeb.registry.reset()
9
- }
8
+
9
+ unistyles.services.registry.reset()
10
+ }
@@ -0,0 +1,20 @@
1
+ export const serialize = (value: any): string => {
2
+ switch (typeof value) {
3
+ case 'function':
4
+ return value.toString()
5
+ case 'object':
6
+ if (Array.isArray(value)) {
7
+ return `[${value.map(serialize).join(',')}]`
8
+ }
9
+
10
+ if (value === null) {
11
+ return 'null'
12
+ }
13
+
14
+ return `{${Object.entries(value)
15
+ .map(([key, value]) => `'${key}':${serialize(value)}`)
16
+ .join(',')}}`
17
+ default:
18
+ return JSON.stringify(value)
19
+ }
20
+ }
@@ -19,7 +19,8 @@ export enum UnistyleDependency {
19
19
  FontScale = 11,
20
20
  StatusBar = 12,
21
21
  NavigationBar = 13,
22
- Ime = 14
22
+ Ime = 14,
23
+ Rtl = 15
23
24
  }
24
25
 
25
26
  export interface UnistylesNativeMiniRuntime {
@@ -40,9 +40,8 @@ HybridShadowRegistry.add = (handle, styles) => {
40
40
  ? styles.flat()
41
41
  : [styles]
42
42
 
43
- // filter Reanimated styles and styles that are undefined
43
+ // filter styles that are undefined or with no keys
44
44
  const filteredStyles = stylesArray
45
- .filter(style => !style?.initial?.updater)
46
45
  .filter(style => style && Object.keys(style).length > 0)
47
46
  .flat()
48
47
  .filter(Boolean)
@@ -1,5 +1,4 @@
1
1
  export type Optional<T> = T | undefined
2
2
  export type Nullable<T> = T | null
3
3
  export type SafeReturnType<T> = T extends (...args: any) => infer R ? R : T
4
- export type PartialBy<T, K> = Omit<T, K & keyof T> & Partial<Pick<T, K & keyof T>>
5
4
  export type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never
package/src/utils.ts CHANGED
@@ -41,3 +41,28 @@ export const copyComponentProperties = (Component: any, UnistylesComponent: any)
41
41
 
42
42
  return UnistylesComponent
43
43
  }
44
+
45
+ const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
46
+ const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
47
+ const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
48
+
49
+ export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
50
+
51
+ export const parseMq = (mq: string) => {
52
+ const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
53
+ const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
54
+
55
+ return {
56
+ minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
57
+ maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
58
+ minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
59
+ maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
60
+ }
61
+ }
62
+
63
+ export const isValidMq = (parsedMQ: ReturnType<typeof parseMq>) => {
64
+ const isWidthValid = parsedMQ.minWidth === undefined || parsedMQ.maxWidth === undefined || parsedMQ.minWidth <= parsedMQ.maxWidth
65
+ const isHeightValid = parsedMQ.minHeight === undefined || parsedMQ.maxHeight === undefined || parsedMQ.minHeight <= parsedMQ.maxHeight
66
+
67
+ return isWidthValid && isHeightValid
68
+ }
@@ -1,21 +1,19 @@
1
1
  import type { UnistylesValues } from '../../types'
2
2
  import { deepMergeObjects } from '../../utils'
3
+ import type { UnistylesRuntime } from '../runtime'
3
4
  import { getBoxShadow, getFilterStyle, getTransformStyle } from './object'
4
5
  import { isPseudo } from './pseudo'
5
6
  import { getBoxShadowStyle, getTextShadowStyle } from './shadow'
6
7
  import { getStyle } from './style'
7
8
  import { isBoxShadow, isFilter, isShadow, isTextShadow, isTransform } from './utils'
8
9
 
9
- export const convertUnistyles = (value: UnistylesValues) => {
10
+ export const convertUnistyles = (value: UnistylesValues, runtime: UnistylesRuntime) => {
10
11
  // Flag to mark if textShadow is already created
11
12
  let hasTextShadow = false
12
13
  // Flag to mark if boxShadow is already created
13
14
  let hasShadow = false
14
15
 
15
- const stylesArray = Object.entries({
16
- ...value,
17
- ...value._web
18
- }).flatMap(([unistylesKey, unistylesValue]) => {
16
+ const stylesArray = Object.entries(value).flatMap(([unistylesKey, unistylesValue]) => {
19
17
  // Keys to omit
20
18
  if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies'].includes(unistylesKey) || unistylesKey.startsWith('unistyles_')) {
21
19
  return []
@@ -23,7 +21,7 @@ export const convertUnistyles = (value: UnistylesValues) => {
23
21
 
24
22
  // Pseudo classes :hover, :before etc.
25
23
  if (isPseudo(unistylesKey)) {
26
- const flattenValues = convertUnistyles(unistylesValue as UnistylesValues)
24
+ const flattenValues = convertUnistyles(unistylesValue as UnistylesValues, runtime)
27
25
 
28
26
  return { [unistylesKey]: flattenValues }
29
27
  }
@@ -51,7 +49,7 @@ export const convertUnistyles = (value: UnistylesValues) => {
51
49
  }
52
50
 
53
51
  if (isFilter(unistylesKey, unistylesValue)) {
54
- return getFilterStyle(unistylesValue)
52
+ return getFilterStyle(unistylesValue, runtime)
55
53
  }
56
54
 
57
55
  if (isBoxShadow(unistylesKey, unistylesValue)) {
@@ -1,6 +1,6 @@
1
1
  import type { DropShadowValue } from 'react-native'
2
- import { isUnistylesMq } from '../../../mq'
3
- import { UnistylesWeb } from '../../index'
2
+ import { isUnistylesMq } from '../../../utils'
3
+ import type { UnistylesRuntime } from '../../runtime'
4
4
  import { hyphenate } from '../../utils'
5
5
  import type { Filters } from '../types'
6
6
  import { normalizeColor, normalizeNumericValue } from '../utils'
@@ -12,7 +12,7 @@ const getDropShadowStyle = (dropShadow: DropShadowValue) => {
12
12
  return `${normalizeColor(String(color))} ${normalizeNumericValue(offsetX)} ${normalizeNumericValue(offsetY)} ${normalizeNumericValue(standardDeviation)}`
13
13
  }
14
14
 
15
- export const getFilterStyle = (filters: Array<Filters>) => {
15
+ export const getFilterStyle = (filters: Array<Filters>, runtime: UnistylesRuntime) => {
16
16
  const restFilters = filters.filter(filter => Object.keys(filter)[0] !== 'dropShadow')
17
17
  const dropShadow = (() => {
18
18
  const dropShadowValue = filters.find(filter => Object.keys(filter)[0] === 'dropShadow')?.dropShadow as Record<string, any>
@@ -21,7 +21,7 @@ export const getFilterStyle = (filters: Array<Filters>) => {
21
21
  return []
22
22
  }
23
23
 
24
- const breakpoints = Object.keys(dropShadowValue).filter(key => Object.keys(UnistylesWeb.runtime.breakpoints).includes(key) || isUnistylesMq(key))
24
+ const breakpoints = Object.keys(dropShadowValue).filter(key => Object.keys(runtime.breakpoints).includes(key) || isUnistylesMq(key))
25
25
  const breakpointsDropShadow = Object.fromEntries(breakpoints.map(breakpoint => [breakpoint, getDropShadowStyle(dropShadowValue[breakpoint])]))
26
26
 
27
27
  if (breakpoints.length === 0) {
package/src/web/create.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
2
- import { UnistylesWeb } from './index'
3
- import { assignSecrets, error, removeInlineStyles } from './utils'
2
+ import * as unistyles from './services'
3
+ import { assignSecrets, error, isServer, removeInlineStyles } from './utils'
4
4
 
5
5
  type Variants = Record<string, string | boolean | undefined>
6
6
 
@@ -9,7 +9,14 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
9
9
  throw error('Unistyles is not initialized correctly. Please add babel plugin to your babel config.')
10
10
  }
11
11
 
12
- const computedStylesheet = UnistylesWeb.registry.getComputedStylesheet(stylesheet)
12
+ // For SSR
13
+ if (!unistyles.services.state.isInitialized && !isServer()) {
14
+ const config = window?.__UNISTYLES_STATE__?.config
15
+
16
+ config && unistyles.services.state.init(config)
17
+ }
18
+
19
+ const computedStylesheet = unistyles.services.registry.getComputedStylesheet(stylesheet)
13
20
  const addSecrets = (value: any, key: string, args = undefined as Array<any> | undefined, variants = {} as Variants) => assignSecrets(value, {
14
21
  __uni__key: key,
15
22
  __uni__stylesheet: stylesheet,
@@ -8,7 +8,7 @@ export const convertToCSS = (hash: string, value: Record<string, any>, state: CS
8
8
 
9
9
  Object.entries(styleValue).forEach(([pseudoStyleKey, pseudoStyleValue]) => {
10
10
  if (typeof pseudoStyleValue === 'object' && pseudoStyleValue !== null) {
11
- const allBreakpoints = Object.keys(pseudoStyleValue)
11
+ const allBreakpoints = Object.keys(styleValue)
12
12
  Object.entries(pseudoStyleValue).forEach(([breakpointStyleKey, breakpointStyleValue]) => {
13
13
  const mediaQuery = getMediaQuery(pseudoStyleKey, allBreakpoints)
14
14
 
@@ -34,7 +34,7 @@ export const convertToCSS = (hash: string, value: Record<string, any>, state: CS
34
34
  }
35
35
 
36
36
  if (typeof styleValue === 'object') {
37
- const allBreakpoints = Object.keys(styleValue)
37
+ const allBreakpoints = Object.keys(value)
38
38
  Object.entries(styleValue).forEach(([breakpointStyleKey, breakpointStyleValue]) => {
39
39
  const mediaQuery = getMediaQuery(styleKey, allBreakpoints)
40
40
 
@@ -1,5 +1,6 @@
1
1
  import type { UnistylesValues } from '../../types'
2
2
  import { convertUnistyles } from '../convert'
3
+ import type { UnistylesServices } from '../types'
3
4
  import { hyphenate, isServer } from '../utils'
4
5
  import { convertToCSS } from './core'
5
6
 
@@ -33,7 +34,7 @@ export class CSSState {
33
34
  private styleTag: HTMLStyleElement | null = null
34
35
  private CSS = ''
35
36
 
36
- constructor() {
37
+ constructor(private services: UnistylesServices) {
37
38
  if (isServer()) {
38
39
  return
39
40
  }
@@ -60,7 +61,7 @@ export class CSSState {
60
61
  }
61
62
 
62
63
  add = (hash: string, values: UnistylesValues) => {
63
- convertToCSS(hash, convertUnistyles(values), this)
64
+ convertToCSS(hash, convertUnistyles(values, this.services.runtime), this)
64
65
 
65
66
  if (this.styleTag) {
66
67
  this.styleTag.innerText = this.getStyles()
@@ -159,8 +160,9 @@ export class CSSState {
159
160
 
160
161
  const mainState = getState(this.mainMap)
161
162
  const mqState = getState(this.mqMap)
163
+ const config = this.services.state.getConfig()
162
164
 
163
- return { mainState, mqState }
165
+ return { mainState, mqState, config }
164
166
  }
165
167
 
166
168
  hydrate = ({ mainState, mqState }: ReturnType<typeof this.getState>) => {
package/src/web/index.ts CHANGED
@@ -3,22 +3,10 @@ import type { StyleSheet as NativeStyleSheet } from '../specs/StyleSheet'
3
3
  import type { Runtime as NativeUnistylesRuntime } from '../specs/UnistylesRuntime'
4
4
  import { deepMergeObjects } from '../utils'
5
5
  import { create } from './create'
6
- import { UnistylesServices } from './services'
7
- import { isServer } from './utils'
6
+ import * as unistyles from './services'
8
7
 
9
- declare global {
10
- // @ts-ignore
11
- var __unistyles__: UnistylesServices
12
- }
13
-
14
- if (isServer() && !globalThis.__unistyles__) {
15
- // @ts-ignore
16
- globalThis.__unistyles__ = new UnistylesServices()
17
- }
18
-
19
- export const UnistylesWeb = isServer() ? globalThis.__unistyles__ : new UnistylesServices()
20
8
  export const StyleSheet = {
21
- configure: UnistylesWeb.state.init,
9
+ configure: unistyles.services.state.init,
22
10
  create: create,
23
11
  absoluteFill: {
24
12
  position: 'absolute',
@@ -39,8 +27,8 @@ export const StyleSheet = {
39
27
  hairlineWidth: 1
40
28
  } as unknown as typeof NativeStyleSheet
41
29
 
42
- export const UnistylesRuntime = UnistylesWeb.runtime as unknown as typeof NativeUnistylesRuntime
43
- export const UnistylesShadowRegistry = UnistylesWeb.shadowRegistry as unknown as typeof NativeUnistylesShadowRegistry
30
+ export const UnistylesRuntime = unistyles.services.runtime as unknown as typeof NativeUnistylesRuntime
31
+ export const UnistylesShadowRegistry = unistyles.services.shadowRegistry as unknown as typeof NativeUnistylesShadowRegistry
44
32
 
45
33
  export * from './mock'
46
34
 
@@ -11,9 +11,11 @@ export class UnistylesRegistry {
11
11
  private readonly stylesCounter = new Map<string, Set<HTMLElement>>()
12
12
  private readonly disposeListenersMap = new Map<object, VoidFunction>()
13
13
  private readonly dependenciesMap = new Map<StyleSheetWithSuperPowers<StyleSheet>, Set<UnistyleDependency>>()
14
- readonly css = new CSSState()
14
+ readonly css: CSSState
15
15
 
16
- constructor(private services: UnistylesServices) {}
16
+ constructor(private services: UnistylesServices) {
17
+ this.css = new CSSState(services)
18
+ }
17
19
 
18
20
  getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, scopedThemeName?: UnistylesTheme) => {
19
21
  if (typeof stylesheet !== 'function') {
@@ -21,7 +23,7 @@ export class UnistylesRegistry {
21
23
  }
22
24
 
23
25
  if (scopedThemeName) {
24
- const scopedTheme = this.services.runtime.getTheme(scopedThemeName, this.services.state.CSSVars)
26
+ const scopedTheme = this.services.runtime.getTheme(scopedThemeName)
25
27
 
26
28
  if (!scopedTheme) {
27
29
  throw error(`Unistyles: You're trying to use scoped theme '${scopedThemeName}' but it wasn't registered.`)
@@ -54,7 +56,10 @@ export class UnistylesRegistry {
54
56
  dependencies.forEach(dependency => dependenciesMap.add(dependency))
55
57
 
56
58
  const dispose = this.services.listener.addStylesheetListeners(Array.from(dependenciesMap), () => {
57
- const newComputedStylesheet = stylesheet(this.services.runtime.theme, this.services.runtime.miniRuntime)
59
+ const newComputedStylesheet = stylesheet(
60
+ this.services.runtime.getTheme(this.services.runtime.themeName, this.services.state.CSSVars),
61
+ this.services.runtime.miniRuntime
62
+ )
58
63
 
59
64
  this.stylesheets.set(stylesheet, newComputedStylesheet)
60
65
  })
@@ -77,23 +82,27 @@ export class UnistylesRegistry {
77
82
 
78
83
  if (stylesCounter.size === 0) {
79
84
  // Move this to the end of the event loop so the element is removed from the DOM
80
- Promise.resolve().then(() => {
85
+ return Promise.resolve().then(() => {
86
+ // Check if element is still in the DOM
81
87
  if (document.querySelector(`.${hash}`)) {
82
- return
88
+ return false
83
89
  }
84
90
 
85
91
  this.css.remove(hash)
86
92
  this.stylesCache.delete(hash)
87
- })
88
93
 
89
- return true
94
+ return true
95
+ })
90
96
  }
91
97
 
92
- return false
98
+ return Promise.resolve(false)
93
99
  }
94
100
 
95
- add = (value: UnistylesValues) => {
96
- const hash = generateHash(value)
101
+ add = (value: UnistylesValues, forChild?: boolean) => {
102
+ const generatedHash = generateHash(value)
103
+ const hash = forChild
104
+ ? `${generatedHash} > *`
105
+ : generatedHash
97
106
 
98
107
  if (!this.stylesCache.has(hash)) {
99
108
  this.applyStyles(hash, value)
@@ -1,7 +1,7 @@
1
1
  import { UnistyleDependency } from '../specs/NativePlatform'
2
2
  import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
3
3
  import { type AppTheme, type AppThemeName, ColorScheme, Orientation } from '../specs/types'
4
- import { WebContentSizeCategory } from '../types'
4
+ import { type UnistylesTheme, WebContentSizeCategory } from '../types'
5
5
  import { NavigationBar, StatusBar } from './mock'
6
6
  import type { UnistylesServices } from './types'
7
7
  import { error, isServer, schemeToTheme } from './utils'
@@ -213,7 +213,11 @@ export class UnistylesRuntime {
213
213
  : this.services.state.themes.get(themeName ?? '')
214
214
 
215
215
  if (!themeName || !theme) {
216
- throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
216
+ return new Proxy({} as UnistylesTheme, {
217
+ get: () => {
218
+ throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
219
+ }
220
+ })
217
221
  }
218
222
 
219
223
  return theme
@@ -3,8 +3,9 @@ import { UnistylesRegistry } from './registry'
3
3
  import { UnistylesRuntime } from './runtime'
4
4
  import { UnistylesShadowRegistry } from './shadowRegistry'
5
5
  import { UnistylesState } from './state'
6
+ import { isServer } from './utils'
6
7
 
7
- export class UnistylesServices {
8
+ class UnistylesServices {
8
9
  runtime: UnistylesRuntime
9
10
  registry: UnistylesRegistry
10
11
  shadowRegistry: UnistylesShadowRegistry
@@ -26,3 +27,15 @@ export class UnistylesServices {
26
27
  this.services.listener = this.listener
27
28
  }
28
29
  }
30
+
31
+ declare global {
32
+ // @ts-ignore
33
+ var __unistyles__: UnistylesServices
34
+ }
35
+
36
+ if (isServer() && !globalThis.__unistyles__) {
37
+ // @ts-ignore
38
+ globalThis.__unistyles__ = new UnistylesServices()
39
+ }
40
+
41
+ export const services = isServer() ? globalThis.__unistyles__ : new UnistylesServices()
@@ -1,8 +1,8 @@
1
- import { UnistyleDependency } from '../specs'
1
+ import { UnistyleDependency } from '../specs/NativePlatform/NativePlatform.nitro'
2
2
  import type { UnistylesTheme, UnistylesValues } from '../types'
3
3
  import { deepMergeObjects } from '../utils'
4
- import type { UnistylesServices } from './types'
5
- import { extractSecrets, extractUnistyleDependencies } from './utils'
4
+ import type { UniGeneratedStyle, UnistylesServices } from './types'
5
+ import { extractSecrets, extractUnistyleDependencies, isGeneratedUnistyle, isServer } from './utils'
6
6
  import { getVariants } from './variants'
7
7
 
8
8
  export class UnistylesShadowRegistry {
@@ -27,7 +27,14 @@ export class UnistylesShadowRegistry {
27
27
  this.services.registry.connect(ref, hash)
28
28
  }
29
29
 
30
- addStyles = (unistyles: Array<UnistylesValues>) => {
30
+ addStyles = (unistyles: Array<UnistylesValues>, forChild?: boolean) => {
31
+ const [firstStyle] = unistyles
32
+
33
+ // If it is already a generated style, return it
34
+ if (firstStyle && isGeneratedUnistyle(firstStyle)) {
35
+ return firstStyle as UniGeneratedStyle
36
+ }
37
+
31
38
  const getParsedStyles = () => {
32
39
  const allStyles = unistyles.map(unistyle => {
33
40
  const secrets = extractSecrets(unistyle)
@@ -37,6 +44,11 @@ export class UnistylesShadowRegistry {
37
44
  return unistyle
38
45
  }
39
46
 
47
+ // Animated styles - shouldn't be processed
48
+ if (Object.keys(secrets).length === 0) {
49
+ return {}
50
+ }
51
+
40
52
  const { __uni__key, __uni__stylesheet, __uni__args = [], __uni_variants: variants } = secrets
41
53
  const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
42
54
  const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
@@ -52,7 +64,10 @@ export class UnistylesShadowRegistry {
52
64
  this.services.registry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
53
65
  }
54
66
 
55
- return resultWithVariants as UnistylesValues
67
+ return {
68
+ ...resultWithVariants,
69
+ ...resultWithVariants._web
70
+ } as UnistylesValues
56
71
  })
57
72
 
58
73
  return deepMergeObjects(...allStyles)
@@ -61,7 +76,7 @@ export class UnistylesShadowRegistry {
61
76
  // Copy scoped theme to not use referenced value
62
77
  const scopedTheme = this.scopedTheme
63
78
  const parsedStyles = getParsedStyles()
64
- const { hash, existingHash } = this.services.registry.add(parsedStyles)
79
+ const { hash, existingHash } = this.services.registry.add(parsedStyles, forChild)
65
80
  const injectedClassNames = parsedStyles?._web?._classNames ?? []
66
81
  const injectedClassName = Array.isArray(injectedClassNames) ? injectedClassNames.join(' ') : injectedClassNames
67
82
  const dependencies = extractUnistyleDependencies(parsedStyles)
@@ -75,7 +90,11 @@ export class UnistylesShadowRegistry {
75
90
  }))
76
91
  }
77
92
 
78
- return { injectedClassName, hash }
93
+ const hashClassname = forChild
94
+ ? hash.replace(' > *', '')
95
+ : hash
96
+
97
+ return { injectedClassName, hash: hashClassname }
79
98
  }
80
99
 
81
100
  setScopedTheme = (theme?: UnistylesTheme) => {
@@ -85,15 +104,18 @@ export class UnistylesShadowRegistry {
85
104
  getScopedTheme = () => this.scopedTheme
86
105
 
87
106
  remove = (ref: any, hash?: string) => {
88
- if (!(ref instanceof HTMLElement) || !hash) {
107
+ if (isServer() || !(ref instanceof HTMLElement) || !hash) {
89
108
  return
90
109
  }
91
110
 
92
- const removed = this.services.registry.remove(ref, hash)
111
+ this.services.registry.remove(ref, hash)
112
+ .then(removed => {
113
+ if (!removed) {
114
+ return
115
+ }
93
116
 
94
- if (removed) {
95
- this.disposeMap.get(hash)?.()
96
- this.disposeMap.delete(hash)
97
- }
117
+ this.disposeMap.get(hash)?.()
118
+ this.disposeMap.delete(hash)
119
+ })
98
120
  }
99
121
  }
package/src/web/state.ts CHANGED
@@ -17,6 +17,7 @@ export class UnistylesState {
17
17
  CSSVars = true
18
18
 
19
19
  private matchingBreakpoints = new Map<string, boolean>()
20
+ private _config: UnistylesConfig = {}
20
21
 
21
22
  get breakpoint() {
22
23
  const [currentBreakpoint] = Array.from(this.matchingBreakpoints)
@@ -37,6 +38,7 @@ export class UnistylesState {
37
38
  return
38
39
  }
39
40
 
41
+ this._config = config
40
42
  this.isInitialized = true
41
43
  this.initThemes(config.themes, config.settings?.CSSVars)
42
44
  this.initBreakpoints(config.breakpoints)
@@ -58,7 +60,11 @@ export class UnistylesState {
58
60
  this.services.listener.initListeners()
59
61
  }
60
62
 
61
- private initThemes = (themes = {} as UnistylesThemes, CSSVars = true) => {
63
+ private initThemes = (themes?: UnistylesThemes, CSSVars = true) => {
64
+ if (!themes) {
65
+ return
66
+ }
67
+
62
68
  this.CSSVars = CSSVars
63
69
 
64
70
  Object.entries(themes).forEach(([themeName, theme]) => {
@@ -117,7 +123,11 @@ export class UnistylesState {
117
123
  }
118
124
  }
119
125
 
120
- private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
126
+ private initBreakpoints = (breakpoints?: UnistylesBreakpoints) => {
127
+ if (!breakpoints) {
128
+ return
129
+ }
130
+
121
131
  this.breakpoints = breakpoints
122
132
  const breakpointsEntries = Object.entries(breakpoints)
123
133
 
@@ -145,4 +155,6 @@ export class UnistylesState {
145
155
  })
146
156
  })
147
157
  }
158
+
159
+ getConfig = () => this._config
148
160
  }
package/src/web/types.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  import type { UnistylesListener } from './listener'
2
- import type{ UnistylesRegistry } from './registry'
3
- import type{ UnistylesRuntime } from './runtime'
4
- import type{ UnistylesShadowRegistry } from './shadowRegistry'
5
- import type{ UnistylesState } from './state'
2
+ import type { UnistylesRegistry } from './registry'
3
+ import type { UnistylesRuntime } from './runtime'
4
+ import type { UnistylesShadowRegistry } from './shadowRegistry'
5
+ import type { UnistylesState } from './state'
6
6
 
7
7
  export type UnistylesServices = {
8
8
  runtime: UnistylesRuntime,
@@ -11,3 +11,8 @@ export type UnistylesServices = {
11
11
  state: UnistylesState,
12
12
  listener: UnistylesListener
13
13
  }
14
+
15
+ export const UNI_GENERATED_KEYS = ['$$css', 'hash', 'injectedClassName'] as const
16
+ export type UniGeneratedKey = typeof UNI_GENERATED_KEYS[number]
17
+
18
+ export type UniGeneratedStyle = Record<UniGeneratedKey, string>
@@ -0,0 +1,33 @@
1
+ import type React from 'react'
2
+ import type { Nullable, UnistylesValues } from '../../types'
3
+ import * as unistyles from '../services'
4
+ import { isServer } from './common'
5
+
6
+ type Styles = readonly [
7
+ {
8
+ hash: string
9
+ },
10
+ Array<UnistylesValues>
11
+ ]
12
+
13
+ export const createUnistylesRef = <T>(styles?: Styles, forwardedRef?: React.ForwardedRef<T>) => {
14
+ const storedRef = { current: null as Nullable<T> }
15
+ const [classNames] = styles ?? []
16
+
17
+ return isServer() ? undefined : (ref: Nullable<T>) => {
18
+ if (!ref) {
19
+ unistyles.services.shadowRegistry.remove(storedRef, classNames?.hash)
20
+ }
21
+
22
+ storedRef.current = ref
23
+ unistyles.services.shadowRegistry.add(ref, classNames?.hash)
24
+
25
+ if (typeof forwardedRef === 'function') {
26
+ return forwardedRef(ref)
27
+ }
28
+
29
+ if (forwardedRef) {
30
+ forwardedRef.current = ref
31
+ }
32
+ }
33
+ }