react-native-unistyles 3.0.0-beta.1 → 3.0.0-beta.3

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 (384) hide show
  1. package/README.md +4 -4
  2. package/Unistyles.podspec +7 -1
  3. package/android/build.gradle +6 -0
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +2 -2
  5. package/components/native/ActivityIndicator/package.json +4 -0
  6. package/components/native/FlatList/package.json +4 -0
  7. package/components/native/Image/package.json +4 -0
  8. package/components/native/ImageBackground/package.json +4 -0
  9. package/components/native/KeyboardAvoidingView/package.json +4 -0
  10. package/components/native/Pressable/package.json +5 -0
  11. package/components/native/RefreshControl/package.json +4 -0
  12. package/components/native/ScrollView/package.json +4 -0
  13. package/components/native/SectionList/package.json +4 -0
  14. package/components/native/Switch/package.json +4 -0
  15. package/components/native/Text/package.json +4 -0
  16. package/components/native/TextInput/package.json +4 -0
  17. package/components/native/TouchableHighlight/package.json +4 -0
  18. package/components/native/TouchableOpacity/package.json +4 -0
  19. package/components/native/View/package.json +4 -0
  20. package/components/native/VirtualizedList/package.json +4 -0
  21. package/cxx/common/Constants.h +2 -0
  22. package/cxx/core/HostStyle.cpp +17 -7
  23. package/cxx/core/HostStyle.h +5 -0
  24. package/cxx/core/UnistyleData.h +3 -3
  25. package/cxx/core/UnistyleWrapper.h +9 -9
  26. package/cxx/core/UnistylesRegistry.cpp +23 -30
  27. package/cxx/core/UnistylesRegistry.h +8 -2
  28. package/cxx/hybridObjects/HybridShadowRegistry.cpp +117 -12
  29. package/cxx/hybridObjects/HybridShadowRegistry.h +27 -3
  30. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +4 -0
  31. package/cxx/parser/Parser.cpp +184 -26
  32. package/cxx/parser/Parser.h +3 -1
  33. package/ios/UnistylesModuleOnLoad.mm +2 -2
  34. package/lib/commonjs/components/ScopedTheme.js +36 -0
  35. package/lib/commonjs/components/ScopedTheme.js.map +1 -0
  36. package/lib/commonjs/components/Variants.js +36 -0
  37. package/lib/commonjs/components/Variants.js.map +1 -0
  38. package/lib/commonjs/components/index.js +10 -3
  39. package/lib/commonjs/components/index.js.map +1 -1
  40. package/lib/commonjs/components/native/ActivityIndicator.js +10 -0
  41. package/lib/commonjs/components/native/ActivityIndicator.js.map +1 -0
  42. package/lib/commonjs/components/native/FlatList.js +10 -0
  43. package/lib/commonjs/components/native/FlatList.js.map +1 -0
  44. package/lib/commonjs/components/native/Image.js +10 -0
  45. package/lib/commonjs/components/native/Image.js.map +1 -0
  46. package/lib/commonjs/components/native/ImageBackground.js +10 -0
  47. package/lib/commonjs/components/native/ImageBackground.js.map +1 -0
  48. package/lib/commonjs/components/native/KeyboardAvoidingView.js +10 -0
  49. package/lib/commonjs/components/native/KeyboardAvoidingView.js.map +1 -0
  50. package/lib/commonjs/components/{Pressable.web.js → native/Pressable.js} +26 -66
  51. package/lib/commonjs/components/native/Pressable.js.map +1 -0
  52. package/lib/commonjs/components/native/Pressable.native.js +51 -0
  53. package/lib/commonjs/components/native/Pressable.native.js.map +1 -0
  54. package/lib/commonjs/components/native/RefreshControl.js +10 -0
  55. package/lib/commonjs/components/native/RefreshControl.js.map +1 -0
  56. package/lib/commonjs/components/native/ScrollView.js +10 -0
  57. package/lib/commonjs/components/native/ScrollView.js.map +1 -0
  58. package/lib/commonjs/components/native/SectionList.js +10 -0
  59. package/lib/commonjs/components/native/SectionList.js.map +1 -0
  60. package/lib/commonjs/components/native/Switch.js +10 -0
  61. package/lib/commonjs/components/native/Switch.js.map +1 -0
  62. package/lib/commonjs/components/native/Text.js +10 -0
  63. package/lib/commonjs/components/native/Text.js.map +1 -0
  64. package/lib/commonjs/components/native/TextInput.js +10 -0
  65. package/lib/commonjs/components/native/TextInput.js.map +1 -0
  66. package/lib/commonjs/components/native/TouchableHighlight.js +10 -0
  67. package/lib/commonjs/components/native/TouchableHighlight.js.map +1 -0
  68. package/lib/commonjs/components/native/TouchableOpacity.js +10 -0
  69. package/lib/commonjs/components/native/TouchableOpacity.js.map +1 -0
  70. package/lib/commonjs/components/native/View.js +10 -0
  71. package/lib/commonjs/components/native/View.js.map +1 -0
  72. package/lib/commonjs/components/native/VirtualizedList.js +10 -0
  73. package/lib/commonjs/components/native/VirtualizedList.js.map +1 -0
  74. package/lib/commonjs/core/createUnistylesComponent.js +5 -68
  75. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
  76. package/lib/commonjs/core/createUnistylesElement.js +16 -0
  77. package/lib/commonjs/core/createUnistylesElement.js.map +1 -0
  78. package/lib/commonjs/core/createUnistylesImageBackground.js +27 -0
  79. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -0
  80. package/lib/commonjs/core/index.js +20 -6
  81. package/lib/commonjs/core/index.js.map +1 -1
  82. package/lib/commonjs/core/passForwardRef.js +27 -0
  83. package/lib/commonjs/core/passForwardRef.js.map +1 -0
  84. package/lib/commonjs/core/withUnistyles/index.js +13 -0
  85. package/lib/commonjs/core/withUnistyles/index.js.map +1 -0
  86. package/lib/commonjs/core/withUnistyles/types.js +8 -0
  87. package/lib/commonjs/core/withUnistyles/types.js.map +1 -0
  88. package/lib/commonjs/core/withUnistyles/useDependencies.js +85 -0
  89. package/lib/commonjs/core/withUnistyles/useDependencies.js.map +1 -0
  90. package/lib/commonjs/core/withUnistyles/withUnistyles.js +88 -0
  91. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -0
  92. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +97 -0
  93. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -0
  94. package/lib/commonjs/hooks/useMedia.js +17 -33
  95. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  96. package/lib/commonjs/hooks/useMedia.native.js +60 -0
  97. package/lib/commonjs/hooks/useMedia.native.js.map +1 -0
  98. package/lib/commonjs/index.js +52 -31
  99. package/lib/commonjs/index.js.map +1 -1
  100. package/lib/commonjs/specs/ShadowRegistry/index.js +3 -3
  101. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  102. package/lib/commonjs/specs/index.js +14 -40
  103. package/lib/commonjs/specs/index.js.map +1 -1
  104. package/lib/commonjs/specs/index.native.js +54 -0
  105. package/lib/commonjs/specs/index.native.js.map +1 -0
  106. package/lib/commonjs/web/create.js +9 -33
  107. package/lib/commonjs/web/create.js.map +1 -1
  108. package/lib/commonjs/web/index.js +15 -16
  109. package/lib/commonjs/web/index.js.map +1 -1
  110. package/lib/commonjs/web/registry.js +10 -3
  111. package/lib/commonjs/web/registry.js.map +1 -1
  112. package/lib/commonjs/web/runtime.js +3 -1
  113. package/lib/commonjs/web/runtime.js.map +1 -1
  114. package/lib/commonjs/web/shadowRegistry.js +66 -64
  115. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  116. package/lib/commonjs/web/utils/unistyle.js +4 -4
  117. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  118. package/lib/module/components/ScopedTheme.js +29 -0
  119. package/lib/module/components/ScopedTheme.js.map +1 -0
  120. package/lib/module/components/Variants.js +29 -0
  121. package/lib/module/components/Variants.js.map +1 -0
  122. package/lib/module/components/index.js +2 -1
  123. package/lib/module/components/index.js.map +1 -1
  124. package/lib/module/components/native/ActivityIndicator.js +6 -0
  125. package/lib/module/components/native/ActivityIndicator.js.map +1 -0
  126. package/lib/module/components/native/FlatList.js +6 -0
  127. package/lib/module/components/native/FlatList.js.map +1 -0
  128. package/lib/module/components/native/Image.js +6 -0
  129. package/lib/module/components/native/Image.js.map +1 -0
  130. package/lib/module/components/native/ImageBackground.js +6 -0
  131. package/lib/module/components/native/ImageBackground.js.map +1 -0
  132. package/lib/module/components/native/KeyboardAvoidingView.js +6 -0
  133. package/lib/module/components/native/KeyboardAvoidingView.js.map +1 -0
  134. package/lib/module/components/native/Pressable.js +69 -0
  135. package/lib/module/components/native/Pressable.js.map +1 -0
  136. package/lib/module/components/native/Pressable.native.js +45 -0
  137. package/lib/module/components/native/Pressable.native.js.map +1 -0
  138. package/lib/module/components/native/RefreshControl.js +6 -0
  139. package/lib/module/components/native/RefreshControl.js.map +1 -0
  140. package/lib/module/components/native/ScrollView.js +6 -0
  141. package/lib/module/components/native/ScrollView.js.map +1 -0
  142. package/lib/module/components/native/SectionList.js +6 -0
  143. package/lib/module/components/native/SectionList.js.map +1 -0
  144. package/lib/module/components/native/Switch.js +6 -0
  145. package/lib/module/components/native/Switch.js.map +1 -0
  146. package/lib/module/components/native/Text.js +6 -0
  147. package/lib/module/components/native/Text.js.map +1 -0
  148. package/lib/module/components/native/TextInput.js +6 -0
  149. package/lib/module/components/native/TextInput.js.map +1 -0
  150. package/lib/module/components/native/TouchableHighlight.js +6 -0
  151. package/lib/module/components/native/TouchableHighlight.js.map +1 -0
  152. package/lib/module/components/native/TouchableOpacity.js +6 -0
  153. package/lib/module/components/native/TouchableOpacity.js.map +1 -0
  154. package/lib/module/components/native/View.js +6 -0
  155. package/lib/module/components/native/View.js.map +1 -0
  156. package/lib/module/components/native/VirtualizedList.js +6 -0
  157. package/lib/module/components/native/VirtualizedList.js.map +1 -0
  158. package/lib/module/core/createUnistylesComponent.js +5 -66
  159. package/lib/module/core/createUnistylesComponent.js.map +1 -1
  160. package/lib/module/core/createUnistylesElement.js +10 -0
  161. package/lib/module/core/createUnistylesElement.js.map +1 -0
  162. package/lib/module/core/createUnistylesImageBackground.js +21 -0
  163. package/lib/module/core/createUnistylesImageBackground.js.map +1 -0
  164. package/lib/module/core/index.js +4 -2
  165. package/lib/module/core/index.js.map +1 -1
  166. package/lib/module/core/passForwardRef.js +22 -0
  167. package/lib/module/core/passForwardRef.js.map +1 -0
  168. package/lib/module/core/withUnistyles/index.js +4 -0
  169. package/lib/module/core/withUnistyles/index.js.map +1 -0
  170. package/lib/module/core/withUnistyles/types.js +4 -0
  171. package/lib/module/core/withUnistyles/types.js.map +1 -0
  172. package/lib/module/core/withUnistyles/useDependencies.js +79 -0
  173. package/lib/module/core/withUnistyles/useDependencies.js.map +1 -0
  174. package/lib/module/core/withUnistyles/withUnistyles.js +81 -0
  175. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -0
  176. package/lib/module/core/withUnistyles/withUnistyles.native.js +90 -0
  177. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -0
  178. package/lib/module/hooks/useMedia.js +19 -35
  179. package/lib/module/hooks/useMedia.js.map +1 -1
  180. package/lib/module/hooks/useMedia.native.js +55 -0
  181. package/lib/module/hooks/useMedia.native.js.map +1 -0
  182. package/lib/module/index.js +3 -3
  183. package/lib/module/index.js.map +1 -1
  184. package/lib/module/specs/ShadowRegistry/index.js +3 -3
  185. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  186. package/lib/module/specs/index.js +2 -8
  187. package/lib/module/specs/index.js.map +1 -1
  188. package/lib/module/specs/index.native.js +11 -0
  189. package/lib/module/specs/index.native.js.map +1 -0
  190. package/lib/module/web/create.js +10 -34
  191. package/lib/module/web/create.js.map +1 -1
  192. package/lib/module/web/index.js +4 -3
  193. package/lib/module/web/index.js.map +1 -1
  194. package/lib/module/web/registry.js +11 -4
  195. package/lib/module/web/registry.js.map +1 -1
  196. package/lib/module/web/runtime.js +3 -1
  197. package/lib/module/web/runtime.js.map +1 -1
  198. package/lib/module/web/shadowRegistry.js +64 -62
  199. package/lib/module/web/shadowRegistry.js.map +1 -1
  200. package/lib/module/web/utils/unistyle.js +2 -2
  201. package/lib/module/web/utils/unistyle.js.map +1 -1
  202. package/lib/typescript/src/components/ScopedTheme.d.ts +8 -0
  203. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -0
  204. package/lib/typescript/src/components/Variants.d.ts +7 -0
  205. package/lib/typescript/src/components/Variants.d.ts.map +1 -0
  206. package/lib/typescript/src/components/index.d.ts +2 -1
  207. package/lib/typescript/src/components/index.d.ts.map +1 -1
  208. package/lib/typescript/src/components/native/ActivityIndicator.d.ts +2 -0
  209. package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -0
  210. package/lib/typescript/src/components/native/FlatList.d.ts +2 -0
  211. package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -0
  212. package/lib/typescript/src/components/native/Image.d.ts +2 -0
  213. package/lib/typescript/src/components/native/Image.d.ts.map +1 -0
  214. package/lib/typescript/src/components/native/ImageBackground.d.ts +3 -0
  215. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -0
  216. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +2 -0
  217. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -0
  218. package/lib/typescript/src/components/{Pressable.web.d.ts → native/Pressable.d.ts} +3 -2
  219. package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -0
  220. package/lib/typescript/src/components/{Pressable.d.ts → native/Pressable.native.d.ts} +1 -3
  221. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -0
  222. package/lib/typescript/src/components/native/RefreshControl.d.ts +2 -0
  223. package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -0
  224. package/lib/typescript/src/components/native/ScrollView.d.ts +2 -0
  225. package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -0
  226. package/lib/typescript/src/components/native/SectionList.d.ts +2 -0
  227. package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -0
  228. package/lib/typescript/src/components/native/Switch.d.ts +2 -0
  229. package/lib/typescript/src/components/native/Switch.d.ts.map +1 -0
  230. package/lib/typescript/src/components/native/Text.d.ts +2 -0
  231. package/lib/typescript/src/components/native/Text.d.ts.map +1 -0
  232. package/lib/typescript/src/components/native/TextInput.d.ts +2 -0
  233. package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -0
  234. package/lib/typescript/src/components/native/TouchableHighlight.d.ts +2 -0
  235. package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -0
  236. package/lib/typescript/src/components/native/TouchableOpacity.d.ts +2 -0
  237. package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -0
  238. package/lib/typescript/src/components/native/View.d.ts +2 -0
  239. package/lib/typescript/src/components/native/View.d.ts.map +1 -0
  240. package/lib/typescript/src/components/native/VirtualizedList.d.ts +2 -0
  241. package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -0
  242. package/lib/typescript/src/core/createUnistylesComponent.d.ts +9 -3
  243. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
  244. package/lib/typescript/src/core/createUnistylesElement.d.ts +3 -0
  245. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -0
  246. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +4 -0
  247. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -0
  248. package/lib/typescript/src/core/index.d.ts +4 -2
  249. package/lib/typescript/src/core/index.d.ts.map +1 -1
  250. package/lib/typescript/src/core/passForwardRef.d.ts +3 -0
  251. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -0
  252. package/lib/typescript/src/core/withUnistyles/index.d.ts +2 -0
  253. package/lib/typescript/src/core/withUnistyles/index.d.ts.map +1 -0
  254. package/lib/typescript/src/core/withUnistyles/types.d.ts +6 -0
  255. package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -0
  256. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +13 -0
  257. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +1 -0
  258. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +11 -0
  259. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -0
  260. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +8 -0
  261. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -0
  262. package/lib/typescript/src/hooks/useMedia.d.ts +1 -1
  263. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  264. package/lib/typescript/src/hooks/useMedia.native.d.ts +6 -0
  265. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -0
  266. package/lib/typescript/src/index.d.ts +3 -3
  267. package/lib/typescript/src/index.d.ts.map +1 -1
  268. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +7 -2
  269. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  270. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +17 -0
  271. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
  272. package/lib/typescript/src/specs/index.d.ts +3 -11
  273. package/lib/typescript/src/specs/index.d.ts.map +1 -1
  274. package/lib/typescript/src/specs/index.native.d.ts +12 -0
  275. package/lib/typescript/src/specs/index.native.d.ts.map +1 -0
  276. package/lib/typescript/src/web/create.d.ts +1 -1441
  277. package/lib/typescript/src/web/create.d.ts.map +1 -1
  278. package/lib/typescript/src/web/index.d.ts +5 -1463
  279. package/lib/typescript/src/web/index.d.ts.map +1 -1
  280. package/lib/typescript/src/web/registry.d.ts +2 -3
  281. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  282. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  283. package/lib/typescript/src/web/shadowRegistry.d.ts +11 -3
  284. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  285. package/lib/typescript/src/web/utils/unistyle.d.ts +1 -2
  286. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  287. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +3 -0
  288. package/package.json +20 -4
  289. package/plugin/common.js +4 -6
  290. package/plugin/import.js +63 -26
  291. package/plugin/index.js +48 -28
  292. package/plugin/ref.js +0 -234
  293. package/plugin/style.js +4 -317
  294. package/plugin/stylesheet.js +25 -10
  295. package/plugin/variants.js +60 -1
  296. package/src/components/ScopedTheme.tsx +32 -0
  297. package/src/components/Variants.tsx +30 -0
  298. package/src/components/index.ts +2 -1
  299. package/src/components/native/ActivityIndicator.tsx +4 -0
  300. package/src/components/native/FlatList.tsx +4 -0
  301. package/src/components/native/Image.tsx +4 -0
  302. package/src/components/native/ImageBackground.tsx +4 -0
  303. package/src/components/native/KeyboardAvoidingView.tsx +4 -0
  304. package/src/components/native/Pressable.native.tsx +57 -0
  305. package/src/components/native/Pressable.tsx +98 -0
  306. package/src/components/native/RefreshControl.tsx +4 -0
  307. package/src/components/native/ScrollView.tsx +4 -0
  308. package/src/components/native/SectionList.tsx +4 -0
  309. package/src/components/native/Switch.tsx +4 -0
  310. package/src/components/native/Text.tsx +4 -0
  311. package/src/components/native/TextInput.tsx +4 -0
  312. package/src/components/native/TouchableHighlight.tsx +4 -0
  313. package/src/components/native/TouchableOpacity.tsx +4 -0
  314. package/src/components/native/View.tsx +4 -0
  315. package/src/components/native/VirtualizedList.tsx +4 -0
  316. package/src/core/createUnistylesComponent.tsx +6 -76
  317. package/src/core/createUnistylesElement.tsx +9 -0
  318. package/src/core/createUnistylesImageBackground.tsx +24 -0
  319. package/src/core/index.ts +4 -2
  320. package/src/core/passForwardRef.ts +29 -0
  321. package/src/core/withUnistyles/index.ts +1 -0
  322. package/src/core/withUnistyles/types.ts +7 -0
  323. package/src/core/withUnistyles/useDependencies.ts +98 -0
  324. package/src/core/withUnistyles/withUnistyles.native.tsx +97 -0
  325. package/src/core/withUnistyles/withUnistyles.tsx +90 -0
  326. package/src/hooks/useMedia.native.ts +65 -0
  327. package/src/hooks/useMedia.ts +19 -36
  328. package/src/index.ts +3 -3
  329. package/src/specs/ShadowRegistry/index.ts +14 -5
  330. package/src/specs/ShadowRegistry/types.ts +18 -1
  331. package/src/specs/index.native.ts +27 -0
  332. package/src/specs/index.ts +3 -27
  333. package/src/web/create.ts +11 -32
  334. package/src/web/index.ts +8 -4
  335. package/src/web/registry.ts +15 -6
  336. package/src/web/runtime.ts +3 -1
  337. package/src/web/shadowRegistry.ts +59 -51
  338. package/src/web/utils/unistyle.ts +2 -3
  339. package/lib/commonjs/components/Pressable.js +0 -74
  340. package/lib/commonjs/components/Pressable.js.map +0 -1
  341. package/lib/commonjs/components/Pressable.web.js.map +0 -1
  342. package/lib/commonjs/core/createUnistylesComponent.native.js +0 -82
  343. package/lib/commonjs/core/createUnistylesComponent.native.js.map +0 -1
  344. package/lib/commonjs/core/getBoundArgs.js +0 -18
  345. package/lib/commonjs/core/getBoundArgs.js.map +0 -1
  346. package/lib/commonjs/core/getId.js +0 -9
  347. package/lib/commonjs/core/getId.js.map +0 -1
  348. package/lib/commonjs/hooks/useMedia.web.js +0 -43
  349. package/lib/commonjs/hooks/useMedia.web.js.map +0 -1
  350. package/lib/commonjs/specs/index.web.js +0 -17
  351. package/lib/commonjs/specs/index.web.js.map +0 -1
  352. package/lib/module/components/Pressable.js +0 -68
  353. package/lib/module/components/Pressable.js.map +0 -1
  354. package/lib/module/components/Pressable.web.js +0 -109
  355. package/lib/module/components/Pressable.web.js.map +0 -1
  356. package/lib/module/core/createUnistylesComponent.native.js +0 -75
  357. package/lib/module/core/createUnistylesComponent.native.js.map +0 -1
  358. package/lib/module/core/getBoundArgs.js +0 -13
  359. package/lib/module/core/getBoundArgs.js.map +0 -1
  360. package/lib/module/core/getId.js +0 -4
  361. package/lib/module/core/getId.js.map +0 -1
  362. package/lib/module/hooks/useMedia.web.js +0 -38
  363. package/lib/module/hooks/useMedia.web.js.map +0 -1
  364. package/lib/module/specs/index.web.js +0 -4
  365. package/lib/module/specs/index.web.js.map +0 -1
  366. package/lib/typescript/src/components/Pressable.d.ts.map +0 -1
  367. package/lib/typescript/src/components/Pressable.web.d.ts.map +0 -1
  368. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +0 -8
  369. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +0 -1
  370. package/lib/typescript/src/core/getBoundArgs.d.ts +0 -2
  371. package/lib/typescript/src/core/getBoundArgs.d.ts.map +0 -1
  372. package/lib/typescript/src/core/getId.d.ts +0 -2
  373. package/lib/typescript/src/core/getId.d.ts.map +0 -1
  374. package/lib/typescript/src/hooks/useMedia.web.d.ts +0 -6
  375. package/lib/typescript/src/hooks/useMedia.web.d.ts.map +0 -1
  376. package/lib/typescript/src/specs/index.web.d.ts +0 -2
  377. package/lib/typescript/src/specs/index.web.d.ts.map +0 -1
  378. package/src/components/Pressable.tsx +0 -89
  379. package/src/components/Pressable.web.tsx +0 -129
  380. package/src/core/createUnistylesComponent.native.tsx +0 -83
  381. package/src/core/getBoundArgs.ts +0 -15
  382. package/src/core/getId.ts +0 -1
  383. package/src/hooks/useMedia.web.ts +0 -47
  384. package/src/specs/index.web.ts +0 -1
package/plugin/ref.js CHANGED
@@ -1,11 +1,3 @@
1
- function getRefProp(t, path) {
2
- return path.node.openingElement.attributes.find(attr =>
3
- t.isJSXAttribute(attr) &&
4
- t.isJSXIdentifier(attr.name, { name: 'ref' }) &&
5
- t.isJSXExpressionContainer(attr.value)
6
- )
7
- }
8
-
9
1
  function hasStringRef(t, path) {
10
2
  return path.node.openingElement.attributes.find(attr =>
11
3
  t.isJSXAttribute(attr) &&
@@ -14,232 +6,6 @@ function hasStringRef(t, path) {
14
6
  )
15
7
  }
16
8
 
17
- function arrayExpressionFromMetadata(t, metadata) {
18
- const memberExpressions = metadata
19
- .map(meta => {
20
- // possible for inline styles
21
- if (meta.members.length === 0) {
22
- return meta.inlineStyle || meta.conditionalExpression || meta.logicalExpression
23
- }
24
-
25
- const [base, ...members] = meta.members
26
-
27
- return members.reduce((object, property) => t.memberExpression(object, t.identifier(property)), t.identifier(base))
28
- })
29
-
30
- return t.arrayExpression(memberExpressions)
31
- }
32
-
33
- function arrayFromDynamicFunctionArgs(t, metadata, path) {
34
- const memberExpressions = metadata
35
- .map(meta => meta.dynamicFunction
36
- ? t.arrayExpression(meta.dynamicFunction.arguments)
37
- : t.arrayExpression([]))
38
- .filter(Boolean)
39
-
40
- return t.arrayExpression(memberExpressions)
41
- }
42
-
43
- function addRef(t, path, metadata, state) {
44
- const hasVariants = state.file.hasVariants
45
-
46
- const newRefFunction = t.arrowFunctionExpression(
47
- [t.identifier('ref')],
48
- t.blockStatement([
49
- t.expressionStatement(
50
- t.callExpression(
51
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
52
- [
53
- t.identifier('ref'),
54
- arrayExpressionFromMetadata(t, metadata),
55
- t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
56
- arrayFromDynamicFunctionArgs(t, metadata, path)
57
- ]
58
- )
59
- ),
60
- t.returnStatement(
61
- t.arrowFunctionExpression([],
62
- t.callExpression(
63
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
64
- [t.identifier('ref')]
65
- )
66
- )
67
- )
68
- ])
69
- )
70
-
71
- const newRefProp = t.jsxAttribute(
72
- t.jsxIdentifier('ref'),
73
- t.jsxExpressionContainer(newRefFunction)
74
- )
75
-
76
- path.node.openingElement.attributes.push(newRefProp)
77
- }
78
-
79
- function overrideRef(t, path, refProp, metadata, state) {
80
- const hasVariants = state.file.hasVariants
81
- const uniqueRefName = path.scope.generateUidIdentifier('ref').name
82
- const isIdentifier = t.isIdentifier(refProp.value.expression)
83
- const binding = path.scope.getBinding(refProp.value.expression.name)
84
-
85
- // ref={ref}
86
- if (isIdentifier && binding && t.isCallExpression(binding.path.node.init)) {
87
- const userVariableName = refProp.value.expression.name
88
- const newRefFunction = t.arrowFunctionExpression(
89
- [t.identifier(uniqueRefName)],
90
- t.blockStatement([
91
- t.expressionStatement(
92
- t.assignmentExpression(
93
- '=',
94
- t.memberExpression(t.identifier(userVariableName), t.identifier('current')),
95
- t.identifier(uniqueRefName)
96
- )
97
- ),
98
- t.expressionStatement(
99
- t.callExpression(
100
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
101
- [
102
- t.identifier(uniqueRefName),
103
- arrayExpressionFromMetadata(t, metadata),
104
- t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
105
- arrayFromDynamicFunctionArgs(t, metadata, path)
106
- ]
107
- )
108
- ),
109
- t.returnStatement(
110
- t.arrowFunctionExpression([],
111
- t.callExpression(
112
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
113
- [
114
- t.identifier(uniqueRefName)
115
- ]
116
- )
117
- )
118
- )
119
- ])
120
- )
121
-
122
- refProp.value = t.jsxExpressionContainer(newRefFunction)
123
-
124
- return
125
- }
126
-
127
- // ref={ref => { }}
128
- if (t.isArrowFunctionExpression(refProp.value.expression)) {
129
- const userArrowFunction = refProp.value.expression
130
- const userStatements = userArrowFunction.body.body
131
- const userReturnStatement = userStatements.find(statement => t.isReturnStatement(statement))
132
- const userCleanupFunction = userReturnStatement
133
- ? userReturnStatement.argument
134
- : null
135
- const userRefName = refProp.value.expression.params.length >= 1
136
- ? refProp.value.expression.params.at(0).name
137
- : 'ref'
138
-
139
- const newRefFunction = t.arrowFunctionExpression(
140
- [t.identifier(userRefName)],
141
- t.blockStatement([
142
- ...userStatements.filter(statement => !t.isReturnStatement(statement)),
143
- t.expressionStatement(
144
- t.callExpression(
145
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
146
- [
147
- t.identifier(userRefName),
148
- arrayExpressionFromMetadata(t, metadata),
149
- t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
150
- arrayFromDynamicFunctionArgs(t, metadata, path)
151
- ]
152
- )
153
- ),
154
- // Merged cleanup function
155
- t.returnStatement(
156
- t.arrowFunctionExpression([], t.blockStatement([
157
- ...(userCleanupFunction ? [
158
- t.expressionStatement(
159
- t.callExpression(userCleanupFunction, [])
160
- )
161
- ] : []),
162
- t.expressionStatement(
163
- t.callExpression(
164
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
165
- [
166
- t.identifier(userRefName)
167
- ]
168
- )
169
- )
170
- ]))
171
- )
172
- ])
173
- )
174
-
175
- refProp.value = t.jsxExpressionContainer(newRefFunction)
176
-
177
- return
178
- }
179
-
180
- if (!binding) {
181
- return
182
- }
183
-
184
- // ref={scopedFunction}
185
- const isArrowFunction = t.isArrowFunctionExpression(binding.path.node.init)
186
- const isFunction = t.isFunctionDeclaration(binding.path.node)
187
-
188
- if (!isArrowFunction && !isFunction) {
189
- return
190
- }
191
-
192
- const userFunctionName = refProp.value.expression
193
- const userFunction = isArrowFunction
194
- ? binding.path.node.init
195
- : binding.path.node
196
- const returnStatement = userFunction.body.body.find(statement => t.isReturnStatement(statement));
197
- const userCleanupFunction = returnStatement ? returnStatement.argument : null;
198
-
199
- const newRefFunction = t.arrowFunctionExpression(
200
- [t.identifier(uniqueRefName)],
201
- t.blockStatement([
202
- t.expressionStatement(
203
- t.callExpression(userFunctionName, [t.identifier(uniqueRefName)])
204
- ),
205
- t.expressionStatement(
206
- t.callExpression(
207
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
208
- [
209
- t.identifier(uniqueRefName),
210
- arrayExpressionFromMetadata(t, metadata),
211
- t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
212
- arrayFromDynamicFunctionArgs(t, metadata, path)
213
- ]
214
- )
215
- ),
216
- t.returnStatement(
217
- t.arrowFunctionExpression([], t.blockStatement([
218
- ...(userCleanupFunction ? [
219
- t.expressionStatement(
220
- t.callExpression(userCleanupFunction, [])
221
- )
222
- ] : []),
223
- t.expressionStatement(
224
- t.callExpression(
225
- t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
226
- [
227
- t.identifier(uniqueRefName)
228
- ]
229
- )
230
- )
231
- ].filter(Boolean)))
232
- )
233
- ])
234
- )
235
-
236
- refProp.value = t.jsxExpressionContainer(newRefFunction)
237
- userFunction.body.body = userFunction.body.body.filter(statement => !t.isReturnStatement(statement))
238
- }
239
-
240
9
  module.exports = {
241
- getRefProp,
242
- addRef,
243
- overrideRef,
244
10
  hasStringRef
245
11
  }
package/plugin/style.js CHANGED
@@ -141,224 +141,6 @@ function styleAttributeToArray(t, path) {
141
141
  styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
142
142
  }
143
143
 
144
- function metadataToRawStyle(t, metadata, styleExpression) {
145
- const expressions = []
146
-
147
- metadata.forEach(meta => {
148
- if (meta.inlineStyle) {
149
- return meta.inlineStyle.properties.forEach(prop => {
150
- if (t.isObjectProperty(prop)) {
151
- expressions.push(t.objectExpression([prop]))
152
- }
153
- })
154
- }
155
-
156
- if (meta.members.length > 0) {
157
- return expressions.push(t.memberExpression(...meta.members.map(member => t.identifier(member))))
158
- }
159
-
160
- if (meta.logicalExpression) {
161
- const expression = t.cloneNode(meta.logicalExpression)
162
-
163
- if (t.isIdentifier(expression.left)) {
164
- if (t.isCallExpression(expression.right)) {
165
- expression.right = expression.right.callee
166
- }
167
-
168
- expressions.push(expression)
169
- }
170
- }
171
-
172
- if (meta.conditionalExpression) {
173
- const expression = t.cloneNode(meta.conditionalExpression)
174
-
175
- if (t.isCallExpression(expression.alternate)) {
176
- expression.alternate = expression.alternate.callee
177
- }
178
-
179
- if (t.isCallExpression(expression.consequent)) {
180
- expression.consequent = expression.consequent.callee
181
- }
182
-
183
- expressions.push(expression)
184
- }
185
- })
186
-
187
- if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 1) {
188
- return t.jsxAttribute(
189
- t.jsxIdentifier('rawStyle'),
190
- t.jsxExpressionContainer(
191
- t.arrowFunctionExpression(styleExpression.params, t.arrayExpression([
192
- ...expressions
193
- ])
194
- ))
195
- )
196
- }
197
-
198
- return t.jsxAttribute(
199
- t.jsxIdentifier('rawStyle'),
200
- t.jsxExpressionContainer(t.arrayExpression([
201
- ...expressions
202
- ]))
203
- )
204
- }
205
-
206
- function wrapInGetBoundArgs(t, toWrap, extraArgs) {
207
- const expression = t.callExpression(
208
- t.identifier('getBoundArgs'),
209
- [toWrap]
210
- )
211
-
212
- return t.callExpression(
213
- t.memberExpression(expression, t.identifier('bind')),
214
- [t.identifier('undefined'), ...extraArgs].filter(Boolean)
215
- )
216
- }
217
-
218
- function handlePressableFromMemberExpression(t, path, metadata, wrapInArrowFunction) {
219
- let expression = undefined
220
- let args = []
221
-
222
- const members = metadata.at(0).members
223
-
224
- if (members) {
225
- expression = members.slice(1).reduce(
226
- (acc, property) => t.memberExpression(acc, t.identifier(property)),
227
- t.identifier(members[0]))
228
- }
229
-
230
- if (t.isMemberExpression(metadata.at(0))) {
231
- expression = metadata.at(0)
232
- }
233
-
234
- if (t.isCallExpression(metadata.at(0))) {
235
- expression = metadata.at(0).callee
236
- args = metadata.at(0).arguments
237
- }
238
-
239
- if (!expression) {
240
- return
241
- }
242
-
243
- const bindCall = wrapInGetBoundArgs(t , expression, wrapInArrowFunction ? [t.identifier("state")] : args)
244
-
245
- if (t.isCallExpression(metadata.at(0))) {
246
- return bindCall
247
- }
248
-
249
- if (!wrapInArrowFunction) {
250
- return t.conditionalExpression(
251
- t.binaryExpression(
252
- "===",
253
- t.unaryExpression(
254
- "typeof",
255
- expression
256
- ),
257
- t.stringLiteral("function")
258
- ),
259
- bindCall,
260
- expression
261
- )
262
- }
263
-
264
- // state => typeof style.pressable === 'function'
265
- // ? getBoundArgs(style.pressable).bind(undefined, state)
266
- // : style.pressable
267
- return t.arrowFunctionExpression(
268
- [t.identifier("state")],
269
- t.conditionalExpression(
270
- t.binaryExpression(
271
- "===",
272
- t.unaryExpression(
273
- "typeof",
274
- expression
275
- ),
276
- t.stringLiteral("function")
277
- ),
278
- bindCall,
279
- expression
280
- )
281
- )
282
- }
283
-
284
- function handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index) {
285
- if (t.isObjectExpression(wrapper)) {
286
- return
287
- }
288
-
289
- if (t.isMemberExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
290
- parentWrapper.elements[index] = handlePressableFromMemberExpression(t, path, [metadata[index]])
291
-
292
- return
293
- }
294
-
295
- if (t.isMemberExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
296
- parentWrapper = handlePressableFromMemberExpression(t, path, metadata)
297
-
298
- return
299
- }
300
-
301
- if (t.isLogicalExpression(wrapper)) {
302
- if (t.isIdentifier(wrapper.left) && t.isMemberExpression(wrapper.right)) {
303
- parentWrapper.elements[index].right = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].right])
304
-
305
- return
306
- }
307
-
308
- return
309
- }
310
-
311
- if (t.isConditionalExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
312
- if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
313
- parentWrapper.elements[index].alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].alternate])
314
- }
315
-
316
- if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
317
- parentWrapper.elements[index].consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.elements[index].consequent])
318
- }
319
-
320
- return
321
- }
322
-
323
- if (t.isConditionalExpression(wrapper) && !t.isArrayExpression(parentWrapper)) {
324
- if (t.isMemberExpression(wrapper.alternate) || t.isCallExpression(wrapper.alternate)) {
325
- parentWrapper.alternate = handlePressableFromMemberExpression(t, path, [parentWrapper.alternate])
326
- }
327
-
328
- if (t.isMemberExpression(wrapper.consequent) || t.isCallExpression(wrapper.consequent)) {
329
- parentWrapper.consequent = handlePressableFromMemberExpression(t, path, [parentWrapper.consequent])
330
- }
331
-
332
- return
333
- }
334
-
335
- const pressableArgs = t.isCallExpression(wrapper)
336
- ? wrapper.arguments
337
- : wrapper.argument.arguments
338
- const callee = t.isCallExpression(wrapper)
339
- ? wrapper.callee
340
- : wrapper.argument.callee
341
-
342
- const getBoundArgsCall = t.callExpression(
343
- t.identifier('getBoundArgs'),
344
- [callee]
345
- )
346
- const bindCall = t.callExpression(
347
- t.memberExpression(getBoundArgsCall, t.identifier('bind')),
348
- [t.identifier('undefined'), ...pressableArgs]
349
- )
350
-
351
- if (t.isCallExpression(wrapper) && t.isArrayExpression(parentWrapper)) {
352
- parentWrapper.elements[index] = bindCall
353
-
354
- return
355
- }
356
-
357
- if (t.isCallExpression(wrapper)) {
358
- styleExpression.body = bindCall
359
- }
360
- }
361
-
362
144
  function handlePressable(t, path, styleAttr, metadata, state) {
363
145
  // add variants
364
146
  if (state.file.hasVariants) {
@@ -370,106 +152,11 @@ function handlePressable(t, path, styleAttr, metadata, state) {
370
152
  path.node.openingElement.attributes.push(variants)
371
153
  }
372
154
 
373
- // add raw C++ style as prop to be bound
374
- path.node.openingElement.attributes.push(metadataToRawStyle(t, metadata, styleAttr.value.expression))
375
-
376
- const styleExpression = styleAttr.value.expression
377
-
378
- // {style.pressable}
379
- if (t.isMemberExpression(styleExpression)) {
380
- styleAttr.value.expression = handlePressableFromMemberExpression(t, path, metadata, true)
381
-
382
- return
383
- }
384
-
385
- // {style.pressable(1, 2)}
386
- if (t.isCallExpression(styleExpression)) {
387
- // user already called dynamic function
388
- const expression = t.callExpression(
389
- t.identifier('getBoundArgs'),
390
- [styleExpression.callee]
391
- )
392
- const bindCall = t.callExpression(
393
- t.memberExpression(expression, t.identifier('bind')),
394
- [t.identifier('undefined'), ...styleExpression.arguments]
395
- )
396
-
397
- path.node.openingElement.attributes = path.node.openingElement.attributes.map(attribute => {
398
- if (attribute.name.name === "style") {
399
- attribute.value.expression = t.arrowFunctionExpression([], bindCall)
400
- }
401
-
402
- return attribute
403
- })
404
-
405
- return
406
- }
407
-
408
- // {() => style.pressable(1, 2)}
409
- if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length === 0) {
410
- let parentWrapper = t.isBlockStatement(styleExpression.body)
411
- ? styleExpression.body.body.find(node => t.isReturnStatement(node))
412
- : styleExpression.body
413
-
414
- if (t.isMemberExpression(parentWrapper)) {
415
- return
416
- }
417
-
418
- if (t.isArrayExpression(parentWrapper)) {
419
- return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
420
- }
421
-
422
- if (t.isReturnStatement(parentWrapper)) {
423
- parentWrapper = parentWrapper.argument
424
-
425
- return handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
426
- }
427
-
428
- const pressableArgs = t.isCallExpression(parentWrapper)
429
- ? parentWrapper.arguments
430
- : parentWrapper.argument.arguments
431
- const callee = t.isCallExpression(parentWrapper)
432
- ? parentWrapper.callee
433
- : parentWrapper.argument.callee
434
- const getBoundArgsCall = t.callExpression(
435
- t.identifier('getBoundArgs'),
436
- [callee]
437
- )
438
- const bindCall = t.callExpression(
439
- t.memberExpression(getBoundArgsCall, t.identifier('bind')),
440
- [t.identifier('undefined'), ...pressableArgs]
441
- )
442
-
443
- if (t.isCallExpression(parentWrapper)) {
444
- styleExpression.body = bindCall
445
-
446
- return
447
- }
448
-
449
- if (parentWrapper) {
450
- parentWrapper.argument = bindCall
451
- }
452
-
453
- return
454
- }
455
-
456
- // {state => style.pressable(state, 1, 2)}
457
- if (t.isArrowFunctionExpression(styleExpression) && styleExpression.params.length > 0) {
458
- // user used state with custom args we need to getBoundArgs
459
- // detect between arrow function with body and arrow function
460
- let parentWrapper = t.isBlockStatement(styleExpression.body)
461
- ? styleExpression.body.body.find(node => t.isReturnStatement(node))
462
- : styleExpression.body
463
-
464
- if (t.isArrayExpression(parentWrapper)) {
465
- return parentWrapper.elements.forEach((wrapper, index) => handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, wrapper, index))
466
- }
467
-
468
- if (t.isReturnStatement(parentWrapper)) {
469
- parentWrapper = parentWrapper.argument
470
- }
155
+ // to add import
156
+ state.file.hasAnyUnistyle = true
471
157
 
472
- handlePressableArgs(t, path, styleExpression, metadata, parentWrapper, parentWrapper)
158
+ if (t.isMemberExpression(styleAttr.value.expression)) {
159
+ // styleAttr.value.expression = handlePressableFromMemberExpression(t, path, metadata, true)
473
160
  }
474
161
  }
475
162
 
@@ -168,30 +168,45 @@ function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
168
168
  }
169
169
  }
170
170
 
171
- function getUnistyle(t, property) {
171
+ function getUnistyles(t, property) {
172
172
  const propertyValue = t.isArrowFunctionExpression(property.value)
173
173
  ? property.value.body
174
174
  : property.value
175
175
 
176
176
  if (t.isObjectExpression(propertyValue)) {
177
- return propertyValue
177
+ return [propertyValue]
178
178
  }
179
179
 
180
180
  if (t.isBlockStatement(propertyValue)) {
181
- const returnStatement = propertyValue.body
182
- .find(value => t.isReturnStatement(value))
183
-
184
- return returnStatement
185
- ? returnStatement.argument
186
- : null
181
+ // here we might have single return statement
182
+ // or if-else statements with return statements
183
+ return propertyValue.body
184
+ .flatMap(value => {
185
+ if (t.isReturnStatement(value)) {
186
+ return [value]
187
+ }
188
+
189
+ if (!t.isIfStatement(value)) {
190
+ return []
191
+ }
192
+
193
+ return [value.consequent, value.alternate]
194
+ .filter(Boolean)
195
+ .flatMap(value => {
196
+ if (t.isBlockStatement(value)) {
197
+ return value.body.filter(t.isReturnStatement)
198
+ }
199
+ })
200
+ })
201
+ .map(value => value.argument)
187
202
  }
188
203
 
189
- return null
204
+ return []
190
205
  }
191
206
 
192
207
  module.exports = {
193
208
  isUnistylesStyleSheet,
194
209
  analyzeDependencies,
195
210
  addStyleSheetTag,
196
- getUnistyle
211
+ getUnistyles
197
212
  }
@@ -27,7 +27,66 @@ function extractVariants(t, path, state) {
27
27
  state.file.hasVariants = true
28
28
  }
29
29
 
30
+ function wrapVariants(t, path) {
31
+ const wrapperElement = t.jsxElement(
32
+ t.jsxOpeningElement(
33
+ t.jsxIdentifier('Variants'),
34
+ [
35
+ t.jsxAttribute(
36
+ t.jsxIdentifier('variants'),
37
+ t.jsxExpressionContainer(t.identifier('__uni__variants'))
38
+ ),
39
+ ],
40
+ false
41
+ ),
42
+ t.jsxClosingElement(t.jsxIdentifier('Variants')),
43
+ []
44
+ )
45
+
46
+ const element = path.openingElement && path.openingElement.name
47
+ const isWrappedInRegularFragment = t.isJSXFragment(path)
48
+ const isWrappedInFragment = (t.isJSXMemberExpression(element) && element.object.name === 'React' && element.property.name === 'Fragment') || (t.isJSXIdentifier(element) && element.name === 'Fragment')
49
+
50
+ wrapperElement.children = (isWrappedInRegularFragment || isWrappedInFragment)
51
+ ? path.children
52
+ : [path]
53
+
54
+ // copy Fragment props like key
55
+ if (isWrappedInFragment) {
56
+ wrapperElement.openingElement.attributes.push(...path.openingElement.attributes)
57
+ }
58
+
59
+ return wrapperElement
60
+ }
61
+
62
+ function addJSXVariants(t, path) {
63
+ if (!t.isReturnStatement(path.node)) {
64
+ return
65
+ }
66
+
67
+ const jsxElement = path.node.argument
68
+
69
+ if (t.isConditionalExpression(jsxElement)) {
70
+ const ifStatement = t.ifStatement(
71
+ jsxElement.test,
72
+ t.blockStatement([t.returnStatement(jsxElement.consequent)]),
73
+ t.blockStatement([t.returnStatement(jsxElement.alternate)])
74
+ )
75
+
76
+ path.replaceWith(ifStatement)
77
+
78
+ return
79
+ }
80
+
81
+ if (!t.isJSXElement(jsxElement) && !t.isJSXFragment(jsxElement)) {
82
+ return
83
+ }
84
+
85
+ path.get('argument').replaceWith(wrapVariants(t, jsxElement));
86
+ }
87
+
30
88
  module.exports = {
31
89
  isUsingVariants,
32
- extractVariants
90
+ extractVariants,
91
+ addJSXVariants
33
92
  }