2026-11-04 17:55:18 +05:30
|
|
|
'use client';
|
|
|
|
|
|
2026-11-04 18:37:52 +05:30
|
|
|
import React, { useEffect, useRef } from 'react';
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
/**
|
|
|
|
|
* LiquidGlassLensCursor:
|
|
|
|
|
* An optical, fluid liquid glass lens cursor that dynamically magnifies, refracts,
|
|
|
|
|
* and reflects light across all content as you glide over the website.
|
|
|
|
|
*
|
|
|
|
|
* Capabilities:
|
|
|
|
|
* - Real optical magnification & refraction with GPU backdrop-filter
|
|
|
|
|
* - Fluid hydrodynamic squash & stretch deformation based on pointer velocity vector
|
|
|
|
|
* - Multi-layer specular convex reflections & iridescent caustic rim
|
|
|
|
|
* - Organic expansion when hovering over interactive elements (cards, buttons, links, media)
|
|
|
|
|
* - Click surface tension compression feedback
|
|
|
|
|
* - Zero CPU layout reflows (100% GPU composited translate3d and scale transforms)
|
|
|
|
|
* - Strict pointer-events-none (never disrupts interactions, dragging, or text selection)
|
|
|
|
|
*/
|
2026-11-04 17:55:18 +05:30
|
|
|
export function SmoothCursor() {
|
2026-11-05 11:18:35 +05:30
|
|
|
const lensRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const dotRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const causticRef = useRef<HTMLDivElement>(null);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
|
|
|
|
useEffect(() => {
|
2026-11-05 11:18:35 +05:30
|
|
|
// Only on non-touch devices with fine pointers
|
2026-11-04 17:55:18 +05:30
|
|
|
if (typeof window === 'undefined') return;
|
|
|
|
|
const isTouch = window.matchMedia('(pointer: coarse)').matches;
|
|
|
|
|
if (isTouch) return;
|
|
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
const lens = lensRef.current;
|
|
|
|
|
const dot = dotRef.current;
|
|
|
|
|
const caustic = causticRef.current;
|
|
|
|
|
if (!lens || !dot) return;
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
let mouseX = -200;
|
|
|
|
|
let mouseY = -200;
|
|
|
|
|
let prevMouseX = -200;
|
|
|
|
|
let prevMouseY = -200;
|
|
|
|
|
|
|
|
|
|
let lensX = -200;
|
|
|
|
|
let lensY = -200;
|
|
|
|
|
let causticX = -200;
|
|
|
|
|
let causticY = -200;
|
|
|
|
|
|
|
|
|
|
let currentSpeed = 0;
|
2026-11-04 18:37:52 +05:30
|
|
|
let isHovered = false;
|
2026-11-05 11:18:35 +05:30
|
|
|
let isPressed = false;
|
2026-11-04 18:37:52 +05:30
|
|
|
let isVisible = false;
|
|
|
|
|
let animId = 0;
|
|
|
|
|
|
|
|
|
|
const onMouseMove = (e: MouseEvent) => {
|
|
|
|
|
mouseX = e.clientX;
|
|
|
|
|
mouseY = e.clientY;
|
|
|
|
|
if (!isVisible) {
|
|
|
|
|
isVisible = true;
|
2026-11-05 11:18:35 +05:30
|
|
|
lens.style.opacity = '1';
|
2026-11-04 18:37:52 +05:30
|
|
|
dot.style.opacity = '1';
|
2026-11-05 11:18:35 +05:30
|
|
|
if (caustic) caustic.style.opacity = '1';
|
2026-11-04 18:37:52 +05:30
|
|
|
}
|
2026-11-04 17:55:18 +05:30
|
|
|
};
|
|
|
|
|
|
2026-11-04 18:37:52 +05:30
|
|
|
const onMouseLeave = () => {
|
|
|
|
|
isVisible = false;
|
2026-11-05 11:18:35 +05:30
|
|
|
lens.style.opacity = '0';
|
2026-11-04 18:37:52 +05:30
|
|
|
dot.style.opacity = '0';
|
2026-11-05 11:18:35 +05:30
|
|
|
if (caustic) caustic.style.opacity = '0';
|
2026-11-04 17:55:18 +05:30
|
|
|
};
|
|
|
|
|
|
2026-11-04 18:37:52 +05:30
|
|
|
const onMouseEnter = () => {
|
|
|
|
|
isVisible = true;
|
2026-11-05 11:18:35 +05:30
|
|
|
lens.style.opacity = '1';
|
2026-11-04 18:37:52 +05:30
|
|
|
dot.style.opacity = '1';
|
2026-11-05 11:18:35 +05:30
|
|
|
if (caustic) caustic.style.opacity = '1';
|
2026-11-04 17:55:18 +05:30
|
|
|
};
|
|
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
const onMouseDown = () => {
|
|
|
|
|
isPressed = true;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onMouseUp = () => {
|
|
|
|
|
isPressed = false;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Throttled interactive element detection for snappy magnetic lens response
|
2026-11-04 18:37:52 +05:30
|
|
|
let lastCheck = 0;
|
|
|
|
|
const onMouseOver = (e: MouseEvent) => {
|
|
|
|
|
const now = performance.now();
|
2026-11-05 11:18:35 +05:30
|
|
|
if (now - lastCheck < 25) return;
|
2026-11-04 18:37:52 +05:30
|
|
|
lastCheck = now;
|
|
|
|
|
|
2026-11-04 17:55:18 +05:30
|
|
|
const target = e.target as HTMLElement | null;
|
|
|
|
|
if (!target) return;
|
2026-11-05 11:18:35 +05:30
|
|
|
const interactive = target.closest('a, button, input, textarea, select, [role="button"], .cursor-pointer, [data-interactive]');
|
|
|
|
|
isHovered = !!interactive;
|
2026-11-04 17:55:18 +05:30
|
|
|
};
|
|
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
// High performance RAF loop (locked 60-120fps, 100% GPU composited)
|
2026-11-04 18:37:52 +05:30
|
|
|
const loop = () => {
|
2026-11-05 11:18:35 +05:30
|
|
|
// Calculate velocity vector of mouse movement
|
|
|
|
|
const vx = mouseX - prevMouseX;
|
|
|
|
|
const vy = mouseY - prevMouseY;
|
|
|
|
|
prevMouseX = mouseX;
|
|
|
|
|
prevMouseY = mouseY;
|
2026-11-04 18:37:52 +05:30
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
const rawSpeed = Math.hypot(vx, vy);
|
|
|
|
|
// Low-pass filter for silky organic fluid momentum
|
|
|
|
|
currentSpeed += (rawSpeed - currentSpeed) * 0.2;
|
2026-11-04 18:48:24 +05:30
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
// Smooth lag for liquid lens (organic water droplet following behavior)
|
|
|
|
|
lensX += (mouseX - lensX) * 0.32;
|
|
|
|
|
lensY += (mouseY - lensY) * 0.32;
|
|
|
|
|
|
|
|
|
|
// Secondary ambient caustic trailing slightly behind
|
|
|
|
|
if (caustic) {
|
|
|
|
|
causticX += (mouseX - causticX) * 0.18;
|
|
|
|
|
causticY += (mouseY - causticY) * 0.18;
|
|
|
|
|
caustic.style.transform = `translate3d(${causticX}px, ${causticY}px, 0) translate3d(-50%, -50%, 0)`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Dynamic liquid squash & stretch based on velocity and direction
|
|
|
|
|
const angle = Math.atan2(vy, vx);
|
|
|
|
|
const stretch = Math.min(currentSpeed * 0.0035, 0.32); // Max stretch 32%
|
|
|
|
|
|
|
|
|
|
const baseScale = isPressed ? (isHovered ? 1.35 : 0.88) : (isHovered ? 1.6 : 1.0);
|
|
|
|
|
const scaleX = baseScale * (1 + stretch);
|
|
|
|
|
const scaleY = baseScale * (1 - stretch * 0.5);
|
|
|
|
|
|
|
|
|
|
// Hardware accelerated transform with velocity alignment
|
|
|
|
|
if (stretch > 0.02) {
|
|
|
|
|
lens.style.transform = `translate3d(${lensX}px, ${lensY}px, 0) translate3d(-50%, -50%, 0) rotate(${angle}rad) scale(${scaleX}, ${scaleY}) rotate(${-angle}rad)`;
|
|
|
|
|
} else {
|
|
|
|
|
lens.style.transform = `translate3d(${lensX}px, ${lensY}px, 0) translate3d(-50%, -50%, 0) scale(${baseScale})`;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zero-latency precision dot (instant pinpoint at mouse coordinates)
|
|
|
|
|
const dotScale = isHovered ? 0 : (isPressed ? 0.7 : 1);
|
2026-11-04 18:48:24 +05:30
|
|
|
dot.style.transform = `translate3d(${mouseX}px, ${mouseY}px, 0) translate3d(-50%, -50%, 0) scale(${dotScale})`;
|
2026-11-04 18:37:52 +05:30
|
|
|
|
|
|
|
|
animId = requestAnimationFrame(loop);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
window.addEventListener('mousemove', onMouseMove, { passive: true });
|
|
|
|
|
window.addEventListener('mouseleave', onMouseLeave);
|
|
|
|
|
window.addEventListener('mouseenter', onMouseEnter);
|
2026-11-05 11:18:35 +05:30
|
|
|
window.addEventListener('mousedown', onMouseDown);
|
|
|
|
|
window.addEventListener('mouseup', onMouseUp);
|
2026-11-04 18:37:52 +05:30
|
|
|
document.addEventListener('mouseover', onMouseOver, { passive: true });
|
|
|
|
|
|
|
|
|
|
animId = requestAnimationFrame(loop);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
|
|
|
|
return () => {
|
2026-11-04 18:37:52 +05:30
|
|
|
cancelAnimationFrame(animId);
|
|
|
|
|
window.removeEventListener('mousemove', onMouseMove);
|
|
|
|
|
window.removeEventListener('mouseleave', onMouseLeave);
|
|
|
|
|
window.removeEventListener('mouseenter', onMouseEnter);
|
2026-11-05 11:18:35 +05:30
|
|
|
window.removeEventListener('mousedown', onMouseDown);
|
|
|
|
|
window.removeEventListener('mouseup', onMouseUp);
|
2026-11-04 18:37:52 +05:30
|
|
|
document.removeEventListener('mouseover', onMouseOver);
|
2026-11-04 17:55:18 +05:30
|
|
|
};
|
2026-11-04 18:37:52 +05:30
|
|
|
}, []);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
|
|
|
|
return (
|
2026-11-05 11:18:35 +05:30
|
|
|
<div className="pointer-events-none fixed inset-0 z-[99999] overflow-hidden select-none">
|
|
|
|
|
{/* 1. Ambient Caustic Aura (Fluid light dispersion) */}
|
2026-11-04 18:37:52 +05:30
|
|
|
<div
|
2026-11-05 11:18:35 +05:30
|
|
|
ref={causticRef}
|
|
|
|
|
className="fixed top-0 left-0 w-24 h-24 rounded-full pointer-events-none opacity-0 transition-opacity duration-300 will-change-transform transform-gpu [backface-visibility:hidden]"
|
|
|
|
|
style={{
|
|
|
|
|
background: 'radial-gradient(circle, rgba(56, 189, 248, 0.16) 0%, rgba(99, 102, 241, 0.08) 45%, transparent 72%)',
|
|
|
|
|
filter: 'blur(8px)',
|
|
|
|
|
}}
|
2026-11-04 17:55:18 +05:30
|
|
|
/>
|
|
|
|
|
|
2026-11-05 11:18:35 +05:30
|
|
|
{/* 2. The Liquid Glass Lens (Refractive Convex Optical Glass Bubble) */}
|
2026-11-04 18:37:52 +05:30
|
|
|
<div
|
2026-11-05 11:18:35 +05:30
|
|
|
ref={lensRef}
|
|
|
|
|
className="fixed top-0 left-0 w-12 h-12 rounded-full pointer-events-none opacity-0 will-change-transform transform-gpu [backface-visibility:hidden] transition-opacity duration-200"
|
|
|
|
|
style={{
|
|
|
|
|
// Optical glass refraction & magnification filter (crystal clarity with heightened contrast & saturation)
|
|
|
|
|
backdropFilter: 'blur(0.8px) contrast(1.24) brightness(1.1) saturate(1.4)',
|
|
|
|
|
WebkitBackdropFilter: 'blur(0.8px) contrast(1.24) brightness(1.1) saturate(1.4)',
|
|
|
|
|
// Multi-layer specular convex glass gradient
|
|
|
|
|
background:
|
|
|
|
|
'radial-gradient(circle at 35% 28%, rgba(255, 255, 255, 0.72) 0%, rgba(255, 255, 255, 0.22) 32%, rgba(255, 255, 255, 0) 65%), linear-gradient(135deg, rgba(255, 255, 255, 0.24) 0%, rgba(56, 189, 248, 0.08) 45%, rgba(99, 102, 241, 0.12) 100%)',
|
|
|
|
|
// Refractive caustic bevel, specular highlight rim & prismatic drop shadow
|
|
|
|
|
boxShadow:
|
|
|
|
|
'0 8px 32px -4px rgba(37, 99, 235, 0.28), 0 2px 10px rgba(15, 23, 42, 0.08), inset 0 1.5px 2.5px rgba(255, 255, 255, 0.95), inset 0 -1.5px 3px rgba(37, 99, 235, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.65)',
|
|
|
|
|
border: '1px solid rgba(255, 255, 255, 0.6)',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{/* Curved Specular Reflection Glint (Simulates spherical glass refraction curvature) */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute top-1.5 left-2 w-4 h-1.5 rounded-full pointer-events-none"
|
|
|
|
|
style={{
|
|
|
|
|
background: 'linear-gradient(to right, rgba(255, 255, 255, 0.9), rgba(255, 255, 255, 0.25))',
|
|
|
|
|
transform: 'rotate(-25deg)',
|
|
|
|
|
filter: 'blur(0.2px)',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Secondary Caustic Rim Reflection */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute bottom-1.5 right-2 w-2.5 h-1 rounded-full pointer-events-none opacity-70"
|
|
|
|
|
style={{
|
|
|
|
|
background: 'linear-gradient(to left, rgba(147, 197, 253, 0.8), rgba(199, 210, 254, 0.25))',
|
|
|
|
|
transform: 'rotate(-25deg)',
|
|
|
|
|
filter: 'blur(0.3px)',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* 3. Ultra-Crisp Precision Dot (Zero Latency Pinpoint) */}
|
|
|
|
|
<div
|
|
|
|
|
ref={dotRef}
|
|
|
|
|
className="fixed top-0 left-0 w-1.5 h-1.5 rounded-full bg-blue-600 shadow-[0_0_8px_rgba(37,99,235,0.9)] pointer-events-none opacity-0 will-change-transform transform-gpu [backface-visibility:hidden] transition-opacity duration-150"
|
2026-11-04 17:55:18 +05:30
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|