@annotorious/openseadragon 3.1.3 → 3.1.4

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,4 +1,4 @@
1
- (function(Mt,Nt){typeof exports=="object"&&typeof module<"u"?Nt(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],Nt):(Mt=typeof globalThis<"u"?globalThis:Mt||self,Nt(Mt.AnnotoriousOSD={},Mt.OpenSeadragon))})(this,function(Mt,Nt){"use strict";var DT=Object.defineProperty;var OT=(Mt,Nt,Pr)=>Nt in Mt?DT(Mt,Nt,{enumerable:!0,configurable:!0,writable:!0,value:Pr}):Mt[Nt]=Pr;var Hl=(Mt,Nt,Pr)=>OT(Mt,typeof Nt!="symbol"?Nt+"":Nt,Pr);var Pr=Object.prototype.hasOwnProperty;function Mr(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--&&Mr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Pr.call(r,e)&&++i&&!Pr.call(t,e)||!(e in t)||!Mr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var ao=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(ao||{});const Ht=[];for(let r=0;r<256;++r)Ht.push((r+256).toString(16).slice(1));function mp(r,t=0){return(Ht[r[t+0]]+Ht[r[t+1]]+Ht[r[t+2]]+Ht[r[t+3]]+"-"+Ht[r[t+4]]+Ht[r[t+5]]+"-"+Ht[r[t+6]]+Ht[r[t+7]]+"-"+Ht[r[t+8]]+Ht[r[t+9]]+"-"+Ht[r[t+10]]+Ht[r[t+11]]+Ht[r[t+12]]+Ht[r[t+13]]+Ht[r[t+14]]+Ht[r[t+15]]).toLowerCase()}let lo;const gp=new Uint8Array(16);function yp(){if(!lo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");lo=crypto.getRandomValues.bind(crypto)}return lo(gp)}const _p=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Kl={randomUUID:_p};function vp(r,t,e){var i;if(Kl.randomUUID&&!r)return Kl.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??yp();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,mp(s)}const ho=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)}},xp=(r,t,e,i)=>({id:vp(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),bp=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},wp=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Ep=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Mr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Tp=(r,t)=>!Mr(r.target,t.target),Ap=(r,t)=>{const e=bp(r,t),i=wp(r,t),s=Ep(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:Tp(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var fr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(fr||{});const Sp=(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 Ap(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}};let Cp=()=>({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 Ip=250,Rp=(r,t)=>{const e=Cp(),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,_=performance.now();if(_-o>Ip)i.splice(s+1),i.push(m),s=i.length-1;else{const y=i.length-1;i[y]=Sp(i[y],m)}o=_}n=!1};r.observe(a,{origin:fr.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),h=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotation(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:_}=i[s+1];h(f),c(m),p(_),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:_}=i[s];l(f),u(m),d(_),e.emit("undo",i[s]),s-=1}}}},Pp=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},p=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},f=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(S=>e.serialize(S)):e.serialize(x),C=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,C)}else v(x,g)})},1)},m=()=>{const{selected:y}=n,x=(y||[]).map(({id:g})=>o.getAnnotation(g));x.forEach(g=>{const v=h.find(w=>w.id===g.id);(!v||!Mr(v,g))&&f("updateAnnotation",g,v)}),h=h.map(g=>x.find(({id:w})=>w===g.id)||g)};n.subscribe(({selected:y})=>{if(!(h.length===0&&y.length===0)){if(h.length===0&&y.length>0)h=y.map(({id:x})=>o.getAnnotation(x));else if(h.length>0&&y.length===0)h.forEach(x=>{const g=o.getAnnotation(x.id);g&&!Mr(g,x)&&f("updateAnnotation",g,x)}),h=[];else{const x=new Set(h.map(v=>v.id)),g=new Set(y.map(({id:v})=>v));h.filter(v=>!g.has(v.id)).forEach(v=>{const w=o.getAnnotation(v.id);w&&!Mr(w,v)&&f("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}f("selectionChanged",h)}}),s.subscribe(y=>{!u&&y?f("mouseEnterAnnotation",o.getAnnotation(y)):u&&!y?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&y&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(y))),u=y}),a==null||a.subscribe(y=>f("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>f("createAnnotation",v)),(g||[]).forEach(v=>f("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const C=h.find(S=>S.id===v.id)||v;h=h.map(S=>S.id===v.id?w:S),f("updateAnnotation",w,C)})},{origin:fr.LOCAL}),o.observe(y=>{if(h){const x=new Set(h.map(v=>v.id)),g=(y.changes.updated||[]).filter(({newValue:v})=>x.has(v.id)).map(({newValue:v})=>v);g.length>0&&(h=h.map(v=>g.find(C=>C.id===v.id)||v))}},{origin:fr.REMOTE});const _=y=>x=>{const{updated:g}=x;y?(g||[]).forEach(v=>f("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>f("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},Mp=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:[]}),Bp=(r,t,e)=>{const{store:i,selection:s}=r,n=y=>{if(e){const{parsed:x,error:g}=e.parse(y);x?i.addAnnotation(x,fr.REMOTE):console.error(g)}else i.addAnnotation(ho(y),fr.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=y=>{const x=i.getAnnotation(y);return e&&x?e.serialize(x):x},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var y;const x=(((y=s.selected)==null?void 0:y.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?x.map(e.serialize):x},c=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(p(g,x),g)),d=y=>{if(typeof y=="string"){const x=i.getAnnotation(y);if(i.deleteAnnotation(y),x)return e?e.serialize(x):x}else{const x=e?e.parse(y).parsed:y;if(x)return i.deleteAnnotation(x),y}},p=(y,x=!0)=>{if(e){const g=e.parseAll||Mp(e),{parsed:v,failed:w}=g(y);w.length>0&&console.warn(`Discarded ${w.length} invalid annotations`,w),i.bulkAddAnnotation(v,x,fr.REMOTE)}else i.bulkAddAnnotation(y.map(ho),x,fr.REMOTE)},f=(y,x)=>{y?s.setSelected(y,x):s.clear()},m=y=>{s.clear(),s.setUserSelectAction(y)},_=y=>{if(e){const x=e.parse(y).parsed,g=e.serialize(i.getAnnotation(x.id));return i.updateAnnotation(x),g}else{const x=i.getAnnotation(y.id);return i.updateAnnotation(ho(y)),x}};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:_}},Dp="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Op=r=>crypto.getRandomValues(new Uint8Array(r)),Lp=(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}}},Fp=(r,t=21)=>Lp(r,t|0,Op),Np=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Dp[e[r]&63];return t};const Up=()=>({isGuest:!0,id:Fp("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),kp=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Gp=()=>{const r=[...kp];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Np();var $p=Object.defineProperty,Hp=(r,t,e)=>t in r?$p(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Zl=(r,t,e)=>Hp(r,typeof t!="symbol"?t+"":t,e);function At(){}function uo(r,t){for(const e in t)r[e]=t[e];return r}function Jl(r){return r()}function Ql(){return Object.create(null)}function Pe(r){r.forEach(Jl)}function Ut(r){return typeof r=="function"}function qt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Xp(r){return Object.keys(r).length===0}function th(r,...t){if(r==null){for(const i of t)i(void 0);return At}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function co(r,t,e){r.$$.on_destroy.push(th(t,e))}function Vp(r,t,e,i){if(r){const s=eh(r,t,e,i);return r[0](s)}}function eh(r,t,e,i){return r[1]&&i?uo(e.ctx.slice(),r[1](i(t))):e.ctx}function zp(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 Wp(r,t,e,i,s,n){if(s){const o=eh(t,e,i,n);r.p(o,s)}}function jp(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 rh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Is(r){return r??""}function Me(r,t){r.appendChild(t)}function st(r,t,e){r.insertBefore(t,e||null)}function rt(r){r.parentNode&&r.parentNode.removeChild(r)}function fo(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function vt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ih(r){return document.createTextNode(r)}function ge(){return ih(" ")}function ye(){return ih("")}function Dt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function T(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Yp(r){return Array.from(r.childNodes)}function pr(r,t,e){r.classList.toggle(t,!!e)}function qp(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let $i;function Hi(r){$i=r}function sh(){if(!$i)throw new Error("Function called outside component initialization");return $i}function Xi(r){sh().$$.on_mount.push(r)}function Qr(){const r=sh();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=qp(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function Ze(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const ti=[],Rs=[];let ei=[];const nh=[],Kp=Promise.resolve();let po=!1;function Zp(){po||(po=!0,Kp.then(oh))}function mo(r){ei.push(r)}const go=new Set;let ri=0;function oh(){if(ri!==0)return;const r=$i;do{try{for(;ri<ti.length;){const t=ti[ri];ri++,Hi(t),Jp(t.$$)}}catch(t){throw ti.length=0,ri=0,t}for(Hi(null),ti.length=0,ri=0;Rs.length;)Rs.pop()();for(let t=0;t<ei.length;t+=1){const e=ei[t];go.has(e)||(go.add(e),e())}ei.length=0}while(ti.length);for(;nh.length;)nh.pop()();po=!1,go.clear(),Hi(r)}function Jp(r){if(r.fragment!==null){r.update(),Pe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(mo)}}function Qp(r){const t=[],e=[];ei.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),ei=t}const Ps=new Set;let Br;function _e(){Br={r:0,c:[],p:Br}}function ve(){Br.r||Pe(Br.c),Br=Br.p}function at(r,t){r&&r.i&&(Ps.delete(r),r.i(t))}function pt(r,t,e,i){if(r&&r.o){if(Ps.has(r))return;Ps.add(r),Br.c.push(()=>{Ps.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function ii(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function ue(r){r&&r.c()}function se(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),mo(()=>{const n=r.$$.on_mount.map(Jl).filter(Ut);r.$$.on_destroy?r.$$.on_destroy.push(...n):Pe(n),r.$$.on_mount=[]}),s.forEach(mo)}function ne(r,t){const e=r.$$;e.fragment!==null&&(Qp(e.after_update),Pe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function tm(r,t){r.$$.dirty[0]===-1&&(ti.push(r),Zp(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ce(r,t,e,i,s,n,o=null,a=[-1]){const l=$i;Hi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:At,not_equal:s,bound:Ql(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Ql(),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&&tm(r,c)),d}):[],h.update(),u=!0,Pe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=Yp(t.target);h.fragment&&h.fragment.l(c),c.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&at(r.$$.fragment),se(r,t.target,t.anchor),oh()}Hi(l)}class de{constructor(){Zl(this,"$$"),Zl(this,"$$set")}$destroy(){ne(this,1),this.$destroy=At}$on(t,e){if(!Ut(e))return At;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&&!Xp(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const em="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(em);var wt=(r=>(r.ELLIPSE="ELLIPSE",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(wt||{});const yo={},_o=(r,t)=>yo[r]=t,vo=r=>yo[r.type].area(r),rm=(r,t,e)=>yo[r.type].intersects(r,t,e),Ms=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}},im={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}};_o(wt.ELLIPSE,im);const sm={area:r=>{const{points:t}=r.geometry;let e=0,i=t.length-1;for(let s=0;s<t.length;s++)e+=(t[i][0]+t[s][0])*(t[i][1]-t[s][1]),i=s;return Math.abs(.5*e)},intersects:(r,t,e)=>{const{points:i}=r.geometry;let s=!1;for(let n=0,o=i.length-1;n<i.length;o=n++){const a=i[n][0],l=i[n][1],h=i[o][0],u=i[o][1];l>e!=u>e&&t<(h-a)*(e-l)/(u-l)+a&&(s=!s)}return s}};_o(wt.POLYGON,sm);const nm={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};_o(wt.RECTANGLE,nm);const Je=r=>Bs(r.target),Bs=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},om=(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:wt.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}}}},am=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}`}},ah="http://www.w3.org/2000/svg",lh=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},lm=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${ah}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},hm=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(ah),i=t.lookupNamespaceURI(null);return e||i?lh(t).firstChild:lh(lm(t)).firstChild},um=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],s=i.split(" ").map(n=>n.split(",").map(parseFloat));return{type:wt.POLYGON,geometry:{points:s,bounds:Ms(s)}}},cm=r=>{const t=hm(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:wt.ELLIPSE,geometry:{cx:e,cy:i,rx:s,ry:n,bounds:o}}},dm=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return um(t);if(t.includes("<ellipse "))return cm(t);throw"Unsupported SVG shape: "+t},fm=r=>{let t;if(r.type===wt.POLYGON){const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(s=>s.join(",")).join(" ")}" /></svg>`}else if(r.type===wt.ELLIPSE){const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},Xt=[];for(let r=0;r<256;++r)Xt.push((r+256).toString(16).slice(1));function pm(r,t=0){return(Xt[r[t+0]]+Xt[r[t+1]]+Xt[r[t+2]]+Xt[r[t+3]]+"-"+Xt[r[t+4]]+Xt[r[t+5]]+"-"+Xt[r[t+6]]+Xt[r[t+7]]+"-"+Xt[r[t+8]]+Xt[r[t+9]]+"-"+Xt[r[t+10]]+Xt[r[t+11]]+Xt[r[t+12]]+Xt[r[t+13]]+Xt[r[t+14]]+Xt[r[t+15]]).toLowerCase()}let xo;const mm=new Uint8Array(16);function gm(){if(!xo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");xo=crypto.getRandomValues.bind(crypto)}return xo(mm)}const ym=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),hh={randomUUID:ym};function uh(r,t,e){var i;if(hh.randomUUID&&!r)return hh.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??gm();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,pm(s)}var ch=Object.prototype.hasOwnProperty;function mr(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--&&mr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(ch.call(r,e)&&++i&&!ch.call(t,e)||!(e in t)||!mr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function bo(){}function _m(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const si=[];function wo(r,t=bo){let e;const i=new Set;function s(a){if(_m(r,a)&&(r=a,e)){const l=!si.length;for(const h of i)h[1](),si.push(h,r);if(l){for(let h=0;h<si.length;h+=2)si[h][0](si[h+1]);si.length=0}}}function n(a){s(a(r))}function o(a,l=bo){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||bo),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const vm=r=>{const{subscribe:t,set:e}=wo();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 dh=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(dh||{});const Ds={selected:[]},xm=(r,t,e)=>{const{subscribe:i,set:s}=wo(Ds);let n=t,o=Ds;i(f=>o=f);const a=()=>{mr(o,Ds)||s(Ds)},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(_=>_.id===m)},u=(f,m)=>{let _;if(Array.isArray(f)){if(_=f.map(x=>r.getAnnotation(x)).filter(Boolean),_.length<f.length){console.warn("Invalid selection: "+f.filter(x=>!_.some(g=>g.id===x)));return}}else{const x=r.getAnnotation(f);if(!x){console.warn("Invalid selection: "+f);return}_=[x]}const y=_.reduce((x,g)=>{const v=fh(g,n,e);return v==="EDIT"?[...x,{id:g.id,editable:!0}]:v==="SELECT"?[...x,{id:g.id}]:x},[]);s({selected:y,event:m})},c=(f,m)=>{const _=Array.isArray(f)?f:[f],y=_.map(x=>r.getAnnotation(x)).filter(x=>!!x);s({selected:y.map(x=>{const g=m===void 0?fh(x,n,e)==="EDIT":m;return{id:x.id,editable:g}})}),y.length!==_.length&&console.warn("Invalid selection",f)},d=f=>{if(l())return!1;const{selected:m}=o;m.some(({id:_})=>f.includes(_))&&s({selected:m.filter(({id:_})=>!f.includes(_))})},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}},fh=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},Vt=[];for(let r=0;r<256;++r)Vt.push((r+256).toString(16).slice(1));function bm(r,t=0){return(Vt[r[t+0]]+Vt[r[t+1]]+Vt[r[t+2]]+Vt[r[t+3]]+"-"+Vt[r[t+4]]+Vt[r[t+5]]+"-"+Vt[r[t+6]]+Vt[r[t+7]]+"-"+Vt[r[t+8]]+Vt[r[t+9]]+"-"+Vt[r[t+10]]+Vt[r[t+11]]+Vt[r[t+12]]+Vt[r[t+13]]+Vt[r[t+14]]+Vt[r[t+15]]).toLowerCase()}let Eo;const wm=new Uint8Array(16);function Em(){if(!Eo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Eo=crypto.getRandomValues.bind(crypto)}return Eo(wm)}const Tm=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ph={randomUUID:Tm};function Am(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))??Em();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,bm(s)}const To=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)}},Sm=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Cm=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Im=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!mr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Rm=(r,t)=>!mr(r.target,t.target),mh=(r,t)=>{const e=Sm(r,t),i=Cm(r,t),s=Im(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:Rm(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var St=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(St||{});const Pm=(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},Mm=(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 mh(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}},Ao=r=>{const t=r.id===void 0?Am():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Bm=r=>r.id!==void 0,Dm=()=>{const r=new Map,t=new Map,e=[],i=(R,D={})=>{e.push({onChange:R,options:D})},s=R=>{const D=e.findIndex(E=>E.onChange==R);D>-1&&e.splice(D,1)},n=(R,D)=>{const E={origin:R,changes:{created:D.created||[],updated:D.updated||[],deleted:D.deleted||[]},state:[...r.values()]};e.forEach(b=>{Pm(b,E)&&b.onChange(E)})},o=(R,D=St.LOCAL)=>{if(R.id&&r.get(R.id))throw Error(`Cannot add annotation ${R.id} - exists already`);{const E=Ao(R);r.set(E.id,E),E.bodies.forEach(b=>t.set(b.id,E.id)),n(D,{created:[E]})}},a=(R,D)=>{const E=Ao(typeof R=="string"?D:R),b=typeof R=="string"?R:R.id,M=b&&r.get(b);if(M){const N=mh(M,E);return b===E.id?r.set(b,E):(r.delete(b),r.set(E.id,E)),M.bodies.forEach($=>t.delete($.id)),E.bodies.forEach($=>t.set($.id,E.id)),N}else console.warn(`Cannot update annotation ${b} - does not exist`)},l=(R,D=St.LOCAL,E=St.LOCAL)=>{const b=Bm(D)?E:D,M=a(R,D);M&&n(b,{updated:[M]})},h=(R,D=St.LOCAL)=>{const E=R.reduce((b,M)=>{const N=a(M);return N?[...b,N]:b},[]);E.length>0&&n(D,{updated:E})},u=(R,D=St.LOCAL)=>{const E=r.get(R.annotation);if(E){const b={...E,bodies:[...E.bodies,R]};r.set(E.id,b),t.set(R.id,b.id),n(D,{updated:[{oldValue:E,newValue:b,bodiesCreated:[R]}]})}else console.warn(`Attempt to add body to missing annotation: ${R.annotation}`)},c=()=>[...r.values()],d=(R=St.LOCAL)=>{const D=[...r.values()];r.clear(),t.clear(),n(R,{deleted:D})},p=(R,D=!0,E=St.LOCAL)=>{const b=R.map(Ao);if(D){const M=[...r.values()];r.clear(),t.clear(),b.forEach(N=>{r.set(N.id,N),N.bodies.forEach($=>t.set($.id,N.id))}),n(E,{created:b,deleted:M})}else{const M=R.reduce((N,$)=>{const k=$.id&&r.get($.id);return k?[...N,k]:N},[]);if(M.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${M.map(N=>N.id).join(", ")}`);b.forEach(N=>{r.set(N.id,N),N.bodies.forEach($=>t.set($.id,N.id))}),n(E,{created:b})}},f=R=>{const D=typeof R=="string"?R:R.id,E=r.get(D);if(E)return r.delete(D),E.bodies.forEach(b=>t.delete(b.id)),E;console.warn(`Attempt to delete missing annotation: ${D}`)},m=(R,D=St.LOCAL)=>{const E=f(R);E&&n(D,{deleted:[E]})},_=(R,D=St.LOCAL)=>{const E=R.reduce((b,M)=>{const N=f(M);return N?[...b,N]:b},[]);E.length>0&&n(D,{deleted:E})},y=R=>{const D=r.get(R.annotation);if(D){const E=D.bodies.find(b=>b.id===R.id);if(E){t.delete(E.id);const b={...D,bodies:D.bodies.filter(M=>M.id!==R.id)};return r.set(D.id,b),{oldValue:D,newValue:b,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${R.id} from annotation ${R.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${R.annotation}`)},x=(R,D=St.LOCAL)=>{const E=y(R);E&&n(D,{updated:[E]})},g=(R,D=St.LOCAL)=>{const E=R.map(b=>y(b)).filter(Boolean);E.length>0&&n(D,{updated:E})},v=R=>{const D=r.get(R);return D?{...D}:void 0},w=R=>{const D=t.get(R);if(D){const E=v(D).bodies.find(b=>b.id===R);if(E)return E;console.error(`Store integrity error: body ${R} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${R}`)},C=(R,D)=>{if(R.annotation!==D.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(R.annotation);if(E){const b=E.bodies.find(N=>N.id===R.id),M={...E,bodies:E.bodies.map(N=>N.id===b.id?D:N)};return r.set(E.id,M),b.id!==D.id&&(t.delete(b.id),t.set(D.id,M.id)),{oldValue:E,newValue:M,bodiesUpdated:[{oldBody:b,newBody:D}]}}else console.warn(`Attempt to add body to missing annotation ${R.annotation}`)},S=(R,D,E=St.LOCAL)=>{const b=C(R,D);b&&n(E,{updated:[b]})},I=(R,D=St.LOCAL)=>{const E=R.map(b=>C({id:b.id,annotation:b.annotation},b)).filter(Boolean);n(D,{updated:E})},L=R=>{const D=r.get(R.annotation);if(D){const E={...D,target:{...D.target,...R}};return r.set(D.id,E),{oldValue:D,newValue:E,targetUpdated:{oldTarget:D.target,newTarget:R}}}else console.warn(`Attempt to update target on missing annotation: ${R.annotation}`)};return{addAnnotation:o,addBody:u,all:c,bulkAddAnnotation:p,bulkDeleteAnnotation:_,bulkDeleteBodies:g,bulkUpdateAnnotation:h,bulkUpdateBodies:I,bulkUpdateTargets:(R,D=St.LOCAL)=>{const E=R.map(b=>L(b)).filter(Boolean);E.length>0&&n(D,{updated:E})},clear:d,deleteAnnotation:m,deleteBody:x,getAnnotation:v,getBody:w,observe:i,unobserve:s,updateAnnotation:l,updateBody:S,updateTarget:(R,D=St.LOCAL)=>{const E=L(R);E&&n(D,{updated:[E]})}}},Om=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let Lm=()=>({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 Fm=250,Nm=(r,t)=>{const e=Lm(),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,_=performance.now();if(_-o>Fm)i.splice(s+1),i.push(m),s=i.length-1;else{const y=i.length-1;i[y]=Mm(i[y],m)}o=_}n=!1};r.observe(a,{origin:St.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),h=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotation(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:_}=i[s+1];h(f),c(m),p(_),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:_}=i[s];l(f),u(m),d(_),e.emit("undo",i[s]),s-=1}}}},Um=()=>{const{subscribe:r,set:t}=wo([]);return{subscribe:r,set:t}},km=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},p=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},f=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(S=>e.serialize(S)):e.serialize(x),C=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,C)}else v(x,g)})},1)},m=()=>{const{selected:y}=n,x=(y||[]).map(({id:g})=>o.getAnnotation(g));x.forEach(g=>{const v=h.find(w=>w.id===g.id);(!v||!mr(v,g))&&f("updateAnnotation",g,v)}),h=h.map(g=>x.find(({id:v})=>v===g.id)||g)};n.subscribe(({selected:y})=>{if(!(h.length===0&&y.length===0)){if(h.length===0&&y.length>0)h=y.map(({id:x})=>o.getAnnotation(x));else if(h.length>0&&y.length===0)h.forEach(x=>{const g=o.getAnnotation(x.id);g&&!mr(g,x)&&f("updateAnnotation",g,x)}),h=[];else{const x=new Set(h.map(v=>v.id)),g=new Set(y.map(({id:v})=>v));h.filter(v=>!g.has(v.id)).forEach(v=>{const w=o.getAnnotation(v.id);w&&!mr(w,v)&&f("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}f("selectionChanged",h)}}),s.subscribe(y=>{!u&&y?f("mouseEnterAnnotation",o.getAnnotation(y)):u&&!y?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&y&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(y))),u=y}),a==null||a.subscribe(y=>f("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>f("createAnnotation",v)),(g||[]).forEach(v=>f("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const C=h.find(S=>S.id===v.id)||v;h=h.map(S=>S.id===v.id?w:S),f("updateAnnotation",w,C)})},{origin:St.LOCAL}),o.observe(y=>{if(h){const x=new Set(h.map(v=>v.id)),g=(y.changes.updated||[]).filter(({newValue:v})=>x.has(v.id)).map(({newValue:v})=>v);g.length>0&&(h=h.map(v=>g.find(w=>w.id===v.id)||v))}},{origin:St.REMOTE});const _=y=>x=>{const{updated:g}=x;y?(g||[]).forEach(v=>f("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>f("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},Gm=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:[]}),$m=(r,t,e)=>{const{store:i,selection:s}=r,n=y=>{if(e){const{parsed:x,error:g}=e.parse(y);x?i.addAnnotation(x,St.REMOTE):console.error(g)}else i.addAnnotation(To(y),St.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=y=>{const x=i.getAnnotation(y);return e&&x?e.serialize(x):x},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var y;const x=(((y=s.selected)==null?void 0:y.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?x.map(e.serialize):x},c=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(p(g,x),g)),d=y=>{if(typeof y=="string"){const x=i.getAnnotation(y);if(i.deleteAnnotation(y),x)return e?e.serialize(x):x}else{const x=e?e.parse(y).parsed:y;if(x)return i.deleteAnnotation(x),y}},p=(y,x=!0)=>{if(e){const g=e.parseAll||Gm(e),{parsed:v,failed:w}=g(y);w.length>0&&console.warn(`Discarded ${w.length} invalid annotations`,w),i.bulkAddAnnotation(v,x,St.REMOTE)}else i.bulkAddAnnotation(y.map(To),x,St.REMOTE)},f=(y,x)=>{y?s.setSelected(y,x):s.clear()},m=y=>{s.clear(),s.setUserSelectAction(y)},_=y=>{if(e){const x=e.parse(y).parsed,g=e.serialize(i.getAnnotation(x.id));return i.updateAnnotation(x),g}else{const x=i.getAnnotation(y.id);return i.updateAnnotation(To(y)),x}};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:_}},Hm=(r,t,e)=>typeof t=="function"?t(r,e):t,Xm=(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||{}}},Vm="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let zm=r=>crypto.getRandomValues(new Uint8Array(r)),Wm=(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)=>Wm(r,t|0,zm),Ym=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Vm[e[r]&63];return t};const qm=()=>({isGuest:!0,id:jm("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Km=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}`},gh=r=>r?typeof r=="object"?{...r}:r:void 0,Zm=(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-${Km(e)}`,annotation:t,type:s,purpose:n,value:o,creator:gh(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),Jm=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});Ym();const Qm=(r,t={strict:!0,invertY:!1})=>({parse:e=>tg(e,t),serialize:e=>eg(e,r,t)}),tg=(r,t={strict:!0,invertY:!1})=>{const e=r.id||uh(),{creator:i,created:s,modified:n,body:o,...a}=r,l=Zm(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"?om(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?dm(u):void 0;return c||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:gh(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)}`)}},eg=(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==wt.RECTANGLE?am(i.geometry):fm(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:Jm(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 yh(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function _h(r){let t,e;return t=new Vi({props:{x:r[10][0],y:r[10][1],scale:r[3]}}),t.$on("pointerdown",function(){Ut(r[9](`HANDLE-${r[12]}`))&&r[9](`HANDLE-${r[12]}`).apply(this,arguments)}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function rg(r){let t,e,i,s,n,o,a,l,h,u,c,d=ii(r[4].points),p=[];for(let m=0;m<d.length;m+=1)p[m]=_h(yh(r,d,m));const f=m=>pt(p[m],1,1,()=>{p[m]=null});return{c(){t=vt("polygon"),s=ge(),n=vt("polygon"),a=ge();for(let m=0;m<p.length;m+=1)p[m].c();l=ye(),T(t,"class","a9s-outer"),T(t,"style",e=r[1]?"display:none;":void 0),T(t,"points",i=r[4].points.map(vh).join(" ")),T(n,"class","a9s-inner a9s-shape-handle"),T(n,"style",r[1]),T(n,"points",o=r[4].points.map(xh).join(" "))},m(m,_){st(m,t,_),st(m,s,_),st(m,n,_),st(m,a,_);for(let y=0;y<p.length;y+=1)p[y]&&p[y].m(m,_);st(m,l,_),h=!0,u||(c=[Dt(t,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Dt(n,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],u=!0)},p(m,_){if(r=m,(!h||_&2&&e!==(e=r[1]?"display:none;":void 0))&&T(t,"style",e),(!h||_&16&&i!==(i=r[4].points.map(vh).join(" ")))&&T(t,"points",i),(!h||_&2)&&T(n,"style",r[1]),(!h||_&16&&o!==(o=r[4].points.map(xh).join(" ")))&&T(n,"points",o),_&536){d=ii(r[4].points);let y;for(y=0;y<d.length;y+=1){const x=yh(r,d,y);p[y]?(p[y].p(x,_),at(p[y],1)):(p[y]=_h(x),p[y].c(),at(p[y],1),p[y].m(l.parentNode,l))}for(_e(),y=d.length;y<p.length;y+=1)f(y);ve()}},i(m){if(!h){for(let _=0;_<d.length;_+=1)at(p[_]);h=!0}},o(m){p=p.filter(Boolean);for(let _=0;_<p.length;_+=1)pt(p[_]);h=!1},d(m){m&&(rt(t),rt(s),rt(n),rt(a),rt(l)),fo(p,m),u=!1,Pe(c)}}}function ig(r){let t,e;return t=new Sh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[rg,({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(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}const vh=r=>r.join(","),xh=r=>r.join(",");function sg(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 _=d.geometry;p==="SHAPE"?m=_.points.map(([x,g])=>[x+f[0],g+f[1]]):m=_.points.map(([x,g],v)=>p===`HANDLE-${v}`?[x+f[0],g+f[1]]:[x,g]);const y=Ms(m);return{...d,geometry:{points:m,bounds:y}}};function h(d){Ze.call(this,r,d)}function u(d){Ze.call(this,r,d)}function c(d){Ze.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 ng extends de{constructor(t){super(),ce(this,t,sg,ig,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const So=(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))},ni=[];function og(r,t=At){let e;const i=new Set;function s(a){if(qt(r,a)&&(r=a,e)){const l=!ni.length;for(const h of i)h[1](),ni.push(h,r);if(l){for(let h=0;h<ni.length;h+=2)ni[h][0](ni[h+1]);ni.length=0}}}function n(a){s(a(r))}function o(a,l=At){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||At),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const ag=(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}`)},lg=(r,t)=>{ag(r,t);const{subscribe:e,set:i}=og(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}},bh=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function hg(r){let t,e,i,s,n,o;return{c(){t=vt("rect"),T(t,"class",e=Is(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),T(t,"x",i=r[0]-r[5]/2),T(t,"y",s=r[1]-r[5]/2),T(t,"width",r[5]),T(t,"height",r[5])},m(a,l){st(a,t,l),n||(o=Dt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=Is(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&T(t,"class",e),l&33&&i!==(i=a[0]-a[5]/2)&&T(t,"x",i),l&34&&s!==(s=a[1]-a[5]/2)&&T(t,"y",s),l&32&&T(t,"width",a[5]),l&32&&T(t,"height",a[5])},d(a){a&&rt(t),n=!1,o()}}}function ug(r){let t,e,i,s,n,o,a,l,h;return{c(){t=vt("g"),e=vt("circle"),s=vt("rect"),T(e,"cx",r[0]),T(e,"cy",r[1]),T(e,"r",i=r[3]/r[2]),T(e,"class","a9s-touch-halo svelte-1sgkh33"),pr(e,"touched",r[4]),T(s,"class",n=Is(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),T(s,"x",o=r[0]-r[5]/2),T(s,"y",a=r[1]-r[5]/2),T(s,"width",r[5]),T(s,"height",r[5]),T(t,"class","a9s-touch-handle")},m(u,c){st(u,t,c),Me(t,e),Me(t,s),l||(h=[Dt(e,"pointerdown",r[10]),Dt(e,"pointerdown",r[6]),Dt(e,"pointerup",r[7]),Dt(s,"pointerdown",r[9]),Dt(s,"pointerdown",r[6]),Dt(s,"pointerup",r[7])],l=!0)},p(u,c){c&1&&T(e,"cx",u[0]),c&2&&T(e,"cy",u[1]),c&12&&i!==(i=u[3]/u[2])&&T(e,"r",i),c&16&&pr(e,"touched",u[4]),c&256&&n!==(n=Is(`a9s-handle ${u[8].class||""}`.trim())+" svelte-1sgkh33")&&T(s,"class",n),c&33&&o!==(o=u[0]-u[5]/2)&&T(s,"x",o),c&34&&a!==(a=u[1]-u[5]/2)&&T(s,"y",a),c&32&&T(s,"width",u[5]),c&32&&T(s,"height",u[5])},d(u){u&&rt(t),l=!1,Pe(h)}}}function cg(r){let t;function e(s,n){return bh?ug:hg}let i=e()(r);return{c(){i.c(),t=ye()},m(s,n){i.m(s,n),st(s,t,n)},p(s,[n]){i.p(s,n)},i:At,o:At,d(s){s&&rt(t),i.d(s)}}}function dg(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){Ze.call(this,r,f)}function d(f){Ze.call(this,r,f)}function p(f){Ze.call(this,r,f)}return r.$$set=f=>{e(8,t=uo(uo({},t),rh(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=rh(t),[s,n,o,a,l,i,h,u,t,c,d,p]}class Vi extends de{constructor(t){super(),ce(this,t,dg,cg,qt,{x:0,y:1,scale:2,radius:3})}}function fg(r){let t,e,i,s,n,o,a,l,h,u,c,d,p,f,m,_,y,x,g,v,w,C,S,I,L,R,D,E,b,M,N,$,k,X,it,A,F,G,Q,Z,H,ft,bt;return X=new Vi({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),X.$on("pointerdown",function(){Ut(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),A=new Vi({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),A.$on("pointerdown",function(){Ut(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),G=new Vi({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),G.$on("pointerdown",function(){Ut(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Z=new Vi({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Z.$on("pointerdown",function(){Ut(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=vt("rect"),a=ge(),l=vt("rect"),p=ge(),f=vt("rect"),x=ge(),g=vt("rect"),S=ge(),I=vt("rect"),E=ge(),b=vt("rect"),k=ge(),ue(X.$$.fragment),it=ge(),ue(A.$$.fragment),F=ge(),ue(G.$$.fragment),Q=ge(),ue(Z.$$.fragment),T(t,"class","a9s-outer"),T(t,"style",e=r[1]?"display:none;":void 0),T(t,"x",i=r[4].x),T(t,"y",s=r[4].y),T(t,"width",n=r[4].w),T(t,"height",o=r[4].h),T(l,"class","a9s-inner a9s-shape-handle"),T(l,"style",r[1]),T(l,"x",h=r[4].x),T(l,"y",u=r[4].y),T(l,"width",c=r[4].w),T(l,"height",d=r[4].h),T(f,"class","a9s-edge-handle a9s-edge-handle-top"),T(f,"x",m=r[4].x),T(f,"y",_=r[4].y),T(f,"height",1),T(f,"width",y=r[4].w),T(g,"class","a9s-edge-handle a9s-edge-handle-right"),T(g,"x",v=r[4].x+r[4].w),T(g,"y",w=r[4].y),T(g,"height",C=r[4].h),T(g,"width",1),T(I,"class","a9s-edge-handle a9s-edge-handle-bottom"),T(I,"x",L=r[4].x),T(I,"y",R=r[4].y+r[4].h),T(I,"height",1),T(I,"width",D=r[4].w),T(b,"class","a9s-edge-handle a9s-edge-handle-left"),T(b,"x",M=r[4].x),T(b,"y",N=r[4].y),T(b,"height",$=r[4].h),T(b,"width",1)},m(B,O){st(B,t,O),st(B,a,O),st(B,l,O),st(B,p,O),st(B,f,O),st(B,x,O),st(B,g,O),st(B,S,O),st(B,I,O),st(B,E,O),st(B,b,O),st(B,k,O),se(X,B,O),st(B,it,O),se(A,B,O),st(B,F,O),se(G,B,O),st(B,Q,O),se(Z,B,O),H=!0,ft||(bt=[Dt(t,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Dt(l,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Dt(f,"pointerdown",function(){Ut(r[9]("TOP"))&&r[9]("TOP").apply(this,arguments)}),Dt(g,"pointerdown",function(){Ut(r[9]("RIGHT"))&&r[9]("RIGHT").apply(this,arguments)}),Dt(I,"pointerdown",function(){Ut(r[9]("BOTTOM"))&&r[9]("BOTTOM").apply(this,arguments)}),Dt(b,"pointerdown",function(){Ut(r[9]("LEFT"))&&r[9]("LEFT").apply(this,arguments)})],ft=!0)},p(B,O){r=B,(!H||O&2&&e!==(e=r[1]?"display:none;":void 0))&&T(t,"style",e),(!H||O&16&&i!==(i=r[4].x))&&T(t,"x",i),(!H||O&16&&s!==(s=r[4].y))&&T(t,"y",s),(!H||O&16&&n!==(n=r[4].w))&&T(t,"width",n),(!H||O&16&&o!==(o=r[4].h))&&T(t,"height",o),(!H||O&2)&&T(l,"style",r[1]),(!H||O&16&&h!==(h=r[4].x))&&T(l,"x",h),(!H||O&16&&u!==(u=r[4].y))&&T(l,"y",u),(!H||O&16&&c!==(c=r[4].w))&&T(l,"width",c),(!H||O&16&&d!==(d=r[4].h))&&T(l,"height",d),(!H||O&16&&m!==(m=r[4].x))&&T(f,"x",m),(!H||O&16&&_!==(_=r[4].y))&&T(f,"y",_),(!H||O&16&&y!==(y=r[4].w))&&T(f,"width",y),(!H||O&16&&v!==(v=r[4].x+r[4].w))&&T(g,"x",v),(!H||O&16&&w!==(w=r[4].y))&&T(g,"y",w),(!H||O&16&&C!==(C=r[4].h))&&T(g,"height",C),(!H||O&16&&L!==(L=r[4].x))&&T(I,"x",L),(!H||O&16&&R!==(R=r[4].y+r[4].h))&&T(I,"y",R),(!H||O&16&&D!==(D=r[4].w))&&T(I,"width",D),(!H||O&16&&M!==(M=r[4].x))&&T(b,"x",M),(!H||O&16&&N!==(N=r[4].y))&&T(b,"y",N),(!H||O&16&&$!==($=r[4].h))&&T(b,"height",$);const et={};O&16&&(et.x=r[4].x),O&16&&(et.y=r[4].y),O&8&&(et.scale=r[3]),X.$set(et);const tt={};O&16&&(tt.x=r[4].x+r[4].w),O&16&&(tt.y=r[4].y),O&8&&(tt.scale=r[3]),A.$set(tt);const yt={};O&16&&(yt.x=r[4].x+r[4].w),O&16&&(yt.y=r[4].y+r[4].h),O&8&&(yt.scale=r[3]),G.$set(yt);const _t={};O&16&&(_t.x=r[4].x),O&16&&(_t.y=r[4].y+r[4].h),O&8&&(_t.scale=r[3]),Z.$set(_t)},i(B){H||(at(X.$$.fragment,B),at(A.$$.fragment,B),at(G.$$.fragment,B),at(Z.$$.fragment,B),H=!0)},o(B){pt(X.$$.fragment,B),pt(A.$$.fragment,B),pt(G.$$.fragment,B),pt(Z.$$.fragment,B),H=!1},d(B){B&&(rt(t),rt(a),rt(l),rt(p),rt(f),rt(x),rt(g),rt(S),rt(I),rt(E),rt(b),rt(k),rt(it),rt(F),rt(Q)),ne(X,B),ne(A,B),ne(G,B),ne(Z,B),ft=!1,Pe(bt)}}}function pg(r){let t,e;return t=new Sh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[fg,({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(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function mg(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],[x,g]=[m.maxX,m.maxY];const[v,w]=f;if(p==="SHAPE")_+=v,x+=v,y+=w,g+=w;else{switch(p){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{y+=w;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=w;break}}switch(p){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{_+=v;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{x+=v;break}}}const C=Math.min(_,x),S=Math.min(y,g),I=Math.abs(x-_),L=Math.abs(g-y);return{...d,geometry:{x:C,y:S,w:I,h:L,bounds:{minX:C,minY:S,maxX:C+I,maxY:S+L}}}};function h(d){Ze.call(this,r,d)}function u(d){Ze.call(this,r,d)}function c(d){Ze.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 gg extends de{constructor(t){super(),ce(this,t,mg,pg,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const wh=new Map([[wt.RECTANGLE,gg],[wt.POLYGON,ng]]),Eh=r=>wh.get(r.type),Th=(r,t)=>wh.set(r,t),yg=r=>({}),Ah=r=>({grab:r[0]});function _g(r){let t,e,i,s;const n=r[7].default,o=Vp(n,r,r[6],Ah);return{c(){t=vt("g"),o&&o.c(),T(t,"class","a9s-annotation selected")},m(a,l){st(a,t,l),o&&o.m(t,null),e=!0,i||(s=[Dt(t,"pointerup",r[2]),Dt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&64)&&Wp(o,n,a,a[6],e?zp(n,a[6],l,yg):jp(a[6]),Ah)},i(a){e||(at(o,a),e=!0)},o(a){pt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,Pe(s)}}}function vg(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Qr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,u,c;const d=m=>_=>{h=m,u=l.elementToImage(_.offsetX,_.offsetY),c=o,_.target.setPointerCapture(_.pointerId),n("grab",_)},p=m=>{if(h){const[_,y]=l.elementToImage(m.offsetX,m.offsetY),x=[_-u[0],y-u[1]];e(3,o=a(c,h,x)),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 Sh extends de{constructor(t){super(),ce(this,t,vg,_g,qt,{shape:3,editor:4,transform:5})}}const Os=(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 xg(r,t,e){let i;const s=Qr();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:u}=t,c;return Xi(()=>(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=Os(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 bg extends de{constructor(t){super(),ce(this,t,xg,null,qt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function wg(r,t,e){const i=Qr();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return Xi(()=>{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 Eg extends de{constructor(t){super(),ce(this,t,wg,null,qt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Ch(r){let t,e;return{c(){t=vt("rect"),e=vt("rect"),T(t,"class","a9s-outer"),T(t,"x",r[1]),T(t,"y",r[2]),T(t,"width",r[3]),T(t,"height",r[4]),T(e,"class","a9s-inner"),T(e,"x",r[1]),T(e,"y",r[2]),T(e,"width",r[3]),T(e,"height",r[4])},m(i,s){st(i,t,s),st(i,e,s)},p(i,s){s&2&&T(t,"x",i[1]),s&4&&T(t,"y",i[2]),s&8&&T(t,"width",i[3]),s&16&&T(t,"height",i[4]),s&2&&T(e,"x",i[1]),s&4&&T(e,"y",i[2]),s&8&&T(e,"width",i[3]),s&16&&T(e,"height",i[4])},d(i){i&&(rt(t),rt(e))}}}function Tg(r){let t,e=r[0]&&Ch(r);return{c(){t=vt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){st(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=Ch(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&rt(t),e&&e.d()}}}function Ag(r,t,e){const i=Qr();let{addEventListener:s}=t,{drawingMode:n}=t,{transform:o}=t,a,l,h,u,c,d,p;const f=x=>{const g=x;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=x=>{const g=x;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])))},_=x=>{const g=x,v=performance.now()-a;if(n==="click"){if(v>300)return;l?y():(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&&(v>300||d*p>100?(g.stopPropagation(),y()):(e(0,l=void 0),h=void 0))},y=()=>{if(d*p>15){const x={type:wt.RECTANGLE,geometry:{bounds:{minX:u,minY:c,maxX:u+d,maxY:c+p},x:u,y:c,w:d,h:p}};i("create",x)}e(0,l=void 0),h=void 0};return Xi(()=>{s("pointerdown",f),s("pointermove",m),s("pointerup",_,!0)}),r.$$set=x=>{"addEventListener"in x&&e(5,s=x.addEventListener),"drawingMode"in x&&e(6,n=x.drawingMode),"transform"in x&&e(7,o=x.transform)},[l,u,c,d,p,s,n,o]}class Sg extends de{constructor(t){super(),ce(this,t,Ag,Tg,qt,{addEventListener:5,drawingMode:6,transform:7})}}function Co(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 Ih(r){let t,e,i,s,n,o=r[2]&&Rh(r);return{c(){t=vt("polygon"),i=vt("polygon"),o&&o.c(),n=ye(),T(t,"class","a9s-outer"),T(t,"points",e=r[16]),T(i,"class","a9s-inner"),T(i,"points",s=r[16])},m(a,l){st(a,t,l),st(a,i,l),o&&o.m(a,l),st(a,n,l)},p(a,l){l&7&&e!==(e=a[16])&&T(t,"points",e),l&7&&s!==(s=a[16])&&T(i,"points",s),a[2]?o?o.p(a,l):(o=Rh(a),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},d(a){a&&(rt(t),rt(i),rt(n)),o&&o.d(a)}}}function Rh(r){let t,e,i;return{c(){t=vt("rect"),T(t,"class","a9s-handle"),T(t,"x",e=r[0][0][0]-r[3]/2),T(t,"y",i=r[0][0][1]-r[3]/2),T(t,"height",r[3]),T(t,"width",r[3])},m(s,n){st(s,t,n)},p(s,n){n&9&&e!==(e=s[0][0][0]-s[3]/2)&&T(t,"x",e),n&9&&i!==(i=s[0][0][1]-s[3]/2)&&T(t,"y",i),n&8&&T(t,"height",s[3]),n&8&&T(t,"width",s[3])},d(s){s&&rt(t)}}}function Cg(r){let t,e=r[1]&&Ih(Co(r));return{c(){t=vt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){st(i,t,s),e&&e.m(t,null)},p(i,[s]){i[1]?e?e.p(Co(i),s):(e=Ih(Co(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&rt(t),e&&e.d()}}}const Ig=20,Rg=1500;function Pg(r,t,e){let i;const s=Qr();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,u=[],c,d,p=!1;const f=g=>{const v=g,{timeStamp:w,offsetX:C,offsetY:S}=v;if(h={timeStamp:w,offsetX:C,offsetY:S},o==="drag"&&u.length===0){const I=a.elementToImage(v.offsetX,v.offsetY);u.push(I),e(1,c=I)}},m=g=>{const v=g;if(d&&clearTimeout(d),u.length>0){if(e(1,c=a.elementToImage(v.offsetX,v.offsetY)),u.length>2){const w=So(c,u[0])*l;e(2,p=w<Ig)}v.pointerType==="touch"&&(d=setTimeout(()=>{y()},Rg))}},_=g=>{const v=g;if(d&&clearTimeout(d),o==="click"){const w=v.timeStamp-h.timeStamp,C=So([h.offsetX,h.offsetY],[v.offsetX,v.offsetY]);if(w>300||C>15)return;if(p)x();else if(u.length===0){const S=a.elementToImage(v.offsetX,v.offsetY);u.push(S),e(1,c=S)}else u.push(c)}else{if(u.length===1&&So(u[0],c)<=4){e(0,u=[]),e(1,c=void 0);return}v.stopImmediatePropagation(),p?x():u.push(c)}},y=()=>{if(!c)return;const g=[...u,c],v={type:wt.POLYGON,geometry:{bounds:Ms(g),points:g}};vo(v)>4&&(e(0,u=[]),e(1,c=void 0),s("create",v))},x=()=>{const g={type:wt.POLYGON,geometry:{bounds:Ms(u),points:[...u]}};e(0,u=[]),e(1,c=void 0),s("create",g)};return Xi(()=>{n("pointerdown",f,!0),n("pointermove",m),n("pointerup",_,!0),n("dblclick",y,!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 Mg extends de{constructor(t){super(),ce(this,t,Pg,Cg,qt,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const Io=new Map([["rectangle",{tool:Sg}],["polygon",{tool:Mg}]]),Ls=()=>[...Io.keys()],Fs=r=>Io.get(r),Ph=(r,t,e)=>Io.set(r,{tool:t,opts:e});function Bg(r){let t,e,i,s,n;return{c(){t=vt("g"),e=vt("ellipse"),s=vt("ellipse"),T(e,"class","a9s-outer"),T(e,"style",i=r[1]?"display:none;":void 0),T(e,"cx",r[2]),T(e,"cy",r[3]),T(e,"rx",r[4]),T(e,"ry",r[5]),T(s,"class","a9s-inner"),T(s,"style",r[1]),T(s,"cx",r[2]),T(s,"cy",r[3]),T(s,"rx",r[4]),T(s,"ry",r[5]),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){st(o,t,a),Me(t,e),Me(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&T(e,"style",i),a&2&&T(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&T(t,"data-id",n)},i:At,o:At,d(o){o&&rt(t)}}}function Dg(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=Os(s,o))},[s,i,a,l,h,u,n,o]}class Og extends de{constructor(t){super(),ce(this,t,Dg,Bg,qt,{annotation:0,geom:6,style:7})}}function Lg(r){let t,e,i,s,n;return{c(){t=vt("g"),e=vt("polygon"),s=vt("polygon"),T(e,"class","a9s-outer"),T(e,"style",i=r[1]?"display:none;":void 0),T(e,"points",r[2].map(Fg).join(" ")),T(s,"class","a9s-inner"),T(s,"style",r[1]),T(s,"points",r[2].map(Ng).join(" ")),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){st(o,t,a),Me(t,e),Me(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&T(e,"style",i),a&2&&T(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&T(t,"data-id",n)},i:At,o:At,d(o){o&&rt(t)}}}const Fg=r=>r.join(","),Ng=r=>r.join(",");function Ug(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=Os(s,o))},[s,i,a,n,o]}class kg extends de{constructor(t){super(),ce(this,t,Ug,Lg,qt,{annotation:0,geom:3,style:4})}}function Gg(r){let t,e,i,s,n;return{c(){t=vt("g"),e=vt("rect"),s=vt("rect"),T(e,"class","a9s-outer"),T(e,"style",i=r[5]?"display:none;":void 0),T(e,"x",r[4]),T(e,"y",r[3]),T(e,"width",r[2]),T(e,"height",r[1]),T(s,"class","a9s-inner"),T(s,"style",r[5]),T(s,"x",r[4]),T(s,"y",r[3]),T(s,"width",r[2]),T(s,"height",r[1]),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){st(o,t,a),Me(t,e),Me(t,s)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&T(e,"style",i),a&16&&T(e,"x",o[4]),a&8&&T(e,"y",o[3]),a&4&&T(e,"width",o[2]),a&2&&T(e,"height",o[1]),a&32&&T(s,"style",o[5]),a&16&&T(s,"x",o[4]),a&8&&T(s,"y",o[3]),a&4&&T(s,"width",o[2]),a&2&&T(s,"height",o[1]),a&1&&n!==(n=o[0].id)&&T(t,"data-id",n)},i:At,o:At,d(o){o&&rt(t)}}}function $g(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=Os(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 Hg extends de{constructor(t){super(),ce(this,t,$g,Gg,qt,{annotation:0,geom:6,style:7})}}const Xg=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]}}),Vg=250,zg=(r,t)=>{const e=Qr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<Vg){const{x:n,y:o}=Mh(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},Mh=(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 Bh(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 Dh(r,t,e){const i=r.slice();return i[43]=t[e],i}function Ro(r){const t=r.slice(),e=t[43].target.selector;return t[46]=e,t}function Oh(r){let t=r[43].id,e,i,s=Lh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&65536&&qt(t,t=n[43].id)?(_e(),pt(s,1,1,At),ve(),s=Lh(n),s.c(),at(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Wg(r){let t,e;return t=new kg({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function jg(r){let t,e;return t=new Hg({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Yg(r){var t;let e,i;return e=new Og({props:{annotation:r[43],geom:(t=r[46])==null?void 0:t.geometry,style:r[1]}}),{c(){ue(e.$$.fragment)},m(s,n){se(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||(at(e.$$.fragment,s),i=!0)},o(s){pt(e.$$.fragment,s),i=!1},d(s){ne(e,s)}}}function Lh(r){let t,e,i,s;const n=[Yg,jg,Wg],o=[];function a(l,h){var u,c,d;return((u=l[46])==null?void 0:u.type)===wt.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===wt.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===wt.POLYGON?2:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=ye()},m(l,h){~t&&o[t].m(l,h),st(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(_e(),pt(o[u],1,1,()=>{o[u]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(at(e),s=!0)},o(l){pt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Fh(r){let t=Je(r[43])&&!r[9](r[43]),e,i,s=t&&Oh(Ro(r));return{c(){s&&s.c(),e=ye()},m(n,o){s&&s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&66048&&(t=Je(n[43])&&!n[9](n[43])),t?s?(s.p(Ro(n),o),o[0]&66048&&at(s,1)):(s=Oh(Ro(n)),s.c(),at(s,1),s.m(e.parentNode,e)):s&&(_e(),pt(s,1,1,()=>{s=null}),ve())},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s&&s.d(n)}}}function Nh(r){let t,e,i,s;const n=[Kg,qg],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=ye()},m(l,h){~t&&o[t].m(l,h),st(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(_e(),pt(o[u],1,1,()=>{o[u]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(at(e),s=!0)},o(l){pt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function qg(r){let t=`${r[2]}-${r[5]}`,e,i,s=Uh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&36&&qt(t,t=`${n[2]}-${n[5]}`)?(_e(),pt(s,1,1,At),ve(),s=Uh(n),s.c(),at(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Kg(r){let t,e,i=ii(r[8]),s=[];for(let o=0;o<i.length;o+=1)s[o]=$h(Bh(r,i,o));const n=o=>pt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=ye()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);st(o,t,a),e=!0},p(o,a){if(a[0]&21107010){i=ii(o[8]);let l;for(l=0;l<i.length;l+=1){const h=Bh(o,i,l);s[l]?(s[l].p(h,a),at(s[l],1)):(s[l]=$h(h),s[l].c(),at(s[l],1),s[l].m(t.parentNode,t))}for(_e(),l=i.length;l<s.length;l+=1)n(l);ve()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)at(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)pt(s[a]);e=!1},d(o){o&&rt(t),fo(s,o)}}}function Uh(r){let t,e;return t=new Eg({props:{target:r[6],tool:r[14],drawingMode:r[13],transform:r[12],viewportScale:r[17]}}),t.$on("create",r[21]),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function kh(r){let t=r[39].id,e,i,s=Gh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&256&&qt(t,t=n[39].id)?(_e(),pt(s,1,1,At),ve(),s=Gh(n),s.c(),at(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Gh(r){let t,e;return t=new bg({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(){Ut(r[22](r[39]))&&r[22](r[39]).apply(this,arguments)}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function $h(r){let t,e,i=r[40]&&kh(r);return{c(){i&&i.c(),t=ye()},m(s,n){i&&i.m(s,n),st(s,t,n),e=!0},p(s,n){s[40]?i?(i.p(s,n),n[0]&256&&at(i,1)):(i=kh(s),i.c(),at(i,1),i.m(t.parentNode,t)):i&&(_e(),pt(i,1,1,()=>{i=null}),ve())},i(s){e||(at(i),e=!0)},o(s){pt(i),e=!1},d(s){s&&rt(t),i&&i.d(s)}}}function Zg(r){let t,e,i,s,n,o,a=ii(r[16].filter(r[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=Fh(Dh(r,a,c));const h=c=>pt(l[c],1,1,()=>{l[c]=null});let u=r[6]&&Nh(r);return{c(){t=vt("svg"),e=vt("g");for(let c=0;c<l.length;c+=1)l[c].c();i=vt("g"),u&&u.c(),T(i,"class","drawing"),T(t,"class","a9s-annotationlayer"),pr(t,"drawing",r[14]),pr(t,"hidden",!r[3]),pr(t,"hover",r[15])},m(c,d){st(c,t,d),Me(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);Me(t,i),u&&u.m(i,null),r[35](i),r[36](t),s=!0,n||(o=[Dt(t,"pointerup",function(){Ut(r[10])&&r[10].apply(this,arguments)}),Dt(t,"pointerdown",function(){Ut(r[11])&&r[11].apply(this,arguments)}),Dt(t,"pointermove",r[23])],n=!0)},p(c,d){if(r=c,d[0]&66050){a=ii(r[16].filter(r[34]));let p;for(p=0;p<a.length;p+=1){const f=Dh(r,a,p);l[p]?(l[p].p(f,d),at(l[p],1)):(l[p]=Fh(f),l[p].c(),at(l[p],1),l[p].m(e,null))}for(_e(),p=a.length;p<l.length;p+=1)h(p);ve()}r[6]?u?(u.p(r,d),d[0]&64&&at(u,1)):(u=Nh(r),u.c(),at(u,1),u.m(i,null)):u&&(_e(),pt(u,1,1,()=>{u=null}),ve()),(!s||d[0]&16384)&&pr(t,"drawing",r[14]),(!s||d[0]&8)&&pr(t,"hidden",!r[3]),(!s||d[0]&32768)&&pr(t,"hover",r[15])},i(c){if(!s){for(let d=0;d<a.length;d+=1)at(l[d]);at(u),s=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)pt(l[d]);pt(u),s=!1},d(c){c&&rt(t),fo(l,c),u&&u.d(),r[35](null),r[36](null),n=!1,Pe(o)}}}function Jg(r,t,e){let i,s,n,o,a,l,h,u,c,d,p,f=At,m=()=>(f(),f=th(M,B=>e(17,p=B)),M);r.$$.on_destroy.push(()=>f());let{drawingEnabled:_}=t,{image:y}=t,{preferredDrawingMode:x}=t,{state:g}=t,{style:v=void 0}=t,{toolName:w=Ls()[0]}=t,{user:C}=t,{visible:S=!0}=t,I=0;const L=()=>e(5,I+=1),R=()=>w,D=()=>_;let E,b,M;Xi(()=>m(e(7,M=lg(y,b))));const{hover:N,selection:$,store:k}=g;co(r,N,B=>e(15,u=B)),co(r,$,B=>e(33,c=B)),co(r,k,B=>e(16,d=B));let X,it;const A=B=>{X&&k.unobserve(X);const O=B.filter(({editable:et})=>et).map(({id:et})=>et);O.length>0?(e(8,it=O.map(et=>k.getAnnotation(et)).filter(et=>et&&Je(et))),X=et=>{const{updated:tt}=et.changes;e(8,it=tt==null?void 0:tt.map(yt=>yt.newValue))},k.observe(X,{annotations:O})):e(8,it=void 0)},F=B=>{const O=uh(),et={id:O,bodies:[],target:{annotation:O,selector:B.detail,creator:C,created:new Date}};k.addAnnotation(et),$.setSelected(et.id)},G=B=>O=>{var et;const{target:tt}=B,yt=10*60*1e3,_t=((et=tt.creator)==null?void 0:et.id)!==C.id||!tt.created||new Date().getTime()-tt.created.getTime()>yt;k.updateTarget({...tt,selector:O.detail,created:_t?tt.created:new Date,updated:_t?new Date:void 0,updatedBy:_t?C:void 0})},Q=B=>{const{x:O,y:et}=Mh(B,b),tt=k.getAt(O,et);tt?u!==tt.id&&N.set(tt.id):N.set(void 0)},Z=B=>Eh(B),H=B=>Je(B);function ft(B){Rs[B?"unshift":"push"](()=>{E=B,e(6,E)})}function bt(B){Rs[B?"unshift":"push"](()=>{b=B,e(4,b)})}return r.$$set=B=>{"drawingEnabled"in B&&e(0,_=B.drawingEnabled),"image"in B&&e(25,y=B.image),"preferredDrawingMode"in B&&e(26,x=B.preferredDrawingMode),"state"in B&&e(27,g=B.state),"style"in B&&e(1,v=B.style),"toolName"in B&&e(2,w=B.toolName),"user"in B&&e(28,C=B.user),"visible"in B&&e(3,S=B.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(14,{tool:i,opts:s}=Fs(w)||{tool:void 0,opts:void 0},i,(e(32,s),e(2,w))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(13,n=(s==null?void 0:s.drawingMode)||x),r.$$.dirty[0]&16&&e(12,o=Xg(b)),r.$$.dirty[0]&16&&e(11,{onPointerDown:a,onPointerUp:l}=zg(b,k),a,(e(10,l),e(4,b))),r.$$.dirty[1]&4&&e(9,h=B=>c.selected.find(O=>O.id===B.id&&O.editable)),r.$$.dirty[1]&4&&A(c.selected)},[_,v,w,S,b,I,E,M,it,h,l,a,o,n,i,u,d,p,N,$,k,F,G,Q,Z,y,x,g,C,L,R,D,s,c,H,ft,bt]}class Qg extends de{constructor(t){super(),ce(this,t,Jg,Zg,qt,{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 Hh(r,t,e=0,i=r.length-1,s=ty){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));Hh(r,t,p,f,s)}const n=r[t];let o=e,a=i;for(zi(r,e,t),s(r[i],n)>0&&zi(r,e,i);o<a;){for(zi(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?zi(r,e,a):(a++,zi(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function zi(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function ty(r,t){return r<t?-1:r>t?1:0}class ey{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(!Us(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;Us(t,l)&&(e.leaf?i.push(a):Mo(t,l)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!Us(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(Us(t,o)){if(e.leaf||Mo(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=ai([]),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=ry(t,i.children,e);if(u!==-1)return i.children.splice(u,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&Mo(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=ai(t.slice(e,i+1)),oi(a,this.toBBox),a;s||(s=Math.ceil(Math.log(n)/Math.log(o)),o=Math.ceil(n/Math.pow(o,s-1))),a=ai([]),a.leaf=!1,a.height=s;const l=Math.ceil(n/o),h=l*Math.ceil(Math.sqrt(o));Xh(t,e,i,h,this.compareMinX);for(let u=e;u<=i;u+=h){const c=Math.min(u+h-1,i);Xh(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 oi(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=Po(h),c=ny(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),ji(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=ai(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,oi(i,this.toBBox),oi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=ai([t,e]),this.data.height=t.height+1,this.data.leaf=!1,oi(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=Wi(t,0,a,this.toBBox),h=Wi(t,a,i,this.toBBox),u=oy(l,h),c=Po(l)+Po(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:iy,n=t.leaf?this.compareMinY:sy,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=Wi(t,0,e,n),a=Wi(t,i-e,i,n);let l=Ns(o)+Ns(a);for(let h=e;h<i-e;h++){const u=t.children[h];ji(o,t.leaf?n(u):u),l+=Ns(o)}for(let h=i-e-1;h>=e;h--){const u=t.children[h];ji(a,t.leaf?n(u):u),l+=Ns(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)ji(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():oi(t[e],this.toBBox)}}function ry(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 oi(r,t){Wi(r,0,r.children.length,t,r)}function Wi(r,t,e,i,s){s||(s=ai(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];ji(s,r.leaf?i(o):o)}return s}function ji(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 iy(r,t){return r.minX-t.minX}function sy(r,t){return r.minY-t.minY}function Po(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Ns(r){return r.maxX-r.minX+(r.maxY-r.minY)}function ny(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 oy(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 Mo(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function Us(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function ai(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Xh(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;Hh(r,o,t,e,s),n.push(t,o,o,e)}}const ay=()=>{const r=new ey,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},s=o=>{if(!Bs(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(!Bs(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===wt.RECTANGLE||rm(h.selector,o,a));if(l.length>0)return l.sort((h,u)=>vo(h.selector)-vo(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(Bs(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)}}},Vh=r=>{const t=Dm(),e=ay(),i=xm(t,r.userSelectAction,r.adapter),s=vm(t),n=Um();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}},ly=r=>{const t=Vh(r);return{...t,store:Om(t.store)}},hy=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},zh=r=>{const t=hy(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},Wh=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?zh(r):e),jh=(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}),Yh=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,qh=(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=()=>{Yh?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Yh?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},uy=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=jh(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:dh.EDIT,theme:"light"}),s=ly(i),{selection:n,store:o}=s,a=Nm(o,i.initialHistory),l=km(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=qh(a);let c=qm();Wh(e,h,i.theme);const d=new Qg({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:c}});d.$on("click",E=>{const{originalEvent:b,annotation:M}=E.detail;M?n.userSelect(M.id,b):n.isEmpty()||n.clear()});const p=$m(s,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),u.destroy(),a.destroy()},_=()=>d.getDrawingTool(),y=()=>c,x=()=>d.isDrawingEnabled(),g=(E,b,M)=>Ph(E,b,M),v=(E,b)=>Th(E,b),w=E=>{if(!Fs(E))throw`No drawing tool named ${E}`;d.$set({toolName:E})},C=E=>d.$set({drawingEnabled:E}),S=E=>{console.warn("Filter not implemented yet")},I=E=>d.$set({style:E}),L=E=>Wh(e,h,E),R=E=>{c=E,d.$set({user:E})},D=E=>d.$set({visible:E});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:_,getUser:y,isDrawingEnabled:x,listDrawingTools:Ls,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:v,setDrawingEnabled:C,setDrawingTool:w,setFilter:S,setStyle:I,setTheme:L,setUser:R,setVisible:D,element:h,state:s}};function Be(){}function Bo(r,t){for(const e in t)r[e]=t[e];return r}function Kh(r){return r()}function Zh(){return Object.create(null)}function Qe(r){r.forEach(Kh)}function Kt(r){return typeof r=="function"}function te(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function cy(r){return Object.keys(r).length===0}function dy(r,...t){if(r==null){for(const i of t)i(void 0);return Be}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Do(r,t,e){r.$$.on_destroy.push(dy(t,e))}function Jh(r,t,e,i){if(r){const s=Qh(r,t,e,i);return r[0](s)}}function Qh(r,t,e,i){return r[1]&&i?Bo(e.ctx.slice(),r[1](i(t))):e.ctx}function tu(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 eu(r,t,e,i,s,n){if(s){const o=Qh(t,e,i,n);r.p(o,s)}}function ru(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 iu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ks(r){return r??""}const fy=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function tr(r,t){r.appendChild(t)}function dt(r,t,e){r.insertBefore(t,e||null)}function ht(r){r.parentNode&&r.parentNode.removeChild(r)}function Oo(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function Tt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Lo(r){return document.createTextNode(r)}function xe(){return Lo(" ")}function er(){return Lo("")}function zt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function P(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function py(r){return Array.from(r.childNodes)}function my(r,t){t=""+t,r.data!==t&&(r.data=t)}function Gs(r,t,e){r.classList.toggle(t,!!e)}function gy(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Yi;function qi(r){Yi=r}function Fo(){if(!Yi)throw new Error("Function called outside component initialization");return Yi}function $s(r){Fo().$$.on_mount.push(r)}function yy(r){Fo().$$.on_destroy.push(r)}function Hs(){const r=Fo();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=gy(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function rr(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const li=[],Xs=[];let hi=[];const su=[],_y=Promise.resolve();let No=!1;function vy(){No||(No=!0,_y.then(nu))}function Uo(r){hi.push(r)}const ko=new Set;let ui=0;function nu(){if(ui!==0)return;const r=Yi;do{try{for(;ui<li.length;){const t=li[ui];ui++,qi(t),xy(t.$$)}}catch(t){throw li.length=0,ui=0,t}for(qi(null),li.length=0,ui=0;Xs.length;)Xs.pop()();for(let t=0;t<hi.length;t+=1){const e=hi[t];ko.has(e)||(ko.add(e),e())}hi.length=0}while(li.length);for(;su.length;)su.pop()();No=!1,ko.clear(),qi(r)}function xy(r){if(r.fragment!==null){r.update(),Qe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Uo)}}function by(r){const t=[],e=[];hi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),hi=t}const Vs=new Set;let Dr;function De(){Dr={r:0,c:[],p:Dr}}function Oe(){Dr.r||Qe(Dr.c),Dr=Dr.p}function nt(r,t){r&&r.i&&(Vs.delete(r),r.i(t))}function ut(r,t,e,i){if(r&&r.o){if(Vs.has(r))return;Vs.add(r),Dr.c.push(()=>{Vs.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function ci(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function ee(r){r&&r.c()}function Zt(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),Uo(()=>{const n=r.$$.on_mount.map(Kh).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...n):Qe(n),r.$$.on_mount=[]}),s.forEach(Uo)}function Jt(r,t){const e=r.$$;e.fragment!==null&&(by(e.after_update),Qe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function wy(r,t){r.$$.dirty[0]===-1&&(li.push(r),vy(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function oe(r,t,e,i,s,n,o=null,a=[-1]){const l=Yi;qi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Be,not_equal:s,bound:Zh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Zh(),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&&wy(r,c)),d}):[],h.update(),u=!0,Qe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=py(t.target);h.fragment&&h.fragment.l(c),c.forEach(ht)}else h.fragment&&h.fragment.c();t.intro&&nt(r.$$.fragment),Zt(r,t.target,t.anchor),nu()}qi(l)}class ae{constructor(){Hl(this,"$$");Hl(this,"$$set")}$destroy(){Jt(this,1),this.$destroy=Be}$on(t,e){if(!Kt(e))return Be;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&&!cy(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Ey="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ey);var Or=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(Or||{}),ou=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(ou||{}),Go=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Go||{}),J=(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))(J||{}),Le=(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))(Le||{}),U=(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))(U||{}),di=(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))(di||{}),K=(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))(K||{}),z=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(z||{}),ir=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(ir||{}),gr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(gr||{}),Fe=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(Fe||{}),ie=(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))(ie||{}),Ne=(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))(Ne||{}),$o=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))($o||{}),fe=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(fe||{}),Lt=(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))(Lt||{}),Ot=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(Ot||{}),Ue=(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))(Ue||{});const W={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 Ho=/iPhone/i,au=/iPod/i,lu=/iPad/i,hu=/\biOS-universal(?:.+)Mac\b/i,Xo=/\bAndroid(?:.+)Mobile\b/i,uu=/Android/i,fi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,zs=/Silk/i,sr=/Windows Phone/i,cu=/\bWindows(?:.+)ARM\b/i,du=/BlackBerry/i,fu=/BB10/i,pu=/Opera Mini/i,mu=/\b(CriOS|Chrome)(?:.+)Mobile/i,gu=/Mobile(?:.+)Firefox\b/i,yu=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Ty(r){return function(t){return t.test(r)}}function _u(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=Ty(e),n={apple:{phone:s(Ho)&&!s(sr),ipod:s(au),tablet:!s(Ho)&&(s(lu)||yu(t))&&!s(sr),universal:s(hu),device:(s(Ho)||s(au)||s(lu)||s(hu)||yu(t))&&!s(sr)},amazon:{phone:s(fi),tablet:!s(fi)&&s(zs),device:s(fi)||s(zs)},android:{phone:!s(sr)&&s(fi)||!s(sr)&&s(Xo),tablet:!s(sr)&&!s(fi)&&!s(Xo)&&(s(zs)||s(uu)),device:!s(sr)&&(s(fi)||s(zs)||s(Xo)||s(uu))||s(/\bokhttp\b/i)},windows:{phone:s(sr),tablet:s(cu),device:s(sr)||s(cu)},other:{blackberry:s(du),blackberry10:s(fu),opera:s(pu),firefox:s(gu),chrome:s(mu),device:s(du)||s(fu)||s(pu)||s(gu)||s(mu)},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 Ay=_u.default??_u,nr=Ay(globalThis.navigator);W.RETINA_PREFIX=/@([0-9\.]+)x/,W.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Ki=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vu(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Sy(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 xu={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 _=this._events[m],y=arguments.length,x,g;if(_.fn){switch(_.once&&this.removeListener(h,_.fn,void 0,!0),y){case 1:return _.fn.call(_.context),!0;case 2:return _.fn.call(_.context,u),!0;case 3:return _.fn.call(_.context,u,c),!0;case 4:return _.fn.call(_.context,u,c,d),!0;case 5:return _.fn.call(_.context,u,c,d,p),!0;case 6:return _.fn.call(_.context,u,c,d,p,f),!0}for(g=1,x=new Array(y-1);g<y;g++)x[g-1]=arguments[g];_.fn.apply(_.context,x)}else{var v=_.length,w;for(g=0;g<v;g++)switch(_[g].once&&this.removeListener(h,_[g].fn,void 0,!0),y){case 1:_[g].fn.call(_[g].context);break;case 2:_[g].fn.call(_[g].context,u);break;case 3:_[g].fn.call(_[g].context,u,c);break;case 4:_[g].fn.call(_[g].context,u,c,d);break;default:if(!x)for(w=1,x=new Array(y-1);w<y;w++)x[w-1]=arguments[w];_[g].fn.apply(_[g].context,x)}}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<y;m++)(f[m].fn!==u||d&&!f[m].once||c&&f[m].context!==c)&&_.push(f[m]);_.length?this._events[p]=_.length===1?_[0]:_: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})(xu);var Cy=xu.exports;const Zi=vu(Cy);var Vo={exports:{}};Vo.exports=Ws,Vo.exports.default=Ws;function Ws(r,t,e){e=e||2;var i=t&&t.length,s=i?t[0]*e:r.length,n=bu(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=By(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 Ji(n,o,e,a,l,p,0),o}function bu(r,t,e,i,s){var n,o;if(s===jo(r,t,e,i)>0)for(n=t;n<e;n+=i)o=Tu(n,r[n],r[n+1],o);else for(n=e-i;n>=t;n-=i)o=Tu(n,r[n],r[n+1],o);return o&&js(o,o.next)&&(ts(o),o=o.next),o}function Lr(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(js(e,e.next)||Ct(e.prev,e,e.next)===0)){if(ts(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Ji(r,t,e,i,s,n,o){if(r){!o&&n&&Ny(r,i,s,n);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,n?Ry(r,i,s,n):Iy(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),ts(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=Py(Lr(r),t,e),Ji(r,t,e,i,s,n,2)):o===2&&My(r,t,e,i,s,n):Ji(Lr(r),t,e,i,s,n,1);break}}}}function Iy(r){var t=r.prev,e=r,i=r.next;if(Ct(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&&pi(s,a,n,l,o,h,f.x,f.y)&&Ct(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Ry(r,t,e,i){var s=r.prev,n=r,o=r.next;if(Ct(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,_=u>c?u>d?u:d:c>d?c:d,y=zo(p,f,t,e,i),x=zo(m,_,t,e,i),g=r.prevZ,v=r.nextZ;g&&g.z>=y&&v&&v.z<=x;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==s&&g!==o&&pi(a,u,l,c,h,d,g.x,g.y)&&Ct(g.prev,g,g.next)>=0||(g=g.prevZ,v.x>=p&&v.x<=m&&v.y>=f&&v.y<=_&&v!==s&&v!==o&&pi(a,u,l,c,h,d,v.x,v.y)&&Ct(v.prev,v,v.next)>=0))return!1;v=v.nextZ}for(;g&&g.z>=y;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==s&&g!==o&&pi(a,u,l,c,h,d,g.x,g.y)&&Ct(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=m&&v.y>=f&&v.y<=_&&v!==s&&v!==o&&pi(a,u,l,c,h,d,v.x,v.y)&&Ct(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function Py(r,t,e){var i=r;do{var s=i.prev,n=i.next.next;!js(s,n)&&wu(s,i,i.next,n)&&Qi(s,n)&&Qi(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),ts(i),ts(i.next),i=r=n),i=i.next}while(i!==r);return Lr(i)}function My(r,t,e,i,s,n){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&Gy(o,a)){var l=Eu(o,a);o=Lr(o,o.next),l=Lr(l,l.next),Ji(o,t,e,i,s,n,0),Ji(l,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function By(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=bu(r,a,l,i,!1),h===h.next&&(h.steiner=!0),s.push(ky(h));for(s.sort(Dy),n=0;n<s.length;n++)e=Oy(s[n],e);return e}function Dy(r,t){return r.x-t.x}function Oy(r,t){var e=Ly(r,t);if(!e)return t;var i=Eu(e,r);return Lr(i,i.next),Lr(e,e.next)}function Ly(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&&pi(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),Qi(e,r)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&Fy(o,e)))&&(o=e,c=d)),e=e.next;while(e!==l);return o}function Fy(r,t){return Ct(r.prev,r,t.prev)<0&&Ct(t.next,r,r.next)<0}function Ny(r,t,e,i){var s=r;do s.z===0&&(s.z=zo(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,Uy(s)}function Uy(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 zo(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 ky(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 pi(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 Gy(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!$y(r,t)&&(Qi(r,t)&&Qi(t,r)&&Hy(r,t)&&(Ct(r.prev,r,t.prev)||Ct(r,t.prev,t))||js(r,t)&&Ct(r.prev,r,r.next)>0&&Ct(t.prev,t,t.next)>0)}function Ct(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function js(r,t){return r.x===t.x&&r.y===t.y}function wu(r,t,e,i){var s=qs(Ct(r,t,e)),n=qs(Ct(r,t,i)),o=qs(Ct(e,i,r)),a=qs(Ct(e,i,t));return!!(s!==n&&o!==a||s===0&&Ys(r,e,t)||n===0&&Ys(r,i,t)||o===0&&Ys(e,r,i)||a===0&&Ys(e,t,i))}function Ys(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 qs(r){return r>0?1:r<0?-1:0}function $y(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&&wu(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Qi(r,t){return Ct(r.prev,r,r.next)<0?Ct(r,t,r.next)>=0&&Ct(r,r.prev,t)>=0:Ct(r,t,r.prev)<0||Ct(r,r.next,t)<0}function Hy(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 Eu(r,t){var e=new Wo(r.i,r.x,r.y),i=new Wo(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 Tu(r,t,e,i){var s=new Wo(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 ts(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 Wo(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}Ws.deviation=function(r,t,e,i){var s=t&&t.length,n=s?t[0]*e:r.length,o=Math.abs(jo(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(jo(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 jo(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}Ws.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 Xy=Vo.exports;const Vy=vu(Xy);var Ks={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Ks.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,s=!r.nodeType&&r,n=typeof Ki=="object"&&Ki;(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="-",_=/^xn--/,y=/[^\x20-\x7E]/,x=/[\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"},v=l-h,w=Math.floor,C=String.fromCharCode,S;function I(A){throw new RangeError(g[A])}function L(A,F){for(var G=A.length,Q=[];G--;)Q[G]=F(A[G]);return Q}function R(A,F){var G=A.split("@"),Q="";G.length>1&&(Q=G[0]+"@",A=G[1]),A=A.replace(x,".");var Z=A.split("."),H=L(Z,F).join(".");return Q+H}function D(A){for(var F=[],G=0,Q=A.length,Z,H;G<Q;)Z=A.charCodeAt(G++),Z>=55296&&Z<=56319&&G<Q?(H=A.charCodeAt(G++),(H&64512)==56320?F.push(((Z&1023)<<10)+(H&1023)+65536):(F.push(Z),G--)):F.push(Z);return F}function E(A){return L(A,function(F){var G="";return F>65535&&(F-=65536,G+=C(F>>>10&1023|55296),F=56320|F&1023),G+=C(F),G}).join("")}function b(A){return A-48<10?A-22:A-65<26?A-65:A-97<26?A-97:l}function M(A,F){return A+22+75*(A<26)-((F!=0)<<5)}function N(A,F,G){var Q=0;for(A=G?w(A/d):A>>1,A+=w(A/F);A>v*u>>1;Q+=l)A=w(A/v);return w(Q+(v+1)*A/(A+c))}function $(A){var F=[],G=A.length,Q,Z=0,H=f,ft=p,bt,B,O,et,tt,yt,_t,Ye,qe;for(bt=A.lastIndexOf(m),bt<0&&(bt=0),B=0;B<bt;++B)A.charCodeAt(B)>=128&&I("not-basic"),F.push(A.charCodeAt(B));for(O=bt>0?bt+1:0;O<G;){for(et=Z,tt=1,yt=l;O>=G&&I("invalid-input"),_t=b(A.charCodeAt(O++)),(_t>=l||_t>w((a-Z)/tt))&&I("overflow"),Z+=_t*tt,Ye=yt<=ft?h:yt>=ft+u?u:yt-ft,!(_t<Ye);yt+=l)qe=l-Ye,tt>w(a/qe)&&I("overflow"),tt*=qe;Q=F.length+1,ft=N(Z-et,Q,et==0),w(Z/Q)>a-H&&I("overflow"),H+=w(Z/Q),Z%=Q,F.splice(Z++,0,H)}return E(F)}function k(A){var F,G,Q,Z,H,ft,bt,B,O,et,tt,yt=[],_t,Ye,qe,ws;for(A=D(A),_t=A.length,F=f,G=0,H=p,ft=0;ft<_t;++ft)tt=A[ft],tt<128&&yt.push(C(tt));for(Q=Z=yt.length,Z&&yt.push(m);Q<_t;){for(bt=a,ft=0;ft<_t;++ft)tt=A[ft],tt>=F&&tt<bt&&(bt=tt);for(Ye=Q+1,bt-F>w((a-G)/Ye)&&I("overflow"),G+=(bt-F)*Ye,F=bt,ft=0;ft<_t;++ft)if(tt=A[ft],tt<F&&++G>a&&I("overflow"),tt==F){for(B=G,O=l;et=O<=H?h:O>=H+u?u:O-H,!(B<et);O+=l)ws=B-et,qe=l-et,yt.push(C(M(et+ws%qe,0))),B=w(ws/qe);yt.push(C(M(B,0))),H=N(G,Ye,Q==Z),G=0,++Q}++G,++F}return yt.join("")}function X(A){return R(A,function(F){return _.test(F)?$(F.slice(4).toLowerCase()):F})}function it(A){return R(A,function(F){return y.test(F)?"xn--"+k(F):F})}if(o={version:"1.4.1",ucs2:{decode:D,encode:E},decode:$,encode:k,toASCII:it,toUnicode:X},i&&s)if(r.exports==i)s.exports=o;else for(S in o)o.hasOwnProperty(S)&&(i[S]=o[S]);else e.punycode=o})(Ki)}(Ks,Ks.exports);var zy=Ks.exports,mi=TypeError;const Wy=Sy(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Yo=typeof Map=="function"&&Map.prototype,qo=Object.getOwnPropertyDescriptor&&Yo?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Zs=Yo&&qo&&typeof qo.get=="function"?qo.get:null,Au=Yo&&Map.prototype.forEach,Ko=typeof Set=="function"&&Set.prototype,Zo=Object.getOwnPropertyDescriptor&&Ko?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Js=Ko&&Zo&&typeof Zo.get=="function"?Zo.get:null,Su=Ko&&Set.prototype.forEach,jy=typeof WeakMap=="function"&&WeakMap.prototype,es=jy?WeakMap.prototype.has:null,Yy=typeof WeakSet=="function"&&WeakSet.prototype,rs=Yy?WeakSet.prototype.has:null,qy=typeof WeakRef=="function"&&WeakRef.prototype,Cu=qy?WeakRef.prototype.deref:null,Ky=Boolean.prototype.valueOf,Zy=Object.prototype.toString,Jy=Function.prototype.toString,Qy=String.prototype.match,Jo=String.prototype.slice,yr=String.prototype.replace,t_=String.prototype.toUpperCase,Iu=String.prototype.toLowerCase,Ru=RegExp.prototype.test,Pu=Array.prototype.concat,ke=Array.prototype.join,e_=Array.prototype.slice,Mu=Math.floor,Qo=typeof BigInt=="function"?BigInt.prototype.valueOf:null,ta=Object.getOwnPropertySymbols,ea=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,gi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Qt=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===gi||!0)?Symbol.toStringTag:null,Bu=Object.prototype.propertyIsEnumerable,Du=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Ou(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Ru.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Mu(-r):Mu(r);if(i!==r){var s=String(i),n=Jo.call(t,s.length+1);return yr.call(s,e,"$&_")+"."+yr.call(yr.call(n,/([0-9]{3})/g,"$&_"),/_$/,"")}}return yr.call(t,e,"$&_")}var ra=Wy,Lu=ra.custom,Fu=Gu(Lu)?Lu:null,Nu={__proto__:null,double:'"',single:"'"},r_={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Qs=function r(t,e,i,s){var n=e||{};if(or(n,"quoteStyle")&&!or(Nu,n.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(or(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=or(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(or(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(or(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 Hu(t,n);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Ou(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Ou(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 ia(t)?"[Array]":"[Object]";var c=x_(n,i);if(typeof s>"u")s=[];else if($u(s,t)>=0)return"[Circular]";function d(b,M,N){if(M&&(s=e_.call(s),s.push(M)),N){var $={depth:n.depth};return or(n,"quoteStyle")&&($.quoteStyle=n.quoteStyle),r(b,$,i+1,s)}return r(b,n,i+1,s)}if(typeof t=="function"&&!ku(t)){var p=c_(t),f=tn(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+ke.call(f,", ")+" }":"")}if(Gu(t)){var m=gi?yr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):ea.call(t);return typeof t=="object"&&!gi?is(m):m}if(y_(t)){for(var _="<"+Iu.call(String(t.nodeName)),y=t.attributes||[],x=0;x<y.length;x++)_+=" "+y[x].name+"="+Uu(i_(y[x].value),"double",n);return _+=">",t.childNodes&&t.childNodes.length&&(_+="..."),_+="</"+Iu.call(String(t.nodeName))+">",_}if(ia(t)){if(t.length===0)return"[]";var g=tn(t,d);return c&&!v_(g)?"["+na(g,c)+"]":"[ "+ke.call(g,", ")+" ]"}if(n_(t)){var v=tn(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Bu.call(t,"cause")?"{ ["+String(t)+"] "+ke.call(Pu.call("[cause]: "+d(t.cause),v),", ")+" }":v.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+ke.call(v,", ")+" }"}if(typeof t=="object"&&o){if(Fu&&typeof t[Fu]=="function"&&ra)return ra(t,{depth:u-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(d_(t)){var w=[];return Au&&Au.call(t,function(b,M){w.push(d(M,t,!0)+" => "+d(b,t))}),Xu("Map",Zs.call(t),w,c)}if(m_(t)){var C=[];return Su&&Su.call(t,function(b){C.push(d(b,t))}),Xu("Set",Js.call(t),C,c)}if(f_(t))return sa("WeakMap");if(g_(t))return sa("WeakSet");if(p_(t))return sa("WeakRef");if(a_(t))return is(d(Number(t)));if(h_(t))return is(d(Qo.call(t)));if(l_(t))return is(Ky.call(t));if(o_(t))return is(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Ki<"u"&&t===Ki)return"{ [object globalThis] }";if(!s_(t)&&!ku(t)){var S=tn(t,d),I=Du?Du(t)===Object.prototype:t instanceof Object||t.constructor===Object,L=t instanceof Object?"":"null prototype",R=!I&&Qt&&Object(t)===t&&Qt in t?Jo.call(_r(t),8,-1):L?"Object":"",D=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",E=D+(R||L?"["+ke.call(Pu.call([],R||[],L||[]),": ")+"] ":"");return S.length===0?E+"{}":c?E+"{"+na(S,c)+"}":E+"{ "+ke.call(S,", ")+" }"}return String(t)};function Uu(r,t,e){var i=e.quoteStyle||t,s=Nu[i];return s+r+s}function i_(r){return yr.call(String(r),/"/g,"&quot;")}function ia(r){return _r(r)==="[object Array]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function s_(r){return _r(r)==="[object Date]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function ku(r){return _r(r)==="[object RegExp]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function n_(r){return _r(r)==="[object Error]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function o_(r){return _r(r)==="[object String]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function a_(r){return _r(r)==="[object Number]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function l_(r){return _r(r)==="[object Boolean]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function Gu(r){if(gi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!ea)return!1;try{return ea.call(r),!0}catch{}return!1}function h_(r){if(!r||typeof r!="object"||!Qo)return!1;try{return Qo.call(r),!0}catch{}return!1}var u_=Object.prototype.hasOwnProperty||function(r){return r in this};function or(r,t){return u_.call(r,t)}function _r(r){return Zy.call(r)}function c_(r){if(r.name)return r.name;var t=Qy.call(Jy.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function $u(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 d_(r){if(!Zs||!r||typeof r!="object")return!1;try{Zs.call(r);try{Js.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function f_(r){if(!es||!r||typeof r!="object")return!1;try{es.call(r,es);try{rs.call(r,rs)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function p_(r){if(!Cu||!r||typeof r!="object")return!1;try{return Cu.call(r),!0}catch{}return!1}function m_(r){if(!Js||!r||typeof r!="object")return!1;try{Js.call(r);try{Zs.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function g_(r){if(!rs||!r||typeof r!="object")return!1;try{rs.call(r,rs);try{es.call(r,es)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function y_(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Hu(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Hu(Jo.call(r,0,t.maxStringLength),t)+i}var s=r_[t.quoteStyle||"single"];s.lastIndex=0;var n=yr.call(yr.call(r,s,"\\$1"),/[\x00-\x1f]/g,__);return Uu(n,"single",t)}function __(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":"")+t_.call(t.toString(16))}function is(r){return"Object("+r+")"}function sa(r){return r+" { ? }"}function Xu(r,t,e,i){var s=i?na(e,i):ke.call(e,", ");return r+" ("+t+") {"+s+"}"}function v_(r){for(var t=0;t<r.length;t++)if($u(r[t],`
1
+ (function(Mt,Nt){typeof exports=="object"&&typeof module<"u"?Nt(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],Nt):(Mt=typeof globalThis<"u"?globalThis:Mt||self,Nt(Mt.AnnotoriousOSD={},Mt.OpenSeadragon))})(this,function(Mt,Nt){"use strict";var DT=Object.defineProperty;var OT=(Mt,Nt,Pr)=>Nt in Mt?DT(Mt,Nt,{enumerable:!0,configurable:!0,writable:!0,value:Pr}):Mt[Nt]=Pr;var Hl=(Mt,Nt,Pr)=>OT(Mt,typeof Nt!="symbol"?Nt+"":Nt,Pr);var Pr=Object.prototype.hasOwnProperty;function Mr(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--&&Mr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Pr.call(r,e)&&++i&&!Pr.call(t,e)||!(e in t)||!Mr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var ao=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(ao||{});const Ht=[];for(let r=0;r<256;++r)Ht.push((r+256).toString(16).slice(1));function mp(r,t=0){return(Ht[r[t+0]]+Ht[r[t+1]]+Ht[r[t+2]]+Ht[r[t+3]]+"-"+Ht[r[t+4]]+Ht[r[t+5]]+"-"+Ht[r[t+6]]+Ht[r[t+7]]+"-"+Ht[r[t+8]]+Ht[r[t+9]]+"-"+Ht[r[t+10]]+Ht[r[t+11]]+Ht[r[t+12]]+Ht[r[t+13]]+Ht[r[t+14]]+Ht[r[t+15]]).toLowerCase()}let lo;const gp=new Uint8Array(16);function yp(){if(!lo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");lo=crypto.getRandomValues.bind(crypto)}return lo(gp)}const _p=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Kl={randomUUID:_p};function vp(r,t,e){var i;if(Kl.randomUUID&&!r)return Kl.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??yp();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,mp(s)}const ho=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)}},xp=(r,t,e,i)=>({id:vp(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),bp=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},wp=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Ep=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!Mr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Tp=(r,t)=>!Mr(r.target,t.target),Ap=(r,t)=>{const e=bp(r,t),i=wp(r,t),s=Ep(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:Tp(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var fr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(fr||{});const Sp=(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 Ap(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}};let Cp=()=>({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 Ip=250,Rp=(r,t)=>{const e=Cp(),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,_=performance.now();if(_-o>Ip)i.splice(s+1),i.push(m),s=i.length-1;else{const y=i.length-1;i[y]=Sp(i[y],m)}o=_}n=!1};r.observe(a,{origin:fr.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),h=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotation(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:_}=i[s+1];h(f),c(m),p(_),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:_}=i[s];l(f),u(m),d(_),e.emit("undo",i[s]),s-=1}}}},Pp=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},p=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},f=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(S=>e.serialize(S)):e.serialize(x),C=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,C)}else v(x,g)})},1)},m=()=>{const{selected:y}=n,x=(y||[]).map(({id:g})=>o.getAnnotation(g));x.forEach(g=>{const v=h.find(w=>w.id===g.id);(!v||!Mr(v,g))&&f("updateAnnotation",g,v)}),h=h.map(g=>x.find(({id:w})=>w===g.id)||g)};n.subscribe(({selected:y})=>{if(!(h.length===0&&y.length===0)){if(h.length===0&&y.length>0)h=y.map(({id:x})=>o.getAnnotation(x));else if(h.length>0&&y.length===0)h.forEach(x=>{const g=o.getAnnotation(x.id);g&&!Mr(g,x)&&f("updateAnnotation",g,x)}),h=[];else{const x=new Set(h.map(v=>v.id)),g=new Set(y.map(({id:v})=>v));h.filter(v=>!g.has(v.id)).forEach(v=>{const w=o.getAnnotation(v.id);w&&!Mr(w,v)&&f("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}f("selectionChanged",h)}}),s.subscribe(y=>{!u&&y?f("mouseEnterAnnotation",o.getAnnotation(y)):u&&!y?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&y&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(y))),u=y}),a==null||a.subscribe(y=>f("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>f("createAnnotation",v)),(g||[]).forEach(v=>f("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const C=h.find(S=>S.id===v.id)||v;h=h.map(S=>S.id===v.id?w:S),f("updateAnnotation",w,C)})},{origin:fr.LOCAL}),o.observe(y=>{if(h){const x=new Set(h.map(v=>v.id)),g=(y.changes.updated||[]).filter(({newValue:v})=>x.has(v.id)).map(({newValue:v})=>v);g.length>0&&(h=h.map(v=>g.find(C=>C.id===v.id)||v))}},{origin:fr.REMOTE});const _=y=>x=>{const{updated:g}=x;y?(g||[]).forEach(v=>f("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>f("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},Mp=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:[]}),Bp=(r,t,e)=>{const{store:i,selection:s}=r,n=y=>{if(e){const{parsed:x,error:g}=e.parse(y);x?i.addAnnotation(x,fr.REMOTE):console.error(g)}else i.addAnnotation(ho(y),fr.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=y=>{const x=i.getAnnotation(y);return e&&x?e.serialize(x):x},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var y;const x=(((y=s.selected)==null?void 0:y.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?x.map(e.serialize):x},c=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(p(g,x),g)),d=y=>{if(typeof y=="string"){const x=i.getAnnotation(y);if(i.deleteAnnotation(y),x)return e?e.serialize(x):x}else{const x=e?e.parse(y).parsed:y;if(x)return i.deleteAnnotation(x),y}},p=(y,x=!0)=>{if(e){const g=e.parseAll||Mp(e),{parsed:v,failed:w}=g(y);w.length>0&&console.warn(`Discarded ${w.length} invalid annotations`,w),i.bulkAddAnnotation(v,x,fr.REMOTE)}else i.bulkAddAnnotation(y.map(ho),x,fr.REMOTE)},f=(y,x)=>{y?s.setSelected(y,x):s.clear()},m=y=>{s.clear(),s.setUserSelectAction(y)},_=y=>{if(e){const x=e.parse(y).parsed,g=e.serialize(i.getAnnotation(x.id));return i.updateAnnotation(x),g}else{const x=i.getAnnotation(y.id);return i.updateAnnotation(ho(y)),x}};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:_}},Dp="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Op=r=>crypto.getRandomValues(new Uint8Array(r)),Lp=(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}}},Fp=(r,t=21)=>Lp(r,t|0,Op),Np=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Dp[e[r]&63];return t};const Up=()=>({isGuest:!0,id:Fp("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),kp=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Gp=()=>{const r=[...kp];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Np();var $p=Object.defineProperty,Hp=(r,t,e)=>t in r?$p(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Zl=(r,t,e)=>Hp(r,typeof t!="symbol"?t+"":t,e);function At(){}function uo(r,t){for(const e in t)r[e]=t[e];return r}function Jl(r){return r()}function Ql(){return Object.create(null)}function Pe(r){r.forEach(Jl)}function Ut(r){return typeof r=="function"}function qt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Xp(r){return Object.keys(r).length===0}function th(r,...t){if(r==null){for(const i of t)i(void 0);return At}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function co(r,t,e){r.$$.on_destroy.push(th(t,e))}function Vp(r,t,e,i){if(r){const s=eh(r,t,e,i);return r[0](s)}}function eh(r,t,e,i){return r[1]&&i?uo(e.ctx.slice(),r[1](i(t))):e.ctx}function zp(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 Wp(r,t,e,i,s,n){if(s){const o=eh(t,e,i,n);r.p(o,s)}}function jp(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 rh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Is(r){return r??""}function Me(r,t){r.appendChild(t)}function st(r,t,e){r.insertBefore(t,e||null)}function rt(r){r.parentNode&&r.parentNode.removeChild(r)}function fo(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function vt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ih(r){return document.createTextNode(r)}function ge(){return ih(" ")}function ye(){return ih("")}function Dt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function T(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Yp(r){return Array.from(r.childNodes)}function pr(r,t,e){r.classList.toggle(t,!!e)}function qp(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let $i;function Hi(r){$i=r}function sh(){if(!$i)throw new Error("Function called outside component initialization");return $i}function Xi(r){sh().$$.on_mount.push(r)}function Qr(){const r=sh();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=qp(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function Ze(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const ti=[],Rs=[];let ei=[];const nh=[],Kp=Promise.resolve();let po=!1;function Zp(){po||(po=!0,Kp.then(oh))}function mo(r){ei.push(r)}const go=new Set;let ri=0;function oh(){if(ri!==0)return;const r=$i;do{try{for(;ri<ti.length;){const t=ti[ri];ri++,Hi(t),Jp(t.$$)}}catch(t){throw ti.length=0,ri=0,t}for(Hi(null),ti.length=0,ri=0;Rs.length;)Rs.pop()();for(let t=0;t<ei.length;t+=1){const e=ei[t];go.has(e)||(go.add(e),e())}ei.length=0}while(ti.length);for(;nh.length;)nh.pop()();po=!1,go.clear(),Hi(r)}function Jp(r){if(r.fragment!==null){r.update(),Pe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(mo)}}function Qp(r){const t=[],e=[];ei.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),ei=t}const Ps=new Set;let Br;function _e(){Br={r:0,c:[],p:Br}}function ve(){Br.r||Pe(Br.c),Br=Br.p}function at(r,t){r&&r.i&&(Ps.delete(r),r.i(t))}function pt(r,t,e,i){if(r&&r.o){if(Ps.has(r))return;Ps.add(r),Br.c.push(()=>{Ps.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function ii(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function ue(r){r&&r.c()}function se(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),mo(()=>{const n=r.$$.on_mount.map(Jl).filter(Ut);r.$$.on_destroy?r.$$.on_destroy.push(...n):Pe(n),r.$$.on_mount=[]}),s.forEach(mo)}function ne(r,t){const e=r.$$;e.fragment!==null&&(Qp(e.after_update),Pe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function tm(r,t){r.$$.dirty[0]===-1&&(ti.push(r),Zp(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ce(r,t,e,i,s,n,o=null,a=[-1]){const l=$i;Hi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:At,not_equal:s,bound:Ql(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Ql(),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&&tm(r,c)),d}):[],h.update(),u=!0,Pe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=Yp(t.target);h.fragment&&h.fragment.l(c),c.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&at(r.$$.fragment),se(r,t.target,t.anchor),oh()}Hi(l)}class de{constructor(){Zl(this,"$$"),Zl(this,"$$set")}$destroy(){ne(this,1),this.$destroy=At}$on(t,e){if(!Ut(e))return At;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&&!Xp(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const em="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(em);var wt=(r=>(r.ELLIPSE="ELLIPSE",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(wt||{});const yo={},_o=(r,t)=>yo[r]=t,vo=r=>yo[r.type].area(r),rm=(r,t,e)=>yo[r.type].intersects(r,t,e),Ms=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}},im={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}};_o(wt.ELLIPSE,im);const sm={area:r=>{const{points:t}=r.geometry;let e=0,i=t.length-1;for(let s=0;s<t.length;s++)e+=(t[i][0]+t[s][0])*(t[i][1]-t[s][1]),i=s;return Math.abs(.5*e)},intersects:(r,t,e)=>{const{points:i}=r.geometry;let s=!1;for(let n=0,o=i.length-1;n<i.length;o=n++){const a=i[n][0],l=i[n][1],h=i[o][0],u=i[o][1];l>e!=u>e&&t<(h-a)*(e-l)/(u-l)+a&&(s=!s)}return s}};_o(wt.POLYGON,sm);const nm={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};_o(wt.RECTANGLE,nm);const Je=r=>Bs(r.target),Bs=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},om=(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:wt.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}}}},am=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}`}},ah="http://www.w3.org/2000/svg",lh=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},lm=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${ah}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},hm=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(ah),i=t.lookupNamespaceURI(null);return e||i?lh(t).firstChild:lh(lm(t)).firstChild},um=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],s=i.split(" ").map(n=>n.split(",").map(parseFloat));return{type:wt.POLYGON,geometry:{points:s,bounds:Ms(s)}}},cm=r=>{const t=hm(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:wt.ELLIPSE,geometry:{cx:e,cy:i,rx:s,ry:n,bounds:o}}},dm=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return um(t);if(t.includes("<ellipse "))return cm(t);throw"Unsupported SVG shape: "+t},fm=r=>{let t;if(r.type===wt.POLYGON){const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(s=>s.join(",")).join(" ")}" /></svg>`}else if(r.type===wt.ELLIPSE){const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},Xt=[];for(let r=0;r<256;++r)Xt.push((r+256).toString(16).slice(1));function pm(r,t=0){return(Xt[r[t+0]]+Xt[r[t+1]]+Xt[r[t+2]]+Xt[r[t+3]]+"-"+Xt[r[t+4]]+Xt[r[t+5]]+"-"+Xt[r[t+6]]+Xt[r[t+7]]+"-"+Xt[r[t+8]]+Xt[r[t+9]]+"-"+Xt[r[t+10]]+Xt[r[t+11]]+Xt[r[t+12]]+Xt[r[t+13]]+Xt[r[t+14]]+Xt[r[t+15]]).toLowerCase()}let xo;const mm=new Uint8Array(16);function gm(){if(!xo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");xo=crypto.getRandomValues.bind(crypto)}return xo(mm)}const ym=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),hh={randomUUID:ym};function uh(r,t,e){var i;if(hh.randomUUID&&!r)return hh.randomUUID();r=r||{};const s=r.random??((i=r.rng)==null?void 0:i.call(r))??gm();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,pm(s)}var ch=Object.prototype.hasOwnProperty;function mr(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--&&mr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(ch.call(r,e)&&++i&&!ch.call(t,e)||!(e in t)||!mr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}function bo(){}function _m(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const si=[];function wo(r,t=bo){let e;const i=new Set;function s(a){if(_m(r,a)&&(r=a,e)){const l=!si.length;for(const h of i)h[1](),si.push(h,r);if(l){for(let h=0;h<si.length;h+=2)si[h][0](si[h+1]);si.length=0}}}function n(a){s(a(r))}function o(a,l=bo){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||bo),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const vm=r=>{const{subscribe:t,set:e}=wo();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 dh=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(dh||{});const Ds={selected:[]},xm=(r,t,e)=>{const{subscribe:i,set:s}=wo(Ds);let n=t,o=Ds;i(f=>o=f);const a=()=>{mr(o,Ds)||s(Ds)},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(_=>_.id===m)},u=(f,m)=>{let _;if(Array.isArray(f)){if(_=f.map(x=>r.getAnnotation(x)).filter(Boolean),_.length<f.length){console.warn("Invalid selection: "+f.filter(x=>!_.some(g=>g.id===x)));return}}else{const x=r.getAnnotation(f);if(!x){console.warn("Invalid selection: "+f);return}_=[x]}const y=_.reduce((x,g)=>{const v=fh(g,n,e);return v==="EDIT"?[...x,{id:g.id,editable:!0}]:v==="SELECT"?[...x,{id:g.id}]:x},[]);s({selected:y,event:m})},c=(f,m)=>{const _=Array.isArray(f)?f:[f],y=_.map(x=>r.getAnnotation(x)).filter(x=>!!x);s({selected:y.map(x=>{const g=m===void 0?fh(x,n,e)==="EDIT":m;return{id:x.id,editable:g}})}),y.length!==_.length&&console.warn("Invalid selection",f)},d=f=>{if(l())return!1;const{selected:m}=o;m.some(({id:_})=>f.includes(_))&&s({selected:m.filter(({id:_})=>!f.includes(_))})},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}},fh=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},Vt=[];for(let r=0;r<256;++r)Vt.push((r+256).toString(16).slice(1));function bm(r,t=0){return(Vt[r[t+0]]+Vt[r[t+1]]+Vt[r[t+2]]+Vt[r[t+3]]+"-"+Vt[r[t+4]]+Vt[r[t+5]]+"-"+Vt[r[t+6]]+Vt[r[t+7]]+"-"+Vt[r[t+8]]+Vt[r[t+9]]+"-"+Vt[r[t+10]]+Vt[r[t+11]]+Vt[r[t+12]]+Vt[r[t+13]]+Vt[r[t+14]]+Vt[r[t+15]]).toLowerCase()}let Eo;const wm=new Uint8Array(16);function Em(){if(!Eo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Eo=crypto.getRandomValues.bind(crypto)}return Eo(wm)}const Tm=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ph={randomUUID:Tm};function Am(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))??Em();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,bm(s)}const To=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)}},Sm=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Cm=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Im=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(s=>s.id===e.id);return{newBody:e,oldBody:i&&!mr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Rm=(r,t)=>!mr(r.target,t.target),mh=(r,t)=>{const e=Sm(r,t),i=Cm(r,t),s=Im(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:Rm(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var St=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(St||{});const Pm=(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},Mm=(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 mh(d,f)}else return c}),...(t.updated||[]).filter(({oldValue:c})=>!a.has(c.id))];return{created:l,deleted:h,updated:u}},Ao=r=>{const t=r.id===void 0?Am():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Bm=r=>r.id!==void 0,Dm=()=>{const r=new Map,t=new Map,e=[],i=(R,D={})=>{e.push({onChange:R,options:D})},s=R=>{const D=e.findIndex(E=>E.onChange==R);D>-1&&e.splice(D,1)},n=(R,D)=>{const E={origin:R,changes:{created:D.created||[],updated:D.updated||[],deleted:D.deleted||[]},state:[...r.values()]};e.forEach(b=>{Pm(b,E)&&b.onChange(E)})},o=(R,D=St.LOCAL)=>{if(R.id&&r.get(R.id))throw Error(`Cannot add annotation ${R.id} - exists already`);{const E=Ao(R);r.set(E.id,E),E.bodies.forEach(b=>t.set(b.id,E.id)),n(D,{created:[E]})}},a=(R,D)=>{const E=Ao(typeof R=="string"?D:R),b=typeof R=="string"?R:R.id,M=b&&r.get(b);if(M){const N=mh(M,E);return b===E.id?r.set(b,E):(r.delete(b),r.set(E.id,E)),M.bodies.forEach($=>t.delete($.id)),E.bodies.forEach($=>t.set($.id,E.id)),N}else console.warn(`Cannot update annotation ${b} - does not exist`)},l=(R,D=St.LOCAL,E=St.LOCAL)=>{const b=Bm(D)?E:D,M=a(R,D);M&&n(b,{updated:[M]})},h=(R,D=St.LOCAL)=>{const E=R.reduce((b,M)=>{const N=a(M);return N?[...b,N]:b},[]);E.length>0&&n(D,{updated:E})},u=(R,D=St.LOCAL)=>{const E=r.get(R.annotation);if(E){const b={...E,bodies:[...E.bodies,R]};r.set(E.id,b),t.set(R.id,b.id),n(D,{updated:[{oldValue:E,newValue:b,bodiesCreated:[R]}]})}else console.warn(`Attempt to add body to missing annotation: ${R.annotation}`)},c=()=>[...r.values()],d=(R=St.LOCAL)=>{const D=[...r.values()];r.clear(),t.clear(),n(R,{deleted:D})},p=(R,D=!0,E=St.LOCAL)=>{const b=R.map(Ao);if(D){const M=[...r.values()];r.clear(),t.clear(),b.forEach(N=>{r.set(N.id,N),N.bodies.forEach($=>t.set($.id,N.id))}),n(E,{created:b,deleted:M})}else{const M=R.reduce((N,$)=>{const k=$.id&&r.get($.id);return k?[...N,k]:N},[]);if(M.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${M.map(N=>N.id).join(", ")}`);b.forEach(N=>{r.set(N.id,N),N.bodies.forEach($=>t.set($.id,N.id))}),n(E,{created:b})}},f=R=>{const D=typeof R=="string"?R:R.id,E=r.get(D);if(E)return r.delete(D),E.bodies.forEach(b=>t.delete(b.id)),E;console.warn(`Attempt to delete missing annotation: ${D}`)},m=(R,D=St.LOCAL)=>{const E=f(R);E&&n(D,{deleted:[E]})},_=(R,D=St.LOCAL)=>{const E=R.reduce((b,M)=>{const N=f(M);return N?[...b,N]:b},[]);E.length>0&&n(D,{deleted:E})},y=R=>{const D=r.get(R.annotation);if(D){const E=D.bodies.find(b=>b.id===R.id);if(E){t.delete(E.id);const b={...D,bodies:D.bodies.filter(M=>M.id!==R.id)};return r.set(D.id,b),{oldValue:D,newValue:b,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${R.id} from annotation ${R.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${R.annotation}`)},x=(R,D=St.LOCAL)=>{const E=y(R);E&&n(D,{updated:[E]})},g=(R,D=St.LOCAL)=>{const E=R.map(b=>y(b)).filter(Boolean);E.length>0&&n(D,{updated:E})},v=R=>{const D=r.get(R);return D?{...D}:void 0},w=R=>{const D=t.get(R);if(D){const E=v(D).bodies.find(b=>b.id===R);if(E)return E;console.error(`Store integrity error: body ${R} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${R}`)},C=(R,D)=>{if(R.annotation!==D.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(R.annotation);if(E){const b=E.bodies.find(N=>N.id===R.id),M={...E,bodies:E.bodies.map(N=>N.id===b.id?D:N)};return r.set(E.id,M),b.id!==D.id&&(t.delete(b.id),t.set(D.id,M.id)),{oldValue:E,newValue:M,bodiesUpdated:[{oldBody:b,newBody:D}]}}else console.warn(`Attempt to add body to missing annotation ${R.annotation}`)},S=(R,D,E=St.LOCAL)=>{const b=C(R,D);b&&n(E,{updated:[b]})},I=(R,D=St.LOCAL)=>{const E=R.map(b=>C({id:b.id,annotation:b.annotation},b)).filter(Boolean);n(D,{updated:E})},L=R=>{const D=r.get(R.annotation);if(D){const E={...D,target:{...D.target,...R}};return r.set(D.id,E),{oldValue:D,newValue:E,targetUpdated:{oldTarget:D.target,newTarget:R}}}else console.warn(`Attempt to update target on missing annotation: ${R.annotation}`)};return{addAnnotation:o,addBody:u,all:c,bulkAddAnnotation:p,bulkDeleteAnnotation:_,bulkDeleteBodies:g,bulkUpdateAnnotation:h,bulkUpdateBodies:I,bulkUpdateTargets:(R,D=St.LOCAL)=>{const E=R.map(b=>L(b)).filter(Boolean);E.length>0&&n(D,{updated:E})},clear:d,deleteAnnotation:m,deleteBody:x,getAnnotation:v,getBody:w,observe:i,unobserve:s,updateAnnotation:l,updateBody:S,updateTarget:(R,D=St.LOCAL)=>{const E=L(R);E&&n(D,{updated:[E]})}}},Om=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let Lm=()=>({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 Fm=250,Nm=(r,t)=>{const e=Lm(),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,_=performance.now();if(_-o>Fm)i.splice(s+1),i.push(m),s=i.length-1;else{const y=i.length-1;i[y]=Mm(i[y],m)}o=_}n=!1};r.observe(a,{origin:St.LOCAL});const l=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),h=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),u=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:m})=>m)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:m})=>m)),d=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),p=f=>f&&f.length>0&&r.bulkDeleteAnnotation(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:_}=i[s+1];h(f),c(m),p(_),e.emit("redo",i[s+1]),s+=1}},undo:()=>{if(s>-1){n=!0;const{created:f,updated:m,deleted:_}=i[s];l(f),u(m),d(_),e.emit("undo",i[s]),s-=1}}}},Um=()=>{const{subscribe:r,set:t}=wo([]);return{subscribe:r,set:t}},km=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],u,c;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},p=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},f=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(S=>e.serialize(S)):e.serialize(x),C=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,C)}else v(x,g)})},1)},m=()=>{const{selected:y}=n,x=(y||[]).map(({id:g})=>o.getAnnotation(g));x.forEach(g=>{const v=h.find(w=>w.id===g.id);(!v||!mr(v,g))&&f("updateAnnotation",g,v)}),h=h.map(g=>x.find(({id:v})=>v===g.id)||g)};n.subscribe(({selected:y})=>{if(!(h.length===0&&y.length===0)){if(h.length===0&&y.length>0)h=y.map(({id:x})=>o.getAnnotation(x));else if(h.length>0&&y.length===0)h.forEach(x=>{const g=o.getAnnotation(x.id);g&&!mr(g,x)&&f("updateAnnotation",g,x)}),h=[];else{const x=new Set(h.map(v=>v.id)),g=new Set(y.map(({id:v})=>v));h.filter(v=>!g.has(v.id)).forEach(v=>{const w=o.getAnnotation(v.id);w&&!mr(w,v)&&f("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}f("selectionChanged",h)}}),s.subscribe(y=>{!u&&y?f("mouseEnterAnnotation",o.getAnnotation(y)):u&&!y?f("mouseLeaveAnnotation",o.getAnnotation(u)):u&&y&&(f("mouseLeaveAnnotation",o.getAnnotation(u)),f("mouseEnterAnnotation",o.getAnnotation(y))),u=y}),a==null||a.subscribe(y=>f("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(c&&clearTimeout(c),c=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>f("createAnnotation",v)),(g||[]).forEach(v=>f("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const C=h.find(S=>S.id===v.id)||v;h=h.map(S=>S.id===v.id?w:S),f("updateAnnotation",w,C)})},{origin:St.LOCAL}),o.observe(y=>{if(h){const x=new Set(h.map(v=>v.id)),g=(y.changes.updated||[]).filter(({newValue:v})=>x.has(v.id)).map(({newValue:v})=>v);g.length>0&&(h=h.map(v=>g.find(w=>w.id===v.id)||v))}},{origin:St.REMOTE});const _=y=>x=>{const{updated:g}=x;y?(g||[]).forEach(v=>f("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>f("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:p,emit:f}},Gm=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:[]}),$m=(r,t,e)=>{const{store:i,selection:s}=r,n=y=>{if(e){const{parsed:x,error:g}=e.parse(y);x?i.addAnnotation(x,St.REMOTE):console.error(g)}else i.addAnnotation(To(y),St.REMOTE)},o=()=>s.clear(),a=()=>i.clear(),l=y=>{const x=i.getAnnotation(y);return e&&x?e.serialize(x):x},h=()=>e?i.all().map(e.serialize):i.all(),u=()=>{var y;const x=(((y=s.selected)==null?void 0:y.map(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?x.map(e.serialize):x},c=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(p(g,x),g)),d=y=>{if(typeof y=="string"){const x=i.getAnnotation(y);if(i.deleteAnnotation(y),x)return e?e.serialize(x):x}else{const x=e?e.parse(y).parsed:y;if(x)return i.deleteAnnotation(x),y}},p=(y,x=!0)=>{if(e){const g=e.parseAll||Gm(e),{parsed:v,failed:w}=g(y);w.length>0&&console.warn(`Discarded ${w.length} invalid annotations`,w),i.bulkAddAnnotation(v,x,St.REMOTE)}else i.bulkAddAnnotation(y.map(To),x,St.REMOTE)},f=(y,x)=>{y?s.setSelected(y,x):s.clear()},m=y=>{s.clear(),s.setUserSelectAction(y)},_=y=>{if(e){const x=e.parse(y).parsed,g=e.serialize(i.getAnnotation(x.id));return i.updateAnnotation(x),g}else{const x=i.getAnnotation(y.id);return i.updateAnnotation(To(y)),x}};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:_}},Hm=(r,t,e)=>typeof t=="function"?t(r,e):t,Xm=(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||{}}},Vm="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let zm=r=>crypto.getRandomValues(new Uint8Array(r)),Wm=(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)=>Wm(r,t|0,zm),Ym=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Vm[e[r]&63];return t};const qm=()=>({isGuest:!0,id:jm("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Km=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}`},gh=r=>r?typeof r=="object"?{...r}:r:void 0,Zm=(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-${Km(e)}`,annotation:t,type:s,purpose:n,value:o,creator:gh(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...u}}),Jm=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});Ym();const Qm=(r,t={strict:!0,invertY:!1})=>({parse:e=>tg(e,t),serialize:e=>eg(e,r,t)}),tg=(r,t={strict:!0,invertY:!1})=>{const e=r.id||uh(),{creator:i,created:s,modified:n,body:o,...a}=r,l=Zm(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"?om(u,t.invertY):(u==null?void 0:u.type)==="SvgSelector"?dm(u):void 0;return c||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:gh(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)}`)}},eg=(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==wt.RECTANGLE?am(i.geometry):fm(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:Jm(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 yh(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function _h(r){let t,e;return t=new Vi({props:{x:r[10][0],y:r[10][1],scale:r[3]}}),t.$on("pointerdown",function(){Ut(r[9](`HANDLE-${r[12]}`))&&r[9](`HANDLE-${r[12]}`).apply(this,arguments)}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function rg(r){let t,e,i,s,n,o,a,l,h,u,c,d=ii(r[4].points),p=[];for(let m=0;m<d.length;m+=1)p[m]=_h(yh(r,d,m));const f=m=>pt(p[m],1,1,()=>{p[m]=null});return{c(){t=vt("polygon"),s=ge(),n=vt("polygon"),a=ge();for(let m=0;m<p.length;m+=1)p[m].c();l=ye(),T(t,"class","a9s-outer"),T(t,"style",e=r[1]?"display:none;":void 0),T(t,"points",i=r[4].points.map(vh).join(" ")),T(n,"class","a9s-inner a9s-shape-handle"),T(n,"style",r[1]),T(n,"points",o=r[4].points.map(xh).join(" "))},m(m,_){st(m,t,_),st(m,s,_),st(m,n,_),st(m,a,_);for(let y=0;y<p.length;y+=1)p[y]&&p[y].m(m,_);st(m,l,_),h=!0,u||(c=[Dt(t,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Dt(n,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],u=!0)},p(m,_){if(r=m,(!h||_&2&&e!==(e=r[1]?"display:none;":void 0))&&T(t,"style",e),(!h||_&16&&i!==(i=r[4].points.map(vh).join(" ")))&&T(t,"points",i),(!h||_&2)&&T(n,"style",r[1]),(!h||_&16&&o!==(o=r[4].points.map(xh).join(" ")))&&T(n,"points",o),_&536){d=ii(r[4].points);let y;for(y=0;y<d.length;y+=1){const x=yh(r,d,y);p[y]?(p[y].p(x,_),at(p[y],1)):(p[y]=_h(x),p[y].c(),at(p[y],1),p[y].m(l.parentNode,l))}for(_e(),y=d.length;y<p.length;y+=1)f(y);ve()}},i(m){if(!h){for(let _=0;_<d.length;_+=1)at(p[_]);h=!0}},o(m){p=p.filter(Boolean);for(let _=0;_<p.length;_+=1)pt(p[_]);h=!1},d(m){m&&(rt(t),rt(s),rt(n),rt(a),rt(l)),fo(p,m),u=!1,Pe(c)}}}function ig(r){let t,e;return t=new Sh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[rg,({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(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}const vh=r=>r.join(","),xh=r=>r.join(",");function sg(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 _=d.geometry;p==="SHAPE"?m=_.points.map(([x,g])=>[x+f[0],g+f[1]]):m=_.points.map(([x,g],v)=>p===`HANDLE-${v}`?[x+f[0],g+f[1]]:[x,g]);const y=Ms(m);return{...d,geometry:{points:m,bounds:y}}};function h(d){Ze.call(this,r,d)}function u(d){Ze.call(this,r,d)}function c(d){Ze.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 ng extends de{constructor(t){super(),ce(this,t,sg,ig,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const So=(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))},ni=[];function og(r,t=At){let e;const i=new Set;function s(a){if(qt(r,a)&&(r=a,e)){const l=!ni.length;for(const h of i)h[1](),ni.push(h,r);if(l){for(let h=0;h<ni.length;h+=2)ni[h][0](ni[h+1]);ni.length=0}}}function n(a){s(a(r))}function o(a,l=At){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||At),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const ag=(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}`)},lg=(r,t)=>{ag(r,t);const{subscribe:e,set:i}=og(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}},bh=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function hg(r){let t,e,i,s,n,o;return{c(){t=vt("rect"),T(t,"class",e=Is(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),T(t,"x",i=r[0]-r[5]/2),T(t,"y",s=r[1]-r[5]/2),T(t,"width",r[5]),T(t,"height",r[5])},m(a,l){st(a,t,l),n||(o=Dt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=Is(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&T(t,"class",e),l&33&&i!==(i=a[0]-a[5]/2)&&T(t,"x",i),l&34&&s!==(s=a[1]-a[5]/2)&&T(t,"y",s),l&32&&T(t,"width",a[5]),l&32&&T(t,"height",a[5])},d(a){a&&rt(t),n=!1,o()}}}function ug(r){let t,e,i,s,n,o,a,l,h;return{c(){t=vt("g"),e=vt("circle"),s=vt("rect"),T(e,"cx",r[0]),T(e,"cy",r[1]),T(e,"r",i=r[3]/r[2]),T(e,"class","a9s-touch-halo svelte-1sgkh33"),pr(e,"touched",r[4]),T(s,"class",n=Is(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),T(s,"x",o=r[0]-r[5]/2),T(s,"y",a=r[1]-r[5]/2),T(s,"width",r[5]),T(s,"height",r[5]),T(t,"class","a9s-touch-handle")},m(u,c){st(u,t,c),Me(t,e),Me(t,s),l||(h=[Dt(e,"pointerdown",r[10]),Dt(e,"pointerdown",r[6]),Dt(e,"pointerup",r[7]),Dt(s,"pointerdown",r[9]),Dt(s,"pointerdown",r[6]),Dt(s,"pointerup",r[7])],l=!0)},p(u,c){c&1&&T(e,"cx",u[0]),c&2&&T(e,"cy",u[1]),c&12&&i!==(i=u[3]/u[2])&&T(e,"r",i),c&16&&pr(e,"touched",u[4]),c&256&&n!==(n=Is(`a9s-handle ${u[8].class||""}`.trim())+" svelte-1sgkh33")&&T(s,"class",n),c&33&&o!==(o=u[0]-u[5]/2)&&T(s,"x",o),c&34&&a!==(a=u[1]-u[5]/2)&&T(s,"y",a),c&32&&T(s,"width",u[5]),c&32&&T(s,"height",u[5])},d(u){u&&rt(t),l=!1,Pe(h)}}}function cg(r){let t;function e(s,n){return bh?ug:hg}let i=e()(r);return{c(){i.c(),t=ye()},m(s,n){i.m(s,n),st(s,t,n)},p(s,[n]){i.p(s,n)},i:At,o:At,d(s){s&&rt(t),i.d(s)}}}function dg(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){Ze.call(this,r,f)}function d(f){Ze.call(this,r,f)}function p(f){Ze.call(this,r,f)}return r.$$set=f=>{e(8,t=uo(uo({},t),rh(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=rh(t),[s,n,o,a,l,i,h,u,t,c,d,p]}class Vi extends de{constructor(t){super(),ce(this,t,dg,cg,qt,{x:0,y:1,scale:2,radius:3})}}function fg(r){let t,e,i,s,n,o,a,l,h,u,c,d,p,f,m,_,y,x,g,v,w,C,S,I,L,R,D,E,b,M,N,$,k,X,it,A,F,G,Q,Z,H,ft,bt;return X=new Vi({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),X.$on("pointerdown",function(){Ut(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),A=new Vi({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),A.$on("pointerdown",function(){Ut(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),G=new Vi({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),G.$on("pointerdown",function(){Ut(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Z=new Vi({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Z.$on("pointerdown",function(){Ut(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=vt("rect"),a=ge(),l=vt("rect"),p=ge(),f=vt("rect"),x=ge(),g=vt("rect"),S=ge(),I=vt("rect"),E=ge(),b=vt("rect"),k=ge(),ue(X.$$.fragment),it=ge(),ue(A.$$.fragment),F=ge(),ue(G.$$.fragment),Q=ge(),ue(Z.$$.fragment),T(t,"class","a9s-outer"),T(t,"style",e=r[1]?"display:none;":void 0),T(t,"x",i=r[4].x),T(t,"y",s=r[4].y),T(t,"width",n=r[4].w),T(t,"height",o=r[4].h),T(l,"class","a9s-inner a9s-shape-handle"),T(l,"style",r[1]),T(l,"x",h=r[4].x),T(l,"y",u=r[4].y),T(l,"width",c=r[4].w),T(l,"height",d=r[4].h),T(f,"class","a9s-edge-handle a9s-edge-handle-top"),T(f,"x",m=r[4].x),T(f,"y",_=r[4].y),T(f,"height",1),T(f,"width",y=r[4].w),T(g,"class","a9s-edge-handle a9s-edge-handle-right"),T(g,"x",v=r[4].x+r[4].w),T(g,"y",w=r[4].y),T(g,"height",C=r[4].h),T(g,"width",1),T(I,"class","a9s-edge-handle a9s-edge-handle-bottom"),T(I,"x",L=r[4].x),T(I,"y",R=r[4].y+r[4].h),T(I,"height",1),T(I,"width",D=r[4].w),T(b,"class","a9s-edge-handle a9s-edge-handle-left"),T(b,"x",M=r[4].x),T(b,"y",N=r[4].y),T(b,"height",$=r[4].h),T(b,"width",1)},m(B,O){st(B,t,O),st(B,a,O),st(B,l,O),st(B,p,O),st(B,f,O),st(B,x,O),st(B,g,O),st(B,S,O),st(B,I,O),st(B,E,O),st(B,b,O),st(B,k,O),se(X,B,O),st(B,it,O),se(A,B,O),st(B,F,O),se(G,B,O),st(B,Q,O),se(Z,B,O),H=!0,ft||(bt=[Dt(t,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Dt(l,"pointerdown",function(){Ut(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),Dt(f,"pointerdown",function(){Ut(r[9]("TOP"))&&r[9]("TOP").apply(this,arguments)}),Dt(g,"pointerdown",function(){Ut(r[9]("RIGHT"))&&r[9]("RIGHT").apply(this,arguments)}),Dt(I,"pointerdown",function(){Ut(r[9]("BOTTOM"))&&r[9]("BOTTOM").apply(this,arguments)}),Dt(b,"pointerdown",function(){Ut(r[9]("LEFT"))&&r[9]("LEFT").apply(this,arguments)})],ft=!0)},p(B,O){r=B,(!H||O&2&&e!==(e=r[1]?"display:none;":void 0))&&T(t,"style",e),(!H||O&16&&i!==(i=r[4].x))&&T(t,"x",i),(!H||O&16&&s!==(s=r[4].y))&&T(t,"y",s),(!H||O&16&&n!==(n=r[4].w))&&T(t,"width",n),(!H||O&16&&o!==(o=r[4].h))&&T(t,"height",o),(!H||O&2)&&T(l,"style",r[1]),(!H||O&16&&h!==(h=r[4].x))&&T(l,"x",h),(!H||O&16&&u!==(u=r[4].y))&&T(l,"y",u),(!H||O&16&&c!==(c=r[4].w))&&T(l,"width",c),(!H||O&16&&d!==(d=r[4].h))&&T(l,"height",d),(!H||O&16&&m!==(m=r[4].x))&&T(f,"x",m),(!H||O&16&&_!==(_=r[4].y))&&T(f,"y",_),(!H||O&16&&y!==(y=r[4].w))&&T(f,"width",y),(!H||O&16&&v!==(v=r[4].x+r[4].w))&&T(g,"x",v),(!H||O&16&&w!==(w=r[4].y))&&T(g,"y",w),(!H||O&16&&C!==(C=r[4].h))&&T(g,"height",C),(!H||O&16&&L!==(L=r[4].x))&&T(I,"x",L),(!H||O&16&&R!==(R=r[4].y+r[4].h))&&T(I,"y",R),(!H||O&16&&D!==(D=r[4].w))&&T(I,"width",D),(!H||O&16&&M!==(M=r[4].x))&&T(b,"x",M),(!H||O&16&&N!==(N=r[4].y))&&T(b,"y",N),(!H||O&16&&$!==($=r[4].h))&&T(b,"height",$);const et={};O&16&&(et.x=r[4].x),O&16&&(et.y=r[4].y),O&8&&(et.scale=r[3]),X.$set(et);const tt={};O&16&&(tt.x=r[4].x+r[4].w),O&16&&(tt.y=r[4].y),O&8&&(tt.scale=r[3]),A.$set(tt);const yt={};O&16&&(yt.x=r[4].x+r[4].w),O&16&&(yt.y=r[4].y+r[4].h),O&8&&(yt.scale=r[3]),G.$set(yt);const _t={};O&16&&(_t.x=r[4].x),O&16&&(_t.y=r[4].y+r[4].h),O&8&&(_t.scale=r[3]),Z.$set(_t)},i(B){H||(at(X.$$.fragment,B),at(A.$$.fragment,B),at(G.$$.fragment,B),at(Z.$$.fragment,B),H=!0)},o(B){pt(X.$$.fragment,B),pt(A.$$.fragment,B),pt(G.$$.fragment,B),pt(Z.$$.fragment,B),H=!1},d(B){B&&(rt(t),rt(a),rt(l),rt(p),rt(f),rt(x),rt(g),rt(S),rt(I),rt(E),rt(b),rt(k),rt(it),rt(F),rt(Q)),ne(X,B),ne(A,B),ne(G,B),ne(Z,B),ft=!1,Pe(bt)}}}function pg(r){let t,e;return t=new Sh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[fg,({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(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function mg(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],[x,g]=[m.maxX,m.maxY];const[v,w]=f;if(p==="SHAPE")_+=v,x+=v,y+=w,g+=w;else{switch(p){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{y+=w;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=w;break}}switch(p){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{_+=v;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{x+=v;break}}}const C=Math.min(_,x),S=Math.min(y,g),I=Math.abs(x-_),L=Math.abs(g-y);return{...d,geometry:{x:C,y:S,w:I,h:L,bounds:{minX:C,minY:S,maxX:C+I,maxY:S+L}}}};function h(d){Ze.call(this,r,d)}function u(d){Ze.call(this,r,d)}function c(d){Ze.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 gg extends de{constructor(t){super(),ce(this,t,mg,pg,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const wh=new Map([[wt.RECTANGLE,gg],[wt.POLYGON,ng]]),Eh=r=>wh.get(r.type),Th=(r,t)=>wh.set(r,t),yg=r=>({}),Ah=r=>({grab:r[0]});function _g(r){let t,e,i,s;const n=r[7].default,o=Vp(n,r,r[6],Ah);return{c(){t=vt("g"),o&&o.c(),T(t,"class","a9s-annotation selected")},m(a,l){st(a,t,l),o&&o.m(t,null),e=!0,i||(s=[Dt(t,"pointerup",r[2]),Dt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&64)&&Wp(o,n,a,a[6],e?zp(n,a[6],l,yg):jp(a[6]),Ah)},i(a){e||(at(o,a),e=!0)},o(a){pt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,Pe(s)}}}function vg(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Qr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,u,c;const d=m=>_=>{h=m,u=l.elementToImage(_.offsetX,_.offsetY),c=o,_.target.setPointerCapture(_.pointerId),n("grab",_)},p=m=>{if(h){const[_,y]=l.elementToImage(m.offsetX,m.offsetY),x=[_-u[0],y-u[1]];e(3,o=a(c,h,x)),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 Sh extends de{constructor(t){super(),ce(this,t,vg,_g,qt,{shape:3,editor:4,transform:5})}}const Os=(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 xg(r,t,e){let i;const s=Qr();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:u}=t,c;return Xi(()=>(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=Os(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 bg extends de{constructor(t){super(),ce(this,t,xg,null,qt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function wg(r,t,e){const i=Qr();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return Xi(()=>{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 Eg extends de{constructor(t){super(),ce(this,t,wg,null,qt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Ch(r){let t,e;return{c(){t=vt("rect"),e=vt("rect"),T(t,"class","a9s-outer"),T(t,"x",r[1]),T(t,"y",r[2]),T(t,"width",r[3]),T(t,"height",r[4]),T(e,"class","a9s-inner"),T(e,"x",r[1]),T(e,"y",r[2]),T(e,"width",r[3]),T(e,"height",r[4])},m(i,s){st(i,t,s),st(i,e,s)},p(i,s){s&2&&T(t,"x",i[1]),s&4&&T(t,"y",i[2]),s&8&&T(t,"width",i[3]),s&16&&T(t,"height",i[4]),s&2&&T(e,"x",i[1]),s&4&&T(e,"y",i[2]),s&8&&T(e,"width",i[3]),s&16&&T(e,"height",i[4])},d(i){i&&(rt(t),rt(e))}}}function Tg(r){let t,e=r[0]&&Ch(r);return{c(){t=vt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){st(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=Ch(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&rt(t),e&&e.d()}}}function Ag(r,t,e){const i=Qr();let{addEventListener:s}=t,{drawingMode:n}=t,{transform:o}=t,a,l,h,u,c,d,p;const f=x=>{const g=x;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=x=>{const g=x;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])))},_=x=>{const g=x,v=performance.now()-a;if(n==="click"){if(v>300)return;l?y():(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&&(v>300||d*p>100?(g.stopPropagation(),y()):(e(0,l=void 0),h=void 0))},y=()=>{if(d*p>15){const x={type:wt.RECTANGLE,geometry:{bounds:{minX:u,minY:c,maxX:u+d,maxY:c+p},x:u,y:c,w:d,h:p}};i("create",x)}e(0,l=void 0),h=void 0};return Xi(()=>{s("pointerdown",f),s("pointermove",m),s("pointerup",_,!0)}),r.$$set=x=>{"addEventListener"in x&&e(5,s=x.addEventListener),"drawingMode"in x&&e(6,n=x.drawingMode),"transform"in x&&e(7,o=x.transform)},[l,u,c,d,p,s,n,o]}class Sg extends de{constructor(t){super(),ce(this,t,Ag,Tg,qt,{addEventListener:5,drawingMode:6,transform:7})}}function Co(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 Ih(r){let t,e,i,s,n,o=r[2]&&Rh(r);return{c(){t=vt("polygon"),i=vt("polygon"),o&&o.c(),n=ye(),T(t,"class","a9s-outer"),T(t,"points",e=r[16]),T(i,"class","a9s-inner"),T(i,"points",s=r[16])},m(a,l){st(a,t,l),st(a,i,l),o&&o.m(a,l),st(a,n,l)},p(a,l){l&7&&e!==(e=a[16])&&T(t,"points",e),l&7&&s!==(s=a[16])&&T(i,"points",s),a[2]?o?o.p(a,l):(o=Rh(a),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},d(a){a&&(rt(t),rt(i),rt(n)),o&&o.d(a)}}}function Rh(r){let t,e,i;return{c(){t=vt("rect"),T(t,"class","a9s-handle"),T(t,"x",e=r[0][0][0]-r[3]/2),T(t,"y",i=r[0][0][1]-r[3]/2),T(t,"height",r[3]),T(t,"width",r[3])},m(s,n){st(s,t,n)},p(s,n){n&9&&e!==(e=s[0][0][0]-s[3]/2)&&T(t,"x",e),n&9&&i!==(i=s[0][0][1]-s[3]/2)&&T(t,"y",i),n&8&&T(t,"height",s[3]),n&8&&T(t,"width",s[3])},d(s){s&&rt(t)}}}function Cg(r){let t,e=r[1]&&Ih(Co(r));return{c(){t=vt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){st(i,t,s),e&&e.m(t,null)},p(i,[s]){i[1]?e?e.p(Co(i),s):(e=Ih(Co(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&rt(t),e&&e.d()}}}const Ig=20,Rg=1500;function Pg(r,t,e){let i;const s=Qr();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,u=[],c,d,p=!1;const f=g=>{const v=g,{timeStamp:w,offsetX:C,offsetY:S}=v;if(h={timeStamp:w,offsetX:C,offsetY:S},o==="drag"&&u.length===0){const I=a.elementToImage(v.offsetX,v.offsetY);u.push(I),e(1,c=I)}},m=g=>{const v=g;if(d&&clearTimeout(d),u.length>0){if(e(1,c=a.elementToImage(v.offsetX,v.offsetY)),u.length>2){const w=So(c,u[0])*l;e(2,p=w<Ig)}v.pointerType==="touch"&&(d=setTimeout(()=>{y()},Rg))}},_=g=>{const v=g;if(d&&clearTimeout(d),o==="click"){const w=v.timeStamp-h.timeStamp,C=So([h.offsetX,h.offsetY],[v.offsetX,v.offsetY]);if(w>300||C>15)return;if(p)x();else if(u.length===0){const S=a.elementToImage(v.offsetX,v.offsetY);u.push(S),e(1,c=S)}else u.push(c)}else{if(u.length===1&&So(u[0],c)<=4){e(0,u=[]),e(1,c=void 0);return}v.stopImmediatePropagation(),p?x():u.push(c)}},y=()=>{if(!c)return;const g=u.slice(0,-1);if(g.length<3)return;const v={type:wt.POLYGON,geometry:{bounds:Ms(u),points:g}};vo(v)>4&&(e(0,u=[]),e(1,c=void 0),s("create",v))},x=()=>{const g={type:wt.POLYGON,geometry:{bounds:Ms(u),points:[...u]}};e(0,u=[]),e(1,c=void 0),s("create",g)};return Xi(()=>{n("pointerdown",f,!0),n("pointermove",m),n("pointerup",_,!0),n("dblclick",y,!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 Mg extends de{constructor(t){super(),ce(this,t,Pg,Cg,qt,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const Io=new Map([["rectangle",{tool:Sg}],["polygon",{tool:Mg}]]),Ls=()=>[...Io.keys()],Fs=r=>Io.get(r),Ph=(r,t,e)=>Io.set(r,{tool:t,opts:e});function Bg(r){let t,e,i,s,n;return{c(){t=vt("g"),e=vt("ellipse"),s=vt("ellipse"),T(e,"class","a9s-outer"),T(e,"style",i=r[1]?"display:none;":void 0),T(e,"cx",r[2]),T(e,"cy",r[3]),T(e,"rx",r[4]),T(e,"ry",r[5]),T(s,"class","a9s-inner"),T(s,"style",r[1]),T(s,"cx",r[2]),T(s,"cy",r[3]),T(s,"rx",r[4]),T(s,"ry",r[5]),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){st(o,t,a),Me(t,e),Me(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&T(e,"style",i),a&2&&T(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&T(t,"data-id",n)},i:At,o:At,d(o){o&&rt(t)}}}function Dg(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=Os(s,o))},[s,i,a,l,h,u,n,o]}class Og extends de{constructor(t){super(),ce(this,t,Dg,Bg,qt,{annotation:0,geom:6,style:7})}}function Lg(r){let t,e,i,s,n;return{c(){t=vt("g"),e=vt("polygon"),s=vt("polygon"),T(e,"class","a9s-outer"),T(e,"style",i=r[1]?"display:none;":void 0),T(e,"points",r[2].map(Fg).join(" ")),T(s,"class","a9s-inner"),T(s,"style",r[1]),T(s,"points",r[2].map(Ng).join(" ")),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){st(o,t,a),Me(t,e),Me(t,s)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&T(e,"style",i),a&2&&T(s,"style",o[1]),a&1&&n!==(n=o[0].id)&&T(t,"data-id",n)},i:At,o:At,d(o){o&&rt(t)}}}const Fg=r=>r.join(","),Ng=r=>r.join(",");function Ug(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=Os(s,o))},[s,i,a,n,o]}class kg extends de{constructor(t){super(),ce(this,t,Ug,Lg,qt,{annotation:0,geom:3,style:4})}}function Gg(r){let t,e,i,s,n;return{c(){t=vt("g"),e=vt("rect"),s=vt("rect"),T(e,"class","a9s-outer"),T(e,"style",i=r[5]?"display:none;":void 0),T(e,"x",r[4]),T(e,"y",r[3]),T(e,"width",r[2]),T(e,"height",r[1]),T(s,"class","a9s-inner"),T(s,"style",r[5]),T(s,"x",r[4]),T(s,"y",r[3]),T(s,"width",r[2]),T(s,"height",r[1]),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){st(o,t,a),Me(t,e),Me(t,s)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&T(e,"style",i),a&16&&T(e,"x",o[4]),a&8&&T(e,"y",o[3]),a&4&&T(e,"width",o[2]),a&2&&T(e,"height",o[1]),a&32&&T(s,"style",o[5]),a&16&&T(s,"x",o[4]),a&8&&T(s,"y",o[3]),a&4&&T(s,"width",o[2]),a&2&&T(s,"height",o[1]),a&1&&n!==(n=o[0].id)&&T(t,"data-id",n)},i:At,o:At,d(o){o&&rt(t)}}}function $g(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=Os(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 Hg extends de{constructor(t){super(),ce(this,t,$g,Gg,qt,{annotation:0,geom:6,style:7})}}const Xg=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]}}),Vg=250,zg=(r,t)=>{const e=Qr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<Vg){const{x:n,y:o}=Mh(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},Mh=(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 Bh(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 Dh(r,t,e){const i=r.slice();return i[43]=t[e],i}function Ro(r){const t=r.slice(),e=t[43].target.selector;return t[46]=e,t}function Oh(r){let t=r[43].id,e,i,s=Lh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&65536&&qt(t,t=n[43].id)?(_e(),pt(s,1,1,At),ve(),s=Lh(n),s.c(),at(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Wg(r){let t,e;return t=new kg({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function jg(r){let t,e;return t=new Hg({props:{annotation:r[43],geom:r[46].geometry,style:r[1]}}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Yg(r){var t;let e,i;return e=new Og({props:{annotation:r[43],geom:(t=r[46])==null?void 0:t.geometry,style:r[1]}}),{c(){ue(e.$$.fragment)},m(s,n){se(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||(at(e.$$.fragment,s),i=!0)},o(s){pt(e.$$.fragment,s),i=!1},d(s){ne(e,s)}}}function Lh(r){let t,e,i,s;const n=[Yg,jg,Wg],o=[];function a(l,h){var u,c,d;return((u=l[46])==null?void 0:u.type)===wt.ELLIPSE?0:((c=l[46])==null?void 0:c.type)===wt.RECTANGLE?1:((d=l[46])==null?void 0:d.type)===wt.POLYGON?2:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=ye()},m(l,h){~t&&o[t].m(l,h),st(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(_e(),pt(o[u],1,1,()=>{o[u]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(at(e),s=!0)},o(l){pt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Fh(r){let t=Je(r[43])&&!r[9](r[43]),e,i,s=t&&Oh(Ro(r));return{c(){s&&s.c(),e=ye()},m(n,o){s&&s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&66048&&(t=Je(n[43])&&!n[9](n[43])),t?s?(s.p(Ro(n),o),o[0]&66048&&at(s,1)):(s=Oh(Ro(n)),s.c(),at(s,1),s.m(e.parentNode,e)):s&&(_e(),pt(s,1,1,()=>{s=null}),ve())},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s&&s.d(n)}}}function Nh(r){let t,e,i,s;const n=[Kg,qg],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=ye()},m(l,h){~t&&o[t].m(l,h),st(l,i,h),s=!0},p(l,h){let u=t;t=a(l),t===u?~t&&o[t].p(l,h):(e&&(_e(),pt(o[u],1,1,()=>{o[u]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),at(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(at(e),s=!0)},o(l){pt(e),s=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function qg(r){let t=`${r[2]}-${r[5]}`,e,i,s=Uh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&36&&qt(t,t=`${n[2]}-${n[5]}`)?(_e(),pt(s,1,1,At),ve(),s=Uh(n),s.c(),at(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Kg(r){let t,e,i=ii(r[8]),s=[];for(let o=0;o<i.length;o+=1)s[o]=$h(Bh(r,i,o));const n=o=>pt(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=ye()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);st(o,t,a),e=!0},p(o,a){if(a[0]&21107010){i=ii(o[8]);let l;for(l=0;l<i.length;l+=1){const h=Bh(o,i,l);s[l]?(s[l].p(h,a),at(s[l],1)):(s[l]=$h(h),s[l].c(),at(s[l],1),s[l].m(t.parentNode,t))}for(_e(),l=i.length;l<s.length;l+=1)n(l);ve()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)at(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)pt(s[a]);e=!1},d(o){o&&rt(t),fo(s,o)}}}function Uh(r){let t,e;return t=new Eg({props:{target:r[6],tool:r[14],drawingMode:r[13],transform:r[12],viewportScale:r[17]}}),t.$on("create",r[21]),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function kh(r){let t=r[39].id,e,i,s=Gh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),st(n,e,o),i=!0},p(n,o){o[0]&256&&qt(t,t=n[39].id)?(_e(),pt(s,1,1,At),ve(),s=Gh(n),s.c(),at(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(at(s),i=!0)},o(n){pt(s),i=!1},d(n){n&&rt(e),s.d(n)}}}function Gh(r){let t,e;return t=new bg({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(){Ut(r[22](r[39]))&&r[22](r[39]).apply(this,arguments)}),{c(){ue(t.$$.fragment)},m(i,s){se(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||(at(t.$$.fragment,i),e=!0)},o(i){pt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function $h(r){let t,e,i=r[40]&&kh(r);return{c(){i&&i.c(),t=ye()},m(s,n){i&&i.m(s,n),st(s,t,n),e=!0},p(s,n){s[40]?i?(i.p(s,n),n[0]&256&&at(i,1)):(i=kh(s),i.c(),at(i,1),i.m(t.parentNode,t)):i&&(_e(),pt(i,1,1,()=>{i=null}),ve())},i(s){e||(at(i),e=!0)},o(s){pt(i),e=!1},d(s){s&&rt(t),i&&i.d(s)}}}function Zg(r){let t,e,i,s,n,o,a=ii(r[16].filter(r[34])),l=[];for(let c=0;c<a.length;c+=1)l[c]=Fh(Dh(r,a,c));const h=c=>pt(l[c],1,1,()=>{l[c]=null});let u=r[6]&&Nh(r);return{c(){t=vt("svg"),e=vt("g");for(let c=0;c<l.length;c+=1)l[c].c();i=vt("g"),u&&u.c(),T(i,"class","drawing"),T(t,"class","a9s-annotationlayer"),pr(t,"drawing",r[14]),pr(t,"hidden",!r[3]),pr(t,"hover",r[15])},m(c,d){st(c,t,d),Me(t,e);for(let p=0;p<l.length;p+=1)l[p]&&l[p].m(e,null);Me(t,i),u&&u.m(i,null),r[35](i),r[36](t),s=!0,n||(o=[Dt(t,"pointerup",function(){Ut(r[10])&&r[10].apply(this,arguments)}),Dt(t,"pointerdown",function(){Ut(r[11])&&r[11].apply(this,arguments)}),Dt(t,"pointermove",r[23])],n=!0)},p(c,d){if(r=c,d[0]&66050){a=ii(r[16].filter(r[34]));let p;for(p=0;p<a.length;p+=1){const f=Dh(r,a,p);l[p]?(l[p].p(f,d),at(l[p],1)):(l[p]=Fh(f),l[p].c(),at(l[p],1),l[p].m(e,null))}for(_e(),p=a.length;p<l.length;p+=1)h(p);ve()}r[6]?u?(u.p(r,d),d[0]&64&&at(u,1)):(u=Nh(r),u.c(),at(u,1),u.m(i,null)):u&&(_e(),pt(u,1,1,()=>{u=null}),ve()),(!s||d[0]&16384)&&pr(t,"drawing",r[14]),(!s||d[0]&8)&&pr(t,"hidden",!r[3]),(!s||d[0]&32768)&&pr(t,"hover",r[15])},i(c){if(!s){for(let d=0;d<a.length;d+=1)at(l[d]);at(u),s=!0}},o(c){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)pt(l[d]);pt(u),s=!1},d(c){c&&rt(t),fo(l,c),u&&u.d(),r[35](null),r[36](null),n=!1,Pe(o)}}}function Jg(r,t,e){let i,s,n,o,a,l,h,u,c,d,p,f=At,m=()=>(f(),f=th(M,B=>e(17,p=B)),M);r.$$.on_destroy.push(()=>f());let{drawingEnabled:_}=t,{image:y}=t,{preferredDrawingMode:x}=t,{state:g}=t,{style:v=void 0}=t,{toolName:w=Ls()[0]}=t,{user:C}=t,{visible:S=!0}=t,I=0;const L=()=>e(5,I+=1),R=()=>w,D=()=>_;let E,b,M;Xi(()=>m(e(7,M=lg(y,b))));const{hover:N,selection:$,store:k}=g;co(r,N,B=>e(15,u=B)),co(r,$,B=>e(33,c=B)),co(r,k,B=>e(16,d=B));let X,it;const A=B=>{X&&k.unobserve(X);const O=B.filter(({editable:et})=>et).map(({id:et})=>et);O.length>0?(e(8,it=O.map(et=>k.getAnnotation(et)).filter(et=>et&&Je(et))),X=et=>{const{updated:tt}=et.changes;e(8,it=tt==null?void 0:tt.map(yt=>yt.newValue))},k.observe(X,{annotations:O})):e(8,it=void 0)},F=B=>{const O=uh(),et={id:O,bodies:[],target:{annotation:O,selector:B.detail,creator:C,created:new Date}};k.addAnnotation(et),$.setSelected(et.id)},G=B=>O=>{var et;const{target:tt}=B,yt=10*60*1e3,_t=((et=tt.creator)==null?void 0:et.id)!==C.id||!tt.created||new Date().getTime()-tt.created.getTime()>yt;k.updateTarget({...tt,selector:O.detail,created:_t?tt.created:new Date,updated:_t?new Date:void 0,updatedBy:_t?C:void 0})},Q=B=>{const{x:O,y:et}=Mh(B,b),tt=k.getAt(O,et);tt?u!==tt.id&&N.set(tt.id):N.set(void 0)},Z=B=>Eh(B),H=B=>Je(B);function ft(B){Rs[B?"unshift":"push"](()=>{E=B,e(6,E)})}function bt(B){Rs[B?"unshift":"push"](()=>{b=B,e(4,b)})}return r.$$set=B=>{"drawingEnabled"in B&&e(0,_=B.drawingEnabled),"image"in B&&e(25,y=B.image),"preferredDrawingMode"in B&&e(26,x=B.preferredDrawingMode),"state"in B&&e(27,g=B.state),"style"in B&&e(1,v=B.style),"toolName"in B&&e(2,w=B.toolName),"user"in B&&e(28,C=B.user),"visible"in B&&e(3,S=B.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(14,{tool:i,opts:s}=Fs(w)||{tool:void 0,opts:void 0},i,(e(32,s),e(2,w))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(13,n=(s==null?void 0:s.drawingMode)||x),r.$$.dirty[0]&16&&e(12,o=Xg(b)),r.$$.dirty[0]&16&&e(11,{onPointerDown:a,onPointerUp:l}=zg(b,k),a,(e(10,l),e(4,b))),r.$$.dirty[1]&4&&e(9,h=B=>c.selected.find(O=>O.id===B.id&&O.editable)),r.$$.dirty[1]&4&&A(c.selected)},[_,v,w,S,b,I,E,M,it,h,l,a,o,n,i,u,d,p,N,$,k,F,G,Q,Z,y,x,g,C,L,R,D,s,c,H,ft,bt]}class Qg extends de{constructor(t){super(),ce(this,t,Jg,Zg,qt,{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 Hh(r,t,e=0,i=r.length-1,s=ty){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));Hh(r,t,p,f,s)}const n=r[t];let o=e,a=i;for(zi(r,e,t),s(r[i],n)>0&&zi(r,e,i);o<a;){for(zi(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?zi(r,e,a):(a++,zi(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function zi(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function ty(r,t){return r<t?-1:r>t?1:0}class ey{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(!Us(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;Us(t,l)&&(e.leaf?i.push(a):Mo(t,l)?this._all(a,i):n.push(a))}e=n.pop()}return i}collides(t){let e=this.data;if(!Us(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(Us(t,o)){if(e.leaf||Mo(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=ai([]),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=ry(t,i.children,e);if(u!==-1)return i.children.splice(u,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&Mo(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=ai(t.slice(e,i+1)),oi(a,this.toBBox),a;s||(s=Math.ceil(Math.log(n)/Math.log(o)),o=Math.ceil(n/Math.pow(o,s-1))),a=ai([]),a.leaf=!1,a.height=s;const l=Math.ceil(n/o),h=l*Math.ceil(Math.sqrt(o));Xh(t,e,i,h,this.compareMinX);for(let u=e;u<=i;u+=h){const c=Math.min(u+h-1,i);Xh(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 oi(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=Po(h),c=ny(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),ji(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=ai(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,oi(i,this.toBBox),oi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=ai([t,e]),this.data.height=t.height+1,this.data.leaf=!1,oi(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=Wi(t,0,a,this.toBBox),h=Wi(t,a,i,this.toBBox),u=oy(l,h),c=Po(l)+Po(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:iy,n=t.leaf?this.compareMinY:sy,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=Wi(t,0,e,n),a=Wi(t,i-e,i,n);let l=Ns(o)+Ns(a);for(let h=e;h<i-e;h++){const u=t.children[h];ji(o,t.leaf?n(u):u),l+=Ns(o)}for(let h=i-e-1;h>=e;h--){const u=t.children[h];ji(a,t.leaf?n(u):u),l+=Ns(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)ji(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():oi(t[e],this.toBBox)}}function ry(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 oi(r,t){Wi(r,0,r.children.length,t,r)}function Wi(r,t,e,i,s){s||(s=ai(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];ji(s,r.leaf?i(o):o)}return s}function ji(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 iy(r,t){return r.minX-t.minX}function sy(r,t){return r.minY-t.minY}function Po(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Ns(r){return r.maxX-r.minX+(r.maxY-r.minY)}function ny(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 oy(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 Mo(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function Us(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function ai(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function Xh(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;Hh(r,o,t,e,s),n.push(t,o,o,e)}}const ay=()=>{const r=new ey,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},s=o=>{if(!Bs(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(!Bs(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===wt.RECTANGLE||rm(h.selector,o,a));if(l.length>0)return l.sort((h,u)=>vo(h.selector)-vo(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(Bs(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)}}},Vh=r=>{const t=Dm(),e=ay(),i=xm(t,r.userSelectAction,r.adapter),s=vm(t),n=Um();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}},ly=r=>{const t=Vh(r);return{...t,store:Om(t.store)}},hy=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},zh=r=>{const t=hy(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},Wh=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?zh(r):e),jh=(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}),Yh=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,qh=(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=()=>{Yh?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Yh?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},uy=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=jh(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:dh.EDIT,theme:"light"}),s=ly(i),{selection:n,store:o}=s,a=Nm(o,i.initialHistory),l=km(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=qh(a);let c=qm();Wh(e,h,i.theme);const d=new Qg({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:c}});d.$on("click",E=>{const{originalEvent:b,annotation:M}=E.detail;M?n.userSelect(M.id,b):n.isEmpty()||n.clear()});const p=$m(s,a,i.adapter),f=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),u.destroy(),a.destroy()},_=()=>d.getDrawingTool(),y=()=>c,x=()=>d.isDrawingEnabled(),g=(E,b,M)=>Ph(E,b,M),v=(E,b)=>Th(E,b),w=E=>{if(!Fs(E))throw`No drawing tool named ${E}`;d.$set({toolName:E})},C=E=>d.$set({drawingEnabled:E}),S=E=>{console.warn("Filter not implemented yet")},I=E=>d.$set({style:E}),L=E=>Wh(e,h,E),R=E=>{c=E,d.$set({user:E})},D=E=>d.$set({visible:E});return{...p,cancelDrawing:f,destroy:m,getDrawingTool:_,getUser:y,isDrawingEnabled:x,listDrawingTools:Ls,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:v,setDrawingEnabled:C,setDrawingTool:w,setFilter:S,setStyle:I,setTheme:L,setUser:R,setVisible:D,element:h,state:s}};function Be(){}function Bo(r,t){for(const e in t)r[e]=t[e];return r}function Kh(r){return r()}function Zh(){return Object.create(null)}function Qe(r){r.forEach(Kh)}function Kt(r){return typeof r=="function"}function te(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function cy(r){return Object.keys(r).length===0}function dy(r,...t){if(r==null){for(const i of t)i(void 0);return Be}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Do(r,t,e){r.$$.on_destroy.push(dy(t,e))}function Jh(r,t,e,i){if(r){const s=Qh(r,t,e,i);return r[0](s)}}function Qh(r,t,e,i){return r[1]&&i?Bo(e.ctx.slice(),r[1](i(t))):e.ctx}function tu(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 eu(r,t,e,i,s,n){if(s){const o=Qh(t,e,i,n);r.p(o,s)}}function ru(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 iu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ks(r){return r??""}const fy=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function tr(r,t){r.appendChild(t)}function dt(r,t,e){r.insertBefore(t,e||null)}function ht(r){r.parentNode&&r.parentNode.removeChild(r)}function Oo(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function Tt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Lo(r){return document.createTextNode(r)}function xe(){return Lo(" ")}function er(){return Lo("")}function zt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function P(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function py(r){return Array.from(r.childNodes)}function my(r,t){t=""+t,r.data!==t&&(r.data=t)}function Gs(r,t,e){r.classList.toggle(t,!!e)}function gy(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Yi;function qi(r){Yi=r}function Fo(){if(!Yi)throw new Error("Function called outside component initialization");return Yi}function $s(r){Fo().$$.on_mount.push(r)}function yy(r){Fo().$$.on_destroy.push(r)}function Hs(){const r=Fo();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=gy(t,e,{cancelable:i});return s.slice().forEach(o=>{o.call(r,n)}),!n.defaultPrevented}return!0}}function rr(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const li=[],Xs=[];let hi=[];const su=[],_y=Promise.resolve();let No=!1;function vy(){No||(No=!0,_y.then(nu))}function Uo(r){hi.push(r)}const ko=new Set;let ui=0;function nu(){if(ui!==0)return;const r=Yi;do{try{for(;ui<li.length;){const t=li[ui];ui++,qi(t),xy(t.$$)}}catch(t){throw li.length=0,ui=0,t}for(qi(null),li.length=0,ui=0;Xs.length;)Xs.pop()();for(let t=0;t<hi.length;t+=1){const e=hi[t];ko.has(e)||(ko.add(e),e())}hi.length=0}while(li.length);for(;su.length;)su.pop()();No=!1,ko.clear(),qi(r)}function xy(r){if(r.fragment!==null){r.update(),Qe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Uo)}}function by(r){const t=[],e=[];hi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),hi=t}const Vs=new Set;let Dr;function De(){Dr={r:0,c:[],p:Dr}}function Oe(){Dr.r||Qe(Dr.c),Dr=Dr.p}function nt(r,t){r&&r.i&&(Vs.delete(r),r.i(t))}function ut(r,t,e,i){if(r&&r.o){if(Vs.has(r))return;Vs.add(r),Dr.c.push(()=>{Vs.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function ci(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function ee(r){r&&r.c()}function Zt(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),Uo(()=>{const n=r.$$.on_mount.map(Kh).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...n):Qe(n),r.$$.on_mount=[]}),s.forEach(Uo)}function Jt(r,t){const e=r.$$;e.fragment!==null&&(by(e.after_update),Qe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function wy(r,t){r.$$.dirty[0]===-1&&(li.push(r),vy(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function oe(r,t,e,i,s,n,o=null,a=[-1]){const l=Yi;qi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Be,not_equal:s,bound:Zh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Zh(),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&&wy(r,c)),d}):[],h.update(),u=!0,Qe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const c=py(t.target);h.fragment&&h.fragment.l(c),c.forEach(ht)}else h.fragment&&h.fragment.c();t.intro&&nt(r.$$.fragment),Zt(r,t.target,t.anchor),nu()}qi(l)}class ae{constructor(){Hl(this,"$$");Hl(this,"$$set")}$destroy(){Jt(this,1),this.$destroy=Be}$on(t,e){if(!Kt(e))return Be;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&&!cy(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Ey="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Ey);var Or=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(Or||{}),ou=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(ou||{}),Go=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Go||{}),J=(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))(J||{}),Le=(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))(Le||{}),U=(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))(U||{}),di=(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))(di||{}),K=(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))(K||{}),z=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(z||{}),ir=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(ir||{}),gr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(gr||{}),Fe=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(Fe||{}),ie=(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))(ie||{}),Ne=(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))(Ne||{}),$o=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))($o||{}),fe=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(fe||{}),Lt=(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))(Lt||{}),Ot=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(Ot||{}),Ue=(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))(Ue||{});const W={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 Ho=/iPhone/i,au=/iPod/i,lu=/iPad/i,hu=/\biOS-universal(?:.+)Mac\b/i,Xo=/\bAndroid(?:.+)Mobile\b/i,uu=/Android/i,fi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,zs=/Silk/i,sr=/Windows Phone/i,cu=/\bWindows(?:.+)ARM\b/i,du=/BlackBerry/i,fu=/BB10/i,pu=/Opera Mini/i,mu=/\b(CriOS|Chrome)(?:.+)Mobile/i,gu=/Mobile(?:.+)Firefox\b/i,yu=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Ty(r){return function(t){return t.test(r)}}function _u(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=Ty(e),n={apple:{phone:s(Ho)&&!s(sr),ipod:s(au),tablet:!s(Ho)&&(s(lu)||yu(t))&&!s(sr),universal:s(hu),device:(s(Ho)||s(au)||s(lu)||s(hu)||yu(t))&&!s(sr)},amazon:{phone:s(fi),tablet:!s(fi)&&s(zs),device:s(fi)||s(zs)},android:{phone:!s(sr)&&s(fi)||!s(sr)&&s(Xo),tablet:!s(sr)&&!s(fi)&&!s(Xo)&&(s(zs)||s(uu)),device:!s(sr)&&(s(fi)||s(zs)||s(Xo)||s(uu))||s(/\bokhttp\b/i)},windows:{phone:s(sr),tablet:s(cu),device:s(sr)||s(cu)},other:{blackberry:s(du),blackberry10:s(fu),opera:s(pu),firefox:s(gu),chrome:s(mu),device:s(du)||s(fu)||s(pu)||s(gu)||s(mu)},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 Ay=_u.default??_u,nr=Ay(globalThis.navigator);W.RETINA_PREFIX=/@([0-9\.]+)x/,W.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Ki=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function vu(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Sy(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 xu={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 _=this._events[m],y=arguments.length,x,g;if(_.fn){switch(_.once&&this.removeListener(h,_.fn,void 0,!0),y){case 1:return _.fn.call(_.context),!0;case 2:return _.fn.call(_.context,u),!0;case 3:return _.fn.call(_.context,u,c),!0;case 4:return _.fn.call(_.context,u,c,d),!0;case 5:return _.fn.call(_.context,u,c,d,p),!0;case 6:return _.fn.call(_.context,u,c,d,p,f),!0}for(g=1,x=new Array(y-1);g<y;g++)x[g-1]=arguments[g];_.fn.apply(_.context,x)}else{var v=_.length,w;for(g=0;g<v;g++)switch(_[g].once&&this.removeListener(h,_[g].fn,void 0,!0),y){case 1:_[g].fn.call(_[g].context);break;case 2:_[g].fn.call(_[g].context,u);break;case 3:_[g].fn.call(_[g].context,u,c);break;case 4:_[g].fn.call(_[g].context,u,c,d);break;default:if(!x)for(w=1,x=new Array(y-1);w<y;w++)x[w-1]=arguments[w];_[g].fn.apply(_[g].context,x)}}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<y;m++)(f[m].fn!==u||d&&!f[m].once||c&&f[m].context!==c)&&_.push(f[m]);_.length?this._events[p]=_.length===1?_[0]:_: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})(xu);var Cy=xu.exports;const Zi=vu(Cy);var Vo={exports:{}};Vo.exports=Ws,Vo.exports.default=Ws;function Ws(r,t,e){e=e||2;var i=t&&t.length,s=i?t[0]*e:r.length,n=bu(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=By(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 Ji(n,o,e,a,l,p,0),o}function bu(r,t,e,i,s){var n,o;if(s===jo(r,t,e,i)>0)for(n=t;n<e;n+=i)o=Tu(n,r[n],r[n+1],o);else for(n=e-i;n>=t;n-=i)o=Tu(n,r[n],r[n+1],o);return o&&js(o,o.next)&&(ts(o),o=o.next),o}function Lr(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(js(e,e.next)||Ct(e.prev,e,e.next)===0)){if(ts(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Ji(r,t,e,i,s,n,o){if(r){!o&&n&&Ny(r,i,s,n);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,n?Ry(r,i,s,n):Iy(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),ts(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=Py(Lr(r),t,e),Ji(r,t,e,i,s,n,2)):o===2&&My(r,t,e,i,s,n):Ji(Lr(r),t,e,i,s,n,1);break}}}}function Iy(r){var t=r.prev,e=r,i=r.next;if(Ct(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&&pi(s,a,n,l,o,h,f.x,f.y)&&Ct(f.prev,f,f.next)>=0)return!1;f=f.next}return!0}function Ry(r,t,e,i){var s=r.prev,n=r,o=r.next;if(Ct(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,_=u>c?u>d?u:d:c>d?c:d,y=zo(p,f,t,e,i),x=zo(m,_,t,e,i),g=r.prevZ,v=r.nextZ;g&&g.z>=y&&v&&v.z<=x;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==s&&g!==o&&pi(a,u,l,c,h,d,g.x,g.y)&&Ct(g.prev,g,g.next)>=0||(g=g.prevZ,v.x>=p&&v.x<=m&&v.y>=f&&v.y<=_&&v!==s&&v!==o&&pi(a,u,l,c,h,d,v.x,v.y)&&Ct(v.prev,v,v.next)>=0))return!1;v=v.nextZ}for(;g&&g.z>=y;){if(g.x>=p&&g.x<=m&&g.y>=f&&g.y<=_&&g!==s&&g!==o&&pi(a,u,l,c,h,d,g.x,g.y)&&Ct(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;v&&v.z<=x;){if(v.x>=p&&v.x<=m&&v.y>=f&&v.y<=_&&v!==s&&v!==o&&pi(a,u,l,c,h,d,v.x,v.y)&&Ct(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function Py(r,t,e){var i=r;do{var s=i.prev,n=i.next.next;!js(s,n)&&wu(s,i,i.next,n)&&Qi(s,n)&&Qi(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),ts(i),ts(i.next),i=r=n),i=i.next}while(i!==r);return Lr(i)}function My(r,t,e,i,s,n){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&Gy(o,a)){var l=Eu(o,a);o=Lr(o,o.next),l=Lr(l,l.next),Ji(o,t,e,i,s,n,0),Ji(l,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function By(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=bu(r,a,l,i,!1),h===h.next&&(h.steiner=!0),s.push(ky(h));for(s.sort(Dy),n=0;n<s.length;n++)e=Oy(s[n],e);return e}function Dy(r,t){return r.x-t.x}function Oy(r,t){var e=Ly(r,t);if(!e)return t;var i=Eu(e,r);return Lr(i,i.next),Lr(e,e.next)}function Ly(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&&pi(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),Qi(e,r)&&(d<c||d===c&&(e.x>o.x||e.x===o.x&&Fy(o,e)))&&(o=e,c=d)),e=e.next;while(e!==l);return o}function Fy(r,t){return Ct(r.prev,r,t.prev)<0&&Ct(t.next,r,r.next)<0}function Ny(r,t,e,i){var s=r;do s.z===0&&(s.z=zo(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,Uy(s)}function Uy(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 zo(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 ky(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 pi(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 Gy(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!$y(r,t)&&(Qi(r,t)&&Qi(t,r)&&Hy(r,t)&&(Ct(r.prev,r,t.prev)||Ct(r,t.prev,t))||js(r,t)&&Ct(r.prev,r,r.next)>0&&Ct(t.prev,t,t.next)>0)}function Ct(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function js(r,t){return r.x===t.x&&r.y===t.y}function wu(r,t,e,i){var s=qs(Ct(r,t,e)),n=qs(Ct(r,t,i)),o=qs(Ct(e,i,r)),a=qs(Ct(e,i,t));return!!(s!==n&&o!==a||s===0&&Ys(r,e,t)||n===0&&Ys(r,i,t)||o===0&&Ys(e,r,i)||a===0&&Ys(e,t,i))}function Ys(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 qs(r){return r>0?1:r<0?-1:0}function $y(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&&wu(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Qi(r,t){return Ct(r.prev,r,r.next)<0?Ct(r,t,r.next)>=0&&Ct(r,r.prev,t)>=0:Ct(r,t,r.prev)<0||Ct(r,r.next,t)<0}function Hy(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 Eu(r,t){var e=new Wo(r.i,r.x,r.y),i=new Wo(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 Tu(r,t,e,i){var s=new Wo(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 ts(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 Wo(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}Ws.deviation=function(r,t,e,i){var s=t&&t.length,n=s?t[0]*e:r.length,o=Math.abs(jo(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(jo(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 jo(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}Ws.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 Xy=Vo.exports;const Vy=vu(Xy);var Ks={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Ks.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,s=!r.nodeType&&r,n=typeof Ki=="object"&&Ki;(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="-",_=/^xn--/,y=/[^\x20-\x7E]/,x=/[\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"},v=l-h,w=Math.floor,C=String.fromCharCode,S;function I(A){throw new RangeError(g[A])}function L(A,F){for(var G=A.length,Q=[];G--;)Q[G]=F(A[G]);return Q}function R(A,F){var G=A.split("@"),Q="";G.length>1&&(Q=G[0]+"@",A=G[1]),A=A.replace(x,".");var Z=A.split("."),H=L(Z,F).join(".");return Q+H}function D(A){for(var F=[],G=0,Q=A.length,Z,H;G<Q;)Z=A.charCodeAt(G++),Z>=55296&&Z<=56319&&G<Q?(H=A.charCodeAt(G++),(H&64512)==56320?F.push(((Z&1023)<<10)+(H&1023)+65536):(F.push(Z),G--)):F.push(Z);return F}function E(A){return L(A,function(F){var G="";return F>65535&&(F-=65536,G+=C(F>>>10&1023|55296),F=56320|F&1023),G+=C(F),G}).join("")}function b(A){return A-48<10?A-22:A-65<26?A-65:A-97<26?A-97:l}function M(A,F){return A+22+75*(A<26)-((F!=0)<<5)}function N(A,F,G){var Q=0;for(A=G?w(A/d):A>>1,A+=w(A/F);A>v*u>>1;Q+=l)A=w(A/v);return w(Q+(v+1)*A/(A+c))}function $(A){var F=[],G=A.length,Q,Z=0,H=f,ft=p,bt,B,O,et,tt,yt,_t,Ye,qe;for(bt=A.lastIndexOf(m),bt<0&&(bt=0),B=0;B<bt;++B)A.charCodeAt(B)>=128&&I("not-basic"),F.push(A.charCodeAt(B));for(O=bt>0?bt+1:0;O<G;){for(et=Z,tt=1,yt=l;O>=G&&I("invalid-input"),_t=b(A.charCodeAt(O++)),(_t>=l||_t>w((a-Z)/tt))&&I("overflow"),Z+=_t*tt,Ye=yt<=ft?h:yt>=ft+u?u:yt-ft,!(_t<Ye);yt+=l)qe=l-Ye,tt>w(a/qe)&&I("overflow"),tt*=qe;Q=F.length+1,ft=N(Z-et,Q,et==0),w(Z/Q)>a-H&&I("overflow"),H+=w(Z/Q),Z%=Q,F.splice(Z++,0,H)}return E(F)}function k(A){var F,G,Q,Z,H,ft,bt,B,O,et,tt,yt=[],_t,Ye,qe,ws;for(A=D(A),_t=A.length,F=f,G=0,H=p,ft=0;ft<_t;++ft)tt=A[ft],tt<128&&yt.push(C(tt));for(Q=Z=yt.length,Z&&yt.push(m);Q<_t;){for(bt=a,ft=0;ft<_t;++ft)tt=A[ft],tt>=F&&tt<bt&&(bt=tt);for(Ye=Q+1,bt-F>w((a-G)/Ye)&&I("overflow"),G+=(bt-F)*Ye,F=bt,ft=0;ft<_t;++ft)if(tt=A[ft],tt<F&&++G>a&&I("overflow"),tt==F){for(B=G,O=l;et=O<=H?h:O>=H+u?u:O-H,!(B<et);O+=l)ws=B-et,qe=l-et,yt.push(C(M(et+ws%qe,0))),B=w(ws/qe);yt.push(C(M(B,0))),H=N(G,Ye,Q==Z),G=0,++Q}++G,++F}return yt.join("")}function X(A){return R(A,function(F){return _.test(F)?$(F.slice(4).toLowerCase()):F})}function it(A){return R(A,function(F){return y.test(F)?"xn--"+k(F):F})}if(o={version:"1.4.1",ucs2:{decode:D,encode:E},decode:$,encode:k,toASCII:it,toUnicode:X},i&&s)if(r.exports==i)s.exports=o;else for(S in o)o.hasOwnProperty(S)&&(i[S]=o[S]);else e.punycode=o})(Ki)}(Ks,Ks.exports);var zy=Ks.exports,mi=TypeError;const Wy=Sy(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Yo=typeof Map=="function"&&Map.prototype,qo=Object.getOwnPropertyDescriptor&&Yo?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Zs=Yo&&qo&&typeof qo.get=="function"?qo.get:null,Au=Yo&&Map.prototype.forEach,Ko=typeof Set=="function"&&Set.prototype,Zo=Object.getOwnPropertyDescriptor&&Ko?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Js=Ko&&Zo&&typeof Zo.get=="function"?Zo.get:null,Su=Ko&&Set.prototype.forEach,jy=typeof WeakMap=="function"&&WeakMap.prototype,es=jy?WeakMap.prototype.has:null,Yy=typeof WeakSet=="function"&&WeakSet.prototype,rs=Yy?WeakSet.prototype.has:null,qy=typeof WeakRef=="function"&&WeakRef.prototype,Cu=qy?WeakRef.prototype.deref:null,Ky=Boolean.prototype.valueOf,Zy=Object.prototype.toString,Jy=Function.prototype.toString,Qy=String.prototype.match,Jo=String.prototype.slice,yr=String.prototype.replace,t_=String.prototype.toUpperCase,Iu=String.prototype.toLowerCase,Ru=RegExp.prototype.test,Pu=Array.prototype.concat,ke=Array.prototype.join,e_=Array.prototype.slice,Mu=Math.floor,Qo=typeof BigInt=="function"?BigInt.prototype.valueOf:null,ta=Object.getOwnPropertySymbols,ea=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,gi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Qt=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===gi||!0)?Symbol.toStringTag:null,Bu=Object.prototype.propertyIsEnumerable,Du=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Ou(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Ru.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Mu(-r):Mu(r);if(i!==r){var s=String(i),n=Jo.call(t,s.length+1);return yr.call(s,e,"$&_")+"."+yr.call(yr.call(n,/([0-9]{3})/g,"$&_"),/_$/,"")}}return yr.call(t,e,"$&_")}var ra=Wy,Lu=ra.custom,Fu=Gu(Lu)?Lu:null,Nu={__proto__:null,double:'"',single:"'"},r_={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Qs=function r(t,e,i,s){var n=e||{};if(or(n,"quoteStyle")&&!or(Nu,n.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(or(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=or(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(or(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(or(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 Hu(t,n);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Ou(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Ou(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 ia(t)?"[Array]":"[Object]";var c=x_(n,i);if(typeof s>"u")s=[];else if($u(s,t)>=0)return"[Circular]";function d(b,M,N){if(M&&(s=e_.call(s),s.push(M)),N){var $={depth:n.depth};return or(n,"quoteStyle")&&($.quoteStyle=n.quoteStyle),r(b,$,i+1,s)}return r(b,n,i+1,s)}if(typeof t=="function"&&!ku(t)){var p=c_(t),f=tn(t,d);return"[Function"+(p?": "+p:" (anonymous)")+"]"+(f.length>0?" { "+ke.call(f,", ")+" }":"")}if(Gu(t)){var m=gi?yr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):ea.call(t);return typeof t=="object"&&!gi?is(m):m}if(y_(t)){for(var _="<"+Iu.call(String(t.nodeName)),y=t.attributes||[],x=0;x<y.length;x++)_+=" "+y[x].name+"="+Uu(i_(y[x].value),"double",n);return _+=">",t.childNodes&&t.childNodes.length&&(_+="..."),_+="</"+Iu.call(String(t.nodeName))+">",_}if(ia(t)){if(t.length===0)return"[]";var g=tn(t,d);return c&&!v_(g)?"["+na(g,c)+"]":"[ "+ke.call(g,", ")+" ]"}if(n_(t)){var v=tn(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Bu.call(t,"cause")?"{ ["+String(t)+"] "+ke.call(Pu.call("[cause]: "+d(t.cause),v),", ")+" }":v.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+ke.call(v,", ")+" }"}if(typeof t=="object"&&o){if(Fu&&typeof t[Fu]=="function"&&ra)return ra(t,{depth:u-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(d_(t)){var w=[];return Au&&Au.call(t,function(b,M){w.push(d(M,t,!0)+" => "+d(b,t))}),Xu("Map",Zs.call(t),w,c)}if(m_(t)){var C=[];return Su&&Su.call(t,function(b){C.push(d(b,t))}),Xu("Set",Js.call(t),C,c)}if(f_(t))return sa("WeakMap");if(g_(t))return sa("WeakSet");if(p_(t))return sa("WeakRef");if(a_(t))return is(d(Number(t)));if(h_(t))return is(d(Qo.call(t)));if(l_(t))return is(Ky.call(t));if(o_(t))return is(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Ki<"u"&&t===Ki)return"{ [object globalThis] }";if(!s_(t)&&!ku(t)){var S=tn(t,d),I=Du?Du(t)===Object.prototype:t instanceof Object||t.constructor===Object,L=t instanceof Object?"":"null prototype",R=!I&&Qt&&Object(t)===t&&Qt in t?Jo.call(_r(t),8,-1):L?"Object":"",D=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",E=D+(R||L?"["+ke.call(Pu.call([],R||[],L||[]),": ")+"] ":"");return S.length===0?E+"{}":c?E+"{"+na(S,c)+"}":E+"{ "+ke.call(S,", ")+" }"}return String(t)};function Uu(r,t,e){var i=e.quoteStyle||t,s=Nu[i];return s+r+s}function i_(r){return yr.call(String(r),/"/g,"&quot;")}function ia(r){return _r(r)==="[object Array]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function s_(r){return _r(r)==="[object Date]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function ku(r){return _r(r)==="[object RegExp]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function n_(r){return _r(r)==="[object Error]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function o_(r){return _r(r)==="[object String]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function a_(r){return _r(r)==="[object Number]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function l_(r){return _r(r)==="[object Boolean]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function Gu(r){if(gi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!ea)return!1;try{return ea.call(r),!0}catch{}return!1}function h_(r){if(!r||typeof r!="object"||!Qo)return!1;try{return Qo.call(r),!0}catch{}return!1}var u_=Object.prototype.hasOwnProperty||function(r){return r in this};function or(r,t){return u_.call(r,t)}function _r(r){return Zy.call(r)}function c_(r){if(r.name)return r.name;var t=Qy.call(Jy.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function $u(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 d_(r){if(!Zs||!r||typeof r!="object")return!1;try{Zs.call(r);try{Js.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function f_(r){if(!es||!r||typeof r!="object")return!1;try{es.call(r,es);try{rs.call(r,rs)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function p_(r){if(!Cu||!r||typeof r!="object")return!1;try{return Cu.call(r),!0}catch{}return!1}function m_(r){if(!Js||!r||typeof r!="object")return!1;try{Js.call(r);try{Zs.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function g_(r){if(!rs||!r||typeof r!="object")return!1;try{rs.call(r,rs);try{es.call(r,es)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function y_(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Hu(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Hu(Jo.call(r,0,t.maxStringLength),t)+i}var s=r_[t.quoteStyle||"single"];s.lastIndex=0;var n=yr.call(yr.call(r,s,"\\$1"),/[\x00-\x1f]/g,__);return Uu(n,"single",t)}function __(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":"")+t_.call(t.toString(16))}function is(r){return"Object("+r+")"}function sa(r){return r+" { ? }"}function Xu(r,t,e,i){var s=i?na(e,i):ke.call(e,", ");return r+" ("+t+") {"+s+"}"}function v_(r){for(var t=0;t<r.length;t++)if($u(r[t],`
2
2
  `)>=0)return!1;return!0}function x_(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=ke.call(Array(r.indent+1)," ");else return null;return{base:e,prev:ke.call(Array(t+1),e)}}function na(r,t){if(r.length===0)return"";var e=`
3
3
  `+t.prev+t.base;return e+ke.call(r,","+e)+`
4
4
  `+t.prev}function tn(r,t){var e=ia(r),i=[];if(e){i.length=r.length;for(var s=0;s<r.length;s++)i[s]=or(r,s)?t(r[s],r):""}var n=typeof ta=="function"?ta(r):[],o;if(gi){o={};for(var a=0;a<n.length;a++)o["$"+n[a]]=n[a]}for(var l in r)or(r,l)&&(e&&String(Number(l))===l&&l<r.length||gi&&o["$"+l]instanceof Symbol||(Ru.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof ta=="function")for(var h=0;h<n.length;h++)Bu.call(r,n[h])&&i.push("["+t(n[h])+"]: "+t(r[n[h]],r));return i}var b_=Qs,w_=mi,en=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},E_=function(r,t){if(r){var e=en(r,t);return e&&e.value}},T_=function(r,t,e){var i=en(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},A_=function(r,t){return r?!!en(r,t):!1},S_=function(r,t){if(r)return en(r,t,!0)},C_=function(){var t,e={assert:function(i){if(!e.has(i))throw new w_("Side channel does not contain "+b_(i))},delete:function(i){var s=t&&t.next,n=S_(t,i);return n&&s&&s===n&&(t=void 0),!!n},get:function(i){return E_(t,i)},has:function(i){return A_(t,i)},set:function(i,s){t||(t={next:void 0}),T_(t,i,s)}};return e},Vu=Object,I_=Error,R_=EvalError,P_=RangeError,M_=ReferenceError,B_=SyntaxError,D_=URIError,O_=Math.abs,L_=Math.floor,F_=Math.max,N_=Math.min,U_=Math.pow,k_=Math.round,G_=Number.isNaN||function(t){return t!==t},$_=G_,H_=function(t){return $_(t)||t===0?t:t<0?-1:1},X_=Object.getOwnPropertyDescriptor,rn=X_;if(rn)try{rn([],"length")}catch{rn=null}var zu=rn,sn=Object.defineProperty||!1;if(sn)try{sn({},"a",{value:1})}catch{sn=!1}var V_=sn,oa,Wu;function z_(){return Wu||(Wu=1,oa=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}),oa}var aa,ju;function W_(){if(ju)return aa;ju=1;var r=typeof Symbol<"u"&&Symbol,t=z_();return aa=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},aa}var la,Yu;function qu(){return Yu||(Yu=1,la=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),la}var ha,Ku;function Zu(){if(Ku)return ha;Ku=1;var r=Vu;return ha=r.getPrototypeOf||null,ha}var ua,Ju;function j_(){if(Ju)return ua;Ju=1;var r="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,e=Math.max,i="[object Function]",s=function(l,h){for(var u=[],c=0;c<l.length;c+=1)u[c]=l[c];for(var d=0;d<h.length;d+=1)u[d+l.length]=h[d];return u},n=function(l,h){for(var u=[],c=h,d=0;c<l.length;c+=1,d+=1)u[d]=l[c];return u},o=function(a,l){for(var h="",u=0;u<a.length;u+=1)h+=a[u],u+1<a.length&&(h+=l);return h};return ua=function(l){var h=this;if(typeof h!="function"||t.apply(h)!==i)throw new TypeError(r+h);for(var u=n(arguments,1),c,d=function(){if(this instanceof c){var y=h.apply(this,s(u,arguments));return Object(y)===y?y:this}return h.apply(l,s(u,arguments))},p=e(0,h.length-u.length),f=[],m=0;m<p;m++)f[m]="$"+m;if(c=Function("binder","return function ("+o(f,",")+"){ return binder.apply(this,arguments); }")(d),h.prototype){var _=function(){};_.prototype=h.prototype,c.prototype=new _,_.prototype=null}return c},ua}var ca,Qu;function nn(){if(Qu)return ca;Qu=1;var r=j_();return ca=Function.prototype.bind||r,ca}var da,tc;function fa(){return tc||(tc=1,da=Function.prototype.call),da}var pa,ec;function rc(){return ec||(ec=1,pa=Function.prototype.apply),pa}var Y_=typeof Reflect<"u"&&Reflect&&Reflect.apply,q_=nn(),K_=rc(),Z_=fa(),J_=Y_,Q_=J_||q_.call(Z_,K_),t0=nn(),e0=mi,r0=fa(),i0=Q_,ic=function(t){if(t.length<1||typeof t[0]!="function")throw new e0("a function is required");return i0(t0,r0,t)},ma,sc;function s0(){if(sc)return ma;sc=1;var r=ic,t=zu,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 ma=i&&typeof i.get=="function"?r([i.get]):typeof n=="function"?function(a){return n(a==null?a:s(a))}:!1,ma}var ga,nc;function n0(){if(nc)return ga;nc=1;var r=qu(),t=Zu(),e=s0();return ga=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,ga}var ya,oc;function o0(){if(oc)return ya;oc=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=nn();return ya=e.call(r,t),ya}var mt,a0=Vu,l0=I_,h0=R_,u0=P_,c0=M_,yi=B_,_i=mi,d0=D_,f0=O_,p0=L_,m0=F_,g0=N_,y0=U_,_0=k_,v0=H_,ac=Function,_a=function(r){try{return ac('"use strict"; return ('+r+").constructor;")()}catch{}},ss=zu,x0=V_,va=function(){throw new _i},b0=ss?function(){try{return arguments.callee,va}catch{try{return ss(arguments,"callee").get}catch{return va}}}():va,vi=W_()(),kt=n0(),w0=Zu(),E0=qu(),lc=rc(),ns=fa(),xi={},T0=typeof Uint8Array>"u"||!kt?mt:kt(Uint8Array),Fr={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?mt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?mt:ArrayBuffer,"%ArrayIteratorPrototype%":vi&&kt?kt([][Symbol.iterator]()):mt,"%AsyncFromSyncIteratorPrototype%":mt,"%AsyncFunction%":xi,"%AsyncGenerator%":xi,"%AsyncGeneratorFunction%":xi,"%AsyncIteratorPrototype%":xi,"%Atomics%":typeof Atomics>"u"?mt:Atomics,"%BigInt%":typeof BigInt>"u"?mt:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?mt:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?mt:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?mt:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":l0,"%eval%":eval,"%EvalError%":h0,"%Float32Array%":typeof Float32Array>"u"?mt:Float32Array,"%Float64Array%":typeof Float64Array>"u"?mt:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?mt:FinalizationRegistry,"%Function%":ac,"%GeneratorFunction%":xi,"%Int8Array%":typeof Int8Array>"u"?mt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?mt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?mt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":vi&&kt?kt(kt([][Symbol.iterator]())):mt,"%JSON%":typeof JSON=="object"?JSON:mt,"%Map%":typeof Map>"u"?mt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!vi||!kt?mt:kt(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":a0,"%Object.getOwnPropertyDescriptor%":ss,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?mt:Promise,"%Proxy%":typeof Proxy>"u"?mt:Proxy,"%RangeError%":u0,"%ReferenceError%":c0,"%Reflect%":typeof Reflect>"u"?mt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?mt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!vi||!kt?mt:kt(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?mt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":vi&&kt?kt(""[Symbol.iterator]()):mt,"%Symbol%":vi?Symbol:mt,"%SyntaxError%":yi,"%ThrowTypeError%":b0,"%TypedArray%":T0,"%TypeError%":_i,"%Uint8Array%":typeof Uint8Array>"u"?mt:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?mt:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?mt:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?mt:Uint32Array,"%URIError%":d0,"%WeakMap%":typeof WeakMap>"u"?mt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?mt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?mt:WeakSet,"%Function.prototype.call%":ns,"%Function.prototype.apply%":lc,"%Object.defineProperty%":x0,"%Object.getPrototypeOf%":w0,"%Math.abs%":f0,"%Math.floor%":p0,"%Math.max%":m0,"%Math.min%":g0,"%Math.pow%":y0,"%Math.round%":_0,"%Math.sign%":v0,"%Reflect.getPrototypeOf%":E0};if(kt)try{null.error}catch(r){var A0=kt(kt(r));Fr["%Error.prototype%"]=A0}var S0=function r(t){var e;if(t==="%AsyncFunction%")e=_a("async function () {}");else if(t==="%GeneratorFunction%")e=_a("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=_a("async function* () {}");else if(t==="%AsyncGenerator%"){var i=r("%AsyncGeneratorFunction%");i&&(e=i.prototype)}else if(t==="%AsyncIteratorPrototype%"){var s=r("%AsyncGenerator%");s&&kt&&(e=kt(s.prototype))}return Fr[t]=e,e},hc={__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"]},os=nn(),on=o0(),C0=os.call(ns,Array.prototype.concat),I0=os.call(lc,Array.prototype.splice),uc=os.call(ns,String.prototype.replace),an=os.call(ns,String.prototype.slice),R0=os.call(ns,RegExp.prototype.exec),P0=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,M0=/\\(\\)?/g,B0=function(t){var e=an(t,0,1),i=an(t,-1);if(e==="%"&&i!=="%")throw new yi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new yi("invalid intrinsic syntax, expected opening `%`");var s=[];return uc(t,P0,function(n,o,a,l){s[s.length]=a?uc(l,M0,"$1"):o||n}),s},D0=function(t,e){var i=t,s;if(on(hc,i)&&(s=hc[i],i="%"+s[0]+"%"),on(Fr,i)){var n=Fr[i];if(n===xi&&(n=S0(i)),typeof n>"u"&&!e)throw new _i("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:s,name:i,value:n}}throw new yi("intrinsic "+t+" does not exist!")},xa=function(t,e){if(typeof t!="string"||t.length===0)throw new _i("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new _i('"allowMissing" argument must be a boolean');if(R0(/^%?[^%]*%?$/,t)===null)throw new yi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=B0(t),s=i.length>0?i[0]:"",n=D0("%"+s+"%",e),o=n.name,a=n.value,l=!1,h=n.alias;h&&(s=h[0],I0(i,C0([0,1],h)));for(var u=1,c=!0;u<i.length;u+=1){var d=i[u],p=an(d,0,1),f=an(d,-1);if((p==='"'||p==="'"||p==="`"||f==='"'||f==="'"||f==="`")&&p!==f)throw new yi("property names with quotes must have matching quotes");if((d==="constructor"||!c)&&(l=!0),s+="."+d,o="%"+s+"%",on(Fr,o))a=Fr[o];else if(a!=null){if(!(d in a)){if(!e)throw new _i("base intrinsic for "+t+" exists, but the property is not available.");return}if(ss&&u+1>=i.length){var m=ss(a,d);c=!!m,c&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else c=on(a,d),a=a[d];c&&!l&&(Fr[o]=a)}}return a},cc=xa,dc=ic,O0=dc([cc("%String.prototype.indexOf%")]),fc=function(t,e){var i=cc(t,!!e);return typeof i=="function"&&O0(t,".prototype.")>-1?dc([i]):i},L0=xa,as=fc,F0=Qs,N0=mi,pc=L0("%Map%",!0),U0=as("Map.prototype.get",!0),k0=as("Map.prototype.set",!0),G0=as("Map.prototype.has",!0),$0=as("Map.prototype.delete",!0),H0=as("Map.prototype.size",!0),mc=!!pc&&function(){var t,e={assert:function(i){if(!e.has(i))throw new N0("Side channel does not contain "+F0(i))},delete:function(i){if(t){var s=$0(t,i);return H0(t)===0&&(t=void 0),s}return!1},get:function(i){if(t)return U0(t,i)},has:function(i){return t?G0(t,i):!1},set:function(i,s){t||(t=new pc),k0(t,i,s)}};return e},X0=xa,ln=fc,V0=Qs,hn=mc,z0=mi,bi=X0("%WeakMap%",!0),W0=ln("WeakMap.prototype.get",!0),j0=ln("WeakMap.prototype.set",!0),Y0=ln("WeakMap.prototype.has",!0),q0=ln("WeakMap.prototype.delete",!0),K0=bi?function(){var t,e,i={assert:function(s){if(!i.has(s))throw new z0("Side channel does not contain "+V0(s))},delete:function(s){if(bi&&s&&(typeof s=="object"||typeof s=="function")){if(t)return q0(t,s)}else if(hn&&e)return e.delete(s);return!1},get:function(s){return bi&&s&&(typeof s=="object"||typeof s=="function")&&t?W0(t,s):e&&e.get(s)},has:function(s){return bi&&s&&(typeof s=="object"||typeof s=="function")&&t?Y0(t,s):!!e&&e.has(s)},set:function(s,n){bi&&s&&(typeof s=="object"||typeof s=="function")?(t||(t=new bi),j0(t,s,n)):hn&&(e||(e=hn()),e.set(s,n))}};return i}:hn,Z0=mi,J0=Qs,Q0=C_,tv=mc,ev=K0,rv=ev||tv||Q0,iv=function(){var t,e={assert:function(i){if(!e.has(i))throw new Z0("Side channel does not contain "+J0(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=rv()),t.set(i,s)}};return e},sv=String.prototype.replace,nv=/%20/g,ba={RFC1738:"RFC1738",RFC3986:"RFC3986"},wa={default:ba.RFC3986,formatters:{RFC1738:function(r){return sv.call(r,nv,"+")},RFC3986:function(r){return String(r)}},RFC1738:ba.RFC1738,RFC3986:ba.RFC3986},ov=wa,Ea=Object.prototype.hasOwnProperty,Nr=Array.isArray,Ge=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),av=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(Nr(i)){for(var s=[],n=0;n<i.length;++n)typeof i[n]<"u"&&s.push(i[n]);e.obj[e.prop]=s}}},gc=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},lv=function r(t,e,i){if(!e)return t;if(typeof e!="object"&&typeof e!="function"){if(Nr(t))t.push(e);else if(t&&typeof t=="object")(i&&(i.plainObjects||i.allowPrototypes)||!Ea.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 Nr(t)&&!Nr(e)&&(s=gc(t,i)),Nr(t)&&Nr(e)?(e.forEach(function(n,o){if(Ea.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 Ea.call(n,o)?n[o]=r(n[o],a,i):n[o]=a,n},s)},hv=function(t,e){return Object.keys(e).reduce(function(i,s){return i[s]=e[s],i},t)},uv=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}},Ta=1024,cv=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+=Ta){for(var h=o.length>=Ta?o.slice(l,l+Ta):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===ov.RFC1738&&(d===40||d===41)){u[u.length]=h.charAt(c);continue}if(d<128){u[u.length]=Ge[d];continue}if(d<2048){u[u.length]=Ge[192|d>>6]+Ge[128|d&63];continue}if(d<55296||d>=57344){u[u.length]=Ge[224|d>>12]+Ge[128|d>>6&63]+Ge[128|d&63];continue}c+=1,d=65536+((d&1023)<<10|h.charCodeAt(c)&1023),u[u.length]=Ge[240|d>>18]+Ge[128|d>>12&63]+Ge[128|d>>6&63]+Ge[128|d&63]}a+=u.join("")}return a},dv=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 av(e),t},fv=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},pv=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},mv=function(t,e){return[].concat(t,e)},gv=function(t,e){if(Nr(t)){for(var i=[],s=0;s<t.length;s+=1)i.push(e(t[s]));return i}return e(t)},yc={arrayToObject:gc,assign:hv,combine:mv,compact:dv,decode:uv,encode:cv,isBuffer:pv,isRegExp:fv,maybeMap:gv,merge:lv},_c=iv,un=yc,ls=wa,yv=Object.prototype.hasOwnProperty,vc={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},$e=Array.isArray,_v=Array.prototype.push,xc=function(r,t){_v.apply(r,$e(t)?t:[t])},vv=Date.prototype.toISOString,bc=ls.default,Ft={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:bc,formatter:ls.formatters[bc],indices:!1,serializeDate:function(t){return vv.call(t)},skipNulls:!1,strictNullHandling:!1},xv=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},Aa={},bv=function r(t,e,i,s,n,o,a,l,h,u,c,d,p,f,m,_,y,x){for(var g=t,v=x,w=0,C=!1;(v=v.get(Aa))!==void 0&&!C;){var S=v.get(t);if(w+=1,typeof S<"u"){if(S===w)throw new RangeError("Cyclic object value");C=!0}typeof v.get(Aa)>"u"&&(w=0)}if(typeof u=="function"?g=u(e,g):g instanceof Date?g=p(g):i==="comma"&&$e(g)&&(g=un.maybeMap(g,function(A){return A instanceof Date?p(A):A})),g===null){if(o)return h&&!_?h(e,Ft.encoder,y,"key",f):e;g=""}if(xv(g)||un.isBuffer(g)){if(h){var I=_?e:h(e,Ft.encoder,y,"key",f);return[m(I)+"="+m(h(g,Ft.encoder,y,"value",f))]}return[m(e)+"="+m(String(g))]}var L=[];if(typeof g>"u")return L;var R;if(i==="comma"&&$e(g))_&&h&&(g=un.maybeMap(g,h)),R=[{value:g.length>0?g.join(",")||null:void 0}];else if($e(u))R=u;else{var D=Object.keys(g);R=c?D.sort(c):D}var E=l?String(e).replace(/\./g,"%2E"):String(e),b=s&&$e(g)&&g.length===1?E+"[]":E;if(n&&$e(g)&&g.length===0)return b+"[]";for(var M=0;M<R.length;++M){var N=R[M],$=typeof N=="object"&&N&&typeof N.value<"u"?N.value:g[N];if(!(a&&$===null)){var k=d&&l?String(N).replace(/\./g,"%2E"):String(N),X=$e(g)?typeof i=="function"?i(b,k):b:b+(d?"."+k:"["+k+"]");x.set(t,w);var it=_c();it.set(Aa,x),xc(L,r($,X,i,s,n,o,a,l,i==="comma"&&_&&$e(g)?null:h,u,c,d,p,f,m,_,y,it))}}return L},wv=function(t){if(!t)return Ft;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||Ft.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(!yv.call(ls.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var s=ls.formatters[i],n=Ft.filter;(typeof t.filter=="function"||$e(t.filter))&&(n=t.filter);var o;if(t.arrayFormat in vc?o=t.arrayFormat:"indices"in t?o=t.indices?"indices":"repeat":o=Ft.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:Ft.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:Ft.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Ft.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Ft.charsetSentinel,commaRoundTrip:!!t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?Ft.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:Ft.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:Ft.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:Ft.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:Ft.encodeValuesOnly,filter:n,format:i,formatter:s,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:Ft.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:Ft.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Ft.strictNullHandling}},Ev=function(r,t){var e=r,i=wv(t),s,n;typeof i.filter=="function"?(n=i.filter,e=n("",e)):$e(i.filter)&&(n=i.filter,s=n);var o=[];if(typeof e!="object"||e===null)return"";var a=vc[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;s||(s=Object.keys(e)),i.sort&&s.sort(i.sort);for(var h=_c(),u=0;u<s.length;++u){var c=s[u],d=e[c];i.skipNulls&&d===null||xc(o,bv(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:""},Ur=yc,Sa=Object.prototype.hasOwnProperty,wc=Array.isArray,Pt={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:Ur.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1,throwOnLimitExceeded:!1},Tv=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},Ec=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},Av="utf8=%26%2310003%3B",Sv="utf8=%E2%9C%93",Cv=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]===Sv?h="utf-8":o[l]===Av&&(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,Pt.decoder,h,"key"),f=e.strictNullHandling?null:""):(p=e.decoder(u.slice(0,d),Pt.decoder,h,"key"),f=Ur.maybeMap(Ec(u.slice(d+1),e,wc(i[p])?i[p].length:0),function(_){return e.decoder(_,Pt.decoder,h,"value")})),f&&e.interpretNumericEntities&&h==="iso-8859-1"&&(f=Tv(String(f))),u.indexOf("[]=")>-1&&(f=wc(f)?[f]:f);var m=Sa.call(i,p);m&&e.duplicates==="combine"?i[p]=Ur.combine(i[p],f):(!m||e.duplicates==="last")&&(i[p]=f)}return i},Iv=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:Ec(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)?[]:Ur.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},Rv=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&&Sa.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&&Sa.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 Iv(u,e,i,s)}},Pv=function(t){if(!t)return Pt;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"?Pt.charset:t.charset,i=typeof t.duplicates>"u"?Pt.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:Pt.allowDots:!!t.allowDots;return{allowDots:s,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Pt.allowEmptyArrays,allowPrototypes:typeof t.allowPrototypes=="boolean"?t.allowPrototypes:Pt.allowPrototypes,allowSparse:typeof t.allowSparse=="boolean"?t.allowSparse:Pt.allowSparse,arrayLimit:typeof t.arrayLimit=="number"?t.arrayLimit:Pt.arrayLimit,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Pt.charsetSentinel,comma:typeof t.comma=="boolean"?t.comma:Pt.comma,decodeDotInKeys:typeof t.decodeDotInKeys=="boolean"?t.decodeDotInKeys:Pt.decodeDotInKeys,decoder:typeof t.decoder=="function"?t.decoder:Pt.decoder,delimiter:typeof t.delimiter=="string"||Ur.isRegExp(t.delimiter)?t.delimiter:Pt.delimiter,depth:typeof t.depth=="number"||t.depth===!1?+t.depth:Pt.depth,duplicates:i,ignoreQueryPrefix:t.ignoreQueryPrefix===!0,interpretNumericEntities:typeof t.interpretNumericEntities=="boolean"?t.interpretNumericEntities:Pt.interpretNumericEntities,parameterLimit:typeof t.parameterLimit=="number"?t.parameterLimit:Pt.parameterLimit,parseArrays:t.parseArrays!==!1,plainObjects:typeof t.plainObjects=="boolean"?t.plainObjects:Pt.plainObjects,strictDepth:typeof t.strictDepth=="boolean"?!!t.strictDepth:Pt.strictDepth,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Pt.strictNullHandling,throwOnLimitExceeded:typeof t.throwOnLimitExceeded=="boolean"?t.throwOnLimitExceeded:!1}},Mv=function(r,t){var e=Pv(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?Cv(r,e):r,s=e.plainObjects?{__proto__:null}:{},n=Object.keys(i),o=0;o<n.length;++o){var a=n[o],l=Rv(a,i[a],e,typeof r=="string");s=Ur.merge(s,l,e)}return e.allowSparse===!0?s:Ur.compact(s)},Bv=Ev,Dv=Mv,Ov=wa,Lv={formats:Ov,parse:Dv,stringify:Bv},Fv=zy;function ar(){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 Nv=/^([a-z0-9.+-]+:)/i,Uv=/:[0-9]*$/,kv=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,Gv=["<",">",'"',"`"," ","\r",`