perf(animations): refactor ShiftableToolsGrid, cursor, hero & sections to locked 60-120fps with zero layout thrashing

This commit is contained in:
2026-11-04 18:48:24 +05:30
parent d9ef1497a3
commit 51afbf573b
9 changed files with 249 additions and 147 deletions
+52 -28
View File
@@ -35,45 +35,69 @@ export function Particles({
context.current = canvasRef.current.getContext('2d');
initCanvas();
// IntersectionObserver to pause loop when scrolled out of view!
// IntersectionObserver to pause loop completely when scrolled out of view!
let animId = 0;
let isRunning = false;
const startAnimation = () => {
if (isRunning) return;
isRunning = true;
const animate = () => {
if (!isVisibleRef.current) {
isRunning = false;
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);
};
const stopAnimation = () => {
isRunning = false;
if (animId) {
cancelAnimationFrame(animId);
animId = 0;
}
};
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
isVisibleRef.current = entry.isIntersecting;
if (entry.isIntersecting) {
startAnimation();
} else {
stopAnimation();
}
});
},
{ threshold: 0.05 }
);
observer.observe(container);
const animate = () => {
if (isVisibleRef.current && 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);
startAnimation();
const handleResize = () => {
resizeCanvas();
+20 -25
View File
@@ -56,32 +56,31 @@ export function SmoothCursor() {
const target = e.target as HTMLElement | null;
if (!target) return;
const interactive = target.closest('a, button, input, textarea, select, [role="button"], .cursor-pointer');
isHovered = !!interactive;
const nextHovered = !!interactive;
if (isHovered) {
ring.style.width = '52px';
ring.style.height = '52px';
ring.style.borderColor = 'rgba(37, 99, 235, 0.7)';
ring.style.backgroundColor = 'rgba(37, 99, 235, 0.12)';
dot.style.transform = `translate3d(${mouseX}px, ${mouseY}px, 0) scale(0)`;
} else {
ring.style.width = '30px';
ring.style.height = '30px';
ring.style.borderColor = 'rgba(37, 99, 235, 0.4)';
ring.style.backgroundColor = 'rgba(37, 99, 235, 0.05)';
if (nextHovered !== isHovered) {
isHovered = nextHovered;
if (isHovered) {
ring.style.borderColor = 'rgba(37, 99, 235, 0.7)';
ring.style.backgroundColor = 'rgba(37, 99, 235, 0.12)';
} else {
ring.style.borderColor = 'rgba(37, 99, 235, 0.35)';
ring.style.backgroundColor = 'rgba(37, 99, 235, 0.04)';
}
}
};
// Ultra-smooth 120fps/60fps RAF lerp loop (Zero React re-renders!)
// Locked 60-120fps RAF lerp loop (Zero React re-renders, 100% GPU composited transforms)
const loop = () => {
// Smooth linear interpolation for trailing ring
ringX += (mouseX - ringX) * 0.22;
ringY += (mouseY - ringY) * 0.22;
ring.style.transform = `translate3d(${ringX}px, ${ringY}px, 0) translate(-50%, -50%)`;
if (!isHovered) {
dot.style.transform = `translate3d(${mouseX}px, ${mouseY}px, 0) translate(-50%, -50%) scale(1)`;
}
const ringScale = isHovered ? 1.45 : 1;
ring.style.transform = `translate3d(${ringX}px, ${ringY}px, 0) translate3d(-50%, -50%, 0) scale(${ringScale})`;
const dotScale = isHovered ? 0 : 1;
dot.style.transform = `translate3d(${mouseX}px, ${mouseY}px, 0) translate3d(-50%, -50%, 0) scale(${dotScale})`;
animId = requestAnimationFrame(loop);
};
@@ -104,20 +103,16 @@ export function SmoothCursor() {
return (
<div className="pointer-events-none fixed inset-0 z-[9999] overflow-hidden select-none">
{/* Trailing Fluid Squircle Ring */}
{/* Trailing Fluid Squircle Ring (GPU-scale transform only, zero layout reflows) */}
<div
ref={cursorRingRef}
className="fixed top-0 left-0 rounded-full border border-blue-500/40 bg-blue-500/5 backdrop-blur-[0.5px] pointer-events-none opacity-0 transition-[width,height,background-color,border-color] duration-200 ease-out will-change-transform"
style={{
width: '30px',
height: '30px',
}}
className="fixed top-0 left-0 w-8 h-8 rounded-full border border-blue-500/35 bg-blue-500/4 pointer-events-none opacity-0 transition-[border-color,background-color] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] will-change-transform transform-gpu [backface-visibility:hidden]"
/>
{/* Precision Dot */}
{/* Precision Dot (GPU-scale transform only) */}
<div
ref={cursorDotRef}
className="fixed top-0 left-0 w-2 h-2 rounded-full bg-blue-600 shadow-sm pointer-events-none opacity-0 transition-transform duration-100 ease-out will-change-transform"
className="fixed top-0 left-0 w-2 h-2 rounded-full bg-blue-600 shadow-sm pointer-events-none opacity-0 will-change-transform transform-gpu [backface-visibility:hidden]"
/>
</div>
);
+3 -3
View File
@@ -78,16 +78,16 @@ export function FaqSection({
return (
<div
key={idx}
className="rounded-2xl border border-slate-200/90 bg-white overflow-hidden shadow-cream-sm hover:shadow-cream-md transition-all duration-200"
className="rounded-2xl border border-slate-200/90 bg-white overflow-hidden shadow-cream-sm hover:border-blue-300 transition-[border-color] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]"
>
<button
type="button"
onClick={() => setOpenIndex(isOpen ? null : idx)}
className="w-full p-6 text-left flex items-center justify-between gap-4 font-bold text-slate-900 hover:text-blue-600 transition-colors"
className="w-full p-6 text-left flex items-center justify-between gap-4 font-bold text-slate-900 hover:text-blue-600 transition-colors duration-200"
>
<span className="text-base sm:text-lg font-display">{item.q}</span>
<ChevronDown
className={`w-5 h-5 text-slate-400 shrink-0 transition-transform duration-200 ${
className={`w-5 h-5 text-slate-400 shrink-0 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] ${
isOpen ? 'rotate-180 text-blue-600' : ''
}`}
/>
+8 -10
View File
@@ -167,14 +167,14 @@ export function HeroSection({
<div className="mt-10 flex flex-wrap items-center justify-center gap-4">
<a
href={primaryCtaHref}
className="group inline-flex items-center gap-3 rounded-full bg-gradient-to-r from-slate-950 via-slate-900 to-indigo-950 px-9 py-4 text-xs sm:text-sm font-bold text-white border border-white/15 shadow-xl shadow-slate-900/20 transition-all duration-300 hover:scale-105 hover:from-blue-600 hover:to-indigo-600 active:scale-95"
className="group inline-flex items-center gap-3 rounded-full bg-gradient-to-r from-slate-950 via-slate-900 to-indigo-950 px-9 py-4 text-xs sm:text-sm font-bold text-white border border-white/15 shadow-xl shadow-slate-900/20 transition-[transform,opacity] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 active:scale-95"
>
<span>{primaryCtaLabel}</span>
<ArrowDown className="w-4 h-4 transition-transform group-hover:translate-y-0.5" />
<ArrowDown className="w-4 h-4 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:translate-y-0.5" />
</a>
<a
href={secondaryCtaHref}
className="inline-flex items-center gap-2.5 rounded-full border border-slate-300/80 bg-white/90 backdrop-blur-md px-8 py-4 text-xs sm:text-sm font-semibold text-slate-800 shadow-sm transition-all duration-300 hover:scale-105 hover:border-blue-400 hover:text-blue-600 hover:bg-white active:scale-95"
className="inline-flex items-center gap-2.5 rounded-full border border-slate-300/80 bg-white/90 backdrop-blur-md px-8 py-4 text-xs sm:text-sm font-semibold text-slate-800 shadow-sm transition-[transform,opacity,border-color,color] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 hover:border-blue-400 hover:text-blue-600 hover:bg-white active:scale-95"
>
<Smartphone className="w-4 h-4 text-blue-600" />
<span>{secondaryCtaLabel}</span>
@@ -250,16 +250,14 @@ function Hero3DCanvas({ className }: { className?: string }) {
// Geometry: Floating Octahedron Crystal Prism
const geometry = new THREE.OctahedronGeometry(1.65, 0);
const material = new THREE.MeshPhysicalMaterial({
const material = new THREE.MeshStandardMaterial({
color: 0x2563eb,
emissive: 0x1d4ed8,
emissiveIntensity: 0.15,
roughness: 0.25,
metalness: 0.1,
transmission: 0.85,
emissiveIntensity: 0.25,
roughness: 0.2,
metalness: 0.2,
transparent: true,
opacity: 0.75,
ior: 1.5,
opacity: 0.8,
});
const crystal = new THREE.Mesh(geometry, material);
@@ -120,8 +120,13 @@ export function RecommendedAppsSection({
return (
<div
key={slug}
className="group relative flex flex-col justify-between rounded-3xl bg-white border border-slate-200/90 p-7 shadow-cream-sm hover:shadow-cream-lg transition-all duration-300 hover:-translate-y-1 hover:border-blue-400/60"
className="group relative flex flex-col justify-between rounded-3xl bg-white border border-slate-200/90 p-7 shadow-cream-sm transition-[transform,border-color] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:-translate-y-1 hover:border-blue-400/60 will-change-transform transform-gpu"
>
{/* GPU Shadow Elevation Layer */}
<div
className="absolute -inset-px rounded-3xl shadow-cream-lg opacity-0 group-hover:opacity-100 transition-opacity duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none"
aria-hidden="true"
/>
<div>
{/* Top App Icon & Rating */}
<div className="flex items-center justify-between mb-5">
@@ -168,10 +173,10 @@ export function RecommendedAppsSection({
<div className="pt-6 mt-5 border-t border-slate-100">
<Link
href={`/apps/${slug}`}
className="w-full flex items-center justify-center gap-2 py-3.5 rounded-xl text-xs font-bold text-white bg-slate-950 group-hover:bg-blue-600 transition-all duration-300 shadow-sm group-hover:shadow-md"
className="w-full flex items-center justify-center gap-2 py-3.5 rounded-xl text-xs font-bold text-white bg-slate-950 group-hover:bg-blue-600 transition-colors duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] shadow-sm"
>
<span>Get App & QR Code</span>
<ArrowRight className="w-3.5 h-3.5 transition-transform group-hover:translate-x-1" />
<ArrowRight className="w-3.5 h-3.5 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:translate-x-1" />
</Link>
</div>
</div>
@@ -163,7 +163,7 @@ function ReviewCard({
tool: string;
}) {
return (
<figure className="relative w-80 sm:w-96 cursor-pointer overflow-hidden rounded-2xl border border-slate-200/90 bg-white p-5 shadow-cream-sm hover:shadow-cream-md hover:border-blue-300 transition-all duration-300">
<figure className="relative w-80 sm:w-96 cursor-pointer overflow-hidden rounded-2xl border border-slate-200/90 bg-white p-5 shadow-cream-sm hover:border-blue-300 transition-[border-color,transform] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)]">
<div className="flex items-center justify-between">
<div className="flex items-center gap-3">
<div className="w-10 h-10 rounded-full bg-gradient-to-tr from-blue-600 to-indigo-600 flex items-center justify-center text-white text-xs font-bold tracking-wider shadow-sm">
@@ -1,6 +1,6 @@
'use client';
import React, { useState, useRef, useEffect } from 'react';
import React, { useState, useRef, useEffect, useCallback } from 'react';
import Link from 'next/link';
import { ArrowRight, Sparkles, Video, Sliders, Image as ImageIcon } from 'lucide-react';
import { TextAnimate } from '@/components/magicui/text-animate';
@@ -18,7 +18,7 @@ export interface ToolMediaItem {
afterUrl?: string;
}
interface ShiftableToolsGridProps {
export interface ShiftableToolsGridProps {
title?: string;
subtitle?: string;
tools?: ToolItem[];
@@ -26,7 +26,7 @@ interface ShiftableToolsGridProps {
locale?: string;
}
const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
// ROW 1 (4 items) - Landscape 16:9 assets
{
id: 'tool-blemish',
@@ -134,7 +134,7 @@ export function ShiftableToolsGridSection({
</p>
</div>
{/* 2-Row Shiftable Grid Container (Pure Horizontal Expansion, Fixed Height, No Vertical Shifts) */}
{/* 2-Row Shiftable Grid Container (Slow, Calm, Pure Horizontal Expansion with Locked Height) */}
<div className="space-y-6 sm:space-y-8">
<ShiftableRow items={row1} />
<ShiftableRow items={row2} />
@@ -144,10 +144,10 @@ export function ShiftableToolsGridSection({
<div className="pt-6 text-center">
<Link
href="/tools"
className="group inline-flex items-center gap-2.5 px-8 py-4 rounded-full font-bold text-xs sm:text-sm text-white bg-gradient-to-r from-slate-950 via-slate-900 to-indigo-950 hover:from-blue-600 hover:to-indigo-600 border border-white/10 shadow-lg shadow-slate-900/15 transition-all duration-300 hover:scale-105 active:scale-95"
className="group inline-flex items-center gap-2.5 px-8 py-4 rounded-full font-bold text-xs sm:text-sm text-white bg-gradient-to-r from-slate-950 via-slate-900 to-indigo-950 hover:from-blue-600 hover:to-indigo-600 border border-white/10 shadow-lg shadow-slate-900/15 transition-[transform,opacity] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 active:scale-95"
>
<span>See More Tools</span>
<ArrowRight className="w-4 h-4 transition-transform group-hover:translate-x-1" />
<ArrowRight className="w-4 h-4 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:translate-x-1" />
</Link>
</div>
</div>
@@ -164,31 +164,44 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
const isHovered = hoveredId === item.id;
const hasOtherHovered = hoveredId !== null && !isHovered;
// Luxurious, slow, and smooth horizontal expansion (flex weighting)
// No vertical scaling, no height changes, purely horizontal shift
const flexClass = isHovered
? 'md:flex-[1.75]'
: hasOtherHovered
? 'md:flex-[0.75]'
: 'md:flex-1';
// Slow, calm, luxurious horizontal expansion:
// When hovered: 1.85 flex-grow (~46% width)
// When other is hovered: 0.716 flex-grow (~18% width)
// At rest: 1.0 flex-grow (25% width each)
// Sum is always mathematically conserved at exactly 4.0 (1.85 + 3 * 0.716 = 4.00)
// Fixed flex-basis: 0 eliminates conflicting layout calculations
const flexGrowValue = isHovered ? 1.85 : hasOtherHovered ? 0.716 : 1;
return (
<div
key={item.id}
onMouseEnter={() => setHoveredId(item.id)}
onMouseLeave={() => setHoveredId(null)}
className={`w-full ${flexClass} transition-[flex-grow,flex-basis] duration-700 ease-[cubic-bezier(0.25,1,0.5,1)] flex flex-col flex-shrink-0 min-w-0`}
style={{
flexGrow: flexGrowValue,
flexShrink: 1,
flexBasis: '0%',
}}
className="w-full transition-[flex-grow] duration-1000 ease-[cubic-bezier(0.16,1,0.3,1)] will-change-[flex-grow] flex flex-col min-w-0"
>
{/* Window Container with strictly locked pixel height & landscape aspect */}
<Link
href={`/tools/${item.slug}`}
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-2xl sm:rounded-3xl overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm hover:shadow-cream-lg transition-shadow duration-500"
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-2xl sm:rounded-3xl overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm"
>
{/* GPU-Composited Shadow Elevation Layer (Opacity-only transition, zero paint thrash) */}
<div
className="absolute -inset-px rounded-2xl sm:rounded-3xl shadow-cream-lg opacity-0 group-hover:opacity-100 transition-opacity duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none z-30"
aria-hidden="true"
/>
{/* Media Renderer */}
<ToolWindowMedia item={item} isHovered={isHovered} />
{/* Hover Media Type Pill */}
<div className="absolute top-3 left-3 z-20 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-500">
{/* Hover Media Type Pill (Smooth GPU Opacity Transition) */}
<div
className="absolute top-3 left-3 z-20 pointer-events-none opacity-0 group-hover:opacity-100 transition-opacity duration-500 ease-[cubic-bezier(0.16,1,0.3,1)]"
>
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/85 backdrop-blur-md text-white border border-white/20">
{item.mediaType === 'video' && <Video className="w-3 h-3 text-cyan-400" />}
{item.mediaType === 'comparison' && <Sliders className="w-3 h-3 text-amber-400" />}
@@ -201,10 +214,10 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
{/* Little Title Below Window (Fixed height, no vertical jumping) */}
<Link
href={`/tools/${item.slug}`}
className="mt-2.5 h-6 px-1 flex items-center justify-between text-xs sm:text-sm font-display font-semibold text-slate-800 hover:text-blue-600 transition-colors group"
className="mt-2.5 h-6 px-1 flex items-center justify-between text-xs sm:text-sm font-display font-semibold text-slate-800 hover:text-blue-600 transition-colors duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] group"
>
<span className="truncate">{item.title}</span>
<ArrowRight className="w-3.5 h-3.5 text-slate-400 group-hover:text-blue-600 group-hover:translate-x-0.5 transition-all flex-shrink-0 ml-1.5" />
<ArrowRight className="w-3.5 h-3.5 text-slate-400 group-hover:text-blue-600 group-hover:translate-x-0.5 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] flex-shrink-0 ml-1.5" />
</Link>
</div>
);
@@ -215,9 +228,26 @@ function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: boolean }) {
const videoRef = useRef<HTMLVideoElement>(null);
const [sliderPos, setSliderPos] = useState<number>(50);
const [isManualHover, setIsManualHover] = useState(false);
const containerRef = useRef<HTMLDivElement>(null);
const dividerRef = useRef<HTMLDivElement>(null);
const afterImgRef = useRef<HTMLImageElement>(null);
// High performance refs - completely eliminates per-frame React re-renders!
const isManualRef = useRef(false);
const animFrameRef = useRef<number | null>(null);
const pointerRafRef = useRef<number | null>(null);
const cachedRectRef = useRef<{ left: number; width: number } | null>(null);
// Directly mutate DOM styles on the GPU layer without triggering React reconciliation
const setSliderDOM = useCallback((percent: number) => {
const clamped = Math.max(8, Math.min(92, percent));
if (dividerRef.current) {
dividerRef.current.style.left = `${clamped}%`;
}
if (afterImgRef.current) {
afterImgRef.current.style.clipPath = `inset(0 ${100 - clamped}% 0 0)`;
}
}, []);
// Video Autoplay Muted Loop only on Hover (No zoom, no scale)
useEffect(() => {
@@ -231,23 +261,28 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
}
}, [isHovered, item.mediaType]);
// Before/After Smooth Automatic Oscillating Scan when hovered
// Smooth Automatic Oscillating Scan when hovered:
// Runs at 60-120fps directly mutating DOM refs (0 React re-renders!)
useEffect(() => {
if (item.mediaType !== 'comparison') return;
if (!isHovered) {
setSliderPos(50);
setIsManualHover(false);
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
isManualRef.current = false;
if (animFrameRef.current) {
cancelAnimationFrame(animFrameRef.current);
animFrameRef.current = null;
}
setSliderDOM(50);
return;
}
let startTime = Date.now();
const sweep = () => {
if (!isManualHover) {
const elapsed = (Date.now() - startTime) / 1000;
const pos = 50 + Math.sin(elapsed * 2.2) * 24;
setSliderPos(pos);
const startTime = performance.now();
const sweep = (now: number) => {
if (!isManualRef.current) {
const elapsed = (now - startTime) / 1000;
// Calm, breathing oscillation: 1.4 rad/s sine wave with 22% sweep amplitude
const pos = 50 + Math.sin(elapsed * 1.4) * 22;
setSliderDOM(pos);
}
animFrameRef.current = requestAnimationFrame(sweep);
};
@@ -255,22 +290,53 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
animFrameRef.current = requestAnimationFrame(sweep);
return () => {
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
if (animFrameRef.current) {
cancelAnimationFrame(animFrameRef.current);
animFrameRef.current = null;
}
};
}, [isHovered, isManualHover, item.mediaType]);
}, [isHovered, item.mediaType, setSliderDOM]);
// Pointer position tracking when mouse moves over the comparison window
const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
// Pointer position tracking:
// Caches container bounding rect on enter to avoid layout thrashing in pointermove.
// Updates slider DOM in requestAnimationFrame with zero React state calls.
const handlePointerEnter = (e: React.PointerEvent<HTMLDivElement>) => {
if (item.mediaType !== 'comparison') return;
setIsManualHover(true);
const rect = e.currentTarget.getBoundingClientRect();
const x = Math.max(0, Math.min(e.clientX - rect.left, rect.width));
const percent = Math.max(10, Math.min(90, (x / rect.width) * 100));
setSliderPos(percent);
cachedRectRef.current = { left: rect.left, width: rect.width };
};
const handleMouseLeave = () => {
setIsManualHover(false);
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
if (item.mediaType !== 'comparison') return;
isManualRef.current = true;
const clientX = e.clientX;
if (pointerRafRef.current) {
cancelAnimationFrame(pointerRafRef.current);
}
pointerRafRef.current = requestAnimationFrame(() => {
let rect = cachedRectRef.current;
if (!rect && containerRef.current) {
const r = containerRef.current.getBoundingClientRect();
rect = { left: r.left, width: r.width };
cachedRectRef.current = rect;
}
if (!rect || rect.width <= 0) return;
const x = Math.max(0, Math.min(clientX - rect.left, rect.width));
const percent = (x / rect.width) * 100;
setSliderDOM(percent);
});
};
const handlePointerLeave = () => {
isManualRef.current = false;
cachedRectRef.current = null;
if (pointerRafRef.current) {
cancelAnimationFrame(pointerRafRef.current);
pointerRafRef.current = null;
}
};
// 1. VIDEO (Strictly locked to fixed 680px centered width - ZERO ZOOM)
@@ -284,9 +350,10 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
muted
loop
playsInline
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none"
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none transform-gpu will-change-transform [backface-visibility:hidden]"
/>
<div className="absolute inset-0 bg-slate-950/10 group-hover:bg-transparent transition-colors duration-500" />
{/* GPU-composited overlay (opacity only) */}
<div className="absolute inset-0 bg-slate-950/10 opacity-100 group-hover:opacity-0 transition-opacity duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none" />
</div>
);
}
@@ -295,51 +362,57 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
if (item.mediaType === 'comparison' && item.beforeUrl && item.afterUrl) {
return (
<div
onMouseMove={handleMouseMove}
onMouseLeave={handleMouseLeave}
className="relative w-full h-full select-none cursor-ew-resize overflow-hidden bg-slate-950"
ref={containerRef}
onPointerEnter={handlePointerEnter}
onPointerMove={handlePointerMove}
onPointerLeave={handlePointerLeave}
className="relative w-full h-full select-none cursor-ew-resize overflow-hidden bg-slate-950 transform-gpu [backface-visibility:hidden]"
>
{/* BEFORE Image (Base layer, fixed scale & position, 0% zoom) */}
<img
src={item.beforeUrl}
alt="Before"
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none"
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none transform-gpu will-change-transform [backface-visibility:hidden]"
loading="lazy"
/>
{/* AFTER Image (Top layer, exact same position & scale, clipped via clip-path) */}
<img
ref={afterImgRef}
src={item.afterUrl}
alt="After"
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none"
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none transform-gpu will-change-transform [backface-visibility:hidden]"
style={{
clipPath: `inset(0 ${100 - sliderPos}% 0 0)`,
clipPath: 'inset(0 50% 0 0)',
}}
loading="lazy"
/>
{/* Glowing Slider Divider Line */}
{/* Glowing Slider Divider Line (Direct GPU transform & position) */}
<div
className="absolute top-0 bottom-0 w-[2px] bg-white shadow-[0_0_12px_rgba(255,255,255,1)] pointer-events-none z-10"
style={{ left: `${sliderPos}%` }}
ref={dividerRef}
className="absolute top-0 bottom-0 w-[2px] bg-white shadow-[0_0_12px_rgba(255,255,255,1)] pointer-events-none z-10 will-change-transform transform-gpu -translate-x-1/2"
style={{ left: '50%' }}
>
{/* Circular Grab Handle with Before/After Arrow Cue */}
<div className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-7 h-7 rounded-full bg-white shadow-lg border border-slate-200/90 flex items-center justify-center text-[10px] font-bold text-slate-900 pointer-events-none">
<div className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-7 h-7 rounded-full bg-white shadow-lg border border-slate-200/90 flex items-center justify-center text-[10px] font-bold text-slate-900 pointer-events-none">
↔
</div>
</div>
{/* Clean Badges Visible on Hover */}
{isHovered && (
<div className="absolute bottom-3 inset-x-3 flex justify-between pointer-events-none z-20 text-[9px] font-mono font-bold uppercase tracking-wider text-white">
<span className="bg-slate-950/80 px-2 py-0.5 rounded backdrop-blur border border-white/10">
AFTER
</span>
<span className="bg-slate-950/80 px-2 py-0.5 rounded backdrop-blur border border-white/10">
BEFORE
</span>
</div>
)}
{/* Badges with Smooth GPU Opacity Transition (No DOM mounting/unmounting) */}
<div
className={`absolute bottom-3 inset-x-3 flex justify-between pointer-events-none z-20 text-[9px] font-mono font-bold uppercase tracking-wider text-white transition-opacity duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] ${
isHovered ? 'opacity-100' : 'opacity-0'
}`}
>
<span className="bg-slate-950/80 px-2 py-0.5 rounded backdrop-blur border border-white/10">
AFTER
</span>
<span className="bg-slate-950/80 px-2 py-0.5 rounded backdrop-blur border border-white/10">
BEFORE
</span>
</div>
</div>
);
}
@@ -350,10 +423,11 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
<img
src={item.imageUrl || item.afterUrl || item.beforeUrl || '/brand/og-default.png'}
alt={item.title}
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none"
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none transform-gpu will-change-transform [backface-visibility:hidden]"
loading="lazy"
/>
<div className="absolute inset-0 bg-slate-950/10 group-hover:bg-transparent transition-colors duration-500" />
{/* GPU-composited overlay (opacity only) */}
<div className="absolute inset-0 bg-slate-950/10 opacity-100 group-hover:opacity-0 transition-opacity duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none" />
</div>
);
}
+12 -6
View File
@@ -230,7 +230,7 @@ export function TrendyBentoSection({
<button
key={cat.id}
onClick={() => setActiveCategory(cat.id)}
className={`flex items-center gap-1.5 px-4 py-2 rounded-full transition-all duration-200 ${
className={`flex items-center gap-1.5 px-4 py-2 rounded-full transition-[transform,background-color,color] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] ${
isActive
? 'bg-slate-950 text-white shadow-md shadow-slate-900/15 scale-105'
: 'bg-white/90 text-slate-700 hover:bg-slate-100 border border-slate-200 shadow-sm'
@@ -259,18 +259,24 @@ export function TrendyBentoSection({
return (
<div
key={tile.id}
className={`group relative flex flex-col justify-between overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm hover:shadow-cream-lg transition-all duration-300 hover:-translate-y-1.5 transform-gpu ${tileClasses}`}
className={`group relative flex flex-col justify-between overflow-hidden bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm transition-[transform] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] hover:-translate-y-1.5 transform-gpu will-change-transform ${tileClasses}`}
>
{/* GPU-composited shadow elevation layer */}
<div
className="absolute -inset-px rounded-[36px] sm:rounded-[42px] shadow-cream-lg opacity-0 group-hover:opacity-100 transition-opacity duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none z-30"
aria-hidden="true"
/>
{/* Background Image (Covering the squarical tile) */}
<img
src={tile.imageUrl}
alt={tile.name}
className="absolute inset-0 w-full h-full object-cover transition-transform duration-500 group-hover:scale-105"
className="absolute inset-0 w-full h-full object-cover transition-transform duration-700 ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:scale-105 will-change-transform transform-gpu"
loading="lazy"
/>
{/* Vignette Overlay for Readability */}
<div className="absolute inset-0 bg-gradient-to-t from-slate-950/90 via-slate-950/30 to-slate-950/20 group-hover:via-slate-950/15 transition-all duration-300 pointer-events-none" />
{/* Vignette Overlay for Readability (GPU Opacity) */}
<div className="absolute inset-0 bg-gradient-to-t from-slate-950/90 via-slate-950/30 to-slate-950/20 opacity-100 group-hover:opacity-85 transition-opacity duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] pointer-events-none" />
{/* Top Tile Bar: Badge and Quick-Settings Resize Button */}
<div className="relative z-20 flex items-center justify-between p-5">
@@ -282,7 +288,7 @@ export function TrendyBentoSection({
<button
onClick={(e) => toggleTileSize(tile.id, e)}
title={tile.isWide ? 'Shrink tile' : 'Expand tile'}
className="w-9 h-9 rounded-2xl bg-white/90 hover:bg-white text-slate-800 shadow-md flex items-center justify-center transition-all duration-200 hover:scale-110 active:scale-95"
className="w-9 h-9 rounded-2xl bg-white/90 hover:bg-white text-slate-800 shadow-md flex items-center justify-center transition-[transform,background-color] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-110 active:scale-95"
>
{tile.isWide ? (
<Minimize2 className="w-4 h-4 text-blue-600" />
+5 -5
View File
@@ -35,7 +35,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
}, [mobileMenuOpen]);
return (
<header className="fixed top-0 left-0 right-0 w-full z-50 pointer-events-none transition-all duration-300">
<header className="fixed top-0 left-0 right-0 w-full z-50 pointer-events-none">
{/* 1. Ultra-Smooth High-Performance Gradient Blur Canopy (Zero lag, locks at 60/120fps) */}
<div className="absolute top-0 inset-x-0 h-28 sm:h-32 pointer-events-none overflow-hidden select-none">
{/* Single hardware-accelerated progressive blur */}
@@ -57,7 +57,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
<div className="absolute top-0 inset-x-0 h-[1px] bg-gradient-to-r from-transparent via-white/80 to-transparent pointer-events-none z-30" />
{/* 3. Main Aligned Edge-to-Edge Navigation Bar */}
<div className={`relative z-30 pointer-events-auto transition-all duration-300 ${isScrolled ? 'py-3' : 'py-3.5 sm:py-4'}`}>
<div className="relative z-30 pointer-events-auto py-3 sm:py-3.5">
<div className="max-w-[1640px] mx-auto px-4 sm:px-6 lg:px-10 flex items-center justify-between">
{/* Brand Logo */}
<div className="relative z-20 flex-shrink-0">
@@ -70,7 +70,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
<Link
href="/"
aria-current={pathname === '/' ? 'page' : undefined}
className={`relative flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-bold tracking-wide transition-all duration-200 ${
className={`relative flex items-center gap-1.5 px-4 py-2 rounded-full text-xs font-bold tracking-wide transition-[background-color,color,box-shadow] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] ${
pathname === '/'
? 'text-blue-700 bg-white shadow-sm border border-slate-900/[0.06]'
: 'text-slate-800 hover:text-slate-950 hover:bg-white/60'
@@ -87,7 +87,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
key={item.href}
href={item.href}
aria-current={active ? 'page' : undefined}
className={`relative px-4 py-2 rounded-full text-xs font-bold tracking-wide transition-all duration-200 ${
className={`relative px-4 py-2 rounded-full text-xs font-bold tracking-wide transition-[background-color,color,box-shadow] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] ${
active
? 'text-blue-700 bg-white shadow-sm border border-slate-900/[0.06]'
: 'text-slate-800 hover:text-slate-950 hover:bg-white/60'
@@ -112,7 +112,7 @@ export function Navbar({ config, currentLocale }: NavbarProps) {
<div className="hidden md:flex items-center space-x-3 relative z-20 flex-shrink-0">
<Link
href={config.nav.cta.href}
className="group relative inline-flex items-center gap-1.5 lg:gap-2 px-3.5 py-2 lg:px-5 lg:py-2.5 rounded-full text-xs font-bold text-white bg-gradient-to-r from-blue-600 via-indigo-600 to-blue-600 hover:from-blue-700 hover:to-indigo-700 shadow-md shadow-blue-500/25 hover:shadow-lg hover:shadow-blue-500/35 transition-all duration-300 hover:scale-105 active:scale-95"
className="group relative inline-flex items-center gap-1.5 lg:gap-2 px-3.5 py-2 lg:px-5 lg:py-2.5 rounded-full text-xs font-bold text-white bg-gradient-to-r from-blue-600 via-indigo-600 to-blue-600 hover:from-blue-700 hover:to-indigo-700 shadow-md shadow-blue-500/25 hover:shadow-lg hover:shadow-blue-500/35 transition-[transform,opacity,box-shadow] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 active:scale-95"
>
<Smartphone className="w-3.5 h-3.5 lg:w-4 lg:h-4 text-white group-hover:rotate-6 transition-transform" />
<span>{resolveLocalised(config.nav.cta.label, currentLocale)}</span>