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

Sign up to get free protection for your applications and to get access to all the features.
Files changed (328) hide show
  1. package/Unistyles.podspec +3 -2
  2. package/cxx/common/Constants.h +3 -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 +58 -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/expo-example/app/(tabs)/_layout.d.ts +3 -0
  172. package/lib/typescript/expo-example/app/(tabs)/_layout.d.ts.map +1 -0
  173. package/lib/typescript/expo-example/app/(tabs)/explore.d.ts +3 -0
  174. package/lib/typescript/expo-example/app/(tabs)/explore.d.ts.map +1 -0
  175. package/lib/typescript/expo-example/app/(tabs)/index.d.ts +3 -0
  176. package/lib/typescript/expo-example/app/(tabs)/index.d.ts.map +1 -0
  177. package/lib/typescript/expo-example/app/+html.d.ts +4 -0
  178. package/lib/typescript/expo-example/app/+html.d.ts.map +1 -0
  179. package/lib/typescript/expo-example/app/+not-found.d.ts +3 -0
  180. package/lib/typescript/expo-example/app/+not-found.d.ts.map +1 -0
  181. package/lib/typescript/expo-example/app/_layout.d.ts +3 -0
  182. package/lib/typescript/expo-example/app/_layout.d.ts.map +1 -0
  183. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +3 -3
  184. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  185. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  186. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  187. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  188. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  189. package/lib/typescript/src/types/stylesheet.d.ts +2 -2
  190. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  191. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  192. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  193. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  194. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  195. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  196. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  197. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  198. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  199. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  200. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  201. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  202. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  203. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  204. package/lib/typescript/src/web/createUnistylesComponent.d.ts +3 -0
  205. package/lib/typescript/src/web/createUnistylesComponent.d.ts.map +1 -0
  206. package/lib/typescript/{web → src/web}/index.d.ts +14 -13
  207. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  208. package/lib/typescript/src/web/listener/index.d.ts +3 -0
  209. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  210. package/lib/typescript/src/web/listener/listenToDependencies.d.ts +12 -0
  211. package/lib/typescript/src/web/listener/listenToDependencies.d.ts.map +1 -0
  212. package/lib/typescript/{web → src/web}/listener/listener.d.ts +3 -2
  213. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  214. package/lib/typescript/src/web/mock.d.ts +5 -0
  215. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  216. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  217. package/lib/typescript/src/web/pseudo.d.ts +6 -0
  218. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  219. package/lib/typescript/src/web/registry.d.ts +15 -0
  220. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  221. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -7
  222. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  223. package/lib/typescript/src/web/shadowRegistry.d.ts +17 -0
  224. package/lib/typescript/src/web/shadowRegistry.d.ts.map +1 -0
  225. package/lib/typescript/{web → src/web}/state.d.ts +4 -9
  226. package/lib/typescript/src/web/state.d.ts.map +1 -0
  227. package/lib/typescript/src/web/utils.d.ts +35 -0
  228. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  229. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  230. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  231. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  232. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  233. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  234. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  235. package/nitrogen/generated/android/c++/JHybridNativePlatformSpec.hpp +6 -3
  236. package/nitrogen/generated/android/kotlin/com/margelo/nitro/unistyles/HybridNativePlatformSpec.kt +8 -3
  237. package/nitrogen/generated/ios/c++/HybridNativePlatformSpecSwift.hpp +1 -1
  238. package/nitrogen/generated/ios/swift/HybridNativePlatformSpec.swift +1 -1
  239. package/nitrogen/generated/ios/swift/HybridNativePlatformSpecCxx.swift +14 -2
  240. package/nitrogen/generated/shared/c++/HybridNativePlatformSpec.hpp +3 -0
  241. package/nitrogen/generated/shared/c++/HybridUnistylesNavigationBarSpec.hpp +3 -0
  242. package/nitrogen/generated/shared/c++/HybridUnistylesRuntimeSpec.hpp +3 -0
  243. package/nitrogen/generated/shared/c++/HybridUnistylesShadowRegistrySpec.hpp +3 -0
  244. package/nitrogen/generated/shared/c++/HybridUnistylesStatusBarSpec.hpp +3 -0
  245. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.cpp +1 -1
  246. package/nitrogen/generated/shared/c++/HybridUnistylesStyleSheetSpec.hpp +4 -1
  247. package/package.json +3 -3
  248. package/plugin/__tests__/dependencies.spec.js +199 -111
  249. package/plugin/__tests__/ref.spec.js +638 -202
  250. package/plugin/__tests__/stylesheet.spec.js +182 -71
  251. package/plugin/index.js +110 -23
  252. package/plugin/ref.js +64 -13
  253. package/plugin/style.js +82 -22
  254. package/plugin/stylesheet.js +44 -1
  255. package/plugin/variants.js +33 -0
  256. package/src/index.ts +3 -0
  257. package/src/specs/NavigtionBar/index.ts +1 -1
  258. package/src/specs/ShadowRegistry/index.ts +10 -9
  259. package/src/specs/StatusBar/index.ts +1 -1
  260. package/src/specs/StyleSheet/index.ts +3 -1
  261. package/src/specs/UnistylesRuntime/index.ts +1 -1
  262. package/src/specs/index.web.ts +1 -1
  263. package/src/types/stylesheet.ts +2 -2
  264. package/{web → src/web}/convert/breakpoint.ts +1 -1
  265. package/{web → src/web}/convert/index.ts +2 -2
  266. package/{web → src/web}/convert/types.ts +1 -1
  267. package/src/web/create.ts +50 -0
  268. package/src/web/createUnistylesComponent.tsx +54 -0
  269. package/{web → src/web}/index.ts +3 -2
  270. package/src/web/listener/index.ts +2 -0
  271. package/src/web/listener/listenToDependencies.ts +45 -0
  272. package/{web → src/web}/listener/listener.ts +2 -2
  273. package/{web → src/web}/mock.ts +2 -12
  274. package/src/web/pseudo.ts +137 -0
  275. package/src/web/registry.ts +60 -0
  276. package/{web → src/web}/runtime.ts +4 -6
  277. package/src/web/shadowRegistry.ts +124 -0
  278. package/{web → src/web}/state.ts +5 -49
  279. package/{web → src/web}/utils.ts +91 -17
  280. package/src/web/variants/getVariants.ts +42 -0
  281. package/src/web/variants/index.ts +2 -0
  282. package/src/web/variants/useVariants.ts +65 -0
  283. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  284. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  285. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  286. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  287. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  288. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  289. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  290. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  291. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  292. package/lib/typescript/web/listener/index.d.ts +0 -2
  293. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  294. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  295. package/lib/typescript/web/mock.d.ts +0 -14
  296. package/lib/typescript/web/mock.d.ts.map +0 -1
  297. package/lib/typescript/web/mq.d.ts.map +0 -1
  298. package/lib/typescript/web/pseudo.d.ts +0 -4
  299. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  300. package/lib/typescript/web/registry.d.ts +0 -12
  301. package/lib/typescript/web/registry.d.ts.map +0 -1
  302. package/lib/typescript/web/runtime.d.ts.map +0 -1
  303. package/lib/typescript/web/state.d.ts.map +0 -1
  304. package/lib/typescript/web/useVariants.d.ts +0 -3
  305. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  306. package/lib/typescript/web/utils.d.ts +0 -18
  307. package/lib/typescript/web/utils.d.ts.map +0 -1
  308. package/web/create.ts +0 -102
  309. package/web/listener/index.ts +0 -1
  310. package/web/pseudo.ts +0 -11
  311. package/web/registry.ts +0 -41
  312. package/web/useVariants.ts +0 -99
  313. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  314. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  315. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  316. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  317. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  318. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  319. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  320. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  321. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  322. /package/{web → src/web}/convert/module.d.ts +0 -0
  323. /package/{web → src/web}/convert/shadow.ts +0 -0
  324. /package/{web → src/web}/convert/style.ts +0 -0
  325. /package/{web → src/web}/convert/textShadow.ts +0 -0
  326. /package/{web → src/web}/convert/transform.ts +0 -0
  327. /package/{web → src/web}/convert/utils.ts +0 -0
  328. /package/{web → src/web}/mq.ts +0 -0
@@ -16,6 +16,7 @@ pluginTester({
16
16
  {
17
17
  title: 'Should not add dependencies to StyleSheet if user is not using theme or miniRuntime',
18
18
  code: `
19
+ import { View, Text } from 'react-native'
19
20
  import { StyleSheet } from 'react-native-unistyles'
20
21
 
21
22
  export const Example = () => {
@@ -34,15 +35,16 @@ pluginTester({
34
35
  `,
35
36
  output: `
36
37
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
38
+ import { View, Text } from 'react-native'
37
39
  import { StyleSheet } from 'react-native-unistyles'
38
40
 
39
41
  export const Example = () => {
40
42
  return (
41
43
  <View
42
- style={styles.container}
44
+ style={[styles.container]}
43
45
  ref={ref => {
44
- UnistylesShadowRegistry.add(ref, styles.container)
45
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
46
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
47
+ return () => UnistylesShadowRegistry.remove(ref)
46
48
  }}
47
49
  >
48
50
  <Text>Hello world</Text>
@@ -50,16 +52,20 @@ pluginTester({
50
52
  )
51
53
  }
52
54
 
53
- const styles = StyleSheet.create({
54
- container: {
55
- backgroundColor: 'red'
56
- }
57
- })
55
+ const styles = StyleSheet.create(
56
+ {
57
+ container: {
58
+ backgroundColor: 'red'
59
+ }
60
+ },
61
+ 793953373
62
+ )
58
63
  `
59
64
  },
60
65
  {
61
66
  title: 'Should add dependencies to StyleSheet if user is using theme',
62
67
  code: `
68
+ import { View, Text } from 'react-native'
63
69
  import { StyleSheet } from 'react-native-unistyles'
64
70
 
65
71
  export const Example = () => {
@@ -78,15 +84,16 @@ pluginTester({
78
84
  `,
79
85
  output: `
80
86
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
87
+ import { View, Text } from 'react-native'
81
88
  import { StyleSheet } from 'react-native-unistyles'
82
89
 
83
90
  export const Example = () => {
84
91
  return (
85
92
  <View
86
- style={styles.container}
93
+ style={[styles.container]}
87
94
  ref={ref => {
88
- UnistylesShadowRegistry.add(ref, styles.container)
89
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
95
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
96
+ return () => UnistylesShadowRegistry.remove(ref)
90
97
  }}
91
98
  >
92
99
  <Text>Hello world</Text>
@@ -94,17 +101,21 @@ pluginTester({
94
101
  )
95
102
  }
96
103
 
97
- const styles = StyleSheet.create(theme => ({
98
- container: {
99
- backgroundColor: theme.colors.background,
100
- uni__dependencies: [0]
101
- }
102
- }))
104
+ const styles = StyleSheet.create(
105
+ theme => ({
106
+ container: {
107
+ backgroundColor: theme.colors.background,
108
+ uni__dependencies: [0]
109
+ }
110
+ }),
111
+ 793953373
112
+ )
103
113
  `
104
114
  },
105
115
  {
106
116
  title: 'Should add dependencies to StyleSheet even if user did rename import',
107
117
  code: `
118
+ import { View, Text } from 'react-native'
108
119
  import { StyleSheet as ST } from 'react-native-unistyles'
109
120
 
110
121
  export const Example = () => {
@@ -123,15 +134,16 @@ pluginTester({
123
134
  `,
124
135
  output: `
125
136
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
137
+ import { View, Text } from 'react-native'
126
138
  import { StyleSheet as ST } from 'react-native-unistyles'
127
139
 
128
140
  export const Example = () => {
129
141
  return (
130
142
  <View
131
- style={styles.container}
143
+ style={[styles.container]}
132
144
  ref={ref => {
133
- UnistylesShadowRegistry.add(ref, styles.container)
134
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
145
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
146
+ return () => UnistylesShadowRegistry.remove(ref)
135
147
  }}
136
148
  >
137
149
  <Text>Hello world</Text>
@@ -139,17 +151,21 @@ pluginTester({
139
151
  )
140
152
  }
141
153
 
142
- const styles = ST.create(theme => ({
143
- container: {
144
- backgroundColor: theme.colors.background,
145
- uni__dependencies: [0]
146
- }
147
- }))
154
+ const styles = ST.create(
155
+ theme => ({
156
+ container: {
157
+ backgroundColor: theme.colors.background,
158
+ uni__dependencies: [0]
159
+ }
160
+ }),
161
+ 793953373
162
+ )
148
163
  `
149
164
  },
150
165
  {
151
166
  title: 'Should detect variants for object StyleSheet',
152
167
  code: `
168
+ import { View, Text } from 'react-native'
153
169
  import { StyleSheet } from 'react-native-unistyles'
154
170
 
155
171
  export const Example = () => {
@@ -169,15 +185,16 @@ pluginTester({
169
185
  `,
170
186
  output: `
171
187
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
188
+ import { View, Text } from 'react-native'
172
189
  import { StyleSheet } from 'react-native-unistyles'
173
190
 
174
191
  export const Example = () => {
175
192
  return (
176
193
  <View
177
- style={styles.container}
194
+ style={[styles.container]}
178
195
  ref={ref => {
179
- UnistylesShadowRegistry.add(ref, styles.container)
180
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
196
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
197
+ return () => UnistylesShadowRegistry.remove(ref)
181
198
  }}
182
199
  >
183
200
  <Text>Hello world</Text>
@@ -185,18 +202,22 @@ pluginTester({
185
202
  )
186
203
  }
187
204
 
188
- const styles = StyleSheet.create({
189
- container: {
190
- backgroundColor: 'red',
191
- variants: {},
192
- uni__dependencies: [4]
193
- }
194
- })
205
+ const styles = StyleSheet.create(
206
+ {
207
+ container: {
208
+ backgroundColor: 'red',
209
+ variants: {},
210
+ uni__dependencies: [4]
211
+ }
212
+ },
213
+ 793953373
214
+ )
195
215
  `
196
216
  },
197
217
  {
198
218
  title: 'Should detect variants for object StyleSheet and dynamic function',
199
219
  code: `
220
+ import { View, Text } from 'react-native'
200
221
  import { StyleSheet } from 'react-native-unistyles'
201
222
 
202
223
  export const Example = () => {
@@ -216,15 +237,16 @@ pluginTester({
216
237
  `,
217
238
  output: `
218
239
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
240
+ import { View, Text } from 'react-native'
219
241
  import { StyleSheet } from 'react-native-unistyles'
220
242
 
221
243
  export const Example = () => {
222
244
  return (
223
245
  <View
224
- style={styles.container}
246
+ style={[styles.container]}
225
247
  ref={ref => {
226
- UnistylesShadowRegistry.add(ref, styles.container)
227
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
248
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
249
+ return () => UnistylesShadowRegistry.remove(ref)
228
250
  }}
229
251
  >
230
252
  <Text>Hello world</Text>
@@ -232,18 +254,22 @@ pluginTester({
232
254
  )
233
255
  }
234
256
 
235
- const styles = StyleSheet.create({
236
- container: () => ({
237
- backgroundColor: 'red',
238
- variants: {},
239
- uni__dependencies: [4]
240
- })
241
- })
257
+ const styles = StyleSheet.create(
258
+ {
259
+ container: () => ({
260
+ backgroundColor: 'red',
261
+ variants: {},
262
+ uni__dependencies: [4]
263
+ })
264
+ },
265
+ 793953373
266
+ )
242
267
  `
243
268
  },
244
269
  {
245
270
  title: 'Should detect miniRuntime dependency',
246
271
  code: `
272
+ import { View, Text } from 'react-native'
247
273
  import { StyleSheet } from 'react-native-unistyles'
248
274
 
249
275
  export const Example = () => {
@@ -264,15 +290,16 @@ pluginTester({
264
290
  `,
265
291
  output: `
266
292
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
293
+ import { View, Text } from 'react-native'
267
294
  import { StyleSheet } from 'react-native-unistyles'
268
295
 
269
296
  export const Example = () => {
270
297
  return (
271
298
  <View
272
- style={styles.container}
299
+ style={[styles.container]}
273
300
  ref={ref => {
274
- UnistylesShadowRegistry.add(ref, styles.container)
275
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
301
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
302
+ return () => UnistylesShadowRegistry.remove(ref)
276
303
  }}
277
304
  >
278
305
  <Text>Hello world</Text>
@@ -280,19 +307,23 @@ pluginTester({
280
307
  )
281
308
  }
282
309
 
283
- const styles = StyleSheet.create((_, rt) => ({
284
- container: () => ({
285
- backgroundColor: 'red',
286
- variants: {},
287
- paddingTop: rt.insets.top,
288
- uni__dependencies: [4, 9]
289
- })
290
- }))
310
+ const styles = StyleSheet.create(
311
+ (_, rt) => ({
312
+ container: () => ({
313
+ backgroundColor: 'red',
314
+ variants: {},
315
+ paddingTop: rt.insets.top,
316
+ uni__dependencies: [4, 9]
317
+ })
318
+ }),
319
+ 793953373
320
+ )
291
321
  `
292
322
  },
293
323
  {
294
324
  title: 'Should detect miniRuntime and theme dependencies even if user renamed it\'s names',
295
325
  code: `
326
+ import { View, Text } from 'react-native'
296
327
  import { StyleSheet } from 'react-native-unistyles'
297
328
 
298
329
  export const Example = () => {
@@ -313,15 +344,16 @@ pluginTester({
313
344
  `,
314
345
  output: `
315
346
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
347
+ import { View, Text } from 'react-native'
316
348
  import { StyleSheet } from 'react-native-unistyles'
317
349
 
318
350
  export const Example = () => {
319
351
  return (
320
352
  <View
321
- style={styles.container}
353
+ style={[styles.container]}
322
354
  ref={ref => {
323
- UnistylesShadowRegistry.add(ref, styles.container)
324
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
355
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
356
+ return () => UnistylesShadowRegistry.remove(ref)
325
357
  }}
326
358
  >
327
359
  <Text>Hello world</Text>
@@ -329,19 +361,23 @@ pluginTester({
329
361
  )
330
362
  }
331
363
 
332
- const styles = StyleSheet.create((hhsa, dee) => ({
333
- container: () => ({
334
- backgroundColor: hhsa.colors.background,
335
- variants: {},
336
- paddingTop: dee.colorScheme === 'dark' ? 0 : 10,
337
- uni__dependencies: [0, 4, 5]
338
- })
339
- }))
364
+ const styles = StyleSheet.create(
365
+ (hhsa, dee) => ({
366
+ container: () => ({
367
+ backgroundColor: hhsa.colors.background,
368
+ variants: {},
369
+ paddingTop: dee.colorScheme === 'dark' ? 0 : 10,
370
+ uni__dependencies: [0, 4, 5]
371
+ })
372
+ }),
373
+ 793953373
374
+ )
340
375
  `
341
376
  },
342
377
  {
343
378
  title: 'Should detect dependencies in function',
344
379
  code: `
380
+ import { View, Text } from 'react-native'
345
381
  import { StyleSheet } from 'react-native-unistyles'
346
382
 
347
383
  export const Example = () => {
@@ -364,15 +400,16 @@ pluginTester({
364
400
  `,
365
401
  output: `
366
402
  import { UnistylesShadowRegistry } from 'react-native-unistyles'
403
+ import { View, Text } from 'react-native'
367
404
  import { StyleSheet } from 'react-native-unistyles'
368
405
 
369
406
  export const Example = () => {
370
407
  return (
371
408
  <View
372
- style={styles.container}
409
+ style={[styles.container]}
373
410
  ref={ref => {
374
- UnistylesShadowRegistry.add(ref, styles.container)
375
- return () => UnistylesShadowRegistry.remove(ref, styles.container)
411
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
412
+ return () => UnistylesShadowRegistry.remove(ref)
376
413
  }}
377
414
  >
378
415
  <Text>Hello world</Text>
@@ -389,7 +426,81 @@ pluginTester({
389
426
  uni__dependencies: [0, 4, 9]
390
427
  })
391
428
  }
429
+ }, 793953373)
430
+ `
431
+ },
432
+ {
433
+ title: 'Should generates two different ids for 2 stylesheets in the same file',
434
+ code: `
435
+ import { View, Text } from 'react-native'
436
+ import { StyleSheet } from 'react-native-unistyles'
437
+
438
+ export const Example = () => {
439
+ return (
440
+ <View style={styles.container}>
441
+ <Text>Hello world</Text>
442
+ </View>
443
+ )
444
+ }
445
+
446
+ const styles = StyleSheet.create((theme, rt) => {
447
+ return {
448
+ container: () => ({
449
+ backgroundColor: theme.colors.background,
450
+ variants: {},
451
+ paddingTop: rt.insets.top
452
+ })
453
+ }
454
+ })
455
+ const styles2 = StyleSheet.create((theme, rt) => {
456
+ return {
457
+ container: () => ({
458
+ backgroundColor: theme.colors.background,
459
+ variants: {},
460
+ paddingTop: rt.insets.top
461
+ })
462
+ }
392
463
  })
464
+ `,
465
+ output: `
466
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
467
+ import { View, Text } from 'react-native'
468
+ import { StyleSheet } from 'react-native-unistyles'
469
+
470
+ export const Example = () => {
471
+ return (
472
+ <View
473
+ style={[styles.container]}
474
+ ref={ref => {
475
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
476
+ return () => UnistylesShadowRegistry.remove(ref)
477
+ }}
478
+ >
479
+ <Text>Hello world</Text>
480
+ </View>
481
+ )
482
+ }
483
+
484
+ const styles = StyleSheet.create((theme, rt) => {
485
+ return {
486
+ container: () => ({
487
+ backgroundColor: theme.colors.background,
488
+ variants: {},
489
+ paddingTop: rt.insets.top,
490
+ uni__dependencies: [0, 4, 9]
491
+ })
492
+ }
493
+ }, 793953373)
494
+ const styles2 = StyleSheet.create((theme, rt) => {
495
+ return {
496
+ container: () => ({
497
+ backgroundColor: theme.colors.background,
498
+ variants: {},
499
+ paddingTop: rt.insets.top,
500
+ uni__dependencies: [0, 4, 9]
501
+ })
502
+ }
503
+ }, 793953374)
393
504
  `
394
505
  },
395
506
  ]
package/plugin/index.js CHANGED
@@ -1,7 +1,28 @@
1
1
  const addShadowRegistryImport = require('./import')
2
- const { getStyleObjectPath, getStyleAttribute } = require('./style')
2
+ const { getStyleMetadata, getStyleAttribute, styleAttributeToArray } = require('./style')
3
3
  const { getRefProp, addRef, overrideRef, hasStringRef } = require('./ref')
4
- const { isUnistylesStyleSheet, analyzeDependencies } = require('./stylesheet')
4
+ const { isUnistylesStyleSheet, analyzeDependencies, addStyleSheetTag, getUnistyle } = require('./stylesheet')
5
+ const { isUsingVariants, extractVariants } = require('./variants')
6
+
7
+ const reactNativeComponentNames = [
8
+ 'View',
9
+ 'Text',
10
+ 'Image',
11
+ 'ImageBackground',
12
+ 'KeyboardAvoidingView',
13
+ 'Modal',
14
+ 'Pressable',
15
+ 'ScrollView',
16
+ 'FlatList',
17
+ 'SectionList',
18
+ 'Switch',
19
+ 'Text',
20
+ 'TextInput',
21
+ 'TouchableHighlight',
22
+ 'TouchableOpacity',
23
+ 'TouchableWithoutFeedback',
24
+ 'VirtualizedList'
25
+ ]
5
26
 
6
27
  module.exports = function ({ types: t }) {
7
28
  return {
@@ -12,7 +33,9 @@ module.exports = function ({ types: t }) {
12
33
  state.file.hasAnyUnistyle = false
13
34
  state.file.hasUnistylesImport = false
14
35
  state.file.styleSheetLocalName = ''
15
- state.file.webDynamicFunctions = {}
36
+ state.file.tagNumber = 0
37
+ state.file.isClassComponent = false
38
+ state.reactNativeImports = {}
16
39
  },
17
40
  exit(path, state) {
18
41
  if (state.file.hasAnyUnistyle) {
@@ -20,6 +43,38 @@ module.exports = function ({ types: t }) {
20
43
  }
21
44
  }
22
45
  },
46
+ FunctionDeclaration(path, state) {
47
+ const componentName = path.node.id
48
+ ? path.node.id.name
49
+ : null
50
+
51
+ if (componentName) {
52
+ state.file.hasVariants = false
53
+ }
54
+ },
55
+ ClassDeclaration(path, state) {
56
+ const componentName = path.node.id
57
+ ? path.node.id.name
58
+ : null
59
+
60
+ if (componentName) {
61
+ state.file.hasVariants = false
62
+ state.file.isClassComponent = true
63
+ }
64
+ },
65
+ VariableDeclaration(path, state) {
66
+ path.node.declarations.forEach((declaration) => {
67
+ if (t.isArrowFunctionExpression(declaration.init) || t.isFunctionExpression(declaration.init)) {
68
+ const componentName = declaration.id
69
+ ? declaration.id.name
70
+ : null
71
+
72
+ if (componentName) {
73
+ state.file.hasVariants = false
74
+ }
75
+ }
76
+ })
77
+ },
23
78
  ImportDeclaration(path, state) {
24
79
  const importSource = path.node.source.value
25
80
 
@@ -32,9 +87,30 @@ module.exports = function ({ types: t }) {
32
87
  }
33
88
  })
34
89
  }
90
+
91
+ if (importSource.includes('react-native')) {
92
+ path.node.specifiers.forEach(specifier => {
93
+ if (specifier.imported && reactNativeComponentNames.includes(specifier.imported.name)) {
94
+ state.reactNativeImports[specifier.local.name] = true
95
+ }
96
+ })
97
+ }
35
98
  },
36
99
  JSXElement(path, state) {
37
- if (!state.file.hasUnistylesImport) {
100
+ if (state.file.isClassComponent) {
101
+ return
102
+ }
103
+
104
+ const openingElement = path.node.openingElement
105
+ const openingElementName = openingElement.name.name
106
+ const isReactNativeComponent = Boolean(state.reactNativeImports[openingElementName])
107
+ const isAnimatedComponent = (
108
+ !isReactNativeComponent &&
109
+ openingElement.name.object &&
110
+ openingElement.name.object.name === 'Animated'
111
+ )
112
+
113
+ if (!isReactNativeComponent && !isAnimatedComponent) {
38
114
  return
39
115
  }
40
116
 
@@ -45,43 +121,52 @@ module.exports = function ({ types: t }) {
45
121
  return
46
122
  }
47
123
 
48
- const stylePath = getStyleObjectPath(t, styleAttr.value.expression, state)
124
+ const metadata = getStyleMetadata(t, styleAttr.value.expression)
49
125
 
50
- // style prop is not using object expression
51
- if (stylePath.length !== 2) {
126
+ // style prop is using unexpected expression
127
+ if (metadata.length === 0) {
52
128
  return
53
129
  }
54
130
 
131
+ styleAttributeToArray(t, path)
132
+
55
133
  // to add import
56
134
  state.file.hasAnyUnistyle = true
57
135
 
58
- const refProp = getRefProp(t, path)
136
+ metadata.forEach(meta => {
137
+ const refProp = getRefProp(t, path)
59
138
 
60
- if (!refProp && hasStringRef(t, path)) {
61
- throw new Error("Detected string based ref which is not supported by Unistyles.")
62
- }
63
-
64
- const styleObj = stylePath[0]
65
- const styleProp = stylePath[1]
139
+ if (!refProp && hasStringRef(t, path)) {
140
+ throw new Error("Detected string based ref which is not supported by Unistyles.")
141
+ }
66
142
 
67
- refProp
68
- ? overrideRef(t, path, refProp, styleObj, styleProp)
69
- : addRef(t, path, styleObj, styleProp)
143
+ refProp
144
+ ? overrideRef(t, path, refProp, meta, state)
145
+ : addRef(t, path, meta, state)
146
+ })
70
147
  },
71
148
  CallExpression(path, state) {
149
+ if (isUsingVariants(t, path)) {
150
+ extractVariants(t, path, state)
151
+ }
152
+
72
153
  if (!isUnistylesStyleSheet(t, path, state)) {
73
154
  return
74
155
  }
75
156
 
157
+ addStyleSheetTag(t, path, state)
158
+
76
159
  const arg = path.node.arguments[0]
77
160
 
78
161
  // Object passed to StyleSheet.create
79
162
  if (t.isObjectExpression(arg)) {
80
163
  arg.properties.forEach(property => {
81
164
  if (t.isObjectProperty(property)) {
82
- const propertyValue = t.isArrowFunctionExpression(property.value)
83
- ? property.value.body
84
- : property.value
165
+ const propertyValue = getUnistyle(t, property)
166
+
167
+ if (!propertyValue) {
168
+ return
169
+ }
85
170
 
86
171
  analyzeDependencies(t, state, property.key.name, propertyValue)
87
172
  }
@@ -107,9 +192,11 @@ module.exports = function ({ types: t }) {
107
192
  if (t.isObjectExpression(body)) {
108
193
  body.properties.forEach(property => {
109
194
  if (t.isObjectProperty(property)) {
110
- const propertyValue = t.isArrowFunctionExpression(property.value)
111
- ? property.value.body
112
- : property.value
195
+ const propertyValue = getUnistyle(t, property)
196
+
197
+ if (!propertyValue) {
198
+ return
199
+ }
113
200
 
114
201
  analyzeDependencies(t, state, property.key.name, propertyValue, themeLocalName, miniRuntimeLocalName)
115
202
  }