diff --git a/CHANGELOG.md b/CHANGELOG.md index 3146e4c6e..ef12742fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,6 @@ # Changelog -## next +## 2.0.0-alpha.2 (Dec 25, 2021) - Fix the cropper responsive when only the height was changed (#835). - Fix TypeScript declarations compatibility (#799). diff --git a/dist/cropper.common.js b/dist/cropper.common.js index 0aca59d53..0e5697ad5 100644 --- a/dist/cropper.common.js +++ b/dist/cropper.common.js @@ -1,27 +1,49 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:24.890Z + * Date: 2021-12-25T08:31:12.767Z */ 'use strict'; -function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); } - return _typeof(obj); + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); } function _classCallCheck(instance, Constructor) { @@ -43,6 +65,9 @@ function _defineProperties(target, props) { function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); return Constructor; } @@ -61,63 +86,42 @@ function _defineProperty(obj, key, value) { 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 _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } -function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i] != null ? arguments[i] : {}; - - if (i % 2) { - ownKeys(source, true).forEach(function (key) { - _defineProperty(target, key, source[key]); - }); - } else if (Object.getOwnPropertyDescriptors) { - Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - } else { - ownKeys(source).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } - } +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); +} - return target; +function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); +function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(o); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; +function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; - return arr2; - } -} + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; -function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); + return arr2; } function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance"); + throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined'; var WINDOW = IS_BROWSER ? window : {}; -var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false; +var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false; var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false; var NAMESPACE = 'cropper'; // Actions @@ -348,10 +352,10 @@ function forEach(data, callback) { if (Array.isArray(data) || isNumber(data.length) /* array-like */ ) { - toArray(data).forEach(function (value, key) { - callback.call(data, value, key, data); - }); - } else if (isObject(data)) { + toArray(data).forEach(function (value, key) { + callback.call(data, value, key, data); + }); + } else if (isObject(data)) { Object.keys(data).forEach(function (key) { callback.call(data, data[key], key, data); }); @@ -387,7 +391,7 @@ var assign = Object.assign || function assign(target) { var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/; /** * Normalize decimal number. - * Check out {@link http://0.30000000000000004.com/} + * Check out {@link https://0.30000000000000004.com/} * @param {number} value - The value to normalize. * @param {number} [times=100000000000] - The times for normalizing. * @returns {number} Returns the normalized number. @@ -792,7 +796,7 @@ function getTransforms(_ref) { function getMaxZoomRatio(pointers) { var pointers2 = _objectSpread2({}, pointers); - var ratios = []; + var maxRatio = 0; forEach(pointers, function (pointer, pointerId) { delete pointers2[pointerId]; forEach(pointers2, function (pointer2) { @@ -803,13 +807,13 @@ function getMaxZoomRatio(pointers) { 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. @@ -861,8 +865,7 @@ function getPointersCenter(pointers) { * @returns {Object} The result sizes. */ -function getAdjustedSizes(_ref4) // or 'cover' -{ +function getAdjustedSizes(_ref4) { var aspectRatio = _ref4.aspectRatio, height = _ref4.height, width = _ref4.width; @@ -1100,14 +1103,14 @@ function resetAndGetOrientation(arrayBuffer) { if (littleEndian || endianness === 0x4D4D /* bigEndian */ ) { - if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { - var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); + if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { + var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); - if (firstIFDOffset >= 0x00000008) { - ifdStart = tiffOffset + firstIFDOffset; - } + if (firstIFDOffset >= 0x00000008) { + ifdStart = tiffOffset + firstIFDOffset; } } + } } } @@ -1124,14 +1127,14 @@ function resetAndGetOrientation(arrayBuffer) { if (dataView.getUint16(_offset, littleEndian) === 0x0112 /* Orientation */ ) { - // 8 is the offset of the current tag's value - _offset += 8; // Get the original orientation value + // 8 is the offset of the current tag's value + _offset += 8; // Get the original orientation value - orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value + orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value - dataView.setUint16(_offset, 1, littleEndian); - break; - } + dataView.setUint16(_offset, 1, littleEndian); + break; + } } } } catch (error) { @@ -1201,9 +1204,10 @@ var render = { render: function render() { this.initContainer(); this.initCanvas(); - this.initCropBox(); - this.initialImageData = assign({}, this.imageData); this.initialCanvasData = assign({}, this.canvasData); + this.initCropBox(); // Store the `initialCropBoxData` outside of the `initCropBox` method, + // just because the `initCropBox` method will be called more then once. + this.initialCropBoxData = assign({}, this.cropBoxData); this.renderCanvas(); @@ -1216,11 +1220,13 @@ var render = { 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) || MIN_CONTAINER_WIDTH), - height: Math.max(container.offsetHeight, Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT) + width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH), + height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT) }; setStyle(cropper, containerData); addClass(element, CLASS_HIDDEN); @@ -1812,19 +1818,18 @@ var events = { var handlers = { resize: function resize() { - var options = this.options, - container = this.container, - containerData = this.containerData; - var minContainerWidth = Number(options.minContainerWidth) || MIN_CONTAINER_WIDTH; - var minContainerHeight = Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT; - - if (this.disabled || containerData.width <= minContainerWidth || containerData.height <= minContainerHeight) { + if (this.disabled) { return; } - var ratio = container.offsetWidth / containerData.width; // Resize when width changed or height changed + var options = this.options, + container = this.container, + containerData = this.containerData; + 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; @@ -3265,9 +3270,7 @@ var methods = { var AnotherCropper = WINDOW.Cropper; -var Cropper = -/*#__PURE__*/ -function () { +var Cropper = /*#__PURE__*/function () { /** * Create a new Cropper. * @param {Element} element - The target element for cropping. @@ -3316,7 +3319,7 @@ function () { if (!url) { return; - } // e.g.: "http://example.com/img/picture.jpg" + } // e.g.: "https://example.com/img/picture.jpg" url = element.src; @@ -3397,9 +3400,10 @@ function () { 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(); @@ -3489,7 +3493,9 @@ function () { naturalWidth: naturalWidth, naturalHeight: naturalHeight, aspectRatio: naturalWidth / naturalHeight - }); + }); // Store the `initialImageData` here for avoiding side effect (jquery-cropper#19) + + _this2.initialImageData = assign({}, _this2.imageData); _this2.sizing = false; _this2.sized = true; diff --git a/dist/cropper.css b/dist/cropper.css index bcd00455c..5ef363931 100644 --- a/dist/cropper.css +++ b/dist/cropper.css @@ -1,11 +1,11 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:20.544Z + * Date: 2021-12-25T08:31:10.935Z */ .cropper-container { @@ -14,23 +14,22 @@ line-height: 0; overflow: hidden; position: relative; - -ms-touch-action: none; touch-action: none; -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none } .cropper-container img { - display: block; - height: 100%; - max-height: none !important; - max-width: none !important; - min-height: 0 !important; - min-width: 0 !important; - width: 100%; -} + display: block; + height: 100%; + max-height: none !important; + max-width: none !important; + min-height: 0 !important; + min-width: 0 !important; + width: 100%; + } .cropper-canvas, .cropper-drag-box, @@ -55,7 +54,7 @@ .cropper-view-box { height: 100%; outline: 1px solid #39f; - outline-color: rgba(51, 153, 255, 0.75); + outline-color: rgb(51 153 255 / 75%); overflow: hidden; width: 100%; } @@ -63,26 +62,26 @@ .cropper-dashed { border: 0 dashed #eee; opacity: 0.5; - position: absolute; + position: absolute } .cropper-dashed.dashed-h { - border-bottom-width: 1px; - border-top-width: 1px; - height: calc(100% / 3); - left: 0; - top: calc(100% / 3); - width: 100%; -} + border-bottom-width: 1px; + border-top-width: 1px; + height: calc(100% / 3); + left: 0; + top: calc(100% / 3); + width: 100%; + } .cropper-dashed.dashed-v { - border-left-width: 1px; - border-right-width: 1px; - height: 100%; - left: calc(100% / 3); - top: 0; - width: calc(100% / 3); -} + border-left-width: 1px; + border-right-width: 1px; + height: 100%; + left: calc(100% / 3); + top: 0; + width: calc(100% / 3); + } .cropper-center { height: 0; @@ -90,30 +89,30 @@ opacity: 0.75; position: absolute; top: 50%; - width: 0; + width: 0 } .cropper-center::before, -.cropper-center::after { - background-color: #eee; - content: ""; - display: block; - position: absolute; -} + .cropper-center::after { + background-color: #eee; + content: " "; + display: block; + position: absolute; + } .cropper-center::before { - height: 1px; - left: -3px; - top: 0; - width: 7px; -} + height: 1px; + left: -3px; + top: 0; + width: 7px; + } .cropper-center::after { - height: 7px; - left: 0; - top: -3px; - width: 1px; -} + height: 7px; + left: 0; + top: -3px; + width: 1px; + } .cropper-face, .cropper-line, @@ -131,139 +130,142 @@ } .cropper-line { - background-color: #39f; + background-color: #39f } .cropper-line.line-e { - cursor: ew-resize; - right: -3px; - top: 0; - width: 5px; -} + cursor: ew-resize; + right: -3px; + top: 0; + width: 5px; + } .cropper-line.line-n { - cursor: ns-resize; - height: 5px; - left: 0; - top: -3px; -} + cursor: ns-resize; + height: 5px; + left: 0; + top: -3px; + } .cropper-line.line-w { - cursor: ew-resize; - left: -3px; - top: 0; - width: 5px; -} + cursor: ew-resize; + left: -3px; + top: 0; + width: 5px; + } .cropper-line.line-s { - bottom: -3px; - cursor: ns-resize; - height: 5px; - left: 0; -} + bottom: -3px; + cursor: ns-resize; + height: 5px; + left: 0; + } .cropper-point { background-color: #39f; height: 5px; opacity: 0.75; - width: 5px; + width: 5px } .cropper-point.point-e { - cursor: ew-resize; - margin-top: -3px; - right: -3px; - top: 50%; -} + cursor: ew-resize; + margin-top: -3px; + right: -3px; + top: 50%; + } .cropper-point.point-n { - cursor: ns-resize; - left: 50%; - margin-left: -3px; - top: -3px; -} + cursor: ns-resize; + left: 50%; + margin-left: -3px; + top: -3px; + } .cropper-point.point-w { - cursor: ew-resize; - left: -3px; - margin-top: -3px; - top: 50%; -} + cursor: ew-resize; + left: -3px; + margin-top: -3px; + top: 50%; + } .cropper-point.point-s { - bottom: -3px; - cursor: s-resize; - left: 50%; - margin-left: -3px; -} + bottom: -3px; + cursor: s-resize; + left: 50%; + margin-left: -3px; + } .cropper-point.point-ne { - cursor: nesw-resize; - right: -3px; - top: -3px; -} + cursor: nesw-resize; + right: -3px; + top: -3px; + } .cropper-point.point-nw { - cursor: nwse-resize; - left: -3px; - top: -3px; -} + cursor: nwse-resize; + left: -3px; + top: -3px; + } .cropper-point.point-sw { - bottom: -3px; - cursor: nesw-resize; - left: -3px; -} + bottom: -3px; + cursor: nesw-resize; + left: -3px; + } .cropper-point.point-se { - bottom: -3px; - cursor: nwse-resize; - height: 20px; - opacity: 1; - right: -3px; - width: 20px; -} + 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; + +.cropper-point.point-se { + height: 15px; + width: 15px } -} + } @media (min-width: 992px) { - .cropper-point.point-se { - height: 10px; - width: 10px; + +.cropper-point.point-se { + height: 10px; + width: 10px } -} + } @media (min-width: 1200px) { - .cropper-point.point-se { - height: 5px; - opacity: 0.75; - width: 5px; + +.cropper-point.point-se { + height: 5px; + opacity: 0.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%; -} + 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'); + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC"); } .cropper-hide { @@ -286,8 +288,8 @@ } .cropper-disabled .cropper-drag-box, -.cropper-disabled .cropper-face, -.cropper-disabled .cropper-line, -.cropper-disabled .cropper-point { - cursor: not-allowed; -} + .cropper-disabled .cropper-face, + .cropper-disabled .cropper-line, + .cropper-disabled .cropper-point { + cursor: not-allowed; + } diff --git a/dist/cropper.esm.js b/dist/cropper.esm.js index 856f36aa5..8b4c39314 100644 --- a/dist/cropper.esm.js +++ b/dist/cropper.esm.js @@ -1,25 +1,47 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:24.890Z + * Date: 2021-12-25T08:31:12.767Z */ -function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; +function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); } - return _typeof(obj); + return keys; +} + +function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; +} + +function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); } function _classCallCheck(instance, Constructor) { @@ -41,6 +63,9 @@ function _defineProperties(target, props) { function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); return Constructor; } @@ -59,63 +84,42 @@ function _defineProperty(obj, key, value) { 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 _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } -function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i] != null ? arguments[i] : {}; - - if (i % 2) { - ownKeys(source, true).forEach(function (key) { - _defineProperty(target, key, source[key]); - }); - } else if (Object.getOwnPropertyDescriptors) { - Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - } else { - ownKeys(source).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } - } +function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); +} - return target; +function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } -function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); +function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(o); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } -function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; +function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; - return arr2; - } -} + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; -function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); + return arr2; } function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance"); + throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined'; var WINDOW = IS_BROWSER ? window : {}; -var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false; +var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false; var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false; var NAMESPACE = 'cropper'; // Actions @@ -346,10 +350,10 @@ function forEach(data, callback) { if (Array.isArray(data) || isNumber(data.length) /* array-like */ ) { - toArray(data).forEach(function (value, key) { - callback.call(data, value, key, data); - }); - } else if (isObject(data)) { + toArray(data).forEach(function (value, key) { + callback.call(data, value, key, data); + }); + } else if (isObject(data)) { Object.keys(data).forEach(function (key) { callback.call(data, data[key], key, data); }); @@ -385,7 +389,7 @@ var assign = Object.assign || function assign(target) { var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/; /** * Normalize decimal number. - * Check out {@link http://0.30000000000000004.com/} + * Check out {@link https://0.30000000000000004.com/} * @param {number} value - The value to normalize. * @param {number} [times=100000000000] - The times for normalizing. * @returns {number} Returns the normalized number. @@ -790,7 +794,7 @@ function getTransforms(_ref) { function getMaxZoomRatio(pointers) { var pointers2 = _objectSpread2({}, pointers); - var ratios = []; + var maxRatio = 0; forEach(pointers, function (pointer, pointerId) { delete pointers2[pointerId]; forEach(pointers2, function (pointer2) { @@ -801,13 +805,13 @@ function getMaxZoomRatio(pointers) { 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. @@ -859,8 +863,7 @@ function getPointersCenter(pointers) { * @returns {Object} The result sizes. */ -function getAdjustedSizes(_ref4) // or 'cover' -{ +function getAdjustedSizes(_ref4) { var aspectRatio = _ref4.aspectRatio, height = _ref4.height, width = _ref4.width; @@ -1098,14 +1101,14 @@ function resetAndGetOrientation(arrayBuffer) { if (littleEndian || endianness === 0x4D4D /* bigEndian */ ) { - if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { - var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); + if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { + var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); - if (firstIFDOffset >= 0x00000008) { - ifdStart = tiffOffset + firstIFDOffset; - } + if (firstIFDOffset >= 0x00000008) { + ifdStart = tiffOffset + firstIFDOffset; } } + } } } @@ -1122,14 +1125,14 @@ function resetAndGetOrientation(arrayBuffer) { if (dataView.getUint16(_offset, littleEndian) === 0x0112 /* Orientation */ ) { - // 8 is the offset of the current tag's value - _offset += 8; // Get the original orientation value + // 8 is the offset of the current tag's value + _offset += 8; // Get the original orientation value - orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value + orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value - dataView.setUint16(_offset, 1, littleEndian); - break; - } + dataView.setUint16(_offset, 1, littleEndian); + break; + } } } } catch (error) { @@ -1199,9 +1202,10 @@ var render = { render: function render() { this.initContainer(); this.initCanvas(); - this.initCropBox(); - this.initialImageData = assign({}, this.imageData); this.initialCanvasData = assign({}, this.canvasData); + this.initCropBox(); // Store the `initialCropBoxData` outside of the `initCropBox` method, + // just because the `initCropBox` method will be called more then once. + this.initialCropBoxData = assign({}, this.cropBoxData); this.renderCanvas(); @@ -1214,11 +1218,13 @@ var render = { 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) || MIN_CONTAINER_WIDTH), - height: Math.max(container.offsetHeight, Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT) + width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH), + height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT) }; setStyle(cropper, containerData); addClass(element, CLASS_HIDDEN); @@ -1810,19 +1816,18 @@ var events = { var handlers = { resize: function resize() { - var options = this.options, - container = this.container, - containerData = this.containerData; - var minContainerWidth = Number(options.minContainerWidth) || MIN_CONTAINER_WIDTH; - var minContainerHeight = Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT; - - if (this.disabled || containerData.width <= minContainerWidth || containerData.height <= minContainerHeight) { + if (this.disabled) { return; } - var ratio = container.offsetWidth / containerData.width; // Resize when width changed or height changed + var options = this.options, + container = this.container, + containerData = this.containerData; + 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; @@ -3263,9 +3268,7 @@ var methods = { var AnotherCropper = WINDOW.Cropper; -var Cropper = -/*#__PURE__*/ -function () { +var Cropper = /*#__PURE__*/function () { /** * Create a new Cropper. * @param {Element} element - The target element for cropping. @@ -3314,7 +3317,7 @@ function () { if (!url) { return; - } // e.g.: "http://example.com/img/picture.jpg" + } // e.g.: "https://example.com/img/picture.jpg" url = element.src; @@ -3395,9 +3398,10 @@ function () { 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(); @@ -3487,7 +3491,9 @@ function () { naturalWidth: naturalWidth, naturalHeight: naturalHeight, aspectRatio: naturalWidth / naturalHeight - }); + }); // Store the `initialImageData` here for avoiding side effect (jquery-cropper#19) + + _this2.initialImageData = assign({}, _this2.imageData); _this2.sizing = false; _this2.sized = true; @@ -3675,4 +3681,4 @@ function () { assign(Cropper.prototype, render, preview, events, handlers, change, methods); -export default Cropper; +export { Cropper as default }; diff --git a/dist/cropper.js b/dist/cropper.js index 5a912267d..fb892d9d9 100644 --- a/dist/cropper.js +++ b/dist/cropper.js @@ -1,31 +1,53 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:24.890Z + * Date: 2021-12-25T08:31:12.767Z */ (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()); -}(this, (function () { 'use strict'; + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Cropper = factory()); +})(this, (function () { 'use strict'; - function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); } - return _typeof(obj); + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); } function _classCallCheck(instance, Constructor) { @@ -47,6 +69,9 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); return Constructor; } @@ -65,63 +90,42 @@ 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 _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } - function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i] != null ? arguments[i] : {}; - - if (i % 2) { - ownKeys(source, true).forEach(function (key) { - _defineProperty(target, key, source[key]); - }); - } else if (Object.getOwnPropertyDescriptors) { - Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - } else { - ownKeys(source).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } - } + function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + } - return target; + function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } - function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); + function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(o); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; - return arr2; - } - } + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; - function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); + return arr2; } function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance"); + throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined'; var WINDOW = IS_BROWSER ? window : {}; - var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false; + var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false; var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false; var NAMESPACE = 'cropper'; // Actions @@ -352,10 +356,10 @@ if (Array.isArray(data) || isNumber(data.length) /* array-like */ ) { - toArray(data).forEach(function (value, key) { - callback.call(data, value, key, data); - }); - } else if (isObject(data)) { + toArray(data).forEach(function (value, key) { + callback.call(data, value, key, data); + }); + } else if (isObject(data)) { Object.keys(data).forEach(function (key) { callback.call(data, data[key], key, data); }); @@ -391,7 +395,7 @@ var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/; /** * Normalize decimal number. - * Check out {@link http://0.30000000000000004.com/} + * Check out {@link https://0.30000000000000004.com/} * @param {number} value - The value to normalize. * @param {number} [times=100000000000] - The times for normalizing. * @returns {number} Returns the normalized number. @@ -796,7 +800,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) { @@ -807,13 +811,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. @@ -865,8 +869,7 @@ * @returns {Object} The result sizes. */ - function getAdjustedSizes(_ref4) // or 'cover' - { + function getAdjustedSizes(_ref4) { var aspectRatio = _ref4.aspectRatio, height = _ref4.height, width = _ref4.width; @@ -1104,14 +1107,14 @@ if (littleEndian || endianness === 0x4D4D /* bigEndian */ ) { - if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { - var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); + if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { + var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); - if (firstIFDOffset >= 0x00000008) { - ifdStart = tiffOffset + firstIFDOffset; - } + if (firstIFDOffset >= 0x00000008) { + ifdStart = tiffOffset + firstIFDOffset; } } + } } } @@ -1128,14 +1131,14 @@ if (dataView.getUint16(_offset, littleEndian) === 0x0112 /* Orientation */ ) { - // 8 is the offset of the current tag's value - _offset += 8; // Get the original orientation value + // 8 is the offset of the current tag's value + _offset += 8; // Get the original orientation value - orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value + orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value - dataView.setUint16(_offset, 1, littleEndian); - break; - } + dataView.setUint16(_offset, 1, littleEndian); + break; + } } } } catch (error) { @@ -1205,9 +1208,10 @@ render: function render() { this.initContainer(); this.initCanvas(); - this.initCropBox(); - this.initialImageData = assign({}, this.imageData); this.initialCanvasData = assign({}, this.canvasData); + this.initCropBox(); // Store the `initialCropBoxData` outside of the `initCropBox` method, + // just because the `initCropBox` method will be called more then once. + this.initialCropBoxData = assign({}, this.cropBoxData); this.renderCanvas(); @@ -1220,11 +1224,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) || MIN_CONTAINER_WIDTH), - height: Math.max(container.offsetHeight, Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT) + width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH), + height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT) }; setStyle(cropper, containerData); addClass(element, CLASS_HIDDEN); @@ -1816,19 +1822,18 @@ var handlers = { resize: function resize() { - var options = this.options, - container = this.container, - containerData = this.containerData; - var minContainerWidth = Number(options.minContainerWidth) || MIN_CONTAINER_WIDTH; - var minContainerHeight = Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT; - - if (this.disabled || containerData.width <= minContainerWidth || containerData.height <= minContainerHeight) { + if (this.disabled) { return; } - var ratio = container.offsetWidth / containerData.width; // Resize when width changed or height changed + var options = this.options, + container = this.container, + containerData = this.containerData; + 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; @@ -3269,9 +3274,7 @@ var AnotherCropper = WINDOW.Cropper; - var Cropper = - /*#__PURE__*/ - function () { + var Cropper = /*#__PURE__*/function () { /** * Create a new Cropper. * @param {Element} element - The target element for cropping. @@ -3320,7 +3323,7 @@ if (!url) { return; - } // e.g.: "http://example.com/img/picture.jpg" + } // e.g.: "https://example.com/img/picture.jpg" url = element.src; @@ -3401,9 +3404,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(); @@ -3493,7 +3497,9 @@ naturalWidth: naturalWidth, naturalHeight: naturalHeight, aspectRatio: naturalWidth / naturalHeight - }); + }); // Store the `initialImageData` here for avoiding side effect (jquery-cropper#19) + + _this2.initialImageData = assign({}, _this2.imageData); _this2.sizing = false; _this2.sized = true; @@ -3683,4 +3689,4 @@ return Cropper; -}))); +})); diff --git a/dist/cropper.min.css b/dist/cropper.min.css index 62c88cc01..a34d5fc6c 100644 --- a/dist/cropper.min.css +++ b/dist/cropper.min.css @@ -1,9 +1,9 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:20.544Z - */.cropper-container{direction:ltr;font-size:0;line-height:0;overflow:hidden;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%;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{left:0;position:absolute;top:0}.cropper-drag-box{background-color:#fff;bottom:0;opacity:0;right:0}.cropper-modal{background-color:#000;opacity:.5}.cropper-view-box{height:100%;outline:1px solid #39f;outline-color:rgba(51,153,255,.75);overflow:hidden;width:100%}.cropper-dashed{border:0 dashed #eee;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{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{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 + * Date: 2021-12-25T08:31:10.935Z + */.cropper-container{direction:ltr;font-size:0;line-height:0;overflow:hidden;position:relative;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%;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{left:0;position:absolute;top:0}.cropper-drag-box{background-color:#fff;bottom:0;opacity:0;right:0}.cropper-modal{background-color:#000;opacity:.5}.cropper-view-box{height:100%;outline:1px solid #39f;outline-color:rgba(51,153,255,.75);overflow:hidden;width:100%}.cropper-dashed{border:0 dashed #eee;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{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{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 a22cffd45..4d3776658 100644 --- a/dist/cropper.min.js +++ b/dist/cropper.min.js @@ -1,10 +1,10 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:24.890Z + * Date: 2021-12-25T08:31:12.767Z */ -!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self).Cropper=e()}(this,function(){"use strict";function e(t){return(e="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})(t)}function a(t,e){for(var i=0;io.maxWidth||o.widtho.maxHeight||o.heighta.maxWidth||a.widtha.maxHeight||a.height=e.width&&a.height>=e.height?W:B),pt(this.cropBox,st({width:a.width,height:a.height},Et({translateX:a.left,translateY:a.top}))),this.disabled||this.output()},output:function(){this.preview(),Dt(this.element,b,this.getData())}},Lt={initPreview:function(){var t=this.element,i=this.crossOrigin,e=this.options.preview,a=i?this.crossOriginUrl:this.url,n=t.alt||"The image to preview",o=document.createElement("img");if(i&&(o.crossOrigin=i),o.src=a,o.alt=n,this.viewBox.appendChild(o),this.viewBoxImage=o,e){var r=e;"string"==typeof e?r=t.ownerDocument.querySelectorAll(e):e.querySelector&&(r=[e]),ht(this.previews=r,function(t){var e=document.createElement("img");bt(t,m,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),i&&(e.crossOrigin=i),e.src=a,e.alt=n,e.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(e)})}},resetPreview:function(){ht(this.previews,function(t){var e=wt(t,m);pt(t,{width:e.width,height:e.height}),t.innerHTML=e.html,function(e,i){if(et(e[i]))try{delete e[i]}catch(t){e[i]=void 0}else if(e.dataset)try{delete e.dataset[i]}catch(t){e.dataset[i]=void 0}else e.removeAttribute("data-".concat(vt(i)))}(t,m)})},preview:function(){var h=this.imageData,t=this.canvasData,e=this.cropBoxData,s=e.width,c=e.height,d=h.width,l=h.height,p=e.left-t.left-h.left,u=e.top-t.top-h.top;this.cropped&&!this.disabled&&(pt(this.viewBoxImage,st({width:d,height:l},Et(st({translateX:-p,translateY:-u},h)))),ht(this.previews,function(t){var e=wt(t,m),i=e.width,a=e.height,n=i,o=a,r=1;s&&(o=c*(r=i/s)),c&&af&&(y.x=f-p);break;case E:s+y.xv&&(y.y=v-u)}}var x=o[Object.keys(o)[0]],y={x:x.endX-x.startX,y:x.endY-x.startY};switch(r){case B:s+=y.x,c+=y.y;break;case H:if(0<=y.x&&(f<=p||h&&(c<=m||v<=u))){w=!1;break}b(H),(d+=y.x)<0&&(r=E,s-=d=-d),h&&(l=d/h,c+=(n.height-l)/2);break;case N:if(y.y<=0&&(c<=m||h&&(s<=g||f<=p))){w=!1;break}b(N),l-=y.y,c+=y.y,l<0&&(r=T,c-=l=-l),h&&(d=l*h,s+=(n.width-d)/2);break;case E:if(y.x<=0&&(s<=g||h&&(c<=m||v<=u))){w=!1;break}b(E),d-=y.x,s+=y.x,d<0&&(r=H,s-=d=-d),h&&(l=d/h,c+=(n.height-l)/2);break;case T:if(0<=y.y&&(v<=u||h&&(s<=g||f<=p))){w=!1;break}b(T),(l+=y.y)<0&&(r=N,c-=l=-l),h&&(d=l*h,s+=(n.width-d)/2);break;case z:if(h){if(y.y<=0&&(c<=m||f<=p)){w=!1;break}b(N),l-=y.y,c+=y.y,d=l*h}else b(N),b(H),0<=y.x?pr.maxWidth||u or element.");this.element=t,this.options=st({},V,at(e)&&e),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 function(t,e,i){e&&a(t.prototype,e),i&&a(t,i)}(i,[{key:"init",value:function(){var t,e=this.element,i=e.tagName.toLowerCase();if(!e[d]){if(e[d]=this,"img"===i){if(this.isImg=!0,t=e.getAttribute("src")||"",!(this.originalUrl=t))return;t=e.src}else"canvas"===i&&window.HTMLCanvasElement&&(t=e.toDataURL());this.load(t)}}},{key:"load",value:function(t){var e=this;if(t){this.url=t,this.imageData={};var i=this.element,a=this.options;if(a.rotatable||a.scalable||(a.checkOrientation=!1),a.checkOrientation&&window.ArrayBuffer)if(Q.test(t))K.test(t)?this.read(function(t){var e=t.replace(Yt,""),i=atob(e),a=new ArrayBuffer(i.length),n=new Uint8Array(a);return ht(n,function(t,e){n[e]=i.charCodeAt(e)}),a}(t)):this.clone();else{var n=new XMLHttpRequest,o=this.clone.bind(this);this.reloading=!0,(this.xhr=n).onabort=o,n.onerror=o,n.ontimeout=o,n.onprogress=function(){n.getResponseHeader("content-type")!==q&&n.abort()},n.onload=function(){e.read(n.response)},n.onloadend=function(){e.reloading=!1,e.xhr=null},a.checkCrossOrigin&&Ot(t)&&i.crossOrigin&&(t=Ht(t)),n.open("GET",t),n.responseType="arraybuffer",n.withCredentials="use-credentials"===i.crossOrigin,n.send()}else this.clone()}}},{key:"read",value:function(t){var e=this.options,i=this.imageData,a=Rt(t),n=0,o=1,r=1;if(1
';var o=n.querySelector(".".concat(d,"-container")),r=o.querySelector(".".concat(d,"-canvas")),h=o.querySelector(".".concat(d,"-drag-box")),s=o.querySelector(".".concat(d,"-crop-box")),c=s.querySelector(".".concat(d,"-face"));this.container=a,this.cropper=o,this.canvas=r,this.dragBox=h,this.cropBox=s,this.viewBox=o.querySelector(".".concat(d,"-view-box")),this.face=c,r.appendChild(i),ut(t,L),a.insertBefore(o,t.nextSibling),this.isImg||gt(i,l),this.initPreview(),this.bind(),e.initialAspectRatio=Math.max(0,e.initialAspectRatio)||NaN,e.aspectRatio=Math.max(0,e.aspectRatio)||NaN,e.viewMode=Math.max(0,Math.min(3,Math.round(e.viewMode)))||0,ut(s,L),e.guides||ut(s.getElementsByClassName("".concat(d,"-dashed")),L),e.center||ut(s.getElementsByClassName("".concat(d,"-center")),L),e.background&&ut(o,"".concat(d,"-bg")),e.highlight||ut(c,p),e.cropBoxMovable&&(ut(c,u),bt(c,g,B)),e.cropBoxResizable||(ut(s.getElementsByClassName("".concat(d,"-line")),L),ut(s.getElementsByClassName("".concat(d,"-point")),L)),this.render(),this.ready=!0,this.setDragMode(e.dragMode),e.autoCrop&&this.crop(),this.setData(e.data),nt(e.ready)&&Ct(t,I,e.ready,{once:!0}),Dt(t,I)}}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),gt(this.element,L))}},{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.onabort=null,this.xhr.abort()):this.image&&this.stop()}}],[{key:"noConflict",value:function(){return window.Cropper=It,i}},{key:"setDefaults",value:function(t){st(V,at(t)&&t)}}]),i}();return st(Ut.prototype,Xt,Lt,St,At,jt,Pt),Ut}); \ No newline at end of file +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t="undefined"!=typeof globalThis?globalThis:t||self).Cropper=e()}(this,function(){"use strict";function e(e,t){var i,a=Object.keys(e);return Object.getOwnPropertySymbols&&(i=Object.getOwnPropertySymbols(e),t&&(i=i.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),a.push.apply(a,i)),a}function k(a){for(var t=1;tt.length)&&(e=t.length);for(var i=0,a=new Array(e);ir.maxWidth||r.widthr.maxHeight||r.heighta.maxWidth||a.widtha.maxHeight||a.height=e.width&&a.height>=e.height?E:O),pt(this.cropBox,st({width:a.width,height:a.height},Nt({translateX:a.left,translateY:a.top}))),this.disabled||this.output()},output:function(){this.preview(),kt(this.element,y,this.getData())}},At={initPreview:function(){var t=this.element,i=this.crossOrigin,e=this.options.preview,a=i?this.crossOriginUrl:this.url,n=t.alt||"The image to preview",o=document.createElement("img");i&&(o.crossOrigin=i),o.src=a,o.alt=n,this.viewBox.appendChild(o),this.viewBoxImage=o,e&&("string"==typeof(o=e)?o=t.ownerDocument.querySelectorAll(e):e.querySelector&&(o=[e]),ht(this.previews=o,function(t){var e=document.createElement("img");bt(t,f,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),i&&(e.crossOrigin=i),e.src=a,e.alt=n,e.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(e)}))},resetPreview:function(){ht(this.previews,function(t){var e=wt(t,f);pt(t,{width:e.width,height:e.height}),t.innerHTML=e.html,function(e,i){if(et(e[i]))try{delete e[i]}catch(t){e[i]=void 0}else if(e.dataset)try{delete e.dataset[i]}catch(t){e.dataset[i]=void 0}else e.removeAttribute("data-".concat(vt(i)))}(t,f)})},preview:function(){var r=this.imageData,t=this.canvasData,e=this.cropBoxData,h=e.width,s=e.height,c=r.width,d=r.height,l=e.left-t.left-r.left,p=e.top-t.top-r.top;this.cropped&&!this.disabled&&(pt(this.viewBoxImage,st({width:c,height:d},Nt(st({translateX:-l,translateY:-p},r)))),ht(this.previews,function(t){var e=wt(t,f),i=e.width,a=e.height,n=i,o=a,e=1;h&&(o=s*(e=i/h)),s&&aMath.abs(a-1)?i:a)&&(t.restore&&(o=this.getCanvasData(),r=this.getCropBoxData()),this.render(),t.restore&&(this.setCanvasData(ht(o,function(t,e){o[e]=t*n})),this.setCropBoxData(ht(r,function(t,e){r[e]=t*n})))))},dblclick:function(){var t,e;this.disabled||this.options.dragMode===b||this.setDragMode((t=this.dragBox,e=s,(t.classList?t.classList.contains(e):-1f&&(D.x=f-p);break;case z:s+D.xv&&(D.y=v-u)}}var y,x,M,C=o[Object.keys(o)[0]],D={x:C.endX-C.startX,y:C.endY-C.startY};switch(r){case O:s+=D.x,c+=D.y;break;case N:if(0<=D.x&&(f<=p||h&&(c<=g||v<=u))){w=!1;break}b(N),(d+=D.x)<0&&(r=z,s-=d=-d),h&&(c+=(n.height-(l=d/h))/2);break;case R:if(D.y<=0&&(c<=g||h&&(s<=m||f<=p))){w=!1;break}b(R),l-=D.y,c+=D.y,l<0&&(r=Y,c-=l=-l),h&&(s+=(n.width-(d=l*h))/2);break;case z:if(D.x<=0&&(s<=m||h&&(c<=g||v<=u))){w=!1;break}b(z),d-=D.x,s+=D.x,d<0&&(r=N,s-=d=-d),h&&(c+=(n.height-(l=d/h))/2);break;case Y:if(0<=D.y&&(v<=u||h&&(s<=m||f<=p))){w=!1;break}b(Y),(l+=D.y)<0&&(r=R,c-=l=-l),h&&(s+=(n.width-(d=l*h))/2);break;case X:if(h){if(D.y<=0&&(c<=g||f<=p)){w=!1;break}b(R),l-=D.y,c+=D.y,d=l*h}else b(R),b(N),!(0<=D.x)||pMath.abs(M)&&(M=i)})}),M),t),w=!1;break;case H:r="";if(D.x&&D.y?(B=180*Math.atan(Math.abs(D.x)/Math.abs(D.y))/Math.PI)<5?h&&(r=0h.maxWidth||m or element.");this.element=t,this.options=st({},V,at(e)&&e),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()}var t,e,a;return t=i,a=[{key:"noConflict",value:function(){return window.Cropper=It,i}},{key:"setDefaults",value:function(t){st(V,at(t)&&t)}}],(e=[{key:"init",value:function(){var t,e=this.element,i=e.tagName.toLowerCase();if(!e[c]){if(e[c]=this,"img"===i){if(this.isImg=!0,t=e.getAttribute("src")||"",!(this.originalUrl=t))return;t=e.src}else"canvas"===i&&window.HTMLCanvasElement&&(t=e.toDataURL());this.load(t)}}},{key:"load",value:function(t){var e,i,a,n,o,r,h=this;t&&(this.url=t,this.imageData={},e=this.element,(i=this.options).rotatable||i.scalable||(i.checkOrientation=!1),i.checkOrientation&&window.ArrayBuffer?Q.test(t)?K.test(t)?this.read((r=(r=t).replace(Xt,""),a=atob(r),r=new ArrayBuffer(a.length),ht(n=new Uint8Array(r),function(t,e){n[e]=a.charCodeAt(e)}),r)):this.clone():(o=new XMLHttpRequest,r=this.clone.bind(this),this.reloading=!0,(this.xhr=o).onabort=r,o.onerror=r,o.ontimeout=r,o.onprogress=function(){o.getResponseHeader("content-type")!==q&&o.abort()},o.onload=function(){h.read(o.response)},o.onloadend=function(){h.reloading=!1,h.xhr=null},i.checkCrossOrigin&&Et(t)&&e.crossOrigin&&(t=Tt(t)),o.open("GET",t,!0),o.responseType="arraybuffer",o.withCredentials="use-credentials"===e.crossOrigin,o.send()):this.clone())}},{key:"read",value:function(t){var e=this.options,i=this.imageData,a=Lt(t),n=0,o=1,r=1;1
',o=(n=s.querySelector(".".concat(c,"-container"))).querySelector(".".concat(c,"-canvas")),r=n.querySelector(".".concat(c,"-drag-box")),s=(h=n.querySelector(".".concat(c,"-crop-box"))).querySelector(".".concat(c,"-face")),this.container=a,this.cropper=n,this.canvas=o,this.dragBox=r,this.cropBox=h,this.viewBox=n.querySelector(".".concat(c,"-view-box")),this.face=s,o.appendChild(i),ut(t,j),a.insertBefore(n,t.nextSibling),this.isImg||mt(i,l),this.initPreview(),this.bind(),e.initialAspectRatio=Math.max(0,e.initialAspectRatio)||NaN,e.aspectRatio=Math.max(0,e.aspectRatio)||NaN,e.viewMode=Math.max(0,Math.min(3,Math.round(e.viewMode)))||0,ut(h,j),e.guides||ut(h.getElementsByClassName("".concat(c,"-dashed")),j),e.center||ut(h.getElementsByClassName("".concat(c,"-center")),j),e.background&&ut(n,"".concat(c,"-bg")),e.highlight||ut(s,p),e.cropBoxMovable&&(ut(s,m),bt(s,g,O)),e.cropBoxResizable||(ut(h.getElementsByClassName("".concat(c,"-line")),j),ut(h.getElementsByClassName("".concat(c,"-point")),j)),this.render(),this.ready=!0,this.setDragMode(e.dragMode),e.autoCrop&&this.crop(),this.setData(e.data),nt(e.ready)&&Bt(t,"ready",e.ready,{once:!0}),kt(t,"ready"))}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),mt(this.element,j))}},{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.onabort=null,this.xhr.abort()):this.image&&this.stop()}}])&&n(t.prototype,e),a&&n(t,a),Object.defineProperty(t,"prototype",{writable:!1}),i}();return st(Pt.prototype,St,At,h,o,t,jt),Pt}); \ No newline at end of file diff --git a/docs/css/cropper.css b/docs/css/cropper.css index bcd00455c..5ef363931 100644 --- a/docs/css/cropper.css +++ b/docs/css/cropper.css @@ -1,11 +1,11 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:20.544Z + * Date: 2021-12-25T08:31:10.935Z */ .cropper-container { @@ -14,23 +14,22 @@ line-height: 0; overflow: hidden; position: relative; - -ms-touch-action: none; touch-action: none; -webkit-user-select: none; - -moz-user-select: none; - -ms-user-select: none; - user-select: none; + -moz-user-select: none; + -ms-user-select: none; + user-select: none } .cropper-container img { - display: block; - height: 100%; - max-height: none !important; - max-width: none !important; - min-height: 0 !important; - min-width: 0 !important; - width: 100%; -} + display: block; + height: 100%; + max-height: none !important; + max-width: none !important; + min-height: 0 !important; + min-width: 0 !important; + width: 100%; + } .cropper-canvas, .cropper-drag-box, @@ -55,7 +54,7 @@ .cropper-view-box { height: 100%; outline: 1px solid #39f; - outline-color: rgba(51, 153, 255, 0.75); + outline-color: rgb(51 153 255 / 75%); overflow: hidden; width: 100%; } @@ -63,26 +62,26 @@ .cropper-dashed { border: 0 dashed #eee; opacity: 0.5; - position: absolute; + position: absolute } .cropper-dashed.dashed-h { - border-bottom-width: 1px; - border-top-width: 1px; - height: calc(100% / 3); - left: 0; - top: calc(100% / 3); - width: 100%; -} + border-bottom-width: 1px; + border-top-width: 1px; + height: calc(100% / 3); + left: 0; + top: calc(100% / 3); + width: 100%; + } .cropper-dashed.dashed-v { - border-left-width: 1px; - border-right-width: 1px; - height: 100%; - left: calc(100% / 3); - top: 0; - width: calc(100% / 3); -} + border-left-width: 1px; + border-right-width: 1px; + height: 100%; + left: calc(100% / 3); + top: 0; + width: calc(100% / 3); + } .cropper-center { height: 0; @@ -90,30 +89,30 @@ opacity: 0.75; position: absolute; top: 50%; - width: 0; + width: 0 } .cropper-center::before, -.cropper-center::after { - background-color: #eee; - content: ""; - display: block; - position: absolute; -} + .cropper-center::after { + background-color: #eee; + content: " "; + display: block; + position: absolute; + } .cropper-center::before { - height: 1px; - left: -3px; - top: 0; - width: 7px; -} + height: 1px; + left: -3px; + top: 0; + width: 7px; + } .cropper-center::after { - height: 7px; - left: 0; - top: -3px; - width: 1px; -} + height: 7px; + left: 0; + top: -3px; + width: 1px; + } .cropper-face, .cropper-line, @@ -131,139 +130,142 @@ } .cropper-line { - background-color: #39f; + background-color: #39f } .cropper-line.line-e { - cursor: ew-resize; - right: -3px; - top: 0; - width: 5px; -} + cursor: ew-resize; + right: -3px; + top: 0; + width: 5px; + } .cropper-line.line-n { - cursor: ns-resize; - height: 5px; - left: 0; - top: -3px; -} + cursor: ns-resize; + height: 5px; + left: 0; + top: -3px; + } .cropper-line.line-w { - cursor: ew-resize; - left: -3px; - top: 0; - width: 5px; -} + cursor: ew-resize; + left: -3px; + top: 0; + width: 5px; + } .cropper-line.line-s { - bottom: -3px; - cursor: ns-resize; - height: 5px; - left: 0; -} + bottom: -3px; + cursor: ns-resize; + height: 5px; + left: 0; + } .cropper-point { background-color: #39f; height: 5px; opacity: 0.75; - width: 5px; + width: 5px } .cropper-point.point-e { - cursor: ew-resize; - margin-top: -3px; - right: -3px; - top: 50%; -} + cursor: ew-resize; + margin-top: -3px; + right: -3px; + top: 50%; + } .cropper-point.point-n { - cursor: ns-resize; - left: 50%; - margin-left: -3px; - top: -3px; -} + cursor: ns-resize; + left: 50%; + margin-left: -3px; + top: -3px; + } .cropper-point.point-w { - cursor: ew-resize; - left: -3px; - margin-top: -3px; - top: 50%; -} + cursor: ew-resize; + left: -3px; + margin-top: -3px; + top: 50%; + } .cropper-point.point-s { - bottom: -3px; - cursor: s-resize; - left: 50%; - margin-left: -3px; -} + bottom: -3px; + cursor: s-resize; + left: 50%; + margin-left: -3px; + } .cropper-point.point-ne { - cursor: nesw-resize; - right: -3px; - top: -3px; -} + cursor: nesw-resize; + right: -3px; + top: -3px; + } .cropper-point.point-nw { - cursor: nwse-resize; - left: -3px; - top: -3px; -} + cursor: nwse-resize; + left: -3px; + top: -3px; + } .cropper-point.point-sw { - bottom: -3px; - cursor: nesw-resize; - left: -3px; -} + bottom: -3px; + cursor: nesw-resize; + left: -3px; + } .cropper-point.point-se { - bottom: -3px; - cursor: nwse-resize; - height: 20px; - opacity: 1; - right: -3px; - width: 20px; -} + 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; + +.cropper-point.point-se { + height: 15px; + width: 15px } -} + } @media (min-width: 992px) { - .cropper-point.point-se { - height: 10px; - width: 10px; + +.cropper-point.point-se { + height: 10px; + width: 10px } -} + } @media (min-width: 1200px) { - .cropper-point.point-se { - height: 5px; - opacity: 0.75; - width: 5px; + +.cropper-point.point-se { + height: 5px; + opacity: 0.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%; -} + 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'); + background-image: url("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQAQMAAAAlPW0iAAAAA3NCSVQICAjb4U/gAAAABlBMVEXMzMz////TjRV2AAAACXBIWXMAAArrAAAK6wGCiw1aAAAAHHRFWHRTb2Z0d2FyZQBBZG9iZSBGaXJld29ya3MgQ1M26LyyjAAAABFJREFUCJlj+M/AgBVhF/0PAH6/D/HkDxOGAAAAAElFTkSuQmCC"); } .cropper-hide { @@ -286,8 +288,8 @@ } .cropper-disabled .cropper-drag-box, -.cropper-disabled .cropper-face, -.cropper-disabled .cropper-line, -.cropper-disabled .cropper-point { - cursor: not-allowed; -} + .cropper-disabled .cropper-face, + .cropper-disabled .cropper-line, + .cropper-disabled .cropper-point { + cursor: not-allowed; + } diff --git a/docs/index.html b/docs/index.html index 806ddd9c8..ada737313 100644 --- a/docs/index.html +++ b/docs/index.html @@ -76,7 +76,7 @@
-

Cropper.js v2.0.0-alpha.1

+

Cropper.js v2.0.0-alpha.2

JavaScript image cropper.

diff --git a/docs/js/cropper.js b/docs/js/cropper.js index 5a912267d..fb892d9d9 100644 --- a/docs/js/cropper.js +++ b/docs/js/cropper.js @@ -1,31 +1,53 @@ /*! - * Cropper.js v2.0.0-alpha.1 + * Cropper.js v2.0.0-alpha.2 * https://fengyuanchen.github.io/cropperjs * * Copyright 2015-present Chen Fengyuan * Released under the MIT license * - * Date: 2019-11-09T12:02:24.890Z + * Date: 2021-12-25T08:31:12.767Z */ (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()); -}(this, (function () { 'use strict'; + (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Cropper = factory()); +})(this, (function () { 'use strict'; - function _typeof(obj) { - if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { - _typeof = function (obj) { - return typeof obj; - }; - } else { - _typeof = function (obj) { - return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; - }; + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); } - return _typeof(obj); + return keys; + } + + function _objectSpread2(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + + return target; + } + + function _typeof(obj) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { + return typeof obj; + } : function (obj) { + return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; + }, _typeof(obj); } function _classCallCheck(instance, Constructor) { @@ -47,6 +69,9 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); return Constructor; } @@ -65,63 +90,42 @@ 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 _toConsumableArray(arr) { + return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } - function _objectSpread2(target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i] != null ? arguments[i] : {}; - - if (i % 2) { - ownKeys(source, true).forEach(function (key) { - _defineProperty(target, key, source[key]); - }); - } else if (Object.getOwnPropertyDescriptors) { - Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); - } else { - ownKeys(source).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); - } - } + function _arrayWithoutHoles(arr) { + if (Array.isArray(arr)) return _arrayLikeToArray(arr); + } - return target; + function _iterableToArray(iter) { + if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); } - function _toConsumableArray(arr) { - return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); + function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(o); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } - function _arrayWithoutHoles(arr) { - if (Array.isArray(arr)) { - for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; + function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; - return arr2; - } - } + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; - function _iterableToArray(iter) { - if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); + return arr2; } function _nonIterableSpread() { - throw new TypeError("Invalid attempt to spread non-iterable instance"); + throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var IS_BROWSER = typeof window !== 'undefined' && typeof window.document !== 'undefined'; var WINDOW = IS_BROWSER ? window : {}; - var IS_TOUCH_DEVICE = IS_BROWSER ? 'ontouchstart' in WINDOW.document.documentElement : false; + var IS_TOUCH_DEVICE = IS_BROWSER && WINDOW.document.documentElement ? 'ontouchstart' in WINDOW.document.documentElement : false; var HAS_POINTER_EVENT = IS_BROWSER ? 'PointerEvent' in WINDOW : false; var NAMESPACE = 'cropper'; // Actions @@ -352,10 +356,10 @@ if (Array.isArray(data) || isNumber(data.length) /* array-like */ ) { - toArray(data).forEach(function (value, key) { - callback.call(data, value, key, data); - }); - } else if (isObject(data)) { + toArray(data).forEach(function (value, key) { + callback.call(data, value, key, data); + }); + } else if (isObject(data)) { Object.keys(data).forEach(function (key) { callback.call(data, data[key], key, data); }); @@ -391,7 +395,7 @@ var REGEXP_DECIMALS = /\.\d*(?:0|9){12}\d*$/; /** * Normalize decimal number. - * Check out {@link http://0.30000000000000004.com/} + * Check out {@link https://0.30000000000000004.com/} * @param {number} value - The value to normalize. * @param {number} [times=100000000000] - The times for normalizing. * @returns {number} Returns the normalized number. @@ -796,7 +800,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) { @@ -807,13 +811,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. @@ -865,8 +869,7 @@ * @returns {Object} The result sizes. */ - function getAdjustedSizes(_ref4) // or 'cover' - { + function getAdjustedSizes(_ref4) { var aspectRatio = _ref4.aspectRatio, height = _ref4.height, width = _ref4.width; @@ -1104,14 +1107,14 @@ if (littleEndian || endianness === 0x4D4D /* bigEndian */ ) { - if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { - var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); + if (dataView.getUint16(tiffOffset + 2, littleEndian) === 0x002A) { + var firstIFDOffset = dataView.getUint32(tiffOffset + 4, littleEndian); - if (firstIFDOffset >= 0x00000008) { - ifdStart = tiffOffset + firstIFDOffset; - } + if (firstIFDOffset >= 0x00000008) { + ifdStart = tiffOffset + firstIFDOffset; } } + } } } @@ -1128,14 +1131,14 @@ if (dataView.getUint16(_offset, littleEndian) === 0x0112 /* Orientation */ ) { - // 8 is the offset of the current tag's value - _offset += 8; // Get the original orientation value + // 8 is the offset of the current tag's value + _offset += 8; // Get the original orientation value - orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value + orientation = dataView.getUint16(_offset, littleEndian); // Override the orientation with its default value - dataView.setUint16(_offset, 1, littleEndian); - break; - } + dataView.setUint16(_offset, 1, littleEndian); + break; + } } } } catch (error) { @@ -1205,9 +1208,10 @@ render: function render() { this.initContainer(); this.initCanvas(); - this.initCropBox(); - this.initialImageData = assign({}, this.imageData); this.initialCanvasData = assign({}, this.canvasData); + this.initCropBox(); // Store the `initialCropBoxData` outside of the `initCropBox` method, + // just because the `initCropBox` method will be called more then once. + this.initialCropBoxData = assign({}, this.cropBoxData); this.renderCanvas(); @@ -1220,11 +1224,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) || MIN_CONTAINER_WIDTH), - height: Math.max(container.offsetHeight, Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT) + width: Math.max(container.offsetWidth, minWidth >= 0 ? minWidth : MIN_CONTAINER_WIDTH), + height: Math.max(container.offsetHeight, minHeight >= 0 ? minHeight : MIN_CONTAINER_HEIGHT) }; setStyle(cropper, containerData); addClass(element, CLASS_HIDDEN); @@ -1816,19 +1822,18 @@ var handlers = { resize: function resize() { - var options = this.options, - container = this.container, - containerData = this.containerData; - var minContainerWidth = Number(options.minContainerWidth) || MIN_CONTAINER_WIDTH; - var minContainerHeight = Number(options.minContainerHeight) || MIN_CONTAINER_HEIGHT; - - if (this.disabled || containerData.width <= minContainerWidth || containerData.height <= minContainerHeight) { + if (this.disabled) { return; } - var ratio = container.offsetWidth / containerData.width; // Resize when width changed or height changed + var options = this.options, + container = this.container, + containerData = this.containerData; + 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; @@ -3269,9 +3274,7 @@ var AnotherCropper = WINDOW.Cropper; - var Cropper = - /*#__PURE__*/ - function () { + var Cropper = /*#__PURE__*/function () { /** * Create a new Cropper. * @param {Element} element - The target element for cropping. @@ -3320,7 +3323,7 @@ if (!url) { return; - } // e.g.: "http://example.com/img/picture.jpg" + } // e.g.: "https://example.com/img/picture.jpg" url = element.src; @@ -3401,9 +3404,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(); @@ -3493,7 +3497,9 @@ naturalWidth: naturalWidth, naturalHeight: naturalHeight, aspectRatio: naturalWidth / naturalHeight - }); + }); // Store the `initialImageData` here for avoiding side effect (jquery-cropper#19) + + _this2.initialImageData = assign({}, _this2.imageData); _this2.sizing = false; _this2.sized = true; @@ -3683,4 +3689,4 @@ return Cropper; -}))); +})); diff --git a/package-lock.json b/package-lock.json index 8031b8370..587f7ca6f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cropperjs", - "version": "2.0.0-alpha.1", + "version": "2.0.0-alpha.2", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "cropperjs", - "version": "2.0.0-alpha.1", + "version": "2.0.0-alpha.2", "license": "MIT", "devDependencies": { "@babel/core": "^7.16.5", diff --git a/package.json b/package.json index 1fdb4126b..ea728dcf2 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "cropperjs", "description": "JavaScript image cropper.", - "version": "2.0.0-alpha.1", + "version": "2.0.0-alpha.2", "main": "dist/cropper.common.js", "module": "dist/cropper.esm.js", "browser": "dist/cropper.js", @@ -103,5 +103,8 @@ "stylelint-config-standard-scss": "^3.0.0", "stylelint-order": "^5.0.0", "uglify-js": "^3.14.5" + }, + "publishConfig": { + "tag": "next" } }