!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 t(e,t){return function(){e.apply(t,arguments)}}function n(e){if("object"!=typeof this)throw TypeError("Promises must be constructed via new");if("function"!=typeof e)throw TypeError("not a function");this._state=null,this._value=null,this._deferreds=[],l(e,t(o,this),t(r,this))}function i(e){var t=this;return null===this._state?void this._deferreds.push(e):void u(function(){var n,i=t._state?e.onFulfilled:e.onRejected;if(null===i)return void(t._state?e.resolve:e.reject)(t._value);try{n=i(t._value)}catch(o){return void e.reject(o)}e.resolve(n)})}function o(e){try{if(e===this)throw TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var n=e.then;if("function"==typeof n)return void l(t(n,e),t(o,this),t(r,this))}this._state=!0,this._value=e,a.call(this)}catch(i){r.call(this,i)}}function r(e){this._state=!1,this._value=e,a.call(this)}function a(){for(var e=0,t=this._deferreds.length;t>e;e++)i.call(this,this._deferreds[e]);this._deferreds=null}function s(e,t,n,i){this.onFulfilled="function"==typeof e?e:null,this.onRejected="function"==typeof t?t:null,this.resolve=n,this.reject=i}function l(e,t,n){var i=!1;try{e(function(e){i||(i=!0,t(e))},function(e){i||(i=!0,n(e))})}catch(o){if(i)return;i=!0,n(o)}}var h=setTimeout,u="function"==typeof setImmediate&&setImmediate||function(e){h(e,1)},c=Array.isArray||function(e){return"[object Array]"===Object.prototype.toString.call(e)};n.prototype.catch=function(e){return this.then(null,e)},n.prototype.then=function(e,t){var o=this;return new n(function(n,r){i.call(o,new s(e,t,n,r))})},n.all=function(){var e=Array.prototype.slice.call(1===arguments.length&&c(arguments[0])?arguments[0]:arguments);return new n(function(t,n){function i(r,a){try{if(a&&("object"==typeof a||"function"==typeof a)){var s=a.then;if("function"==typeof s)return void s.call(a,function(e){i(r,e)},n)}e[r]=a,0==--o&&t(e)}catch(l){n(l)}}if(0===e.length)return t([]);for(var o=e.length,r=0;r<e.length;r++)i(r,e[r])})},n.resolve=function(e){return e&&"object"==typeof e&&e.constructor===n?e:new n(function(t){t(e)})},n.reject=function(e){return new n(function(t,n){n(e)})},n.race=function(e){return new n(function(t,n){for(var i=0,o=e.length;o>i;i++)e[i].then(t,n)})},n._setImmediateFn=function(e){u=e},"undefined"!=typeof module&&module.exports?module.exports=n:e.Promise||(e.Promise=n)}(this),"undefined"!=typeof window&&"function"!=typeof window.CustomEvent&&function(){function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}e.prototype=window.Event.prototype,window.CustomEvent=e}(),"undefined"==typeof HTMLCanvasElement||HTMLCanvasElement.prototype.toBlob||Object.defineProperty(HTMLCanvasElement.prototype,"toBlob",{value:function(e,t,n){for(var i=atob(this.toDataURL(t,n).split(",")[1]),o=i.length,r=new Uint8Array(o),a=0;a<o;a++)r[a]=i.charCodeAt(a);e(new Blob([r],{type:t||"image/png"}))}});var e,t,n,i=["Webkit","Moz","ms"],o="undefined"!=typeof document?document.createElement("div").style:{},r=[1,8,3,6],a=[2,7,4,5];function s(e){if(e in o)return e;for(var t=e[0].toUpperCase()+e.slice(1),n=i.length;n--;)if((e=i[n]+t)in o)return e}function l(e,t){for(var n in e=e||{},t)t[n]&&t[n].constructor&&t[n].constructor===Object?(e[n]=e[n]||{},l(e[n],t[n])):e[n]=t[n];return e}function h(e){return l({},e)}function u(e){if("createEvent"in document){var t=document.createEvent("HTMLEvents");t.initEvent("change",!1,!0),e.dispatchEvent(t)}else e.fireEvent("onchange")}function c(e,t,n){if("string"==typeof t){var i=t;(t={})[i]=n}for(var o in t)e.style[o]=t[o]}function p(e,t){e.classList?e.classList.add(t):e.className+=" "+t}function d(e,t){for(var n in t)e.setAttribute(n,t[n])}function m(e){return parseInt(e,10)}function f(e,t){var n=e.naturalWidth,i=e.naturalHeight,o=t||y(e);if(o&&o>=5){var r=n;n=i,i=r}return{width:n,height:i}}t=s("transform"),e=s("transformOrigin"),n=s("userSelect");var v={translate3d:{suffix:", 0px"},translate:{suffix:""}},g=function(e,t,n){this.x=parseFloat(e),this.y=parseFloat(t),this.scale=parseFloat(n)};g.parse=function(e){return e.style?g.parse(e.style[t]):e.indexOf("matrix")>-1||e.indexOf("none")>-1?g.fromMatrix(e):g.fromString(e)},g.fromMatrix=function(e){var t=e.substring(7).split(",");return t.length&&"none"!==e||(t=[1,0,0,1,0,0]),new g(m(t[4]),m(t[5]),parseFloat(t[0]))},g.fromString=function(e){var t=e.split(") "),n=t[0].substring(ei.globals.translate.length+1).split(","),i=t.length>1?t[1].substring(6):1,o=n.length>1?n[0]:0,r=n.length>1?n[1]:0;return new g(o,r,i)},g.prototype.toString=function(){var e=v[ei.globals.translate].suffix||"";return ei.globals.translate+"("+this.x+"px, "+this.y+"px"+e+") scale("+this.scale+")"};var w=function(t){if(!t||!t.style[e]){this.x=0,this.y=0;return}var n=t.style[e].split(" ");this.x=parseFloat(n[0]),this.y=parseFloat(n[1])};function y(e){return e.exifdata&&e.exifdata.Orientation?m(e.exifdata.Orientation):1}function $(e,t,n){var i=t.width,o=t.height,r=e.getContext("2d");switch(e.width=t.width,e.height=t.height,r.save(),n){case 2:r.translate(i,0),r.scale(-1,1);break;case 3:r.translate(i,o),r.rotate(180*Math.PI/180);break;case 4:r.translate(0,o),r.scale(1,-1);break;case 5:e.width=o,e.height=i,r.rotate(90*Math.PI/180),r.scale(1,-1);break;case 6:e.width=o,e.height=i,r.rotate(90*Math.PI/180),r.translate(0,-o);break;case 7:e.width=o,e.height=i,r.rotate(-90*Math.PI/180),r.translate(-i,o),r.scale(1,-1);break;case 8:e.width=o,e.height=i,r.translate(0,i),r.rotate(-90*Math.PI/180)}r.drawImage(t,0,0,i,o),r.restore()}function b(){var e,t,n,i,o,r,a=this,s=a.options.viewport.type?"cr-vp-"+a.options.viewport.type:null;a.options.useCanvas=a.options.enableOrientation||_.call(a),a.data={},a.elements={},e=a.elements.boundary=document.createElement("div"),n=a.elements.viewport=document.createElement("div"),t=a.elements.img=document.createElement("img"),i=a.elements.overlay=document.createElement("div"),a.options.useCanvas?(a.elements.canvas=document.createElement("canvas"),a.elements.preview=a.elements.canvas):a.elements.preview=t,p(e,"cr-boundary"),e.setAttribute("aria-dropeffect","none"),o=a.options.boundary.width,r=a.options.boundary.height,c(e,{width:o+(isNaN(o)?"":"px"),height:r+(isNaN(r)?"":"px")}),p(n,"cr-viewport"),s&&p(n,s),c(n,{width:a.options.viewport.width+"px",height:a.options.viewport.height+"px"}),n.setAttribute("tabindex",0),p(a.elements.preview,"cr-image"),d(a.elements.preview,{alt:"preview","aria-grabbed":"false"}),p(i,"cr-overlay"),a.element.appendChild(e),e.appendChild(a.elements.preview),e.appendChild(n),e.appendChild(i),p(a.element,"croppie-container"),a.options.customClass&&p(a.element,a.options.customClass),B.call(this),a.options.enableZoom&&E.call(a),a.options.enableResize&&x.call(a)}function _(){return this.options.enableExif&&window.EXIF}function x(){var e,t,i,o,r,a,s,l=this,h=document.createElement("div"),u=!1;function d(a){if((void 0===a.button||0===a.button)&&(a.preventDefault(),!u)){var s=l.elements.overlay.getBoundingClientRect();if(u=!0,t=a.pageX,i=a.pageY,e=-1!==a.currentTarget.className.indexOf("vertical")?"v":"h",o=s.width,r=s.height,a.touches){var h=a.touches[0];t=h.pageX,i=h.pageY}window.addEventListener("mousemove",m),window.addEventListener("touchmove",m),window.addEventListener("mouseup",f),window.addEventListener("touchend",f),document.body.style[n]="none"}}function m(n){var a=n.pageX,s=n.pageY;if(n.preventDefault(),n.touches){var u=n.touches[0];a=u.pageX,s=u.pageY}var p=a-t,d=s-i,m=l.options.viewport.height+d,f=l.options.viewport.width+p;"v"===e&&m>=50&&m<=r?(c(h,{height:m+"px"}),l.options.boundary.height+=d,c(l.elements.boundary,{height:l.options.boundary.height+"px"}),l.options.viewport.height+=d,c(l.elements.viewport,{height:l.options.viewport.height+"px"})):"h"===e&&f>=50&&f<=o&&(c(h,{width:f+"px"}),l.options.boundary.width+=p,c(l.elements.boundary,{width:l.options.boundary.width+"px"}),l.options.viewport.width+=p,c(l.elements.viewport,{width:l.options.viewport.width+"px"})),z.call(l),O.call(l),Z.call(l),k.call(l),i=s,t=a}function f(){u=!1,window.removeEventListener("mousemove",m),window.removeEventListener("touchmove",m),window.removeEventListener("mouseup",f),window.removeEventListener("touchend",f),document.body.style[n]=""}p(h,"cr-resizer"),c(h,{width:this.options.viewport.width+"px",height:this.options.viewport.height+"px"}),this.options.resizeControls.height&&(p(a=document.createElement("div"),"cr-resizer-vertical"),h.appendChild(a)),this.options.resizeControls.width&&(p(s=document.createElement("div"),"cr-resizer-horisontal"),h.appendChild(s)),a&&(a.addEventListener("mousedown",d),a.addEventListener("touchstart",d)),s&&(s.addEventListener("mousedown",d),s.addEventListener("touchstart",d)),this.elements.boundary.appendChild(h)}function C(e){if(this.options.enableZoom){var t=this.elements.zoomer,n=T(e,4);t.value=Math.max(parseFloat(t.min),Math.min(parseFloat(t.max),n)).toString()}}function E(){var e=this,t=e.elements.zoomerWrap=document.createElement("div"),n=e.elements.zoomer=document.createElement("input");function i(){L.call(e,{value:parseFloat(n.value),origin:new w(e.elements.preview),viewportRect:e.elements.viewport.getBoundingClientRect(),transform:g.parse(e.elements.preview)})}function o(t){var n,o;if("ctrl"===e.options.mouseWheelZoom&&!0!==t.ctrlKey)return 0;n=t.wheelDelta?t.wheelDelta/1200:t.deltaY?t.deltaY/1060:t.detail?-(t.detail/60):0,o=e._currentZoom+n*e._currentZoom,t.preventDefault(),C.call(e,o),i.call(e)}p(t,"cr-slider-wrap"),p(n,"cr-slider"),n.type="range",n.step="0.0001",n.value="1",n.style.display=e.options.showZoomer?"":"none",n.setAttribute("aria-label","zoom"),e.element.appendChild(t),t.appendChild(n),e._currentZoom=1,e.elements.zoomer.addEventListener("input",i),e.elements.zoomer.addEventListener("change",i),e.options.mouseWheelZoom&&(e.elements.boundary.addEventListener("mousewheel",o),e.elements.boundary.addEventListener("DOMMouseScroll",o))}function L(n){var i=this,o=n?n.transform:g.parse(i.elements.preview),r=n?n.viewportRect:i.elements.viewport.getBoundingClientRect(),a=n?n.origin:new w(i.elements.preview);function s(){var n={};n[t]=o.toString(),n[e]=a.toString(),c(i.elements.preview,n)}if(i._currentZoom=n?n.value:i._currentZoom,o.scale=i._currentZoom,i.elements.zoomer.setAttribute("aria-valuenow",i._currentZoom),s(),i.options.enforceBoundary){var l=R.call(i,r),h=l.translate,u=l.origin;o.x>=h.maxX&&(a.x=u.minX,o.x=h.maxX),o.x<=h.minX&&(a.x=u.maxX,o.x=h.minX),o.y>=h.maxY&&(a.y=u.minY,o.y=h.maxY),o.y<=h.minY&&(a.y=u.maxY,o.y=h.minY)}s(),X.call(i),k.call(i)}function R(e){var t=this._currentZoom,n=e.width,i=e.height,o=this.elements.boundary.clientWidth/2,r=this.elements.boundary.clientHeight/2,a=this.elements.preview.getBoundingClientRect(),s=a.width,l=a.height,h=n/2,u=i/2,c=-((h/t-o)*1),p=-((u/t-r)*1),d=1/t*h,m=1/t*u;return{translate:{maxX:c,minX:c-(s*(1/t)-n*(1/t)),maxY:p,minY:p-(l*(1/t)-i*(1/t))},origin:{maxX:s*(1/t)-d,minX:d,maxY:l*(1/t)-m,minY:m}}}function Z(n){var i=this._currentZoom,o=this.elements.preview.getBoundingClientRect(),r=this.elements.viewport.getBoundingClientRect(),a=g.parse(this.elements.preview.style[t]),s=new w(this.elements.preview),l=r.top-o.top+r.height/2,h=r.left-o.left+r.width/2,u={},p={};if(n){var d=s.x,m=s.y,f=a.x,v=a.y;u.y=d,u.x=m,a.y=f,a.x=v}else u.y=l/i,u.x=h/i,p.y=(u.y-s.y)*(1-i),p.x=(u.x-s.x)*(1-i),a.x-=p.x,a.y-=p.y;var y={};y[e]=u.x+"px "+u.y+"px",y[t]=a.toString(),c(this.elements.preview,y)}function B(){var e,i,o,r,a,s=this,l=!1;function h(e,t){var n=s.elements.preview.getBoundingClientRect(),i=a.y+t,o=a.x+e;s.options.enforceBoundary?(r.top>n.top+t&&r.bottom<n.bottom+t&&(a.y=i),r.left>n.left+e&&r.right<n.right+e&&(a.x=o)):(a.y=i,a.x=o)}function p(e){s.elements.preview.setAttribute("aria-grabbed",e),s.elements.boundary.setAttribute("aria-dropeffect",e?"move":"none")}function d(t){if((void 0===t.button||0===t.button)&&(t.preventDefault(),!l)){if(l=!0,e=t.pageX,i=t.pageY,t.touches){var o=t.touches[0];e=o.pageX,i=o.pageY}p(l),a=g.parse(s.elements.preview),window.addEventListener("mousemove",m),window.addEventListener("touchmove",m),window.addEventListener("mouseup",f),window.addEventListener("touchend",f),document.body.style[n]="none",r=s.elements.viewport.getBoundingClientRect()}}function m(n){n.preventDefault();var r=n.pageX,l=n.pageY;if(n.touches){var p=n.touches[0];r=p.pageX,l=p.pageY}var d=r-e,m=l-i,f={};if("touchmove"===n.type&&n.touches.length>1){var v=n.touches[0],g=n.touches[1],w=Math.sqrt((v.pageX-g.pageX)*(v.pageX-g.pageX)+(v.pageY-g.pageY)*(v.pageY-g.pageY));o||(o=w/s._currentZoom);var y=w/o;C.call(s,y),u(s.elements.zoomer);return}h(d,m),f[t]=a.toString(),c(s.elements.preview,f),z.call(s),i=l,e=r}function f(){p(l=!1),window.removeEventListener("mousemove",m),window.removeEventListener("touchmove",m),window.removeEventListener("mouseup",f),window.removeEventListener("touchend",f),document.body.style[n]="",Z.call(s),k.call(s),o=0}s.elements.overlay.addEventListener("mousedown",d),s.elements.viewport.addEventListener("keydown",function e(i){var l;if(i.shiftKey&&(38===i.keyCode||40===i.keyCode))l=38===i.keyCode?parseFloat(s.elements.zoomer.value)+parseFloat(s.elements.zoomer.step):parseFloat(s.elements.zoomer.value)-parseFloat(s.elements.zoomer.step),s.setZoom(l);else if(s.options.enableKeyMovement&&i.keyCode>=37&&i.keyCode<=40){i.preventDefault();var u,p,d,m,f=function e(t){switch(t){case 37:return[1,0];case 38:return[0,1];case 39:return[-1,0];case 40:return[0,-1]}}(i.keyCode);a=g.parse(s.elements.preview),document.body.style[n]="none",r=s.elements.viewport.getBoundingClientRect(),p=(u=f)[0],d=u[1],m={},h(p,d),m[t]=a.toString(),c(s.elements.preview,m),z.call(s),document.body.style[n]="",Z.call(s),k.call(s),o=0}}),s.elements.overlay.addEventListener("touchstart",d)}function z(){if(this.elements){var e=this.elements.boundary.getBoundingClientRect(),t=this.elements.preview.getBoundingClientRect();c(this.elements.overlay,{width:t.width+"px",height:t.height+"px",top:t.top-e.top+"px",left:t.left-e.left+"px"})}}w.prototype.toString=function(){return this.x+"px "+this.y+"px"};var I,W,Y,X=(I=z,function(){var e=this,t=arguments,n=function(){Y=null,W||I.apply(e,t)},i=W&&!Y;clearTimeout(Y),Y=setTimeout(n,500),i&&I.apply(e,t)});function k(){var e,t=this.get();S.call(this)&&(this.options.update.call(this,t),this.$&&"undefined"==typeof Prototype?this.$(this.element).trigger("update.croppie",t):(window.CustomEvent?e=new CustomEvent("update",{detail:t}):(e=document.createEvent("CustomEvent")).initCustomEvent("update",!0,!0,t),this.element.dispatchEvent(e)))}function S(){return this.elements.preview.offsetHeight>0&&this.elements.preview.offsetWidth>0}function H(){var n,i=this,o={},r=i.elements.preview,a=new g(0,0,1),s=new w;S.call(i)&&!i.data.bound&&(i.data.bound=!0,o[t]=a.toString(),o[e]=s.toString(),o.opacity=1,c(r,o),n=i.elements.preview.getBoundingClientRect(),i._originalImageWidth=n.width,i._originalImageHeight=n.height,i.data.orientation=_.call(i)?y(i.elements.img):i.data.orientation,i.options.enableZoom?O.call(i,!0):i._currentZoom=1,a.scale=i._currentZoom,o[t]=a.toString(),c(r,o),i.data.points.length?j.call(i,i.data.points):A.call(i),Z.call(i),z.call(i))}function O(e){var t,n,i,o,r=Math.max(this.options.minZoom,0)||0,a=this.options.maxZoom||1.5,s=this.elements.zoomer,l=parseFloat(s.value),h=this.elements.boundary.getBoundingClientRect(),c=f(this.elements.img,this.data.orientation),p=this.elements.viewport.getBoundingClientRect();this.options.enforceBoundary&&(r=Math.max(i=p.width/c.width,o=p.height/c.height)),r>=a&&(a=r+1),s.min=T(r,4),s.max=T(a,4),!e&&(l<s.min||l>s.max)?C.call(this,l<s.min?s.min:s.max):e&&(n=Math.max(h.width/c.width,h.height/c.height),t=null!==this.data.boundZoom?this.data.boundZoom:n,C.call(this,t)),u(s)}function j(n){if(4!==n.length)throw"Croppie - Invalid number of points supplied: "+n;var i=this,o=n[2]-n[0],r=i.elements.viewport.getBoundingClientRect(),a=i.elements.boundary.getBoundingClientRect(),s={left:r.left-a.left,top:r.top-a.top},l=r.width/o,h=n[1],u=n[0],p=-1*n[1]+s.top,d=-1*n[0]+s.left,m={};m[e]=u+"px "+h+"px",m[t]=new g(d,p,l).toString(),c(i.elements.preview,m),C.call(i,l),i._currentZoom=l}function A(){var e=this.elements.preview.getBoundingClientRect(),n=this.elements.viewport.getBoundingClientRect(),i=this.elements.boundary.getBoundingClientRect(),o=n.left-i.left,r=n.top-i.top,a=o-(e.width-n.width)/2,s=r-(e.height-n.height)/2,l=new g(a,s,this._currentZoom);c(this.elements.preview,t,l.toString())}function D(e){var t=this.elements.canvas,n=this.elements.img;t.getContext("2d").clearRect(0,0,t.width,t.height),t.width=n.width,t.height=n.height;var i=this.options.enableOrientation&&e||y(n);$(t,n,i)}function N(e){var t=e.points,n=m(t[0]),i=m(t[1]),o=m(t[2]),r=m(t[3]),a=o-n,s=r-i,l=e.circle,h=document.createElement("canvas"),u=h.getContext("2d"),c=e.outputWidth||a,p=e.outputHeight||s;h.width=c,h.height=p,e.backgroundColor&&(u.fillStyle=e.backgroundColor,u.fillRect(0,0,c,p));var d=n,f=i,v=a,g=s,w=0,y=0,$=c,b=p;return n<0&&(d=0,w=Math.abs(n)/a*c),v+d>this._originalImageWidth&&($=(v=this._originalImageWidth-d)/a*c),i<0&&(f=0,y=Math.abs(i)/s*p),g+f>this._originalImageHeight&&(b=(g=this._originalImageHeight-f)/s*p),u.drawImage(this.elements.preview,d,f,v,g,w,y,$,b),l&&(u.fillStyle="#fff",u.globalCompositeOperation="destination-in",u.beginPath(),u.arc(h.width/2,h.height/2,h.width/2,0,2*Math.PI,!0),u.closePath(),u.fill()),h}function P(e){var t=e.points,n=document.createElement("div"),i=document.createElement("img"),o=t[2]-t[0],r=t[3]-t[1];return p(n,"croppie-result"),n.appendChild(i),c(i,{left:-1*t[0]+"px",top:-1*t[1]+"px"}),i.src=e.url,c(n,{width:o+"px",height:r+"px"}),n}function F(e){return N.call(this,e).toDataURL(e.format,e.quality)}function M(e){var t=this;return new Promise(function(n){N.call(t,e).toBlob(function(e){n(e)},e.format,e.quality)})}function q(e){this.elements.img.parentNode&&(Array.prototype.forEach.call(this.elements.img.classList,function(t){e.classList.add(t)}),this.elements.img.parentNode.replaceChild(e,this.elements.img),this.elements.preview=e),this.elements.img=e}function K(e,t){var n,i=this,o=[],r=null,a=_.call(i);if("string"==typeof e)n=e,e={};else if(Array.isArray(e))o=e.slice();else{if(void 0===e&&i.data.url)return H.call(i),k.call(i),null;n=e.url,o=e.points||[],r=void 0===e.zoom?null:e.zoom}return i.data.bound=!1,i.data.url=n||i.data.url,i.data.boundZoom=r,(function e(t,n){if(!t)throw"Source image missing";var i=new Image;return i.style.opacity="0",new Promise(function(e,o){function r(){i.style.opacity="1",setTimeout(function(){e(i)},1)}i.removeAttribute("crossOrigin"),t.match(/^https?:\/\/|^\/\//)&&i.setAttribute("crossOrigin","anonymous"),i.onload=function(){n?EXIF.getData(i,function(){r()}):r()},i.onerror=function(e){i.style.opacity=1,setTimeout(function(){o(e)},1)},i.src=t})})(n,a).then(function(n){if(q.call(i,n),o.length)i.options.relative&&(o=[o[0]*n.naturalWidth/100,o[1]*n.naturalHeight/100,o[2]*n.naturalWidth/100,o[3]*n.naturalHeight/100]);else{var r,a,s=f(n),l=i.elements.viewport.getBoundingClientRect(),h=l.width/l.height;s.width/s.height>h?r=(a=s.height)*h:(r=s.width,a=s.height/h);var u=(s.width-r)/2,c=(s.height-a)/2,p=u+r,d=c+a;i.data.points=[u,c,p,d]}i.data.orientation=e.orientation||1,i.data.points=o.map(function(e){return parseFloat(e)}),i.options.useCanvas&&D.call(i,i.data.orientation),H.call(i),k.call(i),t&&t()})}function T(e,t){return parseFloat(e).toFixed(t||0)}function U(){var e=this.elements.preview.getBoundingClientRect(),t=this.elements.viewport.getBoundingClientRect(),n=t.left-e.left,i=t.top-e.top,o=(t.width-this.elements.viewport.offsetWidth)/2,r=(t.height-this.elements.viewport.offsetHeight)/2,a=n+this.elements.viewport.offsetWidth+o,s=i+this.elements.viewport.offsetHeight+r,l=this._currentZoom;(l===1/0||isNaN(l))&&(l=1);var h=this.options.enforceBoundary?0:Number.NEGATIVE_INFINITY;return n=Math.max(h,n/l),i=Math.max(h,i/l),a=Math.max(h,a/l),s=Math.max(h,s/l),{points:[T(n),T(i),T(a),T(s)],zoom:l,orientation:this.data.orientation}}var Q={type:"canvas",format:"png",quality:1},G=["jpeg","webp","png"];function V(e){var t,n=this,i=U.call(n),o=l(h(Q),h(e)),r="string"==typeof e?e:o.type||"base64",a=o.size||"viewport",s=o.format,u=o.quality,c=o.backgroundColor,p="boolean"==typeof o.circle?o.circle:"circle"===n.options.viewport.type,d=n.elements.viewport.getBoundingClientRect(),m=d.width/d.height;return"viewport"===a?(i.outputWidth=d.width,i.outputHeight=d.height):"object"==typeof a&&(a.width&&a.height?(i.outputWidth=a.width,i.outputHeight=a.height):a.width?(i.outputWidth=a.width,i.outputHeight=a.width/m):a.height&&(i.outputWidth=a.height*m,i.outputHeight=a.height)),G.indexOf(s)>-1&&(i.format="image/"+s,i.quality=u),i.circle=p,i.url=n.data.url,i.backgroundColor=c,t=new Promise(function(e){switch(r.toLowerCase()){case"rawcanvas":e(N.call(n,i));break;case"canvas":case"base64":e(F.call(n,i));break;case"blob":M.call(n,i).then(e);break;default:e(P.call(n,i))}})}function J(){H.call(this)}function ee(e){if(!this.options.useCanvas||!this.options.enableOrientation)throw"Croppie: Cannot rotate without enableOrientation && EXIF.js included";var t,n,i,o,s,l=this,h=l.elements.canvas;if(l.data.orientation=(t=l.data.orientation,n=e,o=(i=r.indexOf(t)>-1?r:a).indexOf(t),s=n/90%i.length,i[(i.length+o+s%i.length)%i.length]),$(h,l.elements.img,l.data.orientation),Z.call(l,!0),O.call(l),Math.abs(e)/90%2==1){var u=l._originalImageHeight,c=l._originalImageWidth;l._originalImageWidth=u,l._originalImageHeight=c}}function et(){this.element.removeChild(this.elements.boundary);var e,t="croppie-container";(e=this.element).classList?e.classList.remove(t):e.className=e.className.replace(t,""),this.options.enableZoom&&this.element.removeChild(this.elements.zoomerWrap),delete this.elements}if("undefined"!=typeof window&&window.jQuery){var en=window.jQuery;en.fn.croppie=function(e){if("string"!=typeof e)return this.each(function(){var t=new ei(this,e);t.$=en,en(this).data("croppie",t)});var t=Array.prototype.slice.call(arguments,1),n=en(this).data("croppie");return"get"===e?n.get():"result"===e?n.result.apply(n,t):"bind"===e?n.bind.apply(n,t):this.each(function(){var n=en(this).data("croppie");if(n){var i=n[e];if(en.isFunction(i))i.apply(n,t),"destroy"===e&&en(this).removeData("croppie");else throw"Croppie "+e+" method not found"}})}}function ei(e,t){if(e.className.indexOf("croppie-container")>-1)throw Error("Croppie: Can't initialize croppie more than once");if(this.element=e,this.options=l(h(ei.defaults),t),"img"===this.element.tagName.toLowerCase()){var n=this.element;p(n,"cr-original-image"),d(n,{"aria-hidden":"true",alt:""});var i=document.createElement("div");this.element.parentNode.appendChild(i),i.appendChild(n),this.element=i,this.options.url=this.options.url||n.src}if(b.call(this),this.options.url){var o={url:this.options.url,points:this.options.points};delete this.options.url,delete this.options.points,K.call(this,o)}}return ei.defaults={viewport:{width:100,height:100,type:"square"},boundary:{},orientationControls:{enabled:!0,leftClass:"",rightClass:""},resizeControls:{width:!0,height:!0},customClass:"",showZoomer:!0,enableZoom:!0,enableResize:!1,mouseWheelZoom:!0,enableExif:!1,enforceBoundary:!0,enableOrientation:!1,enableKeyMovement:!0,update:function(){}},ei.globals={translate:"translate3d"},l(ei.prototype,{bind:function(e,t){return K.call(this,e,t)},get:function(){var e=U.call(this),t=e.points;return this.options.relative&&(t[0]/=this.elements.img.naturalWidth/100,t[1]/=this.elements.img.naturalHeight/100,t[2]/=this.elements.img.naturalWidth/100,t[3]/=this.elements.img.naturalHeight/100),e},result:function(e){return V.call(this,e)},refresh:function(){return J.call(this)},setZoom:function(e){C.call(this,e),u(this.elements.zoomer)},rotate:function(e){ee.call(this,e)},destroy:function(){return et.call(this)}}),ei});
