@@ -204,21 +204,22 @@ interface CrossfadeParams {
204
204
easing : EasingFunction ;
205
205
}
206
206
207
- type ClientRectMap = Map < any , { rect : ClientRect } > ;
207
+ type ElementMap = Map < any , { node : Element } > ;
208
208
209
209
export function crossfade ( { fallback, ...defaults } : CrossfadeParams & {
210
210
fallback : ( node : Element , params : CrossfadeParams , intro : boolean ) => TransitionConfig ;
211
211
} ) {
212
- const to_receive : ClientRectMap = new Map ( ) ;
213
- const to_send : ClientRectMap = new Map ( ) ;
212
+ const to_receive : ElementMap = new Map ( ) ;
213
+ const to_send : ElementMap = new Map ( ) ;
214
214
215
- function crossfade ( from : ClientRect , node : Element , params : CrossfadeParams ) : TransitionConfig {
215
+ function crossfade ( from_node : Element , node : Element , params : CrossfadeParams ) : TransitionConfig {
216
216
const {
217
217
delay = 0 ,
218
218
duration = d => Math . sqrt ( d ) * 30 ,
219
219
easing = cubicOut
220
220
} = assign ( assign ( { } , defaults ) , params ) ;
221
221
222
+ const from = from_node . getBoundingClientRect ( ) ;
222
223
const to = node . getBoundingClientRect ( ) ;
223
224
const dx = from . left - to . left ;
224
225
const dy = from . top - to . top ;
@@ -242,18 +243,16 @@ export function crossfade({ fallback, ...defaults }: CrossfadeParams & {
242
243
} ;
243
244
}
244
245
245
- function transition ( items : ClientRectMap , counterparts : ClientRectMap , intro : boolean ) {
246
+ function transition ( items : ElementMap , counterparts : ElementMap , intro : boolean ) {
246
247
return ( node : Element , params : CrossfadeParams & { key : any } ) => {
247
- items . set ( params . key , {
248
- rect : node . getBoundingClientRect ( )
249
- } ) ;
248
+ items . set ( params . key , { node } ) ;
250
249
251
250
return ( ) => {
252
251
if ( counterparts . has ( params . key ) ) {
253
- const { rect } = counterparts . get ( params . key ) ;
252
+ const from_node = counterparts . get ( params . key ) . node ;
254
253
counterparts . delete ( params . key ) ;
255
254
256
- return crossfade ( rect , node , params ) ;
255
+ return crossfade ( from_node , node , params ) ;
257
256
}
258
257
259
258
// if the node is disappearing altogether
0 commit comments