MCPcopy
hub / github.com/sveltejs/svelte / animate

Function animate

packages/svelte/src/internal/client/dom/elements/transitions.js:338–497  ·  view source on GitHub ↗

* Animates an element, according to the provided configuration * @param {Element} element * @param {AnimationConfig | ((opts: { direction: 'in' | 'out' }) => AnimationConfig)} options * @param {Animation | undefined} counterpart The corresponding intro/outro to this outro/intro * @param {number}

(element, options, counterpart, t2, on_begin, on_finish)

Source from the content-addressed store, hash-verified

336 * @returns {Animation}
337 */
338function animate(element, options, counterpart, t2, on_begin, on_finish) {
339 var is_intro = t2 === 1;
340
341 if (is_function(options)) {
342 // In the case of a deferred transition (such as `crossfade`), `option` will be
343 // a function rather than an `AnimationConfig`. We need to call this function
344 // once the DOM has been updated...
345 /** @type {Animation} */
346 var a;
347 var aborted = false;
348
349 queue_micro_task(() => {
350 if (aborted) return;
351 var o = options({ direction: is_intro ? 'in' : 'out' });
352 a = animate(element, o, counterpart, t2, on_begin, on_finish);
353 });
354
355 // ...but we want to do so without using `async`/`await` everywhere, so
356 // we return a facade that allows everything to remain synchronous
357 return {
358 abort: () => {
359 aborted = true;
360 a?.abort();
361 },
362 deactivate: () => a.deactivate(),
363 reset: () => a.reset(),
364 t: () => a.t()
365 };
366 }
367
368 counterpart?.deactivate();
369
370 if (!options?.duration && !options?.delay) {
371 on_begin();
372 on_finish();
373
374 return {
375 abort: noop,
376 deactivate: noop,
377 reset: noop,
378 t: () => t2
379 };
380 }
381
382 const { delay = 0, css, tick, easing = linear } = options;
383
384 var keyframes = [];
385
386 if (is_intro && counterpart === undefined) {
387 if (tick) {
388 tick(0, 1); // TODO put in nested effect, to avoid interleaved reads/writes?
389 }
390
391 if (css) {
392 var styles = css_to_keyframe(css(0, 1));
393 keyframes.push(styles, styles);
394 }
395 }

Callers 3

applyFunction · 0.85
inFunction · 0.85
outFunction · 0.85

Calls 11

is_functionFunction · 0.90
queue_micro_taskFunction · 0.90
loopFunction · 0.90
css_to_keyframeFunction · 0.85
get_tFunction · 0.85
abortMethod · 0.80
deactivateMethod · 0.80
resetMethod · 0.80
pushMethod · 0.80
cancelMethod · 0.80
tickFunction · 0.50

Tested by

no test coverage detected