feat(tool-workspace): add default image cropper, dynamic remaining quota badge, clean studio header, and larger title
This commit is contained in:
@@ -147,6 +147,7 @@ export async function POST(req: NextRequest, { params }: { params: { toolId: str
|
||||
|
||||
// Record rate-limit usage
|
||||
recordUsage(visitorId, ip);
|
||||
const remainingAfterUsage = Math.max(0, rateCheck.remainingToday - 1);
|
||||
|
||||
// Call backend or mock engine
|
||||
const { buffer: resultBuffer, contentType } = await executeBackendTryIt(
|
||||
@@ -164,7 +165,7 @@ export async function POST(req: NextRequest, { params }: { params: { toolId: str
|
||||
'Content-Type': contentType,
|
||||
'Content-Length': resultBuffer.length.toString(),
|
||||
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
||||
'X-Remaining-Tries': rateCheck.remainingToday.toString(),
|
||||
'X-Remaining-Tries': remainingAfterUsage.toString(),
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
import { checkRateLimits } from '@/lib/api/rateLimiter';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
export const revalidate = 0;
|
||||
|
||||
export async function GET(req: NextRequest) {
|
||||
const ip = req.headers.get('x-forwarded-for')?.split(',')[0].trim() || '127.0.0.1';
|
||||
let visitorId = req.cookies.get('photoai_vid')?.value;
|
||||
let isNewVisitor = false;
|
||||
if (!visitorId) {
|
||||
visitorId = 'v_' + Math.random().toString(36).substring(2, 15);
|
||||
isNewVisitor = true;
|
||||
}
|
||||
|
||||
const rateCheck = checkRateLimits(visitorId, ip);
|
||||
const response = NextResponse.json({
|
||||
allowed: rateCheck.allowed,
|
||||
remainingToday: rateCheck.remainingToday,
|
||||
limit: 5,
|
||||
timestamp: Date.now(),
|
||||
}, {
|
||||
headers: {
|
||||
'Cache-Control': 'no-store, no-cache, must-revalidate',
|
||||
},
|
||||
});
|
||||
|
||||
if (isNewVisitor) {
|
||||
response.cookies.set('photoai_vid', visitorId, {
|
||||
path: '/',
|
||||
maxAge: 60 * 60 * 24 * 30,
|
||||
httpOnly: true,
|
||||
sameSite: 'lax',
|
||||
});
|
||||
}
|
||||
|
||||
return response;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useRef, useCallback } from 'react';
|
||||
import React, { useState, useRef, useCallback, useEffect } from 'react';
|
||||
import Link from 'next/link';
|
||||
import {
|
||||
UploadCloud,
|
||||
@@ -10,20 +10,11 @@ import {
|
||||
RotateCcw,
|
||||
Loader2,
|
||||
AlertCircle,
|
||||
CheckCircle2,
|
||||
Layers,
|
||||
SlidersHorizontal,
|
||||
ArrowRight,
|
||||
Maximize2,
|
||||
Wand2,
|
||||
RefreshCw,
|
||||
Image as ImageIcon,
|
||||
Check,
|
||||
ChevronRight,
|
||||
Smartphone,
|
||||
FolderOpen,
|
||||
Zap,
|
||||
ShieldCheck
|
||||
Crop
|
||||
} from 'lucide-react';
|
||||
import {
|
||||
ToolItem,
|
||||
@@ -38,7 +29,7 @@ import { MaskCanvasEditor } from './MaskCanvasEditor';
|
||||
import { ThumbnailsSection } from './ThumbnailsSection';
|
||||
import { AlternatingFeaturesSection } from './AlternatingFeaturesSection';
|
||||
import { ProcessingOverlay } from './ProcessingOverlay';
|
||||
import { KineticText } from '@/components/magicui/kinetic-text';
|
||||
import { ImageCropper } from './ImageCropper';
|
||||
import { AnimatedShinyText } from '@/components/magicui/animated-shiny-text';
|
||||
import { BorderBeam } from '@/components/magicui/border-beam';
|
||||
|
||||
@@ -59,7 +50,7 @@ export function DynamicToolWorkspace({
|
||||
const pageType: ToolPageType = tool.pageType || (
|
||||
tool.id.includes('lama') || tool.id.includes('eraser') || tool.id.includes('inpaint')
|
||||
? 'masking'
|
||||
: tool.id.includes('cartoon') || tool.id.includes('polaroid')
|
||||
: tool.thumbnails && tool.thumbnails.length > 0
|
||||
? 'image-thumbnail'
|
||||
: tool.id.includes('text') || tool.id.includes('prompt')
|
||||
? 'text-to-image'
|
||||
@@ -91,6 +82,10 @@ export function DynamicToolWorkspace({
|
||||
const [hasMaskDrawn, setHasMaskDrawn] = useState(false);
|
||||
const getMaskBlobRef = useRef<(() => Promise<Blob | null>) | null>(null);
|
||||
|
||||
// Cropper State & Export Ref
|
||||
const getCroppedBlobRef = useRef<(() => Promise<Blob | null>) | null>(null);
|
||||
const [isCropFull, setIsCropFull] = useState(true);
|
||||
|
||||
// Inference Execution State
|
||||
const [status, setStatus] = useState<'idle' | 'processing' | 'success' | 'error' | 'limit'>('idle');
|
||||
const [resultUrl, setResultUrl] = useState<string | null>(null);
|
||||
@@ -100,6 +95,25 @@ export function DynamicToolWorkspace({
|
||||
const fileInputRef = useRef<HTMLInputElement>(null);
|
||||
const secondaryFileInputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
// Fetch verified user quota from server dynamically (immune to inspect tool manipulation)
|
||||
const fetchUserQuota = useCallback(async () => {
|
||||
try {
|
||||
const res = await fetch('/api/user-quota', { cache: 'no-store' });
|
||||
if (res.ok) {
|
||||
const data = await res.json();
|
||||
if (typeof data.remainingToday === 'number') {
|
||||
setRemainingTries(data.remainingToday);
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
// Keep existing state
|
||||
}
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
fetchUserQuota();
|
||||
}, [fetchUserQuota]);
|
||||
|
||||
// Examples from JSON
|
||||
const primaryExample = tool.content?.examples?.[0] || {
|
||||
before: 'https://images.unsplash.com/photo-1534528741775-53994a69daeb?w=800&auto=format&fit=crop&q=80',
|
||||
@@ -151,7 +165,7 @@ export function DynamicToolWorkspace({
|
||||
setSecondaryPreview(URL.createObjectURL(file));
|
||||
};
|
||||
|
||||
const handleLoadSample = (sampleUrl: string, sampleResult?: string) => {
|
||||
const handleLoadSample = (sampleUrl: string) => {
|
||||
setPrimaryPreview(sampleUrl);
|
||||
setPrimaryFile(null);
|
||||
setResultUrl(null);
|
||||
@@ -165,6 +179,12 @@ export function DynamicToolWorkspace({
|
||||
|
||||
// Execute Request dynamically according to pageType
|
||||
const handleExecute = async () => {
|
||||
if (remainingTries <= 0) {
|
||||
setStatus('limit');
|
||||
setErrorMessage('You have reached the free operations limit for today. Try again tomorrow or get the mobile app.');
|
||||
return;
|
||||
}
|
||||
|
||||
setStatus('processing');
|
||||
setErrorMessage('');
|
||||
|
||||
@@ -174,8 +194,23 @@ export function DynamicToolWorkspace({
|
||||
// 1. Primary Image (for image-based archetypes)
|
||||
if (pageType !== 'text-to-image') {
|
||||
const imageParamName = tool.maskingConfig?.imageParamName || tool.twoImagesConfig?.firstImageParam || 'image';
|
||||
if (primaryFile) {
|
||||
formData.append(imageParamName, primaryFile);
|
||||
|
||||
let fileToSend: Blob | File | null = primaryFile;
|
||||
|
||||
// If user cropped the image via ImageCropper
|
||||
if (getCroppedBlobRef.current) {
|
||||
try {
|
||||
const croppedBlob = await getCroppedBlobRef.current();
|
||||
if (croppedBlob) {
|
||||
fileToSend = croppedBlob;
|
||||
}
|
||||
} catch (e) {
|
||||
console.error('Failed to export cropped blob, using original:', e);
|
||||
}
|
||||
}
|
||||
|
||||
if (fileToSend) {
|
||||
formData.append(imageParamName, fileToSend, 'photo.jpg');
|
||||
} else if (primaryPreview) {
|
||||
const res = await fetch(primaryPreview);
|
||||
const blob = await res.blob();
|
||||
@@ -226,7 +261,7 @@ export function DynamicToolWorkspace({
|
||||
formData.append('aspect_ratio', aspectRatio);
|
||||
}
|
||||
|
||||
// 5. Selected Thumbnail / Style Preset (for image-thumbnail or any tool with thumbnails)
|
||||
// 5. Selected Thumbnail / Style Preset
|
||||
if (selectedThumbnail) {
|
||||
formData.append('style', selectedThumbnail.value);
|
||||
formData.append('variant', selectedThumbnail.value);
|
||||
@@ -254,7 +289,14 @@ export function DynamicToolWorkspace({
|
||||
const outputUrl = URL.createObjectURL(blob);
|
||||
setResultUrl(outputUrl);
|
||||
setStatus('success');
|
||||
setRemainingTries((prev) => Math.max(0, prev - 1));
|
||||
|
||||
// Update verified remaining count from server response headers or server quota
|
||||
const remainingHeader = res.headers.get('X-Remaining-Tries');
|
||||
if (remainingHeader !== null && !isNaN(parseInt(remainingHeader, 10))) {
|
||||
setRemainingTries(parseInt(remainingHeader, 10));
|
||||
} else {
|
||||
fetchUserQuota();
|
||||
}
|
||||
} catch {
|
||||
setStatus('error');
|
||||
setErrorMessage('Network error during model inference.');
|
||||
@@ -283,83 +325,54 @@ export function DynamicToolWorkspace({
|
||||
if (viewMode === 'studio') {
|
||||
return (
|
||||
<div className="min-h-screen bg-paper pb-20">
|
||||
{/* Studio Sticky Header */}
|
||||
|
||||
{/* Studio Clean Top Bar (Old duplicate buttons & pills removed) */}
|
||||
<div className="sticky top-0 z-40 bg-paper-hi/95 backdrop-blur-md border-b border-rule shadow-2xs">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 h-16 flex items-center justify-between gap-4">
|
||||
{/* Left: Back to Overview & Tool Title */}
|
||||
{/* Left: Clean Back to Overview */}
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode('landing')}
|
||||
className="inline-flex items-center gap-2 px-3.5 py-2 rounded-xl text-xs font-sans font-semibold text-slate-700 bg-slate-100 hover:bg-slate-200 transition-colors cursor-pointer"
|
||||
>
|
||||
<ArrowLeft className="w-4 h-4" />
|
||||
<span>Back to Overview</span>
|
||||
</button>
|
||||
|
||||
{/* Right: Direct Download when Result is Ready */}
|
||||
<div className="flex items-center gap-3">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setViewMode('landing')}
|
||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-body font-semibold text-ink-2 bg-paper-2 hover:bg-paper hover:text-ink transition-colors cursor-pointer"
|
||||
>
|
||||
<ArrowLeft className="w-3.5 h-3.5" />
|
||||
<span>Overview</span>
|
||||
</button>
|
||||
|
||||
<div className="h-4 w-px bg-rule hidden sm:block" />
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<span className="font-display font-bold text-ink text-sm sm:text-base">
|
||||
{toolName}
|
||||
</span>
|
||||
<span className="px-2 py-0.5 rounded-full bg-accent/10 border border-accent/20 text-[10px] font-semibold text-accent uppercase tracking-wider font-body hidden md:inline-block">
|
||||
{pageType} studio
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Right: Actions, Tries, Process Button */}
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-xs text-muted font-body hidden sm:inline-block">
|
||||
{remainingTries} free tries today
|
||||
</span>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleResetStudio}
|
||||
className="p-2 rounded-xl text-ink-2 hover:bg-paper hover:text-ink transition-colors cursor-pointer"
|
||||
title="Reset studio"
|
||||
>
|
||||
<RotateCcw className="w-4 h-4" />
|
||||
</button>
|
||||
|
||||
{status === 'success' && resultUrl ? (
|
||||
{status === 'success' && resultUrl && (
|
||||
<a
|
||||
href={resultUrl}
|
||||
download={`${tool.slug}-result.png`}
|
||||
className="inline-flex items-center gap-1.5 px-4 py-2 rounded-full bg-ink text-paper-hi text-xs font-semibold shadow-xs hover:bg-slate-900 transition-colors cursor-pointer"
|
||||
className="inline-flex items-center gap-2 px-5 py-2 rounded-full bg-slate-900 text-white text-xs font-semibold shadow-xs hover:bg-slate-800 transition-colors cursor-pointer"
|
||||
>
|
||||
<Download className="w-3.5 h-3.5" />
|
||||
<Download className="w-3.5 h-3.5 text-accent" />
|
||||
<span>Download Result</span>
|
||||
</a>
|
||||
) : (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExecute}
|
||||
disabled={status === 'processing'}
|
||||
className="inline-flex items-center gap-2 px-5 py-2 rounded-full bg-accent text-white text-xs font-semibold shadow-xs hover:bg-accent-hi transition-colors cursor-pointer disabled:opacity-50"
|
||||
>
|
||||
{status === 'processing' ? (
|
||||
<>
|
||||
<Loader2 className="w-3.5 h-3.5 animate-spin" />
|
||||
<span>Processing...</span>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<Sparkles className="w-3.5 h-3.5" />
|
||||
<span>Process Photo</span>
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Studio Workspace Canvas */}
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pt-5 space-y-5">
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 pt-6 space-y-6">
|
||||
|
||||
{/* Prominent, Visually Large Tool Heading & Subtitle */}
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2 text-xs font-sans text-slate-500">
|
||||
<Link href="/tools" className="hover:text-slate-900 hover:underline">Tools</Link>
|
||||
<span>/</span>
|
||||
<span className="text-slate-700 font-medium">{toolName}</span>
|
||||
</div>
|
||||
<h1 className="text-3xl sm:text-5xl font-display font-extrabold text-slate-900 tracking-tight">
|
||||
{toolName}
|
||||
</h1>
|
||||
<p className="text-sm sm:text-base text-slate-600 font-sans max-w-3xl leading-relaxed">
|
||||
{toolSummary}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Error Banner */}
|
||||
{errorMessage && (
|
||||
<div className="p-3.5 rounded-xl bg-red-500/10 border border-red-500/20 text-red-600 text-xs font-sans flex items-center gap-2">
|
||||
@@ -369,7 +382,7 @@ export function DynamicToolWorkspace({
|
||||
)}
|
||||
|
||||
{/* Archetype Studio Layout */}
|
||||
<div className="studio-sheet p-5 sm:p-6 rounded-2xl bg-paper-hi border border-rule shadow-sheet space-y-5">
|
||||
<div className="studio-sheet p-5 sm:p-6 rounded-3xl bg-paper-hi border border-rule shadow-sheet space-y-6">
|
||||
|
||||
{/* POST-EDIT RESULT COMPARISON VIEW (If inference succeeded) */}
|
||||
{status === 'success' && resultUrl ? (
|
||||
@@ -405,8 +418,8 @@ export function DynamicToolWorkspace({
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* POST-EDIT ACTION BAR: DIRECTLY BELOW THE RESULT SLIDER */}
|
||||
<div className="pt-6 border-t border-rule space-y-4">
|
||||
{/* POST-EDIT ACTION BAR */}
|
||||
<div className="pt-6 border-t border-rule">
|
||||
<div className="flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
<div className="flex items-center gap-2.5 w-full sm:w-auto order-2 sm:order-1">
|
||||
<button
|
||||
@@ -441,7 +454,8 @@ export function DynamicToolWorkspace({
|
||||
) : (
|
||||
/* PRE-EDIT WORKSPACE (Interactive Editing by Page Type) */
|
||||
<div className="space-y-6">
|
||||
{/* 1. MASKING STUDIO (Auto-mask + Custom Mask Brush) */}
|
||||
|
||||
{/* 1. MASKING STUDIO (Inpainting & Brush Editor) */}
|
||||
{pageType === 'masking' && primaryPreview && (
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between pb-2 border-b border-rule">
|
||||
@@ -467,41 +481,30 @@ export function DynamicToolWorkspace({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 2. IMAGE + THUMBNAIL STUDIO */}
|
||||
{pageType === 'image-thumbnail' && primaryPreview && (
|
||||
{/* 2. DEFAULT PHOTO CROPPER STUDIO (For image-only and image-thumbnail) */}
|
||||
{(pageType === 'image-only' || pageType === 'image-thumbnail') && primaryPreview && (
|
||||
<div className="space-y-4">
|
||||
<div className="aspect-[4/3] sm:aspect-[16/10] max-h-[520px] w-full rounded-2xl overflow-hidden bg-paper-2 border border-rule relative">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={primaryPreview}
|
||||
alt="Uploaded preview"
|
||||
className="w-full h-full object-contain"
|
||||
<div className="relative">
|
||||
<ImageCropper
|
||||
imageUrl={primaryPreview}
|
||||
onCropChange={(crop, isFull) => {
|
||||
setIsCropFull(isFull);
|
||||
}}
|
||||
onExportReady={(fn) => {
|
||||
getCroppedBlobRef.current = fn;
|
||||
}}
|
||||
disabled={status === 'processing'}
|
||||
/>
|
||||
{status === 'processing' && (
|
||||
<ProcessingOverlay toolName={toolName} />
|
||||
<div className="absolute inset-0 z-30 rounded-2xl overflow-hidden">
|
||||
<ProcessingOverlay toolName={toolName} />
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 3. IMAGE-ONLY STUDIO */}
|
||||
{pageType === 'image-only' && primaryPreview && (
|
||||
<div className="space-y-4">
|
||||
<div className="aspect-[4/3] sm:aspect-[16/10] max-h-[520px] w-full rounded-2xl overflow-hidden bg-paper-2 border border-rule relative">
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
src={primaryPreview}
|
||||
alt="Uploaded preview"
|
||||
className="w-full h-full object-contain"
|
||||
/>
|
||||
{status === 'processing' && (
|
||||
<ProcessingOverlay toolName={toolName} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 4. TEXT-TO-IMAGE STUDIO */}
|
||||
{/* 3. TEXT-TO-IMAGE STUDIO */}
|
||||
{pageType === 'text-to-image' && (
|
||||
<div className="space-y-5">
|
||||
<label className="block text-xs font-semibold text-ink font-body">
|
||||
@@ -548,7 +551,7 @@ export function DynamicToolWorkspace({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* 5. TWO-IMAGES STUDIO */}
|
||||
{/* 4. TWO-IMAGES STUDIO */}
|
||||
{pageType === 'two-images' && (
|
||||
<div className="relative">
|
||||
<div className="grid grid-cols-1 md:grid-cols-2 gap-6">
|
||||
@@ -604,7 +607,7 @@ export function DynamicToolWorkspace({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* In-Studio Style Preset Thumbnails (for image-thumbnail or masking with thumbnails) */}
|
||||
{/* In-Studio Style Preset Thumbnails (if available) */}
|
||||
{tool.thumbnails && tool.thumbnails.length > 0 && (
|
||||
<div className="pt-4 border-t border-rule">
|
||||
<ThumbnailsSection
|
||||
@@ -618,42 +621,31 @@ export function DynamicToolWorkspace({
|
||||
)}
|
||||
|
||||
{/* ================================================================= */}
|
||||
{/* STUDIO MAIN ACTION BAR: CLEARLY VISIBLE PRIMARY & SECONDARY BUTTONS */}
|
||||
{/* DIRECTLY BELOW THE PHOTO UPLOAD CANVAS (USER MANDATE) */}
|
||||
{/* STUDIO MAIN ACTION BAR: CLEARLY VISIBLE PRIMARY BUTTON WITH REMAINING COUNT */}
|
||||
{/* DIRECTLY BELOW THE PHOTO UPLOAD CANVAS */}
|
||||
{/* ================================================================= */}
|
||||
<div className="pt-6 border-t border-rule space-y-4">
|
||||
<div className="pt-6 border-t border-rule">
|
||||
<div className="flex flex-col sm:flex-row items-center justify-between gap-4">
|
||||
|
||||
{/* Left: Secondary actions (Change Photo, Reset, etc.) */}
|
||||
{/* Left: Reset / Try Another Photo */}
|
||||
<div className="flex items-center gap-2.5 w-full sm:w-auto order-2 sm:order-1">
|
||||
{pageType !== 'text-to-image' && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="flex-1 sm:flex-none inline-flex items-center justify-center gap-2 px-5 py-3.5 rounded-2xl bg-paper-2 hover:bg-paper text-ink font-body text-xs sm:text-sm font-semibold border border-rule transition-colors cursor-pointer shadow-2xs"
|
||||
>
|
||||
<FolderOpen className="w-4 h-4 text-accent" />
|
||||
<span>Change Photo</span>
|
||||
</button>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleResetStudio}
|
||||
className="inline-flex items-center justify-center gap-1.5 px-4 py-3.5 rounded-2xl bg-paper-2 hover:bg-red-50 hover:text-red-600 hover:border-red-200 text-ink-2 font-body text-xs sm:text-sm font-medium border border-rule transition-colors cursor-pointer shadow-2xs"
|
||||
className="inline-flex items-center justify-center gap-2 px-5 py-3.5 rounded-2xl bg-paper-2 hover:bg-paper text-ink font-body text-xs sm:text-sm font-semibold border border-rule transition-colors cursor-pointer shadow-2xs"
|
||||
>
|
||||
<RotateCcw className="w-3.5 h-3.5" />
|
||||
<span>Reset</span>
|
||||
<RotateCcw className="w-4 h-4 text-slate-500" />
|
||||
<span>Try Another Photo</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Right: Massive High-Visibility Main Process Button */}
|
||||
{/* Right: Massive High-Visibility Main Process Button with Dynamic Server-backed Quota Icon */}
|
||||
<div className="w-full sm:w-auto order-1 sm:order-2">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleExecute}
|
||||
disabled={status === 'processing'}
|
||||
className="w-full sm:w-auto inline-flex items-center justify-center gap-3 px-8 sm:px-12 py-4 rounded-2xl sm:rounded-full bg-accent hover:bg-accent-hi text-white font-display font-extrabold text-sm sm:text-base shadow-xl shadow-accent/25 hover:shadow-accent/40 hover:scale-[1.02] active:scale-98 transition-all cursor-pointer disabled:opacity-50 disabled:hover:scale-100"
|
||||
disabled={status === 'processing' || remainingTries <= 0}
|
||||
className="w-full sm:w-auto inline-flex items-center justify-center gap-3 px-8 sm:px-10 py-4 rounded-2xl sm:rounded-full bg-accent hover:bg-accent-hi text-white font-display font-extrabold text-sm sm:text-base shadow-xl shadow-accent/25 hover:shadow-accent/40 hover:scale-[1.02] active:scale-98 transition-all cursor-pointer disabled:opacity-50 disabled:hover:scale-100"
|
||||
>
|
||||
{status === 'processing' ? (
|
||||
<>
|
||||
@@ -674,19 +666,17 @@ export function DynamicToolWorkspace({
|
||||
? `Apply ${resolveLocalised(selectedThumbnail.label, locale)} Look`
|
||||
: 'Process & Enhance Photo'}
|
||||
</span>
|
||||
<ArrowRight className="w-4 h-4" />
|
||||
{/* Dynamic Icon Badge Showing Remaining Tries */}
|
||||
<span className="inline-flex items-center gap-1.5 px-2.5 py-1 rounded-full bg-white/20 text-white font-mono text-xs font-bold shadow-2xs backdrop-blur-xs ml-1">
|
||||
<Zap className="w-3.5 h-3.5 text-amber-300" />
|
||||
<span>{remainingTries} left</span>
|
||||
</span>
|
||||
<ArrowRight className="w-4 h-4 ml-0.5" />
|
||||
</>
|
||||
)}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-wrap items-center justify-between text-[11px] text-muted font-body px-1 gap-2">
|
||||
<span className="flex items-center gap-1 text-emerald-600 font-medium">
|
||||
<CheckCircle2 className="w-3 h-3" />
|
||||
<span>Volatile GPU memory execution · Zero server storage</span>
|
||||
</span>
|
||||
<span className="font-mono">{remainingTries} free daily operations remaining</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -695,15 +685,6 @@ export function DynamicToolWorkspace({
|
||||
|
||||
</div>
|
||||
|
||||
{/* Quick Info Row */}
|
||||
<div className="flex flex-wrap items-center justify-between gap-4 text-xs font-body text-muted px-2">
|
||||
<div className="flex items-center gap-2 text-emerald-600">
|
||||
<CheckCircle2 className="w-3.5 h-3.5" />
|
||||
<span>In-browser volatile GPU RAM execution · Zero server storage</span>
|
||||
</div>
|
||||
<span>Unlimited batch & 4K exports available in {homeApp ? resolveLocalised(homeApp.name, locale) : 'the mobile app'}</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -716,17 +697,17 @@ export function DynamicToolWorkspace({
|
||||
<div className="min-h-screen bg-paper">
|
||||
|
||||
{/* ================= HERO SECTION ================= */}
|
||||
<section className="relative pt-6 sm:pt-8 pb-10 sm:pb-12 bg-paper border-b border-rule overflow-hidden">
|
||||
<section className="relative pt-6 sm:pt-10 pb-12 sm:pb-16 bg-paper border-b border-rule overflow-hidden">
|
||||
{/* Ambient Radial Spotlight */}
|
||||
<div
|
||||
className="pointer-events-none absolute top-0 left-1/2 -translate-x-1/2 w-[800px] h-[350px] [background:radial-gradient(ellipse_at_top,color-mix(in_oklab,var(--color-accent)_10%,transparent)_0%,transparent_70%)]"
|
||||
className="pointer-events-none absolute top-0 left-1/2 -translate-x-1/2 w-[900px] h-[400px] [background:radial-gradient(ellipse_at_top,color-mix(in_oklab,var(--color-accent)_12%,transparent)_0%,transparent_70%)]"
|
||||
aria-hidden="true"
|
||||
/>
|
||||
|
||||
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 relative z-10">
|
||||
|
||||
{/* Breadcrumb row */}
|
||||
<div className="flex items-center gap-2 text-xs font-sans text-slate-500 mb-4 tracking-wide">
|
||||
<div className="flex items-center gap-2 text-xs font-sans text-slate-500 mb-5 tracking-wide">
|
||||
<Link href="/" className="hover:text-slate-900 hover:underline">Home</Link>
|
||||
<span>/</span>
|
||||
<Link href="/tools" className="hover:text-slate-900 hover:underline">Tools</Link>
|
||||
@@ -734,12 +715,12 @@ export function DynamicToolWorkspace({
|
||||
<span className="text-accent font-semibold">{toolName}</span>
|
||||
</div>
|
||||
|
||||
{/* Header Title & Summary (Pills removed, generous typography breathing room) */}
|
||||
<div className="max-w-5xl mb-8 sm:mb-10 space-y-4">
|
||||
<h1 className="text-3xl sm:text-5xl font-display font-extrabold text-ink tracking-tight leading-tight">
|
||||
{/* Header Title & Summary (Larger, visually striking typography) */}
|
||||
<div className="max-w-5xl mb-8 sm:mb-12 space-y-4 sm:space-y-5">
|
||||
<h1 className="text-4xl sm:text-6xl lg:text-7xl font-display font-extrabold text-slate-900 tracking-tight leading-[1.08]">
|
||||
<AnimatedShinyText>{toolName}</AnimatedShinyText>
|
||||
</h1>
|
||||
<p className="text-base sm:text-lg text-ink-2 font-sans max-w-4xl leading-relaxed">
|
||||
<p className="text-base sm:text-xl text-slate-600 font-sans max-w-4xl leading-relaxed">
|
||||
{toolSummary}
|
||||
</p>
|
||||
</div>
|
||||
@@ -753,9 +734,8 @@ export function DynamicToolWorkspace({
|
||||
|
||||
<div className="border-b border-rule pb-3.5 mb-6 flex items-center justify-between">
|
||||
<span className="text-sm font-bold font-sans text-slate-900">
|
||||
{pageType === 'text-to-image' ? 'Text prompt studio' : 'Interactive tool studio'}
|
||||
{pageType === 'text-to-image' ? 'Generate AI Image' : 'Select Photo to Edit'}
|
||||
</span>
|
||||
<span className="text-xs text-slate-500 font-sans">Zero server retention</span>
|
||||
</div>
|
||||
|
||||
{/* Dynamic Upload Input by Type */}
|
||||
@@ -780,10 +760,10 @@ export function DynamicToolWorkspace({
|
||||
key={t.id}
|
||||
type="button"
|
||||
onClick={() => setSelectedThumbnail(t)}
|
||||
className={`shrink-0 flex items-center gap-2 px-3.5 py-2 rounded-xl border text-xs sm:text-sm font-sans font-semibold transition-all cursor-pointer ${
|
||||
className={`shrink-0 flex items-center gap-2 px-3 py-1.5 rounded-xl text-xs font-sans transition-all cursor-pointer ${
|
||||
isSelected
|
||||
? 'bg-accent/10 border-accent text-accent shadow-xs'
|
||||
: 'bg-paper border-rule text-slate-800 hover:border-rule-2'
|
||||
? 'bg-slate-900 text-white shadow-xs font-semibold'
|
||||
: 'bg-slate-100 text-slate-700 hover:bg-slate-200'
|
||||
}`}
|
||||
>
|
||||
{(t.thumbnail || t.preview) && (
|
||||
@@ -798,117 +778,110 @@ export function DynamicToolWorkspace({
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Type 1, 2, 3: Spacious, Prominently Sized Drag & Drop Dropzone */}
|
||||
{pageType !== 'text-to-image' && pageType !== 'two-images' && (
|
||||
{/* 1. Standard Single Upload Dropzone */}
|
||||
{pageType !== 'two-images' && pageType !== 'text-to-image' && (
|
||||
<div className="space-y-5">
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Prominent High-Visibility Drag & Drop Zone */}
|
||||
<div
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
onDragOver={(e) => e.preventDefault()}
|
||||
onDrop={(e) => {
|
||||
e.preventDefault();
|
||||
if (e.dataTransfer.files?.[0]) handlePrimaryFileSelect(e.dataTransfer.files[0]);
|
||||
}}
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="min-h-[280px] sm:min-h-[320px] flex flex-col items-center justify-center border-2 border-dashed border-rule hover:border-accent rounded-3xl p-8 sm:p-12 text-center bg-paper/60 hover:bg-accent/5 transition-all cursor-pointer group"
|
||||
className="w-full min-h-[320px] p-8 sm:p-12 rounded-2xl border-2 border-dashed border-accent/40 hover:border-accent bg-accent/5 hover:bg-accent/10 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-4 group shadow-inner"
|
||||
>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
|
||||
}}
|
||||
/>
|
||||
|
||||
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-3xl bg-paper-hi border border-rule flex items-center justify-center text-accent mx-auto mb-4 group-hover:scale-105 group-hover:border-accent transition-transform shadow-xs">
|
||||
<div className="w-16 h-16 sm:w-20 sm:h-20 rounded-2xl bg-white shadow-md flex items-center justify-center group-hover:scale-110 transition-transform">
|
||||
<UploadCloud className="w-8 h-8 sm:w-10 sm:h-10 text-accent" />
|
||||
</div>
|
||||
|
||||
<h4 className="text-lg sm:text-xl font-display font-bold text-ink tracking-tight">
|
||||
Drag and drop your image here
|
||||
</h4>
|
||||
<p className="text-xs sm:text-sm text-slate-500 font-sans mt-2 max-w-sm mx-auto leading-relaxed">
|
||||
Supports high-resolution JPG, PNG, and WebP up to 12MB. Zero server retention.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* PROMINENT ACTION BUTTONS DIRECTLY BELOW PHOTO UPLOAD */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-3.5 pt-1">
|
||||
<div className="space-y-1">
|
||||
<span className="text-base sm:text-lg font-bold text-slate-900 block font-sans">
|
||||
Click to upload or drag photo here
|
||||
</span>
|
||||
<p className="text-xs sm:text-sm text-slate-500 font-sans">
|
||||
Supports JPEG, PNG, and WebP (up to {tool.tryIt?.limits?.maxMB || 12}MB)
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="w-full inline-flex items-center justify-center gap-2.5 px-6 py-4 rounded-2xl bg-accent hover:bg-accent-hi text-white font-display font-bold text-sm shadow-md hover:shadow-lg hover:scale-[1.01] active:scale-98 transition-all cursor-pointer group"
|
||||
onClick={(e) => {
|
||||
e.stopPropagation();
|
||||
fileInputRef.current?.click();
|
||||
}}
|
||||
className="w-full sm:w-auto px-8 py-3.5 rounded-xl bg-slate-900 hover:bg-slate-800 text-white font-sans font-semibold text-xs sm:text-sm shadow-md transition-colors"
|
||||
>
|
||||
<FolderOpen className="w-4 h-4 text-white group-hover:scale-110 transition-transform" />
|
||||
<span>Select Photo to Upload</span>
|
||||
Select from Device
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{samplePresets.length > 0 && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleLoadSample(samplePresets[0].url, samplePresets[0].resultUrl)}
|
||||
className="w-full inline-flex items-center justify-center gap-2.5 px-6 py-4 rounded-2xl bg-paper-hi hover:bg-paper-2 border border-rule hover:border-accent text-slate-800 font-sans text-sm font-semibold shadow-2xs hover:shadow-xs active:scale-98 transition-all cursor-pointer group"
|
||||
>
|
||||
<Sparkles className="w-4 h-4 text-accent group-hover:rotate-12 transition-transform" />
|
||||
<span>Try Demo Portrait</span>
|
||||
</button>
|
||||
)}
|
||||
{/* Sample Presets */}
|
||||
<div className="pt-2 flex items-center justify-between text-xs text-slate-500 font-sans">
|
||||
<span>No photo ready?</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleLoadSample(primaryExample.before)}
|
||||
className="text-accent font-semibold hover:underline cursor-pointer"
|
||||
>
|
||||
Try with sample photo →
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Type 5: Two-Images Dual Upload Dropzones */}
|
||||
{/* 2. Two-Images Archetype Upload */}
|
||||
{pageType === 'two-images' && (
|
||||
<div className="space-y-5">
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
{/* Box 1: Primary Image */}
|
||||
{/* Image 1 Dropzone */}
|
||||
<div
|
||||
onClick={() => fileInputRef.current?.click()}
|
||||
className="min-h-[220px] flex flex-col items-center justify-center border-2 border-dashed border-rule hover:border-accent rounded-2xl p-6 text-center bg-paper/60 hover:bg-accent/5 transition-all cursor-pointer group"
|
||||
className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[160px]"
|
||||
>
|
||||
<input
|
||||
ref={fileInputRef}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
if (e.target.files?.[0]) handlePrimaryFileSelect(e.target.files[0]);
|
||||
}}
|
||||
/>
|
||||
<div className="w-14 h-14 rounded-2xl bg-paper-hi border border-rule flex items-center justify-center text-accent mx-auto mb-3 group-hover:scale-105 transition-transform shadow-xs">
|
||||
<UploadCloud className="w-7 h-7" />
|
||||
</div>
|
||||
<h5 className="text-sm font-display font-bold text-ink">
|
||||
{resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Primary Photo'}
|
||||
</h5>
|
||||
<p className="text-xs text-slate-500 font-sans mt-1">
|
||||
{primaryFile ? primaryFile.name : 'Target face or subject'}
|
||||
</p>
|
||||
<UploadCloud className="w-6 h-6 text-accent" />
|
||||
<span className="text-xs font-bold text-ink font-body">
|
||||
{resolveLocalised(tool.twoImagesConfig?.firstImageLabel, locale) || '1. Source Face'}
|
||||
</span>
|
||||
<span className="text-[10px] text-muted font-body">Click to choose</span>
|
||||
</div>
|
||||
|
||||
{/* Box 2: Reference Image */}
|
||||
{/* Image 2 Dropzone */}
|
||||
<div
|
||||
onClick={() => secondaryFileInputRef.current?.click()}
|
||||
className="min-h-[220px] flex flex-col items-center justify-center border-2 border-dashed border-rule hover:border-accent rounded-2xl p-6 text-center bg-paper/60 hover:bg-accent/5 transition-all cursor-pointer group"
|
||||
className="p-5 rounded-2xl border-2 border-dashed border-rule hover:border-accent bg-paper hover:bg-accent/5 transition-all cursor-pointer flex flex-col items-center justify-center text-center space-y-2 min-h-[160px]"
|
||||
>
|
||||
<input
|
||||
ref={secondaryFileInputRef}
|
||||
type="file"
|
||||
accept="image/jpeg,image/png,image/webp"
|
||||
accept="image/*"
|
||||
className="hidden"
|
||||
onChange={(e) => {
|
||||
if (e.target.files?.[0]) handleSecondaryFileSelect(e.target.files[0]);
|
||||
}}
|
||||
/>
|
||||
<div className="w-14 h-14 rounded-2xl bg-paper-hi border border-rule flex items-center justify-center text-accent mx-auto mb-3 group-hover:scale-105 transition-transform shadow-xs">
|
||||
<ImageIcon className="w-7 h-7" />
|
||||
</div>
|
||||
<h5 className="text-sm font-display font-bold text-ink">
|
||||
{resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Reference Photo'}
|
||||
</h5>
|
||||
<p className="text-xs text-slate-500 font-sans mt-1">
|
||||
{secondaryFile ? secondaryFile.name : 'Source identity to fuse'}
|
||||
</p>
|
||||
<UploadCloud className="w-6 h-6 text-accent" />
|
||||
<span className="text-xs font-bold text-ink font-body">
|
||||
{resolveLocalised(tool.twoImagesConfig?.secondImageLabel, locale) || '2. Target Body/Photo'}
|
||||
</span>
|
||||
<span className="text-[10px] text-muted font-body">Click to choose</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -922,13 +895,13 @@ export function DynamicToolWorkspace({
|
||||
}}
|
||||
className="w-full py-4 rounded-2xl bg-accent hover:bg-accent-hi text-white font-display font-bold text-sm shadow-md hover:shadow-lg transition-all cursor-pointer flex items-center justify-center gap-2.5"
|
||||
>
|
||||
<Sparkles className="w-4 h-4 text-white" />
|
||||
<span>Open in Dual-Image Studio</span>
|
||||
<Sparkles className="w-4 h-4 text-amber-300" />
|
||||
<span>Open Fusion Studio</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Type 4: Text-to-image Landing Input */}
|
||||
{/* 3. Text-to-Image Archetype Input */}
|
||||
{pageType === 'text-to-image' && (
|
||||
<div className="space-y-4">
|
||||
<textarea
|
||||
@@ -937,50 +910,26 @@ export function DynamicToolWorkspace({
|
||||
onChange={(e) => setPromptText(e.target.value)}
|
||||
placeholder={
|
||||
resolveLocalised(tool.textToImageConfig?.placeholder, locale) ||
|
||||
'Describe what you want to create (e.g. A solitary astronaut standing on crystal sands under a violet nebula, cinematic rim lighting, 8k resolution)...'
|
||||
'Describe what you want to create in detail...'
|
||||
}
|
||||
className="w-full p-4 rounded-2xl border border-rule bg-paper text-ink text-sm font-body placeholder:text-muted focus:outline-none focus:border-accent focus:ring-2 focus:ring-accent/20"
|
||||
/>
|
||||
|
||||
{/* Quick Prompt Ideas */}
|
||||
<div className="space-y-1.5">
|
||||
<span className="text-[11px] font-semibold text-muted font-body">Quick prompt inspiration:</span>
|
||||
<div className="flex flex-wrap items-center gap-1.5">
|
||||
{[
|
||||
'Cinematic 35mm portrait with golden hour rim light',
|
||||
'Makoto Shinkai anime cityscape under starry skies',
|
||||
'3D Disney character with luminous amber eyes',
|
||||
'Hyperrealistic wildlife in lush emerald rain forest'
|
||||
].map((samplePrompt) => (
|
||||
{/* Sample Prompts */}
|
||||
{tool.textToImageConfig?.samplePrompts && (
|
||||
<div className="flex flex-wrap gap-1.5 pt-1">
|
||||
{tool.textToImageConfig.samplePrompts.slice(0, 3).map((sp, idx) => (
|
||||
<button
|
||||
key={samplePrompt}
|
||||
key={idx}
|
||||
type="button"
|
||||
onClick={() => setPromptText(samplePrompt)}
|
||||
className="px-2.5 py-1 rounded-xl bg-paper-2 hover:bg-paper text-ink-2 hover:text-ink text-[11px] font-body border border-rule transition-colors cursor-pointer text-left truncate max-w-full"
|
||||
onClick={() => setPromptText(resolveLocalised(sp, locale))}
|
||||
className="px-2.5 py-1 rounded-lg bg-paper-2 hover:bg-paper border border-rule text-[11px] text-muted hover:text-ink font-body transition-colors cursor-pointer text-left line-clamp-1"
|
||||
>
|
||||
+ {samplePrompt}
|
||||
“{resolveLocalised(sp, locale)}”
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2 pt-1">
|
||||
<span className="text-xs text-muted font-body">Aspect:</span>
|
||||
{['1:1', '16:9', '9:16', '4:3'].map((ratio) => (
|
||||
<button
|
||||
key={ratio}
|
||||
type="button"
|
||||
onClick={() => setAspectRatio(ratio)}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-body font-semibold transition-colors cursor-pointer ${
|
||||
aspectRatio === ratio
|
||||
? 'bg-ink text-paper-hi shadow-xs'
|
||||
: 'bg-paper-2 text-ink-2 hover:bg-paper'
|
||||
}`}
|
||||
>
|
||||
{ratio}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<button
|
||||
type="button"
|
||||
@@ -992,26 +941,11 @@ export function DynamicToolWorkspace({
|
||||
}
|
||||
}
|
||||
}}
|
||||
className="w-full py-4 rounded-2xl bg-accent hover:bg-accent-hi text-white text-sm font-display font-bold shadow-md hover:shadow-lg transition-all cursor-pointer flex items-center justify-center gap-2 group"
|
||||
disabled={!promptText.trim()}
|
||||
className="w-full py-4 rounded-2xl bg-accent hover:bg-accent-hi disabled:opacity-50 text-white font-display font-bold text-sm shadow-md hover:shadow-lg transition-all cursor-pointer flex items-center justify-center gap-2.5"
|
||||
>
|
||||
<Sparkles className="w-4 h-4 text-amber-300 group-hover:rotate-12 transition-transform" />
|
||||
<span>Open in AI Generation Studio</span>
|
||||
<ArrowRight className="w-4 h-4 text-white" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Sample Presets to Try Instantly with 1 Click */}
|
||||
{samplePresets.length > 0 && pageType !== 'text-to-image' && (
|
||||
<div className="pt-2 border-t border-rule/60 flex items-center justify-between text-xs font-body">
|
||||
<span className="text-muted">No photo handy?</span>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => handleLoadSample(samplePresets[0].url, samplePresets[0].resultUrl)}
|
||||
className="text-accent font-semibold hover:underline inline-flex items-center gap-1 cursor-pointer"
|
||||
>
|
||||
<span>Try sample portrait</span>
|
||||
<ChevronRight className="w-3.5 h-3.5" />
|
||||
<Sparkles className="w-4 h-4 text-amber-300" />
|
||||
<span>Open Creation Studio</span>
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
@@ -1031,13 +965,11 @@ export function DynamicToolWorkspace({
|
||||
beforeUrl={primaryExample.before}
|
||||
afterUrl={primaryExample.after}
|
||||
title={toolName}
|
||||
slug={tool.slug}
|
||||
aspectRatio="aspect-[4/3]"
|
||||
aspectRatio="aspect-auto h-full"
|
||||
beforeLabel="ORIGINAL"
|
||||
afterLabel="ENHANCED"
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-4 text-xs text-slate-500 font-sans text-center leading-relaxed">
|
||||
Full 4K batch processing available in {homeApp ? resolveLocalised(homeApp.name, locale) : 'the mobile app'}.
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -1064,8 +996,7 @@ export function DynamicToolWorkspace({
|
||||
}
|
||||
}}
|
||||
locale={locale}
|
||||
title="Explore Visual Styles & Presets"
|
||||
subtitle="Click any preset thumbnail to select your effect before or during editing."
|
||||
title={resolveLocalised(tool.name, locale)}
|
||||
/>
|
||||
)}
|
||||
|
||||
@@ -1163,7 +1094,6 @@ export function DynamicToolWorkspace({
|
||||
href="/apps"
|
||||
className="shrink-0 inline-flex items-center gap-2 px-5 py-2.5 rounded-full bg-slate-900 hover:bg-slate-800 text-white text-xs font-semibold shadow-md transition-colors"
|
||||
>
|
||||
<Smartphone className="w-4 h-4 text-accent" />
|
||||
<span>Explore Mobile Apps Suite</span>
|
||||
</Link>
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,419 @@
|
||||
'use client';
|
||||
|
||||
import React, { useState, useRef, useEffect, useCallback } from 'react';
|
||||
import { Crop, RotateCcw, Maximize2, Sparkles, Check } from 'lucide-react';
|
||||
|
||||
export interface CropRect {
|
||||
x: number; // 0 to 100%
|
||||
y: number; // 0 to 100%
|
||||
width: number; // 0 to 100%
|
||||
height: number; // 0 to 100%
|
||||
}
|
||||
|
||||
interface ImageCropperProps {
|
||||
imageUrl: string;
|
||||
onCropChange?: (crop: CropRect, isFullImage: boolean) => void;
|
||||
onExportReady?: (getCroppedBlob: () => Promise<Blob | null>) => void;
|
||||
disabled?: boolean;
|
||||
}
|
||||
|
||||
type AspectRatioOption = 'freeform' | '1:1' | '4:5' | '16:9' | '9:16' | '4:3' | '3:4';
|
||||
|
||||
const RATIO_CONFIGS: Array<{ id: AspectRatioOption; label: string; ratio?: number }> = [
|
||||
{ id: 'freeform', label: 'Freeform' },
|
||||
{ id: '1:1', label: '1:1 Square', ratio: 1 / 1 },
|
||||
{ id: '4:5', label: '4:5 Portrait', ratio: 4 / 5 },
|
||||
{ id: '16:9', label: '16:9 Wide', ratio: 16 / 9 },
|
||||
{ id: '9:16', label: '9:16 Story', ratio: 9 / 16 },
|
||||
{ id: '4:3', label: '4:3 Photo', ratio: 4 / 3 },
|
||||
{ id: '3:4', label: '3:4 Classic', ratio: 3 / 4 },
|
||||
];
|
||||
|
||||
export function ImageCropper({
|
||||
imageUrl,
|
||||
onCropChange,
|
||||
onExportReady,
|
||||
disabled = false,
|
||||
}: ImageCropperProps) {
|
||||
const [selectedRatio, setSelectedRatio] = useState<AspectRatioOption>('freeform');
|
||||
const [crop, setCrop] = useState<CropRect>({ x: 0, y: 0, width: 100, height: 100 });
|
||||
const [imageSize, setImageSize] = useState<{ width: number; height: number }>({ width: 0, height: 0 });
|
||||
|
||||
const containerRef = useRef<HTMLDivElement>(null);
|
||||
const imgRef = useRef<HTMLImageElement>(null);
|
||||
|
||||
// Drag interaction state
|
||||
const dragModeRef = useRef<'move' | 'nw' | 'ne' | 'se' | 'sw' | 'n' | 'e' | 's' | 'w' | null>(null);
|
||||
const startPosRef = useRef<{ clientX: number; clientY: number }>({ clientX: 0, clientY: 0 });
|
||||
const startCropRef = useRef<CropRect>({ x: 0, y: 0, width: 100, height: 100 });
|
||||
|
||||
// Reset crop to full
|
||||
const handleResetCrop = useCallback(() => {
|
||||
const full: CropRect = { x: 0, y: 0, width: 100, height: 100 };
|
||||
setCrop(full);
|
||||
setSelectedRatio('freeform');
|
||||
onCropChange?.(full, true);
|
||||
}, [onCropChange]);
|
||||
|
||||
// Handle image load to initialize dimensions
|
||||
const handleImageLoaded = (e: React.SyntheticEvent<HTMLImageElement>) => {
|
||||
const img = e.currentTarget;
|
||||
setImageSize({ width: img.naturalWidth, height: img.naturalHeight });
|
||||
};
|
||||
|
||||
// Adjust crop box to a specified aspect ratio while keeping it within bounds
|
||||
const applyAspectRatio = useCallback(
|
||||
(ratioId: AspectRatioOption) => {
|
||||
setSelectedRatio(ratioId);
|
||||
const conf = RATIO_CONFIGS.find((r) => r.id === ratioId);
|
||||
|
||||
if (!conf?.ratio || !imageSize.width || !imageSize.height) {
|
||||
return;
|
||||
}
|
||||
|
||||
const targetRatio = conf.ratio;
|
||||
const imgAspect = imageSize.width / imageSize.height;
|
||||
|
||||
let newWidthPct = 90;
|
||||
let newHeightPct = (newWidthPct * imgAspect) / targetRatio;
|
||||
|
||||
if (newHeightPct > 90) {
|
||||
newHeightPct = 90;
|
||||
newWidthPct = (newHeightPct * targetRatio) / imgAspect;
|
||||
}
|
||||
|
||||
const newX = (100 - newWidthPct) / 2;
|
||||
const newY = (100 - newHeightPct) / 2;
|
||||
|
||||
const newCrop: CropRect = {
|
||||
x: Math.max(0, Math.min(100, newX)),
|
||||
y: Math.max(0, Math.min(100, newY)),
|
||||
width: Math.max(10, Math.min(100, newWidthPct)),
|
||||
height: Math.max(10, Math.min(100, newHeightPct)),
|
||||
};
|
||||
|
||||
setCrop(newCrop);
|
||||
onCropChange?.(newCrop, false);
|
||||
},
|
||||
[imageSize, onCropChange]
|
||||
);
|
||||
|
||||
// Dragging logic
|
||||
const handlePointerDown = (
|
||||
e: React.PointerEvent<HTMLDivElement>,
|
||||
mode: 'move' | 'nw' | 'ne' | 'se' | 'sw' | 'n' | 'e' | 's' | 'w'
|
||||
) => {
|
||||
if (disabled) return;
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
|
||||
dragModeRef.current = mode;
|
||||
startPosRef.current = { clientX: e.clientX, clientY: e.clientY };
|
||||
startCropRef.current = { ...crop };
|
||||
|
||||
try {
|
||||
(e.currentTarget as HTMLElement).setPointerCapture(e.pointerId);
|
||||
} catch {}
|
||||
};
|
||||
|
||||
const handlePointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (!dragModeRef.current || !containerRef.current || disabled) return;
|
||||
|
||||
const rect = containerRef.current.getBoundingClientRect();
|
||||
if (rect.width <= 0 || rect.height <= 0) return;
|
||||
|
||||
const deltaXPct = ((e.clientX - startPosRef.current.clientX) / rect.width) * 100;
|
||||
const deltaYPct = ((e.clientY - startPosRef.current.clientY) / rect.height) * 100;
|
||||
|
||||
const start = startCropRef.current;
|
||||
let newCrop = { ...start };
|
||||
|
||||
if (dragModeRef.current === 'move') {
|
||||
let nextX = start.x + deltaXPct;
|
||||
let nextY = start.y + deltaYPct;
|
||||
|
||||
nextX = Math.max(0, Math.min(100 - start.width, nextX));
|
||||
nextY = Math.max(0, Math.min(100 - start.height, nextY));
|
||||
|
||||
newCrop.x = nextX;
|
||||
newCrop.y = nextY;
|
||||
} else {
|
||||
// Handle corner and edge resizing
|
||||
const mode = dragModeRef.current;
|
||||
const minSize = 8; // min 8% size
|
||||
|
||||
if (mode.includes('e')) {
|
||||
newCrop.width = Math.max(minSize, Math.min(100 - start.x, start.width + deltaXPct));
|
||||
}
|
||||
if (mode.includes('s')) {
|
||||
newCrop.height = Math.max(minSize, Math.min(100 - start.y, start.height + deltaYPct));
|
||||
}
|
||||
if (mode.includes('w')) {
|
||||
const potentialW = start.width - deltaXPct;
|
||||
if (potentialW >= minSize && start.x + deltaXPct >= 0) {
|
||||
newCrop.x = start.x + deltaXPct;
|
||||
newCrop.width = potentialW;
|
||||
}
|
||||
}
|
||||
if (mode.includes('n')) {
|
||||
const potentialH = start.height - deltaYPct;
|
||||
if (potentialH >= minSize && start.y + deltaYPct >= 0) {
|
||||
newCrop.y = start.y + deltaYPct;
|
||||
newCrop.height = potentialH;
|
||||
}
|
||||
}
|
||||
|
||||
// Constrain aspect ratio if a fixed ratio is selected
|
||||
const conf = RATIO_CONFIGS.find((r) => r.id === selectedRatio);
|
||||
if (conf?.ratio && imageSize.width && imageSize.height) {
|
||||
const imgAspect = imageSize.width / imageSize.height;
|
||||
const targetRatio = conf.ratio;
|
||||
// height in % = (width% * imgAspect) / targetRatio
|
||||
const constrainedHeight = (newCrop.width * imgAspect) / targetRatio;
|
||||
if (newCrop.y + constrainedHeight <= 100) {
|
||||
newCrop.height = constrainedHeight;
|
||||
} else {
|
||||
newCrop.height = 100 - newCrop.y;
|
||||
newCrop.width = (newCrop.height * targetRatio) / imgAspect;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setCrop(newCrop);
|
||||
const isFull =
|
||||
newCrop.x <= 1 &&
|
||||
newCrop.y <= 1 &&
|
||||
newCrop.width >= 98 &&
|
||||
newCrop.height >= 98;
|
||||
onCropChange?.(newCrop, isFull);
|
||||
};
|
||||
|
||||
const handlePointerUp = (e: React.PointerEvent<HTMLDivElement>) => {
|
||||
if (dragModeRef.current) {
|
||||
dragModeRef.current = null;
|
||||
try {
|
||||
(e.currentTarget as HTMLElement).releasePointerCapture(e.pointerId);
|
||||
} catch {}
|
||||
}
|
||||
};
|
||||
|
||||
// Provide high-resolution canvas export blob function to parent
|
||||
useEffect(() => {
|
||||
if (!onExportReady) return;
|
||||
|
||||
const getCroppedBlob = async (): Promise<Blob | null> => {
|
||||
const isFull =
|
||||
crop.x <= 0.5 &&
|
||||
crop.y <= 0.5 &&
|
||||
crop.width >= 99 &&
|
||||
crop.height >= 99;
|
||||
|
||||
return new Promise<Blob | null>((resolve) => {
|
||||
const img = new Image();
|
||||
img.crossOrigin = 'anonymous';
|
||||
img.onload = () => {
|
||||
const naturalW = img.naturalWidth;
|
||||
const naturalH = img.naturalHeight;
|
||||
|
||||
if (isFull) {
|
||||
// Full image without crop clipping
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = naturalW;
|
||||
canvas.height = naturalH;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return resolve(null);
|
||||
ctx.drawImage(img, 0, 0);
|
||||
canvas.toBlob((b) => resolve(b), 'image/jpeg', 0.95);
|
||||
return;
|
||||
}
|
||||
|
||||
const pixelX = Math.max(0, Math.round((crop.x / 100) * naturalW));
|
||||
const pixelY = Math.max(0, Math.round((crop.y / 100) * naturalH));
|
||||
const pixelW = Math.min(naturalW - pixelX, Math.round((crop.width / 100) * naturalW));
|
||||
const pixelH = Math.min(naturalH - pixelY, Math.round((crop.height / 100) * naturalH));
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = pixelW;
|
||||
canvas.height = pixelH;
|
||||
const ctx = canvas.getContext('2d');
|
||||
if (!ctx) return resolve(null);
|
||||
|
||||
ctx.drawImage(img, pixelX, pixelY, pixelW, pixelH, 0, 0, pixelW, pixelH);
|
||||
canvas.toBlob((b) => resolve(b), 'image/jpeg', 0.95);
|
||||
};
|
||||
img.onerror = () => resolve(null);
|
||||
img.src = imageUrl;
|
||||
});
|
||||
};
|
||||
|
||||
onExportReady(getCroppedBlob);
|
||||
}, [crop, imageUrl, onExportReady]);
|
||||
|
||||
const isCropped = crop.x > 1 || crop.y > 1 || crop.width < 98 || crop.height < 98;
|
||||
|
||||
return (
|
||||
<div className="space-y-3.5 select-none">
|
||||
|
||||
{/* Aspect Ratio Toolbar */}
|
||||
<div className="flex flex-wrap items-center justify-between gap-2.5 p-2 rounded-2xl bg-paper-2 border border-rule">
|
||||
<div className="flex items-center gap-1.5 overflow-x-auto no-scrollbar py-0.5">
|
||||
<div className="flex items-center gap-1 px-2 text-xs font-semibold text-slate-700 shrink-0">
|
||||
<Crop className="w-3.5 h-3.5 text-accent" />
|
||||
<span className="hidden sm:inline">Aspect Ratio:</span>
|
||||
</div>
|
||||
|
||||
{RATIO_CONFIGS.map((conf) => {
|
||||
const active = selectedRatio === conf.id;
|
||||
return (
|
||||
<button
|
||||
key={conf.id}
|
||||
type="button"
|
||||
onClick={() => applyAspectRatio(conf.id)}
|
||||
className={`px-3 py-1.5 rounded-xl text-xs font-sans font-medium transition-all cursor-pointer whitespace-nowrap ${
|
||||
active
|
||||
? 'bg-slate-900 text-white shadow-xs font-semibold'
|
||||
: 'bg-white/80 hover:bg-white text-slate-700 border border-slate-200/80 hover:border-slate-300'
|
||||
}`}
|
||||
>
|
||||
{conf.label}
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
{/* Reset / Fit Full Button */}
|
||||
{isCropped && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleResetCrop}
|
||||
className="inline-flex items-center gap-1.5 px-3 py-1.5 rounded-xl text-xs font-semibold text-rose-600 bg-rose-50 hover:bg-rose-100 border border-rose-200 transition-colors cursor-pointer shrink-0 ml-auto"
|
||||
title="Reset to full image"
|
||||
>
|
||||
<RotateCcw className="w-3 h-3" />
|
||||
<span>Fit Full Image</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Interactive Cropper Stage */}
|
||||
<div
|
||||
className="relative w-full aspect-[4/3] sm:aspect-[16/10] max-h-[540px] rounded-2xl overflow-hidden bg-slate-950/90 border border-rule flex items-center justify-center p-2 sm:p-4 touch-none"
|
||||
onPointerMove={handlePointerMove}
|
||||
onPointerUp={handlePointerUp}
|
||||
>
|
||||
{/* Constrained Image Wrapper matching exact image aspect ratio */}
|
||||
<div
|
||||
ref={containerRef}
|
||||
className="relative max-w-full max-h-full overflow-hidden shadow-2xl rounded-lg"
|
||||
style={{
|
||||
touchAction: 'none',
|
||||
}}
|
||||
>
|
||||
{/* Base Image */}
|
||||
{/* eslint-disable-next-line @next/next/no-img-element */}
|
||||
<img
|
||||
ref={imgRef}
|
||||
src={imageUrl}
|
||||
alt="Source for cropping"
|
||||
onLoad={handleImageLoaded}
|
||||
draggable={false}
|
||||
className="max-h-[500px] w-auto max-w-full object-contain pointer-events-none block"
|
||||
/>
|
||||
|
||||
{/* Semi-transparent Dimmed Outer Overlays */}
|
||||
{/* Top Overlay */}
|
||||
<div
|
||||
className="absolute top-0 left-0 right-0 bg-black/60 pointer-events-none transition-all duration-75"
|
||||
style={{ height: `${crop.y}%` }}
|
||||
/>
|
||||
{/* Bottom Overlay */}
|
||||
<div
|
||||
className="absolute bottom-0 left-0 right-0 bg-black/60 pointer-events-none transition-all duration-75"
|
||||
style={{ height: `${100 - (crop.y + crop.height)}%` }}
|
||||
/>
|
||||
{/* Left Overlay */}
|
||||
<div
|
||||
className="absolute left-0 bg-black/60 pointer-events-none transition-all duration-75"
|
||||
style={{
|
||||
top: `${crop.y}%`,
|
||||
height: `${crop.height}%`,
|
||||
width: `${crop.x}%`,
|
||||
}}
|
||||
/>
|
||||
{/* Right Overlay */}
|
||||
<div
|
||||
className="absolute right-0 bg-black/60 pointer-events-none transition-all duration-75"
|
||||
style={{
|
||||
top: `${crop.y}%`,
|
||||
height: `${crop.height}%`,
|
||||
width: `${100 - (crop.x + crop.width)}%`,
|
||||
}}
|
||||
/>
|
||||
|
||||
{/* Active Crop Box */}
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'move')}
|
||||
className="absolute border border-white/90 shadow-[0_0_0_1px_rgba(0,0,0,0.6)] cursor-move transition-[border-color] hover:border-white"
|
||||
style={{
|
||||
top: `${crop.y}%`,
|
||||
left: `${crop.x}%`,
|
||||
width: `${crop.width}%`,
|
||||
height: `${crop.height}%`,
|
||||
touchAction: 'none',
|
||||
}}
|
||||
>
|
||||
{/* Rule of Thirds Grid Lines (Subtle Framing Guides) */}
|
||||
<div className="absolute inset-0 pointer-events-none grid grid-cols-3 grid-rows-3 opacity-30">
|
||||
<div className="border-r border-b border-white" />
|
||||
<div className="border-r border-b border-white" />
|
||||
<div className="border-b border-white" />
|
||||
<div className="border-r border-b border-white" />
|
||||
<div className="border-r border-b border-white" />
|
||||
<div className="border-b border-white" />
|
||||
<div className="border-r border-white" />
|
||||
<div className="border-r border-white" />
|
||||
<div />
|
||||
</div>
|
||||
|
||||
{/* Corner Resize Handles */}
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'nw')}
|
||||
className="absolute -top-2 -left-2 w-4 h-4 rounded-sm bg-white border-2 border-slate-900 shadow-md cursor-nwse-resize z-20 touch-none"
|
||||
/>
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'ne')}
|
||||
className="absolute -top-2 -right-2 w-4 h-4 rounded-sm bg-white border-2 border-slate-900 shadow-md cursor-nesw-resize z-20 touch-none"
|
||||
/>
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'se')}
|
||||
className="absolute -bottom-2 -right-2 w-4 h-4 rounded-sm bg-white border-2 border-slate-900 shadow-md cursor-nwse-resize z-20 touch-none"
|
||||
/>
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'sw')}
|
||||
className="absolute -bottom-2 -left-2 w-4 h-4 rounded-sm bg-white border-2 border-slate-900 shadow-md cursor-nesw-resize z-20 touch-none"
|
||||
/>
|
||||
|
||||
{/* Edge Midpoint Resize Handles */}
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'n')}
|
||||
className="absolute -top-1.5 left-1/2 -translate-x-1/2 w-6 h-2 rounded-full bg-white border border-slate-900 shadow-xs cursor-ns-resize z-10 touch-none"
|
||||
/>
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 's')}
|
||||
className="absolute -bottom-1.5 left-1/2 -translate-x-1/2 w-6 h-2 rounded-full bg-white border border-slate-900 shadow-xs cursor-ns-resize z-10 touch-none"
|
||||
/>
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'w')}
|
||||
className="absolute top-1/2 -left-1.5 -translate-y-1/2 w-2 h-6 rounded-full bg-white border border-slate-900 shadow-xs cursor-ew-resize z-10 touch-none"
|
||||
/>
|
||||
<div
|
||||
onPointerDown={(e) => handlePointerDown(e, 'e')}
|
||||
className="absolute top-1/2 -right-1.5 -translate-y-1/2 w-2 h-6 rounded-full bg-white border border-slate-900 shadow-xs cursor-ew-resize z-10 touch-none"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
);
|
||||
}
|
||||
@@ -131,7 +131,7 @@ export function ProcessingOverlay({
|
||||
{/* 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>Volatile GPU RAM Execution · Zero Server Storage</span>
|
||||
<span>Neural Engine Processing · Direct Stream</span>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user