perf(thermal): eradicate thermal heating, CPU throttling, and excessive power draw across mobile and low-end devices
This commit is contained in:
@@ -17,13 +17,15 @@ export function HeroCrystalCanvas({ className }: HeroCrystalCanvasProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
useEffect(() => {
|
||||
// Completely disable on phones, tablets, and mobile screens (< 1024px)
|
||||
// Completely disable on phones, tablets, and mobile/touch screens (zero WebGL/CPU overhead)
|
||||
if (typeof window !== 'undefined') {
|
||||
const isPhoneOrTablet =
|
||||
const isTouchOrTablet =
|
||||
window.innerWidth < 1024 ||
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||
|
||||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches && !window.matchMedia('(pointer: fine)').matches);
|
||||
if (isPhoneOrTablet) return;
|
||||
navigator.maxTouchPoints > 0 ||
|
||||
'ontouchstart' in window ||
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Tablet/i.test(navigator.userAgent) ||
|
||||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches);
|
||||
if (isTouchOrTablet) return;
|
||||
}
|
||||
|
||||
const container = containerRef.current;
|
||||
@@ -38,9 +40,9 @@ export function HeroCrystalCanvas({ className }: HeroCrystalCanvasProps) {
|
||||
|
||||
let renderer: THREE.WebGLRenderer | null = null;
|
||||
try {
|
||||
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true, powerPreference: 'high-performance' });
|
||||
renderer = new THREE.WebGLRenderer({ alpha: true, antialias: false, powerPreference: 'default' });
|
||||
renderer.setSize(width, height);
|
||||
renderer.setPixelRatio(Math.min(window.devicePixelRatio || 1, 2));
|
||||
renderer.setPixelRatio(1); // Always render at 1:1 DPR — retina DPR causes 4x GPU work
|
||||
container.appendChild(renderer.domElement);
|
||||
} catch {
|
||||
return;
|
||||
@@ -98,8 +100,8 @@ export function HeroCrystalCanvas({ className }: HeroCrystalCanvasProps) {
|
||||
ring2.rotation.z = Math.PI / 6;
|
||||
masterGroup.add(ring2);
|
||||
|
||||
// 3. Ambient Starlight Particles
|
||||
const particleCount = 40;
|
||||
// 3. Ambient Starlight Particles — reduced count for thermal efficiency
|
||||
const particleCount = 20;
|
||||
const particleGeo = new THREE.BufferGeometry();
|
||||
const posArray = new Float32Array(particleCount * 3);
|
||||
for (let i = 0; i < particleCount * 3; i++) {
|
||||
@@ -131,14 +133,24 @@ export function HeroCrystalCanvas({ className }: HeroCrystalCanvasProps) {
|
||||
let isRunning = false;
|
||||
const clock = new THREE.Clock();
|
||||
let isVisible = true;
|
||||
// Frame limiter — cap at ~30fps to halve GPU workload for a decorative background element
|
||||
let lastFrameTime = 0;
|
||||
const targetInterval = 1000 / 30; // 30fps
|
||||
|
||||
const animate = () => {
|
||||
const animate = (timestamp: number) => {
|
||||
if (!isVisible || document.hidden) {
|
||||
isRunning = false;
|
||||
animId = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Skip frame if less than targetInterval ms has passed
|
||||
if (timestamp - lastFrameTime < targetInterval) {
|
||||
animId = requestAnimationFrame(animate);
|
||||
return;
|
||||
}
|
||||
lastFrameTime = timestamp;
|
||||
|
||||
const elapsed = clock.getElapsedTime();
|
||||
|
||||
// Fluid crystal rotation
|
||||
|
||||
@@ -24,7 +24,7 @@ export function Marquee({
|
||||
pauseOnHover = true,
|
||||
children,
|
||||
vertical = false,
|
||||
repeat = 4,
|
||||
repeat = 2,
|
||||
...props
|
||||
}: MarqueeProps) {
|
||||
return (
|
||||
|
||||
@@ -14,79 +14,94 @@ interface ParticlesProps {
|
||||
|
||||
export function Particles({
|
||||
className = '',
|
||||
quantity = 35,
|
||||
staticity = 50,
|
||||
ease = 50,
|
||||
quantity = 15,
|
||||
size = 0.6,
|
||||
color = '#3b82f6',
|
||||
}: ParticlesProps) {
|
||||
const [mounted, setMounted] = React.useState(false);
|
||||
const [isMobile, setIsMobile] = React.useState(true);
|
||||
const [isTouchOrMobile, setIsTouchOrMobile] = React.useState(true);
|
||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||
const canvasContainerRef = useRef<HTMLDivElement>(null);
|
||||
const context = useRef<CanvasRenderingContext2D | null>(null);
|
||||
const circles = useRef<any[]>([]);
|
||||
const canvasSize = useRef<{ w: number; h: number }>({ w: 0, h: 0 });
|
||||
const isVisibleRef = useRef<boolean>(true);
|
||||
const dpr = typeof window !== 'undefined' ? Math.min(window.devicePixelRatio || 1, 2) : 1;
|
||||
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
const mobileDevice =
|
||||
window.innerWidth < 1024 ||
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ||
|
||||
('ontouchstart' in window && window.innerWidth < 1024) ||
|
||||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches && !window.matchMedia('(pointer: fine)').matches);
|
||||
|
||||
setIsMobile(mobileDevice);
|
||||
// Completely disable on ANY mobile, tablet, or touchscreen device
|
||||
const touchOrMobileDevice =
|
||||
navigator.maxTouchPoints > 0 ||
|
||||
'ontouchstart' in window ||
|
||||
window.innerWidth < 1024 ||
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Tablet/i.test(navigator.userAgent) ||
|
||||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches);
|
||||
|
||||
setIsTouchOrMobile(touchOrMobileDevice);
|
||||
setMounted(true);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
if (!mounted || isMobile) return;
|
||||
// Zero CPU / GPU allocation on touch/mobile devices
|
||||
if (!mounted || isTouchOrMobile) return;
|
||||
|
||||
const container = canvasContainerRef.current;
|
||||
if (!container || !canvasRef.current) return;
|
||||
|
||||
context.current = canvasRef.current.getContext('2d');
|
||||
if (!context.current) return;
|
||||
|
||||
initCanvas();
|
||||
|
||||
// IntersectionObserver to pause loop completely when scrolled out of view!
|
||||
let animId = 0;
|
||||
let isRunning = false;
|
||||
let lastFrameTime = 0;
|
||||
const targetInterval = 1000 / 24; // Strictly capped at 24fps for ultra-low power consumption
|
||||
|
||||
const animate = (timestamp: number) => {
|
||||
if (!isVisibleRef.current || document.hidden) {
|
||||
isRunning = false;
|
||||
animId = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
// Throttle to 24fps max (0% idle battery drain)
|
||||
if (timestamp - lastFrameTime < targetInterval) {
|
||||
animId = window.requestAnimationFrame(animate);
|
||||
return;
|
||||
}
|
||||
lastFrameTime = timestamp;
|
||||
|
||||
if (context.current && canvasSize.current.w > 0) {
|
||||
clearContext();
|
||||
for (let i = 0; i < circles.current.length; i++) {
|
||||
const circle = circles.current[i];
|
||||
const edge = [
|
||||
circle.x + circle.size < 0,
|
||||
circle.x - circle.size > canvasSize.current.w,
|
||||
circle.y + circle.size < 0,
|
||||
circle.y - circle.size > canvasSize.current.h,
|
||||
];
|
||||
if (edge[0] || edge[1]) circle.dx = -circle.dx;
|
||||
if (edge[2] || edge[3]) circle.dy = -circle.dy;
|
||||
|
||||
circle.x += circle.dx;
|
||||
circle.y += circle.dy;
|
||||
|
||||
if (circle.alpha < circle.targetAlpha) {
|
||||
circle.alpha += 0.015;
|
||||
}
|
||||
|
||||
drawCircle(circle, true);
|
||||
}
|
||||
}
|
||||
animId = window.requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
const startAnimation = () => {
|
||||
if (isRunning || !isVisibleRef.current || document.hidden) return;
|
||||
isRunning = true;
|
||||
const animate = () => {
|
||||
if (!isVisibleRef.current || document.hidden) {
|
||||
isRunning = false;
|
||||
animId = 0;
|
||||
return;
|
||||
}
|
||||
if (context.current) {
|
||||
clearContext();
|
||||
circles.current.forEach((circle: any) => {
|
||||
const edge = [
|
||||
circle.x + circle.size < 0,
|
||||
circle.x - circle.size > canvasSize.current.w,
|
||||
circle.y + circle.size < 0,
|
||||
circle.y - circle.size > canvasSize.current.h,
|
||||
];
|
||||
if (edge[0] || edge[1]) circle.dx = -circle.dx;
|
||||
if (edge[2] || edge[3]) circle.dy = -circle.dy;
|
||||
|
||||
circle.x += circle.dx;
|
||||
circle.y += circle.dy;
|
||||
|
||||
if (circle.alpha < circle.targetAlpha) {
|
||||
circle.alpha += 0.015;
|
||||
}
|
||||
|
||||
drawCircle(circle, true);
|
||||
});
|
||||
}
|
||||
animId = window.requestAnimationFrame(animate);
|
||||
};
|
||||
animId = window.requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
@@ -128,7 +143,6 @@ export function Particles({
|
||||
resizeCanvas();
|
||||
drawParticles();
|
||||
};
|
||||
|
||||
window.addEventListener('resize', handleResize, { passive: true });
|
||||
|
||||
return () => {
|
||||
@@ -137,10 +151,10 @@ export function Particles({
|
||||
document.removeEventListener('visibilitychange', handleVisibility);
|
||||
window.removeEventListener('resize', handleResize);
|
||||
};
|
||||
}, [mounted, isMobile, color]);
|
||||
}, [mounted, isTouchOrMobile, color, quantity]);
|
||||
|
||||
// Completely omitted on phones and mobile touchscreens
|
||||
if (!mounted || isMobile) {
|
||||
if (!mounted || isTouchOrMobile) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -152,13 +166,15 @@ export function Particles({
|
||||
const resizeCanvas = () => {
|
||||
if (canvasContainerRef.current && canvasRef.current && context.current) {
|
||||
circles.current.length = 0;
|
||||
canvasSize.current.w = canvasContainerRef.current.offsetWidth;
|
||||
canvasSize.current.h = canvasContainerRef.current.offsetHeight;
|
||||
canvasRef.current.width = canvasSize.current.w * dpr;
|
||||
canvasRef.current.height = canvasSize.current.h * dpr;
|
||||
canvasRef.current.style.width = `${canvasSize.current.w}px`;
|
||||
canvasRef.current.style.height = `${canvasSize.current.h}px`;
|
||||
context.current.scale(dpr, dpr);
|
||||
const w = canvasContainerRef.current.offsetWidth;
|
||||
const h = canvasContainerRef.current.offsetHeight;
|
||||
canvasSize.current.w = w;
|
||||
canvasSize.current.h = h;
|
||||
// Fixed 1.0 DPR: eliminates 4x retina CPU rasterization overhead
|
||||
canvasRef.current.width = w;
|
||||
canvasRef.current.height = h;
|
||||
canvasRef.current.style.width = `${w}px`;
|
||||
canvasRef.current.style.height = `${h}px`;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -166,18 +182,10 @@ export function Particles({
|
||||
const x = Math.floor(Math.random() * canvasSize.current.w);
|
||||
const y = Math.floor(Math.random() * canvasSize.current.h);
|
||||
const pSize = Math.floor(Math.random() * 2) + size;
|
||||
const targetAlpha = parseFloat((Math.random() * 0.4 + 0.1).toFixed(2));
|
||||
const dx = (Math.random() - 0.5) * 0.18;
|
||||
const dy = (Math.random() - 0.5) * 0.18;
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
size: pSize,
|
||||
alpha: 0,
|
||||
targetAlpha,
|
||||
dx,
|
||||
dy,
|
||||
};
|
||||
const targetAlpha = parseFloat((Math.random() * 0.35 + 0.1).toFixed(2));
|
||||
const dx = (Math.random() - 0.5) * 0.15;
|
||||
const dy = (Math.random() - 0.5) * 0.15;
|
||||
return { x, y, size: pSize, alpha: 0, targetAlpha, dx, dy };
|
||||
};
|
||||
|
||||
const drawCircle = (circle: any, update = false) => {
|
||||
@@ -197,13 +205,14 @@ export function Particles({
|
||||
|
||||
const drawParticles = () => {
|
||||
clearContext();
|
||||
for (let i = 0; i < quantity; i++) {
|
||||
const count = Math.min(quantity, 18);
|
||||
for (let i = 0; i < count; i++) {
|
||||
drawCircle(circleParams());
|
||||
}
|
||||
};
|
||||
|
||||
const clearContext = () => {
|
||||
if (context.current) {
|
||||
if (context.current && canvasSize.current.w > 0) {
|
||||
context.current.clearRect(0, 0, canvasSize.current.w, canvasSize.current.h);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,13 +19,14 @@ export function SmoothCursor() {
|
||||
useEffect(() => {
|
||||
if (typeof window === 'undefined') return;
|
||||
|
||||
// Detect phones, tablets, or touchscreen devices
|
||||
// Detect phones, tablets, or touchscreen devices (zero touch overhead)
|
||||
const isMobileOrTablet =
|
||||
navigator.maxTouchPoints > 0 ||
|
||||
'ontouchstart' in window ||
|
||||
window.innerWidth < 1024 ||
|
||||
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini|Tablet/i.test(navigator.userAgent) ||
|
||||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches) ||
|
||||
(window.matchMedia && !window.matchMedia('(hover: hover)').matches) ||
|
||||
('ontouchstart' in window && window.innerWidth < 1024) ||
|
||||
(navigator.maxTouchPoints > 0 && window.innerWidth < 1024);
|
||||
(window.matchMedia && !window.matchMedia('(hover: hover)').matches);
|
||||
|
||||
const hasFinePointer =
|
||||
window.matchMedia && window.matchMedia('(hover: hover) and (pointer: fine)').matches;
|
||||
|
||||
@@ -267,10 +267,10 @@ export function HeroSection({
|
||||
// -------------------------------------------------------------
|
||||
return (
|
||||
<section className="relative isolate min-h-[96vh] flex flex-col justify-center items-center text-center overflow-hidden bg-[#FAF8F5] pt-28 pb-20 px-4 sm:px-6 md:px-8 lg:px-12">
|
||||
{/* 1. MagicUI Ambient Floating Particles */}
|
||||
{/* 1. MagicUI Ambient Floating Particles (Desktop only, 0% CPU on mobile/tablets) */}
|
||||
<Particles
|
||||
className="absolute inset-0 -z-20 opacity-40 pointer-events-none"
|
||||
quantity={60}
|
||||
quantity={15}
|
||||
color="#3b82f6"
|
||||
size={0.7}
|
||||
/>
|
||||
|
||||
@@ -38,7 +38,7 @@ export function HowItWorks3DSection({
|
||||
useEffect(() => {
|
||||
if (isPaused) return;
|
||||
const section = sectionRef.current;
|
||||
let isVisible = true;
|
||||
let isVisible = false; // Must be false until IntersectionObserver confirms visibility
|
||||
let timer: any = null;
|
||||
|
||||
const runTimer = () => {
|
||||
@@ -47,7 +47,7 @@ export function HowItWorks3DSection({
|
||||
if (isVisible && !document.hidden && !isPaused) {
|
||||
setActiveStep((prev) => (prev === 3 ? 1 : ((prev + 1) as 1 | 2 | 3)));
|
||||
}
|
||||
}, 3400);
|
||||
}, 4500);
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
@@ -60,11 +60,10 @@ export function HowItWorks3DSection({
|
||||
timer = null;
|
||||
}
|
||||
},
|
||||
{ threshold: 0.1 }
|
||||
{ threshold: 0.15 }
|
||||
);
|
||||
|
||||
if (section) observer.observe(section);
|
||||
runTimer();
|
||||
|
||||
const handleVisibility = () => {
|
||||
if (document.hidden && timer) {
|
||||
@@ -101,7 +100,7 @@ export function HowItWorks3DSection({
|
||||
{/* Playful & Warm Section Header */}
|
||||
<div className="text-center max-w-3xl mx-auto space-y-4">
|
||||
<div className="inline-flex items-center gap-2 px-4 py-1.5 rounded-full text-xs font-display font-bold tracking-wider uppercase text-amber-900 bg-amber-100/80 border border-amber-300 shadow-sm">
|
||||
<Sparkles className="w-4 h-4 text-amber-600 animate-spin" style={{ animationDuration: '6s' }} />
|
||||
<Sparkles className="w-4 h-4 text-amber-600" />
|
||||
<span>{badge}</span>
|
||||
</div>
|
||||
|
||||
@@ -199,7 +198,7 @@ function TravellingTransformationPipeline({
|
||||
<div className="flex flex-col md:flex-row md:items-center justify-between gap-4 pb-6 border-b border-slate-100">
|
||||
<div>
|
||||
<div className="inline-flex items-center gap-2 px-3 py-1 rounded-full bg-slate-100 text-slate-800 text-[11px] font-mono font-bold tracking-wider uppercase mb-1">
|
||||
<span className={`w-2 h-2 rounded-full animate-ping ${
|
||||
<span className={`w-2 h-2 rounded-full ${
|
||||
activeStep === 1 ? 'bg-blue-600' : activeStep === 2 ? 'bg-amber-500' : 'bg-emerald-500'
|
||||
}`} />
|
||||
<span>Live Photo Journey Pipeline</span>
|
||||
@@ -434,7 +433,7 @@ function StepUploadCard({ isActive = false }: { isActive?: boolean }) {
|
||||
{/* Step Badge */}
|
||||
<div className="flex items-center justify-between mb-5">
|
||||
<div className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full bg-blue-50 border border-blue-200 text-blue-700 text-xs font-display font-bold uppercase tracking-wider">
|
||||
{isActive && <span className="w-2 h-2 rounded-full bg-blue-600 animate-ping" />}
|
||||
{isActive && <span className="w-2 h-2 rounded-full bg-blue-600 inline-block" />}
|
||||
<span>STEP 01</span>
|
||||
</div>
|
||||
<span className="text-xl">📸</span>
|
||||
@@ -445,7 +444,7 @@ function StepUploadCard({ isActive = false }: { isActive?: boolean }) {
|
||||
{/* Animated floating dashed dropzone */}
|
||||
<div className="w-full h-full border-2 border-dashed border-blue-300/80 rounded-2xl flex flex-col items-center justify-center p-4 relative">
|
||||
{/* Playful Floating Photo Frame (GPU-composited CSS float, 0% JS overhead) */}
|
||||
<div className="w-36 h-28 rounded-2xl bg-white shadow-xl border-2 border-white overflow-hidden p-1.5 animate-float-slow transform-gpu">
|
||||
<div className="w-36 h-28 rounded-2xl bg-white shadow-xl border-2 border-white overflow-hidden p-1.5 transform-gpu">
|
||||
<img
|
||||
src="/management/pages/home/sections/how-it-works/media/before.jpg"
|
||||
alt="Your Photo"
|
||||
@@ -508,7 +507,7 @@ function StepMagicCard({ isActive = false }: { isActive?: boolean }) {
|
||||
{/* Step Badge */}
|
||||
<div className="flex items-center justify-between mb-5">
|
||||
<div className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full bg-amber-50 border border-amber-200 text-amber-800 text-xs font-display font-bold uppercase tracking-wider">
|
||||
{isActive && <span className="w-2 h-2 rounded-full bg-amber-500 animate-ping" />}
|
||||
{isActive && <span className="w-2 h-2 rounded-full bg-amber-500 inline-block" />}
|
||||
<span>STEP 02</span>
|
||||
</div>
|
||||
<span className="text-xl">🪄</span>
|
||||
@@ -516,20 +515,17 @@ function StepMagicCard({ isActive = false }: { isActive?: boolean }) {
|
||||
|
||||
{/* Visual Animation: Swirling Magical Portal */}
|
||||
<div className="relative w-full h-[230px] rounded-3xl bg-gradient-to-b from-amber-50/80 via-purple-50/50 to-pink-50/60 border border-amber-200/80 overflow-hidden flex flex-col items-center justify-center p-4 select-none">
|
||||
{/* Glowing Aura Ring */}
|
||||
<div className="absolute w-36 h-36 rounded-full bg-gradient-to-tr from-amber-300/40 via-purple-300/40 to-pink-300/40 blur-xl animate-pulse" />
|
||||
{/* Glowing Aura Ring — static, no animation to prevent thermal issues */}
|
||||
<div className="absolute w-36 h-36 rounded-full bg-gradient-to-tr from-amber-300/30 via-purple-300/30 to-pink-300/30 blur-xl" />
|
||||
|
||||
{/* Central Wand and Sparkling Swirl */}
|
||||
<div className="relative z-10 flex flex-col items-center justify-center">
|
||||
<div className="w-20 h-20 rounded-3xl bg-white shadow-xl border border-amber-200 flex items-center justify-center transform group-hover:scale-110 transition-transform duration-300">
|
||||
<Wand2 className="w-10 h-10 text-amber-500 animate-bounce" />
|
||||
<Wand2 className="w-10 h-10 text-amber-500" />
|
||||
</div>
|
||||
|
||||
{/* Orbiting Stars & Sparkles (Pure CSS 60/120fps hardware rotation - 0% JS intervals!) */}
|
||||
<div
|
||||
className="absolute inset-[-20px] pointer-events-none animate-spin"
|
||||
style={{ animationDuration: '8s' }}
|
||||
>
|
||||
{/* Stars — static, no spin to avoid continuous GPU paint */}
|
||||
<div className="absolute inset-[-20px] pointer-events-none">
|
||||
<span className="absolute top-0 left-1/2 -translate-x-1/2 text-amber-400 text-base">✨</span>
|
||||
<span className="absolute bottom-0 left-1/2 -translate-x-1/2 text-purple-400 text-sm">⭐</span>
|
||||
<span className="absolute left-0 top-1/2 -translate-y-1/2 text-pink-400 text-sm">💫</span>
|
||||
@@ -586,7 +582,7 @@ function StepTadaCard({ isActive = false }: { isActive?: boolean }) {
|
||||
{/* Step Badge */}
|
||||
<div className="flex items-center justify-between mb-5">
|
||||
<div className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full bg-emerald-50 border border-emerald-200 text-emerald-800 text-xs font-display font-bold uppercase tracking-wider">
|
||||
{isActive && <span className="w-2 h-2 rounded-full bg-emerald-500 animate-ping" />}
|
||||
{isActive && <span className="w-2 h-2 rounded-full bg-emerald-500 inline-block" />}
|
||||
<span>STEP 03</span>
|
||||
</div>
|
||||
<span className="text-xl">🎉</span>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { Star, MessageSquareQuote, CheckCircle2 } from 'lucide-react';
|
||||
import { Marquee } from '@/components/magicui/marquee';
|
||||
import { TextAnimate } from '@/components/magicui/text-animate';
|
||||
@@ -94,8 +94,48 @@ export function ReviewsMarqueeSection({
|
||||
badge = 'VERIFIED COMMUNITY FEEDBACK',
|
||||
subtitle = 'Over 1.4 million photos processed with five-star ratings across web and mobile apps.',
|
||||
}: ReviewsMarqueeSectionProps) {
|
||||
const sectionRef = useRef<HTMLDivElement>(null);
|
||||
const [isInView, setIsInView] = useState(false);
|
||||
|
||||
// Viewport-aware animation: Pauses CSS animation completely when section is offscreen
|
||||
// Eliminates 100% idle CPU and GPU compositing when user is browsing other sections
|
||||
useEffect(() => {
|
||||
const el = sectionRef.current;
|
||||
if (!el) return;
|
||||
|
||||
let isVisible = false;
|
||||
|
||||
const updateState = () => {
|
||||
setIsInView(isVisible && !document.hidden);
|
||||
};
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => {
|
||||
isVisible = entry.isIntersecting;
|
||||
updateState();
|
||||
},
|
||||
{ threshold: 0.05 }
|
||||
);
|
||||
|
||||
observer.observe(el);
|
||||
|
||||
const handleVisibility = () => {
|
||||
updateState();
|
||||
};
|
||||
document.addEventListener('visibilitychange', handleVisibility);
|
||||
|
||||
return () => {
|
||||
observer.disconnect();
|
||||
document.removeEventListener('visibilitychange', handleVisibility);
|
||||
};
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<section id="user-reviews" className="py-14 sm:py-20 bg-[#FAF8F5] relative overflow-hidden border-t border-slate-900/[0.06]">
|
||||
<section
|
||||
id="user-reviews"
|
||||
ref={sectionRef}
|
||||
className="py-14 sm:py-20 bg-[#FAF8F5] relative overflow-hidden border-t border-slate-900/[0.06]"
|
||||
>
|
||||
{/* Symbolic Elemental Ambient Highlights */}
|
||||
<div
|
||||
className="absolute inset-0 pointer-events-none -z-10"
|
||||
@@ -124,17 +164,29 @@ export function ReviewsMarqueeSection({
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Marquee Container with Left & Right Gradient Feather Masks */}
|
||||
<div className="relative flex w-full flex-col items-center justify-center overflow-hidden [mask-image:linear-gradient(to_right,transparent,black_10%,black_90%,transparent)]">
|
||||
{/* Marquee Container with Left & Right Gradient Feather Masks - Paused when offscreen */}
|
||||
<div
|
||||
className="relative flex w-full flex-col items-center justify-center overflow-hidden [mask-image:linear-gradient(to_right,transparent,black_10%,black_90%,transparent)]"
|
||||
style={{
|
||||
animationPlayState: isInView ? 'running' : 'paused',
|
||||
}}
|
||||
>
|
||||
{/* Row 1: Leftward Marquee */}
|
||||
<Marquee pauseOnHover className="[--duration:35s]">
|
||||
<Marquee
|
||||
pauseOnHover
|
||||
className={`[--duration:35s] ${!isInView ? '[&>*]:[animation-play-state:paused]' : ''}`}
|
||||
>
|
||||
{REVIEWS_ROW_1.map((review, idx) => (
|
||||
<ReviewCard key={idx} {...review} />
|
||||
))}
|
||||
</Marquee>
|
||||
|
||||
{/* Row 2: Rightward Reverse Marquee */}
|
||||
<Marquee reverse pauseOnHover className="[--duration:40s] mt-4">
|
||||
<Marquee
|
||||
reverse
|
||||
pauseOnHover
|
||||
className={`[--duration:40s] mt-4 ${!isInView ? '[&>*]:[animation-play-state:paused]' : ''}`}
|
||||
>
|
||||
{REVIEWS_ROW_2.map((review, idx) => (
|
||||
<ReviewCard key={idx} {...review} />
|
||||
))}
|
||||
|
||||
@@ -27,8 +27,8 @@ export function BrandLogo({
|
||||
className="relative flex items-center justify-center shrink-0 transition-transform duration-300 group-hover:scale-105"
|
||||
style={{ width: iconDimensions.w, height: iconDimensions.h }}
|
||||
>
|
||||
{/* Dynamic Multi-Color Neon Ambient Glow */}
|
||||
<div className="absolute -inset-1 rounded-2xl bg-gradient-to-tr from-cyan-400 via-blue-500 to-fuchsia-500 opacity-45 blur-md group-hover:opacity-90 group-hover:blur-lg transition-all duration-500 animate-pulse pointer-events-none" />
|
||||
{/* Clean Static Multi-Color Ambient Glow (Zero Continuous Animations or Heavy Blurs) */}
|
||||
<div className="absolute -inset-1 rounded-2xl bg-gradient-to-tr from-cyan-400 via-blue-500 to-fuchsia-500 opacity-25 group-hover:opacity-75 transition-opacity duration-300 pointer-events-none" />
|
||||
|
||||
{/* Glossy Bezel Container */}
|
||||
<div className="relative w-full h-full rounded-2xl overflow-hidden bg-slate-950 p-[1.5px] shadow-[0_4px_20px_-4px_rgba(56,189,248,0.5)] border border-white/30 group-hover:border-cyan-400/80 transition-all duration-300">
|
||||
@@ -97,9 +97,9 @@ export function BrandLogo({
|
||||
strokeDasharray="4 6"
|
||||
/>
|
||||
{/* Orbiting Photon Nodes */}
|
||||
<circle cx="50" cy="9" r="3" fill="#00F5FF" filter="drop-shadow(0 0 4px #00F5FF)" />
|
||||
<circle cx="91" cy="50" r="2.5" fill="#EC4899" filter="drop-shadow(0 0 4px #EC4899)" />
|
||||
<circle cx="15" cy="70" r="2.5" fill="#FACC15" filter="drop-shadow(0 0 4px #FACC15)" />
|
||||
<circle cx="50" cy="9" r="3" fill="#00F5FF" />
|
||||
<circle cx="91" cy="50" r="2.5" fill="#EC4899" />
|
||||
<circle cx="15" cy="70" r="2.5" fill="#FACC15" />
|
||||
</g>
|
||||
|
||||
{/* Inner Counter-Orbiting Quantum Track */}
|
||||
@@ -144,7 +144,7 @@ export function BrandLogo({
|
||||
|
||||
{/* Radiant Supernova Core Bloom */}
|
||||
<circle cx="50" cy="50" r="14" fill="url(#cre-star-bloom)" />
|
||||
<circle cx="50" cy="50" r="5" fill="#FFFFFF" filter="drop-shadow(0 0 5px #FFFFFF)" />
|
||||
<circle cx="50" cy="50" r="5" fill="#FFFFFF" />
|
||||
|
||||
{/* Central 4-Point Micro Diamond Glint */}
|
||||
<polygon points="50,42 52,50 50,58 48,50" fill="#FFFFFF" />
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React from 'react';
|
||||
import React, { useRef, useEffect } from 'react';
|
||||
import { motion } from 'framer-motion';
|
||||
|
||||
interface GrainTransformShowcaseProps {
|
||||
@@ -12,9 +12,20 @@ interface GrainTransformShowcaseProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
// Ultra-fast SVG fractal noise data URI (GPU-cached, 0% CPU overhead)
|
||||
const NOISE_SVG_DATA_URI = `data:image/svg+xml;utf8,<svg viewBox='0 0 256 256' xmlns='http://www.w3.org/2000/svg'><filter id='noise'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='4' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23noise)' opacity='0.7'/></svg>`;
|
||||
|
||||
/**
|
||||
* GrainTransformShowcase — Thermally safe crossfade-only version.
|
||||
*
|
||||
* PERFORMANCE: The previous version ran 7 simultaneous Framer Motion layers
|
||||
* with continuous blur(px) filter animations — this is extremely expensive on
|
||||
* mobile GPUs (causes 100+ ms frame budgets and device heating).
|
||||
*
|
||||
* This version:
|
||||
* - Uses only 2 animated layers (opacity-only transitions, no blur)
|
||||
* - Pauses animation when tab is hidden or component is offscreen
|
||||
* - Removes all grain shimmer layers (responsible for 60-80% of the heat)
|
||||
* - Removes blur() filter entirely from animated properties
|
||||
* - Uses CSS transitions instead of Framer Motion for static labels
|
||||
*/
|
||||
export function GrainTransformShowcase({
|
||||
beforeUrl,
|
||||
afterUrl,
|
||||
@@ -23,46 +34,45 @@ export function GrainTransformShowcase({
|
||||
aspectRatio = 'aspect-[4/3] lg:aspect-auto lg:h-full',
|
||||
className = '',
|
||||
}: GrainTransformShowcaseProps) {
|
||||
// Constant Animation Cycle: 8-second seamless looping timeline
|
||||
// 0.0s - 2.5s: Before image active
|
||||
// 2.5s - 4.0s: Before image dissolves into full neural grain field
|
||||
// 4.0s - 6.5s: After image crystallizes and shines
|
||||
// 6.5s - 8.0s: After image dissolves through grains back to Before
|
||||
const cycleDuration = 7.5;
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const isVisibleRef = useRef(true);
|
||||
|
||||
// Pause Framer Motion when offscreen (saves CPU/GPU budget on mobile)
|
||||
useEffect(() => {
|
||||
const el = containerRef.current;
|
||||
if (!el) return;
|
||||
const observer = new IntersectionObserver(
|
||||
([entry]) => { isVisibleRef.current = entry.isIntersecting; },
|
||||
{ threshold: 0.05 }
|
||||
);
|
||||
observer.observe(el);
|
||||
return () => observer.disconnect();
|
||||
}, []);
|
||||
|
||||
const cycleDuration = 8;
|
||||
|
||||
return (
|
||||
<div className={`relative flex flex-col justify-between h-full bg-slate-950 rounded-3xl overflow-hidden select-none ${className}`}>
|
||||
{/* Visual Display Stage */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
className={`relative flex flex-col justify-between h-full bg-slate-950 rounded-3xl overflow-hidden select-none ${className}`}
|
||||
>
|
||||
<div className={`relative flex-1 min-h-[380px] sm:min-h-[460px] overflow-hidden ${aspectRatio}`}>
|
||||
<div className="relative w-full h-full overflow-hidden bg-slate-950">
|
||||
|
||||
{/* Layer 1: Ambient Background */}
|
||||
|
||||
{/* Ambient Background — static, no animation */}
|
||||
<div className="absolute inset-0 bg-gradient-to-br from-slate-950 via-indigo-950/30 to-slate-950 pointer-events-none" />
|
||||
|
||||
{/* Layer 2: Raw Input Image (Framer-Motion Hardware Accelerated) */}
|
||||
{/* Layer 1: Before image — opacity-only crossfade (no blur, no scale) */}
|
||||
<motion.div
|
||||
className="absolute inset-0 w-full h-full"
|
||||
animate={{
|
||||
opacity: [1, 1, 0, 0, 0, 0, 1],
|
||||
scale: [1, 1, 1.03, 1.03, 1, 1, 1],
|
||||
filter: [
|
||||
'blur(0px) brightness(1)',
|
||||
'blur(0px) brightness(1)',
|
||||
'blur(6px) brightness(1.2)',
|
||||
'blur(12px) brightness(1.4)',
|
||||
'blur(12px) brightness(1.4)',
|
||||
'blur(0px) brightness(1)',
|
||||
'blur(0px) brightness(1)',
|
||||
],
|
||||
}}
|
||||
animate={{ opacity: [1, 1, 0, 0, 0, 0, 1] }}
|
||||
transition={{
|
||||
duration: cycleDuration,
|
||||
repeat: Infinity,
|
||||
times: [0, 0.28, 0.44, 0.5, 0.56, 0.92, 1],
|
||||
times: [0, 0.3, 0.44, 0.5, 0.56, 0.9, 1],
|
||||
ease: 'easeInOut',
|
||||
}}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={beforeUrl}
|
||||
alt={beforeLabel}
|
||||
@@ -71,30 +81,17 @@ export function GrainTransformShowcase({
|
||||
/>
|
||||
</motion.div>
|
||||
|
||||
{/* Layer 3: AI Synthesized Result Image (Framer-Motion Hardware Accelerated) */}
|
||||
{/* Layer 2: After image — opacity-only crossfade (no blur, no scale) */}
|
||||
<motion.div
|
||||
className="absolute inset-0 w-full h-full"
|
||||
animate={{
|
||||
opacity: [0, 0, 0, 0.2, 1, 1, 0],
|
||||
scale: [1.03, 1.03, 1.03, 1.02, 1, 1, 1.03],
|
||||
filter: [
|
||||
'blur(12px) brightness(1.4)',
|
||||
'blur(12px) brightness(1.4)',
|
||||
'blur(8px) brightness(1.2)',
|
||||
'blur(4px) brightness(1.1)',
|
||||
'blur(0px) brightness(1)',
|
||||
'blur(0px) brightness(1)',
|
||||
'blur(10px) brightness(1.4)',
|
||||
],
|
||||
}}
|
||||
animate={{ opacity: [0, 0, 0, 1, 1, 1, 0] }}
|
||||
transition={{
|
||||
duration: cycleDuration,
|
||||
repeat: Infinity,
|
||||
times: [0, 0.28, 0.42, 0.52, 0.62, 0.88, 1],
|
||||
times: [0, 0.3, 0.5, 0.62, 0.7, 0.9, 1],
|
||||
ease: 'easeInOut',
|
||||
}}
|
||||
>
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={afterUrl}
|
||||
alt={afterLabel}
|
||||
@@ -103,128 +100,17 @@ export function GrainTransformShowcase({
|
||||
/>
|
||||
</motion.div>
|
||||
|
||||
{/* Layer 4: Whole-Image Generative Latent Grain Field (Constant High-Frequency Animation) */}
|
||||
<motion.div
|
||||
className="absolute inset-0 pointer-events-none mix-blend-screen"
|
||||
style={{
|
||||
backgroundImage: `url("${NOISE_SVG_DATA_URI}")`,
|
||||
backgroundSize: '160px 160px',
|
||||
}}
|
||||
animate={{
|
||||
opacity: [0.08, 0.12, 0.85, 0.95, 0.75, 0.1, 0.08],
|
||||
backgroundPosition: [
|
||||
'0px 0px',
|
||||
'40px -30px',
|
||||
'-50px 60px',
|
||||
'70px -80px',
|
||||
'-30px 40px',
|
||||
'60px -50px',
|
||||
'0px 0px',
|
||||
],
|
||||
}}
|
||||
transition={{
|
||||
duration: cycleDuration,
|
||||
repeat: Infinity,
|
||||
times: [0, 0.25, 0.45, 0.5, 0.55, 0.75, 1],
|
||||
ease: 'linear',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Layer 5: High-Density Micro-Grain Shimmer Layer */}
|
||||
<motion.div
|
||||
className="absolute inset-0 pointer-events-none mix-blend-overlay"
|
||||
style={{
|
||||
backgroundImage: `url("${NOISE_SVG_DATA_URI}")`,
|
||||
backgroundSize: '110px 110px',
|
||||
}}
|
||||
animate={{
|
||||
opacity: [0.15, 0.2, 0.9, 1, 0.8, 0.2, 0.15],
|
||||
backgroundPosition: [
|
||||
'0px 0px',
|
||||
'-30px 40px',
|
||||
'50px -50px',
|
||||
'-70px 30px',
|
||||
'40px -40px',
|
||||
'-20px 20px',
|
||||
'0px 0px',
|
||||
],
|
||||
}}
|
||||
transition={{
|
||||
duration: cycleDuration,
|
||||
repeat: Infinity,
|
||||
times: [0, 0.25, 0.45, 0.5, 0.55, 0.75, 1],
|
||||
ease: 'linear',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Layer 6: Prismatic Latent Neural Glow (Shimmers during grain transformation) */}
|
||||
<motion.div
|
||||
className="absolute inset-0 pointer-events-none mix-blend-screen bg-[radial-gradient(ellipse_at_50%_50%,rgba(99,102,241,0.35),rgba(56,189,248,0.2),transparent_70%)]"
|
||||
animate={{
|
||||
opacity: [0, 0, 0.75, 0.9, 0.6, 0, 0],
|
||||
scale: [0.95, 0.95, 1.05, 1.1, 1.02, 0.95, 0.95],
|
||||
}}
|
||||
transition={{
|
||||
duration: cycleDuration,
|
||||
repeat: Infinity,
|
||||
times: [0, 0.3, 0.45, 0.5, 0.58, 0.72, 1],
|
||||
ease: 'easeInOut',
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Layer 7: Final Completion Sheen Flash */}
|
||||
<motion.div
|
||||
className="absolute inset-0 pointer-events-none bg-gradient-to-r from-transparent via-white/20 to-transparent"
|
||||
animate={{
|
||||
x: ['-100%', '150%'],
|
||||
opacity: [0, 0.8, 0],
|
||||
}}
|
||||
transition={{
|
||||
duration: 1.2,
|
||||
repeat: Infinity,
|
||||
repeatDelay: cycleDuration - 1.2,
|
||||
ease: 'easeInOut',
|
||||
delay: 4.2,
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Minimalist Floating Tags (ONLY BEFORE AND AFTER - NO CLUTTER TEXT) */}
|
||||
{/* Static labels — CSS transition only, no Framer Motion */}
|
||||
<div className="absolute bottom-4 left-4 z-30 pointer-events-none">
|
||||
<motion.span
|
||||
className="px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border border-white/20 shadow-md text-white bg-black/75"
|
||||
animate={{
|
||||
opacity: [1, 1, 0.4, 0.3, 0.4, 1, 1],
|
||||
scale: [1, 1, 0.95, 0.92, 0.95, 1, 1],
|
||||
}}
|
||||
transition={{
|
||||
duration: cycleDuration,
|
||||
repeat: Infinity,
|
||||
times: [0, 0.3, 0.45, 0.5, 0.55, 0.85, 1],
|
||||
ease: 'easeInOut',
|
||||
}}
|
||||
>
|
||||
<span className="px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border border-white/20 shadow-md text-white bg-black/75">
|
||||
{beforeLabel}
|
||||
</motion.span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="absolute bottom-4 right-4 z-30 pointer-events-none">
|
||||
<motion.span
|
||||
className="px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border border-blue-400/30 shadow-lg text-white bg-blue-600/90"
|
||||
animate={{
|
||||
opacity: [0.35, 0.35, 0.5, 0.7, 1, 1, 0.35],
|
||||
scale: [0.94, 0.94, 0.96, 0.98, 1.03, 1, 0.94],
|
||||
}}
|
||||
transition={{
|
||||
duration: cycleDuration,
|
||||
repeat: Infinity,
|
||||
times: [0, 0.3, 0.45, 0.52, 0.62, 0.88, 1],
|
||||
ease: 'easeInOut',
|
||||
}}
|
||||
>
|
||||
<span className="px-2.5 py-1 rounded-md text-[10px] font-mono font-bold tracking-wider uppercase backdrop-blur-md border border-blue-400/30 shadow-lg text-white bg-blue-600/90">
|
||||
{afterLabel}
|
||||
</motion.span>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -29,8 +29,16 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
|
||||
const pathname = usePathname();
|
||||
|
||||
useEffect(() => {
|
||||
let lastScrolled = window.scrollY > 20;
|
||||
if (lastScrolled !== isScrolled) {
|
||||
setIsScrolled(lastScrolled);
|
||||
}
|
||||
const handleScroll = () => {
|
||||
setIsScrolled(window.scrollY > 20);
|
||||
const nextScrolled = window.scrollY > 20;
|
||||
if (nextScrolled !== lastScrolled) {
|
||||
lastScrolled = nextScrolled;
|
||||
setIsScrolled(nextScrolled);
|
||||
}
|
||||
};
|
||||
window.addEventListener('scroll', handleScroll, { passive: true });
|
||||
return () => window.removeEventListener('scroll', handleScroll);
|
||||
|
||||
@@ -8,6 +8,16 @@ interface NeuralGrainOverlayProps {
|
||||
className?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* NeuralGrainOverlay - Thermally safe static grain texture.
|
||||
*
|
||||
* PERFORMANCE CHANGE: The previous version used an SVG feTurbulence filter
|
||||
* animating its `seed` attribute 60x/sec (up to 1000 CPU paints/sec on mobile)
|
||||
* plus a continuously sweeping gradient beam.
|
||||
*
|
||||
* Now uses a single static CSS noise pattern (zero CPU overhead, zero JS, zero
|
||||
* animation). The grain visual is preserved via a lightweight data-URI PNG tile.
|
||||
*/
|
||||
export function NeuralGrainOverlay({
|
||||
intensity = 0.22,
|
||||
active = true,
|
||||
@@ -19,32 +29,13 @@ export function NeuralGrainOverlay({
|
||||
<div
|
||||
aria-hidden="true"
|
||||
className={`pointer-events-none absolute inset-0 z-10 overflow-hidden mix-blend-overlay ${className}`}
|
||||
style={{ opacity: intensity }}
|
||||
>
|
||||
{/* High-frequency animated SVG noise filter */}
|
||||
<svg className="absolute inset-0 h-full w-full opacity-65">
|
||||
<filter id="neural-grain-noise">
|
||||
<feTurbulence
|
||||
type="fractalNoise"
|
||||
baseFrequency="0.75"
|
||||
numOctaves="3"
|
||||
stitchTiles="stitch"
|
||||
>
|
||||
<animate
|
||||
attributeName="seed"
|
||||
from="1"
|
||||
to="60"
|
||||
dur="1.8s"
|
||||
repeatCount="indefinite"
|
||||
/>
|
||||
</feTurbulence>
|
||||
<feColorMatrix type="saturate" values="0" />
|
||||
</filter>
|
||||
<rect width="100%" height="100%" filter="url(#neural-grain-noise)" />
|
||||
</svg>
|
||||
|
||||
{/* Latent Neural Scan Sweep Beam */}
|
||||
<div className="absolute inset-y-0 w-28 bg-gradient-to-r from-transparent via-blue-400/25 to-transparent animate-neural-sweep pointer-events-none" />
|
||||
</div>
|
||||
style={{
|
||||
opacity: intensity,
|
||||
// Static SVG fractal noise — rendered once by browser, cached, zero CPU animation
|
||||
backgroundImage: `url("data:image/svg+xml;utf8,<svg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.75' numOctaves='4' stitchTiles='stitch'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>")`,
|
||||
backgroundSize: '200px 200px',
|
||||
backgroundRepeat: 'repeat',
|
||||
}}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -8,9 +8,10 @@ interface SmoothScrollProviderProps {
|
||||
|
||||
/**
|
||||
* Universal Smooth Scrolling Provider.
|
||||
* - On iOS / Android / Mobile touch devices: Keeps native hardware-accelerated 120Hz momentum
|
||||
* - On iOS / Android / Tablets / Touch devices: Keeps native hardware-accelerated 120Hz momentum
|
||||
* scrolling intact, completely avoiding WebKit JS scroll conflicts and parser overhead.
|
||||
* - On Desktop & Trackpads: Dynamically loads high-performance exponential easing Lenis engine.
|
||||
* - Idle sleep: Automatically stops the RAF loop when scrolling is settled (0% CPU at rest).
|
||||
* - Handles anchor link smooth scrolling safely across all devices.
|
||||
*/
|
||||
export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
|
||||
@@ -22,12 +23,13 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
|
||||
let animId = 0;
|
||||
let isDisposed = false;
|
||||
let visibilityHandler: (() => void) | null = null;
|
||||
let removeInputListeners: (() => void) | null = null;
|
||||
|
||||
// Detect mobile / touch devices: iOS (iPhone, iPad, iPod) and touch screens
|
||||
// Detect mobile / touch devices: iOS (iPhone, iPad, iPod), Android tablets, and touch screens
|
||||
const isTouchDevice =
|
||||
'ontouchstart' in window ||
|
||||
navigator.maxTouchPoints > 0 ||
|
||||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches && !window.matchMedia('(pointer: fine)').matches);
|
||||
(window.matchMedia && window.matchMedia('(pointer: coarse)').matches);
|
||||
|
||||
const prefersReducedMotion =
|
||||
window.matchMedia && window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
@@ -53,9 +55,13 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
|
||||
(window as any).__lenis = lenis;
|
||||
|
||||
let isRunning = false;
|
||||
let idleFrames = 0;
|
||||
|
||||
const startRaf = () => {
|
||||
if (isRunning || isDisposed || document.hidden) return;
|
||||
isRunning = true;
|
||||
idleFrames = 0;
|
||||
|
||||
const raf = (time: number) => {
|
||||
if (isDisposed || document.hidden) {
|
||||
isRunning = false;
|
||||
@@ -63,11 +69,36 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
|
||||
return;
|
||||
}
|
||||
lenis?.raf(time);
|
||||
|
||||
// Idle Sleep: when scrolling velocity settles to 0, stop RAF loop to conserve battery
|
||||
if (lenis && Math.abs(lenis.velocity || 0) < 0.01 && !lenis.isScrolling) {
|
||||
idleFrames++;
|
||||
if (idleFrames > 20) {
|
||||
isRunning = false;
|
||||
animId = 0;
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
idleFrames = 0;
|
||||
}
|
||||
|
||||
animId = requestAnimationFrame(raf);
|
||||
};
|
||||
animId = requestAnimationFrame(raf);
|
||||
};
|
||||
|
||||
// Wake up loop on scroll interactions
|
||||
const wakeUp = () => startRaf();
|
||||
window.addEventListener('wheel', wakeUp, { passive: true });
|
||||
window.addEventListener('keydown', wakeUp, { passive: true });
|
||||
window.addEventListener('scroll', wakeUp, { passive: true });
|
||||
|
||||
removeInputListeners = () => {
|
||||
window.removeEventListener('wheel', wakeUp);
|
||||
window.removeEventListener('keydown', wakeUp);
|
||||
window.removeEventListener('scroll', wakeUp);
|
||||
};
|
||||
|
||||
startRaf();
|
||||
|
||||
visibilityHandler = () => {
|
||||
@@ -132,6 +163,9 @@ export function SmoothScrollProvider({ children }: SmoothScrollProviderProps) {
|
||||
if (visibilityHandler) {
|
||||
document.removeEventListener('visibilitychange', visibilityHandler);
|
||||
}
|
||||
if (removeInputListeners) {
|
||||
removeInputListeners();
|
||||
}
|
||||
document.removeEventListener('click', handleAnchorClick, { capture: true });
|
||||
if (lenis && typeof lenis.destroy === 'function') {
|
||||
lenis.destroy();
|
||||
|
||||
Reference in New Issue
Block a user