From 2b495003fb4aa1b1be00959028b330766137e423 Mon Sep 17 00:00:00 2001 From: yun Date: Wed, 8 Jul 2026 17:05:10 +0800 Subject: [PATCH] =?UTF-8?q?=E6=93=A6=E9=99=A4=20=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../media/MediaInpaintingOverlay.tsx | 20 +++++++++++++++---- .../image-edit/InpaintingEditSession.tsx | 2 +- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/components/media/MediaInpaintingOverlay.tsx b/src/components/media/MediaInpaintingOverlay.tsx index bbd78a0e..5cb33565 100644 --- a/src/components/media/MediaInpaintingOverlay.tsx +++ b/src/components/media/MediaInpaintingOverlay.tsx @@ -42,6 +42,10 @@ interface MediaInpaintingOverlayProps { const MAX_HISTORY = 30; +function clamp(value: number, min: number, max: number) { + return Math.min(max, Math.max(min, value)); +} + function validDimensions(width: unknown, height: unknown): { width: number; height: number } | null { return typeof width === "number" && typeof height === "number" && width > 0 && height > 0 ? { width, height } @@ -269,8 +273,8 @@ export function MediaInpaintingOverlay({ const canvas = canvasRef.current; if (!rect || !canvas) return null; return { - x: ((event.clientX - rect.left) / rect.width) * canvas.width, - y: ((event.clientY - rect.top) / rect.height) * canvas.height, + x: clamp(((event.clientX - rect.left) / rect.width) * canvas.width, 0, canvas.width), + y: clamp(((event.clientY - rect.top) / rect.height) * canvas.height, 0, canvas.height), }; }, []); @@ -278,8 +282,16 @@ export function MediaInpaintingOverlay({ const rect = canvasRef.current?.getBoundingClientRect(); if (!rect || !bounds) return null; return { - x: bounds.left + ((event.clientX - rect.left) / rect.width) * bounds.width, - y: bounds.top + ((event.clientY - rect.top) / rect.height) * bounds.height, + x: clamp( + bounds.left + ((event.clientX - rect.left) / rect.width) * bounds.width, + bounds.left, + bounds.left + bounds.width + ), + y: clamp( + bounds.top + ((event.clientY - rect.top) / rect.height) * bounds.height, + bounds.top, + bounds.top + bounds.height + ), }; }, [bounds]); diff --git a/src/components/media/image-edit/InpaintingEditSession.tsx b/src/components/media/image-edit/InpaintingEditSession.tsx index 556c9253..91553e75 100644 --- a/src/components/media/image-edit/InpaintingEditSession.tsx +++ b/src/components/media/image-edit/InpaintingEditSession.tsx @@ -23,7 +23,7 @@ export function InpaintingEditSession({ const [mask, setMask] = useState(null); const [prompt, setPrompt] = useState(""); const [batchSize, setBatchSize] = useState(1); - const [brushSize, setBrushSize] = useState(40); + const [brushSize, setBrushSize] = useState(90); const [drawTool, setDrawTool] = useState("brush"); const [eraseMode, setEraseMode] = useState(false); const [frameRect, setFrameRect] = useState(null);