From 26a1268175305ea243bbef7a21eaa9f2809b3b47 Mon Sep 17 00:00:00 2001 From: Chen Fengyuan Date: Fri, 1 Jun 2018 23:34:07 +0800 Subject: [PATCH] build: release 1.4.0 --- CHANGELOG.md | 5 ++ dist/cropper.common.js | 117 +++++++++++++++++++++++++---------------- dist/cropper.css | 4 +- dist/cropper.esm.js | 117 +++++++++++++++++++++++++---------------- dist/cropper.js | 117 +++++++++++++++++++++++++---------------- dist/cropper.min.css | 4 +- dist/cropper.min.js | 6 +-- docs/css/cropper.css | 4 +- docs/index.html | 2 +- docs/js/cropper.js | 117 +++++++++++++++++++++++++---------------- package-lock.json | 30 ++++++++--- package.json | 2 +- 12 files changed, 322 insertions(+), 203 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 093d568d5..20c6b98ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## 1.4.0 (Jun 1, 2018) + +- Added 1 new option: `initialAspectRatio`. +- Improve the smoothness of crop box resizing. + ## 1.3.6 (May 20, 2018) - Check orientation only when both the `rotatable` and `scalable` options are set to `true`. diff --git a/dist/cropper.common.js b/dist/cropper.common.js index 07ed8c300..f546bbe3d 100644 --- a/dist/cropper.common.js +++ b/dist/cropper.common.js @@ -1,11 +1,11 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:58:21.682Z + * Date: 2018-06-01T15:18:18.692Z */ 'use strict'; @@ -73,6 +73,9 @@ var DEFAULTS = { // Define the dragging mode of the cropper dragMode: DRAG_MODE_CROP, // 'crop', 'move' or 'none' + // Define the initial aspect ratio of the crop box + initialAspectRatio: NaN, + // Define the aspect ratio of the crop box aspectRatio: NaN, @@ -1432,8 +1435,8 @@ var render = { initCropBox: function initCropBox() { var options = this.options, canvasData = this.canvasData; - var aspectRatio = options.aspectRatio; + var aspectRatio = options.aspectRatio || options.initialAspectRatio; var autoCropArea = Number(options.autoCropArea) || 0.8; var cropBoxData = { width: canvasData.width, @@ -1909,6 +1912,7 @@ var handlers = { return; } + // This line is required for preventing page zooming in iOS browsers e.preventDefault(); this.action = action; @@ -2080,14 +2084,15 @@ var change = { check(ACTION_EAST); width += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top -= range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_WEST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2102,14 +2107,15 @@ var change = { height -= range.y; top += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left += range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_SOUTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2124,14 +2130,15 @@ var change = { width -= range.x; left += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top += range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_EAST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2145,14 +2152,15 @@ var change = { check(ACTION_SOUTH); height += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left -= range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_NORTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2195,14 +2203,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_SOUTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2218,7 +2230,7 @@ var change = { height -= range.y; top += range.y; width = height * aspectRatio; - left += range.y * aspectRatio; + left += cropBoxData.width - width; } else { check(ACTION_NORTH); check(ACTION_WEST); @@ -2248,14 +2260,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_SOUTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2298,14 +2314,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_NORTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2345,14 +2365,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_NORTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2667,9 +2691,9 @@ var methods = { var newHeight = naturalHeight * ratio; if (dispatchEvent(this.element, EVENT_ZOOM, { - originalEvent: _originalEvent, + ratio: ratio, oldRatio: width / naturalWidth, - ratio: newWidth / naturalWidth + originalEvent: _originalEvent }) === false) { return this; } @@ -3573,6 +3597,7 @@ var Cropper = function () { this.initPreview(); this.bind(); + options.initialAspectRatio = Math.max(0, options.initialAspectRatio) || NaN; options.aspectRatio = Math.max(0, options.aspectRatio) || NaN; options.viewMode = Math.max(0, Math.min(3, Math.round(options.viewMode))) || 0; diff --git a/dist/cropper.css b/dist/cropper.css index faa86c7e1..f9c960eac 100644 --- a/dist/cropper.css +++ b/dist/cropper.css @@ -1,11 +1,11 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:56:44.346Z + * Date: 2018-06-01T15:18:09.891Z */ .cropper-container { diff --git a/dist/cropper.esm.js b/dist/cropper.esm.js index d45a692a7..a0b3feb0f 100644 --- a/dist/cropper.esm.js +++ b/dist/cropper.esm.js @@ -1,11 +1,11 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:58:21.682Z + * Date: 2018-06-01T15:18:18.692Z */ var IN_BROWSER = typeof window !== 'undefined'; @@ -71,6 +71,9 @@ var DEFAULTS = { // Define the dragging mode of the cropper dragMode: DRAG_MODE_CROP, // 'crop', 'move' or 'none' + // Define the initial aspect ratio of the crop box + initialAspectRatio: NaN, + // Define the aspect ratio of the crop box aspectRatio: NaN, @@ -1430,8 +1433,8 @@ var render = { initCropBox: function initCropBox() { var options = this.options, canvasData = this.canvasData; - var aspectRatio = options.aspectRatio; + var aspectRatio = options.aspectRatio || options.initialAspectRatio; var autoCropArea = Number(options.autoCropArea) || 0.8; var cropBoxData = { width: canvasData.width, @@ -1907,6 +1910,7 @@ var handlers = { return; } + // This line is required for preventing page zooming in iOS browsers e.preventDefault(); this.action = action; @@ -2078,14 +2082,15 @@ var change = { check(ACTION_EAST); width += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top -= range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_WEST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2100,14 +2105,15 @@ var change = { height -= range.y; top += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left += range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_SOUTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2122,14 +2128,15 @@ var change = { width -= range.x; left += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top += range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_EAST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2143,14 +2150,15 @@ var change = { check(ACTION_SOUTH); height += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left -= range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_NORTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2193,14 +2201,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_SOUTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2216,7 +2228,7 @@ var change = { height -= range.y; top += range.y; width = height * aspectRatio; - left += range.y * aspectRatio; + left += cropBoxData.width - width; } else { check(ACTION_NORTH); check(ACTION_WEST); @@ -2246,14 +2258,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_SOUTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2296,14 +2312,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_NORTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2343,14 +2363,18 @@ var change = { if (width < 0 && height < 0) { action = ACTION_NORTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2665,9 +2689,9 @@ var methods = { var newHeight = naturalHeight * ratio; if (dispatchEvent(this.element, EVENT_ZOOM, { - originalEvent: _originalEvent, + ratio: ratio, oldRatio: width / naturalWidth, - ratio: newWidth / naturalWidth + originalEvent: _originalEvent }) === false) { return this; } @@ -3571,6 +3595,7 @@ var Cropper = function () { this.initPreview(); this.bind(); + options.initialAspectRatio = Math.max(0, options.initialAspectRatio) || NaN; options.aspectRatio = Math.max(0, options.aspectRatio) || NaN; options.viewMode = Math.max(0, Math.min(3, Math.round(options.viewMode))) || 0; diff --git a/dist/cropper.js b/dist/cropper.js index a316304af..2c0e171fd 100644 --- a/dist/cropper.js +++ b/dist/cropper.js @@ -1,11 +1,11 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:58:21.682Z + * Date: 2018-06-01T15:18:18.692Z */ (function (global, factory) { @@ -77,6 +77,9 @@ // Define the dragging mode of the cropper dragMode: DRAG_MODE_CROP, // 'crop', 'move' or 'none' + // Define the initial aspect ratio of the crop box + initialAspectRatio: NaN, + // Define the aspect ratio of the crop box aspectRatio: NaN, @@ -1436,8 +1439,8 @@ initCropBox: function initCropBox() { var options = this.options, canvasData = this.canvasData; - var aspectRatio = options.aspectRatio; + var aspectRatio = options.aspectRatio || options.initialAspectRatio; var autoCropArea = Number(options.autoCropArea) || 0.8; var cropBoxData = { width: canvasData.width, @@ -1913,6 +1916,7 @@ return; } + // This line is required for preventing page zooming in iOS browsers e.preventDefault(); this.action = action; @@ -2084,14 +2088,15 @@ check(ACTION_EAST); width += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top -= range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_WEST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2106,14 +2111,15 @@ height -= range.y; top += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left += range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_SOUTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2128,14 +2134,15 @@ width -= range.x; left += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top += range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_EAST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2149,14 +2156,15 @@ check(ACTION_SOUTH); height += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left -= range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_NORTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2199,14 +2207,18 @@ if (width < 0 && height < 0) { action = ACTION_SOUTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2222,7 +2234,7 @@ height -= range.y; top += range.y; width = height * aspectRatio; - left += range.y * aspectRatio; + left += cropBoxData.width - width; } else { check(ACTION_NORTH); check(ACTION_WEST); @@ -2252,14 +2264,18 @@ if (width < 0 && height < 0) { action = ACTION_SOUTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2302,14 +2318,18 @@ if (width < 0 && height < 0) { action = ACTION_NORTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2349,14 +2369,18 @@ if (width < 0 && height < 0) { action = ACTION_NORTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2671,9 +2695,9 @@ var newHeight = naturalHeight * ratio; if (dispatchEvent(this.element, EVENT_ZOOM, { - originalEvent: _originalEvent, + ratio: ratio, oldRatio: width / naturalWidth, - ratio: newWidth / naturalWidth + originalEvent: _originalEvent }) === false) { return this; } @@ -3577,6 +3601,7 @@ this.initPreview(); this.bind(); + options.initialAspectRatio = Math.max(0, options.initialAspectRatio) || NaN; options.aspectRatio = Math.max(0, options.aspectRatio) || NaN; options.viewMode = Math.max(0, Math.min(3, Math.round(options.viewMode))) || 0; diff --git a/dist/cropper.min.css b/dist/cropper.min.css index 49b257f64..9f910be7c 100644 --- a/dist/cropper.min.css +++ b/dist/cropper.min.css @@ -1,9 +1,9 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:56:44.346Z + * Date: 2018-06-01T15:18:09.891Z */.cropper-container{direction:ltr;font-size:0;line-height:0;position:relative;-ms-touch-action:none;touch-action:none;-webkit-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none}.cropper-container img{display:block;height:100%;image-orientation:0deg;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;width:100%}.cropper-canvas,.cropper-crop-box,.cropper-drag-box,.cropper-modal,.cropper-wrap-box{bottom:0;left:0;position:absolute;right:0;top:0}.cropper-canvas,.cropper-wrap-box{overflow:hidden}.cropper-drag-box{background-color:#fff;opacity:0}.cropper-modal{background-color:#000;opacity:.5}.cropper-view-box{display:block;height:100%;outline-color:rgba(51,153,255,.75);outline:1px solid #39f;overflow:hidden;width:100%}.cropper-dashed{border:0 dashed #eee;display:block;opacity:.5;position:absolute}.cropper-dashed.dashed-h{border-bottom-width:1px;border-top-width:1px;height:33.33333%;left:0;top:33.33333%;width:100%}.cropper-dashed.dashed-v{border-left-width:1px;border-right-width:1px;height:100%;left:33.33333%;top:0;width:33.33333%}.cropper-center{display:block;height:0;left:50%;opacity:.75;position:absolute;top:50%;width:0}.cropper-center:after,.cropper-center:before{background-color:#eee;content:" ";display:block;position:absolute}.cropper-center:before{height:1px;left:-3px;top:0;width:7px}.cropper-center:after{height:7px;left:0;top:-3px;width:1px}.cropper-face,.cropper-line,.cropper-point{display:block;height:100%;opacity:.1;position:absolute;width:100%}.cropper-face{background-color:#fff;left:0;top:0}.cropper-line{background-color:#39f}.cropper-line.line-e{cursor:ew-resize;right:-3px;top:0;width:5px}.cropper-line.line-n{cursor:ns-resize;height:5px;left:0;top:-3px}.cropper-line.line-w{cursor:ew-resize;left:-3px;top:0;width:5px}.cropper-line.line-s{bottom:-3px;cursor:ns-resize;height:5px;left:0}.cropper-point{background-color:#39f;height:5px;opacity:.75;width:5px}.cropper-point.point-e{cursor:ew-resize;margin-top:-3px;right:-3px;top:50%}.cropper-point.point-n{cursor:ns-resize;left:50%;margin-left:-3px;top:-3px}.cropper-point.point-w{cursor:ew-resize;left:-3px;margin-top:-3px;top:50%}.cropper-point.point-s{bottom:-3px;cursor:s-resize;left:50%;margin-left:-3px}.cropper-point.point-ne{cursor:nesw-resize;right:-3px;top:-3px}.cropper-point.point-nw{cursor:nwse-resize;left:-3px;top:-3px}.cropper-point.point-sw{bottom:-3px;cursor:nesw-resize;left:-3px}.cropper-point.point-se{bottom:-3px;cursor:nwse-resize;height:20px;opacity:1;right:-3px;width:20px}@media (min-width:768px){.cropper-point.point-se{height:15px;width:15px}}@media (min-width:992px){.cropper-point.point-se{height:10px;width:10px}}@media (min-width:1200px){.cropper-point.point-se{height:5px;opacity:.75;width:5px}}.cropper-point.point-se:before{background-color:#39f;bottom:-50%;content:" ";display:block;height:200%;opacity:0;position:absolute;right:-50%;width:200%}.cropper-invisible{opacity:0}.cropper-bg{background-image:url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC")}.cropper-hide{display:block;height:0;position:absolute;width:0}.cropper-hidden{display:none!important}.cropper-move{cursor:move}.cropper-crop{cursor:crosshair}.cropper-disabled .cropper-drag-box,.cropper-disabled .cropper-face,.cropper-disabled .cropper-line,.cropper-disabled .cropper-point{cursor:not-allowed} \ No newline at end of file diff --git a/dist/cropper.min.js b/dist/cropper.min.js index 264021d88..605979f69 100644 --- a/dist/cropper.min.js +++ b/dist/cropper.min.js @@ -1,10 +1,10 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:58:21.682Z + * Date: 2018-06-01T15:18:18.692Z */ -!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.Cropper=i()}(this,function(){"use strict";var n="undefined"!=typeof window,h=n?window:{},d="cropper",k="all",T="crop",W="move",E="zoom",H="e",N="w",L="s",O="n",z="ne",Y="nw",X="se",R="sw",r=d+"-crop",t=d+"-disabled",S=d+"-hidden",l=d+"-hide",o=d+"-modal",p=d+"-move",m=d+"Action",g=d+"Preview",s="crop",c="move",u="none",a="crop",f="cropend",v="cropmove",w="cropstart",x="dblclick",b=h.PointerEvent?"pointerdown":"touchstart mousedown",y=h.PointerEvent?"pointermove":"touchmove mousemove",M=h.PointerEvent?"pointerup pointercancel":"touchend touchcancel mouseup",C="ready",D="resize",B="wheel mousewheel DOMMouseScroll",A="zoom",I=/^(?:e|w|s|n|se|sw|ne|nw|all|crop|move|zoom)$/,U=/^data:/,j=/^data:image\/jpeg;base64,/,P=/^(?:img|canvas)$/i,q={viewMode:0,dragMode:s,aspectRatio:NaN,data:null,preview:"",responsive:!0,restore:!0,checkCrossOrigin:!0,checkOrientation:!0,modal:!0,guides:!0,center:!0,highlight:!0,background:!0,autoCrop:!0,autoCropArea:.8,movable:!0,rotatable:!0,scalable:!0,zoomable:!0,zoomOnTouch:!0,zoomOnWheel:!0,wheelZoomRatio:.1,cropBoxMovable:!0,cropBoxResizable:!0,toggleDragModeOnDblclick:!0,minCanvasWidth:0,minCanvasHeight:0,minCropBoxWidth:0,minCropBoxHeight:0,minContainerWidth:200,minContainerHeight:100,ready:null,cropstart:null,cropmove:null,cropend:null,crop:null,zoom:null},i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},$=function(){function a(t,i){for(var e=0;et.width?3===e?r=t.height*h:s=t.width/h:3===e?s=t.width/h:r=t.height*h;var c={aspectRatio:h,naturalWidth:n,naturalHeight:o,width:r,height:s};c.left=(t.width-r)/2,c.top=(t.height-s)/2,c.oldLeft=c.left,c.oldTop=c.top,this.canvasData=c,this.limited=1===e||2===e,this.limitCanvas(!0,!0),this.initialImageData=_({},i),this.initialCanvasData=_({},c)},limitCanvas:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,h=e.viewMode,r=n.aspectRatio,s=this.cropped&&o;if(t){var c=Number(e.minCanvasWidth)||0,d=Number(e.minCanvasHeight)||0;1=a.width&&(n.minLeft=Math.min(0,p),n.maxLeft=Math.max(0,p)),n.height>=a.height&&(n.minTop=Math.min(0,m),n.maxTop=Math.max(0,m))))}else n.minLeft=-n.width,n.minTop=-n.height,n.maxLeft=a.width,n.maxTop=a.height},renderCanvas:function(t,i){var e=this.canvasData,a=this.imageData;if(i){var n=function(t){var i=t.width,e=t.height,a=t.degree;if(90==(a=Math.abs(a)%180))return{width:e,height:i};var n=a%90*Math.PI/180,o=Math.sin(n),h=Math.cos(n),r=i*h+e*o,s=i*o+e*h;return 90e.maxWidth||e.widthe.maxHeight||e.heighti.width?n.height=n.width/e:n.width=n.height*e),this.cropBoxData=n,this.limitCropBox(!0,!0),n.width=Math.min(Math.max(n.width,n.minWidth),n.maxWidth),n.height=Math.min(Math.max(n.height,n.minHeight),n.maxHeight),n.width=Math.max(n.minWidth,n.width*a),n.height=Math.max(n.minHeight,n.height*a),n.left=i.left+(i.width-n.width)/2,n.top=i.top+(i.height-n.height)/2,n.oldLeft=n.left,n.oldTop=n.top,this.initialCropBoxData=_({},n)},limitCropBox:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,h=this.limited,r=e.aspectRatio;if(t){var s=Number(e.minCropBoxWidth)||0,c=Number(e.minCropBoxHeight)||0,d=Math.min(a.width,h?n.width:a.width),l=Math.min(a.height,h?n.height:a.height);s=Math.min(s,a.width),c=Math.min(c,a.height),r&&(s&&c?se.maxWidth||e.widthe.maxHeight||e.height=i.width&&e.height>=i.height?W:k),et(this.cropBox,_({width:e.width,height:e.height},Ct({translateX:e.left,translateY:e.top}))),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),ut(this.element,a,this.getData())}},Nt={initPreview:function(){var e=this.crossOrigin,t=this.options.preview,a=e?this.crossOriginUrl:this.url,i=document.createElement("img");if(e&&(i.crossOrigin=e),i.src=a,this.viewBox.appendChild(i),this.viewBoxImage=i,t){var n=t;"string"==typeof t?n=this.element.ownerDocument.querySelectorAll(t):t.querySelector&&(n=[t]),J(this.previews=n,function(t){var i=document.createElement("img");ct(t,g,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),e&&(i.crossOrigin=e),i.src=a,i.style.cssText='display:block;width:100%;height:auto;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;image-orientation:0deg!important;"',t.innerHTML="",t.appendChild(i)})}},resetPreview:function(){J(this.previews,function(t){var i=st(t,g);et(t,{width:i.width,height:i.height}),t.innerHTML=i.html,dt(t,g)})},preview:function(){var r=this.imageData,t=this.canvasData,i=this.cropBoxData,s=i.width,c=i.height,d=r.width,l=r.height,p=i.left-t.left-r.left,m=i.top-t.top-r.top;this.cropped&&!this.disabled&&(et(this.viewBoxImage,_({width:d,height:l},Ct(_({translateX:-p,translateY:-m},r)))),J(this.previews,function(t){var i=st(t,g),e=i.width,a=i.height,n=e,o=a,h=1;s&&(o=c*(h=e/s)),c&&af&&(D.x=f-p);break;case N:s+D.xv&&(D.y=v-m)}};switch(h){case k:s+=D.x,c+=D.y;break;case H:if(0<=D.x&&(f<=p||r&&(c<=u||v<=m))){w=!1;break}B(H),d+=D.x,r&&(l=d/r,c-=D.x/r/2),d<0&&(h=N,d=0);break;case O:if(D.y<=0&&(c<=u||r&&(s<=g||f<=p))){w=!1;break}B(O),l-=D.y,c+=D.y,r&&(d=l*r,s+=D.y*r/2),l<0&&(h=L,l=0);break;case N:if(D.x<=0&&(s<=g||r&&(c<=u||v<=m))){w=!1;break}B(N),d-=D.x,s+=D.x,r&&(l=d/r,c+=D.x/r/2),d<0&&(h=H,d=0);break;case L:if(0<=D.y&&(v<=m||r&&(s<=g||f<=p))){w=!1;break}B(L),l+=D.y,r&&(d=l*r,s-=D.y*r/2),l<0&&(h=O,l=0);break;case z:if(r){if(D.y<=0&&(c<=u||f<=p)){w=!1;break}B(O),l-=D.y,c+=D.y,d=l*r}else B(O),B(H),0<=D.x?p or element.");this.element=t,this.options=_({},q,V(i)&&i),this.cropped=!1,this.disabled=!1,this.pointers={},this.ready=!1,this.reloading=!1,this.replaced=!1,this.sized=!1,this.sizing=!1,this.init()}return $(e,[{key:"init",value:function(){var t=this.element,i=t.tagName.toLowerCase(),e=void 0;if(!st(t,d)){if(ct(t,d,this),"img"===i){if(this.isImg=!0,e=t.getAttribute("src")||"",!(this.originalUrl=e))return;e=t.src}else"canvas"===i&&window.HTMLCanvasElement&&(e=t.toDataURL());this.load(e)}}},{key:"load",value:function(t){var i=this;if(t){this.url=t,this.imageData={};var e=this.element,a=this.options;if(a.rotatable||a.scalable||(a.checkOrientation=!1),a.checkOrientation&&window.ArrayBuffer)if(U.test(t))j.test(t)?this.read((n=t.replace(Wt,""),o=atob(n),h=new ArrayBuffer(o.length),J(r=new Uint8Array(h),function(t,i){r[i]=o.charCodeAt(i)}),h)):this.clone();else{var n,o,h,r,s=new XMLHttpRequest;this.reloading=!0,this.xhr=s;var c=function(){i.reloading=!1,i.xhr=null};s.ontimeout=c,s.onabort=c,s.onerror=function(){c(),i.clone()},s.onload=function(){c(),i.read(s.response)},a.checkCrossOrigin&&yt(t)&&e.crossOrigin&&(t=Mt(t)),s.open("get",t),s.responseType="arraybuffer",s.withCredentials="use-credentials"===e.crossOrigin,s.send()}else this.clone()}}},{key:"read",value:function(t){var i,e,a,n=this.options,o=this.imageData,h=Et(t),r=0,s=1,c=1;if(1
';var o=n.querySelector("."+d+"-container"),h=o.querySelector("."+d+"-canvas"),r=o.querySelector("."+d+"-drag-box"),s=o.querySelector("."+d+"-crop-box"),c=s.querySelector("."+d+"-face");this.container=a,this.cropper=o,this.canvas=h,this.dragBox=r,this.cropBox=s,this.viewBox=o.querySelector("."+d+"-view-box"),this.face=c,h.appendChild(e),at(t,S),a.insertBefore(o,t.nextSibling),this.isImg||nt(e,l),this.initPreview(),this.bind(),i.aspectRatio=Math.max(0,i.aspectRatio)||NaN,i.viewMode=Math.max(0,Math.min(3,Math.round(i.viewMode)))||0,at(s,S),i.guides||at(s.getElementsByClassName(d+"-dashed"),S),i.center||at(s.getElementsByClassName(d+"-center"),S),i.background&&at(o,d+"-bg"),i.highlight||at(c,"cropper-invisible"),i.cropBoxMovable&&(at(c,p),ct(c,m,k)),i.cropBoxResizable||(at(s.getElementsByClassName(d+"-line"),S),at(s.getElementsByClassName(d+"-point"),S)),this.render(),this.ready=!0,this.setDragMode(i.dragMode),i.autoCrop&&this.crop(),this.setData(i.data),G(i.ready)&>(t,C,i.ready,{once:!0}),ut(t,C)}}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),nt(this.element,S))}},{key:"uncreate",value:function(){this.ready?(this.unbuild(),this.ready=!1,this.cropped=!1):this.sizing?(this.sizingImage.onload=null,this.sizing=!1,this.sized=!1):this.reloading?this.xhr.abort():this.image&&this.stop()}}],[{key:"noConflict",value:function(){return window.Cropper=Xt,e}},{key:"setDefaults",value:function(t){_(q,V(t)&&t)}}]),e}();return _(Rt.prototype,Ht,Nt,Lt,Ot,zt,Yt),Rt}); \ No newline at end of file +!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.Cropper=i()}(this,function(){"use strict";var n="undefined"!=typeof window,h=n?window:{},d="cropper",k="all",T="crop",W="move",N="zoom",E="e",H="w",L="s",O="n",z="ne",Y="nw",X="se",R="sw",r=d+"-crop",t=d+"-disabled",S=d+"-hidden",l=d+"-hide",o=d+"-modal",p=d+"-move",m=d+"Action",g=d+"Preview",s="crop",c="move",u="none",a="crop",f="cropend",v="cropmove",w="cropstart",x="dblclick",b=h.PointerEvent?"pointerdown":"touchstart mousedown",y=h.PointerEvent?"pointermove":"touchmove mousemove",M=h.PointerEvent?"pointerup pointercancel":"touchend touchcancel mouseup",C="ready",D="resize",B="wheel mousewheel DOMMouseScroll",A="zoom",I=/^(?:e|w|s|n|se|sw|ne|nw|all|crop|move|zoom)$/,U=/^data:/,j=/^data:image\/jpeg;base64,/,P=/^(?:img|canvas)$/i,q={viewMode:0,dragMode:s,initialAspectRatio:NaN,aspectRatio:NaN,data:null,preview:"",responsive:!0,restore:!0,checkCrossOrigin:!0,checkOrientation:!0,modal:!0,guides:!0,center:!0,highlight:!0,background:!0,autoCrop:!0,autoCropArea:.8,movable:!0,rotatable:!0,scalable:!0,zoomable:!0,zoomOnTouch:!0,zoomOnWheel:!0,wheelZoomRatio:.1,cropBoxMovable:!0,cropBoxResizable:!0,toggleDragModeOnDblclick:!0,minCanvasWidth:0,minCanvasHeight:0,minCropBoxWidth:0,minCropBoxHeight:0,minContainerWidth:200,minContainerHeight:100,ready:null,cropstart:null,cropmove:null,cropend:null,crop:null,zoom:null},i="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},$=function(){function a(t,i){for(var e=0;et.width?3===e?r=t.height*h:s=t.width/h:3===e?s=t.width/h:r=t.height*h;var c={aspectRatio:h,naturalWidth:n,naturalHeight:o,width:r,height:s};c.left=(t.width-r)/2,c.top=(t.height-s)/2,c.oldLeft=c.left,c.oldTop=c.top,this.canvasData=c,this.limited=1===e||2===e,this.limitCanvas(!0,!0),this.initialImageData=_({},i),this.initialCanvasData=_({},c)},limitCanvas:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,h=e.viewMode,r=n.aspectRatio,s=this.cropped&&o;if(t){var c=Number(e.minCanvasWidth)||0,d=Number(e.minCanvasHeight)||0;1=a.width&&(n.minLeft=Math.min(0,p),n.maxLeft=Math.max(0,p)),n.height>=a.height&&(n.minTop=Math.min(0,m),n.maxTop=Math.max(0,m))))}else n.minLeft=-n.width,n.minTop=-n.height,n.maxLeft=a.width,n.maxTop=a.height},renderCanvas:function(t,i){var e=this.canvasData,a=this.imageData;if(i){var n=function(t){var i=t.width,e=t.height,a=t.degree;if(90==(a=Math.abs(a)%180))return{width:e,height:i};var n=a%90*Math.PI/180,o=Math.sin(n),h=Math.cos(n),r=i*h+e*o,s=i*o+e*h;return 90e.maxWidth||e.widthe.maxHeight||e.heighti.width?n.height=n.width/e:n.width=n.height*e),this.cropBoxData=n,this.limitCropBox(!0,!0),n.width=Math.min(Math.max(n.width,n.minWidth),n.maxWidth),n.height=Math.min(Math.max(n.height,n.minHeight),n.maxHeight),n.width=Math.max(n.minWidth,n.width*a),n.height=Math.max(n.minHeight,n.height*a),n.left=i.left+(i.width-n.width)/2,n.top=i.top+(i.height-n.height)/2,n.oldLeft=n.left,n.oldTop=n.top,this.initialCropBoxData=_({},n)},limitCropBox:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,h=this.limited,r=e.aspectRatio;if(t){var s=Number(e.minCropBoxWidth)||0,c=Number(e.minCropBoxHeight)||0,d=Math.min(a.width,h?n.width:a.width),l=Math.min(a.height,h?n.height:a.height);s=Math.min(s,a.width),c=Math.min(c,a.height),r&&(s&&c?se.maxWidth||e.widthe.maxHeight||e.height=i.width&&e.height>=i.height?W:k),et(this.cropBox,_({width:e.width,height:e.height},Ct({translateX:e.left,translateY:e.top}))),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),ut(this.element,a,this.getData())}},Ht={initPreview:function(){var e=this.crossOrigin,t=this.options.preview,a=e?this.crossOriginUrl:this.url,i=document.createElement("img");if(e&&(i.crossOrigin=e),i.src=a,this.viewBox.appendChild(i),this.viewBoxImage=i,t){var n=t;"string"==typeof t?n=this.element.ownerDocument.querySelectorAll(t):t.querySelector&&(n=[t]),J(this.previews=n,function(t){var i=document.createElement("img");ct(t,g,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),e&&(i.crossOrigin=e),i.src=a,i.style.cssText='display:block;width:100%;height:auto;min-width:0!important;min-height:0!important;max-width:none!important;max-height:none!important;image-orientation:0deg!important;"',t.innerHTML="",t.appendChild(i)})}},resetPreview:function(){J(this.previews,function(t){var i=st(t,g);et(t,{width:i.width,height:i.height}),t.innerHTML=i.html,dt(t,g)})},preview:function(){var r=this.imageData,t=this.canvasData,i=this.cropBoxData,s=i.width,c=i.height,d=r.width,l=r.height,p=i.left-t.left-r.left,m=i.top-t.top-r.top;this.cropped&&!this.disabled&&(et(this.viewBoxImage,_({width:d,height:l},Ct(_({translateX:-p,translateY:-m},r)))),J(this.previews,function(t){var i=st(t,g),e=i.width,a=i.height,n=e,o=a,h=1;s&&(o=c*(h=e/s)),c&&af&&(D.x=f-p);break;case H:s+D.xv&&(D.y=v-m)}};switch(h){case k:s+=D.x,c+=D.y;break;case E:if(0<=D.x&&(f<=p||r&&(c<=u||v<=m))){w=!1;break}B(E),(d+=D.x)<0&&(h=H,s-=d=-d),r&&(l=d/r,c+=(n.height-l)/2);break;case O:if(D.y<=0&&(c<=u||r&&(s<=g||f<=p))){w=!1;break}B(O),l-=D.y,c+=D.y,l<0&&(h=L,c-=l=-l),r&&(d=l*r,s+=(n.width-d)/2);break;case H:if(D.x<=0&&(s<=g||r&&(c<=u||v<=m))){w=!1;break}B(H),d-=D.x,s+=D.x,d<0&&(h=E,s-=d=-d),r&&(l=d/r,c+=(n.height-l)/2);break;case L:if(0<=D.y&&(v<=m||r&&(s<=g||f<=p))){w=!1;break}B(L),(l+=D.y)<0&&(h=O,c-=l=-l),r&&(d=l*r,s+=(n.width-d)/2);break;case z:if(r){if(D.y<=0&&(c<=u||f<=p)){w=!1;break}B(O),l-=D.y,c+=D.y,d=l*r}else B(O),B(E),0<=D.x?p or element.");this.element=t,this.options=_({},q,V(i)&&i),this.cropped=!1,this.disabled=!1,this.pointers={},this.ready=!1,this.reloading=!1,this.replaced=!1,this.sized=!1,this.sizing=!1,this.init()}return $(e,[{key:"init",value:function(){var t=this.element,i=t.tagName.toLowerCase(),e=void 0;if(!st(t,d)){if(ct(t,d,this),"img"===i){if(this.isImg=!0,e=t.getAttribute("src")||"",!(this.originalUrl=e))return;e=t.src}else"canvas"===i&&window.HTMLCanvasElement&&(e=t.toDataURL());this.load(e)}}},{key:"load",value:function(t){var i=this;if(t){this.url=t,this.imageData={};var e=this.element,a=this.options;if(a.rotatable||a.scalable||(a.checkOrientation=!1),a.checkOrientation&&window.ArrayBuffer)if(U.test(t))j.test(t)?this.read((n=t.replace(Wt,""),o=atob(n),h=new ArrayBuffer(o.length),J(r=new Uint8Array(h),function(t,i){r[i]=o.charCodeAt(i)}),h)):this.clone();else{var n,o,h,r,s=new XMLHttpRequest;this.reloading=!0,this.xhr=s;var c=function(){i.reloading=!1,i.xhr=null};s.ontimeout=c,s.onabort=c,s.onerror=function(){c(),i.clone()},s.onload=function(){c(),i.read(s.response)},a.checkCrossOrigin&&yt(t)&&e.crossOrigin&&(t=Mt(t)),s.open("get",t),s.responseType="arraybuffer",s.withCredentials="use-credentials"===e.crossOrigin,s.send()}else this.clone()}}},{key:"read",value:function(t){var i,e,a,n=this.options,o=this.imageData,h=Nt(t),r=0,s=1,c=1;if(1
';var o=n.querySelector("."+d+"-container"),h=o.querySelector("."+d+"-canvas"),r=o.querySelector("."+d+"-drag-box"),s=o.querySelector("."+d+"-crop-box"),c=s.querySelector("."+d+"-face");this.container=a,this.cropper=o,this.canvas=h,this.dragBox=r,this.cropBox=s,this.viewBox=o.querySelector("."+d+"-view-box"),this.face=c,h.appendChild(e),at(t,S),a.insertBefore(o,t.nextSibling),this.isImg||nt(e,l),this.initPreview(),this.bind(),i.initialAspectRatio=Math.max(0,i.initialAspectRatio)||NaN,i.aspectRatio=Math.max(0,i.aspectRatio)||NaN,i.viewMode=Math.max(0,Math.min(3,Math.round(i.viewMode)))||0,at(s,S),i.guides||at(s.getElementsByClassName(d+"-dashed"),S),i.center||at(s.getElementsByClassName(d+"-center"),S),i.background&&at(o,d+"-bg"),i.highlight||at(c,"cropper-invisible"),i.cropBoxMovable&&(at(c,p),ct(c,m,k)),i.cropBoxResizable||(at(s.getElementsByClassName(d+"-line"),S),at(s.getElementsByClassName(d+"-point"),S)),this.render(),this.ready=!0,this.setDragMode(i.dragMode),i.autoCrop&&this.crop(),this.setData(i.data),G(i.ready)&>(t,C,i.ready,{once:!0}),ut(t,C)}}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),nt(this.element,S))}},{key:"uncreate",value:function(){this.ready?(this.unbuild(),this.ready=!1,this.cropped=!1):this.sizing?(this.sizingImage.onload=null,this.sizing=!1,this.sized=!1):this.reloading?this.xhr.abort():this.image&&this.stop()}}],[{key:"noConflict",value:function(){return window.Cropper=Xt,e}},{key:"setDefaults",value:function(t){_(q,V(t)&&t)}}]),e}();return _(Rt.prototype,Et,Ht,Lt,Ot,zt,Yt),Rt}); \ No newline at end of file diff --git a/docs/css/cropper.css b/docs/css/cropper.css index faa86c7e1..f9c960eac 100644 --- a/docs/css/cropper.css +++ b/docs/css/cropper.css @@ -1,11 +1,11 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:56:44.346Z + * Date: 2018-06-01T15:18:09.891Z */ .cropper-container { diff --git a/docs/index.html b/docs/index.html index 334dc29e6..7a08212e8 100644 --- a/docs/index.html +++ b/docs/index.html @@ -46,7 +46,7 @@
-

Cropper.js v1.3.6

+

Cropper.js v1.4.0

JavaScript image cropper.

diff --git a/docs/js/cropper.js b/docs/js/cropper.js index a316304af..2c0e171fd 100644 --- a/docs/js/cropper.js +++ b/docs/js/cropper.js @@ -1,11 +1,11 @@ /*! - * Cropper.js v1.3.6 + * Cropper.js v1.4.0 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2018-05-20T07:58:21.682Z + * Date: 2018-06-01T15:18:18.692Z */ (function (global, factory) { @@ -77,6 +77,9 @@ // Define the dragging mode of the cropper dragMode: DRAG_MODE_CROP, // 'crop', 'move' or 'none' + // Define the initial aspect ratio of the crop box + initialAspectRatio: NaN, + // Define the aspect ratio of the crop box aspectRatio: NaN, @@ -1436,8 +1439,8 @@ initCropBox: function initCropBox() { var options = this.options, canvasData = this.canvasData; - var aspectRatio = options.aspectRatio; + var aspectRatio = options.aspectRatio || options.initialAspectRatio; var autoCropArea = Number(options.autoCropArea) || 0.8; var cropBoxData = { width: canvasData.width, @@ -1913,6 +1916,7 @@ return; } + // This line is required for preventing page zooming in iOS browsers e.preventDefault(); this.action = action; @@ -2084,14 +2088,15 @@ check(ACTION_EAST); width += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top -= range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_WEST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2106,14 +2111,15 @@ height -= range.y; top += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left += range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_SOUTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2128,14 +2134,15 @@ width -= range.x; left += range.x; - if (aspectRatio) { - height = width / aspectRatio; - top += range.x / aspectRatio / 2; - } - if (width < 0) { action = ACTION_EAST; - width = 0; + width = -width; + left -= width; + } + + if (aspectRatio) { + height = width / aspectRatio; + top += (cropBoxData.height - height) / 2; } break; @@ -2149,14 +2156,15 @@ check(ACTION_SOUTH); height += range.y; - if (aspectRatio) { - width = height * aspectRatio; - left -= range.y * aspectRatio / 2; - } - if (height < 0) { action = ACTION_NORTH; - height = 0; + height = -height; + top -= height; + } + + if (aspectRatio) { + width = height * aspectRatio; + left += (cropBoxData.width - width) / 2; } break; @@ -2199,14 +2207,18 @@ if (width < 0 && height < 0) { action = ACTION_SOUTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2222,7 +2234,7 @@ height -= range.y; top += range.y; width = height * aspectRatio; - left += range.y * aspectRatio; + left += cropBoxData.width - width; } else { check(ACTION_NORTH); check(ACTION_WEST); @@ -2252,14 +2264,18 @@ if (width < 0 && height < 0) { action = ACTION_SOUTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_NORTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_SOUTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2302,14 +2318,18 @@ if (width < 0 && height < 0) { action = ACTION_NORTH_EAST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_EAST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_WEST; - height = 0; + height = -height; + top -= height; } break; @@ -2349,14 +2369,18 @@ if (width < 0 && height < 0) { action = ACTION_NORTH_WEST; - height = 0; - width = 0; + height = -height; + width = -width; + top -= height; + left -= width; } else if (width < 0) { action = ACTION_SOUTH_WEST; - width = 0; + width = -width; + left -= width; } else if (height < 0) { action = ACTION_NORTH_EAST; - height = 0; + height = -height; + top -= height; } break; @@ -2671,9 +2695,9 @@ var newHeight = naturalHeight * ratio; if (dispatchEvent(this.element, EVENT_ZOOM, { - originalEvent: _originalEvent, + ratio: ratio, oldRatio: width / naturalWidth, - ratio: newWidth / naturalWidth + originalEvent: _originalEvent }) === false) { return this; } @@ -3577,6 +3601,7 @@ this.initPreview(); this.bind(); + options.initialAspectRatio = Math.max(0, options.initialAspectRatio) || NaN; options.aspectRatio = Math.max(0, options.aspectRatio) || NaN; options.viewMode = Math.max(0, Math.min(3, Math.round(options.viewMode))) || 0; diff --git a/package-lock.json b/package-lock.json index 171595dfc..255dc5696 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "cropperjs", - "version": "1.3.6", + "version": "1.4.0", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -4626,12 +4626,14 @@ "balanced-match": { "version": "1.0.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "brace-expansion": { "version": "1.1.11", "bundled": true, "dev": true, + "optional": true, "requires": { "balanced-match": "^1.0.0", "concat-map": "0.0.1" @@ -4646,17 +4648,20 @@ "code-point-at": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "concat-map": { "version": "0.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "console-control-strings": { "version": "1.1.0", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "core-util-is": { "version": "1.0.2", @@ -4773,7 +4778,8 @@ "inherits": { "version": "2.0.3", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "ini": { "version": "1.3.5", @@ -4785,6 +4791,7 @@ "version": "1.0.0", "bundled": true, "dev": true, + "optional": true, "requires": { "number-is-nan": "^1.0.0" } @@ -4799,6 +4806,7 @@ "version": "3.0.4", "bundled": true, "dev": true, + "optional": true, "requires": { "brace-expansion": "^1.1.7" } @@ -4806,12 +4814,14 @@ "minimist": { "version": "0.0.8", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "minipass": { "version": "2.2.4", "bundled": true, "dev": true, + "optional": true, "requires": { "safe-buffer": "^5.1.1", "yallist": "^3.0.0" @@ -4830,6 +4840,7 @@ "version": "0.5.1", "bundled": true, "dev": true, + "optional": true, "requires": { "minimist": "0.0.8" } @@ -4910,7 +4921,8 @@ "number-is-nan": { "version": "1.0.1", "bundled": true, - "dev": true + "dev": true, + "optional": true }, "object-assign": { "version": "4.1.1", @@ -4922,6 +4934,7 @@ "version": "1.4.0", "bundled": true, "dev": true, + "optional": true, "requires": { "wrappy": "1" } @@ -5043,6 +5056,7 @@ "version": "1.0.2", "bundled": true, "dev": true, + "optional": true, "requires": { "code-point-at": "^1.0.0", "is-fullwidth-code-point": "^1.0.0", diff --git a/package.json b/package.json index eecbe4919..3aa9a97a2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cropperjs", "description": "JavaScript image cropper.", - "version": "1.3.6", + "version": "1.4.0", "main": "dist/cropper.common.js", "module": "dist/cropper.esm.js", "unpkg": "dist/cropper.js",