@annotorious/annotorious 3.5.0 → 3.6.0

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 dl=Object.defineProperty;var gl=(D,q,He)=>q in D?dl(D,q,{enumerable:!0,configurable:!0,writable:!0,value:He}):D[q]=He;var re=(D,q,He)=>gl(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 le(e){return typeof e=="function"}function fe(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function lo(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 ao(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 uo(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 fo(e,t,n,i,o,s){if(o){const r=_n(t,n,i,s);e.p(r,o)}}function co(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 Z(e,t){e.appendChild(t)}function V(e,t,n){e.insertBefore(t,n||null)}function U(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 ve(){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 ho(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function go(e,t,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:i})}let st;function rt(e){st=e}function En(){if(!st)throw new Error("Function called outside component initialization");return st}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=go(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=st;do{try{for(;Je<Ke.length;){const t=Ke[Je];Je++,rt(t),po(t.$$)}}catch(t){throw Ke.length=0,Je=0,t}for(rt(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(),rt(e)}function po(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 yo(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 Y(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(le);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ie(s),e.$$.on_mount=[]}),o.forEach(Dt)}function de(e,t){const n=e.$$;n.fragment!==null&&(yo(n.after_update),Ie(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function _o(e,t){e.$$.dirty[0]===-1&&(Ke.push(e),An(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function Ae(e,t,n,i,o,s,r=null,l=[-1]){const a=st;rt(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,...y)=>{const p=y.length?y[0]:d;return u.ctx&&o(u.ctx[c],u.ctx[c]=p)&&(!u.skip_bound&&u.bound[c]&&u.bound[c](p),h&&_o(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=ho(t.target);u.fragment&&u.fragment.l(c),c.forEach(U)}else u.fragment&&u.fragment.c();t.intro&&Y(e.$$.fragment),he(e,t.target,t.anchor),Mn()}rt(a)}class Oe{constructor(){re(this,"$$");re(this,"$$set")}$destroy(){de(this,1),this.$destroy=q}$on(t,n){if(!le(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&&!lo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const mo="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(mo);var ne=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGLON="MULTIPOLYGON",e.POLYGON="POLYGON",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(ne||{});function wo(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,y=u.y-c;if(d!==0||y!==0){var p=((l.x-h)*d+(l.y-c)*y)/(d*d+y*y);p>1?(h=u.x,c=u.y):p>0&&(h+=d*p,c+=y*p)}return d=l.x-h,y=l.y-c,d*d+y*y}function i(l,a){for(var u=l[0],h=[u],c,d=1,y=l.length;d<y;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,y,p=a+1;p<u;p++){var g=n(l[p],l[a],l[u]);g>d&&(y=p,d=g)}d>h&&(y-a>1&&o(l,a,y,h,c),c.push(l[y]),u-y>1&&o(l,y,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 Eo=vn.exports;const bo=wo(Eo),Ht={},xe=(e,t)=>Ht[e]=t,wt=e=>Ht[e.type].area(e),Sn=(e,t,n,i)=>Ht[e.type].intersects(e,t,n,i),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 bo(n,t,!0).map(i=>[i.x,i.y])},lt=(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))},To={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,y=u*h-a*c;return d*d/(s*s)+y*y/(r*r)<=1}};xe(ne.ELLIPSE,To);const Ao={area:e=>0,intersects:(e,t,n,i=2)=>{const[[o,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-o)*n+r*s-l*o),u=lt([o,s],[r,l]);return a/u<=i}};xe(ne.LINE,Ao);const Oo={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}},at=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],[])],[]),Mo=(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=at(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:i}}};xe(ne.MULTIPOLYGLON,Oo);const vo={area:e=>{const t=e.geometry.points;return Et(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return bt(i,t,n)}},So=(e,t=1)=>{const n=Vt(e.geometry.points,t),i=ye(n);return{...e,geometry:{...e.geometry,bounds:i,points:n}}};xe(ne.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};xe(ne.RECTANGLE,In);const ut=e=>ft(e.target),ft=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,y,p,g]=[a,u,h,c].map(parseFloat);return{type:ne.RECTANGLE,geometry:{x:d,y,w:p,h:g,bounds:{minX:d,minY:t?y-g:y,maxX:d+p,maxY:t?y:y+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},Co=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${kn}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},Yt=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(Co(n)).firstChild},ce=" ";function No(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+ce+i.y;else if(i.type===A.LINE_TO)t+=(i.relative?"l":"L")+i.x+ce+i.y;else if(i.type===A.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+ce+i.y1+ce+i.x2+ce+i.y2+ce+i.x+ce+i.y;else if(i.type===A.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+ce+i.y2+ce+i.x+ce+i.y;else if(i.type===A.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+ce+i.y1+ce+i.x+ce+i.y;else if(i.type===A.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+ce+i.y;else if(i.type===A.ARC)t+=(i.relative?"a":"A")+i.rX+ce+i.rY+ce+i.xRot+ce+ +i.lArcFlag+ce+ +i.sweepFlag+ce+i.x+ce+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Bt([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 Xt(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]=Bt([(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)),y=i*u/o*d,p=-o*a/i*d,g=Bt([y,p],l);e.cX=g[0]+(t+s)/2,e.cY=g[1]+(n+r)/2,e.phi1=Math.atan2((u-p)/o,(a-y)/i),e.phi2=Math.atan2((-u-p)/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 Dn(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 Un(e,t,n){return(1-n)*e+n*t}function Hn(e,t,n,i){return e+Math.cos(i/180*Ye)*t+Math.sin(i/180*Ye)*n}function Vn(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 Yn(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||Xt(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,y)=>{const[p,g]=Bt([d*e.rX,y*e.rY],i);return[e.cX+p,e.cY+g]};for(let d=0;d<l;d++){const y=Un(e.phi1,e.phi2,d/l),p=Un(e.phi1,e.phi2,(d+1)/l),g=p-y,O=4/3*Math.tan(g*qe/4),_=Math.cos(y*qe)-O*Math.sin(y*qe),M=Math.sin(y*qe)+O*Math.cos(y*qe),b=Math.cos(p*qe),v=Math.sin(p*qe),S=b+O*v,I=v-O*b,C=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:C[0],y1:C[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 Tt(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){if(e.length<=2)return e;const t=[],n=e.map(ue.INFO((o,s,r)=>{const l="relative"in o&&o.relative;return["x"in o?o.x+(l?s:0):s,"y"in o?o.y+(l?r:0):r]}));let i=n[0];t.push(e[0]);for(let o=1;o<e.length;o++){const s=e[o],r=e[o+1];if(o<e.length-1&&r&&s.type&A.LINE_COMMANDS&&r.type&A.LINE_COMMANDS){const l=n[o+1];if(Tt(i,n[o],l)){"relative"in r&&r.relative&&("x"in r&&(r.x=l[0]-i[0]),"y"in r&&(r.y=l[1]-i[1]));continue}}t.push(s),i=n[o]}return t}function ko(e,t=!0){if(e.length<2)return e;const n=ue.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(...At(o)):i.unshift(...At(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...At(o)):i.unshift(...At(o))),i}function At(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 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 Bn(){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&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];Tt(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];Tt(u,h,d)&&Tt(u,c,d)&&(o.type=A.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function Xn(){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 Fn(){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 Ho(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,y=0;if(s.type&A.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:r-t,y=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 p=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,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;h(p)<=e&&h(g)<=e&&h(d)<=e&&h(y)<=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),y=typeof r.x<"u"?r.x:d?0:l,p=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+p*n+(d?0:o)),typeof r.y<"u"&&(r.y=y*t+r.y*i+(d?0:s)),typeof r.x1<"u"&&(r.x1=r.x1*e+r.y1*n+(d?0:o)),typeof r.y1<"u"&&(r.y1=h*t+r.y1*i+(d?0:s)),typeof r.x2<"u"&&(r.x2=r.x2*e+r.y2*n+(d?0:o)),typeof r.y2<"u"&&(r.y2=c*t+r.y2*i+(d?0:s));function 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,C=2*M*b*(v-S),P=g(M)*v+g(b)*S,k=I*i*i-C*t*i+P*t*t,G=C*(e*i+t*n)-2*(I*n*i+P*e*t),z=I*n*n-C*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 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 Go(e=0){return Re(e),Be(1,0,0,-1,0,e)}function zo(){return Le((e,t,n)=>A.ARC===e.type?Ro(e,e.relative?0:t,e.relative?0:n):e)}function Qo(){return Le((e,t,n)=>(e.relative&&(t=0,n=0),A.ARC===e.type&&Xt(e,t,n),e))}function jn(){return e=>({...e})}function qo(){const e=jn(),t=Bn(),n=Fn(),i=Xn(),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=Vn(r,a.x1,a.x2,a.x);for(const y of c)0<y&&1>y&&u(Yn(r,a.x1,a.x2,a.x,y));const d=Vn(l,a.y1,a.y2,a.y);for(const y of d)0<y&&1>y&&h(Yn(l,a.y1,a.y2,a.y,y))}if(a.type&A.ARC){u(a.x),h(a.y),Xt(a,r,l);const c=a.xRot/180*Math.PI,d=Math.cos(c)*a.rX,y=Math.sin(c)*a.rX,p=-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=Dn(p,-d,0).map(M);for(const S of b)S>O&&S<_&&u(Hn(a.cX,d,p,S));const v=Dn(g,-y,0).map(M);for(const S of v)S>O&&S<_&&h(Hn(a.cY,y,g,S))}return s});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const ue={ROUND:Po,TO_ABS:Bn,TO_REL:Do,NORMALIZE_HVZ:Uo,NORMALIZE_ST:Xn,QT_TO_C:Fn,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:Go,A_TO_C:zo,ANNOTATE_ARCS:Qo,CLONE:jn,CALCULATE_BOUNDS:qo,REVERSE_PATH:ko,REMOVE_COLLINEAR:Lo};class Gn{round(t){return this.transform(ue.ROUND(t))}toAbs(){return this.transform(ue.TO_ABS())}toRel(){return this.transform(ue.TO_REL())}normalizeHVZ(t,n,i){return this.transform(ue.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(ue.NORMALIZE_ST())}qtToC(){return this.transform(ue.QT_TO_C())}aToC(){return this.transform(ue.A_TO_C())}sanitize(t){return this.transform(ue.SANITIZE(t))}translate(t,n){return this.transform(ue.TRANSLATE(t,n))}scale(t,n){return this.transform(ue.SCALE(t,n))}rotate(t,n,i){return this.transform(ue.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(ue.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(ue.SKEW_X(t))}skewY(t){return this.transform(ue.SKEW_Y(t))}xSymmetry(t){return this.transform(ue.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(ue.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(ue.ANNOTATE_ARCS())}}const Zo=e=>e===" "||e===" "||e==="\r"||e===`
2
- `,zn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class Ko extends Gn{constructor(){super();re(this,"curNumber","");re(this,"curCommandType",-1);re(this,"curCommandRelative",!1);re(this,"canParseCommandOrComma",!0);re(this,"curNumberHasExp",!1);re(this,"curNumberHasExpDigits",!1);re(this,"curNumberHasDecimal",!1);re(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=zn(r)&&(this.curNumber==="0"&&r==="0"||l);if(zn(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===Wo[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(!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: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 ie=class ie extends Gn{constructor(n){super();re(this,"commands");typeof n=="string"?this.commands=ie.parse(n):this.commands=n}encode(){return ie.encode(this.commands)}getBounds(){const n=ue.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=ue.REVERSE_PATH(this.commands,n),this}removeCollinear(){return this.commands=ue.REMOVE_COLLINEAR(this.commands),this}static encode(n){return No(n)}static parse(n){const i=new Ko,o=[];return i.parse(n,o),i.finish(o),o}};re(ie,"CLOSE_PATH",1),re(ie,"MOVE_TO",2),re(ie,"HORIZ_LINE_TO",4),re(ie,"VERT_LINE_TO",8),re(ie,"LINE_TO",16),re(ie,"CURVE_TO",32),re(ie,"SMOOTH_CURVE_TO",64),re(ie,"QUAD_TO",128),re(ie,"SMOOTH_QUAD_TO",256),re(ie,"ARC",512),re(ie,"LINE_COMMANDS",ie.LINE_TO|ie.HORIZ_LINE_TO|ie.VERT_LINE_TO),re(ie,"DRAWING_COMMANDS",ie.HORIZ_LINE_TO|ie.VERT_LINE_TO|ie.LINE_TO|ie.CURVE_TO|ie.SMOOTH_CURVE_TO|ie.QUAD_TO|ie.SMOOTH_QUAD_TO|ie.ARC);let A=ie;const Wo={[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},Jo=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}}},xo=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:ne.POLYGON,geometry:{points:o,bounds:ye(o)}}},$o=e=>{const t=Yt(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:ne.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},es=e=>{const t=Yt(e),n=parseFloat(t.getAttribute("x1")),i=parseFloat(t.getAttribute("x2")),o=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,i),minY:Math.min(o,s),maxX:Math.max(n,i),maxY:Math.max(o,s)};return{type:ne.LINE,geometry:{points:[[n,o],[i,s]],bounds:r}}},ts=e=>{const t=Yt(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:ne.POLYGON,geometry:{points:s,bounds:r}}:{type:ne.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 ts(t);if(t.includes("<ellipse "))return $o(t);if(t.includes("<line "))return es(t);throw"Unsupported SVG shape: "+t},ns=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${De(n)}" />`).join("")}</g>`,qn=e=>{let t;switch(e.type){case ne.POLYGON:{const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`;break}case ne.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case ne.MULTIPOLYGLON:{const n=e.geometry;t=`<svg>${ns(n)}</svg>`;break}case ne.LINE:{const n=e.geometry,[[i,o],[s,r]]=n.points;t=`<svg><line x1="${i}" y1="${o}" x2="${s}" y2="${r}" /></svg>`;break}}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 is(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 os=new Uint8Array(16);function ss(){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(os)}const Zn={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Kn(e,t,n){var o;if(Zn.randomUUID&&!e)return Zn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??ss();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,is(i)}var Wn=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(Wn.call(e,n)&&++i&&!Wn.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 rs(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const $e=[];function Gt(e,t=jt){let n;const i=new Set;function o(l){if(rs(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=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 ls=e=>{const{subscribe:t,set:n}=Gt();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 zt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(zt||{});const Ot={selected:[]},as=(e,t,n)=>{const{subscribe:i,set:o}=Gt(Ot);let s=t,r=Ot;i(g=>r=g);const l=()=>{Xe(r,Ot)||o(Ot)},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=p(v);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?p(b)==="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(_))})},y=g=>{s=g,c(r.selected.map(({id:O})=>O))},p=g=>us(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:p,isEmpty:a,isSelected:u,setSelected:c,setUserSelectAction:y,subscribe:i,userSelect:h}},us=(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 fs(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 cs=new Uint8Array(16);function hs(){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(cs)}const ds=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jn={randomUUID:ds};function xn(e,t,n){var i;if(Jn.randomUUID&&!e)return Jn.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??hs();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,fs(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)}},gs=(e,t,n,i)=>({id:xn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),ps=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},ys=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},_s=(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})),ms=(e,t)=>!Xe(e.target,t.target),$n=(e,t)=>{const n=ps(e,t),i=ys(e,t),o=_s(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:ms(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 ws=(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},Es=(e,t)=>{const n=new Set((e.created||[]).map(c=>c.id)),i=new Set((e.updated||[]).map(({newValue:c})=>c.id)),o=new Set((t.created||[]).map(c=>c.id)),s=new Set((t.deleted||[]).map(c=>c.id)),r=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),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:y}=c;if(r.has(y.id)){const p=t.updated.find(g=>g.oldValue.id===y.id).newValue;return $n(d,p)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!l.has(c.id))];return{created:a,deleted:u,updated:h}},Mt=e=>{const t=e.id===void 0?xn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},bs=e=>e.id!==void 0,Ts=()=>{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=>{ws(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=Mt(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=Mt(typeof w=="string"?T:w),E=typeof w=="string"?w:w.id,R=E&&e.get(E);if(R){const N=$n(R,m);return E===m.id?e.set(E,m):(e.delete(E),e.set(m.id,m)),R.bodies.forEach(H=>t.delete(H.id)),m.bodies.forEach(H=>t.set(H.id,m.id)),N}else console.warn(`Cannot update annotation ${E} - does not exist`)},a=(w,T=oe.LOCAL,m=oe.LOCAL)=>{const E=bs(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 N=l(R);return N?[...E,N]:E},[]);m.length>0&&s(T,{updated:m})},c=(w,T=oe.LOCAL)=>{const m=w.map(Mt),{toAdd:E,toUpdate:R}=m.reduce((H,Q)=>e.get(Q.id)?{...H,toUpdate:[...H.toUpdate,Q]}:{...H,toAdd:[...H.toAdd,Q]},{toAdd:[],toUpdate:[]}),N=R.map(H=>l(H,T)).filter(Boolean);E.forEach(H=>{e.set(H.id,H),H.bodies.forEach(Q=>t.set(Q.id,H.id))}),s(T,{created:E,updated:N})},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}`)},y=()=>[...e.values()],p=(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(Mt);if(T){const R=[...e.values()];e.clear(),t.clear(),E.forEach(N=>{e.set(N.id,N),N.bodies.forEach(H=>t.set(H.id,N.id))}),s(m,{created:E,deleted:R})}else{const R=w.reduce((N,H)=>{const Q=H.id&&e.get(H.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(H=>t.set(H.id,N.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 N=O(R);return N?[...E,N]: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},C=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(N=>N.id===w.id),R={...m,bodies:m.bodies.map(N=>N.id===E.id?T:N)};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:y,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:p,deleteAnnotation:_,deleteBody:v,getAnnotation:I,getBody:C,observe:i,unobserve:o,updateAnnotation:a,updateBody:k,updateTarget:(w,T=oe.LOCAL)=>{const m=z(w);m&&s(T,{updated:[m]})},upsertAnnotation:u}},As=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let Os=()=>({emit(e,...t){for(let n=this.events[e]||[],i=0,o=n.length;i<o;i++)n[i](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var i;this.events[e]=(i=this.events[e])==null?void 0:i.filter(o=>t!==o)}}});const Ms=250,vs=(e,t)=>{const n=Os(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const l=p=>{if(!s){const{changes:g}=p,O=performance.now();if(O-r>Ms)i.splice(o+1),i.push(g),o=i.length-1;else{const _=i.length-1;i[_]=Es(i[_],g)}r=O}s=!1};e.observe(l,{origin:oe.LOCAL});const a=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p),u=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),h=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({oldValue:g})=>g)),c=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({newValue:g})=>g)),d=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),y=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...i],pointer:o}),on:(p,g)=>n.on(p,g),redo:()=>{if(i.length-1>o){s=!0;const{created:p,updated:g,deleted:O}=i[o+1];u(p),c(g),y(O),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:p,updated:g,deleted:O}=i[o];a(p),h(g),d(O),n.emit("undo",i[o]),o-=1}}}},Ss=()=>{const{subscribe:e,set:t}=Gt([]);return{subscribe:e,set:t}},Cs=(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])},y=(_,M)=>{const b=a.get(_);if(b){const v=b.indexOf(M);v!==-1&&b.splice(v,1)}},p=(_,M,b)=>{a.has(_)&&setTimeout(()=>{a.get(_).forEach(v=>{if(n){const S=Array.isArray(M)?M.map(C=>n.serialize(C)):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))&&p("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)&&p("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)&&p("updateAnnotation",S,v)}),u=[...u.filter(v=>b.has(v.id)),..._.filter(({id:v})=>!M.has(v)).map(({id:v})=>r.getAnnotation(v))]}p("selectionChanged",u)}}),o.subscribe(_=>{!h&&_?p("mouseEnterAnnotation",r.getAnnotation(_)):h&&!_?p("mouseLeaveAnnotation",r.getAnnotation(h)):h&&_&&(p("mouseLeaveAnnotation",r.getAnnotation(h)),p("mouseEnterAnnotation",r.getAnnotation(_))),h=_}),l==null||l.subscribe(_=>p("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=>p("createAnnotation",v)),(b||[]).forEach(v=>p("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),p("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=>p("updateAnnotation",v.oldValue,v.newValue)):(b||[]).forEach(v=>p("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",O(!0)),t.on("redo",O(!1)),{on:d,off:y,emit:p}},Ns=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:[]}),Is=(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=>(y(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),_}},y=(_,M=!0)=>{if(n){const b=n.parseAll||Ns(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)},p=(_,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:y,setSelected:p,setUserSelectAction:g,undo:t.undo,updateAnnotation:O}},Rs=(e,t,n)=>typeof t=="function"?t(e,n):t,Ls=(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||{}}},ks="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Ps=e=>crypto.getRandomValues(new Uint8Array(e)),Ds=(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}}},Us=(e,t=21)=>Ds(e,t|0,Ps),Hs=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=ks[n[e]&63];return t};const Vs=()=>({isGuest:!0,id:Us("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Ys=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}`},ei=e=>e?typeof e=="object"?{...e}:e:void 0,Bs=(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-${Ys(n)}`,annotation:t,type:o,purpose:s,value:r,creator:ei(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...h}}),Xs=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}),Fs=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],js=()=>{const e=[...Fs];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};Hs();const Gs=(e,t={strict:!0,invertY:!1})=>({parse:o=>ti(o,t),serialize:o=>ni(o,e,t)}),ti=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Kn(),{creator:i,created:o,modified:s,body:r,...l}=e,a=Bs(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:ei(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:n,selector:c||h}}}:{error:Error(`Invalid selector: ${JSON.stringify(h)}`)}},ni=(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==ne.RECTANGLE?Ln(i.geometry):qn(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:Xs(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},et=[];function zs(e,t=q){let n;const i=new Set;function o(l){if(fe(e,l)&&(e=l,n)){const a=!et.length;for(const u of i)u[1](),et.push(u,e);if(a){for(let u=0;u<et.length;u+=2)et[u][0](et[u+1]);et.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 Qs=(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}`)},ii=(e,t)=>{Qs(e,t);const{subscribe:n,set:i}=zs(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}},tt=(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}},ct=(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,qs=e=>({}),oi=e=>({grab:e[0]});function Zs(e){let t,n,i,o;const s=e[8].default,r=ao(s,e,e[7],oi);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)&&fo(r,s,l,l[7],n?uo(s,l[7],a,qs):co(l[7]),oi)},i(l){n||(Y(r,l),n=!0)},o(l){F(r,l),n=!1},d(l){l&&U(t),r&&r.d(l),i=!1,Ie(o)}}}function Ks(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 y=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",_)},p=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)},[y,p,g,r,l,a,u,o,i]}class vt extends Oe{constructor(t){super(),Ae(this,t,Ks,Zs,fe,{shape:3,editor:4,transform:5,svgEl:6})}}function Ws(e){let t,n,i,o,s,r,l,a,u=e[3]&&si(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),Z(t,n),u&&u.m(t,null),Z(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=si(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&&U(t),u&&u.d(),l=!1,Ie(a)}}}function Js(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),Z(t,n),Z(t,o),Z(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&&U(t),a=!1,Ie(u)}}}function si(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&&U(t)}}}function xs(e){let t;function n(s,r){return Ue?Js:Ws}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&&U(t),o.d(s)}}}function $s(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 y(_){Ee.call(this,e,_)}function p(_){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,y,p,g,O]}class Ze extends Oe{constructor(t){super(),Ae(this,t,$s,xs,fe,{x:0,y:1,scale:2,selected:3})}}function er(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),Z(t,n),Z(t,o),Z(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&&U(t),r=!1,Ie(l)}}}function tr(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&&U(t)}}}function nr(e){let t;function n(s,r){return Ue?tr:er}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&&U(t),o.d(s)}}}function ir(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 ri extends Oe{constructor(t){super(),Ae(this,t,ir,nr,fe,{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 li(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 ai(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=ht/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=ht/s[3])&&f(t,"r",o)},d(s){s&&U(t)}}}function ui(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=ht/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),Z(t,n),Z(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=ht/c[3])&&f(l,"r",h)},d(c){c&&U(t)}}}function fi(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(){le(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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function ci(e){let t,n;return t=new ri({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){le(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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function or(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g,O,_,M,b,v,S,I=e[6]!==void 0&&!e[7]&&ai(Wt(e)),C=e[6]!==void 0&&!e[7]&&ui(Kt(e)),P=Ce(e[5].points),k=[];for(let w=0;w<P.length;w+=1)k[w]=fi(li(e,P,w));const G=w=>F(k[w],1,1,()=>{k[w]=null});let z=e[6]!==void 0&&!e[7]&&ci(Zt(e));return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),I&&I.c(),C&&C.c(),h=ve(),c=L("polygon"),y=ve(),p=L("polygon"),O=ve();for(let w=0;w<k.length;w+=1)k[w].c();_=ve(),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(hi).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(di).join(" ")),f(p,"class","a9s-inner a9s-shape-handle"),f(p,"mask",`url(#${e[19]}-inner)`),f(p,"style",e[1]),f(p,"points",g=e[5].points.map(gi).join(" "))},m(w,T){V(w,t,T),Z(t,n),Z(n,i),Z(n,a),I&&I.m(n,null),C&&C.m(t,null),V(w,h,T),V(w,c,T),V(w,y,T),V(w,p,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(){le(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),ee(p,"pointermove",e[13]),ee(p,"pointerup",e[14]),ee(p,"pointerdown",function(){le(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(hi).join(" ")))&&f(a,"points",u),e[6]!==void 0&&!e[7]?I?I.p(Wt(e),T):(I=ai(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),T):(C=ui(Kt(e)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!b||T[0]&32&&d!==(d=e[5].points.map(di).join(" ")))&&f(c,"points",d),(!b||T[0]&2)&&f(p,"style",e[1]),(!b||T[0]&32&&g!==(g=e[5].points.map(gi).join(" ")))&&f(p,"points",g),T[0]&134322472){P=Ce(e[5].points);let m;for(m=0;m<P.length;m+=1){const E=li(e,P,m);k[m]?(k[m].p(E,T),Y(k[m],1)):(k[m]=fi(E),k[m].c(),Y(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&&Y(z,1)):(z=ci(Zt(e)),z.c(),Y(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)Y(k[T]);Y(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&&(U(t),U(h),U(c),U(y),U(p),U(O),U(_),U(M)),I&&I.d(),C&&C.d(),Ge(k,w),z&&z.d(w),v=!1,Ie(S)}}}function sr(e){let t,n;return t=new vt({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[or,({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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}const rr=250,lr=1e3,ar=12,ht=4.5,hi=e=>e.join(","),di=e=>e.join(","),gi=e=>e.join(",");function ur(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,y=!1,p,g=[];const O=()=>n(7,y=!0),_=()=>n(7,y=!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),N=W=>Math.pow(W[0]-E,2)+Math.pow(W[1]-R,2),H=i.points.reduce((W,x)=>N(x)<N(W)?x:W),Q=o.filter(W=>W.visible).reduce((W,x)=>N(x.point)<N(W.point)?x:W),j=Math.pow(lr/h,2);N(H)<j||N(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,y=!0),m.preventDefault(),m.stopPropagation(),p=performance.now()},I=m=>E=>{if(!p||Ue||performance.now()-p>rr)return;const R=g.includes(m);E.metaKey||E.ctrlKey||E.shiftKey?R?n(8,g=g.filter(N=>N!==m)):n(8,g=[...g,m]):R&&g.length>1?n(8,g=[m]):R?n(8,g=[]):n(8,g=[m]),b()},C=(m,E,R)=>{b();let N;const H=m.geometry;g.length>1?N=H.points.map(([j,J],W)=>g.includes(W)?[j+R[0],J+R[1]]:[j,J]):E==="SHAPE"?N=H.points.map(([j,J])=>[j+R[0],J+R[1]]):N=H.points.map(([j,J],W)=>E===`HANDLE-${W}`?[j+R[0],J+R[1]]:[j,J]);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 H=[...document.querySelectorAll(".a9s-handle")][m+1];if(H!=null&&H.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});H.firstChild.dispatchEvent(Q)}},k=()=>{if(i.points.length-g.length<3)return;const m=i.points.filter((R,N)=>!g.includes(N)),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],N=(m[0]+R[0])/2,H=(m[1]+R[1])/2,j=Math.sqrt(Math.pow(R[0]-N,2)+Math.pow(R[1]-H,2))>ar/h;return{point:[N,H],visible:j}})),e.$$.dirty[0]&40&&n(9,s=ct(i.bounds,ht/h))},[l,a,u,h,c,i,d,y,g,s,o,O,_,M,v,S,I,C,P,G,z,w,T]}class pi extends Oe{constructor(t){super(),Ae(this,t,ur,sr,fe,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function fr(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g,O,_,M,b,v,S,I,C,P,k,G,z,w,T,m,E,R,N,H,Q,j,J,W,x,se,ae,Ne,ke,X,ge,te,we,Me,ot,Fe,hn,je,$,dn,ro;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(){le(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),Me=new Ze({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),Me.$on("pointerdown",function(){le(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(){le(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(){le(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=ve(),p=L("rect"),b=ve(),v=L("rect"),k=ve(),G=L("rect"),m=ve(),E=L("rect"),Q=ve(),j=L("rect"),se=ve(),ae=L("rect"),ge=ve(),pe(te.$$.fragment),we=ve(),pe(Me.$$.fragment),ot=ve(),pe(Fe.$$.fragment),hn=ve(),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(p,"class","a9s-outer"),f(p,"mask",`url(#${e[8]})`),f(p,"x",g=e[5].x),f(p,"y",O=e[5].y),f(p,"width",_=e[5].w),f(p,"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",C=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",N=e[5].y),f(E,"height",H=e[5].h),f(E,"width",1),f(j,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(j,"x",J=e[5].x),f(j,"y",W=e[5].y+e[5].h),f(j,"height",1),f(j,"width",x=e[5].w),f(ae,"class","a9s-edge-handle a9s-edge-handle-left"),f(ae,"x",Ne=e[5].x),f(ae,"y",ke=e[5].y),f(ae,"height",X=e[5].h),f(ae,"width",1)},m(K,B){V(K,t,B),Z(t,n),Z(n,i),Z(n,a),V(K,y,B),V(K,p,B),V(K,b,B),V(K,v,B),V(K,k,B),V(K,G,B),V(K,m,B),V(K,E,B),V(K,Q,B),V(K,j,B),V(K,se,B),V(K,ae,B),V(K,ge,B),he(te,K,B),V(K,we,B),he(Me,K,B),V(K,ot,B),he(Fe,K,B),V(K,hn,B),he(je,K,B),$=!0,dn||(ro=[ee(p,"pointerdown",function(){le(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(v,"pointerdown",function(){le(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(G,"pointerdown",function(){le(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),ee(E,"pointerdown",function(){le(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),ee(j,"pointerdown",function(){le(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),ee(ae,"pointerdown",function(){le(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],dn=!0)},p(K,B){e=K,(!$||B&64&&o!==(o=e[6].x))&&f(i,"x",o),(!$||B&64&&s!==(s=e[6].y))&&f(i,"y",s),(!$||B&64&&r!==(r=e[6].w))&&f(i,"width",r),(!$||B&64&&l!==(l=e[6].h))&&f(i,"height",l),(!$||B&32&&u!==(u=e[5].x))&&f(a,"x",u),(!$||B&32&&h!==(h=e[5].y))&&f(a,"y",h),(!$||B&32&&c!==(c=e[5].w))&&f(a,"width",c),(!$||B&32&&d!==(d=e[5].h))&&f(a,"height",d),(!$||B&32&&g!==(g=e[5].x))&&f(p,"x",g),(!$||B&32&&O!==(O=e[5].y))&&f(p,"y",O),(!$||B&32&&_!==(_=e[5].w))&&f(p,"width",_),(!$||B&32&&M!==(M=e[5].h))&&f(p,"height",M),(!$||B&2)&&f(v,"style",e[1]),(!$||B&32&&S!==(S=e[5].x))&&f(v,"x",S),(!$||B&32&&I!==(I=e[5].y))&&f(v,"y",I),(!$||B&32&&C!==(C=e[5].w))&&f(v,"width",C),(!$||B&32&&P!==(P=e[5].h))&&f(v,"height",P),(!$||B&32&&z!==(z=e[5].x))&&f(G,"x",z),(!$||B&32&&w!==(w=e[5].y))&&f(G,"y",w),(!$||B&32&&T!==(T=e[5].w))&&f(G,"width",T),(!$||B&32&&R!==(R=e[5].x+e[5].w))&&f(E,"x",R),(!$||B&32&&N!==(N=e[5].y))&&f(E,"y",N),(!$||B&32&&H!==(H=e[5].h))&&f(E,"height",H),(!$||B&32&&J!==(J=e[5].x))&&f(j,"x",J),(!$||B&32&&W!==(W=e[5].y+e[5].h))&&f(j,"y",W),(!$||B&32&&x!==(x=e[5].w))&&f(j,"width",x),(!$||B&32&&Ne!==(Ne=e[5].x))&&f(ae,"x",Ne),(!$||B&32&&ke!==(ke=e[5].y))&&f(ae,"y",ke),(!$||B&32&&X!==(X=e[5].h))&&f(ae,"height",X);const Nt={};B&32&&(Nt.x=e[5].x),B&32&&(Nt.y=e[5].y),B&8&&(Nt.scale=e[3]),te.$set(Nt);const It={};B&32&&(It.x=e[5].x+e[5].w),B&32&&(It.y=e[5].y),B&8&&(It.scale=e[3]),Me.$set(It);const Rt={};B&32&&(Rt.x=e[5].x+e[5].w),B&32&&(Rt.y=e[5].y+e[5].h),B&8&&(Rt.scale=e[3]),Fe.$set(Rt);const Lt={};B&32&&(Lt.x=e[5].x),B&32&&(Lt.y=e[5].y+e[5].h),B&8&&(Lt.scale=e[3]),je.$set(Lt)},i(K){$||(Y(te.$$.fragment,K),Y(Me.$$.fragment,K),Y(Fe.$$.fragment,K),Y(je.$$.fragment,K),$=!0)},o(K){F(te.$$.fragment,K),F(Me.$$.fragment,K),F(Fe.$$.fragment,K),F(je.$$.fragment,K),$=!1},d(K){K&&(U(t),U(y),U(p),U(b),U(v),U(k),U(G),U(m),U(E),U(Q),U(j),U(se),U(ae),U(ge),U(we),U(ot),U(hn)),de(te,K),de(Me,K),de(Fe,K),de(je,K),dn=!1,Ie(ro)}}}function cr(e){let t,n;return t=new vt({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[fr,({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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function hr(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[C,P]=_;if(O==="SHAPE")b+=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":{b+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;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 y(g){Ee.call(this,e,g)}function p(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=ct(i.bounds,2/a))},[s,r,l,a,u,i,o,h,c,d,y,p]}class yi extends Oe{constructor(t){super(),Ae(this,t,hr,cr,fe,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var _i=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(_i.call(e,n)&&++i&&!_i.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 dr=12,gr=(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],y=(h[0]+d[0])/2,p=(h[1]+d[1])/2,O=Math.sqrt(Math.pow(d[0]-y,2)+Math.pow(d[1]-p,2))>dr/t;return{point:[y,p],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 mi(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function wi(e,t,n){const i=e.slice();return i[33]=t[n],i[35]=n,i}function Ei(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 bi(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&&U(t)}}}function Ti(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=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,d){V(c,t,d),Z(t,n),Z(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=dt/c[3])&&f(l,"r",h)},d(c){c&&U(t)}}}function Ai(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(){le(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||(Y(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function Oi(e){let t,n,i=Ce(e[33].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=Ai(Ei(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=Ei(r,i,a);o[a]?(o[a].p(u,l),Y(o[a],1)):(o[a]=Ai(u),o[a].c(),Y(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)Y(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&&U(t),Ge(o,r)}}}function Mi(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g,O,_,M=e[6]!==void 0&&!e[7]&&bi(en(e)),b=e[6]!==void 0&&!e[7]&&Ti($t(e)),v=Ce(e[30].rings),S=[];for(let C=0;C<v.length;C+=1)S[C]=Oi(wi(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"),M&&M.c(),b&&b.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",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(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",p=De(e[30]))},m(C,P){V(C,t,P),Z(t,n),Z(n,i),Z(i,o),Z(i,u),M&&M.m(i,null),b&&b.m(n,null),Z(t,c),Z(t,y);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(){le(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),ee(y,"pointerup",e[13]),ee(y,"pointerdown",function(){le(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],O=!0)},p(C,P){if(e=C,(!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=bi(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=Ti($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(y,"style",e[1]),(!g||P[0]&32&&p!==(p=De(e[30])))&&f(y,"d",p),P[0]&268491048){v=Ce(e[30].rings);let k;for(k=0;k<v.length;k+=1){const G=wi(e,v,k);S[k]?(S[k].p(G,P),Y(S[k],1)):(S[k]=Oi(G),S[k].c(),Y(S[k],1),S[k].m(t,null))}for(be(),k=v.length;k<S.length;k+=1)I(k);Te()}},i(C){if(!g){for(let P=0;P<v.length;P+=1)Y(S[P]);g=!0}},o(C){S=S.filter(Boolean);for(let P=0;P<S.length;P+=1)F(S[P]);g=!1},d(C){C&&U(t),M&&M.d(),b&&b.d(),Ge(S,C),O=!1,Ie(_)}}}function vi(e){let t,n;return t=new ri({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){le(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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function pr(e){let t,n,i,o=Ce(e[5].polygons),s=[];for(let a=0;a<o.length;a+=1)s[a]=Mi(mi(e,o,a));const r=a=>F(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&vi(xt(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=ve(),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=Ce(a[5].polygons);let h;for(h=0;h<o.length;h+=1){const c=mi(a,o,h);s[h]?(s[h].p(c,u),Y(s[h],1)):(s[h]=Mi(c),s[h].c(),Y(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&&Y(l,1)):(l=vi(xt(a)),l.c(),Y(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)Y(s[u]);Y(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&&(U(t),U(n)),Ge(s,a),l&&l.d(a)}}}function yr(e){let t,n;return t=new vt({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[pr,({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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}const _r=250,mr=1e3,dt=4.5;function wr(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,y=!1,p,g=[];const O=()=>n(7,y=!0),_=()=>n(7,y=!1),M=E=>{if(g.length>0||!o.some(x=>x.visible)){n(6,d=void 0);return}const[R,N]=u.elementToImage(E.offsetX,E.offsetY),H=x=>Math.pow(x[0]-R,2)+Math.pow(x[1]-N,2),Q=Nn(i).reduce((x,se)=>H(se)<H(x)?se:x),j=o.filter(x=>x.visible).reduce((x,se)=>H(se.point)<H(x.point)?se:x),J=Math.pow(mr/h,2);H(Q)<J||H(j.point)<J?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,y=!0),E.preventDefault(),E.stopPropagation(),p=performance.now()},I=(E,R,N)=>H=>{if(!p||Ue||performance.now()-p>_r)return;const Q=J=>J.polygon===E&&J.ring===R&&J.point===N,j=g.some(Q);H.metaKey||H.ctrlKey||H.shiftKey?j?n(8,g=g.filter(J=>!Q(J))):n(8,g=[...g,{polygon:E,ring:R,point:N}]):j&&g.length>1?n(8,g=[{polygon:E,ring:R,point:N}]):j?n(8,g=[]):n(8,g=[{polygon:E,ring:R,point:N}]),b()},C=(E,R,N)=>{b();const H=E.geometry.polygons;let Q;if(R==="SHAPE")Q=H.map(j=>{const J=j.rings.map((x,se)=>({points:x.points.map((Ne,ke)=>[Ne[0]+N[0],Ne[1]+N[1]])})),W=ye(J[0].points);return{rings:J,bounds:W}});else{const[j,J,W,x]=R.split("-").map(se=>parseInt(se));Q=H.map((se,ae)=>{if(ae===J){const Ne=se.rings.map((X,ge)=>ge===W?{points:X.points.map((we,Me)=>Me===x?[we[0]+N[0],we[1]+N[1]]:we)}:X),ke=ye(Ne[0].points);return{rings:Ne,bounds:ke}}else return se})}return{...E,geometry:{polygons:Q,bounds:at(Q)}}},P=E=>async R=>{R.stopPropagation();const N=o[E],H=i.polygons.map((j,J)=>{if(J===N.elementIdx){const W=j.rings.map((se,ae)=>ae===N.ringIdx?{points:[...se.points.slice(0,N.pointIdx+1),N.point,...se.points.slice(N.pointIdx+1)]}:se),x=ye(W[0].points);return{rings:W,bounds:x}}else return j});r("change",{...l,geometry:{polygons:H,bounds:at(H)}}),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,H)=>{if(g.some(j=>j.polygon===H)){const j=N.rings.map((W,x)=>{const se=g.filter(ae=>ae.polygon===H&&ae.ring===x);return se.length&&W.points.length-se.length>=3?{points:W.points.filter((Ne,ke)=>!se.some(X=>X.point===ke))}:W}),J=ye(j[0].points);return{rings:j,bounds:J}}else return N});!Jt(i.polygons,E)&&(r("change",{...l,geometry:{polygons:E,bounds:at(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,N,{polygon:H,ring:Q,point:j})=>H===E&&Q===R&&j===N;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?[]:gr(i,h)),e.$$.dirty[0]&40&&n(9,s=ct(i.bounds,dt/h))},[l,a,u,h,c,i,d,y,g,s,o,O,_,v,S,I,C,P,G,z,w,T,m]}class Er extends Oe{constructor(t){super(),Ae(this,t,wr,yr,fe,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Si=new Map([[ne.RECTANGLE,yi],[ne.POLYGON,pi],[ne.MULTIPOLYGLON,Er]]),Ci=e=>Si.get(e.type),Ni=(e,t)=>Si.set(e,t);function br(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=tt(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 Ii extends Oe{constructor(t){super(),Ae(this,t,br,null,fe,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Tr(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=(y,p,g)=>{h==null||h.addEventListener(y,p,g),c.push(()=>h==null?void 0:h.removeEventListener(y,p,g))};return n(5,u=new r({target:s,props:{addEventListener:d,drawingMode:o,transform:l,viewportScale:a}})),u.$on("create",y=>i("create",y.detail)),()=>{c.forEach(y=>y()),u.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,o=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,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 Ri extends Oe{constructor(t){super(),Ae(this,t,Tr,null,fe,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Li(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),Z(t,n),Z(n,i),Z(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&&(U(t),U(u),U(h))}}}function Ar(e){let t,n=e[0]&&Li(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=Li(i),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&U(t),n&&n.d()}}}function Or(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,y,p,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,y=h[1]),n(3,p=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,y=Math.min(c[1],h[1])),n(3,p=Math.abs(c[0]-h[0])),n(4,g=Math.abs(c[1]-h[1])))},M=S=>{const I=S,C=performance.now()-u;if(r==="click"){if(C>300)return;h?b():(n(0,h=l.elementToImage(I.offsetX,I.offsetY)),c=h,n(1,d=h[0]),n(2,y=h[1]),n(3,p=1),n(4,g=1))}else h&&(C>300||p*g>100?(I.stopPropagation(),b()):(n(0,h=void 0),c=void 0))},b=()=>{if(p*g>15){const S={type:ne.RECTANGLE,geometry:{bounds:{minX:d,minY:y,maxX:d+p,maxY:y+g},x:d,y,w:p,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,y,p,g,i,v,s,r,l,a]}class ki extends Oe{constructor(t){super(),Ae(this,t,Or,Ar,fe,{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 Pi(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g=e[1]&&Di(e);return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),h=L("polygon"),d=L("polygon"),g&&g.c(),p=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",y=e[19])},m(O,_){V(O,t,_),Z(t,n),Z(n,i),Z(n,a),V(O,h,_),V(O,d,_),g&&g.m(O,_),V(O,p,_)},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&&y!==(y=O[19])&&f(d,"points",y),O[1]?g?g.p(O,_):(g=Di(O),g.c(),g.m(p.parentNode,p)):g&&(g.d(1),g=null)},d(O){O&&(U(t),U(h),U(d),U(p)),g&&g.d(O)}}}function Di(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&&U(t)}}}function Mr(e){let t,n=e[3]&&Pi(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=Pi(tn(i)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:q,o:q,d(i){i&&U(t),n&&n.d()}}}const vr=20,Sr=1500;function Cr(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=[],y,p,g=!1;const O=I=>{const C=I,{timeStamp:P,offsetX:k,offsetY:G}=C;if(c={timeStamp:P,offsetX:k,offsetY:G},a==="drag"&&d.length===0){const z=u.elementToImage(C.offsetX,C.offsetY);d.push(z),n(10,y=z)}},_=I=>{const C=I;if(p&&clearTimeout(p),d.length>0){if(n(10,y=u.elementToImage(C.offsetX,C.offsetY)),d.length>2){const P=lt(y,d[0])*h;n(1,g=P<vr)}C.pointerType==="touch"&&(p=setTimeout(()=>{b()},Sr))}},M=I=>{const C=I;if(p&&clearTimeout(p),a==="click"){const P=C.timeStamp-c.timeStamp,k=lt([c.offsetX,c.offsetY],[C.offsetX,C.offsetY]);if(P>300||k>15)return;if(g)v();else if(d.length===0){const G=u.elementToImage(C.offsetX,C.offsetY);d.push(G),n(10,y=G)}else d.push(y)}else{if(d.length===1&&lt(d[0],y)<=4){n(0,d=[]),n(10,y=void 0);return}C.stopImmediatePropagation(),g?v():d.push(y)}},b=()=>{if(!y)return;const I=d.slice(0,-1);if(I.length<3)return;const C={type:ne.POLYGON,geometry:{bounds:ye(d),points:I}};wt(C)>4&&(n(0,d=[]),n(10,y=void 0),r("create",C))},v=()=>{const I={type:ne.POLYGON,geometry:{bounds:ye(d),points:[...d]}};n(0,d=[]),n(10,y=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=y?g?d:[...d,y]:[]),e.$$.dirty&516&&n(3,s=o.length>0?ct(ye(o),2/h):void 0)},[d,g,o,s,i,S,l,a,u,h,y]}class Nr extends Oe{constructor(t){super(),Ae(this,t,Cr,Mr,fe,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const nn=new Map([["rectangle",{tool:ki}],["polygon",{tool:Nr}]]),on=()=>[...nn.keys()],sn=e=>nn.get(e),Ui=(e,t,n={})=>nn.set(e,{tool:t,opts:n});function Ir(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),Z(t,n),Z(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&&U(t)}}}function Rr(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=tt(o,r))},[o,i,l,a,u,h,s,r]}class Lr extends Oe{constructor(t){super(),Ae(this,t,Rr,Ir,fe,{annotation:0,geom:6,style:7})}}function Hi(e,t,n){const i=e.slice();return i[5]=t[n],i}function Vi(e){let t,n,i;return{c(){t=L("path"),i=L("path"),f(t,"class","a9s-outer"),f(t,"style",n=e[1]?"display:none;":void 0),f(t,"fill-rule","evenodd"),f(t,"d",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&&(U(t),U(i))}}}function kr(e){let t,n,i=Ce(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=Vi(Hi(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=Hi(s,i,l);o[l]?o[l].p(a,r):(o[l]=Vi(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&&U(t),Ge(o,s)}}}function Pr(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=tt(o,r))},[o,i,l,s,r]}class Dr extends Oe{constructor(t){super(),Ae(this,t,Pr,kr,fe,{annotation:0,geom:3,style:4})}}function Ur(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(Hr).join(" ")),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"points",e[2].map(Vr).join(" ")),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,l){V(r,t,l),Z(t,n),Z(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&&U(t)}}}const Hr=e=>e.join(","),Vr=e=>e.join(",");function Yr(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=tt(o,r))},[o,i,l,s,r]}class Br extends Oe{constructor(t){super(),Ae(this,t,Yr,Ur,fe,{annotation:0,geom:3,style:4})}}function Xr(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),Z(t,n),Z(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&&U(t)}}}function Fr(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=tt(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 jr extends Oe{constructor(t){super(),Ae(this,t,Fr,Xr,fe,{annotation:0,geom:6,style:7})}}function Gr(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("line"),o=L("line"),f(n,"class","a9s-outer"),f(n,"style",i=e[1]?"display:none;":void 0),f(n,"x1",e[2]),f(n,"y1",e[3]),f(n,"x2",e[4]),f(n,"y2",e[5]),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"x1",e[2]),f(o,"y1",e[3]),f(o,"x2",e[4]),f(o,"y2",e[5]),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,l){V(r,t,l),Z(t,n),Z(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&&U(t)}}}function zr(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[h,c]]=l;return e.$$set=d=>{"annotation"in d&&n(0,o=d.annotation),"geom"in d&&n(6,s=d.geom),"style"in d&&n(7,r=d.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,i=tt(o,r))},[o,i,a,u,h,c,s,r]}class Qr extends Oe{constructor(t){super(),Ae(this,t,zr,Gr,fe,{annotation:0,geom:6,style:7})}}const qr={elementToImage:(e,t)=>[e,t]},Yi=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]}}),Zr=250,Bi=(e,t)=>{const n=Ve();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<Zr){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 Xi(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 Fi(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 ji(e){let t=e[43],n,i,o=Gi(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&&fe(t,t=s[43])?(be(),F(o,1,1,q),Te(),o=Gi(s),o.c(),Y(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(Y(o),i=!0)},o(s){F(o),i=!1},d(s){s&&U(n),o.d(s)}}}function Kr(e){let t,n;return t=new Qr({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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function Wr(e){let t,n;return t=new Dr({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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function Jr(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){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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function xr(e){let t,n;return t=new jr({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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function $r(e){var i;let t,n;return t=new Lr({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||(Y(t.$$.fragment,o),n=!0)},o(o){F(t.$$.fragment,o),n=!1},d(o){de(t,o)}}}function Gi(e){let t,n,i,o;const s=[$r,xr,Jr,Wr,Kr],r=[];function l(a,u){var h,c,d,y,p;return((h=a[46])==null?void 0:h.type)===ne.ELLIPSE?0:((c=a[46])==null?void 0:c.type)===ne.RECTANGLE?1:((d=a[46])==null?void 0:d.type)===ne.POLYGON?2:((y=a[46])==null?void 0:y.type)===ne.MULTIPOLYGLON?3:((p=a[46])==null?void 0:p.type)===ne.LINE?4:-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()),Y(n,1),n.m(i.parentNode,i)):n=null)},i(a){o||(Y(n),o=!0)},o(a){F(n),o=!1},d(a){a&&U(i),~t&&r[t].d(a)}}}function zi(e){let t=ut(e[43])&&!e[9](e[43]),n,i,o=t&&ji(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=ut(s[43])&&!s[9](s[43])),t?o?(o.p(ln(s),r),r[0]&66048&&Y(o,1)):(o=ji(ln(s)),o.c(),Y(o,1),o.m(n.parentNode,n)):o&&(be(),F(o,1,1,()=>{o=null}),Te())},i(s){i||(Y(o),i=!0)},o(s){F(o),i=!1},d(s){s&&U(n),o&&o.d(s)}}}function Qi(e){let t,n,i,o;const s=[tl,el],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()),Y(n,1),n.m(i.parentNode,i)):n=null)},i(a){o||(Y(n),o=!0)},o(a){F(n),o=!1},d(a){a&&U(i),~t&&r[t].d(a)}}}function el(e){let t=`${e[2]}-${e[5]}`,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]&36&&fe(t,t=`${s[2]}-${s[5]}`)?(be(),F(o,1,1,q),Te(),o=qi(s),o.c(),Y(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(Y(o),i=!0)},o(s){F(o),i=!1},d(s){s&&U(n),o.d(s)}}}function tl(e){let t,n,i=Ce(e[8]),o=[];for(let r=0;r<i.length;r+=1)o[r]=Wi(Xi(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=Xi(r,i,a);o[a]?(o[a].p(u,l),Y(o[a],1)):(o[a]=Wi(u),o[a].c(),Y(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)Y(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&&U(t),Ge(o,r)}}}function qi(e){let t,n;return t=new Ri({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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function Zi(e){let t=e[39].id,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]&256&&fe(t,t=s[39].id)?(be(),F(o,1,1,q),Te(),o=Ki(s),o.c(),Y(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(Y(o),i=!0)},o(s){F(o),i=!1},d(s){s&&U(n),o.d(s)}}}function Ki(e){let t,n;return t=new Ii({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(){le(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||(Y(t.$$.fragment,i),n=!0)},o(i){F(t.$$.fragment,i),n=!1},d(i){de(t,i)}}}function Wi(e){let t,n,i=e[40]&&Zi(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&&Y(i,1)):(i=Zi(o),i.c(),Y(i,1),i.m(t.parentNode,t)):i&&(be(),F(i,1,1,()=>{i=null}),Te())},i(o){n||(Y(i),n=!0)},o(o){F(i),n=!1},d(o){o&&U(t),i&&i.d(o)}}}function nl(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]=zi(Fi(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),Z(t,n);for(let y=0;y<a.length;y+=1)a[y]&&a[y].m(n,null);Z(t,i),h&&h.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[ee(t,"pointerup",function(){le(e[10])&&e[10].apply(this,arguments)}),ee(t,"pointerdown",function(){le(e[11])&&e[11].apply(this,arguments)}),ee(t,"pointermove",e[23])],s=!0)},p(c,d){if(e=c,d[0]&66050){l=Ce(e[16].filter(e[34]));let y;for(y=0;y<l.length;y+=1){const p=Fi(e,l,y);a[y]?(a[y].p(p,d),Y(a[y],1)):(a[y]=zi(p),a[y].c(),Y(a[y],1),a[y].m(n,null))}for(be(),y=l.length;y<a.length;y+=1)u(y);Te()}e[6]?h?(h.p(e,d),d[0]&64&&Y(h,1)):(h=Qi(e),h.c(),Y(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)Y(a[d]);Y(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&&U(t),Ge(a,c),h&&h.d(),e[35](null),e[36](null),s=!1,Ie(r)}}}function il(e,t,n){let i,o,s,r,l,a,u,h,c,d,y,p=q,g=()=>(p(),p=yn(m,X=>n(17,y=X)),m);e.$$.on_destroy.push(()=>p());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:C=!0}=t,P=0;const k=()=>n(5,P+=1),G=()=>S,z=()=>O;let w,T,m;ze(()=>g(n(7,m=ii(_,T))));const{hover:E,selection:R,store:N}=b;kt(e,E,X=>n(15,h=X)),kt(e,R,X=>n(33,c=X)),kt(e,N,X=>n(16,d=X));let H,Q;const j=X=>{H&&N.unobserve(H);const ge=X.filter(({editable:te})=>te).map(({id:te})=>te);ge.length>0?(n(8,Q=ge.map(te=>N.getAnnotation(te)).filter(te=>te&&ut(te))),H=te=>{const{updated:we}=te.changes;n(8,Q=we==null?void 0:we.map(Me=>Me.newValue))},N.observe(H,{annotations:ge})):n(8,Q=void 0)},J=X=>{const ge=Kn(),te={id:ge,bodies:[],target:{annotation:ge,selector:X.detail,creator:I,created:new Date}};N.addAnnotation(te),R.setSelected(te.id)},W=X=>ge=>{var ot;const{target:te}=X,we=10*60*1e3,Me=((ot=te.creator)==null?void 0:ot.id)!==I.id||!te.created||new Date().getTime()-te.created.getTime()>we;N.updateTarget({...te,selector:ge.detail,created:Me?te.created:new Date,updated:Me?new Date:void 0,updatedBy:Me?I:void 0})},x=X=>{const{x:ge,y:te}=rn(X,T),we=N.getAt(ge,te);we?h!==we.id&&E.set(we.id):E.set(void 0)},se=X=>Ci(X),ae=X=>ut(X);function Ne(X){_t[X?"unshift":"push"](()=>{w=X,n(6,w)})}function ke(X){_t[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,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)||M),e.$$.dirty[0]&16&&n(12,r=Yi(T)),e.$$.dirty[0]&16&&n(11,{onPointerDown:l,onPointerUp:a}=Bi(T,N),l,(n(10,a),n(4,T))),e.$$.dirty[1]&4&&n(9,u=X=>c.selected.find(ge=>ge.id===X.id&&ge.editable)),e.$$.dirty[1]&4&&j(c.selected)},[O,v,S,C,T,P,w,m,Q,u,a,l,r,s,i,h,d,y,E,R,N,J,W,x,se,_,M,b,I,k,G,z,o,c,ae,Ne,ke]}class Ji extends Oe{constructor(t){super(),Ae(this,t,il,nl,fe,{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 xi(e,t,n=0,i=e.length-1,o=ol){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),y=Math.max(n,Math.floor(t-u*c/a+d)),p=Math.min(i,Math.floor(t+(a-u)*c/a+d));xi(e,t,y,p,o)}const s=e[t];let r=n,l=i;for(gt(e,n,t),o(e[i],s)>0&&gt(e,n,i);r<l;){for(gt(e,r,l),r++,l--;o(e[r],s)<0;)r++;for(;o(e[l],s)>0;)l--}o(e[n],s)===0?gt(e,n,l):(l++,gt(e,l,i)),l<=t&&(n=l+1),t<=l&&(i=l-1)}}function gt(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function ol(e,t){return e<t?-1:e>t?1:0}class sl{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=it([]),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=rl(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=it(t.slice(n,i+1)),nt(l,this.toBBox),l;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),l=it([]),l.leaf=!1,l.height=o;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));$i(t,n,i,u,this.compareMinX);for(let h=n;h<=i;h+=u){const c=Math.min(h+u-1,i);$i(t,h,c,a,this.compareMinY);for(let d=h;d<=c;d+=a){const y=Math.min(d+a-1,c);l.children.push(this._build(t,d,y,o-1))}}return nt(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=ul(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),yt(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=it(i.children.splice(r,i.children.length-r));l.height=i.height,l.leaf=i.leaf,nt(i,this.toBBox),nt(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(i,l)}_splitRoot(t,n){this.data=it([t,n]),this.data.height=t.height+1,this.data.leaf=!1,nt(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=pt(t,0,l,this.toBBox),u=pt(t,l,i,this.toBBox),h=fl(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:ll,s=t.leaf?this.compareMinY:al,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=pt(t,0,n,s),l=pt(t,i-n,i,s);let a=St(r)+St(l);for(let u=n;u<i-n;u++){const h=t.children[u];yt(r,t.leaf?s(h):h),a+=St(r)}for(let u=i-n-1;u>=n;u--){const h=t.children[u];yt(l,t.leaf?s(h):h),a+=St(l)}return a}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)yt(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():nt(t[n],this.toBBox)}}function rl(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 nt(e,t){pt(e,0,e.children.length,t,e)}function pt(e,t,n,i,o){o||(o=it(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];yt(o,e.leaf?i(r):r)}return o}function yt(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 ll(e,t){return e.minX-t.minX}function al(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 ul(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 fl(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 it(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function $i(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;xi(e,r,t,n,o),s.push(t,r,r,n)}}const cl=()=>{const e=new sl,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!ft(c))return;const{minX:d,minY:y,maxX:p,maxY:g}=c.selector.geometry.bounds,O={minX:d,minY:y,maxX:p,maxY:g,target:c};e.insert(O),t.set(c.annotation,O)},s=c=>{if(!ft(c))return;const d=t.get(c.annotation);d&&e.remove(d),t.delete(c.annotation)};return{all:n,clear:i,getAt:(c,d,y,p=0)=>{const O=e.search({minX:c-p,minY:d-p,maxX:c+p,maxY:d+p}).map(_=>_.target).filter(_=>_.selector.type===ne.RECTANGLE||Sn(_.selector,c,d,p));return O.length>0?(O.sort((_,M)=>wt(_.selector)-wt(M.selector)),O):[]},getIntersecting:(c,d,y,p)=>e.search({minX:c,minY:d,maxX:c+y,maxY:d+p}).map(g=>g.target),insert:o,remove:s,set:(c,d=!0)=>{d&&i();const y=c.reduce((p,g)=>{if(ft(g)){const{minX:O,minY:_,maxX:M,maxY:b}=g.selector.geometry.bounds;return[...p,{minX:O,minY:_,maxX:M,maxY:b,target:g}]}else return p},[]);y.forEach(p=>t.set(p.target.annotation,p)),e.load(y)},size:()=>e.all().length,update:(c,d)=>{s(c),o(d)}}},eo=e=>{const t=Ts(),n=cl(),i=as(t,e.userSelectAction,e.adapter),o=ls(t),s=Ss();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,c)=>{const d=n.getAt(a,u,h,c);if(h)return d.map(p=>t.getAnnotation(p.annotation)).filter(Boolean).filter(h)[0];{const y=d[0];return y?t.getAnnotation(y.annotation):void 0}},getIntersecting:(a,u,h,c)=>n.getIntersecting(a,u,h,c).map(d=>t.getAnnotation(d.annotation)).filter(Boolean)},selection:i,hover:o,viewport:s}},to=e=>{const t=eo(e);return{...t,store:As(t.store)}},no=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},io=e=>{const t=no(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"?io(e):n),oo=(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,so=(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}},hl=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=oo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:zt.EDIT,theme:"light"}),o=to(i),{selection:s,store:r}=o,l=vs(r,i.initialHistory),a=Cs(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=so(l);let c=Vs();fn(n,u,i.theme);const d=new Ji({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 y=Is(o,l,i.adapter),p=()=>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)=>Ui(w,T,m),v=(w,T)=>Ni(w,T),S=w=>{if(!sn(w))throw`No drawing tool named ${w}`;d.$set({toolName:w})},I=w=>d.$set({drawingEnabled:w}),C=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{...y,cancelDrawing:p,destroy:g,getDrawingTool:O,getUser:_,isDrawingEnabled:M,listDrawingTools:on,on:a.on,off:a.off,registerDrawingTool:b,registerShapeEditor:v,setDrawingEnabled:I,setDrawingTool:S,setFilter:C,setStyle:P,setTheme:k,setUser:G,setVisible:z,element:u,state:o}};D.Editor=vt,D.EditorMount=Ii,D.Handle=Ze,D.IdentityTransform=qr,D.PolygonEditor=pi,D.RectangleEditor=yi,D.RectangleUtil=In,D.RubberbandRectangle=ki,D.SVGAnnotationLayer=Ji,D.ShapeType=ne,D.ToolMount=Ri,D.UserSelectAction=zt,D.W3CImageFormat=Gs,D.addEventListeners=Bi,D.boundsFromMultiPolygonElements=at,D.boundsFromPoints=ye,D.chainStyles=Ls,D.computeArea=wt,D.computePolygonArea=Et,D.computeStyle=Rs,D.createBody=gs,D.createImageAnnotator=hl,D.createImageAnnotatorState=eo,D.createSVGTransform=Yi,D.createSvelteImageAnnotatorState=to,D.defaultColorProvider=js,D.detectTheme=io,D.distance=lt,D.enableResponsive=ii,D.fillDefaults=oo,D.getAllCorners=Nn,D.getEditor=Ci,D.getMaskDimensions=ct,D.getSVGPoint=rn,D.getTool=sn,D.initKeyboardCommands=so,D.intersects=Sn,D.isImageAnnotation=ut,D.isImageAnnotationTarget=ft,D.isMac=cn,D.isPointInPolygon=bt,D.isTouch=Ue,D.listDrawingTools=on,D.multipolygonElementToPath=De,D.parseFragmentSelector=Rn,D.parseSVGSelector=Qn,D.parseW3CImageAnnotation=ti,D.pointsToPath=Cn,D.registerEditor=Ni,D.registerShapeUtil=xe,D.registerTool=Ui,D.sampleBrightness=no,D.serializeFragmentSelector=Ln,D.serializeSVGSelector=qn,D.serializeW3CImageAnnotation=ni,D.setTheme=fn,D.simplifyMultiPolygon=Mo,D.simplifyPoints=Vt,D.simplifyPolygon=So,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 Al=Object.defineProperty;var Ol=(D,q,He)=>q in D?Al(D,q,{enumerable:!0,configurable:!0,writable:!0,value:He}):D[q]=He;var re=(D,q,He)=>Ol(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 yn(e){return e()}function _n(){return Object.create(null)}function Ne(e){e.forEach(yn)}function le(e){return typeof e=="function"}function fe(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function co(e){return Object.keys(e).length===0}function mn(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 Pt(e,t,n){e.$$.on_destroy.push(mn(t,n))}function ho(e,t,n,i){if(e){const o=wn(e,t,n,i);return e[0](o)}}function wn(e,t,n,i){return e[1]&&i?He(n.ctx.slice(),e[1](i(t))):n.ctx}function go(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 po(e,t,n,i,o,s){if(o){const r=wn(t,n,i,s);e.p(r,o)}}function yo(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 En(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function wt(e){return e??""}function Z(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 bn(e){return document.createTextNode(e)}function Oe(){return bn(" ")}function Ie(){return bn("")}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 _o(e){return Array.from(e.childNodes)}function Pe(e,t,n){e.classList.toggle(t,!!n)}function mo(e,t,{bubbles:n=!1,cancelable:i=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:i})}let st;function rt(e){st=e}function Tn(){if(!st)throw new Error("Function called outside component initialization");return st}function ze(e){Tn().$$.on_mount.push(e)}function Ve(){const e=Tn();return(t,n,{cancelable:i=!1}={})=>{const o=e.$$.callbacks[t];if(o){const s=mo(t,n,{cancelable:i});return o.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function Te(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(i=>i.call(this,t))}const Je=[],Et=[];let xe=[];const An=[],On=Promise.resolve();let Dt=!1;function Mn(){Dt||(Dt=!0,On.then(Sn))}function vn(){return Mn(),On}function Ut(e){xe.push(e)}const Ht=new Set;let $e=0;function Sn(){if($e!==0)return;const e=st;do{try{for(;$e<Je.length;){const t=Je[$e];$e++,rt(t),wo(t.$$)}}catch(t){throw Je.length=0,$e=0,t}for(rt(null),Je.length=0,$e=0;Et.length;)Et.pop()();for(let t=0;t<xe.length;t+=1){const n=xe[t];Ht.has(n)||(Ht.add(n),n())}xe.length=0}while(Je.length);for(;An.length;)An.pop()();Dt=!1,Ht.clear(),rt(e)}function wo(e){if(e.fragment!==null){e.update(),Ne(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Ut)}}function Eo(e){const t=[],n=[];xe.forEach(i=>e.indexOf(i)===-1?t.push(i):n.push(i)),n.forEach(i=>i()),xe=t}const bt=new Set;let qe;function Me(){qe={r:0,c:[],p:qe}}function ve(){qe.r||Ne(qe.c),qe=qe.p}function B(e,t){e&&e.i&&(bt.delete(e),e.i(t))}function j(e,t,n,i){if(e&&e.o){if(bt.has(e))return;bt.add(e),qe.c.push(()=>{bt.delete(e),i&&(n&&e.d(1),i())}),e.o(t)}else i&&i()}function Se(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ge(e){e&&e.c()}function ce(e,t,n){const{fragment:i,after_update:o}=e.$$;i&&i.m(t,n),Ut(()=>{const s=e.$$.on_mount.map(yn).filter(le);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ne(s),e.$$.on_mount=[]}),o.forEach(Ut)}function he(e,t){const n=e.$$;n.fragment!==null&&(Eo(n.after_update),Ne(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function bo(e,t){e.$$.dirty[0]===-1&&(Je.push(e),Mn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function ye(e,t,n,i,o,s,r=null,l=[-1]){const a=st;rt(e);const u=e.$$={fragment:null,ctx:[],props:s,update:q,not_equal:o,bound:_n(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:_n(),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,...y)=>{const p=y.length?y[0]:d;return u.ctx&&o(u.ctx[c],u.ctx[c]=p)&&(!u.skip_bound&&u.bound[c]&&u.bound[c](p),h&&bo(e,c)),d}):[],u.update(),h=!0,Ne(u.before_update),u.fragment=i?i(u.ctx):!1,t.target){if(t.hydrate){const c=_o(t.target);u.fragment&&u.fragment.l(c),c.forEach(H)}else u.fragment&&u.fragment.c();t.intro&&B(e.$$.fragment),ce(e,t.target,t.anchor),Sn()}rt(a)}class _e{constructor(){re(this,"$$");re(this,"$$set")}$destroy(){he(this,1),this.$destroy=q}$on(t,n){if(!le(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&&!co(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const To="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(To);var te=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(te||{});function Ao(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var Cn={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,y=u.y-c;if(d!==0||y!==0){var p=((l.x-h)*d+(l.y-c)*y)/(d*d+y*y);p>1?(h=u.x,c=u.y):p>0&&(h+=d*p,c+=y*p)}return d=l.x-h,y=l.y-c,d*d+y*y}function i(l,a){for(var u=l[0],h=[u],c,d=1,y=l.length;d<y;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,y,p=a+1;p<u;p++){var g=n(l[p],l[a],l[u]);g>d&&(y=p,d=g)}d>h&&(y-a>1&&o(l,a,y,h,c),c.push(l[y]),u-y>1&&o(l,y,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})()})(Cn);var Oo=Cn.exports;const Mo=Ao(Oo),Vt={},Qe=(e,t)=>Vt[e]=t,Tt=e=>Vt[e.type].area(e),Nn=(e,t,n,i)=>Vt[e.type].intersects(e,t,n,i),me=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}},lt=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)},at=(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},In=(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},Yt=(e,t=1)=>{const n=e.map(([i,o])=>({x:i,y:o}));return Mo(n,t,!0).map(i=>[i.x,i.y])},ut=(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))},vo={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,y=u*h-a*c;return d*d/(s*s)+y*y/(r*r)<=1}};Qe(te.ELLIPSE,vo);const So={area:e=>0,intersects:(e,t,n,i=2)=>{const[[o,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-o)*n+r*s-l*o),u=ut([o,s],[r,l]);return a/u<=i}};Qe(te.LINE,So);const Co={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,i)=>{const[o,...s]=i.rings,r=lt(o.points),l=s.reduce((a,u)=>a+lt(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(at(s.points,t,n)){let l=!1;for(const a of r)if(at(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},ft=e=>{const t=e.reduce((n,i)=>[...n,...i.rings[0].points],[]);return me(t)},De=e=>e.rings.map(n=>In(n.points)).join(" "),Ln=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((i,o)=>[...i,...o.points],[])],[]),No=(e,t=1)=>{const n=e.geometry.polygons.map(o=>{const s=o.rings.map(l=>{const a=Yt(l.points,t);return{...l,points:a}}),r=me(s[0].points);return{...o,rings:s,bounds:r}}),i=ft(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:i}}};Qe(te.MULTIPOLYGON,Co);const Io={area:e=>{const t=e.geometry.points;return lt(t)},intersects:(e,t,n)=>{const i=e.geometry.points;return at(i,t,n)}},Lo=(e,t=1)=>{const n=Yt(e.geometry.points,t),i=me(n);return{...e,geometry:{...e.geometry,bounds:i,points:n}}};Qe(te.POLYGON,Io);const Ro={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=Bt(t);return lt(n)},intersects:(e,t,n,i=2)=>{const o=e.geometry;if(o.closed){const s=Bt(o);return at(s,t,n)}else return ko(o,[t,n],i)}},Bt=e=>{const t=[];for(let n=0;n<e.points.length;n++){const i=e.points[n],o=e.points[(n+1)%e.points.length];if(t.push(i.point),(n<e.points.length-1||e.closed)&&(i.outHandle||o.inHandle)){const r=Rn(i.point,i.outHandle||i.point,o.inHandle||o.point,o.point,10);t.push(...r.slice(1))}}return t},Rn=(e,t,n,i,o=10)=>{const s=[];for(let r=0;r<=o;r++){const l=r/o,a=Math.pow(1-l,3)*e[0]+3*Math.pow(1-l,2)*l*t[0]+3*(1-l)*Math.pow(l,2)*n[0]+Math.pow(l,3)*i[0],u=Math.pow(1-l,3)*e[1]+3*Math.pow(1-l,2)*l*t[1]+3*(1-l)*Math.pow(l,2)*n[1]+Math.pow(l,3)*i[1];s.push([a,u])}return s},ko=(e,t,n)=>{for(let i=0;i<e.points.length-1;i++){const o=e.points[i],s=e.points[i+1];if(o.outHandle||s.inHandle){const l=Rn(o.point,o.outHandle||o.point,s.inHandle||s.point,s.point,20);for(let a=0;a<l.length-1;a++)if(kn(t,l[a],l[a+1])<=n)return!0}else if(kn(t,o.point,s.point)<=n)return!0}return!1},kn=(e,t,n)=>{const[i,o]=e,[s,r]=t,[l,a]=n,u=l-s,h=a-r,c=Math.sqrt(u*u+h*h);if(c===0)return Math.sqrt((i-s)*(i-s)+(o-r)*(o-r));const d=((i-s)*u+(o-r)*h)/(c*c);return d<=0?Math.sqrt((i-s)*(i-s)+(o-r)*(o-r)):d>=1?Math.sqrt((i-l)*(i-l)+(o-a)*(o-a)):Math.abs((a-r)*i-(l-s)*o+l*r-a*s)/c},Pn=e=>{if(!e.points||e.points.length===0)return"";const t=[],n=e.points[0];t.push(`M ${n.point[0]} ${n.point[1]}`);for(let i=1;i<e.points.length;i++){const o=e.points[i],s=e.points[i-1];if(o.type==="CURVE"||s.type==="CURVE"){const r=s.outHandle||s.point,l=o.inHandle||o.point,a=o.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}else t.push(`L ${o.point[0]} ${o.point[1]}`)}if(e.closed){const i=e.points[e.points.length-1],o=e.points[0];if(i.outHandle||o.inHandle){const r=i.outHandle||i.point,l=o.inHandle||o.point,a=o.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Qe(te.POLYLINE,Ro);const Dn={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};Qe(te.RECTANGLE,Dn);const ct=e=>ht(e.target),ht=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},Un=(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,y,p,g]=[a,u,h,c].map(parseFloat);return{type:te.RECTANGLE,geometry:{x:d,y,w:p,h:g,bounds:{minX:d,minY:t?y-g:y,maxX:d+p,maxY:t?y:y+g}}}},Hn=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}`}},Vn="http://www.w3.org/2000/svg",Yn=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},Po=e=>{const i=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${Vn}">`);return new DOMParser().parseFromString(i,"image/svg+xml").documentElement},Xt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),i=n.lookupPrefix(Vn),o=n.lookupNamespaceURI(null);return i||o?Yn(n).firstChild:Yn(Po(n)).firstChild},de=" ";function Do(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+de+i.y;else if(i.type===A.LINE_TO)t+=(i.relative?"l":"L")+i.x+de+i.y;else if(i.type===A.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+de+i.y1+de+i.x2+de+i.y2+de+i.x+de+i.y;else if(i.type===A.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+de+i.y2+de+i.x+de+i.y;else if(i.type===A.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+de+i.y1+de+i.x+de+i.y;else if(i.type===A.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+de+i.y;else if(i.type===A.ARC)t+=(i.relative?"a":"A")+i.rX+de+i.rY+de+i.xRot+de+ +i.lArcFlag+de+ +i.sweepFlag+de+i.x+de+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${n}.`)}return t}function Ft([e,t],n){return[e*Math.cos(n)-t*Math.sin(n),e*Math.sin(n)+t*Math.cos(n)]}function Le(...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 jt(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]=Ft([(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)),y=i*u/o*d,p=-o*a/i*d,g=Ft([y,p],l);e.cX=g[0]+(t+s)/2,e.cY=g[1]+(n+r)/2,e.phi1=Math.atan2((u-p)/o,(a-y)/i),e.phi2=Math.atan2((-u-p)/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 Bn(e,t,n){Le(e,t,n);const i=e*e+t*t-n*n;if(0>i)return[];if(i===0)return[[e*n/(e*e+t*t),t*n/(e*e+t*t)]];const o=Math.sqrt(i);return[[(e*n+t*o)/(e*e+t*t),(t*n-e*o)/(e*e+t*t)],[(e*n-t*o)/(e*e+t*t),(t*n+e*o)/(e*e+t*t)]]}const Ze=Math.PI/180;function Xn(e,t,n){return(1-n)*e+n*t}function Fn(e,t,n,i){return e+Math.cos(i/180*Ye)*t+Math.sin(i/180*Ye)*n}function jn(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]:Uo(u/a,h/a,1e-6)}function Gn(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 Uo(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 Ho(e,t,n){e.cX||jt(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,y)=>{const[p,g]=Ft([d*e.rX,y*e.rY],i);return[e.cX+p,e.cY+g]};for(let d=0;d<l;d++){const y=Xn(e.phi1,e.phi2,d/l),p=Xn(e.phi1,e.phi2,(d+1)/l),g=p-y,v=4/3*Math.tan(g*Ze/4),_=Math.cos(y*Ze)-v*Math.sin(y*Ze),O=Math.sin(y*Ze)+v*Math.cos(y*Ze),b=Math.cos(p*Ze),M=Math.sin(p*Ze),S=b+v*M,N=M-v*b,C=c(_,O),U=c(S,N),k=c(b,M),G={relative:e.relative,type:A.CURVE_TO,x:k[0],y:k[1],x1:C[0],y1:C[1],x2:U[0],y2:U[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 At(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 Vo(e){if(e.length<=2)return e;const t=[],n=e.map(ue.INFO((o,s,r)=>{const l="relative"in o&&o.relative;return["x"in o?o.x+(l?s:0):s,"y"in o?o.y+(l?r:0):r]}));let i=n[0];t.push(e[0]);for(let o=1;o<e.length;o++){const s=e[o],r=e[o+1];if(o<e.length-1&&r&&s.type&A.LINE_COMMANDS&&r.type&A.LINE_COMMANDS){const l=n[o+1];if(At(i,n[o],l)){"relative"in r&&r.relative&&("x"in r&&(r.x=l[0]-i[0]),"y"in r&&(r.y=l[1]-i[1]));continue}}t.push(s),i=n[o]}return t}function Yo(e,t=!0){if(e.length<2)return e;const n=ue.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(...Ot(o)):i.unshift(...Ot(o)),o=[]),o.push(r)}return o.length>0&&(t?i.push(...Ot(o)):i.unshift(...Ot(o))),i}function Ot(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 Bo(e=1e13){Le(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 zn(){return Re((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 Xo(){return Re((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 Fo(e=!0,t=!0,n=!0,i=!0){return Re((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];At(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];At(u,h,d)&&At(u,c,d)&&(o.type=A.LINE_TO,delete o.x1,delete o.y1,delete o.x2,delete o.y2)}return o})}function qn(){let e=NaN,t=NaN,n=NaN,i=NaN;return Re((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 Qn(){let e=NaN,t=NaN;return Re((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 Re(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 jo(e=0){Le(e);let t=NaN,n=NaN,i=NaN,o=NaN;return Re((s,r,l,a,u)=>{const h=Math.abs;let c=!1,d=0,y=0;if(s.type&A.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:r-t,y=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 p=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,y=isNaN(o)?typeof s.y1>"u"?y:s.relative?s.y:s.y1-l:o-l;const v=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(p)<=e&&h(g)<=e&&h(d)<=e&&h(y)<=e&&h(v)<=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 Le(e,t,n,i,o,s),Re((r,l,a,u)=>{const h=r.x1,c=r.x2,d=r.relative&&!isNaN(u),y=typeof r.x<"u"?r.x:d?0:l,p=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+p*n+(d?0:o)),typeof r.y<"u"&&(r.y=y*t+r.y*i+(d?0:s)),typeof r.x1<"u"&&(r.x1=r.x1*e+r.y1*n+(d?0:o)),typeof r.y1<"u"&&(r.y1=h*t+r.y1*i+(d?0:s)),typeof r.x2<"u"&&(r.x2=r.x2*e+r.y2*n+(d?0:o)),typeof r.y2<"u"&&(r.y2=c*t+r.y2*i+(d?0:s));function g(_){return _*_}const v=e*i-t*n;if(typeof r.xRot<"u"&&(e!==1||t!==0||n!==0||i!==1))if(v===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,O=Math.sin(_),b=Math.cos(_),M=1/g(r.rX),S=1/g(r.rY),N=g(b)*M+g(O)*S,C=2*O*b*(M-S),U=g(O)*M+g(b)*S,k=N*i*i-C*t*i+U*t*t,G=C*(e*i+t*n)-2*(N*n*i+U*e*t),z=N*n*n-C*e*n+U*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(v)/Math.sqrt(k*g(m)+G*T*m+z*g(T)),r.rY=Math.abs(v)/Math.sqrt(k*g(T)-G*T*m+z*g(m)),r.xRot=w*180/Math.PI}return typeof r.sweepFlag<"u"&&0>v&&(r.sweepFlag=+!r.sweepFlag),r})}function Go(e,t=0,n=0){Le(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 zo(e,t=0){return Le(e,t),Be(1,0,0,1,e,t)}function qo(e,t=e){return Le(e,t),Be(e,0,0,t,0,0)}function Qo(e){return Le(e),Be(1,0,Math.tan(e),1,0,0)}function Zo(e){return Le(e),Be(1,Math.tan(e),0,1,0,0)}function Ko(e=0){return Le(e),Be(-1,0,0,1,e,0)}function Wo(e=0){return Le(e),Be(1,0,0,-1,0,e)}function Jo(){return Re((e,t,n)=>A.ARC===e.type?Ho(e,e.relative?0:t,e.relative?0:n):e)}function xo(){return Re((e,t,n)=>(e.relative&&(t=0,n=0),A.ARC===e.type&&jt(e,t,n),e))}function Zn(){return e=>({...e})}function $o(){const e=Zn(),t=zn(),n=Qn(),i=qn(),o=Re((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=jn(r,a.x1,a.x2,a.x);for(const y of c)0<y&&1>y&&u(Gn(r,a.x1,a.x2,a.x,y));const d=jn(l,a.y1,a.y2,a.y);for(const y of d)0<y&&1>y&&h(Gn(l,a.y1,a.y2,a.y,y))}if(a.type&A.ARC){u(a.x),h(a.y),jt(a,r,l);const c=a.xRot/180*Math.PI,d=Math.cos(c)*a.rX,y=Math.sin(c)*a.rX,p=-Math.sin(c)*a.rY,g=Math.cos(c)*a.rY,[v,_]=a.phi1<a.phi2?[a.phi1,a.phi2]:-180>a.phi2?[a.phi2+360,a.phi1+360]:[a.phi2,a.phi1],O=([S,N])=>{const U=Math.atan2(N,S)*180/Math.PI;return U<v?U+360:U},b=Bn(p,-d,0).map(O);for(const S of b)S>v&&S<_&&u(Fn(a.cX,d,p,S));const M=Bn(g,-y,0).map(O);for(const S of M)S>v&&S<_&&h(Fn(a.cY,y,g,S))}return s});return o.minX=1/0,o.maxX=-1/0,o.minY=1/0,o.maxY=-1/0,o}const ue={ROUND:Bo,TO_ABS:zn,TO_REL:Xo,NORMALIZE_HVZ:Fo,NORMALIZE_ST:qn,QT_TO_C:Qn,INFO:Re,SANITIZE:jo,MATRIX:Be,ROTATE:Go,TRANSLATE:zo,SCALE:qo,SKEW_X:Qo,SKEW_Y:Zo,X_AXIS_SYMMETRY:Ko,Y_AXIS_SYMMETRY:Wo,A_TO_C:Jo,ANNOTATE_ARCS:xo,CLONE:Zn,CALCULATE_BOUNDS:$o,REVERSE_PATH:Yo,REMOVE_COLLINEAR:Vo};class Kn{round(t){return this.transform(ue.ROUND(t))}toAbs(){return this.transform(ue.TO_ABS())}toRel(){return this.transform(ue.TO_REL())}normalizeHVZ(t,n,i){return this.transform(ue.NORMALIZE_HVZ(t,n,i))}normalizeST(){return this.transform(ue.NORMALIZE_ST())}qtToC(){return this.transform(ue.QT_TO_C())}aToC(){return this.transform(ue.A_TO_C())}sanitize(t){return this.transform(ue.SANITIZE(t))}translate(t,n){return this.transform(ue.TRANSLATE(t,n))}scale(t,n){return this.transform(ue.SCALE(t,n))}rotate(t,n,i){return this.transform(ue.ROTATE(t,n,i))}matrix(t,n,i,o,s,r){return this.transform(ue.MATRIX(t,n,i,o,s,r))}skewX(t){return this.transform(ue.SKEW_X(t))}skewY(t){return this.transform(ue.SKEW_Y(t))}xSymmetry(t){return this.transform(ue.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(ue.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(ue.ANNOTATE_ARCS())}}const es=e=>e===" "||e===" "||e==="\r"||e===`
2
+ `,Wn=e=>48<=e.charCodeAt(0)&&e.charCodeAt(0)<=57;class ts extends Kn{constructor(){super();re(this,"curNumber","");re(this,"curCommandType",-1);re(this,"curCommandRelative",!1);re(this,"canParseCommandOrComma",!0);re(this,"curNumberHasExp",!1);re(this,"curNumberHasExpDigits",!1);re(this,"curNumberHasDecimal",!1);re(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=Wn(r)&&(this.curNumber==="0"&&r==="0"||l);if(Wn(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===ns[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(!es(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 ie=class ie extends Kn{constructor(n){super();re(this,"commands");typeof n=="string"?this.commands=ie.parse(n):this.commands=n}encode(){return ie.encode(this.commands)}getBounds(){const n=ue.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=ue.REVERSE_PATH(this.commands,n),this}removeCollinear(){return this.commands=ue.REMOVE_COLLINEAR(this.commands),this}static encode(n){return Do(n)}static parse(n){const i=new ts,o=[];return i.parse(n,o),i.finish(o),o}};re(ie,"CLOSE_PATH",1),re(ie,"MOVE_TO",2),re(ie,"HORIZ_LINE_TO",4),re(ie,"VERT_LINE_TO",8),re(ie,"LINE_TO",16),re(ie,"CURVE_TO",32),re(ie,"SMOOTH_CURVE_TO",64),re(ie,"QUAD_TO",128),re(ie,"SMOOTH_QUAD_TO",256),re(ie,"ARC",512),re(ie,"LINE_COMMANDS",ie.LINE_TO|ie.HORIZ_LINE_TO|ie.VERT_LINE_TO),re(ie,"DRAWING_COMMANDS",ie.HORIZ_LINE_TO|ie.VERT_LINE_TO|ie.LINE_TO|ie.CURVE_TO|ie.SMOOTH_CURVE_TO|ie.QUAD_TO|ie.SMOOTH_QUAD_TO|ie.ARC);let A=ie;const ns={[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},is=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=me(n[0].points);return{rings:n,bounds:s}}},os=e=>{const[t,n,i]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],o=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:te.POLYGON,geometry:{points:o,bounds:me(o)}}},ss=e=>{const t=Xt(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:te.ELLIPSE,geometry:{cx:n,cy:i,rx:o,ry:s,bounds:r}}},rs=e=>{const t=Xt(e),n=parseFloat(t.getAttribute("x1")),i=parseFloat(t.getAttribute("x2")),o=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,i),minY:Math.min(o,s),maxX:Math.max(n,i),maxY:Math.max(o,s)};return{type:te.LINE,geometry:{points:[[n,o],[i,s]],bounds:r}}},ls=e=>{const t=Xt(e),o=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>is(a)).filter(Boolean),s=o.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=me(s);return o.length===1&&o[0].rings.length===1?{type:te.POLYGON,geometry:{points:s,bounds:r}}:{type:te.MULTIPOLYGON,geometry:{polygons:o,bounds:r}}},Jn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return os(t);if(t.includes("<path "))return ls(t);if(t.includes("<ellipse "))return ss(t);if(t.includes("<line "))return rs(t);throw"Unsupported SVG shape: "+t},as=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${De(n)}" />`).join("")}</g>`,xn=e=>{let t;switch(e.type){case te.POLYGON:{const n=e.geometry,{points:i}=n;t=`<svg><polygon points="${i.map(o=>o.join(",")).join(" ")}" /></svg>`;break}case te.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case te.MULTIPOLYGON:{const n=e.geometry;t=`<svg>${as(n)}</svg>`;break}case te.LINE:{const n=e.geometry,[[i,o],[s,r]]=n.points;t=`<svg><line x1="${i}" y1="${o}" x2="${s}" y2="${r}" /></svg>`;break}}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},we=[];for(let e=0;e<256;++e)we.push((e+256).toString(16).slice(1));function us(e,t=0){return(we[e[t+0]]+we[e[t+1]]+we[e[t+2]]+we[e[t+3]]+"-"+we[e[t+4]]+we[e[t+5]]+"-"+we[e[t+6]]+we[e[t+7]]+"-"+we[e[t+8]]+we[e[t+9]]+"-"+we[e[t+10]]+we[e[t+11]]+we[e[t+12]]+we[e[t+13]]+we[e[t+14]]+we[e[t+15]]).toLowerCase()}let Gt;const fs=new Uint8Array(16);function cs(){if(!Gt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Gt=crypto.getRandomValues.bind(crypto)}return Gt(fs)}const $n={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function ei(e,t,n){var o;if($n.randomUUID&&!e)return $n.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??cs();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,us(i)}var ti=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(ti.call(e,n)&&++i&&!ti.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 zt(){}function hs(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const et=[];function qt(e,t=zt){let n;const i=new Set;function o(l){if(hs(e,l)&&(e=l,n)){const a=!et.length;for(const u of i)u[1](),et.push(u,e);if(a){for(let u=0;u<et.length;u+=2)et[u][0](et[u+1]);et.length=0}}}function s(l){o(l(e))}function r(l,a=zt){const u=[l,a];return i.add(u),i.size===1&&(n=t(o,s)||zt),l(e),()=>{i.delete(u),i.size===0&&n&&(n(),n=null)}}return{set:o,update:s,subscribe:r}}const ds=e=>{const{subscribe:t,set:n}=qt();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 Qt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Qt||{});const Mt={selected:[]},gs=(e,t,n)=>{const{subscribe:i,set:o}=qt(Mt);let s=t,r=Mt;i(g=>r=g);const l=()=>{Xe(r,Mt)||o(Mt)},a=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(a())return!1;const v=typeof g=="string"?g:g.id;return r.selected.some(_=>_.id===v)},h=(g,v)=>{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(M=>M.id===b)));return}}else{const b=e.getAnnotation(g);if(!b){console.warn("Invalid selection: "+g);return}_=[b]}const O=_.reduce((b,M)=>{const S=p(M);return S==="EDIT"?[...b,{id:M.id,editable:!0}]:S==="SELECT"?[...b,{id:M.id}]:b},[]);o({selected:O,event:v})},c=(g,v)=>{const _=Array.isArray(g)?g:[g],O=_.map(b=>e.getAnnotation(b)).filter(b=>!!b);o({selected:O.map(b=>{const M=v===void 0?p(b)==="EDIT":v;return{id:b.id,editable:M}})}),O.length!==_.length&&console.warn("Invalid selection",g)},d=g=>{if(a())return!1;const{selected:v}=r;v.some(({id:_})=>g.includes(_))&&o({selected:v.filter(({id:_})=>!g.includes(_))})},y=g=>{s=g,c(r.selected.map(({id:v})=>v))},p=g=>ps(g,s,n);return e.observe(({changes:g})=>d((g.deleted||[]).map(v=>v.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:l,evalSelectAction:p,isEmpty:a,isSelected:u,setSelected:c,setUserSelectAction:y,subscribe:i,userSelect:h}},ps=(e,t,n)=>{const i=n?n.serialize(e):e;return typeof t=="function"?t(i):t||"EDIT"},Ee=[];for(let e=0;e<256;++e)Ee.push((e+256).toString(16).slice(1));function ys(e,t=0){return(Ee[e[t+0]]+Ee[e[t+1]]+Ee[e[t+2]]+Ee[e[t+3]]+"-"+Ee[e[t+4]]+Ee[e[t+5]]+"-"+Ee[e[t+6]]+Ee[e[t+7]]+"-"+Ee[e[t+8]]+Ee[e[t+9]]+"-"+Ee[e[t+10]]+Ee[e[t+11]]+Ee[e[t+12]]+Ee[e[t+13]]+Ee[e[t+14]]+Ee[e[t+15]]).toLowerCase()}let Zt;const _s=new Uint8Array(16);function ms(){if(!Zt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Zt=crypto.getRandomValues.bind(crypto)}return Zt(_s)}const ws=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ni={randomUUID:ws};function ii(e,t,n){var i;if(ni.randomUUID&&!e)return ni.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??ms();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,ys(o)}const Kt=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)}},Es=(e,t,n,i)=>({id:ii(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:i,...t}),bs=(e,t)=>{const n=new Set(e.bodies.map(i=>i.id));return t.bodies.filter(i=>!n.has(i.id))},Ts=(e,t)=>{const n=new Set(t.bodies.map(i=>i.id));return e.bodies.filter(i=>!n.has(i.id))},As=(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})),Os=(e,t)=>!Xe(e.target,t.target),oi=(e,t)=>{const n=bs(e,t),i=Ts(e,t),o=As(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:Os(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 Ms=(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},vs=(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:y}=c;if(r.has(y.id)){const p=t.updated.find(g=>g.oldValue.id===y.id).newValue;return oi(d,p)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!l.has(c.id))];return{created:a,deleted:u,updated:h}},vt=e=>{const t=e.id===void 0?ii():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Ss=e=>e.id!==void 0,Cs=()=>{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=>{Ms(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=vt(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=vt(typeof w=="string"?T:w),E=typeof w=="string"?w:w.id,R=E&&e.get(E);if(R){const I=oi(R,m);return E===m.id?e.set(E,m):(e.delete(E),e.set(m.id,m)),R.bodies.forEach(P=>t.delete(P.id)),m.bodies.forEach(P=>t.set(P.id,m.id)),I}else console.warn(`Cannot update annotation ${E} - does not exist`)},a=(w,T=oe.LOCAL,m=oe.LOCAL)=>{const E=Ss(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 I=l(R);return I?[...E,I]:E},[]);m.length>0&&s(T,{updated:m})},c=(w,T=oe.LOCAL)=>{const m=w.map(vt),{toAdd:E,toUpdate:R}=m.reduce((P,Q)=>e.get(Q.id)?{...P,toUpdate:[...P.toUpdate,Q]}:{...P,toAdd:[...P.toAdd,Q]},{toAdd:[],toUpdate:[]}),I=R.map(P=>l(P,T)).filter(Boolean);E.forEach(P=>{e.set(P.id,P),P.bodies.forEach(Q=>t.set(Q.id,P.id))}),s(T,{created:E,updated:I})},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}`)},y=()=>[...e.values()],p=(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(vt);if(T){const R=[...e.values()];e.clear(),t.clear(),E.forEach(I=>{e.set(I.id,I),I.bodies.forEach(P=>t.set(P.id,I.id))}),s(m,{created:E,deleted:R})}else{const R=w.reduce((I,P)=>{const Q=P.id&&e.get(P.id);return Q?[...I,Q]:I},[]);if(R.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${R.map(I=>I.id).join(", ")}`);E.forEach(I=>{e.set(I.id,I),I.bodies.forEach(P=>t.set(P.id,I.id))}),s(m,{created:E})}},v=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=v(w);m&&s(T,{deleted:[m]})},O=(w,T=oe.LOCAL)=>{const m=w.reduce((E,R)=>{const I=v(R);return I?[...E,I]: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}`)},M=(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})},N=w=>{const T=e.get(w);return T?{...T}:void 0},C=w=>{const T=t.get(w);if(T){const m=N(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}`)},U=(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(I=>I.id===w.id),R={...m,bodies:m.bodies.map(I=>I.id===E.id?T:I)};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=U(w,T);E&&s(m,{updated:[E]})},G=(w,T=oe.LOCAL)=>{const m=w.map(E=>U({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:y,bulkAddAnnotations:g,bulkDeleteAnnotations:O,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:p,deleteAnnotation:_,deleteBody:M,getAnnotation:N,getBody:C,observe:i,unobserve:o,updateAnnotation:a,updateBody:k,updateTarget:(w,T=oe.LOCAL)=>{const m=z(w);m&&s(T,{updated:[m]})},upsertAnnotation:u}},Ns=e=>({...e,subscribe:t=>{const n=i=>t(i.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let Is=()=>({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 Ls=250,Rs=(e,t)=>{const n=Is(),i=(t==null?void 0:t.changes)||[];let o=t?t.pointer:-1,s=!1,r=0;const l=p=>{if(!s){const{changes:g}=p,v=performance.now();if(v-r>Ls)i.splice(o+1),i.push(g),o=i.length-1;else{const _=i.length-1;i[_]=vs(i[_],g)}r=v}s=!1};e.observe(l,{origin:oe.LOCAL});const a=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p),u=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),h=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({oldValue:g})=>g)),c=p=>p&&p.length>0&&e.bulkUpdateAnnotations(p.map(({newValue:g})=>g)),d=p=>p&&p.length>0&&e.bulkAddAnnotations(p,!1),y=p=>p&&p.length>0&&e.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>o,canUndo:()=>o>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...i],pointer:o}),on:(p,g)=>n.on(p,g),redo:()=>{if(i.length-1>o){s=!0;const{created:p,updated:g,deleted:v}=i[o+1];u(p),c(g),y(v),n.emit("redo",i[o+1]),o+=1}},undo:()=>{if(o>-1){s=!0;const{created:p,updated:g,deleted:v}=i[o];a(p),h(g),d(v),n.emit("undo",i[o]),o-=1}}}},ks=()=>{const{subscribe:e,set:t}=qt([]);return{subscribe:e,set:t}},Ps=(e,t,n,i)=>{const{hover:o,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],h,c;const d=(_,O)=>{a.has(_)?a.get(_).push(O):a.set(_,[O])},y=(_,O)=>{const b=a.get(_);if(b){const M=b.indexOf(O);M!==-1&&b.splice(M,1)}},p=(_,O,b)=>{a.has(_)&&setTimeout(()=>{a.get(_).forEach(M=>{if(n){const S=Array.isArray(O)?O.map(C=>n.serialize(C)):n.serialize(O),N=b?b instanceof PointerEvent?b:n.serialize(b):void 0;M(S,N)}else M(O,b)})},1)},g=()=>{const{selected:_}=s,O=(_||[]).map(({id:b})=>r.getAnnotation(b));O.forEach(b=>{const M=u.find(S=>S.id===b.id);(!M||!Xe(M,b))&&p("updateAnnotation",b,M)}),u=u.map(b=>O.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:O})=>r.getAnnotation(O));else if(u.length>0&&_.length===0)u.forEach(O=>{const b=r.getAnnotation(O.id);b&&!Xe(b,O)&&p("updateAnnotation",b,O)}),u=[];else{const O=new Set(u.map(M=>M.id)),b=new Set(_.map(({id:M})=>M));u.filter(M=>!b.has(M.id)).forEach(M=>{const S=r.getAnnotation(M.id);S&&!Xe(S,M)&&p("updateAnnotation",S,M)}),u=[...u.filter(M=>b.has(M.id)),..._.filter(({id:M})=>!O.has(M)).map(({id:M})=>r.getAnnotation(M))]}p("selectionChanged",u)}}),o.subscribe(_=>{!h&&_?p("mouseEnterAnnotation",r.getAnnotation(_)):h&&!_?p("mouseLeaveAnnotation",r.getAnnotation(h)):h&&_&&(p("mouseLeaveAnnotation",r.getAnnotation(h)),p("mouseEnterAnnotation",r.getAnnotation(_))),h=_}),l==null||l.subscribe(_=>p("viewportIntersect",_.map(O=>r.getAnnotation(O)))),r.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(g,1e3));const{created:O,deleted:b}=_.changes;(O||[]).forEach(M=>p("createAnnotation",M)),(b||[]).forEach(M=>p("deleteAnnotation",M)),(_.changes.updated||[]).filter(M=>[...M.bodiesCreated||[],...M.bodiesDeleted||[],...M.bodiesUpdated||[]].length>0).forEach(({oldValue:M,newValue:S})=>{const N=u.find(C=>C.id===M.id)||M;u=u.map(C=>C.id===M.id?S:C),p("updateAnnotation",S,N)})},{origin:oe.LOCAL}),r.observe(_=>{if(u){const O=new Set(u.map(M=>M.id)),b=(_.changes.updated||[]).filter(({newValue:M})=>O.has(M.id)).map(({newValue:M})=>M);b.length>0&&(u=u.map(M=>b.find(N=>N.id===M.id)||M))}},{origin:oe.REMOTE});const v=_=>O=>{const{updated:b}=O;_?(b||[]).forEach(M=>p("updateAnnotation",M.oldValue,M.newValue)):(b||[]).forEach(M=>p("updateAnnotation",M.newValue,M.oldValue))};return t.on("undo",v(!0)),t.on("redo",v(!1)),{on:d,off:y,emit:p}},Ds=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:[]}),Us=(e,t,n)=>{const{store:i,selection:o}=e,s=_=>{if(n){const{parsed:O,error:b}=n.parse(_);O?i.addAnnotation(O,oe.REMOTE):console.error(b)}else i.addAnnotation(Kt(_),oe.REMOTE)},r=()=>o.clear(),l=()=>i.clear(),a=_=>{const O=i.getAnnotation(_);return n&&O?n.serialize(O):O},u=()=>n?i.all().map(n.serialize):i.all(),h=()=>{var _;const O=(((_=o.selected)==null?void 0:_.map(b=>b.id))||[]).map(b=>i.getAnnotation(b)).filter(Boolean);return n?O.map(n.serialize):O},c=(_,O=!0)=>fetch(_).then(b=>b.json()).then(b=>(y(b,O),b)),d=_=>{if(typeof _=="string"){const O=i.getAnnotation(_);if(i.deleteAnnotation(_),O)return n?n.serialize(O):O}else{const O=n?n.parse(_).parsed:_;if(O)return i.deleteAnnotation(O),_}},y=(_,O=!0)=>{if(n){const b=n.parseAll||Ds(n),{parsed:M,failed:S}=b(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(M,O,oe.REMOTE)}else i.bulkAddAnnotations(_.map(Kt),O,oe.REMOTE)},p=(_,O)=>{_?o.setSelected(_,O):o.clear()},g=_=>{o.clear(),o.setUserSelectAction(_)},v=_=>{if(n){const O=n.parse(_).parsed,b=n.serialize(i.getAnnotation(O.id));return i.updateAnnotation(O),b}else{const O=i.getAnnotation(_.id);return i.updateAnnotation(Kt(_)),O}};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:y,setSelected:p,setUserSelectAction:g,undo:t.undo,updateAnnotation:v}},Hs=(e,t,n)=>typeof t=="function"?t(e,n):t,Vs=(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||{}}},Ys="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Bs=e=>crypto.getRandomValues(new Uint8Array(e)),Xs=(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}}},Fs=(e,t=21)=>Xs(e,t|0,Bs),js=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Ys[n[e]&63];return t};const Gs=()=>({isGuest:!0,id:Fs("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),zs=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}`},si=e=>e?typeof e=="object"?{...e}:e:void 0,qs=(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-${zs(n)}`,annotation:t,type:o,purpose:s,value:r,creator:si(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...h}}),Qs=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}),Zs=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Ks=()=>{const e=[...Zs];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};js();const Ws=(e,t={strict:!0,invertY:!1})=>({parse:o=>ri(o,t),serialize:o=>li(o,e,t)}),ri=(e,t={strict:!0,invertY:!1})=>{const n=e.id||ei(),{creator:i,created:o,modified:s,body:r,...l}=e,a=qs(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"?Un(h,t.invertY):(h==null?void 0:h.type)==="SvgSelector"?Jn(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:si(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:n,selector:c||h}}}:{error:Error(`Invalid selector: ${JSON.stringify(h)}`)}},li=(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==te.RECTANGLE?Hn(i.geometry):xn(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:Qs(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},tt=[];function Js(e,t=q){let n;const i=new Set;function o(l){if(fe(e,l)&&(e=l,n)){const a=!tt.length;for(const u of i)u[1](),tt.push(u,e);if(a){for(let u=0;u<tt.length;u+=2)tt[u][0](tt[u+1]);tt.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 xs=(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}`)},ai=(e,t)=>{xs(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}},Ke=(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}},dt=(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,$s=e=>({}),ui=e=>({grab:e[0]});function er(e){let t,n,i,o;const s=e[8].default,r=ho(s,e,e[7],ui);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)&&po(r,s,l,l[7],n?go(s,l[7],a,$s):yo(l[7]),ui)},i(l){n||(B(r,l),n=!0)},o(l){j(r,l),n=!1},d(l){l&&H(t),r&&r.d(l),i=!1,Ne(o)}}}function tr(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 y=v=>_=>{if(h=v,u){const{left:b,top:M}=u.getBoundingClientRect(),S=_.clientX-b,N=_.clientY-M;c=a.elementToImage(S,N)}else{const{offsetX:b,offsetY:M}=_;c=a.elementToImage(b,M)}d=r,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=v=>{if(h){const[_,O]=a.elementToImage(v.offsetX,v.offsetY),b=[_-c[0],O-c[1]];n(3,r=l(d,h,b)),s("change",r)}},g=v=>{v.target.releasePointerCapture(v.pointerId),h=void 0,d=r,s("release",v)};return e.$$set=v=>{"shape"in v&&n(3,r=v.shape),"editor"in v&&n(4,l=v.editor),"transform"in v&&n(5,a=v.transform),"svgEl"in v&&n(6,u=v.svgEl),"$$scope"in v&&n(7,o=v.$$scope)},[y,p,g,r,l,a,u,o,i]}class St extends _e{constructor(t){super(),ye(this,t,tr,er,fe,{shape:3,editor:4,transform:5,svgEl:6})}}function nr(e){let t,n,i,o,s,r,l,a,u=e[3]&&fi(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),Z(t,n),u&&u.m(t,null),Z(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=fi(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,Ne(a)}}}function ir(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),Z(t,n),Z(t,o),Z(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,Ne(u)}}}function fi(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 or(e){let t;function n(s,r){return Ue?ir:nr}let o=n()(e);return{c(){o.c(),t=Ie()},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 sr(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(_){Te.call(this,e,_)}function d(_){Te.call(this,e,_)}function y(_){Te.call(this,e,_)}function p(_){Te.call(this,e,_)}function g(_){Te.call(this,e,_)}function v(_){Te.call(this,e,_)}return e.$$set=_=>{n(8,t=He(He({},t),En(_))),"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=En(t),[o,s,r,l,a,i,u,h,t,c,d,y,p,g,v]}class We extends _e{constructor(t){super(),ye(this,t,sr,or,fe,{x:0,y:1,scale:2,selected:3})}}function rr(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),Z(t,n),Z(t,o),Z(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,Ne(l)}}}function lr(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 ar(e){let t;function n(s,r){return Ue?lr:rr}let o=n()(e);return{c(){o.c(),t=Ie()},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 ur(e,t,n){let i,{x:o}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){Te.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 ci extends _e{constructor(t){super(),ye(this,t,ur,ar,fe,{x:0,y:1,scale:4})}}function Wt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function hi(e,t,n){const i=e.slice();return i[28]=t[n],i[30]=n,i}function Jt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function xt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function di(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=gt/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=gt/s[3])&&f(t,"r",o)},d(s){s&&H(t)}}}function gi(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=gt/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),Z(t,n),Z(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=gt/c[3])&&f(l,"r",h)},d(c){c&&H(t)}}}function pi(e){let t,n;return t=new We({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(){le(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ge(t.$$.fragment)},m(i,o){ce(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){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function yi(e){let t,n;return t=new ci({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){le(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ge(t.$$.fragment)},m(i,o){ce(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){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function fr(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g,v,_,O,b,M,S,N=e[6]!==void 0&&!e[7]&&di(xt(e)),C=e[6]!==void 0&&!e[7]&&gi(Jt(e)),U=Se(e[5].points),k=[];for(let w=0;w<U.length;w+=1)k[w]=pi(hi(e,U,w));const G=w=>j(k[w],1,1,()=>{k[w]=null});let z=e[6]!==void 0&&!e[7]&&yi(Wt(e));return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),N&&N.c(),C&&C.c(),h=Oe(),c=L("polygon"),y=Oe(),p=L("polygon"),v=Oe();for(let w=0;w<k.length;w+=1)k[w].c();_=Oe(),z&&z.c(),O=Ie(),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(_i).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(mi).join(" ")),f(p,"class","a9s-inner a9s-shape-handle"),f(p,"mask",`url(#${e[19]}-inner)`),f(p,"style",e[1]),f(p,"points",g=e[5].points.map(wi).join(" "))},m(w,T){V(w,t,T),Z(t,n),Z(n,i),Z(n,a),N&&N.m(n,null),C&&C.m(t,null),V(w,h,T),V(w,c,T),V(w,y,T),V(w,p,T),V(w,v,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,O,T),b=!0,M||(S=[ee(c,"pointerup",e[14]),ee(c,"pointerdown",function(){le(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),ee(p,"pointermove",e[13]),ee(p,"pointerup",e[14]),ee(p,"pointerdown",function(){le(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],M=!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(_i).join(" ")))&&f(a,"points",u),e[6]!==void 0&&!e[7]?N?N.p(xt(e),T):(N=di(xt(e)),N.c(),N.m(n,null)):N&&(N.d(1),N=null),e[6]!==void 0&&!e[7]?C?C.p(Jt(e),T):(C=gi(Jt(e)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!b||T[0]&32&&d!==(d=e[5].points.map(mi).join(" ")))&&f(c,"points",d),(!b||T[0]&2)&&f(p,"style",e[1]),(!b||T[0]&32&&g!==(g=e[5].points.map(wi).join(" ")))&&f(p,"points",g),T[0]&134322472){U=Se(e[5].points);let m;for(m=0;m<U.length;m+=1){const E=hi(e,U,m);k[m]?(k[m].p(E,T),B(k[m],1)):(k[m]=pi(E),k[m].c(),B(k[m],1),k[m].m(_.parentNode,_))}for(Me(),m=U.length;m<k.length;m+=1)G(m);ve()}e[6]!==void 0&&!e[7]?z?(z.p(Wt(e),T),T[0]&192&&B(z,1)):(z=yi(Wt(e)),z.c(),B(z,1),z.m(O.parentNode,O)):z&&(Me(),j(z,1,1,()=>{z=null}),ve())},i(w){if(!b){for(let T=0;T<U.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)j(k[T]);j(z),b=!1},d(w){w&&(H(t),H(h),H(c),H(y),H(p),H(v),H(_),H(O)),N&&N.d(),C&&C.d(),Ge(k,w),z&&z.d(w),M=!1,Ne(S)}}}function cr(e){let t,n;return t=new St({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[fr,({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(){ge(t.$$.fragment)},m(i,o){ce(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){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}const hr=250,dr=1e3,gr=12,gt=4.5,_i=e=>e.join(","),mi=e=>e.join(","),wi=e=>e.join(",");function pr(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,y=!1,p,g=[];const v=()=>n(7,y=!0),_=()=>n(7,y=!1),O=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),I=W=>Math.pow(W[0]-E,2)+Math.pow(W[1]-R,2),P=i.points.reduce((W,x)=>I(x)<I(W)?x:W),Q=o.filter(W=>W.visible).reduce((W,x)=>I(x.point)<I(W.point)?x:W),F=Math.pow(dr/h,2);I(P)<F||I(Q.point)<F?n(6,d=o.indexOf(Q)):n(6,d=void 0)},b=()=>{document.activeElement!==c&&c.focus()},M=()=>{n(8,g=[]),b()},S=m=>{n(7,y=!0),m.preventDefault(),m.stopPropagation(),p=performance.now()},N=m=>E=>{if(!p||Ue||performance.now()-p>hr)return;const R=g.includes(m);E.metaKey||E.ctrlKey||E.shiftKey?R?n(8,g=g.filter(I=>I!==m)):n(8,g=[...g,m]):R&&g.length>1?n(8,g=[m]):R?n(8,g=[]):n(8,g=[m]),b()},C=(m,E,R)=>{b();let I;const P=m.geometry;g.length>1?I=P.points.map(([F,J],W)=>g.includes(W)?[F+R[0],J+R[1]]:[F,J]):E==="SHAPE"?I=P.points.map(([F,J])=>[F+R[0],J+R[1]]):I=P.points.map(([F,J],W)=>E===`HANDLE-${W}`?[F+R[0],J+R[1]]:[F,J]);const Q=me(I);return{...m,geometry:{points:I,bounds:Q}}},U=m=>async E=>{E.stopPropagation();const R=[...i.points.slice(0,m+1),o[m].point,...i.points.slice(m+1)],I=me(R);r("change",{...l,geometry:{points:R,bounds:I}}),await vn();const P=[...document.querySelectorAll(".a9s-handle")][m+1];if(P!=null&&P.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});P.firstChild.dispatchEvent(Q)}},k=()=>{if(i.points.length-g.length<3)return;const m=i.points.filter((R,I)=>!g.includes(I)),E=me(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",O),c.addEventListener("keydown",m),()=>{c.removeEventListener("pointermove",O),c.removeEventListener("keydown",m)}});const G=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function z(m){Te.call(this,e,m)}function w(m){Te.call(this,e,m)}function T(m){Te.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],I=(m[0]+R[0])/2,P=(m[1]+R[1])/2,F=Math.sqrt(Math.pow(R[0]-I,2)+Math.pow(R[1]-P,2))>gr/h;return{point:[I,P],visible:F}})),e.$$.dirty[0]&40&&n(9,s=dt(i.bounds,gt/h))},[l,a,u,h,c,i,d,y,g,s,o,v,_,O,M,S,N,C,U,G,z,w,T]}class Ei extends _e{constructor(t){super(),ye(this,t,pr,cr,fe,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function yr(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g,v,_,O,b,M,S,N,C,U,k,G,z,w,T,m,E,R,I,P,Q,F,J,W,x,se,ae,Ce,ke,X,pe,ne,be,Ae,ot,Fe,gn,je,$,pn,fo;return ne=new We({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),ne.$on("pointerdown",function(){le(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),Ae=new We({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),Ae.$on("pointerdown",function(){le(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),Fe=new We({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(){le(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),je=new We({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),je.$on("pointerdown",function(){le(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(),p=L("rect"),b=Oe(),M=L("rect"),k=Oe(),G=L("rect"),m=Oe(),E=L("rect"),Q=Oe(),F=L("rect"),se=Oe(),ae=L("rect"),pe=Oe(),ge(ne.$$.fragment),be=Oe(),ge(Ae.$$.fragment),ot=Oe(),ge(Fe.$$.fragment),gn=Oe(),ge(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(p,"class","a9s-outer"),f(p,"mask",`url(#${e[8]})`),f(p,"x",g=e[5].x),f(p,"y",v=e[5].y),f(p,"width",_=e[5].w),f(p,"height",O=e[5].h),f(M,"class","a9s-inner a9s-shape-handle"),f(M,"style",e[1]),f(M,"x",S=e[5].x),f(M,"y",N=e[5].y),f(M,"width",C=e[5].w),f(M,"height",U=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",I=e[5].y),f(E,"height",P=e[5].h),f(E,"width",1),f(F,"class","a9s-edge-handle a9s-edge-handle-bottom"),f(F,"x",J=e[5].x),f(F,"y",W=e[5].y+e[5].h),f(F,"height",1),f(F,"width",x=e[5].w),f(ae,"class","a9s-edge-handle a9s-edge-handle-left"),f(ae,"x",Ce=e[5].x),f(ae,"y",ke=e[5].y),f(ae,"height",X=e[5].h),f(ae,"width",1)},m(K,Y){V(K,t,Y),Z(t,n),Z(n,i),Z(n,a),V(K,y,Y),V(K,p,Y),V(K,b,Y),V(K,M,Y),V(K,k,Y),V(K,G,Y),V(K,m,Y),V(K,E,Y),V(K,Q,Y),V(K,F,Y),V(K,se,Y),V(K,ae,Y),V(K,pe,Y),ce(ne,K,Y),V(K,be,Y),ce(Ae,K,Y),V(K,ot,Y),ce(Fe,K,Y),V(K,gn,Y),ce(je,K,Y),$=!0,pn||(fo=[ee(p,"pointerdown",function(){le(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(M,"pointerdown",function(){le(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(G,"pointerdown",function(){le(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),ee(E,"pointerdown",function(){le(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),ee(F,"pointerdown",function(){le(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),ee(ae,"pointerdown",function(){le(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],pn=!0)},p(K,Y){e=K,(!$||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(p,"x",g),(!$||Y&32&&v!==(v=e[5].y))&&f(p,"y",v),(!$||Y&32&&_!==(_=e[5].w))&&f(p,"width",_),(!$||Y&32&&O!==(O=e[5].h))&&f(p,"height",O),(!$||Y&2)&&f(M,"style",e[1]),(!$||Y&32&&S!==(S=e[5].x))&&f(M,"x",S),(!$||Y&32&&N!==(N=e[5].y))&&f(M,"y",N),(!$||Y&32&&C!==(C=e[5].w))&&f(M,"width",C),(!$||Y&32&&U!==(U=e[5].h))&&f(M,"height",U),(!$||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&&I!==(I=e[5].y))&&f(E,"y",I),(!$||Y&32&&P!==(P=e[5].h))&&f(E,"height",P),(!$||Y&32&&J!==(J=e[5].x))&&f(F,"x",J),(!$||Y&32&&W!==(W=e[5].y+e[5].h))&&f(F,"y",W),(!$||Y&32&&x!==(x=e[5].w))&&f(F,"width",x),(!$||Y&32&&Ce!==(Ce=e[5].x))&&f(ae,"x",Ce),(!$||Y&32&&ke!==(ke=e[5].y))&&f(ae,"y",ke),(!$||Y&32&&X!==(X=e[5].h))&&f(ae,"height",X);const It={};Y&32&&(It.x=e[5].x),Y&32&&(It.y=e[5].y),Y&8&&(It.scale=e[3]),ne.$set(It);const Lt={};Y&32&&(Lt.x=e[5].x+e[5].w),Y&32&&(Lt.y=e[5].y),Y&8&&(Lt.scale=e[3]),Ae.$set(Lt);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 kt={};Y&32&&(kt.x=e[5].x),Y&32&&(kt.y=e[5].y+e[5].h),Y&8&&(kt.scale=e[3]),je.$set(kt)},i(K){$||(B(ne.$$.fragment,K),B(Ae.$$.fragment,K),B(Fe.$$.fragment,K),B(je.$$.fragment,K),$=!0)},o(K){j(ne.$$.fragment,K),j(Ae.$$.fragment,K),j(Fe.$$.fragment,K),j(je.$$.fragment,K),$=!1},d(K){K&&(H(t),H(y),H(p),H(b),H(M),H(k),H(G),H(m),H(E),H(Q),H(F),H(se),H(ae),H(pe),H(be),H(ot),H(gn)),he(ne,K),he(Ae,K),he(Fe,K),he(je,K),pn=!1,Ne(fo)}}}function _r(e){let t,n;return t=new St({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[yr,({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(){ge(t.$$.fragment)},m(i,o){ce(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){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function mr(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,v,_)=>{const O=g.geometry.bounds;let[b,M]=[O.minX,O.minY],[S,N]=[O.maxX,O.maxY];const[C,U]=_;if(v==="SHAPE")b+=C,S+=C,M+=U,N+=U;else{switch(v){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{M+=U;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{N+=U;break}}switch(v){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{b+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const k=Math.min(b,S),G=Math.min(M,N),z=Math.abs(S-b),w=Math.abs(N-M);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){Te.call(this,e,g)}function y(g){Te.call(this,e,g)}function p(g){Te.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=dt(i.bounds,2/a))},[s,r,l,a,u,i,o,h,c,d,y,p]}class bi extends _e{constructor(t){super(),ye(this,t,mr,_r,fe,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Ti=Object.prototype.hasOwnProperty;function $t(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--&&$t(e[i],t[i]););return i===-1}if(!n||typeof e=="object"){i=0;for(n in e)if(Ti.call(e,n)&&++i&&!Ti.call(t,n)||!(n in t)||!$t(e[n],t[n]))return!1;return Object.keys(t).length===i}}return e!==e&&t!==t}const wr=12,Er=(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],y=(h[0]+d[0])/2,p=(h[1]+d[1])/2,v=Math.sqrt(Math.pow(d[0]-y,2)+Math.pow(d[1]-p,2))>wr/t;return{point:[y,p],visible:v,elementIdx:o,ringIdx:a,pointIdx:c}});return[...r,...u]},[]);return[...n,...s]},[]);function en(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function Ai(e,t,n){const i=e.slice();return i[30]=t[n],i[32]=n,i}function Oi(e,t,n){const i=e.slice();return i[33]=t[n],i[35]=n,i}function Mi(e,t,n){const i=e.slice();return i[29]=t[n],i[37]=n,i}function tn(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function nn(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function vi(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=pt/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=pt/s[3])&&f(t,"r",o)},d(s){s&&H(t)}}}function Si(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=pt/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),Z(t,n),Z(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=pt/c[3])&&f(l,"r",h)},d(c){c&&H(t)}}}function Ci(e){let t,n;function i(...o){return e[19](e[32],e[35],e[37],...o)}return t=new We({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(){le(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(){ge(t.$$.fragment)},m(o,s){ce(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){j(t.$$.fragment,o),n=!1},d(o){he(t,o)}}}function Ni(e){let t,n,i=Se(e[33].points),o=[];for(let r=0;r<i.length;r+=1)o[r]=Ci(Mi(e,i,r));const s=r=>j(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ie()},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=Se(r[33].points);let a;for(a=0;a<i.length;a+=1){const u=Mi(r,i,a);o[a]?(o[a].p(u,l),B(o[a],1)):(o[a]=Ci(u),o[a].c(),B(o[a],1),o[a].m(t.parentNode,t))}for(Me(),a=i.length;a<o.length;a+=1)s(a);ve()}},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)j(o[l]);n=!1},d(r){r&&H(t),Ge(o,r)}}}function Ii(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g,v,_,O=e[6]!==void 0&&!e[7]&&vi(nn(e)),b=e[6]!==void 0&&!e[7]&&Si(tn(e)),M=Se(e[30].rings),S=[];for(let C=0;C<M.length;C+=1)S[C]=Ni(Oi(e,M,C));const N=C=>j(S[C],1,1,()=>{S[C]=null});return{c(){t=L("g"),n=L("defs"),i=L("mask"),o=L("rect"),u=L("path"),O&&O.c(),b&&b.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",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(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",p=De(e[30]))},m(C,U){V(C,t,U),Z(t,n),Z(n,i),Z(i,o),Z(i,u),O&&O.m(i,null),b&&b.m(n,null),Z(t,c),Z(t,y);for(let k=0;k<S.length;k+=1)S[k]&&S[k].m(t,null);g=!0,v||(_=[ee(c,"pointerup",e[13]),ee(c,"pointerdown",function(){le(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),ee(y,"pointerup",e[13]),ee(y,"pointerdown",function(){le(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],v=!0)},p(C,U){if(e=C,(!g||U[0]&512&&s!==(s=e[9].x))&&f(o,"x",s),(!g||U[0]&512&&r!==(r=e[9].y))&&f(o,"y",r),(!g||U[0]&512&&l!==(l=e[9].w))&&f(o,"width",l),(!g||U[0]&512&&a!==(a=e[9].h))&&f(o,"height",a),(!g||U[0]&32&&h!==(h=De(e[30])))&&f(u,"d",h),e[6]!==void 0&&!e[7]?O?O.p(nn(e),U):(O=vi(nn(e)),O.c(),O.m(i,null)):O&&(O.d(1),O=null),e[6]!==void 0&&!e[7]?b?b.p(tn(e),U):(b=Si(tn(e)),b.c(),b.m(n,null)):b&&(b.d(1),b=null),(!g||U[0]&32&&d!==(d=De(e[30])))&&f(c,"d",d),(!g||U[0]&2)&&f(y,"style",e[1]),(!g||U[0]&32&&p!==(p=De(e[30])))&&f(y,"d",p),U[0]&268491048){M=Se(e[30].rings);let k;for(k=0;k<M.length;k+=1){const G=Oi(e,M,k);S[k]?(S[k].p(G,U),B(S[k],1)):(S[k]=Ni(G),S[k].c(),B(S[k],1),S[k].m(t,null))}for(Me(),k=M.length;k<S.length;k+=1)N(k);ve()}},i(C){if(!g){for(let U=0;U<M.length;U+=1)B(S[U]);g=!0}},o(C){S=S.filter(Boolean);for(let U=0;U<S.length;U+=1)j(S[U]);g=!1},d(C){C&&H(t),O&&O.d(),b&&b.d(),Ge(S,C),v=!1,Ne(_)}}}function Li(e){let t,n;return t=new ci({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){le(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ge(t.$$.fragment)},m(i,o){ce(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){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function br(e){let t,n,i,o=Se(e[5].polygons),s=[];for(let a=0;a<o.length;a+=1)s[a]=Ii(Ai(e,o,a));const r=a=>j(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&Li(en(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=Oe(),l&&l.c(),n=Ie()},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=Se(a[5].polygons);let h;for(h=0;h<o.length;h+=1){const c=Ai(a,o,h);s[h]?(s[h].p(c,u),B(s[h],1)):(s[h]=Ii(c),s[h].c(),B(s[h],1),s[h].m(t.parentNode,t))}for(Me(),h=o.length;h<s.length;h+=1)r(h);ve()}a[6]!==void 0&&!a[7]?l?(l.p(en(a),u),u[0]&192&&B(l,1)):(l=Li(en(a)),l.c(),B(l,1),l.m(n.parentNode,n)):l&&(Me(),j(l,1,1,()=>{l=null}),ve())},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)j(s[u]);j(l),i=!1},d(a){a&&(H(t),H(n)),Ge(s,a),l&&l.d(a)}}}function Tr(e){let t,n;return t=new St({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[br,({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(){ge(t.$$.fragment)},m(i,o){ce(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){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}const Ar=250,Or=1e3,pt=4.5;function Mr(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,y=!1,p,g=[];const v=()=>n(7,y=!0),_=()=>n(7,y=!1),O=E=>{if(g.length>0||!o.some(x=>x.visible)){n(6,d=void 0);return}const[R,I]=u.elementToImage(E.offsetX,E.offsetY),P=x=>Math.pow(x[0]-R,2)+Math.pow(x[1]-I,2),Q=Ln(i).reduce((x,se)=>P(se)<P(x)?se:x),F=o.filter(x=>x.visible).reduce((x,se)=>P(se.point)<P(x.point)?se:x),J=Math.pow(Or/h,2);P(Q)<J||P(F.point)<J?n(6,d=o.indexOf(F)):n(6,d=void 0)},b=()=>{document.activeElement!==c&&c.focus()},M=()=>{n(8,g=[]),b()},S=E=>{n(7,y=!0),E.preventDefault(),E.stopPropagation(),p=performance.now()},N=(E,R,I)=>P=>{if(!p||Ue||performance.now()-p>Ar)return;const Q=J=>J.polygon===E&&J.ring===R&&J.point===I,F=g.some(Q);P.metaKey||P.ctrlKey||P.shiftKey?F?n(8,g=g.filter(J=>!Q(J))):n(8,g=[...g,{polygon:E,ring:R,point:I}]):F&&g.length>1?n(8,g=[{polygon:E,ring:R,point:I}]):F?n(8,g=[]):n(8,g=[{polygon:E,ring:R,point:I}]),b()},C=(E,R,I)=>{b();const P=E.geometry.polygons;let Q;if(R==="SHAPE")Q=P.map(F=>{const J=F.rings.map((x,se)=>({points:x.points.map((Ce,ke)=>[Ce[0]+I[0],Ce[1]+I[1]])})),W=me(J[0].points);return{rings:J,bounds:W}});else{const[F,J,W,x]=R.split("-").map(se=>parseInt(se));Q=P.map((se,ae)=>{if(ae===J){const Ce=se.rings.map((X,pe)=>pe===W?{points:X.points.map((be,Ae)=>Ae===x?[be[0]+I[0],be[1]+I[1]]:be)}:X),ke=me(Ce[0].points);return{rings:Ce,bounds:ke}}else return se})}return{...E,geometry:{polygons:Q,bounds:ft(Q)}}},U=E=>async R=>{R.stopPropagation();const I=o[E],P=i.polygons.map((F,J)=>{if(J===I.elementIdx){const W=F.rings.map((se,ae)=>ae===I.ringIdx?{points:[...se.points.slice(0,I.pointIdx+1),I.point,...se.points.slice(I.pointIdx+1)]}:se),x=me(W[0].points);return{rings:W,bounds:x}}else return F});r("change",{...l,geometry:{polygons:P,bounds:ft(P)}}),await vn();const Q=[...document.querySelectorAll(".a9s-handle")][E+1];if(Q!=null&&Q.firstChild){const F=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(F)}},k=()=>{const E=i.polygons.map((I,P)=>{if(g.some(F=>F.polygon===P)){const F=I.rings.map((W,x)=>{const se=g.filter(ae=>ae.polygon===P&&ae.ring===x);return se.length&&W.points.length-se.length>=3?{points:W.points.filter((Ce,ke)=>!se.some(X=>X.point===ke))}:W}),J=me(F[0].points);return{rings:F,bounds:J}}else return I});!$t(i.polygons,E)&&(r("change",{...l,geometry:{polygons:E,bounds:ft(E)}}),n(8,g=[]))};ze(()=>{if(Ue)return;const E=R=>{(R.key==="Delete"||R.key==="Backspace")&&(R.preventDefault(),k())};return c.addEventListener("pointermove",O),c.addEventListener("keydown",E),()=>{c.removeEventListener("pointermove",O),c.removeEventListener("keydown",E)}});const G=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,z=(E,R,I,{polygon:P,ring:Q,point:F})=>P===E&&Q===R&&F===I;function w(E){Te.call(this,e,E)}function T(E){Te.call(this,e,E)}function m(E){Te.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?[]:Er(i,h)),e.$$.dirty[0]&40&&n(9,s=dt(i.bounds,pt/h))},[l,a,u,h,c,i,d,y,g,s,o,v,_,M,S,N,C,U,G,z,w,T,m]}class vr extends _e{constructor(t){super(),ye(this,t,Mr,Tr,fe,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Ri=new Map([[te.RECTANGLE,bi],[te.POLYGON,Ei],[te.MULTIPOLYGON,vr]]),ki=e=>Ri.get(e.type),Pi=(e,t)=>Ri.set(e,t);function Sr(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=Ke(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 Di extends _e{constructor(t){super(),ye(this,t,Sr,null,fe,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Cr(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=(y,p,g)=>{h==null||h.addEventListener(y,p,g),c.push(()=>h==null?void 0:h.removeEventListener(y,p,g))};return n(5,u=new r({target:s,props:{addEventListener:d,drawingMode:o,transform:l,viewportScale:a}})),u.$on("create",y=>i("create",y.detail)),()=>{c.forEach(y=>y()),u.$destroy()}}),e.$$set=h=>{"drawingMode"in h&&n(0,o=h.drawingMode),"target"in h&&n(1,s=h.target),"tool"in h&&n(2,r=h.tool),"transform"in h&&n(3,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 Ui extends _e{constructor(t){super(),ye(this,t,Cr,null,fe,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Hi(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),Z(t,n),Z(n,i),Z(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 Nr(e){let t,n=e[0]&&Hi(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=Hi(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 Ir(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,y,p,g;const v=S=>{const N=S;u=performance.now(),r==="drag"&&(n(0,h=l.elementToImage(N.offsetX,N.offsetY)),c=h,n(1,d=h[0]),n(2,y=h[1]),n(3,p=1),n(4,g=1))},_=S=>{const N=S;h&&(c=l.elementToImage(N.offsetX,N.offsetY),n(1,d=Math.min(c[0],h[0])),n(2,y=Math.min(c[1],h[1])),n(3,p=Math.abs(c[0]-h[0])),n(4,g=Math.abs(c[1]-h[1])))},O=S=>{const N=S,C=performance.now()-u;if(r==="click"){if(C>300)return;h?b():(n(0,h=l.elementToImage(N.offsetX,N.offsetY)),c=h,n(1,d=h[0]),n(2,y=h[1]),n(3,p=1),n(4,g=1))}else h&&(C>300||p*g>100?(N.stopPropagation(),b()):(n(0,h=void 0),c=void 0))},b=()=>{if(p*g>15){const S={type:te.RECTANGLE,geometry:{bounds:{minX:d,minY:y,maxX:d+p,maxY:y+g},x:d,y,w:p,h:g}};o("create",S)}n(0,h=void 0),c=void 0};ze(()=>{s("pointerdown",v),s("pointermove",_),s("pointerup",O,!0)});const M=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=S=>{"addEventListener"in S&&n(7,s=S.addEventListener),"drawingMode"in S&&n(8,r=S.drawingMode),"transform"in S&&n(9,l=S.transform),"viewportScale"in S&&n(10,a=S.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,i=2/a)},[h,d,y,p,g,i,M,s,r,l,a]}class Vi extends _e{constructor(t){super(),ye(this,t,Ir,Nr,fe,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function on(e){const t=e.slice(),n=t[2].map(i=>i.join(",")).join(" ");return t[19]=n,t}function Yi(e){let t,n,i,o,s,r,l,a,u,h,c,d,y,p,g=e[1]&&Bi(e);return{c(){t=L("defs"),n=L("mask"),i=L("rect"),a=L("polygon"),h=L("polygon"),d=L("polygon"),g&&g.c(),p=Ie(),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",y=e[19])},m(v,_){V(v,t,_),Z(t,n),Z(n,i),Z(n,a),V(v,h,_),V(v,d,_),g&&g.m(v,_),V(v,p,_)},p(v,_){_&8&&o!==(o=v[3].x)&&f(i,"x",o),_&8&&s!==(s=v[3].y)&&f(i,"y",s),_&8&&r!==(r=v[3].w)&&f(i,"width",r),_&8&&l!==(l=v[3].h)&&f(i,"height",l),_&4&&u!==(u=v[19])&&f(a,"points",u),_&4&&c!==(c=v[19])&&f(h,"points",c),_&4&&y!==(y=v[19])&&f(d,"points",y),v[1]?g?g.p(v,_):(g=Bi(v),g.c(),g.m(p.parentNode,p)):g&&(g.d(1),g=null)},d(v){v&&(H(t),H(h),H(d),H(p)),g&&g.d(v)}}}function Bi(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 Lr(e){let t,n=e[3]&&Yi(on(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(on(i),o):(n=Yi(on(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 Rr=20,kr=1500;function Pr(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=[],y,p,g=!1;const v=N=>{const C=N,{timeStamp:U,offsetX:k,offsetY:G}=C;if(c={timeStamp:U,offsetX:k,offsetY:G},a==="drag"&&d.length===0){const z=u.elementToImage(C.offsetX,C.offsetY);d.push(z),n(10,y=z)}},_=N=>{const C=N;if(p&&clearTimeout(p),d.length>0){if(n(10,y=u.elementToImage(C.offsetX,C.offsetY)),d.length>2){const U=ut(y,d[0])*h;n(1,g=U<Rr)}C.pointerType==="touch"&&(p=setTimeout(()=>{b()},kr))}},O=N=>{const C=N;if(p&&clearTimeout(p),a==="click"){const U=C.timeStamp-c.timeStamp,k=ut([c.offsetX,c.offsetY],[C.offsetX,C.offsetY]);if(U>300||k>15)return;if(g)M();else if(d.length===0){const G=u.elementToImage(C.offsetX,C.offsetY);d.push(G),n(10,y=G)}else d.push(y)}else{if(d.length===1&&ut(d[0],y)<=4){n(0,d=[]),n(10,y=void 0);return}C.stopImmediatePropagation(),g?M():d.push(y)}},b=()=>{if(!y)return;const N=d.slice(0,-1);if(N.length<3)return;const C={type:te.POLYGON,geometry:{bounds:me(d),points:N}};Tt(C)>4&&(n(0,d=[]),n(10,y=void 0),r("create",C))},M=()=>{const N={type:te.POLYGON,geometry:{bounds:me(d),points:[...d]}};n(0,d=[]),n(10,y=void 0),r("create",N)};ze(()=>{l("pointerdown",v,!0),l("pointermove",_),l("pointerup",O,!0),l("dblclick",b,!0)});const S=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=N=>{"addEventListener"in N&&n(6,l=N.addEventListener),"drawingMode"in N&&n(7,a=N.drawingMode),"transform"in N&&n(8,u=N.transform),"viewportScale"in N&&n(9,h=N.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,i=4/h),e.$$.dirty&1027&&n(2,o=y?g?d:[...d,y]:[]),e.$$.dirty&516&&n(3,s=o.length>0?dt(me(o),2/h):void 0)},[d,g,o,s,i,S,l,a,u,h,y]}class Dr extends _e{constructor(t){super(),ye(this,t,Pr,Lr,fe,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const sn=new Map([["rectangle",{tool:Vi}],["polygon",{tool:Dr}]]),rn=()=>[...sn.keys()],ln=e=>sn.get(e),Xi=(e,t,n={})=>sn.set(e,{tool:t,opts:n});function Ur(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),Z(t,n),Z(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 Hr(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=Ke(o,r))},[o,i,l,a,u,h,s,r]}class Vr extends _e{constructor(t){super(),ye(this,t,Hr,Ur,fe,{annotation:0,geom:6,style:7})}}function Yr(e){let t,n,i,o,s;return{c(){t=L("g"),n=L("line"),o=L("line"),f(n,"class","a9s-outer"),f(n,"style",i=e[1]?"display:none;":void 0),f(n,"x1",e[2]),f(n,"y1",e[3]),f(n,"x2",e[4]),f(n,"y2",e[5]),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"x1",e[2]),f(o,"y1",e[3]),f(o,"x2",e[4]),f(o,"y2",e[5]),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,l){V(r,t,l),Z(t,n),Z(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 Br(e,t,n){let i,{annotation:o}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[h,c]]=l;return e.$$set=d=>{"annotation"in d&&n(0,o=d.annotation),"geom"in d&&n(6,s=d.geom),"style"in d&&n(7,r=d.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,i=Ke(o,r))},[o,i,a,u,h,c,s,r]}class Xr extends _e{constructor(t){super(),ye(this,t,Br,Yr,fe,{annotation:0,geom:6,style:7})}}function Fi(e,t,n){const i=e.slice();return i[5]=t[n],i}function ji(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 Fr(e){let t,n,i=Se(e[2]),o=[];for(let s=0;s<i.length;s+=1)o[s]=ji(Fi(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=Se(s[2]);let l;for(l=0;l<i.length;l+=1){const a=Fi(s,i,l);o[l]?o[l].p(a,r):(o[l]=ji(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 jr(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=Ke(o,r))},[o,i,l,s,r]}class Gr extends _e{constructor(t){super(),ye(this,t,jr,Fr,fe,{annotation:0,geom:3,style:4})}}function zr(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(qr).join(" ")),f(o,"class","a9s-inner"),f(o,"style",e[1]),f(o,"points",e[2].map(Qr).join(" ")),f(t,"class","a9s-annotation"),f(t,"data-id",s=e[0].id)},m(r,l){V(r,t,l),Z(t,n),Z(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 qr=e=>e.join(","),Qr=e=>e.join(",");function Zr(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=Ke(o,r))},[o,i,l,s,r]}class Kr extends _e{constructor(t){super(),ye(this,t,Zr,zr,fe,{annotation:0,geom:3,style:4})}}function Wr(e){let t,n,i,o,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),f(n,"class",i=wt(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),f(n,"style",o=e[3]?"display:none;":void 0),f(n,"d",e[2]),f(s,"class",r=wt(`a9s-inner ${e[1]}`)+" svelte-1w0132l"),f(s,"style",e[3]),f(s,"d",e[2]),f(t,"class","a9s-annotation"),f(t,"data-id",l=e[0].id)},m(a,u){V(a,t,u),Z(t,n),Z(t,s)},p(a,[u]){u&2&&i!==(i=wt(`a9s-outer ${a[1]}`)+" svelte-1w0132l")&&f(n,"class",i),u&8&&o!==(o=a[3]?"display:none;":void 0)&&f(n,"style",o),u&4&&f(n,"d",a[2]),u&2&&r!==(r=wt(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&f(s,"class",r),u&8&&f(s,"style",a[3]),u&4&&f(s,"d",a[2]),u&1&&l!==(l=a[0].id)&&f(t,"data-id",l)},i:q,o:q,d(a){a&&H(t)}}}function Jr(e,t,n){let i,o,s,{annotation:r}=t,{geom:l}=t,{style:a}=t;return e.$$set=u=>{"annotation"in u&&n(0,r=u.annotation),"geom"in u&&n(4,l=u.geom),"style"in u&&n(5,a=u.style)},e.$$.update=()=>{e.$$.dirty&33&&n(3,i=Ke(r,a)),e.$$.dirty&16&&n(2,o=Pn(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,o,i,l,a]}class xr extends _e{constructor(t){super(),ye(this,t,Jr,Wr,fe,{annotation:0,geom:4,style:5})}}function $r(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),Z(t,n),Z(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 el(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=Ke(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 tl extends _e{constructor(t){super(),ye(this,t,el,$r,fe,{annotation:0,geom:6,style:7})}}const nl={elementToImage:(e,t)=>[e,t]},Gi=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]}}),il=250,zi=(e,t)=>{const n=Ve();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:r=>{if(performance.now()-i<il){const{x:a,y:u}=an(r,e),h=t.getAt(a,u,void 0,2);h?n("click",{originalEvent:r,annotation:h}):n("click",{originalEvent:r})}}}},an=(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 qi(e,t,n){const i=e.slice();return i[39]=t[n],i}function Qi(e,t,n){const i=e.slice();return i[42]=t[n],i}function un(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Zi(e){let t=e[42],n,i,o=Ki(e);return{c(){o.c(),n=Ie()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&131072&&fe(t,t=s[42])?(Me(),j(o,1,1,q),ve(),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){j(o),i=!1},d(s){s&&H(n),o.d(s)}}}function ol(e){let t,n;return t=new Xr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(i,o){ce(t,i,o),n=!0},p(i,o){const s={};o[0]&131072&&(s.annotation=i[42]),o[0]&131072&&(s.geom=i[45].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function sl(e){let t,n;return t=new xr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(i,o){ce(t,i,o),n=!0},p(i,o){const s={};o[0]&131072&&(s.annotation=i[42]),o[0]&131072&&(s.geom=i[45].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function rl(e){let t,n;return t=new Gr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(i,o){ce(t,i,o),n=!0},p(i,o){const s={};o[0]&131072&&(s.annotation=i[42]),o[0]&131072&&(s.geom=i[45].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function ll(e){let t,n;return t=new Kr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(i,o){ce(t,i,o),n=!0},p(i,o){const s={};o[0]&131072&&(s.annotation=i[42]),o[0]&131072&&(s.geom=i[45].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function al(e){let t,n;return t=new tl({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(i,o){ce(t,i,o),n=!0},p(i,o){const s={};o[0]&131072&&(s.annotation=i[42]),o[0]&131072&&(s.geom=i[45].geometry),o[0]&2&&(s.style=i[1]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function ul(e){var i;let t,n;return t=new Vr({props:{annotation:e[42],geom:(i=e[45])==null?void 0:i.geometry,style:e[1]}}),{c(){ge(t.$$.fragment)},m(o,s){ce(t,o,s),n=!0},p(o,s){var l;const r={};s[0]&131072&&(r.annotation=o[42]),s[0]&131072&&(r.geom=(l=o[45])==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){j(t.$$.fragment,o),n=!1},d(o){he(t,o)}}}function Ki(e){let t,n,i,o;const s=[ul,al,ll,rl,sl,ol],r=[];function l(a,u){var h,c,d,y,p,g;return((h=a[45])==null?void 0:h.type)===te.ELLIPSE?0:((c=a[45])==null?void 0:c.type)===te.RECTANGLE?1:((d=a[45])==null?void 0:d.type)===te.POLYGON?2:((y=a[45])==null?void 0:y.type)===te.MULTIPOLYGON?3:((p=a[45])==null?void 0:p.type)===te.POLYLINE?4:((g=a[45])==null?void 0:g.type)===te.LINE?5:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Ie()},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&&(Me(),j(r[h],1,1,()=>{r[h]=null}),ve()),~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){j(n),o=!1},d(a){a&&H(i),~t&&r[t].d(a)}}}function Wi(e){let t=ct(e[42])&&!e[10](e[42]),n,i,o=t&&Zi(un(e));return{c(){o&&o.c(),n=Ie()},m(s,r){o&&o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&132096&&(t=ct(s[42])&&!s[10](s[42])),t?o?(o.p(un(s),r),r[0]&132096&&B(o,1)):(o=Zi(un(s)),o.c(),B(o,1),o.m(n.parentNode,n)):o&&(Me(),j(o,1,1,()=>{o=null}),ve())},i(s){i||(B(o),i=!0)},o(s){j(o),i=!1},d(s){s&&H(n),o&&o.d(s)}}}function Ji(e){let t,n,i,o;const s=[cl,fl],r=[];function l(a,u){return a[6]?0:a[15]&&a[0]?1:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),i=Ie()},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&&(Me(),j(r[h],1,1,()=>{r[h]=null}),ve()),~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){j(n),o=!1},d(a){a&&H(i),~t&&r[t].d(a)}}}function fl(e){let t=`${e[2]}-${e[7]}`,n,i,o=xi(e);return{c(){o.c(),n=Ie()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&132&&fe(t,t=`${s[2]}-${s[7]}`)?(Me(),j(o,1,1,q),ve(),o=xi(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){j(o),i=!1},d(s){s&&H(n),o.d(s)}}}function cl(e){let t,n,i=Se(e[6]),o=[];for(let r=0;r<i.length;r+=1)o[r]=eo(qi(e,i,r));const s=r=>j(o[r],1,1,()=>{o[r]=null});return{c(){for(let r=0;r<o.length;r+=1)o[r].c();t=Ie()},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]&8659266){i=Se(r[6]);let a;for(a=0;a<i.length;a+=1){const u=qi(r,i,a);o[a]?(o[a].p(u,l),B(o[a],1)):(o[a]=eo(u),o[a].c(),B(o[a],1),o[a].m(t.parentNode,t))}for(Me(),a=i.length;a<o.length;a+=1)s(a);ve()}},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)j(o[l]);n=!1},d(r){r&&H(t),Ge(o,r)}}}function xi(e){let t,n;return t=new Ui({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ge(t.$$.fragment)},m(i,o){ce(t,i,o),n=!0},p(i,o){const s={};o[0]&256&&(s.target=i[8]),o[0]&32768&&(s.tool=i[15]),o[0]&16384&&(s.drawingMode=i[14]),o[0]&8192&&(s.transform=i[13]),o[0]&262144&&(s.viewportScale=i[18]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function $i(e){let t,n;return t=new Di({props:{target:e[8],editor:e[39].editor,annotation:e[39].annotation,style:e[1],transform:e[13],viewportScale:e[18]}}),t.$on("change",function(){le(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ge(t.$$.fragment)},m(i,o){ce(t,i,o),n=!0},p(i,o){e=i;const s={};o[0]&256&&(s.target=e[8]),o[0]&64&&(s.editor=e[39].editor),o[0]&64&&(s.annotation=e[39].annotation),o[0]&2&&(s.style=e[1]),o[0]&8192&&(s.transform=e[13]),o[0]&262144&&(s.viewportScale=e[18]),t.$set(s)},i(i){n||(B(t.$$.fragment,i),n=!0)},o(i){j(t.$$.fragment,i),n=!1},d(i){he(t,i)}}}function eo(e){let t=e[39].annotation.id,n,i,o=$i(e);return{c(){o.c(),n=Ie()},m(s,r){o.m(s,r),V(s,n,r),i=!0},p(s,r){r[0]&64&&fe(t,t=s[39].annotation.id)?(Me(),j(o,1,1,q),ve(),o=$i(s),o.c(),B(o,1),o.m(n.parentNode,n)):o.p(s,r)},i(s){i||(B(o),i=!0)},o(s){j(o),i=!1},d(s){s&&H(n),o.d(s)}}}function hl(e){let t,n,i,o,s,r,l=Se(e[17].filter(e[34])),a=[];for(let c=0;c<l.length;c+=1)a[c]=Wi(Qi(e,l,c));const u=c=>j(a[c],1,1,()=>{a[c]=null});let h=e[8]&&Ji(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[15]),Pe(t,"editing",e[5]),Pe(t,"hidden",!e[3]),Pe(t,"hover",e[16])},m(c,d){V(c,t,d),Z(t,n);for(let y=0;y<a.length;y+=1)a[y]&&a[y].m(n,null);Z(t,i),h&&h.m(i,null),e[35](i),e[36](t),o=!0,s||(r=[ee(t,"pointerup",function(){le(e[11])&&e[11].apply(this,arguments)}),ee(t,"pointerdown",function(){le(e[12])&&e[12].apply(this,arguments)}),ee(t,"pointermove",e[24])],s=!0)},p(c,d){if(e=c,d[0]&132098){l=Se(e[17].filter(e[34]));let y;for(y=0;y<l.length;y+=1){const p=Qi(e,l,y);a[y]?(a[y].p(p,d),B(a[y],1)):(a[y]=Wi(p),a[y].c(),B(a[y],1),a[y].m(n,null))}for(Me(),y=l.length;y<a.length;y+=1)u(y);ve()}e[8]?h?(h.p(e,d),d[0]&256&&B(h,1)):(h=Ji(e),h.c(),B(h,1),h.m(i,null)):h&&(Me(),j(h,1,1,()=>{h=null}),ve()),(!o||d[0]&32768)&&Pe(t,"drawing",e[15]),(!o||d[0]&32)&&Pe(t,"editing",e[5]),(!o||d[0]&8)&&Pe(t,"hidden",!e[3]),(!o||d[0]&65536)&&Pe(t,"hover",e[16])},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)j(a[d]);j(h),o=!1},d(c){c&&H(t),Ge(a,c),h&&h.d(),e[35](null),e[36](null),s=!1,Ne(r)}}}function dl(e,t,n){let i,o,s,r,l,a,u,h,c,d,y,p,g=q,v=()=>(g(),g=mn(E,X=>n(18,p=X)),E);e.$$.on_destroy.push(()=>g());let{drawingEnabled:_}=t,{image:O}=t,{preferredDrawingMode:b}=t,{state:M}=t,{style:S=void 0}=t,{toolName:N=rn()[0]}=t,{user:C}=t,{visible:U=!0}=t,k=0;const G=()=>n(7,k+=1),z=()=>N,w=()=>_;let T,m,E;ze(()=>v(n(9,E=ai(O,m))));const{hover:R,selection:I,store:P}=M;Pt(e,R,X=>n(16,c=X)),Pt(e,I,X=>n(33,d=X)),Pt(e,P,X=>n(17,y=X));let Q,F;const J=X=>{Q&&P.unobserve(Q);const pe=X.filter(({editable:ne})=>ne).map(({id:ne})=>ne);pe.length>0?(n(5,F=pe.map(ne=>P.getAnnotation(ne)).filter(ne=>ne&&ct(ne))),Q=ne=>{const{updated:be}=ne.changes;n(5,F=be==null?void 0:be.map(Ae=>Ae.newValue))},P.observe(Q,{annotations:pe})):n(5,F=void 0)},W=X=>{const pe=ei(),ne={id:pe,bodies:[],target:{annotation:pe,selector:X.detail,creator:C,created:new Date}};P.addAnnotation(ne),I.setSelected(ne.id)},x=X=>pe=>{var ot;const{target:ne}=X,be=10*60*1e3,Ae=((ot=ne.creator)==null?void 0:ot.id)!==C.id||!ne.created||new Date().getTime()-ne.created.getTime()>be;P.updateTarget({...ne,selector:pe.detail,created:Ae?ne.created:new Date,updated:Ae?new Date:void 0,updatedBy:Ae?C:void 0})},se=X=>{const{x:pe,y:ne}=an(X,m),be=P.getAt(pe,ne,void 0,2);be?c!==be.id&&R.set(be.id):R.set(void 0)},ae=X=>ct(X);function Ce(X){Et[X?"unshift":"push"](()=>{T=X,n(8,T)})}function ke(X){Et[X?"unshift":"push"](()=>{m=X,n(4,m)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,_=X.drawingEnabled),"image"in X&&n(25,O=X.image),"preferredDrawingMode"in X&&n(26,b=X.preferredDrawingMode),"state"in X&&n(27,M=X.state),"style"in X&&n(1,S=X.style),"toolName"in X&&n(2,N=X.toolName),"user"in X&&n(28,C=X.user),"visible"in X&&n(3,U=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:i,opts:o}=ln(N)||{tool:void 0,opts:void 0},i,(n(32,o),n(2,N))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(14,s=(o==null?void 0:o.drawingMode)||b),e.$$.dirty[0]&16&&n(13,r=Gi(m)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=zi(m,P),l,(n(11,a),n(4,m))),e.$$.dirty[1]&4&&J(d.selected),e.$$.dirty[0]&32&&n(6,u=F?F.map(X=>({annotation:X,editor:ki(X.target.selector)})).filter(X=>X.editor):void 0),e.$$.dirty[0]&64&&n(10,h=X=>u&&u.some(pe=>pe.annotation.id===X.id))},[_,S,N,U,m,F,u,k,T,E,h,a,l,r,s,i,c,y,p,R,I,P,W,x,se,O,b,M,C,G,z,w,o,d,ae,Ce,ke]}class to extends _e{constructor(t){super(),ye(this,t,dl,hl,fe,{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 no(e,t,n=0,i=e.length-1,o=gl){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),y=Math.max(n,Math.floor(t-u*c/a+d)),p=Math.min(i,Math.floor(t+(a-u)*c/a+d));no(e,t,y,p,o)}const s=e[t];let r=n,l=i;for(yt(e,n,t),o(e[i],s)>0&&yt(e,n,i);r<l;){for(yt(e,r,l),r++,l--;o(e[r],s)<0;)r++;for(;o(e[l],s)>0;)l--}o(e[n],s)===0?yt(e,n,l):(l++,yt(e,l,i)),l<=t&&(n=l+1),t<=l&&(i=l-1)}}function yt(e,t,n){const i=e[t];e[t]=e[n],e[n]=i}function gl(e,t){return e<t?-1:e>t?1:0}class pl{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(!Nt(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;Nt(t,a)&&(n.leaf?i.push(l):cn(t,a)?this._all(l,i):s.push(l))}n=s.pop()}return i}collides(t){let n=this.data;if(!Nt(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(Nt(t,r)){if(n.leaf||cn(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=it([]),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=yl(t,i.children,n);if(h!==-1)return i.children.splice(h,1),s.push(i),this._condense(s),this}!u&&!i.leaf&&cn(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=it(t.slice(n,i+1)),nt(l,this.toBBox),l;o||(o=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,o-1))),l=it([]),l.leaf=!1,l.height=o;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));io(t,n,i,u,this.compareMinX);for(let h=n;h<=i;h+=u){const c=Math.min(h+u-1,i);io(t,h,c,a,this.compareMinY);for(let d=h;d<=c;d+=a){const y=Math.min(d+a-1,c);l.children.push(this._build(t,d,y,o-1))}}return nt(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=fn(u),c=wl(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),mt(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=it(i.children.splice(r,i.children.length-r));l.height=i.height,l.leaf=i.leaf,nt(i,this.toBBox),nt(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(i,l)}_splitRoot(t,n){this.data=it([t,n]),this.data.height=t.height+1,this.data.leaf=!1,nt(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=_t(t,0,l,this.toBBox),u=_t(t,l,i,this.toBBox),h=El(a,u),c=fn(a)+fn(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:_l,s=t.leaf?this.compareMinY:ml,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=_t(t,0,n,s),l=_t(t,i-n,i,s);let a=Ct(r)+Ct(l);for(let u=n;u<i-n;u++){const h=t.children[u];mt(r,t.leaf?s(h):h),a+=Ct(r)}for(let u=i-n-1;u>=n;u--){const h=t.children[u];mt(l,t.leaf?s(h):h),a+=Ct(l)}return a}_adjustParentBBoxes(t,n,i){for(let o=i;o>=0;o--)mt(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():nt(t[n],this.toBBox)}}function yl(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 nt(e,t){_t(e,0,e.children.length,t,e)}function _t(e,t,n,i,o){o||(o=it(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];mt(o,e.leaf?i(r):r)}return o}function mt(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 _l(e,t){return e.minX-t.minX}function ml(e,t){return e.minY-t.minY}function fn(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function Ct(e){return e.maxX-e.minX+(e.maxY-e.minY)}function wl(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 El(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 cn(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function Nt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function it(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function io(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;no(e,r,t,n,o),s.push(t,r,r,n)}}const bl=()=>{const e=new pl,t=new Map,n=()=>[...t.values()],i=()=>{e.clear(),t.clear()},o=c=>{if(!ht(c))return;const{minX:d,minY:y,maxX:p,maxY:g}=c.selector.geometry.bounds,v={minX:d,minY:y,maxX:p,maxY:g,target:c};e.insert(v),t.set(c.annotation,v)},s=c=>{if(!ht(c))return;const d=t.get(c.annotation);d&&e.remove(d),t.delete(c.annotation)};return{all:n,clear:i,getAt:(c,d,y,p=0)=>{const v=e.search({minX:c-p,minY:d-p,maxX:c+p,maxY:d+p}).map(_=>_.target).filter(_=>_.selector.type===te.RECTANGLE||Nn(_.selector,c,d,p));return v.length>0?(v.sort((_,O)=>Tt(_.selector)-Tt(O.selector)),v):[]},getIntersecting:(c,d,y,p)=>e.search({minX:c,minY:d,maxX:c+y,maxY:d+p}).map(g=>g.target),insert:o,remove:s,set:(c,d=!0)=>{d&&i();const y=c.reduce((p,g)=>{if(ht(g)){const{minX:v,minY:_,maxX:O,maxY:b}=g.selector.geometry.bounds;return[...p,{minX:v,minY:_,maxX:O,maxY:b,target:g}]}else return p},[]);y.forEach(p=>t.set(p.target.annotation,p)),e.load(y)},size:()=>e.all().length,update:(c,d)=>{s(c),o(d)}}},oo=e=>{const t=Cs(),n=bl(),i=gs(t,e.userSelectAction,e.adapter),o=ds(t),s=ks();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,c)=>{const d=n.getAt(a,u,h,c);if(h)return d.map(p=>t.getAnnotation(p.annotation)).filter(Boolean).filter(h)[0];{const y=d[0];return y?t.getAnnotation(y.annotation):void 0}},getIntersecting:(a,u,h,c)=>n.getIntersecting(a,u,h,c).map(d=>t.getAnnotation(d.annotation)).filter(Boolean)},selection:i,hover:o,viewport:s}},so=e=>{const t=oo(e);return{...t,store:Ns(t.store)}},ro=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},lo=e=>{const t=ro(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},hn=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?lo(e):n),ao=(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}),dn=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,uo=(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=()=>{dn?n.removeEventListener("keydown",o):n.removeEventListener("keydown",i)};return dn?n.addEventListener("keydown",o):n.addEventListener("keydown",i),{destroy:s}},Tl=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,i=ao(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Qt.EDIT,theme:"light"}),o=so(i),{selection:s,store:r}=o,l=Rs(r,i.initialHistory),a=Ps(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=uo(l);let c=Gs();hn(n,u,i.theme);const d=new to({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 y=Us(o,l,i.adapter),p=()=>d.cancelDrawing(),g=()=>{d.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),h.destroy(),l.destroy()},v=()=>d.getDrawingTool(),_=()=>c,O=()=>d.isDrawingEnabled(),b=(w,T,m)=>Xi(w,T,m),M=(w,T)=>Pi(w,T),S=w=>{if(!ln(w))throw`No drawing tool named ${w}`;d.$set({toolName:w})},N=w=>d.$set({drawingEnabled:w}),C=w=>{console.warn("Filter not implemented yet")},U=w=>d.$set({style:w}),k=w=>hn(n,u,w),G=w=>{c=w,d.$set({user:w})},z=w=>d.$set({visible:w});return{...y,cancelDrawing:p,destroy:g,getDrawingTool:v,getUser:_,isDrawingEnabled:O,listDrawingTools:rn,on:a.on,off:a.off,registerDrawingTool:b,registerShapeEditor:M,setDrawingEnabled:N,setDrawingTool:S,setFilter:C,setStyle:U,setTheme:k,setUser:G,setVisible:z,element:u,state:o}};D.Editor=St,D.EditorMount=Di,D.Handle=We,D.IdentityTransform=nl,D.PolygonEditor=Ei,D.RectangleEditor=bi,D.RectangleUtil=Dn,D.RubberbandRectangle=Vi,D.SVGAnnotationLayer=to,D.ShapeType=te,D.ToolMount=Ui,D.UserSelectAction=Qt,D.W3CImageFormat=Ws,D.addEventListeners=zi,D.approximateAsPolygon=Bt,D.boundsFromMultiPolygonElements=ft,D.boundsFromPoints=me,D.chainStyles=Vs,D.computeArea=Tt,D.computePolygonArea=lt,D.computeSVGPath=Pn,D.computeStyle=Hs,D.createBody=Es,D.createImageAnnotator=Tl,D.createImageAnnotatorState=oo,D.createSVGTransform=Gi,D.createSvelteImageAnnotatorState=so,D.defaultColorProvider=Ks,D.detectTheme=lo,D.distance=ut,D.enableResponsive=ai,D.fillDefaults=ao,D.getAllCorners=Ln,D.getEditor=ki,D.getMaskDimensions=dt,D.getSVGPoint=an,D.getTool=ln,D.initKeyboardCommands=uo,D.intersects=Nn,D.isImageAnnotation=ct,D.isImageAnnotationTarget=ht,D.isMac=dn,D.isPointInPolygon=at,D.isTouch=Ue,D.listDrawingTools=rn,D.multipolygonElementToPath=De,D.parseFragmentSelector=Un,D.parseSVGSelector=Jn,D.parseW3CImageAnnotation=ri,D.pointsToPath=In,D.registerEditor=Pi,D.registerShapeUtil=Qe,D.registerTool=Xi,D.sampleBrightness=ro,D.serializeFragmentSelector=Hn,D.serializeSVGSelector=xn,D.serializeW3CImageAnnotation=li,D.setTheme=hn,D.simplifyMultiPolygon=No,D.simplifyPoints=Yt,D.simplifyPolygon=Lo,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
3
3
  //# sourceMappingURL=annotorious.js.map