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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (367) hide show
  1. package/README.md +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/cxx/common/Constants.h +2 -0
  6. package/cxx/core/HostStyle.cpp +12 -7
  7. package/cxx/core/HostStyle.h +5 -0
  8. package/cxx/core/UnistyleData.h +3 -3
  9. package/cxx/core/UnistyleWrapper.h +8 -8
  10. package/cxx/core/UnistylesRegistry.cpp +23 -30
  11. package/cxx/core/UnistylesRegistry.h +8 -2
  12. package/cxx/hybridObjects/HybridShadowRegistry.cpp +108 -12
  13. package/cxx/hybridObjects/HybridShadowRegistry.h +21 -2
  14. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +4 -0
  15. package/cxx/parser/Parser.cpp +182 -26
  16. package/cxx/parser/Parser.h +3 -1
  17. package/ios/UnistylesModuleOnLoad.mm +2 -2
  18. package/lib/commonjs/components/ScopedTheme.js +36 -0
  19. package/lib/commonjs/components/ScopedTheme.js.map +1 -0
  20. package/lib/commonjs/components/Variants.js +33 -0
  21. package/lib/commonjs/components/Variants.js.map +1 -0
  22. package/lib/commonjs/components/index.js +10 -3
  23. package/lib/commonjs/components/index.js.map +1 -1
  24. package/lib/commonjs/components/native/ActivityIndicator.js +10 -0
  25. package/lib/commonjs/components/native/ActivityIndicator.js.map +1 -0
  26. package/lib/commonjs/components/native/FlatList.js +10 -0
  27. package/lib/commonjs/components/native/FlatList.js.map +1 -0
  28. package/lib/commonjs/components/native/Image.js +10 -0
  29. package/lib/commonjs/components/native/Image.js.map +1 -0
  30. package/lib/commonjs/components/native/ImageBackground.js +10 -0
  31. package/lib/commonjs/components/native/ImageBackground.js.map +1 -0
  32. package/lib/commonjs/components/native/KeyboardAvoidingView.js +10 -0
  33. package/lib/commonjs/components/native/KeyboardAvoidingView.js.map +1 -0
  34. package/lib/commonjs/components/{Pressable.web.js → native/Pressable.js} +26 -66
  35. package/lib/commonjs/components/native/Pressable.js.map +1 -0
  36. package/lib/commonjs/components/native/Pressable.native.js +48 -0
  37. package/lib/commonjs/components/native/Pressable.native.js.map +1 -0
  38. package/lib/commonjs/components/native/RefreshControl.js +10 -0
  39. package/lib/commonjs/components/native/RefreshControl.js.map +1 -0
  40. package/lib/commonjs/components/native/ScrollView.js +10 -0
  41. package/lib/commonjs/components/native/ScrollView.js.map +1 -0
  42. package/lib/commonjs/components/native/SectionList.js +10 -0
  43. package/lib/commonjs/components/native/SectionList.js.map +1 -0
  44. package/lib/commonjs/components/native/Switch.js +10 -0
  45. package/lib/commonjs/components/native/Switch.js.map +1 -0
  46. package/lib/commonjs/components/native/Text.js +10 -0
  47. package/lib/commonjs/components/native/Text.js.map +1 -0
  48. package/lib/commonjs/components/native/TextInput.js +10 -0
  49. package/lib/commonjs/components/native/TextInput.js.map +1 -0
  50. package/lib/commonjs/components/native/TouchableHighlight.js +10 -0
  51. package/lib/commonjs/components/native/TouchableHighlight.js.map +1 -0
  52. package/lib/commonjs/components/native/TouchableOpacity.js +10 -0
  53. package/lib/commonjs/components/native/TouchableOpacity.js.map +1 -0
  54. package/lib/commonjs/components/native/View.js +10 -0
  55. package/lib/commonjs/components/native/View.js.map +1 -0
  56. package/lib/commonjs/components/native/VirtualizedList.js +10 -0
  57. package/lib/commonjs/components/native/VirtualizedList.js.map +1 -0
  58. package/lib/commonjs/core/createUnistylesComponent.js +5 -68
  59. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -1
  60. package/lib/commonjs/core/createUnistylesElement.js +16 -0
  61. package/lib/commonjs/core/createUnistylesElement.js.map +1 -0
  62. package/lib/commonjs/core/createUnistylesImageBackground.js +27 -0
  63. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -0
  64. package/lib/commonjs/core/index.js +20 -6
  65. package/lib/commonjs/core/index.js.map +1 -1
  66. package/lib/commonjs/core/passForwardRef.js +27 -0
  67. package/lib/commonjs/core/passForwardRef.js.map +1 -0
  68. package/lib/commonjs/core/withUnistyles/index.js +13 -0
  69. package/lib/commonjs/core/withUnistyles/index.js.map +1 -0
  70. package/lib/commonjs/core/withUnistyles/types.js +8 -0
  71. package/lib/commonjs/core/withUnistyles/types.js.map +1 -0
  72. package/lib/commonjs/core/withUnistyles/useDependencies.js +81 -0
  73. package/lib/commonjs/core/withUnistyles/useDependencies.js.map +1 -0
  74. package/lib/commonjs/core/withUnistyles/withUnistyles.js +88 -0
  75. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -0
  76. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +96 -0
  77. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -0
  78. package/lib/commonjs/hooks/useMedia.js +17 -33
  79. package/lib/commonjs/hooks/useMedia.js.map +1 -1
  80. package/lib/commonjs/hooks/useMedia.native.js +60 -0
  81. package/lib/commonjs/hooks/useMedia.native.js.map +1 -0
  82. package/lib/commonjs/index.js +33 -16
  83. package/lib/commonjs/index.js.map +1 -1
  84. package/lib/commonjs/specs/ShadowRegistry/index.js +3 -3
  85. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  86. package/lib/commonjs/specs/index.js +14 -40
  87. package/lib/commonjs/specs/index.js.map +1 -1
  88. package/lib/commonjs/specs/index.native.js +54 -0
  89. package/lib/commonjs/specs/index.native.js.map +1 -0
  90. package/lib/commonjs/web/create.js +12 -33
  91. package/lib/commonjs/web/create.js.map +1 -1
  92. package/lib/commonjs/web/index.js.map +1 -1
  93. package/lib/commonjs/web/registry.js +10 -3
  94. package/lib/commonjs/web/registry.js.map +1 -1
  95. package/lib/commonjs/web/runtime.js +3 -1
  96. package/lib/commonjs/web/runtime.js.map +1 -1
  97. package/lib/commonjs/web/shadowRegistry.js +71 -64
  98. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  99. package/lib/commonjs/web/utils/unistyle.js +3 -3
  100. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  101. package/lib/module/components/ScopedTheme.js +29 -0
  102. package/lib/module/components/ScopedTheme.js.map +1 -0
  103. package/lib/module/components/Variants.js +26 -0
  104. package/lib/module/components/Variants.js.map +1 -0
  105. package/lib/module/components/index.js +2 -1
  106. package/lib/module/components/index.js.map +1 -1
  107. package/lib/module/components/native/ActivityIndicator.js +6 -0
  108. package/lib/module/components/native/ActivityIndicator.js.map +1 -0
  109. package/lib/module/components/native/FlatList.js +6 -0
  110. package/lib/module/components/native/FlatList.js.map +1 -0
  111. package/lib/module/components/native/Image.js +6 -0
  112. package/lib/module/components/native/Image.js.map +1 -0
  113. package/lib/module/components/native/ImageBackground.js +6 -0
  114. package/lib/module/components/native/ImageBackground.js.map +1 -0
  115. package/lib/module/components/native/KeyboardAvoidingView.js +6 -0
  116. package/lib/module/components/native/KeyboardAvoidingView.js.map +1 -0
  117. package/lib/module/components/native/Pressable.js +69 -0
  118. package/lib/module/components/native/Pressable.js.map +1 -0
  119. package/lib/module/components/native/Pressable.native.js +42 -0
  120. package/lib/module/components/native/Pressable.native.js.map +1 -0
  121. package/lib/module/components/native/RefreshControl.js +6 -0
  122. package/lib/module/components/native/RefreshControl.js.map +1 -0
  123. package/lib/module/components/native/ScrollView.js +6 -0
  124. package/lib/module/components/native/ScrollView.js.map +1 -0
  125. package/lib/module/components/native/SectionList.js +6 -0
  126. package/lib/module/components/native/SectionList.js.map +1 -0
  127. package/lib/module/components/native/Switch.js +6 -0
  128. package/lib/module/components/native/Switch.js.map +1 -0
  129. package/lib/module/components/native/Text.js +6 -0
  130. package/lib/module/components/native/Text.js.map +1 -0
  131. package/lib/module/components/native/TextInput.js +6 -0
  132. package/lib/module/components/native/TextInput.js.map +1 -0
  133. package/lib/module/components/native/TouchableHighlight.js +6 -0
  134. package/lib/module/components/native/TouchableHighlight.js.map +1 -0
  135. package/lib/module/components/native/TouchableOpacity.js +6 -0
  136. package/lib/module/components/native/TouchableOpacity.js.map +1 -0
  137. package/lib/module/components/native/View.js +6 -0
  138. package/lib/module/components/native/View.js.map +1 -0
  139. package/lib/module/components/native/VirtualizedList.js +6 -0
  140. package/lib/module/components/native/VirtualizedList.js.map +1 -0
  141. package/lib/module/core/createUnistylesComponent.js +5 -66
  142. package/lib/module/core/createUnistylesComponent.js.map +1 -1
  143. package/lib/module/core/createUnistylesElement.js +10 -0
  144. package/lib/module/core/createUnistylesElement.js.map +1 -0
  145. package/lib/module/core/createUnistylesImageBackground.js +21 -0
  146. package/lib/module/core/createUnistylesImageBackground.js.map +1 -0
  147. package/lib/module/core/index.js +4 -2
  148. package/lib/module/core/index.js.map +1 -1
  149. package/lib/module/core/passForwardRef.js +22 -0
  150. package/lib/module/core/passForwardRef.js.map +1 -0
  151. package/lib/module/core/withUnistyles/index.js +4 -0
  152. package/lib/module/core/withUnistyles/index.js.map +1 -0
  153. package/lib/module/core/withUnistyles/types.js +4 -0
  154. package/lib/module/core/withUnistyles/types.js.map +1 -0
  155. package/lib/module/core/withUnistyles/useDependencies.js +75 -0
  156. package/lib/module/core/withUnistyles/useDependencies.js.map +1 -0
  157. package/lib/module/core/withUnistyles/withUnistyles.js +81 -0
  158. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -0
  159. package/lib/module/core/withUnistyles/withUnistyles.native.js +89 -0
  160. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -0
  161. package/lib/module/hooks/useMedia.js +19 -35
  162. package/lib/module/hooks/useMedia.js.map +1 -1
  163. package/lib/module/hooks/useMedia.native.js +55 -0
  164. package/lib/module/hooks/useMedia.native.js.map +1 -0
  165. package/lib/module/index.js +2 -2
  166. package/lib/module/index.js.map +1 -1
  167. package/lib/module/specs/ShadowRegistry/index.js +3 -3
  168. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  169. package/lib/module/specs/index.js +2 -8
  170. package/lib/module/specs/index.js.map +1 -1
  171. package/lib/module/specs/index.native.js +11 -0
  172. package/lib/module/specs/index.native.js.map +1 -0
  173. package/lib/module/web/create.js +13 -34
  174. package/lib/module/web/create.js.map +1 -1
  175. package/lib/module/web/index.js +1 -1
  176. package/lib/module/web/index.js.map +1 -1
  177. package/lib/module/web/registry.js +11 -4
  178. package/lib/module/web/registry.js.map +1 -1
  179. package/lib/module/web/runtime.js +3 -1
  180. package/lib/module/web/runtime.js.map +1 -1
  181. package/lib/module/web/shadowRegistry.js +70 -63
  182. package/lib/module/web/shadowRegistry.js.map +1 -1
  183. package/lib/module/web/utils/unistyle.js +1 -1
  184. package/lib/module/web/utils/unistyle.js.map +1 -1
  185. package/lib/typescript/src/components/ScopedTheme.d.ts +8 -0
  186. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -0
  187. package/lib/typescript/src/components/Variants.d.ts +7 -0
  188. package/lib/typescript/src/components/Variants.d.ts.map +1 -0
  189. package/lib/typescript/src/components/index.d.ts +2 -1
  190. package/lib/typescript/src/components/index.d.ts.map +1 -1
  191. package/lib/typescript/src/components/native/ActivityIndicator.d.ts +2 -0
  192. package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -0
  193. package/lib/typescript/src/components/native/FlatList.d.ts +2 -0
  194. package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -0
  195. package/lib/typescript/src/components/native/Image.d.ts +2 -0
  196. package/lib/typescript/src/components/native/Image.d.ts.map +1 -0
  197. package/lib/typescript/src/components/native/ImageBackground.d.ts +3 -0
  198. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -0
  199. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +2 -0
  200. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -0
  201. package/lib/typescript/src/components/{Pressable.web.d.ts → native/Pressable.d.ts} +3 -2
  202. package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -0
  203. package/lib/typescript/src/components/{Pressable.d.ts → native/Pressable.native.d.ts} +1 -3
  204. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -0
  205. package/lib/typescript/src/components/native/RefreshControl.d.ts +2 -0
  206. package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -0
  207. package/lib/typescript/src/components/native/ScrollView.d.ts +2 -0
  208. package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -0
  209. package/lib/typescript/src/components/native/SectionList.d.ts +2 -0
  210. package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -0
  211. package/lib/typescript/src/components/native/Switch.d.ts +2 -0
  212. package/lib/typescript/src/components/native/Switch.d.ts.map +1 -0
  213. package/lib/typescript/src/components/native/Text.d.ts +2 -0
  214. package/lib/typescript/src/components/native/Text.d.ts.map +1 -0
  215. package/lib/typescript/src/components/native/TextInput.d.ts +2 -0
  216. package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -0
  217. package/lib/typescript/src/components/native/TouchableHighlight.d.ts +2 -0
  218. package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -0
  219. package/lib/typescript/src/components/native/TouchableOpacity.d.ts +2 -0
  220. package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -0
  221. package/lib/typescript/src/components/native/View.d.ts +2 -0
  222. package/lib/typescript/src/components/native/View.d.ts.map +1 -0
  223. package/lib/typescript/src/components/native/VirtualizedList.d.ts +2 -0
  224. package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -0
  225. package/lib/typescript/src/core/createUnistylesComponent.d.ts +9 -3
  226. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -1
  227. package/lib/typescript/src/core/createUnistylesElement.d.ts +3 -0
  228. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -0
  229. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts +4 -0
  230. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -0
  231. package/lib/typescript/src/core/index.d.ts +4 -2
  232. package/lib/typescript/src/core/index.d.ts.map +1 -1
  233. package/lib/typescript/src/core/passForwardRef.d.ts +3 -0
  234. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -0
  235. package/lib/typescript/src/core/withUnistyles/index.d.ts +2 -0
  236. package/lib/typescript/src/core/withUnistyles/index.d.ts.map +1 -0
  237. package/lib/typescript/src/core/withUnistyles/types.d.ts +6 -0
  238. package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -0
  239. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +13 -0
  240. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +1 -0
  241. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +11 -0
  242. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -0
  243. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts +8 -0
  244. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -0
  245. package/lib/typescript/src/hooks/useMedia.d.ts +1 -1
  246. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  247. package/lib/typescript/src/hooks/useMedia.native.d.ts +6 -0
  248. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -0
  249. package/lib/typescript/src/index.d.ts +2 -2
  250. package/lib/typescript/src/index.d.ts.map +1 -1
  251. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +7 -2
  252. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  253. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +17 -0
  254. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
  255. package/lib/typescript/src/specs/index.d.ts +3 -11
  256. package/lib/typescript/src/specs/index.d.ts.map +1 -1
  257. package/lib/typescript/src/specs/index.native.d.ts +12 -0
  258. package/lib/typescript/src/specs/index.native.d.ts.map +1 -0
  259. package/lib/typescript/src/web/create.d.ts +1 -1441
  260. package/lib/typescript/src/web/create.d.ts.map +1 -1
  261. package/lib/typescript/src/web/index.d.ts +2 -1441
  262. package/lib/typescript/src/web/index.d.ts.map +1 -1
  263. package/lib/typescript/src/web/registry.d.ts +2 -3
  264. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  265. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  266. package/lib/typescript/src/web/shadowRegistry.d.ts +11 -3
  267. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  268. package/lib/typescript/src/web/utils/unistyle.d.ts +1 -2
  269. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  270. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +3 -0
  271. package/package.json +4 -4
  272. package/plugin/common.js +4 -6
  273. package/plugin/import.js +63 -26
  274. package/plugin/index.js +48 -28
  275. package/plugin/ref.js +0 -234
  276. package/plugin/style.js +4 -317
  277. package/plugin/stylesheet.js +25 -10
  278. package/plugin/variants.js +54 -1
  279. package/src/components/ScopedTheme.tsx +32 -0
  280. package/src/components/Variants.tsx +29 -0
  281. package/src/components/index.ts +2 -1
  282. package/src/components/native/ActivityIndicator.tsx +4 -0
  283. package/src/components/native/FlatList.tsx +4 -0
  284. package/src/components/native/Image.tsx +4 -0
  285. package/src/components/native/ImageBackground.tsx +4 -0
  286. package/src/components/native/KeyboardAvoidingView.tsx +4 -0
  287. package/src/components/native/Pressable.native.tsx +55 -0
  288. package/src/components/native/Pressable.tsx +98 -0
  289. package/src/components/native/RefreshControl.tsx +4 -0
  290. package/src/components/native/ScrollView.tsx +4 -0
  291. package/src/components/native/SectionList.tsx +4 -0
  292. package/src/components/native/Switch.tsx +4 -0
  293. package/src/components/native/Text.tsx +4 -0
  294. package/src/components/native/TextInput.tsx +4 -0
  295. package/src/components/native/TouchableHighlight.tsx +4 -0
  296. package/src/components/native/TouchableOpacity.tsx +4 -0
  297. package/src/components/native/View.tsx +4 -0
  298. package/src/components/native/VirtualizedList.tsx +4 -0
  299. package/src/core/createUnistylesComponent.tsx +6 -76
  300. package/src/core/createUnistylesElement.tsx +9 -0
  301. package/src/core/createUnistylesImageBackground.tsx +24 -0
  302. package/src/core/index.ts +4 -2
  303. package/src/core/passForwardRef.ts +29 -0
  304. package/src/core/withUnistyles/index.ts +1 -0
  305. package/src/core/withUnistyles/types.ts +7 -0
  306. package/src/core/withUnistyles/useDependencies.ts +93 -0
  307. package/src/core/withUnistyles/withUnistyles.native.tsx +96 -0
  308. package/src/core/withUnistyles/withUnistyles.tsx +90 -0
  309. package/src/hooks/useMedia.native.ts +65 -0
  310. package/src/hooks/useMedia.ts +19 -36
  311. package/src/index.ts +2 -2
  312. package/src/specs/ShadowRegistry/index.ts +14 -5
  313. package/src/specs/ShadowRegistry/types.ts +18 -1
  314. package/src/specs/index.native.ts +27 -0
  315. package/src/specs/index.ts +3 -27
  316. package/src/web/create.ts +14 -32
  317. package/src/web/index.ts +3 -2
  318. package/src/web/registry.ts +15 -6
  319. package/src/web/runtime.ts +3 -1
  320. package/src/web/shadowRegistry.ts +66 -52
  321. package/src/web/utils/unistyle.ts +1 -2
  322. package/lib/commonjs/components/Pressable.js +0 -74
  323. package/lib/commonjs/components/Pressable.js.map +0 -1
  324. package/lib/commonjs/components/Pressable.web.js.map +0 -1
  325. package/lib/commonjs/core/createUnistylesComponent.native.js +0 -82
  326. package/lib/commonjs/core/createUnistylesComponent.native.js.map +0 -1
  327. package/lib/commonjs/core/getBoundArgs.js +0 -18
  328. package/lib/commonjs/core/getBoundArgs.js.map +0 -1
  329. package/lib/commonjs/core/getId.js +0 -9
  330. package/lib/commonjs/core/getId.js.map +0 -1
  331. package/lib/commonjs/hooks/useMedia.web.js +0 -43
  332. package/lib/commonjs/hooks/useMedia.web.js.map +0 -1
  333. package/lib/commonjs/specs/index.web.js +0 -17
  334. package/lib/commonjs/specs/index.web.js.map +0 -1
  335. package/lib/module/components/Pressable.js +0 -68
  336. package/lib/module/components/Pressable.js.map +0 -1
  337. package/lib/module/components/Pressable.web.js +0 -109
  338. package/lib/module/components/Pressable.web.js.map +0 -1
  339. package/lib/module/core/createUnistylesComponent.native.js +0 -75
  340. package/lib/module/core/createUnistylesComponent.native.js.map +0 -1
  341. package/lib/module/core/getBoundArgs.js +0 -13
  342. package/lib/module/core/getBoundArgs.js.map +0 -1
  343. package/lib/module/core/getId.js +0 -4
  344. package/lib/module/core/getId.js.map +0 -1
  345. package/lib/module/hooks/useMedia.web.js +0 -38
  346. package/lib/module/hooks/useMedia.web.js.map +0 -1
  347. package/lib/module/specs/index.web.js +0 -4
  348. package/lib/module/specs/index.web.js.map +0 -1
  349. package/lib/typescript/src/components/Pressable.d.ts.map +0 -1
  350. package/lib/typescript/src/components/Pressable.web.d.ts.map +0 -1
  351. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +0 -8
  352. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +0 -1
  353. package/lib/typescript/src/core/getBoundArgs.d.ts +0 -2
  354. package/lib/typescript/src/core/getBoundArgs.d.ts.map +0 -1
  355. package/lib/typescript/src/core/getId.d.ts +0 -2
  356. package/lib/typescript/src/core/getId.d.ts.map +0 -1
  357. package/lib/typescript/src/hooks/useMedia.web.d.ts +0 -6
  358. package/lib/typescript/src/hooks/useMedia.web.d.ts.map +0 -1
  359. package/lib/typescript/src/specs/index.web.d.ts +0 -2
  360. package/lib/typescript/src/specs/index.web.d.ts.map +0 -1
  361. package/src/components/Pressable.tsx +0 -89
  362. package/src/components/Pressable.web.tsx +0 -129
  363. package/src/core/createUnistylesComponent.native.tsx +0 -83
  364. package/src/core/getBoundArgs.ts +0 -15
  365. package/src/core/getId.ts +0 -1
  366. package/src/hooks/useMedia.web.ts +0 -47
  367. package/src/specs/index.web.ts +0 -1
@@ -0,0 +1,96 @@
1
+ import React, { forwardRef, useEffect, useRef, type ComponentType } from 'react'
2
+ import { StyleSheet, UnistyleDependency } from '../../specs'
3
+ import type { PartialBy } from '../../types/common'
4
+ import { deepMergeObjects } from '../../utils'
5
+ import { SUPPORTED_STYLE_PROPS } from './types'
6
+ import type { Mappings, SupportedStyleProps } from './types'
7
+ import { useDependencies } from './useDependencies'
8
+
9
+ // @ts-expect-error
10
+ type GenericComponentProps<P> = ComponentProps<P>
11
+ // @ts-expect-error
12
+ type GenericComponentRef<T> = ComponentRef<T>
13
+
14
+ export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
15
+ type TProps = GenericComponentProps<TComponent>
16
+ type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
17
+ uniProps?: Mappings<TProps>
18
+ }
19
+
20
+ return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
21
+ const narrowedProps = props as PropsWithUnistyles
22
+ const stylesRef = useRef<Record<string, any>>({})
23
+ const isForcedRef = useRef(false)
24
+ const NativeComponent = Component as ComponentType
25
+
26
+ if (!isForcedRef.current) {
27
+ SUPPORTED_STYLE_PROPS.forEach(propName => {
28
+ if (narrowedProps?.[propName]) {
29
+ if (Array.isArray(narrowedProps[propName])) {
30
+ console.error(`🦄 Unistyles: withUnistyles requires ${propName} to be an object. Please check props for component: ${NativeComponent.displayName}`)
31
+ }
32
+
33
+ // @ts-expect-error - this is hidden from TS
34
+ if (props[propName].__unistyles_name && !props[propName].__proto__?.getStyle) {
35
+ console.error(`🦄 Unistyles: withUnistyles received style that is not bound. You likely used the spread operator on a Unistyle style. Please check props for component: ${NativeComponent.displayName}`)
36
+ }
37
+
38
+ stylesRef.current = {
39
+ ...stylesRef.current,
40
+ [propName]: narrowedProps[propName]
41
+ }
42
+ }
43
+ })
44
+ }
45
+
46
+ const { mappingsCallback, addDependencies } = useDependencies(({ dependencies, updateTheme, updateRuntime }) => {
47
+ const listensToTheme = dependencies.includes(UnistyleDependency.Theme)
48
+ // @ts-expect-error - this is hidden from TS
49
+ const dispose = StyleSheet.addChangeListener(changedDependencies => {
50
+ if (listensToTheme && changedDependencies.includes(UnistyleDependency.Theme)) {
51
+ updateTheme()
52
+ }
53
+
54
+ if (changedDependencies.some((dependency: UnistyleDependency) => dependencies.includes(dependency))) {
55
+ SUPPORTED_STYLE_PROPS.forEach(propName => {
56
+ if (narrowedProps?.[propName]) {
57
+ stylesRef.current = {
58
+ ...stylesRef.current,
59
+ // @ts-expect-error - this is hidden from TS
60
+ [propName]: props[propName].__proto__?.getStyle?.() || props[propName]
61
+ }
62
+
63
+ isForcedRef.current = true
64
+ }
65
+ })
66
+
67
+ updateRuntime()
68
+ }
69
+ })
70
+
71
+ return () => dispose()
72
+ })
73
+
74
+ useEffect(() => {
75
+ const styleDependencies = narrowedProps.style?.__proto__.uni__dependencies ?? [] as Array<UnistyleDependency>
76
+ const contentContainerStyleDependencies = narrowedProps.contentContainerStyle?.__proto__.uni__dependencies ?? [] as Array<UnistyleDependency>
77
+
78
+ addDependencies([...styleDependencies, ...contentContainerStyleDependencies])
79
+ }, [narrowedProps.style, narrowedProps.contentContainerStyle])
80
+
81
+ const mappingProps = mappings ? mappingsCallback(mappings) : {}
82
+ const unistyleProps = narrowedProps.uniProps ? mappingsCallback(narrowedProps.uniProps) : {}
83
+ const finalProps = deepMergeObjects<Record<string, any>>(mappingProps, unistyleProps, props)
84
+
85
+ // override with Unistyles styles
86
+ SUPPORTED_STYLE_PROPS.forEach(propName => {
87
+ if (finalProps[propName]) {
88
+ finalProps[propName] = stylesRef.current[propName]
89
+ }
90
+ })
91
+
92
+ isForcedRef.current = false
93
+
94
+ return <NativeComponent {...finalProps as TProps} ref={ref} />
95
+ })
96
+ }
@@ -0,0 +1,90 @@
1
+ import React, { useEffect, useState, type ComponentType, forwardRef, useRef, useMemo, type ComponentProps, type ComponentRef } from 'react'
2
+ import type { PartialBy } from '../../types/common'
3
+ import { UnistylesListener } from '../../web/listener'
4
+ import { UnistylesShadowRegistry } from '../../web'
5
+ import { equal } from '../../web/utils'
6
+ import { deepMergeObjects } from '../../utils'
7
+ import type { Mappings, SupportedStyleProps } from './types'
8
+ import { useDependencies } from './useDependencies'
9
+ import { UnistyleDependency } from '../../specs/NativePlatform'
10
+ import type { UnistylesValues } from '../../types'
11
+
12
+ const useShadowRegistry = (style?: Record<string, any>) => {
13
+ const [ref] = useState(document.createElement('div'))
14
+ const oldClassNames = useRef<Array<string>>([])
15
+ const classNames = useMemo(() => {
16
+ if (!style) {
17
+ return []
18
+ }
19
+
20
+ const newClassNames = UnistylesShadowRegistry.add(ref, [style]) ?? []
21
+
22
+ if (equal(oldClassNames.current, newClassNames)) {
23
+ return oldClassNames.current
24
+ }
25
+
26
+ oldClassNames.current = newClassNames
27
+
28
+ return newClassNames
29
+ }, [style])
30
+
31
+ useEffect(() => () => {
32
+ // Remove styles on unmount
33
+ if (style) {
34
+ UnistylesShadowRegistry.add(null, [style])
35
+ }
36
+ })
37
+
38
+ return classNames
39
+ }
40
+
41
+ // @ts-expect-error
42
+ type GenericComponentProps<T> = ComponentProps<T>
43
+ // @ts-expect-error
44
+ type GenericComponentRef<T> = ComponentRef<T>
45
+
46
+ export const withUnistyles = <TComponent, TMappings extends GenericComponentProps<TComponent>>(Component: TComponent, mappings?: Mappings<TMappings>) => {
47
+ type TProps = GenericComponentProps<TComponent>
48
+ type PropsWithUnistyles = PartialBy<TProps, keyof TMappings | SupportedStyleProps> & {
49
+ uniProps?: Mappings<TProps>
50
+ style?: UnistylesValues,
51
+ contentContainerStyle?: UnistylesValues
52
+ }
53
+
54
+ return forwardRef<GenericComponentRef<TComponent>, PropsWithUnistyles>((props, ref) => {
55
+ const narrowedProps = props as PropsWithUnistyles
56
+ const styleClassNames = useShadowRegistry(narrowedProps.style)
57
+ const contentContainerStyleClassNames = useShadowRegistry(narrowedProps.contentContainerStyle)
58
+ const { mappingsCallback } = useDependencies(({ dependencies, updateTheme, updateRuntime }) => {
59
+ const disposeTheme = UnistylesListener.addListeners(dependencies.filter(dependency => dependency === UnistyleDependency.Theme), updateTheme)
60
+ const disposeRuntime = UnistylesListener.addListeners(dependencies.filter(dependency => dependency !== UnistyleDependency.Theme), updateRuntime)
61
+
62
+ return () => {
63
+ disposeTheme()
64
+ disposeRuntime()
65
+ }
66
+ })
67
+ const mappingsProps = mappings ? mappingsCallback(mappings) : {}
68
+ const unistyleProps = narrowedProps.uniProps ? mappingsCallback(narrowedProps.uniProps) : {}
69
+
70
+ const combinedProps = {
71
+ ...deepMergeObjects(mappingsProps, unistyleProps, props),
72
+ ...narrowedProps.style ? {
73
+ style: {
74
+ $$css: true,
75
+ 'unistyles': styleClassNames.join(' ')
76
+ },
77
+ } : {},
78
+ ...narrowedProps.contentContainerStyle ? {
79
+ style: {
80
+ $$css: true,
81
+ 'unistyles': contentContainerStyleClassNames.join(' ')
82
+ },
83
+ } : {},
84
+ } as any
85
+
86
+ const NativeComponent = Component as ComponentType
87
+
88
+ return <NativeComponent {...combinedProps} ref={ref} />
89
+ })
90
+ }
@@ -0,0 +1,65 @@
1
+ import { useEffect, useLayoutEffect, useState } from 'react'
2
+ import { StyleSheet, UnistyleDependency, UnistylesRuntime } from '../specs'
3
+ import { isValidMq, parseMq, isUnistylesMq } from '../mq'
4
+
5
+ export const useMedia = (config: { mq: symbol }) => {
6
+ const computeIsVisible = (): boolean => {
7
+ const maybeMq = config.mq as unknown as string
8
+
9
+ if (!isUnistylesMq(maybeMq)) {
10
+ console.error(`🦄 Unistyles: Received invalid mq: ${maybeMq}`)
11
+
12
+ return false
13
+ }
14
+
15
+ const parsedMq = parseMq(maybeMq)
16
+
17
+ if (!isValidMq(parsedMq)) {
18
+ console.error(`🦄 Unistyles: Received invalid mq where min is greater than max: ${maybeMq}`)
19
+
20
+ return false
21
+ }
22
+
23
+ const { width, height } = UnistylesRuntime.screen
24
+
25
+ if (parsedMq.minWidth !== undefined && width < parsedMq.minWidth) {
26
+ return false
27
+ }
28
+
29
+ if (parsedMq.maxWidth !== undefined && width > parsedMq.maxWidth) {
30
+ return false
31
+ }
32
+
33
+ if (parsedMq.minHeight !== undefined && height < parsedMq.minHeight) {
34
+ return false
35
+ }
36
+
37
+ if (parsedMq.maxHeight !== undefined && height > parsedMq.maxHeight) {
38
+ return false
39
+ }
40
+
41
+ return true
42
+ }
43
+ const [isVisible, setIsVisible] = useState<boolean | null>(computeIsVisible())
44
+
45
+ useEffect(() => {
46
+ setIsVisible(computeIsVisible())
47
+ }, [config.mq])
48
+
49
+ useLayoutEffect(() => {
50
+ // @ts-expect-error - this is hidden from TS
51
+ const removeChangeListener = StyleSheet.addChangeListener((dependencies: Array<UnistyleDependency>) => {
52
+ if (dependencies.includes(UnistyleDependency.Breakpoints)) {
53
+ setIsVisible(computeIsVisible())
54
+ }
55
+ })
56
+
57
+ return () => {
58
+ removeChangeListener()
59
+ }
60
+ }, [config.mq])
61
+
62
+ return {
63
+ isVisible
64
+ }
65
+ }
@@ -1,9 +1,9 @@
1
- import { useEffect, useLayoutEffect, useState } from 'react'
2
- import { StyleSheet, UnistyleDependency, UnistylesRuntime, type UnistylesStyleSheet } from '../specs'
3
- import { isValidMq, parseMq, isUnistylesMq } from '../mq'
1
+ import { useEffect, useRef, useState } from 'react'
2
+ import { isUnistylesMq, isValidMq, parseMq } from '../mq'
4
3
 
5
4
  export const useMedia = (config: { mq: symbol }) => {
6
- const computeIsVisible = (): boolean => {
5
+ const disposeRef = useRef(() => {})
6
+ const [isVisible, setIsVisible] = useState(() => {
7
7
  const maybeMq = config.mq as unknown as string
8
8
 
9
9
  if (!isUnistylesMq(maybeMq)) {
@@ -20,43 +20,26 @@ export const useMedia = (config: { mq: symbol }) => {
20
20
  return false
21
21
  }
22
22
 
23
- const { width, height } = UnistylesRuntime.screen
23
+ const { minWidth, maxWidth, minHeight, maxHeight } = parsedMq
24
24
 
25
- if (parsedMq.minWidth !== undefined && width < parsedMq.minWidth) {
26
- return false
27
- }
25
+ const mediaQuery = [
26
+ minWidth !== undefined ? `(min-width: ${minWidth}px)` : undefined,
27
+ maxWidth !== undefined ? `(max-width: ${maxWidth}px)` : undefined,
28
+ minHeight !== undefined ? `(min-height: ${minHeight}px)` : undefined,
29
+ maxHeight !== undefined ? `(max-height: ${maxHeight}px)` : undefined
30
+ ].filter(Boolean).join(' and ')
28
31
 
29
- if (parsedMq.maxWidth !== undefined && width > parsedMq.maxWidth) {
30
- return false
31
- }
32
+ const media = window.matchMedia(mediaQuery)
33
+ const handler = (event: MediaQueryListEvent) => setIsVisible(event.matches)
32
34
 
33
- if (parsedMq.minHeight !== undefined && height < parsedMq.minHeight) {
34
- return false
35
- }
35
+ media.addEventListener('change', handler)
36
+ disposeRef.current = () => media.removeEventListener('change', handler)
36
37
 
37
- if (parsedMq.maxHeight !== undefined && height > parsedMq.maxHeight) {
38
- return false
39
- }
40
-
41
- return true
42
- }
43
- const [isVisible, setIsVisible] = useState<boolean | null>(computeIsVisible())
38
+ return media.matches
39
+ })
44
40
 
45
- useEffect(() => {
46
- setIsVisible(computeIsVisible())
47
- }, [config.mq])
48
-
49
- useLayoutEffect(() => {
50
- const removeChangeListener = (StyleSheet as UnistylesStyleSheet).addChangeListener(dependencies => {
51
- if (dependencies.includes(UnistyleDependency.Breakpoints)) {
52
- setIsVisible(computeIsVisible())
53
- }
54
- })
55
-
56
- return () => {
57
- removeChangeListener()
58
- }
59
- }, [config.mq])
41
+ // Unmount
42
+ useEffect(() => () => disposeRef.current(), [])
60
43
 
61
44
  return {
62
45
  isVisible
package/src/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  export * from './specs'
2
2
  export { mq } from './mq'
3
3
  export type { UnistylesThemes, UnistylesBreakpoints } from './global'
4
- export { createUnistylesComponent, getBoundArgs } from './core'
4
+ export { createUnistylesComponent, withUnistyles } from './core'
5
5
  export type { UnistylesVariants } from './types'
6
- export * from './components'
6
+ export { Display, Hide, Variants, ScopedTheme } from './components'
@@ -2,13 +2,19 @@ import { NitroModules } from 'react-native-nitro-modules'
2
2
  import type { UnistylesShadowRegistry as UnistylesShadowRegistrySpec } from './ShadowRegistry.nitro'
3
3
  import type { ShadowNode, Unistyle, ViewHandle } from './types'
4
4
 
5
+ type Variants = Record<string, string | boolean | undefined>
6
+
5
7
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
6
8
  // Babel API
7
- add(handle?: ViewHandle, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, id?: string): void,
9
+ add(handle?: ViewHandle, styles?: Array<Unistyle>): void,
8
10
  remove(handle?: ViewHandle): void,
9
11
  // JSI
10
- link(node: ShadowNode, styles?: Array<Unistyle>, variants?: Record<string, string | boolean>, args?: Array<Array<any>>, id?: string): void,
11
- unlink(node: ShadowNode): void
12
+ link(node: ShadowNode, styles?: Array<Unistyle>): void,
13
+ unlink(node: ShadowNode): void,
14
+ selectVariants(variants?: Variants): void,
15
+ setScopedTheme(themeName?: string): void,
16
+ getScopedTheme(): string | undefined,
17
+ getVariants(): Record<string, string | boolean | undefined> | undefined,
12
18
  }
13
19
 
14
20
  const HybridShadowRegistry = NitroModules.createHybridObject<ShadowRegistry>('UnistylesShadowRegistry')
@@ -17,6 +23,9 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
17
23
  const node = handle?.__internalInstanceHandle?.stateNode?.node
18
24
  ?? handle?.getScrollResponder?.()?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
19
25
  ?? handle?.getNativeScrollRef?.()?.__internalInstanceHandle?.stateNode?.node
26
+ ?? handle?._viewRef?.__internalInstanceHandle?.stateNode?.node
27
+ ?? handle?.viewRef?.current?.__internalInstanceHandle?.stateNode?.node
28
+ ?? handle?._nativeRef?.__internalInstanceHandle?.stateNode?.node
20
29
 
21
30
  if (!node) {
22
31
  throw new Error(`Unistyles: Could not find shadow node for one of your components of type ${handle?.__internalInstanceHandle?.elementType ?? 'unknown'}`)
@@ -25,7 +34,7 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
25
34
  return node
26
35
  }
27
36
 
28
- HybridShadowRegistry.add = (handle, styles, variants, args, id) => {
37
+ HybridShadowRegistry.add = (handle, styles) => {
29
38
  // virtualized nodes can be null
30
39
  if (!handle || !styles || !Array.isArray(styles)) {
31
40
  return
@@ -36,7 +45,7 @@ HybridShadowRegistry.add = (handle, styles, variants, args, id) => {
36
45
  .filter(style => !style?.initial?.updater)
37
46
  .filter(Boolean)
38
47
 
39
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles, variants ?? {}, args ?? [], id)
48
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), filteredStyles)
40
49
  }
41
50
 
42
51
  HybridShadowRegistry.remove = handle => {
@@ -22,7 +22,24 @@ export type ViewHandle = {
22
22
  __internalInstanceHandle?: {
23
23
  stateNode?: StateNode
24
24
  }
25
- })
25
+ }),
26
+ _viewRef?: {
27
+ __internalInstanceHandle?: {
28
+ stateNode?: StateNode
29
+ }
30
+ },
31
+ viewRef?: {
32
+ current?: {
33
+ __internalInstanceHandle?: {
34
+ stateNode?: StateNode
35
+ }
36
+ }
37
+ },
38
+ _nativeRef?: {
39
+ __internalInstanceHandle?: {
40
+ stateNode?: StateNode
41
+ }
42
+ }
26
43
  }
27
44
 
28
45
  export type Unistyle = {
@@ -0,0 +1,27 @@
1
+ import './TurboUnistyles'
2
+
3
+ import { Runtime } from './UnistylesRuntime'
4
+ import { StyleSheet } from './StyleSheet'
5
+ import type { UnistylesStyleSheet } from './StyleSheet'
6
+ import { UnistylesShadowRegistry } from './ShadowRegistry'
7
+ import type { UnistylesMiniRuntime } from './UnistylesRuntime'
8
+ import { StatusBarStyle, ColorScheme, Orientation } from './types'
9
+ import { UnistyleDependency } from './NativePlatform'
10
+
11
+ export {
12
+ StatusBarStyle,
13
+ ColorScheme,
14
+ Orientation,
15
+ UnistyleDependency
16
+ }
17
+
18
+ export {
19
+ UnistylesShadowRegistry,
20
+ Runtime as UnistylesRuntime,
21
+ StyleSheet,
22
+ }
23
+
24
+ export type {
25
+ UnistylesMiniRuntime,
26
+ UnistylesStyleSheet
27
+ }
@@ -1,27 +1,3 @@
1
- import './TurboUnistyles'
2
-
3
- import { Runtime } from './UnistylesRuntime'
4
- import { StyleSheet } from './StyleSheet'
5
- import type { UnistylesStyleSheet } from './StyleSheet'
6
- import { UnistylesShadowRegistry } from './ShadowRegistry'
7
- import type { UnistylesMiniRuntime } from './UnistylesRuntime'
8
- import { StatusBarStyle, ColorScheme, Orientation } from './types'
9
- import { UnistyleDependency } from './NativePlatform'
10
-
11
- export {
12
- StatusBarStyle,
13
- ColorScheme,
14
- Orientation,
15
- UnistyleDependency
16
- }
17
-
18
- export {
19
- UnistylesShadowRegistry,
20
- Runtime as UnistylesRuntime,
21
- StyleSheet,
22
- }
23
-
24
- export type {
25
- UnistylesMiniRuntime,
26
- UnistylesStyleSheet
27
- }
1
+ export * from '../web'
2
+ export type { UnistylesMiniRuntime } from './UnistylesRuntime'
3
+ export { UnistyleDependency } from './NativePlatform'
package/src/web/create.ts CHANGED
@@ -1,9 +1,11 @@
1
- import type { ReactNativeStyleSheet } from '../types'
2
1
  import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
3
- import { assignSecrets, reduceObject, getStyles, error } from './utils'
4
- import { deepMergeObjects } from '../utils'
2
+ import { assignSecrets, error, removeInlineStyles } from './utils'
5
3
  import { UnistylesRuntime } from './runtime'
6
- import { getVariants } from './variants'
4
+ import { UnistylesShadowRegistry } from '../specs'
5
+
6
+ const useVariants = ['useVariants', (variants: Record<string, string | boolean>) => {
7
+ UnistylesShadowRegistry.selectVariants(variants)
8
+ }]
7
9
 
8
10
  export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: string) => {
9
11
  if (!id) {
@@ -13,45 +15,25 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
13
15
  const computedStylesheet = typeof stylesheet === 'function'
14
16
  ? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
15
17
  : stylesheet
16
- const selectedVariants = new Map<string, any>()
17
18
 
18
- const copyVariants = () => Object.fromEntries(selectedVariants.entries())
19
19
  const addSecrets = (value: any, key: string, args?: Array<any>) => assignSecrets(value, {
20
20
  __uni__key: key,
21
- __uni__refs: new Set(),
22
21
  __uni__stylesheet: stylesheet,
23
22
  __uni__args: args,
24
- __uni__variants: copyVariants()
23
+ __uni__refs: new Set()
25
24
  })
26
25
 
27
- const styles = reduceObject(computedStylesheet, (value, _key) => {
28
- const key = String(_key)
29
-
26
+ const styleSheetStyles = Object.entries(computedStylesheet).map(([key, value]) => {
30
27
  if (typeof value === 'function') {
31
- const dynamicStyle = (...args: Array<any>) => {
32
- const result = value(...args)
33
- const variants = Object.fromEntries(getVariants({ [key]: result } as ReactNativeStyleSheet<StyleSheet>, copyVariants()))
34
- const resultWithVariants = deepMergeObjects(result, variants[key] ?? {})
28
+ return [key, (...args: Array<any>) => {
29
+ const result = removeInlineStyles(value(...args))
35
30
 
36
- // Add secrets to result of dynamic styles function
37
- return addSecrets(getStyles(resultWithVariants), key, args)
38
- }
39
-
40
- // Add secrets to dynamic styles function
41
- return addSecrets(dynamicStyle, key)
31
+ return addSecrets(result, key, args)
32
+ }]
42
33
  }
43
34
 
44
- // Add secrets to static styles
45
- return addSecrets(getStyles(value), key)
46
- }) as ReactNativeStyleSheet<StyleSheet>
47
-
48
- // Inject useVariants hook to styles
49
- Object.defineProperty(styles, 'useVariants', {
50
- value: (variants: Record<string, string | boolean>) => {
51
- Object.entries(variants).forEach(([key, value]) => selectedVariants.set(key, value))
52
- },
53
- configurable: false,
35
+ return [key, addSecrets(removeInlineStyles(value), key)]
54
36
  })
55
37
 
56
- return styles
38
+ return Object.fromEntries(styleSheetStyles.concat([useVariants]))
57
39
  }
package/src/web/index.ts CHANGED
@@ -1,10 +1,11 @@
1
1
  import { create } from './create'
2
2
  import { UnistylesState } from './state'
3
3
  import { deepMergeObjects } from '../utils'
4
+ import type { CreateUnistylesStyleSheet } from '../types'
4
5
 
5
6
  export const StyleSheet = {
6
7
  configure: UnistylesState.init,
7
- create,
8
+ create: create as CreateUnistylesStyleSheet,
8
9
  absoluteFill: {
9
10
  position: 'absolute',
10
11
  left: 0,
@@ -21,7 +22,7 @@ export const StyleSheet = {
21
22
  },
22
23
  compose: (a: object, b: object) => deepMergeObjects(a, b),
23
24
  flatten: (...styles: Array<object>) => deepMergeObjects(...styles),
24
- hairlineWidth: 1
25
+ hairlineWidth: 1 as number
25
26
  }
26
27
 
27
28
  export { UnistylesRuntime } from './runtime'
@@ -1,11 +1,10 @@
1
1
  import type { UnistylesTheme, UnistylesValues } from '../types'
2
2
  import type { StyleSheet, StyleSheetWithSuperPowers } from '../types/stylesheet'
3
3
  import { UnistylesRuntime } from './runtime'
4
- import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies } from './utils'
4
+ import { extractMediaQueryValue, keyInObject, getMediaQuery, generateHash, extractUnistyleDependencies, error } from './utils'
5
5
  import { UnistylesListener } from './listener'
6
6
  import { convertUnistyles } from './convert'
7
- import type { UnistyleDependency } from '../specs/NativePlatform'
8
- import type { UnistylesMiniRuntime } from '../specs'
7
+ import type { UnistylesMiniRuntime, UnistyleDependency } from '../specs'
9
8
 
10
9
  type ApplyRuleProps = {
11
10
  hash: string,
@@ -39,11 +38,21 @@ class UnistylesRegistryBuilder {
39
38
  return tag
40
39
  }
41
40
 
42
- getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
41
+ getComputedStylesheet = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, scopedThemeName?: UnistylesTheme) => {
43
42
  if (typeof stylesheet !== 'function') {
44
43
  return stylesheet
45
44
  }
46
45
 
46
+ if (scopedThemeName) {
47
+ const scopedTheme = UnistylesRuntime.getTheme(scopedThemeName)
48
+
49
+ if (!scopedTheme) {
50
+ throw error(`Unistyles: You're trying to use scoped theme '${scopedThemeName}' but it wasn't registered.`)
51
+ }
52
+
53
+ return stylesheet(scopedTheme, UnistylesRuntime.miniRuntime)
54
+ }
55
+
47
56
  const computedStylesheet = this.stylesheets.get(stylesheet)
48
57
 
49
58
  if (computedStylesheet) {
@@ -85,7 +94,7 @@ class UnistylesRegistryBuilder {
85
94
 
86
95
  counter.add(value)
87
96
  this.stylesCounter.set(hash, counter)
88
- this.applyStyles(hash, convertUnistyles(value))
97
+ this.applyStyles(hash, value)
89
98
 
90
99
  return { hash, existingHash: false }
91
100
  }
@@ -96,7 +105,7 @@ class UnistylesRegistryBuilder {
96
105
  }
97
106
 
98
107
  applyStyles = (hash: string, styles: Record<string, any>) => {
99
- Object.entries(styles).forEach(([key, value]) => {
108
+ Object.entries(convertUnistyles(styles)).forEach(([key, value]) => {
100
109
  if (!this.styleTag.sheet) {
101
110
  return
102
111
  }
@@ -4,9 +4,11 @@ import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
4
4
  import { WebContentSizeCategory } from '../types'
5
5
  import { UnistylesListener } from './listener'
6
6
  import { NavigationBar, StatusBar } from './mock'
7
- import { UnistylesState } from './state'
8
7
  import { error, isServer, schemeToTheme } from './utils'
9
8
 
9
+ // Keep this import here, otherwise circular dependency will occur and break the build
10
+ import { UnistylesState } from './state'
11
+
10
12
  class UnistylesRuntimeBuilder {
11
13
  lightMedia = this.getLightMedia()
12
14
  darkMedia = this.getDarkMedia()