react-native-unistyles 3.0.0-alpha.2 → 3.0.0-alpha.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (316) hide show
  1. package/Unistyles.podspec +3 -2
  2. package/cxx/common/Constants.h +2 -0
  3. package/cxx/common/Helpers.h +97 -5
  4. package/cxx/core/HostStyle.cpp +19 -13
  5. package/cxx/core/HostStyle.h +4 -0
  6. package/cxx/core/StyleSheet.h +0 -2
  7. package/cxx/core/StyleSheetRegistry.cpp +10 -13
  8. package/cxx/core/StyleSheetRegistry.h +4 -4
  9. package/cxx/core/Unistyle.h +7 -10
  10. package/cxx/core/UnistyleData.h +23 -0
  11. package/cxx/core/UnistyleWrapper.h +78 -10
  12. package/cxx/core/UnistylesCommitHook.cpp +22 -13
  13. package/cxx/core/UnistylesCommitHook.h +8 -1
  14. package/cxx/core/UnistylesCommitShadowNode.h +13 -0
  15. package/cxx/core/UnistylesMountHook.cpp +37 -0
  16. package/cxx/core/UnistylesMountHook.h +31 -0
  17. package/cxx/core/UnistylesRegistry.cpp +56 -81
  18. package/cxx/core/UnistylesRegistry.h +15 -13
  19. package/cxx/core/UnistylesState.cpp +14 -8
  20. package/cxx/core/UnistylesState.h +1 -0
  21. package/cxx/hybridObjects/HybridShadowRegistry.cpp +15 -9
  22. package/cxx/hybridObjects/HybridStyleSheet.cpp +43 -38
  23. package/cxx/hybridObjects/HybridStyleSheet.h +10 -7
  24. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +35 -16
  25. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  26. package/cxx/parser/Parser.cpp +105 -164
  27. package/cxx/parser/Parser.h +8 -14
  28. package/cxx/shadowTree/ShadowLeafUpdate.h +1 -1
  29. package/cxx/shadowTree/ShadowTrafficController.h +33 -0
  30. package/cxx/shadowTree/ShadowTreeManager.cpp +13 -11
  31. package/cxx/shadowTree/ShadowTreeManager.h +1 -0
  32. package/ios/Unistyles.h +1 -0
  33. package/ios/UnistylesModuleOnLoad.h +2 -0
  34. package/ios/UnistylesModuleOnLoad.mm +8 -1
  35. package/lib/commonjs/index.js +4 -0
  36. package/lib/commonjs/index.js.map +1 -1
  37. package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
  38. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  39. package/lib/commonjs/specs/ShadowRegistry/index.js +7 -6
  40. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  41. package/lib/commonjs/specs/StatusBar/index.js +1 -1
  42. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  43. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  44. package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
  45. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  46. package/lib/commonjs/specs/index.web.js +1 -1
  47. package/lib/commonjs/web/convert/boxShadow.js +77 -0
  48. package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
  49. package/lib/commonjs/web/convert/breakpoint.js +25 -0
  50. package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
  51. package/lib/commonjs/web/convert/index.js +76 -0
  52. package/lib/commonjs/web/convert/index.js.map +1 -0
  53. package/lib/commonjs/web/convert/module.d.js +2 -0
  54. package/lib/commonjs/web/convert/module.d.js.map +1 -0
  55. package/lib/commonjs/web/convert/shadow.js +68 -0
  56. package/lib/commonjs/web/convert/shadow.js.map +1 -0
  57. package/lib/commonjs/web/convert/style.js +89 -0
  58. package/lib/commonjs/web/convert/style.js.map +1 -0
  59. package/lib/commonjs/web/convert/textShadow.js +73 -0
  60. package/lib/commonjs/web/convert/textShadow.js.map +1 -0
  61. package/lib/commonjs/web/convert/transform.js +72 -0
  62. package/lib/commonjs/web/convert/transform.js.map +1 -0
  63. package/lib/commonjs/web/convert/types.js +9 -0
  64. package/lib/commonjs/web/convert/types.js.map +1 -0
  65. package/lib/commonjs/web/convert/utils.js +55 -0
  66. package/lib/commonjs/web/convert/utils.js.map +1 -0
  67. package/lib/commonjs/web/create.js +51 -0
  68. package/lib/commonjs/web/create.js.map +1 -0
  69. package/lib/commonjs/web/createUnistylesComponent.js +61 -0
  70. package/lib/commonjs/web/createUnistylesComponent.js.map +1 -0
  71. package/lib/commonjs/web/index.js +60 -0
  72. package/lib/commonjs/web/index.js.map +1 -0
  73. package/lib/commonjs/web/listener/index.js +20 -0
  74. package/lib/commonjs/web/listener/index.js.map +1 -0
  75. package/lib/commonjs/web/listener/listenToDependencies.js +38 -0
  76. package/lib/commonjs/web/listener/listenToDependencies.js.map +1 -0
  77. package/lib/commonjs/web/listener/listener.js +35 -0
  78. package/lib/commonjs/web/listener/listener.js.map +1 -0
  79. package/lib/commonjs/web/mock.js +28 -0
  80. package/lib/commonjs/web/mock.js.map +1 -0
  81. package/lib/commonjs/web/mq.js +23 -0
  82. package/lib/commonjs/web/mq.js.map +1 -0
  83. package/lib/commonjs/web/pseudo.js +10 -0
  84. package/lib/commonjs/web/pseudo.js.map +1 -0
  85. package/lib/commonjs/web/registry.js +50 -0
  86. package/lib/commonjs/web/registry.js.map +1 -0
  87. package/lib/commonjs/web/runtime.js +163 -0
  88. package/lib/commonjs/web/runtime.js.map +1 -0
  89. package/lib/commonjs/web/shadowRegistry.js +123 -0
  90. package/lib/commonjs/web/shadowRegistry.js.map +1 -0
  91. package/lib/commonjs/web/state.js +81 -0
  92. package/lib/commonjs/web/state.js.map +1 -0
  93. package/lib/commonjs/web/utils.js +130 -0
  94. package/lib/commonjs/web/utils.js.map +1 -0
  95. package/lib/commonjs/web/variants/getVariants.js +39 -0
  96. package/lib/commonjs/web/variants/getVariants.js.map +1 -0
  97. package/lib/commonjs/web/variants/index.js +28 -0
  98. package/lib/commonjs/web/variants/index.js.map +1 -0
  99. package/lib/commonjs/web/variants/useVariants.js +59 -0
  100. package/lib/commonjs/web/variants/useVariants.js.map +1 -0
  101. package/lib/module/index.js +4 -0
  102. package/lib/module/index.js.map +1 -1
  103. package/lib/module/specs/NavigtionBar/index.js +1 -1
  104. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  105. package/lib/module/specs/ShadowRegistry/index.js +7 -6
  106. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  107. package/lib/module/specs/StatusBar/index.js +1 -1
  108. package/lib/module/specs/StatusBar/index.js.map +1 -1
  109. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  110. package/lib/module/specs/UnistylesRuntime/index.js +1 -1
  111. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  112. package/lib/module/specs/index.web.js +1 -1
  113. package/lib/module/specs/index.web.js.map +1 -1
  114. package/lib/module/web/convert/boxShadow.js +72 -0
  115. package/lib/module/web/convert/boxShadow.js.map +1 -0
  116. package/lib/module/web/convert/breakpoint.js +20 -0
  117. package/lib/module/web/convert/breakpoint.js.map +1 -0
  118. package/lib/module/web/convert/index.js +71 -0
  119. package/lib/module/web/convert/index.js.map +1 -0
  120. package/lib/module/web/convert/module.d.js +2 -0
  121. package/lib/module/web/convert/module.d.js.map +1 -0
  122. package/lib/module/web/convert/shadow.js +63 -0
  123. package/lib/module/web/convert/shadow.js.map +1 -0
  124. package/lib/module/web/convert/style.js +84 -0
  125. package/lib/module/web/convert/style.js.map +1 -0
  126. package/lib/module/web/convert/textShadow.js +68 -0
  127. package/lib/module/web/convert/textShadow.js.map +1 -0
  128. package/lib/module/web/convert/transform.js +67 -0
  129. package/lib/module/web/convert/transform.js.map +1 -0
  130. package/lib/module/web/convert/types.js +5 -0
  131. package/lib/module/web/convert/types.js.map +1 -0
  132. package/lib/module/web/convert/utils.js +43 -0
  133. package/lib/module/web/convert/utils.js.map +1 -0
  134. package/lib/module/web/create.js +46 -0
  135. package/lib/module/web/create.js.map +1 -0
  136. package/lib/module/web/createUnistylesComponent.js +54 -0
  137. package/lib/module/web/createUnistylesComponent.js.map +1 -0
  138. package/lib/module/web/index.js +26 -0
  139. package/lib/module/web/index.js.map +1 -0
  140. package/lib/module/web/listener/index.js +5 -0
  141. package/lib/module/web/listener/index.js.map +1 -0
  142. package/lib/module/web/listener/listenToDependencies.js +33 -0
  143. package/lib/module/web/listener/listenToDependencies.js.map +1 -0
  144. package/lib/module/web/listener/listener.js +31 -0
  145. package/lib/module/web/listener/listener.js.map +1 -0
  146. package/lib/module/web/mock.js +24 -0
  147. package/lib/module/web/mock.js.map +1 -0
  148. package/lib/module/web/mq.js +17 -0
  149. package/lib/module/web/mq.js.map +1 -0
  150. package/lib/module/web/pseudo.js +5 -0
  151. package/lib/module/web/pseudo.js.map +1 -0
  152. package/lib/module/web/registry.js +46 -0
  153. package/lib/module/web/registry.js.map +1 -0
  154. package/lib/module/web/runtime.js +159 -0
  155. package/lib/module/web/runtime.js.map +1 -0
  156. package/lib/module/web/shadowRegistry.js +119 -0
  157. package/lib/module/web/shadowRegistry.js.map +1 -0
  158. package/lib/module/web/state.js +77 -0
  159. package/lib/module/web/state.js.map +1 -0
  160. package/lib/module/web/utils.js +112 -0
  161. package/lib/module/web/utils.js.map +1 -0
  162. package/lib/module/web/variants/getVariants.js +34 -0
  163. package/lib/module/web/variants/getVariants.js.map +1 -0
  164. package/lib/module/web/variants/index.js +5 -0
  165. package/lib/module/web/variants/index.js.map +1 -0
  166. package/lib/module/web/variants/useVariants.js +54 -0
  167. package/lib/module/web/variants/useVariants.js.map +1 -0
  168. package/lib/typescript/example/App.d.ts.map +1 -1
  169. package/lib/typescript/example/Typography.d.ts +12 -0
  170. package/lib/typescript/example/Typography.d.ts.map +1 -0
  171. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
  172. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  173. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  174. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  175. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  176. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  177. package/lib/typescript/src/types/stylesheet.d.ts +2 -2
  178. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  179. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  180. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  181. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  182. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  183. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  184. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  185. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  186. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  187. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  188. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  189. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  190. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  191. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  192. package/lib/typescript/src/web/createUnistylesComponent.d.ts +3 -0
  193. package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +1 -0
  194. package/lib/typescript/{web → src/web}/index.d.ts +14 -13
  195. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  196. package/lib/typescript/src/web/listener/index.d.ts +3 -0
  197. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  198. package/lib/typescript/src/web/listener/listenToDependencies.d.ts +12 -0
  199. package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +1 -0
  200. package/lib/typescript/{web → src/web}/listener/listener.d.ts +3 -2
  201. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  202. package/lib/typescript/src/web/mock.d.ts +5 -0
  203. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  204. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  205. package/lib/typescript/src/web/pseudo.d.ts +6 -0
  206. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  207. package/lib/typescript/src/web/registry.d.ts +15 -0
  208. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  209. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -7
  210. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  211. package/lib/typescript/src/web/shadowRegistry.d.ts +17 -0
  212. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
  213. package/lib/typescript/{web → src/web}/state.d.ts +4 -9
  214. package/lib/typescript/src/web/state.d.ts.map +1 -0
  215. package/lib/typescript/src/web/utils.d.ts +35 -0
  216. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  217. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  218. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  219. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  220. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  221. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  222. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  223. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +6 -3
  224. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +8 -3
  225. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
  226. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
  227. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +14 -2
  228. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +3 -0
  229. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -0
  230. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +3 -0
  231. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
  232. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -0
  233. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  234. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +4 -1
  235. package/package.json +3 -3
  236. package/plugin/__tests__/dependencies.spec.js +199 -111
  237. package/plugin/__tests__/ref.spec.js +638 -202
  238. package/plugin/__tests__/stylesheet.spec.js +182 -71
  239. package/plugin/index.js +110 -23
  240. package/plugin/ref.js +64 -13
  241. package/plugin/style.js +82 -22
  242. package/plugin/stylesheet.js +44 -1
  243. package/plugin/variants.js +33 -0
  244. package/src/index.ts +3 -0
  245. package/src/specs/NavigtionBar/index.ts +1 -1
  246. package/src/specs/ShadowRegistry/index.ts +10 -9
  247. package/src/specs/StatusBar/index.ts +1 -1
  248. package/src/specs/StyleSheet/index.ts +3 -1
  249. package/src/specs/UnistylesRuntime/index.ts +1 -1
  250. package/src/specs/index.web.ts +1 -1
  251. package/src/types/stylesheet.ts +2 -2
  252. package/{web → src/web}/convert/breakpoint.ts +1 -1
  253. package/{web → src/web}/convert/index.ts +2 -2
  254. package/{web → src/web}/convert/types.ts +1 -1
  255. package/src/web/create.ts +50 -0
  256. package/src/web/createUnistylesComponent.tsx +54 -0
  257. package/{web → src/web}/index.ts +3 -2
  258. package/src/web/listener/index.ts +2 -0
  259. package/src/web/listener/listenToDependencies.ts +45 -0
  260. package/{web → src/web}/listener/listener.ts +2 -2
  261. package/{web → src/web}/mock.ts +2 -12
  262. package/src/web/pseudo.ts +137 -0
  263. package/src/web/registry.ts +60 -0
  264. package/{web → src/web}/runtime.ts +4 -6
  265. package/src/web/shadowRegistry.ts +124 -0
  266. package/{web → src/web}/state.ts +5 -49
  267. package/{web → src/web}/utils.ts +91 -17
  268. package/src/web/variants/getVariants.ts +42 -0
  269. package/src/web/variants/index.ts +2 -0
  270. package/src/web/variants/useVariants.ts +65 -0
  271. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  272. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  273. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  274. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  275. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  276. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  277. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  278. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  279. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  280. package/lib/typescript/web/listener/index.d.ts +0 -2
  281. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  282. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  283. package/lib/typescript/web/mock.d.ts +0 -14
  284. package/lib/typescript/web/mock.d.ts.map +0 -1
  285. package/lib/typescript/web/mq.d.ts.map +0 -1
  286. package/lib/typescript/web/pseudo.d.ts +0 -4
  287. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  288. package/lib/typescript/web/registry.d.ts +0 -12
  289. package/lib/typescript/web/registry.d.ts.map +0 -1
  290. package/lib/typescript/web/runtime.d.ts.map +0 -1
  291. package/lib/typescript/web/state.d.ts.map +0 -1
  292. package/lib/typescript/web/useVariants.d.ts +0 -3
  293. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  294. package/lib/typescript/web/utils.d.ts +0 -18
  295. package/lib/typescript/web/utils.d.ts.map +0 -1
  296. package/web/create.ts +0 -102
  297. package/web/listener/index.ts +0 -1
  298. package/web/pseudo.ts +0 -11
  299. package/web/registry.ts +0 -41
  300. package/web/useVariants.ts +0 -99
  301. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  302. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  303. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  304. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  305. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  306. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  307. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  308. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  309. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  310. /package/{web → src/web}/convert/module.d.ts +0 -0
  311. /package/{web → src/web}/convert/shadow.ts +0 -0
  312. /package/{web → src/web}/convert/style.ts +0 -0
  313. /package/{web → src/web}/convert/textShadow.ts +0 -0
  314. /package/{web → src/web}/convert/transform.ts +0 -0
  315. /package/{web → src/web}/convert/utils.ts +0 -0
  316. /package/{web → src/web}/mq.ts +0 -0
package/plugin/ref.js CHANGED
@@ -14,21 +14,39 @@ function hasStringRef(t, path) {
14
14
  )
15
15
  }
16
16
 
17
- function addRef(t, path, styleObj, styleProp) {
17
+ function memberExpressionFromArray(t, identifiers) {
18
+ // possible for inline styles
19
+ if (identifiers.length === 0) {
20
+ return undefined
21
+ }
22
+
23
+ const [base, ...members] = identifiers
24
+
25
+ return members.reduce((object, property) => t.memberExpression(object, t.identifier(property)), t.identifier(base))
26
+ }
27
+
28
+ function addRef(t, path, metadata, state) {
29
+ const hasVariants = state.file.hasVariants
30
+
18
31
  const newRefFunction = t.arrowFunctionExpression(
19
32
  [t.identifier('ref')],
20
33
  t.blockStatement([
21
34
  t.expressionStatement(
22
35
  t.callExpression(
23
36
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
24
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
37
+ [
38
+ t.identifier('ref'),
39
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
40
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
41
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
42
+ ]
25
43
  )
26
44
  ),
27
45
  t.returnStatement(
28
46
  t.arrowFunctionExpression([],
29
47
  t.callExpression(
30
48
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
31
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
49
+ [t.identifier('ref')]
32
50
  )
33
51
  )
34
52
  )
@@ -43,7 +61,8 @@ function addRef(t, path, styleObj, styleProp) {
43
61
  path.node.openingElement.attributes.push(newRefProp)
44
62
  }
45
63
 
46
- function overrideRef(t, path, refProp, styleObj, styleProp) {
64
+ function overrideRef(t, path, refProp, metadata, state) {
65
+ const hasVariants = state.file.hasVariants
47
66
  const uniqueRefName = path.scope.generateUidIdentifier('ref').name
48
67
  const isIdentifier = t.isIdentifier(refProp.value.expression)
49
68
  const binding = path.scope.getBinding(refProp.value.expression.name)
@@ -55,19 +74,30 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
55
74
  [t.identifier(uniqueRefName)],
56
75
  t.blockStatement([
57
76
  t.expressionStatement(
58
- t.assignmentExpression('=', t.identifier(userVariableName), t.identifier(uniqueRefName))
77
+ t.assignmentExpression(
78
+ '=',
79
+ t.memberExpression(t.identifier(userVariableName), t.identifier('current')),
80
+ t.identifier(uniqueRefName)
81
+ )
59
82
  ),
60
83
  t.expressionStatement(
61
84
  t.callExpression(
62
85
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
63
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
86
+ [
87
+ t.identifier(uniqueRefName),
88
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
89
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
90
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
91
+ ]
64
92
  )
65
93
  ),
66
94
  t.returnStatement(
67
95
  t.arrowFunctionExpression([],
68
96
  t.callExpression(
69
97
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
70
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
98
+ [
99
+ t.identifier(uniqueRefName)
100
+ ]
71
101
  )
72
102
  )
73
103
  )
@@ -87,15 +117,23 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
87
117
  const userCleanupFunction = userReturnStatement
88
118
  ? userReturnStatement.argument
89
119
  : null
120
+ const userRefName = refProp.value.expression.params.length >= 1
121
+ ? refProp.value.expression.params.at(0).name
122
+ : 'ref'
90
123
 
91
124
  const newRefFunction = t.arrowFunctionExpression(
92
- [t.identifier('ref')],
125
+ [t.identifier(userRefName)],
93
126
  t.blockStatement([
94
127
  ...userStatements.filter(statement => !t.isReturnStatement(statement)),
95
128
  t.expressionStatement(
96
129
  t.callExpression(
97
130
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
98
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
131
+ [
132
+ t.identifier(userRefName),
133
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
134
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
135
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
136
+ ]
99
137
  )
100
138
  ),
101
139
  // Merged cleanup function
@@ -109,7 +147,9 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
109
147
  t.expressionStatement(
110
148
  t.callExpression(
111
149
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
112
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
150
+ [
151
+ t.identifier(userRefName)
152
+ ]
113
153
  )
114
154
  )
115
155
  ]))
@@ -122,6 +162,10 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
122
162
  return
123
163
  }
124
164
 
165
+ if (!binding) {
166
+ return
167
+ }
168
+
125
169
  // ref={scopedFunction}
126
170
  const isArrowFunction = t.isArrowFunctionExpression(binding.path.node.init)
127
171
  const isFunction = t.isFunctionDeclaration(binding.path.node)
@@ -146,7 +190,12 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
146
190
  t.expressionStatement(
147
191
  t.callExpression(
148
192
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
149
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
193
+ [
194
+ t.identifier(uniqueRefName),
195
+ memberExpressionFromArray(t, metadata.members) || metadata.inlineStyle,
196
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
197
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
198
+ ]
150
199
  )
151
200
  ),
152
201
  t.returnStatement(
@@ -159,10 +208,12 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
159
208
  t.expressionStatement(
160
209
  t.callExpression(
161
210
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
162
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
211
+ [
212
+ t.identifier(uniqueRefName)
213
+ ]
163
214
  )
164
215
  )
165
- ]))
216
+ ].filter(Boolean)))
166
217
  )
167
218
  ])
168
219
  )
package/plugin/style.js CHANGED
@@ -1,44 +1,69 @@
1
- function getStyleObjectPath(t, node, state) {
1
+ function getStyleMetadata(t, node, dynamicFunction = null) {
2
2
  // {styles.container}
3
3
  if (t.isMemberExpression(node)) {
4
- return [node.object.name, node.property.name]
4
+ const members = t.isMemberExpression(node.object)
5
+ ? [node.object.object.name, node.object.property.name, node.property.name]
6
+ : [node.object.name, node.property.name]
7
+
8
+ return [
9
+ {
10
+ members: members.filter(Boolean),
11
+ inlineStyle: undefined,
12
+ dynamicFunction
13
+ }
14
+ ]
5
15
  }
6
16
 
7
17
  // [styles.container]
8
18
  if (t.isArrayExpression(node)) {
9
- return node.elements.flatMap(element => getStyleObjectPath(t, element, state))
19
+ return node.elements.flatMap(element => getStyleMetadata(t, element))
10
20
  }
11
21
 
12
22
  // [...styles.container]
13
23
  if (t.isSpreadElement(node)) {
14
- return getStyleObjectPath(t, node.argument, state)
24
+ return getStyleMetadata(t, node.argument)
15
25
  }
16
26
 
17
27
  // {{ ...styles.container }}
18
28
  if (t.isObjectExpression(node)) {
19
- return node.properties.flatMap(prop => getStyleObjectPath(t, prop.argument, state))
20
- }
29
+ const inlineStyles = []
21
30
 
22
- // {styles.container(arg1, arg2)}
23
- if (t.isCallExpression(node)) {
24
- const path = getStyleObjectPath(t, node.callee, state)
25
- const lastPart = path.slice(-1)
31
+ const partialResult = node
32
+ .properties
33
+ .flatMap(prop => {
34
+ // handle inline styles
35
+ if (t.isObjectProperty(prop)) {
36
+ inlineStyles.push(prop)
26
37
 
27
- if (!lastPart) {
28
- return path
29
- }
38
+ return null
39
+ }
30
40
 
31
- // for web increment counter for dynamic functions
32
- if (state.file.webDynamicFunctions[lastPart]) {
33
- node.arguments.push(t.numericLiteral(++state.file.webDynamicFunctions[lastPart]))
41
+ return getStyleMetadata(t, prop.argument)
42
+ })
43
+ .filter(Boolean)
34
44
 
35
- return path
45
+ if (inlineStyles.length > 0) {
46
+ return partialResult.concat([{
47
+ members: [],
48
+ inlineStyle: t.objectExpression(inlineStyles),
49
+ dynamicFunction: undefined
50
+ }])
36
51
  }
37
52
 
38
- state.file.webDynamicFunctions[lastPart] = 1
39
- node.arguments.push(t.numericLiteral(1))
53
+ return partialResult
54
+ }
40
55
 
41
- return path
56
+ // {styles.container(arg1, arg2)}
57
+ if (t.isCallExpression(node)) {
58
+ return getStyleMetadata(t, node.callee, node)
59
+ }
60
+
61
+ if (t.isIdentifier(node)) {
62
+ return [{
63
+ members: [node.name],
64
+ inlineStyle: undefined,
65
+ dynamicFunction: undefined
66
+ }]
42
67
  }
43
68
 
44
69
  return []
@@ -52,7 +77,42 @@ function getStyleAttribute(t, path) {
52
77
  )
53
78
  }
54
79
 
80
+ function styleAttributeToArray(t, path) {
81
+ const styleAttribute = getStyleAttribute(t, path)
82
+
83
+ // {{...style.container, ...style.container}}
84
+ if (t.isObjectExpression(styleAttribute.value.expression)) {
85
+ const properties = styleAttribute.value.expression.properties
86
+ .map(property => t.isSpreadElement(property)
87
+ ? property.argument
88
+ : t.objectExpression([property])
89
+ )
90
+
91
+ styleAttribute.value.expression = t.arrayExpression(properties)
92
+
93
+ return
94
+ }
95
+
96
+ // [{...style.container, ...style.container}]
97
+ if (t.isArrayExpression(styleAttribute.value.expression)) {
98
+ const properties = styleAttribute.value.expression.elements
99
+ .flatMap(property => {
100
+ if (t.isSpreadElement(property)) {
101
+ return property.argument
102
+ }
103
+ return property
104
+ })
105
+
106
+ styleAttribute.value.expression = t.arrayExpression(properties)
107
+
108
+ return
109
+ }
110
+
111
+ styleAttribute.value.expression = t.arrayExpression([styleAttribute.value.expression])
112
+ }
113
+
55
114
  module.exports = {
56
- getStyleObjectPath,
57
- getStyleAttribute
115
+ getStyleMetadata,
116
+ getStyleAttribute,
117
+ styleAttributeToArray
58
118
  }
@@ -17,6 +17,19 @@ const UnistyleDependency = {
17
17
  NavigationBar: 13
18
18
  }
19
19
 
20
+ function stringToUniqueId(str) {
21
+ let hash = 0;
22
+
23
+ for (let i = 0; i < str.length; i++) {
24
+ hash = (hash << 5) - hash + str.charCodeAt(i)
25
+ hash |= 0
26
+ }
27
+
28
+ const absHash = Math.abs(hash)
29
+
30
+ return absHash % 1000000000
31
+ }
32
+
20
33
  function isUnistylesStyleSheet(t, path, state) {
21
34
  const callee = path.get('callee')
22
35
 
@@ -28,6 +41,13 @@ function isUnistylesStyleSheet(t, path, state) {
28
41
  )
29
42
  }
30
43
 
44
+ function addStyleSheetTag(t, path, state) {
45
+ const callee = path.get('callee')
46
+ const uniqueId = stringToUniqueId(state.filename) + ++state.file.tagNumber
47
+
48
+ callee.container.arguments.push(t.numericLiteral(uniqueId))
49
+ }
50
+
31
51
  function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
32
52
  const debugMessage = deps => {
33
53
  if (state.opts.debug) {
@@ -141,7 +161,30 @@ function analyzeDependencies(t, state, name, unistyleObj, themeName, rtName) {
141
161
  }
142
162
  }
143
163
 
164
+ function getUnistyle(t, property) {
165
+ const propertyValue = t.isArrowFunctionExpression(property.value)
166
+ ? property.value.body
167
+ : property.value
168
+
169
+ if (t.isObjectExpression(propertyValue)) {
170
+ return propertyValue
171
+ }
172
+
173
+ if (t.isBlockStatement(propertyValue)) {
174
+ const returnStatement = propertyValue.body
175
+ .find(value => t.isReturnStatement(value))
176
+
177
+ return returnStatement
178
+ ? returnStatement.argument
179
+ : null
180
+ }
181
+
182
+ return null
183
+ }
184
+
144
185
  module.exports = {
145
186
  isUnistylesStyleSheet,
146
- analyzeDependencies
187
+ analyzeDependencies,
188
+ addStyleSheetTag,
189
+ getUnistyle
147
190
  }
@@ -0,0 +1,33 @@
1
+ function isUsingVariants(t, path) {
2
+ const callee = path.get('callee')
3
+
4
+ return (
5
+ t.isMemberExpression(callee) &&
6
+ t.isIdentifier(callee.node.object, { name: 'styles' }) &&
7
+ t.isIdentifier(callee.node.property, { name: 'useVariants' }) &&
8
+ t.isObjectExpression(path.node.arguments[0])
9
+ )
10
+ }
11
+
12
+ function extractVariants(t, path, state) {
13
+ const arg = path.node.arguments[0]
14
+
15
+ const variantDeclaration = t.variableDeclaration('const', [
16
+ t.variableDeclarator(
17
+ t.identifier('__uni__variants'),
18
+ arg
19
+ )
20
+ ])
21
+
22
+ // Replace useVariants argument with __uni__variants
23
+ path.node.arguments[0] = t.identifier('__uni__variants')
24
+
25
+ path.insertBefore(variantDeclaration)
26
+
27
+ state.file.hasVariants = true
28
+ }
29
+
30
+ module.exports = {
31
+ isUsingVariants,
32
+ extractVariants
33
+ }
package/src/index.ts CHANGED
@@ -3,6 +3,9 @@ import React from 'react'
3
3
  export * from './specs'
4
4
  export { mq } from './mq'
5
5
  export type { UnistylesThemes, UnistylesBreakpoints } from './global'
6
+ // TODO: export Native createUnistylesComponent
7
+ // can't import it this way, it will break native build
8
+ // export { createUnistylesComponent } from './web/createUnistylesComponent'
6
9
 
7
10
  // todo verify true min version
8
11
  const minReactVersionRequiredByUnistyles = '18.3.1'
@@ -12,7 +12,7 @@ export const attachNavigationBarJSMethods = (hybridObject: UnistylesNavigationBa
12
12
 
13
13
  privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
14
14
  hybridObject.setBackgroundColor = (color?: string) => {
15
- const parsedColor = processColor(color)
15
+ const parsedColor = processColor(color) ?? 0
16
16
 
17
17
  privateHybrid._setBackgroundColor(parsedColor as number)
18
18
  }
@@ -4,11 +4,11 @@ import type { ShadowNode, Unistyle, ViewHandle } from './types'
4
4
 
5
5
  interface ShadowRegistry extends UnistylesShadowRegistrySpec {
6
6
  // Babel API
7
- add(handle?: ViewHandle, style?: Unistyle): void,
7
+ add(handle?: ViewHandle, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
8
8
  remove(handle?: ViewHandle, style?: Unistyle): void,
9
9
  // JSI
10
- link(node: ShadowNode, style: Unistyle): void,
11
- unlink(node: ShadowNode, style: Unistyle): void
10
+ link(node: ShadowNode, style?: Unistyle, variants?: Record<string, string | boolean>, args?: Array<any>): void,
11
+ unlink(node: ShadowNode): void
12
12
  }
13
13
 
14
14
  const HybridShadowRegistry = NitroModules.createHybridObject<ShadowRegistry>('UnistylesShadowRegistry')
@@ -26,20 +26,21 @@ const findShadowNodeForHandle = (handle: ViewHandle) => {
26
26
  return node
27
27
  }
28
28
 
29
- HybridShadowRegistry.add = (handle, style) => {
30
- if (!handle || !style?.__unid) {
29
+ HybridShadowRegistry.add = (handle, style, variants, args) => {
30
+ // virtualized nodes can be null
31
+ if (!handle || !style) {
31
32
  return
32
33
  }
33
34
 
34
- HybridShadowRegistry.link(findShadowNodeForHandle(handle), style)
35
+ HybridShadowRegistry.link(findShadowNodeForHandle(handle), style, variants ?? {}, args ?? [])
35
36
  }
36
37
 
37
- HybridShadowRegistry.remove = (handle, style) => {
38
- if (!handle || !style?.__unid) {
38
+ HybridShadowRegistry.remove = handle => {
39
+ if (!handle) {
39
40
  return
40
41
  }
41
42
 
42
- HybridShadowRegistry.unlink(findShadowNodeForHandle(handle), style)
43
+ HybridShadowRegistry.unlink(findShadowNodeForHandle(handle))
43
44
  }
44
45
 
45
46
  type PrivateMethods =
@@ -34,7 +34,7 @@ export const attachStatusBarJSMethods = (hybridObject: UnistylesStatusBar) => {
34
34
 
35
35
  privateHybrid._setBackgroundColor = hybridObject.setBackgroundColor
36
36
  hybridObject.setBackgroundColor = (color?: string) => {
37
- const parsedColor = processColor(color)
37
+ const parsedColor = processColor(color) ?? 0
38
38
 
39
39
  privateHybrid._setBackgroundColor(parsedColor as number)
40
40
  }
@@ -41,4 +41,6 @@ HybridUnistylesStyleSheet.jsMethods = {
41
41
  processColor
42
42
  }
43
43
 
44
- export const StyleSheet = HybridUnistylesStyleSheet as Omit<UnistylesStyleSheet, 'jsMethods'>
44
+ type PrivateMethods = 'jsMethods'
45
+
46
+ export const StyleSheet = HybridUnistylesStyleSheet as Omit<UnistylesStyleSheet, PrivateMethods>
@@ -45,7 +45,7 @@ HybridUnistylesRuntime.navigationBar = HybridUnistylesRuntime.createHybridNaviga
45
45
  HybridUnistylesRuntime._setRootViewBackgroundColor = HybridUnistylesRuntime.setRootViewBackgroundColor
46
46
 
47
47
  HybridUnistylesRuntime.setRootViewBackgroundColor = (color?: string) => {
48
- const parsedColor = processColor(color)
48
+ const parsedColor = processColor(color) ?? 0
49
49
 
50
50
  HybridUnistylesRuntime._setRootViewBackgroundColor(parsedColor as number)
51
51
  }
@@ -2,4 +2,4 @@ import type { ReactElement } from 'react'
2
2
 
3
3
  export const getSSRUnistyles = () => [] as Array<ReactElement>
4
4
 
5
- export * from '../../web'
5
+ export * from '../web'
@@ -5,7 +5,7 @@ import type { UnistylesMiniRuntime } from '../specs'
5
5
  import type { ReactNativeStyleSheet } from './breakpoints'
6
6
  import type { ExtractVariantNames } from './variants'
7
7
  import type { CSSProperties } from 'react'
8
- import type { Pseudo } from '../../web/pseudo'
8
+ import type { Pseudo } from '../web/pseudo'
9
9
 
10
10
  // these props are treated differently to nest breakpoints and media queries
11
11
  type NestedKeys = 'shadowOffset' | 'transform' | 'textShadowOffset'
@@ -27,7 +27,7 @@ type VariantsObject = {
27
27
  }
28
28
 
29
29
  type CustomClassName = {
30
- _css?: string | Array<string>
30
+ _classNames?: string | Array<string>
31
31
  }
32
32
 
33
33
  type CompoundVariant = {
@@ -2,7 +2,7 @@ import type { MediaQuery } from 'typestyle/lib/types'
2
2
  import { UnistylesState } from '../state'
3
3
  import { keyInObject } from '../utils'
4
4
  import { isUnistylesMq, parseMq } from '../mq'
5
- import { Orientation } from '../../src/specs/types'
5
+ import { Orientation } from '../../specs/types'
6
6
 
7
7
  export const convertBreakpoint = (breakpoint: string): MediaQuery => {
8
8
  if (Object.values(Orientation).includes(breakpoint as Orientation)) {
@@ -1,5 +1,5 @@
1
1
  import type { NestedCSSProperties } from 'typestyle/lib/types'
2
- import type { UnistylesValues } from '../../src/types'
2
+ import type { UnistylesValues } from '../../types'
3
3
  import { media } from 'typestyle'
4
4
  import { isPseudo } from '../pseudo'
5
5
  import { convertBreakpoint } from './breakpoint'
@@ -21,7 +21,7 @@ export const convertToTypeStyle = (value: UnistylesValues) => {
21
21
  ...value._web
22
22
  }).flatMap(([unistylesKey, unistylesValue]) => {
23
23
  // Keys to omit
24
- if (['_css', '_web', 'variants', 'compoundVariants', 'uni__dependencies'].includes(unistylesKey)) {
24
+ if (['_classNames', '_web', 'variants', 'compoundVariants', 'uni__dependencies', '__unistyles-secrets__'].includes(unistylesKey) || unistylesKey.startsWith('variant-')) {
25
25
  return []
26
26
  }
27
27
 
@@ -1,5 +1,5 @@
1
1
  import type { TextStyle, ViewStyle } from 'react-native'
2
- import type { ToDeepUnistyles } from '../../src/types/stylesheet'
2
+ import type { ToDeepUnistyles } from '../../types/stylesheet'
3
3
 
4
4
  export type ShadowOffset = ToDeepUnistyles<{ width: number, height: number }>
5
5
 
@@ -0,0 +1,50 @@
1
+ import type { ReactNativeStyleSheet } from '../types'
2
+ import type { StyleSheetWithSuperPowers, StyleSheet } from '../types/stylesheet'
3
+ import { assignSecrets, reduceObject, getStyles } from './utils'
4
+ import { UnistylesRuntime } from './runtime'
5
+ import { createUseVariants, getVariants } from './variants'
6
+
7
+ export const create = (stylesheet: StyleSheetWithSuperPowers<StyleSheet>) => {
8
+ const computedStylesheet = typeof stylesheet === 'function'
9
+ ? stylesheet(UnistylesRuntime.theme, UnistylesRuntime.miniRuntime)
10
+ : stylesheet
11
+ const selectedVariants = new Map<string, any>()
12
+
13
+ const copyVariants = () => Object.fromEntries(selectedVariants.entries())
14
+ const addSecrets = (value: any, key: string, args?: Array<any>) => assignSecrets(value, {
15
+ __uni__key: key,
16
+ __uni__refs: new Set(),
17
+ __uni__stylesheet: stylesheet,
18
+ __uni__args: args,
19
+ __uni__variants: copyVariants()
20
+ })
21
+
22
+ const styles = reduceObject(computedStylesheet, (value, _key) => {
23
+ const key = String(_key)
24
+
25
+ if (typeof value === 'function') {
26
+ const dynamicStyle = (...args: Array<any>) => {
27
+ const result = value(...args)
28
+ const variants = Object.fromEntries(getVariants({ [key]: result } as ReactNativeStyleSheet<StyleSheet>, copyVariants()))
29
+ const resultWithVariants = {
30
+ ...result,
31
+ ...variants[key]
32
+ }
33
+
34
+ // Add secrets to result of dynamic styles function
35
+ return addSecrets(getStyles(resultWithVariants), key, args)
36
+ }
37
+
38
+ // Add secrets to dynamic styles function
39
+ return addSecrets(dynamicStyle, key)
40
+ }
41
+
42
+ // Add secrets to static styles
43
+ return addSecrets(getStyles(value), key)
44
+ }) as ReactNativeStyleSheet<StyleSheet>
45
+
46
+ // Inject useVariants hook to styles
47
+ createUseVariants(styles, newVariants => Object.entries(newVariants).forEach(([key, value]) => selectedVariants.set(key, value)))
48
+
49
+ return styles
50
+ }
@@ -0,0 +1,54 @@
1
+ import React, { useEffect, useState } from 'react'
2
+ import { extractHiddenProperties, extractSecrets } from './utils'
3
+ import { getVariants } from './variants'
4
+ import { UnistylesListener } from './listener'
5
+ import { UnistylesRegistry } from './registry'
6
+
7
+ const getStyles = (value: Record<string, any>) => {
8
+ const secrets = extractSecrets(value)
9
+
10
+ if (secrets.length === 0) {
11
+ return undefined
12
+ }
13
+
14
+ return secrets.reduce((acc, { __uni__stylesheet, __uni__key, __uni__args = [], __uni__variants }) => {
15
+ const newComputedStylesheet = UnistylesRegistry.getComputedStylesheet(__uni__stylesheet)
16
+ const style = newComputedStylesheet[__uni__key]
17
+ const resultHidden = typeof style === 'function'
18
+ ? style(...__uni__args)
19
+ : style
20
+ const result = extractHiddenProperties(resultHidden)
21
+ const { variants } = Object.fromEntries(getVariants({ variants: result }, __uni__variants ))
22
+ const resultWithVariants = {
23
+ ...result,
24
+ ...variants
25
+ }
26
+
27
+ return {
28
+ ...acc,
29
+ ...resultWithVariants
30
+ }
31
+ }, {} as Record<string, any>)
32
+ }
33
+
34
+ export const createUnistylesComponent = <TProps extends object>(Component: React.ComponentType<TProps>) => (props: TProps) => {
35
+ const passedStyles = (props as TProps & { style: Record<string, any> }).style ?? {}
36
+ const [style, setStyle] = useState(getStyles(passedStyles))
37
+
38
+ useEffect(() => {
39
+ const newStyles = getStyles(passedStyles)
40
+ const dependencies = newStyles?.['uni__dependencies'] ?? []
41
+ const dispose = UnistylesListener.addListeners(dependencies, () => setStyle(getStyles(passedStyles)))
42
+
43
+ setStyle(newStyles)
44
+
45
+ return dispose
46
+ }, [passedStyles])
47
+
48
+ return (
49
+ <Component
50
+ {...props}
51
+ style={style}
52
+ />
53
+ )
54
+ }