@ -88,6 +88,9 @@ export function animation(element, get_fn, get_params) {
/** @type {import('#client').Animation | undefined} */
/** @type {import('#client').Animation | undefined} */
var animation ;
var animation ;
/** @type {null | { position: string, width: string, height: string }} */
var original _styles = null ;
item . a ? ? = {
item . a ? ? = {
element ,
element ,
measure ( ) {
measure ( ) {
@ -106,11 +109,43 @@ export function animation(element, get_fn, get_params) {
) {
) {
const options = get _fn ( ) ( this . element , { from , to } , get _params ? . ( ) ) ;
const options = get _fn ( ) ( this . element , { from , to } , get _params ? . ( ) ) ;
animation = animate ( this . element , options , false, undefined, 1 , ( ) => {
animation = animate ( this . element , options , undefined, 1 , ( ) => {
animation ? . abort ( ) ;
animation ? . abort ( ) ;
animation = undefined ;
animation = undefined ;
} ) ;
} ) ;
}
}
} ,
fix ( ) {
var computed _style = getComputedStyle ( element ) ;
if ( computed _style . position !== 'absolute' && computed _style . position !== 'fixed' ) {
var style = /** @type {HTMLElement | SVGElement} */ ( element ) . style ;
original _styles = {
position : style . position ,
width : style . width ,
height : style . height
} ;
style . position = 'absolute' ;
style . width = computed _style . width ;
style . height = computed _style . height ;
var to = element . getBoundingClientRect ( ) ;
if ( from . left !== to . left || from . top !== to . top ) {
var transform = ` translate( ${ from . left - to . left } px, ${ from . top - to . top } px) ` ;
style . transform = style . transform ? ` ${ style . transform } ${ transform } ` : transform ;
}
}
} ,
unfix ( ) {
if ( original _styles ) {
var style = /** @type {HTMLElement | SVGElement} */ ( element ) . style ;
style . position = original _styles . position ;
style . width = original _styles . width ;
style . height = original _styles . height ;
}
}
}
} ;
} ;
@ -169,7 +204,7 @@ export function transition(flags, element, get_fn, get_params) {
if ( is _intro ) {
if ( is _intro ) {
dispatch _event ( element , 'introstart' ) ;
dispatch _event ( element , 'introstart' ) ;
intro = animate ( element , get _options ( ) , false , outro , 1 , ( ) => {
intro = animate ( element , get _options ( ) , outro , 1 , ( ) => {
dispatch _event ( element , 'introend' ) ;
dispatch _event ( element , 'introend' ) ;
intro = current _options = undefined ;
intro = current _options = undefined ;
} ) ;
} ) ;
@ -178,12 +213,12 @@ export function transition(flags, element, get_fn, get_params) {
reset ? . ( ) ;
reset ? . ( ) ;
}
}
} ,
} ,
out ( fn , position _absolute = false ) {
out ( fn ) {
if ( is _outro ) {
if ( is _outro ) {
element . inert = true ;
element . inert = true ;
dispatch _event ( element , 'outrostart' ) ;
dispatch _event ( element , 'outrostart' ) ;
outro = animate ( element , get _options ( ) , position_absolute , intro, 0 , ( ) => {
outro = animate ( element , get _options ( ) , intro, 0 , ( ) => {
dispatch _event ( element , 'outroend' ) ;
dispatch _event ( element , 'outroend' ) ;
outro = current _options = undefined ;
outro = current _options = undefined ;
fn ? . ( ) ;
fn ? . ( ) ;
@ -229,13 +264,12 @@ export function transition(flags, element, get_fn, get_params) {
* Animates an element , according to the provided configuration
* Animates an element , according to the provided configuration
* @ param { Element } element
* @ param { Element } element
* @ param { import ( '#client' ) . AnimationConfig | ( ( opts : { direction : 'in' | 'out' } ) => import ( '#client' ) . AnimationConfig ) } options
* @ param { import ( '#client' ) . AnimationConfig | ( ( opts : { direction : 'in' | 'out' } ) => import ( '#client' ) . AnimationConfig ) } options
* @ param { boolean } position _absolute
* @ param { import ( '#client' ) . Animation | undefined } counterpart The corresponding intro / outro to this outro / intro
* @ param { import ( '#client' ) . Animation | undefined } counterpart The corresponding intro / outro to this outro / intro
* @ param { number } t2 The target ` t ` value — ` 1 ` for intro , ` 0 ` for outro
* @ 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 , position_absolute , 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
// 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
// a function rather than an `AnimationConfig`. We need to call this function
@ -245,7 +279,7 @@ function animate(element, options, position_absolute, counterpart, t2, callback)
effect ( ( ) => {
effect ( ( ) => {
var o = untrack ( ( ) => options ( { direction : t2 === 1 ? 'in' : 'out' } ) ) ;
var o = untrack ( ( ) => options ( { direction : t2 === 1 ? 'in' : 'out' } ) ) ;
a = animate ( element , o , position_absolute , counterpart, t2 , callback ) ;
a = animate ( element , o , counterpart, t2 , callback ) ;
} ) ;
} ) ;
// ...but we want to do so without using `async`/`await` everywhere, so
// ...but we want to do so without using `async`/`await` everywhere, so
@ -285,9 +319,6 @@ function animate(element, options, position_absolute, counterpart, t2, callback)
/** @type {import('#client').Task} */
/** @type {import('#client').Task} */
var task ;
var task ;
/** @type {null | { position: string, width: string, height: string }} */
var original _styles = null ;
if ( css ) {
if ( css ) {
// WAAPI
// WAAPI
var keyframes = [ ] ;
var keyframes = [ ] ;
@ -299,37 +330,6 @@ function animate(element, options, position_absolute, counterpart, t2, callback)
keyframes . push ( css _to _keyframe ( styles ) ) ;
keyframes . push ( css _to _keyframe ( styles ) ) ;
}
}
if ( position _absolute ) {
// we take the element out of the flow, so that sibling elements with an `animate:`
// directive can transform to the correct position
var computed _style = getComputedStyle ( element ) ;
if ( computed _style . position !== 'absolute' && computed _style . position !== 'fixed' ) {
var style = /** @type {HTMLElement | SVGElement} */ ( element ) . style ;
original _styles = {
position : style . position ,
width : style . width ,
height : style . height
} ;
var rect _a = element . getBoundingClientRect ( ) ;
style . position = 'absolute' ;
style . width = computed _style . width ;
style . height = computed _style . height ;
var rect _b = element . getBoundingClientRect ( ) ;
if ( rect _a . left !== rect _b . left || rect _a . top !== rect _b . top ) {
var transform = ` translate( ${ rect _a . left - rect _b . left } px, ${ rect _a . top - rect _b . top } px) ` ;
for ( var keyframe of keyframes ) {
keyframe . transform = keyframe . transform
? ` ${ keyframe . transform } ${ transform } `
: transform ;
}
}
}
}
animation = element . animate ( keyframes , {
animation = element . animate ( keyframes , {
delay ,
delay ,
duration ,
duration ,
@ -340,6 +340,10 @@ function animate(element, options, position_absolute, counterpart, t2, callback)
animation . finished
animation . finished
. then ( ( ) => {
. then ( ( ) => {
callback ? . ( ) ;
callback ? . ( ) ;
if ( t2 === 1 ) {
animation . cancel ( ) ;
}
} )
} )
. catch ( ( e ) => {
. catch ( ( e ) => {
// Error for DOMException: The user aborted a request. This results in two things:
// Error for DOMException: The user aborted a request. This results in two things:
@ -380,15 +384,6 @@ function animate(element, options, position_absolute, counterpart, t2, callback)
task ? . abort ( ) ;
task ? . abort ( ) ;
} ,
} ,
deactivate : ( ) => {
deactivate : ( ) => {
if ( original _styles ) {
// revert `animate:` position fixing
var style = /** @type {HTMLElement | SVGElement} */ ( element ) . style ;
style . position = original _styles . position ;
style . width = original _styles . width ;
style . height = original _styles . height ;
}
callback = undefined ;
callback = undefined ;
} ,
} ,
reset : ( ) => {
reset : ( ) => {