@annotorious/annotorious 3.6.1 → 3.6.3

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,2 @@
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 R(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(" "),Rn=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)}},Ro=(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 Lo={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=Ln(i.point,i.outHandle||i.point,o.inHandle||o.point,o.point,10);t.push(...r.slice(1))}}return t},Ln=(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=Ln(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.type==="CURVE"&&s.outHandle||s.point,l=o.type==="CURVE"&&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,Lo);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 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 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){Re(e,t,n);const i=e*e+t*t-n*n;if(0>i)return[];if(i===0)return[[e*n/(e*e+t*t),t*n/(e*e+t*t)]];const o=Math.sqrt(i);return[[(e*n+t*o)/(e*e+t*t),(t*n-e*o)/(e*e+t*t)],[(e*n-t*o)/(e*e+t*t),(t*n+e*o)/(e*e+t*t)]]}const Ze=Math.PI/180;function 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){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 zn(){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 Xo(){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 Fo(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];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 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 Qn(){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 jo(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 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 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 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){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 zo(e,t=0){return Re(e,t),Be(1,0,0,1,e,t)}function qo(e,t=e){return Re(e,t),Be(e,0,0,t,0,0)}function Qo(e){return Re(e),Be(1,0,Math.tan(e),1,0,0)}function Zo(e){return Re(e),Be(1,Math.tan(e),0,1,0,0)}function Ko(e=0){return Re(e),Be(-1,0,0,1,e,0)}function Wo(e=0){return Re(e),Be(1,0,0,-1,0,e)}function Jo(){return Le((e,t,n)=>A.ARC===e.type?Ho(e,e.relative?0:t,e.relative?0:n):e)}function xo(){return Le((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=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=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:Le,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,L=E&&e.get(E);if(L){const I=oi(L,m);return E===m.id?e.set(E,m):(e.delete(E),e.set(m.id,m)),L.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,L=l(w,T);L&&s(E,{updated:[L]})},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,L)=>{const I=l(L);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:L}=m.reduce((P,Q)=>e.get(Q.id)?{...P,toUpdate:[...P.toUpdate,Q]}:{...P,toAdd:[...P.toAdd,Q]},{toAdd:[],toUpdate:[]}),I=L.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 L=[...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:L})}else{const L=w.reduce((I,P)=>{const Q=P.id&&e.get(P.id);return Q?[...I,Q]:I},[]);if(L.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${L.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,L)=>{const I=v(L);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(L=>L.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),L={...m,bodies:m.bodies.map(I=>I.id===E.id?T:I)};return e.set(m.id,L),E.id!==T.id&&(t.delete(E.id),t.set(T.id,L.id)),{oldValue:m,newValue:L,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 Rs=250,Ls=(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>Rs)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=R("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=R("g"),n=R("circle"),u&&u.c(),o=R("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=R("g"),n=R("circle"),o=R("circle"),r=R("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=R("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=R("g"),n=R("circle"),o=R("circle"),s=R("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=R("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=R("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=R("mask"),n=R("rect"),l=R("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=R("defs"),n=R("mask"),i=R("rect"),a=R("polygon"),N&&N.c(),C&&C.c(),h=Oe(),c=R("polygon"),y=Oe(),p=R("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,L]=u.elementToImage(m.offsetX,m.offsetY),I=W=>Math.pow(W[0]-E,2)+Math.pow(W[1]-L,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 L=g.includes(m);E.metaKey||E.ctrlKey||E.shiftKey?L?n(8,g=g.filter(I=>I!==m)):n(8,g=[...g,m]):L&&g.length>1?n(8,g=[m]):L?n(8,g=[]):n(8,g=[m]),b()},C=(m,E,L)=>{b();let I;const P=m.geometry;g.length>1?I=P.points.map(([F,J],W)=>g.includes(W)?[F+L[0],J+L[1]]:[F,J]):E==="SHAPE"?I=P.points.map(([F,J])=>[F+L[0],J+L[1]]):I=P.points.map(([F,J],W)=>E===`HANDLE-${W}`?[F+L[0],J+L[1]]:[F,J]);const Q=me(I);return{...m,geometry:{points:I,bounds:Q}}},U=m=>async E=>{E.stopPropagation();const L=[...i.points.slice(0,m+1),o[m].point,...i.points.slice(m+1)],I=me(L);r("change",{...l,geometry:{points:L,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((L,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 L=E===i.points.length-1?i.points[0]:i.points[E+1],I=(m[0]+L[0])/2,P=(m[1]+L[1])/2,F=Math.sqrt(Math.pow(L[0]-I,2)+Math.pow(L[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,L,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=R("defs"),n=R("mask"),i=R("rect"),a=R("rect"),y=Oe(),p=R("rect"),b=Oe(),M=R("rect"),k=Oe(),G=R("rect"),m=Oe(),E=R("rect"),Q=Oe(),F=R("rect"),se=Oe(),ae=R("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",L=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&&L!==(L=e[5].x+e[5].w))&&f(E,"x",L),(!$||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 Rt={};Y&32&&(Rt.x=e[5].x+e[5].w),Y&32&&(Rt.y=e[5].y),Y&8&&(Rt.scale=e[3]),Ae.$set(Rt);const Lt={};Y&32&&(Lt.x=e[5].x+e[5].w),Y&32&&(Lt.y=e[5].y+e[5].h),Y&8&&(Lt.scale=e[3]),Fe.$set(Lt);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=R("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=R("mask"),n=R("rect"),l=R("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=R("g"),n=R("defs"),i=R("mask"),o=R("rect"),u=R("path"),O&&O.c(),b&&b.c(),c=R("path"),y=R("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 Ri(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]&&Ri(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=Ri(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[L,I]=u.elementToImage(E.offsetX,E.offsetY),P=x=>Math.pow(x[0]-L,2)+Math.pow(x[1]-I,2),Q=Rn(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,L,I)=>P=>{if(!p||Ue||performance.now()-p>Ar)return;const Q=J=>J.polygon===E&&J.ring===L&&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:L,point:I}]):F&&g.length>1?n(8,g=[{polygon:E,ring:L,point:I}]):F?n(8,g=[]):n(8,g=[{polygon:E,ring:L,point:I}]),b()},C=(E,L,I)=>{b();const P=E.geometry.polygons;let Q;if(L==="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]=L.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 L=>{L.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:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.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=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.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,L,I,{polygon:P,ring:Q,point:F})=>P===E&&Q===L&&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 Li=new Map([[te.RECTANGLE,bi],[te.POLYGON,Ei],[te.MULTIPOLYGON,vr]]),ki=e=>Li.get(e.type),Pi=(e,t)=>Li.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=R("defs"),n=R("mask"),i=R("rect"),a=R("rect"),u=R("rect"),h=R("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=R("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=R("defs"),n=R("mask"),i=R("rect"),a=R("polygon"),h=R("polygon"),d=R("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=R("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 Rr(e){let t,n=e[3]&&Yi(on(e));return{c(){t=R("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 Lr=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<Lr)}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,Rr,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=R("g"),n=R("ellipse"),o=R("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=R("g"),n=R("line"),o=R("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=R("path"),i=R("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=R("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=R("g"),n=R("polygon"),o=R("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=R("g"),n=R("path"),s=R("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=R("g"),n=R("rect"),o=R("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=R("svg"),n=R("g");for(let c=0;c<a.length;c+=1)a[c].c();i=R("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:L,selection:I,store:P}=M;Pt(e,L,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&&L.set(be.id):L.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,L,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=Ls(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=Rn,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=Ro,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
1
+ (function(D,j){typeof exports=="object"&&typeof module<"u"?j(exports):typeof define=="function"&&define.amd?define(["exports"],j):(D=typeof globalThis<"u"?globalThis:D||self,j(D.Annotorious={}))})(this,function(D){"use strict";var Nr=Object.defineProperty;var Yr=(D,j,Ie)=>j in D?Nr(D,j,{enumerable:!0,configurable:!0,writable:!0,value:Ie}):D[j]=Ie;var nn=(D,j,Ie)=>Yr(D,typeof j!="symbol"?j+"":j,Ie);function j(){}function Ie(e,t){for(const n in t)e[n]=t[n];return e}function on(e){return e()}function sn(){return Object.create(null)}function Ae(e){e.forEach(on)}function ie(e){return typeof e=="function"}function re(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}function jo(e){return Object.keys(e).length===0}function rn(e,...t){if(e==null){for(const o of t)o(void 0);return j}const n=e.subscribe(...t);return n.unsubscribe?()=>n.unsubscribe():n}function At(e,t,n){e.$$.on_destroy.push(rn(t,n))}function zo(e,t,n,o){if(e){const i=ln(e,t,n,o);return e[0](i)}}function ln(e,t,n,o){return e[1]&&o?Ie(n.ctx.slice(),e[1](o(t))):n.ctx}function Fo(e,t,n,o){if(e[2]&&o){const i=e[2](o(n));if(t.dirty===void 0)return i;if(typeof i=="object"){const s=[],r=Math.max(t.dirty.length,i.length);for(let l=0;l<r;l+=1)s[l]=t.dirty[l]|i[l];return s}return t.dirty|i}return t.dirty}function qo(e,t,n,o,i,s){if(i){const r=ln(t,n,o,s);e.p(r,i)}}function Ko(e){if(e.ctx.length>32){const t=[],n=e.ctx.length/32;for(let o=0;o<n;o++)t[o]=-1;return t}return-1}function an(e){const t={};for(const n in e)n[0]!=="$"&&(t[n]=e[n]);return t}function ct(e){return e??""}function F(e,t){e.appendChild(t)}function Y(e,t,n){e.insertBefore(t,n||null)}function N(e){e.parentNode&&e.parentNode.removeChild(e)}function Ye(e,t){for(let n=0;n<e.length;n+=1)e[n]&&e[n].d(t)}function L(e){return document.createElementNS("http://www.w3.org/2000/svg",e)}function cn(e){return document.createTextNode(e)}function we(){return cn(" ")}function ke(){return cn("")}function ee(e,t,n,o){return e.addEventListener(t,n,o),()=>e.removeEventListener(t,n,o)}function c(e,t,n){n==null?e.removeAttribute(t):e.getAttribute(t)!==n&&e.setAttribute(t,n)}function Wo(e){return Array.from(e.childNodes)}function Te(e,t,n){e.classList.toggle(t,!!n)}function Zo(e,t,{bubbles:n=!1,cancelable:o=!1}={}){return new CustomEvent(e,{detail:t,bubbles:n,cancelable:o})}let Ze;function Je(e){Ze=e}function un(){if(!Ze)throw new Error("Function called outside component initialization");return Ze}function Be(e){un().$$.on_mount.push(e)}function Ce(){const e=un();return(t,n,{cancelable:o=!1}={})=>{const i=e.$$.callbacks[t];if(i){const s=Zo(t,n,{cancelable:o});return i.slice().forEach(r=>{r.call(e,s)}),!s.defaultPrevented}return!0}}function _e(e,t){const n=e.$$.callbacks[t.type];n&&n.slice().forEach(o=>o.call(this,t))}const He=[],ut=[];let Ge=[];const fn=[],dn=Promise.resolve();let kt=!1;function hn(){kt||(kt=!0,dn.then(mn))}function gn(){return hn(),dn}function Mt(e){Ge.push(e)}const Tt=new Set;let je=0;function mn(){if(je!==0)return;const e=Ze;do{try{for(;je<He.length;){const t=He[je];je++,Je(t),Jo(t.$$)}}catch(t){throw He.length=0,je=0,t}for(Je(null),He.length=0,je=0;ut.length;)ut.pop()();for(let t=0;t<Ge.length;t+=1){const n=Ge[t];Tt.has(n)||(Tt.add(n),n())}Ge.length=0}while(He.length);for(;fn.length;)fn.pop()();kt=!1,Tt.clear(),Je(e)}function Jo(e){if(e.fragment!==null){e.update(),Ae(e.before_update);const t=e.dirty;e.dirty=[-1],e.fragment&&e.fragment.p(e.ctx,t),e.after_update.forEach(Mt)}}function Qo(e){const t=[],n=[];Ge.forEach(o=>e.indexOf(o)===-1?t.push(o):n.push(o)),n.forEach(o=>o()),Ge=t}const ft=new Set;let Re;function be(){Re={r:0,c:[],p:Re}}function Ee(){Re.r||Ae(Re.c),Re=Re.p}function U(e,t){e&&e.i&&(ft.delete(e),e.i(t))}function G(e,t,n,o){if(e&&e.o){if(ft.has(e))return;ft.add(e),Re.c.push(()=>{ft.delete(e),o&&(n&&e.d(1),o())}),e.o(t)}else o&&o()}function ve(e){return(e==null?void 0:e.length)!==void 0?e:Array.from(e)}function ce(e){e&&e.c()}function le(e,t,n){const{fragment:o,after_update:i}=e.$$;o&&o.m(t,n),Mt(()=>{const s=e.$$.on_mount.map(on).filter(ie);e.$$.on_destroy?e.$$.on_destroy.push(...s):Ae(s),e.$$.on_mount=[]}),i.forEach(Mt)}function ae(e,t){const n=e.$$;n.fragment!==null&&(Qo(n.after_update),Ae(n.on_destroy),n.fragment&&n.fragment.d(t),n.on_destroy=n.fragment=null,n.ctx=[])}function xo(e,t){e.$$.dirty[0]===-1&&(He.push(e),hn(),e.$$.dirty.fill(0)),e.$$.dirty[t/31|0]|=1<<t%31}function de(e,t,n,o,i,s,r=null,l=[-1]){const a=Ze;Je(e);const u=e.$$={fragment:null,ctx:[],props:s,update:j,not_equal:i,bound:sn(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(a?a.$$.context:[])),callbacks:sn(),dirty:l,skip_bound:!1,root:t.target||a.$$.root};r&&r(u.root);let d=!1;if(u.ctx=n?n(e,t.props||{},(f,h,...y)=>{const m=y.length?y[0]:h;return u.ctx&&i(u.ctx[f],u.ctx[f]=m)&&(!u.skip_bound&&u.bound[f]&&u.bound[f](m),d&&xo(e,f)),h}):[],u.update(),d=!0,Ae(u.before_update),u.fragment=o?o(u.ctx):!1,t.target){if(t.hydrate){const f=Wo(t.target);u.fragment&&u.fragment.l(f),f.forEach(N)}else u.fragment&&u.fragment.c();t.intro&&U(e.$$.fragment),le(e,t.target,t.anchor),mn()}Je(a)}class he{constructor(){nn(this,"$$");nn(this,"$$set")}$destroy(){ae(this,1),this.$destroy=j}$on(t,n){if(!ie(n))return j;const o=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return o.push(n),()=>{const i=o.indexOf(n);i!==-1&&o.splice(i,1)}}$set(t){this.$$set&&!jo(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const $o="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add($o);var J=(e=>(e.ELLIPSE="ELLIPSE",e.MULTIPOLYGON="MULTIPOLYGON",e.POLYGON="POLYGON",e.POLYLINE="POLYLINE",e.RECTANGLE="RECTANGLE",e.LINE="LINE",e))(J||{});function ei(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var pn={exports:{}};(function(e){(function(){function t(l,a){var u=l.x-a.x,d=l.y-a.y;return u*u+d*d}function n(l,a,u){var d=a.x,f=a.y,h=u.x-d,y=u.y-f;if(h!==0||y!==0){var m=((l.x-d)*h+(l.y-f)*y)/(h*h+y*y);m>1?(d=u.x,f=u.y):m>0&&(d+=h*m,f+=y*m)}return h=l.x-d,y=l.y-f,h*h+y*y}function o(l,a){for(var u=l[0],d=[u],f,h=1,y=l.length;h<y;h++)f=l[h],t(f,u)>a&&(d.push(f),u=f);return u!==f&&d.push(f),d}function i(l,a,u,d,f){for(var h=d,y,m=a+1;m<u;m++){var g=n(l[m],l[a],l[u]);g>h&&(y=m,h=g)}h>d&&(y-a>1&&i(l,a,y,d,f),f.push(l[y]),u-y>1&&i(l,y,u,d,f))}function s(l,a){var u=l.length-1,d=[l[0]];return i(l,0,u,a,d),d.push(l[u]),d}function r(l,a,u){if(l.length<=2)return l;var d=a!==void 0?a*a:1;return l=u?l:o(l,d),l=s(l,d),l}e.exports=r,e.exports.default=r})()})(pn);var ti=pn.exports;const ni=ei(ti),Pt={},Ue=(e,t)=>Pt[e]=t,dt=e=>Pt[e.type].area(e),_n=(e,t,n,o)=>Pt[e.type].intersects(e,t,n,o),ue=e=>{let t=1/0,n=1/0,o=-1/0,i=-1/0;return e.forEach(([s,r])=>{t=Math.min(t,s),n=Math.min(n,r),o=Math.max(o,s),i=Math.max(i,r)}),{minX:t,minY:n,maxX:o,maxY:i}},Qe=e=>{let t=0,n=e.length-1;for(let o=0;o<e.length;o++)t+=(e[n][0]+e[o][0])*(e[n][1]-e[o][1]),n=o;return Math.abs(.5*t)},xe=(e,t,n)=>{let o=!1;for(let i=0,s=e.length-1;i<e.length;s=i++){const r=e[i][0],l=e[i][1],a=e[s][0],u=e[s][1];l>n!=u>n&&t<(a-r)*(n-l)/(u-l)+r&&(o=!o)}return o},yn=(e,t=!0)=>{let n="M ";return e.forEach(([o,i],s)=>{s===0?n+=`${o},${i}`:n+=` L ${o},${i}`}),t&&(n+=" Z"),n},Lt=(e,t=1)=>{const n=e.map(([o,i])=>({x:o,y:i}));return ni(n,t,!0).map(o=>[o.x,o.y])},$e=(e,t)=>{const n=Math.abs(t[0]-e[0]),o=Math.abs(t[1]-e[1]);return Math.sqrt(Math.pow(n,2)+Math.pow(o,2))},oi={area:e=>Math.PI*e.geometry.rx*e.geometry.ry,intersects:(e,t,n)=>{const{cx:o,cy:i,rx:s,ry:r}=e.geometry,l=0,a=Math.cos(l),u=Math.sin(l),d=t-o,f=n-i,h=a*d+u*f,y=u*d-a*f;return h*h/(s*s)+y*y/(r*r)<=1}};Ue(J.ELLIPSE,oi);const ii={area:e=>0,intersects:(e,t,n,o=2)=>{const[[i,s],[r,l]]=e.geometry.points,a=Math.abs((l-s)*t-(r-i)*n+r*s-l*i),u=$e([i,s],[r,l]);return a/u<=o}};Ue(J.LINE,ii);const si={area:e=>{const{polygons:t}=e.geometry;return t.reduce((n,o)=>{const[i,...s]=o.rings,r=Qe(i.points),l=s.reduce((a,u)=>a+Qe(u.points),0);return n+r-l},0)},intersects:(e,t,n)=>{const{polygons:o}=e.geometry;for(const i of o){const[s,...r]=i.rings;if(xe(s.points,t,n)){let l=!1;for(const a of r)if(xe(a.points,t,n)){l=!0;break}if(!l)return!0}}return!1}},et=e=>{const t=e.reduce((n,o)=>[...n,...o.rings[0].points],[]);return ue(t)},Pe=e=>e.rings.map(n=>yn(n.points)).join(" "),wn=e=>e.polygons.reduce((t,n)=>[...t,...n.rings.reduce((o,i)=>[...o,...i.points],[])],[]),ri=(e,t=1)=>{const n=e.geometry.polygons.map(i=>{const s=i.rings.map(l=>{const a=Lt(l.points,t);return{...l,points:a}}),r=ue(s[0].points);return{...i,rings:s,bounds:r}}),o=et(n);return{...e,geometry:{...e.geometry,polygons:n,bounds:o}}};Ue(J.MULTIPOLYGON,si);const li={area:e=>{const t=e.geometry.points;return Qe(t)},intersects:(e,t,n)=>{const o=e.geometry.points;return xe(o,t,n)}},ai=(e,t=1)=>{const n=Lt(e.geometry.points,t),o=ue(n);return{...e,geometry:{...e.geometry,bounds:o,points:n}}};Ue(J.POLYGON,li);const ci={area:e=>{const t=e.geometry;if(!t.closed||t.points.length<3)return 0;const n=ht(t.points,t.closed);return Qe(n)},intersects:(e,t,n,o=2)=>{const i=e.geometry;if(i.closed){const s=ht(i.points,i.closed);return xe(s,t,n)}else return ui(i,[t,n],o)}},ht=(e,t=!1)=>{const n=[];for(let o=0;o<e.length;o++){const i=e[o],s=e[(o+1)%e.length];if(n.push(i.point),(o<e.length-1||t)&&(i.outHandle||s.inHandle)){const l=bn(i.point,i.outHandle||i.point,s.inHandle||s.point,s.point,10);n.push(...l.slice(1))}}return n},bn=(e,t,n,o,i=10)=>{const s=[];for(let r=0;r<=i;r++){const l=r/i,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)*o[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)*o[1];s.push([a,u])}return s},ui=(e,t,n)=>{for(let o=0;o<e.points.length-1;o++){const i=e.points[o],s=e.points[o+1];if(i.outHandle||s.inHandle){const l=bn(i.point,i.outHandle||i.point,s.inHandle||s.point,s.point,20);for(let a=0;a<l.length-1;a++)if(En(t,l[a],l[a+1])<=n)return!0}else if(En(t,i.point,s.point)<=n)return!0}return!1},En=(e,t,n)=>{const[o,i]=e,[s,r]=t,[l,a]=n,u=l-s,d=a-r,f=Math.sqrt(u*u+d*d);if(f===0)return Math.sqrt((o-s)*(o-s)+(i-r)*(i-r));const h=((o-s)*u+(i-r)*d)/(f*f);return h<=0?Math.sqrt((o-s)*(o-s)+(i-r)*(i-r)):h>=1?Math.sqrt((o-l)*(o-l)+(i-a)*(i-a)):Math.abs((a-r)*o-(l-s)*i+l*r-a*s)/f},It=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 o=1;o<e.points.length;o++){const i=e.points[o],s=e.points[o-1];if(i.type==="CURVE"||s.type==="CURVE"){const r=s.type==="CURVE"&&s.outHandle||s.point,l=i.type==="CURVE"&&i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}else t.push(`L ${i.point[0]} ${i.point[1]}`)}if(e.closed){const o=e.points[e.points.length-1],i=e.points[0];if(o.outHandle||i.inHandle){const r=o.outHandle||o.point,l=i.inHandle||i.point,a=i.point;t.push(`C ${r[0]} ${r[1]} ${l[0]} ${l[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Ue(J.POLYLINE,ci);const vn={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};Ue(J.RECTANGLE,vn);const tt=e=>nt(e.target),nt=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},Sn=(e,t=!1)=>{const n=typeof e=="string"?e:e.value,o=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,i=[...n.matchAll(o)][0],[s,r,l,a,u,d,f]=i;if(r!=="xywh")throw new Error("Unsupported MediaFragment: "+n);if(l&&l!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${l}`);const[h,y,m,g]=[a,u,d,f].map(parseFloat);return{type:J.RECTANGLE,geometry:{x:h,y,w:m,h:g,bounds:{minX:h,minY:t?y-g:y,maxX:h+m,maxY:t?y:y+g}}}},An=e=>{const{x:t,y:n,w:o,h:i}=e;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${n},${o},${i}`}},kn="http://www.w3.org/2000/svg",Mn=e=>{const t=o=>{Array.from(o.attributes).forEach(i=>{i.name.startsWith("on")&&o.removeAttribute(i.name)})},n=e.getElementsByTagName("script");return Array.from(n).reverse().forEach(o=>o.parentNode.removeChild(o)),Array.from(e.querySelectorAll("*")).forEach(t),e},fi=e=>{const o=new XMLSerializer().serializeToString(e.documentElement).replace("<svg>",`<svg xmlns="${kn}">`);return new DOMParser().parseFromString(o,"image/svg+xml").documentElement},gt=e=>{const n=new DOMParser().parseFromString(e,"image/svg+xml"),o=n.lookupPrefix(kn),i=n.lookupNamespaceURI(null);return o||i?Mn(n).firstChild:Mn(fi(n)).firstChild},di=e=>{const t=Tn(e),n=[];let o=[],i=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":o.length>0&&(n.push({points:o}),o=[]),i=[s.args[0],s.args[1]],o.push([...i]);break;case"L":i=[s.args[0],s.args[1]],o.push([...i]);break;case"H":i=[s.args[0],i[1]],o.push([...i]);break;case"V":i=[i[0],s.args[0]],o.push([...i]);break;case"C":i=[s.args[4],s.args[5]],o.push([...i]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(o.length>2&&n.push({points:o}),n.length>0){const s=ue(n[0].points);return{rings:n,bounds:s}}},hi=e=>{const t=Tn(e),n=[];let o=[0,0],i=!1;for(let r=0;r<t.length;r++){const l=t[r];switch(l.type.toUpperCase()){case"M":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"L":o=[l.args[0],l.args[1]],n.push({type:"CORNER",point:[...o]});break;case"C":const a=[l.args[0],l.args[1]],u=[l.args[2],l.args[3]],d=[l.args[4],l.args[5]];if(n.length>0){const h=n[n.length-1];(a[0]!==h.point[0]||a[1]!==h.point[1])&&(h.type="CURVE",h.outHandle=a)}const f={type:u[0]!==d[0]||u[1]!==d[1]?"CURVE":"CORNER",point:d};f.type==="CURVE"&&(f.inHandle=u),n.push(f),o=d;break;case"Z":i=!0;break;default:console.warn(`Unsupported SVG path command: ${l.type}`);break}}const s=ue(ht(n,i));return{points:n,closed:i,bounds:s}},Tn=e=>{const t=[],n=e.replace(/,/g," ").trim(),o=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let i;for(;(i=o.exec(n))!==null;){const[,s,r]=i,l=r.trim()===""?[]:r.trim().split(/\s+/).map(Number).filter(a=>!isNaN(a));t.push({type:s,args:l})}return t},gi=e=>{const[t,n,o]=e.match(/(<polygon points=["|'])([^("|')]*)/)||[],i=o.split(" ").map(s=>s.split(",").map(parseFloat));return{type:J.POLYGON,geometry:{points:i,bounds:ue(i)}}},mi=e=>{const t=gt(e),n=parseFloat(t.getAttribute("cx")),o=parseFloat(t.getAttribute("cy")),i=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),r={minX:n-i,minY:o-s,maxX:n+i,maxY:o+s};return{type:J.ELLIPSE,geometry:{cx:n,cy:o,rx:i,ry:s,bounds:r}}},pi=e=>{const t=gt(e),n=parseFloat(t.getAttribute("x1")),o=parseFloat(t.getAttribute("x2")),i=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),r={minX:Math.min(n,o),minY:Math.min(i,s),maxX:Math.max(n,o),maxY:Math.max(i,s)};return{type:J.LINE,geometry:{points:[[n,i],[o,s]],bounds:r}}},_i=e=>{const t=gt(e),n=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],o=n==null?void 0:n.getAttribute("d");if(!o)throw new Error("Could not parse SVG path");const i=hi(o);if(!i)throw new Error("Could not parse SVG path");return{type:J.POLYLINE,geometry:i}},yi=e=>{const t=gt(e),i=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(a=>a.getAttribute("d")||"").map(a=>di(a)).filter(Boolean),s=i.reduce((a,u)=>[...a,...u.rings[0].points],[]),r=ue(s);return i.length===1&&i[0].rings.length===1?{type:J.POLYGON,geometry:{points:s,bounds:r}}:{type:J.MULTIPOLYGON,geometry:{polygons:i,bounds:r}}},Pn=e=>{const t=typeof e=="string"?e:e.value;if(t.includes("<polygon points="))return gi(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return _i(t);if(t.includes("<path "))return yi(t);if(t.includes("<ellipse "))return mi(t);if(t.includes("<line "))return pi(t);throw"Unsupported SVG shape: "+t},wi=e=>`<g>${e.polygons.map(n=>`<path fill-rule="evenodd" d="${Pe(n)}" />`).join("")}</g>`,Ln=e=>{let t;switch(e.type){case J.POLYGON:{const n=e.geometry,{points:o}=n;t=`<svg><polygon points="${o.map(i=>i.join(",")).join(" ")}" /></svg>`;break}case J.ELLIPSE:{const n=e.geometry;t=`<svg><ellipse cx="${n.cx}" cy="${n.cy}" rx="${n.rx}" ry="${n.ry}" /></svg>`;break}case J.MULTIPOLYGON:{const n=e.geometry;t=`<svg>${wi(n)}</svg>`;break}case J.LINE:{const n=e.geometry,[[o,i],[s,r]]=n.points;t=`<svg><line x1="${o}" y1="${i}" x2="${s}" y2="${r}" /></svg>`;break}case J.POLYLINE:t=`<svg><path d="${It(e.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${e.type}`},ge=[];for(let e=0;e<256;++e)ge.push((e+256).toString(16).slice(1));function bi(e,t=0){return(ge[e[t+0]]+ge[e[t+1]]+ge[e[t+2]]+ge[e[t+3]]+"-"+ge[e[t+4]]+ge[e[t+5]]+"-"+ge[e[t+6]]+ge[e[t+7]]+"-"+ge[e[t+8]]+ge[e[t+9]]+"-"+ge[e[t+10]]+ge[e[t+11]]+ge[e[t+12]]+ge[e[t+13]]+ge[e[t+14]]+ge[e[t+15]]).toLowerCase()}let Ct;const Ei=new Uint8Array(16);function vi(){if(!Ct){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ct=crypto.getRandomValues.bind(crypto)}return Ct(Ei)}const In={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function Cn(e,t,n){var i;if(In.randomUUID&&!e)return In.randomUUID();e=e||{};const o=e.random??((i=e.rng)==null?void 0:i.call(e))??vi();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,bi(o)}var On=Object.prototype.hasOwnProperty;function Oe(e,t){var n,o;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((o=e.length)===t.length)for(;o--&&Oe(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if(On.call(e,n)&&++o&&!On.call(t,n)||!(n in t)||!Oe(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}function Ot(){}function Si(e,t){return e!=e?t==t:e!==t||e&&typeof e=="object"||typeof e=="function"}const ze=[];function Dt(e,t=Ot){let n;const o=new Set;function i(l){if(Si(e,l)&&(e=l,n)){const a=!ze.length;for(const u of o)u[1](),ze.push(u,e);if(a){for(let u=0;u<ze.length;u+=2)ze[u][0](ze[u+1]);ze.length=0}}}function s(l){i(l(e))}function r(l,a=Ot){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||Ot),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const Ai=e=>{const{subscribe:t,set:n}=Dt();let o;return t(i=>o=i),e.observe(({changes:i})=>{if(o){(i.deleted||[]).some(r=>r.id===o)&&n(void 0);const s=(i.updated||[]).find(({oldValue:r})=>r.id===o);s&&n(s.newValue.id)}}),{get current(){return o},subscribe:t,set:n}};var Nt=(e=>(e.EDIT="EDIT",e.SELECT="SELECT",e.NONE="NONE",e))(Nt||{});const mt={selected:[]},ki=(e,t,n)=>{const{subscribe:o,set:i}=Dt(mt);let s=t,r=mt;o(g=>r=g);const l=()=>{Oe(r,mt)||i(mt)},a=()=>{var g;return((g=r.selected)==null?void 0:g.length)===0},u=g=>{if(a())return!1;const k=typeof g=="string"?g:g.id;return r.selected.some(p=>p.id===k)},d=(g,k)=>{let p;if(Array.isArray(g)){if(p=g.map(E=>e.getAnnotation(E)).filter(Boolean),p.length<g.length){console.warn("Invalid selection: "+g.filter(E=>!p.some(A=>A.id===E)));return}}else{const E=e.getAnnotation(g);if(!E){console.warn("Invalid selection: "+g);return}p=[E]}const S=p.reduce((E,A)=>{const M=m(A);return M==="EDIT"?[...E,{id:A.id,editable:!0}]:M==="SELECT"?[...E,{id:A.id}]:E},[]);i({selected:S,event:k})},f=(g,k)=>{const p=Array.isArray(g)?g:[g],S=p.map(E=>e.getAnnotation(E)).filter(E=>!!E);i({selected:S.map(E=>{const A=k===void 0?m(E)==="EDIT":k;return{id:E.id,editable:A}})}),S.length!==p.length&&console.warn("Invalid selection",g)},h=g=>{if(a())return!1;const{selected:k}=r;k.some(({id:p})=>g.includes(p))&&i({selected:k.filter(({id:p})=>!g.includes(p))})},y=g=>{s=g,f(r.selected.map(({id:k})=>k))},m=g=>Mi(g,s,n);return e.observe(({changes:g})=>h((g.deleted||[]).map(k=>k.id))),{get event(){return r?r.event:null},get selected(){return r?[...r.selected]:null},get userSelectAction(){return s},clear:l,evalSelectAction:m,isEmpty:a,isSelected:u,setSelected:f,setUserSelectAction:y,subscribe:o,userSelect:d}},Mi=(e,t,n)=>{const o=n?n.serialize(e):e;return typeof t=="function"?t(o):t||"EDIT"},me=[];for(let e=0;e<256;++e)me.push((e+256).toString(16).slice(1));function Ti(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 Yt;const Pi=new Uint8Array(16);function Li(){if(!Yt){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Yt=crypto.getRandomValues.bind(crypto)}return Yt(Pi)}const Ii=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Dn={randomUUID:Ii};function Nn(e,t,n){var o;if(Dn.randomUUID&&!e)return Dn.randomUUID();e=e||{};const i=e.random??((o=e.rng)==null?void 0:o.call(e))??Li();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,Ti(i)}const Bt=e=>{const t=n=>{const o={...n};return n.created&&typeof n.created=="string"&&(o.created=new Date(n.created)),n.updated&&typeof n.updated=="string"&&(o.updated=new Date(n.updated)),o};return{...e,bodies:(e.bodies||[]).map(t),target:t(e.target)}},Ci=(e,t,n,o)=>({id:Nn(),annotation:typeof e=="string"?e:e.id,created:n||new Date,creator:o,...t}),Oi=(e,t)=>{const n=new Set(e.bodies.map(o=>o.id));return t.bodies.filter(o=>!n.has(o.id))},Di=(e,t)=>{const n=new Set(t.bodies.map(o=>o.id));return e.bodies.filter(o=>!n.has(o.id))},Ni=(e,t)=>t.bodies.map(n=>{const o=e.bodies.find(i=>i.id===n.id);return{newBody:n,oldBody:o&&!Oe(o,n)?o:void 0}}).filter(({oldBody:n})=>n).map(({oldBody:n,newBody:o})=>({oldBody:n,newBody:o})),Yi=(e,t)=>!Oe(e.target,t.target),Yn=(e,t)=>{const n=Oi(e,t),o=Di(e,t),i=Ni(e,t);return{oldValue:e,newValue:t,bodiesCreated:n.length>0?n:void 0,bodiesDeleted:o.length>0?o:void 0,bodiesUpdated:i.length>0?i:void 0,targetUpdated:Yi(e,t)?{oldTarget:e.target,newTarget:t.target}:void 0}};var ne=(e=>(e.LOCAL="LOCAL",e.REMOTE="REMOTE",e.SILENT="SILENT",e))(ne||{});const Bi=(e,t)=>{var n,o;const{changes:i,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(i.created)||l(i.deleted))){const a=(n=i.updated)==null?void 0:n.some(d=>l(d.bodiesCreated)||l(d.bodiesDeleted)||l(d.bodiesUpdated)),u=(o=i.updated)==null?void 0:o.some(d=>d.targetUpdated);if(r==="BODY_ONLY"&&a&&!u||r==="TARGET_ONLY"&&u&&!a)return!1}}if(e.options.annotations){const r=new Set([...(i.created||[]).map(l=>l.id),...(i.deleted||[]).map(l=>l.id),...(i.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},Ri=(e,t)=>{const n=new Set((e.created||[]).map(f=>f.id)),o=new Set((e.updated||[]).map(({newValue:f})=>f.id)),i=new Set((t.created||[]).map(f=>f.id)),s=new Set((t.deleted||[]).map(f=>f.id)),r=new Set((t.updated||[]).map(({oldValue:f})=>f.id)),l=new Set((t.updated||[]).filter(({oldValue:f})=>n.has(f.id)||o.has(f.id)).map(({oldValue:f})=>f.id)),a=[...(e.created||[]).filter(f=>!s.has(f.id)).map(f=>r.has(f.id)?t.updated.find(({oldValue:h})=>h.id===f.id).newValue:f),...t.created||[]],u=[...(e.deleted||[]).filter(f=>!i.has(f.id)),...(t.deleted||[]).filter(f=>!n.has(f.id))],d=[...(e.updated||[]).filter(({newValue:f})=>!s.has(f.id)).map(f=>{const{oldValue:h,newValue:y}=f;if(r.has(y.id)){const m=t.updated.find(g=>g.oldValue.id===y.id).newValue;return Yn(h,m)}else return f}),...(t.updated||[]).filter(({oldValue:f})=>!l.has(f.id))];return{created:a,deleted:u,updated:d}},pt=e=>{const t=e.id===void 0?Nn():e.id;return{...e,id:t,bodies:e.bodies===void 0?[]:e.bodies.map(n=>({...n,annotation:t})),target:{...e.target,annotation:t}}},Ui=e=>e.id!==void 0,Vi=()=>{const e=new Map,t=new Map,n=[],o=(w,v={})=>{n.push({onChange:w,options:v})},i=w=>{const v=n.findIndex(_=>_.onChange==w);v>-1&&n.splice(v,1)},s=(w,v)=>{const _={origin:w,changes:{created:v.created||[],updated:v.updated||[],deleted:v.deleted||[]},state:[...e.values()]};n.forEach(b=>{Bi(b,_)&&b.onChange(_)})},r=(w,v=ne.LOCAL)=>{if(w.id&&e.get(w.id))throw Error(`Cannot add annotation ${w.id} - exists already`);{const _=pt(w);e.set(_.id,_),_.bodies.forEach(b=>t.set(b.id,_.id)),s(v,{created:[_]})}},l=(w,v)=>{const _=pt(typeof w=="string"?v:w),b=typeof w=="string"?w:w.id,I=b&&e.get(b);if(I){const P=Yn(I,_);return b===_.id?e.set(b,_):(e.delete(b),e.set(_.id,_)),I.bodies.forEach(O=>t.delete(O.id)),_.bodies.forEach(O=>t.set(O.id,_.id)),P}else console.warn(`Cannot update annotation ${b} - does not exist`)},a=(w,v=ne.LOCAL,_=ne.LOCAL)=>{const b=Ui(v)?_:v,I=l(w,v);I&&s(b,{updated:[I]})},u=(w,v=ne.LOCAL)=>{e.get(w.id)?a(w,v):r(w,v)},d=(w,v=ne.LOCAL)=>{const _=w.reduce((b,I)=>{const P=l(I);return P?[...b,P]:b},[]);_.length>0&&s(v,{updated:_})},f=(w,v=ne.LOCAL)=>{const _=w.map(pt),{toAdd:b,toUpdate:I}=_.reduce((O,z)=>e.get(z.id)?{...O,toUpdate:[...O.toUpdate,z]}:{...O,toAdd:[...O.toAdd,z]},{toAdd:[],toUpdate:[]}),P=I.map(O=>l(O,v)).filter(Boolean);b.forEach(O=>{e.set(O.id,O),O.bodies.forEach(z=>t.set(z.id,O.id))}),s(v,{created:b,updated:P})},h=(w,v=ne.LOCAL)=>{const _=e.get(w.annotation);if(_){const b={..._,bodies:[..._.bodies,w]};e.set(_.id,b),t.set(w.id,b.id),s(v,{updated:[{oldValue:_,newValue:b,bodiesCreated:[w]}]})}else console.warn(`Attempt to add body to missing annotation: ${w.annotation}`)},y=()=>[...e.values()],m=(w=ne.LOCAL)=>{const v=[...e.values()];e.clear(),t.clear(),s(w,{deleted:v})},g=(w,v=!0,_=ne.LOCAL)=>{const b=w.map(pt);if(v){const I=[...e.values()];e.clear(),t.clear(),b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(O=>t.set(O.id,P.id))}),s(_,{created:b,deleted:I})}else{const I=w.reduce((P,O)=>{const z=O.id&&e.get(O.id);return z?[...P,z]:P},[]);if(I.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${I.map(P=>P.id).join(", ")}`);b.forEach(P=>{e.set(P.id,P),P.bodies.forEach(O=>t.set(O.id,P.id))}),s(_,{created:b})}},k=w=>{const v=typeof w=="string"?w:w.id,_=e.get(v);if(_)return e.delete(v),_.bodies.forEach(b=>t.delete(b.id)),_;console.warn(`Attempt to delete missing annotation: ${v}`)},p=(w,v=ne.LOCAL)=>{const _=k(w);_&&s(v,{deleted:[_]})},S=(w,v=ne.LOCAL)=>{const _=w.reduce((b,I)=>{const P=k(I);return P?[...b,P]:b},[]);_.length>0&&s(v,{deleted:_})},E=w=>{const v=e.get(w.annotation);if(v){const _=v.bodies.find(b=>b.id===w.id);if(_){t.delete(_.id);const b={...v,bodies:v.bodies.filter(I=>I.id!==w.id)};return e.set(v.id,b),{oldValue:v,newValue:b,bodiesDeleted:[_]}}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}`)},A=(w,v=ne.LOCAL)=>{const _=E(w);_&&s(v,{updated:[_]})},M=(w,v=ne.LOCAL)=>{const _=w.map(b=>E(b)).filter(Boolean);_.length>0&&s(v,{updated:_})},C=w=>{const v=e.get(w);return v?{...v}:void 0},T=w=>{const v=t.get(w);if(v){const _=C(v).bodies.find(b=>b.id===w);if(_)return _;console.error(`Store integrity error: body ${w} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${w}`)},V=(w,v)=>{if(w.annotation!==v.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const _=e.get(w.annotation);if(_){const b=_.bodies.find(P=>P.id===w.id),I={..._,bodies:_.bodies.map(P=>P.id===b.id?v:P)};return e.set(_.id,I),b.id!==v.id&&(t.delete(b.id),t.set(v.id,I.id)),{oldValue:_,newValue:I,bodiesUpdated:[{oldBody:b,newBody:v}]}}else console.warn(`Attempt to add body to missing annotation ${w.annotation}`)},B=(w,v,_=ne.LOCAL)=>{const b=V(w,v);b&&s(_,{updated:[b]})},W=(w,v=ne.LOCAL)=>{const _=w.map(b=>V({id:b.id,annotation:b.annotation},b)).filter(Boolean);s(v,{updated:_})},q=w=>{const v=e.get(w.annotation);if(v){const _={...v,target:{...v.target,...w}};return e.set(v.id,_),{oldValue:v,newValue:_,targetUpdated:{oldTarget:v.target,newTarget:w}}}else console.warn(`Attempt to update target on missing annotation: ${w.annotation}`)};return{addAnnotation:r,addBody:h,all:y,bulkAddAnnotations:g,bulkDeleteAnnotations:S,bulkDeleteBodies:M,bulkUpdateAnnotations:d,bulkUpdateBodies:W,bulkUpdateTargets:(w,v=ne.LOCAL)=>{const _=w.map(b=>q(b)).filter(Boolean);_.length>0&&s(v,{updated:_})},bulkUpsertAnnotations:f,clear:m,deleteAnnotation:p,deleteBody:A,getAnnotation:C,getBody:T,observe:o,unobserve:i,updateAnnotation:a,updateBody:B,updateTarget:(w,v=ne.LOCAL)=>{const _=q(w);_&&s(v,{updated:[_]})},upsertAnnotation:u}},Xi=e=>({...e,subscribe:t=>{const n=o=>t(o.state);return e.observe(n),t(e.all()),()=>e.unobserve(n)}});let Hi=()=>({emit(e,...t){for(let n=this.events[e]||[],o=0,i=n.length;o<i;o++)n[o](...t)},events:{},on(e,t){var n;return((n=this.events)[e]||(n[e]=[])).push(t),()=>{var o;this.events[e]=(o=this.events[e])==null?void 0:o.filter(i=>t!==i)}}});const Gi=250,ji=(e,t)=>{const n=Hi(),o=(t==null?void 0:t.changes)||[];let i=t?t.pointer:-1,s=!1,r=0;const l=m=>{if(!s){const{changes:g}=m,k=performance.now();if(k-r>Gi)o.splice(i+1),o.push(g),i=o.length-1;else{const p=o.length-1;o[p]=Ri(o[p],g)}r=k}s=!1};e.observe(l,{origin:ne.LOCAL});const a=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m),u=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),d=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({oldValue:g})=>g)),f=m=>m&&m.length>0&&e.bulkUpdateAnnotations(m.map(({newValue:g})=>g)),h=m=>m&&m.length>0&&e.bulkAddAnnotations(m,!1),y=m=>m&&m.length>0&&e.bulkDeleteAnnotations(m);return{canRedo:()=>o.length-1>i,canUndo:()=>i>-1,destroy:()=>e.unobserve(l),getHistory:()=>({changes:[...o],pointer:i}),on:(m,g)=>n.on(m,g),redo:()=>{if(o.length-1>i){s=!0;const{created:m,updated:g,deleted:k}=o[i+1];u(m),f(g),y(k),n.emit("redo",o[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:m,updated:g,deleted:k}=o[i];a(m),d(g),h(k),n.emit("undo",o[i]),i-=1}}}},zi=()=>{const{subscribe:e,set:t}=Dt([]);return{subscribe:e,set:t}},Fi=(e,t,n,o)=>{const{hover:i,selection:s,store:r,viewport:l}=e,a=new Map;let u=[],d,f;const h=(p,S)=>{a.has(p)?a.get(p).push(S):a.set(p,[S])},y=(p,S)=>{const E=a.get(p);if(E){const A=E.indexOf(S);A!==-1&&E.splice(A,1)}},m=(p,S,E)=>{a.has(p)&&setTimeout(()=>{a.get(p).forEach(A=>{if(n){const M=Array.isArray(S)?S.map(T=>n.serialize(T)):n.serialize(S),C=E?E instanceof PointerEvent?E:n.serialize(E):void 0;A(M,C)}else A(S,E)})},1)},g=()=>{const{selected:p}=s,S=(p||[]).map(({id:E})=>r.getAnnotation(E));S.forEach(E=>{const A=u.find(M=>M.id===E.id);(!A||!Oe(A,E))&&m("updateAnnotation",E,A)}),u=u.map(E=>S.find(({id:M})=>M===E.id)||E)};s.subscribe(({selected:p})=>{if(!(u.length===0&&p.length===0)){if(u.length===0&&p.length>0)u=p.map(({id:S})=>r.getAnnotation(S));else if(u.length>0&&p.length===0)u.forEach(S=>{const E=r.getAnnotation(S.id);E&&!Oe(E,S)&&m("updateAnnotation",E,S)}),u=[];else{const S=new Set(u.map(A=>A.id)),E=new Set(p.map(({id:A})=>A));u.filter(A=>!E.has(A.id)).forEach(A=>{const M=r.getAnnotation(A.id);M&&!Oe(M,A)&&m("updateAnnotation",M,A)}),u=[...u.filter(A=>E.has(A.id)),...p.filter(({id:A})=>!S.has(A)).map(({id:A})=>r.getAnnotation(A))]}m("selectionChanged",u)}}),i.subscribe(p=>{!d&&p?m("mouseEnterAnnotation",r.getAnnotation(p)):d&&!p?m("mouseLeaveAnnotation",r.getAnnotation(d)):d&&p&&(m("mouseLeaveAnnotation",r.getAnnotation(d)),m("mouseEnterAnnotation",r.getAnnotation(p))),d=p}),l==null||l.subscribe(p=>m("viewportIntersect",p.map(S=>r.getAnnotation(S)))),r.observe(p=>{o&&(f&&clearTimeout(f),f=setTimeout(g,1e3));const{created:S,deleted:E}=p.changes;(S||[]).forEach(A=>m("createAnnotation",A)),(E||[]).forEach(A=>m("deleteAnnotation",A)),(p.changes.updated||[]).filter(A=>[...A.bodiesCreated||[],...A.bodiesDeleted||[],...A.bodiesUpdated||[]].length>0).forEach(({oldValue:A,newValue:M})=>{const C=u.find(T=>T.id===A.id)||A;u=u.map(T=>T.id===A.id?M:T),m("updateAnnotation",M,C)})},{origin:ne.LOCAL}),r.observe(p=>{if(u){const S=new Set(u.map(A=>A.id)),E=(p.changes.updated||[]).filter(({newValue:A})=>S.has(A.id)).map(({newValue:A})=>A);E.length>0&&(u=u.map(A=>E.find(C=>C.id===A.id)||A))}},{origin:ne.REMOTE});const k=p=>S=>{const{updated:E}=S;p?(E||[]).forEach(A=>m("updateAnnotation",A.oldValue,A.newValue)):(E||[]).forEach(A=>m("updateAnnotation",A.newValue,A.oldValue))};return t.on("undo",k(!0)),t.on("redo",k(!1)),{on:h,off:y,emit:m}},qi=e=>t=>t.reduce((n,o)=>{const{parsed:i,error:s}=e.parse(o);return s?{parsed:n.parsed,failed:[...n.failed,o]}:i?{parsed:[...n.parsed,i],failed:n.failed}:{...n}},{parsed:[],failed:[]}),Ki=(e,t,n)=>{const{store:o,selection:i}=e,s=p=>{if(n){const{parsed:S,error:E}=n.parse(p);S?o.addAnnotation(S,ne.REMOTE):console.error(E)}else o.addAnnotation(Bt(p),ne.REMOTE)},r=()=>i.clear(),l=()=>o.clear(),a=p=>{const S=o.getAnnotation(p);return n&&S?n.serialize(S):S},u=()=>n?o.all().map(n.serialize):o.all(),d=()=>{var p;const S=(((p=i.selected)==null?void 0:p.map(E=>E.id))||[]).map(E=>o.getAnnotation(E)).filter(Boolean);return n?S.map(n.serialize):S},f=(p,S=!0)=>fetch(p).then(E=>E.json()).then(E=>(y(E,S),E)),h=p=>{if(typeof p=="string"){const S=o.getAnnotation(p);if(o.deleteAnnotation(p),S)return n?n.serialize(S):S}else{const S=n?n.parse(p).parsed:p;if(S)return o.deleteAnnotation(S),p}},y=(p,S=!0)=>{if(n){const E=n.parseAll||qi(n),{parsed:A,failed:M}=E(p);M.length>0&&console.warn(`Discarded ${M.length} invalid annotations`,M),o.bulkAddAnnotations(A,S,ne.REMOTE)}else o.bulkAddAnnotations(p.map(Bt),S,ne.REMOTE)},m=(p,S)=>{p?i.setSelected(p,S):i.clear()},g=p=>{i.clear(),i.setUserSelectAction(p)},k=p=>{if(n){const S=n.parse(p).parsed,E=n.serialize(o.getAnnotation(S.id));return o.updateAnnotation(S),E}else{const S=o.getAnnotation(p.id);return o.updateAnnotation(Bt(p)),S}};return{addAnnotation:s,cancelSelected:r,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:l,getAnnotationById:a,getAnnotations:u,getHistory:t.getHistory,getSelected:d,loadAnnotations:f,redo:t.redo,removeAnnotation:h,setAnnotations:y,setSelected:m,setUserSelectAction:g,undo:t.undo,updateAnnotation:k}},Wi=(e,t,n)=>typeof t=="function"?t(e,n):t,Zi=(e,t)=>typeof e!="function"&&typeof t!="function"?{...e||{},...t||{}}:(n,o)=>{const i=typeof e=="function"?e(n,o):e,s=typeof t=="function"?t(n,o):t;return{...i||{},...s||{}}},Ji="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Qi=e=>crypto.getRandomValues(new Uint8Array(e)),xi=(e,t,n)=>{let o=(2<<Math.log2(e.length-1))-1,i=-~(1.6*o*t/e.length);return(s=t)=>{let r="";for(;;){let l=n(i),a=i|0;for(;a--;)if(r+=e[l[a]&o]||"",r.length>=s)return r}}},$i=(e,t=21)=>xi(e,t|0,Qi),es=(e=21)=>{let t="",n=crypto.getRandomValues(new Uint8Array(e|=0));for(;e--;)t+=Ji[n[e]&63];return t};const ts=()=>({isGuest:!0,id:$i("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ns=e=>{const t=JSON.stringify(e);let n=0;for(let o=0,i=t.length;o<i;o++){let s=t.charCodeAt(o);n=(n<<5)-n+s,n|=0}return`${n}`},Bn=e=>e?typeof e=="object"?{...e}:e:void 0,os=(e,t)=>(Array.isArray(e)?e:[e]).map(n=>{const{id:o,type:i,purpose:s,value:r,created:l,modified:a,creator:u,...d}=n;return{id:o||`temp-${ns(n)}`,annotation:t,type:i,purpose:s,value:r,creator:Bn(u),created:l?new Date(l):void 0,updated:a?new Date(a):void 0,...d}}),is=e=>e.map(t=>{var n;const{annotation:o,created:i,updated:s,...r}=t,l={...r,created:i==null?void 0:i.toISOString(),modified:s==null?void 0:s.toISOString()};return(n=l.id)!=null&&n.startsWith("temp-")&&delete l.id,l}),ss=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],rs=()=>{const e=[...ss];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*e.length),n=e[t];return e.splice(t,1),n},releaseColor:t=>e.push(t)}};es();const ls=(e,t={strict:!0,invertY:!1})=>({parse:i=>Rn(i,t),serialize:i=>Un(i,e,t)}),Rn=(e,t={strict:!0,invertY:!1})=>{const n=e.id||Cn(),{creator:o,created:i,modified:s,body:r,...l}=e,a=os(r||[],n),u=Array.isArray(e.target)?e.target[0]:e.target,d=typeof u=="string"?u:Array.isArray(u.selector)?u.selector[0]:u.selector,f=typeof d=="string"||(d==null?void 0:d.type)==="FragmentSelector"?Sn(d,t.invertY):(d==null?void 0:d.type)==="SvgSelector"?Pn(d):void 0,h=Array.isArray(l.target)?l.target[0]:l.targret;return f||!t.strict?{parsed:{...l,id:n,bodies:a,target:{created:i?new Date(i):void 0,creator:Bn(o),updated:s?new Date(s):void 0,...typeof h=="string"?{}:h,annotation:n,selector:f||d}}}:{error:Error(`Invalid selector: ${JSON.stringify(d)}`)}},Un=(e,t,n={strict:!0,invertY:!1})=>{const{selector:o,creator:i,created:s,updated:r,updatedBy:l,...a}=e.target;let u;try{u=o.type==J.RECTANGLE?An(o.geometry):Ln(o)}catch(f){if(n.strict)throw f;u=o}const d={...e,"@context":"http://www.w3.org/ns/anno.jsonld",id:e.id,type:"Annotation",body:is(e.bodies),created:s==null?void 0:s.toISOString(),creator:i,modified:r==null?void 0:r.toISOString(),target:{...a,source:t,type:"SpecificResource",selector:u}};return delete d.bodies,"annotation"in d.target&&delete d.target.annotation,d},Fe=[];function as(e,t=j){let n;const o=new Set;function i(l){if(re(e,l)&&(e=l,n)){const a=!Fe.length;for(const u of o)u[1](),Fe.push(u,e);if(a){for(let u=0;u<Fe.length;u+=2)Fe[u][0](Fe[u+1]);Fe.length=0}}}function s(l){i(l(e))}function r(l,a=j){const u=[l,a];return o.add(u),o.size===1&&(n=t(i,s)||j),l(e),()=>{o.delete(u),o.size===0&&n&&(n(),n=null)}}return{set:i,update:s,subscribe:r}}const cs=(e,t)=>{const{naturalWidth:n,naturalHeight:o}=e;if(!n&&!o){const{width:i,height:s}=e;t.setAttribute("viewBox",`0 0 ${i} ${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} ${o}`)},Vn=(e,t)=>{cs(e,t);const{subscribe:n,set:o}=as(1);let i;return window.ResizeObserver&&(i=new ResizeObserver(()=>{const r=t.getBoundingClientRect(),{width:l,height:a}=t.viewBox.baseVal,u=Math.max(r.width/l,r.height/a);o(u)}),i.observe(t.parentElement)),{destroy:()=>{i&&i.disconnect()},subscribe:n}},Ve=(e,t)=>{const n=typeof t=="function"?t(e):t;if(n){const{fill:o,fillOpacity:i,stroke:s,strokeWidth:r,strokeOpacity:l}=n;let a="";return o&&(a+=`fill:${o};`,a+=`fill-opacity:${i||"0.25"};`),s&&(a+=`stroke:${s};`,a+=`stroke-width:${r||"1"};`,a+=`stroke-opacity:${l||"1"};`),a}},ot=(e,t=0)=>{const{minX:n,minY:o,maxX:i,maxY:s}=e;return{x:n-t,y:o-t,w:i-n+2*t,h:s-o+2*t}},Le=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,us=e=>({}),Xn=e=>({grab:e[0]});function fs(e){let t,n,o,i;const s=e[8].default,r=zo(s,e,e[7],Xn);return{c(){t=L("g"),r&&r.c(),c(t,"class","a9s-annotation selected")},m(l,a){Y(l,t,a),r&&r.m(t,null),n=!0,o||(i=[ee(t,"pointerup",e[2]),ee(t,"pointermove",e[1])],o=!0)},p(l,[a]){r&&r.p&&(!n||a&128)&&qo(r,s,l,l[7],n?Fo(s,l[7],a,us):Ko(l[7]),Xn)},i(l){n||(U(r,l),n=!0)},o(l){G(r,l),n=!1},d(l){l&&N(t),r&&r.d(l),o=!1,Ae(i)}}}function ds(e,t,n){let{$$slots:o={},$$scope:i}=t;const s=Ce();let{shape:r}=t,{editor:l}=t,{transform:a}=t,{svgEl:u}=t,d,f,h;const y=k=>p=>{if(d=k,u){const{left:E,top:A}=u.getBoundingClientRect(),M=p.clientX-E,C=p.clientY-A;f=a.elementToImage(M,C)}else{const{offsetX:E,offsetY:A}=p;f=a.elementToImage(E,A)}h=r,p.target.setPointerCapture(p.pointerId),s("grab",p)},m=k=>{if(d){const[p,S]=a.elementToImage(k.offsetX,k.offsetY),E=[p-f[0],S-f[1]];n(3,r=l(h,d,E)),s("change",r)}},g=k=>{k.target.releasePointerCapture(k.pointerId),d=void 0,h=r,s("release",k)};return e.$$set=k=>{"shape"in k&&n(3,r=k.shape),"editor"in k&&n(4,l=k.editor),"transform"in k&&n(5,a=k.transform),"svgEl"in k&&n(6,u=k.svgEl),"$$scope"in k&&n(7,i=k.$$scope)},[y,m,g,r,l,a,u,i,o]}class _t extends he{constructor(t){super(),de(this,t,ds,fs,re,{shape:3,editor:4,transform:5,svgEl:6})}}function hs(e){let t,n,o,i,s,r,l,a,u=e[3]&&Hn(e);return{c(){t=L("g"),n=L("circle"),u&&u.c(),i=L("circle"),c(n,"class","a9s-handle-buffer"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]+6/e[2]),c(i,"class",s=`a9s-handle-dot${e[3]?" selected":""}`),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[5]),c(t,"class",r=`a9s-handle ${e[8].class||""}`.trim())},m(d,f){Y(d,t,f),F(t,n),u&&u.m(t,null),F(t,i),l||(a=[ee(n,"pointerenter",e[11]),ee(n,"pointerleave",e[12]),ee(n,"pointerdown",e[13]),ee(n,"pointerdown",e[6]),ee(n,"pointerup",e[14]),ee(n,"pointerup",e[7])],l=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&36&&o!==(o=d[5]+6/d[2])&&c(n,"r",o),d[3]?u?u.p(d,f):(u=Hn(d),u.c(),u.m(t,i)):u&&(u.d(1),u=null),f&8&&s!==(s=`a9s-handle-dot${d[3]?" selected":""}`)&&c(i,"class",s),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&32&&c(i,"r",d[5]),f&256&&r!==(r=`a9s-handle ${d[8].class||""}`.trim())&&c(t,"class",r)},d(d){d&&N(t),u&&u.d(),l=!1,Ae(a)}}}function gs(e){let t,n,o,i,s,r,l,a,u;return{c(){t=L("g"),n=L("circle"),i=L("circle"),r=L("circle"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=e[5]*10),c(n,"class","a9s-touch-halo"),Te(n,"touched",e[4]),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",s=e[5]+10/e[2]),c(i,"class","a9s-handle-buffer"),c(r,"class","a9s-handle-dot"),c(r,"cx",e[0]),c(r,"cy",e[1]),c(r,"r",l=e[5]+2/e[2]),c(t,"class","a9s-touch-handle")},m(d,f){Y(d,t,f),F(t,n),F(t,i),F(t,r),a||(u=[ee(i,"pointerdown",e[9]),ee(i,"pointerup",e[10]),ee(i,"pointerdown",e[6]),ee(i,"pointerup",e[7])],a=!0)},p(d,f){f&1&&c(n,"cx",d[0]),f&2&&c(n,"cy",d[1]),f&32&&o!==(o=d[5]*10)&&c(n,"r",o),f&16&&Te(n,"touched",d[4]),f&1&&c(i,"cx",d[0]),f&2&&c(i,"cy",d[1]),f&36&&s!==(s=d[5]+10/d[2])&&c(i,"r",s),f&1&&c(r,"cx",d[0]),f&2&&c(r,"cy",d[1]),f&36&&l!==(l=d[5]+2/d[2])&&c(r,"r",l)},d(d){d&&N(t),a=!1,Ae(u)}}}function Hn(e){let t,n;return{c(){t=L("circle"),c(t,"class","a9s-handle-selected"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",n=e[5]+8/e[2])},m(o,i){Y(o,t,i)},p(o,i){i&1&&c(t,"cx",o[0]),i&2&&c(t,"cy",o[1]),i&36&&n!==(n=o[5]+8/o[2])&&c(t,"r",n)},d(o){o&&N(t)}}}function ms(e){let t;function n(s,r){return Le?gs:hs}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),Y(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&N(t),i.d(s)}}}function ps(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t,{selected:l=void 0}=t,a=!1;const u=p=>{p.pointerType==="touch"&&n(4,a=!0)},d=()=>n(4,a=!1);function f(p){_e.call(this,e,p)}function h(p){_e.call(this,e,p)}function y(p){_e.call(this,e,p)}function m(p){_e.call(this,e,p)}function g(p){_e.call(this,e,p)}function k(p){_e.call(this,e,p)}return e.$$set=p=>{n(8,t=Ie(Ie({},t),an(p))),"x"in p&&n(0,i=p.x),"y"in p&&n(1,s=p.y),"scale"in p&&n(2,r=p.scale),"selected"in p&&n(3,l=p.selected)},e.$$.update=()=>{e.$$.dirty&4&&n(5,o=4/r)},t=an(t),[i,s,r,l,a,o,u,d,t,f,h,y,m,g,k]}class Xe extends he{constructor(t){super(),de(this,t,ps,ms,re,{x:0,y:1,scale:2,selected:3})}}function _s(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("circle"),i=L("circle"),s=L("circle"),c(n,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),c(n,"cx",e[0]),c(n,"cy",e[1]),c(n,"r",o=1.75*e[2]),c(i,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),c(i,"cx",e[0]),c(i,"cy",e[1]),c(i,"r",e[2]),c(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),c(s,"cx",e[0]),c(s,"cy",e[1]),c(s,"r",e[2]),c(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(a,u){Y(a,t,u),F(t,n),F(t,i),F(t,s),r||(l=[ee(n,"pointerdown",e[5]),ee(n,"pointerdown",e[3])],r=!0)},p(a,u){u&1&&c(n,"cx",a[0]),u&2&&c(n,"cy",a[1]),u&4&&o!==(o=1.75*a[2])&&c(n,"r",o),u&1&&c(i,"cx",a[0]),u&2&&c(i,"cy",a[1]),u&4&&c(i,"r",a[2]),u&1&&c(s,"cx",a[0]),u&2&&c(s,"cy",a[1]),u&4&&c(s,"r",a[2])},d(a){a&&N(t),r=!1,Ae(l)}}}function ys(e){let t;return{c(){t=L("circle"),c(t,"cx",e[0]),c(t,"cy",e[1]),c(t,"r",e[2])},m(n,o){Y(n,t,o)},p(n,o){o&1&&c(t,"cx",n[0]),o&2&&c(t,"cy",n[1]),o&4&&c(t,"r",n[2])},d(n){n&&N(t)}}}function ws(e){let t;function n(s,r){return Le?ys:_s}let i=n()(e);return{c(){i.c(),t=ke()},m(s,r){i.m(s,r),Y(s,t,r)},p(s,[r]){i.p(s,r)},i:j,o:j,d(s){s&&N(t),i.d(s)}}}function bs(e,t,n){let o,{x:i}=t,{y:s}=t,{scale:r}=t;const l=u=>{u.pointerType};function a(u){_e.call(this,e,u)}return e.$$set=u=>{"x"in u&&n(0,i=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,o=4/r)},[i,s,o,l,r,a]}class Gn extends he{constructor(t){super(),de(this,t,bs,ws,re,{x:0,y:1,scale:4})}}function Rt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function jn(e,t,n){const o=e.slice();return o[28]=t[n],o[30]=n,o}function Ut(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function Vt(e){const t=e.slice(),n=t[10][t[6]];return t[28]=n.point,t}function zn(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[28][0]),c(t,"cy",o=e[28][1]),c(t,"r",i=it/e[3]),c(t,"class","svelte-1h2slbm")},m(s,r){Y(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[28][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[28][1])&&c(t,"cy",o),r[0]&8&&i!==(i=it/s[3])&&c(t,"r",i)},d(s){s&&N(t)}}}function Fn(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1h2slbm"),c(l,"cx",a=e[28][0]),c(l,"cy",u=e[28][1]),c(l,"r",d=it/e[3]),c(l,"class","svelte-1h2slbm"),c(t,"id",`${e[19]}-inner`),c(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(f,h){Y(f,t,h),F(t,n),F(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[28][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[28][1])&&c(l,"cy",u),h[0]&8&&d!==(d=it/f[3])&&c(l,"r",d)},d(f){f&&N(t)}}}function qn(e){let t,n;return t=new Xe({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(){ie(e[27](`HANDLE-${e[30]}`))&&e[27](`HANDLE-${e[30]}`).apply(this,arguments)}),t.$on("pointerup",e[16](e[30])),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&32&&(s.x=e[28][0]),i[0]&32&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),i[0]&256&&(s.selected=e[8].includes(e[30])),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Kn(e){let t,n;return t=new Gn({props:{x:e[28][0],y:e[28][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[18](e[6]))&&e[18](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[28][0]),i[0]&1088&&(s.y=e[28][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Es(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g,k,p,S,E,A,M,C=e[6]!==void 0&&!e[7]&&zn(Vt(e)),T=e[6]!==void 0&&!e[7]&&Fn(Ut(e)),V=ve(e[5].points),B=[];for(let w=0;w<V.length;w+=1)B[w]=qn(jn(e,V,w));const W=w=>G(B[w],1,1,()=>{B[w]=null});let q=e[6]!==void 0&&!e[7]&&Kn(Rt(e));return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),C&&C.c(),T&&T.c(),d=we(),f=L("polygon"),y=we(),m=L("polygon"),k=we();for(let w=0;w<B.length;w+=1)B[w].c();p=we(),q&&q.c(),S=ke(),c(o,"x",i=e[9].x),c(o,"y",s=e[9].y),c(o,"width",r=e[9].w),c(o,"height",l=e[9].h),c(o,"class","svelte-1h2slbm"),c(a,"points",u=e[5].points.map(Wn).join(" ")),c(a,"class","svelte-1h2slbm"),c(n,"id",`${e[19]}-outer`),c(n,"class","a9s-polygon-editor-mask svelte-1h2slbm"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[19]}-outer)`),c(f,"points",h=e[5].points.map(Zn).join(" ")),c(m,"class","a9s-inner a9s-shape-handle"),c(m,"mask",`url(#${e[19]}-inner)`),c(m,"style",e[1]),c(m,"points",g=e[5].points.map(Jn).join(" "))},m(w,v){Y(w,t,v),F(t,n),F(n,o),F(n,a),C&&C.m(n,null),T&&T.m(t,null),Y(w,d,v),Y(w,f,v),Y(w,y,v),Y(w,m,v),Y(w,k,v);for(let _=0;_<B.length;_+=1)B[_]&&B[_].m(w,v);Y(w,p,v),q&&q.m(w,v),Y(w,S,v),E=!0,A||(M=[ee(f,"pointerup",e[14]),ee(f,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)}),ee(m,"pointermove",e[13]),ee(m,"pointerup",e[14]),ee(m,"pointerdown",function(){ie(e[27]("SHAPE"))&&e[27]("SHAPE").apply(this,arguments)})],A=!0)},p(w,v){if(e=w,(!E||v[0]&512&&i!==(i=e[9].x))&&c(o,"x",i),(!E||v[0]&512&&s!==(s=e[9].y))&&c(o,"y",s),(!E||v[0]&512&&r!==(r=e[9].w))&&c(o,"width",r),(!E||v[0]&512&&l!==(l=e[9].h))&&c(o,"height",l),(!E||v[0]&32&&u!==(u=e[5].points.map(Wn).join(" ")))&&c(a,"points",u),e[6]!==void 0&&!e[7]?C?C.p(Vt(e),v):(C=zn(Vt(e)),C.c(),C.m(n,null)):C&&(C.d(1),C=null),e[6]!==void 0&&!e[7]?T?T.p(Ut(e),v):(T=Fn(Ut(e)),T.c(),T.m(t,null)):T&&(T.d(1),T=null),(!E||v[0]&32&&h!==(h=e[5].points.map(Zn).join(" ")))&&c(f,"points",h),(!E||v[0]&2)&&c(m,"style",e[1]),(!E||v[0]&32&&g!==(g=e[5].points.map(Jn).join(" ")))&&c(m,"points",g),v[0]&134322472){V=ve(e[5].points);let _;for(_=0;_<V.length;_+=1){const b=jn(e,V,_);B[_]?(B[_].p(b,v),U(B[_],1)):(B[_]=qn(b),B[_].c(),U(B[_],1),B[_].m(p.parentNode,p))}for(be(),_=V.length;_<B.length;_+=1)W(_);Ee()}e[6]!==void 0&&!e[7]?q?(q.p(Rt(e),v),v[0]&192&&U(q,1)):(q=Kn(Rt(e)),q.c(),U(q,1),q.m(S.parentNode,S)):q&&(be(),G(q,1,1,()=>{q=null}),Ee())},i(w){if(!E){for(let v=0;v<V.length;v+=1)U(B[v]);U(q),E=!0}},o(w){B=B.filter(Boolean);for(let v=0;v<B.length;v+=1)G(B[v]);G(q),E=!1},d(w){w&&(N(t),N(d),N(f),N(y),N(m),N(k),N(p),N(S)),C&&C.d(),T&&T.d(),Ye(B,w),q&&q.d(w),A=!1,Ae(M)}}}function vs(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[17],svgEl:e[4],$$slots:{default:[Es,({grab:o})=>({27:o}),({grab:o})=>[o?134217728:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&134219754|i[1]&1&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ss=250,As=1e3,ks=12,it=4.5,Wn=e=>e.join(","),Zn=e=>e.join(","),Jn=e=>e.join(",");function Ms(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,y=!1,m,g=[];const k=()=>n(7,y=!0),p=()=>n(7,y=!1),S=_=>{if(g.length>0||!i.some(Z=>Z.visible)){n(6,h=void 0);return}const[b,I]=u.elementToImage(_.offsetX,_.offsetY),P=Z=>Math.pow(Z[0]-b,2)+Math.pow(Z[1]-I,2),O=o.points.reduce((Z,x)=>P(x)<P(Z)?x:Z),z=i.filter(Z=>Z.visible).reduce((Z,x)=>P(x.point)<P(Z.point)?x:Z),H=Math.pow(As/d,2);P(O)<H||P(z.point)<H?n(6,h=i.indexOf(z)):n(6,h=void 0)},E=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),E()},M=_=>{n(7,y=!0),_.preventDefault(),_.stopPropagation(),m=performance.now()},C=_=>b=>{if(!m||Le||performance.now()-m>Ss)return;const I=g.includes(_);b.metaKey||b.ctrlKey||b.shiftKey?I?n(8,g=g.filter(P=>P!==_)):n(8,g=[...g,_]):I&&g.length>1?n(8,g=[_]):I?n(8,g=[]):n(8,g=[_]),E()},T=(_,b,I)=>{E();let P;const O=_.geometry;g.length>1?P=O.points.map(([H,Q],Z)=>g.includes(Z)?[H+I[0],Q+I[1]]:[H,Q]):b==="SHAPE"?P=O.points.map(([H,Q])=>[H+I[0],Q+I[1]]):P=O.points.map(([H,Q],Z)=>b===`HANDLE-${Z}`?[H+I[0],Q+I[1]]:[H,Q]);const z=ue(P);return{..._,geometry:{points:P,bounds:z}}},V=_=>async b=>{b.stopPropagation();const I=[...o.points.slice(0,_+1),i[_].point,...o.points.slice(_+1)],P=ue(I);r("change",{...l,geometry:{points:I,bounds:P}}),await gn();const O=[...document.querySelectorAll(".a9s-handle")][_+1];if(O!=null&&O.firstChild){const z=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:b.clientX,clientY:b.clientY,pointerId:b.pointerId,pointerType:b.pointerType,isPrimary:b.isPrimary,buttons:b.buttons});O.firstChild.dispatchEvent(z)}},B=()=>{if(o.points.length-g.length<3)return;const _=o.points.filter((I,P)=>!g.includes(P)),b=ue(_);r("change",{...l,geometry:{points:_,bounds:b}}),n(8,g=[])};Be(()=>{if(Le)return;const _=b=>{(b.key==="Delete"||b.key==="Backspace")&&(b.preventDefault(),B())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",_),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",_)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function q(_){_e.call(this,e,_)}function w(_){_e.call(this,e,_)}function v(_){_e.call(this,e,_)}return e.$$set=_=>{"shape"in _&&n(0,l=_.shape),"computedStyle"in _&&n(1,a=_.computedStyle),"transform"in _&&n(2,u=_.transform),"viewportScale"in _&&n(3,d=_.viewportScale),"svgEl"in _&&n(4,f=_.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Le?[]:o.points.map((_,b)=>{const I=b===o.points.length-1?o.points[0]:o.points[b+1],P=(_[0]+I[0])/2,O=(_[1]+I[1])/2,H=Math.sqrt(Math.pow(I[0]-P,2)+Math.pow(I[1]-O,2))>ks/d;return{point:[P,O],visible:H}})),e.$$.dirty[0]&40&&n(9,s=ot(o.bounds,it/d))},[l,a,u,d,f,o,h,y,g,s,i,k,p,S,A,M,C,T,V,W,q,w,v]}class Qn extends he{constructor(t){super(),de(this,t,Ms,vs,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Ts(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g,k,p,S,E,A,M,C,T,V,B,W,q,w,v,_,b,I,P,O,z,H,Q,Z,x,oe,se,Se,Me,X,fe,te,pe,ye,We,De,en,Ne,$,tn,Go;return te=new Xe({props:{class:"a9s-corner-handle-topleft",x:e[5].x,y:e[5].y,scale:e[3]}}),te.$on("pointerdown",function(){ie(e[12]("TOP_LEFT"))&&e[12]("TOP_LEFT").apply(this,arguments)}),ye=new Xe({props:{class:"a9s-corner-handle-topright",x:e[5].x+e[5].w,y:e[5].y,scale:e[3]}}),ye.$on("pointerdown",function(){ie(e[12]("TOP_RIGHT"))&&e[12]("TOP_RIGHT").apply(this,arguments)}),De=new Xe({props:{class:"a9s-corner-handle-bottomright",x:e[5].x+e[5].w,y:e[5].y+e[5].h,scale:e[3]}}),De.$on("pointerdown",function(){ie(e[12]("BOTTOM_RIGHT"))&&e[12]("BOTTOM_RIGHT").apply(this,arguments)}),Ne=new Xe({props:{class:"a9s-corner-handle-bottomleft",x:e[5].x,y:e[5].y+e[5].h,scale:e[3]}}),Ne.$on("pointerdown",function(){ie(e[12]("BOTTOM_LEFT"))&&e[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),y=we(),m=L("rect"),E=we(),A=L("rect"),B=we(),W=L("rect"),_=we(),b=L("rect"),z=we(),H=L("rect"),oe=we(),se=L("rect"),fe=we(),ce(te.$$.fragment),pe=we(),ce(ye.$$.fragment),We=we(),ce(De.$$.fragment),en=we(),ce(Ne.$$.fragment),c(o,"class","rect-mask-bg svelte-1njczvj"),c(o,"x",i=e[6].x),c(o,"y",s=e[6].y),c(o,"width",r=e[6].w),c(o,"height",l=e[6].h),c(a,"class","rect-mask-fg svelte-1njczvj"),c(a,"x",u=e[5].x),c(a,"y",d=e[5].y),c(a,"width",f=e[5].w),c(a,"height",h=e[5].h),c(n,"id",e[8]),c(n,"class","a9s-rectangle-editor-mask svelte-1njczvj"),c(m,"class","a9s-outer"),c(m,"mask",`url(#${e[8]})`),c(m,"x",g=e[5].x),c(m,"y",k=e[5].y),c(m,"width",p=e[5].w),c(m,"height",S=e[5].h),c(A,"class","a9s-inner a9s-shape-handle"),c(A,"style",e[1]),c(A,"x",M=e[5].x),c(A,"y",C=e[5].y),c(A,"width",T=e[5].w),c(A,"height",V=e[5].h),c(W,"class","a9s-edge-handle a9s-edge-handle-top"),c(W,"x",q=e[5].x),c(W,"y",w=e[5].y),c(W,"height",1),c(W,"width",v=e[5].w),c(b,"class","a9s-edge-handle a9s-edge-handle-right"),c(b,"x",I=e[5].x+e[5].w),c(b,"y",P=e[5].y),c(b,"height",O=e[5].h),c(b,"width",1),c(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),c(H,"x",Q=e[5].x),c(H,"y",Z=e[5].y+e[5].h),c(H,"height",1),c(H,"width",x=e[5].w),c(se,"class","a9s-edge-handle a9s-edge-handle-left"),c(se,"x",Se=e[5].x),c(se,"y",Me=e[5].y),c(se,"height",X=e[5].h),c(se,"width",1)},m(K,R){Y(K,t,R),F(t,n),F(n,o),F(n,a),Y(K,y,R),Y(K,m,R),Y(K,E,R),Y(K,A,R),Y(K,B,R),Y(K,W,R),Y(K,_,R),Y(K,b,R),Y(K,z,R),Y(K,H,R),Y(K,oe,R),Y(K,se,R),Y(K,fe,R),le(te,K,R),Y(K,pe,R),le(ye,K,R),Y(K,We,R),le(De,K,R),Y(K,en,R),le(Ne,K,R),$=!0,tn||(Go=[ee(m,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(A,"pointerdown",function(){ie(e[12]("SHAPE"))&&e[12]("SHAPE").apply(this,arguments)}),ee(W,"pointerdown",function(){ie(e[12]("TOP"))&&e[12]("TOP").apply(this,arguments)}),ee(b,"pointerdown",function(){ie(e[12]("RIGHT"))&&e[12]("RIGHT").apply(this,arguments)}),ee(H,"pointerdown",function(){ie(e[12]("BOTTOM"))&&e[12]("BOTTOM").apply(this,arguments)}),ee(se,"pointerdown",function(){ie(e[12]("LEFT"))&&e[12]("LEFT").apply(this,arguments)})],tn=!0)},p(K,R){e=K,(!$||R&64&&i!==(i=e[6].x))&&c(o,"x",i),(!$||R&64&&s!==(s=e[6].y))&&c(o,"y",s),(!$||R&64&&r!==(r=e[6].w))&&c(o,"width",r),(!$||R&64&&l!==(l=e[6].h))&&c(o,"height",l),(!$||R&32&&u!==(u=e[5].x))&&c(a,"x",u),(!$||R&32&&d!==(d=e[5].y))&&c(a,"y",d),(!$||R&32&&f!==(f=e[5].w))&&c(a,"width",f),(!$||R&32&&h!==(h=e[5].h))&&c(a,"height",h),(!$||R&32&&g!==(g=e[5].x))&&c(m,"x",g),(!$||R&32&&k!==(k=e[5].y))&&c(m,"y",k),(!$||R&32&&p!==(p=e[5].w))&&c(m,"width",p),(!$||R&32&&S!==(S=e[5].h))&&c(m,"height",S),(!$||R&2)&&c(A,"style",e[1]),(!$||R&32&&M!==(M=e[5].x))&&c(A,"x",M),(!$||R&32&&C!==(C=e[5].y))&&c(A,"y",C),(!$||R&32&&T!==(T=e[5].w))&&c(A,"width",T),(!$||R&32&&V!==(V=e[5].h))&&c(A,"height",V),(!$||R&32&&q!==(q=e[5].x))&&c(W,"x",q),(!$||R&32&&w!==(w=e[5].y))&&c(W,"y",w),(!$||R&32&&v!==(v=e[5].w))&&c(W,"width",v),(!$||R&32&&I!==(I=e[5].x+e[5].w))&&c(b,"x",I),(!$||R&32&&P!==(P=e[5].y))&&c(b,"y",P),(!$||R&32&&O!==(O=e[5].h))&&c(b,"height",O),(!$||R&32&&Q!==(Q=e[5].x))&&c(H,"x",Q),(!$||R&32&&Z!==(Z=e[5].y+e[5].h))&&c(H,"y",Z),(!$||R&32&&x!==(x=e[5].w))&&c(H,"width",x),(!$||R&32&&Se!==(Se=e[5].x))&&c(se,"x",Se),(!$||R&32&&Me!==(Me=e[5].y))&&c(se,"y",Me),(!$||R&32&&X!==(X=e[5].h))&&c(se,"height",X);const bt={};R&32&&(bt.x=e[5].x),R&32&&(bt.y=e[5].y),R&8&&(bt.scale=e[3]),te.$set(bt);const Et={};R&32&&(Et.x=e[5].x+e[5].w),R&32&&(Et.y=e[5].y),R&8&&(Et.scale=e[3]),ye.$set(Et);const vt={};R&32&&(vt.x=e[5].x+e[5].w),R&32&&(vt.y=e[5].y+e[5].h),R&8&&(vt.scale=e[3]),De.$set(vt);const St={};R&32&&(St.x=e[5].x),R&32&&(St.y=e[5].y+e[5].h),R&8&&(St.scale=e[3]),Ne.$set(St)},i(K){$||(U(te.$$.fragment,K),U(ye.$$.fragment,K),U(De.$$.fragment,K),U(Ne.$$.fragment,K),$=!0)},o(K){G(te.$$.fragment,K),G(ye.$$.fragment,K),G(De.$$.fragment,K),G(Ne.$$.fragment,K),$=!1},d(K){K&&(N(t),N(y),N(m),N(E),N(A),N(B),N(W),N(_),N(b),N(z),N(H),N(oe),N(se),N(fe),N(pe),N(We),N(en)),ae(te,K),ae(ye,K),ae(De,K),ae(Ne,K),tn=!1,Ae(Go)}}}function Ps(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[7],svgEl:e[4],$$slots:{default:[Ts,({grab:o})=>({12:o}),({grab:o})=>o?4096:0]},$$scope:{ctx:e}}}),t.$on("grab",e[9]),t.$on("change",e[10]),t.$on("release",e[11]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,[i]){const s={};i&1&&(s.shape=o[0]),i&4&&(s.transform=o[2]),i&16&&(s.svgEl=o[4]),i&12394&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Ls(e,t,n){let o,i,{shape:s}=t,{computedStyle:r}=t,{transform:l}=t,{viewportScale:a=1}=t,{svgEl:u}=t;const d=(g,k,p)=>{const S=g.geometry.bounds;let[E,A]=[S.minX,S.minY],[M,C]=[S.maxX,S.maxY];const[T,V]=p;if(k==="SHAPE")E+=T,M+=T,A+=V,C+=V;else{switch(k){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{A+=V;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{C+=V;break}}switch(k){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{E+=T;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{M+=T;break}}}const B=Math.min(E,M),W=Math.min(A,C),q=Math.abs(M-E),w=Math.abs(C-A);return{...g,geometry:{x:B,y:W,w:q,h:w,bounds:{minX:B,minY:W,maxX:B+q,maxY:W+w}}}},f=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function h(g){_e.call(this,e,g)}function y(g){_e.call(this,e,g)}function m(g){_e.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,o=s.geometry),e.$$.dirty&40&&n(6,i=ot(o.bounds,2/a))},[s,r,l,a,u,o,i,d,f,h,y,m]}class xn extends he{constructor(t){super(),de(this,t,Ls,Ps,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var $n=Object.prototype.hasOwnProperty;function Xt(e,t){var n,o;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((o=e.length)===t.length)for(;o--&&Xt(e[o],t[o]););return o===-1}if(!n||typeof e=="object"){o=0;for(n in e)if($n.call(e,n)&&++o&&!$n.call(t,n)||!(n in t)||!Xt(e[n],t[n]))return!1;return Object.keys(t).length===o}}return e!==e&&t!==t}const Is=12,Cs=(e,t)=>e.polygons.reduce((n,o,i)=>{const s=o.rings.reduce((r,l,a)=>{const u=l.points.map((d,f)=>{const h=f===l.points.length-1?l.points[0]:l.points[f+1],y=(d[0]+h[0])/2,m=(d[1]+h[1])/2,k=Math.sqrt(Math.pow(h[0]-y,2)+Math.pow(h[1]-m,2))>Is/t;return{point:[y,m],visible:k,elementIdx:i,ringIdx:a,pointIdx:f}});return[...r,...u]},[]);return[...n,...s]},[]);function Ht(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function eo(e,t,n){const o=e.slice();return o[30]=t[n],o[32]=n,o}function to(e,t,n){const o=e.slice();return o[33]=t[n],o[35]=n,o}function no(e,t,n){const o=e.slice();return o[29]=t[n],o[37]=n,o}function Gt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function jt(e){const t=e.slice(),n=t[10][t[6]];return t[29]=n.point,t}function oo(e){let t,n,o,i;return{c(){t=L("circle"),c(t,"cx",n=e[29][0]),c(t,"cy",o=e[29][1]),c(t,"r",i=st/e[3]),c(t,"class","svelte-1vxo6dc")},m(s,r){Y(s,t,r)},p(s,r){r[0]&1088&&n!==(n=s[29][0])&&c(t,"cx",n),r[0]&1088&&o!==(o=s[29][1])&&c(t,"cy",o),r[0]&8&&i!==(i=st/s[3])&&c(t,"r",i)},d(s){s&&N(t)}}}function io(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("mask"),n=L("rect"),l=L("circle"),c(n,"x",o=e[9].x),c(n,"y",i=e[9].y),c(n,"width",s=e[9].w),c(n,"height",r=e[9].h),c(n,"class","svelte-1vxo6dc"),c(l,"cx",a=e[29][0]),c(l,"cy",u=e[29][1]),c(l,"r",d=st/e[3]),c(l,"class","svelte-1vxo6dc"),c(t,"id",`${e[18]}-${e[32]}-inner`),c(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(f,h){Y(f,t,h),F(t,n),F(t,l)},p(f,h){h[0]&512&&o!==(o=f[9].x)&&c(n,"x",o),h[0]&512&&i!==(i=f[9].y)&&c(n,"y",i),h[0]&512&&s!==(s=f[9].w)&&c(n,"width",s),h[0]&512&&r!==(r=f[9].h)&&c(n,"height",r),h[0]&1088&&a!==(a=f[29][0])&&c(l,"cx",a),h[0]&1088&&u!==(u=f[29][1])&&c(l,"cy",u),h[0]&8&&d!==(d=st/f[3])&&c(l,"r",d)},d(f){f&&N(t)}}}function so(e){let t,n;function o(...i){return e[19](e[32],e[35],e[37],...i)}return t=new Xe({props:{class:"a9s-corner-handle",x:e[29][0],y:e[29][1],scale:e[3],selected:e[8].some(o)}}),t.$on("pointerenter",e[11]),t.$on("pointerleave",e[12]),t.$on("pointerdown",e[14]),t.$on("pointerdown",function(){ie(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(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){e=i;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(o)),t.$set(r)},i(i){n||(U(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function ro(e){let t,n,o=ve(e[33].points),i=[];for(let r=0;r<o.length;r+=1)i[r]=so(no(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);Y(r,t,l),n=!0},p(r,l){if(l[0]&268491048){o=ve(r[33].points);let a;for(a=0;a<o.length;a+=1){const u=no(r,o,a);i[a]?(i[a].p(u,l),U(i[a],1)):(i[a]=so(u),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&N(t),Ye(i,r)}}}function lo(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g,k,p,S=e[6]!==void 0&&!e[7]&&oo(jt(e)),E=e[6]!==void 0&&!e[7]&&io(Gt(e)),A=ve(e[30].rings),M=[];for(let T=0;T<A.length;T+=1)M[T]=ro(to(e,A,T));const C=T=>G(M[T],1,1,()=>{M[T]=null});return{c(){t=L("g"),n=L("defs"),o=L("mask"),i=L("rect"),u=L("path"),S&&S.c(),E&&E.c(),f=L("path"),y=L("path");for(let T=0;T<M.length;T+=1)M[T].c();c(i,"x",s=e[9].x),c(i,"y",r=e[9].y),c(i,"width",l=e[9].w),c(i,"height",a=e[9].h),c(i,"class","svelte-1vxo6dc"),c(u,"d",d=Pe(e[30])),c(u,"class","svelte-1vxo6dc"),c(o,"id",`${e[18]}-${e[32]}-outer`),c(o,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),c(f,"class","a9s-outer"),c(f,"mask",`url(#${e[18]}-${e[32]}-outer)`),c(f,"fill-rule","evenodd"),c(f,"d",h=Pe(e[30])),c(y,"class","a9s-inner"),c(y,"mask",`url(#${e[18]}-${e[32]}-inner)`),c(y,"style",e[1]),c(y,"fill-rule","evenodd"),c(y,"d",m=Pe(e[30]))},m(T,V){Y(T,t,V),F(t,n),F(n,o),F(o,i),F(o,u),S&&S.m(o,null),E&&E.m(n,null),F(t,f),F(t,y);for(let B=0;B<M.length;B+=1)M[B]&&M[B].m(t,null);g=!0,k||(p=[ee(f,"pointerup",e[13]),ee(f,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)}),ee(y,"pointerup",e[13]),ee(y,"pointerdown",function(){ie(e[28]("SHAPE"))&&e[28]("SHAPE").apply(this,arguments)})],k=!0)},p(T,V){if(e=T,(!g||V[0]&512&&s!==(s=e[9].x))&&c(i,"x",s),(!g||V[0]&512&&r!==(r=e[9].y))&&c(i,"y",r),(!g||V[0]&512&&l!==(l=e[9].w))&&c(i,"width",l),(!g||V[0]&512&&a!==(a=e[9].h))&&c(i,"height",a),(!g||V[0]&32&&d!==(d=Pe(e[30])))&&c(u,"d",d),e[6]!==void 0&&!e[7]?S?S.p(jt(e),V):(S=oo(jt(e)),S.c(),S.m(o,null)):S&&(S.d(1),S=null),e[6]!==void 0&&!e[7]?E?E.p(Gt(e),V):(E=io(Gt(e)),E.c(),E.m(n,null)):E&&(E.d(1),E=null),(!g||V[0]&32&&h!==(h=Pe(e[30])))&&c(f,"d",h),(!g||V[0]&2)&&c(y,"style",e[1]),(!g||V[0]&32&&m!==(m=Pe(e[30])))&&c(y,"d",m),V[0]&268491048){A=ve(e[30].rings);let B;for(B=0;B<A.length;B+=1){const W=to(e,A,B);M[B]?(M[B].p(W,V),U(M[B],1)):(M[B]=ro(W),M[B].c(),U(M[B],1),M[B].m(t,null))}for(be(),B=A.length;B<M.length;B+=1)C(B);Ee()}},i(T){if(!g){for(let V=0;V<A.length;V+=1)U(M[V]);g=!0}},o(T){M=M.filter(Boolean);for(let V=0;V<M.length;V+=1)G(M[V]);g=!1},d(T){T&&N(t),S&&S.d(),E&&E.d(),Ye(M,T),k=!1,Ae(p)}}}function ao(e){let t,n;return t=new Gn({props:{x:e[29][0],y:e[29][1],scale:e[3]}}),t.$on("pointerdown",function(){ie(e[17](e[6]))&&e[17](e[6]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&1088&&(s.x=e[29][0]),i[0]&1088&&(s.y=e[29][1]),i[0]&8&&(s.scale=e[3]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Os(e){let t,n,o,i=ve(e[5].polygons),s=[];for(let a=0;a<i.length;a+=1)s[a]=lo(eo(e,i,a));const r=a=>G(s[a],1,1,()=>{s[a]=null});let l=e[6]!==void 0&&!e[7]&&ao(Ht(e));return{c(){for(let a=0;a<s.length;a+=1)s[a].c();t=we(),l&&l.c(),n=ke()},m(a,u){for(let d=0;d<s.length;d+=1)s[d]&&s[d].m(a,u);Y(a,t,u),l&&l.m(a,u),Y(a,n,u),o=!0},p(a,u){if(u[0]&268763114){i=ve(a[5].polygons);let d;for(d=0;d<i.length;d+=1){const f=eo(a,i,d);s[d]?(s[d].p(f,u),U(s[d],1)):(s[d]=lo(f),s[d].c(),U(s[d],1),s[d].m(t.parentNode,t))}for(be(),d=i.length;d<s.length;d+=1)r(d);Ee()}a[6]!==void 0&&!a[7]?l?(l.p(Ht(a),u),u[0]&192&&U(l,1)):(l=ao(Ht(a)),l.c(),U(l,1),l.m(n.parentNode,n)):l&&(be(),G(l,1,1,()=>{l=null}),Ee())},i(a){if(!o){for(let u=0;u<i.length;u+=1)U(s[u]);U(l),o=!0}},o(a){s=s.filter(Boolean);for(let u=0;u<s.length;u+=1)G(s[u]);G(l),o=!1},d(a){a&&(N(t),N(n)),Ye(s,a),l&&l.d(a)}}}function Ds(e){let t,n;return t=new _t({props:{shape:e[0],transform:e[2],editor:e[16],svgEl:e[4],$$slots:{default:[Os,({grab:o})=>({28:o}),({grab:o})=>[o?268435456:0]]},$$scope:{ctx:e}}}),t.$on("change",e[20]),t.$on("grab",e[21]),t.$on("release",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&1&&(s.shape=o[0]),i[0]&4&&(s.transform=o[2]),i[0]&16&&(s.svgEl=o[4]),i[0]&268437482|i[1]&128&&(s.$$scope={dirty:i,ctx:o}),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}const Ns=250,Ys=1e3,st=4.5;function Bs(e,t,n){let o,i,s;const r=Ce();let{shape:l}=t,{computedStyle:a}=t,{transform:u}=t,{viewportScale:d=1}=t,{svgEl:f}=t,h,y=!1,m,g=[];const k=()=>n(7,y=!0),p=()=>n(7,y=!1),S=b=>{if(g.length>0||!i.some(x=>x.visible)){n(6,h=void 0);return}const[I,P]=u.elementToImage(b.offsetX,b.offsetY),O=x=>Math.pow(x[0]-I,2)+Math.pow(x[1]-P,2),z=wn(o).reduce((x,oe)=>O(oe)<O(x)?oe:x),H=i.filter(x=>x.visible).reduce((x,oe)=>O(oe.point)<O(x.point)?oe:x),Q=Math.pow(Ys/d,2);O(z)<Q||O(H.point)<Q?n(6,h=i.indexOf(H)):n(6,h=void 0)},E=()=>{document.activeElement!==f&&f.focus()},A=()=>{n(8,g=[]),E()},M=b=>{n(7,y=!0),b.preventDefault(),b.stopPropagation(),m=performance.now()},C=(b,I,P)=>O=>{if(!m||Le||performance.now()-m>Ns)return;const z=Q=>Q.polygon===b&&Q.ring===I&&Q.point===P,H=g.some(z);O.metaKey||O.ctrlKey||O.shiftKey?H?n(8,g=g.filter(Q=>!z(Q))):n(8,g=[...g,{polygon:b,ring:I,point:P}]):H&&g.length>1?n(8,g=[{polygon:b,ring:I,point:P}]):H?n(8,g=[]):n(8,g=[{polygon:b,ring:I,point:P}]),E()},T=(b,I,P)=>{E();const O=b.geometry.polygons;let z;if(I==="SHAPE")z=O.map(H=>{const Q=H.rings.map((x,oe)=>({points:x.points.map((Se,Me)=>[Se[0]+P[0],Se[1]+P[1]])})),Z=ue(Q[0].points);return{rings:Q,bounds:Z}});else{const[H,Q,Z,x]=I.split("-").map(oe=>parseInt(oe));z=O.map((oe,se)=>{if(se===Q){const Se=oe.rings.map((X,fe)=>fe===Z?{points:X.points.map((pe,ye)=>ye===x?[pe[0]+P[0],pe[1]+P[1]]:pe)}:X),Me=ue(Se[0].points);return{rings:Se,bounds:Me}}else return oe})}return{...b,geometry:{polygons:z,bounds:et(z)}}},V=b=>async I=>{I.stopPropagation();const P=i[b],O=o.polygons.map((H,Q)=>{if(Q===P.elementIdx){const Z=H.rings.map((oe,se)=>se===P.ringIdx?{points:[...oe.points.slice(0,P.pointIdx+1),P.point,...oe.points.slice(P.pointIdx+1)]}:oe),x=ue(Z[0].points);return{rings:Z,bounds:x}}else return H});r("change",{...l,geometry:{polygons:O,bounds:et(O)}}),await gn();const z=[...document.querySelectorAll(".a9s-handle")][b+1];if(z!=null&&z.firstChild){const H=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:I.clientX,clientY:I.clientY,pointerId:I.pointerId,pointerType:I.pointerType,isPrimary:I.isPrimary,buttons:I.buttons});z.firstChild.dispatchEvent(H)}},B=()=>{const b=o.polygons.map((P,O)=>{if(g.some(H=>H.polygon===O)){const H=P.rings.map((Z,x)=>{const oe=g.filter(se=>se.polygon===O&&se.ring===x);return oe.length&&Z.points.length-oe.length>=3?{points:Z.points.filter((Se,Me)=>!oe.some(X=>X.point===Me))}:Z}),Q=ue(H[0].points);return{rings:H,bounds:Q}}else return P});!Xt(o.polygons,b)&&(r("change",{...l,geometry:{polygons:b,bounds:et(b)}}),n(8,g=[]))};Be(()=>{if(Le)return;const b=I=>{(I.key==="Delete"||I.key==="Backspace")&&(I.preventDefault(),B())};return f.addEventListener("pointermove",S),f.addEventListener("keydown",b),()=>{f.removeEventListener("pointermove",S),f.removeEventListener("keydown",b)}});const W=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,q=(b,I,P,{polygon:O,ring:z,point:H})=>O===b&&z===I&&H===P;function w(b){_e.call(this,e,b)}function v(b){_e.call(this,e,b)}function _(b){_e.call(this,e,b)}return e.$$set=b=>{"shape"in b&&n(0,l=b.shape),"computedStyle"in b&&n(1,a=b.computedStyle),"transform"in b&&n(2,u=b.transform),"viewportScale"in b&&n(3,d=b.viewportScale),"svgEl"in b&&n(4,f=b.svgEl)},e.$$.update=()=>{e.$$.dirty[0]&1&&n(5,o=l.geometry),e.$$.dirty[0]&40&&n(10,i=Le?[]:Cs(o,d)),e.$$.dirty[0]&40&&n(9,s=ot(o.bounds,st/d))},[l,a,u,d,f,o,h,y,g,s,i,k,p,A,M,C,T,V,W,q,w,v,_]}class Rs extends he{constructor(t){super(),de(this,t,Bs,Ds,re,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const co=new Map([[J.RECTANGLE,xn],[J.POLYGON,Qn],[J.MULTIPOLYGON,Rs]]),uo=e=>co.get(e.type),fo=(e,t)=>co.set(e,t);function Us(e,t,n){let o;const i=Ce();let{annotation:s}=t,{editor:r}=t,{style:l}=t,{target:a}=t,{transform:u}=t,{viewportScale:d}=t,f;return Be(()=>(n(6,f=new r({target:a,props:{shape:s.target.selector,computedStyle:o,transform:u,viewportScale:d,svgEl:a.closest("svg")}})),f.$on("change",h=>{f.$$set({shape:h.detail}),i("change",h.detail)}),f.$on("grab",h=>i("grab",h.detail)),f.$on("release",h=>i("release",h.detail)),()=>{f.$destroy()})),e.$$set=h=>{"annotation"in h&&n(0,s=h.annotation),"editor"in h&&n(1,r=h.editor),"style"in h&&n(2,l=h.style),"target"in h&&n(3,a=h.target),"transform"in h&&n(4,u=h.transform),"viewportScale"in h&&n(5,d=h.viewportScale)},e.$$.update=()=>{e.$$.dirty&5&&n(7,o=Ve(s,l)),e.$$.dirty&65&&s&&(f==null||f.$set({shape:s.target.selector})),e.$$.dirty&80&&f&&f.$set({transform:u}),e.$$.dirty&96&&f&&f.$set({viewportScale:d}),e.$$.dirty&192&&f&&o&&f.$set({computedStyle:o})},[s,r,l,a,u,d,f,o]}class ho extends he{constructor(t){super(),de(this,t,Us,null,re,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function Vs(e,t,n){const o=Ce();let{drawingMode:i}=t,{target:s}=t,{tool:r}=t,{transform:l}=t,{viewportScale:a}=t,u;return Be(()=>{const d=s.closest("svg"),f=[],h=(y,m,g)=>{d==null||d.addEventListener(y,m,g),f.push(()=>d==null?void 0:d.removeEventListener(y,m,g))};return n(5,u=new r({target:s,props:{addEventListener:h,drawingMode:i,transform:l,viewportScale:a}})),u.$on("create",y=>o("create",y.detail)),()=>{f.forEach(y=>y()),u.$destroy()}}),e.$$set=d=>{"drawingMode"in d&&n(0,i=d.drawingMode),"target"in d&&n(1,s=d.target),"tool"in d&&n(2,r=d.tool),"transform"in d&&n(3,l=d.transform),"viewportScale"in d&&n(4,a=d.viewportScale)},e.$$.update=()=>{e.$$.dirty&40&&u&&u.$set({transform:l}),e.$$.dirty&48&&u&&u.$set({viewportScale:a})},[i,s,r,l,a,u]}class go extends he{constructor(t){super(),de(this,t,Vs,null,re,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function mo(e){let t,n,o,i,s,r,l,a,u,d;return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("rect"),u=L("rect"),d=L("rect"),c(o,"class","rect-mask-bg svelte-1a76qe7"),c(o,"x",i=e[1]-e[5]),c(o,"y",s=e[2]-e[5]),c(o,"width",r=e[3]+2*e[5]),c(o,"height",l=e[4]+2*e[5]),c(a,"class","rect-mask-fg svelte-1a76qe7"),c(a,"x",e[1]),c(a,"y",e[2]),c(a,"width",e[3]),c(a,"height",e[4]),c(n,"id",e[6]),c(n,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),c(u,"class","a9s-outer"),c(u,"mask",`url(#${e[6]})`),c(u,"x",e[1]),c(u,"y",e[2]),c(u,"width",e[3]),c(u,"height",e[4]),c(d,"class","a9s-inner"),c(d,"x",e[1]),c(d,"y",e[2]),c(d,"width",e[3]),c(d,"height",e[4])},m(f,h){Y(f,t,h),F(t,n),F(n,o),F(n,a),Y(f,u,h),Y(f,d,h)},p(f,h){h&34&&i!==(i=f[1]-f[5])&&c(o,"x",i),h&36&&s!==(s=f[2]-f[5])&&c(o,"y",s),h&40&&r!==(r=f[3]+2*f[5])&&c(o,"width",r),h&48&&l!==(l=f[4]+2*f[5])&&c(o,"height",l),h&2&&c(a,"x",f[1]),h&4&&c(a,"y",f[2]),h&8&&c(a,"width",f[3]),h&16&&c(a,"height",f[4]),h&2&&c(u,"x",f[1]),h&4&&c(u,"y",f[2]),h&8&&c(u,"width",f[3]),h&16&&c(u,"height",f[4]),h&2&&c(d,"x",f[1]),h&4&&c(d,"y",f[2]),h&8&&c(d,"width",f[3]),h&16&&c(d,"height",f[4])},d(f){f&&(N(t),N(u),N(d))}}}function Xs(e){let t,n=e[0]&&mo(e);return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){Y(o,t,i),n&&n.m(t,null)},p(o,[i]){o[0]?n?n.p(o,i):(n=mo(o),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&N(t),n&&n.d()}}}function Hs(e,t,n){let o;const i=Ce();let{addEventListener:s}=t,{drawingMode:r}=t,{transform:l}=t,{viewportScale:a=1}=t,u,d,f,h,y,m,g;const k=M=>{const C=M;u=performance.now(),r==="drag"&&(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,y=d[1]),n(3,m=1),n(4,g=1))},p=M=>{const C=M;d&&(f=l.elementToImage(C.offsetX,C.offsetY),n(1,h=Math.min(f[0],d[0])),n(2,y=Math.min(f[1],d[1])),n(3,m=Math.abs(f[0]-d[0])),n(4,g=Math.abs(f[1]-d[1])))},S=M=>{const C=M,T=performance.now()-u;if(r==="click"){if(T>300)return;d?E():(n(0,d=l.elementToImage(C.offsetX,C.offsetY)),f=d,n(1,h=d[0]),n(2,y=d[1]),n(3,m=1),n(4,g=1))}else d&&(T>300||m*g>100?(C.stopPropagation(),E()):(n(0,d=void 0),f=void 0))},E=()=>{if(m*g>15){const M={type:J.RECTANGLE,geometry:{bounds:{minX:h,minY:y,maxX:h+m,maxY:y+g},x:h,y,w:m,h:g}};i("create",M)}n(0,d=void 0),f=void 0};Be(()=>{s("pointerdown",k),s("pointermove",p),s("pointerup",S,!0)});const A=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=M=>{"addEventListener"in M&&n(7,s=M.addEventListener),"drawingMode"in M&&n(8,r=M.drawingMode),"transform"in M&&n(9,l=M.transform),"viewportScale"in M&&n(10,a=M.viewportScale)},e.$$.update=()=>{e.$$.dirty&1024&&n(5,o=2/a)},[d,h,y,m,g,o,A,s,r,l,a]}class po extends he{constructor(t){super(),de(this,t,Hs,Xs,re,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function zt(e){const t=e.slice(),n=t[2].map(o=>o.join(",")).join(" ");return t[19]=n,t}function _o(e){let t,n,o,i,s,r,l,a,u,d,f,h,y,m,g=e[1]&&yo(e);return{c(){t=L("defs"),n=L("mask"),o=L("rect"),a=L("polygon"),d=L("polygon"),h=L("polygon"),g&&g.c(),m=ke(),c(o,"x",i=e[3].x),c(o,"y",s=e[3].y),c(o,"width",r=e[3].w),c(o,"height",l=e[3].h),c(o,"class","svelte-18wrg3t"),c(a,"points",u=e[19]),c(a,"class","svelte-18wrg3t"),c(n,"id",e[5]),c(n,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),c(d,"class","a9s-outer"),c(d,"mask",`url(#${e[5]})`),c(d,"points",f=e[19]),c(h,"class","a9s-inner"),c(h,"points",y=e[19])},m(k,p){Y(k,t,p),F(t,n),F(n,o),F(n,a),Y(k,d,p),Y(k,h,p),g&&g.m(k,p),Y(k,m,p)},p(k,p){p&8&&i!==(i=k[3].x)&&c(o,"x",i),p&8&&s!==(s=k[3].y)&&c(o,"y",s),p&8&&r!==(r=k[3].w)&&c(o,"width",r),p&8&&l!==(l=k[3].h)&&c(o,"height",l),p&4&&u!==(u=k[19])&&c(a,"points",u),p&4&&f!==(f=k[19])&&c(d,"points",f),p&4&&y!==(y=k[19])&&c(h,"points",y),k[1]?g?g.p(k,p):(g=yo(k),g.c(),g.m(m.parentNode,m)):g&&(g.d(1),g=null)},d(k){k&&(N(t),N(d),N(h),N(m)),g&&g.d(k)}}}function yo(e){let t,n,o;return{c(){t=L("circle"),c(t,"class","a9s-handle svelte-18wrg3t"),c(t,"cx",n=e[0][0][0]),c(t,"cy",o=e[0][0][1]),c(t,"r",e[4])},m(i,s){Y(i,t,s)},p(i,s){s&1&&n!==(n=i[0][0][0])&&c(t,"cx",n),s&1&&o!==(o=i[0][0][1])&&c(t,"cy",o),s&16&&c(t,"r",i[4])},d(i){i&&N(t)}}}function Gs(e){let t,n=e[3]&&_o(zt(e));return{c(){t=L("g"),n&&n.c(),c(t,"class","a9s-annotation a9s-rubberband")},m(o,i){Y(o,t,i),n&&n.m(t,null)},p(o,[i]){o[3]?n?n.p(zt(o),i):(n=_o(zt(o)),n.c(),n.m(t,null)):n&&(n.d(1),n=null)},i:j,o:j,d(o){o&&N(t),n&&n.d()}}}const js=20,zs=1500;function Fs(e,t,n){let o,i,s;const r=Ce();let{addEventListener:l}=t,{drawingMode:a}=t,{transform:u}=t,{viewportScale:d=1}=t,f,h=[],y,m,g=!1;const k=C=>{const T=C,{timeStamp:V,offsetX:B,offsetY:W}=T;if(f={timeStamp:V,offsetX:B,offsetY:W},a==="drag"&&h.length===0){const q=u.elementToImage(T.offsetX,T.offsetY);h.push(q),n(10,y=q)}},p=C=>{const T=C;if(m&&clearTimeout(m),h.length>0){if(n(10,y=u.elementToImage(T.offsetX,T.offsetY)),h.length>2){const V=$e(y,h[0])*d;n(1,g=V<js)}T.pointerType==="touch"&&(m=setTimeout(()=>{E()},zs))}},S=C=>{const T=C;if(m&&clearTimeout(m),a==="click"){const V=T.timeStamp-f.timeStamp,B=$e([f.offsetX,f.offsetY],[T.offsetX,T.offsetY]);if(V>300||B>15)return;if(g)A();else if(h.length===0){const W=u.elementToImage(T.offsetX,T.offsetY);h.push(W),n(10,y=W)}else h.push(y)}else{if(h.length===1&&$e(h[0],y)<=4){n(0,h=[]),n(10,y=void 0);return}T.stopImmediatePropagation(),g?A():h.push(y)}},E=()=>{if(!y)return;const C=h.slice(0,-1);if(C.length<3)return;const T={type:J.POLYGON,geometry:{bounds:ue(h),points:C}};dt(T)>4&&(n(0,h=[]),n(10,y=void 0),r("create",T))},A=()=>{const C={type:J.POLYGON,geometry:{bounds:ue(h),points:[...h]}};n(0,h=[]),n(10,y=void 0),r("create",C)};Be(()=>{l("pointerdown",k,!0),l("pointermove",p),l("pointerup",S,!0),l("dblclick",E,!0)});const M=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return e.$$set=C=>{"addEventListener"in C&&n(6,l=C.addEventListener),"drawingMode"in C&&n(7,a=C.drawingMode),"transform"in C&&n(8,u=C.transform),"viewportScale"in C&&n(9,d=C.viewportScale)},e.$$.update=()=>{e.$$.dirty&512&&n(4,o=4/d),e.$$.dirty&1027&&n(2,i=y?g?h:[...h,y]:[]),e.$$.dirty&516&&n(3,s=i.length>0?ot(ue(i),2/d):void 0)},[h,g,i,s,o,M,l,a,u,d,y]}class qs extends he{constructor(t){super(),de(this,t,Fs,Gs,re,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Ft=new Map([["rectangle",{tool:po}],["polygon",{tool:qs}]]),qt=()=>[...Ft.keys()],Kt=e=>Ft.get(e),wo=(e,t,n={})=>Ft.set(e,{tool:t,opts:n});function Ks(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("ellipse"),i=L("ellipse"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"cx",e[2]),c(n,"cy",e[3]),c(n,"rx",e[4]),c(n,"ry",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"cx",e[2]),c(i,"cy",e[3]),c(i,"rx",e[4]),c(i,"ry",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function Ws(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{cx:l,cy:a,rx:u,ry:d}=s;return e.$$set=f=>{"annotation"in f&&n(0,i=f.annotation),"geom"in f&&n(6,s=f.geom),"style"in f&&n(7,r=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ve(i,r))},[i,o,l,a,u,d,s,r]}class Zs extends he{constructor(t){super(),de(this,t,Ws,Ks,re,{annotation:0,geom:6,style:7})}}function Js(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("line"),i=L("line"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"x1",e[2]),c(n,"y1",e[3]),c(n,"x2",e[4]),c(n,"y2",e[5]),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"x1",e[2]),c(i,"y1",e[3]),c(i,"x2",e[4]),c(i,"y2",e[5]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function Qs(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s,[[a,u],[d,f]]=l;return e.$$set=h=>{"annotation"in h&&n(0,i=h.annotation),"geom"in h&&n(6,s=h.geom),"style"in h&&n(7,r=h.style)},e.$$.update=()=>{e.$$.dirty&129&&n(1,o=Ve(i,r))},[i,o,a,u,d,f,s,r]}class xs extends he{constructor(t){super(),de(this,t,Qs,Js,re,{annotation:0,geom:6,style:7})}}function bo(e,t,n){const o=e.slice();return o[5]=t[n],o}function Eo(e){let t,n,o;return{c(){t=L("path"),o=L("path"),c(t,"class","a9s-outer"),c(t,"style",n=e[1]?"display:none;":void 0),c(t,"fill-rule","evenodd"),c(t,"d",Pe(e[5])),c(o,"class","a9s-inner"),c(o,"style",e[1]),c(o,"fill-rule","evenodd"),c(o,"d",Pe(e[5]))},m(i,s){Y(i,t,s),Y(i,o,s)},p(i,s){s&2&&n!==(n=i[1]?"display:none;":void 0)&&c(t,"style",n),s&2&&c(o,"style",i[1])},d(i){i&&(N(t),N(o))}}}function $s(e){let t,n,o=ve(e[2]),i=[];for(let s=0;s<o.length;s+=1)i[s]=Eo(bo(e,o,s));return{c(){t=L("g");for(let s=0;s<i.length;s+=1)i[s].c();c(t,"class","a9s-annotation"),c(t,"data-id",n=e[0].id)},m(s,r){Y(s,t,r);for(let l=0;l<i.length;l+=1)i[l]&&i[l].m(t,null)},p(s,[r]){if(r&6){o=ve(s[2]);let l;for(l=0;l<o.length;l+=1){const a=bo(s,o,l);i[l]?i[l].p(a,r):(i[l]=Eo(a),i[l].c(),i[l].m(t,null))}for(;l<i.length;l+=1)i[l].d(1);i.length=o.length}r&1&&n!==(n=s[0].id)&&c(t,"data-id",n)},i:j,o:j,d(s){s&&N(t),Ye(i,s)}}}function er(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{polygons:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=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,o=Ve(i,r))},[i,o,l,s,r]}class tr extends he{constructor(t){super(),de(this,t,er,$s,re,{annotation:0,geom:3,style:4})}}function nr(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("polygon"),i=L("polygon"),c(n,"class","a9s-outer"),c(n,"style",o=e[1]?"display:none;":void 0),c(n,"points",e[2].map(or).join(" ")),c(i,"class","a9s-inner"),c(i,"style",e[1]),c(i,"points",e[2].map(ir).join(" ")),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&2&&o!==(o=r[1]?"display:none;":void 0)&&c(n,"style",o),l&2&&c(i,"style",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}const or=e=>e.join(","),ir=e=>e.join(",");function sr(e,t,n){let o,{annotation:i}=t,{geom:s}=t,{style:r}=t;const{points:l}=s;return e.$$set=a=>{"annotation"in a&&n(0,i=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,o=Ve(i,r))},[i,o,l,s,r]}class rr extends he{constructor(t){super(),de(this,t,sr,nr,re,{annotation:0,geom:3,style:4})}}function lr(e){let t,n,o,i,s,r,l;return{c(){t=L("g"),n=L("path"),s=L("path"),c(n,"class",o=ct(`a9s-outer ${e[1]}`)+" svelte-1w0132l"),c(n,"style",i=e[3]?"display:none;":void 0),c(n,"d",e[2]),c(s,"class",r=ct(`a9s-inner ${e[1]}`)+" svelte-1w0132l"),c(s,"style",e[3]),c(s,"d",e[2]),c(t,"class","a9s-annotation"),c(t,"data-id",l=e[0].id)},m(a,u){Y(a,t,u),F(t,n),F(t,s)},p(a,[u]){u&2&&o!==(o=ct(`a9s-outer ${a[1]}`)+" svelte-1w0132l")&&c(n,"class",o),u&8&&i!==(i=a[3]?"display:none;":void 0)&&c(n,"style",i),u&4&&c(n,"d",a[2]),u&2&&r!==(r=ct(`a9s-inner ${a[1]}`)+" svelte-1w0132l")&&c(s,"class",r),u&8&&c(s,"style",a[3]),u&4&&c(s,"d",a[2]),u&1&&l!==(l=a[0].id)&&c(t,"data-id",l)},i:j,o:j,d(a){a&&N(t)}}}function ar(e,t,n){let o,i,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,o=Ve(r,a)),e.$$.dirty&16&&n(2,i=It(l)),e.$$.dirty&16&&n(1,s=l.closed?"closed":"open")},[r,s,i,o,l,a]}class cr extends he{constructor(t){super(),de(this,t,ar,lr,re,{annotation:0,geom:4,style:5})}}function ur(e){let t,n,o,i,s;return{c(){t=L("g"),n=L("rect"),i=L("rect"),c(n,"class","a9s-outer"),c(n,"style",o=e[5]?"display:none;":void 0),c(n,"x",e[4]),c(n,"y",e[3]),c(n,"width",e[2]),c(n,"height",e[1]),c(i,"class","a9s-inner"),c(i,"style",e[5]),c(i,"x",e[4]),c(i,"y",e[3]),c(i,"width",e[2]),c(i,"height",e[1]),c(t,"class","a9s-annotation"),c(t,"data-id",s=e[0].id)},m(r,l){Y(r,t,l),F(t,n),F(t,i)},p(r,[l]){l&32&&o!==(o=r[5]?"display:none;":void 0)&&c(n,"style",o),l&16&&c(n,"x",r[4]),l&8&&c(n,"y",r[3]),l&4&&c(n,"width",r[2]),l&2&&c(n,"height",r[1]),l&32&&c(i,"style",r[5]),l&16&&c(i,"x",r[4]),l&8&&c(i,"y",r[3]),l&4&&c(i,"width",r[2]),l&2&&c(i,"height",r[1]),l&1&&s!==(s=r[0].id)&&c(t,"data-id",s)},i:j,o:j,d(r){r&&N(t)}}}function fr(e,t,n){let o,i,s,r,l,{annotation:a}=t,{geom:u}=t,{style:d}=t;return e.$$set=f=>{"annotation"in f&&n(0,a=f.annotation),"geom"in f&&n(6,u=f.geom),"style"in f&&n(7,d=f.style)},e.$$.update=()=>{e.$$.dirty&129&&n(5,o=Ve(a,d)),e.$$.dirty&64&&n(4,{x:i,y:s,w:r,h:l}=u,i,(n(3,s),n(6,u)),(n(2,r),n(6,u)),(n(1,l),n(6,u)))},[a,l,r,s,i,o,u,d]}class dr extends he{constructor(t){super(),de(this,t,fr,ur,re,{annotation:0,geom:6,style:7})}}const hr={elementToImage:(e,t)=>[e,t]},vo=e=>({elementToImage:(t,n)=>{const o=e.getBoundingClientRect(),i=e.createSVGPoint();i.x=t+o.x,i.y=n+o.y;const{x:s,y:r}=i.matrixTransform(e.getScreenCTM().inverse());return[s,r]}}),gr=250,So=(e,t)=>{const n=Ce();let o;return{onPointerDown:()=>o=performance.now(),onPointerUp:r=>{if(performance.now()-o<gr){const{x:a,y:u}=Wt(r,e),d=t.getAt(a,u,void 0,2);d?n("click",{originalEvent:r,annotation:d}):n("click",{originalEvent:r})}}}},Wt=(e,t)=>{const n=t.createSVGPoint(),o=t.getBoundingClientRect(),i=e.clientX-o.x,s=e.clientY-o.y,{left:r,top:l}=t.getBoundingClientRect();return n.x=i+r,n.y=s+l,n.matrixTransform(t.getScreenCTM().inverse())};function Ao(e,t,n){const o=e.slice();return o[39]=t[n],o}function ko(e,t,n){const o=e.slice();return o[42]=t[n],o}function Zt(e){const t=e.slice(),n=t[42].target.selector;return t[45]=n,t}function Mo(e){let t=e[42],n,o,i=To(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&131072&&re(t,t=s[42])?(be(),G(i,1,1,j),Ee(),i=To(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function mr(e){let t,n;return t=new xs({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function pr(e){let t,n;return t=new cr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function _r(e){let t,n;return t=new tr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function yr(e){let t,n;return t=new rr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function wr(e){let t,n;return t=new dr({props:{annotation:e[42],geom:e[45].geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&131072&&(s.annotation=o[42]),i[0]&131072&&(s.geom=o[45].geometry),i[0]&2&&(s.style=o[1]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function br(e){var o;let t,n;return t=new Zs({props:{annotation:e[42],geom:(o=e[45])==null?void 0:o.geometry,style:e[1]}}),{c(){ce(t.$$.fragment)},m(i,s){le(t,i,s),n=!0},p(i,s){var l;const r={};s[0]&131072&&(r.annotation=i[42]),s[0]&131072&&(r.geom=(l=i[45])==null?void 0:l.geometry),s[0]&2&&(r.style=i[1]),t.$set(r)},i(i){n||(U(t.$$.fragment,i),n=!0)},o(i){G(t.$$.fragment,i),n=!1},d(i){ae(t,i)}}}function To(e){let t,n,o,i;const s=[br,wr,yr,_r,pr,mr],r=[];function l(a,u){var d,f,h,y,m,g;return((d=a[45])==null?void 0:d.type)===J.ELLIPSE?0:((f=a[45])==null?void 0:f.type)===J.RECTANGLE?1:((h=a[45])==null?void 0:h.type)===J.POLYGON?2:((y=a[45])==null?void 0:y.type)===J.MULTIPOLYGON?3:((m=a[45])==null?void 0:m.type)===J.POLYLINE?4:((g=a[45])==null?void 0:g.type)===J.LINE?5:-1}return~(t=l(e))&&(n=r[t]=s[t](e)),{c(){n&&n.c(),o=ke()},m(a,u){~t&&r[t].m(a,u),Y(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){G(n),i=!1},d(a){a&&N(o),~t&&r[t].d(a)}}}function Po(e){let t=tt(e[42])&&!e[10](e[42]),n,o,i=t&&Mo(Zt(e));return{c(){i&&i.c(),n=ke()},m(s,r){i&&i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&132096&&(t=tt(s[42])&&!s[10](s[42])),t?i?(i.p(Zt(s),r),r[0]&132096&&U(i,1)):(i=Mo(Zt(s)),i.c(),U(i,1),i.m(n.parentNode,n)):i&&(be(),G(i,1,1,()=>{i=null}),Ee())},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i&&i.d(s)}}}function Lo(e){let t,n,o,i;const s=[vr,Er],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(),o=ke()},m(a,u){~t&&r[t].m(a,u),Y(a,o,u),i=!0},p(a,u){let d=t;t=l(a),t===d?~t&&r[t].p(a,u):(n&&(be(),G(r[d],1,1,()=>{r[d]=null}),Ee()),~t?(n=r[t],n?n.p(a,u):(n=r[t]=s[t](a),n.c()),U(n,1),n.m(o.parentNode,o)):n=null)},i(a){i||(U(n),i=!0)},o(a){G(n),i=!1},d(a){a&&N(o),~t&&r[t].d(a)}}}function Er(e){let t=`${e[2]}-${e[7]}`,n,o,i=Io(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&132&&re(t,t=`${s[2]}-${s[7]}`)?(be(),G(i,1,1,j),Ee(),i=Io(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function vr(e){let t,n,o=ve(e[6]),i=[];for(let r=0;r<o.length;r+=1)i[r]=Oo(Ao(e,o,r));const s=r=>G(i[r],1,1,()=>{i[r]=null});return{c(){for(let r=0;r<i.length;r+=1)i[r].c();t=ke()},m(r,l){for(let a=0;a<i.length;a+=1)i[a]&&i[a].m(r,l);Y(r,t,l),n=!0},p(r,l){if(l[0]&8659266){o=ve(r[6]);let a;for(a=0;a<o.length;a+=1){const u=Ao(r,o,a);i[a]?(i[a].p(u,l),U(i[a],1)):(i[a]=Oo(u),i[a].c(),U(i[a],1),i[a].m(t.parentNode,t))}for(be(),a=o.length;a<i.length;a+=1)s(a);Ee()}},i(r){if(!n){for(let l=0;l<o.length;l+=1)U(i[l]);n=!0}},o(r){i=i.filter(Boolean);for(let l=0;l<i.length;l+=1)G(i[l]);n=!1},d(r){r&&N(t),Ye(i,r)}}}function Io(e){let t,n;return t=new go({props:{target:e[8],tool:e[15],drawingMode:e[14],transform:e[13],viewportScale:e[18]}}),t.$on("create",e[22]),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){const s={};i[0]&256&&(s.target=o[8]),i[0]&32768&&(s.tool=o[15]),i[0]&16384&&(s.drawingMode=o[14]),i[0]&8192&&(s.transform=o[13]),i[0]&262144&&(s.viewportScale=o[18]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Co(e){let t,n;return t=new ho({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(){ie(e[23](e[39].annotation))&&e[23](e[39].annotation).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(o,i){le(t,o,i),n=!0},p(o,i){e=o;const s={};i[0]&256&&(s.target=e[8]),i[0]&64&&(s.editor=e[39].editor),i[0]&64&&(s.annotation=e[39].annotation),i[0]&2&&(s.style=e[1]),i[0]&8192&&(s.transform=e[13]),i[0]&262144&&(s.viewportScale=e[18]),t.$set(s)},i(o){n||(U(t.$$.fragment,o),n=!0)},o(o){G(t.$$.fragment,o),n=!1},d(o){ae(t,o)}}}function Oo(e){let t=e[39].annotation.id,n,o,i=Co(e);return{c(){i.c(),n=ke()},m(s,r){i.m(s,r),Y(s,n,r),o=!0},p(s,r){r[0]&64&&re(t,t=s[39].annotation.id)?(be(),G(i,1,1,j),Ee(),i=Co(s),i.c(),U(i,1),i.m(n.parentNode,n)):i.p(s,r)},i(s){o||(U(i),o=!0)},o(s){G(i),o=!1},d(s){s&&N(n),i.d(s)}}}function Sr(e){let t,n,o,i,s,r,l=ve(e[17].filter(e[34])),a=[];for(let f=0;f<l.length;f+=1)a[f]=Po(ko(e,l,f));const u=f=>G(a[f],1,1,()=>{a[f]=null});let d=e[8]&&Lo(e);return{c(){t=L("svg"),n=L("g");for(let f=0;f<a.length;f+=1)a[f].c();o=L("g"),d&&d.c(),c(o,"class","drawing"),c(t,"role","application"),c(t,"tabindex",0),c(t,"class","a9s-annotationlayer"),Te(t,"drawing",e[15]),Te(t,"editing",e[5]),Te(t,"hidden",!e[3]),Te(t,"hover",e[16])},m(f,h){Y(f,t,h),F(t,n);for(let y=0;y<a.length;y+=1)a[y]&&a[y].m(n,null);F(t,o),d&&d.m(o,null),e[35](o),e[36](t),i=!0,s||(r=[ee(t,"pointerup",function(){ie(e[11])&&e[11].apply(this,arguments)}),ee(t,"pointerdown",function(){ie(e[12])&&e[12].apply(this,arguments)}),ee(t,"pointermove",e[24])],s=!0)},p(f,h){if(e=f,h[0]&132098){l=ve(e[17].filter(e[34]));let y;for(y=0;y<l.length;y+=1){const m=ko(e,l,y);a[y]?(a[y].p(m,h),U(a[y],1)):(a[y]=Po(m),a[y].c(),U(a[y],1),a[y].m(n,null))}for(be(),y=l.length;y<a.length;y+=1)u(y);Ee()}e[8]?d?(d.p(e,h),h[0]&256&&U(d,1)):(d=Lo(e),d.c(),U(d,1),d.m(o,null)):d&&(be(),G(d,1,1,()=>{d=null}),Ee()),(!i||h[0]&32768)&&Te(t,"drawing",e[15]),(!i||h[0]&32)&&Te(t,"editing",e[5]),(!i||h[0]&8)&&Te(t,"hidden",!e[3]),(!i||h[0]&65536)&&Te(t,"hover",e[16])},i(f){if(!i){for(let h=0;h<l.length;h+=1)U(a[h]);U(d),i=!0}},o(f){a=a.filter(Boolean);for(let h=0;h<a.length;h+=1)G(a[h]);G(d),i=!1},d(f){f&&N(t),Ye(a,f),d&&d.d(),e[35](null),e[36](null),s=!1,Ae(r)}}}function Ar(e,t,n){let o,i,s,r,l,a,u,d,f,h,y,m,g=j,k=()=>(g(),g=rn(b,X=>n(18,m=X)),b);e.$$.on_destroy.push(()=>g());let{drawingEnabled:p}=t,{image:S}=t,{preferredDrawingMode:E}=t,{state:A}=t,{style:M=void 0}=t,{toolName:C=qt()[0]}=t,{user:T}=t,{visible:V=!0}=t,B=0;const W=()=>n(7,B+=1),q=()=>C,w=()=>p;let v,_,b;Be(()=>k(n(9,b=Vn(S,_))));const{hover:I,selection:P,store:O}=A;At(e,I,X=>n(16,f=X)),At(e,P,X=>n(33,h=X)),At(e,O,X=>n(17,y=X));let z,H;const Q=X=>{z&&O.unobserve(z);const fe=X.filter(({editable:te})=>te).map(({id:te})=>te);fe.length>0?(n(5,H=fe.map(te=>O.getAnnotation(te)).filter(te=>te&&tt(te))),z=te=>{const{updated:pe}=te.changes;n(5,H=pe==null?void 0:pe.map(ye=>ye.newValue))},O.observe(z,{annotations:fe})):n(5,H=void 0)},Z=X=>{const fe=Cn(),te={id:fe,bodies:[],target:{annotation:fe,selector:X.detail,creator:T,created:new Date}};O.addAnnotation(te),P.setSelected(te.id)},x=X=>fe=>{var We;const{target:te}=X,pe=10*60*1e3,ye=((We=te.creator)==null?void 0:We.id)!==T.id||!te.created||new Date().getTime()-te.created.getTime()>pe;O.updateTarget({...te,selector:fe.detail,created:ye?te.created:new Date,updated:ye?new Date:void 0,updatedBy:ye?T:void 0})},oe=X=>{const{x:fe,y:te}=Wt(X,_),pe=O.getAt(fe,te,void 0,2);pe?f!==pe.id&&I.set(pe.id):I.set(void 0)},se=X=>tt(X);function Se(X){ut[X?"unshift":"push"](()=>{v=X,n(8,v)})}function Me(X){ut[X?"unshift":"push"](()=>{_=X,n(4,_)})}return e.$$set=X=>{"drawingEnabled"in X&&n(0,p=X.drawingEnabled),"image"in X&&n(25,S=X.image),"preferredDrawingMode"in X&&n(26,E=X.preferredDrawingMode),"state"in X&&n(27,A=X.state),"style"in X&&n(1,M=X.style),"toolName"in X&&n(2,C=X.toolName),"user"in X&&n(28,T=X.user),"visible"in X&&n(3,V=X.visible)},e.$$.update=()=>{e.$$.dirty[0]&4&&n(15,{tool:o,opts:i}=Kt(C)||{tool:void 0,opts:void 0},o,(n(32,i),n(2,C))),e.$$.dirty[0]&67108864|e.$$.dirty[1]&2&&n(14,s=(i==null?void 0:i.drawingMode)||E),e.$$.dirty[0]&16&&n(13,r=vo(_)),e.$$.dirty[0]&16&&n(12,{onPointerDown:l,onPointerUp:a}=So(_,O),l,(n(11,a),n(4,_))),e.$$.dirty[1]&4&&Q(h.selected),e.$$.dirty[0]&32&&n(6,u=H?H.map(X=>({annotation:X,editor:uo(X.target.selector)})).filter(X=>X.editor):void 0),e.$$.dirty[0]&64&&n(10,d=X=>u&&u.some(fe=>fe.annotation.id===X.id))},[p,M,C,V,_,H,u,B,v,b,d,a,l,r,s,o,f,y,m,I,P,O,Z,x,oe,S,E,A,T,W,q,w,i,h,se,Se,Me]}class Do extends he{constructor(t){super(),de(this,t,Ar,Sr,re,{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,o=e.length-1,i=kr){for(;o>n;){if(o-n>600){const a=o-n+1,u=t-n+1,d=Math.log(a),f=.5*Math.exp(2*d/3),h=.5*Math.sqrt(d*f*(a-f)/a)*(u-a/2<0?-1:1),y=Math.max(n,Math.floor(t-u*f/a+h)),m=Math.min(o,Math.floor(t+(a-u)*f/a+h));No(e,t,y,m,i)}const s=e[t];let r=n,l=o;for(rt(e,n,t),i(e[o],s)>0&&rt(e,n,o);r<l;){for(rt(e,r,l),r++,l--;i(e[r],s)<0;)r++;for(;i(e[l],s)>0;)l--}i(e[n],s)===0?rt(e,n,l):(l++,rt(e,l,o)),l<=t&&(n=l+1),t<=l&&(o=l-1)}}function rt(e,t,n){const o=e[t];e[t]=e[n],e[n]=o}function kr(e,t){return e<t?-1:e>t?1:0}class Mr{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 o=[];if(!wt(t,n))return o;const i=this.toBBox,s=[];for(;n;){for(let r=0;r<n.children.length;r++){const l=n.children[r],a=n.leaf?i(l):l;wt(t,a)&&(n.leaf?o.push(l):Qt(t,a)?this._all(l,o):s.push(l))}n=s.pop()}return o}collides(t){let n=this.data;if(!wt(t,n))return!1;const o=[];for(;n;){for(let i=0;i<n.children.length;i++){const s=n.children[i],r=n.leaf?this.toBBox(s):s;if(wt(t,r)){if(n.leaf||Qt(t,r))return!0;o.push(s)}}n=o.pop()}return!1}load(t){if(!(t&&t.length))return this;if(t.length<this._minEntries){for(let o=0;o<t.length;o++)this.insert(t[o]);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 o=this.data;this.data=n,n=o}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=Ke([]),this}remove(t,n){if(!t)return this;let o=this.data;const i=this.toBBox(t),s=[],r=[];let l,a,u;for(;o||s.length;){if(o||(o=s.pop(),a=s[s.length-1],l=r.pop(),u=!0),o.leaf){const d=Tr(t,o.children,n);if(d!==-1)return o.children.splice(d,1),s.push(o),this._condense(s),this}!u&&!o.leaf&&Qt(o,i)?(s.push(o),r.push(l),l=0,a=o,o=o.children[0]):a?(l++,o=a.children[l],u=!1):o=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 o=[];for(;t;)t.leaf?n.push(...t.children):o.push(...t.children),t=o.pop();return n}_build(t,n,o,i){const s=o-n+1;let r=this._maxEntries,l;if(s<=r)return l=Ke(t.slice(n,o+1)),qe(l,this.toBBox),l;i||(i=Math.ceil(Math.log(s)/Math.log(r)),r=Math.ceil(s/Math.pow(r,i-1))),l=Ke([]),l.leaf=!1,l.height=i;const a=Math.ceil(s/r),u=a*Math.ceil(Math.sqrt(r));Yo(t,n,o,u,this.compareMinX);for(let d=n;d<=o;d+=u){const f=Math.min(d+u-1,o);Yo(t,d,f,a,this.compareMinY);for(let h=d;h<=f;h+=a){const y=Math.min(h+a-1,f);l.children.push(this._build(t,h,y,i-1))}}return qe(l,this.toBBox),l}_chooseSubtree(t,n,o,i){for(;i.push(n),!(n.leaf||i.length-1===o);){let s=1/0,r=1/0,l;for(let a=0;a<n.children.length;a++){const u=n.children[a],d=Jt(u),f=Ir(t,u)-d;f<r?(r=f,s=d<s?d:s,l=u):f===r&&d<s&&(s=d,l=u)}n=l||n.children[0]}return n}_insert(t,n,o){const i=o?t:this.toBBox(t),s=[],r=this._chooseSubtree(i,this.data,n,s);for(r.children.push(t),at(r,i);n>=0&&s[n].children.length>this._maxEntries;)this._split(s,n),n--;this._adjustParentBBoxes(i,s,n)}_split(t,n){const o=t[n],i=o.children.length,s=this._minEntries;this._chooseSplitAxis(o,s,i);const r=this._chooseSplitIndex(o,s,i),l=Ke(o.children.splice(r,o.children.length-r));l.height=o.height,l.leaf=o.leaf,qe(o,this.toBBox),qe(l,this.toBBox),n?t[n-1].children.push(l):this._splitRoot(o,l)}_splitRoot(t,n){this.data=Ke([t,n]),this.data.height=t.height+1,this.data.leaf=!1,qe(this.data,this.toBBox)}_chooseSplitIndex(t,n,o){let i,s=1/0,r=1/0;for(let l=n;l<=o-n;l++){const a=lt(t,0,l,this.toBBox),u=lt(t,l,o,this.toBBox),d=Cr(a,u),f=Jt(a)+Jt(u);d<s?(s=d,i=l,r=f<r?f:r):d===s&&f<r&&(r=f,i=l)}return i||o-n}_chooseSplitAxis(t,n,o){const i=t.leaf?this.compareMinX:Pr,s=t.leaf?this.compareMinY:Lr,r=this._allDistMargin(t,n,o,i),l=this._allDistMargin(t,n,o,s);r<l&&t.children.sort(i)}_allDistMargin(t,n,o,i){t.children.sort(i);const s=this.toBBox,r=lt(t,0,n,s),l=lt(t,o-n,o,s);let a=yt(r)+yt(l);for(let u=n;u<o-n;u++){const d=t.children[u];at(r,t.leaf?s(d):d),a+=yt(r)}for(let u=o-n-1;u>=n;u--){const d=t.children[u];at(l,t.leaf?s(d):d),a+=yt(l)}return a}_adjustParentBBoxes(t,n,o){for(let i=o;i>=0;i--)at(n[i],t)}_condense(t){for(let n=t.length-1,o;n>=0;n--)t[n].children.length===0?n>0?(o=t[n-1].children,o.splice(o.indexOf(t[n]),1)):this.clear():qe(t[n],this.toBBox)}}function Tr(e,t,n){if(!n)return t.indexOf(e);for(let o=0;o<t.length;o++)if(n(e,t[o]))return o;return-1}function qe(e,t){lt(e,0,e.children.length,t,e)}function lt(e,t,n,o,i){i||(i=Ke(null)),i.minX=1/0,i.minY=1/0,i.maxX=-1/0,i.maxY=-1/0;for(let s=t;s<n;s++){const r=e.children[s];at(i,e.leaf?o(r):r)}return i}function at(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 Pr(e,t){return e.minX-t.minX}function Lr(e,t){return e.minY-t.minY}function Jt(e){return(e.maxX-e.minX)*(e.maxY-e.minY)}function yt(e){return e.maxX-e.minX+(e.maxY-e.minY)}function Ir(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 Cr(e,t){const n=Math.max(e.minX,t.minX),o=Math.max(e.minY,t.minY),i=Math.min(e.maxX,t.maxX),s=Math.min(e.maxY,t.maxY);return Math.max(0,i-n)*Math.max(0,s-o)}function Qt(e,t){return e.minX<=t.minX&&e.minY<=t.minY&&t.maxX<=e.maxX&&t.maxY<=e.maxY}function wt(e,t){return t.minX<=e.maxX&&t.minY<=e.maxY&&t.maxX>=e.minX&&t.maxY>=e.minY}function Ke(e){return{children:e,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Yo(e,t,n,o,i){const s=[t,n];for(;s.length;){if(n=s.pop(),t=s.pop(),n-t<=o)continue;const r=t+Math.ceil((n-t)/o/2)*o;No(e,r,t,n,i),s.push(t,r,r,n)}}const Or=()=>{const e=new Mr,t=new Map,n=()=>[...t.values()],o=()=>{e.clear(),t.clear()},i=f=>{if(!nt(f))return;const{minX:h,minY:y,maxX:m,maxY:g}=f.selector.geometry.bounds,k={minX:h,minY:y,maxX:m,maxY:g,target:f};e.insert(k),t.set(f.annotation,k)},s=f=>{if(!nt(f))return;const h=t.get(f.annotation);h&&e.remove(h),t.delete(f.annotation)};return{all:n,clear:o,getAt:(f,h,y,m=0)=>{const k=e.search({minX:f-m,minY:h-m,maxX:f+m,maxY:h+m}).map(p=>p.target).filter(p=>p.selector.type===J.RECTANGLE||_n(p.selector,f,h,m));return k.length>0?(k.sort((p,S)=>dt(p.selector)-dt(S.selector)),k):[]},getIntersecting:(f,h,y,m)=>e.search({minX:f,minY:h,maxX:f+y,maxY:h+m}).map(g=>g.target),insert:i,remove:s,set:(f,h=!0)=>{h&&o();const y=f.reduce((m,g)=>{if(nt(g)){const{minX:k,minY:p,maxX:S,maxY:E}=g.selector.geometry.bounds;return[...m,{minX:k,minY:p,maxX:S,maxY:E,target:g}]}else return m},[]);y.forEach(m=>t.set(m.target.annotation,m)),e.load(y)},size:()=>e.all().length,update:(f,h)=>{s(f),i(h)}}},Bo=e=>{const t=Vi(),n=Or(),o=ki(t,e.userSelectAction,e.adapter),i=Ai(t),s=zi();return t.observe(({changes:a})=>{n.set((a.created||[]).map(u=>u.target),!1),(a.deleted||[]).forEach(u=>n.remove(u.target)),(a.updated||[]).forEach(({oldValue:u,newValue:d})=>n.update(u.target,d.target))}),{store:{...t,getAt:(a,u,d,f)=>{const h=n.getAt(a,u,d,f);if(d)return h.map(m=>t.getAnnotation(m.annotation)).filter(Boolean).filter(d)[0];{const y=h[0];return y?t.getAnnotation(y.annotation):void 0}},getIntersecting:(a,u,d,f)=>n.getIntersecting(a,u,d,f).map(h=>t.getAnnotation(h.annotation)).filter(Boolean)},selection:o,hover:i,viewport:s}},Ro=e=>{const t=Bo(e);return{...t,store:Xi(t.store)}},Uo=e=>{let t,n;if(e.nodeName==="CANVAS")t=e,n=t.getContext("2d",{willReadFrequently:!0});else{const i=e;t=document.createElement("canvas"),t.width=i.width,t.height=i.height,n=t.getContext("2d",{willReadFrequently:!0}),n.drawImage(i,0,0,i.width,i.height)}let o=0;for(let i=1;i<10;i++)for(let s=1;s<10;s++){const r=Math.round(s*t.width/10),l=Math.round(i*t.height/10),a=n.getImageData(r,l,1,1).data,u=(.299*a[0]+.587*a[1]+.114*a[2])/255;o+=u}return o/81},Vo=e=>{const t=Uo(e),n=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${n} theme.`),n},xt=(e,t,n)=>t.setAttribute("data-theme",n==="auto"?Vo(e):n),Xo=(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}),$t=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Ho=(e,t)=>{const n=t||document,o=r=>{const l=r;l.key==="z"&&l.ctrlKey?e.undo():l.key==="y"&&l.ctrlKey&&e.redo()},i=r=>{const l=r;l.key==="z"&&l.metaKey&&(l.shiftKey?e.redo():e.undo())},s=()=>{$t?n.removeEventListener("keydown",i):n.removeEventListener("keydown",o)};return $t?n.addEventListener("keydown",i):n.addEventListener("keydown",o),{destroy:s}},Dr=(e,t={})=>{if(!e)throw"Missing argument: image";const n=typeof e=="string"?document.getElementById(e):e,o=Xo(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:Nt.EDIT,theme:"light"}),i=Ro(o),{selection:s,store:r}=i,l=ji(r,o.initialHistory),a=Fi(i,l,o.adapter,o.autoSave),u=document.createElement("DIV");u.style.position="relative",u.style.display="inline-block",n.style.display="block",n.parentNode.insertBefore(u,n),u.appendChild(n);const d=Ho(l);let f=ts();xt(n,u,o.theme);const h=new Do({target:u,props:{drawingEnabled:!!o.drawingEnabled,image:n,preferredDrawingMode:o.drawingMode,state:i,style:o.style,user:f}});h.$on("click",w=>{const{originalEvent:v,annotation:_}=w.detail;_?s.userSelect(_.id,v):s.isEmpty()||s.clear()});const y=Ki(i,l,o.adapter),m=()=>h.cancelDrawing(),g=()=>{h.$destroy(),u.parentNode.insertBefore(n,u),u.parentNode.removeChild(u),d.destroy(),l.destroy()},k=()=>h.getDrawingTool(),p=()=>f,S=()=>h.isDrawingEnabled(),E=(w,v,_)=>wo(w,v,_),A=(w,v)=>fo(w,v),M=w=>{if(!Kt(w))throw`No drawing tool named ${w}`;h.$set({toolName:w})},C=w=>h.$set({drawingEnabled:w}),T=w=>{console.warn("Filter not implemented yet")},V=w=>h.$set({style:w}),B=w=>xt(n,u,w),W=w=>{f=w,h.$set({user:w})},q=w=>h.$set({visible:w});return{...y,cancelDrawing:m,destroy:g,getDrawingTool:k,getUser:p,isDrawingEnabled:S,listDrawingTools:qt,on:a.on,off:a.off,registerDrawingTool:E,registerShapeEditor:A,setDrawingEnabled:C,setDrawingTool:M,setFilter:T,setStyle:V,setTheme:B,setUser:W,setVisible:q,element:u,state:i}};D.Editor=_t,D.EditorMount=ho,D.Handle=Xe,D.IdentityTransform=hr,D.PolygonEditor=Qn,D.RectangleEditor=xn,D.RectangleUtil=vn,D.RubberbandRectangle=po,D.SVGAnnotationLayer=Do,D.ShapeType=J,D.ToolMount=go,D.UserSelectAction=Nt,D.W3CImageFormat=ls,D.addEventListeners=So,D.approximateAsPolygon=ht,D.boundsFromMultiPolygonElements=et,D.boundsFromPoints=ue,D.chainStyles=Zi,D.computeArea=dt,D.computePolygonArea=Qe,D.computeSVGPath=It,D.computeStyle=Wi,D.createBody=Ci,D.createImageAnnotator=Dr,D.createImageAnnotatorState=Bo,D.createSVGTransform=vo,D.createSvelteImageAnnotatorState=Ro,D.defaultColorProvider=rs,D.detectTheme=Vo,D.distance=$e,D.enableResponsive=Vn,D.fillDefaults=Xo,D.getAllCorners=wn,D.getEditor=uo,D.getMaskDimensions=ot,D.getSVGPoint=Wt,D.getTool=Kt,D.initKeyboardCommands=Ho,D.intersects=_n,D.isImageAnnotation=tt,D.isImageAnnotationTarget=nt,D.isMac=$t,D.isPointInPolygon=xe,D.isTouch=Le,D.listDrawingTools=qt,D.multipolygonElementToPath=Pe,D.parseFragmentSelector=Sn,D.parseSVGSelector=Pn,D.parseW3CImageAnnotation=Rn,D.pointsToPath=yn,D.registerEditor=fo,D.registerShapeUtil=Ue,D.registerTool=wo,D.sampleBrightness=Uo,D.serializeFragmentSelector=An,D.serializeSVGSelector=Ln,D.serializeW3CImageAnnotation=Un,D.setTheme=xt,D.simplifyMultiPolygon=ri,D.simplifyPoints=Lt,D.simplifyPolygon=ai,Object.defineProperty(D,Symbol.toStringTag,{value:"Module"})});
3
2
  //# sourceMappingURL=annotorious.js.map