2026-03-22 03:05:45 +08:00
|
|
|
import { TOOLS } from "@stirling-image/shared";
|
2026-03-25 09:27:12 +08:00
|
|
|
import * as icons from "lucide-react";
|
|
|
|
|
import { CheckCircle2, ChevronLeft, ChevronRight, Download } from "lucide-react";
|
|
|
|
|
import { useCallback, useEffect, useMemo, useState } from "react";
|
|
|
|
|
import type { Crop } from "react-image-crop";
|
|
|
|
|
import { useParams } from "react-router-dom";
|
|
|
|
|
import { BeforeAfterSlider } from "@/components/common/before-after-slider";
|
2026-03-22 03:05:45 +08:00
|
|
|
import { Dropzone } from "@/components/common/dropzone";
|
2026-03-23 19:22:53 +08:00
|
|
|
import { ImageViewer } from "@/components/common/image-viewer";
|
2026-03-22 10:47:46 +08:00
|
|
|
import { ReviewPanel } from "@/components/common/review-panel";
|
2026-03-25 09:27:12 +08:00
|
|
|
import { SideBySideComparison } from "@/components/common/side-by-side-comparison";
|
|
|
|
|
import { ThumbnailStrip } from "@/components/common/thumbnail-strip";
|
|
|
|
|
import { AppLayout } from "@/components/layout/app-layout";
|
2026-03-22 04:21:10 +08:00
|
|
|
import { BarcodeReadSettings } from "@/components/tools/barcode-read-settings";
|
2026-03-25 09:27:12 +08:00
|
|
|
import { BlurFacesSettings } from "@/components/tools/blur-faces-settings";
|
2026-03-22 04:21:10 +08:00
|
|
|
import { BorderSettings } from "@/components/tools/border-settings";
|
|
|
|
|
// Phase 3: Optimization extras
|
|
|
|
|
import { BulkRenameSettings } from "@/components/tools/bulk-rename-settings";
|
2026-03-25 09:27:12 +08:00
|
|
|
// Phase 3: Layout & Composition
|
|
|
|
|
import { CollageSettings } from "@/components/tools/collage-settings";
|
|
|
|
|
import { ColorPaletteSettings } from "@/components/tools/color-palette-settings";
|
|
|
|
|
import { ColorSettings } from "@/components/tools/color-settings";
|
|
|
|
|
import { CompareSettings } from "@/components/tools/compare-settings";
|
|
|
|
|
import { ComposeSettings } from "@/components/tools/compose-settings";
|
|
|
|
|
import { CompressSettings } from "@/components/tools/compress-settings";
|
|
|
|
|
import { ConvertSettings } from "@/components/tools/convert-settings";
|
|
|
|
|
import { CropCanvas } from "@/components/tools/crop-canvas";
|
|
|
|
|
import { CropSettings } from "@/components/tools/crop-settings";
|
|
|
|
|
import { EraseObjectSettings } from "@/components/tools/erase-object-settings";
|
2026-03-22 04:21:10 +08:00
|
|
|
import { FaviconSettings } from "@/components/tools/favicon-settings";
|
2026-03-25 09:27:12 +08:00
|
|
|
import { FindDuplicatesSettings } from "@/components/tools/find-duplicates-settings";
|
|
|
|
|
import { GifToolsSettings } from "@/components/tools/gif-tools-settings";
|
2026-03-22 04:21:10 +08:00
|
|
|
import { ImageToPdfSettings } from "@/components/tools/image-to-pdf-settings";
|
2026-03-25 09:27:12 +08:00
|
|
|
// Phase 3: Utilities
|
|
|
|
|
import { InfoSettings } from "@/components/tools/info-settings";
|
|
|
|
|
import { OcrSettings } from "@/components/tools/ocr-settings";
|
|
|
|
|
import { QrGenerateSettings } from "@/components/tools/qr-generate-settings";
|
2026-03-22 04:31:49 +08:00
|
|
|
// Phase 4: AI Tools
|
|
|
|
|
import { RemoveBgSettings } from "@/components/tools/remove-bg-settings";
|
2026-03-25 09:27:12 +08:00
|
|
|
// Phase 3: Adjustments extra
|
|
|
|
|
import { ReplaceColorSettings } from "@/components/tools/replace-color-settings";
|
|
|
|
|
import { ResizeSettings } from "@/components/tools/resize-settings";
|
|
|
|
|
import type { PreviewTransform } from "@/components/tools/rotate-settings";
|
|
|
|
|
import { RotateSettings } from "@/components/tools/rotate-settings";
|
2026-03-22 04:31:49 +08:00
|
|
|
import { SmartCropSettings } from "@/components/tools/smart-crop-settings";
|
2026-03-25 09:27:12 +08:00
|
|
|
import { SplitSettings } from "@/components/tools/split-settings";
|
|
|
|
|
import { StripMetadataSettings } from "@/components/tools/strip-metadata-settings";
|
|
|
|
|
// Phase 3: Format & Conversion
|
|
|
|
|
import { SvgToRasterSettings } from "@/components/tools/svg-to-raster-settings";
|
|
|
|
|
import { TextOverlaySettings } from "@/components/tools/text-overlay-settings";
|
|
|
|
|
import { UpscaleSettings } from "@/components/tools/upscale-settings";
|
|
|
|
|
import { VectorizeSettings } from "@/components/tools/vectorize-settings";
|
|
|
|
|
import { WatermarkImageSettings } from "@/components/tools/watermark-image-settings";
|
|
|
|
|
// Phase 3: Watermark & Overlay
|
|
|
|
|
import { WatermarkTextSettings } from "@/components/tools/watermark-text-settings";
|
|
|
|
|
import { useMobile } from "@/hooks/use-mobile";
|
|
|
|
|
import { formatFileSize } from "@/lib/download";
|
|
|
|
|
import { useFileStore } from "@/stores/file-store";
|
2026-03-22 03:05:45 +08:00
|
|
|
|
2026-03-22 03:56:44 +08:00
|
|
|
const COLOR_TOOL_IDS = new Set([
|
|
|
|
|
"brightness-contrast",
|
|
|
|
|
"saturation",
|
|
|
|
|
"color-channels",
|
|
|
|
|
"color-effects",
|
|
|
|
|
]);
|
|
|
|
|
|
2026-03-22 04:21:10 +08:00
|
|
|
// Tools that don't need a file dropzone (they generate content or have custom UI)
|
|
|
|
|
const NO_DROPZONE_TOOLS = new Set(["qr-generate"]);
|
2026-03-24 00:41:54 +08:00
|
|
|
const SIDE_BY_SIDE_TOOLS = new Set(["resize", "crop", "rotate"]);
|
2026-03-23 12:53:18 +08:00
|
|
|
const LIVE_PREVIEW_TOOLS = new Set(["rotate"]);
|
2026-03-24 00:41:54 +08:00
|
|
|
const NO_COMPARISON_TOOLS = new Set(["strip-metadata", "convert"]);
|
2026-03-23 19:22:53 +08:00
|
|
|
const INTERACTIVE_CROP_TOOLS = new Set(["crop"]);
|
2026-03-22 04:21:10 +08:00
|
|
|
|
2026-03-23 12:53:18 +08:00
|
|
|
function ToolSettingsPanel({
|
|
|
|
|
toolId,
|
|
|
|
|
onPreviewTransform,
|
2026-03-23 19:22:53 +08:00
|
|
|
cropProps,
|
2026-03-23 12:53:18 +08:00
|
|
|
}: {
|
|
|
|
|
toolId: string;
|
|
|
|
|
onPreviewTransform?: (t: PreviewTransform) => void;
|
2026-03-23 19:22:53 +08:00
|
|
|
cropProps?: {
|
|
|
|
|
cropState: {
|
|
|
|
|
crop: Crop;
|
|
|
|
|
aspect: number | undefined;
|
|
|
|
|
showGrid: boolean;
|
|
|
|
|
imgDimensions: { width: number; height: number } | null;
|
|
|
|
|
};
|
|
|
|
|
onCropChange: (crop: Crop) => void;
|
|
|
|
|
onAspectChange: (aspect: number | undefined) => void;
|
|
|
|
|
onGridToggle: (show: boolean) => void;
|
|
|
|
|
};
|
2026-03-23 12:53:18 +08:00
|
|
|
}) {
|
2026-03-22 04:21:10 +08:00
|
|
|
// Phase 2: Core tools
|
2026-03-22 03:56:44 +08:00
|
|
|
if (toolId === "resize") return <ResizeSettings />;
|
2026-03-23 19:22:53 +08:00
|
|
|
if (toolId === "crop" && cropProps) return <CropSettings {...cropProps} />;
|
2026-03-23 12:53:18 +08:00
|
|
|
if (toolId === "rotate") return <RotateSettings onPreviewTransform={onPreviewTransform} />;
|
2026-03-22 03:56:44 +08:00
|
|
|
if (toolId === "convert") return <ConvertSettings />;
|
|
|
|
|
if (toolId === "compress") return <CompressSettings />;
|
|
|
|
|
if (toolId === "strip-metadata") return <StripMetadataSettings />;
|
|
|
|
|
if (COLOR_TOOL_IDS.has(toolId)) return <ColorSettings toolId={toolId} />;
|
2026-03-22 04:21:10 +08:00
|
|
|
// Phase 3: Watermark & Overlay
|
|
|
|
|
if (toolId === "watermark-text") return <WatermarkTextSettings />;
|
|
|
|
|
if (toolId === "watermark-image") return <WatermarkImageSettings />;
|
|
|
|
|
if (toolId === "text-overlay") return <TextOverlaySettings />;
|
|
|
|
|
if (toolId === "compose") return <ComposeSettings />;
|
|
|
|
|
// Phase 3: Utilities
|
|
|
|
|
if (toolId === "info") return <InfoSettings />;
|
|
|
|
|
if (toolId === "compare") return <CompareSettings />;
|
|
|
|
|
if (toolId === "find-duplicates") return <FindDuplicatesSettings />;
|
|
|
|
|
if (toolId === "color-palette") return <ColorPaletteSettings />;
|
|
|
|
|
if (toolId === "qr-generate") return <QrGenerateSettings />;
|
|
|
|
|
if (toolId === "barcode-read") return <BarcodeReadSettings />;
|
|
|
|
|
// Phase 3: Layout & Composition
|
|
|
|
|
if (toolId === "collage") return <CollageSettings />;
|
|
|
|
|
if (toolId === "split") return <SplitSettings />;
|
|
|
|
|
if (toolId === "border") return <BorderSettings />;
|
|
|
|
|
// Phase 3: Format & Conversion
|
|
|
|
|
if (toolId === "svg-to-raster") return <SvgToRasterSettings />;
|
|
|
|
|
if (toolId === "vectorize") return <VectorizeSettings />;
|
|
|
|
|
if (toolId === "gif-tools") return <GifToolsSettings />;
|
|
|
|
|
// Phase 3: Optimization extras
|
|
|
|
|
if (toolId === "bulk-rename") return <BulkRenameSettings />;
|
|
|
|
|
if (toolId === "favicon") return <FaviconSettings />;
|
|
|
|
|
if (toolId === "image-to-pdf") return <ImageToPdfSettings />;
|
|
|
|
|
// Phase 3: Adjustments extra
|
|
|
|
|
if (toolId === "replace-color") return <ReplaceColorSettings />;
|
2026-03-22 04:31:49 +08:00
|
|
|
// Phase 4: AI Tools
|
|
|
|
|
if (toolId === "remove-background") return <RemoveBgSettings />;
|
|
|
|
|
if (toolId === "upscale") return <UpscaleSettings />;
|
|
|
|
|
if (toolId === "ocr") return <OcrSettings />;
|
|
|
|
|
if (toolId === "blur-faces") return <BlurFacesSettings />;
|
|
|
|
|
if (toolId === "erase-object") return <EraseObjectSettings />;
|
|
|
|
|
if (toolId === "smart-crop") return <SmartCropSettings />;
|
2026-03-22 03:56:44 +08:00
|
|
|
|
|
|
|
|
return (
|
2026-03-25 09:27:12 +08:00
|
|
|
<p className="text-xs text-muted-foreground italic">Settings for this tool are coming soon.</p>
|
2026-03-22 03:56:44 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 10:47:46 +08:00
|
|
|
/** File selection indicator shown in left panel */
|
|
|
|
|
function FileSelectionInfo({
|
|
|
|
|
files,
|
|
|
|
|
selectedFileName,
|
|
|
|
|
selectedFileSize,
|
|
|
|
|
onClear,
|
2026-03-23 14:07:28 +08:00
|
|
|
onAddMore,
|
2026-03-22 10:47:46 +08:00
|
|
|
}: {
|
|
|
|
|
files: File[];
|
|
|
|
|
selectedFileName: string | null;
|
|
|
|
|
selectedFileSize: number | null;
|
|
|
|
|
onClear: () => void;
|
2026-03-23 14:07:28 +08:00
|
|
|
onAddMore: () => void;
|
2026-03-22 10:47:46 +08:00
|
|
|
}) {
|
|
|
|
|
if (files.length === 0) {
|
|
|
|
|
return (
|
2026-03-25 09:27:12 +08:00
|
|
|
<p className="text-xs text-muted-foreground italic">Drop or upload an image to get started</p>
|
2026-03-22 10:47:46 +08:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-1">
|
2026-03-23 14:07:28 +08:00
|
|
|
<div className="flex items-center justify-between">
|
|
|
|
|
<span className="text-xs font-medium text-foreground">Files ({files.length})</span>
|
2026-03-25 09:27:12 +08:00
|
|
|
<button onClick={onAddMore} className="text-xs text-primary hover:text-primary/80">
|
|
|
|
|
+ Add more
|
|
|
|
|
</button>
|
2026-03-23 14:07:28 +08:00
|
|
|
</div>
|
2026-03-22 10:47:46 +08:00
|
|
|
<div className="flex items-center gap-1.5 text-xs text-foreground bg-muted rounded px-2 py-1.5">
|
|
|
|
|
<CheckCircle2 className="h-3.5 w-3.5 text-green-500 shrink-0" />
|
2026-03-23 14:07:28 +08:00
|
|
|
<span className="truncate flex-1">{selectedFileName ?? files[0].name}</span>
|
2026-03-25 09:27:12 +08:00
|
|
|
<span className="text-muted-foreground shrink-0 ml-1">
|
|
|
|
|
{formatFileSize(selectedFileSize ?? files[0].size)}
|
|
|
|
|
</span>
|
2026-03-22 10:47:46 +08:00
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
<button onClick={onClear} className="text-xs text-muted-foreground hover:text-foreground">
|
|
|
|
|
Clear all
|
|
|
|
|
</button>
|
2026-03-22 10:47:46 +08:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 03:05:45 +08:00
|
|
|
export function ToolPage() {
|
|
|
|
|
const { toolId } = useParams<{ toolId: string }>();
|
|
|
|
|
const tool = useMemo(() => TOOLS.find((t) => t.id === toolId), [toolId]);
|
2026-03-22 10:47:46 +08:00
|
|
|
const {
|
|
|
|
|
files,
|
2026-03-23 14:07:28 +08:00
|
|
|
entries,
|
2026-03-22 10:47:46 +08:00
|
|
|
setFiles,
|
2026-03-23 14:07:28 +08:00
|
|
|
addFiles,
|
2026-03-22 10:47:46 +08:00
|
|
|
reset,
|
|
|
|
|
processedUrl,
|
|
|
|
|
originalBlobUrl,
|
|
|
|
|
originalSize,
|
|
|
|
|
processedSize,
|
|
|
|
|
selectedFileName,
|
|
|
|
|
selectedFileSize,
|
|
|
|
|
undoProcessing,
|
2026-03-23 14:07:28 +08:00
|
|
|
batchZipBlob,
|
|
|
|
|
batchZipFilename,
|
2026-03-24 00:41:54 +08:00
|
|
|
selectedIndex,
|
|
|
|
|
setSelectedIndex,
|
|
|
|
|
navigateNext,
|
|
|
|
|
navigatePrev,
|
2026-03-22 10:47:46 +08:00
|
|
|
} = useFileStore();
|
2026-03-22 04:42:31 +08:00
|
|
|
const isMobile = useMobile();
|
2026-03-24 00:41:54 +08:00
|
|
|
const hasMultiple = entries.length > 1;
|
|
|
|
|
const hasPrev = selectedIndex > 0;
|
|
|
|
|
const hasNext = selectedIndex < entries.length - 1;
|
|
|
|
|
|
2026-03-25 09:27:12 +08:00
|
|
|
const handleImageKeyDown = useCallback(
|
|
|
|
|
(e: React.KeyboardEvent) => {
|
|
|
|
|
if (e.key === "ArrowLeft") {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
navigatePrev();
|
|
|
|
|
} else if (e.key === "ArrowRight") {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
navigateNext();
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
[navigateNext, navigatePrev],
|
|
|
|
|
);
|
2026-03-22 04:42:31 +08:00
|
|
|
const [mobileSettingsOpen, setMobileSettingsOpen] = useState(true);
|
2026-03-23 12:53:18 +08:00
|
|
|
const [previewTransform, setPreviewTransform] = useState<PreviewTransform | null>(null);
|
2026-03-22 03:56:44 +08:00
|
|
|
|
2026-03-23 19:22:53 +08:00
|
|
|
const [cropCrop, setCropCrop] = useState<Crop>({
|
|
|
|
|
unit: "%",
|
|
|
|
|
x: 0,
|
|
|
|
|
y: 0,
|
|
|
|
|
width: 100,
|
|
|
|
|
height: 100,
|
|
|
|
|
});
|
|
|
|
|
const [cropAspect, setCropAspect] = useState<number | undefined>(undefined);
|
|
|
|
|
const [cropShowGrid, setCropShowGrid] = useState(true);
|
|
|
|
|
const [cropImgDimensions, setCropImgDimensions] = useState<{
|
|
|
|
|
width: number;
|
|
|
|
|
height: number;
|
|
|
|
|
} | null>(null);
|
|
|
|
|
|
|
|
|
|
const cropState = useMemo(
|
|
|
|
|
() => ({
|
|
|
|
|
crop: cropCrop,
|
|
|
|
|
aspect: cropAspect,
|
|
|
|
|
showGrid: cropShowGrid,
|
|
|
|
|
imgDimensions: cropImgDimensions,
|
|
|
|
|
}),
|
|
|
|
|
[cropCrop, cropAspect, cropShowGrid, cropImgDimensions],
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// Reset crop state when the image changes
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setCropCrop({ unit: "%", x: 0, y: 0, width: 100, height: 100 });
|
|
|
|
|
setCropImgDimensions(null);
|
2026-03-25 09:27:12 +08:00
|
|
|
}, []);
|
2026-03-23 19:22:53 +08:00
|
|
|
|
2026-03-22 03:56:44 +08:00
|
|
|
const handleFiles = useCallback(
|
|
|
|
|
(newFiles: File[]) => {
|
|
|
|
|
reset();
|
|
|
|
|
setFiles(newFiles);
|
|
|
|
|
},
|
|
|
|
|
[setFiles, reset],
|
|
|
|
|
);
|
2026-03-22 03:05:45 +08:00
|
|
|
|
2026-03-22 10:47:46 +08:00
|
|
|
const handleUndo = useCallback(() => {
|
|
|
|
|
undoProcessing();
|
|
|
|
|
}, [undoProcessing]);
|
|
|
|
|
|
2026-03-23 14:07:28 +08:00
|
|
|
const handleAddMore = useCallback(() => {
|
|
|
|
|
const input = document.createElement("input");
|
|
|
|
|
input.type = "file";
|
|
|
|
|
input.multiple = true;
|
|
|
|
|
input.accept = "image/*";
|
|
|
|
|
input.onchange = (e) => {
|
|
|
|
|
const newFiles = Array.from((e.target as HTMLInputElement).files || []);
|
|
|
|
|
if (newFiles.length > 0) addFiles(newFiles);
|
|
|
|
|
};
|
|
|
|
|
input.click();
|
|
|
|
|
}, [addFiles]);
|
|
|
|
|
|
|
|
|
|
const handleDownloadAll = useCallback(() => {
|
|
|
|
|
if (!batchZipBlob) return;
|
|
|
|
|
const url = URL.createObjectURL(batchZipBlob);
|
|
|
|
|
const a = document.createElement("a");
|
|
|
|
|
a.href = url;
|
|
|
|
|
a.download = batchZipFilename ?? "processed-images.zip";
|
|
|
|
|
a.click();
|
|
|
|
|
URL.revokeObjectURL(url);
|
|
|
|
|
}, [batchZipBlob, batchZipFilename]);
|
|
|
|
|
|
2026-03-22 03:05:45 +08:00
|
|
|
if (!tool) {
|
|
|
|
|
return (
|
|
|
|
|
<AppLayout>
|
|
|
|
|
<div className="flex items-center justify-center h-full text-muted-foreground">
|
|
|
|
|
Tool not found
|
|
|
|
|
</div>
|
|
|
|
|
</AppLayout>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-03-22 03:56:44 +08:00
|
|
|
const IconComponent =
|
2026-03-25 09:27:12 +08:00
|
|
|
(icons as unknown as Record<string, React.ComponentType<{ className?: string }>>)[tool.icon] ||
|
|
|
|
|
icons.FileImage;
|
2026-03-22 03:56:44 +08:00
|
|
|
|
|
|
|
|
const hasFile = files.length > 0;
|
2026-03-22 10:47:46 +08:00
|
|
|
const hasProcessed = !!processedUrl;
|
2026-03-22 04:21:10 +08:00
|
|
|
const isNoDropzone = NO_DROPZONE_TOOLS.has(tool.id);
|
2026-03-22 03:05:45 +08:00
|
|
|
|
2026-03-22 10:47:46 +08:00
|
|
|
// Derive processed file info from context
|
2026-03-25 09:27:12 +08:00
|
|
|
const processedFileName = selectedFileName ? `processed-${selectedFileName}` : "processed-image";
|
2026-03-22 10:47:46 +08:00
|
|
|
const processedFileType = selectedFileName
|
|
|
|
|
? selectedFileName.split(".").pop()?.toUpperCase() || "IMAGE"
|
|
|
|
|
: "IMAGE";
|
|
|
|
|
|
2026-03-22 04:42:31 +08:00
|
|
|
// Mobile layout: settings above dropzone (stacked)
|
|
|
|
|
if (isMobile) {
|
|
|
|
|
return (
|
|
|
|
|
<AppLayout showToolPanel={false}>
|
|
|
|
|
<div className="flex flex-col w-full h-full">
|
|
|
|
|
{/* Tool header */}
|
|
|
|
|
<div className="flex items-center gap-3 p-4 border-b border-border shrink-0">
|
|
|
|
|
<div className="p-2 rounded-lg bg-primary text-primary-foreground">
|
|
|
|
|
<IconComponent className="h-5 w-5" />
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
<h2 className="font-semibold text-lg text-foreground flex-1">{tool.name}</h2>
|
2026-03-22 04:42:31 +08:00
|
|
|
<button
|
|
|
|
|
onClick={() => setMobileSettingsOpen(!mobileSettingsOpen)}
|
|
|
|
|
className="px-3 py-1.5 rounded-lg border border-border text-xs text-muted-foreground hover:bg-muted"
|
|
|
|
|
>
|
|
|
|
|
{mobileSettingsOpen ? "Hide Settings" : "Settings"}
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Collapsible settings */}
|
|
|
|
|
{mobileSettingsOpen && (
|
|
|
|
|
<div className="p-4 border-b border-border space-y-3 shrink-0 max-h-[40vh] overflow-y-auto">
|
|
|
|
|
{/* File info */}
|
2026-03-22 10:47:46 +08:00
|
|
|
{!isNoDropzone && (
|
|
|
|
|
<div className="space-y-2">
|
2026-03-25 09:27:12 +08:00
|
|
|
<h3 className="text-sm font-medium text-muted-foreground">Files</h3>
|
2026-03-22 10:47:46 +08:00
|
|
|
<FileSelectionInfo
|
|
|
|
|
files={files}
|
|
|
|
|
selectedFileName={selectedFileName}
|
|
|
|
|
selectedFileSize={selectedFileSize}
|
|
|
|
|
onClear={reset}
|
2026-03-23 14:07:28 +08:00
|
|
|
onAddMore={handleAddMore}
|
2026-03-22 10:47:46 +08:00
|
|
|
/>
|
2026-03-22 04:42:31 +08:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-22 10:47:46 +08:00
|
|
|
|
|
|
|
|
<div className="border-t border-border" />
|
|
|
|
|
|
|
|
|
|
<div className="space-y-2">
|
2026-03-25 09:27:12 +08:00
|
|
|
<h3 className="text-sm font-medium text-muted-foreground">Settings</h3>
|
2026-03-23 12:53:18 +08:00
|
|
|
<ToolSettingsPanel
|
|
|
|
|
toolId={tool.id}
|
2026-03-25 09:27:12 +08:00
|
|
|
onPreviewTransform={
|
|
|
|
|
LIVE_PREVIEW_TOOLS.has(tool.id) ? setPreviewTransform : undefined
|
|
|
|
|
}
|
|
|
|
|
cropProps={
|
|
|
|
|
INTERACTIVE_CROP_TOOLS.has(tool.id)
|
|
|
|
|
? {
|
|
|
|
|
cropState,
|
|
|
|
|
onCropChange: setCropCrop,
|
|
|
|
|
onAspectChange: setCropAspect,
|
|
|
|
|
onGridToggle: setCropShowGrid,
|
|
|
|
|
}
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
2026-03-23 12:53:18 +08:00
|
|
|
/>
|
2026-03-22 10:47:46 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{/* Review panel (mobile) */}
|
|
|
|
|
{hasProcessed && processedSize != null && (
|
|
|
|
|
<ReviewPanel
|
|
|
|
|
filename={processedFileName}
|
|
|
|
|
fileSize={processedSize}
|
|
|
|
|
fileType={processedFileType}
|
|
|
|
|
downloadUrl={processedUrl}
|
|
|
|
|
previewUrl={processedUrl}
|
|
|
|
|
onUndo={handleUndo}
|
|
|
|
|
currentToolId={tool.id}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-03-22 04:42:31 +08:00
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-03-23 19:22:53 +08:00
|
|
|
{/* Main area: Dropzone / Image Viewer / Before-After */}
|
2026-03-25 09:27:12 +08:00
|
|
|
<div
|
|
|
|
|
className="flex-1 flex flex-col min-h-0"
|
|
|
|
|
onKeyDown={hasMultiple ? handleImageKeyDown : undefined}
|
|
|
|
|
tabIndex={hasMultiple ? 0 : undefined}
|
|
|
|
|
>
|
2026-03-24 00:41:54 +08:00
|
|
|
<div className="flex-1 relative flex items-center justify-center p-4 min-h-0">
|
|
|
|
|
{hasMultiple && hasPrev && (
|
2026-03-25 09:27:12 +08:00
|
|
|
<button
|
|
|
|
|
onClick={navigatePrev}
|
|
|
|
|
className="absolute left-3 z-10 w-8 h-8 rounded-full bg-background/80 border border-border shadow-sm flex items-center justify-center hover:bg-background transition-colors"
|
|
|
|
|
aria-label="Previous image"
|
|
|
|
|
>
|
2026-03-24 00:41:54 +08:00
|
|
|
<ChevronLeft className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{isNoDropzone ? (
|
|
|
|
|
<div className="text-center text-muted-foreground">
|
|
|
|
|
<p className="text-sm">Configure settings and generate.</p>
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
) : INTERACTIVE_CROP_TOOLS.has(tool.id) &&
|
|
|
|
|
hasFile &&
|
|
|
|
|
!hasProcessed &&
|
|
|
|
|
originalBlobUrl ? (
|
2026-03-24 00:41:54 +08:00
|
|
|
<CropCanvas
|
|
|
|
|
imageSrc={originalBlobUrl}
|
|
|
|
|
crop={cropCrop}
|
|
|
|
|
aspect={cropAspect}
|
|
|
|
|
showGrid={cropShowGrid}
|
|
|
|
|
imgDimensions={cropImgDimensions}
|
|
|
|
|
onCropChange={setCropCrop}
|
|
|
|
|
onImageLoad={setCropImgDimensions}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl && SIDE_BY_SIDE_TOOLS.has(tool.id) ? (
|
|
|
|
|
<SideBySideComparison
|
|
|
|
|
beforeSrc={originalBlobUrl}
|
|
|
|
|
afterSrc={processedUrl}
|
|
|
|
|
beforeSize={originalSize ?? undefined}
|
|
|
|
|
afterSize={processedSize ?? undefined}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl && LIVE_PREVIEW_TOOLS.has(tool.id) ? (
|
|
|
|
|
<ImageViewer
|
|
|
|
|
src={processedUrl}
|
|
|
|
|
filename={processedFileName}
|
|
|
|
|
fileSize={processedSize ?? 0}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl && NO_COMPARISON_TOOLS.has(tool.id) ? (
|
|
|
|
|
<ImageViewer
|
|
|
|
|
src={processedUrl}
|
|
|
|
|
filename={processedFileName}
|
|
|
|
|
fileSize={processedSize ?? 0}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl ? (
|
|
|
|
|
<BeforeAfterSlider
|
|
|
|
|
beforeSrc={originalBlobUrl}
|
|
|
|
|
afterSrc={processedUrl}
|
|
|
|
|
beforeSize={originalSize ?? undefined}
|
|
|
|
|
afterSize={processedSize ?? undefined}
|
|
|
|
|
/>
|
|
|
|
|
) : hasFile && originalBlobUrl ? (
|
|
|
|
|
<ImageViewer
|
|
|
|
|
src={originalBlobUrl}
|
|
|
|
|
filename={selectedFileName ?? files[0].name}
|
|
|
|
|
fileSize={selectedFileSize ?? files[0].size}
|
|
|
|
|
{...(LIVE_PREVIEW_TOOLS.has(tool.id) && previewTransform
|
|
|
|
|
? {
|
|
|
|
|
cssRotate: previewTransform.rotate,
|
|
|
|
|
cssFlipH: previewTransform.flipH,
|
|
|
|
|
cssFlipV: previewTransform.flipV,
|
|
|
|
|
}
|
|
|
|
|
: {})}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
2026-03-25 09:27:12 +08:00
|
|
|
<Dropzone onFiles={handleFiles} accept="image/*" multiple currentFiles={files} />
|
2026-03-24 00:41:54 +08:00
|
|
|
)}
|
|
|
|
|
{hasMultiple && hasNext && (
|
2026-03-25 09:27:12 +08:00
|
|
|
<button
|
|
|
|
|
onClick={navigateNext}
|
|
|
|
|
className="absolute right-3 z-10 w-8 h-8 rounded-full bg-background/80 border border-border shadow-sm flex items-center justify-center hover:bg-background transition-colors"
|
|
|
|
|
aria-label="Next image"
|
|
|
|
|
>
|
2026-03-24 00:41:54 +08:00
|
|
|
<ChevronRight className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{hasMultiple && (
|
|
|
|
|
<div className="absolute top-3 right-3 z-10 bg-background/80 border border-border px-2 py-0.5 rounded-full text-xs text-muted-foreground tabular-nums">
|
|
|
|
|
{selectedIndex + 1} / {entries.length}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{hasMultiple && (
|
2026-03-25 09:27:12 +08:00
|
|
|
<ThumbnailStrip
|
|
|
|
|
entries={entries}
|
|
|
|
|
selectedIndex={selectedIndex}
|
|
|
|
|
onSelect={setSelectedIndex}
|
|
|
|
|
/>
|
2026-03-22 04:42:31 +08:00
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</AppLayout>
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Desktop layout: side-by-side
|
2026-03-22 03:05:45 +08:00
|
|
|
return (
|
|
|
|
|
<AppLayout showToolPanel={false}>
|
|
|
|
|
<div className="flex h-full w-full">
|
|
|
|
|
{/* Tool Settings Panel */}
|
|
|
|
|
<div className="w-72 border-r border-border p-4 space-y-4 overflow-y-auto shrink-0">
|
|
|
|
|
<div className="flex items-center gap-3">
|
|
|
|
|
<div className="p-2 rounded-lg bg-primary text-primary-foreground">
|
|
|
|
|
<IconComponent className="h-5 w-5" />
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
<h2 className="font-semibold text-lg text-foreground">{tool.name}</h2>
|
2026-03-22 03:05:45 +08:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-22 04:21:10 +08:00
|
|
|
{/* File info - hidden for tools that don't need files */}
|
|
|
|
|
{!isNoDropzone && (
|
|
|
|
|
<div className="space-y-2">
|
2026-03-25 09:27:12 +08:00
|
|
|
<h3 className="text-sm font-medium text-muted-foreground">Files</h3>
|
2026-03-22 10:47:46 +08:00
|
|
|
<FileSelectionInfo
|
|
|
|
|
files={files}
|
|
|
|
|
selectedFileName={selectedFileName}
|
|
|
|
|
selectedFileSize={selectedFileSize}
|
|
|
|
|
onClear={reset}
|
2026-03-23 14:07:28 +08:00
|
|
|
onAddMore={handleAddMore}
|
2026-03-22 10:47:46 +08:00
|
|
|
/>
|
2026-03-22 04:21:10 +08:00
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-22 03:05:45 +08:00
|
|
|
|
|
|
|
|
<div className="border-t border-border" />
|
|
|
|
|
|
2026-03-22 03:56:44 +08:00
|
|
|
{/* Tool-specific settings */}
|
2026-03-22 03:05:45 +08:00
|
|
|
<div className="space-y-2">
|
2026-03-25 09:27:12 +08:00
|
|
|
<h3 className="text-sm font-medium text-muted-foreground">Settings</h3>
|
2026-03-23 12:53:18 +08:00
|
|
|
<ToolSettingsPanel
|
|
|
|
|
toolId={tool.id}
|
|
|
|
|
onPreviewTransform={LIVE_PREVIEW_TOOLS.has(tool.id) ? setPreviewTransform : undefined}
|
2026-03-25 09:27:12 +08:00
|
|
|
cropProps={
|
|
|
|
|
INTERACTIVE_CROP_TOOLS.has(tool.id)
|
|
|
|
|
? {
|
|
|
|
|
cropState,
|
|
|
|
|
onCropChange: setCropCrop,
|
|
|
|
|
onAspectChange: setCropAspect,
|
|
|
|
|
onGridToggle: setCropShowGrid,
|
|
|
|
|
}
|
|
|
|
|
: undefined
|
|
|
|
|
}
|
2026-03-23 12:53:18 +08:00
|
|
|
/>
|
2026-03-22 03:05:45 +08:00
|
|
|
</div>
|
2026-03-22 10:47:46 +08:00
|
|
|
|
|
|
|
|
{/* Review panel (desktop - below settings) */}
|
|
|
|
|
{hasProcessed && processedSize != null && (
|
|
|
|
|
<ReviewPanel
|
|
|
|
|
filename={processedFileName}
|
|
|
|
|
fileSize={processedSize}
|
|
|
|
|
fileType={processedFileType}
|
|
|
|
|
downloadUrl={processedUrl}
|
|
|
|
|
previewUrl={processedUrl}
|
|
|
|
|
onUndo={handleUndo}
|
|
|
|
|
currentToolId={tool.id}
|
|
|
|
|
/>
|
|
|
|
|
)}
|
2026-03-23 14:07:28 +08:00
|
|
|
|
|
|
|
|
{/* Batch download */}
|
|
|
|
|
{entries.length > 1 && hasProcessed && batchZipBlob && (
|
|
|
|
|
<div className="space-y-2">
|
|
|
|
|
<div className="border-t border-border pt-2" />
|
|
|
|
|
<button
|
|
|
|
|
onClick={handleDownloadAll}
|
|
|
|
|
className="w-full py-2 rounded-lg bg-primary text-primary-foreground flex items-center justify-center gap-1.5 text-xs font-medium hover:bg-primary/90"
|
|
|
|
|
>
|
|
|
|
|
<Download className="h-3.5 w-3.5" />
|
|
|
|
|
Download All (ZIP)
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2026-03-22 03:05:45 +08:00
|
|
|
</div>
|
|
|
|
|
|
2026-03-23 19:22:53 +08:00
|
|
|
{/* Main area: Dropzone / Image Viewer / Before-After */}
|
2026-03-25 09:27:12 +08:00
|
|
|
<div
|
|
|
|
|
className="flex-1 flex flex-col min-h-0"
|
|
|
|
|
onKeyDown={hasMultiple ? handleImageKeyDown : undefined}
|
|
|
|
|
tabIndex={hasMultiple ? 0 : undefined}
|
|
|
|
|
>
|
2026-03-24 00:41:54 +08:00
|
|
|
<div className="flex-1 relative flex items-center justify-center p-6 min-h-0">
|
|
|
|
|
{hasMultiple && hasPrev && (
|
2026-03-25 09:27:12 +08:00
|
|
|
<button
|
|
|
|
|
onClick={navigatePrev}
|
|
|
|
|
className="absolute left-3 z-10 w-8 h-8 rounded-full bg-background/80 border border-border shadow-sm flex items-center justify-center hover:bg-background transition-colors"
|
|
|
|
|
aria-label="Previous image"
|
|
|
|
|
>
|
2026-03-24 00:41:54 +08:00
|
|
|
<ChevronLeft className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{isNoDropzone ? (
|
|
|
|
|
<div className="text-center text-muted-foreground">
|
|
|
|
|
<p className="text-sm">Configure settings and generate.</p>
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
) : INTERACTIVE_CROP_TOOLS.has(tool.id) &&
|
|
|
|
|
hasFile &&
|
|
|
|
|
!hasProcessed &&
|
|
|
|
|
originalBlobUrl ? (
|
2026-03-24 00:41:54 +08:00
|
|
|
<CropCanvas
|
|
|
|
|
imageSrc={originalBlobUrl}
|
|
|
|
|
crop={cropCrop}
|
|
|
|
|
aspect={cropAspect}
|
|
|
|
|
showGrid={cropShowGrid}
|
|
|
|
|
imgDimensions={cropImgDimensions}
|
|
|
|
|
onCropChange={setCropCrop}
|
|
|
|
|
onImageLoad={setCropImgDimensions}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl && SIDE_BY_SIDE_TOOLS.has(tool.id) ? (
|
|
|
|
|
<SideBySideComparison
|
|
|
|
|
beforeSrc={originalBlobUrl}
|
|
|
|
|
afterSrc={processedUrl}
|
|
|
|
|
beforeSize={originalSize ?? undefined}
|
|
|
|
|
afterSize={processedSize ?? undefined}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl && LIVE_PREVIEW_TOOLS.has(tool.id) ? (
|
|
|
|
|
<ImageViewer
|
|
|
|
|
src={processedUrl}
|
|
|
|
|
filename={processedFileName}
|
|
|
|
|
fileSize={processedSize ?? 0}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl && NO_COMPARISON_TOOLS.has(tool.id) ? (
|
|
|
|
|
<ImageViewer
|
|
|
|
|
src={processedUrl}
|
|
|
|
|
filename={processedFileName}
|
|
|
|
|
fileSize={processedSize ?? 0}
|
|
|
|
|
/>
|
|
|
|
|
) : hasProcessed && originalBlobUrl ? (
|
|
|
|
|
<BeforeAfterSlider
|
|
|
|
|
beforeSrc={originalBlobUrl}
|
|
|
|
|
afterSrc={processedUrl}
|
|
|
|
|
beforeSize={originalSize ?? undefined}
|
|
|
|
|
afterSize={processedSize ?? undefined}
|
|
|
|
|
/>
|
|
|
|
|
) : hasFile && originalBlobUrl ? (
|
|
|
|
|
<ImageViewer
|
|
|
|
|
src={originalBlobUrl}
|
|
|
|
|
filename={selectedFileName ?? files[0].name}
|
|
|
|
|
fileSize={selectedFileSize ?? files[0].size}
|
|
|
|
|
{...(LIVE_PREVIEW_TOOLS.has(tool.id) && previewTransform
|
|
|
|
|
? {
|
|
|
|
|
cssRotate: previewTransform.rotate,
|
|
|
|
|
cssFlipH: previewTransform.flipH,
|
|
|
|
|
cssFlipV: previewTransform.flipV,
|
|
|
|
|
}
|
|
|
|
|
: {})}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
2026-03-25 09:27:12 +08:00
|
|
|
<Dropzone onFiles={handleFiles} accept="image/*" multiple currentFiles={files} />
|
2026-03-24 00:41:54 +08:00
|
|
|
)}
|
|
|
|
|
{hasMultiple && hasNext && (
|
2026-03-25 09:27:12 +08:00
|
|
|
<button
|
|
|
|
|
onClick={navigateNext}
|
|
|
|
|
className="absolute right-3 z-10 w-8 h-8 rounded-full bg-background/80 border border-border shadow-sm flex items-center justify-center hover:bg-background transition-colors"
|
|
|
|
|
aria-label="Next image"
|
|
|
|
|
>
|
2026-03-24 00:41:54 +08:00
|
|
|
<ChevronRight className="h-4 w-4" />
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
{hasMultiple && (
|
|
|
|
|
<div className="absolute top-3 right-3 z-10 bg-background/80 border border-border px-2 py-0.5 rounded-full text-xs text-muted-foreground tabular-nums">
|
|
|
|
|
{selectedIndex + 1} / {entries.length}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
{hasMultiple && (
|
2026-03-25 09:27:12 +08:00
|
|
|
<ThumbnailStrip
|
|
|
|
|
entries={entries}
|
|
|
|
|
selectedIndex={selectedIndex}
|
|
|
|
|
onSelect={setSelectedIndex}
|
|
|
|
|
/>
|
2026-03-22 04:03:30 +08:00
|
|
|
)}
|
2026-03-22 03:05:45 +08:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</AppLayout>
|
|
|
|
|
);
|
|
|
|
|
}
|