UNPKG

cropperjs

Version:
3 lines (2 loc) 44.6 kB
/*! Cropper.js v2.2.0 | (c) 2015-present Chen Fengyuan | MIT */ const t="undefined"!=typeof window&&void 0!==window.document,e=t?window:{},i=!!t&&"ontouchstart"in e.document.documentElement,s=!!t&&"PointerEvent"in e,n="cropper",a=`${n}-canvas`,o=`${n}-crosshair`,r=`${n}-grid`,h=`${n}-handle`,c=`${n}-image`,l=`${n}-selection`,d=`${n}-shade`,u=`${n}-viewer`,$="select",p="move",g="scale",m="rotate",b="transform",f="none",v="n-resize",w="e-resize",y="s-resize",C="w-resize",k="ne-resize",S="nw-resize",x="se-resize",A="sw-resize",E="action",z=i?"touchend touchcancel":"mouseup",T=i?"touchmove":"mousemove",M=i?"touchstart":"mousedown",P=s?"pointerdown":M,R=s?"pointermove":T,D=s?"pointerup pointercancel":z,O="error",I="keydown",N="load",W="resize",X="wheel",Y="action",j="actionend",L="actionmove",q="actionstart",B="change",F="transform",H="contain",U="cover",K="fill",Z="none",G="scale-down";function J(t){return"string"==typeof t}const Q=Number.isNaN||e.isNaN;function V(t){return"number"==typeof t&&!Q(t)}function _(t){return V(t)&&t>0&&t<1/0}function tt(t){return void 0===t}function et(t){return"object"==typeof t&&null!==t}const{hasOwnProperty:it}=Object.prototype;function st(t){if(!et(t))return!1;try{const{constructor:e}=t,{prototype:i}=e;return e&&i&&it.call(i,"isPrototypeOf")}catch(t){return!1}}function nt(t){return"function"==typeof t}function at(t){return"object"==typeof t&&null!==t&&1===t.nodeType}const ot=/([a-z\d])([A-Z])/g;function rt(t){return String(t).replace(ot,"$1-$2").toLowerCase()}const ht=/-[A-z\d]/g;function ct(t){return t.replace(ht,(t=>t.slice(1).toUpperCase()))}const lt=/\s\s*/;function dt(t,e,i,s){e.trim().split(lt).forEach((e=>{t.removeEventListener(e,i,s)}))}function ut(t,e,i,s){e.trim().split(lt).forEach((e=>{t.addEventListener(e,i,s)}))}function $t(t,e,i,s){ut(t,e,i,Object.assign(Object.assign({},s),{once:!0}))}const pt={bubbles:!0,cancelable:!0,composed:!0};function gt(t,e,i,s){return t.dispatchEvent(new CustomEvent(e,Object.assign(Object.assign(Object.assign({},pt),{detail:i}),s)))}function mt(t){if("function"==typeof t.composedPath){return t.composedPath().find(at)||t.target}return t.target}const bt=Promise.resolve();function ft(t,e){return e?bt.then(t?e.bind(t):e):bt}function vt(t){const e=t.getRootNode();switch(e.nodeType){case 1:return e.ownerDocument;case 9:case 11:return e}return null}function wt(t){const{documentElement:i}=t.ownerDocument,s=t.getBoundingClientRect();return{left:s.left+(e.pageXOffset-i.clientLeft),top:s.top+(e.pageYOffset-i.clientTop)}}const yt=/deg|g?rad|turn$/i;function Ct(t){const e=parseFloat(t)||0;if(0!==e){const[i="rad"]=String(t).match(yt)||[];switch(i.toLowerCase()){case"deg":return e/360*(2*Math.PI);case"grad":return e/400*(2*Math.PI);case"turn":return e*(2*Math.PI)}}return e}const kt="contain";function St(t,e=kt){const{aspectRatio:i}=t;let{width:s,height:n}=t;const a=_(s),o=_(n);if(a&&o){const t=n*i;e===kt&&t>s||"cover"===e&&t<s?n=s/i:s=n*i}else a?n=s/i:o&&(s=n*i);return{width:s,height:n}}function xt(t,...e){if(0===e.length)return t;const[i,s,n,a,o,r]=t,[h,c,l,d,u,$]=e[0];return xt(t=[i*h+n*c,s*h+a*c,i*l+n*d,s*l+a*d,i*u+n*$+o,s*u+a*$+r],...e.slice(1))}const At=/left|top|width|height/i,Et="open",zt=new WeakMap,Tt=new WeakMap,Mt=new Map,Pt=Boolean(e.document&&Array.isArray(e.document.adoptedStyleSheets)&&e.CSSStyleSheet&&"replaceSync"in e.CSSStyleSheet.prototype);class Rt extends HTMLElement{get $sharedStyle(){return(this.themeColor?`:host{--theme-color: ${this.themeColor};}`:"")+":host([hidden]){display:none!important}"}constructor(){var t,e;super(),this.shadowRootMode=Et,this.slottable=!0;const i=null===(e=null===(t=Object.getPrototypeOf(this))||void 0===t?void 0:t.constructor)||void 0===e?void 0:e.$name;i&&Mt.set(i,this.tagName.toLowerCase())}static get observedAttributes(){return["shadow-root-mode","slottable","theme-color"]}attributeChangedCallback(t,e,i){if(Object.is(i,e))return;const s=ct(t);let n=i;switch(typeof this[s]){case"boolean":n=null!==i&&"false"!==i;break;case"number":n=Number(i)}switch(this[s]=n,t){case"theme-color":{const t=Tt.get(this),e=this.$sharedStyle;t&&e&&(Pt?t.replaceSync(e):t.textContent=e);break}}}$propertyChangedCallback(t,e,i){if(!Object.is(i,e))switch(t=rt(t),typeof i){case"boolean":!0===i?this.hasAttribute(t)||this.setAttribute(t,""):this.removeAttribute(t);break;case"number":i=Q(i)?"":String(i);default:i?this.getAttribute(t)!==i&&this.setAttribute(t,i):this.removeAttribute(t)}}connectedCallback(){Object.getPrototypeOf(this).constructor.observedAttributes.forEach((t=>{const e=ct(t);let i=this[e];tt(i)||this.$propertyChangedCallback(e,void 0,i),Object.defineProperty(this,e,{enumerable:!0,configurable:!0,get:()=>i,set(t){const s=i;i=t,this.$propertyChangedCallback(e,s,t)}})}));const t=this.shadowRoot||this.attachShadow({mode:this.shadowRootMode||Et});if(zt.set(this,t),Tt.set(this,this.$addStyles(this.$sharedStyle)),this.$style&&this.$addStyles(this.$style),this.$template){const e=document.createElement("template");e.innerHTML=this.$template,t.appendChild(e.content)}if(this.slottable){const e=document.createElement("slot");t.appendChild(e)}}disconnectedCallback(){Tt.has(this)&&Tt.delete(this),zt.has(this)&&zt.delete(this)}$getTagNameOf(t){var e;return null!==(e=Mt.get(t))&&void 0!==e?e:t}$setStyles(t){return Object.keys(t).forEach((e=>{let i=t[e];V(i)&&(i=0!==i&&At.test(e)?`${i}px`:String(i)),this.style[e]=i})),this}$getShadowRoot(){return this.shadowRoot||zt.get(this)}$addStyles(t){let e;const i=this.$getShadowRoot();return Pt?(e=new CSSStyleSheet,e.replaceSync(t),i.adoptedStyleSheets=i.adoptedStyleSheets.concat(e)):(e=document.createElement("style"),e.textContent=t,i.appendChild(e)),e}$emit(t,e,i){return gt(this,t,e,i)}$nextTick(t){return ft(this,t)}static $define(i,s){et(i)&&(s=i,i=""),i||(i=this.$name||this.name),i=rt(i),t&&e.customElements&&!e.customElements.get(i)&&customElements.define(i,this,s)}}Rt.$version="2.2.0";class Dt extends Rt{constructor(){super(...arguments),this.$onPointerDown=null,this.$onPointerMove=null,this.$onPointerUp=null,this.$onWheel=null,this.$wheeling=!1,this.$pointers=new Map,this.$style=':host{display:block;min-height:100px;min-width:200px;overflow:hidden;position:relative;touch-action:none;-webkit-touch-callout:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}:host([background]){background-color:#fff;background-image:repeating-linear-gradient(45deg,#ccc 25%,transparent 0,transparent 75%,#ccc 0,#ccc),repeating-linear-gradient(45deg,#ccc 25%,transparent 0,transparent 75%,#ccc 0,#ccc);background-image:repeating-conic-gradient(#ccc 0 25%,#fff 0 50%);background-position:0 0,.5rem .5rem;background-size:1rem 1rem}:host([disabled]){pointer-events:none}:host([disabled]):after{bottom:0;content:"";cursor:not-allowed;display:block;left:0;pointer-events:none;position:absolute;right:0;top:0}',this.$action=f,this.background=!1,this.disabled=!1,this.scaleStep=.1,this.themeColor="#39f"}static get observedAttributes(){return super.observedAttributes.concat(["background","disabled","scale-step"])}connectedCallback(){super.connectedCallback(),this.disabled||this.$bind()}disconnectedCallback(){this.$unbind(),super.disconnectedCallback()}$propertyChangedCallback(t,e,i){if(!Object.is(i,e)&&(super.$propertyChangedCallback(t,e,i),"disabled"===t))i?this.$unbind():this.$bind()}$bind(){this.$onPointerDown||(this.$onPointerDown=this.$handlePointerDown.bind(this),ut(this,P,this.$onPointerDown)),this.$onPointerMove||(this.$onPointerMove=this.$handlePointerMove.bind(this),ut(this.ownerDocument,R,this.$onPointerMove)),this.$onPointerUp||(this.$onPointerUp=this.$handlePointerUp.bind(this),ut(this.ownerDocument,D,this.$onPointerUp)),this.$onWheel||(this.$onWheel=this.$handleWheel.bind(this),ut(this,X,this.$onWheel,{passive:!1,capture:!0}))}$unbind(){this.$onPointerDown&&(dt(this,P,this.$onPointerDown),this.$onPointerDown=null),this.$onPointerMove&&(dt(this.ownerDocument,R,this.$onPointerMove),this.$onPointerMove=null),this.$onPointerUp&&(dt(this.ownerDocument,D,this.$onPointerUp),this.$onPointerUp=null),this.$onWheel&&(dt(this,X,this.$onWheel,{capture:!0}),this.$onWheel=null),this.$pointers.clear(),this.style.willChange="",this.$action=f}$addPointers(t){const{$pointers:e}=this;if(t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:i,pageY:s})=>{e.set(t,{startX:i,startY:s,endX:i,endY:s})}));else{const{pointerId:i=0,pageX:s,pageY:n}=t;e.set(i,{startX:s,startY:n,endX:s,endY:n})}}$removePointers(t){const{$pointers:e}=this;if(t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t})=>{e.delete(t)}));else{const{pointerId:i=0}=t;e.delete(i)}0===e.size&&(this.style.willChange="",this.$action=f)}$handlePointerDown(t){const{buttons:e,button:i,type:s}=t;if(this.disabled||("pointerdown"===s&&"mouse"===t.pointerType||"mousedown"===s)&&(V(e)&&1!==e||V(i)&&0!==i||t.ctrlKey))return;this.$addPointers(t);const{$pointers:n}=this;let a=f;n.size>1?a=b:at(t.target)&&(a=t.target.action||t.target.getAttribute(E)||f),!1!==this.$emit(q,{action:a,relatedEvent:t})?(t.preventDefault(),this.$action=a,this.style.willChange="transform"):this.$removePointers(t)}$handlePointerMove(t){const{$action:e,$pointers:i}=this;if(this.disabled||e===f||0===i.size)return;if(!1===this.$emit(L,{action:e,relatedEvent:t}))return;if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:s})=>{const n=i.get(t);n&&Object.assign(n,{endX:e,endY:s})}));else{const{pointerId:e=0,pageX:s,pageY:n}=t,a=i.get(e);a&&Object.assign(a,{endX:s,endY:n})}const s={action:e,relatedEvent:t};if(e===b){const e=new Map(i);let n=0,a=0,o=0,r=0,h=t.pageX,c=t.pageY;i.forEach(((t,i)=>{e.delete(i),e.forEach((e=>{let i=e.startX-t.startX,s=e.startY-t.startY,l=e.endX-t.endX,d=e.endY-t.endY,u=0,$=0,p=0,g=0;if(0===i?s<0?p=2*Math.PI:s>0&&(p=Math.PI):i>0?p=Math.PI/2+Math.atan(s/i):i<0&&(p=1.5*Math.PI+Math.atan(s/i)),0===l?d<0?g=2*Math.PI:d>0&&(g=Math.PI):l>0?g=Math.PI/2+Math.atan(d/l):l<0&&(g=1.5*Math.PI+Math.atan(d/l)),g>0||p>0){const i=g-p,s=Math.abs(i);s>n&&(n=s,o=i,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}if(i=Math.abs(i),s=Math.abs(s),l=Math.abs(l),d=Math.abs(d),i>0&&s>0?u=Math.sqrt(i*i+s*s):i>0?u=i:s>0&&(u=s),l>0&&d>0?$=Math.sqrt(l*l+d*d):l>0?$=l:d>0&&($=d),u>0&&$>0){const i=($-u)/u,s=Math.abs(i);s>a&&(a=s,r=i,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}}))}));const l=n>0,d=a>0;l&&d?(s.rotate=o,s.scale=r,s.centerX=h,s.centerY=c):l?(s.action=m,s.rotate=o,s.centerX=h,s.centerY=c):d?(s.action=g,s.scale=r,s.centerX=h,s.centerY=c):s.action=f}else{const[t]=Array.from(i.values());Object.assign(s,t)}i.forEach((t=>{t.startX=t.endX,t.startY=t.endY})),s.action!==f&&this.$emit(Y,s)}$handlePointerUp(t){const{$action:e}=this;this.disabled?this.$removePointers(t):e!==f&&!1!==this.$emit(j,{action:e,relatedEvent:t})?(t.preventDefault(),this.$removePointers(t)):this.$removePointers(t)}$handleWheel(t){if(this.disabled)return;if(t.preventDefault(),this.$wheeling)return;this.$wheeling=!0,setTimeout((()=>{this.$wheeling=!1}),50);const e=(t.deltaY>0?-1:1)*this.scaleStep;this.$emit(Y,{action:g,scale:e,relatedEvent:t})}$setAction(t){return J(t)&&(this.$action=t),this}$toCanvas(t){return new Promise(((e,i)=>{if(!this.isConnected)return void i(new Error("The current element is not connected to the DOM."));const s=document.createElement("canvas");let n=this.offsetWidth,a=this.offsetHeight,o=1;st(t)&&(_(t.width)||_(t.height))&&(({width:n,height:a}=St({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.offsetWidth),s.width=n,s.height=a;const r=this.querySelector(this.$getTagNameOf(c));r?r.$ready().then((i=>{const h=s.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform();let p=u,g=$,m=i.naturalWidth,b=i.naturalHeight;1!==o&&(p*=o,g*=o,m*=o,b*=o);const f=m/2,v=b/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),st(t)&&nt(t.beforeDraw)&&t.beforeDraw.call(this,h,s),h.save(),h.translate(f,v),h.transform(e,c,l,d,p,g),h.translate(-f,-v),h.drawImage(i,0,0,m,b),h.restore()}e(s)})).catch(i):e(s)}))}}Dt.$name=a,Dt.$version="2.2.0";const Ot=new WeakMap,It=["alt","crossorigin","decoding","elementtiming","fetchpriority","loading","referrerpolicy","sizes","src","srcset"];class Nt extends Rt{constructor(){super(...arguments),this.$isReady=!1,this.$matrix=[1,0,0,1,0,0],this.$onLoad=null,this.$onCanvasAction=null,this.$onCanvasActionEnd=null,this.$onCanvasActionStart=null,this.$actionStartTarget=null,this.$style=":host{display:inline-block}img{display:block;height:100%;max-height:none!important;max-width:none!important;min-height:0!important;min-width:0!important;width:100%}",this.$image=new Image,this.initialCenterSize="",this.initialFit=H,this.maxFit="",this.minFit="",this.rotatable=!1,this.scalable=!1,this.skewable=!1,this.slottable=!1,this.translatable=!1,this.alt="",this.crossorigin="",this.decoding="",this.elementtiming="",this.fetchpriority="",this.loading="",this.referrerpolicy="",this.sizes="",this.src="",this.srcset=""}set $canvas(t){Ot.set(this,t)}get $canvas(){return Ot.get(this)}static get observedAttributes(){return super.observedAttributes.concat(It,["initial-center-size","initial-fit","max-fit","min-fit","rotatable","scalable","skewable","translatable"])}attributeChangedCallback(t,e,i){Object.is(i,e)||(super.attributeChangedCallback(t,e,i),It.includes(t)&&(null===i?this.$image.removeAttribute(t):this.$image.setAttribute(t,i)))}$propertyChangedCallback(t,e,i){if(!Object.is(i,e))switch(super.$propertyChangedCallback(t,e,i),t){case"initialCenterSize":case"initialFit":this.$nextTick((()=>{this.$isReady&&this.$canvas&&this.$center(i)}));break;case"maxFit":case"minFit":this.$nextTick((()=>{this.$isReady&&this.$canvas&&(this.$resetTransform(),this.$center(this.initialCenterSize||this.initialFit))}));break;case"src":this.$isReady=!1}}connectedCallback(){super.connectedCallback();const{$image:t}=this,e=this.closest(this.$getTagNameOf(a));e&&(this.$canvas=e,this.$setStyles({display:"block",position:"absolute"}),this.$onCanvasActionStart=t=>{var e,i;t.defaultPrevented||(this.$actionStartTarget=null===(i=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===i?void 0:i.target)},this.$onCanvasActionEnd=()=>{this.$actionStartTarget=null},this.$onCanvasAction=this.$handleAction.bind(this),ut(e,q,this.$onCanvasActionStart),ut(e,j,this.$onCanvasActionEnd),ut(e,Y,this.$onCanvasAction)),this.$onLoad=this.$handleLoad.bind(this),ut(t,N,this.$onLoad),this.$getShadowRoot().appendChild(t)}disconnectedCallback(){const{$image:t,$canvas:e}=this;e&&(this.$onCanvasActionStart&&(dt(e,q,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(dt(e,j,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(dt(e,Y,this.$onCanvasAction),this.$onCanvasAction=null)),t&&this.$onLoad&&(dt(t,N,this.$onLoad),this.$onLoad=null),this.$getShadowRoot().removeChild(t),super.disconnectedCallback()}$handleLoad(){const{$image:t}=this;this.$setStyles({width:t.naturalWidth,height:t.naturalHeight}),this.$canvas&&this.$center(this.initialCenterSize||this.initialFit),this.$isReady=!0}$handleAction(t){if(t.defaultPrevented||this.hidden||!(this.rotatable||this.scalable||this.translatable))return;const{$canvas:e}=this,{detail:i}=t;if(i){const{relatedEvent:t}=i;let{action:s}=i;switch(s!==b||this.rotatable&&this.scalable||(s=this.rotatable?m:this.scalable?g:f),s){case p:if(this.translatable){let s=null;t&&(s=t.target.closest(this.$getTagNameOf(l))),s||(s=e.querySelector(this.$getTagNameOf(l))),s&&s.multiple&&!s.active&&(s=e.querySelector(`${this.$getTagNameOf(l)}[active]`)),s&&!s.hidden&&s.movable&&!s.dynamic&&this.$actionStartTarget&&s.contains(this.$actionStartTarget)||this.$move(i.endX-i.startX,i.endY-i.startY)}break;case m:if(this.rotatable)if(t){const{x:e,y:s}=this.getBoundingClientRect();this.$rotate(i.rotate,t.clientX-e,t.clientY-s)}else this.$rotate(i.rotate);break;case g:if(this.scalable)if(t){const e=t.target.closest(this.$getTagNameOf(l));if(!e||!e.zoomable||e.zoomable&&e.dynamic){const{x:e,y:s}=this.getBoundingClientRect();this.$zoom(i.scale,t.clientX-e,t.clientY-s)}}else this.$zoom(i.scale);break;case b:if(this.rotatable&&this.scalable){const{rotate:e}=i;let{scale:s}=i;s<0?s=1/(1-s):s+=1;const n=Math.cos(e),a=Math.sin(e),[o,r,h,c]=[n*s,a*s,-a*s,n*s];if(t){const e=this.getBoundingClientRect(),i=t.clientX-e.x,s=t.clientY-e.y,[n,a,l,d]=this.$matrix,u=i-e.width/2,$=s-e.height/2,p=(u*d-l*$)/(n*d-l*a),g=($*n-a*u)/(n*d-l*a);this.$transform(o,r,h,c,p*(1-o)+g*h,g*(1-c)+p*r)}else this.$transform(o,r,h,c,0,0)}}}}$ready(t){const{$image:e}=this,i=new Promise(((t,i)=>{const s=new Error("Failed to load the image source");if(e.complete)e.naturalWidth>0&&e.naturalHeight>0?t(e):i(s);else{const n=()=>{dt(e,O,a),setTimeout((()=>{t(e)}))},a=()=>{dt(e,N,n),i(s)};$t(e,N,n),$t(e,O,a)}}));return nt(t)&&i.then((e=>(t(e),e))),i}$center(t){const{parentElement:e}=this;if(!e)return this;const i=e.getBoundingClientRect(),s=i.width,n=i.height,{x:a,y:o,width:r,height:h}=this.getBoundingClientRect(),c=a+r/2,l=o+h/2,d=i.x+s/2,u=i.y+n/2,{translatable:$}=this;$||this.$isReady||(this.translatable=!0,this.$nextTick((()=>{this.translatable=$}))),this.$move(d-c,u-l);const{maxFit:p,minFit:g}=this;if(t||p||g){const{naturalWidth:e,naturalHeight:i}=this.$image;switch(t){case U:[K,H,G].includes(p)||p===Z&&(e<s||i<n)?t=p:g===Z&&e>s&&i>n&&(t=g);break;case K:[H,G].includes(p)||p===Z&&(e<s||i<n)?t=p:(g===U||g===Z&&e>s&&i>n)&&(t=g);break;case H:p===G||p===Z&&e<s&&i<n?t=p:([U,K].includes(g)||g===Z&&(e>s||i>n))&&(t=g);break;case G:p===Z&&e<s&&i<n?t=p:([U,K,H].includes(g)||g===Z&&e>s&&i>n)&&(t=g);break;default:[U,K,H,G].includes(p)&&(e>s||i>n)?t=p:[U,K,H,G].includes(g)&&e<s&&i<n&&(t=g)}const a=s/r,o=n/h,{scalable:c}=this;switch(c||this.$isReady||(this.scalable=!0,this.$nextTick((()=>{this.scalable=c}))),t){case U:this.$scale(Math.max(a,o));break;case H:this.$scale(Math.min(a,o));break;case K:this.$scale(a,o);break;case G:this.$scale(Math.min(a,o,1));break;case Z:this.$scale(1)}}return this}$move(t,e=t){if(this.translatable&&V(t)&&V(e)){const[i,s,n,a]=this.$matrix,o=(t*a-n*e)/(i*a-n*s),r=(e*i-s*t)/(i*a-n*s);this.$translate(o,r)}return this}$moveTo(t,e=t){if(this.translatable&&V(t)&&V(e)){const[i,s,n,a]=this.$matrix,o=(t*a-n*e)/(i*a-n*s),r=(e*i-s*t)/(i*a-n*s);this.$setTransform(i,s,n,a,o,r)}return this}$rotate(t,e,i){if(this.rotatable){const s=Ct(t),n=Math.cos(s),a=Math.sin(s),[o,r,h,c]=[n,a,-a,n];if(V(e)&&V(i)){const[t,s,n,a]=this.$matrix,{width:l,height:d}=this.getBoundingClientRect(),u=e-l/2,$=i-d/2,p=(u*a-n*$)/(t*a-n*s),g=($*t-s*u)/(t*a-n*s);this.$transform(o,r,h,c,p*(1-o)-g*h,g*(1-c)-p*r)}else this.$transform(o,r,h,c,0,0)}return this}$zoom(t,e,i){if(!this.scalable||0===t)return this;if(t<0?t=1/(1-t):t+=1,V(e)&&V(i)){const[s,n,a,o]=this.$matrix,{width:r,height:h}=this.getBoundingClientRect(),c=e-r/2,l=i-h/2,d=(c*o-a*l)/(s*o-a*n),u=(l*s-n*c)/(s*o-a*n);this.$transform(t,0,0,t,d*(1-t),u*(1-t))}else this.$scale(t);return this}$scale(t,e=t){return this.scalable&&this.$transform(t,0,0,e,0,0),this}$skew(t,e=0){if(this.skewable){const i=Ct(t),s=Ct(e);this.$transform(1,Math.tan(s),Math.tan(i),1,0,0)}return this}$translate(t,e=t){return this.translatable&&V(t)&&V(e)&&this.$transform(1,0,0,1,t,e),this}$transform(t,e,i,s,n,a){return V(t)&&V(e)&&V(i)&&V(s)&&V(n)&&V(a)?this.$setTransform(xt(this.$matrix,[t,e,i,s,n,a])):this}$setTransform(t,e,i,s,n,a){if((this.rotatable||this.scalable||this.skewable||this.translatable)&&(Array.isArray(t)&&([t,e,i,s,n,a]=t),V(t)&&V(e)&&V(i)&&V(s)&&V(n)&&V(a))){const o=[...this.$matrix],r=[t,e,i,s,n,a];if(this.$isReady&&this.$canvas){const{$canvas:t}=this,e=t.getBoundingClientRect();this.style.transform=`matrix(${r.join(", ")})`;const i=this.$image.getBoundingClientRect();this.style.transform=`matrix(${o.join(", ")})`;let{maxFit:s,minFit:n}=this;if(s||n){if(i.top>e.bottom||i.right<e.left||i.bottom<e.top||i.left>e.right)return this;const{naturalWidth:t,naturalHeight:a}=this.$image;switch(s===G&&(s=t>=e.width||a>=e.height?H:Z),s){case U:if(i.width>e.width&&i.height>e.height)return this;break;case K:case H:if(i.width>e.width||i.height>e.height)return this;break;case Z:if(i.width>t||i.height>a)return this}switch(n===G&&(n=t>=e.width||a>=e.height?H:Z),n){case U:case K:if(i.width<e.width||i.height<e.height)return this;break;case H:if(i.width<e.width&&i.height<e.height)return this;break;case Z:if(i.width<t||i.height<a)return this}}if(!1===this.$emit(B,{x:i.x-e.x,y:i.y-e.y,width:i.width,height:i.height}))return this}if(!1===this.$emit(F,{matrix:r,oldMatrix:o}))return this;this.$matrix=r,this.style.transform=`matrix(${r.join(", ")})`}return this}$getTransform(){return this.$matrix.slice()}$resetTransform(){return this.$setTransform([1,0,0,1,0,0])}}Nt.$name=c,Nt.$version="2.2.0";const Wt=new WeakMap;class Xt extends Rt{constructor(){super(...arguments),this.$onWindowResize=null,this.$onCanvasActionEnd=null,this.$onCanvasActionStart=null,this.$onSelectionChange=null,this.$style=":host{display:block;height:0;left:0;outline:var(--theme-color) solid 1px;position:relative;top:0;width:0}:host([transparent]){outline-color:transparent}",this.x=0,this.y=0,this.width=0,this.height=0,this.slottable=!1,this.themeColor="rgba(0, 0, 0, 0.65)"}set $canvas(t){Wt.set(this,t)}get $canvas(){return Wt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["height","width","x","y"])}connectedCallback(){super.connectedCallback();const t=this.closest(this.$getTagNameOf(a));if(t){this.$canvas=t,this.style.position="absolute";const e=t.querySelector(this.$getTagNameOf(l));e&&(this.$onWindowResize=this.$render.bind(this),this.$onCanvasActionStart=t=>{e.hidden&&t.detail.action===$&&(this.hidden=!1)},this.$onCanvasActionEnd=t=>{e.hidden&&t.detail.action===$&&(this.hidden=!0)},this.$onSelectionChange=t=>{var i,s;if((null===(s=null===(i=t.target)||void 0===i?void 0:i.constructor)||void 0===s?void 0:s.$name)!==l)return;const{x:n,y:a,width:o,height:r}=t.defaultPrevented?e:t.detail;this.$change(n,a,o,r),(e.hidden||0===n&&0===a&&0===o&&0===r)&&(this.hidden=!0)},ut(window,W,this.$onWindowResize),ut(t,q,this.$onCanvasActionStart),ut(t,j,this.$onCanvasActionEnd),ut(t,B,this.$onSelectionChange))}this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onWindowResize&&(dt(window,W,this.$onWindowResize),this.$onWindowResize=null),this.$onCanvasActionStart&&(dt(t,q,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(dt(t,j,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onSelectionChange&&(dt(t,B,this.$onSelectionChange),this.$onSelectionChange=null)),super.disconnectedCallback()}$change(t,e,i=this.width,s=this.height){return V(t)&&V(e)&&V(i)&&V(s)&&(t!==this.x||e!==this.y||i!==this.width||s!==this.height)?(this.hidden&&(this.hidden=!1),this.x=t,this.y=e,this.width=i,this.height=s,this.$render()):this}$reset(){return this.$change(0,0,0,0)}$render(){return this.$setStyles({transform:`translate(${this.x}px, ${this.y}px)`,width:this.width,height:this.height,outlineWidth:e.innerWidth*e.devicePixelRatio})}}Xt.$name=d,Xt.$version="2.2.0";class Yt extends Rt{constructor(){super(...arguments),this.$onCanvasCropEnd=null,this.$onCanvasCropStart=null,this.$style=':host{background-color:var(--theme-color);display:block}:host([action=move]),:host([action=select]){height:100%;left:0;position:absolute;top:0;width:100%}:host([action=move]){cursor:move}:host([action=select]){cursor:crosshair}:host([action$=-resize]){background-color:transparent;height:15px;position:absolute;width:15px}:host([action$=-resize]):after{background-color:var(--theme-color);content:"";display:block;height:5px;left:50%;position:absolute;top:50%;transform:translate(-50%,-50%);width:5px}:host([action=n-resize]),:host([action=s-resize]){cursor:ns-resize;left:50%;transform:translateX(-50%);width:100%}:host([action=n-resize]){top:-8px}:host([action=s-resize]){bottom:-8px}:host([action=e-resize]),:host([action=w-resize]){cursor:ew-resize;height:100%;top:50%;transform:translateY(-50%)}:host([action=e-resize]){right:-8px}:host([action=w-resize]){left:-8px}:host([action=ne-resize]){cursor:nesw-resize;right:-8px;top:-8px}:host([action=nw-resize]){cursor:nwse-resize;left:-8px;top:-8px}:host([action=se-resize]){bottom:-8px;cursor:nwse-resize;right:-8px}:host([action=se-resize]):after{height:15px;width:15px}@media (pointer:coarse){:host([action=se-resize]):after{height:10px;width:10px}}@media (pointer:fine){:host([action=se-resize]):after{height:5px;width:5px}}:host([action=sw-resize]){bottom:-8px;cursor:nesw-resize;left:-8px}:host([plain]){background-color:transparent}',this.action=f,this.plain=!1,this.slottable=!1,this.themeColor="rgba(51, 153, 255, 0.5)"}static get observedAttributes(){return super.observedAttributes.concat(["action","plain"])}}Yt.$name=h,Yt.$version="2.2.0";const jt=new WeakMap;class Lt extends Rt{constructor(){super(...arguments),this.$onCanvasAction=null,this.$onCanvasActionStart=null,this.$onCanvasActionEnd=null,this.$onDocumentKeyDown=null,this.$action="",this.$actionStartTarget=null,this.$changing=!1,this.$style=':host{display:block;left:0;position:relative;right:0}:host([outlined]){outline:1px solid var(--theme-color)}:host([multiple]){outline:1px dashed hsla(0,0%,100%,.5)}:host([multiple]):after{bottom:0;content:"";cursor:pointer;display:block;left:0;position:absolute;right:0;top:0}:host([multiple][active]){outline-color:var(--theme-color);z-index:1}:host([multiple])>*{visibility:hidden}:host([multiple][active])>*{visibility:visible}:host([multiple][active]):after{display:none}',this.$initialSelection={x:0,y:0,width:0,height:0},this.x=0,this.y=0,this.width=0,this.height=0,this.aspectRatio=NaN,this.initialAspectRatio=NaN,this.initialCoverage=NaN,this.active=!1,this.linked=!1,this.dynamic=!1,this.movable=!1,this.resizable=!1,this.zoomable=!1,this.multiple=!1,this.keyboard=!1,this.outlined=!1,this.precise=!1}set $canvas(t){jt.set(this,t)}get $canvas(){return jt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["active","aspect-ratio","dynamic","height","initial-aspect-ratio","initial-coverage","keyboard","linked","movable","multiple","outlined","precise","resizable","width","x","y","zoomable"])}$propertyChangedCallback(t,e,i){if(!Object.is(i,e))switch(super.$propertyChangedCallback(t,e,i),t){case"x":case"y":case"width":case"height":this.$changing||this.$nextTick((()=>{this.$change(this.x,this.y,this.width,this.height,this.aspectRatio,!0)}));break;case"aspectRatio":case"initialAspectRatio":this.$nextTick((()=>{this.$initSelection()}));break;case"initialCoverage":this.$nextTick((()=>{_(i)&&i<=1&&this.$initSelection(!0,!0)}));break;case"keyboard":this.$nextTick((()=>{this.$canvas&&(i?this.$onDocumentKeyDown||(this.$onDocumentKeyDown=this.$handleKeyDown.bind(this),ut(this.ownerDocument,I,this.$onDocumentKeyDown)):this.$onDocumentKeyDown&&(dt(this.ownerDocument,I,this.$onDocumentKeyDown),this.$onDocumentKeyDown=null))}));break;case"multiple":this.$nextTick((()=>{if(this.$canvas){const t=this.$getSelections();i?(t.forEach((t=>{t.active=!1})),this.active=!0,this.$emit(B,{x:this.x,y:this.y,width:this.width,height:this.height})):(this.active=!1,t.slice(1).forEach((t=>{this.$removeSelection(t)})))}}));break;case"precise":this.$nextTick((()=>{this.$change(this.x,this.y)}));break;case"linked":i&&(this.dynamic=!0)}}connectedCallback(){super.connectedCallback();const t=this.closest(this.$getTagNameOf(a));t?(this.$canvas=t,this.$setStyles({position:"absolute",transform:`translate(${this.x}px, ${this.y}px)`}),this.hidden||this.$render(),this.$initSelection(!0),this.$onCanvasActionStart=this.$handleActionStart.bind(this),this.$onCanvasActionEnd=this.$handleActionEnd.bind(this),this.$onCanvasAction=this.$handleAction.bind(this),ut(t,q,this.$onCanvasActionStart),ut(t,j,this.$onCanvasActionEnd),ut(t,Y,this.$onCanvasAction)):this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(dt(t,q,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(dt(t,j,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(dt(t,Y,this.$onCanvasAction),this.$onCanvasAction=null)),super.disconnectedCallback()}$getSelections(){let t=[];return this.parentElement&&(t=Array.from(this.parentElement.querySelectorAll(this.$getTagNameOf(l)))),t}$initSelection(t=!1,e=!1){const{initialCoverage:i,parentElement:s}=this;if(_(i)&&s){const n=this.aspectRatio||this.initialAspectRatio;let a=(e?0:this.width)||s.offsetWidth*i,o=(e?0:this.height)||s.offsetHeight*i;_(n)&&({width:a,height:o}=St({aspectRatio:n,width:a,height:o})),this.$change(this.x,this.y,a,o),t&&this.$center(),this.$initialSelection={x:this.x,y:this.y,width:this.width,height:this.height}}}$createSelection(){const t=this.cloneNode(!0);return this.hasAttribute("id")&&t.removeAttribute("id"),t.initialCoverage=NaN,this.active=!1,this.parentElement&&this.parentElement.insertBefore(t,this.nextSibling),t}$removeSelection(t=this){if(this.parentElement){const e=this.$getSelections();if(e.length>1){const i=e.indexOf(t),s=e[i+1]||e[i-1];s&&(t.active=!1,this.parentElement.removeChild(t),s.active=!0,s.$emit(B,{x:s.x,y:s.y,width:s.width,height:s.height}))}else this.$clear()}}$handleActionStart(t){var e,i;if(t.defaultPrevented)return;const s=null===(i=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===i?void 0:i.target;this.$action="",this.$actionStartTarget=s,!this.hidden&&this.multiple&&!this.active&&s===this&&this.parentElement&&(this.$getSelections().forEach((t=>{t.active=!1})),this.active=!0,this.$emit(B,{x:this.x,y:this.y,width:this.width,height:this.height}))}$handleAction(t){const{currentTarget:e,detail:i}=t;if(t.defaultPrevented||!e||!i)return;const{relatedEvent:s}=i;let{action:n}=i;const a=s?mt(s):null;if(!n&&this.multiple&&(n=this.$action||(null==a?void 0:a.action),this.$action=n),!n||this.hidden&&n!==$||this.multiple&&!this.active&&n!==g)return;const{width:o,height:r}=this;let h=i.endX-i.startX,c=i.endY-i.startY,{aspectRatio:l}=this;switch(!_(l)&&s.shiftKey&&(l=_(o)&&_(r)?o/r:1),n){case $:if(0!==h||0!==c){0===h?h=c:0===c&&(c=h);const{$canvas:t}=this,s=wt(e);(this.multiple&&!this.hidden?this.$createSelection():this).$change(i.startX-s.left,i.startY-s.top,Math.abs(h),Math.abs(c),l),h<0?c<0?n=S:c>0&&(n=A):h>0&&(c<0?n=k:c>0&&(n=x)),t&&(t.$action=n)}break;case p:this.movable&&(this.dynamic||this.$actionStartTarget&&this.contains(this.$actionStartTarget))&&this.$move(h,c);break;case g:case b:if(s&&this.zoomable&&(this.dynamic||this.contains(s.target))){const t=wt(e);this.$zoom(i.scale,s.pageX-t.left,s.pageY-t.top)}break;default:this.$resize(n,h,c,l)}}$handleActionEnd(){this.$action="",this.$actionStartTarget=null}$handleKeyDown(t){if(t.defaultPrevented||this.hidden||!this.keyboard||this.multiple&&!this.active)return;const{activeElement:e}=document;if(!e||!["INPUT","TEXTAREA"].includes(e.tagName)&&!["true","plaintext-only"].includes(e.contentEditable))switch(t.key){case"Backspace":t.metaKey&&(t.preventDefault(),this.$removeSelection());break;case"Delete":t.preventDefault(),this.$removeSelection();break;case"ArrowLeft":t.preventDefault(),this.$move(-1,0);break;case"ArrowRight":t.preventDefault(),this.$move(1,0);break;case"ArrowUp":t.preventDefault(),this.$move(0,-1);break;case"ArrowDown":t.preventDefault(),this.$move(0,1);break;case"+":t.preventDefault(),this.$zoom(.1);break;case"-":t.preventDefault(),this.$zoom(-.1)}}$center(){const{parentElement:t}=this;if(!t)return this;const e=(t.offsetWidth-this.width)/2,i=(t.offsetHeight-this.height)/2;return this.$change(e,i)}$move(t,e=t){return this.$moveTo(this.x+t,this.y+e)}$moveTo(t,e=t){return this.movable?this.$change(t,e):this}$resize(t,e=0,i=0,s=this.aspectRatio){if(!this.resizable)return this;const n=_(s),{$canvas:a}=this;let{x:o,y:r,width:h,height:c}=this;switch(t){case v:r+=i,c-=i,c<0&&(t=y,c=-c,r-=c),n&&(o+=(e=i*s)/2,h-=e,h<0&&(h=-h,o-=h));break;case w:h+=e,h<0&&(t=C,h=-h,o-=h),n&&(r-=(i=e/s)/2,c+=i,c<0&&(c=-c,r-=c));break;case y:c+=i,c<0&&(t=v,c=-c,r-=c),n&&(o-=(e=i*s)/2,h+=e,h<0&&(h=-h,o-=h));break;case C:o+=e,h-=e,h<0&&(t=w,h=-h,o-=h),n&&(r+=(i=e/s)/2,c-=i,c<0&&(c=-c,r-=c));break;case k:n&&(i=-e/s),r+=i,c-=i,h+=e,h<0&&c<0?(t=A,h=-h,c=-c,o-=h,r-=c):h<0?(t=S,h=-h,o-=h):c<0&&(t=x,c=-c,r-=c);break;case S:n&&(i=e/s),o+=e,r+=i,h-=e,c-=i,h<0&&c<0?(t=x,h=-h,c=-c,o-=h,r-=c):h<0?(t=k,h=-h,o-=h):c<0&&(t=A,c=-c,r-=c);break;case x:n&&(i=e/s),h+=e,c+=i,h<0&&c<0?(t=S,h=-h,c=-c,o-=h,r-=c):h<0?(t=A,h=-h,o-=h):c<0&&(t=k,c=-c,r-=c);break;case A:n&&(i=-e/s),o+=e,h-=e,c+=i,h<0&&c<0?(t=k,h=-h,c=-c,o-=h,r-=c):h<0?(t=x,h=-h,o-=h):c<0&&(t=S,c=-c,r-=c)}return a&&a.$setAction(t),this.$change(o,r,h,c)}$zoom(t,e,i){if(!this.zoomable||0===t)return this;t<0?t=1/(1-t):t+=1;const{width:s,height:n}=this,a=s*t,o=n*t;let r=this.x,h=this.y;return V(e)&&V(i)?(r-=(a-s)*((e-this.x)/s),h-=(o-n)*((i-this.y)/n)):(r-=(a-s)/2,h-=(o-n)/2),this.$change(r,h,a,o)}$change(t,e,i=this.width,s=this.height,n=this.aspectRatio,a=!1){return this.$changing||!V(t)||!V(e)||!V(i)||!V(s)||i<0||s<0?this:(_(n)&&({width:i,height:s}=St({aspectRatio:n,width:i,height:s},"cover")),this.precise||(t=Math.round(t),e=Math.round(e),i=Math.round(i),s=Math.round(s)),t===this.x&&e===this.y&&i===this.width&&s===this.height&&Object.is(n,this.aspectRatio)&&!a?this:(this.hidden&&(this.hidden=!1),!1===this.$emit(B,{x:t,y:e,width:i,height:s})?this:(this.$changing=!0,this.x=t,this.y=e,this.width=i,this.height=s,this.$changing=!1,this.$render())))}$reset(){const{x:t,y:e,width:i,height:s}=this.$initialSelection;return this.$change(t,e,i,s)}$clear(){return this.$change(0,0,0,0,NaN,!0),this.hidden=!0,this}$render(){return this.$setStyles({transform:`translate(${this.x}px, ${this.y}px)`,width:this.width,height:this.height})}$toCanvas(t){return new Promise(((e,i)=>{if(!this.isConnected)return void i(new Error("The current element is not connected to the DOM."));const s=document.createElement("canvas");let{width:n,height:a}=this,o=1;if(st(t)&&(_(t.width)||_(t.height))&&(({width:n,height:a}=St({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.width),s.width=n,s.height=a,!this.$canvas)return void e(s);const r=this.$canvas.querySelector(this.$getTagNameOf(c));r?r.$ready().then((i=>{const h=s.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform(),p=-this.x,g=-this.y,m=(p*d-l*g)/(e*d-l*c),b=(g*e-c*p)/(e*d-l*c);let f=e*m+l*b+u,v=c*m+d*b+$,w=i.naturalWidth,y=i.naturalHeight;1!==o&&(f*=o,v*=o,w*=o,y*=o);const C=w/2,k=y/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),st(t)&&nt(t.beforeDraw)&&t.beforeDraw.call(this,h,s),h.save(),h.translate(C,k),h.transform(e,c,l,d,f,v),h.translate(-C,-k),h.drawImage(i,0,0,w,y),h.restore()}e(s)})).catch(i):e(s)}))}}Lt.$name=l,Lt.$version="2.2.0";class qt extends Rt{constructor(){super(...arguments),this.$style=":host{display:flex;flex-direction:column;position:relative;touch-action:none;-webkit-user-select:none;-moz-user-select:none;user-select:none}:host([bordered]){border:1px dashed var(--theme-color)}:host([covered]){bottom:0;left:0;position:absolute;right:0;top:0}:host>span{display:flex;flex:1}:host>span+span{border-top:1px dashed var(--theme-color)}:host>span>span{flex:1}:host>span>span+span{border-left:1px dashed var(--theme-color)}",this.bordered=!1,this.columns=3,this.covered=!1,this.rows=3,this.slottable=!1,this.themeColor="rgba(238, 238, 238, 0.5)"}static get observedAttributes(){return super.observedAttributes.concat(["bordered","columns","covered","rows"])}$propertyChangedCallback(t,e,i){Object.is(i,e)||(super.$propertyChangedCallback(t,e,i),"rows"!==t&&"columns"!==t||this.$nextTick((()=>{this.$render()})))}connectedCallback(){super.connectedCallback(),this.$render()}$render(){const t=this.$getShadowRoot(),e=document.createDocumentFragment();for(let t=0;t<this.rows;t+=1){const t=document.createElement("span");t.setAttribute("data-cropper-grid-row",""),t.setAttribute("role","row");for(let e=0;e<this.columns;e+=1){const e=document.createElement("span");e.setAttribute("role","gridcell"),t.appendChild(e)}e.appendChild(t)}t&&(t.querySelectorAll("[data-cropper-grid-row]").forEach((t=>t.remove())),t.appendChild(e))}}qt.$name=r,qt.$version="2.2.0";class Bt extends Rt{constructor(){super(...arguments),this.$style=':host{display:inline-block;height:1em;position:relative;touch-action:none;-webkit-user-select:none;-moz-user-select:none;user-select:none;vertical-align:middle;width:1em}:host:after,:host:before{background-color:var(--theme-color);content:"";display:block;position:absolute}:host:before{height:1px;left:0;top:50%;transform:translateY(-50%);width:100%}:host:after{height:100%;left:50%;top:0;transform:translateX(-50%);width:1px}:host([centered]){left:50%;position:absolute;top:50%;transform:translate(-50%,-50%)}',this.centered=!1,this.slottable=!1,this.themeColor="rgba(238, 238, 238, 0.5)"}static get observedAttributes(){return super.observedAttributes.concat(["centered"])}}Bt.$name=o,Bt.$version="2.2.0";const Ft=new WeakMap,Ht=new WeakMap,Ut=new WeakMap,Kt=new WeakMap,Zt="vertical";class Gt extends Rt{constructor(){super(...arguments),this.$onSelectionChange=null,this.$onSourceImageLoad=null,this.$onSourceImageTransform=null,this.$scale=1,this.$style=":host{display:block;height:100%;overflow:hidden;position:relative;width:100%}",this.resize=Zt,this.selection="",this.slottable=!1}set $image(t){Ht.set(this,t)}get $image(){return Ht.get(this)}set $sourceImage(t){Kt.set(this,t)}get $sourceImage(){return Kt.get(this)}set $canvas(t){Ft.set(this,t)}get $canvas(){return Ft.get(this)}set $selection(t){Ut.set(this,t)}get $selection(){return Ut.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["resize","selection"])}connectedCallback(){var t,e;super.connectedCallback();let i=null;if(i=this.selection?null!==(e=null===(t=vt(this))||void 0===t?void 0:t.querySelector(this.selection))&&void 0!==e?e:null:this.closest(this.$getTagNameOf(l)),at(i)){this.$selection=i,this.$onSelectionChange=this.$handleSelectionChange.bind(this),ut(i,B,this.$onSelectionChange);const t=i.closest(this.$getTagNameOf(a));if(t){this.$canvas=t;const e=t.querySelector(this.$getTagNameOf(c));e&&(this.$sourceImage=e,this.$image=e.cloneNode(!0),this.$getShadowRoot().appendChild(this.$image),this.$onSourceImageLoad=this.$handleSourceImageLoad.bind(this),this.$onSourceImageTransform=this.$handleSourceImageTransform.bind(this),ut(e.$image,N,this.$onSourceImageLoad),ut(e,F,this.$onSourceImageTransform))}this.$render()}}disconnectedCallback(){const{$image:t,$selection:e,$sourceImage:i}=this;e&&this.$onSelectionChange&&(dt(e,B,this.$onSelectionChange),this.$onSelectionChange=null),i&&this.$onSourceImageLoad&&(dt(i.$image,N,this.$onSourceImageLoad),this.$onSourceImageLoad=null),i&&this.$onSourceImageTransform&&(dt(i,F,this.$onSourceImageTransform),this.$onSourceImageTransform=null);const s=this.$getShadowRoot();t&&(null==s?void 0:s.contains(t))&&s.removeChild(t),super.disconnectedCallback()}$handleSelectionChange(t){this.$render(t.defaultPrevented?this.$selection:t.detail)}$handleSourceImageLoad(){const{$image:t,$sourceImage:e}=this,i=t.getAttribute("src"),s=e.getAttribute("src");s&&s!==i&&(t.setAttribute("src",s),t.$ready((()=>{this.$render()})))}$handleSourceImageTransform(t){this.$render(void 0,t.detail.matrix)}$render(t,e){const{$canvas:i,$selection:s}=this;t||s.hidden||(t=s),(!t||0===t.x&&0===t.y&&0===t.width&&0===t.height)&&(t={x:0,y:0,width:i.offsetWidth,height:i.offsetHeight});const{x:n,y:a,width:o,height:r}=t,h={},{clientWidth:c,clientHeight:l}=this;let d=c,u=l,$=NaN;switch(this.resize){case"both":$=1,d=o,u=r,h.width=o,h.height=r;break;case"horizontal":$=r>0?l/r:0,d=o*$,h.width=d;break;case Zt:$=o>0?c/o:0,u=r*$,h.height=u;break;default:c>0?$=o>0?c/o:0:l>0&&($=r>0?l/r:0)}this.$scale=$,this.$setStyles(h),this.$sourceImage&&setTimeout((()=>{this.$transformImageByOffset(null!=e?e:this.$sourceImage.$getTransform(),-n,-a)}))}$transformImageByOffset(t,e,i){const{$image:s,$scale:n,$sourceImage:a}=this;if(a&&s&&n>=0){const[o,r,h,c,l,d]=t,u=(e*c-h*i)/(o*c-h*r),$=(i*o-r*e)/(o*c-h*r),p=o*u+h*$+l,g=r*u+c*$+d;a.$ready((t=>{this.$setStyles.call(s,{width:t.naturalWidth*n,height:t.naturalHeight*n})})),s.$setTransform(o,r,h,c,p*n,g*n)}}}Gt.$name=u,Gt.$version="2.2.0";var Jt='<cropper-canvas background><cropper-image rotatable scalable skewable translatable></cropper-image><cropper-shade hidden></cropper-shade><cropper-handle action="select" plain></cropper-handle><cropper-selection initial-coverage="0.5" movable resizable><cropper-grid role="grid" bordered covered></cropper-grid><cropper-crosshair centered></cropper-crosshair><cropper-handle action="move" theme-color="rgba(255, 255, 255, 0.35)"></cropper-handle><cropper-handle action="n-resize"></cropper-handle><cropper-handle action="e-resize"></cropper-handle><cropper-handle action="s-resize"></cropper-handle><cropper-handle action="w-resize"></cropper-handle><cropper-handle action="ne-resize"></cropper-handle><cropper-handle action="nw-resize"></cropper-handle><cropper-handle action="se-resize"></cropper-handle><cropper-handle action="sw-resize"></cropper-handle></cropper-selection></cropper-canvas>';const Qt=/^(img|canvas)$/,Vt=/<(\/?(?:script|style)[^>]*)>/gi,_t={template:Jt};Dt.$define(),Bt.$define(),qt.$define(),Yt.$define(),Nt.$define(),Lt.$define(),Xt.$define(),Gt.$define();class te{constructor(t,e){var i;if(this.options=_t,J(t)&&(t=document.querySelector(t)),!at(t)||!Qt.test(t.localName))throw new Error("The first argument is required and must be an <img> or <canvas> element.");this.element=t,e=Object.assign(Object.assign({},_t),e),this.options=e;let{container:s}=e;if(s&&(J(s)&&(s=null===(i=vt(t))||void 0===i?void 0:i.querySelector(s)),!at(s)))throw new Error("The `container` option must be an element or a valid selector.");at(s)||(s=t.parentElement?t.parentElement:t.ownerDocument.body),this.container=s;const n=t.localName;let a="";"img"===n?({src:a}=t):"canvas"===n&&window.HTMLCanvasElement&&(a=t.toDataURL());const{template:o}=e;if(o&&J(o)){const e=document.createElement("template"),i=document.createDocumentFragment();e.innerHTML=o.replace(Vt,"&lt;$1&gt;"),i.appendChild(e.content),Array.from(i.querySelectorAll(c)).forEach((e=>{e.setAttribute("src",a),e.setAttribute("alt",t.alt||"The image to crop"),"img"===n&&["crossorigin","decoding","elementtiming","fetchpriority","loading","referrerpolicy","sizes","srcset"].forEach((i=>{t.hasAttribute(i)&&e.setAttribute(i,t.getAttribute(i)||"")}))})),t.parentElement?(t.style.display="none",s.insertBefore(i,t.nextSibling)):s.appendChild(i)}}getCropperCanvas(){return this.container.querySelector(a)}getCropperImage(){return this.container.querySelector(c)}getCropperSelection(){return this.container.querySelector(l)}getCropperSelections(){return this.container.querySelectorAll(l)}destroy(){var t;const e=this.getCropperCanvas();e&&(null===(t=e.parentElement)||void 0===t||t.removeChild(e)),this.element&&(this.element.style.display="")}}te.version="2.2.0";export{p as ACTION_MOVE,f as ACTION_NONE,w as ACTION_RESIZE_EAST,v as ACTION_RESIZE_NORTH,k as ACTION_RESIZE_NORTHEAST,S as ACTION_RESIZE_NORTHWEST,y as ACTION_RESIZE_SOUTH,x as ACTION_RESIZE_SOUTHEAST,A as ACTION_RESIZE_SOUTHWEST,C as ACTION_RESIZE_WEST,m as ACTION_ROTATE,g as ACTION_SCALE,$ as ACTION_SELECT,b as ACTION_TRANSFORM,E as ATTRIBUTE_ACTION,a as CROPPER_CANVAS,o as CROPPER_CROSSHAIR,r as CROPPER_GIRD,h as CROPPER_HANDLE,c as CROPPER_IMAGE,l as CROPPER_SELECTION,d as CROPPER_SHADE,u as CROPPER_VIEWER,Dt as CropperCanvas,Bt as CropperCrosshair,Rt as CropperElement,qt as CropperGrid,Yt as CropperHandle,Nt as CropperImage,Lt as CropperSelection,Xt as CropperShade,Gt as CropperViewer,Jt as DEFAULT_TEMPLATE,Y as EVENT_ACTION,j as EVENT_ACTION_END,L as EVENT_ACTION_MOVE,q as EVENT_ACTION_START,B as EVENT_CHANGE,O as EVENT_ERROR,I as EVENT_KEYDOWN,N as EVENT_LOAD,P as EVENT_POINTER_DOWN,R as EVENT_POINTER_MOVE,D as EVENT_POINTER_UP,W as EVENT_RESIZE,z as EVENT_TOUCH_END,T as EVENT_TOUCH_MOVE,M as EVENT_TOUCH_START,F as EVENT_TRANSFORM,X as EVENT_WHEEL,s as HAS_POINTER_EVENT,t as IS_BROWSER,i as IS_TOUCH_DEVICE,n as NAMESPACE,H as OBJECT_FIT_CONTAIN,U as OBJECT_FIT_COVER,K as OBJECT_FIT_FILL,Z as OBJECT_FIT_NONE,G as OBJECT_FIT_SCALE_DOWN,e as WINDOW,te as default,gt as emit,St as getAdjustedSizes,mt as getComposedPathTarget,wt as getOffset,vt as getRootDocument,at as isElement,nt as isFunction,Q as isNaN,V as isNumber,et as isObject,st as isPlainObject,_ as isPositiveNumber,J as isString,tt as isUndefined,xt as multiplyMatrices,ft as nextTick,dt as off,ut as on,$t as once,Ct as toAngleInRadian,ct as toCamelCase,rt as toKebabCase};