fix: prevent div/0 when generating transition keyframes (#13058)

closes #13047
pull/13046/head
Rich Harris 3 weeks ago committed by GitHub
parent 77096a1f30
commit fffb305f46
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: prevent div/0 when generating transition keyframes

@ -358,6 +358,7 @@ function animate(element, options, counterpart, t2, on_finish) {
var duration = /** @type {number} */ (options.duration) * Math.abs(delta);
var keyframes = [];
if (duration > 0) {
if (css) {
var n = Math.ceil(duration / (1000 / 60)); // `n` must be an integer, or we risk missing the `t2` value
@ -368,14 +369,6 @@ function animate(element, options, counterpart, t2, on_finish) {
}
}
animation = element.animate(keyframes, { duration, fill: 'forwards' });
animation.onfinish = () => {
get_t = () => t2;
tick?.(t2, 1 - t2);
on_finish();
};
get_t = () => {
var time = /** @type {number} */ (
/** @type {globalThis.Animation} */ (animation).currentTime
@ -394,6 +387,15 @@ function animate(element, options, counterpart, t2, on_finish) {
return true;
});
}
}
animation = element.animate(keyframes, { duration, fill: 'forwards' });
animation.onfinish = () => {
get_t = () => t2;
tick?.(t2, 1 - t2);
on_finish();
};
};
return {

Loading…
Cancel
Save