react-native-unistyles 3.0.0-alpha.6 → 3.0.0-alpha.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (233) hide show
  1. package/cxx/common/Helpers.h +24 -0
  2. package/cxx/core/HostStyle.cpp +4 -5
  3. package/cxx/core/HostStyle.h +4 -0
  4. package/cxx/core/StyleSheet.h +0 -1
  5. package/cxx/core/StyleSheetRegistry.cpp +9 -17
  6. package/cxx/core/StyleSheetRegistry.h +3 -4
  7. package/cxx/core/UnistyleData.h +22 -0
  8. package/cxx/core/UnistylesCommitHook.cpp +4 -1
  9. package/cxx/core/UnistylesRegistry.cpp +33 -49
  10. package/cxx/core/UnistylesRegistry.h +8 -8
  11. package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -3
  12. package/cxx/hybridObjects/HybridStyleSheet.cpp +8 -11
  13. package/cxx/parser/Parser.cpp +41 -57
  14. package/cxx/parser/Parser.h +8 -13
  15. package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
  16. package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
  17. package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
  18. package/lib/commonjs/specs/index.web.js +1 -1
  19. package/lib/commonjs/web/convert/boxShadow.js +77 -0
  20. package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
  21. package/lib/commonjs/web/convert/breakpoint.js +25 -0
  22. package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
  23. package/lib/commonjs/web/convert/index.js +76 -0
  24. package/lib/commonjs/web/convert/index.js.map +1 -0
  25. package/lib/commonjs/web/convert/module.d.js +2 -0
  26. package/lib/commonjs/web/convert/module.d.js.map +1 -0
  27. package/lib/commonjs/web/convert/shadow.js +68 -0
  28. package/lib/commonjs/web/convert/shadow.js.map +1 -0
  29. package/lib/commonjs/web/convert/style.js +89 -0
  30. package/lib/commonjs/web/convert/style.js.map +1 -0
  31. package/lib/commonjs/web/convert/textShadow.js +73 -0
  32. package/lib/commonjs/web/convert/textShadow.js.map +1 -0
  33. package/lib/commonjs/web/convert/transform.js +72 -0
  34. package/lib/commonjs/web/convert/transform.js.map +1 -0
  35. package/lib/commonjs/web/convert/types.js +9 -0
  36. package/lib/commonjs/web/convert/types.js.map +1 -0
  37. package/lib/commonjs/web/convert/utils.js +55 -0
  38. package/lib/commonjs/web/convert/utils.js.map +1 -0
  39. package/lib/commonjs/web/create.js +89 -0
  40. package/lib/commonjs/web/create.js.map +1 -0
  41. package/lib/commonjs/web/index.js +51 -0
  42. package/lib/commonjs/web/index.js.map +1 -0
  43. package/lib/commonjs/web/listener/index.js +13 -0
  44. package/lib/commonjs/web/listener/index.js.map +1 -0
  45. package/lib/commonjs/web/listener/listener.js +36 -0
  46. package/lib/commonjs/web/listener/listener.js.map +1 -0
  47. package/lib/commonjs/web/mock.js +37 -0
  48. package/lib/commonjs/web/mock.js.map +1 -0
  49. package/lib/commonjs/web/mq.js +23 -0
  50. package/lib/commonjs/web/mq.js.map +1 -0
  51. package/lib/commonjs/web/pseudo.js +11 -0
  52. package/lib/commonjs/web/pseudo.js.map +1 -0
  53. package/lib/commonjs/web/registry.js +37 -0
  54. package/lib/commonjs/web/registry.js.map +1 -0
  55. package/lib/commonjs/web/runtime.js +164 -0
  56. package/lib/commonjs/web/runtime.js.map +1 -0
  57. package/lib/commonjs/web/state.js +121 -0
  58. package/lib/commonjs/web/state.js.map +1 -0
  59. package/lib/commonjs/web/utils.js +78 -0
  60. package/lib/commonjs/web/utils.js.map +1 -0
  61. package/lib/commonjs/web/variants/getVariants.js +39 -0
  62. package/lib/commonjs/web/variants/getVariants.js.map +1 -0
  63. package/lib/commonjs/web/variants/index.js +28 -0
  64. package/lib/commonjs/web/variants/index.js.map +1 -0
  65. package/lib/commonjs/web/variants/useVariants.js +75 -0
  66. package/lib/commonjs/web/variants/useVariants.js.map +1 -0
  67. package/lib/module/specs/ShadowRegistry/index.js +2 -2
  68. package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
  69. package/lib/module/specs/StyleSheet/index.js.map +1 -1
  70. package/lib/module/specs/index.web.js +1 -1
  71. package/lib/module/specs/index.web.js.map +1 -1
  72. package/lib/module/web/convert/boxShadow.js +72 -0
  73. package/lib/module/web/convert/boxShadow.js.map +1 -0
  74. package/lib/module/web/convert/breakpoint.js +20 -0
  75. package/lib/module/web/convert/breakpoint.js.map +1 -0
  76. package/lib/module/web/convert/index.js +71 -0
  77. package/lib/module/web/convert/index.js.map +1 -0
  78. package/lib/module/web/convert/module.d.js +2 -0
  79. package/lib/module/web/convert/module.d.js.map +1 -0
  80. package/lib/module/web/convert/shadow.js +63 -0
  81. package/lib/module/web/convert/shadow.js.map +1 -0
  82. package/lib/module/web/convert/style.js +84 -0
  83. package/lib/module/web/convert/style.js.map +1 -0
  84. package/lib/module/web/convert/textShadow.js +68 -0
  85. package/lib/module/web/convert/textShadow.js.map +1 -0
  86. package/lib/module/web/convert/transform.js +67 -0
  87. package/lib/module/web/convert/transform.js.map +1 -0
  88. package/lib/module/web/convert/types.js +5 -0
  89. package/lib/module/web/convert/types.js.map +1 -0
  90. package/lib/module/web/convert/utils.js +43 -0
  91. package/lib/module/web/convert/utils.js.map +1 -0
  92. package/lib/module/web/create.js +84 -0
  93. package/lib/module/web/create.js.map +1 -0
  94. package/lib/module/web/index.js +24 -0
  95. package/lib/module/web/index.js.map +1 -0
  96. package/lib/module/web/listener/index.js +4 -0
  97. package/lib/module/web/listener/index.js.map +1 -0
  98. package/lib/module/web/listener/listener.js +31 -0
  99. package/lib/module/web/listener/listener.js.map +1 -0
  100. package/lib/module/web/mock.js +33 -0
  101. package/lib/module/web/mock.js.map +1 -0
  102. package/lib/module/web/mq.js +17 -0
  103. package/lib/module/web/mq.js.map +1 -0
  104. package/lib/module/web/pseudo.js +6 -0
  105. package/lib/module/web/pseudo.js.map +1 -0
  106. package/lib/module/web/registry.js +33 -0
  107. package/lib/module/web/registry.js.map +1 -0
  108. package/lib/module/web/runtime.js +160 -0
  109. package/lib/module/web/runtime.js.map +1 -0
  110. package/lib/module/web/state.js +117 -0
  111. package/lib/module/web/state.js.map +1 -0
  112. package/lib/module/web/utils.js +65 -0
  113. package/lib/module/web/utils.js.map +1 -0
  114. package/lib/module/web/variants/getVariants.js +34 -0
  115. package/lib/module/web/variants/getVariants.js.map +1 -0
  116. package/lib/module/web/variants/index.js +5 -0
  117. package/lib/module/web/variants/index.js.map +1 -0
  118. package/lib/module/web/variants/useVariants.js +70 -0
  119. package/lib/module/web/variants/useVariants.js.map +1 -0
  120. package/lib/typescript/example/App.d.ts.map +1 -1
  121. package/lib/typescript/example/Typography.d.ts +11 -0
  122. package/lib/typescript/example/Typography.d.ts.map +1 -0
  123. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
  124. package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
  125. package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
  126. package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
  127. package/lib/typescript/src/specs/index.web.d.ts +1 -1
  128. package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
  129. package/lib/typescript/src/types/stylesheet.d.ts +1 -1
  130. package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
  131. package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
  132. package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
  133. package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
  134. package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
  135. package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
  136. package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
  137. package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
  138. package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
  139. package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
  140. package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
  141. package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
  142. package/lib/typescript/{web → src/web}/create.d.ts +11 -11
  143. package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
  144. package/lib/typescript/{web → src/web}/index.d.ts +12 -12
  145. package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
  146. package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
  147. package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
  148. package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
  149. package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
  150. package/lib/typescript/src/web/mock.d.ts.map +1 -0
  151. package/lib/typescript/src/web/mq.d.ts.map +1 -0
  152. package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
  153. package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
  154. package/lib/typescript/src/web/registry.d.ts.map +1 -0
  155. package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
  156. package/lib/typescript/src/web/runtime.d.ts.map +1 -0
  157. package/lib/typescript/{web → src/web}/state.d.ts +4 -4
  158. package/lib/typescript/src/web/state.d.ts.map +1 -0
  159. package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
  160. package/lib/typescript/src/web/utils.d.ts.map +1 -0
  161. package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
  162. package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
  163. package/lib/typescript/src/web/variants/index.d.ts +3 -0
  164. package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
  165. package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
  166. package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
  167. package/package.json +1 -1
  168. package/plugin/__tests__/dependencies.spec.js +181 -103
  169. package/plugin/__tests__/ref.spec.js +346 -156
  170. package/plugin/__tests__/stylesheet.spec.js +148 -55
  171. package/plugin/index.js +31 -21
  172. package/plugin/ref.js +67 -15
  173. package/plugin/style.js +13 -24
  174. package/plugin/stylesheet.js +44 -1
  175. package/plugin/variants.js +33 -0
  176. package/src/specs/ShadowRegistry/index.ts +4 -4
  177. package/src/specs/StyleSheet/index.ts +3 -1
  178. package/src/specs/index.web.ts +1 -1
  179. package/src/types/stylesheet.ts +1 -1
  180. package/{web → src/web}/convert/breakpoint.ts +1 -1
  181. package/{web → src/web}/convert/index.ts +1 -1
  182. package/{web → src/web}/convert/types.ts +1 -1
  183. package/{web → src/web}/create.ts +36 -33
  184. package/{web → src/web}/listener/listener.ts +1 -1
  185. package/{web → src/web}/mock.ts +2 -2
  186. package/{web → src/web}/registry.ts +1 -1
  187. package/{web → src/web}/runtime.ts +4 -4
  188. package/{web → src/web}/state.ts +5 -5
  189. package/{web → src/web}/utils.ts +5 -5
  190. package/src/web/variants/getVariants.ts +42 -0
  191. package/src/web/variants/index.ts +2 -0
  192. package/{web → src/web/variants}/useVariants.ts +24 -44
  193. package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
  194. package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
  195. package/lib/typescript/web/convert/index.d.ts.map +0 -1
  196. package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
  197. package/lib/typescript/web/convert/style.d.ts.map +0 -1
  198. package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
  199. package/lib/typescript/web/convert/transform.d.ts.map +0 -1
  200. package/lib/typescript/web/convert/types.d.ts.map +0 -1
  201. package/lib/typescript/web/convert/utils.d.ts.map +0 -1
  202. package/lib/typescript/web/listener/index.d.ts.map +0 -1
  203. package/lib/typescript/web/listener/listener.d.ts.map +0 -1
  204. package/lib/typescript/web/mock.d.ts.map +0 -1
  205. package/lib/typescript/web/mq.d.ts.map +0 -1
  206. package/lib/typescript/web/pseudo.d.ts.map +0 -1
  207. package/lib/typescript/web/registry.d.ts.map +0 -1
  208. package/lib/typescript/web/runtime.d.ts.map +0 -1
  209. package/lib/typescript/web/state.d.ts.map +0 -1
  210. package/lib/typescript/web/useVariants.d.ts +0 -3
  211. package/lib/typescript/web/useVariants.d.ts.map +0 -1
  212. package/lib/typescript/web/utils.d.ts.map +0 -1
  213. /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
  214. /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
  215. /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
  216. /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
  217. /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
  218. /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
  219. /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
  220. /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
  221. /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
  222. /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
  223. /package/{web → src/web}/convert/boxShadow.ts +0 -0
  224. /package/{web → src/web}/convert/module.d.ts +0 -0
  225. /package/{web → src/web}/convert/shadow.ts +0 -0
  226. /package/{web → src/web}/convert/style.ts +0 -0
  227. /package/{web → src/web}/convert/textShadow.ts +0 -0
  228. /package/{web → src/web}/convert/transform.ts +0 -0
  229. /package/{web → src/web}/convert/utils.ts +0 -0
  230. /package/{web → src/web}/index.ts +0 -0
  231. /package/{web → src/web}/listener/index.ts +0 -0
  232. /package/{web → src/web}/mq.ts +0 -0
  233. /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)
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)
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)
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)
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)
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)
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)
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)
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)
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,25 +14,37 @@ 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([
23
+ metadata.dynamicFunction ? t.expressionStatement(
24
+ t.callExpression(
25
+ metadata.dynamicFunction.callee,
26
+ metadata.dynamicFunction.arguments.concat(t.identifier('ref'))
27
+ )
28
+ ) : null,
21
29
  t.expressionStatement(
22
30
  t.callExpression(
23
31
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
24
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
32
+ [
33
+ t.identifier('ref'),
34
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
35
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined')
36
+ ]
25
37
  )
26
38
  ),
27
39
  t.returnStatement(
28
40
  t.arrowFunctionExpression([],
29
41
  t.callExpression(
30
42
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
31
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
43
+ [t.identifier('ref'), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
32
44
  )
33
45
  )
34
46
  )
35
- ])
47
+ ].filter(Boolean))
36
48
  )
37
49
 
38
50
  const newRefProp = t.jsxAttribute(
@@ -43,7 +55,8 @@ function addRef(t, path, styleObj, styleProp) {
43
55
  path.node.openingElement.attributes.push(newRefProp)
44
56
  }
45
57
 
46
- function overrideRef(t, path, refProp, styleObj, styleProp) {
58
+ function overrideRef(t, path, refProp, metadata, state) {
59
+ const hasVariants = state.file.hasVariants
47
60
  const uniqueRefName = path.scope.generateUidIdentifier('ref').name
48
61
  const isIdentifier = t.isIdentifier(refProp.value.expression)
49
62
  const binding = path.scope.getBinding(refProp.value.expression.name)
@@ -55,23 +68,38 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
55
68
  [t.identifier(uniqueRefName)],
56
69
  t.blockStatement([
57
70
  t.expressionStatement(
58
- t.assignmentExpression('=', t.identifier(userVariableName), t.identifier(uniqueRefName))
71
+ t.assignmentExpression(
72
+ '=',
73
+ t.memberExpression(t.identifier(userVariableName), t.identifier('current')),
74
+ t.identifier(uniqueRefName)
75
+ )
59
76
  ),
77
+ metadata.dynamicFunction ? t.expressionStatement(
78
+ t.callExpression(
79
+ metadata.dynamicFunction.callee,
80
+ metadata.dynamicFunction.arguments.concat(t.identifier(uniqueRefName))
81
+ )
82
+ ) : null,
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
+ [
88
+ t.identifier(uniqueRefName),
89
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
90
+ t.identifier(hasVariants ? '__uni__variants' : '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
+ [t.identifier(uniqueRefName), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
71
99
  )
72
100
  )
73
101
  )
74
- ])
102
+ ].filter(Boolean))
75
103
  )
76
104
 
77
105
  refProp.value = t.jsxExpressionContainer(newRefFunction)
@@ -92,10 +120,20 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
92
120
  [t.identifier('ref')],
93
121
  t.blockStatement([
94
122
  ...userStatements.filter(statement => !t.isReturnStatement(statement)),
123
+ metadata.dynamicFunction ? t.expressionStatement(
124
+ t.callExpression(
125
+ metadata.dynamicFunction.callee,
126
+ metadata.dynamicFunction.arguments.concat(t.identifier('ref'))
127
+ )
128
+ ) : null,
95
129
  t.expressionStatement(
96
130
  t.callExpression(
97
131
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
98
- [t.identifier('ref'), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
132
+ [
133
+ t.identifier('ref'),
134
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
135
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined')
136
+ ]
99
137
  )
100
138
  ),
101
139
  // Merged cleanup function
@@ -109,12 +147,12 @@ 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
+ [t.identifier('ref'), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
113
151
  )
114
152
  )
115
153
  ]))
116
154
  )
117
- ])
155
+ ].filter(Boolean))
118
156
  )
119
157
 
120
158
  refProp.value = t.jsxExpressionContainer(newRefFunction)
@@ -122,6 +160,10 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
122
160
  return
123
161
  }
124
162
 
163
+ if (!binding) {
164
+ return
165
+ }
166
+
125
167
  // ref={scopedFunction}
126
168
  const isArrowFunction = t.isArrowFunctionExpression(binding.path.node.init)
127
169
  const isFunction = t.isFunctionDeclaration(binding.path.node)
@@ -143,10 +185,20 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
143
185
  t.expressionStatement(
144
186
  t.callExpression(userFunctionName, [t.identifier(uniqueRefName)])
145
187
  ),
188
+ metadata.dynamicFunction ? t.expressionStatement(
189
+ t.callExpression(
190
+ metadata.dynamicFunction.callee,
191
+ metadata.dynamicFunction.arguments.concat(t.identifier(uniqueRefName))
192
+ )
193
+ ) : null,
146
194
  t.expressionStatement(
147
195
  t.callExpression(
148
196
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
149
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
197
+ [
198
+ t.identifier(uniqueRefName),
199
+ t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp)),
200
+ t.identifier(hasVariants ? '__uni__variants' : 'undefined')
201
+ ]
150
202
  )
151
203
  ),
152
204
  t.returnStatement(
@@ -159,12 +211,12 @@ function overrideRef(t, path, refProp, styleObj, styleProp) {
159
211
  t.expressionStatement(
160
212
  t.callExpression(
161
213
  t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('remove')),
162
- [t.identifier(uniqueRefName), t.memberExpression(t.identifier(styleObj), t.identifier(styleProp))]
214
+ [t.identifier(uniqueRefName), t.memberExpression(t.identifier(metadata.styleObj), t.identifier(metadata.styleProp))]
163
215
  )
164
216
  )
165
217
  ]))
166
218
  )
167
- ])
219
+ ].filter(Boolean))
168
220
  )
169
221
 
170
222
  refProp.value = t.jsxExpressionContainer(newRefFunction)
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
  }