@ -1,10 +1,11 @@
import { noop , run } from '../../../common.js' ;
import { user_effect } from '../../reactivity/effects.js' ;
import { render_effect , user_effect } from '../../reactivity/effects.js' ;
import { current _effect , untrack } from '../../runtime.js' ;
import { raf } from '../../timing.js' ;
import { loop } from '../../loop.js' ;
import { run _transitions } from '../../render.js' ;
import { TRANSITION _GLOBAL , TRANSITION _IN , TRANSITION _OUT } from '../../constants.js' ;
import { is _function } from '../../utils.js' ;
const active _tick _animations = new Set ( ) ;
const DELAY _NEXT _TICK = Number . MIN _SAFE _INTEGER ;
@ -83,6 +84,15 @@ function css_to_keyframe(css) {
/** @param {number} t */
const linear = ( t ) => t ;
/** @param {() => any} fn */
function defer ( fn ) {
return new Promise ( ( fulfil ) => {
render _effect ( ( ) => {
fulfil ( fn ( ) ) ;
} ) ;
} ) ;
}
// TODO make transition mode (`in:`, `out:`, `transition:` and `|global`) a bitmask
/ * *
* @ template P
@ -121,16 +131,20 @@ export function transition(flags, element, get_fn, get_params) {
let callbacks = [ ] ;
/** @param {number} 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
async function start ( target ) {
stop ( ) ;
dispatch _event ( element , target === 1 ? 'introstart' : 'outrostart' ) ;
current _options ? ? = get _fn ( ) ( element , get _params ? . ( ) , { direction } ) ;
if ( ! current _options ) {
var result = get _fn ( ) ( element , get _params ? . ( ) , { direction } ) ;
current _options = is _function ( result )
? await defer ( ( ) =>
/** @type {Function} */ ( result ) ( { direction : target === 1 ? 'in' : 'out' } )
)
: result ;
}
if ( ! current _options ? . duration ) {
current _options = null ;