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,13 +358,34 @@ function animate(element, options, counterpart, t2, on_finish) {
var duration = /** @type {number} */ (options.duration) * Math.abs(delta);
var keyframes = [];
if (css) {
var n = Math.ceil(duration / (1000 / 60)); // `n` must be an integer, or we risk missing the `t2` value
if (duration > 0) {
if (css) {
var n = Math.ceil(duration / (1000 / 60)); // `n` must be an integer, or we risk missing the `t2` value
for (var i = 0; i <= n; i += 1) {
var t = t1 + delta * easing(i / n);
var styles = css(t, 1 - t);
keyframes.push(css_to_keyframe(styles));
}
}
get_t = () => {
var time = /** @type {number} */ (
/** @type {globalThis.Animation} */ (animation).currentTime
);
return t1 + delta * easing(time / duration);
};
for (var i = 0; i <= n; i += 1) {
var t = t1 + delta * easing(i / n);
var styles = css(t, 1 - t);
keyframes.push(css_to_keyframe(styles));
if (tick) {
loop(() => {
if (animation.playState !== 'running') return false;
var t = get_t();
tick(t, 1 - t);
return true;
});
}
}
@ -375,25 +396,6 @@ function animate(element, options, counterpart, t2, on_finish) {
tick?.(t2, 1 - t2);
on_finish();
};
get_t = () => {
var time = /** @type {number} */ (
/** @type {globalThis.Animation} */ (animation).currentTime
);
return t1 + delta * easing(time / duration);
};
if (tick) {
loop(() => {
if (animation.playState !== 'running') return false;
var t = get_t();
tick(t, 1 - t);
return true;
});
}
};
return {

Loading…
Cancel
Save