@@ -371,22 +371,6 @@ function create_transition(dom, init, direction, effect) {
371
371
o ( ) {
372
372
// @ts -ignore
373
373
const has_keyed_transition = dom . __animate ;
374
- const needs_reverse = direction === 'both' && curr_direction !== 'out' ;
375
- curr_direction = 'out' ;
376
- if ( animation === null || cancelled ) {
377
- cancelled = false ;
378
- create_animation ( ) ;
379
- }
380
- if ( animation === null ) {
381
- transition . x ( ) ;
382
- } else {
383
- dispatch_event ( dom , 'outrostart' ) ;
384
- if ( needs_reverse ) {
385
- /** @type {Animation | TickAnimation } */ ( animation ) . reverse ( ) ;
386
- } else {
387
- /** @type {Animation | TickAnimation } */ ( animation ) . play ( ) ;
388
- }
389
- }
390
374
// If we're outroing an element that has an animation, then we need to fix
391
375
// its position to ensure it behaves nicely without causing layout shift.
392
376
if ( has_keyed_transition ) {
@@ -402,20 +386,46 @@ function create_transition(dom, init, direction, effect) {
402
386
dom . style . height = height ;
403
387
const b = dom . getBoundingClientRect ( ) ;
404
388
if ( a . left !== b . left || a . top !== b . top ) {
405
- // Previously, in the Svelte 4, we'd just apply the transform the the DOM element. However,
406
- // because we're now using Web Animations, we can't do that as it won't work properly if the
407
- // animation is also making use of the same transformations. So instead, we apply an instantaneous
408
- // animation and pause it on the first frame, just applying the same behavior.
409
- const style = getComputedStyle ( dom ) ;
410
- const transform = style . transform === 'none' ? '' : style . transform ;
411
- const frame = {
412
- transform : `${ transform } translate(${ a . left - b . left } px, ${ a . top - b . top } px)`
413
- } ;
414
- const animation = dom . animate ( [ frame , frame ] , { duration : 1 } ) ;
415
- animation . pause ( ) ;
389
+ const translate = `translate(${ a . left - b . left } px, ${ a . top - b . top } px)` ;
390
+ const existing_transform = style . transform ;
391
+ if ( existing_transform === 'none' ) {
392
+ dom . style . transform = translate ;
393
+ } else {
394
+ // Previously, in the Svelte 4, we'd just apply the transform the the DOM element. However,
395
+ // because we're now using Web Animations, we can't do that as it won't work properly if the
396
+ // animation is also making use of the same transformations. So instead, we apply an
397
+ // instantaneous animation and pause it on the first frame, just applying the same behavior.
398
+ // We also need to take into consideration matrix transforms and how they might combine with
399
+ // an existing behavior that is already in progress (such as scale).
400
+ // > Follow the white rabbit.
401
+ const transform = existing_transform . startsWith ( 'matrix(1,' )
402
+ ? translate
403
+ : `matrix(1,0,0,1,0,0)` ;
404
+ const frame = {
405
+ transform
406
+ } ;
407
+ const animation = dom . animate ( [ frame , frame ] , { duration : 1 } ) ;
408
+ animation . pause ( ) ;
409
+ }
416
410
}
417
411
}
418
412
}
413
+ const needs_reverse = direction === 'both' && curr_direction !== 'out' ;
414
+ curr_direction = 'out' ;
415
+ if ( animation === null || cancelled ) {
416
+ cancelled = false ;
417
+ create_animation ( ) ;
418
+ }
419
+ if ( animation === null ) {
420
+ transition . x ( ) ;
421
+ } else {
422
+ dispatch_event ( dom , 'outrostart' ) ;
423
+ if ( needs_reverse ) {
424
+ /** @type {Animation | TickAnimation } */ ( animation ) . reverse ( ) ;
425
+ } else {
426
+ /** @type {Animation | TickAnimation } */ ( animation ) . play ( ) ;
427
+ }
428
+ }
419
429
} ,
420
430
// cancel
421
431
c ( ) {
@@ -584,14 +594,15 @@ export function trigger_transitions(transitions, target_direction, from) {
584
594
const outros = [ ] ;
585
595
for ( const transition of transitions ) {
586
596
const direction = transition . r ;
597
+ const effect = transition . e ;
587
598
if ( target_direction === 'in' ) {
588
599
if ( direction === 'in' || direction === 'both' ) {
589
600
transition . in ( ) ;
590
601
} else {
591
602
transition . c ( ) ;
592
603
}
593
604
transition . d . inert = false ;
594
- mark_subtree_inert ( transition . e , false ) ;
605
+ mark_subtree_inert ( effect , effect , false ) ;
595
606
} else if ( target_direction === 'key' ) {
596
607
if ( direction === 'key' ) {
597
608
transition . p = transition . i ( /** @type {DOMRect } */ ( from ) ) ;
@@ -603,7 +614,7 @@ export function trigger_transitions(transitions, target_direction, from) {
603
614
outros . push ( transition . o ) ;
604
615
}
605
616
transition . d . inert = true ;
606
- mark_subtree_inert ( transition . e , true ) ;
617
+ mark_subtree_inert ( effect , effect , true ) ;
607
618
}
608
619
}
609
620
if ( outros . length > 0 ) {
0 commit comments