@cropper/elements
Advanced tools
@@ -1,1 +0,1 @@ | ||
| const t="undefined"!=typeof window&&void 0!==window.document,e=t?window:{},s=!!t&&"ontouchstart"in e.document.documentElement,i=!!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",g="move",p="scale",m="rotate",b="transform",f="none",v="n-resize",w="e-resize",C="s-resize",y="w-resize",S="ne-resize",k="nw-resize",x="se-resize",A="sw-resize",E=i?"pointerdown":s?"touchstart":"mousedown",T=i?"pointermove":s?"touchmove":"mousemove",M=i?"pointerup pointercancel":s?"touchend touchcancel":"mouseup",z="error",D="keydown",P="load",I="wheel",O="action",R="actionend",Y="actionstart",X="change",N="transform";const W=Number.isNaN||e.isNaN;function L(t){return"number"==typeof t&&!W(t)}function j(t){return L(t)&&t>0&&t<1/0}function B(t){return"object"==typeof t&&null!==t}const{hasOwnProperty:H}=Object.prototype;function K(t){if(!B(t))return!1;try{const{constructor:e}=t,{prototype:s}=e;return e&&s&&H.call(s,"isPrototypeOf")}catch(t){return!1}}function U(t){return"function"==typeof t}function q(t){return"object"==typeof t&&null!==t&&1===t.nodeType}const F=/([a-z\d])([A-Z])/g;function Z(t){return String(t).replace(F,"$1-$2").toLowerCase()}const G=/-[A-z\d]/g;function J(t){return t.replace(G,(t=>t.slice(1).toUpperCase()))}const Q=/\s\s*/;function V(t,e,s,i){e.trim().split(Q).forEach((e=>{t.removeEventListener(e,s,i)}))}function _(t,e,s,i){e.trim().split(Q).forEach((e=>{t.addEventListener(e,s,i)}))}function tt(t,e,s,i){_(t,e,s,Object.assign(Object.assign({},i),{once:!0}))}const et={bubbles:!0,cancelable:!0,composed:!0};const st=Promise.resolve();function it(t){const{documentElement:s}=t.ownerDocument,i=t.getBoundingClientRect();return{left:i.left+(e.pageXOffset-s.clientLeft),top:i.top+(e.pageYOffset-s.clientTop)}}const nt=/deg|g?rad|turn$/i;function at(t){const e=parseFloat(t)||0;if(0!==e){const[s="rad"]=String(t).match(nt)||[];switch(s.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 ot="contain";function rt(t,e=ot){const{aspectRatio:s}=t;let{width:i,height:n}=t;const a=j(i),o=j(n);if(a&&o){const t=n*s;e===ot&&t>i||"cover"===e&&t<i?n=i/s:i=n*s}else a?n=i/s:o&&(i=n*s);return{width:i,height:n}}function ht(t,...e){if(0===e.length)return t;const[s,i,n,a,o,r]=t,[h,c,l,d,u,$]=e[0];return ht(t=[s*h+n*c,i*h+a*c,s*l+n*d,i*l+a*d,s*u+n*$+o,i*u+a*$+r],...e.slice(1))}const ct=/left|top|width|height/i,lt="open",dt=new WeakMap,ut=new WeakMap,$t=new Map,gt=e.document&&Array.isArray(e.document.adoptedStyleSheets)&&"replaceSync"in e.CSSStyleSheet.prototype;class pt extends HTMLElement{constructor(){var t,e;super(),this.shadowRootMode=lt,this.slottable=!0;const s=null===(e=null===(t=Object.getPrototypeOf(this))||void 0===t?void 0:t.constructor)||void 0===e?void 0:e.$name;s&&$t.set(s,this.tagName.toLowerCase())}get $sharedStyle(){return(this.themeColor?`:host{--theme-color: ${this.themeColor};}`:"")+":host([hidden]){display:none!important}"}static get observedAttributes(){return["shadow-root-mode","slottable","theme-color"]}attributeChangedCallback(t,e,s){if(Object.is(s,e))return;const i=J(t);let n=s;switch(typeof this[i]){case"boolean":n=null!==s&&"false"!==s;break;case"number":n=Number(s)}switch(this[i]=n,t){case"theme-color":{const t=ut.get(this),e=this.$sharedStyle;t&&e&&(gt?t.replaceSync(e):t.textContent=e);break}}}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(t=Z(t),typeof s){case"boolean":!0===s?this.hasAttribute(t)||this.setAttribute(t,""):this.removeAttribute(t);break;case"number":s=W(s)?"":String(s);default:s?this.getAttribute(t)!==s&&this.setAttribute(t,s):this.removeAttribute(t)}}connectedCallback(){Object.getPrototypeOf(this).constructor.observedAttributes.forEach((t=>{const e=J(t);let s=this[e];(function(t){return void 0===t})(s)||this.$propertyChangedCallback(e,void 0,s),Object.defineProperty(this,e,{enumerable:!0,configurable:!0,get:()=>s,set(t){const i=s;s=t,this.$propertyChangedCallback(e,i,t)}})}));const t=this.attachShadow({mode:this.shadowRootMode||lt});if(this.shadowRoot||dt.set(this,t),ut.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(){ut.has(this)&&ut.delete(this),dt.has(this)&&dt.delete(this)}$getTagNameOf(t){var e;return null!==(e=$t.get(t))&&void 0!==e?e:t}$setStyles(t){return Object.keys(t).forEach((e=>{let s=t[e];L(s)&&(s=0!==s&&ct.test(e)?`${s}px`:String(s)),this.style[e]=s})),this}$getShadowRoot(){return this.shadowRoot||dt.get(this)}$addStyles(t){let e;const s=this.$getShadowRoot();return gt?(e=new CSSStyleSheet,e.replaceSync(t),s.adoptedStyleSheets=s.adoptedStyleSheets.concat(e)):(e=document.createElement("style"),e.textContent=t,s.appendChild(e)),e}$emit(t,e,s){return function(t,e,s,i){return t.dispatchEvent(new CustomEvent(e,Object.assign(Object.assign(Object.assign({},et),{detail:s}),i)))}(this,t,e,s)}$nextTick(t){return function(t,e){return e?st.then(t?e.bind(t):e):st}(this,t)}static $define(s,i){B(s)&&(i=s,s=""),s||(s=this.$name||this.name),s=Z(s),t&&e.customElements&&!e.customElements.get(s)&&customElements.define(s,this,i)}}pt.$version="2.0.0-beta.2";class mt extends pt{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-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.disabled||this.$unbind(),super.disconnectedCallback()}$propertyChangedCallback(t,e,s){if(!Object.is(s,e)&&(super.$propertyChangedCallback(t,e,s),"disabled"===t))s?this.$unbind():this.$bind()}$bind(){this.$onPointerDown||(this.$onPointerDown=this.$handlePointerDown.bind(this),_(this,E,this.$onPointerDown)),this.$onPointerMove||(this.$onPointerMove=this.$handlePointerMove.bind(this),_(this.ownerDocument,T,this.$onPointerMove)),this.$onPointerUp||(this.$onPointerUp=this.$handlePointerUp.bind(this),_(this.ownerDocument,M,this.$onPointerUp)),this.$onWheel||(this.$onWheel=this.$handleWheel.bind(this),_(this,I,this.$onWheel,{passive:!1,capture:!0}))}$unbind(){this.$onPointerDown&&(V(this,E,this.$onPointerDown),this.$onPointerDown=null),this.$onPointerMove&&(V(this.ownerDocument,T,this.$onPointerMove),this.$onPointerMove=null),this.$onPointerUp&&(V(this.ownerDocument,M,this.$onPointerUp),this.$onPointerUp=null),this.$onWheel&&(V(this,I,this.$onWheel,{capture:!0}),this.$onWheel=null)}$handlePointerDown(t){const{buttons:e,button:s,type:i}=t;if(this.disabled||("pointerdown"===i&&"mouse"===t.pointerType||"mousedown"===i)&&(L(e)&&1!==e||L(s)&&0!==s||t.ctrlKey))return;const{$pointers:n}=this;let a="";if(t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:s})=>{n.set(t,{startX:e,startY:s,endX:e,endY:s})}));else{const{pointerId:e=0,pageX:s,pageY:i}=t;n.set(e,{startX:s,startY:i,endX:s,endY:i})}n.size>1?a=b:q(t.target)&&(a=t.target.action||t.target.getAttribute("action")||""),!1!==this.$emit(Y,{action:a,relatedEvent:t})&&(t.preventDefault(),this.$action=a,this.style.willChange="transform")}$handlePointerMove(t){const{$action:e,$pointers:s}=this;if(this.disabled||e===f||0===s.size)return;if(!1===this.$emit("actionmove",{action:e,relatedEvent:t}))return;if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:i})=>{const n=s.get(t);n&&Object.assign(n,{endX:e,endY:i})}));else{const{pointerId:e=0,pageX:i,pageY:n}=t,a=s.get(e);a&&Object.assign(a,{endX:i,endY:n})}const i={action:e,relatedEvent:t};if(e===b){const e=new Map(s);let n=0,a=0,o=0,r=0,h=t.pageX,c=t.pageY;s.forEach(((t,s)=>{e.delete(s),e.forEach((e=>{let s=e.startX-t.startX,i=e.startY-t.startY,l=e.endX-t.endX,d=e.endY-t.endY,u=0,$=0,g=0,p=0;if(0===s?i<0?g=2*Math.PI:i>0&&(g=Math.PI):s>0?g=Math.PI/2+Math.atan(i/s):s<0&&(g=1.5*Math.PI+Math.atan(i/s)),0===l?d<0?p=2*Math.PI:d>0&&(p=Math.PI):l>0?p=Math.PI/2+Math.atan(d/l):l<0&&(p=1.5*Math.PI+Math.atan(d/l)),p>0||g>0){const s=p-g,i=Math.abs(s);i>n&&(n=i,o=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}if(s=Math.abs(s),i=Math.abs(i),l=Math.abs(l),d=Math.abs(d),s>0&&i>0?u=Math.sqrt(s*s+i*i):s>0?u=s:i>0&&(u=i),l>0&&d>0?$=Math.sqrt(l*l+d*d):l>0?$=l:d>0&&($=d),u>0&&$>0){const s=($-u)/u,i=Math.abs(s);i>a&&(a=i,r=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}}))}));const l=n>0,d=a>0;l&&d?(i.rotate=o,i.scale=r,i.centerX=h,i.centerY=c):l?(i.action=m,i.rotate=o,i.centerX=h,i.centerY=c):d?(i.action=p,i.scale=r,i.centerX=h,i.centerY=c):i.action=f}else{const[t]=Array.from(s.values());Object.assign(i,t)}s.forEach((t=>{t.startX=t.endX,t.startY=t.endY})),i.action!==f&&this.$emit(O,i,{cancelable:!1})}$handlePointerUp(t){const{$action:e,$pointers:s}=this;if(!this.disabled&&e!==f&&!1!==this.$emit(R,{action:e,relatedEvent:t})){if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t})=>{s.delete(t)}));else{const{pointerId:e=0}=t;s.delete(e)}0===s.size&&(this.style.willChange="",this.$action=f)}}$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(O,{action:p,scale:e,relatedEvent:t},{cancelable:!1})}$setAction(t){return"string"==typeof t&&(this.$action=t),this}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let n=this.offsetWidth,a=this.offsetHeight,o=1;K(t)&&(j(t.width)||j(t.height))&&(({width:n,height:a}=rt({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.offsetWidth),i.width=n,i.height=a;const r=this.querySelector(this.$getTagNameOf(c));r?r.$ready().then((s=>{const h=i.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform();let g=u,p=$,m=s.naturalWidth,b=s.naturalHeight;1!==o&&(g*=o,p*=o,m*=o,b*=o);const f=m/2,v=b/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),K(t)&&U(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(f,v),h.transform(e,c,l,d,g,p),h.translate(-f,-v),h.drawImage(s,0,0,m,b),h.restore()}e(i)})).catch(s):e(i)}))}}mt.$name=a,mt.$version="2.0.0-beta.2";const bt=new WeakMap,ft=["alt","crossorigin","decoding","importance","loading","referrerpolicy","sizes","src","srcset"];class vt extends pt{constructor(){super(...arguments),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.rotatable=!0,this.scalable=!0,this.skewable=!0,this.slottable=!1,this.translatable=!0}set $canvas(t){bt.set(this,t)}get $canvas(){return bt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(ft,["rotatable","scalable","skewable","translatable"])}attributeChangedCallback(t,e,s){Object.is(s,e)||(super.attributeChangedCallback(t,e,s),ft.includes(t)&&this.$image.setAttribute(t,s))}connectedCallback(){super.connectedCallback();const{$image:t}=this,e=this.closest(this.$getTagNameOf(a));e&&(this.$canvas=e,this.$setStyles({position:"absolute"}),this.$onCanvasActionStart=t=>{var e,s;this.$actionStartTarget=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target},this.$onCanvasActionEnd=()=>{this.$actionStartTarget=null},this.$onCanvasAction=this.$handleAction.bind(this),_(e,Y,this.$onCanvasActionStart),_(e,R,this.$onCanvasActionEnd),_(e,O,this.$onCanvasAction)),this.$onLoad=this.$handleLoad.bind(this),_(t,P,this.$onLoad),this.$getShadowRoot().appendChild(t)}disconnectedCallback(){const{$image:t,$canvas:e}=this;e&&(this.$onCanvasActionStart&&(V(e,Y,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(V(e,R,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(V(e,O,this.$onCanvasAction),this.$onCanvasAction=null)),t&&this.$onLoad&&(V(t,P,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("cover")}$handleAction(t){if(this.hidden||!(this.rotatable||this.scalable||this.translatable))return;const{$canvas:e}=this,{detail:s}=t;if(s){const{relatedEvent:t}=s;let{action:i}=s;switch(i!==b||this.rotatable&&this.scalable||(i=this.rotatable?m:this.scalable?p:f),i){case g:if(this.translatable){const t=this.$getTagNameOf(l);let i=e.querySelector(t);i&&i.multiple&&!i.active&&(i=e.querySelector(`${t}[active]`)),i&&!i.hidden&&i.movable&&this.$actionStartTarget&&i.contains(this.$actionStartTarget)||this.$move(s.endX-s.startX,s.endY-s.startY)}break;case m:if(this.rotatable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$rotate(s.rotate,t.clientX-e,t.clientY-i)}else this.$rotate(s.rotate);break;case p:if(this.scalable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$zoom(s.scale,t.clientX-e,t.clientY-i)}else this.$zoom(s.scale);break;case b:if(this.rotatable&&this.scalable){const{rotate:e}=s;let{scale:i}=s;i<0?i=1/(1-i):i+=1;const n=Math.cos(e),a=Math.sin(e),[o,r,h,c]=[n*i,a*i,-a*i,n*i];if(t){const e=this.getBoundingClientRect(),s=t.clientX-e.x,i=t.clientY-e.y,[n,a,l,d]=this.$matrix,u=e.width/2,$=i-e.height/2,g=((s-u)*d-l*$)/(n*d-l*a),p=($-a*g)/d;this.$transform(o,r,h,c,g*(1-o)+p*h,p*(1-c)+g*r)}else this.$transform(o,r,h,c,0,0)}}}}$ready(t){const{$image:e}=this,s=new Promise(((t,s)=>{const i=new Error("Failed to load the image source");if(e.complete)e.naturalWidth>0&&e.naturalHeight>0?t(e):s(i);else{const n=()=>{V(e,z,a),t(e)},a=()=>{V(e,P,n),s(i)};tt(e,P,n),tt(e,z,a)}}));return U(t)&&s.then((e=>(t(e),e))),s}$center(t){const{parentElement:e}=this;if(!e)return this;const s=e.getBoundingClientRect(),i=s.width,n=s.height,{x:a,y:o,width:r,height:h}=this.getBoundingClientRect(),c=a+r/2,l=o+h/2,d=s.x+i/2,u=s.y+n/2;if(this.$move(d-c,u-l),t&&(r!==i||h!==n)){const e=i/r,s=n/h;switch(t){case"cover":this.$scale(Math.max(e,s));break;case"contain":this.$scale(Math.min(e,s))}}return this}$move(t,e=t){if(this.translatable&&L(t)&&L(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$translate(o,r)}return this}$moveTo(t,e=t){if(this.translatable&&L(t)&&L(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$setTransform(s,i,n,a,o,r)}return this}$rotate(t,e,s){if(this.rotatable){const i=at(t),n=Math.cos(i),a=Math.sin(i),[o,r,h,c]=[n,a,-a,n];if(L(e)&&L(s)){const[t,i,n,a]=this.$matrix,{width:l,height:d}=this.getBoundingClientRect(),u=s-d/2,$=((e-l/2)*a-n*u)/(t*a-n*i),g=(u-i*$)/a;this.$transform(o,r,h,c,$*(1-o)-g*h,g*(1-c)-$*r)}else this.$transform(o,r,h,c,0,0)}return this}$zoom(t,e,s){if(!this.scalable||0===t)return this;if(t<0?t=1/(1-t):t+=1,L(e)&&L(s)){const[i,n,a,o]=this.$matrix,{width:r,height:h}=this.getBoundingClientRect(),c=s-h/2,l=((e-r/2)*o-a*c)/(i*o-a*n),d=(c-n*l)/o;this.$transform(t,0,0,t,l*(1-t),d*(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 s=at(t),i=at(e);this.$transform(1,Math.tan(i),Math.tan(s),1,0,0)}return this}$translate(t,e=t){return this.translatable&&L(t)&&L(e)&&this.$transform(1,0,0,1,t,e),this}$transform(t,e,s,i,n,a){return L(t)&&L(e)&&L(s)&&L(i)&&L(n)&&L(a)?this.$setTransform(ht(this.$matrix,[t,e,s,i,n,a])):this}$setTransform(t,e,s,i,n,a){if((this.rotatable||this.scalable||this.skewable||this.translatable)&&(Array.isArray(t)&&([t,e,s,i,n,a]=t),L(t)&&L(e)&&L(s)&&L(i)&&L(n)&&L(a))){const o=[t,e,s,i,n,a];if(!1===this.$emit(N,{matrix:o,oldMatrix:this.$matrix}))return this;this.$matrix=o,this.style.transform=`matrix(${o.join(", ")})`}return this}$getTransform(){return this.$matrix.slice()}$resetTransform(){return this.$setTransform([1,0,0,1,0,0])}}vt.$name=c,vt.$version="2.0.0-beta.2";const wt=new WeakMap;class Ct extends pt{constructor(){super(...arguments),this.$onCanvasChange=null,this.$onCanvasActionEnd=null,this.$onCanvasActionStart=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.$onCanvasActionStart=t=>{e.hidden&&t.detail.action===$&&(this.hidden=!1)},this.$onCanvasActionEnd=t=>{e.hidden&&t.detail.action===$&&(this.hidden=!0)},this.$onCanvasChange=t=>{const{x:s,y:i,width:n,height:a}=t.detail;this.$change(s,i,n,a),(e.hidden||0===s&&0===i&&0===n&&0===a)&&(this.hidden=!0)},_(t,Y,this.$onCanvasActionStart),_(t,R,this.$onCanvasActionEnd),_(t,X,this.$onCanvasChange))}this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(V(t,Y,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(V(t,R,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasChange&&(V(t,X,this.$onCanvasChange),this.$onCanvasChange=null)),super.disconnectedCallback()}$change(t,e,s=this.width,i=this.height){return L(t)&&L(e)&&L(s)&&L(i)&&(t!==this.x||e!==this.y||s!==this.width||i!==this.height)?(this.hidden&&(this.hidden=!1),this.x=t,this.y=e,this.width=s,this.height=i,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})}}Ct.$name=d,Ct.$version="2.0.0-beta.2";class yt extends pt{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.0.0-beta.2";const St=new WeakMap;class kt extends pt{constructor(){super(...arguments),this.$onCanvasAction=null,this.$onCanvasActionStart=null,this.$onCanvasActionEnd=null,this.$onDocumentKeyDown=null,this.$actionStartTarget=null,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.x=0,this.y=0,this.width=0,this.height=0,this.aspectRatio=NaN,this.initialAspectRatio=NaN,this.initialCoverage=NaN,this.active=!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){St.set(this,t)}get $canvas(){return St.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["active","aspect-ratio","height","initial-aspect-ratio","initial-coverage","keyboard","movable","multiple","outlined","precise","resizable","width","x","y","zoomable"])}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(super.$propertyChangedCallback(t,e,s),t){case"aspectRatio":j(s)||(this.aspectRatio=NaN);break;case"initialAspectRatio":j(s)||(this.initialAspectRatio=NaN);break;case"initialCoverage":(!j(s)||s>1)&&(this.initialCoverage=NaN);break;case"keyboard":this.$nextTick((()=>{this.$canvas&&(s?this.$onDocumentKeyDown||(this.$onDocumentKeyDown=this.$handleKeyDown.bind(this),_(this.ownerDocument,D,this.$onDocumentKeyDown)):this.$onDocumentKeyDown&&(V(this.ownerDocument,D,this.$onDocumentKeyDown),this.$onDocumentKeyDown=null))}));break;case"multiple":this.$nextTick((()=>{this.$canvas&&(s?this.active=!0:(this.$getSelections().forEach(((t,e)=>{e>0&&this.$removeSelection(t)})),this.active=!1))}))}}connectedCallback(){super.connectedCallback(),this.multiple&&!this.active&&(this.active=!0);const t=this.closest(this.$getTagNameOf(a));if(t){this.$canvas=t,this.$setStyles({position:"absolute",transform:`translate(${this.x}px, ${this.y}px)`}),this.hidden||this.$render();const{initialCoverage:e,parentElement:s}=this;if(j(e)&&s){const t=this.aspectRatio||this.initialAspectRatio,{offsetWidth:i,offsetHeight:n}=s;let a=i*e,o=n*e;j(t)&&({width:a,height:o}=rt({aspectRatio:t,width:a,height:o})),this.$change(this.x,this.y,a,o),this.$center()}this.$onCanvasActionStart=this.$handleActionStart.bind(this),this.$onCanvasActionEnd=this.$handleActionEnd.bind(this),this.$onCanvasAction=this.$handleAction.bind(this),_(t,Y,this.$onCanvasActionStart),_(t,R,this.$onCanvasActionStart),_(t,O,this.$onCanvasAction)}else this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(V(t,Y,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(V(t,R,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(V(t,O,this.$onCanvasAction),this.$onCanvasAction=null)),super.disconnectedCallback()}$getSelections(){let t=[];return this.parentElement&&(t=Array.from(this.parentElement.querySelectorAll(this.$getTagNameOf(l)))),t}$createSelection(){const t=this.cloneNode(!0);return this.hasAttribute("id")&&t.removeAttribute("id"),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 s=e.indexOf(t),i=e[s+1]||e[s-1];i&&(this.parentElement.removeChild(t),i.active=!0,i.$emit(X,{x:i.x,y:i.y,width:i.width,height:i.height}))}else this.$reset(),this.hidden=!0}}$handleActionStart(t){var e,s;const i=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target;this.$actionStartTarget=i,!this.hidden&&this.multiple&&!this.active&&i===this&&this.parentElement&&(this.$getSelections().forEach((t=>{t.active=!1})),this.active=!0,this.$emit(X,{x:this.x,y:this.y,width:this.width,height:this.height}))}$handleAction(t){if(this.multiple&&!this.active)return;const{currentTarget:e,detail:s}=t;if(e&&s){const{relatedEvent:i}=s;let{action:n}=s;if(!n&&this.multiple&&(n=null==i?void 0:i.target.action),!n||this.hidden&&n!==$)return;const a=s.endX-s.startX,o=s.endY-s.startY,{width:r,height:h}=this;let{aspectRatio:c}=this;switch(!j(c)&&t.shiftKey&&(c=j(r)&&j(h)?r/h:1),n){case $:{const{$canvas:t}=this,i=it(e);(this.multiple&&!this.hidden?this.$createSelection():this).$change(s.startX-i.left,s.startY-i.top,a,o,c),n=x,a<0?o>0?n=A:o<0&&(n=k):a>0&&o<0&&(n=S),t&&(t.$action=n);break}case g:this.movable&&this.$actionStartTarget&&this.contains(this.$actionStartTarget)&&this.$move(a,o);break;case p:if(i&&this.zoomable){const t=it(e);this.$zoom(s.scale,i.pageX-t.left,i.pageY-t.top)}break;default:this.$resize(n,a,o,c)}}}$handleActionEnd(){this.$actionStartTarget=null}$handleKeyDown(t){if(!(this.hidden||!this.keyboard||this.multiple&&!this.active||t.defaultPrevented))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,s=(t.offsetHeight-this.height)/2;return this.$change(e,s)}$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,s=0,i=this.aspectRatio){if(!this.resizable)return this;const n=j(i),{$canvas:a}=this;let{x:o,y:r,width:h,height:c}=this;switch(t){case v:r+=s,c-=s,c<0&&(t=C,c=-c,r-=c),n&&(o+=(e=s*i)/2,h-=e,h<0&&(h=-h,o-=h));break;case w:h+=e,h<0&&(t=y,h=-h,o-=h),n&&(r-=(s=e/i)/2,c+=s,c<0&&(c=-c,r-=c));break;case C:c+=s,c<0&&(t=v,c=-c,r-=c),n&&(o-=(e=s*i)/2,h+=e,h<0&&(h=-h,o-=h));break;case y:o+=e,h-=e,h<0&&(t=w,h=-h,o-=h),n&&(r+=(s=e/i)/2,c-=s,c<0&&(c=-c,r-=c));break;case S:n&&(s=-e/i),r+=s,c-=s,h+=e,h<0&&c<0?(t=A,h=-h,c=-c,o-=h,r-=c):h<0?(t=k,h=-h,o-=h):c<0&&(t=x,c=-c,r-=c);break;case k:n&&(s=e/i),o+=e,r+=s,h-=e,c-=s,h<0&&c<0?(t=x,h=-h,c=-c,o-=h,r-=c):h<0?(t=S,h=-h,o-=h):c<0&&(t=A,c=-c,r-=c);break;case x:n&&(s=e/i),h+=e,c+=s,h<0&&c<0?(t=k,h=-h,c=-c,o-=h,r-=c):h<0?(t=A,h=-h,o-=h):c<0&&(t=S,c=-c,r-=c);break;case A:n&&(s=-e/i),o+=e,h-=e,c+=s,h<0&&c<0?(t=S,h=-h,c=-c,o-=h,r-=c):h<0?(t=x,h=-h,o-=h):c<0&&(t=k,c=-c,r-=c)}return a&&a.$setAction(t),this.$change(o,r,h,c)}$zoom(t,e,s){if(!this.zoomable||0===t)return this;t<0?t=1/(1-t):t+=1;const{width:i,height:n}=this,a=i*t,o=n*t;let r=this.x,h=this.y;return L(e)&&L(s)?(r-=(a-i)*((e-this.x)/i),h-=(o-n)*((s-this.y)/n)):(r-=(a-i)/2,h-=(o-n)/2),this.$change(r,h,a,o)}$change(t,e,s=this.width,i=this.height,n=this.aspectRatio){return L(t)&&L(e)&&L(s)&&L(i)?(this.precise||(t=Math.round(t),e=Math.round(e),s=Math.round(s),i=Math.round(i)),t===this.x&&e===this.y&&s===this.width&&i===this.height?this:(this.hidden&&(this.hidden=!1),j(n)&&({width:s,height:i}=rt({aspectRatio:n,width:s,height:i},"cover")),!1===this.$emit(X,{x:t,y:e,width:s,height:i})?this:(this.x=t,this.y=e,this.width=s,this.height=i,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})}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let{width:n,height:a}=this,o=1;if(K(t)&&(j(t.width)||j(t.height))&&(({width:n,height:a}=rt({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.width),i.width=n,i.height=a,!this.$canvas)return void e(i);const r=this.$canvas.querySelector(this.$getTagNameOf(c));r?r.$ready().then((s=>{const h=i.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform(),g=-this.x,p=-this.y,m=(g*d-l*p)/(e*d-l*c),b=(p-c*m)/d;let f=e*m+l*b+u,v=c*m+d*b+$,w=s.naturalWidth,C=s.naturalHeight;1!==o&&(f*=o,v*=o,w*=o,C*=o);const y=w/2,S=C/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),K(t)&&U(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(y,S),h.transform(e,c,l,d,f,v),h.translate(-y,-S),h.drawImage(s,0,0,w,C),h.restore()}e(i)})).catch(s):e(i)}))}}kt.$name=l,kt.$version="2.0.0-beta.2";class xt extends pt{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,s){Object.is(s,e)||(super.$propertyChangedCallback(t,e,s),"rows"!==t&&"columns"!==t||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("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.innerHTML="",t.appendChild(e))}}xt.$name=r,xt.$version="2.0.0-beta.2";class At extends pt{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"])}}At.$name=o,At.$version="2.0.0-beta.2";const Et=new WeakMap,Tt=new WeakMap,Mt=new WeakMap,zt="vertical";class Dt extends pt{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){Et.set(this,t)}get $image(){return Et.get(this)}set $sourceImage(t){Mt.set(this,t)}get $sourceImage(){return Mt.get(this)}set $selection(t){Tt.set(this,t)}get $selection(){return Tt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["resize","selection"])}connectedCallback(){super.connectedCallback();let t=null;if(t=this.selection?this.ownerDocument.querySelector(this.selection):this.closest(this.$getTagNameOf(l)),q(t)){this.$selection=t,this.$onSelectionChange=this.$handleSelectionChange.bind(this),_(t,X,this.$onSelectionChange);const e=t.closest(this.$getTagNameOf(a));if(e){const t=e.querySelector(this.$getTagNameOf(c));t&&(this.$sourceImage=t,this.$image=t.cloneNode(!0),this.$getShadowRoot().appendChild(this.$image),this.$onSourceImageLoad=this.$handleSourceImageLoad.bind(this),this.$onSourceImageTransform=this.$handleSourceImageTransform.bind(this),_(t.$image,P,this.$onSourceImageLoad),_(t,N,this.$onSourceImageTransform))}this.$render()}}disconnectedCallback(){const{$selection:t,$sourceImage:e}=this;t&&this.$onSelectionChange&&(V(t,X,this.$onSelectionChange),this.$onSelectionChange=null),e&&this.$onSourceImageLoad&&(V(e.$image,P,this.$onSourceImageLoad),this.$onSourceImageLoad=null),e&&this.$onSourceImageTransform&&(V(e,N,this.$onSourceImageTransform),this.$onSourceImageTransform=null),super.disconnectedCallback()}$handleSelectionChange(t){this.$render(t.detail)}$handleSourceImageLoad(){const{$image:t,$sourceImage:e}=this,s=t.getAttribute("src"),i=e.getAttribute("src");i&&i!==s&&(t.setAttribute("src",i),t.$ready((()=>{setTimeout((()=>{const{x:t,y:s}=this.$selection;this.$transformImageByOffset(e.$getTransform(),-t,-s)}))})))}$handleSourceImageTransform(t){const{x:e,y:s}=this.$selection;this.$transformImageByOffset(t.detail.matrix,-e,-s)}$render(t){const{x:e,y:s,width:i,height:n}=t||this.$selection,a={},{clientWidth:o,clientHeight:r}=this;let h=o,c=r,l=NaN;switch(this.resize){case"both":l=1,h=i,c=n,a.width=i,a.height=n;break;case"horizontal":l=r/n,h=i*l,a.width=h;break;case zt:l=o/i,c=n*l,a.height=c;break;default:o>0?l=o/i:r>0&&(l=r/n)}this.$scale=l,this.$setStyles(a),this.$sourceImage&&this.$transformImageByOffset(this.$sourceImage.$getTransform(),-e,-s)}$transformImageByOffset(t,e,s){const{$image:i,$scale:n,$sourceImage:a}=this;if(a&&i&&n>0){const[a,o,r,h,c,l]=t,d=(e*h-r*s)/(a*h-r*o),u=(s-o*d)/h,$=a*d+r*u+c,g=o*d+h*u+l;i.$ready((t=>{this.$setStyles.call(i,{width:t.naturalWidth*n,height:t.naturalHeight*n})})),i.$setTransform(a,o,r,h,$*n,g*n)}}}Dt.$name=u,Dt.$version="2.0.0-beta.2";export{mt as CropperCanvas,At as CropperCrosshair,pt as CropperElement,xt as CropperGrid,yt as CropperHandle,vt as CropperImage,kt as CropperSelection,Ct as CropperShade,Dt as CropperViewer}; | ||
| const t="undefined"!=typeof window&&void 0!==window.document,e=t?window:{},s=!!t&&"ontouchstart"in e.document.documentElement,i=!!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",g="move",p="scale",m="rotate",b="transform",f="none",v="n-resize",w="e-resize",C="s-resize",y="w-resize",S="ne-resize",k="nw-resize",x="se-resize",A="sw-resize",E=i?"pointerdown":s?"touchstart":"mousedown",T=i?"pointermove":s?"touchmove":"mousemove",M=i?"pointerup pointercancel":s?"touchend touchcancel":"mouseup",z="error",D="keydown",P="load",I="wheel",O="action",R="actionend",Y="actionstart",X="change",N="transform";const W=Number.isNaN||e.isNaN;function L(t){return"number"==typeof t&&!W(t)}function j(t){return L(t)&&t>0&&t<1/0}function B(t){return"object"==typeof t&&null!==t}const{hasOwnProperty:H}=Object.prototype;function K(t){if(!B(t))return!1;try{const{constructor:e}=t,{prototype:s}=e;return e&&s&&H.call(s,"isPrototypeOf")}catch(t){return!1}}function U(t){return"function"==typeof t}function q(t){return"object"==typeof t&&null!==t&&1===t.nodeType}const F=/([a-z\d])([A-Z])/g;function Z(t){return String(t).replace(F,"$1-$2").toLowerCase()}const G=/-[A-z\d]/g;function J(t){return t.replace(G,(t=>t.slice(1).toUpperCase()))}const Q=/\s\s*/;function V(t,e,s,i){e.trim().split(Q).forEach((e=>{t.removeEventListener(e,s,i)}))}function _(t,e,s,i){e.trim().split(Q).forEach((e=>{t.addEventListener(e,s,i)}))}function tt(t,e,s,i){_(t,e,s,Object.assign(Object.assign({},i),{once:!0}))}const et={bubbles:!0,cancelable:!0,composed:!0};const st=Promise.resolve();function it(t){const{documentElement:s}=t.ownerDocument,i=t.getBoundingClientRect();return{left:i.left+(e.pageXOffset-s.clientLeft),top:i.top+(e.pageYOffset-s.clientTop)}}const nt=/deg|g?rad|turn$/i;function at(t){const e=parseFloat(t)||0;if(0!==e){const[s="rad"]=String(t).match(nt)||[];switch(s.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 ot="contain";function rt(t,e=ot){const{aspectRatio:s}=t;let{width:i,height:n}=t;const a=j(i),o=j(n);if(a&&o){const t=n*s;e===ot&&t>i||"cover"===e&&t<i?n=i/s:i=n*s}else a?n=i/s:o&&(i=n*s);return{width:i,height:n}}function ht(t,...e){if(0===e.length)return t;const[s,i,n,a,o,r]=t,[h,c,l,d,u,$]=e[0];return ht(t=[s*h+n*c,i*h+a*c,s*l+n*d,i*l+a*d,s*u+n*$+o,i*u+a*$+r],...e.slice(1))}const ct=/left|top|width|height/i,lt="open",dt=new WeakMap,ut=new WeakMap,$t=new Map,gt=e.document&&Array.isArray(e.document.adoptedStyleSheets)&&"replaceSync"in e.CSSStyleSheet.prototype;class pt extends HTMLElement{get $sharedStyle(){return(this.themeColor?`:host{--theme-color: ${this.themeColor};}`:"")+":host([hidden]){display:none!important}"}constructor(){var t,e;super(),this.shadowRootMode=lt,this.slottable=!0;const s=null===(e=null===(t=Object.getPrototypeOf(this))||void 0===t?void 0:t.constructor)||void 0===e?void 0:e.$name;s&&$t.set(s,this.tagName.toLowerCase())}static get observedAttributes(){return["shadow-root-mode","slottable","theme-color"]}attributeChangedCallback(t,e,s){if(Object.is(s,e))return;const i=J(t);let n=s;switch(typeof this[i]){case"boolean":n=null!==s&&"false"!==s;break;case"number":n=Number(s)}switch(this[i]=n,t){case"theme-color":{const t=ut.get(this),e=this.$sharedStyle;t&&e&&(gt?t.replaceSync(e):t.textContent=e);break}}}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(t=Z(t),typeof s){case"boolean":!0===s?this.hasAttribute(t)||this.setAttribute(t,""):this.removeAttribute(t);break;case"number":s=W(s)?"":String(s);default:s?this.getAttribute(t)!==s&&this.setAttribute(t,s):this.removeAttribute(t)}}connectedCallback(){Object.getPrototypeOf(this).constructor.observedAttributes.forEach((t=>{const e=J(t);let s=this[e];(function(t){return void 0===t})(s)||this.$propertyChangedCallback(e,void 0,s),Object.defineProperty(this,e,{enumerable:!0,configurable:!0,get:()=>s,set(t){const i=s;s=t,this.$propertyChangedCallback(e,i,t)}})}));const t=this.attachShadow({mode:this.shadowRootMode||lt});if(this.shadowRoot||dt.set(this,t),ut.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(){ut.has(this)&&ut.delete(this),dt.has(this)&&dt.delete(this)}$getTagNameOf(t){var e;return null!==(e=$t.get(t))&&void 0!==e?e:t}$setStyles(t){return Object.keys(t).forEach((e=>{let s=t[e];L(s)&&(s=0!==s&&ct.test(e)?`${s}px`:String(s)),this.style[e]=s})),this}$getShadowRoot(){return this.shadowRoot||dt.get(this)}$addStyles(t){let e;const s=this.$getShadowRoot();return gt?(e=new CSSStyleSheet,e.replaceSync(t),s.adoptedStyleSheets=s.adoptedStyleSheets.concat(e)):(e=document.createElement("style"),e.textContent=t,s.appendChild(e)),e}$emit(t,e,s){return function(t,e,s,i){return t.dispatchEvent(new CustomEvent(e,Object.assign(Object.assign(Object.assign({},et),{detail:s}),i)))}(this,t,e,s)}$nextTick(t){return function(t,e){return e?st.then(t?e.bind(t):e):st}(this,t)}static $define(s,i){B(s)&&(i=s,s=""),s||(s=this.$name||this.name),s=Z(s),t&&e.customElements&&!e.customElements.get(s)&&customElements.define(s,this,i)}}pt.$version="2.0.0-beta.3";class mt extends pt{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-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.disabled||this.$unbind(),super.disconnectedCallback()}$propertyChangedCallback(t,e,s){if(!Object.is(s,e)&&(super.$propertyChangedCallback(t,e,s),"disabled"===t))s?this.$unbind():this.$bind()}$bind(){this.$onPointerDown||(this.$onPointerDown=this.$handlePointerDown.bind(this),_(this,E,this.$onPointerDown)),this.$onPointerMove||(this.$onPointerMove=this.$handlePointerMove.bind(this),_(this.ownerDocument,T,this.$onPointerMove)),this.$onPointerUp||(this.$onPointerUp=this.$handlePointerUp.bind(this),_(this.ownerDocument,M,this.$onPointerUp)),this.$onWheel||(this.$onWheel=this.$handleWheel.bind(this),_(this,I,this.$onWheel,{passive:!1,capture:!0}))}$unbind(){this.$onPointerDown&&(V(this,E,this.$onPointerDown),this.$onPointerDown=null),this.$onPointerMove&&(V(this.ownerDocument,T,this.$onPointerMove),this.$onPointerMove=null),this.$onPointerUp&&(V(this.ownerDocument,M,this.$onPointerUp),this.$onPointerUp=null),this.$onWheel&&(V(this,I,this.$onWheel,{capture:!0}),this.$onWheel=null)}$handlePointerDown(t){const{buttons:e,button:s,type:i}=t;if(this.disabled||("pointerdown"===i&&"mouse"===t.pointerType||"mousedown"===i)&&(L(e)&&1!==e||L(s)&&0!==s||t.ctrlKey))return;const{$pointers:n}=this;let a="";if(t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:s})=>{n.set(t,{startX:e,startY:s,endX:e,endY:s})}));else{const{pointerId:e=0,pageX:s,pageY:i}=t;n.set(e,{startX:s,startY:i,endX:s,endY:i})}n.size>1?a=b:q(t.target)&&(a=t.target.action||t.target.getAttribute("action")||""),!1!==this.$emit(Y,{action:a,relatedEvent:t})&&(t.preventDefault(),this.$action=a,this.style.willChange="transform")}$handlePointerMove(t){const{$action:e,$pointers:s}=this;if(this.disabled||e===f||0===s.size)return;if(!1===this.$emit("actionmove",{action:e,relatedEvent:t}))return;if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:i})=>{const n=s.get(t);n&&Object.assign(n,{endX:e,endY:i})}));else{const{pointerId:e=0,pageX:i,pageY:n}=t,a=s.get(e);a&&Object.assign(a,{endX:i,endY:n})}const i={action:e,relatedEvent:t};if(e===b){const e=new Map(s);let n=0,a=0,o=0,r=0,h=t.pageX,c=t.pageY;s.forEach(((t,s)=>{e.delete(s),e.forEach((e=>{let s=e.startX-t.startX,i=e.startY-t.startY,l=e.endX-t.endX,d=e.endY-t.endY,u=0,$=0,g=0,p=0;if(0===s?i<0?g=2*Math.PI:i>0&&(g=Math.PI):s>0?g=Math.PI/2+Math.atan(i/s):s<0&&(g=1.5*Math.PI+Math.atan(i/s)),0===l?d<0?p=2*Math.PI:d>0&&(p=Math.PI):l>0?p=Math.PI/2+Math.atan(d/l):l<0&&(p=1.5*Math.PI+Math.atan(d/l)),p>0||g>0){const s=p-g,i=Math.abs(s);i>n&&(n=i,o=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}if(s=Math.abs(s),i=Math.abs(i),l=Math.abs(l),d=Math.abs(d),s>0&&i>0?u=Math.sqrt(s*s+i*i):s>0?u=s:i>0&&(u=i),l>0&&d>0?$=Math.sqrt(l*l+d*d):l>0?$=l:d>0&&($=d),u>0&&$>0){const s=($-u)/u,i=Math.abs(s);i>a&&(a=i,r=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}}))}));const l=n>0,d=a>0;l&&d?(i.rotate=o,i.scale=r,i.centerX=h,i.centerY=c):l?(i.action=m,i.rotate=o,i.centerX=h,i.centerY=c):d?(i.action=p,i.scale=r,i.centerX=h,i.centerY=c):i.action=f}else{const[t]=Array.from(s.values());Object.assign(i,t)}s.forEach((t=>{t.startX=t.endX,t.startY=t.endY})),i.action!==f&&this.$emit(O,i,{cancelable:!1})}$handlePointerUp(t){const{$action:e,$pointers:s}=this;if(!this.disabled&&e!==f&&!1!==this.$emit(R,{action:e,relatedEvent:t})){if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t})=>{s.delete(t)}));else{const{pointerId:e=0}=t;s.delete(e)}0===s.size&&(this.style.willChange="",this.$action=f)}}$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(O,{action:p,scale:e,relatedEvent:t},{cancelable:!1})}$setAction(t){return"string"==typeof t&&(this.$action=t),this}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let n=this.offsetWidth,a=this.offsetHeight,o=1;K(t)&&(j(t.width)||j(t.height))&&(({width:n,height:a}=rt({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.offsetWidth),i.width=n,i.height=a;const r=this.querySelector(this.$getTagNameOf(c));r?r.$ready().then((s=>{const h=i.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform();let g=u,p=$,m=s.naturalWidth,b=s.naturalHeight;1!==o&&(g*=o,p*=o,m*=o,b*=o);const f=m/2,v=b/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),K(t)&&U(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(f,v),h.transform(e,c,l,d,g,p),h.translate(-f,-v),h.drawImage(s,0,0,m,b),h.restore()}e(i)})).catch(s):e(i)}))}}mt.$name=a,mt.$version="2.0.0-beta.3";const bt=new WeakMap,ft=["alt","crossorigin","decoding","importance","loading","referrerpolicy","sizes","src","srcset"];class vt extends pt{constructor(){super(...arguments),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.rotatable=!0,this.scalable=!0,this.skewable=!0,this.slottable=!1,this.translatable=!0}set $canvas(t){bt.set(this,t)}get $canvas(){return bt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(ft,["rotatable","scalable","skewable","translatable"])}attributeChangedCallback(t,e,s){Object.is(s,e)||(super.attributeChangedCallback(t,e,s),ft.includes(t)&&this.$image.setAttribute(t,s))}connectedCallback(){super.connectedCallback();const{$image:t}=this,e=this.closest(this.$getTagNameOf(a));e&&(this.$canvas=e,this.$setStyles({position:"absolute"}),this.$onCanvasActionStart=t=>{var e,s;this.$actionStartTarget=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target},this.$onCanvasActionEnd=()=>{this.$actionStartTarget=null},this.$onCanvasAction=this.$handleAction.bind(this),_(e,Y,this.$onCanvasActionStart),_(e,R,this.$onCanvasActionEnd),_(e,O,this.$onCanvasAction)),this.$onLoad=this.$handleLoad.bind(this),_(t,P,this.$onLoad),this.$getShadowRoot().appendChild(t)}disconnectedCallback(){const{$image:t,$canvas:e}=this;e&&(this.$onCanvasActionStart&&(V(e,Y,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(V(e,R,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(V(e,O,this.$onCanvasAction),this.$onCanvasAction=null)),t&&this.$onLoad&&(V(t,P,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("cover")}$handleAction(t){if(this.hidden||!(this.rotatable||this.scalable||this.translatable))return;const{$canvas:e}=this,{detail:s}=t;if(s){const{relatedEvent:t}=s;let{action:i}=s;switch(i!==b||this.rotatable&&this.scalable||(i=this.rotatable?m:this.scalable?p:f),i){case g:if(this.translatable){const t=this.$getTagNameOf(l);let i=e.querySelector(t);i&&i.multiple&&!i.active&&(i=e.querySelector(`${t}[active]`)),i&&!i.hidden&&i.movable&&this.$actionStartTarget&&i.contains(this.$actionStartTarget)||this.$move(s.endX-s.startX,s.endY-s.startY)}break;case m:if(this.rotatable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$rotate(s.rotate,t.clientX-e,t.clientY-i)}else this.$rotate(s.rotate);break;case p:if(this.scalable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$zoom(s.scale,t.clientX-e,t.clientY-i)}else this.$zoom(s.scale);break;case b:if(this.rotatable&&this.scalable){const{rotate:e}=s;let{scale:i}=s;i<0?i=1/(1-i):i+=1;const n=Math.cos(e),a=Math.sin(e),[o,r,h,c]=[n*i,a*i,-a*i,n*i];if(t){const e=this.getBoundingClientRect(),s=t.clientX-e.x,i=t.clientY-e.y,[n,a,l,d]=this.$matrix,u=e.width/2,$=i-e.height/2,g=((s-u)*d-l*$)/(n*d-l*a),p=($-a*g)/d;this.$transform(o,r,h,c,g*(1-o)+p*h,p*(1-c)+g*r)}else this.$transform(o,r,h,c,0,0)}}}}$ready(t){const{$image:e}=this,s=new Promise(((t,s)=>{const i=new Error("Failed to load the image source");if(e.complete)e.naturalWidth>0&&e.naturalHeight>0?t(e):s(i);else{const n=()=>{V(e,z,a),t(e)},a=()=>{V(e,P,n),s(i)};tt(e,P,n),tt(e,z,a)}}));return U(t)&&s.then((e=>(t(e),e))),s}$center(t){const{parentElement:e}=this;if(!e)return this;const s=e.getBoundingClientRect(),i=s.width,n=s.height,{x:a,y:o,width:r,height:h}=this.getBoundingClientRect(),c=a+r/2,l=o+h/2,d=s.x+i/2,u=s.y+n/2;if(this.$move(d-c,u-l),t&&(r!==i||h!==n)){const e=i/r,s=n/h;switch(t){case"cover":this.$scale(Math.max(e,s));break;case"contain":this.$scale(Math.min(e,s))}}return this}$move(t,e=t){if(this.translatable&&L(t)&&L(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$translate(o,r)}return this}$moveTo(t,e=t){if(this.translatable&&L(t)&&L(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$setTransform(s,i,n,a,o,r)}return this}$rotate(t,e,s){if(this.rotatable){const i=at(t),n=Math.cos(i),a=Math.sin(i),[o,r,h,c]=[n,a,-a,n];if(L(e)&&L(s)){const[t,i,n,a]=this.$matrix,{width:l,height:d}=this.getBoundingClientRect(),u=s-d/2,$=((e-l/2)*a-n*u)/(t*a-n*i),g=(u-i*$)/a;this.$transform(o,r,h,c,$*(1-o)-g*h,g*(1-c)-$*r)}else this.$transform(o,r,h,c,0,0)}return this}$zoom(t,e,s){if(!this.scalable||0===t)return this;if(t<0?t=1/(1-t):t+=1,L(e)&&L(s)){const[i,n,a,o]=this.$matrix,{width:r,height:h}=this.getBoundingClientRect(),c=s-h/2,l=((e-r/2)*o-a*c)/(i*o-a*n),d=(c-n*l)/o;this.$transform(t,0,0,t,l*(1-t),d*(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 s=at(t),i=at(e);this.$transform(1,Math.tan(i),Math.tan(s),1,0,0)}return this}$translate(t,e=t){return this.translatable&&L(t)&&L(e)&&this.$transform(1,0,0,1,t,e),this}$transform(t,e,s,i,n,a){return L(t)&&L(e)&&L(s)&&L(i)&&L(n)&&L(a)?this.$setTransform(ht(this.$matrix,[t,e,s,i,n,a])):this}$setTransform(t,e,s,i,n,a){if((this.rotatable||this.scalable||this.skewable||this.translatable)&&(Array.isArray(t)&&([t,e,s,i,n,a]=t),L(t)&&L(e)&&L(s)&&L(i)&&L(n)&&L(a))){const o=[t,e,s,i,n,a];if(!1===this.$emit(N,{matrix:o,oldMatrix:this.$matrix}))return this;this.$matrix=o,this.style.transform=`matrix(${o.join(", ")})`}return this}$getTransform(){return this.$matrix.slice()}$resetTransform(){return this.$setTransform([1,0,0,1,0,0])}}vt.$name=c,vt.$version="2.0.0-beta.3";const wt=new WeakMap;class Ct extends pt{constructor(){super(...arguments),this.$onCanvasChange=null,this.$onCanvasActionEnd=null,this.$onCanvasActionStart=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.$onCanvasActionStart=t=>{e.hidden&&t.detail.action===$&&(this.hidden=!1)},this.$onCanvasActionEnd=t=>{e.hidden&&t.detail.action===$&&(this.hidden=!0)},this.$onCanvasChange=t=>{const{x:s,y:i,width:n,height:a}=t.detail;this.$change(s,i,n,a),(e.hidden||0===s&&0===i&&0===n&&0===a)&&(this.hidden=!0)},_(t,Y,this.$onCanvasActionStart),_(t,R,this.$onCanvasActionEnd),_(t,X,this.$onCanvasChange))}this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(V(t,Y,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(V(t,R,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasChange&&(V(t,X,this.$onCanvasChange),this.$onCanvasChange=null)),super.disconnectedCallback()}$change(t,e,s=this.width,i=this.height){return L(t)&&L(e)&&L(s)&&L(i)&&(t!==this.x||e!==this.y||s!==this.width||i!==this.height)?(this.hidden&&(this.hidden=!1),this.x=t,this.y=e,this.width=s,this.height=i,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})}}Ct.$name=d,Ct.$version="2.0.0-beta.3";class yt extends pt{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.0.0-beta.3";const St=new WeakMap;class kt extends pt{constructor(){super(...arguments),this.$onCanvasAction=null,this.$onCanvasActionStart=null,this.$onCanvasActionEnd=null,this.$onDocumentKeyDown=null,this.$actionStartTarget=null,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.x=0,this.y=0,this.width=0,this.height=0,this.aspectRatio=NaN,this.initialAspectRatio=NaN,this.initialCoverage=NaN,this.active=!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){St.set(this,t)}get $canvas(){return St.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["active","aspect-ratio","height","initial-aspect-ratio","initial-coverage","keyboard","movable","multiple","outlined","precise","resizable","width","x","y","zoomable"])}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(super.$propertyChangedCallback(t,e,s),t){case"aspectRatio":j(s)||(this.aspectRatio=NaN);break;case"initialAspectRatio":j(s)||(this.initialAspectRatio=NaN);break;case"initialCoverage":(!j(s)||s>1)&&(this.initialCoverage=NaN);break;case"keyboard":this.$nextTick((()=>{this.$canvas&&(s?this.$onDocumentKeyDown||(this.$onDocumentKeyDown=this.$handleKeyDown.bind(this),_(this.ownerDocument,D,this.$onDocumentKeyDown)):this.$onDocumentKeyDown&&(V(this.ownerDocument,D,this.$onDocumentKeyDown),this.$onDocumentKeyDown=null))}));break;case"multiple":this.$nextTick((()=>{this.$canvas&&(s?this.active=!0:(this.$getSelections().forEach(((t,e)=>{e>0&&this.$removeSelection(t)})),this.active=!1))}))}}connectedCallback(){super.connectedCallback(),this.multiple&&!this.active&&(this.active=!0);const t=this.closest(this.$getTagNameOf(a));if(t){this.$canvas=t,this.$setStyles({position:"absolute",transform:`translate(${this.x}px, ${this.y}px)`}),this.hidden||this.$render();const{initialCoverage:e,parentElement:s}=this;if(j(e)&&s){const t=this.aspectRatio||this.initialAspectRatio,{offsetWidth:i,offsetHeight:n}=s;let a=i*e,o=n*e;j(t)&&({width:a,height:o}=rt({aspectRatio:t,width:a,height:o})),this.$change(this.x,this.y,a,o),this.$center()}this.$onCanvasActionStart=this.$handleActionStart.bind(this),this.$onCanvasActionEnd=this.$handleActionEnd.bind(this),this.$onCanvasAction=this.$handleAction.bind(this),_(t,Y,this.$onCanvasActionStart),_(t,R,this.$onCanvasActionStart),_(t,O,this.$onCanvasAction)}else this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(V(t,Y,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(V(t,R,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(V(t,O,this.$onCanvasAction),this.$onCanvasAction=null)),super.disconnectedCallback()}$getSelections(){let t=[];return this.parentElement&&(t=Array.from(this.parentElement.querySelectorAll(this.$getTagNameOf(l)))),t}$createSelection(){const t=this.cloneNode(!0);return this.hasAttribute("id")&&t.removeAttribute("id"),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 s=e.indexOf(t),i=e[s+1]||e[s-1];i&&(t.active=!1,this.parentElement.removeChild(t),i.active=!0,i.$emit(X,{x:i.x,y:i.y,width:i.width,height:i.height}))}else this.$reset(),this.hidden=!0}}$handleActionStart(t){var e,s;const i=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target;this.$actionStartTarget=i,!this.hidden&&this.multiple&&!this.active&&i===this&&this.parentElement&&(this.$getSelections().forEach((t=>{t.active=!1})),this.active=!0,this.$emit(X,{x:this.x,y:this.y,width:this.width,height:this.height}))}$handleAction(t){if(this.multiple&&!this.active)return;const{currentTarget:e,detail:s}=t;if(e&&s){const{relatedEvent:i}=s;let{action:n}=s;if(!n&&this.multiple&&(n=null==i?void 0:i.target.action),!n||this.hidden&&n!==$)return;const a=s.endX-s.startX,o=s.endY-s.startY,{width:r,height:h}=this;let{aspectRatio:c}=this;switch(!j(c)&&t.shiftKey&&(c=j(r)&&j(h)?r/h:1),n){case $:{const{$canvas:t}=this,i=it(e);(this.multiple&&!this.hidden?this.$createSelection():this).$change(s.startX-i.left,s.startY-i.top,a,o,c),n=x,a<0?o>0?n=A:o<0&&(n=k):a>0&&o<0&&(n=S),t&&(t.$action=n);break}case g:this.movable&&this.$actionStartTarget&&this.contains(this.$actionStartTarget)&&this.$move(a,o);break;case p:if(i&&this.zoomable){const t=it(e);this.$zoom(s.scale,i.pageX-t.left,i.pageY-t.top)}break;default:this.$resize(n,a,o,c)}}}$handleActionEnd(){this.$actionStartTarget=null}$handleKeyDown(t){if(!(this.hidden||!this.keyboard||this.multiple&&!this.active||t.defaultPrevented))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,s=(t.offsetHeight-this.height)/2;return this.$change(e,s)}$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,s=0,i=this.aspectRatio){if(!this.resizable)return this;const n=j(i),{$canvas:a}=this;let{x:o,y:r,width:h,height:c}=this;switch(t){case v:r+=s,c-=s,c<0&&(t=C,c=-c,r-=c),n&&(o+=(e=s*i)/2,h-=e,h<0&&(h=-h,o-=h));break;case w:h+=e,h<0&&(t=y,h=-h,o-=h),n&&(r-=(s=e/i)/2,c+=s,c<0&&(c=-c,r-=c));break;case C:c+=s,c<0&&(t=v,c=-c,r-=c),n&&(o-=(e=s*i)/2,h+=e,h<0&&(h=-h,o-=h));break;case y:o+=e,h-=e,h<0&&(t=w,h=-h,o-=h),n&&(r+=(s=e/i)/2,c-=s,c<0&&(c=-c,r-=c));break;case S:n&&(s=-e/i),r+=s,c-=s,h+=e,h<0&&c<0?(t=A,h=-h,c=-c,o-=h,r-=c):h<0?(t=k,h=-h,o-=h):c<0&&(t=x,c=-c,r-=c);break;case k:n&&(s=e/i),o+=e,r+=s,h-=e,c-=s,h<0&&c<0?(t=x,h=-h,c=-c,o-=h,r-=c):h<0?(t=S,h=-h,o-=h):c<0&&(t=A,c=-c,r-=c);break;case x:n&&(s=e/i),h+=e,c+=s,h<0&&c<0?(t=k,h=-h,c=-c,o-=h,r-=c):h<0?(t=A,h=-h,o-=h):c<0&&(t=S,c=-c,r-=c);break;case A:n&&(s=-e/i),o+=e,h-=e,c+=s,h<0&&c<0?(t=S,h=-h,c=-c,o-=h,r-=c):h<0?(t=x,h=-h,o-=h):c<0&&(t=k,c=-c,r-=c)}return a&&a.$setAction(t),this.$change(o,r,h,c)}$zoom(t,e,s){if(!this.zoomable||0===t)return this;t<0?t=1/(1-t):t+=1;const{width:i,height:n}=this,a=i*t,o=n*t;let r=this.x,h=this.y;return L(e)&&L(s)?(r-=(a-i)*((e-this.x)/i),h-=(o-n)*((s-this.y)/n)):(r-=(a-i)/2,h-=(o-n)/2),this.$change(r,h,a,o)}$change(t,e,s=this.width,i=this.height,n=this.aspectRatio){return L(t)&&L(e)&&L(s)&&L(i)?(this.precise||(t=Math.round(t),e=Math.round(e),s=Math.round(s),i=Math.round(i)),t===this.x&&e===this.y&&s===this.width&&i===this.height?this:(this.hidden&&(this.hidden=!1),j(n)&&({width:s,height:i}=rt({aspectRatio:n,width:s,height:i},"cover")),!1===this.$emit(X,{x:t,y:e,width:s,height:i})?this:(this.x=t,this.y=e,this.width=s,this.height=i,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})}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let{width:n,height:a}=this,o=1;if(K(t)&&(j(t.width)||j(t.height))&&(({width:n,height:a}=rt({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.width),i.width=n,i.height=a,!this.$canvas)return void e(i);const r=this.$canvas.querySelector(this.$getTagNameOf(c));r?r.$ready().then((s=>{const h=i.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform(),g=-this.x,p=-this.y,m=(g*d-l*p)/(e*d-l*c),b=(p-c*m)/d;let f=e*m+l*b+u,v=c*m+d*b+$,w=s.naturalWidth,C=s.naturalHeight;1!==o&&(f*=o,v*=o,w*=o,C*=o);const y=w/2,S=C/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),K(t)&&U(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(y,S),h.transform(e,c,l,d,f,v),h.translate(-y,-S),h.drawImage(s,0,0,w,C),h.restore()}e(i)})).catch(s):e(i)}))}}kt.$name=l,kt.$version="2.0.0-beta.3";class xt extends pt{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,s){Object.is(s,e)||(super.$propertyChangedCallback(t,e,s),"rows"!==t&&"columns"!==t||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("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.innerHTML="",t.appendChild(e))}}xt.$name=r,xt.$version="2.0.0-beta.3";class At extends pt{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"])}}At.$name=o,At.$version="2.0.0-beta.3";const Et=new WeakMap,Tt=new WeakMap,Mt=new WeakMap,zt="vertical";class Dt extends pt{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){Et.set(this,t)}get $image(){return Et.get(this)}set $sourceImage(t){Mt.set(this,t)}get $sourceImage(){return Mt.get(this)}set $selection(t){Tt.set(this,t)}get $selection(){return Tt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["resize","selection"])}connectedCallback(){super.connectedCallback();let t=null;if(t=this.selection?this.ownerDocument.querySelector(this.selection):this.closest(this.$getTagNameOf(l)),q(t)){this.$selection=t,this.$onSelectionChange=this.$handleSelectionChange.bind(this),_(t,X,this.$onSelectionChange);const e=t.closest(this.$getTagNameOf(a));if(e){const t=e.querySelector(this.$getTagNameOf(c));t&&(this.$sourceImage=t,this.$image=t.cloneNode(!0),this.$getShadowRoot().appendChild(this.$image),this.$onSourceImageLoad=this.$handleSourceImageLoad.bind(this),this.$onSourceImageTransform=this.$handleSourceImageTransform.bind(this),_(t.$image,P,this.$onSourceImageLoad),_(t,N,this.$onSourceImageTransform))}this.$render()}}disconnectedCallback(){const{$selection:t,$sourceImage:e}=this;t&&this.$onSelectionChange&&(V(t,X,this.$onSelectionChange),this.$onSelectionChange=null),e&&this.$onSourceImageLoad&&(V(e.$image,P,this.$onSourceImageLoad),this.$onSourceImageLoad=null),e&&this.$onSourceImageTransform&&(V(e,N,this.$onSourceImageTransform),this.$onSourceImageTransform=null),super.disconnectedCallback()}$handleSelectionChange(t){this.$render(t.detail)}$handleSourceImageLoad(){const{$image:t,$sourceImage:e}=this,s=t.getAttribute("src"),i=e.getAttribute("src");i&&i!==s&&(t.setAttribute("src",i),t.$ready((()=>{setTimeout((()=>{const{x:t,y:s}=this.$selection;this.$transformImageByOffset(e.$getTransform(),-t,-s)}))})))}$handleSourceImageTransform(t){const{x:e,y:s}=this.$selection;this.$transformImageByOffset(t.detail.matrix,-e,-s)}$render(t){const{x:e,y:s,width:i,height:n}=t||this.$selection,a={},{clientWidth:o,clientHeight:r}=this;let h=o,c=r,l=NaN;switch(this.resize){case"both":l=1,h=i,c=n,a.width=i,a.height=n;break;case"horizontal":l=r/n,h=i*l,a.width=h;break;case zt:l=o/i,c=n*l,a.height=c;break;default:o>0?l=o/i:r>0&&(l=r/n)}this.$scale=l,this.$setStyles(a),this.$sourceImage&&this.$transformImageByOffset(this.$sourceImage.$getTransform(),-e,-s)}$transformImageByOffset(t,e,s){const{$image:i,$scale:n,$sourceImage:a}=this;if(a&&i&&n>0){const[a,o,r,h,c,l]=t,d=(e*h-r*s)/(a*h-r*o),u=(s-o*d)/h,$=a*d+r*u+c,g=o*d+h*u+l;i.$ready((t=>{this.$setStyles.call(i,{width:t.naturalWidth*n,height:t.naturalHeight*n})})),i.$setTransform(a,o,r,h,$*n,g*n)}}}Dt.$name=u,Dt.$version="2.0.0-beta.3";export{mt as CropperCanvas,At as CropperCrosshair,pt as CropperElement,xt as CropperGrid,yt as CropperHandle,vt as CropperImage,kt as CropperSelection,Ct as CropperShade,Dt as CropperViewer}; |
@@ -1,1 +0,1 @@ | ||
| !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CropperElements={})}(this,(function(t){"use strict";const e="undefined"!=typeof window&&void 0!==window.document,s=e?window:{},i=!!e&&"ontouchstart"in s.document.documentElement,n=!!e&&"PointerEvent"in s,a="cropper",o=`${a}-canvas`,r=`${a}-crosshair`,h=`${a}-grid`,c=`${a}-handle`,l=`${a}-image`,d=`${a}-selection`,u=`${a}-shade`,$=`${a}-viewer`,p="select",g="move",m="scale",b="rotate",f="transform",v="none",w="n-resize",C="e-resize",y="s-resize",S="w-resize",k="ne-resize",x="nw-resize",A="se-resize",E="sw-resize",T=n?"pointerdown":i?"touchstart":"mousedown",M=n?"pointermove":i?"touchmove":"mousemove",z=n?"pointerup pointercancel":i?"touchend touchcancel":"mouseup",D="error",P="keydown",I="load",O="wheel",R="action",Y="actionend",X="actionstart",N="change",W="transform";const L=Number.isNaN||s.isNaN;function j(t){return"number"==typeof t&&!L(t)}function B(t){return j(t)&&t>0&&t<1/0}function H(t){return"object"==typeof t&&null!==t}const{hasOwnProperty:K}=Object.prototype;function U(t){if(!H(t))return!1;try{const{constructor:e}=t,{prototype:s}=e;return e&&s&&K.call(s,"isPrototypeOf")}catch(t){return!1}}function q(t){return"function"==typeof t}function F(t){return"object"==typeof t&&null!==t&&1===t.nodeType}const _=/([a-z\d])([A-Z])/g;function G(t){return String(t).replace(_,"$1-$2").toLowerCase()}const V=/-[A-z\d]/g;function Z(t){return t.replace(V,(t=>t.slice(1).toUpperCase()))}const J=/\s\s*/;function Q(t,e,s,i){e.trim().split(J).forEach((e=>{t.removeEventListener(e,s,i)}))}function tt(t,e,s,i){e.trim().split(J).forEach((e=>{t.addEventListener(e,s,i)}))}function et(t,e,s,i){tt(t,e,s,Object.assign(Object.assign({},i),{once:!0}))}const st={bubbles:!0,cancelable:!0,composed:!0};const it=Promise.resolve();function nt(t){const{documentElement:e}=t.ownerDocument,i=t.getBoundingClientRect();return{left:i.left+(s.pageXOffset-e.clientLeft),top:i.top+(s.pageYOffset-e.clientTop)}}const at=/deg|g?rad|turn$/i;function ot(t){const e=parseFloat(t)||0;if(0!==e){const[s="rad"]=String(t).match(at)||[];switch(s.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 rt="contain";function ht(t,e=rt){const{aspectRatio:s}=t;let{width:i,height:n}=t;const a=B(i),o=B(n);if(a&&o){const t=n*s;e===rt&&t>i||"cover"===e&&t<i?n=i/s:i=n*s}else a?n=i/s:o&&(i=n*s);return{width:i,height:n}}function ct(t,...e){if(0===e.length)return t;const[s,i,n,a,o,r]=t,[h,c,l,d,u,$]=e[0];return ct(t=[s*h+n*c,i*h+a*c,s*l+n*d,i*l+a*d,s*u+n*$+o,i*u+a*$+r],...e.slice(1))}const lt=/left|top|width|height/i,dt="open",ut=new WeakMap,$t=new WeakMap,pt=new Map,gt=s.document&&Array.isArray(s.document.adoptedStyleSheets)&&"replaceSync"in s.CSSStyleSheet.prototype;class mt extends HTMLElement{constructor(){var t,e;super(),this.shadowRootMode=dt,this.slottable=!0;const s=null===(e=null===(t=Object.getPrototypeOf(this))||void 0===t?void 0:t.constructor)||void 0===e?void 0:e.$name;s&&pt.set(s,this.tagName.toLowerCase())}get $sharedStyle(){return(this.themeColor?`:host{--theme-color: ${this.themeColor};}`:"")+":host([hidden]){display:none!important}"}static get observedAttributes(){return["shadow-root-mode","slottable","theme-color"]}attributeChangedCallback(t,e,s){if(Object.is(s,e))return;const i=Z(t);let n=s;switch(typeof this[i]){case"boolean":n=null!==s&&"false"!==s;break;case"number":n=Number(s)}switch(this[i]=n,t){case"theme-color":{const t=$t.get(this),e=this.$sharedStyle;t&&e&&(gt?t.replaceSync(e):t.textContent=e);break}}}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(t=G(t),typeof s){case"boolean":!0===s?this.hasAttribute(t)||this.setAttribute(t,""):this.removeAttribute(t);break;case"number":s=L(s)?"":String(s);default:s?this.getAttribute(t)!==s&&this.setAttribute(t,s):this.removeAttribute(t)}}connectedCallback(){Object.getPrototypeOf(this).constructor.observedAttributes.forEach((t=>{const e=Z(t);let s=this[e];(function(t){return void 0===t})(s)||this.$propertyChangedCallback(e,void 0,s),Object.defineProperty(this,e,{enumerable:!0,configurable:!0,get:()=>s,set(t){const i=s;s=t,this.$propertyChangedCallback(e,i,t)}})}));const t=this.attachShadow({mode:this.shadowRootMode||dt});if(this.shadowRoot||ut.set(this,t),$t.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(){$t.has(this)&&$t.delete(this),ut.has(this)&&ut.delete(this)}$getTagNameOf(t){var e;return null!==(e=pt.get(t))&&void 0!==e?e:t}$setStyles(t){return Object.keys(t).forEach((e=>{let s=t[e];j(s)&&(s=0!==s&<.test(e)?`${s}px`:String(s)),this.style[e]=s})),this}$getShadowRoot(){return this.shadowRoot||ut.get(this)}$addStyles(t){let e;const s=this.$getShadowRoot();return gt?(e=new CSSStyleSheet,e.replaceSync(t),s.adoptedStyleSheets=s.adoptedStyleSheets.concat(e)):(e=document.createElement("style"),e.textContent=t,s.appendChild(e)),e}$emit(t,e,s){return function(t,e,s,i){return t.dispatchEvent(new CustomEvent(e,Object.assign(Object.assign(Object.assign({},st),{detail:s}),i)))}(this,t,e,s)}$nextTick(t){return function(t,e){return e?it.then(t?e.bind(t):e):it}(this,t)}static $define(t,i){H(t)&&(i=t,t=""),t||(t=this.$name||this.name),t=G(t),e&&s.customElements&&!s.customElements.get(t)&&customElements.define(t,this,i)}}mt.$version="2.0.0-beta.2";class bt extends mt{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-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=v,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.disabled||this.$unbind(),super.disconnectedCallback()}$propertyChangedCallback(t,e,s){if(!Object.is(s,e)&&(super.$propertyChangedCallback(t,e,s),"disabled"===t))s?this.$unbind():this.$bind()}$bind(){this.$onPointerDown||(this.$onPointerDown=this.$handlePointerDown.bind(this),tt(this,T,this.$onPointerDown)),this.$onPointerMove||(this.$onPointerMove=this.$handlePointerMove.bind(this),tt(this.ownerDocument,M,this.$onPointerMove)),this.$onPointerUp||(this.$onPointerUp=this.$handlePointerUp.bind(this),tt(this.ownerDocument,z,this.$onPointerUp)),this.$onWheel||(this.$onWheel=this.$handleWheel.bind(this),tt(this,O,this.$onWheel,{passive:!1,capture:!0}))}$unbind(){this.$onPointerDown&&(Q(this,T,this.$onPointerDown),this.$onPointerDown=null),this.$onPointerMove&&(Q(this.ownerDocument,M,this.$onPointerMove),this.$onPointerMove=null),this.$onPointerUp&&(Q(this.ownerDocument,z,this.$onPointerUp),this.$onPointerUp=null),this.$onWheel&&(Q(this,O,this.$onWheel,{capture:!0}),this.$onWheel=null)}$handlePointerDown(t){const{buttons:e,button:s,type:i}=t;if(this.disabled||("pointerdown"===i&&"mouse"===t.pointerType||"mousedown"===i)&&(j(e)&&1!==e||j(s)&&0!==s||t.ctrlKey))return;const{$pointers:n}=this;let a="";if(t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:s})=>{n.set(t,{startX:e,startY:s,endX:e,endY:s})}));else{const{pointerId:e=0,pageX:s,pageY:i}=t;n.set(e,{startX:s,startY:i,endX:s,endY:i})}n.size>1?a=f:F(t.target)&&(a=t.target.action||t.target.getAttribute("action")||""),!1!==this.$emit(X,{action:a,relatedEvent:t})&&(t.preventDefault(),this.$action=a,this.style.willChange="transform")}$handlePointerMove(t){const{$action:e,$pointers:s}=this;if(this.disabled||e===v||0===s.size)return;if(!1===this.$emit("actionmove",{action:e,relatedEvent:t}))return;if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:i})=>{const n=s.get(t);n&&Object.assign(n,{endX:e,endY:i})}));else{const{pointerId:e=0,pageX:i,pageY:n}=t,a=s.get(e);a&&Object.assign(a,{endX:i,endY:n})}const i={action:e,relatedEvent:t};if(e===f){const e=new Map(s);let n=0,a=0,o=0,r=0,h=t.pageX,c=t.pageY;s.forEach(((t,s)=>{e.delete(s),e.forEach((e=>{let s=e.startX-t.startX,i=e.startY-t.startY,l=e.endX-t.endX,d=e.endY-t.endY,u=0,$=0,p=0,g=0;if(0===s?i<0?p=2*Math.PI:i>0&&(p=Math.PI):s>0?p=Math.PI/2+Math.atan(i/s):s<0&&(p=1.5*Math.PI+Math.atan(i/s)),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 s=g-p,i=Math.abs(s);i>n&&(n=i,o=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}if(s=Math.abs(s),i=Math.abs(i),l=Math.abs(l),d=Math.abs(d),s>0&&i>0?u=Math.sqrt(s*s+i*i):s>0?u=s:i>0&&(u=i),l>0&&d>0?$=Math.sqrt(l*l+d*d):l>0?$=l:d>0&&($=d),u>0&&$>0){const s=($-u)/u,i=Math.abs(s);i>a&&(a=i,r=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}}))}));const l=n>0,d=a>0;l&&d?(i.rotate=o,i.scale=r,i.centerX=h,i.centerY=c):l?(i.action=b,i.rotate=o,i.centerX=h,i.centerY=c):d?(i.action=m,i.scale=r,i.centerX=h,i.centerY=c):i.action=v}else{const[t]=Array.from(s.values());Object.assign(i,t)}s.forEach((t=>{t.startX=t.endX,t.startY=t.endY})),i.action!==v&&this.$emit(R,i,{cancelable:!1})}$handlePointerUp(t){const{$action:e,$pointers:s}=this;if(!this.disabled&&e!==v&&!1!==this.$emit(Y,{action:e,relatedEvent:t})){if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t})=>{s.delete(t)}));else{const{pointerId:e=0}=t;s.delete(e)}0===s.size&&(this.style.willChange="",this.$action=v)}}$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(R,{action:m,scale:e,relatedEvent:t},{cancelable:!1})}$setAction(t){return"string"==typeof t&&(this.$action=t),this}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let n=this.offsetWidth,a=this.offsetHeight,o=1;U(t)&&(B(t.width)||B(t.height))&&(({width:n,height:a}=ht({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.offsetWidth),i.width=n,i.height=a;const r=this.querySelector(this.$getTagNameOf(l));r?r.$ready().then((s=>{const h=i.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform();let p=u,g=$,m=s.naturalWidth,b=s.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),U(t)&&q(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(f,v),h.transform(e,c,l,d,p,g),h.translate(-f,-v),h.drawImage(s,0,0,m,b),h.restore()}e(i)})).catch(s):e(i)}))}}bt.$name=o,bt.$version="2.0.0-beta.2";const ft=new WeakMap,vt=["alt","crossorigin","decoding","importance","loading","referrerpolicy","sizes","src","srcset"];class wt extends mt{constructor(){super(...arguments),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.rotatable=!0,this.scalable=!0,this.skewable=!0,this.slottable=!1,this.translatable=!0}set $canvas(t){ft.set(this,t)}get $canvas(){return ft.get(this)}static get observedAttributes(){return super.observedAttributes.concat(vt,["rotatable","scalable","skewable","translatable"])}attributeChangedCallback(t,e,s){Object.is(s,e)||(super.attributeChangedCallback(t,e,s),vt.includes(t)&&this.$image.setAttribute(t,s))}connectedCallback(){super.connectedCallback();const{$image:t}=this,e=this.closest(this.$getTagNameOf(o));e&&(this.$canvas=e,this.$setStyles({position:"absolute"}),this.$onCanvasActionStart=t=>{var e,s;this.$actionStartTarget=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target},this.$onCanvasActionEnd=()=>{this.$actionStartTarget=null},this.$onCanvasAction=this.$handleAction.bind(this),tt(e,X,this.$onCanvasActionStart),tt(e,Y,this.$onCanvasActionEnd),tt(e,R,this.$onCanvasAction)),this.$onLoad=this.$handleLoad.bind(this),tt(t,I,this.$onLoad),this.$getShadowRoot().appendChild(t)}disconnectedCallback(){const{$image:t,$canvas:e}=this;e&&(this.$onCanvasActionStart&&(Q(e,X,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(Q(e,Y,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(Q(e,R,this.$onCanvasAction),this.$onCanvasAction=null)),t&&this.$onLoad&&(Q(t,I,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("cover")}$handleAction(t){if(this.hidden||!(this.rotatable||this.scalable||this.translatable))return;const{$canvas:e}=this,{detail:s}=t;if(s){const{relatedEvent:t}=s;let{action:i}=s;switch(i!==f||this.rotatable&&this.scalable||(i=this.rotatable?b:this.scalable?m:v),i){case g:if(this.translatable){const t=this.$getTagNameOf(d);let i=e.querySelector(t);i&&i.multiple&&!i.active&&(i=e.querySelector(`${t}[active]`)),i&&!i.hidden&&i.movable&&this.$actionStartTarget&&i.contains(this.$actionStartTarget)||this.$move(s.endX-s.startX,s.endY-s.startY)}break;case b:if(this.rotatable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$rotate(s.rotate,t.clientX-e,t.clientY-i)}else this.$rotate(s.rotate);break;case m:if(this.scalable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$zoom(s.scale,t.clientX-e,t.clientY-i)}else this.$zoom(s.scale);break;case f:if(this.rotatable&&this.scalable){const{rotate:e}=s;let{scale:i}=s;i<0?i=1/(1-i):i+=1;const n=Math.cos(e),a=Math.sin(e),[o,r,h,c]=[n*i,a*i,-a*i,n*i];if(t){const e=this.getBoundingClientRect(),s=t.clientX-e.x,i=t.clientY-e.y,[n,a,l,d]=this.$matrix,u=e.width/2,$=i-e.height/2,p=((s-u)*d-l*$)/(n*d-l*a),g=($-a*p)/d;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,s=new Promise(((t,s)=>{const i=new Error("Failed to load the image source");if(e.complete)e.naturalWidth>0&&e.naturalHeight>0?t(e):s(i);else{const n=()=>{Q(e,D,a),t(e)},a=()=>{Q(e,I,n),s(i)};et(e,I,n),et(e,D,a)}}));return q(t)&&s.then((e=>(t(e),e))),s}$center(t){const{parentElement:e}=this;if(!e)return this;const s=e.getBoundingClientRect(),i=s.width,n=s.height,{x:a,y:o,width:r,height:h}=this.getBoundingClientRect(),c=a+r/2,l=o+h/2,d=s.x+i/2,u=s.y+n/2;if(this.$move(d-c,u-l),t&&(r!==i||h!==n)){const e=i/r,s=n/h;switch(t){case"cover":this.$scale(Math.max(e,s));break;case"contain":this.$scale(Math.min(e,s))}}return this}$move(t,e=t){if(this.translatable&&j(t)&&j(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$translate(o,r)}return this}$moveTo(t,e=t){if(this.translatable&&j(t)&&j(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$setTransform(s,i,n,a,o,r)}return this}$rotate(t,e,s){if(this.rotatable){const i=ot(t),n=Math.cos(i),a=Math.sin(i),[o,r,h,c]=[n,a,-a,n];if(j(e)&&j(s)){const[t,i,n,a]=this.$matrix,{width:l,height:d}=this.getBoundingClientRect(),u=s-d/2,$=((e-l/2)*a-n*u)/(t*a-n*i),p=(u-i*$)/a;this.$transform(o,r,h,c,$*(1-o)-p*h,p*(1-c)-$*r)}else this.$transform(o,r,h,c,0,0)}return this}$zoom(t,e,s){if(!this.scalable||0===t)return this;if(t<0?t=1/(1-t):t+=1,j(e)&&j(s)){const[i,n,a,o]=this.$matrix,{width:r,height:h}=this.getBoundingClientRect(),c=s-h/2,l=((e-r/2)*o-a*c)/(i*o-a*n),d=(c-n*l)/o;this.$transform(t,0,0,t,l*(1-t),d*(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 s=ot(t),i=ot(e);this.$transform(1,Math.tan(i),Math.tan(s),1,0,0)}return this}$translate(t,e=t){return this.translatable&&j(t)&&j(e)&&this.$transform(1,0,0,1,t,e),this}$transform(t,e,s,i,n,a){return j(t)&&j(e)&&j(s)&&j(i)&&j(n)&&j(a)?this.$setTransform(ct(this.$matrix,[t,e,s,i,n,a])):this}$setTransform(t,e,s,i,n,a){if((this.rotatable||this.scalable||this.skewable||this.translatable)&&(Array.isArray(t)&&([t,e,s,i,n,a]=t),j(t)&&j(e)&&j(s)&&j(i)&&j(n)&&j(a))){const o=[t,e,s,i,n,a];if(!1===this.$emit(W,{matrix:o,oldMatrix:this.$matrix}))return this;this.$matrix=o,this.style.transform=`matrix(${o.join(", ")})`}return this}$getTransform(){return this.$matrix.slice()}$resetTransform(){return this.$setTransform([1,0,0,1,0,0])}}wt.$name=l,wt.$version="2.0.0-beta.2";const Ct=new WeakMap;class yt extends mt{constructor(){super(...arguments),this.$onCanvasChange=null,this.$onCanvasActionEnd=null,this.$onCanvasActionStart=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){Ct.set(this,t)}get $canvas(){return Ct.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["height","width","x","y"])}connectedCallback(){super.connectedCallback();const t=this.closest(this.$getTagNameOf(o));if(t){this.$canvas=t,this.style.position="absolute";const e=t.querySelector(this.$getTagNameOf(d));e&&(this.$onCanvasActionStart=t=>{e.hidden&&t.detail.action===p&&(this.hidden=!1)},this.$onCanvasActionEnd=t=>{e.hidden&&t.detail.action===p&&(this.hidden=!0)},this.$onCanvasChange=t=>{const{x:s,y:i,width:n,height:a}=t.detail;this.$change(s,i,n,a),(e.hidden||0===s&&0===i&&0===n&&0===a)&&(this.hidden=!0)},tt(t,X,this.$onCanvasActionStart),tt(t,Y,this.$onCanvasActionEnd),tt(t,N,this.$onCanvasChange))}this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(Q(t,X,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(Q(t,Y,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasChange&&(Q(t,N,this.$onCanvasChange),this.$onCanvasChange=null)),super.disconnectedCallback()}$change(t,e,s=this.width,i=this.height){return j(t)&&j(e)&&j(s)&&j(i)&&(t!==this.x||e!==this.y||s!==this.width||i!==this.height)?(this.hidden&&(this.hidden=!1),this.x=t,this.y=e,this.width=s,this.height=i,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:s.innerWidth})}}yt.$name=u,yt.$version="2.0.0-beta.2";class St extends mt{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=v,this.plain=!1,this.slottable=!1,this.themeColor="rgba(51, 153, 255, 0.5)"}static get observedAttributes(){return super.observedAttributes.concat(["action","plain"])}}St.$name=c,St.$version="2.0.0-beta.2";const kt=new WeakMap;class xt extends mt{constructor(){super(...arguments),this.$onCanvasAction=null,this.$onCanvasActionStart=null,this.$onCanvasActionEnd=null,this.$onDocumentKeyDown=null,this.$actionStartTarget=null,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.x=0,this.y=0,this.width=0,this.height=0,this.aspectRatio=NaN,this.initialAspectRatio=NaN,this.initialCoverage=NaN,this.active=!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){kt.set(this,t)}get $canvas(){return kt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["active","aspect-ratio","height","initial-aspect-ratio","initial-coverage","keyboard","movable","multiple","outlined","precise","resizable","width","x","y","zoomable"])}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(super.$propertyChangedCallback(t,e,s),t){case"aspectRatio":B(s)||(this.aspectRatio=NaN);break;case"initialAspectRatio":B(s)||(this.initialAspectRatio=NaN);break;case"initialCoverage":(!B(s)||s>1)&&(this.initialCoverage=NaN);break;case"keyboard":this.$nextTick((()=>{this.$canvas&&(s?this.$onDocumentKeyDown||(this.$onDocumentKeyDown=this.$handleKeyDown.bind(this),tt(this.ownerDocument,P,this.$onDocumentKeyDown)):this.$onDocumentKeyDown&&(Q(this.ownerDocument,P,this.$onDocumentKeyDown),this.$onDocumentKeyDown=null))}));break;case"multiple":this.$nextTick((()=>{this.$canvas&&(s?this.active=!0:(this.$getSelections().forEach(((t,e)=>{e>0&&this.$removeSelection(t)})),this.active=!1))}))}}connectedCallback(){super.connectedCallback(),this.multiple&&!this.active&&(this.active=!0);const t=this.closest(this.$getTagNameOf(o));if(t){this.$canvas=t,this.$setStyles({position:"absolute",transform:`translate(${this.x}px, ${this.y}px)`}),this.hidden||this.$render();const{initialCoverage:e,parentElement:s}=this;if(B(e)&&s){const t=this.aspectRatio||this.initialAspectRatio,{offsetWidth:i,offsetHeight:n}=s;let a=i*e,o=n*e;B(t)&&({width:a,height:o}=ht({aspectRatio:t,width:a,height:o})),this.$change(this.x,this.y,a,o),this.$center()}this.$onCanvasActionStart=this.$handleActionStart.bind(this),this.$onCanvasActionEnd=this.$handleActionEnd.bind(this),this.$onCanvasAction=this.$handleAction.bind(this),tt(t,X,this.$onCanvasActionStart),tt(t,Y,this.$onCanvasActionStart),tt(t,R,this.$onCanvasAction)}else this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(Q(t,X,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(Q(t,Y,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(Q(t,R,this.$onCanvasAction),this.$onCanvasAction=null)),super.disconnectedCallback()}$getSelections(){let t=[];return this.parentElement&&(t=Array.from(this.parentElement.querySelectorAll(this.$getTagNameOf(d)))),t}$createSelection(){const t=this.cloneNode(!0);return this.hasAttribute("id")&&t.removeAttribute("id"),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 s=e.indexOf(t),i=e[s+1]||e[s-1];i&&(this.parentElement.removeChild(t),i.active=!0,i.$emit(N,{x:i.x,y:i.y,width:i.width,height:i.height}))}else this.$reset(),this.hidden=!0}}$handleActionStart(t){var e,s;const i=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target;this.$actionStartTarget=i,!this.hidden&&this.multiple&&!this.active&&i===this&&this.parentElement&&(this.$getSelections().forEach((t=>{t.active=!1})),this.active=!0,this.$emit(N,{x:this.x,y:this.y,width:this.width,height:this.height}))}$handleAction(t){if(this.multiple&&!this.active)return;const{currentTarget:e,detail:s}=t;if(e&&s){const{relatedEvent:i}=s;let{action:n}=s;if(!n&&this.multiple&&(n=null==i?void 0:i.target.action),!n||this.hidden&&n!==p)return;const a=s.endX-s.startX,o=s.endY-s.startY,{width:r,height:h}=this;let{aspectRatio:c}=this;switch(!B(c)&&t.shiftKey&&(c=B(r)&&B(h)?r/h:1),n){case p:{const{$canvas:t}=this,i=nt(e);(this.multiple&&!this.hidden?this.$createSelection():this).$change(s.startX-i.left,s.startY-i.top,a,o,c),n=A,a<0?o>0?n=E:o<0&&(n=x):a>0&&o<0&&(n=k),t&&(t.$action=n);break}case g:this.movable&&this.$actionStartTarget&&this.contains(this.$actionStartTarget)&&this.$move(a,o);break;case m:if(i&&this.zoomable){const t=nt(e);this.$zoom(s.scale,i.pageX-t.left,i.pageY-t.top)}break;default:this.$resize(n,a,o,c)}}}$handleActionEnd(){this.$actionStartTarget=null}$handleKeyDown(t){if(!(this.hidden||!this.keyboard||this.multiple&&!this.active||t.defaultPrevented))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,s=(t.offsetHeight-this.height)/2;return this.$change(e,s)}$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,s=0,i=this.aspectRatio){if(!this.resizable)return this;const n=B(i),{$canvas:a}=this;let{x:o,y:r,width:h,height:c}=this;switch(t){case w:r+=s,c-=s,c<0&&(t=y,c=-c,r-=c),n&&(o+=(e=s*i)/2,h-=e,h<0&&(h=-h,o-=h));break;case C:h+=e,h<0&&(t=S,h=-h,o-=h),n&&(r-=(s=e/i)/2,c+=s,c<0&&(c=-c,r-=c));break;case y:c+=s,c<0&&(t=w,c=-c,r-=c),n&&(o-=(e=s*i)/2,h+=e,h<0&&(h=-h,o-=h));break;case S:o+=e,h-=e,h<0&&(t=C,h=-h,o-=h),n&&(r+=(s=e/i)/2,c-=s,c<0&&(c=-c,r-=c));break;case k:n&&(s=-e/i),r+=s,c-=s,h+=e,h<0&&c<0?(t=E,h=-h,c=-c,o-=h,r-=c):h<0?(t=x,h=-h,o-=h):c<0&&(t=A,c=-c,r-=c);break;case x:n&&(s=e/i),o+=e,r+=s,h-=e,c-=s,h<0&&c<0?(t=A,h=-h,c=-c,o-=h,r-=c):h<0?(t=k,h=-h,o-=h):c<0&&(t=E,c=-c,r-=c);break;case A:n&&(s=e/i),h+=e,c+=s,h<0&&c<0?(t=x,h=-h,c=-c,o-=h,r-=c):h<0?(t=E,h=-h,o-=h):c<0&&(t=k,c=-c,r-=c);break;case E:n&&(s=-e/i),o+=e,h-=e,c+=s,h<0&&c<0?(t=k,h=-h,c=-c,o-=h,r-=c):h<0?(t=A,h=-h,o-=h):c<0&&(t=x,c=-c,r-=c)}return a&&a.$setAction(t),this.$change(o,r,h,c)}$zoom(t,e,s){if(!this.zoomable||0===t)return this;t<0?t=1/(1-t):t+=1;const{width:i,height:n}=this,a=i*t,o=n*t;let r=this.x,h=this.y;return j(e)&&j(s)?(r-=(a-i)*((e-this.x)/i),h-=(o-n)*((s-this.y)/n)):(r-=(a-i)/2,h-=(o-n)/2),this.$change(r,h,a,o)}$change(t,e,s=this.width,i=this.height,n=this.aspectRatio){return j(t)&&j(e)&&j(s)&&j(i)?(this.precise||(t=Math.round(t),e=Math.round(e),s=Math.round(s),i=Math.round(i)),t===this.x&&e===this.y&&s===this.width&&i===this.height?this:(this.hidden&&(this.hidden=!1),B(n)&&({width:s,height:i}=ht({aspectRatio:n,width:s,height:i},"cover")),!1===this.$emit(N,{x:t,y:e,width:s,height:i})?this:(this.x=t,this.y=e,this.width=s,this.height=i,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})}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let{width:n,height:a}=this,o=1;if(U(t)&&(B(t.width)||B(t.height))&&(({width:n,height:a}=ht({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.width),i.width=n,i.height=a,!this.$canvas)return void e(i);const r=this.$canvas.querySelector(this.$getTagNameOf(l));r?r.$ready().then((s=>{const h=i.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-c*m)/d;let f=e*m+l*b+u,v=c*m+d*b+$,w=s.naturalWidth,C=s.naturalHeight;1!==o&&(f*=o,v*=o,w*=o,C*=o);const y=w/2,S=C/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),U(t)&&q(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(y,S),h.transform(e,c,l,d,f,v),h.translate(-y,-S),h.drawImage(s,0,0,w,C),h.restore()}e(i)})).catch(s):e(i)}))}}xt.$name=d,xt.$version="2.0.0-beta.2";class At extends mt{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,s){Object.is(s,e)||(super.$propertyChangedCallback(t,e,s),"rows"!==t&&"columns"!==t||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("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.innerHTML="",t.appendChild(e))}}At.$name=h,At.$version="2.0.0-beta.2";class Et extends mt{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"])}}Et.$name=r,Et.$version="2.0.0-beta.2";const Tt=new WeakMap,Mt=new WeakMap,zt=new WeakMap,Dt="vertical";class Pt extends mt{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=Dt,this.selection="",this.slottable=!1}set $image(t){Tt.set(this,t)}get $image(){return Tt.get(this)}set $sourceImage(t){zt.set(this,t)}get $sourceImage(){return zt.get(this)}set $selection(t){Mt.set(this,t)}get $selection(){return Mt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["resize","selection"])}connectedCallback(){super.connectedCallback();let t=null;if(t=this.selection?this.ownerDocument.querySelector(this.selection):this.closest(this.$getTagNameOf(d)),F(t)){this.$selection=t,this.$onSelectionChange=this.$handleSelectionChange.bind(this),tt(t,N,this.$onSelectionChange);const e=t.closest(this.$getTagNameOf(o));if(e){const t=e.querySelector(this.$getTagNameOf(l));t&&(this.$sourceImage=t,this.$image=t.cloneNode(!0),this.$getShadowRoot().appendChild(this.$image),this.$onSourceImageLoad=this.$handleSourceImageLoad.bind(this),this.$onSourceImageTransform=this.$handleSourceImageTransform.bind(this),tt(t.$image,I,this.$onSourceImageLoad),tt(t,W,this.$onSourceImageTransform))}this.$render()}}disconnectedCallback(){const{$selection:t,$sourceImage:e}=this;t&&this.$onSelectionChange&&(Q(t,N,this.$onSelectionChange),this.$onSelectionChange=null),e&&this.$onSourceImageLoad&&(Q(e.$image,I,this.$onSourceImageLoad),this.$onSourceImageLoad=null),e&&this.$onSourceImageTransform&&(Q(e,W,this.$onSourceImageTransform),this.$onSourceImageTransform=null),super.disconnectedCallback()}$handleSelectionChange(t){this.$render(t.detail)}$handleSourceImageLoad(){const{$image:t,$sourceImage:e}=this,s=t.getAttribute("src"),i=e.getAttribute("src");i&&i!==s&&(t.setAttribute("src",i),t.$ready((()=>{setTimeout((()=>{const{x:t,y:s}=this.$selection;this.$transformImageByOffset(e.$getTransform(),-t,-s)}))})))}$handleSourceImageTransform(t){const{x:e,y:s}=this.$selection;this.$transformImageByOffset(t.detail.matrix,-e,-s)}$render(t){const{x:e,y:s,width:i,height:n}=t||this.$selection,a={},{clientWidth:o,clientHeight:r}=this;let h=o,c=r,l=NaN;switch(this.resize){case"both":l=1,h=i,c=n,a.width=i,a.height=n;break;case"horizontal":l=r/n,h=i*l,a.width=h;break;case Dt:l=o/i,c=n*l,a.height=c;break;default:o>0?l=o/i:r>0&&(l=r/n)}this.$scale=l,this.$setStyles(a),this.$sourceImage&&this.$transformImageByOffset(this.$sourceImage.$getTransform(),-e,-s)}$transformImageByOffset(t,e,s){const{$image:i,$scale:n,$sourceImage:a}=this;if(a&&i&&n>0){const[a,o,r,h,c,l]=t,d=(e*h-r*s)/(a*h-r*o),u=(s-o*d)/h,$=a*d+r*u+c,p=o*d+h*u+l;i.$ready((t=>{this.$setStyles.call(i,{width:t.naturalWidth*n,height:t.naturalHeight*n})})),i.$setTransform(a,o,r,h,$*n,p*n)}}}Pt.$name=$,Pt.$version="2.0.0-beta.2",t.CropperCanvas=bt,t.CropperCrosshair=Et,t.CropperElement=mt,t.CropperGrid=At,t.CropperHandle=St,t.CropperImage=wt,t.CropperSelection=xt,t.CropperShade=yt,t.CropperViewer=Pt,Object.defineProperty(t,"__esModule",{value:!0})})); | ||
| !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).CropperElements={})}(this,(function(t){"use strict";const e="undefined"!=typeof window&&void 0!==window.document,s=e?window:{},i=!!e&&"ontouchstart"in s.document.documentElement,n=!!e&&"PointerEvent"in s,a="cropper",o=`${a}-canvas`,r=`${a}-crosshair`,h=`${a}-grid`,c=`${a}-handle`,l=`${a}-image`,d=`${a}-selection`,u=`${a}-shade`,$=`${a}-viewer`,p="select",g="move",m="scale",b="rotate",f="transform",v="none",w="n-resize",C="e-resize",y="s-resize",S="w-resize",k="ne-resize",x="nw-resize",A="se-resize",E="sw-resize",T=n?"pointerdown":i?"touchstart":"mousedown",M=n?"pointermove":i?"touchmove":"mousemove",z=n?"pointerup pointercancel":i?"touchend touchcancel":"mouseup",D="error",P="keydown",I="load",O="wheel",R="action",Y="actionend",X="actionstart",N="change",W="transform";const L=Number.isNaN||s.isNaN;function j(t){return"number"==typeof t&&!L(t)}function B(t){return j(t)&&t>0&&t<1/0}function H(t){return"object"==typeof t&&null!==t}const{hasOwnProperty:K}=Object.prototype;function U(t){if(!H(t))return!1;try{const{constructor:e}=t,{prototype:s}=e;return e&&s&&K.call(s,"isPrototypeOf")}catch(t){return!1}}function q(t){return"function"==typeof t}function F(t){return"object"==typeof t&&null!==t&&1===t.nodeType}const _=/([a-z\d])([A-Z])/g;function G(t){return String(t).replace(_,"$1-$2").toLowerCase()}const V=/-[A-z\d]/g;function Z(t){return t.replace(V,(t=>t.slice(1).toUpperCase()))}const J=/\s\s*/;function Q(t,e,s,i){e.trim().split(J).forEach((e=>{t.removeEventListener(e,s,i)}))}function tt(t,e,s,i){e.trim().split(J).forEach((e=>{t.addEventListener(e,s,i)}))}function et(t,e,s,i){tt(t,e,s,Object.assign(Object.assign({},i),{once:!0}))}const st={bubbles:!0,cancelable:!0,composed:!0};const it=Promise.resolve();function nt(t){const{documentElement:e}=t.ownerDocument,i=t.getBoundingClientRect();return{left:i.left+(s.pageXOffset-e.clientLeft),top:i.top+(s.pageYOffset-e.clientTop)}}const at=/deg|g?rad|turn$/i;function ot(t){const e=parseFloat(t)||0;if(0!==e){const[s="rad"]=String(t).match(at)||[];switch(s.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 rt="contain";function ht(t,e=rt){const{aspectRatio:s}=t;let{width:i,height:n}=t;const a=B(i),o=B(n);if(a&&o){const t=n*s;e===rt&&t>i||"cover"===e&&t<i?n=i/s:i=n*s}else a?n=i/s:o&&(i=n*s);return{width:i,height:n}}function ct(t,...e){if(0===e.length)return t;const[s,i,n,a,o,r]=t,[h,c,l,d,u,$]=e[0];return ct(t=[s*h+n*c,i*h+a*c,s*l+n*d,i*l+a*d,s*u+n*$+o,i*u+a*$+r],...e.slice(1))}const lt=/left|top|width|height/i,dt="open",ut=new WeakMap,$t=new WeakMap,pt=new Map,gt=s.document&&Array.isArray(s.document.adoptedStyleSheets)&&"replaceSync"in s.CSSStyleSheet.prototype;class mt extends HTMLElement{get $sharedStyle(){return(this.themeColor?`:host{--theme-color: ${this.themeColor};}`:"")+":host([hidden]){display:none!important}"}constructor(){var t,e;super(),this.shadowRootMode=dt,this.slottable=!0;const s=null===(e=null===(t=Object.getPrototypeOf(this))||void 0===t?void 0:t.constructor)||void 0===e?void 0:e.$name;s&&pt.set(s,this.tagName.toLowerCase())}static get observedAttributes(){return["shadow-root-mode","slottable","theme-color"]}attributeChangedCallback(t,e,s){if(Object.is(s,e))return;const i=Z(t);let n=s;switch(typeof this[i]){case"boolean":n=null!==s&&"false"!==s;break;case"number":n=Number(s)}switch(this[i]=n,t){case"theme-color":{const t=$t.get(this),e=this.$sharedStyle;t&&e&&(gt?t.replaceSync(e):t.textContent=e);break}}}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(t=G(t),typeof s){case"boolean":!0===s?this.hasAttribute(t)||this.setAttribute(t,""):this.removeAttribute(t);break;case"number":s=L(s)?"":String(s);default:s?this.getAttribute(t)!==s&&this.setAttribute(t,s):this.removeAttribute(t)}}connectedCallback(){Object.getPrototypeOf(this).constructor.observedAttributes.forEach((t=>{const e=Z(t);let s=this[e];(function(t){return void 0===t})(s)||this.$propertyChangedCallback(e,void 0,s),Object.defineProperty(this,e,{enumerable:!0,configurable:!0,get:()=>s,set(t){const i=s;s=t,this.$propertyChangedCallback(e,i,t)}})}));const t=this.attachShadow({mode:this.shadowRootMode||dt});if(this.shadowRoot||ut.set(this,t),$t.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(){$t.has(this)&&$t.delete(this),ut.has(this)&&ut.delete(this)}$getTagNameOf(t){var e;return null!==(e=pt.get(t))&&void 0!==e?e:t}$setStyles(t){return Object.keys(t).forEach((e=>{let s=t[e];j(s)&&(s=0!==s&<.test(e)?`${s}px`:String(s)),this.style[e]=s})),this}$getShadowRoot(){return this.shadowRoot||ut.get(this)}$addStyles(t){let e;const s=this.$getShadowRoot();return gt?(e=new CSSStyleSheet,e.replaceSync(t),s.adoptedStyleSheets=s.adoptedStyleSheets.concat(e)):(e=document.createElement("style"),e.textContent=t,s.appendChild(e)),e}$emit(t,e,s){return function(t,e,s,i){return t.dispatchEvent(new CustomEvent(e,Object.assign(Object.assign(Object.assign({},st),{detail:s}),i)))}(this,t,e,s)}$nextTick(t){return function(t,e){return e?it.then(t?e.bind(t):e):it}(this,t)}static $define(t,i){H(t)&&(i=t,t=""),t||(t=this.$name||this.name),t=G(t),e&&s.customElements&&!s.customElements.get(t)&&customElements.define(t,this,i)}}mt.$version="2.0.0-beta.3";class bt extends mt{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-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=v,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.disabled||this.$unbind(),super.disconnectedCallback()}$propertyChangedCallback(t,e,s){if(!Object.is(s,e)&&(super.$propertyChangedCallback(t,e,s),"disabled"===t))s?this.$unbind():this.$bind()}$bind(){this.$onPointerDown||(this.$onPointerDown=this.$handlePointerDown.bind(this),tt(this,T,this.$onPointerDown)),this.$onPointerMove||(this.$onPointerMove=this.$handlePointerMove.bind(this),tt(this.ownerDocument,M,this.$onPointerMove)),this.$onPointerUp||(this.$onPointerUp=this.$handlePointerUp.bind(this),tt(this.ownerDocument,z,this.$onPointerUp)),this.$onWheel||(this.$onWheel=this.$handleWheel.bind(this),tt(this,O,this.$onWheel,{passive:!1,capture:!0}))}$unbind(){this.$onPointerDown&&(Q(this,T,this.$onPointerDown),this.$onPointerDown=null),this.$onPointerMove&&(Q(this.ownerDocument,M,this.$onPointerMove),this.$onPointerMove=null),this.$onPointerUp&&(Q(this.ownerDocument,z,this.$onPointerUp),this.$onPointerUp=null),this.$onWheel&&(Q(this,O,this.$onWheel,{capture:!0}),this.$onWheel=null)}$handlePointerDown(t){const{buttons:e,button:s,type:i}=t;if(this.disabled||("pointerdown"===i&&"mouse"===t.pointerType||"mousedown"===i)&&(j(e)&&1!==e||j(s)&&0!==s||t.ctrlKey))return;const{$pointers:n}=this;let a="";if(t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:s})=>{n.set(t,{startX:e,startY:s,endX:e,endY:s})}));else{const{pointerId:e=0,pageX:s,pageY:i}=t;n.set(e,{startX:s,startY:i,endX:s,endY:i})}n.size>1?a=f:F(t.target)&&(a=t.target.action||t.target.getAttribute("action")||""),!1!==this.$emit(X,{action:a,relatedEvent:t})&&(t.preventDefault(),this.$action=a,this.style.willChange="transform")}$handlePointerMove(t){const{$action:e,$pointers:s}=this;if(this.disabled||e===v||0===s.size)return;if(!1===this.$emit("actionmove",{action:e,relatedEvent:t}))return;if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t,pageX:e,pageY:i})=>{const n=s.get(t);n&&Object.assign(n,{endX:e,endY:i})}));else{const{pointerId:e=0,pageX:i,pageY:n}=t,a=s.get(e);a&&Object.assign(a,{endX:i,endY:n})}const i={action:e,relatedEvent:t};if(e===f){const e=new Map(s);let n=0,a=0,o=0,r=0,h=t.pageX,c=t.pageY;s.forEach(((t,s)=>{e.delete(s),e.forEach((e=>{let s=e.startX-t.startX,i=e.startY-t.startY,l=e.endX-t.endX,d=e.endY-t.endY,u=0,$=0,p=0,g=0;if(0===s?i<0?p=2*Math.PI:i>0&&(p=Math.PI):s>0?p=Math.PI/2+Math.atan(i/s):s<0&&(p=1.5*Math.PI+Math.atan(i/s)),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 s=g-p,i=Math.abs(s);i>n&&(n=i,o=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}if(s=Math.abs(s),i=Math.abs(i),l=Math.abs(l),d=Math.abs(d),s>0&&i>0?u=Math.sqrt(s*s+i*i):s>0?u=s:i>0&&(u=i),l>0&&d>0?$=Math.sqrt(l*l+d*d):l>0?$=l:d>0&&($=d),u>0&&$>0){const s=($-u)/u,i=Math.abs(s);i>a&&(a=i,r=s,h=(t.startX+e.startX)/2,c=(t.startY+e.startY)/2)}}))}));const l=n>0,d=a>0;l&&d?(i.rotate=o,i.scale=r,i.centerX=h,i.centerY=c):l?(i.action=b,i.rotate=o,i.centerX=h,i.centerY=c):d?(i.action=m,i.scale=r,i.centerX=h,i.centerY=c):i.action=v}else{const[t]=Array.from(s.values());Object.assign(i,t)}s.forEach((t=>{t.startX=t.endX,t.startY=t.endY})),i.action!==v&&this.$emit(R,i,{cancelable:!1})}$handlePointerUp(t){const{$action:e,$pointers:s}=this;if(!this.disabled&&e!==v&&!1!==this.$emit(Y,{action:e,relatedEvent:t})){if(t.preventDefault(),t.changedTouches)Array.from(t.changedTouches).forEach((({identifier:t})=>{s.delete(t)}));else{const{pointerId:e=0}=t;s.delete(e)}0===s.size&&(this.style.willChange="",this.$action=v)}}$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(R,{action:m,scale:e,relatedEvent:t},{cancelable:!1})}$setAction(t){return"string"==typeof t&&(this.$action=t),this}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let n=this.offsetWidth,a=this.offsetHeight,o=1;U(t)&&(B(t.width)||B(t.height))&&(({width:n,height:a}=ht({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.offsetWidth),i.width=n,i.height=a;const r=this.querySelector(this.$getTagNameOf(l));r?r.$ready().then((s=>{const h=i.getContext("2d");if(h){const[e,c,l,d,u,$]=r.$getTransform();let p=u,g=$,m=s.naturalWidth,b=s.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),U(t)&&q(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(f,v),h.transform(e,c,l,d,p,g),h.translate(-f,-v),h.drawImage(s,0,0,m,b),h.restore()}e(i)})).catch(s):e(i)}))}}bt.$name=o,bt.$version="2.0.0-beta.3";const ft=new WeakMap,vt=["alt","crossorigin","decoding","importance","loading","referrerpolicy","sizes","src","srcset"];class wt extends mt{constructor(){super(...arguments),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.rotatable=!0,this.scalable=!0,this.skewable=!0,this.slottable=!1,this.translatable=!0}set $canvas(t){ft.set(this,t)}get $canvas(){return ft.get(this)}static get observedAttributes(){return super.observedAttributes.concat(vt,["rotatable","scalable","skewable","translatable"])}attributeChangedCallback(t,e,s){Object.is(s,e)||(super.attributeChangedCallback(t,e,s),vt.includes(t)&&this.$image.setAttribute(t,s))}connectedCallback(){super.connectedCallback();const{$image:t}=this,e=this.closest(this.$getTagNameOf(o));e&&(this.$canvas=e,this.$setStyles({position:"absolute"}),this.$onCanvasActionStart=t=>{var e,s;this.$actionStartTarget=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target},this.$onCanvasActionEnd=()=>{this.$actionStartTarget=null},this.$onCanvasAction=this.$handleAction.bind(this),tt(e,X,this.$onCanvasActionStart),tt(e,Y,this.$onCanvasActionEnd),tt(e,R,this.$onCanvasAction)),this.$onLoad=this.$handleLoad.bind(this),tt(t,I,this.$onLoad),this.$getShadowRoot().appendChild(t)}disconnectedCallback(){const{$image:t,$canvas:e}=this;e&&(this.$onCanvasActionStart&&(Q(e,X,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(Q(e,Y,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(Q(e,R,this.$onCanvasAction),this.$onCanvasAction=null)),t&&this.$onLoad&&(Q(t,I,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("cover")}$handleAction(t){if(this.hidden||!(this.rotatable||this.scalable||this.translatable))return;const{$canvas:e}=this,{detail:s}=t;if(s){const{relatedEvent:t}=s;let{action:i}=s;switch(i!==f||this.rotatable&&this.scalable||(i=this.rotatable?b:this.scalable?m:v),i){case g:if(this.translatable){const t=this.$getTagNameOf(d);let i=e.querySelector(t);i&&i.multiple&&!i.active&&(i=e.querySelector(`${t}[active]`)),i&&!i.hidden&&i.movable&&this.$actionStartTarget&&i.contains(this.$actionStartTarget)||this.$move(s.endX-s.startX,s.endY-s.startY)}break;case b:if(this.rotatable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$rotate(s.rotate,t.clientX-e,t.clientY-i)}else this.$rotate(s.rotate);break;case m:if(this.scalable)if(t){const{x:e,y:i}=this.getBoundingClientRect();this.$zoom(s.scale,t.clientX-e,t.clientY-i)}else this.$zoom(s.scale);break;case f:if(this.rotatable&&this.scalable){const{rotate:e}=s;let{scale:i}=s;i<0?i=1/(1-i):i+=1;const n=Math.cos(e),a=Math.sin(e),[o,r,h,c]=[n*i,a*i,-a*i,n*i];if(t){const e=this.getBoundingClientRect(),s=t.clientX-e.x,i=t.clientY-e.y,[n,a,l,d]=this.$matrix,u=e.width/2,$=i-e.height/2,p=((s-u)*d-l*$)/(n*d-l*a),g=($-a*p)/d;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,s=new Promise(((t,s)=>{const i=new Error("Failed to load the image source");if(e.complete)e.naturalWidth>0&&e.naturalHeight>0?t(e):s(i);else{const n=()=>{Q(e,D,a),t(e)},a=()=>{Q(e,I,n),s(i)};et(e,I,n),et(e,D,a)}}));return q(t)&&s.then((e=>(t(e),e))),s}$center(t){const{parentElement:e}=this;if(!e)return this;const s=e.getBoundingClientRect(),i=s.width,n=s.height,{x:a,y:o,width:r,height:h}=this.getBoundingClientRect(),c=a+r/2,l=o+h/2,d=s.x+i/2,u=s.y+n/2;if(this.$move(d-c,u-l),t&&(r!==i||h!==n)){const e=i/r,s=n/h;switch(t){case"cover":this.$scale(Math.max(e,s));break;case"contain":this.$scale(Math.min(e,s))}}return this}$move(t,e=t){if(this.translatable&&j(t)&&j(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$translate(o,r)}return this}$moveTo(t,e=t){if(this.translatable&&j(t)&&j(e)){const[s,i,n,a]=this.$matrix,o=(t*a-n*e)/(s*a-n*i),r=(e-i*o)/a;this.$setTransform(s,i,n,a,o,r)}return this}$rotate(t,e,s){if(this.rotatable){const i=ot(t),n=Math.cos(i),a=Math.sin(i),[o,r,h,c]=[n,a,-a,n];if(j(e)&&j(s)){const[t,i,n,a]=this.$matrix,{width:l,height:d}=this.getBoundingClientRect(),u=s-d/2,$=((e-l/2)*a-n*u)/(t*a-n*i),p=(u-i*$)/a;this.$transform(o,r,h,c,$*(1-o)-p*h,p*(1-c)-$*r)}else this.$transform(o,r,h,c,0,0)}return this}$zoom(t,e,s){if(!this.scalable||0===t)return this;if(t<0?t=1/(1-t):t+=1,j(e)&&j(s)){const[i,n,a,o]=this.$matrix,{width:r,height:h}=this.getBoundingClientRect(),c=s-h/2,l=((e-r/2)*o-a*c)/(i*o-a*n),d=(c-n*l)/o;this.$transform(t,0,0,t,l*(1-t),d*(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 s=ot(t),i=ot(e);this.$transform(1,Math.tan(i),Math.tan(s),1,0,0)}return this}$translate(t,e=t){return this.translatable&&j(t)&&j(e)&&this.$transform(1,0,0,1,t,e),this}$transform(t,e,s,i,n,a){return j(t)&&j(e)&&j(s)&&j(i)&&j(n)&&j(a)?this.$setTransform(ct(this.$matrix,[t,e,s,i,n,a])):this}$setTransform(t,e,s,i,n,a){if((this.rotatable||this.scalable||this.skewable||this.translatable)&&(Array.isArray(t)&&([t,e,s,i,n,a]=t),j(t)&&j(e)&&j(s)&&j(i)&&j(n)&&j(a))){const o=[t,e,s,i,n,a];if(!1===this.$emit(W,{matrix:o,oldMatrix:this.$matrix}))return this;this.$matrix=o,this.style.transform=`matrix(${o.join(", ")})`}return this}$getTransform(){return this.$matrix.slice()}$resetTransform(){return this.$setTransform([1,0,0,1,0,0])}}wt.$name=l,wt.$version="2.0.0-beta.3";const Ct=new WeakMap;class yt extends mt{constructor(){super(...arguments),this.$onCanvasChange=null,this.$onCanvasActionEnd=null,this.$onCanvasActionStart=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){Ct.set(this,t)}get $canvas(){return Ct.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["height","width","x","y"])}connectedCallback(){super.connectedCallback();const t=this.closest(this.$getTagNameOf(o));if(t){this.$canvas=t,this.style.position="absolute";const e=t.querySelector(this.$getTagNameOf(d));e&&(this.$onCanvasActionStart=t=>{e.hidden&&t.detail.action===p&&(this.hidden=!1)},this.$onCanvasActionEnd=t=>{e.hidden&&t.detail.action===p&&(this.hidden=!0)},this.$onCanvasChange=t=>{const{x:s,y:i,width:n,height:a}=t.detail;this.$change(s,i,n,a),(e.hidden||0===s&&0===i&&0===n&&0===a)&&(this.hidden=!0)},tt(t,X,this.$onCanvasActionStart),tt(t,Y,this.$onCanvasActionEnd),tt(t,N,this.$onCanvasChange))}this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(Q(t,X,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(Q(t,Y,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasChange&&(Q(t,N,this.$onCanvasChange),this.$onCanvasChange=null)),super.disconnectedCallback()}$change(t,e,s=this.width,i=this.height){return j(t)&&j(e)&&j(s)&&j(i)&&(t!==this.x||e!==this.y||s!==this.width||i!==this.height)?(this.hidden&&(this.hidden=!1),this.x=t,this.y=e,this.width=s,this.height=i,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:s.innerWidth})}}yt.$name=u,yt.$version="2.0.0-beta.3";class St extends mt{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=v,this.plain=!1,this.slottable=!1,this.themeColor="rgba(51, 153, 255, 0.5)"}static get observedAttributes(){return super.observedAttributes.concat(["action","plain"])}}St.$name=c,St.$version="2.0.0-beta.3";const kt=new WeakMap;class xt extends mt{constructor(){super(...arguments),this.$onCanvasAction=null,this.$onCanvasActionStart=null,this.$onCanvasActionEnd=null,this.$onDocumentKeyDown=null,this.$actionStartTarget=null,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.x=0,this.y=0,this.width=0,this.height=0,this.aspectRatio=NaN,this.initialAspectRatio=NaN,this.initialCoverage=NaN,this.active=!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){kt.set(this,t)}get $canvas(){return kt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["active","aspect-ratio","height","initial-aspect-ratio","initial-coverage","keyboard","movable","multiple","outlined","precise","resizable","width","x","y","zoomable"])}$propertyChangedCallback(t,e,s){if(!Object.is(s,e))switch(super.$propertyChangedCallback(t,e,s),t){case"aspectRatio":B(s)||(this.aspectRatio=NaN);break;case"initialAspectRatio":B(s)||(this.initialAspectRatio=NaN);break;case"initialCoverage":(!B(s)||s>1)&&(this.initialCoverage=NaN);break;case"keyboard":this.$nextTick((()=>{this.$canvas&&(s?this.$onDocumentKeyDown||(this.$onDocumentKeyDown=this.$handleKeyDown.bind(this),tt(this.ownerDocument,P,this.$onDocumentKeyDown)):this.$onDocumentKeyDown&&(Q(this.ownerDocument,P,this.$onDocumentKeyDown),this.$onDocumentKeyDown=null))}));break;case"multiple":this.$nextTick((()=>{this.$canvas&&(s?this.active=!0:(this.$getSelections().forEach(((t,e)=>{e>0&&this.$removeSelection(t)})),this.active=!1))}))}}connectedCallback(){super.connectedCallback(),this.multiple&&!this.active&&(this.active=!0);const t=this.closest(this.$getTagNameOf(o));if(t){this.$canvas=t,this.$setStyles({position:"absolute",transform:`translate(${this.x}px, ${this.y}px)`}),this.hidden||this.$render();const{initialCoverage:e,parentElement:s}=this;if(B(e)&&s){const t=this.aspectRatio||this.initialAspectRatio,{offsetWidth:i,offsetHeight:n}=s;let a=i*e,o=n*e;B(t)&&({width:a,height:o}=ht({aspectRatio:t,width:a,height:o})),this.$change(this.x,this.y,a,o),this.$center()}this.$onCanvasActionStart=this.$handleActionStart.bind(this),this.$onCanvasActionEnd=this.$handleActionEnd.bind(this),this.$onCanvasAction=this.$handleAction.bind(this),tt(t,X,this.$onCanvasActionStart),tt(t,Y,this.$onCanvasActionStart),tt(t,R,this.$onCanvasAction)}else this.$render()}disconnectedCallback(){const{$canvas:t}=this;t&&(this.$onCanvasActionStart&&(Q(t,X,this.$onCanvasActionStart),this.$onCanvasActionStart=null),this.$onCanvasActionEnd&&(Q(t,Y,this.$onCanvasActionEnd),this.$onCanvasActionEnd=null),this.$onCanvasAction&&(Q(t,R,this.$onCanvasAction),this.$onCanvasAction=null)),super.disconnectedCallback()}$getSelections(){let t=[];return this.parentElement&&(t=Array.from(this.parentElement.querySelectorAll(this.$getTagNameOf(d)))),t}$createSelection(){const t=this.cloneNode(!0);return this.hasAttribute("id")&&t.removeAttribute("id"),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 s=e.indexOf(t),i=e[s+1]||e[s-1];i&&(t.active=!1,this.parentElement.removeChild(t),i.active=!0,i.$emit(N,{x:i.x,y:i.y,width:i.width,height:i.height}))}else this.$reset(),this.hidden=!0}}$handleActionStart(t){var e,s;const i=null===(s=null===(e=t.detail)||void 0===e?void 0:e.relatedEvent)||void 0===s?void 0:s.target;this.$actionStartTarget=i,!this.hidden&&this.multiple&&!this.active&&i===this&&this.parentElement&&(this.$getSelections().forEach((t=>{t.active=!1})),this.active=!0,this.$emit(N,{x:this.x,y:this.y,width:this.width,height:this.height}))}$handleAction(t){if(this.multiple&&!this.active)return;const{currentTarget:e,detail:s}=t;if(e&&s){const{relatedEvent:i}=s;let{action:n}=s;if(!n&&this.multiple&&(n=null==i?void 0:i.target.action),!n||this.hidden&&n!==p)return;const a=s.endX-s.startX,o=s.endY-s.startY,{width:r,height:h}=this;let{aspectRatio:c}=this;switch(!B(c)&&t.shiftKey&&(c=B(r)&&B(h)?r/h:1),n){case p:{const{$canvas:t}=this,i=nt(e);(this.multiple&&!this.hidden?this.$createSelection():this).$change(s.startX-i.left,s.startY-i.top,a,o,c),n=A,a<0?o>0?n=E:o<0&&(n=x):a>0&&o<0&&(n=k),t&&(t.$action=n);break}case g:this.movable&&this.$actionStartTarget&&this.contains(this.$actionStartTarget)&&this.$move(a,o);break;case m:if(i&&this.zoomable){const t=nt(e);this.$zoom(s.scale,i.pageX-t.left,i.pageY-t.top)}break;default:this.$resize(n,a,o,c)}}}$handleActionEnd(){this.$actionStartTarget=null}$handleKeyDown(t){if(!(this.hidden||!this.keyboard||this.multiple&&!this.active||t.defaultPrevented))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,s=(t.offsetHeight-this.height)/2;return this.$change(e,s)}$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,s=0,i=this.aspectRatio){if(!this.resizable)return this;const n=B(i),{$canvas:a}=this;let{x:o,y:r,width:h,height:c}=this;switch(t){case w:r+=s,c-=s,c<0&&(t=y,c=-c,r-=c),n&&(o+=(e=s*i)/2,h-=e,h<0&&(h=-h,o-=h));break;case C:h+=e,h<0&&(t=S,h=-h,o-=h),n&&(r-=(s=e/i)/2,c+=s,c<0&&(c=-c,r-=c));break;case y:c+=s,c<0&&(t=w,c=-c,r-=c),n&&(o-=(e=s*i)/2,h+=e,h<0&&(h=-h,o-=h));break;case S:o+=e,h-=e,h<0&&(t=C,h=-h,o-=h),n&&(r+=(s=e/i)/2,c-=s,c<0&&(c=-c,r-=c));break;case k:n&&(s=-e/i),r+=s,c-=s,h+=e,h<0&&c<0?(t=E,h=-h,c=-c,o-=h,r-=c):h<0?(t=x,h=-h,o-=h):c<0&&(t=A,c=-c,r-=c);break;case x:n&&(s=e/i),o+=e,r+=s,h-=e,c-=s,h<0&&c<0?(t=A,h=-h,c=-c,o-=h,r-=c):h<0?(t=k,h=-h,o-=h):c<0&&(t=E,c=-c,r-=c);break;case A:n&&(s=e/i),h+=e,c+=s,h<0&&c<0?(t=x,h=-h,c=-c,o-=h,r-=c):h<0?(t=E,h=-h,o-=h):c<0&&(t=k,c=-c,r-=c);break;case E:n&&(s=-e/i),o+=e,h-=e,c+=s,h<0&&c<0?(t=k,h=-h,c=-c,o-=h,r-=c):h<0?(t=A,h=-h,o-=h):c<0&&(t=x,c=-c,r-=c)}return a&&a.$setAction(t),this.$change(o,r,h,c)}$zoom(t,e,s){if(!this.zoomable||0===t)return this;t<0?t=1/(1-t):t+=1;const{width:i,height:n}=this,a=i*t,o=n*t;let r=this.x,h=this.y;return j(e)&&j(s)?(r-=(a-i)*((e-this.x)/i),h-=(o-n)*((s-this.y)/n)):(r-=(a-i)/2,h-=(o-n)/2),this.$change(r,h,a,o)}$change(t,e,s=this.width,i=this.height,n=this.aspectRatio){return j(t)&&j(e)&&j(s)&&j(i)?(this.precise||(t=Math.round(t),e=Math.round(e),s=Math.round(s),i=Math.round(i)),t===this.x&&e===this.y&&s===this.width&&i===this.height?this:(this.hidden&&(this.hidden=!1),B(n)&&({width:s,height:i}=ht({aspectRatio:n,width:s,height:i},"cover")),!1===this.$emit(N,{x:t,y:e,width:s,height:i})?this:(this.x=t,this.y=e,this.width=s,this.height=i,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})}$toCanvas(t){return new Promise(((e,s)=>{if(!this.isConnected)return void s(new Error("The current element is not connected to the DOM."));const i=document.createElement("canvas");let{width:n,height:a}=this,o=1;if(U(t)&&(B(t.width)||B(t.height))&&(({width:n,height:a}=ht({aspectRatio:n/a,width:t.width,height:t.height})),o=n/this.width),i.width=n,i.height=a,!this.$canvas)return void e(i);const r=this.$canvas.querySelector(this.$getTagNameOf(l));r?r.$ready().then((s=>{const h=i.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-c*m)/d;let f=e*m+l*b+u,v=c*m+d*b+$,w=s.naturalWidth,C=s.naturalHeight;1!==o&&(f*=o,v*=o,w*=o,C*=o);const y=w/2,S=C/2;h.fillStyle="transparent",h.fillRect(0,0,n,a),U(t)&&q(t.beforeDraw)&&t.beforeDraw.call(this,h,i),h.save(),h.translate(y,S),h.transform(e,c,l,d,f,v),h.translate(-y,-S),h.drawImage(s,0,0,w,C),h.restore()}e(i)})).catch(s):e(i)}))}}xt.$name=d,xt.$version="2.0.0-beta.3";class At extends mt{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,s){Object.is(s,e)||(super.$propertyChangedCallback(t,e,s),"rows"!==t&&"columns"!==t||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("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.innerHTML="",t.appendChild(e))}}At.$name=h,At.$version="2.0.0-beta.3";class Et extends mt{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"])}}Et.$name=r,Et.$version="2.0.0-beta.3";const Tt=new WeakMap,Mt=new WeakMap,zt=new WeakMap,Dt="vertical";class Pt extends mt{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=Dt,this.selection="",this.slottable=!1}set $image(t){Tt.set(this,t)}get $image(){return Tt.get(this)}set $sourceImage(t){zt.set(this,t)}get $sourceImage(){return zt.get(this)}set $selection(t){Mt.set(this,t)}get $selection(){return Mt.get(this)}static get observedAttributes(){return super.observedAttributes.concat(["resize","selection"])}connectedCallback(){super.connectedCallback();let t=null;if(t=this.selection?this.ownerDocument.querySelector(this.selection):this.closest(this.$getTagNameOf(d)),F(t)){this.$selection=t,this.$onSelectionChange=this.$handleSelectionChange.bind(this),tt(t,N,this.$onSelectionChange);const e=t.closest(this.$getTagNameOf(o));if(e){const t=e.querySelector(this.$getTagNameOf(l));t&&(this.$sourceImage=t,this.$image=t.cloneNode(!0),this.$getShadowRoot().appendChild(this.$image),this.$onSourceImageLoad=this.$handleSourceImageLoad.bind(this),this.$onSourceImageTransform=this.$handleSourceImageTransform.bind(this),tt(t.$image,I,this.$onSourceImageLoad),tt(t,W,this.$onSourceImageTransform))}this.$render()}}disconnectedCallback(){const{$selection:t,$sourceImage:e}=this;t&&this.$onSelectionChange&&(Q(t,N,this.$onSelectionChange),this.$onSelectionChange=null),e&&this.$onSourceImageLoad&&(Q(e.$image,I,this.$onSourceImageLoad),this.$onSourceImageLoad=null),e&&this.$onSourceImageTransform&&(Q(e,W,this.$onSourceImageTransform),this.$onSourceImageTransform=null),super.disconnectedCallback()}$handleSelectionChange(t){this.$render(t.detail)}$handleSourceImageLoad(){const{$image:t,$sourceImage:e}=this,s=t.getAttribute("src"),i=e.getAttribute("src");i&&i!==s&&(t.setAttribute("src",i),t.$ready((()=>{setTimeout((()=>{const{x:t,y:s}=this.$selection;this.$transformImageByOffset(e.$getTransform(),-t,-s)}))})))}$handleSourceImageTransform(t){const{x:e,y:s}=this.$selection;this.$transformImageByOffset(t.detail.matrix,-e,-s)}$render(t){const{x:e,y:s,width:i,height:n}=t||this.$selection,a={},{clientWidth:o,clientHeight:r}=this;let h=o,c=r,l=NaN;switch(this.resize){case"both":l=1,h=i,c=n,a.width=i,a.height=n;break;case"horizontal":l=r/n,h=i*l,a.width=h;break;case Dt:l=o/i,c=n*l,a.height=c;break;default:o>0?l=o/i:r>0&&(l=r/n)}this.$scale=l,this.$setStyles(a),this.$sourceImage&&this.$transformImageByOffset(this.$sourceImage.$getTransform(),-e,-s)}$transformImageByOffset(t,e,s){const{$image:i,$scale:n,$sourceImage:a}=this;if(a&&i&&n>0){const[a,o,r,h,c,l]=t,d=(e*h-r*s)/(a*h-r*o),u=(s-o*d)/h,$=a*d+r*u+c,p=o*d+h*u+l;i.$ready((t=>{this.$setStyles.call(i,{width:t.naturalWidth*n,height:t.naturalHeight*n})})),i.$setTransform(a,o,r,h,$*n,p*n)}}}Pt.$name=$,Pt.$version="2.0.0-beta.3",t.CropperCanvas=bt,t.CropperCrosshair=Et,t.CropperElement=mt,t.CropperGrid=At,t.CropperHandle=St,t.CropperImage=wt,t.CropperSelection=xt,t.CropperShade=yt,t.CropperViewer=Pt,Object.defineProperty(t,"__esModule",{value:!0})})); |
+11
-11
| { | ||
| "name": "@cropper/elements", | ||
| "version": "2.0.0-beta.2", | ||
| "version": "2.0.0-beta.3", | ||
| "description": "A series of custom elements for the Cropper.", | ||
@@ -36,11 +36,11 @@ "main": "dist/elements.raw.js", | ||
| "dependencies": { | ||
| "@cropper/element": "^2.0.0-beta.2", | ||
| "@cropper/element-canvas": "^2.0.0-beta.2", | ||
| "@cropper/element-crosshair": "^2.0.0-beta.2", | ||
| "@cropper/element-grid": "^2.0.0-beta.2", | ||
| "@cropper/element-handle": "^2.0.0-beta.2", | ||
| "@cropper/element-image": "^2.0.0-beta.2", | ||
| "@cropper/element-selection": "^2.0.0-beta.2", | ||
| "@cropper/element-shade": "^2.0.0-beta.2", | ||
| "@cropper/element-viewer": "^2.0.0-beta.2" | ||
| "@cropper/element": "^2.0.0-beta.3", | ||
| "@cropper/element-canvas": "^2.0.0-beta.3", | ||
| "@cropper/element-crosshair": "^2.0.0-beta.3", | ||
| "@cropper/element-grid": "^2.0.0-beta.3", | ||
| "@cropper/element-handle": "^2.0.0-beta.3", | ||
| "@cropper/element-image": "^2.0.0-beta.3", | ||
| "@cropper/element-selection": "^2.0.0-beta.3", | ||
| "@cropper/element-shade": "^2.0.0-beta.3", | ||
| "@cropper/element-viewer": "^2.0.0-beta.3" | ||
| }, | ||
@@ -51,3 +51,3 @@ "publishConfig": { | ||
| }, | ||
| "gitHead": "78de561af17e39b47626c419c756bfe43a45c808" | ||
| "gitHead": "3bbcba410e0781b5dee18ba8ae150f1a1ea51c50" | ||
| } |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
Long strings
Supply chain riskContains long string literals, which may be a sign of obfuscated or packed code.
Found 1 instance in 1 package
370374
-0.58%7290
-3.17%