checkpoint2
This commit is contained in:
@@ -2,8 +2,7 @@
|
||||
|
||||
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
||||
import Link from 'next/link';
|
||||
import { ArrowRight, Sparkles } from 'lucide-react';
|
||||
import { TextAnimate } from '@/components/magicui/text-animate';
|
||||
import { ArrowRight } from 'lucide-react';
|
||||
import { ToolItem } from '@/types';
|
||||
|
||||
export interface ToolMediaItem {
|
||||
@@ -27,11 +26,11 @@ export interface ShiftableToolsGridProps {
|
||||
}
|
||||
|
||||
export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
||||
// ROW 1 (4 items) - Landscape 16:9 assets
|
||||
// ROW 1 (4 items)
|
||||
{
|
||||
id: 'tool-blemish',
|
||||
slug: 'blemish-remover',
|
||||
title: 'Skin & Blemish Retoucher',
|
||||
title: 'Skin & blemish retoucher',
|
||||
mediaType: 'comparison',
|
||||
beforeUrl: '/management/pages/home/sections/our-tools/blemish-remover/before.jpg',
|
||||
afterUrl: '/management/pages/home/sections/our-tools/blemish-remover/after.jpg',
|
||||
@@ -39,7 +38,7 @@ export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
||||
{
|
||||
id: 'tool-bg-remover',
|
||||
slug: 'background-remover',
|
||||
title: 'Background Remover (Alpha Matting)',
|
||||
title: 'Background remover (alpha matting)',
|
||||
mediaType: 'video',
|
||||
videoUrl: '/management/pages/home/sections/our-tools/background-remover/sample_reel.mp4',
|
||||
poster: '/management/pages/home/sections/our-tools/background-remover/poster.jpg',
|
||||
@@ -47,7 +46,7 @@ export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
||||
{
|
||||
id: 'tool-enhancer',
|
||||
slug: 'photo-enhancer',
|
||||
title: 'Photo Enhancer 4K',
|
||||
title: 'Photo enhancer 4K',
|
||||
mediaType: 'comparison',
|
||||
beforeUrl: '/management/pages/home/sections/our-tools/photo-enhancer/before.jpg',
|
||||
afterUrl: '/management/pages/home/sections/our-tools/photo-enhancer/after.jpg',
|
||||
@@ -55,17 +54,17 @@ export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
||||
{
|
||||
id: 'tool-restorer',
|
||||
slug: 'old-photo-restorer',
|
||||
title: 'Vintage Photo Restorer',
|
||||
title: 'Vintage photo restorer',
|
||||
mediaType: 'comparison',
|
||||
beforeUrl: '/management/pages/home/sections/our-tools/old-photo-restorer/before.jpg',
|
||||
afterUrl: '/management/pages/home/sections/our-tools/old-photo-restorer/after.jpg',
|
||||
},
|
||||
|
||||
// ROW 2 (4 items) - Landscape 16:9 assets
|
||||
// ROW 2 (4 items)
|
||||
{
|
||||
id: 'tool-colorization',
|
||||
slug: 'colorization',
|
||||
title: 'AI Colorizer',
|
||||
title: 'Photo colorizer',
|
||||
mediaType: 'comparison',
|
||||
beforeUrl: '/management/pages/home/sections/our-tools/colorization/before.jpg',
|
||||
afterUrl: '/management/pages/home/sections/our-tools/colorization/after.jpg',
|
||||
@@ -73,7 +72,7 @@ export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
||||
{
|
||||
id: 'tool-teeth',
|
||||
slug: 'teeth-whitener',
|
||||
title: 'Teeth Whitener & Brightener',
|
||||
title: 'Teeth whitener & brightener',
|
||||
mediaType: 'comparison',
|
||||
beforeUrl: '/management/pages/home/sections/our-tools/teeth-whitener/before.jpg',
|
||||
afterUrl: '/management/pages/home/sections/our-tools/teeth-whitener/after.jpg',
|
||||
@@ -81,7 +80,7 @@ export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
||||
{
|
||||
id: 'tool-cartoon',
|
||||
slug: 'cartoon-avatar',
|
||||
title: 'Cartoon & Anime Avatar',
|
||||
title: 'Cartoon & anime avatar',
|
||||
mediaType: 'comparison',
|
||||
beforeUrl: '/management/pages/home/sections/our-tools/cartoon-avatar/before.jpg',
|
||||
afterUrl: '/management/pages/home/sections/our-tools/cartoon-avatar/after.jpg',
|
||||
@@ -89,22 +88,21 @@ export const DEFAULT_TOOL_ITEMS: ToolMediaItem[] = [
|
||||
{
|
||||
id: 'tool-polaroid',
|
||||
slug: 'polaroid-maker',
|
||||
title: 'Vintage Polaroid Maker',
|
||||
title: 'Vintage polaroid maker',
|
||||
mediaType: 'photo',
|
||||
imageUrl: '/management/pages/home/sections/our-tools/polaroid-maker/image.jpg',
|
||||
},
|
||||
];
|
||||
|
||||
export function ShiftableToolsGridSection({
|
||||
title = 'Our Tools',
|
||||
subtitle = 'Click on any tool window to try with your own photos in seconds.',
|
||||
title = 'Our tools',
|
||||
subtitle = 'Test any tool directly in your browser with your own photos.',
|
||||
items,
|
||||
}: ShiftableToolsGridProps) {
|
||||
const displayItems = items && items.length >= 8 ? items : DEFAULT_TOOL_ITEMS;
|
||||
const row1 = displayItems.slice(0, 4);
|
||||
const row2 = displayItems.slice(4, 8);
|
||||
|
||||
// Expansion only starts when that section reaches the middle (top of section <= 50% of viewport)
|
||||
const [isMiddleReached, setIsMiddleReached] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -112,7 +110,6 @@ export function ShiftableToolsGridSection({
|
||||
const section = document.getElementById('our-tools');
|
||||
if (!section) return;
|
||||
const rect = section.getBoundingClientRect();
|
||||
// Only start expansion once the section reaches the middle of the viewport
|
||||
const inMiddle = rect.top <= window.innerHeight * 0.5 && rect.bottom >= window.innerHeight * 0.15;
|
||||
setIsMiddleReached(inMiddle);
|
||||
};
|
||||
@@ -127,32 +124,15 @@ export function ShiftableToolsGridSection({
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<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">
|
||||
{/* 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">
|
||||
<TextAnimate animation="slideLeft" by="word">
|
||||
{title}
|
||||
</TextAnimate>
|
||||
<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}
|
||||
</h2>
|
||||
|
||||
<p className="text-sm sm:text-base text-slate-600 font-sans text-pretty">
|
||||
<TextAnimate animation="fadeIn" by="word" delay={0.08}>
|
||||
{subtitle}
|
||||
</TextAnimate>
|
||||
<p className="text-sm sm:text-base text-ink-2 font-body text-pretty">
|
||||
{subtitle}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
@@ -162,19 +142,20 @@ export function ShiftableToolsGridSection({
|
||||
<ShiftableRow items={row2} isEnabled={isMiddleReached} />
|
||||
</div>
|
||||
|
||||
{/* Mobile / Phone View (<md): Pure Vertical Stack (NOT placed horizontally) */}
|
||||
{/* Mobile / Phone View (<md): Pure Vertical Stack */}
|
||||
<div className="block md:hidden">
|
||||
<MobileVerticalToolsList items={displayItems} />
|
||||
</div>
|
||||
|
||||
{/* See More Section Button Redirecting to /tools */}
|
||||
<div className="pt-6 text-center">
|
||||
{/* 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>
|
||||
<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-[transform,opacity] duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] hover:scale-105 active:scale-95"
|
||||
className="text-accent hover:underline font-medium inline-flex items-center gap-1"
|
||||
>
|
||||
<span>See More Tools</span>
|
||||
<ArrowRight className="w-4 h-4 transition-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] group-hover:translate-x-1" />
|
||||
<span>View complete tool directory</span>
|
||||
<ArrowRight className="w-3.5 h-3.5" aria-hidden="true" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
@@ -187,39 +168,26 @@ function MobileVerticalToolsList({ items }: { items: ToolMediaItem[] }) {
|
||||
<div className="flex flex-col gap-6 w-full">
|
||||
{items.map((item) => (
|
||||
<div key={item.id} className="w-full flex flex-col">
|
||||
{item.mediaType === 'comparison' ? (
|
||||
<div
|
||||
style={{ borderRadius: '24px' }}
|
||||
className="group block relative w-full h-[240px] rounded-[24px] overflow-hidden isolate bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm"
|
||||
>
|
||||
<div className="studio-sheet p-3 crop-marked">
|
||||
<div className="relative w-full h-[220px] rounded-card overflow-hidden bg-paper-2">
|
||||
<ToolWindowMedia item={item} isHovered={false} />
|
||||
<Link
|
||||
href={`/tools/${item.slug}`}
|
||||
className="absolute top-3 right-3 z-30 inline-flex items-center gap-1.5 px-3.5 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"
|
||||
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"
|
||||
aria-label={`Open ${item.title}`}
|
||||
>
|
||||
<span>TRY TOOL</span>
|
||||
<ArrowRight className="w-2.5 h-2.5" />
|
||||
<span>Try tool</span>
|
||||
<ArrowRight className="w-3 h-3" aria-hidden="true" />
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
<Link
|
||||
href={`/tools/${item.slug}`}
|
||||
style={{ borderRadius: '24px' }}
|
||||
className="group block relative w-full h-[240px] rounded-[24px] overflow-hidden isolate bg-slate-950 border border-slate-900/[0.08] shadow-cream-sm cursor-pointer"
|
||||
className="mt-2.5 flex items-center justify-between text-sm font-body font-semibold text-ink hover:text-accent transition-colors"
|
||||
>
|
||||
<ToolWindowMedia item={item} isHovered={false} />
|
||||
<span>{item.title}</span>
|
||||
<ArrowRight className="w-3.5 h-3.5 text-muted" aria-hidden="true" />
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{/* Title Below Window */}
|
||||
<Link
|
||||
href={`/tools/${item.slug}`}
|
||||
className="mt-2.5 px-1 flex items-center justify-between text-sm font-display font-bold text-slate-900 hover:text-blue-600 transition-colors"
|
||||
>
|
||||
<span>{item.title}</span>
|
||||
<ArrowRight className="w-4 h-4 text-slate-400 group-hover:text-blue-600 group-hover:translate-x-0.5 transition-transform" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
@@ -229,7 +197,6 @@ function MobileVerticalToolsList({ items }: { items: ToolMediaItem[] }) {
|
||||
function ShiftableRow({ items, isEnabled = true }: { items: ToolMediaItem[]; isEnabled?: boolean }) {
|
||||
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
||||
|
||||
// Clear any active hover expansion if the section leaves the active middle viewport zone
|
||||
useEffect(() => {
|
||||
if (!isEnabled) {
|
||||
setHoveredId(null);
|
||||
@@ -237,17 +204,11 @@ function ShiftableRow({ items, isEnabled = true }: { items: ToolMediaItem[]; isE
|
||||
}, [isEnabled]);
|
||||
|
||||
return (
|
||||
<div className="flex flex-row gap-6 w-full items-start overflow-visible">
|
||||
<div className="flex flex-row gap-5 w-full items-start overflow-visible">
|
||||
{items.map((item) => {
|
||||
const isHovered = isEnabled && hoveredId === item.id;
|
||||
const hasOtherHovered = isEnabled && hoveredId !== null && !isHovered;
|
||||
|
||||
// Subtle, refined expansion (lesser shift, lesser expansion):
|
||||
// Hovered card: 1.28 flex-grow (~32% width, gentle expansion)
|
||||
// Other cards: 0.9066 flex-grow (~22.6% width, minimal displacement)
|
||||
// At rest or before middle reached: 1.0 flex-grow (25% width each)
|
||||
// Sum is mathematically conserved at exactly 4.0 (1.28 + 3 * 0.9066 = 4.00)
|
||||
const flexGrowValue = isHovered ? 1.28 : hasOtherHovered ? 0.9066 : 1;
|
||||
const flexGrowValue = isHovered ? 1.25 : hasOtherHovered ? 0.916 : 1;
|
||||
|
||||
return (
|
||||
<div
|
||||
@@ -256,63 +217,31 @@ function ShiftableRow({ items, isEnabled = true }: { items: ToolMediaItem[]; isE
|
||||
if (isEnabled) setHoveredId(item.id);
|
||||
}}
|
||||
onMouseLeave={() => setHoveredId(null)}
|
||||
className="w-[82vw] max-w-[320px] md:max-w-none md:w-auto shrink-0 md:shrink md:flex-1 snap-start transition-[flex-grow] duration-500 ease-[cubic-bezier(0.16,1,0.3,1)] flex flex-col min-w-0"
|
||||
style={{
|
||||
flexGrow: flexGrowValue,
|
||||
}}
|
||||
className="flex-1 transition-[flex-grow] duration-300 ease-out flex flex-col min-w-0"
|
||||
style={{ flexGrow: flexGrowValue }}
|
||||
>
|
||||
{/* Window Container with strictly locked pixel height & landscape aspect */}
|
||||
{item.mediaType === 'comparison' ? (
|
||||
<div
|
||||
style={{ borderRadius: '28px' }}
|
||||
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"
|
||||
>
|
||||
{/* GPU-Composited Shadow Elevation Layer */}
|
||||
<div
|
||||
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"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
{/* Media Renderer (Interactive comparison slider with desktop hover + mobile touch handle) */}
|
||||
<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">
|
||||
<ToolWindowMedia item={item} isHovered={isHovered} />
|
||||
|
||||
{/* Dedicated Tool Link Pill on top right so sliding never accidentally navigates */}
|
||||
<Link
|
||||
href={`/tools/${item.slug}`}
|
||||
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"
|
||||
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"
|
||||
aria-label={`Open ${item.title}`}
|
||||
>
|
||||
<span>TRY TOOL</span>
|
||||
<ArrowRight className="w-2.5 h-2.5" />
|
||||
<span>Try tool</span>
|
||||
<ArrowRight className="w-3 h-3" aria-hidden="true" />
|
||||
</Link>
|
||||
</div>
|
||||
) : (
|
||||
|
||||
<Link
|
||||
href={`/tools/${item.slug}`}
|
||||
style={{ borderRadius: '28px' }}
|
||||
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"
|
||||
className="mt-2.5 flex items-center justify-between text-sm font-body font-medium text-ink hover:text-accent transition-colors"
|
||||
>
|
||||
{/* GPU-Composited Shadow Elevation Layer (Opacity-only transition, zero paint thrash) */}
|
||||
<div
|
||||
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"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
{/* Media Renderer */}
|
||||
<ToolWindowMedia item={item} isHovered={isHovered} />
|
||||
<span className="truncate">{item.title}</span>
|
||||
<ArrowRight className="w-3.5 h-3.5 text-muted ml-1 shrink-0" aria-hidden="true" />
|
||||
</Link>
|
||||
)}
|
||||
|
||||
{/* 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 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-transform duration-300 ease-[cubic-bezier(0.16,1,0.3,1)] flex-shrink-0 ml-1.5" />
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
@@ -327,7 +256,6 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
const clipLayerRef = useRef<HTMLDivElement>(null);
|
||||
const handleRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// High performance refs - completely eliminates per-frame React re-renders!
|
||||
const isManualRef = useRef(false);
|
||||
const isPointerDownRef = useRef(false);
|
||||
const currentPercentRef = useRef(50);
|
||||
@@ -335,7 +263,6 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
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(0, Math.min(100, percent));
|
||||
currentPercentRef.current = clamped;
|
||||
@@ -343,16 +270,14 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
dividerRef.current.style.left = `${clamped}%`;
|
||||
}
|
||||
if (clipLayerRef.current) {
|
||||
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)`;
|
||||
clipLayerRef.current.style.clipPath = `inset(0 ${100 - clamped}% 0 0)`;
|
||||
(clipLayerRef.current.style as any).webkitClipPath = `inset(0 ${100 - clamped}% 0 0)`;
|
||||
}
|
||||
if (handleRef.current) {
|
||||
handleRef.current.setAttribute('aria-valuenow', `${Math.round(clamped)}`);
|
||||
}
|
||||
}, []);
|
||||
|
||||
// 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
|
||||
useEffect(() => {
|
||||
if (item.mediaType !== 'video') return;
|
||||
const video = videoRef.current;
|
||||
@@ -394,7 +319,6 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
};
|
||||
}, [item.mediaType]);
|
||||
|
||||
// When unhovered, reset slider smoothly to 50%
|
||||
useEffect(() => {
|
||||
if (item.mediaType !== 'comparison') return;
|
||||
|
||||
@@ -408,7 +332,6 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
}
|
||||
}, [isHovered, item.mediaType, setSliderDOM]);
|
||||
|
||||
// Instant pixel-precise cursor alignment calculation
|
||||
const updateToClientX = useCallback((clientX: number) => {
|
||||
if (!containerRef.current) return;
|
||||
const rect = cachedRectRef.current || containerRef.current.getBoundingClientRect();
|
||||
@@ -418,7 +341,6 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
setSliderDOM(percent);
|
||||
}, [setSliderDOM]);
|
||||
|
||||
// Desktop Mouse Movement: Immediately aligns comparison bar with cursor on hover and stays locked
|
||||
const handleContainerPointerEnter = (e: React.PointerEvent<HTMLDivElement> | React.MouseEvent<HTMLDivElement>) => {
|
||||
if (item.mediaType !== 'comparison') return;
|
||||
if (!('pointerType' in e) || e.pointerType === 'mouse') {
|
||||
@@ -451,7 +373,6 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
}
|
||||
};
|
||||
|
||||
// Dedicated Drag Handlers for Center Arrow Handle (Works on mobile touch & desktop click-drag)
|
||||
const handleHandlePointerDown = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (item.mediaType !== 'comparison') return;
|
||||
if (e.button !== 0 && e.pointerType === 'mouse') return;
|
||||
@@ -511,27 +432,10 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
// 1. VIDEO (Strictly locked to fixed 680px centered width - ZERO ZOOM)
|
||||
// 1. VIDEO
|
||||
if (item.mediaType === 'video' && item.videoUrl) {
|
||||
return (
|
||||
<div
|
||||
style={{ borderRadius: '28px' }}
|
||||
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate"
|
||||
>
|
||||
<div className="relative w-full h-full overflow-hidden bg-paper-2 isolate">
|
||||
<video
|
||||
ref={videoRef}
|
||||
src={item.videoUrl}
|
||||
@@ -541,19 +445,13 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
loop
|
||||
playsInline
|
||||
preload="auto"
|
||||
style={{ borderRadius: '28px' }}
|
||||
className="absolute inset-0 w-full h-full md:inset-y-0 md:left-1/2 md:-translate-x-1/2 md:w-[680px] md:max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
||||
/>
|
||||
{/* GPU-composited overlay (opacity only) */}
|
||||
<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"
|
||||
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 2. COMPARISON: Pixel-perfect clip-path slider (ZERO ZOOM - locked fixed scale & centered position)
|
||||
// 2. COMPARISON
|
||||
if (item.mediaType === 'comparison' && item.beforeUrl && item.afterUrl) {
|
||||
return (
|
||||
<div
|
||||
@@ -564,54 +462,44 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
onMouseMove={handleContainerPointerMove}
|
||||
onPointerLeave={handleContainerPointerLeave}
|
||||
onMouseLeave={handleContainerPointerLeave}
|
||||
style={{
|
||||
touchAction: 'pan-y',
|
||||
borderRadius: '28px',
|
||||
}}
|
||||
className="relative w-full h-full select-none overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate cursor-ew-resize"
|
||||
style={{ touchAction: 'pan-y' }}
|
||||
className="relative w-full h-full select-none overflow-hidden bg-paper-2 isolate cursor-ew-resize"
|
||||
>
|
||||
{/* Layer 1: AFTER Image (Base layer, fixed scale & position, 0% zoom) */}
|
||||
{/* Layer 1: Enhanced Image */}
|
||||
<img
|
||||
src={item.afterUrl}
|
||||
alt="After"
|
||||
style={{ borderRadius: '28px' }}
|
||||
className="absolute inset-0 w-full h-full md:inset-y-0 md:left-1/2 md:-translate-x-1/2 md:w-[680px] md:max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
||||
alt={`${item.title} - enhanced`}
|
||||
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
||||
loading="lazy"
|
||||
/>
|
||||
|
||||
{/* Layer 2: BEFORE Image (Clipped container-sized layer - 100% exact alignment with slider divider on phone & desktop) */}
|
||||
{/* Layer 2: Original Image */}
|
||||
<div
|
||||
ref={clipLayerRef}
|
||||
className="absolute inset-0 overflow-hidden rounded-[28px] sm:rounded-[36px] isolate pointer-events-none"
|
||||
style={{
|
||||
borderRadius: '28px',
|
||||
clipPath: 'inset(0 50% 0 0 round 28px 0 0 28px)',
|
||||
WebkitClipPath: 'inset(0 50% 0 0 round 28px 0 0 28px)',
|
||||
}}
|
||||
className="absolute inset-0 overflow-hidden isolate pointer-events-none"
|
||||
style={{ clipPath: 'inset(0 50% 0 0)' }}
|
||||
>
|
||||
<img
|
||||
src={item.beforeUrl}
|
||||
alt="Before"
|
||||
style={{ borderRadius: '28px' }}
|
||||
className="absolute inset-0 w-full h-full md:inset-y-0 md:left-1/2 md:-translate-x-1/2 md:w-[680px] md:max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
||||
alt={`${item.title} - original`}
|
||||
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
||||
loading="lazy"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Glowing Slider Divider Line (pointer-events-none so touching the line allows page scroll) */}
|
||||
{/* Slider Divider Line */}
|
||||
<div
|
||||
ref={dividerRef}
|
||||
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"
|
||||
className="absolute top-0 bottom-0 w-px bg-paper-hi z-10 pointer-events-none -translate-x-1/2"
|
||||
style={{ left: '50%' }}
|
||||
>
|
||||
{/* Circular Grab Handle with Before/After Arrow Cue & Touch Hit Area */}
|
||||
{/* Circular Grab Handle */}
|
||||
<div
|
||||
ref={handleRef}
|
||||
onPointerDown={handleHandlePointerDown}
|
||||
onPointerMove={handleHandlePointerMove}
|
||||
onPointerUp={handleHandlePointerUp}
|
||||
onPointerCancel={handleHandlePointerUp}
|
||||
onKeyDown={handleKeyDown}
|
||||
role="slider"
|
||||
aria-label="Before and after comparison slider"
|
||||
aria-valuemin={0}
|
||||
@@ -619,45 +507,36 @@ function ToolWindowMedia({ item, isHovered }: { item: ToolMediaItem; isHovered:
|
||||
aria-valuenow={50}
|
||||
tabIndex={0}
|
||||
style={{ touchAction: 'none' }}
|
||||
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"
|
||||
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"
|
||||
>
|
||||
↔
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Badges with Smooth Contrast: BEFORE on left, AFTER on right */}
|
||||
<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/85 px-2 py-0.5 rounded border border-white/10 shadow-xs">
|
||||
BEFORE
|
||||
{/* 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
|
||||
</span>
|
||||
<span className="bg-blue-600 px-2 py-0.5 rounded border border-white/20 shadow-xs">
|
||||
AFTER
|
||||
<span className="bg-paper-hi/90 px-1.5 py-0.5 rounded border border-rule shadow-xs">
|
||||
Enhanced
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// 3. PHOTO (Strictly locked to fixed 680px centered width - ZERO ZOOM)
|
||||
// 3. PHOTO
|
||||
return (
|
||||
<div
|
||||
style={{ borderRadius: '28px' }}
|
||||
className="relative w-full h-full overflow-hidden bg-slate-950 rounded-[28px] sm:rounded-[36px] isolate"
|
||||
>
|
||||
<div className="relative w-full h-full overflow-hidden bg-paper-2 isolate">
|
||||
<img
|
||||
src={item.imageUrl || item.afterUrl || item.beforeUrl || '/brand/og-default.png'}
|
||||
alt={item.title}
|
||||
style={{ borderRadius: '28px' }}
|
||||
className="absolute inset-0 w-full h-full md:inset-y-0 md:left-1/2 md:-translate-x-1/2 md:w-[680px] md:max-w-none object-cover pointer-events-none [backface-visibility:hidden]"
|
||||
className="absolute inset-0 w-full h-full object-cover pointer-events-none"
|
||||
loading="lazy"
|
||||
/>
|
||||
{/* GPU-composited overlay (opacity only) */}
|
||||
<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"
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user