react-native-unistyles 3.0.0-alpha.6 → 3.0.0-alpha.8
Sign up to get free protection for your applications and to get access to all the features.
- package/cxx/common/Helpers.h +24 -0
- package/cxx/core/HostStyle.cpp +4 -5
- package/cxx/core/HostStyle.h +4 -0
- package/cxx/core/StyleSheet.h +0 -1
- package/cxx/core/StyleSheetRegistry.cpp +9 -17
- package/cxx/core/StyleSheetRegistry.h +3 -4
- package/cxx/core/UnistyleData.h +22 -0
- package/cxx/core/UnistylesCommitHook.cpp +4 -1
- package/cxx/core/UnistylesRegistry.cpp +33 -49
- package/cxx/core/UnistylesRegistry.h +8 -8
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +4 -3
- package/cxx/hybridObjects/HybridStyleSheet.cpp +8 -11
- package/cxx/parser/Parser.cpp +41 -57
- package/cxx/parser/Parser.h +8 -13
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/index.web.js +1 -1
- package/lib/commonjs/web/convert/boxShadow.js +77 -0
- package/lib/commonjs/web/convert/boxShadow.js.map +1 -0
- package/lib/commonjs/web/convert/breakpoint.js +25 -0
- package/lib/commonjs/web/convert/breakpoint.js.map +1 -0
- package/lib/commonjs/web/convert/index.js +76 -0
- package/lib/commonjs/web/convert/index.js.map +1 -0
- package/lib/commonjs/web/convert/module.d.js +2 -0
- package/lib/commonjs/web/convert/module.d.js.map +1 -0
- package/lib/commonjs/web/convert/shadow.js +68 -0
- package/lib/commonjs/web/convert/shadow.js.map +1 -0
- package/lib/commonjs/web/convert/style.js +89 -0
- package/lib/commonjs/web/convert/style.js.map +1 -0
- package/lib/commonjs/web/convert/textShadow.js +73 -0
- package/lib/commonjs/web/convert/textShadow.js.map +1 -0
- package/lib/commonjs/web/convert/transform.js +72 -0
- package/lib/commonjs/web/convert/transform.js.map +1 -0
- package/lib/commonjs/web/convert/types.js +9 -0
- package/lib/commonjs/web/convert/types.js.map +1 -0
- package/lib/commonjs/web/convert/utils.js +55 -0
- package/lib/commonjs/web/convert/utils.js.map +1 -0
- package/lib/commonjs/web/create.js +89 -0
- package/lib/commonjs/web/create.js.map +1 -0
- package/lib/commonjs/web/index.js +51 -0
- package/lib/commonjs/web/index.js.map +1 -0
- package/lib/commonjs/web/listener/index.js +13 -0
- package/lib/commonjs/web/listener/index.js.map +1 -0
- package/lib/commonjs/web/listener/listener.js +36 -0
- package/lib/commonjs/web/listener/listener.js.map +1 -0
- package/lib/commonjs/web/mock.js +37 -0
- package/lib/commonjs/web/mock.js.map +1 -0
- package/lib/commonjs/web/mq.js +23 -0
- package/lib/commonjs/web/mq.js.map +1 -0
- package/lib/commonjs/web/pseudo.js +11 -0
- package/lib/commonjs/web/pseudo.js.map +1 -0
- package/lib/commonjs/web/registry.js +37 -0
- package/lib/commonjs/web/registry.js.map +1 -0
- package/lib/commonjs/web/runtime.js +164 -0
- package/lib/commonjs/web/runtime.js.map +1 -0
- package/lib/commonjs/web/state.js +121 -0
- package/lib/commonjs/web/state.js.map +1 -0
- package/lib/commonjs/web/utils.js +78 -0
- package/lib/commonjs/web/utils.js.map +1 -0
- package/lib/commonjs/web/variants/getVariants.js +39 -0
- package/lib/commonjs/web/variants/getVariants.js.map +1 -0
- package/lib/commonjs/web/variants/index.js +28 -0
- package/lib/commonjs/web/variants/index.js.map +1 -0
- package/lib/commonjs/web/variants/useVariants.js +75 -0
- package/lib/commonjs/web/variants/useVariants.js.map +1 -0
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/index.web.js +1 -1
- package/lib/module/specs/index.web.js.map +1 -1
- package/lib/module/web/convert/boxShadow.js +72 -0
- package/lib/module/web/convert/boxShadow.js.map +1 -0
- package/lib/module/web/convert/breakpoint.js +20 -0
- package/lib/module/web/convert/breakpoint.js.map +1 -0
- package/lib/module/web/convert/index.js +71 -0
- package/lib/module/web/convert/index.js.map +1 -0
- package/lib/module/web/convert/module.d.js +2 -0
- package/lib/module/web/convert/module.d.js.map +1 -0
- package/lib/module/web/convert/shadow.js +63 -0
- package/lib/module/web/convert/shadow.js.map +1 -0
- package/lib/module/web/convert/style.js +84 -0
- package/lib/module/web/convert/style.js.map +1 -0
- package/lib/module/web/convert/textShadow.js +68 -0
- package/lib/module/web/convert/textShadow.js.map +1 -0
- package/lib/module/web/convert/transform.js +67 -0
- package/lib/module/web/convert/transform.js.map +1 -0
- package/lib/module/web/convert/types.js +5 -0
- package/lib/module/web/convert/types.js.map +1 -0
- package/lib/module/web/convert/utils.js +43 -0
- package/lib/module/web/convert/utils.js.map +1 -0
- package/lib/module/web/create.js +84 -0
- package/lib/module/web/create.js.map +1 -0
- package/lib/module/web/index.js +24 -0
- package/lib/module/web/index.js.map +1 -0
- package/lib/module/web/listener/index.js +4 -0
- package/lib/module/web/listener/index.js.map +1 -0
- package/lib/module/web/listener/listener.js +31 -0
- package/lib/module/web/listener/listener.js.map +1 -0
- package/lib/module/web/mock.js +33 -0
- package/lib/module/web/mock.js.map +1 -0
- package/lib/module/web/mq.js +17 -0
- package/lib/module/web/mq.js.map +1 -0
- package/lib/module/web/pseudo.js +6 -0
- package/lib/module/web/pseudo.js.map +1 -0
- package/lib/module/web/registry.js +33 -0
- package/lib/module/web/registry.js.map +1 -0
- package/lib/module/web/runtime.js +160 -0
- package/lib/module/web/runtime.js.map +1 -0
- package/lib/module/web/state.js +117 -0
- package/lib/module/web/state.js.map +1 -0
- package/lib/module/web/utils.js +65 -0
- package/lib/module/web/utils.js.map +1 -0
- package/lib/module/web/variants/getVariants.js +34 -0
- package/lib/module/web/variants/getVariants.js.map +1 -0
- package/lib/module/web/variants/index.js +5 -0
- package/lib/module/web/variants/index.js.map +1 -0
- package/lib/module/web/variants/useVariants.js +70 -0
- package/lib/module/web/variants/useVariants.js.map +1 -0
- package/lib/typescript/example/App.d.ts.map +1 -1
- package/lib/typescript/example/Typography.d.ts +11 -0
- package/lib/typescript/example/Typography.d.ts.map +1 -0
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts +2 -2
- package/lib/typescript/src/specs/ShadowRegistry/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts +2 -1
- package/lib/typescript/src/specs/StyleSheet/index.d.ts.map +1 -1
- package/lib/typescript/src/specs/index.web.d.ts +1 -1
- package/lib/typescript/src/specs/index.web.d.ts.map +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts +1 -1
- package/lib/typescript/src/types/stylesheet.d.ts.map +1 -1
- package/lib/typescript/src/web/convert/boxShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/breakpoint.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/index.d.ts +1 -1
- package/lib/typescript/src/web/convert/index.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/shadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/style.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/textShadow.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/transform.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/convert/types.d.ts +1 -1
- package/lib/typescript/src/web/convert/types.d.ts.map +1 -0
- package/lib/typescript/src/web/convert/utils.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/create.d.ts +11 -11
- package/lib/typescript/{web → src/web}/create.d.ts.map +1 -1
- package/lib/typescript/{web → src/web}/index.d.ts +12 -12
- package/lib/typescript/{web → src/web}/index.d.ts.map +1 -1
- package/lib/typescript/src/web/listener/index.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/listener/listener.d.ts +1 -1
- package/lib/typescript/src/web/listener/listener.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/mock.d.ts +2 -2
- package/lib/typescript/src/web/mock.d.ts.map +1 -0
- package/lib/typescript/src/web/mq.d.ts.map +1 -0
- package/lib/typescript/src/web/pseudo.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/registry.d.ts +1 -1
- package/lib/typescript/src/web/registry.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/runtime.d.ts +6 -6
- package/lib/typescript/src/web/runtime.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/state.d.ts +4 -4
- package/lib/typescript/src/web/state.d.ts.map +1 -0
- package/lib/typescript/{web → src/web}/utils.d.ts +5 -3
- package/lib/typescript/src/web/utils.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/getVariants.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/index.d.ts +3 -0
- package/lib/typescript/src/web/variants/index.d.ts.map +1 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts +3 -0
- package/lib/typescript/src/web/variants/useVariants.d.ts.map +1 -0
- package/package.json +1 -1
- package/plugin/__tests__/dependencies.spec.js +181 -103
- package/plugin/__tests__/ref.spec.js +346 -156
- package/plugin/__tests__/stylesheet.spec.js +148 -55
- package/plugin/index.js +31 -21
- package/plugin/ref.js +67 -15
- package/plugin/style.js +13 -24
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/specs/ShadowRegistry/index.ts +4 -4
- package/src/specs/StyleSheet/index.ts +3 -1
- package/src/specs/index.web.ts +1 -1
- package/src/types/stylesheet.ts +1 -1
- package/{web → src/web}/convert/breakpoint.ts +1 -1
- package/{web → src/web}/convert/index.ts +1 -1
- package/{web → src/web}/convert/types.ts +1 -1
- package/{web → src/web}/create.ts +36 -33
- package/{web → src/web}/listener/listener.ts +1 -1
- package/{web → src/web}/mock.ts +2 -2
- package/{web → src/web}/registry.ts +1 -1
- package/{web → src/web}/runtime.ts +4 -4
- package/{web → src/web}/state.ts +5 -5
- package/{web → src/web}/utils.ts +5 -5
- package/src/web/variants/getVariants.ts +42 -0
- package/src/web/variants/index.ts +2 -0
- package/{web → src/web/variants}/useVariants.ts +24 -44
- package/lib/typescript/web/convert/boxShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/breakpoint.d.ts.map +0 -1
- package/lib/typescript/web/convert/index.d.ts.map +0 -1
- package/lib/typescript/web/convert/shadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/style.d.ts.map +0 -1
- package/lib/typescript/web/convert/textShadow.d.ts.map +0 -1
- package/lib/typescript/web/convert/transform.d.ts.map +0 -1
- package/lib/typescript/web/convert/types.d.ts.map +0 -1
- package/lib/typescript/web/convert/utils.d.ts.map +0 -1
- package/lib/typescript/web/listener/index.d.ts.map +0 -1
- package/lib/typescript/web/listener/listener.d.ts.map +0 -1
- package/lib/typescript/web/mock.d.ts.map +0 -1
- package/lib/typescript/web/mq.d.ts.map +0 -1
- package/lib/typescript/web/pseudo.d.ts.map +0 -1
- package/lib/typescript/web/registry.d.ts.map +0 -1
- package/lib/typescript/web/runtime.d.ts.map +0 -1
- package/lib/typescript/web/state.d.ts.map +0 -1
- package/lib/typescript/web/useVariants.d.ts +0 -3
- package/lib/typescript/web/useVariants.d.ts.map +0 -1
- package/lib/typescript/web/utils.d.ts.map +0 -1
- /package/lib/typescript/{web → src/web}/convert/boxShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/breakpoint.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/shadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/style.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/textShadow.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/transform.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/convert/utils.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/listener/index.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/mq.d.ts +0 -0
- /package/lib/typescript/{web → src/web}/pseudo.d.ts +0 -0
- /package/{web → src/web}/convert/boxShadow.ts +0 -0
- /package/{web → src/web}/convert/module.d.ts +0 -0
- /package/{web → src/web}/convert/shadow.ts +0 -0
- /package/{web → src/web}/convert/style.ts +0 -0
- /package/{web → src/web}/convert/textShadow.ts +0 -0
- /package/{web → src/web}/convert/transform.ts +0 -0
- /package/{web → src/web}/convert/utils.ts +0 -0
- /package/{web → src/web}/index.ts +0 -0
- /package/{web → src/web}/listener/index.ts +0 -0
- /package/{web → src/web}/mq.ts +0 -0
- /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
|
-
|
55
|
-
|
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(
|
98
|
-
|
99
|
-
|
100
|
-
|
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(
|
143
|
-
|
144
|
-
|
145
|
-
|
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
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
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
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
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(
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
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(
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
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 {
|
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.
|
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
|
49
|
+
const metadata = getStyleMetadata(t, styleAttr.value.expression)
|
49
50
|
|
50
51
|
// style prop is not using object expression
|
51
|
-
if (
|
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
|
-
|
59
|
+
metadata.forEach(meta => {
|
60
|
+
const refProp = getRefProp(t, path)
|
59
61
|
|
60
|
-
|
61
|
-
|
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
|
-
|
68
|
-
|
69
|
-
|
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
|
83
|
-
|
84
|
-
|
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
|
111
|
-
|
112
|
-
|
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,
|
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
|
-
[
|
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,
|
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(
|
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
|
-
|
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
|
-
[
|
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
|
-
[
|
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
|
1
|
+
function getStyleMetadata(t, node, dynamicFunction = null) {
|
2
2
|
// {styles.container}
|
3
3
|
if (t.isMemberExpression(node)) {
|
4
|
-
return [
|
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 =>
|
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
|
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 =>
|
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
|
-
|
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
|
-
|
45
|
+
getStyleMetadata,
|
57
46
|
getStyleAttribute
|
58
47
|
}
|