2026-11-04 17:55:18 +05:30
|
|
|
'use client';
|
|
|
|
|
|
2026-11-04 18:48:24 +05:30
|
|
|
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
2026-11-04 17:55:18 +05:30
|
|
|
import Link from 'next/link';
|
2026-11-05 15:25:23 +05:30
|
|
|
import { ArrowRight, Sparkles } from 'lucide-react';
|
2026-11-04 17:55:18 +05:30
|
|
|
import { TextAnimate } from '@/components/magicui/text-animate';
|
|
|
|
|
import { ToolItem } from '@/types';
|
|
|
|
|
|
|
|
|
|
export interface ToolMediaItem {
|
|
|
|
|
id: string;
|
|
|
|
|
slug: string;
|
|
|
|
|
title: string;
|
|
|
|
|
mediaType: 'video' | 'photo' | 'comparison';
|
|
|
|
|
videoUrl?: string;
|
|
|
|
|
poster?: string;
|
|
|
|
|
imageUrl?: string;
|
|
|
|
|
beforeUrl?: string;
|
|
|
|
|
afterUrl?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-04 18:48:24 +05:30
|
|
|
export interface ShiftableToolsGridProps {
|
2026-11-04 17:55:18 +05:30
|
|
|
title?: string;
|
|
|
|
|
subtitle?: string;
|
|
|
|
|
tools?: ToolItem[];
|
|
|
|
|
items?: ToolMediaItem[];
|
|
|
|
|
locale?: string;
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-04 18:48:24 +05:30
|
|
|
export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
2026-11-04 18:22:18 +05:30
|
|
|
// ROW 1 (4 items) - Landscape 16:9 assets
|
2026-11-04 17:55:18 +05:30
|
|
|
{
|
|
|
|
|
id: 'tool-blemish',
|
|
|
|
|
slug: 'blemish-remover',
|
2026-11-05 11:01:09 +05:30
|
|
|
title: 'Skin & Blemish Retoucher',
|
2026-11-04 17:55:18 +05:30
|
|
|
mediaType: 'comparison',
|
2026-11-05 14:47:04 +05:30
|
|
|
beforeUrl: '/management/pages/home/sections/our-tools/blemish-remover/before.jpg',
|
|
|
|
|
afterUrl: '/management/pages/home/sections/our-tools/blemish-remover/after.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'tool-bg-remover',
|
|
|
|
|
slug: 'background-remover',
|
|
|
|
|
title: 'Background Remover (Alpha Matting)',
|
|
|
|
|
mediaType: 'video',
|
2026-11-05 14:47:04 +05:30
|
|
|
videoUrl: '/management/pages/home/sections/our-tools/background-remover/sample_reel.mp4',
|
|
|
|
|
poster: '/management/pages/home/sections/our-tools/background-remover/poster.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'tool-enhancer',
|
|
|
|
|
slug: 'photo-enhancer',
|
|
|
|
|
title: 'Photo Enhancer 4K',
|
|
|
|
|
mediaType: 'comparison',
|
2026-11-05 14:47:04 +05:30
|
|
|
beforeUrl: '/management/pages/home/sections/our-tools/photo-enhancer/before.jpg',
|
|
|
|
|
afterUrl: '/management/pages/home/sections/our-tools/photo-enhancer/after.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'tool-restorer',
|
|
|
|
|
slug: 'old-photo-restorer',
|
|
|
|
|
title: 'Vintage Photo Restorer',
|
2026-11-04 18:22:18 +05:30
|
|
|
mediaType: 'comparison',
|
2026-11-05 14:47:04 +05:30
|
|
|
beforeUrl: '/management/pages/home/sections/our-tools/old-photo-restorer/before.jpg',
|
|
|
|
|
afterUrl: '/management/pages/home/sections/our-tools/old-photo-restorer/after.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
|
2026-11-04 18:22:18 +05:30
|
|
|
// ROW 2 (4 items) - Landscape 16:9 assets
|
2026-11-04 17:55:18 +05:30
|
|
|
{
|
|
|
|
|
id: 'tool-colorization',
|
|
|
|
|
slug: 'colorization',
|
|
|
|
|
title: 'AI Colorizer',
|
|
|
|
|
mediaType: 'comparison',
|
2026-11-05 14:47:04 +05:30
|
|
|
beforeUrl: '/management/pages/home/sections/our-tools/colorization/before.jpg',
|
|
|
|
|
afterUrl: '/management/pages/home/sections/our-tools/colorization/after.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'tool-teeth',
|
|
|
|
|
slug: 'teeth-whitener',
|
|
|
|
|
title: 'Teeth Whitener & Brightener',
|
2026-11-04 18:22:18 +05:30
|
|
|
mediaType: 'comparison',
|
2026-11-05 14:47:04 +05:30
|
|
|
beforeUrl: '/management/pages/home/sections/our-tools/teeth-whitener/before.jpg',
|
|
|
|
|
afterUrl: '/management/pages/home/sections/our-tools/teeth-whitener/after.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'tool-cartoon',
|
|
|
|
|
slug: 'cartoon-avatar',
|
|
|
|
|
title: 'Cartoon & Anime Avatar',
|
|
|
|
|
mediaType: 'comparison',
|
2026-11-05 14:47:04 +05:30
|
|
|
beforeUrl: '/management/pages/home/sections/our-tools/cartoon-avatar/before.jpg',
|
|
|
|
|
afterUrl: '/management/pages/home/sections/our-tools/cartoon-avatar/after.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: 'tool-polaroid',
|
|
|
|
|
slug: 'polaroid-maker',
|
|
|
|
|
title: 'Vintage Polaroid Maker',
|
|
|
|
|
mediaType: 'photo',
|
2026-11-05 14:47:04 +05:30
|
|
|
imageUrl: '/management/pages/home/sections/our-tools/polaroid-maker/image.jpg',
|
2026-11-04 17:55:18 +05:30
|
|
|
},
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
export function ShiftableToolsGridSection({
|
|
|
|
|
title = 'Our Tools',
|
|
|
|
|
subtitle = 'Click on any tool window to try with your own photos in seconds.',
|
|
|
|
|
items,
|
|
|
|
|
}: ShiftableToolsGridProps) {
|
|
|
|
|
const displayItems = items && items.length >= 8 ? items : DEFAULT_TOOL_ITEMS;
|
|
|
|
|
const row1 = displayItems.slice(0, 4);
|
|
|
|
|
const row2 = displayItems.slice(4, 8);
|
|
|
|
|
|
|
|
|
|
return (
|
2026-11-04 18:37:52 +05:30
|
|
|
<section id="our-tools" className="py-14 sm:py-20 px-4 sm:px-6 md:px-8 lg:px-10 bg-[#FAF8F5] relative overflow-hidden">
|
|
|
|
|
{/* Symbolic Elemental Ambient Highlights */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute inset-0 pointer-events-none -z-10"
|
|
|
|
|
style={{
|
|
|
|
|
background: 'radial-gradient(circle at 15% 30%, rgba(37,99,235,0.06) 0%, transparent 60%), radial-gradient(circle at 85% 70%, rgba(147,51,234,0.05) 0%, transparent 60%)',
|
|
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
<div className="max-w-[1640px] mx-auto space-y-10">
|
2026-11-04 17:55:18 +05:30
|
|
|
{/* Header */}
|
|
|
|
|
<div className="text-center max-w-3xl mx-auto space-y-4">
|
|
|
|
|
<div className="inline-flex items-center gap-2 px-3.5 py-1 rounded-full text-xs font-mono font-semibold tracking-wider uppercase text-blue-700 bg-blue-50 border border-blue-200">
|
|
|
|
|
<Sparkles className="w-3.5 h-3.5 text-blue-600" />
|
|
|
|
|
<span>AI Creative Tools</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<h2 className="text-3xl sm:text-5xl font-display font-extrabold text-slate-900 tracking-tight">
|
2026-11-05 12:45:11 +05:30
|
|
|
<TextAnimate animation="slideLeft" by="word">
|
2026-11-04 17:55:18 +05:30
|
|
|
{title}
|
|
|
|
|
</TextAnimate>
|
|
|
|
|
</h2>
|
|
|
|
|
|
2026-11-04 18:05:26 +05:30
|
|
|
<p className="text-sm sm:text-base text-slate-600 font-sans text-pretty">
|
2026-11-05 12:45:11 +05:30
|
|
|
<TextAnimate animation="fadeIn" by="word" delay={0.08}>
|
2026-11-04 17:55:18 +05:30
|
|
|
{subtitle}
|
|
|
|
|
</TextAnimate>
|
|
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-04 18:48:24 +05:30
|
|
|
{/* 2-Row Shiftable Grid Container (Slow, Calm, Pure Horizontal Expansion with Locked Height) */}
|
2026-11-04 17:55:18 +05:30
|
|
|
<div className="space-y-6 sm:space-y-8">
|
|
|
|
|
<ShiftableRow items={row1} />
|
|
|
|
|
<ShiftableRow items={row2} />
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* See More Section Button Redirecting to /tools */}
|
|
|
|
|
<div className="pt-6 text-center">
|
|
|
|
|
<Link
|
|
|
|
|
href="/tools"
|
2026-11-04 18:48:24 +05:30
|
|
|
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"
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
|
|
|
|
<span>See More Tools</span>
|
2026-11-04 18:48:24 +05:30
|
|
|
<ArrowRight className="w-4 h-4 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:translate-x-1" />
|
2026-11-04 17:55:18 +05:30
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ShiftableRow({ items }: { items: ToolMediaItem[] }) {
|
|
|
|
|
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
|
|
|
|
|
|
|
|
|
return (
|
2026-11-04 18:05:26 +05:30
|
|
|
<div className="flex flex-col md:flex-row gap-4 sm:gap-6 w-full items-start">
|
2026-11-04 17:55:18 +05:30
|
|
|
{items.map((item) => {
|
|
|
|
|
const isHovered = hoveredId === item.id;
|
|
|
|
|
const hasOtherHovered = hoveredId !== null && !isHovered;
|
|
|
|
|
|
2026-11-04 18:48:24 +05:30
|
|
|
// 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;
|
2026-11-04 17:55:18 +05:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={item.id}
|
|
|
|
|
onMouseEnter={() => setHoveredId(item.id)}
|
|
|
|
|
onMouseLeave={() => setHoveredId(null)}
|
2026-11-04 18:48:24 +05:30
|
|
|
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"
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
2026-11-05 13:20:36 +05:30
|
|
|
{/* Window Container with strictly locked pixel height & landscape aspect */}
|
|
|
|
|
{item.mediaType === 'comparison' ? (
|
2026-11-05 15:25:23 +05:30
|
|
|
<div
|
|
|
|
|
style={{ borderRadius: '28px' }}
|
2026-11-05 17:15:36 +05:30
|
|
|
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-[28px] sm:rounded-[36px] overflow-hidden isolate bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm"
|
2026-11-05 15:25:23 +05:30
|
|
|
>
|
2026-11-05 13:20:36 +05:30
|
|
|
{/* GPU-Composited Shadow Elevation Layer */}
|
|
|
|
|
<div
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
className="absolute -inset-px rounded-[28px] sm:rounded-[36px] 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"
|
2026-11-05 13:20:36 +05:30
|
|
|
aria-hidden="true"
|
|
|
|
|
/>
|
2026-11-04 18:48:24 +05:30
|
|
|
|
2026-11-05 13:20:36 +05:30
|
|
|
{/* Media Renderer (Interactive comparison slider with desktop hover + mobile touch handle) */}
|
|
|
|
|
<ToolWindowMedia item={item} isHovered={isHovered} />
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 13:20:36 +05:30
|
|
|
{/* Dedicated Tool Link Pill on top right so sliding never accidentally navigates */}
|
|
|
|
|
<Link
|
|
|
|
|
href={`/tools/${item.slug}`}
|
2026-11-05 17:15:36 +05:30
|
|
|
className="absolute top-3 right-3 z-30 inline-flex items-center gap-1.5 px-3 py-1.5 rounded-full text-[10px] font-mono font-bold tracking-wider uppercase bg-slate-950/90 text-white border border-white/20 hover:bg-blue-600 transition-colors shadow-sm cursor-pointer"
|
2026-11-05 13:20:36 +05:30
|
|
|
aria-label={`Open ${item.title}`}
|
|
|
|
|
>
|
|
|
|
|
<span>TRY TOOL</span>
|
|
|
|
|
<ArrowRight className="w-2.5 h-2.5" />
|
|
|
|
|
</Link>
|
2026-11-05 13:10:05 +05:30
|
|
|
</div>
|
2026-11-05 13:20:36 +05:30
|
|
|
) : (
|
|
|
|
|
<Link
|
|
|
|
|
href={`/tools/${item.slug}`}
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{ borderRadius: '28px' }}
|
2026-11-05 17:15:36 +05:30
|
|
|
className="group block relative w-full h-[220px] sm:h-[240px] lg:h-[260px] rounded-[28px] sm:rounded-[36px] overflow-hidden isolate bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm cursor-pointer"
|
2026-11-05 13:20:36 +05:30
|
|
|
>
|
|
|
|
|
{/* GPU-Composited Shadow Elevation Layer (Opacity-only transition, zero paint thrash) */}
|
|
|
|
|
<div
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
className="absolute -inset-px rounded-[28px] sm:rounded-[36px] 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"
|
2026-11-05 13:20:36 +05:30
|
|
|
aria-hidden="true"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Media Renderer */}
|
|
|
|
|
<ToolWindowMedia item={item} isHovered={isHovered} />
|
|
|
|
|
</Link>
|
|
|
|
|
)}
|
2026-11-04 17:55:18 +05:30
|
|
|
|
|
|
|
|
{/* Little Title Below Window (Fixed height, no vertical jumping) */}
|
|
|
|
|
<Link
|
|
|
|
|
href={`/tools/${item.slug}`}
|
2026-11-04 18:48:24 +05:30
|
|
|
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"
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
|
|
|
|
<span className="truncate">{item.title}</span>
|
2026-11-04 18:48:24 +05:30
|
|
|
<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" />
|
2026-11-04 17:55:18 +05:30
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
})}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered: boolean }) {
|
|
|
|
|
const videoRef = useRef<HTMLVideoElement>(null);
|
2026-11-04 18:48:24 +05:30
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
|
|
|
|
const dividerRef = useRef<HTMLDivElement>(null);
|
2026-11-05 13:42:18 +05:30
|
|
|
const clipLayerRef = useRef<HTMLDivElement>(null);
|
2026-11-05 13:20:36 +05:30
|
|
|
const handleRef = useRef<HTMLDivElement>(null);
|
2026-11-04 18:48:24 +05:30
|
|
|
|
|
|
|
|
// High performance refs - completely eliminates per-frame React re-renders!
|
|
|
|
|
const isManualRef = useRef(false);
|
2026-11-05 13:03:19 +05:30
|
|
|
const isPointerDownRef = useRef(false);
|
|
|
|
|
const currentPercentRef = useRef(50);
|
2026-11-04 17:55:18 +05:30
|
|
|
const animFrameRef = useRef<number | null>(null);
|
2026-11-04 18:48:24 +05:30
|
|
|
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) => {
|
2026-11-05 13:31:58 +05:30
|
|
|
const clamped = Math.max(0, Math.min(100, percent));
|
2026-11-05 13:03:19 +05:30
|
|
|
currentPercentRef.current = clamped;
|
2026-11-04 18:48:24 +05:30
|
|
|
if (dividerRef.current) {
|
|
|
|
|
dividerRef.current.style.left = `${clamped}%`;
|
|
|
|
|
}
|
2026-11-05 13:42:18 +05:30
|
|
|
if (clipLayerRef.current) {
|
2026-11-05 15:25:23 +05:30
|
|
|
clipLayerRef.current.style.clipPath = `inset(0 ${100 - clamped}% 0 0 round 28px 0 0 28px)`;
|
|
|
|
|
(clipLayerRef.current.style as any).webkitClipPath = `inset(0 ${100 - clamped}% 0 0 round 28px 0 0 28px)`;
|
2026-11-04 18:48:24 +05:30
|
|
|
}
|
2026-11-05 13:20:36 +05:30
|
|
|
if (handleRef.current) {
|
|
|
|
|
handleRef.current.setAttribute('aria-valuenow', `${Math.round(clamped)}`);
|
2026-11-05 13:03:19 +05:30
|
|
|
}
|
2026-11-04 18:48:24 +05:30
|
|
|
}, []);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 15:04:28 +05:30
|
|
|
// Continuous Autoplay Muted Loop when visible in viewport
|
|
|
|
|
// Pauses automatically when scrolled out of view or tab is hidden to save GPU/battery and eliminate device heating
|
2026-11-04 17:55:18 +05:30
|
|
|
useEffect(() => {
|
2026-11-05 15:04:28 +05:30
|
|
|
if (item.mediaType !== 'video') return;
|
|
|
|
|
const video = videoRef.current;
|
|
|
|
|
if (!video) return;
|
|
|
|
|
|
|
|
|
|
video.muted = true;
|
|
|
|
|
video.defaultMuted = true;
|
|
|
|
|
video.playsInline = true;
|
|
|
|
|
|
|
|
|
|
let isIntersecting = false;
|
|
|
|
|
|
|
|
|
|
const updatePlayState = () => {
|
|
|
|
|
if (isIntersecting && !document.hidden) {
|
|
|
|
|
video.play().catch(() => {});
|
|
|
|
|
} else {
|
|
|
|
|
video.pause();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const observer = new IntersectionObserver(
|
|
|
|
|
([entry]) => {
|
|
|
|
|
isIntersecting = entry.isIntersecting;
|
|
|
|
|
updatePlayState();
|
|
|
|
|
},
|
|
|
|
|
{ threshold: 0.05 }
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
observer.observe(video);
|
|
|
|
|
|
|
|
|
|
const handleVisibility = () => {
|
|
|
|
|
updatePlayState();
|
|
|
|
|
};
|
|
|
|
|
document.addEventListener('visibilitychange', handleVisibility);
|
|
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
|
observer.disconnect();
|
|
|
|
|
document.removeEventListener('visibilitychange', handleVisibility);
|
|
|
|
|
video.pause();
|
|
|
|
|
};
|
2026-11-05 13:44:30 +05:30
|
|
|
}, [item.mediaType]);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 13:31:58 +05:30
|
|
|
// When unhovered, reset slider smoothly to 50%
|
2026-11-04 17:55:18 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
if (item.mediaType !== 'comparison') return;
|
|
|
|
|
|
|
|
|
|
if (!isHovered) {
|
2026-11-05 13:20:36 +05:30
|
|
|
isManualRef.current = false;
|
|
|
|
|
if (animFrameRef.current) {
|
|
|
|
|
cancelAnimationFrame(animFrameRef.current);
|
|
|
|
|
animFrameRef.current = null;
|
2026-11-04 18:48:24 +05:30
|
|
|
}
|
2026-11-05 13:20:36 +05:30
|
|
|
setSliderDOM(50);
|
2026-11-04 17:55:18 +05:30
|
|
|
}
|
2026-11-04 18:48:24 +05:30
|
|
|
}, [isHovered, item.mediaType, setSliderDOM]);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 13:31:58 +05:30
|
|
|
// Instant pixel-precise cursor alignment calculation
|
|
|
|
|
const updateToClientX = useCallback((clientX: number) => {
|
|
|
|
|
if (!containerRef.current) return;
|
2026-11-05 13:42:18 +05:30
|
|
|
const rect = cachedRectRef.current || containerRef.current.getBoundingClientRect();
|
2026-11-05 13:31:58 +05:30
|
|
|
if (rect.width <= 0) return;
|
|
|
|
|
const x = Math.max(0, Math.min(clientX - rect.left, rect.width));
|
|
|
|
|
const percent = (x / rect.width) * 100;
|
|
|
|
|
setSliderDOM(percent);
|
|
|
|
|
}, [setSliderDOM]);
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 13:31:58 +05:30
|
|
|
// Desktop Mouse Movement: Immediately aligns comparison bar with cursor on hover and stays locked
|
|
|
|
|
const handleContainerPointerEnter = (e: React.PointerEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>) => {
|
2026-11-05 13:20:36 +05:30
|
|
|
if (item.mediaType !== 'comparison') return;
|
2026-11-05 13:31:58 +05:30
|
|
|
if (!('pointerType' in e) || e.pointerType === 'mouse') {
|
|
|
|
|
isManualRef.current = true;
|
|
|
|
|
updateToClientX(e.clientX);
|
2026-11-05 13:20:36 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-05 13:31:58 +05:30
|
|
|
const handleContainerPointerMove = (e: React.PointerEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>) => {
|
2026-11-05 13:20:36 +05:30
|
|
|
if (item.mediaType !== 'comparison') return;
|
2026-11-05 13:31:58 +05:30
|
|
|
if (!('pointerType' in e) || e.pointerType === 'mouse') {
|
2026-11-05 13:20:36 +05:30
|
|
|
isManualRef.current = true;
|
|
|
|
|
const clientX = e.clientX;
|
|
|
|
|
if (pointerRafRef.current) cancelAnimationFrame(pointerRafRef.current);
|
|
|
|
|
pointerRafRef.current = requestAnimationFrame(() => {
|
2026-11-05 13:31:58 +05:30
|
|
|
updateToClientX(clientX);
|
2026-11-05 13:20:36 +05:30
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-05 13:31:58 +05:30
|
|
|
const handleContainerPointerLeave = (e: React.PointerEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>) => {
|
2026-11-05 13:20:36 +05:30
|
|
|
if (isPointerDownRef.current) return;
|
2026-11-05 13:31:58 +05:30
|
|
|
if (!('pointerType' in e) || e.pointerType === 'mouse') {
|
|
|
|
|
isManualRef.current = false;
|
|
|
|
|
if (pointerRafRef.current) {
|
|
|
|
|
cancelAnimationFrame(pointerRafRef.current);
|
|
|
|
|
pointerRafRef.current = null;
|
|
|
|
|
}
|
|
|
|
|
setSliderDOM(50);
|
2026-11-05 13:20:36 +05:30
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Dedicated Drag Handlers for Center Arrow Handle (Works on mobile touch & desktop click-drag)
|
|
|
|
|
const handleHandlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
|
2026-11-05 13:03:19 +05:30
|
|
|
if (item.mediaType !== 'comparison') return;
|
|
|
|
|
if (e.button !== 0 && e.pointerType === 'mouse') return;
|
|
|
|
|
|
2026-11-05 13:42:18 +05:30
|
|
|
e.preventDefault();
|
2026-11-05 13:03:19 +05:30
|
|
|
e.stopPropagation();
|
|
|
|
|
isManualRef.current = true;
|
|
|
|
|
isPointerDownRef.current = true;
|
|
|
|
|
|
|
|
|
|
if (animFrameRef.current) {
|
|
|
|
|
cancelAnimationFrame(animFrameRef.current);
|
|
|
|
|
animFrameRef.current = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
e.currentTarget.setPointerCapture(e.pointerId);
|
|
|
|
|
} catch {
|
|
|
|
|
// Fallback
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 13:42:18 +05:30
|
|
|
if (containerRef.current) {
|
|
|
|
|
const r = containerRef.current.getBoundingClientRect();
|
|
|
|
|
cachedRectRef.current = { left: r.left, width: r.width };
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 13:31:58 +05:30
|
|
|
updateToClientX(e.clientX);
|
2026-11-05 13:03:19 +05:30
|
|
|
};
|
|
|
|
|
|
2026-11-05 13:20:36 +05:30
|
|
|
const handleHandlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
|
2026-11-05 13:03:19 +05:30
|
|
|
if (!isPointerDownRef.current) return;
|
2026-11-05 13:20:36 +05:30
|
|
|
e.stopPropagation();
|
2026-11-04 18:48:24 +05:30
|
|
|
isManualRef.current = true;
|
|
|
|
|
|
|
|
|
|
const clientX = e.clientX;
|
|
|
|
|
if (pointerRafRef.current) {
|
|
|
|
|
cancelAnimationFrame(pointerRafRef.current);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
pointerRafRef.current = requestAnimationFrame(() => {
|
2026-11-05 13:31:58 +05:30
|
|
|
updateToClientX(clientX);
|
2026-11-04 18:48:24 +05:30
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-05 13:20:36 +05:30
|
|
|
const handleHandlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
|
|
|
|
|
if (!isPointerDownRef.current) return;
|
|
|
|
|
e.stopPropagation();
|
2026-11-05 13:03:19 +05:30
|
|
|
isPointerDownRef.current = false;
|
2026-11-05 13:42:18 +05:30
|
|
|
cachedRectRef.current = null;
|
2026-11-04 18:48:24 +05:30
|
|
|
if (pointerRafRef.current) {
|
|
|
|
|
cancelAnimationFrame(pointerRafRef.current);
|
|
|
|
|
pointerRafRef.current = null;
|
|
|
|
|
}
|
2026-11-05 13:03:19 +05:30
|
|
|
try {
|
|
|
|
|
e.currentTarget.releasePointerCapture(e.pointerId);
|
|
|
|
|
} catch {
|
|
|
|
|
// Fallback
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {
|
|
|
|
|
if (item.mediaType !== 'comparison') return;
|
|
|
|
|
const step = e.shiftKey ? 10 : 2;
|
|
|
|
|
if (e.key === 'ArrowLeft' || e.key === 'ArrowDown') {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
isManualRef.current = true;
|
|
|
|
|
setSliderDOM(currentPercentRef.current - step);
|
|
|
|
|
} else if (e.key === 'ArrowRight' || e.key === 'ArrowUp') {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
isManualRef.current = true;
|
|
|
|
|
setSliderDOM(currentPercentRef.current + step);
|
|
|
|
|
}
|
2026-11-04 17:55:18 +05:30
|
|
|
};
|
|
|
|
|
|
2026-11-04 18:22:18 +05:30
|
|
|
// 1. VIDEO (Strictly locked to fixed 680px centered width - ZERO ZOOM)
|
2026-11-04 17:55:18 +05:30
|
|
|
if (item.mediaType === 'video' && item.videoUrl) {
|
|
|
|
|
return (
|
2026-11-05 15:25:23 +05:30
|
|
|
<div
|
|
|
|
|
style={{ borderRadius: '28px' }}
|
2026-11-05 17:15:36 +05:30
|
|
|
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate"
|
2026-11-05 15:25:23 +05:30
|
|
|
>
|
2026-11-04 17:55:18 +05:30
|
|
|
<video
|
|
|
|
|
ref={videoRef}
|
|
|
|
|
src={item.videoUrl}
|
|
|
|
|
poster={item.poster}
|
2026-11-05 13:44:30 +05:30
|
|
|
autoPlay
|
2026-11-04 17:55:18 +05:30
|
|
|
muted
|
|
|
|
|
loop
|
|
|
|
|
playsInline
|
2026-11-05 13:44:30 +05:30
|
|
|
preload="auto"
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
2026-11-04 17:55:18 +05:30
|
|
|
/>
|
2026-11-04 18:48:24 +05:30
|
|
|
{/* GPU-composited overlay (opacity only) */}
|
2026-11-05 15:25:23 +05:30
|
|
|
<div
|
|
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
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"
|
|
|
|
|
/>
|
2026-11-04 17:55:18 +05:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-04 18:22:18 +05:30
|
|
|
// 2. COMPARISON: Pixel-perfect clip-path slider (ZERO ZOOM - locked fixed scale & centered position)
|
2026-11-04 17:55:18 +05:30
|
|
|
if (item.mediaType === 'comparison' && item.beforeUrl && item.afterUrl) {
|
|
|
|
|
return (
|
|
|
|
|
<div
|
2026-11-04 18:48:24 +05:30
|
|
|
ref={containerRef}
|
2026-11-05 13:20:36 +05:30
|
|
|
onPointerEnter={handleContainerPointerEnter}
|
2026-11-05 13:31:58 +05:30
|
|
|
onMouseEnter={handleContainerPointerEnter}
|
2026-11-05 13:20:36 +05:30
|
|
|
onPointerMove={handleContainerPointerMove}
|
2026-11-05 13:31:58 +05:30
|
|
|
onMouseMove={handleContainerPointerMove}
|
2026-11-05 13:20:36 +05:30
|
|
|
onPointerLeave={handleContainerPointerLeave}
|
2026-11-05 13:31:58 +05:30
|
|
|
onMouseLeave={handleContainerPointerLeave}
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{
|
|
|
|
|
touchAction: 'pan-y',
|
|
|
|
|
borderRadius: '28px',
|
|
|
|
|
}}
|
2026-11-05 17:15:36 +05:30
|
|
|
className="relative w-full h-full select-none overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate cursor-ew-resize"
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
2026-11-05 13:42:18 +05:30
|
|
|
{/* Layer 1: AFTER Image (Base layer, fixed scale & position, 0% zoom) */}
|
2026-11-04 17:55:18 +05:30
|
|
|
<img
|
2026-11-05 13:42:18 +05:30
|
|
|
src={item.afterUrl}
|
|
|
|
|
alt="After"
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
2026-11-04 17:55:18 +05:30
|
|
|
loading="lazy"
|
|
|
|
|
/>
|
|
|
|
|
|
2026-11-05 13:42:18 +05:30
|
|
|
{/* Layer 2: BEFORE Image (Clipped container-sized layer - 100% exact alignment with slider divider on phone & desktop) */}
|
|
|
|
|
<div
|
|
|
|
|
ref={clipLayerRef}
|
2026-11-05 17:15:36 +05:30
|
|
|
className="absolute inset-0 overflow-hidden rounded-[28px] sm:rounded-[36px] isolate pointer-events-none"
|
2026-11-04 17:55:18 +05:30
|
|
|
style={{
|
2026-11-05 15:25:23 +05:30
|
|
|
borderRadius: '28px',
|
|
|
|
|
clipPath: 'inset(0 50% 0 0 round 28px 0 0 28px)',
|
|
|
|
|
WebkitClipPath: 'inset(0 50% 0 0 round 28px 0 0 28px)',
|
2026-11-04 17:55:18 +05:30
|
|
|
}}
|
2026-11-05 13:42:18 +05:30
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
src={item.beforeUrl}
|
|
|
|
|
alt="Before"
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
2026-11-05 13:42:18 +05:30
|
|
|
loading="lazy"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 13:10:05 +05:30
|
|
|
{/* Glowing Slider Divider Line (pointer-events-none so touching the line allows page scroll) */}
|
2026-11-04 17:55:18 +05:30
|
|
|
<div
|
2026-11-04 18:48:24 +05:30
|
|
|
ref={dividerRef}
|
2026-11-05 13:03:19 +05:30
|
|
|
className="absolute top-0 bottom-0 w-[2.5px] 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"
|
2026-11-04 18:48:24 +05:30
|
|
|
style={{ left: '50%' }}
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
2026-11-05 13:20:36 +05:30
|
|
|
{/* Circular Grab Handle with Before/After Arrow Cue & Touch Hit Area */}
|
2026-11-05 13:10:05 +05:30
|
|
|
<div
|
2026-11-05 13:20:36 +05:30
|
|
|
ref={handleRef}
|
|
|
|
|
onPointerDown={handleHandlePointerDown}
|
|
|
|
|
onPointerMove={handleHandlePointerMove}
|
|
|
|
|
onPointerUp={handleHandlePointerUp}
|
|
|
|
|
onPointerCancel={handleHandlePointerUp}
|
2026-11-05 13:10:05 +05:30
|
|
|
onKeyDown={handleKeyDown}
|
|
|
|
|
role="slider"
|
|
|
|
|
aria-label="Before and after comparison slider"
|
2026-11-05 13:42:18 +05:30
|
|
|
aria-valuemin={0}
|
|
|
|
|
aria-valuemax={100}
|
2026-11-05 13:10:05 +05:30
|
|
|
aria-valuenow={50}
|
|
|
|
|
tabIndex={0}
|
|
|
|
|
style={{ touchAction: 'none' }}
|
2026-11-05 13:20:36 +05:30
|
|
|
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-9 h-9 sm:w-10 sm:h-10 rounded-full bg-white shadow-xl border border-slate-200/90 flex items-center justify-center text-xs font-bold text-blue-600 pointer-events-auto cursor-ew-resize touch-none before:absolute before:-inset-4 before:content-[''] hover:scale-110 active:scale-95 transition-transform"
|
2026-11-05 13:10:05 +05:30
|
|
|
>
|
2026-11-04 17:55:18 +05:30
|
|
|
↔
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-05 13:42:18 +05:30
|
|
|
{/* Badges with Smooth Contrast: BEFORE on left, AFTER on right */}
|
2026-11-04 18:48:24 +05:30
|
|
|
<div
|
2026-11-05 13:03:19 +05:30
|
|
|
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"
|
2026-11-04 18:48:24 +05:30
|
|
|
>
|
2026-11-05 17:15:36 +05:30
|
|
|
<span className="bg-slate-950/85 px-2 py-0.5 rounded border border-white/10 shadow-xs">
|
2026-11-04 18:48:24 +05:30
|
|
|
BEFORE
|
|
|
|
|
</span>
|
2026-11-05 17:15:36 +05:30
|
|
|
<span className="bg-blue-600 px-2 py-0.5 rounded border border-white/20 shadow-xs">
|
2026-11-05 13:42:18 +05:30
|
|
|
AFTER
|
|
|
|
|
</span>
|
2026-11-04 18:48:24 +05:30
|
|
|
</div>
|
2026-11-04 17:55:18 +05:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-04 18:22:18 +05:30
|
|
|
// 3. PHOTO (Strictly locked to fixed 680px centered width - ZERO ZOOM)
|
2026-11-04 17:55:18 +05:30
|
|
|
return (
|
2026-11-05 15:25:23 +05:30
|
|
|
<div
|
|
|
|
|
style={{ borderRadius: '28px' }}
|
2026-11-05 17:15:36 +05:30
|
|
|
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate"
|
2026-11-05 15:25:23 +05:30
|
|
|
>
|
2026-11-04 17:55:18 +05:30
|
|
|
<img
|
|
|
|
|
src={item.imageUrl || item.afterUrl || item.beforeUrl || '/brand/og-default.png'}
|
|
|
|
|
alt={item.title}
|
2026-11-05 15:25:23 +05:30
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
className="absolute inset-y-0 left-1/2 -translate-x-1/2 h-full w-[680px] max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
2026-11-04 17:55:18 +05:30
|
|
|
loading="lazy"
|
|
|
|
|
/>
|
2026-11-04 18:48:24 +05:30
|
|
|
{/* GPU-composited overlay (opacity only) */}
|
2026-11-05 15:25:23 +05:30
|
|
|
<div
|
|
|
|
|
style={{ borderRadius: '28px' }}
|
|
|
|
|
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"
|
|
|
|
|
/>
|
2026-11-04 17:55:18 +05:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|