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
@@ -1,89 +0,0 @@
1
- import { media } from 'typestyle'
2
- import type { NestedCSSProperties } from 'typestyle/lib/types'
3
- import { deepMergeObjects, keyInObject } from '../utils'
4
- import { normalizeNumericValue } from './utils'
5
- import { convertBreakpoint } from './breakpoint'
6
-
7
- type Transforms = Array<Record<string, any>>
8
-
9
- const normalizeTransform = (key: string, value: any) => {
10
- if (key.includes('scale')) {
11
- return value
12
- }
13
-
14
- if (typeof value === 'number') {
15
- return normalizeNumericValue(value)
16
- }
17
-
18
- return value
19
- }
20
-
21
- const createTransformValue = (transforms: Transforms) => transforms
22
- .map(transform => {
23
- const [key] = Object.keys(transform)
24
-
25
- if (!key) {
26
- return undefined
27
- }
28
-
29
- const value = transform[key]
30
-
31
- switch(key) {
32
- case 'matrix':
33
- case 'matrix3d':
34
- return `${key}(${(value as Array<number>).join(',')})`
35
- default:
36
- return `${key}(${normalizeTransform(key, value)})`
37
- }
38
- })
39
- .filter(Boolean)
40
- .join(' ')
41
-
42
- export const getTransformStyle = (transforms: Transforms): NestedCSSProperties => {
43
- const breakpoints = new Set<string>()
44
- const normalTransforms: Transforms = []
45
-
46
- transforms.forEach(transform => {
47
- const [property] = Object.keys(transform)
48
-
49
- if (!property) {
50
- return
51
- }
52
-
53
- const value = transform[property]
54
-
55
- if (typeof value === 'object' && !Array.isArray(value)) {
56
- Object.keys(value).forEach(breakpoint => breakpoints.add(breakpoint))
57
-
58
- return
59
- }
60
-
61
- normalTransforms.push(transform)
62
- })
63
-
64
- const breakpointTransforms = Array.from(breakpoints).flatMap(breakpoint => {
65
- const transformsPerBreakpoint = transforms.flatMap(transform => {
66
- const [property] = Object.keys(transform)
67
-
68
- if (!property) {
69
- return []
70
- }
71
-
72
- const value = transform[property]
73
-
74
- if (typeof value === 'object' && !Array.isArray(value)) {
75
- return keyInObject(value, breakpoint) ? [{ [property]: value[breakpoint] }] : []
76
- }
77
-
78
- return []
79
- })
80
-
81
- return media(convertBreakpoint(breakpoint), {
82
- transform: createTransformValue(transformsPerBreakpoint)
83
- })
84
- })
85
-
86
- return deepMergeObjects({
87
- transform: createTransformValue(normalTransforms)
88
- }, ...breakpointTransforms)
89
- }
package/web/create.ts DELETED
@@ -1,102 +0,0 @@
1
- import type { TypeStyle } from 'typestyle'
2
- import type { ReactNativeStyleSheet } from '../src/types'
3
- import type { StyleSheetWithSuperPowers, StyleSheet } from '../src/types/stylesheet'
4
- import { UnistylesRegistry } from './registry'
5
- import { keyInObject, reduceObject, toReactNativeClassName } from './utils'
6
- import { UnistylesRuntime } from './runtime'
7
- import { createUseVariants } from './useVariants'
8
- import { UnistylesListener } from './listener'
9
- import type { UnistyleDependency } from '../src/specs/NativePlatform'
10
-
11
- type ListenToDependenciesProps = {
12
- value: StyleSheet[keyof StyleSheet],
13
- key: PropertyKey,
14
- unistyles: TypeStyle,
15
- className: string,
16
- args?: Array<any>
17
- }
18
-
19
- export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
20
- const computedStylesheet = typeof stylesheet === 'function'
21
- ? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
22
- : stylesheet
23
-
24
- const listenToDependencies = ({ key, className, unistyles, value, args = [] } : ListenToDependenciesProps) => {
25
- const dependencies = ('uni__dependencies' in value ? value['uni__dependencies'] : []) as Array<UnistyleDependency>
26
-
27
- if (dependencies.length === 0) {
28
- return
29
- }
30
-
31
- return UnistylesListener.addListeners(dependencies, () => {
32
- const newComputedStylesheet = typeof stylesheet === 'function'
33
- ? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
34
- : stylesheet
35
-
36
- if (!keyInObject(newComputedStylesheet, key)) {
37
- return
38
- }
39
-
40
- const value = newComputedStylesheet[key]!
41
- const result = typeof value === 'function'
42
- ? value(...args)
43
- : value
44
-
45
- UnistylesRegistry.updateStyles(unistyles, result, className)
46
- })
47
- }
48
-
49
- const styles = reduceObject(computedStylesheet, (value, key) => {
50
- if (typeof value === 'function') {
51
- const classNameMap = new Map<number, string>()
52
- const unistylesMap = new Map<number, TypeStyle>()
53
- const disposeMap = new Map<number, VoidFunction | undefined>()
54
-
55
- return (...args: Array<any>) => {
56
- const [id] = args.slice(-1)
57
- const result = value(...args.slice(0, -1))
58
- const dispose = disposeMap.get(id)
59
- const unistyles = unistylesMap.get(id)
60
- const className = classNameMap.get(id)
61
-
62
- if (unistyles && className && dispose) {
63
- dispose()
64
- UnistylesRegistry.updateStyles(unistyles, result, className)
65
- disposeMap.set(id, listenToDependencies({
66
- key,
67
- value,
68
- unistyles,
69
- className,
70
- args
71
- }))
72
-
73
- return toReactNativeClassName(className, result)
74
- }
75
-
76
- const entry = UnistylesRegistry.createStyles(result, key)
77
-
78
- classNameMap.set(id, entry.className)
79
- unistylesMap.set(id, entry.unistyles)
80
- disposeMap.set(id, listenToDependencies({
81
- key,
82
- value,
83
- unistyles: entry.unistyles,
84
- className: entry.className,
85
- args
86
- }))
87
-
88
- return toReactNativeClassName(entry.className, result)
89
- }
90
- }
91
-
92
- const { className, unistyles } = UnistylesRegistry.createStyles(value, key)
93
-
94
- listenToDependencies({ key, value, unistyles, className })
95
-
96
- return toReactNativeClassName(className, value)
97
- }) as ReactNativeStyleSheet<StyleSheet>
98
-
99
- createUseVariants(styles)
100
-
101
- return styles
102
- }
@@ -1 +0,0 @@
1
- export { UnistylesListener } from './listener'
@@ -1,33 +0,0 @@
1
- import { UnistyleDependency } from '../../src/specs/NativePlatform'
2
- import { UnistylesRuntime } from '../runtime'
3
-
4
- export class UnistylesListenerBuilder {
5
- private isInitialized = false
6
- private listeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<VoidFunction>())
7
-
8
- emitChange = (dependency: UnistyleDependency) => {
9
- this.listeners[dependency]?.forEach(listener => listener())
10
- }
11
-
12
- initListeners = () => {
13
- if (this.isInitialized) {
14
- return
15
- }
16
-
17
- this.isInitialized = true
18
- UnistylesRuntime.darkMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme))
19
- UnistylesRuntime.lightMedia?.addEventListener('change', () => this.emitChange(UnistyleDependency.ColorScheme))
20
- window.addEventListener('orientationchange', () => this.emitChange(UnistyleDependency.Orientation))
21
- window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
22
- }
23
-
24
- addListeners = (dependencies: Array<UnistyleDependency>, listener: VoidFunction) => {
25
- dependencies.forEach(dependency => this.listeners[dependency]?.add(listener))
26
-
27
- return () => {
28
- dependencies.forEach(dependency => this.listeners[dependency]?.delete(listener))
29
- }
30
- }
31
- }
32
-
33
- export const UnistylesListener = new UnistylesListenerBuilder()
package/web/mq.ts DELETED
@@ -1,19 +0,0 @@
1
- import type { MediaQuery } from 'typestyle/lib/types'
2
-
3
- const IS_UNISTYLES_REGEX = /:([hw])\[(\d+)(?:,\s*(\d+|Infinity))?]/
4
- const UNISTYLES_WIDTH_REGEX = /:(w)\[(\d+)(?:,\s*(\d+|Infinity))?]/
5
- const UNISTYLES_HEIGHT_REGEX = /:(h)\[(\d+)(?:,\s*(\d+|Infinity))?]/
6
-
7
- export const parseMq = (mq: string): MediaQuery => {
8
- const [, width, fromW, toW] = UNISTYLES_WIDTH_REGEX.exec(mq) || []
9
- const [, height, fromH, toH] = UNISTYLES_HEIGHT_REGEX.exec(mq) || []
10
-
11
- return {
12
- minWidth: !width || fromW === 'Infinity' ? undefined : Number(fromW),
13
- maxWidth: !width || toW === 'Infinity' ? undefined : Number(toW),
14
- minHeight: !height || fromH === 'Infinity' ? undefined : Number(fromH),
15
- maxHeight: !height || toH === 'Infinity' ? undefined : Number(toH),
16
- }
17
- }
18
-
19
- export const isUnistylesMq = (mq: string) => IS_UNISTYLES_REGEX.test(mq)
package/web/pseudo.ts DELETED
@@ -1,11 +0,0 @@
1
- // TODO: Add complete list of pseudo selectors
2
- export const pseudos = [
3
- '_hover',
4
- '_css',
5
- '_before',
6
- '_after'
7
- ] as const
8
-
9
- export const isPseudo = (selector: string) => pseudos.includes(selector as Pseudo)
10
-
11
- export type Pseudo = typeof pseudos[number]
package/web/registry.ts DELETED
@@ -1,41 +0,0 @@
1
- import { createTypeStyle, TypeStyle } from 'typestyle'
2
- import type { UnistylesValues } from '../src/types'
3
- import { convertToTypeStyle } from './convert'
4
- import { UnistylesState } from './state'
5
-
6
- class UnistylesRegistryBuilder {
7
- createStyles = (stylesheet: UnistylesValues, key: string | number) => {
8
- const stylesTag = UnistylesState.createTag()
9
- const unistyles = createTypeStyle(stylesTag)
10
- const typestyleStylesheet = convertToTypeStyle(stylesheet)
11
-
12
- const className = unistyles.style({
13
- $debugName: String(key),
14
- }, typestyleStylesheet)
15
-
16
- if (stylesheet._web?._css) {
17
- const customClassName = Array.isArray(stylesheet._web._css)
18
- ? stylesheet._web._css.join(' ')
19
- : stylesheet._web._css
20
-
21
- return {
22
- className: `${className} ${customClassName}`,
23
- unistyles
24
- }
25
- }
26
-
27
- return {
28
- className,
29
- unistyles
30
- }
31
- }
32
-
33
- updateStyles = (unistyles: TypeStyle, stylesheet: UnistylesValues, className: string) => {
34
- const typestyleStylesheet = convertToTypeStyle(stylesheet)
35
-
36
- unistyles.reinit()
37
- unistyles.cssRule(`.${className}`, typestyleStylesheet)
38
- }
39
- }
40
-
41
- export const UnistylesRegistry = new UnistylesRegistryBuilder()
package/web/state.ts DELETED
@@ -1,148 +0,0 @@
1
- import { type ReactElement, createElement, createRef } from 'react'
2
- import type { UnistylesTheme } from '../src/types'
3
- import type { UnistylesConfig } from '../src/specs/StyleSheet'
4
- import type { AppBreakpoint, AppThemeName } from '../src/specs/types'
5
- import type { UnistylesBreakpoints, UnistylesThemes } from '../src/global'
6
- import { UnistylesRuntime } from './runtime'
7
- import { isServer, schemeToTheme } from './utils'
8
- import { UnistylesListener } from './listener'
9
- import { UnistyleDependency } from '../src/specs/NativePlatform'
10
-
11
- class UnistylesStateBuilder {
12
- private readonly isSSR = isServer()
13
- readonly tags = [] as Array<ReactElement>
14
-
15
- themes = new Map<string, UnistylesTheme>()
16
- themeName?: AppThemeName
17
-
18
- breakpoint?: AppBreakpoint
19
- breakpoints?: UnistylesBreakpoints
20
-
21
- hasAdaptiveThemes = false
22
-
23
- init = (config: UnistylesConfig) => {
24
- this.initThemes(config.themes)
25
- this.initBreakpoints(config.breakpoints)
26
- this.initSettings(config.settings)
27
-
28
- if (this.isSSR) {
29
- return
30
- }
31
-
32
- UnistylesListener.initListeners()
33
- }
34
-
35
- private initThemes = (themes = {} as UnistylesThemes) => {
36
- Object.entries(themes).forEach(([themeName, theme]) => {
37
- this.themes.set(themeName, theme)
38
- })
39
- }
40
-
41
- private initSettings = (settings: UnistylesConfig['settings']) => {
42
- this.hasAdaptiveThemes = settings?.adaptiveThemes ?? false
43
- const themeNames = Array.from(this.themes.keys()) as Array<AppThemeName>
44
-
45
- // Single theme + no settings
46
- if (!settings?.adaptiveThemes && !settings?.initialTheme && themeNames.length === 1) {
47
- this.themeName = themeNames[0]
48
-
49
- return
50
- }
51
-
52
- // No settings
53
- if (!settings?.adaptiveThemes && !settings?.initialTheme) {
54
- throw new Error('🦄 You need to specify either "initialTheme" or "adaptiveThemes" in your config')
55
- }
56
-
57
- // Adaptive themes
58
- if (settings.adaptiveThemes) {
59
- this.themeName = schemeToTheme(UnistylesRuntime.colorScheme)
60
-
61
- return
62
- }
63
-
64
- // Initial theme
65
- this.themeName = typeof settings.initialTheme === 'function' ? settings.initialTheme() : settings.initialTheme
66
- }
67
-
68
- private initBreakpoints = (breakpoints = {} as UnistylesBreakpoints) => {
69
- const breakpointsMap = new Map<string, MediaQueryList>()
70
-
71
- this.breakpoints = breakpoints
72
-
73
- Object.entries(breakpoints)
74
- .sort(([, a], [, b]) => a - b)
75
- .forEach(([breakpoint, value]) => {
76
- if (isServer()) {
77
- return
78
- }
79
-
80
- const mediaQuery = window.matchMedia(`(min-width: ${value}px)`)
81
- breakpointsMap.set(breakpoint, mediaQuery)
82
-
83
- if (mediaQuery.matches) {
84
- this.breakpoint = breakpoint as AppBreakpoint
85
- }
86
-
87
- mediaQuery.addEventListener('change', event => {
88
- if (!event.matches) {
89
- const [currentBreakpoint] = Array.from(breakpointsMap).find(([,mq]) => mq.matches) ?? []
90
-
91
- if (currentBreakpoint) {
92
- this.breakpoint = currentBreakpoint as AppBreakpoint
93
- UnistylesListener.emitChange(UnistyleDependency.Breakpoints)
94
- }
95
-
96
- return
97
- }
98
-
99
- this.breakpoint = breakpoint as AppBreakpoint
100
- UnistylesListener.emitChange(UnistyleDependency.Breakpoints)
101
- })
102
- })
103
- }
104
-
105
- createTag() {
106
- if (!this.isSSR) {
107
- const tag = document.createElement('style')
108
-
109
- document.head.appendChild(tag)
110
-
111
- return tag
112
- }
113
-
114
- const tagRef = new Proxy(createRef<HTMLStyleElement>(), {
115
- set: (target, prop, value) => {
116
- // When ref is assigned
117
- if ('textContent' in value) {
118
- value.textContent = tag.textContent
119
- }
120
-
121
- return Reflect.set(target, prop, value)
122
- }
123
- })
124
- const tagElement = createElement('style', { ref: tagRef, key: this.tags.length }, '')
125
- const tag = new Proxy({ textContent: '' }, {
126
- set: (target, prop, value) => {
127
- if (prop !== 'textContent') {
128
- return false
129
- }
130
-
131
- // When css is updated
132
- target.textContent = value
133
-
134
- if (tagRef.current) {
135
- tagRef.current.textContent = value
136
- }
137
-
138
- return true
139
- }
140
- })
141
-
142
- this.tags.push(tagElement)
143
-
144
- return tag
145
- }
146
- }
147
-
148
- export const UnistylesState = new UnistylesStateBuilder()
@@ -1,99 +0,0 @@
1
- import { useMemo, useRef, useState } from 'react'
2
- import type { TypeStyle } from 'typestyle'
3
- import type { ReactNativeStyleSheet, StyleSheet } from '../src/types'
4
- import { deepMergeObjects, equal, reduceObject } from './utils'
5
- import { UnistylesRegistry } from './registry'
6
-
7
- type StylesWithVariants = {
8
- variants: Record<string, any>,
9
- compoundVariants?: Array<Record<string, any> & {
10
- styles: Record<string, any>
11
- }>
12
- }
13
-
14
- const hasVariants = <T extends object>(value: [string, T]): value is [string, T & StylesWithVariants] => 'variants' in value[1]
15
-
16
- export const createUseVariants = (styles: ReactNativeStyleSheet<StyleSheet>) => {
17
- const useVariants = (selectedVariants: Record<string, any>) => {
18
- const [unistylesMap] = useState(() => new Map<string, TypeStyle>())
19
- const [classNameMap] = useState(() => new Map<string, string>())
20
- const [selectedVariantStylesMap] = useState(() => new Map<string, Record<string, any>>())
21
- const lastSelectedVariantsRef = useRef<Record<string, any>>()
22
- // Variable that determines if variants have changed and we need to recalculate styles
23
- const variantsChanged = !equal(lastSelectedVariantsRef.current, selectedVariants)
24
-
25
- if (variantsChanged) {
26
- lastSelectedVariantsRef.current = selectedVariants
27
- }
28
-
29
- const combinedVariantStyles = useMemo(() => {
30
- return Object.entries(styles)
31
- .filter(hasVariants)
32
- .filter(([_key, { variants }]) => Object.keys(variants).some(variant => variant in variants))
33
- .map(([key, { variants, compoundVariants = [] }]) => {
34
- const variantStyles = Object.entries(variants).flatMap(([variant, styles]) => {
35
- const selectedVariant = selectedVariants[variant]
36
- const selectedVariantStyles = styles[selectedVariant] ?? styles['default']
37
-
38
- if (!selectedVariantStyles) {
39
- return []
40
- }
41
-
42
- return selectedVariantStyles
43
- })
44
-
45
- const compoundVariantStyles = compoundVariants.flatMap(compoundVariant => {
46
- const { styles, ...conditions } = compoundVariant
47
-
48
- if (Object.entries(conditions).some(([variant, value]) => String(selectedVariants[variant]) !== String(value))) {
49
- return []
50
- }
51
-
52
- return styles
53
- })
54
-
55
- const mergedVariantStyles = deepMergeObjects(...variantStyles, ...compoundVariantStyles)
56
-
57
- selectedVariantStylesMap.set(key, mergedVariantStyles)
58
-
59
- return [key, mergedVariantStyles] as const
60
- })
61
- }, [lastSelectedVariantsRef.current])
62
-
63
- if (unistylesMap.size === 0 && combinedVariantStyles.length > 0) {
64
- combinedVariantStyles.forEach(([key, value]) => {
65
- const { className, unistyles } = UnistylesRegistry.createStyles(value, `variant-${key}`)
66
-
67
- unistylesMap.set(key, unistyles)
68
- classNameMap.set(key, className)
69
- })
70
- }
71
-
72
- combinedVariantStyles.forEach(([key, value]) => {
73
- const styleEntry = styles[key]
74
- const unistyles = unistylesMap.get(key)
75
- const className = classNameMap.get(key)
76
- const selectedVariantStyles = selectedVariantStylesMap.get(key)
77
-
78
- if (!unistyles || !className) {
79
- return
80
- }
81
-
82
- if (variantsChanged) {
83
- UnistylesRegistry.updateStyles(unistyles, value, className)
84
- }
85
-
86
- Object.defineProperties(styleEntry, reduceObject(selectedVariantStyles ?? {}, value => ({
87
- value,
88
- enumerable: false,
89
- configurable: true
90
- })))
91
- // @ts-expect-error - apply variant className
92
- styleEntry[className] = className
93
- })
94
- }
95
-
96
- Object.defineProperty(styles, 'useVariants', {
97
- value: useVariants
98
- })
99
- }
package/web/utils.ts DELETED
@@ -1,95 +0,0 @@
1
- import { ColorScheme, type AppThemeName} from '../src/specs/types'
2
- import type { UnistylesValues } from '../src/types'
3
-
4
- export const reduceObject = <TObj extends Record<string, any>, TReducer>(
5
- obj: TObj,
6
- reducer: (value: TObj[keyof TObj], key: keyof TObj) => TReducer,
7
- ) => Object.fromEntries(Object.entries(obj).map(([key, value]) => [key, reducer(value as TObj[keyof TObj], key)])) as { [K in keyof TObj]: TReducer }
8
-
9
- export const toReactNativeClassName = (className: string, values: UnistylesValues) => {
10
- const returnValue = {
11
- $$css: true,
12
- [className]: className
13
- }
14
-
15
- Object.defineProperties(returnValue, reduceObject(values, value => ({
16
- value,
17
- enumerable: false,
18
- configurable: true
19
- })))
20
-
21
- return returnValue
22
- }
23
-
24
- export const keyInObject = <T extends Record<string, any>>(obj: T, key: PropertyKey): key is keyof T => key in obj
25
-
26
- export const schemeToTheme = (scheme: ColorScheme): AppThemeName => {
27
- switch (scheme) {
28
- case ColorScheme.Dark:
29
- return 'dark'
30
- case ColorScheme.Light:
31
- default:
32
- return 'light'
33
- }
34
- }
35
-
36
- export const hexToRGBA = (hex: string, opacity: number) => hex
37
- .replace('#', '')
38
- .split(/(?=(?:..)*$)/)
39
- .map(x => parseInt(x, 16))
40
- .filter(num => !isNaN(num))
41
- .reduce((acc, color) => `${acc}${color},`, 'rgba(')
42
- .concat(`${opacity})`)
43
-
44
- export const isServer = () => typeof window === 'undefined'
45
-
46
- /**
47
- * Deeply merges properties of passed object
48
- */
49
- export const deepMergeObjects = <T extends Record<PropertyKey, any>>(...sources: Array<T>) => {
50
- const target = {} as T
51
-
52
- sources.forEach(source => {
53
- Object.keys(source).forEach(key => {
54
- const sourceValue = source[key]
55
- const targetValue = target[key]
56
-
57
- if (Object(sourceValue) == sourceValue && Object(targetValue) === targetValue) {
58
- // @ts-expect-error - can't assign to generic
59
- target[key] = deepMergeObjects(targetValue, sourceValue)
60
-
61
- return
62
- }
63
-
64
- // @ts-expect-error - can't assign to generic
65
- target[key] = sourceValue
66
- })
67
- })
68
-
69
- return target
70
- }
71
-
72
- export const warn = (message: string) => console.warn(`🦄 [react-native-unistyles] ${message}`)
73
-
74
- export const equal = <T>(a: T, b: T) => {
75
- if (Object.is(a, b)) {
76
- return true
77
- }
78
-
79
- if (
80
- typeof a !== 'object'
81
- || a === null
82
- || typeof b !== 'object'
83
- || b === null
84
- ) {
85
- return false
86
- }
87
-
88
- const keysA = Object.keys(a) as Array<keyof T>
89
-
90
- if (keysA.length !== Object.keys(b).length) {
91
- return false
92
- }
93
-
94
- return keysA.every(key => Object.is(a[key], b[key]) && Object.prototype.hasOwnProperty.call(b, key))
95
- }
File without changes