fix(studio): replace geeky processing animation with porcelain studio theme and fix zoomed-in result comparison

This commit is contained in:
2026-11-11 14:59:21 +05:30
parent ed7115e785
commit 7799aed34b
3 changed files with 97 additions and 111 deletions
@@ -89,6 +89,7 @@ export function DynamicToolWorkspace({
// Inference Execution State // Inference Execution State
const [status, setStatus] = useState<'idle' | 'processing' | 'success' | 'error' | 'limit'>('idle'); const [status, setStatus] = useState<'idle' | 'processing' | 'success' | 'error' | 'limit'>('idle');
const [resultUrl, setResultUrl] = useState<string | null>(null); const [resultUrl, setResultUrl] = useState<string | null>(null);
const [comparisonBeforeUrl, setComparisonBeforeUrl] = useState<string | null>(null);
const [errorMessage, setErrorMessage] = useState<string>(''); const [errorMessage, setErrorMessage] = useState<string>('');
const [remainingTries, setRemainingTries] = useState<number>(tool.tryIt?.limits?.perDay || 5); const [remainingTries, setRemainingTries] = useState<number>(tool.tryIt?.limits?.perDay || 5);
@@ -210,8 +211,11 @@ export function DynamicToolWorkspace({
} }
if (fileToSend) { if (fileToSend) {
const compUrl = URL.createObjectURL(fileToSend);
setComparisonBeforeUrl(compUrl);
formData.append(imageParamName, fileToSend, 'photo.jpg'); formData.append(imageParamName, fileToSend, 'photo.jpg');
} else if (primaryPreview) { } else if (primaryPreview) {
setComparisonBeforeUrl(primaryPreview);
const res = await fetch(primaryPreview); const res = await fetch(primaryPreview);
const blob = await res.blob(); const blob = await res.blob();
formData.append(imageParamName, blob, 'sample.jpg'); formData.append(imageParamName, blob, 'sample.jpg');
@@ -309,6 +313,7 @@ export function DynamicToolWorkspace({
setSecondaryFile(null); setSecondaryFile(null);
setSecondaryPreview(null); setSecondaryPreview(null);
setResultUrl(null); setResultUrl(null);
setComparisonBeforeUrl(null);
setStatus('idle'); setStatus('idle');
setErrorMessage(''); setErrorMessage('');
if (fileInputRef.current) fileInputRef.current.value = ''; if (fileInputRef.current) fileInputRef.current.value = '';
@@ -407,12 +412,13 @@ export function DynamicToolWorkspace({
</button> </button>
</div> </div>
<div className="aspect-[4/3] sm:aspect-[16/10] max-h-[580px] w-full rounded-2xl overflow-hidden bg-paper-2 border border-rule"> <div className="w-full flex items-center justify-center p-3 sm:p-5 rounded-2xl bg-paper-2/60 border border-rule overflow-hidden">
<CardBeforeAfterSlider <CardBeforeAfterSlider
beforeUrl={primaryPreview || primaryExample.before} beforeUrl={comparisonBeforeUrl || primaryPreview || primaryExample.before}
afterUrl={resultUrl} afterUrl={resultUrl}
title={toolName} title={toolName}
aspectRatio="aspect-auto h-full" aspectRatio="aspect-auto"
objectFit="contain"
beforeLabel="ORIGINAL" beforeLabel="ORIGINAL"
afterLabel="RESULT" afterLabel="RESULT"
/> />
+45 -86
View File
@@ -1,7 +1,7 @@
'use client'; 'use client';
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Sparkles, Cpu, Layers, Zap, ShieldCheck } from 'lucide-react'; import { Sparkles } from 'lucide-react';
interface ProcessingOverlayProps { interface ProcessingOverlayProps {
toolName?: string; toolName?: string;
@@ -10,45 +10,34 @@ interface ProcessingOverlayProps {
} }
export function ProcessingOverlay({ export function ProcessingOverlay({
toolName = 'Neural Vision Model', toolName = 'Photo',
stageMessages, stageMessages,
aspectRatio = 'aspect-[4/3] sm:aspect-[16/10]',
}: ProcessingOverlayProps) { }: ProcessingOverlayProps) {
const defaultStages = [ const defaultStages = [
'Initializing volatile GPU tensor core...', 'Analyzing lighting & textures...',
'Analyzing photographic topology & lighting coordinates...', 'Applying neural enhancements...',
'Synthesizing generative neural model...', 'Refining high-definition details...',
'Reconstructing sub-pixel micro-details & HD polish...', 'Finalizing studio quality export...',
'Finalizing crystal-clear preview...',
]; ];
const stages = stageMessages && stageMessages.length > 0 ? stageMessages : defaultStages; const stages = stageMessages && stageMessages.length > 0 ? stageMessages : defaultStages;
const [currentStageIdx, setCurrentStageIdx] = useState(0); const [currentStageIdx, setCurrentStageIdx] = useState(0);
const [progress, setProgress] = useState(12); const [progress, setProgress] = useState(15);
const [elapsedSec, setElapsedSec] = useState(0);
// Smooth elapsed timer // Cycle through natural photo editing stages & smooth progress curve
useEffect(() => {
const timer = setInterval(() => {
setElapsedSec((prev) => +(prev + 0.1).toFixed(1));
}, 100);
return () => clearInterval(timer);
}, []);
// Cycle through inference stages & smooth progress curve
useEffect(() => { useEffect(() => {
const stageInterval = setInterval(() => { const stageInterval = setInterval(() => {
setCurrentStageIdx((prev) => (prev < stages.length - 1 ? prev + 1 : prev)); setCurrentStageIdx((prev) => (prev < stages.length - 1 ? prev + 1 : prev));
}, 900); }, 1100);
const progressInterval = setInterval(() => { const progressInterval = setInterval(() => {
setProgress((prev) => { setProgress((prev) => {
if (prev >= 94) return 94; // Wait for server resolution if (prev >= 94) return 94; // Wait for backend resolution
const delta = Math.max(1, Math.floor((95 - prev) * 0.15)); const delta = Math.max(1, Math.floor((95 - prev) * 0.16));
return Math.min(94, prev + delta); return Math.min(94, prev + delta);
}); });
}, 150); }, 140);
return () => { return () => {
clearInterval(stageInterval); clearInterval(stageInterval);
@@ -57,81 +46,51 @@ export function ProcessingOverlay({
}, [stages.length]); }, [stages.length]);
return ( return (
<div className="absolute inset-0 z-30 flex items-center justify-center overflow-hidden rounded-2xl bg-black/60 backdrop-blur-md transition-all duration-300"> <div className="absolute inset-0 z-30 flex items-center justify-center p-4 bg-white/75 backdrop-blur-md transition-all duration-300 select-none">
{/* 1. Moving Laser Scanning Beam */}
<div className="laser-scanner">
<div className="laser-scanner-line" />
</div>
{/* 2. Cybernetic Vision Grid Overlay */} {/* Elegant Porcelain Studio Card */}
<div <div className="relative z-10 max-w-xs sm:max-w-sm w-full p-6 sm:p-8 rounded-3xl bg-white border border-slate-200/90 shadow-2xl text-center space-y-5">
className="absolute inset-0 pointer-events-none opacity-20 bg-[linear-gradient(to_right,#38bdf8_1px,transparent_1px),linear-gradient(to_bottom,#38bdf8_1px,transparent_1px)] bg-[size:32px_32px]"
aria-hidden="true"
/>
{/* 3. Corner Targeting Reticles */} {/* Minimalist Dual-Ring Spinner with Warm Accent */}
<div className="absolute top-4 left-4 w-7 h-7 border-t-2 border-l-2 border-cyan-400/80 rounded-tl-sm pointer-events-none animate-pulse" /> <div className="relative w-16 h-16 mx-auto flex items-center justify-center">
<div className="absolute top-4 right-4 w-7 h-7 border-t-2 border-r-2 border-cyan-400/80 rounded-tr-sm pointer-events-none animate-pulse" /> {/* Subtle Outer Track */}
<div className="absolute bottom-4 left-4 w-7 h-7 border-b-2 border-l-2 border-cyan-400/80 rounded-bl-sm pointer-events-none animate-pulse" /> <div className="absolute inset-0 rounded-full border-2 border-slate-100" />
<div className="absolute bottom-4 right-4 w-7 h-7 border-b-2 border-r-2 border-cyan-400/80 rounded-br-sm pointer-events-none animate-pulse" />
{/* 4. Central Holographic HUD Card */} {/* Rotating Accent Ring */}
<div className="relative z-30 max-w-sm sm:max-w-md w-11/12 p-6 sm:p-7 rounded-3xl bg-slate-950/85 border border-cyan-500/30 shadow-[0_0_50px_rgba(56,189,248,0.25)] text-center text-white space-y-5 backdrop-blur-xl">
{/* Top Badges */}
<div className="flex items-center justify-between text-[11px] font-mono font-semibold text-cyan-300 border-b border-cyan-500/20 pb-3">
<span className="flex items-center gap-1.5 uppercase tracking-wider">
<Cpu className="w-3.5 h-3.5 text-cyan-400 animate-spin" style={{ animationDuration: '6s' }} />
<span>GPU Tensor Model</span>
</span>
<span className="px-2 py-0.5 rounded-full bg-cyan-950/80 border border-cyan-400/30 text-cyan-300 font-mono">
{elapsedSec.toFixed(1)}s
</span>
</div>
{/* Radar Spinner & Icon */}
<div className="relative w-16 h-16 sm:w-20 sm:h-20 mx-auto flex items-center justify-center">
{/* Outer glowing pulsed ring */}
<div className="absolute inset-0 rounded-full border-2 border-cyan-400/20 animate-ping opacity-30" />
{/* Rotating gradient track */}
<div <div
className="absolute inset-0 rounded-full border-2 border-t-cyan-400 border-r-indigo-500 border-b-purple-500 border-l-transparent animate-spin" className="absolute inset-0 rounded-full border-2 border-transparent border-t-accent border-r-accent/60 animate-spin"
style={{ animationDuration: '1.2s' }} style={{ animationDuration: '1s' }}
/> />
{/* Inner pulsating core */}
<div className="w-10 h-10 sm:w-12 sm:h-12 rounded-full bg-gradient-to-tr from-cyan-500 to-indigo-600 flex items-center justify-center shadow-lg shadow-cyan-500/50"> {/* Inner Soft Glowing Center */}
<Sparkles className="w-5 h-5 sm:w-6 sm:h-6 text-white animate-pulse" /> <div className="w-10 h-10 rounded-full bg-accent/10 flex items-center justify-center">
<Sparkles className="w-5 h-5 text-accent animate-pulse" />
</div> </div>
</div> </div>
{/* Dynamic Stage Title & Progress */} {/* Studio Status Header */}
<div className="space-y-2"> <div className="space-y-1">
<div className="flex items-center justify-between text-xs font-body font-medium"> <h3 className="text-base sm:text-lg font-display font-bold text-slate-900 tracking-tight">
<span className="text-white font-semibold flex items-center gap-1.5"> Enhancing Photo
<Zap className="w-3.5 h-3.5 text-amber-400 animate-pulse" /> </h3>
<span>Processing {toolName}</span> <p className="text-xs text-slate-500 font-sans min-h-[20px] transition-opacity duration-200">
</span>
<span className="font-mono text-cyan-400 font-bold">{progress}%</span>
</div>
{/* Glowing Animated Progress Bar */}
<div className="w-full h-2 rounded-full bg-slate-900 border border-cyan-500/30 overflow-hidden p-0.5">
<div
className="h-full rounded-full bg-gradient-to-r from-cyan-400 via-indigo-400 to-purple-400 transition-all duration-200 shadow-[0_0_12px_#38bdf8]"
style={{ width: `${progress}%` }}
/>
</div>
{/* Current Step Description */}
<p className="text-xs text-slate-300 font-body min-h-[36px] flex items-center justify-center leading-relaxed animate-fade-in">
{stages[currentStageIdx]} {stages[currentStageIdx]}
</p> </p>
</div> </div>
{/* Reassurance Footer */} {/* Minimalist Studio Progress Bar */}
<div className="pt-2 border-t border-cyan-500/20 flex items-center justify-center gap-1.5 text-[10px] text-slate-400 font-body"> <div className="space-y-1.5 pt-1">
<ShieldCheck className="w-3.5 h-3.5 text-emerald-400" /> <div className="w-full h-1.5 rounded-full bg-slate-100 overflow-hidden">
<span>Neural Engine Processing · Direct Stream</span> <div
className="h-full rounded-full bg-slate-900 transition-all duration-200"
style={{ width: `${progress}%` }}
/>
</div>
<div className="flex items-center justify-between text-[11px] font-sans text-slate-400">
<span>Studio Processing</span>
<span className="font-mono font-medium text-slate-600">{progress}%</span>
</div>
</div> </div>
</div> </div>
+41 -20
View File
@@ -10,6 +10,7 @@ interface CardBeforeAfterSliderProps {
beforeLabel?: string; beforeLabel?: string;
afterLabel?: string; afterLabel?: string;
aspectRatio?: string; aspectRatio?: string;
objectFit?: 'cover' | 'contain';
} }
export function CardBeforeAfterSlider({ export function CardBeforeAfterSlider({
@@ -20,6 +21,7 @@ export function CardBeforeAfterSlider({
beforeLabel = 'Original', beforeLabel = 'Original',
afterLabel = 'Enhanced', afterLabel = 'Enhanced',
aspectRatio = 'aspect-[16/10]', aspectRatio = 'aspect-[16/10]',
objectFit = 'contain',
}: CardBeforeAfterSliderProps) { }: CardBeforeAfterSliderProps) {
const containerRef = useRef<HTMLDivElement>(null); const containerRef = useRef<HTMLDivElement>(null);
const isHoveredRef = useRef(false); const isHoveredRef = useRef(false);
@@ -29,15 +31,24 @@ export function CardBeforeAfterSlider({
const animIdRef = useRef<number>(0); const animIdRef = useRef<number>(0);
const rafIdRef = useRef<number | null>(null); const rafIdRef = useRef<number | null>(null);
const [isHoveredState, setIsHoveredState] = useState(false); const [isHoveredState, setIsHoveredState] = useState(false);
const [naturalDimensions, setNaturalDimensions] = useState<{ width: number; height: number } | null>(null);
const setSplit = useCallback((percent: number) => { const setSplit = useCallback((percent: number) => {
const clamped = Math.max(3, Math.min(97, percent)); const clamped = Math.max(2, Math.min(98, percent));
if (containerRef.current) { if (containerRef.current) {
containerRef.current.style.setProperty('--split', `${clamped}%`); containerRef.current.style.setProperty('--split', `${clamped}%`);
containerRef.current.setAttribute('aria-valuenow', `${Math.round(clamped)}`); containerRef.current.setAttribute('aria-valuenow', `${Math.round(clamped)}`);
} }
}, []); }, []);
// Handle image load to detect natural aspect ratio for exact, unzoomed display
const handleImageLoad = (e: React.SyntheticEvent<HTMLImageElement>) => {
const img = e.currentTarget;
if (img.naturalWidth && img.naturalHeight) {
setNaturalDimensions({ width: img.naturalWidth, height: img.naturalHeight });
}
};
// Smooth gentle oscillation: runs on desktop when hovered before user manually drags // Smooth gentle oscillation: runs on desktop when hovered before user manually drags
useEffect(() => { useEffect(() => {
let startTime: number | null = null; let startTime: number | null = null;
@@ -110,14 +121,9 @@ export function CardBeforeAfterSlider({
cachedRectRef.current = null; cachedRectRef.current = null;
try { try {
(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId); (e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId);
} catch { } catch {}
// Ignore if pointer capture already released
}
}; };
// On desktop with mouse, clicking anywhere on the card moves the slider.
// On phones / touch screens, touching the card does NOT move the slider,
// allowing completely unobstructed vertical page scrolling!
const handleContainerPointerDown = (e: React.PointerEvent) => { const handleContainerPointerDown = (e: React.PointerEvent) => {
if (e.pointerType !== 'mouse' || e.button !== 0) return; if (e.pointerType !== 'mouse' || e.button !== 0) return;
handlePointerDown(e); handlePointerDown(e);
@@ -140,14 +146,27 @@ export function CardBeforeAfterSlider({
} }
}; };
const imgFitClass = objectFit === 'contain' ? 'object-contain object-center' : 'object-cover';
const containerAspectClass = naturalDimensions ? '' : aspectRatio;
return ( return (
<div <div
ref={containerRef} ref={containerRef}
onPointerDown={handleContainerPointerDown} onPointerDown={handleContainerPointerDown}
onMouseEnter={handleMouseEnter} onMouseEnter={handleMouseEnter}
onMouseLeave={handleMouseLeave} onMouseLeave={handleMouseLeave}
className={`relative w-full ${aspectRatio} select-none overflow-hidden rounded-card bg-paper-2 cursor-ew-resize group/slider touch-pan-y`} className={`relative ${naturalDimensions ? 'mx-auto' : 'w-full ' + containerAspectClass} select-none overflow-hidden rounded-2xl bg-paper-2 cursor-ew-resize group/slider touch-pan-y max-w-full`}
style={{ touchAction: 'pan-y', ['--split' as any]: '50%' }} style={{
touchAction: 'pan-y',
['--split' as any]: '50%',
...(naturalDimensions
? {
aspectRatio: `${naturalDimensions.width} / ${naturalDimensions.height}`,
width: `min(100%, calc(640px * (${naturalDimensions.width} / ${naturalDimensions.height})))`,
maxHeight: '640px',
}
: {}),
}}
role="region" role="region"
aria-label={`${title} comparison slider`} aria-label={`${title} comparison slider`}
> >
@@ -157,26 +176,28 @@ export function CardBeforeAfterSlider({
alt={`${title} - enhanced result`} alt={`${title} - enhanced result`}
loading="eager" loading="eager"
decoding="sync" decoding="sync"
className="absolute inset-0 h-full w-full object-cover" onLoad={handleImageLoad}
className={`absolute inset-0 h-full w-full pointer-events-none select-none ${imgFitClass}`}
/> />
{/* Layer 2: Before / Original Image (Clipped) */} {/* Layer 2: Before / Original Image (Clipped) */}
<div <div
className="absolute inset-0 overflow-hidden" className="absolute inset-0 overflow-hidden pointer-events-none select-none"
style={{ clipPath: 'polygon(0 0, var(--split) 0, var(--split) 100%, 0 100%)' }} style={{ clipPath: 'polygon(0 0, var(--split) 0, var(--split) 100%, 0 100%)' }}
> >
<img <img
src={beforeUrl} src={beforeUrl}
alt={`${title} - original`} alt={`${title} - original`}
loading="lazy" loading="eager"
decoding="async" decoding="sync"
className="absolute inset-0 h-full w-full object-cover" onLoad={handleImageLoad}
className={`absolute inset-0 h-full w-full pointer-events-none select-none ${imgFitClass}`}
/> />
</div> </div>
{/* Layer 3: Vertical Split Divider Line */} {/* Layer 3: Vertical Split Divider Line */}
<div <div
className="absolute top-0 bottom-0 w-px bg-paper-hi z-20 pointer-events-none -translate-x-1/2" className="absolute top-0 bottom-0 w-[2px] bg-white shadow-[0_0_8px_rgba(0,0,0,0.5)] z-20 pointer-events-none -translate-x-1/2"
style={{ left: 'var(--split)' }} style={{ left: 'var(--split)' }}
> >
{/* Center Round Handle */} {/* Center Round Handle */}
@@ -190,19 +211,19 @@ export function CardBeforeAfterSlider({
aria-valuenow={50} aria-valuenow={50}
tabIndex={0} tabIndex={0}
style={{ touchAction: 'none' }} style={{ touchAction: 'none' }}
className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-8 h-8 rounded-full bg-paper-hi text-ink border border-rule flex items-center justify-center pointer-events-auto cursor-ew-resize touch-none shadow-sm before:absolute before:-inset-3 before:content-['']" className="absolute top-1/2 -translate-y-1/2 -translate-x-1/2 w-8 h-8 rounded-full bg-white text-slate-900 border border-slate-300 flex items-center justify-center pointer-events-auto cursor-ew-resize touch-none shadow-md before:absolute before:-inset-3 before:content-['']"
> >
<svg className="w-3.5 h-3.5 text-accent pointer-events-none" fill="none" stroke="currentColor" viewBox="0 0 24 24" aria-hidden="true"> <svg className="w-3.5 h-3.5 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" /> <path strokeLinecap="round" strokeLinejoin="round" strokeWidth={2.5} d="M8 9l-3 3 3 3m8-6l3 3-3 3" />
</svg> </svg>
</div> </div>
</div> </div>
{/* Floating Labels inside colored pills */} {/* Floating Labels inside refined frosted pills */}
<div className="pointer-events-none absolute bottom-2.5 left-2.5 z-20 rounded-full bg-ink/80 backdrop-blur-md px-2.5 py-0.5 text-[10px] font-semibold text-paper-hi border border-white/20 shadow-xs"> <div className="pointer-events-none absolute bottom-3 left-3 z-20 rounded-full bg-slate-950/75 backdrop-blur-md px-3 py-1 text-[10px] font-bold text-white border border-white/20 shadow-sm uppercase tracking-wider">
{beforeLabel} {beforeLabel}
</div> </div>
<div className="pointer-events-none absolute bottom-2.5 right-2.5 z-20 rounded-full bg-accent backdrop-blur-md px-2.5 py-0.5 text-[10px] font-bold text-paper-hi border border-white/25 shadow-xs"> <div className="pointer-events-none absolute bottom-3 right-3 z-20 rounded-full bg-accent/90 backdrop-blur-md px-3 py-1 text-[10px] font-bold text-white border border-white/25 shadow-sm uppercase tracking-wider">
{afterLabel} {afterLabel}
</div> </div>
</div> </div>