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.
- package/Unistyles.podspec +33 -0
- package/cxx/common/Constants.h +1 -0
- package/cxx/common/Helpers.h +92 -0
- package/cxx/core/HostStyle.cpp +18 -12
- package/cxx/core/HostStyle.h +3 -0
- package/cxx/core/StyleSheet.h +0 -1
- package/cxx/core/StyleSheetRegistry.cpp +10 -13
- package/cxx/core/StyleSheetRegistry.h +4 -4
- package/cxx/core/Unistyle.h +0 -6
- package/cxx/core/UnistyleData.h +23 -0
- package/cxx/core/UnistyleWrapper.h +6 -6
- package/cxx/core/UnistylesCommitHook.cpp +8 -7
- package/cxx/core/UnistylesCommitHook.h +6 -1
- package/cxx/core/UnistylesCommitShadowNode.h +13 -0
- package/cxx/core/UnistylesMountHook.cpp +40 -0
- package/cxx/core/UnistylesMountHook.h +30 -0
- package/cxx/core/UnistylesRegistry.cpp +42 -56
- package/cxx/core/UnistylesRegistry.h +10 -8
- package/cxx/core/UnistylesState.cpp +4 -4
- package/cxx/hybridObjects/HybridShadowRegistry.cpp +8 -1
- package/cxx/hybridObjects/HybridStyleSheet.cpp +35 -39
- package/cxx/hybridObjects/HybridStyleSheet.h +9 -6
- package/cxx/hybridObjects/HybridUnistylesRuntime.cpp +34 -15
- package/cxx/hybridObjects/HybridUnistylesRuntime.h +2 -0
- package/cxx/parser/Parser.cpp +65 -137
- package/cxx/parser/Parser.h +8 -14
- package/ios/UnistylesModuleOnLoad.h +2 -0
- package/ios/UnistylesModuleOnLoad.mm +8 -1
- package/lib/commonjs/specs/NavigtionBar/index.js +1 -1
- package/lib/commonjs/specs/NavigtionBar/index.js.map +1 -1
- package/lib/commonjs/specs/ShadowRegistry/index.js +2 -2
- package/lib/commonjs/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/commonjs/specs/StatusBar/index.js +1 -1
- package/lib/commonjs/specs/StatusBar/index.js.map +1 -1
- package/lib/commonjs/specs/StyleSheet/index.js.map +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/index.js +1 -1
- package/lib/commonjs/specs/UnistylesRuntime/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/NavigtionBar/index.js +1 -1
- package/lib/module/specs/NavigtionBar/index.js.map +1 -1
- package/lib/module/specs/ShadowRegistry/index.js +2 -2
- package/lib/module/specs/ShadowRegistry/index.js.map +1 -1
- package/lib/module/specs/StatusBar/index.js +1 -1
- package/lib/module/specs/StatusBar/index.js.map +1 -1
- package/lib/module/specs/StyleSheet/index.js.map +1 -1
- package/lib/module/specs/UnistylesRuntime/index.js +1 -1
- package/lib/module/specs/UnistylesRuntime/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 +12 -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 +2 -2
- package/plugin/__tests__/dependencies.spec.js +181 -103
- package/plugin/__tests__/ref.spec.js +335 -156
- package/plugin/__tests__/stylesheet.spec.js +148 -55
- package/plugin/index.js +31 -21
- package/plugin/ref.js +43 -11
- package/plugin/style.js +13 -24
- package/plugin/stylesheet.js +44 -1
- package/plugin/variants.js +33 -0
- package/src/specs/NavigtionBar/index.ts +1 -1
- package/src/specs/ShadowRegistry/index.ts +4 -4
- package/src/specs/StatusBar/index.ts +1 -1
- package/src/specs/StyleSheet/index.ts +3 -1
- package/src/specs/UnistylesRuntime/index.ts +1 -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, 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, 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, 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, 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, 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, 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, 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, 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 {
|
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,21 +14,28 @@ 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([
|
21
23
|
t.expressionStatement(
|
22
24
|
t.callExpression(
|
23
25
|
t.memberExpression(t.identifier('UnistylesShadowRegistry'), t.identifier('add')),
|
24
|
-
[
|
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,
|
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(
|
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
|
-
|
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
|
-
[
|
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
|
-
[
|
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
|
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
|
}
|
package/plugin/stylesheet.js
CHANGED
@@ -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
|
}
|