!function(t,i){"object"==typeof exports&&"undefined"!=typeof module?i(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],i):i(t.jQuery)}(this,function(t){"use strict";function i(t){return"number"==typeof t&&!xt(t)}function e(t){return void 0===t}function a(t){return"object"===(void 0===t?"undefined":gt(t))&&null!==t}function n(t){if(!a(t))return!1;try{var i=t.constructor,e=i.prototype;return i&&e&&bt.call(e,"isPrototypeOf")}catch(t){return!1}}function o(t){return"function"==typeof t}function h(t,e){if(t&&o(e))if(Array.isArray(t)||i(t.length)){var n=t.length,h=void 0;for(h=0;h1&&void 0!==arguments[1]?arguments[1]:1e11;return Mt.test(t)?Math.round(t*i)/i:t}function s(t,e){var a=t.style;h(e,function(t,e){Ct.test(e)&&i(t)&&(t+="px"),a[e]=t})}function d(t,e){if(e)if(i(t.length))h(t,function(t){d(t,e)});else if(t.classList)t.classList.add(e);else{var a=t.className.trim();a?a.indexOf(e)<0&&(t.className=a+" "+e):t.className=e}}function c(t,e){e&&(i(t.length)?h(t,function(t){c(t,e)}):t.classList?t.classList.remove(e):t.className.indexOf(e)>=0&&(t.className=t.className.replace(e,"")))}function l(t,e,a){e&&(i(t.length)?h(t,function(t){l(t,e,a)}):a?d(t,e):c(t,e))}function p(t){return t.replace(Dt,"$1-$2").toLowerCase()}function m(t,i){return a(t[i])?t[i]:t.dataset?t.dataset[i]:t.getAttribute("data-"+p(i))}function u(t,i,e){a(e)?t[i]=e:t.dataset?t.dataset[i]=e:t.setAttribute("data-"+p(i),e)}function g(t,i){if(a(t[i]))try{delete t[i]}catch(e){t[i]=void 0}else if(t.dataset)try{delete t.dataset[i]}catch(e){t.dataset[i]=void 0}else t.removeAttribute("data-"+p(i))}function f(t,i,e){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};h(i.trim().split(Bt),function(i){t.removeEventListener(i,e,a)})}function v(t,i,e){var a=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};if(a.once){var n=e;e=function(){for(var o=arguments.length,h=Array(o),r=0;r1&&void 0!==arguments[1]?arguments[1]:"contain",o=function(t){return Wt(t)&&t>0};if(o(a)&&o(e)){var h=e*i;"contain"===n&&h>a||"cover"===n&&h=8&&(o=s+c)}}}if(o){var l=i.getUint16(o,a),p=void 0,m=void 0;for(m=0;m1?i-1:0),n=1;n0&&e.forEach(function(i){a(i)&&Object.keys(i).forEach(function(e){t[e]=i[e]})}),t},Mt=/\.\d*(?:0|9){12}\d*$/i,Ct=/^(?:width|height|left|top|marginLeft|marginTop)$/,Dt=/([a-z\d])([A-Z])/g,Bt=/\s\s*/,kt=k.location,Tt=/^(https?:)\/\/([^:/?#]+):?(\d*)/i,Wt=Number.isFinite||k.isFinite,Ht=String.fromCharCode,Nt=/^data:.*,/,Et={render:function(){this.initContainer(),this.initCanvas(),this.initCropBox(),this.renderCanvas(),this.cropped&&this.renderCropBox()},initContainer:function(){var t=this.element,i=this.options,e=this.container,a=this.cropper;d(a,j),c(t,j);var n={width:Math.max(e.offsetWidth,Number(i.minContainerWidth)||200),height:Math.max(e.offsetHeight,Number(i.minContainerHeight)||100)};this.containerData=n,s(a,{width:n.width,height:n.height}),d(t,j),c(a,j)},initCanvas:function(){var t=this.containerData,i=this.imageData,e=this.options.viewMode,a=Math.abs(i.rotate)%180==90,n=a?i.naturalHeight:i.naturalWidth,o=a?i.naturalWidth:i.naturalHeight,h=n/o,r=t.width,s=t.height;t.height*h>t.width?3===e?r=t.height*h:s=t.width/h:3===e?s=t.width/h:r=t.height*h;var d={aspectRatio:h,naturalWidth:n,naturalHeight:o,width:r,height:s};d.left=(t.width-r)/2,d.top=(t.height-s)/2,d.oldLeft=d.left,d.oldTop=d.top,this.canvasData=d,this.limited=1===e||2===e,this.limitCanvas(!0,!0),this.initialImageData=yt({},i),this.initialCanvasData=yt({},d)},limitCanvas:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,h=e.viewMode,r=n.aspectRatio,s=this.cropped&&o;if(t){var d=Number(e.minCanvasWidth)||0,c=Number(e.minCanvasHeight)||0;h>1?(d=Math.max(d,a.width),c=Math.max(c,a.height),3===h&&(c*r>d?d=c*r:c=d/r)):h>0&&(d?d=Math.max(d,s?o.width:0):c?c=Math.max(c,s?o.height:0):s&&(d=o.width,(c=o.height)*r>d?d=c*r:c=d/r));var l=D({aspectRatio:r,width:d,height:c});d=l.width,c=l.height,n.minWidth=d,n.minHeight=c,n.maxWidth=1/0,n.maxHeight=1/0}if(i)if(h){var p=a.width-n.width,m=a.height-n.height;n.minLeft=Math.min(0,p),n.minTop=Math.min(0,m),n.maxLeft=Math.max(0,p),n.maxTop=Math.max(0,m),s&&this.limited&&(n.minLeft=Math.min(o.left,o.left+(o.width-n.width)),n.minTop=Math.min(o.top,o.top+(o.height-n.height)),n.maxLeft=o.left,n.maxTop=o.top,2===h&&(n.width>=a.width&&(n.minLeft=Math.min(0,p),n.maxLeft=Math.max(0,p)),n.height>=a.height&&(n.minTop=Math.min(0,m),n.maxTop=Math.max(0,m))))}else n.minLeft=-n.width,n.minTop=-n.height,n.maxLeft=a.width,n.maxTop=a.height},renderCanvas:function(t,i){var e=this.canvasData,a=this.imageData;if(i){var n=function(t){var i=t.width,e=t.height,a=t.degree;if(90==(a=Math.abs(a)%180))return{width:e,height:i};var n=a%90*Math.PI/180,o=Math.sin(n),h=Math.cos(n),r=i*h+e*o,s=i*o+e*h;return a>90?{width:s,height:r}:{width:r,height:s}}({width:a.naturalWidth*Math.abs(a.scaleX||1),height:a.naturalHeight*Math.abs(a.scaleY||1),degree:a.rotate||0}),o=n.width,h=n.height,r=e.width*(o/e.naturalWidth),d=e.height*(h/e.naturalHeight);e.left-=(r-e.width)/2,e.top-=(d-e.height)/2,e.width=r,e.height=d,e.aspectRatio=o/h,e.naturalWidth=o,e.naturalHeight=h,this.limitCanvas(!0,!1)}(e.width>e.maxWidth||e.widthe.maxHeight||e.heighti.width?n.height=n.width/e:n.width=n.height*e),this.cropBoxData=n,this.limitCropBox(!0,!0),n.width=Math.min(Math.max(n.width,n.minWidth),n.maxWidth),n.height=Math.min(Math.max(n.height,n.minHeight),n.maxHeight),n.width=Math.max(n.minWidth,n.width*a),n.height=Math.max(n.minHeight,n.height*a),n.left=i.left+(i.width-n.width)/2,n.top=i.top+(i.height-n.height)/2,n.oldLeft=n.left,n.oldTop=n.top,this.initialCropBoxData=yt({},n)},limitCropBox:function(t,i){var e=this.options,a=this.containerData,n=this.canvasData,o=this.cropBoxData,h=this.limited,r=e.aspectRatio;if(t){var s=Number(e.minCropBoxWidth)||0,d=Number(e.minCropBoxHeight)||0,c=Math.min(a.width,h?n.width:a.width),l=Math.min(a.height,h?n.height:a.height);s=Math.min(s,a.width),d=Math.min(d,a.height),r&&(s&&d?d*r>s?d=s/r:s=d*r:s?d=s/r:d&&(s=d*r),l*r>c?l=c/r:c=l*r),o.minWidth=Math.min(s,c),o.minHeight=Math.min(d,l),o.maxWidth=c,o.maxHeight=l}i&&(h?(o.minLeft=Math.max(0,n.left),o.minTop=Math.max(0,n.top),o.maxLeft=Math.min(a.width,n.left+n.width)-o.width,o.maxTop=Math.min(a.height,n.top+n.height)-o.height):(o.minLeft=0,o.minTop=0,o.maxLeft=a.width-o.width,o.maxTop=a.height-o.height))},renderCropBox:function(){var t=this.options,i=this.containerData,e=this.cropBoxData;(e.width>e.maxWidth||e.widthe.maxHeight||e.height=i.width&&e.height>=i.height?N:W),s(this.cropBox,yt({width:e.width,height:e.height},M({translateX:e.left,translateY:e.top}))),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),w(this.element,G,this.getData())}},zt={initPreview:function(){var t=this.crossOrigin,i=this.options.preview,e=t?this.crossOriginUrl:this.url,a=document.createElement("img");if(t&&(a.crossOrigin=t),a.src=e,this.viewBox.appendChild(a),this.viewBoxImage=a,i){var n=i;"string"==typeof i?n=this.element.ownerDocument.querySelectorAll(i):i.querySelector&&(n=[i]),this.previews=n,h(n,function(i){var a=document.createElement("img");u(i,F,{width:i.offsetWidth,height:i.offsetHeight,html:i.innerHTML}),t&&(a.crossOrigin=t),a.src=e,a.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;"',i.innerHTML="",i.appendChild(a)})}},resetPreview:function(){h(this.previews,function(t){var i=m(t,F);s(t,{width:i.width,height:i.height}),t.innerHTML=i.html,g(t,F)})},preview:function(){var t=this.imageData,i=this.canvasData,e=this.cropBoxData,a=e.width,n=e.height,o=t.width,r=t.height,d=e.left-i.left-t.left,c=e.top-i.top-t.top;this.cropped&&!this.disabled&&(s(this.viewBoxImage,yt({width:o,height:r},M(yt({translateX:-d,translateY:-c},t)))),h(this.previews,function(i){var e=m(i,F),h=e.width,l=e.height,p=h,u=l,g=1;a&&(u=n*(g=h/a)),n&&u>l&&(p=a*(g=l/n),u=l),s(i,{width:p,height:u}),s(i.getElementsByTagName("img")[0],yt({width:o*g,height:r*g},M(yt({translateX:-d*g,translateY:-c*g},t))))}))}},Lt={bind:function(){var t=this.element,i=this.options,e=this.cropper;o(i.cropstart)&&v(t,tt,i.cropstart),o(i.cropmove)&&v(t,_,i.cropmove),o(i.cropend)&&v(t,J,i.cropend),o(i.crop)&&v(t,G,i.crop),o(i.zoom)&&v(t,dt,i.zoom),v(e,at,this.onCropStart=this.cropStart.bind(this)),i.zoomable&&i.zoomOnWheel&&v(e,st,this.onWheel=this.wheel.bind(this)),i.toggleDragModeOnDblclick&&v(e,it,this.onDblclick=this.dblclick.bind(this)),v(t.ownerDocument,nt,this.onCropMove=this.cropMove.bind(this)),v(t.ownerDocument,ot,this.onCropEnd=this.cropEnd.bind(this)),i.responsive&&v(window,rt,this.onResize=this.resize.bind(this))},unbind:function(){var t=this.element,i=this.options,e=this.cropper;o(i.cropstart)&&f(t,tt,i.cropstart),o(i.cropmove)&&f(t,_,i.cropmove),o(i.cropend)&&f(t,J,i.cropend),o(i.crop)&&f(t,G,i.crop),o(i.zoom)&&f(t,dt,i.zoom),f(e,at,this.onCropStart),i.zoomable&&i.zoomOnWheel&&f(e,st,this.onWheel),i.toggleDragModeOnDblclick&&f(e,it,this.onDblclick),f(t.ownerDocument,nt,this.onCropMove),f(t.ownerDocument,ot,this.onCropEnd),i.responsive&&f(window,rt,this.onResize)}},Yt={resize:function(){var t=this.options,i=this.container,e=this.containerData,a=Number(t.minContainerWidth)||200,n=Number(t.minContainerHeight)||100;if(!(this.disabled||e.width<=a||e.height<=n)){var o=i.offsetWidth/e.width;if(1!==o||i.offsetHeight!==e.height){var r=void 0,s=void 0;t.restore&&(r=this.getCanvasData(),s=this.getCropBoxData()),this.render(),t.restore&&(this.setCanvasData(h(r,function(t,i){r[i]=t*o})),this.setCropBoxData(h(s,function(t,i){s[i]=t*o})))}}},dblclick:function(){var t,i;this.disabled||this.options.dragMode===V||this.setDragMode((t=this.dragBox,i=I,(t.classList?t.classList.contains(i):t.className.indexOf(i)>-1)?K:Z))},wheel:function(t){var i=this,e=Number(this.options.wheelZoomRatio)||.1,a=1;this.disabled||(t.preventDefault(),this.wheeling||(this.wheeling=!0,setTimeout(function(){i.wheeling=!1},50),t.deltaY?a=t.deltaY>0?1:-1:t.wheelDelta?a=-t.wheelDelta/120:t.detail&&(a=t.detail>0?1:-1),this.zoom(-a*e,t)))},cropStart:function(t){if(!this.disabled){var i=this.options,e=this.pointers,a=void 0;t.changedTouches?h(t.changedTouches,function(t){e[t.identifier]=C(t)}):e[t.pointerId||0]=C(t),a=Object.keys(e).length>1&&i.zoomable&&i.zoomOnTouch?E:m(t.target,Q),ct.test(a)&&!1!==w(this.element,tt,{originalEvent:t,action:a})&&(t.preventDefault(),this.action=a,this.cropping=!1,a===H&&(this.cropping=!0,d(this.dragBox,q)))}},cropMove:function(t){var i=this.action;if(!this.disabled&&i){var e=this.pointers;t.preventDefault(),!1!==w(this.element,_,{originalEvent:t,action:i})&&(t.changedTouches?h(t.changedTouches,function(t){yt(e[t.identifier],C(t,!0))}):yt(e[t.pointerId||0],C(t,!0)),this.change(t))}},cropEnd:function(t){if(!this.disabled){var i=this.action,e=this.pointers;t.changedTouches?h(t.changedTouches,function(t){delete e[t.identifier]}):delete e[t.pointerId||0],i&&(t.preventDefault(),Object.keys(e).length||(this.action=""),this.cropping&&(this.cropping=!1,l(this.dragBox,q,this.cropped&&this.options.modal)),w(this.element,J,{originalEvent:t,action:i}))}}},Ot={change:function(t){var i=this.options,e=this.canvasData,a=this.containerData,n=this.cropBoxData,o=this.pointers,r=this.action,s=i.aspectRatio,d=n.left,l=n.top,p=n.width,m=n.height,u=d+p,g=l+m,f=0,v=0,w=a.width,b=a.height,y=!0,M=void 0;!s&&t.shiftKey&&(s=p&&m?p/m:1),this.limited&&(f=n.minLeft,v=n.minTop,w=f+Math.min(a.width,e.width,e.left+e.width),b=v+Math.min(a.height,e.height,e.top+e.height));var C,D,B,k=o[Object.keys(o)[0]],T={x:k.endX-k.startX,y:k.endY-k.startY},I=function(t){switch(t){case z:u+T.x>w&&(T.x=w-u);break;case L:d+T.xb&&(T.y=b-g)}};switch(r){case W:d+=T.x,l+=T.y;break;case z:if(T.x>=0&&(u>=w||s&&(l<=v||g>=b))){y=!1;break}I(z),p+=T.x,s&&(m=p/s,l-=T.x/s/2),p<0&&(r=L,p=0);break;case O:if(T.y<=0&&(l<=v||s&&(d<=f||u>=w))){y=!1;break}I(O),m-=T.y,l+=T.y,s&&(p=m*s,d+=T.y*s/2),m<0&&(r=Y,m=0);break;case L:if(T.x<=0&&(d<=f||s&&(l<=v||g>=b))){y=!1;break}I(L),p-=T.x,d+=T.x,s&&(m=p/s,l+=T.x/s/2),p<0&&(r=z,p=0);break;case Y:if(T.y>=0&&(g>=b||s&&(d<=f||u>=w))){y=!1;break}I(Y),m+=T.y,s&&(p=m*s,d-=T.y*s/2),m<0&&(r=O,m=0);break;case X:if(s){if(T.y<=0&&(l<=v||u>=w)){y=!1;break}I(O),m-=T.y,l+=T.y,p=m*s}else I(O),I(z),T.x>=0?uv&&(m-=T.y,l+=T.y):(m-=T.y,l+=T.y);p<0&&m<0?(r=A,m=0,p=0):p<0?(r=R,p=0):m<0&&(r=S,m=0);break;case R:if(s){if(T.y<=0&&(l<=v||d<=f)){y=!1;break}I(O),m-=T.y,l+=T.y,p=m*s,d+=T.y*s}else I(O),I(L),T.x<=0?d>f?(p-=T.x,d+=T.x):T.y<=0&&l<=v&&(y=!1):(p-=T.x,d+=T.x),T.y<=0?l>v&&(m-=T.y,l+=T.y):(m-=T.y,l+=T.y);p<0&&m<0?(r=S,m=0,p=0):p<0?(r=X,p=0):m<0&&(r=A,m=0);break;case A:if(s){if(T.x<=0&&(d<=f||g>=b)){y=!1;break}I(L),p-=T.x,d+=T.x,m=p/s}else I(Y),I(L),T.x<=0?d>f?(p-=T.x,d+=T.x):T.y>=0&&g>=b&&(y=!1):(p-=T.x,d+=T.x),T.y>=0?g=0&&(u>=w||g>=b)){y=!1;break}I(z),m=(p+=T.x)/s}else I(Y),I(z),T.x>=0?u=0&&g>=b&&(y=!1):p+=T.x,T.y>=0?g0?r=T.y>0?S:X:T.x<0&&(d-=p,r=T.y>0?A:R),T.y<0&&(l-=m),this.cropped||(c(this.cropBox,j),this.cropped=!0,this.limited&&this.limitCropBox(!0,!0))}y&&(n.width=p,n.height=m,n.left=d,n.top=l,this.action=r,this.renderCropBox()),h(o,function(t){t.startX=t.endX,t.startY=t.endY})}},Xt={crop:function(){return!this.ready||this.cropped||this.disabled||(this.cropped=!0,this.limitCropBox(!0,!0),this.options.modal&&d(this.dragBox,q),c(this.cropBox,j),this.setCropBoxData(this.initialCropBoxData)),this},reset:function(){return this.ready&&!this.disabled&&(this.imageData=yt({},this.initialImageData),this.canvasData=yt({},this.initialCanvasData),this.cropBoxData=yt({},this.initialCropBoxData),this.renderCanvas(),this.cropped&&this.renderCropBox()),this},clear:function(){return this.cropped&&!this.disabled&&(yt(this.cropBoxData,{left:0,top:0,width:0,height:0}),this.cropped=!1,this.renderCropBox(),this.limitCanvas(!0,!0),this.renderCanvas(),c(this.dragBox,q),d(this.cropBox,j)),this},replace:function(t){var i=arguments.length>1&&void 0!==arguments[1]&&arguments[1];return!this.disabled&&t&&(this.isImg&&(this.element.src=t),i?(this.url=t,this.image.src=t,this.ready&&(this.viewBoxImage.src=t,h(this.previews,function(i){i.getElementsByTagName("img")[0].src=t}))):(this.isImg&&(this.replaced=!0),this.options.data=null,this.uncreate(),this.load(t))),this},enable:function(){return this.ready&&this.disabled&&(this.disabled=!1,c(this.cropper,U)),this},disable:function(){return this.ready&&!this.disabled&&(this.disabled=!0,d(this.cropper,U)),this},destroy:function(){var t=this.element;return m(t,T)?(this.isImg&&this.replaced&&(t.src=this.originalUrl),this.uncreate(),g(t,T),this):this},move:function(t){var i=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,a=this.canvasData,n=a.left,o=a.top;return this.moveTo(e(t)?t:n+Number(t),e(i)?i:o+Number(i))},moveTo:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,a=this.canvasData,n=!1;return t=Number(t),e=Number(e),this.ready&&!this.disabled&&this.options.movable&&(i(t)&&(a.left=t,n=!0),i(e)&&(a.top=e,n=!0),n&&this.renderCanvas(!0)),this},zoom:function(t,i){var e=this.canvasData;return t=(t=Number(t))<0?1/(1-t):1+t,this.zoomTo(e.width*t/e.naturalWidth,null,i)},zoomTo:function(t,e,a){var o,r,s,d=this.options,c=this.canvasData,l=c.width,p=c.height,m=c.naturalWidth,u=c.naturalHeight;if((t=Number(t))>=0&&this.ready&&!this.disabled&&d.zoomable){var g=m*t,f=u*t;if(!1===w(this.element,dt,{originalEvent:a,oldRatio:l/m,ratio:g/m}))return this;if(a){var v=this.pointers,b=x(this.cropper),y=v&&Object.keys(v).length?(o=0,r=0,s=0,h(v,function(t){var i=t.startX,e=t.startY;o+=i,r+=e,s+=1}),{pageX:o/=s,pageY:r/=s}):{pageX:a.pageX,pageY:a.pageY};c.left-=(g-l)*((y.pageX-b.left-c.left)/l),c.top-=(f-p)*((y.pageY-b.top-c.top)/p)}else n(e)&&i(e.x)&&i(e.y)?(c.left-=(g-l)*((e.x-c.left)/l),c.top-=(f-p)*((e.y-c.top)/p)):(c.left-=(g-l)/2,c.top-=(f-p)/2);c.width=g,c.height=f,this.renderCanvas(!0)}return this},rotate:function(t){return this.rotateTo((this.imageData.rotate||0)+Number(t))},rotateTo:function(t){return i(t=Number(t))&&this.ready&&!this.disabled&&this.options.rotatable&&(this.imageData.rotate=t%360,this.renderCanvas(!0,!0)),this},scaleX:function(t){var e=this.imageData.scaleY;return this.scale(t,i(e)?e:1)},scaleY:function(t){var e=this.imageData.scaleX;return this.scale(i(e)?e:1,t)},scale:function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:t,a=this.imageData,n=!1;return t=Number(t),e=Number(e),this.ready&&!this.disabled&&this.options.scalable&&(i(t)&&(a.scaleX=t,n=!0),i(e)&&(a.scaleY=e,n=!0),n&&this.renderCanvas(!0,!0)),this},getData:function(){var t=arguments.length>0&&void 0!==arguments[0]&&arguments[0],i=this.options,e=this.imageData,a=this.canvasData,n=this.cropBoxData,o=void 0;if(this.ready&&this.cropped){o={x:n.left-a.left,y:n.top-a.top,width:n.width,height:n.height};var r=e.width/e.naturalWidth;h(o,function(i,e){i/=r,o[e]=t?Math.round(i):i})}else o={x:0,y:0,width:0,height:0};return i.rotatable&&(o.rotate=e.rotate||0),i.scalable&&(o.scaleX=e.scaleX||1,o.scaleY=e.scaleY||1),o},setData:function(t){var e=this.options,a=this.imageData,o=this.canvasData,h={};if(this.ready&&!this.disabled&&n(t)){var r=!1;e.rotatable&&i(t.rotate)&&t.rotate!==a.rotate&&(a.rotate=t.rotate,r=!0),e.scalable&&(i(t.scaleX)&&t.scaleX!==a.scaleX&&(a.scaleX=t.scaleX,r=!0),i(t.scaleY)&&t.scaleY!==a.scaleY&&(a.scaleY=t.scaleY,r=!0)),r&&this.renderCanvas(!0,!0);var s=a.width/a.naturalWidth;i(t.x)&&(h.left=t.x*s+o.left),i(t.y)&&(h.top=t.y*s+o.top),i(t.width)&&(h.width=t.width*s),i(t.height)&&(h.height=t.height*s),this.setCropBoxData(h)}return this},getContainerData:function(){return this.ready?yt({},this.containerData):{}},getImageData:function(){return this.sized?yt({},this.imageData):{}},getCanvasData:function(){var t=this.canvasData,i={};return this.ready&&h(["left","top","width","height","naturalWidth","naturalHeight"],function(e){i[e]=t[e]}),i},setCanvasData:function(t){var e=this.canvasData,a=e.aspectRatio;return this.ready&&!this.disabled&&n(t)&&(i(t.left)&&(e.left=t.left),i(t.top)&&(e.top=t.top),i(t.width)?(e.width=t.width,e.height=t.width/a):i(t.height)&&(e.height=t.height,e.width=t.height*a),this.renderCanvas(!0)),this},getCropBoxData:function(){var t=this.cropBoxData,i=void 0;return this.ready&&this.cropped&&(i={left:t.left,top:t.top,width:t.width,height:t.height}),i||{}},setCropBoxData:function(t){var e=this.cropBoxData,a=this.options.aspectRatio,o=void 0,h=void 0;return this.ready&&this.cropped&&!this.disabled&&n(t)&&(i(t.left)&&(e.left=t.left),i(t.top)&&(e.top=t.top),i(t.width)&&t.width!==e.width&&(o=!0,e.width=t.width),i(t.height)&&t.height!==e.height&&(h=!0,e.height=t.height),a&&(o?e.height=e.width/a:h&&(e.width=e.height*a)),this.renderCropBox()),this},getCroppedCanvas:function(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};if(!this.ready||!window.HTMLCanvasElement)return null;var i,e,a,n,o,h,s,d,c,l,p,m,u,g,f,v,w,x,b,y,M,C,B,k,T,W,H,N,E,z,L,Y,O,X,R,S,A,I,U=this.canvasData,j=(i=this.image,e=this.imageData,a=U,n=t,o=e.naturalWidth,h=e.naturalHeight,s=e.rotate,d=void 0===s?0:s,c=e.scaleX,l=void 0===c?1:c,p=e.scaleY,m=void 0===p?1:p,u=a.aspectRatio,g=a.naturalWidth,f=a.naturalHeight,v=n.fillColor,w=void 0===v?"transparent":v,x=n.imageSmoothingEnabled,b=void 0===x||x,y=n.imageSmoothingQuality,M=void 0===y?"low":y,C=n.maxWidth,B=void 0===C?1/0:C,k=n.maxHeight,T=void 0===k?1/0:k,W=n.minWidth,H=void 0===W?0:W,N=n.minHeight,E=void 0===N?0:N,z=document.createElement("canvas"),L=z.getContext("2d"),Y=D({aspectRatio:u,width:B,height:T}),O=D({aspectRatio:u,width:H,height:E},"cover"),X=Math.min(Y.width,Math.max(O.width,g)),R=Math.min(Y.height,Math.max(O.height,f)),S=Math.min(Y.width,Math.max(O.width,o)),A=Math.min(Y.height,Math.max(O.height,h)),I=[-S/2,-A/2,S,A],z.width=r(X),z.height=r(R),L.fillStyle=w,L.fillRect(0,0,X,R),L.save(),L.translate(X/2,R/2),L.rotate(d*Math.PI/180),L.scale(l,m),L.imageSmoothingEnabled=b,L.imageSmoothingQuality=M,L.drawImage.apply(L,[i].concat(wt(I.map(function(t){return Math.floor(r(t))})))),L.restore(),z);if(!this.cropped)return j;var P=this.getData(),q=P.x,$=P.y,Q=P.width,F=P.height,Z=j.width/Math.floor(U.naturalWidth);1!==Z&&(q*=Z,$*=Z,Q*=Z,F*=Z);var K=Q/F,V=D({aspectRatio:K,width:t.maxWidth||1/0,height:t.maxHeight||1/0}),G=D({aspectRatio:K,width:t.minWidth||0,height:t.minHeight||0},"cover"),J=D({aspectRatio:K,width:t.width||(1!==Z?j.width:Q),height:t.height||(1!==Z?j.height:F)}),_=J.width,tt=J.height;_=Math.min(V.width,Math.max(G.width,_)),tt=Math.min(V.height,Math.max(G.height,tt));var it=document.createElement("canvas"),et=it.getContext("2d");it.width=r(_),it.height=r(tt),et.fillStyle=t.fillColor||"transparent",et.fillRect(0,0,_,tt);var at=t.imageSmoothingEnabled,nt=void 0===at||at,ot=t.imageSmoothingQuality;et.imageSmoothingEnabled=nt,ot&&(et.imageSmoothingQuality=ot);var ht=j.width,rt=j.height,st=q,dt=$,ct=void 0,lt=void 0,pt=void 0,mt=void 0,ut=void 0,gt=void 0;st<=-Q||st>ht?(st=0,ct=0,pt=0,ut=0):st<=0?(pt=-st,st=0,ut=ct=Math.min(ht,Q+st)):st<=ht&&(pt=0,ut=ct=Math.min(Q,ht-st)),ct<=0||dt<=-F||dt>rt?(dt=0,lt=0,mt=0,gt=0):dt<=0?(mt=-dt,dt=0,gt=lt=Math.min(rt,F+dt)):dt<=rt&&(mt=0,gt=lt=Math.min(F,rt-dt));var ft=[st,dt,ct,lt];if(ut>0&>>0){var vt=_/Q;ft.push(pt*vt,mt*vt,ut*vt,gt*vt)}return et.drawImage.apply(et,[j].concat(wt(ft.map(function(t){return Math.floor(r(t))})))),it},setAspectRatio:function(t){var i=this.options;return this.disabled||e(t)||(i.aspectRatio=Math.max(0,t)||NaN,this.ready&&(this.initCropBox(),this.cropped&&this.renderCropBox())),this},setDragMode:function(t){var i=this.options,e=this.dragBox,a=this.face;if(this.ready&&!this.disabled){var n=t===Z,o=i.movable&&t===K;t=n||o?t:V,i.dragMode=t,u(e,Q,t),l(e,I,n),l(e,$,o),i.cropBoxMovable||(u(a,Q,t),l(a,I,n),l(a,$,o))}return this}},Rt=k.Cropper,St=function(){function t(i){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(ft(this,t),!i||!mt.test(i.tagName))throw new Error("The first argument is required and must be an or element.");this.element=i,this.options=yt({},ut,n(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 vt(t,[{key:"init",value:function(){var t=this.element,i=t.tagName.toLowerCase(),e=void 0;if(!m(t,T)){if(u(t,T,this),"img"===i){if(this.isImg=!0,e=t.getAttribute("src")||"",this.originalUrl=e,!e)return;e=t.src}else"canvas"===i&&window.HTMLCanvasElement&&(e=t.toDataURL());this.load(e)}}},{key:"load",value:function(t){var i=this;if(t){this.url=t,this.imageData={};var e=this.element,a=this.options;if(a.checkOrientation&&window.ArrayBuffer)if(lt.test(t))pt.test(t)?this.read((n=t.replace(Nt,""),o=atob(n),r=new ArrayBuffer(o.length),h(s=new Uint8Array(r),function(t,i){s[i]=o.charCodeAt(i)}),r)):this.clone();else{var n,o,r,s,d=new XMLHttpRequest;this.reloading=!0,this.xhr=d;var c=function(){i.reloading=!1,i.xhr=null};d.ontimeout=c,d.onabort=c,d.onerror=function(){c(),i.clone()},d.onload=function(){c(),i.read(d.response)},a.checkCrossOrigin&&b(t)&&e.crossOrigin&&(t=y(t)),d.open("get",t),d.responseType="arraybuffer",d.withCredentials="use-credentials"===e.crossOrigin,d.send()}else this.clone()}}},{key:"read",value:function(t){var i,e,a,n=this.options,o=this.imageData,r=B(t),s=0,d=1,c=1;if(r>1){this.url=(i="image/jpeg",e=new Uint8Array(t),a="",h(e,function(t){a+=Ht(t)}),"data:"+i+";base64,"+btoa(a));var l=function(t){var i=0,e=1,a=1;switch(r){case 2:e=-1;break;case 3:i=-180;break;case 4:a=-1;break;case 5:i=90,a=-1;break;case 6:i=90;break;case 7:i=90,e=-1;break;case 8:i=-90}return{rotate:i,scaleX:e,scaleY:a}}();s=l.rotate,d=l.scaleX,c=l.scaleY}n.rotatable&&(o.rotate=s),n.scalable&&(o.scaleX=d,o.scaleY=c),this.clone()}},{key:"clone",value:function(){var t=this.element,i=this.url,e=void 0,a=void 0;this.options.checkCrossOrigin&&b(i)&&((e=t.crossOrigin)?a=i:(e="anonymous",a=y(i))),this.crossOrigin=e,this.crossOriginUrl=a;var n=document.createElement("img");e&&(n.crossOrigin=e),n.src=a||i;var o=this.start.bind(this),h=this.stop.bind(this);this.image=n,this.onStart=o,this.onStop=h,this.isImg?t.complete?this.timeout=setTimeout(o,0):v(t,et,o,{once:!0}):(n.onload=o,n.onerror=h,d(n,P),t.parentNode.insertBefore(n,t.nextSibling))}},{key:"start",value:function(t){var i=this,e=this.isImg?this.element:this.image;t&&(e.onload=null,e.onerror=null),this.sizing=!0;var a=k.navigator&&/(Macintosh|iPhone|iPod|iPad).*AppleWebKit/i.test(k.navigator.userAgent),n=function(t,e){yt(i.imageData,{naturalWidth:t,naturalHeight:e,aspectRatio:t/e}),i.sizing=!1,i.sized=!0,i.build()};if(!e.naturalWidth||a){var o=document.createElement("img"),h=document.body||document.documentElement;this.sizingImage=o,o.onload=function(){n(o.width,o.height),a||h.removeChild(o)},o.src=e.src,a||(o.style.cssText="left:0;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;opacity:0;position:absolute;top:0;z-index:-1;",h.appendChild(o))}else n(e.naturalWidth,e.naturalHeight)}},{key:"stop",value:function(){var t=this.image;t.onload=null,t.onerror=null,t.parentNode.removeChild(t),this.image=null}},{key:"build",value:function(){if(this.sized&&!this.ready){var t=this.element,i=this.options,e=this.image,a=t.parentNode,n=document.createElement("div");n.innerHTML='
';var h=n.querySelector("."+T+"-container"),r=h.querySelector("."+T+"-canvas"),s=h.querySelector("."+T+"-drag-box"),l=h.querySelector("."+T+"-crop-box"),p=l.querySelector("."+T+"-face");this.container=a,this.cropper=h,this.canvas=r,this.dragBox=s,this.cropBox=l,this.viewBox=h.querySelector("."+T+"-view-box"),this.face=p,r.appendChild(e),d(t,j),a.insertBefore(h,t.nextSibling),this.isImg||c(e,P),this.initPreview(),this.bind(),i.aspectRatio=Math.max(0,i.aspectRatio)||NaN,i.viewMode=Math.max(0,Math.min(3,Math.round(i.viewMode)))||0,d(l,j),i.guides||d(l.getElementsByClassName(T+"-dashed"),j),i.center||d(l.getElementsByClassName(T+"-center"),j),i.background&&d(h,T+"-bg"),i.highlight||d(p,"cropper-invisible"),i.cropBoxMovable&&(d(p,$),u(p,Q,W)),i.cropBoxResizable||(d(l.getElementsByClassName(T+"-line"),j),d(l.getElementsByClassName(T+"-point"),j)),this.render(),this.ready=!0,this.setDragMode(i.dragMode),i.autoCrop&&this.crop(),this.setData(i.data),o(i.ready)&&v(t,ht,i.ready,{once:!0}),w(t,ht)}}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),c(this.element,j))}},{key:"uncreate",value:function(){var t=this.element;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.abort():this.isImg?t.complete?clearTimeout(this.timeout):f(t,et,this.onStart):this.image&&this.stop()}}],[{key:"noConflict",value:function(){return window.Cropper=Rt,t}},{key:"setDefaults",value:function(t){yt(ut,n(t)&&t)}}]),t}();if(yt(St.prototype,Et,zt,Lt,Yt,Ot,Xt),t.fn){var At=t.fn.cropper,It="cropper";t.fn.cropper=function(i){for(var e=arguments.length,a=Array(e>1?e-1:0),n=1;n