diff --git a/web/src/components/AvatarCropModal.tsx b/web/src/components/AvatarCropModal.tsx index 152b732..f299f33 100644 --- a/web/src/components/AvatarCropModal.tsx +++ b/web/src/components/AvatarCropModal.tsx @@ -12,6 +12,7 @@ const VIEWPORT_SIZE = 320; const OUTPUT_SIZE = 500; const MIN_ZOOM = 1; const MAX_ZOOM = 4; +const MASK_RATIO = 0.88; export function AvatarCropModal({ open, file, onCancel, onApply }: AvatarCropModalProps) { const [imageUrl, setImageUrl] = useState(null); @@ -162,13 +163,13 @@ export function AvatarCropModal({ open, file, onCancel, onApply }: AvatarCropMod
event.stopPropagation()}>
-

Crop avatar

+

Drag to reposition

-
+
) : null} +
+
+
@@ -229,10 +236,16 @@ export function AvatarCropModal({ open, file, onCancel, onApply }: AvatarCropMod } function clampPosition(pos: { x: number; y: number }, width: number, height: number) { - const minX = Math.min(0, VIEWPORT_SIZE - width); - const maxX = 0; - const minY = Math.min(0, VIEWPORT_SIZE - height); - const maxY = 0; + if (width <= VIEWPORT_SIZE && height <= VIEWPORT_SIZE) { + return { + x: (VIEWPORT_SIZE - width) / 2, + y: (VIEWPORT_SIZE - height) / 2, + }; + } + const minX = width <= VIEWPORT_SIZE ? (VIEWPORT_SIZE - width) / 2 : VIEWPORT_SIZE - width; + const maxX = width <= VIEWPORT_SIZE ? (VIEWPORT_SIZE - width) / 2 : 0; + const minY = height <= VIEWPORT_SIZE ? (VIEWPORT_SIZE - height) / 2 : VIEWPORT_SIZE - height; + const maxY = height <= VIEWPORT_SIZE ? (VIEWPORT_SIZE - height) / 2 : 0; return { x: Math.max(minX, Math.min(maxX, pos.x)), y: Math.max(minY, Math.min(maxY, pos.y)),