react-native-unistyles 3.5.3 → 3.7.0

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 (401) hide show
  1. package/README.md +6 -8
  2. package/android/build.gradle +42 -0
  3. package/android/src/legacy/java/com/unistyles/NativePlatform+extraWindows.kt +16 -0
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +5 -11
  5. package/android/src/main/cxx/NativeUnistylesModule.h +0 -4
  6. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +82 -39
  7. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +73 -0
  8. package/android/src/main/java/com/unistyles/UnistylesModule.kt +2 -13
  9. package/android/src/rn86/java/com/unistyles/NativePlatform+extraWindows.kt +28 -0
  10. package/cxx/common/PerformanceTracing.h +85 -0
  11. package/cxx/converters/BackgroundImageConverter.cpp +198 -11
  12. package/cxx/converters/BackgroundImageConverter.h +1 -0
  13. package/cxx/converters/BackgroundLayerConverter.cpp +523 -0
  14. package/cxx/converters/BackgroundLayerConverter.h +14 -0
  15. package/cxx/converters/FontVariationSettingsConverter.cpp +104 -0
  16. package/cxx/converters/FontVariationSettingsConverter.h +17 -0
  17. package/cxx/core/HostUnistyle.cpp +6 -0
  18. package/cxx/core/UnistyleWrapper.h +16 -1
  19. package/cxx/hybridObjects/HybridShadowRegistry.cpp +13 -0
  20. package/cxx/hybridObjects/HybridStyleSheet.cpp +11 -0
  21. package/cxx/hybridObjects/HybridStyleSheet.h +1 -0
  22. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +10 -30
  23. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -2
  24. package/cxx/parser/Parser.cpp +92 -5
  25. package/cxx/shadowTree/ShadowTreeDiagnostics.cpp +74 -0
  26. package/cxx/shadowTree/ShadowTreeManager.cpp +3 -0
  27. package/ios/NativePlatform+ios.swift +22 -11
  28. package/ios/NativePlatformListener+ios.swift +9 -0
  29. package/lib/commonjs/components/NamedTheme.js +4 -4
  30. package/lib/commonjs/components/NamedTheme.js.map +1 -1
  31. package/lib/commonjs/components/ScopedThemeContext.js +3 -1
  32. package/lib/commonjs/components/ScopedThemeContext.js.map +1 -1
  33. package/lib/commonjs/components/native/deep/ActivityIndicator.js +19 -0
  34. package/lib/commonjs/components/native/deep/ActivityIndicator.js.map +1 -0
  35. package/lib/commonjs/components/native/deep/Animated.js +19 -0
  36. package/lib/commonjs/components/native/deep/Animated.js.map +1 -0
  37. package/lib/commonjs/components/native/deep/FlatList.js +19 -0
  38. package/lib/commonjs/components/native/deep/FlatList.js.map +1 -0
  39. package/lib/commonjs/components/native/deep/Image.js +19 -0
  40. package/lib/commonjs/components/native/deep/Image.js.map +1 -0
  41. package/lib/commonjs/components/native/deep/ImageBackground.js +19 -0
  42. package/lib/commonjs/components/native/deep/ImageBackground.js.map +1 -0
  43. package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js +19 -0
  44. package/lib/commonjs/components/native/deep/KeyboardAvoidingView.js.map +1 -0
  45. package/lib/commonjs/components/native/deep/Pressable.js +19 -0
  46. package/lib/commonjs/components/native/deep/Pressable.js.map +1 -0
  47. package/lib/commonjs/components/native/deep/RefreshControl.js +19 -0
  48. package/lib/commonjs/components/native/deep/RefreshControl.js.map +1 -0
  49. package/lib/commonjs/components/native/deep/SafeAreaView.js +19 -0
  50. package/lib/commonjs/components/native/deep/SafeAreaView.js.map +1 -0
  51. package/lib/commonjs/components/native/deep/ScrollView.js +19 -0
  52. package/lib/commonjs/components/native/deep/ScrollView.js.map +1 -0
  53. package/lib/commonjs/components/native/deep/SectionList.js +19 -0
  54. package/lib/commonjs/components/native/deep/SectionList.js.map +1 -0
  55. package/lib/commonjs/components/native/deep/Switch.js +19 -0
  56. package/lib/commonjs/components/native/deep/Switch.js.map +1 -0
  57. package/lib/commonjs/components/native/deep/Text.js +19 -0
  58. package/lib/commonjs/components/native/deep/Text.js.map +1 -0
  59. package/lib/commonjs/components/native/deep/TextInput.js +19 -0
  60. package/lib/commonjs/components/native/deep/TextInput.js.map +1 -0
  61. package/lib/commonjs/components/native/deep/TextNativeComponent.js +28 -0
  62. package/lib/commonjs/components/native/deep/TextNativeComponent.js.map +1 -0
  63. package/lib/commonjs/components/native/deep/TouchableHighlight.js +19 -0
  64. package/lib/commonjs/components/native/deep/TouchableHighlight.js.map +1 -0
  65. package/lib/commonjs/components/native/deep/TouchableOpacity.js +19 -0
  66. package/lib/commonjs/components/native/deep/TouchableOpacity.js.map +1 -0
  67. package/lib/commonjs/components/native/deep/View.js +19 -0
  68. package/lib/commonjs/components/native/deep/View.js.map +1 -0
  69. package/lib/commonjs/components/native/deep/ViewNativeComponent.js +26 -0
  70. package/lib/commonjs/components/native/deep/ViewNativeComponent.js.map +1 -0
  71. package/lib/commonjs/components/native/deep/VirtualizedList.js +19 -0
  72. package/lib/commonjs/components/native/deep/VirtualizedList.js.map +1 -0
  73. package/lib/commonjs/components/native/index.js +43 -0
  74. package/lib/commonjs/components/native/index.js.map +1 -0
  75. package/lib/commonjs/core/createUnistylesActivityIndicator.js +13 -3
  76. package/lib/commonjs/core/createUnistylesActivityIndicator.js.map +1 -1
  77. package/lib/commonjs/core/createUnistylesElement.native.js +6 -0
  78. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  79. package/lib/commonjs/core/createUnistylesImageBackground.js +26 -19
  80. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  81. package/lib/commonjs/core/createUnistylesTouchableHighlight.js +6 -0
  82. package/lib/commonjs/core/createUnistylesTouchableHighlight.js.map +1 -1
  83. package/lib/commonjs/core/getClassname.js +15 -0
  84. package/lib/commonjs/core/getClassname.js.map +1 -1
  85. package/lib/commonjs/core/hasUnistyles.js +26 -0
  86. package/lib/commonjs/core/hasUnistyles.js.map +1 -0
  87. package/lib/commonjs/core/withUnistyles/withUnistyles.js +10 -7
  88. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  89. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +22 -3
  90. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  91. package/lib/commonjs/mocks.js +27 -3
  92. package/lib/commonjs/mocks.js.map +1 -1
  93. package/lib/commonjs/specs/ShadowRegistry/index.js +69 -76
  94. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  95. package/lib/commonjs/specs/ShadowRegistry/styleSource.js +65 -0
  96. package/lib/commonjs/specs/ShadowRegistry/styleSource.js.map +1 -0
  97. package/lib/commonjs/specs/ShadowRegistry/tracing.js +26 -0
  98. package/lib/commonjs/specs/ShadowRegistry/tracing.js.map +1 -0
  99. package/lib/commonjs/unifiber/src/adapters/reanimated.js +157 -0
  100. package/lib/commonjs/unifiber/src/adapters/reanimated.js.map +1 -0
  101. package/lib/commonjs/unifiber/src/adapters/registry.js +67 -0
  102. package/lib/commonjs/unifiber/src/adapters/registry.js.map +1 -0
  103. package/lib/commonjs/unifiber/src/diagnostics.js +59 -0
  104. package/lib/commonjs/unifiber/src/diagnostics.js.map +1 -0
  105. package/lib/commonjs/unifiber/src/fiber.js +199 -0
  106. package/lib/commonjs/unifiber/src/fiber.js.map +1 -0
  107. package/lib/commonjs/unifiber/src/host.js +214 -0
  108. package/lib/commonjs/unifiber/src/host.js.map +1 -0
  109. package/lib/commonjs/unifiber/src/index.js +38 -0
  110. package/lib/commonjs/unifiber/src/index.js.map +1 -0
  111. package/lib/commonjs/utils.js +52 -1
  112. package/lib/commonjs/utils.js.map +1 -1
  113. package/lib/commonjs/web/convert/index.js +19 -1
  114. package/lib/commonjs/web/convert/index.js.map +1 -1
  115. package/lib/commonjs/web/convert/module.d.ts +3 -0
  116. package/lib/commonjs/web/convert/object/backgroundLayers.js +30 -0
  117. package/lib/commonjs/web/convert/object/backgroundLayers.js.map +1 -0
  118. package/lib/commonjs/web/convert/object/fontVariationSettings.js +12 -0
  119. package/lib/commonjs/web/convert/object/fontVariationSettings.js.map +1 -0
  120. package/lib/commonjs/web/convert/object/index.js +22 -0
  121. package/lib/commonjs/web/convert/object/index.js.map +1 -1
  122. package/lib/commonjs/web/convert/utils.js +7 -1
  123. package/lib/commonjs/web/convert/utils.js.map +1 -1
  124. package/lib/commonjs/web/registry.js +6 -4
  125. package/lib/commonjs/web/registry.js.map +1 -1
  126. package/lib/commonjs/web/runtime.js +9 -6
  127. package/lib/commonjs/web/runtime.js.map +1 -1
  128. package/lib/commonjs/web/utils/unistyle.js +9 -3
  129. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  130. package/lib/module/components/NamedTheme.js +4 -4
  131. package/lib/module/components/NamedTheme.js.map +1 -1
  132. package/lib/module/components/ScopedThemeContext.js +3 -1
  133. package/lib/module/components/ScopedThemeContext.js.map +1 -1
  134. package/lib/module/components/native/deep/ActivityIndicator.js +5 -0
  135. package/lib/module/components/native/deep/ActivityIndicator.js.map +1 -0
  136. package/lib/module/components/native/deep/Animated.js +5 -0
  137. package/lib/module/components/native/deep/Animated.js.map +1 -0
  138. package/lib/module/components/native/deep/FlatList.js +5 -0
  139. package/lib/module/components/native/deep/FlatList.js.map +1 -0
  140. package/lib/module/components/native/deep/Image.js +5 -0
  141. package/lib/module/components/native/deep/Image.js.map +1 -0
  142. package/lib/module/components/native/deep/ImageBackground.js +5 -0
  143. package/lib/module/components/native/deep/ImageBackground.js.map +1 -0
  144. package/lib/module/components/native/deep/KeyboardAvoidingView.js +5 -0
  145. package/lib/module/components/native/deep/KeyboardAvoidingView.js.map +1 -0
  146. package/lib/module/components/native/deep/Pressable.js +5 -0
  147. package/lib/module/components/native/deep/Pressable.js.map +1 -0
  148. package/lib/module/components/native/deep/RefreshControl.js +5 -0
  149. package/lib/module/components/native/deep/RefreshControl.js.map +1 -0
  150. package/lib/module/components/native/deep/SafeAreaView.js +5 -0
  151. package/lib/module/components/native/deep/SafeAreaView.js.map +1 -0
  152. package/lib/module/components/native/deep/ScrollView.js +5 -0
  153. package/lib/module/components/native/deep/ScrollView.js.map +1 -0
  154. package/lib/module/components/native/deep/SectionList.js +5 -0
  155. package/lib/module/components/native/deep/SectionList.js.map +1 -0
  156. package/lib/module/components/native/deep/Switch.js +5 -0
  157. package/lib/module/components/native/deep/Switch.js.map +1 -0
  158. package/lib/module/components/native/deep/Text.js +5 -0
  159. package/lib/module/components/native/deep/Text.js.map +1 -0
  160. package/lib/module/components/native/deep/TextInput.js +5 -0
  161. package/lib/module/components/native/deep/TextInput.js.map +1 -0
  162. package/lib/module/components/native/deep/TextNativeComponent.js +8 -0
  163. package/lib/module/components/native/deep/TextNativeComponent.js.map +1 -0
  164. package/lib/module/components/native/deep/TouchableHighlight.js +5 -0
  165. package/lib/module/components/native/deep/TouchableHighlight.js.map +1 -0
  166. package/lib/module/components/native/deep/TouchableOpacity.js +5 -0
  167. package/lib/module/components/native/deep/TouchableOpacity.js.map +1 -0
  168. package/lib/module/components/native/deep/View.js +5 -0
  169. package/lib/module/components/native/deep/View.js.map +1 -0
  170. package/lib/module/components/native/deep/ViewNativeComponent.js +8 -0
  171. package/lib/module/components/native/deep/ViewNativeComponent.js.map +1 -0
  172. package/lib/module/components/native/deep/VirtualizedList.js +5 -0
  173. package/lib/module/components/native/deep/VirtualizedList.js.map +1 -0
  174. package/lib/module/components/native/index.js +43 -0
  175. package/lib/module/components/native/index.js.map +1 -0
  176. package/lib/module/core/createUnistylesActivityIndicator.js +13 -3
  177. package/lib/module/core/createUnistylesActivityIndicator.js.map +1 -1
  178. package/lib/module/core/createUnistylesElement.native.js +6 -0
  179. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  180. package/lib/module/core/createUnistylesImageBackground.js +26 -19
  181. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  182. package/lib/module/core/createUnistylesTouchableHighlight.js +6 -0
  183. package/lib/module/core/createUnistylesTouchableHighlight.js.map +1 -1
  184. package/lib/module/core/getClassname.js +16 -1
  185. package/lib/module/core/getClassname.js.map +1 -1
  186. package/lib/module/core/hasUnistyles.js +21 -0
  187. package/lib/module/core/hasUnistyles.js.map +1 -0
  188. package/lib/module/core/withUnistyles/withUnistyles.js +9 -6
  189. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  190. package/lib/module/core/withUnistyles/withUnistyles.native.js +24 -5
  191. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  192. package/lib/module/mocks.js +27 -3
  193. package/lib/module/mocks.js.map +1 -1
  194. package/lib/module/specs/ShadowRegistry/index.js +69 -76
  195. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  196. package/lib/module/specs/ShadowRegistry/styleSource.js +60 -0
  197. package/lib/module/specs/ShadowRegistry/styleSource.js.map +1 -0
  198. package/lib/module/specs/ShadowRegistry/tracing.js +21 -0
  199. package/lib/module/specs/ShadowRegistry/tracing.js.map +1 -0
  200. package/lib/module/unifiber/src/adapters/reanimated.js +152 -0
  201. package/lib/module/unifiber/src/adapters/reanimated.js.map +1 -0
  202. package/lib/module/unifiber/src/adapters/registry.js +62 -0
  203. package/lib/module/unifiber/src/adapters/registry.js.map +1 -0
  204. package/lib/module/unifiber/src/diagnostics.js +52 -0
  205. package/lib/module/unifiber/src/diagnostics.js.map +1 -0
  206. package/lib/module/unifiber/src/fiber.js +183 -0
  207. package/lib/module/unifiber/src/fiber.js.map +1 -0
  208. package/lib/module/unifiber/src/host.js +191 -0
  209. package/lib/module/unifiber/src/host.js.map +1 -0
  210. package/lib/module/unifiber/src/index.js +33 -0
  211. package/lib/module/unifiber/src/index.js.map +1 -0
  212. package/lib/module/utils.js +50 -0
  213. package/lib/module/utils.js.map +1 -1
  214. package/lib/module/web/convert/index.js +22 -3
  215. package/lib/module/web/convert/index.js.map +1 -1
  216. package/lib/module/web/convert/module.d.ts +3 -0
  217. package/lib/module/web/convert/object/backgroundLayers.js +25 -0
  218. package/lib/module/web/convert/object/backgroundLayers.js.map +1 -0
  219. package/lib/module/web/convert/object/fontVariationSettings.js +7 -0
  220. package/lib/module/web/convert/object/fontVariationSettings.js.map +1 -0
  221. package/lib/module/web/convert/object/index.js +2 -0
  222. package/lib/module/web/convert/object/index.js.map +1 -1
  223. package/lib/module/web/convert/utils.js +4 -0
  224. package/lib/module/web/convert/utils.js.map +1 -1
  225. package/lib/module/web/registry.js +6 -4
  226. package/lib/module/web/registry.js.map +1 -1
  227. package/lib/module/web/runtime.js +9 -6
  228. package/lib/module/web/runtime.js.map +1 -1
  229. package/lib/module/web/utils/unistyle.js +10 -4
  230. package/lib/module/web/utils/unistyle.js.map +1 -1
  231. package/lib/typescript/src/components/ScopedThemeContext.d.ts +2 -1
  232. package/lib/typescript/src/components/ScopedThemeContext.d.ts.map +1 -1
  233. package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts +2 -0
  234. package/lib/typescript/src/components/native/deep/ActivityIndicator.d.ts.map +1 -0
  235. package/lib/typescript/src/components/native/deep/Animated.d.ts +2 -0
  236. package/lib/typescript/src/components/native/deep/Animated.d.ts.map +1 -0
  237. package/lib/typescript/src/components/native/deep/FlatList.d.ts +2 -0
  238. package/lib/typescript/src/components/native/deep/FlatList.d.ts.map +1 -0
  239. package/lib/typescript/src/components/native/deep/Image.d.ts +2 -0
  240. package/lib/typescript/src/components/native/deep/Image.d.ts.map +1 -0
  241. package/lib/typescript/src/components/native/deep/ImageBackground.d.ts +2 -0
  242. package/lib/typescript/src/components/native/deep/ImageBackground.d.ts.map +1 -0
  243. package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts +2 -0
  244. package/lib/typescript/src/components/native/deep/KeyboardAvoidingView.d.ts.map +1 -0
  245. package/lib/typescript/src/components/native/deep/Pressable.d.ts +2 -0
  246. package/lib/typescript/src/components/native/deep/Pressable.d.ts.map +1 -0
  247. package/lib/typescript/src/components/native/deep/RefreshControl.d.ts +2 -0
  248. package/lib/typescript/src/components/native/deep/RefreshControl.d.ts.map +1 -0
  249. package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts +2 -0
  250. package/lib/typescript/src/components/native/deep/SafeAreaView.d.ts.map +1 -0
  251. package/lib/typescript/src/components/native/deep/ScrollView.d.ts +2 -0
  252. package/lib/typescript/src/components/native/deep/ScrollView.d.ts.map +1 -0
  253. package/lib/typescript/src/components/native/deep/SectionList.d.ts +2 -0
  254. package/lib/typescript/src/components/native/deep/SectionList.d.ts.map +1 -0
  255. package/lib/typescript/src/components/native/deep/Switch.d.ts +2 -0
  256. package/lib/typescript/src/components/native/deep/Switch.d.ts.map +1 -0
  257. package/lib/typescript/src/components/native/deep/Text.d.ts +2 -0
  258. package/lib/typescript/src/components/native/deep/Text.d.ts.map +1 -0
  259. package/lib/typescript/src/components/native/deep/TextInput.d.ts +2 -0
  260. package/lib/typescript/src/components/native/deep/TextInput.d.ts.map +1 -0
  261. package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts +3 -0
  262. package/lib/typescript/src/components/native/deep/TextNativeComponent.d.ts.map +1 -0
  263. package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts +2 -0
  264. package/lib/typescript/src/components/native/deep/TouchableHighlight.d.ts.map +1 -0
  265. package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts +2 -0
  266. package/lib/typescript/src/components/native/deep/TouchableOpacity.d.ts.map +1 -0
  267. package/lib/typescript/src/components/native/deep/View.d.ts +2 -0
  268. package/lib/typescript/src/components/native/deep/View.d.ts.map +1 -0
  269. package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts +3 -0
  270. package/lib/typescript/src/components/native/deep/ViewNativeComponent.d.ts.map +1 -0
  271. package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts +2 -0
  272. package/lib/typescript/src/components/native/deep/VirtualizedList.d.ts.map +1 -0
  273. package/lib/typescript/src/components/native/index.d.ts +4 -0
  274. package/lib/typescript/src/components/native/index.d.ts.map +1 -0
  275. package/lib/typescript/src/components/scopeChildren.d.ts +1 -1
  276. package/lib/typescript/src/core/createUnistylesActivityIndicator.d.ts.map +1 -1
  277. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  278. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  279. package/lib/typescript/src/core/createUnistylesTouchableHighlight.d.ts.map +1 -1
  280. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  281. package/lib/typescript/src/core/hasUnistyles.d.ts +2 -0
  282. package/lib/typescript/src/core/hasUnistyles.d.ts.map +1 -0
  283. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +6 -3
  284. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  285. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +7 -4
  286. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  287. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  288. package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts +11 -0
  289. package/lib/typescript/src/specs/ShadowRegistry/styleSource.d.ts.map +1 -0
  290. package/lib/typescript/src/specs/ShadowRegistry/tracing.d.ts +2 -0
  291. package/lib/typescript/src/specs/ShadowRegistry/tracing.d.ts.map +1 -0
  292. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +4 -41
  293. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
  294. package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts +17 -0
  295. package/lib/typescript/src/unifiber/src/adapters/reanimated.d.ts.map +1 -0
  296. package/lib/typescript/src/unifiber/src/adapters/registry.d.ts +23 -0
  297. package/lib/typescript/src/unifiber/src/adapters/registry.d.ts.map +1 -0
  298. package/lib/typescript/src/unifiber/src/diagnostics.d.ts +10 -0
  299. package/lib/typescript/src/unifiber/src/diagnostics.d.ts.map +1 -0
  300. package/lib/typescript/src/unifiber/src/fiber.d.ts +48 -0
  301. package/lib/typescript/src/unifiber/src/fiber.d.ts.map +1 -0
  302. package/lib/typescript/src/unifiber/src/host.d.ts +32 -0
  303. package/lib/typescript/src/unifiber/src/host.d.ts.map +1 -0
  304. package/lib/typescript/src/unifiber/src/index.d.ts +49 -0
  305. package/lib/typescript/src/unifiber/src/index.d.ts.map +1 -0
  306. package/lib/typescript/src/utils.d.ts +1 -0
  307. package/lib/typescript/src/utils.d.ts.map +1 -1
  308. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  309. package/lib/typescript/src/web/convert/object/backgroundLayers.d.ts +4 -0
  310. package/lib/typescript/src/web/convert/object/backgroundLayers.d.ts.map +1 -0
  311. package/lib/typescript/src/web/convert/object/fontVariationSettings.d.ts +4 -0
  312. package/lib/typescript/src/web/convert/object/fontVariationSettings.d.ts.map +1 -0
  313. package/lib/typescript/src/web/convert/object/index.d.ts +2 -0
  314. package/lib/typescript/src/web/convert/object/index.d.ts.map +1 -1
  315. package/lib/typescript/src/web/convert/utils.d.ts +2 -0
  316. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  317. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  318. package/lib/typescript/src/web/runtime.d.ts +1 -0
  319. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  320. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  321. package/metro/babel-transformer.js +1102 -0
  322. package/metro/index.d.ts +31 -0
  323. package/metro/index.js +170 -0
  324. package/package.json +50 -32
  325. package/plugin/index.d.ts +7 -0
  326. package/plugin/index.js +115 -33
  327. package/src/components/NamedTheme.tsx +5 -5
  328. package/src/components/ScopedThemeContext.ts +6 -2
  329. package/src/components/native/deep/ActivityIndicator.ts +2 -0
  330. package/src/components/native/deep/Animated.ts +2 -0
  331. package/src/components/native/deep/FlatList.ts +2 -0
  332. package/src/components/native/deep/Image.ts +2 -0
  333. package/src/components/native/deep/ImageBackground.ts +2 -0
  334. package/src/components/native/deep/KeyboardAvoidingView.ts +2 -0
  335. package/src/components/native/deep/Pressable.ts +2 -0
  336. package/src/components/native/deep/RefreshControl.ts +2 -0
  337. package/src/components/native/deep/SafeAreaView.ts +2 -0
  338. package/src/components/native/deep/ScrollView.ts +2 -0
  339. package/src/components/native/deep/SectionList.ts +2 -0
  340. package/src/components/native/deep/Switch.ts +2 -0
  341. package/src/components/native/deep/Text.ts +2 -0
  342. package/src/components/native/deep/TextInput.ts +2 -0
  343. package/src/components/native/deep/TextNativeComponent.ts +5 -0
  344. package/src/components/native/deep/TouchableHighlight.ts +2 -0
  345. package/src/components/native/deep/TouchableOpacity.ts +2 -0
  346. package/src/components/native/deep/View.ts +2 -0
  347. package/src/components/native/deep/ViewNativeComponent.ts +5 -0
  348. package/src/components/native/deep/VirtualizedList.ts +2 -0
  349. package/src/components/native/index.ts +41 -0
  350. package/src/core/createUnistylesActivityIndicator.tsx +11 -4
  351. package/src/core/createUnistylesElement.native.tsx +5 -0
  352. package/src/core/createUnistylesImageBackground.tsx +33 -25
  353. package/src/core/createUnistylesTouchableHighlight.tsx +5 -0
  354. package/src/core/getClassname.ts +10 -1
  355. package/src/core/hasUnistyles.ts +20 -0
  356. package/src/core/withUnistyles/withUnistyles.native.tsx +28 -6
  357. package/src/core/withUnistyles/withUnistyles.tsx +6 -6
  358. package/src/mocks.ts +14 -5
  359. package/src/specs/ShadowRegistry/index.ts +62 -103
  360. package/src/specs/ShadowRegistry/styleSource.ts +78 -0
  361. package/src/specs/ShadowRegistry/tracing.ts +23 -0
  362. package/src/specs/ShadowRegistry/types.ts +3 -43
  363. package/src/unifiber/LICENSE +21 -0
  364. package/src/unifiber/README.md +92 -0
  365. package/src/unifiber/src/adapters/reanimated.ts +204 -0
  366. package/src/unifiber/src/adapters/registry.ts +102 -0
  367. package/src/unifiber/src/diagnostics.ts +55 -0
  368. package/src/unifiber/src/fiber.ts +262 -0
  369. package/src/unifiber/src/host.ts +236 -0
  370. package/src/unifiber/src/index.ts +43 -0
  371. package/src/utils.ts +51 -0
  372. package/src/web/convert/index.ts +39 -3
  373. package/src/web/convert/object/backgroundLayers.ts +33 -0
  374. package/src/web/convert/object/fontVariationSettings.ts +7 -0
  375. package/src/web/convert/object/index.ts +2 -0
  376. package/src/web/convert/utils.ts +11 -0
  377. package/src/web/registry.ts +7 -8
  378. package/src/web/runtime.ts +7 -7
  379. package/src/web/utils/unistyle.ts +11 -4
  380. package/lib/commonjs/web/convert/module.d.js +0 -2
  381. package/lib/commonjs/web/convert/module.d.js.map +0 -1
  382. package/lib/module/web/convert/module.d.js +0 -2
  383. package/lib/module/web/convert/module.d.js.map +0 -1
  384. package/lib/typescript/src/__tests__/mocks.spec.d.ts +0 -2
  385. package/lib/typescript/src/__tests__/mocks.spec.d.ts.map +0 -1
  386. package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts +0 -2
  387. package/lib/typescript/src/__tests__/passForwardRef.spec.d.ts.map +0 -1
  388. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts +0 -2
  389. package/lib/typescript/src/__tests__/scoped-theme.spec.d.ts.map +0 -1
  390. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts +0 -2
  391. package/lib/typescript/src/__tests__/shadow-registry.spec.d.ts.map +0 -1
  392. package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts +0 -2
  393. package/lib/typescript/src/__tests__/web-child-selector.spec.d.ts.map +0 -1
  394. package/lib/typescript/src/__tests__/web-listener.spec.d.ts +0 -2
  395. package/lib/typescript/src/__tests__/web-listener.spec.d.ts.map +0 -1
  396. package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts +0 -2
  397. package/lib/typescript/src/__tests__/web-pointer-events.spec.d.ts.map +0 -1
  398. package/lib/typescript/src/__tests__/web-runtime.spec.d.ts +0 -2
  399. package/lib/typescript/src/__tests__/web-runtime.spec.d.ts.map +0 -1
  400. package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts +0 -2
  401. package/lib/typescript/src/__tests__/withUnistyles.spec.d.ts.map +0 -1
@@ -0,0 +1,31 @@
1
+ type MetroConfig = {
2
+ transformer?: {
3
+ babelTransformerPath?: string
4
+ }
5
+ resolver?: {
6
+ resolveRequest?: ((...args: Array<any>) => any) | null
7
+ }
8
+ }
9
+
10
+ export interface UnistylesMetroOptions {
11
+ /**
12
+ * Logs the dependencies detected in every StyleSheet, same as the `debug` option of the Babel plugin
13
+ */
14
+ debug?: boolean
15
+ }
16
+
17
+ /**
18
+ * Experimental, replaces `react-native-unistyles/plugin` in babel.config.js
19
+ *
20
+ * Every `react-native` import (also from node_modules) resolves to Unistyles components
21
+ * and StyleSheets are processed by the Unistyles Babel plugin, run by Metro.
22
+ * There is nothing to configure: no `root`, `autoProcessImports`, `autoProcessPaths` or `autoRemapImports`.
23
+ *
24
+ * ```js
25
+ * const { getDefaultConfig } = require('expo/metro-config')
26
+ * const { withUnistylesConfig } = require('react-native-unistyles/metro')
27
+ *
28
+ * module.exports = withUnistylesConfig(getDefaultConfig(__dirname))
29
+ * ```
30
+ */
31
+ export declare const withUnistylesConfig: <T extends MetroConfig>(config: T, options?: UnistylesMetroOptions) => T
package/metro/index.js ADDED
@@ -0,0 +1,170 @@
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);
29
+
30
+ // metro/src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ withUnistylesConfig: () => withUnistylesConfig
34
+ });
35
+ module.exports = __toCommonJS(index_exports);
36
+ var import_node_fs = __toESM(require("node:fs"));
37
+ var import_node_path2 = __toESM(require("node:path"));
38
+
39
+ // plugin/src/consts.ts
40
+ var REACT_NATIVE_COMPONENT_NAMES = [
41
+ "ActivityIndicator",
42
+ "View",
43
+ "Text",
44
+ "Image",
45
+ "ImageBackground",
46
+ "KeyboardAvoidingView",
47
+ "Pressable",
48
+ "ScrollView",
49
+ "FlatList",
50
+ "SectionList",
51
+ "Switch",
52
+ "TextInput",
53
+ "RefreshControl",
54
+ "TouchableHighlight",
55
+ "TouchableOpacity",
56
+ "VirtualizedList",
57
+ "Animated",
58
+ "SafeAreaView"
59
+ // Modal - there is no exposed native handle
60
+ // TouchableWithoutFeedback - can't accept a ref
61
+ ];
62
+ var METRO_UPSTREAM_TRANSFORMER_ENV = "UNISTYLES_METRO_UPSTREAM_TRANSFORMER";
63
+ var METRO_OPTIONS_ENV = "UNISTYLES_METRO_OPTIONS";
64
+
65
+ // metro/src/resolver.ts
66
+ var import_node_path = __toESM(require("node:path"));
67
+ var DEEP_IMPORTS = [...REACT_NATIVE_COMPONENT_NAMES, "ViewNativeComponent", "TextNativeComponent"];
68
+ var PASSTHROUGH_PACKAGES = ["react-native", "@react-native", "react-native-web"];
69
+ var createResolveRequest = ({ unistylesRoot, upstream, path: path2 = import_node_path.default }) => {
70
+ const { sep } = path2;
71
+ const sourceDir = path2.join(unistylesRoot, "src");
72
+ const componentsDir = path2.join(sourceDir, "components", "native");
73
+ const componentsIndex = path2.join(componentsDir, "index.ts");
74
+ const builds = [path2.join(unistylesRoot, "lib", "module"), path2.join(unistylesRoot, "lib", "commonjs")];
75
+ const getSourcePath = (filePath) => {
76
+ const build = builds.find((buildDir) => filePath.startsWith(`${buildDir}${sep}`));
77
+ if (!build) {
78
+ return void 0;
79
+ }
80
+ const modulePath = filePath.slice(build.length + 1).replace(/\.js$/, "").replace(/\.(native|ios|android|web)$/, "");
81
+ return path2.join(sourceDir, modulePath);
82
+ };
83
+ const getPackageName = (filePath) => {
84
+ const parts = filePath.split(`${sep}node_modules${sep}`);
85
+ if (parts.length === 1) {
86
+ return void 0;
87
+ }
88
+ const segments = parts.at(-1).split(sep);
89
+ return segments[0]?.startsWith("@") ? `${segments[0]}${sep}${segments[1]}` : segments[0];
90
+ };
91
+ const shouldSwapFrom = (originModulePath) => {
92
+ if (originModulePath.startsWith(`${unistylesRoot}${sep}`)) {
93
+ return false;
94
+ }
95
+ const packageName = getPackageName(originModulePath);
96
+ return !PASSTHROUGH_PACKAGES.some((name) => packageName === name || packageName?.startsWith(`${name}${sep}`));
97
+ };
98
+ const getDeepImport = (filePath) => {
99
+ const segments = filePath.split(sep);
100
+ if (segments.at(-5) === "react-native-web" && segments.at(-4) === "dist" && segments.at(-3) === "exports") {
101
+ return segments.at(-2);
102
+ }
103
+ if (filePath.includes(`${sep}react-native${sep}Libraries${sep}`)) {
104
+ return segments.at(-1)?.split(".").at(0);
105
+ }
106
+ return void 0;
107
+ };
108
+ const getSwapTarget = (moduleName, filePath) => {
109
+ if (moduleName === "react-native" || filePath.endsWith(`${sep}react-native-web${sep}dist${sep}index.js`)) {
110
+ return componentsIndex;
111
+ }
112
+ const deepImport = getDeepImport(filePath);
113
+ return deepImport && DEEP_IMPORTS.includes(deepImport) ? path2.join(componentsDir, "deep", `${deepImport}.ts`) : void 0;
114
+ };
115
+ return (context, moduleName, platform) => {
116
+ const resolve = upstream ?? context.resolveRequest;
117
+ const resolution = resolve(context, moduleName, platform);
118
+ if (resolution.type !== "sourceFile" || !("filePath" in resolution)) {
119
+ return resolution;
120
+ }
121
+ const sourcePath = getSourcePath(resolution.filePath);
122
+ if (sourcePath) {
123
+ return resolve(context, sourcePath, platform);
124
+ }
125
+ if (!shouldSwapFrom(context.originModulePath)) {
126
+ return resolution;
127
+ }
128
+ const swapTarget = getSwapTarget(moduleName, resolution.filePath);
129
+ return swapTarget ? { type: "sourceFile", filePath: swapTarget } : resolution;
130
+ };
131
+ };
132
+
133
+ // metro/src/index.ts
134
+ var withUnistylesConfig = (config, options = {}) => {
135
+ const babelTransformerPath = import_node_path2.default.join(__dirname, "babel-transformer.js");
136
+ const upstreamBabelTransformerPath = config.transformer?.babelTransformerPath;
137
+ if (upstreamBabelTransformerPath === babelTransformerPath) {
138
+ throw new Error("Unistyles \u{1F984}: withUnistylesConfig was applied twice to the same Metro config");
139
+ }
140
+ if (!upstreamBabelTransformerPath) {
141
+ throw new Error(
142
+ "Unistyles \u{1F984}: Metro config has no babelTransformerPath, pass the config returned by getDefaultConfig to withUnistylesConfig"
143
+ );
144
+ }
145
+ const unistylesOptions = {
146
+ debug: options.debug ?? false
147
+ };
148
+ process.env[METRO_UPSTREAM_TRANSFORMER_ENV] = upstreamBabelTransformerPath;
149
+ process.env[METRO_OPTIONS_ENV] = JSON.stringify(unistylesOptions);
150
+ return {
151
+ ...config,
152
+ transformer: {
153
+ ...config.transformer,
154
+ babelTransformerPath,
155
+ // part of Metro's transform cache key
156
+ unistyles: unistylesOptions
157
+ },
158
+ resolver: {
159
+ ...config.resolver,
160
+ resolveRequest: createResolveRequest({
161
+ unistylesRoot: import_node_fs.default.realpathSync(import_node_path2.default.join(__dirname, "..")),
162
+ upstream: config.resolver?.resolveRequest
163
+ })
164
+ }
165
+ };
166
+ };
167
+ // Annotate the CommonJS export names for ESM import in node:
168
+ 0 && (module.exports = {
169
+ withUnistylesConfig
170
+ });
package/package.json CHANGED
@@ -1,19 +1,20 @@
1
1
  {
2
2
  "name": "react-native-unistyles",
3
- "version": "3.5.3",
3
+ "version": "3.7.0",
4
4
  "description": "Level up your React Native StyleSheet",
5
5
  "scripts": {
6
- "test": "NODE_ENV=babel-test jest ./plugin ./src/__tests__",
6
+ "test": "NODE_ENV=babel-test jest ./plugin ./metro ./src/__tests__",
7
7
  "test:coverage": "NODE_ENV=babel-test jest --passWithNoTests --coverage",
8
8
  "tsc": "node_modules/typescript/bin/tsc --noEmit",
9
- "format": "oxfmt src plugin repack-plugin",
10
- "lint": "oxlint src plugin repack-plugin",
11
- "check": "oxfmt src plugin repack-plugin && oxlint --fix src plugin repack-plugin",
12
- "check:ci": "oxfmt --check src plugin repack-plugin && oxlint src plugin repack-plugin",
13
- "prepare": "bob build && bun run plugin:build && bun run repack:plugin:build",
9
+ "format": "oxfmt src plugin repack-plugin metro",
10
+ "lint": "oxlint src plugin repack-plugin metro",
11
+ "check": "oxfmt src plugin repack-plugin metro && oxlint --fix src plugin repack-plugin metro",
12
+ "check:ci": "oxfmt --check src plugin repack-plugin metro && oxlint src plugin repack-plugin metro",
13
+ "prepare": "bob build && bun run plugin:build && bun run repack:plugin:build && bun run metro:build",
14
14
  "precommit": "concurrently 'bun run tsc' 'bun run lint' 'bun run check' 'bun run test' 'bun run circular:check'",
15
15
  "plugin:build": "node plugin/esbuild.js",
16
16
  "repack:plugin:build": "node repack-plugin/esbuild.js",
17
+ "metro:build": "node metro/esbuild.js",
17
18
  "circular:check": "dpdm --no-warning --no-tree -T --exit-code circular:1 src/**/*.ts",
18
19
  "components:build": "node build-components.js"
19
20
  },
@@ -25,22 +26,22 @@
25
26
  "exports": {
26
27
  ".": {
27
28
  "types": "./lib/typescript/src/index.d.ts",
28
- "import": "./lib/module/index.js",
29
29
  "browser": "./lib/module/index.js",
30
30
  "react-native": "./src/index.ts",
31
+ "import": "./lib/module/index.js",
31
32
  "default": "./lib/commonjs/index.js"
32
33
  },
33
34
  "./mocks": {
34
35
  "types": "./lib/typescript/src/mocks.d.ts",
35
- "import": "./lib/module/mocks.js",
36
36
  "browser": "./lib/module/mocks.js",
37
37
  "react-native": "./src/mocks.ts",
38
+ "import": "./lib/module/mocks.js",
38
39
  "default": "./lib/commonjs/mocks.js"
39
40
  },
40
41
  "./components/native/*": {
41
- "import": "./lib/module/components/native/*",
42
42
  "browser": "./lib/module/components/native/*",
43
43
  "react-native": "./src/components/native/*",
44
+ "import": "./lib/module/components/native/*",
44
45
  "default": "./lib/commonjs/components/native/*"
45
46
  },
46
47
  "./plugin": {
@@ -53,33 +54,37 @@
53
54
  "types": "./repack-plugin/index.d.ts",
54
55
  "default": "./repack-plugin/index.js"
55
56
  },
57
+ "./metro": {
58
+ "types": "./metro/index.d.ts",
59
+ "default": "./metro/index.js"
60
+ },
56
61
  "./package.json": "./package.json",
57
62
  "./server": {
58
63
  "types": "./lib/typescript/src/server/index.d.ts",
59
- "import": "./lib/module/server/index.js",
60
64
  "browser": "./lib/module/server/index.js",
61
65
  "react-native": "./src/server/index.ts",
66
+ "import": "./lib/module/server/index.js",
62
67
  "default": "./lib/commonjs/server/index.js"
63
68
  },
64
69
  "./web": {
65
70
  "types": "./lib/typescript/src/web-only/index.d.ts",
66
- "import": "./lib/module/web-only/index.js",
67
71
  "browser": "./lib/module/web-only/index.js",
68
72
  "react-native": "./src/web-only/index.ts",
73
+ "import": "./lib/module/web-only/index.js",
69
74
  "default": "./lib/commonjs/web-only/index.js"
70
75
  },
71
76
  "./reanimated": {
72
77
  "types": "./lib/typescript/src/reanimated/index.d.ts",
73
- "import": "./lib/module/reanimated/index.js",
74
78
  "browser": "./lib/module/reanimated/index.js",
75
79
  "react-native": "./src/reanimated/index.ts",
80
+ "import": "./lib/module/reanimated/index.js",
76
81
  "default": "./lib/commonjs/reanimated/index.js"
77
82
  },
78
83
  "./diagnostics": {
79
84
  "types": "./lib/typescript/src/diagnostics/index.d.ts",
80
- "import": "./lib/module/diagnostics/index.js",
81
85
  "browser": "./lib/module/diagnostics/index.js",
82
86
  "react-native": "./src/diagnostics/index.ts",
87
+ "import": "./lib/module/diagnostics/index.js",
83
88
  "default": "./lib/commonjs/diagnostics/index.js"
84
89
  }
85
90
  },
@@ -100,6 +105,7 @@
100
105
  "react-native.config.js",
101
106
  "Unistyles.podspec",
102
107
  "repack-plugin",
108
+ "metro",
103
109
  "unistyles_get_rn_version.rb",
104
110
  "!repack-plugin/__tests__",
105
111
  "!repack-plugin/src",
@@ -107,6 +113,9 @@
107
113
  "!plugin/__tests__",
108
114
  "!plugin/src",
109
115
  "!plugin/esbuild.js",
116
+ "!metro/__tests__",
117
+ "!metro/src",
118
+ "!metro/esbuild.js",
110
119
  "!ios/build",
111
120
  "!android/build",
112
121
  "!android/gradle",
@@ -115,7 +124,13 @@
115
124
  "!android/local.properties",
116
125
  "!**/*.spec.ts",
117
126
  "!**/*.spec.tsx",
118
- "!**/.*"
127
+ "!**/__tests__",
128
+ "!**/.*",
129
+ "!src/unifiber/test",
130
+ "!src/unifiber/bench",
131
+ "!src/unifiber/package.json",
132
+ "!src/unifiber/tsconfig.json",
133
+ "!src/unifiber/bun.lock"
119
134
  ],
120
135
  "keywords": [
121
136
  "react-native",
@@ -139,31 +154,33 @@
139
154
  "@babel/types": "7.29.8"
140
155
  },
141
156
  "devDependencies": {
142
- "@callstack/repack": "5.4.0",
143
- "@commitlint/config-conventional": "21.2.3",
144
- "@react-native/normalize-colors": "0.87.1",
145
- "@rspack/core": "2.2.7",
157
+ "@callstack/repack": "5.4.2",
158
+ "@commitlint/config-conventional": "21.2.4",
159
+ "@react-native/normalize-colors": "0.88.0",
160
+ "@rspack/core": "2.2.9",
146
161
  "@types/jest": "30.0.0",
147
- "@types/react": "19.2.18",
162
+ "@types/react": "19.3.0",
148
163
  "babel-plugin-tester": "12.0.0",
149
- "commitlint": "21.2.3",
150
- "concurrently": "10.0.5",
164
+ "commitlint": "21.2.4",
165
+ "concurrently": "10.0.6",
151
166
  "dpdm": "4.3.0",
152
167
  "esbuild": "0.28.2",
153
168
  "jest": "30.5.2",
169
+ "@babel/core": "7.29.7",
154
170
  "@babel/plugin-syntax-jsx": "7.29.7",
155
- "@babel/runtime": "7.29.7",
156
- "@react-native/babel-preset": "0.87.1",
157
- "@react-native/jest-preset": "0.87.1",
171
+ "@babel/runtime": "7.29.10",
172
+ "@react-native/babel-preset": "0.88.0",
173
+ "@react-native/jest-preset": "0.88.0",
174
+ "@react-native/metro-babel-transformer": "0.88.0",
158
175
  "nitrogen": "0.37.1",
159
- "oxfmt": "0.70.0",
160
- "oxlint": "1.85.0",
161
- "react": "19.2.3",
162
- "react-native": "0.87.1",
163
- "react-native-builder-bob": "0.43.1",
176
+ "oxfmt": "0.74.0",
177
+ "oxlint": "1.89.0",
178
+ "react": "19.3.0",
179
+ "react-native": "0.88.0",
180
+ "react-native-builder-bob": "0.43.2",
164
181
  "react-native-nitro-modules": "0.37.1",
165
- "react-native-reanimated": "4.7.0",
166
- "react-native-web": "0.21.3",
182
+ "react-native-reanimated": "4.7.1",
183
+ "react-native-web": "0.21.4",
167
184
  "typescript": "6.0.3"
168
185
  },
169
186
  "peerDependencies": {
@@ -209,6 +226,7 @@
209
226
  "react-native-builder-bob": {
210
227
  "source": "src",
211
228
  "output": "lib",
229
+ "exclude": "{**/{__tests__,__fixtures__,__mocks__}/**,**/unifiber/{test,bench}/**,**/unifiber/*}",
212
230
  "targets": [
213
231
  "commonjs",
214
232
  "module",
package/plugin/index.d.ts CHANGED
@@ -44,6 +44,13 @@ export interface UnistylesPluginOptions {
44
44
  */
45
45
  root: string
46
46
 
47
+ /**
48
+ * Set by react-native-unistyles/metro, don't use it!
49
+ * Metro picks the files to process and swaps imports in its resolver,
50
+ * so `root`, `autoProcessImports`, `autoProcessPaths` and `autoRemapImports` are ignored
51
+ */
52
+ isMetro?: boolean
53
+
47
54
  /**
48
55
  * Example: ['@my-org/styles']
49
56
  * Enable this option if you want to process only files containing specific imports.
package/plugin/index.js CHANGED
@@ -91,6 +91,7 @@ var NATIVE_COMPONENTS_PATHS = {
91
91
  }
92
92
  ]
93
93
  };
94
+ var METRO_UPSTREAM_TRANSFORMER_ENV = "UNISTYLES_METRO_UPSTREAM_TRANSFORMER";
94
95
 
95
96
  // plugin/src/exotic.ts
96
97
  var t2 = __toESM(require("@babel/types"));
@@ -139,6 +140,9 @@ function addUnistylesImport(path2, state) {
139
140
  nodesToRemove.forEach((node) => path2.node.body.splice(path2.node.body.indexOf(node), 1));
140
141
  }
141
142
  function isInsideNodeModules(state) {
143
+ if (state.opts.isMetro) {
144
+ return false;
145
+ }
142
146
  return state.file.opts.filename?.includes("node_modules") && !state.file.replaceWithUnistyles;
143
147
  }
144
148
  function addUnistylesRequire(path2, state) {
@@ -351,6 +355,47 @@ function getReturnStatementsFromBody(node, results = []) {
351
355
  }
352
356
  return results;
353
357
  }
358
+ function countReturnStatements(node) {
359
+ if (t4.isFunction(node) || t4.isClass(node)) {
360
+ return 0;
361
+ }
362
+ if (t4.isReturnStatement(node)) {
363
+ return 1;
364
+ }
365
+ return (t4.VISITOR_KEYS[node.type] ?? []).reduce((count, key) => {
366
+ const child = node[key];
367
+ const children = (Array.isArray(child) ? child : [child]).filter(
368
+ (childNode) => t4.isNode(childNode)
369
+ );
370
+ return count + children.reduce((childCount, childNode) => childCount + countReturnStatements(childNode), 0);
371
+ }, 0);
372
+ }
373
+ function collectReturnedObjects(node, targets, unsupported) {
374
+ if (t4.isObjectExpression(node)) {
375
+ targets.push(node);
376
+ return;
377
+ }
378
+ if (t4.isConditionalExpression(node)) {
379
+ collectReturnedObjects(node.consequent, targets, unsupported);
380
+ collectReturnedObjects(node.alternate, targets, unsupported);
381
+ return;
382
+ }
383
+ if (t4.isLogicalExpression(node)) {
384
+ if (node.operator !== "&&") {
385
+ collectReturnedObjects(node.left, targets, unsupported);
386
+ }
387
+ collectReturnedObjects(node.right, targets, unsupported);
388
+ return;
389
+ }
390
+ if (t4.isTSAsExpression(node) || t4.isTSSatisfiesExpression(node) || t4.isParenthesizedExpression(node)) {
391
+ collectReturnedObjects(node.expression, targets, unsupported);
392
+ return;
393
+ }
394
+ if (t4.isNullLiteral(node) || t4.isBooleanLiteral(node) || t4.isIdentifier(node) && node.name === "undefined") {
395
+ return;
396
+ }
397
+ unsupported.push(node);
398
+ }
354
399
  function isUnistylesStyleSheet(path2, state) {
355
400
  const { callee } = path2.node;
356
401
  if (!t4.isMemberExpression(callee) || !t4.isIdentifier(callee.property)) {
@@ -665,42 +710,63 @@ function getStylesDependenciesFromFunction(funcPath) {
665
710
  }, {});
666
711
  }
667
712
  function addDependencies(state, styleName, unistyle, detectedDependencies) {
668
- const debugMessage = (deps) => {
713
+ const debugMessage = (deps, unsupportedReason) => {
669
714
  if (state.opts.debug) {
670
715
  const mappedDeps = deps.map(
671
716
  (dep) => Object.keys(UnistyleDependency).find(
672
717
  (key) => UnistyleDependency[key] === dep
673
718
  )
674
719
  ).join(", ");
675
- console.log(
676
- `${state.filename?.replace(`${state.file.opts.root}/`, "")}: styles.${styleName}: [${mappedDeps}]`
677
- );
720
+ const style = `${state.filename?.replace(`${state.file.opts.root}/`, "")}: styles.${styleName}`;
721
+ if (unsupportedReason) {
722
+ console.warn(
723
+ `Unistyles \u{1F984}: ${style}: detected [${mappedDeps}], but ${unsupportedReason}. Return an object literal, or a ternary/logical expression of object literals.`
724
+ );
725
+ return;
726
+ }
727
+ console.log(`${style}: [${mappedDeps}]`);
678
728
  }
679
729
  };
680
730
  const styleDependencies = detectedDependencies.map(toUnistylesDependency);
681
731
  if (styleDependencies.length > 0) {
682
732
  const uniqueDependencies = Array.from(new Set(styleDependencies));
683
- debugMessage(uniqueDependencies);
684
- let targets = [];
733
+ const targets = [];
734
+ const unsupported = [];
735
+ let unsupportedReturns = 0;
685
736
  if (t4.isArrowFunctionExpression(unistyle.value) || t4.isFunctionExpression(unistyle.value)) {
686
- if (t4.isObjectExpression(unistyle.value.body)) {
687
- targets.push(unistyle.value.body);
688
- }
689
737
  if (t4.isBlockStatement(unistyle.value.body)) {
690
- targets = getReturnStatementsFromBody(unistyle.value.body).map((node) => {
738
+ const returnStatements = getReturnStatementsFromBody(unistyle.value.body);
739
+ unsupportedReturns = countReturnStatements(unistyle.value.body) - returnStatements.length;
740
+ returnStatements.forEach((node) => {
691
741
  if (t4.isIdentifier(node.argument)) {
692
742
  node.argument = t4.objectExpression([t4.spreadElement(node.argument)]);
693
743
  }
694
- return node.argument;
695
- }).filter((node) => t4.isObjectExpression(node));
744
+ if (node.argument) {
745
+ collectReturnedObjects(node.argument, targets, unsupported);
746
+ }
747
+ });
748
+ } else {
749
+ collectReturnedObjects(unistyle.value.body, targets, unsupported);
696
750
  }
697
- }
698
- if (t4.isObjectExpression(unistyle.value)) {
699
- targets.push(unistyle.value);
700
- }
701
- if (t4.isMemberExpression(unistyle.value)) {
751
+ } else if (t4.isMemberExpression(unistyle.value)) {
702
752
  unistyle.value = t4.objectExpression([t4.spreadElement(unistyle.value)]);
703
753
  targets.push(unistyle.value);
754
+ } else {
755
+ collectReturnedObjects(unistyle.value, targets, unsupported);
756
+ }
757
+ if (unsupported.length > 0 || unsupportedReturns > 0) {
758
+ const reasons = unsupported.map((node) => `${node.type}${node.loc ? ` (line ${node.loc.start.line})` : ""}`).concat(
759
+ unsupportedReturns > 0 ? `${unsupportedReturns} return statement(s) inside switch, loop or try blocks` : []
760
+ );
761
+ const consequence = targets.length > 0 ? "the style may not update when these dependencies change, eg. when one of these values is returned first" : "the style won't update when these dependencies change";
762
+ debugMessage(uniqueDependencies, `they can't be attached to: ${reasons.join(", ")}, so ${consequence}`);
763
+ } else if (targets.length === 0) {
764
+ debugMessage(
765
+ uniqueDependencies,
766
+ "no returned object was found to attach them to, so the style won't update when these dependencies change"
767
+ );
768
+ } else {
769
+ debugMessage(uniqueDependencies);
704
770
  }
705
771
  if (targets.length > 0) {
706
772
  targets.forEach((target) => {
@@ -719,6 +785,7 @@ function addDependencies(state, styleName, unistyle, detectedDependencies) {
719
785
 
720
786
  // plugin/src/variants.ts
721
787
  var t5 = __toESM(require("@babel/types"));
788
+ var scopedVariants = /* @__PURE__ */ new WeakMap();
722
789
  function extractVariants(path2, state) {
723
790
  const maybeVariants = path2.node.body.filter(
724
791
  (node2) => t5.isExpressionStatement(node2) && t5.isCallExpression(node2.expression) && t5.isMemberExpression(node2.expression.callee)
@@ -745,22 +812,29 @@ function extractVariants(path2, state) {
745
812
  return;
746
813
  }
747
814
  const calleeName = callee.object.name;
748
- const newUniqueName = path2.scope.generateUidIdentifier(calleeName);
749
- const shadowDeclaration = t5.variableDeclaration("const", [
750
- t5.variableDeclarator(newUniqueName, t5.identifier(calleeName))
751
- ]);
815
+ const binding = path2.scope.getBinding(calleeName);
816
+ const existingShadowName = binding && t5.isVariableDeclarator(binding.path.node) ? scopedVariants.get(binding.path.node) : void 0;
817
+ const shadowName = existingShadowName ?? path2.scope.generateUidIdentifier(calleeName).name;
752
818
  const newCallExpression = t5.callExpression(
753
- t5.memberExpression(t5.identifier(newUniqueName.name), t5.identifier("useVariants")),
819
+ t5.memberExpression(t5.identifier(shadowName), t5.identifier("useVariants")),
754
820
  node.arguments
755
821
  );
756
- const finalDeclaration = t5.variableDeclaration("const", [
757
- t5.variableDeclarator(t5.identifier(calleeName), newCallExpression)
758
- ]);
822
+ const finalDeclarator = t5.variableDeclarator(t5.identifier(calleeName), newCallExpression);
823
+ const finalDeclaration = t5.variableDeclaration("const", [finalDeclarator]);
824
+ scopedVariants.set(finalDeclarator, shadowName);
759
825
  const pathIndex = path2.node.body.findIndex((bodyPath) => bodyPath === targetVariant);
760
826
  const rest = path2.node.body.slice(pathIndex + 1);
761
827
  const statement = t5.blockStatement([finalDeclaration, ...rest]);
762
- path2.node.body = [...path2.node.body.slice(0, pathIndex), shadowDeclaration, statement];
763
828
  state.file.hasVariants = true;
829
+ if (existingShadowName) {
830
+ path2.node.body = [...path2.node.body.slice(0, pathIndex), statement];
831
+ return;
832
+ }
833
+ const shadowDeclaration = t5.variableDeclaration("const", [
834
+ t5.variableDeclarator(t5.identifier(shadowName), t5.identifier(calleeName))
835
+ ]);
836
+ path2.node.body = [...path2.node.body.slice(0, pathIndex), shadowDeclaration, statement];
837
+ path2.scope.registerDeclaration(path2.get(`body.${pathIndex}`));
764
838
  }
765
839
 
766
840
  // plugin/src/index.ts
@@ -776,13 +850,18 @@ function index_default() {
776
850
  visitor: {
777
851
  Program: {
778
852
  enter(path2, state) {
779
- if (!state.opts.root) {
853
+ if (!state.opts.isMetro && process.env[METRO_UPSTREAM_TRANSFORMER_ENV]) {
854
+ throw new Error(
855
+ "Unistyles \u{1F984}: react-native-unistyles/metro is enabled in metro.config.js, remove react-native-unistyles/plugin from babel.config.js"
856
+ );
857
+ }
858
+ if (!state.opts.root && !state.opts.isMetro) {
780
859
  throw new Error(
781
860
  "Unistyles \u{1F984}: Babel plugin requires `root` option to be set. Please check https://www.unistyl.es/v3/other/babel-plugin#extra-configuration"
782
861
  );
783
862
  }
784
- const appRoot = toPlatformPath(import_node_path2.default.join(state.file.opts.root, state.opts.root));
785
- if (state.file.opts.root === appRoot) {
863
+ const appRoot = toPlatformPath(import_node_path2.default.join(state.file.opts.root, state.opts.root ?? ""));
864
+ if (!state.opts.isMetro && state.file.opts.root === appRoot) {
786
865
  throw new Error(
787
866
  "Unistyles \u{1F984}: Root option can't resolve to project root as it will include node_modules folder. Please check https://www.unistyl.es/v3/other/babel-plugin#extra-configuration"
788
867
  );
@@ -797,7 +876,7 @@ function index_default() {
797
876
  state.file.styleSheetLocalName = "";
798
877
  state.file.reactNativeCommonJSName = "";
799
878
  state.reactNativeImports = {};
800
- state.file.forceProcessing = state.filename?.includes(appRoot) ?? false;
879
+ state.file.forceProcessing = state.opts.isMetro || (state.filename?.includes(appRoot) ?? false);
801
880
  path2.traverse({
802
881
  BlockStatement(blockPath) {
803
882
  if (isInsideNodeModules(state)) {
@@ -808,7 +887,7 @@ function index_default() {
808
887
  });
809
888
  },
810
889
  exit(path2, state) {
811
- if (isInsideNodeModules(state)) {
890
+ if (state.opts.isMetro || isInsideNodeModules(state)) {
812
891
  return;
813
892
  }
814
893
  if (state.file.addUnistylesRequire) {
@@ -851,7 +930,7 @@ function index_default() {
851
930
  });
852
931
  },
853
932
  ImportDeclaration(path2, state) {
854
- const exoticImport = REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find(
933
+ const exoticImport = state.opts.isMetro ? void 0 : REPLACE_WITH_UNISTYLES_EXOTIC_PATHS.concat(state.opts.autoRemapImports ?? []).find(
855
934
  (exotic) => state.filename?.includes(exotic.path)
856
935
  );
857
936
  if (exoticImport) {
@@ -869,6 +948,9 @@ function index_default() {
869
948
  }
870
949
  });
871
950
  }
951
+ if (state.opts.isMetro) {
952
+ return;
953
+ }
872
954
  if (importSource === "react-native") {
873
955
  path2.node.specifiers.forEach((specifier) => {
874
956
  if (t6.isImportSpecifier(specifier) && t6.isIdentifier(specifier.imported) && REACT_NATIVE_COMPONENT_NAMES.includes(specifier.imported.name)) {
@@ -892,7 +974,7 @@ function index_default() {
892
974
  }
893
975
  },
894
976
  MemberExpression(path2, state) {
895
- if (isInsideNodeModules(state)) {
977
+ if (state.opts.isMetro || isInsideNodeModules(state)) {
896
978
  return;
897
979
  }
898
980
  if (!state.file.reactNativeCommonJSName || !t6.isIdentifier(path2.node.object)) {