stable state

This commit is contained in:
achraf
2026-04-01 00:41:31 +02:00
parent a4ee12732d
commit 8e62a0fa92
16 changed files with 779 additions and 565 deletions

View File

@@ -39,10 +39,18 @@ export default function GridCanvas() {
window.addEventListener("resize", resize);
// ── mouse tracking (global so it works across the whole page) ────────────
const onMove = (e: MouseEvent) => { tx = e.clientX; ty = e.clientY; };
const onLeave = () => { tx = -3000; ty = -3000; };
window.addEventListener("mousemove", onMove);
document.documentElement.addEventListener("mouseleave", onLeave);
const onPointerMove = (e: PointerEvent) => { if (e.pointerType === "mouse") { tx = e.clientX; ty = e.clientY; } };
const onPointerLeave = (e: PointerEvent) => { if (e.pointerType === "mouse") { tx = -3000; ty = -3000; } };
window.addEventListener("pointermove", onPointerMove);
document.documentElement.addEventListener("pointerleave", onPointerLeave);
// ── touch tracking (mobile) ───────────────────────────────────────────────
const onTouch = (e: TouchEvent) => {
const t = e.touches[0];
if (t) { tx = t.clientX; ty = t.clientY; }
};
window.addEventListener("touchstart", onTouch, { passive: true });
window.addEventListener("touchmove", onTouch, { passive: true });
// ── displacement: pull a point (px,py) toward the cursor ─────────────────
const warp = (px: number, py: number): [number, number] => {
@@ -159,8 +167,10 @@ export default function GridCanvas() {
return () => {
cancelAnimationFrame(raf);
window.removeEventListener("resize", resize);
window.removeEventListener("mousemove", onMove);
document.documentElement.removeEventListener("mouseleave", onLeave);
window.removeEventListener("pointermove", onPointerMove);
document.documentElement.removeEventListener("pointerleave", onPointerLeave);
window.removeEventListener("touchstart", onTouch);
window.removeEventListener("touchmove", onTouch);
};
}, []);