react-native-unistyles 3.0.0-beta.7 → 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 (390) hide show
  1. package/README.md +41 -19
  2. package/Unistyles.podspec +1 -0
  3. package/android/CMakeLists.txt +2 -1
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +3 -7
  5. package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
  6. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +5 -1
  7. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +11 -4
  8. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +1 -1
  9. package/android/src/main/java/com/unistyles/UnistylesModule.kt +1 -7
  10. package/components/native/ActivityIndicator/package.json +1 -0
  11. package/components/native/Animated/package.json +1 -0
  12. package/components/native/FlatList/package.json +1 -0
  13. package/components/native/Image/package.json +2 -1
  14. package/components/native/ImageBackground/package.json +1 -0
  15. package/components/native/KeyboardAvoidingView/package.json +1 -0
  16. package/components/native/NativeText/package.json +1 -0
  17. package/components/native/NativeView/package.json +1 -0
  18. package/components/native/Pressable/package.json +1 -0
  19. package/components/native/RefreshControl/package.json +1 -0
  20. package/components/native/ScrollView/package.json +1 -0
  21. package/components/native/SectionList/package.json +1 -0
  22. package/components/native/Switch/package.json +1 -0
  23. package/components/native/Text/package.json +1 -0
  24. package/components/native/TextInput/package.json +1 -0
  25. package/components/native/TouchableHighlight/package.json +1 -0
  26. package/components/native/TouchableOpacity/package.json +1 -0
  27. package/components/native/View/package.json +1 -0
  28. package/components/native/VirtualizedList/package.json +1 -0
  29. package/cxx/common/Helpers.h +89 -0
  30. package/cxx/core/HostUnistyle.cpp +14 -5
  31. package/cxx/core/StyleSheet.h +1 -1
  32. package/cxx/core/UnistyleWrapper.h +1 -1
  33. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  34. package/cxx/core/UnistylesRegistry.cpp +74 -69
  35. package/cxx/core/UnistylesRegistry.h +1 -1
  36. package/cxx/hybridObjects/HybridShadowRegistry.cpp +2 -5
  37. package/cxx/hybridObjects/HybridStyleSheet.cpp +10 -19
  38. package/cxx/hybridObjects/HybridStyleSheet.h +3 -8
  39. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +5 -1
  40. package/cxx/parser/Parser.cpp +200 -89
  41. package/cxx/parser/Parser.h +1 -1
  42. package/cxx/shadowTree/ShadowTrafficController.h +13 -9
  43. package/cxx/shadowTree/ShadowTreeManager.cpp +64 -59
  44. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  45. package/ios/NativePlatform+ios.swift +1 -1
  46. package/ios/NativePlatformListener+ios.swift +12 -7
  47. package/ios/UnistylesModuleOnLoad.h +1 -5
  48. package/ios/UnistylesModuleOnLoad.mm +5 -13
  49. package/lib/commonjs/components/native/Image.js +27 -1
  50. package/lib/commonjs/components/native/Image.js.map +1 -1
  51. package/lib/commonjs/components/native/Image.native.js +10 -0
  52. package/lib/commonjs/components/native/Image.native.js.map +1 -0
  53. package/lib/commonjs/components/native/ImageBackground.js +21 -36
  54. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  55. package/lib/commonjs/components/native/Pressable.native.js +16 -2
  56. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  57. package/lib/commonjs/core/createUnistylesElement.js +17 -21
  58. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  59. package/lib/commonjs/core/createUnistylesElement.native.js +7 -1
  60. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  61. package/lib/commonjs/core/createUnistylesImageBackground.js +10 -4
  62. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  63. package/lib/commonjs/core/getClassname.js +11 -5
  64. package/lib/commonjs/core/getClassname.js.map +1 -1
  65. package/lib/commonjs/core/passForwardRef.js +3 -5
  66. package/lib/commonjs/core/passForwardRef.js.map +1 -1
  67. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +5 -3
  68. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  69. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +15 -2
  70. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  71. package/lib/commonjs/core/withUnistyles/withUnistyles.js +14 -5
  72. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  73. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +14 -7
  74. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  75. package/lib/commonjs/hooks/useMedia.js +4 -4
  76. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  77. package/lib/commonjs/hooks/useMedia.native.js +4 -4
  78. package/lib/commonjs/hooks/useMedia.native.js.map +1 -1
  79. package/lib/commonjs/mocks.js +203 -0
  80. package/lib/commonjs/mocks.js.map +1 -0
  81. package/lib/commonjs/mq.js +1 -23
  82. package/lib/commonjs/mq.js.map +1 -1
  83. package/lib/commonjs/reanimated/index.js +13 -0
  84. package/lib/commonjs/reanimated/index.js.map +1 -0
  85. package/lib/commonjs/reanimated/useAnimatedTheme.js +22 -0
  86. package/lib/commonjs/reanimated/useAnimatedTheme.js.map +1 -0
  87. package/lib/commonjs/reanimated/useAnimatedTheme.native.js +24 -0
  88. package/lib/commonjs/reanimated/useAnimatedTheme.native.js.map +1 -0
  89. package/lib/commonjs/server/getServerUnistyles.js +9 -4
  90. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  91. package/lib/commonjs/server/hydrateServerUnistyles.js +4 -2
  92. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  93. package/lib/commonjs/server/resetServerUnistyles.js +4 -2
  94. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  95. package/lib/commonjs/server/serialize.js +24 -0
  96. package/lib/commonjs/server/serialize.js.map +1 -0
  97. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  98. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  99. package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
  100. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  101. package/lib/commonjs/utils.js +23 -1
  102. package/lib/commonjs/utils.js.map +1 -1
  103. package/lib/commonjs/web/convert/index.js +4 -7
  104. package/lib/commonjs/web/convert/index.js.map +1 -1
  105. package/lib/commonjs/web/convert/object/filter.js +7 -8
  106. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  107. package/lib/commonjs/web/create.js +10 -2
  108. package/lib/commonjs/web/create.js.map +1 -1
  109. package/lib/commonjs/web/css/core.js +2 -2
  110. package/lib/commonjs/web/css/core.js.map +1 -1
  111. package/lib/commonjs/web/css/state.js +6 -3
  112. package/lib/commonjs/web/css/state.js.map +1 -1
  113. package/lib/commonjs/web/index.js +7 -12
  114. package/lib/commonjs/web/index.js.map +1 -1
  115. package/lib/commonjs/web/registry.js +11 -9
  116. package/lib/commonjs/web/registry.js.map +1 -1
  117. package/lib/commonjs/web/runtime.js +5 -1
  118. package/lib/commonjs/web/runtime.js.map +1 -1
  119. package/lib/commonjs/web/services.js +7 -2
  120. package/lib/commonjs/web/services.js.map +1 -1
  121. package/lib/commonjs/web/shadowRegistry.js +27 -10
  122. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  123. package/lib/commonjs/web/state.js +11 -2
  124. package/lib/commonjs/web/state.js.map +1 -1
  125. package/lib/commonjs/web/types.js +2 -0
  126. package/lib/commonjs/web/types.js.map +1 -1
  127. package/lib/commonjs/web/utils/createUnistylesRef.js +31 -0
  128. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -0
  129. package/lib/commonjs/web/utils/unistyle.js +40 -14
  130. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  131. package/lib/commonjs/web-only/getWebProps.js +19 -0
  132. package/lib/commonjs/web-only/getWebProps.js.map +1 -0
  133. package/lib/commonjs/web-only/index.js +13 -0
  134. package/lib/commonjs/web-only/index.js.map +1 -0
  135. package/lib/module/components/native/Image.js +26 -2
  136. package/lib/module/components/native/Image.js.map +1 -1
  137. package/lib/module/components/native/Image.native.js +6 -0
  138. package/lib/module/components/native/Image.native.js.map +1 -0
  139. package/lib/module/components/native/ImageBackground.js +22 -37
  140. package/lib/module/components/native/ImageBackground.js.map +1 -1
  141. package/lib/module/components/native/Pressable.native.js +16 -2
  142. package/lib/module/components/native/Pressable.native.js.map +1 -1
  143. package/lib/module/core/createUnistylesElement.js +17 -21
  144. package/lib/module/core/createUnistylesElement.js.map +1 -1
  145. package/lib/module/core/createUnistylesElement.native.js +7 -1
  146. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  147. package/lib/module/core/createUnistylesImageBackground.js +10 -4
  148. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  149. package/lib/module/core/getClassname.js +9 -5
  150. package/lib/module/core/getClassname.js.map +1 -1
  151. package/lib/module/core/passForwardRef.js +3 -5
  152. package/lib/module/core/passForwardRef.js.map +1 -1
  153. package/lib/module/core/useProxifiedUnistyles/listener.js +3 -3
  154. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  155. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +15 -2
  156. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  157. package/lib/module/core/withUnistyles/withUnistyles.js +14 -5
  158. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  159. package/lib/module/core/withUnistyles/withUnistyles.native.js +14 -7
  160. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  161. package/lib/module/hooks/useMedia.js +1 -1
  162. package/lib/module/hooks/useMedia.js.map +1 -1
  163. package/lib/module/hooks/useMedia.native.js +1 -1
  164. package/lib/module/hooks/useMedia.native.js.map +1 -1
  165. package/lib/module/mocks.js +201 -0
  166. package/lib/module/mocks.js.map +1 -0
  167. package/lib/module/mq.js +0 -19
  168. package/lib/module/mq.js.map +1 -1
  169. package/lib/module/reanimated/index.js +4 -0
  170. package/lib/module/reanimated/index.js.map +1 -0
  171. package/lib/module/reanimated/useAnimatedTheme.js +17 -0
  172. package/lib/module/reanimated/useAnimatedTheme.js.map +1 -0
  173. package/lib/module/reanimated/useAnimatedTheme.native.js +19 -0
  174. package/lib/module/reanimated/useAnimatedTheme.native.js.map +1 -0
  175. package/lib/module/server/getServerUnistyles.js +7 -4
  176. package/lib/module/server/getServerUnistyles.js.map +1 -1
  177. package/lib/module/server/hydrateServerUnistyles.js +2 -2
  178. package/lib/module/server/hydrateServerUnistyles.js.map +1 -1
  179. package/lib/module/server/resetServerUnistyles.js +2 -2
  180. package/lib/module/server/resetServerUnistyles.js.map +1 -1
  181. package/lib/module/server/serialize.js +19 -0
  182. package/lib/module/server/serialize.js.map +1 -0
  183. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  184. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  185. package/lib/module/specs/ShadowRegistry/index.js +2 -2
  186. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  187. package/lib/module/utils.js +19 -0
  188. package/lib/module/utils.js.map +1 -1
  189. package/lib/module/web/convert/index.js +4 -7
  190. package/lib/module/web/convert/index.js.map +1 -1
  191. package/lib/module/web/convert/object/filter.js +3 -4
  192. package/lib/module/web/convert/object/filter.js.map +1 -1
  193. package/lib/module/web/create.js +9 -3
  194. package/lib/module/web/create.js.map +1 -1
  195. package/lib/module/web/css/core.js +2 -2
  196. package/lib/module/web/css/core.js.map +1 -1
  197. package/lib/module/web/css/state.js +6 -3
  198. package/lib/module/web/css/state.js.map +1 -1
  199. package/lib/module/web/index.js +4 -10
  200. package/lib/module/web/index.js.map +1 -1
  201. package/lib/module/web/registry.js +11 -9
  202. package/lib/module/web/registry.js.map +1 -1
  203. package/lib/module/web/runtime.js +5 -1
  204. package/lib/module/web/runtime.js.map +1 -1
  205. package/lib/module/web/services.js +7 -1
  206. package/lib/module/web/services.js.map +1 -1
  207. package/lib/module/web/shadowRegistry.js +27 -10
  208. package/lib/module/web/shadowRegistry.js.map +1 -1
  209. package/lib/module/web/state.js +11 -2
  210. package/lib/module/web/state.js.map +1 -1
  211. package/lib/module/web/types.js +1 -1
  212. package/lib/module/web/types.js.map +1 -1
  213. package/lib/module/web/utils/createUnistylesRef.js +24 -0
  214. package/lib/module/web/utils/createUnistylesRef.js.map +1 -0
  215. package/lib/module/web/utils/unistyle.js +32 -10
  216. package/lib/module/web/utils/unistyle.js.map +1 -1
  217. package/lib/module/web-only/getWebProps.js +14 -0
  218. package/lib/module/web-only/getWebProps.js.map +1 -0
  219. package/lib/module/web-only/index.js +4 -0
  220. package/lib/module/web-only/index.js.map +1 -0
  221. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  222. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  223. package/lib/typescript/src/components/native/Image.native.d.ts +2 -0
  224. package/lib/typescript/src/components/native/Image.native.d.ts.map +1 -0
  225. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  226. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  227. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  228. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  229. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  230. package/lib/typescript/src/core/getClassname.d.ts +5 -5
  231. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  232. package/lib/typescript/src/core/passForwardRef.d.ts +1 -1
  233. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  234. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  235. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  236. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  237. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  238. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +1 -1
  239. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  240. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +1 -3
  241. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  242. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  243. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  244. package/lib/typescript/src/mocks.d.ts +2 -0
  245. package/lib/typescript/src/mocks.d.ts.map +1 -0
  246. package/lib/typescript/src/mq.d.ts +0 -8
  247. package/lib/typescript/src/mq.d.ts.map +1 -1
  248. package/lib/typescript/src/reanimated/index.d.ts +2 -0
  249. package/lib/typescript/src/reanimated/index.d.ts.map +1 -0
  250. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts +4 -0
  251. package/lib/typescript/src/reanimated/useAnimatedTheme.d.ts.map +1 -0
  252. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts +4 -0
  253. package/lib/typescript/src/reanimated/useAnimatedTheme.native.d.ts.map +1 -0
  254. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  255. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +0 -1
  256. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -1
  257. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -1
  258. package/lib/typescript/src/server/serialize.d.ts +2 -0
  259. package/lib/typescript/src/server/serialize.d.ts.map +1 -0
  260. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  261. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +2 -1
  262. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  263. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  264. package/lib/typescript/src/types/common.d.ts +0 -1
  265. package/lib/typescript/src/types/common.d.ts.map +1 -1
  266. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  267. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  268. package/lib/typescript/src/utils.d.ts +8 -0
  269. package/lib/typescript/src/utils.d.ts.map +1 -1
  270. package/lib/typescript/src/web/convert/index.d.ts +2 -1
  271. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  272. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  273. package/lib/typescript/src/web/convert/object/filter.d.ts +2 -1
  274. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  275. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  276. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  277. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  278. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  279. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  280. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  281. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  282. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  283. package/lib/typescript/src/web/create.d.ts.map +1 -1
  284. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  285. package/lib/typescript/src/web/css/state.d.ts +4 -1
  286. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  287. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  288. package/lib/typescript/src/web/index.d.ts +0 -5
  289. package/lib/typescript/src/web/index.d.ts.map +1 -1
  290. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  291. package/lib/typescript/src/web/registry.d.ts +2 -2
  292. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  293. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  294. package/lib/typescript/src/web/services.d.ts +6 -1
  295. package/lib/typescript/src/web/services.d.ts.map +1 -1
  296. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -2
  297. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  298. package/lib/typescript/src/web/state.d.ts +2 -0
  299. package/lib/typescript/src/web/state.d.ts.map +1 -1
  300. package/lib/typescript/src/web/types.d.ts +3 -0
  301. package/lib/typescript/src/web/types.d.ts.map +1 -1
  302. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  303. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts +11 -0
  304. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -0
  305. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -2
  306. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  307. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  308. package/lib/typescript/src/web-only/getWebProps.d.ts +7 -0
  309. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -0
  310. package/lib/typescript/src/web-only/index.d.ts +2 -0
  311. package/lib/typescript/src/web-only/index.d.ts.map +1 -0
  312. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +2 -2
  313. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +2 -2
  314. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +19 -19
  315. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +3 -0
  316. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +7 -2
  317. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +7 -2
  318. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +22 -22
  319. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  320. package/nitrogen/generated/android/unistyles+autolinking.cmake +16 -0
  321. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -1
  322. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  323. package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -0
  324. package/nitrogen/generated/shared/c++/Insets.hpp +1 -0
  325. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  326. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -0
  327. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -0
  328. package/package.json +77 -33
  329. package/plugin/index.d.ts +51 -18
  330. package/plugin/index.js +878 -177
  331. package/reanimated/package.json +6 -0
  332. package/server/package.json +6 -0
  333. package/src/components/native/Image.native.tsx +4 -0
  334. package/src/components/native/Image.tsx +36 -3
  335. package/src/components/native/ImageBackground.tsx +20 -36
  336. package/src/components/native/Pressable.native.tsx +25 -2
  337. package/src/core/createUnistylesElement.native.tsx +13 -2
  338. package/src/core/createUnistylesElement.tsx +26 -27
  339. package/src/core/createUnistylesImageBackground.tsx +16 -5
  340. package/src/core/getClassname.ts +16 -5
  341. package/src/core/passForwardRef.ts +5 -5
  342. package/src/core/useProxifiedUnistyles/listener.ts +3 -3
  343. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +18 -1
  344. package/src/core/withUnistyles/withUnistyles.native.tsx +42 -17
  345. package/src/core/withUnistyles/withUnistyles.tsx +23 -6
  346. package/src/hooks/useMedia.native.ts +1 -1
  347. package/src/hooks/useMedia.ts +1 -1
  348. package/src/mocks.ts +217 -0
  349. package/src/mq.ts +0 -24
  350. package/src/reanimated/index.ts +1 -0
  351. package/src/reanimated/useAnimatedTheme.native.ts +21 -0
  352. package/src/reanimated/useAnimatedTheme.ts +19 -0
  353. package/src/server/getServerUnistyles.tsx +15 -10
  354. package/src/server/hydrateServerUnistyles.ts +3 -2
  355. package/src/server/resetServerUnistyles.ts +4 -3
  356. package/src/server/serialize.ts +20 -0
  357. package/src/specs/NativePlatform/NativePlatform.nitro.ts +2 -1
  358. package/src/specs/ShadowRegistry/index.ts +2 -2
  359. package/src/types/common.ts +0 -1
  360. package/src/types/stylesheet.ts +1 -1
  361. package/src/utils.ts +25 -0
  362. package/src/web/convert/index.ts +5 -7
  363. package/src/web/convert/object/filter.ts +4 -4
  364. package/src/web/create.ts +10 -3
  365. package/src/web/css/core.ts +2 -2
  366. package/src/web/css/state.ts +5 -3
  367. package/src/web/index.ts +4 -16
  368. package/src/web/registry.ts +20 -11
  369. package/src/web/runtime.ts +6 -2
  370. package/src/web/services.ts +14 -1
  371. package/src/web/shadowRegistry.ts +35 -13
  372. package/src/web/state.ts +14 -2
  373. package/src/web/types.ts +9 -4
  374. package/src/web/utils/createUnistylesRef.ts +33 -0
  375. package/src/web/utils/unistyle.ts +55 -23
  376. package/src/web-only/getWebProps.ts +18 -0
  377. package/src/web-only/index.ts +2 -0
  378. package/web/package.json +6 -0
  379. package/cxx/core/UnistylesCommitHook.cpp +0 -49
  380. package/cxx/core/UnistylesCommitHook.h +0 -27
  381. package/cxx/core/UnistylesMountHook.cpp +0 -28
  382. package/cxx/core/UnistylesMountHook.h +0 -27
  383. package/lib/module/package.json +0 -1
  384. package/plugin/consts.js +0 -63
  385. package/plugin/exotic.js +0 -54
  386. package/plugin/import.js +0 -51
  387. package/plugin/ref.js +0 -11
  388. package/plugin/stylesheet.js +0 -565
  389. package/plugin/variants.js +0 -66
  390. /package/cxx/common/{Constants.h → UnistylesConstants.h} +0 -0
package/plugin/index.js CHANGED
@@ -1,192 +1,893 @@
1
- const { addUnistylesImport, isInsideNodeModules } = require('./import')
2
- const { hasStringRef } = require('./ref')
3
- const { isUnistylesStyleSheet, addStyleSheetTag, isKindOfStyleSheet, getStylesDependenciesFromFunction, addDependencies, getStylesDependenciesFromObject } = require('./stylesheet')
4
- const { extractVariants } = require('./variants')
5
- const { REACT_NATIVE_COMPONENT_NAMES, REPLACE_WITH_UNISTYLES_PATHS, REPLACE_WITH_UNISTYLES_EXOTIC_PATHS, NATIVE_COMPONENTS_PATHS } = require('./consts')
6
- const { handleExoticImport } = require('./exotic')
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
7
29
 
8
- module.exports = function ({ types: t }) {
9
- return {
10
- name: 'babel-react-native-unistyles',
11
- visitor: {
12
- Program: {
13
- /** @param {import('./index').UnistylesPluginPass} state */
14
- enter(path, state) {
15
- state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS
16
- .concat(state.opts.autoProcessPaths ?? [])
17
- .some(path => state.filename.includes(path))
18
-
19
- state.file.hasAnyUnistyle = false
20
- state.file.hasUnistylesImport = false
21
- state.file.hasVariants = false
22
- state.file.styleSheetLocalName = ''
23
- state.file.tagNumber = 0
24
- state.reactNativeImports = {}
25
- state.file.forceProcessing = state.opts.autoProcessRoot
26
- ? state.filename.includes(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)
27
- : false
28
- },
29
- exit(path, state) {
30
- if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
31
- return
32
- }
33
-
34
- if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
35
- addUnistylesImport(t, path, state)
36
- }
37
- }
38
- },
39
- FunctionDeclaration(path, state) {
40
- if (isInsideNodeModules(state)) {
41
- return
42
- }
43
-
44
- const componentName = path.node.id
45
- ? path.node.id.name
46
- : null
47
-
48
- if (componentName) {
49
- state.file.hasVariants = false
50
- }
51
- },
52
- ClassDeclaration(path, state) {
53
- if (isInsideNodeModules(state)) {
54
- return
55
- }
56
-
57
- const componentName = path.node.id
58
- ? path.node.id.name
59
- : null
60
-
61
- if (componentName) {
62
- state.file.hasVariants = false
63
- }
64
- },
65
- VariableDeclaration(path, state) {
66
- if (isInsideNodeModules(state)) {
67
- return
68
- }
69
-
70
- path.node.declarations.forEach((declaration) => {
71
- if (t.isArrowFunctionExpression(declaration.init) || t.isFunctionExpression(declaration.init)) {
72
- const componentName = declaration.id
73
- ? declaration.id.name
74
- : null
75
-
76
- if (componentName) {
77
- state.file.hasVariants = false
78
- }
79
- }
80
- })
81
- },
82
- /** @param {import('./index').UnistylesPluginPass} state */
83
- ImportDeclaration(path, state) {
84
- const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS
85
- .concat(state.opts.autoRemapImports ?? [])
86
- .find(exotic => state.filename.includes(exotic.path))
87
-
88
- if (exoticImport) {
89
- return handleExoticImport(t, path, state, exoticImport)
90
- }
91
-
92
- if (isInsideNodeModules(state) && !state.file.replaceWithUnistyles) {
93
- return
94
- }
30
+ // plugin/src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ default: () => index_default
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var t6 = __toESM(require("@babel/types"));
95
37
 
96
- const importSource = path.node.source.value
97
-
98
- if (importSource.includes('react-native-unistyles')) {
99
- state.file.hasUnistylesImport = true
100
-
101
- path.node.specifiers.forEach(specifier => {
102
- if (specifier.imported && specifier.imported.name === 'StyleSheet') {
103
- state.file.styleSheetLocalName = specifier.local.name
104
- }
105
- })
106
- }
107
-
108
- if (importSource === 'react-native') {
109
- path.node.specifiers.forEach(specifier => {
110
- if (specifier.imported && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
111
- state.reactNativeImports[specifier.local.name] = specifier.imported.name
112
- }
113
- })
114
- }
115
-
116
- if (importSource.includes('react-native/Libraries')) {
117
- handleExoticImport(t, path, state, NATIVE_COMPONENTS_PATHS)
118
- }
119
-
120
- if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
121
- state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource)
122
- }
123
- },
124
- JSXElement(path, state) {
125
- if (isInsideNodeModules(state)) {
126
- return
127
- }
128
-
129
- if (hasStringRef(t, path)) {
130
- throw new Error("Detected string based ref which is not supported by Unistyles.")
131
- }
132
- },
133
- BlockStatement(path, state) {
134
- if (isInsideNodeModules(state)) {
135
- return
136
- }
38
+ // plugin/src/consts.ts
39
+ var REACT_NATIVE_COMPONENT_NAMES = [
40
+ "ActivityIndicator",
41
+ "View",
42
+ "Text",
43
+ "Image",
44
+ "ImageBackground",
45
+ "KeyboardAvoidingView",
46
+ "Pressable",
47
+ "ScrollView",
48
+ "FlatList",
49
+ "SectionList",
50
+ "Switch",
51
+ "TextInput",
52
+ "RefreshControl",
53
+ "TouchableHighlight",
54
+ "TouchableOpacity",
55
+ "VirtualizedList",
56
+ "Animated"
57
+ // Modal - there is no exposed native handle
58
+ // TouchableWithoutFeedback - can't accept a ref
59
+ ];
60
+ var REPLACE_WITH_UNISTYLES_PATHS = [
61
+ "react-native-reanimated/src/component",
62
+ "react-native-reanimated/lib/module/component",
63
+ "react-native-gesture-handler/lib/module/components",
64
+ "react-native-gesture-handler/lib/commonjs/components",
65
+ "react-native-gesture-handler/src/components"
66
+ ];
67
+ var REPLACE_WITH_UNISTYLES_EXOTIC_PATHS = [];
68
+ var NATIVE_COMPONENTS_PATHS = {
69
+ imports: [
70
+ {
71
+ name: "NativeText",
72
+ isDefault: false,
73
+ path: "react-native/Libraries/Text/TextNativeComponent",
74
+ mapTo: "NativeText"
75
+ },
76
+ {
77
+ isDefault: true,
78
+ path: "react-native/Libraries/Components/View/ViewNativeComponent",
79
+ mapTo: "NativeView"
80
+ }
81
+ ]
82
+ };
137
83
 
138
- extractVariants(t, path, state)
139
- },
140
- CallExpression(path, state) {
141
- if (isInsideNodeModules(state)) {
142
- return
143
- }
84
+ // plugin/src/exotic.ts
85
+ var t = __toESM(require("@babel/types"));
86
+ function handleExoticImport(path2, state, exoticImport) {
87
+ const specifiers = path2.node.specifiers;
88
+ const source = path2.node.source;
89
+ if (path2.node.importKind !== "value") {
90
+ return;
91
+ }
92
+ specifiers.forEach((specifier) => {
93
+ for (const rule of exoticImport.imports) {
94
+ const hasMatchingImportType = !rule.isDefault && t.isImportSpecifier(specifier) || rule.isDefault && t.isImportDefaultSpecifier(specifier);
95
+ const hasMatchingImportName = rule.isDefault || !rule.isDefault && rule.name === specifier.local.name;
96
+ const hasMatchingPath = rule.path === source.value;
97
+ if (!hasMatchingImportType || !hasMatchingImportName || !hasMatchingPath) {
98
+ continue;
99
+ }
100
+ if (t.isImportDefaultSpecifier(specifier)) {
101
+ const newImport = t.importDeclaration(
102
+ [t.importDefaultSpecifier(t.identifier(specifier.local.name))],
103
+ t.stringLiteral(
104
+ state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
105
+ )
106
+ );
107
+ path2.replaceWith(newImport);
108
+ } else {
109
+ const newImport = t.importDeclaration(
110
+ [t.importSpecifier(t.identifier(rule.mapTo), t.identifier(rule.mapTo))],
111
+ t.stringLiteral(
112
+ state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/components/native/${rule.mapTo}`) ?? "" : `react-native-unistyles/components/native/${rule.mapTo}`
113
+ )
114
+ );
115
+ path2.node.specifiers = specifiers.filter((s) => s !== specifier);
116
+ if (path2.node.specifiers.length === 0) {
117
+ path2.replaceWith(newImport);
118
+ } else {
119
+ path2.insertBefore(newImport);
120
+ }
121
+ }
122
+ return;
123
+ }
124
+ });
125
+ }
144
126
 
145
- if (!isUnistylesStyleSheet(t, path, state) && !isKindOfStyleSheet(t, path, state)) {
146
- return
147
- }
127
+ // plugin/src/import.ts
128
+ var t2 = __toESM(require("@babel/types"));
129
+ function addUnistylesImport(path2, state) {
130
+ const localNames = Object.keys(state.reactNativeImports);
131
+ const names = Object.values(state.reactNativeImports);
132
+ const pairs = Object.entries(state.reactNativeImports);
133
+ const nodesToRemove = [];
134
+ path2.node.body.forEach((node) => {
135
+ if (t2.isImportDeclaration(node) && node.source.value === "react-native") {
136
+ node.specifiers = node.specifiers.filter((specifier) => !localNames.some((name) => name === specifier.local.name));
137
+ if (node.specifiers.length === 0) {
138
+ nodesToRemove.push(node);
139
+ }
140
+ }
141
+ });
142
+ names.forEach((name) => {
143
+ const rnWebImport = path2.node.body.find((node) => t2.isImportDeclaration(node) && node.source.value === `react-native-web/dist/exports/${name}`);
144
+ if (rnWebImport) {
145
+ rnWebImport.specifiers = [];
146
+ }
147
+ });
148
+ pairs.forEach(([localName, name]) => {
149
+ const newImport = t2.importDeclaration(
150
+ [t2.importSpecifier(t2.identifier(localName), t2.identifier(name))],
151
+ t2.stringLiteral(
152
+ state.opts.isLocal ? state.file.opts.filename?.split("react-native-unistyles").at(0)?.concat(`react-native-unistyles/src/components/native/${name}`) ?? "" : `react-native-unistyles/components/native/${name}`
153
+ )
154
+ );
155
+ path2.node.body.unshift(newImport);
156
+ });
157
+ nodesToRemove.forEach((node) => path2.node.body.splice(path2.node.body.indexOf(node), 1));
158
+ }
159
+ function isInsideNodeModules(state) {
160
+ return state.file.opts.filename?.includes("node_modules") && !state.file.replaceWithUnistyles;
161
+ }
162
+ function addUnistylesRequire(path2, state) {
163
+ Object.entries(state.reactNativeImports).forEach(([componentName, uniqueName]) => {
164
+ const newRequire = t2.variableDeclaration("const", [
165
+ t2.variableDeclarator(
166
+ t2.identifier(uniqueName),
167
+ t2.callExpression(t2.identifier("require"), [
168
+ t2.stringLiteral(`react-native-unistyles/src/components/native/${componentName}`)
169
+ ])
170
+ )
171
+ ]);
172
+ path2.node.body.unshift(newRequire);
173
+ });
174
+ }
148
175
 
149
- state.file.hasAnyUnistyle = true
176
+ // plugin/src/paths.ts
177
+ var import_node_path = __toESM(require("node:path"));
178
+ var isWindows = process.platform === "win32";
179
+ var toWinPath = (pathString) => {
180
+ return import_node_path.default.normalize(pathString).replace(/\//g, "\\");
181
+ };
182
+ var toPlatformPath = (pathString) => {
183
+ return isWindows ? toWinPath(pathString) : pathString;
184
+ };
150
185
 
151
- addStyleSheetTag(t, path, state)
186
+ // plugin/src/ref.ts
187
+ var t3 = __toESM(require("@babel/types"));
188
+ function hasStringRef(path2) {
189
+ return path2.node.openingElement.attributes.find(
190
+ (attr) => t3.isJSXAttribute(attr) && t3.isJSXIdentifier(attr.name, { name: "ref" }) && t3.isStringLiteral(attr.value)
191
+ );
192
+ }
152
193
 
153
- const arg = path.node.arguments[0]
194
+ // plugin/src/stylesheet.ts
195
+ var t4 = __toESM(require("@babel/types"));
196
+ var UnistyleDependency = {
197
+ Theme: 0,
198
+ ThemeName: 1,
199
+ AdaptiveThemes: 2,
200
+ Breakpoints: 3,
201
+ Variants: 4,
202
+ ColorScheme: 5,
203
+ Dimensions: 6,
204
+ Orientation: 7,
205
+ ContentSizeCategory: 8,
206
+ Insets: 9,
207
+ PixelRatio: 10,
208
+ FontScale: 11,
209
+ StatusBar: 12,
210
+ NavigationBar: 13,
211
+ Ime: 14,
212
+ Rtl: 15
213
+ };
214
+ function getProperty(property) {
215
+ if (!property) {
216
+ return void 0;
217
+ }
218
+ if (t4.isIdentifier(property)) {
219
+ const prop = property;
220
+ return {
221
+ properties: [prop.name]
222
+ };
223
+ }
224
+ if (t4.isObjectPattern(property)) {
225
+ const prop = property;
226
+ const matchingProperties = prop.properties.flatMap((p) => getProperty(p));
227
+ return {
228
+ properties: matchingProperties.flatMap((properties) => properties?.properties).filter((prop2) => prop2 !== void 0)
229
+ };
230
+ }
231
+ if (t4.isObjectProperty(property) && t4.isIdentifier(property.value)) {
232
+ const prop = property.key;
233
+ return {
234
+ properties: [prop.name]
235
+ };
236
+ }
237
+ if (t4.isObjectProperty(property) && t4.isObjectPattern(property.value)) {
238
+ const matchingProperties = property.value.properties.flatMap((p) => getProperty(p));
239
+ const prop = property.key;
240
+ return {
241
+ parent: prop.name,
242
+ properties: matchingProperties.flatMap((properties) => properties?.properties).filter((prop2) => prop2 !== void 0)
243
+ };
244
+ }
245
+ return void 0;
246
+ }
247
+ function toUnistylesDependency(dependency) {
248
+ switch (dependency) {
249
+ case "theme": {
250
+ return UnistyleDependency.Theme;
251
+ }
252
+ case "themeName": {
253
+ return UnistyleDependency.ThemeName;
254
+ }
255
+ case "adaptiveThemes": {
256
+ return UnistyleDependency.AdaptiveThemes;
257
+ }
258
+ case "breakpoint": {
259
+ return UnistyleDependency.Breakpoints;
260
+ }
261
+ case "colorScheme": {
262
+ return UnistyleDependency.ColorScheme;
263
+ }
264
+ case "screen": {
265
+ return UnistyleDependency.Dimensions;
266
+ }
267
+ case "isPortrait":
268
+ case "isLandscape": {
269
+ return UnistyleDependency.Orientation;
270
+ }
271
+ case "contentSizeCategory": {
272
+ return UnistyleDependency.ContentSizeCategory;
273
+ }
274
+ case "ime": {
275
+ return UnistyleDependency.Ime;
276
+ }
277
+ case "insets": {
278
+ return UnistyleDependency.Insets;
279
+ }
280
+ case "pixelRatio": {
281
+ return UnistyleDependency.PixelRatio;
282
+ }
283
+ case "fontScale": {
284
+ return UnistyleDependency.FontScale;
285
+ }
286
+ case "statusBar": {
287
+ return UnistyleDependency.StatusBar;
288
+ }
289
+ case "navigationBar": {
290
+ return UnistyleDependency.NavigationBar;
291
+ }
292
+ case "variants": {
293
+ return UnistyleDependency.Variants;
294
+ }
295
+ case "rtl": {
296
+ return UnistyleDependency.Rtl;
297
+ }
298
+ default:
299
+ return null;
300
+ }
301
+ }
302
+ function getReturnStatementsFromBody(node, results = []) {
303
+ if (t4.isReturnStatement(node)) {
304
+ results.push(node);
305
+ }
306
+ if (t4.isBlockStatement(node)) {
307
+ node.body.forEach((child) => getReturnStatementsFromBody(child, results));
308
+ }
309
+ if (t4.isIfStatement(node)) {
310
+ getReturnStatementsFromBody(node.consequent, results);
311
+ if (node.alternate) {
312
+ getReturnStatementsFromBody(node.alternate, results);
313
+ }
314
+ }
315
+ return results;
316
+ }
317
+ function stringToUniqueId(str) {
318
+ let hash = 0;
319
+ for (let i = 0; i < str.length; i++) {
320
+ hash = (hash << 5) - hash + str.charCodeAt(i);
321
+ hash |= 0;
322
+ }
323
+ const absHash = Math.abs(hash);
324
+ return absHash % 1e9;
325
+ }
326
+ function isUnistylesStyleSheet(path2, state) {
327
+ const { callee } = path2.node;
328
+ if (!t4.isMemberExpression(callee) || !t4.isIdentifier(callee.property)) {
329
+ return false;
330
+ }
331
+ const isImport = callee.property.name === "create" && t4.isIdentifier(callee.object) && callee.object.name === state.file.styleSheetLocalName;
332
+ const isRequire = state.file.hasUnistylesImport && callee.property.name === "create" && t4.isMemberExpression(callee.object) && t4.isIdentifier(callee.object.property) && t4.isIdentifier(callee.object.object) && callee.object.object.name === state.file.styleSheetLocalName && callee.object.property.name === "StyleSheet";
333
+ return isImport || isRequire;
334
+ }
335
+ function isUnistylesCommonJSRequire(path2, state) {
336
+ const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && t4.isStringLiteral(path2.node.arguments[0]) && path2.node.arguments[0].value === "react-native-unistyles";
337
+ if (isRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
338
+ state.file.hasUnistylesImport = true;
339
+ state.file.styleSheetLocalName = path2.parent.id.name;
340
+ }
341
+ return isRequire;
342
+ }
343
+ function isReactNativeCommonJSRequire(path2, state) {
344
+ const isRequire = t4.isIdentifier(path2.node.callee) && path2.node.arguments.length > 0 && path2.node.callee.name === "require";
345
+ const requireImportName = path2.node.arguments.find((node) => t4.isStringLiteral(node));
346
+ const isReactNativeRequire = isRequire && requireImportName && (requireImportName.value === "react-native" || requireImportName.value === "react-native-web/dist/index");
347
+ if (isReactNativeRequire && t4.isVariableDeclarator(path2.parent) && t4.isIdentifier(path2.parent.id)) {
348
+ state.file.reactNativeCommonJSName = path2.parent.id.name;
349
+ }
350
+ return isRequire;
351
+ }
352
+ function isKindOfStyleSheet(path2, state) {
353
+ if (!state.file.forceProcessing && !state.file.hasUnistylesImport) {
354
+ return false;
355
+ }
356
+ const { callee } = path2.node;
357
+ return t4.isMemberExpression(callee) && t4.isIdentifier(callee.property) && callee.property.name === "create" && t4.isIdentifier(callee.object);
358
+ }
359
+ function addStyleSheetTag(path2, state) {
360
+ const str = state.filename?.replace(state.cwd, "") ?? "";
361
+ const uniqueId = stringToUniqueId(str) + ++state.file.tagNumber;
362
+ path2.node.arguments.push(t4.numericLiteral(uniqueId));
363
+ }
364
+ function getStylesDependenciesFromObject(path2) {
365
+ const detectedStylesWithVariants = /* @__PURE__ */ new Set();
366
+ const stylesheet = path2.node.arguments[0];
367
+ if (t4.isObjectExpression(stylesheet)) {
368
+ stylesheet?.properties.forEach((property) => {
369
+ if (!t4.isObjectProperty(property) || !t4.isIdentifier(property.key)) {
370
+ return;
371
+ }
372
+ if (t4.isObjectProperty(property)) {
373
+ if (t4.isObjectExpression(property.value)) {
374
+ property.value.properties.forEach((innerProp) => {
375
+ if (t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && t4.isIdentifier(property.key) && innerProp.key.name === "variants") {
376
+ detectedStylesWithVariants.add({
377
+ label: "variants",
378
+ key: property.key.name
379
+ });
380
+ }
381
+ });
382
+ }
383
+ }
384
+ if (t4.isArrowFunctionExpression(property.value)) {
385
+ if (t4.isObjectExpression(property.value.body)) {
386
+ property.value.body.properties.forEach((innerProp) => {
387
+ if (t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && t4.isIdentifier(property.key) && innerProp.key.name === "variants") {
388
+ detectedStylesWithVariants.add({
389
+ label: "variants",
390
+ key: property.key.name
391
+ });
392
+ }
393
+ });
394
+ }
395
+ }
396
+ });
397
+ }
398
+ const variants = Array.from(detectedStylesWithVariants);
399
+ return variants.reduce((acc, { key, label }) => {
400
+ if (acc[key]) {
401
+ acc[key] = [
402
+ ...acc[key],
403
+ label
404
+ ];
405
+ return acc;
406
+ }
407
+ acc[key] = [label];
408
+ return acc;
409
+ }, {});
410
+ }
411
+ function getStylesDependenciesFromFunction(funcPath) {
412
+ if (!funcPath) {
413
+ return;
414
+ }
415
+ if (Array.isArray(funcPath)) {
416
+ return;
417
+ }
418
+ if (!t4.isFunctionExpression(funcPath.node) && !t4.isArrowFunctionExpression(funcPath.node)) {
419
+ return;
420
+ }
421
+ const params = funcPath.node.params;
422
+ const [themeParam, rtParam] = params;
423
+ const themeNames = [];
424
+ if (t4.isObjectPattern(themeParam)) {
425
+ for (const prop of themeParam.properties) {
426
+ const property = getProperty(prop);
427
+ if (property) {
428
+ themeNames.push(property);
429
+ }
430
+ }
431
+ }
432
+ if (t4.isIdentifier(themeParam)) {
433
+ themeNames.push({
434
+ properties: [themeParam.name]
435
+ });
436
+ }
437
+ const rtNames = [];
438
+ if (t4.isObjectPattern(rtParam)) {
439
+ for (const prop of rtParam.properties) {
440
+ const property = getProperty(prop);
441
+ if (property) {
442
+ rtNames.push(property);
443
+ }
444
+ }
445
+ }
446
+ if (t4.isIdentifier(rtParam)) {
447
+ rtNames.push({
448
+ properties: [rtParam.name]
449
+ });
450
+ }
451
+ let returnedObjectPath = null;
452
+ if (t4.isObjectExpression(funcPath.node.body)) {
453
+ returnedObjectPath = funcPath.get("body");
454
+ } else {
455
+ funcPath.traverse({
456
+ ReturnStatement(retPath) {
457
+ if (!returnedObjectPath && retPath.get("argument").isObjectExpression()) {
458
+ const argumentPath = retPath.get("argument");
459
+ if (argumentPath.isObjectExpression()) {
460
+ returnedObjectPath = argumentPath;
461
+ }
462
+ }
463
+ }
464
+ });
465
+ }
466
+ if (!returnedObjectPath) {
467
+ return;
468
+ }
469
+ const detectedStylesWithVariants = /* @__PURE__ */ new Set();
470
+ const properties = returnedObjectPath.get("properties");
471
+ properties.forEach((propPath) => {
472
+ const stylePath = propPath.get("key");
473
+ if (Array.isArray(stylePath)) {
474
+ return;
475
+ }
476
+ if (!stylePath.isIdentifier()) {
477
+ return;
478
+ }
479
+ const styleKey = stylePath.node.name;
480
+ const valuePath = propPath.get("value");
481
+ if (Array.isArray(valuePath)) {
482
+ return;
483
+ }
484
+ if (valuePath.isObjectExpression()) {
485
+ const hasVariants = valuePath.get("properties").some((innerProp) => {
486
+ const innerKey = innerProp.get("key");
487
+ if (Array.isArray(innerKey)) {
488
+ return;
489
+ }
490
+ return innerKey.isIdentifier() && innerKey.node.name === "variants";
491
+ });
492
+ if (hasVariants) {
493
+ detectedStylesWithVariants.add({
494
+ label: "variants",
495
+ key: styleKey
496
+ });
497
+ }
498
+ }
499
+ if (valuePath.isArrowFunctionExpression()) {
500
+ if (t4.isObjectExpression(valuePath.node.body)) {
501
+ const hasVariants = valuePath.node.body.properties.some((innerProp) => {
502
+ return t4.isObjectProperty(innerProp) && t4.isIdentifier(innerProp.key) && innerProp.key.name === "variants";
503
+ });
504
+ if (hasVariants) {
505
+ detectedStylesWithVariants.add({
506
+ label: "variants",
507
+ key: styleKey
508
+ });
509
+ }
510
+ }
511
+ }
512
+ });
513
+ const detectedStylesWithTheme = /* @__PURE__ */ new Set();
514
+ themeNames.forEach(({ properties: properties2 }) => {
515
+ properties2.forEach((property) => {
516
+ const binding = funcPath.scope.getBinding(property);
517
+ if (!binding) {
518
+ return;
519
+ }
520
+ binding.referencePaths.forEach((refPath) => {
521
+ const containerProp = refPath.findParent((parent) => parent.isObjectProperty() && parent.parentPath === returnedObjectPath);
522
+ if (!containerProp) {
523
+ return;
524
+ }
525
+ const keyNode = containerProp.get("key");
526
+ if (Array.isArray(keyNode)) {
527
+ return;
528
+ }
529
+ const keyValue = keyNode.isLiteral() ? keyNode.isStringLiteral() || keyNode.isNumericLiteral() || keyNode.isBooleanLiteral() ? String(keyNode.node.value) : null : null;
530
+ const styleKey = keyNode.isIdentifier() ? keyNode.node.name : keyValue;
531
+ if (styleKey) {
532
+ detectedStylesWithTheme.add({
533
+ label: "theme",
534
+ key: styleKey
535
+ });
536
+ }
537
+ });
538
+ });
539
+ });
540
+ const detectedStylesWithRt = /* @__PURE__ */ new Set();
541
+ const localRtName = t4.isIdentifier(rtParam) ? rtParam.name : void 0;
542
+ rtNames.forEach(({ properties: properties2, parent }) => {
543
+ properties2.forEach((property) => {
544
+ const rtBinding = funcPath.scope.getBinding(property);
545
+ if (!rtBinding) {
546
+ return;
547
+ }
548
+ const isValidDependency = Boolean(toUnistylesDependency(property));
549
+ let validRtName = property;
550
+ if (!isValidDependency && (!localRtName || localRtName && localRtName !== property)) {
551
+ if (!parent) {
552
+ return;
553
+ }
554
+ if (!toUnistylesDependency(parent)) {
555
+ return;
556
+ }
557
+ validRtName = parent;
558
+ }
559
+ rtBinding.referencePaths.forEach((refPath) => {
560
+ let usedLabel = validRtName;
561
+ if (refPath.parentPath?.isMemberExpression() && refPath.parentPath.get("object") === refPath) {
562
+ const memberExpr = refPath.parentPath;
563
+ const propPath = memberExpr.get("property");
564
+ if (propPath.isIdentifier()) {
565
+ if (localRtName) {
566
+ usedLabel = propPath.node.name;
567
+ }
568
+ if (usedLabel === "insets" && memberExpr.parentPath.isMemberExpression() && memberExpr.parentPath.get("object") === memberExpr) {
569
+ const secondPropPath = memberExpr.parentPath.get("property");
570
+ if (secondPropPath.isIdentifier() && secondPropPath.node.name === "ime") {
571
+ usedLabel = "ime";
572
+ }
573
+ }
574
+ if (usedLabel === "insets" && (memberExpr.parentPath.isBinaryExpression() || memberExpr.parentPath.isLogicalExpression())) {
575
+ const secondPropPath = memberExpr.node.property;
576
+ if (t4.isIdentifier(secondPropPath) && secondPropPath.name === "ime") {
577
+ usedLabel = "ime";
578
+ }
579
+ }
580
+ }
581
+ }
582
+ const containerProp = refPath.findParent((parent2) => parent2.isObjectProperty() && parent2.parentPath === returnedObjectPath);
583
+ if (!containerProp) {
584
+ return;
585
+ }
586
+ const keyNode = containerProp.get("key");
587
+ if (Array.isArray(keyNode)) {
588
+ return;
589
+ }
590
+ const keyValue = keyNode.isLiteral() ? keyNode.isStringLiteral() || keyNode.isNumericLiteral() || keyNode.isBooleanLiteral() ? String(keyNode.node.value) : null : null;
591
+ const styleKey = keyNode.isIdentifier() ? keyNode.node.name : keyValue;
592
+ if (styleKey) {
593
+ detectedStylesWithRt.add({
594
+ label: usedLabel,
595
+ key: styleKey
596
+ });
597
+ }
598
+ });
599
+ });
600
+ });
601
+ const variants = Array.from(detectedStylesWithVariants);
602
+ const theme = Array.from(detectedStylesWithTheme);
603
+ const rt = Array.from(detectedStylesWithRt);
604
+ return theme.concat(rt).concat(variants).reduce((acc, { key, label }) => {
605
+ if (acc[key]) {
606
+ acc[key] = [
607
+ ...acc[key],
608
+ label
609
+ ];
610
+ return acc;
611
+ }
612
+ acc[key] = [label];
613
+ return acc;
614
+ }, {});
615
+ }
616
+ function addDependencies(state, styleName, unistyle, detectedDependencies) {
617
+ const debugMessage = (deps) => {
618
+ if (state.opts.debug) {
619
+ const mappedDeps = deps.map((dep) => Object.keys(UnistyleDependency).find((key) => UnistyleDependency[key] === dep)).join(", ");
620
+ console.log(`${state.filename?.replace(`${state.file.opts.root}/`, "")}: styles.${styleName}: [${mappedDeps}]`);
621
+ }
622
+ };
623
+ const styleDependencies = detectedDependencies.map(toUnistylesDependency);
624
+ if (styleDependencies.length > 0) {
625
+ const uniqueDependencies = Array.from(new Set(styleDependencies));
626
+ debugMessage(uniqueDependencies);
627
+ let targets = [];
628
+ if (t4.isArrowFunctionExpression(unistyle.value) || t4.isFunctionExpression(unistyle.value)) {
629
+ if (t4.isObjectExpression(unistyle.value.body)) {
630
+ targets.push(unistyle.value.body);
631
+ }
632
+ if (t4.isBlockStatement(unistyle.value.body)) {
633
+ targets = getReturnStatementsFromBody(unistyle.value.body).map((node) => {
634
+ if (t4.isIdentifier(node.argument)) {
635
+ node.argument = t4.objectExpression([
636
+ t4.spreadElement(node.argument)
637
+ ]);
638
+ }
639
+ return node.argument;
640
+ }).filter((node) => t4.isObjectExpression(node));
641
+ }
642
+ }
643
+ if (t4.isObjectExpression(unistyle.value)) {
644
+ targets.push(unistyle.value);
645
+ }
646
+ if (t4.isMemberExpression(unistyle.value)) {
647
+ unistyle.value = t4.objectExpression([t4.spreadElement(unistyle.value)]);
648
+ targets.push(unistyle.value);
649
+ }
650
+ if (targets.length > 0) {
651
+ targets.forEach((target) => {
652
+ target.properties.push(
653
+ t4.objectProperty(
654
+ t4.identifier("uni__dependencies"),
655
+ t4.arrayExpression(uniqueDependencies.filter((dep) => dep !== void 0).map((dep) => t4.numericLiteral(dep)))
656
+ )
657
+ );
658
+ });
659
+ }
660
+ }
661
+ }
154
662
 
155
- // Object passed to StyleSheet.create (may contain variants)
156
- if (t.isObjectExpression(arg)) {
157
- const detectedDependencies = getStylesDependenciesFromObject(t, path)
663
+ // plugin/src/variants.ts
664
+ var t5 = __toESM(require("@babel/types"));
665
+ function extractVariants(path2, state) {
666
+ const maybeVariants = path2.node.body.filter((node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee));
667
+ if (maybeVariants.length === 0) {
668
+ return;
669
+ }
670
+ const targetVariant = maybeVariants.find((variant) => {
671
+ if (!t5.isExpressionStatement(variant) || !t5.isCallExpression(variant.expression) || !t5.isMemberExpression(variant.expression.callee) || !t5.isIdentifier(variant.expression.callee.object)) {
672
+ return false;
673
+ }
674
+ const calleeName2 = variant.expression.callee.object.name;
675
+ return t5.isIdentifier(variant.expression.callee.object, { name: calleeName2 }) && t5.isIdentifier(variant.expression.callee.property, { name: "useVariants" }) && variant.expression.arguments.length === 1;
676
+ });
677
+ if (!targetVariant) {
678
+ return;
679
+ }
680
+ const node = targetVariant.expression;
681
+ if (!t5.isCallExpression(node)) {
682
+ return;
683
+ }
684
+ const callee = node.callee;
685
+ if (!t5.isMemberExpression(callee) || !t5.isIdentifier(callee.object)) {
686
+ return;
687
+ }
688
+ const calleeName = callee.object.name;
689
+ const newUniqueName = path2.scope.generateUidIdentifier(calleeName);
690
+ const shadowDeclaration = t5.variableDeclaration("const", [
691
+ t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
692
+ ]);
693
+ const newCallExpression = t5.callExpression(
694
+ t5.memberExpression(t5.identifier(newUniqueName.name), t5.identifier("useVariants")),
695
+ node.arguments
696
+ );
697
+ const finalDeclaration = t5.variableDeclaration("const", [
698
+ t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
699
+ ]);
700
+ const pathIndex = path2.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
701
+ const rest = path2.node.body.slice(pathIndex + 1);
702
+ const statement = t5.blockStatement([
703
+ finalDeclaration,
704
+ ...rest
705
+ ]);
706
+ path2.node.body = [
707
+ ...path2.node.body.slice(0, pathIndex),
708
+ shadowDeclaration,
709
+ statement
710
+ ];
711
+ state.file.hasVariants = true;
712
+ }
158
713
 
159
- if (detectedDependencies) {
160
- if (t.isObjectExpression(arg)) {
161
- arg.properties.forEach(property => {
162
- if (detectedDependencies.hasOwnProperty(property.key.name)) {
163
- addDependencies(t, state, property.key.name, property, detectedDependencies[property.key.name])
164
- }
165
- })
166
- }
167
- }
714
+ // plugin/src/index.ts
715
+ function index_default() {
716
+ if (process.env.NODE_ENV === "test") {
717
+ return {
718
+ name: "babel-react-native-unistyles",
719
+ visitor: {}
720
+ };
721
+ }
722
+ return {
723
+ name: "babel-react-native-unistyles",
724
+ visitor: {
725
+ Program: {
726
+ enter(path2, state) {
727
+ state.file.replaceWithUnistyles = REPLACE_WITH_UNISTYLES_PATHS.map(toPlatformPath).concat(state.opts.autoProcessPaths ?? []).some((path3) => state.filename?.includes(path3));
728
+ state.file.hasAnyUnistyle = false;
729
+ state.file.hasUnistylesImport = false;
730
+ state.file.addUnistylesRequire = false;
731
+ state.file.hasVariants = false;
732
+ state.file.styleSheetLocalName = "";
733
+ state.file.reactNativeCommonJSName = "";
734
+ state.file.tagNumber = 0;
735
+ state.reactNativeImports = {};
736
+ state.file.forceProcessing = state.opts.autoProcessRoot && state.filename ? state.filename.includes(toPlatformPath(`${state.file.opts.root}/${state.opts.autoProcessRoot}/`)) : false;
737
+ path2.traverse({
738
+ BlockStatement(blockPath) {
739
+ if (isInsideNodeModules(state)) {
740
+ return;
741
+ }
742
+ extractVariants(blockPath, state);
743
+ }
744
+ });
745
+ },
746
+ exit(path2, state) {
747
+ if (isInsideNodeModules(state)) {
748
+ return;
749
+ }
750
+ if (state.file.addUnistylesRequire) {
751
+ return addUnistylesRequire(path2, state);
752
+ }
753
+ if (state.file.hasAnyUnistyle || state.file.hasVariants || state.file.replaceWithUnistyles || state.file.forceProcessing) {
754
+ addUnistylesImport(path2, state);
755
+ }
756
+ }
757
+ },
758
+ FunctionDeclaration(path2, state) {
759
+ if (isInsideNodeModules(state)) {
760
+ return;
761
+ }
762
+ const componentName = path2.node.id ? path2.node.id.name : null;
763
+ if (componentName) {
764
+ state.file.hasVariants = false;
765
+ }
766
+ },
767
+ ClassDeclaration(path2, state) {
768
+ if (isInsideNodeModules(state)) {
769
+ return;
770
+ }
771
+ const componentName = path2.node.id ? path2.node.id.name : null;
772
+ if (componentName) {
773
+ state.file.hasVariants = false;
774
+ }
775
+ },
776
+ VariableDeclaration(path2, state) {
777
+ if (isInsideNodeModules(state)) {
778
+ return;
779
+ }
780
+ path2.node.declarations.forEach((declaration) => {
781
+ if (t6.isArrowFunctionExpression(declaration.init) || t6.isFunctionExpression(declaration.init)) {
782
+ const componentName = declaration.id && t6.isIdentifier(declaration.id) ? declaration.id.name : null;
783
+ if (componentName) {
784
+ state.file.hasVariants = false;
785
+ }
786
+ }
787
+ });
788
+ },
789
+ ImportDeclaration(path2, state) {
790
+ const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find((exotic) => state.filename?.includes(exotic.path));
791
+ if (exoticImport) {
792
+ return handleExoticImport(path2, state, exoticImport);
793
+ }
794
+ if (isInsideNodeModules(state)) {
795
+ return;
796
+ }
797
+ const importSource = path2.node.source.value;
798
+ if (importSource.includes("react-native-unistyles")) {
799
+ state.file.hasUnistylesImport = true;
800
+ path2.node.specifiers.forEach((specifier) => {
801
+ if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && specifier.imported.name === "StyleSheet") {
802
+ state.file.styleSheetLocalName = specifier.local.name;
803
+ }
804
+ });
805
+ }
806
+ if (importSource === "react-native") {
807
+ path2.node.specifiers.forEach((specifier) => {
808
+ if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
809
+ state.reactNativeImports[specifier.local.name] = specifier.imported.name;
810
+ }
811
+ });
812
+ }
813
+ if (importSource.includes("react-native/Libraries")) {
814
+ handleExoticImport(path2, state, NATIVE_COMPONENTS_PATHS);
815
+ }
816
+ if (!state.file.forceProcessing && Array.isArray(state.opts.autoProcessImports)) {
817
+ state.file.forceProcessing = state.opts.autoProcessImports.includes(importSource);
818
+ }
819
+ },
820
+ JSXElement(path2, state) {
821
+ if (isInsideNodeModules(state)) {
822
+ return;
823
+ }
824
+ if (hasStringRef(path2)) {
825
+ throw new Error("Detected string based ref which is not supported by Unistyles.");
826
+ }
827
+ },
828
+ MemberExpression(path2, state) {
829
+ if (isInsideNodeModules(state)) {
830
+ return;
831
+ }
832
+ if (!state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.object)) {
833
+ return;
834
+ }
835
+ if (path2.node.object.name !== state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.property)) {
836
+ return;
837
+ }
838
+ if (!REACT_NATIVE_COMPONENT_NAMES.includes(path2.node.property.name)) {
839
+ return;
840
+ }
841
+ if (!state.reactNativeImports[path2.node.property.name]) {
842
+ const uniqueId = path2.scope.generateUidIdentifier(`reactNativeUnistyles_${path2.node.property.name}`);
843
+ state.reactNativeImports[path2.node.property.name] = uniqueId.name;
844
+ state.file.addUnistylesRequire = true;
845
+ }
846
+ path2.node.object.name = state.reactNativeImports[path2.node.property.name];
847
+ },
848
+ CallExpression(path2, state) {
849
+ if (isInsideNodeModules(state)) {
850
+ return;
851
+ }
852
+ if (isUnistylesCommonJSRequire(path2, state)) {
853
+ return;
854
+ }
855
+ if (isReactNativeCommonJSRequire(path2, state)) {
856
+ return;
857
+ }
858
+ if (!isUnistylesStyleSheet(path2, state) && !isKindOfStyleSheet(path2, state)) {
859
+ return;
860
+ }
861
+ state.file.hasAnyUnistyle = true;
862
+ addStyleSheetTag(path2, state);
863
+ const arg = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.node.arguments[0].right : path2.node.arguments[0];
864
+ if (t6.isObjectExpression(arg)) {
865
+ const detectedDependencies = getStylesDependenciesFromObject(path2);
866
+ if (detectedDependencies) {
867
+ if (t6.isObjectExpression(arg)) {
868
+ arg.properties.forEach((property) => {
869
+ if (t6.isObjectProperty(property) && t6.isIdentifier(property.key) && Object.prototype.hasOwnProperty.call(detectedDependencies, property.key.name)) {
870
+ addDependencies(state, property.key.name, property, detectedDependencies[property.key.name] ?? []);
168
871
  }
169
-
170
- // Function passed to StyleSheet.create (e.g., theme => ({ container: {} }))
171
- if (t.isArrowFunctionExpression(arg) || t.isFunctionExpression(arg)) {
172
- const detectedDependencies = getStylesDependenciesFromFunction(t, path)
173
-
174
- if (detectedDependencies) {
175
- const body = t.isBlockStatement(arg.body)
176
- ? arg.body.body.find(statement => t.isReturnStatement(statement)).argument
177
- : arg.body
178
-
179
- // Ensure the function body returns an object
180
- if (t.isObjectExpression(body)) {
181
- body.properties.forEach(property => {
182
- if (detectedDependencies.hasOwnProperty(property.key.name)) {
183
- addDependencies(t, state, property.key.name, property, detectedDependencies[property.key.name])
184
- }
185
- })
186
- }
187
- }
872
+ });
873
+ }
874
+ }
875
+ }
876
+ if (t6.isArrowFunctionExpression(arg) || t6.isFunctionExpression(arg)) {
877
+ const funcPath = t6.isAssignmentExpression(path2.node.arguments[0]) ? path2.get("arguments.0.right") : path2.get("arguments.0");
878
+ const detectedDependencies = getStylesDependenciesFromFunction(funcPath);
879
+ if (detectedDependencies) {
880
+ const body = t6.isBlockStatement(arg.body) ? arg.body.body.find((statement) => t6.isReturnStatement(statement))?.argument : arg.body;
881
+ if (t6.isObjectExpression(body)) {
882
+ body.properties.forEach((property) => {
883
+ if (t6.isObjectProperty(property) && t6.isIdentifier(property.key) && Object.prototype.hasOwnProperty.call(detectedDependencies, property.key.name)) {
884
+ addDependencies(state, property.key.name, property, detectedDependencies[property.key.name] ?? []);
188
885
  }
886
+ });
189
887
  }
888
+ }
190
889
  }
890
+ }
191
891
  }
892
+ };
192
893
  }