react-native-unistyles 3.0.0-alpha.1 → 3.0.0-alpha.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (262) hide show
  1. package/Unistyles.podspec +33 -0
  2. package/cxx/common/Constants.h +1 -0
  3. package/cxx/common/Helpers.h +92 -0
  4. package/cxx/core/HostStyle.cpp +18 -12
  5. package/cxx/core/HostStyle.h +3 -0
  6. package/cxx/core/StyleSheet.h +0 -1
  7. package/cxx/core/StyleSheetRegistry.cpp +10 -13
  8. package/cxx/core/StyleSheetRegistry.h +4 -4
  9. package/cxx/core/Unistyle.h +0 -6
  10. package/cxx/core/UnistyleData.h +23 -0
  11. package/cxx/core/UnistyleWrapper.h +6 -6
  12. package/cxx/core/UnistylesCommitHook.cpp +8 -7
  13. package/cxx/core/UnistylesCommitHook.h +6 -1
  14. package/cxx/core/UnistylesCommitShadowNode.h +13 -0
  15. package/cxx/core/UnistylesMountHook.cpp +40 -0
  16. package/cxx/core/UnistylesMountHook.h +30 -0
  17. package/cxx/core/UnistylesRegistry.cpp +42 -56
  18. package/cxx/core/UnistylesRegistry.h +10 -8
  19. package/cxx/core/UnistylesState.cpp +4 -4
  20. package/cxx/hybridObjects/HybridShadowRegistry.cpp +8 -1
  21. package/cxx/hybridObjects/HybridStyleSheet.cpp +35 -39
  22. package/cxx/hybridObjects/HybridStyleSheet.h +9 -6
  23. package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +34 -15
  24. package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
  25. package/cxx/parser/Parser.cpp +65 -137
  26. package/cxx/parser/Parser.h +8 -14
  27. package/ios/UnistylesModuleOnLoad.h +2 -0
  28. package/ios/UnistylesModuleOnLoad.mm +8 -1
  29. package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
  30. package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
  31. package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
  32. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  33. package/lib/commonjs/specs/StatusBar/index.js +1 -1
  34. package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
  35. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  36. package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
  37. package/lib/commonjs/specs/UnistylesRuntime/index.js.map +1 -1
  38. package/lib/commonjs/specs/index.web.js +1 -1
  39. package/lib/commonjs/web/convert/boxShadow.js +77 -0
  40. package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
  41. package/lib/commonjs/web/convert/breakpoint.js +25 -0
  42. package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
  43. package/lib/commonjs/web/convert/index.js +76 -0
  44. package/lib/commonjs/web/convert/index.js.map +1 -0
  45. package/lib/commonjs/web/convert/module.d.js +2 -0
  46. package/lib/commonjs/web/convert/module.d.js.map +1 -0
  47. package/lib/commonjs/web/convert/shadow.js +68 -0
  48. package/lib/commonjs/web/convert/shadow.js.map +1 -0
  49. package/lib/commonjs/web/convert/style.js +89 -0
  50. package/lib/commonjs/web/convert/style.js.map +1 -0
  51. package/lib/commonjs/web/convert/textShadow.js +73 -0
  52. package/lib/commonjs/web/convert/textShadow.js.map +1 -0
  53. package/lib/commonjs/web/convert/transform.js +72 -0
  54. package/lib/commonjs/web/convert/transform.js.map +1 -0
  55. package/lib/commonjs/web/convert/types.js +9 -0
  56. package/lib/commonjs/web/convert/types.js.map +1 -0
  57. package/lib/commonjs/web/convert/utils.js +55 -0
  58. package/lib/commonjs/web/convert/utils.js.map +1 -0
  59. package/lib/commonjs/web/create.js +89 -0
  60. package/lib/commonjs/web/create.js.map +1 -0
  61. package/lib/commonjs/web/index.js +51 -0
  62. package/lib/commonjs/web/index.js.map +1 -0
  63. package/lib/commonjs/web/listener/index.js +13 -0
  64. package/lib/commonjs/web/listener/index.js.map +1 -0
  65. package/lib/commonjs/web/listener/listener.js +36 -0
  66. package/lib/commonjs/web/listener/listener.js.map +1 -0
  67. package/lib/commonjs/web/mock.js +37 -0
  68. package/lib/commonjs/web/mock.js.map +1 -0
  69. package/lib/commonjs/web/mq.js +23 -0
  70. package/lib/commonjs/web/mq.js.map +1 -0
  71. package/lib/commonjs/web/pseudo.js +11 -0
  72. package/lib/commonjs/web/pseudo.js.map +1 -0
  73. package/lib/commonjs/web/registry.js +37 -0
  74. package/lib/commonjs/web/registry.js.map +1 -0
  75. package/lib/commonjs/web/runtime.js +164 -0
  76. package/lib/commonjs/web/runtime.js.map +1 -0
  77. package/lib/commonjs/web/state.js +121 -0
  78. package/lib/commonjs/web/state.js.map +1 -0
  79. package/lib/commonjs/web/utils.js +78 -0
  80. package/lib/commonjs/web/utils.js.map +1 -0
  81. package/lib/commonjs/web/variants/getVariants.js +39 -0
  82. package/lib/commonjs/web/variants/getVariants.js.map +1 -0
  83. package/lib/commonjs/web/variants/index.js +28 -0
  84. package/lib/commonjs/web/variants/index.js.map +1 -0
  85. package/lib/commonjs/web/variants/useVariants.js +75 -0
  86. package/lib/commonjs/web/variants/useVariants.js.map +1 -0
  87. package/lib/module/specs/NavigtionBar/index.js +1 -1
  88. package/lib/module/specs/NavigtionBar/index.js.map +1 -1
  89. package/lib/module/specs/ShadowRegistry/index.js +2 -2
  90. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  91. package/lib/module/specs/StatusBar/index.js +1 -1
  92. package/lib/module/specs/StatusBar/index.js.map +1 -1
  93. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  94. package/lib/module/specs/UnistylesRuntime/index.js +1 -1
  95. package/lib/module/specs/UnistylesRuntime/index.js.map +1 -1
  96. package/lib/module/specs/index.web.js +1 -1
  97. package/lib/module/specs/index.web.js.map +1 -1
  98. package/lib/module/web/convert/boxShadow.js +72 -0
  99. package/lib/module/web/convert/boxShadow.js.map +1 -0
  100. package/lib/module/web/convert/breakpoint.js +20 -0
  101. package/lib/module/web/convert/breakpoint.js.map +1 -0
  102. package/lib/module/web/convert/index.js +71 -0
  103. package/lib/module/web/convert/index.js.map +1 -0
  104. package/lib/module/web/convert/module.d.js +2 -0
  105. package/lib/module/web/convert/module.d.js.map +1 -0
  106. package/lib/module/web/convert/shadow.js +63 -0
  107. package/lib/module/web/convert/shadow.js.map +1 -0
  108. package/lib/module/web/convert/style.js +84 -0
  109. package/lib/module/web/convert/style.js.map +1 -0
  110. package/lib/module/web/convert/textShadow.js +68 -0
  111. package/lib/module/web/convert/textShadow.js.map +1 -0
  112. package/lib/module/web/convert/transform.js +67 -0
  113. package/lib/module/web/convert/transform.js.map +1 -0
  114. package/lib/module/web/convert/types.js +5 -0
  115. package/lib/module/web/convert/types.js.map +1 -0
  116. package/lib/module/web/convert/utils.js +43 -0
  117. package/lib/module/web/convert/utils.js.map +1 -0
  118. package/lib/module/web/create.js +84 -0
  119. package/lib/module/web/create.js.map +1 -0
  120. package/lib/module/web/index.js +24 -0
  121. package/lib/module/web/index.js.map +1 -0
  122. package/lib/module/web/listener/index.js +4 -0
  123. package/lib/module/web/listener/index.js.map +1 -0
  124. package/lib/module/web/listener/listener.js +31 -0
  125. package/lib/module/web/listener/listener.js.map +1 -0
  126. package/lib/module/web/mock.js +33 -0
  127. package/lib/module/web/mock.js.map +1 -0
  128. package/lib/module/web/mq.js +17 -0
  129. package/lib/module/web/mq.js.map +1 -0
  130. package/lib/module/web/pseudo.js +6 -0
  131. package/lib/module/web/pseudo.js.map +1 -0
  132. package/lib/module/web/registry.js +33 -0
  133. package/lib/module/web/registry.js.map +1 -0
  134. package/lib/module/web/runtime.js +160 -0
  135. package/lib/module/web/runtime.js.map +1 -0
  136. package/lib/module/web/state.js +117 -0
  137. package/lib/module/web/state.js.map +1 -0
  138. package/lib/module/web/utils.js +65 -0
  139. package/lib/module/web/utils.js.map +1 -0
  140. package/lib/module/web/variants/getVariants.js +34 -0
  141. package/lib/module/web/variants/getVariants.js.map +1 -0
  142. package/lib/module/web/variants/index.js +5 -0
  143. package/lib/module/web/variants/index.js.map +1 -0
  144. package/lib/module/web/variants/useVariants.js +70 -0
  145. package/lib/module/web/variants/useVariants.js.map +1 -0
  146. package/lib/typescript/example/App.d.ts.map +1 -1
  147. package/lib/typescript/example/Typography.d.ts +12 -0
  148. package/lib/typescript/example/Typography.d.ts.map +1 -0
  149. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
  150. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  151. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  152. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  153. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  154. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  155. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  156. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  157. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  158. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  159. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  160. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  161. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  162. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  163. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  164. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  165. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  166. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  167. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  168. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  169. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  170. package/lib/typescript/{web → src/web}/index.d.ts +12 -12
  171. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  172. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  173. package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
  174. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  175. package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
  176. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  177. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  178. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  179. package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
  180. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  181. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
  182. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  183. package/lib/typescript/{web → src/web}/state.d.ts +4 -4
  184. package/lib/typescript/src/web/state.d.ts.map +1 -0
  185. package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
  186. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  187. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  188. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  189. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  190. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  191. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  192. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  193. package/package.json +2 -2
  194. package/plugin/__tests__/dependencies.spec.js +181 -103
  195. package/plugin/__tests__/ref.spec.js +335 -156
  196. package/plugin/__tests__/stylesheet.spec.js +148 -55
  197. package/plugin/index.js +31 -21
  198. package/plugin/ref.js +43 -11
  199. package/plugin/style.js +13 -24
  200. package/plugin/stylesheet.js +44 -1
  201. package/plugin/variants.js +33 -0
  202. package/src/specs/NavigtionBar/index.ts +1 -1
  203. package/src/specs/ShadowRegistry/index.ts +4 -4
  204. package/src/specs/StatusBar/index.ts +1 -1
  205. package/src/specs/StyleSheet/index.ts +3 -1
  206. package/src/specs/UnistylesRuntime/index.ts +1 -1
  207. package/src/specs/index.web.ts +1 -1
  208. package/src/types/stylesheet.ts +1 -1
  209. package/{web → src/web}/convert/breakpoint.ts +1 -1
  210. package/{web → src/web}/convert/index.ts +1 -1
  211. package/{web → src/web}/convert/types.ts +1 -1
  212. package/{web → src/web}/create.ts +36 -33
  213. package/{web → src/web}/listener/listener.ts +1 -1
  214. package/{web → src/web}/mock.ts +2 -2
  215. package/{web → src/web}/registry.ts +1 -1
  216. package/{web → src/web}/runtime.ts +4 -4
  217. package/{web → src/web}/state.ts +5 -5
  218. package/{web → src/web}/utils.ts +5 -5
  219. package/src/web/variants/getVariants.ts +42 -0
  220. package/src/web/variants/index.ts +2 -0
  221. package/{web → src/web/variants}/useVariants.ts +24 -44
  222. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  223. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  224. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  225. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  226. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  227. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  228. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  229. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  230. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  231. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  232. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  233. package/lib/typescript/web/mock.d.ts.map +0 -1
  234. package/lib/typescript/web/mq.d.ts.map +0 -1
  235. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  236. package/lib/typescript/web/registry.d.ts.map +0 -1
  237. package/lib/typescript/web/runtime.d.ts.map +0 -1
  238. package/lib/typescript/web/state.d.ts.map +0 -1
  239. package/lib/typescript/web/useVariants.d.ts +0 -3
  240. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  241. package/lib/typescript/web/utils.d.ts.map +0 -1
  242. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  243. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  244. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  245. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  246. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  247. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  248. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  249. /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
  250. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  251. /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
  252. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  253. /package/{web → src/web}/convert/module.d.ts +0 -0
  254. /package/{web → src/web}/convert/shadow.ts +0 -0
  255. /package/{web → src/web}/convert/style.ts +0 -0
  256. /package/{web → src/web}/convert/textShadow.ts +0 -0
  257. /package/{web → src/web}/convert/transform.ts +0 -0
  258. /package/{web → src/web}/convert/utils.ts +0 -0
  259. /package/{web → src/web}/index.ts +0 -0
  260. /package/{web → src/web}/listener/index.ts +0 -0
  261. /package/{web → src/web}/mq.ts +0 -0
  262. /package/{web → src/web}/pseudo.ts +0 -0
@@ -41,7 +41,7 @@ pluginTester({
41
41
  <View
42
42
  style={styles.container}
43
43
  ref={ref => {
44
- UnistylesShadowRegistry.add(ref, styles.container)
44
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
45
45
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
46
46
  }}
47
47
  >
@@ -50,11 +50,14 @@ pluginTester({
50
50
  )
51
51
  }
52
52
 
53
- const styles = StyleSheet.create({
54
- container: {
55
- backgroundColor: 'red'
56
- }
57
- })
53
+ const styles = StyleSheet.create(
54
+ {
55
+ container: {
56
+ backgroundColor: 'red'
57
+ }
58
+ },
59
+ 793953373
60
+ )
58
61
  `
59
62
  },
60
63
  {
@@ -85,7 +88,7 @@ pluginTester({
85
88
  <View
86
89
  style={styles.container}
87
90
  ref={ref => {
88
- UnistylesShadowRegistry.add(ref, styles.container)
91
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
89
92
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
90
93
  }}
91
94
  >
@@ -94,12 +97,15 @@ pluginTester({
94
97
  )
95
98
  }
96
99
 
97
- const styles = StyleSheet.create(theme => ({
98
- container: {
99
- backgroundColor: theme.colors.background,
100
- uni__dependencies: [0]
101
- }
102
- }))
100
+ const styles = StyleSheet.create(
101
+ theme => ({
102
+ container: {
103
+ backgroundColor: theme.colors.background,
104
+ uni__dependencies: [0]
105
+ }
106
+ }),
107
+ 793953373
108
+ )
103
109
  `
104
110
  },
105
111
  {
@@ -130,7 +136,7 @@ pluginTester({
130
136
  <View
131
137
  style={styles.container}
132
138
  ref={ref => {
133
- UnistylesShadowRegistry.add(ref, styles.container)
139
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
134
140
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
135
141
  }}
136
142
  >
@@ -139,12 +145,15 @@ pluginTester({
139
145
  )
140
146
  }
141
147
 
142
- const styles = ST.create(theme => ({
143
- container: {
144
- backgroundColor: theme.colors.background,
145
- uni__dependencies: [0]
146
- }
147
- }))
148
+ const styles = ST.create(
149
+ theme => ({
150
+ container: {
151
+ backgroundColor: theme.colors.background,
152
+ uni__dependencies: [0]
153
+ }
154
+ }),
155
+ 793953373
156
+ )
148
157
  `
149
158
  },
150
159
  {
@@ -176,7 +185,7 @@ pluginTester({
176
185
  <View
177
186
  style={styles.container}
178
187
  ref={ref => {
179
- UnistylesShadowRegistry.add(ref, styles.container)
188
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
180
189
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
181
190
  }}
182
191
  >
@@ -185,13 +194,16 @@ pluginTester({
185
194
  )
186
195
  }
187
196
 
188
- const styles = StyleSheet.create({
189
- container: {
190
- backgroundColor: 'red',
191
- variants: {},
192
- uni__dependencies: [4]
193
- }
194
- })
197
+ const styles = StyleSheet.create(
198
+ {
199
+ container: {
200
+ backgroundColor: 'red',
201
+ variants: {},
202
+ uni__dependencies: [4]
203
+ }
204
+ },
205
+ 793953373
206
+ )
195
207
  `
196
208
  },
197
209
  {
@@ -223,7 +235,7 @@ pluginTester({
223
235
  <View
224
236
  style={styles.container}
225
237
  ref={ref => {
226
- UnistylesShadowRegistry.add(ref, styles.container)
238
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
227
239
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
228
240
  }}
229
241
  >
@@ -232,13 +244,16 @@ pluginTester({
232
244
  )
233
245
  }
234
246
 
235
- const styles = StyleSheet.create({
236
- container: () => ({
237
- backgroundColor: 'red',
238
- variants: {},
239
- uni__dependencies: [4]
240
- })
241
- })
247
+ const styles = StyleSheet.create(
248
+ {
249
+ container: () => ({
250
+ backgroundColor: 'red',
251
+ variants: {},
252
+ uni__dependencies: [4]
253
+ })
254
+ },
255
+ 793953373
256
+ )
242
257
  `
243
258
  },
244
259
  {
@@ -271,7 +286,7 @@ pluginTester({
271
286
  <View
272
287
  style={styles.container}
273
288
  ref={ref => {
274
- UnistylesShadowRegistry.add(ref, styles.container)
289
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
275
290
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
276
291
  }}
277
292
  >
@@ -280,14 +295,17 @@ pluginTester({
280
295
  )
281
296
  }
282
297
 
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
- }))
298
+ const styles = StyleSheet.create(
299
+ (_, rt) => ({
300
+ container: () => ({
301
+ backgroundColor: 'red',
302
+ variants: {},
303
+ paddingTop: rt.insets.top,
304
+ uni__dependencies: [4, 9]
305
+ })
306
+ }),
307
+ 793953373
308
+ )
291
309
  `
292
310
  },
293
311
  {
@@ -320,7 +338,7 @@ pluginTester({
320
338
  <View
321
339
  style={styles.container}
322
340
  ref={ref => {
323
- UnistylesShadowRegistry.add(ref, styles.container)
341
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
324
342
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
325
343
  }}
326
344
  >
@@ -329,14 +347,17 @@ pluginTester({
329
347
  )
330
348
  }
331
349
 
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
- }))
350
+ const styles = StyleSheet.create(
351
+ (hhsa, dee) => ({
352
+ container: () => ({
353
+ backgroundColor: hhsa.colors.background,
354
+ variants: {},
355
+ paddingTop: dee.colorScheme === 'dark' ? 0 : 10,
356
+ uni__dependencies: [0, 4, 5]
357
+ })
358
+ }),
359
+ 793953373
360
+ )
340
361
  `
341
362
  },
342
363
  {
@@ -371,7 +392,7 @@ pluginTester({
371
392
  <View
372
393
  style={styles.container}
373
394
  ref={ref => {
374
- UnistylesShadowRegistry.add(ref, styles.container)
395
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
375
396
  return () => UnistylesShadowRegistry.remove(ref, styles.container)
376
397
  }}
377
398
  >
@@ -389,7 +410,79 @@ pluginTester({
389
410
  uni__dependencies: [0, 4, 9]
390
411
  })
391
412
  }
413
+ }, 793953373)
414
+ `
415
+ },
416
+ {
417
+ title: 'Should generates two different ids for 2 stylesheets in the same file',
418
+ code: `
419
+ import { StyleSheet } from 'react-native-unistyles'
420
+
421
+ export const Example = () => {
422
+ return (
423
+ <View style={styles.container}>
424
+ <Text>Hello world</Text>
425
+ </View>
426
+ )
427
+ }
428
+
429
+ const styles = StyleSheet.create((theme, rt) => {
430
+ return {
431
+ container: () => ({
432
+ backgroundColor: theme.colors.background,
433
+ variants: {},
434
+ paddingTop: rt.insets.top
435
+ })
436
+ }
392
437
  })
438
+ const styles2 = StyleSheet.create((theme, rt) => {
439
+ return {
440
+ container: () => ({
441
+ backgroundColor: theme.colors.background,
442
+ variants: {},
443
+ paddingTop: rt.insets.top
444
+ })
445
+ }
446
+ })
447
+ `,
448
+ output: `
449
+ import { UnistylesShadowRegistry } from 'react-native-unistyles'
450
+ import { StyleSheet } from 'react-native-unistyles'
451
+
452
+ export const Example = () => {
453
+ return (
454
+ <View
455
+ style={styles.container}
456
+ ref={ref => {
457
+ UnistylesShadowRegistry.add(ref, styles.container, undefined, undefined)
458
+ return () => UnistylesShadowRegistry.remove(ref, styles.container)
459
+ }}
460
+ >
461
+ <Text>Hello world</Text>
462
+ </View>
463
+ )
464
+ }
465
+
466
+ const styles = StyleSheet.create((theme, rt) => {
467
+ return {
468
+ container: () => ({
469
+ backgroundColor: theme.colors.background,
470
+ variants: {},
471
+ paddingTop: rt.insets.top,
472
+ uni__dependencies: [0, 4, 9]
473
+ })
474
+ }
475
+ }, 793953373)
476
+ const styles2 = StyleSheet.create((theme, rt) => {
477
+ return {
478
+ container: () => ({
479
+ backgroundColor: theme.colors.background,
480
+ variants: {},
481
+ paddingTop: rt.insets.top,
482
+ uni__dependencies: [0, 4, 9]
483
+ })
484
+ }
485
+ }, 793953374)
393
486
  `
394
487
  },
395
488
  ]
package/plugin/index.js CHANGED
@@ -1,7 +1,8 @@
1
1
  const addShadowRegistryImport = require('./import')
2
- const { getStyleObjectPath, getStyleAttribute } = require('./style')
2
+ const { getStyleMetadata, getStyleAttribute } = 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')
5
6
 
6
7
  module.exports = function ({ types: t }) {
7
8
  return {
@@ -12,7 +13,7 @@ module.exports = function ({ types: t }) {
12
13
  state.file.hasAnyUnistyle = false
13
14
  state.file.hasUnistylesImport = false
14
15
  state.file.styleSheetLocalName = ''
15
- state.file.webDynamicFunctions = {}
16
+ state.file.tagNumber = 0
16
17
  },
17
18
  exit(path, state) {
18
19
  if (state.file.hasAnyUnistyle) {
@@ -45,43 +46,50 @@ module.exports = function ({ types: t }) {
45
46
  return
46
47
  }
47
48
 
48
- const stylePath = getStyleObjectPath(t, styleAttr.value.expression, state)
49
+ const metadata = getStyleMetadata(t, styleAttr.value.expression)
49
50
 
50
51
  // style prop is not using object expression
51
- if (stylePath.length !== 2) {
52
+ if (metadata.length === 0) {
52
53
  return
53
54
  }
54
55
 
55
56
  // to add import
56
57
  state.file.hasAnyUnistyle = true
57
58
 
58
- const refProp = getRefProp(t, path)
59
+ metadata.forEach(meta => {
60
+ const refProp = getRefProp(t, path)
59
61
 
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]
62
+ if (!refProp && hasStringRef(t, path)) {
63
+ throw new Error("Detected string based ref which is not supported by Unistyles.")
64
+ }
66
65
 
67
- refProp
68
- ? overrideRef(t, path, refProp, styleObj, styleProp)
69
- : addRef(t, path, styleObj, styleProp)
66
+ refProp
67
+ ? overrideRef(t, path, refProp, meta, state)
68
+ : addRef(t, path, meta, state)
69
+ })
70
70
  },
71
71
  CallExpression(path, state) {
72
+ if (isUsingVariants(t, path)) {
73
+ extractVariants(t, path, state)
74
+ }
75
+
72
76
  if (!isUnistylesStyleSheet(t, path, state)) {
73
77
  return
74
78
  }
75
79
 
80
+ addStyleSheetTag(t, path, state)
81
+
76
82
  const arg = path.node.arguments[0]
77
83
 
78
84
  // Object passed to StyleSheet.create
79
85
  if (t.isObjectExpression(arg)) {
80
86
  arg.properties.forEach(property => {
81
87
  if (t.isObjectProperty(property)) {
82
- const propertyValue = t.isArrowFunctionExpression(property.value)
83
- ? property.value.body
84
- : property.value
88
+ const propertyValue = getUnistyle(t, property)
89
+
90
+ if (!propertyValue) {
91
+ return
92
+ }
85
93
 
86
94
  analyzeDependencies(t, state, property.key.name, propertyValue)
87
95
  }
@@ -107,9 +115,11 @@ module.exports = function ({ types: t }) {
107
115
  if (t.isObjectExpression(body)) {
108
116
  body.properties.forEach(property => {
109
117
  if (t.isObjectProperty(property)) {
110
- const propertyValue = t.isArrowFunctionExpression(property.value)
111
- ? property.value.body
112
- : property.value
118
+ const propertyValue = getUnistyle(t, property)
119
+
120
+ if (!propertyValue) {
121
+ return
122
+ }
113
123
 
114
124
  analyzeDependencies(t, state, property.key.name, propertyValue, themeLocalName, miniRuntimeLocalName)
115
125
  }
package/plugin/ref.js CHANGED
@@ -14,21 +14,28 @@ function hasStringRef(t, path) {
14
14
  )
15
15
  }
16
16
 
17
- function addRef(t, path, styleObj, styleProp) {
17
+ function addRef(t, path, metadata, state) {
18
+ const hasVariants = state.file.hasVariants
19
+
18
20
  const newRefFunction = t.arrowFunctionExpression(
19
21
  [t.identifier('ref')],
20
22
  t.blockStatement([
21
23
  t.expressionStatement(
22
24
  t.callExpression(
23
25
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
24
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
26
+ [
27
+ t.identifier('ref'),
28
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
29
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
30
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
31
+ ]
25
32
  )
26
33
  ),
27
34
  t.returnStatement(
28
35
  t.arrowFunctionExpression([],
29
36
  t.callExpression(
30
37
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
31
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
38
+ [t.identifier('ref'), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
32
39
  )
33
40
  )
34
41
  )
@@ -43,7 +50,8 @@ function addRef(t, path, styleObj, styleProp) {
43
50
  path.node.openingElement.attributes.push(newRefProp)
44
51
  }
45
52
 
46
- function overrideRef(t, path, refProp, styleObj, styleProp) {
53
+ function overrideRef(t, path, refProp, metadata, state) {
54
+ const hasVariants = state.file.hasVariants
47
55
  const uniqueRefName = path.scope.generateUidIdentifier('ref').name
48
56
  const isIdentifier = t.isIdentifier(refProp.value.expression)
49
57
  const binding = path.scope.getBinding(refProp.value.expression.name)
@@ -55,19 +63,29 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
55
63
  [t.identifier(uniqueRefName)],
56
64
  t.blockStatement([
57
65
  t.expressionStatement(
58
- t.assignmentExpression('=', t.identifier(userVariableName), t.identifier(uniqueRefName))
66
+ t.assignmentExpression(
67
+ '=',
68
+ t.memberExpression(t.identifier(userVariableName), t.identifier('current')),
69
+ t.identifier(uniqueRefName)
70
+ )
59
71
  ),
60
72
  t.expressionStatement(
61
73
  t.callExpression(
62
74
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
63
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
75
+
76
+ [
77
+ t.identifier(uniqueRefName),
78
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
79
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
80
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
81
+ ]
64
82
  )
65
83
  ),
66
84
  t.returnStatement(
67
85
  t.arrowFunctionExpression([],
68
86
  t.callExpression(
69
87
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
70
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
88
+ [t.identifier(uniqueRefName), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
71
89
  )
72
90
  )
73
91
  )
@@ -95,7 +113,12 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
95
113
  t.expressionStatement(
96
114
  t.callExpression(
97
115
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
98
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
116
+ [
117
+ t.identifier('ref'),
118
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
119
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
120
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
121
+ ]
99
122
  )
100
123
  ),
101
124
  // Merged cleanup function
@@ -109,7 +132,7 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
109
132
  t.expressionStatement(
110
133
  t.callExpression(
111
134
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
112
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
135
+ [t.identifier('ref'), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
113
136
  )
114
137
  )
115
138
  ]))
@@ -122,6 +145,10 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
122
145
  return
123
146
  }
124
147
 
148
+ if (!binding) {
149
+ return
150
+ }
151
+
125
152
  // ref={scopedFunction}
126
153
  const isArrowFunction = t.isArrowFunctionExpression(binding.path.node.init)
127
154
  const isFunction = t.isFunctionDeclaration(binding.path.node)
@@ -146,7 +173,12 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
146
173
  t.expressionStatement(
147
174
  t.callExpression(
148
175
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
149
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
176
+ [
177
+ t.identifier(uniqueRefName),
178
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
179
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined'),
180
+ metadata.dynamicFunction ? t.arrayExpression(metadata.dynamicFunction.arguments) : t.identifier('undefined')
181
+ ]
150
182
  )
151
183
  ),
152
184
  t.returnStatement(
@@ -159,7 +191,7 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
159
191
  t.expressionStatement(
160
192
  t.callExpression(
161
193
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
162
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
194
+ [t.identifier(uniqueRefName), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
163
195
  )
164
196
  )
165
197
  ]))
package/plugin/style.js CHANGED
@@ -1,44 +1,33 @@
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
+ return [
5
+ {
6
+ styleObj: node.object.name,
7
+ styleProp: node.property.name,
8
+ dynamicFunction
9
+ }
10
+ ]
5
11
  }
6
12
 
7
13
  // [styles.container]
8
14
  if (t.isArrayExpression(node)) {
9
- return node.elements.flatMap(element => getStyleObjectPath(t, element, state))
15
+ return node.elements.flatMap(element => getStyleMetadata(t, element))
10
16
  }
11
17
 
12
18
  // [...styles.container]
13
19
  if (t.isSpreadElement(node)) {
14
- return getStyleObjectPath(t, node.argument, state)
20
+ return getStyleMetadata(t, node.argument)
15
21
  }
16
22
 
17
23
  // {{ ...styles.container }}
18
24
  if (t.isObjectExpression(node)) {
19
- return node.properties.flatMap(prop => getStyleObjectPath(t, prop.argument, state))
25
+ return node.properties.flatMap(prop => getStyleMetadata(t, prop.argument))
20
26
  }
21
27
 
22
28
  // {styles.container(arg1, arg2)}
23
29
  if (t.isCallExpression(node)) {
24
- const path = getStyleObjectPath(t, node.callee, state)
25
- const lastPart = path.slice(-1)
26
-
27
- if (!lastPart) {
28
- return path
29
- }
30
-
31
- // for web increment counter for dynamic functions
32
- if (state.file.webDynamicFunctions[lastPart]) {
33
- node.arguments.push(t.numericLiteral(++state.file.webDynamicFunctions[lastPart]))
34
-
35
- return path
36
- }
37
-
38
- state.file.webDynamicFunctions[lastPart] = 1
39
- node.arguments.push(t.numericLiteral(1))
40
-
41
- return path
30
+ return getStyleMetadata(t, node.callee, node)
42
31
  }
43
32
 
44
33
  return []
@@ -53,6 +42,6 @@ function getStyleAttribute(t, path) {
53
42
  }
54
43
 
55
44
  module.exports = {
56
- getStyleObjectPath,
45
+ getStyleMetadata,
57
46
  getStyleAttribute
58
47
  }
@@ -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
  }