Browse Source

set a min width and height for crop

Ryan Di 11 months ago
parent
commit
50e4a0b37d
1 changed files with 4 additions and 4 deletions
  1. 4 4
      packages/excalidraw/element/cropElement.ts

+ 4 - 4
packages/excalidraw/element/cropElement.ts

@@ -85,7 +85,7 @@ const _cropElement = (
     pointerY = clamp(pointerY, northBound, southBound);
 
     const pointerDeltaY = pointerY - element.y;
-    nextHeight = element.height - pointerDeltaY;
+    nextHeight = Math.max(element.height - pointerDeltaY, 1);
 
     crop.y = ((pointerDeltaY + croppedTop) / uncroppedHeight) * naturalHeight;
     crop.height = (nextHeight / uncroppedHeight) * naturalHeight;
@@ -97,7 +97,7 @@ const _cropElement = (
 
     pointerY = clamp(pointerY, northBound, southBound);
 
-    nextHeight = pointerY - element.y;
+    nextHeight = Math.max(pointerY - element.y, 1);
     crop.height = (nextHeight / uncroppedHeight) * naturalHeight;
   }
 
@@ -108,7 +108,7 @@ const _cropElement = (
     pointerX = clamp(pointerX, westBound, eastBound);
 
     const pointerDeltaX = pointerX - element.x;
-    nextWidth = element.width - pointerDeltaX;
+    nextWidth = Math.max(element.width - pointerDeltaX, 1);
 
     crop.x = ((pointerDeltaX + croppedLeft) / uncroppedWidth) * naturalWidth;
     crop.width = (nextWidth / uncroppedWidth) * naturalWidth;
@@ -120,7 +120,7 @@ const _cropElement = (
 
     pointerX = clamp(pointerX, westBound, eastBound);
 
-    nextWidth = pointerX - element.x;
+    nextWidth = Math.max(pointerX - element.x, 1);
     crop.width = (nextWidth / uncroppedWidth) * naturalWidth;
   }