2026-03-23 01:45:58 +08:00
|
|
|
import { Download } from "lucide-react";
|
2026-03-25 09:27:12 +08:00
|
|
|
import { useState } from "react";
|
2026-03-23 01:45:58 +08:00
|
|
|
import { ProgressCard } from "@/components/common/progress-card";
|
2026-03-25 09:27:12 +08:00
|
|
|
import { useToolProcessor } from "@/hooks/use-tool-processor";
|
|
|
|
|
import { useFileStore } from "@/stores/file-store";
|
2026-03-22 04:20:43 +08:00
|
|
|
|
|
|
|
|
export function BorderSettings() {
|
|
|
|
|
const { files } = useFileStore();
|
2026-03-25 09:27:12 +08:00
|
|
|
const {
|
|
|
|
|
processFiles,
|
|
|
|
|
processAllFiles,
|
|
|
|
|
processing,
|
|
|
|
|
error,
|
|
|
|
|
downloadUrl,
|
|
|
|
|
originalSize,
|
|
|
|
|
processedSize,
|
|
|
|
|
progress,
|
|
|
|
|
} = useToolProcessor("border");
|
2026-03-22 04:20:43 +08:00
|
|
|
|
|
|
|
|
const [borderWidth, setBorderWidth] = useState(10);
|
|
|
|
|
const [borderColor, setBorderColor] = useState("#000000");
|
|
|
|
|
const [cornerRadius, setCornerRadius] = useState(0);
|
|
|
|
|
const [padding, setPadding] = useState(0);
|
|
|
|
|
const [shadowBlur, setShadowBlur] = useState(0);
|
|
|
|
|
|
|
|
|
|
const handleProcess = () => {
|
2026-03-23 14:11:08 +08:00
|
|
|
const settings = { borderWidth, borderColor, cornerRadius, padding, shadowBlur };
|
|
|
|
|
if (files.length > 1) {
|
|
|
|
|
processAllFiles(files, settings);
|
|
|
|
|
} else {
|
|
|
|
|
processFiles(files, settings);
|
|
|
|
|
}
|
2026-03-22 04:20:43 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const hasFile = files.length > 0;
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div className="space-y-4">
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between items-center">
|
2026-03-26 01:10:13 +08:00
|
|
|
<label htmlFor="border-border-width" className="text-xs text-muted-foreground">
|
|
|
|
|
Border Width
|
|
|
|
|
</label>
|
2026-03-22 04:20:43 +08:00
|
|
|
<span className="text-xs font-mono text-foreground">{borderWidth}px</span>
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
<input
|
2026-03-26 01:10:13 +08:00
|
|
|
id="border-border-width"
|
2026-03-25 09:27:12 +08:00
|
|
|
type="range"
|
|
|
|
|
min={0}
|
|
|
|
|
max={100}
|
|
|
|
|
value={borderWidth}
|
|
|
|
|
onChange={(e) => setBorderWidth(Number(e.target.value))}
|
|
|
|
|
className="w-full mt-1"
|
|
|
|
|
/>
|
2026-03-22 04:20:43 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
2026-03-26 01:10:13 +08:00
|
|
|
<label htmlFor="border-border-color" className="text-xs text-muted-foreground">
|
|
|
|
|
Border Color
|
|
|
|
|
</label>
|
2026-03-25 09:27:12 +08:00
|
|
|
<input
|
2026-03-26 01:10:13 +08:00
|
|
|
id="border-border-color"
|
2026-03-25 09:27:12 +08:00
|
|
|
type="color"
|
|
|
|
|
value={borderColor}
|
|
|
|
|
onChange={(e) => setBorderColor(e.target.value)}
|
|
|
|
|
className="w-full mt-0.5 h-8 rounded border border-border"
|
|
|
|
|
/>
|
2026-03-22 04:20:43 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between items-center">
|
2026-03-26 01:10:13 +08:00
|
|
|
<label htmlFor="border-corner-radius" className="text-xs text-muted-foreground">
|
|
|
|
|
Corner Radius
|
|
|
|
|
</label>
|
2026-03-22 04:20:43 +08:00
|
|
|
<span className="text-xs font-mono text-foreground">{cornerRadius}px</span>
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
<input
|
2026-03-26 01:10:13 +08:00
|
|
|
id="border-corner-radius"
|
2026-03-25 09:27:12 +08:00
|
|
|
type="range"
|
|
|
|
|
min={0}
|
|
|
|
|
max={200}
|
|
|
|
|
value={cornerRadius}
|
|
|
|
|
onChange={(e) => setCornerRadius(Number(e.target.value))}
|
|
|
|
|
className="w-full mt-1"
|
|
|
|
|
/>
|
2026-03-22 04:20:43 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between items-center">
|
2026-03-26 01:10:13 +08:00
|
|
|
<label htmlFor="border-padding" className="text-xs text-muted-foreground">
|
|
|
|
|
Padding
|
|
|
|
|
</label>
|
2026-03-22 04:20:43 +08:00
|
|
|
<span className="text-xs font-mono text-foreground">{padding}px</span>
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
<input
|
2026-03-26 01:10:13 +08:00
|
|
|
id="border-padding"
|
2026-03-25 09:27:12 +08:00
|
|
|
type="range"
|
|
|
|
|
min={0}
|
|
|
|
|
max={100}
|
|
|
|
|
value={padding}
|
|
|
|
|
onChange={(e) => setPadding(Number(e.target.value))}
|
|
|
|
|
className="w-full mt-1"
|
|
|
|
|
/>
|
2026-03-22 04:20:43 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div>
|
|
|
|
|
<div className="flex justify-between items-center">
|
2026-03-26 01:10:13 +08:00
|
|
|
<label htmlFor="border-shadow" className="text-xs text-muted-foreground">
|
|
|
|
|
Shadow
|
|
|
|
|
</label>
|
2026-03-22 04:20:43 +08:00
|
|
|
<span className="text-xs font-mono text-foreground">{shadowBlur}px</span>
|
|
|
|
|
</div>
|
2026-03-25 09:27:12 +08:00
|
|
|
<input
|
2026-03-26 01:10:13 +08:00
|
|
|
id="border-shadow"
|
2026-03-25 09:27:12 +08:00
|
|
|
type="range"
|
|
|
|
|
min={0}
|
|
|
|
|
max={50}
|
|
|
|
|
value={shadowBlur}
|
|
|
|
|
onChange={(e) => setShadowBlur(Number(e.target.value))}
|
|
|
|
|
className="w-full mt-1"
|
|
|
|
|
/>
|
2026-03-22 04:20:43 +08:00
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{error && <p className="text-xs text-red-500">{error}</p>}
|
|
|
|
|
|
|
|
|
|
{originalSize != null && processedSize != null && (
|
|
|
|
|
<div className="text-xs text-muted-foreground space-y-0.5">
|
|
|
|
|
<p>Original: {(originalSize / 1024).toFixed(1)} KB</p>
|
|
|
|
|
<p>Processed: {(processedSize / 1024).toFixed(1)} KB</p>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
|
2026-03-23 01:45:58 +08:00
|
|
|
{processing ? (
|
|
|
|
|
<ProgressCard
|
|
|
|
|
active={processing}
|
|
|
|
|
phase={progress.phase === "idle" ? "uploading" : progress.phase}
|
|
|
|
|
label="Adding border"
|
|
|
|
|
stage={progress.stage}
|
|
|
|
|
percent={progress.percent}
|
|
|
|
|
elapsed={progress.elapsed}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
<button
|
2026-03-26 01:10:13 +08:00
|
|
|
type="button"
|
2026-03-23 01:45:58 +08:00
|
|
|
onClick={handleProcess}
|
|
|
|
|
disabled={!hasFile || processing}
|
|
|
|
|
className="w-full py-2.5 rounded-lg bg-primary text-primary-foreground font-medium disabled:opacity-50 disabled:cursor-not-allowed flex items-center justify-center gap-2"
|
|
|
|
|
>
|
2026-03-23 14:11:08 +08:00
|
|
|
{files.length > 1 ? `Apply Border (${files.length} files)` : "Apply Border"}
|
2026-03-23 01:45:58 +08:00
|
|
|
</button>
|
|
|
|
|
)}
|
2026-03-22 04:20:43 +08:00
|
|
|
|
|
|
|
|
{downloadUrl && (
|
2026-03-25 09:27:12 +08:00
|
|
|
<a
|
|
|
|
|
href={downloadUrl}
|
|
|
|
|
download
|
|
|
|
|
className="w-full py-2.5 rounded-lg border border-primary text-primary font-medium flex items-center justify-center gap-2 hover:bg-primary/5"
|
|
|
|
|
>
|
2026-03-22 04:20:43 +08:00
|
|
|
<Download className="h-4 w-4" />
|
|
|
|
|
Download
|
|
|
|
|
</a>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|