|
|
@ -371,22 +371,6 @@ function create_transition(dom, init, direction, effect) {
|
|
|
|
o() {
|
|
|
|
o() {
|
|
|
|
// @ts-ignore
|
|
|
|
// @ts-ignore
|
|
|
|
const has_keyed_transition = dom.__animate;
|
|
|
|
const has_keyed_transition = dom.__animate;
|
|
|
|
const needs_reverse = direction === 'both' && curr_direction !== 'out';
|
|
|
|
|
|
|
|
curr_direction = 'out';
|
|
|
|
|
|
|
|
if (animation === null || cancelled) {
|
|
|
|
|
|
|
|
cancelled = false;
|
|
|
|
|
|
|
|
create_animation();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animation === null) {
|
|
|
|
|
|
|
|
transition.x();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dispatch_event(dom, 'outrostart');
|
|
|
|
|
|
|
|
if (needs_reverse) {
|
|
|
|
|
|
|
|
/** @type {Animation | TickAnimation} */ (animation).reverse();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/** @type {Animation | TickAnimation} */ (animation).play();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're outroing an element that has an animation, then we need to fix
|
|
|
|
// If we're outroing an element that has an animation, then we need to fix
|
|
|
|
// its position to ensure it behaves nicely without causing layout shift.
|
|
|
|
// its position to ensure it behaves nicely without causing layout shift.
|
|
|
|
if (has_keyed_transition) {
|
|
|
|
if (has_keyed_transition) {
|
|
|
@ -402,20 +386,46 @@ function create_transition(dom, init, direction, effect) {
|
|
|
|
dom.style.height = height;
|
|
|
|
dom.style.height = height;
|
|
|
|
const b = dom.getBoundingClientRect();
|
|
|
|
const b = dom.getBoundingClientRect();
|
|
|
|
if (a.left !== b.left || a.top !== b.top) {
|
|
|
|
if (a.left !== b.left || a.top !== b.top) {
|
|
|
|
|
|
|
|
const translate = `translate(${a.left - b.left}px, ${a.top - b.top}px)`;
|
|
|
|
|
|
|
|
const existing_transform = style.transform;
|
|
|
|
|
|
|
|
if (existing_transform === 'none') {
|
|
|
|
|
|
|
|
dom.style.transform = translate;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
// Previously, in the Svelte 4, we'd just apply the transform the the DOM element. However,
|
|
|
|
// Previously, in the Svelte 4, we'd just apply the transform the the DOM element. However,
|
|
|
|
// because we're now using Web Animations, we can't do that as it won't work properly if the
|
|
|
|
// because we're now using Web Animations, we can't do that as it won't work properly if the
|
|
|
|
// animation is also making use of the same transformations. So instead, we apply an instantaneous
|
|
|
|
// animation is also making use of the same transformations. So instead, we apply an
|
|
|
|
// animation and pause it on the first frame, just applying the same behavior.
|
|
|
|
// instantaneous animation and pause it on the first frame, just applying the same behavior.
|
|
|
|
const style = getComputedStyle(dom);
|
|
|
|
// We also need to take into consideration matrix transforms and how they might combine with
|
|
|
|
const transform = style.transform === 'none' ? '' : style.transform;
|
|
|
|
// an existing behavior that is already in progress (such as scale).
|
|
|
|
|
|
|
|
// > Follow the white rabbit.
|
|
|
|
|
|
|
|
const transform = existing_transform.startsWith('matrix(1,')
|
|
|
|
|
|
|
|
? translate
|
|
|
|
|
|
|
|
: `matrix(1,0,0,1,0,0)`;
|
|
|
|
const frame = {
|
|
|
|
const frame = {
|
|
|
|
transform: `${transform} translate(${a.left - b.left}px, ${a.top - b.top}px)`
|
|
|
|
transform
|
|
|
|
};
|
|
|
|
};
|
|
|
|
const animation = dom.animate([frame, frame], { duration: 1 });
|
|
|
|
const animation = dom.animate([frame, frame], { duration: 1 });
|
|
|
|
animation.pause();
|
|
|
|
animation.pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const needs_reverse = direction === 'both' && curr_direction !== 'out';
|
|
|
|
|
|
|
|
curr_direction = 'out';
|
|
|
|
|
|
|
|
if (animation === null || cancelled) {
|
|
|
|
|
|
|
|
cancelled = false;
|
|
|
|
|
|
|
|
create_animation();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (animation === null) {
|
|
|
|
|
|
|
|
transition.x();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
dispatch_event(dom, 'outrostart');
|
|
|
|
|
|
|
|
if (needs_reverse) {
|
|
|
|
|
|
|
|
/** @type {Animation | TickAnimation} */ (animation).reverse();
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
/** @type {Animation | TickAnimation} */ (animation).play();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// cancel
|
|
|
|
// cancel
|
|
|
|
c() {
|
|
|
|
c() {
|
|
|
@ -584,6 +594,7 @@ export function trigger_transitions(transitions, target_direction, from) {
|
|
|
|
const outros = [];
|
|
|
|
const outros = [];
|
|
|
|
for (const transition of transitions) {
|
|
|
|
for (const transition of transitions) {
|
|
|
|
const direction = transition.r;
|
|
|
|
const direction = transition.r;
|
|
|
|
|
|
|
|
const effect = transition.e;
|
|
|
|
if (target_direction === 'in') {
|
|
|
|
if (target_direction === 'in') {
|
|
|
|
if (direction === 'in' || direction === 'both') {
|
|
|
|
if (direction === 'in' || direction === 'both') {
|
|
|
|
transition.in();
|
|
|
|
transition.in();
|
|
|
@ -591,7 +602,7 @@ export function trigger_transitions(transitions, target_direction, from) {
|
|
|
|
transition.c();
|
|
|
|
transition.c();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
transition.d.inert = false;
|
|
|
|
transition.d.inert = false;
|
|
|
|
mark_subtree_inert(transition.e, false);
|
|
|
|
mark_subtree_inert(effect, effect, false);
|
|
|
|
} else if (target_direction === 'key') {
|
|
|
|
} else if (target_direction === 'key') {
|
|
|
|
if (direction === 'key') {
|
|
|
|
if (direction === 'key') {
|
|
|
|
transition.p = transition.i(/** @type {DOMRect} */ (from));
|
|
|
|
transition.p = transition.i(/** @type {DOMRect} */ (from));
|
|
|
@ -603,7 +614,7 @@ export function trigger_transitions(transitions, target_direction, from) {
|
|
|
|
outros.push(transition.o);
|
|
|
|
outros.push(transition.o);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
transition.d.inert = true;
|
|
|
|
transition.d.inert = true;
|
|
|
|
mark_subtree_inert(transition.e, true);
|
|
|
|
mark_subtree_inert(effect, effect, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (outros.length > 0) {
|
|
|
|
if (outros.length > 0) {
|
|
|
|