feat(ui): complete vertical layout overhaul, dynamic JSON banners, and animate-ui text motion graphics
This commit is contained in:
@@ -22,42 +22,36 @@ export function Cinematic3DComparison({
|
||||
afterLabel = 'AI RECONSTRUCTED',
|
||||
caption,
|
||||
aspectRatio = 'aspect-[4/3] sm:aspect-[16/10]',
|
||||
autoSlide = true,
|
||||
maxTilt = 7,
|
||||
autoSlide = false,
|
||||
maxTilt = 6,
|
||||
className = '',
|
||||
}: Cinematic3DComparisonProps) {
|
||||
const [sliderPosition, setSliderPosition] = useState(50);
|
||||
const [isDragging, setIsDragging] = useState(false);
|
||||
const [isUserInteracting, setIsUserInteracting] = useState(false);
|
||||
const [tilt, setTilt] = useState({ rx: 0, ry: 0, glareX: 50, glareY: 50, active: false });
|
||||
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const stageRef = useRef<HTMLDivElement>(null);
|
||||
const animFrameRef = useRef<number | null>(null);
|
||||
const resumeTimerRef = useRef<NodeJS.Timeout | null>(null);
|
||||
const startTimeRef = useRef<number>(Date.now());
|
||||
const glareRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// Auto-slide smooth sine oscillation loop
|
||||
// Auto-slide smooth sine oscillation loop (only when explicitly requested)
|
||||
useEffect(() => {
|
||||
if (!autoSlide || isDragging || isUserInteracting) {
|
||||
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
||||
return;
|
||||
}
|
||||
if (!autoSlide || isDragging) return;
|
||||
|
||||
let animId: number;
|
||||
const start = Date.now();
|
||||
const animate = () => {
|
||||
const elapsed = Date.now() - startTimeRef.current;
|
||||
// Gentle cinematic oscillation between 28% and 72%
|
||||
const newPos = 50 + 22 * Math.sin(elapsed * 0.0014);
|
||||
const elapsed = Date.now() - start;
|
||||
// Gentle cinematic oscillation between 30% and 70%
|
||||
const newPos = 50 + 20 * Math.sin(elapsed * 0.0014);
|
||||
setSliderPosition(newPos);
|
||||
animFrameRef.current = requestAnimationFrame(animate);
|
||||
animId = requestAnimationFrame(animate);
|
||||
};
|
||||
|
||||
animFrameRef.current = requestAnimationFrame(animate);
|
||||
animId = requestAnimationFrame(animate);
|
||||
|
||||
return () => {
|
||||
if (animFrameRef.current) cancelAnimationFrame(animFrameRef.current);
|
||||
if (animId) cancelAnimationFrame(animId);
|
||||
};
|
||||
}, [autoSlide, isDragging, isUserInteracting]);
|
||||
}, [autoSlide, isDragging]);
|
||||
|
||||
// Handle position calculation
|
||||
const handleMove = useCallback((clientX: number) => {
|
||||
@@ -97,7 +91,7 @@ export function Cinematic3DComparison({
|
||||
};
|
||||
}, [isDragging, handleMouseMove, handleMouseUp, handleTouchMove]);
|
||||
|
||||
// 3D Spatial Tilt Tracking
|
||||
// 3D Spatial Tilt - Pure Direct DOM Manipulation (Zero React Re-renders on mousemove!)
|
||||
const handleStageMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {
|
||||
if (!containerRef.current) return;
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
@@ -107,27 +101,20 @@ export function Cinematic3DComparison({
|
||||
const rx = -(y - 0.5) * maxTilt * 2;
|
||||
const ry = (x - 0.5) * maxTilt * 2;
|
||||
|
||||
setTilt({
|
||||
rx,
|
||||
ry,
|
||||
glareX: x * 100,
|
||||
glareY: y * 100,
|
||||
active: true,
|
||||
});
|
||||
};
|
||||
|
||||
const handleMouseEnter = () => {
|
||||
setIsUserInteracting(true);
|
||||
if (resumeTimerRef.current) clearTimeout(resumeTimerRef.current);
|
||||
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%)`;
|
||||
}
|
||||
};
|
||||
|
||||
const handleMouseLeave = () => {
|
||||
setTilt((prev) => ({ ...prev, rx: 0, ry: 0, active: false }));
|
||||
if (resumeTimerRef.current) clearTimeout(resumeTimerRef.current);
|
||||
resumeTimerRef.current = setTimeout(() => {
|
||||
setIsUserInteracting(false);
|
||||
startTimeRef.current = Date.now();
|
||||
}, 2800);
|
||||
if (containerRef.current) {
|
||||
containerRef.current.style.transform = 'rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)';
|
||||
}
|
||||
if (glareRef.current) {
|
||||
glareRef.current.style.opacity = '0';
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -136,21 +123,12 @@ export function Cinematic3DComparison({
|
||||
<div
|
||||
ref={containerRef}
|
||||
onMouseMove={handleStageMouseMove}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
onMouseDown={() => {
|
||||
setIsDragging(true);
|
||||
setIsUserInteracting(true);
|
||||
}}
|
||||
onTouchStart={() => {
|
||||
setIsDragging(true);
|
||||
setIsUserInteracting(true);
|
||||
}}
|
||||
className={`relative w-full ${aspectRatio} rounded-2xl sm:rounded-3xl overflow-hidden cursor-ew-resize preserve-3d transition-transform duration-200 ease-out shadow-cinematic-3d hover:shadow-cinematic-hover border border-slate-900/[0.08] bg-slate-950`}
|
||||
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`}
|
||||
style={{
|
||||
transform: tilt.active
|
||||
? `rotateX(${tilt.rx.toFixed(2)}deg) rotateY(${tilt.ry.toFixed(2)}deg) scale3d(1.015, 1.015, 1.015)`
|
||||
: 'rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)',
|
||||
transform: 'rotateX(0deg) rotateY(0deg) scale3d(1, 1, 1)',
|
||||
touchAction: 'pan-y',
|
||||
}}
|
||||
>
|
||||
@@ -165,10 +143,10 @@ export function Cinematic3DComparison({
|
||||
|
||||
{/* Dynamic 3D Cursor Specular Light Glint */}
|
||||
<div
|
||||
className="absolute inset-0 pointer-events-none transition-opacity duration-300 z-10"
|
||||
ref={glareRef}
|
||||
className="absolute inset-0 pointer-events-none transition-opacity duration-300 z-10 opacity-0"
|
||||
style={{
|
||||
opacity: tilt.active ? 0.65 : 0,
|
||||
background: `radial-gradient(circle 380px at ${tilt.glareX}% ${tilt.glareY}%, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.08) 50%, transparent 80%)`,
|
||||
background: 'radial-gradient(circle 380px at 50% 50%, rgba(255, 255, 255, 0.35) 0%, rgba(255, 255, 255, 0.08) 50%, transparent 80%)',
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user