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-06 10:53:55 +05:30
|
|
|
import { ArrowRight } from 'lucide-react';
|
2026-11-04 17:55:18 +05:30
|
|
|
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-06 10:53:55 +05:30
|
|
|
// ROW 1 (4 items)
|
2026-11-04 17:55:18 +05:30
|
|
|
{
|
|
|
|
|
id: 'tool-blemish',
|
|
|
|
|
slug: 'blemish-remover',
|
2026-11-06 10:53:55 +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',
|
2026-11-06 10:53:55 +05:30
|
|
|
title: 'Background remover (alpha matting)',
|
2026-11-04 17:55:18 +05:30
|
|
|
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',
|
2026-11-06 10:53:55 +05:30
|
|
|
title: 'Photo enhancer 4K',
|
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/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',
|
2026-11-06 10:53:55 +05:30
|
|
|
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-06 10:53:55 +05:30
|
|
|
// ROW 2 (4 items)
|
2026-11-04 17:55:18 +05:30
|
|
|
{
|
|
|
|
|
id: 'tool-colorization',
|
|
|
|
|
slug: 'colorization',
|
2026-11-06 10:53:55 +05:30
|
|
|
title: 'Photo colorizer',
|
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/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',
|
2026-11-06 10:53:55 +05:30
|
|
|
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',
|
2026-11-06 10:53:55 +05:30
|
|
|
title: 'Cartoon & anime avatar',
|
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/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',
|
2026-11-06 10:53:55 +05:30
|
|
|
title: 'Vintage polaroid maker',
|
2026-11-04 17:55:18 +05:30
|
|
|
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({
|
2026-11-06 10:53:55 +05:30
|
|
|
title = 'Our tools',
|
|
|
|
|
subtitle = 'Test any tool directly in your browser with your own photos.',
|
2026-11-04 17:55:18 +05:30
|
|
|
items,
|
|
|
|
|
}: ShiftableToolsGridProps) {
|
|
|
|
|
const displayItems = items && items.length >= 8 ? items : DEFAULT_TOOL_ITEMS;
|
|
|
|
|
const row1 = displayItems.slice(0, 4);
|
|
|
|
|
const row2 = displayItems.slice(4, 8);
|
|
|
|
|
|
2026-11-05 18:23:55 +05:30
|
|
|
const [isMiddleReached, setIsMiddleReached] = useState(false);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
const checkPosition = () => {
|
|
|
|
|
const section = document.getElementById('our-tools');
|
|
|
|
|
if (!section) return;
|
|
|
|
|
const rect = section.getBoundingClientRect();
|
|
|
|
|
const inMiddle = rect.top <= window.innerHeight * 0.5 && rect.bottom >= window.innerHeight * 0.15;
|
|
|
|
|
setIsMiddleReached(inMiddle);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
checkPosition();
|
|
|
|
|
window.addEventListener('scroll', checkPosition, { passive: true });
|
|
|
|
|
window.addEventListener('resize', checkPosition, { passive: true });
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener('scroll', checkPosition);
|
|
|
|
|
window.removeEventListener('resize', checkPosition);
|
|
|
|
|
};
|
|
|
|
|
}, []);
|
|
|
|
|
|
2026-11-04 17:55:18 +05:30
|
|
|
return (
|
2026-11-06 10:53:55 +05:30
|
|
|
<section id="our-tools" className="py-16 sm:py-24 px-4 sm:px-6 md:px-8 lg:px-10 bg-paper border-b border-rule relative overflow-hidden">
|
|
|
|
|
<div className="max-w-container mx-auto space-y-10">
|
|
|
|
|
{/* Section Header - Clean editorial layout without eyebrows */}
|
|
|
|
|
<div className="max-w-2xl space-y-2 border-b border-rule pb-5">
|
|
|
|
|
<h2 className="text-3xl sm:text-4xl font-display font-bold text-ink tracking-tight">
|
|
|
|
|
{title}
|
2026-11-04 17:55:18 +05:30
|
|
|
</h2>
|
2026-11-06 10:53:55 +05:30
|
|
|
<p className="text-sm sm:text-base text-ink-2 font-body text-pretty">
|
|
|
|
|
{subtitle}
|
2026-11-04 17:55:18 +05:30
|
|
|
</p>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-05 18:14:27 +05:30
|
|
|
{/* Desktop View (md and up): 2-Row Shiftable Expansion Grid */}
|
|
|
|
|
<div className="hidden md:block space-y-8">
|
2026-11-05 18:23:55 +05:30
|
|
|
<ShiftableRow items={row1} isEnabled={isMiddleReached} />
|
|
|
|
|
<ShiftableRow items={row2} isEnabled={isMiddleReached} />
|
2026-11-04 17:55:18 +05:30
|
|
|
</div>
|
|
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
{/* Mobile / Phone View (<md): Pure Vertical Stack */}
|
2026-11-05 18:14:27 +05:30
|
|
|
<div className="block md:hidden">
|
|
|
|
|
<MobileVerticalToolsList items={displayItems} />
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
{/* All tools link */}
|
|
|
|
|
<div className="pt-4 flex justify-between items-center text-xs font-body text-muted border-t border-rule">
|
|
|
|
|
<span>Eight neural models active on web trial</span>
|
2026-11-04 17:55:18 +05:30
|
|
|
<Link
|
|
|
|
|
href="/tools"
|
2026-11-06 10:53:55 +05:30
|
|
|
className="text-accent hover:underline font-medium inline-flex items-center gap-1"
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
<span>View complete tool directory</span>
|
|
|
|
|
<ArrowRight className="w-3.5 h-3.5" aria-hidden="true" />
|
2026-11-04 17:55:18 +05:30
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 18:14:27 +05:30
|
|
|
function MobileVerticalToolsList({ items }: { items: ToolMediaItem[] }) {
|
|
|
|
|
return (
|
|
|
|
|
<div className="flex flex-col gap-6 w-full">
|
|
|
|
|
{items.map((item) => (
|
|
|
|
|
<div key={item.id} className="w-full flex flex-col">
|
2026-11-06 10:53:55 +05:30
|
|
|
<div className="studio-sheet p-3 crop-marked">
|
|
|
|
|
<div className="relative w-full h-[220px] rounded-card overflow-hidden bg-paper-2">
|
2026-11-05 18:14:27 +05:30
|
|
|
<ToolWindowMedia item={item} isHovered={false} />
|
|
|
|
|
<Link
|
|
|
|
|
href={`/tools/${item.slug}`}
|
2026-11-06 10:53:55 +05:30
|
|
|
className="absolute top-2.5 right-2.5 z-30 inline-flex items-center gap-1 px-2.5 py-1 rounded-card text-xs font-body bg-paper-hi/90 text-ink border border-rule hover:border-ink transition-colors shadow-sm"
|
2026-11-05 18:14:27 +05:30
|
|
|
aria-label={`Open ${item.title}`}
|
|
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
<span>Try tool</span>
|
|
|
|
|
<ArrowRight className="w-3 h-3" aria-hidden="true" />
|
2026-11-05 18:14:27 +05:30
|
|
|
</Link>
|
|
|
|
|
</div>
|
|
|
|
|
<Link
|
|
|
|
|
href={`/tools/${item.slug}`}
|
2026-11-06 10:53:55 +05:30
|
|
|
className="mt-2.5 flex items-center justify-between text-sm font-body font-semibold text-ink hover:text-accent transition-colors"
|
2026-11-05 18:14:27 +05:30
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
<span>{item.title}</span>
|
|
|
|
|
<ArrowRight className="w-3.5 h-3.5 text-muted" aria-hidden="true" />
|
2026-11-05 18:14:27 +05:30
|
|
|
</Link>
|
2026-11-06 10:53:55 +05:30
|
|
|
</div>
|
2026-11-05 18:14:27 +05:30
|
|
|
</div>
|
|
|
|
|
))}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-05 18:23:55 +05:30
|
|
|
function ShiftableRow({ items, isEnabled = true }: { items: ToolMediaItem[]; isEnabled?: boolean }) {
|
2026-11-04 17:55:18 +05:30
|
|
|
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
|
|
|
|
|
2026-11-05 18:23:55 +05:30
|
|
|
useEffect(() => {
|
|
|
|
|
if (!isEnabled) {
|
|
|
|
|
setHoveredId(null);
|
|
|
|
|
}
|
|
|
|
|
}, [isEnabled]);
|
|
|
|
|
|
2026-11-04 17:55:18 +05:30
|
|
|
return (
|
2026-11-06 10:53:55 +05:30
|
|
|
<div className="flex flex-row gap-5 w-full items-start overflow-visible">
|
2026-11-04 17:55:18 +05:30
|
|
|
{items.map((item) => {
|
2026-11-05 18:23:55 +05:30
|
|
|
const isHovered = isEnabled && hoveredId === item.id;
|
|
|
|
|
const hasOtherHovered = isEnabled && hoveredId !== null && !isHovered;
|
2026-11-06 10:53:55 +05:30
|
|
|
const flexGrowValue = isHovered ? 1.25 : hasOtherHovered ? 0.916 : 1;
|
2026-11-04 17:55:18 +05:30
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div
|
|
|
|
|
key={item.id}
|
2026-11-05 18:23:55 +05:30
|
|
|
onMouseEnter={() => {
|
|
|
|
|
if (isEnabled) setHoveredId(item.id);
|
|
|
|
|
}}
|
2026-11-04 17:55:18 +05:30
|
|
|
onMouseLeave={() => setHoveredId(null)}
|
2026-11-06 10:53:55 +05:30
|
|
|
className="flex-1 transition-[flex-grow] duration-300 ease-out flex flex-col min-w-0"
|
|
|
|
|
style={{ flexGrow: flexGrowValue }}
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
<div className="studio-sheet p-3 crop-marked">
|
|
|
|
|
<div className="relative w-full h-[200px] lg:h-[220px] rounded-card overflow-hidden bg-paper-2">
|
2026-11-05 13:20:36 +05:30
|
|
|
<ToolWindowMedia item={item} isHovered={isHovered} />
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-05 13:20:36 +05:30
|
|
|
<Link
|
|
|
|
|
href={`/tools/${item.slug}`}
|
2026-11-06 10:53:55 +05:30
|
|
|
className="absolute top-2.5 right-2.5 z-30 inline-flex items-center gap-1 px-2.5 py-1 rounded-card text-xs font-body bg-paper-hi/90 text-ink border border-rule hover:border-ink transition-colors shadow-sm"
|
2026-11-05 13:20:36 +05:30
|
|
|
aria-label={`Open ${item.title}`}
|
|
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
<span>Try tool</span>
|
|
|
|
|
<ArrowRight className="w-3 h-3" aria-hidden="true" />
|
2026-11-05 13:20:36 +05:30
|
|
|
</Link>
|
2026-11-05 13:10:05 +05:30
|
|
|
</div>
|
2026-11-06 10:53:55 +05:30
|
|
|
|
2026-11-05 13:20:36 +05:30
|
|
|
<Link
|
|
|
|
|
href={`/tools/${item.slug}`}
|
2026-11-06 10:53:55 +05:30
|
|
|
className="mt-2.5 flex items-center justify-between text-sm font-body font-medium text-ink hover:text-accent transition-colors"
|
2026-11-05 13:20:36 +05:30
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
<span className="truncate">{item.title}</span>
|
|
|
|
|
<ArrowRight className="w-3.5 h-3.5 text-muted ml-1 shrink-0" aria-hidden="true" />
|
2026-11-05 13:20:36 +05:30
|
|
|
</Link>
|
2026-11-06 10:53:55 +05:30
|
|
|
</div>
|
2026-11-04 17:55:18 +05:30
|
|
|
</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
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
|
|
|
|
|
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-06 10:53:55 +05:30
|
|
|
clipLayerRef.current.style.clipPath = `inset(0 ${100 - clamped}% 0 0)`;
|
|
|
|
|
(clipLayerRef.current.style as any).webkitClipPath = `inset(0 ${100 - clamped}% 0 0)`;
|
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
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
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
|
|
|
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
|
|
|
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
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
// 1. VIDEO
|
2026-11-04 17:55:18 +05:30
|
|
|
if (item.mediaType === 'video' && item.videoUrl) {
|
|
|
|
|
return (
|
2026-11-06 10:53:55 +05:30
|
|
|
<div className="relative w-full h-full overflow-hidden bg-paper-2 isolate">
|
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-06 10:53:55 +05:30
|
|
|
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
2026-11-05 15:25:23 +05:30
|
|
|
/>
|
2026-11-04 17:55:18 +05:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
// 2. COMPARISON
|
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-06 10:53:55 +05:30
|
|
|
style={{ touchAction: 'pan-y' }}
|
|
|
|
|
className="relative w-full h-full select-none overflow-hidden bg-paper-2 isolate cursor-ew-resize"
|
2026-11-04 17:55:18 +05:30
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
{/* Layer 1: Enhanced Image */}
|
2026-11-04 17:55:18 +05:30
|
|
|
<img
|
2026-11-05 13:42:18 +05:30
|
|
|
src={item.afterUrl}
|
2026-11-06 10:53:55 +05:30
|
|
|
alt={`${item.title} - enhanced`}
|
|
|
|
|
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
2026-11-04 17:55:18 +05:30
|
|
|
loading="lazy"
|
|
|
|
|
/>
|
|
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
{/* Layer 2: Original Image */}
|
2026-11-05 13:42:18 +05:30
|
|
|
<div
|
|
|
|
|
ref={clipLayerRef}
|
2026-11-06 10:53:55 +05:30
|
|
|
className="absolute inset-0 overflow-hidden isolate pointer-events-none"
|
|
|
|
|
style={{ clipPath: 'inset(0 50% 0 0)' }}
|
2026-11-05 13:42:18 +05:30
|
|
|
>
|
|
|
|
|
<img
|
|
|
|
|
src={item.beforeUrl}
|
2026-11-06 10:53:55 +05:30
|
|
|
alt={`${item.title} - original`}
|
|
|
|
|
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
2026-11-05 13:42:18 +05:30
|
|
|
loading="lazy"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2026-11-04 17:55:18 +05:30
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
{/* Slider Divider Line */}
|
2026-11-04 17:55:18 +05:30
|
|
|
<div
|
2026-11-04 18:48:24 +05:30
|
|
|
ref={dividerRef}
|
2026-11-06 10:53:55 +05:30
|
|
|
className="absolute top-0 bottom-0 w-px bg-paper-hi z-10 pointer-events-none -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-06 10:53:55 +05:30
|
|
|
{/* Circular Grab Handle */}
|
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
|
|
|
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-06 10:53:55 +05:30
|
|
|
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 left-1/2 w-7 h-7 rounded-full bg-paper-hi border border-rule flex items-center justify-center text-xs text-accent pointer-events-auto cursor-ew-resize touch-none shadow-sm"
|
2026-11-05 13:10:05 +05:30
|
|
|
>
|
2026-11-06 10:53:55 +05:30
|
|
|
<svg className="w-3 h-3 text-accent pointer-events-none" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true">
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2} d="M8 9l-3 3 3 3m8-6l3 3-3 3" />
|
|
|
|
|
</svg>
|
2026-11-04 17:55:18 +05:30
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
{/* Badges in sentence case body face */}
|
|
|
|
|
<div className="absolute bottom-2 inset-x-2 flex justify-between pointer-events-none z-20 text-xs font-body text-ink">
|
|
|
|
|
<span className="bg-paper-hi/90 px-1.5 py-0.5 rounded border border-rule shadow-xs">
|
|
|
|
|
Original
|
2026-11-04 18:48:24 +05:30
|
|
|
</span>
|
2026-11-06 10:53:55 +05:30
|
|
|
<span className="bg-paper-hi/90 px-1.5 py-0.5 rounded border border-rule shadow-xs">
|
|
|
|
|
Enhanced
|
2026-11-05 13:42:18 +05:30
|
|
|
</span>
|
2026-11-04 18:48:24 +05:30
|
|
|
</div>
|
2026-11-04 17:55:18 +05:30
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-06 10:53:55 +05:30
|
|
|
// 3. PHOTO
|
2026-11-04 17:55:18 +05:30
|
|
|
return (
|
2026-11-06 10:53:55 +05:30
|
|
|
<div className="relative w-full h-full overflow-hidden bg-paper-2 isolate">
|
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-06 10:53:55 +05:30
|
|
|
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
2026-11-04 17:55:18 +05:30
|
|
|
loading="lazy"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|