升级cropper到最新版本v1.5.12
This commit is contained in:
@ -1,19 +1,57 @@
|
||||
/*!
|
||||
* Cropper.js v1.5.7
|
||||
* Cropper.js v1.5.12
|
||||
* https://fengyuanchen.github.io/cropperjs
|
||||
*
|
||||
* Copyright 2015-present Chen Fengyuan
|
||||
* Released under the MIT license
|
||||
*
|
||||
* Date: 2020-05-23T05:23:00.081Z
|
||||
* Date: 2021-06-12T08:00:17.411Z
|
||||
*/
|
||||
|
||||
(function (global, factory) {
|
||||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
||||
typeof define === 'function' && define.amd ? define(factory) :
|
||||
(global = global || self, global.Cropper = factory());
|
||||
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Cropper = factory());
|
||||
}(this, (function () { 'use strict';
|
||||
|
||||
function ownKeys(object, enumerableOnly) {
|
||||
var keys = Object.keys(object);
|
||||
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var symbols = Object.getOwnPropertySymbols(object);
|
||||
|
||||
if (enumerableOnly) {
|
||||
symbols = symbols.filter(function (sym) {
|
||||
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
||||
});
|
||||
}
|
||||
|
||||
keys.push.apply(keys, symbols);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
function _objectSpread2(target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i] != null ? arguments[i] : {};
|
||||
|
||||
if (i % 2) {
|
||||
ownKeys(Object(source), true).forEach(function (key) {
|
||||
_defineProperty(target, key, source[key]);
|
||||
});
|
||||
} else if (Object.getOwnPropertyDescriptors) {
|
||||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
||||
} else {
|
||||
ownKeys(Object(source)).forEach(function (key) {
|
||||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
function _typeof(obj) {
|
||||
"@babel/helpers - typeof";
|
||||
|
||||
@ -67,40 +105,6 @@
|
||||
return obj;
|
||||
}
|
||||
|
||||
function ownKeys(object, enumerableOnly) {
|
||||
var keys = Object.keys(object);
|
||||
|
||||
if (Object.getOwnPropertySymbols) {
|
||||
var symbols = Object.getOwnPropertySymbols(object);
|
||||
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
||||
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
||||
});
|
||||
keys.push.apply(keys, symbols);
|
||||
}
|
||||
|
||||
return keys;
|
||||
}
|
||||
|
||||
function _objectSpread2(target) {
|
||||
for (var i = 1; i < arguments.length; i++) {
|
||||
var source = arguments[i] != null ? arguments[i] : {};
|
||||
|
||||
if (i % 2) {
|
||||
ownKeys(Object(source), true).forEach(function (key) {
|
||||
_defineProperty(target, key, source[key]);
|
||||
});
|
||||
} else if (Object.getOwnPropertyDescriptors) {
|
||||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
||||
} else {
|
||||
ownKeys(Object(source)).forEach(function (key) {
|
||||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
function _toConsumableArray(arr) {
|
||||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
|
||||
}
|
||||
@ -110,7 +114,7 @@
|
||||
}
|
||||
|
||||
function _iterableToArray(iter) {
|
||||
if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
|
||||
if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
|
||||
}
|
||||
|
||||
function _unsupportedIterableToArray(o, minLen) {
|
||||
@ -190,6 +194,10 @@
|
||||
var REGEXP_DATA_URL = /^data:/;
|
||||
var REGEXP_DATA_URL_JPEG = /^data:image\/jpeg;base64,/;
|
||||
var REGEXP_TAG_NAME = /^img|canvas$/i; // Misc
|
||||
// Inspired by the default width and height of a canvas element.
|
||||
|
||||
var MIN_CONTAINER_WIDTH = 200;
|
||||
var MIN_CONTAINER_HEIGHT = 100;
|
||||
|
||||
var DEFAULTS = {
|
||||
// Define the view mode of the cropper
|
||||
@ -253,8 +261,8 @@
|
||||
minCanvasHeight: 0,
|
||||
minCropBoxWidth: 0,
|
||||
minCropBoxHeight: 0,
|
||||
minContainerWidth: 200,
|
||||
minContainerHeight: 100,
|
||||
minContainerWidth: MIN_CONTAINER_WIDTH,
|
||||
minContainerHeight: MIN_CONTAINER_HEIGHT,
|
||||
// Shortcuts of events
|
||||
ready: null,
|
||||
cropstart: null,
|
||||
@ -802,7 +810,7 @@
|
||||
function getMaxZoomRatio(pointers) {
|
||||
var pointers2 = _objectSpread2({}, pointers);
|
||||
|
||||
var ratios = [];
|
||||
var maxRatio = 0;
|
||||
forEach(pointers, function (pointer, pointerId) {
|
||||
delete pointers2[pointerId];
|
||||
forEach(pointers2, function (pointer2) {
|
||||
@ -813,13 +821,13 @@
|
||||
var z1 = Math.sqrt(x1 * x1 + y1 * y1);
|
||||
var z2 = Math.sqrt(x2 * x2 + y2 * y2);
|
||||
var ratio = (z2 - z1) / z1;
|
||||
ratios.push(ratio);
|
||||
|
||||
if (Math.abs(ratio) > Math.abs(maxRatio)) {
|
||||
maxRatio = ratio;
|
||||
}
|
||||
});
|
||||
});
|
||||
ratios.sort(function (a, b) {
|
||||
return Math.abs(a) < Math.abs(b);
|
||||
});
|
||||
return ratios[0];
|
||||
return maxRatio;
|
||||
}
|
||||
/**
|
||||
* Get a pointer from an event object.
|
||||
@ -1223,11 +1231,13 @@
|
||||
options = this.options,
|
||||
container = this.container,
|
||||
cropper = this.cropper;
|
||||
var minWidth = Number(options.minContainerWidth);
|
||||
var minHeight = Number(options.minContainerHeight);
|
||||
addClass(cropper, CLASS_HIDDEN);
|
||||
removeClass(element, CLASS_HIDDEN);
|
||||
var containerData = {
|
||||
width: Math.max(container.offsetWidth, Number(options.minContainerWidth) || 200),
|
||||
height: Math.max(container.offsetHeight, Number(options.minContainerHeight) || 100)
|
||||
width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH),
|
||||
height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT)
|
||||
};
|
||||
this.containerData = containerData;
|
||||
setStyle(cropper, {
|
||||
@ -1268,14 +1278,15 @@
|
||||
width: canvasWidth,
|
||||
height: canvasHeight
|
||||
};
|
||||
canvasData.left = (containerData.width - canvasWidth) / 2;
|
||||
canvasData.top = (containerData.height - canvasHeight) / 2;
|
||||
canvasData.oldLeft = canvasData.left;
|
||||
canvasData.oldTop = canvasData.top;
|
||||
this.canvasData = canvasData;
|
||||
this.limited = viewMode === 1 || viewMode === 2;
|
||||
this.limitCanvas(true, true);
|
||||
this.initialImageData = assign({}, imageData);
|
||||
canvasData.width = Math.min(Math.max(canvasData.width, canvasData.minWidth), canvasData.maxWidth);
|
||||
canvasData.height = Math.min(Math.max(canvasData.height, canvasData.minHeight), canvasData.maxHeight);
|
||||
canvasData.left = (containerData.width - canvasData.width) / 2;
|
||||
canvasData.top = (containerData.height - canvasData.height) / 2;
|
||||
canvasData.oldLeft = canvasData.left;
|
||||
canvasData.oldTop = canvasData.top;
|
||||
this.initialCanvasData = assign({}, canvasData);
|
||||
},
|
||||
limitCanvas: function limitCanvas(sizeLimited, positionLimited) {
|
||||
@ -1809,9 +1820,11 @@
|
||||
var options = this.options,
|
||||
container = this.container,
|
||||
containerData = this.containerData;
|
||||
var ratio = container.offsetWidth / containerData.width; // Resize when width changed or height changed
|
||||
var ratioX = container.offsetWidth / containerData.width;
|
||||
var ratioY = container.offsetHeight / containerData.height;
|
||||
var ratio = Math.abs(ratioX - 1) > Math.abs(ratioY - 1) ? ratioX : ratioY; // Resize when width changed or height changed
|
||||
|
||||
if (ratio !== 1 || container.offsetHeight !== containerData.height) {
|
||||
if (ratio !== 1) {
|
||||
var canvasData;
|
||||
var cropBoxData;
|
||||
|
||||
@ -3331,9 +3344,10 @@
|
||||
|
||||
if (options.checkCrossOrigin && isCrossOriginURL(url) && element.crossOrigin) {
|
||||
url = addTimestamp(url);
|
||||
}
|
||||
} // The third parameter is required for avoiding side-effect (#682)
|
||||
|
||||
xhr.open('GET', url);
|
||||
|
||||
xhr.open('GET', url, true);
|
||||
xhr.responseType = 'arraybuffer';
|
||||
xhr.withCredentials = element.crossOrigin === 'use-credentials';
|
||||
xhr.send();
|
||||
@ -3424,6 +3438,7 @@
|
||||
naturalHeight: naturalHeight,
|
||||
aspectRatio: naturalWidth / naturalHeight
|
||||
});
|
||||
_this2.initialImageData = assign({}, _this2.imageData);
|
||||
_this2.sizing = false;
|
||||
_this2.sized = true;
|
||||
|
||||
|
Reference in New Issue
Block a user