diff --git a/src/js/action.js b/src/js/action.js index 55329f02b..273acb8a3 100644 --- a/src/js/action.js +++ b/src/js/action.js @@ -1,5 +1,5 @@ import { extend } from 'tui-code-snippet'; -import { isSupportFileApi, base64ToBlob, toInteger } from './util'; +import { isSupportFileApi, base64ToBlob, toInteger, isEmptyCropzone } from './util'; import Imagetracer from './helper/imagetracer'; export default { @@ -304,7 +304,7 @@ export default { { crop: () => { const cropRect = this.getCropzoneRect(); - if (cropRect) { + if (cropRect && !isEmptyCropzone(cropRect)) { this.crop(cropRect) .then(() => { this.stopDrawingMode(); diff --git a/src/js/consts.js b/src/js/consts.js index 4145e98db..555073433 100644 --- a/src/js/consts.js +++ b/src/js/consts.js @@ -291,3 +291,10 @@ export const defaultFilterRangeValus = { value: 0.1, }, }; + +export const emptyCropRectValues = { + LEFT: 0, + TOP: 0, + WIDTH: 0.5, + HEIGHT: 0.5, +}; diff --git a/src/js/util.js b/src/js/util.js index 4400bc6bf..d9f2dcb86 100644 --- a/src/js/util.js +++ b/src/js/util.js @@ -4,7 +4,7 @@ */ import { forEach, sendHostname, extend, isString, pick, inArray } from 'tui-code-snippet'; import Promise from 'core-js-pure/features/promise'; -import { SHAPE_FILL_TYPE, SHAPE_TYPE } from './consts'; +import { SHAPE_FILL_TYPE, SHAPE_TYPE, emptyCropRectValues } from './consts'; const FLOATING_POINT_DIGIT = 2; const CSS_PREFIX = 'tui-image-editor-'; const { min, max } = Math; @@ -343,3 +343,19 @@ export function getFillTypeFromObject(shapeObj) { export function isShape(obj) { return inArray(obj.get('type'), SHAPE_TYPE) >= 0; } + +/** + * Check if cropRect is Empty. + * @param {Object} cropRect - cropRect object + * @param {Number} cropRect.left - cropRect left position value + * @param {Number} cropRect.top - cropRect top position value + * @param {Number} cropRect.width - cropRect width value + * @param {Number} cropRect.height - cropRect height value + * @returns {boolean} + */ +export function isEmptyCropzone(cropRect) { + const { left, top, width, height } = cropRect; + const { LEFT, TOP, WIDTH, HEIGHT } = emptyCropRectValues; + + return left === LEFT && top === TOP && width === WIDTH && height === HEIGHT; +}