1
0
mirror of https://github.com/misskey-dev/misskey.git synced 2026-07-25 10:54:56 +02:00

Delete animation.ts

This commit is contained in:
syuilo
2026-07-10 15:03:00 +09:00
parent 62afbc32fb
commit 327c447b9a

View File

@@ -1,39 +0,0 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/
export const easing_easeInOutQuad = (t: number) => t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
export function beginAnimation<const T extends Record<string, number>>(options: {
from: T;
to: T;
duration: number;
easing?: (t: number) => number;
apply: (state: T) => void;
onEnd?: () => void;
}) {
const easing = options.easing ?? ((t: number) => t);
const startTime = performance.now();
function animate(now: number) {
const elapsed = now - startTime;
const t = easing(Math.min(elapsed / options.duration, 1));
const state = {} as T;
for (const _key in options.from) {
const key = _key as keyof T;
state[key] = options.from[key] + (options.to[key] - options.from[key]) * t;
}
options.apply(state);
if (t < 1) {
window.requestAnimationFrame(animate);
} else {
options.onEnd?.();
}
}
window.requestAnimationFrame(animate);
}