|
|
|
|
@ -75,20 +75,17 @@ export function transition_in(block, local) {
|
|
|
|
|
*/
|
|
|
|
|
export function transition_out(block, local, detach, callback) {
|
|
|
|
|
if (block && block.o) {
|
|
|
|
|
if (outroing.has(block))
|
|
|
|
|
return;
|
|
|
|
|
if (outroing.has(block)) return;
|
|
|
|
|
outroing.add(block);
|
|
|
|
|
outros.c.push(() => {
|
|
|
|
|
outroing.delete(block);
|
|
|
|
|
if (callback) {
|
|
|
|
|
if (detach)
|
|
|
|
|
block.d(1);
|
|
|
|
|
if (detach) block.d(1);
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
block.o(local);
|
|
|
|
|
}
|
|
|
|
|
else if (callback) {
|
|
|
|
|
} else if (callback) {
|
|
|
|
|
callback();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -104,7 +101,6 @@ const null_transition = { duration: 0 };
|
|
|
|
|
* @returns {{ start(): void; invalidate(): void; end(): void; }}
|
|
|
|
|
*/
|
|
|
|
|
export function create_in_transition(node, fn, params) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {TransitionOptions} */
|
|
|
|
|
const options = { direction: 'in' };
|
|
|
|
|
@ -117,21 +113,24 @@ export function create_in_transition(node, fn, params) {
|
|
|
|
|
/**
|
|
|
|
|
* @returns {void} */
|
|
|
|
|
function cleanup() {
|
|
|
|
|
if (animation_name)
|
|
|
|
|
delete_rule(node, animation_name);
|
|
|
|
|
if (animation_name) delete_rule(node, animation_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @returns {void} */
|
|
|
|
|
function go() {
|
|
|
|
|
const { delay = 0, duration = 300, easing = linear, tick = noop, css } = config || null_transition;
|
|
|
|
|
if (css)
|
|
|
|
|
animation_name = create_rule(node, 0, 1, duration, delay, easing, css, uid++);
|
|
|
|
|
const {
|
|
|
|
|
delay = 0,
|
|
|
|
|
duration = 300,
|
|
|
|
|
easing = linear,
|
|
|
|
|
tick = noop,
|
|
|
|
|
css
|
|
|
|
|
} = config || null_transition;
|
|
|
|
|
if (css) animation_name = create_rule(node, 0, 1, duration, delay, easing, css, uid++);
|
|
|
|
|
tick(0, 1);
|
|
|
|
|
const start_time = now() + delay;
|
|
|
|
|
const end_time = start_time + duration;
|
|
|
|
|
if (task)
|
|
|
|
|
task.abort();
|
|
|
|
|
if (task) task.abort();
|
|
|
|
|
running = true;
|
|
|
|
|
add_render_callback(() => dispatch(node, true, 'start'));
|
|
|
|
|
task = loop((now) => {
|
|
|
|
|
@ -153,15 +152,13 @@ export function create_in_transition(node, fn, params) {
|
|
|
|
|
let started = false;
|
|
|
|
|
return {
|
|
|
|
|
start() {
|
|
|
|
|
if (started)
|
|
|
|
|
return;
|
|
|
|
|
if (started) return;
|
|
|
|
|
started = true;
|
|
|
|
|
delete_rule(node);
|
|
|
|
|
if (is_function(config)) {
|
|
|
|
|
config = config(options);
|
|
|
|
|
wait().then(go);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
go();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
@ -184,7 +181,6 @@ export function create_in_transition(node, fn, params) {
|
|
|
|
|
* @returns {{ end(reset: any): void; }}
|
|
|
|
|
*/
|
|
|
|
|
export function create_out_transition(node, fn, params) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {TransitionOptions} */
|
|
|
|
|
const options = { direction: 'out' };
|
|
|
|
|
@ -197,9 +193,14 @@ export function create_out_transition(node, fn, params) {
|
|
|
|
|
/**
|
|
|
|
|
* @returns {void} */
|
|
|
|
|
function go() {
|
|
|
|
|
const { delay = 0, duration = 300, easing = linear, tick = noop, css } = config || null_transition;
|
|
|
|
|
if (css)
|
|
|
|
|
animation_name = create_rule(node, 1, 0, duration, delay, easing, css);
|
|
|
|
|
const {
|
|
|
|
|
delay = 0,
|
|
|
|
|
duration = 300,
|
|
|
|
|
easing = linear,
|
|
|
|
|
tick = noop,
|
|
|
|
|
css
|
|
|
|
|
} = config || null_transition;
|
|
|
|
|
if (css) animation_name = create_rule(node, 1, 0, duration, delay, easing, css);
|
|
|
|
|
const start_time = now() + delay;
|
|
|
|
|
const end_time = start_time + duration;
|
|
|
|
|
add_render_callback(() => dispatch(node, false, 'start'));
|
|
|
|
|
@ -229,8 +230,7 @@ export function create_out_transition(node, fn, params) {
|
|
|
|
|
config = config(options);
|
|
|
|
|
go();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
go();
|
|
|
|
|
}
|
|
|
|
|
return {
|
|
|
|
|
@ -239,8 +239,7 @@ export function create_out_transition(node, fn, params) {
|
|
|
|
|
config.tick(1, 0);
|
|
|
|
|
}
|
|
|
|
|
if (running) {
|
|
|
|
|
if (animation_name)
|
|
|
|
|
delete_rule(node, animation_name);
|
|
|
|
|
if (animation_name) delete_rule(node, animation_name);
|
|
|
|
|
running = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -255,7 +254,6 @@ export function create_out_transition(node, fn, params) {
|
|
|
|
|
* @returns {{ run(b: 0 | 1): void; end(): void; }}
|
|
|
|
|
*/
|
|
|
|
|
export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {TransitionOptions} */
|
|
|
|
|
const options = { direction: 'both' };
|
|
|
|
|
@ -274,8 +272,7 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
/**
|
|
|
|
|
* @returns {void} */
|
|
|
|
|
function clear_animation() {
|
|
|
|
|
if (animation_name)
|
|
|
|
|
delete_rule(node, animation_name);
|
|
|
|
|
if (animation_name) delete_rule(node, animation_name);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@ -284,7 +281,7 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
* @returns {Program}
|
|
|
|
|
*/
|
|
|
|
|
function init(program, duration) {
|
|
|
|
|
const d = (program.b - t);
|
|
|
|
|
const d = program.b - t;
|
|
|
|
|
duration *= Math.abs(d);
|
|
|
|
|
return {
|
|
|
|
|
a: t,
|
|
|
|
|
@ -302,7 +299,13 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
* @returns {void}
|
|
|
|
|
*/
|
|
|
|
|
function go(b) {
|
|
|
|
|
const { delay = 0, duration = 300, easing = linear, tick = noop, css } = config || null_transition;
|
|
|
|
|
const {
|
|
|
|
|
delay = 0,
|
|
|
|
|
duration = 300,
|
|
|
|
|
easing = linear,
|
|
|
|
|
tick = noop,
|
|
|
|
|
css
|
|
|
|
|
} = config || null_transition;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @type {PendingProgram} */
|
|
|
|
|
@ -317,16 +320,14 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
}
|
|
|
|
|
if (running_program || pending_program) {
|
|
|
|
|
pending_program = program;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
// if this is an intro, and there's a delay, we need to do
|
|
|
|
|
// an initial tick and/or apply CSS animation immediately
|
|
|
|
|
if (css) {
|
|
|
|
|
clear_animation();
|
|
|
|
|
animation_name = create_rule(node, t, b, duration, delay, easing, css);
|
|
|
|
|
}
|
|
|
|
|
if (b)
|
|
|
|
|
tick(0, 1);
|
|
|
|
|
if (b) tick(0, 1);
|
|
|
|
|
running_program = init(program, duration);
|
|
|
|
|
add_render_callback(() => dispatch(node, b, 'start'));
|
|
|
|
|
loop((now) => {
|
|
|
|
|
@ -336,7 +337,15 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
dispatch(node, running_program.b, 'start');
|
|
|
|
|
if (css) {
|
|
|
|
|
clear_animation();
|
|
|
|
|
animation_name = create_rule(node, t, running_program.b, running_program.duration, 0, easing, config.css);
|
|
|
|
|
animation_name = create_rule(
|
|
|
|
|
node,
|
|
|
|
|
t,
|
|
|
|
|
running_program.b,
|
|
|
|
|
running_program.duration,
|
|
|
|
|
0,
|
|
|
|
|
easing,
|
|
|
|
|
config.css
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if (running_program) {
|
|
|
|
|
@ -348,16 +357,13 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
if (running_program.b) {
|
|
|
|
|
// intro — we can tidy up immediately
|
|
|
|
|
clear_animation();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
// outro — needs to be coordinated
|
|
|
|
|
if (!--running_program.group.r)
|
|
|
|
|
run_all(running_program.group.c);
|
|
|
|
|
if (!--running_program.group.r) run_all(running_program.group.c);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
running_program = null;
|
|
|
|
|
}
|
|
|
|
|
else if (now >= running_program.start) {
|
|
|
|
|
} else if (now >= running_program.start) {
|
|
|
|
|
const p = now - running_program.start;
|
|
|
|
|
t = running_program.a + running_program.d * easing(p / running_program.duration);
|
|
|
|
|
tick(t, 1 - t);
|
|
|
|
|
@ -376,8 +382,7 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
config = config(opts);
|
|
|
|
|
go(b);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
} else {
|
|
|
|
|
go(b);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
@ -388,7 +393,6 @@ export function create_bidirectional_transition(node, fn, params, intro) {
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** @typedef {1} INTRO */
|
|
|
|
|
/** @typedef {0} OUTRO */
|
|
|
|
|
/** @typedef {{ direction: 'in' | 'out' | 'both' }} TransitionOptions */
|
|
|
|
|
|