@ -163,22 +163,12 @@ export function bind_transition(element, get_fn, get_params, direction, global)
let callbacks = [ ] ;
/** @param {number} target */
function go ( target ) {
function start ( target ) {
// TODO if this is an `in:` transition and we just called `out()`, do nothing (let it play until the block is destroyed, probably immediately)
// TODO if this is an `out:` transition and we just called `in()`, abort everything and reset to 1 immediately
// TODO add a `transition.abort()` method to cancel an outro transition immediately when an effect is destroyed before the transition finishes running — don't want tickers etc to continue
if ( current _task ) {
current _task . abort ( ) ;
current _task = null ;
}
if ( current _animation && current _options ) {
const time = /** @type {number} */ ( current _animation . currentTime ) ;
const duration = /** @type {number} */ ( current _options . duration ) ;
p = ( Math . abs ( current _delta ) * time ) / duration ;
current _animation . cancel ( ) ;
}
stop ( ) ;
current _options ? ? = get _fn ( ) ( element , get _params ? . ( ) , { direction } ) ;
@ -251,6 +241,21 @@ export function bind_transition(element, get_fn, get_params, direction, global)
}
}
function stop ( ) {
if ( current _task ) {
current _task . abort ( ) ;
current _task = null ;
}
if ( current _animation && current _options ) {
const time = /** @type {number} */ ( current _animation . currentTime ) ;
const duration = /** @type {number} */ ( current _options . duration ) ;
p = ( Math . abs ( current _delta ) * time ) / duration ;
current _animation . cancel ( ) ;
current _animation = null ;
}
}
/** @type {import('#client').Transition2} */
// TODO this needs to be `in()` and `out()` rather than `to()`, and both
// need to be idempotent (because of `{#if ...}{#if ...}`). `out()` should
@ -259,19 +264,35 @@ export function bind_transition(element, get_fn, get_params, direction, global)
const transition = {
global ,
in ( ) {
if ( current _direction === TRANSITION _IN ) return ;
current _direction = TRANSITION _IN ;
callbacks = [ ] ;
go ( 1 ) ;
if ( direction === 'in' || direction === 'both' ) {
if ( current _direction !== TRANSITION _IN ) {
current _direction = TRANSITION _IN ;
start ( 1 ) ;
}
} else {
current _direction = 0 ;
stop ( ) ;
}
} ,
out ( callback ) {
if ( callback ) callbacks . push ( callback ) ;
if ( current _direction === TRANSITION _OUT ) return ;
if ( direction === 'out' || direction === 'both' ) {
if ( callback ) {
callbacks . push ( callback ) ;
}
current _direction = TRANSITION _OUT ;
go ( 0 ) ;
}
if ( current _direction !== TRANSITION _OUT ) {
current _direction = TRANSITION _OUT ;
start ( 0 ) ;
}
} else {
if ( callback ) {
callback ( ) ;
}
}
} ,
stop
} ;
( effect . transitions ? ? = [ ] ) . push ( transition ) ;