@annotorious/annotorious 3.4.5 → 3.4.6

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(D,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(D=typeof globalThis<"u"?globalThis:D||self,q(D.Annotorious={}))})(this,function(D){"use strict";var ll=Object.defineProperty;var al=(D,q,He)=>q in D?ll(D,q,{enumerable:!0,configurable:!0,writable:!0,value:He}):D[q]=He;var se=(D,q,He)=>al(D,typeof q!="symbol"?q+"":q,He);function q(){}function He(e,t){for(const n in t)e[n]=t[n];return e}function gn(e){return e()}function pn(){return Object.create(null)}function Ie(e){e.forEach(gn)}function re(e){return typeof e=="function"}function ce(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function uo(e){return Object.keys(e).length===0}function yn(e,...t){if(e==null){for(const i of t)i(void 0);return q}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function kt(e,t,n){e.$$.on_destroy.push(yn(t,n))}function fo(e,t,n,i){if(e){const o=_n(e,t,n,i);return e[0](o)}}function _n(e,t,n,i){return e[1]&&i?He(n.ctx.slice(),e[1](i(t))):n.ctx}function co(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 l=0;l<r;l+=1)s[l]=t.dirty[l]|o[l];return s}return t.dirty|o}return t.dirty}function ho(e,t,n,i,o,s){if(o){const r=_n(t,n,i,s);e.p(r,o)}}function go(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 mn(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function yt(e){return e??""}function K(e,t){e.appendChild(t)}function V(e,t,n){e.insertBefore(t,n||null)}function H(e){e.parentNode&&e.parentNode.removeChild(e)}function ze(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 wn(e){return document.createTextNode(e)}function Oe(){return wn(" ")}function Se(){return wn("")}function ee(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 po(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function yo(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 En(){if(!it)throw new Error("Function called outside component initialization");return it}function Ge(e){En().$$.on_mount.push(e)}function Ve(){const e=En();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const s=yo(t,n,{cancelable:i});return o.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function Ee(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Ke=[],_t=[];let We=[];const bn=[],Tn=Promise.resolve();let Pt=!1;function An(){Pt||(Pt=!0,Tn.then(Mn))}function On(){return An(),Tn}function Dt(e){We.push(e)}const Ut=new Set;let Je=0;function Mn(){if(Je!==0)return;const e=it;do{try{for(;Je<Ke.length;){const t=Ke[Je];Je++,ot(t),_o(t.$$)}}catch(t){throw Ke.length=0,Je=0,t}for(ot(null),Ke.length=0,Je=0;_t.length;)_t.pop()();for(let t=0;t<We.length;t+=1){const n=We[t];Ut.has(n)||(Ut.add(n),n())}We.length=0}while(Ke.length);for(;bn.length;)bn.pop()();Pt=!1,Ut.clear(),ot(e)}function _o(e){if(e.fragment!==null){e.update(),Ie(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Dt)}}function mo(e){const t=[],n=[];We.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),We=t}const mt=new Set;let Qe;function be(){Qe={r:0,c:[],p:Qe}}function Te(){Qe.r||Ie(Qe.c),Qe=Qe.p}function B(e,t){e&&e.i&&(mt.delete(e),e.i(t))}function F(e,t,n,i){if(e&&e.o){if(mt.has(e))return;mt.add(e),Qe.c.push(()=>{mt.delete(e),i&&(n&&e.d(1),i())}),e.o(t)}else i&&i()}function Ce(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function pe(e){e&&e.c()}function he(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),Dt(()=>{const s=e.$$.on_mount.map(gn).filter(re);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ie(s),e.$$.on_mount=[]}),o.forEach(Dt)}function ge(e,t){const n=e.$$;n.fragment!==null&&(mo(n.after_update),Ie(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function wo(e,t){e.$$.dirty[0]===-1&&(Ke.push(e),An(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function Me(e,t,n,i,o,s,r=null,l=[-1]){const a=it;ot(e);const u=e.$$={fragment:null,ctx:[],props:s,update:q,not_equal:o,bound:pn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:pn(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(c,h,...y)=>{const g=y.length?y[0]:h;return u.ctx&&o(u.ctx[c],u.ctx[c]=g)&&(!u.skip_bound&&u.bound[c]&&u.bound[c](g),d&&wo(e,c)),h}):[],u.update(),d=!0,Ie(u.before_update),u.fragment=i?i(u.ctx):!1,t.target){if(t.hydrate){const c=po(t.target);u.fragment&&u.fragment.l(c),c.forEach(H)}else u.fragment&&u.fragment.c();t.intro&&B(e.$$.fragment),he(e,t.target,t.anchor),Mn()}ot(a)}class ve{constructor(){se(this,"$$");se(this,"$$set")}$destroy(){ge(this,1),this.$destroy=q}$on(t,n){if(!re(n))return q;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&&!uo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Eo="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Eo);var ie=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(ie||{});function bo(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var vn={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,d=l.y-a.y;return u*u+d*d}function n(l,a,u){var d=a.x,c=a.y,h=u.x-d,y=u.y-c;if(h!==0||y!==0){var g=((l.x-d)*h+(l.y-c)*y)/(h*h+y*y);g>1?(d=u.x,c=u.y):g>0&&(d+=h*g,c+=y*g)}return h=l.x-d,y=l.y-c,h*h+y*y}function i(l,a){for(var u=l[0],d=[u],c,h=1,y=l.length;h<y;h++)c=l[h],t(c,u)>a&&(d.push(c),u=c);return u!==c&&d.push(c),d}function o(l,a,u,d,c){for(var h=d,y,g=a+1;g<u;g++){var p=n(l[g],l[a],l[u]);p>h&&(y=g,h=p)}h>d&&(y-a>1&&o(l,a,y,d,c),c.push(l[y]),u-y>1&&o(l,y,u,d,c))}function s(l,a){var u=l.length-1,d=[l[0]];return o(l,0,u,a,d),d.push(l[u]),d}function r(l,a,u){if(l.length<=2)return l;var d=a!==void 0?a*a:1;return l=u?l:i(l,d),l=s(l,d),l}e.exports=r,e.exports.default=r})()})(vn);var To=vn.exports;const Ao=bo(To),Ht={},st=(e,t)=>Ht[e]=t,wt=e=>Ht[e.type].area(e),Sn=(e,t,n)=>Ht[e.type].intersects(e,t,n),ye=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}},Et=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)},bt=(e,t,n)=>{let i=!1;for(let o=0,s=e.length-1;o<e.length;s=o++){const r=e[o][0],l=e[o][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(i=!i)}return i},Cn=(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},Vt=(e,t=1)=>{const n=e.map(([i,o])=>({x:i,y:o}));return Ao(n,t,!0).map(i=>[i.x,i.y])},Oo={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,l=0,a=Math.cos(l),u=Math.sin(l),d=t-i,c=n-o,h=a*d+u*c,y=u*d-a*c;return h*h/(s*s)+y*y/(r*r)<=1}};st(ie.ELLIPSE,Oo);const Mo={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...s]=i.rings,r=Et(o.points),l=s.reduce((a,u)=>a+Et(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:i}=e.geometry;for(const o of i){const[s,...r]=o.rings;if(bt(s.points,t,n)){let l=!1;for(const a of r)if(bt(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},rt=e=>{const t=e.reduce((n,i)=>[...n,...i.rings[0].points],[]);return ye(t)},De=e=>e.rings.map(n=>Cn(n.points)).join(" "),Nn=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((i,o)=>[...i,...o.points],[])],[]),vo=(e,t=1)=>{const n=e.geometry.polygons.map(o=>{const s=o.rings.map(l=>{const a=Vt(l.points,t);return{...l,points:a}}),r=ye(s[0].points);return{...o,rings:s,bounds:r}}),i=rt(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:i}}};st(ie.MULTIPOLYGLON,Mo);const So={area:e=>{const t=e.geometry.points;return Et(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return bt(i,t,n)}},Co=(e,t=1)=>{const n=Vt(e.geometry.points,t),i=ye(n);return{...e,geometry:{...e.geometry,bounds:i,points:n}}};st(ie.POLYGON,So);const In={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(ie.RECTANGLE,In);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},Rn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,o=[...n.matchAll(i)][0],[s,r,l,a,u,d,c]=o;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[h,y,g,p]=[a,u,d,c].map(parseFloat);return{type:ie.RECTANGLE,geometry:{x:h,y,w:g,h:p,bounds:{minX:h,minY:t?y-p:y,maxX:h+g,maxY:t?y:y+p}}}},Ln=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}`}},kn="http://www.w3.org/2000/svg",Pn=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},No=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${kn}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},Dn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(kn),o=n.lookupNamespaceURI(null);return i||o?Pn(n).firstChild:Pn(No(n)).firstChild},ue=" ";function Io(e){let t="";Array.isArray(e)||(e=[e]);for(let n=0;n<e.length;n++){const i=e[n];if(i.type===M.CLOSE_PATH)t+="z";else if(i.type===M.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===M.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===M.MOVE_TO)t+=(i.relative?"m":"M")+i.x+ue+i.y;else if(i.type===M.LINE_TO)t+=(i.relative?"l":"L")+i.x+ue+i.y;else if(i.type===M.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+ue+i.y1+ue+i.x2+ue+i.y2+ue+i.x+ue+i.y;else if(i.type===M.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+ue+i.y2+ue+i.x+ue+i.y;else if(i.type===M.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+ue+i.y1+ue+i.x+ue+i.y;else if(i.type===M.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+ue+i.y;else if(i.type===M.ARC)t+=(i.relative?"a":"A")+i.rX+ue+i.rY+ue+i.xRot+ue+ +i.lArcFlag+ue+ +i.sweepFlag+ue+i.x+ue+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Yt([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 Ye=Math.PI;function Bt(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 l=e.xRot/180*Ye,[a,u]=Yt([(t-s)/2,(n-r)/2],-l),d=Math.pow(a,2)/Math.pow(i,2)+Math.pow(u,2)/Math.pow(o,2);1<d&&(i*=Math.sqrt(d),o*=Math.sqrt(d)),e.rX=i,e.rY=o;const c=Math.pow(i,2)*Math.pow(u,2)+Math.pow(o,2)*Math.pow(a,2),h=(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*h,g=-o*a/i*h,p=Yt([y,g],l);e.cX=p[0]+(t+s)/2,e.cY=p[1]+(n+r)/2,e.phi1=Math.atan2((u-g)/o,(a-y)/i),e.phi2=Math.atan2((-u-g)/o,(-a-y)/i),e.sweepFlag===0&&e.phi2>e.phi1&&(e.phi2-=2*Ye),e.sweepFlag===1&&e.phi2<e.phi1&&(e.phi2+=2*Ye),e.phi1*=180/Ye,e.phi2*=180/Ye}function Un(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 qe=Math.PI/180;function Hn(e,t,n){return(1-n)*e+n*t}function Vn(e,t,n,i){return e+Math.cos(i/180*Ye)*t+Math.sin(i/180*Ye)*n}function Yn(e,t,n,i){const s=t-e,r=n-t,l=i-n,a=3*s+3*l-6*r,u=(r-s)*6,d=3*s;return Math.abs(a)<1e-6?Math.abs(u)<1e-6?[]:[-d/u]:Ro(u/a,d/a,1e-6)}function Bn(e,t,n,i,o){const s=1-o,r=s*s*s,l=3*s*s*o,a=3*s*o*o,u=o*o*o;return e*r+t*l+n*a+i*u}function Ro(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 Lo(e,t,n){e.cX||Bt(e,t,n);const i=e.xRot/180*Ye;if(Math.abs(e.rX)<1e-10||Math.abs(e.rY)<1e-10)return[{relative:e.relative,type:M.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,l=Math.ceil(r/90),a=new Array(l);let u=t,d=n;const c=(h,y)=>{const[g,p]=Yt([h*e.rX,y*e.rY],i);return[e.cX+g,e.cY+p]};for(let h=0;h<l;h++){const y=Hn(e.phi1,e.phi2,h/l),g=Hn(e.phi1,e.phi2,(h+1)/l),p=g-y,O=4/3*Math.tan(p*qe/4),_=Math.cos(y*qe)-O*Math.sin(y*qe),T=Math.sin(y*qe)+O*Math.cos(y*qe),A=Math.cos(g*qe),v=Math.sin(g*qe),S=A+O*v,I=v-O*A,C=c(_,T),P=c(S,I),k=c(A,v),z={relative:e.relative,type:M.CURVE_TO,x:k[0],y:k[1],x1:C[0],y1:C[1],x2:P[0],y2:P[1]};e.relative&&(z.x1-=u,z.y1-=d,z.x2-=u,z.y2-=d,z.x-=u,z.y-=d),u=k[0],d=k[1],a[h]=z}return a}function Xt(e,t,n){const i=t[0]-e[0],o=t[1]-e[1],s=n[0]-e[0],r=n[1]-e[1],l=i*r-o*s;if(!(Math.abs(l)<1e-10))return!1;const u=i*s+o*r,d=i*i+o*o,c=s*s+r*r;return 0<=u&&u<=c&&d<=c}function ko(e,t=!0){if(e.length<2)return e;const n=fe.INFO((s,r,l)=>({...s,x:s.x??r,y:s.y??l,relative:s.relative??!1})),i=[];let o=[];for(const s of e){const r=n(s);r.type===M.MOVE_TO&&o.length>0&&(t?i.push(...Tt(o)):i.unshift(...Tt(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...Tt(o)):i.unshift(...Tt(o))),i}function Tt(e){var o;const t=((o=e[e.length-1])==null?void 0:o.type)===M.CLOSE_PATH,n=t?e.length-2:e.length-1,i=[{type:M.MOVE_TO,relative:!1,x:e[n].x,y:e[n].y}];for(let s=n;s>0;s--){const r=e[s],l=e[s-1];if(r.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(r.type){case M.HORIZ_LINE_TO:i.push({type:M.HORIZ_LINE_TO,relative:!1,x:l.x});break;case M.VERT_LINE_TO:i.push({type:M.VERT_LINE_TO,relative:!1,y:l.y});break;case M.LINE_TO:case M.MOVE_TO:i.push({type:M.LINE_TO,relative:!1,x:l.x,y:l.y});break;case M.CURVE_TO:i.push({type:M.CURVE_TO,relative:!1,x:l.x,y:l.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case M.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case M.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case M.ARC:throw new Error("Unsupported command: A (arc)");case M.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:M.CLOSE_PATH}),i}function Po(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 Xn(){return Le((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 Do(){return Le((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 Uo(e=!0,t=!0,n=!0,i=!0){return Le((o,s,r,l,a)=>{if(isNaN(l)&&!(o.type&M.MOVE_TO))throw new Error("path must start with moveto");if(t&&o.type&M.HORIZ_LINE_TO&&(o.type=M.LINE_TO,o.y=o.relative?0:r),n&&o.type&M.VERT_LINE_TO&&(o.type=M.LINE_TO,o.x=o.relative?0:s),e&&o.type&M.CLOSE_PATH&&(o.type=M.LINE_TO,o.x=o.relative?l-s:l,o.y=o.relative?a-r:a),o.type&M.ARC&&(o.rX===0||o.rY===0)&&(o.type=M.LINE_TO,delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag),i&&o.type&M.QUAD_TO){const u=[s,r],d=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];Xt(u,d,c)&&(o.type=M.LINE_TO,delete o.x1,delete o.y1)}if(i&&o.type&M.CURVE_TO){const u=[s,r],d=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],h=o.relative?[s+o.x,r+o.y]:[o.x,o.y];Xt(u,d,h)&&Xt(u,c,h)&&(o.type=M.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function Fn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Le((o,s,r)=>(o.type&M.SMOOTH_CURVE_TO&&(o.type=M.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&M.CURVE_TO?(e=o.relative?s+o.x2:o.x2,t=o.relative?r+o.y2:o.y2):(e=NaN,t=NaN),o.type&M.SMOOTH_QUAD_TO&&(o.type=M.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&M.QUAD_TO?(n=o.relative?s+o.x1:o.x1,i=o.relative?r+o.y1:o.y1):(n=NaN,i=NaN),o))}function jn(){let e=NaN,t=NaN;return Le((n,i,o)=>{if(n.type&M.SMOOTH_QUAD_TO&&(n.type=M.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&M.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=M.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 Le(e){let t=0,n=0,i=NaN,o=NaN;return function(r){if(isNaN(i)&&!(r.type&M.MOVE_TO))throw new Error("path must start with moveto");const l=e(r,t,n,i,o);return r.type&M.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&M.MOVE_TO&&(i=t,o=n),l}}function Ho(e=0){Re(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Le((s,r,l,a,u)=>{const d=Math.abs;let c=!1,h=0,y=0;if(s.type&M.SMOOTH_CURVE_TO&&(h=isNaN(t)?0:r-t,y=isNaN(n)?0:l-n),s.type&(M.CURVE_TO|M.SMOOTH_CURVE_TO)?(t=s.relative?r+s.x2:s.x2,n=s.relative?l+s.y2:s.y2):(t=NaN,n=NaN),s.type&M.SMOOTH_QUAD_TO?(i=isNaN(i)?r:2*r-i,o=isNaN(o)?l:2*l-o):s.type&M.QUAD_TO?(i=s.relative?r+s.x1:s.x1,o=s.relative?l+s.y1:s.y2):(i=NaN,o=NaN),s.type&M.LINE_COMMANDS||s.type&M.ARC&&(s.rX===0||s.rY===0||!s.lArcFlag)||s.type&M.CURVE_TO||s.type&M.SMOOTH_CURVE_TO||s.type&M.QUAD_TO||s.type&M.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-l;h=isNaN(i)?typeof s.x1>"u"?h:s.relative?s.x:s.x1-r:i-r,y=isNaN(o)?typeof s.y1>"u"?y:s.relative?s.y:s.y1-l:o-l;const O=typeof s.x2>"u"?0:s.relative?s.x:s.x2-r,_=typeof s.y2>"u"?0:s.relative?s.y:s.y2-l;d(g)<=e&&d(p)<=e&&d(h)<=e&&d(y)<=e&&d(O)<=e&&d(_)<=e&&(c=!0)}return s.type&M.CLOSE_PATH&&d(r-a)<=e&&d(l-u)<=e&&(c=!0),c?[]:s})}function Be(e,t,n,i,o,s){return Re(e,t,n,i,o,s),Le((r,l,a,u)=>{const d=r.x1,c=r.x2,h=r.relative&&!isNaN(u),y=typeof r.x<"u"?r.x:h?0:l,g=typeof r.y<"u"?r.y:h?0:a;r.type&M.HORIZ_LINE_TO&&t!==0&&(r.type=M.LINE_TO,r.y=r.relative?0:a),r.type&M.VERT_LINE_TO&&n!==0&&(r.type=M.LINE_TO,r.x=r.relative?0:l),typeof r.x<"u"&&(r.x=r.x*e+g*n+(h?0:o)),typeof r.y<"u"&&(r.y=y*t+r.y*i+(h?0:s)),typeof r.x1<"u"&&(r.x1=r.x1*e+r.y1*n+(h?0:o)),typeof r.y1<"u"&&(r.y1=d*t+r.y1*i+(h?0:s)),typeof r.x2<"u"&&(r.x2=r.x2*e+r.y2*n+(h?0:o)),typeof r.y2<"u"&&(r.y2=c*t+r.y2*i+(h?0:s));function p(_){return _*_}const O=e*i-t*n;if(typeof r.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(O===0)delete r.rX,delete r.rY,delete r.xRot,delete r.lArcFlag,delete r.sweepFlag,r.type=M.LINE_TO;else{const _=r.xRot*Math.PI/180,T=Math.sin(_),A=Math.cos(_),v=1/p(r.rX),S=1/p(r.rY),I=p(A)*v+p(T)*S,C=2*T*A*(v-S),P=p(T)*v+p(A)*S,k=I*i*i-C*t*i+P*t*t,z=C*(e*i+t*n)-2*(I*n*i+P*e*t),G=I*n*n-C*e*n+P*e*e,w=(Math.atan2(z,k-G)+Math.PI)%Math.PI/2,b=Math.sin(w),m=Math.cos(w);r.rX=Math.abs(O)/Math.sqrt(k*p(m)+z*b*m+G*p(b)),r.rY=Math.abs(O)/Math.sqrt(k*p(b)-z*b*m+G*p(m)),r.xRot=w*180/Math.PI}return typeof r.sweepFlag<"u"&&0>O&&(r.sweepFlag=+!r.sweepFlag),r})}function Vo(e,t=0,n=0){Re(e,t,n);const i=Math.sin(e),o=Math.cos(e);return Be(o,i,-i,o,t-t*o+n*i,n-t*i-n*o)}function Yo(e,t=0){return Re(e,t),Be(1,0,0,1,e,t)}function Bo(e,t=e){return Re(e,t),Be(e,0,0,t,0,0)}function Xo(e){return Re(e),Be(1,0,Math.tan(e),1,0,0)}function Fo(e){return Re(e),Be(1,Math.tan(e),0,1,0,0)}function jo(e=0){return Re(e),Be(-1,0,0,1,e,0)}function zo(e=0){return Re(e),Be(1,0,0,-1,0,e)}function Go(){return Le((e,t,n)=>M.ARC===e.type?Lo(e,e.relative?0:t,e.relative?0:n):e)}function Qo(){return Le((e,t,n)=>(e.relative&&(t=0,n=0),M.ARC===e.type&&Bt(e,t,n),e))}function zn(){return e=>({...e})}function qo(){const e=zn(),t=Xn(),n=jn(),i=Fn(),o=Le((s,r,l)=>{const a=i(n(t(e(s))));function u(c){c>o.maxX&&(o.maxX=c),c<o.minX&&(o.minX=c)}function d(c){c>o.maxY&&(o.maxY=c),c<o.minY&&(o.minY=c)}if(a.type&M.DRAWING_COMMANDS&&(u(r),d(l)),a.type&M.HORIZ_LINE_TO&&u(a.x),a.type&M.VERT_LINE_TO&&d(a.y),a.type&M.LINE_TO&&(u(a.x),d(a.y)),a.type&M.CURVE_TO){u(a.x),d(a.y);const c=Yn(r,a.x1,a.x2,a.x);for(const y of c)0<y&&1>y&&u(Bn(r,a.x1,a.x2,a.x,y));const h=Yn(l,a.y1,a.y2,a.y);for(const y of h)0<y&&1>y&&d(Bn(l,a.y1,a.y2,a.y,y))}if(a.type&M.ARC){u(a.x),d(a.y),Bt(a,r,l);const c=a.xRot/180*Math.PI,h=Math.cos(c)*a.rX,y=Math.sin(c)*a.rX,g=-Math.sin(c)*a.rY,p=Math.cos(c)*a.rY,[O,_]=a.phi1<a.phi2?[a.phi1,a.phi2]:-180>a.phi2?[a.phi2+360,a.phi1+360]:[a.phi2,a.phi1],T=([S,I])=>{const P=Math.atan2(I,S)*180/Math.PI;return P<O?P+360:P},A=Un(g,-h,0).map(T);for(const S of A)S>O&&S<_&&u(Vn(a.cX,h,g,S));const v=Un(p,-y,0).map(T);for(const S of v)S>O&&S<_&&d(Vn(a.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 fe={ROUND:Po,TO_ABS:Xn,TO_REL:Do,NORMALIZE_HVZ:Uo,NORMALIZE_ST:Fn,QT_TO_C:jn,INFO:Le,SANITIZE:Ho,MATRIX:Be,ROTATE:Vo,TRANSLATE:Yo,SCALE:Bo,SKEW_X:Xo,SKEW_Y:Fo,X_AXIS_SYMMETRY:jo,Y_AXIS_SYMMETRY:zo,A_TO_C:Go,ANNOTATE_ARCS:Qo,CLONE:zn,CALCULATE_BOUNDS:qo,REVERSE_PATH:ko};class Gn{round(t){return this.transform(fe.ROUND(t))}toAbs(){return this.transform(fe.TO_ABS())}toRel(){return this.transform(fe.TO_REL())}normalizeHVZ(t,n,i){return this.transform(fe.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(fe.NORMALIZE_ST())}qtToC(){return this.transform(fe.QT_TO_C())}aToC(){return this.transform(fe.A_TO_C())}sanitize(t){return this.transform(fe.SANITIZE(t))}translate(t,n){return this.transform(fe.TRANSLATE(t,n))}scale(t,n){return this.transform(fe.SCALE(t,n))}rotate(t,n,i){return this.transform(fe.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(fe.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(fe.SKEW_X(t))}skewY(t){return this.transform(fe.SKEW_Y(t))}xSymmetry(t){return this.transform(fe.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(fe.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(fe.ANNOTATE_ARCS())}}const Zo=e=>e===" "||e===" "||e==="\r"||e===`
2
- `,Qn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class Ko extends Gn{constructor(){super();se(this,"curNumber","");se(this,"curCommandType",-1);se(this,"curCommandRelative",!1);se(this,"canParseCommandOrComma",!0);se(this,"curNumberHasExp",!1);se(this,"curNumberHasExpDigits",!1);se(this,"curNumberHasDecimal",!1);se(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],l=this.curCommandType===M.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),a=Qn(r)&&(this.curNumber==="0"&&r==="0"||l);if(Qn(r)&&!a){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&&!l){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===M.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===Wo[this.curCommandType]&&(M.HORIZ_LINE_TO===this.curCommandType?o({type:M.HORIZ_LINE_TO,relative:this.curCommandRelative,x:u}):M.VERT_LINE_TO===this.curCommandType?o({type:M.VERT_LINE_TO,relative:this.curCommandRelative,y:u}):this.curCommandType===M.MOVE_TO||this.curCommandType===M.LINE_TO||this.curCommandType===M.SMOOTH_QUAD_TO?(o({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),M.MOVE_TO===this.curCommandType&&(this.curCommandType=M.LINE_TO)):this.curCommandType===M.CURVE_TO?o({type:M.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===M.SMOOTH_CURVE_TO?o({type:M.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===M.QUAD_TO?o({type:M.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===M.ARC&&o({type:M.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(!Zo(r)){if(r===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(r==="+"||r==="-"||r==="."){this.curNumber=r,this.curNumberHasDecimal=r===".";continue}if(a){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:M.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(r==="h"||r==="H")this.curCommandType=M.HORIZ_LINE_TO,this.curCommandRelative=r==="h";else if(r==="v"||r==="V")this.curCommandType=M.VERT_LINE_TO,this.curCommandRelative=r==="v";else if(r==="m"||r==="M")this.curCommandType=M.MOVE_TO,this.curCommandRelative=r==="m";else if(r==="l"||r==="L")this.curCommandType=M.LINE_TO,this.curCommandRelative=r==="l";else if(r==="c"||r==="C")this.curCommandType=M.CURVE_TO,this.curCommandRelative=r==="c";else if(r==="s"||r==="S")this.curCommandType=M.SMOOTH_CURVE_TO,this.curCommandRelative=r==="s";else if(r==="q"||r==="Q")this.curCommandType=M.QUAD_TO,this.curCommandRelative=r==="q";else if(r==="t"||r==="T")this.curCommandType=M.SMOOTH_QUAD_TO,this.curCommandRelative=r==="t";else if(r==="a"||r==="A")this.curCommandType=M.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 l of r){const a=n(l);Array.isArray(a)?s.push(...a):s.push(a)}return s}}})}}const ne=class ne extends Gn{constructor(n){super();se(this,"commands");typeof n=="string"?this.commands=ne.parse(n):this.commands=n}encode(){return ne.encode(this.commands)}getBounds(){const n=fe.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=fe.REVERSE_PATH(this.commands,n),this}static encode(n){return Io(n)}static parse(n){const i=new Ko,o=[];return i.parse(n,o),i.finish(o),o}};se(ne,"CLOSE_PATH",1),se(ne,"MOVE_TO",2),se(ne,"HORIZ_LINE_TO",4),se(ne,"VERT_LINE_TO",8),se(ne,"LINE_TO",16),se(ne,"CURVE_TO",32),se(ne,"SMOOTH_CURVE_TO",64),se(ne,"QUAD_TO",128),se(ne,"SMOOTH_QUAD_TO",256),se(ne,"ARC",512),se(ne,"LINE_COMMANDS",ne.LINE_TO|ne.HORIZ_LINE_TO|ne.VERT_LINE_TO),se(ne,"DRAWING_COMMANDS",ne.HORIZ_LINE_TO|ne.VERT_LINE_TO|ne.LINE_TO|ne.CURVE_TO|ne.SMOOTH_CURVE_TO|ne.QUAD_TO|ne.SMOOTH_QUAD_TO|ne.ARC);let M=ne;const Wo={[M.MOVE_TO]:2,[M.LINE_TO]:2,[M.HORIZ_LINE_TO]:1,[M.VERT_LINE_TO]:1,[M.CLOSE_PATH]:0,[M.QUAD_TO]:4,[M.SMOOTH_QUAD_TO]:2,[M.CURVE_TO]:6,[M.SMOOTH_CURVE_TO]:4,[M.ARC]:7},Jo=e=>{const t=new M(e).toAbs().commands,n=[];let i=[],o=null;for(const s of t)switch(s.type){case M.MOVE_TO:i.length>0&&(n.push({points:i}),i=[]),o=[s.x,s.y],i.push(o);break;case M.LINE_TO:i.push([s.x,s.y]);break;case M.HORIZ_LINE_TO:const r=i[i.length-1][1];i.push([s.x,r]);break;case M.VERT_LINE_TO:const l=i[i.length-1][0];i.push([l,s.y]);break;case M.CURVE_TO:case M.SMOOTH_CURVE_TO:case M.QUAD_TO:case M.SMOOTH_QUAD_TO:case M.ARC:i.push([s.x,s.y]);break}if(i.length>2&&n.push({points:i}),n.length>0){const s=ye(n[0].points);return{rings:n,bounds:s}}},xo=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:ie.POLYGON,geometry:{points:o,bounds:ye(o)}}},$o=e=>{const t=Dn(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:ie.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},es=e=>{const t=Dn(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>Jo(a)).filter(Boolean),s=o.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=ye(s);return o.length===1&&o[0].rings.length===1?{type:ie.POLYGON,geometry:{points:s,bounds:r}}:{type:ie.MULTIPOLYGLON,geometry:{polygons:o,bounds:r}}},qn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return xo(t);if(t.includes("<path "))return es(t);if(t.includes("<ellipse "))return $o(t);throw"Unsupported SVG shape: "+t},ts=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${De(n)}" />`).join("")}</g>`,Zn=e=>{let t;if(e.type===ie.POLYGON){const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`}else if(e.type===ie.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===ie.MULTIPOLYGLON){const n=e.geometry;t=`<svg>${ts(n)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},_e=[];for(let e=0;e<256;++e)_e.push((e+256).toString(16).slice(1));function ns(e,t=0){return(_e[e[t+0]]+_e[e[t+1]]+_e[e[t+2]]+_e[e[t+3]]+"-"+_e[e[t+4]]+_e[e[t+5]]+"-"+_e[e[t+6]]+_e[e[t+7]]+"-"+_e[e[t+8]]+_e[e[t+9]]+"-"+_e[e[t+10]]+_e[e[t+11]]+_e[e[t+12]]+_e[e[t+13]]+_e[e[t+14]]+_e[e[t+15]]).toLowerCase()}let Ft;const is=new Uint8Array(16);function os(){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(is)}const Kn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Wn(e,t,n){var o;if(Kn.randomUUID&&!e)return Kn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??os();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,ns(i)}var Jn=Object.prototype.hasOwnProperty;function Xe(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--&&Xe(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Jn.call(e,n)&&++i&&!Jn.call(t,n)||!(n in t)||!Xe(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}function jt(){}function ss(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const xe=[];function zt(e,t=jt){let n;const i=new Set;function o(l){if(ss(e,l)&&(e=l,n)){const a=!xe.length;for(const u of i)u[1](),xe.push(u,e);if(a){for(let u=0;u<xe.length;u+=2)xe[u][0](xe[u+1]);xe.length=0}}}function s(l){o(l(e))}function r(l,a=jt){const u=[l,a];return i.add(u),i.size===1&&(n=t(o,s)||jt),l(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const rs=e=>{const{subscribe:t,set:n}=zt();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 Gt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Gt||{});const At={selected:[]},ls=(e,t,n)=>{const{subscribe:i,set:o}=zt(At);let s=t,r=At;i(g=>r=g);const l=()=>{Xe(r,At)||o(At)},a=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(a())return!1;const p=typeof g=="string"?g:g.id;return r.selected.some(O=>O.id===p)},d=(g,p)=>{let O;if(Array.isArray(g)){if(O=g.map(T=>e.getAnnotation(T)).filter(Boolean),O.length<g.length){console.warn("Invalid selection: "+g.filter(T=>!O.some(A=>A.id===T)));return}}else{const T=e.getAnnotation(g);if(!T){console.warn("Invalid selection: "+g);return}O=[T]}const _=O.reduce((T,A)=>{const v=xn(A,s,n);return v==="EDIT"?[...T,{id:A.id,editable:!0}]:v==="SELECT"?[...T,{id:A.id}]:T},[]);o({selected:_,event:p})},c=(g,p)=>{const O=Array.isArray(g)?g:[g],_=O.map(T=>e.getAnnotation(T)).filter(T=>!!T);o({selected:_.map(T=>{const A=p===void 0?xn(T,s,n)==="EDIT":p;return{id:T.id,editable:A}})}),_.length!==O.length&&console.warn("Invalid selection",g)},h=g=>{if(a())return!1;const{selected:p}=r;p.some(({id:O})=>g.includes(O))&&o({selected:p.filter(({id:O})=>!g.includes(O))})},y=g=>{s=g,c(r.selected.map(({id:p})=>p))};return e.observe(({changes:g})=>h((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:l,isEmpty:a,isSelected:u,setSelected:c,setUserSelectAction:y,subscribe:i,userSelect:d}},xn=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function as(e,t=0){return(me[e[t+0]]+me[e[t+1]]+me[e[t+2]]+me[e[t+3]]+"-"+me[e[t+4]]+me[e[t+5]]+"-"+me[e[t+6]]+me[e[t+7]]+"-"+me[e[t+8]]+me[e[t+9]]+"-"+me[e[t+10]]+me[e[t+11]]+me[e[t+12]]+me[e[t+13]]+me[e[t+14]]+me[e[t+15]]).toLowerCase()}let Qt;const us=new Uint8Array(16);function fs(){if(!Qt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qt=crypto.getRandomValues.bind(crypto)}return Qt(us)}const cs=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),$n={randomUUID:cs};function ei(e,t,n){var i;if($n.randomUUID&&!e)return $n.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??fs();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,as(o)}const qt=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)}},ds=(e,t,n,i)=>({id:ei(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),hs=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},gs=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},ps=(e,t)=>t.bodies.map(n=>{const i=e.bodies.find(o=>o.id===n.id);return{newBody:n,oldBody:i&&!Xe(i,n)?i:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:i})=>({oldBody:n,newBody:i})),ys=(e,t)=>!Xe(e.target,t.target),ti=(e,t)=>{const n=hs(e,t),i=gs(e,t),o=ps(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:ys(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var oe=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(oe||{});const _s=(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,l=a=>a&&a.length>0;if(!(l(o.created)||l(o.deleted))){const a=(n=o.updated)==null?void 0:n.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),u=(i=o.updated)==null?void 0:i.some(d=>d.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(o.created||[]).map(l=>l.id),...(o.deleted||[]).map(l=>l.id),...(o.updated||[]).map(({oldValue:l})=>l.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(l=>r.has(l))}else return!0},ms=(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)),l=new Set((t.updated||[]).filter(({oldValue:c})=>n.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),a=[...(e.created||[]).filter(c=>!s.has(c.id)).map(c=>r.has(c.id)?t.updated.find(({oldValue:h})=>h.id===c.id).newValue:c),...t.created||[]],u=[...(e.deleted||[]).filter(c=>!o.has(c.id)),...(t.deleted||[]).filter(c=>!n.has(c.id))],d=[...(e.updated||[]).filter(({newValue:c})=>!s.has(c.id)).map(c=>{const{oldValue:h,newValue:y}=c;if(r.has(y.id)){const g=t.updated.find(p=>p.oldValue.id===y.id).newValue;return ti(h,g)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!l.has(c.id))];return{created:a,deleted:u,updated:d}},Ot=e=>{const t=e.id===void 0?ei():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ws=e=>e.id!==void 0,Es=()=>{const e=new Map,t=new Map,n=[],i=(w,b={})=>{n.push({onChange:w,options:b})},o=w=>{const b=n.findIndex(m=>m.onChange==w);b>-1&&n.splice(b,1)},s=(w,b)=>{const m={origin:w,changes:{created:b.created||[],updated:b.updated||[],deleted:b.deleted||[]},state:[...e.values()]};n.forEach(E=>{_s(E,m)&&E.onChange(m)})},r=(w,b=oe.LOCAL)=>{if(w.id&&e.get(w.id))throw Error(`Cannot add annotation ${w.id} - exists already`);{const m=Ot(w);e.set(m.id,m),m.bodies.forEach(E=>t.set(E.id,m.id)),s(b,{created:[m]})}},l=(w,b)=>{const m=Ot(typeof w=="string"?b:w),E=typeof w=="string"?w:w.id,R=E&&e.get(E);if(R){const N=ti(R,m);return E===m.id?e.set(E,m):(e.delete(E),e.set(m.id,m)),R.bodies.forEach(U=>t.delete(U.id)),m.bodies.forEach(U=>t.set(U.id,m.id)),N}else console.warn(`Cannot update annotation ${E} - does not exist`)},a=(w,b=oe.LOCAL,m=oe.LOCAL)=>{const E=ws(b)?m:b,R=l(w,b);R&&s(E,{updated:[R]})},u=(w,b=oe.LOCAL)=>{e.get(w.id)?a(w,b):r(w,b)},d=(w,b=oe.LOCAL)=>{const m=w.reduce((E,R)=>{const N=l(R);return N?[...E,N]:E},[]);m.length>0&&s(b,{updated:m})},c=(w,b=oe.LOCAL)=>{const m=w.map(Ot),{toAdd:E,toUpdate:R}=m.reduce((U,Q)=>e.get(Q.id)?{...U,toUpdate:[...U.toUpdate,Q]}:{...U,toAdd:[...U.toAdd,Q]},{toAdd:[],toUpdate:[]}),N=R.map(U=>l(U,b)).filter(Boolean);E.forEach(U=>{e.set(U.id,U),U.bodies.forEach(Q=>t.set(Q.id,U.id))}),s(b,{created:E,updated:N})},h=(w,b=oe.LOCAL)=>{const m=e.get(w.annotation);if(m){const E={...m,bodies:[...m.bodies,w]};e.set(m.id,E),t.set(w.id,E.id),s(b,{updated:[{oldValue:m,newValue:E,bodiesCreated:[w]}]})}else console.warn(`Attempt to add body to missing annotation: ${w.annotation}`)},y=()=>[...e.values()],g=(w=oe.LOCAL)=>{const b=[...e.values()];e.clear(),t.clear(),s(w,{deleted:b})},p=(w,b=!0,m=oe.LOCAL)=>{const E=w.map(Ot);if(b){const R=[...e.values()];e.clear(),t.clear(),E.forEach(N=>{e.set(N.id,N),N.bodies.forEach(U=>t.set(U.id,N.id))}),s(m,{created:E,deleted:R})}else{const R=w.reduce((N,U)=>{const Q=U.id&&e.get(U.id);return Q?[...N,Q]:N},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(N=>N.id).join(", ")}`);E.forEach(N=>{e.set(N.id,N),N.bodies.forEach(U=>t.set(U.id,N.id))}),s(m,{created:E})}},O=w=>{const b=typeof w=="string"?w:w.id,m=e.get(b);if(m)return e.delete(b),m.bodies.forEach(E=>t.delete(E.id)),m;console.warn(`Attempt to delete missing annotation: ${b}`)},_=(w,b=oe.LOCAL)=>{const m=O(w);m&&s(b,{deleted:[m]})},T=(w,b=oe.LOCAL)=>{const m=w.reduce((E,R)=>{const N=O(R);return N?[...E,N]:E},[]);m.length>0&&s(b,{deleted:m})},A=w=>{const b=e.get(w.annotation);if(b){const m=b.bodies.find(E=>E.id===w.id);if(m){t.delete(m.id);const E={...b,bodies:b.bodies.filter(R=>R.id!==w.id)};return e.set(b.id,E),{oldValue:b,newValue:E,bodiesDeleted:[m]}}else console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${w.annotation}`)},v=(w,b=oe.LOCAL)=>{const m=A(w);m&&s(b,{updated:[m]})},S=(w,b=oe.LOCAL)=>{const m=w.map(E=>A(E)).filter(Boolean);m.length>0&&s(b,{updated:m})},I=w=>{const b=e.get(w);return b?{...b}:void 0},C=w=>{const b=t.get(w);if(b){const m=I(b).bodies.find(E=>E.id===w);if(m)return m;console.error(`Store integrity error: body ${w} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${w}`)},P=(w,b)=>{if(w.annotation!==b.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const m=e.get(w.annotation);if(m){const E=m.bodies.find(N=>N.id===w.id),R={...m,bodies:m.bodies.map(N=>N.id===E.id?b:N)};return e.set(m.id,R),E.id!==b.id&&(t.delete(E.id),t.set(b.id,R.id)),{oldValue:m,newValue:R,bodiesUpdated:[{oldBody:E,newBody:b}]}}else console.warn(`Attempt to add body to missing annotation ${w.annotation}`)},k=(w,b,m=oe.LOCAL)=>{const E=P(w,b);E&&s(m,{updated:[E]})},z=(w,b=oe.LOCAL)=>{const m=w.map(E=>P({id:E.id,annotation:E.annotation},E)).filter(Boolean);s(b,{updated:m})},G=w=>{const b=e.get(w.annotation);if(b){const m={...b,target:{...b.target,...w}};return e.set(b.id,m),{oldValue:b,newValue:m,targetUpdated:{oldTarget:b.target,newTarget:w}}}else console.warn(`Attempt to update target on missing annotation: ${w.annotation}`)};return{addAnnotation:r,addBody:h,all:y,bulkAddAnnotations:p,bulkDeleteAnnotations:T,bulkDeleteBodies:S,bulkUpdateAnnotations:d,bulkUpdateBodies:z,bulkUpdateTargets:(w,b=oe.LOCAL)=>{const m=w.map(E=>G(E)).filter(Boolean);m.length>0&&s(b,{updated:m})},bulkUpsertAnnotations:c,clear:g,deleteAnnotation:_,deleteBody:v,getAnnotation:I,getBody:C,observe:i,unobserve:o,updateAnnotation:a,updateBody:k,updateTarget:(w,b=oe.LOCAL)=>{const m=G(w);m&&s(b,{updated:[m]})},upsertAnnotation:u}},bs=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let Ts=()=>({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 As=250,Os=(e,t)=>{const n=Ts(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const l=g=>{if(!s){const{changes:p}=g,O=performance.now();if(O-r>As)i.splice(o+1),i.push(p),o=i.length-1;else{const _=i.length-1;i[_]=ms(i[_],p)}r=O}s=!1};e.observe(l,{origin:oe.LOCAL});const a=g=>g&&g.length>0&&e.bulkDeleteAnnotations(g),u=g=>g&&g.length>0&&e.bulkAddAnnotations(g,!1),d=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)),h=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(l),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:O}=i[o+1];u(g),c(p),y(O),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:g,updated:p,deleted:O}=i[o];a(g),d(p),h(O),n.emit("undo",i[o]),o-=1}}}},Ms=()=>{const{subscribe:e,set:t}=zt([]);return{subscribe:e,set:t}},vs=(e,t,n,i)=>{const{hover:o,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],d,c;const h=(_,T)=>{a.has(_)?a.get(_).push(T):a.set(_,[T])},y=(_,T)=>{const A=a.get(_);if(A){const v=A.indexOf(T);v!==-1&&A.splice(v,1)}},g=(_,T,A)=>{a.has(_)&&setTimeout(()=>{a.get(_).forEach(v=>{if(n){const S=Array.isArray(T)?T.map(C=>n.serialize(C)):n.serialize(T),I=A?A instanceof PointerEvent?A:n.serialize(A):void 0;v(S,I)}else v(T,A)})},1)},p=()=>{const{selected:_}=s,T=(_||[]).map(({id:A})=>r.getAnnotation(A));T.forEach(A=>{const v=u.find(S=>S.id===A.id);(!v||!Xe(v,A))&&g("updateAnnotation",A,v)}),u=u.map(A=>T.find(({id:S})=>S===A.id)||A)};s.subscribe(({selected:_})=>{if(!(u.length===0&&_.length===0)){if(u.length===0&&_.length>0)u=_.map(({id:T})=>r.getAnnotation(T));else if(u.length>0&&_.length===0)u.forEach(T=>{const A=r.getAnnotation(T.id);A&&!Xe(A,T)&&g("updateAnnotation",A,T)}),u=[];else{const T=new Set(u.map(v=>v.id)),A=new Set(_.map(({id:v})=>v));u.filter(v=>!A.has(v.id)).forEach(v=>{const S=r.getAnnotation(v.id);S&&!Xe(S,v)&&g("updateAnnotation",S,v)}),u=[...u.filter(v=>A.has(v.id)),..._.filter(({id:v})=>!T.has(v)).map(({id:v})=>r.getAnnotation(v))]}g("selectionChanged",u)}}),o.subscribe(_=>{!d&&_?g("mouseEnterAnnotation",r.getAnnotation(_)):d&&!_?g("mouseLeaveAnnotation",r.getAnnotation(d)):d&&_&&(g("mouseLeaveAnnotation",r.getAnnotation(d)),g("mouseEnterAnnotation",r.getAnnotation(_))),d=_}),l==null||l.subscribe(_=>g("viewportIntersect",_.map(T=>r.getAnnotation(T)))),r.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(p,1e3));const{created:T,deleted:A}=_.changes;(T||[]).forEach(v=>g("createAnnotation",v)),(A||[]).forEach(v=>g("deleteAnnotation",v)),(_.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:S})=>{const I=u.find(C=>C.id===v.id)||v;u=u.map(C=>C.id===v.id?S:C),g("updateAnnotation",S,I)})},{origin:oe.LOCAL}),r.observe(_=>{if(u){const T=new Set(u.map(v=>v.id)),A=(_.changes.updated||[]).filter(({newValue:v})=>T.has(v.id)).map(({newValue:v})=>v);A.length>0&&(u=u.map(v=>A.find(I=>I.id===v.id)||v))}},{origin:oe.REMOTE});const O=_=>T=>{const{updated:A}=T;_?(A||[]).forEach(v=>g("updateAnnotation",v.oldValue,v.newValue)):(A||[]).forEach(v=>g("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",O(!0)),t.on("redo",O(!1)),{on:h,off:y,emit:g}},Ss=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:[]}),Cs=(e,t,n)=>{const{store:i,selection:o}=e,s=_=>{if(n){const{parsed:T,error:A}=n.parse(_);T?i.addAnnotation(T,oe.REMOTE):console.error(A)}else i.addAnnotation(qt(_),oe.REMOTE)},r=()=>o.clear(),l=()=>i.clear(),a=_=>{const T=i.getAnnotation(_);return n&&T?n.serialize(T):T},u=()=>n?i.all().map(n.serialize):i.all(),d=()=>{var _;const T=(((_=o.selected)==null?void 0:_.map(A=>A.id))||[]).map(A=>i.getAnnotation(A)).filter(Boolean);return n?T.map(n.serialize):T},c=(_,T=!0)=>fetch(_).then(A=>A.json()).then(A=>(y(A,T),A)),h=_=>{if(typeof _=="string"){const T=i.getAnnotation(_);if(i.deleteAnnotation(_),T)return n?n.serialize(T):T}else{const T=n?n.parse(_).parsed:_;if(T)return i.deleteAnnotation(T),_}},y=(_,T=!0)=>{if(n){const A=n.parseAll||Ss(n),{parsed:v,failed:S}=A(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(v,T,oe.REMOTE)}else i.bulkAddAnnotations(_.map(qt),T,oe.REMOTE)},g=(_,T)=>{_?o.setSelected(_,T):o.clear()},p=_=>{o.clear(),o.setUserSelectAction(_)},O=_=>{if(n){const T=n.parse(_).parsed,A=n.serialize(i.getAnnotation(T.id));return i.updateAnnotation(T),A}else{const T=i.getAnnotation(_.id);return i.updateAnnotation(qt(_)),T}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:c,redo:t.redo,removeAnnotation:h,setAnnotations:y,setSelected:g,setUserSelectAction:p,undo:t.undo,updateAnnotation:O}},Ns=(e,t,n)=>typeof t=="function"?t(e,n):t,Is=(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||{}}},Rs="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ls=e=>crypto.getRandomValues(new Uint8Array(e)),ks=(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 l=n(o),a=o|0;for(;a--;)if(r+=e[l[a]&i]||"",r.length>=s)return r}}},Ps=(e,t=21)=>ks(e,t|0,Ls),Ds=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Rs[n[e]&63];return t};const Us=()=>({isGuest:!0,id:Ps("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Hs=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}`},ni=e=>e?typeof e=="object"?{...e}:e:void 0,Vs=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:s,value:r,created:l,modified:a,creator:u,...d}=n;return{id:i||`temp-${Hs(n)}`,annotation:t,type:o,purpose:s,value:r,creator:ni(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),Ys=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:s,...r}=t,l={...r,created:o==null?void 0:o.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),Bs=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Xs=()=>{const e=[...Bs];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};Ds();const Fs=(e,t={strict:!0,invertY:!1})=>({parse:o=>ii(o,t),serialize:o=>oi(o,e,t)}),ii=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Wn(),{creator:i,created:o,modified:s,body:r,...l}=e,a=Vs(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,d=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,c=typeof d=="string"||(d==null?void 0:d.type)==="FragmentSelector"?Rn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?qn(d):void 0,h=Array.isArray(l.target)?l.target[0]:l.targret;return c||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:o?new Date(o):void 0,creator:ni(i),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:c||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},oi=(e,t,n={strict:!0,invertY:!1})=>{const{selector:i,creator:o,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=i.type==ie.RECTANGLE?Ln(i.geometry):Zn(i)}catch(c){if(n.strict)throw c;u=i}const d={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:Ys(e.bodies),created:s==null?void 0:s.toISOString(),creator:o,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,"annotation"in d.target&&delete d.target.annotation,d},Mt=(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))},$e=[];function js(e,t=q){let n;const i=new Set;function o(l){if(ce(e,l)&&(e=l,n)){const a=!$e.length;for(const u of i)u[1](),$e.push(u,e);if(a){for(let u=0;u<$e.length;u+=2)$e[u][0]($e[u+1]);$e.length=0}}}function s(l){o(l(e))}function r(l,a=q){const u=[l,a];return i.add(u),i.size===1&&(n=t(o,s)||q),l(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const zs=(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 l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${i}`)},si=(e,t)=>{zs(e,t);const{subscribe:n,set:i}=js(1);let o;return window.ResizeObserver&&(o=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);i(u)}),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:l}=n;let a="";return i&&(a+=`fill:${i};`,a+=`fill-opacity:${o||"0.25"};`),s&&(a+=`stroke:${s};`,a+=`stroke-width:${r||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}},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}},Ue=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Gs=e=>({}),ri=e=>({grab:e[0]});function Qs(e){let t,n,i,o;const s=e[8].default,r=fo(s,e,e[7],ri);return{c(){t=L("g"),r&&r.c(),f(t,"class","a9s-annotation selected")},m(l,a){V(l,t,a),r&&r.m(t,null),n=!0,i||(o=[ee(t,"pointerup",e[2]),ee(t,"pointermove",e[1])],i=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&ho(r,s,l,l[7],n?co(s,l[7],a,Gs):go(l[7]),ri)},i(l){n||(B(r,l),n=!0)},o(l){F(r,l),n=!1},d(l){l&&H(t),r&&r.d(l),i=!1,Ie(o)}}}function qs(e,t,n){let{$$slots:i={},$$scope:o}=t;const s=Ve();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,c,h;const y=O=>_=>{if(d=O,u){const{left:A,top:v}=u.getBoundingClientRect(),S=_.clientX-A,I=_.clientY-v;c=a.elementToImage(S,I)}else{const{offsetX:A,offsetY:v}=_;c=a.elementToImage(A,v)}h=r,_.target.setPointerCapture(_.pointerId),s("grab",_)},g=O=>{if(d){const[_,T]=a.elementToImage(O.offsetX,O.offsetY),A=[_-c[0],T-c[1]];n(3,r=l(h,d,A)),s("change",r)}},p=O=>{O.target.releasePointerCapture(O.pointerId),d=void 0,h=r,s("release",O)};return e.$$set=O=>{"shape"in O&&n(3,r=O.shape),"editor"in O&&n(4,l=O.editor),"transform"in O&&n(5,a=O.transform),"svgEl"in O&&n(6,u=O.svgEl),"$$scope"in O&&n(7,o=O.$$scope)},[y,g,p,r,l,a,u,o,i]}class vt extends ve{constructor(t){super(),Me(this,t,qs,Qs,ce,{shape:3,editor:4,transform:5,svgEl:6})}}function Zs(e){let t,n,i,o,s,r,l,a,u=e[3]&&li(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),o=L("circle"),f(n,"class","a9s-handle-buffer svelte-160z737"),f(n,"cx",e[0]),f(n,"cy",e[1]),f(n,"r",i=e[5]+6/e[2]),f(o,"class",s=yt(`a9s-handle-dot${e[3]?" selected":""}`)+" svelte-160z737"),f(o,"cx",e[0]),f(o,"cy",e[1]),f(o,"r",e[5]),f(t,"class",r=yt(`a9s-handle ${e[8].class||""}`.trim())+" svelte-160z737")},m(d,c){V(d,t,c),K(t,n),u&&u.m(t,null),K(t,o),l||(a=[ee(n,"pointerenter",e[11]),ee(n,"pointerleave",e[12]),ee(n,"pointerdown",e[13]),ee(n,"pointerdown",e[6]),ee(n,"pointerup",e[14]),ee(n,"pointerup",e[7])],l=!0)},p(d,c){c&1&&f(n,"cx",d[0]),c&2&&f(n,"cy",d[1]),c&36&&i!==(i=d[5]+6/d[2])&&f(n,"r",i),d[3]?u?u.p(d,c):(u=li(d),u.c(),u.m(t,o)):u&&(u.d(1),u=null),c&8&&s!==(s=yt(`a9s-handle-dot${d[3]?" selected":""}`)+" svelte-160z737")&&f(o,"class",s),c&1&&f(o,"cx",d[0]),c&2&&f(o,"cy",d[1]),c&32&&f(o,"r",d[5]),c&256&&r!==(r=yt(`a9s-handle ${d[8].class||""}`.trim())+" svelte-160z737")&&f(t,"class",r)},d(d){d&&H(t),u&&u.d(),l=!1,Ie(a)}}}function Ks(e){let t,n,i,o,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),o=L("circle"),r=L("circle"),f(n,"cx",e[0]),f(n,"cy",e[1]),f(n,"r",i=e[5]*10),f(n,"class","a9s-touch-halo svelte-160z737"),Pe(n,"touched",e[4]),f(o,"cx",e[0]),f(o,"cy",e[1]),f(o,"r",s=e[5]+10/e[2]),f(o,"class","a9s-handle-buffer svelte-160z737"),f(r,"class","a9s-handle-dot svelte-160z737"),f(r,"cx",e[0]),f(r,"cy",e[1]),f(r,"r",l=e[5]+2/e[2]),f(t,"class","a9s-touch-handle")},m(d,c){V(d,t,c),K(t,n),K(t,o),K(t,r),a||(u=[ee(o,"pointerdown",e[9]),ee(o,"pointerup",e[10]),ee(o,"pointerdown",e[6]),ee(o,"pointerup",e[7])],a=!0)},p(d,c){c&1&&f(n,"cx",d[0]),c&2&&f(n,"cy",d[1]),c&32&&i!==(i=d[5]*10)&&f(n,"r",i),c&16&&Pe(n,"touched",d[4]),c&1&&f(o,"cx",d[0]),c&2&&f(o,"cy",d[1]),c&36&&s!==(s=d[5]+10/d[2])&&f(o,"r",s),c&1&&f(r,"cx",d[0]),c&2&&f(r,"cy",d[1]),c&36&&l!==(l=d[5]+2/d[2])&&f(r,"r",l)},d(d){d&&H(t),a=!1,Ie(u)}}}function li(e){let t,n;return{c(){t=L("circle"),f(t,"class","a9s-handle-selected svelte-160z737"),f(t,"cx",e[0]),f(t,"cy",e[1]),f(t,"r",n=e[5]+8/e[2])},m(i,o){V(i,t,o)},p(i,o){o&1&&f(t,"cx",i[0]),o&2&&f(t,"cy",i[1]),o&36&&n!==(n=i[5]+8/i[2])&&f(t,"r",n)},d(i){i&&H(t)}}}function Ws(e){let t;function n(s,r){return Ue?Ks:Zs}let o=n()(e);return{c(){o.c(),t=Se()},m(s,r){o.m(s,r),V(s,t,r)},p(s,[r]){o.p(s,r)},i:q,o:q,d(s){s&&H(t),o.d(s)}}}function Js(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=_=>{_.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function c(_){Ee.call(this,e,_)}function h(_){Ee.call(this,e,_)}function y(_){Ee.call(this,e,_)}function g(_){Ee.call(this,e,_)}function p(_){Ee.call(this,e,_)}function O(_){Ee.call(this,e,_)}return e.$$set=_=>{n(8,t=He(He({},t),mn(_))),"x"in _&&n(0,o=_.x),"y"in _&&n(1,s=_.y),"scale"in _&&n(2,r=_.scale),"selected"in _&&n(3,l=_.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,i=4/r)},t=mn(t),[o,s,r,l,a,i,u,d,t,c,h,y,g,p,O]}class Ze extends ve{constructor(t){super(),Me(this,t,Js,Ws,ce,{x:0,y:1,scale:2,selected:3})}}function xs(e){let t,n,i,o,s,r,l;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(a,u){V(a,t,u),K(t,n),K(t,o),K(t,s),r||(l=[ee(n,"pointerdown",e[5]),ee(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&f(n,"cx",a[0]),u&2&&f(n,"cy",a[1]),u&4&&i!==(i=1.75*a[2])&&f(n,"r",i),u&1&&f(o,"cx",a[0]),u&2&&f(o,"cy",a[1]),u&4&&f(o,"r",a[2]),u&1&&f(s,"cx",a[0]),u&2&&f(s,"cy",a[1]),u&4&&f(s,"r",a[2])},d(a){a&&H(t),r=!1,Ie(l)}}}function $s(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){V(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&&H(t)}}}function er(e){let t;function n(s,r){return Ue?$s:xs}let o=n()(e);return{c(){o.c(),t=Se()},m(s,r){o.m(s,r),V(s,t,r)},p(s,[r]){o.p(s,r)},i:q,o:q,d(s){s&&H(t),o.d(s)}}}function tr(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){Ee.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,l,r,a]}class ai extends ve{constructor(t){super(),Me(this,t,tr,er,ce,{x:0,y:1,scale:4})}}function Zt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function ui(e,t,n){const i=e.slice();return i[28]=t[n],i[30]=n,i}function Kt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Wt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function fi(e){let t,n,i,o;return{c(){t=L("circle"),f(t,"cx",n=e[28][0]),f(t,"cy",i=e[28][1]),f(t,"r",o=ct/e[3]),f(t,"class","svelte-1h2slbm")},m(s,r){V(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&f(t,"cx",n),r[0]&1088&&i!==(i=s[28][1])&&f(t,"cy",i),r[0]&8&&o!==(o=ct/s[3])&&f(t,"r",o)},d(s){s&&H(t)}}}function ci(e){let t,n,i,o,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),f(n,"x",i=e[9].x),f(n,"y",o=e[9].y),f(n,"width",s=e[9].w),f(n,"height",r=e[9].h),f(n,"class","svelte-1h2slbm"),f(l,"cx",a=e[28][0]),f(l,"cy",u=e[28][1]),f(l,"r",d=ct/e[3]),f(l,"class","svelte-1h2slbm"),f(t,"id",`${e[19]}-inner`),f(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,h){V(c,t,h),K(t,n),K(t,l)},p(c,h){h[0]&512&&i!==(i=c[9].x)&&f(n,"x",i),h[0]&512&&o!==(o=c[9].y)&&f(n,"y",o),h[0]&512&&s!==(s=c[9].w)&&f(n,"width",s),h[0]&512&&r!==(r=c[9].h)&&f(n,"height",r),h[0]&1088&&a!==(a=c[28][0])&&f(l,"cx",a),h[0]&1088&&u!==(u=c[28][1])&&f(l,"cy",u),h[0]&8&&d!==(d=ct/c[3])&&f(l,"r",d)},d(c){c&&H(t)}}}function di(e){let t,n;return t=new Ze({props:{class:"a9s-corner-handle",x:e[28][0],y:e[28][1],scale:e[3],selected:e[8].includes(e[30])}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[15]),t.$on("pointerdown",function(){re(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){pe(t.$$.fragment)},m(i,o){he(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&32&&(s.x=e[28][0]),o[0]&32&&(s.y=e[28][1]),o[0]&8&&(s.scale=e[3]),o[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function hi(e){let t,n;return t=new ai({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){re(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){he(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&1088&&(s.x=e[28][0]),o[0]&1088&&(s.y=e[28][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function nr(e){let t,n,i,o,s,r,l,a,u,d,c,h,y,g,p,O,_,T,A,v,S,I=e[6]!==void 0&&!e[7]&&fi(Wt(e)),C=e[6]!==void 0&&!e[7]&&ci(Kt(e)),P=Ce(e[5].points),k=[];for(let w=0;w<P.length;w+=1)k[w]=di(ui(e,P,w));const z=w=>F(k[w],1,1,()=>{k[w]=null});let G=e[6]!==void 0&&!e[7]&&hi(Zt(e));return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),I&&I.c(),C&&C.c(),d=Oe(),c=L("polygon"),y=Oe(),g=L("polygon"),O=Oe();for(let w=0;w<k.length;w+=1)k[w].c();_=Oe(),G&&G.c(),T=Se(),f(i,"x",o=e[9].x),f(i,"y",s=e[9].y),f(i,"width",r=e[9].w),f(i,"height",l=e[9].h),f(i,"class","svelte-1h2slbm"),f(a,"points",u=e[5].points.map(gi).join(" ")),f(a,"class","svelte-1h2slbm"),f(n,"id",`${e[19]}-outer`),f(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),f(c,"class","a9s-outer"),f(c,"mask",`url(#${e[19]}-outer)`),f(c,"points",h=e[5].points.map(pi).join(" ")),f(g,"class","a9s-inner a9s-shape-handle"),f(g,"mask",`url(#${e[19]}-inner)`),f(g,"style",e[1]),f(g,"points",p=e[5].points.map(yi).join(" "))},m(w,b){V(w,t,b),K(t,n),K(n,i),K(n,a),I&&I.m(n,null),C&&C.m(t,null),V(w,d,b),V(w,c,b),V(w,y,b),V(w,g,b),V(w,O,b);for(let m=0;m<k.length;m+=1)k[m]&&k[m].m(w,b);V(w,_,b),G&&G.m(w,b),V(w,T,b),A=!0,v||(S=[ee(c,"pointerup",e[14]),ee(c,"pointerdown",function(){re(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),ee(g,"pointermove",e[13]),ee(g,"pointerup",e[14]),ee(g,"pointerdown",function(){re(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],v=!0)},p(w,b){if(e=w,(!A||b[0]&512&&o!==(o=e[9].x))&&f(i,"x",o),(!A||b[0]&512&&s!==(s=e[9].y))&&f(i,"y",s),(!A||b[0]&512&&r!==(r=e[9].w))&&f(i,"width",r),(!A||b[0]&512&&l!==(l=e[9].h))&&f(i,"height",l),(!A||b[0]&32&&u!==(u=e[5].points.map(gi).join(" ")))&&f(a,"points",u),e[6]!==void 0&&!e[7]?I?I.p(Wt(e),b):(I=fi(Wt(e)),I.c(),I.m(n,null)):I&&(I.d(1),I=null),e[6]!==void 0&&!e[7]?C?C.p(Kt(e),b):(C=ci(Kt(e)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!A||b[0]&32&&h!==(h=e[5].points.map(pi).join(" ")))&&f(c,"points",h),(!A||b[0]&2)&&f(g,"style",e[1]),(!A||b[0]&32&&p!==(p=e[5].points.map(yi).join(" ")))&&f(g,"points",p),b[0]&134322472){P=Ce(e[5].points);let m;for(m=0;m<P.length;m+=1){const E=ui(e,P,m);k[m]?(k[m].p(E,b),B(k[m],1)):(k[m]=di(E),k[m].c(),B(k[m],1),k[m].m(_.parentNode,_))}for(be(),m=P.length;m<k.length;m+=1)z(m);Te()}e[6]!==void 0&&!e[7]?G?(G.p(Zt(e),b),b[0]&192&&B(G,1)):(G=hi(Zt(e)),G.c(),B(G,1),G.m(T.parentNode,T)):G&&(be(),F(G,1,1,()=>{G=null}),Te())},i(w){if(!A){for(let b=0;b<P.length;b+=1)B(k[b]);B(G),A=!0}},o(w){k=k.filter(Boolean);for(let b=0;b<k.length;b+=1)F(k[b]);F(G),A=!1},d(w){w&&(H(t),H(d),H(c),H(y),H(g),H(O),H(_),H(T)),I&&I.d(),C&&C.d(),ze(k,w),G&&G.d(w),v=!1,Ie(S)}}}function ir(e){let t,n;return t=new vt({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[nr,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){pe(t.$$.fragment)},m(i,o){he(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]&134219754|o[1]&1&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}const or=250,sr=1e3,rr=12,ct=4.5,gi=e=>e.join(","),pi=e=>e.join(","),yi=e=>e.join(",");function lr(e,t,n){let i,o,s;const r=Ve();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:c}=t,h,y=!1,g,p=[];const O=()=>n(7,y=!0),_=()=>n(7,y=!1),T=m=>{if(p.length>0||!o.some(W=>W.visible)){n(6,h=void 0);return}const[E,R]=u.elementToImage(m.offsetX,m.offsetY),N=W=>Math.pow(W[0]-E,2)+Math.pow(W[1]-R,2),U=i.points.reduce((W,J)=>N(J)<N(W)?J:W),Q=o.filter(W=>W.visible).reduce((W,J)=>N(J.point)<N(W.point)?J:W),j=Math.pow(sr/d,2);N(U)<j||N(Q.point)<j?n(6,h=o.indexOf(Q)):n(6,h=void 0)},A=()=>{document.activeElement!==c&&c.focus()},v=()=>{n(8,p=[]),A()},S=m=>{n(7,y=!0),m.preventDefault(),m.stopPropagation(),g=performance.now()},I=m=>E=>{if(!g||Ue||performance.now()-g>or)return;const R=p.includes(m);E.metaKey||E.ctrlKey||E.shiftKey?R?n(8,p=p.filter(N=>N!==m)):n(8,p=[...p,m]):R&&p.length>1?n(8,p=[m]):R?n(8,p=[]):n(8,p=[m]),A()},C=(m,E,R)=>{A();let N;const U=m.geometry;p.length>1?N=U.points.map(([j,x],W)=>p.includes(W)?[j+R[0],x+R[1]]:[j,x]):E==="SHAPE"?N=U.points.map(([j,x])=>[j+R[0],x+R[1]]):N=U.points.map(([j,x],W)=>E===`HANDLE-${W}`?[j+R[0],x+R[1]]:[j,x]);const Q=ye(N);return{...m,geometry:{points:N,bounds:Q}}},P=m=>async E=>{E.stopPropagation();const R=[...i.points.slice(0,m+1),o[m].point,...i.points.slice(m+1)],N=ye(R);r("change",{...l,geometry:{points:R,bounds:N}}),await On();const U=[...document.querySelectorAll(".a9s-handle")][m+1];if(U!=null&&U.firstChild){const Q=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:E.clientX,clientY:E.clientY,pointerId:E.pointerId,pointerType:E.pointerType,isPrimary:E.isPrimary,buttons:E.buttons});U.firstChild.dispatchEvent(Q)}},k=()=>{if(i.points.length<4)return;const m=i.points.filter((R,N)=>!p.includes(N)),E=ye(m);r("change",{...l,geometry:{points:m,bounds:E}}),n(8,p=[])};Ge(()=>{if(Ue)return;const m=E=>{(E.key==="Delete"||E.key==="Backspace")&&(E.preventDefault(),k())};return c.addEventListener("pointermove",T),c.addEventListener("keydown",m),()=>{c.removeEventListener("pointermove",T),c.removeEventListener("keydown",m)}});const z=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function G(m){Ee.call(this,e,m)}function w(m){Ee.call(this,e,m)}function b(m){Ee.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,l=m.shape),"computedStyle"in m&&n(1,a=m.computedStyle),"transform"in m&&n(2,u=m.transform),"viewportScale"in m&&n(3,d=m.viewportScale),"svgEl"in m&&n(4,c=m.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=l.geometry),e.$$.dirty[0]&40&&n(10,o=Ue?[]:i.points.map((m,E)=>{const R=E===i.points.length-1?i.points[0]:i.points[E+1],N=(m[0]+R[0])/2,U=(m[1]+R[1])/2,j=Math.sqrt(Math.pow(R[0]-N,2)+Math.pow(R[1]-U,2))>rr/d;return{point:[N,U],visible:j}})),e.$$.dirty[0]&40&&n(9,s=ft(i.bounds,ct/d))},[l,a,u,d,c,i,h,y,p,s,o,O,_,T,v,S,I,C,P,z,G,w,b]}class _i extends ve{constructor(t){super(),Me(this,t,lr,ir,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function ar(e){let t,n,i,o,s,r,l,a,u,d,c,h,y,g,p,O,_,T,A,v,S,I,C,P,k,z,G,w,b,m,E,R,N,U,Q,j,x,W,J,ae,le,Ne,ke,X,de,te,we,Ae,nt,Fe,dn,je,$,hn,ao;return te=new Ze({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){re(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),Ae=new Ze({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),Ae.$on("pointerdown",function(){re(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),Fe=new Ze({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),Fe.$on("pointerdown",function(){re(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),je=new Ze({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),je.$on("pointerdown",function(){re(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("rect"),y=Oe(),g=L("rect"),A=Oe(),v=L("rect"),k=Oe(),z=L("rect"),m=Oe(),E=L("rect"),Q=Oe(),j=L("rect"),ae=Oe(),le=L("rect"),de=Oe(),pe(te.$$.fragment),we=Oe(),pe(Ae.$$.fragment),nt=Oe(),pe(Fe.$$.fragment),dn=Oe(),pe(je.$$.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",l=e[6].h),f(a,"class","rect-mask-fg svelte-1njczvj"),f(a,"x",u=e[5].x),f(a,"y",d=e[5].y),f(a,"width",c=e[5].w),f(a,"height",h=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",O=e[5].y),f(g,"width",_=e[5].w),f(g,"height",T=e[5].h),f(v,"class","a9s-inner a9s-shape-handle"),f(v,"style",e[1]),f(v,"x",S=e[5].x),f(v,"y",I=e[5].y),f(v,"width",C=e[5].w),f(v,"height",P=e[5].h),f(z,"class","a9s-edge-handle a9s-edge-handle-top"),f(z,"x",G=e[5].x),f(z,"y",w=e[5].y),f(z,"height",1),f(z,"width",b=e[5].w),f(E,"class","a9s-edge-handle a9s-edge-handle-right"),f(E,"x",R=e[5].x+e[5].w),f(E,"y",N=e[5].y),f(E,"height",U=e[5].h),f(E,"width",1),f(j,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(j,"x",x=e[5].x),f(j,"y",W=e[5].y+e[5].h),f(j,"height",1),f(j,"width",J=e[5].w),f(le,"class","a9s-edge-handle a9s-edge-handle-left"),f(le,"x",Ne=e[5].x),f(le,"y",ke=e[5].y),f(le,"height",X=e[5].h),f(le,"width",1)},m(Z,Y){V(Z,t,Y),K(t,n),K(n,i),K(n,a),V(Z,y,Y),V(Z,g,Y),V(Z,A,Y),V(Z,v,Y),V(Z,k,Y),V(Z,z,Y),V(Z,m,Y),V(Z,E,Y),V(Z,Q,Y),V(Z,j,Y),V(Z,ae,Y),V(Z,le,Y),V(Z,de,Y),he(te,Z,Y),V(Z,we,Y),he(Ae,Z,Y),V(Z,nt,Y),he(Fe,Z,Y),V(Z,dn,Y),he(je,Z,Y),$=!0,hn||(ao=[ee(g,"pointerdown",function(){re(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(v,"pointerdown",function(){re(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(z,"pointerdown",function(){re(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),ee(E,"pointerdown",function(){re(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),ee(j,"pointerdown",function(){re(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),ee(le,"pointerdown",function(){re(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],hn=!0)},p(Z,Y){e=Z,(!$||Y&64&&o!==(o=e[6].x))&&f(i,"x",o),(!$||Y&64&&s!==(s=e[6].y))&&f(i,"y",s),(!$||Y&64&&r!==(r=e[6].w))&&f(i,"width",r),(!$||Y&64&&l!==(l=e[6].h))&&f(i,"height",l),(!$||Y&32&&u!==(u=e[5].x))&&f(a,"x",u),(!$||Y&32&&d!==(d=e[5].y))&&f(a,"y",d),(!$||Y&32&&c!==(c=e[5].w))&&f(a,"width",c),(!$||Y&32&&h!==(h=e[5].h))&&f(a,"height",h),(!$||Y&32&&p!==(p=e[5].x))&&f(g,"x",p),(!$||Y&32&&O!==(O=e[5].y))&&f(g,"y",O),(!$||Y&32&&_!==(_=e[5].w))&&f(g,"width",_),(!$||Y&32&&T!==(T=e[5].h))&&f(g,"height",T),(!$||Y&2)&&f(v,"style",e[1]),(!$||Y&32&&S!==(S=e[5].x))&&f(v,"x",S),(!$||Y&32&&I!==(I=e[5].y))&&f(v,"y",I),(!$||Y&32&&C!==(C=e[5].w))&&f(v,"width",C),(!$||Y&32&&P!==(P=e[5].h))&&f(v,"height",P),(!$||Y&32&&G!==(G=e[5].x))&&f(z,"x",G),(!$||Y&32&&w!==(w=e[5].y))&&f(z,"y",w),(!$||Y&32&&b!==(b=e[5].w))&&f(z,"width",b),(!$||Y&32&&R!==(R=e[5].x+e[5].w))&&f(E,"x",R),(!$||Y&32&&N!==(N=e[5].y))&&f(E,"y",N),(!$||Y&32&&U!==(U=e[5].h))&&f(E,"height",U),(!$||Y&32&&x!==(x=e[5].x))&&f(j,"x",x),(!$||Y&32&&W!==(W=e[5].y+e[5].h))&&f(j,"y",W),(!$||Y&32&&J!==(J=e[5].w))&&f(j,"width",J),(!$||Y&32&&Ne!==(Ne=e[5].x))&&f(le,"x",Ne),(!$||Y&32&&ke!==(ke=e[5].y))&&f(le,"y",ke),(!$||Y&32&&X!==(X=e[5].h))&&f(le,"height",X);const Nt={};Y&32&&(Nt.x=e[5].x),Y&32&&(Nt.y=e[5].y),Y&8&&(Nt.scale=e[3]),te.$set(Nt);const It={};Y&32&&(It.x=e[5].x+e[5].w),Y&32&&(It.y=e[5].y),Y&8&&(It.scale=e[3]),Ae.$set(It);const Rt={};Y&32&&(Rt.x=e[5].x+e[5].w),Y&32&&(Rt.y=e[5].y+e[5].h),Y&8&&(Rt.scale=e[3]),Fe.$set(Rt);const Lt={};Y&32&&(Lt.x=e[5].x),Y&32&&(Lt.y=e[5].y+e[5].h),Y&8&&(Lt.scale=e[3]),je.$set(Lt)},i(Z){$||(B(te.$$.fragment,Z),B(Ae.$$.fragment,Z),B(Fe.$$.fragment,Z),B(je.$$.fragment,Z),$=!0)},o(Z){F(te.$$.fragment,Z),F(Ae.$$.fragment,Z),F(Fe.$$.fragment,Z),F(je.$$.fragment,Z),$=!1},d(Z){Z&&(H(t),H(y),H(g),H(A),H(v),H(k),H(z),H(m),H(E),H(Q),H(j),H(ae),H(le),H(de),H(we),H(nt),H(dn)),ge(te,Z),ge(Ae,Z),ge(Fe,Z),ge(je,Z),hn=!1,Ie(ao)}}}function ur(e){let t,n;return t=new vt({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[ar,({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){he(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function fr(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(p,O,_)=>{const T=p.geometry.bounds;let[A,v]=[T.minX,T.minY],[S,I]=[T.maxX,T.maxY];const[C,P]=_;if(O==="SHAPE")A+=C,S+=C,v+=P,I+=P;else{switch(O){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{v+=P;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{I+=P;break}}switch(O){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{A+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const k=Math.min(A,S),z=Math.min(v,I),G=Math.abs(S-A),w=Math.abs(I-v);return{...p,geometry:{x:k,y:z,w:G,h:w,bounds:{minX:k,minY:z,maxX:k+G,maxY:z+w}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(p){Ee.call(this,e,p)}function y(p){Ee.call(this,e,p)}function g(p){Ee.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,l=p.transform),"viewportScale"in p&&n(3,a=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=ft(i.bounds,2/a))},[s,r,l,a,u,i,o,d,c,h,y,g]}class mi extends ve{constructor(t){super(),Me(this,t,fr,ur,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var wi=Object.prototype.hasOwnProperty;function Jt(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--&&Jt(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(wi.call(e,n)&&++i&&!wi.call(t,n)||!(n in t)||!Jt(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}const cr=12,dr=(e,t)=>e.polygons.reduce((n,i,o)=>{const s=i.rings.reduce((r,l,a)=>{const u=l.points.map((d,c)=>{const h=c===l.points.length-1?l.points[0]:l.points[c+1],y=(d[0]+h[0])/2,g=(d[1]+h[1])/2,O=Math.sqrt(Math.pow(h[0]-y,2)+Math.pow(h[1]-g,2))>cr/t;return{point:[y,g],visible:O,elementIdx:o,ringIdx:a,pointIdx:c}});return[...r,...u]},[]);return[...n,...s]},[]);function xt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function Ei(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function bi(e,t,n){const i=e.slice();return i[33]=t[n],i[35]=n,i}function Ti(e,t,n){const i=e.slice();return i[29]=t[n],i[37]=n,i}function $t(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function en(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function Ai(e){let t,n,i,o;return{c(){t=L("circle"),f(t,"cx",n=e[29][0]),f(t,"cy",i=e[29][1]),f(t,"r",o=dt/e[3]),f(t,"class","svelte-1vxo6dc")},m(s,r){V(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&f(t,"cx",n),r[0]&1088&&i!==(i=s[29][1])&&f(t,"cy",i),r[0]&8&&o!==(o=dt/s[3])&&f(t,"r",o)},d(s){s&&H(t)}}}function Oi(e){let t,n,i,o,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),f(n,"x",i=e[9].x),f(n,"y",o=e[9].y),f(n,"width",s=e[9].w),f(n,"height",r=e[9].h),f(n,"class","svelte-1vxo6dc"),f(l,"cx",a=e[29][0]),f(l,"cy",u=e[29][1]),f(l,"r",d=dt/e[3]),f(l,"class","svelte-1vxo6dc"),f(t,"id",`${e[18]}-${e[32]}-inner`),f(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(c,h){V(c,t,h),K(t,n),K(t,l)},p(c,h){h[0]&512&&i!==(i=c[9].x)&&f(n,"x",i),h[0]&512&&o!==(o=c[9].y)&&f(n,"y",o),h[0]&512&&s!==(s=c[9].w)&&f(n,"width",s),h[0]&512&&r!==(r=c[9].h)&&f(n,"height",r),h[0]&1088&&a!==(a=c[29][0])&&f(l,"cx",a),h[0]&1088&&u!==(u=c[29][1])&&f(l,"cy",u),h[0]&8&&d!==(d=dt/c[3])&&f(l,"r",d)},d(c){c&&H(t)}}}function Mi(e){let t,n;function i(...o){return e[19](e[32],e[35],e[37],...o)}return t=new Ze({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(i)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){re(e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`))&&e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`).apply(this,arguments)}),t.$on("pointerup",e[15](e[32],e[35],e[37])),{c(){pe(t.$$.fragment)},m(o,s){he(t,o,s),n=!0},p(o,s){e=o;const r={};s[0]&32&&(r.x=e[29][0]),s[0]&32&&(r.y=e[29][1]),s[0]&8&&(r.scale=e[3]),s[0]&256&&(r.selected=e[8].some(i)),t.$set(r)},i(o){n||(B(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){ge(t,o)}}}function vi(e){let t,n,i=Ce(e[33].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=Mi(Ti(e,i,r));const s=r=>F(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Se()},m(r,l){for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(r,l);V(r,t,l),n=!0},p(r,l){if(l[0]&268491048){i=Ce(r[33].points);let a;for(a=0;a<i.length;a+=1){const u=Ti(r,i,a);o[a]?(o[a].p(u,l),B(o[a],1)):(o[a]=Mi(u),o[a].c(),B(o[a],1),o[a].m(t.parentNode,t))}for(be(),a=i.length;a<o.length;a+=1)s(a);Te()}},i(r){if(!n){for(let l=0;l<i.length;l+=1)B(o[l]);n=!0}},o(r){o=o.filter(Boolean);for(let l=0;l<o.length;l+=1)F(o[l]);n=!1},d(r){r&&H(t),ze(o,r)}}}function Si(e){let t,n,i,o,s,r,l,a,u,d,c,h,y,g,p,O,_,T=e[6]!==void 0&&!e[7]&&Ai(en(e)),A=e[6]!==void 0&&!e[7]&&Oi($t(e)),v=Ce(e[30].rings),S=[];for(let C=0;C<v.length;C+=1)S[C]=vi(bi(e,v,C));const I=C=>F(S[C],1,1,()=>{S[C]=null});return{c(){t=L("g"),n=L("defs"),i=L("mask"),o=L("rect"),u=L("path"),T&&T.c(),A&&A.c(),c=L("path"),y=L("path");for(let C=0;C<S.length;C+=1)S[C].c();f(o,"x",s=e[9].x),f(o,"y",r=e[9].y),f(o,"width",l=e[9].w),f(o,"height",a=e[9].h),f(o,"class","svelte-1vxo6dc"),f(u,"d",d=De(e[30])),f(u,"class","svelte-1vxo6dc"),f(i,"id",`${e[18]}-${e[32]}-outer`),f(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),f(c,"class","a9s-outer"),f(c,"mask",`url(#${e[18]}-${e[32]}-outer)`),f(c,"fill-rule","evenodd"),f(c,"d",h=De(e[30])),f(y,"class","a9s-inner"),f(y,"mask",`url(#${e[18]}-${e[32]}-inner)`),f(y,"style",e[1]),f(y,"fill-rule","evenodd"),f(y,"d",g=De(e[30]))},m(C,P){V(C,t,P),K(t,n),K(n,i),K(i,o),K(i,u),T&&T.m(i,null),A&&A.m(n,null),K(t,c),K(t,y);for(let k=0;k<S.length;k+=1)S[k]&&S[k].m(t,null);p=!0,O||(_=[ee(c,"pointerup",e[13]),ee(c,"pointerdown",function(){re(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),ee(y,"pointerup",e[13]),ee(y,"pointerdown",function(){re(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],O=!0)},p(C,P){if(e=C,(!p||P[0]&512&&s!==(s=e[9].x))&&f(o,"x",s),(!p||P[0]&512&&r!==(r=e[9].y))&&f(o,"y",r),(!p||P[0]&512&&l!==(l=e[9].w))&&f(o,"width",l),(!p||P[0]&512&&a!==(a=e[9].h))&&f(o,"height",a),(!p||P[0]&32&&d!==(d=De(e[30])))&&f(u,"d",d),e[6]!==void 0&&!e[7]?T?T.p(en(e),P):(T=Ai(en(e)),T.c(),T.m(i,null)):T&&(T.d(1),T=null),e[6]!==void 0&&!e[7]?A?A.p($t(e),P):(A=Oi($t(e)),A.c(),A.m(n,null)):A&&(A.d(1),A=null),(!p||P[0]&32&&h!==(h=De(e[30])))&&f(c,"d",h),(!p||P[0]&2)&&f(y,"style",e[1]),(!p||P[0]&32&&g!==(g=De(e[30])))&&f(y,"d",g),P[0]&268491048){v=Ce(e[30].rings);let k;for(k=0;k<v.length;k+=1){const z=bi(e,v,k);S[k]?(S[k].p(z,P),B(S[k],1)):(S[k]=vi(z),S[k].c(),B(S[k],1),S[k].m(t,null))}for(be(),k=v.length;k<S.length;k+=1)I(k);Te()}},i(C){if(!p){for(let P=0;P<v.length;P+=1)B(S[P]);p=!0}},o(C){S=S.filter(Boolean);for(let P=0;P<S.length;P+=1)F(S[P]);p=!1},d(C){C&&H(t),T&&T.d(),A&&A.d(),ze(S,C),O=!1,Ie(_)}}}function Ci(e){let t,n;return t=new ai({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){re(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){he(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&1088&&(s.x=e[29][0]),o[0]&1088&&(s.y=e[29][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function hr(e){let t,n,i,o=Ce(e[5].polygons),s=[];for(let a=0;a<o.length;a+=1)s[a]=Si(Ei(e,o,a));const r=a=>F(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&Ci(xt(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=Oe(),l&&l.c(),n=Se()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);V(a,t,u),l&&l.m(a,u),V(a,n,u),i=!0},p(a,u){if(u[0]&268763114){o=Ce(a[5].polygons);let d;for(d=0;d<o.length;d+=1){const c=Ei(a,o,d);s[d]?(s[d].p(c,u),B(s[d],1)):(s[d]=Si(c),s[d].c(),B(s[d],1),s[d].m(t.parentNode,t))}for(be(),d=o.length;d<s.length;d+=1)r(d);Te()}a[6]!==void 0&&!a[7]?l?(l.p(xt(a),u),u[0]&192&&B(l,1)):(l=Ci(xt(a)),l.c(),B(l,1),l.m(n.parentNode,n)):l&&(be(),F(l,1,1,()=>{l=null}),Te())},i(a){if(!i){for(let u=0;u<o.length;u+=1)B(s[u]);B(l),i=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)F(s[u]);F(l),i=!1},d(a){a&&(H(t),H(n)),ze(s,a),l&&l.d(a)}}}function gr(e){let t,n;return t=new vt({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[hr,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){pe(t.$$.fragment)},m(i,o){he(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]&268437482|o[1]&128&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}const pr=250,yr=1e3,dt=4.5;function _r(e,t,n){let i,o,s;const r=Ve();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:c}=t,h,y=!1,g,p=[];const O=()=>n(7,y=!0),_=()=>n(7,y=!1),T=E=>{if(p.length>0||!o.some(J=>J.visible)){n(6,h=void 0);return}const[R,N]=u.elementToImage(E.offsetX,E.offsetY),U=J=>Math.pow(J[0]-R,2)+Math.pow(J[1]-N,2),Q=Nn(i).reduce((J,ae)=>U(ae)<U(J)?ae:J),j=o.filter(J=>J.visible).reduce((J,ae)=>U(ae.point)<U(J.point)?ae:J),x=Math.pow(yr/d,2);U(Q)<x||U(j.point)<x?n(6,h=o.indexOf(j)):n(6,h=void 0)},A=()=>{document.activeElement!==c&&c.focus()},v=()=>{n(8,p=[]),A()},S=E=>{n(7,y=!0),E.preventDefault(),E.stopPropagation(),g=performance.now()},I=(E,R,N)=>U=>{if(!g||Ue||performance.now()-g>pr)return;const Q=x=>x.polygon===E&&x.ring===R&&x.point===N,j=p.some(Q);U.metaKey||U.ctrlKey||U.shiftKey?j?n(8,p=p.filter(x=>!Q(x))):n(8,p=[...p,{polygon:E,ring:R,point:N}]):j&&p.length>1?n(8,p=[{polygon:E,ring:R,point:N}]):j?n(8,p=[]):n(8,p=[{polygon:E,ring:R,point:N}]),A()},C=(E,R,N)=>{A();const U=E.geometry.polygons;let Q;if(R==="SHAPE")Q=U.map(j=>{const x=j.rings.map((J,ae)=>({points:J.points.map((Ne,ke)=>[Ne[0]+N[0],Ne[1]+N[1]])})),W=ye(x[0].points);return{rings:x,bounds:W}});else{const[j,x,W,J]=R.split("-").map(ae=>parseInt(ae));Q=U.map((ae,le)=>{if(le===x){const Ne=ae.rings.map((X,de)=>de===W?{points:X.points.map((we,Ae)=>Ae===J?[we[0]+N[0],we[1]+N[1]]:we)}:X),ke=ye(Ne[0].points);return{rings:Ne,bounds:ke}}else return ae})}return{...E,geometry:{polygons:Q,bounds:rt(Q)}}},P=E=>async R=>{R.stopPropagation();const N=o[E],U=i.polygons.map((j,x)=>{if(x===N.elementIdx){const W=j.rings.map((ae,le)=>le===N.ringIdx?{points:[...ae.points.slice(0,N.pointIdx+1),N.point,...ae.points.slice(N.pointIdx+1)]}:ae),J=ye(W[0].points);return{rings:W,bounds:J}}else return j});r("change",{...l,geometry:{polygons:U,bounds:rt(U)}}),await On();const Q=[...document.querySelectorAll(".a9s-handle")][E+1];if(Q!=null&&Q.firstChild){const j=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:R.clientX,clientY:R.clientY,pointerId:R.pointerId,pointerType:R.pointerType,isPrimary:R.isPrimary,buttons:R.buttons});Q.firstChild.dispatchEvent(j)}},k=()=>{const E=i.polygons.map((N,U)=>{if(p.some(j=>j.polygon===U)){const j=N.rings.map((W,J)=>p.some(le=>le.polygon===U&&le.ring===J)&&W.points.length>3?{points:W.points.filter((Ne,ke)=>!p.some(X=>X.polygon===U&&X.ring===J&&X.point===ke))}:W),x=ye(j[0].points);return{rings:j,bounds:x}}else return N});!Jt(i.polygons,E)&&(r("change",{...l,geometry:{polygons:E,bounds:rt(E)}}),n(8,p=[]))};Ge(()=>{if(Ue)return;const E=R=>{(R.key==="Delete"||R.key==="Backspace")&&(R.preventDefault(),k())};return c.addEventListener("pointermove",T),c.addEventListener("keydown",E),()=>{c.removeEventListener("pointermove",T),c.removeEventListener("keydown",E)}});const z=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,G=(E,R,N,{polygon:U,ring:Q,point:j})=>U===E&&Q===R&&j===N;function w(E){Ee.call(this,e,E)}function b(E){Ee.call(this,e,E)}function m(E){Ee.call(this,e,E)}return e.$$set=E=>{"shape"in E&&n(0,l=E.shape),"computedStyle"in E&&n(1,a=E.computedStyle),"transform"in E&&n(2,u=E.transform),"viewportScale"in E&&n(3,d=E.viewportScale),"svgEl"in E&&n(4,c=E.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=l.geometry),e.$$.dirty[0]&40&&n(10,o=Ue?[]:dr(i,d)),e.$$.dirty[0]&40&&n(9,s=ft(i.bounds,dt/d))},[l,a,u,d,c,i,h,y,p,s,o,O,_,v,S,I,C,P,z,G,w,b,m]}class mr extends ve{constructor(t){super(),Me(this,t,_r,gr,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Ni=new Map([[ie.RECTANGLE,mi],[ie.POLYGON,_i],[ie.MULTIPOLYGLON,mr]]),Ii=e=>Ni.get(e.type),Ri=(e,t)=>Ni.set(e,t);function wr(e,t,n){let i;const o=Ve();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,c;return Ge(()=>(n(6,c=new r({target:a,props:{shape:s.target.selector,computedStyle:i,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),c.$on("change",h=>{c.$$set({shape:h.detail}),o("change",h.detail)}),c.$on("grab",h=>o("grab",h.detail)),c.$on("release",h=>o("release",h.detail)),()=>{c.$destroy()})),e.$$set=h=>{"annotation"in h&&n(0,s=h.annotation),"editor"in h&&n(1,r=h.editor),"style"in h&&n(2,l=h.style),"target"in h&&n(3,a=h.target),"transform"in h&&n(4,u=h.transform),"viewportScale"in h&&n(5,d=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,i=ut(s,l)),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:d}),e.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[s,r,l,a,u,d,c,i]}class Li extends ve{constructor(t){super(),Me(this,t,wr,null,ce,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Er(e,t,n){const i=Ve();let{drawingMode:o}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Ge(()=>{const d=s.closest("svg"),c=[],h=(y,g,p)=>{d==null||d.addEventListener(y,g,p),c.push(()=>d==null?void 0:d.removeEventListener(y,g,p))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:o,transform:l,viewportScale:a}})),u.$on("create",y=>i("create",y.detail)),()=>{c.forEach(y=>y()),u.$destroy()}}),e.$$set=d=>{"drawingMode"in d&&n(0,o=d.drawingMode),"target"in d&&n(1,s=d.target),"tool"in d&&n(2,r=d.tool),"transform"in d&&n(3,l=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[o,s,r,l,a,u]}class ki extends ve{constructor(t){super(),Me(this,t,Er,null,ce,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Pi(e){let t,n,i,o,s,r,l,a,u,d;return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("rect"),u=L("rect"),d=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",l=e[4]+2*e[5]),f(a,"class","rect-mask-fg svelte-1a76qe7"),f(a,"x",e[1]),f(a,"y",e[2]),f(a,"width",e[3]),f(a,"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(d,"class","a9s-inner"),f(d,"x",e[1]),f(d,"y",e[2]),f(d,"width",e[3]),f(d,"height",e[4])},m(c,h){V(c,t,h),K(t,n),K(n,i),K(n,a),V(c,u,h),V(c,d,h)},p(c,h){h&34&&o!==(o=c[1]-c[5])&&f(i,"x",o),h&36&&s!==(s=c[2]-c[5])&&f(i,"y",s),h&40&&r!==(r=c[3]+2*c[5])&&f(i,"width",r),h&48&&l!==(l=c[4]+2*c[5])&&f(i,"height",l),h&2&&f(a,"x",c[1]),h&4&&f(a,"y",c[2]),h&8&&f(a,"width",c[3]),h&16&&f(a,"height",c[4]),h&2&&f(u,"x",c[1]),h&4&&f(u,"y",c[2]),h&8&&f(u,"width",c[3]),h&16&&f(u,"height",c[4]),h&2&&f(d,"x",c[1]),h&4&&f(d,"y",c[2]),h&8&&f(d,"width",c[3]),h&16&&f(d,"height",c[4])},d(c){c&&(H(t),H(u),H(d))}}}function br(e){let t,n=e[0]&&Pi(e);return{c(){t=L("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(i,o){V(i,t,o),n&&n.m(t,null)},p(i,[o]){i[0]?n?n.p(i,o):(n=Pi(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&H(t),n&&n.d()}}}function Tr(e,t,n){let i;const o=Ve();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,c,h,y,g,p;const O=S=>{const I=S;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(I.offsetX,I.offsetY)),c=d,n(1,h=d[0]),n(2,y=d[1]),n(3,g=1),n(4,p=1))},_=S=>{const I=S;d&&(c=l.elementToImage(I.offsetX,I.offsetY),n(1,h=Math.min(c[0],d[0])),n(2,y=Math.min(c[1],d[1])),n(3,g=Math.abs(c[0]-d[0])),n(4,p=Math.abs(c[1]-d[1])))},T=S=>{const I=S,C=performance.now()-u;if(r==="click"){if(C>300)return;d?A():(n(0,d=l.elementToImage(I.offsetX,I.offsetY)),c=d,n(1,h=d[0]),n(2,y=d[1]),n(3,g=1),n(4,p=1))}else d&&(C>300||g*p>100?(I.stopPropagation(),A()):(n(0,d=void 0),c=void 0))},A=()=>{if(g*p>15){const S={type:ie.RECTANGLE,geometry:{bounds:{minX:h,minY:y,maxX:h+g,maxY:y+p},x:h,y,w:g,h:p}};o("create",S)}n(0,d=void 0),c=void 0};Ge(()=>{s("pointerdown",O),s("pointermove",_),s("pointerup",T,!0)});const v=`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,l=S.transform),"viewportScale"in S&&n(10,a=S.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,i=2/a)},[d,h,y,g,p,i,v,s,r,l,a]}class Di extends ve{constructor(t){super(),Me(this,t,Tr,br,ce,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function tn(e){const t=e.slice(),n=t[2].map(i=>i.join(",")).join(" ");return t[19]=n,t}function Ui(e){let t,n,i,o,s,r,l,a,u,d,c,h,y,g,p=e[1]&&Hi(e);return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),p&&p.c(),g=Se(),f(i,"x",o=e[3].x),f(i,"y",s=e[3].y),f(i,"width",r=e[3].w),f(i,"height",l=e[3].h),f(i,"class","svelte-18wrg3t"),f(a,"points",u=e[19]),f(a,"class","svelte-18wrg3t"),f(n,"id",e[5]),f(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),f(d,"class","a9s-outer"),f(d,"mask",`url(#${e[5]})`),f(d,"points",c=e[19]),f(h,"class","a9s-inner"),f(h,"points",y=e[19])},m(O,_){V(O,t,_),K(t,n),K(n,i),K(n,a),V(O,d,_),V(O,h,_),p&&p.m(O,_),V(O,g,_)},p(O,_){_&8&&o!==(o=O[3].x)&&f(i,"x",o),_&8&&s!==(s=O[3].y)&&f(i,"y",s),_&8&&r!==(r=O[3].w)&&f(i,"width",r),_&8&&l!==(l=O[3].h)&&f(i,"height",l),_&4&&u!==(u=O[19])&&f(a,"points",u),_&4&&c!==(c=O[19])&&f(d,"points",c),_&4&&y!==(y=O[19])&&f(h,"points",y),O[1]?p?p.p(O,_):(p=Hi(O),p.c(),p.m(g.parentNode,g)):p&&(p.d(1),p=null)},d(O){O&&(H(t),H(d),H(h),H(g)),p&&p.d(O)}}}function Hi(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){V(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&&H(t)}}}function Ar(e){let t,n=e[3]&&Ui(tn(e));return{c(){t=L("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(i,o){V(i,t,o),n&&n.m(t,null)},p(i,[o]){i[3]?n?n.p(tn(i),o):(n=Ui(tn(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&H(t),n&&n.d()}}}const Or=20,Mr=1500;function vr(e,t,n){let i,o,s;const r=Ve();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,c,h=[],y,g,p=!1;const O=I=>{const C=I,{timeStamp:P,offsetX:k,offsetY:z}=C;if(c={timeStamp:P,offsetX:k,offsetY:z},a==="drag"&&h.length===0){const G=u.elementToImage(C.offsetX,C.offsetY);h.push(G),n(10,y=G)}},_=I=>{const C=I;if(g&&clearTimeout(g),h.length>0){if(n(10,y=u.elementToImage(C.offsetX,C.offsetY)),h.length>2){const P=Mt(y,h[0])*d;n(1,p=P<Or)}C.pointerType==="touch"&&(g=setTimeout(()=>{A()},Mr))}},T=I=>{const C=I;if(g&&clearTimeout(g),a==="click"){const P=C.timeStamp-c.timeStamp,k=Mt([c.offsetX,c.offsetY],[C.offsetX,C.offsetY]);if(P>300||k>15)return;if(p)v();else if(h.length===0){const z=u.elementToImage(C.offsetX,C.offsetY);h.push(z),n(10,y=z)}else h.push(y)}else{if(h.length===1&&Mt(h[0],y)<=4){n(0,h=[]),n(10,y=void 0);return}C.stopImmediatePropagation(),p?v():h.push(y)}},A=()=>{if(!y)return;const I=h.slice(0,-1);if(I.length<3)return;const C={type:ie.POLYGON,geometry:{bounds:ye(h),points:I}};wt(C)>4&&(n(0,h=[]),n(10,y=void 0),r("create",C))},v=()=>{const I={type:ie.POLYGON,geometry:{bounds:ye(h),points:[...h]}};n(0,h=[]),n(10,y=void 0),r("create",I)};Ge(()=>{l("pointerdown",O,!0),l("pointermove",_),l("pointerup",T,!0),l("dblclick",A,!0)});const S=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=I=>{"addEventListener"in I&&n(6,l=I.addEventListener),"drawingMode"in I&&n(7,a=I.drawingMode),"transform"in I&&n(8,u=I.transform),"viewportScale"in I&&n(9,d=I.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,i=4/d),e.$$.dirty&1027&&n(2,o=y?p?h:[...h,y]:[]),e.$$.dirty&516&&n(3,s=o.length>0?ft(ye(o),2/d):void 0)},[h,p,o,s,i,S,l,a,u,d,y]}class Sr extends ve{constructor(t){super(),Me(this,t,vr,Ar,ce,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const nn=new Map([["rectangle",{tool:Di}],["polygon",{tool:Sr}]]),on=()=>[...nn.keys()],sn=e=>nn.get(e),Vi=(e,t,n={})=>nn.set(e,{tool:t,opts:n});function Cr(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,l){V(r,t,l),K(t,n),K(t,o)},p(r,[l]){l&2&&i!==(i=r[1]?"display:none;":void 0)&&f(n,"style",i),l&2&&f(o,"style",r[1]),l&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}function Nr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,rx:u,ry:d}=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,l,a,u,d,s,r]}class Ir extends ve{constructor(t){super(),Me(this,t,Nr,Cr,ce,{annotation:0,geom:6,style:7})}}function Yi(e,t,n){const i=e.slice();return i[5]=t[n],i}function Bi(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",De(e[5])),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"fill-rule","evenodd"),f(i,"d",De(e[5]))},m(o,s){V(o,t,s),V(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&&(H(t),H(i))}}}function Rr(e){let t,n,i=Ce(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=Bi(Yi(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){V(s,t,r);for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(t,null)},p(s,[r]){if(r&6){i=Ce(s[2]);let l;for(l=0;l<i.length;l+=1){const a=Yi(s,i,l);o[l]?o[l].p(a,r):(o[l]=Bi(a),o[l].c(),o[l].m(t,null))}for(;l<o.length;l+=1)o[l].d(1);o.length=i.length}r&1&&n!==(n=s[0].id)&&f(t,"data-id",n)},i:q,o:q,d(s){s&&H(t),ze(o,s)}}}function Lr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,o=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,l,s,r]}class kr extends ve{constructor(t){super(),Me(this,t,Lr,Rr,ce,{annotation:0,geom:3,style:4})}}function Pr(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(Dr).join(" ")),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"points",e[2].map(Ur).join(" ")),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,l){V(r,t,l),K(t,n),K(t,o)},p(r,[l]){l&2&&i!==(i=r[1]?"display:none;":void 0)&&f(n,"style",i),l&2&&f(o,"style",r[1]),l&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}const Dr=e=>e.join(","),Ur=e=>e.join(",");function Hr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,o=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,l,s,r]}class Vr extends ve{constructor(t){super(),Me(this,t,Hr,Pr,ce,{annotation:0,geom:3,style:4})}}function Yr(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,l){V(r,t,l),K(t,n),K(t,o)},p(r,[l]){l&32&&i!==(i=r[5]?"display:none;":void 0)&&f(n,"style",i),l&16&&f(n,"x",r[4]),l&8&&f(n,"y",r[3]),l&4&&f(n,"width",r[2]),l&2&&f(n,"height",r[1]),l&32&&f(o,"style",r[5]),l&16&&f(o,"x",r[4]),l&8&&f(o,"y",r[3]),l&4&&f(o,"width",r[2]),l&2&&f(o,"height",r[1]),l&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}function Br(e,t,n){let i,o,s,r,l,{annotation:a}=t,{geom:u}=t,{style:d}=t;return e.$$set=c=>{"annotation"in c&&n(0,a=c.annotation),"geom"in c&&n(6,u=c.geom),"style"in c&&n(7,d=c.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,i=ut(a,d)),e.$$.dirty&64&&n(4,{x:o,y:s,w:r,h:l}=u,o,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,o,i,u,d]}class Xr extends ve{constructor(t){super(),Me(this,t,Br,Yr,ce,{annotation:0,geom:6,style:7})}}const Fr={elementToImage:(e,t)=>[e,t]},Xi=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]}}),jr=250,Fi=(e,t)=>{const n=Ve();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<jr){const{x:a,y:u}=rn(r,e),d=t.getAt(a,u);d?n("click",{originalEvent:r,annotation:d}):n("click",{originalEvent:r})}}}},rn=(e,t)=>{const n=t.createSVGPoint(),i=t.getBoundingClientRect(),o=e.clientX-i.x,s=e.clientY-i.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=o+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function ji(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 zi(e,t,n){const i=e.slice();return i[43]=t[n],i}function ln(e){const t=e.slice(),n=t[43].target.selector;return t[46]=n,t}function Gi(e){let t=e[43],n,i,o=Qi(e);return{c(){o.c(),n=Se()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&65536&&ce(t,t=s[43])?(be(),F(o,1,1,q),Te(),o=Qi(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function zr(e){let t,n;return t=new kr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){he(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Gr(e){let t,n;return t=new Vr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){he(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Qr(e){let t,n;return t=new Xr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){he(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function qr(e){var i;let t,n;return t=new Ir({props:{annotation:e[43],geom:(i=e[46])==null?void 0:i.geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(o,s){he(t,o,s),n=!0},p(o,s){var l;const r={};s[0]&65536&&(r.annotation=o[43]),s[0]&65536&&(r.geom=(l=o[46])==null?void 0:l.geometry),s[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(B(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){ge(t,o)}}}function Qi(e){let t,n,i,o;const s=[qr,Qr,Gr,zr],r=[];function l(a,u){var d,c,h,y;return((d=a[46])==null?void 0:d.type)===ie.ELLIPSE?0:((c=a[46])==null?void 0:c.type)===ie.RECTANGLE?1:((h=a[46])==null?void 0:h.type)===ie.POLYGON?2:((y=a[46])==null?void 0:y.type)===ie.MULTIPOLYGLON?3:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Se()},m(a,u){~t&&r[t].m(a,u),V(a,i,u),o=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),F(r[d],1,1,()=>{r[d]=null}),Te()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),B(n,1),n.m(i.parentNode,i)):n=null)},i(a){o||(B(n),o=!0)},o(a){F(n),o=!1},d(a){a&&H(i),~t&&r[t].d(a)}}}function qi(e){let t=lt(e[43])&&!e[9](e[43]),n,i,o=t&&Gi(ln(e));return{c(){o&&o.c(),n=Se()},m(s,r){o&&o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&66048&&(t=lt(s[43])&&!s[9](s[43])),t?o?(o.p(ln(s),r),r[0]&66048&&B(o,1)):(o=Gi(ln(s)),o.c(),B(o,1),o.m(n.parentNode,n)):o&&(be(),F(o,1,1,()=>{o=null}),Te())},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o&&o.d(s)}}}function Zi(e){let t,n,i,o;const s=[Kr,Zr],r=[];function l(a,u){return a[8]?0:a[14]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Se()},m(a,u){~t&&r[t].m(a,u),V(a,i,u),o=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),F(r[d],1,1,()=>{r[d]=null}),Te()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),B(n,1),n.m(i.parentNode,i)):n=null)},i(a){o||(B(n),o=!0)},o(a){F(n),o=!1},d(a){a&&H(i),~t&&r[t].d(a)}}}function Zr(e){let t=`${e[2]}-${e[5]}`,n,i,o=Ki(e);return{c(){o.c(),n=Se()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&36&&ce(t,t=`${s[2]}-${s[5]}`)?(be(),F(o,1,1,q),Te(),o=Ki(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function Kr(e){let t,n,i=Ce(e[8]),o=[];for(let r=0;r<i.length;r+=1)o[r]=xi(ji(e,i,r));const s=r=>F(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Se()},m(r,l){for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(r,l);V(r,t,l),n=!0},p(r,l){if(l[0]&21107010){i=Ce(r[8]);let a;for(a=0;a<i.length;a+=1){const u=ji(r,i,a);o[a]?(o[a].p(u,l),B(o[a],1)):(o[a]=xi(u),o[a].c(),B(o[a],1),o[a].m(t.parentNode,t))}for(be(),a=i.length;a<o.length;a+=1)s(a);Te()}},i(r){if(!n){for(let l=0;l<i.length;l+=1)B(o[l]);n=!0}},o(r){o=o.filter(Boolean);for(let l=0;l<o.length;l+=1)F(o[l]);n=!1},d(r){r&&H(t),ze(o,r)}}}function Ki(e){let t,n;return t=new ki({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){he(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Wi(e){let t=e[39].id,n,i,o=Ji(e);return{c(){o.c(),n=Se()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&256&&ce(t,t=s[39].id)?(be(),F(o,1,1,q),Te(),o=Ji(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function Ji(e){let t,n;return t=new Li({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(){re(e[22](e[39]))&&e[22](e[39]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){he(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function xi(e){let t,n,i=e[40]&&Wi(e);return{c(){i&&i.c(),t=Se()},m(o,s){i&&i.m(o,s),V(o,t,s),n=!0},p(o,s){o[40]?i?(i.p(o,s),s[0]&256&&B(i,1)):(i=Wi(o),i.c(),B(i,1),i.m(t.parentNode,t)):i&&(be(),F(i,1,1,()=>{i=null}),Te())},i(o){n||(B(i),n=!0)},o(o){F(i),n=!1},d(o){o&&H(t),i&&i.d(o)}}}function Wr(e){let t,n,i,o,s,r,l=Ce(e[16].filter(e[34])),a=[];for(let c=0;c<l.length;c+=1)a[c]=qi(zi(e,l,c));const u=c=>F(a[c],1,1,()=>{a[c]=null});let d=e[6]&&Zi(e);return{c(){t=L("svg"),n=L("g");for(let c=0;c<a.length;c+=1)a[c].c();i=L("g"),d&&d.c(),f(i,"class","drawing"),f(t,"role","application"),f(t,"tabindex",0),f(t,"class","a9s-annotationlayer"),Pe(t,"drawing",e[14]),Pe(t,"editing",e[8]),Pe(t,"hidden",!e[3]),Pe(t,"hover",e[15])},m(c,h){V(c,t,h),K(t,n);for(let y=0;y<a.length;y+=1)a[y]&&a[y].m(n,null);K(t,i),d&&d.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[ee(t,"pointerup",function(){re(e[10])&&e[10].apply(this,arguments)}),ee(t,"pointerdown",function(){re(e[11])&&e[11].apply(this,arguments)}),ee(t,"pointermove",e[23])],s=!0)},p(c,h){if(e=c,h[0]&66050){l=Ce(e[16].filter(e[34]));let y;for(y=0;y<l.length;y+=1){const g=zi(e,l,y);a[y]?(a[y].p(g,h),B(a[y],1)):(a[y]=qi(g),a[y].c(),B(a[y],1),a[y].m(n,null))}for(be(),y=l.length;y<a.length;y+=1)u(y);Te()}e[6]?d?(d.p(e,h),h[0]&64&&B(d,1)):(d=Zi(e),d.c(),B(d,1),d.m(i,null)):d&&(be(),F(d,1,1,()=>{d=null}),Te()),(!o||h[0]&16384)&&Pe(t,"drawing",e[14]),(!o||h[0]&256)&&Pe(t,"editing",e[8]),(!o||h[0]&8)&&Pe(t,"hidden",!e[3]),(!o||h[0]&32768)&&Pe(t,"hover",e[15])},i(c){if(!o){for(let h=0;h<l.length;h+=1)B(a[h]);B(d),o=!0}},o(c){a=a.filter(Boolean);for(let h=0;h<a.length;h+=1)F(a[h]);F(d),o=!1},d(c){c&&H(t),ze(a,c),d&&d.d(),e[35](null),e[36](null),s=!1,Ie(r)}}}function Jr(e,t,n){let i,o,s,r,l,a,u,d,c,h,y,g=q,p=()=>(g(),g=yn(m,X=>n(17,y=X)),m);e.$$.on_destroy.push(()=>g());let{drawingEnabled:O}=t,{image:_}=t,{preferredDrawingMode:T}=t,{state:A}=t,{style:v=void 0}=t,{toolName:S=on()[0]}=t,{user:I}=t,{visible:C=!0}=t,P=0;const k=()=>n(5,P+=1),z=()=>S,G=()=>O;let w,b,m;Ge(()=>p(n(7,m=si(_,b))));const{hover:E,selection:R,store:N}=A;kt(e,E,X=>n(15,d=X)),kt(e,R,X=>n(33,c=X)),kt(e,N,X=>n(16,h=X));let U,Q;const j=X=>{U&&N.unobserve(U);const de=X.filter(({editable:te})=>te).map(({id:te})=>te);de.length>0?(n(8,Q=de.map(te=>N.getAnnotation(te)).filter(te=>te&&lt(te))),U=te=>{const{updated:we}=te.changes;n(8,Q=we==null?void 0:we.map(Ae=>Ae.newValue))},N.observe(U,{annotations:de})):n(8,Q=void 0)},x=X=>{const de=Wn(),te={id:de,bodies:[],target:{annotation:de,selector:X.detail,creator:I,created:new Date}};N.addAnnotation(te),R.setSelected(te.id)},W=X=>de=>{var nt;const{target:te}=X,we=10*60*1e3,Ae=((nt=te.creator)==null?void 0:nt.id)!==I.id||!te.created||new Date().getTime()-te.created.getTime()>we;N.updateTarget({...te,selector:de.detail,created:Ae?te.created:new Date,updated:Ae?new Date:void 0,updatedBy:Ae?I:void 0})},J=X=>{const{x:de,y:te}=rn(X,b),we=N.getAt(de,te);we?d!==we.id&&E.set(we.id):E.set(void 0)},ae=X=>Ii(X),le=X=>lt(X);function Ne(X){_t[X?"unshift":"push"](()=>{w=X,n(6,w)})}function ke(X){_t[X?"unshift":"push"](()=>{b=X,n(4,b)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,O=X.drawingEnabled),"image"in X&&n(25,_=X.image),"preferredDrawingMode"in X&&n(26,T=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,v=X.style),"toolName"in X&&n(2,S=X.toolName),"user"in X&&n(28,I=X.user),"visible"in X&&n(3,C=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(14,{tool:i,opts:o}=sn(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)||T),e.$$.dirty[0]&16&&n(12,r=Xi(b)),e.$$.dirty[0]&16&&n(11,{onPointerDown:l,onPointerUp:a}=Fi(b,N),l,(n(10,a),n(4,b))),e.$$.dirty[1]&4&&n(9,u=X=>c.selected.find(de=>de.id===X.id&&de.editable)),e.$$.dirty[1]&4&&j(c.selected)},[O,v,S,C,b,P,w,m,Q,u,a,l,r,s,i,d,h,y,E,R,N,x,W,J,ae,_,T,A,I,k,z,G,o,c,le,Ne,ke]}class $i extends ve{constructor(t){super(),Me(this,t,Jr,Wr,ce,{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 eo(e,t,n=0,i=e.length-1,o=xr){for(;i>n;){if(i-n>600){const a=i-n+1,u=t-n+1,d=Math.log(a),c=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*c*(a-c)/a)*(u-a/2<0?-1:1),y=Math.max(n,Math.floor(t-u*c/a+h)),g=Math.min(i,Math.floor(t+(a-u)*c/a+h));eo(e,t,y,g,o)}const s=e[t];let r=n,l=i;for(ht(e,n,t),o(e[i],s)>0&&ht(e,n,i);r<l;){for(ht(e,r,l),r++,l--;o(e[r],s)<0;)r++;for(;o(e[l],s)>0;)l--}o(e[n],s)===0?ht(e,n,l):(l++,ht(e,l,i)),l<=t&&(n=l+1),t<=l&&(i=l-1)}}function ht(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function xr(e,t){return e<t?-1:e>t?1:0}class $r{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(!Ct(t,n))return i;const o=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?o(l):l;Ct(t,a)&&(n.leaf?i.push(l):un(t,a)?this._all(l,i):s.push(l))}n=s.pop()}return i}collides(t){let n=this.data;if(!Ct(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(Ct(t,r)){if(n.leaf||un(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=tt([]),this}remove(t,n){if(!t)return this;let i=this.data;const o=this.toBBox(t),s=[],r=[];let l,a,u;for(;i||s.length;){if(i||(i=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),i.leaf){const d=el(t,i.children,n);if(d!==-1)return i.children.splice(d,1),s.push(i),this._condense(s),this}!u&&!i.leaf&&un(i,o)?(s.push(i),r.push(l),l=0,a=i,i=i.children[0]):a?(l++,i=a.children[l],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,l;if(s<=r)return l=tt(t.slice(n,i+1)),et(l,this.toBBox),l;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),l=tt([]),l.leaf=!1,l.height=o;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));to(t,n,i,u,this.compareMinX);for(let d=n;d<=i;d+=u){const c=Math.min(d+u-1,i);to(t,d,c,a,this.compareMinY);for(let h=d;h<=c;h+=a){const y=Math.min(h+a-1,c);l.children.push(this._build(t,h,y,o-1))}}return et(l,this.toBBox),l}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=an(u),c=il(t,u)-d;c<r?(r=c,s=d<s?d:s,l=u):c===r&&d<s&&(s=d,l=u)}n=l||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),pt(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),l=tt(i.children.splice(r,i.children.length-r));l.height=i.height,l.leaf=i.leaf,et(i,this.toBBox),et(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(i,l)}_splitRoot(t,n){this.data=tt([t,n]),this.data.height=t.height+1,this.data.leaf=!1,et(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,s=1/0,r=1/0;for(let l=n;l<=i-n;l++){const a=gt(t,0,l,this.toBBox),u=gt(t,l,i,this.toBBox),d=ol(a,u),c=an(a)+an(u);d<s?(s=d,o=l,r=c<r?c:r):d===s&&c<r&&(r=c,o=l)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:tl,s=t.leaf?this.compareMinY:nl,r=this._allDistMargin(t,n,i,o),l=this._allDistMargin(t,n,i,s);r<l&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const s=this.toBBox,r=gt(t,0,n,s),l=gt(t,i-n,i,s);let a=St(r)+St(l);for(let u=n;u<i-n;u++){const d=t.children[u];pt(r,t.leaf?s(d):d),a+=St(r)}for(let u=i-n-1;u>=n;u--){const d=t.children[u];pt(l,t.leaf?s(d):d),a+=St(l)}return a}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)pt(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():et(t[n],this.toBBox)}}function el(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 et(e,t){gt(e,0,e.children.length,t,e)}function gt(e,t,n,i,o){o||(o=tt(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];pt(o,e.leaf?i(r):r)}return o}function pt(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 tl(e,t){return e.minX-t.minX}function nl(e,t){return e.minY-t.minY}function an(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function St(e){return e.maxX-e.minX+(e.maxY-e.minY)}function il(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 ol(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 un(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Ct(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function tt(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function to(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;eo(e,r,t,n,o),s.push(t,r,r,n)}}const sl=()=>{const e=new $r,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!at(c))return;const{minX:h,minY:y,maxX:g,maxY:p}=c.selector.geometry.bounds,O={minX:h,minY:y,maxX:g,maxY:p,target:c};e.insert(O),t.set(c.annotation,O)},s=c=>{if(!at(c))return;const h=t.get(c.annotation);h&&e.remove(h),t.delete(c.annotation)};return{all:n,clear:i,getAt:(c,h,y)=>{const p=e.search({minX:c,minY:h,maxX:c,maxY:h}).map(O=>O.target).filter(O=>O.selector.type===ie.RECTANGLE||Sn(O.selector,c,h));return p.length>0?(p.sort((O,_)=>wt(O.selector)-wt(_.selector)),p):[]},getIntersecting:(c,h,y,g)=>e.search({minX:c,minY:h,maxX:c+y,maxY:h+g}).map(p=>p.target),insert:o,remove:s,set:(c,h=!0)=>{h&&i();const y=c.reduce((g,p)=>{if(at(p)){const{minX:O,minY:_,maxX:T,maxY:A}=p.selector.geometry.bounds;return[...g,{minX:O,minY:_,maxX:T,maxY:A,target:p}]}else return g},[]);y.forEach(g=>t.set(g.target.annotation,g)),e.load(y)},size:()=>e.all().length,update:(c,h)=>{s(c),o(h)}}},no=e=>{const t=Es(),n=sl(),i=ls(t,e.userSelectAction,e.adapter),o=rs(t),s=Ms();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:d})=>n.update(u.target,d.target))}),{store:{...t,getAt:(a,u,d)=>{const c=n.getAt(a,u,d);if(d)return c.map(y=>t.getAnnotation(y.annotation)).filter(Boolean).filter(d)[0];{const h=c[0];return h?t.getAnnotation(h.annotation):void 0}},getIntersecting:(a,u,d,c)=>n.getIntersecting(a,u,d,c).map(h=>t.getAnnotation(h.annotation))},selection:i,hover:o,viewport:s}},io=e=>{const t=no(e);return{...t,store:bs(t.store)}},oo=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),l=Math.round(o*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;i+=u}return i/81},so=e=>{const t=oo(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},fn=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?so(e):n),ro=(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}),cn=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,lo=(e,t)=>{const n=t||document,i=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},o=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{cn?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return cn?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:s}},rl=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=ro(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Gt.EDIT,theme:"light"}),o=io(i),{selection:s,store:r}=o,l=Os(r,i.initialHistory),a=vs(o,l,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 d=lo(l);let c=Us();fn(n,u,i.theme);const h=new $i({target:u,props:{drawingEnabled:!!i.drawingEnabled,image:n,preferredDrawingMode:i.drawingMode,state:o,style:i.style,user:c}});h.$on("click",w=>{const{originalEvent:b,annotation:m}=w.detail;m?s.userSelect(m.id,b):s.isEmpty()||s.clear()});const y=Cs(o,l,i.adapter),g=()=>h.cancelDrawing(),p=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},O=()=>h.getDrawingTool(),_=()=>c,T=()=>h.isDrawingEnabled(),A=(w,b,m)=>Vi(w,b,m),v=(w,b)=>Ri(w,b),S=w=>{if(!sn(w))throw`No drawing tool named ${w}`;h.$set({toolName:w})},I=w=>h.$set({drawingEnabled:w}),C=w=>{console.warn("Filter not implemented yet")},P=w=>h.$set({style:w}),k=w=>fn(n,u,w),z=w=>{c=w,h.$set({user:w})},G=w=>h.$set({visible:w});return{...y,cancelDrawing:g,destroy:p,getDrawingTool:O,getUser:_,isDrawingEnabled:T,listDrawingTools:on,on:a.on,off:a.off,registerDrawingTool:A,registerShapeEditor:v,setDrawingEnabled:I,setDrawingTool:S,setFilter:C,setStyle:P,setTheme:k,setUser:z,setVisible:G,element:u,state:o}};D.Editor=vt,D.EditorMount=Li,D.Handle=Ze,D.IdentityTransform=Fr,D.PolygonEditor=_i,D.RectangleEditor=mi,D.RectangleUtil=In,D.RubberbandRectangle=Di,D.SVGAnnotationLayer=$i,D.ShapeType=ie,D.ToolMount=ki,D.UserSelectAction=Gt,D.W3CImageFormat=Fs,D.addEventListeners=Fi,D.boundsFromMultiPolygonElements=rt,D.boundsFromPoints=ye,D.chainStyles=Is,D.computeArea=wt,D.computePolygonArea=Et,D.computeStyle=Ns,D.createBody=ds,D.createImageAnnotator=rl,D.createImageAnnotatorState=no,D.createSVGTransform=Xi,D.createSvelteImageAnnotatorState=io,D.defaultColorProvider=Xs,D.detectTheme=so,D.distance=Mt,D.enableResponsive=si,D.fillDefaults=ro,D.getAllCorners=Nn,D.getEditor=Ii,D.getMaskDimensions=ft,D.getSVGPoint=rn,D.getTool=sn,D.initKeyboardCommands=lo,D.intersects=Sn,D.isImageAnnotation=lt,D.isImageAnnotationTarget=at,D.isMac=cn,D.isPointInPolygon=bt,D.isTouch=Ue,D.listDrawingTools=on,D.multipolygonElementToPath=De,D.parseFragmentSelector=Rn,D.parseSVGSelector=qn,D.parseW3CImageAnnotation=ii,D.pointsToPath=Cn,D.registerEditor=Ri,D.registerShapeUtil=st,D.registerTool=Vi,D.sampleBrightness=oo,D.serializeFragmentSelector=Ln,D.serializeSVGSelector=Zn,D.serializeW3CImageAnnotation=oi,D.setTheme=fn,D.simplifyMultiPolygon=vo,D.simplifyPoints=Vt,D.simplifyPolygon=Co,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,q){typeof exports=="object"&&typeof module<"u"?q(exports):typeof define=="function"&&define.amd?define(["exports"],q):(D=typeof globalThis<"u"?globalThis:D||self,q(D.Annotorious={}))})(this,function(D){"use strict";var rl=Object.defineProperty;var ll=(D,q,He)=>q in D?rl(D,q,{enumerable:!0,configurable:!0,writable:!0,value:He}):D[q]=He;var se=(D,q,He)=>ll(D,typeof q!="symbol"?q+"":q,He);function q(){}function He(e,t){for(const n in t)e[n]=t[n];return e}function gn(e){return e()}function pn(){return Object.create(null)}function Ie(e){e.forEach(gn)}function re(e){return typeof e=="function"}function ce(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function ao(e){return Object.keys(e).length===0}function yn(e,...t){if(e==null){for(const i of t)i(void 0);return q}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function Lt(e,t,n){e.$$.on_destroy.push(yn(t,n))}function uo(e,t,n,i){if(e){const o=_n(e,t,n,i);return e[0](o)}}function _n(e,t,n,i){return e[1]&&i?He(n.ctx.slice(),e[1](i(t))):n.ctx}function fo(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 l=0;l<r;l+=1)s[l]=t.dirty[l]|o[l];return s}return t.dirty|o}return t.dirty}function co(e,t,n,i,o,s){if(o){const r=_n(t,n,i,s);e.p(r,o)}}function ho(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 mn(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function K(e,t){e.appendChild(t)}function V(e,t,n){e.insertBefore(t,n||null)}function H(e){e.parentNode&&e.parentNode.removeChild(e)}function Ge(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 wn(e){return document.createTextNode(e)}function Oe(){return wn(" ")}function Se(){return wn("")}function ee(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 go(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function po(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 En(){if(!it)throw new Error("Function called outside component initialization");return it}function ze(e){En().$$.on_mount.push(e)}function Ve(){const e=En();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const s=po(t,n,{cancelable:i});return o.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function Ee(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Ke=[],yt=[];let We=[];const bn=[],Tn=Promise.resolve();let kt=!1;function An(){kt||(kt=!0,Tn.then(Mn))}function On(){return An(),Tn}function Pt(e){We.push(e)}const Dt=new Set;let Je=0;function Mn(){if(Je!==0)return;const e=it;do{try{for(;Je<Ke.length;){const t=Ke[Je];Je++,ot(t),yo(t.$$)}}catch(t){throw Ke.length=0,Je=0,t}for(ot(null),Ke.length=0,Je=0;yt.length;)yt.pop()();for(let t=0;t<We.length;t+=1){const n=We[t];Dt.has(n)||(Dt.add(n),n())}We.length=0}while(Ke.length);for(;bn.length;)bn.pop()();kt=!1,Dt.clear(),ot(e)}function yo(e){if(e.fragment!==null){e.update(),Ie(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Pt)}}function _o(e){const t=[],n=[];We.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),We=t}const _t=new Set;let Qe;function be(){Qe={r:0,c:[],p:Qe}}function Te(){Qe.r||Ie(Qe.c),Qe=Qe.p}function B(e,t){e&&e.i&&(_t.delete(e),e.i(t))}function F(e,t,n,i){if(e&&e.o){if(_t.has(e))return;_t.add(e),Qe.c.push(()=>{_t.delete(e),i&&(n&&e.d(1),i())}),e.o(t)}else i&&i()}function Ne(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function pe(e){e&&e.c()}function de(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),Pt(()=>{const s=e.$$.on_mount.map(gn).filter(re);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ie(s),e.$$.on_mount=[]}),o.forEach(Pt)}function ge(e,t){const n=e.$$;n.fragment!==null&&(_o(n.after_update),Ie(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function mo(e,t){e.$$.dirty[0]===-1&&(Ke.push(e),An(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function Me(e,t,n,i,o,s,r=null,l=[-1]){const a=it;ot(e);const u=e.$$={fragment:null,ctx:[],props:s,update:q,not_equal:o,bound:pn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:pn(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let h=!1;if(u.ctx=n?n(e,t.props||{},(c,d,...p)=>{const y=p.length?p[0]:d;return u.ctx&&o(u.ctx[c],u.ctx[c]=y)&&(!u.skip_bound&&u.bound[c]&&u.bound[c](y),h&&mo(e,c)),d}):[],u.update(),h=!0,Ie(u.before_update),u.fragment=i?i(u.ctx):!1,t.target){if(t.hydrate){const c=go(t.target);u.fragment&&u.fragment.l(c),c.forEach(H)}else u.fragment&&u.fragment.c();t.intro&&B(e.$$.fragment),de(e,t.target,t.anchor),Mn()}ot(a)}class ve{constructor(){se(this,"$$");se(this,"$$set")}$destroy(){ge(this,1),this.$destroy=q}$on(t,n){if(!re(n))return q;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&&!ao(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const wo="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(wo);var ie=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e))(ie||{});function Eo(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var vn={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,h=l.y-a.y;return u*u+h*h}function n(l,a,u){var h=a.x,c=a.y,d=u.x-h,p=u.y-c;if(d!==0||p!==0){var y=((l.x-h)*d+(l.y-c)*p)/(d*d+p*p);y>1?(h=u.x,c=u.y):y>0&&(h+=d*y,c+=p*y)}return d=l.x-h,p=l.y-c,d*d+p*p}function i(l,a){for(var u=l[0],h=[u],c,d=1,p=l.length;d<p;d++)c=l[d],t(c,u)>a&&(h.push(c),u=c);return u!==c&&h.push(c),h}function o(l,a,u,h,c){for(var d=h,p,y=a+1;y<u;y++){var g=n(l[y],l[a],l[u]);g>d&&(p=y,d=g)}d>h&&(p-a>1&&o(l,a,p,h,c),c.push(l[p]),u-p>1&&o(l,p,u,h,c))}function s(l,a){var u=l.length-1,h=[l[0]];return o(l,0,u,a,h),h.push(l[u]),h}function r(l,a,u){if(l.length<=2)return l;var h=a!==void 0?a*a:1;return l=u?l:i(l,h),l=s(l,h),l}e.exports=r,e.exports.default=r})()})(vn);var bo=vn.exports;const To=Eo(bo),Ut={},st=(e,t)=>Ut[e]=t,mt=e=>Ut[e.type].area(e),Sn=(e,t,n)=>Ut[e.type].intersects(e,t,n),ye=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}},wt=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)},Et=(e,t,n)=>{let i=!1;for(let o=0,s=e.length-1;o<e.length;s=o++){const r=e[o][0],l=e[o][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(i=!i)}return i},Nn=(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},Ht=(e,t=1)=>{const n=e.map(([i,o])=>({x:i,y:o}));return To(n,t,!0).map(i=>[i.x,i.y])},Ao={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,l=0,a=Math.cos(l),u=Math.sin(l),h=t-i,c=n-o,d=a*h+u*c,p=u*h-a*c;return d*d/(s*s)+p*p/(r*r)<=1}};st(ie.ELLIPSE,Ao);const Oo={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...s]=i.rings,r=wt(o.points),l=s.reduce((a,u)=>a+wt(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:i}=e.geometry;for(const o of i){const[s,...r]=o.rings;if(Et(s.points,t,n)){let l=!1;for(const a of r)if(Et(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},rt=e=>{const t=e.reduce((n,i)=>[...n,...i.rings[0].points],[]);return ye(t)},De=e=>e.rings.map(n=>Nn(n.points)).join(" "),Cn=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((i,o)=>[...i,...o.points],[])],[]),Mo=(e,t=1)=>{const n=e.geometry.polygons.map(o=>{const s=o.rings.map(l=>{const a=Ht(l.points,t);return{...l,points:a}}),r=ye(s[0].points);return{...o,rings:s,bounds:r}}),i=rt(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:i}}};st(ie.MULTIPOLYGLON,Oo);const vo={area:e=>{const t=e.geometry.points;return wt(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return Et(i,t,n)}},So=(e,t=1)=>{const n=Ht(e.geometry.points,t),i=ye(n);return{...e,geometry:{...e.geometry,bounds:i,points:n}}};st(ie.POLYGON,vo);const In={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(ie.RECTANGLE,In);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},Rn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,o=[...n.matchAll(i)][0],[s,r,l,a,u,h,c]=o;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[d,p,y,g]=[a,u,h,c].map(parseFloat);return{type:ie.RECTANGLE,geometry:{x:d,y:p,w:y,h:g,bounds:{minX:d,minY:t?p-g:p,maxX:d+y,maxY:t?p:p+g}}}},Ln=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}`}},kn="http://www.w3.org/2000/svg",Pn=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},No=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${kn}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},Dn=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(kn),o=n.lookupNamespaceURI(null);return i||o?Pn(n).firstChild:Pn(No(n)).firstChild},ue=" ";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===A.CLOSE_PATH)t+="z";else if(i.type===A.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===A.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===A.MOVE_TO)t+=(i.relative?"m":"M")+i.x+ue+i.y;else if(i.type===A.LINE_TO)t+=(i.relative?"l":"L")+i.x+ue+i.y;else if(i.type===A.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+ue+i.y1+ue+i.x2+ue+i.y2+ue+i.x+ue+i.y;else if(i.type===A.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+ue+i.y2+ue+i.x+ue+i.y;else if(i.type===A.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+ue+i.y1+ue+i.x+ue+i.y;else if(i.type===A.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+ue+i.y;else if(i.type===A.ARC)t+=(i.relative?"a":"A")+i.rX+ue+i.rY+ue+i.xRot+ue+ +i.lArcFlag+ue+ +i.sweepFlag+ue+i.x+ue+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Vt([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 Ye=Math.PI;function Yt(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 l=e.xRot/180*Ye,[a,u]=Vt([(t-s)/2,(n-r)/2],-l),h=Math.pow(a,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(a,2),d=(e.lArcFlag!==e.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(o,2)-c)/c)),p=i*u/o*d,y=-o*a/i*d,g=Vt([p,y],l);e.cX=g[0]+(t+s)/2,e.cY=g[1]+(n+r)/2,e.phi1=Math.atan2((u-y)/o,(a-p)/i),e.phi2=Math.atan2((-u-y)/o,(-a-p)/i),e.sweepFlag===0&&e.phi2>e.phi1&&(e.phi2-=2*Ye),e.sweepFlag===1&&e.phi2<e.phi1&&(e.phi2+=2*Ye),e.phi1*=180/Ye,e.phi2*=180/Ye}function Un(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 qe=Math.PI/180;function Hn(e,t,n){return(1-n)*e+n*t}function Vn(e,t,n,i){return e+Math.cos(i/180*Ye)*t+Math.sin(i/180*Ye)*n}function Yn(e,t,n,i){const s=t-e,r=n-t,l=i-n,a=3*s+3*l-6*r,u=(r-s)*6,h=3*s;return Math.abs(a)<1e-6?Math.abs(u)<1e-6?[]:[-h/u]:Io(u/a,h/a,1e-6)}function Bn(e,t,n,i,o){const s=1-o,r=s*s*s,l=3*s*s*o,a=3*s*o*o,u=o*o*o;return e*r+t*l+n*a+i*u}function Io(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 Ro(e,t,n){e.cX||Yt(e,t,n);const i=e.xRot/180*Ye;if(Math.abs(e.rX)<1e-10||Math.abs(e.rY)<1e-10)return[{relative:e.relative,type:A.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,l=Math.ceil(r/90),a=new Array(l);let u=t,h=n;const c=(d,p)=>{const[y,g]=Vt([d*e.rX,p*e.rY],i);return[e.cX+y,e.cY+g]};for(let d=0;d<l;d++){const p=Hn(e.phi1,e.phi2,d/l),y=Hn(e.phi1,e.phi2,(d+1)/l),g=y-p,O=4/3*Math.tan(g*qe/4),_=Math.cos(p*qe)-O*Math.sin(p*qe),M=Math.sin(p*qe)+O*Math.cos(p*qe),b=Math.cos(y*qe),v=Math.sin(y*qe),S=b+O*v,I=v-O*b,N=c(_,M),P=c(S,I),k=c(b,v),G={relative:e.relative,type:A.CURVE_TO,x:k[0],y:k[1],x1:N[0],y1:N[1],x2:P[0],y2:P[1]};e.relative&&(G.x1-=u,G.y1-=h,G.x2-=u,G.y2-=h,G.x-=u,G.y-=h),u=k[0],h=k[1],a[d]=G}return a}function Bt(e,t,n){const i=t[0]-e[0],o=t[1]-e[1],s=n[0]-e[0],r=n[1]-e[1],l=i*r-o*s;if(!(Math.abs(l)<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 Lo(e,t=!0){if(e.length<2)return e;const n=fe.INFO((s,r,l)=>({...s,x:s.x??r,y:s.y??l,relative:s.relative??!1})),i=[];let o=[];for(const s of e){const r=n(s);r.type===A.MOVE_TO&&o.length>0&&(t?i.push(...bt(o)):i.unshift(...bt(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...bt(o)):i.unshift(...bt(o))),i}function bt(e){var o;const t=((o=e[e.length-1])==null?void 0:o.type)===A.CLOSE_PATH,n=t?e.length-2:e.length-1,i=[{type:A.MOVE_TO,relative:!1,x:e[n].x,y:e[n].y}];for(let s=n;s>0;s--){const r=e[s],l=e[s-1];if(r.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(r.type){case A.HORIZ_LINE_TO:i.push({type:A.HORIZ_LINE_TO,relative:!1,x:l.x});break;case A.VERT_LINE_TO:i.push({type:A.VERT_LINE_TO,relative:!1,y:l.y});break;case A.LINE_TO:case A.MOVE_TO:i.push({type:A.LINE_TO,relative:!1,x:l.x,y:l.y});break;case A.CURVE_TO:i.push({type:A.CURVE_TO,relative:!1,x:l.x,y:l.y,x1:r.x2,y1:r.y2,x2:r.x1,y2:r.y1});break;case A.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case A.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case A.ARC:throw new Error("Unsupported command: A (arc)");case A.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return t&&i.push({type:A.CLOSE_PATH}),i}function ko(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 Xn(){return Le((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 Po(){return Le((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 Do(e=!0,t=!0,n=!0,i=!0){return Le((o,s,r,l,a)=>{if(isNaN(l)&&!(o.type&A.MOVE_TO))throw new Error("path must start with moveto");if(t&&o.type&A.HORIZ_LINE_TO&&(o.type=A.LINE_TO,o.y=o.relative?0:r),n&&o.type&A.VERT_LINE_TO&&(o.type=A.LINE_TO,o.x=o.relative?0:s),e&&o.type&A.CLOSE_PATH&&(o.type=A.LINE_TO,o.x=o.relative?l-s:l,o.y=o.relative?a-r:a),o.type&A.ARC&&(o.rX===0||o.rY===0)&&(o.type=A.LINE_TO,delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag),i&&o.type&A.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];Bt(u,h,c)&&(o.type=A.LINE_TO,delete o.x1,delete o.y1)}if(i&&o.type&A.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];Bt(u,h,d)&&Bt(u,c,d)&&(o.type=A.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function Fn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Le((o,s,r)=>(o.type&A.SMOOTH_CURVE_TO&&(o.type=A.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&A.CURVE_TO?(e=o.relative?s+o.x2:o.x2,t=o.relative?r+o.y2:o.y2):(e=NaN,t=NaN),o.type&A.SMOOTH_QUAD_TO&&(o.type=A.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&A.QUAD_TO?(n=o.relative?s+o.x1:o.x1,i=o.relative?r+o.y1:o.y1):(n=NaN,i=NaN),o))}function jn(){let e=NaN,t=NaN;return Le((n,i,o)=>{if(n.type&A.SMOOTH_QUAD_TO&&(n.type=A.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&A.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=A.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 Le(e){let t=0,n=0,i=NaN,o=NaN;return function(r){if(isNaN(i)&&!(r.type&A.MOVE_TO))throw new Error("path must start with moveto");const l=e(r,t,n,i,o);return r.type&A.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&A.MOVE_TO&&(i=t,o=n),l}}function Uo(e=0){Re(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Le((s,r,l,a,u)=>{const h=Math.abs;let c=!1,d=0,p=0;if(s.type&A.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:r-t,p=isNaN(n)?0:l-n),s.type&(A.CURVE_TO|A.SMOOTH_CURVE_TO)?(t=s.relative?r+s.x2:s.x2,n=s.relative?l+s.y2:s.y2):(t=NaN,n=NaN),s.type&A.SMOOTH_QUAD_TO?(i=isNaN(i)?r:2*r-i,o=isNaN(o)?l:2*l-o):s.type&A.QUAD_TO?(i=s.relative?r+s.x1:s.x1,o=s.relative?l+s.y1:s.y2):(i=NaN,o=NaN),s.type&A.LINE_COMMANDS||s.type&A.ARC&&(s.rX===0||s.rY===0||!s.lArcFlag)||s.type&A.CURVE_TO||s.type&A.SMOOTH_CURVE_TO||s.type&A.QUAD_TO||s.type&A.SMOOTH_QUAD_TO){const y=typeof s.x>"u"?0:s.relative?s.x:s.x-r,g=typeof s.y>"u"?0:s.relative?s.y:s.y-l;d=isNaN(i)?typeof s.x1>"u"?d:s.relative?s.x:s.x1-r:i-r,p=isNaN(o)?typeof s.y1>"u"?p:s.relative?s.y:s.y1-l:o-l;const O=typeof s.x2>"u"?0:s.relative?s.x:s.x2-r,_=typeof s.y2>"u"?0:s.relative?s.y:s.y2-l;h(y)<=e&&h(g)<=e&&h(d)<=e&&h(p)<=e&&h(O)<=e&&h(_)<=e&&(c=!0)}return s.type&A.CLOSE_PATH&&h(r-a)<=e&&h(l-u)<=e&&(c=!0),c?[]:s})}function Be(e,t,n,i,o,s){return Re(e,t,n,i,o,s),Le((r,l,a,u)=>{const h=r.x1,c=r.x2,d=r.relative&&!isNaN(u),p=typeof r.x<"u"?r.x:d?0:l,y=typeof r.y<"u"?r.y:d?0:a;r.type&A.HORIZ_LINE_TO&&t!==0&&(r.type=A.LINE_TO,r.y=r.relative?0:a),r.type&A.VERT_LINE_TO&&n!==0&&(r.type=A.LINE_TO,r.x=r.relative?0:l),typeof r.x<"u"&&(r.x=r.x*e+y*n+(d?0:o)),typeof r.y<"u"&&(r.y=p*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 g(_){return _*_}const O=e*i-t*n;if(typeof r.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(O===0)delete r.rX,delete r.rY,delete r.xRot,delete r.lArcFlag,delete r.sweepFlag,r.type=A.LINE_TO;else{const _=r.xRot*Math.PI/180,M=Math.sin(_),b=Math.cos(_),v=1/g(r.rX),S=1/g(r.rY),I=g(b)*v+g(M)*S,N=2*M*b*(v-S),P=g(M)*v+g(b)*S,k=I*i*i-N*t*i+P*t*t,G=N*(e*i+t*n)-2*(I*n*i+P*e*t),z=I*n*n-N*e*n+P*e*e,w=(Math.atan2(G,k-z)+Math.PI)%Math.PI/2,T=Math.sin(w),m=Math.cos(w);r.rX=Math.abs(O)/Math.sqrt(k*g(m)+G*T*m+z*g(T)),r.rY=Math.abs(O)/Math.sqrt(k*g(T)-G*T*m+z*g(m)),r.xRot=w*180/Math.PI}return typeof r.sweepFlag<"u"&&0>O&&(r.sweepFlag=+!r.sweepFlag),r})}function Ho(e,t=0,n=0){Re(e,t,n);const i=Math.sin(e),o=Math.cos(e);return Be(o,i,-i,o,t-t*o+n*i,n-t*i-n*o)}function Vo(e,t=0){return Re(e,t),Be(1,0,0,1,e,t)}function Yo(e,t=e){return Re(e,t),Be(e,0,0,t,0,0)}function Bo(e){return Re(e),Be(1,0,Math.tan(e),1,0,0)}function Xo(e){return Re(e),Be(1,Math.tan(e),0,1,0,0)}function Fo(e=0){return Re(e),Be(-1,0,0,1,e,0)}function jo(e=0){return Re(e),Be(1,0,0,-1,0,e)}function Go(){return Le((e,t,n)=>A.ARC===e.type?Ro(e,e.relative?0:t,e.relative?0:n):e)}function zo(){return Le((e,t,n)=>(e.relative&&(t=0,n=0),A.ARC===e.type&&Yt(e,t,n),e))}function Gn(){return e=>({...e})}function Qo(){const e=Gn(),t=Xn(),n=jn(),i=Fn(),o=Le((s,r,l)=>{const a=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(a.type&A.DRAWING_COMMANDS&&(u(r),h(l)),a.type&A.HORIZ_LINE_TO&&u(a.x),a.type&A.VERT_LINE_TO&&h(a.y),a.type&A.LINE_TO&&(u(a.x),h(a.y)),a.type&A.CURVE_TO){u(a.x),h(a.y);const c=Yn(r,a.x1,a.x2,a.x);for(const p of c)0<p&&1>p&&u(Bn(r,a.x1,a.x2,a.x,p));const d=Yn(l,a.y1,a.y2,a.y);for(const p of d)0<p&&1>p&&h(Bn(l,a.y1,a.y2,a.y,p))}if(a.type&A.ARC){u(a.x),h(a.y),Yt(a,r,l);const c=a.xRot/180*Math.PI,d=Math.cos(c)*a.rX,p=Math.sin(c)*a.rX,y=-Math.sin(c)*a.rY,g=Math.cos(c)*a.rY,[O,_]=a.phi1<a.phi2?[a.phi1,a.phi2]:-180>a.phi2?[a.phi2+360,a.phi1+360]:[a.phi2,a.phi1],M=([S,I])=>{const P=Math.atan2(I,S)*180/Math.PI;return P<O?P+360:P},b=Un(y,-d,0).map(M);for(const S of b)S>O&&S<_&&u(Vn(a.cX,d,y,S));const v=Un(g,-p,0).map(M);for(const S of v)S>O&&S<_&&h(Vn(a.cY,p,g,S))}return s});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const fe={ROUND:ko,TO_ABS:Xn,TO_REL:Po,NORMALIZE_HVZ:Do,NORMALIZE_ST:Fn,QT_TO_C:jn,INFO:Le,SANITIZE:Uo,MATRIX:Be,ROTATE:Ho,TRANSLATE:Vo,SCALE:Yo,SKEW_X:Bo,SKEW_Y:Xo,X_AXIS_SYMMETRY:Fo,Y_AXIS_SYMMETRY:jo,A_TO_C:Go,ANNOTATE_ARCS:zo,CLONE:Gn,CALCULATE_BOUNDS:Qo,REVERSE_PATH:Lo};class zn{round(t){return this.transform(fe.ROUND(t))}toAbs(){return this.transform(fe.TO_ABS())}toRel(){return this.transform(fe.TO_REL())}normalizeHVZ(t,n,i){return this.transform(fe.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(fe.NORMALIZE_ST())}qtToC(){return this.transform(fe.QT_TO_C())}aToC(){return this.transform(fe.A_TO_C())}sanitize(t){return this.transform(fe.SANITIZE(t))}translate(t,n){return this.transform(fe.TRANSLATE(t,n))}scale(t,n){return this.transform(fe.SCALE(t,n))}rotate(t,n,i){return this.transform(fe.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(fe.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(fe.SKEW_X(t))}skewY(t){return this.transform(fe.SKEW_Y(t))}xSymmetry(t){return this.transform(fe.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(fe.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(fe.ANNOTATE_ARCS())}}const qo=e=>e===" "||e===" "||e==="\r"||e===`
2
+ `,Qn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class Zo extends zn{constructor(){super();se(this,"curNumber","");se(this,"curCommandType",-1);se(this,"curCommandRelative",!1);se(this,"canParseCommandOrComma",!0);se(this,"curNumberHasExp",!1);se(this,"curNumberHasExpDigits",!1);se(this,"curNumberHasDecimal",!1);se(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],l=this.curCommandType===A.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),a=Qn(r)&&(this.curNumber==="0"&&r==="0"||l);if(Qn(r)&&!a){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&&!l){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===A.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===Ko[this.curCommandType]&&(A.HORIZ_LINE_TO===this.curCommandType?o({type:A.HORIZ_LINE_TO,relative:this.curCommandRelative,x:u}):A.VERT_LINE_TO===this.curCommandType?o({type:A.VERT_LINE_TO,relative:this.curCommandRelative,y:u}):this.curCommandType===A.MOVE_TO||this.curCommandType===A.LINE_TO||this.curCommandType===A.SMOOTH_QUAD_TO?(o({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),A.MOVE_TO===this.curCommandType&&(this.curCommandType=A.LINE_TO)):this.curCommandType===A.CURVE_TO?o({type:A.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===A.SMOOTH_CURVE_TO?o({type:A.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===A.QUAD_TO?o({type:A.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===A.ARC&&o({type:A.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(!qo(r)){if(r===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(r==="+"||r==="-"||r==="."){this.curNumber=r,this.curNumberHasDecimal=r===".";continue}if(a){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:A.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(r==="h"||r==="H")this.curCommandType=A.HORIZ_LINE_TO,this.curCommandRelative=r==="h";else if(r==="v"||r==="V")this.curCommandType=A.VERT_LINE_TO,this.curCommandRelative=r==="v";else if(r==="m"||r==="M")this.curCommandType=A.MOVE_TO,this.curCommandRelative=r==="m";else if(r==="l"||r==="L")this.curCommandType=A.LINE_TO,this.curCommandRelative=r==="l";else if(r==="c"||r==="C")this.curCommandType=A.CURVE_TO,this.curCommandRelative=r==="c";else if(r==="s"||r==="S")this.curCommandType=A.SMOOTH_CURVE_TO,this.curCommandRelative=r==="s";else if(r==="q"||r==="Q")this.curCommandType=A.QUAD_TO,this.curCommandRelative=r==="q";else if(r==="t"||r==="T")this.curCommandType=A.SMOOTH_QUAD_TO,this.curCommandRelative=r==="t";else if(r==="a"||r==="A")this.curCommandType=A.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 l of r){const a=n(l);Array.isArray(a)?s.push(...a):s.push(a)}return s}}})}}const ne=class ne extends zn{constructor(n){super();se(this,"commands");typeof n=="string"?this.commands=ne.parse(n):this.commands=n}encode(){return ne.encode(this.commands)}getBounds(){const n=fe.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=fe.REVERSE_PATH(this.commands,n),this}static encode(n){return Co(n)}static parse(n){const i=new Zo,o=[];return i.parse(n,o),i.finish(o),o}};se(ne,"CLOSE_PATH",1),se(ne,"MOVE_TO",2),se(ne,"HORIZ_LINE_TO",4),se(ne,"VERT_LINE_TO",8),se(ne,"LINE_TO",16),se(ne,"CURVE_TO",32),se(ne,"SMOOTH_CURVE_TO",64),se(ne,"QUAD_TO",128),se(ne,"SMOOTH_QUAD_TO",256),se(ne,"ARC",512),se(ne,"LINE_COMMANDS",ne.LINE_TO|ne.HORIZ_LINE_TO|ne.VERT_LINE_TO),se(ne,"DRAWING_COMMANDS",ne.HORIZ_LINE_TO|ne.VERT_LINE_TO|ne.LINE_TO|ne.CURVE_TO|ne.SMOOTH_CURVE_TO|ne.QUAD_TO|ne.SMOOTH_QUAD_TO|ne.ARC);let A=ne;const Ko={[A.MOVE_TO]:2,[A.LINE_TO]:2,[A.HORIZ_LINE_TO]:1,[A.VERT_LINE_TO]:1,[A.CLOSE_PATH]:0,[A.QUAD_TO]:4,[A.SMOOTH_QUAD_TO]:2,[A.CURVE_TO]:6,[A.SMOOTH_CURVE_TO]:4,[A.ARC]:7},Wo=e=>{const t=new A(e).toAbs().commands,n=[];let i=[],o=null;for(const s of t)switch(s.type){case A.MOVE_TO:i.length>0&&(n.push({points:i}),i=[]),o=[s.x,s.y],i.push(o);break;case A.LINE_TO:i.push([s.x,s.y]);break;case A.HORIZ_LINE_TO:const r=i[i.length-1][1];i.push([s.x,r]);break;case A.VERT_LINE_TO:const l=i[i.length-1][0];i.push([l,s.y]);break;case A.CURVE_TO:case A.SMOOTH_CURVE_TO:case A.QUAD_TO:case A.SMOOTH_QUAD_TO:case A.ARC:i.push([s.x,s.y]);break}if(i.length>2&&n.push({points:i}),n.length>0){const s=ye(n[0].points);return{rings:n,bounds:s}}},Jo=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:ie.POLYGON,geometry:{points:o,bounds:ye(o)}}},xo=e=>{const t=Dn(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:ie.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},$o=e=>{const t=Dn(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>Wo(a)).filter(Boolean),s=o.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=ye(s);return o.length===1&&o[0].rings.length===1?{type:ie.POLYGON,geometry:{points:s,bounds:r}}:{type:ie.MULTIPOLYGLON,geometry:{polygons:o,bounds:r}}},qn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return Jo(t);if(t.includes("<path "))return $o(t);if(t.includes("<ellipse "))return xo(t);throw"Unsupported SVG shape: "+t},es=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${De(n)}" />`).join("")}</g>`,Zn=e=>{let t;if(e.type===ie.POLYGON){const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`}else if(e.type===ie.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===ie.MULTIPOLYGLON){const n=e.geometry;t=`<svg>${es(n)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},_e=[];for(let e=0;e<256;++e)_e.push((e+256).toString(16).slice(1));function ts(e,t=0){return(_e[e[t+0]]+_e[e[t+1]]+_e[e[t+2]]+_e[e[t+3]]+"-"+_e[e[t+4]]+_e[e[t+5]]+"-"+_e[e[t+6]]+_e[e[t+7]]+"-"+_e[e[t+8]]+_e[e[t+9]]+"-"+_e[e[t+10]]+_e[e[t+11]]+_e[e[t+12]]+_e[e[t+13]]+_e[e[t+14]]+_e[e[t+15]]).toLowerCase()}let Xt;const ns=new Uint8Array(16);function is(){if(!Xt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Xt=crypto.getRandomValues.bind(crypto)}return Xt(ns)}const Kn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Wn(e,t,n){var o;if(Kn.randomUUID&&!e)return Kn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??is();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,ts(i)}var Jn=Object.prototype.hasOwnProperty;function Xe(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--&&Xe(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Jn.call(e,n)&&++i&&!Jn.call(t,n)||!(n in t)||!Xe(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}function Ft(){}function os(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const xe=[];function jt(e,t=Ft){let n;const i=new Set;function o(l){if(os(e,l)&&(e=l,n)){const a=!xe.length;for(const u of i)u[1](),xe.push(u,e);if(a){for(let u=0;u<xe.length;u+=2)xe[u][0](xe[u+1]);xe.length=0}}}function s(l){o(l(e))}function r(l,a=Ft){const u=[l,a];return i.add(u),i.size===1&&(n=t(o,s)||Ft),l(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const ss=e=>{const{subscribe:t,set:n}=jt();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 Gt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Gt||{});const Tt={selected:[]},rs=(e,t,n)=>{const{subscribe:i,set:o}=jt(Tt);let s=t,r=Tt;i(g=>r=g);const l=()=>{Xe(r,Tt)||o(Tt)},a=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(a())return!1;const O=typeof g=="string"?g:g.id;return r.selected.some(_=>_.id===O)},h=(g,O)=>{let _;if(Array.isArray(g)){if(_=g.map(b=>e.getAnnotation(b)).filter(Boolean),_.length<g.length){console.warn("Invalid selection: "+g.filter(b=>!_.some(v=>v.id===b)));return}}else{const b=e.getAnnotation(g);if(!b){console.warn("Invalid selection: "+g);return}_=[b]}const M=_.reduce((b,v)=>{const S=zt(v,s,n);return S==="EDIT"?[...b,{id:v.id,editable:!0}]:S==="SELECT"?[...b,{id:v.id}]:b},[]);o({selected:M,event:O})},c=(g,O)=>{const _=Array.isArray(g)?g:[g],M=_.map(b=>e.getAnnotation(b)).filter(b=>!!b);o({selected:M.map(b=>{const v=O===void 0?zt(b,s,n)==="EDIT":O;return{id:b.id,editable:v}})}),M.length!==_.length&&console.warn("Invalid selection",g)},d=g=>{if(a())return!1;const{selected:O}=r;O.some(({id:_})=>g.includes(_))&&o({selected:O.filter(({id:_})=>!g.includes(_))})},p=g=>{s=g,c(r.selected.map(({id:O})=>O))},y=g=>zt(g,s,n);return e.observe(({changes:g})=>d((g.deleted||[]).map(O=>O.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:l,evalSelectAction:y,isEmpty:a,isSelected:u,setSelected:c,setUserSelectAction:p,subscribe:i,userSelect:h}},zt=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function ls(e,t=0){return(me[e[t+0]]+me[e[t+1]]+me[e[t+2]]+me[e[t+3]]+"-"+me[e[t+4]]+me[e[t+5]]+"-"+me[e[t+6]]+me[e[t+7]]+"-"+me[e[t+8]]+me[e[t+9]]+"-"+me[e[t+10]]+me[e[t+11]]+me[e[t+12]]+me[e[t+13]]+me[e[t+14]]+me[e[t+15]]).toLowerCase()}let Qt;const as=new Uint8Array(16);function us(){if(!Qt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Qt=crypto.getRandomValues.bind(crypto)}return Qt(as)}const fs=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),xn={randomUUID:fs};function $n(e,t,n){var i;if(xn.randomUUID&&!e)return xn.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??us();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,ls(o)}const qt=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)}},cs=(e,t,n,i)=>({id:$n(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),hs=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},ds=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},gs=(e,t)=>t.bodies.map(n=>{const i=e.bodies.find(o=>o.id===n.id);return{newBody:n,oldBody:i&&!Xe(i,n)?i:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:i})=>({oldBody:n,newBody:i})),ps=(e,t)=>!Xe(e.target,t.target),ei=(e,t)=>{const n=hs(e,t),i=ds(e,t),o=gs(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:ps(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var oe=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(oe||{});const ys=(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,l=a=>a&&a.length>0;if(!(l(o.created)||l(o.deleted))){const a=(n=o.updated)==null?void 0:n.some(h=>l(h.bodiesCreated)||l(h.bodiesDeleted)||l(h.bodiesUpdated)),u=(i=o.updated)==null?void 0:i.some(h=>h.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(o.created||[]).map(l=>l.id),...(o.deleted||[]).map(l=>l.id),...(o.updated||[]).map(({oldValue:l})=>l.id)]);return!!(Array.isArray(e.options.annotations)?e.options.annotations:[e.options.annotations]).find(l=>r.has(l))}else return!0},_s=(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)),l=new Set((t.updated||[]).filter(({oldValue:c})=>n.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),a=[...(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:p}=c;if(r.has(p.id)){const y=t.updated.find(g=>g.oldValue.id===p.id).newValue;return ei(d,y)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!l.has(c.id))];return{created:a,deleted:u,updated:h}},At=e=>{const t=e.id===void 0?$n():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},ms=e=>e.id!==void 0,ws=()=>{const e=new Map,t=new Map,n=[],i=(w,T={})=>{n.push({onChange:w,options:T})},o=w=>{const T=n.findIndex(m=>m.onChange==w);T>-1&&n.splice(T,1)},s=(w,T)=>{const m={origin:w,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...e.values()]};n.forEach(E=>{ys(E,m)&&E.onChange(m)})},r=(w,T=oe.LOCAL)=>{if(w.id&&e.get(w.id))throw Error(`Cannot add annotation ${w.id} - exists already`);{const m=At(w);e.set(m.id,m),m.bodies.forEach(E=>t.set(E.id,m.id)),s(T,{created:[m]})}},l=(w,T)=>{const m=At(typeof w=="string"?T:w),E=typeof w=="string"?w:w.id,R=E&&e.get(E);if(R){const C=ei(R,m);return E===m.id?e.set(E,m):(e.delete(E),e.set(m.id,m)),R.bodies.forEach(U=>t.delete(U.id)),m.bodies.forEach(U=>t.set(U.id,m.id)),C}else console.warn(`Cannot update annotation ${E} - does not exist`)},a=(w,T=oe.LOCAL,m=oe.LOCAL)=>{const E=ms(T)?m:T,R=l(w,T);R&&s(E,{updated:[R]})},u=(w,T=oe.LOCAL)=>{e.get(w.id)?a(w,T):r(w,T)},h=(w,T=oe.LOCAL)=>{const m=w.reduce((E,R)=>{const C=l(R);return C?[...E,C]:E},[]);m.length>0&&s(T,{updated:m})},c=(w,T=oe.LOCAL)=>{const m=w.map(At),{toAdd:E,toUpdate:R}=m.reduce((U,Q)=>e.get(Q.id)?{...U,toUpdate:[...U.toUpdate,Q]}:{...U,toAdd:[...U.toAdd,Q]},{toAdd:[],toUpdate:[]}),C=R.map(U=>l(U,T)).filter(Boolean);E.forEach(U=>{e.set(U.id,U),U.bodies.forEach(Q=>t.set(Q.id,U.id))}),s(T,{created:E,updated:C})},d=(w,T=oe.LOCAL)=>{const m=e.get(w.annotation);if(m){const E={...m,bodies:[...m.bodies,w]};e.set(m.id,E),t.set(w.id,E.id),s(T,{updated:[{oldValue:m,newValue:E,bodiesCreated:[w]}]})}else console.warn(`Attempt to add body to missing annotation: ${w.annotation}`)},p=()=>[...e.values()],y=(w=oe.LOCAL)=>{const T=[...e.values()];e.clear(),t.clear(),s(w,{deleted:T})},g=(w,T=!0,m=oe.LOCAL)=>{const E=w.map(At);if(T){const R=[...e.values()];e.clear(),t.clear(),E.forEach(C=>{e.set(C.id,C),C.bodies.forEach(U=>t.set(U.id,C.id))}),s(m,{created:E,deleted:R})}else{const R=w.reduce((C,U)=>{const Q=U.id&&e.get(U.id);return Q?[...C,Q]:C},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(C=>C.id).join(", ")}`);E.forEach(C=>{e.set(C.id,C),C.bodies.forEach(U=>t.set(U.id,C.id))}),s(m,{created:E})}},O=w=>{const T=typeof w=="string"?w:w.id,m=e.get(T);if(m)return e.delete(T),m.bodies.forEach(E=>t.delete(E.id)),m;console.warn(`Attempt to delete missing annotation: ${T}`)},_=(w,T=oe.LOCAL)=>{const m=O(w);m&&s(T,{deleted:[m]})},M=(w,T=oe.LOCAL)=>{const m=w.reduce((E,R)=>{const C=O(R);return C?[...E,C]:E},[]);m.length>0&&s(T,{deleted:m})},b=w=>{const T=e.get(w.annotation);if(T){const m=T.bodies.find(E=>E.id===w.id);if(m){t.delete(m.id);const E={...T,bodies:T.bodies.filter(R=>R.id!==w.id)};return e.set(T.id,E),{oldValue:T,newValue:E,bodiesDeleted:[m]}}else console.warn(`Attempt to delete missing body ${w.id} from annotation ${w.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${w.annotation}`)},v=(w,T=oe.LOCAL)=>{const m=b(w);m&&s(T,{updated:[m]})},S=(w,T=oe.LOCAL)=>{const m=w.map(E=>b(E)).filter(Boolean);m.length>0&&s(T,{updated:m})},I=w=>{const T=e.get(w);return T?{...T}:void 0},N=w=>{const T=t.get(w);if(T){const m=I(T).bodies.find(E=>E.id===w);if(m)return m;console.error(`Store integrity error: body ${w} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${w}`)},P=(w,T)=>{if(w.annotation!==T.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const m=e.get(w.annotation);if(m){const E=m.bodies.find(C=>C.id===w.id),R={...m,bodies:m.bodies.map(C=>C.id===E.id?T:C)};return e.set(m.id,R),E.id!==T.id&&(t.delete(E.id),t.set(T.id,R.id)),{oldValue:m,newValue:R,bodiesUpdated:[{oldBody:E,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${w.annotation}`)},k=(w,T,m=oe.LOCAL)=>{const E=P(w,T);E&&s(m,{updated:[E]})},G=(w,T=oe.LOCAL)=>{const m=w.map(E=>P({id:E.id,annotation:E.annotation},E)).filter(Boolean);s(T,{updated:m})},z=w=>{const T=e.get(w.annotation);if(T){const m={...T,target:{...T.target,...w}};return e.set(T.id,m),{oldValue:T,newValue:m,targetUpdated:{oldTarget:T.target,newTarget:w}}}else console.warn(`Attempt to update target on missing annotation: ${w.annotation}`)};return{addAnnotation:r,addBody:d,all:p,bulkAddAnnotations:g,bulkDeleteAnnotations:M,bulkDeleteBodies:S,bulkUpdateAnnotations:h,bulkUpdateBodies:G,bulkUpdateTargets:(w,T=oe.LOCAL)=>{const m=w.map(E=>z(E)).filter(Boolean);m.length>0&&s(T,{updated:m})},bulkUpsertAnnotations:c,clear:y,deleteAnnotation:_,deleteBody:v,getAnnotation:I,getBody:N,observe:i,unobserve:o,updateAnnotation:a,updateBody:k,updateTarget:(w,T=oe.LOCAL)=>{const m=z(w);m&&s(T,{updated:[m]})},upsertAnnotation:u}},Es=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let bs=()=>({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 Ts=250,As=(e,t)=>{const n=bs(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const l=y=>{if(!s){const{changes:g}=y,O=performance.now();if(O-r>Ts)i.splice(o+1),i.push(g),o=i.length-1;else{const _=i.length-1;i[_]=_s(i[_],g)}r=O}s=!1};e.observe(l,{origin:oe.LOCAL});const a=y=>y&&y.length>0&&e.bulkDeleteAnnotations(y),u=y=>y&&y.length>0&&e.bulkAddAnnotations(y,!1),h=y=>y&&y.length>0&&e.bulkUpdateAnnotations(y.map(({oldValue:g})=>g)),c=y=>y&&y.length>0&&e.bulkUpdateAnnotations(y.map(({newValue:g})=>g)),d=y=>y&&y.length>0&&e.bulkAddAnnotations(y,!1),p=y=>y&&y.length>0&&e.bulkDeleteAnnotations(y);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...i],pointer:o}),on:(y,g)=>n.on(y,g),redo:()=>{if(i.length-1>o){s=!0;const{created:y,updated:g,deleted:O}=i[o+1];u(y),c(g),p(O),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:y,updated:g,deleted:O}=i[o];a(y),h(g),d(O),n.emit("undo",i[o]),o-=1}}}},Os=()=>{const{subscribe:e,set:t}=jt([]);return{subscribe:e,set:t}},Ms=(e,t,n,i)=>{const{hover:o,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],h,c;const d=(_,M)=>{a.has(_)?a.get(_).push(M):a.set(_,[M])},p=(_,M)=>{const b=a.get(_);if(b){const v=b.indexOf(M);v!==-1&&b.splice(v,1)}},y=(_,M,b)=>{a.has(_)&&setTimeout(()=>{a.get(_).forEach(v=>{if(n){const S=Array.isArray(M)?M.map(N=>n.serialize(N)):n.serialize(M),I=b?b instanceof PointerEvent?b:n.serialize(b):void 0;v(S,I)}else v(M,b)})},1)},g=()=>{const{selected:_}=s,M=(_||[]).map(({id:b})=>r.getAnnotation(b));M.forEach(b=>{const v=u.find(S=>S.id===b.id);(!v||!Xe(v,b))&&y("updateAnnotation",b,v)}),u=u.map(b=>M.find(({id:S})=>S===b.id)||b)};s.subscribe(({selected:_})=>{if(!(u.length===0&&_.length===0)){if(u.length===0&&_.length>0)u=_.map(({id:M})=>r.getAnnotation(M));else if(u.length>0&&_.length===0)u.forEach(M=>{const b=r.getAnnotation(M.id);b&&!Xe(b,M)&&y("updateAnnotation",b,M)}),u=[];else{const M=new Set(u.map(v=>v.id)),b=new Set(_.map(({id:v})=>v));u.filter(v=>!b.has(v.id)).forEach(v=>{const S=r.getAnnotation(v.id);S&&!Xe(S,v)&&y("updateAnnotation",S,v)}),u=[...u.filter(v=>b.has(v.id)),..._.filter(({id:v})=>!M.has(v)).map(({id:v})=>r.getAnnotation(v))]}y("selectionChanged",u)}}),o.subscribe(_=>{!h&&_?y("mouseEnterAnnotation",r.getAnnotation(_)):h&&!_?y("mouseLeaveAnnotation",r.getAnnotation(h)):h&&_&&(y("mouseLeaveAnnotation",r.getAnnotation(h)),y("mouseEnterAnnotation",r.getAnnotation(_))),h=_}),l==null||l.subscribe(_=>y("viewportIntersect",_.map(M=>r.getAnnotation(M)))),r.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(g,1e3));const{created:M,deleted:b}=_.changes;(M||[]).forEach(v=>y("createAnnotation",v)),(b||[]).forEach(v=>y("deleteAnnotation",v)),(_.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:S})=>{const I=u.find(N=>N.id===v.id)||v;u=u.map(N=>N.id===v.id?S:N),y("updateAnnotation",S,I)})},{origin:oe.LOCAL}),r.observe(_=>{if(u){const M=new Set(u.map(v=>v.id)),b=(_.changes.updated||[]).filter(({newValue:v})=>M.has(v.id)).map(({newValue:v})=>v);b.length>0&&(u=u.map(v=>b.find(I=>I.id===v.id)||v))}},{origin:oe.REMOTE});const O=_=>M=>{const{updated:b}=M;_?(b||[]).forEach(v=>y("updateAnnotation",v.oldValue,v.newValue)):(b||[]).forEach(v=>y("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",O(!0)),t.on("redo",O(!1)),{on:d,off:p,emit:y}},vs=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:[]}),Ss=(e,t,n)=>{const{store:i,selection:o}=e,s=_=>{if(n){const{parsed:M,error:b}=n.parse(_);M?i.addAnnotation(M,oe.REMOTE):console.error(b)}else i.addAnnotation(qt(_),oe.REMOTE)},r=()=>o.clear(),l=()=>i.clear(),a=_=>{const M=i.getAnnotation(_);return n&&M?n.serialize(M):M},u=()=>n?i.all().map(n.serialize):i.all(),h=()=>{var _;const M=(((_=o.selected)==null?void 0:_.map(b=>b.id))||[]).map(b=>i.getAnnotation(b)).filter(Boolean);return n?M.map(n.serialize):M},c=(_,M=!0)=>fetch(_).then(b=>b.json()).then(b=>(p(b,M),b)),d=_=>{if(typeof _=="string"){const M=i.getAnnotation(_);if(i.deleteAnnotation(_),M)return n?n.serialize(M):M}else{const M=n?n.parse(_).parsed:_;if(M)return i.deleteAnnotation(M),_}},p=(_,M=!0)=>{if(n){const b=n.parseAll||vs(n),{parsed:v,failed:S}=b(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(v,M,oe.REMOTE)}else i.bulkAddAnnotations(_.map(qt),M,oe.REMOTE)},y=(_,M)=>{_?o.setSelected(_,M):o.clear()},g=_=>{o.clear(),o.setUserSelectAction(_)},O=_=>{if(n){const M=n.parse(_).parsed,b=n.serialize(i.getAnnotation(M.id));return i.updateAnnotation(M),b}else{const M=i.getAnnotation(_.id);return i.updateAnnotation(qt(_)),M}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:h,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:y,setUserSelectAction:g,undo:t.undo,updateAnnotation:O}},Ns=(e,t,n)=>typeof t=="function"?t(e,n):t,Cs=(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||{}}},Is="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Rs=e=>crypto.getRandomValues(new Uint8Array(e)),Ls=(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 l=n(o),a=o|0;for(;a--;)if(r+=e[l[a]&i]||"",r.length>=s)return r}}},ks=(e,t=21)=>Ls(e,t|0,Rs),Ps=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Is[n[e]&63];return t};const Ds=()=>({isGuest:!0,id:ks("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Us=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}`},ti=e=>e?typeof e=="object"?{...e}:e:void 0,Hs=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:i,type:o,purpose:s,value:r,created:l,modified:a,creator:u,...h}=n;return{id:i||`temp-${Us(n)}`,annotation:t,type:o,purpose:s,value:r,creator:ti(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...h}}),Vs=e=>e.map(t=>{var n;const{annotation:i,created:o,updated:s,...r}=t,l={...r,created:o==null?void 0:o.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),Ys=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Bs=()=>{const e=[...Ys];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};Ps();const Xs=(e,t={strict:!0,invertY:!1})=>({parse:o=>ni(o,t),serialize:o=>ii(o,e,t)}),ni=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Wn(),{creator:i,created:o,modified:s,body:r,...l}=e,a=Hs(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"?Rn(h,t.invertY):(h==null?void 0:h.type)==="SvgSelector"?qn(h):void 0,d=Array.isArray(l.target)?l.target[0]:l.targret;return c||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:o?new Date(o):void 0,creator:ti(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:n,selector:c||h}}}:{error:Error(`Invalid selector: ${JSON.stringify(h)}`)}},ii=(e,t,n={strict:!0,invertY:!1})=>{const{selector:i,creator:o,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=i.type==ie.RECTANGLE?Ln(i.geometry):Zn(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:Vs(e.bodies),created:s==null?void 0:s.toISOString(),creator:o,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete h.bodies,"annotation"in h.target&&delete h.target.annotation,h},Ot=(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))},$e=[];function Fs(e,t=q){let n;const i=new Set;function o(l){if(ce(e,l)&&(e=l,n)){const a=!$e.length;for(const u of i)u[1](),$e.push(u,e);if(a){for(let u=0;u<$e.length;u+=2)$e[u][0]($e[u+1]);$e.length=0}}}function s(l){o(l(e))}function r(l,a=q){const u=[l,a];return i.add(u),i.size===1&&(n=t(o,s)||q),l(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const js=(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 l=r.target;t.setAttribute("viewBox",`0 0 ${l.naturalWidth} ${l.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${n} ${i}`)},oi=(e,t)=>{js(e,t);const{subscribe:n,set:i}=Fs(1);let o;return window.ResizeObserver&&(o=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);i(u)}),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:l}=n;let a="";return i&&(a+=`fill:${i};`,a+=`fill-opacity:${o||"0.25"};`),s&&(a+=`stroke:${s};`,a+=`stroke-width:${r||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}},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}},Ue=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Gs=e=>({}),si=e=>({grab:e[0]});function zs(e){let t,n,i,o;const s=e[8].default,r=uo(s,e,e[7],si);return{c(){t=L("g"),r&&r.c(),f(t,"class","a9s-annotation selected")},m(l,a){V(l,t,a),r&&r.m(t,null),n=!0,i||(o=[ee(t,"pointerup",e[2]),ee(t,"pointermove",e[1])],i=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&co(r,s,l,l[7],n?fo(s,l[7],a,Gs):ho(l[7]),si)},i(l){n||(B(r,l),n=!0)},o(l){F(r,l),n=!1},d(l){l&&H(t),r&&r.d(l),i=!1,Ie(o)}}}function Qs(e,t,n){let{$$slots:i={},$$scope:o}=t;const s=Ve();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,h,c,d;const p=O=>_=>{if(h=O,u){const{left:b,top:v}=u.getBoundingClientRect(),S=_.clientX-b,I=_.clientY-v;c=a.elementToImage(S,I)}else{const{offsetX:b,offsetY:v}=_;c=a.elementToImage(b,v)}d=r,_.target.setPointerCapture(_.pointerId),s("grab",_)},y=O=>{if(h){const[_,M]=a.elementToImage(O.offsetX,O.offsetY),b=[_-c[0],M-c[1]];n(3,r=l(d,h,b)),s("change",r)}},g=O=>{O.target.releasePointerCapture(O.pointerId),h=void 0,d=r,s("release",O)};return e.$$set=O=>{"shape"in O&&n(3,r=O.shape),"editor"in O&&n(4,l=O.editor),"transform"in O&&n(5,a=O.transform),"svgEl"in O&&n(6,u=O.svgEl),"$$scope"in O&&n(7,o=O.$$scope)},[p,y,g,r,l,a,u,o,i]}class Mt extends ve{constructor(t){super(),Me(this,t,Qs,zs,ce,{shape:3,editor:4,transform:5,svgEl:6})}}function qs(e){let t,n,i,o,s,r,l,a,u=e[3]&&ri(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),o=L("circle"),f(n,"class","a9s-handle-buffer"),f(n,"cx",e[0]),f(n,"cy",e[1]),f(n,"r",i=e[5]+6/e[2]),f(o,"class",s=`a9s-handle-dot${e[3]?" selected":""}`),f(o,"cx",e[0]),f(o,"cy",e[1]),f(o,"r",e[5]),f(t,"class",r=`a9s-handle ${e[8].class||""}`.trim())},m(h,c){V(h,t,c),K(t,n),u&&u.m(t,null),K(t,o),l||(a=[ee(n,"pointerenter",e[11]),ee(n,"pointerleave",e[12]),ee(n,"pointerdown",e[13]),ee(n,"pointerdown",e[6]),ee(n,"pointerup",e[14]),ee(n,"pointerup",e[7])],l=!0)},p(h,c){c&1&&f(n,"cx",h[0]),c&2&&f(n,"cy",h[1]),c&36&&i!==(i=h[5]+6/h[2])&&f(n,"r",i),h[3]?u?u.p(h,c):(u=ri(h),u.c(),u.m(t,o)):u&&(u.d(1),u=null),c&8&&s!==(s=`a9s-handle-dot${h[3]?" selected":""}`)&&f(o,"class",s),c&1&&f(o,"cx",h[0]),c&2&&f(o,"cy",h[1]),c&32&&f(o,"r",h[5]),c&256&&r!==(r=`a9s-handle ${h[8].class||""}`.trim())&&f(t,"class",r)},d(h){h&&H(t),u&&u.d(),l=!1,Ie(a)}}}function Zs(e){let t,n,i,o,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),o=L("circle"),r=L("circle"),f(n,"cx",e[0]),f(n,"cy",e[1]),f(n,"r",i=e[5]*10),f(n,"class","a9s-touch-halo"),Pe(n,"touched",e[4]),f(o,"cx",e[0]),f(o,"cy",e[1]),f(o,"r",s=e[5]+10/e[2]),f(o,"class","a9s-handle-buffer"),f(r,"class","a9s-handle-dot"),f(r,"cx",e[0]),f(r,"cy",e[1]),f(r,"r",l=e[5]+2/e[2]),f(t,"class","a9s-touch-handle")},m(h,c){V(h,t,c),K(t,n),K(t,o),K(t,r),a||(u=[ee(o,"pointerdown",e[9]),ee(o,"pointerup",e[10]),ee(o,"pointerdown",e[6]),ee(o,"pointerup",e[7])],a=!0)},p(h,c){c&1&&f(n,"cx",h[0]),c&2&&f(n,"cy",h[1]),c&32&&i!==(i=h[5]*10)&&f(n,"r",i),c&16&&Pe(n,"touched",h[4]),c&1&&f(o,"cx",h[0]),c&2&&f(o,"cy",h[1]),c&36&&s!==(s=h[5]+10/h[2])&&f(o,"r",s),c&1&&f(r,"cx",h[0]),c&2&&f(r,"cy",h[1]),c&36&&l!==(l=h[5]+2/h[2])&&f(r,"r",l)},d(h){h&&H(t),a=!1,Ie(u)}}}function ri(e){let t,n;return{c(){t=L("circle"),f(t,"class","a9s-handle-selected"),f(t,"cx",e[0]),f(t,"cy",e[1]),f(t,"r",n=e[5]+8/e[2])},m(i,o){V(i,t,o)},p(i,o){o&1&&f(t,"cx",i[0]),o&2&&f(t,"cy",i[1]),o&36&&n!==(n=i[5]+8/i[2])&&f(t,"r",n)},d(i){i&&H(t)}}}function Ks(e){let t;function n(s,r){return Ue?Zs:qs}let o=n()(e);return{c(){o.c(),t=Se()},m(s,r){o.m(s,r),V(s,t,r)},p(s,[r]){o.p(s,r)},i:q,o:q,d(s){s&&H(t),o.d(s)}}}function Ws(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=_=>{_.pointerType==="touch"&&n(4,a=!0)},h=()=>n(4,a=!1);function c(_){Ee.call(this,e,_)}function d(_){Ee.call(this,e,_)}function p(_){Ee.call(this,e,_)}function y(_){Ee.call(this,e,_)}function g(_){Ee.call(this,e,_)}function O(_){Ee.call(this,e,_)}return e.$$set=_=>{n(8,t=He(He({},t),mn(_))),"x"in _&&n(0,o=_.x),"y"in _&&n(1,s=_.y),"scale"in _&&n(2,r=_.scale),"selected"in _&&n(3,l=_.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,i=4/r)},t=mn(t),[o,s,r,l,a,i,u,h,t,c,d,p,y,g,O]}class Ze extends ve{constructor(t){super(),Me(this,t,Ws,Ks,ce,{x:0,y:1,scale:2,selected:3})}}function Js(e){let t,n,i,o,s,r,l;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(a,u){V(a,t,u),K(t,n),K(t,o),K(t,s),r||(l=[ee(n,"pointerdown",e[5]),ee(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&f(n,"cx",a[0]),u&2&&f(n,"cy",a[1]),u&4&&i!==(i=1.75*a[2])&&f(n,"r",i),u&1&&f(o,"cx",a[0]),u&2&&f(o,"cy",a[1]),u&4&&f(o,"r",a[2]),u&1&&f(s,"cx",a[0]),u&2&&f(s,"cy",a[1]),u&4&&f(s,"r",a[2])},d(a){a&&H(t),r=!1,Ie(l)}}}function xs(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){V(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&&H(t)}}}function $s(e){let t;function n(s,r){return Ue?xs:Js}let o=n()(e);return{c(){o.c(),t=Se()},m(s,r){o.m(s,r),V(s,t,r)},p(s,[r]){o.p(s,r)},i:q,o:q,d(s){s&&H(t),o.d(s)}}}function er(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){Ee.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,l,r,a]}class li extends ve{constructor(t){super(),Me(this,t,er,$s,ce,{x:0,y:1,scale:4})}}function Zt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function ai(e,t,n){const i=e.slice();return i[28]=t[n],i[30]=n,i}function Kt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Wt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function ui(e){let t,n,i,o;return{c(){t=L("circle"),f(t,"cx",n=e[28][0]),f(t,"cy",i=e[28][1]),f(t,"r",o=ct/e[3]),f(t,"class","svelte-1h2slbm")},m(s,r){V(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&f(t,"cx",n),r[0]&1088&&i!==(i=s[28][1])&&f(t,"cy",i),r[0]&8&&o!==(o=ct/s[3])&&f(t,"r",o)},d(s){s&&H(t)}}}function fi(e){let t,n,i,o,s,r,l,a,u,h;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),f(n,"x",i=e[9].x),f(n,"y",o=e[9].y),f(n,"width",s=e[9].w),f(n,"height",r=e[9].h),f(n,"class","svelte-1h2slbm"),f(l,"cx",a=e[28][0]),f(l,"cy",u=e[28][1]),f(l,"r",h=ct/e[3]),f(l,"class","svelte-1h2slbm"),f(t,"id",`${e[19]}-inner`),f(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(c,d){V(c,t,d),K(t,n),K(t,l)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&f(n,"x",i),d[0]&512&&o!==(o=c[9].y)&&f(n,"y",o),d[0]&512&&s!==(s=c[9].w)&&f(n,"width",s),d[0]&512&&r!==(r=c[9].h)&&f(n,"height",r),d[0]&1088&&a!==(a=c[28][0])&&f(l,"cx",a),d[0]&1088&&u!==(u=c[28][1])&&f(l,"cy",u),d[0]&8&&h!==(h=ct/c[3])&&f(l,"r",h)},d(c){c&&H(t)}}}function ci(e){let t,n;return t=new Ze({props:{class:"a9s-corner-handle",x:e[28][0],y:e[28][1],scale:e[3],selected:e[8].includes(e[30])}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[15]),t.$on("pointerdown",function(){re(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&32&&(s.x=e[28][0]),o[0]&32&&(s.y=e[28][1]),o[0]&8&&(s.scale=e[3]),o[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function hi(e){let t,n;return t=new li({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){re(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&1088&&(s.x=e[28][0]),o[0]&1088&&(s.y=e[28][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function tr(e){let t,n,i,o,s,r,l,a,u,h,c,d,p,y,g,O,_,M,b,v,S,I=e[6]!==void 0&&!e[7]&&ui(Wt(e)),N=e[6]!==void 0&&!e[7]&&fi(Kt(e)),P=Ne(e[5].points),k=[];for(let w=0;w<P.length;w+=1)k[w]=ci(ai(e,P,w));const G=w=>F(k[w],1,1,()=>{k[w]=null});let z=e[6]!==void 0&&!e[7]&&hi(Zt(e));return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),I&&I.c(),N&&N.c(),h=Oe(),c=L("polygon"),p=Oe(),y=L("polygon"),O=Oe();for(let w=0;w<k.length;w+=1)k[w].c();_=Oe(),z&&z.c(),M=Se(),f(i,"x",o=e[9].x),f(i,"y",s=e[9].y),f(i,"width",r=e[9].w),f(i,"height",l=e[9].h),f(i,"class","svelte-1h2slbm"),f(a,"points",u=e[5].points.map(di).join(" ")),f(a,"class","svelte-1h2slbm"),f(n,"id",`${e[19]}-outer`),f(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),f(c,"class","a9s-outer"),f(c,"mask",`url(#${e[19]}-outer)`),f(c,"points",d=e[5].points.map(gi).join(" ")),f(y,"class","a9s-inner a9s-shape-handle"),f(y,"mask",`url(#${e[19]}-inner)`),f(y,"style",e[1]),f(y,"points",g=e[5].points.map(pi).join(" "))},m(w,T){V(w,t,T),K(t,n),K(n,i),K(n,a),I&&I.m(n,null),N&&N.m(t,null),V(w,h,T),V(w,c,T),V(w,p,T),V(w,y,T),V(w,O,T);for(let m=0;m<k.length;m+=1)k[m]&&k[m].m(w,T);V(w,_,T),z&&z.m(w,T),V(w,M,T),b=!0,v||(S=[ee(c,"pointerup",e[14]),ee(c,"pointerdown",function(){re(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),ee(y,"pointermove",e[13]),ee(y,"pointerup",e[14]),ee(y,"pointerdown",function(){re(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],v=!0)},p(w,T){if(e=w,(!b||T[0]&512&&o!==(o=e[9].x))&&f(i,"x",o),(!b||T[0]&512&&s!==(s=e[9].y))&&f(i,"y",s),(!b||T[0]&512&&r!==(r=e[9].w))&&f(i,"width",r),(!b||T[0]&512&&l!==(l=e[9].h))&&f(i,"height",l),(!b||T[0]&32&&u!==(u=e[5].points.map(di).join(" ")))&&f(a,"points",u),e[6]!==void 0&&!e[7]?I?I.p(Wt(e),T):(I=ui(Wt(e)),I.c(),I.m(n,null)):I&&(I.d(1),I=null),e[6]!==void 0&&!e[7]?N?N.p(Kt(e),T):(N=fi(Kt(e)),N.c(),N.m(t,null)):N&&(N.d(1),N=null),(!b||T[0]&32&&d!==(d=e[5].points.map(gi).join(" ")))&&f(c,"points",d),(!b||T[0]&2)&&f(y,"style",e[1]),(!b||T[0]&32&&g!==(g=e[5].points.map(pi).join(" ")))&&f(y,"points",g),T[0]&134322472){P=Ne(e[5].points);let m;for(m=0;m<P.length;m+=1){const E=ai(e,P,m);k[m]?(k[m].p(E,T),B(k[m],1)):(k[m]=ci(E),k[m].c(),B(k[m],1),k[m].m(_.parentNode,_))}for(be(),m=P.length;m<k.length;m+=1)G(m);Te()}e[6]!==void 0&&!e[7]?z?(z.p(Zt(e),T),T[0]&192&&B(z,1)):(z=hi(Zt(e)),z.c(),B(z,1),z.m(M.parentNode,M)):z&&(be(),F(z,1,1,()=>{z=null}),Te())},i(w){if(!b){for(let T=0;T<P.length;T+=1)B(k[T]);B(z),b=!0}},o(w){k=k.filter(Boolean);for(let T=0;T<k.length;T+=1)F(k[T]);F(z),b=!1},d(w){w&&(H(t),H(h),H(c),H(p),H(y),H(O),H(_),H(M)),I&&I.d(),N&&N.d(),Ge(k,w),z&&z.d(w),v=!1,Ie(S)}}}function nr(e){let t,n;return t=new Mt({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[tr,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){pe(t.$$.fragment)},m(i,o){de(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]&134219754|o[1]&1&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}const ir=250,or=1e3,sr=12,ct=4.5,di=e=>e.join(","),gi=e=>e.join(","),pi=e=>e.join(",");function rr(e,t,n){let i,o,s;const r=Ve();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:h=1}=t,{svgEl:c}=t,d,p=!1,y,g=[];const O=()=>n(7,p=!0),_=()=>n(7,p=!1),M=m=>{if(g.length>0||!o.some(W=>W.visible)){n(6,d=void 0);return}const[E,R]=u.elementToImage(m.offsetX,m.offsetY),C=W=>Math.pow(W[0]-E,2)+Math.pow(W[1]-R,2),U=i.points.reduce((W,J)=>C(J)<C(W)?J:W),Q=o.filter(W=>W.visible).reduce((W,J)=>C(J.point)<C(W.point)?J:W),j=Math.pow(or/h,2);C(U)<j||C(Q.point)<j?n(6,d=o.indexOf(Q)):n(6,d=void 0)},b=()=>{document.activeElement!==c&&c.focus()},v=()=>{n(8,g=[]),b()},S=m=>{n(7,p=!0),m.preventDefault(),m.stopPropagation(),y=performance.now()},I=m=>E=>{if(!y||Ue||performance.now()-y>ir)return;const R=g.includes(m);E.metaKey||E.ctrlKey||E.shiftKey?R?n(8,g=g.filter(C=>C!==m)):n(8,g=[...g,m]):R&&g.length>1?n(8,g=[m]):R?n(8,g=[]):n(8,g=[m]),b()},N=(m,E,R)=>{b();let C;const U=m.geometry;g.length>1?C=U.points.map(([j,x],W)=>g.includes(W)?[j+R[0],x+R[1]]:[j,x]):E==="SHAPE"?C=U.points.map(([j,x])=>[j+R[0],x+R[1]]):C=U.points.map(([j,x],W)=>E===`HANDLE-${W}`?[j+R[0],x+R[1]]:[j,x]);const Q=ye(C);return{...m,geometry:{points:C,bounds:Q}}},P=m=>async E=>{E.stopPropagation();const R=[...i.points.slice(0,m+1),o[m].point,...i.points.slice(m+1)],C=ye(R);r("change",{...l,geometry:{points:R,bounds:C}}),await On();const U=[...document.querySelectorAll(".a9s-handle")][m+1];if(U!=null&&U.firstChild){const Q=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:E.clientX,clientY:E.clientY,pointerId:E.pointerId,pointerType:E.pointerType,isPrimary:E.isPrimary,buttons:E.buttons});U.firstChild.dispatchEvent(Q)}},k=()=>{if(i.points.length<4)return;const m=i.points.filter((R,C)=>!g.includes(C)),E=ye(m);r("change",{...l,geometry:{points:m,bounds:E}}),n(8,g=[])};ze(()=>{if(Ue)return;const m=E=>{(E.key==="Delete"||E.key==="Backspace")&&(E.preventDefault(),k())};return c.addEventListener("pointermove",M),c.addEventListener("keydown",m),()=>{c.removeEventListener("pointermove",M),c.removeEventListener("keydown",m)}});const G=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function z(m){Ee.call(this,e,m)}function w(m){Ee.call(this,e,m)}function T(m){Ee.call(this,e,m)}return e.$$set=m=>{"shape"in m&&n(0,l=m.shape),"computedStyle"in m&&n(1,a=m.computedStyle),"transform"in m&&n(2,u=m.transform),"viewportScale"in m&&n(3,h=m.viewportScale),"svgEl"in m&&n(4,c=m.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=l.geometry),e.$$.dirty[0]&40&&n(10,o=Ue?[]:i.points.map((m,E)=>{const R=E===i.points.length-1?i.points[0]:i.points[E+1],C=(m[0]+R[0])/2,U=(m[1]+R[1])/2,j=Math.sqrt(Math.pow(R[0]-C,2)+Math.pow(R[1]-U,2))>sr/h;return{point:[C,U],visible:j}})),e.$$.dirty[0]&40&&n(9,s=ft(i.bounds,ct/h))},[l,a,u,h,c,i,d,p,g,s,o,O,_,M,v,S,I,N,P,G,z,w,T]}class yi extends ve{constructor(t){super(),Me(this,t,rr,nr,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function lr(e){let t,n,i,o,s,r,l,a,u,h,c,d,p,y,g,O,_,M,b,v,S,I,N,P,k,G,z,w,T,m,E,R,C,U,Q,j,x,W,J,ae,le,Ce,ke,X,he,te,we,Ae,nt,Fe,hn,je,$,dn,lo;return te=new Ze({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){re(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),Ae=new Ze({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),Ae.$on("pointerdown",function(){re(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),Fe=new Ze({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),Fe.$on("pointerdown",function(){re(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),je=new Ze({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),je.$on("pointerdown",function(){re(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("rect"),p=Oe(),y=L("rect"),b=Oe(),v=L("rect"),k=Oe(),G=L("rect"),m=Oe(),E=L("rect"),Q=Oe(),j=L("rect"),ae=Oe(),le=L("rect"),he=Oe(),pe(te.$$.fragment),we=Oe(),pe(Ae.$$.fragment),nt=Oe(),pe(Fe.$$.fragment),hn=Oe(),pe(je.$$.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",l=e[6].h),f(a,"class","rect-mask-fg svelte-1njczvj"),f(a,"x",u=e[5].x),f(a,"y",h=e[5].y),f(a,"width",c=e[5].w),f(a,"height",d=e[5].h),f(n,"id",e[8]),f(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),f(y,"class","a9s-outer"),f(y,"mask",`url(#${e[8]})`),f(y,"x",g=e[5].x),f(y,"y",O=e[5].y),f(y,"width",_=e[5].w),f(y,"height",M=e[5].h),f(v,"class","a9s-inner a9s-shape-handle"),f(v,"style",e[1]),f(v,"x",S=e[5].x),f(v,"y",I=e[5].y),f(v,"width",N=e[5].w),f(v,"height",P=e[5].h),f(G,"class","a9s-edge-handle a9s-edge-handle-top"),f(G,"x",z=e[5].x),f(G,"y",w=e[5].y),f(G,"height",1),f(G,"width",T=e[5].w),f(E,"class","a9s-edge-handle a9s-edge-handle-right"),f(E,"x",R=e[5].x+e[5].w),f(E,"y",C=e[5].y),f(E,"height",U=e[5].h),f(E,"width",1),f(j,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(j,"x",x=e[5].x),f(j,"y",W=e[5].y+e[5].h),f(j,"height",1),f(j,"width",J=e[5].w),f(le,"class","a9s-edge-handle a9s-edge-handle-left"),f(le,"x",Ce=e[5].x),f(le,"y",ke=e[5].y),f(le,"height",X=e[5].h),f(le,"width",1)},m(Z,Y){V(Z,t,Y),K(t,n),K(n,i),K(n,a),V(Z,p,Y),V(Z,y,Y),V(Z,b,Y),V(Z,v,Y),V(Z,k,Y),V(Z,G,Y),V(Z,m,Y),V(Z,E,Y),V(Z,Q,Y),V(Z,j,Y),V(Z,ae,Y),V(Z,le,Y),V(Z,he,Y),de(te,Z,Y),V(Z,we,Y),de(Ae,Z,Y),V(Z,nt,Y),de(Fe,Z,Y),V(Z,hn,Y),de(je,Z,Y),$=!0,dn||(lo=[ee(y,"pointerdown",function(){re(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(v,"pointerdown",function(){re(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(G,"pointerdown",function(){re(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),ee(E,"pointerdown",function(){re(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),ee(j,"pointerdown",function(){re(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),ee(le,"pointerdown",function(){re(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],dn=!0)},p(Z,Y){e=Z,(!$||Y&64&&o!==(o=e[6].x))&&f(i,"x",o),(!$||Y&64&&s!==(s=e[6].y))&&f(i,"y",s),(!$||Y&64&&r!==(r=e[6].w))&&f(i,"width",r),(!$||Y&64&&l!==(l=e[6].h))&&f(i,"height",l),(!$||Y&32&&u!==(u=e[5].x))&&f(a,"x",u),(!$||Y&32&&h!==(h=e[5].y))&&f(a,"y",h),(!$||Y&32&&c!==(c=e[5].w))&&f(a,"width",c),(!$||Y&32&&d!==(d=e[5].h))&&f(a,"height",d),(!$||Y&32&&g!==(g=e[5].x))&&f(y,"x",g),(!$||Y&32&&O!==(O=e[5].y))&&f(y,"y",O),(!$||Y&32&&_!==(_=e[5].w))&&f(y,"width",_),(!$||Y&32&&M!==(M=e[5].h))&&f(y,"height",M),(!$||Y&2)&&f(v,"style",e[1]),(!$||Y&32&&S!==(S=e[5].x))&&f(v,"x",S),(!$||Y&32&&I!==(I=e[5].y))&&f(v,"y",I),(!$||Y&32&&N!==(N=e[5].w))&&f(v,"width",N),(!$||Y&32&&P!==(P=e[5].h))&&f(v,"height",P),(!$||Y&32&&z!==(z=e[5].x))&&f(G,"x",z),(!$||Y&32&&w!==(w=e[5].y))&&f(G,"y",w),(!$||Y&32&&T!==(T=e[5].w))&&f(G,"width",T),(!$||Y&32&&R!==(R=e[5].x+e[5].w))&&f(E,"x",R),(!$||Y&32&&C!==(C=e[5].y))&&f(E,"y",C),(!$||Y&32&&U!==(U=e[5].h))&&f(E,"height",U),(!$||Y&32&&x!==(x=e[5].x))&&f(j,"x",x),(!$||Y&32&&W!==(W=e[5].y+e[5].h))&&f(j,"y",W),(!$||Y&32&&J!==(J=e[5].w))&&f(j,"width",J),(!$||Y&32&&Ce!==(Ce=e[5].x))&&f(le,"x",Ce),(!$||Y&32&&ke!==(ke=e[5].y))&&f(le,"y",ke),(!$||Y&32&&X!==(X=e[5].h))&&f(le,"height",X);const Nt={};Y&32&&(Nt.x=e[5].x),Y&32&&(Nt.y=e[5].y),Y&8&&(Nt.scale=e[3]),te.$set(Nt);const Ct={};Y&32&&(Ct.x=e[5].x+e[5].w),Y&32&&(Ct.y=e[5].y),Y&8&&(Ct.scale=e[3]),Ae.$set(Ct);const It={};Y&32&&(It.x=e[5].x+e[5].w),Y&32&&(It.y=e[5].y+e[5].h),Y&8&&(It.scale=e[3]),Fe.$set(It);const Rt={};Y&32&&(Rt.x=e[5].x),Y&32&&(Rt.y=e[5].y+e[5].h),Y&8&&(Rt.scale=e[3]),je.$set(Rt)},i(Z){$||(B(te.$$.fragment,Z),B(Ae.$$.fragment,Z),B(Fe.$$.fragment,Z),B(je.$$.fragment,Z),$=!0)},o(Z){F(te.$$.fragment,Z),F(Ae.$$.fragment,Z),F(Fe.$$.fragment,Z),F(je.$$.fragment,Z),$=!1},d(Z){Z&&(H(t),H(p),H(y),H(b),H(v),H(k),H(G),H(m),H(E),H(Q),H(j),H(ae),H(le),H(he),H(we),H(nt),H(hn)),ge(te,Z),ge(Ae,Z),ge(Fe,Z),ge(je,Z),dn=!1,Ie(lo)}}}function ar(e){let t,n;return t=new Mt({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[lr,({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){de(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function ur(e,t,n){let i,o,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const h=(g,O,_)=>{const M=g.geometry.bounds;let[b,v]=[M.minX,M.minY],[S,I]=[M.maxX,M.maxY];const[N,P]=_;if(O==="SHAPE")b+=N,S+=N,v+=P,I+=P;else{switch(O){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{v+=P;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{I+=P;break}}switch(O){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{b+=N;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=N;break}}}const k=Math.min(b,S),G=Math.min(v,I),z=Math.abs(S-b),w=Math.abs(I-v);return{...g,geometry:{x:k,y:G,w:z,h:w,bounds:{minX:k,minY:G,maxX:k+z,maxY:G+w}}}},c=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(g){Ee.call(this,e,g)}function p(g){Ee.call(this,e,g)}function y(g){Ee.call(this,e,g)}return e.$$set=g=>{"shape"in g&&n(0,s=g.shape),"computedStyle"in g&&n(1,r=g.computedStyle),"transform"in g&&n(2,l=g.transform),"viewportScale"in g&&n(3,a=g.viewportScale),"svgEl"in g&&n(4,u=g.svgEl)},e.$$.update=()=>{e.$$.dirty&1&&n(5,i=s.geometry),e.$$.dirty&40&&n(6,o=ft(i.bounds,2/a))},[s,r,l,a,u,i,o,h,c,d,p,y]}class _i extends ve{constructor(t){super(),Me(this,t,ur,ar,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var mi=Object.prototype.hasOwnProperty;function Jt(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--&&Jt(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(mi.call(e,n)&&++i&&!mi.call(t,n)||!(n in t)||!Jt(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}const fr=12,cr=(e,t)=>e.polygons.reduce((n,i,o)=>{const s=i.rings.reduce((r,l,a)=>{const u=l.points.map((h,c)=>{const d=c===l.points.length-1?l.points[0]:l.points[c+1],p=(h[0]+d[0])/2,y=(h[1]+d[1])/2,O=Math.sqrt(Math.pow(d[0]-p,2)+Math.pow(d[1]-y,2))>fr/t;return{point:[p,y],visible:O,elementIdx:o,ringIdx:a,pointIdx:c}});return[...r,...u]},[]);return[...n,...s]},[]);function xt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function wi(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function Ei(e,t,n){const i=e.slice();return i[33]=t[n],i[35]=n,i}function bi(e,t,n){const i=e.slice();return i[29]=t[n],i[37]=n,i}function $t(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function en(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function Ti(e){let t,n,i,o;return{c(){t=L("circle"),f(t,"cx",n=e[29][0]),f(t,"cy",i=e[29][1]),f(t,"r",o=ht/e[3]),f(t,"class","svelte-1vxo6dc")},m(s,r){V(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&f(t,"cx",n),r[0]&1088&&i!==(i=s[29][1])&&f(t,"cy",i),r[0]&8&&o!==(o=ht/s[3])&&f(t,"r",o)},d(s){s&&H(t)}}}function Ai(e){let t,n,i,o,s,r,l,a,u,h;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),f(n,"x",i=e[9].x),f(n,"y",o=e[9].y),f(n,"width",s=e[9].w),f(n,"height",r=e[9].h),f(n,"class","svelte-1vxo6dc"),f(l,"cx",a=e[29][0]),f(l,"cy",u=e[29][1]),f(l,"r",h=ht/e[3]),f(l,"class","svelte-1vxo6dc"),f(t,"id",`${e[18]}-${e[32]}-inner`),f(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(c,d){V(c,t,d),K(t,n),K(t,l)},p(c,d){d[0]&512&&i!==(i=c[9].x)&&f(n,"x",i),d[0]&512&&o!==(o=c[9].y)&&f(n,"y",o),d[0]&512&&s!==(s=c[9].w)&&f(n,"width",s),d[0]&512&&r!==(r=c[9].h)&&f(n,"height",r),d[0]&1088&&a!==(a=c[29][0])&&f(l,"cx",a),d[0]&1088&&u!==(u=c[29][1])&&f(l,"cy",u),d[0]&8&&h!==(h=ht/c[3])&&f(l,"r",h)},d(c){c&&H(t)}}}function Oi(e){let t,n;function i(...o){return e[19](e[32],e[35],e[37],...o)}return t=new Ze({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(i)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){re(e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`))&&e[28](`HANDLE-${e[32]}-${e[35]}-${e[37]}`).apply(this,arguments)}),t.$on("pointerup",e[15](e[32],e[35],e[37])),{c(){pe(t.$$.fragment)},m(o,s){de(t,o,s),n=!0},p(o,s){e=o;const r={};s[0]&32&&(r.x=e[29][0]),s[0]&32&&(r.y=e[29][1]),s[0]&8&&(r.scale=e[3]),s[0]&256&&(r.selected=e[8].some(i)),t.$set(r)},i(o){n||(B(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){ge(t,o)}}}function Mi(e){let t,n,i=Ne(e[33].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=Oi(bi(e,i,r));const s=r=>F(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Se()},m(r,l){for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(r,l);V(r,t,l),n=!0},p(r,l){if(l[0]&268491048){i=Ne(r[33].points);let a;for(a=0;a<i.length;a+=1){const u=bi(r,i,a);o[a]?(o[a].p(u,l),B(o[a],1)):(o[a]=Oi(u),o[a].c(),B(o[a],1),o[a].m(t.parentNode,t))}for(be(),a=i.length;a<o.length;a+=1)s(a);Te()}},i(r){if(!n){for(let l=0;l<i.length;l+=1)B(o[l]);n=!0}},o(r){o=o.filter(Boolean);for(let l=0;l<o.length;l+=1)F(o[l]);n=!1},d(r){r&&H(t),Ge(o,r)}}}function vi(e){let t,n,i,o,s,r,l,a,u,h,c,d,p,y,g,O,_,M=e[6]!==void 0&&!e[7]&&Ti(en(e)),b=e[6]!==void 0&&!e[7]&&Ai($t(e)),v=Ne(e[30].rings),S=[];for(let N=0;N<v.length;N+=1)S[N]=Mi(Ei(e,v,N));const I=N=>F(S[N],1,1,()=>{S[N]=null});return{c(){t=L("g"),n=L("defs"),i=L("mask"),o=L("rect"),u=L("path"),M&&M.c(),b&&b.c(),c=L("path"),p=L("path");for(let N=0;N<S.length;N+=1)S[N].c();f(o,"x",s=e[9].x),f(o,"y",r=e[9].y),f(o,"width",l=e[9].w),f(o,"height",a=e[9].h),f(o,"class","svelte-1vxo6dc"),f(u,"d",h=De(e[30])),f(u,"class","svelte-1vxo6dc"),f(i,"id",`${e[18]}-${e[32]}-outer`),f(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),f(c,"class","a9s-outer"),f(c,"mask",`url(#${e[18]}-${e[32]}-outer)`),f(c,"fill-rule","evenodd"),f(c,"d",d=De(e[30])),f(p,"class","a9s-inner"),f(p,"mask",`url(#${e[18]}-${e[32]}-inner)`),f(p,"style",e[1]),f(p,"fill-rule","evenodd"),f(p,"d",y=De(e[30]))},m(N,P){V(N,t,P),K(t,n),K(n,i),K(i,o),K(i,u),M&&M.m(i,null),b&&b.m(n,null),K(t,c),K(t,p);for(let k=0;k<S.length;k+=1)S[k]&&S[k].m(t,null);g=!0,O||(_=[ee(c,"pointerup",e[13]),ee(c,"pointerdown",function(){re(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),ee(p,"pointerup",e[13]),ee(p,"pointerdown",function(){re(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],O=!0)},p(N,P){if(e=N,(!g||P[0]&512&&s!==(s=e[9].x))&&f(o,"x",s),(!g||P[0]&512&&r!==(r=e[9].y))&&f(o,"y",r),(!g||P[0]&512&&l!==(l=e[9].w))&&f(o,"width",l),(!g||P[0]&512&&a!==(a=e[9].h))&&f(o,"height",a),(!g||P[0]&32&&h!==(h=De(e[30])))&&f(u,"d",h),e[6]!==void 0&&!e[7]?M?M.p(en(e),P):(M=Ti(en(e)),M.c(),M.m(i,null)):M&&(M.d(1),M=null),e[6]!==void 0&&!e[7]?b?b.p($t(e),P):(b=Ai($t(e)),b.c(),b.m(n,null)):b&&(b.d(1),b=null),(!g||P[0]&32&&d!==(d=De(e[30])))&&f(c,"d",d),(!g||P[0]&2)&&f(p,"style",e[1]),(!g||P[0]&32&&y!==(y=De(e[30])))&&f(p,"d",y),P[0]&268491048){v=Ne(e[30].rings);let k;for(k=0;k<v.length;k+=1){const G=Ei(e,v,k);S[k]?(S[k].p(G,P),B(S[k],1)):(S[k]=Mi(G),S[k].c(),B(S[k],1),S[k].m(t,null))}for(be(),k=v.length;k<S.length;k+=1)I(k);Te()}},i(N){if(!g){for(let P=0;P<v.length;P+=1)B(S[P]);g=!0}},o(N){S=S.filter(Boolean);for(let P=0;P<S.length;P+=1)F(S[P]);g=!1},d(N){N&&H(t),M&&M.d(),b&&b.d(),Ge(S,N),O=!1,Ie(_)}}}function Si(e){let t,n;return t=new li({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){re(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){de(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&1088&&(s.x=e[29][0]),o[0]&1088&&(s.y=e[29][1]),o[0]&8&&(s.scale=e[3]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function hr(e){let t,n,i,o=Ne(e[5].polygons),s=[];for(let a=0;a<o.length;a+=1)s[a]=vi(wi(e,o,a));const r=a=>F(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&Si(xt(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=Oe(),l&&l.c(),n=Se()},m(a,u){for(let h=0;h<s.length;h+=1)s[h]&&s[h].m(a,u);V(a,t,u),l&&l.m(a,u),V(a,n,u),i=!0},p(a,u){if(u[0]&268763114){o=Ne(a[5].polygons);let h;for(h=0;h<o.length;h+=1){const c=wi(a,o,h);s[h]?(s[h].p(c,u),B(s[h],1)):(s[h]=vi(c),s[h].c(),B(s[h],1),s[h].m(t.parentNode,t))}for(be(),h=o.length;h<s.length;h+=1)r(h);Te()}a[6]!==void 0&&!a[7]?l?(l.p(xt(a),u),u[0]&192&&B(l,1)):(l=Si(xt(a)),l.c(),B(l,1),l.m(n.parentNode,n)):l&&(be(),F(l,1,1,()=>{l=null}),Te())},i(a){if(!i){for(let u=0;u<o.length;u+=1)B(s[u]);B(l),i=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)F(s[u]);F(l),i=!1},d(a){a&&(H(t),H(n)),Ge(s,a),l&&l.d(a)}}}function dr(e){let t,n;return t=new Mt({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[hr,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){pe(t.$$.fragment)},m(i,o){de(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]&268437482|o[1]&128&&(s.$$scope={dirty:o,ctx:i}),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}const gr=250,pr=1e3,ht=4.5;function yr(e,t,n){let i,o,s;const r=Ve();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:h=1}=t,{svgEl:c}=t,d,p=!1,y,g=[];const O=()=>n(7,p=!0),_=()=>n(7,p=!1),M=E=>{if(g.length>0||!o.some(J=>J.visible)){n(6,d=void 0);return}const[R,C]=u.elementToImage(E.offsetX,E.offsetY),U=J=>Math.pow(J[0]-R,2)+Math.pow(J[1]-C,2),Q=Cn(i).reduce((J,ae)=>U(ae)<U(J)?ae:J),j=o.filter(J=>J.visible).reduce((J,ae)=>U(ae.point)<U(J.point)?ae:J),x=Math.pow(pr/h,2);U(Q)<x||U(j.point)<x?n(6,d=o.indexOf(j)):n(6,d=void 0)},b=()=>{document.activeElement!==c&&c.focus()},v=()=>{n(8,g=[]),b()},S=E=>{n(7,p=!0),E.preventDefault(),E.stopPropagation(),y=performance.now()},I=(E,R,C)=>U=>{if(!y||Ue||performance.now()-y>gr)return;const Q=x=>x.polygon===E&&x.ring===R&&x.point===C,j=g.some(Q);U.metaKey||U.ctrlKey||U.shiftKey?j?n(8,g=g.filter(x=>!Q(x))):n(8,g=[...g,{polygon:E,ring:R,point:C}]):j&&g.length>1?n(8,g=[{polygon:E,ring:R,point:C}]):j?n(8,g=[]):n(8,g=[{polygon:E,ring:R,point:C}]),b()},N=(E,R,C)=>{b();const U=E.geometry.polygons;let Q;if(R==="SHAPE")Q=U.map(j=>{const x=j.rings.map((J,ae)=>({points:J.points.map((Ce,ke)=>[Ce[0]+C[0],Ce[1]+C[1]])})),W=ye(x[0].points);return{rings:x,bounds:W}});else{const[j,x,W,J]=R.split("-").map(ae=>parseInt(ae));Q=U.map((ae,le)=>{if(le===x){const Ce=ae.rings.map((X,he)=>he===W?{points:X.points.map((we,Ae)=>Ae===J?[we[0]+C[0],we[1]+C[1]]:we)}:X),ke=ye(Ce[0].points);return{rings:Ce,bounds:ke}}else return ae})}return{...E,geometry:{polygons:Q,bounds:rt(Q)}}},P=E=>async R=>{R.stopPropagation();const C=o[E],U=i.polygons.map((j,x)=>{if(x===C.elementIdx){const W=j.rings.map((ae,le)=>le===C.ringIdx?{points:[...ae.points.slice(0,C.pointIdx+1),C.point,...ae.points.slice(C.pointIdx+1)]}:ae),J=ye(W[0].points);return{rings:W,bounds:J}}else return j});r("change",{...l,geometry:{polygons:U,bounds:rt(U)}}),await On();const Q=[...document.querySelectorAll(".a9s-handle")][E+1];if(Q!=null&&Q.firstChild){const j=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:R.clientX,clientY:R.clientY,pointerId:R.pointerId,pointerType:R.pointerType,isPrimary:R.isPrimary,buttons:R.buttons});Q.firstChild.dispatchEvent(j)}},k=()=>{const E=i.polygons.map((C,U)=>{if(g.some(j=>j.polygon===U)){const j=C.rings.map((W,J)=>g.some(le=>le.polygon===U&&le.ring===J)&&W.points.length>3?{points:W.points.filter((Ce,ke)=>!g.some(X=>X.polygon===U&&X.ring===J&&X.point===ke))}:W),x=ye(j[0].points);return{rings:j,bounds:x}}else return C});!Jt(i.polygons,E)&&(r("change",{...l,geometry:{polygons:E,bounds:rt(E)}}),n(8,g=[]))};ze(()=>{if(Ue)return;const E=R=>{(R.key==="Delete"||R.key==="Backspace")&&(R.preventDefault(),k())};return c.addEventListener("pointermove",M),c.addEventListener("keydown",E),()=>{c.removeEventListener("pointermove",M),c.removeEventListener("keydown",E)}});const G=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,z=(E,R,C,{polygon:U,ring:Q,point:j})=>U===E&&Q===R&&j===C;function w(E){Ee.call(this,e,E)}function T(E){Ee.call(this,e,E)}function m(E){Ee.call(this,e,E)}return e.$$set=E=>{"shape"in E&&n(0,l=E.shape),"computedStyle"in E&&n(1,a=E.computedStyle),"transform"in E&&n(2,u=E.transform),"viewportScale"in E&&n(3,h=E.viewportScale),"svgEl"in E&&n(4,c=E.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,i=l.geometry),e.$$.dirty[0]&40&&n(10,o=Ue?[]:cr(i,h)),e.$$.dirty[0]&40&&n(9,s=ft(i.bounds,ht/h))},[l,a,u,h,c,i,d,p,g,s,o,O,_,v,S,I,N,P,G,z,w,T,m]}class _r extends ve{constructor(t){super(),Me(this,t,yr,dr,ce,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Ni=new Map([[ie.RECTANGLE,_i],[ie.POLYGON,yi],[ie.MULTIPOLYGLON,_r]]),Ci=e=>Ni.get(e.type),Ii=(e,t)=>Ni.set(e,t);function mr(e,t,n){let i;const o=Ve();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:h}=t,c;return ze(()=>(n(6,c=new r({target:a,props:{shape:s.target.selector,computedStyle:i,transform:u,viewportScale:h,svgEl:a.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,l=d.style),"target"in d&&n(3,a=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=ut(s,l)),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,l,a,u,h,c,i]}class Ri extends ve{constructor(t){super(),Me(this,t,mr,null,ce,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function wr(e,t,n){const i=Ve();let{drawingMode:o}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return ze(()=>{const h=s.closest("svg"),c=[],d=(p,y,g)=>{h==null||h.addEventListener(p,y,g),c.push(()=>h==null?void 0:h.removeEventListener(p,y,g))};return n(5,u=new r({target:s,props:{addEventListener:d,drawingMode:o,transform:l,viewportScale:a}})),u.$on("create",p=>i("create",p.detail)),()=>{c.forEach(p=>p()),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,l=h.transform),"viewportScale"in h&&n(4,a=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[o,s,r,l,a,u]}class Li extends ve{constructor(t){super(),Me(this,t,wr,null,ce,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function ki(e){let t,n,i,o,s,r,l,a,u,h;return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=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",l=e[4]+2*e[5]),f(a,"class","rect-mask-fg svelte-1a76qe7"),f(a,"x",e[1]),f(a,"y",e[2]),f(a,"width",e[3]),f(a,"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){V(c,t,d),K(t,n),K(n,i),K(n,a),V(c,u,d),V(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&&l!==(l=c[4]+2*c[5])&&f(i,"height",l),d&2&&f(a,"x",c[1]),d&4&&f(a,"y",c[2]),d&8&&f(a,"width",c[3]),d&16&&f(a,"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&&(H(t),H(u),H(h))}}}function Er(e){let t,n=e[0]&&ki(e);return{c(){t=L("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(i,o){V(i,t,o),n&&n.m(t,null)},p(i,[o]){i[0]?n?n.p(i,o):(n=ki(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&H(t),n&&n.d()}}}function br(e,t,n){let i;const o=Ve();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,h,c,d,p,y,g;const O=S=>{const I=S;u=performance.now(),r==="drag"&&(n(0,h=l.elementToImage(I.offsetX,I.offsetY)),c=h,n(1,d=h[0]),n(2,p=h[1]),n(3,y=1),n(4,g=1))},_=S=>{const I=S;h&&(c=l.elementToImage(I.offsetX,I.offsetY),n(1,d=Math.min(c[0],h[0])),n(2,p=Math.min(c[1],h[1])),n(3,y=Math.abs(c[0]-h[0])),n(4,g=Math.abs(c[1]-h[1])))},M=S=>{const I=S,N=performance.now()-u;if(r==="click"){if(N>300)return;h?b():(n(0,h=l.elementToImage(I.offsetX,I.offsetY)),c=h,n(1,d=h[0]),n(2,p=h[1]),n(3,y=1),n(4,g=1))}else h&&(N>300||y*g>100?(I.stopPropagation(),b()):(n(0,h=void 0),c=void 0))},b=()=>{if(y*g>15){const S={type:ie.RECTANGLE,geometry:{bounds:{minX:d,minY:p,maxX:d+y,maxY:p+g},x:d,y:p,w:y,h:g}};o("create",S)}n(0,h=void 0),c=void 0};ze(()=>{s("pointerdown",O),s("pointermove",_),s("pointerup",M,!0)});const v=`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,l=S.transform),"viewportScale"in S&&n(10,a=S.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,i=2/a)},[h,d,p,y,g,i,v,s,r,l,a]}class Pi extends ve{constructor(t){super(),Me(this,t,br,Er,ce,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function tn(e){const t=e.slice(),n=t[2].map(i=>i.join(",")).join(" ");return t[19]=n,t}function Di(e){let t,n,i,o,s,r,l,a,u,h,c,d,p,y,g=e[1]&&Ui(e);return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),h=L("polygon"),d=L("polygon"),g&&g.c(),y=Se(),f(i,"x",o=e[3].x),f(i,"y",s=e[3].y),f(i,"width",r=e[3].w),f(i,"height",l=e[3].h),f(i,"class","svelte-18wrg3t"),f(a,"points",u=e[19]),f(a,"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",p=e[19])},m(O,_){V(O,t,_),K(t,n),K(n,i),K(n,a),V(O,h,_),V(O,d,_),g&&g.m(O,_),V(O,y,_)},p(O,_){_&8&&o!==(o=O[3].x)&&f(i,"x",o),_&8&&s!==(s=O[3].y)&&f(i,"y",s),_&8&&r!==(r=O[3].w)&&f(i,"width",r),_&8&&l!==(l=O[3].h)&&f(i,"height",l),_&4&&u!==(u=O[19])&&f(a,"points",u),_&4&&c!==(c=O[19])&&f(h,"points",c),_&4&&p!==(p=O[19])&&f(d,"points",p),O[1]?g?g.p(O,_):(g=Ui(O),g.c(),g.m(y.parentNode,y)):g&&(g.d(1),g=null)},d(O){O&&(H(t),H(h),H(d),H(y)),g&&g.d(O)}}}function Ui(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){V(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&&H(t)}}}function Tr(e){let t,n=e[3]&&Di(tn(e));return{c(){t=L("g"),n&&n.c(),f(t,"class","a9s-annotation a9s-rubberband")},m(i,o){V(i,t,o),n&&n.m(t,null)},p(i,[o]){i[3]?n?n.p(tn(i),o):(n=Di(tn(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&H(t),n&&n.d()}}}const Ar=20,Or=1500;function Mr(e,t,n){let i,o,s;const r=Ve();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:h=1}=t,c,d=[],p,y,g=!1;const O=I=>{const N=I,{timeStamp:P,offsetX:k,offsetY:G}=N;if(c={timeStamp:P,offsetX:k,offsetY:G},a==="drag"&&d.length===0){const z=u.elementToImage(N.offsetX,N.offsetY);d.push(z),n(10,p=z)}},_=I=>{const N=I;if(y&&clearTimeout(y),d.length>0){if(n(10,p=u.elementToImage(N.offsetX,N.offsetY)),d.length>2){const P=Ot(p,d[0])*h;n(1,g=P<Ar)}N.pointerType==="touch"&&(y=setTimeout(()=>{b()},Or))}},M=I=>{const N=I;if(y&&clearTimeout(y),a==="click"){const P=N.timeStamp-c.timeStamp,k=Ot([c.offsetX,c.offsetY],[N.offsetX,N.offsetY]);if(P>300||k>15)return;if(g)v();else if(d.length===0){const G=u.elementToImage(N.offsetX,N.offsetY);d.push(G),n(10,p=G)}else d.push(p)}else{if(d.length===1&&Ot(d[0],p)<=4){n(0,d=[]),n(10,p=void 0);return}N.stopImmediatePropagation(),g?v():d.push(p)}},b=()=>{if(!p)return;const I=d.slice(0,-1);if(I.length<3)return;const N={type:ie.POLYGON,geometry:{bounds:ye(d),points:I}};mt(N)>4&&(n(0,d=[]),n(10,p=void 0),r("create",N))},v=()=>{const I={type:ie.POLYGON,geometry:{bounds:ye(d),points:[...d]}};n(0,d=[]),n(10,p=void 0),r("create",I)};ze(()=>{l("pointerdown",O,!0),l("pointermove",_),l("pointerup",M,!0),l("dblclick",b,!0)});const S=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=I=>{"addEventListener"in I&&n(6,l=I.addEventListener),"drawingMode"in I&&n(7,a=I.drawingMode),"transform"in I&&n(8,u=I.transform),"viewportScale"in I&&n(9,h=I.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,i=4/h),e.$$.dirty&1027&&n(2,o=p?g?d:[...d,p]:[]),e.$$.dirty&516&&n(3,s=o.length>0?ft(ye(o),2/h):void 0)},[d,g,o,s,i,S,l,a,u,h,p]}class vr extends ve{constructor(t){super(),Me(this,t,Mr,Tr,ce,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const nn=new Map([["rectangle",{tool:Pi}],["polygon",{tool:vr}]]),on=()=>[...nn.keys()],sn=e=>nn.get(e),Hi=(e,t,n={})=>nn.set(e,{tool:t,opts:n});function Sr(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,l){V(r,t,l),K(t,n),K(t,o)},p(r,[l]){l&2&&i!==(i=r[1]?"display:none;":void 0)&&f(n,"style",i),l&2&&f(o,"style",r[1]),l&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}function Nr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,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=ut(o,r))},[o,i,l,a,u,h,s,r]}class Cr extends ve{constructor(t){super(),Me(this,t,Nr,Sr,ce,{annotation:0,geom:6,style:7})}}function Vi(e,t,n){const i=e.slice();return i[5]=t[n],i}function Yi(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",De(e[5])),f(i,"class","a9s-inner"),f(i,"style",e[1]),f(i,"fill-rule","evenodd"),f(i,"d",De(e[5]))},m(o,s){V(o,t,s),V(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&&(H(t),H(i))}}}function Ir(e){let t,n,i=Ne(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=Yi(Vi(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){V(s,t,r);for(let l=0;l<o.length;l+=1)o[l]&&o[l].m(t,null)},p(s,[r]){if(r&6){i=Ne(s[2]);let l;for(l=0;l<i.length;l+=1){const a=Vi(s,i,l);o[l]?o[l].p(a,r):(o[l]=Yi(a),o[l].c(),o[l].m(t,null))}for(;l<o.length;l+=1)o[l].d(1);o.length=i.length}r&1&&n!==(n=s[0].id)&&f(t,"data-id",n)},i:q,o:q,d(s){s&&H(t),Ge(o,s)}}}function Rr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,o=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,l,s,r]}class Lr extends ve{constructor(t){super(),Me(this,t,Rr,Ir,ce,{annotation:0,geom:3,style:4})}}function kr(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(Pr).join(" ")),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"points",e[2].map(Dr).join(" ")),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,l){V(r,t,l),K(t,n),K(t,o)},p(r,[l]){l&2&&i!==(i=r[1]?"display:none;":void 0)&&f(n,"style",i),l&2&&f(o,"style",r[1]),l&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}const Pr=e=>e.join(","),Dr=e=>e.join(",");function Ur(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,o=a.annotation),"geom"in a&&n(3,s=a.geom),"style"in a&&n(4,r=a.style)},e.$$.update=()=>{e.$$.dirty&17&&n(1,i=ut(o,r))},[o,i,l,s,r]}class Hr extends ve{constructor(t){super(),Me(this,t,Ur,kr,ce,{annotation:0,geom:3,style:4})}}function Vr(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,l){V(r,t,l),K(t,n),K(t,o)},p(r,[l]){l&32&&i!==(i=r[5]?"display:none;":void 0)&&f(n,"style",i),l&16&&f(n,"x",r[4]),l&8&&f(n,"y",r[3]),l&4&&f(n,"width",r[2]),l&2&&f(n,"height",r[1]),l&32&&f(o,"style",r[5]),l&16&&f(o,"x",r[4]),l&8&&f(o,"y",r[3]),l&4&&f(o,"width",r[2]),l&2&&f(o,"height",r[1]),l&1&&s!==(s=r[0].id)&&f(t,"data-id",s)},i:q,o:q,d(r){r&&H(t)}}}function Yr(e,t,n){let i,o,s,r,l,{annotation:a}=t,{geom:u}=t,{style:h}=t;return e.$$set=c=>{"annotation"in c&&n(0,a=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=ut(a,h)),e.$$.dirty&64&&n(4,{x:o,y:s,w:r,h:l}=u,o,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,o,i,u,h]}class Br extends ve{constructor(t){super(),Me(this,t,Yr,Vr,ce,{annotation:0,geom:6,style:7})}}const Xr={elementToImage:(e,t)=>[e,t]},Bi=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]}}),Fr=250,Xi=(e,t)=>{const n=Ve();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<Fr){const{x:a,y:u}=rn(r,e),h=t.getAt(a,u);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},rn=(e,t)=>{const n=t.createSVGPoint(),i=t.getBoundingClientRect(),o=e.clientX-i.x,s=e.clientY-i.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=o+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function Fi(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 ji(e,t,n){const i=e.slice();return i[43]=t[n],i}function ln(e){const t=e.slice(),n=t[43].target.selector;return t[46]=n,t}function Gi(e){let t=e[43],n,i,o=zi(e);return{c(){o.c(),n=Se()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&65536&&ce(t,t=s[43])?(be(),F(o,1,1,q),Te(),o=zi(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function jr(e){let t,n;return t=new Lr({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){de(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Gr(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){de(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function zr(e){let t,n;return t=new Br({props:{annotation:e[43],geom:e[46].geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(i,o){de(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Qr(e){var i;let t,n;return t=new Cr({props:{annotation:e[43],geom:(i=e[46])==null?void 0:i.geometry,style:e[1]}}),{c(){pe(t.$$.fragment)},m(o,s){de(t,o,s),n=!0},p(o,s){var l;const r={};s[0]&65536&&(r.annotation=o[43]),s[0]&65536&&(r.geom=(l=o[46])==null?void 0:l.geometry),s[0]&2&&(r.style=o[1]),t.$set(r)},i(o){n||(B(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){ge(t,o)}}}function zi(e){let t,n,i,o;const s=[Qr,zr,Gr,jr],r=[];function l(a,u){var h,c,d,p;return((h=a[46])==null?void 0:h.type)===ie.ELLIPSE?0:((c=a[46])==null?void 0:c.type)===ie.RECTANGLE?1:((d=a[46])==null?void 0:d.type)===ie.POLYGON?2:((p=a[46])==null?void 0:p.type)===ie.MULTIPOLYGLON?3:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Se()},m(a,u){~t&&r[t].m(a,u),V(a,i,u),o=!0},p(a,u){let h=t;t=l(a),t===h?~t&&r[t].p(a,u):(n&&(be(),F(r[h],1,1,()=>{r[h]=null}),Te()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),B(n,1),n.m(i.parentNode,i)):n=null)},i(a){o||(B(n),o=!0)},o(a){F(n),o=!1},d(a){a&&H(i),~t&&r[t].d(a)}}}function Qi(e){let t=lt(e[43])&&!e[9](e[43]),n,i,o=t&&Gi(ln(e));return{c(){o&&o.c(),n=Se()},m(s,r){o&&o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&66048&&(t=lt(s[43])&&!s[9](s[43])),t?o?(o.p(ln(s),r),r[0]&66048&&B(o,1)):(o=Gi(ln(s)),o.c(),B(o,1),o.m(n.parentNode,n)):o&&(be(),F(o,1,1,()=>{o=null}),Te())},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o&&o.d(s)}}}function qi(e){let t,n,i,o;const s=[Zr,qr],r=[];function l(a,u){return a[8]?0:a[14]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Se()},m(a,u){~t&&r[t].m(a,u),V(a,i,u),o=!0},p(a,u){let h=t;t=l(a),t===h?~t&&r[t].p(a,u):(n&&(be(),F(r[h],1,1,()=>{r[h]=null}),Te()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),B(n,1),n.m(i.parentNode,i)):n=null)},i(a){o||(B(n),o=!0)},o(a){F(n),o=!1},d(a){a&&H(i),~t&&r[t].d(a)}}}function qr(e){let t=`${e[2]}-${e[5]}`,n,i,o=Zi(e);return{c(){o.c(),n=Se()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&36&&ce(t,t=`${s[2]}-${s[5]}`)?(be(),F(o,1,1,q),Te(),o=Zi(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function Zr(e){let t,n,i=Ne(e[8]),o=[];for(let r=0;r<i.length;r+=1)o[r]=Ji(Fi(e,i,r));const s=r=>F(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Se()},m(r,l){for(let a=0;a<o.length;a+=1)o[a]&&o[a].m(r,l);V(r,t,l),n=!0},p(r,l){if(l[0]&21107010){i=Ne(r[8]);let a;for(a=0;a<i.length;a+=1){const u=Fi(r,i,a);o[a]?(o[a].p(u,l),B(o[a],1)):(o[a]=Ji(u),o[a].c(),B(o[a],1),o[a].m(t.parentNode,t))}for(be(),a=i.length;a<o.length;a+=1)s(a);Te()}},i(r){if(!n){for(let l=0;l<i.length;l+=1)B(o[l]);n=!0}},o(r){o=o.filter(Boolean);for(let l=0;l<o.length;l+=1)F(o[l]);n=!1},d(r){r&&H(t),Ge(o,r)}}}function Zi(e){let t,n;return t=new Li({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){de(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Ki(e){let t=e[39].id,n,i,o=Wi(e);return{c(){o.c(),n=Se()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&256&&ce(t,t=s[39].id)?(be(),F(o,1,1,q),Te(),o=Wi(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){F(o),i=!1},d(s){s&&H(n),o.d(s)}}}function Wi(e){let t,n;return t=new Ri({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(){re(e[22](e[39]))&&e[22](e[39]).apply(this,arguments)}),{c(){pe(t.$$.fragment)},m(i,o){de(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||(B(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){ge(t,i)}}}function Ji(e){let t,n,i=e[40]&&Ki(e);return{c(){i&&i.c(),t=Se()},m(o,s){i&&i.m(o,s),V(o,t,s),n=!0},p(o,s){o[40]?i?(i.p(o,s),s[0]&256&&B(i,1)):(i=Ki(o),i.c(),B(i,1),i.m(t.parentNode,t)):i&&(be(),F(i,1,1,()=>{i=null}),Te())},i(o){n||(B(i),n=!0)},o(o){F(i),n=!1},d(o){o&&H(t),i&&i.d(o)}}}function Kr(e){let t,n,i,o,s,r,l=Ne(e[16].filter(e[34])),a=[];for(let c=0;c<l.length;c+=1)a[c]=Qi(ji(e,l,c));const u=c=>F(a[c],1,1,()=>{a[c]=null});let h=e[6]&&qi(e);return{c(){t=L("svg"),n=L("g");for(let c=0;c<a.length;c+=1)a[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"),Pe(t,"drawing",e[14]),Pe(t,"editing",e[8]),Pe(t,"hidden",!e[3]),Pe(t,"hover",e[15])},m(c,d){V(c,t,d),K(t,n);for(let p=0;p<a.length;p+=1)a[p]&&a[p].m(n,null);K(t,i),h&&h.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[ee(t,"pointerup",function(){re(e[10])&&e[10].apply(this,arguments)}),ee(t,"pointerdown",function(){re(e[11])&&e[11].apply(this,arguments)}),ee(t,"pointermove",e[23])],s=!0)},p(c,d){if(e=c,d[0]&66050){l=Ne(e[16].filter(e[34]));let p;for(p=0;p<l.length;p+=1){const y=ji(e,l,p);a[p]?(a[p].p(y,d),B(a[p],1)):(a[p]=Qi(y),a[p].c(),B(a[p],1),a[p].m(n,null))}for(be(),p=l.length;p<a.length;p+=1)u(p);Te()}e[6]?h?(h.p(e,d),d[0]&64&&B(h,1)):(h=qi(e),h.c(),B(h,1),h.m(i,null)):h&&(be(),F(h,1,1,()=>{h=null}),Te()),(!o||d[0]&16384)&&Pe(t,"drawing",e[14]),(!o||d[0]&256)&&Pe(t,"editing",e[8]),(!o||d[0]&8)&&Pe(t,"hidden",!e[3]),(!o||d[0]&32768)&&Pe(t,"hover",e[15])},i(c){if(!o){for(let d=0;d<l.length;d+=1)B(a[d]);B(h),o=!0}},o(c){a=a.filter(Boolean);for(let d=0;d<a.length;d+=1)F(a[d]);F(h),o=!1},d(c){c&&H(t),Ge(a,c),h&&h.d(),e[35](null),e[36](null),s=!1,Ie(r)}}}function Wr(e,t,n){let i,o,s,r,l,a,u,h,c,d,p,y=q,g=()=>(y(),y=yn(m,X=>n(17,p=X)),m);e.$$.on_destroy.push(()=>y());let{drawingEnabled:O}=t,{image:_}=t,{preferredDrawingMode:M}=t,{state:b}=t,{style:v=void 0}=t,{toolName:S=on()[0]}=t,{user:I}=t,{visible:N=!0}=t,P=0;const k=()=>n(5,P+=1),G=()=>S,z=()=>O;let w,T,m;ze(()=>g(n(7,m=oi(_,T))));const{hover:E,selection:R,store:C}=b;Lt(e,E,X=>n(15,h=X)),Lt(e,R,X=>n(33,c=X)),Lt(e,C,X=>n(16,d=X));let U,Q;const j=X=>{U&&C.unobserve(U);const he=X.filter(({editable:te})=>te).map(({id:te})=>te);he.length>0?(n(8,Q=he.map(te=>C.getAnnotation(te)).filter(te=>te&&lt(te))),U=te=>{const{updated:we}=te.changes;n(8,Q=we==null?void 0:we.map(Ae=>Ae.newValue))},C.observe(U,{annotations:he})):n(8,Q=void 0)},x=X=>{const he=Wn(),te={id:he,bodies:[],target:{annotation:he,selector:X.detail,creator:I,created:new Date}};C.addAnnotation(te),R.setSelected(te.id)},W=X=>he=>{var nt;const{target:te}=X,we=10*60*1e3,Ae=((nt=te.creator)==null?void 0:nt.id)!==I.id||!te.created||new Date().getTime()-te.created.getTime()>we;C.updateTarget({...te,selector:he.detail,created:Ae?te.created:new Date,updated:Ae?new Date:void 0,updatedBy:Ae?I:void 0})},J=X=>{const{x:he,y:te}=rn(X,T),we=C.getAt(he,te);we?h!==we.id&&E.set(we.id):E.set(void 0)},ae=X=>Ci(X),le=X=>lt(X);function Ce(X){yt[X?"unshift":"push"](()=>{w=X,n(6,w)})}function ke(X){yt[X?"unshift":"push"](()=>{T=X,n(4,T)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,O=X.drawingEnabled),"image"in X&&n(25,_=X.image),"preferredDrawingMode"in X&&n(26,M=X.preferredDrawingMode),"state"in X&&n(27,b=X.state),"style"in X&&n(1,v=X.style),"toolName"in X&&n(2,S=X.toolName),"user"in X&&n(28,I=X.user),"visible"in X&&n(3,N=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(14,{tool:i,opts:o}=sn(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)||M),e.$$.dirty[0]&16&&n(12,r=Bi(T)),e.$$.dirty[0]&16&&n(11,{onPointerDown:l,onPointerUp:a}=Xi(T,C),l,(n(10,a),n(4,T))),e.$$.dirty[1]&4&&n(9,u=X=>c.selected.find(he=>he.id===X.id&&he.editable)),e.$$.dirty[1]&4&&j(c.selected)},[O,v,S,N,T,P,w,m,Q,u,a,l,r,s,i,h,d,p,E,R,C,x,W,J,ae,_,M,b,I,k,G,z,o,c,le,Ce,ke]}class xi extends ve{constructor(t){super(),Me(this,t,Wr,Kr,ce,{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 $i(e,t,n=0,i=e.length-1,o=Jr){for(;i>n;){if(i-n>600){const a=i-n+1,u=t-n+1,h=Math.log(a),c=.5*Math.exp(2*h/3),d=.5*Math.sqrt(h*c*(a-c)/a)*(u-a/2<0?-1:1),p=Math.max(n,Math.floor(t-u*c/a+d)),y=Math.min(i,Math.floor(t+(a-u)*c/a+d));$i(e,t,p,y,o)}const s=e[t];let r=n,l=i;for(dt(e,n,t),o(e[i],s)>0&&dt(e,n,i);r<l;){for(dt(e,r,l),r++,l--;o(e[r],s)<0;)r++;for(;o(e[l],s)>0;)l--}o(e[n],s)===0?dt(e,n,l):(l++,dt(e,l,i)),l<=t&&(n=l+1),t<=l&&(i=l-1)}}function dt(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function Jr(e,t){return e<t?-1:e>t?1:0}class xr{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 l=n.children[r],a=n.leaf?o(l):l;St(t,a)&&(n.leaf?i.push(l):un(t,a)?this._all(l,i):s.push(l))}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||un(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=tt([]),this}remove(t,n){if(!t)return this;let i=this.data;const o=this.toBBox(t),s=[],r=[];let l,a,u;for(;i||s.length;){if(i||(i=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),i.leaf){const h=$r(t,i.children,n);if(h!==-1)return i.children.splice(h,1),s.push(i),this._condense(s),this}!u&&!i.leaf&&un(i,o)?(s.push(i),r.push(l),l=0,a=i,i=i.children[0]):a?(l++,i=a.children[l],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,l;if(s<=r)return l=tt(t.slice(n,i+1)),et(l,this.toBBox),l;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),l=tt([]),l.leaf=!1,l.height=o;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));eo(t,n,i,u,this.compareMinX);for(let h=n;h<=i;h+=u){const c=Math.min(h+u-1,i);eo(t,h,c,a,this.compareMinY);for(let d=h;d<=c;d+=a){const p=Math.min(d+a-1,c);l.children.push(this._build(t,d,p,o-1))}}return et(l,this.toBBox),l}_chooseSubtree(t,n,i,o){for(;o.push(n),!(n.leaf||o.length-1===i);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],h=an(u),c=nl(t,u)-h;c<r?(r=c,s=h<s?h:s,l=u):c===r&&h<s&&(s=h,l=u)}n=l||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),pt(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),l=tt(i.children.splice(r,i.children.length-r));l.height=i.height,l.leaf=i.leaf,et(i,this.toBBox),et(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(i,l)}_splitRoot(t,n){this.data=tt([t,n]),this.data.height=t.height+1,this.data.leaf=!1,et(this.data,this.toBBox)}_chooseSplitIndex(t,n,i){let o,s=1/0,r=1/0;for(let l=n;l<=i-n;l++){const a=gt(t,0,l,this.toBBox),u=gt(t,l,i,this.toBBox),h=il(a,u),c=an(a)+an(u);h<s?(s=h,o=l,r=c<r?c:r):h===s&&c<r&&(r=c,o=l)}return o||i-n}_chooseSplitAxis(t,n,i){const o=t.leaf?this.compareMinX:el,s=t.leaf?this.compareMinY:tl,r=this._allDistMargin(t,n,i,o),l=this._allDistMargin(t,n,i,s);r<l&&t.children.sort(o)}_allDistMargin(t,n,i,o){t.children.sort(o);const s=this.toBBox,r=gt(t,0,n,s),l=gt(t,i-n,i,s);let a=vt(r)+vt(l);for(let u=n;u<i-n;u++){const h=t.children[u];pt(r,t.leaf?s(h):h),a+=vt(r)}for(let u=i-n-1;u>=n;u--){const h=t.children[u];pt(l,t.leaf?s(h):h),a+=vt(l)}return a}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)pt(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():et(t[n],this.toBBox)}}function $r(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 et(e,t){gt(e,0,e.children.length,t,e)}function gt(e,t,n,i,o){o||(o=tt(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];pt(o,e.leaf?i(r):r)}return o}function pt(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 el(e,t){return e.minX-t.minX}function tl(e,t){return e.minY-t.minY}function an(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function vt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function nl(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 il(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 un(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 tt(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function eo(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;$i(e,r,t,n,o),s.push(t,r,r,n)}}const ol=()=>{const e=new xr,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!at(c))return;const{minX:d,minY:p,maxX:y,maxY:g}=c.selector.geometry.bounds,O={minX:d,minY:p,maxX:y,maxY:g,target:c};e.insert(O),t.set(c.annotation,O)},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,p)=>{const g=e.search({minX:c,minY:d,maxX:c,maxY:d}).map(O=>O.target).filter(O=>O.selector.type===ie.RECTANGLE||Sn(O.selector,c,d));return g.length>0?(g.sort((O,_)=>mt(O.selector)-mt(_.selector)),g):[]},getIntersecting:(c,d,p,y)=>e.search({minX:c,minY:d,maxX:c+p,maxY:d+y}).map(g=>g.target),insert:o,remove:s,set:(c,d=!0)=>{d&&i();const p=c.reduce((y,g)=>{if(at(g)){const{minX:O,minY:_,maxX:M,maxY:b}=g.selector.geometry.bounds;return[...y,{minX:O,minY:_,maxX:M,maxY:b,target:g}]}else return y},[]);p.forEach(y=>t.set(y.target.annotation,y)),e.load(p)},size:()=>e.all().length,update:(c,d)=>{s(c),o(d)}}},to=e=>{const t=ws(),n=ol(),i=rs(t,e.userSelectAction,e.adapter),o=ss(t),s=Os();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:h})=>n.update(u.target,h.target))}),{store:{...t,getAt:(a,u,h)=>{const c=n.getAt(a,u,h);if(h)return c.map(p=>t.getAnnotation(p.annotation)).filter(Boolean).filter(h)[0];{const d=c[0];return d?t.getAnnotation(d.annotation):void 0}},getIntersecting:(a,u,h,c)=>n.getIntersecting(a,u,h,c).map(d=>t.getAnnotation(d.annotation))},selection:i,hover:o,viewport:s}},no=e=>{const t=to(e);return{...t,store:Es(t.store)}},io=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),l=Math.round(o*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;i+=u}return i/81},oo=e=>{const t=io(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},fn=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?oo(e):n),so=(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}),cn=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,ro=(e,t)=>{const n=t||document,i=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},o=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{cn?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return cn?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:s}},sl=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=so(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Gt.EDIT,theme:"light"}),o=no(i),{selection:s,store:r}=o,l=As(r,i.initialHistory),a=Ms(o,l,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=ro(l);let c=Ds();fn(n,u,i.theme);const d=new xi({target:u,props:{drawingEnabled:!!i.drawingEnabled,image:n,preferredDrawingMode:i.drawingMode,state:o,style:i.style,user:c}});d.$on("click",w=>{const{originalEvent:T,annotation:m}=w.detail;m?s.userSelect(m.id,T):s.isEmpty()||s.clear()});const p=Ss(o,l,i.adapter),y=()=>d.cancelDrawing(),g=()=>{d.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),h.destroy(),l.destroy()},O=()=>d.getDrawingTool(),_=()=>c,M=()=>d.isDrawingEnabled(),b=(w,T,m)=>Hi(w,T,m),v=(w,T)=>Ii(w,T),S=w=>{if(!sn(w))throw`No drawing tool named ${w}`;d.$set({toolName:w})},I=w=>d.$set({drawingEnabled:w}),N=w=>{console.warn("Filter not implemented yet")},P=w=>d.$set({style:w}),k=w=>fn(n,u,w),G=w=>{c=w,d.$set({user:w})},z=w=>d.$set({visible:w});return{...p,cancelDrawing:y,destroy:g,getDrawingTool:O,getUser:_,isDrawingEnabled:M,listDrawingTools:on,on:a.on,off:a.off,registerDrawingTool:b,registerShapeEditor:v,setDrawingEnabled:I,setDrawingTool:S,setFilter:N,setStyle:P,setTheme:k,setUser:G,setVisible:z,element:u,state:o}};D.Editor=Mt,D.EditorMount=Ri,D.Handle=Ze,D.IdentityTransform=Xr,D.PolygonEditor=yi,D.RectangleEditor=_i,D.RectangleUtil=In,D.RubberbandRectangle=Pi,D.SVGAnnotationLayer=xi,D.ShapeType=ie,D.ToolMount=Li,D.UserSelectAction=Gt,D.W3CImageFormat=Xs,D.addEventListeners=Xi,D.boundsFromMultiPolygonElements=rt,D.boundsFromPoints=ye,D.chainStyles=Cs,D.computeArea=mt,D.computePolygonArea=wt,D.computeStyle=Ns,D.createBody=cs,D.createImageAnnotator=sl,D.createImageAnnotatorState=to,D.createSVGTransform=Bi,D.createSvelteImageAnnotatorState=no,D.defaultColorProvider=Bs,D.detectTheme=oo,D.distance=Ot,D.enableResponsive=oi,D.fillDefaults=so,D.getAllCorners=Cn,D.getEditor=Ci,D.getMaskDimensions=ft,D.getSVGPoint=rn,D.getTool=sn,D.initKeyboardCommands=ro,D.intersects=Sn,D.isImageAnnotation=lt,D.isImageAnnotationTarget=at,D.isMac=cn,D.isPointInPolygon=Et,D.isTouch=Ue,D.listDrawingTools=on,D.multipolygonElementToPath=De,D.parseFragmentSelector=Rn,D.parseSVGSelector=qn,D.parseW3CImageAnnotation=ni,D.pointsToPath=Nn,D.registerEditor=Ii,D.registerShapeUtil=st,D.registerTool=Hi,D.sampleBrightness=io,D.serializeFragmentSelector=Ln,D.serializeSVGSelector=Zn,D.serializeW3CImageAnnotation=ii,D.setTheme=fn,D.simplifyMultiPolygon=Mo,D.simplifyPoints=Ht,D.simplifyPolygon=So,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
3
3
  //# sourceMappingURL=annotorious.js.map