2026-11-03 16:44:13 +05:30
|
|
|
'use client';
|
|
|
|
|
|
|
|
|
|
import React, { useState, useRef, useCallback, useEffect } from 'react';
|
|
|
|
|
import { Eye, Sparkles, Scan, Activity } from 'lucide-react';
|
|
|
|
|
|
|
|
|
|
interface Cinematic3DComparisonProps {
|
|
|
|
|
beforeUrl: string;
|
|
|
|
|
afterUrl: string;
|
|
|
|
|
beforeLabel?: string;
|
|
|
|
|
afterLabel?: string;
|
|
|
|
|
caption?: string;
|
|
|
|
|
aspectRatio?: string;
|
|
|
|
|
autoSlide?: boolean;
|
|
|
|
|
maxTilt?: number;
|
|
|
|
|
className?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export function Cinematic3DComparison({
|
|
|
|
|
beforeUrl,
|
|
|
|
|
afterUrl,
|
|
|
|
|
beforeLabel = 'RAW SOURCE',
|
|
|
|
|
afterLabel = 'AI RECONSTRUCTED',
|
|
|
|
|
caption,
|
|
|
|
|
aspectRatio = 'aspect-[4/3] sm:aspect-[16/10]',
|
2026-11-03 18:06:20 +05:30
|
|
|
autoSlide = false,
|
|
|
|
|
maxTilt = 6,
|
2026-11-03 16:44:13 +05:30
|
|
|
className = '',
|
|
|
|
|
}: Cinematic3DComparisonProps) {
|
|
|
|
|
const [sliderPosition, setSliderPosition] = useState(50);
|
|
|
|
|
const [isDragging, setIsDragging] = useState(false);
|
|
|
|
|
|
|
|
|
|
const containerRef = useRef<HTMLDivElement>(null);
|
2026-11-03 18:06:20 +05:30
|
|
|
const glareRef = useRef<HTMLDivElement>(null);
|
2026-11-03 16:44:13 +05:30
|
|
|
|
2026-11-03 18:06:20 +05:30
|
|
|
// Auto-slide smooth sine oscillation loop (only when explicitly requested)
|
2026-11-03 16:44:13 +05:30
|
|
|
useEffect(() => {
|
2026-11-03 18:06:20 +05:30
|
|
|
if (!autoSlide || isDragging) return;
|
2026-11-03 16:44:13 +05:30
|
|
|
|
2026-11-03 18:06:20 +05:30
|
|
|
let animId: number;
|
|
|
|
|
const start = Date.now();
|
2026-11-03 16:44:13 +05:30
|
|
|
const animate = () => {
|
2026-11-03 18:06:20 +05:30
|
|
|
const elapsed = Date.now() - start;
|
|
|
|
|
// Gentle cinematic oscillation between 30% and 70%
|
|
|
|
|
const newPos = 50 + 20 * Math.sin(elapsed * 0.0014);
|
2026-11-03 16:44:13 +05:30
|
|
|
setSliderPosition(newPos);
|
2026-11-03 18:06:20 +05:30
|
|
|
animId = requestAnimationFrame(animate);
|
2026-11-03 16:44:13 +05:30
|
|
|
};
|
|
|
|
|
|
2026-11-03 18:06:20 +05:30
|
|
|
animId = requestAnimationFrame(animate);
|
2026-11-03 16:44:13 +05:30
|
|
|
|
|
|
|
|
return () => {
|
2026-11-03 18:06:20 +05:30
|
|
|
if (animId) cancelAnimationFrame(animId);
|
2026-11-03 16:44:13 +05:30
|
|
|
};
|
2026-11-03 18:06:20 +05:30
|
|
|
}, [autoSlide, isDragging]);
|
2026-11-03 16:44:13 +05:30
|
|
|
|
|
|
|
|
// Handle position calculation
|
|
|
|
|
const handleMove = useCallback((clientX: number) => {
|
|
|
|
|
if (!containerRef.current) return;
|
|
|
|
|
const rect = containerRef.current.getBoundingClientRect();
|
|
|
|
|
const x = Math.max(0, Math.min(clientX - rect.left, rect.width));
|
|
|
|
|
const percent = Math.max(0, Math.min(100, (x / rect.width) * 100));
|
|
|
|
|
setSliderPosition(percent);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
const handleTouchMove = useCallback((e: TouchEvent) => {
|
|
|
|
|
if (!isDragging) return;
|
|
|
|
|
handleMove(e.touches[0].clientX);
|
|
|
|
|
}, [isDragging, handleMove]);
|
|
|
|
|
|
|
|
|
|
const handleMouseMove = useCallback((e: MouseEvent) => {
|
|
|
|
|
if (!isDragging) return;
|
|
|
|
|
handleMove(e.clientX);
|
|
|
|
|
}, [isDragging, handleMove]);
|
|
|
|
|
|
|
|
|
|
const handleMouseUp = useCallback(() => {
|
|
|
|
|
setIsDragging(false);
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
if (isDragging) {
|
|
|
|
|
window.addEventListener('mousemove', handleMouseMove, { passive: true });
|
|
|
|
|
window.addEventListener('mouseup', handleMouseUp);
|
|
|
|
|
window.addEventListener('touchmove', handleTouchMove, { passive: true });
|
|
|
|
|
window.addEventListener('touchend', handleMouseUp);
|
|
|
|
|
}
|
|
|
|
|
return () => {
|
|
|
|
|
window.removeEventListener('mousemove', handleMouseMove);
|
|
|
|
|
window.removeEventListener('mouseup', handleMouseUp);
|
|
|
|
|
window.removeEventListener('touchmove', handleTouchMove);
|
|
|
|
|
window.removeEventListener('touchend', handleMouseUp);
|
|
|
|
|
};
|
|
|
|
|
}, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove]);
|
|
|
|
|
|
2026-11-03 18:06:20 +05:30
|
|
|
// 3D Spatial Tilt - Pure Direct DOM Manipulation (Zero React Re-renders on mousemove!)
|
2026-11-03 16:44:13 +05:30
|
|
|
const handleStageMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
|
|
|
if (!containerRef.current) return;
|
|
|
|
|
const rect = containerRef.current.getBoundingClientRect();
|
|
|
|
|
const x = (e.clientX - rect.left) / rect.width;
|
|
|
|
|
const y = (e.clientY - rect.top) / rect.height;
|
|
|
|
|
|
|
|
|
|
const rx = -(y - 0.5) * maxTilt * 2;
|
|
|
|
|
const ry = (x - 0.5) * maxTilt * 2;
|
|
|
|
|
|
2026-11-03 18:06:20 +05:30
|
|
|
containerRef.current.style.transform = `rotateX(${rx.toFixed(2)}deg) rotateY(${ry.toFixed(2)}deg) scale3d(1.012, 1.012, 1.012)`;
|
|
|
|
|
if (glareRef.current) {
|
|
|
|
|
glareRef.current.style.opacity = '0.55';
|
|
|
|
|
glareRef.current.style.background = `radial-gradient(circle 380px at ${(x * 100).toFixed(1)}% ${(y * 100).toFixed(1)}%, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.08) 50%, transparent 80%)`;
|
|
|
|
|
}
|
2026-11-03 16:44:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const handleMouseLeave = () => {
|
2026-11-03 18:06:20 +05:30
|
|
|
if (containerRef.current) {
|
|
|
|
|
containerRef.current.style.transform = 'rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)';
|
|
|
|
|
}
|
|
|
|
|
if (glareRef.current) {
|
|
|
|
|
glareRef.current.style.opacity = '0';
|
|
|
|
|
}
|
2026-11-03 16:44:13 +05:30
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className={`w-full perspective-1400 select-none ${className}`}>
|
|
|
|
|
{/* 3D Kinetic Tilt Stage */}
|
|
|
|
|
<div
|
|
|
|
|
ref={containerRef}
|
|
|
|
|
onMouseMove={handleStageMouseMove}
|
|
|
|
|
onMouseLeave={handleMouseLeave}
|
2026-11-03 18:06:20 +05:30
|
|
|
onMouseDown={() => setIsDragging(true)}
|
|
|
|
|
onTouchStart={() => setIsDragging(true)}
|
|
|
|
|
className={`relative w-full ${aspectRatio} rounded-2xl sm:rounded-3xl overflow-hidden cursor-ew-resize preserve-3d transition-transform duration-150 ease-out shadow-cinematic-3d hover:shadow-cinematic-hover border border-slate-900/[0.08] bg-slate-950`}
|
2026-11-03 16:44:13 +05:30
|
|
|
style={{
|
2026-11-03 18:06:20 +05:30
|
|
|
transform: 'rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)',
|
2026-11-03 16:44:13 +05:30
|
|
|
touchAction: 'pan-y',
|
|
|
|
|
}}
|
|
|
|
|
>
|
|
|
|
|
{/* Layer 1: After Image (Full Reconstructed Neural Result) */}
|
|
|
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
|
|
|
<img
|
|
|
|
|
src={afterUrl}
|
|
|
|
|
alt="AI Reconstructed result"
|
|
|
|
|
loading="eager"
|
|
|
|
|
className="absolute inset-0 w-full h-full object-cover pointer-events-none will-change-transform"
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Dynamic 3D Cursor Specular Light Glint */}
|
|
|
|
|
<div
|
2026-11-03 18:06:20 +05:30
|
|
|
ref={glareRef}
|
|
|
|
|
className="absolute inset-0 pointer-events-none transition-opacity duration-300 z-10 opacity-0"
|
2026-11-03 16:44:13 +05:30
|
|
|
style={{
|
2026-11-03 18:06:20 +05:30
|
|
|
background: 'radial-gradient(circle 380px at 50% 50%, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.08) 50%, transparent 80%)',
|
2026-11-03 16:44:13 +05:30
|
|
|
}}
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
|
|
{/* Layer 2: Before Image (Clipped Left Side with Polygon Split) */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute inset-0 overflow-hidden pointer-events-none will-change-transform"
|
|
|
|
|
style={{ clipPath: `polygon(0 0, ${sliderPosition}% 0, ${sliderPosition}% 100%, 0 100%)` }}
|
|
|
|
|
>
|
|
|
|
|
{/* eslint-disable-next-line @next/next/no-img-element */}
|
|
|
|
|
<img
|
|
|
|
|
src={beforeUrl}
|
|
|
|
|
alt="Original input"
|
|
|
|
|
loading="eager"
|
|
|
|
|
className="absolute inset-0 w-full h-full object-cover"
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Layer 3: Illuminated Holographic Laser Split Line (Champagne Gold + Electric Sapphire) */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute top-0 bottom-0 w-[2px] bg-gradient-to-b from-blue-400 via-white to-amber-300 holographic-laser-split z-20 pointer-events-none will-change-transform"
|
|
|
|
|
style={{ left: `${sliderPosition}%` }}
|
|
|
|
|
>
|
|
|
|
|
{/* Subtle Vertical Caustic Glow Beam */}
|
|
|
|
|
<div className="absolute -top-4 -bottom-4 -left-1.5 w-3.5 bg-gradient-to-r from-blue-500/20 via-white/40 to-amber-400/20 blur-[3px]" />
|
|
|
|
|
|
|
|
|
|
{/* 3D Tactile Center Control Handle floating at translateZ */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-9 h-9 sm:w-11 sm:h-11 rounded-full bg-white/95 backdrop-blur-md border border-slate-900/10 shadow-2xl flex items-center justify-center pointer-events-auto cursor-ew-resize hover:scale-110 active:scale-95 transition-transform duration-150 preserve-3d"
|
|
|
|
|
style={{ transform: 'translateZ(28px)' }}
|
|
|
|
|
>
|
|
|
|
|
{/* Outer Metallic Ring */}
|
|
|
|
|
<div className="absolute inset-0 rounded-full border border-blue-600/30 shadow-[0_0_12px_rgba(37,99,235,0.3)]" />
|
|
|
|
|
|
|
|
|
|
{/* Inner Arrows SVG */}
|
|
|
|
|
<svg
|
|
|
|
|
className="w-4 h-4 text-blue-700"
|
|
|
|
|
fill="none"
|
|
|
|
|
stroke="currentColor"
|
|
|
|
|
viewBox="0 0 24 24"
|
|
|
|
|
>
|
|
|
|
|
<path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2.5} d="M8 9l-3 3 3 3m8-6l3 3-3 3" />
|
|
|
|
|
</svg>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Layer 4: Floating 3D Telemetry Badges (Floating at translateZ(32px)) */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute top-3.5 left-3.5 sm:top-5 sm:left-5 bg-white/85 backdrop-blur-md px-3 py-1.5 rounded-xl text-[10px] sm:text-[11px] font-mono font-bold text-slate-800 border border-slate-900/[0.08] pointer-events-none z-20 flex items-center gap-1.5 shadow-sm preserve-3d"
|
|
|
|
|
style={{ transform: 'translateZ(30px)' }}
|
|
|
|
|
>
|
|
|
|
|
<Eye className="w-3.5 h-3.5 text-slate-600" />
|
|
|
|
|
<span>{beforeLabel}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
className="absolute top-3.5 right-3.5 sm:top-5 sm:right-5 bg-gradient-to-r from-blue-600 via-indigo-600 to-blue-700 text-white backdrop-blur-md px-3.5 py-1.5 rounded-xl text-[10px] sm:text-[11px] font-mono font-bold shadow-md border border-white/20 pointer-events-none z-20 flex items-center gap-1.5 preserve-3d"
|
|
|
|
|
style={{ transform: 'translateZ(30px)' }}
|
|
|
|
|
>
|
|
|
|
|
<Sparkles className="w-3.5 h-3.5 text-white" />
|
|
|
|
|
<span>{afterLabel}</span>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Lower Spatial Telemetry Chips (Enigma Archive Aesthetic) */}
|
|
|
|
|
<div
|
|
|
|
|
className="absolute bottom-3.5 left-3.5 sm:bottom-4 sm:left-4 hidden sm:flex items-center gap-2 pointer-events-none z-20 preserve-3d"
|
|
|
|
|
style={{ transform: 'translateZ(26px)' }}
|
|
|
|
|
>
|
|
|
|
|
<div className="bg-slate-950/60 backdrop-blur-md px-2.5 py-1 rounded-lg text-[9px] font-mono font-semibold text-white/90 border border-white/10 flex items-center gap-1.5">
|
|
|
|
|
<Activity className="w-3 h-3 text-emerald-400 animate-pulse" />
|
|
|
|
|
<span>DELTA DEPTH MAP</span>
|
|
|
|
|
</div>
|
|
|
|
|
<div className="bg-slate-950/60 backdrop-blur-md px-2.5 py-1 rounded-lg text-[9px] font-mono font-semibold text-white/90 border border-white/10 flex items-center gap-1.5">
|
|
|
|
|
<Scan className="w-3 h-3 text-cyan-400" />
|
|
|
|
|
<span>LOSSLESS 4K</span>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div
|
|
|
|
|
className="absolute bottom-3.5 right-3.5 sm:bottom-4 sm:right-4 bg-white/80 backdrop-blur-md px-2.5 py-1 rounded-lg text-[9px] font-mono font-bold text-slate-700 border border-slate-900/[0.06] pointer-events-none z-20 preserve-3d"
|
|
|
|
|
style={{ transform: 'translateZ(26px)' }}
|
|
|
|
|
>
|
|
|
|
|
SCAN: {Math.round(sliderPosition)}%
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{caption && (
|
|
|
|
|
<p className="mt-3 text-center text-xs font-mono text-slate-500 tracking-wide uppercase">
|
|
|
|
|
{caption}
|
|
|
|
|
</p>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|