react-native-unistyles 3.0.0-rc.4 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (338) hide show
  1. package/README.md +9 -7
  2. package/Unistyles.podspec +12 -1
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/cxx/NativeUnistylesModule.cpp +5 -8
  5. package/android/src/main/cxx/NativeUnistylesModule.h +4 -4
  6. package/android/src/main/java/com/unistyles/NativePlatform+android.kt +1 -0
  7. package/android/src/main/java/com/unistyles/NativePlatform+insets.kt +21 -9
  8. package/android/src/main/java/com/unistyles/UnistylesModule.kt +8 -7
  9. package/cxx/core/UnistyleWrapper.h +4 -1
  10. package/cxx/core/UnistylesCommitShadowNode.h +0 -21
  11. package/cxx/core/UnistylesRegistry.cpp +52 -49
  12. package/cxx/core/UnistylesRegistry.h +2 -1
  13. package/cxx/core/UnistylesState.cpp +10 -0
  14. package/cxx/core/UnistylesState.h +3 -0
  15. package/cxx/hybridObjects/HybridShadowRegistry.cpp +6 -1
  16. package/cxx/hybridObjects/HybridShadowRegistry.h +6 -0
  17. package/cxx/hybridObjects/HybridStyleSheet.cpp +13 -16
  18. package/cxx/hybridObjects/HybridStyleSheet.h +2 -7
  19. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +17 -2
  20. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  21. package/cxx/parser/Parser.cpp +175 -110
  22. package/cxx/parser/Parser.h +1 -0
  23. package/cxx/shadowTree/ShadowTreeManager.cpp +36 -33
  24. package/cxx/shadowTree/ShadowTreeManager.h +0 -1
  25. package/get_rn_version.rb +28 -0
  26. package/ios/UnistylesModuleOnLoad.h +1 -5
  27. package/ios/UnistylesModuleOnLoad.mm +10 -13
  28. package/lib/commonjs/components/AdaptiveTheme.js +35 -0
  29. package/lib/commonjs/components/AdaptiveTheme.js.map +1 -0
  30. package/lib/commonjs/components/ApplyScopedTheme.js +19 -0
  31. package/lib/commonjs/components/ApplyScopedTheme.js.map +1 -0
  32. package/lib/commonjs/components/NamedTheme.js +31 -0
  33. package/lib/commonjs/components/NamedTheme.js.map +1 -0
  34. package/lib/commonjs/components/ScopedTheme.js +30 -21
  35. package/lib/commonjs/components/ScopedTheme.js.map +1 -1
  36. package/lib/commonjs/components/native/Image.js +1 -2
  37. package/lib/commonjs/components/native/Image.js.map +1 -1
  38. package/lib/commonjs/components/native/ImageBackground.js +1 -2
  39. package/lib/commonjs/components/native/ImageBackground.js.map +1 -1
  40. package/lib/commonjs/components/native/Pressable.js +1 -2
  41. package/lib/commonjs/components/native/Pressable.js.map +1 -1
  42. package/lib/commonjs/components/native/Pressable.native.js +1 -2
  43. package/lib/commonjs/components/native/Pressable.native.js.map +1 -1
  44. package/lib/commonjs/core/createUnistylesElement.js +5 -5
  45. package/lib/commonjs/core/createUnistylesElement.js.map +1 -1
  46. package/lib/commonjs/core/createUnistylesElement.native.js +18 -31
  47. package/lib/commonjs/core/createUnistylesElement.native.js.map +1 -1
  48. package/lib/commonjs/core/createUnistylesImageBackground.js +6 -21
  49. package/lib/commonjs/core/createUnistylesImageBackground.js.map +1 -1
  50. package/lib/commonjs/core/getClassname.js +1 -2
  51. package/lib/commonjs/core/getClassname.js.map +1 -1
  52. package/lib/commonjs/core/parseBoxShadow.js +57 -0
  53. package/lib/commonjs/core/parseBoxShadow.js.map +1 -0
  54. package/lib/commonjs/core/useProxifiedUnistyles/listener.js +2 -3
  55. package/lib/commonjs/core/useProxifiedUnistyles/listener.js.map +1 -1
  56. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js +2 -1
  57. package/lib/commonjs/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  58. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
  59. package/lib/commonjs/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  60. package/lib/commonjs/core/withUnistyles/withUnistyles.js +10 -5
  61. package/lib/commonjs/core/withUnistyles/withUnistyles.js.map +1 -1
  62. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js +10 -5
  63. package/lib/commonjs/core/withUnistyles/withUnistyles.native.js.map +1 -1
  64. package/lib/commonjs/index.js +6 -0
  65. package/lib/commonjs/index.js.map +1 -1
  66. package/lib/commonjs/mocks.js +26 -2
  67. package/lib/commonjs/mocks.js.map +1 -1
  68. package/lib/commonjs/reanimated/index.js +7 -0
  69. package/lib/commonjs/reanimated/index.js.map +1 -1
  70. package/lib/commonjs/reanimated/variant/index.js +17 -0
  71. package/lib/commonjs/reanimated/variant/index.js.map +1 -0
  72. package/lib/commonjs/reanimated/variant/types.js +2 -0
  73. package/lib/commonjs/reanimated/variant/types.js.map +1 -0
  74. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js +38 -0
  75. package/lib/commonjs/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  76. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js +66 -0
  77. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  78. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js +39 -0
  79. package/lib/commonjs/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  80. package/lib/commonjs/server/getServerUnistyles.js +1 -2
  81. package/lib/commonjs/server/getServerUnistyles.js.map +1 -1
  82. package/lib/commonjs/server/hydrateServerUnistyles.js +1 -2
  83. package/lib/commonjs/server/hydrateServerUnistyles.js.map +1 -1
  84. package/lib/commonjs/server/resetServerUnistyles.js +1 -2
  85. package/lib/commonjs/server/resetServerUnistyles.js.map +1 -1
  86. package/lib/commonjs/specs/ShadowRegistry/index.js +6 -1
  87. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  88. package/lib/commonjs/specs/StyleSheet/index.js +3 -1
  89. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  90. package/lib/commonjs/specs/UnistylesRuntime/index.js +0 -1
  91. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  92. package/lib/commonjs/utils.js +0 -3
  93. package/lib/commonjs/utils.js.map +1 -1
  94. package/lib/commonjs/web/convert/object/boxShadow.js.map +1 -1
  95. package/lib/commonjs/web/convert/pseudo.js +13 -3
  96. package/lib/commonjs/web/convert/pseudo.js.map +1 -1
  97. package/lib/commonjs/web/convert/utils.js +1 -0
  98. package/lib/commonjs/web/convert/utils.js.map +1 -1
  99. package/lib/commonjs/web/create.js +2 -3
  100. package/lib/commonjs/web/create.js.map +1 -1
  101. package/lib/commonjs/web/css/core.js +9 -2
  102. package/lib/commonjs/web/css/core.js.map +1 -1
  103. package/lib/commonjs/web/css/state.js +10 -7
  104. package/lib/commonjs/web/css/state.js.map +1 -1
  105. package/lib/commonjs/web/index.js +1 -2
  106. package/lib/commonjs/web/index.js.map +1 -1
  107. package/lib/commonjs/web/listener.js +4 -2
  108. package/lib/commonjs/web/listener.js.map +1 -1
  109. package/lib/commonjs/web/runtime.js +26 -2
  110. package/lib/commonjs/web/runtime.js.map +1 -1
  111. package/lib/commonjs/web/shadowRegistry.js +5 -3
  112. package/lib/commonjs/web/shadowRegistry.js.map +1 -1
  113. package/lib/commonjs/web/state.js +1 -10
  114. package/lib/commonjs/web/state.js.map +1 -1
  115. package/lib/commonjs/web/types.js.map +1 -1
  116. package/lib/commonjs/web/utils/createUnistylesRef.js +1 -2
  117. package/lib/commonjs/web/utils/createUnistylesRef.js.map +1 -1
  118. package/lib/commonjs/web/utils/unistyle.js +26 -4
  119. package/lib/commonjs/web/utils/unistyle.js.map +1 -1
  120. package/lib/module/components/AdaptiveTheme.js +29 -0
  121. package/lib/module/components/AdaptiveTheme.js.map +1 -0
  122. package/lib/module/components/ApplyScopedTheme.js +14 -0
  123. package/lib/module/components/ApplyScopedTheme.js.map +1 -0
  124. package/lib/module/components/NamedTheme.js +25 -0
  125. package/lib/module/components/NamedTheme.js.map +1 -0
  126. package/lib/module/components/ScopedTheme.js +30 -20
  127. package/lib/module/components/ScopedTheme.js.map +1 -1
  128. package/lib/module/core/createUnistylesElement.js +5 -5
  129. package/lib/module/core/createUnistylesElement.js.map +1 -1
  130. package/lib/module/core/createUnistylesElement.native.js +18 -30
  131. package/lib/module/core/createUnistylesElement.native.js.map +1 -1
  132. package/lib/module/core/createUnistylesImageBackground.js +5 -19
  133. package/lib/module/core/createUnistylesImageBackground.js.map +1 -1
  134. package/lib/module/core/parseBoxShadow.js +52 -0
  135. package/lib/module/core/parseBoxShadow.js.map +1 -0
  136. package/lib/module/core/useProxifiedUnistyles/listener.js +1 -1
  137. package/lib/module/core/useProxifiedUnistyles/listener.js.map +1 -1
  138. package/lib/module/core/useProxifiedUnistyles/listener.native.js +2 -1
  139. package/lib/module/core/useProxifiedUnistyles/listener.native.js.map +1 -1
  140. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js +14 -2
  141. package/lib/module/core/useProxifiedUnistyles/useProxifiedUnistyles.js.map +1 -1
  142. package/lib/module/core/withUnistyles/withUnistyles.js +9 -3
  143. package/lib/module/core/withUnistyles/withUnistyles.js.map +1 -1
  144. package/lib/module/core/withUnistyles/withUnistyles.native.js +9 -3
  145. package/lib/module/core/withUnistyles/withUnistyles.native.js.map +1 -1
  146. package/lib/module/index.js +5 -0
  147. package/lib/module/index.js.map +1 -1
  148. package/lib/module/mocks.js +26 -2
  149. package/lib/module/mocks.js.map +1 -1
  150. package/lib/module/reanimated/index.js +1 -0
  151. package/lib/module/reanimated/index.js.map +1 -1
  152. package/lib/module/reanimated/variant/index.js +4 -0
  153. package/lib/module/reanimated/variant/index.js.map +1 -0
  154. package/lib/module/reanimated/variant/types.js +2 -0
  155. package/lib/module/reanimated/variant/types.js.map +1 -0
  156. package/lib/module/reanimated/variant/useAnimatedVariantColor.js +33 -0
  157. package/lib/module/reanimated/variant/useAnimatedVariantColor.js.map +1 -0
  158. package/lib/module/reanimated/variant/useUpdateVariantColor.js +61 -0
  159. package/lib/module/reanimated/variant/useUpdateVariantColor.js.map +1 -0
  160. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js +34 -0
  161. package/lib/module/reanimated/variant/useUpdateVariantColor.native.js.map +1 -0
  162. package/lib/module/specs/ShadowRegistry/index.js +6 -1
  163. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  164. package/lib/module/specs/StyleSheet/index.js +3 -1
  165. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  166. package/lib/module/specs/UnistylesRuntime/index.js +0 -1
  167. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  168. package/lib/module/utils.js +0 -3
  169. package/lib/module/utils.js.map +1 -1
  170. package/lib/module/web/convert/object/boxShadow.js.map +1 -1
  171. package/lib/module/web/convert/pseudo.js +10 -2
  172. package/lib/module/web/convert/pseudo.js.map +1 -1
  173. package/lib/module/web/convert/utils.js +1 -0
  174. package/lib/module/web/convert/utils.js.map +1 -1
  175. package/lib/module/web/create.js +1 -1
  176. package/lib/module/web/create.js.map +1 -1
  177. package/lib/module/web/css/core.js +9 -2
  178. package/lib/module/web/css/core.js.map +1 -1
  179. package/lib/module/web/css/state.js +10 -7
  180. package/lib/module/web/css/state.js.map +1 -1
  181. package/lib/module/web/listener.js +4 -2
  182. package/lib/module/web/listener.js.map +1 -1
  183. package/lib/module/web/runtime.js +27 -3
  184. package/lib/module/web/runtime.js.map +1 -1
  185. package/lib/module/web/shadowRegistry.js +5 -3
  186. package/lib/module/web/shadowRegistry.js.map +1 -1
  187. package/lib/module/web/state.js +1 -10
  188. package/lib/module/web/state.js.map +1 -1
  189. package/lib/module/web/types.js.map +1 -1
  190. package/lib/module/web/utils/unistyle.js +24 -3
  191. package/lib/module/web/utils/unistyle.js.map +1 -1
  192. package/lib/typescript/plugin/src/consts.d.ts +17 -0
  193. package/lib/typescript/plugin/src/consts.d.ts.map +1 -0
  194. package/lib/typescript/repack-plugin/src/index.d.ts +18 -0
  195. package/lib/typescript/repack-plugin/src/index.d.ts.map +1 -0
  196. package/lib/typescript/repack-plugin/src/loader.d.ts +9 -0
  197. package/lib/typescript/repack-plugin/src/loader.d.ts.map +1 -0
  198. package/lib/typescript/src/components/AdaptiveTheme.d.ts +8 -0
  199. package/lib/typescript/src/components/AdaptiveTheme.d.ts.map +1 -0
  200. package/lib/typescript/src/components/ApplyScopedTheme.d.ts +7 -0
  201. package/lib/typescript/src/components/ApplyScopedTheme.d.ts.map +1 -0
  202. package/lib/typescript/src/components/NamedTheme.d.ts +10 -0
  203. package/lib/typescript/src/components/NamedTheme.d.ts.map +1 -0
  204. package/lib/typescript/src/components/ScopedTheme.d.ts +10 -0
  205. package/lib/typescript/src/components/ScopedTheme.d.ts.map +1 -1
  206. package/lib/typescript/src/components/native/Animated.d.ts.map +1 -1
  207. package/lib/typescript/src/core/createUnistylesElement.d.ts.map +1 -1
  208. package/lib/typescript/src/core/createUnistylesElement.native.d.ts.map +1 -1
  209. package/lib/typescript/src/core/createUnistylesImageBackground.d.ts.map +1 -1
  210. package/lib/typescript/src/core/getClassname.d.ts.map +1 -1
  211. package/lib/typescript/src/core/parseBoxShadow.d.ts +11 -0
  212. package/lib/typescript/src/core/parseBoxShadow.d.ts.map +1 -0
  213. package/lib/typescript/src/core/passForwardRef.d.ts.map +1 -1
  214. package/lib/typescript/src/core/useProxifiedUnistyles/listener.d.ts.map +1 -1
  215. package/lib/typescript/src/core/useProxifiedUnistyles/listener.native.d.ts.map +1 -1
  216. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts +1 -1
  217. package/lib/typescript/src/core/useProxifiedUnistyles/types.d.ts.map +1 -1
  218. package/lib/typescript/src/core/useProxifiedUnistyles/useProxifiedUnistyles.d.ts.map +1 -1
  219. package/lib/typescript/src/core/warn.d.ts.map +1 -1
  220. package/lib/typescript/src/core/withUnistyles/types.d.ts +3 -1
  221. package/lib/typescript/src/core/withUnistyles/types.d.ts.map +1 -1
  222. package/lib/typescript/src/core/withUnistyles/withUnistyles.d.ts.map +1 -1
  223. package/lib/typescript/src/core/withUnistyles/withUnistyles.native.d.ts.map +1 -1
  224. package/lib/typescript/src/hooks/useMedia.d.ts.map +1 -1
  225. package/lib/typescript/src/hooks/useMedia.native.d.ts.map +1 -1
  226. package/lib/typescript/src/index.d.ts.map +1 -1
  227. package/lib/typescript/src/reanimated/index.d.ts +1 -0
  228. package/lib/typescript/src/reanimated/index.d.ts.map +1 -1
  229. package/lib/typescript/src/reanimated/variant/index.d.ts +2 -0
  230. package/lib/typescript/src/reanimated/variant/index.d.ts.map +1 -0
  231. package/lib/typescript/src/reanimated/variant/types.d.ts +10 -0
  232. package/lib/typescript/src/reanimated/variant/types.d.ts.map +1 -0
  233. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts +3 -0
  234. package/lib/typescript/src/reanimated/variant/useAnimatedVariantColor.d.ts.map +1 -0
  235. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts +6 -0
  236. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.d.ts.map +1 -0
  237. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts +6 -0
  238. package/lib/typescript/src/reanimated/variant/useUpdateVariantColor.native.d.ts.map +1 -0
  239. package/lib/typescript/src/server/getServerUnistyles.d.ts.map +1 -1
  240. package/lib/typescript/src/server/serialize.d.ts.map +1 -1
  241. package/lib/typescript/src/server/useServerUnistyles.d.ts.map +1 -1
  242. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +1 -0
  243. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  244. package/lib/typescript/src/specs/StatusBar/index.d.ts.map +1 -1
  245. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -0
  246. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  247. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts +2 -0
  248. package/lib/typescript/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.d.ts.map +1 -1
  249. package/lib/typescript/src/specs/UnistylesRuntime/index.d.ts.map +1 -1
  250. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  251. package/lib/typescript/src/utils.d.ts.map +1 -1
  252. package/lib/typescript/src/web/convert/index.d.ts.map +1 -1
  253. package/lib/typescript/src/web/convert/object/boxShadow.d.ts.map +1 -1
  254. package/lib/typescript/src/web/convert/object/filter.d.ts.map +1 -1
  255. package/lib/typescript/src/web/convert/object/objectStyle.d.ts.map +1 -1
  256. package/lib/typescript/src/web/convert/object/transform.d.ts.map +1 -1
  257. package/lib/typescript/src/web/convert/pseudo.d.ts +6 -3
  258. package/lib/typescript/src/web/convert/pseudo.d.ts.map +1 -1
  259. package/lib/typescript/src/web/convert/shadow/boxShadow.d.ts.map +1 -1
  260. package/lib/typescript/src/web/convert/shadow/getShadowBreakpoints.d.ts.map +1 -1
  261. package/lib/typescript/src/web/convert/shadow/textShadow.d.ts.map +1 -1
  262. package/lib/typescript/src/web/convert/style.d.ts.map +1 -1
  263. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -1
  264. package/lib/typescript/src/web/create.d.ts.map +1 -1
  265. package/lib/typescript/src/web/css/core.d.ts.map +1 -1
  266. package/lib/typescript/src/web/css/state.d.ts +2 -1
  267. package/lib/typescript/src/web/css/state.d.ts.map +1 -1
  268. package/lib/typescript/src/web/css/utils.d.ts.map +1 -1
  269. package/lib/typescript/src/web/listener.d.ts +4 -2
  270. package/lib/typescript/src/web/listener.d.ts.map +1 -1
  271. package/lib/typescript/src/web/registry.d.ts.map +1 -1
  272. package/lib/typescript/src/web/runtime.d.ts +2 -0
  273. package/lib/typescript/src/web/runtime.d.ts.map +1 -1
  274. package/lib/typescript/src/web/shadowRegistry.d.ts +2 -0
  275. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -1
  276. package/lib/typescript/src/web/state.d.ts.map +1 -1
  277. package/lib/typescript/src/web/types.d.ts +4 -1
  278. package/lib/typescript/src/web/types.d.ts.map +1 -1
  279. package/lib/typescript/src/web/utils/common.d.ts.map +1 -1
  280. package/lib/typescript/src/web/utils/createUnistylesRef.d.ts.map +1 -1
  281. package/lib/typescript/src/web/utils/unistyle.d.ts +5 -1
  282. package/lib/typescript/src/web/utils/unistyle.d.ts.map +1 -1
  283. package/lib/typescript/src/web/variants.d.ts.map +1 -1
  284. package/lib/typescript/src/web-only/getWebProps.d.ts.map +1 -1
  285. package/nitrogen/generated/ios/Unistyles-Swift-Cxx-Umbrella.hpp +1 -0
  286. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.cpp +2 -0
  287. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +2 -0
  288. package/package.json +33 -23
  289. package/plugin/index.d.ts +6 -5
  290. package/plugin/index.js +11 -6
  291. package/repack-plugin/index.d.ts +19 -0
  292. package/repack-plugin/index.js +149 -0
  293. package/src/components/AdaptiveTheme.tsx +34 -0
  294. package/src/components/ApplyScopedTheme.tsx +17 -0
  295. package/src/components/NamedTheme.tsx +33 -0
  296. package/src/components/ScopedTheme.tsx +51 -24
  297. package/src/core/createUnistylesElement.native.tsx +21 -31
  298. package/src/core/createUnistylesElement.tsx +8 -6
  299. package/src/core/createUnistylesImageBackground.tsx +7 -22
  300. package/src/core/parseBoxShadow.ts +87 -0
  301. package/src/core/useProxifiedUnistyles/listener.native.ts +3 -1
  302. package/src/core/useProxifiedUnistyles/listener.ts +1 -1
  303. package/src/core/useProxifiedUnistyles/types.ts +1 -1
  304. package/src/core/useProxifiedUnistyles/useProxifiedUnistyles.ts +19 -2
  305. package/src/core/withUnistyles/types.ts +1 -1
  306. package/src/core/withUnistyles/withUnistyles.native.tsx +10 -3
  307. package/src/core/withUnistyles/withUnistyles.tsx +11 -8
  308. package/src/index.ts +8 -0
  309. package/src/mocks.ts +28 -2
  310. package/src/reanimated/index.ts +1 -0
  311. package/src/reanimated/variant/index.ts +1 -0
  312. package/src/reanimated/variant/types.ts +14 -0
  313. package/src/reanimated/variant/useAnimatedVariantColor.ts +38 -0
  314. package/src/reanimated/variant/useUpdateVariantColor.native.ts +38 -0
  315. package/src/reanimated/variant/useUpdateVariantColor.ts +81 -0
  316. package/src/specs/ShadowRegistry/index.ts +7 -1
  317. package/src/specs/StyleSheet/index.ts +5 -2
  318. package/src/specs/UnistylesRuntime/UnistylesRuntime.nitro.ts +2 -0
  319. package/src/specs/UnistylesRuntime/index.ts +0 -1
  320. package/src/utils.ts +1 -3
  321. package/src/web/convert/object/boxShadow.ts +2 -2
  322. package/src/web/convert/pseudo.ts +23 -52
  323. package/src/web/convert/utils.ts +2 -1
  324. package/src/web/create.ts +1 -1
  325. package/src/web/css/core.ts +12 -2
  326. package/src/web/css/state.ts +10 -8
  327. package/src/web/listener.ts +10 -6
  328. package/src/web/runtime.ts +37 -3
  329. package/src/web/shadowRegistry.ts +5 -3
  330. package/src/web/state.ts +7 -17
  331. package/src/web/types.ts +4 -1
  332. package/src/web/utils/unistyle.ts +34 -4
  333. package/cxx/core/UnistylesCommitHook.cpp +0 -59
  334. package/cxx/core/UnistylesCommitHook.h +0 -27
  335. package/cxx/core/UnistylesMountHook.cpp +0 -26
  336. package/cxx/core/UnistylesMountHook.h +0 -24
  337. package/lib/module/package.json +0 -1
  338. /package/{web-only → web}/package.json +0 -0
package/src/utils.ts CHANGED
@@ -35,10 +35,8 @@ export const copyComponentProperties = (Component: any, UnistylesComponent: any)
35
35
  UnistylesComponent[key] = value
36
36
  })
37
37
 
38
- // Those are not enumerable, so we need to copy them manually
39
38
  UnistylesComponent.displayName = Component.displayName
40
- UnistylesComponent.name = Component.name
41
-
39
+
42
40
  return UnistylesComponent
43
41
  }
44
42
 
@@ -25,7 +25,7 @@ export const getBoxShadow = (boxShadow: Array<BoxShadowValue>) => {
25
25
  const boxShadowStyle = Object.fromEntries(boxShadow.map(shadow => {
26
26
  const [key] = Object.keys(shadow)
27
27
  return [key, shadow[key as keyof BoxShadowValue]]
28
- }))
28
+ })) as BoxShadowValue
29
29
 
30
30
  return {
31
31
  boxShadow: createBoxShadowValue(boxShadowStyle)
@@ -42,7 +42,7 @@ export const getBoxShadow = (boxShadow: Array<BoxShadowValue>) => {
42
42
  }
43
43
 
44
44
  return [key, value]
45
- }))
45
+ })) as BoxShadowValue
46
46
 
47
47
  return {
48
48
  [breakpoint]: {
@@ -1,26 +1,12 @@
1
- export const pseudos = [
2
- '_-moz-broken',
3
- '_-moz-drag-over',
4
- '_-moz-first-node',
5
- '_-moz-handler-blocked',
6
- '_-moz-handler-crashed',
7
- '_-moz-handler-disabled',
8
- '_-moz-last-node',
9
- '_-moz-loading',
10
- '_-moz-locale-dir(ltr)',
11
- '_-moz-locale-dir(rtl)',
12
- '_-moz-only-whitespace',
13
- '_-moz-submit-invalid',
14
- '_-moz-suppressed',
15
- '_-moz-user-disabled',
16
- '_-moz-window-inactive',
1
+ // All non experimental pseudo clasess and elements
2
+
3
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-classes
4
+ const pseudoClasses = [
17
5
  '_active',
18
6
  '_any-link',
19
7
  '_autofill',
20
- '_blank',
21
8
  '_buffering',
22
9
  '_checked',
23
- '_current',
24
10
  '_default',
25
11
  '_defined',
26
12
  '_dir(',
@@ -33,8 +19,8 @@ export const pseudos = [
33
19
  '_focus',
34
20
  '_focus-visible',
35
21
  '_focus-within',
36
- '_fullscreen',
37
22
  '_future',
23
+ '_has-slotted',
38
24
  '_has(',
39
25
  '_host',
40
26
  '_host-context(',
@@ -49,7 +35,6 @@ export const pseudos = [
49
35
  '_last-of-type',
50
36
  '_left',
51
37
  '_link',
52
- '_local-link',
53
38
  '_modal',
54
39
  '_muted',
55
40
  '_not(',
@@ -59,6 +44,7 @@ export const pseudos = [
59
44
  '_nth-of-type(',
60
45
  '_only-child',
61
46
  '_only-of-type',
47
+ '_open',
62
48
  '_optional',
63
49
  '_out-of-range',
64
50
  '_past',
@@ -71,45 +57,27 @@ export const pseudos = [
71
57
  '_read-write',
72
58
  '_required',
73
59
  '_right',
60
+ '_root',
74
61
  '_scope',
75
62
  '_seeking',
76
63
  '_stalled',
77
64
  '_state(',
78
65
  '_target',
79
- '_target-within',
80
66
  '_user-invalid',
81
67
  '_user-valid',
82
68
  '_valid',
83
69
  '_visited',
84
70
  '_volume-locked',
85
- '_where(',
86
- '_-moz-color-swatch',
87
- '_-moz-focus-inner',
88
- '_-moz-list-bullet',
89
- '_-moz-list-number',
90
- '_-moz-meter-bar',
91
- '_-moz-progress-bar',
92
- '_-moz-range-progress',
93
- '_-moz-range-thumb',
94
- '_-moz-range-track',
95
- '_-webkit-inner-spin-button',
96
- '_-webkit-meter-barDeprecated',
97
- '_-webkit-meter-even-less-good-value',
98
- '_-webkit-meter-inner-element',
99
- '_-webkit-meter-optimum-value',
100
- '_-webkit-meter-suboptimum-value',
101
- '_-webkit-progress-bar',
102
- '_-webkit-progress-inner-element',
103
- '_-webkit-progress-value',
104
- '_-webkit-scrollbar',
105
- '_-webkit-search-cancel-button',
106
- '_-webkit-search-results-button',
107
- '_-webkit-slider-runnable-track',
108
- '_-webkit-slider-thumb',
71
+ '_where',
72
+ ] as const
73
+
74
+ // https://developer.mozilla.org/en-US/docs/Web/CSS/Pseudo-elements
75
+ const pseudoElements = [
109
76
  '_after',
110
77
  '_backdrop',
111
78
  '_before',
112
79
  '_cue',
80
+ '_details-content',
113
81
  '_file-selector-button',
114
82
  '_first-letter',
115
83
  '_first-line',
@@ -123,15 +91,18 @@ export const pseudos = [
123
91
  '_spelling-error',
124
92
  '_target-text',
125
93
  '_view-transition',
126
- '_view-transition-group',
127
- '_view-transition-image-pair',
128
- '_view-transition-new',
129
- '_view-transition-old',
94
+ '_view-transition-group(',
95
+ '_view-transition-image-pair(',
96
+ '_view-transition-new(',
97
+ '_view-transition-old(',
130
98
  ] as const
131
99
 
132
- export const isPseudo = (selector: string) => pseudos.some(pseudo => selector.startsWith(pseudo))
133
-
134
100
  type AddDynamicSelector<T extends string> = T extends `${infer U}(` ? `${U}(${string})` : T
135
101
 
136
- export type Pseudo = AddDynamicSelector<typeof pseudos[number]>
102
+ export type Pseudo = AddDynamicSelector<(typeof pseudoClasses)[number] | (typeof pseudoElements)[number]>
103
+
104
+ export const isPseudoClass = (selector: string) => pseudoClasses.some(pseudo => selector.startsWith(pseudo))
105
+
106
+ export const isPseudoElement = (selector: string) => pseudoElements.some(pseudo => selector.startsWith(pseudo))
137
107
 
108
+ export const isPseudo = (selector: string) => isPseudoClass(selector) || isPseudoElement(selector)
@@ -1,5 +1,6 @@
1
1
  // based on react-native-web normalizer
2
2
  // https://github.com/necolas/react-native-web
3
+ /// <reference path="module.d.ts" />
3
4
  import normalizeColors from '@react-native/normalize-colors'
4
5
  import type { BoxShadowValue } from 'react-native'
5
6
  import type { TransformStyles } from '../../types/core'
@@ -30,7 +31,7 @@ export const normalizeColor = (color: string, opacity = 1) => {
30
31
  return color
31
32
  }
32
33
 
33
- const hex = integer.toString(16).padStart(8, '0')
34
+ const hex = integer.toString(16).padStart(8, '0') as string
34
35
 
35
36
  if (hex.length === 8) {
36
37
  const [r = 0, g = 0, b = 0, a = 1] = hex
package/src/web/create.ts CHANGED
@@ -21,7 +21,7 @@ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>, id?: s
21
21
  __uni__key: key,
22
22
  __uni__stylesheet: stylesheet,
23
23
  __uni__args: args,
24
- __uni_variants: variants
24
+ __stylesheetVariants: variants
25
25
  })
26
26
 
27
27
  const createStyleSheetStyles = (variants?: Variants) => {
@@ -1,10 +1,12 @@
1
+ import { isPseudoClass } from '../convert/pseudo'
1
2
  import { getMediaQuery } from '../utils'
2
3
  import type { CSSState } from './state'
3
4
 
4
5
  export const convertToCSS = (hash: string, value: Record<string, any>, state: CSSState) => {
5
6
  Object.entries(value).forEach(([styleKey, styleValue]) => {
6
7
  if (styleKey[0] === '_') {
7
- const pseudoClassName = styleKey.replace('_', `${hash}:`)
8
+ const isStylePseudoClass = isPseudoClass(styleKey)
9
+ const pseudoClassName = `${hash}${isStylePseudoClass ? ':' : '::'}${styleKey.slice(1)}`
8
10
 
9
11
  Object.entries(styleValue).forEach(([pseudoStyleKey, pseudoStyleValue]) => {
10
12
  if (typeof pseudoStyleValue === 'object' && pseudoStyleValue !== null) {
@@ -34,8 +36,16 @@ export const convertToCSS = (hash: string, value: Record<string, any>, state: CS
34
36
  }
35
37
 
36
38
  if (typeof styleValue === 'object') {
37
- const allBreakpoints = Object.keys(value)
38
39
  Object.entries(styleValue).forEach(([breakpointStyleKey, breakpointStyleValue]) => {
40
+ const allBreakpoints = Object.entries(value)
41
+ .filter(([_, value]) => {
42
+ if (typeof value !== 'object' || value === null) {
43
+ return false
44
+ }
45
+
46
+ return breakpointStyleKey in value
47
+ })
48
+ .map(([key]) => key)
39
49
  const mediaQuery = getMediaQuery(styleKey, allBreakpoints)
40
50
 
41
51
  state.set({
@@ -32,7 +32,7 @@ export class CSSState {
32
32
  mainMap: MapType = new Map()
33
33
  mqMap: MapType = new Map()
34
34
  private styleTag: HTMLStyleElement | null = null
35
- private CSS = ''
35
+ private themesCSS = new Map<string, string>()
36
36
 
37
37
  constructor(private services: UnistylesServices) {
38
38
  if (isServer()) {
@@ -62,7 +62,10 @@ export class CSSState {
62
62
 
63
63
  add = (hash: string, values: UnistylesValues) => {
64
64
  convertToCSS(hash, convertUnistyles(values, this.services.runtime), this)
65
+ this.recreate()
66
+ }
65
67
 
68
+ recreate = () => {
66
69
  if (this.styleTag) {
67
70
  this.styleTag.innerText = this.getStyles()
68
71
  }
@@ -84,10 +87,10 @@ export class CSSState {
84
87
  Object.entries(values).forEach(([key, value]) => convertToCSS(key, value))
85
88
 
86
89
  if (theme === 'light' || theme === 'dark') {
87
- this.CSS += `@media (prefers-color-scheme: ${theme}){:root{${themeVars}}}`
90
+ this.themesCSS.set(`media ${theme}`, `@media (prefers-color-scheme: ${theme}){:root{${themeVars}}}`)
88
91
  }
89
92
 
90
- this.CSS += `:root.${theme}{${themeVars}}`
93
+ this.themesCSS.set(theme, `:root.${theme}{${themeVars}}`)
91
94
  }
92
95
 
93
96
  remove = (hash: string) => {
@@ -97,14 +100,13 @@ export class CSSState {
97
100
  this.mqMap.forEach(styles => {
98
101
  styles.delete(hash)
99
102
  })
100
-
101
- if (this.styleTag) {
102
- this.styleTag.innerText = this.getStyles()
103
- }
103
+ this.recreate()
104
104
  }
105
105
 
106
106
  getStyles = () => {
107
- let styles = this.CSS
107
+ let styles = Array.from(this.themesCSS.entries()).reduce((acc, [, themeCss]) => {
108
+ return acc + themeCss
109
+ }, '')
108
110
 
109
111
  const generate = (mediaQuery: string, secondLevelMap: Map<string, Map<string, string>>) => {
110
112
  if (mediaQuery) {
@@ -1,16 +1,18 @@
1
1
  import { UnistyleDependency } from '../specs/NativePlatform'
2
2
  import type { UnistylesServices } from './types'
3
3
 
4
+ type Listener = (dependency: UnistyleDependency) => void
5
+
4
6
  export class UnistylesListener {
5
7
  private isInitialized = false
6
- private listeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<VoidFunction>())
7
- private stylesheetListeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<VoidFunction>())
8
+ private listeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<Listener>())
9
+ private stylesheetListeners = Array.from({ length: Object.keys(UnistyleDependency).length / 2 }, () => new Set<Listener>())
8
10
 
9
11
  constructor(private services: UnistylesServices) {}
10
12
 
11
13
  emitChange = (dependency: UnistyleDependency) => {
12
- this.stylesheetListeners[dependency]?.forEach(listener => listener())
13
- this.listeners[dependency]?.forEach(listener => listener())
14
+ this.stylesheetListeners[dependency]?.forEach(listener => listener(dependency))
15
+ this.listeners[dependency]?.forEach(listener => listener(dependency))
14
16
  }
15
17
 
16
18
  initListeners = () => {
@@ -29,6 +31,7 @@ export class UnistylesListener {
29
31
 
30
32
  if (this.services.runtime.hasAdaptiveThemes) {
31
33
  this.emitChange(UnistyleDependency.Theme)
34
+ this.emitChange(UnistyleDependency.ThemeName)
32
35
  }
33
36
  })
34
37
  this.services.runtime.lightMedia?.addEventListener('change', event => {
@@ -40,6 +43,7 @@ export class UnistylesListener {
40
43
 
41
44
  if (this.services.runtime.hasAdaptiveThemes) {
42
45
  this.emitChange(UnistyleDependency.Theme)
46
+ this.emitChange(UnistyleDependency.ThemeName)
43
47
  }
44
48
  })
45
49
 
@@ -47,7 +51,7 @@ export class UnistylesListener {
47
51
  window.addEventListener('resize', () => this.emitChange(UnistyleDependency.Dimensions))
48
52
  }
49
53
 
50
- addListeners = (dependencies: Array<UnistyleDependency>, listener: VoidFunction) => {
54
+ addListeners = (dependencies: Array<UnistyleDependency>, listener: Listener) => {
51
55
  dependencies.forEach(dependency => this.listeners[dependency]?.add(listener))
52
56
 
53
57
  return () => {
@@ -55,7 +59,7 @@ export class UnistylesListener {
55
59
  }
56
60
  }
57
61
 
58
- addStylesheetListeners = (dependencies: Array<UnistyleDependency>, listener: VoidFunction) => {
62
+ addStylesheetListeners = (dependencies: Array<UnistyleDependency>, listener: Listener) => {
59
63
  dependencies.forEach(dependency => this.stylesheetListeners[dependency]?.add(listener))
60
64
 
61
65
  return () => {
@@ -4,7 +4,7 @@ import { type AppTheme, type AppThemeName, ColorScheme, Orientation } from '../s
4
4
  import { type UnistylesTheme, WebContentSizeCategory } from '../types'
5
5
  import { NavigationBar, StatusBar } from './mock'
6
6
  import type { UnistylesServices } from './types'
7
- import { error, isServer, schemeToTheme } from './utils'
7
+ import { convertTheme, error, isServer, schemeToTheme } from './utils'
8
8
 
9
9
  export class UnistylesRuntime {
10
10
  lightMedia = this.getLightMedia()
@@ -49,6 +49,12 @@ export class UnistylesRuntime {
49
49
  }
50
50
 
51
51
  get themeName() {
52
+ const scopedTheme = this.services.shadowRegistry.getScopedTheme()
53
+
54
+ if (scopedTheme) {
55
+ return scopedTheme
56
+ }
57
+
52
58
  if (this.services.state.hasAdaptiveThemes) {
53
59
  return schemeToTheme(this.colorScheme) as AppThemeName
54
60
  }
@@ -76,6 +82,14 @@ export class UnistylesRuntime {
76
82
  return screen.orientation.type.includes('portrait') ? Orientation.Portrait : Orientation.Landscape
77
83
  }
78
84
 
85
+ get isLandscape() {
86
+ return this.orientation === Orientation.Landscape
87
+ }
88
+
89
+ get isPortrait() {
90
+ return this.orientation === Orientation.Portrait
91
+ }
92
+
79
93
  get theme() {
80
94
  return this.getTheme(this.themeName)
81
95
  }
@@ -175,9 +189,14 @@ export class UnistylesRuntime {
175
189
  }
176
190
 
177
191
  setAdaptiveThemes = (isEnabled: boolean) => {
178
- this.services.state.hasAdaptiveThemes = isEnabled
192
+ if (this.services.state.hasAdaptiveThemes === isEnabled) {
193
+ return
194
+ }
195
+
196
+ this.services.listener.emitChange(UnistyleDependency.AdaptiveThemes)
179
197
 
180
198
  if (!isEnabled) {
199
+ this.services.state.hasAdaptiveThemes = isEnabled
181
200
  this.rootElement?.classList.add(this.themeName ?? '')
182
201
 
183
202
  return
@@ -185,6 +204,7 @@ export class UnistylesRuntime {
185
204
 
186
205
  this.rootElement?.classList.remove(this.themeName ?? '')
187
206
  this.setTheme(schemeToTheme(this.colorScheme) as AppThemeName)
207
+ this.services.state.hasAdaptiveThemes = isEnabled
188
208
  }
189
209
 
190
210
  setRootViewBackgroundColor = (color: string) => {
@@ -204,7 +224,21 @@ export class UnistylesRuntime {
204
224
  throw error(`Unistyles: You're trying to update theme "${themeName}" but it wasn't registered.`)
205
225
  }
206
226
 
207
- this.services.state.themes.set(themeName, updater(oldTheme))
227
+ const newTheme = updater(oldTheme)
228
+
229
+ this.services.state.themes.set(themeName, newTheme)
230
+ this.services.listener.emitChange(UnistyleDependency.Theme)
231
+
232
+ if (this.services.state.CSSVars) {
233
+ this.services.state.cssThemes.set(
234
+ themeName,
235
+ Object.fromEntries(Object.entries(newTheme).map(([key, value]) => {
236
+ return convertTheme(key, value)
237
+ })) as UnistylesTheme
238
+ )
239
+ this.services.registry.css.addTheme(themeName, newTheme)
240
+ this.services.registry.css.recreate()
241
+ }
208
242
  }
209
243
 
210
244
  getTheme = (themeName = this.themeName, CSSVars = false) => {
@@ -20,7 +20,7 @@ export class UnistylesShadowRegistry {
20
20
  constructor(private services: UnistylesServices) {}
21
21
 
22
22
  add = (ref: any, hash?: string) => {
23
- if (!(ref instanceof HTMLElement) || !hash) {
23
+ if (isServer() || !(ref instanceof HTMLElement) || !hash) {
24
24
  return
25
25
  }
26
26
 
@@ -49,7 +49,7 @@ export class UnistylesShadowRegistry {
49
49
  return {}
50
50
  }
51
51
 
52
- const { __uni__key, __uni__stylesheet, __uni__args = [], __uni_variants: variants } = secrets
52
+ const { __uni__key, __uni__stylesheet, __uni__args = [], __stylesheetVariants: variants } = secrets
53
53
  const newComputedStylesheet = this.services.registry.getComputedStylesheet(__uni__stylesheet, scopedTheme)
54
54
  const style = newComputedStylesheet[__uni__key] as (UnistylesValues | ((...args: any) => UnistylesValues))
55
55
  const result = typeof style === 'function'
@@ -94,7 +94,7 @@ export class UnistylesShadowRegistry {
94
94
  ? hash.replace(' > *', '')
95
95
  : hash
96
96
 
97
- return { injectedClassName, hash: hashClassname }
97
+ return { injectedClassName, hash: hashClassname, parsedStyles }
98
98
  }
99
99
 
100
100
  setScopedTheme = (theme?: UnistylesTheme) => {
@@ -118,4 +118,6 @@ export class UnistylesShadowRegistry {
118
118
  this.disposeMap.delete(hash)
119
119
  })
120
120
  }
121
+
122
+ flush = () => {}
121
123
  }
package/src/web/state.ts CHANGED
@@ -5,7 +5,7 @@ import type { AppBreakpoint, AppTheme, AppThemeName } from '../specs/types'
5
5
  import type { UnistylesTheme } from '../types'
6
6
  import type { UnionToIntersection } from '../types'
7
7
  import type { UnistylesServices } from './types'
8
- import { error, hyphenate, isServer, schemeToTheme } from './utils'
8
+ import { convertTheme, error, isServer, schemeToTheme } from './utils'
9
9
 
10
10
  type UnistylesSettings = Partial<UnionToIntersection<Required<UnistylesConfig>['settings']>>
11
11
 
@@ -72,22 +72,12 @@ export class UnistylesState {
72
72
 
73
73
  if (CSSVars) {
74
74
  this.services.registry.css.addTheme(themeName, theme)
75
-
76
- const convertTheme = (key: string, value: any, prev = '-'): [string, any] => {
77
- if (typeof value === 'object' && value !== null) {
78
- return [key, Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => convertTheme(nestedKey, nestedValue, `${prev}-${key}`)))]
79
- }
80
-
81
- if (typeof value === 'string') {
82
- return [key, `var(${prev}-${hyphenate(key)})`]
83
- }
84
-
85
- return [key, value]
86
- }
87
-
88
- this.cssThemes.set(themeName, Object.fromEntries(Object.entries(theme).map(([key, value]) => {
89
- return convertTheme(key, value)
90
- })) as UnistylesTheme)
75
+ this.cssThemes.set(
76
+ themeName,
77
+ Object.fromEntries(Object.entries(theme).map(([key, value]) => {
78
+ return convertTheme(key, value)
79
+ })) as UnistylesTheme
80
+ )
91
81
  }
92
82
  })
93
83
  }
package/src/web/types.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { UnistylesValues } from '../types'
1
2
  import type { UnistylesListener } from './listener'
2
3
  import type { UnistylesRegistry } from './registry'
3
4
  import type { UnistylesRuntime } from './runtime'
@@ -15,4 +16,6 @@ export type UnistylesServices = {
15
16
  export const UNI_GENERATED_KEYS = ['$$css', 'hash', 'injectedClassName'] as const
16
17
  export type UniGeneratedKey = typeof UNI_GENERATED_KEYS[number]
17
18
 
18
- export type UniGeneratedStyle = Record<UniGeneratedKey, string>
19
+ export type UniGeneratedStyle = Record<UniGeneratedKey, string> & {
20
+ parsedStyles?: UnistylesValues
21
+ }
@@ -3,10 +3,11 @@ import type { UnistylesBreakpoints } from '../../global'
3
3
  import type { UnistyleDependency } from '../../specs/NativePlatform/NativePlatform.nitro'
4
4
  import { ColorScheme, Orientation } from '../../specs/types'
5
5
  import type { StyleSheet, StyleSheetWithSuperPowers, UnistylesValues } from '../../types/stylesheet'
6
- import { isUnistylesMq, parseMq } from '../../utils'
6
+ import { isDefined, isUnistylesMq, parseMq } from '../../utils'
7
+ import type { UnistylesRuntime } from '../runtime'
7
8
  import * as unistyles from '../services'
8
9
  import { UNI_GENERATED_KEYS, type UniGeneratedKey, type UniGeneratedStyle } from '../types'
9
- import { keyInObject, reduceObject } from './common'
10
+ import { hyphenate, keyInObject, reduceObject } from './common'
10
11
 
11
12
  export const schemeToTheme = (scheme: ColorScheme) => {
12
13
  switch (scheme) {
@@ -22,7 +23,7 @@ export type UnistyleSecrets = {
22
23
  __uni__stylesheet: StyleSheetWithSuperPowers<StyleSheet>,
23
24
  __uni__key: string,
24
25
  __uni__args?: Array<any>,
25
- __uni_variants: Record<string, string | boolean | undefined>
26
+ __stylesheetVariants: Record<string, string | boolean | undefined>
26
27
  }
27
28
 
28
29
  export const assignSecrets = <T>(object: T, secrets: UnistyleSecrets) => {
@@ -142,5 +143,34 @@ export const checkForAnimated = (value: any): boolean => {
142
143
  }
143
144
 
144
145
  export const isGeneratedUnistyle = (value: Record<string, any>): value is UniGeneratedStyle => {
145
- return Object.keys(value).every(key => UNI_GENERATED_KEYS.includes(key as UniGeneratedKey))
146
+ const keys = Object.keys(value)
147
+
148
+ return keys.length > 0 && keys.every(key => UNI_GENERATED_KEYS.includes(key as UniGeneratedKey))
149
+ }
150
+
151
+ export const convertTheme = (key: string, value: any, prev = '-'): [string, any] => {
152
+ if (typeof value === 'object' && value !== null) {
153
+ return [key, Object.fromEntries(Object.entries(value).map(([nestedKey, nestedValue]) => convertTheme(nestedKey, nestedValue, `${prev}-${key}`)))]
154
+ }
155
+
156
+ if (typeof value === 'string') {
157
+ return [key, `var(${prev}-${hyphenate(key)})`]
158
+ }
159
+
160
+ return [key, value]
161
+ }
162
+
163
+ export const getClosestBreakpointValue = <T>(runtime: UnistylesRuntime, values: Partial<Record<keyof UnistylesBreakpoints, T>>) => {
164
+ const breakpoints = runtime.breakpoints
165
+ const breakpointValues = Object.entries(values)
166
+ // Filter out non-breakpoint values
167
+ .filter((pair): pair is [keyof UnistylesBreakpoints, T] => pair[0] in breakpoints)
168
+ // Sort in descending order
169
+ .sort(([a], [b]) => (breakpoints[b] ?? 0) - (breakpoints[a] ?? 0))
170
+ // Get breakpoint value with highest priority
171
+ const [_, currentBreakpointValue] = breakpointValues.find(
172
+ ([key]) => isDefined(runtime.breakpoint) && (breakpoints[key] ?? 0) <= (breakpoints[runtime.breakpoint] ?? 0)
173
+ ) ?? []
174
+
175
+ return currentBreakpointValue
146
176
  }
@@ -1,59 +0,0 @@
1
- #include "UnistylesCommitHook.h"
2
-
3
- using namespace margelo::nitro::unistyles;
4
- using namespace facebook::react;
5
-
6
- core::UnistylesCommitHook::~UnistylesCommitHook() noexcept {
7
- _uiManager->unregisterCommitHook(*this);
8
- }
9
-
10
- void core::UnistylesCommitHook::commitHookWasRegistered(const UIManager &uiManager) noexcept {}
11
- void core::UnistylesCommitHook::commitHookWasUnregistered(const UIManager &uiManager) noexcept {}
12
-
13
- RootShadowNode::Unshared core::UnistylesCommitHook::shadowTreeWillCommit(
14
- const ShadowTree &shadowTree,
15
- const RootShadowNode::Shared &oldRootShadowNode,
16
- const RootShadowNode::Unshared &newRootShadowNode
17
- ) noexcept {
18
- RootShadowNode::Unshared rootNode = newRootShadowNode;
19
- auto unistylesRootNode = std::reinterpret_pointer_cast<core::UnistylesCommitShadowNode>(newRootShadowNode);
20
-
21
- // this is Unistyles commit, we don't need to override it
22
- if (unistylesRootNode->hasUnistylesCommitTrait()) {
23
- unistylesRootNode->removeUnistylesCommitTrait();
24
- unistylesRootNode->addUnistylesMountTrait();
25
-
26
- return newRootShadowNode;
27
- }
28
-
29
- auto& registry = core::UnistylesRegistry::get();
30
-
31
- if (registry.trafficController.shouldStop()) {
32
- registry.trafficController.resumeUnistylesTraffic();
33
-
34
- return newRootShadowNode;
35
- }
36
-
37
- // this is React Native / Reanimated commit
38
- // merge Unistyles updates before it completes
39
-
40
- return registry.trafficController.withLock([&](){
41
- auto& shadowLeafUpdates = registry.trafficController.getUpdates();
42
-
43
- // oops, no updates from Unistyles yet, skip it!
44
- if (shadowLeafUpdates.size() == 0) {
45
- return newRootShadowNode;
46
- }
47
-
48
- auto affectedNodes = shadow::ShadowTreeManager::findAffectedNodes(*rootNode, shadowLeafUpdates);
49
-
50
- registry.trafficController.stopUnistylesTraffic();
51
-
52
- // we have few updates, so merge it
53
- return std::static_pointer_cast<RootShadowNode>(shadow::ShadowTreeManager::cloneShadowTree(
54
- *rootNode,
55
- shadowLeafUpdates,
56
- affectedNodes
57
- ));
58
- });
59
- }
@@ -1,27 +0,0 @@
1
- #pragma once
2
-
3
- #include <react/renderer/uimanager/UIManager.h>
4
- #include <react/renderer/uimanager/UIManagerCommitHook.h>
5
- #include "ShadowTreeManager.h"
6
- #include "ShadowTrafficController.h"
7
-
8
- namespace margelo::nitro::unistyles::core {
9
-
10
- using namespace facebook::react;
11
-
12
- struct UnistylesCommitHook : public UIManagerCommitHook {
13
- UnistylesCommitHook(std::shared_ptr<UIManager> uiManager) : _uiManager{uiManager} {
14
- _uiManager->registerCommitHook(*this);
15
- }
16
-
17
- ~UnistylesCommitHook() noexcept override;
18
-
19
- void commitHookWasRegistered(const UIManager &uiManager) noexcept override;
20
- void commitHookWasUnregistered(const UIManager &uiManager) noexcept override;
21
- RootShadowNode::Unshared shadowTreeWillCommit(const ShadowTree &shadowTree, const RootShadowNode::Shared &oldRootShadowNode, const RootShadowNode::Unshared &newRootShadowNode) noexcept override;
22
-
23
- private:
24
- std::shared_ptr<UIManager> _uiManager;
25
- };
26
-
27
- }