Skip to content

Commit eb428d0

Browse files
committed
revise
1 parent 89b0af6 commit eb428d0

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

packages/svelte/src/internal/client/transitions.js

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -371,8 +371,6 @@ function create_transition(dom, init, direction, effect) {
371371
o() {
372372
// @ts-ignore
373373
const has_keyed_transition = dom.__animate;
374-
const needs_reverse = direction === 'both' && curr_direction !== 'out';
375-
curr_direction = 'out';
376374
// If we're outroing an element that has an animation, then we need to fix
377375
// its position to ensure it behaves nicely without causing layout shift.
378376
if (has_keyed_transition) {
@@ -388,20 +386,32 @@ function create_transition(dom, init, direction, effect) {
388386
dom.style.height = height;
389387
const b = dom.getBoundingClientRect();
390388
if (a.left !== b.left || a.top !== b.top) {
391-
// Previously, in the Svelte 4, we'd just apply the transform the the DOM element. However,
392-
// because we're now using Web Animations, we can't do that as it won't work properly if the
393-
// animation is also making use of the same transformations. So instead, we apply an instantaneous
394-
// animation and pause it on the first frame, just applying the same behavior.
395-
const style = getComputedStyle(dom);
396-
const transform = style.transform === 'none' ? '' : style.transform;
397-
const frame = {
398-
transform: `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`
399-
};
400-
const animation = dom.animate([frame, frame], { duration: 1 });
401-
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+
}
402410
}
403411
}
404412
}
413+
const needs_reverse = direction === 'both' && curr_direction !== 'out';
414+
curr_direction = 'out';
405415
if (animation === null || cancelled) {
406416
cancelled = false;
407417
create_animation();

0 commit comments

Comments
 (0)