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:
|
2026-11-05 11:26:05 +05:30
|
|
|
* Pure Optical Liquid Glass Lens cursor with 100% transparent crystal body,
|
|
|
|
|
* sharp specular water-drop glints, dynamic velocity squash & stretch,
|
|
|
|
|
* and universal responsiveness across all devices (Desktop, Mobile, Tablet, Trackpad).
|
2026-11-05 11:18:35 +05:30
|
|
|
*
|
2026-11-05 11:26:05 +05:30
|
|
|
* Key Capabilities:
|
|
|
|
|
* - Ultra-transparent liquid glass (Zero frosting, zero milky haze, pure optical clarity)
|
|
|
|
|
* - Sharp meniscus rim & caustic reflections matching brand theme (#2563EB, #06B6D4)
|
|
|
|
|
* - True multi-device responsiveness: Mouse on desktop + fluid touch lens on mobile/tablets
|
|
|
|
|
* - Hardware-accelerated GPU transforms (locked 60-120fps, zero layout reflows)
|
|
|
|
|
* - Strictly pointer-events-none: never blocks taps, clicks, scrolls, or dragging
|
2026-11-05 11:18:35 +05:30
|
|
|
*/
|
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(() => {
|
|
|
|
|
if (typeof window === 'undefined') 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;
|
2026-11-05 11:26:05 +05:30
|
|
|
let isTouchActive = false;
|
|
|
|
|
let fadeTimeout: NodeJS.Timeout | null = null;
|
2026-11-04 18:37:52 +05:30
|
|
|
let animId = 0;
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
// 1. Mouse & Pointer Movement (Desktop & Trackpads)
|
2026-11-04 18:37:52 +05:30
|
|
|
const onMouseMove = (e: MouseEvent) => {
|
2026-11-05 11:26:05 +05:30
|
|
|
isTouchActive = false;
|
2026-11-04 18:37:52 +05:30
|
|
|
mouseX = e.clientX;
|
|
|
|
|
mouseY = e.clientY;
|
2026-11-05 11:26:05 +05:30
|
|
|
if (fadeTimeout) clearTimeout(fadeTimeout);
|
|
|
|
|
|
2026-11-04 18:37:52 +05:30
|
|
|
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 = () => {
|
2026-11-05 11:26:05 +05:30
|
|
|
if (isTouchActive) return;
|
2026-11-04 18:37:52 +05:30
|
|
|
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 = () => {
|
2026-11-05 11:26:05 +05:30
|
|
|
if (isTouchActive) return;
|
2026-11-04 18:37:52 +05:30
|
|
|
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;
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
// 2. Touch Handlers (Full Mobile, Tablet, iPad & Touchscreen Compatibility)
|
|
|
|
|
const onTouchStart = (e: TouchEvent) => {
|
2026-11-05 11:42:47 +05:30
|
|
|
try {
|
|
|
|
|
if (!e.touches || e.touches.length === 0) return;
|
|
|
|
|
isTouchActive = true;
|
|
|
|
|
if (fadeTimeout) clearTimeout(fadeTimeout);
|
2026-11-05 11:26:05 +05:30
|
|
|
|
2026-11-05 11:42:47 +05:30
|
|
|
const touch = e.touches[0];
|
|
|
|
|
if (!touch) return;
|
|
|
|
|
mouseX = touch.clientX;
|
|
|
|
|
mouseY = touch.clientY;
|
2026-11-05 11:26:05 +05:30
|
|
|
|
2026-11-05 11:42:47 +05:30
|
|
|
// If opening fresh, snap directly to finger touch point
|
|
|
|
|
if (!isVisible) {
|
|
|
|
|
lensX = mouseX;
|
|
|
|
|
lensY = mouseY;
|
|
|
|
|
prevMouseX = mouseX;
|
|
|
|
|
prevMouseY = mouseY;
|
|
|
|
|
isVisible = true;
|
|
|
|
|
lens.style.opacity = '1';
|
|
|
|
|
if (caustic) caustic.style.opacity = '1';
|
|
|
|
|
}
|
|
|
|
|
// On touch, hide the tiny dot (the finger is right there)
|
|
|
|
|
dot.style.opacity = '0';
|
|
|
|
|
isPressed = true;
|
|
|
|
|
} catch {
|
|
|
|
|
// Safe failover
|
2026-11-05 11:26:05 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onTouchMove = (e: TouchEvent) => {
|
2026-11-05 11:42:47 +05:30
|
|
|
try {
|
|
|
|
|
if (!e.touches || e.touches.length === 0) return;
|
|
|
|
|
const touch = e.touches[0];
|
|
|
|
|
if (!touch) return;
|
|
|
|
|
mouseX = touch.clientX;
|
|
|
|
|
mouseY = touch.clientY;
|
|
|
|
|
} catch {
|
|
|
|
|
// Safe failover
|
|
|
|
|
}
|
2026-11-05 11:26:05 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const onTouchEnd = () => {
|
2026-11-05 11:42:47 +05:30
|
|
|
try {
|
|
|
|
|
isPressed = false;
|
|
|
|
|
// Graceful liquid fade out after touch interaction completes
|
|
|
|
|
if (fadeTimeout) clearTimeout(fadeTimeout);
|
|
|
|
|
fadeTimeout = setTimeout(() => {
|
|
|
|
|
isVisible = false;
|
|
|
|
|
if (lens) lens.style.opacity = '0';
|
|
|
|
|
if (caustic) caustic.style.opacity = '0';
|
|
|
|
|
}, 350);
|
|
|
|
|
} catch {
|
|
|
|
|
// Safe failover
|
|
|
|
|
}
|
2026-11-05 11:26:05 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Throttled interactive element detection for magnetic lens scaling
|
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-05 11:42:47 +05:30
|
|
|
const target = e.target as Node | null;
|
2026-11-04 17:55:18 +05:30
|
|
|
if (!target) return;
|
2026-11-05 11:42:47 +05:30
|
|
|
const element = (target instanceof Element ? target : target.parentElement) as HTMLElement | null;
|
|
|
|
|
if (!element || typeof element.closest !== 'function') return;
|
|
|
|
|
|
|
|
|
|
const interactive = element.closest('a, button, input, textarea, select, [role="button"], .cursor-pointer, [data-interactive]');
|
2026-11-05 11:18:35 +05:30
|
|
|
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:26:05 +05:30
|
|
|
// Calculate velocity vector of pointer movement
|
2026-11-05 11:18:35 +05:30
|
|
|
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);
|
|
|
|
|
currentSpeed += (rawSpeed - currentSpeed) * 0.2;
|
2026-11-04 18:48:24 +05:30
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
// Silky liquid lag for pure organic fluid following
|
|
|
|
|
lensX += (mouseX - lensX) * 0.35;
|
|
|
|
|
lensY += (mouseY - lensY) * 0.35;
|
2026-11-05 11:18:35 +05:30
|
|
|
|
|
|
|
|
// 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%
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
const baseScale = isPressed ? (isHovered ? 1.35 : 0.9) : (isHovered ? 1.55 : 1.0);
|
2026-11-05 11:18:35 +05:30
|
|
|
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})`;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
// Precision pinpoint dot (Desktop only, hidden on touch or hover)
|
|
|
|
|
if (!isTouchActive) {
|
|
|
|
|
const dotScale = isHovered ? 0 : (isPressed ? 0.7 : 1);
|
|
|
|
|
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);
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
// Desktop Pointer Listeners
|
2026-11-04 18:37:52 +05:30
|
|
|
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 });
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
// Touch Device Listeners
|
|
|
|
|
window.addEventListener('touchstart', onTouchStart, { passive: true });
|
|
|
|
|
window.addEventListener('touchmove', onTouchMove, { passive: true });
|
|
|
|
|
window.addEventListener('touchend', onTouchEnd, { passive: true });
|
|
|
|
|
window.addEventListener('touchcancel', onTouchEnd, { passive: true });
|
|
|
|
|
|
2026-11-04 18:37:52 +05:30
|
|
|
animId = requestAnimationFrame(loop);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
|
|
|
|
return () => {
|
2026-11-04 18:37:52 +05:30
|
|
|
cancelAnimationFrame(animId);
|
2026-11-05 11:26:05 +05:30
|
|
|
if (fadeTimeout) clearTimeout(fadeTimeout);
|
2026-11-04 18:37:52 +05:30
|
|
|
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-05 11:26:05 +05:30
|
|
|
|
|
|
|
|
window.removeEventListener('touchstart', onTouchStart);
|
|
|
|
|
window.removeEventListener('touchmove', onTouchMove);
|
|
|
|
|
window.removeEventListener('touchend', onTouchEnd);
|
|
|
|
|
window.removeEventListener('touchcancel', onTouchEnd);
|
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">
|
2026-11-05 11:26:05 +05:30
|
|
|
{/* 1. Ambient Caustic Aura (Fluid blue 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={{
|
2026-11-05 11:26:05 +05:30
|
|
|
background: 'radial-gradient(circle, rgba(56, 189, 248, 0.12) 0%, rgba(99, 102, 241, 0.05) 50%, transparent 70%)',
|
|
|
|
|
filter: 'blur(10px)',
|
2026-11-05 11:18:35 +05:30
|
|
|
}}
|
2026-11-04 17:55:18 +05:30
|
|
|
/>
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
{/* 2. Pure Liquid Glass Lens (100% Crystal Transparent Body, Sharp Specular Glints, Zero Frosting) */}
|
2026-11-04 18:37:52 +05:30
|
|
|
<div
|
2026-11-05 11:18:35 +05:30
|
|
|
ref={lensRef}
|
2026-11-05 11:26:05 +05:30
|
|
|
className="fixed top-0 left-0 w-11 h-11 sm:w-12 sm:h-12 rounded-full pointer-events-none opacity-0 will-change-transform transform-gpu [backface-visibility:hidden] transition-opacity duration-200"
|
2026-11-05 11:18:35 +05:30
|
|
|
style={{
|
2026-11-05 11:26:05 +05:30
|
|
|
// Optical clear glass: ZERO blur (eliminates all frosted haze) + optical contrast & saturation pop
|
|
|
|
|
backdropFilter: 'contrast(1.16) brightness(1.05) saturate(1.28)',
|
|
|
|
|
WebkitBackdropFilter: 'contrast(1.16) brightness(1.05) saturate(1.28)',
|
|
|
|
|
// Ultra-sheer crystal body: 98% transparent center, subtle sapphire meniscus tint at the outer rim
|
2026-11-05 11:18:35 +05:30
|
|
|
background:
|
2026-11-05 11:26:05 +05:30
|
|
|
'radial-gradient(circle at 40% 35%, rgba(255, 255, 255, 0.12) 0%, rgba(255, 255, 255, 0.02) 40%, rgba(37, 99, 235, 0.04) 75%, rgba(37, 99, 235, 0.12) 100%)',
|
|
|
|
|
// Sharp liquid meniscus rim & caustic reflection
|
2026-11-05 11:18:35 +05:30
|
|
|
boxShadow:
|
2026-11-05 11:26:05 +05:30
|
|
|
'0 4px 20px -2px rgba(37, 99, 235, 0.22), 0 1px 4px rgba(15, 23, 42, 0.06), inset 0 1.5px 2px rgba(255, 255, 255, 0.85), inset 0 -1.5px 2.5px rgba(37, 99, 235, 0.35), inset 0 0 0 1px rgba(255, 255, 255, 0.45)',
|
|
|
|
|
border: '1px solid rgba(255, 255, 255, 0.55)',
|
2026-11-05 11:18:35 +05:30
|
|
|
}}
|
|
|
|
|
>
|
2026-11-05 11:26:05 +05:30
|
|
|
{/* Primary Sharp Specular Glint (Simulates sunlight reflecting off curved water droplet meniscus) */}
|
2026-11-05 11:18:35 +05:30
|
|
|
<div
|
2026-11-05 11:26:05 +05:30
|
|
|
className="absolute top-1.5 left-2 w-3.5 h-1.5 rounded-full pointer-events-none"
|
2026-11-05 11:18:35 +05:30
|
|
|
style={{
|
2026-11-05 11:26:05 +05:30
|
|
|
background: 'linear-gradient(135deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.4) 60%, transparent 100%)',
|
2026-11-05 11:18:35 +05:30
|
|
|
transform: 'rotate(-25deg)',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
{/* Pinpoint Micro-Glint (Sharp point-light reflection) */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute top-1 left-2.5 w-1 h-1 rounded-full bg-white pointer-events-none shadow-[0_0_2px_rgba(255,255,255,0.95)]"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Secondary Ambient Caustic Rim (Bottom-right rim reflection) */}
|
2026-11-05 11:18:35 +05:30
|
|
|
<div
|
2026-11-05 11:26:05 +05:30
|
|
|
className="absolute bottom-1 right-2 w-2.5 h-1 rounded-full pointer-events-none opacity-80"
|
2026-11-05 11:18:35 +05:30
|
|
|
style={{
|
2026-11-05 11:26:05 +05:30
|
|
|
background: 'linear-gradient(315deg, rgba(56, 189, 248, 0.7) 0%, rgba(99, 102, 241, 0.2) 100%)',
|
2026-11-05 11:18:35 +05:30
|
|
|
transform: 'rotate(-25deg)',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-05 11:26:05 +05:30
|
|
|
{/* 3. Precision Point Pip (Desktop Only, Zero Latency Pinpoint) */}
|
2026-11-05 11:18:35 +05:30
|
|
|
<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>
|
|
|
|
|
);
|
|
|
|
|
}
|