@annotorious/annotorious 3.4.0 → 3.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,3 @@
1
- (function(k,z){typeof exports=="object"&&typeof module<"u"?z(exports):typeof define=="function"&&define.amd?define(["exports"],z):(k=typeof globalThis<"u"?globalThis:k||self,z(k.Annotorious={}))})(this,function(k){"use strict";var Yr=Object.defineProperty;var Xr=(k,z,ke)=>z in k?Yr(k,z,{enumerable:!0,configurable:!0,writable:!0,value:ke}):k[z]=ke;var ne=(k,z,ke)=>Xr(k,typeof z!="symbol"?z+"":z,ke);function z(){}function ke(e,t){for(const n in t)e[n]=t[n];return e}function ln(e){return e()}function an(){return Object.create(null)}function Ce(e){e.forEach(ln)}function ie(e){return typeof e=="function"}function ae(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Wi(e){return Object.keys(e).length===0}function un(e,...t){if(e==null){for(const i of t)i(void 0);return z}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function Rt(e,t,n){e.$$.on_destroy.push(un(t,n))}function Ki(e,t,n,i){if(e){const o=fn(e,t,n,i);return e[0](o)}}function fn(e,t,n,i){return e[1]&&i?ke(n.ctx.slice(),e[1](i(t))):n.ctx}function Ji(e,t,n,i){if(e[2]&&i){const o=e[2](i(n));if(t.dirty===void 0)return o;if(typeof o=="object"){const s=[],r=Math.max(t.dirty.length,o.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|o[a];return s}return t.dirty|o}return t.dirty}function xi(e,t,n,i,o,s){if(o){const r=fn(t,n,i,s);e.p(r,o)}}function $i(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let i=0;i<n;i++)t[i]=-1;return t}return-1}function cn(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function gt(e){return e??""}function Z(e,t){e.appendChild(t)}function P(e,t,n){e.insertBefore(t,n||null)}function D(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function L(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function hn(e){return document.createTextNode(e)}function be(){return hn(" ")}function Te(){return hn("")}function $(e,t,n,i){return e.addEventListener(t,n,i),()=>e.removeEventListener(t,n,i)}function f(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function eo(e){return Array.from(e.childNodes)}function De(e,t,n){e.classList.toggle(t,!!n)}function to(e,t,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:i})}let nt;function it(e){nt=e}function dn(){if(!nt)throw new Error("Function called outside component initialization");return nt}function ze(e){dn().$$.on_mount.push(e)}function Xe(){const e=dn();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const s=to(t,n,{cancelable:i});return o.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function Ae(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Qe=[],ot=[];let qe=[];const gn=[],pn=Promise.resolve();let It=!1;function yn(){It||(It=!0,pn.then(_n))}function no(){return yn(),pn}function Lt(e){qe.push(e)}const kt=new Set;let Ze=0;function _n(){if(Ze!==0)return;const e=nt;do{try{for(;Ze<Qe.length;){const t=Qe[Ze];Ze++,it(t),io(t.$$)}}catch(t){throw Qe.length=0,Ze=0,t}for(it(null),Qe.length=0,Ze=0;ot.length;)ot.pop()();for(let t=0;t<qe.length;t+=1){const n=qe[t];kt.has(n)||(kt.add(n),n())}qe.length=0}while(Qe.length);for(;gn.length;)gn.pop()();It=!1,kt.clear(),it(e)}function io(e){if(e.fragment!==null){e.update(),Ce(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Lt)}}function oo(e){const t=[],n=[];qe.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),qe=t}const pt=new Set;let Fe;function ye(){Fe={r:0,c:[],p:Fe}}function _e(){Fe.r||Ce(Fe.c),Fe=Fe.p}function V(e,t){e&&e.i&&(pt.delete(e),e.i(t))}function G(e,t,n,i){if(e&&e.o){if(pt.has(e))return;pt.add(e),Fe.c.push(()=>{pt.delete(e),i&&(n&&e.d(1),i())}),e.o(t)}else i&&i()}function Oe(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function pe(e){e&&e.c()}function fe(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),Lt(()=>{const s=e.$$.on_mount.map(ln).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ce(s),e.$$.on_mount=[]}),o.forEach(Lt)}function ce(e,t){const n=e.$$;n.fragment!==null&&(oo(n.after_update),Ce(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function so(e,t){e.$$.dirty[0]===-1&&(Qe.push(e),yn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function me(e,t,n,i,o,s,r=null,a=[-1]){const l=nt;it(e);const u=e.$$={fragment:null,ctx:[],props:s,update:z,not_equal:o,bound:an(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:an(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(u.root);let h=!1;if(u.ctx=n?n(e,t.props||{},(c,d,...y)=>{const g=y.length?y[0]:d;return u.ctx&&o(u.ctx[c],u.ctx[c]=g)&&(!u.skip_bound&&u.bound[c]&&u.bound[c](g),h&&so(e,c)),d}):[],u.update(),h=!0,Ce(u.before_update),u.fragment=i?i(u.ctx):!1,t.target){if(t.hydrate){const c=eo(t.target);u.fragment&&u.fragment.l(c),c.forEach(D)}else u.fragment&&u.fragment.c();t.intro&&V(e.$$.fragment),fe(e,t.target,t.anchor),_n()}it(l)}class we{constructor(){ne(this,"$$");ne(this,"$$set")}$destroy(){ce(this,1),this.$destroy=z}$on(t,n){if(!ie(n))return z;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(n),()=>{const o=i.indexOf(n);o!==-1&&i.splice(o,1)}}$set(t){this.$$set&&!Wi(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ro="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ro);var ee=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(ee||{});const Dt={},st=(e,t)=>Dt[e]=t,yt=e=>Dt[e.type].area(e),mn=(e,t,n)=>Dt[e.type].intersects(e,t,n),Se=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),i=Math.max(i,s),o=Math.max(o,r)}),{minX:t,minY:n,maxX:i,maxY:o}},_t=e=>{let t=0,n=e.length-1;for(let i=0;i<e.length;i++)t+=(e[n][0]+e[i][0])*(e[n][1]-e[i][1]),n=i;return Math.abs(.5*t)},mt=(e,t,n)=>{let i=!1;for(let o=0,s=e.length-1;o<e.length;s=o++){const r=e[o][0],a=e[o][1],l=e[s][0],u=e[s][1];a>n!=u>n&&t<(l-r)*(n-a)/(u-a)+r&&(i=!i)}return i},wn=(e,t=!0)=>{let n="M ";return e.forEach(([i,o],s)=>{s===0?n+=`${i},${o}`:n+=` L ${i},${o}`}),t&&(n+=" Z"),n},lo={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:i,cy:o,rx:s,ry:r}=e.geometry,a=0,l=Math.cos(a),u=Math.sin(a),h=t-i,c=n-o,d=l*h+u*c,y=u*h-l*c;return d*d/(s*s)+y*y/(r*r)<=1}};st(ee.ELLIPSE,lo);const ao={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...s]=i.rings,r=_t(o.points),a=s.reduce((l,u)=>l+_t(u.points),0);return n+r-a},0)},intersects:(e,t,n)=>{const{polygons:i}=e.geometry;for(const o of i){const[s,...r]=o.rings;if(mt(s.points,t,n)){let a=!1;for(const l of r)if(mt(l.points,t,n)){a=!0;break}if(!a)return!0}}return!1}},En=e=>{const t=e.reduce((n,i)=>[...n,...i.rings[0].points],[]);return Se(t)},Le=e=>e.rings.map(n=>wn(n.points)).join(" ");st(ee.MULTIPOLYGLON,ao);const uo={area:e=>{const t=e.geometry.points;return _t(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return mt(i,t,n)}};st(ee.POLYGON,uo);const bn={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};st(ee.RECTANGLE,bn);const rt=e=>lt(e.target),lt=e=>{var t,n;return(e==null?void 0:e.annotation)!==void 0&&((n=(t=e==null?void 0:e.selector)==null?void 0:t.geometry)==null?void 0:n.bounds)!==void 0},Tn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,o=[...n.matchAll(i)][0],[s,r,a,l,u,h,c]=o;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,y,g,p]=[l,u,h,c].map(parseFloat);return{type:ee.RECTANGLE,geometry:{x:d,y,w:g,h:p,bounds:{minX:d,minY:t?y-p:y,maxX:d+g,maxY:t?y:y+p}}}},An=e=>{const{x:t,y:n,w:i,h:o}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${i},${o}`}},On="http://www.w3.org/2000/svg",Mn=e=>{const t=i=>{Array.from(i.attributes).forEach(o=>{o.name.startsWith("on")&&i.removeAttribute(o.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(e.querySelectorAll("*")).forEach(t),e},fo=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${On}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},vn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(On),o=n.lookupNamespaceURI(null);return i||o?Mn(n).firstChild:Mn(fo(n)).firstChild},oe=" ";function co(e){let t="";Array.isArray(e)||(e=[e]);for(let n=0;n<e.length;n++){const i=e[n];if(i.type===T.CLOSE_PATH)t+="z";else if(i.type===T.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===T.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===T.MOVE_TO)t+=(i.relative?"m":"M")+i.x+oe+i.y;else if(i.type===T.LINE_TO)t+=(i.relative?"l":"L")+i.x+oe+i.y;else if(i.type===T.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+oe+i.y1+oe+i.x2+oe+i.y2+oe+i.x+oe+i.y;else if(i.type===T.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+oe+i.y2+oe+i.x+oe+i.y;else if(i.type===T.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+oe+i.y1+oe+i.x+oe+i.y;else if(i.type===T.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+oe+i.y;else if(i.type===T.ARC)t+=(i.relative?"a":"A")+i.rX+oe+i.rY+oe+i.xRot+oe+ +i.lArcFlag+oe+ +i.sweepFlag+oe+i.x+oe+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Pt([e,t],n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Re(...e){for(let t=0;t<e.length;t++)if(typeof e[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof e[t]} == typeof ${e[t]}`);return!0}const Pe=Math.PI;function Ut(e,t,n){e.lArcFlag=e.lArcFlag===0?0:1,e.sweepFlag=e.sweepFlag===0?0:1;let{rX:i,rY:o}=e;const{x:s,y:r}=e;if(Math.abs(i)<1e-10||Math.abs(o)<1e-10){e.rX=0,e.rY=0,e.cX=(t+s)/2,e.cY=(n+r)/2,e.phi1=0,e.phi2=0;return}i=Math.abs(e.rX),o=Math.abs(e.rY);const a=e.xRot/180*Pe,[l,u]=Pt([(t-s)/2,(n-r)/2],-a),h=Math.pow(l,2)/Math.pow(i,2)+Math.pow(u,2)/Math.pow(o,2);1<h&&(i*=Math.sqrt(h),o*=Math.sqrt(h)),e.rX=i,e.rY=o;const c=Math.pow(i,2)*Math.pow(u,2)+Math.pow(o,2)*Math.pow(l,2),d=(e.lArcFlag!==e.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(o,2)-c)/c)),y=i*u/o*d,g=-o*l/i*d,p=Pt([y,g],a);e.cX=p[0]+(t+s)/2,e.cY=p[1]+(n+r)/2,e.phi1=Math.atan2((u-g)/o,(l-y)/i),e.phi2=Math.atan2((-u-g)/o,(-l-y)/i),e.sweepFlag===0&&e.phi2>e.phi1&&(e.phi2-=2*Pe),e.sweepFlag===1&&e.phi2<e.phi1&&(e.phi2+=2*Pe),e.phi1*=180/Pe,e.phi2*=180/Pe}function Sn(e,t,n){Re(e,t,n);const i=e*e+t*t-n*n;if(0>i)return[];if(i===0)return[[e*n/(e*e+t*t),t*n/(e*e+t*t)]];const o=Math.sqrt(i);return[[(e*n+t*o)/(e*e+t*t),(t*n-e*o)/(e*e+t*t)],[(e*n-t*o)/(e*e+t*t),(t*n+e*o)/(e*e+t*t)]]}const Ge=Math.PI/180;function Nn(e,t,n){return(1-n)*e+n*t}function Cn(e,t,n,i){return e+Math.cos(i/180*Pe)*t+Math.sin(i/180*Pe)*n}function Rn(e,t,n,i){const s=t-e,r=n-t,a=i-n,l=3*s+3*a-6*r,u=(r-s)*6,h=3*s;return Math.abs(l)<1e-6?Math.abs(u)<1e-6?[]:[-h/u]:ho(u/l,h/l,1e-6)}function In(e,t,n,i,o){const s=1-o,r=s*s*s,a=3*s*s*o,l=3*s*o*o,u=o*o*o;return e*r+t*a+n*l+i*u}function ho(e,t,n=1e-6){const i=e*e/4-t;if(i<-n)return[];if(i<=n)return[-e/2];const o=Math.sqrt(i);return[-(e/2)-o,-(e/2)+o]}function go(e,t,n){e.cX||Ut(e,t,n);const i=e.xRot/180*Pe;if(Math.abs(e.rX)<1e-10||Math.abs(e.rY)<1e-10)return[{relative:e.relative,type:T.CURVE_TO,x1:t+(e.x-t)/3,y1:n+(e.y-n)/3,x2:t+2*(e.x-t)/3,y2:n+2*(e.y-n)/3,x:e.x,y:e.y}];const o=Math.min(e.phi1,e.phi2),s=Math.max(e.phi1,e.phi2),r=s-o,a=Math.ceil(r/90),l=new Array(a);let u=t,h=n;const c=(d,y)=>{const[g,p]=Pt([d*e.rX,y*e.rY],i);return[e.cX+g,e.cY+p]};for(let d=0;d<a;d++){const y=Nn(e.phi1,e.phi2,d/a),g=Nn(e.phi1,e.phi2,(d+1)/a),p=g-y,w=4/3*Math.tan(p*Ge/4),m=Math.cos(y*Ge)-w*Math.sin(y*Ge),A=Math.sin(y*Ge)+w*Math.cos(y*Ge),E=Math.cos(g*Ge),M=Math.sin(g*Ge),S=E+w*M,v=M-w*E,N=c(m,A),H=c(S,v),B=c(E,M),X={relative:e.relative,type:T.CURVE_TO,x:B[0],y:B[1],x1:N[0],y1:N[1],x2:H[0],y2:H[1]};e.relative&&(X.x1-=u,X.y1-=h,X.x2-=u,X.y2-=h,X.x-=u,X.y-=h),u=B[0],h=B[1],l[d]=X}return l}function Vt(e,t,n){const i=t[0]-e[0],o=t[1]-e[1],s=n[0]-e[0],r=n[1]-e[1],a=i*r-o*s;if(!(Math.abs(a)<1e-10))return!1;const u=i*s+o*r,h=i*i+o*o,c=s*s+r*r;return 0<=u&&u<=c&&h<=c}function po(e,t=!0){if(e.length<2)return e;const n=se.INFO((s,r,a)=>({...s,x:s.x??r,y:s.y??a,relative:s.relative??!1})),i=[];let o=[];for(const s of e){const r=n(s);r.type===T.MOVE_TO&&o.length>0&&(t?i.push(...wt(o)):i.unshift(...wt(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...wt(o)):i.unshift(...wt(o))),i}function wt(e){var o;const t=((o=e[e.length-1])==null?void 0:o.type)===T.CLOSE_PATH,n=t?e.length-2:e.length-1,i=[{type:T.MOVE_TO,relative:!1,x:e[n].x,y:e[n].y}];for(let s=n;s>0;s--){const r=e[s],a=e[s-1];if(r.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(r.type){case T.HORIZ_LINE_TO:i.push({type:T.HORIZ_LINE_TO,relative:!1,x:a.x});break;case T.VERT_LINE_TO:i.push({type:T.VERT_LINE_TO,relative:!1,y:a.y});break;case T.LINE_TO:case T.MOVE_TO:i.push({type:T.LINE_TO,relative:!1,x:a.x,y:a.y});break;case T.CURVE_TO:i.push({type:T.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case T.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case T.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case T.ARC:throw new Error("Unsupported command: A (arc)");case T.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:T.CLOSE_PATH}),i}function yo(e=1e13){Re(e);function t(n){return Math.round(n*e)/e}return function(i){return"x1"in i&&typeof i.x1<"u"&&(i.x1=t(i.x1)),"y1"in i&&typeof i.y1<"u"&&(i.y1=t(i.y1)),"x2"in i&&typeof i.x2<"u"&&(i.x2=t(i.x2)),"y2"in i&&typeof i.y2<"u"&&(i.y2=t(i.y2)),"x"in i&&typeof i.x<"u"&&(i.x=t(i.x)),"y"in i&&typeof i.y<"u"&&(i.y=t(i.y)),"rX"in i&&typeof i.rX<"u"&&(i.rX=t(i.rX)),"rY"in i&&typeof i.rY<"u"&&(i.rY=t(i.rY)),i}}function Ln(){return Ie((e,t,n)=>(e.relative&&(typeof e.x1<"u"&&(e.x1+=t),typeof e.y1<"u"&&(e.y1+=n),typeof e.x2<"u"&&(e.x2+=t),typeof e.y2<"u"&&(e.y2+=n),typeof e.x<"u"&&(e.x+=t),typeof e.y<"u"&&(e.y+=n),e.relative=!1),e))}function _o(){return Ie((e,t,n)=>(e.relative||(typeof e.x1<"u"&&(e.x1-=t),typeof e.y1<"u"&&(e.y1-=n),typeof e.x2<"u"&&(e.x2-=t),typeof e.y2<"u"&&(e.y2-=n),typeof e.x<"u"&&(e.x-=t),typeof e.y<"u"&&(e.y-=n),e.relative=!0),e))}function mo(e=!0,t=!0,n=!0,i=!0){return Ie((o,s,r,a,l)=>{if(isNaN(a)&&!(o.type&T.MOVE_TO))throw new Error("path must start with moveto");if(t&&o.type&T.HORIZ_LINE_TO&&(o.type=T.LINE_TO,o.y=o.relative?0:r),n&&o.type&T.VERT_LINE_TO&&(o.type=T.LINE_TO,o.x=o.relative?0:s),e&&o.type&T.CLOSE_PATH&&(o.type=T.LINE_TO,o.x=o.relative?a-s:a,o.y=o.relative?l-r:l),o.type&T.ARC&&(o.rX===0||o.rY===0)&&(o.type=T.LINE_TO,delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag),i&&o.type&T.QUAD_TO){const u=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Vt(u,h,c)&&(o.type=T.LINE_TO,delete o.x1,delete o.y1)}if(i&&o.type&T.CURVE_TO){const u=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x2,r+o.y2]:[o.x2,o.y2],d=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Vt(u,h,d)&&Vt(u,c,d)&&(o.type=T.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function kn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Ie((o,s,r)=>(o.type&T.SMOOTH_CURVE_TO&&(o.type=T.CURVE_TO,e=isNaN(e)?s:e,t=isNaN(t)?r:t,o.x1=o.relative?s-e:2*s-e,o.y1=o.relative?r-t:2*r-t),o.type&T.CURVE_TO?(e=o.relative?s+o.x2:o.x2,t=o.relative?r+o.y2:o.y2):(e=NaN,t=NaN),o.type&T.SMOOTH_QUAD_TO&&(o.type=T.QUAD_TO,n=isNaN(n)?s:n,i=isNaN(i)?r:i,o.x1=o.relative?s-n:2*s-n,o.y1=o.relative?r-i:2*r-i),o.type&T.QUAD_TO?(n=o.relative?s+o.x1:o.x1,i=o.relative?r+o.y1:o.y1):(n=NaN,i=NaN),o))}function Dn(){let e=NaN,t=NaN;return Ie((n,i,o)=>{if(n.type&T.SMOOTH_QUAD_TO&&(n.type=T.QUAD_TO,e=isNaN(e)?i:e,t=isNaN(t)?o:t,n.x1=n.relative?i-e:2*i-e,n.y1=n.relative?o-t:2*o-t),n.type&T.QUAD_TO){e=n.relative?i+n.x1:n.x1,t=n.relative?o+n.y1:n.y1;const s=n.x1,r=n.y1;n.type=T.CURVE_TO,n.x1=((n.relative?0:i)+s*2)/3,n.y1=((n.relative?0:o)+r*2)/3,n.x2=(n.x+s*2)/3,n.y2=(n.y+r*2)/3}else e=NaN,t=NaN;return n})}function Ie(e){let t=0,n=0,i=NaN,o=NaN;return function(r){if(isNaN(i)&&!(r.type&T.MOVE_TO))throw new Error("path must start with moveto");const a=e(r,t,n,i,o);return r.type&T.CLOSE_PATH&&(t=i,n=o),"x"in r&&typeof r.x<"u"&&(t=r.relative?t+r.x:r.x),"y"in r&&typeof r.y<"u"&&(n=r.relative?n+r.y:r.y),r.type&T.MOVE_TO&&(i=t,o=n),a}}function wo(e=0){Re(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Ie((s,r,a,l,u)=>{const h=Math.abs;let c=!1,d=0,y=0;if(s.type&T.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:r-t,y=isNaN(n)?0:a-n),s.type&(T.CURVE_TO|T.SMOOTH_CURVE_TO)?(t=s.relative?r+s.x2:s.x2,n=s.relative?a+s.y2:s.y2):(t=NaN,n=NaN),s.type&T.SMOOTH_QUAD_TO?(i=isNaN(i)?r:2*r-i,o=isNaN(o)?a:2*a-o):s.type&T.QUAD_TO?(i=s.relative?r+s.x1:s.x1,o=s.relative?a+s.y1:s.y2):(i=NaN,o=NaN),s.type&T.LINE_COMMANDS||s.type&T.ARC&&(s.rX===0||s.rY===0||!s.lArcFlag)||s.type&T.CURVE_TO||s.type&T.SMOOTH_CURVE_TO||s.type&T.QUAD_TO||s.type&T.SMOOTH_QUAD_TO){const g=typeof s.x>"u"?0:s.relative?s.x:s.x-r,p=typeof s.y>"u"?0:s.relative?s.y:s.y-a;d=isNaN(i)?typeof s.x1>"u"?d:s.relative?s.x:s.x1-r:i-r,y=isNaN(o)?typeof s.y1>"u"?y:s.relative?s.y:s.y1-a:o-a;const w=typeof s.x2>"u"?0:s.relative?s.x:s.x2-r,m=typeof s.y2>"u"?0:s.relative?s.y:s.y2-a;h(g)<=e&&h(p)<=e&&h(d)<=e&&h(y)<=e&&h(w)<=e&&h(m)<=e&&(c=!0)}return s.type&T.CLOSE_PATH&&h(r-l)<=e&&h(a-u)<=e&&(c=!0),c?[]:s})}function Ue(e,t,n,i,o,s){return Re(e,t,n,i,o,s),Ie((r,a,l,u)=>{const h=r.x1,c=r.x2,d=r.relative&&!isNaN(u),y=typeof r.x<"u"?r.x:d?0:a,g=typeof r.y<"u"?r.y:d?0:l;r.type&T.HORIZ_LINE_TO&&t!==0&&(r.type=T.LINE_TO,r.y=r.relative?0:l),r.type&T.VERT_LINE_TO&&n!==0&&(r.type=T.LINE_TO,r.x=r.relative?0:a),typeof r.x<"u"&&(r.x=r.x*e+g*n+(d?0:o)),typeof r.y<"u"&&(r.y=y*t+r.y*i+(d?0:s)),typeof r.x1<"u"&&(r.x1=r.x1*e+r.y1*n+(d?0:o)),typeof r.y1<"u"&&(r.y1=h*t+r.y1*i+(d?0:s)),typeof r.x2<"u"&&(r.x2=r.x2*e+r.y2*n+(d?0:o)),typeof r.y2<"u"&&(r.y2=c*t+r.y2*i+(d?0:s));function p(m){return m*m}const w=e*i-t*n;if(typeof r.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(w===0)delete r.rX,delete r.rY,delete r.xRot,delete r.lArcFlag,delete r.sweepFlag,r.type=T.LINE_TO;else{const m=r.xRot*Math.PI/180,A=Math.sin(m),E=Math.cos(m),M=1/p(r.rX),S=1/p(r.rY),v=p(E)*M+p(A)*S,N=2*A*E*(M-S),H=p(A)*M+p(E)*S,B=v*i*i-N*t*i+H*t*t,X=N*(e*i+t*n)-2*(v*n*i+H*e*t),j=v*n*n-N*e*n+H*e*e,_=(Math.atan2(X,B-j)+Math.PI)%Math.PI/2,b=Math.sin(_),O=Math.cos(_);r.rX=Math.abs(w)/Math.sqrt(B*p(O)+X*b*O+j*p(b)),r.rY=Math.abs(w)/Math.sqrt(B*p(b)-X*b*O+j*p(O)),r.xRot=_*180/Math.PI}return typeof r.sweepFlag<"u"&&0>w&&(r.sweepFlag=+!r.sweepFlag),r})}function Eo(e,t=0,n=0){Re(e,t,n);const i=Math.sin(e),o=Math.cos(e);return Ue(o,i,-i,o,t-t*o+n*i,n-t*i-n*o)}function bo(e,t=0){return Re(e,t),Ue(1,0,0,1,e,t)}function To(e,t=e){return Re(e,t),Ue(e,0,0,t,0,0)}function Ao(e){return Re(e),Ue(1,0,Math.tan(e),1,0,0)}function Oo(e){return Re(e),Ue(1,Math.tan(e),0,1,0,0)}function Mo(e=0){return Re(e),Ue(-1,0,0,1,e,0)}function vo(e=0){return Re(e),Ue(1,0,0,-1,0,e)}function So(){return Ie((e,t,n)=>T.ARC===e.type?go(e,e.relative?0:t,e.relative?0:n):e)}function No(){return Ie((e,t,n)=>(e.relative&&(t=0,n=0),T.ARC===e.type&&Ut(e,t,n),e))}function Pn(){return e=>({...e})}function Co(){const e=Pn(),t=Ln(),n=Dn(),i=kn(),o=Ie((s,r,a)=>{const l=i(n(t(e(s))));function u(c){c>o.maxX&&(o.maxX=c),c<o.minX&&(o.minX=c)}function h(c){c>o.maxY&&(o.maxY=c),c<o.minY&&(o.minY=c)}if(l.type&T.DRAWING_COMMANDS&&(u(r),h(a)),l.type&T.HORIZ_LINE_TO&&u(l.x),l.type&T.VERT_LINE_TO&&h(l.y),l.type&T.LINE_TO&&(u(l.x),h(l.y)),l.type&T.CURVE_TO){u(l.x),h(l.y);const c=Rn(r,l.x1,l.x2,l.x);for(const y of c)0<y&&1>y&&u(In(r,l.x1,l.x2,l.x,y));const d=Rn(a,l.y1,l.y2,l.y);for(const y of d)0<y&&1>y&&h(In(a,l.y1,l.y2,l.y,y))}if(l.type&T.ARC){u(l.x),h(l.y),Ut(l,r,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,y=Math.sin(c)*l.rX,g=-Math.sin(c)*l.rY,p=Math.cos(c)*l.rY,[w,m]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],A=([S,v])=>{const H=Math.atan2(v,S)*180/Math.PI;return H<w?H+360:H},E=Sn(g,-d,0).map(A);for(const S of E)S>w&&S<m&&u(Cn(l.cX,d,g,S));const M=Sn(p,-y,0).map(A);for(const S of M)S>w&&S<m&&h(Cn(l.cY,y,p,S))}return s});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const se={ROUND:yo,TO_ABS:Ln,TO_REL:_o,NORMALIZE_HVZ:mo,NORMALIZE_ST:kn,QT_TO_C:Dn,INFO:Ie,SANITIZE:wo,MATRIX:Ue,ROTATE:Eo,TRANSLATE:bo,SCALE:To,SKEW_X:Ao,SKEW_Y:Oo,X_AXIS_SYMMETRY:Mo,Y_AXIS_SYMMETRY:vo,A_TO_C:So,ANNOTATE_ARCS:No,CLONE:Pn,CALCULATE_BOUNDS:Co,REVERSE_PATH:po};class Un{round(t){return this.transform(se.ROUND(t))}toAbs(){return this.transform(se.TO_ABS())}toRel(){return this.transform(se.TO_REL())}normalizeHVZ(t,n,i){return this.transform(se.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(se.NORMALIZE_ST())}qtToC(){return this.transform(se.QT_TO_C())}aToC(){return this.transform(se.A_TO_C())}sanitize(t){return this.transform(se.SANITIZE(t))}translate(t,n){return this.transform(se.TRANSLATE(t,n))}scale(t,n){return this.transform(se.SCALE(t,n))}rotate(t,n,i){return this.transform(se.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(se.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(se.SKEW_X(t))}skewY(t){return this.transform(se.SKEW_Y(t))}xSymmetry(t){return this.transform(se.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(se.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(se.ANNOTATE_ARCS())}}const Ro=e=>e===" "||e===" "||e==="\r"||e===`
2
- `,Vn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class Io extends Un{constructor(){super();ne(this,"curNumber","");ne(this,"curCommandType",-1);ne(this,"curCommandRelative",!1);ne(this,"canParseCommandOrComma",!0);ne(this,"curNumberHasExp",!1);ne(this,"curNumberHasExpDigits",!1);ne(this,"curNumberHasDecimal",!1);ne(this,"curArgs",[])}finish(n=[]){if(this.parse(" ",n),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return n}parse(n,i=[]){const o=s=>{i.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<n.length;s++){const r=n[s],a=this.curCommandType===T.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),l=Vn(r)&&(this.curNumber==="0"&&r==="0"||a);if(Vn(r)&&!l){this.curNumber+=r,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(r==="e"||r==="E"){this.curNumber+=r,this.curNumberHasExp=!0;continue}if((r==="-"||r==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=r;continue}if(r==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!a){this.curNumber+=r,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const u=Number(this.curNumber);if(isNaN(u))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===T.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>u)throw new SyntaxError(`Expected positive number, got "${u}" at index "${s}"`)}else if((this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber!=="0"&&this.curNumber!=="1")throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${s}"`)}this.curArgs.push(u),this.curArgs.length===Lo[this.curCommandType]&&(T.HORIZ_LINE_TO===this.curCommandType?o({type:T.HORIZ_LINE_TO,relative:this.curCommandRelative,x:u}):T.VERT_LINE_TO===this.curCommandType?o({type:T.VERT_LINE_TO,relative:this.curCommandRelative,y:u}):this.curCommandType===T.MOVE_TO||this.curCommandType===T.LINE_TO||this.curCommandType===T.SMOOTH_QUAD_TO?(o({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),T.MOVE_TO===this.curCommandType&&(this.curCommandType=T.LINE_TO)):this.curCommandType===T.CURVE_TO?o({type:T.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===T.SMOOTH_CURVE_TO?o({type:T.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===T.QUAD_TO?o({type:T.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===T.ARC&&o({type:T.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!Ro(r)){if(r===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(r==="+"||r==="-"||r==="."){this.curNumber=r,this.curNumberHasDecimal=r===".";continue}if(l){this.curNumber=r,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${s}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${r}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,r==="z"||r==="Z"){i.push({type:T.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(r==="h"||r==="H")this.curCommandType=T.HORIZ_LINE_TO,this.curCommandRelative=r==="h";else if(r==="v"||r==="V")this.curCommandType=T.VERT_LINE_TO,this.curCommandRelative=r==="v";else if(r==="m"||r==="M")this.curCommandType=T.MOVE_TO,this.curCommandRelative=r==="m";else if(r==="l"||r==="L")this.curCommandType=T.LINE_TO,this.curCommandRelative=r==="l";else if(r==="c"||r==="C")this.curCommandType=T.CURVE_TO,this.curCommandRelative=r==="c";else if(r==="s"||r==="S")this.curCommandType=T.SMOOTH_CURVE_TO,this.curCommandRelative=r==="s";else if(r==="q"||r==="Q")this.curCommandType=T.QUAD_TO,this.curCommandRelative=r==="q";else if(r==="t"||r==="T")this.curCommandType=T.SMOOTH_QUAD_TO,this.curCommandRelative=r==="t";else if(r==="a"||r==="A")this.curCommandType=T.ARC,this.curCommandRelative=r==="a";else throw new SyntaxError(`Unexpected character "${r}" at index ${s}.`)}}return i}transform(n){return Object.create(this,{parse:{value(o,s=[]){const r=Object.getPrototypeOf(this).parse.call(this,o);for(const a of r){const l=n(a);Array.isArray(l)?s.push(...l):s.push(l)}return s}}})}}const x=class x extends Un{constructor(n){super();ne(this,"commands");typeof n=="string"?this.commands=x.parse(n):this.commands=n}encode(){return x.encode(this.commands)}getBounds(){const n=se.CALCULATE_BOUNDS();return this.transform(n),n}transform(n){const i=[];for(const o of this.commands){const s=n(o);Array.isArray(s)?i.push(...s):i.push(s)}return this.commands=i,this}reverse(n=!0){return this.commands=se.REVERSE_PATH(this.commands,n),this}static encode(n){return co(n)}static parse(n){const i=new Io,o=[];return i.parse(n,o),i.finish(o),o}};ne(x,"CLOSE_PATH",1),ne(x,"MOVE_TO",2),ne(x,"HORIZ_LINE_TO",4),ne(x,"VERT_LINE_TO",8),ne(x,"LINE_TO",16),ne(x,"CURVE_TO",32),ne(x,"SMOOTH_CURVE_TO",64),ne(x,"QUAD_TO",128),ne(x,"SMOOTH_QUAD_TO",256),ne(x,"ARC",512),ne(x,"LINE_COMMANDS",x.LINE_TO|x.HORIZ_LINE_TO|x.VERT_LINE_TO),ne(x,"DRAWING_COMMANDS",x.HORIZ_LINE_TO|x.VERT_LINE_TO|x.LINE_TO|x.CURVE_TO|x.SMOOTH_CURVE_TO|x.QUAD_TO|x.SMOOTH_QUAD_TO|x.ARC);let T=x;const Lo={[T.MOVE_TO]:2,[T.LINE_TO]:2,[T.HORIZ_LINE_TO]:1,[T.VERT_LINE_TO]:1,[T.CLOSE_PATH]:0,[T.QUAD_TO]:4,[T.SMOOTH_QUAD_TO]:2,[T.CURVE_TO]:6,[T.SMOOTH_CURVE_TO]:4,[T.ARC]:7},ko=e=>{const t=new T(e).toAbs().commands,n=[];let i=[],o=null;for(const s of t)switch(s.type){case T.MOVE_TO:i.length>0&&(n.push({points:i}),i=[]),o=[s.x,s.y],i.push(o);break;case T.LINE_TO:i.push([s.x,s.y]);break;case T.HORIZ_LINE_TO:const r=i[i.length-1][1];i.push([s.x,r]);break;case T.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,s.y]);break;case T.CURVE_TO:case T.SMOOTH_CURVE_TO:case T.QUAD_TO:case T.SMOOTH_QUAD_TO:case T.ARC:i.push([s.x,s.y]);break}if(i.length>2&&n.push({points:i}),n.length>0){const s=Se(n[0].points);return{rings:n,bounds:s}}},Do=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:ee.POLYGON,geometry:{points:o,bounds:Se(o)}}},Po=e=>{const t=vn(e),n=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),o=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-o,minY:i-s,maxX:n+o,maxY:i+s};return{type:ee.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},Uo=e=>{const t=vn(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(l=>l.getAttribute("d")||"").map(l=>ko(l)).filter(Boolean),s=o.reduce((l,u)=>[...l,...u.rings[0].points],[]),r=Se(s);return o.length===1&&o[0].rings.length===1?{type:ee.POLYGON,geometry:{points:s,bounds:r}}:{type:ee.MULTIPOLYGLON,geometry:{polygons:o,bounds:r}}},Hn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Do(t);if(t.includes("<path "))return Uo(t);if(t.includes("<ellipse "))return Po(t);throw"Unsupported SVG shape: "+t},Vo=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Le(n)}" />`).join("")}</g>`,Bn=e=>{let t;if(e.type===ee.POLYGON){const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`}else if(e.type===ee.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}else if(e.type===ee.MULTIPOLYGLON){const n=e.geometry;t=`<svg>${Vo(n)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},he=[];for(let e=0;e<256;++e)he.push((e+256).toString(16).slice(1));function Ho(e,t=0){return(he[e[t+0]]+he[e[t+1]]+he[e[t+2]]+he[e[t+3]]+"-"+he[e[t+4]]+he[e[t+5]]+"-"+he[e[t+6]]+he[e[t+7]]+"-"+he[e[t+8]]+he[e[t+9]]+"-"+he[e[t+10]]+he[e[t+11]]+he[e[t+12]]+he[e[t+13]]+he[e[t+14]]+he[e[t+15]]).toLowerCase()}let Ht;const Bo=new Uint8Array(16);function Yo(){if(!Ht){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ht=crypto.getRandomValues.bind(crypto)}return Ht(Bo)}const Yn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xn(e,t,n){var o;if(Yn.randomUUID&&!e)return Yn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Yo();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Ho(i)}var Fn=Object.prototype.hasOwnProperty;function Ve(e,t){var n,i;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((i=e.length)===t.length)for(;i--&&Ve(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Fn.call(e,n)&&++i&&!Fn.call(t,n)||!(n in t)||!Ve(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}function Bt(){}function Xo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const We=[];function Yt(e,t=Bt){let n;const i=new Set;function o(a){if(Xo(e,a)&&(e=a,n)){const l=!We.length;for(const u of i)u[1](),We.push(u,e);if(l){for(let u=0;u<We.length;u+=2)We[u][0](We[u+1]);We.length=0}}}function s(a){o(a(e))}function r(a,l=Bt){const u=[a,l];return i.add(u),i.size===1&&(n=t(o,s)||Bt),a(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const Fo=e=>{const{subscribe:t,set:n}=Yt();let i;return t(o=>i=o),e.observe(({changes:o})=>{if(i){(o.deleted||[]).some(r=>r.id===i)&&n(void 0);const s=(o.updated||[]).find(({oldValue:r})=>r.id===i);s&&n(s.newValue.id)}}),{get current(){return i},subscribe:t,set:n}};var Xt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Xt||{});const Et={selected:[]},Go=(e,t,n)=>{const{subscribe:i,set:o}=Yt(Et);let s=t,r=Et;i(g=>r=g);const a=()=>{Ve(r,Et)||o(Et)},l=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(l())return!1;const p=typeof g=="string"?g:g.id;return r.selected.some(w=>w.id===p)},h=(g,p)=>{let w;if(Array.isArray(g)){if(w=g.map(A=>e.getAnnotation(A)).filter(Boolean),w.length<g.length){console.warn("Invalid selection: "+g.filter(A=>!w.some(E=>E.id===A)));return}}else{const A=e.getAnnotation(g);if(!A){console.warn("Invalid selection: "+g);return}w=[A]}const m=w.reduce((A,E)=>{const M=Gn(E,s,n);return M==="EDIT"?[...A,{id:E.id,editable:!0}]:M==="SELECT"?[...A,{id:E.id}]:A},[]);o({selected:m,event:p})},c=(g,p)=>{const w=Array.isArray(g)?g:[g],m=w.map(A=>e.getAnnotation(A)).filter(A=>!!A);o({selected:m.map(A=>{const E=p===void 0?Gn(A,s,n)==="EDIT":p;return{id:A.id,editable:E}})}),m.length!==w.length&&console.warn("Invalid selection",g)},d=g=>{if(l())return!1;const{selected:p}=r;p.some(({id:w})=>g.includes(w))&&o({selected:p.filter(({id:w})=>!g.includes(w))})},y=g=>{s=g,c(r.selected.map(({id:p})=>p))};return e.observe(({changes:g})=>d((g.deleted||[]).map(p=>p.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:a,isEmpty:l,isSelected:u,setSelected:c,setUserSelectAction:y,subscribe:i,userSelect:h}},Gn=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},de=[];for(let e=0;e<256;++e)de.push((e+256).toString(16).slice(1));function jo(e,t=0){return(de[e[t+0]]+de[e[t+1]]+de[e[t+2]]+de[e[t+3]]+"-"+de[e[t+4]]+de[e[t+5]]+"-"+de[e[t+6]]+de[e[t+7]]+"-"+de[e[t+8]]+de[e[t+9]]+"-"+de[e[t+10]]+de[e[t+11]]+de[e[t+12]]+de[e[t+13]]+de[e[t+14]]+de[e[t+15]]).toLowerCase()}let Ft;const zo=new Uint8Array(16);function Qo(){if(!Ft){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ft=crypto.getRandomValues.bind(crypto)}return Ft(zo)}const qo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),jn={randomUUID:qo};function zn(e,t,n){var i;if(jn.randomUUID&&!e)return jn.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Qo();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,jo(o)}const Gt=e=>{const t=n=>{const i={...n};return n.created&&typeof n.created=="string"&&(i.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(i.updated=new Date(n.updated)),i};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Zo=(e,t,n,i)=>({id:zn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),Wo=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},Ko=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},Jo=(e,t)=>t.bodies.map(n=>{const i=e.bodies.find(o=>o.id===n.id);return{newBody:n,oldBody:i&&!Ve(i,n)?i:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:i})=>({oldBody:n,newBody:i})),xo=(e,t)=>!Ve(e.target,t.target),Qn=(e,t)=>{const n=Wo(e,t),i=Ko(e,t),o=Jo(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:o.length>0?o:void 0,targetUpdated:xo(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var te=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(te||{});const $o=(e,t)=>{var n,i;const{changes:o,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(o.created)||a(o.deleted))){const l=(n=o.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),u=(i=o.updated)==null?void 0:i.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!u||r==="TARGET_ONLY"&&u&&!l)return!1}}if(e.options.annotations){const r=new Set([...(o.created||[]).map(a=>a.id),...(o.deleted||[]).map(a=>a.id),...(o.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},es=(e,t)=>{const n=new Set((e.created||[]).map(c=>c.id)),i=new Set((e.updated||[]).map(({newValue:c})=>c.id)),o=new Set((t.created||[]).map(c=>c.id)),s=new Set((t.deleted||[]).map(c=>c.id)),r=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>n.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(e.created||[]).filter(c=>!s.has(c.id)).map(c=>r.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],u=[...(e.deleted||[]).filter(c=>!o.has(c.id)),...(t.deleted||[]).filter(c=>!n.has(c.id))],h=[...(e.updated||[]).filter(({newValue:c})=>!s.has(c.id)).map(c=>{const{oldValue:d,newValue:y}=c;if(r.has(y.id)){const g=t.updated.find(p=>p.oldValue.id===y.id).newValue;return Qn(d,g)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:u,updated:h}},bt=e=>{const t=e.id===void 0?zn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ts=e=>e.id!==void 0,ns=()=>{const e=new Map,t=new Map,n=[],i=(_,b={})=>{n.push({onChange:_,options:b})},o=_=>{const b=n.findIndex(O=>O.onChange==_);b>-1&&n.splice(b,1)},s=(_,b)=>{const O={origin:_,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(C=>{$o(C,O)&&C.onChange(O)})},r=(_,b=te.LOCAL)=>{if(_.id&&e.get(_.id))throw Error(`Cannot add annotation ${_.id} - exists already`);{const O=bt(_);e.set(O.id,O),O.bodies.forEach(C=>t.set(C.id,O.id)),s(b,{created:[O]})}},a=(_,b)=>{const O=bt(typeof _=="string"?b:_),C=typeof _=="string"?_:_.id,R=C&&e.get(C);if(R){const I=Qn(R,O);return C===O.id?e.set(C,O):(e.delete(C),e.set(O.id,O)),R.bodies.forEach(Y=>t.delete(Y.id)),O.bodies.forEach(Y=>t.set(Y.id,O.id)),I}else console.warn(`Cannot update annotation ${C} - does not exist`)},l=(_,b=te.LOCAL,O=te.LOCAL)=>{const C=ts(b)?O:b,R=a(_,b);R&&s(C,{updated:[R]})},u=(_,b=te.LOCAL)=>{e.get(_.id)?l(_,b):r(_,b)},h=(_,b=te.LOCAL)=>{const O=_.reduce((C,R)=>{const I=a(R);return I?[...C,I]:C},[]);O.length>0&&s(b,{updated:O})},c=(_,b=te.LOCAL)=>{const O=_.map(bt),{toAdd:C,toUpdate:R}=O.reduce((Y,Q)=>e.get(Q.id)?{...Y,toUpdate:[...Y.toUpdate,Q]}:{...Y,toAdd:[...Y.toAdd,Q]},{toAdd:[],toUpdate:[]}),I=R.map(Y=>a(Y,b)).filter(Boolean);C.forEach(Y=>{e.set(Y.id,Y),Y.bodies.forEach(Q=>t.set(Q.id,Y.id))}),s(b,{created:C,updated:I})},d=(_,b=te.LOCAL)=>{const O=e.get(_.annotation);if(O){const C={...O,bodies:[...O.bodies,_]};e.set(O.id,C),t.set(_.id,C.id),s(b,{updated:[{oldValue:O,newValue:C,bodiesCreated:[_]}]})}else console.warn(`Attempt to add body to missing annotation: ${_.annotation}`)},y=()=>[...e.values()],g=(_=te.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(_,{deleted:b})},p=(_,b=!0,O=te.LOCAL)=>{const C=_.map(bt);if(b){const R=[...e.values()];e.clear(),t.clear(),C.forEach(I=>{e.set(I.id,I),I.bodies.forEach(Y=>t.set(Y.id,I.id))}),s(O,{created:C,deleted:R})}else{const R=_.reduce((I,Y)=>{const Q=Y.id&&e.get(Y.id);return Q?[...I,Q]:I},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(I=>I.id).join(", ")}`);C.forEach(I=>{e.set(I.id,I),I.bodies.forEach(Y=>t.set(Y.id,I.id))}),s(O,{created:C})}},w=_=>{const b=typeof _=="string"?_:_.id,O=e.get(b);if(O)return e.delete(b),O.bodies.forEach(C=>t.delete(C.id)),O;console.warn(`Attempt to delete missing annotation: ${b}`)},m=(_,b=te.LOCAL)=>{const O=w(_);O&&s(b,{deleted:[O]})},A=(_,b=te.LOCAL)=>{const O=_.reduce((C,R)=>{const I=w(R);return I?[...C,I]:C},[]);O.length>0&&s(b,{deleted:O})},E=_=>{const b=e.get(_.annotation);if(b){const O=b.bodies.find(C=>C.id===_.id);if(O){t.delete(O.id);const C={...b,bodies:b.bodies.filter(R=>R.id!==_.id)};return e.set(b.id,C),{oldValue:b,newValue:C,bodiesDeleted:[O]}}else console.warn(`Attempt to delete missing body ${_.id} from annotation ${_.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${_.annotation}`)},M=(_,b=te.LOCAL)=>{const O=E(_);O&&s(b,{updated:[O]})},S=(_,b=te.LOCAL)=>{const O=_.map(C=>E(C)).filter(Boolean);O.length>0&&s(b,{updated:O})},v=_=>{const b=e.get(_);return b?{...b}:void 0},N=_=>{const b=t.get(_);if(b){const O=v(b).bodies.find(C=>C.id===_);if(O)return O;console.error(`Store integrity error: body ${_} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${_}`)},H=(_,b)=>{if(_.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const O=e.get(_.annotation);if(O){const C=O.bodies.find(I=>I.id===_.id),R={...O,bodies:O.bodies.map(I=>I.id===C.id?b:I)};return e.set(O.id,R),C.id!==b.id&&(t.delete(C.id),t.set(b.id,R.id)),{oldValue:O,newValue:R,bodiesUpdated:[{oldBody:C,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${_.annotation}`)},B=(_,b,O=te.LOCAL)=>{const C=H(_,b);C&&s(O,{updated:[C]})},X=(_,b=te.LOCAL)=>{const O=_.map(C=>H({id:C.id,annotation:C.annotation},C)).filter(Boolean);s(b,{updated:O})},j=_=>{const b=e.get(_.annotation);if(b){const O={...b,target:{...b.target,..._}};return e.set(b.id,O),{oldValue:b,newValue:O,targetUpdated:{oldTarget:b.target,newTarget:_}}}else console.warn(`Attempt to update target on missing annotation: ${_.annotation}`)};return{addAnnotation:r,addBody:d,all:y,bulkAddAnnotations:p,bulkDeleteAnnotations:A,bulkDeleteBodies:S,bulkUpdateAnnotations:h,bulkUpdateBodies:X,bulkUpdateTargets:(_,b=te.LOCAL)=>{const O=_.map(C=>j(C)).filter(Boolean);O.length>0&&s(b,{updated:O})},bulkUpsertAnnotations:c,clear:g,deleteAnnotation:m,deleteBody:M,getAnnotation:v,getBody:N,observe:i,unobserve:o,updateAnnotation:l,updateBody:B,updateTarget:(_,b=te.LOCAL)=>{const O=j(_);O&&s(b,{updated:[O]})},upsertAnnotation:u}},is=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let os=()=>({emit(e,...t){for(let n=this.events[e]||[],i=0,o=n.length;i<o;i++)n[i](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var i;this.events[e]=(i=this.events[e])==null?void 0:i.filter(o=>t!==o)}}});const ss=250,rs=(e,t)=>{const n=os(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const a=g=>{if(!s){const{changes:p}=g,w=performance.now();if(w-r>ss)i.splice(o+1),i.push(p),o=i.length-1;else{const m=i.length-1;i[m]=es(i[m],p)}r=w}s=!1};e.observe(a,{origin:te.LOCAL});const l=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g),u=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),h=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({oldValue:p})=>p)),c=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({newValue:p})=>p)),d=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),y=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...i],pointer:o}),on:(g,p)=>n.on(g,p),redo:()=>{if(i.length-1>o){s=!0;const{created:g,updated:p,deleted:w}=i[o+1];u(g),c(p),y(w),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:g,updated:p,deleted:w}=i[o];l(g),h(p),d(w),n.emit("undo",i[o]),o-=1}}}},ls=()=>{const{subscribe:e,set:t}=Yt([]);return{subscribe:e,set:t}},as=(e,t,n,i)=>{const{hover:o,selection:s,store:r,viewport:a}=e,l=new Map;let u=[],h,c;const d=(m,A)=>{l.has(m)?l.get(m).push(A):l.set(m,[A])},y=(m,A)=>{const E=l.get(m);if(E){const M=E.indexOf(A);M!==-1&&E.splice(M,1)}},g=(m,A,E)=>{l.has(m)&&setTimeout(()=>{l.get(m).forEach(M=>{if(n){const S=Array.isArray(A)?A.map(N=>n.serialize(N)):n.serialize(A),v=E?E instanceof PointerEvent?E:n.serialize(E):void 0;M(S,v)}else M(A,E)})},1)},p=()=>{const{selected:m}=s,A=(m||[]).map(({id:E})=>r.getAnnotation(E));A.forEach(E=>{const M=u.find(S=>S.id===E.id);(!M||!Ve(M,E))&&g("updateAnnotation",E,M)}),u=u.map(E=>A.find(({id:S})=>S===E.id)||E)};s.subscribe(({selected:m})=>{if(!(u.length===0&&m.length===0)){if(u.length===0&&m.length>0)u=m.map(({id:A})=>r.getAnnotation(A));else if(u.length>0&&m.length===0)u.forEach(A=>{const E=r.getAnnotation(A.id);E&&!Ve(E,A)&&g("updateAnnotation",E,A)}),u=[];else{const A=new Set(u.map(M=>M.id)),E=new Set(m.map(({id:M})=>M));u.filter(M=>!E.has(M.id)).forEach(M=>{const S=r.getAnnotation(M.id);S&&!Ve(S,M)&&g("updateAnnotation",S,M)}),u=[...u.filter(M=>E.has(M.id)),...m.filter(({id:M})=>!A.has(M)).map(({id:M})=>r.getAnnotation(M))]}g("selectionChanged",u)}}),o.subscribe(m=>{!h&&m?g("mouseEnterAnnotation",r.getAnnotation(m)):h&&!m?g("mouseLeaveAnnotation",r.getAnnotation(h)):h&&m&&(g("mouseLeaveAnnotation",r.getAnnotation(h)),g("mouseEnterAnnotation",r.getAnnotation(m))),h=m}),a==null||a.subscribe(m=>g("viewportIntersect",m.map(A=>r.getAnnotation(A)))),r.observe(m=>{i&&(c&&clearTimeout(c),c=setTimeout(p,1e3));const{created:A,deleted:E}=m.changes;(A||[]).forEach(M=>g("createAnnotation",M)),(E||[]).forEach(M=>g("deleteAnnotation",M)),(m.changes.updated||[]).filter(M=>[...M.bodiesCreated||[],...M.bodiesDeleted||[],...M.bodiesUpdated||[]].length>0).forEach(({oldValue:M,newValue:S})=>{const v=u.find(N=>N.id===M.id)||M;u=u.map(N=>N.id===M.id?S:N),g("updateAnnotation",S,v)})},{origin:te.LOCAL}),r.observe(m=>{if(u){const A=new Set(u.map(M=>M.id)),E=(m.changes.updated||[]).filter(({newValue:M})=>A.has(M.id)).map(({newValue:M})=>M);E.length>0&&(u=u.map(M=>E.find(v=>v.id===M.id)||M))}},{origin:te.REMOTE});const w=m=>A=>{const{updated:E}=A;m?(E||[]).forEach(M=>g("updateAnnotation",M.oldValue,M.newValue)):(E||[]).forEach(M=>g("updateAnnotation",M.newValue,M.oldValue))};return t.on("undo",w(!0)),t.on("redo",w(!1)),{on:d,off:y,emit:g}},us=e=>t=>t.reduce((n,i)=>{const{parsed:o,error:s}=e.parse(i);return s?{parsed:n.parsed,failed:[...n.failed,i]}:o?{parsed:[...n.parsed,o],failed:n.failed}:{...n}},{parsed:[],failed:[]}),fs=(e,t,n)=>{const{store:i,selection:o}=e,s=m=>{if(n){const{parsed:A,error:E}=n.parse(m);A?i.addAnnotation(A,te.REMOTE):console.error(E)}else i.addAnnotation(Gt(m),te.REMOTE)},r=()=>o.clear(),a=()=>i.clear(),l=m=>{const A=i.getAnnotation(m);return n&&A?n.serialize(A):A},u=()=>n?i.all().map(n.serialize):i.all(),h=()=>{var m;const A=(((m=o.selected)==null?void 0:m.map(E=>E.id))||[]).map(E=>i.getAnnotation(E)).filter(Boolean);return n?A.map(n.serialize):A},c=(m,A=!0)=>fetch(m).then(E=>E.json()).then(E=>(y(E,A),E)),d=m=>{if(typeof m=="string"){const A=i.getAnnotation(m);if(i.deleteAnnotation(m),A)return n?n.serialize(A):A}else{const A=n?n.parse(m).parsed:m;if(A)return i.deleteAnnotation(A),m}},y=(m,A=!0)=>{if(n){const E=n.parseAll||us(n),{parsed:M,failed:S}=E(m);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(M,A,te.REMOTE)}else i.bulkAddAnnotations(m.map(Gt),A,te.REMOTE)},g=(m,A)=>{m?o.setSelected(m,A):o.clear()},p=m=>{o.clear(),o.setUserSelectAction(m)},w=m=>{if(n){const A=n.parse(m).parsed,E=n.serialize(i.getAnnotation(A.id));return i.updateAnnotation(A),E}else{const A=i.getAnnotation(m.id);return i.updateAnnotation(Gt(m)),A}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:u,getHistory:t.getHistory,getSelected:h,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:y,setSelected:g,setUserSelectAction:p,undo:t.undo,updateAnnotation:w}},cs=(e,t,n)=>typeof t=="function"?t(e,n):t,hs=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,i)=>{const o=typeof e=="function"?e(n,i):e,s=typeof t=="function"?t(n,i):t;return{...o||{},...s||{}}},ds="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let gs=e=>crypto.getRandomValues(new Uint8Array(e)),ps=(e,t,n)=>{let i=(2<<Math.log2(e.length-1))-1,o=-~(1.6*i*t/e.length);return(s=t)=>{let r="";for(;;){let a=n(o),l=o|0;for(;l--;)if(r+=e[a[l]&i]||"",r.length>=s)return r}}},ys=(e,t=21)=>ps(e,t|0,gs),_s=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=ds[n[e]&63];return t};const ms=()=>({isGuest:!0,id:ys("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ws=e=>{const t=JSON.stringify(e);let n=0;for(let i=0,o=t.length;i<o;i++){let s=t.charCodeAt(i);n=(n<<5)-n+s,n|=0}return`${n}`},qn=e=>e?typeof e=="object"?{...e}:e:void 0,Es=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:s,value:r,created:a,modified:l,creator:u,...h}=n;return{id:i||`temp-${ws(n)}`,annotation:t,type:o,purpose:s,value:r,creator:qn(u),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),bs=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:s,...r}=t,a={...r,created:o==null?void 0:o.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a}),Ts=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],As=()=>{const e=[...Ts];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};_s();const Os=(e,t={strict:!0,invertY:!1})=>({parse:o=>Zn(o,t),serialize:o=>Wn(o,e,t)}),Zn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Xn(),{creator:i,created:o,modified:s,body:r,...a}=e,l=Es(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,h=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,c=typeof h=="string"||(h==null?void 0:h.type)==="FragmentSelector"?Tn(h,t.invertY):(h==null?void 0:h.type)==="SvgSelector"?Hn(h):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return c||!t.strict?{parsed:{...a,id:n,bodies:l,target:{created:o?new Date(o):void 0,creator:qn(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:n,selector:c||h}}}:{error:Error(`Invalid selector: ${JSON.stringify(h)}`)}},Wn=(e,t,n={strict:!0,invertY:!1})=>{const{selector:i,creator:o,created:s,updated:r,updatedBy:a,...l}=e.target;let u;try{u=i.type==ee.RECTANGLE?An(i.geometry):Bn(i)}catch(c){if(n.strict)throw c;u=i}const h={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:bs(e.bodies),created:s==null?void 0:s.toISOString(),creator:o,modified:r==null?void 0:r.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:u}};return delete h.bodies,"annotation"in h.target&&delete h.target.annotation,h},Tt=(e,t)=>{const n=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))},Ke=[];function Ms(e,t=z){let n;const i=new Set;function o(a){if(ae(e,a)&&(e=a,n)){const l=!Ke.length;for(const u of i)u[1](),Ke.push(u,e);if(l){for(let u=0;u<Ke.length;u+=2)Ke[u][0](Ke[u+1]);Ke.length=0}}}function s(a){o(a(e))}function r(a,l=z){const u=[a,l];return i.add(u),i.size===1&&(n=t(o,s)||z),a(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const vs=(e,t)=>{const{naturalWidth:n,naturalHeight:i}=e;if(!n&&!i){const{width:o,height:s}=e;t.setAttribute("viewBox",`0 0 ${o} ${s}`),e.addEventListener("load",r=>{const a=r.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${i}`)},Kn=(e,t)=>{vs(e,t);const{subscribe:n,set:i}=Ms(1);let o;return window.ResizeObserver&&(o=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,u=Math.max(r.width/a,r.height/l);i(u)}),o.observe(t.parentElement)),{destroy:()=>{o&&o.disconnect()},subscribe:n}},at=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:i,fillOpacity:o,stroke:s,strokeWidth:r,strokeOpacity:a}=n;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${o||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${r||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ut=(e,t=0)=>{const{minX:n,minY:i,maxX:o,maxY:s}=e;return{x:n-t,y:i-t,w:o-n+2*t,h:s-i+2*t}},jt=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Ss=e=>({}),Jn=e=>({grab:e[0]});function Ns(e){let t,n,i,o;const s=e[8].default,r=Ki(s,e,e[7],Jn);return{c(){t=L("g"),r&&r.c(),f(t,"class","a9s-annotation selected")},m(a,l){P(a,t,l),r&&r.m(t,null),n=!0,i||(o=[$(t,"pointerup",e[2]),$(t,"pointermove",e[1])],i=!0)},p(a,[l]){r&&r.p&&(!n||l&128)&&xi(r,s,a,a[7],n?Ji(s,a[7],l,Ss):$i(a[7]),Jn)},i(a){n||(V(r,a),n=!0)},o(a){G(r,a),n=!1},d(a){a&&D(t),r&&r.d(a),i=!1,Ce(o)}}}function Cs(e,t,n){let{$$slots:i={},$$scope:o}=t;const s=Xe();let{shape:r}=t,{editor:a}=t,{transform:l}=t,{svgEl:u}=t,h,c,d;const y=w=>m=>{if(h=w,u){const{left:E,top:M}=u.getBoundingClientRect(),S=m.clientX-E,v=m.clientY-M;c=l.elementToImage(S,v)}else{const{offsetX:E,offsetY:M}=m;c=l.elementToImage(E,M)}d=r,m.target.setPointerCapture(m.pointerId),s("grab",m)},g=w=>{if(h){const[m,A]=l.elementToImage(w.offsetX,w.offsetY),E=[m-c[0],A-c[1]];n(3,r=a(d,h,E)),s("change",r)}},p=w=>{w.target.releasePointerCapture(w.pointerId),h=void 0,d=r,s("release",w)};return e.$$set=w=>{"shape"in w&&n(3,r=w.shape),"editor"in w&&n(4,a=w.editor),"transform"in w&&n(5,l=w.transform),"svgEl"in w&&n(6,u=w.svgEl),"$$scope"in w&&n(7,o=w.$$scope)},[y,g,p,r,a,l,u,o,i]}class At extends we{constructor(t){super(),me(this,t,Cs,Ns,ae,{shape:3,editor:4,transform:5,svgEl:6})}}function Rs(e){let t,n,i,o,s,r,a,l,u=e[3]&&xn(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),o=L("circle"),f(n,"class","a9s-handle-buffer svelte-19vpcvx"),f(n,"cx",e[0]),f(n,"cy",e[1]),f(n,"r",i=e[4]+6/e[2]),f(o,"class",s=gt(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-19vpcvx"),f(o,"cx",e[0]),f(o,"cy",e[1]),f(o,"r",e[4]),f(t,"class",r=gt(`a9s-handle ${e[7].class||""}`.trim())+" svelte-19vpcvx")},m(h,c){P(h,t,c),Z(t,n),u&&u.m(t,null),Z(t,o),a||(l=[$(n,"pointerenter",e[8]),$(n,"pointerleave",e[9]),$(n,"pointerdown",e[10]),$(n,"pointerdown",e[5]),$(n,"pointerup",e[11]),$(n,"pointerup",e[6])],a=!0)},p(h,c){c&1&&f(n,"cx",h[0]),c&2&&f(n,"cy",h[1]),c&20&&i!==(i=h[4]+6/h[2])&&f(n,"r",i),h[3]?u?u.p(h,c):(u=xn(h),u.c(),u.m(t,o)):u&&(u.d(1),u=null),c&8&&s!==(s=gt(`a9s-handle-dot${h[3]?" selected":""}`)+" svelte-19vpcvx")&&f(o,"class",s),c&1&&f(o,"cx",h[0]),c&2&&f(o,"cy",h[1]),c&16&&f(o,"r",h[4]),c&128&&r!==(r=gt(`a9s-handle ${h[7].class||""}`.trim())+" svelte-19vpcvx")&&f(t,"class",r)},d(h){h&&D(t),u&&u.d(),a=!1,Ce(l)}}}function Is(e){let t,n;return{c(){t=L("circle"),f(t,"cx",e[0]),f(t,"cy",e[1]),f(t,"r",n=2*e[4])},m(i,o){P(i,t,o)},p(i,o){o&1&&f(t,"cx",i[0]),o&2&&f(t,"cy",i[1]),o&16&&n!==(n=2*i[4])&&f(t,"r",n)},d(i){i&&D(t)}}}function xn(e){let t,n;return{c(){t=L("circle"),f(t,"class","a9s-handle-selected svelte-19vpcvx"),f(t,"cx",e[0]),f(t,"cy",e[1]),f(t,"r",n=e[4]+6/e[2])},m(i,o){P(i,t,o)},p(i,o){o&1&&f(t,"cx",i[0]),o&2&&f(t,"cy",i[1]),o&20&&n!==(n=i[4]+6/i[2])&&f(t,"r",n)},d(i){i&&D(t)}}}function Ls(e){let t;function n(s,r){return jt?Is:Rs}let o=n()(e);return{c(){o.c(),t=Te()},m(s,r){o.m(s,r),P(s,t,r)},p(s,[r]){o.p(s,r)},i:z,o:z,d(s){s&&D(t),o.d(s)}}}function ks(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t,{selected:a=void 0}=t;const l=g=>{g.pointerType},u=()=>!1;function h(g){Ae.call(this,e,g)}function c(g){Ae.call(this,e,g)}function d(g){Ae.call(this,e,g)}function y(g){Ae.call(this,e,g)}return e.$$set=g=>{n(7,t=ke(ke({},t),cn(g))),"x"in g&&n(0,o=g.x),"y"in g&&n(1,s=g.y),"scale"in g&&n(2,r=g.scale),"selected"in g&&n(3,a=g.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(4,i=4/r)},t=cn(t),[o,s,r,a,i,l,u,t,h,c,d,y]}class je extends we{constructor(t){super(),me(this,t,ks,Ls,ae,{x:0,y:1,scale:2,selected:3})}}function Ds(e){let t,n,i,o,s,r,a;return{c(){t=L("g"),n=L("circle"),o=L("circle"),s=L("circle"),f(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),f(n,"cx",e[0]),f(n,"cy",e[1]),f(n,"r",i=1.75*e[2]),f(o,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),f(o,"cx",e[0]),f(o,"cy",e[1]),f(o,"r",e[2]),f(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),f(s,"cx",e[0]),f(s,"cy",e[1]),f(s,"r",e[2]),f(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,u){P(l,t,u),Z(t,n),Z(t,o),Z(t,s),r||(a=[$(n,"pointerdown",e[5]),$(n,"pointerdown",e[3])],r=!0)},p(l,u){u&1&&f(n,"cx",l[0]),u&2&&f(n,"cy",l[1]),u&4&&i!==(i=1.75*l[2])&&f(n,"r",i),u&1&&f(o,"cx",l[0]),u&2&&f(o,"cy",l[1]),u&4&&f(o,"r",l[2]),u&1&&f(s,"cx",l[0]),u&2&&f(s,"cy",l[1]),u&4&&f(s,"r",l[2])},d(l){l&&D(t),r=!1,Ce(a)}}}function Ps(e){let t;return{c(){t=L("circle"),f(t,"cx",e[0]),f(t,"cy",e[1]),f(t,"r",e[2])},m(n,i){P(n,t,i)},p(n,i){i&1&&f(t,"cx",n[0]),i&2&&f(t,"cy",n[1]),i&4&&f(t,"r",n[2])},d(n){n&&D(t)}}}function Us(e){let t;function n(s,r){return jt?Ps:Ds}let o=n()(e);return{c(){o.c(),t=Te()},m(s,r){o.m(s,r),P(s,t,r)},p(s,[r]){o.p(s,r)},i:z,o:z,d(s){s&&D(t),o.d(s)}}}function Vs(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t;const a=u=>{u.pointerType};function l(u){Ae.call(this,e,u)}return e.$$set=u=>{"x"in u&&n(0,o=u.x),"y"in u&&n(1,s=u.y),"scale"in u&&n(4,r=u.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,i=4/r)},[o,s,i,a,r,l]}class Hs extends we{constructor(t){super(),me(this,t,Vs,Us,ae,{x:0,y:1,scale:4})}}function zt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function $n(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function Qt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function qt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function ei(e){let t,n,i,o;return{c(){t=L("circle"),f(t,"cx",n=e[30][0]),f(t,"cy",i=e[30][1]),f(t,"r",o=ft/e[3]),f(t,"class","svelte-1h2slbm")},m(s,r){P(s,t,r)},p(s,r){r[0]&2176&&n!==(n=s[30][0])&&f(t,"cx",n),r[0]&2176&&i!==(i=s[30][1])&&f(t,"cy",i),r[0]&8&&o!==(o=ft/s[3])&&f(t,"r",o)},d(s){s&&D(t)}}}function ti(e){let t,n,i,o,s,r,a,l,u,h;return{c(){t=L("mask"),n=L("rect"),a=L("circle"),f(n,"x",i=e[10].x),f(n,"y",o=e[10].y),f(n,"width",s=e[10].w),f(n,"height",r=e[10].h),f(n,"class","svelte-1h2slbm"),f(a,"cx",l=e[30][0]),f(a,"cy",u=e[30][1]),f(a,"r",h=ft/e[3]),f(a,"class","svelte-1h2slbm"),f(t,"id",`${e[20]}-inner`),f(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){P(c,t,d),Z(t,n),Z(t,a)},p(c,d){d[0]&1024&&i!==(i=c[10].x)&&f(n,"x",i),d[0]&1024&&o!==(o=c[10].y)&&f(n,"y",o),d[0]&1024&&s!==(s=c[10].w)&&f(n,"width",s),d[0]&1024&&r!==(r=c[10].h)&&f(n,"height",r),d[0]&2176&&l!==(l=c[30][0])&&f(a,"cx",l),d[0]&2176&&u!==(u=c[30][1])&&f(a,"cy",u),d[0]&8&&h!==(h=ft/c[3])&&f(a,"r",h)},d(c){c&&D(t)}}}function ni(e){let t,n;return t=new je({props:{class:"a9s-corner-handle",x:e[30][0],y:e[30][1],scale:e[3],selected:e[9].includes(e[32])}}),t.$on("pointerenter",e[12]),t.$on("pointerleave",e[13]),t.$on("pointerdown",e[16]),t.$on("pointerdown",function(){ie(e[29](`HANDLE-${e[32]}`))&&e[29](`HANDLE-${e[32]}`).apply(this,arguments)}),t.$on("pointerup",e[17](e[32])),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&32&&(s.x=e[30][0]),o[0]&32&&(s.y=e[30][1]),o[0]&8&&(s.scale=e[3]),o[0]&512&&(s.selected=e[9].includes(e[32])),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function ii(e){let t,n;return t=new Hs({props:{x:e[30][0],y:e[30][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[19](e[7]))&&e[19](e[7]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&2176&&(s.x=e[30][0]),o[0]&2176&&(s.y=e[30][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Bs(e){let t,n,i,o,s,r,a,l,u,h,c,d,y,g,p,w,m,A,E,M,S,v=e[7]!==void 0&&!e[8]&&ei(qt(e)),N=e[7]!==void 0&&!e[8]&&ti(Qt(e)),H=Oe(e[5].points),B=[];for(let _=0;_<H.length;_+=1)B[_]=ni($n(e,H,_));const X=_=>G(B[_],1,1,()=>{B[_]=null});let j=e[7]!==void 0&&!e[8]&&ii(zt(e));return{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("polygon"),v&&v.c(),N&&N.c(),h=be(),c=L("polygon"),y=be(),g=L("polygon"),w=be();for(let _=0;_<B.length;_+=1)B[_].c();m=be(),j&&j.c(),A=Te(),f(i,"x",o=e[10].x),f(i,"y",s=e[10].y),f(i,"width",r=e[10].w),f(i,"height",a=e[10].h),f(i,"class","svelte-1h2slbm"),f(l,"points",u=e[5].points.map(oi).join(" ")),f(l,"class","svelte-1h2slbm"),f(n,"id",`${e[20]}-outer`),f(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),f(c,"class","a9s-outer"),f(c,"mask",`url(#${e[20]}-outer)`),f(c,"points",d=e[5].points.map(si).join(" ")),f(g,"class","a9s-inner a9s-shape-handle"),f(g,"mask",`url(#${e[20]}-inner)`),f(g,"style",e[1]),f(g,"points",p=e[5].points.map(ri).join(" "))},m(_,b){P(_,t,b),Z(t,n),Z(n,i),Z(n,l),v&&v.m(n,null),N&&N.m(t,null),P(_,h,b),P(_,c,b),P(_,y,b),P(_,g,b),e[21](g),P(_,w,b);for(let O=0;O<B.length;O+=1)B[O]&&B[O].m(_,b);P(_,m,b),j&&j.m(_,b),P(_,A,b),E=!0,M||(S=[$(c,"pointerup",e[15]),$(c,"pointerdown",function(){ie(e[29]("SHAPE"))&&e[29]("SHAPE").apply(this,arguments)}),$(g,"pointermove",e[14]),$(g,"pointerup",e[15]),$(g,"pointerdown",function(){ie(e[29]("SHAPE"))&&e[29]("SHAPE").apply(this,arguments)})],M=!0)},p(_,b){if(e=_,(!E||b[0]&1024&&o!==(o=e[10].x))&&f(i,"x",o),(!E||b[0]&1024&&s!==(s=e[10].y))&&f(i,"y",s),(!E||b[0]&1024&&r!==(r=e[10].w))&&f(i,"width",r),(!E||b[0]&1024&&a!==(a=e[10].h))&&f(i,"height",a),(!E||b[0]&32&&u!==(u=e[5].points.map(oi).join(" ")))&&f(l,"points",u),e[7]!==void 0&&!e[8]?v?v.p(qt(e),b):(v=ei(qt(e)),v.c(),v.m(n,null)):v&&(v.d(1),v=null),e[7]!==void 0&&!e[8]?N?N.p(Qt(e),b):(N=ti(Qt(e)),N.c(),N.m(t,null)):N&&(N.d(1),N=null),(!E||b[0]&32&&d!==(d=e[5].points.map(si).join(" ")))&&f(c,"points",d),(!E||b[0]&2)&&f(g,"style",e[1]),(!E||b[0]&32&&p!==(p=e[5].points.map(ri).join(" ")))&&f(g,"points",p),b[0]&537080360){H=Oe(e[5].points);let O;for(O=0;O<H.length;O+=1){const C=$n(e,H,O);B[O]?(B[O].p(C,b),V(B[O],1)):(B[O]=ni(C),B[O].c(),V(B[O],1),B[O].m(m.parentNode,m))}for(ye(),O=H.length;O<B.length;O+=1)X(O);_e()}e[7]!==void 0&&!e[8]?j?(j.p(zt(e),b),b[0]&384&&V(j,1)):(j=ii(zt(e)),j.c(),V(j,1),j.m(A.parentNode,A)):j&&(ye(),G(j,1,1,()=>{j=null}),_e())},i(_){if(!E){for(let b=0;b<H.length;b+=1)V(B[b]);V(j),E=!0}},o(_){B=B.filter(Boolean);for(let b=0;b<B.length;b+=1)G(B[b]);G(j),E=!1},d(_){_&&(D(t),D(h),D(c),D(y),D(g),D(w),D(m),D(A)),v&&v.d(),N&&N.d(),e[21](null),Ye(B,_),j&&j.d(_),M=!1,Ce(S)}}}function Ys(e){let t,n;return t=new At({props:{shape:e[0],transform:e[2],editor:e[18],svgEl:e[4],$$slots:{default:[Bs,({grab:i})=>({29:i}),({grab:i})=>[i?536870912:0]]},$$scope:{ctx:e}}}),t.$on("change",e[22]),t.$on("grab",e[23]),t.$on("release",e[24]),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&1&&(s.shape=i[0]),o[0]&4&&(s.transform=i[2]),o[0]&16&&(s.svgEl=i[4]),o[0]&536874986|o[1]&4&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}const Xs=250,Fs=1e3,Gs=12,ft=4.5,oi=e=>e.join(","),si=e=>e.join(","),ri=e=>e.join(",");function js(e,t,n){let i,o,s;const r=Xe();let{shape:a}=t,{computedStyle:l}=t,{transform:u}=t,{viewportScale:h=1}=t,{svgEl:c}=t,d,y,g=!1,p,w=[];const m=()=>n(8,g=!0),A=()=>n(8,g=!1),E=R=>{if(w.length>0){n(7,y=void 0);return}const[I,Y]=u.elementToImage(R.offsetX,R.offsetY),Q=re=>Math.pow(re[0]-I,2)+Math.pow(re[1]-Y,2),J=i.points.reduce((re,le)=>Q(le)<Q(re)?le:re),Me=o.filter(re=>re.visible).reduce((re,le)=>Q(le.point)<Q(re.point)?le:re),ue=Math.pow(Fs/h,2);Q(J)<ue||Q(Me.point)<ue?n(7,y=o.indexOf(Me)):n(7,y=void 0)},M=()=>{document.activeElement!==c&&c.focus()},S=()=>{n(9,w=[]),M()},v=R=>{n(8,g=!0),R.preventDefault(),R.stopPropagation(),p=performance.now()},N=R=>I=>{if(!p||performance.now()-p>Xs)return;const Y=w.includes(R);I.metaKey||I.ctrlKey||I.shiftKey?Y?n(9,w=w.filter(Q=>Q!==R)):n(9,w=[...w,R]):Y&&w.length>1?n(9,w=[R]):Y?n(9,w=[]):n(9,w=[R]),M()},H=(R,I,Y)=>{M();let Q;const J=R.geometry;w.length>1?Q=J.points.map(([ue,Ee],re)=>w.includes(re)?[ue+Y[0],Ee+Y[1]]:[ue,Ee]):I==="SHAPE"?Q=J.points.map(([ue,Ee])=>[ue+Y[0],Ee+Y[1]]):Q=J.points.map(([ue,Ee],re)=>I===`HANDLE-${re}`?[ue+Y[0],Ee+Y[1]]:[ue,Ee]);const Me=Se(Q);return{...R,geometry:{points:Q,bounds:Me}}},B=R=>async I=>{I.stopPropagation();const Y=[...i.points.slice(0,R+1),o[R].point,...i.points.slice(R+1)],Q=Se(Y);r("change",{...a,geometry:{points:Y,bounds:Q}}),await no();const J=[...document.querySelectorAll(".a9s-handle")][R+1];if(J!=null&&J.firstChild){const Me=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:I.clientX,clientY:I.clientY,pointerId:I.pointerId,pointerType:I.pointerType,isPrimary:I.isPrimary,buttons:I.buttons});J.firstChild.dispatchEvent(Me)}},X=()=>{if(i.points.length<4)return;const R=i.points.filter((Y,Q)=>!w.includes(Q)),I=Se(R);r("change",{...a,geometry:{points:R,bounds:I}}),n(9,w=[])};ze(()=>{const R=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),X())};return c.addEventListener("pointermove",E),c.addEventListener("keydown",R),()=>{c.removeEventListener("pointermove",E),c.removeEventListener("keydown",R)}});const j=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function _(R){ot[R?"unshift":"push"](()=>{d=R,n(6,d)})}function b(R){Ae.call(this,e,R)}function O(R){Ae.call(this,e,R)}function C(R){Ae.call(this,e,R)}return e.$$set=R=>{"shape"in R&&n(0,a=R.shape),"computedStyle"in R&&n(1,l=R.computedStyle),"transform"in R&&n(2,u=R.transform),"viewportScale"in R&&n(3,h=R.viewportScale),"svgEl"in R&&n(4,c=R.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=a.geometry),e.$$.dirty[0]&40&&n(11,o=i.points.map((R,I)=>{const Y=I===i.points.length-1?i.points[0]:i.points[I+1],Q=(R[0]+Y[0])/2,J=(R[1]+Y[1])/2,ue=Math.sqrt(Math.pow(Y[0]-Q,2)+Math.pow(Y[1]-J,2))>Gs/h;return{point:[Q,J],visible:ue}})),e.$$.dirty[0]&40&&n(10,s=ut(i.bounds,ft/h))},[a,l,u,h,c,i,d,y,g,w,s,o,m,A,E,S,v,N,H,B,j,_,b,O,C]}class li extends we{constructor(t){super(),me(this,t,js,Ys,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function zs(e){let t,n,i,o,s,r,a,l,u,h,c,d,y,g,p,w,m,A,E,M,S,v,N,H,B,X,j,_,b,O,C,R,I,Y,Q,J,Me,ue,Ee,re,le,$e,et,F,ge,K,Ne,ve,tt,He,sn,Be,W,rn,Zi;return K=new je({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),K.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),ve=new je({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),ve.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),He=new je({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),He.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Be=new je({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Be.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("rect"),y=be(),g=L("rect"),E=be(),M=L("rect"),B=be(),X=L("rect"),O=be(),C=L("rect"),Q=be(),J=L("rect"),re=be(),le=L("rect"),ge=be(),pe(K.$$.fragment),Ne=be(),pe(ve.$$.fragment),tt=be(),pe(He.$$.fragment),sn=be(),pe(Be.$$.fragment),f(i,"class","rect-mask-bg svelte-1njczvj"),f(i,"x",o=e[6].x),f(i,"y",s=e[6].y),f(i,"width",r=e[6].w),f(i,"height",a=e[6].h),f(l,"class","rect-mask-fg svelte-1njczvj"),f(l,"x",u=e[5].x),f(l,"y",h=e[5].y),f(l,"width",c=e[5].w),f(l,"height",d=e[5].h),f(n,"id",e[8]),f(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),f(g,"class","a9s-outer"),f(g,"mask",`url(#${e[8]})`),f(g,"x",p=e[5].x),f(g,"y",w=e[5].y),f(g,"width",m=e[5].w),f(g,"height",A=e[5].h),f(M,"class","a9s-inner a9s-shape-handle"),f(M,"style",e[1]),f(M,"x",S=e[5].x),f(M,"y",v=e[5].y),f(M,"width",N=e[5].w),f(M,"height",H=e[5].h),f(X,"class","a9s-edge-handle a9s-edge-handle-top"),f(X,"x",j=e[5].x),f(X,"y",_=e[5].y),f(X,"height",1),f(X,"width",b=e[5].w),f(C,"class","a9s-edge-handle a9s-edge-handle-right"),f(C,"x",R=e[5].x+e[5].w),f(C,"y",I=e[5].y),f(C,"height",Y=e[5].h),f(C,"width",1),f(J,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(J,"x",Me=e[5].x),f(J,"y",ue=e[5].y+e[5].h),f(J,"height",1),f(J,"width",Ee=e[5].w),f(le,"class","a9s-edge-handle a9s-edge-handle-left"),f(le,"x",$e=e[5].x),f(le,"y",et=e[5].y),f(le,"height",F=e[5].h),f(le,"width",1)},m(q,U){P(q,t,U),Z(t,n),Z(n,i),Z(n,l),P(q,y,U),P(q,g,U),P(q,E,U),P(q,M,U),P(q,B,U),P(q,X,U),P(q,O,U),P(q,C,U),P(q,Q,U),P(q,J,U),P(q,re,U),P(q,le,U),P(q,ge,U),fe(K,q,U),P(q,Ne,U),fe(ve,q,U),P(q,tt,U),fe(He,q,U),P(q,sn,U),fe(Be,q,U),W=!0,rn||(Zi=[$(g,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),$(M,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),$(X,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),$(C,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),$(J,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),$(le,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],rn=!0)},p(q,U){e=q,(!W||U&64&&o!==(o=e[6].x))&&f(i,"x",o),(!W||U&64&&s!==(s=e[6].y))&&f(i,"y",s),(!W||U&64&&r!==(r=e[6].w))&&f(i,"width",r),(!W||U&64&&a!==(a=e[6].h))&&f(i,"height",a),(!W||U&32&&u!==(u=e[5].x))&&f(l,"x",u),(!W||U&32&&h!==(h=e[5].y))&&f(l,"y",h),(!W||U&32&&c!==(c=e[5].w))&&f(l,"width",c),(!W||U&32&&d!==(d=e[5].h))&&f(l,"height",d),(!W||U&32&&p!==(p=e[5].x))&&f(g,"x",p),(!W||U&32&&w!==(w=e[5].y))&&f(g,"y",w),(!W||U&32&&m!==(m=e[5].w))&&f(g,"width",m),(!W||U&32&&A!==(A=e[5].h))&&f(g,"height",A),(!W||U&2)&&f(M,"style",e[1]),(!W||U&32&&S!==(S=e[5].x))&&f(M,"x",S),(!W||U&32&&v!==(v=e[5].y))&&f(M,"y",v),(!W||U&32&&N!==(N=e[5].w))&&f(M,"width",N),(!W||U&32&&H!==(H=e[5].h))&&f(M,"height",H),(!W||U&32&&j!==(j=e[5].x))&&f(X,"x",j),(!W||U&32&&_!==(_=e[5].y))&&f(X,"y",_),(!W||U&32&&b!==(b=e[5].w))&&f(X,"width",b),(!W||U&32&&R!==(R=e[5].x+e[5].w))&&f(C,"x",R),(!W||U&32&&I!==(I=e[5].y))&&f(C,"y",I),(!W||U&32&&Y!==(Y=e[5].h))&&f(C,"height",Y),(!W||U&32&&Me!==(Me=e[5].x))&&f(J,"x",Me),(!W||U&32&&ue!==(ue=e[5].y+e[5].h))&&f(J,"y",ue),(!W||U&32&&Ee!==(Ee=e[5].w))&&f(J,"width",Ee),(!W||U&32&&$e!==($e=e[5].x))&&f(le,"x",$e),(!W||U&32&&et!==(et=e[5].y))&&f(le,"y",et),(!W||U&32&&F!==(F=e[5].h))&&f(le,"height",F);const vt={};U&32&&(vt.x=e[5].x),U&32&&(vt.y=e[5].y),U&8&&(vt.scale=e[3]),K.$set(vt);const St={};U&32&&(St.x=e[5].x+e[5].w),U&32&&(St.y=e[5].y),U&8&&(St.scale=e[3]),ve.$set(St);const Nt={};U&32&&(Nt.x=e[5].x+e[5].w),U&32&&(Nt.y=e[5].y+e[5].h),U&8&&(Nt.scale=e[3]),He.$set(Nt);const Ct={};U&32&&(Ct.x=e[5].x),U&32&&(Ct.y=e[5].y+e[5].h),U&8&&(Ct.scale=e[3]),Be.$set(Ct)},i(q){W||(V(K.$$.fragment,q),V(ve.$$.fragment,q),V(He.$$.fragment,q),V(Be.$$.fragment,q),W=!0)},o(q){G(K.$$.fragment,q),G(ve.$$.fragment,q),G(He.$$.fragment,q),G(Be.$$.fragment,q),W=!1},d(q){q&&(D(t),D(y),D(g),D(E),D(M),D(B),D(X),D(O),D(C),D(Q),D(J),D(re),D(le),D(ge),D(Ne),D(tt),D(sn)),ce(K,q),ce(ve,q),ce(He,q),ce(Be,q),rn=!1,Ce(Zi)}}}function Qs(e){let t,n;return t=new At({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[zs,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,[o]){const s={};o&1&&(s.shape=i[0]),o&4&&(s.transform=i[2]),o&16&&(s.svgEl=i[4]),o&12394&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function qs(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:u}=t;const h=(p,w,m)=>{const A=p.geometry.bounds;let[E,M]=[A.minX,A.minY],[S,v]=[A.maxX,A.maxY];const[N,H]=m;if(w==="SHAPE")E+=N,S+=N,M+=H,v+=H;else{switch(w){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{M+=H;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{v+=H;break}}switch(w){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{E+=N;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=N;break}}}const B=Math.min(E,S),X=Math.min(M,v),j=Math.abs(S-E),_=Math.abs(v-M);return{...p,geometry:{x:B,y:X,w:j,h:_,bounds:{minX:B,minY:X,maxX:B+j,maxY:X+_}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(p){Ae.call(this,e,p)}function y(p){Ae.call(this,e,p)}function g(p){Ae.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,s=p.shape),"computedStyle"in p&&n(1,r=p.computedStyle),"transform"in p&&n(2,a=p.transform),"viewportScale"in p&&n(3,l=p.viewportScale),"svgEl"in p&&n(4,u=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ut(i.bounds,2/l))},[s,r,a,l,u,i,o,h,c,d,y,g]}class ai extends we{constructor(t){super(),me(this,t,qs,Qs,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}function ui(e,t,n){const i=e.slice();return i[13]=t[n],i[15]=n,i}function fi(e,t,n){const i=e.slice();return i[16]=t[n],i[18]=n,i}function ci(e,t,n){const i=e.slice();return i[19]=t[n],i[21]=n,i}function hi(e){let t,n;return t=new je({props:{class:"a9s-corner-handle",x:e[19][0],y:e[19][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[12](`HANDLE-${e[15]}-${e[18]}-${e[21]}`))&&e[12](`HANDLE-${e[15]}-${e[18]}-${e[21]}`).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o&32&&(s.x=e[19][0]),o&32&&(s.y=e[19][1]),o&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function di(e){let t,n,i=Oe(e[16].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=hi(ci(e,i,r));const s=r=>G(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Te()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a&4136){i=Oe(r[16].points);let l;for(l=0;l<i.length;l+=1){const u=ci(r,i,l);o[l]?(o[l].p(u,a),V(o[l],1)):(o[l]=hi(u),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(ye(),l=i.length;l<o.length;l+=1)s(l);_e()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)G(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function gi(e){let t,n,i,o,s,r,a,l,u,h,c,d,y,g,p,w,m,A=Oe(e[13].rings),E=[];for(let S=0;S<A.length;S+=1)E[S]=di(fi(e,A,S));const M=S=>G(E[S],1,1,()=>{E[S]=null});return{c(){t=L("g"),n=L("defs"),i=L("mask"),o=L("rect"),u=L("path"),c=L("path"),y=L("path");for(let S=0;S<E.length;S+=1)E[S].c();f(o,"x",s=e[6].x),f(o,"y",r=e[6].y),f(o,"width",a=e[6].w),f(o,"height",l=e[6].h),f(o,"class","svelte-rfq8ys"),f(u,"d",h=Le(e[13])),f(u,"class","svelte-rfq8ys"),f(i,"id",`${e[8]}-${e[15]}`),f(i,"class","a9s-multipolygon-editor-mask svelte-rfq8ys"),f(c,"class","a9s-outer"),f(c,"mask",`url(#${e[8]}-${e[15]})`),f(c,"fill-rule","evenodd"),f(c,"d",d=Le(e[13])),f(y,"class","a9s-inner"),f(y,"style",e[1]),f(y,"fill-rule","evenodd"),f(y,"d",g=Le(e[13]))},m(S,v){P(S,t,v),Z(t,n),Z(n,i),Z(i,o),Z(i,u),Z(t,c),Z(t,y);for(let N=0;N<E.length;N+=1)E[N]&&E[N].m(t,null);p=!0,w||(m=[$(c,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),$(y,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)})],w=!0)},p(S,v){if(e=S,(!p||v&64&&s!==(s=e[6].x))&&f(o,"x",s),(!p||v&64&&r!==(r=e[6].y))&&f(o,"y",r),(!p||v&64&&a!==(a=e[6].w))&&f(o,"width",a),(!p||v&64&&l!==(l=e[6].h))&&f(o,"height",l),(!p||v&32&&h!==(h=Le(e[13])))&&f(u,"d",h),(!p||v&32&&d!==(d=Le(e[13])))&&f(c,"d",d),(!p||v&2)&&f(y,"style",e[1]),(!p||v&32&&g!==(g=Le(e[13])))&&f(y,"d",g),v&4136){A=Oe(e[13].rings);let N;for(N=0;N<A.length;N+=1){const H=fi(e,A,N);E[N]?(E[N].p(H,v),V(E[N],1)):(E[N]=di(H),E[N].c(),V(E[N],1),E[N].m(t,null))}for(ye(),N=A.length;N<E.length;N+=1)M(N);_e()}},i(S){if(!p){for(let v=0;v<A.length;v+=1)V(E[v]);p=!0}},o(S){E=E.filter(Boolean);for(let v=0;v<E.length;v+=1)G(E[v]);p=!1},d(S){S&&D(t),Ye(E,S),w=!1,Ce(m)}}}function Zs(e){let t,n,i=Oe(e[5].polygons),o=[];for(let r=0;r<i.length;r+=1)o[r]=gi(ui(e,i,r));const s=r=>G(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Te()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a&4458){i=Oe(r[5].polygons);let l;for(l=0;l<i.length;l+=1){const u=ui(r,i,l);o[l]?(o[l].p(u,a),V(o[l],1)):(o[l]=gi(u),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(ye(),l=i.length;l<o.length;l+=1)s(l);_e()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)G(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function Ws(e){let t,n;return t=new At({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Zs,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:e}}}),t.$on("change",e[9]),t.$on("grab",e[10]),t.$on("release",e[11]),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,[o]){const s={};o&1&&(s.shape=i[0]),o&4&&(s.transform=i[2]),o&16&&(s.svgEl=i[4]),o&4198506&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Ks(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:u}=t;const h=(p,w,m)=>{const A=p.geometry.polygons;let E;if(w==="SHAPE")E=A.map(M=>{const S=M.rings.map((N,H)=>({points:N.points.map((X,j)=>[X[0]+m[0],X[1]+m[1]])})),v=Se(S[0].points);return{rings:S,bounds:v}});else{const[M,S,v,N]=w.split("-").map(H=>parseInt(H));E=A.map((H,B)=>{if(B===S){const X=H.rings.map((_,b)=>b===v?{points:_.points.map((C,R)=>R===N?[C[0]+m[0],C[1]+m[1]]:C)}:_),j=Se(X[0].points);return{rings:X,bounds:j}}else return H})}return{...p,geometry:{polygons:E,bounds:En(E)}}},c=`multipoly-mask-${Math.random().toString(36).substring(2,12)}`;function d(p){Ae.call(this,e,p)}function y(p){Ae.call(this,e,p)}function g(p){Ae.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,s=p.shape),"computedStyle"in p&&n(1,r=p.computedStyle),"transform"in p&&n(2,a=p.transform),"viewportScale"in p&&n(3,l=p.viewportScale),"svgEl"in p&&n(4,u=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ut(i.bounds,2/l))},[s,r,a,l,u,i,o,h,c,d,y,g]}class Js extends we{constructor(t){super(),me(this,t,Ks,Ws,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}const pi=new Map([[ee.RECTANGLE,ai],[ee.POLYGON,li],[ee.MULTIPOLYGLON,Js]]),yi=e=>pi.get(e.type),_i=(e,t)=>pi.set(e,t);function xs(e,t,n){let i;const o=Xe();let{annotation:s}=t,{editor:r}=t,{style:a}=t,{target:l}=t,{transform:u}=t,{viewportScale:h}=t,c;return ze(()=>(n(6,c=new r({target:l,props:{shape:s.target.selector,computedStyle:i,transform:u,viewportScale:h,svgEl:l.closest("svg")}})),c.$on("change",d=>{c.$$set({shape:d.detail}),o("change",d.detail)}),c.$on("grab",d=>o("grab",d.detail)),c.$on("release",d=>o("release",d.detail)),()=>{c.$destroy()})),e.$$set=d=>{"annotation"in d&&n(0,s=d.annotation),"editor"in d&&n(1,r=d.editor),"style"in d&&n(2,a=d.style),"target"in d&&n(3,l=d.target),"transform"in d&&n(4,u=d.transform),"viewportScale"in d&&n(5,h=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,i=at(s,a)),e.$$.dirty&65&&s&&(c==null||c.$set({shape:s.target.selector})),e.$$.dirty&80&&c&&c.$set({transform:u}),e.$$.dirty&96&&c&&c.$set({viewportScale:h}),e.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[s,r,a,l,u,h,c,i]}class mi extends we{constructor(t){super(),me(this,t,xs,null,ae,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function $s(e,t,n){const i=Xe();let{drawingMode:o}=t,{target:s}=t,{tool:r}=t,{transform:a}=t,{viewportScale:l}=t,u;return ze(()=>{const h=s.closest("svg"),c=[],d=(y,g,p)=>{h==null||h.addEventListener(y,g,p),c.push(()=>h==null?void 0:h.removeEventListener(y,g,p))};return n(5,u=new r({target:s,props:{addEventListener:d,drawingMode:o,transform:a,viewportScale:l}})),u.$on("create",y=>i("create",y.detail)),()=>{c.forEach(y=>y()),u.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,o=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,a=h.transform),"viewportScale"in h&&n(4,l=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:a}),e.$$.dirty&48&&u&&u.$set({viewportScale:l})},[o,s,r,a,l,u]}class wi extends we{constructor(t){super(),me(this,t,$s,null,ae,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Ei(e){let t,n,i,o,s,r,a,l,u,h;return{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("rect"),u=L("rect"),h=L("rect"),f(i,"class","rect-mask-bg svelte-1a76qe7"),f(i,"x",o=e[1]-e[5]),f(i,"y",s=e[2]-e[5]),f(i,"width",r=e[3]+2*e[5]),f(i,"height",a=e[4]+2*e[5]),f(l,"class","rect-mask-fg svelte-1a76qe7"),f(l,"x",e[1]),f(l,"y",e[2]),f(l,"width",e[3]),f(l,"height",e[4]),f(n,"id",e[6]),f(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),f(u,"class","a9s-outer"),f(u,"mask",`url(#${e[6]})`),f(u,"x",e[1]),f(u,"y",e[2]),f(u,"width",e[3]),f(u,"height",e[4]),f(h,"class","a9s-inner"),f(h,"x",e[1]),f(h,"y",e[2]),f(h,"width",e[3]),f(h,"height",e[4])},m(c,d){P(c,t,d),Z(t,n),Z(n,i),Z(n,l),P(c,u,d),P(c,h,d)},p(c,d){d&34&&o!==(o=c[1]-c[5])&&f(i,"x",o),d&36&&s!==(s=c[2]-c[5])&&f(i,"y",s),d&40&&r!==(r=c[3]+2*c[5])&&f(i,"width",r),d&48&&a!==(a=c[4]+2*c[5])&&f(i,"height",a),d&2&&f(l,"x",c[1]),d&4&&f(l,"y",c[2]),d&8&&f(l,"width",c[3]),d&16&&f(l,"height",c[4]),d&2&&f(u,"x",c[1]),d&4&&f(u,"y",c[2]),d&8&&f(u,"width",c[3]),d&16&&f(u,"height",c[4]),d&2&&f(h,"x",c[1]),d&4&&f(h,"y",c[2]),d&8&&f(h,"width",c[3]),d&16&&f(h,"height",c[4])},d(c){c&&(D(t),D(u),D(h))}}}function er(e){let t,n=e[0]&&Ei(e);return{c(){t=L("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(i,o){P(i,t,o),n&&n.m(t,null)},p(i,[o]){i[0]?n?n.p(i,o):(n=Ei(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:z,o:z,d(i){i&&D(t),n&&n.d()}}}function tr(e,t,n){let i;const o=Xe();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:a}=t,{viewportScale:l=1}=t,u,h,c,d,y,g,p;const w=S=>{const v=S;u=performance.now(),r==="drag"&&(n(0,h=a.elementToImage(v.offsetX,v.offsetY)),c=h,n(1,d=h[0]),n(2,y=h[1]),n(3,g=1),n(4,p=1))},m=S=>{const v=S;h&&(c=a.elementToImage(v.offsetX,v.offsetY),n(1,d=Math.min(c[0],h[0])),n(2,y=Math.min(c[1],h[1])),n(3,g=Math.abs(c[0]-h[0])),n(4,p=Math.abs(c[1]-h[1])))},A=S=>{const v=S,N=performance.now()-u;if(r==="click"){if(N>300)return;h?E():(n(0,h=a.elementToImage(v.offsetX,v.offsetY)),c=h,n(1,d=h[0]),n(2,y=h[1]),n(3,g=1),n(4,p=1))}else h&&(N>300||g*p>100?(v.stopPropagation(),E()):(n(0,h=void 0),c=void 0))},E=()=>{if(g*p>15){const S={type:ee.RECTANGLE,geometry:{bounds:{minX:d,minY:y,maxX:d+g,maxY:y+p},x:d,y,w:g,h:p}};o("create",S)}n(0,h=void 0),c=void 0};ze(()=>{s("pointerdown",w),s("pointermove",m),s("pointerup",A,!0)});const M=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=S=>{"addEventListener"in S&&n(7,s=S.addEventListener),"drawingMode"in S&&n(8,r=S.drawingMode),"transform"in S&&n(9,a=S.transform),"viewportScale"in S&&n(10,l=S.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,i=2/l)},[h,d,y,g,p,i,M,s,r,a,l]}class bi extends we{constructor(t){super(),me(this,t,tr,er,ae,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Zt(e){const t=e.slice(),n=t[2].map(i=>i.join(",")).join(" ");return t[19]=n,t}function Ti(e){let t,n,i,o,s,r,a,l,u,h,c,d,y,g,p=e[1]&&Ai(e);return{c(){t=L("defs"),n=L("mask"),i=L("rect"),l=L("polygon"),h=L("polygon"),d=L("polygon"),p&&p.c(),g=Te(),f(i,"x",o=e[3].x),f(i,"y",s=e[3].y),f(i,"width",r=e[3].w),f(i,"height",a=e[3].h),f(i,"class","svelte-18wrg3t"),f(l,"points",u=e[19]),f(l,"class","svelte-18wrg3t"),f(n,"id",e[5]),f(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),f(h,"class","a9s-outer"),f(h,"mask",`url(#${e[5]})`),f(h,"points",c=e[19]),f(d,"class","a9s-inner"),f(d,"points",y=e[19])},m(w,m){P(w,t,m),Z(t,n),Z(n,i),Z(n,l),P(w,h,m),P(w,d,m),p&&p.m(w,m),P(w,g,m)},p(w,m){m&8&&o!==(o=w[3].x)&&f(i,"x",o),m&8&&s!==(s=w[3].y)&&f(i,"y",s),m&8&&r!==(r=w[3].w)&&f(i,"width",r),m&8&&a!==(a=w[3].h)&&f(i,"height",a),m&4&&u!==(u=w[19])&&f(l,"points",u),m&4&&c!==(c=w[19])&&f(h,"points",c),m&4&&y!==(y=w[19])&&f(d,"points",y),w[1]?p?p.p(w,m):(p=Ai(w),p.c(),p.m(g.parentNode,g)):p&&(p.d(1),p=null)},d(w){w&&(D(t),D(h),D(d),D(g)),p&&p.d(w)}}}function Ai(e){let t,n,i;return{c(){t=L("circle"),f(t,"class","a9s-handle svelte-18wrg3t"),f(t,"cx",n=e[0][0][0]),f(t,"cy",i=e[0][0][1]),f(t,"r",e[4])},m(o,s){P(o,t,s)},p(o,s){s&1&&n!==(n=o[0][0][0])&&f(t,"cx",n),s&1&&i!==(i=o[0][0][1])&&f(t,"cy",i),s&16&&f(t,"r",o[4])},d(o){o&&D(t)}}}function nr(e){let t,n=e[3]&&Ti(Zt(e));return{c(){t=L("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(i,o){P(i,t,o),n&&n.m(t,null)},p(i,[o]){i[3]?n?n.p(Zt(i),o):(n=Ti(Zt(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:z,o:z,d(i){i&&D(t),n&&n.d()}}}const ir=20,or=1500;function sr(e,t,n){let i,o,s;const r=Xe();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:u}=t,{viewportScale:h=1}=t,c,d=[],y,g,p=!1;const w=v=>{const N=v,{timeStamp:H,offsetX:B,offsetY:X}=N;if(c={timeStamp:H,offsetX:B,offsetY:X},l==="drag"&&d.length===0){const j=u.elementToImage(N.offsetX,N.offsetY);d.push(j),n(10,y=j)}},m=v=>{const N=v;if(g&&clearTimeout(g),d.length>0){if(n(10,y=u.elementToImage(N.offsetX,N.offsetY)),d.length>2){const H=Tt(y,d[0])*h;n(1,p=H<ir)}N.pointerType==="touch"&&(g=setTimeout(()=>{E()},or))}},A=v=>{const N=v;if(g&&clearTimeout(g),l==="click"){const H=N.timeStamp-c.timeStamp,B=Tt([c.offsetX,c.offsetY],[N.offsetX,N.offsetY]);if(H>300||B>15)return;if(p)M();else if(d.length===0){const X=u.elementToImage(N.offsetX,N.offsetY);d.push(X),n(10,y=X)}else d.push(y)}else{if(d.length===1&&Tt(d[0],y)<=4){n(0,d=[]),n(10,y=void 0);return}N.stopImmediatePropagation(),p?M():d.push(y)}},E=()=>{if(!y)return;const v=d.slice(0,-1);if(v.length<3)return;const N={type:ee.POLYGON,geometry:{bounds:Se(d),points:v}};yt(N)>4&&(n(0,d=[]),n(10,y=void 0),r("create",N))},M=()=>{const v={type:ee.POLYGON,geometry:{bounds:Se(d),points:[...d]}};n(0,d=[]),n(10,y=void 0),r("create",v)};ze(()=>{a("pointerdown",w,!0),a("pointermove",m),a("pointerup",A,!0),a("dblclick",E,!0)});const S=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=v=>{"addEventListener"in v&&n(6,a=v.addEventListener),"drawingMode"in v&&n(7,l=v.drawingMode),"transform"in v&&n(8,u=v.transform),"viewportScale"in v&&n(9,h=v.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,i=4/h),e.$$.dirty&1027&&n(2,o=y?p?d:[...d,y]:[]),e.$$.dirty&516&&n(3,s=o.length>0?ut(Se(o),2/h):void 0)},[d,p,o,s,i,S,a,l,u,h,y]}class rr extends we{constructor(t){super(),me(this,t,sr,nr,ae,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Wt=new Map([["rectangle",{tool:bi}],["polygon",{tool:rr}]]),Kt=()=>[...Wt.keys()],Jt=e=>Wt.get(e),Oi=(e,t,n={})=>Wt.set(e,{tool:t,opts:n});function lr(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("ellipse"),o=L("ellipse"),f(n,"class","a9s-outer"),f(n,"style",i=e[1]?"display:none;":void 0),f(n,"cx",e[2]),f(n,"cy",e[3]),f(n,"rx",e[4]),f(n,"ry",e[5]),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"cx",e[2]),f(o,"cy",e[3]),f(o,"rx",e[4]),f(o,"ry",e[5]),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&f(n,"style",i),a&2&&f(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:z,o:z,d(r){r&&D(t)}}}function ar(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{cx:a,cy:l,rx:u,ry:h}=s;return e.$$set=c=>{"annotation"in c&&n(0,o=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,i=at(o,r))},[o,i,a,l,u,h,s,r]}class ur extends we{constructor(t){super(),me(this,t,ar,lr,ae,{annotation:0,geom:6,style:7})}}function Mi(e,t,n){const i=e.slice();return i[5]=t[n],i}function vi(e){let t,n,i;return{c(){t=L("path"),i=L("path"),f(t,"class","a9s-outer"),f(t,"style",n=e[1]?"display:none;":void 0),f(t,"fill-rule","evenodd"),f(t,"d",Le(e[5])),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"fill-rule","evenodd"),f(i,"d",Le(e[5]))},m(o,s){P(o,t,s),P(o,i,s)},p(o,s){s&2&&n!==(n=o[1]?"display:none;":void 0)&&f(t,"style",n),s&2&&f(i,"style",o[1])},d(o){o&&(D(t),D(i))}}}function fr(e){let t,n,i=Oe(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=vi(Mi(e,i,s));return{c(){t=L("g");for(let s=0;s<o.length;s+=1)o[s].c();f(t,"class","a9s-annotation"),f(t,"data-id",n=e[0].id)},m(s,r){P(s,t,r);for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(t,null)},p(s,[r]){if(r&6){i=Oe(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Mi(s,i,a);o[a]?o[a].p(l,r):(o[a]=vi(l),o[a].c(),o[a].m(t,null))}for(;a<o.length;a+=1)o[a].d(1);o.length=i.length}r&1&&n!==(n=s[0].id)&&f(t,"data-id",n)},i:z,o:z,d(s){s&&D(t),Ye(o,s)}}}function cr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{polygons:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=at(o,r))},[o,i,a,s,r]}class hr extends we{constructor(t){super(),me(this,t,cr,fr,ae,{annotation:0,geom:3,style:4})}}function dr(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("polygon"),o=L("polygon"),f(n,"class","a9s-outer"),f(n,"style",i=e[1]?"display:none;":void 0),f(n,"points",e[2].map(gr).join(" ")),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"points",e[2].map(pr).join(" ")),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&f(n,"style",i),a&2&&f(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:z,o:z,d(r){r&&D(t)}}}const gr=e=>e.join(","),pr=e=>e.join(",");function yr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=at(o,r))},[o,i,a,s,r]}class _r extends we{constructor(t){super(),me(this,t,yr,dr,ae,{annotation:0,geom:3,style:4})}}function mr(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("rect"),o=L("rect"),f(n,"class","a9s-outer"),f(n,"style",i=e[5]?"display:none;":void 0),f(n,"x",e[4]),f(n,"y",e[3]),f(n,"width",e[2]),f(n,"height",e[1]),f(o,"class","a9s-inner"),f(o,"style",e[5]),f(o,"x",e[4]),f(o,"y",e[3]),f(o,"width",e[2]),f(o,"height",e[1]),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&32&&i!==(i=r[5]?"display:none;":void 0)&&f(n,"style",i),a&16&&f(n,"x",r[4]),a&8&&f(n,"y",r[3]),a&4&&f(n,"width",r[2]),a&2&&f(n,"height",r[1]),a&32&&f(o,"style",r[5]),a&16&&f(o,"x",r[4]),a&8&&f(o,"y",r[3]),a&4&&f(o,"width",r[2]),a&2&&f(o,"height",r[1]),a&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:z,o:z,d(r){r&&D(t)}}}function wr(e,t,n){let i,o,s,r,a,{annotation:l}=t,{geom:u}=t,{style:h}=t;return e.$$set=c=>{"annotation"in c&&n(0,l=c.annotation),"geom"in c&&n(6,u=c.geom),"style"in c&&n(7,h=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,i=at(l,h)),e.$$.dirty&64&&n(4,{x:o,y:s,w:r,h:a}=u,o,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,a),n(6,u)))},[l,a,r,s,o,i,u,h]}class Er extends we{constructor(t){super(),me(this,t,wr,mr,ae,{annotation:0,geom:6,style:7})}}const br={elementToImage:(e,t)=>[e,t]},Si=e=>({elementToImage:(t,n)=>{const i=e.getBoundingClientRect(),o=e.createSVGPoint();o.x=t+i.x,o.y=n+i.y;const{x:s,y:r}=o.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),Tr=250,Ni=(e,t)=>{const n=Xe();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<Tr){const{x:l,y:u}=xt(r,e),h=t.getAt(l,u);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},xt=(e,t)=>{const n=t.createSVGPoint(),i=t.getBoundingClientRect(),o=e.clientX-i.x,s=e.clientY-i.y,{left:r,top:a}=t.getBoundingClientRect();return n.x=o+r,n.y=s+a,n.matrixTransform(t.getScreenCTM().inverse())};function Ci(e,t,n){const i=e.slice();i[39]=t[n];const o=i[24](i[39].target.selector);return i[40]=o,i}function Ri(e,t,n){const i=e.slice();return i[43]=t[n],i}function $t(e){const t=e.slice(),n=t[43].target.selector;return t[46]=n,t}function Ii(e){let t=e[43],n,i,o=Li(e);return{c(){o.c(),n=Te()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&65536&&ae(t,t=s[43])?(ye(),G(o,1,1,z),_e(),o=Li(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){G(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Ar(e){let t,n;return t=new hr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Or(e){let t,n;return t=new _r({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Mr(e){let t,n;return t=new Er({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function vr(e){var i;let t,n;return t=new ur({props:{annotation:e[43],geom:(i=e[46])==null?void 0:i.geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(o,s){fe(t,o,s),n=!0},p(o,s){var a;const r={};s[0]&65536&&(r.annotation=o[43]),s[0]&65536&&(r.geom=(a=o[46])==null?void 0:a.geometry),s[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(V(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function Li(e){let t,n,i,o;const s=[vr,Mr,Or,Ar],r=[];function a(l,u){var h,c,d,y;return((h=l[46])==null?void 0:h.type)===ee.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===ee.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===ee.POLYGON?2:((y=l[46])==null?void 0:y.type)===ee.MULTIPOLYGLON?3:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Te()},m(l,u){~t&&r[t].m(l,u),P(l,i,u),o=!0},p(l,u){let h=t;t=a(l),t===h?~t&&r[t].p(l,u):(n&&(ye(),G(r[h],1,1,()=>{r[h]=null}),_e()),~t?(n=r[t],n?n.p(l,u):(n=r[t]=s[t](l),n.c()),V(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(V(n),o=!0)},o(l){G(n),o=!1},d(l){l&&D(i),~t&&r[t].d(l)}}}function ki(e){let t=rt(e[43])&&!e[9](e[43]),n,i,o=t&&Ii($t(e));return{c(){o&&o.c(),n=Te()},m(s,r){o&&o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&66048&&(t=rt(s[43])&&!s[9](s[43])),t?o?(o.p($t(s),r),r[0]&66048&&V(o,1)):(o=Ii($t(s)),o.c(),V(o,1),o.m(n.parentNode,n)):o&&(ye(),G(o,1,1,()=>{o=null}),_e())},i(s){i||(V(o),i=!0)},o(s){G(o),i=!1},d(s){s&&D(n),o&&o.d(s)}}}function Di(e){let t,n,i,o;const s=[Nr,Sr],r=[];function a(l,u){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Te()},m(l,u){~t&&r[t].m(l,u),P(l,i,u),o=!0},p(l,u){let h=t;t=a(l),t===h?~t&&r[t].p(l,u):(n&&(ye(),G(r[h],1,1,()=>{r[h]=null}),_e()),~t?(n=r[t],n?n.p(l,u):(n=r[t]=s[t](l),n.c()),V(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(V(n),o=!0)},o(l){G(n),o=!1},d(l){l&&D(i),~t&&r[t].d(l)}}}function Sr(e){let t=`${e[2]}-${e[5]}`,n,i,o=Pi(e);return{c(){o.c(),n=Te()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&36&&ae(t,t=`${s[2]}-${s[5]}`)?(ye(),G(o,1,1,z),_e(),o=Pi(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){G(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Nr(e){let t,n,i=Oe(e[8]),o=[];for(let r=0;r<i.length;r+=1)o[r]=Hi(Ci(e,i,r));const s=r=>G(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Te()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a[0]&21107010){i=Oe(r[8]);let l;for(l=0;l<i.length;l+=1){const u=Ci(r,i,l);o[l]?(o[l].p(u,a),V(o[l],1)):(o[l]=Hi(u),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(ye(),l=i.length;l<o.length;l+=1)s(l);_e()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)G(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function Pi(e){let t,n;return t=new wi({props:{target:e[6],tool:e[14],drawingMode:e[13],transform:e[12],viewportScale:e[17]}}),t.$on("create",e[21]),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&64&&(s.target=i[6]),o[0]&16384&&(s.tool=i[14]),o[0]&8192&&(s.drawingMode=i[13]),o[0]&4096&&(s.transform=i[12]),o[0]&131072&&(s.viewportScale=i[17]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Ui(e){let t=e[39].id,n,i,o=Vi(e);return{c(){o.c(),n=Te()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&256&&ae(t,t=s[39].id)?(ye(),G(o,1,1,z),_e(),o=Vi(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){G(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Vi(e){let t,n;return t=new mi({props:{target:e[6],editor:e[24](e[39].target.selector),annotation:e[39],style:e[1],transform:e[12],viewportScale:e[17]}}),t.$on("change",function(){ie(e[22](e[39]))&&e[22](e[39]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&64&&(s.target=e[6]),o[0]&256&&(s.editor=e[24](e[39].target.selector)),o[0]&256&&(s.annotation=e[39]),o[0]&2&&(s.style=e[1]),o[0]&4096&&(s.transform=e[12]),o[0]&131072&&(s.viewportScale=e[17]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Hi(e){let t,n,i=e[40]&&Ui(e);return{c(){i&&i.c(),t=Te()},m(o,s){i&&i.m(o,s),P(o,t,s),n=!0},p(o,s){o[40]?i?(i.p(o,s),s[0]&256&&V(i,1)):(i=Ui(o),i.c(),V(i,1),i.m(t.parentNode,t)):i&&(ye(),G(i,1,1,()=>{i=null}),_e())},i(o){n||(V(i),n=!0)},o(o){G(i),n=!1},d(o){o&&D(t),i&&i.d(o)}}}function Cr(e){let t,n,i,o,s,r,a=Oe(e[16].filter(e[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=ki(Ri(e,a,c));const u=c=>G(l[c],1,1,()=>{l[c]=null});let h=e[6]&&Di(e);return{c(){t=L("svg"),n=L("g");for(let c=0;c<l.length;c+=1)l[c].c();i=L("g"),h&&h.c(),f(i,"class","drawing"),f(t,"role","application"),f(t,"tabindex",0),f(t,"class","a9s-annotationlayer"),De(t,"drawing",e[14]),De(t,"editing",e[8]),De(t,"hidden",!e[3]),De(t,"hover",e[15])},m(c,d){P(c,t,d),Z(t,n);for(let y=0;y<l.length;y+=1)l[y]&&l[y].m(n,null);Z(t,i),h&&h.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[$(t,"pointerup",function(){ie(e[10])&&e[10].apply(this,arguments)}),$(t,"pointerdown",function(){ie(e[11])&&e[11].apply(this,arguments)}),$(t,"pointermove",e[23])],s=!0)},p(c,d){if(e=c,d[0]&66050){a=Oe(e[16].filter(e[34]));let y;for(y=0;y<a.length;y+=1){const g=Ri(e,a,y);l[y]?(l[y].p(g,d),V(l[y],1)):(l[y]=ki(g),l[y].c(),V(l[y],1),l[y].m(n,null))}for(ye(),y=a.length;y<l.length;y+=1)u(y);_e()}e[6]?h?(h.p(e,d),d[0]&64&&V(h,1)):(h=Di(e),h.c(),V(h,1),h.m(i,null)):h&&(ye(),G(h,1,1,()=>{h=null}),_e()),(!o||d[0]&16384)&&De(t,"drawing",e[14]),(!o||d[0]&256)&&De(t,"editing",e[8]),(!o||d[0]&8)&&De(t,"hidden",!e[3]),(!o||d[0]&32768)&&De(t,"hover",e[15])},i(c){if(!o){for(let d=0;d<a.length;d+=1)V(l[d]);V(h),o=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)G(l[d]);G(h),o=!1},d(c){c&&D(t),Ye(l,c),h&&h.d(),e[35](null),e[36](null),s=!1,Ce(r)}}}function Rr(e,t,n){let i,o,s,r,a,l,u,h,c,d,y,g=z,p=()=>(g(),g=un(O,F=>n(17,y=F)),O);e.$$.on_destroy.push(()=>g());let{drawingEnabled:w}=t,{image:m}=t,{preferredDrawingMode:A}=t,{state:E}=t,{style:M=void 0}=t,{toolName:S=Kt()[0]}=t,{user:v}=t,{visible:N=!0}=t,H=0;const B=()=>n(5,H+=1),X=()=>S,j=()=>w;let _,b,O;ze(()=>p(n(7,O=Kn(m,b))));const{hover:C,selection:R,store:I}=E;Rt(e,C,F=>n(15,h=F)),Rt(e,R,F=>n(33,c=F)),Rt(e,I,F=>n(16,d=F));let Y,Q;const J=F=>{Y&&I.unobserve(Y);const ge=F.filter(({editable:K})=>K).map(({id:K})=>K);ge.length>0?(n(8,Q=ge.map(K=>I.getAnnotation(K)).filter(K=>K&&rt(K))),Y=K=>{const{updated:Ne}=K.changes;n(8,Q=Ne==null?void 0:Ne.map(ve=>ve.newValue))},I.observe(Y,{annotations:ge})):n(8,Q=void 0)},Me=F=>{const ge=Xn(),K={id:ge,bodies:[],target:{annotation:ge,selector:F.detail,creator:v,created:new Date}};I.addAnnotation(K),R.setSelected(K.id)},ue=F=>ge=>{var tt;const{target:K}=F,Ne=10*60*1e3,ve=((tt=K.creator)==null?void 0:tt.id)!==v.id||!K.created||new Date().getTime()-K.created.getTime()>Ne;I.updateTarget({...K,selector:ge.detail,created:ve?K.created:new Date,updated:ve?new Date:void 0,updatedBy:ve?v:void 0})},Ee=F=>{const{x:ge,y:K}=xt(F,b),Ne=I.getAt(ge,K);Ne?h!==Ne.id&&C.set(Ne.id):C.set(void 0)},re=F=>yi(F),le=F=>rt(F);function $e(F){ot[F?"unshift":"push"](()=>{_=F,n(6,_)})}function et(F){ot[F?"unshift":"push"](()=>{b=F,n(4,b)})}return e.$$set=F=>{"drawingEnabled"in F&&n(0,w=F.drawingEnabled),"image"in F&&n(25,m=F.image),"preferredDrawingMode"in F&&n(26,A=F.preferredDrawingMode),"state"in F&&n(27,E=F.state),"style"in F&&n(1,M=F.style),"toolName"in F&&n(2,S=F.toolName),"user"in F&&n(28,v=F.user),"visible"in F&&n(3,N=F.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(14,{tool:i,opts:o}=Jt(S)||{tool:void 0,opts:void 0},i,(n(32,o),n(2,S))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(13,s=(o==null?void 0:o.drawingMode)||A),e.$$.dirty[0]&16&&n(12,r=Si(b)),e.$$.dirty[0]&16&&n(11,{onPointerDown:a,onPointerUp:l}=Ni(b,I),a,(n(10,l),n(4,b))),e.$$.dirty[1]&4&&n(9,u=F=>c.selected.find(ge=>ge.id===F.id&&ge.editable)),e.$$.dirty[1]&4&&J(c.selected)},[w,M,S,N,b,H,_,O,Q,u,l,a,r,s,i,h,d,y,C,R,I,Me,ue,Ee,re,m,A,E,v,B,X,j,o,c,le,$e,et]}class Bi extends we{constructor(t){super(),me(this,t,Rr,Cr,ae,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function Yi(e,t,n=0,i=e.length-1,o=Ir){for(;i>n;){if(i-n>600){const l=i-n+1,u=t-n+1,h=Math.log(l),c=.5*Math.exp(2*h/3),d=.5*Math.sqrt(h*c*(l-c)/l)*(u-l/2<0?-1:1),y=Math.max(n,Math.floor(t-u*c/l+d)),g=Math.min(i,Math.floor(t+(l-u)*c/l+d));Yi(e,t,y,g,o)}const s=e[t];let r=n,a=i;for(ct(e,n,t),o(e[i],s)>0&&ct(e,n,i);r<a;){for(ct(e,r,a),r++,a--;o(e[r],s)<0;)r++;for(;o(e[a],s)>0;)a--}o(e[n],s)===0?ct(e,n,a):(a++,ct(e,a,i)),a<=t&&(n=a+1),t<=a&&(i=a-1)}}function ct(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function Ir(e,t){return e<t?-1:e>t?1:0}class Lr{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const i=[];if(!Mt(t,n))return i;const o=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?o(a):a;Mt(t,l)&&(n.leaf?i.push(a):tn(t,l)?this._all(a,i):s.push(a))}n=s.pop()}return i}collides(t){let n=this.data;if(!Mt(t,n))return!1;const i=[];for(;n;){for(let o=0;o<n.children.length;o++){const s=n.children[o],r=n.leaf?this.toBBox(s):s;if(Mt(t,r)){if(n.leaf||tn(t,r))return!0;i.push(s)}}n=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const i=this.data;this.data=n,n=i}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=xe([]),this}remove(t,n){if(!t)return this;let i=this.data;const o=this.toBBox(t),s=[],r=[];let a,l,u;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=r.pop(),u=!0),i.leaf){const h=kr(t,i.children,n);if(h!==-1)return i.children.splice(h,1),s.push(i),this._condense(s),this}!u&&!i.leaf&&tn(i,o)?(s.push(i),r.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],u=!1):i=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const i=[];for(;t;)t.leaf?n.push(...t.children):i.push(...t.children),t=i.pop();return n}_build(t,n,i,o){const s=i-n+1;let r=this._maxEntries,a;if(s<=r)return a=xe(t.slice(n,i+1)),Je(a,this.toBBox),a;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),a=xe([]),a.leaf=!1,a.height=o;const l=Math.ceil(s/r),u=l*Math.ceil(Math.sqrt(r));Xi(t,n,i,u,this.compareMinX);for(let h=n;h<=i;h+=u){const c=Math.min(h+u-1,i);Xi(t,h,c,l,this.compareMinY);for(let d=h;d<=c;d+=l){const y=Math.min(d+l-1,c);a.children.push(this._build(t,d,y,o-1))}}return Je(a,this.toBBox),a}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const u=n.children[l],h=en(u),c=Ur(t,u)-h;c<r?(r=c,s=h<s?h:s,a=u):c===r&&h<s&&(s=h,a=u)}n=a||n.children[0]}return n}_insert(t,n,i){const o=i?t:this.toBBox(t),s=[],r=this._chooseSubtree(o,this.data,n,s);for(r.children.push(t),dt(r,o);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(o,s,n)}_split(t,n){const i=t[n],o=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,o);const r=this._chooseSplitIndex(i,s,o),a=xe(i.children.splice(r,i.children.length-r));a.height=i.height,a.leaf=i.leaf,Je(i,this.toBBox),Je(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,n){this.data=xe([t,n]),this.data.height=t.height+1,this.data.leaf=!1,Je(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,s=1/0,r=1/0;for(let a=n;a<=i-n;a++){const l=ht(t,0,a,this.toBBox),u=ht(t,a,i,this.toBBox),h=Vr(l,u),c=en(l)+en(u);h<s?(s=h,o=a,r=c<r?c:r):h===s&&c<r&&(r=c,o=a)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:Dr,s=t.leaf?this.compareMinY:Pr,r=this._allDistMargin(t,n,i,o),a=this._allDistMargin(t,n,i,s);r<a&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const s=this.toBBox,r=ht(t,0,n,s),a=ht(t,i-n,i,s);let l=Ot(r)+Ot(a);for(let u=n;u<i-n;u++){const h=t.children[u];dt(r,t.leaf?s(h):h),l+=Ot(r)}for(let u=i-n-1;u>=n;u--){const h=t.children[u];dt(a,t.leaf?s(h):h),l+=Ot(a)}return l}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)dt(n[o],t)}_condense(t){for(let n=t.length-1,i;n>=0;n--)t[n].children.length===0?n>0?(i=t[n-1].children,i.splice(i.indexOf(t[n]),1)):this.clear():Je(t[n],this.toBBox)}}function kr(e,t,n){if(!n)return t.indexOf(e);for(let i=0;i<t.length;i++)if(n(e,t[i]))return i;return-1}function Je(e,t){ht(e,0,e.children.length,t,e)}function ht(e,t,n,i,o){o||(o=xe(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];dt(o,e.leaf?i(r):r)}return o}function dt(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Dr(e,t){return e.minX-t.minX}function Pr(e,t){return e.minY-t.minY}function en(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ot(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Ur(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Vr(e,t){const n=Math.max(e.minX,t.minX),i=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,s-i)}function tn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Mt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function xe(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Xi(e,t,n,i,o){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=i)continue;const r=t+Math.ceil((n-t)/i/2)*i;Yi(e,r,t,n,o),s.push(t,r,r,n)}}const Hr=()=>{const e=new Lr,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!lt(c))return;const{minX:d,minY:y,maxX:g,maxY:p}=c.selector.geometry.bounds,w={minX:d,minY:y,maxX:g,maxY:p,target:c};e.insert(w),t.set(c.annotation,w)},s=c=>{if(!lt(c))return;const d=t.get(c.annotation);d&&e.remove(d),t.delete(c.annotation)};return{all:n,clear:i,getAt:(c,d,y)=>{const p=e.search({minX:c,minY:d,maxX:c,maxY:d}).map(w=>w.target).filter(w=>w.selector.type===ee.RECTANGLE||mn(w.selector,c,d));return p.length>0?(p.sort((w,m)=>yt(w.selector)-yt(m.selector)),p):[]},getIntersecting:(c,d,y,g)=>e.search({minX:c,minY:d,maxX:c+y,maxY:d+g}).map(p=>p.target),insert:o,remove:s,set:(c,d=!0)=>{d&&i();const y=c.reduce((g,p)=>{if(lt(p)){const{minX:w,minY:m,maxX:A,maxY:E}=p.selector.geometry.bounds;return[...g,{minX:w,minY:m,maxX:A,maxY:E,target:p}]}else return g},[]);y.forEach(g=>t.set(g.target.annotation,g)),e.load(y)},size:()=>e.all().length,update:(c,d)=>{s(c),o(d)}}},Fi=e=>{const t=ns(),n=Hr(),i=Go(t,e.userSelectAction,e.adapter),o=Fo(t),s=ls();return t.observe(({changes:l})=>{n.set((l.created||[]).map(u=>u.target),!1),(l.deleted||[]).forEach(u=>n.remove(u.target)),(l.updated||[]).forEach(({oldValue:u,newValue:h})=>n.update(u.target,h.target))}),{store:{...t,getAt:(l,u,h)=>{const c=n.getAt(l,u,h);if(h)return c.map(y=>t.getAnnotation(y.annotation)).filter(Boolean).filter(h)[0];{const d=c[0];return d?t.getAnnotation(d.annotation):void 0}},getIntersecting:(l,u,h,c)=>n.getIntersecting(l,u,h,c).map(d=>t.getAnnotation(d.annotation))},selection:i,hover:o,viewport:s}},Gi=e=>{const t=Fi(e);return{...t,store:is(t.store)}},ji=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const o=e;t=document.createElement("canvas"),t.width=o.width,t.height=o.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(o,0,0,o.width,o.height)}let i=0;for(let o=1;o<10;o++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),a=Math.round(o*t.height/10),l=n.getImageData(r,a,1,1).data,u=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=u}return i/81},zi=e=>{const t=ji(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},nn=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?zi(e):n),Qi=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),on=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,qi=(e,t)=>{const n=t||document,i=r=>{const a=r;a.key==="z"&&a.ctrlKey?e.undo():a.key==="y"&&a.ctrlKey&&e.redo()},o=r=>{const a=r;a.key==="z"&&a.metaKey&&(a.shiftKey?e.redo():e.undo())},s=()=>{on?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return on?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:s}},Br=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=Qi(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Xt.EDIT,theme:"light"}),o=Gi(i),{selection:s,store:r}=o,a=rs(r,i.initialHistory),l=as(o,a,i.adapter,i.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const h=qi(a);let c=ms();nn(n,u,i.theme);const d=new Bi({target:u,props:{drawingEnabled:!!i.drawingEnabled,image:n,preferredDrawingMode:i.drawingMode,state:o,style:i.style,user:c}});d.$on("click",_=>{const{originalEvent:b,annotation:O}=_.detail;O?s.userSelect(O.id,b):s.isEmpty()||s.clear()});const y=fs(o,a,i.adapter),g=()=>d.cancelDrawing(),p=()=>{d.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),h.destroy(),a.destroy()},w=()=>d.getDrawingTool(),m=()=>c,A=()=>d.isDrawingEnabled(),E=(_,b,O)=>Oi(_,b,O),M=(_,b)=>_i(_,b),S=_=>{if(!Jt(_))throw`No drawing tool named ${_}`;d.$set({toolName:_})},v=_=>d.$set({drawingEnabled:_}),N=_=>{console.warn("Filter not implemented yet")},H=_=>d.$set({style:_}),B=_=>nn(n,u,_),X=_=>{c=_,d.$set({user:_})},j=_=>d.$set({visible:_});return{...y,cancelDrawing:g,destroy:p,getDrawingTool:w,getUser:m,isDrawingEnabled:A,listDrawingTools:Kt,on:l.on,off:l.off,registerDrawingTool:E,registerShapeEditor:M,setDrawingEnabled:v,setDrawingTool:S,setFilter:N,setStyle:H,setTheme:B,setUser:X,setVisible:j,element:u,state:o}};k.Editor=At,k.EditorMount=mi,k.Handle=je,k.IdentityTransform=br,k.PolygonEditor=li,k.RectangleEditor=ai,k.RectangleUtil=bn,k.RubberbandRectangle=bi,k.SVGAnnotationLayer=Bi,k.ShapeType=ee,k.ToolMount=wi,k.UserSelectAction=Xt,k.W3CImageFormat=Os,k.addEventListeners=Ni,k.boundsFromMultiPolygonElements=En,k.boundsFromPoints=Se,k.chainStyles=hs,k.computeArea=yt,k.computePolygonArea=_t,k.computeStyle=cs,k.createBody=Zo,k.createImageAnnotator=Br,k.createImageAnnotatorState=Fi,k.createSVGTransform=Si,k.createSvelteImageAnnotatorState=Gi,k.defaultColorProvider=As,k.detectTheme=zi,k.distance=Tt,k.enableResponsive=Kn,k.fillDefaults=Qi,k.getEditor=yi,k.getMaskDimensions=ut,k.getSVGPoint=xt,k.getTool=Jt,k.initKeyboardCommands=qi,k.intersects=mn,k.isImageAnnotation=rt,k.isImageAnnotationTarget=lt,k.isMac=on,k.isPointInPolygon=mt,k.isTouch=jt,k.listDrawingTools=Kt,k.multipolygonElementToPath=Le,k.parseFragmentSelector=Tn,k.parseSVGSelector=Hn,k.parseW3CImageAnnotation=Zn,k.pointsToPath=wn,k.registerEditor=_i,k.registerShapeUtil=st,k.registerTool=Oi,k.sampleBrightness=ji,k.serializeFragmentSelector=An,k.serializeSVGSelector=Bn,k.serializeW3CImageAnnotation=Wn,k.setTheme=nn,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
1
+ (function(k,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(k=typeof globalThis<"u"?globalThis:k||self,j(k.Annotorious={}))})(this,function(k){"use strict";var Yr=Object.defineProperty;var Xr=(k,j,De)=>j in k?Yr(k,j,{enumerable:!0,configurable:!0,writable:!0,value:De}):k[j]=De;var ne=(k,j,De)=>Xr(k,typeof j!="symbol"?j+"":j,De);function j(){}function De(e,t){for(const n in t)e[n]=t[n];return e}function ln(e){return e()}function an(){return Object.create(null)}function ve(e){e.forEach(ln)}function ie(e){return typeof e=="function"}function ae(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function Wi(e){return Object.keys(e).length===0}function un(e,...t){if(e==null){for(const i of t)i(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function It(e,t,n){e.$$.on_destroy.push(un(t,n))}function Ki(e,t,n,i){if(e){const o=fn(e,t,n,i);return e[0](o)}}function fn(e,t,n,i){return e[1]&&i?De(n.ctx.slice(),e[1](i(t))):n.ctx}function Ji(e,t,n,i){if(e[2]&&i){const o=e[2](i(n));if(t.dirty===void 0)return o;if(typeof o=="object"){const s=[],r=Math.max(t.dirty.length,o.length);for(let a=0;a<r;a+=1)s[a]=t.dirty[a]|o[a];return s}return t.dirty|o}return t.dirty}function xi(e,t,n,i,o,s){if(o){const r=fn(t,n,i,s);e.p(r,o)}}function $i(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let i=0;i<n;i++)t[i]=-1;return t}return-1}function cn(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function pt(e){return e??""}function Z(e,t){e.appendChild(t)}function P(e,t,n){e.insertBefore(t,n||null)}function D(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function I(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function hn(e){return document.createTextNode(e)}function Te(){return hn(" ")}function Ae(){return hn("")}function K(e,t,n,i){return e.addEventListener(t,n,i),()=>e.removeEventListener(t,n,i)}function u(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function eo(e){return Array.from(e.childNodes)}function Le(e,t,n){e.classList.toggle(t,!!n)}function to(e,t,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:i})}let it;function ot(e){it=e}function dn(){if(!it)throw new Error("Function called outside component initialization");return it}function je(e){dn().$$.on_mount.push(e)}function Xe(){const e=dn();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const s=to(t,n,{cancelable:i});return o.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function pe(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Qe=[],st=[];let qe=[];const gn=[],pn=Promise.resolve();let Lt=!1;function yn(){Lt||(Lt=!0,pn.then(_n))}function no(){return yn(),pn}function kt(e){qe.push(e)}const Dt=new Set;let Ze=0;function _n(){if(Ze!==0)return;const e=it;do{try{for(;Ze<Qe.length;){const t=Qe[Ze];Ze++,ot(t),io(t.$$)}}catch(t){throw Qe.length=0,Ze=0,t}for(ot(null),Qe.length=0,Ze=0;st.length;)st.pop()();for(let t=0;t<qe.length;t+=1){const n=qe[t];Dt.has(n)||(Dt.add(n),n())}qe.length=0}while(Qe.length);for(;gn.length;)gn.pop()();Lt=!1,Dt.clear(),ot(e)}function io(e){if(e.fragment!==null){e.update(),ve(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(kt)}}function oo(e){const t=[],n=[];qe.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),qe=t}const yt=new Set;let Fe;function _e(){Fe={r:0,c:[],p:Fe}}function me(){Fe.r||ve(Fe.c),Fe=Fe.p}function V(e,t){e&&e.i&&(yt.delete(e),e.i(t))}function z(e,t,n,i){if(e&&e.o){if(yt.has(e))return;yt.add(e),Fe.c.push(()=>{yt.delete(e),i&&(n&&e.d(1),i())}),e.o(t)}else i&&i()}function Oe(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ye(e){e&&e.c()}function fe(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),kt(()=>{const s=e.$$.on_mount.map(ln).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):ve(s),e.$$.on_mount=[]}),o.forEach(kt)}function ce(e,t){const n=e.$$;n.fragment!==null&&(oo(n.after_update),ve(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function so(e,t){e.$$.dirty[0]===-1&&(Qe.push(e),yn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function we(e,t,n,i,o,s,r=null,a=[-1]){const l=it;ot(e);const f=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:o,bound:an(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:an(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};r&&r(f.root);let h=!1;if(f.ctx=n?n(e,t.props||{},(c,d,..._)=>{const g=_.length?_[0]:d;return f.ctx&&o(f.ctx[c],f.ctx[c]=g)&&(!f.skip_bound&&f.bound[c]&&f.bound[c](g),h&&so(e,c)),d}):[],f.update(),h=!0,ve(f.before_update),f.fragment=i?i(f.ctx):!1,t.target){if(t.hydrate){const c=eo(t.target);f.fragment&&f.fragment.l(c),c.forEach(D)}else f.fragment&&f.fragment.c();t.intro&&V(e.$$.fragment),fe(e,t.target,t.anchor),_n()}ot(l)}class Ee{constructor(){ne(this,"$$");ne(this,"$$set")}$destroy(){ce(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(n),()=>{const o=i.indexOf(n);o!==-1&&i.splice(o,1)}}$set(t){this.$$set&&!Wi(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ro="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ro);var ee=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(ee||{});const Pt={},rt=(e,t)=>Pt[e]=t,_t=e=>Pt[e.type].area(e),mn=(e,t,n)=>Pt[e.type].intersects(e,t,n),Ne=e=>{let t=1/0,n=1/0,i=-1/0,o=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),i=Math.max(i,s),o=Math.max(o,r)}),{minX:t,minY:n,maxX:i,maxY:o}},mt=e=>{let t=0,n=e.length-1;for(let i=0;i<e.length;i++)t+=(e[n][0]+e[i][0])*(e[n][1]-e[i][1]),n=i;return Math.abs(.5*t)},wt=(e,t,n)=>{let i=!1;for(let o=0,s=e.length-1;o<e.length;s=o++){const r=e[o][0],a=e[o][1],l=e[s][0],f=e[s][1];a>n!=f>n&&t<(l-r)*(n-a)/(f-a)+r&&(i=!i)}return i},wn=(e,t=!0)=>{let n="M ";return e.forEach(([i,o],s)=>{s===0?n+=`${i},${o}`:n+=` L ${i},${o}`}),t&&(n+=" Z"),n},lo={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:i,cy:o,rx:s,ry:r}=e.geometry,a=0,l=Math.cos(a),f=Math.sin(a),h=t-i,c=n-o,d=l*h+f*c,_=f*h-l*c;return d*d/(s*s)+_*_/(r*r)<=1}};rt(ee.ELLIPSE,lo);const ao={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...s]=i.rings,r=mt(o.points),a=s.reduce((l,f)=>l+mt(f.points),0);return n+r-a},0)},intersects:(e,t,n)=>{const{polygons:i}=e.geometry;for(const o of i){const[s,...r]=o.rings;if(wt(s.points,t,n)){let a=!1;for(const l of r)if(wt(l.points,t,n)){a=!0;break}if(!a)return!0}}return!1}},En=e=>{const t=e.reduce((n,i)=>[...n,...i.rings[0].points],[]);return Ne(t)},ke=e=>e.rings.map(n=>wn(n.points)).join(" ");rt(ee.MULTIPOLYGLON,ao);const uo={area:e=>{const t=e.geometry.points;return mt(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return wt(i,t,n)}};rt(ee.POLYGON,uo);const bn={area:e=>e.geometry.w*e.geometry.h,intersects:(e,t,n)=>t>=e.geometry.x&&t<=e.geometry.x+e.geometry.w&&n>=e.geometry.y&&n<=e.geometry.y+e.geometry.h};rt(ee.RECTANGLE,bn);const lt=e=>at(e.target),at=e=>{var t,n;return(e==null?void 0:e.annotation)!==void 0&&((n=(t=e==null?void 0:e.selector)==null?void 0:t.geometry)==null?void 0:n.bounds)!==void 0},Tn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,o=[...n.matchAll(i)][0],[s,r,a,l,f,h,c]=o;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,_,g,p]=[l,f,h,c].map(parseFloat);return{type:ee.RECTANGLE,geometry:{x:d,y:_,w:g,h:p,bounds:{minX:d,minY:t?_-p:_,maxX:d+g,maxY:t?_:_+p}}}},An=e=>{const{x:t,y:n,w:i,h:o}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${i},${o}`}},On="http://www.w3.org/2000/svg",Mn=e=>{const t=i=>{Array.from(i.attributes).forEach(o=>{o.name.startsWith("on")&&i.removeAttribute(o.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(e.querySelectorAll("*")).forEach(t),e},fo=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${On}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},Sn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(On),o=n.lookupNamespaceURI(null);return i||o?Mn(n).firstChild:Mn(fo(n)).firstChild},oe=" ";function co(e){let t="";Array.isArray(e)||(e=[e]);for(let n=0;n<e.length;n++){const i=e[n];if(i.type===T.CLOSE_PATH)t+="z";else if(i.type===T.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===T.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===T.MOVE_TO)t+=(i.relative?"m":"M")+i.x+oe+i.y;else if(i.type===T.LINE_TO)t+=(i.relative?"l":"L")+i.x+oe+i.y;else if(i.type===T.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+oe+i.y1+oe+i.x2+oe+i.y2+oe+i.x+oe+i.y;else if(i.type===T.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+oe+i.y2+oe+i.x+oe+i.y;else if(i.type===T.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+oe+i.y1+oe+i.x+oe+i.y;else if(i.type===T.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+oe+i.y;else if(i.type===T.ARC)t+=(i.relative?"a":"A")+i.rX+oe+i.rY+oe+i.xRot+oe+ +i.lArcFlag+oe+ +i.sweepFlag+oe+i.x+oe+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Ut([e,t],n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Re(...e){for(let t=0;t<e.length;t++)if(typeof e[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof e[t]} == typeof ${e[t]}`);return!0}const Pe=Math.PI;function Vt(e,t,n){e.lArcFlag=e.lArcFlag===0?0:1,e.sweepFlag=e.sweepFlag===0?0:1;let{rX:i,rY:o}=e;const{x:s,y:r}=e;if(Math.abs(i)<1e-10||Math.abs(o)<1e-10){e.rX=0,e.rY=0,e.cX=(t+s)/2,e.cY=(n+r)/2,e.phi1=0,e.phi2=0;return}i=Math.abs(e.rX),o=Math.abs(e.rY);const a=e.xRot/180*Pe,[l,f]=Ut([(t-s)/2,(n-r)/2],-a),h=Math.pow(l,2)/Math.pow(i,2)+Math.pow(f,2)/Math.pow(o,2);1<h&&(i*=Math.sqrt(h),o*=Math.sqrt(h)),e.rX=i,e.rY=o;const c=Math.pow(i,2)*Math.pow(f,2)+Math.pow(o,2)*Math.pow(l,2),d=(e.lArcFlag!==e.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(o,2)-c)/c)),_=i*f/o*d,g=-o*l/i*d,p=Ut([_,g],a);e.cX=p[0]+(t+s)/2,e.cY=p[1]+(n+r)/2,e.phi1=Math.atan2((f-g)/o,(l-_)/i),e.phi2=Math.atan2((-f-g)/o,(-l-_)/i),e.sweepFlag===0&&e.phi2>e.phi1&&(e.phi2-=2*Pe),e.sweepFlag===1&&e.phi2<e.phi1&&(e.phi2+=2*Pe),e.phi1*=180/Pe,e.phi2*=180/Pe}function vn(e,t,n){Re(e,t,n);const i=e*e+t*t-n*n;if(0>i)return[];if(i===0)return[[e*n/(e*e+t*t),t*n/(e*e+t*t)]];const o=Math.sqrt(i);return[[(e*n+t*o)/(e*e+t*t),(t*n-e*o)/(e*e+t*t)],[(e*n-t*o)/(e*e+t*t),(t*n+e*o)/(e*e+t*t)]]}const ze=Math.PI/180;function Nn(e,t,n){return(1-n)*e+n*t}function Cn(e,t,n,i){return e+Math.cos(i/180*Pe)*t+Math.sin(i/180*Pe)*n}function Rn(e,t,n,i){const s=t-e,r=n-t,a=i-n,l=3*s+3*a-6*r,f=(r-s)*6,h=3*s;return Math.abs(l)<1e-6?Math.abs(f)<1e-6?[]:[-h/f]:ho(f/l,h/l,1e-6)}function In(e,t,n,i,o){const s=1-o,r=s*s*s,a=3*s*s*o,l=3*s*o*o,f=o*o*o;return e*r+t*a+n*l+i*f}function ho(e,t,n=1e-6){const i=e*e/4-t;if(i<-n)return[];if(i<=n)return[-e/2];const o=Math.sqrt(i);return[-(e/2)-o,-(e/2)+o]}function go(e,t,n){e.cX||Vt(e,t,n);const i=e.xRot/180*Pe;if(Math.abs(e.rX)<1e-10||Math.abs(e.rY)<1e-10)return[{relative:e.relative,type:T.CURVE_TO,x1:t+(e.x-t)/3,y1:n+(e.y-n)/3,x2:t+2*(e.x-t)/3,y2:n+2*(e.y-n)/3,x:e.x,y:e.y}];const o=Math.min(e.phi1,e.phi2),s=Math.max(e.phi1,e.phi2),r=s-o,a=Math.ceil(r/90),l=new Array(a);let f=t,h=n;const c=(d,_)=>{const[g,p]=Ut([d*e.rX,_*e.rY],i);return[e.cX+g,e.cY+p]};for(let d=0;d<a;d++){const _=Nn(e.phi1,e.phi2,d/a),g=Nn(e.phi1,e.phi2,(d+1)/a),p=g-_,w=4/3*Math.tan(p*ze/4),y=Math.cos(_*ze)-w*Math.sin(_*ze),A=Math.sin(_*ze)+w*Math.cos(_*ze),E=Math.cos(g*ze),M=Math.sin(g*ze),v=E+w*M,S=M-w*E,N=c(y,A),H=c(v,S),B=c(E,M),X={relative:e.relative,type:T.CURVE_TO,x:B[0],y:B[1],x1:N[0],y1:N[1],x2:H[0],y2:H[1]};e.relative&&(X.x1-=f,X.y1-=h,X.x2-=f,X.y2-=h,X.x-=f,X.y-=h),f=B[0],h=B[1],l[d]=X}return l}function Ht(e,t,n){const i=t[0]-e[0],o=t[1]-e[1],s=n[0]-e[0],r=n[1]-e[1],a=i*r-o*s;if(!(Math.abs(a)<1e-10))return!1;const f=i*s+o*r,h=i*i+o*o,c=s*s+r*r;return 0<=f&&f<=c&&h<=c}function po(e,t=!0){if(e.length<2)return e;const n=se.INFO((s,r,a)=>({...s,x:s.x??r,y:s.y??a,relative:s.relative??!1})),i=[];let o=[];for(const s of e){const r=n(s);r.type===T.MOVE_TO&&o.length>0&&(t?i.push(...Et(o)):i.unshift(...Et(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...Et(o)):i.unshift(...Et(o))),i}function Et(e){var o;const t=((o=e[e.length-1])==null?void 0:o.type)===T.CLOSE_PATH,n=t?e.length-2:e.length-1,i=[{type:T.MOVE_TO,relative:!1,x:e[n].x,y:e[n].y}];for(let s=n;s>0;s--){const r=e[s],a=e[s-1];if(r.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(r.type){case T.HORIZ_LINE_TO:i.push({type:T.HORIZ_LINE_TO,relative:!1,x:a.x});break;case T.VERT_LINE_TO:i.push({type:T.VERT_LINE_TO,relative:!1,y:a.y});break;case T.LINE_TO:case T.MOVE_TO:i.push({type:T.LINE_TO,relative:!1,x:a.x,y:a.y});break;case T.CURVE_TO:i.push({type:T.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case T.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case T.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case T.ARC:throw new Error("Unsupported command: A (arc)");case T.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:T.CLOSE_PATH}),i}function yo(e=1e13){Re(e);function t(n){return Math.round(n*e)/e}return function(i){return"x1"in i&&typeof i.x1<"u"&&(i.x1=t(i.x1)),"y1"in i&&typeof i.y1<"u"&&(i.y1=t(i.y1)),"x2"in i&&typeof i.x2<"u"&&(i.x2=t(i.x2)),"y2"in i&&typeof i.y2<"u"&&(i.y2=t(i.y2)),"x"in i&&typeof i.x<"u"&&(i.x=t(i.x)),"y"in i&&typeof i.y<"u"&&(i.y=t(i.y)),"rX"in i&&typeof i.rX<"u"&&(i.rX=t(i.rX)),"rY"in i&&typeof i.rY<"u"&&(i.rY=t(i.rY)),i}}function Ln(){return Ie((e,t,n)=>(e.relative&&(typeof e.x1<"u"&&(e.x1+=t),typeof e.y1<"u"&&(e.y1+=n),typeof e.x2<"u"&&(e.x2+=t),typeof e.y2<"u"&&(e.y2+=n),typeof e.x<"u"&&(e.x+=t),typeof e.y<"u"&&(e.y+=n),e.relative=!1),e))}function _o(){return Ie((e,t,n)=>(e.relative||(typeof e.x1<"u"&&(e.x1-=t),typeof e.y1<"u"&&(e.y1-=n),typeof e.x2<"u"&&(e.x2-=t),typeof e.y2<"u"&&(e.y2-=n),typeof e.x<"u"&&(e.x-=t),typeof e.y<"u"&&(e.y-=n),e.relative=!0),e))}function mo(e=!0,t=!0,n=!0,i=!0){return Ie((o,s,r,a,l)=>{if(isNaN(a)&&!(o.type&T.MOVE_TO))throw new Error("path must start with moveto");if(t&&o.type&T.HORIZ_LINE_TO&&(o.type=T.LINE_TO,o.y=o.relative?0:r),n&&o.type&T.VERT_LINE_TO&&(o.type=T.LINE_TO,o.x=o.relative?0:s),e&&o.type&T.CLOSE_PATH&&(o.type=T.LINE_TO,o.x=o.relative?a-s:a,o.y=o.relative?l-r:l),o.type&T.ARC&&(o.rX===0||o.rY===0)&&(o.type=T.LINE_TO,delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag),i&&o.type&T.QUAD_TO){const f=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Ht(f,h,c)&&(o.type=T.LINE_TO,delete o.x1,delete o.y1)}if(i&&o.type&T.CURVE_TO){const f=[s,r],h=o.relative?[s+o.x1,r+o.y1]:[o.x1,o.y1],c=o.relative?[s+o.x2,r+o.y2]:[o.x2,o.y2],d=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Ht(f,h,d)&&Ht(f,c,d)&&(o.type=T.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function kn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Ie((o,s,r)=>(o.type&T.SMOOTH_CURVE_TO&&(o.type=T.CURVE_TO,e=isNaN(e)?s:e,t=isNaN(t)?r:t,o.x1=o.relative?s-e:2*s-e,o.y1=o.relative?r-t:2*r-t),o.type&T.CURVE_TO?(e=o.relative?s+o.x2:o.x2,t=o.relative?r+o.y2:o.y2):(e=NaN,t=NaN),o.type&T.SMOOTH_QUAD_TO&&(o.type=T.QUAD_TO,n=isNaN(n)?s:n,i=isNaN(i)?r:i,o.x1=o.relative?s-n:2*s-n,o.y1=o.relative?r-i:2*r-i),o.type&T.QUAD_TO?(n=o.relative?s+o.x1:o.x1,i=o.relative?r+o.y1:o.y1):(n=NaN,i=NaN),o))}function Dn(){let e=NaN,t=NaN;return Ie((n,i,o)=>{if(n.type&T.SMOOTH_QUAD_TO&&(n.type=T.QUAD_TO,e=isNaN(e)?i:e,t=isNaN(t)?o:t,n.x1=n.relative?i-e:2*i-e,n.y1=n.relative?o-t:2*o-t),n.type&T.QUAD_TO){e=n.relative?i+n.x1:n.x1,t=n.relative?o+n.y1:n.y1;const s=n.x1,r=n.y1;n.type=T.CURVE_TO,n.x1=((n.relative?0:i)+s*2)/3,n.y1=((n.relative?0:o)+r*2)/3,n.x2=(n.x+s*2)/3,n.y2=(n.y+r*2)/3}else e=NaN,t=NaN;return n})}function Ie(e){let t=0,n=0,i=NaN,o=NaN;return function(r){if(isNaN(i)&&!(r.type&T.MOVE_TO))throw new Error("path must start with moveto");const a=e(r,t,n,i,o);return r.type&T.CLOSE_PATH&&(t=i,n=o),"x"in r&&typeof r.x<"u"&&(t=r.relative?t+r.x:r.x),"y"in r&&typeof r.y<"u"&&(n=r.relative?n+r.y:r.y),r.type&T.MOVE_TO&&(i=t,o=n),a}}function wo(e=0){Re(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Ie((s,r,a,l,f)=>{const h=Math.abs;let c=!1,d=0,_=0;if(s.type&T.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:r-t,_=isNaN(n)?0:a-n),s.type&(T.CURVE_TO|T.SMOOTH_CURVE_TO)?(t=s.relative?r+s.x2:s.x2,n=s.relative?a+s.y2:s.y2):(t=NaN,n=NaN),s.type&T.SMOOTH_QUAD_TO?(i=isNaN(i)?r:2*r-i,o=isNaN(o)?a:2*a-o):s.type&T.QUAD_TO?(i=s.relative?r+s.x1:s.x1,o=s.relative?a+s.y1:s.y2):(i=NaN,o=NaN),s.type&T.LINE_COMMANDS||s.type&T.ARC&&(s.rX===0||s.rY===0||!s.lArcFlag)||s.type&T.CURVE_TO||s.type&T.SMOOTH_CURVE_TO||s.type&T.QUAD_TO||s.type&T.SMOOTH_QUAD_TO){const g=typeof s.x>"u"?0:s.relative?s.x:s.x-r,p=typeof s.y>"u"?0:s.relative?s.y:s.y-a;d=isNaN(i)?typeof s.x1>"u"?d:s.relative?s.x:s.x1-r:i-r,_=isNaN(o)?typeof s.y1>"u"?_:s.relative?s.y:s.y1-a:o-a;const w=typeof s.x2>"u"?0:s.relative?s.x:s.x2-r,y=typeof s.y2>"u"?0:s.relative?s.y:s.y2-a;h(g)<=e&&h(p)<=e&&h(d)<=e&&h(_)<=e&&h(w)<=e&&h(y)<=e&&(c=!0)}return s.type&T.CLOSE_PATH&&h(r-l)<=e&&h(a-f)<=e&&(c=!0),c?[]:s})}function Ue(e,t,n,i,o,s){return Re(e,t,n,i,o,s),Ie((r,a,l,f)=>{const h=r.x1,c=r.x2,d=r.relative&&!isNaN(f),_=typeof r.x<"u"?r.x:d?0:a,g=typeof r.y<"u"?r.y:d?0:l;r.type&T.HORIZ_LINE_TO&&t!==0&&(r.type=T.LINE_TO,r.y=r.relative?0:l),r.type&T.VERT_LINE_TO&&n!==0&&(r.type=T.LINE_TO,r.x=r.relative?0:a),typeof r.x<"u"&&(r.x=r.x*e+g*n+(d?0:o)),typeof r.y<"u"&&(r.y=_*t+r.y*i+(d?0:s)),typeof r.x1<"u"&&(r.x1=r.x1*e+r.y1*n+(d?0:o)),typeof r.y1<"u"&&(r.y1=h*t+r.y1*i+(d?0:s)),typeof r.x2<"u"&&(r.x2=r.x2*e+r.y2*n+(d?0:o)),typeof r.y2<"u"&&(r.y2=c*t+r.y2*i+(d?0:s));function p(y){return y*y}const w=e*i-t*n;if(typeof r.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(w===0)delete r.rX,delete r.rY,delete r.xRot,delete r.lArcFlag,delete r.sweepFlag,r.type=T.LINE_TO;else{const y=r.xRot*Math.PI/180,A=Math.sin(y),E=Math.cos(y),M=1/p(r.rX),v=1/p(r.rY),S=p(E)*M+p(A)*v,N=2*A*E*(M-v),H=p(A)*M+p(E)*v,B=S*i*i-N*t*i+H*t*t,X=N*(e*i+t*n)-2*(S*n*i+H*e*t),G=S*n*n-N*e*n+H*e*e,m=(Math.atan2(X,B-G)+Math.PI)%Math.PI/2,b=Math.sin(m),O=Math.cos(m);r.rX=Math.abs(w)/Math.sqrt(B*p(O)+X*b*O+G*p(b)),r.rY=Math.abs(w)/Math.sqrt(B*p(b)-X*b*O+G*p(O)),r.xRot=m*180/Math.PI}return typeof r.sweepFlag<"u"&&0>w&&(r.sweepFlag=+!r.sweepFlag),r})}function Eo(e,t=0,n=0){Re(e,t,n);const i=Math.sin(e),o=Math.cos(e);return Ue(o,i,-i,o,t-t*o+n*i,n-t*i-n*o)}function bo(e,t=0){return Re(e,t),Ue(1,0,0,1,e,t)}function To(e,t=e){return Re(e,t),Ue(e,0,0,t,0,0)}function Ao(e){return Re(e),Ue(1,0,Math.tan(e),1,0,0)}function Oo(e){return Re(e),Ue(1,Math.tan(e),0,1,0,0)}function Mo(e=0){return Re(e),Ue(-1,0,0,1,e,0)}function So(e=0){return Re(e),Ue(1,0,0,-1,0,e)}function vo(){return Ie((e,t,n)=>T.ARC===e.type?go(e,e.relative?0:t,e.relative?0:n):e)}function No(){return Ie((e,t,n)=>(e.relative&&(t=0,n=0),T.ARC===e.type&&Vt(e,t,n),e))}function Pn(){return e=>({...e})}function Co(){const e=Pn(),t=Ln(),n=Dn(),i=kn(),o=Ie((s,r,a)=>{const l=i(n(t(e(s))));function f(c){c>o.maxX&&(o.maxX=c),c<o.minX&&(o.minX=c)}function h(c){c>o.maxY&&(o.maxY=c),c<o.minY&&(o.minY=c)}if(l.type&T.DRAWING_COMMANDS&&(f(r),h(a)),l.type&T.HORIZ_LINE_TO&&f(l.x),l.type&T.VERT_LINE_TO&&h(l.y),l.type&T.LINE_TO&&(f(l.x),h(l.y)),l.type&T.CURVE_TO){f(l.x),h(l.y);const c=Rn(r,l.x1,l.x2,l.x);for(const _ of c)0<_&&1>_&&f(In(r,l.x1,l.x2,l.x,_));const d=Rn(a,l.y1,l.y2,l.y);for(const _ of d)0<_&&1>_&&h(In(a,l.y1,l.y2,l.y,_))}if(l.type&T.ARC){f(l.x),h(l.y),Vt(l,r,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,_=Math.sin(c)*l.rX,g=-Math.sin(c)*l.rY,p=Math.cos(c)*l.rY,[w,y]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],A=([v,S])=>{const H=Math.atan2(S,v)*180/Math.PI;return H<w?H+360:H},E=vn(g,-d,0).map(A);for(const v of E)v>w&&v<y&&f(Cn(l.cX,d,g,v));const M=vn(p,-_,0).map(A);for(const v of M)v>w&&v<y&&h(Cn(l.cY,_,p,v))}return s});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const se={ROUND:yo,TO_ABS:Ln,TO_REL:_o,NORMALIZE_HVZ:mo,NORMALIZE_ST:kn,QT_TO_C:Dn,INFO:Ie,SANITIZE:wo,MATRIX:Ue,ROTATE:Eo,TRANSLATE:bo,SCALE:To,SKEW_X:Ao,SKEW_Y:Oo,X_AXIS_SYMMETRY:Mo,Y_AXIS_SYMMETRY:So,A_TO_C:vo,ANNOTATE_ARCS:No,CLONE:Pn,CALCULATE_BOUNDS:Co,REVERSE_PATH:po};class Un{round(t){return this.transform(se.ROUND(t))}toAbs(){return this.transform(se.TO_ABS())}toRel(){return this.transform(se.TO_REL())}normalizeHVZ(t,n,i){return this.transform(se.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(se.NORMALIZE_ST())}qtToC(){return this.transform(se.QT_TO_C())}aToC(){return this.transform(se.A_TO_C())}sanitize(t){return this.transform(se.SANITIZE(t))}translate(t,n){return this.transform(se.TRANSLATE(t,n))}scale(t,n){return this.transform(se.SCALE(t,n))}rotate(t,n,i){return this.transform(se.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(se.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(se.SKEW_X(t))}skewY(t){return this.transform(se.SKEW_Y(t))}xSymmetry(t){return this.transform(se.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(se.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(se.ANNOTATE_ARCS())}}const Ro=e=>e===" "||e===" "||e==="\r"||e===`
2
+ `,Vn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class Io extends Un{constructor(){super();ne(this,"curNumber","");ne(this,"curCommandType",-1);ne(this,"curCommandRelative",!1);ne(this,"canParseCommandOrComma",!0);ne(this,"curNumberHasExp",!1);ne(this,"curNumberHasExpDigits",!1);ne(this,"curNumberHasDecimal",!1);ne(this,"curArgs",[])}finish(n=[]){if(this.parse(" ",n),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return n}parse(n,i=[]){const o=s=>{i.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<n.length;s++){const r=n[s],a=this.curCommandType===T.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),l=Vn(r)&&(this.curNumber==="0"&&r==="0"||a);if(Vn(r)&&!l){this.curNumber+=r,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(r==="e"||r==="E"){this.curNumber+=r,this.curNumberHasExp=!0;continue}if((r==="-"||r==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=r;continue}if(r==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!a){this.curNumber+=r,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const f=Number(this.curNumber);if(isNaN(f))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===T.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>f)throw new SyntaxError(`Expected positive number, got "${f}" at index "${s}"`)}else if((this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber!=="0"&&this.curNumber!=="1")throw new SyntaxError(`Expected a flag, got "${this.curNumber}" at index "${s}"`)}this.curArgs.push(f),this.curArgs.length===Lo[this.curCommandType]&&(T.HORIZ_LINE_TO===this.curCommandType?o({type:T.HORIZ_LINE_TO,relative:this.curCommandRelative,x:f}):T.VERT_LINE_TO===this.curCommandType?o({type:T.VERT_LINE_TO,relative:this.curCommandRelative,y:f}):this.curCommandType===T.MOVE_TO||this.curCommandType===T.LINE_TO||this.curCommandType===T.SMOOTH_QUAD_TO?(o({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),T.MOVE_TO===this.curCommandType&&(this.curCommandType=T.LINE_TO)):this.curCommandType===T.CURVE_TO?o({type:T.CURVE_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x2:this.curArgs[2],y2:this.curArgs[3],x:this.curArgs[4],y:this.curArgs[5]}):this.curCommandType===T.SMOOTH_CURVE_TO?o({type:T.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===T.QUAD_TO?o({type:T.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===T.ARC&&o({type:T.ARC,relative:this.curCommandRelative,rX:this.curArgs[0],rY:this.curArgs[1],xRot:this.curArgs[2],lArcFlag:this.curArgs[3],sweepFlag:this.curArgs[4],x:this.curArgs[5],y:this.curArgs[6]})),this.curNumber="",this.curNumberHasExpDigits=!1,this.curNumberHasExp=!1,this.curNumberHasDecimal=!1,this.canParseCommandOrComma=!0}if(!Ro(r)){if(r===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(r==="+"||r==="-"||r==="."){this.curNumber=r,this.curNumberHasDecimal=r===".";continue}if(l){this.curNumber=r,this.curNumberHasDecimal=!1;continue}if(this.curArgs.length!==0)throw new SyntaxError(`Unterminated command at index ${s}.`);if(!this.canParseCommandOrComma)throw new SyntaxError(`Unexpected character "${r}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,r==="z"||r==="Z"){i.push({type:T.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(r==="h"||r==="H")this.curCommandType=T.HORIZ_LINE_TO,this.curCommandRelative=r==="h";else if(r==="v"||r==="V")this.curCommandType=T.VERT_LINE_TO,this.curCommandRelative=r==="v";else if(r==="m"||r==="M")this.curCommandType=T.MOVE_TO,this.curCommandRelative=r==="m";else if(r==="l"||r==="L")this.curCommandType=T.LINE_TO,this.curCommandRelative=r==="l";else if(r==="c"||r==="C")this.curCommandType=T.CURVE_TO,this.curCommandRelative=r==="c";else if(r==="s"||r==="S")this.curCommandType=T.SMOOTH_CURVE_TO,this.curCommandRelative=r==="s";else if(r==="q"||r==="Q")this.curCommandType=T.QUAD_TO,this.curCommandRelative=r==="q";else if(r==="t"||r==="T")this.curCommandType=T.SMOOTH_QUAD_TO,this.curCommandRelative=r==="t";else if(r==="a"||r==="A")this.curCommandType=T.ARC,this.curCommandRelative=r==="a";else throw new SyntaxError(`Unexpected character "${r}" at index ${s}.`)}}return i}transform(n){return Object.create(this,{parse:{value(o,s=[]){const r=Object.getPrototypeOf(this).parse.call(this,o);for(const a of r){const l=n(a);Array.isArray(l)?s.push(...l):s.push(l)}return s}}})}}const $=class $ extends Un{constructor(n){super();ne(this,"commands");typeof n=="string"?this.commands=$.parse(n):this.commands=n}encode(){return $.encode(this.commands)}getBounds(){const n=se.CALCULATE_BOUNDS();return this.transform(n),n}transform(n){const i=[];for(const o of this.commands){const s=n(o);Array.isArray(s)?i.push(...s):i.push(s)}return this.commands=i,this}reverse(n=!0){return this.commands=se.REVERSE_PATH(this.commands,n),this}static encode(n){return co(n)}static parse(n){const i=new Io,o=[];return i.parse(n,o),i.finish(o),o}};ne($,"CLOSE_PATH",1),ne($,"MOVE_TO",2),ne($,"HORIZ_LINE_TO",4),ne($,"VERT_LINE_TO",8),ne($,"LINE_TO",16),ne($,"CURVE_TO",32),ne($,"SMOOTH_CURVE_TO",64),ne($,"QUAD_TO",128),ne($,"SMOOTH_QUAD_TO",256),ne($,"ARC",512),ne($,"LINE_COMMANDS",$.LINE_TO|$.HORIZ_LINE_TO|$.VERT_LINE_TO),ne($,"DRAWING_COMMANDS",$.HORIZ_LINE_TO|$.VERT_LINE_TO|$.LINE_TO|$.CURVE_TO|$.SMOOTH_CURVE_TO|$.QUAD_TO|$.SMOOTH_QUAD_TO|$.ARC);let T=$;const Lo={[T.MOVE_TO]:2,[T.LINE_TO]:2,[T.HORIZ_LINE_TO]:1,[T.VERT_LINE_TO]:1,[T.CLOSE_PATH]:0,[T.QUAD_TO]:4,[T.SMOOTH_QUAD_TO]:2,[T.CURVE_TO]:6,[T.SMOOTH_CURVE_TO]:4,[T.ARC]:7},ko=e=>{const t=new T(e).toAbs().commands,n=[];let i=[],o=null;for(const s of t)switch(s.type){case T.MOVE_TO:i.length>0&&(n.push({points:i}),i=[]),o=[s.x,s.y],i.push(o);break;case T.LINE_TO:i.push([s.x,s.y]);break;case T.HORIZ_LINE_TO:const r=i[i.length-1][1];i.push([s.x,r]);break;case T.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,s.y]);break;case T.CURVE_TO:case T.SMOOTH_CURVE_TO:case T.QUAD_TO:case T.SMOOTH_QUAD_TO:case T.ARC:i.push([s.x,s.y]);break}if(i.length>2&&n.push({points:i}),n.length>0){const s=Ne(n[0].points);return{rings:n,bounds:s}}},Do=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:ee.POLYGON,geometry:{points:o,bounds:Ne(o)}}},Po=e=>{const t=Sn(e),n=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),o=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-o,minY:i-s,maxX:n+o,maxY:i+s};return{type:ee.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},Uo=e=>{const t=Sn(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(l=>l.getAttribute("d")||"").map(l=>ko(l)).filter(Boolean),s=o.reduce((l,f)=>[...l,...f.rings[0].points],[]),r=Ne(s);return o.length===1&&o[0].rings.length===1?{type:ee.POLYGON,geometry:{points:s,bounds:r}}:{type:ee.MULTIPOLYGLON,geometry:{polygons:o,bounds:r}}},Hn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Do(t);if(t.includes("<path "))return Uo(t);if(t.includes("<ellipse "))return Po(t);throw"Unsupported SVG shape: "+t},Vo=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${ke(n)}" />`).join("")}</g>`,Bn=e=>{let t;if(e.type===ee.POLYGON){const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`}else if(e.type===ee.ELLIPSE){const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`}else if(e.type===ee.MULTIPOLYGLON){const n=e.geometry;t=`<svg>${Vo(n)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},he=[];for(let e=0;e<256;++e)he.push((e+256).toString(16).slice(1));function Ho(e,t=0){return(he[e[t+0]]+he[e[t+1]]+he[e[t+2]]+he[e[t+3]]+"-"+he[e[t+4]]+he[e[t+5]]+"-"+he[e[t+6]]+he[e[t+7]]+"-"+he[e[t+8]]+he[e[t+9]]+"-"+he[e[t+10]]+he[e[t+11]]+he[e[t+12]]+he[e[t+13]]+he[e[t+14]]+he[e[t+15]]).toLowerCase()}let Bt;const Bo=new Uint8Array(16);function Yo(){if(!Bt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Bt=crypto.getRandomValues.bind(crypto)}return Bt(Bo)}const Yn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Xn(e,t,n){var o;if(Yn.randomUUID&&!e)return Yn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Yo();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Ho(i)}var Fn=Object.prototype.hasOwnProperty;function Ve(e,t){var n,i;if(e===t)return!0;if(e&&t&&(n=e.constructor)===t.constructor){if(n===Date)return e.getTime()===t.getTime();if(n===RegExp)return e.toString()===t.toString();if(n===Array){if((i=e.length)===t.length)for(;i--&&Ve(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Fn.call(e,n)&&++i&&!Fn.call(t,n)||!(n in t)||!Ve(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}function Yt(){}function Xo(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const We=[];function Xt(e,t=Yt){let n;const i=new Set;function o(a){if(Xo(e,a)&&(e=a,n)){const l=!We.length;for(const f of i)f[1](),We.push(f,e);if(l){for(let f=0;f<We.length;f+=2)We[f][0](We[f+1]);We.length=0}}}function s(a){o(a(e))}function r(a,l=Yt){const f=[a,l];return i.add(f),i.size===1&&(n=t(o,s)||Yt),a(e),()=>{i.delete(f),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const Fo=e=>{const{subscribe:t,set:n}=Xt();let i;return t(o=>i=o),e.observe(({changes:o})=>{if(i){(o.deleted||[]).some(r=>r.id===i)&&n(void 0);const s=(o.updated||[]).find(({oldValue:r})=>r.id===i);s&&n(s.newValue.id)}}),{get current(){return i},subscribe:t,set:n}};var Ft=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Ft||{});const bt={selected:[]},zo=(e,t,n)=>{const{subscribe:i,set:o}=Xt(bt);let s=t,r=bt;i(g=>r=g);const a=()=>{Ve(r,bt)||o(bt)},l=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},f=g=>{if(l())return!1;const p=typeof g=="string"?g:g.id;return r.selected.some(w=>w.id===p)},h=(g,p)=>{let w;if(Array.isArray(g)){if(w=g.map(A=>e.getAnnotation(A)).filter(Boolean),w.length<g.length){console.warn("Invalid selection: "+g.filter(A=>!w.some(E=>E.id===A)));return}}else{const A=e.getAnnotation(g);if(!A){console.warn("Invalid selection: "+g);return}w=[A]}const y=w.reduce((A,E)=>{const M=zn(E,s,n);return M==="EDIT"?[...A,{id:E.id,editable:!0}]:M==="SELECT"?[...A,{id:E.id}]:A},[]);o({selected:y,event:p})},c=(g,p)=>{const w=Array.isArray(g)?g:[g],y=w.map(A=>e.getAnnotation(A)).filter(A=>!!A);o({selected:y.map(A=>{const E=p===void 0?zn(A,s,n)==="EDIT":p;return{id:A.id,editable:E}})}),y.length!==w.length&&console.warn("Invalid selection",g)},d=g=>{if(l())return!1;const{selected:p}=r;p.some(({id:w})=>g.includes(w))&&o({selected:p.filter(({id:w})=>!g.includes(w))})},_=g=>{s=g,c(r.selected.map(({id:p})=>p))};return e.observe(({changes:g})=>d((g.deleted||[]).map(p=>p.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:a,isEmpty:l,isSelected:f,setSelected:c,setUserSelectAction:_,subscribe:i,userSelect:h}},zn=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},de=[];for(let e=0;e<256;++e)de.push((e+256).toString(16).slice(1));function Go(e,t=0){return(de[e[t+0]]+de[e[t+1]]+de[e[t+2]]+de[e[t+3]]+"-"+de[e[t+4]]+de[e[t+5]]+"-"+de[e[t+6]]+de[e[t+7]]+"-"+de[e[t+8]]+de[e[t+9]]+"-"+de[e[t+10]]+de[e[t+11]]+de[e[t+12]]+de[e[t+13]]+de[e[t+14]]+de[e[t+15]]).toLowerCase()}let zt;const jo=new Uint8Array(16);function Qo(){if(!zt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");zt=crypto.getRandomValues.bind(crypto)}return zt(jo)}const qo=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Gn={randomUUID:qo};function jn(e,t,n){var i;if(Gn.randomUUID&&!e)return Gn.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??Qo();if(o.length<16)throw new Error("Random bytes length must be >= 16");return o[6]=o[6]&15|64,o[8]=o[8]&63|128,Go(o)}const Gt=e=>{const t=n=>{const i={...n};return n.created&&typeof n.created=="string"&&(i.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(i.updated=new Date(n.updated)),i};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Zo=(e,t,n,i)=>({id:jn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),Wo=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},Ko=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},Jo=(e,t)=>t.bodies.map(n=>{const i=e.bodies.find(o=>o.id===n.id);return{newBody:n,oldBody:i&&!Ve(i,n)?i:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:i})=>({oldBody:n,newBody:i})),xo=(e,t)=>!Ve(e.target,t.target),Qn=(e,t)=>{const n=Wo(e,t),i=Ko(e,t),o=Jo(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:o.length>0?o:void 0,targetUpdated:xo(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var te=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(te||{});const $o=(e,t)=>{var n,i;const{changes:o,origin:s}=t;if(!(e.options.origin?e.options.origin===s:s!=="SILENT"))return!1;if(e.options.ignore){const{ignore:r}=e.options,a=l=>l&&l.length>0;if(!(a(o.created)||a(o.deleted))){const l=(n=o.updated)==null?void 0:n.some(h=>a(h.bodiesCreated)||a(h.bodiesDeleted)||a(h.bodiesUpdated)),f=(i=o.updated)==null?void 0:i.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&l&&!f||r==="TARGET_ONLY"&&f&&!l)return!1}}if(e.options.annotations){const r=new Set([...(o.created||[]).map(a=>a.id),...(o.deleted||[]).map(a=>a.id),...(o.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(a=>r.has(a))}else return!0},es=(e,t)=>{const n=new Set((e.created||[]).map(c=>c.id)),i=new Set((e.updated||[]).map(({newValue:c})=>c.id)),o=new Set((t.created||[]).map(c=>c.id)),s=new Set((t.deleted||[]).map(c=>c.id)),r=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>n.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(e.created||[]).filter(c=>!s.has(c.id)).map(c=>r.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],f=[...(e.deleted||[]).filter(c=>!o.has(c.id)),...(t.deleted||[]).filter(c=>!n.has(c.id))],h=[...(e.updated||[]).filter(({newValue:c})=>!s.has(c.id)).map(c=>{const{oldValue:d,newValue:_}=c;if(r.has(_.id)){const g=t.updated.find(p=>p.oldValue.id===_.id).newValue;return Qn(d,g)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:f,updated:h}},Tt=e=>{const t=e.id===void 0?jn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ts=e=>e.id!==void 0,ns=()=>{const e=new Map,t=new Map,n=[],i=(m,b={})=>{n.push({onChange:m,options:b})},o=m=>{const b=n.findIndex(O=>O.onChange==m);b>-1&&n.splice(b,1)},s=(m,b)=>{const O={origin:m,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(C=>{$o(C,O)&&C.onChange(O)})},r=(m,b=te.LOCAL)=>{if(m.id&&e.get(m.id))throw Error(`Cannot add annotation ${m.id} - exists already`);{const O=Tt(m);e.set(O.id,O),O.bodies.forEach(C=>t.set(C.id,O.id)),s(b,{created:[O]})}},a=(m,b)=>{const O=Tt(typeof m=="string"?b:m),C=typeof m=="string"?m:m.id,R=C&&e.get(C);if(R){const L=Qn(R,O);return C===O.id?e.set(C,O):(e.delete(C),e.set(O.id,O)),R.bodies.forEach(Y=>t.delete(Y.id)),O.bodies.forEach(Y=>t.set(Y.id,O.id)),L}else console.warn(`Cannot update annotation ${C} - does not exist`)},l=(m,b=te.LOCAL,O=te.LOCAL)=>{const C=ts(b)?O:b,R=a(m,b);R&&s(C,{updated:[R]})},f=(m,b=te.LOCAL)=>{e.get(m.id)?l(m,b):r(m,b)},h=(m,b=te.LOCAL)=>{const O=m.reduce((C,R)=>{const L=a(R);return L?[...C,L]:C},[]);O.length>0&&s(b,{updated:O})},c=(m,b=te.LOCAL)=>{const O=m.map(Tt),{toAdd:C,toUpdate:R}=O.reduce((Y,Q)=>e.get(Q.id)?{...Y,toUpdate:[...Y.toUpdate,Q]}:{...Y,toAdd:[...Y.toAdd,Q]},{toAdd:[],toUpdate:[]}),L=R.map(Y=>a(Y,b)).filter(Boolean);C.forEach(Y=>{e.set(Y.id,Y),Y.bodies.forEach(Q=>t.set(Q.id,Y.id))}),s(b,{created:C,updated:L})},d=(m,b=te.LOCAL)=>{const O=e.get(m.annotation);if(O){const C={...O,bodies:[...O.bodies,m]};e.set(O.id,C),t.set(m.id,C.id),s(b,{updated:[{oldValue:O,newValue:C,bodiesCreated:[m]}]})}else console.warn(`Attempt to add body to missing annotation: ${m.annotation}`)},_=()=>[...e.values()],g=(m=te.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(m,{deleted:b})},p=(m,b=!0,O=te.LOCAL)=>{const C=m.map(Tt);if(b){const R=[...e.values()];e.clear(),t.clear(),C.forEach(L=>{e.set(L.id,L),L.bodies.forEach(Y=>t.set(Y.id,L.id))}),s(O,{created:C,deleted:R})}else{const R=m.reduce((L,Y)=>{const Q=Y.id&&e.get(Y.id);return Q?[...L,Q]:L},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(L=>L.id).join(", ")}`);C.forEach(L=>{e.set(L.id,L),L.bodies.forEach(Y=>t.set(Y.id,L.id))}),s(O,{created:C})}},w=m=>{const b=typeof m=="string"?m:m.id,O=e.get(b);if(O)return e.delete(b),O.bodies.forEach(C=>t.delete(C.id)),O;console.warn(`Attempt to delete missing annotation: ${b}`)},y=(m,b=te.LOCAL)=>{const O=w(m);O&&s(b,{deleted:[O]})},A=(m,b=te.LOCAL)=>{const O=m.reduce((C,R)=>{const L=w(R);return L?[...C,L]:C},[]);O.length>0&&s(b,{deleted:O})},E=m=>{const b=e.get(m.annotation);if(b){const O=b.bodies.find(C=>C.id===m.id);if(O){t.delete(O.id);const C={...b,bodies:b.bodies.filter(R=>R.id!==m.id)};return e.set(b.id,C),{oldValue:b,newValue:C,bodiesDeleted:[O]}}else console.warn(`Attempt to delete missing body ${m.id} from annotation ${m.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${m.annotation}`)},M=(m,b=te.LOCAL)=>{const O=E(m);O&&s(b,{updated:[O]})},v=(m,b=te.LOCAL)=>{const O=m.map(C=>E(C)).filter(Boolean);O.length>0&&s(b,{updated:O})},S=m=>{const b=e.get(m);return b?{...b}:void 0},N=m=>{const b=t.get(m);if(b){const O=S(b).bodies.find(C=>C.id===m);if(O)return O;console.error(`Store integrity error: body ${m} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${m}`)},H=(m,b)=>{if(m.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const O=e.get(m.annotation);if(O){const C=O.bodies.find(L=>L.id===m.id),R={...O,bodies:O.bodies.map(L=>L.id===C.id?b:L)};return e.set(O.id,R),C.id!==b.id&&(t.delete(C.id),t.set(b.id,R.id)),{oldValue:O,newValue:R,bodiesUpdated:[{oldBody:C,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${m.annotation}`)},B=(m,b,O=te.LOCAL)=>{const C=H(m,b);C&&s(O,{updated:[C]})},X=(m,b=te.LOCAL)=>{const O=m.map(C=>H({id:C.id,annotation:C.annotation},C)).filter(Boolean);s(b,{updated:O})},G=m=>{const b=e.get(m.annotation);if(b){const O={...b,target:{...b.target,...m}};return e.set(b.id,O),{oldValue:b,newValue:O,targetUpdated:{oldTarget:b.target,newTarget:m}}}else console.warn(`Attempt to update target on missing annotation: ${m.annotation}`)};return{addAnnotation:r,addBody:d,all:_,bulkAddAnnotations:p,bulkDeleteAnnotations:A,bulkDeleteBodies:v,bulkUpdateAnnotations:h,bulkUpdateBodies:X,bulkUpdateTargets:(m,b=te.LOCAL)=>{const O=m.map(C=>G(C)).filter(Boolean);O.length>0&&s(b,{updated:O})},bulkUpsertAnnotations:c,clear:g,deleteAnnotation:y,deleteBody:M,getAnnotation:S,getBody:N,observe:i,unobserve:o,updateAnnotation:l,updateBody:B,updateTarget:(m,b=te.LOCAL)=>{const O=G(m);O&&s(b,{updated:[O]})},upsertAnnotation:f}},is=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let os=()=>({emit(e,...t){for(let n=this.events[e]||[],i=0,o=n.length;i<o;i++)n[i](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var i;this.events[e]=(i=this.events[e])==null?void 0:i.filter(o=>t!==o)}}});const ss=250,rs=(e,t)=>{const n=os(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const a=g=>{if(!s){const{changes:p}=g,w=performance.now();if(w-r>ss)i.splice(o+1),i.push(p),o=i.length-1;else{const y=i.length-1;i[y]=es(i[y],p)}r=w}s=!1};e.observe(a,{origin:te.LOCAL});const l=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g),f=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),h=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({oldValue:p})=>p)),c=g=>g&&g.length>0&&e.bulkUpdateAnnotations(g.map(({newValue:p})=>p)),d=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),_=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(a),getHistory:()=>({changes:[...i],pointer:o}),on:(g,p)=>n.on(g,p),redo:()=>{if(i.length-1>o){s=!0;const{created:g,updated:p,deleted:w}=i[o+1];f(g),c(p),_(w),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:g,updated:p,deleted:w}=i[o];l(g),h(p),d(w),n.emit("undo",i[o]),o-=1}}}},ls=()=>{const{subscribe:e,set:t}=Xt([]);return{subscribe:e,set:t}},as=(e,t,n,i)=>{const{hover:o,selection:s,store:r,viewport:a}=e,l=new Map;let f=[],h,c;const d=(y,A)=>{l.has(y)?l.get(y).push(A):l.set(y,[A])},_=(y,A)=>{const E=l.get(y);if(E){const M=E.indexOf(A);M!==-1&&E.splice(M,1)}},g=(y,A,E)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(M=>{if(n){const v=Array.isArray(A)?A.map(N=>n.serialize(N)):n.serialize(A),S=E?E instanceof PointerEvent?E:n.serialize(E):void 0;M(v,S)}else M(A,E)})},1)},p=()=>{const{selected:y}=s,A=(y||[]).map(({id:E})=>r.getAnnotation(E));A.forEach(E=>{const M=f.find(v=>v.id===E.id);(!M||!Ve(M,E))&&g("updateAnnotation",E,M)}),f=f.map(E=>A.find(({id:v})=>v===E.id)||E)};s.subscribe(({selected:y})=>{if(!(f.length===0&&y.length===0)){if(f.length===0&&y.length>0)f=y.map(({id:A})=>r.getAnnotation(A));else if(f.length>0&&y.length===0)f.forEach(A=>{const E=r.getAnnotation(A.id);E&&!Ve(E,A)&&g("updateAnnotation",E,A)}),f=[];else{const A=new Set(f.map(M=>M.id)),E=new Set(y.map(({id:M})=>M));f.filter(M=>!E.has(M.id)).forEach(M=>{const v=r.getAnnotation(M.id);v&&!Ve(v,M)&&g("updateAnnotation",v,M)}),f=[...f.filter(M=>E.has(M.id)),...y.filter(({id:M})=>!A.has(M)).map(({id:M})=>r.getAnnotation(M))]}g("selectionChanged",f)}}),o.subscribe(y=>{!h&&y?g("mouseEnterAnnotation",r.getAnnotation(y)):h&&!y?g("mouseLeaveAnnotation",r.getAnnotation(h)):h&&y&&(g("mouseLeaveAnnotation",r.getAnnotation(h)),g("mouseEnterAnnotation",r.getAnnotation(y))),h=y}),a==null||a.subscribe(y=>g("viewportIntersect",y.map(A=>r.getAnnotation(A)))),r.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(p,1e3));const{created:A,deleted:E}=y.changes;(A||[]).forEach(M=>g("createAnnotation",M)),(E||[]).forEach(M=>g("deleteAnnotation",M)),(y.changes.updated||[]).filter(M=>[...M.bodiesCreated||[],...M.bodiesDeleted||[],...M.bodiesUpdated||[]].length>0).forEach(({oldValue:M,newValue:v})=>{const S=f.find(N=>N.id===M.id)||M;f=f.map(N=>N.id===M.id?v:N),g("updateAnnotation",v,S)})},{origin:te.LOCAL}),r.observe(y=>{if(f){const A=new Set(f.map(M=>M.id)),E=(y.changes.updated||[]).filter(({newValue:M})=>A.has(M.id)).map(({newValue:M})=>M);E.length>0&&(f=f.map(M=>E.find(S=>S.id===M.id)||M))}},{origin:te.REMOTE});const w=y=>A=>{const{updated:E}=A;y?(E||[]).forEach(M=>g("updateAnnotation",M.oldValue,M.newValue)):(E||[]).forEach(M=>g("updateAnnotation",M.newValue,M.oldValue))};return t.on("undo",w(!0)),t.on("redo",w(!1)),{on:d,off:_,emit:g}},us=e=>t=>t.reduce((n,i)=>{const{parsed:o,error:s}=e.parse(i);return s?{parsed:n.parsed,failed:[...n.failed,i]}:o?{parsed:[...n.parsed,o],failed:n.failed}:{...n}},{parsed:[],failed:[]}),fs=(e,t,n)=>{const{store:i,selection:o}=e,s=y=>{if(n){const{parsed:A,error:E}=n.parse(y);A?i.addAnnotation(A,te.REMOTE):console.error(E)}else i.addAnnotation(Gt(y),te.REMOTE)},r=()=>o.clear(),a=()=>i.clear(),l=y=>{const A=i.getAnnotation(y);return n&&A?n.serialize(A):A},f=()=>n?i.all().map(n.serialize):i.all(),h=()=>{var y;const A=(((y=o.selected)==null?void 0:y.map(E=>E.id))||[]).map(E=>i.getAnnotation(E)).filter(Boolean);return n?A.map(n.serialize):A},c=(y,A=!0)=>fetch(y).then(E=>E.json()).then(E=>(_(E,A),E)),d=y=>{if(typeof y=="string"){const A=i.getAnnotation(y);if(i.deleteAnnotation(y),A)return n?n.serialize(A):A}else{const A=n?n.parse(y).parsed:y;if(A)return i.deleteAnnotation(A),y}},_=(y,A=!0)=>{if(n){const E=n.parseAll||us(n),{parsed:M,failed:v}=E(y);v.length>0&&console.warn(`Discarded ${v.length} invalid annotations`,v),i.bulkAddAnnotations(M,A,te.REMOTE)}else i.bulkAddAnnotations(y.map(Gt),A,te.REMOTE)},g=(y,A)=>{y?o.setSelected(y,A):o.clear()},p=y=>{o.clear(),o.setUserSelectAction(y)},w=y=>{if(n){const A=n.parse(y).parsed,E=n.serialize(i.getAnnotation(A.id));return i.updateAnnotation(A),E}else{const A=i.getAnnotation(y.id);return i.updateAnnotation(Gt(y)),A}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:f,getHistory:t.getHistory,getSelected:h,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:_,setSelected:g,setUserSelectAction:p,undo:t.undo,updateAnnotation:w}},cs=(e,t,n)=>typeof t=="function"?t(e,n):t,hs=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,i)=>{const o=typeof e=="function"?e(n,i):e,s=typeof t=="function"?t(n,i):t;return{...o||{},...s||{}}},ds="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let gs=e=>crypto.getRandomValues(new Uint8Array(e)),ps=(e,t,n)=>{let i=(2<<Math.log2(e.length-1))-1,o=-~(1.6*i*t/e.length);return(s=t)=>{let r="";for(;;){let a=n(o),l=o|0;for(;l--;)if(r+=e[a[l]&i]||"",r.length>=s)return r}}},ys=(e,t=21)=>ps(e,t|0,gs),_s=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=ds[n[e]&63];return t};const ms=()=>({isGuest:!0,id:ys("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ws=e=>{const t=JSON.stringify(e);let n=0;for(let i=0,o=t.length;i<o;i++){let s=t.charCodeAt(i);n=(n<<5)-n+s,n|=0}return`${n}`},qn=e=>e?typeof e=="object"?{...e}:e:void 0,Es=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:s,value:r,created:a,modified:l,creator:f,...h}=n;return{id:i||`temp-${ws(n)}`,annotation:t,type:o,purpose:s,value:r,creator:qn(f),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...h}}),bs=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:s,...r}=t,a={...r,created:o==null?void 0:o.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=a.id)!=null&&n.startsWith("temp-")&&delete a.id,a}),Ts=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],As=()=>{const e=[...Ts];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};_s();const Os=(e,t={strict:!0,invertY:!1})=>({parse:o=>Zn(o,t),serialize:o=>Wn(o,e,t)}),Zn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Xn(),{creator:i,created:o,modified:s,body:r,...a}=e,l=Es(r||[],n),f=Array.isArray(e.target)?e.target[0]:e.target,h=typeof f=="string"?f:Array.isArray(f.selector)?f.selector[0]:f.selector,c=typeof h=="string"||(h==null?void 0:h.type)==="FragmentSelector"?Tn(h,t.invertY):(h==null?void 0:h.type)==="SvgSelector"?Hn(h):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return c||!t.strict?{parsed:{...a,id:n,bodies:l,target:{created:o?new Date(o):void 0,creator:qn(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:n,selector:c||h}}}:{error:Error(`Invalid selector: ${JSON.stringify(h)}`)}},Wn=(e,t,n={strict:!0,invertY:!1})=>{const{selector:i,creator:o,created:s,updated:r,updatedBy:a,...l}=e.target;let f;try{f=i.type==ee.RECTANGLE?An(i.geometry):Bn(i)}catch(c){if(n.strict)throw c;f=i}const h={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:bs(e.bodies),created:s==null?void 0:s.toISOString(),creator:o,modified:r==null?void 0:r.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:f}};return delete h.bodies,"annotation"in h.target&&delete h.target.annotation,h},At=(e,t)=>{const n=Math.abs(t[0]-e[0]),i=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(i,2))},Ke=[];function Ms(e,t=j){let n;const i=new Set;function o(a){if(ae(e,a)&&(e=a,n)){const l=!Ke.length;for(const f of i)f[1](),Ke.push(f,e);if(l){for(let f=0;f<Ke.length;f+=2)Ke[f][0](Ke[f+1]);Ke.length=0}}}function s(a){o(a(e))}function r(a,l=j){const f=[a,l];return i.add(f),i.size===1&&(n=t(o,s)||j),a(e),()=>{i.delete(f),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const Ss=(e,t)=>{const{naturalWidth:n,naturalHeight:i}=e;if(!n&&!i){const{width:o,height:s}=e;t.setAttribute("viewBox",`0 0 ${o} ${s}`),e.addEventListener("load",r=>{const a=r.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${i}`)},Kn=(e,t)=>{Ss(e,t);const{subscribe:n,set:i}=Ms(1);let o;return window.ResizeObserver&&(o=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:a,height:l}=t.viewBox.baseVal,f=Math.max(r.width/a,r.height/l);i(f)}),o.observe(t.parentElement)),{destroy:()=>{o&&o.disconnect()},subscribe:n}},ut=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:i,fillOpacity:o,stroke:s,strokeWidth:r,strokeOpacity:a}=n;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${o||"0.25"};`),s&&(l+=`stroke:${s};`,l+=`stroke-width:${r||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}},ft=(e,t=0)=>{const{minX:n,minY:i,maxX:o,maxY:s}=e;return{x:n-t,y:i-t,w:o-n+2*t,h:s-i+2*t}},Je=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,vs=e=>({}),Jn=e=>({grab:e[0]});function Ns(e){let t,n,i,o;const s=e[8].default,r=Ki(s,e,e[7],Jn);return{c(){t=I("g"),r&&r.c(),u(t,"class","a9s-annotation selected")},m(a,l){P(a,t,l),r&&r.m(t,null),n=!0,i||(o=[K(t,"pointerup",e[2]),K(t,"pointermove",e[1])],i=!0)},p(a,[l]){r&&r.p&&(!n||l&128)&&xi(r,s,a,a[7],n?Ji(s,a[7],l,vs):$i(a[7]),Jn)},i(a){n||(V(r,a),n=!0)},o(a){z(r,a),n=!1},d(a){a&&D(t),r&&r.d(a),i=!1,ve(o)}}}function Cs(e,t,n){let{$$slots:i={},$$scope:o}=t;const s=Xe();let{shape:r}=t,{editor:a}=t,{transform:l}=t,{svgEl:f}=t,h,c,d;const _=w=>y=>{if(h=w,f){const{left:E,top:M}=f.getBoundingClientRect(),v=y.clientX-E,S=y.clientY-M;c=l.elementToImage(v,S)}else{const{offsetX:E,offsetY:M}=y;c=l.elementToImage(E,M)}d=r,y.target.setPointerCapture(y.pointerId),s("grab",y)},g=w=>{if(h){const[y,A]=l.elementToImage(w.offsetX,w.offsetY),E=[y-c[0],A-c[1]];n(3,r=a(d,h,E)),s("change",r)}},p=w=>{w.target.releasePointerCapture(w.pointerId),h=void 0,d=r,s("release",w)};return e.$$set=w=>{"shape"in w&&n(3,r=w.shape),"editor"in w&&n(4,a=w.editor),"transform"in w&&n(5,l=w.transform),"svgEl"in w&&n(6,f=w.svgEl),"$$scope"in w&&n(7,o=w.$$scope)},[_,g,p,r,a,l,f,o,i]}class Ot extends Ee{constructor(t){super(),we(this,t,Cs,Ns,ae,{shape:3,editor:4,transform:5,svgEl:6})}}function Rs(e){let t,n,i,o,s,r,a,l,f=e[3]&&xn(e);return{c(){t=I("g"),n=I("circle"),f&&f.c(),o=I("circle"),u(n,"class","a9s-handle-buffer svelte-160z737"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=e[5]+6/e[2]),u(o,"class",s=pt(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-160z737"),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",e[5]),u(t,"class",r=pt(`a9s-handle ${e[8].class||""}`.trim())+" svelte-160z737")},m(h,c){P(h,t,c),Z(t,n),f&&f.m(t,null),Z(t,o),a||(l=[K(n,"pointerenter",e[11]),K(n,"pointerleave",e[12]),K(n,"pointerdown",e[13]),K(n,"pointerdown",e[6]),K(n,"pointerup",e[14]),K(n,"pointerup",e[7])],a=!0)},p(h,c){c&1&&u(n,"cx",h[0]),c&2&&u(n,"cy",h[1]),c&36&&i!==(i=h[5]+6/h[2])&&u(n,"r",i),h[3]?f?f.p(h,c):(f=xn(h),f.c(),f.m(t,o)):f&&(f.d(1),f=null),c&8&&s!==(s=pt(`a9s-handle-dot${h[3]?" selected":""}`)+" svelte-160z737")&&u(o,"class",s),c&1&&u(o,"cx",h[0]),c&2&&u(o,"cy",h[1]),c&32&&u(o,"r",h[5]),c&256&&r!==(r=pt(`a9s-handle ${h[8].class||""}`.trim())+" svelte-160z737")&&u(t,"class",r)},d(h){h&&D(t),f&&f.d(),a=!1,ve(l)}}}function Is(e){let t,n,i,o,s,r,a,l,f;return{c(){t=I("g"),n=I("circle"),o=I("circle"),r=I("circle"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=e[5]*10),u(n,"class","a9s-touch-halo svelte-160z737"),Le(n,"touched",e[4]),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",s=e[5]+10/e[2]),u(o,"class","a9s-handle-buffer svelte-160z737"),u(r,"class","a9s-handle-dot svelte-160z737"),u(r,"cx",e[0]),u(r,"cy",e[1]),u(r,"r",a=e[5]+2/e[2]),u(t,"class","a9s-touch-handle")},m(h,c){P(h,t,c),Z(t,n),Z(t,o),Z(t,r),l||(f=[K(o,"pointerdown",e[9]),K(o,"pointerup",e[10]),K(o,"pointerdown",e[6]),K(o,"pointerup",e[7])],l=!0)},p(h,c){c&1&&u(n,"cx",h[0]),c&2&&u(n,"cy",h[1]),c&32&&i!==(i=h[5]*10)&&u(n,"r",i),c&16&&Le(n,"touched",h[4]),c&1&&u(o,"cx",h[0]),c&2&&u(o,"cy",h[1]),c&36&&s!==(s=h[5]+10/h[2])&&u(o,"r",s),c&1&&u(r,"cx",h[0]),c&2&&u(r,"cy",h[1]),c&36&&a!==(a=h[5]+2/h[2])&&u(r,"r",a)},d(h){h&&D(t),l=!1,ve(f)}}}function xn(e){let t,n;return{c(){t=I("circle"),u(t,"class","a9s-handle-selected svelte-160z737"),u(t,"cx",e[0]),u(t,"cy",e[1]),u(t,"r",n=e[5]+8/e[2])},m(i,o){P(i,t,o)},p(i,o){o&1&&u(t,"cx",i[0]),o&2&&u(t,"cy",i[1]),o&36&&n!==(n=i[5]+8/i[2])&&u(t,"r",n)},d(i){i&&D(t)}}}function Ls(e){let t;function n(s,r){return Je?Is:Rs}let o=n()(e);return{c(){o.c(),t=Ae()},m(s,r){o.m(s,r),P(s,t,r)},p(s,[r]){o.p(s,r)},i:j,o:j,d(s){s&&D(t),o.d(s)}}}function ks(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t,{selected:a=void 0}=t,l=!1;const f=y=>{y.pointerType==="touch"&&n(4,l=!0)},h=()=>n(4,l=!1);function c(y){pe.call(this,e,y)}function d(y){pe.call(this,e,y)}function _(y){pe.call(this,e,y)}function g(y){pe.call(this,e,y)}function p(y){pe.call(this,e,y)}function w(y){pe.call(this,e,y)}return e.$$set=y=>{n(8,t=De(De({},t),cn(y))),"x"in y&&n(0,o=y.x),"y"in y&&n(1,s=y.y),"scale"in y&&n(2,r=y.scale),"selected"in y&&n(3,a=y.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,i=4/r)},t=cn(t),[o,s,r,a,l,i,f,h,t,c,d,_,g,p,w]}class Ge extends Ee{constructor(t){super(),we(this,t,ks,Ls,ae,{x:0,y:1,scale:2,selected:3})}}function Ds(e){let t,n,i,o,s,r,a;return{c(){t=I("g"),n=I("circle"),o=I("circle"),s=I("circle"),u(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),u(n,"cx",e[0]),u(n,"cy",e[1]),u(n,"r",i=1.75*e[2]),u(o,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),u(o,"cx",e[0]),u(o,"cy",e[1]),u(o,"r",e[2]),u(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),u(s,"cx",e[0]),u(s,"cy",e[1]),u(s,"r",e[2]),u(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,f){P(l,t,f),Z(t,n),Z(t,o),Z(t,s),r||(a=[K(n,"pointerdown",e[5]),K(n,"pointerdown",e[3])],r=!0)},p(l,f){f&1&&u(n,"cx",l[0]),f&2&&u(n,"cy",l[1]),f&4&&i!==(i=1.75*l[2])&&u(n,"r",i),f&1&&u(o,"cx",l[0]),f&2&&u(o,"cy",l[1]),f&4&&u(o,"r",l[2]),f&1&&u(s,"cx",l[0]),f&2&&u(s,"cy",l[1]),f&4&&u(s,"r",l[2])},d(l){l&&D(t),r=!1,ve(a)}}}function Ps(e){let t;return{c(){t=I("circle"),u(t,"cx",e[0]),u(t,"cy",e[1]),u(t,"r",e[2])},m(n,i){P(n,t,i)},p(n,i){i&1&&u(t,"cx",n[0]),i&2&&u(t,"cy",n[1]),i&4&&u(t,"r",n[2])},d(n){n&&D(t)}}}function Us(e){let t;function n(s,r){return Je?Ps:Ds}let o=n()(e);return{c(){o.c(),t=Ae()},m(s,r){o.m(s,r),P(s,t,r)},p(s,[r]){o.p(s,r)},i:j,o:j,d(s){s&&D(t),o.d(s)}}}function Vs(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t;const a=f=>{f.pointerType};function l(f){pe.call(this,e,f)}return e.$$set=f=>{"x"in f&&n(0,o=f.x),"y"in f&&n(1,s=f.y),"scale"in f&&n(4,r=f.scale)},e.$$.update=()=>{e.$$.dirty&16&&n(2,i=4/r)},[o,s,i,a,r,l]}class Hs extends Ee{constructor(t){super(),we(this,t,Vs,Us,ae,{x:0,y:1,scale:4})}}function jt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function $n(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function Qt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function qt(e){const t=e.slice(),n=t[11][t[7]];return t[30]=n.point,t}function ei(e){let t,n,i,o;return{c(){t=I("circle"),u(t,"cx",n=e[30][0]),u(t,"cy",i=e[30][1]),u(t,"r",o=ct/e[3]),u(t,"class","svelte-1h2slbm")},m(s,r){P(s,t,r)},p(s,r){r[0]&2176&&n!==(n=s[30][0])&&u(t,"cx",n),r[0]&2176&&i!==(i=s[30][1])&&u(t,"cy",i),r[0]&8&&o!==(o=ct/s[3])&&u(t,"r",o)},d(s){s&&D(t)}}}function ti(e){let t,n,i,o,s,r,a,l,f,h;return{c(){t=I("mask"),n=I("rect"),a=I("circle"),u(n,"x",i=e[10].x),u(n,"y",o=e[10].y),u(n,"width",s=e[10].w),u(n,"height",r=e[10].h),u(n,"class","svelte-1h2slbm"),u(a,"cx",l=e[30][0]),u(a,"cy",f=e[30][1]),u(a,"r",h=ct/e[3]),u(a,"class","svelte-1h2slbm"),u(t,"id",`${e[20]}-inner`),u(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){P(c,t,d),Z(t,n),Z(t,a)},p(c,d){d[0]&1024&&i!==(i=c[10].x)&&u(n,"x",i),d[0]&1024&&o!==(o=c[10].y)&&u(n,"y",o),d[0]&1024&&s!==(s=c[10].w)&&u(n,"width",s),d[0]&1024&&r!==(r=c[10].h)&&u(n,"height",r),d[0]&2176&&l!==(l=c[30][0])&&u(a,"cx",l),d[0]&2176&&f!==(f=c[30][1])&&u(a,"cy",f),d[0]&8&&h!==(h=ct/c[3])&&u(a,"r",h)},d(c){c&&D(t)}}}function ni(e){let t,n;return t=new Ge({props:{class:"a9s-corner-handle",x:e[30][0],y:e[30][1],scale:e[3],selected:e[9].includes(e[32])}}),t.$on("pointerenter",e[12]),t.$on("pointerleave",e[13]),t.$on("pointerdown",e[16]),t.$on("pointerdown",function(){ie(e[29](`HANDLE-${e[32]}`))&&e[29](`HANDLE-${e[32]}`).apply(this,arguments)}),t.$on("pointerup",e[17](e[32])),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&32&&(s.x=e[30][0]),o[0]&32&&(s.y=e[30][1]),o[0]&8&&(s.scale=e[3]),o[0]&512&&(s.selected=e[9].includes(e[32])),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function ii(e){let t,n;return t=new Hs({props:{x:e[30][0],y:e[30][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[19](e[7]))&&e[19](e[7]).apply(this,arguments)}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&2176&&(s.x=e[30][0]),o[0]&2176&&(s.y=e[30][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Bs(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p,w,y,A,E,M,v,S=e[7]!==void 0&&!e[8]&&ei(qt(e)),N=e[7]!==void 0&&!e[8]&&ti(Qt(e)),H=Oe(e[5].points),B=[];for(let m=0;m<H.length;m+=1)B[m]=ni($n(e,H,m));const X=m=>z(B[m],1,1,()=>{B[m]=null});let G=e[7]!==void 0&&!e[8]&&ii(jt(e));return{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("polygon"),S&&S.c(),N&&N.c(),h=Te(),c=I("polygon"),_=Te(),g=I("polygon"),w=Te();for(let m=0;m<B.length;m+=1)B[m].c();y=Te(),G&&G.c(),A=Ae(),u(i,"x",o=e[10].x),u(i,"y",s=e[10].y),u(i,"width",r=e[10].w),u(i,"height",a=e[10].h),u(i,"class","svelte-1h2slbm"),u(l,"points",f=e[5].points.map(oi).join(" ")),u(l,"class","svelte-1h2slbm"),u(n,"id",`${e[20]}-outer`),u(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),u(c,"class","a9s-outer"),u(c,"mask",`url(#${e[20]}-outer)`),u(c,"points",d=e[5].points.map(si).join(" ")),u(g,"class","a9s-inner a9s-shape-handle"),u(g,"mask",`url(#${e[20]}-inner)`),u(g,"style",e[1]),u(g,"points",p=e[5].points.map(ri).join(" "))},m(m,b){P(m,t,b),Z(t,n),Z(n,i),Z(n,l),S&&S.m(n,null),N&&N.m(t,null),P(m,h,b),P(m,c,b),P(m,_,b),P(m,g,b),e[21](g),P(m,w,b);for(let O=0;O<B.length;O+=1)B[O]&&B[O].m(m,b);P(m,y,b),G&&G.m(m,b),P(m,A,b),E=!0,M||(v=[K(c,"pointerup",e[15]),K(c,"pointerdown",function(){ie(e[29]("SHAPE"))&&e[29]("SHAPE").apply(this,arguments)}),K(g,"pointermove",e[14]),K(g,"pointerup",e[15]),K(g,"pointerdown",function(){ie(e[29]("SHAPE"))&&e[29]("SHAPE").apply(this,arguments)})],M=!0)},p(m,b){if(e=m,(!E||b[0]&1024&&o!==(o=e[10].x))&&u(i,"x",o),(!E||b[0]&1024&&s!==(s=e[10].y))&&u(i,"y",s),(!E||b[0]&1024&&r!==(r=e[10].w))&&u(i,"width",r),(!E||b[0]&1024&&a!==(a=e[10].h))&&u(i,"height",a),(!E||b[0]&32&&f!==(f=e[5].points.map(oi).join(" ")))&&u(l,"points",f),e[7]!==void 0&&!e[8]?S?S.p(qt(e),b):(S=ei(qt(e)),S.c(),S.m(n,null)):S&&(S.d(1),S=null),e[7]!==void 0&&!e[8]?N?N.p(Qt(e),b):(N=ti(Qt(e)),N.c(),N.m(t,null)):N&&(N.d(1),N=null),(!E||b[0]&32&&d!==(d=e[5].points.map(si).join(" ")))&&u(c,"points",d),(!E||b[0]&2)&&u(g,"style",e[1]),(!E||b[0]&32&&p!==(p=e[5].points.map(ri).join(" ")))&&u(g,"points",p),b[0]&537080360){H=Oe(e[5].points);let O;for(O=0;O<H.length;O+=1){const C=$n(e,H,O);B[O]?(B[O].p(C,b),V(B[O],1)):(B[O]=ni(C),B[O].c(),V(B[O],1),B[O].m(y.parentNode,y))}for(_e(),O=H.length;O<B.length;O+=1)X(O);me()}e[7]!==void 0&&!e[8]?G?(G.p(jt(e),b),b[0]&384&&V(G,1)):(G=ii(jt(e)),G.c(),V(G,1),G.m(A.parentNode,A)):G&&(_e(),z(G,1,1,()=>{G=null}),me())},i(m){if(!E){for(let b=0;b<H.length;b+=1)V(B[b]);V(G),E=!0}},o(m){B=B.filter(Boolean);for(let b=0;b<B.length;b+=1)z(B[b]);z(G),E=!1},d(m){m&&(D(t),D(h),D(c),D(_),D(g),D(w),D(y),D(A)),S&&S.d(),N&&N.d(),e[21](null),Ye(B,m),G&&G.d(m),M=!1,ve(v)}}}function Ys(e){let t,n;return t=new Ot({props:{shape:e[0],transform:e[2],editor:e[18],svgEl:e[4],$$slots:{default:[Bs,({grab:i})=>({29:i}),({grab:i})=>[i?536870912:0]]},$$scope:{ctx:e}}}),t.$on("change",e[22]),t.$on("grab",e[23]),t.$on("release",e[24]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&1&&(s.shape=i[0]),o[0]&4&&(s.transform=i[2]),o[0]&16&&(s.svgEl=i[4]),o[0]&536874986|o[1]&4&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}const Xs=250,Fs=1e3,zs=12,ct=4.5,oi=e=>e.join(","),si=e=>e.join(","),ri=e=>e.join(",");function Gs(e,t,n){let i,o,s;const r=Xe();let{shape:a}=t,{computedStyle:l}=t,{transform:f}=t,{viewportScale:h=1}=t,{svgEl:c}=t,d,_,g=!1,p,w=[];const y=()=>n(8,g=!0),A=()=>n(8,g=!1),E=R=>{if(w.length>0){n(7,_=void 0);return}const[L,Y]=f.elementToImage(R.offsetX,R.offsetY),Q=re=>Math.pow(re[0]-L,2)+Math.pow(re[1]-Y,2),x=i.points.reduce((re,le)=>Q(le)<Q(re)?le:re),Me=o.filter(re=>re.visible).reduce((re,le)=>Q(le.point)<Q(re.point)?le:re),ue=Math.pow(Fs/h,2);Q(x)<ue||Q(Me.point)<ue?n(7,_=o.indexOf(Me)):n(7,_=void 0)},M=()=>{document.activeElement!==c&&c.focus()},v=()=>{n(9,w=[]),M()},S=R=>{n(8,g=!0),R.preventDefault(),R.stopPropagation(),p=performance.now()},N=R=>L=>{if(!p||Je||performance.now()-p>Xs)return;const Y=w.includes(R);L.metaKey||L.ctrlKey||L.shiftKey?Y?n(9,w=w.filter(Q=>Q!==R)):n(9,w=[...w,R]):Y&&w.length>1?n(9,w=[R]):Y?n(9,w=[]):n(9,w=[R]),M()},H=(R,L,Y)=>{M();let Q;const x=R.geometry;w.length>1?Q=x.points.map(([ue,be],re)=>w.includes(re)?[ue+Y[0],be+Y[1]]:[ue,be]):L==="SHAPE"?Q=x.points.map(([ue,be])=>[ue+Y[0],be+Y[1]]):Q=x.points.map(([ue,be],re)=>L===`HANDLE-${re}`?[ue+Y[0],be+Y[1]]:[ue,be]);const Me=Ne(Q);return{...R,geometry:{points:Q,bounds:Me}}},B=R=>async L=>{L.stopPropagation();const Y=[...i.points.slice(0,R+1),o[R].point,...i.points.slice(R+1)],Q=Ne(Y);r("change",{...a,geometry:{points:Y,bounds:Q}}),await no();const x=[...document.querySelectorAll(".a9s-handle")][R+1];if(x!=null&&x.firstChild){const Me=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});x.firstChild.dispatchEvent(Me)}},X=()=>{if(i.points.length<4)return;const R=i.points.filter((Y,Q)=>!w.includes(Q)),L=Ne(R);r("change",{...a,geometry:{points:R,bounds:L}}),n(9,w=[])};je(()=>{if(Je)return;const R=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),X())};return c.addEventListener("pointermove",E),c.addEventListener("keydown",R),()=>{c.removeEventListener("pointermove",E),c.removeEventListener("keydown",R)}});const G=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function m(R){st[R?"unshift":"push"](()=>{d=R,n(6,d)})}function b(R){pe.call(this,e,R)}function O(R){pe.call(this,e,R)}function C(R){pe.call(this,e,R)}return e.$$set=R=>{"shape"in R&&n(0,a=R.shape),"computedStyle"in R&&n(1,l=R.computedStyle),"transform"in R&&n(2,f=R.transform),"viewportScale"in R&&n(3,h=R.viewportScale),"svgEl"in R&&n(4,c=R.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=a.geometry),e.$$.dirty[0]&40&&n(11,o=Je?[]:i.points.map((R,L)=>{const Y=L===i.points.length-1?i.points[0]:i.points[L+1],Q=(R[0]+Y[0])/2,x=(R[1]+Y[1])/2,ue=Math.sqrt(Math.pow(Y[0]-Q,2)+Math.pow(Y[1]-x,2))>zs/h;return{point:[Q,x],visible:ue}})),e.$$.dirty[0]&40&&n(10,s=ft(i.bounds,ct/h))},[a,l,f,h,c,i,d,_,g,w,s,o,y,A,E,v,S,N,H,B,G,m,b,O,C]}class li extends Ee{constructor(t){super(),we(this,t,Gs,Ys,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function js(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p,w,y,A,E,M,v,S,N,H,B,X,G,m,b,O,C,R,L,Y,Q,x,Me,ue,be,re,le,et,tt,F,ge,J,Ce,Se,nt,He,sn,Be,W,rn,Zi;return J=new Ge({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),J.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),Se=new Ge({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),Se.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),He=new Ge({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),He.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Be=new Ge({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Be.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("rect"),_=Te(),g=I("rect"),E=Te(),M=I("rect"),B=Te(),X=I("rect"),O=Te(),C=I("rect"),Q=Te(),x=I("rect"),re=Te(),le=I("rect"),ge=Te(),ye(J.$$.fragment),Ce=Te(),ye(Se.$$.fragment),nt=Te(),ye(He.$$.fragment),sn=Te(),ye(Be.$$.fragment),u(i,"class","rect-mask-bg svelte-1njczvj"),u(i,"x",o=e[6].x),u(i,"y",s=e[6].y),u(i,"width",r=e[6].w),u(i,"height",a=e[6].h),u(l,"class","rect-mask-fg svelte-1njczvj"),u(l,"x",f=e[5].x),u(l,"y",h=e[5].y),u(l,"width",c=e[5].w),u(l,"height",d=e[5].h),u(n,"id",e[8]),u(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),u(g,"class","a9s-outer"),u(g,"mask",`url(#${e[8]})`),u(g,"x",p=e[5].x),u(g,"y",w=e[5].y),u(g,"width",y=e[5].w),u(g,"height",A=e[5].h),u(M,"class","a9s-inner a9s-shape-handle"),u(M,"style",e[1]),u(M,"x",v=e[5].x),u(M,"y",S=e[5].y),u(M,"width",N=e[5].w),u(M,"height",H=e[5].h),u(X,"class","a9s-edge-handle a9s-edge-handle-top"),u(X,"x",G=e[5].x),u(X,"y",m=e[5].y),u(X,"height",1),u(X,"width",b=e[5].w),u(C,"class","a9s-edge-handle a9s-edge-handle-right"),u(C,"x",R=e[5].x+e[5].w),u(C,"y",L=e[5].y),u(C,"height",Y=e[5].h),u(C,"width",1),u(x,"class","a9s-edge-handle a9s-edge-handle-bottom"),u(x,"x",Me=e[5].x),u(x,"y",ue=e[5].y+e[5].h),u(x,"height",1),u(x,"width",be=e[5].w),u(le,"class","a9s-edge-handle a9s-edge-handle-left"),u(le,"x",et=e[5].x),u(le,"y",tt=e[5].y),u(le,"height",F=e[5].h),u(le,"width",1)},m(q,U){P(q,t,U),Z(t,n),Z(n,i),Z(n,l),P(q,_,U),P(q,g,U),P(q,E,U),P(q,M,U),P(q,B,U),P(q,X,U),P(q,O,U),P(q,C,U),P(q,Q,U),P(q,x,U),P(q,re,U),P(q,le,U),P(q,ge,U),fe(J,q,U),P(q,Ce,U),fe(Se,q,U),P(q,nt,U),fe(He,q,U),P(q,sn,U),fe(Be,q,U),W=!0,rn||(Zi=[K(g,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),K(M,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),K(X,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),K(C,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),K(x,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),K(le,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],rn=!0)},p(q,U){e=q,(!W||U&64&&o!==(o=e[6].x))&&u(i,"x",o),(!W||U&64&&s!==(s=e[6].y))&&u(i,"y",s),(!W||U&64&&r!==(r=e[6].w))&&u(i,"width",r),(!W||U&64&&a!==(a=e[6].h))&&u(i,"height",a),(!W||U&32&&f!==(f=e[5].x))&&u(l,"x",f),(!W||U&32&&h!==(h=e[5].y))&&u(l,"y",h),(!W||U&32&&c!==(c=e[5].w))&&u(l,"width",c),(!W||U&32&&d!==(d=e[5].h))&&u(l,"height",d),(!W||U&32&&p!==(p=e[5].x))&&u(g,"x",p),(!W||U&32&&w!==(w=e[5].y))&&u(g,"y",w),(!W||U&32&&y!==(y=e[5].w))&&u(g,"width",y),(!W||U&32&&A!==(A=e[5].h))&&u(g,"height",A),(!W||U&2)&&u(M,"style",e[1]),(!W||U&32&&v!==(v=e[5].x))&&u(M,"x",v),(!W||U&32&&S!==(S=e[5].y))&&u(M,"y",S),(!W||U&32&&N!==(N=e[5].w))&&u(M,"width",N),(!W||U&32&&H!==(H=e[5].h))&&u(M,"height",H),(!W||U&32&&G!==(G=e[5].x))&&u(X,"x",G),(!W||U&32&&m!==(m=e[5].y))&&u(X,"y",m),(!W||U&32&&b!==(b=e[5].w))&&u(X,"width",b),(!W||U&32&&R!==(R=e[5].x+e[5].w))&&u(C,"x",R),(!W||U&32&&L!==(L=e[5].y))&&u(C,"y",L),(!W||U&32&&Y!==(Y=e[5].h))&&u(C,"height",Y),(!W||U&32&&Me!==(Me=e[5].x))&&u(x,"x",Me),(!W||U&32&&ue!==(ue=e[5].y+e[5].h))&&u(x,"y",ue),(!W||U&32&&be!==(be=e[5].w))&&u(x,"width",be),(!W||U&32&&et!==(et=e[5].x))&&u(le,"x",et),(!W||U&32&&tt!==(tt=e[5].y))&&u(le,"y",tt),(!W||U&32&&F!==(F=e[5].h))&&u(le,"height",F);const vt={};U&32&&(vt.x=e[5].x),U&32&&(vt.y=e[5].y),U&8&&(vt.scale=e[3]),J.$set(vt);const Nt={};U&32&&(Nt.x=e[5].x+e[5].w),U&32&&(Nt.y=e[5].y),U&8&&(Nt.scale=e[3]),Se.$set(Nt);const Ct={};U&32&&(Ct.x=e[5].x+e[5].w),U&32&&(Ct.y=e[5].y+e[5].h),U&8&&(Ct.scale=e[3]),He.$set(Ct);const Rt={};U&32&&(Rt.x=e[5].x),U&32&&(Rt.y=e[5].y+e[5].h),U&8&&(Rt.scale=e[3]),Be.$set(Rt)},i(q){W||(V(J.$$.fragment,q),V(Se.$$.fragment,q),V(He.$$.fragment,q),V(Be.$$.fragment,q),W=!0)},o(q){z(J.$$.fragment,q),z(Se.$$.fragment,q),z(He.$$.fragment,q),z(Be.$$.fragment,q),W=!1},d(q){q&&(D(t),D(_),D(g),D(E),D(M),D(B),D(X),D(O),D(C),D(Q),D(x),D(re),D(le),D(ge),D(Ce),D(nt),D(sn)),ce(J,q),ce(Se,q),ce(He,q),ce(Be,q),rn=!1,ve(Zi)}}}function Qs(e){let t,n;return t=new Ot({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[js,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,[o]){const s={};o&1&&(s.shape=i[0]),o&4&&(s.transform=i[2]),o&16&&(s.svgEl=i[4]),o&12394&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function qs(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:f}=t;const h=(p,w,y)=>{const A=p.geometry.bounds;let[E,M]=[A.minX,A.minY],[v,S]=[A.maxX,A.maxY];const[N,H]=y;if(w==="SHAPE")E+=N,v+=N,M+=H,S+=H;else{switch(w){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{M+=H;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{S+=H;break}}switch(w){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{E+=N;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{v+=N;break}}}const B=Math.min(E,v),X=Math.min(M,S),G=Math.abs(v-E),m=Math.abs(S-M);return{...p,geometry:{x:B,y:X,w:G,h:m,bounds:{minX:B,minY:X,maxX:B+G,maxY:X+m}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(p){pe.call(this,e,p)}function _(p){pe.call(this,e,p)}function g(p){pe.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,s=p.shape),"computedStyle"in p&&n(1,r=p.computedStyle),"transform"in p&&n(2,a=p.transform),"viewportScale"in p&&n(3,l=p.viewportScale),"svgEl"in p&&n(4,f=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ft(i.bounds,2/l))},[s,r,a,l,f,i,o,h,c,d,_,g]}class ai extends Ee{constructor(t){super(),we(this,t,qs,Qs,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}function ui(e,t,n){const i=e.slice();return i[13]=t[n],i[15]=n,i}function fi(e,t,n){const i=e.slice();return i[16]=t[n],i[18]=n,i}function ci(e,t,n){const i=e.slice();return i[19]=t[n],i[21]=n,i}function hi(e){let t,n;return t=new Ge({props:{class:"a9s-corner-handle",x:e[19][0],y:e[19][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[12](`HANDLE-${e[15]}-${e[18]}-${e[21]}`))&&e[12](`HANDLE-${e[15]}-${e[18]}-${e[21]}`).apply(this,arguments)}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o&32&&(s.x=e[19][0]),o&32&&(s.y=e[19][1]),o&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function di(e){let t,n,i=Oe(e[16].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=hi(ci(e,i,r));const s=r=>z(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ae()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a&4136){i=Oe(r[16].points);let l;for(l=0;l<i.length;l+=1){const f=ci(r,i,l);o[l]?(o[l].p(f,a),V(o[l],1)):(o[l]=hi(f),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(_e(),l=i.length;l<o.length;l+=1)s(l);me()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)z(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function gi(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p,w,y,A=Oe(e[13].rings),E=[];for(let v=0;v<A.length;v+=1)E[v]=di(fi(e,A,v));const M=v=>z(E[v],1,1,()=>{E[v]=null});return{c(){t=I("g"),n=I("defs"),i=I("mask"),o=I("rect"),f=I("path"),c=I("path"),_=I("path");for(let v=0;v<E.length;v+=1)E[v].c();u(o,"x",s=e[6].x),u(o,"y",r=e[6].y),u(o,"width",a=e[6].w),u(o,"height",l=e[6].h),u(o,"class","svelte-rfq8ys"),u(f,"d",h=ke(e[13])),u(f,"class","svelte-rfq8ys"),u(i,"id",`${e[8]}-${e[15]}`),u(i,"class","a9s-multipolygon-editor-mask svelte-rfq8ys"),u(c,"class","a9s-outer"),u(c,"mask",`url(#${e[8]}-${e[15]})`),u(c,"fill-rule","evenodd"),u(c,"d",d=ke(e[13])),u(_,"class","a9s-inner"),u(_,"style",e[1]),u(_,"fill-rule","evenodd"),u(_,"d",g=ke(e[13]))},m(v,S){P(v,t,S),Z(t,n),Z(n,i),Z(i,o),Z(i,f),Z(t,c),Z(t,_);for(let N=0;N<E.length;N+=1)E[N]&&E[N].m(t,null);p=!0,w||(y=[K(c,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),K(_,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)})],w=!0)},p(v,S){if(e=v,(!p||S&64&&s!==(s=e[6].x))&&u(o,"x",s),(!p||S&64&&r!==(r=e[6].y))&&u(o,"y",r),(!p||S&64&&a!==(a=e[6].w))&&u(o,"width",a),(!p||S&64&&l!==(l=e[6].h))&&u(o,"height",l),(!p||S&32&&h!==(h=ke(e[13])))&&u(f,"d",h),(!p||S&32&&d!==(d=ke(e[13])))&&u(c,"d",d),(!p||S&2)&&u(_,"style",e[1]),(!p||S&32&&g!==(g=ke(e[13])))&&u(_,"d",g),S&4136){A=Oe(e[13].rings);let N;for(N=0;N<A.length;N+=1){const H=fi(e,A,N);E[N]?(E[N].p(H,S),V(E[N],1)):(E[N]=di(H),E[N].c(),V(E[N],1),E[N].m(t,null))}for(_e(),N=A.length;N<E.length;N+=1)M(N);me()}},i(v){if(!p){for(let S=0;S<A.length;S+=1)V(E[S]);p=!0}},o(v){E=E.filter(Boolean);for(let S=0;S<E.length;S+=1)z(E[S]);p=!1},d(v){v&&D(t),Ye(E,v),w=!1,ve(y)}}}function Zs(e){let t,n,i=Oe(e[5].polygons),o=[];for(let r=0;r<i.length;r+=1)o[r]=gi(ui(e,i,r));const s=r=>z(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ae()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a&4458){i=Oe(r[5].polygons);let l;for(l=0;l<i.length;l+=1){const f=ui(r,i,l);o[l]?(o[l].p(f,a),V(o[l],1)):(o[l]=gi(f),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(_e(),l=i.length;l<o.length;l+=1)s(l);me()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)z(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function Ws(e){let t,n;return t=new Ot({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Zs,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:e}}}),t.$on("change",e[9]),t.$on("grab",e[10]),t.$on("release",e[11]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,[o]){const s={};o&1&&(s.shape=i[0]),o&4&&(s.transform=i[2]),o&16&&(s.svgEl=i[4]),o&4198506&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Ks(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:f}=t;const h=(p,w,y)=>{const A=p.geometry.polygons;let E;if(w==="SHAPE")E=A.map(M=>{const v=M.rings.map((N,H)=>({points:N.points.map((X,G)=>[X[0]+y[0],X[1]+y[1]])})),S=Ne(v[0].points);return{rings:v,bounds:S}});else{const[M,v,S,N]=w.split("-").map(H=>parseInt(H));E=A.map((H,B)=>{if(B===v){const X=H.rings.map((m,b)=>b===S?{points:m.points.map((C,R)=>R===N?[C[0]+y[0],C[1]+y[1]]:C)}:m),G=Ne(X[0].points);return{rings:X,bounds:G}}else return H})}return{...p,geometry:{polygons:E,bounds:En(E)}}},c=`multipoly-mask-${Math.random().toString(36).substring(2,12)}`;function d(p){pe.call(this,e,p)}function _(p){pe.call(this,e,p)}function g(p){pe.call(this,e,p)}return e.$$set=p=>{"shape"in p&&n(0,s=p.shape),"computedStyle"in p&&n(1,r=p.computedStyle),"transform"in p&&n(2,a=p.transform),"viewportScale"in p&&n(3,l=p.viewportScale),"svgEl"in p&&n(4,f=p.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ft(i.bounds,2/l))},[s,r,a,l,f,i,o,h,c,d,_,g]}class Js extends Ee{constructor(t){super(),we(this,t,Ks,Ws,ae,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}const pi=new Map([[ee.RECTANGLE,ai],[ee.POLYGON,li],[ee.MULTIPOLYGLON,Js]]),yi=e=>pi.get(e.type),_i=(e,t)=>pi.set(e,t);function xs(e,t,n){let i;const o=Xe();let{annotation:s}=t,{editor:r}=t,{style:a}=t,{target:l}=t,{transform:f}=t,{viewportScale:h}=t,c;return je(()=>(n(6,c=new r({target:l,props:{shape:s.target.selector,computedStyle:i,transform:f,viewportScale:h,svgEl:l.closest("svg")}})),c.$on("change",d=>{c.$$set({shape:d.detail}),o("change",d.detail)}),c.$on("grab",d=>o("grab",d.detail)),c.$on("release",d=>o("release",d.detail)),()=>{c.$destroy()})),e.$$set=d=>{"annotation"in d&&n(0,s=d.annotation),"editor"in d&&n(1,r=d.editor),"style"in d&&n(2,a=d.style),"target"in d&&n(3,l=d.target),"transform"in d&&n(4,f=d.transform),"viewportScale"in d&&n(5,h=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,i=ut(s,a)),e.$$.dirty&65&&s&&(c==null||c.$set({shape:s.target.selector})),e.$$.dirty&80&&c&&c.$set({transform:f}),e.$$.dirty&96&&c&&c.$set({viewportScale:h}),e.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[s,r,a,l,f,h,c,i]}class mi extends Ee{constructor(t){super(),we(this,t,xs,null,ae,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function $s(e,t,n){const i=Xe();let{drawingMode:o}=t,{target:s}=t,{tool:r}=t,{transform:a}=t,{viewportScale:l}=t,f;return je(()=>{const h=s.closest("svg"),c=[],d=(_,g,p)=>{h==null||h.addEventListener(_,g,p),c.push(()=>h==null?void 0:h.removeEventListener(_,g,p))};return n(5,f=new r({target:s,props:{addEventListener:d,drawingMode:o,transform:a,viewportScale:l}})),f.$on("create",_=>i("create",_.detail)),()=>{c.forEach(_=>_()),f.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,o=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,a=h.transform),"viewportScale"in h&&n(4,l=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&f&&f.$set({transform:a}),e.$$.dirty&48&&f&&f.$set({viewportScale:l})},[o,s,r,a,l,f]}class wi extends Ee{constructor(t){super(),we(this,t,$s,null,ae,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Ei(e){let t,n,i,o,s,r,a,l,f,h;return{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("rect"),f=I("rect"),h=I("rect"),u(i,"class","rect-mask-bg svelte-1a76qe7"),u(i,"x",o=e[1]-e[5]),u(i,"y",s=e[2]-e[5]),u(i,"width",r=e[3]+2*e[5]),u(i,"height",a=e[4]+2*e[5]),u(l,"class","rect-mask-fg svelte-1a76qe7"),u(l,"x",e[1]),u(l,"y",e[2]),u(l,"width",e[3]),u(l,"height",e[4]),u(n,"id",e[6]),u(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),u(f,"class","a9s-outer"),u(f,"mask",`url(#${e[6]})`),u(f,"x",e[1]),u(f,"y",e[2]),u(f,"width",e[3]),u(f,"height",e[4]),u(h,"class","a9s-inner"),u(h,"x",e[1]),u(h,"y",e[2]),u(h,"width",e[3]),u(h,"height",e[4])},m(c,d){P(c,t,d),Z(t,n),Z(n,i),Z(n,l),P(c,f,d),P(c,h,d)},p(c,d){d&34&&o!==(o=c[1]-c[5])&&u(i,"x",o),d&36&&s!==(s=c[2]-c[5])&&u(i,"y",s),d&40&&r!==(r=c[3]+2*c[5])&&u(i,"width",r),d&48&&a!==(a=c[4]+2*c[5])&&u(i,"height",a),d&2&&u(l,"x",c[1]),d&4&&u(l,"y",c[2]),d&8&&u(l,"width",c[3]),d&16&&u(l,"height",c[4]),d&2&&u(f,"x",c[1]),d&4&&u(f,"y",c[2]),d&8&&u(f,"width",c[3]),d&16&&u(f,"height",c[4]),d&2&&u(h,"x",c[1]),d&4&&u(h,"y",c[2]),d&8&&u(h,"width",c[3]),d&16&&u(h,"height",c[4])},d(c){c&&(D(t),D(f),D(h))}}}function er(e){let t,n=e[0]&&Ei(e);return{c(){t=I("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(i,o){P(i,t,o),n&&n.m(t,null)},p(i,[o]){i[0]?n?n.p(i,o):(n=Ei(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(i){i&&D(t),n&&n.d()}}}function tr(e,t,n){let i;const o=Xe();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:a}=t,{viewportScale:l=1}=t,f,h,c,d,_,g,p;const w=v=>{const S=v;f=performance.now(),r==="drag"&&(n(0,h=a.elementToImage(S.offsetX,S.offsetY)),c=h,n(1,d=h[0]),n(2,_=h[1]),n(3,g=1),n(4,p=1))},y=v=>{const S=v;h&&(c=a.elementToImage(S.offsetX,S.offsetY),n(1,d=Math.min(c[0],h[0])),n(2,_=Math.min(c[1],h[1])),n(3,g=Math.abs(c[0]-h[0])),n(4,p=Math.abs(c[1]-h[1])))},A=v=>{const S=v,N=performance.now()-f;if(r==="click"){if(N>300)return;h?E():(n(0,h=a.elementToImage(S.offsetX,S.offsetY)),c=h,n(1,d=h[0]),n(2,_=h[1]),n(3,g=1),n(4,p=1))}else h&&(N>300||g*p>100?(S.stopPropagation(),E()):(n(0,h=void 0),c=void 0))},E=()=>{if(g*p>15){const v={type:ee.RECTANGLE,geometry:{bounds:{minX:d,minY:_,maxX:d+g,maxY:_+p},x:d,y:_,w:g,h:p}};o("create",v)}n(0,h=void 0),c=void 0};je(()=>{s("pointerdown",w),s("pointermove",y),s("pointerup",A,!0)});const M=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=v=>{"addEventListener"in v&&n(7,s=v.addEventListener),"drawingMode"in v&&n(8,r=v.drawingMode),"transform"in v&&n(9,a=v.transform),"viewportScale"in v&&n(10,l=v.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,i=2/l)},[h,d,_,g,p,i,M,s,r,a,l]}class bi extends Ee{constructor(t){super(),we(this,t,tr,er,ae,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Zt(e){const t=e.slice(),n=t[2].map(i=>i.join(",")).join(" ");return t[19]=n,t}function Ti(e){let t,n,i,o,s,r,a,l,f,h,c,d,_,g,p=e[1]&&Ai(e);return{c(){t=I("defs"),n=I("mask"),i=I("rect"),l=I("polygon"),h=I("polygon"),d=I("polygon"),p&&p.c(),g=Ae(),u(i,"x",o=e[3].x),u(i,"y",s=e[3].y),u(i,"width",r=e[3].w),u(i,"height",a=e[3].h),u(i,"class","svelte-18wrg3t"),u(l,"points",f=e[19]),u(l,"class","svelte-18wrg3t"),u(n,"id",e[5]),u(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),u(h,"class","a9s-outer"),u(h,"mask",`url(#${e[5]})`),u(h,"points",c=e[19]),u(d,"class","a9s-inner"),u(d,"points",_=e[19])},m(w,y){P(w,t,y),Z(t,n),Z(n,i),Z(n,l),P(w,h,y),P(w,d,y),p&&p.m(w,y),P(w,g,y)},p(w,y){y&8&&o!==(o=w[3].x)&&u(i,"x",o),y&8&&s!==(s=w[3].y)&&u(i,"y",s),y&8&&r!==(r=w[3].w)&&u(i,"width",r),y&8&&a!==(a=w[3].h)&&u(i,"height",a),y&4&&f!==(f=w[19])&&u(l,"points",f),y&4&&c!==(c=w[19])&&u(h,"points",c),y&4&&_!==(_=w[19])&&u(d,"points",_),w[1]?p?p.p(w,y):(p=Ai(w),p.c(),p.m(g.parentNode,g)):p&&(p.d(1),p=null)},d(w){w&&(D(t),D(h),D(d),D(g)),p&&p.d(w)}}}function Ai(e){let t,n,i;return{c(){t=I("circle"),u(t,"class","a9s-handle svelte-18wrg3t"),u(t,"cx",n=e[0][0][0]),u(t,"cy",i=e[0][0][1]),u(t,"r",e[4])},m(o,s){P(o,t,s)},p(o,s){s&1&&n!==(n=o[0][0][0])&&u(t,"cx",n),s&1&&i!==(i=o[0][0][1])&&u(t,"cy",i),s&16&&u(t,"r",o[4])},d(o){o&&D(t)}}}function nr(e){let t,n=e[3]&&Ti(Zt(e));return{c(){t=I("g"),n&&n.c(),u(t,"class","a9s-annotation a9s-rubberband")},m(i,o){P(i,t,o),n&&n.m(t,null)},p(i,[o]){i[3]?n?n.p(Zt(i),o):(n=Ti(Zt(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(i){i&&D(t),n&&n.d()}}}const ir=20,or=1500;function sr(e,t,n){let i,o,s;const r=Xe();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:f}=t,{viewportScale:h=1}=t,c,d=[],_,g,p=!1;const w=S=>{const N=S,{timeStamp:H,offsetX:B,offsetY:X}=N;if(c={timeStamp:H,offsetX:B,offsetY:X},l==="drag"&&d.length===0){const G=f.elementToImage(N.offsetX,N.offsetY);d.push(G),n(10,_=G)}},y=S=>{const N=S;if(g&&clearTimeout(g),d.length>0){if(n(10,_=f.elementToImage(N.offsetX,N.offsetY)),d.length>2){const H=At(_,d[0])*h;n(1,p=H<ir)}N.pointerType==="touch"&&(g=setTimeout(()=>{E()},or))}},A=S=>{const N=S;if(g&&clearTimeout(g),l==="click"){const H=N.timeStamp-c.timeStamp,B=At([c.offsetX,c.offsetY],[N.offsetX,N.offsetY]);if(H>300||B>15)return;if(p)M();else if(d.length===0){const X=f.elementToImage(N.offsetX,N.offsetY);d.push(X),n(10,_=X)}else d.push(_)}else{if(d.length===1&&At(d[0],_)<=4){n(0,d=[]),n(10,_=void 0);return}N.stopImmediatePropagation(),p?M():d.push(_)}},E=()=>{if(!_)return;const S=d.slice(0,-1);if(S.length<3)return;const N={type:ee.POLYGON,geometry:{bounds:Ne(d),points:S}};_t(N)>4&&(n(0,d=[]),n(10,_=void 0),r("create",N))},M=()=>{const S={type:ee.POLYGON,geometry:{bounds:Ne(d),points:[...d]}};n(0,d=[]),n(10,_=void 0),r("create",S)};je(()=>{a("pointerdown",w,!0),a("pointermove",y),a("pointerup",A,!0),a("dblclick",E,!0)});const v=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=S=>{"addEventListener"in S&&n(6,a=S.addEventListener),"drawingMode"in S&&n(7,l=S.drawingMode),"transform"in S&&n(8,f=S.transform),"viewportScale"in S&&n(9,h=S.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,i=4/h),e.$$.dirty&1027&&n(2,o=_?p?d:[...d,_]:[]),e.$$.dirty&516&&n(3,s=o.length>0?ft(Ne(o),2/h):void 0)},[d,p,o,s,i,v,a,l,f,h,_]}class rr extends Ee{constructor(t){super(),we(this,t,sr,nr,ae,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Wt=new Map([["rectangle",{tool:bi}],["polygon",{tool:rr}]]),Kt=()=>[...Wt.keys()],Jt=e=>Wt.get(e),Oi=(e,t,n={})=>Wt.set(e,{tool:t,opts:n});function lr(e){let t,n,i,o,s;return{c(){t=I("g"),n=I("ellipse"),o=I("ellipse"),u(n,"class","a9s-outer"),u(n,"style",i=e[1]?"display:none;":void 0),u(n,"cx",e[2]),u(n,"cy",e[3]),u(n,"rx",e[4]),u(n,"ry",e[5]),u(o,"class","a9s-inner"),u(o,"style",e[1]),u(o,"cx",e[2]),u(o,"cy",e[3]),u(o,"rx",e[4]),u(o,"ry",e[5]),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&u(n,"style",i),a&2&&u(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:j,o:j,d(r){r&&D(t)}}}function ar(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{cx:a,cy:l,rx:f,ry:h}=s;return e.$$set=c=>{"annotation"in c&&n(0,o=c.annotation),"geom"in c&&n(6,s=c.geom),"style"in c&&n(7,r=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,i=ut(o,r))},[o,i,a,l,f,h,s,r]}class ur extends Ee{constructor(t){super(),we(this,t,ar,lr,ae,{annotation:0,geom:6,style:7})}}function Mi(e,t,n){const i=e.slice();return i[5]=t[n],i}function Si(e){let t,n,i;return{c(){t=I("path"),i=I("path"),u(t,"class","a9s-outer"),u(t,"style",n=e[1]?"display:none;":void 0),u(t,"fill-rule","evenodd"),u(t,"d",ke(e[5])),u(i,"class","a9s-inner"),u(i,"style",e[1]),u(i,"fill-rule","evenodd"),u(i,"d",ke(e[5]))},m(o,s){P(o,t,s),P(o,i,s)},p(o,s){s&2&&n!==(n=o[1]?"display:none;":void 0)&&u(t,"style",n),s&2&&u(i,"style",o[1])},d(o){o&&(D(t),D(i))}}}function fr(e){let t,n,i=Oe(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=Si(Mi(e,i,s));return{c(){t=I("g");for(let s=0;s<o.length;s+=1)o[s].c();u(t,"class","a9s-annotation"),u(t,"data-id",n=e[0].id)},m(s,r){P(s,t,r);for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(t,null)},p(s,[r]){if(r&6){i=Oe(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Mi(s,i,a);o[a]?o[a].p(l,r):(o[a]=Si(l),o[a].c(),o[a].m(t,null))}for(;a<o.length;a+=1)o[a].d(1);o.length=i.length}r&1&&n!==(n=s[0].id)&&u(t,"data-id",n)},i:j,o:j,d(s){s&&D(t),Ye(o,s)}}}function cr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{polygons:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,a,s,r]}class hr extends Ee{constructor(t){super(),we(this,t,cr,fr,ae,{annotation:0,geom:3,style:4})}}function dr(e){let t,n,i,o,s;return{c(){t=I("g"),n=I("polygon"),o=I("polygon"),u(n,"class","a9s-outer"),u(n,"style",i=e[1]?"display:none;":void 0),u(n,"points",e[2].map(gr).join(" ")),u(o,"class","a9s-inner"),u(o,"style",e[1]),u(o,"points",e[2].map(pr).join(" ")),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&2&&i!==(i=r[1]?"display:none;":void 0)&&u(n,"style",i),a&2&&u(o,"style",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:j,o:j,d(r){r&&D(t)}}}const gr=e=>e.join(","),pr=e=>e.join(",");function yr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:a}=s;return e.$$set=l=>{"annotation"in l&&n(0,o=l.annotation),"geom"in l&&n(3,s=l.geom),"style"in l&&n(4,r=l.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,a,s,r]}class _r extends Ee{constructor(t){super(),we(this,t,yr,dr,ae,{annotation:0,geom:3,style:4})}}function mr(e){let t,n,i,o,s;return{c(){t=I("g"),n=I("rect"),o=I("rect"),u(n,"class","a9s-outer"),u(n,"style",i=e[5]?"display:none;":void 0),u(n,"x",e[4]),u(n,"y",e[3]),u(n,"width",e[2]),u(n,"height",e[1]),u(o,"class","a9s-inner"),u(o,"style",e[5]),u(o,"x",e[4]),u(o,"y",e[3]),u(o,"width",e[2]),u(o,"height",e[1]),u(t,"class","a9s-annotation"),u(t,"data-id",s=e[0].id)},m(r,a){P(r,t,a),Z(t,n),Z(t,o)},p(r,[a]){a&32&&i!==(i=r[5]?"display:none;":void 0)&&u(n,"style",i),a&16&&u(n,"x",r[4]),a&8&&u(n,"y",r[3]),a&4&&u(n,"width",r[2]),a&2&&u(n,"height",r[1]),a&32&&u(o,"style",r[5]),a&16&&u(o,"x",r[4]),a&8&&u(o,"y",r[3]),a&4&&u(o,"width",r[2]),a&2&&u(o,"height",r[1]),a&1&&s!==(s=r[0].id)&&u(t,"data-id",s)},i:j,o:j,d(r){r&&D(t)}}}function wr(e,t,n){let i,o,s,r,a,{annotation:l}=t,{geom:f}=t,{style:h}=t;return e.$$set=c=>{"annotation"in c&&n(0,l=c.annotation),"geom"in c&&n(6,f=c.geom),"style"in c&&n(7,h=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,i=ut(l,h)),e.$$.dirty&64&&n(4,{x:o,y:s,w:r,h:a}=f,o,(n(3,s),n(6,f)),(n(2,r),n(6,f)),(n(1,a),n(6,f)))},[l,a,r,s,o,i,f,h]}class Er extends Ee{constructor(t){super(),we(this,t,wr,mr,ae,{annotation:0,geom:6,style:7})}}const br={elementToImage:(e,t)=>[e,t]},vi=e=>({elementToImage:(t,n)=>{const i=e.getBoundingClientRect(),o=e.createSVGPoint();o.x=t+i.x,o.y=n+i.y;const{x:s,y:r}=o.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),Tr=250,Ni=(e,t)=>{const n=Xe();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<Tr){const{x:l,y:f}=xt(r,e),h=t.getAt(l,f);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},xt=(e,t)=>{const n=t.createSVGPoint(),i=t.getBoundingClientRect(),o=e.clientX-i.x,s=e.clientY-i.y,{left:r,top:a}=t.getBoundingClientRect();return n.x=o+r,n.y=s+a,n.matrixTransform(t.getScreenCTM().inverse())};function Ci(e,t,n){const i=e.slice();i[39]=t[n];const o=i[24](i[39].target.selector);return i[40]=o,i}function Ri(e,t,n){const i=e.slice();return i[43]=t[n],i}function $t(e){const t=e.slice(),n=t[43].target.selector;return t[46]=n,t}function Ii(e){let t=e[43],n,i,o=Li(e);return{c(){o.c(),n=Ae()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&65536&&ae(t,t=s[43])?(_e(),z(o,1,1,j),me(),o=Li(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Ar(e){let t,n;return t=new hr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Or(e){let t,n;return t=new _r({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Mr(e){let t,n;return t=new Er({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&65536&&(s.annotation=i[43]),o[0]&65536&&(s.geom=i[46].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Sr(e){var i;let t,n;return t=new ur({props:{annotation:e[43],geom:(i=e[46])==null?void 0:i.geometry,style:e[1]}}),{c(){ye(t.$$.fragment)},m(o,s){fe(t,o,s),n=!0},p(o,s){var a;const r={};s[0]&65536&&(r.annotation=o[43]),s[0]&65536&&(r.geom=(a=o[46])==null?void 0:a.geometry),s[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(V(t.$$.fragment,o),n=!0)},o(o){z(t.$$.fragment,o),n=!1},d(o){ce(t,o)}}}function Li(e){let t,n,i,o;const s=[Sr,Mr,Or,Ar],r=[];function a(l,f){var h,c,d,_;return((h=l[46])==null?void 0:h.type)===ee.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===ee.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===ee.POLYGON?2:((_=l[46])==null?void 0:_.type)===ee.MULTIPOLYGLON?3:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Ae()},m(l,f){~t&&r[t].m(l,f),P(l,i,f),o=!0},p(l,f){let h=t;t=a(l),t===h?~t&&r[t].p(l,f):(n&&(_e(),z(r[h],1,1,()=>{r[h]=null}),me()),~t?(n=r[t],n?n.p(l,f):(n=r[t]=s[t](l),n.c()),V(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(V(n),o=!0)},o(l){z(n),o=!1},d(l){l&&D(i),~t&&r[t].d(l)}}}function ki(e){let t=lt(e[43])&&!e[9](e[43]),n,i,o=t&&Ii($t(e));return{c(){o&&o.c(),n=Ae()},m(s,r){o&&o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&66048&&(t=lt(s[43])&&!s[9](s[43])),t?o?(o.p($t(s),r),r[0]&66048&&V(o,1)):(o=Ii($t(s)),o.c(),V(o,1),o.m(n.parentNode,n)):o&&(_e(),z(o,1,1,()=>{o=null}),me())},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o&&o.d(s)}}}function Di(e){let t,n,i,o;const s=[Nr,vr],r=[];function a(l,f){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Ae()},m(l,f){~t&&r[t].m(l,f),P(l,i,f),o=!0},p(l,f){let h=t;t=a(l),t===h?~t&&r[t].p(l,f):(n&&(_e(),z(r[h],1,1,()=>{r[h]=null}),me()),~t?(n=r[t],n?n.p(l,f):(n=r[t]=s[t](l),n.c()),V(n,1),n.m(i.parentNode,i)):n=null)},i(l){o||(V(n),o=!0)},o(l){z(n),o=!1},d(l){l&&D(i),~t&&r[t].d(l)}}}function vr(e){let t=`${e[2]}-${e[5]}`,n,i,o=Pi(e);return{c(){o.c(),n=Ae()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&36&&ae(t,t=`${s[2]}-${s[5]}`)?(_e(),z(o,1,1,j),me(),o=Pi(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Nr(e){let t,n,i=Oe(e[8]),o=[];for(let r=0;r<i.length;r+=1)o[r]=Hi(Ci(e,i,r));const s=r=>z(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ae()},m(r,a){for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(r,a);P(r,t,a),n=!0},p(r,a){if(a[0]&21107010){i=Oe(r[8]);let l;for(l=0;l<i.length;l+=1){const f=Ci(r,i,l);o[l]?(o[l].p(f,a),V(o[l],1)):(o[l]=Hi(f),o[l].c(),V(o[l],1),o[l].m(t.parentNode,t))}for(_e(),l=i.length;l<o.length;l+=1)s(l);me()}},i(r){if(!n){for(let a=0;a<i.length;a+=1)V(o[a]);n=!0}},o(r){o=o.filter(Boolean);for(let a=0;a<o.length;a+=1)z(o[a]);n=!1},d(r){r&&D(t),Ye(o,r)}}}function Pi(e){let t,n;return t=new wi({props:{target:e[6],tool:e[14],drawingMode:e[13],transform:e[12],viewportScale:e[17]}}),t.$on("create",e[21]),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){const s={};o[0]&64&&(s.target=i[6]),o[0]&16384&&(s.tool=i[14]),o[0]&8192&&(s.drawingMode=i[13]),o[0]&4096&&(s.transform=i[12]),o[0]&131072&&(s.viewportScale=i[17]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Ui(e){let t=e[39].id,n,i,o=Vi(e);return{c(){o.c(),n=Ae()},m(s,r){o.m(s,r),P(s,n,r),i=!0},p(s,r){r[0]&256&&ae(t,t=s[39].id)?(_e(),z(o,1,1,j),me(),o=Vi(s),o.c(),V(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(V(o),i=!0)},o(s){z(o),i=!1},d(s){s&&D(n),o.d(s)}}}function Vi(e){let t,n;return t=new mi({props:{target:e[6],editor:e[24](e[39].target.selector),annotation:e[39],style:e[1],transform:e[12],viewportScale:e[17]}}),t.$on("change",function(){ie(e[22](e[39]))&&e[22](e[39]).apply(this,arguments)}),{c(){ye(t.$$.fragment)},m(i,o){fe(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&64&&(s.target=e[6]),o[0]&256&&(s.editor=e[24](e[39].target.selector)),o[0]&256&&(s.annotation=e[39]),o[0]&2&&(s.style=e[1]),o[0]&4096&&(s.transform=e[12]),o[0]&131072&&(s.viewportScale=e[17]),t.$set(s)},i(i){n||(V(t.$$.fragment,i),n=!0)},o(i){z(t.$$.fragment,i),n=!1},d(i){ce(t,i)}}}function Hi(e){let t,n,i=e[40]&&Ui(e);return{c(){i&&i.c(),t=Ae()},m(o,s){i&&i.m(o,s),P(o,t,s),n=!0},p(o,s){o[40]?i?(i.p(o,s),s[0]&256&&V(i,1)):(i=Ui(o),i.c(),V(i,1),i.m(t.parentNode,t)):i&&(_e(),z(i,1,1,()=>{i=null}),me())},i(o){n||(V(i),n=!0)},o(o){z(i),n=!1},d(o){o&&D(t),i&&i.d(o)}}}function Cr(e){let t,n,i,o,s,r,a=Oe(e[16].filter(e[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=ki(Ri(e,a,c));const f=c=>z(l[c],1,1,()=>{l[c]=null});let h=e[6]&&Di(e);return{c(){t=I("svg"),n=I("g");for(let c=0;c<l.length;c+=1)l[c].c();i=I("g"),h&&h.c(),u(i,"class","drawing"),u(t,"role","application"),u(t,"tabindex",0),u(t,"class","a9s-annotationlayer"),Le(t,"drawing",e[14]),Le(t,"editing",e[8]),Le(t,"hidden",!e[3]),Le(t,"hover",e[15])},m(c,d){P(c,t,d),Z(t,n);for(let _=0;_<l.length;_+=1)l[_]&&l[_].m(n,null);Z(t,i),h&&h.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[K(t,"pointerup",function(){ie(e[10])&&e[10].apply(this,arguments)}),K(t,"pointerdown",function(){ie(e[11])&&e[11].apply(this,arguments)}),K(t,"pointermove",e[23])],s=!0)},p(c,d){if(e=c,d[0]&66050){a=Oe(e[16].filter(e[34]));let _;for(_=0;_<a.length;_+=1){const g=Ri(e,a,_);l[_]?(l[_].p(g,d),V(l[_],1)):(l[_]=ki(g),l[_].c(),V(l[_],1),l[_].m(n,null))}for(_e(),_=a.length;_<l.length;_+=1)f(_);me()}e[6]?h?(h.p(e,d),d[0]&64&&V(h,1)):(h=Di(e),h.c(),V(h,1),h.m(i,null)):h&&(_e(),z(h,1,1,()=>{h=null}),me()),(!o||d[0]&16384)&&Le(t,"drawing",e[14]),(!o||d[0]&256)&&Le(t,"editing",e[8]),(!o||d[0]&8)&&Le(t,"hidden",!e[3]),(!o||d[0]&32768)&&Le(t,"hover",e[15])},i(c){if(!o){for(let d=0;d<a.length;d+=1)V(l[d]);V(h),o=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)z(l[d]);z(h),o=!1},d(c){c&&D(t),Ye(l,c),h&&h.d(),e[35](null),e[36](null),s=!1,ve(r)}}}function Rr(e,t,n){let i,o,s,r,a,l,f,h,c,d,_,g=j,p=()=>(g(),g=un(O,F=>n(17,_=F)),O);e.$$.on_destroy.push(()=>g());let{drawingEnabled:w}=t,{image:y}=t,{preferredDrawingMode:A}=t,{state:E}=t,{style:M=void 0}=t,{toolName:v=Kt()[0]}=t,{user:S}=t,{visible:N=!0}=t,H=0;const B=()=>n(5,H+=1),X=()=>v,G=()=>w;let m,b,O;je(()=>p(n(7,O=Kn(y,b))));const{hover:C,selection:R,store:L}=E;It(e,C,F=>n(15,h=F)),It(e,R,F=>n(33,c=F)),It(e,L,F=>n(16,d=F));let Y,Q;const x=F=>{Y&&L.unobserve(Y);const ge=F.filter(({editable:J})=>J).map(({id:J})=>J);ge.length>0?(n(8,Q=ge.map(J=>L.getAnnotation(J)).filter(J=>J&&lt(J))),Y=J=>{const{updated:Ce}=J.changes;n(8,Q=Ce==null?void 0:Ce.map(Se=>Se.newValue))},L.observe(Y,{annotations:ge})):n(8,Q=void 0)},Me=F=>{const ge=Xn(),J={id:ge,bodies:[],target:{annotation:ge,selector:F.detail,creator:S,created:new Date}};L.addAnnotation(J),R.setSelected(J.id)},ue=F=>ge=>{var nt;const{target:J}=F,Ce=10*60*1e3,Se=((nt=J.creator)==null?void 0:nt.id)!==S.id||!J.created||new Date().getTime()-J.created.getTime()>Ce;L.updateTarget({...J,selector:ge.detail,created:Se?J.created:new Date,updated:Se?new Date:void 0,updatedBy:Se?S:void 0})},be=F=>{const{x:ge,y:J}=xt(F,b),Ce=L.getAt(ge,J);Ce?h!==Ce.id&&C.set(Ce.id):C.set(void 0)},re=F=>yi(F),le=F=>lt(F);function et(F){st[F?"unshift":"push"](()=>{m=F,n(6,m)})}function tt(F){st[F?"unshift":"push"](()=>{b=F,n(4,b)})}return e.$$set=F=>{"drawingEnabled"in F&&n(0,w=F.drawingEnabled),"image"in F&&n(25,y=F.image),"preferredDrawingMode"in F&&n(26,A=F.preferredDrawingMode),"state"in F&&n(27,E=F.state),"style"in F&&n(1,M=F.style),"toolName"in F&&n(2,v=F.toolName),"user"in F&&n(28,S=F.user),"visible"in F&&n(3,N=F.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(14,{tool:i,opts:o}=Jt(v)||{tool:void 0,opts:void 0},i,(n(32,o),n(2,v))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(13,s=(o==null?void 0:o.drawingMode)||A),e.$$.dirty[0]&16&&n(12,r=vi(b)),e.$$.dirty[0]&16&&n(11,{onPointerDown:a,onPointerUp:l}=Ni(b,L),a,(n(10,l),n(4,b))),e.$$.dirty[1]&4&&n(9,f=F=>c.selected.find(ge=>ge.id===F.id&&ge.editable)),e.$$.dirty[1]&4&&x(c.selected)},[w,M,v,N,b,H,m,O,Q,f,l,a,r,s,i,h,d,_,C,R,L,Me,ue,be,re,y,A,E,S,B,X,G,o,c,le,et,tt]}class Bi extends Ee{constructor(t){super(),we(this,t,Rr,Cr,ae,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function Yi(e,t,n=0,i=e.length-1,o=Ir){for(;i>n;){if(i-n>600){const l=i-n+1,f=t-n+1,h=Math.log(l),c=.5*Math.exp(2*h/3),d=.5*Math.sqrt(h*c*(l-c)/l)*(f-l/2<0?-1:1),_=Math.max(n,Math.floor(t-f*c/l+d)),g=Math.min(i,Math.floor(t+(l-f)*c/l+d));Yi(e,t,_,g,o)}const s=e[t];let r=n,a=i;for(ht(e,n,t),o(e[i],s)>0&&ht(e,n,i);r<a;){for(ht(e,r,a),r++,a--;o(e[r],s)<0;)r++;for(;o(e[a],s)>0;)a--}o(e[n],s)===0?ht(e,n,a):(a++,ht(e,a,i)),a<=t&&(n=a+1),t<=a&&(i=a-1)}}function ht(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function Ir(e,t){return e<t?-1:e>t?1:0}class Lr{constructor(t=9){this._maxEntries=Math.max(4,t),this._minEntries=Math.max(2,Math.ceil(this._maxEntries*.4)),this.clear()}all(){return this._all(this.data,[])}search(t){let n=this.data;const i=[];if(!St(t,n))return i;const o=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const a=n.children[r],l=n.leaf?o(a):a;St(t,l)&&(n.leaf?i.push(a):tn(t,l)?this._all(a,i):s.push(a))}n=s.pop()}return i}collides(t){let n=this.data;if(!St(t,n))return!1;const i=[];for(;n;){for(let o=0;o<n.children.length;o++){const s=n.children[o],r=n.leaf?this.toBBox(s):s;if(St(t,r)){if(n.leaf||tn(t,r))return!0;i.push(s)}}n=i.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let i=0;i<t.length;i++)this.insert(t[i]);return this}let n=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=n;else if(this.data.height===n.height)this._splitRoot(this.data,n);else{if(this.data.height<n.height){const i=this.data;this.data=n,n=i}this._insert(n,this.data.height-n.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=$e([]),this}remove(t,n){if(!t)return this;let i=this.data;const o=this.toBBox(t),s=[],r=[];let a,l,f;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=r.pop(),f=!0),i.leaf){const h=kr(t,i.children,n);if(h!==-1)return i.children.splice(h,1),s.push(i),this._condense(s),this}!f&&!i.leaf&&tn(i,o)?(s.push(i),r.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],f=!1):i=null}return this}toBBox(t){return t}compareMinX(t,n){return t.minX-n.minX}compareMinY(t,n){return t.minY-n.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,n){const i=[];for(;t;)t.leaf?n.push(...t.children):i.push(...t.children),t=i.pop();return n}_build(t,n,i,o){const s=i-n+1;let r=this._maxEntries,a;if(s<=r)return a=$e(t.slice(n,i+1)),xe(a,this.toBBox),a;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),a=$e([]),a.leaf=!1,a.height=o;const l=Math.ceil(s/r),f=l*Math.ceil(Math.sqrt(r));Xi(t,n,i,f,this.compareMinX);for(let h=n;h<=i;h+=f){const c=Math.min(h+f-1,i);Xi(t,h,c,l,this.compareMinY);for(let d=h;d<=c;d+=l){const _=Math.min(d+l-1,c);a.children.push(this._build(t,d,_,o-1))}}return xe(a,this.toBBox),a}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let s=1/0,r=1/0,a;for(let l=0;l<n.children.length;l++){const f=n.children[l],h=en(f),c=Ur(t,f)-h;c<r?(r=c,s=h<s?h:s,a=f):c===r&&h<s&&(s=h,a=f)}n=a||n.children[0]}return n}_insert(t,n,i){const o=i?t:this.toBBox(t),s=[],r=this._chooseSubtree(o,this.data,n,s);for(r.children.push(t),gt(r,o);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(o,s,n)}_split(t,n){const i=t[n],o=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,o);const r=this._chooseSplitIndex(i,s,o),a=$e(i.children.splice(r,i.children.length-r));a.height=i.height,a.leaf=i.leaf,xe(i,this.toBBox),xe(a,this.toBBox),n?t[n-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,n){this.data=$e([t,n]),this.data.height=t.height+1,this.data.leaf=!1,xe(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,s=1/0,r=1/0;for(let a=n;a<=i-n;a++){const l=dt(t,0,a,this.toBBox),f=dt(t,a,i,this.toBBox),h=Vr(l,f),c=en(l)+en(f);h<s?(s=h,o=a,r=c<r?c:r):h===s&&c<r&&(r=c,o=a)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:Dr,s=t.leaf?this.compareMinY:Pr,r=this._allDistMargin(t,n,i,o),a=this._allDistMargin(t,n,i,s);r<a&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const s=this.toBBox,r=dt(t,0,n,s),a=dt(t,i-n,i,s);let l=Mt(r)+Mt(a);for(let f=n;f<i-n;f++){const h=t.children[f];gt(r,t.leaf?s(h):h),l+=Mt(r)}for(let f=i-n-1;f>=n;f--){const h=t.children[f];gt(a,t.leaf?s(h):h),l+=Mt(a)}return l}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)gt(n[o],t)}_condense(t){for(let n=t.length-1,i;n>=0;n--)t[n].children.length===0?n>0?(i=t[n-1].children,i.splice(i.indexOf(t[n]),1)):this.clear():xe(t[n],this.toBBox)}}function kr(e,t,n){if(!n)return t.indexOf(e);for(let i=0;i<t.length;i++)if(n(e,t[i]))return i;return-1}function xe(e,t){dt(e,0,e.children.length,t,e)}function dt(e,t,n,i,o){o||(o=$e(null)),o.minX=1/0,o.minY=1/0,o.maxX=-1/0,o.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];gt(o,e.leaf?i(r):r)}return o}function gt(e,t){return e.minX=Math.min(e.minX,t.minX),e.minY=Math.min(e.minY,t.minY),e.maxX=Math.max(e.maxX,t.maxX),e.maxY=Math.max(e.maxY,t.maxY),e}function Dr(e,t){return e.minX-t.minX}function Pr(e,t){return e.minY-t.minY}function en(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Mt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Ur(e,t){return(Math.max(t.maxX,e.maxX)-Math.min(t.minX,e.minX))*(Math.max(t.maxY,e.maxY)-Math.min(t.minY,e.minY))}function Vr(e,t){const n=Math.max(e.minX,t.minX),i=Math.max(e.minY,t.minY),o=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,o-n)*Math.max(0,s-i)}function tn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function St(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function $e(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Xi(e,t,n,i,o){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=i)continue;const r=t+Math.ceil((n-t)/i/2)*i;Yi(e,r,t,n,o),s.push(t,r,r,n)}}const Hr=()=>{const e=new Lr,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!at(c))return;const{minX:d,minY:_,maxX:g,maxY:p}=c.selector.geometry.bounds,w={minX:d,minY:_,maxX:g,maxY:p,target:c};e.insert(w),t.set(c.annotation,w)},s=c=>{if(!at(c))return;const d=t.get(c.annotation);d&&e.remove(d),t.delete(c.annotation)};return{all:n,clear:i,getAt:(c,d,_)=>{const p=e.search({minX:c,minY:d,maxX:c,maxY:d}).map(w=>w.target).filter(w=>w.selector.type===ee.RECTANGLE||mn(w.selector,c,d));return p.length>0?(p.sort((w,y)=>_t(w.selector)-_t(y.selector)),p):[]},getIntersecting:(c,d,_,g)=>e.search({minX:c,minY:d,maxX:c+_,maxY:d+g}).map(p=>p.target),insert:o,remove:s,set:(c,d=!0)=>{d&&i();const _=c.reduce((g,p)=>{if(at(p)){const{minX:w,minY:y,maxX:A,maxY:E}=p.selector.geometry.bounds;return[...g,{minX:w,minY:y,maxX:A,maxY:E,target:p}]}else return g},[]);_.forEach(g=>t.set(g.target.annotation,g)),e.load(_)},size:()=>e.all().length,update:(c,d)=>{s(c),o(d)}}},Fi=e=>{const t=ns(),n=Hr(),i=zo(t,e.userSelectAction,e.adapter),o=Fo(t),s=ls();return t.observe(({changes:l})=>{n.set((l.created||[]).map(f=>f.target),!1),(l.deleted||[]).forEach(f=>n.remove(f.target)),(l.updated||[]).forEach(({oldValue:f,newValue:h})=>n.update(f.target,h.target))}),{store:{...t,getAt:(l,f,h)=>{const c=n.getAt(l,f,h);if(h)return c.map(_=>t.getAnnotation(_.annotation)).filter(Boolean).filter(h)[0];{const d=c[0];return d?t.getAnnotation(d.annotation):void 0}},getIntersecting:(l,f,h,c)=>n.getIntersecting(l,f,h,c).map(d=>t.getAnnotation(d.annotation))},selection:i,hover:o,viewport:s}},zi=e=>{const t=Fi(e);return{...t,store:is(t.store)}},Gi=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const o=e;t=document.createElement("canvas"),t.width=o.width,t.height=o.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(o,0,0,o.width,o.height)}let i=0;for(let o=1;o<10;o++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),a=Math.round(o*t.height/10),l=n.getImageData(r,a,1,1).data,f=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=f}return i/81},ji=e=>{const t=Gi(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},nn=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?ji(e):n),Qi=(e,t)=>({...e,drawingEnabled:e.drawingEnabled===void 0?t.drawingEnabled:e.drawingEnabled,drawingMode:e.drawingMode||t.drawingMode,userSelectAction:e.userSelectAction||t.userSelectAction,theme:e.theme||t.theme}),on=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,qi=(e,t)=>{const n=t||document,i=r=>{const a=r;a.key==="z"&&a.ctrlKey?e.undo():a.key==="y"&&a.ctrlKey&&e.redo()},o=r=>{const a=r;a.key==="z"&&a.metaKey&&(a.shiftKey?e.redo():e.undo())},s=()=>{on?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return on?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:s}},Br=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=Qi(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Ft.EDIT,theme:"light"}),o=zi(i),{selection:s,store:r}=o,a=rs(r,i.initialHistory),l=as(o,a,i.adapter,i.autoSave),f=document.createElement("DIV");f.style.position="relative",f.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(f,n),f.appendChild(n);const h=qi(a);let c=ms();nn(n,f,i.theme);const d=new Bi({target:f,props:{drawingEnabled:!!i.drawingEnabled,image:n,preferredDrawingMode:i.drawingMode,state:o,style:i.style,user:c}});d.$on("click",m=>{const{originalEvent:b,annotation:O}=m.detail;O?s.userSelect(O.id,b):s.isEmpty()||s.clear()});const _=fs(o,a,i.adapter),g=()=>d.cancelDrawing(),p=()=>{d.$destroy(),f.parentNode.insertBefore(n,f),f.parentNode.removeChild(f),h.destroy(),a.destroy()},w=()=>d.getDrawingTool(),y=()=>c,A=()=>d.isDrawingEnabled(),E=(m,b,O)=>Oi(m,b,O),M=(m,b)=>_i(m,b),v=m=>{if(!Jt(m))throw`No drawing tool named ${m}`;d.$set({toolName:m})},S=m=>d.$set({drawingEnabled:m}),N=m=>{console.warn("Filter not implemented yet")},H=m=>d.$set({style:m}),B=m=>nn(n,f,m),X=m=>{c=m,d.$set({user:m})},G=m=>d.$set({visible:m});return{..._,cancelDrawing:g,destroy:p,getDrawingTool:w,getUser:y,isDrawingEnabled:A,listDrawingTools:Kt,on:l.on,off:l.off,registerDrawingTool:E,registerShapeEditor:M,setDrawingEnabled:S,setDrawingTool:v,setFilter:N,setStyle:H,setTheme:B,setUser:X,setVisible:G,element:f,state:o}};k.Editor=Ot,k.EditorMount=mi,k.Handle=Ge,k.IdentityTransform=br,k.PolygonEditor=li,k.RectangleEditor=ai,k.RectangleUtil=bn,k.RubberbandRectangle=bi,k.SVGAnnotationLayer=Bi,k.ShapeType=ee,k.ToolMount=wi,k.UserSelectAction=Ft,k.W3CImageFormat=Os,k.addEventListeners=Ni,k.boundsFromMultiPolygonElements=En,k.boundsFromPoints=Ne,k.chainStyles=hs,k.computeArea=_t,k.computePolygonArea=mt,k.computeStyle=cs,k.createBody=Zo,k.createImageAnnotator=Br,k.createImageAnnotatorState=Fi,k.createSVGTransform=vi,k.createSvelteImageAnnotatorState=zi,k.defaultColorProvider=As,k.detectTheme=ji,k.distance=At,k.enableResponsive=Kn,k.fillDefaults=Qi,k.getEditor=yi,k.getMaskDimensions=ft,k.getSVGPoint=xt,k.getTool=Jt,k.initKeyboardCommands=qi,k.intersects=mn,k.isImageAnnotation=lt,k.isImageAnnotationTarget=at,k.isMac=on,k.isPointInPolygon=wt,k.isTouch=Je,k.listDrawingTools=Kt,k.multipolygonElementToPath=ke,k.parseFragmentSelector=Tn,k.parseSVGSelector=Hn,k.parseW3CImageAnnotation=Zn,k.pointsToPath=wn,k.registerEditor=_i,k.registerShapeUtil=rt,k.registerTool=Oi,k.sampleBrightness=Gi,k.serializeFragmentSelector=An,k.serializeSVGSelector=Bn,k.serializeW3CImageAnnotation=Wn,k.setTheme=nn,Object.defineProperty(k,Symbol.toStringTag,{value:"Module"})});
3
3
  //# sourceMappingURL=annotorious.js.map