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

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 (496) hide show
  1. package/README.md +6 -3
  2. package/android/src/main/cxx/NativeUnistylesModule.cpp +1 -1
  3. package/android/src/main/cxx/NativeUnistylesModule.h +1 -1
  4. package/components/native/ActivityIndicator/package.json +2 -1
  5. package/components/native/FlatList/package.json +2 -1
  6. package/components/native/Image/package.json +2 -1
  7. package/components/native/ImageBackground/package.json +2 -1
  8. package/components/native/KeyboardAvoidingView/package.json +2 -1
  9. package/components/native/Pressable/package.json +1 -1
  10. package/components/native/RefreshControl/package.json +2 -1
  11. package/components/native/ScrollView/package.json +2 -1
  12. package/components/native/SectionList/package.json +2 -1
  13. package/components/native/Switch/package.json +2 -1
  14. package/components/native/Text/package.json +2 -1
  15. package/components/native/TextInput/package.json +2 -1
  16. package/components/native/TouchableHighlight/package.json +2 -1
  17. package/components/native/TouchableOpacity/package.json +2 -1
  18. package/components/native/View/package.json +2 -1
  19. package/components/native/VirtualizedList/package.json +2 -1
  20. package/cxx/common/Constants.h +4 -4
  21. package/cxx/common/Helpers.h +1 -1
  22. package/cxx/core/HashGenerator.cpp +23 -0
  23. package/cxx/core/HashGenerator.h +13 -0
  24. package/cxx/core/HostUnistyle.cpp +83 -0
  25. package/cxx/core/HostUnistyle.h +27 -0
  26. package/cxx/core/RNStyle.h +18 -0
  27. package/cxx/core/Unistyle.h +9 -4
  28. package/cxx/core/UnistyleWrapper.h +92 -47
  29. package/cxx/core/UnistylesRegistry.cpp +19 -11
  30. package/cxx/core/UnistylesRegistry.h +2 -4
  31. package/cxx/hybridObjects/HybridNavigationBar.cpp +3 -3
  32. package/cxx/hybridObjects/HybridNavigationBar.h +2 -2
  33. package/cxx/hybridObjects/HybridShadowRegistry.cpp +32 -45
  34. package/cxx/hybridObjects/HybridShadowRegistry.h +0 -10
  35. package/cxx/hybridObjects/HybridStatusBar.cpp +3 -3
  36. package/cxx/hybridObjects/HybridStatusBar.h +2 -2
  37. package/cxx/hybridObjects/HybridStyleSheet.cpp +25 -8
  38. package/cxx/hybridObjects/HybridStyleSheet.h +2 -1
  39. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +15 -15
  40. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -2
  41. package/cxx/parser/Parser.cpp +17 -24
  42. package/cxx/parser/Parser.h +2 -1
  43. package/ios/NativePlatform+ios.swift +5 -7
  44. package/ios/NativePlatform.swift +2 -2
  45. package/ios/UnistylesModuleOnLoad.mm +2 -1
  46. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  47. package/lib/commonjs/components/index.js +0 -7
  48. package/lib/commonjs/components/index.js.map +1 -1
  49. package/lib/commonjs/components/native/ImageBackground.js +45 -1
  50. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  51. package/lib/commonjs/components/native/ImageBackground.native.js +10 -0
  52. package/lib/commonjs/components/native/ImageBackground.native.js.map +1 -0
  53. package/lib/commonjs/components/native/Pressable.js +26 -51
  54. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  55. package/lib/commonjs/components/native/Pressable.native.js +14 -11
  56. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  57. package/lib/commonjs/core/createUnistylesElement.js +29 -5
  58. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  59. package/lib/commonjs/core/createUnistylesElement.native.js +40 -0
  60. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -0
  61. package/lib/commonjs/core/createUnistylesImageBackground.js +36 -14
  62. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  63. package/lib/commonjs/core/getClassname.js +25 -0
  64. package/lib/commonjs/core/getClassname.js.map +1 -0
  65. package/lib/commonjs/core/getClassname.native.js +9 -0
  66. package/lib/commonjs/core/getClassname.native.js.map +1 -0
  67. package/lib/commonjs/core/index.js +14 -7
  68. package/lib/commonjs/core/index.js.map +1 -1
  69. package/lib/commonjs/core/passForwardRef.js +2 -2
  70. package/lib/commonjs/core/passForwardRef.js.map +1 -1
  71. package/lib/commonjs/core/useProxifiedUnistyles/index.js +13 -0
  72. package/lib/commonjs/core/useProxifiedUnistyles/index.js.map +1 -0
  73. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +22 -0
  74. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -0
  75. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +26 -0
  76. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -0
  77. package/lib/commonjs/core/useProxifiedUnistyles/types.js +6 -0
  78. package/lib/commonjs/core/useProxifiedUnistyles/types.js.map +1 -0
  79. package/lib/commonjs/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +22 -22
  80. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
  81. package/lib/commonjs/core/useUnistyles.js +19 -0
  82. package/lib/commonjs/core/useUnistyles.js.map +1 -0
  83. package/lib/commonjs/core/warn.js +16 -0
  84. package/lib/commonjs/core/warn.js.map +1 -0
  85. package/lib/commonjs/core/withUnistyles/withUnistyles.js +19 -55
  86. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  87. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +32 -65
  88. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  89. package/lib/commonjs/index.js +23 -4
  90. package/lib/commonjs/index.js.map +1 -1
  91. package/lib/commonjs/server/getServerUnistyles.js +38 -0
  92. package/lib/commonjs/server/getServerUnistyles.js.map +1 -0
  93. package/lib/commonjs/server/hydrateServerUnistyles.js +17 -0
  94. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -0
  95. package/lib/commonjs/server/index.js +34 -0
  96. package/lib/commonjs/server/index.js.map +1 -0
  97. package/lib/commonjs/server/resetServerUnistyles.js +16 -0
  98. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -0
  99. package/lib/commonjs/server/types.js +8 -0
  100. package/lib/commonjs/server/types.js.map +1 -0
  101. package/lib/commonjs/server/useServerUnistyles.js +27 -0
  102. package/lib/commonjs/server/useServerUnistyles.js.map +1 -0
  103. package/lib/commonjs/specs/ShadowRegistry/index.js +6 -3
  104. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  105. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  106. package/lib/commonjs/utils.js +4 -2
  107. package/lib/commonjs/utils.js.map +1 -1
  108. package/lib/commonjs/web/convert/object/filter.js +2 -2
  109. package/lib/commonjs/web/convert/object/filter.js.map +1 -1
  110. package/lib/commonjs/web/convert/style.js +4 -4
  111. package/lib/commonjs/web/convert/style.js.map +1 -1
  112. package/lib/commonjs/web/create.js +20 -15
  113. package/lib/commonjs/web/create.js.map +1 -1
  114. package/lib/commonjs/web/css/core.js +55 -0
  115. package/lib/commonjs/web/css/core.js.map +1 -0
  116. package/lib/commonjs/web/css/index.js +17 -0
  117. package/lib/commonjs/web/css/index.js.map +1 -0
  118. package/lib/commonjs/web/css/state.js +155 -0
  119. package/lib/commonjs/web/css/state.js.map +1 -0
  120. package/lib/commonjs/web/css/utils.js +47 -0
  121. package/lib/commonjs/web/css/utils.js.map +1 -0
  122. package/lib/commonjs/web/index.js +14 -18
  123. package/lib/commonjs/web/index.js.map +1 -1
  124. package/lib/commonjs/web/listener.js +9 -7
  125. package/lib/commonjs/web/listener.js.map +1 -1
  126. package/lib/commonjs/web/registry.js +44 -123
  127. package/lib/commonjs/web/registry.js.map +1 -1
  128. package/lib/commonjs/web/runtime.js +28 -21
  129. package/lib/commonjs/web/runtime.js.map +1 -1
  130. package/lib/commonjs/web/services.js +28 -0
  131. package/lib/commonjs/web/services.js.map +1 -0
  132. package/lib/commonjs/web/shadowRegistry.js +46 -93
  133. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  134. package/lib/commonjs/web/state.js +39 -9
  135. package/lib/commonjs/web/state.js.map +1 -1
  136. package/lib/commonjs/web/types.js +6 -0
  137. package/lib/commonjs/web/types.js.map +1 -0
  138. package/lib/commonjs/web/utils/common.js +29 -9
  139. package/lib/commonjs/web/utils/common.js.map +1 -1
  140. package/lib/commonjs/web/utils/unistyle.js +28 -19
  141. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  142. package/lib/commonjs/web/variants.js +25 -27
  143. package/lib/commonjs/web/variants.js.map +1 -1
  144. package/lib/module/components/ScopedTheme.js.map +1 -1
  145. package/lib/module/components/index.js +0 -1
  146. package/lib/module/components/index.js.map +1 -1
  147. package/lib/module/components/native/ImageBackground.js +45 -2
  148. package/lib/module/components/native/ImageBackground.js.map +1 -1
  149. package/lib/module/components/native/ImageBackground.native.js +6 -0
  150. package/lib/module/components/native/ImageBackground.native.js.map +1 -0
  151. package/lib/module/components/native/Pressable.js +27 -52
  152. package/lib/module/components/native/Pressable.js.map +1 -1
  153. package/lib/module/components/native/Pressable.native.js +15 -12
  154. package/lib/module/components/native/Pressable.native.js.map +1 -1
  155. package/lib/module/core/createUnistylesElement.js +29 -5
  156. package/lib/module/core/createUnistylesElement.js.map +1 -1
  157. package/lib/module/core/createUnistylesElement.native.js +33 -0
  158. package/lib/module/core/createUnistylesElement.native.js.map +1 -0
  159. package/lib/module/core/createUnistylesImageBackground.js +34 -13
  160. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  161. package/lib/module/core/getClassname.js +20 -0
  162. package/lib/module/core/getClassname.js.map +1 -0
  163. package/lib/module/core/getClassname.native.js +4 -0
  164. package/lib/module/core/getClassname.native.js.map +1 -0
  165. package/lib/module/core/index.js +2 -1
  166. package/lib/module/core/index.js.map +1 -1
  167. package/lib/module/core/passForwardRef.js +2 -2
  168. package/lib/module/core/passForwardRef.js.map +1 -1
  169. package/lib/module/core/useProxifiedUnistyles/index.js +4 -0
  170. package/lib/module/core/useProxifiedUnistyles/index.js.map +1 -0
  171. package/lib/module/core/useProxifiedUnistyles/listener.js +17 -0
  172. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -0
  173. package/lib/module/core/useProxifiedUnistyles/listener.native.js +21 -0
  174. package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -0
  175. package/lib/module/core/useProxifiedUnistyles/types.js +4 -0
  176. package/lib/module/core/useProxifiedUnistyles/types.js.map +1 -0
  177. package/lib/module/core/{withUnistyles/useDependencies.js → useProxifiedUnistyles/useProxifiedUnistyles.js} +19 -19
  178. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -0
  179. package/lib/module/core/useUnistyles.js +14 -0
  180. package/lib/module/core/useUnistyles.js.map +1 -0
  181. package/lib/module/core/warn.js +11 -0
  182. package/lib/module/core/warn.js.map +1 -0
  183. package/lib/module/core/withUnistyles/withUnistyles.js +19 -55
  184. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  185. package/lib/module/core/withUnistyles/withUnistyles.native.js +33 -66
  186. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  187. package/lib/module/index.js +3 -2
  188. package/lib/module/index.js.map +1 -1
  189. package/lib/module/server/getServerUnistyles.js +32 -0
  190. package/lib/module/server/getServerUnistyles.js.map +1 -0
  191. package/lib/module/server/hydrateServerUnistyles.js +12 -0
  192. package/lib/module/server/hydrateServerUnistyles.js.map +1 -0
  193. package/lib/module/server/index.js +7 -0
  194. package/lib/module/server/index.js.map +1 -0
  195. package/lib/module/server/resetServerUnistyles.js +11 -0
  196. package/lib/module/server/resetServerUnistyles.js.map +1 -0
  197. package/lib/module/server/types.js +4 -0
  198. package/lib/module/server/types.js.map +1 -0
  199. package/lib/module/server/useServerUnistyles.js +22 -0
  200. package/lib/module/server/useServerUnistyles.js.map +1 -0
  201. package/lib/module/specs/ShadowRegistry/index.js +6 -3
  202. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  203. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  204. package/lib/module/utils.js +2 -1
  205. package/lib/module/utils.js.map +1 -1
  206. package/lib/module/web/convert/object/filter.js +2 -2
  207. package/lib/module/web/convert/object/filter.js.map +1 -1
  208. package/lib/module/web/convert/style.js +4 -4
  209. package/lib/module/web/convert/style.js.map +1 -1
  210. package/lib/module/web/create.js +20 -15
  211. package/lib/module/web/create.js.map +1 -1
  212. package/lib/module/web/css/core.js +50 -0
  213. package/lib/module/web/css/core.js.map +1 -0
  214. package/lib/module/web/css/index.js +4 -0
  215. package/lib/module/web/css/index.js.map +1 -0
  216. package/lib/module/web/css/state.js +150 -0
  217. package/lib/module/web/css/state.js.map +1 -0
  218. package/lib/module/web/css/utils.js +41 -0
  219. package/lib/module/web/css/utils.js.map +1 -0
  220. package/lib/module/web/index.js +10 -5
  221. package/lib/module/web/index.js.map +1 -1
  222. package/lib/module/web/listener.js +8 -7
  223. package/lib/module/web/listener.js.map +1 -1
  224. package/lib/module/web/registry.js +44 -124
  225. package/lib/module/web/registry.js.map +1 -1
  226. package/lib/module/web/runtime.js +27 -21
  227. package/lib/module/web/runtime.js.map +1 -1
  228. package/lib/module/web/services.js +23 -0
  229. package/lib/module/web/services.js.map +1 -0
  230. package/lib/module/web/shadowRegistry.js +46 -94
  231. package/lib/module/web/shadowRegistry.js.map +1 -1
  232. package/lib/module/web/state.js +39 -10
  233. package/lib/module/web/state.js.map +1 -1
  234. package/lib/module/web/types.js +4 -0
  235. package/lib/module/web/types.js.map +1 -0
  236. package/lib/module/web/utils/common.js +26 -7
  237. package/lib/module/web/utils/common.js.map +1 -1
  238. package/lib/module/web/utils/unistyle.js +27 -17
  239. package/lib/module/web/utils/unistyle.js.map +1 -1
  240. package/lib/module/web/variants.js +25 -27
  241. package/lib/module/web/variants.js.map +1 -1
  242. package/lib/typescript/src/components/index.d.ts +0 -1
  243. package/lib/typescript/src/components/index.d.ts.map +1 -1
  244. package/lib/typescript/src/components/native/ActivityIndicator.d.ts +3 -1
  245. package/lib/typescript/src/components/native/ActivityIndicator.d.ts.map +1 -1
  246. package/lib/typescript/src/components/native/FlatList.d.ts +3 -1
  247. package/lib/typescript/src/components/native/FlatList.d.ts.map +1 -1
  248. package/lib/typescript/src/components/native/Image.d.ts +3 -1
  249. package/lib/typescript/src/components/native/Image.d.ts.map +1 -1
  250. package/lib/typescript/src/components/native/ImageBackground.d.ts +8 -2
  251. package/lib/typescript/src/components/native/ImageBackground.d.ts.map +1 -1
  252. package/lib/typescript/src/components/native/ImageBackground.native.d.ts +3 -0
  253. package/lib/typescript/src/components/native/ImageBackground.native.d.ts.map +1 -0
  254. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts +3 -1
  255. package/lib/typescript/src/components/native/KeyboardAvoidingView.d.ts.map +1 -1
  256. package/lib/typescript/src/components/native/Pressable.d.ts +3 -2
  257. package/lib/typescript/src/components/native/Pressable.d.ts.map +1 -1
  258. package/lib/typescript/src/components/native/Pressable.native.d.ts.map +1 -1
  259. package/lib/typescript/src/components/native/RefreshControl.d.ts +3 -1
  260. package/lib/typescript/src/components/native/RefreshControl.d.ts.map +1 -1
  261. package/lib/typescript/src/components/native/ScrollView.d.ts +3 -1
  262. package/lib/typescript/src/components/native/ScrollView.d.ts.map +1 -1
  263. package/lib/typescript/src/components/native/SectionList.d.ts +3 -1
  264. package/lib/typescript/src/components/native/SectionList.d.ts.map +1 -1
  265. package/lib/typescript/src/components/native/Switch.d.ts +3 -1
  266. package/lib/typescript/src/components/native/Switch.d.ts.map +1 -1
  267. package/lib/typescript/src/components/native/Text.d.ts +3 -1
  268. package/lib/typescript/src/components/native/Text.d.ts.map +1 -1
  269. package/lib/typescript/src/components/native/TextInput.d.ts +3 -1
  270. package/lib/typescript/src/components/native/TextInput.d.ts.map +1 -1
  271. package/lib/typescript/src/components/native/TouchableHighlight.d.ts +3 -1
  272. package/lib/typescript/src/components/native/TouchableHighlight.d.ts.map +1 -1
  273. package/lib/typescript/src/components/native/TouchableOpacity.d.ts +3 -1
  274. package/lib/typescript/src/components/native/TouchableOpacity.d.ts.map +1 -1
  275. package/lib/typescript/src/components/native/View.d.ts +3 -1
  276. package/lib/typescript/src/components/native/View.d.ts.map +1 -1
  277. package/lib/typescript/src/components/native/VirtualizedList.d.ts +3 -1
  278. package/lib/typescript/src/components/native/VirtualizedList.d.ts.map +1 -1
  279. package/lib/typescript/src/core/createUnistylesElement.d.ts +6 -1
  280. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  281. package/lib/typescript/src/core/createUnistylesElement.native.d.ts +3 -0
  282. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -0
  283. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  284. package/lib/typescript/src/core/getClassname.d.ts +7 -0
  285. package/lib/typescript/src/core/getClassname.d.ts.map +1 -0
  286. package/lib/typescript/src/core/getClassname.native.d.ts +2 -0
  287. package/lib/typescript/src/core/getClassname.native.d.ts.map +1 -0
  288. package/lib/typescript/src/core/index.d.ts +2 -1
  289. package/lib/typescript/src/core/index.d.ts.map +1 -1
  290. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  291. package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts +2 -0
  292. package/lib/typescript/src/core/useProxifiedUnistyles/index.d.ts.map +1 -0
  293. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts +3 -0
  294. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -0
  295. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts +3 -0
  296. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -0
  297. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +7 -0
  298. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -0
  299. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts +8 -0
  300. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -0
  301. package/lib/typescript/src/core/useUnistyles.d.ts +6 -0
  302. package/lib/typescript/src/core/useUnistyles.d.ts.map +1 -0
  303. package/lib/typescript/src/core/warn.d.ts +3 -0
  304. package/lib/typescript/src/core/warn.d.ts.map +1 -0
  305. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts +0 -3
  306. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  307. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  308. package/lib/typescript/src/index.d.ts +3 -2
  309. package/lib/typescript/src/index.d.ts.map +1 -1
  310. package/lib/typescript/src/server/getServerUnistyles.d.ts +4 -0
  311. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -0
  312. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts +8 -0
  313. package/lib/typescript/src/server/hydrateServerUnistyles.d.ts.map +1 -0
  314. package/lib/typescript/src/server/index.d.ts +5 -0
  315. package/lib/typescript/src/server/index.d.ts.map +1 -0
  316. package/lib/typescript/src/server/resetServerUnistyles.d.ts +2 -0
  317. package/lib/typescript/src/server/resetServerUnistyles.d.ts.map +1 -0
  318. package/lib/typescript/src/server/types.d.ts +5 -0
  319. package/lib/typescript/src/server/types.d.ts.map +1 -0
  320. package/lib/typescript/src/server/useServerUnistyles.d.ts +4 -0
  321. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -0
  322. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +0 -3
  323. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  324. package/lib/typescript/src/specs/StyleSheet/index.d.ts +4 -1
  325. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  326. package/lib/typescript/src/utils.d.ts +1 -0
  327. package/lib/typescript/src/utils.d.ts.map +1 -1
  328. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  329. package/lib/typescript/src/web/create.d.ts.map +1 -1
  330. package/lib/typescript/src/web/css/core.d.ts +3 -0
  331. package/lib/typescript/src/web/css/core.d.ts.map +1 -0
  332. package/lib/typescript/src/web/css/index.d.ts +2 -0
  333. package/lib/typescript/src/web/css/index.d.ts.map +1 -0
  334. package/lib/typescript/src/web/css/state.d.ts +30 -0
  335. package/lib/typescript/src/web/css/state.d.ts.map +1 -0
  336. package/lib/typescript/src/web/css/utils.d.ts +4 -0
  337. package/lib/typescript/src/web/css/utils.d.ts.map +1 -0
  338. package/lib/typescript/src/web/index.d.ts +7 -1
  339. package/lib/typescript/src/web/index.d.ts.map +1 -1
  340. package/lib/typescript/src/web/listener.d.ts +4 -3
  341. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  342. package/lib/typescript/src/web/registry.d.ts +11 -8
  343. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  344. package/lib/typescript/src/web/runtime.d.ts +6 -4
  345. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  346. package/lib/typescript/src/web/services.d.ts +15 -0
  347. package/lib/typescript/src/web/services.d.ts.map +1 -0
  348. package/lib/typescript/src/web/shadowRegistry.d.ts +10 -13
  349. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  350. package/lib/typescript/src/web/state.d.ts +7 -3
  351. package/lib/typescript/src/web/state.d.ts.map +1 -1
  352. package/lib/typescript/src/web/types.d.ts +13 -0
  353. package/lib/typescript/src/web/types.d.ts.map +1 -0
  354. package/lib/typescript/src/web/utils/common.d.ts +2 -1
  355. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  356. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -4
  357. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  358. package/lib/typescript/src/web/variants.d.ts +2 -2
  359. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  360. package/nitrogen/generated/android/c++/JColorScheme.hpp +2 -1
  361. package/nitrogen/generated/android/c++/JDimensions.hpp +2 -1
  362. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +36 -10
  363. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +53 -19
  364. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +5 -5
  365. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +1 -1
  366. package/nitrogen/generated/android/c++/JInsets.hpp +2 -1
  367. package/nitrogen/generated/android/c++/JOrientation.hpp +2 -1
  368. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +2 -1
  369. package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +2 -1
  370. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/ColorScheme.kt +1 -1
  371. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +10 -5
  372. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_UnistylesNativeMiniRuntime.kt +43 -14
  373. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +43 -14
  374. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +10 -10
  375. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +13 -8
  376. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Orientation.kt +1 -1
  377. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +1 -1
  378. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +19 -14
  379. package/nitrogen/generated/android/unistyles+autolinking.cmake +4 -1
  380. package/nitrogen/generated/android/unistyles+autolinking.gradle +1 -1
  381. package/nitrogen/generated/android/unistylesOnLoad.cpp +7 -3
  382. package/nitrogen/generated/android/unistylesOnLoad.hpp +1 -1
  383. package/nitrogen/generated/ios/Unistyles+autolinking.rb +1 -1
  384. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +21 -6
  385. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +105 -27
  386. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +5 -3
  387. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.cpp +1 -1
  388. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +92 -33
  389. package/nitrogen/generated/ios/swift/ColorScheme.swift +1 -1
  390. package/nitrogen/generated/ios/swift/Dimensions.swift +1 -1
  391. package/nitrogen/generated/ios/swift/Func_void_UnistylesNativeMiniRuntime.swift +46 -0
  392. package/nitrogen/generated/ios/swift/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.swift +46 -0
  393. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +36 -23
  394. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec_cxx.swift +327 -0
  395. package/nitrogen/generated/ios/swift/Insets.swift +1 -1
  396. package/nitrogen/generated/ios/swift/Orientation.swift +1 -1
  397. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +1 -1
  398. package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +1 -1
  399. package/nitrogen/generated/shared/c++/ColorScheme.hpp +1 -1
  400. package/nitrogen/generated/shared/c++/Dimensions.hpp +1 -1
  401. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +1 -1
  402. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +1 -1
  403. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +1 -1
  404. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +1 -1
  405. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -1
  406. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +1 -1
  407. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.cpp +1 -1
  408. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +1 -1
  409. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +1 -1
  410. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +1 -1
  411. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  412. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +1 -1
  413. package/nitrogen/generated/shared/c++/Insets.hpp +1 -1
  414. package/nitrogen/generated/shared/c++/Orientation.hpp +1 -1
  415. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -2
  416. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +1 -1
  417. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +1 -1
  418. package/package.json +21 -12
  419. package/plugin/import.js +1 -21
  420. package/plugin/index.d.ts +41 -0
  421. package/plugin/index.js +44 -76
  422. package/plugin/stylesheet.js +17 -1
  423. package/plugin/variants.js +49 -75
  424. package/src/components/ScopedTheme.tsx +1 -1
  425. package/src/components/index.ts +0 -1
  426. package/src/components/native/ImageBackground.native.tsx +4 -0
  427. package/src/components/native/ImageBackground.tsx +54 -2
  428. package/src/components/native/Pressable.native.tsx +16 -17
  429. package/src/components/native/Pressable.tsx +35 -69
  430. package/src/core/createUnistylesElement.native.tsx +36 -0
  431. package/src/core/createUnistylesElement.tsx +42 -8
  432. package/src/core/createUnistylesImageBackground.tsx +40 -19
  433. package/src/core/getClassname.native.ts +1 -0
  434. package/src/core/getClassname.ts +13 -0
  435. package/src/core/index.ts +2 -1
  436. package/src/core/passForwardRef.ts +1 -2
  437. package/src/core/useProxifiedUnistyles/index.ts +1 -0
  438. package/src/core/useProxifiedUnistyles/listener.native.ts +18 -0
  439. package/src/core/useProxifiedUnistyles/listener.ts +13 -0
  440. package/src/core/useProxifiedUnistyles/types.ts +7 -0
  441. package/src/core/{withUnistyles/useDependencies.ts → useProxifiedUnistyles/useProxifiedUnistyles.ts} +19 -26
  442. package/src/core/useUnistyles.ts +11 -0
  443. package/src/core/warn.ts +13 -0
  444. package/src/core/withUnistyles/withUnistyles.native.tsx +39 -68
  445. package/src/core/withUnistyles/withUnistyles.tsx +19 -56
  446. package/src/index.ts +3 -2
  447. package/src/server/getServerUnistyles.tsx +20 -0
  448. package/src/server/hydrateServerUnistyles.ts +17 -0
  449. package/src/server/index.ts +5 -0
  450. package/src/server/resetServerUnistyles.ts +9 -0
  451. package/src/server/types.ts +4 -0
  452. package/src/server/useServerUnistyles.tsx +22 -0
  453. package/src/specs/ShadowRegistry/index.ts +12 -9
  454. package/src/specs/StyleSheet/index.ts +5 -1
  455. package/src/utils.ts +15 -11
  456. package/src/web/convert/object/filter.ts +2 -2
  457. package/src/web/convert/style.ts +8 -7
  458. package/src/web/create.ts +23 -18
  459. package/src/web/css/core.ts +58 -0
  460. package/src/web/css/index.ts +1 -0
  461. package/src/web/css/state.ts +191 -0
  462. package/src/web/css/utils.ts +54 -0
  463. package/src/web/index.ts +18 -5
  464. package/src/web/listener.ts +8 -8
  465. package/src/web/registry.ts +47 -152
  466. package/src/web/runtime.ts +32 -22
  467. package/src/web/services.ts +28 -0
  468. package/src/web/shadowRegistry.ts +46 -104
  469. package/src/web/state.ts +46 -11
  470. package/src/web/types.ts +13 -0
  471. package/src/web/utils/common.ts +32 -8
  472. package/src/web/utils/unistyle.ts +40 -25
  473. package/src/web/variants.ts +27 -27
  474. package/cxx/core/HostStyle.cpp +0 -73
  475. package/cxx/core/HostStyle.h +0 -34
  476. package/lib/commonjs/components/Variants.js +0 -36
  477. package/lib/commonjs/components/Variants.js.map +0 -1
  478. package/lib/commonjs/core/createUnistylesComponent.js +0 -16
  479. package/lib/commonjs/core/createUnistylesComponent.js.map +0 -1
  480. package/lib/commonjs/core/withUnistyles/useDependencies.js.map +0 -1
  481. package/lib/module/components/Variants.js +0 -29
  482. package/lib/module/components/Variants.js.map +0 -1
  483. package/lib/module/core/createUnistylesComponent.js +0 -11
  484. package/lib/module/core/createUnistylesComponent.js.map +0 -1
  485. package/lib/module/core/withUnistyles/useDependencies.js.map +0 -1
  486. package/lib/typescript/src/components/Variants.d.ts +0 -7
  487. package/lib/typescript/src/components/Variants.d.ts.map +0 -1
  488. package/lib/typescript/src/core/createUnistylesComponent.d.ts +0 -14
  489. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +0 -1
  490. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts +0 -13
  491. package/lib/typescript/src/core/withUnistyles/useDependencies.d.ts.map +0 -1
  492. package/nitrogen/generated/android/unistylesOnLoad.kt +0 -1
  493. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +0 -314
  494. package/plugin/style.js +0 -168
  495. package/src/components/Variants.tsx +0 -30
  496. package/src/core/createUnistylesComponent.tsx +0 -14
@@ -2,16 +2,16 @@ import { UnistyleDependency } from '../specs/NativePlatform'
2
2
  import { ColorScheme, Orientation, type AppTheme, type AppThemeName } from '../specs/types'
3
3
  import type { UnistylesMiniRuntime } from '../specs/UnistylesRuntime'
4
4
  import { WebContentSizeCategory } from '../types'
5
- import { UnistylesListener } from './listener'
6
5
  import { NavigationBar, StatusBar } from './mock'
7
6
  import { error, isServer, schemeToTheme } from './utils'
7
+ import type { UnistylesServices } from './types'
8
8
 
9
- // Keep this import here, otherwise circular dependency will occur and break the build
10
- import { UnistylesState } from './state'
11
-
12
- class UnistylesRuntimeBuilder {
9
+ export class UnistylesRuntime {
13
10
  lightMedia = this.getLightMedia()
14
11
  darkMedia = this.getDarkMedia()
12
+ rootElement = isServer() ? null : document.querySelector(':root')
13
+
14
+ constructor(private services: UnistylesServices) {}
15
15
 
16
16
  private getLightMedia(): MediaQueryList | null {
17
17
  if (isServer()) {
@@ -49,11 +49,11 @@ class UnistylesRuntimeBuilder {
49
49
  }
50
50
 
51
51
  get themeName() {
52
- if (UnistylesState.hasAdaptiveThemes) {
52
+ if (this.services.state.hasAdaptiveThemes) {
53
53
  return schemeToTheme(this.colorScheme) as AppThemeName
54
54
  }
55
55
 
56
- return UnistylesState.themeName
56
+ return this.services.state.themeName
57
57
  }
58
58
 
59
59
  get contentSizeCategory() {
@@ -61,11 +61,11 @@ class UnistylesRuntimeBuilder {
61
61
  }
62
62
 
63
63
  get breakpoints() {
64
- return UnistylesState.breakpoints ?? {}
64
+ return this.services.state.breakpoints ?? {}
65
65
  }
66
66
 
67
67
  get breakpoint() {
68
- return UnistylesState.breakpoint
68
+ return this.services.state.breakpoint
69
69
  }
70
70
 
71
71
  get orientation() {
@@ -121,7 +121,7 @@ class UnistylesRuntimeBuilder {
121
121
  }
122
122
 
123
123
  get hasAdaptiveThemes() {
124
- return UnistylesState.hasAdaptiveThemes
124
+ return this.services.state.hasAdaptiveThemes
125
125
  }
126
126
 
127
127
  get navigationBar() {
@@ -158,23 +158,33 @@ class UnistylesRuntimeBuilder {
158
158
  throw error(`You're trying to set theme to: '${themeName}', but adaptiveThemes are enabled.`)
159
159
  }
160
160
 
161
- if (themeName === UnistylesRuntime.themeName) {
161
+ if (themeName === this.themeName) {
162
162
  return
163
163
  }
164
164
 
165
- UnistylesState.themeName = themeName
166
- UnistylesListener.emitChange(UnistyleDependency.Theme)
167
- UnistylesListener.emitChange(UnistyleDependency.ThemeName)
165
+ const oldTheme = this.services.state.themeName
166
+
167
+ this.services.state.themeName = themeName
168
+ this.services.listener.emitChange(UnistyleDependency.Theme)
169
+ this.services.listener.emitChange(UnistyleDependency.ThemeName)
170
+
171
+ if (!isServer() && !this.services.state.hasAdaptiveThemes && this.services.state.CSSVars) {
172
+ this.rootElement?.classList.remove(oldTheme ?? '')
173
+ this.rootElement?.classList.add(themeName ?? '')
174
+ }
168
175
  }
169
176
 
170
177
  setAdaptiveThemes = (isEnabled: boolean) => {
171
- UnistylesState.hasAdaptiveThemes = isEnabled
178
+ this.services.state.hasAdaptiveThemes = isEnabled
172
179
 
173
180
  if (!isEnabled) {
181
+ this.rootElement?.classList.add(this.themeName ?? '')
182
+
174
183
  return
175
184
  }
176
185
 
177
- this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName)
186
+ this.rootElement?.classList.remove(this.themeName ?? '')
187
+ this.setTheme(schemeToTheme(this.colorScheme) as AppThemeName)
178
188
  }
179
189
 
180
190
  setRootViewBackgroundColor = (color: string) => {
@@ -188,17 +198,19 @@ class UnistylesRuntimeBuilder {
188
198
  setImmersiveMode = () => {}
189
199
 
190
200
  updateTheme = (themeName: AppThemeName, updater: (currentTheme: AppTheme) => AppTheme) => {
191
- const oldTheme = UnistylesState.themes.get(themeName)
201
+ const oldTheme = this.services.state.themes.get(themeName)
192
202
 
193
203
  if (!oldTheme) {
194
204
  throw error(`Unistyles: You're trying to update theme "${themeName}" but it wasn't registered.`)
195
205
  }
196
206
 
197
- UnistylesState.themes.set(themeName, updater(oldTheme))
207
+ this.services.state.themes.set(themeName, updater(oldTheme))
198
208
  }
199
209
 
200
- getTheme = (themeName = this.themeName) => {
201
- const theme = UnistylesState.themes.get(themeName ?? '')
210
+ getTheme = (themeName = this.themeName, CSSVars = false) => {
211
+ const theme = CSSVars
212
+ ? this.services.state.cssThemes.get(themeName ?? '')
213
+ : this.services.state.themes.get(themeName ?? '')
202
214
 
203
215
  if (!themeName || !theme) {
204
216
  throw error(`You're trying to get theme "${themeName}" but it wasn't registered.`)
@@ -207,5 +219,3 @@ class UnistylesRuntimeBuilder {
207
219
  return theme
208
220
  }
209
221
  }
210
-
211
- export const UnistylesRuntime = new UnistylesRuntimeBuilder()
@@ -0,0 +1,28 @@
1
+ import { UnistylesListener } from './listener'
2
+ import { UnistylesRegistry } from './registry'
3
+ import { UnistylesRuntime } from './runtime'
4
+ import { UnistylesShadowRegistry } from './shadowRegistry'
5
+ import { UnistylesState } from './state'
6
+
7
+ export class UnistylesServices {
8
+ runtime: UnistylesRuntime
9
+ registry: UnistylesRegistry
10
+ shadowRegistry: UnistylesShadowRegistry
11
+ state: UnistylesState
12
+ listener: UnistylesListener
13
+
14
+ private services = {} as UnistylesServices
15
+
16
+ constructor() {
17
+ this.runtime = new UnistylesRuntime(this.services)
18
+ this.registry = new UnistylesRegistry(this.services)
19
+ this.shadowRegistry = new UnistylesShadowRegistry(this.services)
20
+ this.state = new UnistylesState(this.services)
21
+ this.listener = new UnistylesListener(this.services)
22
+ this.services.runtime = this.runtime
23
+ this.services.registry = this.registry
24
+ this.services.shadowRegistry = this.shadowRegistry
25
+ this.services.state = this.state
26
+ this.services.listener = this.listener
27
+ }
28
+ }
@@ -1,13 +1,11 @@
1
1
  import type { UnistylesTheme, UnistylesValues } from '../types'
2
- import { UnistylesListener } from './listener'
3
- import { UnistylesRegistry } from './registry'
4
2
  import { deepMergeObjects } from '../utils'
5
- import { equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils'
3
+ import { extractSecrets, extractUnistyleDependencies } from './utils'
6
4
  import { getVariants } from './variants'
5
+ import type { UnistylesServices } from './types'
6
+ import { UnistyleDependency } from '../specs'
7
7
 
8
- type Style = UnistylesValues | ((...args: Array<any>) => UnistylesValues)
9
-
10
- class UnistylesShadowRegistryBuilder {
8
+ export class UnistylesShadowRegistry {
11
9
  // MOCKS
12
10
  name = 'UnistylesShadowRegistry'
13
11
  __type = 'web'
@@ -16,131 +14,68 @@ class UnistylesShadowRegistryBuilder {
16
14
  dispose = () => {}
17
15
  // END MOCKS
18
16
 
19
- private resultsMap = new Map<HTMLElement, UnistylesValues>()
20
- private classNamesMap = new Map<HTMLElement, Array<string>>()
21
- private selectedVariants = new Map<string, string | boolean | undefined>()
22
17
  private scopedTheme: UnistylesTheme | undefined = undefined
23
- private disposeMap = new Map<HTMLElement, VoidFunction>()
24
-
25
- add = (ref: any, styles: Array<Style>) => {
26
- // Styles are not provided
27
- if (!styles || !Array.isArray(styles)) {
28
- return
29
- }
18
+ private disposeMap = new Map<string, VoidFunction>()
30
19
 
31
- // Ref is unmounted
32
- if (ref === null) {
33
- styles.flat().forEach(style => {
34
- extractSecrets(style)?.__uni__refs.forEach(ref => {
35
- if (isInDocument(ref)) {
36
- return
37
- }
38
-
39
- const oldResult = this.resultsMap.get(ref)
40
-
41
- this.resultsMap.delete(ref)
42
- this.classNamesMap.delete(ref)
43
- this.disposeMap.get(ref)?.()
44
- this.disposeMap.delete(ref)
45
-
46
- if (oldResult) {
47
- UnistylesRegistry.remove(oldResult)
48
- }
49
- })
50
- })
20
+ constructor(private services: UnistylesServices) {}
51
21
 
22
+ add = (ref: any, hash?: string) => {
23
+ if (!(ref instanceof HTMLElement) || !hash) {
52
24
  return
53
25
  }
54
26
 
55
- // Ref is not an HTMLElement
56
- if (!(ref instanceof HTMLElement)) {
57
- return
58
- }
27
+ this.services.registry.connect(ref, hash)
28
+ }
59
29
 
30
+ addStyles = (unistyles: Array<UnistylesValues>) => {
60
31
  const getParsedStyles = () => {
61
- return styles.flat().flatMap(unistyleStyle => {
62
- if (!unistyleStyle) {
63
- return []
64
- }
65
-
66
- const secrets = extractSecrets(unistyleStyle)
32
+ const allStyles = unistyles.map(unistyle => {
33
+ const secrets = extractSecrets(unistyle)
67
34
 
68
35
  // Regular style
69
36
  if (!secrets) {
70
- return unistyleStyle as UnistylesValues
37
+ return unistyle
71
38
  }
72
39
 
73
- const { __uni__key, __uni__stylesheet, __uni__args = [], __uni__refs } = secrets
74
- const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
40
+ const { __uni__key, __uni__stylesheet, __uni__args = [], __uni_variants: variants } = secrets
41
+ const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
75
42
  const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
76
- const args = __uni__args
77
43
  const result = typeof style === 'function'
78
- ? style(...args)
44
+ ? style(...__uni__args)
79
45
  : style
80
- const { variantsResult } = Object.fromEntries(getVariants({ variantsResult: result }, variants))
81
- const resultWithVariants = deepMergeObjects(result, variantsResult ?? {})
46
+ const variantsResult = getVariants(result, variants)
47
+ const resultWithVariants = deepMergeObjects(result, variantsResult)
82
48
  const dependencies = extractUnistyleDependencies(resultWithVariants)
83
49
 
84
50
  if (typeof __uni__stylesheet === 'function') {
85
51
  // Add dependencies from dynamic styles to stylesheet
86
- UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
52
+ this.services.registry.addDependenciesToStylesheet(__uni__stylesheet, dependencies)
87
53
  }
88
54
 
89
- __uni__refs.add(ref)
90
-
91
55
  return resultWithVariants as UnistylesValues
92
56
  })
57
+
58
+ return deepMergeObjects(...allStyles)
93
59
  }
94
60
 
95
61
  // Copy scoped theme to not use referenced value
96
- const variants = this.getVariants()
97
62
  const scopedTheme = this.scopedTheme
98
63
  const parsedStyles = getParsedStyles()
99
- const combinedStyles = deepMergeObjects(...parsedStyles)
100
- const oldStyles = this.resultsMap.get(ref)
101
-
102
- if (equal(combinedStyles, oldStyles)) {
103
- return
64
+ const { hash, existingHash } = this.services.registry.add(parsedStyles)
65
+ const injectedClassNames = parsedStyles?._web?._classNames ?? []
66
+ const injectedClassName = Array.isArray(injectedClassNames) ? injectedClassNames.join(' ') : injectedClassNames
67
+ const dependencies = extractUnistyleDependencies(parsedStyles)
68
+ const filteredDependencies = this.services.state.CSSVars
69
+ ? dependencies.filter(dependency => dependency !== UnistyleDependency.Theme)
70
+ : dependencies
71
+
72
+ if (!existingHash) {
73
+ this.disposeMap.set(hash, this.services.listener.addListeners(filteredDependencies, () => {
74
+ this.services.registry.applyStyles(hash, getParsedStyles())
75
+ }))
104
76
  }
105
77
 
106
- const oldClassNames = this.classNamesMap.get(ref)
107
-
108
- // Remove old styles
109
- if (oldStyles) {
110
- UnistylesRegistry.remove(oldStyles)
111
- }
112
-
113
- // Remove old classnames from the ref
114
- oldClassNames?.forEach(className => ref.classList.remove(className))
115
- this.resultsMap.set(ref, combinedStyles)
116
-
117
- const { hash } = UnistylesRegistry.add(combinedStyles)
118
- const injectedClassNames = combinedStyles?._web?._classNames ?? []
119
- const newClassNames = (Array.isArray(injectedClassNames) ? injectedClassNames : [injectedClassNames]).concat(hash)
120
- const dependencies = Array.from(new Set(parsedStyles.flatMap(style => extractUnistyleDependencies(style))))
121
-
122
- this.disposeMap.get(ref)?.()
123
- this.disposeMap.set(ref, UnistylesListener.addListeners(dependencies, () => {
124
- UnistylesRegistry.applyStyles(hash, deepMergeObjects(...getParsedStyles()))
125
- }))
126
- this.classNamesMap.set(ref, newClassNames)
127
- // Add new classnames to the ref
128
- ref.classList.add(...newClassNames)
129
- ref.removeAttribute('styles')
130
-
131
- return newClassNames
132
- }
133
-
134
- selectVariants = (variants?: Record<string, string | boolean | undefined>) => {
135
- if (!variants) {
136
- this.selectedVariants.clear()
137
-
138
- return
139
- }
140
-
141
- Object.entries(variants).forEach(([key, value]) => {
142
- this.selectedVariants.set(key, value)
143
- })
78
+ return { injectedClassName, hash }
144
79
  }
145
80
 
146
81
  setScopedTheme = (theme?: UnistylesTheme) => {
@@ -149,9 +84,16 @@ class UnistylesShadowRegistryBuilder {
149
84
 
150
85
  getScopedTheme = () => this.scopedTheme
151
86
 
152
- getVariants = () => Object.fromEntries(this.selectedVariants.entries())
87
+ remove = (ref: any, hash?: string) => {
88
+ if (!(ref instanceof HTMLElement) || !hash) {
89
+ return
90
+ }
153
91
 
154
- remove = () => {}
155
- }
92
+ const removed = this.services.registry.remove(ref, hash)
156
93
 
157
- export const UnistylesShadowRegistry = new UnistylesShadowRegistryBuilder()
94
+ if (removed) {
95
+ this.disposeMap.get(hash)?.()
96
+ this.disposeMap.delete(hash)
97
+ }
98
+ }
99
+ }
package/src/web/state.ts CHANGED
@@ -2,17 +2,19 @@ import type { UnistylesTheme } from '../types'
2
2
  import type { UnistylesConfig } from '../specs/StyleSheet'
3
3
  import type { AppBreakpoint, AppTheme, AppThemeName } from '../specs/types'
4
4
  import type { UnistylesBreakpoints, UnistylesThemes } from '../global'
5
- import { UnistylesRuntime } from './runtime'
6
- import { error, isServer, schemeToTheme } from './utils'
7
- import { UnistylesListener } from './listener'
5
+ import { error, hyphenate, isServer, schemeToTheme } from './utils'
8
6
  import { UnistyleDependency } from '../specs/NativePlatform'
9
7
  import type { UnionToIntersection } from '../types'
8
+ import type { UnistylesServices } from './types'
10
9
 
11
10
  type UnistylesSettings = Partial<UnionToIntersection<Required<UnistylesConfig>['settings']>>
12
11
 
13
- class UnistylesStateBuilder {
12
+ export class UnistylesState {
13
+ isInitialized = false
14
14
  themes = new Map<string, UnistylesTheme>()
15
+ cssThemes = new Map<string, UnistylesTheme>()
15
16
  themeName?: AppThemeName
17
+ CSSVars = true
16
18
 
17
19
  private matchingBreakpoints = new Map<string, boolean>()
18
20
 
@@ -28,8 +30,15 @@ class UnistylesStateBuilder {
28
30
 
29
31
  hasAdaptiveThemes = false
30
32
 
33
+ constructor(private services: UnistylesServices) {}
34
+
31
35
  init = (config: UnistylesConfig) => {
32
- this.initThemes(config.themes)
36
+ if (this.isInitialized) {
37
+ return
38
+ }
39
+
40
+ this.isInitialized = true
41
+ this.initThemes(config.themes, config.settings?.CSSVars)
33
42
  this.initBreakpoints(config.breakpoints)
34
43
 
35
44
  if (config.settings) {
@@ -40,12 +49,40 @@ class UnistylesStateBuilder {
40
49
  return
41
50
  }
42
51
 
43
- UnistylesListener.initListeners()
52
+ // Ensure we have a themeName before calling this
53
+ // classList.add throws a "SyntaxError" DOMException if one of the arguments is an empty string.
54
+ if (!this.hasAdaptiveThemes && this.CSSVars && this.themeName) {
55
+ document.querySelector(':root')?.classList.add(this.themeName)
56
+ }
57
+
58
+ this.services.listener.initListeners()
44
59
  }
45
60
 
46
- private initThemes = (themes = {} as UnistylesThemes) => {
61
+ private initThemes = (themes = {} as UnistylesThemes, CSSVars = true) => {
62
+ this.CSSVars = CSSVars
63
+
47
64
  Object.entries(themes).forEach(([themeName, theme]) => {
48
65
  this.themes.set(themeName, theme as AppTheme)
66
+
67
+ if (CSSVars) {
68
+ this.services.registry.css.addTheme(themeName, theme)
69
+
70
+ const convertTheme = (key: string, value: any, prev = '-'): [string, any] => {
71
+ if (typeof value === 'object' && value !== null) {
72
+ return [key, Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => convertTheme(nestedKey, nestedValue, `${prev}-${key}`)))]
73
+ }
74
+
75
+ if (typeof value === 'string') {
76
+ return [key, `var(${prev}-${hyphenate(key)})`]
77
+ }
78
+
79
+ return [key, value]
80
+ }
81
+
82
+ this.cssThemes.set(themeName, Object.fromEntries(Object.entries(theme).map(([key, value]) => {
83
+ return convertTheme(key, value)
84
+ })) as UnistylesTheme)
85
+ }
49
86
  })
50
87
  }
51
88
 
@@ -62,7 +99,7 @@ class UnistylesStateBuilder {
62
99
  throw error(`You're trying to enable adaptiveThemes, but you didn't register both 'light' and 'dark' themes.`)
63
100
  }
64
101
 
65
- this.themeName = schemeToTheme(UnistylesRuntime.colorScheme) as AppThemeName
102
+ this.themeName = schemeToTheme(this.services.runtime.colorScheme) as AppThemeName
66
103
 
67
104
  return
68
105
  }
@@ -104,10 +141,8 @@ class UnistylesStateBuilder {
104
141
 
105
142
  mediaQuery.addEventListener('change', event => {
106
143
  this.matchingBreakpoints.set(breakpoint, event.matches)
107
- UnistylesListener.emitChange(UnistyleDependency.Breakpoints)
144
+ this.services.listener.emitChange(UnistyleDependency.Breakpoints)
108
145
  })
109
146
  })
110
147
  }
111
148
  }
112
-
113
- export const UnistylesState = new UnistylesStateBuilder()
@@ -0,0 +1,13 @@
1
+ import type { UnistylesListener } from './listener'
2
+ import type{ UnistylesRegistry } from './registry'
3
+ import type{ UnistylesRuntime } from './runtime'
4
+ import type{ UnistylesShadowRegistry } from './shadowRegistry'
5
+ import type{ UnistylesState } from './state'
6
+
7
+ export type UnistylesServices = {
8
+ runtime: UnistylesRuntime,
9
+ registry: UnistylesRegistry,
10
+ shadowRegistry: UnistylesShadowRegistry,
11
+ state: UnistylesState,
12
+ listener: UnistylesListener
13
+ }
@@ -5,7 +5,7 @@ export const reduceObject = <TObj extends Record<string, any>, TReducer>(
5
5
 
6
6
  export const keyInObject = <T extends Record<string, any>>(obj: T, key: PropertyKey): key is keyof T => key in obj
7
7
 
8
- export const isServer = () => typeof window === 'undefined'
8
+ export const isServer = () => typeof window === 'undefined' || typeof document === 'undefined'
9
9
 
10
10
  export const error = (message: string) => new Error(`Unistyles: ${message}`)
11
11
 
@@ -32,14 +32,38 @@ export const equal = <T>(a: T, b: T) => {
32
32
  return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key))
33
33
  }
34
34
 
35
- export const generateHash = (value: any) => {
36
- const str = JSON.stringify(value)
37
- let hasher = 5381
38
- let length = str.length
35
+ export const hyphenate = (propertyName: string) => propertyName.replace(/[A-Z]/g, (m: string) => `-${m.toLowerCase()}`)
36
+
37
+ export const serialize = (obj: string | number | object): string => {
38
+ if (typeof obj !== 'object') {
39
+ return String(obj)
40
+ }
39
41
 
40
- while (length--) hasher = (hasher * 33) ^ str.charCodeAt(length)
42
+ const sortedKeys = Object.keys(obj).sort()
43
+ const sortedKeyValuePairs = sortedKeys.map(key => `${key}:${serialize(obj[key as keyof typeof obj])}`)
41
44
 
42
- return `unistyles-${(hasher >>> 0).toString(36)}`
45
+ return `{${sortedKeyValuePairs.join(',')}}`
43
46
  }
44
47
 
45
- export const hyphenate = (propertyName: string) => propertyName.replace(/[A-Z]/g, (m: string) => `-${m.toLowerCase()}`)
48
+ // Based on https://github.com/bryc/code/blob/master/jshash/experimental/cyrb53.js
49
+ const cyrb53 = (data: string, seed = 0) => {
50
+ let h1 = 0xdeadbeef ^ seed
51
+ let h2 = 0x41c6ce57 ^ seed
52
+
53
+ for (let i = 0, ch: number; i < data.length; i++) {
54
+ ch = data.charCodeAt(i)
55
+ h1 = Math.imul(h1 ^ ch, 2654435761)
56
+ h2 = Math.imul(h2 ^ ch, 1597334677)
57
+ }
58
+
59
+ h1 = Math.imul(h1 ^ (h1 >>> 16), 2246822507) ^ Math.imul(h2 ^ (h2 >>> 13), 3266489909)
60
+ h2 = Math.imul(h2 ^ (h2 >>> 16), 2246822507) ^ Math.imul(h1 ^ (h1 >>> 13), 3266489909)
61
+
62
+ return 4294967296 * (2097151 & h2) + (h1 >>> 0)
63
+ }
64
+
65
+ export const generateHash = (value: any) => {
66
+ const serialized = serialize(value)
67
+
68
+ return `unistyles-${cyrb53(serialized).toString(36)}`
69
+ }
@@ -2,8 +2,9 @@ import type { UnistyleDependency } from '../../specs/NativePlatform'
2
2
  import { ColorScheme, Orientation } from '../../specs/types'
3
3
  import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
4
4
  import { isUnistylesMq, parseMq } from '../../mq'
5
- import { UnistylesState } from '../state'
6
5
  import { keyInObject, reduceObject } from './common'
6
+ import type { UnistylesBreakpoints } from '../../global'
7
+ import { UnistylesWeb } from '../index'
7
8
 
8
9
  export const schemeToTheme = (scheme: ColorScheme) => {
9
10
  switch (scheme) {
@@ -18,19 +19,37 @@ export const schemeToTheme = (scheme: ColorScheme) => {
18
19
  export type UnistyleSecrets = {
19
20
  __uni__stylesheet: StyleSheetWithSuperPowers<StyleSheet>,
20
21
  __uni__key: string,
21
- __uni__refs: Set<HTMLElement>
22
- __uni__args?: Array<any>
22
+ __uni__args?: Array<any>,
23
+ __uni_variants: Record<string, string | boolean | undefined>
23
24
  }
24
25
 
25
26
  export const assignSecrets = <T>(object: T, secrets: UnistyleSecrets) => {
26
- // @ts-expect-error - assign secrets to object
27
- object.__uni__secrets__ = secrets
27
+ const secretsId = Math.random().toString(36).slice(8)
28
+
29
+ // @ts-expect-error assign hidden secrets
30
+ object[`unistyles-${secretsId}`] = {}
31
+ // @ts-expect-error assign hidden secrets
32
+ Object.defineProperties(object[`unistyles-${secretsId}`], reduceObject(secrets, secret => ({
33
+ value: secret,
34
+ enumerable: false,
35
+ configurable: true
36
+ })))
28
37
 
29
38
  return object
30
39
  }
31
40
 
32
41
  export const extractSecrets = (object: any) => {
33
- return object && keyInObject(object, '__uni__secrets__') ? object.__uni__secrets__ as UnistyleSecrets : undefined
42
+ if (!object) {
43
+ return undefined
44
+ }
45
+
46
+ const [, secrets] = Object.entries(object).find(([key]) => key.startsWith('unistyles-')) ?? []
47
+
48
+ if (!secrets) {
49
+ return undefined
50
+ }
51
+
52
+ return reduceObject(Object.getOwnPropertyDescriptors(secrets), secret => secret.value)
34
53
  }
35
54
 
36
55
  export const removeInlineStyles = (values: UnistylesValues) => {
@@ -47,39 +66,35 @@ export const removeInlineStyles = (values: UnistylesValues) => {
47
66
 
48
67
  export const isInDocument = (element: HTMLElement) => document.body.contains(element)
49
68
 
50
- export const extractMediaQueryValue = (query: string) => {
51
- const [_, px] = query.match(/(\d+)px/) ?? []
52
-
53
- if (!px) {
54
- return undefined
55
- }
56
-
57
- const value = Number(px)
58
-
59
- return Number.isNaN(value)
60
- ? undefined
61
- : value
62
- }
63
-
64
- export const getMediaQuery = (query: string) => {
69
+ export const getMediaQuery = (query: string, allBreakpoints: Array<string>) => {
65
70
  if (Object.values(Orientation).includes(query as Orientation)) {
66
- return `(orientation: ${query})`
71
+ return `@media (orientation: ${query})`
67
72
  }
68
73
 
69
74
  if (isUnistylesMq(query)) {
70
75
  const { minWidth, maxWidth, minHeight, maxHeight } = parseMq(query)
71
76
 
72
- return [
77
+ const queries = [
73
78
  minWidth ? `(min-width: ${minWidth}px)` : undefined,
74
79
  maxWidth ? `(max-width: ${maxWidth}px)` : undefined,
75
80
  minHeight ? `(min-height: ${minHeight}px)` : undefined,
76
81
  maxHeight ? `(max-height: ${maxHeight}px)` : undefined
77
82
  ].filter(Boolean).join(' and ')
83
+ return `@media ${queries}`
78
84
  }
79
85
 
80
- const minWidth = UnistylesState.breakpoints && keyInObject(UnistylesState.breakpoints, query) ? UnistylesState.breakpoints[query] : undefined
86
+ const breakpointValue = UnistylesWeb.runtime.breakpoints[query as keyof UnistylesBreakpoints] ?? 0
87
+ const nextBreakpoint = allBreakpoints
88
+ .filter((b): b is keyof UnistylesBreakpoints => b in UnistylesWeb.runtime.breakpoints)
89
+ .map(b => UnistylesWeb.runtime.breakpoints[b] as number)
90
+ .sort((a, b) => a - b)
91
+ .find(b => b > breakpointValue)
92
+ const queries = [
93
+ `(min-width: ${breakpointValue}px)`,
94
+ nextBreakpoint ? `(max-width: ${nextBreakpoint - 1}px)` : undefined,
95
+ ].filter(Boolean).join(' and ')
81
96
 
82
- return `(min-width: ${minWidth ?? 0}px)`
97
+ return `@media ${queries}`
83
98
  }
84
99
 
85
100
  export const extractUnistyleDependencies = (value: any) => {