fix(mobile): resolve mobile touch runtime errors, webgl transmission GPU stall and add root icon

This commit is contained in:
2026-11-05 11:42:47 +05:30
parent d20f98cb36
commit 35a615f4ea
4 changed files with 184 additions and 76 deletions
+49 -32
View File
@@ -87,45 +87,59 @@ export function SmoothCursor() {
// 2. Touch Handlers (Full Mobile, Tablet, iPad & Touchscreen Compatibility)
const onTouchStart = (e: TouchEvent) => {
if (!e.touches || e.touches.length === 0) return;
isTouchActive = true;
if (fadeTimeout) clearTimeout(fadeTimeout);
try {
if (!e.touches || e.touches.length === 0) return;
isTouchActive = true;
if (fadeTimeout) clearTimeout(fadeTimeout);
const touch = e.touches[0];
mouseX = touch.clientX;
mouseY = touch.clientY;
const touch = e.touches[0];
if (!touch) return;
mouseX = touch.clientX;
mouseY = touch.clientY;
// 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';
// 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
}
// On touch, hide the tiny dot (the finger is right there)
dot.style.opacity = '0';
isPressed = true;
};
const onTouchMove = (e: TouchEvent) => {
if (!e.touches || e.touches.length === 0) return;
const touch = e.touches[0];
mouseX = touch.clientX;
mouseY = touch.clientY;
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
}
};
const onTouchEnd = () => {
isPressed = false;
// Graceful liquid fade out after touch interaction completes
if (fadeTimeout) clearTimeout(fadeTimeout);
fadeTimeout = setTimeout(() => {
isVisible = false;
lens.style.opacity = '0';
if (caustic) caustic.style.opacity = '0';
}, 350);
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
}
};
// Throttled interactive element detection for magnetic lens scaling
@@ -135,9 +149,12 @@ export function SmoothCursor() {
if (now - lastCheck < 25) return;
lastCheck = now;
const target = e.target as HTMLElement | null;
const target = e.target as Node | null;
if (!target) return;
const interactive = target.closest('a, button, input, textarea, select, [role="button"], .cursor-pointer, [data-interactive]');
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]');
isHovered = !!interactive;
};
+20 -8
View File
@@ -453,18 +453,16 @@ function Hero3DCanvas({ className }: { className?: string }) {
const masterGroup = new THREE.Group();
scene.add(masterGroup);
// 1. Central Optical Translucent Crystal (Icosahedron, non-obstructive)
// 1. Central Optical Translucent Crystal (Icosahedron, mobile GPU safe)
const crystalGeo = new THREE.IcosahedronGeometry(1.25, 0);
const crystalMat = new THREE.MeshPhysicalMaterial({
const crystalMat = new THREE.MeshStandardMaterial({
color: 0x3b82f6,
emissive: 0x1d4ed8,
emissiveIntensity: 0.1,
roughness: 0.15,
emissiveIntensity: 0.12,
roughness: 0.18,
metalness: 0.1,
transmission: 0.9,
transparent: true,
opacity: 0.11,
ior: 1.4,
opacity: 0.14,
});
const crystal = new THREE.Mesh(crystalGeo, crystalMat);
masterGroup.add(crystal);
@@ -568,11 +566,24 @@ function Hero3DCanvas({ className }: { className?: string }) {
particles.rotation.y = elapsed * 0.03;
particles.rotation.x = elapsed * 0.02;
if (renderer) renderer.render(scene, camera);
if (renderer) {
try {
renderer.render(scene, camera);
} catch {
cancelAnimationFrame(animId);
}
}
};
animate();
const canvas = renderer.domElement;
const handleContextLost = (e: Event) => {
e.preventDefault();
cancelAnimationFrame(animId);
};
canvas.addEventListener('webglcontextlost', handleContextLost, false);
const handleResize = () => {
if (!container || !renderer) return;
const w = container.clientWidth;
@@ -587,6 +598,7 @@ function Hero3DCanvas({ className }: { className?: string }) {
return () => {
cancelAnimationFrame(animId);
observer.disconnect();
canvas.removeEventListener('webglcontextlost', handleContextLost);
window.removeEventListener('resize', handleResize);
if (renderer && renderer.domElement && container.contains(renderer.domElement)) {
container.removeChild(renderer.domElement);
+50 -36
View File
@@ -25,49 +25,63 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (prefersReducedMotion) return;
// Initialize ultra-lightweight Lenis instance
const lenis = new Lenis({
duration: 1.15,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // Silky exponential ease-out
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
wheelMultiplier: 0.95,
touchMultiplier: 1.25,
infinite: false,
});
// Expose lenis instance globally for programmatic scrolling
(window as any).__lenis = lenis;
// Locked high-frequency RAF loop
let lenis: Lenis | null = null;
let animId = 0;
const raf = (time: number) => {
lenis.raf(time);
try {
// Initialize ultra-lightweight Lenis instance
lenis = new Lenis({
duration: 1.15,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)), // Silky exponential ease-out
orientation: 'vertical',
gestureOrientation: 'vertical',
smoothWheel: true,
syncTouch: false, // Preserves native 120Hz iOS/Android touch momentum without interference
wheelMultiplier: 0.95,
touchMultiplier: 1.0,
infinite: false,
});
// Expose lenis instance globally for programmatic scrolling
(window as any).__lenis = lenis;
// Locked high-frequency RAF loop
const raf = (time: number) => {
lenis?.raf(time);
animId = requestAnimationFrame(raf);
};
animId = requestAnimationFrame(raf);
};
animId = requestAnimationFrame(raf);
} catch {
// Fallback silently to native smooth scrolling
}
// Intercept in-page anchor links for seamless animated scrolling
// Intercept in-page anchor links for seamless animated scrolling (safe on text nodes on mobile)
const handleAnchorClick = (e: MouseEvent) => {
const target = e.target as HTMLElement | null;
if (!target) return;
const anchor = target.closest('a[href^="#"]') as HTMLAnchorElement | null;
if (!anchor) return;
const href = anchor.getAttribute('href');
if (!href || href === '#' || href === '#!') return;
try {
const target = e.target as Node | null;
if (!target) return;
const element = (target instanceof Element ? target : target.parentElement) as HTMLElement | null;
if (!element || typeof element.closest !== 'function') return;
const anchor = element.closest('a[href^="#"]') as HTMLAnchorElement | null;
if (!anchor) return;
const href = anchor.getAttribute('href');
if (!href || href === '#' || href === '#!') return;
const targetElement = document.querySelector(href);
if (targetElement) {
e.preventDefault();
lenis.scrollTo(targetElement as HTMLElement, {
offset: -80, // Offset for floating glass navbar
duration: 1.25,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
});
if (lenis) {
lenis.scrollTo(targetElement as HTMLElement, {
offset: -80, // Offset for floating glass navbar
duration: 1.25,
easing: (t: number) => Math.min(1, 1.001 - Math.pow(2, -10 * t)),
});
} else {
targetElement.scrollIntoView({ behavior: 'smooth' });
}
}
} catch {
// Fallback gracefully to default navigation if querySelector fails
@@ -79,7 +93,7 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
return () => {
cancelAnimationFrame(animId);
document.removeEventListener('click', handleAnchorClick, { capture: true });
lenis.destroy();
lenis?.destroy();
delete (window as any).__lenis;
};
}, []);