@ -138,7 +138,7 @@ export function transition(flags, element, get_fn, get_params) {
/** @type {'in' | 'out' | 'both'} */
/** @type {'in' | 'out' | 'both'} */
var direction = is _intro && is _outro ? 'both' : is _intro ? 'in' : 'out' ;
var direction = is _intro && is _outro ? 'both' : is _intro ? 'in' : 'out' ;
/** @type {import('#client'). TransitionConfig | ((opts: { direction: 'in' | 'out' }) => import('#client').Transi tionConfig) | undefined} */
/** @type {import('#client'). AnimationConfig | ((opts: { direction: 'in' | 'out' }) => import('#client').Anima tionConfig) | undefined} */
var current _options ;
var current _options ;
var inert = element . inert ;
var inert = element . inert ;
@ -183,6 +183,8 @@ export function transition(flags, element, get_fn, get_params) {
fn ? . ( ) ;
fn ? . ( ) ;
} ) ;
} ) ;
// TODO arguably the outro should never null itself out until _all_ outros for this effect have completed...
// in that case we wouldn't need to store `reset` separately
reset = outro . reset ;
reset = outro . reset ;
} else {
} else {
fn ? . ( ) ;
fn ? . ( ) ;
@ -213,15 +215,19 @@ export function transition(flags, element, get_fn, get_params) {
}
}
/ * *
/ * *
* Animates an element , according to the provided configuration
* @ param { Element } element
* @ param { Element } element
* @ param { import ( '#client' ) . Transi tionConfig | ( ( opts : { direction : 'in' | 'out' } ) => import ( '#client' ) . Transi tionConfig) } options
* @ param { import ( '#client' ) . Anima tionConfig | ( ( opts : { direction : 'in' | 'out' } ) => import ( '#client' ) . Anima tionConfig) } options
* @ param { import ( '#client' ) . Animation | undefined } counterpart
* @ param { import ( '#client' ) . Animation | undefined } counterpart The corresponding intro / outro to this outro / intro
* @ param { number } t2
* @ param { number } t2 The target ` t ` value — ` 1 ` for intro , ` 0 ` for outro
* @ param { ( ( ) => void ) | undefined } callback
* @ param { ( ( ) => void ) | undefined } callback
* @ returns { import ( '#client' ) . Animation }
* @ returns { import ( '#client' ) . Animation }
* /
* /
function animate ( element , options , counterpart , t2 , callback ) {
function animate ( element , options , counterpart , t2 , callback ) {
if ( is _function ( options ) ) {
if ( is _function ( options ) ) {
// In the case of a deferred transition (such as `crossfade`), `option` will be
// a function rather than an `AnimationConfig`. We need to call this function
// once DOM has been updated...
/** @type {import('#client').Animation} */
/** @type {import('#client').Animation} */
var a ;
var a ;
@ -230,23 +236,25 @@ function animate(element, options, counterpart, t2, callback) {
a = animate ( element , o , counterpart , t2 , callback ) ;
a = animate ( element , o , counterpart , t2 , callback ) ;
} ) ;
} ) ;
// ...but we want to do so without using `async`/`await` everywhere, so
// we return a facade that allows everything to remain synchronous
return {
return {
abort : ( ) => a . abort ( ) ,
abort : ( ) => a . abort ( ) ,
neuter: ( ) => a . neuter ( ) ,
deactivate: ( ) => a . deactivate ( ) ,
reset : ( ) => a . reset ( ) ,
reset : ( ) => a . reset ( ) ,
p: ( now ) => a . p ( now )
t: ( now ) => a . t ( now )
} ;
} ;
}
}
counterpart ? . neuter ( ) ;
counterpart ? . deactivate ( ) ;
if ( ! options ? . duration ) {
if ( ! options ? . duration ) {
callback ? . ( ) ;
callback ? . ( ) ;
return {
return {
abort : noop ,
abort : noop ,
neuter : noop ,
deactivate : noop ,
reset : noop ,
reset : noop ,
p : ( ) => t2
t : ( ) => t2
} ;
} ;
}
}
@ -255,7 +263,7 @@ function animate(element, options, counterpart, t2, callback) {
var { delay = 0 , duration , css , tick , easing = linear } = options ;
var { delay = 0 , duration , css , tick , easing = linear } = options ;
var start = raf . now ( ) + delay ;
var start = raf . now ( ) + delay ;
var t1 = counterpart ? . p ( start ) ? ? 1 - t2 ;
var t1 = counterpart ? . t ( start ) ? ? 1 - t2 ;
var delta = t2 - t1 ;
var delta = t2 - t1 ;
duration *= Math . abs ( delta ) ;
duration *= Math . abs ( delta ) ;
@ -319,7 +327,7 @@ function animate(element, options, counterpart, t2, callback) {
animation ? . cancel ( ) ;
animation ? . cancel ( ) ;
task ? . abort ( ) ;
task ? . abort ( ) ;
} ,
} ,
neuter : ( ) => {
deactivate : ( ) => {
callback = undefined ;
callback = undefined ;
} ,
} ,
reset : ( ) => {
reset : ( ) => {
@ -327,7 +335,7 @@ function animate(element, options, counterpart, t2, callback) {
tick ? . ( 1 , 0 ) ;
tick ? . ( 1 , 0 ) ;
}
}
} ,
} ,
p : ( now ) => {
t : ( now ) => {
var t = t1 + delta * easing ( ( now - start ) / duration ) ;
var t = t1 + delta * easing ( ( now - start ) / duration ) ;
return Math . min ( 1 , Math . max ( 0 , t ) ) ;
return Math . min ( 1 , Math . max ( 0 , t ) ) ;
}
}