@@ -303,13 +303,13 @@ function animate(element, options, counterpart, t2, callback) {
303
303
} ;
304
304
}
305
305
306
- var { delay = 0 , duration , css, tick, easing = linear } = options ;
306
+ const { delay = 0 , css, tick, easing = linear } = options ;
307
307
308
308
var start = raf . now ( ) + delay ;
309
309
var t1 = counterpart ?. t ( start ) ?? 1 - t2 ;
310
310
var delta = t2 - t1 ;
311
311
312
- duration *= Math . abs ( delta ) ;
312
+ var duration = options . duration * Math . abs ( delta ) ;
313
313
var end = start + duration ;
314
314
315
315
/** @type {Animation } */
@@ -319,52 +319,54 @@ function animate(element, options, counterpart, t2, callback) {
319
319
var task ;
320
320
321
321
if ( css ) {
322
- // WAAPI
323
- var keyframes = [ ] ;
324
- var n = Math . ceil ( duration / ( 1000 / 60 ) ) ; // `n` must be an integer, or we risk missing the `t2` value
325
-
326
- // In case of a delayed intro, apply the initial style for the duration of the delay;
327
- // else in case of a fade-in for example the element would be visible until the animation starts
328
- if ( is_intro && delay > 0 ) {
329
- let m = Math . ceil ( delay / ( 1000 / 60 ) ) ;
330
- let keyframe = css_to_keyframe ( css ( 0 , 1 ) ) ;
331
- for ( let i = 0 ; i < m ; i += 1 ) {
332
- keyframes . push ( keyframe ) ;
322
+ queue_micro_task ( ( ) => {
323
+ // WAAPI
324
+ var keyframes = [ ] ;
325
+ var n = Math . ceil ( duration / ( 1000 / 60 ) ) ; // `n` must be an integer, or we risk missing the `t2` value
326
+
327
+ // In case of a delayed intro, apply the initial style for the duration of the delay;
328
+ // else in case of a fade-in for example the element would be visible until the animation starts
329
+ if ( is_intro && delay > 0 ) {
330
+ let m = Math . ceil ( delay / ( 1000 / 60 ) ) ;
331
+ let keyframe = css_to_keyframe ( css ( 0 , 1 ) ) ;
332
+ for ( let i = 0 ; i < m ; i += 1 ) {
333
+ keyframes . push ( keyframe ) ;
334
+ }
333
335
}
334
- }
335
-
336
- for ( var i = 0 ; i <= n ; i += 1 ) {
337
- var t = t1 + delta * easing ( i / n ) ;
338
- var styles = css ( t , 1 - t ) ;
339
- keyframes . push ( css_to_keyframe ( styles ) ) ;
340
- }
341
-
342
- animation = element . animate ( keyframes , {
343
- delay : is_intro ? 0 : delay ,
344
- duration : duration + ( is_intro ? delay : 0 ) ,
345
- easing : 'linear' ,
346
- fill : 'forwards'
347
- } ) ;
348
336
349
- animation . finished
350
- . then ( ( ) => {
351
- callback ?. ( ) ;
337
+ for ( var i = 0 ; i <= n ; i += 1 ) {
338
+ var t = t1 + delta * easing ( i / n ) ;
339
+ var styles = css ( t , 1 - t ) ;
340
+ keyframes . push ( css_to_keyframe ( styles ) ) ;
341
+ }
352
342
353
- if ( t2 === 1 ) {
354
- animation . cancel ( ) ;
355
- }
356
- } )
357
- . catch ( ( e ) => {
358
- // Error for DOMException: The user aborted a request. This results in two things:
359
- // - startTime is `null`
360
- // - currentTime is `null`
361
- // We can't use the existence of an AbortError as this error and error code is shared
362
- // with other Web APIs such as fetch().
363
-
364
- if ( animation . startTime !== null && animation . currentTime !== null ) {
365
- throw e ;
366
- }
343
+ animation = element . animate ( keyframes , {
344
+ delay : is_intro ? 0 : delay ,
345
+ duration : duration + ( is_intro ? delay : 0 ) ,
346
+ easing : 'linear' ,
347
+ fill : 'forwards'
367
348
} ) ;
349
+
350
+ animation . finished
351
+ . then ( ( ) => {
352
+ callback ?. ( ) ;
353
+
354
+ if ( t2 === 1 ) {
355
+ animation . cancel ( ) ;
356
+ }
357
+ } )
358
+ . catch ( ( e ) => {
359
+ // Error for DOMException: The user aborted a request. This results in two things:
360
+ // - startTime is `null`
361
+ // - currentTime is `null`
362
+ // We can't use the existence of an AbortError as this error and error code is shared
363
+ // with other Web APIs such as fetch().
364
+
365
+ if ( animation . startTime !== null && animation . currentTime !== null ) {
366
+ throw e ;
367
+ }
368
+ } ) ;
369
+ } ) ;
368
370
} else {
369
371
// Timer
370
372
if ( t1 === 0 ) {
0 commit comments