@annotorious/openseadragon 3.3.1 → 3.3.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,5 +1,5 @@
1
- (function(Gt,de){typeof exports=="object"&&typeof module<"u"?de(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],de):(Gt=typeof globalThis<"u"?globalThis:Gt||self,de(Gt.AnnotoriousOSD={},Gt.OpenSeadragon))})(this,function(Gt,de){"use strict";var CC=Object.defineProperty;var IC=(Gt,de,Zr)=>de in Gt?CC(Gt,de,{enumerable:!0,configurable:!0,writable:!0,value:Zr}):Gt[de]=Zr;var Pt=(Gt,de,Zr)=>IC(Gt,typeof de!="symbol"?de+"":de,Zr);var Zr=Object.prototype.hasOwnProperty;function Qr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Qr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Zr.call(r,e)&&++i&&!Zr.call(t,e)||!(e in t)||!Qr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var $o=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))($o||{});const oe=[];for(let r=0;r<256;++r)oe.push((r+256).toString(16).slice(1));function Om(r,t=0){return(oe[r[t+0]]+oe[r[t+1]]+oe[r[t+2]]+oe[r[t+3]]+"-"+oe[r[t+4]]+oe[r[t+5]]+"-"+oe[r[t+6]]+oe[r[t+7]]+"-"+oe[r[t+8]]+oe[r[t+9]]+"-"+oe[r[t+10]]+oe[r[t+11]]+oe[r[t+12]]+oe[r[t+13]]+oe[r[t+14]]+oe[r[t+15]]).toLowerCase()}let Ho;const Nm=new Uint8Array(16);function Dm(){if(!Ho){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ho=crypto.getRandomValues.bind(crypto)}return Ho(Nm)}const Lm=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ph={randomUUID:Lm};function Bm(r,t,e){var i;if(Ph.randomUUID&&!r)return Ph.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??Dm();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,Om(s)}const Vo=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},Fm=(r,t,e,i)=>({id:Bm(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),Um=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},km=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Gm=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Qr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),$m=(r,t)=>!Qr(r.target,t.target),Hm=(r,t)=>{const e=Um(r,t),i=km(r,t),s=Gm(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:s.length>0?s:void 0,targetUpdated:$m(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Rr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Rr||{});const Vm=(r,t)=>{const e=new Set((r.created||[]).map(c=>c.id)),i=new Set((r.updated||[]).map(({newValue:c})=>c.id)),s=new Set((t.created||[]).map(c=>c.id)),n=new Set((t.deleted||[]).map(c=>c.id)),o=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>e.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(r.created||[]).filter(c=>!n.has(c.id)).map(c=>o.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],h=[...(r.deleted||[]).filter(c=>!s.has(c.id)),...(t.deleted||[]).filter(c=>!e.has(c.id))],u=[...(r.updated||[]).filter(({newValue:c})=>!n.has(c.id)).map(c=>{const{oldValue:d,newValue:p}=c;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return Hm(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}};let Xm=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,s=e.length;i<s;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(s=>t!==s)}}});const zm=250,Wm=(r,t)=>{const e=Xm(),i=(t==null?void 0:t.changes)||[];let s=t?t.pointer:-1,n=!1,o=0;const a=f=>{if(!n){const{changes:m}=f,y=performance.now();if(y-o>zm)i.splice(s+1),i.push(m),s=i.length-1;else{const _=i.length-1;i[_]=Vm(i[_],m)}o=y}n=!1};r.observe(a,{origin:Rr.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>s,canUndo:()=>s>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:s}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>s){n=!0;const{created:f,updated:m,deleted:y}=i[s+1];h(f),c(m),p(y),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:y}=i[s];l(f),u(m),d(y),e.emit("undo",i[s]),s-=1}}}},Ym=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const x=g.indexOf(v);x!==-1&&g.splice(x,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const b=Array.isArray(v)?v.map(w=>e.serialize(w)):e.serialize(v),S=g?g instanceof PointerEvent?g:e.serialize(g):void 0;x(b,S)}else x(v,g)})},1)},m=()=>{const{selected:_}=n,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const x=h.find(b=>b.id===g.id);(!x||!Qr(x,g))&&f("updateAnnotation",g,x)}),h=h.map(g=>v.find(({id:b})=>b===g.id)||g)};n.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Qr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),g=new Set(_.map(({id:x})=>x));h.filter(x=>!g.has(x.id)).forEach(x=>{const b=o.getAnnotation(x.id);b&&!Qr(b,x)&&f("updateAnnotation",b,x)}),h=[...h.filter(x=>g.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}f("selectionChanged",h)}}),s.subscribe(_=>{!u&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):u&&!_?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(_))),u=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(x=>f("createAnnotation",x)),(g||[]).forEach(x=>f("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:b})=>{const S=h.find(w=>w.id===x.id)||x;h=h.map(w=>w.id===x.id?b:w),f("updateAnnotation",b,S)})},{origin:Rr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),g=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);g.length>0&&(h=h.map(x=>g.find(S=>S.id===x.id)||x))}},{origin:Rr.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(x=>f("updateAnnotation",x.oldValue,x.newValue)):(g||[]).forEach(x=>f("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},jm=r=>t=>t.reduce((e,i)=>{const{parsed:s,error:n}=r.parse(i);return n?{parsed:e.parsed,failed:[...e.failed,i]}:s?{parsed:[...e.parsed,s],failed:e.failed}:{...e}},{parsed:[],failed:[]}),qm=(r,t,e)=>{const{store:i,selection:s}=r,n=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Rr.REMOTE):console.error(g)}else i.addAnnotation(Vo(_),Rr.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var _;const v=(((_=s.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},c=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||jm(e),{parsed:x,failed:b}=g(_);b.length>0&&console.warn(`Discarded ${b.length} invalid annotations`,b),i.bulkAddAnnotations(x,v,Rr.REMOTE)}else i.bulkAddAnnotations(_.map(Vo),v,Rr.REMOTE)},f=(_,v)=>{_?s.setSelected(_,v):s.clear()},m=_=>{s.clear(),s.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(Vo(_)),v}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:u,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Km="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Zm=r=>crypto.getRandomValues(new Uint8Array(r)),Qm=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,s=-~(1.6*i*t/r.length);return(n=t)=>{let o="";for(;;){let a=e(s),l=s|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=n)return o}}},Jm=(r,t=21)=>Qm(r,t|0,Zm),tg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Km[e[r]&63];return t};const eg=()=>({isGuest:!0,id:Jm("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),rg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],ig=()=>{const r=[...rg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};tg();var sg=Object.defineProperty,ng=(r,t,e)=>t in r?sg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ot=(r,t,e)=>ng(r,typeof t!="symbol"?t+"":t,e);function Ct(){}function Xo(r,t){for(const e in t)r[e]=t[e];return r}function Oh(r){return r()}function Nh(){return Object.create(null)}function Ue(r){r.forEach(Oh)}function $t(r){return typeof r=="function"}function te(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function og(r){return Object.keys(r).length===0}function Dh(r,...t){if(r==null){for(const i of t)i(void 0);return Ct}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function zo(r,t,e){r.$$.on_destroy.push(Dh(t,e))}function ag(r,t,e,i){if(r){const s=Lh(r,t,e,i);return r[0](s)}}function Lh(r,t,e,i){return r[1]&&i?Xo(e.ctx.slice(),r[1](i(t))):e.ctx}function lg(r,t,e,i){if(r[2]&&i){const s=r[2](i(e));if(t.dirty===void 0)return s;if(typeof s=="object"){const n=[],o=Math.max(t.dirty.length,s.length);for(let a=0;a<o;a+=1)n[a]=t.dirty[a]|s[a];return n}return t.dirty|s}return t.dirty}function hg(r,t,e,i,s,n){if(s){const o=Lh(t,e,i,n);r.p(o,s)}}function ug(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function Bh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function tn(r){return r??""}function Oe(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function nt(r){r.parentNode&&r.parentNode.removeChild(r)}function Jr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function mt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Fh(r){return document.createTextNode(r)}function ke(){return Fh(" ")}function Ie(){return Fh("")}function Bt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function A(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function cg(r){return Array.from(r.childNodes)}function Mr(r,t,e){r.classList.toggle(t,!!e)}function dg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let fs;function ps(r){fs=r}function Uh(){if(!fs)throw new Error("Function called outside component initialization");return fs}function ms(r){Uh().$$.on_mount.push(r)}function Si(){const r=Uh();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=dg(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function Ne(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ci=[],en=[];let Ii=[];const kh=[],fg=Promise.resolve();let Wo=!1;function pg(){Wo||(Wo=!0,fg.then(Gh))}function Yo(r){Ii.push(r)}const jo=new Set;let Ri=0;function Gh(){if(Ri!==0)return;const r=fs;do{try{for(;Ri<Ci.length;){const t=Ci[Ri];Ri++,ps(t),mg(t.$$)}}catch(t){throw Ci.length=0,Ri=0,t}for(ps(null),Ci.length=0,Ri=0;en.length;)en.pop()();for(let t=0;t<Ii.length;t+=1){const e=Ii[t];jo.has(e)||(jo.add(e),e())}Ii.length=0}while(Ci.length);for(;kh.length;)kh.pop()();Wo=!1,jo.clear(),ps(r)}function mg(r){if(r.fragment!==null){r.update(),Ue(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Yo)}}function gg(r){const t=[],e=[];Ii.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ii=t}const rn=new Set;let ti;function xe(){ti={r:0,c:[],p:ti}}function be(){ti.r||Ue(ti.c),ti=ti.p}function it(r,t){r&&r.i&&(rn.delete(r),r.i(t))}function dt(r,t,e,i){if(r&&r.o){if(rn.has(r))return;rn.add(r),ti.c.push(()=>{rn.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ee(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function _e(r){r&&r.c()}function fe(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),Yo(()=>{const n=r.$$.on_mount.map(Oh).filter($t);r.$$.on_destroy?r.$$.on_destroy.push(...n):Ue(n),r.$$.on_mount=[]}),s.forEach(Yo)}function pe(r,t){const e=r.$$;e.fragment!==null&&(gg(e.after_update),Ue(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function yg(r,t){r.$$.dirty[0]===-1&&(Ci.push(r),pg(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Te(r,t,e,i,s,n,o=null,a=[-1]){const l=fs;ps(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Ct,not_equal:s,bound:Nh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Nh(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let u=!1;if(h.ctx=e?e(r,t.props||{},(c,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&s(h.ctx[c],h.ctx[c]=f)&&(!h.skip_bound&&h.bound[c]&&h.bound[c](f),u&&yg(r,c)),d}):[],h.update(),u=!0,Ue(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=cg(t.target);h.fragment&&h.fragment.l(c),c.forEach(nt)}else h.fragment&&h.fragment.c();t.intro&&it(r.$$.fragment),fe(r,t.target,t.anchor),Gh()}ps(l)}class we{constructor(){Ot(this,"$$"),Ot(this,"$$set")}$destroy(){pe(this,1),this.$destroy=Ct}$on(t,e){if(!$t(e))return Ct;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const s=i.indexOf(e);s!==-1&&i.splice(s,1)}}$set(t){this.$$set&&!og(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const _g="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(_g);var vt=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGLON="MULTIPOLYGON",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(vt||{});const qo={},sn=(r,t)=>qo[r]=t,Ko=r=>qo[r.type].area(r),vg=(r,t,e)=>qo[r.type].intersects(r,t,e),_r=r=>{let t=1/0,e=1/0,i=-1/0,s=-1/0;return r.forEach(([n,o])=>{t=Math.min(t,n),e=Math.min(e,o),i=Math.max(i,n),s=Math.max(s,o)}),{minX:t,minY:e,maxX:i,maxY:s}},Zo=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Qo=(r,t,e)=>{let i=!1;for(let s=0,n=r.length-1;s<r.length;n=s++){const o=r[s][0],a=r[s][1],l=r[n][0],h=r[n][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},xg=(r,t=!0)=>{let e="M ";return r.forEach(([i,s],n)=>{n===0?e+=`${i},${s}`:e+=` L ${i},${s}`}),t&&(e+=" Z"),e},bg={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:s,rx:n,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),u=t-i,c=e-s,d=l*u+h*c,p=h*u-l*c;return d*d/(n*n)+p*p/(o*o)<=1}};sn(vt.ELLIPSE,bg);const Eg={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[s,...n]=i.rings,o=Zo(s.points),a=n.reduce((l,h)=>l+Zo(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const s of i){const[n,...o]=s.rings;if(Qo(n.points,t,e)){let a=!1;for(const l of o)if(Qo(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Tg=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return _r(t)},ei=r=>r.rings.map(t=>xg(t.points)).join(" ");sn(vt.MULTIPOLYGLON,Eg);const wg={area:r=>{const t=r.geometry.points;return Zo(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Qo(i,t,e)}};sn(vt.POLYGON,wg);const Ag={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};sn(vt.RECTANGLE,Ag);const Ge=r=>nn(r.target),nn=r=>{var t,e;return(r==null?void 0:r.annotation)!==void 0&&((e=(t=r==null?void 0:r.selector)==null?void 0:t.geometry)==null?void 0:e.bounds)!==void 0},Sg=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/^(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,s=[...e.matchAll(i)][0],[n,o,a,l,h,u,c]=s;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,p,f,m]=[l,h,u,c].map(parseFloat);return{type:vt.RECTANGLE,geometry:{x:d,y:p,w:f,h:m,bounds:{minX:d,minY:t?p-m:p,maxX:d+f,maxY:t?p:p+m}}}},Cg=r=>{const{x:t,y:e,w:i,h:s}=r;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${e},${i},${s}`}},$h="http://www.w3.org/2000/svg",Hh=r=>{const t=i=>{Array.from(i.attributes).forEach(s=>{s.name.startsWith("on")&&i.removeAttribute(s.name)})},e=r.getElementsByTagName("script");return Array.from(e).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(r.querySelectorAll("*")).forEach(t),r},Ig=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${$h}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},Vh=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix($h),i=t.lookupNamespaceURI(null);return e||i?Hh(t).firstChild:Hh(Ig(t)).firstChild},Xt=" ";function Rg(r){let t="";Array.isArray(r)||(r=[r]);for(let e=0;e<r.length;e++){const i=r[e];if(i.type===B.CLOSE_PATH)t+="z";else if(i.type===B.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===B.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===B.MOVE_TO)t+=(i.relative?"m":"M")+i.x+Xt+i.y;else if(i.type===B.LINE_TO)t+=(i.relative?"l":"L")+i.x+Xt+i.y;else if(i.type===B.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+Xt+i.y1+Xt+i.x2+Xt+i.y2+Xt+i.x+Xt+i.y;else if(i.type===B.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+Xt+i.y2+Xt+i.x+Xt+i.y;else if(i.type===B.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+Xt+i.y1+Xt+i.x+Xt+i.y;else if(i.type===B.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+Xt+i.y;else if(i.type===B.ARC)t+=(i.relative?"a":"A")+i.rX+Xt+i.rY+Xt+i.xRot+Xt+ +i.lArcFlag+Xt+ +i.sweepFlag+Xt+i.x+Xt+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${e}.`)}return t}function Jo([r,t],e){return[r*Math.cos(e)-t*Math.sin(e),r*Math.sin(e)+t*Math.cos(e)]}function $e(...r){for(let t=0;t<r.length;t++)if(typeof r[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof r[t]} == typeof ${r[t]}`);return!0}const Pr=Math.PI;function ta(r,t,e){r.lArcFlag=r.lArcFlag===0?0:1,r.sweepFlag=r.sweepFlag===0?0:1;let{rX:i,rY:s}=r;const{x:n,y:o}=r;if(Math.abs(i)<1e-10||Math.abs(s)<1e-10){r.rX=0,r.rY=0,r.cX=(t+n)/2,r.cY=(e+o)/2,r.phi1=0,r.phi2=0;return}i=Math.abs(r.rX),s=Math.abs(r.rY);const a=r.xRot/180*Pr,[l,h]=Jo([(t-n)/2,(e-o)/2],-a),u=Math.pow(l,2)/Math.pow(i,2)+Math.pow(h,2)/Math.pow(s,2);1<u&&(i*=Math.sqrt(u),s*=Math.sqrt(u)),r.rX=i,r.rY=s;const c=Math.pow(i,2)*Math.pow(h,2)+Math.pow(s,2)*Math.pow(l,2),d=(r.lArcFlag!==r.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(s,2)-c)/c)),p=i*h/s*d,f=-s*l/i*d,m=Jo([p,f],a);r.cX=m[0]+(t+n)/2,r.cY=m[1]+(e+o)/2,r.phi1=Math.atan2((h-f)/s,(l-p)/i),r.phi2=Math.atan2((-h-f)/s,(-l-p)/i),r.sweepFlag===0&&r.phi2>r.phi1&&(r.phi2-=2*Pr),r.sweepFlag===1&&r.phi2<r.phi1&&(r.phi2+=2*Pr),r.phi1*=180/Pr,r.phi2*=180/Pr}function Xh(r,t,e){$e(r,t,e);const i=r*r+t*t-e*e;if(0>i)return[];if(i===0)return[[r*e/(r*r+t*t),t*e/(r*r+t*t)]];const s=Math.sqrt(i);return[[(r*e+t*s)/(r*r+t*t),(t*e-r*s)/(r*r+t*t)],[(r*e-t*s)/(r*r+t*t),(t*e+r*s)/(r*r+t*t)]]}const ri=Math.PI/180;function zh(r,t,e){return(1-e)*r+e*t}function Wh(r,t,e,i){return r+Math.cos(i/180*Pr)*t+Math.sin(i/180*Pr)*e}function Yh(r,t,e,i){const s=t-r,n=e-t,o=i-e,a=3*s+3*o-6*n,l=(n-s)*6,h=3*s;return Math.abs(a)<1e-6?Math.abs(l)<1e-6?[]:[-h/l]:Mg(l/a,h/a,1e-6)}function jh(r,t,e,i,s){const n=1-s,o=n*n*n,a=3*n*n*s,l=3*n*s*s,h=s*s*s;return r*o+t*a+e*l+i*h}function Mg(r,t,e=1e-6){const i=r*r/4-t;if(i<-e)return[];if(i<=e)return[-r/2];const s=Math.sqrt(i);return[-(r/2)-s,-(r/2)+s]}function Pg(r,t,e){r.cX||ta(r,t,e);const i=r.xRot/180*Pr;if(Math.abs(r.rX)<1e-10||Math.abs(r.rY)<1e-10)return[{relative:r.relative,type:B.CURVE_TO,x1:t+(r.x-t)/3,y1:e+(r.y-e)/3,x2:t+2*(r.x-t)/3,y2:e+2*(r.y-e)/3,x:r.x,y:r.y}];const s=Math.min(r.phi1,r.phi2),n=Math.max(r.phi1,r.phi2),o=n-s,a=Math.ceil(o/90),l=new Array(a);let h=t,u=e;const c=(d,p)=>{const[f,m]=Jo([d*r.rX,p*r.rY],i);return[r.cX+f,r.cY+m]};for(let d=0;d<a;d++){const p=zh(r.phi1,r.phi2,d/a),f=zh(r.phi1,r.phi2,(d+1)/a),m=f-p,y=4/3*Math.tan(m*ri/4),_=Math.cos(p*ri)-y*Math.sin(p*ri),v=Math.sin(p*ri)+y*Math.cos(p*ri),g=Math.cos(f*ri),x=Math.sin(f*ri),b=g+y*x,S=x-y*g,w=c(_,v),T=c(b,S),N=c(g,x),F={relative:r.relative,type:B.CURVE_TO,x:N[0],y:N[1],x1:w[0],y1:w[1],x2:T[0],y2:T[1]};r.relative&&(F.x1-=h,F.y1-=u,F.x2-=h,F.y2-=u,F.x-=h,F.y-=u),h=N[0],u=N[1],l[d]=F}return l}function ea(r,t,e){const i=t[0]-r[0],s=t[1]-r[1],n=e[0]-r[0],o=e[1]-r[1],a=i*o-s*n;if(!(Math.abs(a)<1e-10))return!1;const l=i*n+s*o,h=i*i+s*s,u=n*n+o*o;return 0<=l&&l<=u&&h<=u}function Og(r,t=!0){if(r.length<2)return r;const e=zt.INFO((n,o,a)=>({...n,x:n.x??o,y:n.y??a,relative:n.relative??!1})),i=[];let s=[];for(const n of r){const o=e(n);o.type===B.MOVE_TO&&s.length>0&&(t?i.push(...on(s)):i.unshift(...on(s)),s=[]),s.push(o)}return s.length>0&&(t?i.push(...on(s)):i.unshift(...on(s))),i}function on(r){var t;const e=((t=r[r.length-1])==null?void 0:t.type)===B.CLOSE_PATH,i=e?r.length-2:r.length-1,s=[{type:B.MOVE_TO,relative:!1,x:r[i].x,y:r[i].y}];for(let n=i;n>0;n--){const o=r[n],a=r[n-1];if(o.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(o.type){case B.HORIZ_LINE_TO:s.push({type:B.HORIZ_LINE_TO,relative:!1,x:a.x});break;case B.VERT_LINE_TO:s.push({type:B.VERT_LINE_TO,relative:!1,y:a.y});break;case B.LINE_TO:case B.MOVE_TO:s.push({type:B.LINE_TO,relative:!1,x:a.x,y:a.y});break;case B.CURVE_TO:s.push({type:B.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:o.x2,y1:o.y2,x2:o.x1,y2:o.y1});break;case B.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case B.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case B.ARC:throw new Error("Unsupported command: A (arc)");case B.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return e&&s.push({type:B.CLOSE_PATH}),s}function Ng(r=1e13){$e(r);function t(e){return Math.round(e*r)/r}return function(e){return"x1"in e&&typeof e.x1<"u"&&(e.x1=t(e.x1)),"y1"in e&&typeof e.y1<"u"&&(e.y1=t(e.y1)),"x2"in e&&typeof e.x2<"u"&&(e.x2=t(e.x2)),"y2"in e&&typeof e.y2<"u"&&(e.y2=t(e.y2)),"x"in e&&typeof e.x<"u"&&(e.x=t(e.x)),"y"in e&&typeof e.y<"u"&&(e.y=t(e.y)),"rX"in e&&typeof e.rX<"u"&&(e.rX=t(e.rX)),"rY"in e&&typeof e.rY<"u"&&(e.rY=t(e.rY)),e}}function qh(){return He((r,t,e)=>(r.relative&&(typeof r.x1<"u"&&(r.x1+=t),typeof r.y1<"u"&&(r.y1+=e),typeof r.x2<"u"&&(r.x2+=t),typeof r.y2<"u"&&(r.y2+=e),typeof r.x<"u"&&(r.x+=t),typeof r.y<"u"&&(r.y+=e),r.relative=!1),r))}function Dg(){return He((r,t,e)=>(r.relative||(typeof r.x1<"u"&&(r.x1-=t),typeof r.y1<"u"&&(r.y1-=e),typeof r.x2<"u"&&(r.x2-=t),typeof r.y2<"u"&&(r.y2-=e),typeof r.x<"u"&&(r.x-=t),typeof r.y<"u"&&(r.y-=e),r.relative=!0),r))}function Lg(r=!0,t=!0,e=!0,i=!0){return He((s,n,o,a,l)=>{if(isNaN(a)&&!(s.type&B.MOVE_TO))throw new Error("path must start with moveto");if(t&&s.type&B.HORIZ_LINE_TO&&(s.type=B.LINE_TO,s.y=s.relative?0:o),e&&s.type&B.VERT_LINE_TO&&(s.type=B.LINE_TO,s.x=s.relative?0:n),r&&s.type&B.CLOSE_PATH&&(s.type=B.LINE_TO,s.x=s.relative?a-n:a,s.y=s.relative?l-o:l),s.type&B.ARC&&(s.rX===0||s.rY===0)&&(s.type=B.LINE_TO,delete s.rX,delete s.rY,delete s.xRot,delete s.lArcFlag,delete s.sweepFlag),i&&s.type&B.QUAD_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x,o+s.y]:[s.x,s.y];ea(h,u,c)&&(s.type=B.LINE_TO,delete s.x1,delete s.y1)}if(i&&s.type&B.CURVE_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x2,o+s.y2]:[s.x2,s.y2],d=s.relative?[n+s.x,o+s.y]:[s.x,s.y];ea(h,u,d)&&ea(h,c,d)&&(s.type=B.LINE_TO,delete s.x1,delete s.y1,delete s.x2,delete s.y2)}return s})}function Kh(){let r=NaN,t=NaN,e=NaN,i=NaN;return He((s,n,o)=>(s.type&B.SMOOTH_CURVE_TO&&(s.type=B.CURVE_TO,r=isNaN(r)?n:r,t=isNaN(t)?o:t,s.x1=s.relative?n-r:2*n-r,s.y1=s.relative?o-t:2*o-t),s.type&B.CURVE_TO?(r=s.relative?n+s.x2:s.x2,t=s.relative?o+s.y2:s.y2):(r=NaN,t=NaN),s.type&B.SMOOTH_QUAD_TO&&(s.type=B.QUAD_TO,e=isNaN(e)?n:e,i=isNaN(i)?o:i,s.x1=s.relative?n-e:2*n-e,s.y1=s.relative?o-i:2*o-i),s.type&B.QUAD_TO?(e=s.relative?n+s.x1:s.x1,i=s.relative?o+s.y1:s.y1):(e=NaN,i=NaN),s))}function Zh(){let r=NaN,t=NaN;return He((e,i,s)=>{if(e.type&B.SMOOTH_QUAD_TO&&(e.type=B.QUAD_TO,r=isNaN(r)?i:r,t=isNaN(t)?s:t,e.x1=e.relative?i-r:2*i-r,e.y1=e.relative?s-t:2*s-t),e.type&B.QUAD_TO){r=e.relative?i+e.x1:e.x1,t=e.relative?s+e.y1:e.y1;const n=e.x1,o=e.y1;e.type=B.CURVE_TO,e.x1=((e.relative?0:i)+n*2)/3,e.y1=((e.relative?0:s)+o*2)/3,e.x2=(e.x+n*2)/3,e.y2=(e.y+o*2)/3}else r=NaN,t=NaN;return e})}function He(r){let t=0,e=0,i=NaN,s=NaN;return function(n){if(isNaN(i)&&!(n.type&B.MOVE_TO))throw new Error("path must start with moveto");const o=r(n,t,e,i,s);return n.type&B.CLOSE_PATH&&(t=i,e=s),"x"in n&&typeof n.x<"u"&&(t=n.relative?t+n.x:n.x),"y"in n&&typeof n.y<"u"&&(e=n.relative?e+n.y:n.y),n.type&B.MOVE_TO&&(i=t,s=e),o}}function Bg(r=0){$e(r);let t=NaN,e=NaN,i=NaN,s=NaN;return He((n,o,a,l,h)=>{const u=Math.abs;let c=!1,d=0,p=0;if(n.type&B.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:o-t,p=isNaN(e)?0:a-e),n.type&(B.CURVE_TO|B.SMOOTH_CURVE_TO)?(t=n.relative?o+n.x2:n.x2,e=n.relative?a+n.y2:n.y2):(t=NaN,e=NaN),n.type&B.SMOOTH_QUAD_TO?(i=isNaN(i)?o:2*o-i,s=isNaN(s)?a:2*a-s):n.type&B.QUAD_TO?(i=n.relative?o+n.x1:n.x1,s=n.relative?a+n.y1:n.y2):(i=NaN,s=NaN),n.type&B.LINE_COMMANDS||n.type&B.ARC&&(n.rX===0||n.rY===0||!n.lArcFlag)||n.type&B.CURVE_TO||n.type&B.SMOOTH_CURVE_TO||n.type&B.QUAD_TO||n.type&B.SMOOTH_QUAD_TO){const f=typeof n.x>"u"?0:n.relative?n.x:n.x-o,m=typeof n.y>"u"?0:n.relative?n.y:n.y-a;d=isNaN(i)?typeof n.x1>"u"?d:n.relative?n.x:n.x1-o:i-o,p=isNaN(s)?typeof n.y1>"u"?p:n.relative?n.y:n.y1-a:s-a;const y=typeof n.x2>"u"?0:n.relative?n.x:n.x2-o,_=typeof n.y2>"u"?0:n.relative?n.y:n.y2-a;u(f)<=r&&u(m)<=r&&u(d)<=r&&u(p)<=r&&u(y)<=r&&u(_)<=r&&(c=!0)}return n.type&B.CLOSE_PATH&&u(o-l)<=r&&u(a-h)<=r&&(c=!0),c?[]:n})}function Or(r,t,e,i,s,n){return $e(r,t,e,i,s,n),He((o,a,l,h)=>{const u=o.x1,c=o.x2,d=o.relative&&!isNaN(h),p=typeof o.x<"u"?o.x:d?0:a,f=typeof o.y<"u"?o.y:d?0:l;o.type&B.HORIZ_LINE_TO&&t!==0&&(o.type=B.LINE_TO,o.y=o.relative?0:l),o.type&B.VERT_LINE_TO&&e!==0&&(o.type=B.LINE_TO,o.x=o.relative?0:a),typeof o.x<"u"&&(o.x=o.x*r+f*e+(d?0:s)),typeof o.y<"u"&&(o.y=p*t+o.y*i+(d?0:n)),typeof o.x1<"u"&&(o.x1=o.x1*r+o.y1*e+(d?0:s)),typeof o.y1<"u"&&(o.y1=u*t+o.y1*i+(d?0:n)),typeof o.x2<"u"&&(o.x2=o.x2*r+o.y2*e+(d?0:s)),typeof o.y2<"u"&&(o.y2=c*t+o.y2*i+(d?0:n));function m(_){return _*_}const y=r*i-t*e;if(typeof o.xRot<"u"&&(r!==1||t!==0||e!==0||i!==1))if(y===0)delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag,o.type=B.LINE_TO;else{const _=o.xRot*Math.PI/180,v=Math.sin(_),g=Math.cos(_),x=1/m(o.rX),b=1/m(o.rY),S=m(g)*x+m(v)*b,w=2*v*g*(x-b),T=m(v)*x+m(g)*b,N=S*i*i-w*t*i+T*t*t,F=w*(r*i+t*e)-2*(S*e*i+T*r*t),z=S*e*e-w*r*e+T*r*r,C=(Math.atan2(F,N-z)+Math.PI)%Math.PI/2,E=Math.sin(C),I=Math.cos(C);o.rX=Math.abs(y)/Math.sqrt(N*m(I)+F*E*I+z*m(E)),o.rY=Math.abs(y)/Math.sqrt(N*m(E)-F*E*I+z*m(I)),o.xRot=C*180/Math.PI}return typeof o.sweepFlag<"u"&&0>y&&(o.sweepFlag=+!o.sweepFlag),o})}function Fg(r,t=0,e=0){$e(r,t,e);const i=Math.sin(r),s=Math.cos(r);return Or(s,i,-i,s,t-t*s+e*i,e-t*i-e*s)}function Ug(r,t=0){return $e(r,t),Or(1,0,0,1,r,t)}function kg(r,t=r){return $e(r,t),Or(r,0,0,t,0,0)}function Gg(r){return $e(r),Or(1,0,Math.tan(r),1,0,0)}function $g(r){return $e(r),Or(1,Math.tan(r),0,1,0,0)}function Hg(r=0){return $e(r),Or(-1,0,0,1,r,0)}function Vg(r=0){return $e(r),Or(1,0,0,-1,0,r)}function Xg(){return He((r,t,e)=>B.ARC===r.type?Pg(r,r.relative?0:t,r.relative?0:e):r)}function zg(){return He((r,t,e)=>(r.relative&&(t=0,e=0),B.ARC===r.type&&ta(r,t,e),r))}function Qh(){return r=>({...r})}function Wg(){const r=Qh(),t=qh(),e=Zh(),i=Kh(),s=He((n,o,a)=>{const l=i(e(t(r(n))));function h(c){c>s.maxX&&(s.maxX=c),c<s.minX&&(s.minX=c)}function u(c){c>s.maxY&&(s.maxY=c),c<s.minY&&(s.minY=c)}if(l.type&B.DRAWING_COMMANDS&&(h(o),u(a)),l.type&B.HORIZ_LINE_TO&&h(l.x),l.type&B.VERT_LINE_TO&&u(l.y),l.type&B.LINE_TO&&(h(l.x),u(l.y)),l.type&B.CURVE_TO){h(l.x),u(l.y);const c=Yh(o,l.x1,l.x2,l.x);for(const p of c)0<p&&1>p&&h(jh(o,l.x1,l.x2,l.x,p));const d=Yh(a,l.y1,l.y2,l.y);for(const p of d)0<p&&1>p&&u(jh(a,l.y1,l.y2,l.y,p))}if(l.type&B.ARC){h(l.x),u(l.y),ta(l,o,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,p=Math.sin(c)*l.rX,f=-Math.sin(c)*l.rY,m=Math.cos(c)*l.rY,[y,_]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],v=([b,S])=>{const w=Math.atan2(S,b)*180/Math.PI;return w<y?w+360:w},g=Xh(f,-d,0).map(v);for(const b of g)b>y&&b<_&&h(Wh(l.cX,d,f,b));const x=Xh(m,-p,0).map(v);for(const b of x)b>y&&b<_&&u(Wh(l.cY,p,m,b))}return n});return s.minX=1/0,s.maxX=-1/0,s.minY=1/0,s.maxY=-1/0,s}const zt={ROUND:Ng,TO_ABS:qh,TO_REL:Dg,NORMALIZE_HVZ:Lg,NORMALIZE_ST:Kh,QT_TO_C:Zh,INFO:He,SANITIZE:Bg,MATRIX:Or,ROTATE:Fg,TRANSLATE:Ug,SCALE:kg,SKEW_X:Gg,SKEW_Y:$g,X_AXIS_SYMMETRY:Hg,Y_AXIS_SYMMETRY:Vg,A_TO_C:Xg,ANNOTATE_ARCS:zg,CLONE:Qh,CALCULATE_BOUNDS:Wg,REVERSE_PATH:Og};class Jh{round(t){return this.transform(zt.ROUND(t))}toAbs(){return this.transform(zt.TO_ABS())}toRel(){return this.transform(zt.TO_REL())}normalizeHVZ(t,e,i){return this.transform(zt.NORMALIZE_HVZ(t,e,i))}normalizeST(){return this.transform(zt.NORMALIZE_ST())}qtToC(){return this.transform(zt.QT_TO_C())}aToC(){return this.transform(zt.A_TO_C())}sanitize(t){return this.transform(zt.SANITIZE(t))}translate(t,e){return this.transform(zt.TRANSLATE(t,e))}scale(t,e){return this.transform(zt.SCALE(t,e))}rotate(t,e,i){return this.transform(zt.ROTATE(t,e,i))}matrix(t,e,i,s,n,o){return this.transform(zt.MATRIX(t,e,i,s,n,o))}skewX(t){return this.transform(zt.SKEW_X(t))}skewY(t){return this.transform(zt.SKEW_Y(t))}xSymmetry(t){return this.transform(zt.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(zt.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(zt.ANNOTATE_ARCS())}}const Yg=r=>r===" "||r===" "||r==="\r"||r===`
2
- `,tu=r=>48<=r.charCodeAt(0)&&r.charCodeAt(0)<=57;class jg extends Jh{constructor(){super(),Ot(this,"curNumber",""),Ot(this,"curCommandType",-1),Ot(this,"curCommandRelative",!1),Ot(this,"canParseCommandOrComma",!0),Ot(this,"curNumberHasExp",!1),Ot(this,"curNumberHasExpDigits",!1),Ot(this,"curNumberHasDecimal",!1),Ot(this,"curArgs",[])}finish(t=[]){if(this.parse(" ",t),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return t}parse(t,e=[]){const i=s=>{e.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<t.length;s++){const n=t[s],o=this.curCommandType===B.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),a=tu(n)&&(this.curNumber==="0"&&n==="0"||o);if(tu(n)&&!a){this.curNumber+=n,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(n==="e"||n==="E"){this.curNumber+=n,this.curNumberHasExp=!0;continue}if((n==="-"||n==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=n;continue}if(n==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!o){this.curNumber+=n,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const l=Number(this.curNumber);if(isNaN(l))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===B.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>l)throw new SyntaxError(`Expected positive number, got "${l}" 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(l),this.curArgs.length===qg[this.curCommandType]&&(B.HORIZ_LINE_TO===this.curCommandType?i({type:B.HORIZ_LINE_TO,relative:this.curCommandRelative,x:l}):B.VERT_LINE_TO===this.curCommandType?i({type:B.VERT_LINE_TO,relative:this.curCommandRelative,y:l}):this.curCommandType===B.MOVE_TO||this.curCommandType===B.LINE_TO||this.curCommandType===B.SMOOTH_QUAD_TO?(i({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),B.MOVE_TO===this.curCommandType&&(this.curCommandType=B.LINE_TO)):this.curCommandType===B.CURVE_TO?i({type:B.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===B.SMOOTH_CURVE_TO?i({type:B.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===B.QUAD_TO?i({type:B.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===B.ARC&&i({type:B.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(!Yg(n)){if(n===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(n==="+"||n==="-"||n==="."){this.curNumber=n,this.curNumberHasDecimal=n===".";continue}if(a){this.curNumber=n,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 "${n}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,n==="z"||n==="Z"){e.push({type:B.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(n==="h"||n==="H")this.curCommandType=B.HORIZ_LINE_TO,this.curCommandRelative=n==="h";else if(n==="v"||n==="V")this.curCommandType=B.VERT_LINE_TO,this.curCommandRelative=n==="v";else if(n==="m"||n==="M")this.curCommandType=B.MOVE_TO,this.curCommandRelative=n==="m";else if(n==="l"||n==="L")this.curCommandType=B.LINE_TO,this.curCommandRelative=n==="l";else if(n==="c"||n==="C")this.curCommandType=B.CURVE_TO,this.curCommandRelative=n==="c";else if(n==="s"||n==="S")this.curCommandType=B.SMOOTH_CURVE_TO,this.curCommandRelative=n==="s";else if(n==="q"||n==="Q")this.curCommandType=B.QUAD_TO,this.curCommandRelative=n==="q";else if(n==="t"||n==="T")this.curCommandType=B.SMOOTH_QUAD_TO,this.curCommandRelative=n==="t";else if(n==="a"||n==="A")this.curCommandType=B.ARC,this.curCommandRelative=n==="a";else throw new SyntaxError(`Unexpected character "${n}" at index ${s}.`)}}return e}transform(t){return Object.create(this,{parse:{value(e,i=[]){const s=Object.getPrototypeOf(this).parse.call(this,e);for(const n of s){const o=t(n);Array.isArray(o)?i.push(...o):i.push(o)}return i}}})}}const Mt=class Th extends Jh{constructor(t){super(),Ot(this,"commands"),typeof t=="string"?this.commands=Th.parse(t):this.commands=t}encode(){return Th.encode(this.commands)}getBounds(){const t=zt.CALCULATE_BOUNDS();return this.transform(t),t}transform(t){const e=[];for(const i of this.commands){const s=t(i);Array.isArray(s)?e.push(...s):e.push(s)}return this.commands=e,this}reverse(t=!0){return this.commands=zt.REVERSE_PATH(this.commands,t),this}static encode(t){return Rg(t)}static parse(t){const e=new jg,i=[];return e.parse(t,i),e.finish(i),i}};Ot(Mt,"CLOSE_PATH",1),Ot(Mt,"MOVE_TO",2),Ot(Mt,"HORIZ_LINE_TO",4),Ot(Mt,"VERT_LINE_TO",8),Ot(Mt,"LINE_TO",16),Ot(Mt,"CURVE_TO",32),Ot(Mt,"SMOOTH_CURVE_TO",64),Ot(Mt,"QUAD_TO",128),Ot(Mt,"SMOOTH_QUAD_TO",256),Ot(Mt,"ARC",512),Ot(Mt,"LINE_COMMANDS",Mt.LINE_TO|Mt.HORIZ_LINE_TO|Mt.VERT_LINE_TO),Ot(Mt,"DRAWING_COMMANDS",Mt.HORIZ_LINE_TO|Mt.VERT_LINE_TO|Mt.LINE_TO|Mt.CURVE_TO|Mt.SMOOTH_CURVE_TO|Mt.QUAD_TO|Mt.SMOOTH_QUAD_TO|Mt.ARC);let B=Mt;const qg={[B.MOVE_TO]:2,[B.LINE_TO]:2,[B.HORIZ_LINE_TO]:1,[B.VERT_LINE_TO]:1,[B.CLOSE_PATH]:0,[B.QUAD_TO]:4,[B.SMOOTH_QUAD_TO]:2,[B.CURVE_TO]:6,[B.SMOOTH_CURVE_TO]:4,[B.ARC]:7},Kg=r=>{const t=new B(r).toAbs().commands,e=[];let i=[],s=null;for(const n of t)switch(n.type){case B.MOVE_TO:i.length>0&&(e.push({points:i}),i=[]),s=[n.x,n.y],i.push(s);break;case B.LINE_TO:i.push([n.x,n.y]);break;case B.HORIZ_LINE_TO:const o=i[i.length-1][1];i.push([n.x,o]);break;case B.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,n.y]);break;case B.CURVE_TO:case B.SMOOTH_CURVE_TO:case B.QUAD_TO:case B.SMOOTH_QUAD_TO:case B.ARC:i.push([n.x,n.y]);break}if(i.length>2&&e.push({points:i}),e.length>0){const n=_r(e[0].points);return{rings:e,bounds:n}}},Zg=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],s=i.split(" ").map(n=>n.split(",").map(parseFloat));return{type:vt.POLYGON,geometry:{points:s,bounds:_r(s)}}},Qg=r=>{const t=Vh(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),s=parseFloat(t.getAttribute("rx")),n=parseFloat(t.getAttribute("ry")),o={minX:e-s,minY:i-n,maxX:e+s,maxY:i+n};return{type:vt.ELLIPSE,geometry:{cx:e,cy:i,rx:s,ry:n,bounds:o}}},Jg=r=>{const t=Vh(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(n=>n.getAttribute("d")||"").map(n=>Kg(n)).filter(Boolean),i=e.reduce((n,o)=>[...n,...o.rings[0].points],[]),s=_r(i);return e.length===1&&e[0].rings.length===1?{type:vt.POLYGON,geometry:{points:i,bounds:s}}:{type:vt.MULTIPOLYGLON,geometry:{polygons:e,bounds:s}}},ty=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return Zg(t);if(t.includes("<path "))return Jg(t);if(t.includes("<ellipse "))return Qg(t);throw"Unsupported SVG shape: "+t},ey=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${ei(t)}" />`).join("")}</g>`,ry=r=>{let t;if(r.type===vt.POLYGON){const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(s=>s.join(",")).join(" ")}" /></svg>`}else if(r.type===vt.ELLIPSE){const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`}else if(r.type===vt.MULTIPOLYGLON){const e=r.geometry;t=`<svg>${ey(e)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ae=[];for(let r=0;r<256;++r)ae.push((r+256).toString(16).slice(1));function iy(r,t=0){return(ae[r[t+0]]+ae[r[t+1]]+ae[r[t+2]]+ae[r[t+3]]+"-"+ae[r[t+4]]+ae[r[t+5]]+"-"+ae[r[t+6]]+ae[r[t+7]]+"-"+ae[r[t+8]]+ae[r[t+9]]+"-"+ae[r[t+10]]+ae[r[t+11]]+ae[r[t+12]]+ae[r[t+13]]+ae[r[t+14]]+ae[r[t+15]]).toLowerCase()}let ra;const sy=new Uint8Array(16);function ny(){if(!ra){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ra=crypto.getRandomValues.bind(crypto)}return ra(sy)}const oy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),eu={randomUUID:oy};function ru(r,t,e){var i;if(eu.randomUUID&&!r)return eu.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??ny();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,iy(s)}var iu=Object.prototype.hasOwnProperty;function Nr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Nr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(iu.call(r,e)&&++i&&!iu.call(t,e)||!(e in t)||!Nr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function ia(){}function ay(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const Mi=[];function sa(r,t=ia){let e;const i=new Set;function s(a){if(ay(r,a)&&(r=a,e)){const l=!Mi.length;for(const h of i)h[1](),Mi.push(h,r);if(l){for(let h=0;h<Mi.length;h+=2)Mi[h][0](Mi[h+1]);Mi.length=0}}}function n(a){s(a(r))}function o(a,l=ia){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||ia),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const ly=r=>{const{subscribe:t,set:e}=sa();let i;return t(s=>i=s),r.observe(({changes:s})=>{if(i){(s.deleted||[]).some(o=>o.id===i)&&e(void 0);const n=(s.updated||[]).find(({oldValue:o})=>o.id===i);n&&e(n.newValue.id)}}),{get current(){return i},subscribe:t,set:e}};var su=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(su||{});const an={selected:[]},hy=(r,t,e)=>{const{subscribe:i,set:s}=sa(an);let n=t,o=an;i(f=>o=f);const a=()=>{Nr(o,an)||s(an)},l=()=>{var f;return((f=o.selected)==null?void 0:f.length)===0},h=f=>{if(l())return!1;const m=typeof f=="string"?f:f.id;return o.selected.some(y=>y.id===m)},u=(f,m)=>{let y;if(Array.isArray(f)){if(y=f.map(v=>r.getAnnotation(v)).filter(Boolean),y.length<f.length){console.warn("Invalid selection: "+f.filter(v=>!y.some(g=>g.id===v)));return}}else{const v=r.getAnnotation(f);if(!v){console.warn("Invalid selection: "+f);return}y=[v]}const _=y.reduce((v,g)=>{const x=nu(g,n,e);return x==="EDIT"?[...v,{id:g.id,editable:!0}]:x==="SELECT"?[...v,{id:g.id}]:v},[]);s({selected:_,event:m})},c=(f,m)=>{const y=Array.isArray(f)?f:[f],_=y.map(v=>r.getAnnotation(v)).filter(v=>!!v);s({selected:_.map(v=>{const g=m===void 0?nu(v,n,e)==="EDIT":m;return{id:v.id,editable:g}})}),_.length!==y.length&&console.warn("Invalid selection",f)},d=f=>{if(l())return!1;const{selected:m}=o;m.some(({id:y})=>f.includes(y))&&s({selected:m.filter(({id:y})=>!f.includes(y))})},p=f=>{n=f,c(o.selected.map(({id:m})=>m))};return r.observe(({changes:f})=>d((f.deleted||[]).map(m=>m.id))),{get event(){return o?o.event:null},get selected(){return o?[...o.selected]:null},get userSelectAction(){return n},clear:a,isEmpty:l,isSelected:h,setSelected:c,setUserSelectAction:p,subscribe:i,userSelect:u}},nu=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},le=[];for(let r=0;r<256;++r)le.push((r+256).toString(16).slice(1));function uy(r,t=0){return(le[r[t+0]]+le[r[t+1]]+le[r[t+2]]+le[r[t+3]]+"-"+le[r[t+4]]+le[r[t+5]]+"-"+le[r[t+6]]+le[r[t+7]]+"-"+le[r[t+8]]+le[r[t+9]]+"-"+le[r[t+10]]+le[r[t+11]]+le[r[t+12]]+le[r[t+13]]+le[r[t+14]]+le[r[t+15]]).toLowerCase()}let na;const cy=new Uint8Array(16);function dy(){if(!na){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");na=crypto.getRandomValues.bind(crypto)}return na(cy)}const fy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ou={randomUUID:fy};function py(r,t,e){var i;if(ou.randomUUID&&!r)return ou.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??dy();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,uy(s)}const oa=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},my=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},gy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},yy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Nr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),_y=(r,t)=>!Nr(r.target,t.target),au=(r,t)=>{const e=my(r,t),i=gy(r,t),s=yy(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:s.length>0?s:void 0,targetUpdated:_y(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var It=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(It||{});const vy=(r,t)=>{var e,i;const{changes:s,origin:n}=t;if(!(r.options.origin?r.options.origin===n:n!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(s.created)||a(s.deleted))){const l=(e=s.updated)==null?void 0:e.some(u=>a(u.bodiesCreated)||a(u.bodiesDeleted)||a(u.bodiesUpdated)),h=(i=s.updated)==null?void 0:i.some(u=>u.targetUpdated);if(o==="BODY_ONLY"&&l&&!h||o==="TARGET_ONLY"&&h&&!l)return!1}}if(r.options.annotations){const o=new Set([...(s.created||[]).map(a=>a.id),...(s.deleted||[]).map(a=>a.id),...(s.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(r.options.annotations)?r.options.annotations:[r.options.annotations]).find(a=>o.has(a))}else return!0},xy=(r,t)=>{const e=new Set((r.created||[]).map(c=>c.id)),i=new Set((r.updated||[]).map(({newValue:c})=>c.id)),s=new Set((t.created||[]).map(c=>c.id)),n=new Set((t.deleted||[]).map(c=>c.id)),o=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>e.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(r.created||[]).filter(c=>!n.has(c.id)).map(c=>o.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],h=[...(r.deleted||[]).filter(c=>!s.has(c.id)),...(t.deleted||[]).filter(c=>!e.has(c.id))],u=[...(r.updated||[]).filter(({newValue:c})=>!n.has(c.id)).map(c=>{const{oldValue:d,newValue:p}=c;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return au(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}},ln=r=>{const t=r.id===void 0?py():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},by=r=>r.id!==void 0,Ey=()=>{const r=new Map,t=new Map,e=[],i=(C,E={})=>{e.push({onChange:C,options:E})},s=C=>{const E=e.findIndex(I=>I.onChange==C);E>-1&&e.splice(E,1)},n=(C,E)=>{const I={origin:C,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...r.values()]};e.forEach(P=>{vy(P,I)&&P.onChange(I)})},o=(C,E=It.LOCAL)=>{if(C.id&&r.get(C.id))throw Error(`Cannot add annotation ${C.id} - exists already`);{const I=ln(C);r.set(I.id,I),I.bodies.forEach(P=>t.set(P.id,I.id)),n(E,{created:[I]})}},a=(C,E)=>{const I=ln(typeof C=="string"?E:C),P=typeof C=="string"?C:C.id,$=P&&r.get(P);if($){const k=au($,I);return P===I.id?r.set(P,I):(r.delete(P),r.set(I.id,I)),$.bodies.forEach(G=>t.delete(G.id)),I.bodies.forEach(G=>t.set(G.id,I.id)),k}else console.warn(`Cannot update annotation ${P} - does not exist`)},l=(C,E=It.LOCAL,I=It.LOCAL)=>{const P=by(E)?I:E,$=a(C,E);$&&n(P,{updated:[$]})},h=(C,E=It.LOCAL)=>{r.get(C.id)?l(C,E):o(C,E)},u=(C,E=It.LOCAL)=>{const I=C.reduce((P,$)=>{const k=a($);return k?[...P,k]:P},[]);I.length>0&&n(E,{updated:I})},c=(C,E=It.LOCAL)=>{const I=C.map(ln),{toAdd:P,toUpdate:$}=I.reduce((G,st)=>r.get(st.id)?{...G,toUpdate:[...G.toUpdate,st]}:{...G,toAdd:[...G.toAdd,st]},{toAdd:[],toUpdate:[]}),k=$.map(G=>a(G,E)).filter(Boolean);P.forEach(G=>{r.set(G.id,G),G.bodies.forEach(st=>t.set(st.id,G.id))}),n(E,{created:P,updated:k})},d=(C,E=It.LOCAL)=>{const I=r.get(C.annotation);if(I){const P={...I,bodies:[...I.bodies,C]};r.set(I.id,P),t.set(C.id,P.id),n(E,{updated:[{oldValue:I,newValue:P,bodiesCreated:[C]}]})}else console.warn(`Attempt to add body to missing annotation: ${C.annotation}`)},p=()=>[...r.values()],f=(C=It.LOCAL)=>{const E=[...r.values()];r.clear(),t.clear(),n(C,{deleted:E})},m=(C,E=!0,I=It.LOCAL)=>{const P=C.map(ln);if(E){const $=[...r.values()];r.clear(),t.clear(),P.forEach(k=>{r.set(k.id,k),k.bodies.forEach(G=>t.set(G.id,k.id))}),n(I,{created:P,deleted:$})}else{const $=C.reduce((k,G)=>{const st=G.id&&r.get(G.id);return st?[...k,st]:k},[]);if($.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${$.map(k=>k.id).join(", ")}`);P.forEach(k=>{r.set(k.id,k),k.bodies.forEach(G=>t.set(G.id,k.id))}),n(I,{created:P})}},y=C=>{const E=typeof C=="string"?C:C.id,I=r.get(E);if(I)return r.delete(E),I.bodies.forEach(P=>t.delete(P.id)),I;console.warn(`Attempt to delete missing annotation: ${E}`)},_=(C,E=It.LOCAL)=>{const I=y(C);I&&n(E,{deleted:[I]})},v=(C,E=It.LOCAL)=>{const I=C.reduce((P,$)=>{const k=y($);return k?[...P,k]:P},[]);I.length>0&&n(E,{deleted:I})},g=C=>{const E=r.get(C.annotation);if(E){const I=E.bodies.find(P=>P.id===C.id);if(I){t.delete(I.id);const P={...E,bodies:E.bodies.filter($=>$.id!==C.id)};return r.set(E.id,P),{oldValue:E,newValue:P,bodiesDeleted:[I]}}else console.warn(`Attempt to delete missing body ${C.id} from annotation ${C.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${C.annotation}`)},x=(C,E=It.LOCAL)=>{const I=g(C);I&&n(E,{updated:[I]})},b=(C,E=It.LOCAL)=>{const I=C.map(P=>g(P)).filter(Boolean);I.length>0&&n(E,{updated:I})},S=C=>{const E=r.get(C);return E?{...E}:void 0},w=C=>{const E=t.get(C);if(E){const I=S(E).bodies.find(P=>P.id===C);if(I)return I;console.error(`Store integrity error: body ${C} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${C}`)},T=(C,E)=>{if(C.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const I=r.get(C.annotation);if(I){const P=I.bodies.find(k=>k.id===C.id),$={...I,bodies:I.bodies.map(k=>k.id===P.id?E:k)};return r.set(I.id,$),P.id!==E.id&&(t.delete(P.id),t.set(E.id,$.id)),{oldValue:I,newValue:$,bodiesUpdated:[{oldBody:P,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${C.annotation}`)},N=(C,E,I=It.LOCAL)=>{const P=T(C,E);P&&n(I,{updated:[P]})},F=(C,E=It.LOCAL)=>{const I=C.map(P=>T({id:P.id,annotation:P.annotation},P)).filter(Boolean);n(E,{updated:I})},z=C=>{const E=r.get(C.annotation);if(E){const I={...E,target:{...E.target,...C}};return r.set(E.id,I),{oldValue:E,newValue:I,targetUpdated:{oldTarget:E.target,newTarget:C}}}else console.warn(`Attempt to update target on missing annotation: ${C.annotation}`)};return{addAnnotation:o,addBody:d,all:p,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:b,bulkUpdateAnnotations:u,bulkUpdateBodies:F,bulkUpdateTargets:(C,E=It.LOCAL)=>{const I=C.map(P=>z(P)).filter(Boolean);I.length>0&&n(E,{updated:I})},bulkUpsertAnnotations:c,clear:f,deleteAnnotation:_,deleteBody:x,getAnnotation:S,getBody:w,observe:i,unobserve:s,updateAnnotation:l,updateBody:N,updateTarget:(C,E=It.LOCAL)=>{const I=z(C);I&&n(E,{updated:[I]})},upsertAnnotation:h}},Ty=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let wy=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,s=e.length;i<s;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(s=>t!==s)}}});const Ay=250,Sy=(r,t)=>{const e=wy(),i=(t==null?void 0:t.changes)||[];let s=t?t.pointer:-1,n=!1,o=0;const a=f=>{if(!n){const{changes:m}=f,y=performance.now();if(y-o>Ay)i.splice(s+1),i.push(m),s=i.length-1;else{const _=i.length-1;i[_]=xy(i[_],m)}o=y}n=!1};r.observe(a,{origin:It.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>s,canUndo:()=>s>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:s}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>s){n=!0;const{created:f,updated:m,deleted:y}=i[s+1];h(f),c(m),p(y),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:y}=i[s];l(f),u(m),d(y),e.emit("undo",i[s]),s-=1}}}},Cy=()=>{const{subscribe:r,set:t}=sa([]);return{subscribe:r,set:t}},Iy=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const x=g.indexOf(v);x!==-1&&g.splice(x,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const b=Array.isArray(v)?v.map(w=>e.serialize(w)):e.serialize(v),S=g?g instanceof PointerEvent?g:e.serialize(g):void 0;x(b,S)}else x(v,g)})},1)},m=()=>{const{selected:_}=n,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const x=h.find(b=>b.id===g.id);(!x||!Nr(x,g))&&f("updateAnnotation",g,x)}),h=h.map(g=>v.find(({id:x})=>x===g.id)||g)};n.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Nr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),g=new Set(_.map(({id:x})=>x));h.filter(x=>!g.has(x.id)).forEach(x=>{const b=o.getAnnotation(x.id);b&&!Nr(b,x)&&f("updateAnnotation",b,x)}),h=[...h.filter(x=>g.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}f("selectionChanged",h)}}),s.subscribe(_=>{!u&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):u&&!_?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(_))),u=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(x=>f("createAnnotation",x)),(g||[]).forEach(x=>f("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:b})=>{const S=h.find(w=>w.id===x.id)||x;h=h.map(w=>w.id===x.id?b:w),f("updateAnnotation",b,S)})},{origin:It.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),g=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);g.length>0&&(h=h.map(x=>g.find(b=>b.id===x.id)||x))}},{origin:It.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(x=>f("updateAnnotation",x.oldValue,x.newValue)):(g||[]).forEach(x=>f("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},Ry=r=>t=>t.reduce((e,i)=>{const{parsed:s,error:n}=r.parse(i);return n?{parsed:e.parsed,failed:[...e.failed,i]}:s?{parsed:[...e.parsed,s],failed:e.failed}:{...e}},{parsed:[],failed:[]}),My=(r,t,e)=>{const{store:i,selection:s}=r,n=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,It.REMOTE):console.error(g)}else i.addAnnotation(oa(_),It.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var _;const v=(((_=s.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},c=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||Ry(e),{parsed:x,failed:b}=g(_);b.length>0&&console.warn(`Discarded ${b.length} invalid annotations`,b),i.bulkAddAnnotations(x,v,It.REMOTE)}else i.bulkAddAnnotations(_.map(oa),v,It.REMOTE)},f=(_,v)=>{_?s.setSelected(_,v):s.clear()},m=_=>{s.clear(),s.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(oa(_)),v}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:u,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Py=(r,t,e)=>typeof t=="function"?t(r,e):t,Oy=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const s=typeof r=="function"?r(e,i):r,n=typeof t=="function"?t(e,i):t;return{...s||{},...n||{}}},Ny="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Dy=r=>crypto.getRandomValues(new Uint8Array(r)),Ly=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,s=-~(1.6*i*t/r.length);return(n=t)=>{let o="";for(;;){let a=e(s),l=s|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=n)return o}}},By=(r,t=21)=>Ly(r,t|0,Dy),Fy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Ny[e[r]&63];return t};const Uy=()=>({isGuest:!0,id:By("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ky=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,s=t.length;i<s;i++){let n=t.charCodeAt(i);e=(e<<5)-e+n,e|=0}return`${e}`},lu=r=>r?typeof r=="object"?{...r}:r:void 0,Gy=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:s,purpose:n,value:o,created:a,modified:l,creator:h,...u}=e;return{id:i||`temp-${ky(e)}`,annotation:t,type:s,purpose:n,value:o,creator:lu(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),$y=r=>r.map(t=>{var e;const{annotation:i,created:s,updated:n,...o}=t,a={...o,created:s==null?void 0:s.toISOString(),modified:n==null?void 0:n.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});Fy();const Hy=(r,t={strict:!0,invertY:!1})=>({parse:e=>Vy(e,t),serialize:e=>Xy(e,r,t)}),Vy=(r,t={strict:!0,invertY:!1})=>{const e=r.id||ru(),{creator:i,created:s,modified:n,body:o,...a}=r,l=Gy(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,u=Array.isArray(h.selector)?h.selector[0]:h.selector,c=(u==null?void 0:u.type)==="FragmentSelector"?Sg(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?ty(u):void 0;return c||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:lu(i),updated:n?new Date(n):void 0,...Array.isArray(a.target)?a.target[0]:a.target,annotation:e,selector:c||u}}}:{error:Error(`Invalid selector: ${JSON.stringify(u)}`)}},Xy=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:s,created:n,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==vt.RECTANGLE?Cg(i.geometry):ry(i)}catch(c){if(e.strict)throw c;h=i}const u={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:$y(r.bodies),created:n==null?void 0:n.toISOString(),creator:s,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,selector:h}};return delete u.bodies,"annotation"in u.target&&delete u.target.annotation,u};function hu(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function uu(r){let t,e;return t=new Oi({props:{x:r[10][0],y:r[10][1],scale:r[3]}}),t.$on("pointerdown",function(){$t(r[9](`HANDLE-${r[12]}`))&&r[9](`HANDLE-${r[12]}`).apply(this,arguments)}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){r=i;const n={};s&16&&(n.x=r[10][0]),s&16&&(n.y=r[10][1]),s&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function zy(r){let t,e,i,s,n,o,a,l,h,u,c,d=Ee(r[4].points),p=[];for(let m=0;m<d.length;m+=1)p[m]=uu(hu(r,d,m));const f=m=>dt(p[m],1,1,()=>{p[m]=null});return{c(){t=mt("polygon"),s=ke(),n=mt("polygon"),a=ke();for(let m=0;m<p.length;m+=1)p[m].c();l=Ie(),A(t,"class","a9s-outer"),A(t,"style",e=r[1]?"display:none;":void 0),A(t,"points",i=r[4].points.map(cu).join(" ")),A(n,"class","a9s-inner a9s-shape-handle"),A(n,"style",r[1]),A(n,"points",o=r[4].points.map(du).join(" "))},m(m,y){ot(m,t,y),ot(m,s,y),ot(m,n,y),ot(m,a,y);for(let _=0;_<p.length;_+=1)p[_]&&p[_].m(m,y);ot(m,l,y),h=!0,u||(c=[Bt(t,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(n,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],u=!0)},p(m,y){if(r=m,(!h||y&2&&e!==(e=r[1]?"display:none;":void 0))&&A(t,"style",e),(!h||y&16&&i!==(i=r[4].points.map(cu).join(" ")))&&A(t,"points",i),(!h||y&2)&&A(n,"style",r[1]),(!h||y&16&&o!==(o=r[4].points.map(du).join(" ")))&&A(n,"points",o),y&536){d=Ee(r[4].points);let _;for(_=0;_<d.length;_+=1){const v=hu(r,d,_);p[_]?(p[_].p(v,y),it(p[_],1)):(p[_]=uu(v),p[_].c(),it(p[_],1),p[_].m(l.parentNode,l))}for(xe(),_=d.length;_<p.length;_+=1)f(_);be()}},i(m){if(!h){for(let y=0;y<d.length;y+=1)it(p[y]);h=!0}},o(m){p=p.filter(Boolean);for(let y=0;y<p.length;y+=1)dt(p[y]);h=!1},d(m){m&&(nt(t),nt(s),nt(n),nt(a),nt(l)),Jr(p,m),u=!1,Ue(c)}}}function Wy(r){let t,e;return t=new la({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[zy,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:r}}}),t.$on("change",r[6]),t.$on("grab",r[7]),t.$on("release",r[8]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&8730&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}const cu=r=>r.join(","),du=r=>r.join(",");function Yy(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,p,f)=>{let m;const y=d.geometry;p==="SHAPE"?m=y.points.map(([v,g])=>[v+f[0],g+f[1]]):m=y.points.map(([v,g],x)=>p===`HANDLE-${x}`?[v+f[0],g+f[1]]:[v,g]);const _=_r(m);return{...d,geometry:{points:m,bounds:_}}};function h(d){Ne.call(this,r,d)}function u(d){Ne.call(this,r,d)}function c(d){Ne.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,s=d.shape),"computedStyle"in d&&e(1,n=d.computedStyle),"transform"in d&&e(2,o=d.transform),"viewportScale"in d&&e(3,a=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,i=s.geometry)},[s,n,o,a,i,l,h,u,c]}class jy extends we{constructor(t){super(),Te(this,t,Yy,Wy,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const aa=(r,t)=>{const e=Math.abs(t[0]-r[0]),i=Math.abs(t[1]-r[1]);return Math.sqrt(Math.pow(e,2)+Math.pow(i,2))},Pi=[];function qy(r,t=Ct){let e;const i=new Set;function s(a){if(te(r,a)&&(r=a,e)){const l=!Pi.length;for(const h of i)h[1](),Pi.push(h,r);if(l){for(let h=0;h<Pi.length;h+=2)Pi[h][0](Pi[h+1]);Pi.length=0}}}function n(a){s(a(r))}function o(a,l=Ct){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||Ct),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const Ky=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:s,height:n}=r;t.setAttribute("viewBox",`0 0 ${s} ${n}`),r.addEventListener("load",o=>{const a=o.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${e} ${i}`)},Zy=(r,t)=>{Ky(r,t);const{subscribe:e,set:i}=qy(1);let s;return window.ResizeObserver&&(s=new ResizeObserver(()=>{const n=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(n.width/o,n.height/a);i(l)}),s.observe(t.parentElement)),{destroy:()=>{s&&s.disconnect()},subscribe:e}},fu=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function Qy(r){let t,e,i,s,n,o;return{c(){t=mt("rect"),A(t,"class",e=tn(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),A(t,"x",i=r[0]-r[5]/2),A(t,"y",s=r[1]-r[5]/2),A(t,"width",r[5]),A(t,"height",r[5])},m(a,l){ot(a,t,l),n||(o=Bt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=tn(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&A(t,"class",e),l&33&&i!==(i=a[0]-a[5]/2)&&A(t,"x",i),l&34&&s!==(s=a[1]-a[5]/2)&&A(t,"y",s),l&32&&A(t,"width",a[5]),l&32&&A(t,"height",a[5])},d(a){a&&nt(t),n=!1,o()}}}function Jy(r){let t,e,i,s,n,o,a,l,h;return{c(){t=mt("g"),e=mt("circle"),s=mt("rect"),A(e,"cx",r[0]),A(e,"cy",r[1]),A(e,"r",i=r[3]/r[2]),A(e,"class","a9s-touch-halo svelte-1sgkh33"),Mr(e,"touched",r[4]),A(s,"class",n=tn(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),A(s,"x",o=r[0]-r[5]/2),A(s,"y",a=r[1]-r[5]/2),A(s,"width",r[5]),A(s,"height",r[5]),A(t,"class","a9s-touch-handle")},m(u,c){ot(u,t,c),Oe(t,e),Oe(t,s),l||(h=[Bt(e,"pointerdown",r[10]),Bt(e,"pointerdown",r[6]),Bt(e,"pointerup",r[7]),Bt(s,"pointerdown",r[9]),Bt(s,"pointerdown",r[6]),Bt(s,"pointerup",r[7])],l=!0)},p(u,c){c&1&&A(e,"cx",u[0]),c&2&&A(e,"cy",u[1]),c&12&&i!==(i=u[3]/u[2])&&A(e,"r",i),c&16&&Mr(e,"touched",u[4]),c&256&&n!==(n=tn(`a9s-handle ${u[8].class||""}`.trim())+" svelte-1sgkh33")&&A(s,"class",n),c&33&&o!==(o=u[0]-u[5]/2)&&A(s,"x",o),c&34&&a!==(a=u[1]-u[5]/2)&&A(s,"y",a),c&32&&A(s,"width",u[5]),c&32&&A(s,"height",u[5])},d(u){u&&nt(t),l=!1,Ue(h)}}}function t_(r){let t;function e(s,n){return fu?Jy:Qy}let i=e()(r);return{c(){i.c(),t=Ie()},m(s,n){i.m(s,n),ot(s,t,n)},p(s,[n]){i.p(s,n)},i:Ct,o:Ct,d(s){s&&nt(t),i.d(s)}}}function e_(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{radius:a=30}=t,l=!1;const h=f=>{f.pointerType==="touch"&&e(4,l=!0)},u=()=>e(4,l=!1);function c(f){Ne.call(this,r,f)}function d(f){Ne.call(this,r,f)}function p(f){Ne.call(this,r,f)}return r.$$set=f=>{e(8,t=Xo(Xo({},t),Bh(f))),"x"in f&&e(0,s=f.x),"y"in f&&e(1,n=f.y),"scale"in f&&e(2,o=f.scale),"radius"in f&&e(3,a=f.radius)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=10/o)},t=Bh(t),[s,n,o,a,l,i,h,u,t,c,d,p]}class Oi extends we{constructor(t){super(),Te(this,t,e_,t_,te,{x:0,y:1,scale:2,radius:3})}}function r_(r){let t,e,i,s,n,o,a,l,h,u,c,d,p,f,m,y,_,v,g,x,b,S,w,T,N,F,z,C,E,I,P,$,k,G,st,M,L,V,rt,Q,X,_t,St;return G=new Oi({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),G.$on("pointerdown",function(){$t(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),M=new Oi({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),M.$on("pointerdown",function(){$t(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),V=new Oi({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),V.$on("pointerdown",function(){$t(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Q=new Oi({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Q.$on("pointerdown",function(){$t(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=mt("rect"),a=ke(),l=mt("rect"),p=ke(),f=mt("rect"),v=ke(),g=mt("rect"),w=ke(),T=mt("rect"),C=ke(),E=mt("rect"),k=ke(),_e(G.$$.fragment),st=ke(),_e(M.$$.fragment),L=ke(),_e(V.$$.fragment),rt=ke(),_e(Q.$$.fragment),A(t,"class","a9s-outer"),A(t,"style",e=r[1]?"display:none;":void 0),A(t,"x",i=r[4].x),A(t,"y",s=r[4].y),A(t,"width",n=r[4].w),A(t,"height",o=r[4].h),A(l,"class","a9s-inner a9s-shape-handle"),A(l,"style",r[1]),A(l,"x",h=r[4].x),A(l,"y",u=r[4].y),A(l,"width",c=r[4].w),A(l,"height",d=r[4].h),A(f,"class","a9s-edge-handle a9s-edge-handle-top"),A(f,"x",m=r[4].x),A(f,"y",y=r[4].y),A(f,"height",1),A(f,"width",_=r[4].w),A(g,"class","a9s-edge-handle a9s-edge-handle-right"),A(g,"x",x=r[4].x+r[4].w),A(g,"y",b=r[4].y),A(g,"height",S=r[4].h),A(g,"width",1),A(T,"class","a9s-edge-handle a9s-edge-handle-bottom"),A(T,"x",N=r[4].x),A(T,"y",F=r[4].y+r[4].h),A(T,"height",1),A(T,"width",z=r[4].w),A(E,"class","a9s-edge-handle a9s-edge-handle-left"),A(E,"x",I=r[4].x),A(E,"y",P=r[4].y),A(E,"height",$=r[4].h),A(E,"width",1)},m(O,D){ot(O,t,D),ot(O,a,D),ot(O,l,D),ot(O,p,D),ot(O,f,D),ot(O,v,D),ot(O,g,D),ot(O,w,D),ot(O,T,D),ot(O,C,D),ot(O,E,D),ot(O,k,D),fe(G,O,D),ot(O,st,D),fe(M,O,D),ot(O,L,D),fe(V,O,D),ot(O,rt,D),fe(Q,O,D),X=!0,_t||(St=[Bt(t,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(l,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(f,"pointerdown",function(){$t(r[9]("TOP"))&&r[9]("TOP").apply(this,arguments)}),Bt(g,"pointerdown",function(){$t(r[9]("RIGHT"))&&r[9]("RIGHT").apply(this,arguments)}),Bt(T,"pointerdown",function(){$t(r[9]("BOTTOM"))&&r[9]("BOTTOM").apply(this,arguments)}),Bt(E,"pointerdown",function(){$t(r[9]("LEFT"))&&r[9]("LEFT").apply(this,arguments)})],_t=!0)},p(O,D){r=O,(!X||D&2&&e!==(e=r[1]?"display:none;":void 0))&&A(t,"style",e),(!X||D&16&&i!==(i=r[4].x))&&A(t,"x",i),(!X||D&16&&s!==(s=r[4].y))&&A(t,"y",s),(!X||D&16&&n!==(n=r[4].w))&&A(t,"width",n),(!X||D&16&&o!==(o=r[4].h))&&A(t,"height",o),(!X||D&2)&&A(l,"style",r[1]),(!X||D&16&&h!==(h=r[4].x))&&A(l,"x",h),(!X||D&16&&u!==(u=r[4].y))&&A(l,"y",u),(!X||D&16&&c!==(c=r[4].w))&&A(l,"width",c),(!X||D&16&&d!==(d=r[4].h))&&A(l,"height",d),(!X||D&16&&m!==(m=r[4].x))&&A(f,"x",m),(!X||D&16&&y!==(y=r[4].y))&&A(f,"y",y),(!X||D&16&&_!==(_=r[4].w))&&A(f,"width",_),(!X||D&16&&x!==(x=r[4].x+r[4].w))&&A(g,"x",x),(!X||D&16&&b!==(b=r[4].y))&&A(g,"y",b),(!X||D&16&&S!==(S=r[4].h))&&A(g,"height",S),(!X||D&16&&N!==(N=r[4].x))&&A(T,"x",N),(!X||D&16&&F!==(F=r[4].y+r[4].h))&&A(T,"y",F),(!X||D&16&&z!==(z=r[4].w))&&A(T,"width",z),(!X||D&16&&I!==(I=r[4].x))&&A(E,"x",I),(!X||D&16&&P!==(P=r[4].y))&&A(E,"y",P),(!X||D&16&&$!==($=r[4].h))&&A(E,"height",$);const ut={};D&16&&(ut.x=r[4].x),D&16&&(ut.y=r[4].y),D&8&&(ut.scale=r[3]),G.$set(ut);const lt={};D&16&&(lt.x=r[4].x+r[4].w),D&16&&(lt.y=r[4].y),D&8&&(lt.scale=r[3]),M.$set(lt);const Et={};D&16&&(Et.x=r[4].x+r[4].w),D&16&&(Et.y=r[4].y+r[4].h),D&8&&(Et.scale=r[3]),V.$set(Et);const Tt={};D&16&&(Tt.x=r[4].x),D&16&&(Tt.y=r[4].y+r[4].h),D&8&&(Tt.scale=r[3]),Q.$set(Tt)},i(O){X||(it(G.$$.fragment,O),it(M.$$.fragment,O),it(V.$$.fragment,O),it(Q.$$.fragment,O),X=!0)},o(O){dt(G.$$.fragment,O),dt(M.$$.fragment,O),dt(V.$$.fragment,O),dt(Q.$$.fragment,O),X=!1},d(O){O&&(nt(t),nt(a),nt(l),nt(p),nt(f),nt(v),nt(g),nt(w),nt(T),nt(C),nt(E),nt(k),nt(st),nt(L),nt(rt)),pe(G,O),pe(M,O),pe(V,O),pe(Q,O),_t=!1,Ue(St)}}}function i_(r){let t,e;return t=new la({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[r_,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:r}}}),t.$on("grab",r[6]),t.$on("change",r[7]),t.$on("release",r[8]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&1562&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function s_(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,p,f)=>{const m=d.geometry.bounds;let[y,_]=[m.minX,m.minY],[v,g]=[m.maxX,m.maxY];const[x,b]=f;if(p==="SHAPE")y+=x,v+=x,_+=b,g+=b;else{switch(p){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{_+=b;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=b;break}}switch(p){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{y+=x;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{v+=x;break}}}const S=Math.min(y,v),w=Math.min(_,g),T=Math.abs(v-y),N=Math.abs(g-_);return{...d,geometry:{x:S,y:w,w:T,h:N,bounds:{minX:S,minY:w,maxX:S+T,maxY:w+N}}}};function h(d){Ne.call(this,r,d)}function u(d){Ne.call(this,r,d)}function c(d){Ne.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,s=d.shape),"computedStyle"in d&&e(1,n=d.computedStyle),"transform"in d&&e(2,o=d.transform),"viewportScale"in d&&e(3,a=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,i=s.geometry)},[s,n,o,a,i,l,h,u,c]}class n_ extends we{constructor(t){super(),Te(this,t,s_,i_,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}function pu(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function mu(r,t,e){const i=r.slice();return i[13]=t[e],i[15]=e,i}function gu(r,t,e){const i=r.slice();return i[16]=t[e],i[18]=e,i}function yu(r){let t,e;return t=new Oi({props:{x:r[16][0],y:r[16][1],scale:r[3]}}),t.$on("pointerdown",function(){$t(r[9](`HANDLE-${r[12]}-${r[15]}-${r[18]}`))&&r[9](`HANDLE-${r[12]}-${r[15]}-${r[18]}`).apply(this,arguments)}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){r=i;const n={};s&16&&(n.x=r[16][0]),s&16&&(n.y=r[16][1]),s&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function _u(r){let t,e,i=Ee(r[13].points),s=[];for(let o=0;o<i.length;o+=1)s[o]=yu(gu(r,i,o));const n=o=>dt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Ie()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a&536){i=Ee(o[13].points);let l;for(l=0;l<i.length;l+=1){const h=gu(o,i,l);s[l]?(s[l].p(h,a),it(s[l],1)):(s[l]=yu(h),s[l].c(),it(s[l],1),s[l].m(t.parentNode,t))}for(xe(),l=i.length;l<s.length;l+=1)n(l);be()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)it(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)dt(s[a]);e=!1},d(o){o&&nt(t),Jr(s,o)}}}function vu(r){let t,e,i,s,n,o,a,l,h,u=Ee(r[10].rings),c=[];for(let p=0;p<u.length;p+=1)c[p]=_u(mu(r,u,p));const d=p=>dt(c[p],1,1,()=>{c[p]=null});return{c(){t=mt("g"),e=mt("path"),n=mt("path");for(let p=0;p<c.length;p+=1)c[p].c();A(e,"class","a9s-outer"),A(e,"style",i=r[1]?"display:none;":void 0),A(e,"fill-rule","evenodd"),A(e,"d",s=ei(r[10])),A(n,"class","a9s-inner"),A(n,"style",r[1]),A(n,"fill-rule","evenodd"),A(n,"d",o=ei(r[10]))},m(p,f){ot(p,t,f),Oe(t,e),Oe(t,n);for(let m=0;m<c.length;m+=1)c[m]&&c[m].m(t,null);a=!0,l||(h=[Bt(e,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(n,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],l=!0)},p(p,f){if(r=p,(!a||f&2&&i!==(i=r[1]?"display:none;":void 0))&&A(e,"style",i),(!a||f&16&&s!==(s=ei(r[10])))&&A(e,"d",s),(!a||f&2)&&A(n,"style",r[1]),(!a||f&16&&o!==(o=ei(r[10])))&&A(n,"d",o),f&536){u=Ee(r[10].rings);let m;for(m=0;m<u.length;m+=1){const y=mu(r,u,m);c[m]?(c[m].p(y,f),it(c[m],1)):(c[m]=_u(y),c[m].c(),it(c[m],1),c[m].m(t,null))}for(xe(),m=u.length;m<c.length;m+=1)d(m);be()}},i(p){if(!a){for(let f=0;f<u.length;f+=1)it(c[f]);a=!0}},o(p){c=c.filter(Boolean);for(let f=0;f<c.length;f+=1)dt(c[f]);a=!1},d(p){p&&nt(t),Jr(c,p),l=!1,Ue(h)}}}function o_(r){let t,e,i=Ee(r[4].polygons),s=[];for(let o=0;o<i.length;o+=1)s[o]=vu(pu(r,i,o));const n=o=>dt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Ie()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a&538){i=Ee(o[4].polygons);let l;for(l=0;l<i.length;l+=1){const h=pu(o,i,l);s[l]?(s[l].p(h,a),it(s[l],1)):(s[l]=vu(h),s[l].c(),it(s[l],1),s[l].m(t.parentNode,t))}for(xe(),l=i.length;l<s.length;l+=1)n(l);be()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)it(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)dt(s[a]);e=!1},d(o){o&&nt(t),Jr(s,o)}}}function a_(r){let t,e;return t=new la({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[o_,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:r}}}),t.$on("change",r[6]),t.$on("grab",r[7]),t.$on("release",r[8]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&524826&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function l_(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,p,f)=>{const m=d.geometry.polygons;let y;if(p==="SHAPE")y=m.map(_=>{const v=_.rings.map((x,b)=>({points:x.points.map((S,w)=>[S[0]+f[0],S[1]+f[1]])})),g=_r(v[0].points);return{rings:v,bounds:g}});else{const[_,v,g,x]=p.split("-").map(b=>parseInt(b));y=m.map((b,S)=>{if(S===v){const w=b.rings.map((N,F)=>F===g?{points:N.points.map((z,C)=>C===x?[z[0]+f[0],z[1]+f[1]]:z)}:N),T=_r(w[0].points);return{rings:w,bounds:T}}else return b})}return{...d,geometry:{polygons:y,bounds:Tg(y)}}};function h(d){Ne.call(this,r,d)}function u(d){Ne.call(this,r,d)}function c(d){Ne.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,s=d.shape),"computedStyle"in d&&e(1,n=d.computedStyle),"transform"in d&&e(2,o=d.transform),"viewportScale"in d&&e(3,a=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,i=s.geometry)},[s,n,o,a,i,l,h,u,c]}class h_ extends we{constructor(t){super(),Te(this,t,l_,a_,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const xu=new Map([[vt.RECTANGLE,n_],[vt.POLYGON,jy],[vt.MULTIPOLYGLON,h_]]),bu=r=>xu.get(r.type),Eu=(r,t)=>xu.set(r,t),u_=r=>({}),Tu=r=>({grab:r[0]});function c_(r){let t,e,i,s;const n=r[7].default,o=ag(n,r,r[6],Tu);return{c(){t=mt("g"),o&&o.c(),A(t,"class","a9s-annotation selected")},m(a,l){ot(a,t,l),o&&o.m(t,null),e=!0,i||(s=[Bt(t,"pointerup",r[2]),Bt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&64)&&hg(o,n,a,a[6],e?lg(n,a[6],l,u_):ug(a[6]),Tu)},i(a){e||(it(o,a),e=!0)},o(a){dt(o,a),e=!1},d(a){a&&nt(t),o&&o.d(a),i=!1,Ue(s)}}}function d_(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Si();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,u,c;const d=m=>y=>{h=m,u=l.elementToImage(y.offsetX,y.offsetY),c=o,y.target.setPointerCapture(y.pointerId),n("grab",y)},p=m=>{if(h){const[y,_]=l.elementToImage(m.offsetX,m.offsetY),v=[y-u[0],_-u[1]];e(3,o=a(c,h,v)),n("change",o)}},f=m=>{m.target.releasePointerCapture(m.pointerId),h=void 0,c=o,n("release",m)};return r.$$set=m=>{"shape"in m&&e(3,o=m.shape),"editor"in m&&e(4,a=m.editor),"transform"in m&&e(5,l=m.transform),"$$scope"in m&&e(6,s=m.$$scope)},[d,p,f,o,a,l,s,i]}class la extends we{constructor(t){super(),Te(this,t,d_,c_,te,{shape:3,editor:4,transform:5})}}const gs=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:s,stroke:n,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${s||"0.25"};`),n&&(l+=`stroke:${n};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}};function f_(r,t,e){let i;const s=Si();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:u}=t,c;return ms(()=>(e(6,c=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:u}})),c.$on("change",d=>{c.$$set({shape:d.detail}),s("change",d.detail)}),c.$on("grab",d=>s("grab",d.detail)),c.$on("release",d=>s("release",d.detail)),()=>{c.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,n=d.annotation),"editor"in d&&e(1,o=d.editor),"style"in d&&e(2,a=d.style),"target"in d&&e(3,l=d.target),"transform"in d&&e(4,h=d.transform),"viewportScale"in d&&e(5,u=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=gs(n,a)),r.$$.dirty&65&&n&&(c==null||c.$set({shape:n.target.selector})),r.$$.dirty&80&&c&&c.$set({transform:h}),r.$$.dirty&96&&c&&c.$set({viewportScale:u}),r.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[n,o,a,l,h,u,c,i]}class p_ extends we{constructor(t){super(),Te(this,t,f_,null,te,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function m_(r,t,e){const i=Si();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return ms(()=>{const u=n.closest("svg"),c=[],d=(p,f,m)=>{u==null||u.addEventListener(p,f,m),c.push(()=>u==null?void 0:u.removeEventListener(p,f,m))};return e(5,h=new o({target:n,props:{addEventListener:d,drawingMode:s,transform:a,viewportScale:l}})),h.$on("create",p=>i("create",p.detail)),()=>{c.forEach(p=>p()),h.$destroy()}}),r.$$set=u=>{"drawingMode"in u&&e(0,s=u.drawingMode),"target"in u&&e(1,n=u.target),"tool"in u&&e(2,o=u.tool),"transform"in u&&e(3,a=u.transform),"viewportScale"in u&&e(4,l=u.viewportScale)},r.$$.update=()=>{r.$$.dirty&40&&h&&h.$set({transform:a}),r.$$.dirty&48&&h&&h.$set({viewportScale:l})},[s,n,o,a,l,h]}class g_ extends we{constructor(t){super(),Te(this,t,m_,null,te,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function wu(r){let t,e;return{c(){t=mt("rect"),e=mt("rect"),A(t,"class","a9s-outer"),A(t,"x",r[1]),A(t,"y",r[2]),A(t,"width",r[3]),A(t,"height",r[4]),A(e,"class","a9s-inner"),A(e,"x",r[1]),A(e,"y",r[2]),A(e,"width",r[3]),A(e,"height",r[4])},m(i,s){ot(i,t,s),ot(i,e,s)},p(i,s){s&2&&A(t,"x",i[1]),s&4&&A(t,"y",i[2]),s&8&&A(t,"width",i[3]),s&16&&A(t,"height",i[4]),s&2&&A(e,"x",i[1]),s&4&&A(e,"y",i[2]),s&8&&A(e,"width",i[3]),s&16&&A(e,"height",i[4])},d(i){i&&(nt(t),nt(e))}}}function y_(r){let t,e=r[0]&&wu(r);return{c(){t=mt("g"),e&&e.c(),A(t,"class","a9s-annotation a9s-rubberband")},m(i,s){ot(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=wu(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Ct,o:Ct,d(i){i&&nt(t),e&&e.d()}}}function __(r,t,e){const i=Si();let{addEventListener:s}=t,{drawingMode:n}=t,{transform:o}=t,a,l,h,u,c,d,p;const f=v=>{const g=v;a=performance.now(),n==="drag"&&(e(0,l=o.elementToImage(g.offsetX,g.offsetY)),h=l,e(1,u=l[0]),e(2,c=l[1]),e(3,d=1),e(4,p=1))},m=v=>{const g=v;l&&(h=o.elementToImage(g.offsetX,g.offsetY),e(1,u=Math.min(h[0],l[0])),e(2,c=Math.min(h[1],l[1])),e(3,d=Math.abs(h[0]-l[0])),e(4,p=Math.abs(h[1]-l[1])))},y=v=>{const g=v,x=performance.now()-a;if(n==="click"){if(x>300)return;l?_():(e(0,l=o.elementToImage(g.offsetX,g.offsetY)),h=l,e(1,u=l[0]),e(2,c=l[1]),e(3,d=1),e(4,p=1))}else l&&(x>300||d*p>100?(g.stopPropagation(),_()):(e(0,l=void 0),h=void 0))},_=()=>{if(d*p>15){const v={type:vt.RECTANGLE,geometry:{bounds:{minX:u,minY:c,maxX:u+d,maxY:c+p},x:u,y:c,w:d,h:p}};i("create",v)}e(0,l=void 0),h=void 0};return ms(()=>{s("pointerdown",f),s("pointermove",m),s("pointerup",y,!0)}),r.$$set=v=>{"addEventListener"in v&&e(5,s=v.addEventListener),"drawingMode"in v&&e(6,n=v.drawingMode),"transform"in v&&e(7,o=v.transform)},[l,u,c,d,p,s,n,o]}class v_ extends we{constructor(t){super(),Te(this,t,__,y_,te,{addEventListener:5,drawingMode:6,transform:7})}}function ha(r){const t=r.slice(),e=(t[2]?t[0]:[...t[0],t[1]]).map(i=>i.join(",")).join(" ");return t[16]=e,t}function Au(r){let t,e,i,s,n,o=r[2]&&Su(r);return{c(){t=mt("polygon"),i=mt("polygon"),o&&o.c(),n=Ie(),A(t,"class","a9s-outer"),A(t,"points",e=r[16]),A(i,"class","a9s-inner"),A(i,"points",s=r[16])},m(a,l){ot(a,t,l),ot(a,i,l),o&&o.m(a,l),ot(a,n,l)},p(a,l){l&7&&e!==(e=a[16])&&A(t,"points",e),l&7&&s!==(s=a[16])&&A(i,"points",s),a[2]?o?o.p(a,l):(o=Su(a),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},d(a){a&&(nt(t),nt(i),nt(n)),o&&o.d(a)}}}function Su(r){let t,e,i;return{c(){t=mt("rect"),A(t,"class","a9s-handle"),A(t,"x",e=r[0][0][0]-r[3]/2),A(t,"y",i=r[0][0][1]-r[3]/2),A(t,"height",r[3]),A(t,"width",r[3])},m(s,n){ot(s,t,n)},p(s,n){n&9&&e!==(e=s[0][0][0]-s[3]/2)&&A(t,"x",e),n&9&&i!==(i=s[0][0][1]-s[3]/2)&&A(t,"y",i),n&8&&A(t,"height",s[3]),n&8&&A(t,"width",s[3])},d(s){s&&nt(t)}}}function x_(r){let t,e=r[1]&&Au(ha(r));return{c(){t=mt("g"),e&&e.c(),A(t,"class","a9s-annotation a9s-rubberband")},m(i,s){ot(i,t,s),e&&e.m(t,null)},p(i,[s]){i[1]?e?e.p(ha(i),s):(e=Au(ha(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Ct,o:Ct,d(i){i&&nt(t),e&&e.d()}}}const b_=20,E_=1500;function T_(r,t,e){let i;const s=Si();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,u=[],c,d,p=!1;const f=g=>{const x=g,{timeStamp:b,offsetX:S,offsetY:w}=x;if(h={timeStamp:b,offsetX:S,offsetY:w},o==="drag"&&u.length===0){const T=a.elementToImage(x.offsetX,x.offsetY);u.push(T),e(1,c=T)}},m=g=>{const x=g;if(d&&clearTimeout(d),u.length>0){if(e(1,c=a.elementToImage(x.offsetX,x.offsetY)),u.length>2){const b=aa(c,u[0])*l;e(2,p=b<b_)}x.pointerType==="touch"&&(d=setTimeout(()=>{_()},E_))}},y=g=>{const x=g;if(d&&clearTimeout(d),o==="click"){const b=x.timeStamp-h.timeStamp,S=aa([h.offsetX,h.offsetY],[x.offsetX,x.offsetY]);if(b>300||S>15)return;if(p)v();else if(u.length===0){const w=a.elementToImage(x.offsetX,x.offsetY);u.push(w),e(1,c=w)}else u.push(c)}else{if(u.length===1&&aa(u[0],c)<=4){e(0,u=[]),e(1,c=void 0);return}x.stopImmediatePropagation(),p?v():u.push(c)}},_=()=>{if(!c)return;const g=u.slice(0,-1);if(g.length<3)return;const x={type:vt.POLYGON,geometry:{bounds:_r(u),points:g}};Ko(x)>4&&(e(0,u=[]),e(1,c=void 0),s("create",x))},v=()=>{const g={type:vt.POLYGON,geometry:{bounds:_r(u),points:[...u]}};e(0,u=[]),e(1,c=void 0),s("create",g)};return ms(()=>{n("pointerdown",f,!0),n("pointermove",m),n("pointerup",y,!0),n("dblclick",_,!0)}),r.$$set=g=>{"addEventListener"in g&&e(4,n=g.addEventListener),"drawingMode"in g&&e(5,o=g.drawingMode),"transform"in g&&e(6,a=g.transform),"viewportScale"in g&&e(7,l=g.viewportScale)},r.$$.update=()=>{r.$$.dirty&128&&e(3,i=10/l)},[u,c,p,i,n,o,a,l]}class w_ extends we{constructor(t){super(),Te(this,t,T_,x_,te,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const ua=new Map([["rectangle",{tool:v_}],["polygon",{tool:w_}]]),hn=()=>[...ua.keys()],un=r=>ua.get(r),Cu=(r,t,e)=>ua.set(r,{tool:t,opts:e});function A_(r){let t,e,i,s,n;return{c(){t=mt("g"),e=mt("ellipse"),s=mt("ellipse"),A(e,"class","a9s-outer"),A(e,"style",i=r[1]?"display:none;":void 0),A(e,"cx",r[2]),A(e,"cy",r[3]),A(e,"rx",r[4]),A(e,"ry",r[5]),A(s,"class","a9s-inner"),A(s,"style",r[1]),A(s,"cx",r[2]),A(s,"cy",r[3]),A(s,"rx",r[4]),A(s,"ry",r[5]),A(t,"class","a9s-annotation"),A(t,"data-id",n=r[0].id)},m(o,a){ot(o,t,a),Oe(t,e),Oe(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&A(e,"style",i),a&2&&A(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&A(t,"data-id",n)},i:Ct,o:Ct,d(o){o&&nt(t)}}}function S_(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:u}=n;return r.$$set=c=>{"annotation"in c&&e(0,s=c.annotation),"geom"in c&&e(6,n=c.geom),"style"in c&&e(7,o=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=gs(s,o))},[s,i,a,l,h,u,n,o]}class C_ extends we{constructor(t){super(),Te(this,t,S_,A_,te,{annotation:0,geom:6,style:7})}}function Iu(r,t,e){const i=r.slice();return i[5]=t[e],i}function Ru(r){let t,e,i;return{c(){t=mt("path"),i=mt("path"),A(t,"class","a9s-outer"),A(t,"style",e=r[1]?"display:none;":void 0),A(t,"fill-rule","evenodd"),A(t,"d",ei(r[5])),A(i,"class","a9s-inner"),A(i,"style",r[1]),A(i,"fill-rule","evenodd"),A(i,"d",ei(r[5]))},m(s,n){ot(s,t,n),ot(s,i,n)},p(s,n){n&2&&e!==(e=s[1]?"display:none;":void 0)&&A(t,"style",e),n&2&&A(i,"style",s[1])},d(s){s&&(nt(t),nt(i))}}}function I_(r){let t,e,i=Ee(r[2]),s=[];for(let n=0;n<i.length;n+=1)s[n]=Ru(Iu(r,i,n));return{c(){t=mt("g");for(let n=0;n<s.length;n+=1)s[n].c();A(t,"class","a9s-annotation"),A(t,"data-id",e=r[0].id)},m(n,o){ot(n,t,o);for(let a=0;a<s.length;a+=1)s[a]&&s[a].m(t,null)},p(n,[o]){if(o&6){i=Ee(n[2]);let a;for(a=0;a<i.length;a+=1){const l=Iu(n,i,a);s[a]?s[a].p(l,o):(s[a]=Ru(l),s[a].c(),s[a].m(t,null))}for(;a<s.length;a+=1)s[a].d(1);s.length=i.length}o&1&&e!==(e=n[0].id)&&A(t,"data-id",e)},i:Ct,o:Ct,d(n){n&&nt(t),Jr(s,n)}}}function R_(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{polygons:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=gs(s,o))},[s,i,a,n,o]}class M_ extends we{constructor(t){super(),Te(this,t,R_,I_,te,{annotation:0,geom:3,style:4})}}function P_(r){let t,e,i,s,n;return{c(){t=mt("g"),e=mt("polygon"),s=mt("polygon"),A(e,"class","a9s-outer"),A(e,"style",i=r[1]?"display:none;":void 0),A(e,"points",r[2].map(O_).join(" ")),A(s,"class","a9s-inner"),A(s,"style",r[1]),A(s,"points",r[2].map(N_).join(" ")),A(t,"class","a9s-annotation"),A(t,"data-id",n=r[0].id)},m(o,a){ot(o,t,a),Oe(t,e),Oe(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&A(e,"style",i),a&2&&A(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&A(t,"data-id",n)},i:Ct,o:Ct,d(o){o&&nt(t)}}}const O_=r=>r.join(","),N_=r=>r.join(",");function D_(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{points:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=gs(s,o))},[s,i,a,n,o]}class L_ extends we{constructor(t){super(),Te(this,t,D_,P_,te,{annotation:0,geom:3,style:4})}}function B_(r){let t,e,i,s,n;return{c(){t=mt("g"),e=mt("rect"),s=mt("rect"),A(e,"class","a9s-outer"),A(e,"style",i=r[5]?"display:none;":void 0),A(e,"x",r[4]),A(e,"y",r[3]),A(e,"width",r[2]),A(e,"height",r[1]),A(s,"class","a9s-inner"),A(s,"style",r[5]),A(s,"x",r[4]),A(s,"y",r[3]),A(s,"width",r[2]),A(s,"height",r[1]),A(t,"class","a9s-annotation"),A(t,"data-id",n=r[0].id)},m(o,a){ot(o,t,a),Oe(t,e),Oe(t,s)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&A(e,"style",i),a&16&&A(e,"x",o[4]),a&8&&A(e,"y",o[3]),a&4&&A(e,"width",o[2]),a&2&&A(e,"height",o[1]),a&32&&A(s,"style",o[5]),a&16&&A(s,"x",o[4]),a&8&&A(s,"y",o[3]),a&4&&A(s,"width",o[2]),a&2&&A(s,"height",o[1]),a&1&&n!==(n=o[0].id)&&A(t,"data-id",n)},i:Ct,o:Ct,d(o){o&&nt(t)}}}function F_(r,t,e){let i,s,n,o,a,{annotation:l}=t,{geom:h}=t,{style:u}=t;return r.$$set=c=>{"annotation"in c&&e(0,l=c.annotation),"geom"in c&&e(6,h=c.geom),"style"in c&&e(7,u=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=gs(l,u)),r.$$.dirty&64&&e(4,{x:s,y:n,w:o,h:a}=h,s,(e(3,n),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,n,s,i,h,u]}class U_ extends we{constructor(t){super(),Te(this,t,F_,B_,te,{annotation:0,geom:6,style:7})}}const k_=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),s=r.createSVGPoint();s.x=t+i.x,s.y=e+i.y;const{x:n,y:o}=s.matrixTransform(r.getScreenCTM().inverse());return[n,o]}}),G_=250,$_=(r,t)=>{const e=Si();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<G_){const{x:n,y:o}=Mu(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},Mu=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),s=r.clientX-i.x,n=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=s+o,e.y=n+a,e.matrixTransform(t.getScreenCTM().inverse())};function Pu(r,t,e){const i=r.slice();i[39]=t[e];const s=i[24](i[39].target.selector);return i[40]=s,i}function Ou(r,t,e){const i=r.slice();return i[43]=t[e],i}function ca(r){const t=r.slice(),e=t[43].target.selector;return t[46]=e,t}function Nu(r){let t=r[43],e,i,s=Du(r);return{c(){s.c(),e=Ie()},m(n,o){s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&65536&&te(t,t=n[43])?(xe(),dt(s,1,1,Ct),be(),s=Du(n),s.c(),it(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s.d(n)}}}function H_(r){let t,e;return t=new M_({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function V_(r){let t,e;return t=new L_({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function X_(r){let t,e;return t=new U_({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function z_(r){var t;let e,i;return e=new C_({props:{annotation:r[43],geom:(t=r[46])==null?void 0:t.geometry,style:r[1]}}),{c(){_e(e.$$.fragment)},m(s,n){fe(e,s,n),i=!0},p(s,n){var o;const a={};n[0]&65536&&(a.annotation=s[43]),n[0]&65536&&(a.geom=(o=s[46])==null?void 0:o.geometry),n[0]&2&&(a.style=s[1]),e.$set(a)},i(s){i||(it(e.$$.fragment,s),i=!0)},o(s){dt(e.$$.fragment,s),i=!1},d(s){pe(e,s)}}}function Du(r){let t,e,i,s;const n=[z_,X_,V_,H_],o=[];function a(l,h){var u,c,d,p;return((u=l[46])==null?void 0:u.type)===vt.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===vt.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===vt.POLYGON?2:((p=l[46])==null?void 0:p.type)===vt.MULTIPOLYGLON?3:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Ie()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(xe(),dt(o[u],1,1,()=>{o[u]=null}),be()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),it(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(it(e),s=!0)},o(l){dt(e),s=!1},d(l){l&&nt(i),~t&&o[t].d(l)}}}function Lu(r){let t=Ge(r[43])&&!r[9](r[43]),e,i,s=t&&Nu(ca(r));return{c(){s&&s.c(),e=Ie()},m(n,o){s&&s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&66048&&(t=Ge(n[43])&&!n[9](n[43])),t?s?(s.p(ca(n),o),o[0]&66048&&it(s,1)):(s=Nu(ca(n)),s.c(),it(s,1),s.m(e.parentNode,e)):s&&(xe(),dt(s,1,1,()=>{s=null}),be())},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s&&s.d(n)}}}function Bu(r){let t,e,i,s;const n=[Y_,W_],o=[];function a(l,h){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Ie()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(xe(),dt(o[u],1,1,()=>{o[u]=null}),be()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),it(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(it(e),s=!0)},o(l){dt(e),s=!1},d(l){l&&nt(i),~t&&o[t].d(l)}}}function W_(r){let t=`${r[2]}-${r[5]}`,e,i,s=Fu(r);return{c(){s.c(),e=Ie()},m(n,o){s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&36&&te(t,t=`${n[2]}-${n[5]}`)?(xe(),dt(s,1,1,Ct),be(),s=Fu(n),s.c(),it(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s.d(n)}}}function Y_(r){let t,e,i=Ee(r[8]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Gu(Pu(r,i,o));const n=o=>dt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Ie()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a[0]&21107010){i=Ee(o[8]);let l;for(l=0;l<i.length;l+=1){const h=Pu(o,i,l);s[l]?(s[l].p(h,a),it(s[l],1)):(s[l]=Gu(h),s[l].c(),it(s[l],1),s[l].m(t.parentNode,t))}for(xe(),l=i.length;l<s.length;l+=1)n(l);be()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)it(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)dt(s[a]);e=!1},d(o){o&&nt(t),Jr(s,o)}}}function Fu(r){let t,e;return t=new g_({props:{target:r[6],tool:r[14],drawingMode:r[13],transform:r[12],viewportScale:r[17]}}),t.$on("create",r[21]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&64&&(n.target=i[6]),s[0]&16384&&(n.tool=i[14]),s[0]&8192&&(n.drawingMode=i[13]),s[0]&4096&&(n.transform=i[12]),s[0]&131072&&(n.viewportScale=i[17]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function Uu(r){let t=r[39].id,e,i,s=ku(r);return{c(){s.c(),e=Ie()},m(n,o){s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&256&&te(t,t=n[39].id)?(xe(),dt(s,1,1,Ct),be(),s=ku(n),s.c(),it(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s.d(n)}}}function ku(r){let t,e;return t=new p_({props:{target:r[6],editor:r[24](r[39].target.selector),annotation:r[39],style:r[1],transform:r[12],viewportScale:r[17]}}),t.$on("change",function(){$t(r[22](r[39]))&&r[22](r[39]).apply(this,arguments)}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&64&&(n.target=r[6]),s[0]&256&&(n.editor=r[24](r[39].target.selector)),s[0]&256&&(n.annotation=r[39]),s[0]&2&&(n.style=r[1]),s[0]&4096&&(n.transform=r[12]),s[0]&131072&&(n.viewportScale=r[17]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function Gu(r){let t,e,i=r[40]&&Uu(r);return{c(){i&&i.c(),t=Ie()},m(s,n){i&&i.m(s,n),ot(s,t,n),e=!0},p(s,n){s[40]?i?(i.p(s,n),n[0]&256&&it(i,1)):(i=Uu(s),i.c(),it(i,1),i.m(t.parentNode,t)):i&&(xe(),dt(i,1,1,()=>{i=null}),be())},i(s){e||(it(i),e=!0)},o(s){dt(i),e=!1},d(s){s&&nt(t),i&&i.d(s)}}}function j_(r){let t,e,i,s,n,o,a=Ee(r[16].filter(r[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=Lu(Ou(r,a,c));const h=c=>dt(l[c],1,1,()=>{l[c]=null});let u=r[6]&&Bu(r);return{c(){t=mt("svg"),e=mt("g");for(let c=0;c<l.length;c+=1)l[c].c();i=mt("g"),u&&u.c(),A(i,"class","drawing"),A(t,"class","a9s-annotationlayer"),Mr(t,"drawing",r[14]),Mr(t,"hidden",!r[3]),Mr(t,"hover",r[15])},m(c,d){ot(c,t,d),Oe(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);Oe(t,i),u&&u.m(i,null),r[35](i),r[36](t),s=!0,n||(o=[Bt(t,"pointerup",function(){$t(r[10])&&r[10].apply(this,arguments)}),Bt(t,"pointerdown",function(){$t(r[11])&&r[11].apply(this,arguments)}),Bt(t,"pointermove",r[23])],n=!0)},p(c,d){if(r=c,d[0]&66050){a=Ee(r[16].filter(r[34]));let p;for(p=0;p<a.length;p+=1){const f=Ou(r,a,p);l[p]?(l[p].p(f,d),it(l[p],1)):(l[p]=Lu(f),l[p].c(),it(l[p],1),l[p].m(e,null))}for(xe(),p=a.length;p<l.length;p+=1)h(p);be()}r[6]?u?(u.p(r,d),d[0]&64&&it(u,1)):(u=Bu(r),u.c(),it(u,1),u.m(i,null)):u&&(xe(),dt(u,1,1,()=>{u=null}),be()),(!s||d[0]&16384)&&Mr(t,"drawing",r[14]),(!s||d[0]&8)&&Mr(t,"hidden",!r[3]),(!s||d[0]&32768)&&Mr(t,"hover",r[15])},i(c){if(!s){for(let d=0;d<a.length;d+=1)it(l[d]);it(u),s=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)dt(l[d]);dt(u),s=!1},d(c){c&&nt(t),Jr(l,c),u&&u.d(),r[35](null),r[36](null),n=!1,Ue(o)}}}function q_(r,t,e){let i,s,n,o,a,l,h,u,c,d,p,f=Ct,m=()=>(f(),f=Dh(I,O=>e(17,p=O)),I);r.$$.on_destroy.push(()=>f());let{drawingEnabled:y}=t,{image:_}=t,{preferredDrawingMode:v}=t,{state:g}=t,{style:x=void 0}=t,{toolName:b=hn()[0]}=t,{user:S}=t,{visible:w=!0}=t,T=0;const N=()=>e(5,T+=1),F=()=>b,z=()=>y;let C,E,I;ms(()=>m(e(7,I=Zy(_,E))));const{hover:P,selection:$,store:k}=g;zo(r,P,O=>e(15,u=O)),zo(r,$,O=>e(33,c=O)),zo(r,k,O=>e(16,d=O));let G,st;const M=O=>{G&&k.unobserve(G);const D=O.filter(({editable:ut})=>ut).map(({id:ut})=>ut);D.length>0?(e(8,st=D.map(ut=>k.getAnnotation(ut)).filter(ut=>ut&&Ge(ut))),G=ut=>{const{updated:lt}=ut.changes;e(8,st=lt==null?void 0:lt.map(Et=>Et.newValue))},k.observe(G,{annotations:D})):e(8,st=void 0)},L=O=>{const D=ru(),ut={id:D,bodies:[],target:{annotation:D,selector:O.detail,creator:S,created:new Date}};k.addAnnotation(ut),$.setSelected(ut.id)},V=O=>D=>{var ut;const{target:lt}=O,Et=10*60*1e3,Tt=((ut=lt.creator)==null?void 0:ut.id)!==S.id||!lt.created||new Date().getTime()-lt.created.getTime()>Et;k.updateTarget({...lt,selector:D.detail,created:Tt?lt.created:new Date,updated:Tt?new Date:void 0,updatedBy:Tt?S:void 0})},rt=O=>{const{x:D,y:ut}=Mu(O,E),lt=k.getAt(D,ut);lt?u!==lt.id&&P.set(lt.id):P.set(void 0)},Q=O=>bu(O),X=O=>Ge(O);function _t(O){en[O?"unshift":"push"](()=>{C=O,e(6,C)})}function St(O){en[O?"unshift":"push"](()=>{E=O,e(4,E)})}return r.$$set=O=>{"drawingEnabled"in O&&e(0,y=O.drawingEnabled),"image"in O&&e(25,_=O.image),"preferredDrawingMode"in O&&e(26,v=O.preferredDrawingMode),"state"in O&&e(27,g=O.state),"style"in O&&e(1,x=O.style),"toolName"in O&&e(2,b=O.toolName),"user"in O&&e(28,S=O.user),"visible"in O&&e(3,w=O.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(14,{tool:i,opts:s}=un(b)||{tool:void 0,opts:void 0},i,(e(32,s),e(2,b))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(13,n=(s==null?void 0:s.drawingMode)||v),r.$$.dirty[0]&16&&e(12,o=k_(E)),r.$$.dirty[0]&16&&e(11,{onPointerDown:a,onPointerUp:l}=$_(E,k),a,(e(10,l),e(4,E))),r.$$.dirty[1]&4&&e(9,h=O=>c.selected.find(D=>D.id===O.id&&D.editable)),r.$$.dirty[1]&4&&M(c.selected)},[y,x,b,w,E,T,C,I,st,h,l,a,o,n,i,u,d,p,P,$,k,L,V,rt,Q,_,v,g,S,N,F,z,s,c,X,_t,St]}class K_ extends we{constructor(t){super(),Te(this,t,q_,j_,te,{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 $u(r,t,e=0,i=r.length-1,s=Z_){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,u=Math.log(l),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(l-c)/l)*(h-l/2<0?-1:1),p=Math.max(e,Math.floor(t-h*c/l+d)),f=Math.min(i,Math.floor(t+(l-h)*c/l+d));$u(r,t,p,f,s)}const n=r[t];let o=e,a=i;for(ys(r,e,t),s(r[i],n)>0&&ys(r,e,i);o<a;){for(ys(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?ys(r,e,a):(a++,ys(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function ys(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function Z_(r,t){return r<t?-1:r>t?1:0}class Q_{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 e=this.data;const i=[];if(!dn(t,e))return i;const s=this.toBBox,n=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?s(a):a;dn(t,l)&&(e.leaf?i.push(a):fa(t,l)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!dn(t,e))return!1;const i=[];for(;e;){for(let s=0;s<e.children.length;s++){const n=e.children[s],o=e.leaf?this.toBBox(n):n;if(dn(t,o)){if(e.leaf||fa(t,o))return!0;i.push(n)}}e=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 e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Di([]),this}remove(t,e){if(!t)return this;let i=this.data;const s=this.toBBox(t),n=[],o=[];let a,l,h;for(;i||n.length;){if(i||(i=n.pop(),l=n[n.length-1],a=o.pop(),h=!0),i.leaf){const u=J_(t,i.children,e);if(u!==-1)return i.children.splice(u,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&fa(i,s)?(n.push(i),o.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],h=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,s){const n=i-e+1;let o=this._maxEntries,a;if(n<=o)return a=Di(t.slice(e,i+1)),Ni(a,this.toBBox),a;s||(s=Math.ceil(Math.log(n)/Math.log(o)),o=Math.ceil(n/Math.pow(o,s-1))),a=Di([]),a.leaf=!1,a.height=s;const l=Math.ceil(n/o),h=l*Math.ceil(Math.sqrt(o));Hu(t,e,i,h,this.compareMinX);for(let u=e;u<=i;u+=h){const c=Math.min(u+h-1,i);Hu(t,u,c,l,this.compareMinY);for(let d=u;d<=c;d+=l){const p=Math.min(d+l-1,c);a.children.push(this._build(t,d,p,s-1))}}return Ni(a,this.toBBox),a}_chooseSubtree(t,e,i,s){for(;s.push(e),!(e.leaf||s.length-1===i);){let n=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],u=da(h),c=r0(t,h)-u;c<o?(o=c,n=u<n?u:n,a=h):c===o&&u<n&&(n=u,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const s=i?t:this.toBBox(t),n=[],o=this._chooseSubtree(s,this.data,e,n);for(o.children.push(t),vs(o,s);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(s,n,e)}_split(t,e){const i=t[e],s=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,s);const o=this._chooseSplitIndex(i,n,s),a=Di(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Ni(i,this.toBBox),Ni(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Di([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Ni(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let s,n=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=_s(t,0,a,this.toBBox),h=_s(t,a,i,this.toBBox),u=i0(l,h),c=da(l)+da(h);u<n?(n=u,s=a,o=c<o?c:o):u===n&&c<o&&(o=c,s=a)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:t0,n=t.leaf?this.compareMinY:e0,o=this._allDistMargin(t,e,i,s),a=this._allDistMargin(t,e,i,n);o<a&&t.children.sort(s)}_allDistMargin(t,e,i,s){t.children.sort(s);const n=this.toBBox,o=_s(t,0,e,n),a=_s(t,i-e,i,n);let l=cn(o)+cn(a);for(let h=e;h<i-e;h++){const u=t.children[h];vs(o,t.leaf?n(u):u),l+=cn(o)}for(let h=i-e-1;h>=e;h--){const u=t.children[h];vs(a,t.leaf?n(u):u),l+=cn(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)vs(e[s],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():Ni(t[e],this.toBBox)}}function J_(r,t,e){if(!e)return t.indexOf(r);for(let i=0;i<t.length;i++)if(e(r,t[i]))return i;return-1}function Ni(r,t){_s(r,0,r.children.length,t,r)}function _s(r,t,e,i,s){s||(s=Di(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let n=t;n<e;n++){const o=r.children[n];vs(s,r.leaf?i(o):o)}return s}function vs(r,t){return r.minX=Math.min(r.minX,t.minX),r.minY=Math.min(r.minY,t.minY),r.maxX=Math.max(r.maxX,t.maxX),r.maxY=Math.max(r.maxY,t.maxY),r}function t0(r,t){return r.minX-t.minX}function e0(r,t){return r.minY-t.minY}function da(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function cn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function r0(r,t){return(Math.max(t.maxX,r.maxX)-Math.min(t.minX,r.minX))*(Math.max(t.maxY,r.maxY)-Math.min(t.minY,r.minY))}function i0(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),s=Math.min(r.maxX,t.maxX),n=Math.min(r.maxY,t.maxY);return Math.max(0,s-e)*Math.max(0,n-i)}function fa(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function dn(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Di(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Hu(r,t,e,i,s){const n=[t,e];for(;n.length;){if(e=n.pop(),t=n.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;$u(r,o,t,e,s),n.push(t,o,o,e)}}const s0=()=>{const r=new Q_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},s=o=>{if(!nn(o))return;const{minX:a,minY:l,maxX:h,maxY:u}=o.selector.geometry.bounds,c={minX:a,minY:l,maxX:h,maxY:u,target:o};r.insert(c),t.set(o.annotation,c)},n=o=>{if(!nn(o))return;const a=t.get(o.annotation);a&&r.remove(a),t.delete(o.annotation)};return{all:e,clear:i,getAt:(o,a)=>{const l=r.search({minX:o,minY:a,maxX:o,maxY:a}).map(h=>h.target).filter(h=>h.selector.type===vt.RECTANGLE||vg(h.selector,o,a));if(l.length>0)return l.sort((h,u)=>Ko(h.selector)-Ko(u.selector)),l[0]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(u=>u.target),insert:s,remove:n,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,u)=>{if(nn(u)){const{minX:c,minY:d,maxX:p,maxY:f}=u.selector.geometry.bounds;return[...h,{minX:c,minY:d,maxX:p,maxY:f,target:u}]}else return h},[]);l.forEach(h=>t.set(h.target.annotation,h)),r.load(l)},size:()=>r.all().length,update:(o,a)=>{n(o),s(a)}}},Vu=r=>{const t=Ey(),e=s0(),i=hy(t,r.userSelectAction,r.adapter),s=ly(t),n=Cy();return t.observe(({changes:o})=>{e.set((o.created||[]).map(a=>a.target),!1),(o.deleted||[]).forEach(a=>e.remove(a.target)),(o.updated||[]).forEach(({oldValue:a,newValue:l})=>e.update(a.target,l.target))}),{store:{...t,getAt:(o,a)=>{const l=e.getAt(o,a);return l?t.getAnnotation(l.annotation):void 0},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(u=>t.getAnnotation(u.annotation))},selection:i,hover:s,viewport:n}},n0=r=>{const t=Vu(r);return{...t,store:Ty(t.store)}},o0=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const s=r;t=document.createElement("canvas"),t.width=s.width,t.height=s.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(s,0,0,s.width,s.height)}let i=0;for(let s=1;s<10;s++)for(let n=1;n<10;n++){const o=Math.round(n*t.width/10),a=Math.round(s*t.height/10),l=e.getImageData(o,a,1,1).data,h=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=h}return i/81},Xu=r=>{const t=o0(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},zu=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?Xu(r):e),Wu=(r,t)=>({...r,drawingEnabled:r.drawingEnabled===void 0?t.drawingEnabled:r.drawingEnabled,drawingMode:r.drawingMode||t.drawingMode,userSelectAction:r.userSelectAction||t.userSelectAction,theme:r.theme||t.theme}),Yu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,ju=(r,t)=>{const e=t||document,i=o=>{const a=o;a.key==="z"&&a.ctrlKey?r.undo():a.key==="y"&&a.ctrlKey&&r.redo()},s=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},n=()=>{Yu?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Yu?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},a0=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=Wu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:su.EDIT,theme:"light"}),s=n0(i),{selection:n,store:o}=s,a=Sy(o,i.initialHistory),l=Iy(s,a,i.adapter,i.autoSave),h=document.createElement("DIV");h.style.position="relative",h.style.display="inline-block",e.style.display="block",e.parentNode.insertBefore(h,e),h.appendChild(e);const u=ju(a);let c=Uy();zu(e,h,i.theme);const d=new K_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:c}});d.$on("click",C=>{const{originalEvent:E,annotation:I}=C.detail;I?n.userSelect(I.id,E):n.isEmpty()||n.clear()});const p=My(s,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),u.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>c,v=()=>d.isDrawingEnabled(),g=(C,E,I)=>Cu(C,E,I),x=(C,E)=>Eu(C,E),b=C=>{if(!un(C))throw`No drawing tool named ${C}`;d.$set({toolName:C})},S=C=>d.$set({drawingEnabled:C}),w=C=>{console.warn("Filter not implemented yet")},T=C=>d.$set({style:C}),N=C=>zu(e,h,C),F=C=>{c=C,d.$set({user:C})},z=C=>d.$set({visible:C});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:hn,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:x,setDrawingEnabled:S,setDrawingTool:b,setFilter:w,setStyle:T,setTheme:N,setUser:F,setVisible:z,element:h,state:s}};function me(){}function pa(r,t){for(const e in t)r[e]=t[e];return r}function qu(r){return r()}function Ku(){return Object.create(null)}function er(r){r.forEach(qu)}function Kt(r){return typeof r=="function"}function Wt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function l0(r){return Object.keys(r).length===0}function h0(r,...t){if(r==null){for(const i of t)i(void 0);return me}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function fn(r,t,e){r.$$.on_destroy.push(h0(t,e))}function Zu(r,t,e,i){if(r){const s=Qu(r,t,e,i);return r[0](s)}}function Qu(r,t,e,i){return r[1]&&i?pa(e.ctx.slice(),r[1](i(t))):e.ctx}function Ju(r,t,e,i){if(r[2]&&i){const s=r[2](i(e));if(t.dirty===void 0)return s;if(typeof s=="object"){const n=[],o=Math.max(t.dirty.length,s.length);for(let a=0;a<o;a+=1)n[a]=t.dirty[a]|s[a];return n}return t.dirty|s}return t.dirty}function tc(r,t,e,i,s,n){if(s){const o=Qu(t,e,i,n);r.p(o,s)}}function ec(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function rc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function pn(r){return r??""}const ic=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ae(r,t){r.appendChild(t)}function ct(r,t,e){r.insertBefore(t,e||null)}function ht(r){r.parentNode&&r.parentNode.removeChild(r)}function ii(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function xt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ma(r){return document.createTextNode(r)}function Ve(){return ma(" ")}function Re(){return ma("")}function Zt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function R(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function u0(r){return Array.from(r.childNodes)}function c0(r,t){t=""+t,r.data!==t&&(r.data=t)}function mn(r,t,e){r.classList.toggle(t,!!e)}function d0(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let xs;function bs(r){xs=r}function ga(){if(!xs)throw new Error("Function called outside component initialization");return xs}function gn(r){ga().$$.on_mount.push(r)}function f0(r){ga().$$.on_destroy.push(r)}function yn(){const r=ga();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=d0(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function De(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Li=[],_n=[];let Bi=[];const sc=[],p0=Promise.resolve();let ya=!1;function m0(){ya||(ya=!0,p0.then(nc))}function _a(r){Bi.push(r)}const va=new Set;let Fi=0;function nc(){if(Fi!==0)return;const r=xs;do{try{for(;Fi<Li.length;){const t=Li[Fi];Fi++,bs(t),g0(t.$$)}}catch(t){throw Li.length=0,Fi=0,t}for(bs(null),Li.length=0,Fi=0;_n.length;)_n.pop()();for(let t=0;t<Bi.length;t+=1){const e=Bi[t];va.has(e)||(va.add(e),e())}Bi.length=0}while(Li.length);for(;sc.length;)sc.pop()();ya=!1,va.clear(),bs(r)}function g0(r){if(r.fragment!==null){r.update(),er(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(_a)}}function y0(r){const t=[],e=[];Bi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Bi=t}const vn=new Set;let si;function ge(){si={r:0,c:[],p:si}}function ye(){si.r||er(si.c),si=si.p}function q(r,t){r&&r.i&&(vn.delete(r),r.i(t))}function et(r,t,e,i){if(r&&r.o){if(vn.has(r))return;vn.add(r),si.c.push(()=>{vn.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Se(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Ht(r){r&&r.c()}function Ft(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),_a(()=>{const n=r.$$.on_mount.map(qu).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...n):er(n),r.$$.on_mount=[]}),s.forEach(_a)}function Ut(r,t){const e=r.$$;e.fragment!==null&&(y0(e.after_update),er(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function _0(r,t){r.$$.dirty[0]===-1&&(Li.push(r),m0(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ee(r,t,e,i,s,n,o=null,a=[-1]){const l=xs;bs(r);const h=r.$$={fragment:null,ctx:[],props:n,update:me,not_equal:s,bound:Ku(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Ku(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let u=!1;if(h.ctx=e?e(r,t.props||{},(c,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&s(h.ctx[c],h.ctx[c]=f)&&(!h.skip_bound&&h.bound[c]&&h.bound[c](f),u&&_0(r,c)),d}):[],h.update(),u=!0,er(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=u0(t.target);h.fragment&&h.fragment.l(c),c.forEach(ht)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Ft(r,t.target,t.anchor),nc()}bs(l)}class re{constructor(){Pt(this,"$$");Pt(this,"$$set")}$destroy(){Ut(this,1),this.$destroy=me}$on(t,e){if(!Kt(e))return me;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const s=i.indexOf(e);s!==-1&&i.splice(s,1)}}$set(t){this.$$set&&!l0(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const v0="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(v0);var ni=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(ni||{}),oc=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(oc||{}),xa=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(xa||{}),at=(r=>(r[r.NORMAL=0]="NORMAL",r[r.ADD=1]="ADD",r[r.MULTIPLY=2]="MULTIPLY",r[r.SCREEN=3]="SCREEN",r[r.OVERLAY=4]="OVERLAY",r[r.DARKEN=5]="DARKEN",r[r.LIGHTEN=6]="LIGHTEN",r[r.COLOR_DODGE=7]="COLOR_DODGE",r[r.COLOR_BURN=8]="COLOR_BURN",r[r.HARD_LIGHT=9]="HARD_LIGHT",r[r.SOFT_LIGHT=10]="SOFT_LIGHT",r[r.DIFFERENCE=11]="DIFFERENCE",r[r.EXCLUSION=12]="EXCLUSION",r[r.HUE=13]="HUE",r[r.SATURATION=14]="SATURATION",r[r.COLOR=15]="COLOR",r[r.LUMINOSITY=16]="LUMINOSITY",r[r.NORMAL_NPM=17]="NORMAL_NPM",r[r.ADD_NPM=18]="ADD_NPM",r[r.SCREEN_NPM=19]="SCREEN_NPM",r[r.NONE=20]="NONE",r[r.SRC_OVER=0]="SRC_OVER",r[r.SRC_IN=21]="SRC_IN",r[r.SRC_OUT=22]="SRC_OUT",r[r.SRC_ATOP=23]="SRC_ATOP",r[r.DST_OVER=24]="DST_OVER",r[r.DST_IN=25]="DST_IN",r[r.DST_OUT=26]="DST_OUT",r[r.DST_ATOP=27]="DST_ATOP",r[r.ERASE=26]="ERASE",r[r.SUBTRACT=28]="SUBTRACT",r[r.XOR=29]="XOR",r))(at||{}),rr=(r=>(r[r.POINTS=0]="POINTS",r[r.LINES=1]="LINES",r[r.LINE_LOOP=2]="LINE_LOOP",r[r.LINE_STRIP=3]="LINE_STRIP",r[r.TRIANGLES=4]="TRIANGLES",r[r.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",r[r.TRIANGLE_FAN=6]="TRIANGLE_FAN",r))(rr||{}),H=(r=>(r[r.RGBA=6408]="RGBA",r[r.RGB=6407]="RGB",r[r.RG=33319]="RG",r[r.RED=6403]="RED",r[r.RGBA_INTEGER=36249]="RGBA_INTEGER",r[r.RGB_INTEGER=36248]="RGB_INTEGER",r[r.RG_INTEGER=33320]="RG_INTEGER",r[r.RED_INTEGER=36244]="RED_INTEGER",r[r.ALPHA=6406]="ALPHA",r[r.LUMINANCE=6409]="LUMINANCE",r[r.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",r[r.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",r[r.DEPTH_STENCIL=34041]="DEPTH_STENCIL",r))(H||{}),Ui=(r=>(r[r.TEXTURE_2D=3553]="TEXTURE_2D",r[r.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",r[r.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",r[r.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",r[r.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",r[r.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",r[r.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",r))(Ui||{}),tt=(r=>(r[r.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",r[r.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",r[r.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",r[r.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",r[r.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",r[r.UNSIGNED_INT=5125]="UNSIGNED_INT",r[r.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",r[r.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",r[r.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",r[r.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",r[r.BYTE=5120]="BYTE",r[r.SHORT=5122]="SHORT",r[r.INT=5124]="INT",r[r.FLOAT=5126]="FLOAT",r[r.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",r[r.HALF_FLOAT=36193]="HALF_FLOAT",r))(tt||{}),Y=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Y||{}),vr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(vr||{}),Dr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Dr||{}),ir=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(ir||{}),Ce=(r=>(r[r.NPM=0]="NPM",r[r.UNPACK=1]="UNPACK",r[r.PMA=2]="PMA",r[r.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",r[r.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",r[r.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA",r))(Ce||{}),sr=(r=>(r[r.NO=0]="NO",r[r.YES=1]="YES",r[r.AUTO=2]="AUTO",r[r.BLEND=0]="BLEND",r[r.CLEAR=1]="CLEAR",r[r.BLIT=2]="BLIT",r))(sr||{}),ba=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(ba||{}),Le=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(Le||{}),Qt=(r=>(r[r.NONE=0]="NONE",r[r.SCISSOR=1]="SCISSOR",r[r.STENCIL=2]="STENCIL",r[r.SPRITE=3]="SPRITE",r[r.COLOR=4]="COLOR",r))(Qt||{}),Yt=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(Yt||{}),nr=(r=>(r[r.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",r[r.ARRAY_BUFFER=34962]="ARRAY_BUFFER",r[r.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",r))(nr||{});const j={ADAPTER:{createCanvas:(r,t)=>{const e=document.createElement("canvas");return e.width=r,e.height=t,e},getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(r,t)=>fetch(r,t),parseXML:r=>new DOMParser().parseFromString(r,"text/xml")},RESOLUTION:1,CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1};var Ea=/iPhone/i,ac=/iPod/i,lc=/iPad/i,hc=/\biOS-universal(?:.+)Mac\b/i,Ta=/\bAndroid(?:.+)Mobile\b/i,uc=/Android/i,ki=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,xn=/Silk/i,xr=/Windows Phone/i,cc=/\bWindows(?:.+)ARM\b/i,dc=/BlackBerry/i,fc=/BB10/i,pc=/Opera Mini/i,mc=/\b(CriOS|Chrome)(?:.+)Mobile/i,gc=/Mobile(?:.+)Firefox\b/i,yc=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function x0(r){return function(t){return t.test(r)}}function _c(r){var t={userAgent:"",platform:"",maxTouchPoints:0};!r&&typeof navigator<"u"?t={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof r=="string"?t.userAgent=r:r&&r.userAgent&&(t={userAgent:r.userAgent,platform:r.platform,maxTouchPoints:r.maxTouchPoints||0});var e=t.userAgent,i=e.split("[FBAN");typeof i[1]<"u"&&(e=i[0]),i=e.split("Twitter"),typeof i[1]<"u"&&(e=i[0]);var s=x0(e),n={apple:{phone:s(Ea)&&!s(xr),ipod:s(ac),tablet:!s(Ea)&&(s(lc)||yc(t))&&!s(xr),universal:s(hc),device:(s(Ea)||s(ac)||s(lc)||s(hc)||yc(t))&&!s(xr)},amazon:{phone:s(ki),tablet:!s(ki)&&s(xn),device:s(ki)||s(xn)},android:{phone:!s(xr)&&s(ki)||!s(xr)&&s(Ta),tablet:!s(xr)&&!s(ki)&&!s(Ta)&&(s(xn)||s(uc)),device:!s(xr)&&(s(ki)||s(xn)||s(Ta)||s(uc))||s(/\bokhttp\b/i)},windows:{phone:s(xr),tablet:s(cc),device:s(xr)||s(cc)},other:{blackberry:s(dc),blackberry10:s(fc),opera:s(pc),firefox:s(gc),chrome:s(mc),device:s(dc)||s(fc)||s(pc)||s(gc)||s(mc)},any:!1,phone:!1,tablet:!1};return n.any=n.apple.device||n.android.device||n.windows.device||n.other.device,n.phone=n.apple.phone||n.android.phone||n.windows.phone,n.tablet=n.apple.tablet||n.android.tablet||n.windows.tablet,n}const b0=_c.default??_c,br=b0(globalThis.navigator);j.RETINA_PREFIX=/@([0-9\.]+)x/,j.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Es=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vc(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function E0(r){if(r.__esModule)return r;var t=r.default;if(typeof t=="function"){var e=function i(){return this instanceof i?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(i){var s=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return r[i]}})}),e}var xc={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(l,h,u){this.fn=l,this.context=h,this.once=u||!1}function n(l,h,u,c,d){if(typeof u!="function")throw new TypeError("The listener must be a function");var p=new s(u,c||l,d),f=e?e+h:h;return l._events[f]?l._events[f].fn?l._events[f]=[l._events[f],p]:l._events[f].push(p):(l._events[f]=p,l._eventsCount++),l}function o(l,h){--l._eventsCount===0?l._events=new i:delete l._events[h]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var h=[],u,c;if(this._eventsCount===0)return h;for(c in u=this._events)t.call(u,c)&&h.push(e?c.slice(1):c);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(u)):h},a.prototype.listeners=function(h){var u=e?e+h:h,c=this._events[u];if(!c)return[];if(c.fn)return[c.fn];for(var d=0,p=c.length,f=new Array(p);d<p;d++)f[d]=c[d].fn;return f},a.prototype.listenerCount=function(h){var u=e?e+h:h,c=this._events[u];return c?c.fn?1:c.length:0},a.prototype.emit=function(h,u,c,d,p,f){var m=e?e+h:h;if(!this._events[m])return!1;var y=this._events[m],_=arguments.length,v,g;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,u),!0;case 3:return y.fn.call(y.context,u,c),!0;case 4:return y.fn.call(y.context,u,c,d),!0;case 5:return y.fn.call(y.context,u,c,d,p),!0;case 6:return y.fn.call(y.context,u,c,d,p,f),!0}for(g=1,v=new Array(_-1);g<_;g++)v[g-1]=arguments[g];y.fn.apply(y.context,v)}else{var x=y.length,b;for(g=0;g<x;g++)switch(y[g].once&&this.removeListener(h,y[g].fn,void 0,!0),_){case 1:y[g].fn.call(y[g].context);break;case 2:y[g].fn.call(y[g].context,u);break;case 3:y[g].fn.call(y[g].context,u,c);break;case 4:y[g].fn.call(y[g].context,u,c,d);break;default:if(!v)for(b=1,v=new Array(_-1);b<_;b++)v[b-1]=arguments[b];y[g].fn.apply(y[g].context,v)}}return!0},a.prototype.on=function(h,u,c){return n(this,h,u,c,!1)},a.prototype.once=function(h,u,c){return n(this,h,u,c,!0)},a.prototype.removeListener=function(h,u,c,d){var p=e?e+h:h;if(!this._events[p])return this;if(!u)return o(this,p),this;var f=this._events[p];if(f.fn)f.fn===u&&(!d||f.once)&&(!c||f.context===c)&&o(this,p);else{for(var m=0,y=[],_=f.length;m<_;m++)(f[m].fn!==u||d&&!f[m].once||c&&f[m].context!==c)&&y.push(f[m]);y.length?this._events[p]=y.length===1?y[0]:y:o(this,p)}return this},a.prototype.removeAllListeners=function(h){var u;return h?(u=e?e+h:h,this._events[u]&&o(this,u)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,r.exports=a})(xc);var T0=xc.exports;const Ts=vc(T0);var wa={exports:{}};wa.exports=bn,wa.exports.default=bn;function bn(r,t,e){e=e||2;var i=t&&t.length,s=i?t[0]*e:r.length,n=bc(r,0,s,e,!0),o=[];if(!n||n.next===n.prev)return o;var a,l,h,u,c,d,p;if(i&&(n=I0(r,t,n,e)),r.length>80*e){a=h=r[0],l=u=r[1];for(var f=e;f<s;f+=e)c=r[f],d=r[f+1],c<a&&(a=c),d<l&&(l=d),c>h&&(h=c),d>u&&(u=d);p=Math.max(h-a,u-l),p=p!==0?32767/p:0}return ws(n,o,e,a,l,p,0),o}function bc(r,t,e,i,s){var n,o;if(s===Ca(r,t,e,i)>0)for(n=t;n<e;n+=i)o=wc(n,r[n],r[n+1],o);else for(n=e-i;n>=t;n-=i)o=wc(n,r[n],r[n+1],o);return o&&En(o,o.next)&&(Ss(o),o=o.next),o}function oi(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(En(e,e.next)||Nt(e.prev,e,e.next)===0)){if(Ss(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function ws(r,t,e,i,s,n,o){if(r){!o&&n&&N0(r,i,s,n);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,n?A0(r,i,s,n):w0(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Ss(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=S0(oi(r),t,e),ws(r,t,e,i,s,n,2)):o===2&&C0(r,t,e,i,s,n):ws(oi(r),t,e,i,s,n,1);break}}}}function w0(r){var t=r.prev,e=r,i=r.next;if(Nt(t,e,i)>=0)return!1;for(var s=t.x,n=e.x,o=i.x,a=t.y,l=e.y,h=i.y,u=s<n?s<o?s:o:n<o?n:o,c=a<l?a<h?a:h:l<h?l:h,d=s>n?s>o?s:o:n>o?n:o,p=a>l?a>h?a:h:l>h?l:h,f=i.next;f!==t;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&Gi(s,a,n,l,o,h,f.x,f.y)&&Nt(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function A0(r,t,e,i){var s=r.prev,n=r,o=r.next;if(Nt(s,n,o)>=0)return!1;for(var a=s.x,l=n.x,h=o.x,u=s.y,c=n.y,d=o.y,p=a<l?a<h?a:h:l<h?l:h,f=u<c?u<d?u:d:c<d?c:d,m=a>l?a>h?a:h:l>h?l:h,y=u>c?u>d?u:d:c>d?c:d,_=Aa(p,f,t,e,i),v=Aa(m,y,t,e,i),g=r.prevZ,x=r.nextZ;g&&g.z>=_&&x&&x.z<=v;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==s&&g!==o&&Gi(a,u,l,c,h,d,g.x,g.y)&&Nt(g.prev,g,g.next)>=0||(g=g.prevZ,x.x>=p&&x.x<=m&&x.y>=f&&x.y<=y&&x!==s&&x!==o&&Gi(a,u,l,c,h,d,x.x,x.y)&&Nt(x.prev,x,x.next)>=0))return!1;x=x.nextZ}for(;g&&g.z>=_;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==s&&g!==o&&Gi(a,u,l,c,h,d,g.x,g.y)&&Nt(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;x&&x.z<=v;){if(x.x>=p&&x.x<=m&&x.y>=f&&x.y<=y&&x!==s&&x!==o&&Gi(a,u,l,c,h,d,x.x,x.y)&&Nt(x.prev,x,x.next)>=0)return!1;x=x.nextZ}return!0}function S0(r,t,e){var i=r;do{var s=i.prev,n=i.next.next;!En(s,n)&&Ec(s,i,i.next,n)&&As(s,n)&&As(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),Ss(i),Ss(i.next),i=r=n),i=i.next}while(i!==r);return oi(i)}function C0(r,t,e,i,s,n){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&B0(o,a)){var l=Tc(o,a);o=oi(o,o.next),l=oi(l,l.next),ws(o,t,e,i,s,n,0),ws(l,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function I0(r,t,e,i){var s=[],n,o,a,l,h;for(n=0,o=t.length;n<o;n++)a=t[n]*i,l=n<o-1?t[n+1]*i:r.length,h=bc(r,a,l,i,!1),h===h.next&&(h.steiner=!0),s.push(L0(h));for(s.sort(R0),n=0;n<s.length;n++)e=M0(s[n],e);return e}function R0(r,t){return r.x-t.x}function M0(r,t){var e=P0(r,t);if(!e)return t;var i=Tc(e,r);return oi(i,i.next),oi(e,e.next)}function P0(r,t){var e=t,i=r.x,s=r.y,n=-1/0,o;do{if(s<=e.y&&s>=e.next.y&&e.next.y!==e.y){var a=e.x+(s-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>n&&(n=a,o=e.x<e.next.x?e:e.next,a===i))return o}e=e.next}while(e!==t);if(!o)return null;var l=o,h=o.x,u=o.y,c=1/0,d;e=o;do i>=e.x&&e.x>=h&&i!==e.x&&Gi(s<u?i:n,s,h,u,s<u?n:i,s,e.x,e.y)&&(d=Math.abs(s-e.y)/(i-e.x),As(e,r)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&O0(o,e)))&&(o=e,c=d)),e=e.next;while(e!==l);return o}function O0(r,t){return Nt(r.prev,r,t.prev)<0&&Nt(t.next,r,r.next)<0}function N0(r,t,e,i){var s=r;do s.z===0&&(s.z=Aa(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==r);s.prevZ.nextZ=null,s.prevZ=null,D0(s)}function D0(r){var t,e,i,s,n,o,a,l,h=1;do{for(e=r,r=null,n=null,o=0;e;){for(o++,i=e,a=0,t=0;t<h&&(a++,i=i.nextZ,!!i);t++);for(l=h;a>0||l>0&&i;)a!==0&&(l===0||!i||e.z<=i.z)?(s=e,e=e.nextZ,a--):(s=i,i=i.nextZ,l--),n?n.nextZ=s:r=s,s.prevZ=n,n=s;e=i}n.nextZ=null,h*=2}while(o>1);return r}function Aa(r,t,e,i,s){return r=(r-e)*s|0,t=(t-i)*s|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function L0(r){var t=r,e=r;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==r);return e}function Gi(r,t,e,i,s,n,o,a){return(s-o)*(t-a)>=(r-o)*(n-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(n-a)>=(s-o)*(i-a)}function B0(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!F0(r,t)&&(As(r,t)&&As(t,r)&&U0(r,t)&&(Nt(r.prev,r,t.prev)||Nt(r,t.prev,t))||En(r,t)&&Nt(r.prev,r,r.next)>0&&Nt(t.prev,t,t.next)>0)}function Nt(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function En(r,t){return r.x===t.x&&r.y===t.y}function Ec(r,t,e,i){var s=wn(Nt(r,t,e)),n=wn(Nt(r,t,i)),o=wn(Nt(e,i,r)),a=wn(Nt(e,i,t));return!!(s!==n&&o!==a||s===0&&Tn(r,e,t)||n===0&&Tn(r,i,t)||o===0&&Tn(e,r,i)||a===0&&Tn(e,t,i))}function Tn(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function wn(r){return r>0?1:r<0?-1:0}function F0(r,t){var e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&Ec(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function As(r,t){return Nt(r.prev,r,r.next)<0?Nt(r,t,r.next)>=0&&Nt(r,r.prev,t)>=0:Nt(r,t,r.prev)<0||Nt(r,r.next,t)<0}function U0(r,t){var e=r,i=!1,s=(r.x+t.x)/2,n=(r.y+t.y)/2;do e.y>n!=e.next.y>n&&e.next.y!==e.y&&s<(e.next.x-e.x)*(n-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function Tc(r,t){var e=new Sa(r.i,r.x,r.y),i=new Sa(t.i,t.x,t.y),s=r.next,n=t.prev;return r.next=t,t.prev=r,e.next=s,s.prev=e,i.next=e,e.prev=i,n.next=i,i.prev=n,i}function wc(r,t,e,i){var s=new Sa(r,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Ss(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function Sa(r,t,e){this.i=r,this.x=t,this.y=e,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}bn.deviation=function(r,t,e,i){var s=t&&t.length,n=s?t[0]*e:r.length,o=Math.abs(Ca(r,0,n,e));if(s)for(var a=0,l=t.length;a<l;a++){var h=t[a]*e,u=a<l-1?t[a+1]*e:r.length;o-=Math.abs(Ca(r,h,u,e))}var c=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,p=i[a+1]*e,f=i[a+2]*e;c+=Math.abs((r[d]-r[f])*(r[p+1]-r[d+1])-(r[d]-r[p])*(r[f+1]-r[d+1]))}return o===0&&c===0?0:Math.abs((c-o)/o)};function Ca(r,t,e,i){for(var s=0,n=t,o=e-i;n<e;n+=i)s+=(r[o]-r[n])*(r[n+1]+r[o+1]),o=n;return s}bn.flatten=function(r){for(var t=r[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,s=0;s<r.length;s++){for(var n=0;n<r[s].length;n++)for(var o=0;o<t;o++)e.vertices.push(r[s][n][o]);s>0&&(i+=r[s-1].length,e.holes.push(i))}return e};var k0=wa.exports;const G0=vc(k0);var An={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */An.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,s=r&&!r.nodeType&&r,n=typeof Es=="object"&&Es;(n.global===n||n.window===n||n.self===n)&&(e=n);var o,a=2147483647,l=36,h=1,u=26,c=38,d=700,p=72,f=128,m="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},x=l-h,b=Math.floor,S=String.fromCharCode,w;function T(M){throw new RangeError(g[M])}function N(M,L){for(var V=M.length,rt=[];V--;)rt[V]=L(M[V]);return rt}function F(M,L){var V=M.split("@"),rt="";V.length>1&&(rt=V[0]+"@",M=V[1]),M=M.replace(v,".");var Q=M.split("."),X=N(Q,L).join(".");return rt+X}function z(M){for(var L=[],V=0,rt=M.length,Q,X;V<rt;)Q=M.charCodeAt(V++),Q>=55296&&Q<=56319&&V<rt?(X=M.charCodeAt(V++),(X&64512)==56320?L.push(((Q&1023)<<10)+(X&1023)+65536):(L.push(Q),V--)):L.push(Q);return L}function C(M){return N(M,function(L){var V="";return L>65535&&(L-=65536,V+=S(L>>>10&1023|55296),L=56320|L&1023),V+=S(L),V}).join("")}function E(M){return M-48<10?M-22:M-65<26?M-65:M-97<26?M-97:l}function I(M,L){return M+22+75*(M<26)-((L!=0)<<5)}function P(M,L,V){var rt=0;for(M=V?b(M/d):M>>1,M+=b(M/L);M>x*u>>1;rt+=l)M=b(M/x);return b(rt+(x+1)*M/(M+c))}function $(M){var L=[],V=M.length,rt,Q=0,X=f,_t=p,St,O,D,ut,lt,Et,Tt,mr,gr;for(St=M.lastIndexOf(m),St<0&&(St=0),O=0;O<St;++O)M.charCodeAt(O)>=128&&T("not-basic"),L.push(M.charCodeAt(O));for(D=St>0?St+1:0;D<V;){for(ut=Q,lt=1,Et=l;D>=V&&T("invalid-input"),Tt=E(M.charCodeAt(D++)),(Tt>=l||Tt>b((a-Q)/lt))&&T("overflow"),Q+=Tt*lt,mr=Et<=_t?h:Et>=_t+u?u:Et-_t,!(Tt<mr);Et+=l)gr=l-mr,lt>b(a/gr)&&T("overflow"),lt*=gr;rt=L.length+1,_t=P(Q-ut,rt,ut==0),b(Q/rt)>a-X&&T("overflow"),X+=b(Q/rt),Q%=rt,L.splice(Q++,0,X)}return C(L)}function k(M){var L,V,rt,Q,X,_t,St,O,D,ut,lt,Et=[],Tt,mr,gr,js;for(M=z(M),Tt=M.length,L=f,V=0,X=p,_t=0;_t<Tt;++_t)lt=M[_t],lt<128&&Et.push(S(lt));for(rt=Q=Et.length,Q&&Et.push(m);rt<Tt;){for(St=a,_t=0;_t<Tt;++_t)lt=M[_t],lt>=L&&lt<St&&(St=lt);for(mr=rt+1,St-L>b((a-V)/mr)&&T("overflow"),V+=(St-L)*mr,L=St,_t=0;_t<Tt;++_t)if(lt=M[_t],lt<L&&++V>a&&T("overflow"),lt==L){for(O=V,D=l;ut=D<=X?h:D>=X+u?u:D-X,!(O<ut);D+=l)js=O-ut,gr=l-ut,Et.push(S(I(ut+js%gr,0))),O=b(js/gr);Et.push(S(I(O,0))),X=P(V,mr,rt==Q),V=0,++rt}++V,++L}return Et.join("")}function G(M){return F(M,function(L){return y.test(L)?$(L.slice(4).toLowerCase()):L})}function st(M){return F(M,function(L){return _.test(L)?"xn--"+k(L):L})}if(o={version:"1.4.1",ucs2:{decode:z,encode:C},decode:$,encode:k,toASCII:st,toUnicode:G},i&&s)if(r.exports==i)s.exports=o;else for(w in o)o.hasOwnProperty(w)&&(i[w]=o[w]);else e.punycode=o})(Es)}(An,An.exports);var $0=An.exports,$i=TypeError;const H0=E0(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Ia=typeof Map=="function"&&Map.prototype,Ra=Object.getOwnPropertyDescriptor&&Ia?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Sn=Ia&&Ra&&typeof Ra.get=="function"?Ra.get:null,Ac=Ia&&Map.prototype.forEach,Ma=typeof Set=="function"&&Set.prototype,Pa=Object.getOwnPropertyDescriptor&&Ma?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Cn=Ma&&Pa&&typeof Pa.get=="function"?Pa.get:null,Sc=Ma&&Set.prototype.forEach,V0=typeof WeakMap=="function"&&WeakMap.prototype,Cs=V0?WeakMap.prototype.has:null,X0=typeof WeakSet=="function"&&WeakSet.prototype,Is=X0?WeakSet.prototype.has:null,z0=typeof WeakRef=="function"&&WeakRef.prototype,Cc=z0?WeakRef.prototype.deref:null,W0=Boolean.prototype.valueOf,Y0=Object.prototype.toString,j0=Function.prototype.toString,q0=String.prototype.match,Oa=String.prototype.slice,Lr=String.prototype.replace,K0=String.prototype.toUpperCase,Ic=String.prototype.toLowerCase,Rc=RegExp.prototype.test,Mc=Array.prototype.concat,or=Array.prototype.join,Z0=Array.prototype.slice,Pc=Math.floor,Na=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Da=Object.getOwnPropertySymbols,La=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Hi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Rs=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Hi||!0)?Symbol.toStringTag:null,Oc=Object.prototype.propertyIsEnumerable,Nc=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Dc(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Rc.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Pc(-r):Pc(r);if(i!==r){var s=String(i),n=Oa.call(t,s.length+1);return Lr.call(s,e,"$&_")+"."+Lr.call(Lr.call(n,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Lr.call(t,e,"$&_")}var Ba=H0,Lc=Ba.custom,Bc=Gc(Lc)?Lc:null,Fc={__proto__:null,double:'"',single:"'"},Q0={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},In=function r(t,e,i,s){var n=e||{};if(Er(n,"quoteStyle")&&!Er(Fc,n.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Er(n,"maxStringLength")&&(typeof n.maxStringLength=="number"?n.maxStringLength<0&&n.maxStringLength!==1/0:n.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=Er(n,"customInspect")?n.customInspect:!0;if(typeof o!="boolean"&&o!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Er(n,"indent")&&n.indent!==null&&n.indent!==" "&&!(parseInt(n.indent,10)===n.indent&&n.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Er(n,"numericSeparator")&&typeof n.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=n.numericSeparator;if(typeof t>"u")return"undefined";if(t===null)return"null";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="string")return Hc(t,n);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Dc(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Dc(t,h):h}var u=typeof n.depth>"u"?5:n.depth;if(typeof i>"u"&&(i=0),i>=u&&u>0&&typeof t=="object")return Fa(t)?"[Array]":"[Object]";var c=gv(n,i);if(typeof s>"u")s=[];else if($c(s,t)>=0)return"[Circular]";function d(E,I,P){if(I&&(s=Z0.call(s),s.push(I)),P){var $={depth:n.depth};return Er(n,"quoteStyle")&&($.quoteStyle=n.quoteStyle),r(E,$,i+1,s)}return r(E,n,i+1,s)}if(typeof t=="function"&&!kc(t)){var p=av(t),f=Rn(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+or.call(f,", ")+" }":"")}if(Gc(t)){var m=Hi?Lr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):La.call(t);return typeof t=="object"&&!Hi?Ms(m):m}if(fv(t)){for(var y="<"+Ic.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Uc(J0(_[v].value),"double",n);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+Ic.call(String(t.nodeName))+">",y}if(Fa(t)){if(t.length===0)return"[]";var g=Rn(t,d);return c&&!mv(g)?"["+ka(g,c)+"]":"[ "+or.call(g,", ")+" ]"}if(ev(t)){var x=Rn(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Oc.call(t,"cause")?"{ ["+String(t)+"] "+or.call(Mc.call("[cause]: "+d(t.cause),x),", ")+" }":x.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+or.call(x,", ")+" }"}if(typeof t=="object"&&o){if(Bc&&typeof t[Bc]=="function"&&Ba)return Ba(t,{depth:u-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(lv(t)){var b=[];return Ac&&Ac.call(t,function(E,I){b.push(d(I,t,!0)+" => "+d(E,t))}),Vc("Map",Sn.call(t),b,c)}if(cv(t)){var S=[];return Sc&&Sc.call(t,function(E){S.push(d(E,t))}),Vc("Set",Cn.call(t),S,c)}if(hv(t))return Ua("WeakMap");if(dv(t))return Ua("WeakSet");if(uv(t))return Ua("WeakRef");if(iv(t))return Ms(d(Number(t)));if(nv(t))return Ms(d(Na.call(t)));if(sv(t))return Ms(W0.call(t));if(rv(t))return Ms(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Es<"u"&&t===Es)return"{ [object globalThis] }";if(!tv(t)&&!kc(t)){var w=Rn(t,d),T=Nc?Nc(t)===Object.prototype:t instanceof Object||t.constructor===Object,N=t instanceof Object?"":"null prototype",F=!T&&Rs&&Object(t)===t&&Rs in t?Oa.call(Br(t),8,-1):N?"Object":"",z=T||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",C=z+(F||N?"["+or.call(Mc.call([],F||[],N||[]),": ")+"] ":"");return w.length===0?C+"{}":c?C+"{"+ka(w,c)+"}":C+"{ "+or.call(w,", ")+" }"}return String(t)};function Uc(r,t,e){var i=e.quoteStyle||t,s=Fc[i];return s+r+s}function J0(r){return Lr.call(String(r),/"/g,"&quot;")}function ai(r){return!Rs||!(typeof r=="object"&&(Rs in r||typeof r[Rs]<"u"))}function Fa(r){return Br(r)==="[object Array]"&&ai(r)}function tv(r){return Br(r)==="[object Date]"&&ai(r)}function kc(r){return Br(r)==="[object RegExp]"&&ai(r)}function ev(r){return Br(r)==="[object Error]"&&ai(r)}function rv(r){return Br(r)==="[object String]"&&ai(r)}function iv(r){return Br(r)==="[object Number]"&&ai(r)}function sv(r){return Br(r)==="[object Boolean]"&&ai(r)}function Gc(r){if(Hi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!La)return!1;try{return La.call(r),!0}catch{}return!1}function nv(r){if(!r||typeof r!="object"||!Na)return!1;try{return Na.call(r),!0}catch{}return!1}var ov=Object.prototype.hasOwnProperty||function(r){return r in this};function Er(r,t){return ov.call(r,t)}function Br(r){return Y0.call(r)}function av(r){if(r.name)return r.name;var t=q0.call(j0.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function $c(r,t){if(r.indexOf)return r.indexOf(t);for(var e=0,i=r.length;e<i;e++)if(r[e]===t)return e;return-1}function lv(r){if(!Sn||!r||typeof r!="object")return!1;try{Sn.call(r);try{Cn.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function hv(r){if(!Cs||!r||typeof r!="object")return!1;try{Cs.call(r,Cs);try{Is.call(r,Is)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function uv(r){if(!Cc||!r||typeof r!="object")return!1;try{return Cc.call(r),!0}catch{}return!1}function cv(r){if(!Cn||!r||typeof r!="object")return!1;try{Cn.call(r);try{Sn.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function dv(r){if(!Is||!r||typeof r!="object")return!1;try{Is.call(r,Is);try{Cs.call(r,Cs)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function fv(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Hc(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Hc(Oa.call(r,0,t.maxStringLength),t)+i}var s=Q0[t.quoteStyle||"single"];s.lastIndex=0;var n=Lr.call(Lr.call(r,s,"\\$1"),/[\x00-\x1f]/g,pv);return Uc(n,"single",t)}function pv(r){var t=r.charCodeAt(0),e={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return e?"\\"+e:"\\x"+(t<16?"0":"")+K0.call(t.toString(16))}function Ms(r){return"Object("+r+")"}function Ua(r){return r+" { ? }"}function Vc(r,t,e,i){var s=i?ka(e,i):or.call(e,", ");return r+" ("+t+") {"+s+"}"}function mv(r){for(var t=0;t<r.length;t++)if($c(r[t],`
1
+ (function(Gt,de){typeof exports=="object"&&typeof module<"u"?de(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],de):(Gt=typeof globalThis<"u"?globalThis:Gt||self,de(Gt.AnnotoriousOSD={},Gt.OpenSeadragon))})(this,function(Gt,de){"use strict";var CC=Object.defineProperty;var IC=(Gt,de,Zr)=>de in Gt?CC(Gt,de,{enumerable:!0,configurable:!0,writable:!0,value:Zr}):Gt[de]=Zr;var Pt=(Gt,de,Zr)=>IC(Gt,typeof de!="symbol"?de+"":de,Zr);var Zr=Object.prototype.hasOwnProperty;function Qr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Qr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Zr.call(r,e)&&++i&&!Zr.call(t,e)||!(e in t)||!Qr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var $o=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))($o||{});const oe=[];for(let r=0;r<256;++r)oe.push((r+256).toString(16).slice(1));function Om(r,t=0){return(oe[r[t+0]]+oe[r[t+1]]+oe[r[t+2]]+oe[r[t+3]]+"-"+oe[r[t+4]]+oe[r[t+5]]+"-"+oe[r[t+6]]+oe[r[t+7]]+"-"+oe[r[t+8]]+oe[r[t+9]]+"-"+oe[r[t+10]]+oe[r[t+11]]+oe[r[t+12]]+oe[r[t+13]]+oe[r[t+14]]+oe[r[t+15]]).toLowerCase()}let Ho;const Nm=new Uint8Array(16);function Dm(){if(!Ho){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ho=crypto.getRandomValues.bind(crypto)}return Ho(Nm)}const Lm=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Ph={randomUUID:Lm};function Bm(r,t,e){var i;if(Ph.randomUUID&&!r)return Ph.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??Dm();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,Om(s)}const Vo=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},Fm=(r,t,e,i)=>({id:Bm(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),Um=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},km=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Gm=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Qr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),$m=(r,t)=>!Qr(r.target,t.target),Hm=(r,t)=>{const e=Um(r,t),i=km(r,t),s=Gm(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:s.length>0?s:void 0,targetUpdated:$m(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Rr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Rr||{});const Vm=(r,t)=>{const e=new Set((r.created||[]).map(c=>c.id)),i=new Set((r.updated||[]).map(({newValue:c})=>c.id)),s=new Set((t.created||[]).map(c=>c.id)),n=new Set((t.deleted||[]).map(c=>c.id)),o=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>e.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(r.created||[]).filter(c=>!n.has(c.id)).map(c=>o.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],h=[...(r.deleted||[]).filter(c=>!s.has(c.id)),...(t.deleted||[]).filter(c=>!e.has(c.id))],u=[...(r.updated||[]).filter(({newValue:c})=>!n.has(c.id)).map(c=>{const{oldValue:d,newValue:p}=c;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return Hm(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}};let Xm=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,s=e.length;i<s;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(s=>t!==s)}}});const zm=250,Wm=(r,t)=>{const e=Xm(),i=(t==null?void 0:t.changes)||[];let s=t?t.pointer:-1,n=!1,o=0;const a=f=>{if(!n){const{changes:m}=f,y=performance.now();if(y-o>zm)i.splice(s+1),i.push(m),s=i.length-1;else{const _=i.length-1;i[_]=Vm(i[_],m)}o=y}n=!1};r.observe(a,{origin:Rr.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>s,canUndo:()=>s>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:s}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>s){n=!0;const{created:f,updated:m,deleted:y}=i[s+1];h(f),c(m),p(y),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:y}=i[s];l(f),u(m),d(y),e.emit("undo",i[s]),s-=1}}}},Ym=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const x=g.indexOf(v);x!==-1&&g.splice(x,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const b=Array.isArray(v)?v.map(w=>e.serialize(w)):e.serialize(v),S=g?g instanceof PointerEvent?g:e.serialize(g):void 0;x(b,S)}else x(v,g)})},1)},m=()=>{const{selected:_}=n,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const x=h.find(b=>b.id===g.id);(!x||!Qr(x,g))&&f("updateAnnotation",g,x)}),h=h.map(g=>v.find(({id:b})=>b===g.id)||g)};n.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Qr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),g=new Set(_.map(({id:x})=>x));h.filter(x=>!g.has(x.id)).forEach(x=>{const b=o.getAnnotation(x.id);b&&!Qr(b,x)&&f("updateAnnotation",b,x)}),h=[...h.filter(x=>g.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}f("selectionChanged",h)}}),s.subscribe(_=>{!u&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):u&&!_?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(_))),u=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(x=>f("createAnnotation",x)),(g||[]).forEach(x=>f("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:b})=>{const S=h.find(w=>w.id===x.id)||x;h=h.map(w=>w.id===x.id?b:w),f("updateAnnotation",b,S)})},{origin:Rr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),g=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);g.length>0&&(h=h.map(x=>g.find(S=>S.id===x.id)||x))}},{origin:Rr.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(x=>f("updateAnnotation",x.oldValue,x.newValue)):(g||[]).forEach(x=>f("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},jm=r=>t=>t.reduce((e,i)=>{const{parsed:s,error:n}=r.parse(i);return n?{parsed:e.parsed,failed:[...e.failed,i]}:s?{parsed:[...e.parsed,s],failed:e.failed}:{...e}},{parsed:[],failed:[]}),qm=(r,t,e)=>{const{store:i,selection:s}=r,n=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Rr.REMOTE):console.error(g)}else i.addAnnotation(Vo(_),Rr.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var _;const v=(((_=s.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},c=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||jm(e),{parsed:x,failed:b}=g(_);b.length>0&&console.warn(`Discarded ${b.length} invalid annotations`,b),i.bulkAddAnnotations(x,v,Rr.REMOTE)}else i.bulkAddAnnotations(_.map(Vo),v,Rr.REMOTE)},f=(_,v)=>{_?s.setSelected(_,v):s.clear()},m=_=>{s.clear(),s.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(Vo(_)),v}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:u,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Km="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Zm=r=>crypto.getRandomValues(new Uint8Array(r)),Qm=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,s=-~(1.6*i*t/r.length);return(n=t)=>{let o="";for(;;){let a=e(s),l=s|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=n)return o}}},Jm=(r,t=21)=>Qm(r,t|0,Zm),tg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Km[e[r]&63];return t};const eg=()=>({isGuest:!0,id:Jm("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),rg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],ig=()=>{const r=[...rg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};tg();var sg=Object.defineProperty,ng=(r,t,e)=>t in r?sg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ot=(r,t,e)=>ng(r,typeof t!="symbol"?t+"":t,e);function Ct(){}function Xo(r,t){for(const e in t)r[e]=t[e];return r}function Oh(r){return r()}function Nh(){return Object.create(null)}function Ue(r){r.forEach(Oh)}function $t(r){return typeof r=="function"}function te(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function og(r){return Object.keys(r).length===0}function Dh(r,...t){if(r==null){for(const i of t)i(void 0);return Ct}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function zo(r,t,e){r.$$.on_destroy.push(Dh(t,e))}function ag(r,t,e,i){if(r){const s=Lh(r,t,e,i);return r[0](s)}}function Lh(r,t,e,i){return r[1]&&i?Xo(e.ctx.slice(),r[1](i(t))):e.ctx}function lg(r,t,e,i){if(r[2]&&i){const s=r[2](i(e));if(t.dirty===void 0)return s;if(typeof s=="object"){const n=[],o=Math.max(t.dirty.length,s.length);for(let a=0;a<o;a+=1)n[a]=t.dirty[a]|s[a];return n}return t.dirty|s}return t.dirty}function hg(r,t,e,i,s,n){if(s){const o=Lh(t,e,i,n);r.p(o,s)}}function ug(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function Bh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function tn(r){return r??""}function Oe(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function nt(r){r.parentNode&&r.parentNode.removeChild(r)}function Jr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function mt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Fh(r){return document.createTextNode(r)}function ke(){return Fh(" ")}function Ie(){return Fh("")}function Bt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function A(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function cg(r){return Array.from(r.childNodes)}function Mr(r,t,e){r.classList.toggle(t,!!e)}function dg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let fs;function ps(r){fs=r}function Uh(){if(!fs)throw new Error("Function called outside component initialization");return fs}function ms(r){Uh().$$.on_mount.push(r)}function Si(){const r=Uh();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=dg(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function Ne(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ci=[],en=[];let Ii=[];const kh=[],fg=Promise.resolve();let Wo=!1;function pg(){Wo||(Wo=!0,fg.then(Gh))}function Yo(r){Ii.push(r)}const jo=new Set;let Ri=0;function Gh(){if(Ri!==0)return;const r=fs;do{try{for(;Ri<Ci.length;){const t=Ci[Ri];Ri++,ps(t),mg(t.$$)}}catch(t){throw Ci.length=0,Ri=0,t}for(ps(null),Ci.length=0,Ri=0;en.length;)en.pop()();for(let t=0;t<Ii.length;t+=1){const e=Ii[t];jo.has(e)||(jo.add(e),e())}Ii.length=0}while(Ci.length);for(;kh.length;)kh.pop()();Wo=!1,jo.clear(),ps(r)}function mg(r){if(r.fragment!==null){r.update(),Ue(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Yo)}}function gg(r){const t=[],e=[];Ii.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ii=t}const rn=new Set;let ti;function xe(){ti={r:0,c:[],p:ti}}function be(){ti.r||Ue(ti.c),ti=ti.p}function it(r,t){r&&r.i&&(rn.delete(r),r.i(t))}function dt(r,t,e,i){if(r&&r.o){if(rn.has(r))return;rn.add(r),ti.c.push(()=>{rn.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ee(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function _e(r){r&&r.c()}function fe(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),Yo(()=>{const n=r.$$.on_mount.map(Oh).filter($t);r.$$.on_destroy?r.$$.on_destroy.push(...n):Ue(n),r.$$.on_mount=[]}),s.forEach(Yo)}function pe(r,t){const e=r.$$;e.fragment!==null&&(gg(e.after_update),Ue(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function yg(r,t){r.$$.dirty[0]===-1&&(Ci.push(r),pg(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Te(r,t,e,i,s,n,o=null,a=[-1]){const l=fs;ps(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Ct,not_equal:s,bound:Nh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Nh(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let u=!1;if(h.ctx=e?e(r,t.props||{},(c,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&s(h.ctx[c],h.ctx[c]=f)&&(!h.skip_bound&&h.bound[c]&&h.bound[c](f),u&&yg(r,c)),d}):[],h.update(),u=!0,Ue(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=cg(t.target);h.fragment&&h.fragment.l(c),c.forEach(nt)}else h.fragment&&h.fragment.c();t.intro&&it(r.$$.fragment),fe(r,t.target,t.anchor),Gh()}ps(l)}class we{constructor(){Ot(this,"$$"),Ot(this,"$$set")}$destroy(){pe(this,1),this.$destroy=Ct}$on(t,e){if(!$t(e))return Ct;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const s=i.indexOf(e);s!==-1&&i.splice(s,1)}}$set(t){this.$$set&&!og(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const _g="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(_g);var vt=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGLON="MULTIPOLYGON",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(vt||{});const qo={},sn=(r,t)=>qo[r]=t,Ko=r=>qo[r.type].area(r),vg=(r,t,e)=>qo[r.type].intersects(r,t,e),_r=r=>{let t=1/0,e=1/0,i=-1/0,s=-1/0;return r.forEach(([n,o])=>{t=Math.min(t,n),e=Math.min(e,o),i=Math.max(i,n),s=Math.max(s,o)}),{minX:t,minY:e,maxX:i,maxY:s}},Zo=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Qo=(r,t,e)=>{let i=!1;for(let s=0,n=r.length-1;s<r.length;n=s++){const o=r[s][0],a=r[s][1],l=r[n][0],h=r[n][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},xg=(r,t=!0)=>{let e="M ";return r.forEach(([i,s],n)=>{n===0?e+=`${i},${s}`:e+=` L ${i},${s}`}),t&&(e+=" Z"),e},bg={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:s,rx:n,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),u=t-i,c=e-s,d=l*u+h*c,p=h*u-l*c;return d*d/(n*n)+p*p/(o*o)<=1}};sn(vt.ELLIPSE,bg);const Eg={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[s,...n]=i.rings,o=Zo(s.points),a=n.reduce((l,h)=>l+Zo(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const s of i){const[n,...o]=s.rings;if(Qo(n.points,t,e)){let a=!1;for(const l of o)if(Qo(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Tg=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return _r(t)},ei=r=>r.rings.map(t=>xg(t.points)).join(" ");sn(vt.MULTIPOLYGLON,Eg);const wg={area:r=>{const t=r.geometry.points;return Zo(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Qo(i,t,e)}};sn(vt.POLYGON,wg);const Ag={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};sn(vt.RECTANGLE,Ag);const Ge=r=>nn(r.target),nn=r=>{var t,e;return(r==null?void 0:r.annotation)!==void 0&&((e=(t=r==null?void 0:r.selector)==null?void 0:t.geometry)==null?void 0:e.bounds)!==void 0},Sg=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(pixel|percent)?:?(.+?),(.+?),(.+?),(.+)*/g,s=[...e.matchAll(i)][0],[n,o,a,l,h,u,c]=s;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,p,f,m]=[l,h,u,c].map(parseFloat);return{type:vt.RECTANGLE,geometry:{x:d,y:p,w:f,h:m,bounds:{minX:d,minY:t?p-m:p,maxX:d+f,maxY:t?p:p+m}}}},Cg=r=>{const{x:t,y:e,w:i,h:s}=r;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${e},${i},${s}`}},$h="http://www.w3.org/2000/svg",Hh=r=>{const t=i=>{Array.from(i.attributes).forEach(s=>{s.name.startsWith("on")&&i.removeAttribute(s.name)})},e=r.getElementsByTagName("script");return Array.from(e).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(r.querySelectorAll("*")).forEach(t),r},Ig=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${$h}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},Vh=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix($h),i=t.lookupNamespaceURI(null);return e||i?Hh(t).firstChild:Hh(Ig(t)).firstChild},Xt=" ";function Rg(r){let t="";Array.isArray(r)||(r=[r]);for(let e=0;e<r.length;e++){const i=r[e];if(i.type===B.CLOSE_PATH)t+="z";else if(i.type===B.HORIZ_LINE_TO)t+=(i.relative?"h":"H")+i.x;else if(i.type===B.VERT_LINE_TO)t+=(i.relative?"v":"V")+i.y;else if(i.type===B.MOVE_TO)t+=(i.relative?"m":"M")+i.x+Xt+i.y;else if(i.type===B.LINE_TO)t+=(i.relative?"l":"L")+i.x+Xt+i.y;else if(i.type===B.CURVE_TO)t+=(i.relative?"c":"C")+i.x1+Xt+i.y1+Xt+i.x2+Xt+i.y2+Xt+i.x+Xt+i.y;else if(i.type===B.SMOOTH_CURVE_TO)t+=(i.relative?"s":"S")+i.x2+Xt+i.y2+Xt+i.x+Xt+i.y;else if(i.type===B.QUAD_TO)t+=(i.relative?"q":"Q")+i.x1+Xt+i.y1+Xt+i.x+Xt+i.y;else if(i.type===B.SMOOTH_QUAD_TO)t+=(i.relative?"t":"T")+i.x+Xt+i.y;else if(i.type===B.ARC)t+=(i.relative?"a":"A")+i.rX+Xt+i.rY+Xt+i.xRot+Xt+ +i.lArcFlag+Xt+ +i.sweepFlag+Xt+i.x+Xt+i.y;else throw new Error(`Unexpected command type "${i==null?void 0:i.type}" at index ${e}.`)}return t}function Jo([r,t],e){return[r*Math.cos(e)-t*Math.sin(e),r*Math.sin(e)+t*Math.cos(e)]}function $e(...r){for(let t=0;t<r.length;t++)if(typeof r[t]!="number")throw new Error(`assertNumbers arguments[${t}] is not a number. ${typeof r[t]} == typeof ${r[t]}`);return!0}const Pr=Math.PI;function ta(r,t,e){r.lArcFlag=r.lArcFlag===0?0:1,r.sweepFlag=r.sweepFlag===0?0:1;let{rX:i,rY:s}=r;const{x:n,y:o}=r;if(Math.abs(i)<1e-10||Math.abs(s)<1e-10){r.rX=0,r.rY=0,r.cX=(t+n)/2,r.cY=(e+o)/2,r.phi1=0,r.phi2=0;return}i=Math.abs(r.rX),s=Math.abs(r.rY);const a=r.xRot/180*Pr,[l,h]=Jo([(t-n)/2,(e-o)/2],-a),u=Math.pow(l,2)/Math.pow(i,2)+Math.pow(h,2)/Math.pow(s,2);1<u&&(i*=Math.sqrt(u),s*=Math.sqrt(u)),r.rX=i,r.rY=s;const c=Math.pow(i,2)*Math.pow(h,2)+Math.pow(s,2)*Math.pow(l,2),d=(r.lArcFlag!==r.sweepFlag?1:-1)*Math.sqrt(Math.max(0,(Math.pow(i,2)*Math.pow(s,2)-c)/c)),p=i*h/s*d,f=-s*l/i*d,m=Jo([p,f],a);r.cX=m[0]+(t+n)/2,r.cY=m[1]+(e+o)/2,r.phi1=Math.atan2((h-f)/s,(l-p)/i),r.phi2=Math.atan2((-h-f)/s,(-l-p)/i),r.sweepFlag===0&&r.phi2>r.phi1&&(r.phi2-=2*Pr),r.sweepFlag===1&&r.phi2<r.phi1&&(r.phi2+=2*Pr),r.phi1*=180/Pr,r.phi2*=180/Pr}function Xh(r,t,e){$e(r,t,e);const i=r*r+t*t-e*e;if(0>i)return[];if(i===0)return[[r*e/(r*r+t*t),t*e/(r*r+t*t)]];const s=Math.sqrt(i);return[[(r*e+t*s)/(r*r+t*t),(t*e-r*s)/(r*r+t*t)],[(r*e-t*s)/(r*r+t*t),(t*e+r*s)/(r*r+t*t)]]}const ri=Math.PI/180;function zh(r,t,e){return(1-e)*r+e*t}function Wh(r,t,e,i){return r+Math.cos(i/180*Pr)*t+Math.sin(i/180*Pr)*e}function Yh(r,t,e,i){const s=t-r,n=e-t,o=i-e,a=3*s+3*o-6*n,l=(n-s)*6,h=3*s;return Math.abs(a)<1e-6?Math.abs(l)<1e-6?[]:[-h/l]:Mg(l/a,h/a,1e-6)}function jh(r,t,e,i,s){const n=1-s,o=n*n*n,a=3*n*n*s,l=3*n*s*s,h=s*s*s;return r*o+t*a+e*l+i*h}function Mg(r,t,e=1e-6){const i=r*r/4-t;if(i<-e)return[];if(i<=e)return[-r/2];const s=Math.sqrt(i);return[-(r/2)-s,-(r/2)+s]}function Pg(r,t,e){r.cX||ta(r,t,e);const i=r.xRot/180*Pr;if(Math.abs(r.rX)<1e-10||Math.abs(r.rY)<1e-10)return[{relative:r.relative,type:B.CURVE_TO,x1:t+(r.x-t)/3,y1:e+(r.y-e)/3,x2:t+2*(r.x-t)/3,y2:e+2*(r.y-e)/3,x:r.x,y:r.y}];const s=Math.min(r.phi1,r.phi2),n=Math.max(r.phi1,r.phi2),o=n-s,a=Math.ceil(o/90),l=new Array(a);let h=t,u=e;const c=(d,p)=>{const[f,m]=Jo([d*r.rX,p*r.rY],i);return[r.cX+f,r.cY+m]};for(let d=0;d<a;d++){const p=zh(r.phi1,r.phi2,d/a),f=zh(r.phi1,r.phi2,(d+1)/a),m=f-p,y=4/3*Math.tan(m*ri/4),_=Math.cos(p*ri)-y*Math.sin(p*ri),v=Math.sin(p*ri)+y*Math.cos(p*ri),g=Math.cos(f*ri),x=Math.sin(f*ri),b=g+y*x,S=x-y*g,w=c(_,v),T=c(b,S),N=c(g,x),F={relative:r.relative,type:B.CURVE_TO,x:N[0],y:N[1],x1:w[0],y1:w[1],x2:T[0],y2:T[1]};r.relative&&(F.x1-=h,F.y1-=u,F.x2-=h,F.y2-=u,F.x-=h,F.y-=u),h=N[0],u=N[1],l[d]=F}return l}function ea(r,t,e){const i=t[0]-r[0],s=t[1]-r[1],n=e[0]-r[0],o=e[1]-r[1],a=i*o-s*n;if(!(Math.abs(a)<1e-10))return!1;const l=i*n+s*o,h=i*i+s*s,u=n*n+o*o;return 0<=l&&l<=u&&h<=u}function Og(r,t=!0){if(r.length<2)return r;const e=zt.INFO((n,o,a)=>({...n,x:n.x??o,y:n.y??a,relative:n.relative??!1})),i=[];let s=[];for(const n of r){const o=e(n);o.type===B.MOVE_TO&&s.length>0&&(t?i.push(...on(s)):i.unshift(...on(s)),s=[]),s.push(o)}return s.length>0&&(t?i.push(...on(s)):i.unshift(...on(s))),i}function on(r){var t;const e=((t=r[r.length-1])==null?void 0:t.type)===B.CLOSE_PATH,i=e?r.length-2:r.length-1,s=[{type:B.MOVE_TO,relative:!1,x:r[i].x,y:r[i].y}];for(let n=i;n>0;n--){const o=r[n],a=r[n-1];if(o.relative)throw new Error("Relative command are not supported convert first with `toAbs()`");switch(o.type){case B.HORIZ_LINE_TO:s.push({type:B.HORIZ_LINE_TO,relative:!1,x:a.x});break;case B.VERT_LINE_TO:s.push({type:B.VERT_LINE_TO,relative:!1,y:a.y});break;case B.LINE_TO:case B.MOVE_TO:s.push({type:B.LINE_TO,relative:!1,x:a.x,y:a.y});break;case B.CURVE_TO:s.push({type:B.CURVE_TO,relative:!1,x:a.x,y:a.y,x1:o.x2,y1:o.y2,x2:o.x1,y2:o.y1});break;case B.SMOOTH_CURVE_TO:throw new Error("Unsupported command: S (smooth cubic bezier)");case B.SMOOTH_QUAD_TO:throw new Error("Unsupported command: T (smooth quadratic bezier)");case B.ARC:throw new Error("Unsupported command: A (arc)");case B.QUAD_TO:throw new Error("Unsupported command: Q (quadratic bezier)")}}return e&&s.push({type:B.CLOSE_PATH}),s}function Ng(r=1e13){$e(r);function t(e){return Math.round(e*r)/r}return function(e){return"x1"in e&&typeof e.x1<"u"&&(e.x1=t(e.x1)),"y1"in e&&typeof e.y1<"u"&&(e.y1=t(e.y1)),"x2"in e&&typeof e.x2<"u"&&(e.x2=t(e.x2)),"y2"in e&&typeof e.y2<"u"&&(e.y2=t(e.y2)),"x"in e&&typeof e.x<"u"&&(e.x=t(e.x)),"y"in e&&typeof e.y<"u"&&(e.y=t(e.y)),"rX"in e&&typeof e.rX<"u"&&(e.rX=t(e.rX)),"rY"in e&&typeof e.rY<"u"&&(e.rY=t(e.rY)),e}}function qh(){return He((r,t,e)=>(r.relative&&(typeof r.x1<"u"&&(r.x1+=t),typeof r.y1<"u"&&(r.y1+=e),typeof r.x2<"u"&&(r.x2+=t),typeof r.y2<"u"&&(r.y2+=e),typeof r.x<"u"&&(r.x+=t),typeof r.y<"u"&&(r.y+=e),r.relative=!1),r))}function Dg(){return He((r,t,e)=>(r.relative||(typeof r.x1<"u"&&(r.x1-=t),typeof r.y1<"u"&&(r.y1-=e),typeof r.x2<"u"&&(r.x2-=t),typeof r.y2<"u"&&(r.y2-=e),typeof r.x<"u"&&(r.x-=t),typeof r.y<"u"&&(r.y-=e),r.relative=!0),r))}function Lg(r=!0,t=!0,e=!0,i=!0){return He((s,n,o,a,l)=>{if(isNaN(a)&&!(s.type&B.MOVE_TO))throw new Error("path must start with moveto");if(t&&s.type&B.HORIZ_LINE_TO&&(s.type=B.LINE_TO,s.y=s.relative?0:o),e&&s.type&B.VERT_LINE_TO&&(s.type=B.LINE_TO,s.x=s.relative?0:n),r&&s.type&B.CLOSE_PATH&&(s.type=B.LINE_TO,s.x=s.relative?a-n:a,s.y=s.relative?l-o:l),s.type&B.ARC&&(s.rX===0||s.rY===0)&&(s.type=B.LINE_TO,delete s.rX,delete s.rY,delete s.xRot,delete s.lArcFlag,delete s.sweepFlag),i&&s.type&B.QUAD_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x,o+s.y]:[s.x,s.y];ea(h,u,c)&&(s.type=B.LINE_TO,delete s.x1,delete s.y1)}if(i&&s.type&B.CURVE_TO){const h=[n,o],u=s.relative?[n+s.x1,o+s.y1]:[s.x1,s.y1],c=s.relative?[n+s.x2,o+s.y2]:[s.x2,s.y2],d=s.relative?[n+s.x,o+s.y]:[s.x,s.y];ea(h,u,d)&&ea(h,c,d)&&(s.type=B.LINE_TO,delete s.x1,delete s.y1,delete s.x2,delete s.y2)}return s})}function Kh(){let r=NaN,t=NaN,e=NaN,i=NaN;return He((s,n,o)=>(s.type&B.SMOOTH_CURVE_TO&&(s.type=B.CURVE_TO,r=isNaN(r)?n:r,t=isNaN(t)?o:t,s.x1=s.relative?n-r:2*n-r,s.y1=s.relative?o-t:2*o-t),s.type&B.CURVE_TO?(r=s.relative?n+s.x2:s.x2,t=s.relative?o+s.y2:s.y2):(r=NaN,t=NaN),s.type&B.SMOOTH_QUAD_TO&&(s.type=B.QUAD_TO,e=isNaN(e)?n:e,i=isNaN(i)?o:i,s.x1=s.relative?n-e:2*n-e,s.y1=s.relative?o-i:2*o-i),s.type&B.QUAD_TO?(e=s.relative?n+s.x1:s.x1,i=s.relative?o+s.y1:s.y1):(e=NaN,i=NaN),s))}function Zh(){let r=NaN,t=NaN;return He((e,i,s)=>{if(e.type&B.SMOOTH_QUAD_TO&&(e.type=B.QUAD_TO,r=isNaN(r)?i:r,t=isNaN(t)?s:t,e.x1=e.relative?i-r:2*i-r,e.y1=e.relative?s-t:2*s-t),e.type&B.QUAD_TO){r=e.relative?i+e.x1:e.x1,t=e.relative?s+e.y1:e.y1;const n=e.x1,o=e.y1;e.type=B.CURVE_TO,e.x1=((e.relative?0:i)+n*2)/3,e.y1=((e.relative?0:s)+o*2)/3,e.x2=(e.x+n*2)/3,e.y2=(e.y+o*2)/3}else r=NaN,t=NaN;return e})}function He(r){let t=0,e=0,i=NaN,s=NaN;return function(n){if(isNaN(i)&&!(n.type&B.MOVE_TO))throw new Error("path must start with moveto");const o=r(n,t,e,i,s);return n.type&B.CLOSE_PATH&&(t=i,e=s),"x"in n&&typeof n.x<"u"&&(t=n.relative?t+n.x:n.x),"y"in n&&typeof n.y<"u"&&(e=n.relative?e+n.y:n.y),n.type&B.MOVE_TO&&(i=t,s=e),o}}function Bg(r=0){$e(r);let t=NaN,e=NaN,i=NaN,s=NaN;return He((n,o,a,l,h)=>{const u=Math.abs;let c=!1,d=0,p=0;if(n.type&B.SMOOTH_CURVE_TO&&(d=isNaN(t)?0:o-t,p=isNaN(e)?0:a-e),n.type&(B.CURVE_TO|B.SMOOTH_CURVE_TO)?(t=n.relative?o+n.x2:n.x2,e=n.relative?a+n.y2:n.y2):(t=NaN,e=NaN),n.type&B.SMOOTH_QUAD_TO?(i=isNaN(i)?o:2*o-i,s=isNaN(s)?a:2*a-s):n.type&B.QUAD_TO?(i=n.relative?o+n.x1:n.x1,s=n.relative?a+n.y1:n.y2):(i=NaN,s=NaN),n.type&B.LINE_COMMANDS||n.type&B.ARC&&(n.rX===0||n.rY===0||!n.lArcFlag)||n.type&B.CURVE_TO||n.type&B.SMOOTH_CURVE_TO||n.type&B.QUAD_TO||n.type&B.SMOOTH_QUAD_TO){const f=typeof n.x>"u"?0:n.relative?n.x:n.x-o,m=typeof n.y>"u"?0:n.relative?n.y:n.y-a;d=isNaN(i)?typeof n.x1>"u"?d:n.relative?n.x:n.x1-o:i-o,p=isNaN(s)?typeof n.y1>"u"?p:n.relative?n.y:n.y1-a:s-a;const y=typeof n.x2>"u"?0:n.relative?n.x:n.x2-o,_=typeof n.y2>"u"?0:n.relative?n.y:n.y2-a;u(f)<=r&&u(m)<=r&&u(d)<=r&&u(p)<=r&&u(y)<=r&&u(_)<=r&&(c=!0)}return n.type&B.CLOSE_PATH&&u(o-l)<=r&&u(a-h)<=r&&(c=!0),c?[]:n})}function Or(r,t,e,i,s,n){return $e(r,t,e,i,s,n),He((o,a,l,h)=>{const u=o.x1,c=o.x2,d=o.relative&&!isNaN(h),p=typeof o.x<"u"?o.x:d?0:a,f=typeof o.y<"u"?o.y:d?0:l;o.type&B.HORIZ_LINE_TO&&t!==0&&(o.type=B.LINE_TO,o.y=o.relative?0:l),o.type&B.VERT_LINE_TO&&e!==0&&(o.type=B.LINE_TO,o.x=o.relative?0:a),typeof o.x<"u"&&(o.x=o.x*r+f*e+(d?0:s)),typeof o.y<"u"&&(o.y=p*t+o.y*i+(d?0:n)),typeof o.x1<"u"&&(o.x1=o.x1*r+o.y1*e+(d?0:s)),typeof o.y1<"u"&&(o.y1=u*t+o.y1*i+(d?0:n)),typeof o.x2<"u"&&(o.x2=o.x2*r+o.y2*e+(d?0:s)),typeof o.y2<"u"&&(o.y2=c*t+o.y2*i+(d?0:n));function m(_){return _*_}const y=r*i-t*e;if(typeof o.xRot<"u"&&(r!==1||t!==0||e!==0||i!==1))if(y===0)delete o.rX,delete o.rY,delete o.xRot,delete o.lArcFlag,delete o.sweepFlag,o.type=B.LINE_TO;else{const _=o.xRot*Math.PI/180,v=Math.sin(_),g=Math.cos(_),x=1/m(o.rX),b=1/m(o.rY),S=m(g)*x+m(v)*b,w=2*v*g*(x-b),T=m(v)*x+m(g)*b,N=S*i*i-w*t*i+T*t*t,F=w*(r*i+t*e)-2*(S*e*i+T*r*t),z=S*e*e-w*r*e+T*r*r,C=(Math.atan2(F,N-z)+Math.PI)%Math.PI/2,E=Math.sin(C),I=Math.cos(C);o.rX=Math.abs(y)/Math.sqrt(N*m(I)+F*E*I+z*m(E)),o.rY=Math.abs(y)/Math.sqrt(N*m(E)-F*E*I+z*m(I)),o.xRot=C*180/Math.PI}return typeof o.sweepFlag<"u"&&0>y&&(o.sweepFlag=+!o.sweepFlag),o})}function Fg(r,t=0,e=0){$e(r,t,e);const i=Math.sin(r),s=Math.cos(r);return Or(s,i,-i,s,t-t*s+e*i,e-t*i-e*s)}function Ug(r,t=0){return $e(r,t),Or(1,0,0,1,r,t)}function kg(r,t=r){return $e(r,t),Or(r,0,0,t,0,0)}function Gg(r){return $e(r),Or(1,0,Math.tan(r),1,0,0)}function $g(r){return $e(r),Or(1,Math.tan(r),0,1,0,0)}function Hg(r=0){return $e(r),Or(-1,0,0,1,r,0)}function Vg(r=0){return $e(r),Or(1,0,0,-1,0,r)}function Xg(){return He((r,t,e)=>B.ARC===r.type?Pg(r,r.relative?0:t,r.relative?0:e):r)}function zg(){return He((r,t,e)=>(r.relative&&(t=0,e=0),B.ARC===r.type&&ta(r,t,e),r))}function Qh(){return r=>({...r})}function Wg(){const r=Qh(),t=qh(),e=Zh(),i=Kh(),s=He((n,o,a)=>{const l=i(e(t(r(n))));function h(c){c>s.maxX&&(s.maxX=c),c<s.minX&&(s.minX=c)}function u(c){c>s.maxY&&(s.maxY=c),c<s.minY&&(s.minY=c)}if(l.type&B.DRAWING_COMMANDS&&(h(o),u(a)),l.type&B.HORIZ_LINE_TO&&h(l.x),l.type&B.VERT_LINE_TO&&u(l.y),l.type&B.LINE_TO&&(h(l.x),u(l.y)),l.type&B.CURVE_TO){h(l.x),u(l.y);const c=Yh(o,l.x1,l.x2,l.x);for(const p of c)0<p&&1>p&&h(jh(o,l.x1,l.x2,l.x,p));const d=Yh(a,l.y1,l.y2,l.y);for(const p of d)0<p&&1>p&&u(jh(a,l.y1,l.y2,l.y,p))}if(l.type&B.ARC){h(l.x),u(l.y),ta(l,o,a);const c=l.xRot/180*Math.PI,d=Math.cos(c)*l.rX,p=Math.sin(c)*l.rX,f=-Math.sin(c)*l.rY,m=Math.cos(c)*l.rY,[y,_]=l.phi1<l.phi2?[l.phi1,l.phi2]:-180>l.phi2?[l.phi2+360,l.phi1+360]:[l.phi2,l.phi1],v=([b,S])=>{const w=Math.atan2(S,b)*180/Math.PI;return w<y?w+360:w},g=Xh(f,-d,0).map(v);for(const b of g)b>y&&b<_&&h(Wh(l.cX,d,f,b));const x=Xh(m,-p,0).map(v);for(const b of x)b>y&&b<_&&u(Wh(l.cY,p,m,b))}return n});return s.minX=1/0,s.maxX=-1/0,s.minY=1/0,s.maxY=-1/0,s}const zt={ROUND:Ng,TO_ABS:qh,TO_REL:Dg,NORMALIZE_HVZ:Lg,NORMALIZE_ST:Kh,QT_TO_C:Zh,INFO:He,SANITIZE:Bg,MATRIX:Or,ROTATE:Fg,TRANSLATE:Ug,SCALE:kg,SKEW_X:Gg,SKEW_Y:$g,X_AXIS_SYMMETRY:Hg,Y_AXIS_SYMMETRY:Vg,A_TO_C:Xg,ANNOTATE_ARCS:zg,CLONE:Qh,CALCULATE_BOUNDS:Wg,REVERSE_PATH:Og};class Jh{round(t){return this.transform(zt.ROUND(t))}toAbs(){return this.transform(zt.TO_ABS())}toRel(){return this.transform(zt.TO_REL())}normalizeHVZ(t,e,i){return this.transform(zt.NORMALIZE_HVZ(t,e,i))}normalizeST(){return this.transform(zt.NORMALIZE_ST())}qtToC(){return this.transform(zt.QT_TO_C())}aToC(){return this.transform(zt.A_TO_C())}sanitize(t){return this.transform(zt.SANITIZE(t))}translate(t,e){return this.transform(zt.TRANSLATE(t,e))}scale(t,e){return this.transform(zt.SCALE(t,e))}rotate(t,e,i){return this.transform(zt.ROTATE(t,e,i))}matrix(t,e,i,s,n,o){return this.transform(zt.MATRIX(t,e,i,s,n,o))}skewX(t){return this.transform(zt.SKEW_X(t))}skewY(t){return this.transform(zt.SKEW_Y(t))}xSymmetry(t){return this.transform(zt.X_AXIS_SYMMETRY(t))}ySymmetry(t){return this.transform(zt.Y_AXIS_SYMMETRY(t))}annotateArcs(){return this.transform(zt.ANNOTATE_ARCS())}}const Yg=r=>r===" "||r===" "||r==="\r"||r===`
2
+ `,tu=r=>48<=r.charCodeAt(0)&&r.charCodeAt(0)<=57;class jg extends Jh{constructor(){super(),Ot(this,"curNumber",""),Ot(this,"curCommandType",-1),Ot(this,"curCommandRelative",!1),Ot(this,"canParseCommandOrComma",!0),Ot(this,"curNumberHasExp",!1),Ot(this,"curNumberHasExpDigits",!1),Ot(this,"curNumberHasDecimal",!1),Ot(this,"curArgs",[])}finish(t=[]){if(this.parse(" ",t),this.curArgs.length!==0||!this.canParseCommandOrComma)throw new SyntaxError("Unterminated command at the path end.");return t}parse(t,e=[]){const i=s=>{e.push(s),this.curArgs.length=0,this.canParseCommandOrComma=!0};for(let s=0;s<t.length;s++){const n=t[s],o=this.curCommandType===B.ARC&&(this.curArgs.length===3||this.curArgs.length===4)&&this.curNumber.length===1&&(this.curNumber==="0"||this.curNumber==="1"),a=tu(n)&&(this.curNumber==="0"&&n==="0"||o);if(tu(n)&&!a){this.curNumber+=n,this.curNumberHasExpDigits=this.curNumberHasExp;continue}if(n==="e"||n==="E"){this.curNumber+=n,this.curNumberHasExp=!0;continue}if((n==="-"||n==="+")&&this.curNumberHasExp&&!this.curNumberHasExpDigits){this.curNumber+=n;continue}if(n==="."&&!this.curNumberHasExp&&!this.curNumberHasDecimal&&!o){this.curNumber+=n,this.curNumberHasDecimal=!0;continue}if(this.curNumber&&this.curCommandType!==-1){const l=Number(this.curNumber);if(isNaN(l))throw new SyntaxError(`Invalid number ending at ${s}`);if(this.curCommandType===B.ARC){if(this.curArgs.length===0||this.curArgs.length===1){if(0>l)throw new SyntaxError(`Expected positive number, got "${l}" 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(l),this.curArgs.length===qg[this.curCommandType]&&(B.HORIZ_LINE_TO===this.curCommandType?i({type:B.HORIZ_LINE_TO,relative:this.curCommandRelative,x:l}):B.VERT_LINE_TO===this.curCommandType?i({type:B.VERT_LINE_TO,relative:this.curCommandRelative,y:l}):this.curCommandType===B.MOVE_TO||this.curCommandType===B.LINE_TO||this.curCommandType===B.SMOOTH_QUAD_TO?(i({type:this.curCommandType,relative:this.curCommandRelative,x:this.curArgs[0],y:this.curArgs[1]}),B.MOVE_TO===this.curCommandType&&(this.curCommandType=B.LINE_TO)):this.curCommandType===B.CURVE_TO?i({type:B.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===B.SMOOTH_CURVE_TO?i({type:B.SMOOTH_CURVE_TO,relative:this.curCommandRelative,x2:this.curArgs[0],y2:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===B.QUAD_TO?i({type:B.QUAD_TO,relative:this.curCommandRelative,x1:this.curArgs[0],y1:this.curArgs[1],x:this.curArgs[2],y:this.curArgs[3]}):this.curCommandType===B.ARC&&i({type:B.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(!Yg(n)){if(n===","&&this.canParseCommandOrComma){this.canParseCommandOrComma=!1;continue}if(n==="+"||n==="-"||n==="."){this.curNumber=n,this.curNumberHasDecimal=n===".";continue}if(a){this.curNumber=n,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 "${n}" at index ${s}. Command cannot follow comma`);if(this.canParseCommandOrComma=!1,n==="z"||n==="Z"){e.push({type:B.CLOSE_PATH}),this.canParseCommandOrComma=!0,this.curCommandType=-1;continue}else if(n==="h"||n==="H")this.curCommandType=B.HORIZ_LINE_TO,this.curCommandRelative=n==="h";else if(n==="v"||n==="V")this.curCommandType=B.VERT_LINE_TO,this.curCommandRelative=n==="v";else if(n==="m"||n==="M")this.curCommandType=B.MOVE_TO,this.curCommandRelative=n==="m";else if(n==="l"||n==="L")this.curCommandType=B.LINE_TO,this.curCommandRelative=n==="l";else if(n==="c"||n==="C")this.curCommandType=B.CURVE_TO,this.curCommandRelative=n==="c";else if(n==="s"||n==="S")this.curCommandType=B.SMOOTH_CURVE_TO,this.curCommandRelative=n==="s";else if(n==="q"||n==="Q")this.curCommandType=B.QUAD_TO,this.curCommandRelative=n==="q";else if(n==="t"||n==="T")this.curCommandType=B.SMOOTH_QUAD_TO,this.curCommandRelative=n==="t";else if(n==="a"||n==="A")this.curCommandType=B.ARC,this.curCommandRelative=n==="a";else throw new SyntaxError(`Unexpected character "${n}" at index ${s}.`)}}return e}transform(t){return Object.create(this,{parse:{value(e,i=[]){const s=Object.getPrototypeOf(this).parse.call(this,e);for(const n of s){const o=t(n);Array.isArray(o)?i.push(...o):i.push(o)}return i}}})}}const Mt=class Th extends Jh{constructor(t){super(),Ot(this,"commands"),typeof t=="string"?this.commands=Th.parse(t):this.commands=t}encode(){return Th.encode(this.commands)}getBounds(){const t=zt.CALCULATE_BOUNDS();return this.transform(t),t}transform(t){const e=[];for(const i of this.commands){const s=t(i);Array.isArray(s)?e.push(...s):e.push(s)}return this.commands=e,this}reverse(t=!0){return this.commands=zt.REVERSE_PATH(this.commands,t),this}static encode(t){return Rg(t)}static parse(t){const e=new jg,i=[];return e.parse(t,i),e.finish(i),i}};Ot(Mt,"CLOSE_PATH",1),Ot(Mt,"MOVE_TO",2),Ot(Mt,"HORIZ_LINE_TO",4),Ot(Mt,"VERT_LINE_TO",8),Ot(Mt,"LINE_TO",16),Ot(Mt,"CURVE_TO",32),Ot(Mt,"SMOOTH_CURVE_TO",64),Ot(Mt,"QUAD_TO",128),Ot(Mt,"SMOOTH_QUAD_TO",256),Ot(Mt,"ARC",512),Ot(Mt,"LINE_COMMANDS",Mt.LINE_TO|Mt.HORIZ_LINE_TO|Mt.VERT_LINE_TO),Ot(Mt,"DRAWING_COMMANDS",Mt.HORIZ_LINE_TO|Mt.VERT_LINE_TO|Mt.LINE_TO|Mt.CURVE_TO|Mt.SMOOTH_CURVE_TO|Mt.QUAD_TO|Mt.SMOOTH_QUAD_TO|Mt.ARC);let B=Mt;const qg={[B.MOVE_TO]:2,[B.LINE_TO]:2,[B.HORIZ_LINE_TO]:1,[B.VERT_LINE_TO]:1,[B.CLOSE_PATH]:0,[B.QUAD_TO]:4,[B.SMOOTH_QUAD_TO]:2,[B.CURVE_TO]:6,[B.SMOOTH_CURVE_TO]:4,[B.ARC]:7},Kg=r=>{const t=new B(r).toAbs().commands,e=[];let i=[],s=null;for(const n of t)switch(n.type){case B.MOVE_TO:i.length>0&&(e.push({points:i}),i=[]),s=[n.x,n.y],i.push(s);break;case B.LINE_TO:i.push([n.x,n.y]);break;case B.HORIZ_LINE_TO:const o=i[i.length-1][1];i.push([n.x,o]);break;case B.VERT_LINE_TO:const a=i[i.length-1][0];i.push([a,n.y]);break;case B.CURVE_TO:case B.SMOOTH_CURVE_TO:case B.QUAD_TO:case B.SMOOTH_QUAD_TO:case B.ARC:i.push([n.x,n.y]);break}if(i.length>2&&e.push({points:i}),e.length>0){const n=_r(e[0].points);return{rings:e,bounds:n}}},Zg=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],s=i.split(" ").map(n=>n.split(",").map(parseFloat));return{type:vt.POLYGON,geometry:{points:s,bounds:_r(s)}}},Qg=r=>{const t=Vh(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),s=parseFloat(t.getAttribute("rx")),n=parseFloat(t.getAttribute("ry")),o={minX:e-s,minY:i-n,maxX:e+s,maxY:i+n};return{type:vt.ELLIPSE,geometry:{cx:e,cy:i,rx:s,ry:n,bounds:o}}},Jg=r=>{const t=Vh(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(n=>n.getAttribute("d")||"").map(n=>Kg(n)).filter(Boolean),i=e.reduce((n,o)=>[...n,...o.rings[0].points],[]),s=_r(i);return e.length===1&&e[0].rings.length===1?{type:vt.POLYGON,geometry:{points:i,bounds:s}}:{type:vt.MULTIPOLYGLON,geometry:{polygons:e,bounds:s}}},ty=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return Zg(t);if(t.includes("<path "))return Jg(t);if(t.includes("<ellipse "))return Qg(t);throw"Unsupported SVG shape: "+t},ey=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${ei(t)}" />`).join("")}</g>`,ry=r=>{let t;if(r.type===vt.POLYGON){const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(s=>s.join(",")).join(" ")}" /></svg>`}else if(r.type===vt.ELLIPSE){const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`}else if(r.type===vt.MULTIPOLYGLON){const e=r.geometry;t=`<svg>${ey(e)}</svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ae=[];for(let r=0;r<256;++r)ae.push((r+256).toString(16).slice(1));function iy(r,t=0){return(ae[r[t+0]]+ae[r[t+1]]+ae[r[t+2]]+ae[r[t+3]]+"-"+ae[r[t+4]]+ae[r[t+5]]+"-"+ae[r[t+6]]+ae[r[t+7]]+"-"+ae[r[t+8]]+ae[r[t+9]]+"-"+ae[r[t+10]]+ae[r[t+11]]+ae[r[t+12]]+ae[r[t+13]]+ae[r[t+14]]+ae[r[t+15]]).toLowerCase()}let ra;const sy=new Uint8Array(16);function ny(){if(!ra){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ra=crypto.getRandomValues.bind(crypto)}return ra(sy)}const oy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),eu={randomUUID:oy};function ru(r,t,e){var i;if(eu.randomUUID&&!r)return eu.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??ny();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,iy(s)}var iu=Object.prototype.hasOwnProperty;function Nr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Nr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(iu.call(r,e)&&++i&&!iu.call(t,e)||!(e in t)||!Nr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function ia(){}function ay(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const Mi=[];function sa(r,t=ia){let e;const i=new Set;function s(a){if(ay(r,a)&&(r=a,e)){const l=!Mi.length;for(const h of i)h[1](),Mi.push(h,r);if(l){for(let h=0;h<Mi.length;h+=2)Mi[h][0](Mi[h+1]);Mi.length=0}}}function n(a){s(a(r))}function o(a,l=ia){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||ia),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const ly=r=>{const{subscribe:t,set:e}=sa();let i;return t(s=>i=s),r.observe(({changes:s})=>{if(i){(s.deleted||[]).some(o=>o.id===i)&&e(void 0);const n=(s.updated||[]).find(({oldValue:o})=>o.id===i);n&&e(n.newValue.id)}}),{get current(){return i},subscribe:t,set:e}};var su=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(su||{});const an={selected:[]},hy=(r,t,e)=>{const{subscribe:i,set:s}=sa(an);let n=t,o=an;i(f=>o=f);const a=()=>{Nr(o,an)||s(an)},l=()=>{var f;return((f=o.selected)==null?void 0:f.length)===0},h=f=>{if(l())return!1;const m=typeof f=="string"?f:f.id;return o.selected.some(y=>y.id===m)},u=(f,m)=>{let y;if(Array.isArray(f)){if(y=f.map(v=>r.getAnnotation(v)).filter(Boolean),y.length<f.length){console.warn("Invalid selection: "+f.filter(v=>!y.some(g=>g.id===v)));return}}else{const v=r.getAnnotation(f);if(!v){console.warn("Invalid selection: "+f);return}y=[v]}const _=y.reduce((v,g)=>{const x=nu(g,n,e);return x==="EDIT"?[...v,{id:g.id,editable:!0}]:x==="SELECT"?[...v,{id:g.id}]:v},[]);s({selected:_,event:m})},c=(f,m)=>{const y=Array.isArray(f)?f:[f],_=y.map(v=>r.getAnnotation(v)).filter(v=>!!v);s({selected:_.map(v=>{const g=m===void 0?nu(v,n,e)==="EDIT":m;return{id:v.id,editable:g}})}),_.length!==y.length&&console.warn("Invalid selection",f)},d=f=>{if(l())return!1;const{selected:m}=o;m.some(({id:y})=>f.includes(y))&&s({selected:m.filter(({id:y})=>!f.includes(y))})},p=f=>{n=f,c(o.selected.map(({id:m})=>m))};return r.observe(({changes:f})=>d((f.deleted||[]).map(m=>m.id))),{get event(){return o?o.event:null},get selected(){return o?[...o.selected]:null},get userSelectAction(){return n},clear:a,isEmpty:l,isSelected:h,setSelected:c,setUserSelectAction:p,subscribe:i,userSelect:u}},nu=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},le=[];for(let r=0;r<256;++r)le.push((r+256).toString(16).slice(1));function uy(r,t=0){return(le[r[t+0]]+le[r[t+1]]+le[r[t+2]]+le[r[t+3]]+"-"+le[r[t+4]]+le[r[t+5]]+"-"+le[r[t+6]]+le[r[t+7]]+"-"+le[r[t+8]]+le[r[t+9]]+"-"+le[r[t+10]]+le[r[t+11]]+le[r[t+12]]+le[r[t+13]]+le[r[t+14]]+le[r[t+15]]).toLowerCase()}let na;const cy=new Uint8Array(16);function dy(){if(!na){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");na=crypto.getRandomValues.bind(crypto)}return na(cy)}const fy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ou={randomUUID:fy};function py(r,t,e){var i;if(ou.randomUUID&&!r)return ou.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??dy();if(s.length<16)throw new Error("Random bytes length must be >= 16");return s[6]=s[6]&15|64,s[8]=s[8]&63|128,uy(s)}const oa=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},my=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},gy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},yy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Nr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),_y=(r,t)=>!Nr(r.target,t.target),au=(r,t)=>{const e=my(r,t),i=gy(r,t),s=yy(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:s.length>0?s:void 0,targetUpdated:_y(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var It=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(It||{});const vy=(r,t)=>{var e,i;const{changes:s,origin:n}=t;if(!(r.options.origin?r.options.origin===n:n!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(s.created)||a(s.deleted))){const l=(e=s.updated)==null?void 0:e.some(u=>a(u.bodiesCreated)||a(u.bodiesDeleted)||a(u.bodiesUpdated)),h=(i=s.updated)==null?void 0:i.some(u=>u.targetUpdated);if(o==="BODY_ONLY"&&l&&!h||o==="TARGET_ONLY"&&h&&!l)return!1}}if(r.options.annotations){const o=new Set([...(s.created||[]).map(a=>a.id),...(s.deleted||[]).map(a=>a.id),...(s.updated||[]).map(({oldValue:a})=>a.id)]);return!!(Array.isArray(r.options.annotations)?r.options.annotations:[r.options.annotations]).find(a=>o.has(a))}else return!0},xy=(r,t)=>{const e=new Set((r.created||[]).map(c=>c.id)),i=new Set((r.updated||[]).map(({newValue:c})=>c.id)),s=new Set((t.created||[]).map(c=>c.id)),n=new Set((t.deleted||[]).map(c=>c.id)),o=new Set((t.updated||[]).map(({oldValue:c})=>c.id)),a=new Set((t.updated||[]).filter(({oldValue:c})=>e.has(c.id)||i.has(c.id)).map(({oldValue:c})=>c.id)),l=[...(r.created||[]).filter(c=>!n.has(c.id)).map(c=>o.has(c.id)?t.updated.find(({oldValue:d})=>d.id===c.id).newValue:c),...t.created||[]],h=[...(r.deleted||[]).filter(c=>!s.has(c.id)),...(t.deleted||[]).filter(c=>!e.has(c.id))],u=[...(r.updated||[]).filter(({newValue:c})=>!n.has(c.id)).map(c=>{const{oldValue:d,newValue:p}=c;if(o.has(p.id)){const f=t.updated.find(m=>m.oldValue.id===p.id).newValue;return au(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}},ln=r=>{const t=r.id===void 0?py():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},by=r=>r.id!==void 0,Ey=()=>{const r=new Map,t=new Map,e=[],i=(C,E={})=>{e.push({onChange:C,options:E})},s=C=>{const E=e.findIndex(I=>I.onChange==C);E>-1&&e.splice(E,1)},n=(C,E)=>{const I={origin:C,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...r.values()]};e.forEach(P=>{vy(P,I)&&P.onChange(I)})},o=(C,E=It.LOCAL)=>{if(C.id&&r.get(C.id))throw Error(`Cannot add annotation ${C.id} - exists already`);{const I=ln(C);r.set(I.id,I),I.bodies.forEach(P=>t.set(P.id,I.id)),n(E,{created:[I]})}},a=(C,E)=>{const I=ln(typeof C=="string"?E:C),P=typeof C=="string"?C:C.id,$=P&&r.get(P);if($){const k=au($,I);return P===I.id?r.set(P,I):(r.delete(P),r.set(I.id,I)),$.bodies.forEach(G=>t.delete(G.id)),I.bodies.forEach(G=>t.set(G.id,I.id)),k}else console.warn(`Cannot update annotation ${P} - does not exist`)},l=(C,E=It.LOCAL,I=It.LOCAL)=>{const P=by(E)?I:E,$=a(C,E);$&&n(P,{updated:[$]})},h=(C,E=It.LOCAL)=>{r.get(C.id)?l(C,E):o(C,E)},u=(C,E=It.LOCAL)=>{const I=C.reduce((P,$)=>{const k=a($);return k?[...P,k]:P},[]);I.length>0&&n(E,{updated:I})},c=(C,E=It.LOCAL)=>{const I=C.map(ln),{toAdd:P,toUpdate:$}=I.reduce((G,st)=>r.get(st.id)?{...G,toUpdate:[...G.toUpdate,st]}:{...G,toAdd:[...G.toAdd,st]},{toAdd:[],toUpdate:[]}),k=$.map(G=>a(G,E)).filter(Boolean);P.forEach(G=>{r.set(G.id,G),G.bodies.forEach(st=>t.set(st.id,G.id))}),n(E,{created:P,updated:k})},d=(C,E=It.LOCAL)=>{const I=r.get(C.annotation);if(I){const P={...I,bodies:[...I.bodies,C]};r.set(I.id,P),t.set(C.id,P.id),n(E,{updated:[{oldValue:I,newValue:P,bodiesCreated:[C]}]})}else console.warn(`Attempt to add body to missing annotation: ${C.annotation}`)},p=()=>[...r.values()],f=(C=It.LOCAL)=>{const E=[...r.values()];r.clear(),t.clear(),n(C,{deleted:E})},m=(C,E=!0,I=It.LOCAL)=>{const P=C.map(ln);if(E){const $=[...r.values()];r.clear(),t.clear(),P.forEach(k=>{r.set(k.id,k),k.bodies.forEach(G=>t.set(G.id,k.id))}),n(I,{created:P,deleted:$})}else{const $=C.reduce((k,G)=>{const st=G.id&&r.get(G.id);return st?[...k,st]:k},[]);if($.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${$.map(k=>k.id).join(", ")}`);P.forEach(k=>{r.set(k.id,k),k.bodies.forEach(G=>t.set(G.id,k.id))}),n(I,{created:P})}},y=C=>{const E=typeof C=="string"?C:C.id,I=r.get(E);if(I)return r.delete(E),I.bodies.forEach(P=>t.delete(P.id)),I;console.warn(`Attempt to delete missing annotation: ${E}`)},_=(C,E=It.LOCAL)=>{const I=y(C);I&&n(E,{deleted:[I]})},v=(C,E=It.LOCAL)=>{const I=C.reduce((P,$)=>{const k=y($);return k?[...P,k]:P},[]);I.length>0&&n(E,{deleted:I})},g=C=>{const E=r.get(C.annotation);if(E){const I=E.bodies.find(P=>P.id===C.id);if(I){t.delete(I.id);const P={...E,bodies:E.bodies.filter($=>$.id!==C.id)};return r.set(E.id,P),{oldValue:E,newValue:P,bodiesDeleted:[I]}}else console.warn(`Attempt to delete missing body ${C.id} from annotation ${C.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${C.annotation}`)},x=(C,E=It.LOCAL)=>{const I=g(C);I&&n(E,{updated:[I]})},b=(C,E=It.LOCAL)=>{const I=C.map(P=>g(P)).filter(Boolean);I.length>0&&n(E,{updated:I})},S=C=>{const E=r.get(C);return E?{...E}:void 0},w=C=>{const E=t.get(C);if(E){const I=S(E).bodies.find(P=>P.id===C);if(I)return I;console.error(`Store integrity error: body ${C} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${C}`)},T=(C,E)=>{if(C.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const I=r.get(C.annotation);if(I){const P=I.bodies.find(k=>k.id===C.id),$={...I,bodies:I.bodies.map(k=>k.id===P.id?E:k)};return r.set(I.id,$),P.id!==E.id&&(t.delete(P.id),t.set(E.id,$.id)),{oldValue:I,newValue:$,bodiesUpdated:[{oldBody:P,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${C.annotation}`)},N=(C,E,I=It.LOCAL)=>{const P=T(C,E);P&&n(I,{updated:[P]})},F=(C,E=It.LOCAL)=>{const I=C.map(P=>T({id:P.id,annotation:P.annotation},P)).filter(Boolean);n(E,{updated:I})},z=C=>{const E=r.get(C.annotation);if(E){const I={...E,target:{...E.target,...C}};return r.set(E.id,I),{oldValue:E,newValue:I,targetUpdated:{oldTarget:E.target,newTarget:C}}}else console.warn(`Attempt to update target on missing annotation: ${C.annotation}`)};return{addAnnotation:o,addBody:d,all:p,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:b,bulkUpdateAnnotations:u,bulkUpdateBodies:F,bulkUpdateTargets:(C,E=It.LOCAL)=>{const I=C.map(P=>z(P)).filter(Boolean);I.length>0&&n(E,{updated:I})},bulkUpsertAnnotations:c,clear:f,deleteAnnotation:_,deleteBody:x,getAnnotation:S,getBody:w,observe:i,unobserve:s,updateAnnotation:l,updateBody:N,updateTarget:(C,E=It.LOCAL)=>{const I=z(C);I&&n(E,{updated:[I]})},upsertAnnotation:h}},Ty=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let wy=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,s=e.length;i<s;i++)e[i](...t)},events:{},on(r,t){var e;return((e=this.events)[r]||(e[r]=[])).push(t),()=>{var i;this.events[r]=(i=this.events[r])==null?void 0:i.filter(s=>t!==s)}}});const Ay=250,Sy=(r,t)=>{const e=wy(),i=(t==null?void 0:t.changes)||[];let s=t?t.pointer:-1,n=!1,o=0;const a=f=>{if(!n){const{changes:m}=f,y=performance.now();if(y-o>Ay)i.splice(s+1),i.push(m),s=i.length-1;else{const _=i.length-1;i[_]=xy(i[_],m)}o=y}n=!1};r.observe(a,{origin:It.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f),h=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotations(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotations(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotations(f);return{canRedo:()=>i.length-1>s,canUndo:()=>s>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:s}),on:(f,m)=>e.on(f,m),redo:()=>{if(i.length-1>s){n=!0;const{created:f,updated:m,deleted:y}=i[s+1];h(f),c(m),p(y),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:y}=i[s];l(f),u(m),d(y),e.emit("undo",i[s]),s-=1}}}},Cy=()=>{const{subscribe:r,set:t}=sa([]);return{subscribe:r,set:t}},Iy=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},p=(_,v)=>{const g=l.get(_);if(g){const x=g.indexOf(v);x!==-1&&g.splice(x,1)}},f=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const b=Array.isArray(v)?v.map(w=>e.serialize(w)):e.serialize(v),S=g?g instanceof PointerEvent?g:e.serialize(g):void 0;x(b,S)}else x(v,g)})},1)},m=()=>{const{selected:_}=n,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const x=h.find(b=>b.id===g.id);(!x||!Nr(x,g))&&f("updateAnnotation",g,x)}),h=h.map(g=>v.find(({id:x})=>x===g.id)||g)};n.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const g=o.getAnnotation(v.id);g&&!Nr(g,v)&&f("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),g=new Set(_.map(({id:x})=>x));h.filter(x=>!g.has(x.id)).forEach(x=>{const b=o.getAnnotation(x.id);b&&!Nr(b,x)&&f("updateAnnotation",b,x)}),h=[...h.filter(x=>g.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}f("selectionChanged",h)}}),s.subscribe(_=>{!u&&_?f("mouseEnterAnnotation",o.getAnnotation(_)):u&&!_?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&_&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(_))),u=_}),a==null||a.subscribe(_=>f("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(x=>f("createAnnotation",x)),(g||[]).forEach(x=>f("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:b})=>{const S=h.find(w=>w.id===x.id)||x;h=h.map(w=>w.id===x.id?b:w),f("updateAnnotation",b,S)})},{origin:It.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),g=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);g.length>0&&(h=h.map(x=>g.find(b=>b.id===x.id)||x))}},{origin:It.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(x=>f("updateAnnotation",x.oldValue,x.newValue)):(g||[]).forEach(x=>f("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:p,emit:f}},Ry=r=>t=>t.reduce((e,i)=>{const{parsed:s,error:n}=r.parse(i);return n?{parsed:e.parsed,failed:[...e.failed,i]}:s?{parsed:[...e.parsed,s],failed:e.failed}:{...e}},{parsed:[],failed:[]}),My=(r,t,e)=>{const{store:i,selection:s}=r,n=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,It.REMOTE):console.error(g)}else i.addAnnotation(oa(_),It.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var _;const v=(((_=s.selected)==null?void 0:_.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},c=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(p(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},p=(_,v=!0)=>{if(e){const g=e.parseAll||Ry(e),{parsed:x,failed:b}=g(_);b.length>0&&console.warn(`Discarded ${b.length} invalid annotations`,b),i.bulkAddAnnotations(x,v,It.REMOTE)}else i.bulkAddAnnotations(_.map(oa),v,It.REMOTE)},f=(_,v)=>{_?s.setSelected(_,v):s.clear()},m=_=>{s.clear(),s.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(oa(_)),v}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:u,loadAnnotations:c,redo:t.redo,removeAnnotation:d,setAnnotations:p,setSelected:f,setUserSelectAction:m,undo:t.undo,updateAnnotation:y}},Py=(r,t,e)=>typeof t=="function"?t(r,e):t,Oy=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const s=typeof r=="function"?r(e,i):r,n=typeof t=="function"?t(e,i):t;return{...s||{},...n||{}}},Ny="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Dy=r=>crypto.getRandomValues(new Uint8Array(r)),Ly=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,s=-~(1.6*i*t/r.length);return(n=t)=>{let o="";for(;;){let a=e(s),l=s|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=n)return o}}},By=(r,t=21)=>Ly(r,t|0,Dy),Fy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Ny[e[r]&63];return t};const Uy=()=>({isGuest:!0,id:By("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),ky=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,s=t.length;i<s;i++){let n=t.charCodeAt(i);e=(e<<5)-e+n,e|=0}return`${e}`},lu=r=>r?typeof r=="object"?{...r}:r:void 0,Gy=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:s,purpose:n,value:o,created:a,modified:l,creator:h,...u}=e;return{id:i||`temp-${ky(e)}`,annotation:t,type:s,purpose:n,value:o,creator:lu(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),$y=r=>r.map(t=>{var e;const{annotation:i,created:s,updated:n,...o}=t,a={...o,created:s==null?void 0:s.toISOString(),modified:n==null?void 0:n.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});Fy();const Hy=(r,t={strict:!0,invertY:!1})=>({parse:e=>Vy(e,t),serialize:e=>Xy(e,r,t)}),Vy=(r,t={strict:!0,invertY:!1})=>{const e=r.id||ru(),{creator:i,created:s,modified:n,body:o,...a}=r,l=Gy(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,u=typeof h=="string"?h:Array.isArray(h.selector)?h.selector[0]:h.selector,c=typeof u=="string"||(u==null?void 0:u.type)==="FragmentSelector"?Sg(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?ty(u):void 0;return c||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:lu(i),updated:n?new Date(n):void 0,...Array.isArray(a.target)?a.target[0]:a.target,annotation:e,selector:c||u}}}:{error:Error(`Invalid selector: ${JSON.stringify(u)}`)}},Xy=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:s,created:n,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==vt.RECTANGLE?Cg(i.geometry):ry(i)}catch(c){if(e.strict)throw c;h=i}const u={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:$y(r.bodies),created:n==null?void 0:n.toISOString(),creator:s,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,selector:h}};return delete u.bodies,"annotation"in u.target&&delete u.target.annotation,u};function hu(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function uu(r){let t,e;return t=new Oi({props:{x:r[10][0],y:r[10][1],scale:r[3]}}),t.$on("pointerdown",function(){$t(r[9](`HANDLE-${r[12]}`))&&r[9](`HANDLE-${r[12]}`).apply(this,arguments)}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){r=i;const n={};s&16&&(n.x=r[10][0]),s&16&&(n.y=r[10][1]),s&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function zy(r){let t,e,i,s,n,o,a,l,h,u,c,d=Ee(r[4].points),p=[];for(let m=0;m<d.length;m+=1)p[m]=uu(hu(r,d,m));const f=m=>dt(p[m],1,1,()=>{p[m]=null});return{c(){t=mt("polygon"),s=ke(),n=mt("polygon"),a=ke();for(let m=0;m<p.length;m+=1)p[m].c();l=Ie(),A(t,"class","a9s-outer"),A(t,"style",e=r[1]?"display:none;":void 0),A(t,"points",i=r[4].points.map(cu).join(" ")),A(n,"class","a9s-inner a9s-shape-handle"),A(n,"style",r[1]),A(n,"points",o=r[4].points.map(du).join(" "))},m(m,y){ot(m,t,y),ot(m,s,y),ot(m,n,y),ot(m,a,y);for(let _=0;_<p.length;_+=1)p[_]&&p[_].m(m,y);ot(m,l,y),h=!0,u||(c=[Bt(t,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(n,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],u=!0)},p(m,y){if(r=m,(!h||y&2&&e!==(e=r[1]?"display:none;":void 0))&&A(t,"style",e),(!h||y&16&&i!==(i=r[4].points.map(cu).join(" ")))&&A(t,"points",i),(!h||y&2)&&A(n,"style",r[1]),(!h||y&16&&o!==(o=r[4].points.map(du).join(" ")))&&A(n,"points",o),y&536){d=Ee(r[4].points);let _;for(_=0;_<d.length;_+=1){const v=hu(r,d,_);p[_]?(p[_].p(v,y),it(p[_],1)):(p[_]=uu(v),p[_].c(),it(p[_],1),p[_].m(l.parentNode,l))}for(xe(),_=d.length;_<p.length;_+=1)f(_);be()}},i(m){if(!h){for(let y=0;y<d.length;y+=1)it(p[y]);h=!0}},o(m){p=p.filter(Boolean);for(let y=0;y<p.length;y+=1)dt(p[y]);h=!1},d(m){m&&(nt(t),nt(s),nt(n),nt(a),nt(l)),Jr(p,m),u=!1,Ue(c)}}}function Wy(r){let t,e;return t=new la({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[zy,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:r}}}),t.$on("change",r[6]),t.$on("grab",r[7]),t.$on("release",r[8]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&8730&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}const cu=r=>r.join(","),du=r=>r.join(",");function Yy(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,p,f)=>{let m;const y=d.geometry;p==="SHAPE"?m=y.points.map(([v,g])=>[v+f[0],g+f[1]]):m=y.points.map(([v,g],x)=>p===`HANDLE-${x}`?[v+f[0],g+f[1]]:[v,g]);const _=_r(m);return{...d,geometry:{points:m,bounds:_}}};function h(d){Ne.call(this,r,d)}function u(d){Ne.call(this,r,d)}function c(d){Ne.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,s=d.shape),"computedStyle"in d&&e(1,n=d.computedStyle),"transform"in d&&e(2,o=d.transform),"viewportScale"in d&&e(3,a=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,i=s.geometry)},[s,n,o,a,i,l,h,u,c]}class jy extends we{constructor(t){super(),Te(this,t,Yy,Wy,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const aa=(r,t)=>{const e=Math.abs(t[0]-r[0]),i=Math.abs(t[1]-r[1]);return Math.sqrt(Math.pow(e,2)+Math.pow(i,2))},Pi=[];function qy(r,t=Ct){let e;const i=new Set;function s(a){if(te(r,a)&&(r=a,e)){const l=!Pi.length;for(const h of i)h[1](),Pi.push(h,r);if(l){for(let h=0;h<Pi.length;h+=2)Pi[h][0](Pi[h+1]);Pi.length=0}}}function n(a){s(a(r))}function o(a,l=Ct){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||Ct),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const Ky=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:s,height:n}=r;t.setAttribute("viewBox",`0 0 ${s} ${n}`),r.addEventListener("load",o=>{const a=o.target;t.setAttribute("viewBox",`0 0 ${a.naturalWidth} ${a.naturalHeight}`)})}else t.setAttribute("viewBox",`0 0 ${e} ${i}`)},Zy=(r,t)=>{Ky(r,t);const{subscribe:e,set:i}=qy(1);let s;return window.ResizeObserver&&(s=new ResizeObserver(()=>{const n=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(n.width/o,n.height/a);i(l)}),s.observe(t.parentElement)),{destroy:()=>{s&&s.disconnect()},subscribe:e}},fu=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function Qy(r){let t,e,i,s,n,o;return{c(){t=mt("rect"),A(t,"class",e=tn(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),A(t,"x",i=r[0]-r[5]/2),A(t,"y",s=r[1]-r[5]/2),A(t,"width",r[5]),A(t,"height",r[5])},m(a,l){ot(a,t,l),n||(o=Bt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=tn(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&A(t,"class",e),l&33&&i!==(i=a[0]-a[5]/2)&&A(t,"x",i),l&34&&s!==(s=a[1]-a[5]/2)&&A(t,"y",s),l&32&&A(t,"width",a[5]),l&32&&A(t,"height",a[5])},d(a){a&&nt(t),n=!1,o()}}}function Jy(r){let t,e,i,s,n,o,a,l,h;return{c(){t=mt("g"),e=mt("circle"),s=mt("rect"),A(e,"cx",r[0]),A(e,"cy",r[1]),A(e,"r",i=r[3]/r[2]),A(e,"class","a9s-touch-halo svelte-1sgkh33"),Mr(e,"touched",r[4]),A(s,"class",n=tn(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),A(s,"x",o=r[0]-r[5]/2),A(s,"y",a=r[1]-r[5]/2),A(s,"width",r[5]),A(s,"height",r[5]),A(t,"class","a9s-touch-handle")},m(u,c){ot(u,t,c),Oe(t,e),Oe(t,s),l||(h=[Bt(e,"pointerdown",r[10]),Bt(e,"pointerdown",r[6]),Bt(e,"pointerup",r[7]),Bt(s,"pointerdown",r[9]),Bt(s,"pointerdown",r[6]),Bt(s,"pointerup",r[7])],l=!0)},p(u,c){c&1&&A(e,"cx",u[0]),c&2&&A(e,"cy",u[1]),c&12&&i!==(i=u[3]/u[2])&&A(e,"r",i),c&16&&Mr(e,"touched",u[4]),c&256&&n!==(n=tn(`a9s-handle ${u[8].class||""}`.trim())+" svelte-1sgkh33")&&A(s,"class",n),c&33&&o!==(o=u[0]-u[5]/2)&&A(s,"x",o),c&34&&a!==(a=u[1]-u[5]/2)&&A(s,"y",a),c&32&&A(s,"width",u[5]),c&32&&A(s,"height",u[5])},d(u){u&&nt(t),l=!1,Ue(h)}}}function t_(r){let t;function e(s,n){return fu?Jy:Qy}let i=e()(r);return{c(){i.c(),t=Ie()},m(s,n){i.m(s,n),ot(s,t,n)},p(s,[n]){i.p(s,n)},i:Ct,o:Ct,d(s){s&&nt(t),i.d(s)}}}function e_(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{radius:a=30}=t,l=!1;const h=f=>{f.pointerType==="touch"&&e(4,l=!0)},u=()=>e(4,l=!1);function c(f){Ne.call(this,r,f)}function d(f){Ne.call(this,r,f)}function p(f){Ne.call(this,r,f)}return r.$$set=f=>{e(8,t=Xo(Xo({},t),Bh(f))),"x"in f&&e(0,s=f.x),"y"in f&&e(1,n=f.y),"scale"in f&&e(2,o=f.scale),"radius"in f&&e(3,a=f.radius)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=10/o)},t=Bh(t),[s,n,o,a,l,i,h,u,t,c,d,p]}class Oi extends we{constructor(t){super(),Te(this,t,e_,t_,te,{x:0,y:1,scale:2,radius:3})}}function r_(r){let t,e,i,s,n,o,a,l,h,u,c,d,p,f,m,y,_,v,g,x,b,S,w,T,N,F,z,C,E,I,P,$,k,G,st,M,L,V,rt,Q,X,_t,St;return G=new Oi({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),G.$on("pointerdown",function(){$t(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),M=new Oi({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),M.$on("pointerdown",function(){$t(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),V=new Oi({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),V.$on("pointerdown",function(){$t(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Q=new Oi({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Q.$on("pointerdown",function(){$t(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=mt("rect"),a=ke(),l=mt("rect"),p=ke(),f=mt("rect"),v=ke(),g=mt("rect"),w=ke(),T=mt("rect"),C=ke(),E=mt("rect"),k=ke(),_e(G.$$.fragment),st=ke(),_e(M.$$.fragment),L=ke(),_e(V.$$.fragment),rt=ke(),_e(Q.$$.fragment),A(t,"class","a9s-outer"),A(t,"style",e=r[1]?"display:none;":void 0),A(t,"x",i=r[4].x),A(t,"y",s=r[4].y),A(t,"width",n=r[4].w),A(t,"height",o=r[4].h),A(l,"class","a9s-inner a9s-shape-handle"),A(l,"style",r[1]),A(l,"x",h=r[4].x),A(l,"y",u=r[4].y),A(l,"width",c=r[4].w),A(l,"height",d=r[4].h),A(f,"class","a9s-edge-handle a9s-edge-handle-top"),A(f,"x",m=r[4].x),A(f,"y",y=r[4].y),A(f,"height",1),A(f,"width",_=r[4].w),A(g,"class","a9s-edge-handle a9s-edge-handle-right"),A(g,"x",x=r[4].x+r[4].w),A(g,"y",b=r[4].y),A(g,"height",S=r[4].h),A(g,"width",1),A(T,"class","a9s-edge-handle a9s-edge-handle-bottom"),A(T,"x",N=r[4].x),A(T,"y",F=r[4].y+r[4].h),A(T,"height",1),A(T,"width",z=r[4].w),A(E,"class","a9s-edge-handle a9s-edge-handle-left"),A(E,"x",I=r[4].x),A(E,"y",P=r[4].y),A(E,"height",$=r[4].h),A(E,"width",1)},m(O,D){ot(O,t,D),ot(O,a,D),ot(O,l,D),ot(O,p,D),ot(O,f,D),ot(O,v,D),ot(O,g,D),ot(O,w,D),ot(O,T,D),ot(O,C,D),ot(O,E,D),ot(O,k,D),fe(G,O,D),ot(O,st,D),fe(M,O,D),ot(O,L,D),fe(V,O,D),ot(O,rt,D),fe(Q,O,D),X=!0,_t||(St=[Bt(t,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(l,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(f,"pointerdown",function(){$t(r[9]("TOP"))&&r[9]("TOP").apply(this,arguments)}),Bt(g,"pointerdown",function(){$t(r[9]("RIGHT"))&&r[9]("RIGHT").apply(this,arguments)}),Bt(T,"pointerdown",function(){$t(r[9]("BOTTOM"))&&r[9]("BOTTOM").apply(this,arguments)}),Bt(E,"pointerdown",function(){$t(r[9]("LEFT"))&&r[9]("LEFT").apply(this,arguments)})],_t=!0)},p(O,D){r=O,(!X||D&2&&e!==(e=r[1]?"display:none;":void 0))&&A(t,"style",e),(!X||D&16&&i!==(i=r[4].x))&&A(t,"x",i),(!X||D&16&&s!==(s=r[4].y))&&A(t,"y",s),(!X||D&16&&n!==(n=r[4].w))&&A(t,"width",n),(!X||D&16&&o!==(o=r[4].h))&&A(t,"height",o),(!X||D&2)&&A(l,"style",r[1]),(!X||D&16&&h!==(h=r[4].x))&&A(l,"x",h),(!X||D&16&&u!==(u=r[4].y))&&A(l,"y",u),(!X||D&16&&c!==(c=r[4].w))&&A(l,"width",c),(!X||D&16&&d!==(d=r[4].h))&&A(l,"height",d),(!X||D&16&&m!==(m=r[4].x))&&A(f,"x",m),(!X||D&16&&y!==(y=r[4].y))&&A(f,"y",y),(!X||D&16&&_!==(_=r[4].w))&&A(f,"width",_),(!X||D&16&&x!==(x=r[4].x+r[4].w))&&A(g,"x",x),(!X||D&16&&b!==(b=r[4].y))&&A(g,"y",b),(!X||D&16&&S!==(S=r[4].h))&&A(g,"height",S),(!X||D&16&&N!==(N=r[4].x))&&A(T,"x",N),(!X||D&16&&F!==(F=r[4].y+r[4].h))&&A(T,"y",F),(!X||D&16&&z!==(z=r[4].w))&&A(T,"width",z),(!X||D&16&&I!==(I=r[4].x))&&A(E,"x",I),(!X||D&16&&P!==(P=r[4].y))&&A(E,"y",P),(!X||D&16&&$!==($=r[4].h))&&A(E,"height",$);const ut={};D&16&&(ut.x=r[4].x),D&16&&(ut.y=r[4].y),D&8&&(ut.scale=r[3]),G.$set(ut);const lt={};D&16&&(lt.x=r[4].x+r[4].w),D&16&&(lt.y=r[4].y),D&8&&(lt.scale=r[3]),M.$set(lt);const Et={};D&16&&(Et.x=r[4].x+r[4].w),D&16&&(Et.y=r[4].y+r[4].h),D&8&&(Et.scale=r[3]),V.$set(Et);const Tt={};D&16&&(Tt.x=r[4].x),D&16&&(Tt.y=r[4].y+r[4].h),D&8&&(Tt.scale=r[3]),Q.$set(Tt)},i(O){X||(it(G.$$.fragment,O),it(M.$$.fragment,O),it(V.$$.fragment,O),it(Q.$$.fragment,O),X=!0)},o(O){dt(G.$$.fragment,O),dt(M.$$.fragment,O),dt(V.$$.fragment,O),dt(Q.$$.fragment,O),X=!1},d(O){O&&(nt(t),nt(a),nt(l),nt(p),nt(f),nt(v),nt(g),nt(w),nt(T),nt(C),nt(E),nt(k),nt(st),nt(L),nt(rt)),pe(G,O),pe(M,O),pe(V,O),pe(Q,O),_t=!1,Ue(St)}}}function i_(r){let t,e;return t=new la({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[r_,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:r}}}),t.$on("grab",r[6]),t.$on("change",r[7]),t.$on("release",r[8]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&1562&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function s_(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,p,f)=>{const m=d.geometry.bounds;let[y,_]=[m.minX,m.minY],[v,g]=[m.maxX,m.maxY];const[x,b]=f;if(p==="SHAPE")y+=x,v+=x,_+=b,g+=b;else{switch(p){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{_+=b;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=b;break}}switch(p){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{y+=x;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{v+=x;break}}}const S=Math.min(y,v),w=Math.min(_,g),T=Math.abs(v-y),N=Math.abs(g-_);return{...d,geometry:{x:S,y:w,w:T,h:N,bounds:{minX:S,minY:w,maxX:S+T,maxY:w+N}}}};function h(d){Ne.call(this,r,d)}function u(d){Ne.call(this,r,d)}function c(d){Ne.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,s=d.shape),"computedStyle"in d&&e(1,n=d.computedStyle),"transform"in d&&e(2,o=d.transform),"viewportScale"in d&&e(3,a=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,i=s.geometry)},[s,n,o,a,i,l,h,u,c]}class n_ extends we{constructor(t){super(),Te(this,t,s_,i_,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}function pu(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function mu(r,t,e){const i=r.slice();return i[13]=t[e],i[15]=e,i}function gu(r,t,e){const i=r.slice();return i[16]=t[e],i[18]=e,i}function yu(r){let t,e;return t=new Oi({props:{x:r[16][0],y:r[16][1],scale:r[3]}}),t.$on("pointerdown",function(){$t(r[9](`HANDLE-${r[12]}-${r[15]}-${r[18]}`))&&r[9](`HANDLE-${r[12]}-${r[15]}-${r[18]}`).apply(this,arguments)}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){r=i;const n={};s&16&&(n.x=r[16][0]),s&16&&(n.y=r[16][1]),s&8&&(n.scale=r[3]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function _u(r){let t,e,i=Ee(r[13].points),s=[];for(let o=0;o<i.length;o+=1)s[o]=yu(gu(r,i,o));const n=o=>dt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Ie()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a&536){i=Ee(o[13].points);let l;for(l=0;l<i.length;l+=1){const h=gu(o,i,l);s[l]?(s[l].p(h,a),it(s[l],1)):(s[l]=yu(h),s[l].c(),it(s[l],1),s[l].m(t.parentNode,t))}for(xe(),l=i.length;l<s.length;l+=1)n(l);be()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)it(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)dt(s[a]);e=!1},d(o){o&&nt(t),Jr(s,o)}}}function vu(r){let t,e,i,s,n,o,a,l,h,u=Ee(r[10].rings),c=[];for(let p=0;p<u.length;p+=1)c[p]=_u(mu(r,u,p));const d=p=>dt(c[p],1,1,()=>{c[p]=null});return{c(){t=mt("g"),e=mt("path"),n=mt("path");for(let p=0;p<c.length;p+=1)c[p].c();A(e,"class","a9s-outer"),A(e,"style",i=r[1]?"display:none;":void 0),A(e,"fill-rule","evenodd"),A(e,"d",s=ei(r[10])),A(n,"class","a9s-inner"),A(n,"style",r[1]),A(n,"fill-rule","evenodd"),A(n,"d",o=ei(r[10]))},m(p,f){ot(p,t,f),Oe(t,e),Oe(t,n);for(let m=0;m<c.length;m+=1)c[m]&&c[m].m(t,null);a=!0,l||(h=[Bt(e,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Bt(n,"pointerdown",function(){$t(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],l=!0)},p(p,f){if(r=p,(!a||f&2&&i!==(i=r[1]?"display:none;":void 0))&&A(e,"style",i),(!a||f&16&&s!==(s=ei(r[10])))&&A(e,"d",s),(!a||f&2)&&A(n,"style",r[1]),(!a||f&16&&o!==(o=ei(r[10])))&&A(n,"d",o),f&536){u=Ee(r[10].rings);let m;for(m=0;m<u.length;m+=1){const y=mu(r,u,m);c[m]?(c[m].p(y,f),it(c[m],1)):(c[m]=_u(y),c[m].c(),it(c[m],1),c[m].m(t,null))}for(xe(),m=u.length;m<c.length;m+=1)d(m);be()}},i(p){if(!a){for(let f=0;f<u.length;f+=1)it(c[f]);a=!0}},o(p){c=c.filter(Boolean);for(let f=0;f<c.length;f+=1)dt(c[f]);a=!1},d(p){p&&nt(t),Jr(c,p),l=!1,Ue(h)}}}function o_(r){let t,e,i=Ee(r[4].polygons),s=[];for(let o=0;o<i.length;o+=1)s[o]=vu(pu(r,i,o));const n=o=>dt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Ie()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a&538){i=Ee(o[4].polygons);let l;for(l=0;l<i.length;l+=1){const h=pu(o,i,l);s[l]?(s[l].p(h,a),it(s[l],1)):(s[l]=vu(h),s[l].c(),it(s[l],1),s[l].m(t.parentNode,t))}for(xe(),l=i.length;l<s.length;l+=1)n(l);be()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)it(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)dt(s[a]);e=!1},d(o){o&&nt(t),Jr(s,o)}}}function a_(r){let t,e;return t=new la({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[o_,({grab:i})=>({9:i}),({grab:i})=>i?512:0]},$$scope:{ctx:r}}}),t.$on("change",r[6]),t.$on("grab",r[7]),t.$on("release",r[8]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,[s]){const n={};s&1&&(n.shape=i[0]),s&4&&(n.transform=i[2]),s&524826&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function l_(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,p,f)=>{const m=d.geometry.polygons;let y;if(p==="SHAPE")y=m.map(_=>{const v=_.rings.map((x,b)=>({points:x.points.map((S,w)=>[S[0]+f[0],S[1]+f[1]])})),g=_r(v[0].points);return{rings:v,bounds:g}});else{const[_,v,g,x]=p.split("-").map(b=>parseInt(b));y=m.map((b,S)=>{if(S===v){const w=b.rings.map((N,F)=>F===g?{points:N.points.map((z,C)=>C===x?[z[0]+f[0],z[1]+f[1]]:z)}:N),T=_r(w[0].points);return{rings:w,bounds:T}}else return b})}return{...d,geometry:{polygons:y,bounds:Tg(y)}}};function h(d){Ne.call(this,r,d)}function u(d){Ne.call(this,r,d)}function c(d){Ne.call(this,r,d)}return r.$$set=d=>{"shape"in d&&e(0,s=d.shape),"computedStyle"in d&&e(1,n=d.computedStyle),"transform"in d&&e(2,o=d.transform),"viewportScale"in d&&e(3,a=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&1&&e(4,i=s.geometry)},[s,n,o,a,i,l,h,u,c]}class h_ extends we{constructor(t){super(),Te(this,t,l_,a_,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const xu=new Map([[vt.RECTANGLE,n_],[vt.POLYGON,jy],[vt.MULTIPOLYGLON,h_]]),bu=r=>xu.get(r.type),Eu=(r,t)=>xu.set(r,t),u_=r=>({}),Tu=r=>({grab:r[0]});function c_(r){let t,e,i,s;const n=r[7].default,o=ag(n,r,r[6],Tu);return{c(){t=mt("g"),o&&o.c(),A(t,"class","a9s-annotation selected")},m(a,l){ot(a,t,l),o&&o.m(t,null),e=!0,i||(s=[Bt(t,"pointerup",r[2]),Bt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&64)&&hg(o,n,a,a[6],e?lg(n,a[6],l,u_):ug(a[6]),Tu)},i(a){e||(it(o,a),e=!0)},o(a){dt(o,a),e=!1},d(a){a&&nt(t),o&&o.d(a),i=!1,Ue(s)}}}function d_(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Si();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,u,c;const d=m=>y=>{h=m,u=l.elementToImage(y.offsetX,y.offsetY),c=o,y.target.setPointerCapture(y.pointerId),n("grab",y)},p=m=>{if(h){const[y,_]=l.elementToImage(m.offsetX,m.offsetY),v=[y-u[0],_-u[1]];e(3,o=a(c,h,v)),n("change",o)}},f=m=>{m.target.releasePointerCapture(m.pointerId),h=void 0,c=o,n("release",m)};return r.$$set=m=>{"shape"in m&&e(3,o=m.shape),"editor"in m&&e(4,a=m.editor),"transform"in m&&e(5,l=m.transform),"$$scope"in m&&e(6,s=m.$$scope)},[d,p,f,o,a,l,s,i]}class la extends we{constructor(t){super(),Te(this,t,d_,c_,te,{shape:3,editor:4,transform:5})}}const gs=(r,t)=>{const e=typeof t=="function"?t(r):t;if(e){const{fill:i,fillOpacity:s,stroke:n,strokeWidth:o,strokeOpacity:a}=e;let l="";return i&&(l+=`fill:${i};`,l+=`fill-opacity:${s||"0.25"};`),n&&(l+=`stroke:${n};`,l+=`stroke-width:${o||"1"};`,l+=`stroke-opacity:${a||"1"};`),l}};function f_(r,t,e){let i;const s=Si();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:u}=t,c;return ms(()=>(e(6,c=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:u}})),c.$on("change",d=>{c.$$set({shape:d.detail}),s("change",d.detail)}),c.$on("grab",d=>s("grab",d.detail)),c.$on("release",d=>s("release",d.detail)),()=>{c.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,n=d.annotation),"editor"in d&&e(1,o=d.editor),"style"in d&&e(2,a=d.style),"target"in d&&e(3,l=d.target),"transform"in d&&e(4,h=d.transform),"viewportScale"in d&&e(5,u=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=gs(n,a)),r.$$.dirty&65&&n&&(c==null||c.$set({shape:n.target.selector})),r.$$.dirty&80&&c&&c.$set({transform:h}),r.$$.dirty&96&&c&&c.$set({viewportScale:u}),r.$$.dirty&192&&c&&i&&c.$set({computedStyle:i})},[n,o,a,l,h,u,c,i]}class p_ extends we{constructor(t){super(),Te(this,t,f_,null,te,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function m_(r,t,e){const i=Si();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return ms(()=>{const u=n.closest("svg"),c=[],d=(p,f,m)=>{u==null||u.addEventListener(p,f,m),c.push(()=>u==null?void 0:u.removeEventListener(p,f,m))};return e(5,h=new o({target:n,props:{addEventListener:d,drawingMode:s,transform:a,viewportScale:l}})),h.$on("create",p=>i("create",p.detail)),()=>{c.forEach(p=>p()),h.$destroy()}}),r.$$set=u=>{"drawingMode"in u&&e(0,s=u.drawingMode),"target"in u&&e(1,n=u.target),"tool"in u&&e(2,o=u.tool),"transform"in u&&e(3,a=u.transform),"viewportScale"in u&&e(4,l=u.viewportScale)},r.$$.update=()=>{r.$$.dirty&40&&h&&h.$set({transform:a}),r.$$.dirty&48&&h&&h.$set({viewportScale:l})},[s,n,o,a,l,h]}class g_ extends we{constructor(t){super(),Te(this,t,m_,null,te,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function wu(r){let t,e;return{c(){t=mt("rect"),e=mt("rect"),A(t,"class","a9s-outer"),A(t,"x",r[1]),A(t,"y",r[2]),A(t,"width",r[3]),A(t,"height",r[4]),A(e,"class","a9s-inner"),A(e,"x",r[1]),A(e,"y",r[2]),A(e,"width",r[3]),A(e,"height",r[4])},m(i,s){ot(i,t,s),ot(i,e,s)},p(i,s){s&2&&A(t,"x",i[1]),s&4&&A(t,"y",i[2]),s&8&&A(t,"width",i[3]),s&16&&A(t,"height",i[4]),s&2&&A(e,"x",i[1]),s&4&&A(e,"y",i[2]),s&8&&A(e,"width",i[3]),s&16&&A(e,"height",i[4])},d(i){i&&(nt(t),nt(e))}}}function y_(r){let t,e=r[0]&&wu(r);return{c(){t=mt("g"),e&&e.c(),A(t,"class","a9s-annotation a9s-rubberband")},m(i,s){ot(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=wu(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Ct,o:Ct,d(i){i&&nt(t),e&&e.d()}}}function __(r,t,e){const i=Si();let{addEventListener:s}=t,{drawingMode:n}=t,{transform:o}=t,a,l,h,u,c,d,p;const f=v=>{const g=v;a=performance.now(),n==="drag"&&(e(0,l=o.elementToImage(g.offsetX,g.offsetY)),h=l,e(1,u=l[0]),e(2,c=l[1]),e(3,d=1),e(4,p=1))},m=v=>{const g=v;l&&(h=o.elementToImage(g.offsetX,g.offsetY),e(1,u=Math.min(h[0],l[0])),e(2,c=Math.min(h[1],l[1])),e(3,d=Math.abs(h[0]-l[0])),e(4,p=Math.abs(h[1]-l[1])))},y=v=>{const g=v,x=performance.now()-a;if(n==="click"){if(x>300)return;l?_():(e(0,l=o.elementToImage(g.offsetX,g.offsetY)),h=l,e(1,u=l[0]),e(2,c=l[1]),e(3,d=1),e(4,p=1))}else l&&(x>300||d*p>100?(g.stopPropagation(),_()):(e(0,l=void 0),h=void 0))},_=()=>{if(d*p>15){const v={type:vt.RECTANGLE,geometry:{bounds:{minX:u,minY:c,maxX:u+d,maxY:c+p},x:u,y:c,w:d,h:p}};i("create",v)}e(0,l=void 0),h=void 0};return ms(()=>{s("pointerdown",f),s("pointermove",m),s("pointerup",y,!0)}),r.$$set=v=>{"addEventListener"in v&&e(5,s=v.addEventListener),"drawingMode"in v&&e(6,n=v.drawingMode),"transform"in v&&e(7,o=v.transform)},[l,u,c,d,p,s,n,o]}class v_ extends we{constructor(t){super(),Te(this,t,__,y_,te,{addEventListener:5,drawingMode:6,transform:7})}}function ha(r){const t=r.slice(),e=(t[2]?t[0]:[...t[0],t[1]]).map(i=>i.join(",")).join(" ");return t[16]=e,t}function Au(r){let t,e,i,s,n,o=r[2]&&Su(r);return{c(){t=mt("polygon"),i=mt("polygon"),o&&o.c(),n=Ie(),A(t,"class","a9s-outer"),A(t,"points",e=r[16]),A(i,"class","a9s-inner"),A(i,"points",s=r[16])},m(a,l){ot(a,t,l),ot(a,i,l),o&&o.m(a,l),ot(a,n,l)},p(a,l){l&7&&e!==(e=a[16])&&A(t,"points",e),l&7&&s!==(s=a[16])&&A(i,"points",s),a[2]?o?o.p(a,l):(o=Su(a),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},d(a){a&&(nt(t),nt(i),nt(n)),o&&o.d(a)}}}function Su(r){let t,e,i;return{c(){t=mt("rect"),A(t,"class","a9s-handle"),A(t,"x",e=r[0][0][0]-r[3]/2),A(t,"y",i=r[0][0][1]-r[3]/2),A(t,"height",r[3]),A(t,"width",r[3])},m(s,n){ot(s,t,n)},p(s,n){n&9&&e!==(e=s[0][0][0]-s[3]/2)&&A(t,"x",e),n&9&&i!==(i=s[0][0][1]-s[3]/2)&&A(t,"y",i),n&8&&A(t,"height",s[3]),n&8&&A(t,"width",s[3])},d(s){s&&nt(t)}}}function x_(r){let t,e=r[1]&&Au(ha(r));return{c(){t=mt("g"),e&&e.c(),A(t,"class","a9s-annotation a9s-rubberband")},m(i,s){ot(i,t,s),e&&e.m(t,null)},p(i,[s]){i[1]?e?e.p(ha(i),s):(e=Au(ha(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Ct,o:Ct,d(i){i&&nt(t),e&&e.d()}}}const b_=20,E_=1500;function T_(r,t,e){let i;const s=Si();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,u=[],c,d,p=!1;const f=g=>{const x=g,{timeStamp:b,offsetX:S,offsetY:w}=x;if(h={timeStamp:b,offsetX:S,offsetY:w},o==="drag"&&u.length===0){const T=a.elementToImage(x.offsetX,x.offsetY);u.push(T),e(1,c=T)}},m=g=>{const x=g;if(d&&clearTimeout(d),u.length>0){if(e(1,c=a.elementToImage(x.offsetX,x.offsetY)),u.length>2){const b=aa(c,u[0])*l;e(2,p=b<b_)}x.pointerType==="touch"&&(d=setTimeout(()=>{_()},E_))}},y=g=>{const x=g;if(d&&clearTimeout(d),o==="click"){const b=x.timeStamp-h.timeStamp,S=aa([h.offsetX,h.offsetY],[x.offsetX,x.offsetY]);if(b>300||S>15)return;if(p)v();else if(u.length===0){const w=a.elementToImage(x.offsetX,x.offsetY);u.push(w),e(1,c=w)}else u.push(c)}else{if(u.length===1&&aa(u[0],c)<=4){e(0,u=[]),e(1,c=void 0);return}x.stopImmediatePropagation(),p?v():u.push(c)}},_=()=>{if(!c)return;const g=u.slice(0,-1);if(g.length<3)return;const x={type:vt.POLYGON,geometry:{bounds:_r(u),points:g}};Ko(x)>4&&(e(0,u=[]),e(1,c=void 0),s("create",x))},v=()=>{const g={type:vt.POLYGON,geometry:{bounds:_r(u),points:[...u]}};e(0,u=[]),e(1,c=void 0),s("create",g)};return ms(()=>{n("pointerdown",f,!0),n("pointermove",m),n("pointerup",y,!0),n("dblclick",_,!0)}),r.$$set=g=>{"addEventListener"in g&&e(4,n=g.addEventListener),"drawingMode"in g&&e(5,o=g.drawingMode),"transform"in g&&e(6,a=g.transform),"viewportScale"in g&&e(7,l=g.viewportScale)},r.$$.update=()=>{r.$$.dirty&128&&e(3,i=10/l)},[u,c,p,i,n,o,a,l]}class w_ extends we{constructor(t){super(),Te(this,t,T_,x_,te,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const ua=new Map([["rectangle",{tool:v_}],["polygon",{tool:w_}]]),hn=()=>[...ua.keys()],un=r=>ua.get(r),Cu=(r,t,e)=>ua.set(r,{tool:t,opts:e});function A_(r){let t,e,i,s,n;return{c(){t=mt("g"),e=mt("ellipse"),s=mt("ellipse"),A(e,"class","a9s-outer"),A(e,"style",i=r[1]?"display:none;":void 0),A(e,"cx",r[2]),A(e,"cy",r[3]),A(e,"rx",r[4]),A(e,"ry",r[5]),A(s,"class","a9s-inner"),A(s,"style",r[1]),A(s,"cx",r[2]),A(s,"cy",r[3]),A(s,"rx",r[4]),A(s,"ry",r[5]),A(t,"class","a9s-annotation"),A(t,"data-id",n=r[0].id)},m(o,a){ot(o,t,a),Oe(t,e),Oe(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&A(e,"style",i),a&2&&A(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&A(t,"data-id",n)},i:Ct,o:Ct,d(o){o&&nt(t)}}}function S_(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:u}=n;return r.$$set=c=>{"annotation"in c&&e(0,s=c.annotation),"geom"in c&&e(6,n=c.geom),"style"in c&&e(7,o=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=gs(s,o))},[s,i,a,l,h,u,n,o]}class C_ extends we{constructor(t){super(),Te(this,t,S_,A_,te,{annotation:0,geom:6,style:7})}}function Iu(r,t,e){const i=r.slice();return i[5]=t[e],i}function Ru(r){let t,e,i;return{c(){t=mt("path"),i=mt("path"),A(t,"class","a9s-outer"),A(t,"style",e=r[1]?"display:none;":void 0),A(t,"fill-rule","evenodd"),A(t,"d",ei(r[5])),A(i,"class","a9s-inner"),A(i,"style",r[1]),A(i,"fill-rule","evenodd"),A(i,"d",ei(r[5]))},m(s,n){ot(s,t,n),ot(s,i,n)},p(s,n){n&2&&e!==(e=s[1]?"display:none;":void 0)&&A(t,"style",e),n&2&&A(i,"style",s[1])},d(s){s&&(nt(t),nt(i))}}}function I_(r){let t,e,i=Ee(r[2]),s=[];for(let n=0;n<i.length;n+=1)s[n]=Ru(Iu(r,i,n));return{c(){t=mt("g");for(let n=0;n<s.length;n+=1)s[n].c();A(t,"class","a9s-annotation"),A(t,"data-id",e=r[0].id)},m(n,o){ot(n,t,o);for(let a=0;a<s.length;a+=1)s[a]&&s[a].m(t,null)},p(n,[o]){if(o&6){i=Ee(n[2]);let a;for(a=0;a<i.length;a+=1){const l=Iu(n,i,a);s[a]?s[a].p(l,o):(s[a]=Ru(l),s[a].c(),s[a].m(t,null))}for(;a<s.length;a+=1)s[a].d(1);s.length=i.length}o&1&&e!==(e=n[0].id)&&A(t,"data-id",e)},i:Ct,o:Ct,d(n){n&&nt(t),Jr(s,n)}}}function R_(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{polygons:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=gs(s,o))},[s,i,a,n,o]}class M_ extends we{constructor(t){super(),Te(this,t,R_,I_,te,{annotation:0,geom:3,style:4})}}function P_(r){let t,e,i,s,n;return{c(){t=mt("g"),e=mt("polygon"),s=mt("polygon"),A(e,"class","a9s-outer"),A(e,"style",i=r[1]?"display:none;":void 0),A(e,"points",r[2].map(O_).join(" ")),A(s,"class","a9s-inner"),A(s,"style",r[1]),A(s,"points",r[2].map(N_).join(" ")),A(t,"class","a9s-annotation"),A(t,"data-id",n=r[0].id)},m(o,a){ot(o,t,a),Oe(t,e),Oe(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&A(e,"style",i),a&2&&A(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&A(t,"data-id",n)},i:Ct,o:Ct,d(o){o&&nt(t)}}}const O_=r=>r.join(","),N_=r=>r.join(",");function D_(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{points:a}=n;return r.$$set=l=>{"annotation"in l&&e(0,s=l.annotation),"geom"in l&&e(3,n=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=gs(s,o))},[s,i,a,n,o]}class L_ extends we{constructor(t){super(),Te(this,t,D_,P_,te,{annotation:0,geom:3,style:4})}}function B_(r){let t,e,i,s,n;return{c(){t=mt("g"),e=mt("rect"),s=mt("rect"),A(e,"class","a9s-outer"),A(e,"style",i=r[5]?"display:none;":void 0),A(e,"x",r[4]),A(e,"y",r[3]),A(e,"width",r[2]),A(e,"height",r[1]),A(s,"class","a9s-inner"),A(s,"style",r[5]),A(s,"x",r[4]),A(s,"y",r[3]),A(s,"width",r[2]),A(s,"height",r[1]),A(t,"class","a9s-annotation"),A(t,"data-id",n=r[0].id)},m(o,a){ot(o,t,a),Oe(t,e),Oe(t,s)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&A(e,"style",i),a&16&&A(e,"x",o[4]),a&8&&A(e,"y",o[3]),a&4&&A(e,"width",o[2]),a&2&&A(e,"height",o[1]),a&32&&A(s,"style",o[5]),a&16&&A(s,"x",o[4]),a&8&&A(s,"y",o[3]),a&4&&A(s,"width",o[2]),a&2&&A(s,"height",o[1]),a&1&&n!==(n=o[0].id)&&A(t,"data-id",n)},i:Ct,o:Ct,d(o){o&&nt(t)}}}function F_(r,t,e){let i,s,n,o,a,{annotation:l}=t,{geom:h}=t,{style:u}=t;return r.$$set=c=>{"annotation"in c&&e(0,l=c.annotation),"geom"in c&&e(6,h=c.geom),"style"in c&&e(7,u=c.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=gs(l,u)),r.$$.dirty&64&&e(4,{x:s,y:n,w:o,h:a}=h,s,(e(3,n),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,n,s,i,h,u]}class U_ extends we{constructor(t){super(),Te(this,t,F_,B_,te,{annotation:0,geom:6,style:7})}}const k_=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),s=r.createSVGPoint();s.x=t+i.x,s.y=e+i.y;const{x:n,y:o}=s.matrixTransform(r.getScreenCTM().inverse());return[n,o]}}),G_=250,$_=(r,t)=>{const e=Si();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<G_){const{x:n,y:o}=Mu(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},Mu=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),s=r.clientX-i.x,n=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=s+o,e.y=n+a,e.matrixTransform(t.getScreenCTM().inverse())};function Pu(r,t,e){const i=r.slice();i[39]=t[e];const s=i[24](i[39].target.selector);return i[40]=s,i}function Ou(r,t,e){const i=r.slice();return i[43]=t[e],i}function ca(r){const t=r.slice(),e=t[43].target.selector;return t[46]=e,t}function Nu(r){let t=r[43],e,i,s=Du(r);return{c(){s.c(),e=Ie()},m(n,o){s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&65536&&te(t,t=n[43])?(xe(),dt(s,1,1,Ct),be(),s=Du(n),s.c(),it(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s.d(n)}}}function H_(r){let t,e;return t=new M_({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function V_(r){let t,e;return t=new L_({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function X_(r){let t,e;return t=new U_({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&65536&&(n.annotation=i[43]),s[0]&65536&&(n.geom=i[46].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function z_(r){var t;let e,i;return e=new C_({props:{annotation:r[43],geom:(t=r[46])==null?void 0:t.geometry,style:r[1]}}),{c(){_e(e.$$.fragment)},m(s,n){fe(e,s,n),i=!0},p(s,n){var o;const a={};n[0]&65536&&(a.annotation=s[43]),n[0]&65536&&(a.geom=(o=s[46])==null?void 0:o.geometry),n[0]&2&&(a.style=s[1]),e.$set(a)},i(s){i||(it(e.$$.fragment,s),i=!0)},o(s){dt(e.$$.fragment,s),i=!1},d(s){pe(e,s)}}}function Du(r){let t,e,i,s;const n=[z_,X_,V_,H_],o=[];function a(l,h){var u,c,d,p;return((u=l[46])==null?void 0:u.type)===vt.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===vt.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===vt.POLYGON?2:((p=l[46])==null?void 0:p.type)===vt.MULTIPOLYGLON?3:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Ie()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(xe(),dt(o[u],1,1,()=>{o[u]=null}),be()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),it(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(it(e),s=!0)},o(l){dt(e),s=!1},d(l){l&&nt(i),~t&&o[t].d(l)}}}function Lu(r){let t=Ge(r[43])&&!r[9](r[43]),e,i,s=t&&Nu(ca(r));return{c(){s&&s.c(),e=Ie()},m(n,o){s&&s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&66048&&(t=Ge(n[43])&&!n[9](n[43])),t?s?(s.p(ca(n),o),o[0]&66048&&it(s,1)):(s=Nu(ca(n)),s.c(),it(s,1),s.m(e.parentNode,e)):s&&(xe(),dt(s,1,1,()=>{s=null}),be())},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s&&s.d(n)}}}function Bu(r){let t,e,i,s;const n=[Y_,W_],o=[];function a(l,h){return l[8]?0:l[14]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=Ie()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(xe(),dt(o[u],1,1,()=>{o[u]=null}),be()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),it(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(it(e),s=!0)},o(l){dt(e),s=!1},d(l){l&&nt(i),~t&&o[t].d(l)}}}function W_(r){let t=`${r[2]}-${r[5]}`,e,i,s=Fu(r);return{c(){s.c(),e=Ie()},m(n,o){s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&36&&te(t,t=`${n[2]}-${n[5]}`)?(xe(),dt(s,1,1,Ct),be(),s=Fu(n),s.c(),it(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s.d(n)}}}function Y_(r){let t,e,i=Ee(r[8]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Gu(Pu(r,i,o));const n=o=>dt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=Ie()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a[0]&21107010){i=Ee(o[8]);let l;for(l=0;l<i.length;l+=1){const h=Pu(o,i,l);s[l]?(s[l].p(h,a),it(s[l],1)):(s[l]=Gu(h),s[l].c(),it(s[l],1),s[l].m(t.parentNode,t))}for(xe(),l=i.length;l<s.length;l+=1)n(l);be()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)it(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)dt(s[a]);e=!1},d(o){o&&nt(t),Jr(s,o)}}}function Fu(r){let t,e;return t=new g_({props:{target:r[6],tool:r[14],drawingMode:r[13],transform:r[12],viewportScale:r[17]}}),t.$on("create",r[21]),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){const n={};s[0]&64&&(n.target=i[6]),s[0]&16384&&(n.tool=i[14]),s[0]&8192&&(n.drawingMode=i[13]),s[0]&4096&&(n.transform=i[12]),s[0]&131072&&(n.viewportScale=i[17]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function Uu(r){let t=r[39].id,e,i,s=ku(r);return{c(){s.c(),e=Ie()},m(n,o){s.m(n,o),ot(n,e,o),i=!0},p(n,o){o[0]&256&&te(t,t=n[39].id)?(xe(),dt(s,1,1,Ct),be(),s=ku(n),s.c(),it(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(it(s),i=!0)},o(n){dt(s),i=!1},d(n){n&&nt(e),s.d(n)}}}function ku(r){let t,e;return t=new p_({props:{target:r[6],editor:r[24](r[39].target.selector),annotation:r[39],style:r[1],transform:r[12],viewportScale:r[17]}}),t.$on("change",function(){$t(r[22](r[39]))&&r[22](r[39]).apply(this,arguments)}),{c(){_e(t.$$.fragment)},m(i,s){fe(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&64&&(n.target=r[6]),s[0]&256&&(n.editor=r[24](r[39].target.selector)),s[0]&256&&(n.annotation=r[39]),s[0]&2&&(n.style=r[1]),s[0]&4096&&(n.transform=r[12]),s[0]&131072&&(n.viewportScale=r[17]),t.$set(n)},i(i){e||(it(t.$$.fragment,i),e=!0)},o(i){dt(t.$$.fragment,i),e=!1},d(i){pe(t,i)}}}function Gu(r){let t,e,i=r[40]&&Uu(r);return{c(){i&&i.c(),t=Ie()},m(s,n){i&&i.m(s,n),ot(s,t,n),e=!0},p(s,n){s[40]?i?(i.p(s,n),n[0]&256&&it(i,1)):(i=Uu(s),i.c(),it(i,1),i.m(t.parentNode,t)):i&&(xe(),dt(i,1,1,()=>{i=null}),be())},i(s){e||(it(i),e=!0)},o(s){dt(i),e=!1},d(s){s&&nt(t),i&&i.d(s)}}}function j_(r){let t,e,i,s,n,o,a=Ee(r[16].filter(r[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=Lu(Ou(r,a,c));const h=c=>dt(l[c],1,1,()=>{l[c]=null});let u=r[6]&&Bu(r);return{c(){t=mt("svg"),e=mt("g");for(let c=0;c<l.length;c+=1)l[c].c();i=mt("g"),u&&u.c(),A(i,"class","drawing"),A(t,"class","a9s-annotationlayer"),Mr(t,"drawing",r[14]),Mr(t,"hidden",!r[3]),Mr(t,"hover",r[15])},m(c,d){ot(c,t,d),Oe(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);Oe(t,i),u&&u.m(i,null),r[35](i),r[36](t),s=!0,n||(o=[Bt(t,"pointerup",function(){$t(r[10])&&r[10].apply(this,arguments)}),Bt(t,"pointerdown",function(){$t(r[11])&&r[11].apply(this,arguments)}),Bt(t,"pointermove",r[23])],n=!0)},p(c,d){if(r=c,d[0]&66050){a=Ee(r[16].filter(r[34]));let p;for(p=0;p<a.length;p+=1){const f=Ou(r,a,p);l[p]?(l[p].p(f,d),it(l[p],1)):(l[p]=Lu(f),l[p].c(),it(l[p],1),l[p].m(e,null))}for(xe(),p=a.length;p<l.length;p+=1)h(p);be()}r[6]?u?(u.p(r,d),d[0]&64&&it(u,1)):(u=Bu(r),u.c(),it(u,1),u.m(i,null)):u&&(xe(),dt(u,1,1,()=>{u=null}),be()),(!s||d[0]&16384)&&Mr(t,"drawing",r[14]),(!s||d[0]&8)&&Mr(t,"hidden",!r[3]),(!s||d[0]&32768)&&Mr(t,"hover",r[15])},i(c){if(!s){for(let d=0;d<a.length;d+=1)it(l[d]);it(u),s=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)dt(l[d]);dt(u),s=!1},d(c){c&&nt(t),Jr(l,c),u&&u.d(),r[35](null),r[36](null),n=!1,Ue(o)}}}function q_(r,t,e){let i,s,n,o,a,l,h,u,c,d,p,f=Ct,m=()=>(f(),f=Dh(I,O=>e(17,p=O)),I);r.$$.on_destroy.push(()=>f());let{drawingEnabled:y}=t,{image:_}=t,{preferredDrawingMode:v}=t,{state:g}=t,{style:x=void 0}=t,{toolName:b=hn()[0]}=t,{user:S}=t,{visible:w=!0}=t,T=0;const N=()=>e(5,T+=1),F=()=>b,z=()=>y;let C,E,I;ms(()=>m(e(7,I=Zy(_,E))));const{hover:P,selection:$,store:k}=g;zo(r,P,O=>e(15,u=O)),zo(r,$,O=>e(33,c=O)),zo(r,k,O=>e(16,d=O));let G,st;const M=O=>{G&&k.unobserve(G);const D=O.filter(({editable:ut})=>ut).map(({id:ut})=>ut);D.length>0?(e(8,st=D.map(ut=>k.getAnnotation(ut)).filter(ut=>ut&&Ge(ut))),G=ut=>{const{updated:lt}=ut.changes;e(8,st=lt==null?void 0:lt.map(Et=>Et.newValue))},k.observe(G,{annotations:D})):e(8,st=void 0)},L=O=>{const D=ru(),ut={id:D,bodies:[],target:{annotation:D,selector:O.detail,creator:S,created:new Date}};k.addAnnotation(ut),$.setSelected(ut.id)},V=O=>D=>{var ut;const{target:lt}=O,Et=10*60*1e3,Tt=((ut=lt.creator)==null?void 0:ut.id)!==S.id||!lt.created||new Date().getTime()-lt.created.getTime()>Et;k.updateTarget({...lt,selector:D.detail,created:Tt?lt.created:new Date,updated:Tt?new Date:void 0,updatedBy:Tt?S:void 0})},rt=O=>{const{x:D,y:ut}=Mu(O,E),lt=k.getAt(D,ut);lt?u!==lt.id&&P.set(lt.id):P.set(void 0)},Q=O=>bu(O),X=O=>Ge(O);function _t(O){en[O?"unshift":"push"](()=>{C=O,e(6,C)})}function St(O){en[O?"unshift":"push"](()=>{E=O,e(4,E)})}return r.$$set=O=>{"drawingEnabled"in O&&e(0,y=O.drawingEnabled),"image"in O&&e(25,_=O.image),"preferredDrawingMode"in O&&e(26,v=O.preferredDrawingMode),"state"in O&&e(27,g=O.state),"style"in O&&e(1,x=O.style),"toolName"in O&&e(2,b=O.toolName),"user"in O&&e(28,S=O.user),"visible"in O&&e(3,w=O.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(14,{tool:i,opts:s}=un(b)||{tool:void 0,opts:void 0},i,(e(32,s),e(2,b))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(13,n=(s==null?void 0:s.drawingMode)||v),r.$$.dirty[0]&16&&e(12,o=k_(E)),r.$$.dirty[0]&16&&e(11,{onPointerDown:a,onPointerUp:l}=$_(E,k),a,(e(10,l),e(4,E))),r.$$.dirty[1]&4&&e(9,h=O=>c.selected.find(D=>D.id===O.id&&D.editable)),r.$$.dirty[1]&4&&M(c.selected)},[y,x,b,w,E,T,C,I,st,h,l,a,o,n,i,u,d,p,P,$,k,L,V,rt,Q,_,v,g,S,N,F,z,s,c,X,_t,St]}class K_ extends we{constructor(t){super(),Te(this,t,q_,j_,te,{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 $u(r,t,e=0,i=r.length-1,s=Z_){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,u=Math.log(l),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(l-c)/l)*(h-l/2<0?-1:1),p=Math.max(e,Math.floor(t-h*c/l+d)),f=Math.min(i,Math.floor(t+(l-h)*c/l+d));$u(r,t,p,f,s)}const n=r[t];let o=e,a=i;for(ys(r,e,t),s(r[i],n)>0&&ys(r,e,i);o<a;){for(ys(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?ys(r,e,a):(a++,ys(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function ys(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function Z_(r,t){return r<t?-1:r>t?1:0}class Q_{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 e=this.data;const i=[];if(!dn(t,e))return i;const s=this.toBBox,n=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?s(a):a;dn(t,l)&&(e.leaf?i.push(a):fa(t,l)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!dn(t,e))return!1;const i=[];for(;e;){for(let s=0;s<e.children.length;s++){const n=e.children[s],o=e.leaf?this.toBBox(n):n;if(dn(t,o)){if(e.leaf||fa(t,o))return!0;i.push(n)}}e=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 e=this._build(t.slice(),0,t.length-1,0);if(!this.data.children.length)this.data=e;else if(this.data.height===e.height)this._splitRoot(this.data,e);else{if(this.data.height<e.height){const i=this.data;this.data=e,e=i}this._insert(e,this.data.height-e.height-1,!0)}return this}insert(t){return t&&this._insert(t,this.data.height-1),this}clear(){return this.data=Di([]),this}remove(t,e){if(!t)return this;let i=this.data;const s=this.toBBox(t),n=[],o=[];let a,l,h;for(;i||n.length;){if(i||(i=n.pop(),l=n[n.length-1],a=o.pop(),h=!0),i.leaf){const u=J_(t,i.children,e);if(u!==-1)return i.children.splice(u,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&fa(i,s)?(n.push(i),o.push(a),a=0,l=i,i=i.children[0]):l?(a++,i=l.children[a],h=!1):i=null}return this}toBBox(t){return t}compareMinX(t,e){return t.minX-e.minX}compareMinY(t,e){return t.minY-e.minY}toJSON(){return this.data}fromJSON(t){return this.data=t,this}_all(t,e){const i=[];for(;t;)t.leaf?e.push(...t.children):i.push(...t.children),t=i.pop();return e}_build(t,e,i,s){const n=i-e+1;let o=this._maxEntries,a;if(n<=o)return a=Di(t.slice(e,i+1)),Ni(a,this.toBBox),a;s||(s=Math.ceil(Math.log(n)/Math.log(o)),o=Math.ceil(n/Math.pow(o,s-1))),a=Di([]),a.leaf=!1,a.height=s;const l=Math.ceil(n/o),h=l*Math.ceil(Math.sqrt(o));Hu(t,e,i,h,this.compareMinX);for(let u=e;u<=i;u+=h){const c=Math.min(u+h-1,i);Hu(t,u,c,l,this.compareMinY);for(let d=u;d<=c;d+=l){const p=Math.min(d+l-1,c);a.children.push(this._build(t,d,p,s-1))}}return Ni(a,this.toBBox),a}_chooseSubtree(t,e,i,s){for(;s.push(e),!(e.leaf||s.length-1===i);){let n=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],u=da(h),c=r0(t,h)-u;c<o?(o=c,n=u<n?u:n,a=h):c===o&&u<n&&(n=u,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const s=i?t:this.toBBox(t),n=[],o=this._chooseSubtree(s,this.data,e,n);for(o.children.push(t),vs(o,s);e>=0&&n[e].children.length>this._maxEntries;)this._split(n,e),e--;this._adjustParentBBoxes(s,n,e)}_split(t,e){const i=t[e],s=i.children.length,n=this._minEntries;this._chooseSplitAxis(i,n,s);const o=this._chooseSplitIndex(i,n,s),a=Di(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Ni(i,this.toBBox),Ni(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Di([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Ni(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let s,n=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=_s(t,0,a,this.toBBox),h=_s(t,a,i,this.toBBox),u=i0(l,h),c=da(l)+da(h);u<n?(n=u,s=a,o=c<o?c:o):u===n&&c<o&&(o=c,s=a)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:t0,n=t.leaf?this.compareMinY:e0,o=this._allDistMargin(t,e,i,s),a=this._allDistMargin(t,e,i,n);o<a&&t.children.sort(s)}_allDistMargin(t,e,i,s){t.children.sort(s);const n=this.toBBox,o=_s(t,0,e,n),a=_s(t,i-e,i,n);let l=cn(o)+cn(a);for(let h=e;h<i-e;h++){const u=t.children[h];vs(o,t.leaf?n(u):u),l+=cn(o)}for(let h=i-e-1;h>=e;h--){const u=t.children[h];vs(a,t.leaf?n(u):u),l+=cn(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)vs(e[s],t)}_condense(t){for(let e=t.length-1,i;e>=0;e--)t[e].children.length===0?e>0?(i=t[e-1].children,i.splice(i.indexOf(t[e]),1)):this.clear():Ni(t[e],this.toBBox)}}function J_(r,t,e){if(!e)return t.indexOf(r);for(let i=0;i<t.length;i++)if(e(r,t[i]))return i;return-1}function Ni(r,t){_s(r,0,r.children.length,t,r)}function _s(r,t,e,i,s){s||(s=Di(null)),s.minX=1/0,s.minY=1/0,s.maxX=-1/0,s.maxY=-1/0;for(let n=t;n<e;n++){const o=r.children[n];vs(s,r.leaf?i(o):o)}return s}function vs(r,t){return r.minX=Math.min(r.minX,t.minX),r.minY=Math.min(r.minY,t.minY),r.maxX=Math.max(r.maxX,t.maxX),r.maxY=Math.max(r.maxY,t.maxY),r}function t0(r,t){return r.minX-t.minX}function e0(r,t){return r.minY-t.minY}function da(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function cn(r){return r.maxX-r.minX+(r.maxY-r.minY)}function r0(r,t){return(Math.max(t.maxX,r.maxX)-Math.min(t.minX,r.minX))*(Math.max(t.maxY,r.maxY)-Math.min(t.minY,r.minY))}function i0(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),s=Math.min(r.maxX,t.maxX),n=Math.min(r.maxY,t.maxY);return Math.max(0,s-e)*Math.max(0,n-i)}function fa(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function dn(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function Di(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Hu(r,t,e,i,s){const n=[t,e];for(;n.length;){if(e=n.pop(),t=n.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;$u(r,o,t,e,s),n.push(t,o,o,e)}}const s0=()=>{const r=new Q_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},s=o=>{if(!nn(o))return;const{minX:a,minY:l,maxX:h,maxY:u}=o.selector.geometry.bounds,c={minX:a,minY:l,maxX:h,maxY:u,target:o};r.insert(c),t.set(o.annotation,c)},n=o=>{if(!nn(o))return;const a=t.get(o.annotation);a&&r.remove(a),t.delete(o.annotation)};return{all:e,clear:i,getAt:(o,a)=>{const l=r.search({minX:o,minY:a,maxX:o,maxY:a}).map(h=>h.target).filter(h=>h.selector.type===vt.RECTANGLE||vg(h.selector,o,a));if(l.length>0)return l.sort((h,u)=>Ko(h.selector)-Ko(u.selector)),l[0]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(u=>u.target),insert:s,remove:n,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,u)=>{if(nn(u)){const{minX:c,minY:d,maxX:p,maxY:f}=u.selector.geometry.bounds;return[...h,{minX:c,minY:d,maxX:p,maxY:f,target:u}]}else return h},[]);l.forEach(h=>t.set(h.target.annotation,h)),r.load(l)},size:()=>r.all().length,update:(o,a)=>{n(o),s(a)}}},Vu=r=>{const t=Ey(),e=s0(),i=hy(t,r.userSelectAction,r.adapter),s=ly(t),n=Cy();return t.observe(({changes:o})=>{e.set((o.created||[]).map(a=>a.target),!1),(o.deleted||[]).forEach(a=>e.remove(a.target)),(o.updated||[]).forEach(({oldValue:a,newValue:l})=>e.update(a.target,l.target))}),{store:{...t,getAt:(o,a)=>{const l=e.getAt(o,a);return l?t.getAnnotation(l.annotation):void 0},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(u=>t.getAnnotation(u.annotation))},selection:i,hover:s,viewport:n}},n0=r=>{const t=Vu(r);return{...t,store:Ty(t.store)}},o0=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const s=r;t=document.createElement("canvas"),t.width=s.width,t.height=s.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(s,0,0,s.width,s.height)}let i=0;for(let s=1;s<10;s++)for(let n=1;n<10;n++){const o=Math.round(n*t.width/10),a=Math.round(s*t.height/10),l=e.getImageData(o,a,1,1).data,h=(.299*l[0]+.587*l[1]+.114*l[2])/255;i+=h}return i/81},Xu=r=>{const t=o0(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},zu=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?Xu(r):e),Wu=(r,t)=>({...r,drawingEnabled:r.drawingEnabled===void 0?t.drawingEnabled:r.drawingEnabled,drawingMode:r.drawingMode||t.drawingMode,userSelectAction:r.userSelectAction||t.userSelectAction,theme:r.theme||t.theme}),Yu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,ju=(r,t)=>{const e=t||document,i=o=>{const a=o;a.key==="z"&&a.ctrlKey?r.undo():a.key==="y"&&a.ctrlKey&&r.redo()},s=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},n=()=>{Yu?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Yu?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},a0=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=Wu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:su.EDIT,theme:"light"}),s=n0(i),{selection:n,store:o}=s,a=Sy(o,i.initialHistory),l=Iy(s,a,i.adapter,i.autoSave),h=document.createElement("DIV");h.style.position="relative",h.style.display="inline-block",e.style.display="block",e.parentNode.insertBefore(h,e),h.appendChild(e);const u=ju(a);let c=Uy();zu(e,h,i.theme);const d=new K_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:c}});d.$on("click",C=>{const{originalEvent:E,annotation:I}=C.detail;I?n.userSelect(I.id,E):n.isEmpty()||n.clear()});const p=My(s,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),u.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>c,v=()=>d.isDrawingEnabled(),g=(C,E,I)=>Cu(C,E,I),x=(C,E)=>Eu(C,E),b=C=>{if(!un(C))throw`No drawing tool named ${C}`;d.$set({toolName:C})},S=C=>d.$set({drawingEnabled:C}),w=C=>{console.warn("Filter not implemented yet")},T=C=>d.$set({style:C}),N=C=>zu(e,h,C),F=C=>{c=C,d.$set({user:C})},z=C=>d.$set({visible:C});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:hn,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:x,setDrawingEnabled:S,setDrawingTool:b,setFilter:w,setStyle:T,setTheme:N,setUser:F,setVisible:z,element:h,state:s}};function me(){}function pa(r,t){for(const e in t)r[e]=t[e];return r}function qu(r){return r()}function Ku(){return Object.create(null)}function er(r){r.forEach(qu)}function Kt(r){return typeof r=="function"}function Wt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function l0(r){return Object.keys(r).length===0}function h0(r,...t){if(r==null){for(const i of t)i(void 0);return me}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function fn(r,t,e){r.$$.on_destroy.push(h0(t,e))}function Zu(r,t,e,i){if(r){const s=Qu(r,t,e,i);return r[0](s)}}function Qu(r,t,e,i){return r[1]&&i?pa(e.ctx.slice(),r[1](i(t))):e.ctx}function Ju(r,t,e,i){if(r[2]&&i){const s=r[2](i(e));if(t.dirty===void 0)return s;if(typeof s=="object"){const n=[],o=Math.max(t.dirty.length,s.length);for(let a=0;a<o;a+=1)n[a]=t.dirty[a]|s[a];return n}return t.dirty|s}return t.dirty}function tc(r,t,e,i,s,n){if(s){const o=Qu(t,e,i,n);r.p(o,s)}}function ec(r){if(r.ctx.length>32){const t=[],e=r.ctx.length/32;for(let i=0;i<e;i++)t[i]=-1;return t}return-1}function rc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function pn(r){return r??""}const ic=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ae(r,t){r.appendChild(t)}function ct(r,t,e){r.insertBefore(t,e||null)}function ht(r){r.parentNode&&r.parentNode.removeChild(r)}function ii(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function xt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ma(r){return document.createTextNode(r)}function Ve(){return ma(" ")}function Re(){return ma("")}function Zt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function R(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function u0(r){return Array.from(r.childNodes)}function c0(r,t){t=""+t,r.data!==t&&(r.data=t)}function mn(r,t,e){r.classList.toggle(t,!!e)}function d0(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let xs;function bs(r){xs=r}function ga(){if(!xs)throw new Error("Function called outside component initialization");return xs}function gn(r){ga().$$.on_mount.push(r)}function f0(r){ga().$$.on_destroy.push(r)}function yn(){const r=ga();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=d0(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function De(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Li=[],_n=[];let Bi=[];const sc=[],p0=Promise.resolve();let ya=!1;function m0(){ya||(ya=!0,p0.then(nc))}function _a(r){Bi.push(r)}const va=new Set;let Fi=0;function nc(){if(Fi!==0)return;const r=xs;do{try{for(;Fi<Li.length;){const t=Li[Fi];Fi++,bs(t),g0(t.$$)}}catch(t){throw Li.length=0,Fi=0,t}for(bs(null),Li.length=0,Fi=0;_n.length;)_n.pop()();for(let t=0;t<Bi.length;t+=1){const e=Bi[t];va.has(e)||(va.add(e),e())}Bi.length=0}while(Li.length);for(;sc.length;)sc.pop()();ya=!1,va.clear(),bs(r)}function g0(r){if(r.fragment!==null){r.update(),er(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(_a)}}function y0(r){const t=[],e=[];Bi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Bi=t}const vn=new Set;let si;function ge(){si={r:0,c:[],p:si}}function ye(){si.r||er(si.c),si=si.p}function q(r,t){r&&r.i&&(vn.delete(r),r.i(t))}function et(r,t,e,i){if(r&&r.o){if(vn.has(r))return;vn.add(r),si.c.push(()=>{vn.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Se(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Ht(r){r&&r.c()}function Ft(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),_a(()=>{const n=r.$$.on_mount.map(qu).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...n):er(n),r.$$.on_mount=[]}),s.forEach(_a)}function Ut(r,t){const e=r.$$;e.fragment!==null&&(y0(e.after_update),er(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function _0(r,t){r.$$.dirty[0]===-1&&(Li.push(r),m0(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ee(r,t,e,i,s,n,o=null,a=[-1]){const l=xs;bs(r);const h=r.$$={fragment:null,ctx:[],props:n,update:me,not_equal:s,bound:Ku(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Ku(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let u=!1;if(h.ctx=e?e(r,t.props||{},(c,d,...p)=>{const f=p.length?p[0]:d;return h.ctx&&s(h.ctx[c],h.ctx[c]=f)&&(!h.skip_bound&&h.bound[c]&&h.bound[c](f),u&&_0(r,c)),d}):[],h.update(),u=!0,er(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=u0(t.target);h.fragment&&h.fragment.l(c),c.forEach(ht)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Ft(r,t.target,t.anchor),nc()}bs(l)}class re{constructor(){Pt(this,"$$");Pt(this,"$$set")}$destroy(){Ut(this,1),this.$destroy=me}$on(t,e){if(!Kt(e))return me;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const s=i.indexOf(e);s!==-1&&i.splice(s,1)}}$set(t){this.$$set&&!l0(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const v0="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(v0);var ni=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(ni||{}),oc=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(oc||{}),xa=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(xa||{}),at=(r=>(r[r.NORMAL=0]="NORMAL",r[r.ADD=1]="ADD",r[r.MULTIPLY=2]="MULTIPLY",r[r.SCREEN=3]="SCREEN",r[r.OVERLAY=4]="OVERLAY",r[r.DARKEN=5]="DARKEN",r[r.LIGHTEN=6]="LIGHTEN",r[r.COLOR_DODGE=7]="COLOR_DODGE",r[r.COLOR_BURN=8]="COLOR_BURN",r[r.HARD_LIGHT=9]="HARD_LIGHT",r[r.SOFT_LIGHT=10]="SOFT_LIGHT",r[r.DIFFERENCE=11]="DIFFERENCE",r[r.EXCLUSION=12]="EXCLUSION",r[r.HUE=13]="HUE",r[r.SATURATION=14]="SATURATION",r[r.COLOR=15]="COLOR",r[r.LUMINOSITY=16]="LUMINOSITY",r[r.NORMAL_NPM=17]="NORMAL_NPM",r[r.ADD_NPM=18]="ADD_NPM",r[r.SCREEN_NPM=19]="SCREEN_NPM",r[r.NONE=20]="NONE",r[r.SRC_OVER=0]="SRC_OVER",r[r.SRC_IN=21]="SRC_IN",r[r.SRC_OUT=22]="SRC_OUT",r[r.SRC_ATOP=23]="SRC_ATOP",r[r.DST_OVER=24]="DST_OVER",r[r.DST_IN=25]="DST_IN",r[r.DST_OUT=26]="DST_OUT",r[r.DST_ATOP=27]="DST_ATOP",r[r.ERASE=26]="ERASE",r[r.SUBTRACT=28]="SUBTRACT",r[r.XOR=29]="XOR",r))(at||{}),rr=(r=>(r[r.POINTS=0]="POINTS",r[r.LINES=1]="LINES",r[r.LINE_LOOP=2]="LINE_LOOP",r[r.LINE_STRIP=3]="LINE_STRIP",r[r.TRIANGLES=4]="TRIANGLES",r[r.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",r[r.TRIANGLE_FAN=6]="TRIANGLE_FAN",r))(rr||{}),H=(r=>(r[r.RGBA=6408]="RGBA",r[r.RGB=6407]="RGB",r[r.RG=33319]="RG",r[r.RED=6403]="RED",r[r.RGBA_INTEGER=36249]="RGBA_INTEGER",r[r.RGB_INTEGER=36248]="RGB_INTEGER",r[r.RG_INTEGER=33320]="RG_INTEGER",r[r.RED_INTEGER=36244]="RED_INTEGER",r[r.ALPHA=6406]="ALPHA",r[r.LUMINANCE=6409]="LUMINANCE",r[r.LUMINANCE_ALPHA=6410]="LUMINANCE_ALPHA",r[r.DEPTH_COMPONENT=6402]="DEPTH_COMPONENT",r[r.DEPTH_STENCIL=34041]="DEPTH_STENCIL",r))(H||{}),Ui=(r=>(r[r.TEXTURE_2D=3553]="TEXTURE_2D",r[r.TEXTURE_CUBE_MAP=34067]="TEXTURE_CUBE_MAP",r[r.TEXTURE_2D_ARRAY=35866]="TEXTURE_2D_ARRAY",r[r.TEXTURE_CUBE_MAP_POSITIVE_X=34069]="TEXTURE_CUBE_MAP_POSITIVE_X",r[r.TEXTURE_CUBE_MAP_NEGATIVE_X=34070]="TEXTURE_CUBE_MAP_NEGATIVE_X",r[r.TEXTURE_CUBE_MAP_POSITIVE_Y=34071]="TEXTURE_CUBE_MAP_POSITIVE_Y",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Y=34072]="TEXTURE_CUBE_MAP_NEGATIVE_Y",r[r.TEXTURE_CUBE_MAP_POSITIVE_Z=34073]="TEXTURE_CUBE_MAP_POSITIVE_Z",r[r.TEXTURE_CUBE_MAP_NEGATIVE_Z=34074]="TEXTURE_CUBE_MAP_NEGATIVE_Z",r))(Ui||{}),tt=(r=>(r[r.UNSIGNED_BYTE=5121]="UNSIGNED_BYTE",r[r.UNSIGNED_SHORT=5123]="UNSIGNED_SHORT",r[r.UNSIGNED_SHORT_5_6_5=33635]="UNSIGNED_SHORT_5_6_5",r[r.UNSIGNED_SHORT_4_4_4_4=32819]="UNSIGNED_SHORT_4_4_4_4",r[r.UNSIGNED_SHORT_5_5_5_1=32820]="UNSIGNED_SHORT_5_5_5_1",r[r.UNSIGNED_INT=5125]="UNSIGNED_INT",r[r.UNSIGNED_INT_10F_11F_11F_REV=35899]="UNSIGNED_INT_10F_11F_11F_REV",r[r.UNSIGNED_INT_2_10_10_10_REV=33640]="UNSIGNED_INT_2_10_10_10_REV",r[r.UNSIGNED_INT_24_8=34042]="UNSIGNED_INT_24_8",r[r.UNSIGNED_INT_5_9_9_9_REV=35902]="UNSIGNED_INT_5_9_9_9_REV",r[r.BYTE=5120]="BYTE",r[r.SHORT=5122]="SHORT",r[r.INT=5124]="INT",r[r.FLOAT=5126]="FLOAT",r[r.FLOAT_32_UNSIGNED_INT_24_8_REV=36269]="FLOAT_32_UNSIGNED_INT_24_8_REV",r[r.HALF_FLOAT=36193]="HALF_FLOAT",r))(tt||{}),Y=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Y||{}),vr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(vr||{}),Dr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Dr||{}),ir=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(ir||{}),Ce=(r=>(r[r.NPM=0]="NPM",r[r.UNPACK=1]="UNPACK",r[r.PMA=2]="PMA",r[r.NO_PREMULTIPLIED_ALPHA=0]="NO_PREMULTIPLIED_ALPHA",r[r.PREMULTIPLY_ON_UPLOAD=1]="PREMULTIPLY_ON_UPLOAD",r[r.PREMULTIPLIED_ALPHA=2]="PREMULTIPLIED_ALPHA",r))(Ce||{}),sr=(r=>(r[r.NO=0]="NO",r[r.YES=1]="YES",r[r.AUTO=2]="AUTO",r[r.BLEND=0]="BLEND",r[r.CLEAR=1]="CLEAR",r[r.BLIT=2]="BLIT",r))(sr||{}),ba=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(ba||{}),Le=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(Le||{}),Qt=(r=>(r[r.NONE=0]="NONE",r[r.SCISSOR=1]="SCISSOR",r[r.STENCIL=2]="STENCIL",r[r.SPRITE=3]="SPRITE",r[r.COLOR=4]="COLOR",r))(Qt||{}),Yt=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(Yt||{}),nr=(r=>(r[r.ELEMENT_ARRAY_BUFFER=34963]="ELEMENT_ARRAY_BUFFER",r[r.ARRAY_BUFFER=34962]="ARRAY_BUFFER",r[r.UNIFORM_BUFFER=35345]="UNIFORM_BUFFER",r))(nr||{});const j={ADAPTER:{createCanvas:(r,t)=>{const e=document.createElement("canvas");return e.width=r,e.height=t,e},getCanvasRenderingContext2D:()=>CanvasRenderingContext2D,getWebGLRenderingContext:()=>WebGLRenderingContext,getNavigator:()=>navigator,getBaseUrl:()=>document.baseURI??window.location.href,getFontFaceSet:()=>document.fonts,fetch:(r,t)=>fetch(r,t),parseXML:r=>new DOMParser().parseFromString(r,"text/xml")},RESOLUTION:1,CREATE_IMAGE_BITMAP:!1,ROUND_PIXELS:!1};var Ea=/iPhone/i,ac=/iPod/i,lc=/iPad/i,hc=/\biOS-universal(?:.+)Mac\b/i,Ta=/\bAndroid(?:.+)Mobile\b/i,uc=/Android/i,ki=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,xn=/Silk/i,xr=/Windows Phone/i,cc=/\bWindows(?:.+)ARM\b/i,dc=/BlackBerry/i,fc=/BB10/i,pc=/Opera Mini/i,mc=/\b(CriOS|Chrome)(?:.+)Mobile/i,gc=/Mobile(?:.+)Firefox\b/i,yc=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function x0(r){return function(t){return t.test(r)}}function _c(r){var t={userAgent:"",platform:"",maxTouchPoints:0};!r&&typeof navigator<"u"?t={userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints||0}:typeof r=="string"?t.userAgent=r:r&&r.userAgent&&(t={userAgent:r.userAgent,platform:r.platform,maxTouchPoints:r.maxTouchPoints||0});var e=t.userAgent,i=e.split("[FBAN");typeof i[1]<"u"&&(e=i[0]),i=e.split("Twitter"),typeof i[1]<"u"&&(e=i[0]);var s=x0(e),n={apple:{phone:s(Ea)&&!s(xr),ipod:s(ac),tablet:!s(Ea)&&(s(lc)||yc(t))&&!s(xr),universal:s(hc),device:(s(Ea)||s(ac)||s(lc)||s(hc)||yc(t))&&!s(xr)},amazon:{phone:s(ki),tablet:!s(ki)&&s(xn),device:s(ki)||s(xn)},android:{phone:!s(xr)&&s(ki)||!s(xr)&&s(Ta),tablet:!s(xr)&&!s(ki)&&!s(Ta)&&(s(xn)||s(uc)),device:!s(xr)&&(s(ki)||s(xn)||s(Ta)||s(uc))||s(/\bokhttp\b/i)},windows:{phone:s(xr),tablet:s(cc),device:s(xr)||s(cc)},other:{blackberry:s(dc),blackberry10:s(fc),opera:s(pc),firefox:s(gc),chrome:s(mc),device:s(dc)||s(fc)||s(pc)||s(gc)||s(mc)},any:!1,phone:!1,tablet:!1};return n.any=n.apple.device||n.android.device||n.windows.device||n.other.device,n.phone=n.apple.phone||n.android.phone||n.windows.phone,n.tablet=n.apple.tablet||n.android.tablet||n.windows.tablet,n}const b0=_c.default??_c,br=b0(globalThis.navigator);j.RETINA_PREFIX=/@([0-9\.]+)x/,j.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Es=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vc(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function E0(r){if(r.__esModule)return r;var t=r.default;if(typeof t=="function"){var e=function i(){return this instanceof i?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(i){var s=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,s.get?s:{enumerable:!0,get:function(){return r[i]}})}),e}var xc={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function s(l,h,u){this.fn=l,this.context=h,this.once=u||!1}function n(l,h,u,c,d){if(typeof u!="function")throw new TypeError("The listener must be a function");var p=new s(u,c||l,d),f=e?e+h:h;return l._events[f]?l._events[f].fn?l._events[f]=[l._events[f],p]:l._events[f].push(p):(l._events[f]=p,l._eventsCount++),l}function o(l,h){--l._eventsCount===0?l._events=new i:delete l._events[h]}function a(){this._events=new i,this._eventsCount=0}a.prototype.eventNames=function(){var h=[],u,c;if(this._eventsCount===0)return h;for(c in u=this._events)t.call(u,c)&&h.push(e?c.slice(1):c);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(u)):h},a.prototype.listeners=function(h){var u=e?e+h:h,c=this._events[u];if(!c)return[];if(c.fn)return[c.fn];for(var d=0,p=c.length,f=new Array(p);d<p;d++)f[d]=c[d].fn;return f},a.prototype.listenerCount=function(h){var u=e?e+h:h,c=this._events[u];return c?c.fn?1:c.length:0},a.prototype.emit=function(h,u,c,d,p,f){var m=e?e+h:h;if(!this._events[m])return!1;var y=this._events[m],_=arguments.length,v,g;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,u),!0;case 3:return y.fn.call(y.context,u,c),!0;case 4:return y.fn.call(y.context,u,c,d),!0;case 5:return y.fn.call(y.context,u,c,d,p),!0;case 6:return y.fn.call(y.context,u,c,d,p,f),!0}for(g=1,v=new Array(_-1);g<_;g++)v[g-1]=arguments[g];y.fn.apply(y.context,v)}else{var x=y.length,b;for(g=0;g<x;g++)switch(y[g].once&&this.removeListener(h,y[g].fn,void 0,!0),_){case 1:y[g].fn.call(y[g].context);break;case 2:y[g].fn.call(y[g].context,u);break;case 3:y[g].fn.call(y[g].context,u,c);break;case 4:y[g].fn.call(y[g].context,u,c,d);break;default:if(!v)for(b=1,v=new Array(_-1);b<_;b++)v[b-1]=arguments[b];y[g].fn.apply(y[g].context,v)}}return!0},a.prototype.on=function(h,u,c){return n(this,h,u,c,!1)},a.prototype.once=function(h,u,c){return n(this,h,u,c,!0)},a.prototype.removeListener=function(h,u,c,d){var p=e?e+h:h;if(!this._events[p])return this;if(!u)return o(this,p),this;var f=this._events[p];if(f.fn)f.fn===u&&(!d||f.once)&&(!c||f.context===c)&&o(this,p);else{for(var m=0,y=[],_=f.length;m<_;m++)(f[m].fn!==u||d&&!f[m].once||c&&f[m].context!==c)&&y.push(f[m]);y.length?this._events[p]=y.length===1?y[0]:y:o(this,p)}return this},a.prototype.removeAllListeners=function(h){var u;return h?(u=e?e+h:h,this._events[u]&&o(this,u)):(this._events=new i,this._eventsCount=0),this},a.prototype.off=a.prototype.removeListener,a.prototype.addListener=a.prototype.on,a.prefixed=e,a.EventEmitter=a,r.exports=a})(xc);var T0=xc.exports;const Ts=vc(T0);var wa={exports:{}};wa.exports=bn,wa.exports.default=bn;function bn(r,t,e){e=e||2;var i=t&&t.length,s=i?t[0]*e:r.length,n=bc(r,0,s,e,!0),o=[];if(!n||n.next===n.prev)return o;var a,l,h,u,c,d,p;if(i&&(n=I0(r,t,n,e)),r.length>80*e){a=h=r[0],l=u=r[1];for(var f=e;f<s;f+=e)c=r[f],d=r[f+1],c<a&&(a=c),d<l&&(l=d),c>h&&(h=c),d>u&&(u=d);p=Math.max(h-a,u-l),p=p!==0?32767/p:0}return ws(n,o,e,a,l,p,0),o}function bc(r,t,e,i,s){var n,o;if(s===Ca(r,t,e,i)>0)for(n=t;n<e;n+=i)o=wc(n,r[n],r[n+1],o);else for(n=e-i;n>=t;n-=i)o=wc(n,r[n],r[n+1],o);return o&&En(o,o.next)&&(Ss(o),o=o.next),o}function oi(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(En(e,e.next)||Nt(e.prev,e,e.next)===0)){if(Ss(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function ws(r,t,e,i,s,n,o){if(r){!o&&n&&N0(r,i,s,n);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,n?A0(r,i,s,n):w0(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Ss(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=S0(oi(r),t,e),ws(r,t,e,i,s,n,2)):o===2&&C0(r,t,e,i,s,n):ws(oi(r),t,e,i,s,n,1);break}}}}function w0(r){var t=r.prev,e=r,i=r.next;if(Nt(t,e,i)>=0)return!1;for(var s=t.x,n=e.x,o=i.x,a=t.y,l=e.y,h=i.y,u=s<n?s<o?s:o:n<o?n:o,c=a<l?a<h?a:h:l<h?l:h,d=s>n?s>o?s:o:n>o?n:o,p=a>l?a>h?a:h:l>h?l:h,f=i.next;f!==t;){if(f.x>=u&&f.x<=d&&f.y>=c&&f.y<=p&&Gi(s,a,n,l,o,h,f.x,f.y)&&Nt(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function A0(r,t,e,i){var s=r.prev,n=r,o=r.next;if(Nt(s,n,o)>=0)return!1;for(var a=s.x,l=n.x,h=o.x,u=s.y,c=n.y,d=o.y,p=a<l?a<h?a:h:l<h?l:h,f=u<c?u<d?u:d:c<d?c:d,m=a>l?a>h?a:h:l>h?l:h,y=u>c?u>d?u:d:c>d?c:d,_=Aa(p,f,t,e,i),v=Aa(m,y,t,e,i),g=r.prevZ,x=r.nextZ;g&&g.z>=_&&x&&x.z<=v;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==s&&g!==o&&Gi(a,u,l,c,h,d,g.x,g.y)&&Nt(g.prev,g,g.next)>=0||(g=g.prevZ,x.x>=p&&x.x<=m&&x.y>=f&&x.y<=y&&x!==s&&x!==o&&Gi(a,u,l,c,h,d,x.x,x.y)&&Nt(x.prev,x,x.next)>=0))return!1;x=x.nextZ}for(;g&&g.z>=_;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=y&&g!==s&&g!==o&&Gi(a,u,l,c,h,d,g.x,g.y)&&Nt(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;x&&x.z<=v;){if(x.x>=p&&x.x<=m&&x.y>=f&&x.y<=y&&x!==s&&x!==o&&Gi(a,u,l,c,h,d,x.x,x.y)&&Nt(x.prev,x,x.next)>=0)return!1;x=x.nextZ}return!0}function S0(r,t,e){var i=r;do{var s=i.prev,n=i.next.next;!En(s,n)&&Ec(s,i,i.next,n)&&As(s,n)&&As(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),Ss(i),Ss(i.next),i=r=n),i=i.next}while(i!==r);return oi(i)}function C0(r,t,e,i,s,n){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&B0(o,a)){var l=Tc(o,a);o=oi(o,o.next),l=oi(l,l.next),ws(o,t,e,i,s,n,0),ws(l,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function I0(r,t,e,i){var s=[],n,o,a,l,h;for(n=0,o=t.length;n<o;n++)a=t[n]*i,l=n<o-1?t[n+1]*i:r.length,h=bc(r,a,l,i,!1),h===h.next&&(h.steiner=!0),s.push(L0(h));for(s.sort(R0),n=0;n<s.length;n++)e=M0(s[n],e);return e}function R0(r,t){return r.x-t.x}function M0(r,t){var e=P0(r,t);if(!e)return t;var i=Tc(e,r);return oi(i,i.next),oi(e,e.next)}function P0(r,t){var e=t,i=r.x,s=r.y,n=-1/0,o;do{if(s<=e.y&&s>=e.next.y&&e.next.y!==e.y){var a=e.x+(s-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>n&&(n=a,o=e.x<e.next.x?e:e.next,a===i))return o}e=e.next}while(e!==t);if(!o)return null;var l=o,h=o.x,u=o.y,c=1/0,d;e=o;do i>=e.x&&e.x>=h&&i!==e.x&&Gi(s<u?i:n,s,h,u,s<u?n:i,s,e.x,e.y)&&(d=Math.abs(s-e.y)/(i-e.x),As(e,r)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&O0(o,e)))&&(o=e,c=d)),e=e.next;while(e!==l);return o}function O0(r,t){return Nt(r.prev,r,t.prev)<0&&Nt(t.next,r,r.next)<0}function N0(r,t,e,i){var s=r;do s.z===0&&(s.z=Aa(s.x,s.y,t,e,i)),s.prevZ=s.prev,s.nextZ=s.next,s=s.next;while(s!==r);s.prevZ.nextZ=null,s.prevZ=null,D0(s)}function D0(r){var t,e,i,s,n,o,a,l,h=1;do{for(e=r,r=null,n=null,o=0;e;){for(o++,i=e,a=0,t=0;t<h&&(a++,i=i.nextZ,!!i);t++);for(l=h;a>0||l>0&&i;)a!==0&&(l===0||!i||e.z<=i.z)?(s=e,e=e.nextZ,a--):(s=i,i=i.nextZ,l--),n?n.nextZ=s:r=s,s.prevZ=n,n=s;e=i}n.nextZ=null,h*=2}while(o>1);return r}function Aa(r,t,e,i,s){return r=(r-e)*s|0,t=(t-i)*s|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function L0(r){var t=r,e=r;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==r);return e}function Gi(r,t,e,i,s,n,o,a){return(s-o)*(t-a)>=(r-o)*(n-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(n-a)>=(s-o)*(i-a)}function B0(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!F0(r,t)&&(As(r,t)&&As(t,r)&&U0(r,t)&&(Nt(r.prev,r,t.prev)||Nt(r,t.prev,t))||En(r,t)&&Nt(r.prev,r,r.next)>0&&Nt(t.prev,t,t.next)>0)}function Nt(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function En(r,t){return r.x===t.x&&r.y===t.y}function Ec(r,t,e,i){var s=wn(Nt(r,t,e)),n=wn(Nt(r,t,i)),o=wn(Nt(e,i,r)),a=wn(Nt(e,i,t));return!!(s!==n&&o!==a||s===0&&Tn(r,e,t)||n===0&&Tn(r,i,t)||o===0&&Tn(e,r,i)||a===0&&Tn(e,t,i))}function Tn(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function wn(r){return r>0?1:r<0?-1:0}function F0(r,t){var e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&Ec(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function As(r,t){return Nt(r.prev,r,r.next)<0?Nt(r,t,r.next)>=0&&Nt(r,r.prev,t)>=0:Nt(r,t,r.prev)<0||Nt(r,r.next,t)<0}function U0(r,t){var e=r,i=!1,s=(r.x+t.x)/2,n=(r.y+t.y)/2;do e.y>n!=e.next.y>n&&e.next.y!==e.y&&s<(e.next.x-e.x)*(n-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function Tc(r,t){var e=new Sa(r.i,r.x,r.y),i=new Sa(t.i,t.x,t.y),s=r.next,n=t.prev;return r.next=t,t.prev=r,e.next=s,s.prev=e,i.next=e,e.prev=i,n.next=i,i.prev=n,i}function wc(r,t,e,i){var s=new Sa(r,t,e);return i?(s.next=i.next,s.prev=i,i.next.prev=s,i.next=s):(s.prev=s,s.next=s),s}function Ss(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function Sa(r,t,e){this.i=r,this.x=t,this.y=e,this.prev=null,this.next=null,this.z=0,this.prevZ=null,this.nextZ=null,this.steiner=!1}bn.deviation=function(r,t,e,i){var s=t&&t.length,n=s?t[0]*e:r.length,o=Math.abs(Ca(r,0,n,e));if(s)for(var a=0,l=t.length;a<l;a++){var h=t[a]*e,u=a<l-1?t[a+1]*e:r.length;o-=Math.abs(Ca(r,h,u,e))}var c=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,p=i[a+1]*e,f=i[a+2]*e;c+=Math.abs((r[d]-r[f])*(r[p+1]-r[d+1])-(r[d]-r[p])*(r[f+1]-r[d+1]))}return o===0&&c===0?0:Math.abs((c-o)/o)};function Ca(r,t,e,i){for(var s=0,n=t,o=e-i;n<e;n+=i)s+=(r[o]-r[n])*(r[n+1]+r[o+1]),o=n;return s}bn.flatten=function(r){for(var t=r[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,s=0;s<r.length;s++){for(var n=0;n<r[s].length;n++)for(var o=0;o<t;o++)e.vertices.push(r[s][n][o]);s>0&&(i+=r[s-1].length,e.holes.push(i))}return e};var k0=wa.exports;const G0=vc(k0);var An={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */An.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,s=r&&!r.nodeType&&r,n=typeof Es=="object"&&Es;(n.global===n||n.window===n||n.self===n)&&(e=n);var o,a=2147483647,l=36,h=1,u=26,c=38,d=700,p=72,f=128,m="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},x=l-h,b=Math.floor,S=String.fromCharCode,w;function T(M){throw new RangeError(g[M])}function N(M,L){for(var V=M.length,rt=[];V--;)rt[V]=L(M[V]);return rt}function F(M,L){var V=M.split("@"),rt="";V.length>1&&(rt=V[0]+"@",M=V[1]),M=M.replace(v,".");var Q=M.split("."),X=N(Q,L).join(".");return rt+X}function z(M){for(var L=[],V=0,rt=M.length,Q,X;V<rt;)Q=M.charCodeAt(V++),Q>=55296&&Q<=56319&&V<rt?(X=M.charCodeAt(V++),(X&64512)==56320?L.push(((Q&1023)<<10)+(X&1023)+65536):(L.push(Q),V--)):L.push(Q);return L}function C(M){return N(M,function(L){var V="";return L>65535&&(L-=65536,V+=S(L>>>10&1023|55296),L=56320|L&1023),V+=S(L),V}).join("")}function E(M){return M-48<10?M-22:M-65<26?M-65:M-97<26?M-97:l}function I(M,L){return M+22+75*(M<26)-((L!=0)<<5)}function P(M,L,V){var rt=0;for(M=V?b(M/d):M>>1,M+=b(M/L);M>x*u>>1;rt+=l)M=b(M/x);return b(rt+(x+1)*M/(M+c))}function $(M){var L=[],V=M.length,rt,Q=0,X=f,_t=p,St,O,D,ut,lt,Et,Tt,mr,gr;for(St=M.lastIndexOf(m),St<0&&(St=0),O=0;O<St;++O)M.charCodeAt(O)>=128&&T("not-basic"),L.push(M.charCodeAt(O));for(D=St>0?St+1:0;D<V;){for(ut=Q,lt=1,Et=l;D>=V&&T("invalid-input"),Tt=E(M.charCodeAt(D++)),(Tt>=l||Tt>b((a-Q)/lt))&&T("overflow"),Q+=Tt*lt,mr=Et<=_t?h:Et>=_t+u?u:Et-_t,!(Tt<mr);Et+=l)gr=l-mr,lt>b(a/gr)&&T("overflow"),lt*=gr;rt=L.length+1,_t=P(Q-ut,rt,ut==0),b(Q/rt)>a-X&&T("overflow"),X+=b(Q/rt),Q%=rt,L.splice(Q++,0,X)}return C(L)}function k(M){var L,V,rt,Q,X,_t,St,O,D,ut,lt,Et=[],Tt,mr,gr,js;for(M=z(M),Tt=M.length,L=f,V=0,X=p,_t=0;_t<Tt;++_t)lt=M[_t],lt<128&&Et.push(S(lt));for(rt=Q=Et.length,Q&&Et.push(m);rt<Tt;){for(St=a,_t=0;_t<Tt;++_t)lt=M[_t],lt>=L&&lt<St&&(St=lt);for(mr=rt+1,St-L>b((a-V)/mr)&&T("overflow"),V+=(St-L)*mr,L=St,_t=0;_t<Tt;++_t)if(lt=M[_t],lt<L&&++V>a&&T("overflow"),lt==L){for(O=V,D=l;ut=D<=X?h:D>=X+u?u:D-X,!(O<ut);D+=l)js=O-ut,gr=l-ut,Et.push(S(I(ut+js%gr,0))),O=b(js/gr);Et.push(S(I(O,0))),X=P(V,mr,rt==Q),V=0,++rt}++V,++L}return Et.join("")}function G(M){return F(M,function(L){return y.test(L)?$(L.slice(4).toLowerCase()):L})}function st(M){return F(M,function(L){return _.test(L)?"xn--"+k(L):L})}if(o={version:"1.4.1",ucs2:{decode:z,encode:C},decode:$,encode:k,toASCII:st,toUnicode:G},i&&s)if(r.exports==i)s.exports=o;else for(w in o)o.hasOwnProperty(w)&&(i[w]=o[w]);else e.punycode=o})(Es)}(An,An.exports);var $0=An.exports,$i=TypeError;const H0=E0(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Ia=typeof Map=="function"&&Map.prototype,Ra=Object.getOwnPropertyDescriptor&&Ia?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Sn=Ia&&Ra&&typeof Ra.get=="function"?Ra.get:null,Ac=Ia&&Map.prototype.forEach,Ma=typeof Set=="function"&&Set.prototype,Pa=Object.getOwnPropertyDescriptor&&Ma?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Cn=Ma&&Pa&&typeof Pa.get=="function"?Pa.get:null,Sc=Ma&&Set.prototype.forEach,V0=typeof WeakMap=="function"&&WeakMap.prototype,Cs=V0?WeakMap.prototype.has:null,X0=typeof WeakSet=="function"&&WeakSet.prototype,Is=X0?WeakSet.prototype.has:null,z0=typeof WeakRef=="function"&&WeakRef.prototype,Cc=z0?WeakRef.prototype.deref:null,W0=Boolean.prototype.valueOf,Y0=Object.prototype.toString,j0=Function.prototype.toString,q0=String.prototype.match,Oa=String.prototype.slice,Lr=String.prototype.replace,K0=String.prototype.toUpperCase,Ic=String.prototype.toLowerCase,Rc=RegExp.prototype.test,Mc=Array.prototype.concat,or=Array.prototype.join,Z0=Array.prototype.slice,Pc=Math.floor,Na=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Da=Object.getOwnPropertySymbols,La=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,Hi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Rs=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===Hi||!0)?Symbol.toStringTag:null,Oc=Object.prototype.propertyIsEnumerable,Nc=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Dc(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Rc.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Pc(-r):Pc(r);if(i!==r){var s=String(i),n=Oa.call(t,s.length+1);return Lr.call(s,e,"$&_")+"."+Lr.call(Lr.call(n,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Lr.call(t,e,"$&_")}var Ba=H0,Lc=Ba.custom,Bc=Gc(Lc)?Lc:null,Fc={__proto__:null,double:'"',single:"'"},Q0={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},In=function r(t,e,i,s){var n=e||{};if(Er(n,"quoteStyle")&&!Er(Fc,n.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Er(n,"maxStringLength")&&(typeof n.maxStringLength=="number"?n.maxStringLength<0&&n.maxStringLength!==1/0:n.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=Er(n,"customInspect")?n.customInspect:!0;if(typeof o!="boolean"&&o!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Er(n,"indent")&&n.indent!==null&&n.indent!==" "&&!(parseInt(n.indent,10)===n.indent&&n.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Er(n,"numericSeparator")&&typeof n.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=n.numericSeparator;if(typeof t>"u")return"undefined";if(t===null)return"null";if(typeof t=="boolean")return t?"true":"false";if(typeof t=="string")return Hc(t,n);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Dc(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Dc(t,h):h}var u=typeof n.depth>"u"?5:n.depth;if(typeof i>"u"&&(i=0),i>=u&&u>0&&typeof t=="object")return Fa(t)?"[Array]":"[Object]";var c=gv(n,i);if(typeof s>"u")s=[];else if($c(s,t)>=0)return"[Circular]";function d(E,I,P){if(I&&(s=Z0.call(s),s.push(I)),P){var $={depth:n.depth};return Er(n,"quoteStyle")&&($.quoteStyle=n.quoteStyle),r(E,$,i+1,s)}return r(E,n,i+1,s)}if(typeof t=="function"&&!kc(t)){var p=av(t),f=Rn(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+or.call(f,", ")+" }":"")}if(Gc(t)){var m=Hi?Lr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):La.call(t);return typeof t=="object"&&!Hi?Ms(m):m}if(fv(t)){for(var y="<"+Ic.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Uc(J0(_[v].value),"double",n);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+Ic.call(String(t.nodeName))+">",y}if(Fa(t)){if(t.length===0)return"[]";var g=Rn(t,d);return c&&!mv(g)?"["+ka(g,c)+"]":"[ "+or.call(g,", ")+" ]"}if(ev(t)){var x=Rn(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Oc.call(t,"cause")?"{ ["+String(t)+"] "+or.call(Mc.call("[cause]: "+d(t.cause),x),", ")+" }":x.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+or.call(x,", ")+" }"}if(typeof t=="object"&&o){if(Bc&&typeof t[Bc]=="function"&&Ba)return Ba(t,{depth:u-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(lv(t)){var b=[];return Ac&&Ac.call(t,function(E,I){b.push(d(I,t,!0)+" => "+d(E,t))}),Vc("Map",Sn.call(t),b,c)}if(cv(t)){var S=[];return Sc&&Sc.call(t,function(E){S.push(d(E,t))}),Vc("Set",Cn.call(t),S,c)}if(hv(t))return Ua("WeakMap");if(dv(t))return Ua("WeakSet");if(uv(t))return Ua("WeakRef");if(iv(t))return Ms(d(Number(t)));if(nv(t))return Ms(d(Na.call(t)));if(sv(t))return Ms(W0.call(t));if(rv(t))return Ms(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Es<"u"&&t===Es)return"{ [object globalThis] }";if(!tv(t)&&!kc(t)){var w=Rn(t,d),T=Nc?Nc(t)===Object.prototype:t instanceof Object||t.constructor===Object,N=t instanceof Object?"":"null prototype",F=!T&&Rs&&Object(t)===t&&Rs in t?Oa.call(Br(t),8,-1):N?"Object":"",z=T||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",C=z+(F||N?"["+or.call(Mc.call([],F||[],N||[]),": ")+"] ":"");return w.length===0?C+"{}":c?C+"{"+ka(w,c)+"}":C+"{ "+or.call(w,", ")+" }"}return String(t)};function Uc(r,t,e){var i=e.quoteStyle||t,s=Fc[i];return s+r+s}function J0(r){return Lr.call(String(r),/"/g,"&quot;")}function ai(r){return!Rs||!(typeof r=="object"&&(Rs in r||typeof r[Rs]<"u"))}function Fa(r){return Br(r)==="[object Array]"&&ai(r)}function tv(r){return Br(r)==="[object Date]"&&ai(r)}function kc(r){return Br(r)==="[object RegExp]"&&ai(r)}function ev(r){return Br(r)==="[object Error]"&&ai(r)}function rv(r){return Br(r)==="[object String]"&&ai(r)}function iv(r){return Br(r)==="[object Number]"&&ai(r)}function sv(r){return Br(r)==="[object Boolean]"&&ai(r)}function Gc(r){if(Hi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!La)return!1;try{return La.call(r),!0}catch{}return!1}function nv(r){if(!r||typeof r!="object"||!Na)return!1;try{return Na.call(r),!0}catch{}return!1}var ov=Object.prototype.hasOwnProperty||function(r){return r in this};function Er(r,t){return ov.call(r,t)}function Br(r){return Y0.call(r)}function av(r){if(r.name)return r.name;var t=q0.call(j0.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function $c(r,t){if(r.indexOf)return r.indexOf(t);for(var e=0,i=r.length;e<i;e++)if(r[e]===t)return e;return-1}function lv(r){if(!Sn||!r||typeof r!="object")return!1;try{Sn.call(r);try{Cn.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function hv(r){if(!Cs||!r||typeof r!="object")return!1;try{Cs.call(r,Cs);try{Is.call(r,Is)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function uv(r){if(!Cc||!r||typeof r!="object")return!1;try{return Cc.call(r),!0}catch{}return!1}function cv(r){if(!Cn||!r||typeof r!="object")return!1;try{Cn.call(r);try{Sn.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function dv(r){if(!Is||!r||typeof r!="object")return!1;try{Is.call(r,Is);try{Cs.call(r,Cs)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function fv(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Hc(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Hc(Oa.call(r,0,t.maxStringLength),t)+i}var s=Q0[t.quoteStyle||"single"];s.lastIndex=0;var n=Lr.call(Lr.call(r,s,"\\$1"),/[\x00-\x1f]/g,pv);return Uc(n,"single",t)}function pv(r){var t=r.charCodeAt(0),e={8:"b",9:"t",10:"n",12:"f",13:"r"}[t];return e?"\\"+e:"\\x"+(t<16?"0":"")+K0.call(t.toString(16))}function Ms(r){return"Object("+r+")"}function Ua(r){return r+" { ? }"}function Vc(r,t,e,i){var s=i?ka(e,i):or.call(e,", ");return r+" ("+t+") {"+s+"}"}function mv(r){for(var t=0;t<r.length;t++)if($c(r[t],`
3
3
  `)>=0)return!1;return!0}function gv(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=or.call(Array(r.indent+1)," ");else return null;return{base:e,prev:or.call(Array(t+1),e)}}function ka(r,t){if(r.length===0)return"";var e=`
4
4
  `+t.prev+t.base;return e+or.call(r,","+e)+`
5
5
  `+t.prev}function Rn(r,t){var e=Fa(r),i=[];if(e){i.length=r.length;for(var s=0;s<r.length;s++)i[s]=Er(r,s)?t(r[s],r):""}var n=typeof Da=="function"?Da(r):[],o;if(Hi){o={};for(var a=0;a<n.length;a++)o["$"+n[a]]=n[a]}for(var l in r)Er(r,l)&&(e&&String(Number(l))===l&&l<r.length||Hi&&o["$"+l]instanceof Symbol||(Rc.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof Da=="function")for(var h=0;h<n.length;h++)Oc.call(r,n[h])&&i.push("["+t(n[h])+"]: "+t(r[n[h]],r));return i}var yv=In,_v=$i,Mn=function(r,t,e){for(var i=r,s;(s=i.next)!=null;i=s)if(s.key===t)return i.next=s.next,e||(s.next=r.next,r.next=s),s},vv=function(r,t){if(r){var e=Mn(r,t);return e&&e.value}},xv=function(r,t,e){var i=Mn(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},bv=function(r,t){return r?!!Mn(r,t):!1},Ev=function(r,t){if(r)return Mn(r,t,!0)},Tv=function(){var t,e={assert:function(i){if(!e.has(i))throw new _v("Side channel does not contain "+yv(i))},delete:function(i){var s=t&&t.next,n=Ev(t,i);return n&&s&&s===n&&(t=void 0),!!n},get:function(i){return vv(t,i)},has:function(i){return bv(t,i)},set:function(i,s){t||(t={next:void 0}),xv(t,i,s)}};return e},Xc=Object,wv=Error,Av=EvalError,Sv=RangeError,Cv=ReferenceError,Iv=SyntaxError,Rv=URIError,Mv=Math.abs,Pv=Math.floor,Ov=Math.max,Nv=Math.min,Dv=Math.pow,Lv=Math.round,Bv=Number.isNaN||function(t){return t!==t},Fv=Bv,Uv=function(t){return Fv(t)||t===0?t:t<0?-1:1},kv=Object.getOwnPropertyDescriptor,Pn=kv;if(Pn)try{Pn([],"length")}catch{Pn=null}var zc=Pn,On=Object.defineProperty||!1;if(On)try{On({},"a",{value:1})}catch{On=!1}var Gv=On,Ga,Wc;function $v(){return Wc||(Wc=1,Ga=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},e=Symbol("test"),i=Object(e);if(typeof e=="string"||Object.prototype.toString.call(e)!=="[object Symbol]"||Object.prototype.toString.call(i)!=="[object Symbol]")return!1;var s=42;t[e]=s;for(var n in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var o=Object.getOwnPropertySymbols(t);if(o.length!==1||o[0]!==e||!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var a=Object.getOwnPropertyDescriptor(t,e);if(a.value!==s||a.enumerable!==!0)return!1}return!0}),Ga}var $a,Yc;function Hv(){if(Yc)return $a;Yc=1;var r=typeof Symbol<"u"&&Symbol,t=$v();return $a=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},$a}var Ha,jc;function qc(){return jc||(jc=1,Ha=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),Ha}var Va,Kc;function Zc(){if(Kc)return Va;Kc=1;var r=Xc;return Va=r.getPrototypeOf||null,Va}var Vv="Function.prototype.bind called on incompatible ",Xv=Object.prototype.toString,zv=Math.max,Wv="[object Function]",Qc=function(t,e){for(var i=[],s=0;s<t.length;s+=1)i[s]=t[s];for(var n=0;n<e.length;n+=1)i[n+t.length]=e[n];return i},Yv=function(t,e){for(var i=[],s=e,n=0;s<t.length;s+=1,n+=1)i[n]=t[s];return i},jv=function(r,t){for(var e="",i=0;i<r.length;i+=1)e+=r[i],i+1<r.length&&(e+=t);return e},qv=function(t){var e=this;if(typeof e!="function"||Xv.apply(e)!==Wv)throw new TypeError(Vv+e);for(var i=Yv(arguments,1),s,n=function(){if(this instanceof s){var u=e.apply(this,Qc(i,arguments));return Object(u)===u?u:this}return e.apply(t,Qc(i,arguments))},o=zv(0,e.length-i.length),a=[],l=0;l<o;l++)a[l]="$"+l;if(s=Function("binder","return function ("+jv(a,",")+"){ return binder.apply(this,arguments); }")(n),e.prototype){var h=function(){};h.prototype=e.prototype,s.prototype=new h,h.prototype=null}return s},Kv=qv,Nn=Function.prototype.bind||Kv,Xa=Function.prototype.call,Jc=Function.prototype.apply,Zv=typeof Reflect<"u"&&Reflect&&Reflect.apply,Qv=Nn,Jv=Jc,t1=Xa,e1=Zv,r1=e1||Qv.call(t1,Jv),i1=Nn,s1=$i,n1=Xa,o1=r1,td=function(t){if(t.length<1||typeof t[0]!="function")throw new s1("a function is required");return o1(i1,n1,t)},za,ed;function a1(){if(ed)return za;ed=1;var r=td,t=zc,e;try{e=[].__proto__===Array.prototype}catch(o){if(!o||typeof o!="object"||!("code"in o)||o.code!=="ERR_PROTO_ACCESS")throw o}var i=!!e&&t&&t(Object.prototype,"__proto__"),s=Object,n=s.getPrototypeOf;return za=i&&typeof i.get=="function"?r([i.get]):typeof n=="function"?function(a){return n(a==null?a:s(a))}:!1,za}var Wa,rd;function l1(){if(rd)return Wa;rd=1;var r=qc(),t=Zc(),e=a1();return Wa=r?function(s){return r(s)}:t?function(s){if(!s||typeof s!="object"&&typeof s!="function")throw new TypeError("getProto: not an object");return t(s)}:e?function(s){return e(s)}:null,Wa}var Ya,id;function h1(){if(id)return Ya;id=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=Nn;return Ya=e.call(r,t),Ya}var yt,u1=Xc,c1=wv,d1=Av,f1=Sv,p1=Cv,Vi=Iv,Xi=$i,m1=Rv,g1=Mv,y1=Pv,_1=Ov,v1=Nv,x1=Dv,b1=Lv,E1=Uv,sd=Function,ja=function(r){try{return sd('"use strict"; return ('+r+").constructor;")()}catch{}},Ps=zc,T1=Gv,qa=function(){throw new Xi},w1=Ps?function(){try{return arguments.callee,qa}catch{try{return Ps(arguments,"callee").get}catch{return qa}}}():qa,zi=Hv()(),ie=l1(),A1=Zc(),S1=qc(),nd=Jc,Os=Xa,Wi={},C1=typeof Uint8Array>"u"||!ie?yt:ie(Uint8Array),li={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?yt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?yt:ArrayBuffer,"%ArrayIteratorPrototype%":zi&&ie?ie([][Symbol.iterator]()):yt,"%AsyncFromSyncIteratorPrototype%":yt,"%AsyncFunction%":Wi,"%AsyncGenerator%":Wi,"%AsyncGeneratorFunction%":Wi,"%AsyncIteratorPrototype%":Wi,"%Atomics%":typeof Atomics>"u"?yt:Atomics,"%BigInt%":typeof BigInt>"u"?yt:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?yt:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?yt:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?yt:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":c1,"%eval%":eval,"%EvalError%":d1,"%Float16Array%":typeof Float16Array>"u"?yt:Float16Array,"%Float32Array%":typeof Float32Array>"u"?yt:Float32Array,"%Float64Array%":typeof Float64Array>"u"?yt:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?yt:FinalizationRegistry,"%Function%":sd,"%GeneratorFunction%":Wi,"%Int8Array%":typeof Int8Array>"u"?yt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?yt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?yt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":zi&&ie?ie(ie([][Symbol.iterator]())):yt,"%JSON%":typeof JSON=="object"?JSON:yt,"%Map%":typeof Map>"u"?yt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!zi||!ie?yt:ie(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":u1,"%Object.getOwnPropertyDescriptor%":Ps,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?yt:Promise,"%Proxy%":typeof Proxy>"u"?yt:Proxy,"%RangeError%":f1,"%ReferenceError%":p1,"%Reflect%":typeof Reflect>"u"?yt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?yt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!zi||!ie?yt:ie(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?yt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":zi&&ie?ie(""[Symbol.iterator]()):yt,"%Symbol%":zi?Symbol:yt,"%SyntaxError%":Vi,"%ThrowTypeError%":w1,"%TypedArray%":C1,"%TypeError%":Xi,"%Uint8Array%":typeof Uint8Array>"u"?yt:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?yt:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?yt:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?yt:Uint32Array,"%URIError%":m1,"%WeakMap%":typeof WeakMap>"u"?yt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?yt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?yt:WeakSet,"%Function.prototype.call%":Os,"%Function.prototype.apply%":nd,"%Object.defineProperty%":T1,"%Object.getPrototypeOf%":A1,"%Math.abs%":g1,"%Math.floor%":y1,"%Math.max%":_1,"%Math.min%":v1,"%Math.pow%":x1,"%Math.round%":b1,"%Math.sign%":E1,"%Reflect.getPrototypeOf%":S1};if(ie)try{null.error}catch(r){var I1=ie(ie(r));li["%Error.prototype%"]=I1}var R1=function r(t){var e;if(t==="%AsyncFunction%")e=ja("async function () {}");else if(t==="%GeneratorFunction%")e=ja("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=ja("async function* () {}");else if(t==="%AsyncGenerator%"){var i=r("%AsyncGeneratorFunction%");i&&(e=i.prototype)}else if(t==="%AsyncIteratorPrototype%"){var s=r("%AsyncGenerator%");s&&ie&&(e=ie(s.prototype))}return li[t]=e,e},od={__proto__:null,"%ArrayBufferPrototype%":["ArrayBuffer","prototype"],"%ArrayPrototype%":["Array","prototype"],"%ArrayProto_entries%":["Array","prototype","entries"],"%ArrayProto_forEach%":["Array","prototype","forEach"],"%ArrayProto_keys%":["Array","prototype","keys"],"%ArrayProto_values%":["Array","prototype","values"],"%AsyncFunctionPrototype%":["AsyncFunction","prototype"],"%AsyncGenerator%":["AsyncGeneratorFunction","prototype"],"%AsyncGeneratorPrototype%":["AsyncGeneratorFunction","prototype","prototype"],"%BooleanPrototype%":["Boolean","prototype"],"%DataViewPrototype%":["DataView","prototype"],"%DatePrototype%":["Date","prototype"],"%ErrorPrototype%":["Error","prototype"],"%EvalErrorPrototype%":["EvalError","prototype"],"%Float32ArrayPrototype%":["Float32Array","prototype"],"%Float64ArrayPrototype%":["Float64Array","prototype"],"%FunctionPrototype%":["Function","prototype"],"%Generator%":["GeneratorFunction","prototype"],"%GeneratorPrototype%":["GeneratorFunction","prototype","prototype"],"%Int8ArrayPrototype%":["Int8Array","prototype"],"%Int16ArrayPrototype%":["Int16Array","prototype"],"%Int32ArrayPrototype%":["Int32Array","prototype"],"%JSONParse%":["JSON","parse"],"%JSONStringify%":["JSON","stringify"],"%MapPrototype%":["Map","prototype"],"%NumberPrototype%":["Number","prototype"],"%ObjectPrototype%":["Object","prototype"],"%ObjProto_toString%":["Object","prototype","toString"],"%ObjProto_valueOf%":["Object","prototype","valueOf"],"%PromisePrototype%":["Promise","prototype"],"%PromiseProto_then%":["Promise","prototype","then"],"%Promise_all%":["Promise","all"],"%Promise_reject%":["Promise","reject"],"%Promise_resolve%":["Promise","resolve"],"%RangeErrorPrototype%":["RangeError","prototype"],"%ReferenceErrorPrototype%":["ReferenceError","prototype"],"%RegExpPrototype%":["RegExp","prototype"],"%SetPrototype%":["Set","prototype"],"%SharedArrayBufferPrototype%":["SharedArrayBuffer","prototype"],"%StringPrototype%":["String","prototype"],"%SymbolPrototype%":["Symbol","prototype"],"%SyntaxErrorPrototype%":["SyntaxError","prototype"],"%TypedArrayPrototype%":["TypedArray","prototype"],"%TypeErrorPrototype%":["TypeError","prototype"],"%Uint8ArrayPrototype%":["Uint8Array","prototype"],"%Uint8ClampedArrayPrototype%":["Uint8ClampedArray","prototype"],"%Uint16ArrayPrototype%":["Uint16Array","prototype"],"%Uint32ArrayPrototype%":["Uint32Array","prototype"],"%URIErrorPrototype%":["URIError","prototype"],"%WeakMapPrototype%":["WeakMap","prototype"],"%WeakSetPrototype%":["WeakSet","prototype"]},Ns=Nn,Dn=h1(),M1=Ns.call(Os,Array.prototype.concat),P1=Ns.call(nd,Array.prototype.splice),ad=Ns.call(Os,String.prototype.replace),Ln=Ns.call(Os,String.prototype.slice),O1=Ns.call(Os,RegExp.prototype.exec),N1=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,D1=/\\(\\)?/g,L1=function(t){var e=Ln(t,0,1),i=Ln(t,-1);if(e==="%"&&i!=="%")throw new Vi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new Vi("invalid intrinsic syntax, expected opening `%`");var s=[];return ad(t,N1,function(n,o,a,l){s[s.length]=a?ad(l,D1,"$1"):o||n}),s},B1=function(t,e){var i=t,s;if(Dn(od,i)&&(s=od[i],i="%"+s[0]+"%"),Dn(li,i)){var n=li[i];if(n===Wi&&(n=R1(i)),typeof n>"u"&&!e)throw new Xi("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:s,name:i,value:n}}throw new Vi("intrinsic "+t+" does not exist!")},Ka=function(t,e){if(typeof t!="string"||t.length===0)throw new Xi("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new Xi('"allowMissing" argument must be a boolean');if(O1(/^%?[^%]*%?$/,t)===null)throw new Vi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=L1(t),s=i.length>0?i[0]:"",n=B1("%"+s+"%",e),o=n.name,a=n.value,l=!1,h=n.alias;h&&(s=h[0],P1(i,M1([0,1],h)));for(var u=1,c=!0;u<i.length;u+=1){var d=i[u],p=Ln(d,0,1),f=Ln(d,-1);if((p==='"'||p==="'"||p==="`"||f==='"'||f==="'"||f==="`")&&p!==f)throw new Vi("property names with quotes must have matching quotes");if((d==="constructor"||!c)&&(l=!0),s+="."+d,o="%"+s+"%",Dn(li,o))a=li[o];else if(a!=null){if(!(d in a)){if(!e)throw new Xi("base intrinsic for "+t+" exists, but the property is not available.");return}if(Ps&&u+1>=i.length){var m=Ps(a,d);c=!!m,c&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else c=Dn(a,d),a=a[d];c&&!l&&(li[o]=a)}}return a},ld=Ka,hd=td,F1=hd([ld("%String.prototype.indexOf%")]),ud=function(t,e){var i=ld(t,!!e);return typeof i=="function"&&F1(t,".prototype.")>-1?hd([i]):i},U1=Ka,Ds=ud,k1=In,G1=$i,cd=U1("%Map%",!0),$1=Ds("Map.prototype.get",!0),H1=Ds("Map.prototype.set",!0),V1=Ds("Map.prototype.has",!0),X1=Ds("Map.prototype.delete",!0),z1=Ds("Map.prototype.size",!0),dd=!!cd&&function(){var t,e={assert:function(i){if(!e.has(i))throw new G1("Side channel does not contain "+k1(i))},delete:function(i){if(t){var s=X1(t,i);return z1(t)===0&&(t=void 0),s}return!1},get:function(i){if(t)return $1(t,i)},has:function(i){return t?V1(t,i):!1},set:function(i,s){t||(t=new cd),H1(t,i,s)}};return e},W1=Ka,Bn=ud,Y1=In,Fn=dd,j1=$i,Yi=W1("%WeakMap%",!0),q1=Bn("WeakMap.prototype.get",!0),K1=Bn("WeakMap.prototype.set",!0),Z1=Bn("WeakMap.prototype.has",!0),Q1=Bn("WeakMap.prototype.delete",!0),J1=Yi?function(){var t,e,i={assert:function(s){if(!i.has(s))throw new j1("Side channel does not contain "+Y1(s))},delete:function(s){if(Yi&&s&&(typeof s=="object"||typeof s=="function")){if(t)return Q1(t,s)}else if(Fn&&e)return e.delete(s);return!1},get:function(s){return Yi&&s&&(typeof s=="object"||typeof s=="function")&&t?q1(t,s):e&&e.get(s)},has:function(s){return Yi&&s&&(typeof s=="object"||typeof s=="function")&&t?Z1(t,s):!!e&&e.has(s)},set:function(s,n){Yi&&s&&(typeof s=="object"||typeof s=="function")?(t||(t=new Yi),K1(t,s,n)):Fn&&(e||(e=Fn()),e.set(s,n))}};return i}:Fn,tx=$i,ex=In,rx=Tv,ix=dd,sx=J1,nx=sx||ix||rx,ox=function(){var t,e={assert:function(i){if(!e.has(i))throw new tx("Side channel does not contain "+ex(i))},delete:function(i){return!!t&&t.delete(i)},get:function(i){return t&&t.get(i)},has:function(i){return!!t&&t.has(i)},set:function(i,s){t||(t=nx()),t.set(i,s)}};return e},ax=String.prototype.replace,lx=/%20/g,Za={RFC1738:"RFC1738",RFC3986:"RFC3986"},Qa={default:Za.RFC3986,formatters:{RFC1738:function(r){return ax.call(r,lx,"+")},RFC3986:function(r){return String(r)}},RFC1738:Za.RFC1738,RFC3986:Za.RFC3986},hx=Qa,Ja=Object.prototype.hasOwnProperty,hi=Array.isArray,ar=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),ux=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(hi(i)){for(var s=[],n=0;n<i.length;++n)typeof i[n]<"u"&&s.push(i[n]);e.obj[e.prop]=s}}},fd=function(t,e){for(var i=e&&e.plainObjects?{__proto__:null}:{},s=0;s<t.length;++s)typeof t[s]<"u"&&(i[s]=t[s]);return i},cx=function r(t,e,i){if(!e)return t;if(typeof e!="object"&&typeof e!="function"){if(hi(t))t.push(e);else if(t&&typeof t=="object")(i&&(i.plainObjects||i.allowPrototypes)||!Ja.call(Object.prototype,e))&&(t[e]=!0);else return[t,e];return t}if(!t||typeof t!="object")return[t].concat(e);var s=t;return hi(t)&&!hi(e)&&(s=fd(t,i)),hi(t)&&hi(e)?(e.forEach(function(n,o){if(Ja.call(t,o)){var a=t[o];a&&typeof a=="object"&&n&&typeof n=="object"?t[o]=r(a,n,i):t.push(n)}else t[o]=n}),t):Object.keys(e).reduce(function(n,o){var a=e[o];return Ja.call(n,o)?n[o]=r(n[o],a,i):n[o]=a,n},s)},dx=function(t,e){return Object.keys(e).reduce(function(i,s){return i[s]=e[s],i},t)},fx=function(r,t,e){var i=r.replace(/\+/g," ");if(e==="iso-8859-1")return i.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(i)}catch{return i}},tl=1024,px=function(t,e,i,s,n){if(t.length===0)return t;var o=t;if(typeof t=="symbol"?o=Symbol.prototype.toString.call(t):typeof t!="string"&&(o=String(t)),i==="iso-8859-1")return escape(o).replace(/%u[0-9a-f]{4}/gi,function(p){return"%26%23"+parseInt(p.slice(2),16)+"%3B"});for(var a="",l=0;l<o.length;l+=tl){for(var h=o.length>=tl?o.slice(l,l+tl):o,u=[],c=0;c<h.length;++c){var d=h.charCodeAt(c);if(d===45||d===46||d===95||d===126||d>=48&&d<=57||d>=65&&d<=90||d>=97&&d<=122||n===hx.RFC1738&&(d===40||d===41)){u[u.length]=h.charAt(c);continue}if(d<128){u[u.length]=ar[d];continue}if(d<2048){u[u.length]=ar[192|d>>6]+ar[128|d&63];continue}if(d<55296||d>=57344){u[u.length]=ar[224|d>>12]+ar[128|d>>6&63]+ar[128|d&63];continue}c+=1,d=65536+((d&1023)<<10|h.charCodeAt(c)&1023),u[u.length]=ar[240|d>>18]+ar[128|d>>12&63]+ar[128|d>>6&63]+ar[128|d&63]}a+=u.join("")}return a},mx=function(t){for(var e=[{obj:{o:t},prop:"o"}],i=[],s=0;s<e.length;++s)for(var n=e[s],o=n.obj[n.prop],a=Object.keys(o),l=0;l<a.length;++l){var h=a[l],u=o[h];typeof u=="object"&&u!==null&&i.indexOf(u)===-1&&(e.push({obj:o,prop:h}),i.push(u))}return ux(e),t},gx=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},yx=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},_x=function(t,e){return[].concat(t,e)},vx=function(t,e){if(hi(t)){for(var i=[],s=0;s<t.length;s+=1)i.push(e(t[s]));return i}return e(t)},pd={arrayToObject:fd,assign:dx,combine:_x,compact:mx,decode:fx,encode:px,isBuffer:yx,isRegExp:gx,maybeMap:vx,merge:cx},md=ox,Un=pd,Ls=Qa,xx=Object.prototype.hasOwnProperty,gd={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},lr=Array.isArray,bx=Array.prototype.push,yd=function(r,t){bx.apply(r,lr(t)?t:[t])},Ex=Date.prototype.toISOString,_d=Ls.default,Jt={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Un.encode,encodeValuesOnly:!1,filter:void 0,format:_d,formatter:Ls.formatters[_d],indices:!1,serializeDate:function(t){return Ex.call(t)},skipNulls:!1,strictNullHandling:!1},Tx=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},el={},wx=function r(t,e,i,s,n,o,a,l,h,u,c,d,p,f,m,y,_,v){for(var g=t,x=v,b=0,S=!1;(x=x.get(el))!==void 0&&!S;){var w=x.get(t);if(b+=1,typeof w<"u"){if(w===b)throw new RangeError("Cyclic object value");S=!0}typeof x.get(el)>"u"&&(b=0)}if(typeof u=="function"?g=u(e,g):g instanceof Date?g=p(g):i==="comma"&&lr(g)&&(g=Un.maybeMap(g,function(M){return M instanceof Date?p(M):M})),g===null){if(o)return h&&!y?h(e,Jt.encoder,_,"key",f):e;g=""}if(Tx(g)||Un.isBuffer(g)){if(h){var T=y?e:h(e,Jt.encoder,_,"key",f);return[m(T)+"="+m(h(g,Jt.encoder,_,"value",f))]}return[m(e)+"="+m(String(g))]}var N=[];if(typeof g>"u")return N;var F;if(i==="comma"&&lr(g))y&&h&&(g=Un.maybeMap(g,h)),F=[{value:g.length>0?g.join(",")||null:void 0}];else if(lr(u))F=u;else{var z=Object.keys(g);F=c?z.sort(c):z}var C=l?String(e).replace(/\./g,"%2E"):String(e),E=s&&lr(g)&&g.length===1?C+"[]":C;if(n&&lr(g)&&g.length===0)return E+"[]";for(var I=0;I<F.length;++I){var P=F[I],$=typeof P=="object"&&P&&typeof P.value<"u"?P.value:g[P];if(!(a&&$===null)){var k=d&&l?String(P).replace(/\./g,"%2E"):String(P),G=lr(g)?typeof i=="function"?i(E,k):E:E+(d?"."+k:"["+k+"]");v.set(t,b);var st=md();st.set(el,v),yd(N,r($,G,i,s,n,o,a,l,i==="comma"&&y&&lr(g)?null:h,u,c,d,p,f,m,y,_,st))}}return N},Ax=function(t){if(!t)return Jt;if(typeof t.allowEmptyArrays<"u"&&typeof t.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof t.encodeDotInKeys<"u"&&typeof t.encodeDotInKeys!="boolean")throw new TypeError("`encodeDotInKeys` option can only be `true` or `false`, when provided");if(t.encoder!==null&&typeof t.encoder<"u"&&typeof t.encoder!="function")throw new TypeError("Encoder has to be a function.");var e=t.charset||Jt.charset;if(typeof t.charset<"u"&&t.charset!=="utf-8"&&t.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var i=Ls.default;if(typeof t.format<"u"){if(!xx.call(Ls.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var s=Ls.formatters[i],n=Jt.filter;(typeof t.filter=="function"||lr(t.filter))&&(n=t.filter);var o;if(t.arrayFormat in gd?o=t.arrayFormat:"indices"in t?o=t.indices?"indices":"repeat":o=Jt.arrayFormat,"commaRoundTrip"in t&&typeof t.commaRoundTrip!="boolean")throw new TypeError("`commaRoundTrip` must be a boolean, or absent");var a=typeof t.allowDots>"u"?t.encodeDotInKeys===!0?!0:Jt.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:Jt.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Jt.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Jt.charsetSentinel,commaRoundTrip:!!t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?Jt.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:Jt.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:Jt.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:Jt.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:Jt.encodeValuesOnly,filter:n,format:i,formatter:s,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:Jt.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:Jt.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Jt.strictNullHandling}},Sx=function(r,t){var e=r,i=Ax(t),s,n;typeof i.filter=="function"?(n=i.filter,e=n("",e)):lr(i.filter)&&(n=i.filter,s=n);var o=[];if(typeof e!="object"||e===null)return"";var a=gd[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;s||(s=Object.keys(e)),i.sort&&s.sort(i.sort);for(var h=md(),u=0;u<s.length;++u){var c=s[u],d=e[c];i.skipNulls&&d===null||yd(o,wx(d,c,a,l,i.allowEmptyArrays,i.strictNullHandling,i.skipNulls,i.encodeDotInKeys,i.encode?i.encoder:null,i.filter,i.sort,i.allowDots,i.serializeDate,i.format,i.formatter,i.encodeValuesOnly,i.charset,h))}var p=o.join(i.delimiter),f=i.addQueryPrefix===!0?"?":"";return i.charsetSentinel&&(i.charset==="iso-8859-1"?f+="utf8=%26%2310003%3B&":f+="utf8=%E2%9C%93&"),p.length>0?f+p:""},ui=pd,rl=Object.prototype.hasOwnProperty,vd=Array.isArray,kt={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:ui.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1,throwOnLimitExceeded:!1},Cx=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},xd=function(r,t,e){if(r&&typeof r=="string"&&t.comma&&r.indexOf(",")>-1)return r.split(",");if(t.throwOnLimitExceeded&&e>=t.arrayLimit)throw new RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(t.arrayLimit===1?"":"s")+" allowed in an array.");return r},Ix="utf8=%26%2310003%3B",Rx="utf8=%E2%9C%93",Mx=function(t,e){var i={__proto__:null},s=e.ignoreQueryPrefix?t.replace(/^\?/,""):t;s=s.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var n=e.parameterLimit===1/0?void 0:e.parameterLimit,o=s.split(e.delimiter,e.throwOnLimitExceeded?n+1:n);if(e.throwOnLimitExceeded&&o.length>n)throw new RangeError("Parameter limit exceeded. Only "+n+" parameter"+(n===1?"":"s")+" allowed.");var a=-1,l,h=e.charset;if(e.charsetSentinel)for(l=0;l<o.length;++l)o[l].indexOf("utf8=")===0&&(o[l]===Rx?h="utf-8":o[l]===Ix&&(h="iso-8859-1"),a=l,l=o.length);for(l=0;l<o.length;++l)if(l!==a){var u=o[l],c=u.indexOf("]="),d=c===-1?u.indexOf("="):c+1,p,f;d===-1?(p=e.decoder(u,kt.decoder,h,"key"),f=e.strictNullHandling?null:""):(p=e.decoder(u.slice(0,d),kt.decoder,h,"key"),f=ui.maybeMap(xd(u.slice(d+1),e,vd(i[p])?i[p].length:0),function(y){return e.decoder(y,kt.decoder,h,"value")})),f&&e.interpretNumericEntities&&h==="iso-8859-1"&&(f=Cx(String(f))),u.indexOf("[]=")>-1&&(f=vd(f)?[f]:f);var m=rl.call(i,p);m&&e.duplicates==="combine"?i[p]=ui.combine(i[p],f):(!m||e.duplicates==="last")&&(i[p]=f)}return i},Px=function(r,t,e,i){var s=0;if(r.length>0&&r[r.length-1]==="[]"){var n=r.slice(0,-1).join("");s=Array.isArray(t)&&t[n]?t[n].length:0}for(var o=i?t:xd(t,e,s),a=r.length-1;a>=0;--a){var l,h=r[a];if(h==="[]"&&e.parseArrays)l=e.allowEmptyArrays&&(o===""||e.strictNullHandling&&o===null)?[]:ui.combine([],o);else{l=e.plainObjects?{__proto__:null}:{};var u=h.charAt(0)==="["&&h.charAt(h.length-1)==="]"?h.slice(1,-1):h,c=e.decodeDotInKeys?u.replace(/%2E/g,"."):u,d=parseInt(c,10);!e.parseArrays&&c===""?l={0:o}:!isNaN(d)&&h!==c&&String(d)===c&&d>=0&&e.parseArrays&&d<=e.arrayLimit?(l=[],l[d]=o):c!=="__proto__"&&(l[c]=o)}o=l}return o},Ox=function(t,e,i,s){if(t){var n=i.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,l=i.depth>0&&o.exec(n),h=l?n.slice(0,l.index):n,u=[];if(h){if(!i.plainObjects&&rl.call(Object.prototype,h)&&!i.allowPrototypes)return;u.push(h)}for(var c=0;i.depth>0&&(l=a.exec(n))!==null&&c<i.depth;){if(c+=1,!i.plainObjects&&rl.call(Object.prototype,l[1].slice(1,-1))&&!i.allowPrototypes)return;u.push(l[1])}if(l){if(i.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+i.depth+" and strictDepth is true");u.push("["+n.slice(l.index)+"]")}return Px(u,e,i,s)}},Nx=function(t){if(!t)return kt;if(typeof t.allowEmptyArrays<"u"&&typeof t.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof t.decodeDotInKeys<"u"&&typeof t.decodeDotInKeys!="boolean")throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(t.decoder!==null&&typeof t.decoder<"u"&&typeof t.decoder!="function")throw new TypeError("Decoder has to be a function.");if(typeof t.charset<"u"&&t.charset!=="utf-8"&&t.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");if(typeof t.throwOnLimitExceeded<"u"&&typeof t.throwOnLimitExceeded!="boolean")throw new TypeError("`throwOnLimitExceeded` option must be a boolean");var e=typeof t.charset>"u"?kt.charset:t.charset,i=typeof t.duplicates>"u"?kt.duplicates:t.duplicates;if(i!=="combine"&&i!=="first"&&i!=="last")throw new TypeError("The duplicates option must be either combine, first, or last");var s=typeof t.allowDots>"u"?t.decodeDotInKeys===!0?!0:kt.allowDots:!!t.allowDots;return{allowDots:s,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:kt.allowEmptyArrays,allowPrototypes:typeof t.allowPrototypes=="boolean"?t.allowPrototypes:kt.allowPrototypes,allowSparse:typeof t.allowSparse=="boolean"?t.allowSparse:kt.allowSparse,arrayLimit:typeof t.arrayLimit=="number"?t.arrayLimit:kt.arrayLimit,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:kt.charsetSentinel,comma:typeof t.comma=="boolean"?t.comma:kt.comma,decodeDotInKeys:typeof t.decodeDotInKeys=="boolean"?t.decodeDotInKeys:kt.decodeDotInKeys,decoder:typeof t.decoder=="function"?t.decoder:kt.decoder,delimiter:typeof t.delimiter=="string"||ui.isRegExp(t.delimiter)?t.delimiter:kt.delimiter,depth:typeof t.depth=="number"||t.depth===!1?+t.depth:kt.depth,duplicates:i,ignoreQueryPrefix:t.ignoreQueryPrefix===!0,interpretNumericEntities:typeof t.interpretNumericEntities=="boolean"?t.interpretNumericEntities:kt.interpretNumericEntities,parameterLimit:typeof t.parameterLimit=="number"?t.parameterLimit:kt.parameterLimit,parseArrays:t.parseArrays!==!1,plainObjects:typeof t.plainObjects=="boolean"?t.plainObjects:kt.plainObjects,strictDepth:typeof t.strictDepth=="boolean"?!!t.strictDepth:kt.strictDepth,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:kt.strictNullHandling,throwOnLimitExceeded:typeof t.throwOnLimitExceeded=="boolean"?t.throwOnLimitExceeded:!1}},Dx=function(r,t){var e=Nx(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?Mx(r,e):r,s=e.plainObjects?{__proto__:null}:{},n=Object.keys(i),o=0;o<n.length;++o){var a=n[o],l=Ox(a,i[a],e,typeof r=="string");s=ui.merge(s,l,e)}return e.allowSparse===!0?s:ui.compact(s)},Lx=Sx,Bx=Dx,Fx=Qa,Ux={formats:Fx,parse:Bx,stringify:Lx},kx=$0;function Tr(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var Gx=/^([a-z0-9.+-]+:)/i,$x=/:[0-9]*$/,Hx=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,Vx=["<",">",'"',"`"," ","\r",`