|
1 | 1 | /*!
|
2 |
| - * Cropper.js v1.5.6 |
| 2 | + * Cropper.js v1.5.9 |
3 | 3 | * https://fengyuanchen.github.io/cropperjs
|
4 | 4 | *
|
5 | 5 | * Copyright 2015-present Chen Fengyuan
|
6 | 6 | * Released under the MIT license
|
7 | 7 | *
|
8 |
| - * Date: 2019-10-04T04:33:48.372Z |
| 8 | + * Date: 2020-09-10T13:16:26.743Z |
9 | 9 | */
|
10 | 10 |
|
11 | 11 | (function (global, factory) {
|
12 | 12 | typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
13 | 13 | typeof define === 'function' && define.amd ? define(factory) :
|
14 |
| - (global = global || self, global.Cropper = factory()); |
15 |
| -}(this, function () { 'use strict'; |
| 14 | + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Cropper = factory()); |
| 15 | +}(this, (function () { 'use strict'; |
16 | 16 |
|
17 | 17 | function _typeof(obj) {
|
| 18 | + "@babel/helpers - typeof"; |
| 19 | + |
18 | 20 | if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
|
19 | 21 | _typeof = function (obj) {
|
20 | 22 | return typeof obj;
|
|
84 | 86 | var source = arguments[i] != null ? arguments[i] : {};
|
85 | 87 |
|
86 | 88 | if (i % 2) {
|
87 |
| - ownKeys(source, true).forEach(function (key) { |
| 89 | + ownKeys(Object(source), true).forEach(function (key) { |
88 | 90 | _defineProperty(target, key, source[key]);
|
89 | 91 | });
|
90 | 92 | } else if (Object.getOwnPropertyDescriptors) {
|
91 | 93 | Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
|
92 | 94 | } else {
|
93 |
| - ownKeys(source).forEach(function (key) { |
| 95 | + ownKeys(Object(source)).forEach(function (key) { |
94 | 96 | Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
|
95 | 97 | });
|
96 | 98 | }
|
|
100 | 102 | }
|
101 | 103 |
|
102 | 104 | function _toConsumableArray(arr) {
|
103 |
| - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); |
| 105 | + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); |
104 | 106 | }
|
105 | 107 |
|
106 | 108 | function _arrayWithoutHoles(arr) {
|
107 |
| - if (Array.isArray(arr)) { |
108 |
| - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; |
109 |
| - |
110 |
| - return arr2; |
111 |
| - } |
| 109 | + if (Array.isArray(arr)) return _arrayLikeToArray(arr); |
112 | 110 | }
|
113 | 111 |
|
114 | 112 | function _iterableToArray(iter) {
|
115 |
| - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); |
| 113 | + if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); |
| 114 | + } |
| 115 | + |
| 116 | + function _unsupportedIterableToArray(o, minLen) { |
| 117 | + if (!o) return; |
| 118 | + if (typeof o === "string") return _arrayLikeToArray(o, minLen); |
| 119 | + var n = Object.prototype.toString.call(o).slice(8, -1); |
| 120 | + if (n === "Object" && o.constructor) n = o.constructor.name; |
| 121 | + if (n === "Map" || n === "Set") return Array.from(o); |
| 122 | + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); |
| 123 | + } |
| 124 | + |
| 125 | + function _arrayLikeToArray(arr, len) { |
| 126 | + if (len == null || len > arr.length) len = arr.length; |
| 127 | + |
| 128 | + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; |
| 129 | + |
| 130 | + return arr2; |
116 | 131 | }
|
117 | 132 |
|
118 | 133 | function _nonIterableSpread() {
|
119 |
| - throw new TypeError("Invalid attempt to spread non-iterable instance"); |
| 134 | + throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); |
120 | 135 | }
|
121 | 136 |
|
122 | 137 | var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined';
|
123 | 138 | var WINDOW = IS_BROWSER ? window : {};
|
124 |
| - var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false; |
| 139 | + var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false; |
125 | 140 | var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false;
|
126 | 141 | var NAMESPACE = 'cropper'; // Actions
|
127 | 142 |
|
|
242 | 257 | minCanvasHeight: 0,
|
243 | 258 | minCropBoxWidth: 0,
|
244 | 259 | minCropBoxHeight: 0,
|
245 |
| - minContainerWidth: 200, |
246 |
| - minContainerHeight: 100, |
| 260 | + minContainerWidth: MIN_CONTAINER_WIDTH, |
| 261 | + minContainerHeight: MIN_CONTAINER_HEIGHT, |
247 | 262 | // Shortcuts of events
|
248 | 263 | ready: null,
|
249 | 264 | cropstart: null,
|
|
386 | 401 | var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/;
|
387 | 402 | /**
|
388 | 403 | * Normalize decimal number.
|
389 |
| - * Check out {@link http://0.30000000000000004.com/} |
| 404 | + * Check out {@link https://0.30000000000000004.com/} |
390 | 405 | * @param {number} value - The value to normalize.
|
391 | 406 | * @param {number} [times=100000000000] - The times for normalizing.
|
392 | 407 | * @returns {number} Returns the normalized number.
|
|
791 | 806 | function getMaxZoomRatio(pointers) {
|
792 | 807 | var pointers2 = _objectSpread2({}, pointers);
|
793 | 808 |
|
794 |
| - var ratios = []; |
| 809 | + var maxRatio = 0; |
795 | 810 | forEach(pointers, function (pointer, pointerId) {
|
796 | 811 | delete pointers2[pointerId];
|
797 | 812 | forEach(pointers2, function (pointer2) {
|
|
802 | 817 | var z1 = Math.sqrt(x1 * x1 + y1 * y1);
|
803 | 818 | var z2 = Math.sqrt(x2 * x2 + y2 * y2);
|
804 | 819 | var ratio = (z2 - z1) / z1;
|
805 |
| - ratios.push(ratio); |
| 820 | + |
| 821 | + if (Math.abs(ratio) > Math.abs(maxRatio)) { |
| 822 | + maxRatio = ratio; |
| 823 | + } |
806 | 824 | });
|
807 | 825 | });
|
808 |
| - ratios.sort(function (a, b) { |
809 |
| - return Math.abs(a) < Math.abs(b); |
810 |
| - }); |
811 |
| - return ratios[0]; |
| 826 | + return maxRatio; |
812 | 827 | }
|
813 | 828 | /**
|
814 | 829 | * Get a pointer from an event object.
|
|
1187 | 1202 | case 8:
|
1188 | 1203 | rotate = -90;
|
1189 | 1204 | break;
|
1190 |
| - |
1191 |
| - default: |
1192 | 1205 | }
|
1193 | 1206 |
|
1194 | 1207 | return {
|
|
1214 | 1227 | options = this.options,
|
1215 | 1228 | container = this.container,
|
1216 | 1229 | cropper = this.cropper;
|
| 1230 | + var minWidth = Number(options.minContainerWidth); |
| 1231 | + var minHeight = Number(options.minContainerHeight); |
1217 | 1232 | addClass(cropper, CLASS_HIDDEN);
|
1218 | 1233 | removeClass(element, CLASS_HIDDEN);
|
1219 | 1234 | var containerData = {
|
1220 |
| - width: Math.max(container.offsetWidth, Number(options.minContainerWidth) || 200), |
1221 |
| - height: Math.max(container.offsetHeight, Number(options.minContainerHeight) || 100) |
| 1235 | + width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH), |
| 1236 | + height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT) |
1222 | 1237 | };
|
1223 | 1238 | this.containerData = containerData;
|
1224 | 1239 | setStyle(cropper, {
|
|
1259 | 1274 | width: canvasWidth,
|
1260 | 1275 | height: canvasHeight
|
1261 | 1276 | };
|
1262 |
| - canvasData.left = (containerData.width - canvasWidth) / 2; |
1263 |
| - canvasData.top = (containerData.height - canvasHeight) / 2; |
1264 |
| - canvasData.oldLeft = canvasData.left; |
1265 |
| - canvasData.oldTop = canvasData.top; |
1266 | 1277 | this.canvasData = canvasData;
|
1267 | 1278 | this.limited = viewMode === 1 || viewMode === 2;
|
1268 | 1279 | this.limitCanvas(true, true);
|
1269 |
| - this.initialImageData = assign({}, imageData); |
| 1280 | + canvasData.width = Math.min(Math.max(canvasData.width, canvasData.minWidth), canvasData.maxWidth); |
| 1281 | + canvasData.height = Math.min(Math.max(canvasData.height, canvasData.minHeight), canvasData.maxHeight); |
| 1282 | + canvasData.left = (containerData.width - canvasData.width) / 2; |
| 1283 | + canvasData.top = (containerData.height - canvasData.height) / 2; |
| 1284 | + canvasData.oldLeft = canvasData.left; |
| 1285 | + canvasData.oldTop = canvasData.top; |
1270 | 1286 | this.initialCanvasData = assign({}, canvasData);
|
1271 | 1287 | },
|
1272 | 1288 | limitCanvas: function limitCanvas(sizeLimited, positionLimited) {
|
|
1793 | 1809 |
|
1794 | 1810 | var handlers = {
|
1795 | 1811 | resize: function resize() {
|
1796 |
| - var options = this.options, |
1797 |
| - container = this.container, |
1798 |
| - containerData = this.containerData; |
1799 |
| - var minContainerWidth = Number(options.minContainerWidth) || MIN_CONTAINER_WIDTH; |
1800 |
| - var minContainerHeight = Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT; |
1801 |
| - |
1802 |
| - if (this.disabled || containerData.width <= minContainerWidth || containerData.height <= minContainerHeight) { |
| 1812 | + if (this.disabled) { |
1803 | 1813 | return;
|
1804 | 1814 | }
|
1805 | 1815 |
|
| 1816 | + var options = this.options, |
| 1817 | + container = this.container, |
| 1818 | + containerData = this.containerData; |
1806 | 1819 | var ratio = container.offsetWidth / containerData.width; // Resize when width changed or height changed
|
1807 | 1820 |
|
1808 | 1821 | if (ratio !== 1 || container.offsetHeight !== containerData.height) {
|
|
2050 | 2063 | }
|
2051 | 2064 |
|
2052 | 2065 | break;
|
2053 |
| - |
2054 |
| - default: |
2055 | 2066 | }
|
2056 | 2067 | };
|
2057 | 2068 |
|
|
2416 | 2427 | }
|
2417 | 2428 |
|
2418 | 2429 | break;
|
2419 |
| - |
2420 |
| - default: |
2421 | 2430 | }
|
2422 | 2431 |
|
2423 | 2432 | if (renderable) {
|
|
3199 | 3208 |
|
3200 | 3209 | var AnotherCropper = WINDOW.Cropper;
|
3201 | 3210 |
|
3202 |
| - var Cropper = |
3203 |
| - /*#__PURE__*/ |
3204 |
| - function () { |
| 3211 | + var Cropper = /*#__PURE__*/function () { |
3205 | 3212 | /**
|
3206 | 3213 | * Create a new Cropper.
|
3207 | 3214 | * @param {Element} element - The target element for cropping.
|
|
3250 | 3257 |
|
3251 | 3258 | if (!url) {
|
3252 | 3259 | return;
|
3253 |
| - } // e.g.: "http://example.com/img/picture.jpg" |
| 3260 | + } // e.g.: "https://example.com/img/picture.jpg" |
3254 | 3261 |
|
3255 | 3262 |
|
3256 | 3263 | url = element.src;
|
|
3424 | 3431 | naturalHeight: naturalHeight,
|
3425 | 3432 | aspectRatio: naturalWidth / naturalHeight
|
3426 | 3433 | });
|
| 3434 | + _this2.initialImageData = assign({}, _this2.imageData); |
3427 | 3435 | _this2.sizing = false;
|
3428 | 3436 | _this2.sized = true;
|
3429 | 3437 |
|
|
3613 | 3621 |
|
3614 | 3622 | return Cropper;
|
3615 | 3623 |
|
3616 |
| -})); |
| 3624 | +}))); |
0 commit comments