"use client"; import { Vector2 } from "three"; /** * Pointer tracking — 1:1 port of the original PointerProvider (module 16265): * uv in [0,1] with y up (1 - clientY/height), `inside` false on * blur/mouseleave/visibilitychange with a (.5,.5) reset. A module singleton * replaces the original React context (same listeners, capture+passive). */ export const pointerUv = new Vector2(0.5, 0.5); export const pointerInsideRef = { current: false }; let listenersAttached = false; function attach() { if (listenersAttached || typeof window === "undefined") return; listenersAttached = true; const set = (x: number, y: number, inside: boolean) => { pointerUv.set(x, y); pointerInsideRef.current = inside; }; const onMove = (e: PointerEvent) => { const w = Math.max(1, window.innerWidth); const h = Math.max(1, window.innerHeight); set(e.clientX / w, 1 - e.clientY / h, true); }; const reset = () => set(0.5, 0.5, false); const options = { capture: true, passive: true } as const; window.addEventListener("pointermove", onMove, options); window.addEventListener("pointerdown", onMove, options); window.addEventListener("pointerover", onMove, options); window.addEventListener("blur", reset, options); document.addEventListener("mouseleave", reset, options); document.addEventListener("visibilitychange", reset, options); } /** Same shape as the original usePointer(): { uv, insideRef }. */ export function usePointer() { attach(); return { uv: pointerUv, insideRef: pointerInsideRef }; }