fix(studio): replace geeky processing animation with porcelain studio theme and fix zoomed-in result comparison
This commit is contained in:
@@ -89,6 +89,7 @@ export function DynamicToolWorkspace({
|
||||
// Inference Execution State
|
||||
const [status, setStatus] = useState<'idle' | 'processing' | 'success' | 'error' | 'limit'>('idle');
|
||||
const [resultUrl, setResultUrl] = useState<string | null>(null);
|
||||
const [comparisonBeforeUrl, setComparisonBeforeUrl] = useState<string | null>(null);
|
||||
const [errorMessage, setErrorMessage] = useState<string>('');
|
||||
const [remainingTries, setRemainingTries] = useState<number>(tool.tryIt?.limits?.perDay || 5);
|
||||
|
||||
@@ -210,8 +211,11 @@ export function DynamicToolWorkspace({
|
||||
}
|
||||
|
||||
if (fileToSend) {
|
||||
const compUrl = URL.createObjectURL(fileToSend);
|
||||
setComparisonBeforeUrl(compUrl);
|
||||
formData.append(imageParamName, fileToSend, 'photo.jpg');
|
||||
} else if (primaryPreview) {
|
||||
setComparisonBeforeUrl(primaryPreview);
|
||||
const res = await fetch(primaryPreview);
|
||||
const blob = await res.blob();
|
||||
formData.append(imageParamName, blob, 'sample.jpg');
|
||||
@@ -309,6 +313,7 @@ export function DynamicToolWorkspace({
|
||||
setSecondaryFile(null);
|
||||
setSecondaryPreview(null);
|
||||
setResultUrl(null);
|
||||
setComparisonBeforeUrl(null);
|
||||
setStatus('idle');
|
||||
setErrorMessage('');
|
||||
if (fileInputRef.current) fileInputRef.current.value = '';
|
||||
@@ -407,12 +412,13 @@ export function DynamicToolWorkspace({
|
||||
</button>
|
||||
</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
|
||||
beforeUrl={primaryPreview || primaryExample.before}
|
||||
beforeUrl={comparisonBeforeUrl || primaryPreview || primaryExample.before}
|
||||
afterUrl={resultUrl}
|
||||
title={toolName}
|
||||
aspectRatio="aspect-auto h-full"
|
||||
aspectRatio="aspect-auto"
|
||||
objectFit="contain"
|
||||
beforeLabel="ORIGINAL"
|
||||
afterLabel="RESULT"
|
||||
/>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Sparkles, Cpu, Layers, Zap, ShieldCheck } from 'lucide-react';
|
||||
import { Sparkles } from 'lucide-react';
|
||||
|
||||
interface ProcessingOverlayProps {
|
||||
toolName?: string;
|
||||
@@ -10,45 +10,34 @@ interface ProcessingOverlayProps {
|
||||
}
|
||||
|
||||
export function ProcessingOverlay({
|
||||
toolName = 'Neural Vision Model',
|
||||
toolName = 'Photo',
|
||||
stageMessages,
|
||||
aspectRatio = 'aspect-[4/3] sm:aspect-[16/10]',
|
||||
}: ProcessingOverlayProps) {
|
||||
const defaultStages = [
|
||||
'Initializing volatile GPU tensor core...',
|
||||
'Analyzing photographic topology & lighting coordinates...',
|
||||
'Synthesizing generative neural model...',
|
||||
'Reconstructing sub-pixel micro-details & HD polish...',
|
||||
'Finalizing crystal-clear preview...',
|
||||
'Analyzing lighting & textures...',
|
||||
'Applying neural enhancements...',
|
||||
'Refining high-definition details...',
|
||||
'Finalizing studio quality export...',
|
||||
];
|
||||
|
||||
const stages = stageMessages && stageMessages.length > 0 ? stageMessages : defaultStages;
|
||||
|
||||
const [currentStageIdx, setCurrentStageIdx] = useState(0);
|
||||
const [progress, setProgress] = useState(12);
|
||||
const [elapsedSec, setElapsedSec] = useState(0);
|
||||
const [progress, setProgress] = useState(15);
|
||||
|
||||
// Smooth elapsed timer
|
||||
useEffect(() => {
|
||||
const timer = setInterval(() => {
|
||||
setElapsedSec((prev) => +(prev + 0.1).toFixed(1));
|
||||
}, 100);
|
||||
return () => clearInterval(timer);
|
||||
}, []);
|
||||
|
||||
// Cycle through inference stages & smooth progress curve
|
||||
// Cycle through natural photo editing stages & smooth progress curve
|
||||
useEffect(() => {
|
||||
const stageInterval = setInterval(() => {
|
||||
setCurrentStageIdx((prev) => (prev < stages.length - 1 ? prev + 1 : prev));
|
||||
}, 900);
|
||||
}, 1100);
|
||||
|
||||
const progressInterval = setInterval(() => {
|
||||
setProgress((prev) => {
|
||||
if (prev >= 94) return 94; // Wait for server resolution
|
||||
const delta = Math.max(1, Math.floor((95 - prev) * 0.15));
|
||||
if (prev >= 94) return 94; // Wait for backend resolution
|
||||
const delta = Math.max(1, Math.floor((95 - prev) * 0.16));
|
||||
return Math.min(94, prev + delta);
|
||||
});
|
||||
}, 150);
|
||||
}, 140);
|
||||
|
||||
return () => {
|
||||
clearInterval(stageInterval);
|
||||
@@ -57,81 +46,51 @@ export function ProcessingOverlay({
|
||||
}, [stages.length]);
|
||||
|
||||
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">
|
||||
{/* 1. Moving Laser Scanning Beam */}
|
||||
<div className="laser-scanner">
|
||||
<div className="laser-scanner-line" />
|
||||
</div>
|
||||
|
||||
{/* 2. Cybernetic Vision Grid Overlay */}
|
||||
<div
|
||||
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 */}
|
||||
<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="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" />
|
||||
<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 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 */}
|
||||
<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">
|
||||
<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">
|
||||
|
||||
{/* Elegant Porcelain Studio Card */}
|
||||
<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">
|
||||
|
||||
{/* 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 */}
|
||||
{/* Minimalist Dual-Ring Spinner with Warm Accent */}
|
||||
<div className="relative w-16 h-16 mx-auto flex items-center justify-center">
|
||||
{/* Subtle Outer Track */}
|
||||
<div className="absolute inset-0 rounded-full border-2 border-slate-100" />
|
||||
|
||||
{/* Rotating Accent Ring */}
|
||||
<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"
|
||||
style={{ animationDuration: '1.2s' }}
|
||||
className="absolute inset-0 rounded-full border-2 border-transparent border-t-accent border-r-accent/60 animate-spin"
|
||||
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">
|
||||
<Sparkles className="w-5 h-5 sm:w-6 sm:h-6 text-white animate-pulse" />
|
||||
|
||||
{/* Inner Soft Glowing Center */}
|
||||
<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>
|
||||
|
||||
{/* Dynamic Stage Title & Progress */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center justify-between text-xs font-body font-medium">
|
||||
<span className="text-white font-semibold flex items-center gap-1.5">
|
||||
<Zap className="w-3.5 h-3.5 text-amber-400 animate-pulse" />
|
||||
<span>Processing {toolName}</span>
|
||||
</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">
|
||||
{/* Studio Status Header */}
|
||||
<div className="space-y-1">
|
||||
<h3 className="text-base sm:text-lg font-display font-bold text-slate-900 tracking-tight">
|
||||
Enhancing Photo
|
||||
</h3>
|
||||
<p className="text-xs text-slate-500 font-sans min-h-[20px] transition-opacity duration-200">
|
||||
{stages[currentStageIdx]}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Reassurance Footer */}
|
||||
<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">
|
||||
<ShieldCheck className="w-3.5 h-3.5 text-emerald-400" />
|
||||
<span>Neural Engine Processing · Direct Stream</span>
|
||||
{/* Minimalist Studio Progress Bar */}
|
||||
<div className="space-y-1.5 pt-1">
|
||||
<div className="w-full h-1.5 rounded-full bg-slate-100 overflow-hidden">
|
||||
<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>
|
||||
|
||||
@@ -10,6 +10,7 @@ interface CardBeforeAfterSliderProps {
|
||||
beforeLabel?: string;
|
||||
afterLabel?: string;
|
||||
aspectRatio?: string;
|
||||
objectFit?: 'cover' | 'contain';
|
||||
}
|
||||
|
||||
export function CardBeforeAfterSlider({
|
||||
@@ -20,6 +21,7 @@ export function CardBeforeAfterSlider({
|
||||
beforeLabel = 'Original',
|
||||
afterLabel = 'Enhanced',
|
||||
aspectRatio = 'aspect-[16/10]',
|
||||
objectFit = 'contain',
|
||||
}: CardBeforeAfterSliderProps) {
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const isHoveredRef = useRef(false);
|
||||
@@ -29,15 +31,24 @@ export function CardBeforeAfterSlider({
|
||||
const animIdRef = useRef<number>(0);
|
||||
const rafIdRef = useRef<number | null>(null);
|
||||
const [isHoveredState, setIsHoveredState] = useState(false);
|
||||
const [naturalDimensions, setNaturalDimensions] = useState<{ width: number; height: number } | null>(null);
|
||||
|
||||
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) {
|
||||
containerRef.current.style.setProperty('--split', `${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
|
||||
useEffect(() => {
|
||||
let startTime: number | null = null;
|
||||
@@ -110,14 +121,9 @@ export function CardBeforeAfterSlider({
|
||||
cachedRectRef.current = null;
|
||||
try {
|
||||
(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId);
|
||||
} catch {
|
||||
// Ignore if pointer capture already released
|
||||
}
|
||||
} catch {}
|
||||
};
|
||||
|
||||
// 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) => {
|
||||
if (e.pointerType !== 'mouse' || e.button !== 0) return;
|
||||
handlePointerDown(e);
|
||||
@@ -140,14 +146,27 @@ export function CardBeforeAfterSlider({
|
||||
}
|
||||
};
|
||||
|
||||
const imgFitClass = objectFit === 'contain' ? 'object-contain object-center' : 'object-cover';
|
||||
const containerAspectClass = naturalDimensions ? '' : aspectRatio;
|
||||
|
||||
return (
|
||||
<div
|
||||
ref={containerRef}
|
||||
onPointerDown={handleContainerPointerDown}
|
||||
onMouseEnter={handleMouseEnter}
|
||||
onMouseLeave={handleMouseLeave}
|
||||
className={`relative w-full ${aspectRatio} select-none overflow-hidden rounded-card bg-paper-2 cursor-ew-resize group/slider touch-pan-y`}
|
||||
style={{ touchAction: 'pan-y', ['--split' as any]: '50%' }}
|
||||
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%',
|
||||
...(naturalDimensions
|
||||
? {
|
||||
aspectRatio: `${naturalDimensions.width} / ${naturalDimensions.height}`,
|
||||
width: `min(100%, calc(640px * (${naturalDimensions.width} / ${naturalDimensions.height})))`,
|
||||
maxHeight: '640px',
|
||||
}
|
||||
: {}),
|
||||
}}
|
||||
role="region"
|
||||
aria-label={`${title} comparison slider`}
|
||||
>
|
||||
@@ -157,26 +176,28 @@ export function CardBeforeAfterSlider({
|
||||
alt={`${title} - enhanced result`}
|
||||
loading="eager"
|
||||
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) */}
|
||||
<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%)' }}
|
||||
>
|
||||
<img
|
||||
src={beforeUrl}
|
||||
alt={`${title} - original`}
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
className="absolute inset-0 h-full w-full object-cover"
|
||||
loading="eager"
|
||||
decoding="sync"
|
||||
onLoad={handleImageLoad}
|
||||
className={`absolute inset-0 h-full w-full pointer-events-none select-none ${imgFitClass}`}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Layer 3: Vertical Split Divider Line */}
|
||||
<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)' }}
|
||||
>
|
||||
{/* Center Round Handle */}
|
||||
@@ -190,19 +211,19 @@ export function CardBeforeAfterSlider({
|
||||
aria-valuenow={50}
|
||||
tabIndex={0}
|
||||
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">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Floating Labels inside colored 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">
|
||||
{/* Floating Labels inside refined frosted pills */}
|
||||
<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}
|
||||
</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}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user