fix: cursor smooth movement on higher refreshrate monitors

This commit is contained in:
HorizonCode committed 2026-05-21 20:30:00 +02:00
1 parent 6f8043d2d0
commit afdd74175a
3 files changed
+21 -19

No files matched your search

@@ -101,7 +101,7 @@
duration: smoothCursor ? $cursorSmoothness : 0,
translateX: mouseX,
translateY: mouseY,
ease: (t: number) => (t - 1) ** 5 + 1,
ease: (t: number) => t === 1 ? 1 : 1 - Math.pow(2, -10 * t),
});
animate(cursor, {
+12 -10
View File
@@ -1,19 +1,21 @@
export function estimateRefreshRate(): Promise<number> {
export async function estimateFrameRate(): Promise<number> {
return new Promise((resolve) => {
const last = performance.now();
let frames = 0;
const samples: number[] = [];
let last = performance.now();
function loop() {
const tick = () => {
const now = performance.now();
frames++;
samples.push(now - last);
last = now;
if (now - last >= 1000) {
resolve(frames - 2);
if (samples.length < 60) {
requestAnimationFrame(tick);
} else {
requestAnimationFrame(loop);
const avgDelta = samples.reduce((a, b) => a + b) / samples.length;
resolve(Math.round(1000 / avgDelta));
}
}
};
requestAnimationFrame(loop);
requestAnimationFrame(tick);
});
}