Skip to content

Commit

Permalink
fix: crop box overflows in "viewMode" 1 and 2
Browse files Browse the repository at this point in the history
When using "viewMode" 1 or 2, the crop box could overflow if the canvas
is moved partly beyond the container boundaries.

If moved beyond the top/left boundaries, it could overflow the
container. If moved beyond the bottom/right boundaries, it could
overflow the canvas (exceeding its size).
  • Loading branch information
ingmarh committed Jun 25, 2018
1 parent e2ae655 commit 121b629
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions src/js/render.js
Original file line number Diff line number Diff line change
Expand Up @@ -366,14 +366,28 @@ export default {
if (sizeLimited) {
let minCropBoxWidth = Number(options.minCropBoxWidth) || 0;
let minCropBoxHeight = Number(options.minCropBoxHeight) || 0;
let maxCropBoxWidth = Math.min(
containerData.width,
limited ? canvasData.width : containerData.width,
);
let maxCropBoxHeight = Math.min(
containerData.height,
limited ? canvasData.height : containerData.height,
);
let maxCropBoxWidth = containerData.width;
let maxCropBoxHeight = containerData.height;

if (limited) {
const canvasRight = containerData.width - canvasData.left - canvasData.width;
const canvasBottom = containerData.height - canvasData.top - canvasData.height;

maxCropBoxWidth = Math.min(
containerData.width,
Math.min(
canvasData.width,
canvasData.width + (canvasRight < 0 ? canvasRight : canvasData.left),
),
);
maxCropBoxHeight = Math.min(
containerData.height,
Math.min(
canvasData.height,
canvasData.height + (canvasBottom < 0 ? canvasBottom : canvasData.top),
),
);
}

// The min/maxCropBoxWidth/Height must be less than container's width/height
minCropBoxWidth = Math.min(minCropBoxWidth, containerData.width);
Expand Down

0 comments on commit 121b629

Please sign in to comment.