react-native-unistyles 3.0.0-alpha.4 → 3.0.0-alpha.40

Sign up to get free protection for your applications and to get access to all the features.
Files changed (539) hide show
  1. package/README.md +7 -0
  2. package/Unistyles.podspec +1 -1
  3. package/android/CMakeLists.txt +19 -45
  4. package/android/build.gradle +6 -5
  5. package/android/src/main/cxx/NativeUnistylesModule.cpp +71 -0
  6. package/android/src/main/cxx/NativeUnistylesModule.h +42 -0
  7. package/android/src/main/cxx/cpp-adapter.cpp +8 -86
  8. package/android/src/main/java/com/unistyles/Equatable.kt +61 -0
  9. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +285 -0
  10. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +152 -0
  11. package/android/src/main/java/com/unistyles/NativePlatform+listener.kt +59 -0
  12. package/android/src/main/java/com/unistyles/UnistylesModule.kt +51 -0
  13. package/android/src/main/java/com/unistyles/UnistylesPackage.kt +16 -14
  14. package/cxx/NativePlatform.h +11 -0
  15. package/cxx/common/Constants.h +3 -0
  16. package/cxx/common/Helpers.h +140 -5
  17. package/cxx/core/HostStyle.cpp +10 -6
  18. package/cxx/core/HostStyle.h +4 -0
  19. package/cxx/core/StyleSheet.h +0 -2
  20. package/cxx/core/StyleSheetRegistry.cpp +9 -17
  21. package/cxx/core/StyleSheetRegistry.h +3 -4
  22. package/cxx/core/Unistyle.h +8 -11
  23. package/cxx/core/UnistyleData.h +23 -0
  24. package/cxx/core/UnistyleWrapper.h +108 -13
  25. package/cxx/core/UnistylesCommitHook.cpp +14 -15
  26. package/cxx/core/UnistylesCommitHook.h +6 -11
  27. package/cxx/core/UnistylesCommitShadowNode.h +13 -0
  28. package/cxx/core/UnistylesMountHook.cpp +28 -0
  29. package/cxx/core/UnistylesMountHook.h +27 -0
  30. package/cxx/core/UnistylesRegistry.cpp +119 -83
  31. package/cxx/core/UnistylesRegistry.h +16 -14
  32. package/cxx/core/UnistylesState.cpp +29 -8
  33. package/cxx/core/UnistylesState.h +5 -2
  34. package/cxx/hybridObjects/HybridNavigationBar.cpp +0 -4
  35. package/cxx/hybridObjects/HybridNavigationBar.h +3 -4
  36. package/cxx/hybridObjects/HybridShadowRegistry.cpp +16 -11
  37. package/cxx/hybridObjects/HybridStatusBar.cpp +0 -4
  38. package/cxx/hybridObjects/HybridStatusBar.h +3 -4
  39. package/cxx/hybridObjects/HybridStyleSheet.cpp +154 -23
  40. package/cxx/hybridObjects/HybridStyleSheet.h +27 -5
  41. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +96 -14
  42. package/cxx/hybridObjects/HybridUnistylesRuntime.h +19 -3
  43. package/cxx/parser/Parser.cpp +226 -175
  44. package/cxx/parser/Parser.h +11 -15
  45. package/cxx/shadowTree/ShadowLeafUpdate.h +2 -1
  46. package/cxx/shadowTree/ShadowTrafficController.h +71 -0
  47. package/cxx/shadowTree/ShadowTreeManager.cpp +23 -18
  48. package/cxx/shadowTree/ShadowTreeManager.h +3 -2
  49. package/ios/Equatable.swift +2 -1
  50. package/ios/NativePlatform+ios.swift +21 -7
  51. package/ios/NativePlatform+keyboard.swift +83 -0
  52. package/ios/NativePlatformListener+ios.swift +37 -24
  53. package/ios/Unistyles.h +1 -0
  54. package/ios/UnistylesModuleOnLoad.h +8 -2
  55. package/ios/UnistylesModuleOnLoad.mm +9 -1
  56. package/lib/commonjs/components/Display.js +18 -0
  57. package/lib/commonjs/components/Display.js.map +1 -0
  58. package/lib/commonjs/components/Hide.js +18 -0
  59. package/lib/commonjs/components/Hide.js.map +1 -0
  60. package/lib/commonjs/components/index.js +20 -0
  61. package/lib/commonjs/components/index.js.map +1 -0
  62. package/lib/commonjs/components/useMedia.js +59 -0
  63. package/lib/commonjs/components/useMedia.js.map +1 -0
  64. package/lib/commonjs/components/useMedia.web.js +43 -0
  65. package/lib/commonjs/components/useMedia.web.js.map +1 -0
  66. package/lib/commonjs/core/createUnistylesComponent.js +79 -0
  67. package/lib/commonjs/core/createUnistylesComponent.js.map +1 -0
  68. package/lib/commonjs/core/createUnistylesComponent.native.js +82 -0
  69. package/lib/commonjs/core/createUnistylesComponent.native.js.map +1 -0
  70. package/lib/commonjs/core/index.js +13 -0
  71. package/lib/commonjs/core/index.js.map +1 -0
  72. package/lib/commonjs/index.js +21 -11
  73. package/lib/commonjs/index.js.map +1 -1
  74. package/lib/commonjs/mq.js +25 -12
  75. package/lib/commonjs/mq.js.map +1 -1
  76. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  77. package/lib/commonjs/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  78. package/lib/commonjs/specs/NavigtionBar/index.js +0 -15
  79. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  80. package/lib/commonjs/specs/ShadowRegistry/index.js +10 -6
  81. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  82. package/lib/commonjs/specs/StatusBar/index.js +0 -5
  83. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  84. package/lib/commonjs/specs/StyleSheet/index.js +1 -0
  85. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  86. package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -3
  87. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  88. package/lib/commonjs/specs/index.js +7 -0
  89. package/lib/commonjs/specs/index.js.map +1 -1
  90. package/lib/commonjs/specs/index.web.js +1 -1
  91. package/lib/commonjs/types/stylesheet.js.map +1 -1
  92. package/lib/commonjs/utils.js +26 -0
  93. package/lib/commonjs/utils.js.map +1 -0
  94. package/lib/commonjs/web/convert/index.js +79 -0
  95. package/lib/commonjs/web/convert/index.js.map +1 -0
  96. package/lib/commonjs/web/convert/module.d.js +2 -0
  97. package/lib/commonjs/web/convert/module.d.js.map +1 -0
  98. package/lib/commonjs/web/convert/object/boxShadow.js +59 -0
  99. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -0
  100. package/lib/commonjs/web/convert/object/filter.js +42 -0
  101. package/lib/commonjs/web/convert/object/filter.js.map +1 -0
  102. package/lib/commonjs/web/convert/object/index.js +39 -0
  103. package/lib/commonjs/web/convert/object/index.js.map +1 -0
  104. package/lib/commonjs/web/convert/object/objectStyle.js +56 -0
  105. package/lib/commonjs/web/convert/object/objectStyle.js.map +1 -0
  106. package/lib/commonjs/web/convert/object/transform.js +27 -0
  107. package/lib/commonjs/web/convert/object/transform.js.map +1 -0
  108. package/lib/commonjs/web/convert/pseudo.js +10 -0
  109. package/lib/commonjs/web/convert/pseudo.js.map +1 -0
  110. package/lib/commonjs/web/convert/shadow/boxShadow.js +62 -0
  111. package/lib/commonjs/web/convert/shadow/boxShadow.js.map +1 -0
  112. package/lib/commonjs/web/convert/shadow/getShadowBreakpoints.js +38 -0
  113. package/lib/commonjs/web/convert/shadow/getShadowBreakpoints.js.map +1 -0
  114. package/lib/commonjs/web/convert/shadow/index.js +28 -0
  115. package/lib/commonjs/web/convert/shadow/index.js.map +1 -0
  116. package/lib/commonjs/web/convert/shadow/textShadow.js +59 -0
  117. package/lib/commonjs/web/convert/shadow/textShadow.js.map +1 -0
  118. package/lib/commonjs/web/convert/style.js +93 -0
  119. package/lib/commonjs/web/convert/style.js.map +1 -0
  120. package/lib/commonjs/web/convert/types.js +9 -0
  121. package/lib/commonjs/web/convert/types.js.map +1 -0
  122. package/lib/commonjs/web/convert/utils.js +59 -0
  123. package/lib/commonjs/web/convert/utils.js.map +1 -0
  124. package/lib/commonjs/web/create.js +49 -0
  125. package/lib/commonjs/web/create.js.map +1 -0
  126. package/lib/commonjs/web/index.js +60 -0
  127. package/lib/commonjs/web/index.js.map +1 -0
  128. package/lib/commonjs/web/listener.js +61 -0
  129. package/lib/commonjs/web/listener.js.map +1 -0
  130. package/lib/commonjs/web/mock.js +27 -0
  131. package/lib/commonjs/web/mock.js.map +1 -0
  132. package/lib/commonjs/web/registry.js +172 -0
  133. package/lib/commonjs/web/registry.js.map +1 -0
  134. package/lib/commonjs/web/runtime.js +173 -0
  135. package/lib/commonjs/web/runtime.js.map +1 -0
  136. package/lib/commonjs/web/shadowRegistry.js +142 -0
  137. package/lib/commonjs/web/shadowRegistry.js.map +1 -0
  138. package/lib/commonjs/web/state.js +73 -0
  139. package/lib/commonjs/web/state.js.map +1 -0
  140. package/lib/commonjs/web/utils/common.js +39 -0
  141. package/lib/commonjs/web/utils/common.js.map +1 -0
  142. package/lib/commonjs/web/utils/index.js +28 -0
  143. package/lib/commonjs/web/utils/index.js.map +1 -0
  144. package/lib/commonjs/web/utils/unistyle.js +85 -0
  145. package/lib/commonjs/web/utils/unistyle.js.map +1 -0
  146. package/lib/commonjs/web/variants/getVariants.js +39 -0
  147. package/lib/commonjs/web/variants/getVariants.js.map +1 -0
  148. package/lib/commonjs/web/variants/index.js +28 -0
  149. package/lib/commonjs/web/variants/index.js.map +1 -0
  150. package/lib/commonjs/web/variants/useVariants.js +59 -0
  151. package/lib/commonjs/web/variants/useVariants.js.map +1 -0
  152. package/lib/module/components/Display.js +13 -0
  153. package/lib/module/components/Display.js.map +1 -0
  154. package/lib/module/components/Hide.js +13 -0
  155. package/lib/module/components/Hide.js.map +1 -0
  156. package/lib/module/components/index.js +5 -0
  157. package/lib/module/components/index.js.map +1 -0
  158. package/lib/module/components/useMedia.js +54 -0
  159. package/lib/module/components/useMedia.js.map +1 -0
  160. package/lib/module/components/useMedia.web.js +38 -0
  161. package/lib/module/components/useMedia.web.js.map +1 -0
  162. package/lib/module/core/createUnistylesComponent.js +72 -0
  163. package/lib/module/core/createUnistylesComponent.js.map +1 -0
  164. package/lib/module/core/createUnistylesComponent.native.js +75 -0
  165. package/lib/module/core/createUnistylesComponent.native.js.map +1 -0
  166. package/lib/module/core/index.js +4 -0
  167. package/lib/module/core/index.js.map +1 -0
  168. package/lib/module/index.js +2 -9
  169. package/lib/module/index.js.map +1 -1
  170. package/lib/module/mq.js +21 -11
  171. package/lib/module/mq.js.map +1 -1
  172. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js +1 -0
  173. package/lib/module/specs/NativePlatform/NativePlatform.nitro.js.map +1 -1
  174. package/lib/module/specs/NavigtionBar/index.js +0 -10
  175. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  176. package/lib/module/specs/ShadowRegistry/index.js +10 -6
  177. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  178. package/lib/module/specs/StatusBar/index.js +1 -6
  179. package/lib/module/specs/StatusBar/index.js.map +1 -1
  180. package/lib/module/specs/StyleSheet/index.js +1 -0
  181. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  182. package/lib/module/specs/UnistylesRuntime/index.js +1 -3
  183. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  184. package/lib/module/specs/index.js +2 -1
  185. package/lib/module/specs/index.js.map +1 -1
  186. package/lib/module/specs/index.web.js +1 -1
  187. package/lib/module/specs/index.web.js.map +1 -1
  188. package/lib/module/types/stylesheet.js.map +1 -1
  189. package/lib/module/utils.js +21 -0
  190. package/lib/module/utils.js.map +1 -0
  191. package/lib/module/web/convert/index.js +74 -0
  192. package/lib/module/web/convert/index.js.map +1 -0
  193. package/lib/module/web/convert/module.d.js +2 -0
  194. package/lib/module/web/convert/module.d.js.map +1 -0
  195. package/lib/module/web/convert/object/boxShadow.js +54 -0
  196. package/lib/module/web/convert/object/boxShadow.js.map +1 -0
  197. package/lib/module/web/convert/object/filter.js +37 -0
  198. package/lib/module/web/convert/object/filter.js.map +1 -0
  199. package/lib/module/web/convert/object/index.js +6 -0
  200. package/lib/module/web/convert/object/index.js.map +1 -0
  201. package/lib/module/web/convert/object/objectStyle.js +51 -0
  202. package/lib/module/web/convert/object/objectStyle.js.map +1 -0
  203. package/lib/module/web/convert/object/transform.js +22 -0
  204. package/lib/module/web/convert/object/transform.js.map +1 -0
  205. package/lib/module/web/convert/pseudo.js +5 -0
  206. package/lib/module/web/convert/pseudo.js.map +1 -0
  207. package/lib/module/web/convert/shadow/boxShadow.js +57 -0
  208. package/lib/module/web/convert/shadow/boxShadow.js.map +1 -0
  209. package/lib/module/web/convert/shadow/getShadowBreakpoints.js +33 -0
  210. package/lib/module/web/convert/shadow/getShadowBreakpoints.js.map +1 -0
  211. package/lib/module/web/convert/shadow/index.js +5 -0
  212. package/lib/module/web/convert/shadow/index.js.map +1 -0
  213. package/lib/module/web/convert/shadow/textShadow.js +54 -0
  214. package/lib/module/web/convert/shadow/textShadow.js.map +1 -0
  215. package/lib/module/web/convert/style.js +88 -0
  216. package/lib/module/web/convert/style.js.map +1 -0
  217. package/lib/module/web/convert/types.js +5 -0
  218. package/lib/module/web/convert/types.js.map +1 -0
  219. package/lib/module/web/convert/utils.js +45 -0
  220. package/lib/module/web/convert/utils.js.map +1 -0
  221. package/lib/module/web/create.js +44 -0
  222. package/lib/module/web/create.js.map +1 -0
  223. package/lib/module/web/index.js +26 -0
  224. package/lib/module/web/index.js.map +1 -0
  225. package/lib/module/web/listener.js +57 -0
  226. package/lib/module/web/listener.js.map +1 -0
  227. package/lib/module/web/mock.js +23 -0
  228. package/lib/module/web/mock.js.map +1 -0
  229. package/lib/module/web/registry.js +168 -0
  230. package/lib/module/web/registry.js.map +1 -0
  231. package/lib/module/web/runtime.js +169 -0
  232. package/lib/module/web/runtime.js.map +1 -0
  233. package/lib/module/web/shadowRegistry.js +138 -0
  234. package/lib/module/web/shadowRegistry.js.map +1 -0
  235. package/lib/module/web/state.js +69 -0
  236. package/lib/module/web/state.js.map +1 -0
  237. package/lib/module/web/utils/common.js +28 -0
  238. package/lib/module/web/utils/common.js.map +1 -0
  239. package/lib/module/web/utils/index.js +5 -0
  240. package/lib/module/web/utils/index.js.map +1 -0
  241. package/lib/module/web/utils/unistyle.js +72 -0
  242. package/lib/module/web/utils/unistyle.js.map +1 -0
  243. package/lib/module/web/variants/getVariants.js +34 -0
  244. package/lib/module/web/variants/getVariants.js.map +1 -0
  245. package/lib/module/web/variants/index.js +5 -0
  246. package/lib/module/web/variants/index.js.map +1 -0
  247. package/lib/module/web/variants/useVariants.js +54 -0
  248. package/lib/module/web/variants/useVariants.js.map +1 -0
  249. package/lib/typescript/src/components/Display.d.ts +7 -0
  250. package/lib/typescript/src/components/Display.d.ts.map +1 -0
  251. package/lib/typescript/src/components/Hide.d.ts +7 -0
  252. package/lib/typescript/src/components/Hide.d.ts.map +1 -0
  253. package/lib/typescript/src/components/index.d.ts +3 -0
  254. package/lib/typescript/src/components/index.d.ts.map +1 -0
  255. package/lib/typescript/src/components/useMedia.d.ts +6 -0
  256. package/lib/typescript/src/components/useMedia.d.ts.map +1 -0
  257. package/lib/typescript/src/components/useMedia.web.d.ts +6 -0
  258. package/lib/typescript/src/components/useMedia.web.d.ts.map +1 -0
  259. package/lib/typescript/src/core/createUnistylesComponent.d.ts +8 -0
  260. package/lib/typescript/src/core/createUnistylesComponent.d.ts.map +1 -0
  261. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts +8 -0
  262. package/lib/typescript/src/core/createUnistylesComponent.native.d.ts.map +1 -0
  263. package/lib/typescript/src/core/index.d.ts +2 -0
  264. package/lib/typescript/src/core/index.d.ts.map +1 -0
  265. package/lib/typescript/src/index.d.ts +3 -0
  266. package/lib/typescript/src/index.d.ts.map +1 -1
  267. package/lib/typescript/src/mq.d.ts +8 -0
  268. package/lib/typescript/src/mq.d.ts.map +1 -1
  269. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts +7 -5
  270. package/lib/typescript/src/specs/NativePlatform/NativePlatform.nitro.d.ts.map +1 -1
  271. package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts +0 -1
  272. package/lib/typescript/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.d.ts.map +1 -1
  273. package/lib/typescript/src/specs/NavigtionBar/index.d.ts +1 -10
  274. package/lib/typescript/src/specs/NavigtionBar/index.d.ts.map +1 -1
  275. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +4 -4
  276. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  277. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts +3 -0
  278. package/lib/typescript/src/specs/ShadowRegistry/types.d.ts.map +1 -1
  279. package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts +0 -1
  280. package/lib/typescript/src/specs/StatusBar/UnistylesStatusBar.nitro.d.ts.map +1 -1
  281. package/lib/typescript/src/specs/StatusBar/index.d.ts +2 -4
  282. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  283. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts +3 -1
  284. package/lib/typescript/src/specs/StyleSheet/UnistylesStyleSheet.nitro.d.ts.map +1 -1
  285. package/lib/typescript/src/specs/StyleSheet/index.d.ts +3 -1
  286. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  287. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +1 -1
  288. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  289. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts +3 -1
  290. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  291. package/lib/typescript/src/specs/index.d.ts +4 -2
  292. package/lib/typescript/src/specs/index.d.ts.map +1 -1
  293. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  294. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  295. package/lib/typescript/src/types/breakpoints.d.ts +11 -11
  296. package/lib/typescript/src/types/breakpoints.d.ts.map +1 -1
  297. package/lib/typescript/src/types/common.d.ts +1 -0
  298. package/lib/typescript/src/types/common.d.ts.map +1 -1
  299. package/lib/typescript/src/types/index.d.ts +1 -1
  300. package/lib/typescript/src/types/index.d.ts.map +1 -1
  301. package/lib/typescript/src/types/stylesheet.d.ts +6 -4
  302. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  303. package/lib/typescript/src/types/variants.d.ts +4 -1
  304. package/lib/typescript/src/types/variants.d.ts.map +1 -1
  305. package/lib/typescript/src/utils.d.ts +2 -0
  306. package/lib/typescript/src/utils.d.ts.map +1 -0
  307. package/lib/typescript/src/web/convert/index.d.ts +3 -0
  308. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  309. package/lib/typescript/src/web/convert/object/boxShadow.d.ts +9 -0
  310. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -0
  311. package/lib/typescript/src/web/convert/object/filter.d.ts +3 -0
  312. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -0
  313. package/lib/typescript/src/web/convert/object/index.d.ts +4 -0
  314. package/lib/typescript/src/web/convert/object/index.d.ts.map +1 -0
  315. package/lib/typescript/src/web/convert/object/objectStyle.d.ts +5 -0
  316. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -0
  317. package/lib/typescript/src/web/convert/object/transform.d.ts +3 -0
  318. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -0
  319. package/lib/typescript/src/web/convert/pseudo.d.ts +6 -0
  320. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -0
  321. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts +8 -0
  322. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -0
  323. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts +2 -0
  324. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -0
  325. package/lib/typescript/src/web/convert/shadow/index.d.ts +3 -0
  326. package/lib/typescript/src/web/convert/shadow/index.d.ts.map +1 -0
  327. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts +8 -0
  328. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -0
  329. package/lib/typescript/src/web/convert/style.d.ts +2 -0
  330. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  331. package/lib/typescript/{web → src/web}/convert/types.d.ts +8 -2
  332. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  333. package/lib/typescript/src/web/convert/utils.d.ts +12 -0
  334. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  335. package/lib/typescript/src/web/create.d.ts +1443 -0
  336. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  337. package/lib/typescript/src/web/index.d.ts +1459 -0
  338. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  339. package/lib/typescript/{web/listener → src/web}/listener.d.ts +5 -2
  340. package/lib/typescript/src/web/listener.d.ts.map +1 -0
  341. package/lib/typescript/src/web/mock.d.ts +5 -0
  342. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  343. package/lib/typescript/src/web/registry.d.ts +24 -0
  344. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  345. package/lib/typescript/{web → src/web}/runtime.d.ts +11 -10
  346. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  347. package/lib/typescript/src/web/shadowRegistry.d.ts +17 -0
  348. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
  349. package/lib/typescript/src/web/state.d.ts +18 -0
  350. package/lib/typescript/src/web/state.d.ts.map +1 -0
  351. package/lib/typescript/src/web/utils/common.d.ts +8 -0
  352. package/lib/typescript/src/web/utils/common.d.ts.map +1 -0
  353. package/lib/typescript/src/web/utils/index.d.ts +3 -0
  354. package/lib/typescript/src/web/utils/index.d.ts.map +1 -0
  355. package/lib/typescript/src/web/utils/unistyle.d.ts +20 -0
  356. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -0
  357. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  358. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  359. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  360. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  361. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  362. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  363. package/nitrogen/generated/android/c++/JColorScheme.hpp +1 -1
  364. package/nitrogen/generated/android/c++/JFunc_void_UnistylesNativeMiniRuntime.hpp +57 -0
  365. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.hpp +69 -0
  366. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.cpp +35 -34
  367. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +15 -6
  368. package/nitrogen/generated/android/c++/JOrientation.hpp +1 -1
  369. package/nitrogen/generated/android/c++/JUnistyleDependency.hpp +4 -1
  370. package/nitrogen/generated/android/c++/JUnistylesNativeMiniRuntime.hpp +9 -7
  371. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Dimensions.kt +1 -0
  372. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/{Func_void_std__vector_UnistyleDependency_.kt → Func_void_UnistylesNativeMiniRuntime.kt} +6 -5
  373. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Func_void_std__vector_UnistyleDependency__UnistylesNativeMiniRuntime.kt +46 -0
  374. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +25 -13
  375. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/Insets.kt +1 -0
  376. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistyleDependency.kt +2 -1
  377. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/UnistylesNativeMiniRuntime.kt +3 -1
  378. package/nitrogen/generated/android/unistyles+autolinking.cmake +13 -1
  379. package/nitrogen/generated/android/unistyles+autolinking.gradle +2 -0
  380. package/nitrogen/generated/android/{UnistylesOnLoad.cpp → unistylesOnLoad.cpp} +6 -4
  381. package/nitrogen/generated/android/{UnistylesOnLoad.hpp → unistylesOnLoad.hpp} +1 -1
  382. package/nitrogen/generated/ios/Unistyles+autolinking.rb +6 -4
  383. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.cpp +25 -0
  384. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Bridge.hpp +73 -38
  385. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +0 -29
  386. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +8 -8
  387. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +4 -16
  388. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +156 -115
  389. package/nitrogen/generated/ios/swift/UnistyleDependency.swift +4 -0
  390. package/nitrogen/generated/ios/swift/UnistylesNativeMiniRuntime.swift +16 -5
  391. package/nitrogen/generated/shared/c++/ColorScheme.hpp +2 -2
  392. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.cpp +2 -2
  393. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +6 -3
  394. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.cpp +0 -1
  395. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -1
  396. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +1 -0
  397. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +5 -0
  398. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
  399. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.cpp +0 -1
  400. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -1
  401. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +2 -1
  402. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +10 -4
  403. package/nitrogen/generated/shared/c++/Orientation.hpp +2 -2
  404. package/nitrogen/generated/shared/c++/UnistyleDependency.hpp +2 -1
  405. package/nitrogen/generated/shared/c++/UnistylesCxxMiniRuntime.hpp +10 -9
  406. package/nitrogen/generated/shared/c++/UnistylesNativeMiniRuntime.hpp +9 -8
  407. package/package.json +20 -30
  408. package/plugin/common.js +31 -3
  409. package/plugin/index.js +107 -18
  410. package/plugin/ref.js +129 -13
  411. package/plugin/style.js +189 -22
  412. package/plugin/stylesheet.js +53 -3
  413. package/plugin/variants.js +33 -0
  414. package/src/components/Display.tsx +12 -0
  415. package/src/components/Hide.tsx +12 -0
  416. package/src/components/index.ts +2 -0
  417. package/src/components/useMedia.ts +64 -0
  418. package/src/components/useMedia.web.ts +47 -0
  419. package/src/core/createUnistylesComponent.native.tsx +83 -0
  420. package/src/core/createUnistylesComponent.tsx +84 -0
  421. package/src/core/index.ts +1 -0
  422. package/src/index.ts +3 -12
  423. package/src/mq.ts +27 -9
  424. package/src/specs/NativePlatform/NativePlatform.nitro.ts +7 -5
  425. package/src/specs/NavigtionBar/UnistylesNavigationBar.nitro.ts +0 -1
  426. package/src/specs/NavigtionBar/index.ts +1 -25
  427. package/src/specs/ShadowRegistry/index.ts +16 -10
  428. package/src/specs/ShadowRegistry/types.ts +4 -1
  429. package/src/specs/StatusBar/UnistylesStatusBar.nitro.ts +0 -1
  430. package/src/specs/StatusBar/index.ts +2 -12
  431. package/src/specs/StyleSheet/UnistylesStyleSheet.nitro.ts +4 -1
  432. package/src/specs/StyleSheet/index.ts +6 -1
  433. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +1 -1
  434. package/src/specs/UnistylesRuntime/index.ts +5 -4
  435. package/src/specs/index.ts +6 -2
  436. package/src/specs/index.web.ts +1 -1
  437. package/src/types/breakpoints.ts +25 -13
  438. package/src/types/common.ts +1 -0
  439. package/src/types/index.ts +1 -1
  440. package/src/types/stylesheet.ts +7 -5
  441. package/src/types/variants.ts +7 -1
  442. package/src/utils.ts +22 -0
  443. package/{web → src/web}/convert/index.ts +25 -25
  444. package/src/web/convert/object/boxShadow.ts +55 -0
  445. package/src/web/convert/object/filter.ts +39 -0
  446. package/src/web/convert/object/index.ts +3 -0
  447. package/src/web/convert/object/objectStyle.ts +69 -0
  448. package/src/web/convert/object/transform.ts +24 -0
  449. package/src/web/convert/pseudo.ts +137 -0
  450. package/src/web/convert/shadow/boxShadow.ts +50 -0
  451. package/src/web/convert/shadow/getShadowBreakpoints.ts +34 -0
  452. package/src/web/convert/shadow/index.ts +2 -0
  453. package/src/web/convert/shadow/textShadow.ts +48 -0
  454. package/{web → src/web}/convert/style.ts +61 -10
  455. package/{web → src/web}/convert/types.ts +9 -2
  456. package/{web → src/web}/convert/utils.ts +11 -5
  457. package/src/web/create.ts +48 -0
  458. package/{web → src/web}/index.ts +4 -3
  459. package/src/web/listener.ts +63 -0
  460. package/{web → src/web}/mock.ts +3 -14
  461. package/src/web/registry.ts +215 -0
  462. package/{web → src/web}/runtime.ts +32 -21
  463. package/src/web/shadowRegistry.ts +145 -0
  464. package/src/web/state.ts +94 -0
  465. package/src/web/utils/common.ts +45 -0
  466. package/src/web/utils/index.ts +2 -0
  467. package/src/web/utils/unistyle.ts +108 -0
  468. package/src/web/variants/getVariants.ts +42 -0
  469. package/src/web/variants/index.ts +2 -0
  470. package/src/web/variants/useVariants.ts +65 -0
  471. package/android/src/main/cxx/helpers.cpp +0 -105
  472. package/android/src/main/cxx/helpers.h +0 -16
  473. package/android/src/main/cxx/platform.cpp +0 -170
  474. package/android/src/main/cxx/platform.h +0 -20
  475. package/lib/typescript/example/App.d.ts +0 -4
  476. package/lib/typescript/example/App.d.ts.map +0 -1
  477. package/lib/typescript/example/unistyles.d.ts +0 -63
  478. package/lib/typescript/example/unistyles.d.ts.map +0 -1
  479. package/lib/typescript/expo-example/App.d.ts +0 -4
  480. package/lib/typescript/expo-example/App.d.ts.map +0 -1
  481. package/lib/typescript/expo-example/unistyles.d.ts +0 -63
  482. package/lib/typescript/expo-example/unistyles.d.ts.map +0 -1
  483. package/lib/typescript/web/convert/boxShadow.d.ts +0 -3
  484. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  485. package/lib/typescript/web/convert/breakpoint.d.ts +0 -3
  486. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  487. package/lib/typescript/web/convert/index.d.ts +0 -4
  488. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  489. package/lib/typescript/web/convert/shadow.d.ts +0 -2
  490. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  491. package/lib/typescript/web/convert/style.d.ts +0 -3
  492. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  493. package/lib/typescript/web/convert/textShadow.d.ts +0 -3
  494. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  495. package/lib/typescript/web/convert/transform.d.ts +0 -5
  496. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  497. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  498. package/lib/typescript/web/convert/utils.d.ts +0 -8
  499. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  500. package/lib/typescript/web/create.d.ts +0 -2449
  501. package/lib/typescript/web/index.d.ts +0 -2464
  502. package/lib/typescript/web/listener/index.d.ts +0 -2
  503. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  504. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  505. package/lib/typescript/web/mock.d.ts +0 -14
  506. package/lib/typescript/web/mock.d.ts.map +0 -1
  507. package/lib/typescript/web/mq.d.ts +0 -4
  508. package/lib/typescript/web/mq.d.ts.map +0 -1
  509. package/lib/typescript/web/pseudo.d.ts +0 -4
  510. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  511. package/lib/typescript/web/registry.d.ts +0 -12
  512. package/lib/typescript/web/registry.d.ts.map +0 -1
  513. package/lib/typescript/web/runtime.d.ts.map +0 -1
  514. package/lib/typescript/web/state.d.ts +0 -24
  515. package/lib/typescript/web/state.d.ts.map +0 -1
  516. package/lib/typescript/web/useVariants.d.ts +0 -3
  517. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  518. package/lib/typescript/web/utils.d.ts +0 -18
  519. package/lib/typescript/web/utils.d.ts.map +0 -1
  520. package/nitrogen/generated/android/c++/JFunc_void_std__vector_UnistyleDependency_.hpp +0 -60
  521. package/plugin/__tests__/dependencies.spec.js +0 -360
  522. package/plugin/__tests__/ref.spec.js +0 -991
  523. package/plugin/__tests__/stylesheet.spec.js +0 -396
  524. package/web/convert/boxShadow.ts +0 -72
  525. package/web/convert/breakpoint.ts +0 -21
  526. package/web/convert/shadow.ts +0 -68
  527. package/web/convert/textShadow.ts +0 -69
  528. package/web/convert/transform.ts +0 -89
  529. package/web/create.ts +0 -102
  530. package/web/listener/index.ts +0 -1
  531. package/web/listener/listener.ts +0 -33
  532. package/web/mq.ts +0 -19
  533. package/web/pseudo.ts +0 -11
  534. package/web/registry.ts +0 -41
  535. package/web/state.ts +0 -148
  536. package/web/useVariants.ts +0 -99
  537. package/web/utils.ts +0 -95
  538. /package/nitrogen/generated/android/{UnistylesOnLoad.kt → unistylesOnLoad.kt} +0 -0
  539. /package/{web → src/web}/convert/module.d.ts +0 -0
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+
3
+ import { UnistyleDependency } from '../specs/NativePlatform';
4
+ import { ColorScheme, Orientation } from '../specs/types';
5
+ import { WebContentSizeCategory } from '../types';
6
+ import { UnistylesListener } from './listener';
7
+ import { NavigationBar, StatusBar } from './mock';
8
+ import { UnistylesState } from './state';
9
+ import { isServer, schemeToTheme } from './utils';
10
+ class UnistylesRuntimeBuilder {
11
+ lightMedia = this.getLightMedia();
12
+ darkMedia = this.getDarkMedia();
13
+ getLightMedia() {
14
+ if (isServer()) {
15
+ return null;
16
+ }
17
+ if (!this.lightMedia) {
18
+ this.lightMedia = window.matchMedia('(prefers-color-scheme: light)');
19
+ }
20
+ return this.lightMedia;
21
+ }
22
+ getDarkMedia() {
23
+ if (isServer()) {
24
+ return null;
25
+ }
26
+ if (!this.darkMedia) {
27
+ this.darkMedia = window.matchMedia('(prefers-color-scheme: dark)');
28
+ }
29
+ return this.darkMedia;
30
+ }
31
+ get colorScheme() {
32
+ switch (true) {
33
+ case this.getLightMedia()?.matches:
34
+ return ColorScheme.Light;
35
+ case this.getDarkMedia()?.matches:
36
+ return ColorScheme.Dark;
37
+ default:
38
+ return ColorScheme.Unspecified;
39
+ }
40
+ }
41
+ get themeName() {
42
+ if (UnistylesState.hasAdaptiveThemes) {
43
+ return schemeToTheme(this.colorScheme);
44
+ }
45
+ return UnistylesState.themeName;
46
+ }
47
+ get contentSizeCategory() {
48
+ return WebContentSizeCategory.Unspecified;
49
+ }
50
+ get breakpoints() {
51
+ return UnistylesState.breakpoints ?? {};
52
+ }
53
+ get breakpoint() {
54
+ return UnistylesState.breakpoint;
55
+ }
56
+ get orientation() {
57
+ if (isServer()) {
58
+ return Orientation.Portrait;
59
+ }
60
+ return screen.orientation.type.includes('portrait') ? Orientation.Portrait : Orientation.Landscape;
61
+ }
62
+ get theme() {
63
+ return this.getTheme(this.themeName);
64
+ }
65
+ get pixelRatio() {
66
+ return isServer() ? 1 : window.devicePixelRatio;
67
+ }
68
+ get screen() {
69
+ if (isServer()) {
70
+ return {
71
+ width: 0,
72
+ height: 0
73
+ };
74
+ }
75
+ return {
76
+ width: window.innerWidth,
77
+ height: window.innerHeight
78
+ };
79
+ }
80
+ get fontScale() {
81
+ return 1;
82
+ }
83
+ get insets() {
84
+ return {
85
+ top: 0,
86
+ bottom: 0,
87
+ left: 0,
88
+ right: 0,
89
+ ime: 0
90
+ };
91
+ }
92
+ get statusBar() {
93
+ return StatusBar;
94
+ }
95
+ get rtl() {
96
+ return isServer() ? true : document.documentElement.dir === 'rtl';
97
+ }
98
+ get hasAdaptiveThemes() {
99
+ return UnistylesState.hasAdaptiveThemes;
100
+ }
101
+ get navigationBar() {
102
+ return NavigationBar;
103
+ }
104
+ get miniRuntime() {
105
+ return {
106
+ colorScheme: this.colorScheme,
107
+ themeName: this.themeName,
108
+ contentSizeCategory: this.contentSizeCategory,
109
+ breakpoint: this.breakpoint,
110
+ isLandscape: this.orientation === Orientation.Landscape,
111
+ isPortrait: this.orientation === Orientation.Portrait,
112
+ pixelRatio: this.pixelRatio,
113
+ screen: this.screen,
114
+ fontScale: this.fontScale,
115
+ insets: this.insets,
116
+ statusBar: {
117
+ width: this.statusBar.width,
118
+ height: this.statusBar.height
119
+ },
120
+ navigationBar: {
121
+ width: this.navigationBar.width,
122
+ height: this.navigationBar.height
123
+ },
124
+ rtl: this.rtl,
125
+ hasAdaptiveThemes: this.hasAdaptiveThemes
126
+ };
127
+ }
128
+ setTheme = themeName => {
129
+ if (themeName === UnistylesRuntime.themeName) {
130
+ return;
131
+ }
132
+ UnistylesState.themeName = themeName;
133
+ UnistylesListener.emitChange(UnistyleDependency.Theme);
134
+ UnistylesListener.emitChange(UnistyleDependency.ThemeName);
135
+ };
136
+ setAdaptiveThemes = isEnabled => {
137
+ UnistylesState.hasAdaptiveThemes = isEnabled;
138
+ if (!isEnabled) {
139
+ return;
140
+ }
141
+ this.setTheme(schemeToTheme(UnistylesRuntime.colorScheme));
142
+ };
143
+ setRootViewBackgroundColor = color => {
144
+ if (isServer()) {
145
+ return;
146
+ }
147
+ document.documentElement.style.backgroundColor = color;
148
+ };
149
+ setImmersiveMode = () => {};
150
+ updateTheme = (themeName, updater) => {
151
+ const oldTheme = UnistylesState.themes.get(themeName);
152
+ if (!oldTheme) {
153
+ throw new Error(`🦄 Theme "${themeName}" is not registered!`);
154
+ }
155
+ UnistylesState.themes.set(themeName, updater(oldTheme));
156
+ };
157
+ getTheme = (themeName = this.themeName) => {
158
+ if (!themeName) {
159
+ throw new Error('🦄 No theme selected!');
160
+ }
161
+ const theme = UnistylesState.themes.get(themeName);
162
+ if (!theme) {
163
+ throw new Error(`🦄 Theme "${this.themeName}" is not registered!`);
164
+ }
165
+ return theme;
166
+ };
167
+ }
168
+ export const UnistylesRuntime = new UnistylesRuntimeBuilder();
169
+ //# sourceMappingURL=runtime.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistyleDependency","ColorScheme","Orientation","WebContentSizeCategory","UnistylesListener","NavigationBar","StatusBar","UnistylesState","isServer","schemeToTheme","UnistylesRuntimeBuilder","lightMedia","getLightMedia","darkMedia","getDarkMedia","window","matchMedia","colorScheme","matches","Light","Dark","Unspecified","themeName","hasAdaptiveThemes","contentSizeCategory","breakpoints","breakpoint","orientation","Portrait","screen","type","includes","Landscape","theme","getTheme","pixelRatio","devicePixelRatio","width","height","innerWidth","innerHeight","fontScale","insets","top","bottom","left","right","ime","statusBar","rtl","document","documentElement","dir","navigationBar","miniRuntime","isLandscape","isPortrait","setTheme","UnistylesRuntime","emitChange","Theme","ThemeName","setAdaptiveThemes","isEnabled","setRootViewBackgroundColor","color","style","backgroundColor","setImmersiveMode","updateTheme","updater","oldTheme","themes","get","Error","set"],"sourceRoot":"../../../src","sources":["web/runtime.ts"],"mappings":";;AAAA,SAASA,kBAAkB,QAAQ,yBAAyB;AAC5D,SAASC,WAAW,EAAEC,WAAW,QAA0C,gBAAgB;AAE3F,SAASC,sBAAsB,QAAQ,UAAU;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,aAAa,EAAEC,SAAS,QAAQ,QAAQ;AACjD,SAASC,cAAc,QAAQ,SAAS;AACxC,SAASC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AAEjD,MAAMC,uBAAuB,CAAC;EAC1BC,UAAU,GAAG,IAAI,CAACC,aAAa,CAAC,CAAC;EACjCC,SAAS,GAAG,IAAI,CAACC,YAAY,CAAC,CAAC;EAEvBF,aAAaA,CAAA,EAA0B;IAC3C,IAAIJ,QAAQ,CAAC,CAAC,EAAE;MACZ,OAAO,IAAI;IACf;IAEA,IAAI,CAAC,IAAI,CAACG,UAAU,EAAE;MAClB,IAAI,CAACA,UAAU,GAAGI,MAAM,CAACC,UAAU,CAAC,+BAA+B,CAAC;IACxE;IAEA,OAAO,IAAI,CAACL,UAAU;EAC1B;EAEQG,YAAYA,CAAA,EAA0B;IAC1C,IAAIN,QAAQ,CAAC,CAAC,EAAE;MACZ,OAAO,IAAI;IACf;IAEA,IAAI,CAAC,IAAI,CAACK,SAAS,EAAE;MACjB,IAAI,CAACA,SAAS,GAAGE,MAAM,CAACC,UAAU,CAAC,8BAA8B,CAAC;IACtE;IAEA,OAAO,IAAI,CAACH,SAAS;EACzB;EAEA,IAAII,WAAWA,CAAA,EAAG;IACd,QAA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,CAAC;IACjE;IAEAf,cAAc,CAACiE,MAAM,CAACG,GAAG,CAACrD,SAAS,EAAEgD,OAAO,CAACC,QAAQ,CAAC,CAAC;EAC3D,CAAC;EAEDrC,QAAQ,GAAGA,CAACZ,SAAS,GAAG,IAAI,CAACA,SAAS,KAAK;IACvC,IAAI,CAACA,SAAS,EAAE;MACZ,MAAM,IAAIoD,KAAK,CAAC,uBAAuB,CAAC;IAC5C;IAEA,MAAMzC,KAAK,GAAG1B,cAAc,CAACiE,MAAM,CAACC,GAAG,CAACnD,SAAS,CAAC;IAElD,IAAI,CAACW,KAAK,EAAE;MACR,MAAM,IAAIyC,KAAK,CAAC,aAAa,IAAI,CAACpD,SAAS,sBAAsB,CAAC;IACtE;IAEA,OAAOW,KAAK;EAChB,CAAC;AACL;AAEA,OAAO,MAAMyB,gBAAgB,GAAG,IAAIhD,uBAAuB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,138 @@
1
+ "use strict";
2
+
3
+ import { convertUnistyles } from './convert';
4
+ import { UnistylesListener } from './listener';
5
+ import { UnistylesRegistry } from './registry';
6
+ import { deepMergeObjects } from '../utils';
7
+ import { equal, extractSecrets, extractUnistyleDependencies, isInDocument } from './utils';
8
+ import { getVariants } from './variants';
9
+ class UnistylesShadowRegistryBuilder {
10
+ // MOCKS
11
+ name = 'UnistylesShadowRegistry';
12
+ __type = 'web';
13
+ equals = () => true;
14
+ toString = () => 'UnistylesShadowRegistry';
15
+ dispose = () => {};
16
+ // END MOCKS
17
+
18
+ resultsMap = new Map();
19
+ hashMap = new Map();
20
+ classNamesMap = new Map();
21
+ add = (ref, _style, _variants, _args) => {
22
+ // Style is not provided
23
+ if (!_style) {
24
+ return;
25
+ }
26
+
27
+ // Ref is unmounted, remove style tags from the document
28
+ if (ref === null) {
29
+ const secrets = extractSecrets(_style);
30
+ secrets.forEach(({
31
+ __uni__refs
32
+ }) => {
33
+ __uni__refs.forEach(ref => {
34
+ if (isInDocument(ref)) {
35
+ return;
36
+ }
37
+ const oldResult = this.resultsMap.get(ref);
38
+ this.resultsMap.delete(ref);
39
+ this.classNamesMap.delete(ref);
40
+ if (oldResult) {
41
+ UnistylesRegistry.remove(oldResult);
42
+ }
43
+ });
44
+ });
45
+ return;
46
+ }
47
+
48
+ // Ref is not an HTMLElement
49
+ if (!(ref instanceof HTMLElement)) {
50
+ return;
51
+ }
52
+ const styles = _style.filter(style => Object.keys(style ?? {}).some(key => key.startsWith('__uni__')));
53
+
54
+ // No unistyles
55
+ if (styles.length === 0) {
56
+ return;
57
+ }
58
+ const parsedStyles = styles.flatMap((style, styleIndex) => extractSecrets(style).map(secret => {
59
+ const {
60
+ __uni__key,
61
+ __uni__stylesheet,
62
+ __uni__variants,
63
+ __uni__args = [],
64
+ __uni__refs
65
+ } = secret;
66
+ const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
67
+ const style = newComputedStylesheet[__uni__key];
68
+ const variants = _variants && Object.keys(_variants).length > 0 ? _variants : __uni__variants;
69
+ const args = _args[styleIndex] ? _args[styleIndex] : __uni__args;
70
+ const result = typeof style === 'function' ? style(...args) : style;
71
+ const {
72
+ variantsResult
73
+ } = Object.fromEntries(getVariants({
74
+ variantsResult: result
75
+ }, variants));
76
+ const resultWithVariants = deepMergeObjects(result, variantsResult ?? {});
77
+ const dependencies = extractUnistyleDependencies(resultWithVariants);
78
+ if (typeof __uni__stylesheet === 'function') {
79
+ // Add dependencies from dynamic styles to stylesheet
80
+ UnistylesRegistry.addDependenciesToStylesheet(__uni__stylesheet, dependencies);
81
+ }
82
+ __uni__refs.add(ref);
83
+ const dispose = UnistylesListener.addListeners(extractUnistyleDependencies(resultWithVariants), () => {
84
+ const hash = this.hashMap.get(ref);
85
+
86
+ // Dispose listener if there is no hash
87
+ if (!hash) {
88
+ dispose();
89
+ return;
90
+ }
91
+ const newComputedStyleSheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet);
92
+ const newValue = newComputedStyleSheet[__uni__key];
93
+ const result = typeof newValue === 'function' ? newValue(...args) : newValue;
94
+ const {
95
+ variantsResult
96
+ } = Object.fromEntries(getVariants({
97
+ variantsResult: result
98
+ }, variants));
99
+ const resultWithVariants = deepMergeObjects(result, variantsResult ?? {});
100
+ UnistylesRegistry.applyStyles(hash, convertUnistyles(resultWithVariants));
101
+ });
102
+ return resultWithVariants;
103
+ }));
104
+ const combinedStyles = deepMergeObjects(...parsedStyles);
105
+ const oldStyles = this.resultsMap.get(ref);
106
+ if (equal(combinedStyles, oldStyles)) {
107
+ return;
108
+ }
109
+ const oldClassNames = this.classNamesMap.get(ref);
110
+
111
+ // Remove old styles
112
+ if (oldStyles) {
113
+ UnistylesRegistry.remove(oldStyles);
114
+ }
115
+
116
+ // Remove old classnames from the ref
117
+ oldClassNames?.forEach(className => ref.classList.remove(className));
118
+ this.resultsMap.set(ref, combinedStyles);
119
+ const {
120
+ hash,
121
+ existingHash
122
+ } = UnistylesRegistry.add(combinedStyles);
123
+ const injectedClassNames = combinedStyles?._web?._classNames ?? [];
124
+ const newClassNames = (Array.isArray(injectedClassNames) ? injectedClassNames : [injectedClassNames]).concat(hash);
125
+ this.classNamesMap.set(ref, newClassNames);
126
+ // Add new classnames to the ref
127
+ ref.classList.add(...newClassNames);
128
+
129
+ // If it is new hash add it to the map to use for the listener
130
+ if (!existingHash) {
131
+ this.hashMap.set(ref, hash);
132
+ }
133
+ return newClassNames;
134
+ };
135
+ remove = () => {};
136
+ }
137
+ export const UnistylesShadowRegistry = new UnistylesShadowRegistryBuilder();
138
+ //# sourceMappingURL=shadowRegistry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["convertUnistyles","UnistylesListener","UnistylesRegistry","deepMergeObjects","equal","extractSecrets","extractUnistyleDependencies","isInDocument","getVariants","UnistylesShadowRegistryBuilder","name","__type","equals","toString","dispose","resultsMap","Map","hashMap","classNamesMap","add","ref","_style","_variants","_args","secrets","forEach","__uni__refs","oldResult","get","delete","remove","HTMLElement","styles","filter","style","Object","keys","some","key","startsWith","length","parsedStyles","flatMap","styleIndex","map","secret","__uni__key","__uni__stylesheet","__uni__variants","__uni__args","newComputedStylesheet","getComputedStylesheet","variants","args","result","variantsResult","fromEntries","resultWithVariants","dependencies","addDependenciesToStylesheet","addListeners","hash","newComputedStyleSheet","newValue","applyStyles","combinedStyles","oldStyles","oldClassNames","className","classList","set","existingHash","injectedClassNames","_web","_classNames","newClassNames","Array","isArray","concat","UnistylesShadowRegistry"],"sourceRoot":"../../../src","sources":["web/shadowRegistry.ts"],"mappings":";;AACA,SAASA,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,gBAAgB,QAAQ,UAAU;AAC3C,SAASC,KAAK,EAAEC,cAAc,EAAEC,2BAA2B,EAAEC,YAAY,QAAQ,SAAS;AAC1F,SAASC,WAAW,QAAQ,YAAY;AAIxC,MAAMC,8BAA8B,CAAC;EACjC;EACAC,IAAI,GAAG,yBAAyB;EAChCC,MAAM,GAAG,KAAK;EACdC,MAAM,GAAGA,CAAA,KAAM,IAAI;EACnBC,QAAQ,GAAGA,CAAA,KAAM,yBAAyB;EAC1CC,OAAO,GAAGA,CAAA,KAAM,CAAC,CAAC;EAClB;;EAEQC,UAAU,GAAG,IAAIC,GAAG,CAA+B,CAAC;EACpDC,OAAO,GAAG,IAAID,GAAG,CAAsB,CAAC;EACxCE,aAAa,GAAG,IAAIF,GAAG,CAA6B,CAAC;EAE7DG,GAAG,GAAGA,CAACC,GAAQ,EAAEC,MAAoB,EAAEC,SAA0C,EAAEC,KAAwB,KAAK;IAC5G;IACA,IAAI,CAACF,MAAM,EAAE;MACT;IACJ;;IAEA;IACA,IAAID,GAAG,KAAK,IAAI,EAAE;MACd,MAAMI,OAAO,GAAGnB,cAAc,CAACgB,MAAM,CAAC;MAEtCG,OAAO,CAACC,OAAO,CAAC,CAAC;QAAEC;MAAY,CAAC,KAAK;QACjCA,WAAW,C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CAAClD,GAAG,EAAEuD,aAAa,CAAC;IAC1C;IACAvD,GAAG,CAACiD,SAAS,CAAClD,GAAG,CAAC,GAAGwD,aAAa,CAAC;;IAEnC;IACA,IAAI,CAACJ,YAAY,EAAE;MACf,IAAI,CAACtD,OAAO,CAACqD,GAAG,CAAClD,GAAG,EAAEyC,IAAI,CAAC;IAC/B;IAEA,OAAOc,aAAa;EACxB,CAAC;EAED7C,MAAM,GAAGA,CAAA,KAAM,CAAC,CAAC;AACrB;AAEA,OAAO,MAAMiD,uBAAuB,GAAG,IAAItE,8BAA8B,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,69 @@
1
+ "use strict";
2
+
3
+ import { UnistylesRuntime } from './runtime';
4
+ import { isServer, schemeToTheme } from './utils';
5
+ import { UnistylesListener } from './listener';
6
+ import { UnistyleDependency } from '../specs/NativePlatform';
7
+ class UnistylesStateBuilder {
8
+ themes = new Map();
9
+ matchingBreakpoints = new Map();
10
+ get breakpoint() {
11
+ const [currentBreakpoint] = Array.from(this.matchingBreakpoints).reverse().find(([_key, value]) => value) ?? [];
12
+ return currentBreakpoint;
13
+ }
14
+ hasAdaptiveThemes = false;
15
+ init = config => {
16
+ this.initThemes(config.themes);
17
+ this.initBreakpoints(config.breakpoints);
18
+ this.initSettings(config.settings);
19
+ if (isServer()) {
20
+ return;
21
+ }
22
+ UnistylesListener.initListeners();
23
+ };
24
+ initThemes = (themes = {}) => {
25
+ Object.entries(themes).forEach(([themeName, theme]) => {
26
+ this.themes.set(themeName, theme);
27
+ });
28
+ };
29
+ initSettings = settings => {
30
+ this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false;
31
+ const themeNames = Array.from(this.themes.keys());
32
+
33
+ // Single theme + no settings
34
+ if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
35
+ this.themeName = themeNames[0];
36
+ return;
37
+ }
38
+
39
+ // No settings
40
+ if (!settings?.adaptiveThemes && !settings?.initialTheme) {
41
+ throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config');
42
+ }
43
+
44
+ // Adaptive themes
45
+ if (settings.adaptiveThemes) {
46
+ this.themeName = schemeToTheme(UnistylesRuntime.colorScheme);
47
+ return;
48
+ }
49
+
50
+ // Initial theme
51
+ this.themeName = typeof settings.initialTheme === 'function' ? settings.initialTheme() : settings.initialTheme;
52
+ };
53
+ initBreakpoints = (breakpoints = {}) => {
54
+ this.breakpoints = breakpoints;
55
+ Object.entries(breakpoints).sort(([, a], [, b]) => a - b).forEach(([breakpoint, value]) => {
56
+ if (isServer()) {
57
+ return;
58
+ }
59
+ const mediaQuery = window.matchMedia(`(min-width: ${value}px)`);
60
+ this.matchingBreakpoints.set(breakpoint, mediaQuery.matches);
61
+ mediaQuery.addEventListener('change', event => {
62
+ this.matchingBreakpoints.set(breakpoint, event.matches);
63
+ UnistylesListener.emitChange(UnistyleDependency.Breakpoints);
64
+ });
65
+ });
66
+ };
67
+ }
68
+ export const UnistylesState = new UnistylesStateBuilder();
69
+ //# sourceMappingURL=state.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["UnistylesRuntime","isServer","schemeToTheme","UnistylesListener","UnistyleDependency","UnistylesStateBuilder","themes","Map","matchingBreakpoints","breakpoint","currentBreakpoint","Array","from","reverse","find","_key","value","hasAdaptiveThemes","init","config","initThemes","initBreakpoints","breakpoints","initSettings","settings","initListeners","Object","entries","forEach","themeName","theme","set","adaptiveThemes","themeNames","keys","initialTheme","length","Error","colorScheme","sort","a","b","mediaQuery","window","matchMedia","matches","addEventListener","event","emitChange","Breakpoints","UnistylesState"],"sourceRoot":"../../../src","sources":["web/state.ts"],"mappings":";;AAIA,SAASA,gBAAgB,QAAQ,WAAW;AAC5C,SAASC,QAAQ,EAAEC,aAAa,QAAQ,SAAS;AACjD,SAASC,iBAAiB,QAAQ,YAAY;AAC9C,SAASC,kBAAkB,QAAQ,yBAAyB;AAE5D,MAAMC,qBAAqB,CAAC;EACxBC,MAAM,GAAG,IAAIC,GAAG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B,CAAC6C,WAAW,CAAC;MAChE,CAAC,CAAC;IACN,CAAC,CAAC;EACV,CAAC;AACL;AAEA,OAAO,MAAMC,cAAc,GAAG,IAAI7C,qBAAqB,CAAC,CAAC","ignoreList":[]}
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+
3
+ export const reduceObject = (obj, reducer) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value, key)]));
4
+ export const keyInObject = (obj, key) => key in obj;
5
+ export const isServer = () => typeof window === 'undefined';
6
+ export const warn = message => console.warn(`🦄 [react-native-unistyles] ${message}`);
7
+ export const equal = (a, b) => {
8
+ if (Object.is(a, b)) {
9
+ return true;
10
+ }
11
+ if (typeof a !== 'object' || a === null || typeof b !== 'object' || b === null) {
12
+ return false;
13
+ }
14
+ const keysA = Object.keys(a);
15
+ if (keysA.length !== Object.keys(b).length) {
16
+ return false;
17
+ }
18
+ return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key));
19
+ };
20
+ export const generateHash = value => {
21
+ const str = JSON.stringify(value);
22
+ let hasher = 5381;
23
+ let length = str.length;
24
+ while (length--) hasher = hasher * 33 ^ str.charCodeAt(length);
25
+ return `unistyles-${(hasher >>> 0).toString(36)}`;
26
+ };
27
+ export const hyphenate = propertyName => propertyName.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
28
+ //# sourceMappingURL=common.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["reduceObject","obj","reducer","Object","fromEntries","entries","map","key","value","keyInObject","isServer","window","warn","message","console","equal","a","b","is","keysA","keys","length","every","prototype","hasOwnProperty","call","generateHash","str","JSON","stringify","hasher","charCodeAt","toString","hyphenate","propertyName","replace","m","toLowerCase"],"sourceRoot":"../../../../src","sources":["web/utils/common.ts"],"mappings":";;AAAA,OAAO,MAAMA,YAAY,GAAGA,CACxBC,GAAS,EACTC,OAA+D,KAC9DC,MAAM,CAACC,WAAW,CAACD,MAAM,CAACE,OAAO,CAACJ,GAAG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AK,CAAC;EACjC,IAAIsB,MAAM,GAAG,IAAI;EACjB,IAAIT,MAAM,GAAGM,GAAG,CAACN,MAAM;EAEvB,OAAOA,MAAM,EAAE,EAAES,MAAM,GAAIA,MAAM,GAAG,EAAE,GAAIH,GAAG,CAACI,UAAU,CAACV,MAAM,CAAC;EAEhE,OAAO,aAAa,CAACS,MAAM,KAAK,CAAC,EAAEE,QAAQ,CAAC,EAAE,CAAC,EAAE;AACrD,CAAC;AAED,OAAO,MAAMC,SAAS,GAAIC,YAAoB,IAAKA,YAAY,CAACC,OAAO,CAAC,QAAQ,EAAGC,CAAS,IAAK,IAAIA,CAAC,CAACC,WAAW,CAAC,CAAC,EAAE,CAAC","ignoreList":[]}
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ export * from './common';
4
+ export * from './unistyle';
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["web/utils/index.ts"],"mappings":";;AAAA,cAAc,UAAU;AACxB,cAAc,YAAY","ignoreList":[]}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ import { ColorScheme, Orientation } from '../../specs/types';
4
+ import { isUnistylesMq, parseMq } from '../../mq';
5
+ import { UnistylesState } from '../state';
6
+ import { keyInObject, reduceObject } from './common';
7
+ export const schemeToTheme = scheme => {
8
+ switch (scheme) {
9
+ case ColorScheme.Dark:
10
+ return 'dark';
11
+ case ColorScheme.Light:
12
+ default:
13
+ return 'light';
14
+ }
15
+ };
16
+ export const hexToRGBA = (hex, opacity) => hex.replace('#', '').split(/(?=(?:..)*$)/).map(x => parseInt(x, 16)).filter(num => !isNaN(num)).reduce((acc, color) => `${acc}${color},`, 'rgba(').concat(`${opacity})`);
17
+ export const assignSecrets = (object, secrets) => {
18
+ // @ts-expect-error - assign secrets to object
19
+ object[`__uni__secrets__${Math.random().toString(16).slice(2)}`] = secrets;
20
+ return object;
21
+ };
22
+ export const extractSecrets = object => {
23
+ const secrets = Object.entries(object).reduce((acc, [key, value]) => {
24
+ if (key.startsWith('__uni__secrets__')) {
25
+ acc.push(value);
26
+ }
27
+ return acc;
28
+ }, []);
29
+ return secrets;
30
+ };
31
+ export const getStyles = values => {
32
+ const returnValue = {};
33
+ Object.defineProperties(returnValue, reduceObject(values, value => ({
34
+ value,
35
+ enumerable: false,
36
+ configurable: true
37
+ })));
38
+ return returnValue;
39
+ };
40
+ export const isInDocument = element => document.body.contains(element);
41
+ export const extractMediaQueryValue = query => {
42
+ const [_, px] = query.match(/(\d+)px/) ?? [];
43
+ if (!px) {
44
+ return undefined;
45
+ }
46
+ const value = Number(px);
47
+ return isNaN(value) ? undefined : value;
48
+ };
49
+ export const getMediaQuery = query => {
50
+ if (Object.values(Orientation).includes(query)) {
51
+ return `(orientation: ${query})`;
52
+ }
53
+ if (isUnistylesMq(query)) {
54
+ const {
55
+ minWidth,
56
+ maxWidth,
57
+ minHeight,
58
+ maxHeight
59
+ } = parseMq(query);
60
+ return [minWidth ? `(min-width: ${minWidth}px)` : undefined, maxWidth ? `(max-width: ${maxWidth}px)` : undefined, minHeight ? `(min-height: ${minHeight}px)` : undefined, maxHeight ? `(max-height: ${maxHeight}px)` : undefined].filter(Boolean).join(' and ');
61
+ }
62
+ const minWidth = UnistylesState.breakpoints && keyInObject(UnistylesState.breakpoints, query) ? UnistylesState.breakpoints[query] : undefined;
63
+ return `(min-width: ${minWidth ?? 0}px)`;
64
+ };
65
+ export const extractUnistyleDependencies = value => {
66
+ if (!value) {
67
+ return [];
68
+ }
69
+ const dependencies = keyInObject(value, 'uni__dependencies') ? value.uni__dependencies : [];
70
+ return Array.isArray(dependencies) ? dependencies : [];
71
+ };
72
+ //# sourceMappingURL=unistyle.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["ColorScheme","Orientation","isUnistylesMq","parseMq","UnistylesState","keyInObject","reduceObject","schemeToTheme","scheme","Dark","Light","hexToRGBA","hex","opacity","replace","split","map","x","parseInt","filter","num","isNaN","reduce","acc","color","concat","assignSecrets","object","secrets","Math","random","toString","slice","extractSecrets","Object","entries","key","value","startsWith","push","getStyles","values","returnValue","defineProperties","enumerable","configurable","isInDocument","element","document","body","contains","extractMediaQueryValue","query","_","px","match","undefined","Number","getMediaQuery","includes","minWidth","maxWidth","minHeight","maxHeight","Boolean","join","breakpoints","extractUnistyleDependencies","dependencies","uni__dependencies","Array","isArray"],"sourceRoot":"../../../../src","sources":["web/utils/unistyle.ts"],"mappings":";;AACA,SAASA,WAAW,EAAEC,WAAW,QAAQ,mBAAmB;AAE5D,SAASC,aAAa,EAAEC,OAAO,QAAQ,UAAU;AACjD,SAASC,cAAc,QAAQ,UAAU;AACzC,SAASC,WAAW,EAAEC,YAAY,QAAQ,UAAU;AAEpD,OAAO,MAAMC,aAAa,GAAIC,MAAmB,IAAK;EAClD,QAAQA,MAAM;IACV,KAAKR,WAAW,CAACS,IAAI;MACjB,OAAO,MAAM;IACjB,KAAKT,WAAW,CAACU,KAAK;IACtB;MACI,OAAO,OAAO;EACtB;AACJ,CAAC;AAED,OAAO,MAAMC,SAAS,GAAGA,CAACC,GAAW,EAAEC,OAAe,KAAKD,GAAG,CACzDE,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,CAChBC,KAAK,CAAC,cAAc,CAAC,CACrBC,GAAG,CAACC,CAAC,IAAIC,QAAQ,CAACD,CAAC,EAAE,EAAE,CAAC,CAAC,CACzBE,MAAM,CAACC,GAAG,IAAI,CAACC,KAAK,CAACD,GAAG,CAAC,CAAC,CAC1BE,MAAM,CAAC,CAACC,GAAG,EAAEC,KAAK,KAAK,GAAGD,GAAG,GAAGC,KAAK,GAAG,EAAE,OAAO,CAAC,CAClDC,MAAM,CAAC,GAAGZ,OAAO,GAAG,CAAC;AAU1B,OAAO,MAAMa,aAAa,GAAGA,CAAIC,MAAS,EAAEC,OAAwB,KAAK;EACrE;EACAD,MAAM,CAAC,mBAAmBE,IAAI,CAACC,MAAM,CAAC,CAAC,CAACC,QAAQ,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value[1];
5
+ export const getVariants = (styles, selectedVariants) => {
6
+ return Object.entries(styles).filter(hasVariants).filter(([_key, {
7
+ variants
8
+ }]) => Object.keys(variants).some(variant => variant in variants)).map(([key, {
9
+ variants,
10
+ compoundVariants = []
11
+ }]) => {
12
+ const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
13
+ const selectedVariant = selectedVariants[variant];
14
+ const selectedVariantStyles = styles[selectedVariant] ?? styles['default'];
15
+ if (!selectedVariantStyles) {
16
+ return [];
17
+ }
18
+ return selectedVariantStyles;
19
+ });
20
+ const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
21
+ const {
22
+ styles,
23
+ ...conditions
24
+ } = compoundVariant;
25
+ if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
26
+ return [];
27
+ }
28
+ return styles;
29
+ });
30
+ const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles);
31
+ return [key, mergedVariantStyles];
32
+ });
33
+ };
34
+ //# sourceMappingURL=getVariants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["deepMergeObjects","hasVariants","value","getVariants","styles","selectedVariants","Object","entries","filter","_key","variants","keys","some","variant","map","key","compoundVariants","variantStyles","flatMap","selectedVariant","selectedVariantStyles","compoundVariantStyles","compoundVariant","conditions","String","mergedVariantStyles"],"sourceRoot":"../../../../src","sources":["web/variants/getVariants.ts"],"mappings":";;AACA,SAASA,gBAAgB,QAAQ,aAAa;AAQ9C,MAAMC,WAAW,GAAsBC,KAAkB,IAAgD,UAAU,IAAIA,KAAK,CAAC,CAAC,CAAC;AAE/H,OAAO,MAAMC,WAAW,GAAGA,CAACC,MAAyC,EAAEC,gBAAqC,KAAK;EAC7G,OAAOC,MAAM,CAACC,OAAO,CAACH,MAAM,CAAC,CACxBI,MAAM,CAACP,WAAW,CAAC,CACnBO,MAAM,CAAC,CAAC,CAACC,IAAI,EAAE;IAAEC;EAAS,CAAC,CAAC,KAAKJ,MAAM,CAAC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@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sourceRoot":"../../../../src","sources":["web/variants/index.ts"],"mappings":";;AAAA,cAAc,eAAe;AAC7B,cAAc,eAAe","ignoreList":[]}
@@ -0,0 +1,54 @@
1
+ "use strict";
2
+
3
+ import { useMemo, useRef, useState } from 'react';
4
+ import { equal, keyInObject, reduceObject } from '../utils';
5
+ import { getVariants } from './getVariants';
6
+ export const createUseVariants = (styles, setSelectedVariants) => {
7
+ const useVariants = selectedVariants => {
8
+ const [selectedVariantStylesMap] = useState(() => new Map());
9
+ const lastSelectedVariantsRef = useRef();
10
+ // Variable that determines if variants have changed and we need to recalculate styles
11
+ const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants);
12
+ if (variantsChanged) {
13
+ lastSelectedVariantsRef.current = selectedVariants;
14
+ setSelectedVariants(selectedVariants);
15
+ }
16
+ const combinedVariantStyles = useMemo(() => {
17
+ const result = getVariants(styles, selectedVariants);
18
+ result.forEach(([key, value]) => {
19
+ selectedVariantStylesMap.set(key, value);
20
+ });
21
+ return result;
22
+ }, [lastSelectedVariantsRef.current]);
23
+ combinedVariantStyles.forEach(([key]) => {
24
+ const styleEntry = styles[key];
25
+ if (!styleEntry) {
26
+ return;
27
+ }
28
+ const selectedVariantStyles = selectedVariantStylesMap.get(key);
29
+ Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
30
+ value,
31
+ enumerable: false,
32
+ configurable: true
33
+ })));
34
+
35
+ // Add __uni__variants to static styles
36
+ Object.keys(styleEntry).forEach(key => {
37
+ if (!key.startsWith('__uni__secrets__')) {
38
+ return;
39
+ }
40
+ const secret = keyInObject(styleEntry, key) ? styleEntry[key] : undefined;
41
+ if (!secret) {
42
+ return;
43
+ }
44
+ Object.defineProperty(secret, '__uni__variants', {
45
+ value: selectedVariants
46
+ });
47
+ });
48
+ });
49
+ };
50
+ Object.defineProperty(styles, 'useVariants', {
51
+ value: useVariants
52
+ });
53
+ };
54
+ //# sourceMappingURL=useVariants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useMemo","useRef","useState","equal","keyInObject","reduceObject","getVariants","createUseVariants","styles","setSelectedVariants","useVariants","selectedVariants","selectedVariantStylesMap","Map","lastSelectedVariantsRef","variantsChanged","current","combinedVariantStyles","result","forEach","key","value","set","styleEntry","selectedVariantStyles","get","Object","defineProperties","enumerable","configurable","keys","startsWith","secret","undefined","defineProperty"],"sourceRoot":"../../../../src","sources":["web/variants/useVariants.ts"],"mappings":";;AAAA,SAASA,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAEjD,SAASC,KAAK,EAAEC,WAAW,EAAEC,YAAY,QAAQ,UAAU;AAC3D,SAASC,WAAW,QAAQ,eAAe;AAE3C,OAAO,MAAMC,iBAAiB,GAAGA,CAACC,MAAyC,EAAEC,mBAA4D,KAAK;EAC1I,MAAMC,WAAW,GAAIC,gBAAqC,IAAK;IAC3D,MAAM,CAACC,wBAAwB,CAAC,GAAGV,QAAQ,CAAC,MAAM,IAAIW,GAAG,CAA8B,CAAC,CAAC;IACzF,MAAMC,uBAAuB,GAAGb,MAAM,CAAsB,CAAC;IAC7D;IACA,MAAMc,eAAe,GAAG,CAACZ,KAAK,CAACW,uBAAuB,CAACE,OAAO,EAAEL,gBAAgB,CAAC;IAEjF,IAAII,eAAe,EAAE;MACjBD,uBAAuB,CAACE,OAAO,GAAGL,gBAAgB;MAClDF,mBAAmB,CAACE,gBAAgB,CAAC;IACzC;IAEA,MAAMM,qBAAqB,GAAGjB,OAAO,CAAC,MAAM;MACxC,MAAMkB,MAAM,GAAGZ,WAAW,CAACE,MAAM,EAAEG,gBAAgB,CAAC;MAEpDO,MAAM,CAACC,OAAO,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;QAC7BT,wBAAwB,CAACU,GAAG,CAACF,GAAG,EAAEC,KAAK,CAAC;MAC5C,CAAC,CAAC;MAEF,OAAOH,MAAM;IACjB,CAAC,EAAE,CA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