/*! * Cropper.js v1.3.3 * https://github.com/fengyuanchen/cropperjs * * Copyright (c) 2015-2018 Chen Fengyuan * Released under the MIT license * * Date: 2018-03-18T03:19:54.147Z */ !function(t,i){"object"==typeof exports&&"undefined"!=typeof module?module.exports=i():"function"==typeof define&&define.amd?define(i):t.Cropper=i()}(this,function(){"use strict";var n="undefined"!=typeof window,r=n?window:{},c="cropper",k="all",T="crop",W="move",E="zoom",H="e",N="w",L="s",z="n",O="ne",Y="nw",X="se",R="sw",h=c+"-crop",t=c+"-disabled",S=c+"-hidden",l=c+"-hide",o=c+"-modal",p=c+"-move",m="action",u="preview",s="crop",d="move",g="none",a="crop",f="cropend",v="cropmove",w="cropstart",b="dblclick",x="load",y=r.PointerEvent?"pointerdown":"touchstart mousedown",M=r.PointerEvent?"pointermove":"touchmove mousemove",C=r.PointerEvent?"pointerup pointercancel":"touchend touchcancel mouseup",D="ready",B="resize",I="wheel mousewheel DOMMouseScroll",A="zoom",U=/^(?:e|w|s|n|se|sw|ne|nw|all|crop|move|zoom)$/,j=/^data:/,P=/^data:image\/jpeg;base64,/,q=/^(?:img|canvas)$/i,$={viewMode:0,dragMode:s,aspectRatio:NaN,data:null,preview:"",responsive:!0,restore:!0,checkCrossOrigin:!0,checkOrientation:!0,modal:!0,guides:!0,center:!0,highlight:!0,background:!0,autoCrop:!0,autoCropArea:.8,movable:!0,rotatable:!0,scalable:!0,zoomable:!0,zoomOnTouch:!0,zoomOnWheel:!0,wheelZoomRatio:.1,cropBoxMovable:!0,cropBoxResizable:!0,toggleDragModeOnDblclick:!0,minCanvasWidth:0,minCanvasHeight:0,minCropBoxWidth:0,minCropBoxHeight:0,minContainerWidth:200,minContainerHeight:100,ready:null,cropstart:null,cropmove:null,cropend:null,crop:null,zoom:null},i="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},Q=function(t,i){if(!(t instanceof i))throw new TypeError("Cannot call a class as a function")},Z=function(){function a(t,i){for(var e=0;et.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=it({},i),this.initialCanvasData=it({},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;1=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 90e.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=it({},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?se.maxWidth||e.widthe.maxHeight||e.height=i.width&&e.height>=i.height?W:k),nt(this.cropBox,it({width:e.width,height:e.height},Bt({translateX:e.left,translateY:e.top}))),this.cropped&&this.limited&&this.limitCanvas(!0,!0),this.disabled||this.output()},output:function(){this.preview(),bt(this.element,a,this.getData())}},zt={initPreview:function(){var e=this.crossOrigin,t=this.options.preview,a=e?this.crossOriginUrl:this.url,i=document.createElement("img");if(e&&(i.crossOrigin=e),i.src=a,this.viewBox.appendChild(i),this.viewBoxImage=i,t){var n=t;"string"==typeof t?n=this.element.ownerDocument.querySelectorAll(t):t.querySelector&&(n=[t]),tt(this.previews=n,function(t){var i=document.createElement("img");lt(t,u,{width:t.offsetWidth,height:t.offsetHeight,html:t.innerHTML}),e&&(i.crossOrigin=e),i.src=a,i.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(i)})}},resetPreview:function(){tt(this.previews,function(t){var i=ct(t,u);nt(t,{width:i.width,height:i.height}),t.innerHTML=i.html,pt(t,u)})},preview:function(){var r=this.imageData,t=this.canvasData,i=this.cropBoxData,s=i.width,d=i.height,c=r.width,l=r.height,p=i.left-t.left-r.left,m=i.top-t.top-r.top;this.cropped&&!this.disabled&&(nt(this.viewBoxImage,it({width:c,height:l},Bt(it({translateX:-p,translateY:-m},r)))),tt(this.previews,function(t){var i=ct(t,u),e=i.width,a=i.height,n=e,o=a,h=1;s&&(o=d*(h=e/s)),d&&af&&(D.x=f-p);break;case N:s+D.xv&&(D.y=v-m)}};switch(h){case k:s+=D.x,d+=D.y;break;case H:if(0<=D.x&&(f<=p||r&&(d<=g||v<=m))){w=!1;break}B(H),c+=D.x,r&&(l=c/r,d-=D.x/r/2),c<0&&(h=N,c=0);break;case z:if(D.y<=0&&(d<=g||r&&(s<=u||f<=p))){w=!1;break}B(z),l-=D.y,d+=D.y,r&&(c=l*r,s+=D.y*r/2),l<0&&(h=L,l=0);break;case N:if(D.x<=0&&(s<=u||r&&(d<=g||v<=m))){w=!1;break}B(N),c-=D.x,s+=D.x,r&&(l=c/r,d+=D.x/r/2),c<0&&(h=H,c=0);break;case L:if(0<=D.y&&(v<=m||r&&(s<=u||f<=p))){w=!1;break}B(L),l+=D.y,r&&(c=l*r,s-=D.y*r/2),l<0&&(h=z,l=0);break;case O:if(r){if(D.y<=0&&(d<=g||f<=p)){w=!1;break}B(z),l-=D.y,d+=D.y,c=l*r}else B(z),B(H),0<=D.x?p or element.");this.element=t,this.options=it({},$,J(i)&&i),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 Z(e,[{key:"init",value:function(){var t=this.element,i=t.tagName.toLowerCase(),e=void 0;if(!ct(t,c)){if(lt(t,c,this),"img"===i){if(this.isImg=!0,e=t.getAttribute("src")||"",!(this.originalUrl=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(j.test(t))P.test(t)?this.read((n=t.replace(Ht,""),o=atob(n),h=new ArrayBuffer(o.length),tt(r=new Uint8Array(h),function(t,i){r[i]=o.charCodeAt(i)}),h)):this.clone();else{var n,o,h,r,s=new XMLHttpRequest;this.reloading=!0,this.xhr=s;var d=function(){i.reloading=!1,i.xhr=null};s.ontimeout=d,s.onabort=d,s.onerror=function(){d(),i.clone()},s.onload=function(){d(),i.read(s.response)},a.checkCrossOrigin&&Ct(t)&&e.crossOrigin&&(t=Dt(t)),s.open("get",t),s.responseType="arraybuffer",s.withCredentials="use-credentials"===e.crossOrigin,s.send()}else this.clone()}}},{key:"read",value:function(t){var i,e,a,n=this.options,o=this.imageData,h=Nt(t),r=0,s=1,d=1;if(1
';var o=n.querySelector("."+c+"-container"),h=o.querySelector("."+c+"-canvas"),r=o.querySelector("."+c+"-drag-box"),s=o.querySelector("."+c+"-crop-box"),d=s.querySelector("."+c+"-face");this.container=a,this.cropper=o,this.canvas=h,this.dragBox=r,this.cropBox=s,this.viewBox=o.querySelector("."+c+"-view-box"),this.face=d,h.appendChild(e),ot(t,S),a.insertBefore(o,t.nextSibling),this.isImg||ht(e,l),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,ot(s,S),i.guides||ot(s.getElementsByClassName(c+"-dashed"),S),i.center||ot(s.getElementsByClassName(c+"-center"),S),i.background&&ot(o,c+"-bg"),i.highlight||ot(d,"cropper-invisible"),i.cropBoxMovable&&(ot(d,p),lt(d,m,k)),i.cropBoxResizable||(ot(s.getElementsByClassName(c+"-line"),S),ot(s.getElementsByClassName(c+"-point"),S)),this.render(),this.ready=!0,this.setDragMode(i.dragMode),i.autoCrop&&this.crop(),this.setData(i.data),_(i.ready)&&wt(t,D,i.ready,{once:!0}),bt(t,D)}}},{key:"unbuild",value:function(){this.ready&&(this.ready=!1,this.unbind(),this.resetPreview(),this.cropper.parentNode.removeChild(this.cropper),ht(this.element,S))}},{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):gt(t,x,this.onStart):this.image&&this.stop()}}],[{key:"noConflict",value:function(){return window.Cropper=St,e}},{key:"setDefaults",value:function(t){it($,J(t)&&t)}}]),e}();return it(It.prototype,Lt,zt,Ot,Yt,Xt,Rt),It});