|
|
@ -42,6 +42,10 @@ interface MediaInpaintingOverlayProps { |
|
|
|
|
|
|
|
|
const MAX_HISTORY = 30; |
|
|
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 { |
|
|
function validDimensions(width: unknown, height: unknown): { width: number; height: number } | null { |
|
|
return typeof width === "number" && typeof height === "number" && width > 0 && height > 0 |
|
|
return typeof width === "number" && typeof height === "number" && width > 0 && height > 0 |
|
|
? { width, height } |
|
|
? { width, height } |
|
|
@ -269,8 +273,8 @@ export function MediaInpaintingOverlay({ |
|
|
const canvas = canvasRef.current; |
|
|
const canvas = canvasRef.current; |
|
|
if (!rect || !canvas) return null; |
|
|
if (!rect || !canvas) return null; |
|
|
return { |
|
|
return { |
|
|
x: ((event.clientX - rect.left) / rect.width) * canvas.width, |
|
|
x: clamp(((event.clientX - rect.left) / rect.width) * canvas.width, 0, canvas.width), |
|
|
y: ((event.clientY - rect.top) / rect.height) * canvas.height, |
|
|
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(); |
|
|
const rect = canvasRef.current?.getBoundingClientRect(); |
|
|
if (!rect || !bounds) return null; |
|
|
if (!rect || !bounds) return null; |
|
|
return { |
|
|
return { |
|
|
x: bounds.left + ((event.clientX - rect.left) / rect.width) * bounds.width, |
|
|
x: clamp( |
|
|
y: bounds.top + ((event.clientY - rect.top) / rect.height) * bounds.height, |
|
|
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]); |
|
|
}, [bounds]); |
|
|
|
|
|
|
|
|
|