Skip to content

Commit

Permalink
fix: improve crop box resizing
Browse files Browse the repository at this point in the history
Resolved #222
  • Loading branch information
fengyuanchen committed Aug 27, 2017
1 parent 18792fc commit 9257e06
Showing 1 changed file with 21 additions and 10 deletions.
31 changes: 21 additions & 10 deletions src/js/change.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@ export default {
y: pointer.endY - pointer.startY,
};

if (aspectRatio) {
range.X = range.y * aspectRatio;
range.Y = range.x / aspectRatio;
}

switch (action) {
// Move crop box
case 'all':
Expand All @@ -106,11 +101,15 @@ export default {
break;
}

if (right + range.x > maxWidth) {
range.x -= (right + range.x) - maxWidth;
}

width += range.x;

if (aspectRatio) {
height = width / aspectRatio;
top -= range.Y / 2;
top -= (range.x / aspectRatio) / 2;
}

if (width < 0) {
Expand All @@ -127,12 +126,16 @@ export default {
break;
}

if (top + range.y < minTop) {
range.y += minTop - (top + range.y);
}

height -= range.y;
top += range.y;

if (aspectRatio) {
width = height * aspectRatio;
left += range.X / 2;
left += (range.y * aspectRatio) / 2;
}

if (height < 0) {
Expand All @@ -149,12 +152,16 @@ export default {
break;
}

if (left + range.x < minLeft) {
range.x += minLeft - (left + range.x);
}

width -= range.x;
left += range.x;

if (aspectRatio) {
height = width / aspectRatio;
top += range.Y / 2;
top += (range.x / aspectRatio) / 2;
}

if (width < 0) {
Expand All @@ -171,11 +178,15 @@ export default {
break;
}

if (bottom + range.y > maxHeight) {
range.y -= (bottom + range.y) - maxHeight;
}

height += range.y;

if (aspectRatio) {
width = height * aspectRatio;
left -= range.X / 2;
left -= (range.y * aspectRatio) / 2;
}

if (height < 0) {
Expand Down Expand Up @@ -241,7 +252,7 @@ export default {
height -= range.y;
top += range.y;
width = height * aspectRatio;
left += range.X;
left += (range.y * aspectRatio);
} else {
if (range.x <= 0) {
if (left > minLeft) {
Expand Down

0 comments on commit 9257e06

Please sign in to comment.