From c771a2bef51d56e40e1147f2be68f62ae6c881b6 Mon Sep 17 00:00:00 2001 From: Petr Chalov Date: Fri, 30 Aug 2019 11:18:29 +0400 Subject: [PATCH] improve perfomance --- croppie.js | 433 ++++++++++++++++++++++++++++++++----------------- croppie.min.js | 2 +- 2 files changed, 283 insertions(+), 152 deletions(-) diff --git a/croppie.js b/croppie.js index 2652d0ef..35c27ce0 100755 --- a/croppie.js +++ b/croppie.js @@ -20,18 +20,134 @@ /* Polyfills */ if (typeof Promise !== 'function') { /*! promise-polyfill 3.1.0 */ - !function(a){function b(a,b){return function(){a.apply(b,arguments)}}function c(a){if("object"!==typeof this)throw new TypeError("Promises must be constructed via new");if("function"!==typeof a)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],i(a,b(e,this),b(f,this))}function d(a){var b=this;return null===this._state?void this._deferreds.push(a):void k(function(){var c=b._state?a.onFulfilled:a.onRejected;if(null===c)return void(b._state?a.resolve:a.reject)(b._value);var d;try{d=c(b._value)}catch(e){return void a.reject(e)}a.resolve(d)})}function e(a){try{if(a===this)throw new TypeError("A promise cannot be resolved with itself.");if(a&&("object"===typeof a||"function"===typeof a)){var c=a.then;if("function"===typeof c)return void i(b(c,a),b(e,this),b(f,this))}this._state=!0,this._value=a,g.call(this)}catch(d){f.call(this,d)}}function f(a){this._state=!1,this._value=a,g.call(this)}function g(){for(var a=0,b=this._deferreds.length;b>a;a++)d.call(this,this._deferreds[a]);this._deferreds=null}function h(a,b,c,d){this.onFulfilled="function"===typeof a?a:null,this.onRejected="function"===typeof b?b:null,this.resolve=c,this.reject=d}function i(a,b,c){var d=!1;try{a(function(a){d||(d=!0,b(a))},function(a){d||(d=!0,c(a))})}catch(e){if(d)return;d=!0,c(e)}}var j=setTimeout,k="function"===typeof setImmediate&&setImmediate||function(a){j(a,1)},l=Array.isArray||function(a){return"[object Array]"===Object.prototype.toString.call(a)};c.prototype["catch"]=function(a){return this.then(null,a)},c.prototype.then=function(a,b){var e=this;return new c(function(c,f){d.call(e,new h(a,b,c,f))})},c.all=function(){var a=Array.prototype.slice.call(1===arguments.length&&l(arguments[0])?arguments[0]:arguments);return new c(function(b,c){function d(f,g){try{if(g&&("object"===typeof g||"function"===typeof g)){var h=g.then;if("function"===typeof h)return void h.call(g,function(a){d(f,a)},c)}a[f]=g,0===--e&&b(a)}catch(i){c(i)}}if(0===a.length)return b([]);for(var e=a.length,f=0;fd;d++)a[d].then(b,c)})},c._setImmediateFn=function(a){k=a},"undefined"!==typeof module&&module.exports?module.exports=c:a.Promise||(a.Promise=c)}(this); + !function (a) { + function b(a, b) { + return function () { + a.apply(b, arguments) + } + } + + function c(a) { + if ("object" !== typeof this) throw new TypeError("Promises must be constructed via new"); + if ("function" !== typeof a) throw new TypeError("not a function"); + this._state = null, this._value = null, this._deferreds = [], i(a, b(e, this), b(f, this)) + } + + function d(a) { + var b = this; + return null === this._state ? void this._deferreds.push(a) : void k(function () { + var c = b._state ? a.onFulfilled : a.onRejected; + if (null === c) return void (b._state ? a.resolve : a.reject)(b._value); + var d; + try { + d = c(b._value) + } catch (e) { + return void a.reject(e) + } + a.resolve(d) + }) + } + + function e(a) { + try { + if (a === this) throw new TypeError("A promise cannot be resolved with itself."); + if (a && ("object" === typeof a || "function" === typeof a)) { + var c = a.then; + if ("function" === typeof c) return void i(b(c, a), b(e, this), b(f, this)) + } + this._state = !0, this._value = a, g.call(this) + } catch (d) { + f.call(this, d) + } + } + + function f(a) { + this._state = !1, this._value = a, g.call(this) + } + + function g() { + for (var a = 0, b = this._deferreds.length; b > a; a++) d.call(this, this._deferreds[a]); + this._deferreds = null + } + + function h(a, b, c, d) { + this.onFulfilled = "function" === typeof a ? a : null, this.onRejected = "function" === typeof b ? b : null, this.resolve = c, this.reject = d + } + + function i(a, b, c) { + var d = !1; + try { + a(function (a) { + d || (d = !0, b(a)) + }, function (a) { + d || (d = !0, c(a)) + }) + } catch (e) { + if (d) return; + d = !0, c(e) + } + } + + var j = setTimeout, k = "function" === typeof setImmediate && setImmediate || function (a) { + j(a, 1) + }, l = Array.isArray || function (a) { + return "[object Array]" === Object.prototype.toString.call(a) + }; + c.prototype["catch"] = function (a) { + return this.then(null, a) + }, c.prototype.then = function (a, b) { + var e = this; + return new c(function (c, f) { + d.call(e, new h(a, b, c, f)) + }) + }, c.all = function () { + var a = Array.prototype.slice.call(1 === arguments.length && l(arguments[0]) ? arguments[0] : arguments); + return new c(function (b, c) { + function d(f, g) { + try { + if (g && ("object" === typeof g || "function" === typeof g)) { + var h = g.then; + if ("function" === typeof h) return void h.call(g, function (a) { + d(f, a) + }, c) + } + a[f] = g, 0 === --e && b(a) + } catch (i) { + c(i) + } + } + + if (0 === a.length) return b([]); + for (var e = a.length, f = 0; f < a.length; f++) d(f, a[f]) + }) + }, c.resolve = function (a) { + return a && "object" === typeof a && a.constructor === c ? a : new c(function (b) { + b(a) + }) + }, c.reject = function (a) { + return new c(function (b, c) { + c(a) + }) + }, c.race = function (a) { + return new c(function (b, c) { + for (var d = 0, e = a.length; e > d; d++) a[d].then(b, c) + }) + }, c._setImmediateFn = function (a) { + k = a + }, "undefined" !== typeof module && module.exports ? module.exports = c : a.Promise || (a.Promise = c) + }(this); } if (typeof window !== 'undefined' && typeof window.CustomEvent !== "function") { - (function(){ - function CustomEvent ( event, params ) { - params = params || { bubbles: false, cancelable: false, detail: undefined }; - var evt = document.createEvent( 'CustomEvent' ); - evt.initCustomEvent( event, params.bubbles, params.cancelable, params.detail ); + (function () { + function CustomEvent(event, params) { + params = params || {bubbles: false, cancelable: false, detail: undefined}; + var evt = document.createEvent('CustomEvent'); + evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail); return evt; } - CustomEvent.prototype = window.Event.prototype; + + CustomEvent.prototype = window.Event ? window.Event.prototype : Object.create(null); window.CustomEvent = CustomEvent; }()); } @@ -39,15 +155,15 @@ if (typeof HTMLCanvasElement !== 'undefined' && !HTMLCanvasElement.prototype.toBlob) { Object.defineProperty(HTMLCanvasElement.prototype, 'toBlob', { value: function (callback, type, quality) { - var binStr = atob( this.toDataURL(type, quality).split(',')[1] ), - len = binStr.length, - arr = new Uint8Array(len); + var binStr = atob(this.toDataURL(type, quality).split(',')[1]), + len = binStr.length, + arr = new Uint8Array(len); - for (var i=0; i= 5) { - var x= w; + var x = w; w = h; h = x; } - return { width: w, height: h }; + return {width: w, height: h}; } /* CSS Transform Prototype */ @@ -243,11 +398,9 @@ Transform.parse = function (v) { if (v.style) { return Transform.parse(v.style[CSS_TRANSFORM]); - } - else if (v.indexOf('matrix') > -1 || v.indexOf('none') > -1) { + } else if (v.indexOf('matrix') > -1 || v.indexOf('none') > -1) { return Transform.fromMatrix(v); - } - else { + } else { return Transform.fromString(v); } }; @@ -291,7 +444,7 @@ return this.x + 'px ' + this.y + 'px'; }; - function getExifOrientation (img) { + function getExifOrientation(img) { return img.exifdata && img.exifdata.Orientation ? num(img.exifdata.Orientation) : 1; } @@ -305,51 +458,51 @@ ctx.save(); switch (orientation) { - case 2: - ctx.translate(width, 0); - ctx.scale(-1, 1); - break; - - case 3: - ctx.translate(width, height); - ctx.rotate(180*Math.PI/180); - break; - - case 4: - ctx.translate(0, height); - ctx.scale(1, -1); - break; - - case 5: - canvas.width = height; - canvas.height = width; - ctx.rotate(90*Math.PI/180); - ctx.scale(1, -1); - break; - - case 6: - canvas.width = height; - canvas.height = width; - ctx.rotate(90*Math.PI/180); - ctx.translate(0, -height); - break; - - case 7: - canvas.width = height; - canvas.height = width; - ctx.rotate(-90*Math.PI/180); - ctx.translate(-width, height); - ctx.scale(1, -1); - break; - - case 8: - canvas.width = height; - canvas.height = width; - ctx.translate(0, width); - ctx.rotate(-90*Math.PI/180); - break; - } - ctx.drawImage(img, 0,0, width, height); + case 2: + ctx.translate(width, 0); + ctx.scale(-1, 1); + break; + + case 3: + ctx.translate(width, height); + ctx.rotate(180 * Math.PI / 180); + break; + + case 4: + ctx.translate(0, height); + ctx.scale(1, -1); + break; + + case 5: + canvas.width = height; + canvas.height = width; + ctx.rotate(90 * Math.PI / 180); + ctx.scale(1, -1); + break; + + case 6: + canvas.width = height; + canvas.height = width; + ctx.rotate(90 * Math.PI / 180); + ctx.translate(0, -height); + break; + + case 7: + canvas.width = height; + canvas.height = width; + ctx.rotate(-90 * Math.PI / 180); + ctx.translate(-width, height); + ctx.scale(1, -1); + break; + + case 8: + canvas.width = height; + canvas.height = width; + ctx.translate(0, width); + ctx.rotate(-90 * Math.PI / 180); + break; + } + ctx.drawImage(img, 0, 0, width, height); ctx.restore(); } @@ -371,10 +524,9 @@ overlay = self.elements.overlay = document.createElement('div'); if (self.options.useCanvas) { - self.elements.canvas = document.createElement('canvas'); + self.elements.canvas = createCanvas(); self.elements.preview = self.elements.canvas; - } - else { + } else { self.elements.preview = img; } @@ -398,7 +550,7 @@ viewport.setAttribute('tabindex', 0); addClass(self.elements.preview, 'cr-image'); - setAttributes(self.elements.preview, { 'alt': 'preview', 'aria-grabbed': 'false' }); + setAttributes(self.elements.preview, {'alt': 'preview', 'aria-grabbed': 'false'}); addClass(overlay, 'cr-overlay'); self.element.appendChild(boundary); @@ -460,7 +612,7 @@ return this.options.enableExif && window.EXIF; } - function _initializeResize () { + function _initializeResize() { var self = this; var wrap = document.createElement('div'); var isDragging = false; @@ -552,8 +704,7 @@ css(self.elements.viewport, { height: self.options.viewport.height + 'px' }); - } - else if (direction === 'h' && newWidth >= minSize && newWidth <= maxWidth) { + } else if (direction === 'h' && newWidth >= minSize && newWidth <= maxWidth) { css(wrap, { width: newWidth + 'px' }); @@ -638,8 +789,8 @@ function scroll(ev) { var delta, targetZoom; - if(self.options.mouseWheelZoom === 'ctrl' && ev.ctrlKey !== true){ - return 0; + if (self.options.mouseWheelZoom === 'ctrl' && ev.ctrlKey !== true) { + return 0; } else if (ev.wheelDelta) { delta = ev.wheelDelta / 1200; //wheelDelta min: -120 max: 120 // max x 10 x 2 } else if (ev.deltaY) { @@ -777,8 +928,7 @@ center.x = cy; transform.y = tx; transform.x = ty; - } - else { + } else { center.y = top / scale; center.x = left / scale; @@ -817,35 +967,32 @@ if (vpRect.left > imgRect.left + deltaX && vpRect.right < imgRect.right + deltaX) { transform.x = left; } - } - else { + } else { transform.y = top; transform.x = left; } } function toggleGrabState(isDragging) { - self.elements.preview.setAttribute('aria-grabbed', isDragging); - self.elements.boundary.setAttribute('aria-dropeffect', isDragging? 'move': 'none'); + self.elements.preview.setAttribute('aria-grabbed', isDragging); + self.elements.boundary.setAttribute('aria-dropeffect', isDragging ? 'move' : 'none'); } function keyDown(ev) { - var LEFT_ARROW = 37, - UP_ARROW = 38, + var LEFT_ARROW = 37, + UP_ARROW = 38, RIGHT_ARROW = 39, - DOWN_ARROW = 40; + DOWN_ARROW = 40; if (ev.shiftKey && (ev.keyCode === UP_ARROW || ev.keyCode === DOWN_ARROW)) { var zoom; if (ev.keyCode === UP_ARROW) { zoom = parseFloat(self.elements.zoomer.value) + parseFloat(self.elements.zoomer.step) - } - else { + } else { zoom = parseFloat(self.elements.zoomer.value) - parseFloat(self.elements.zoomer.step) } self.setZoom(zoom); - } - else if (self.options.enableKeyMovement && (ev.keyCode >= 37 && ev.keyCode <= 40)) { + } else if (self.options.enableKeyMovement && (ev.keyCode >= 37 && ev.keyCode <= 40)) { ev.preventDefault(); var movement = parseKeyDown(ev.keyCode); @@ -982,6 +1129,7 @@ left: (imgData.left - boundRect.left) + 'px' }); } + var _debouncedOverlay = debounce(_updateOverlay, 500); function _triggerUpdate() { @@ -995,11 +1143,10 @@ self.options.update.call(self, data); if (self.$ && typeof Prototype === 'undefined') { self.$(self.element).trigger('update.croppie', data); - } - else { + } else { var ev; if (window.CustomEvent) { - ev = new CustomEvent('update', { detail: data }); + ev = new CustomEvent('update', {detail: data}); } else { ev = document.createEvent('CustomEvent'); ev.initCustomEvent('update', true, true, data); @@ -1041,8 +1188,7 @@ if (self.options.enableZoom) { _updateZoomLimits.call(self, true); - } - else { + } else { self._currentZoom = initialZoom; } @@ -1052,8 +1198,7 @@ if (self.data.points.length) { _bindPoints.call(self, self.data.points); - } - else { + } else { _centerImage.call(self); } @@ -1061,7 +1206,7 @@ _updateOverlay.call(self); } - function _updateZoomLimits (initial) { + function _updateZoomLimits(initial) { var self = this, minZoom = Math.max(self.options.minZoom, 0) || 0, maxZoom = self.options.maxZoom || 1.5, @@ -1089,8 +1234,7 @@ if (!initial && (scale < zoomer.min || scale > zoomer.max)) { _setZoomerVal.call(self, scale < zoomer.min ? zoomer.min : zoomer.max); - } - else if (initial) { + } else if (initial) { defaultInitialZoom = Math.max((boundaryData.width / imgData.width), (boundaryData.height / imgData.height)); initialZoom = self.data.boundZoom !== null ? self.data.boundZoom : defaultInitialZoom; _setZoomerVal.call(self, initialZoom); @@ -1162,18 +1306,16 @@ top = num(points[1]), right = num(points[2]), bottom = num(points[3]), - width = right-left, - height = bottom-top, + width = right - left, + height = bottom - top, circle = data.circle, - canvas = document.createElement('canvas'), - ctx = canvas.getContext('2d'), startX = 0, startY = 0, canvasWidth = data.outputWidth || width, - canvasHeight = data.outputHeight || height; + canvasHeight = data.outputHeight || height, + canvas = createCanvas(canvasWidth, canvasHeight), + ctx = canvas.getContext('2d'); - canvas.width = canvasWidth; - canvas.height = canvasHeight; if (data.backgroundColor) { ctx.fillStyle = data.backgroundColor; @@ -1205,7 +1347,7 @@ // The largest possible source width is the original image's width. if (sWidth + sx > self._originalImageWidth) { sWidth = self._originalImageWidth - sx; - dWidth = (sWidth / width) * canvasWidth; + dWidth = (sWidth / width) * canvasWidth; } // @@ -1235,6 +1377,7 @@ ctx.closePath(); ctx.fill(); } + return canvas; } @@ -1261,21 +1404,18 @@ } function _getBase64Result(data) { - return _getCanvas.call(this, data).toDataURL(data.format, data.quality); + return canvasToBase64(_getCanvas.call(this, data), data.format, data.quality) } function _getBlobResult(data) { - var self = this; - return new Promise(function (resolve) { - _getCanvas.call(self, data).toBlob(function (blob) { - resolve(blob); - }, data.format, data.quality); - }); + return canvasToBlob(_getCanvas.call(this, data), data.format, data.quality); } function _replaceImage(img) { if (this.elements.img.parentNode) { - Array.prototype.forEach.call(this.elements.img.classList, function(c) { img.classList.add(c); }); + Array.prototype.forEach.call(this.elements.img.classList, function (c) { + img.classList.add(c); + }); this.elements.img.parentNode.replaceChild(img, this.elements.img); this.elements.preview = img; // if the img is attached to the DOM, they're not using the canvas } @@ -1292,19 +1432,16 @@ if (typeof (options) === 'string') { url = options; options = {}; - } - else if (Array.isArray(options)) { + } else if (Array.isArray(options)) { points = options.slice(); - } - else if (typeof (options) === 'undefined' && self.data.url) { //refreshing + } else if (typeof (options) === 'undefined' && self.data.url) { //refreshing _updatePropertiesFromImage.call(self); _triggerUpdate.call(self); return null; - } - else { + } else { url = options.url; points = options.points || []; - zoom = typeof(options.zoom) === 'undefined' ? null : options.zoom; + zoom = typeof (options.zoom) === 'undefined' ? null : options.zoom; } self.data.bound = false; @@ -1323,8 +1460,7 @@ if (imgAspectRatio > aspectRatio) { height = natDim.height; width = height * aspectRatio; - } - else { + } else { width = natDim.width; height = natDim.height / aspectRatio; } @@ -1334,8 +1470,7 @@ var x1 = x0 + width; var y1 = y0 + height; self.data.points = [x0, y0, x1, y1]; - } - else if (self.options.relative) { + } else if (self.options.relative) { points = [ points[0] * img.naturalWidth / 100, points[1] * img.naturalHeight / 100, @@ -1437,10 +1572,9 @@ data.backgroundColor = backgroundColor; prom = new Promise(function (resolve) { - switch(resultType.toLowerCase()) - { + switch (resultType.toLowerCase()) { case 'rawcanvas': - resolve(_getCanvas.call(self, data)); + resolve(toOnscreenCanvas(_getCanvas.call(self, data))); break; case 'canvas': case 'base64': @@ -1476,8 +1610,8 @@ // Reverses image dimensions if the degrees of rotation is not divisible by 180. if ((Math.abs(deg) / 90) % 2 === 1) { - let oldHeight = self._originalImageHeight; - let oldWidth = self._originalImageWidth; + var oldHeight = self._originalImageHeight; + var oldWidth = self._originalImageWidth; self._originalImageWidth = oldHeight; self._originalImageHeight = oldWidth; } @@ -1504,11 +1638,9 @@ if (opts === 'get') { return singleInst.get(); - } - else if (opts === 'result') { + } else if (opts === 'result') { return singleInst.result.apply(singleInst, args); - } - else if (opts === 'bind') { + } else if (opts === 'bind') { return singleInst.bind.apply(singleInst, args); } @@ -1522,13 +1654,11 @@ if (opts === 'destroy') { $(this).removeData('croppie'); } - } - else { + } else { throw 'Croppie ' + opts + ' method not found'; } }); - } - else { + } else { return this.each(function () { var i = new Croppie(this, opts); i.$ = $; @@ -1548,7 +1678,7 @@ if (this.element.tagName.toLowerCase() === 'img') { var origImage = this.element; addClass(origImage, 'cr-original-image'); - setAttributes(origImage, {'aria-hidden' : 'true', 'alt' : '' }); + setAttributes(origImage, {'aria-hidden': 'true', 'alt': ''}); var replacementDiv = document.createElement('div'); this.element.parentNode.appendChild(replacementDiv); replacementDiv.appendChild(origImage); @@ -1574,7 +1704,7 @@ height: 100, type: 'square' }, - boundary: { }, + boundary: {}, orientationControls: { enabled: true, leftClass: '', @@ -1593,7 +1723,8 @@ enforceBoundary: true, enableOrientation: false, enableKeyMovement: true, - update: function () { } + update: function () { + } }; Croppie.globals = { diff --git a/croppie.min.js b/croppie.min.js index 1223fd23..13d85301 100644 --- a/croppie.min.js +++ b/croppie.min.js @@ -1 +1 @@ -!function(e,t){"function"==typeof define&&define.amd?define(t):"object"==typeof exports&&"string"!=typeof exports.nodeName?module.exports=t():e.Croppie=t()}("undefined"!=typeof self?self:this,function(){"function"!=typeof Promise&&function(e){function n(e,t){return function(){e.apply(t,arguments)}}function r(e){if("object"!=typeof this)throw new TypeError("Promises must be constructed via new");if("function"!=typeof e)throw new TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],u(e,n(i,this),n(o,this))}function a(n){var i=this;return null===this._state?void this._deferreds.push(n):void c(function(){var e=i._state?n.onFulfilled:n.onRejected;if(null!==e){var t;try{t=e(i._value)}catch(e){return void n.reject(e)}n.resolve(t)}else(i._state?n.resolve:n.reject)(i._value)})}function i(e){try{if(e===this)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var t=e.then;if("function"==typeof t)return void u(n(t,e),n(i,this),n(o,this))}this._state=!0,this._value=e,s.call(this)}catch(e){o.call(this,e)}}function o(e){this._state=!1,this._value=e,s.call(this)}function s(){for(var e=0,t=this._deferreds.length;en.top+t&&l.bottomn.left+e&&l.right=s.maxX&&(o.x=l.minX,n.x=s.maxX),n.x<=s.minX&&(o.x=l.maxX,n.x=s.minX),n.y>=s.maxY&&(o.y=l.minY,n.y=s.maxY),n.y<=s.minY&&(o.y=l.maxY,n.y=s.minY)}r(),I.call(t),F.call(t)}).call(i,{value:parseFloat(t.value),origin:new L(i.elements.preview),viewportRect:i.elements.viewport.getBoundingClientRect(),transform:E.parse(i.elements.preview)})}function n(e){var t,n;if("ctrl"===i.options.mouseWheelZoom&&!0!==e.ctrlKey)return 0;t=e.wheelDelta?e.wheelDelta/1200:e.deltaY?e.deltaY/1060:e.detail?e.detail/-60:0,n=i._currentZoom+t*i._currentZoom,e.preventDefault(),B.call(i,n),o.call(i)}x(e,"cr-slider-wrap"),x(t,"cr-slider"),t.type="range",t.step="0.0001",t.value="1",t.style.display=i.options.showZoomer?"":"none",t.setAttribute("aria-label","zoom"),i.element.appendChild(e),e.appendChild(t),i._currentZoom=1,i.elements.zoomer.addEventListener("input",o),i.elements.zoomer.addEventListener("change",o),i.options.mouseWheelZoom&&(i.elements.boundary.addEventListener("mousewheel",n),i.elements.boundary.addEventListener("DOMMouseScroll",n))}.call(a),a.options.enableResize&&function(){var l,u,c,h,p,e,t,d=this,m=document.createElement("div"),i=!1,f=50;x(m,"cr-resizer"),b(m,{width:this.options.viewport.width+"px",height:this.options.viewport.height+"px"}),this.options.resizeControls.height&&(x(e=document.createElement("div"),"cr-resizer-vertical"),m.appendChild(e));this.options.resizeControls.width&&(x(t=document.createElement("div"),"cr-resizer-horisontal"),m.appendChild(t));function n(e){if((void 0===e.button||0===e.button)&&(e.preventDefault(),!i)){var t=d.elements.overlay.getBoundingClientRect();if(i=!0,u=e.pageX,c=e.pageY,l=-1!==e.currentTarget.className.indexOf("vertical")?"v":"h",h=t.width,p=t.height,e.touches){var n=e.touches[0];u=n.pageX,c=n.pageY}window.addEventListener("mousemove",o),window.addEventListener("touchmove",o),window.addEventListener("mouseup",r),window.addEventListener("touchend",r),document.body.style[w]="none"}}function o(e){var t=e.pageX,n=e.pageY;if(e.preventDefault(),e.touches){var i=e.touches[0];t=i.pageX,n=i.pageY}var o=t-u,r=n-c,a=d.options.viewport.height+r,s=d.options.viewport.width+o;"v"===l&&f<=a&&a<=p?(b(m,{height:a+"px"}),d.options.boundary.height+=r,b(d.elements.boundary,{height:d.options.boundary.height+"px"}),d.options.viewport.height+=r,b(d.elements.viewport,{height:d.options.viewport.height+"px"})):"h"===l&&f<=s&&s<=h&&(b(m,{width:s+"px"}),d.options.boundary.width+=o,b(d.elements.boundary,{width:d.options.boundary.width+"px"}),d.options.viewport.width+=o,b(d.elements.viewport,{width:d.options.viewport.width+"px"})),z.call(d),W.call(d),Z.call(d),F.call(d),c=n,u=t}function r(){i=!1,window.removeEventListener("mousemove",o),window.removeEventListener("touchmove",o),window.removeEventListener("mouseup",r),window.removeEventListener("touchend",r),document.body.style[w]=""}e&&(e.addEventListener("mousedown",n),e.addEventListener("touchstart",n));t&&(t.addEventListener("mousedown",n),t.addEventListener("touchstart",n));this.elements.boundary.appendChild(m)}.call(a)}function R(){return this.options.enableExif&&window.EXIF}function B(e){if(this.options.enableZoom){var t=this.elements.zoomer,n=A(e,4);t.value=Math.max(parseFloat(t.min),Math.min(parseFloat(t.max),n)).toString()}}function Z(e){var t=this,n=t._currentZoom,i=t.elements.preview.getBoundingClientRect(),o=t.elements.viewport.getBoundingClientRect(),r=E.parse(t.elements.preview.style[g]),a=new L(t.elements.preview),s=o.top-i.top+o.height/2,l=o.left-i.left+o.width/2,u={},c={};if(e){var h=a.x,p=a.y,d=r.x,m=r.y;u.y=h,u.x=p,r.y=d,r.x=m}else u.y=s/n,u.x=l/n,c.y=(u.y-a.y)*(1-n),c.x=(u.x-a.x)*(1-n),r.x-=c.x,r.y-=c.y;var f={};f[v]=u.x+"px "+u.y+"px",f[g]=r.toString(),b(t.elements.preview,f)}function z(){if(this.elements){var e=this.elements.boundary.getBoundingClientRect(),t=this.elements.preview.getBoundingClientRect();b(this.elements.overlay,{width:t.width+"px",height:t.height+"px",top:t.top-e.top+"px",left:t.left-e.left+"px"})}}L.prototype.toString=function(){return this.x+"px "+this.y+"px"};var a,s,h,M,I=(a=z,s=500,function(){var e=this,t=arguments,n=h&&!M;clearTimeout(M),M=setTimeout(function(){M=null,h||a.apply(e,t)},s),n&&a.apply(e,t)});function F(){var e,t=this,n=t.get();X.call(t)&&(t.options.update.call(t,n),t.$&&"undefined"==typeof Prototype?t.$(t.element).trigger("update.croppie",n):(window.CustomEvent?e=new CustomEvent("update",{detail:n}):(e=document.createEvent("CustomEvent")).initCustomEvent("update",!0,!0,n),t.element.dispatchEvent(e)))}function X(){return 0l.max)?B.call(r,uthis._originalImageWidth&&(g=(d=this._originalImageWidth-h)/o*u),i<0&&(p=0,v=Math.abs(i)/r*c),m+p>this._originalImageHeight&&(w=(m=this._originalImageHeight-p)/r*c),l.drawImage(this.elements.preview,h,p,d,m,f,v,g,w),a&&(l.fillStyle="#fff",l.globalCompositeOperation="destination-in",l.beginPath(),l.arc(s.width/2,s.height/2,s.width/2,0,2*Math.PI,!0),l.closePath(),l.fill()),s}function k(c,h){var e,i,o,r,p=this,d=[],t=null,n=R.call(p);if("string"==typeof c)e=c,c={};else if(Array.isArray(c))d=c.slice();else{if(void 0===c&&p.data.url)return Y.call(p),F.call(p),null;e=c.url,d=c.points||[],t=void 0===c.zoom?null:c.zoom}return p.data.bound=!1,p.data.url=e||p.data.url,p.data.boundZoom=t,(i=e,o=n,r=new Image,r.style.opacity="0",new Promise(function(e,t){function n(){r.style.opacity="1",setTimeout(function(){e(r)},1)}r.removeAttribute("crossOrigin"),i.match(/^https?:\/\/|^\/\//)&&r.setAttribute("crossOrigin","anonymous"),r.onload=function(){o?EXIF.getData(r,function(){n()}):n()},r.onerror=function(e){r.style.opacity=1,setTimeout(function(){t(e)},1)},r.src=i})).then(function(e){if(function(t){this.elements.img.parentNode&&(Array.prototype.forEach.call(this.elements.img.classList,function(e){t.classList.add(e)}),this.elements.img.parentNode.replaceChild(t,this.elements.img),this.elements.preview=t),this.elements.img=t}.call(p,e),d.length)p.options.relative&&(d=[d[0]*e.naturalWidth/100,d[1]*e.naturalHeight/100,d[2]*e.naturalWidth/100,d[3]*e.naturalHeight/100]);else{var t,n,i=m(e),o=p.elements.viewport.getBoundingClientRect(),r=o.width/o.height;rn.top+t&&m.bottomn.left+e&&m.right=s.maxX&&(o.x=l.minX,n.x=s.maxX),n.x<=s.minX&&(o.x=l.maxX,n.x=s.minX),n.y>=s.maxY&&(o.y=l.minY,n.y=s.maxY),n.y<=s.minY&&(o.y=l.maxY,n.y=s.minY)}r(),F.call(t),W.call(t)}).call(i,{value:parseFloat(t.value),origin:new L(i.elements.preview),viewportRect:i.elements.viewport.getBoundingClientRect(),transform:_.parse(i.elements.preview)})}function n(e){var t,n;if("ctrl"===i.options.mouseWheelZoom&&!0!==e.ctrlKey)return 0;t=e.wheelDelta?e.wheelDelta/1200:e.deltaY?e.deltaY/1060:e.detail?e.detail/-60:0,n=i._currentZoom+t*i._currentZoom,e.preventDefault(),I.call(i,n),o.call(i)}g(e,"cr-slider-wrap"),g(t,"cr-slider"),t.type="range",t.step="0.0001",t.value="1",t.style.display=i.options.showZoomer?"":"none",t.setAttribute("aria-label","zoom"),i.element.appendChild(e),e.appendChild(t),i._currentZoom=1,i.elements.zoomer.addEventListener("input",o),i.elements.zoomer.addEventListener("change",o),i.options.mouseWheelZoom&&(i.elements.boundary.addEventListener("mousewheel",n),i.elements.boundary.addEventListener("DOMMouseScroll",n))}.call(a),a.options.enableResize&&function(){var l,u,c,h,p,e,t,d=this,m=document.createElement("div"),i=!1,f=50;g(m,"cr-resizer"),x(m,{width:this.options.viewport.width+"px",height:this.options.viewport.height+"px"}),this.options.resizeControls.height&&(g(e=document.createElement("div"),"cr-resizer-vertical"),m.appendChild(e));this.options.resizeControls.width&&(g(t=document.createElement("div"),"cr-resizer-horisontal"),m.appendChild(t));function n(e){if((void 0===e.button||0===e.button)&&(e.preventDefault(),!i)){var t=d.elements.overlay.getBoundingClientRect();if(i=!0,u=e.pageX,c=e.pageY,l=-1!==e.currentTarget.className.indexOf("vertical")?"v":"h",h=t.width,p=t.height,e.touches){var n=e.touches[0];u=n.pageX,c=n.pageY}window.addEventListener("mousemove",o),window.addEventListener("touchmove",o),window.addEventListener("mouseup",r),window.addEventListener("touchend",r),document.body.style[y]="none"}}function o(e){var t=e.pageX,n=e.pageY;if(e.preventDefault(),e.touches){var i=e.touches[0];t=i.pageX,n=i.pageY}var o=t-u,r=n-c,a=d.options.viewport.height+r,s=d.options.viewport.width+o;"v"===l&&f<=a&&a<=p?(x(m,{height:a+"px"}),d.options.boundary.height+=r,x(d.elements.boundary,{height:d.options.boundary.height+"px"}),d.options.viewport.height+=r,x(d.elements.viewport,{height:d.options.viewport.height+"px"})):"h"===l&&f<=s&&s<=h&&(x(m,{width:s+"px"}),d.options.boundary.width+=o,x(d.elements.boundary,{width:d.options.boundary.width+"px"}),d.options.viewport.width+=o,x(d.elements.viewport,{width:d.options.viewport.width+"px"})),M.call(d),H.call(d),Z.call(d),W.call(d),c=n,u=t}function r(){i=!1,window.removeEventListener("mousemove",o),window.removeEventListener("touchmove",o),window.removeEventListener("mouseup",r),window.removeEventListener("touchend",r),document.body.style[y]=""}e&&(e.addEventListener("mousedown",n),e.addEventListener("touchstart",n));t&&(t.addEventListener("mousedown",n),t.addEventListener("touchstart",n));this.elements.boundary.appendChild(m)}.call(a)}function u(){return this.options.enableExif&&window.EXIF}function I(e){if(this.options.enableZoom){var t=this.elements.zoomer,n=N(e,4);t.value=Math.max(parseFloat(t.min),Math.min(parseFloat(t.max),n)).toString()}}function Z(e){var t=this,n=t._currentZoom,i=t.elements.preview.getBoundingClientRect(),o=t.elements.viewport.getBoundingClientRect(),r=_.parse(t.elements.preview.style[w]),a=new L(t.elements.preview),s=o.top-i.top+o.height/2,l=o.left-i.left+o.width/2,u={},c={};if(e){var h=a.x,p=a.y,d=r.x,m=r.y;u.y=h,u.x=p,r.y=d,r.x=m}else u.y=s/n,u.x=l/n,c.y=(u.y-a.y)*(1-n),c.x=(u.x-a.x)*(1-n),r.x-=c.x,r.y-=c.y;var f={};f[v]=u.x+"px "+u.y+"px",f[w]=r.toString(),x(t.elements.preview,f)}function M(){if(this.elements){var e=this.elements.boundary.getBoundingClientRect(),t=this.elements.preview.getBoundingClientRect();x(this.elements.overlay,{width:t.width+"px",height:t.height+"px",top:t.top-e.top+"px",left:t.left-e.left+"px"})}}L.prototype.toString=function(){return this.x+"px "+this.y+"px"};var a,s,z,O,F=(a=M,s=500,function(){var e=this,t=arguments,n=z&&!O;clearTimeout(O),O=setTimeout(function(){O=null,z||a.apply(e,t)},s),n&&a.apply(e,t)});function W(){var e,t=this,n=t.get();X.call(t)&&(t.options.update.call(t,n),t.$&&"undefined"==typeof Prototype?t.$(t.element).trigger("update.croppie",n):(window.CustomEvent?e=new CustomEvent("update",{detail:n}):(e=document.createEvent("CustomEvent")).initCustomEvent("update",!0,!0,n),t.element.dispatchEvent(e)))}function X(){return 0l.max)?I.call(r,uthis._originalImageWidth&&(g=(d=this._originalImageWidth-h)/o*s),i<0&&(p=0,v=Math.abs(i)/r*l),m+p>this._originalImageHeight&&(w=(m=this._originalImageHeight-p)/r*l),c.drawImage(this.elements.preview,h,p,d,m,f,v,g,w),a&&(c.fillStyle="#fff",c.globalCompositeOperation="destination-in",c.beginPath(),c.arc(u.width/2,u.height/2,u.width/2,0,2*Math.PI,!0),c.closePath(),c.fill()),u}function A(e){return t=k.call(this,e),n=e.format,i=e.quality,m(t).toDataURL(n,i);var t,n,i}function S(e){return n=k.call(this,e),i=e.format,o=e.quality,n.convertToBlob?Promise.resolve(n.convertToBlob({type:i,quality:o})):new Promise(function(t){n.toBlob(function(e){t(e)},i,o)});var n,i,o}function j(c,h){var e,p=this,d=[],t=null,n=u.call(p);if("string"==typeof c)e=c,c={};else if(Array.isArray(c))d=c.slice();else{if(void 0===c&&p.data.url)return Y.call(p),W.call(p),null;e=c.url,d=c.points||[],t=void 0===c.zoom?null:c.zoom}return p.data.bound=!1,p.data.url=e||p.data.url,p.data.boundZoom=t,function(i,o){if(!i)throw"Source image missing";var r=new Image;return r.style.opacity="0",new Promise(function(e,t){function n(){r.style.opacity="1",setTimeout(function(){e(r)},1)}r.removeAttribute("crossOrigin"),i.match(/^https?:\/\/|^\/\//)&&r.setAttribute("crossOrigin","anonymous"),r.onload=function(){o?EXIF.getData(r,function(){n()}):n()},r.onerror=function(e){r.style.opacity=1,setTimeout(function(){t(e)},1)},r.src=i})}(e,n).then(function(e){if(function(t){this.elements.img.parentNode&&(Array.prototype.forEach.call(this.elements.img.classList,function(e){t.classList.add(e)}),this.elements.img.parentNode.replaceChild(t,this.elements.img),this.elements.preview=t),this.elements.img=t}.call(p,e),d.length)p.options.relative&&(d=[d[0]*e.naturalWidth/100,d[1]*e.naturalHeight/100,d[2]*e.naturalWidth/100,d[3]*e.naturalHeight/100]);else{var t,n,i=f(e),o=p.elements.viewport.getBoundingClientRect(),r=o.width/o.height;r