2026-11-03 13:36:36 +05:30
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import React, { useEffect, useRef, useState } from 'react';
|
|
|
|
|
|
|
|
|
|
export function CursorAura() {
|
|
|
|
|
const [mounted, setMounted] = useState<boolean>(false);
|
|
|
|
|
const posRef = useRef({ targetX: -500, targetY: -500, currentX: -500, currentY: -500 });
|
|
|
|
|
const auraRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-11-03 13:46:51 +05:30
|
|
|
try {
|
|
|
|
|
if (typeof window === 'undefined') return;
|
|
|
|
|
if (window.matchMedia && window.matchMedia('(pointer: coarse)').matches) return;
|
|
|
|
|
if (window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
|
|
|
|
|
setMounted(true);
|
|
|
|
|
} catch {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2026-11-03 13:36:36 +05:30
|
|
|
|
|
|
|
|
const onMouseMove = (e: MouseEvent) => {
|
|
|
|
|
posRef.current.targetX = e.clientX;
|
|
|
|
|
posRef.current.targetY = e.clientY;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener('mousemove', onMouseMove, { passive: true });
|
|
|
|
|
|
|
|
|
|
let animId: number;
|
|
|
|
|
|
|
|
|
|
const render = () => {
|
|
|
|
|
const pos = posRef.current;
|
|
|
|
|
// Damped lerp follower
|
|
|
|
|
pos.currentX += (pos.targetX - pos.currentX) * 0.08;
|
|
|
|
|
pos.currentY += (pos.targetY - pos.currentY) * 0.08;
|
|
|
|
|
|
|
|
|
|
if (auraRef.current) {
|
|
|
|
|
auraRef.current.style.transform = `translate3d(${pos.currentX - 250}px, ${pos.currentY - 250}px, 0)`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
animId = requestAnimationFrame(render);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
animId = requestAnimationFrame(render);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
cancelAnimationFrame(animId);
|
|
|
|
|
window.removeEventListener('mousemove', onMouseMove);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
if (!mounted) return null;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
aria-hidden="true"
|
|
|
|
|
className="pointer-events-none fixed inset-0 z-0 overflow-hidden hidden [@media(hover:hover)]:block"
|
|
|
|
|
>
|
|
|
|
|
<div
|
|
|
|
|
ref={auraRef}
|
|
|
|
|
className="absolute top-0 left-0 w-[500px] h-[500px] rounded-full will-change-transform opacity-60"
|
|
|
|
|
style={{
|
|
|
|
|
background:
|
|
|
|
|
'radial-gradient(circle, rgba(59, 130, 246, 0.09) 0%, rgba(99, 102, 241, 0.05) 35%, rgba(168, 85, 247, 0.02) 60%, transparent 80%)',
|
|
|
|
|
filter: 'blur(35px)',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|