@annotorious/openseadragon 3.0.12 → 3.0.13

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,7 +1,7 @@
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 kE=Object.defineProperty;var GE=(Mt,Nt,Pr)=>Nt in Mt?kE(Mt,Nt,{enumerable:!0,configurable:!0,writable:!0,value:Pr}):Mt[Nt]=Pr;var Ml=(Mt,Nt,Pr)=>GE(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 io=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(io||{});const Ht=[];for(let r=0;r<256;++r)Ht.push((r+256).toString(16).slice(1));function qf(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 so;const Kf=new Uint8Array(16);function Zf(){if(!so){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");so=crypto.getRandomValues.bind(crypto)}return so(Kf)}const Jf=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),kl={randomUUID:Jf};function Qf(r,t,e){if(kl.randomUUID&&!t&&!r)return kl.randomUUID();r=r||{};const i=r.random||(r.rng||Zf)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,qf(i)}const no=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)}},tp=(r,t,e,i)=>({id:Qf(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),ep=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},rp=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},ip=(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})),sp=(r,t)=>!Mr(r.target,t.target),np=(r,t)=>{const e=ep(r,t),i=rp(r,t),s=ip(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:sp(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 op=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),s=new Set((t.created||[]).map(u=>u.id)),n=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!n.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!s.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!n.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return np(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let ap=()=>({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 lp=250,hp=r=>{const t=ap(),e=[];let i=-1,s=!1,n=0;const o=f=>{if(!s){const{changes:p}=f,m=performance.now();if(m-n>lp)e.splice(i+1),e.push(p),i=e.length-1;else{const _=e.length-1;e[_]=op(e[_],p)}n=m}s=!1};r.observe(o,{origin:fr.LOCAL});const a=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),l=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),h=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:p})=>p)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:p})=>p)),u=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),d=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f);return{canRedo:()=>e.length-1>i,canUndo:()=>i>-1,destroy:()=>r.unobserve(o),on:(f,p)=>t.on(f,p),redo:()=>{if(e.length-1>i){s=!0;const{created:f,updated:p,deleted:m}=e[i+1];l(f),c(p),d(m),t.emit("redo",e[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:f,updated:p,deleted:m}=e[i];a(f),h(p),u(m),t.emit("undo",e[i]),i-=1}}}},cp=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},f=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},p=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(A=>e.serialize(A)):e.serialize(x),I=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,I)}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))&&p("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)&&p("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)&&p("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}p("selectionChanged",h)}}),s.subscribe(y=>{!c&&y?p("mouseEnterAnnotation",o.getAnnotation(y)):c&&!y?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&y&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(y))),c=y}),a==null||a.subscribe(y=>p("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>p("createAnnotation",v)),(g||[]).forEach(v=>p("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const I=h.find(A=>A.id===v.id)||v;h=h.map(A=>A.id===v.id?w:A),p("updateAnnotation",w,I)})},{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(I=>I.id===v.id)||v))}},{origin:fr.REMOTE});const _=y=>x=>{const{updated:g}=x;y?(g||[]).forEach(v=>p("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>p("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:f,emit:p}},up=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:[]}),dp=(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(no(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(),c=()=>{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},u=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(f(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}},f=(y,x=!0)=>{if(e){const g=e.parseAll||up(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(no),x,fr.REMOTE)},p=(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(no(y)),x}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},fp="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let pp=r=>crypto.getRandomValues(new Uint8Array(r)),mp=(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;for(;l--;)if(o+=r[a[l]&i]||"",o.length===n)return o}}},gp=(r,t=21)=>mp(r,t,pp),yp=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r));for(;r--;)t+=fp[e[r]&63];return t};const _p=()=>({isGuest:!0,id:gp("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),vp=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],xp=()=>{const r=[...vp];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};yp();var bp=Object.defineProperty,wp=(r,t,e)=>t in r?bp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Gl=(r,t,e)=>wp(r,typeof t!="symbol"?t+"":t,e);function At(){}function oo(r,t){for(const e in t)r[e]=t[e];return r}function $l(r){return r()}function Hl(){return Object.create(null)}function Pe(r){r.forEach($l)}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 Ep(r){return Object.keys(r).length===0}function Xl(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 ao(r,t,e){r.$$.on_destroy.push(Xl(t,e))}function Tp(r,t,e,i){if(r){const s=Vl(r,t,e,i);return r[0](s)}}function Vl(r,t,e,i){return r[1]&&i?oo(e.ctx.slice(),r[1](i(t))):e.ctx}function Ap(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 Sp(r,t,e,i,s,n){if(s){const o=Vl(t,e,i,n);r.p(o,s)}}function Ip(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 zl(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Cs(r){return r??""}function Me(r,t){r.appendChild(t)}function it(r,t,e){r.insertBefore(t,e||null)}function et(r){r.parentNode&&r.parentNode.removeChild(r)}function lo(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function yt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Wl(r){return document.createTextNode(r)}function ge(){return Wl(" ")}function ye(){return Wl("")}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 Cp(r){return Array.from(r.childNodes)}function pr(r,t,e){r.classList.toggle(t,!!e)}function Rp(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Xi;function Vi(r){Xi=r}function jl(){if(!Xi)throw new Error("Function called outside component initialization");return Xi}function zi(r){jl().$$.on_mount.push(r)}function Qr(){const r=jl();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=Rp(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 Yl=[],Pp=Promise.resolve();let ho=!1;function Mp(){ho||(ho=!0,Pp.then(ql))}function co(r){ei.push(r)}const uo=new Set;let ri=0;function ql(){if(ri!==0)return;const r=Xi;do{try{for(;ri<ti.length;){const t=ti[ri];ri++,Vi(t),Bp(t.$$)}}catch(t){throw ti.length=0,ri=0,t}for(Vi(null),ti.length=0,ri=0;Rs.length;)Rs.pop()();for(let t=0;t<ei.length;t+=1){const e=ei[t];uo.has(e)||(uo.add(e),e())}ei.length=0}while(ti.length);for(;Yl.length;)Yl.pop()();ho=!1,uo.clear(),Vi(r)}function Bp(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(co)}}function Dp(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 ot(r,t){r&&r.i&&(Ps.delete(r),r.i(t))}function mt(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 ce(r){r&&r.c()}function se(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),co(()=>{const n=r.$$.on_mount.map($l).filter(Ut);r.$$.on_destroy?r.$$.on_destroy.push(...n):Pe(n),r.$$.on_mount=[]}),s.forEach(co)}function ne(r,t){const e=r.$$;e.fragment!==null&&(Dp(e.after_update),Pe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Op(r,t){r.$$.dirty[0]===-1&&(ti.push(r),Mp(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ue(r,t,e,i,s,n,o=null,a=[-1]){const l=Xi;Vi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:At,not_equal:s,bound:Hl(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Hl(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...f)=>{const p=f.length?f[0]:d;return h.ctx&&s(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&Op(r,u)),d}):[],h.update(),c=!0,Pe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Cp(t.target);h.fragment&&h.fragment.l(u),u.forEach(et)}else h.fragment&&h.fragment.c();t.intro&&ot(r.$$.fragment),se(r,t.target,t.anchor),ql()}Vi(l)}class de{constructor(){Gl(this,"$$"),Gl(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&&!Ep(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Fp="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Fp);var wt=(r=>(r.ELLIPSE="ELLIPSE",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(wt||{});const fo={},po=(r,t)=>fo[r]=t,mo=r=>fo[r.type].area(r),Lp=(r,t,e)=>fo[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}},Np={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),c=t-i,u=e-s,d=l*c+h*u,f=h*c-l*u;return d*d/(n*n)+f*f/(o*o)<=1}};po(wt.ELLIPSE,Np);const Up={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],c=i[o][1];l>e!=c>e&&t<(h-a)*(e-l)/(c-l)+a&&(s=!s)}return s}};po(wt.POLYGON,Up);const kp={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};po(wt.RECTANGLE,kp);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},Gp=(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,c,u]=s;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,f,p,m]=[l,h,c,u].map(parseFloat);return{type:wt.RECTANGLE,geometry:{x:d,y:f,w:p,h:m,bounds:{minX:d,minY:t?f-m:f,maxX:d+p,maxY:t?f:f+m}}}},$p=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}`}},Kl="http://www.w3.org/2000/svg",Zl=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},Hp=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${Kl}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},Xp=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(Kl),i=t.lookupNamespaceURI(null);return e||i?Zl(t).firstChild:Zl(Hp(t)).firstChild},Vp=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)}}},zp=r=>{const t=Xp(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}}},Wp=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return Vp(t);if(t.includes("<ellipse "))return zp(t);throw"Unsupported SVG shape: "+t},jp=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 Yp(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 go;const qp=new Uint8Array(16);function Kp(){if(!go){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");go=crypto.getRandomValues.bind(crypto)}return go(qp)}const Zp=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jl={randomUUID:Zp};function Ql(r,t,e){if(Jl.randomUUID&&!t&&!r)return Jl.randomUUID();r=r||{};const i=r.random||(r.rng||Kp)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Yp(i)}var th=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(th.call(r,e)&&++i&&!th.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 yo(){}function Jp(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const si=[];function _o(r,t=yo){let e;const i=new Set;function s(a){if(Jp(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=yo){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||yo),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const Qp=r=>{const{subscribe:t,set:e}=_o();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 eh=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(eh||{});const Ds={selected:[]},tm=(r,t,e)=>{const{subscribe:i,set:s}=_o(Ds);let n=t,o=Ds;i(p=>o=p);const a=()=>{mr(o,Ds)||s(Ds)},l=()=>{var p;return((p=o.selected)==null?void 0:p.length)===0},h=p=>{if(l())return!1;const m=typeof p=="string"?p:p.id;return o.selected.some(_=>_.id===m)},c=(p,m)=>{let _;if(Array.isArray(p)){if(_=p.map(x=>r.getAnnotation(x)).filter(Boolean),_.length<p.length){console.warn("Invalid selection: "+p.filter(x=>!_.some(g=>g.id===x)));return}}else{const x=r.getAnnotation(p);if(!x){console.warn("Invalid selection: "+p);return}_=[x]}const y=_.reduce((x,g)=>{const v=rh(g,n,e);return v==="EDIT"?[...x,{id:g.id,editable:!0}]:v==="SELECT"?[...x,{id:g.id}]:x},[]);s({selected:y,event:m})},u=(p,m)=>{const _=Array.isArray(p)?p:[p],y=_.map(x=>r.getAnnotation(x)).filter(x=>!!x);s({selected:y.map(x=>{const g=m===void 0?rh(x,n,e)==="EDIT":m;return{id:x.id,editable:g}})}),y.length!==_.length&&console.warn("Invalid selection",p)},d=p=>{if(l())return!1;const{selected:m}=o;m.some(({id:_})=>p.includes(_))&&s({selected:m.filter(({id:_})=>!p.includes(_))})},f=p=>n=p;return r.observe(({changes:p})=>d((p.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:u,setUserSelectAction:f,subscribe:i,userSelect:c}},rh=(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 em(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 vo;const rm=new Uint8Array(16);function im(){if(!vo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");vo=crypto.getRandomValues.bind(crypto)}return vo(rm)}const sm=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ih={randomUUID:sm};function nm(r,t,e){if(ih.randomUUID&&!t&&!r)return ih.randomUUID();r=r||{};const i=r.random||(r.rng||im)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,em(i)}const xo=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)}},om=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},am=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},lm=(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})),hm=(r,t)=>!mr(r.target,t.target),sh=(r,t)=>{const e=om(r,t),i=am(r,t),s=lm(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:hm(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 cm=(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(c=>a(c.bodiesCreated)||a(c.bodiesDeleted)||a(c.bodiesUpdated)),h=(i=s.updated)==null?void 0:i.some(c=>c.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},um=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),s=new Set((t.created||[]).map(u=>u.id)),n=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!n.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!s.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!n.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return sh(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},bo=r=>{const t=r.id===void 0?nm():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},dm=r=>r.id!==void 0,fm=()=>{const r=new Map,t=new Map,e=[],i=(S,R={})=>{e.push({onChange:S,options:R})},s=S=>{const R=e.findIndex(E=>E.onChange==S);R>-1&&e.splice(R,1)},n=(S,R)=>{const E={origin:S,changes:{created:R.created||[],updated:R.updated||[],deleted:R.deleted||[]},state:[...r.values()]};e.forEach(b=>{cm(b,E)&&b.onChange(E)})},o=(S,R=St.LOCAL)=>{if(S.id&&r.get(S.id))throw Error(`Cannot add annotation ${S.id} - exists already`);{const E=bo(S);r.set(E.id,E),E.bodies.forEach(b=>t.set(b.id,E.id)),n(R,{created:[E]})}},a=(S,R)=>{const E=bo(typeof S=="string"?R:S),b=typeof S=="string"?S:S.id,D=b&&r.get(b);if(D){const F=sh(D,E);return b===E.id?r.set(b,E):(r.delete(b),r.set(E.id,E)),D.bodies.forEach(G=>t.delete(G.id)),E.bodies.forEach(G=>t.set(G.id,E.id)),F}else console.warn(`Cannot update annotation ${b} - does not exist`)},l=(S,R=St.LOCAL,E=St.LOCAL)=>{const b=dm(R)?E:R,D=a(S,R);D&&n(b,{updated:[D]})},h=(S,R=St.LOCAL)=>{const E=S.reduce((b,D)=>{const F=a(D);return F?[...b,F]:b},[]);E.length>0&&n(R,{updated:E})},c=(S,R=St.LOCAL)=>{const E=r.get(S.annotation);if(E){const b={...E,bodies:[...E.bodies,S]};r.set(E.id,b),t.set(S.id,b.id),n(R,{updated:[{oldValue:E,newValue:b,bodiesCreated:[S]}]})}else console.warn(`Attempt to add body to missing annotation: ${S.annotation}`)},u=()=>[...r.values()],d=(S=St.LOCAL)=>{const R=[...r.values()];r.clear(),t.clear(),n(S,{deleted:R})},f=(S,R=!0,E=St.LOCAL)=>{const b=S.map(bo);if(R){const D=[...r.values()];r.clear(),t.clear(),b.forEach(F=>{r.set(F.id,F),F.bodies.forEach(G=>t.set(G.id,F.id))}),n(E,{created:b,deleted:D})}else{const D=S.reduce((F,G)=>{const $=G.id&&r.get(G.id);return $?[...F,$]:F},[]);if(D.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${D.map(F=>F.id).join(", ")}`);b.forEach(F=>{r.set(F.id,F),F.bodies.forEach(G=>t.set(G.id,F.id))}),n(E,{created:b})}},p=S=>{const R=typeof S=="string"?S:S.id,E=r.get(R);if(E)return r.delete(R),E.bodies.forEach(b=>t.delete(b.id)),E;console.warn(`Attempt to delete missing annotation: ${R}`)},m=(S,R=St.LOCAL)=>{const E=p(S);E&&n(R,{deleted:[E]})},_=(S,R=St.LOCAL)=>{const E=S.reduce((b,D)=>{const F=p(D);return F?[...b,F]:b},[]);E.length>0&&n(R,{deleted:E})},y=S=>{const R=r.get(S.annotation);if(R){const E=R.bodies.find(b=>b.id===S.id);if(E){t.delete(E.id);const b={...R,bodies:R.bodies.filter(D=>D.id!==S.id)};return r.set(R.id,b),{oldValue:R,newValue:b,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${S.id} from annotation ${S.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${S.annotation}`)},x=(S,R=St.LOCAL)=>{const E=y(S);E&&n(R,{updated:[E]})},g=(S,R=St.LOCAL)=>{const E=S.map(b=>y(b)).filter(Boolean);E.length>0&&n(R,{updated:E})},v=S=>{const R=r.get(S);return R?{...R}:void 0},w=S=>{const R=t.get(S);if(R){const E=v(R).bodies.find(b=>b.id===S);if(E)return E;console.error(`Store integrity error: body ${S} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${S}`)},I=(S,R)=>{if(S.annotation!==R.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(S.annotation);if(E){const b=E.bodies.find(F=>F.id===S.id),D={...E,bodies:E.bodies.map(F=>F.id===b.id?R:F)};return r.set(E.id,D),b.id!==R.id&&(t.delete(b.id),t.set(R.id,D.id)),{oldValue:E,newValue:D,bodiesUpdated:[{oldBody:b,newBody:R}]}}else console.warn(`Attempt to add body to missing annotation ${S.annotation}`)},A=(S,R,E=St.LOCAL)=>{const b=I(S,R);b&&n(E,{updated:[b]})},C=(S,R=St.LOCAL)=>{const E=S.map(b=>I({id:b.id,annotation:b.annotation},b)).filter(Boolean);n(R,{updated:E})},N=S=>{const R=r.get(S.annotation);if(R){const E={...R,target:{...R.target,...S}};return r.set(R.id,E),{oldValue:R,newValue:E,targetUpdated:{oldTarget:R.target,newTarget:S}}}else console.warn(`Attempt to update target on missing annotation: ${S.annotation}`)};return{addAnnotation:o,addBody:c,all:u,bulkAddAnnotation:f,bulkDeleteAnnotation:_,bulkDeleteBodies:g,bulkUpdateAnnotation:h,bulkUpdateBodies:C,bulkUpdateTargets:(S,R=St.LOCAL)=>{const E=S.map(b=>N(b)).filter(Boolean);E.length>0&&n(R,{updated:E})},clear:d,deleteAnnotation:m,deleteBody:x,getAnnotation:v,getBody:w,observe:i,unobserve:s,updateAnnotation:l,updateBody:A,updateTarget:(S,R=St.LOCAL)=>{const E=N(S);E&&n(R,{updated:[E]})}}},pm=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let mm=()=>({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 gm=250,ym=r=>{const t=mm(),e=[];let i=-1,s=!1,n=0;const o=f=>{if(!s){const{changes:p}=f,m=performance.now();if(m-n>gm)e.splice(i+1),e.push(p),i=e.length-1;else{const _=e.length-1;e[_]=um(e[_],p)}n=m}s=!1};r.observe(o,{origin:St.LOCAL});const a=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),l=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),h=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:p})=>p)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:p})=>p)),u=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),d=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f);return{canRedo:()=>e.length-1>i,canUndo:()=>i>-1,destroy:()=>r.unobserve(o),on:(f,p)=>t.on(f,p),redo:()=>{if(e.length-1>i){s=!0;const{created:f,updated:p,deleted:m}=e[i+1];l(f),c(p),d(m),t.emit("redo",e[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:f,updated:p,deleted:m}=e[i];a(f),h(p),u(m),t.emit("undo",e[i]),i-=1}}}},_m=()=>{const{subscribe:r,set:t}=_o([]);return{subscribe:r,set:t}},vm=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},f=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},p=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(A=>e.serialize(A)):e.serialize(x),I=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,I)}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))&&p("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)&&p("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)&&p("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}p("selectionChanged",h)}}),s.subscribe(y=>{!c&&y?p("mouseEnterAnnotation",o.getAnnotation(y)):c&&!y?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&y&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(y))),c=y}),a==null||a.subscribe(y=>p("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>p("createAnnotation",v)),(g||[]).forEach(v=>p("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const I=h.find(A=>A.id===v.id)||v;h=h.map(A=>A.id===v.id?w:A),p("updateAnnotation",w,I)})},{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=>p("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>p("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:f,emit:p}},xm=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:[]}),bm=(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(xo(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(),c=()=>{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},u=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(f(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}},f=(y,x=!0)=>{if(e){const g=e.parseAll||xm(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(xo),x,St.REMOTE)},p=(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(xo(y)),x}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},wm=(r,t,e)=>typeof t=="function"?t(r,e):t,Em=(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||{}}},Tm="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Am=r=>crypto.getRandomValues(new Uint8Array(r)),Sm=(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;for(;l--;)if(o+=r[a[l]&i]||"",o.length===n)return o}}},Im=(r,t=21)=>Sm(r,t,Am),Cm=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r));for(;r--;)t+=Tm[e[r]&63];return t};const Rm=()=>({isGuest:!0,id:Im("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Pm=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}`},nh=r=>r?typeof r=="object"?{...r}:r:void 0,Mm=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:s,purpose:n,value:o,created:a,modified:l,creator:h,...c}=e;return{id:i||`temp-${Pm(e)}`,annotation:t,type:s,purpose:n,value:o,creator:nh(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),Bm=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});Cm();const Dm=(r,t={strict:!0,invertY:!1})=>({parse:e=>Om(e,t),serialize:e=>Fm(e,r,t)}),Om=(r,t={strict:!0,invertY:!1})=>{const e=r.id||Ql(),{creator:i,created:s,modified:n,body:o,...a}=r,l=Mm(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,c=Array.isArray(h.selector)?h.selector[0]:h.selector,u=(c==null?void 0:c.type)==="FragmentSelector"?Gp(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?Wp(c):void 0;return u||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:nh(i),updated:n?new Date(n):void 0,...Array.isArray(a.target)?a.target[0]:a.target,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},Fm=(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?$p(i.geometry):jp(i)}catch(u){if(e.strict)throw u;h=i}const c={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:Bm(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 c.bodies,"annotation"in c.target&&delete c.target.annotation,c};function oh(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function ah(r){let t,e;return t=new Wi({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(){ce(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||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Lm(r){let t,e,i,s,n,o,a,l,h,c,u,d=ii(r[4].points),f=[];for(let m=0;m<d.length;m+=1)f[m]=ah(oh(r,d,m));const p=m=>mt(f[m],1,1,()=>{f[m]=null});return{c(){t=yt("polygon"),s=ge(),n=yt("polygon"),a=ge();for(let m=0;m<f.length;m+=1)f[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(lh).join(" ")),T(n,"class","a9s-inner a9s-shape-handle"),T(n,"style",r[1]),T(n,"points",o=r[4].points.map(hh).join(" "))},m(m,_){it(m,t,_),it(m,s,_),it(m,n,_),it(m,a,_);for(let y=0;y<f.length;y+=1)f[y]&&f[y].m(m,_);it(m,l,_),h=!0,c||(u=[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)})],c=!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(lh).join(" ")))&&T(t,"points",i),(!h||_&2)&&T(n,"style",r[1]),(!h||_&16&&o!==(o=r[4].points.map(hh).join(" ")))&&T(n,"points",o),_&536){d=ii(r[4].points);let y;for(y=0;y<d.length;y+=1){const x=oh(r,d,y);f[y]?(f[y].p(x,_),ot(f[y],1)):(f[y]=ah(x),f[y].c(),ot(f[y],1),f[y].m(l.parentNode,l))}for(_e(),y=d.length;y<f.length;y+=1)p(y);ve()}},i(m){if(!h){for(let _=0;_<d.length;_+=1)ot(f[_]);h=!0}},o(m){f=f.filter(Boolean);for(let _=0;_<f.length;_+=1)mt(f[_]);h=!1},d(m){m&&(et(t),et(s),et(n),et(a),et(l)),lo(f,m),c=!1,Pe(u)}}}function Nm(r){let t,e;return t=new mh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Lm,({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(){ce(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||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}const lh=r=>r.join(","),hh=r=>r.join(",");function Um(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{let m;const _=d.geometry;f==="SHAPE"?m=_.points.map(([x,g])=>[x+p[0],g+p[1]]):m=_.points.map(([x,g],v)=>f===`HANDLE-${v}`?[x+p[0],g+p[1]]:[x,g]);const y=Ms(m);return{...d,geometry:{points:m,bounds:y}}};function h(d){Ze.call(this,r,d)}function c(d){Ze.call(this,r,d)}function u(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,c,u]}class km extends de{constructor(t){super(),ue(this,t,Um,Nm,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const wo=(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 Gm(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 $m=(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}`)},Hm=(r,t)=>{$m(r,t);const{subscribe:e,set:i}=Gm(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}},ch=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function Xm(r){let t,e,i,s,n,o;return{c(){t=yt("rect"),T(t,"class",e=Cs(`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){it(a,t,l),n||(o=Dt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=Cs(`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&&et(t),n=!1,o()}}}function Vm(r){let t,e,i,s,n,o,a,l,h;return{c(){t=yt("g"),e=yt("circle"),s=yt("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=Cs(`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(c,u){it(c,t,u),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(c,u){u&1&&T(e,"cx",c[0]),u&2&&T(e,"cy",c[1]),u&12&&i!==(i=c[3]/c[2])&&T(e,"r",i),u&16&&pr(e,"touched",c[4]),u&256&&n!==(n=Cs(`a9s-handle ${c[8].class||""}`.trim())+" svelte-1sgkh33")&&T(s,"class",n),u&33&&o!==(o=c[0]-c[5]/2)&&T(s,"x",o),u&34&&a!==(a=c[1]-c[5]/2)&&T(s,"y",a),u&32&&T(s,"width",c[5]),u&32&&T(s,"height",c[5])},d(c){c&&et(t),l=!1,Pe(h)}}}function zm(r){let t;function e(s,n){return ch?Vm:Xm}let i=e()(r);return{c(){i.c(),t=ye()},m(s,n){i.m(s,n),it(s,t,n)},p(s,[n]){i.p(s,n)},i:At,o:At,d(s){s&&et(t),i.d(s)}}}function Wm(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{radius:a=30}=t,l=!1;const h=p=>{p.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(p){Ze.call(this,r,p)}function d(p){Ze.call(this,r,p)}function f(p){Ze.call(this,r,p)}return r.$$set=p=>{e(8,t=oo(oo({},t),zl(p))),"x"in p&&e(0,s=p.x),"y"in p&&e(1,n=p.y),"scale"in p&&e(2,o=p.scale),"radius"in p&&e(3,a=p.radius)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=10/o)},t=zl(t),[s,n,o,a,l,i,h,c,t,u,d,f]}class Wi extends de{constructor(t){super(),ue(this,t,Wm,zm,qt,{x:0,y:1,scale:2,radius:3})}}function jm(r){let t,e,i,s,n,o,a,l,h,c,u,d,f,p,m,_,y,x,g,v,w,I,A,C,N,S,R,E,b,D,F,G,$,B,Z,P,U,j,rt,Q,H,V,lt;return B=new Wi({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),B.$on("pointerdown",function(){Ut(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),P=new Wi({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),P.$on("pointerdown",function(){Ut(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),j=new Wi({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),j.$on("pointerdown",function(){Ut(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Q=new Wi({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Q.$on("pointerdown",function(){Ut(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=yt("rect"),a=ge(),l=yt("rect"),f=ge(),p=yt("rect"),x=ge(),g=yt("rect"),A=ge(),C=yt("rect"),E=ge(),b=yt("rect"),$=ge(),ce(B.$$.fragment),Z=ge(),ce(P.$$.fragment),U=ge(),ce(j.$$.fragment),rt=ge(),ce(Q.$$.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",c=r[4].y),T(l,"width",u=r[4].w),T(l,"height",d=r[4].h),T(p,"class","a9s-edge-handle a9s-edge-handle-top"),T(p,"x",m=r[4].x),T(p,"y",_=r[4].y),T(p,"height",1),T(p,"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",I=r[4].h),T(g,"width",1),T(C,"class","a9s-edge-handle a9s-edge-handle-bottom"),T(C,"x",N=r[4].x),T(C,"y",S=r[4].y+r[4].h),T(C,"height",1),T(C,"width",R=r[4].w),T(b,"class","a9s-edge-handle a9s-edge-handle-left"),T(b,"x",D=r[4].x),T(b,"y",F=r[4].y),T(b,"height",G=r[4].h),T(b,"width",1)},m(L,O){it(L,t,O),it(L,a,O),it(L,l,O),it(L,f,O),it(L,p,O),it(L,x,O),it(L,g,O),it(L,A,O),it(L,C,O),it(L,E,O),it(L,b,O),it(L,$,O),se(B,L,O),it(L,Z,O),se(P,L,O),it(L,U,O),se(j,L,O),it(L,rt,O),se(Q,L,O),H=!0,V||(lt=[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(p,"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(C,"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)})],V=!0)},p(L,O){r=L,(!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&&c!==(c=r[4].y))&&T(l,"y",c),(!H||O&16&&u!==(u=r[4].w))&&T(l,"width",u),(!H||O&16&&d!==(d=r[4].h))&&T(l,"height",d),(!H||O&16&&m!==(m=r[4].x))&&T(p,"x",m),(!H||O&16&&_!==(_=r[4].y))&&T(p,"y",_),(!H||O&16&&y!==(y=r[4].w))&&T(p,"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&&I!==(I=r[4].h))&&T(g,"height",I),(!H||O&16&&N!==(N=r[4].x))&&T(C,"x",N),(!H||O&16&&S!==(S=r[4].y+r[4].h))&&T(C,"y",S),(!H||O&16&&R!==(R=r[4].w))&&T(C,"width",R),(!H||O&16&&D!==(D=r[4].x))&&T(b,"x",D),(!H||O&16&&F!==(F=r[4].y))&&T(b,"y",F),(!H||O&16&&G!==(G=r[4].h))&&T(b,"height",G);const _t={};O&16&&(_t.x=r[4].x),O&16&&(_t.y=r[4].y),O&8&&(_t.scale=r[3]),B.$set(_t);const ht={};O&16&&(ht.x=r[4].x+r[4].w),O&16&&(ht.y=r[4].y),O&8&&(ht.scale=r[3]),P.$set(ht);const vt={};O&16&&(vt.x=r[4].x+r[4].w),O&16&&(vt.y=r[4].y+r[4].h),O&8&&(vt.scale=r[3]),j.$set(vt);const xt={};O&16&&(xt.x=r[4].x),O&16&&(xt.y=r[4].y+r[4].h),O&8&&(xt.scale=r[3]),Q.$set(xt)},i(L){H||(ot(B.$$.fragment,L),ot(P.$$.fragment,L),ot(j.$$.fragment,L),ot(Q.$$.fragment,L),H=!0)},o(L){mt(B.$$.fragment,L),mt(P.$$.fragment,L),mt(j.$$.fragment,L),mt(Q.$$.fragment,L),H=!1},d(L){L&&(et(t),et(a),et(l),et(f),et(p),et(x),et(g),et(A),et(C),et(E),et(b),et($),et(Z),et(U),et(rt)),ne(B,L),ne(P,L),ne(j,L),ne(Q,L),V=!1,Pe(lt)}}}function Ym(r){let t,e;return t=new mh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[jm,({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(){ce(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||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function qm(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{const m=d.geometry.bounds;let[_,y]=[m.minX,m.minY],[x,g]=[m.maxX,m.maxY];const[v,w]=p;if(f==="SHAPE")_+=v,x+=v,y+=w,g+=w;else{switch(f){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{y+=w;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=w;break}}switch(f){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{_+=v;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{x+=v;break}}}const I=Math.min(_,x),A=Math.min(y,g),C=Math.abs(x-_),N=Math.abs(g-y);return{...d,geometry:{x:I,y:A,w:C,h:N,bounds:{minX:I,minY:A,maxX:I+C,maxY:A+N}}}};function h(d){Ze.call(this,r,d)}function c(d){Ze.call(this,r,d)}function u(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,c,u]}class Km extends de{constructor(t){super(),ue(this,t,qm,Ym,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const uh=new Map([[wt.RECTANGLE,Km],[wt.POLYGON,km]]),dh=r=>uh.get(r.type),fh=(r,t)=>uh.set(r,t),Zm=r=>({}),ph=r=>({grab:r[0]});function Jm(r){let t,e,i,s;const n=r[7].default,o=Tp(n,r,r[6],ph);return{c(){t=yt("g"),o&&o.c(),T(t,"class","a9s-annotation selected")},m(a,l){it(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)&&Sp(o,n,a,a[6],e?Ap(n,a[6],l,Zm):Ip(a[6]),ph)},i(a){e||(ot(o,a),e=!0)},o(a){mt(o,a),e=!1},d(a){a&&et(t),o&&o.d(a),i=!1,Pe(s)}}}function Qm(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Qr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,c,u;const d=m=>_=>{h=m,c=l.elementToImage(_.offsetX,_.offsetY),u=o,_.target.setPointerCapture(_.pointerId),n("grab",_)},f=m=>{if(h){const[_,y]=l.elementToImage(m.offsetX,m.offsetY),x=[_-c[0],y-c[1]];e(3,o=a(u,h,x)),n("change",o)}},p=m=>{m.target.releasePointerCapture(m.pointerId),h=void 0,u=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,f,p,o,a,l,s,i]}class mh extends de{constructor(t){super(),ue(this,t,Qm,Jm,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 tg(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:c}=t,u;return zi(()=>(e(6,u=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:c}})),u.$on("change",d=>{u.$$set({shape:d.detail}),s("change",d.detail)}),u.$on("grab",d=>s("grab",d.detail)),u.$on("release",d=>s("release",d.detail)),()=>{u.$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,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=Os(n,a)),r.$$.dirty&65&&n&&(u==null||u.$set({shape:n.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[n,o,a,l,h,c,u,i]}class eg extends de{constructor(t){super(),ue(this,t,tg,null,qt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function rg(r,t,e){const i=Qr();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return zi(()=>{const c=n.closest("svg"),u=[],d=(f,p,m)=>{c==null||c.addEventListener(f,p,m),u.push(()=>c==null?void 0:c.removeEventListener(f,p,m))};return e(5,h=new o({target:n,props:{addEventListener:d,drawingMode:s,transform:a,viewportScale:l}})),h.$on("create",f=>i("create",f.detail)),()=>{u.forEach(f=>f()),h.$destroy()}}),r.$$set=c=>{"drawingMode"in c&&e(0,s=c.drawingMode),"target"in c&&e(1,n=c.target),"tool"in c&&e(2,o=c.tool),"transform"in c&&e(3,a=c.transform),"viewportScale"in c&&e(4,l=c.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 ig extends de{constructor(t){super(),ue(this,t,rg,null,qt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function gh(r){let t,e;return{c(){t=yt("rect"),e=yt("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){it(i,t,s),it(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&&(et(t),et(e))}}}function sg(r){let t,e=r[0]&&gh(r);return{c(){t=yt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=gh(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&et(t),e&&e.d()}}}function ng(r,t,e){const i=Qr();let{addEventListener:s}=t,{drawingMode:n}=t,{transform:o}=t,a,l,h,c,u,d,f;const p=x=>{const g=x;a=performance.now(),n==="drag"&&(e(0,l=o.elementToImage(g.offsetX,g.offsetY)),h=l,e(1,c=l[0]),e(2,u=l[1]),e(3,d=1),e(4,f=1))},m=x=>{const g=x;l&&(h=o.elementToImage(g.offsetX,g.offsetY),e(1,c=Math.min(h[0],l[0])),e(2,u=Math.min(h[1],l[1])),e(3,d=Math.abs(h[0]-l[0])),e(4,f=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,c=l[0]),e(2,u=l[1]),e(3,d=1),e(4,f=1))}else l&&(v>300||d*f>100?(g.stopPropagation(),y()):(e(0,l=void 0),h=void 0))},y=()=>{if(d*f>15){const x={type:wt.RECTANGLE,geometry:{bounds:{minX:c,minY:u,maxX:c+d,maxY:u+f},x:c,y:u,w:d,h:f}};i("create",x)}e(0,l=void 0),h=void 0};return zi(()=>{s("pointerdown",p),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,c,u,d,f,s,n,o]}class og extends de{constructor(t){super(),ue(this,t,ng,sg,qt,{addEventListener:5,drawingMode:6,transform:7})}}function Eo(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 yh(r){let t,e,i,s,n,o=r[2]&&_h(r);return{c(){t=yt("polygon"),i=yt("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){it(a,t,l),it(a,i,l),o&&o.m(a,l),it(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=_h(a),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},d(a){a&&(et(t),et(i),et(n)),o&&o.d(a)}}}function _h(r){let t,e,i;return{c(){t=yt("rect"),T(t,"class","a9s-corner-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){it(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&&et(t)}}}function ag(r){let t,e=r[1]&&yh(Eo(r));return{c(){t=yt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[1]?e?e.p(Eo(i),s):(e=yh(Eo(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&et(t),e&&e.d()}}}const lg=20,hg=1500;function cg(r,t,e){let i;const s=Qr();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c=[],u,d,f=!1;const p=g=>{const v=g,{timeStamp:w,offsetX:I,offsetY:A}=v;if(h={timeStamp:w,offsetX:I,offsetY:A},o==="drag"&&c.length===0){const C=a.elementToImage(v.offsetX,v.offsetY);c.push(C),e(1,u=C)}},m=g=>{const v=g;if(d&&clearTimeout(d),c.length>0){if(e(1,u=a.elementToImage(v.offsetX,v.offsetY)),c.length>2){const w=wo(u,c[0])*l;e(2,f=w<lg)}v.pointerType==="touch"&&(d=setTimeout(()=>{y()},hg))}},_=g=>{const v=g;if(d&&clearTimeout(d),o==="click"){const w=v.timeStamp-h.timeStamp,I=wo([h.offsetX,h.offsetY],[v.offsetX,v.offsetY]);if(w>300||I>15)return;if(f)x();else if(c.length===0){const A=a.elementToImage(v.offsetX,v.offsetY);c.push(A),e(1,u=A)}else c.push(u)}else{if(c.length===1&&wo(c[0],u)<=4){e(0,c=[]),e(1,u=void 0);return}v.stopImmediatePropagation(),f?x():c.push(u)}},y=()=>{if(!u)return;const g=[...c,u],v={type:wt.POLYGON,geometry:{bounds:Ms(g),points:g}};mo(v)>4&&(e(0,c=[]),e(1,u=void 0),s("create",v))},x=()=>{const g={type:wt.POLYGON,geometry:{bounds:Ms(c),points:[...c]}};e(0,c=[]),e(1,u=void 0),s("create",g)};return zi(()=>{n("pointerdown",p,!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)},[c,u,f,i,n,o,a,l]}class ug extends de{constructor(t){super(),ue(this,t,cg,ag,qt,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const To=new Map([["rectangle",{tool:og}],["polygon",{tool:ug}]]),Fs=()=>[...To.keys()],Ls=r=>To.get(r),vh=(r,t,e)=>To.set(r,{tool:t,opts:e});function dg(r){let t,e,i,s,n;return{c(){t=yt("g"),e=yt("ellipse"),s=yt("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){it(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&&et(t)}}}function fg(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:c}=n;return r.$$set=u=>{"annotation"in u&&e(0,s=u.annotation),"geom"in u&&e(6,n=u.geom),"style"in u&&e(7,o=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=Os(s,o))},[s,i,a,l,h,c,n,o]}class pg extends de{constructor(t){super(),ue(this,t,fg,dg,qt,{annotation:0,geom:6,style:7})}}function mg(r){let t,e,i,s,n;return{c(){t=yt("g"),e=yt("polygon"),s=yt("polygon"),T(e,"class","a9s-outer"),T(e,"style",i=r[1]?"display:none;":void 0),T(e,"points",r[2].map(gg).join(" ")),T(s,"class","a9s-inner"),T(s,"style",r[1]),T(s,"points",r[2].map(yg).join(" ")),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){it(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&&et(t)}}}const gg=r=>r.join(","),yg=r=>r.join(",");function _g(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 vg extends de{constructor(t){super(),ue(this,t,_g,mg,qt,{annotation:0,geom:3,style:4})}}function xg(r){let t,e,i,s,n;return{c(){t=yt("g"),e=yt("rect"),s=yt("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){it(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&&et(t)}}}function bg(r,t,e){let i,s,n,o,a,{annotation:l}=t,{geom:h}=t,{style:c}=t;return r.$$set=u=>{"annotation"in u&&e(0,l=u.annotation),"geom"in u&&e(6,h=u.geom),"style"in u&&e(7,c=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=Os(l,c)),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,c]}class wg extends de{constructor(t){super(),ue(this,t,bg,xg,qt,{annotation:0,geom:6,style:7})}}const Eg=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]}}),Tg=250,Ag=(r,t)=>{const e=Qr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<Tg){const{x:n,y:o}=xh(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},xh=(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[37]=t[e];const s=i[23](i[37].target.selector);return i[38]=s,i}function wh(r,t,e){const i=r.slice();return i[41]=t[e],i}function Ao(r){const t=r.slice(),e=t[41].target.selector;return t[44]=e,t}function Eh(r){let t=r[41].id,e,i,s=Th(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&32768&&qt(t,t=n[41].id)?(_e(),mt(s,1,1,At),ve(),s=Th(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s.d(n)}}}function Sg(r){let t,e;return t=new vg({props:{annotation:r[41],geom:r[44].geometry,style:r[1]}}),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){const n={};s[0]&32768&&(n.annotation=i[41]),s[0]&32768&&(n.geom=i[44].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Ig(r){let t,e;return t=new wg({props:{annotation:r[41],geom:r[44].geometry,style:r[1]}}),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){const n={};s[0]&32768&&(n.annotation=i[41]),s[0]&32768&&(n.geom=i[44].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Cg(r){var t;let e,i;return e=new pg({props:{annotation:r[41],geom:(t=r[44])==null?void 0:t.geometry,style:r[1]}}),{c(){ce(e.$$.fragment)},m(s,n){se(e,s,n),i=!0},p(s,n){var o;const a={};n[0]&32768&&(a.annotation=s[41]),n[0]&32768&&(a.geom=(o=s[44])==null?void 0:o.geometry),n[0]&2&&(a.style=s[1]),e.$set(a)},i(s){i||(ot(e.$$.fragment,s),i=!0)},o(s){mt(e.$$.fragment,s),i=!1},d(s){ne(e,s)}}}function Th(r){let t,e,i,s;const n=[Cg,Ig,Sg],o=[];function a(l,h){var c,u,d;return((c=l[44])==null?void 0:c.type)===wt.ELLIPSE?0:((u=l[44])==null?void 0:u.type)===wt.RECTANGLE?1:((d=l[44])==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),it(l,i,h),s=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(_e(),mt(o[c],1,1,()=>{o[c]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){mt(e),s=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function Ah(r){let t=Je(r[41])&&!r[8](r[41]),e,i,s=t&&Eh(Ao(r));return{c(){s&&s.c(),e=ye()},m(n,o){s&&s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&33024&&(t=Je(n[41])&&!n[8](n[41])),t?s?(s.p(Ao(n),o),o[0]&33024&&ot(s,1)):(s=Eh(Ao(n)),s.c(),ot(s,1),s.m(e.parentNode,e)):s&&(_e(),mt(s,1,1,()=>{s=null}),ve())},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s&&s.d(n)}}}function Sh(r){let t,e,i,s;const n=[Pg,Rg],o=[];function a(l,h){return l[7]?0:l[13]&&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),it(l,i,h),s=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(_e(),mt(o[c],1,1,()=>{o[c]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){mt(e),s=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function Rg(r){let t=r[2],e,i,s=Ih(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&4&&qt(t,t=n[2])?(_e(),mt(s,1,1,At),ve(),s=Ih(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s.d(n)}}}function Pg(r){let t,e,i=ii(r[7]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Ph(bh(r,i,o));const n=o=>mt(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);it(o,t,a),e=!0},p(o,a){if(a[0]&10553506){i=ii(o[7]);let l;for(l=0;l<i.length;l+=1){const h=bh(o,i,l);s[l]?(s[l].p(h,a),ot(s[l],1)):(s[l]=Ph(h),s[l].c(),ot(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)ot(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)mt(s[a]);e=!1},d(o){o&&et(t),lo(s,o)}}}function Ih(r){let t,e;return t=new ig({props:{target:r[5],tool:r[13],drawingMode:r[12],transform:r[11],viewportScale:r[16]}}),t.$on("create",r[20]),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){const n={};s[0]&32&&(n.target=i[5]),s[0]&8192&&(n.tool=i[13]),s[0]&4096&&(n.drawingMode=i[12]),s[0]&2048&&(n.transform=i[11]),s[0]&65536&&(n.viewportScale=i[16]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Ch(r){let t=r[37].id,e,i,s=Rh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&128&&qt(t,t=n[37].id)?(_e(),mt(s,1,1,At),ve(),s=Rh(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s.d(n)}}}function Rh(r){let t,e;return t=new eg({props:{target:r[5],editor:r[23](r[37].target.selector),annotation:r[37],style:r[1],transform:r[11],viewportScale:r[16]}}),t.$on("change",function(){Ut(r[21](r[37]))&&r[21](r[37]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&32&&(n.target=r[5]),s[0]&128&&(n.editor=r[23](r[37].target.selector)),s[0]&128&&(n.annotation=r[37]),s[0]&2&&(n.style=r[1]),s[0]&2048&&(n.transform=r[11]),s[0]&65536&&(n.viewportScale=r[16]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Ph(r){let t,e,i=r[38]&&Ch(r);return{c(){i&&i.c(),t=ye()},m(s,n){i&&i.m(s,n),it(s,t,n),e=!0},p(s,n){s[38]?i?(i.p(s,n),n[0]&128&&ot(i,1)):(i=Ch(s),i.c(),ot(i,1),i.m(t.parentNode,t)):i&&(_e(),mt(i,1,1,()=>{i=null}),ve())},i(s){e||(ot(i),e=!0)},o(s){mt(i),e=!1},d(s){s&&et(t),i&&i.d(s)}}}function Mg(r){let t,e,i,s,n,o,a=ii(r[15].filter(r[32])),l=[];for(let u=0;u<a.length;u+=1)l[u]=Ah(wh(r,a,u));const h=u=>mt(l[u],1,1,()=>{l[u]=null});let c=r[5]&&Sh(r);return{c(){t=yt("svg"),e=yt("g");for(let u=0;u<l.length;u+=1)l[u].c();i=yt("g"),c&&c.c(),T(i,"class","drawing"),T(t,"class","a9s-annotationlayer"),pr(t,"drawing",r[13]),pr(t,"hidden",!r[3]),pr(t,"hover",r[14])},m(u,d){it(u,t,d),Me(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);Me(t,i),c&&c.m(i,null),r[33](i),r[34](t),s=!0,n||(o=[Dt(t,"pointerup",function(){Ut(r[9])&&r[9].apply(this,arguments)}),Dt(t,"pointerdown",function(){Ut(r[10])&&r[10].apply(this,arguments)}),Dt(t,"pointermove",r[22])],n=!0)},p(u,d){if(r=u,d[0]&33026){a=ii(r[15].filter(r[32]));let f;for(f=0;f<a.length;f+=1){const p=wh(r,a,f);l[f]?(l[f].p(p,d),ot(l[f],1)):(l[f]=Ah(p),l[f].c(),ot(l[f],1),l[f].m(e,null))}for(_e(),f=a.length;f<l.length;f+=1)h(f);ve()}r[5]?c?(c.p(r,d),d[0]&32&&ot(c,1)):(c=Sh(r),c.c(),ot(c,1),c.m(i,null)):c&&(_e(),mt(c,1,1,()=>{c=null}),ve()),(!s||d[0]&8192)&&pr(t,"drawing",r[13]),(!s||d[0]&8)&&pr(t,"hidden",!r[3]),(!s||d[0]&16384)&&pr(t,"hover",r[14])},i(u){if(!s){for(let d=0;d<a.length;d+=1)ot(l[d]);ot(c),s=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)mt(l[d]);mt(c),s=!1},d(u){u&&et(t),lo(l,u),c&&c.d(),r[33](null),r[34](null),n=!1,Pe(o)}}}function Bg(r,t,e){let i,s,n,o,a,l,h,c,u,d,f,p=At,m=()=>(p(),p=Xl(E,V=>e(16,f=V)),E);r.$$.on_destroy.push(()=>p());let{drawingEnabled:_}=t,{image:y}=t,{preferredDrawingMode:x}=t,{state:g}=t,{style:v=void 0}=t,{toolName:w=Fs()[0]}=t,{user:I}=t,{visible:A=!0}=t;const C=()=>w,N=()=>_;let S,R,E;zi(()=>m(e(6,E=Hm(y,R))));const{hover:b,selection:D,store:F}=g;ao(r,b,V=>e(14,c=V)),ao(r,D,V=>e(31,u=V)),ao(r,F,V=>e(15,d=V));let G,$;const B=V=>{G&&F.unobserve(G);const lt=V.filter(({editable:L})=>L).map(({id:L})=>L);lt.length>0?(e(7,$=lt.map(L=>F.getAnnotation(L)).filter(L=>L&&Je(L))),G=L=>{const{updated:O}=L.changes;e(7,$=O==null?void 0:O.map(_t=>_t.newValue))},F.observe(G,{annotations:lt})):e(7,$=void 0)},Z=V=>{const lt=Ql(),L={id:lt,bodies:[],target:{annotation:lt,selector:V.detail,creator:I,created:new Date}};F.addAnnotation(L),D.setSelected(L.id)},P=V=>lt=>{var L;const{target:O}=V,_t=10*60*1e3,ht=((L=O.creator)==null?void 0:L.id)!==I.id||!O.created||new Date().getTime()-O.created.getTime()>_t;F.updateTarget({...O,selector:lt.detail,created:ht?O.created:new Date,updated:ht?new Date:void 0,updatedBy:ht?I:void 0})},U=V=>{const{x:lt,y:L}=xh(V,R),O=F.getAt(lt,L);O?c!==O.id&&b.set(O.id):b.set(void 0)},j=V=>dh(V),rt=V=>Je(V);function Q(V){Rs[V?"unshift":"push"](()=>{S=V,e(5,S)})}function H(V){Rs[V?"unshift":"push"](()=>{R=V,e(4,R)})}return r.$$set=V=>{"drawingEnabled"in V&&e(0,_=V.drawingEnabled),"image"in V&&e(24,y=V.image),"preferredDrawingMode"in V&&e(25,x=V.preferredDrawingMode),"state"in V&&e(26,g=V.state),"style"in V&&e(1,v=V.style),"toolName"in V&&e(2,w=V.toolName),"user"in V&&e(27,I=V.user),"visible"in V&&e(3,A=V.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(13,{tool:i,opts:s}=Ls(w)||{tool:void 0,opts:void 0},i,(e(30,s),e(2,w))),r.$$.dirty[0]&1107296256&&e(12,n=(s==null?void 0:s.drawingMode)||x),r.$$.dirty[0]&16&&e(11,o=Eg(R)),r.$$.dirty[0]&16&&e(10,{onPointerDown:a,onPointerUp:l}=Ag(R,F),a,(e(9,l),e(4,R))),r.$$.dirty[1]&1&&e(8,h=V=>u.selected.find(lt=>lt.id===V.id&&lt.editable)),r.$$.dirty[1]&1&&B(u.selected)},[_,v,w,A,R,S,E,$,h,l,a,o,n,i,c,d,f,b,D,F,Z,P,U,j,y,x,g,I,C,N,s,u,rt,Q,H]}class Dg extends de{constructor(t){super(),ue(this,t,Bg,Mg,qt,{drawingEnabled:0,image:24,preferredDrawingMode:25,state:26,style:1,toolName:2,user:27,visible:3,getDrawingTool:28,isDrawingEnabled:29},null,[-1,-1])}get getDrawingTool(){return this.$$.ctx[28]}get isDrawingEnabled(){return this.$$.ctx[29]}}function Mh(r,t,e=0,i=r.length-1,s=Og){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,c=Math.log(l),u=.5*Math.exp(2*c/3),d=.5*Math.sqrt(c*u*(l-u)/l)*(h-l/2<0?-1:1),f=Math.max(e,Math.floor(t-h*u/l+d)),p=Math.min(i,Math.floor(t+(l-h)*u/l+d));Mh(r,t,f,p,s)}const n=r[t];let o=e,a=i;for(ji(r,e,t),s(r[i],n)>0&&ji(r,e,i);o<a;){for(ji(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?ji(r,e,a):(a++,ji(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function ji(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function Og(r,t){return r<t?-1:r>t?1:0}class Fg{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):Io(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||Io(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 c=Lg(t,i.children,e);if(c!==-1)return i.children.splice(c,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&Io(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));Bh(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);Bh(t,c,u,l,this.compareMinY);for(let d=c;d<=u;d+=l){const f=Math.min(d+l-1,u);a.children.push(this._build(t,d,f,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],c=So(h),u=kg(t,h)-c;u<o?(o=u,n=c<n?c:n,a=h):u===o&&c<n&&(n=c,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),qi(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=Yi(t,0,a,this.toBBox),h=Yi(t,a,i,this.toBBox),c=Gg(l,h),u=So(l)+So(h);c<n?(n=c,s=a,o=u<o?u:o):c===n&&u<o&&(o=u,s=a)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:Ng,n=t.leaf?this.compareMinY:Ug,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=Yi(t,0,e,n),a=Yi(t,i-e,i,n);let l=Ns(o)+Ns(a);for(let h=e;h<i-e;h++){const c=t.children[h];qi(o,t.leaf?n(c):c),l+=Ns(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];qi(a,t.leaf?n(c):c),l+=Ns(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)qi(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 Lg(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){Yi(r,0,r.children.length,t,r)}function Yi(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];qi(s,r.leaf?i(o):o)}return s}function qi(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 Ng(r,t){return r.minX-t.minX}function Ug(r,t){return r.minY-t.minY}function So(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Ns(r){return r.maxX-r.minX+(r.maxY-r.minY)}function kg(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 Gg(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 Io(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 Bh(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;Mh(r,o,t,e,s),n.push(t,o,o,e)}}const $g=()=>{const r=new Fg,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:c}=o.selector.geometry.bounds,u={minX:a,minY:l,maxX:h,maxY:c,target:o};r.insert(u),t.set(o.annotation,u)},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||Lp(h.selector,o,a));if(l.length>0)return l.sort((h,c)=>mo(h.selector)-mo(c.selector)),l[0]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(c=>c.target),insert:s,remove:n,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,c)=>{if(Bs(c)){const{minX:u,minY:d,maxX:f,maxY:p}=c.selector.geometry.bounds;return[...h,{minX:u,minY:d,maxX:f,maxY:p,target:c}]}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)}}},Dh=r=>{const t=fm(),e=$g(),i=tm(t,r.userSelectAction,r.adapter),s=Qp(t),n=_m();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(c=>t.getAnnotation(c.annotation))},selection:i,hover:s,viewport:n}},Hg=r=>{const t=Dh(r);return{...t,store:pm(t.store)}},Xg=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},Oh=r=>{const t=Xg(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},Fh=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?Oh(r):e),Lh=(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}),Nh=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Uh=(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=()=>{Nh?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Nh?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},Vg=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=Lh(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:eh.EDIT,theme:"light"}),s=Hg(i),{selection:n,store:o}=s,a=ym(o),l=vm(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 c=Uh(a);let u=Rm();Fh(e,h,i.theme);const d=new Dg({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:u}});d.$on("click",E=>{const{originalEvent:b,annotation:D}=E.detail;D?n.userSelect(D.id,b):n.isEmpty()||n.clear()});const f=bm(s,a,i.adapter),p=()=>{d.$set({drawingEnabled:!1}),setTimeout(()=>d.$set({drawingEnabled:!0}),1)},m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},_=()=>d.getDrawingTool(),y=()=>u,x=()=>d.isDrawingEnabled(),g=(E,b,D)=>vh(E,b,D),v=(E,b)=>fh(E,b),w=E=>{if(!Ls(E))throw`No drawing tool named ${E}`;d.$set({toolName:E})},I=E=>d.$set({drawingEnabled:E}),A=E=>{console.warn("Filter not implemented yet")},C=E=>d.$set({style:E}),N=E=>Fh(e,h,E),S=E=>{u=E,d.$set({user:E})},R=E=>d.$set({visible:E});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:_,getUser:y,isDrawingEnabled:x,listDrawingTools:Fs,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:v,setDrawingEnabled:I,setDrawingTool:w,setFilter:A,setStyle:C,setTheme:N,setUser:S,setVisible:R,element:h,state:s}};function Be(){}function Co(r,t){for(const e in t)r[e]=t[e];return r}function kh(r){return r()}function Gh(){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 zg(r){return Object.keys(r).length===0}function Wg(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 Ro(r,t,e){r.$$.on_destroy.push(Wg(t,e))}function $h(r,t,e,i){if(r){const s=Hh(r,t,e,i);return r[0](s)}}function Hh(r,t,e,i){return r[1]&&i?Co(e.ctx.slice(),r[1](i(t))):e.ctx}function Xh(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 Vh(r,t,e,i,s,n){if(s){const o=Hh(t,e,i,n);r.p(o,s)}}function zh(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 Wh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ks(r){return r??""}const jg=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function tr(r,t){r.appendChild(t)}function ft(r,t,e){r.insertBefore(t,e||null)}function ct(r){r.parentNode&&r.parentNode.removeChild(r)}function Po(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 Mo(r){return document.createTextNode(r)}function xe(){return Mo(" ")}function er(){return Mo("")}function zt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function M(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Yg(r){return Array.from(r.childNodes)}function qg(r,t){t=""+t,r.data!==t&&(r.data=t)}function Gs(r,t,e){r.classList.toggle(t,!!e)}function Kg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Ki;function Zi(r){Ki=r}function Bo(){if(!Ki)throw new Error("Function called outside component initialization");return Ki}function $s(r){Bo().$$.on_mount.push(r)}function Zg(r){Bo().$$.on_destroy.push(r)}function Hs(){const r=Bo();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=Kg(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 jh=[],Jg=Promise.resolve();let Do=!1;function Qg(){Do||(Do=!0,Jg.then(Yh))}function Oo(r){hi.push(r)}const Fo=new Set;let ci=0;function Yh(){if(ci!==0)return;const r=Ki;do{try{for(;ci<li.length;){const t=li[ci];ci++,Zi(t),ty(t.$$)}}catch(t){throw li.length=0,ci=0,t}for(Zi(null),li.length=0,ci=0;Xs.length;)Xs.pop()();for(let t=0;t<hi.length;t+=1){const e=hi[t];Fo.has(e)||(Fo.add(e),e())}hi.length=0}while(li.length);for(;jh.length;)jh.pop()();Do=!1,Fo.clear(),Zi(r)}function ty(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(Oo)}}function ey(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 st(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 ui(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),Oo(()=>{const n=r.$$.on_mount.map(kh).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...n):Qe(n),r.$$.on_mount=[]}),s.forEach(Oo)}function Jt(r,t){const e=r.$$;e.fragment!==null&&(ey(e.after_update),Qe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function ry(r,t){r.$$.dirty[0]===-1&&(li.push(r),Qg(),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=Ki;Zi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Be,not_equal:s,bound:Gh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Gh(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...f)=>{const p=f.length?f[0]:d;return h.ctx&&s(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&ry(r,u)),d}):[],h.update(),c=!0,Qe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Yg(t.target);h.fragment&&h.fragment.l(u),u.forEach(ct)}else h.fragment&&h.fragment.c();t.intro&&st(r.$$.fragment),Zt(r,t.target,t.anchor),Yh()}Zi(l)}class ae{constructor(){Ml(this,"$$");Ml(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&&!zg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const iy="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(iy);var Or=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(Or||{}),qh=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(qh||{}),Lo=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Lo||{}),tt=(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))(tt||{}),Fe=(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))(Fe||{}),k=(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))(k||{}),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||{}),J=(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))(J||{}),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||{}),Le=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(Le||{}),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||{}),No=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(No||{}),fe=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(fe||{}),Ft=(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))(Ft||{}),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 Uo=/iPhone/i,Kh=/iPod/i,Zh=/iPad/i,Jh=/\biOS-universal(?:.+)Mac\b/i,ko=/\bAndroid(?:.+)Mobile\b/i,Qh=/Android/i,fi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,zs=/Silk/i,sr=/Windows Phone/i,tc=/\bWindows(?:.+)ARM\b/i,ec=/BlackBerry/i,rc=/BB10/i,ic=/Opera Mini/i,sc=/\b(CriOS|Chrome)(?:.+)Mobile/i,nc=/Mobile(?:.+)Firefox\b/i,oc=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function sy(r){return function(t){return t.test(r)}}function ac(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=sy(e),n={apple:{phone:s(Uo)&&!s(sr),ipod:s(Kh),tablet:!s(Uo)&&(s(Zh)||oc(t))&&!s(sr),universal:s(Jh),device:(s(Uo)||s(Kh)||s(Zh)||s(Jh)||oc(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(ko),tablet:!s(sr)&&!s(fi)&&!s(ko)&&(s(zs)||s(Qh)),device:!s(sr)&&(s(fi)||s(zs)||s(ko)||s(Qh))||s(/\bokhttp\b/i)},windows:{phone:s(sr),tablet:s(tc),device:s(sr)||s(tc)},other:{blackberry:s(ec),blackberry10:s(rc),opera:s(ic),firefox:s(nc),chrome:s(sc),device:s(ec)||s(rc)||s(ic)||s(nc)||s(sc)},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 ny=ac.default??ac,nr=ny(globalThis.navigator);W.RETINA_PREFIX=/@([0-9\.]+)x/,W.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Ji=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function lc(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function oy(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 hc={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,c){this.fn=l,this.context=h,this.once=c||!1}function n(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new s(c,u||l,d),p=e?e+h:h;return l._events[p]?l._events[p].fn?l._events[p]=[l._events[p],f]:l._events[p].push(f):(l._events[p]=f,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=[],c,u;if(this._eventsCount===0)return h;for(u in c=this._events)t.call(c,u)&&h.push(e?u.slice(1):u);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(c)):h},a.prototype.listeners=function(h){var c=e?e+h:h,u=this._events[c];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,f=u.length,p=new Array(f);d<f;d++)p[d]=u[d].fn;return p},a.prototype.listenerCount=function(h){var c=e?e+h:h,u=this._events[c];return u?u.fn?1:u.length:0},a.prototype.emit=function(h,c,u,d,f,p){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,c),!0;case 3:return _.fn.call(_.context,c,u),!0;case 4:return _.fn.call(_.context,c,u,d),!0;case 5:return _.fn.call(_.context,c,u,d,f),!0;case 6:return _.fn.call(_.context,c,u,d,f,p),!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,c);break;case 3:_[g].fn.call(_[g].context,c,u);break;case 4:_[g].fn.call(_[g].context,c,u,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,c,u){return n(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return n(this,h,c,u,!0)},a.prototype.removeListener=function(h,c,u,d){var f=e?e+h:h;if(!this._events[f])return this;if(!c)return o(this,f),this;var p=this._events[f];if(p.fn)p.fn===c&&(!d||p.once)&&(!u||p.context===u)&&o(this,f);else{for(var m=0,_=[],y=p.length;m<y;m++)(p[m].fn!==c||d&&!p[m].once||u&&p[m].context!==u)&&_.push(p[m]);_.length?this._events[f]=_.length===1?_[0]:_:o(this,f)}return this},a.prototype.removeAllListeners=function(h){var c;return h?(c=e?e+h:h,this._events[c]&&o(this,c)):(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})(hc);var ay=hc.exports;const Qi=lc(ay);var Go={exports:{}};Go.exports=Ws,Go.exports.default=Ws;function Ws(r,t,e){e=e||2;var i=t&&t.length,s=i?t[0]*e:r.length,n=cc(r,0,s,e,!0),o=[];if(!n||n.next===n.prev)return o;var a,l,h,c,u,d,f;if(i&&(n=dy(r,t,n,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var p=e;p<s;p+=e)u=r[p],d=r[p+1],u<a&&(a=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);f=Math.max(h-a,c-l),f=f!==0?32767/f:0}return ts(n,o,e,a,l,f,0),o}function cc(r,t,e,i,s){var n,o;if(s===Xo(r,t,e,i)>0)for(n=t;n<e;n+=i)o=fc(n,r[n],r[n+1],o);else for(n=e-i;n>=t;n-=i)o=fc(n,r[n],r[n+1],o);return o&&js(o,o.next)&&(rs(o),o=o.next),o}function Fr(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(js(e,e.next)||It(e.prev,e,e.next)===0)){if(rs(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function ts(r,t,e,i,s,n,o){if(r){!o&&n&&yy(r,i,s,n);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,n?hy(r,i,s,n):ly(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),rs(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=cy(Fr(r),t,e),ts(r,t,e,i,s,n,2)):o===2&&uy(r,t,e,i,s,n):ts(Fr(r),t,e,i,s,n,1);break}}}}function ly(r){var t=r.prev,e=r,i=r.next;if(It(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,c=s<n?s<o?s:o:n<o?n:o,u=a<l?a<h?a:h:l<h?l:h,d=s>n?s>o?s:o:n>o?n:o,f=a>l?a>h?a:h:l>h?l:h,p=i.next;p!==t;){if(p.x>=c&&p.x<=d&&p.y>=u&&p.y<=f&&pi(s,a,n,l,o,h,p.x,p.y)&&It(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function hy(r,t,e,i){var s=r.prev,n=r,o=r.next;if(It(s,n,o)>=0)return!1;for(var a=s.x,l=n.x,h=o.x,c=s.y,u=n.y,d=o.y,f=a<l?a<h?a:h:l<h?l:h,p=c<u?c<d?c:d:u<d?u:d,m=a>l?a>h?a:h:l>h?l:h,_=c>u?c>d?c:d:u>d?u:d,y=$o(f,p,t,e,i),x=$o(m,_,t,e,i),g=r.prevZ,v=r.nextZ;g&&g.z>=y&&v&&v.z<=x;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=_&&g!==s&&g!==o&&pi(a,c,l,u,h,d,g.x,g.y)&&It(g.prev,g,g.next)>=0||(g=g.prevZ,v.x>=f&&v.x<=m&&v.y>=p&&v.y<=_&&v!==s&&v!==o&&pi(a,c,l,u,h,d,v.x,v.y)&&It(v.prev,v,v.next)>=0))return!1;v=v.nextZ}for(;g&&g.z>=y;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=_&&g!==s&&g!==o&&pi(a,c,l,u,h,d,g.x,g.y)&&It(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;v&&v.z<=x;){if(v.x>=f&&v.x<=m&&v.y>=p&&v.y<=_&&v!==s&&v!==o&&pi(a,c,l,u,h,d,v.x,v.y)&&It(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function cy(r,t,e){var i=r;do{var s=i.prev,n=i.next.next;!js(s,n)&&uc(s,i,i.next,n)&&es(s,n)&&es(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),rs(i),rs(i.next),i=r=n),i=i.next}while(i!==r);return Fr(i)}function uy(r,t,e,i,s,n){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&xy(o,a)){var l=dc(o,a);o=Fr(o,o.next),l=Fr(l,l.next),ts(o,t,e,i,s,n,0),ts(l,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function dy(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=cc(r,a,l,i,!1),h===h.next&&(h.steiner=!0),s.push(vy(h));for(s.sort(fy),n=0;n<s.length;n++)e=py(s[n],e);return e}function fy(r,t){return r.x-t.x}function py(r,t){var e=my(r,t);if(!e)return t;var i=dc(e,r);return Fr(i,i.next),Fr(e,e.next)}function my(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,c=o.y,u=1/0,d;e=o;do i>=e.x&&e.x>=h&&i!==e.x&&pi(s<c?i:n,s,h,c,s<c?n:i,s,e.x,e.y)&&(d=Math.abs(s-e.y)/(i-e.x),es(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&gy(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function gy(r,t){return It(r.prev,r,t.prev)<0&&It(t.next,r,r.next)<0}function yy(r,t,e,i){var s=r;do s.z===0&&(s.z=$o(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,_y(s)}function _y(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 $o(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 vy(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 xy(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!by(r,t)&&(es(r,t)&&es(t,r)&&wy(r,t)&&(It(r.prev,r,t.prev)||It(r,t.prev,t))||js(r,t)&&It(r.prev,r,r.next)>0&&It(t.prev,t,t.next)>0)}function It(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 uc(r,t,e,i){var s=qs(It(r,t,e)),n=qs(It(r,t,i)),o=qs(It(e,i,r)),a=qs(It(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 by(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&&uc(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function es(r,t){return It(r.prev,r,r.next)<0?It(r,t,r.next)>=0&&It(r,r.prev,t)>=0:It(r,t,r.prev)<0||It(r,r.next,t)<0}function wy(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 dc(r,t){var e=new Ho(r.i,r.x,r.y),i=new Ho(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 fc(r,t,e,i){var s=new Ho(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 rs(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 Ho(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(Xo(r,0,n,e));if(s)for(var a=0,l=t.length;a<l;a++){var h=t[a]*e,c=a<l-1?t[a+1]*e:r.length;o-=Math.abs(Xo(r,h,c,e))}var u=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,f=i[a+1]*e,p=i[a+2]*e;u+=Math.abs((r[d]-r[p])*(r[f+1]-r[d+1])-(r[d]-r[f])*(r[p+1]-r[d+1]))}return o===0&&u===0?0:Math.abs((u-o)/o)};function Xo(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 Ey=Go.exports;const Ty=lc(Ey);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&&!r.nodeType&&r,n=typeof Ji=="object"&&Ji;(n.global===n||n.window===n||n.self===n)&&(e=n);var o,a=2147483647,l=36,h=1,c=26,u=38,d=700,f=72,p=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,I=String.fromCharCode,A;function C(P){throw new RangeError(g[P])}function N(P,U){for(var j=P.length,rt=[];j--;)rt[j]=U(P[j]);return rt}function S(P,U){var j=P.split("@"),rt="";j.length>1&&(rt=j[0]+"@",P=j[1]),P=P.replace(x,".");var Q=P.split("."),H=N(Q,U).join(".");return rt+H}function R(P){for(var U=[],j=0,rt=P.length,Q,H;j<rt;)Q=P.charCodeAt(j++),Q>=55296&&Q<=56319&&j<rt?(H=P.charCodeAt(j++),(H&64512)==56320?U.push(((Q&1023)<<10)+(H&1023)+65536):(U.push(Q),j--)):U.push(Q);return U}function E(P){return N(P,function(U){var j="";return U>65535&&(U-=65536,j+=I(U>>>10&1023|55296),U=56320|U&1023),j+=I(U),j}).join("")}function b(P){return P-48<10?P-22:P-65<26?P-65:P-97<26?P-97:l}function D(P,U){return P+22+75*(P<26)-((U!=0)<<5)}function F(P,U,j){var rt=0;for(P=j?w(P/d):P>>1,P+=w(P/U);P>v*c>>1;rt+=l)P=w(P/v);return w(rt+(v+1)*P/(P+u))}function G(P){var U=[],j=P.length,rt,Q=0,H=p,V=f,lt,L,O,_t,ht,vt,xt,Ye,qe;for(lt=P.lastIndexOf(m),lt<0&&(lt=0),L=0;L<lt;++L)P.charCodeAt(L)>=128&&C("not-basic"),U.push(P.charCodeAt(L));for(O=lt>0?lt+1:0;O<j;){for(_t=Q,ht=1,vt=l;O>=j&&C("invalid-input"),xt=b(P.charCodeAt(O++)),(xt>=l||xt>w((a-Q)/ht))&&C("overflow"),Q+=xt*ht,Ye=vt<=V?h:vt>=V+c?c:vt-V,!(xt<Ye);vt+=l)qe=l-Ye,ht>w(a/qe)&&C("overflow"),ht*=qe;rt=U.length+1,V=F(Q-_t,rt,_t==0),w(Q/rt)>a-H&&C("overflow"),H+=w(Q/rt),Q%=rt,U.splice(Q++,0,H)}return E(U)}function $(P){var U,j,rt,Q,H,V,lt,L,O,_t,ht,vt=[],xt,Ye,qe,ws;for(P=R(P),xt=P.length,U=p,j=0,H=f,V=0;V<xt;++V)ht=P[V],ht<128&&vt.push(I(ht));for(rt=Q=vt.length,Q&&vt.push(m);rt<xt;){for(lt=a,V=0;V<xt;++V)ht=P[V],ht>=U&&ht<lt&&(lt=ht);for(Ye=rt+1,lt-U>w((a-j)/Ye)&&C("overflow"),j+=(lt-U)*Ye,U=lt,V=0;V<xt;++V)if(ht=P[V],ht<U&&++j>a&&C("overflow"),ht==U){for(L=j,O=l;_t=O<=H?h:O>=H+c?c:O-H,!(L<_t);O+=l)ws=L-_t,qe=l-_t,vt.push(I(D(_t+ws%qe,0))),L=w(ws/qe);vt.push(I(D(L,0))),H=F(j,Ye,rt==Q),j=0,++rt}++j,++U}return vt.join("")}function B(P){return S(P,function(U){return _.test(U)?G(U.slice(4).toLowerCase()):U})}function Z(P){return S(P,function(U){return y.test(U)?"xn--"+$(U):U})}if(o={version:"1.4.1",ucs2:{decode:R,encode:E},decode:G,encode:$,toASCII:Z,toUnicode:B},i&&s)if(r.exports==i)s.exports=o;else for(A in o)o.hasOwnProperty(A)&&(i[A]=o[A]);else e.punycode=o})(Ji)}(Ks,Ks.exports);var Ay=Ks.exports,Sy=Error,Iy=EvalError,Cy=RangeError,Ry=ReferenceError,pc=SyntaxError,is=TypeError,Py=URIError,My=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(e 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 n=Object.getOwnPropertySymbols(t);if(n.length!==1||n[0]!==e||!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var o=Object.getOwnPropertyDescriptor(t,e);if(o.value!==s||o.enumerable!==!0)return!1}return!0},mc=typeof Symbol<"u"&&Symbol,By=My,Dy=function(){return typeof mc!="function"||typeof Symbol!="function"||typeof mc("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:By()},Vo={__proto__:null,foo:{}},Oy=Object,Fy=function(){return{__proto__:Vo}.foo===Vo.foo&&!(Vo instanceof Oy)},Ly="Function.prototype.bind called on incompatible ",Ny=Object.prototype.toString,Uy=Math.max,ky="[object Function]",gc=function(t,e){for(var i=[],s=0;s<t.length;s+=1)i[s]=t[s];for(var n=0;n<e.length;n+=1)i[n+t.length]=e[n];return i},Gy=function(t,e){for(var i=[],s=e,n=0;s<t.length;s+=1,n+=1)i[n]=t[s];return i},$y=function(r,t){for(var e="",i=0;i<r.length;i+=1)e+=r[i],i+1<r.length&&(e+=t);return e},Hy=function(t){var e=this;if(typeof e!="function"||Ny.apply(e)!==ky)throw new TypeError(Ly+e);for(var i=Gy(arguments,1),s,n=function(){if(this instanceof s){var c=e.apply(this,gc(i,arguments));return Object(c)===c?c:this}return e.apply(t,gc(i,arguments))},o=Uy(0,e.length-i.length),a=[],l=0;l<o;l++)a[l]="$"+l;if(s=Function("binder","return function ("+$y(a,",")+"){ return binder.apply(this,arguments); }")(n),e.prototype){var h=function(){};h.prototype=e.prototype,s.prototype=new h,h.prototype=null}return s},Xy=Hy,zo=Function.prototype.bind||Xy,Vy=Function.prototype.call,zy=Object.prototype.hasOwnProperty,Wy=zo,jy=Wy.call(Vy,zy),pt,Yy=Sy,qy=Iy,Ky=Cy,Zy=Ry,mi=pc,gi=is,Jy=Py,yc=Function,Wo=function(r){try{return yc('"use strict"; return ('+r+").constructor;")()}catch{}},Lr=Object.getOwnPropertyDescriptor;if(Lr)try{Lr({},"")}catch{Lr=null}var jo=function(){throw new gi},Qy=Lr?function(){try{return arguments.callee,jo}catch{try{return Lr(arguments,"callee").get}catch{return jo}}}():jo,yi=Dy(),t0=Fy(),kt=Object.getPrototypeOf||(t0?function(r){return r.__proto__}:null),_i={},e0=typeof Uint8Array>"u"||!kt?pt:kt(Uint8Array),Nr={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?pt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?pt:ArrayBuffer,"%ArrayIteratorPrototype%":yi&&kt?kt([][Symbol.iterator]()):pt,"%AsyncFromSyncIteratorPrototype%":pt,"%AsyncFunction%":_i,"%AsyncGenerator%":_i,"%AsyncGeneratorFunction%":_i,"%AsyncIteratorPrototype%":_i,"%Atomics%":typeof Atomics>"u"?pt:Atomics,"%BigInt%":typeof BigInt>"u"?pt:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?pt:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?pt:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?pt:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Yy,"%eval%":eval,"%EvalError%":qy,"%Float32Array%":typeof Float32Array>"u"?pt:Float32Array,"%Float64Array%":typeof Float64Array>"u"?pt:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?pt:FinalizationRegistry,"%Function%":yc,"%GeneratorFunction%":_i,"%Int8Array%":typeof Int8Array>"u"?pt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?pt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?pt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":yi&&kt?kt(kt([][Symbol.iterator]())):pt,"%JSON%":typeof JSON=="object"?JSON:pt,"%Map%":typeof Map>"u"?pt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!yi||!kt?pt:kt(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?pt:Promise,"%Proxy%":typeof Proxy>"u"?pt:Proxy,"%RangeError%":Ky,"%ReferenceError%":Zy,"%Reflect%":typeof Reflect>"u"?pt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?pt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!yi||!kt?pt:kt(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?pt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":yi&&kt?kt(""[Symbol.iterator]()):pt,"%Symbol%":yi?Symbol:pt,"%SyntaxError%":mi,"%ThrowTypeError%":Qy,"%TypedArray%":e0,"%TypeError%":gi,"%Uint8Array%":typeof Uint8Array>"u"?pt:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?pt:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?pt:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?pt:Uint32Array,"%URIError%":Jy,"%WeakMap%":typeof WeakMap>"u"?pt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?pt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?pt:WeakSet};if(kt)try{null.error}catch(r){var r0=kt(kt(r));Nr["%Error.prototype%"]=r0}var i0=function r(t){var e;if(t==="%AsyncFunction%")e=Wo("async function () {}");else if(t==="%GeneratorFunction%")e=Wo("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=Wo("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 Nr[t]=e,e},_c={__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"]},ss=zo,Zs=jy,s0=ss.call(Function.call,Array.prototype.concat),n0=ss.call(Function.apply,Array.prototype.splice),vc=ss.call(Function.call,String.prototype.replace),Js=ss.call(Function.call,String.prototype.slice),o0=ss.call(Function.call,RegExp.prototype.exec),a0=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,l0=/\\(\\)?/g,h0=function(t){var e=Js(t,0,1),i=Js(t,-1);if(e==="%"&&i!=="%")throw new mi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new mi("invalid intrinsic syntax, expected opening `%`");var s=[];return vc(t,a0,function(n,o,a,l){s[s.length]=a?vc(l,l0,"$1"):o||n}),s},c0=function(t,e){var i=t,s;if(Zs(_c,i)&&(s=_c[i],i="%"+s[0]+"%"),Zs(Nr,i)){var n=Nr[i];if(n===_i&&(n=i0(i)),typeof n>"u"&&!e)throw new gi("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:s,name:i,value:n}}throw new mi("intrinsic "+t+" does not exist!")},vi=function(t,e){if(typeof t!="string"||t.length===0)throw new gi("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new gi('"allowMissing" argument must be a boolean');if(o0(/^%?[^%]*%?$/,t)===null)throw new mi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=h0(t),s=i.length>0?i[0]:"",n=c0("%"+s+"%",e),o=n.name,a=n.value,l=!1,h=n.alias;h&&(s=h[0],n0(i,s0([0,1],h)));for(var c=1,u=!0;c<i.length;c+=1){var d=i[c],f=Js(d,0,1),p=Js(d,-1);if((f==='"'||f==="'"||f==="`"||p==='"'||p==="'"||p==="`")&&f!==p)throw new mi("property names with quotes must have matching quotes");if((d==="constructor"||!u)&&(l=!0),s+="."+d,o="%"+s+"%",Zs(Nr,o))a=Nr[o];else if(a!=null){if(!(d in a)){if(!e)throw new gi("base intrinsic for "+t+" exists, but the property is not available.");return}if(Lr&&c+1>=i.length){var m=Lr(a,d);u=!!m,u&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else u=Zs(a,d),a=a[d];u&&!l&&(Nr[o]=a)}}return a},xc={exports:{}},Yo,bc;function qo(){if(bc)return Yo;bc=1;var r=vi,t=r("%Object.defineProperty%",!0)||!1;if(t)try{t({},"a",{value:1})}catch{t=!1}return Yo=t,Yo}var u0=vi,Qs=u0("%Object.getOwnPropertyDescriptor%",!0);if(Qs)try{Qs([],"length")}catch{Qs=null}var wc=Qs,Ec=qo(),d0=pc,xi=is,Tc=wc,f0=function(t,e,i){if(!t||typeof t!="object"&&typeof t!="function")throw new xi("`obj` must be an object or a function`");if(typeof e!="string"&&typeof e!="symbol")throw new xi("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new xi("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new xi("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new xi("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new xi("`loose`, if provided, must be a boolean");var s=arguments.length>3?arguments[3]:null,n=arguments.length>4?arguments[4]:null,o=arguments.length>5?arguments[5]:null,a=arguments.length>6?arguments[6]:!1,l=!!Tc&&Tc(t,e);if(Ec)Ec(t,e,{configurable:o===null&&l?l.configurable:!o,enumerable:s===null&&l?l.enumerable:!s,value:i,writable:n===null&&l?l.writable:!n});else if(a||!s&&!n&&!o)t[e]=i;else throw new d0("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},Ko=qo(),Ac=function(){return!!Ko};Ac.hasArrayLengthDefineBug=function(){if(!Ko)return null;try{return Ko([],"length",{value:1}).length!==1}catch{return!0}};var p0=Ac,m0=vi,Sc=f0,g0=p0(),Ic=wc,Cc=is,y0=m0("%Math.floor%"),_0=function(t,e){if(typeof t!="function")throw new Cc("`fn` is not a function");if(typeof e!="number"||e<0||e>4294967295||y0(e)!==e)throw new Cc("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],s=!0,n=!0;if("length"in t&&Ic){var o=Ic(t,"length");o&&!o.configurable&&(s=!1),o&&!o.writable&&(n=!1)}return(s||n||!i)&&(g0?Sc(t,"length",e,!0,!0):Sc(t,"length",e)),t};(function(r){var t=zo,e=vi,i=_0,s=is,n=e("%Function.prototype.apply%"),o=e("%Function.prototype.call%"),a=e("%Reflect.apply%",!0)||t.call(o,n),l=qo(),h=e("%Math.max%");r.exports=function(d){if(typeof d!="function")throw new s("a function is required");var f=a(t,o,arguments);return i(f,1+h(0,d.length-(arguments.length-1)),!0)};var c=function(){return a(t,n,arguments)};l?l(r.exports,"apply",{value:c}):r.exports.apply=c})(xc);var v0=xc.exports,Rc=vi,Pc=v0,x0=Pc(Rc("String.prototype.indexOf")),b0=function(t,e){var i=Rc(t,!!e);return typeof i=="function"&&x0(t,".prototype.")>-1?Pc(i):i};const w0=oy(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Zo=typeof Map=="function"&&Map.prototype,Jo=Object.getOwnPropertyDescriptor&&Zo?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,tn=Zo&&Jo&&typeof Jo.get=="function"?Jo.get:null,Mc=Zo&&Map.prototype.forEach,Qo=typeof Set=="function"&&Set.prototype,ta=Object.getOwnPropertyDescriptor&&Qo?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,en=Qo&&ta&&typeof ta.get=="function"?ta.get:null,Bc=Qo&&Set.prototype.forEach,E0=typeof WeakMap=="function"&&WeakMap.prototype,ns=E0?WeakMap.prototype.has:null,T0=typeof WeakSet=="function"&&WeakSet.prototype,os=T0?WeakSet.prototype.has:null,A0=typeof WeakRef=="function"&&WeakRef.prototype,Dc=A0?WeakRef.prototype.deref:null,S0=Boolean.prototype.valueOf,I0=Object.prototype.toString,C0=Function.prototype.toString,R0=String.prototype.match,ea=String.prototype.slice,yr=String.prototype.replace,P0=String.prototype.toUpperCase,Oc=String.prototype.toLowerCase,Fc=RegExp.prototype.test,Lc=Array.prototype.concat,ke=Array.prototype.join,M0=Array.prototype.slice,Nc=Math.floor,ra=typeof BigInt=="function"?BigInt.prototype.valueOf:null,ia=Object.getOwnPropertySymbols,sa=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,bi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Qt=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===bi||!0)?Symbol.toStringTag:null,Uc=Object.prototype.propertyIsEnumerable,kc=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Gc(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Fc.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Nc(-r):Nc(r);if(i!==r){var s=String(i),n=ea.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 na=w0,$c=na.custom,Hc=Wc($c)?$c:null,Xc={__proto__:null,double:'"',single:"'"},B0={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},D0=function r(t,e,i,s){var n=e||{};if(or(n,"quoteStyle")&&!or(Xc,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 Yc(t,n);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Gc(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Gc(t,h):h}var c=typeof n.depth>"u"?5:n.depth;if(typeof i>"u"&&(i=0),i>=c&&c>0&&typeof t=="object")return oa(t)?"[Array]":"[Object]";var u=Z0(n,i);if(typeof s>"u")s=[];else if(jc(s,t)>=0)return"[Circular]";function d(b,D,F){if(D&&(s=M0.call(s),s.push(D)),F){var G={depth:n.depth};return or(n,"quoteStyle")&&(G.quoteStyle=n.quoteStyle),r(b,G,i+1,s)}return r(b,n,i+1,s)}if(typeof t=="function"&&!zc(t)){var f=H0(t),p=rn(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+ke.call(p,", ")+" }":"")}if(Wc(t)){var m=bi?yr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):sa.call(t);return typeof t=="object"&&!bi?as(m):m}if(Y0(t)){for(var _="<"+Oc.call(String(t.nodeName)),y=t.attributes||[],x=0;x<y.length;x++)_+=" "+y[x].name+"="+Vc(O0(y[x].value),"double",n);return _+=">",t.childNodes&&t.childNodes.length&&(_+="..."),_+="</"+Oc.call(String(t.nodeName))+">",_}if(oa(t)){if(t.length===0)return"[]";var g=rn(t,d);return u&&!K0(g)?"["+la(g,u)+"]":"[ "+ke.call(g,", ")+" ]"}if(L0(t)){var v=rn(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Uc.call(t,"cause")?"{ ["+String(t)+"] "+ke.call(Lc.call("[cause]: "+d(t.cause),v),", ")+" }":v.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+ke.call(v,", ")+" }"}if(typeof t=="object"&&o){if(Hc&&typeof t[Hc]=="function"&&na)return na(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(X0(t)){var w=[];return Mc&&Mc.call(t,function(b,D){w.push(d(D,t,!0)+" => "+d(b,t))}),qc("Map",tn.call(t),w,u)}if(W0(t)){var I=[];return Bc&&Bc.call(t,function(b){I.push(d(b,t))}),qc("Set",en.call(t),I,u)}if(V0(t))return aa("WeakMap");if(j0(t))return aa("WeakSet");if(z0(t))return aa("WeakRef");if(U0(t))return as(d(Number(t)));if(G0(t))return as(d(ra.call(t)));if(k0(t))return as(S0.call(t));if(N0(t))return as(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Ji<"u"&&t===Ji)return"{ [object globalThis] }";if(!F0(t)&&!zc(t)){var A=rn(t,d),C=kc?kc(t)===Object.prototype:t instanceof Object||t.constructor===Object,N=t instanceof Object?"":"null prototype",S=!C&&Qt&&Object(t)===t&&Qt in t?ea.call(_r(t),8,-1):N?"Object":"",R=C||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",E=R+(S||N?"["+ke.call(Lc.call([],S||[],N||[]),": ")+"] ":"");return A.length===0?E+"{}":u?E+"{"+la(A,u)+"}":E+"{ "+ke.call(A,", ")+" }"}return String(t)};function Vc(r,t,e){var i=e.quoteStyle||t,s=Xc[i];return s+r+s}function O0(r){return yr.call(String(r),/"/g,"&quot;")}function oa(r){return _r(r)==="[object Array]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function F0(r){return _r(r)==="[object Date]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function zc(r){return _r(r)==="[object RegExp]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function L0(r){return _r(r)==="[object Error]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function N0(r){return _r(r)==="[object String]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function U0(r){return _r(r)==="[object Number]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function k0(r){return _r(r)==="[object Boolean]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function Wc(r){if(bi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!sa)return!1;try{return sa.call(r),!0}catch{}return!1}function G0(r){if(!r||typeof r!="object"||!ra)return!1;try{return ra.call(r),!0}catch{}return!1}var $0=Object.prototype.hasOwnProperty||function(r){return r in this};function or(r,t){return $0.call(r,t)}function _r(r){return I0.call(r)}function H0(r){if(r.name)return r.name;var t=R0.call(C0.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function jc(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 X0(r){if(!tn||!r||typeof r!="object")return!1;try{tn.call(r);try{en.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function V0(r){if(!ns||!r||typeof r!="object")return!1;try{ns.call(r,ns);try{os.call(r,os)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function z0(r){if(!Dc||!r||typeof r!="object")return!1;try{return Dc.call(r),!0}catch{}return!1}function W0(r){if(!en||!r||typeof r!="object")return!1;try{en.call(r);try{tn.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function j0(r){if(!os||!r||typeof r!="object")return!1;try{os.call(r,os);try{ns.call(r,ns)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function Y0(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Yc(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Yc(ea.call(r,0,t.maxStringLength),t)+i}var s=B0[t.quoteStyle||"single"];s.lastIndex=0;var n=yr.call(yr.call(r,s,"\\$1"),/[\x00-\x1f]/g,q0);return Vc(n,"single",t)}function q0(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":"")+P0.call(t.toString(16))}function as(r){return"Object("+r+")"}function aa(r){return r+" { ? }"}function qc(r,t,e,i){var s=i?la(e,i):ke.call(e,", ");return r+" ("+t+") {"+s+"}"}function K0(r){for(var t=0;t<r.length;t++)if(jc(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 kE=Object.defineProperty;var GE=(Mt,Nt,Pr)=>Nt in Mt?kE(Mt,Nt,{enumerable:!0,configurable:!0,writable:!0,value:Pr}):Mt[Nt]=Pr;var Ml=(Mt,Nt,Pr)=>GE(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 io=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(io||{});const Ht=[];for(let r=0;r<256;++r)Ht.push((r+256).toString(16).slice(1));function qf(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 so;const Kf=new Uint8Array(16);function Zf(){if(!so){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");so=crypto.getRandomValues.bind(crypto)}return so(Kf)}const Jf=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),kl={randomUUID:Jf};function Qf(r,t,e){if(kl.randomUUID&&!t&&!r)return kl.randomUUID();r=r||{};const i=r.random||(r.rng||Zf)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,qf(i)}const no=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)}},tp=(r,t,e,i)=>({id:Qf(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),ep=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},rp=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},ip=(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})),sp=(r,t)=>!Mr(r.target,t.target),np=(r,t)=>{const e=ep(r,t),i=rp(r,t),s=ip(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:sp(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 op=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),s=new Set((t.created||[]).map(u=>u.id)),n=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!n.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!s.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!n.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return np(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let ap=()=>({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 lp=250,hp=r=>{const t=ap(),e=[];let i=-1,s=!1,n=0;const o=f=>{if(!s){const{changes:p}=f,m=performance.now();if(m-n>lp)e.splice(i+1),e.push(p),i=e.length-1;else{const _=e.length-1;e[_]=op(e[_],p)}n=m}s=!1};r.observe(o,{origin:fr.LOCAL});const a=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),l=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),h=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:p})=>p)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:p})=>p)),u=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),d=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f);return{canRedo:()=>e.length-1>i,canUndo:()=>i>-1,destroy:()=>r.unobserve(o),on:(f,p)=>t.on(f,p),redo:()=>{if(e.length-1>i){s=!0;const{created:f,updated:p,deleted:m}=e[i+1];l(f),c(p),d(m),t.emit("redo",e[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:f,updated:p,deleted:m}=e[i];a(f),h(p),u(m),t.emit("undo",e[i]),i-=1}}}},cp=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},f=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},p=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(A=>e.serialize(A)):e.serialize(x),I=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,I)}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))&&p("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)&&p("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)&&p("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}p("selectionChanged",h)}}),s.subscribe(y=>{!c&&y?p("mouseEnterAnnotation",o.getAnnotation(y)):c&&!y?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&y&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(y))),c=y}),a==null||a.subscribe(y=>p("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>p("createAnnotation",v)),(g||[]).forEach(v=>p("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const I=h.find(A=>A.id===v.id)||v;h=h.map(A=>A.id===v.id?w:A),p("updateAnnotation",w,I)})},{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(I=>I.id===v.id)||v))}},{origin:fr.REMOTE});const _=y=>x=>{const{updated:g}=x;y?(g||[]).forEach(v=>p("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>p("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:f,emit:p}},up=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:[]}),dp=(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(no(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(),c=()=>{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},u=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(f(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}},f=(y,x=!0)=>{if(e){const g=e.parseAll||up(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(no),x,fr.REMOTE)},p=(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(no(y)),x}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},fp="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let pp=r=>crypto.getRandomValues(new Uint8Array(r)),mp=(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;for(;l--;)if(o+=r[a[l]&i]||"",o.length===n)return o}}},gp=(r,t=21)=>mp(r,t,pp),yp=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r));for(;r--;)t+=fp[e[r]&63];return t};const _p=()=>({isGuest:!0,id:gp("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),vp=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],xp=()=>{const r=[...vp];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};yp();var bp=Object.defineProperty,wp=(r,t,e)=>t in r?bp(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Gl=(r,t,e)=>wp(r,typeof t!="symbol"?t+"":t,e);function At(){}function oo(r,t){for(const e in t)r[e]=t[e];return r}function $l(r){return r()}function Hl(){return Object.create(null)}function Pe(r){r.forEach($l)}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 Ep(r){return Object.keys(r).length===0}function Xl(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 ao(r,t,e){r.$$.on_destroy.push(Xl(t,e))}function Tp(r,t,e,i){if(r){const s=Vl(r,t,e,i);return r[0](s)}}function Vl(r,t,e,i){return r[1]&&i?oo(e.ctx.slice(),r[1](i(t))):e.ctx}function Ap(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 Sp(r,t,e,i,s,n){if(s){const o=Vl(t,e,i,n);r.p(o,s)}}function Ip(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 zl(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Cs(r){return r??""}function Me(r,t){r.appendChild(t)}function it(r,t,e){r.insertBefore(t,e||null)}function et(r){r.parentNode&&r.parentNode.removeChild(r)}function lo(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function yt(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Wl(r){return document.createTextNode(r)}function ge(){return Wl(" ")}function ye(){return Wl("")}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 Cp(r){return Array.from(r.childNodes)}function pr(r,t,e){r.classList.toggle(t,!!e)}function Rp(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Xi;function Vi(r){Xi=r}function jl(){if(!Xi)throw new Error("Function called outside component initialization");return Xi}function zi(r){jl().$$.on_mount.push(r)}function Qr(){const r=jl();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=Rp(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 Yl=[],Pp=Promise.resolve();let ho=!1;function Mp(){ho||(ho=!0,Pp.then(ql))}function co(r){ei.push(r)}const uo=new Set;let ri=0;function ql(){if(ri!==0)return;const r=Xi;do{try{for(;ri<ti.length;){const t=ti[ri];ri++,Vi(t),Bp(t.$$)}}catch(t){throw ti.length=0,ri=0,t}for(Vi(null),ti.length=0,ri=0;Rs.length;)Rs.pop()();for(let t=0;t<ei.length;t+=1){const e=ei[t];uo.has(e)||(uo.add(e),e())}ei.length=0}while(ti.length);for(;Yl.length;)Yl.pop()();ho=!1,uo.clear(),Vi(r)}function Bp(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(co)}}function Dp(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 ot(r,t){r&&r.i&&(Ps.delete(r),r.i(t))}function mt(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 ce(r){r&&r.c()}function se(r,t,e){const{fragment:i,after_update:s}=r.$$;i&&i.m(t,e),co(()=>{const n=r.$$.on_mount.map($l).filter(Ut);r.$$.on_destroy?r.$$.on_destroy.push(...n):Pe(n),r.$$.on_mount=[]}),s.forEach(co)}function ne(r,t){const e=r.$$;e.fragment!==null&&(Dp(e.after_update),Pe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Op(r,t){r.$$.dirty[0]===-1&&(ti.push(r),Mp(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function ue(r,t,e,i,s,n,o=null,a=[-1]){const l=Xi;Vi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:At,not_equal:s,bound:Hl(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Hl(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...f)=>{const p=f.length?f[0]:d;return h.ctx&&s(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&Op(r,u)),d}):[],h.update(),c=!0,Pe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Cp(t.target);h.fragment&&h.fragment.l(u),u.forEach(et)}else h.fragment&&h.fragment.c();t.intro&&ot(r.$$.fragment),se(r,t.target,t.anchor),ql()}Vi(l)}class de{constructor(){Gl(this,"$$"),Gl(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&&!Ep(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Fp="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Fp);var wt=(r=>(r.ELLIPSE="ELLIPSE",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(wt||{});const fo={},po=(r,t)=>fo[r]=t,mo=r=>fo[r.type].area(r),Lp=(r,t,e)=>fo[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}},Np={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),c=t-i,u=e-s,d=l*c+h*u,f=h*c-l*u;return d*d/(n*n)+f*f/(o*o)<=1}};po(wt.ELLIPSE,Np);const Up={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],c=i[o][1];l>e!=c>e&&t<(h-a)*(e-l)/(c-l)+a&&(s=!s)}return s}};po(wt.POLYGON,Up);const kp={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};po(wt.RECTANGLE,kp);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},Gp=(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,c,u]=s;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,f,p,m]=[l,h,c,u].map(parseFloat);return{type:wt.RECTANGLE,geometry:{x:d,y:f,w:p,h:m,bounds:{minX:d,minY:t?f-m:f,maxX:d+p,maxY:t?f:f+m}}}},$p=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}`}},Kl="http://www.w3.org/2000/svg",Zl=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},Hp=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${Kl}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},Xp=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(Kl),i=t.lookupNamespaceURI(null);return e||i?Zl(t).firstChild:Zl(Hp(t)).firstChild},Vp=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)}}},zp=r=>{const t=Xp(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}}},Wp=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return Vp(t);if(t.includes("<ellipse "))return zp(t);throw"Unsupported SVG shape: "+t},jp=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 Yp(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 go;const qp=new Uint8Array(16);function Kp(){if(!go){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");go=crypto.getRandomValues.bind(crypto)}return go(qp)}const Zp=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),Jl={randomUUID:Zp};function Ql(r,t,e){if(Jl.randomUUID&&!t&&!r)return Jl.randomUUID();r=r||{};const i=r.random||(r.rng||Kp)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Yp(i)}var th=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(th.call(r,e)&&++i&&!th.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 yo(){}function Jp(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}const si=[];function _o(r,t=yo){let e;const i=new Set;function s(a){if(Jp(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=yo){const h=[a,l];return i.add(h),i.size===1&&(e=t(s,n)||yo),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:s,update:n,subscribe:o}}const Qp=r=>{const{subscribe:t,set:e}=_o();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 eh=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(eh||{});const Ds={selected:[]},tm=(r,t,e)=>{const{subscribe:i,set:s}=_o(Ds);let n=t,o=Ds;i(p=>o=p);const a=()=>{mr(o,Ds)||s(Ds)},l=()=>{var p;return((p=o.selected)==null?void 0:p.length)===0},h=p=>{if(l())return!1;const m=typeof p=="string"?p:p.id;return o.selected.some(_=>_.id===m)},c=(p,m)=>{let _;if(Array.isArray(p)){if(_=p.map(x=>r.getAnnotation(x)).filter(Boolean),_.length<p.length){console.warn("Invalid selection: "+p.filter(x=>!_.some(g=>g.id===x)));return}}else{const x=r.getAnnotation(p);if(!x){console.warn("Invalid selection: "+p);return}_=[x]}const y=_.reduce((x,g)=>{const v=rh(g,n,e);return v==="EDIT"?[...x,{id:g.id,editable:!0}]:v==="SELECT"?[...x,{id:g.id}]:x},[]);s({selected:y,event:m})},u=(p,m)=>{const _=Array.isArray(p)?p:[p],y=_.map(x=>r.getAnnotation(x)).filter(x=>!!x);s({selected:y.map(x=>{const g=m===void 0?rh(x,n,e)==="EDIT":m;return{id:x.id,editable:g}})}),y.length!==_.length&&console.warn("Invalid selection",p)},d=p=>{if(l())return!1;const{selected:m}=o;m.some(({id:_})=>p.includes(_))&&s({selected:m.filter(({id:_})=>!p.includes(_))})},f=p=>n=p;return r.observe(({changes:p})=>d((p.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:u,setUserSelectAction:f,subscribe:i,userSelect:c}},rh=(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 em(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 vo;const rm=new Uint8Array(16);function im(){if(!vo){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");vo=crypto.getRandomValues.bind(crypto)}return vo(rm)}const sm=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),ih={randomUUID:sm};function nm(r,t,e){if(ih.randomUUID&&!t&&!r)return ih.randomUUID();r=r||{};const i=r.random||(r.rng||im)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,em(i)}const xo=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)}},om=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},am=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},lm=(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})),hm=(r,t)=>!mr(r.target,t.target),sh=(r,t)=>{const e=om(r,t),i=am(r,t),s=lm(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:hm(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 cm=(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(c=>a(c.bodiesCreated)||a(c.bodiesDeleted)||a(c.bodiesUpdated)),h=(i=s.updated)==null?void 0:i.some(c=>c.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},um=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),s=new Set((t.created||[]).map(u=>u.id)),n=new Set((t.deleted||[]).map(u=>u.id)),o=new Set((t.updated||[]).map(({oldValue:u})=>u.id)),a=new Set((t.updated||[]).filter(({oldValue:u})=>e.has(u.id)||i.has(u.id)).map(({oldValue:u})=>u.id)),l=[...(r.created||[]).filter(u=>!n.has(u.id)).map(u=>o.has(u.id)?t.updated.find(({oldValue:d})=>d.id===u.id).newValue:u),...t.created||[]],h=[...(r.deleted||[]).filter(u=>!s.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!n.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(m=>m.oldValue.id===f.id).newValue;return sh(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},bo=r=>{const t=r.id===void 0?nm():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},dm=r=>r.id!==void 0,fm=()=>{const r=new Map,t=new Map,e=[],i=(S,R={})=>{e.push({onChange:S,options:R})},s=S=>{const R=e.findIndex(E=>E.onChange==S);R>-1&&e.splice(R,1)},n=(S,R)=>{const E={origin:S,changes:{created:R.created||[],updated:R.updated||[],deleted:R.deleted||[]},state:[...r.values()]};e.forEach(b=>{cm(b,E)&&b.onChange(E)})},o=(S,R=St.LOCAL)=>{if(S.id&&r.get(S.id))throw Error(`Cannot add annotation ${S.id} - exists already`);{const E=bo(S);r.set(E.id,E),E.bodies.forEach(b=>t.set(b.id,E.id)),n(R,{created:[E]})}},a=(S,R)=>{const E=bo(typeof S=="string"?R:S),b=typeof S=="string"?S:S.id,D=b&&r.get(b);if(D){const F=sh(D,E);return b===E.id?r.set(b,E):(r.delete(b),r.set(E.id,E)),D.bodies.forEach(G=>t.delete(G.id)),E.bodies.forEach(G=>t.set(G.id,E.id)),F}else console.warn(`Cannot update annotation ${b} - does not exist`)},l=(S,R=St.LOCAL,E=St.LOCAL)=>{const b=dm(R)?E:R,D=a(S,R);D&&n(b,{updated:[D]})},h=(S,R=St.LOCAL)=>{const E=S.reduce((b,D)=>{const F=a(D);return F?[...b,F]:b},[]);E.length>0&&n(R,{updated:E})},c=(S,R=St.LOCAL)=>{const E=r.get(S.annotation);if(E){const b={...E,bodies:[...E.bodies,S]};r.set(E.id,b),t.set(S.id,b.id),n(R,{updated:[{oldValue:E,newValue:b,bodiesCreated:[S]}]})}else console.warn(`Attempt to add body to missing annotation: ${S.annotation}`)},u=()=>[...r.values()],d=(S=St.LOCAL)=>{const R=[...r.values()];r.clear(),t.clear(),n(S,{deleted:R})},f=(S,R=!0,E=St.LOCAL)=>{const b=S.map(bo);if(R){const D=[...r.values()];r.clear(),t.clear(),b.forEach(F=>{r.set(F.id,F),F.bodies.forEach(G=>t.set(G.id,F.id))}),n(E,{created:b,deleted:D})}else{const D=S.reduce((F,G)=>{const $=G.id&&r.get(G.id);return $?[...F,$]:F},[]);if(D.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${D.map(F=>F.id).join(", ")}`);b.forEach(F=>{r.set(F.id,F),F.bodies.forEach(G=>t.set(G.id,F.id))}),n(E,{created:b})}},p=S=>{const R=typeof S=="string"?S:S.id,E=r.get(R);if(E)return r.delete(R),E.bodies.forEach(b=>t.delete(b.id)),E;console.warn(`Attempt to delete missing annotation: ${R}`)},m=(S,R=St.LOCAL)=>{const E=p(S);E&&n(R,{deleted:[E]})},_=(S,R=St.LOCAL)=>{const E=S.reduce((b,D)=>{const F=p(D);return F?[...b,F]:b},[]);E.length>0&&n(R,{deleted:E})},y=S=>{const R=r.get(S.annotation);if(R){const E=R.bodies.find(b=>b.id===S.id);if(E){t.delete(E.id);const b={...R,bodies:R.bodies.filter(D=>D.id!==S.id)};return r.set(R.id,b),{oldValue:R,newValue:b,bodiesDeleted:[E]}}else console.warn(`Attempt to delete missing body ${S.id} from annotation ${S.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${S.annotation}`)},x=(S,R=St.LOCAL)=>{const E=y(S);E&&n(R,{updated:[E]})},g=(S,R=St.LOCAL)=>{const E=S.map(b=>y(b)).filter(Boolean);E.length>0&&n(R,{updated:E})},v=S=>{const R=r.get(S);return R?{...R}:void 0},w=S=>{const R=t.get(S);if(R){const E=v(R).bodies.find(b=>b.id===S);if(E)return E;console.error(`Store integrity error: body ${S} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${S}`)},I=(S,R)=>{if(S.annotation!==R.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const E=r.get(S.annotation);if(E){const b=E.bodies.find(F=>F.id===S.id),D={...E,bodies:E.bodies.map(F=>F.id===b.id?R:F)};return r.set(E.id,D),b.id!==R.id&&(t.delete(b.id),t.set(R.id,D.id)),{oldValue:E,newValue:D,bodiesUpdated:[{oldBody:b,newBody:R}]}}else console.warn(`Attempt to add body to missing annotation ${S.annotation}`)},A=(S,R,E=St.LOCAL)=>{const b=I(S,R);b&&n(E,{updated:[b]})},C=(S,R=St.LOCAL)=>{const E=S.map(b=>I({id:b.id,annotation:b.annotation},b)).filter(Boolean);n(R,{updated:E})},N=S=>{const R=r.get(S.annotation);if(R){const E={...R,target:{...R.target,...S}};return r.set(R.id,E),{oldValue:R,newValue:E,targetUpdated:{oldTarget:R.target,newTarget:S}}}else console.warn(`Attempt to update target on missing annotation: ${S.annotation}`)};return{addAnnotation:o,addBody:c,all:u,bulkAddAnnotation:f,bulkDeleteAnnotation:_,bulkDeleteBodies:g,bulkUpdateAnnotation:h,bulkUpdateBodies:C,bulkUpdateTargets:(S,R=St.LOCAL)=>{const E=S.map(b=>N(b)).filter(Boolean);E.length>0&&n(R,{updated:E})},clear:d,deleteAnnotation:m,deleteBody:x,getAnnotation:v,getBody:w,observe:i,unobserve:s,updateAnnotation:l,updateBody:A,updateTarget:(S,R=St.LOCAL)=>{const E=N(S);E&&n(R,{updated:[E]})}}},pm=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}});let mm=()=>({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 gm=250,ym=r=>{const t=mm(),e=[];let i=-1,s=!1,n=0;const o=f=>{if(!s){const{changes:p}=f,m=performance.now();if(m-n>gm)e.splice(i+1),e.push(p),i=e.length-1;else{const _=e.length-1;e[_]=um(e[_],p)}n=m}s=!1};r.observe(o,{origin:St.LOCAL});const a=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f),l=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),h=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({oldValue:p})=>p)),c=f=>f&&f.length>0&&r.bulkUpdateAnnotation(f.map(({newValue:p})=>p)),u=f=>f&&f.length>0&&r.bulkAddAnnotation(f,!1),d=f=>f&&f.length>0&&r.bulkDeleteAnnotation(f);return{canRedo:()=>e.length-1>i,canUndo:()=>i>-1,destroy:()=>r.unobserve(o),on:(f,p)=>t.on(f,p),redo:()=>{if(e.length-1>i){s=!0;const{created:f,updated:p,deleted:m}=e[i+1];l(f),c(p),d(m),t.emit("redo",e[i+1]),i+=1}},undo:()=>{if(i>-1){s=!0;const{created:f,updated:p,deleted:m}=e[i];a(f),h(p),u(m),t.emit("undo",e[i]),i-=1}}}},_m=()=>{const{subscribe:r,set:t}=_o([]);return{subscribe:r,set:t}},vm=(r,t,e,i)=>{const{hover:s,selection:n,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(y,x)=>{l.has(y)?l.get(y).push(x):l.set(y,[x])},f=(y,x)=>{const g=l.get(y);if(g){const v=g.indexOf(x);v!==-1&&g.splice(v,1)}},p=(y,x,g)=>{l.has(y)&&setTimeout(()=>{l.get(y).forEach(v=>{if(e){const w=Array.isArray(x)?x.map(A=>e.serialize(A)):e.serialize(x),I=g?g instanceof PointerEvent?g:e.serialize(g):void 0;v(w,I)}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))&&p("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)&&p("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)&&p("updateAnnotation",w,v)}),h=[...h.filter(v=>g.has(v.id)),...y.filter(({id:v})=>!x.has(v)).map(({id:v})=>o.getAnnotation(v))]}p("selectionChanged",h)}}),s.subscribe(y=>{!c&&y?p("mouseEnterAnnotation",o.getAnnotation(y)):c&&!y?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&y&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(y))),c=y}),a==null||a.subscribe(y=>p("viewportIntersect",y.map(x=>o.getAnnotation(x)))),o.observe(y=>{i&&(u&&clearTimeout(u),u=setTimeout(m,1e3));const{created:x,deleted:g}=y.changes;(x||[]).forEach(v=>p("createAnnotation",v)),(g||[]).forEach(v=>p("deleteAnnotation",v)),(y.changes.updated||[]).filter(v=>[...v.bodiesCreated||[],...v.bodiesDeleted||[],...v.bodiesUpdated||[]].length>0).forEach(({oldValue:v,newValue:w})=>{const I=h.find(A=>A.id===v.id)||v;h=h.map(A=>A.id===v.id?w:A),p("updateAnnotation",w,I)})},{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=>p("updateAnnotation",v.oldValue,v.newValue)):(g||[]).forEach(v=>p("updateAnnotation",v.newValue,v.oldValue))};return t.on("undo",_(!0)),t.on("redo",_(!1)),{on:d,off:f,emit:p}},xm=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:[]}),bm=(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(xo(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(),c=()=>{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},u=(y,x=!0)=>fetch(y).then(g=>g.json()).then(g=>(f(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}},f=(y,x=!0)=>{if(e){const g=e.parseAll||xm(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(xo),x,St.REMOTE)},p=(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(xo(y)),x}};return{addAnnotation:n,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:m,undo:t.undo,updateAnnotation:_}},wm=(r,t,e)=>typeof t=="function"?t(r,e):t,Em=(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||{}}},Tm="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Am=r=>crypto.getRandomValues(new Uint8Array(r)),Sm=(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;for(;l--;)if(o+=r[a[l]&i]||"",o.length===n)return o}}},Im=(r,t=21)=>Sm(r,t,Am),Cm=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r));for(;r--;)t+=Tm[e[r]&63];return t};const Rm=()=>({isGuest:!0,id:Im("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Pm=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}`},nh=r=>r?typeof r=="object"?{...r}:r:void 0,Mm=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:s,purpose:n,value:o,created:a,modified:l,creator:h,...c}=e;return{id:i||`temp-${Pm(e)}`,annotation:t,type:s,purpose:n,value:o,creator:nh(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),Bm=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});Cm();const Dm=(r,t={strict:!0,invertY:!1})=>({parse:e=>Om(e,t),serialize:e=>Fm(e,r,t)}),Om=(r,t={strict:!0,invertY:!1})=>{const e=r.id||Ql(),{creator:i,created:s,modified:n,body:o,...a}=r,l=Mm(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,c=Array.isArray(h.selector)?h.selector[0]:h.selector,u=(c==null?void 0:c.type)==="FragmentSelector"?Gp(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?Wp(c):void 0;return u||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:s?new Date(s):void 0,creator:nh(i),updated:n?new Date(n):void 0,...Array.isArray(a.target)?a.target[0]:a.target,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},Fm=(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?$p(i.geometry):jp(i)}catch(u){if(e.strict)throw u;h=i}const c={...r,"@context":"http://www.w3.org/ns/anno.jsonld",id:r.id,type:"Annotation",body:Bm(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 c.bodies,"annotation"in c.target&&delete c.target.annotation,c};function oh(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function ah(r){let t,e;return t=new Wi({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(){ce(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||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Lm(r){let t,e,i,s,n,o,a,l,h,c,u,d=ii(r[4].points),f=[];for(let m=0;m<d.length;m+=1)f[m]=ah(oh(r,d,m));const p=m=>mt(f[m],1,1,()=>{f[m]=null});return{c(){t=yt("polygon"),s=ge(),n=yt("polygon"),a=ge();for(let m=0;m<f.length;m+=1)f[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(lh).join(" ")),T(n,"class","a9s-inner a9s-shape-handle"),T(n,"style",r[1]),T(n,"points",o=r[4].points.map(hh).join(" "))},m(m,_){it(m,t,_),it(m,s,_),it(m,n,_),it(m,a,_);for(let y=0;y<f.length;y+=1)f[y]&&f[y].m(m,_);it(m,l,_),h=!0,c||(u=[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)})],c=!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(lh).join(" ")))&&T(t,"points",i),(!h||_&2)&&T(n,"style",r[1]),(!h||_&16&&o!==(o=r[4].points.map(hh).join(" ")))&&T(n,"points",o),_&536){d=ii(r[4].points);let y;for(y=0;y<d.length;y+=1){const x=oh(r,d,y);f[y]?(f[y].p(x,_),ot(f[y],1)):(f[y]=ah(x),f[y].c(),ot(f[y],1),f[y].m(l.parentNode,l))}for(_e(),y=d.length;y<f.length;y+=1)p(y);ve()}},i(m){if(!h){for(let _=0;_<d.length;_+=1)ot(f[_]);h=!0}},o(m){f=f.filter(Boolean);for(let _=0;_<f.length;_+=1)mt(f[_]);h=!1},d(m){m&&(et(t),et(s),et(n),et(a),et(l)),lo(f,m),c=!1,Pe(u)}}}function Nm(r){let t,e;return t=new mh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Lm,({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(){ce(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||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}const lh=r=>r.join(","),hh=r=>r.join(",");function Um(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{let m;const _=d.geometry;f==="SHAPE"?m=_.points.map(([x,g])=>[x+p[0],g+p[1]]):m=_.points.map(([x,g],v)=>f===`HANDLE-${v}`?[x+p[0],g+p[1]]:[x,g]);const y=Ms(m);return{...d,geometry:{points:m,bounds:y}}};function h(d){Ze.call(this,r,d)}function c(d){Ze.call(this,r,d)}function u(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,c,u]}class km extends de{constructor(t){super(),ue(this,t,Um,Nm,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const wo=(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 Gm(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 $m=(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}`)},Hm=(r,t)=>{$m(r,t);const{subscribe:e,set:i}=Gm(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}},ch=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function Xm(r){let t,e,i,s,n,o;return{c(){t=yt("rect"),T(t,"class",e=Cs(`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){it(a,t,l),n||(o=Dt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=Cs(`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&&et(t),n=!1,o()}}}function Vm(r){let t,e,i,s,n,o,a,l,h;return{c(){t=yt("g"),e=yt("circle"),s=yt("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=Cs(`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(c,u){it(c,t,u),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(c,u){u&1&&T(e,"cx",c[0]),u&2&&T(e,"cy",c[1]),u&12&&i!==(i=c[3]/c[2])&&T(e,"r",i),u&16&&pr(e,"touched",c[4]),u&256&&n!==(n=Cs(`a9s-handle ${c[8].class||""}`.trim())+" svelte-1sgkh33")&&T(s,"class",n),u&33&&o!==(o=c[0]-c[5]/2)&&T(s,"x",o),u&34&&a!==(a=c[1]-c[5]/2)&&T(s,"y",a),u&32&&T(s,"width",c[5]),u&32&&T(s,"height",c[5])},d(c){c&&et(t),l=!1,Pe(h)}}}function zm(r){let t;function e(s,n){return ch?Vm:Xm}let i=e()(r);return{c(){i.c(),t=ye()},m(s,n){i.m(s,n),it(s,t,n)},p(s,[n]){i.p(s,n)},i:At,o:At,d(s){s&&et(t),i.d(s)}}}function Wm(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{radius:a=30}=t,l=!1;const h=p=>{p.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(p){Ze.call(this,r,p)}function d(p){Ze.call(this,r,p)}function f(p){Ze.call(this,r,p)}return r.$$set=p=>{e(8,t=oo(oo({},t),zl(p))),"x"in p&&e(0,s=p.x),"y"in p&&e(1,n=p.y),"scale"in p&&e(2,o=p.scale),"radius"in p&&e(3,a=p.radius)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=10/o)},t=zl(t),[s,n,o,a,l,i,h,c,t,u,d,f]}class Wi extends de{constructor(t){super(),ue(this,t,Wm,zm,qt,{x:0,y:1,scale:2,radius:3})}}function jm(r){let t,e,i,s,n,o,a,l,h,c,u,d,f,p,m,_,y,x,g,v,w,I,A,C,N,S,R,E,b,D,F,G,$,B,K,P,U,j,rt,Q,H,V,lt;return B=new Wi({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),B.$on("pointerdown",function(){Ut(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),P=new Wi({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),P.$on("pointerdown",function(){Ut(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),j=new Wi({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),j.$on("pointerdown",function(){Ut(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Q=new Wi({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Q.$on("pointerdown",function(){Ut(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=yt("rect"),a=ge(),l=yt("rect"),f=ge(),p=yt("rect"),x=ge(),g=yt("rect"),A=ge(),C=yt("rect"),E=ge(),b=yt("rect"),$=ge(),ce(B.$$.fragment),K=ge(),ce(P.$$.fragment),U=ge(),ce(j.$$.fragment),rt=ge(),ce(Q.$$.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",c=r[4].y),T(l,"width",u=r[4].w),T(l,"height",d=r[4].h),T(p,"class","a9s-edge-handle a9s-edge-handle-top"),T(p,"x",m=r[4].x),T(p,"y",_=r[4].y),T(p,"height",1),T(p,"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",I=r[4].h),T(g,"width",1),T(C,"class","a9s-edge-handle a9s-edge-handle-bottom"),T(C,"x",N=r[4].x),T(C,"y",S=r[4].y+r[4].h),T(C,"height",1),T(C,"width",R=r[4].w),T(b,"class","a9s-edge-handle a9s-edge-handle-left"),T(b,"x",D=r[4].x),T(b,"y",F=r[4].y),T(b,"height",G=r[4].h),T(b,"width",1)},m(L,O){it(L,t,O),it(L,a,O),it(L,l,O),it(L,f,O),it(L,p,O),it(L,x,O),it(L,g,O),it(L,A,O),it(L,C,O),it(L,E,O),it(L,b,O),it(L,$,O),se(B,L,O),it(L,K,O),se(P,L,O),it(L,U,O),se(j,L,O),it(L,rt,O),se(Q,L,O),H=!0,V||(lt=[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(p,"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(C,"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)})],V=!0)},p(L,O){r=L,(!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&&c!==(c=r[4].y))&&T(l,"y",c),(!H||O&16&&u!==(u=r[4].w))&&T(l,"width",u),(!H||O&16&&d!==(d=r[4].h))&&T(l,"height",d),(!H||O&16&&m!==(m=r[4].x))&&T(p,"x",m),(!H||O&16&&_!==(_=r[4].y))&&T(p,"y",_),(!H||O&16&&y!==(y=r[4].w))&&T(p,"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&&I!==(I=r[4].h))&&T(g,"height",I),(!H||O&16&&N!==(N=r[4].x))&&T(C,"x",N),(!H||O&16&&S!==(S=r[4].y+r[4].h))&&T(C,"y",S),(!H||O&16&&R!==(R=r[4].w))&&T(C,"width",R),(!H||O&16&&D!==(D=r[4].x))&&T(b,"x",D),(!H||O&16&&F!==(F=r[4].y))&&T(b,"y",F),(!H||O&16&&G!==(G=r[4].h))&&T(b,"height",G);const _t={};O&16&&(_t.x=r[4].x),O&16&&(_t.y=r[4].y),O&8&&(_t.scale=r[3]),B.$set(_t);const ht={};O&16&&(ht.x=r[4].x+r[4].w),O&16&&(ht.y=r[4].y),O&8&&(ht.scale=r[3]),P.$set(ht);const vt={};O&16&&(vt.x=r[4].x+r[4].w),O&16&&(vt.y=r[4].y+r[4].h),O&8&&(vt.scale=r[3]),j.$set(vt);const xt={};O&16&&(xt.x=r[4].x),O&16&&(xt.y=r[4].y+r[4].h),O&8&&(xt.scale=r[3]),Q.$set(xt)},i(L){H||(ot(B.$$.fragment,L),ot(P.$$.fragment,L),ot(j.$$.fragment,L),ot(Q.$$.fragment,L),H=!0)},o(L){mt(B.$$.fragment,L),mt(P.$$.fragment,L),mt(j.$$.fragment,L),mt(Q.$$.fragment,L),H=!1},d(L){L&&(et(t),et(a),et(l),et(f),et(p),et(x),et(g),et(A),et(C),et(E),et(b),et($),et(K),et(U),et(rt)),ne(B,L),ne(P,L),ne(j,L),ne(Q,L),V=!1,Pe(lt)}}}function Ym(r){let t,e;return t=new mh({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[jm,({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(){ce(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||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function qm(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{const m=d.geometry.bounds;let[_,y]=[m.minX,m.minY],[x,g]=[m.maxX,m.maxY];const[v,w]=p;if(f==="SHAPE")_+=v,x+=v,y+=w,g+=w;else{switch(f){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{y+=w;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=w;break}}switch(f){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{_+=v;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{x+=v;break}}}const I=Math.min(_,x),A=Math.min(y,g),C=Math.abs(x-_),N=Math.abs(g-y);return{...d,geometry:{x:I,y:A,w:C,h:N,bounds:{minX:I,minY:A,maxX:I+C,maxY:A+N}}}};function h(d){Ze.call(this,r,d)}function c(d){Ze.call(this,r,d)}function u(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,c,u]}class Km extends de{constructor(t){super(),ue(this,t,qm,Ym,qt,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const uh=new Map([[wt.RECTANGLE,Km],[wt.POLYGON,km]]),dh=r=>uh.get(r.type),fh=(r,t)=>uh.set(r,t),Zm=r=>({}),ph=r=>({grab:r[0]});function Jm(r){let t,e,i,s;const n=r[7].default,o=Tp(n,r,r[6],ph);return{c(){t=yt("g"),o&&o.c(),T(t,"class","a9s-annotation selected")},m(a,l){it(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)&&Sp(o,n,a,a[6],e?Ap(n,a[6],l,Zm):Ip(a[6]),ph)},i(a){e||(ot(o,a),e=!0)},o(a){mt(o,a),e=!1},d(a){a&&et(t),o&&o.d(a),i=!1,Pe(s)}}}function Qm(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Qr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,c,u;const d=m=>_=>{h=m,c=l.elementToImage(_.offsetX,_.offsetY),u=o,_.target.setPointerCapture(_.pointerId),n("grab",_)},f=m=>{if(h){const[_,y]=l.elementToImage(m.offsetX,m.offsetY),x=[_-c[0],y-c[1]];e(3,o=a(u,h,x)),n("change",o)}},p=m=>{m.target.releasePointerCapture(m.pointerId),h=void 0,u=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,f,p,o,a,l,s,i]}class mh extends de{constructor(t){super(),ue(this,t,Qm,Jm,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 tg(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:c}=t,u;return zi(()=>(e(6,u=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:c}})),u.$on("change",d=>{u.$$set({shape:d.detail}),s("change",d.detail)}),u.$on("grab",d=>s("grab",d.detail)),u.$on("release",d=>s("release",d.detail)),()=>{u.$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,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=Os(n,a)),r.$$.dirty&65&&n&&(u==null||u.$set({shape:n.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[n,o,a,l,h,c,u,i]}class eg extends de{constructor(t){super(),ue(this,t,tg,null,qt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function rg(r,t,e){const i=Qr();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return zi(()=>{const c=n.closest("svg"),u=[],d=(f,p,m)=>{c==null||c.addEventListener(f,p,m),u.push(()=>c==null?void 0:c.removeEventListener(f,p,m))};return e(5,h=new o({target:n,props:{addEventListener:d,drawingMode:s,transform:a,viewportScale:l}})),h.$on("create",f=>i("create",f.detail)),()=>{u.forEach(f=>f()),h.$destroy()}}),r.$$set=c=>{"drawingMode"in c&&e(0,s=c.drawingMode),"target"in c&&e(1,n=c.target),"tool"in c&&e(2,o=c.tool),"transform"in c&&e(3,a=c.transform),"viewportScale"in c&&e(4,l=c.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 ig extends de{constructor(t){super(),ue(this,t,rg,null,qt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function gh(r){let t,e;return{c(){t=yt("rect"),e=yt("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){it(i,t,s),it(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&&(et(t),et(e))}}}function sg(r){let t,e=r[0]&&gh(r);return{c(){t=yt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[0]?e?e.p(i,s):(e=gh(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&et(t),e&&e.d()}}}function ng(r,t,e){const i=Qr();let{addEventListener:s}=t,{drawingMode:n}=t,{transform:o}=t,a,l,h,c,u,d,f;const p=x=>{const g=x;a=performance.now(),n==="drag"&&(e(0,l=o.elementToImage(g.offsetX,g.offsetY)),h=l,e(1,c=l[0]),e(2,u=l[1]),e(3,d=1),e(4,f=1))},m=x=>{const g=x;l&&(h=o.elementToImage(g.offsetX,g.offsetY),e(1,c=Math.min(h[0],l[0])),e(2,u=Math.min(h[1],l[1])),e(3,d=Math.abs(h[0]-l[0])),e(4,f=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,c=l[0]),e(2,u=l[1]),e(3,d=1),e(4,f=1))}else l&&(v>300||d*f>100?(g.stopPropagation(),y()):(e(0,l=void 0),h=void 0))},y=()=>{if(d*f>15){const x={type:wt.RECTANGLE,geometry:{bounds:{minX:c,minY:u,maxX:c+d,maxY:u+f},x:c,y:u,w:d,h:f}};i("create",x)}e(0,l=void 0),h=void 0};return zi(()=>{s("pointerdown",p),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,c,u,d,f,s,n,o]}class og extends de{constructor(t){super(),ue(this,t,ng,sg,qt,{addEventListener:5,drawingMode:6,transform:7})}}function Eo(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 yh(r){let t,e,i,s,n,o=r[2]&&_h(r);return{c(){t=yt("polygon"),i=yt("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){it(a,t,l),it(a,i,l),o&&o.m(a,l),it(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=_h(a),o.c(),o.m(n.parentNode,n)):o&&(o.d(1),o=null)},d(a){a&&(et(t),et(i),et(n)),o&&o.d(a)}}}function _h(r){let t,e,i;return{c(){t=yt("rect"),T(t,"class","a9s-corner-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){it(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&&et(t)}}}function ag(r){let t,e=r[1]&&yh(Eo(r));return{c(){t=yt("g"),e&&e.c(),T(t,"class","a9s-annotation a9s-rubberband")},m(i,s){it(i,t,s),e&&e.m(t,null)},p(i,[s]){i[1]?e?e.p(Eo(i),s):(e=yh(Eo(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:At,o:At,d(i){i&&et(t),e&&e.d()}}}const lg=20,hg=1500;function cg(r,t,e){let i;const s=Qr();let{addEventListener:n}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c=[],u,d,f=!1;const p=g=>{const v=g,{timeStamp:w,offsetX:I,offsetY:A}=v;if(h={timeStamp:w,offsetX:I,offsetY:A},o==="drag"&&c.length===0){const C=a.elementToImage(v.offsetX,v.offsetY);c.push(C),e(1,u=C)}},m=g=>{const v=g;if(d&&clearTimeout(d),c.length>0){if(e(1,u=a.elementToImage(v.offsetX,v.offsetY)),c.length>2){const w=wo(u,c[0])*l;e(2,f=w<lg)}v.pointerType==="touch"&&(d=setTimeout(()=>{y()},hg))}},_=g=>{const v=g;if(d&&clearTimeout(d),o==="click"){const w=v.timeStamp-h.timeStamp,I=wo([h.offsetX,h.offsetY],[v.offsetX,v.offsetY]);if(w>300||I>15)return;if(f)x();else if(c.length===0){const A=a.elementToImage(v.offsetX,v.offsetY);c.push(A),e(1,u=A)}else c.push(u)}else{if(c.length===1&&wo(c[0],u)<=4){e(0,c=[]),e(1,u=void 0);return}v.stopImmediatePropagation(),f?x():c.push(u)}},y=()=>{if(!u)return;const g=[...c,u],v={type:wt.POLYGON,geometry:{bounds:Ms(g),points:g}};mo(v)>4&&(e(0,c=[]),e(1,u=void 0),s("create",v))},x=()=>{const g={type:wt.POLYGON,geometry:{bounds:Ms(c),points:[...c]}};e(0,c=[]),e(1,u=void 0),s("create",g)};return zi(()=>{n("pointerdown",p,!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)},[c,u,f,i,n,o,a,l]}class ug extends de{constructor(t){super(),ue(this,t,cg,ag,qt,{addEventListener:4,drawingMode:5,transform:6,viewportScale:7})}}const To=new Map([["rectangle",{tool:og}],["polygon",{tool:ug}]]),Fs=()=>[...To.keys()],Ls=r=>To.get(r),vh=(r,t,e)=>To.set(r,{tool:t,opts:e});function dg(r){let t,e,i,s,n;return{c(){t=yt("g"),e=yt("ellipse"),s=yt("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){it(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&&et(t)}}}function fg(r,t,e){let i,{annotation:s}=t,{geom:n}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:c}=n;return r.$$set=u=>{"annotation"in u&&e(0,s=u.annotation),"geom"in u&&e(6,n=u.geom),"style"in u&&e(7,o=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=Os(s,o))},[s,i,a,l,h,c,n,o]}class pg extends de{constructor(t){super(),ue(this,t,fg,dg,qt,{annotation:0,geom:6,style:7})}}function mg(r){let t,e,i,s,n;return{c(){t=yt("g"),e=yt("polygon"),s=yt("polygon"),T(e,"class","a9s-outer"),T(e,"style",i=r[1]?"display:none;":void 0),T(e,"points",r[2].map(gg).join(" ")),T(s,"class","a9s-inner"),T(s,"style",r[1]),T(s,"points",r[2].map(yg).join(" ")),T(t,"class","a9s-annotation"),T(t,"data-id",n=r[0].id)},m(o,a){it(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&&et(t)}}}const gg=r=>r.join(","),yg=r=>r.join(",");function _g(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 vg extends de{constructor(t){super(),ue(this,t,_g,mg,qt,{annotation:0,geom:3,style:4})}}function xg(r){let t,e,i,s,n;return{c(){t=yt("g"),e=yt("rect"),s=yt("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){it(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&&et(t)}}}function bg(r,t,e){let i,s,n,o,a,{annotation:l}=t,{geom:h}=t,{style:c}=t;return r.$$set=u=>{"annotation"in u&&e(0,l=u.annotation),"geom"in u&&e(6,h=u.geom),"style"in u&&e(7,c=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=Os(l,c)),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,c]}class wg extends de{constructor(t){super(),ue(this,t,bg,xg,qt,{annotation:0,geom:6,style:7})}}const Eg=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]}}),Tg=250,Ag=(r,t)=>{const e=Qr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:s=>{if(performance.now()-i<Tg){const{x:n,y:o}=xh(s,r),a=t.getAt(n,o);a?e("click",{originalEvent:s,annotation:a}):e("click",{originalEvent:s})}}}},xh=(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[37]=t[e];const s=i[23](i[37].target.selector);return i[38]=s,i}function wh(r,t,e){const i=r.slice();return i[41]=t[e],i}function Ao(r){const t=r.slice(),e=t[41].target.selector;return t[44]=e,t}function Eh(r){let t=r[41].id,e,i,s=Th(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&32768&&qt(t,t=n[41].id)?(_e(),mt(s,1,1,At),ve(),s=Th(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s.d(n)}}}function Sg(r){let t,e;return t=new vg({props:{annotation:r[41],geom:r[44].geometry,style:r[1]}}),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){const n={};s[0]&32768&&(n.annotation=i[41]),s[0]&32768&&(n.geom=i[44].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Ig(r){let t,e;return t=new wg({props:{annotation:r[41],geom:r[44].geometry,style:r[1]}}),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){const n={};s[0]&32768&&(n.annotation=i[41]),s[0]&32768&&(n.geom=i[44].geometry),s[0]&2&&(n.style=i[1]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Cg(r){var t;let e,i;return e=new pg({props:{annotation:r[41],geom:(t=r[44])==null?void 0:t.geometry,style:r[1]}}),{c(){ce(e.$$.fragment)},m(s,n){se(e,s,n),i=!0},p(s,n){var o;const a={};n[0]&32768&&(a.annotation=s[41]),n[0]&32768&&(a.geom=(o=s[44])==null?void 0:o.geometry),n[0]&2&&(a.style=s[1]),e.$set(a)},i(s){i||(ot(e.$$.fragment,s),i=!0)},o(s){mt(e.$$.fragment,s),i=!1},d(s){ne(e,s)}}}function Th(r){let t,e,i,s;const n=[Cg,Ig,Sg],o=[];function a(l,h){var c,u,d;return((c=l[44])==null?void 0:c.type)===wt.ELLIPSE?0:((u=l[44])==null?void 0:u.type)===wt.RECTANGLE?1:((d=l[44])==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),it(l,i,h),s=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(_e(),mt(o[c],1,1,()=>{o[c]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){mt(e),s=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function Ah(r){let t=Je(r[41])&&!r[8](r[41]),e,i,s=t&&Eh(Ao(r));return{c(){s&&s.c(),e=ye()},m(n,o){s&&s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&33024&&(t=Je(n[41])&&!n[8](n[41])),t?s?(s.p(Ao(n),o),o[0]&33024&&ot(s,1)):(s=Eh(Ao(n)),s.c(),ot(s,1),s.m(e.parentNode,e)):s&&(_e(),mt(s,1,1,()=>{s=null}),ve())},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s&&s.d(n)}}}function Sh(r){let t,e,i,s;const n=[Pg,Rg],o=[];function a(l,h){return l[7]?0:l[13]&&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),it(l,i,h),s=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(_e(),mt(o[c],1,1,()=>{o[c]=null}),ve()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),ot(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(ot(e),s=!0)},o(l){mt(e),s=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function Rg(r){let t=r[2],e,i,s=Ih(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&4&&qt(t,t=n[2])?(_e(),mt(s,1,1,At),ve(),s=Ih(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s.d(n)}}}function Pg(r){let t,e,i=ii(r[7]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Ph(bh(r,i,o));const n=o=>mt(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);it(o,t,a),e=!0},p(o,a){if(a[0]&10553506){i=ii(o[7]);let l;for(l=0;l<i.length;l+=1){const h=bh(o,i,l);s[l]?(s[l].p(h,a),ot(s[l],1)):(s[l]=Ph(h),s[l].c(),ot(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)ot(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)mt(s[a]);e=!1},d(o){o&&et(t),lo(s,o)}}}function Ih(r){let t,e;return t=new ig({props:{target:r[5],tool:r[13],drawingMode:r[12],transform:r[11],viewportScale:r[16]}}),t.$on("create",r[20]),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){const n={};s[0]&32&&(n.target=i[5]),s[0]&8192&&(n.tool=i[13]),s[0]&4096&&(n.drawingMode=i[12]),s[0]&2048&&(n.transform=i[11]),s[0]&65536&&(n.viewportScale=i[16]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Ch(r){let t=r[37].id,e,i,s=Rh(r);return{c(){s.c(),e=ye()},m(n,o){s.m(n,o),it(n,e,o),i=!0},p(n,o){o[0]&128&&qt(t,t=n[37].id)?(_e(),mt(s,1,1,At),ve(),s=Rh(n),s.c(),ot(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(ot(s),i=!0)},o(n){mt(s),i=!1},d(n){n&&et(e),s.d(n)}}}function Rh(r){let t,e;return t=new eg({props:{target:r[5],editor:r[23](r[37].target.selector),annotation:r[37],style:r[1],transform:r[11],viewportScale:r[16]}}),t.$on("change",function(){Ut(r[21](r[37]))&&r[21](r[37]).apply(this,arguments)}),{c(){ce(t.$$.fragment)},m(i,s){se(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&32&&(n.target=r[5]),s[0]&128&&(n.editor=r[23](r[37].target.selector)),s[0]&128&&(n.annotation=r[37]),s[0]&2&&(n.style=r[1]),s[0]&2048&&(n.transform=r[11]),s[0]&65536&&(n.viewportScale=r[16]),t.$set(n)},i(i){e||(ot(t.$$.fragment,i),e=!0)},o(i){mt(t.$$.fragment,i),e=!1},d(i){ne(t,i)}}}function Ph(r){let t,e,i=r[38]&&Ch(r);return{c(){i&&i.c(),t=ye()},m(s,n){i&&i.m(s,n),it(s,t,n),e=!0},p(s,n){s[38]?i?(i.p(s,n),n[0]&128&&ot(i,1)):(i=Ch(s),i.c(),ot(i,1),i.m(t.parentNode,t)):i&&(_e(),mt(i,1,1,()=>{i=null}),ve())},i(s){e||(ot(i),e=!0)},o(s){mt(i),e=!1},d(s){s&&et(t),i&&i.d(s)}}}function Mg(r){let t,e,i,s,n,o,a=ii(r[15].filter(r[32])),l=[];for(let u=0;u<a.length;u+=1)l[u]=Ah(wh(r,a,u));const h=u=>mt(l[u],1,1,()=>{l[u]=null});let c=r[5]&&Sh(r);return{c(){t=yt("svg"),e=yt("g");for(let u=0;u<l.length;u+=1)l[u].c();i=yt("g"),c&&c.c(),T(i,"class","drawing"),T(t,"class","a9s-annotationlayer"),pr(t,"drawing",r[13]),pr(t,"hidden",!r[3]),pr(t,"hover",r[14])},m(u,d){it(u,t,d),Me(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);Me(t,i),c&&c.m(i,null),r[33](i),r[34](t),s=!0,n||(o=[Dt(t,"pointerup",function(){Ut(r[9])&&r[9].apply(this,arguments)}),Dt(t,"pointerdown",function(){Ut(r[10])&&r[10].apply(this,arguments)}),Dt(t,"pointermove",r[22])],n=!0)},p(u,d){if(r=u,d[0]&33026){a=ii(r[15].filter(r[32]));let f;for(f=0;f<a.length;f+=1){const p=wh(r,a,f);l[f]?(l[f].p(p,d),ot(l[f],1)):(l[f]=Ah(p),l[f].c(),ot(l[f],1),l[f].m(e,null))}for(_e(),f=a.length;f<l.length;f+=1)h(f);ve()}r[5]?c?(c.p(r,d),d[0]&32&&ot(c,1)):(c=Sh(r),c.c(),ot(c,1),c.m(i,null)):c&&(_e(),mt(c,1,1,()=>{c=null}),ve()),(!s||d[0]&8192)&&pr(t,"drawing",r[13]),(!s||d[0]&8)&&pr(t,"hidden",!r[3]),(!s||d[0]&16384)&&pr(t,"hover",r[14])},i(u){if(!s){for(let d=0;d<a.length;d+=1)ot(l[d]);ot(c),s=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)mt(l[d]);mt(c),s=!1},d(u){u&&et(t),lo(l,u),c&&c.d(),r[33](null),r[34](null),n=!1,Pe(o)}}}function Bg(r,t,e){let i,s,n,o,a,l,h,c,u,d,f,p=At,m=()=>(p(),p=Xl(E,V=>e(16,f=V)),E);r.$$.on_destroy.push(()=>p());let{drawingEnabled:_}=t,{image:y}=t,{preferredDrawingMode:x}=t,{state:g}=t,{style:v=void 0}=t,{toolName:w=Fs()[0]}=t,{user:I}=t,{visible:A=!0}=t;const C=()=>w,N=()=>_;let S,R,E;zi(()=>m(e(6,E=Hm(y,R))));const{hover:b,selection:D,store:F}=g;ao(r,b,V=>e(14,c=V)),ao(r,D,V=>e(31,u=V)),ao(r,F,V=>e(15,d=V));let G,$;const B=V=>{G&&F.unobserve(G);const lt=V.filter(({editable:L})=>L).map(({id:L})=>L);lt.length>0?(e(7,$=lt.map(L=>F.getAnnotation(L)).filter(L=>L&&Je(L))),G=L=>{const{updated:O}=L.changes;e(7,$=O==null?void 0:O.map(_t=>_t.newValue))},F.observe(G,{annotations:lt})):e(7,$=void 0)},K=V=>{const lt=Ql(),L={id:lt,bodies:[],target:{annotation:lt,selector:V.detail,creator:I,created:new Date}};F.addAnnotation(L),D.setSelected(L.id)},P=V=>lt=>{var L;const{target:O}=V,_t=10*60*1e3,ht=((L=O.creator)==null?void 0:L.id)!==I.id||!O.created||new Date().getTime()-O.created.getTime()>_t;F.updateTarget({...O,selector:lt.detail,created:ht?O.created:new Date,updated:ht?new Date:void 0,updatedBy:ht?I:void 0})},U=V=>{const{x:lt,y:L}=xh(V,R),O=F.getAt(lt,L);O?c!==O.id&&b.set(O.id):b.set(void 0)},j=V=>dh(V),rt=V=>Je(V);function Q(V){Rs[V?"unshift":"push"](()=>{S=V,e(5,S)})}function H(V){Rs[V?"unshift":"push"](()=>{R=V,e(4,R)})}return r.$$set=V=>{"drawingEnabled"in V&&e(0,_=V.drawingEnabled),"image"in V&&e(24,y=V.image),"preferredDrawingMode"in V&&e(25,x=V.preferredDrawingMode),"state"in V&&e(26,g=V.state),"style"in V&&e(1,v=V.style),"toolName"in V&&e(2,w=V.toolName),"user"in V&&e(27,I=V.user),"visible"in V&&e(3,A=V.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(13,{tool:i,opts:s}=Ls(w)||{tool:void 0,opts:void 0},i,(e(30,s),e(2,w))),r.$$.dirty[0]&1107296256&&e(12,n=(s==null?void 0:s.drawingMode)||x),r.$$.dirty[0]&16&&e(11,o=Eg(R)),r.$$.dirty[0]&16&&e(10,{onPointerDown:a,onPointerUp:l}=Ag(R,F),a,(e(9,l),e(4,R))),r.$$.dirty[1]&1&&e(8,h=V=>u.selected.find(lt=>lt.id===V.id&&lt.editable)),r.$$.dirty[1]&1&&B(u.selected)},[_,v,w,A,R,S,E,$,h,l,a,o,n,i,c,d,f,b,D,F,K,P,U,j,y,x,g,I,C,N,s,u,rt,Q,H]}class Dg extends de{constructor(t){super(),ue(this,t,Bg,Mg,qt,{drawingEnabled:0,image:24,preferredDrawingMode:25,state:26,style:1,toolName:2,user:27,visible:3,getDrawingTool:28,isDrawingEnabled:29},null,[-1,-1])}get getDrawingTool(){return this.$$.ctx[28]}get isDrawingEnabled(){return this.$$.ctx[29]}}function Mh(r,t,e=0,i=r.length-1,s=Og){for(;i>e;){if(i-e>600){const l=i-e+1,h=t-e+1,c=Math.log(l),u=.5*Math.exp(2*c/3),d=.5*Math.sqrt(c*u*(l-u)/l)*(h-l/2<0?-1:1),f=Math.max(e,Math.floor(t-h*u/l+d)),p=Math.min(i,Math.floor(t+(l-h)*u/l+d));Mh(r,t,f,p,s)}const n=r[t];let o=e,a=i;for(ji(r,e,t),s(r[i],n)>0&&ji(r,e,i);o<a;){for(ji(r,o,a),o++,a--;s(r[o],n)<0;)o++;for(;s(r[a],n)>0;)a--}s(r[e],n)===0?ji(r,e,a):(a++,ji(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function ji(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function Og(r,t){return r<t?-1:r>t?1:0}class Fg{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):Io(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||Io(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 c=Lg(t,i.children,e);if(c!==-1)return i.children.splice(c,1),n.push(i),this._condense(n),this}!h&&!i.leaf&&Io(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));Bh(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);Bh(t,c,u,l,this.compareMinY);for(let d=c;d<=u;d+=l){const f=Math.min(d+l-1,u);a.children.push(this._build(t,d,f,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],c=So(h),u=kg(t,h)-c;u<o?(o=u,n=c<n?c:n,a=h):u===o&&c<n&&(n=c,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),qi(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=Yi(t,0,a,this.toBBox),h=Yi(t,a,i,this.toBBox),c=Gg(l,h),u=So(l)+So(h);c<n?(n=c,s=a,o=u<o?u:o):c===n&&u<o&&(o=u,s=a)}return s||i-e}_chooseSplitAxis(t,e,i){const s=t.leaf?this.compareMinX:Ng,n=t.leaf?this.compareMinY:Ug,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=Yi(t,0,e,n),a=Yi(t,i-e,i,n);let l=Ns(o)+Ns(a);for(let h=e;h<i-e;h++){const c=t.children[h];qi(o,t.leaf?n(c):c),l+=Ns(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];qi(a,t.leaf?n(c):c),l+=Ns(a)}return l}_adjustParentBBoxes(t,e,i){for(let s=i;s>=0;s--)qi(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 Lg(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){Yi(r,0,r.children.length,t,r)}function Yi(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];qi(s,r.leaf?i(o):o)}return s}function qi(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 Ng(r,t){return r.minX-t.minX}function Ug(r,t){return r.minY-t.minY}function So(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Ns(r){return r.maxX-r.minX+(r.maxY-r.minY)}function kg(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 Gg(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 Io(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 Bh(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;Mh(r,o,t,e,s),n.push(t,o,o,e)}}const $g=()=>{const r=new Fg,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:c}=o.selector.geometry.bounds,u={minX:a,minY:l,maxX:h,maxY:c,target:o};r.insert(u),t.set(o.annotation,u)},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||Lp(h.selector,o,a));if(l.length>0)return l.sort((h,c)=>mo(h.selector)-mo(c.selector)),l[0]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(c=>c.target),insert:s,remove:n,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,c)=>{if(Bs(c)){const{minX:u,minY:d,maxX:f,maxY:p}=c.selector.geometry.bounds;return[...h,{minX:u,minY:d,maxX:f,maxY:p,target:c}]}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)}}},Dh=r=>{const t=fm(),e=$g(),i=tm(t,r.userSelectAction,r.adapter),s=Qp(t),n=_m();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(c=>t.getAnnotation(c.annotation))},selection:i,hover:s,viewport:n}},Hg=r=>{const t=Dh(r);return{...t,store:pm(t.store)}},Xg=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},Oh=r=>{const t=Xg(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},Fh=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?Oh(r):e),Lh=(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}),Nh=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,Uh=(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=()=>{Nh?e.removeEventListener("keydown",s):e.removeEventListener("keydown",i)};return Nh?e.addEventListener("keydown",s):e.addEventListener("keydown",i),{destroy:n}},Vg=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=Lh(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:eh.EDIT,theme:"light"}),s=Hg(i),{selection:n,store:o}=s,a=ym(o),l=vm(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 c=Uh(a);let u=Rm();Fh(e,h,i.theme);const d=new Dg({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:s,style:i.style,user:u}});d.$on("click",E=>{const{originalEvent:b,annotation:D}=E.detail;D?n.userSelect(D.id,b):n.isEmpty()||n.clear()});const f=bm(s,a,i.adapter),p=()=>{d.$set({drawingEnabled:!1}),setTimeout(()=>d.$set({drawingEnabled:!0}),1)},m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},_=()=>d.getDrawingTool(),y=()=>u,x=()=>d.isDrawingEnabled(),g=(E,b,D)=>vh(E,b,D),v=(E,b)=>fh(E,b),w=E=>{if(!Ls(E))throw`No drawing tool named ${E}`;d.$set({toolName:E})},I=E=>d.$set({drawingEnabled:E}),A=E=>{console.warn("Filter not implemented yet")},C=E=>d.$set({style:E}),N=E=>Fh(e,h,E),S=E=>{u=E,d.$set({user:E})},R=E=>d.$set({visible:E});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:_,getUser:y,isDrawingEnabled:x,listDrawingTools:Fs,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:v,setDrawingEnabled:I,setDrawingTool:w,setFilter:A,setStyle:C,setTheme:N,setUser:S,setVisible:R,element:h,state:s}};function Be(){}function Co(r,t){for(const e in t)r[e]=t[e];return r}function kh(r){return r()}function Gh(){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 zg(r){return Object.keys(r).length===0}function Wg(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 Ro(r,t,e){r.$$.on_destroy.push(Wg(t,e))}function $h(r,t,e,i){if(r){const s=Hh(r,t,e,i);return r[0](s)}}function Hh(r,t,e,i){return r[1]&&i?Co(e.ctx.slice(),r[1](i(t))):e.ctx}function Xh(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 Vh(r,t,e,i,s,n){if(s){const o=Hh(t,e,i,n);r.p(o,s)}}function zh(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 Wh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ks(r){return r??""}const jg=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function tr(r,t){r.appendChild(t)}function ft(r,t,e){r.insertBefore(t,e||null)}function ct(r){r.parentNode&&r.parentNode.removeChild(r)}function Po(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 Mo(r){return document.createTextNode(r)}function xe(){return Mo(" ")}function er(){return Mo("")}function zt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function M(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function Yg(r){return Array.from(r.childNodes)}function qg(r,t){t=""+t,r.data!==t&&(r.data=t)}function Gs(r,t,e){r.classList.toggle(t,!!e)}function Kg(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Ki;function Zi(r){Ki=r}function Bo(){if(!Ki)throw new Error("Function called outside component initialization");return Ki}function $s(r){Bo().$$.on_mount.push(r)}function Zg(r){Bo().$$.on_destroy.push(r)}function Hs(){const r=Bo();return(t,e,{cancelable:i=!1}={})=>{const s=r.$$.callbacks[t];if(s){const n=Kg(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 jh=[],Jg=Promise.resolve();let Do=!1;function Qg(){Do||(Do=!0,Jg.then(Yh))}function Oo(r){hi.push(r)}const Fo=new Set;let ci=0;function Yh(){if(ci!==0)return;const r=Ki;do{try{for(;ci<li.length;){const t=li[ci];ci++,Zi(t),ty(t.$$)}}catch(t){throw li.length=0,ci=0,t}for(Zi(null),li.length=0,ci=0;Xs.length;)Xs.pop()();for(let t=0;t<hi.length;t+=1){const e=hi[t];Fo.has(e)||(Fo.add(e),e())}hi.length=0}while(li.length);for(;jh.length;)jh.pop()();Do=!1,Fo.clear(),Zi(r)}function ty(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(Oo)}}function ey(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 st(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 ui(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),Oo(()=>{const n=r.$$.on_mount.map(kh).filter(Kt);r.$$.on_destroy?r.$$.on_destroy.push(...n):Qe(n),r.$$.on_mount=[]}),s.forEach(Oo)}function Jt(r,t){const e=r.$$;e.fragment!==null&&(ey(e.after_update),Qe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function ry(r,t){r.$$.dirty[0]===-1&&(li.push(r),Qg(),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=Ki;Zi(r);const h=r.$$={fragment:null,ctx:[],props:n,update:Be,not_equal:s,bound:Gh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Gh(),dirty:a,skip_bound:!1,root:t.target||l.$$.root};o&&o(h.root);let c=!1;if(h.ctx=e?e(r,t.props||{},(u,d,...f)=>{const p=f.length?f[0]:d;return h.ctx&&s(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&ry(r,u)),d}):[],h.update(),c=!0,Qe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=Yg(t.target);h.fragment&&h.fragment.l(u),u.forEach(ct)}else h.fragment&&h.fragment.c();t.intro&&st(r.$$.fragment),Zt(r,t.target,t.anchor),Yh()}Zi(l)}class ae{constructor(){Ml(this,"$$");Ml(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&&!zg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const iy="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(iy);var Or=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(Or||{}),qh=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(qh||{}),Lo=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Lo||{}),tt=(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))(tt||{}),Fe=(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))(Fe||{}),k=(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))(k||{}),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||{}),J=(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))(J||{}),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||{}),Le=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(Le||{}),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||{}),No=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(No||{}),fe=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(fe||{}),Ft=(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))(Ft||{}),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 Uo=/iPhone/i,Kh=/iPod/i,Zh=/iPad/i,Jh=/\biOS-universal(?:.+)Mac\b/i,ko=/\bAndroid(?:.+)Mobile\b/i,Qh=/Android/i,fi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,zs=/Silk/i,sr=/Windows Phone/i,tc=/\bWindows(?:.+)ARM\b/i,ec=/BlackBerry/i,rc=/BB10/i,ic=/Opera Mini/i,sc=/\b(CriOS|Chrome)(?:.+)Mobile/i,nc=/Mobile(?:.+)Firefox\b/i,oc=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function sy(r){return function(t){return t.test(r)}}function ac(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=sy(e),n={apple:{phone:s(Uo)&&!s(sr),ipod:s(Kh),tablet:!s(Uo)&&(s(Zh)||oc(t))&&!s(sr),universal:s(Jh),device:(s(Uo)||s(Kh)||s(Zh)||s(Jh)||oc(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(ko),tablet:!s(sr)&&!s(fi)&&!s(ko)&&(s(zs)||s(Qh)),device:!s(sr)&&(s(fi)||s(zs)||s(ko)||s(Qh))||s(/\bokhttp\b/i)},windows:{phone:s(sr),tablet:s(tc),device:s(sr)||s(tc)},other:{blackberry:s(ec),blackberry10:s(rc),opera:s(ic),firefox:s(nc),chrome:s(sc),device:s(ec)||s(rc)||s(ic)||s(nc)||s(sc)},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 ny=ac.default??ac,nr=ny(globalThis.navigator);W.RETINA_PREFIX=/@([0-9\.]+)x/,W.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Ji=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function lc(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function oy(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 hc={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,c){this.fn=l,this.context=h,this.once=c||!1}function n(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new s(c,u||l,d),p=e?e+h:h;return l._events[p]?l._events[p].fn?l._events[p]=[l._events[p],f]:l._events[p].push(f):(l._events[p]=f,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=[],c,u;if(this._eventsCount===0)return h;for(u in c=this._events)t.call(c,u)&&h.push(e?u.slice(1):u);return Object.getOwnPropertySymbols?h.concat(Object.getOwnPropertySymbols(c)):h},a.prototype.listeners=function(h){var c=e?e+h:h,u=this._events[c];if(!u)return[];if(u.fn)return[u.fn];for(var d=0,f=u.length,p=new Array(f);d<f;d++)p[d]=u[d].fn;return p},a.prototype.listenerCount=function(h){var c=e?e+h:h,u=this._events[c];return u?u.fn?1:u.length:0},a.prototype.emit=function(h,c,u,d,f,p){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,c),!0;case 3:return _.fn.call(_.context,c,u),!0;case 4:return _.fn.call(_.context,c,u,d),!0;case 5:return _.fn.call(_.context,c,u,d,f),!0;case 6:return _.fn.call(_.context,c,u,d,f,p),!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,c);break;case 3:_[g].fn.call(_[g].context,c,u);break;case 4:_[g].fn.call(_[g].context,c,u,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,c,u){return n(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return n(this,h,c,u,!0)},a.prototype.removeListener=function(h,c,u,d){var f=e?e+h:h;if(!this._events[f])return this;if(!c)return o(this,f),this;var p=this._events[f];if(p.fn)p.fn===c&&(!d||p.once)&&(!u||p.context===u)&&o(this,f);else{for(var m=0,_=[],y=p.length;m<y;m++)(p[m].fn!==c||d&&!p[m].once||u&&p[m].context!==u)&&_.push(p[m]);_.length?this._events[f]=_.length===1?_[0]:_:o(this,f)}return this},a.prototype.removeAllListeners=function(h){var c;return h?(c=e?e+h:h,this._events[c]&&o(this,c)):(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})(hc);var ay=hc.exports;const Qi=lc(ay);var Go={exports:{}};Go.exports=Ws,Go.exports.default=Ws;function Ws(r,t,e){e=e||2;var i=t&&t.length,s=i?t[0]*e:r.length,n=cc(r,0,s,e,!0),o=[];if(!n||n.next===n.prev)return o;var a,l,h,c,u,d,f;if(i&&(n=dy(r,t,n,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var p=e;p<s;p+=e)u=r[p],d=r[p+1],u<a&&(a=u),d<l&&(l=d),u>h&&(h=u),d>c&&(c=d);f=Math.max(h-a,c-l),f=f!==0?32767/f:0}return ts(n,o,e,a,l,f,0),o}function cc(r,t,e,i,s){var n,o;if(s===Xo(r,t,e,i)>0)for(n=t;n<e;n+=i)o=fc(n,r[n],r[n+1],o);else for(n=e-i;n>=t;n-=i)o=fc(n,r[n],r[n+1],o);return o&&js(o,o.next)&&(rs(o),o=o.next),o}function Fr(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(js(e,e.next)||It(e.prev,e,e.next)===0)){if(rs(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function ts(r,t,e,i,s,n,o){if(r){!o&&n&&yy(r,i,s,n);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,n?hy(r,i,s,n):ly(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),rs(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=cy(Fr(r),t,e),ts(r,t,e,i,s,n,2)):o===2&&uy(r,t,e,i,s,n):ts(Fr(r),t,e,i,s,n,1);break}}}}function ly(r){var t=r.prev,e=r,i=r.next;if(It(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,c=s<n?s<o?s:o:n<o?n:o,u=a<l?a<h?a:h:l<h?l:h,d=s>n?s>o?s:o:n>o?n:o,f=a>l?a>h?a:h:l>h?l:h,p=i.next;p!==t;){if(p.x>=c&&p.x<=d&&p.y>=u&&p.y<=f&&pi(s,a,n,l,o,h,p.x,p.y)&&It(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function hy(r,t,e,i){var s=r.prev,n=r,o=r.next;if(It(s,n,o)>=0)return!1;for(var a=s.x,l=n.x,h=o.x,c=s.y,u=n.y,d=o.y,f=a<l?a<h?a:h:l<h?l:h,p=c<u?c<d?c:d:u<d?u:d,m=a>l?a>h?a:h:l>h?l:h,_=c>u?c>d?c:d:u>d?u:d,y=$o(f,p,t,e,i),x=$o(m,_,t,e,i),g=r.prevZ,v=r.nextZ;g&&g.z>=y&&v&&v.z<=x;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=_&&g!==s&&g!==o&&pi(a,c,l,u,h,d,g.x,g.y)&&It(g.prev,g,g.next)>=0||(g=g.prevZ,v.x>=f&&v.x<=m&&v.y>=p&&v.y<=_&&v!==s&&v!==o&&pi(a,c,l,u,h,d,v.x,v.y)&&It(v.prev,v,v.next)>=0))return!1;v=v.nextZ}for(;g&&g.z>=y;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=_&&g!==s&&g!==o&&pi(a,c,l,u,h,d,g.x,g.y)&&It(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;v&&v.z<=x;){if(v.x>=f&&v.x<=m&&v.y>=p&&v.y<=_&&v!==s&&v!==o&&pi(a,c,l,u,h,d,v.x,v.y)&&It(v.prev,v,v.next)>=0)return!1;v=v.nextZ}return!0}function cy(r,t,e){var i=r;do{var s=i.prev,n=i.next.next;!js(s,n)&&uc(s,i,i.next,n)&&es(s,n)&&es(n,s)&&(t.push(s.i/e|0),t.push(i.i/e|0),t.push(n.i/e|0),rs(i),rs(i.next),i=r=n),i=i.next}while(i!==r);return Fr(i)}function uy(r,t,e,i,s,n){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&xy(o,a)){var l=dc(o,a);o=Fr(o,o.next),l=Fr(l,l.next),ts(o,t,e,i,s,n,0),ts(l,t,e,i,s,n,0);return}a=a.next}o=o.next}while(o!==r)}function dy(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=cc(r,a,l,i,!1),h===h.next&&(h.steiner=!0),s.push(vy(h));for(s.sort(fy),n=0;n<s.length;n++)e=py(s[n],e);return e}function fy(r,t){return r.x-t.x}function py(r,t){var e=my(r,t);if(!e)return t;var i=dc(e,r);return Fr(i,i.next),Fr(e,e.next)}function my(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,c=o.y,u=1/0,d;e=o;do i>=e.x&&e.x>=h&&i!==e.x&&pi(s<c?i:n,s,h,c,s<c?n:i,s,e.x,e.y)&&(d=Math.abs(s-e.y)/(i-e.x),es(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&gy(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function gy(r,t){return It(r.prev,r,t.prev)<0&&It(t.next,r,r.next)<0}function yy(r,t,e,i){var s=r;do s.z===0&&(s.z=$o(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,_y(s)}function _y(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 $o(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 vy(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 xy(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!by(r,t)&&(es(r,t)&&es(t,r)&&wy(r,t)&&(It(r.prev,r,t.prev)||It(r,t.prev,t))||js(r,t)&&It(r.prev,r,r.next)>0&&It(t.prev,t,t.next)>0)}function It(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 uc(r,t,e,i){var s=qs(It(r,t,e)),n=qs(It(r,t,i)),o=qs(It(e,i,r)),a=qs(It(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 by(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&&uc(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function es(r,t){return It(r.prev,r,r.next)<0?It(r,t,r.next)>=0&&It(r,r.prev,t)>=0:It(r,t,r.prev)<0||It(r,r.next,t)<0}function wy(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 dc(r,t){var e=new Ho(r.i,r.x,r.y),i=new Ho(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 fc(r,t,e,i){var s=new Ho(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 rs(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 Ho(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(Xo(r,0,n,e));if(s)for(var a=0,l=t.length;a<l;a++){var h=t[a]*e,c=a<l-1?t[a+1]*e:r.length;o-=Math.abs(Xo(r,h,c,e))}var u=0;for(a=0;a<i.length;a+=3){var d=i[a]*e,f=i[a+1]*e,p=i[a+2]*e;u+=Math.abs((r[d]-r[p])*(r[f+1]-r[d+1])-(r[d]-r[f])*(r[p+1]-r[d+1]))}return o===0&&u===0?0:Math.abs((u-o)/o)};function Xo(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 Ey=Go.exports;const Ty=lc(Ey);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&&!r.nodeType&&r,n=typeof Ji=="object"&&Ji;(n.global===n||n.window===n||n.self===n)&&(e=n);var o,a=2147483647,l=36,h=1,c=26,u=38,d=700,f=72,p=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,I=String.fromCharCode,A;function C(P){throw new RangeError(g[P])}function N(P,U){for(var j=P.length,rt=[];j--;)rt[j]=U(P[j]);return rt}function S(P,U){var j=P.split("@"),rt="";j.length>1&&(rt=j[0]+"@",P=j[1]),P=P.replace(x,".");var Q=P.split("."),H=N(Q,U).join(".");return rt+H}function R(P){for(var U=[],j=0,rt=P.length,Q,H;j<rt;)Q=P.charCodeAt(j++),Q>=55296&&Q<=56319&&j<rt?(H=P.charCodeAt(j++),(H&64512)==56320?U.push(((Q&1023)<<10)+(H&1023)+65536):(U.push(Q),j--)):U.push(Q);return U}function E(P){return N(P,function(U){var j="";return U>65535&&(U-=65536,j+=I(U>>>10&1023|55296),U=56320|U&1023),j+=I(U),j}).join("")}function b(P){return P-48<10?P-22:P-65<26?P-65:P-97<26?P-97:l}function D(P,U){return P+22+75*(P<26)-((U!=0)<<5)}function F(P,U,j){var rt=0;for(P=j?w(P/d):P>>1,P+=w(P/U);P>v*c>>1;rt+=l)P=w(P/v);return w(rt+(v+1)*P/(P+u))}function G(P){var U=[],j=P.length,rt,Q=0,H=p,V=f,lt,L,O,_t,ht,vt,xt,Ye,qe;for(lt=P.lastIndexOf(m),lt<0&&(lt=0),L=0;L<lt;++L)P.charCodeAt(L)>=128&&C("not-basic"),U.push(P.charCodeAt(L));for(O=lt>0?lt+1:0;O<j;){for(_t=Q,ht=1,vt=l;O>=j&&C("invalid-input"),xt=b(P.charCodeAt(O++)),(xt>=l||xt>w((a-Q)/ht))&&C("overflow"),Q+=xt*ht,Ye=vt<=V?h:vt>=V+c?c:vt-V,!(xt<Ye);vt+=l)qe=l-Ye,ht>w(a/qe)&&C("overflow"),ht*=qe;rt=U.length+1,V=F(Q-_t,rt,_t==0),w(Q/rt)>a-H&&C("overflow"),H+=w(Q/rt),Q%=rt,U.splice(Q++,0,H)}return E(U)}function $(P){var U,j,rt,Q,H,V,lt,L,O,_t,ht,vt=[],xt,Ye,qe,ws;for(P=R(P),xt=P.length,U=p,j=0,H=f,V=0;V<xt;++V)ht=P[V],ht<128&&vt.push(I(ht));for(rt=Q=vt.length,Q&&vt.push(m);rt<xt;){for(lt=a,V=0;V<xt;++V)ht=P[V],ht>=U&&ht<lt&&(lt=ht);for(Ye=rt+1,lt-U>w((a-j)/Ye)&&C("overflow"),j+=(lt-U)*Ye,U=lt,V=0;V<xt;++V)if(ht=P[V],ht<U&&++j>a&&C("overflow"),ht==U){for(L=j,O=l;_t=O<=H?h:O>=H+c?c:O-H,!(L<_t);O+=l)ws=L-_t,qe=l-_t,vt.push(I(D(_t+ws%qe,0))),L=w(ws/qe);vt.push(I(D(L,0))),H=F(j,Ye,rt==Q),j=0,++rt}++j,++U}return vt.join("")}function B(P){return S(P,function(U){return _.test(U)?G(U.slice(4).toLowerCase()):U})}function K(P){return S(P,function(U){return y.test(U)?"xn--"+$(U):U})}if(o={version:"1.4.1",ucs2:{decode:R,encode:E},decode:G,encode:$,toASCII:K,toUnicode:B},i&&s)if(r.exports==i)s.exports=o;else for(A in o)o.hasOwnProperty(A)&&(i[A]=o[A]);else e.punycode=o})(Ji)}(Ks,Ks.exports);var Ay=Ks.exports,Sy=Error,Iy=EvalError,Cy=RangeError,Ry=ReferenceError,pc=SyntaxError,is=TypeError,Py=URIError,My=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(e 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 n=Object.getOwnPropertySymbols(t);if(n.length!==1||n[0]!==e||!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var o=Object.getOwnPropertyDescriptor(t,e);if(o.value!==s||o.enumerable!==!0)return!1}return!0},mc=typeof Symbol<"u"&&Symbol,By=My,Dy=function(){return typeof mc!="function"||typeof Symbol!="function"||typeof mc("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:By()},Vo={__proto__:null,foo:{}},Oy=Object,Fy=function(){return{__proto__:Vo}.foo===Vo.foo&&!(Vo instanceof Oy)},Ly="Function.prototype.bind called on incompatible ",Ny=Object.prototype.toString,Uy=Math.max,ky="[object Function]",gc=function(t,e){for(var i=[],s=0;s<t.length;s+=1)i[s]=t[s];for(var n=0;n<e.length;n+=1)i[n+t.length]=e[n];return i},Gy=function(t,e){for(var i=[],s=e,n=0;s<t.length;s+=1,n+=1)i[n]=t[s];return i},$y=function(r,t){for(var e="",i=0;i<r.length;i+=1)e+=r[i],i+1<r.length&&(e+=t);return e},Hy=function(t){var e=this;if(typeof e!="function"||Ny.apply(e)!==ky)throw new TypeError(Ly+e);for(var i=Gy(arguments,1),s,n=function(){if(this instanceof s){var c=e.apply(this,gc(i,arguments));return Object(c)===c?c:this}return e.apply(t,gc(i,arguments))},o=Uy(0,e.length-i.length),a=[],l=0;l<o;l++)a[l]="$"+l;if(s=Function("binder","return function ("+$y(a,",")+"){ return binder.apply(this,arguments); }")(n),e.prototype){var h=function(){};h.prototype=e.prototype,s.prototype=new h,h.prototype=null}return s},Xy=Hy,zo=Function.prototype.bind||Xy,Vy=Function.prototype.call,zy=Object.prototype.hasOwnProperty,Wy=zo,jy=Wy.call(Vy,zy),pt,Yy=Sy,qy=Iy,Ky=Cy,Zy=Ry,mi=pc,gi=is,Jy=Py,yc=Function,Wo=function(r){try{return yc('"use strict"; return ('+r+").constructor;")()}catch{}},Lr=Object.getOwnPropertyDescriptor;if(Lr)try{Lr({},"")}catch{Lr=null}var jo=function(){throw new gi},Qy=Lr?function(){try{return arguments.callee,jo}catch{try{return Lr(arguments,"callee").get}catch{return jo}}}():jo,yi=Dy(),t0=Fy(),kt=Object.getPrototypeOf||(t0?function(r){return r.__proto__}:null),_i={},e0=typeof Uint8Array>"u"||!kt?pt:kt(Uint8Array),Nr={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?pt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?pt:ArrayBuffer,"%ArrayIteratorPrototype%":yi&&kt?kt([][Symbol.iterator]()):pt,"%AsyncFromSyncIteratorPrototype%":pt,"%AsyncFunction%":_i,"%AsyncGenerator%":_i,"%AsyncGeneratorFunction%":_i,"%AsyncIteratorPrototype%":_i,"%Atomics%":typeof Atomics>"u"?pt:Atomics,"%BigInt%":typeof BigInt>"u"?pt:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?pt:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?pt:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?pt:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Yy,"%eval%":eval,"%EvalError%":qy,"%Float32Array%":typeof Float32Array>"u"?pt:Float32Array,"%Float64Array%":typeof Float64Array>"u"?pt:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?pt:FinalizationRegistry,"%Function%":yc,"%GeneratorFunction%":_i,"%Int8Array%":typeof Int8Array>"u"?pt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?pt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?pt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":yi&&kt?kt(kt([][Symbol.iterator]())):pt,"%JSON%":typeof JSON=="object"?JSON:pt,"%Map%":typeof Map>"u"?pt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!yi||!kt?pt:kt(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Object,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?pt:Promise,"%Proxy%":typeof Proxy>"u"?pt:Proxy,"%RangeError%":Ky,"%ReferenceError%":Zy,"%Reflect%":typeof Reflect>"u"?pt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?pt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!yi||!kt?pt:kt(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?pt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":yi&&kt?kt(""[Symbol.iterator]()):pt,"%Symbol%":yi?Symbol:pt,"%SyntaxError%":mi,"%ThrowTypeError%":Qy,"%TypedArray%":e0,"%TypeError%":gi,"%Uint8Array%":typeof Uint8Array>"u"?pt:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?pt:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?pt:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?pt:Uint32Array,"%URIError%":Jy,"%WeakMap%":typeof WeakMap>"u"?pt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?pt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?pt:WeakSet};if(kt)try{null.error}catch(r){var r0=kt(kt(r));Nr["%Error.prototype%"]=r0}var i0=function r(t){var e;if(t==="%AsyncFunction%")e=Wo("async function () {}");else if(t==="%GeneratorFunction%")e=Wo("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=Wo("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 Nr[t]=e,e},_c={__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"]},ss=zo,Zs=jy,s0=ss.call(Function.call,Array.prototype.concat),n0=ss.call(Function.apply,Array.prototype.splice),vc=ss.call(Function.call,String.prototype.replace),Js=ss.call(Function.call,String.prototype.slice),o0=ss.call(Function.call,RegExp.prototype.exec),a0=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,l0=/\\(\\)?/g,h0=function(t){var e=Js(t,0,1),i=Js(t,-1);if(e==="%"&&i!=="%")throw new mi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new mi("invalid intrinsic syntax, expected opening `%`");var s=[];return vc(t,a0,function(n,o,a,l){s[s.length]=a?vc(l,l0,"$1"):o||n}),s},c0=function(t,e){var i=t,s;if(Zs(_c,i)&&(s=_c[i],i="%"+s[0]+"%"),Zs(Nr,i)){var n=Nr[i];if(n===_i&&(n=i0(i)),typeof n>"u"&&!e)throw new gi("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:s,name:i,value:n}}throw new mi("intrinsic "+t+" does not exist!")},vi=function(t,e){if(typeof t!="string"||t.length===0)throw new gi("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new gi('"allowMissing" argument must be a boolean');if(o0(/^%?[^%]*%?$/,t)===null)throw new mi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=h0(t),s=i.length>0?i[0]:"",n=c0("%"+s+"%",e),o=n.name,a=n.value,l=!1,h=n.alias;h&&(s=h[0],n0(i,s0([0,1],h)));for(var c=1,u=!0;c<i.length;c+=1){var d=i[c],f=Js(d,0,1),p=Js(d,-1);if((f==='"'||f==="'"||f==="`"||p==='"'||p==="'"||p==="`")&&f!==p)throw new mi("property names with quotes must have matching quotes");if((d==="constructor"||!u)&&(l=!0),s+="."+d,o="%"+s+"%",Zs(Nr,o))a=Nr[o];else if(a!=null){if(!(d in a)){if(!e)throw new gi("base intrinsic for "+t+" exists, but the property is not available.");return}if(Lr&&c+1>=i.length){var m=Lr(a,d);u=!!m,u&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else u=Zs(a,d),a=a[d];u&&!l&&(Nr[o]=a)}}return a},xc={exports:{}},Yo,bc;function qo(){if(bc)return Yo;bc=1;var r=vi,t=r("%Object.defineProperty%",!0)||!1;if(t)try{t({},"a",{value:1})}catch{t=!1}return Yo=t,Yo}var u0=vi,Qs=u0("%Object.getOwnPropertyDescriptor%",!0);if(Qs)try{Qs([],"length")}catch{Qs=null}var wc=Qs,Ec=qo(),d0=pc,xi=is,Tc=wc,f0=function(t,e,i){if(!t||typeof t!="object"&&typeof t!="function")throw new xi("`obj` must be an object or a function`");if(typeof e!="string"&&typeof e!="symbol")throw new xi("`property` must be a string or a symbol`");if(arguments.length>3&&typeof arguments[3]!="boolean"&&arguments[3]!==null)throw new xi("`nonEnumerable`, if provided, must be a boolean or null");if(arguments.length>4&&typeof arguments[4]!="boolean"&&arguments[4]!==null)throw new xi("`nonWritable`, if provided, must be a boolean or null");if(arguments.length>5&&typeof arguments[5]!="boolean"&&arguments[5]!==null)throw new xi("`nonConfigurable`, if provided, must be a boolean or null");if(arguments.length>6&&typeof arguments[6]!="boolean")throw new xi("`loose`, if provided, must be a boolean");var s=arguments.length>3?arguments[3]:null,n=arguments.length>4?arguments[4]:null,o=arguments.length>5?arguments[5]:null,a=arguments.length>6?arguments[6]:!1,l=!!Tc&&Tc(t,e);if(Ec)Ec(t,e,{configurable:o===null&&l?l.configurable:!o,enumerable:s===null&&l?l.enumerable:!s,value:i,writable:n===null&&l?l.writable:!n});else if(a||!s&&!n&&!o)t[e]=i;else throw new d0("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable.")},Ko=qo(),Ac=function(){return!!Ko};Ac.hasArrayLengthDefineBug=function(){if(!Ko)return null;try{return Ko([],"length",{value:1}).length!==1}catch{return!0}};var p0=Ac,m0=vi,Sc=f0,g0=p0(),Ic=wc,Cc=is,y0=m0("%Math.floor%"),_0=function(t,e){if(typeof t!="function")throw new Cc("`fn` is not a function");if(typeof e!="number"||e<0||e>4294967295||y0(e)!==e)throw new Cc("`length` must be a positive 32-bit integer");var i=arguments.length>2&&!!arguments[2],s=!0,n=!0;if("length"in t&&Ic){var o=Ic(t,"length");o&&!o.configurable&&(s=!1),o&&!o.writable&&(n=!1)}return(s||n||!i)&&(g0?Sc(t,"length",e,!0,!0):Sc(t,"length",e)),t};(function(r){var t=zo,e=vi,i=_0,s=is,n=e("%Function.prototype.apply%"),o=e("%Function.prototype.call%"),a=e("%Reflect.apply%",!0)||t.call(o,n),l=qo(),h=e("%Math.max%");r.exports=function(d){if(typeof d!="function")throw new s("a function is required");var f=a(t,o,arguments);return i(f,1+h(0,d.length-(arguments.length-1)),!0)};var c=function(){return a(t,n,arguments)};l?l(r.exports,"apply",{value:c}):r.exports.apply=c})(xc);var v0=xc.exports,Rc=vi,Pc=v0,x0=Pc(Rc("String.prototype.indexOf")),b0=function(t,e){var i=Rc(t,!!e);return typeof i=="function"&&x0(t,".prototype.")>-1?Pc(i):i};const w0=oy(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var Zo=typeof Map=="function"&&Map.prototype,Jo=Object.getOwnPropertyDescriptor&&Zo?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,tn=Zo&&Jo&&typeof Jo.get=="function"?Jo.get:null,Mc=Zo&&Map.prototype.forEach,Qo=typeof Set=="function"&&Set.prototype,ta=Object.getOwnPropertyDescriptor&&Qo?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,en=Qo&&ta&&typeof ta.get=="function"?ta.get:null,Bc=Qo&&Set.prototype.forEach,E0=typeof WeakMap=="function"&&WeakMap.prototype,ns=E0?WeakMap.prototype.has:null,T0=typeof WeakSet=="function"&&WeakSet.prototype,os=T0?WeakSet.prototype.has:null,A0=typeof WeakRef=="function"&&WeakRef.prototype,Dc=A0?WeakRef.prototype.deref:null,S0=Boolean.prototype.valueOf,I0=Object.prototype.toString,C0=Function.prototype.toString,R0=String.prototype.match,ea=String.prototype.slice,yr=String.prototype.replace,P0=String.prototype.toUpperCase,Oc=String.prototype.toLowerCase,Fc=RegExp.prototype.test,Lc=Array.prototype.concat,ke=Array.prototype.join,M0=Array.prototype.slice,Nc=Math.floor,ra=typeof BigInt=="function"?BigInt.prototype.valueOf:null,ia=Object.getOwnPropertySymbols,sa=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,bi=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Qt=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===bi||!0)?Symbol.toStringTag:null,Uc=Object.prototype.propertyIsEnumerable,kc=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Gc(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Fc.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Nc(-r):Nc(r);if(i!==r){var s=String(i),n=ea.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 na=w0,$c=na.custom,Hc=Wc($c)?$c:null,Xc={__proto__:null,double:'"',single:"'"},B0={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},D0=function r(t,e,i,s){var n=e||{};if(or(n,"quoteStyle")&&!or(Xc,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 Yc(t,n);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Gc(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Gc(t,h):h}var c=typeof n.depth>"u"?5:n.depth;if(typeof i>"u"&&(i=0),i>=c&&c>0&&typeof t=="object")return oa(t)?"[Array]":"[Object]";var u=Z0(n,i);if(typeof s>"u")s=[];else if(jc(s,t)>=0)return"[Circular]";function d(b,D,F){if(D&&(s=M0.call(s),s.push(D)),F){var G={depth:n.depth};return or(n,"quoteStyle")&&(G.quoteStyle=n.quoteStyle),r(b,G,i+1,s)}return r(b,n,i+1,s)}if(typeof t=="function"&&!zc(t)){var f=H0(t),p=rn(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+ke.call(p,", ")+" }":"")}if(Wc(t)){var m=bi?yr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):sa.call(t);return typeof t=="object"&&!bi?as(m):m}if(Y0(t)){for(var _="<"+Oc.call(String(t.nodeName)),y=t.attributes||[],x=0;x<y.length;x++)_+=" "+y[x].name+"="+Vc(O0(y[x].value),"double",n);return _+=">",t.childNodes&&t.childNodes.length&&(_+="..."),_+="</"+Oc.call(String(t.nodeName))+">",_}if(oa(t)){if(t.length===0)return"[]";var g=rn(t,d);return u&&!K0(g)?"["+la(g,u)+"]":"[ "+ke.call(g,", ")+" ]"}if(L0(t)){var v=rn(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!Uc.call(t,"cause")?"{ ["+String(t)+"] "+ke.call(Lc.call("[cause]: "+d(t.cause),v),", ")+" }":v.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+ke.call(v,", ")+" }"}if(typeof t=="object"&&o){if(Hc&&typeof t[Hc]=="function"&&na)return na(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(X0(t)){var w=[];return Mc&&Mc.call(t,function(b,D){w.push(d(D,t,!0)+" => "+d(b,t))}),qc("Map",tn.call(t),w,u)}if(W0(t)){var I=[];return Bc&&Bc.call(t,function(b){I.push(d(b,t))}),qc("Set",en.call(t),I,u)}if(V0(t))return aa("WeakMap");if(j0(t))return aa("WeakSet");if(z0(t))return aa("WeakRef");if(U0(t))return as(d(Number(t)));if(G0(t))return as(d(ra.call(t)));if(k0(t))return as(S0.call(t));if(N0(t))return as(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Ji<"u"&&t===Ji)return"{ [object globalThis] }";if(!F0(t)&&!zc(t)){var A=rn(t,d),C=kc?kc(t)===Object.prototype:t instanceof Object||t.constructor===Object,N=t instanceof Object?"":"null prototype",S=!C&&Qt&&Object(t)===t&&Qt in t?ea.call(_r(t),8,-1):N?"Object":"",R=C||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",E=R+(S||N?"["+ke.call(Lc.call([],S||[],N||[]),": ")+"] ":"");return A.length===0?E+"{}":u?E+"{"+la(A,u)+"}":E+"{ "+ke.call(A,", ")+" }"}return String(t)};function Vc(r,t,e){var i=e.quoteStyle||t,s=Xc[i];return s+r+s}function O0(r){return yr.call(String(r),/"/g,"&quot;")}function oa(r){return _r(r)==="[object Array]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function F0(r){return _r(r)==="[object Date]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function zc(r){return _r(r)==="[object RegExp]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function L0(r){return _r(r)==="[object Error]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function N0(r){return _r(r)==="[object String]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function U0(r){return _r(r)==="[object Number]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function k0(r){return _r(r)==="[object Boolean]"&&(!Qt||!(typeof r=="object"&&Qt in r))}function Wc(r){if(bi)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!sa)return!1;try{return sa.call(r),!0}catch{}return!1}function G0(r){if(!r||typeof r!="object"||!ra)return!1;try{return ra.call(r),!0}catch{}return!1}var $0=Object.prototype.hasOwnProperty||function(r){return r in this};function or(r,t){return $0.call(r,t)}function _r(r){return I0.call(r)}function H0(r){if(r.name)return r.name;var t=R0.call(C0.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function jc(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 X0(r){if(!tn||!r||typeof r!="object")return!1;try{tn.call(r);try{en.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function V0(r){if(!ns||!r||typeof r!="object")return!1;try{ns.call(r,ns);try{os.call(r,os)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function z0(r){if(!Dc||!r||typeof r!="object")return!1;try{return Dc.call(r),!0}catch{}return!1}function W0(r){if(!en||!r||typeof r!="object")return!1;try{en.call(r);try{tn.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function j0(r){if(!os||!r||typeof r!="object")return!1;try{os.call(r,os);try{ns.call(r,ns)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function Y0(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Yc(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Yc(ea.call(r,0,t.maxStringLength),t)+i}var s=B0[t.quoteStyle||"single"];s.lastIndex=0;var n=yr.call(yr.call(r,s,"\\$1"),/[\x00-\x1f]/g,q0);return Vc(n,"single",t)}function q0(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":"")+P0.call(t.toString(16))}function as(r){return"Object("+r+")"}function aa(r){return r+" { ? }"}function qc(r,t,e,i){var s=i?la(e,i):ke.call(e,", ");return r+" ("+t+") {"+s+"}"}function K0(r){for(var t=0;t<r.length;t++)if(jc(r[t],`
2
2
  `)>=0)return!1;return!0}function Z0(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 la(r,t){if(r.length===0)return"";var e=`
3
3
  `+t.prev+t.base;return e+ke.call(r,","+e)+`
4
- `+t.prev}function rn(r,t){var e=oa(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 ia=="function"?ia(r):[],o;if(bi){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||bi&&o["$"+l]instanceof Symbol||(Fc.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof ia=="function")for(var h=0;h<n.length;h++)Uc.call(r,n[h])&&i.push("["+t(n[h])+"]: "+t(r[n[h]],r));return i}var Kc=vi,wi=b0,J0=D0,Q0=is,sn=Kc("%WeakMap%",!0),nn=Kc("%Map%",!0),t_=wi("WeakMap.prototype.get",!0),e_=wi("WeakMap.prototype.set",!0),r_=wi("WeakMap.prototype.has",!0),i_=wi("Map.prototype.get",!0),s_=wi("Map.prototype.set",!0),n_=wi("Map.prototype.has",!0),ha=function(r,t){for(var e=r,i;(i=e.next)!==null;e=i)if(i.key===t)return e.next=i.next,i.next=r.next,r.next=i,i},o_=function(r,t){var e=ha(r,t);return e&&e.value},a_=function(r,t,e){var i=ha(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},l_=function(r,t){return!!ha(r,t)},h_=function(){var t,e,i,s={assert:function(n){if(!s.has(n))throw new Q0("Side channel does not contain "+J0(n))},get:function(n){if(sn&&n&&(typeof n=="object"||typeof n=="function")){if(t)return t_(t,n)}else if(nn){if(e)return i_(e,n)}else if(i)return o_(i,n)},has:function(n){if(sn&&n&&(typeof n=="object"||typeof n=="function")){if(t)return r_(t,n)}else if(nn){if(e)return n_(e,n)}else if(i)return l_(i,n);return!1},set:function(n,o){sn&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new sn),e_(t,n,o)):nn?(e||(e=new nn),s_(e,n,o)):(i||(i={key:{},next:null}),a_(i,n,o))}};return s},c_=String.prototype.replace,u_=/%20/g,ca={RFC1738:"RFC1738",RFC3986:"RFC3986"},ua={default:ca.RFC3986,formatters:{RFC1738:function(r){return c_.call(r,u_,"+")},RFC3986:function(r){return String(r)}},RFC1738:ca.RFC1738,RFC3986:ca.RFC3986},d_=ua,da=Object.prototype.hasOwnProperty,Ur=Array.isArray,Ge=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),f_=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(Ur(i)){for(var s=[],n=0;n<i.length;++n)typeof i[n]<"u"&&s.push(i[n]);e.obj[e.prop]=s}}},Zc=function(t,e){for(var i=e&&e.plainObjects?Object.create(null):{},s=0;s<t.length;++s)typeof t[s]<"u"&&(i[s]=t[s]);return i},p_=function r(t,e,i){if(!e)return t;if(typeof e!="object"){if(Ur(t))t.push(e);else if(t&&typeof t=="object")(i&&(i.plainObjects||i.allowPrototypes)||!da.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 Ur(t)&&!Ur(e)&&(s=Zc(t,i)),Ur(t)&&Ur(e)?(e.forEach(function(n,o){if(da.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 da.call(n,o)?n[o]=r(n[o],a,i):n[o]=a,n},s)},m_=function(t,e){return Object.keys(e).reduce(function(i,s){return i[s]=e[s],i},t)},g_=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}},fa=1024,y_=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(f){return"%26%23"+parseInt(f.slice(2),16)+"%3B"});for(var a="",l=0;l<o.length;l+=fa){for(var h=o.length>=fa?o.slice(l,l+fa):o,c=[],u=0;u<h.length;++u){var d=h.charCodeAt(u);if(d===45||d===46||d===95||d===126||d>=48&&d<=57||d>=65&&d<=90||d>=97&&d<=122||n===d_.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=Ge[d];continue}if(d<2048){c[c.length]=Ge[192|d>>6]+Ge[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=Ge[224|d>>12]+Ge[128|d>>6&63]+Ge[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=Ge[240|d>>18]+Ge[128|d>>12&63]+Ge[128|d>>6&63]+Ge[128|d&63]}a+=c.join("")}return a},__=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],c=o[h];typeof c=="object"&&c!==null&&i.indexOf(c)===-1&&(e.push({obj:o,prop:h}),i.push(c))}return f_(e),t},v_=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},x_=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},b_=function(t,e){return[].concat(t,e)},w_=function(t,e){if(Ur(t)){for(var i=[],s=0;s<t.length;s+=1)i.push(e(t[s]));return i}return e(t)},Jc={arrayToObject:Zc,assign:m_,combine:b_,compact:__,decode:g_,encode:y_,isBuffer:x_,isRegExp:v_,maybeMap:w_,merge:p_},Qc=h_,on=Jc,ls=ua,E_=Object.prototype.hasOwnProperty,tu={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},$e=Array.isArray,T_=Array.prototype.push,eu=function(r,t){T_.apply(r,$e(t)?t:[t])},A_=Date.prototype.toISOString,ru=ls.default,Lt={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:on.encode,encodeValuesOnly:!1,format:ru,formatter:ls.formatters[ru],indices:!1,serializeDate:function(t){return A_.call(t)},skipNulls:!1,strictNullHandling:!1},S_=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},pa={},I_=function r(t,e,i,s,n,o,a,l,h,c,u,d,f,p,m,_,y,x){for(var g=t,v=x,w=0,I=!1;(v=v.get(pa))!==void 0&&!I;){var A=v.get(t);if(w+=1,typeof A<"u"){if(A===w)throw new RangeError("Cyclic object value");I=!0}typeof v.get(pa)>"u"&&(w=0)}if(typeof c=="function"?g=c(e,g):g instanceof Date?g=f(g):i==="comma"&&$e(g)&&(g=on.maybeMap(g,function(P){return P instanceof Date?f(P):P})),g===null){if(o)return h&&!_?h(e,Lt.encoder,y,"key",p):e;g=""}if(S_(g)||on.isBuffer(g)){if(h){var C=_?e:h(e,Lt.encoder,y,"key",p);return[m(C)+"="+m(h(g,Lt.encoder,y,"value",p))]}return[m(e)+"="+m(String(g))]}var N=[];if(typeof g>"u")return N;var S;if(i==="comma"&&$e(g))_&&h&&(g=on.maybeMap(g,h)),S=[{value:g.length>0?g.join(",")||null:void 0}];else if($e(c))S=c;else{var R=Object.keys(g);S=u?R.sort(u):R}var E=l?e.replace(/\./g,"%2E"):e,b=s&&$e(g)&&g.length===1?E+"[]":E;if(n&&$e(g)&&g.length===0)return b+"[]";for(var D=0;D<S.length;++D){var F=S[D],G=typeof F=="object"&&typeof F.value<"u"?F.value:g[F];if(!(a&&G===null)){var $=d&&l?F.replace(/\./g,"%2E"):F,B=$e(g)?typeof i=="function"?i(b,$):b:b+(d?"."+$:"["+$+"]");x.set(t,w);var Z=Qc();Z.set(pa,x),eu(N,r(G,B,i,s,n,o,a,l,i==="comma"&&_&&$e(g)?null:h,c,u,d,f,p,m,_,y,Z))}}return N},C_=function(t){if(!t)return Lt;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||Lt.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(!E_.call(ls.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var s=ls.formatters[i],n=Lt.filter;(typeof t.filter=="function"||$e(t.filter))&&(n=t.filter);var o;if(t.arrayFormat in tu?o=t.arrayFormat:"indices"in t?o=t.indices?"indices":"repeat":o=Lt.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:Lt.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:Lt.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Lt.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Lt.charsetSentinel,commaRoundTrip:t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?Lt.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:Lt.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:Lt.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:Lt.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:Lt.encodeValuesOnly,filter:n,format:i,formatter:s,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:Lt.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:Lt.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Lt.strictNullHandling}},R_=function(r,t){var e=r,i=C_(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=tu[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;s||(s=Object.keys(e)),i.sort&&s.sort(i.sort);for(var h=Qc(),c=0;c<s.length;++c){var u=s[c];i.skipNulls&&e[u]===null||eu(o,I_(e[u],u,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 d=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&"),d.length>0?f+d:""},Ei=Jc,ma=Object.prototype.hasOwnProperty,P_=Array.isArray,Pt={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:Ei.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1},M_=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},iu=function(r,t){return r&&typeof r=="string"&&t.comma&&r.indexOf(",")>-1?r.split(","):r},B_="utf8=%26%2310003%3B",D_="utf8=%E2%9C%93",O_=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,n),a=-1,l,h=e.charset;if(e.charsetSentinel)for(l=0;l<o.length;++l)o[l].indexOf("utf8=")===0&&(o[l]===D_?h="utf-8":o[l]===B_&&(h="iso-8859-1"),a=l,l=o.length);for(l=0;l<o.length;++l)if(l!==a){var c=o[l],u=c.indexOf("]="),d=u===-1?c.indexOf("="):u+1,f,p;d===-1?(f=e.decoder(c,Pt.decoder,h,"key"),p=e.strictNullHandling?null:""):(f=e.decoder(c.slice(0,d),Pt.decoder,h,"key"),p=Ei.maybeMap(iu(c.slice(d+1),e),function(_){return e.decoder(_,Pt.decoder,h,"value")})),p&&e.interpretNumericEntities&&h==="iso-8859-1"&&(p=M_(p)),c.indexOf("[]=")>-1&&(p=P_(p)?[p]:p);var m=ma.call(i,f);m&&e.duplicates==="combine"?i[f]=Ei.combine(i[f],p):(!m||e.duplicates==="last")&&(i[f]=p)}return i},F_=function(r,t,e,i){for(var s=i?t:iu(t,e),n=r.length-1;n>=0;--n){var o,a=r[n];if(a==="[]"&&e.parseArrays)o=e.allowEmptyArrays&&(s===""||e.strictNullHandling&&s===null)?[]:[].concat(s);else{o=e.plainObjects?Object.create(null):{};var l=a.charAt(0)==="["&&a.charAt(a.length-1)==="]"?a.slice(1,-1):a,h=e.decodeDotInKeys?l.replace(/%2E/g,"."):l,c=parseInt(h,10);!e.parseArrays&&h===""?o={0:s}:!isNaN(c)&&a!==h&&String(c)===h&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(o=[],o[c]=s):h!=="__proto__"&&(o[h]=s)}s=o}return s},L_=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,c=[];if(h){if(!i.plainObjects&&ma.call(Object.prototype,h)&&!i.allowPrototypes)return;c.push(h)}for(var u=0;i.depth>0&&(l=a.exec(n))!==null&&u<i.depth;){if(u+=1,!i.plainObjects&&ma.call(Object.prototype,l[1].slice(1,-1))&&!i.allowPrototypes)return;c.push(l[1])}if(l){if(i.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+i.depth+" and strictDepth is true");c.push("["+n.slice(l.index)+"]")}return F_(c,e,i,s)}},N_=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");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"||Ei.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}},U_=function(r,t){var e=N_(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?Object.create(null):{};for(var i=typeof r=="string"?O_(r,e):r,s=e.plainObjects?Object.create(null):{},n=Object.keys(i),o=0;o<n.length;++o){var a=n[o],l=L_(a,i[a],e,typeof r=="string");s=Ei.merge(s,l,e)}return e.allowSparse===!0?s:Ei.compact(s)},k_=R_,G_=U_,$_=ua,H_={formats:$_,parse:G_,stringify:k_},X_=Ay;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 V_=/^([a-z0-9.+-]+:)/i,z_=/:[0-9]*$/,W_=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,j_=["<",">",'"',"`"," ","\r",`
4
+ `+t.prev}function rn(r,t){var e=oa(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 ia=="function"?ia(r):[],o;if(bi){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||bi&&o["$"+l]instanceof Symbol||(Fc.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof ia=="function")for(var h=0;h<n.length;h++)Uc.call(r,n[h])&&i.push("["+t(n[h])+"]: "+t(r[n[h]],r));return i}var Kc=vi,wi=b0,J0=D0,Q0=is,sn=Kc("%WeakMap%",!0),nn=Kc("%Map%",!0),t_=wi("WeakMap.prototype.get",!0),e_=wi("WeakMap.prototype.set",!0),r_=wi("WeakMap.prototype.has",!0),i_=wi("Map.prototype.get",!0),s_=wi("Map.prototype.set",!0),n_=wi("Map.prototype.has",!0),ha=function(r,t){for(var e=r,i;(i=e.next)!==null;e=i)if(i.key===t)return e.next=i.next,i.next=r.next,r.next=i,i},o_=function(r,t){var e=ha(r,t);return e&&e.value},a_=function(r,t,e){var i=ha(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},l_=function(r,t){return!!ha(r,t)},h_=function(){var t,e,i,s={assert:function(n){if(!s.has(n))throw new Q0("Side channel does not contain "+J0(n))},get:function(n){if(sn&&n&&(typeof n=="object"||typeof n=="function")){if(t)return t_(t,n)}else if(nn){if(e)return i_(e,n)}else if(i)return o_(i,n)},has:function(n){if(sn&&n&&(typeof n=="object"||typeof n=="function")){if(t)return r_(t,n)}else if(nn){if(e)return n_(e,n)}else if(i)return l_(i,n);return!1},set:function(n,o){sn&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new sn),e_(t,n,o)):nn?(e||(e=new nn),s_(e,n,o)):(i||(i={key:{},next:null}),a_(i,n,o))}};return s},c_=String.prototype.replace,u_=/%20/g,ca={RFC1738:"RFC1738",RFC3986:"RFC3986"},ua={default:ca.RFC3986,formatters:{RFC1738:function(r){return c_.call(r,u_,"+")},RFC3986:function(r){return String(r)}},RFC1738:ca.RFC1738,RFC3986:ca.RFC3986},d_=ua,da=Object.prototype.hasOwnProperty,Ur=Array.isArray,Ge=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),f_=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(Ur(i)){for(var s=[],n=0;n<i.length;++n)typeof i[n]<"u"&&s.push(i[n]);e.obj[e.prop]=s}}},Zc=function(t,e){for(var i=e&&e.plainObjects?Object.create(null):{},s=0;s<t.length;++s)typeof t[s]<"u"&&(i[s]=t[s]);return i},p_=function r(t,e,i){if(!e)return t;if(typeof e!="object"){if(Ur(t))t.push(e);else if(t&&typeof t=="object")(i&&(i.plainObjects||i.allowPrototypes)||!da.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 Ur(t)&&!Ur(e)&&(s=Zc(t,i)),Ur(t)&&Ur(e)?(e.forEach(function(n,o){if(da.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 da.call(n,o)?n[o]=r(n[o],a,i):n[o]=a,n},s)},m_=function(t,e){return Object.keys(e).reduce(function(i,s){return i[s]=e[s],i},t)},g_=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}},fa=1024,y_=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(f){return"%26%23"+parseInt(f.slice(2),16)+"%3B"});for(var a="",l=0;l<o.length;l+=fa){for(var h=o.length>=fa?o.slice(l,l+fa):o,c=[],u=0;u<h.length;++u){var d=h.charCodeAt(u);if(d===45||d===46||d===95||d===126||d>=48&&d<=57||d>=65&&d<=90||d>=97&&d<=122||n===d_.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=Ge[d];continue}if(d<2048){c[c.length]=Ge[192|d>>6]+Ge[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=Ge[224|d>>12]+Ge[128|d>>6&63]+Ge[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=Ge[240|d>>18]+Ge[128|d>>12&63]+Ge[128|d>>6&63]+Ge[128|d&63]}a+=c.join("")}return a},__=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],c=o[h];typeof c=="object"&&c!==null&&i.indexOf(c)===-1&&(e.push({obj:o,prop:h}),i.push(c))}return f_(e),t},v_=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},x_=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},b_=function(t,e){return[].concat(t,e)},w_=function(t,e){if(Ur(t)){for(var i=[],s=0;s<t.length;s+=1)i.push(e(t[s]));return i}return e(t)},Jc={arrayToObject:Zc,assign:m_,combine:b_,compact:__,decode:g_,encode:y_,isBuffer:x_,isRegExp:v_,maybeMap:w_,merge:p_},Qc=h_,on=Jc,ls=ua,E_=Object.prototype.hasOwnProperty,tu={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},$e=Array.isArray,T_=Array.prototype.push,eu=function(r,t){T_.apply(r,$e(t)?t:[t])},A_=Date.prototype.toISOString,ru=ls.default,Lt={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:on.encode,encodeValuesOnly:!1,format:ru,formatter:ls.formatters[ru],indices:!1,serializeDate:function(t){return A_.call(t)},skipNulls:!1,strictNullHandling:!1},S_=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},pa={},I_=function r(t,e,i,s,n,o,a,l,h,c,u,d,f,p,m,_,y,x){for(var g=t,v=x,w=0,I=!1;(v=v.get(pa))!==void 0&&!I;){var A=v.get(t);if(w+=1,typeof A<"u"){if(A===w)throw new RangeError("Cyclic object value");I=!0}typeof v.get(pa)>"u"&&(w=0)}if(typeof c=="function"?g=c(e,g):g instanceof Date?g=f(g):i==="comma"&&$e(g)&&(g=on.maybeMap(g,function(P){return P instanceof Date?f(P):P})),g===null){if(o)return h&&!_?h(e,Lt.encoder,y,"key",p):e;g=""}if(S_(g)||on.isBuffer(g)){if(h){var C=_?e:h(e,Lt.encoder,y,"key",p);return[m(C)+"="+m(h(g,Lt.encoder,y,"value",p))]}return[m(e)+"="+m(String(g))]}var N=[];if(typeof g>"u")return N;var S;if(i==="comma"&&$e(g))_&&h&&(g=on.maybeMap(g,h)),S=[{value:g.length>0?g.join(",")||null:void 0}];else if($e(c))S=c;else{var R=Object.keys(g);S=u?R.sort(u):R}var E=l?e.replace(/\./g,"%2E"):e,b=s&&$e(g)&&g.length===1?E+"[]":E;if(n&&$e(g)&&g.length===0)return b+"[]";for(var D=0;D<S.length;++D){var F=S[D],G=typeof F=="object"&&typeof F.value<"u"?F.value:g[F];if(!(a&&G===null)){var $=d&&l?F.replace(/\./g,"%2E"):F,B=$e(g)?typeof i=="function"?i(b,$):b:b+(d?"."+$:"["+$+"]");x.set(t,w);var K=Qc();K.set(pa,x),eu(N,r(G,B,i,s,n,o,a,l,i==="comma"&&_&&$e(g)?null:h,c,u,d,f,p,m,_,y,K))}}return N},C_=function(t){if(!t)return Lt;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||Lt.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(!E_.call(ls.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var s=ls.formatters[i],n=Lt.filter;(typeof t.filter=="function"||$e(t.filter))&&(n=t.filter);var o;if(t.arrayFormat in tu?o=t.arrayFormat:"indices"in t?o=t.indices?"indices":"repeat":o=Lt.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:Lt.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:Lt.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Lt.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Lt.charsetSentinel,commaRoundTrip:t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?Lt.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:Lt.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:Lt.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:Lt.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:Lt.encodeValuesOnly,filter:n,format:i,formatter:s,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:Lt.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:Lt.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Lt.strictNullHandling}},R_=function(r,t){var e=r,i=C_(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=tu[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;s||(s=Object.keys(e)),i.sort&&s.sort(i.sort);for(var h=Qc(),c=0;c<s.length;++c){var u=s[c];i.skipNulls&&e[u]===null||eu(o,I_(e[u],u,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 d=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&"),d.length>0?f+d:""},Ei=Jc,ma=Object.prototype.hasOwnProperty,P_=Array.isArray,Pt={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:Ei.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1},M_=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},iu=function(r,t){return r&&typeof r=="string"&&t.comma&&r.indexOf(",")>-1?r.split(","):r},B_="utf8=%26%2310003%3B",D_="utf8=%E2%9C%93",O_=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,n),a=-1,l,h=e.charset;if(e.charsetSentinel)for(l=0;l<o.length;++l)o[l].indexOf("utf8=")===0&&(o[l]===D_?h="utf-8":o[l]===B_&&(h="iso-8859-1"),a=l,l=o.length);for(l=0;l<o.length;++l)if(l!==a){var c=o[l],u=c.indexOf("]="),d=u===-1?c.indexOf("="):u+1,f,p;d===-1?(f=e.decoder(c,Pt.decoder,h,"key"),p=e.strictNullHandling?null:""):(f=e.decoder(c.slice(0,d),Pt.decoder,h,"key"),p=Ei.maybeMap(iu(c.slice(d+1),e),function(_){return e.decoder(_,Pt.decoder,h,"value")})),p&&e.interpretNumericEntities&&h==="iso-8859-1"&&(p=M_(p)),c.indexOf("[]=")>-1&&(p=P_(p)?[p]:p);var m=ma.call(i,f);m&&e.duplicates==="combine"?i[f]=Ei.combine(i[f],p):(!m||e.duplicates==="last")&&(i[f]=p)}return i},F_=function(r,t,e,i){for(var s=i?t:iu(t,e),n=r.length-1;n>=0;--n){var o,a=r[n];if(a==="[]"&&e.parseArrays)o=e.allowEmptyArrays&&(s===""||e.strictNullHandling&&s===null)?[]:[].concat(s);else{o=e.plainObjects?Object.create(null):{};var l=a.charAt(0)==="["&&a.charAt(a.length-1)==="]"?a.slice(1,-1):a,h=e.decodeDotInKeys?l.replace(/%2E/g,"."):l,c=parseInt(h,10);!e.parseArrays&&h===""?o={0:s}:!isNaN(c)&&a!==h&&String(c)===h&&c>=0&&e.parseArrays&&c<=e.arrayLimit?(o=[],o[c]=s):h!=="__proto__"&&(o[h]=s)}s=o}return s},L_=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,c=[];if(h){if(!i.plainObjects&&ma.call(Object.prototype,h)&&!i.allowPrototypes)return;c.push(h)}for(var u=0;i.depth>0&&(l=a.exec(n))!==null&&u<i.depth;){if(u+=1,!i.plainObjects&&ma.call(Object.prototype,l[1].slice(1,-1))&&!i.allowPrototypes)return;c.push(l[1])}if(l){if(i.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+i.depth+" and strictDepth is true");c.push("["+n.slice(l.index)+"]")}return F_(c,e,i,s)}},N_=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");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"||Ei.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}},U_=function(r,t){var e=N_(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?Object.create(null):{};for(var i=typeof r=="string"?O_(r,e):r,s=e.plainObjects?Object.create(null):{},n=Object.keys(i),o=0;o<n.length;++o){var a=n[o],l=L_(a,i[a],e,typeof r=="string");s=Ei.merge(s,l,e)}return e.allowSparse===!0?s:Ei.compact(s)},k_=R_,G_=U_,$_=ua,H_={formats:$_,parse:G_,stringify:k_},X_=Ay;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 V_=/^([a-z0-9.+-]+:)/i,z_=/:[0-9]*$/,W_=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,j_=["<",">",'"',"`"," ","\r",`
5
5
  `," "],Y_=["{","}","|","\\","^","`"].concat(j_),ga=["'"].concat(Y_),su=["%","/","?",";","#"].concat(ga),nu=["/","?","#"],q_=255,ou=/^[+a-z0-9A-Z_-]{0,63}$/,K_=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,Z_={javascript:!0,"javascript:":!0},ya={javascript:!0,"javascript:":!0},Ti={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},_a=H_;function J_(r,t,e){if(r&&typeof r=="object"&&r instanceof ar)return r;var i=new ar;return i.parse(r,t,e),i}ar.prototype.parse=function(r,t,e){if(typeof r!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof r);var i=r.indexOf("?"),s=i!==-1&&i<r.indexOf("#")?"?":"#",n=r.split(s),o=/\\/g;n[0]=n[0].replace(o,"/"),r=n.join(s);var a=r;if(a=a.trim(),!e&&r.split("#").length===1){var l=W_.exec(a);if(l)return this.path=a,this.href=a,this.pathname=l[1],l[2]?(this.search=l[2],t?this.query=_a.parse(this.search.substr(1)):this.query=this.search.substr(1)):t&&(this.search="",this.query={}),this}var h=V_.exec(a);if(h){h=h[0];var c=h.toLowerCase();this.protocol=c,a=a.substr(h.length)}if(e||h||a.match(/^\/\/[^@/]+@[^@/]+/)){var u=a.substr(0,2)==="//";u&&!(h&&ya[h])&&(a=a.substr(2),this.slashes=!0)}if(!ya[h]&&(u||h&&!Ti[h])){for(var d=-1,f=0;f<nu.length;f++){var p=a.indexOf(nu[f]);p!==-1&&(d===-1||p<d)&&(d=p)}var m,_;d===-1?_=a.lastIndexOf("@"):_=a.lastIndexOf("@",d),_!==-1&&(m=a.slice(0,_),a=a.slice(_+1),this.auth=decodeURIComponent(m)),d=-1;for(var f=0;f<su.length;f++){var p=a.indexOf(su[f]);p!==-1&&(d===-1||p<d)&&(d=p)}d===-1&&(d=a.length),this.host=a.slice(0,d),a=a.slice(d),this.parseHost(),this.hostname=this.hostname||"";var y=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!y)for(var x=this.hostname.split(/\./),f=0,g=x.length;f<g;f++){var v=x[f];if(v&&!v.match(ou)){for(var w="",I=0,A=v.length;I<A;I++)v.charCodeAt(I)>127?w+="x":w+=v[I];if(!w.match(ou)){var C=x.slice(0,f),N=x.slice(f+1),S=v.match(K_);S&&(C.push(S[1]),N.unshift(S[2])),N.length&&(a="/"+N.join(".")+a),this.hostname=C.join(".");break}}}this.hostname.length>q_?this.hostname="":this.hostname=this.hostname.toLowerCase(),y||(this.hostname=X_.toASCII(this.hostname));var R=this.port?":"+this.port:"",E=this.hostname||"";this.host=E+R,this.href+=this.host,y&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),a[0]!=="/"&&(a="/"+a))}if(!Z_[c])for(var f=0,g=ga.length;f<g;f++){var b=ga[f];if(a.indexOf(b)!==-1){var D=encodeURIComponent(b);D===b&&(D=escape(b)),a=a.split(b).join(D)}}var F=a.indexOf("#");F!==-1&&(this.hash=a.substr(F),a=a.slice(0,F));var G=a.indexOf("?");if(G!==-1?(this.search=a.substr(G),this.query=a.substr(G+1),t&&(this.query=_a.parse(this.query)),a=a.slice(0,G)):t&&(this.search="",this.query={}),a&&(this.pathname=a),Ti[c]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var R=this.pathname||"",$=this.search||"";this.path=R+$}return this.href=this.format(),this},ar.prototype.format=function(){var r=this.auth||"";r&&(r=encodeURIComponent(r),r=r.replace(/%3A/i,":"),r+="@");var t=this.protocol||"",e=this.pathname||"",i=this.hash||"",s=!1,n="";this.host?s=r+this.host:this.hostname&&(s=r+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]"),this.port&&(s+=":"+this.port)),this.query&&typeof this.query=="object"&&Object.keys(this.query).length&&(n=_a.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var o=this.search||n&&"?"+n||"";return t&&t.substr(-1)!==":"&&(t+=":"),this.slashes||(!t||Ti[t])&&s!==!1?(s="//"+(s||""),e&&e.charAt(0)!=="/"&&(e="/"+e)):s||(s=""),i&&i.charAt(0)!=="#"&&(i="#"+i),o&&o.charAt(0)!=="?"&&(o="?"+o),e=e.replace(/[?#]/g,function(a){return encodeURIComponent(a)}),o=o.replace("#","%23"),t+s+e+o+i},ar.prototype.resolve=function(r){return this.resolveObject(J_(r,!1,!0)).format()},ar.prototype.resolveObject=function(r){if(typeof r=="string"){var t=new ar;t.parse(r,!1,!0),r=t}for(var e=new ar,i=Object.keys(this),s=0;s<i.length;s++){var n=i[s];e[n]=this[n]}if(e.hash=r.hash,r.href==="")return e.href=e.format(),e;if(r.slashes&&!r.protocol){for(var o=Object.keys(r),a=0;a<o.length;a++){var l=o[a];l!=="protocol"&&(e[l]=r[l])}return Ti[e.protocol]&&e.hostname&&!e.pathname&&(e.pathname="/",e.path=e.pathname),e.href=e.format(),e}if(r.protocol&&r.protocol!==e.protocol){if(!Ti[r.protocol]){for(var h=Object.keys(r),c=0;c<h.length;c++){var u=h[c];e[u]=r[u]}return e.href=e.format(),e}if(e.protocol=r.protocol,!r.host&&!ya[r.protocol]){for(var g=(r.pathname||"").split("/");g.length&&!(r.host=g.shift()););r.host||(r.host=""),r.hostname||(r.hostname=""),g[0]!==""&&g.unshift(""),g.length<2&&g.unshift(""),e.pathname=g.join("/")}else e.pathname=r.pathname;if(e.search=r.search,e.query=r.query,e.host=r.host||"",e.auth=r.auth,e.hostname=r.hostname||r.host,e.port=r.port,e.pathname||e.search){var d=e.pathname||"",f=e.search||"";e.path=d+f}return e.slashes=e.slashes||r.slashes,e.href=e.format(),e}var p=e.pathname&&e.pathname.charAt(0)==="/",m=r.host||r.pathname&&r.pathname.charAt(0)==="/",_=m||p||e.host&&r.pathname,y=_,x=e.pathname&&e.pathname.split("/")||[],g=r.pathname&&r.pathname.split("/")||[],v=e.protocol&&!Ti[e.protocol];if(v&&(e.hostname="",e.port=null,e.host&&(x[0]===""?x[0]=e.host:x.unshift(e.host)),e.host="",r.protocol&&(r.hostname=null,r.port=null,r.host&&(g[0]===""?g[0]=r.host:g.unshift(r.host)),r.host=null),_=_&&(g[0]===""||x[0]==="")),m)e.host=r.host||r.host===""?r.host:e.host,e.hostname=r.hostname||r.hostname===""?r.hostname:e.hostname,e.search=r.search,e.query=r.query,x=g;else if(g.length)x||(x=[]),x.pop(),x=x.concat(g),e.search=r.search,e.query=r.query;else if(r.search!=null){if(v){e.host=x.shift(),e.hostname=e.host;var w=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;w&&(e.auth=w.shift(),e.hostname=w.shift(),e.host=e.hostname)}return e.search=r.search,e.query=r.query,(e.pathname!==null||e.search!==null)&&(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.href=e.format(),e}if(!x.length)return e.pathname=null,e.search?e.path="/"+e.search:e.path=null,e.href=e.format(),e;for(var I=x.slice(-1)[0],A=(e.host||r.host||x.length>1)&&(I==="."||I==="..")||I==="",C=0,N=x.length;N>=0;N--)I=x[N],I==="."?x.splice(N,1):I===".."?(x.splice(N,1),C++):C&&(x.splice(N,1),C--);if(!_&&!y)for(;C--;C)x.unshift("..");_&&x[0]!==""&&(!x[0]||x[0].charAt(0)!=="/")&&x.unshift(""),A&&x.join("/").substr(-1)!=="/"&&x.push("");var S=x[0]===""||x[0]&&x[0].charAt(0)==="/";if(v){e.hostname=S?"":x.length?x.shift():"",e.host=e.hostname;var w=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;w&&(e.auth=w.shift(),e.hostname=w.shift(),e.host=e.hostname)}return _=_||e.host&&x.length,_&&!S&&x.unshift(""),x.length>0?e.pathname=x.join("/"):(e.pathname=null,e.path=null),(e.pathname!==null||e.search!==null)&&(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.auth=r.auth||e.auth,e.slashes=e.slashes||r.slashes,e.href=e.format(),e},ar.prototype.parseHost=function(){var r=this.host,t=z_.exec(r);t&&(t=t[0],t!==":"&&(this.port=t.substr(1)),r=r.substr(0,r.length-t.length)),r&&(this.hostname=r)};const au={};function dt(r,t,e=3){if(au[t])return;let i=new Error().stack;typeof i>"u"?console.warn("PixiJS Deprecation Warning: ",`${t}
6
6
  Deprecated since v${r}`):(i=i.split(`
7
7
  `).splice(e).join(`
@@ -908,7 +908,7 @@ ${u}`)}});return await Promise.all(l),n?s[o[0].src]:s}async unload(t){const e=Se
908
908
  };
909
909
  })();
910
910
  `;let Oi=null;class Ld{constructor(){Oi||(Oi=URL.createObjectURL(new Blob([Gx],{type:"application/javascript"}))),this.worker=new Worker(Oi)}}Ld.revokeObjectURL=function(){Oi&&(URL.revokeObjectURL(Oi),Oi=null)};let Nd=0,ll;class $x{constructor(){this._initialized=!1,this._createdWorkers=0,this.workerPool=[],this.queue=[],this.resolveHash={}}isImageBitmapSupported(){return this._isImageBitmapSupported!==void 0?this._isImageBitmapSupported:(this._isImageBitmapSupported=new Promise(t=>{const{worker:e}=new al;e.addEventListener("message",i=>{e.terminate(),al.revokeObjectURL(),t(i.data)})}),this._isImageBitmapSupported)}loadImageBitmap(t){return this._run("loadImageBitmap",[t])}async _initWorkers(){this._initialized||(this._initialized=!0)}getWorker(){ll===void 0&&(ll=navigator.hardwareConcurrency||4);let t=this.workerPool.pop();return!t&&this._createdWorkers<ll&&(this._createdWorkers++,t=new Ld().worker,t.addEventListener("message",e=>{this.complete(e.data),this.returnWorker(e.target),this.next()})),t}returnWorker(t){this.workerPool.push(t)}complete(t){t.error!==void 0?this.resolveHash[t.uuid].reject(t.error):this.resolveHash[t.uuid].resolve(t.data),this.resolveHash[t.uuid]=null}async _run(t,e){await this._initWorkers();const i=new Promise((s,n)=>{this.queue.push({id:t,arguments:e,resolve:s,reject:n})});return this.next(),i}next(){if(!this.queue.length)return;const t=this.getWorker();if(!t)return;const e=this.queue.pop(),i=e.id;this.resolveHash[Nd]={resolve:e.resolve,reject:e.reject},t.postMessage({data:e.arguments,uuid:Nd++,id:i})}}const Ud=new $x;function _s(r,t,e){r.resource.internal=!0;const i=new q(r),s=()=>{delete t.promiseCache[e],Kr.has(e)&&Kr.remove(e)};return i.baseTexture.once("destroyed",()=>{e in t.promiseCache&&(console.warn("[Assets] A BaseTexture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the BaseTexture."),s())}),i.once("destroyed",()=>{r.destroyed||(console.warn("[Assets] A Texture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the Texture."),s())}),i}const Hx=[".jpeg",".jpg",".png",".webp",".avif"],Xx=["image/jpeg","image/png","image/webp","image/avif"];async function Vx(r){const t=await W.ADAPTER.fetch(r);if(!t.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${r}: ${t.status} ${t.statusText}`);const e=await t.blob();return await createImageBitmap(e)}const Dn={name:"loadTextures",extension:{type:X.LoadParser,priority:Ie.High},config:{preferWorkers:!0,preferCreateImageBitmap:!0,crossOrigin:"anonymous"},test(r){return Bi(r,Xx)||Er(r,Hx)},async load(r,t,e){var a;const i=globalThis.createImageBitmap&&this.config.preferCreateImageBitmap;let s;i?this.config.preferWorkers&&await Ud.isImageBitmapSupported()?s=await Ud.loadImageBitmap(r):s=await Vx(r):s=await new Promise((l,h)=>{const c=new Image;c.crossOrigin=this.config.crossOrigin,c.src=r,c.complete?l(c):(c.onload=()=>l(c),c.onerror=u=>h(u))});const n={...t.data};n.resolution??(n.resolution=hr(r)),i&&((a=n.resourceOptions)==null?void 0:a.ownsImageBitmap)===void 0&&(n.resourceOptions={...n.resourceOptions},n.resourceOptions.ownsImageBitmap=!0);const o=new nt(s,n);return o.resource.src=r,_s(o,e,r)},unload(r){r.destroy(!0)}};Y.add(Dn);const zx=".svg",Wx="image/svg+xml",jx={extension:{type:X.LoadParser,priority:Ie.High},name:"loadSVG",test(r){return Bi(r,Wx)||Er(r,zx)},async testParse(r){return Qa.test(r)},async parse(r,t,e){var n;const i=new Qa(r,(n=t==null?void 0:t.data)==null?void 0:n.resourceOptions);await i.load();const s=new nt(i,{resolution:hr(r),...t==null?void 0:t.data});return s.resource.src=t.src,_s(s,e,t.src)},async load(r,t){return(await W.ADAPTER.fetch(r)).text()},unload:Dn.unload};Y.add(jx);const Yx=[".mp4",".m4v",".webm",".ogv"],qx=["video/mp4","video/webm","video/ogg"],Kx={name:"loadVideo",extension:{type:X.LoadParser,priority:Ie.High},config:{defaultAutoPlay:!0,defaultUpdateFPS:0,defaultLoop:!1,defaultMuted:!1,defaultPlaysinline:!0},test(r){return Bi(r,qx)||Er(r,Yx)},async load(r,t,e){var o;let i;const s=await(await W.ADAPTER.fetch(r)).blob(),n=URL.createObjectURL(s);try{const a={autoPlay:this.config.defaultAutoPlay,updateFPS:this.config.defaultUpdateFPS,loop:this.config.defaultLoop,muted:this.config.defaultMuted,playsinline:this.config.defaultPlaysinline,...(o=t==null?void 0:t.data)==null?void 0:o.resourceOptions,autoLoad:!0},l=new Td(n,a);await l.load();const h=new nt(l,{alphaMode:await rv(),resolution:hr(r),...t==null?void 0:t.data});h.resource.src=r,i=_s(h,e,r),i.baseTexture.once("destroyed",()=>{URL.revokeObjectURL(n)})}catch(a){throw URL.revokeObjectURL(n),a}return i},unload(r){r.destroy(!0)}};Y.add(Kx);class Zx{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(t,e)=>`${t}${this._bundleIdConnector}${e}`,extractAssetIdFromBundle:(t,e)=>e.replace(`${t}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(t){if(this._bundleIdConnector=t.connector??this._bundleIdConnector,this._createBundleAssetId=t.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=t.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...t){t.forEach(e=>{this._preferredOrder.push(e),e.priority||(e.priority=Object.keys(e.params))}),this._resolverHash={}}set basePath(t){this._basePath=t}get basePath(){return this._basePath}set rootPath(t){this._rootPath=t}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(t){if(typeof t=="string")this._defaultSearchParams=t;else{const e=t;this._defaultSearchParams=Object.keys(e).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(e[i])}`).join("&")}}getAlias(t){const{alias:e,name:i,src:s,srcs:n}=t;return Se(e||i||s||n,o=>typeof o=="string"?o:Array.isArray(o)?o.map(a=>(a==null?void 0:a.src)??(a==null?void 0:a.srcs)??a):o!=null&&o.src||o!=null&&o.srcs?o.src??o.srcs:o,!0)}addManifest(t){this._manifest&&console.warn("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=t,t.bundles.forEach(e=>{this.addBundle(e.name,e.assets)})}addBundle(t,e){const i=[];Array.isArray(e)?e.forEach(s=>{const n=s.src??s.srcs,o=s.alias??s.name;let a;if(typeof o=="string"){const l=this._createBundleAssetId(t,o);i.push(l),a=[o,l]}else{const l=o.map(h=>this._createBundleAssetId(t,h));i.push(...l),a=[...o,...l]}this.add({...s,alias:a,src:n})}):Object.keys(e).forEach(s=>{const n=[s,this._createBundleAssetId(t,s)];if(typeof e[s]=="string")this.add({alias:n,src:e[s]});else if(Array.isArray(e[s]))this.add({alias:n,src:e[s]});else{const o=e[s],a=o.src??o.srcs;this.add({...o,alias:n,src:Array.isArray(a)?a:[a]})}i.push(...n)}),this._bundles[t]=i}add(t,e,i,s,n){const o=[];typeof t=="string"||Array.isArray(t)&&typeof t[0]=="string"?(dt("7.2.0",`Assets.add now uses an object instead of individual parameters.
911
- Please use Assets.add({ alias, src, data, format, loadParser }) instead.`),o.push({alias:t,src:e,data:i,format:s,loadParser:n})):Array.isArray(t)?o.push(...t):o.push(t);let a;a=l=>{this.hasKey(l)&&console.warn(`[Resolver] already has key: ${l} overwriting`)},Se(o).forEach(l=>{const{src:h,srcs:c}=l;let{data:u,format:d,loadParser:f}=l;const p=Se(h||c).map(y=>typeof y=="string"?wx(y):Array.isArray(y)?y:[y]),m=this.getAlias(l);Array.isArray(m)?m.forEach(a):a(m);const _=[];p.forEach(y=>{y.forEach(x=>{let g={};if(typeof x!="object"){g.src=x;for(let v=0;v<this._parsers.length;v++){const w=this._parsers[v];if(w.test(x)){g=w.parse(x);break}}}else u=x.data??u,d=x.format??d,f=x.loadParser??f,g={...g,...x};if(!m)throw new Error(`[Resolver] alias is undefined for this asset: ${g.src}`);g=this.buildResolvedAsset(g,{aliases:m,data:u,format:d,loadParser:f}),_.push(g)})}),m.forEach(y=>{this._assetMap[y]=_})})}resolveBundle(t){const e=Bn(t);t=Se(t);const i={};return t.forEach(s=>{const n=this._bundles[s];if(n){const o=this.resolve(n),a={};for(const l in o){const h=o[l];a[this._extractAssetIdFromBundle(s,l)]=h}i[s]=a}}),e?i[t[0]]:i}resolveUrl(t){const e=this.resolve(t);if(typeof t!="string"){const i={};for(const s in e)i[s]=e[s].src;return i}return e.src}resolve(t){const e=Bn(t);t=Se(t);const i={};return t.forEach(s=>{if(!this._resolverHash[s])if(this._assetMap[s]){let n=this._assetMap[s];const o=n[0],a=this._getPreferredOrder(n);a==null||a.priority.forEach(l=>{a.params[l].forEach(h=>{const c=n.filter(u=>u[l]?u[l]===h:!1);c.length&&(n=c)})}),this._resolverHash[s]=n[0]??o}else this._resolverHash[s]=this.buildResolvedAsset({alias:[s],src:s},{});i[s]=this._resolverHash[s]}),e?i[t[0]]:i}hasKey(t){return!!this._assetMap[t]}hasBundle(t){return!!this._bundles[t]}_getPreferredOrder(t){for(let e=0;e<t.length;e++){const i=t[0],s=this._preferredOrder.find(n=>n.params.format.includes(i.format));if(s)return s}return this._preferredOrder[0]}_appendDefaultSearchParams(t){if(!this._defaultSearchParams)return t;const e=/\?/.test(t)?"&":"?";return`${t}${e}${this._defaultSearchParams}`}buildResolvedAsset(t,e){const{aliases:i,data:s,loadParser:n,format:o}=e;return(this._basePath||this._rootPath)&&(t.src=Gt.toAbsolute(t.src,this._basePath,this._rootPath)),t.alias=i??t.alias??[t.src],t.src=this._appendDefaultSearchParams(t.src),t.data={...s||{},...t.data},t.loadParser=n??t.loadParser,t.format=o??t.format??Gt.extname(t.src).slice(1),t.srcs=t.src,t.name=t.alias,t}}class Jx{constructor(){this._detections=[],this._initialized=!1,this.resolver=new Zx,this.loader=new Tx,this.cache=Kr,this._backgroundLoader=new bx(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(t={}){var n,o;if(this._initialized){console.warn("[Assets]AssetManager already initialized, did you load before calling this Assets.init()?");return}if(this._initialized=!0,t.defaultSearchParams&&this.resolver.setDefaultSearchParams(t.defaultSearchParams),t.basePath&&(this.resolver.basePath=t.basePath),t.bundleIdentifier&&this.resolver.setBundleIdentifier(t.bundleIdentifier),t.manifest){let a=t.manifest;typeof a=="string"&&(a=await this.load(a)),this.resolver.addManifest(a)}const e=((n=t.texturePreference)==null?void 0:n.resolution)??1,i=typeof e=="number"?[e]:e,s=await this._detectFormats({preferredFormats:(o=t.texturePreference)==null?void 0:o.format,skipDetections:t.skipDetections,detections:this._detections});this.resolver.prefer({params:{format:s,resolution:i}}),t.preferences&&this.setPreferences(t.preferences)}add(t,e,i,s,n){this.resolver.add(t,e,i,s,n)}async load(t,e){this._initialized||await this.init();const i=Bn(t),s=Se(t).map(a=>{if(typeof a!="string"){const l=this.resolver.getAlias(a);return l.some(h=>!this.resolver.hasKey(h))&&this.add(a),Array.isArray(l)?l[0]:l}return this.resolver.hasKey(a)||this.add({alias:a,src:a}),a}),n=this.resolver.resolve(s),o=await this._mapLoadToResolve(n,e);return i?o[s[0]]:o}addBundle(t,e){this.resolver.addBundle(t,e)}async loadBundle(t,e){this._initialized||await this.init();let i=!1;typeof t=="string"&&(i=!0,t=[t]);const s=this.resolver.resolveBundle(t),n={},o=Object.keys(s);let a=0,l=0;const h=()=>{e==null||e(++a/l)},c=o.map(u=>{const d=s[u];return l+=Object.keys(d).length,this._mapLoadToResolve(d,h).then(f=>{n[u]=f})});return await Promise.all(c),i?n[t[0]]:n}async backgroundLoad(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolve(t);this._backgroundLoader.add(Object.values(e))}async backgroundLoadBundle(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolveBundle(t);Object.values(e).forEach(i=>{this._backgroundLoader.add(Object.values(i))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(t){if(typeof t=="string")return Kr.get(t);const e={};for(let i=0;i<t.length;i++)e[i]=Kr.get(t[i]);return e}async _mapLoadToResolve(t,e){const i=Object.values(t),s=Object.keys(t);this._backgroundLoader.active=!1;const n=await this.loader.load(i,e);this._backgroundLoader.active=!0;const o={};return i.forEach((a,l)=>{const h=n[a.src],c=[a.src];a.alias&&c.push(...a.alias),o[s[l]]=h,Kr.set(c,h)}),o}async unload(t){this._initialized||await this.init();const e=Se(t).map(s=>typeof s!="string"?s.src:s),i=this.resolver.resolve(e);await this._unloadFromResolved(i)}async unloadBundle(t){this._initialized||await this.init(),t=Se(t);const e=this.resolver.resolveBundle(t),i=Object.keys(e).map(s=>this._unloadFromResolved(e[s]));await Promise.all(i)}async _unloadFromResolved(t){const e=Object.values(t);e.forEach(i=>{Kr.remove(i.src)}),await this.loader.unload(e)}async _detectFormats(t){let e=[];t.preferredFormats&&(e=Array.isArray(t.preferredFormats)?t.preferredFormats:[t.preferredFormats]);for(const i of t.detections)t.skipDetections||await i.test()?e=await i.add(e):t.skipDetections||(e=await i.remove(e));return e=e.filter((i,s)=>e.indexOf(i)===s),e}get detections(){return this._detections}get preferWorkers(){return Dn.config.preferWorkers}set preferWorkers(t){dt("7.2.0","Assets.prefersWorkers is deprecated, use Assets.setPreferences({ preferWorkers: true }) instead."),this.setPreferences({preferWorkers:t})}setPreferences(t){this.loader.parsers.forEach(e=>{e.config&&Object.keys(e.config).filter(i=>i in t).forEach(i=>{e.config[i]=t[i]})})}}const On=new Jx;Y.handleByList(X.LoadParser,On.loader.parsers).handleByList(X.ResolveParser,On.resolver.parsers).handleByList(X.CacheParser,On.cache.parsers).handleByList(X.DetectionParser,On.detections);const Qx={extension:X.CacheParser,test:r=>Array.isArray(r)&&r.every(t=>t instanceof q),getCacheableAssets:(r,t)=>{const e={};return r.forEach(i=>{t.forEach((s,n)=>{e[i+(n===0?"":n+1)]=s})}),e}};Y.add(Qx);async function kd(r){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(r)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const tb={extension:{type:X.DetectionParser,priority:1},test:async()=>kd("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(t=>t!=="avif")};Y.add(tb);const eb={extension:{type:X.DetectionParser,priority:0},test:async()=>kd("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(t=>t!=="webp")};Y.add(eb);const Gd=["png","jpg","jpeg"],rb={extension:{type:X.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Gd],remove:async r=>r.filter(t=>!Gd.includes(t))};Y.add(rb);const ib="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function hl(r){return ib?!1:document.createElement("video").canPlayType(r)!==""}const sb={extension:{type:X.DetectionParser,priority:0},test:async()=>hl("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(t=>t!=="webm")};Y.add(sb);const nb={extension:{type:X.DetectionParser,priority:0},test:async()=>hl("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(t=>t!=="mp4"&&t!=="m4v")};Y.add(nb);const ob={extension:{type:X.DetectionParser,priority:0},test:async()=>hl("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(t=>t!=="ogv")};Y.add(ob);const ab={extension:X.ResolveParser,test:Dn.test,parse:r=>{var t;return{resolution:parseFloat(((t=W.RETINA_PREFIX.exec(r))==null?void 0:t[1])??"1"),format:Gt.extname(r).slice(1),src:r}}};Y.add(ab);var jt=(r=>(r[r.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",r[r.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",r[r.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",r[r.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",r[r.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",r[r.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",r[r.COMPRESSED_RGBA8_ETC2_EAC=37496]="COMPRESSED_RGBA8_ETC2_EAC",r[r.COMPRESSED_SRGB8_ETC2=37493]="COMPRESSED_SRGB8_ETC2",r[r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37497]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",r[r.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37494]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37495]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",r[r.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",r[r.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35987]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",r[r.COMPRESSED_RGBA_BPTC_UNORM_EXT=36492]="COMPRESSED_RGBA_BPTC_UNORM_EXT",r[r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT=36493]="COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT",r[r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT=36494]="COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT",r[r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT=36495]="COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT",r))(jt||{});const Fn={33776:.5,33777:.5,33778:1,33779:1,35916:.5,35917:.5,35918:1,35919:1,37488:.5,37489:.5,37490:1,37491:1,37492:.5,37496:1,37493:.5,37497:1,37494:.5,37495:.5,35840:.5,35842:.5,35841:.25,35843:.25,36196:.5,35986:.5,35987:1,34798:1,37808:1,36492:1,36493:1,36494:1,36495:1};let We,Fi;function $d(){Fi={bptc:We.getExtension("EXT_texture_compression_bptc"),astc:We.getExtension("WEBGL_compressed_texture_astc"),etc:We.getExtension("WEBGL_compressed_texture_etc"),s3tc:We.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:We.getExtension("WEBGL_compressed_texture_s3tc_srgb"),pvrtc:We.getExtension("WEBGL_compressed_texture_pvrtc")||We.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),etc1:We.getExtension("WEBGL_compressed_texture_etc1"),atc:We.getExtension("WEBGL_compressed_texture_atc")}}const lb={extension:{type:X.DetectionParser,priority:2},test:async()=>{const r=W.ADAPTER.createCanvas().getContext("webgl");return r?(We=r,!0):(console.warn("WebGL not available for compressed textures."),!1)},add:async r=>{Fi||$d();const t=[];for(const e in Fi)Fi[e]&&t.push(e);return[...t,...r]},remove:async r=>(Fi||$d(),r.filter(t=>!(t in Fi)))};Y.add(lb);class hb extends hn{constructor(t,e={width:1,height:1,autoLoad:!0}){let i,s;typeof t=="string"?(i=t,s=new Uint8Array):(i=null,s=t),super(s,e),this.origin=i,this.buffer=s?new Ca(s):null,this._load=null,this.loaded=!1,this.origin!==null&&e.autoLoad!==!1&&this.load(),this.origin===null&&this.buffer&&(this._load=Promise.resolve(this),this.loaded=!0,this.onBlobLoaded(this.buffer.rawBinaryData))}onBlobLoaded(t){}load(){return this._load?this._load:(this._load=fetch(this.origin).then(t=>t.blob()).then(t=>t.arrayBuffer()).then(t=>(this.data=new Uint32Array(t),this.buffer=new Ca(t),this.loaded=!0,this.onBlobLoaded(t),this.update(),this)),this._load)}}class Zr extends hb{constructor(t,e){super(t,e),this.format=e.format,this.levels=e.levels||1,this._width=e.width,this._height=e.height,this._extension=Zr._formatToExtension(this.format),(e.levelBuffers||this.buffer)&&(this._levelBuffers=e.levelBuffers||Zr._createLevelBuffers(t instanceof Uint8Array?t:this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height))}upload(t,e,i){const s=t.gl;if(!t.context.extensions[this._extension])throw new Error(`${this._extension} textures are not supported on the current machine`);if(!this._levelBuffers)return!1;s.pixelStorei(s.UNPACK_ALIGNMENT,4);for(let n=0,o=this.levels;n<o;n++){const{levelID:a,levelWidth:l,levelHeight:h,levelBuffer:c}=this._levelBuffers[n];s.compressedTexImage2D(s.TEXTURE_2D,a,this.format,l,h,0,c)}return!0}onBlobLoaded(){this._levelBuffers=Zr._createLevelBuffers(this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height)}static _formatToExtension(t){if(t>=33776&&t<=33779)return"s3tc";if(t>=35916&&t<=35919)return"s3tc_sRGB";if(t>=37488&&t<=37497)return"etc";if(t>=35840&&t<=35843)return"pvrtc";if(t===36196)return"etc1";if(t===35986||t===35987||t===34798)return"atc";if(t>=36492&&t<=36495)return"bptc";if(t===37808)return"astc";throw new Error(`Invalid (compressed) texture format given: ${t}`)}static _createLevelBuffers(t,e,i,s,n,o,a){const l=new Array(i);let h=t.byteOffset,c=o,u=a,d=c+s-1&~(s-1),f=u+n-1&~(n-1),p=d*f*Fn[e];for(let m=0;m<i;m++)l[m]={levelID:m,levelWidth:i>1?c:d,levelHeight:i>1?u:f,levelBuffer:new Uint8Array(t.buffer,h,p)},h+=p,c=c>>1||1,u=u>>1||1,d=c+s-1&~(s-1),f=u+n-1&~(n-1),p=d*f*Fn[e];return l}}const cl=4,Ln=124,cb=32,Hd=20,ub=542327876,Nn={SIZE:1,FLAGS:2,HEIGHT:3,WIDTH:4,MIPMAP_COUNT:7,PIXEL_FORMAT:19},db={SIZE:0,FLAGS:1,FOURCC:2,RGB_BITCOUNT:3,R_BIT_MASK:4,G_BIT_MASK:5,B_BIT_MASK:6,A_BIT_MASK:7},Un={DXGI_FORMAT:0,RESOURCE_DIMENSION:1,MISC_FLAG:2,ARRAY_SIZE:3,MISC_FLAGS2:4},fb=1,pb=2,mb=4,gb=64,yb=512,_b=131072,vb=827611204,xb=861165636,bb=894720068,wb=808540228,Eb=4,Tb={[vb]:jt.COMPRESSED_RGBA_S3TC_DXT1_EXT,[xb]:jt.COMPRESSED_RGBA_S3TC_DXT3_EXT,[bb]:jt.COMPRESSED_RGBA_S3TC_DXT5_EXT},Ab={70:jt.COMPRESSED_RGBA_S3TC_DXT1_EXT,71:jt.COMPRESSED_RGBA_S3TC_DXT1_EXT,73:jt.COMPRESSED_RGBA_S3TC_DXT3_EXT,74:jt.COMPRESSED_RGBA_S3TC_DXT3_EXT,76:jt.COMPRESSED_RGBA_S3TC_DXT5_EXT,77:jt.COMPRESSED_RGBA_S3TC_DXT5_EXT,72:jt.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,75:jt.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,78:jt.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,96:jt.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,95:jt.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,98:jt.COMPRESSED_RGBA_BPTC_UNORM_EXT,99:jt.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT};function Sb(r){const t=new Uint32Array(r);if(t[0]!==ub)throw new Error("Invalid DDS file magic word");const e=new Uint32Array(r,0,Ln/Uint32Array.BYTES_PER_ELEMENT),i=e[Nn.HEIGHT],s=e[Nn.WIDTH],n=e[Nn.MIPMAP_COUNT],o=new Uint32Array(r,Nn.PIXEL_FORMAT*Uint32Array.BYTES_PER_ELEMENT,cb/Uint32Array.BYTES_PER_ELEMENT),a=o[fb];if(a&mb){const l=o[db.FOURCC];if(l!==wb){const x=Tb[l],g=cl+Ln,v=new Uint8Array(r,g);return[new Zr(v,{format:x,width:s,height:i,levels:n})]}const h=cl+Ln,c=new Uint32Array(t.buffer,h,Hd/Uint32Array.BYTES_PER_ELEMENT),u=c[Un.DXGI_FORMAT],d=c[Un.RESOURCE_DIMENSION],f=c[Un.MISC_FLAG],p=c[Un.ARRAY_SIZE],m=Ab[u];if(m===void 0)throw new Error(`DDSParser cannot parse texture data with DXGI format ${u}`);if(f===Eb)throw new Error("DDSParser does not support cubemap textures");if(d===6)throw new Error("DDSParser does not supported 3D texture data");const _=new Array,y=cl+Ln+Hd;if(p===1)_.push(new Uint8Array(r,y));else{const x=Fn[m];let g=0,v=s,w=i;for(let A=0;A<n;A++){const C=Math.max(1,v+3&-4),N=Math.max(1,w+3&-4),S=C*N*x;g+=S,v=v>>>1,w=w>>>1}let I=y;for(let A=0;A<p;A++)_.push(new Uint8Array(r,I,g)),I+=g}return _.map(x=>new Zr(x,{format:m,width:s,height:i,levels:n}))}throw a&gb?new Error("DDSParser does not support uncompressed texture data."):a&yb?new Error("DDSParser does not supported YUV uncompressed texture data."):a&_b?new Error("DDSParser does not support single-channel (lumninance) texture data!"):a&pb?new Error("DDSParser does not support single-channel (alpha) texture data!"):new Error("DDSParser failed to load a texture file due to an unknown reason!")}const Xd=[171,75,84,88,32,49,49,187,13,10,26,10],Ib=67305985,Ce={FILE_IDENTIFIER:0,ENDIANNESS:12,GL_TYPE:16,GL_TYPE_SIZE:20,GL_FORMAT:24,GL_INTERNAL_FORMAT:28,GL_BASE_INTERNAL_FORMAT:32,PIXEL_WIDTH:36,PIXEL_HEIGHT:40,PIXEL_DEPTH:44,NUMBER_OF_ARRAY_ELEMENTS:48,NUMBER_OF_FACES:52,NUMBER_OF_MIPMAP_LEVELS:56,BYTES_OF_KEY_VALUE_DATA:60},ul=64,Vd={[J.UNSIGNED_BYTE]:1,[J.UNSIGNED_SHORT]:2,[J.INT]:4,[J.UNSIGNED_INT]:4,[J.FLOAT]:4,[J.HALF_FLOAT]:8},Cb={[k.RGBA]:4,[k.RGB]:3,[k.RG]:2,[k.RED]:1,[k.LUMINANCE]:1,[k.LUMINANCE_ALPHA]:2,[k.ALPHA]:1},Rb={[J.UNSIGNED_SHORT_4_4_4_4]:2,[J.UNSIGNED_SHORT_5_5_5_1]:2,[J.UNSIGNED_SHORT_5_6_5]:2};function Pb(r,t,e=!1){const i=new DataView(t);if(!Mb(r,i))return null;const s=i.getUint32(Ce.ENDIANNESS,!0)===Ib,n=i.getUint32(Ce.GL_TYPE,s),o=i.getUint32(Ce.GL_FORMAT,s),a=i.getUint32(Ce.GL_INTERNAL_FORMAT,s),l=i.getUint32(Ce.PIXEL_WIDTH,s),h=i.getUint32(Ce.PIXEL_HEIGHT,s)||1,c=i.getUint32(Ce.PIXEL_DEPTH,s)||1,u=i.getUint32(Ce.NUMBER_OF_ARRAY_ELEMENTS,s)||1,d=i.getUint32(Ce.NUMBER_OF_FACES,s),f=i.getUint32(Ce.NUMBER_OF_MIPMAP_LEVELS,s),p=i.getUint32(Ce.BYTES_OF_KEY_VALUE_DATA,s);if(h===0||c!==1)throw new Error("Only 2D textures are supported");if(d!==1)throw new Error("CubeTextures are not supported by KTXLoader yet!");if(u!==1)throw new Error("WebGL does not support array textures");const m=4,_=4,y=l+3&-4,x=h+3&-4,g=new Array(u);let v=l*h;n===0&&(v=y*x);let w;if(n!==0?Vd[n]?w=Vd[n]*Cb[o]:w=Rb[n]:w=Fn[a],w===void 0)throw new Error("Unable to resolve the pixel format stored in the *.ktx file!");const I=e?Db(i,p,s):null;let A=v*w,C=l,N=h,S=y,R=x,E=ul+p;for(let b=0;b<f;b++){const D=i.getUint32(E,s);let F=E+4;for(let G=0;G<u;G++){let $=g[G];$||($=g[G]=new Array(f)),$[b]={levelID:b,levelWidth:f>1||n!==0?C:S,levelHeight:f>1||n!==0?N:R,levelBuffer:new Uint8Array(t,F,A)},F+=A}E+=D+4,E=E%4!==0?E+4-E%4:E,C=C>>1||1,N=N>>1||1,S=C+m-1&~(m-1),R=N+_-1&~(_-1),A=S*R*w}return n!==0?{uncompressed:g.map(b=>{let D=b[0].levelBuffer,F=!1;return n===J.FLOAT?D=new Float32Array(b[0].levelBuffer.buffer,b[0].levelBuffer.byteOffset,b[0].levelBuffer.byteLength/4):n===J.UNSIGNED_INT?(F=!0,D=new Uint32Array(b[0].levelBuffer.buffer,b[0].levelBuffer.byteOffset,b[0].levelBuffer.byteLength/4)):n===J.INT&&(F=!0,D=new Int32Array(b[0].levelBuffer.buffer,b[0].levelBuffer.byteOffset,b[0].levelBuffer.byteLength/4)),{resource:new hn(D,{width:b[0].levelWidth,height:b[0].levelHeight}),type:n,format:F?Bb(o):o}}),kvData:I}:{compressed:g.map(b=>new Zr(null,{format:a,width:l,height:h,levels:f,levelBuffers:b})),kvData:I}}function Mb(r,t){for(let e=0;e<Xd.length;e++)if(t.getUint8(e)!==Xd[e])return console.error(`${r} is not a valid *.ktx file!`),!1;return!0}function Bb(r){switch(r){case k.RGBA:return k.RGBA_INTEGER;case k.RGB:return k.RGB_INTEGER;case k.RG:return k.RG_INTEGER;case k.RED:return k.RED_INTEGER;default:return r}}function Db(r,t,e){const i=new Map;let s=0;for(;s<t;){const n=r.getUint32(ul+s,e),o=ul+s+4,a=3-(n+3)%4;if(n===0||n>t-s){console.error("KTXLoader: keyAndValueByteSize out of bounds");break}let l=0;for(;l<n&&r.getUint8(o+l)!==0;l++);if(l===-1){console.error("KTXLoader: Failed to find null byte terminating kvData key");break}const h=new TextDecoder().decode(new Uint8Array(r.buffer,o,l)),c=new DataView(r.buffer,o+l+1,n-l-1);i.set(h,c),s+=4+n+a}return i}const Ob={extension:{type:X.LoadParser,priority:Ie.High},name:"loadDDS",test(r){return Er(r,".dds")},async load(r,t,e){const i=await(await W.ADAPTER.fetch(r)).arrayBuffer(),s=Sb(i).map(n=>{const o=new nt(n,{mipmap:Le.OFF,alphaMode:ie.NO_PREMULTIPLIED_ALPHA,resolution:hr(r),...t.data});return _s(o,e,r)});return s.length===1?s[0]:s},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};Y.add(Ob);const Fb={extension:{type:X.LoadParser,priority:Ie.High},name:"loadKTX",test(r){return Er(r,".ktx")},async load(r,t,e){const i=await(await W.ADAPTER.fetch(r)).arrayBuffer(),{compressed:s,uncompressed:n,kvData:o}=Pb(r,i),a=s??n,l={mipmap:Le.OFF,alphaMode:ie.NO_PREMULTIPLIED_ALPHA,resolution:hr(r),...t.data},h=a.map(c=>{a===n&&Object.assign(l,{type:c.type,format:c.format});const u=c.resource??c,d=new nt(u,l);return d.ktxKeyValueData=o,_s(d,e,r)});return h.length===1?h[0]:h},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};Y.add(Fb);const Lb=["s3tc","s3tc_sRGB","etc","etc1","pvrtc","atc","astc","bptc"],Nb={extension:X.ResolveParser,test:r=>{const t=Gt.extname(r).slice(1);return["basis","ktx","dds"].includes(t)},parse:r=>{var i,s;const t=r.split("."),e=t.pop();if(["ktx","dds"].includes(e)){const n=t.pop();if(Lb.includes(n))return{resolution:parseFloat(((i=W.RETINA_PREFIX.exec(r))==null?void 0:i[1])??"1"),format:n,src:r}}return{resolution:parseFloat(((s=W.RETINA_PREFIX.exec(r))==null?void 0:s[1])??"1"),format:e,src:r}}};Y.add(Nb);const kn=new at,Ub=4,zd=class As{constructor(t){this.renderer=t,this._rendererPremultipliedAlpha=!1}contextChange(){var e;const t=(e=this.renderer)==null?void 0:e.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(t&&t.alpha&&t.premultipliedAlpha)}async image(t,e,i,s){const n=new Image;return n.src=await this.base64(t,e,i,s),n}async base64(t,e,i,s){const n=this.canvas(t,s);if(n.toBlob!==void 0)return new Promise((o,a)=>{n.toBlob(l=>{if(!l){a(new Error("ICanvas.toBlob failed!"));return}const h=new FileReader;h.onload=()=>o(h.result),h.onerror=a,h.readAsDataURL(l)},e,i)});if(n.toDataURL!==void 0)return n.toDataURL(e,i);if(n.convertToBlob!==void 0){const o=await n.convertToBlob({type:e,quality:i});return new Promise((a,l)=>{const h=new FileReader;h.onload=()=>a(h.result),h.onerror=l,h.readAsDataURL(o)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(t,e){const{pixels:i,width:s,height:n,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);o&&As._flipY(i,s,n),a&&As._unpremultiplyAlpha(i);const l=new _v(s,n,1),h=new ImageData(new Uint8ClampedArray(i.buffer),s,n);return l.context.putImageData(h,0,0),l.canvas}pixels(t,e){const{pixels:i,width:s,height:n,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);return o&&As._flipY(i,s,n),a&&As._unpremultiplyAlpha(i),i}_rawPixels(t,e){const i=this.renderer;if(!i)throw new Error("The Extract has already been destroyed");let s,n=!1,o=!1,a,l=!1;t&&(t instanceof Wr?a=t:(a=i.generateTexture(t,{region:e,resolution:i.resolution,multisample:i.multisample}),l=!0,e&&(kn.width=e.width,kn.height=e.height,e=kn)));const h=i.gl;if(a){if(s=a.baseTexture.resolution,e=e??a.frame,n=!1,o=a.baseTexture.alphaMode>0&&a.baseTexture.format===k.RGBA,!l){i.renderTexture.bind(a);const f=a.framebuffer.glFramebuffers[i.CONTEXT_UID];f.blitFramebuffer&&i.framebuffer.bind(f.blitFramebuffer)}}else s=i.resolution,e||(e=kn,e.width=i.width/s,e.height=i.height/s),n=!0,o=this._rendererPremultipliedAlpha,i.renderTexture.bind();const c=Math.max(Math.round(e.width*s),1),u=Math.max(Math.round(e.height*s),1),d=new Uint8Array(Ub*c*u);return h.readPixels(Math.round(e.x*s),Math.round(e.y*s),c,u,h.RGBA,h.UNSIGNED_BYTE,d),l&&(a==null||a.destroy(!0)),{pixels:d,width:c,height:u,flipY:n,premultipliedAlpha:o}}destroy(){this.renderer=null}static _flipY(t,e,i){const s=e<<2,n=i>>1,o=new Uint8Array(s);for(let a=0;a<n;a++){const l=a*s,h=(i-a-1)*s;o.set(t.subarray(l,l+s)),t.copyWithin(l,h,h+s),t.set(o,h)}}static _unpremultiplyAlpha(t){t instanceof Uint8ClampedArray&&(t=new Uint8Array(t.buffer));const e=t.length;for(let i=0;i<e;i+=4){const s=t[i+3];if(s!==0){const n=255.001/s;t[i]=t[i]*n+.5,t[i+1]=t[i+1]*n+.5,t[i+2]=t[i+2]*n+.5}}}};zd.extension={name:"extract",type:X.RendererSystem};let kb=zd;Y.add(kb);const Gn={build(r){const t=r.points;let e,i,s,n,o,a;if(r.type===Wt.CIRC){const p=r.shape;e=p.x,i=p.y,o=a=p.radius,s=n=0}else if(r.type===Wt.ELIP){const p=r.shape;e=p.x,i=p.y,o=p.width,a=p.height,s=n=0}else{const p=r.shape,m=p.width/2,_=p.height/2;e=p.x+m,i=p.y+_,o=a=Math.max(0,Math.min(p.radius,Math.min(m,_))),s=m-o,n=_-a}if(!(o>=0&&a>=0&&s>=0&&n>=0)){t.length=0;return}const l=Math.ceil(2.3*Math.sqrt(o+a)),h=l*8+(s?4:0)+(n?4:0);if(t.length=h,h===0)return;if(l===0){t.length=8,t[0]=t[6]=e+s,t[1]=t[3]=i+n,t[2]=t[4]=e-s,t[5]=t[7]=i-n;return}let c=0,u=l*4+(s?2:0)+2,d=u,f=h;{const p=s+o,m=n,_=e+p,y=e-p,x=i+m;if(t[c++]=_,t[c++]=x,t[--u]=x,t[--u]=y,n){const g=i-m;t[d++]=y,t[d++]=g,t[--f]=g,t[--f]=_}}for(let p=1;p<l;p++){const m=Math.PI/2*(p/l),_=s+Math.cos(m)*o,y=n+Math.sin(m)*a,x=e+_,g=e-_,v=i+y,w=i-y;t[c++]=x,t[c++]=v,t[--u]=v,t[--u]=g,t[d++]=g,t[d++]=w,t[--f]=w,t[--f]=x}{const p=s,m=n+a,_=e+p,y=e-p,x=i+m,g=i-m;t[c++]=_,t[c++]=x,t[--f]=g,t[--f]=_,s&&(t[c++]=y,t[c++]=x,t[--f]=g,t[--f]=y)}},triangulate(r,t){const e=r.points,i=t.points,s=t.indices;if(e.length===0)return;let n=i.length/2;const o=n;let a,l;if(r.type!==Wt.RREC){const c=r.shape;a=c.x,l=c.y}else{const c=r.shape;a=c.x+c.width/2,l=c.y+c.height/2}const h=r.matrix;i.push(r.matrix?h.a*a+h.c*l+h.tx:a,r.matrix?h.b*a+h.d*l+h.ty:l),n++,i.push(e[0],e[1]);for(let c=2;c<e.length;c+=2)i.push(e[c],e[c+1]),s.push(n++,o,n);s.push(o+1,o,n)}};function Wd(r,t=!1){const e=r.length;if(e<6)return;let i=0;for(let s=0,n=r[e-2],o=r[e-1];s<e;s+=2){const a=r[s],l=r[s+1];i+=(a-n)*(l+o),n=a,o=l}if(!t&&i>0||t&&i<=0){const s=e/2;for(let n=s+s%2;n<e;n+=2){const o=e-n-2,a=e-n-1,l=n,h=n+1;[r[o],r[l]]=[r[l],r[o]],[r[a],r[h]]=[r[h],r[a]]}}}const jd={build(r){r.points=r.shape.points.slice()},triangulate(r,t){let e=r.points;const i=r.holes,s=t.points,n=t.indices;if(e.length>=6){Wd(e,!1);const o=[];for(let h=0;h<i.length;h++){const c=i[h];Wd(c.points,!0),o.push(e.length/2),e=e.concat(c.points)}const a=Ty(e,o,2);if(!a)return;const l=s.length/2;for(let h=0;h<a.length;h+=3)n.push(a[h]+l),n.push(a[h+1]+l),n.push(a[h+2]+l);for(let h=0;h<e.length;h++)s.push(e[h])}}},Gb={build(r){const t=r.shape,e=t.x,i=t.y,s=t.width,n=t.height,o=r.points;o.length=0,s>=0&&n>=0&&o.push(e,i,e+s,i,e+s,i+n,e,i+n)},triangulate(r,t){const e=r.points,i=t.points;if(e.length===0)return;const s=i.length/2;i.push(e[0],e[1],e[2],e[3],e[6],e[7],e[4],e[5]),t.indices.push(s,s+1,s+2,s+1,s+2,s+3)}},$b={build(r){Gn.build(r)},triangulate(r,t){Gn.triangulate(r,t)}};var me=(r=>(r.MITER="miter",r.BEVEL="bevel",r.ROUND="round",r))(me||{}),Tr=(r=>(r.BUTT="butt",r.ROUND="round",r.SQUARE="square",r))(Tr||{});const Li={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount(r,t=20){if(!this.adaptive||!r||isNaN(r))return t;let e=Math.ceil(r/this.maxLength);return e<this.minSegments?e=this.minSegments:e>this.maxSegments&&(e=this.maxSegments),e}};class Yd{static curveTo(t,e,i,s,n,o){const a=o[o.length-2],l=o[o.length-1]-e,h=a-t,c=s-e,u=i-t,d=Math.abs(l*u-h*c);if(d<1e-8||n===0)return(o[o.length-2]!==t||o[o.length-1]!==e)&&o.push(t,e),null;const f=l*l+h*h,p=c*c+u*u,m=l*c+h*u,_=n*Math.sqrt(f)/d,y=n*Math.sqrt(p)/d,x=_*m/f,g=y*m/p,v=_*u+y*h,w=_*c+y*l,I=h*(y+x),A=l*(y+x),C=u*(_+g),N=c*(_+g),S=Math.atan2(A-w,I-v),R=Math.atan2(N-w,C-v);return{cx:v+t,cy:w+e,radius:n,startAngle:S,endAngle:R,anticlockwise:h*c>u*l}}static arc(t,e,i,s,n,o,a,l,h){const c=a-o,u=Li._segmentsCount(Math.abs(c)*n,Math.ceil(Math.abs(c)/un)*40),d=c/(u*2),f=d*2,p=Math.cos(d),m=Math.sin(d),_=u-1,y=_%1/_;for(let x=0;x<=_;++x){const g=x+y*x,v=d+o+f*g,w=Math.cos(v),I=-Math.sin(v);h.push((p*w+m*I)*n+i,(p*-I+m*w)*n+s)}}}class Hb{constructor(){this.reset()}begin(t,e,i){this.reset(),this.style=t,this.start=e,this.attribStart=i}end(t,e){this.attribSize=e-this.attribStart,this.size=t-this.start}reset(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0}}class dl{static curveLength(t,e,i,s,n,o,a,l){let h=0,c=0,u=0,d=0,f=0,p=0,m=0,_=0,y=0,x=0,g=0,v=t,w=e;for(let I=1;I<=10;++I)c=I/10,u=c*c,d=u*c,f=1-c,p=f*f,m=p*f,_=m*t+3*p*c*i+3*f*u*n+d*a,y=m*e+3*p*c*s+3*f*u*o+d*l,x=v-_,g=w-y,v=_,w=y,h+=Math.sqrt(x*x+g*g);return h}static curveTo(t,e,i,s,n,o,a){const l=a[a.length-2],h=a[a.length-1];a.length-=2;const c=Li._segmentsCount(dl.curveLength(l,h,t,e,i,s,n,o));let u=0,d=0,f=0,p=0,m=0;a.push(l,h);for(let _=1,y=0;_<=c;++_)y=_/c,u=1-y,d=u*u,f=d*u,p=y*y,m=p*y,a.push(f*l+3*d*y*t+3*u*p*i+m*n,f*h+3*d*y*e+3*u*p*s+m*o)}}function qd(r,t,e,i,s,n,o,a){const l=r-e*s,h=t-i*s,c=r+e*n,u=t+i*n;let d,f;o?(d=i,f=-e):(d=-i,f=e);const p=l+d,m=h+f,_=c+d,y=u+f;return a.push(p,m,_,y),2}function Jr(r,t,e,i,s,n,o,a){const l=e-r,h=i-t;let c=Math.atan2(l,h),u=Math.atan2(s-r,n-t);a&&c<u?c+=Math.PI*2:!a&&c>u&&(u+=Math.PI*2);let d=c;const f=u-c,p=Math.abs(f),m=Math.sqrt(l*l+h*h),_=(15*p*Math.sqrt(m)/Math.PI>>0)+1,y=f/_;if(d+=y,a){o.push(r,t,e,i);for(let x=1,g=d;x<_;x++,g+=y)o.push(r,t,r+Math.sin(g)*m,t+Math.cos(g)*m);o.push(r,t,s,n)}else{o.push(e,i,r,t);for(let x=1,g=d;x<_;x++,g+=y)o.push(r+Math.sin(g)*m,t+Math.cos(g)*m,r,t);o.push(s,n,r,t)}return _*2}function Xb(r,t){const e=r.shape;let i=r.points||e.points.slice();const s=t.closePointEps;if(i.length===0)return;const n=r.lineStyle,o=new gt(i[0],i[1]),a=new gt(i[i.length-2],i[i.length-1]),l=e.type!==Wt.POLY||e.closeStroke,h=Math.abs(o.x-a.x)<s&&Math.abs(o.y-a.y)<s;if(l){i=i.slice(),h&&(i.pop(),i.pop(),a.set(i[i.length-2],i[i.length-1]));const $=(o.x+a.x)*.5,B=(a.y+o.y)*.5;i.unshift($,B),i.push($,B)}const c=t.points,u=i.length/2;let d=i.length;const f=c.length/2,p=n.width/2,m=p*p,_=n.miterLimit*n.miterLimit;let y=i[0],x=i[1],g=i[2],v=i[3],w=0,I=0,A=-(x-v),C=y-g,N=0,S=0,R=Math.sqrt(A*A+C*C);A/=R,C/=R,A*=p,C*=p;const E=n.alignment,b=(1-E)*2,D=E*2;l||(n.cap===Tr.ROUND?d+=Jr(y-A*(b-D)*.5,x-C*(b-D)*.5,y-A*b,x-C*b,y+A*D,x+C*D,c,!0)+2:n.cap===Tr.SQUARE&&(d+=qd(y,x,A,C,b,D,!0,c))),c.push(y-A*b,x-C*b,y+A*D,x+C*D);for(let $=1;$<u-1;++$){y=i[($-1)*2],x=i[($-1)*2+1],g=i[$*2],v=i[$*2+1],w=i[($+1)*2],I=i[($+1)*2+1],A=-(x-v),C=y-g,R=Math.sqrt(A*A+C*C),A/=R,C/=R,A*=p,C*=p,N=-(v-I),S=g-w,R=Math.sqrt(N*N+S*S),N/=R,S/=R,N*=p,S*=p;const B=g-y,Z=x-v,P=g-w,U=I-v,j=B*P+Z*U,rt=Z*P-U*B,Q=rt<0;if(Math.abs(rt)<.001*Math.abs(j)){c.push(g-A*b,v-C*b,g+A*D,v+C*D),j>=0&&(n.join===me.ROUND?d+=Jr(g,v,g-A*b,v-C*b,g-N*b,v-S*b,c,!1)+4:d+=2,c.push(g-N*D,v-S*D,g+N*b,v+S*b));continue}const H=(-A+y)*(-C+v)-(-A+g)*(-C+x),V=(-N+w)*(-S+v)-(-N+g)*(-S+I),lt=(B*V-P*H)/rt,L=(U*H-Z*V)/rt,O=(lt-g)*(lt-g)+(L-v)*(L-v),_t=g+(lt-g)*b,ht=v+(L-v)*b,vt=g-(lt-g)*D,xt=v-(L-v)*D,Ye=Math.min(B*B+Z*Z,P*P+U*U),qe=Q?b:D,ws=Ye+qe*qe*m,UE=O<=ws;let Zn=n.join;if(Zn===me.MITER&&O/m>_&&(Zn=me.BEVEL),UE)switch(Zn){case me.MITER:{c.push(_t,ht,vt,xt);break}case me.BEVEL:{Q?c.push(_t,ht,g+A*D,v+C*D,_t,ht,g+N*D,v+S*D):c.push(g-A*b,v-C*b,vt,xt,g-N*b,v-S*b,vt,xt),d+=2;break}case me.ROUND:{Q?(c.push(_t,ht,g+A*D,v+C*D),d+=Jr(g,v,g+A*D,v+C*D,g+N*D,v+S*D,c,!0)+4,c.push(_t,ht,g+N*D,v+S*D)):(c.push(g-A*b,v-C*b,vt,xt),d+=Jr(g,v,g-A*b,v-C*b,g-N*b,v-S*b,c,!1)+4,c.push(g-N*b,v-S*b,vt,xt));break}}else{switch(c.push(g-A*b,v-C*b,g+A*D,v+C*D),Zn){case me.MITER:{Q?c.push(vt,xt,vt,xt):c.push(_t,ht,_t,ht),d+=2;break}case me.ROUND:{Q?d+=Jr(g,v,g+A*D,v+C*D,g+N*D,v+S*D,c,!0)+2:d+=Jr(g,v,g-A*b,v-C*b,g-N*b,v-S*b,c,!1)+2;break}}c.push(g-N*b,v-S*b,g+N*D,v+S*D),d+=2}}y=i[(u-2)*2],x=i[(u-2)*2+1],g=i[(u-1)*2],v=i[(u-1)*2+1],A=-(x-v),C=y-g,R=Math.sqrt(A*A+C*C),A/=R,C/=R,A*=p,C*=p,c.push(g-A*b,v-C*b,g+A*D,v+C*D),l||(n.cap===Tr.ROUND?d+=Jr(g-A*(b-D)*.5,v-C*(b-D)*.5,g-A*b,v-C*b,g+A*D,v+C*D,c,!1)+2:n.cap===Tr.SQUARE&&(d+=qd(g,v,A,C,b,D,!1,c)));const F=t.indices,G=Li.epsilon*Li.epsilon;for(let $=f;$<d+f-2;++$)y=c[$*2],x=c[$*2+1],g=c[($+1)*2],v=c[($+1)*2+1],w=c[($+2)*2],I=c[($+2)*2+1],!(Math.abs(y*(v-I)+g*(I-x)+w*(x-v))<G)&&F.push($,$+1,$+2)}function Vb(r,t){let e=0;const i=r.shape,s=r.points||i.points,n=i.type!==Wt.POLY||i.closeStroke;if(s.length===0)return;const o=t.points,a=t.indices,l=s.length/2,h=o.length/2;let c=h;for(o.push(s[0],s[1]),e=1;e<l;e++)o.push(s[e*2],s[e*2+1]),a.push(c,c+1),c++;n&&a.push(c,h)}function Kd(r,t){r.lineStyle.native?Vb(r,t):Xb(r,t)}class fl{static curveLength(t,e,i,s,n,o){const a=t-2*i+n,l=e-2*s+o,h=2*i-2*t,c=2*s-2*e,u=4*(a*a+l*l),d=4*(a*h+l*c),f=h*h+c*c,p=2*Math.sqrt(u+d+f),m=Math.sqrt(u),_=2*u*m,y=2*Math.sqrt(f),x=d/m;return(_*p+m*d*(p-y)+(4*f*u-d*d)*Math.log((2*m+x+p)/(x+y)))/(4*_)}static curveTo(t,e,i,s,n){const o=n[n.length-2],a=n[n.length-1],l=Li._segmentsCount(fl.curveLength(o,a,t,e,i,s));let h=0,c=0;for(let u=1;u<=l;++u){const d=u/l;h=o+(t-o)*d,c=a+(e-a)*d,n.push(h+(t+(i-t)*d-h)*d,c+(e+(s-e)*d-c)*d)}}}const pl={[Wt.POLY]:jd,[Wt.CIRC]:Gn,[Wt.ELIP]:Gn,[Wt.RECT]:Gb,[Wt.RREC]:$b},Zd=[],$n=[];class Hn{constructor(t,e=null,i=null,s=null){this.points=[],this.holes=[],this.shape=t,this.lineStyle=i,this.fillStyle=e,this.matrix=s,this.type=t.type}clone(){return new Hn(this.shape,this.fillStyle,this.lineStyle,this.matrix)}destroy(){this.shape=null,this.holes.length=0,this.holes=null,this.points.length=0,this.points=null,this.lineStyle=null,this.fillStyle=null}}const Ni=new gt,Jd=class zf extends Pu{constructor(){super(),this.closePointEps=1e-4,this.boundsPadding=0,this.uvsFloat32=null,this.indicesUint16=null,this.batchable=!1,this.points=[],this.colors=[],this.uvs=[],this.indices=[],this.textureIds=[],this.graphicsData=[],this.drawCalls=[],this.batchDirty=-1,this.batches=[],this.dirty=0,this.cacheDirty=-1,this.clearDirty=0,this.shapeIndex=0,this._bounds=new Rn,this.boundsDirty=-1}get bounds(){return this.updateBatches(),this.boundsDirty!==this.dirty&&(this.boundsDirty=this.dirty,this.calculateBounds()),this._bounds}invalidate(){this.boundsDirty=-1,this.dirty++,this.batchDirty++,this.shapeIndex=0,this.points.length=0,this.colors.length=0,this.uvs.length=0,this.indices.length=0,this.textureIds.length=0;for(let t=0;t<this.drawCalls.length;t++)this.drawCalls[t].texArray.clear(),$n.push(this.drawCalls[t]);this.drawCalls.length=0;for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e.reset(),Zd.push(e)}this.batches.length=0}clear(){return this.graphicsData.length>0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this}drawShape(t,e=null,i=null,s=null){const n=new Hn(t,e,i,s);return this.graphicsData.push(n),this.dirty++,this}drawHole(t,e=null){if(!this.graphicsData.length)return null;const i=new Hn(t,null,null,e),s=this.graphicsData[this.graphicsData.length-1];return i.lineStyle=s.lineStyle,s.holes.push(i),this.dirty++,this}destroy(){super.destroy();for(let t=0;t<this.graphicsData.length;++t)this.graphicsData[t].destroy();this.points.length=0,this.points=null,this.colors.length=0,this.colors=null,this.uvs.length=0,this.uvs=null,this.indices.length=0,this.indices=null,this.indexBuffer.destroy(),this.indexBuffer=null,this.graphicsData.length=0,this.graphicsData=null,this.drawCalls.length=0,this.drawCalls=null,this.batches.length=0,this.batches=null,this._bounds=null}containsPoint(t){const e=this.graphicsData;for(let i=0;i<e.length;++i){const s=e[i];if(s.fillStyle.visible&&s.shape&&(s.matrix?s.matrix.applyInverse(t,Ni):Ni.copyFrom(t),s.shape.contains(Ni.x,Ni.y))){let n=!1;if(s.holes){for(let o=0;o<s.holes.length;o++)if(s.holes[o].shape.contains(Ni.x,Ni.y)){n=!0;break}}if(!n)return!0}}return!1}updateBatches(){if(!this.graphicsData.length){this.batchable=!0;return}if(!this.validateBatching())return;this.cacheDirty=this.dirty;const t=this.uvs,e=this.graphicsData;let i=null,s=null;this.batches.length>0&&(i=this.batches[this.batches.length-1],s=i.style);for(let l=this.shapeIndex;l<e.length;l++){this.shapeIndex++;const h=e[l],c=h.fillStyle,u=h.lineStyle;pl[h.type].build(h),h.matrix&&this.transformPoints(h.points,h.matrix),(c.visible||u.visible)&&this.processHoles(h.holes);for(let d=0;d<2;d++){const f=d===0?c:u;if(!f.visible)continue;const p=f.texture.baseTexture,m=this.indices.length,_=this.points.length/2;p.wrapMode=gr.REPEAT,d===0?this.processFill(h):this.processLine(h);const y=this.points.length/2-_;y!==0&&(i&&!this._compareStyles(s,f)&&(i.end(m,_),i=null),i||(i=Zd.pop()||new Hb,i.begin(f,m,_),this.batches.push(i),s=f),this.addUvs(this.points,t,f.texture,_,y,f.matrix))}}const n=this.indices.length,o=this.points.length/2;if(i&&i.end(n,o),this.batches.length===0){this.batchable=!0;return}const a=o>65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&a===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=a?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}_compareStyles(t,e){return!(!t||!e||t.texture.baseTexture!==e.texture.baseTexture||t.color+t.alpha!==e.color+e.alpha||!!t.native!=!!e.native)}validateBatching(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(let t=0,e=this.graphicsData.length;t<e;t++){const i=this.graphicsData[t],s=i.fillStyle,n=i.lineStyle;if(s&&!s.texture.baseTexture.valid||n&&!n.texture.baseTexture.valid)return!1}return!0}packBatches(){this.batchDirty++,this.uvsFloat32=new Float32Array(this.uvs);const t=this.batches;for(let e=0,i=t.length;e<i;e++){const s=t[e];for(let n=0;n<s.size;n++){const o=s.start+n;this.indicesUint16[o]=this.indicesUint16[o]-s.attribStart}}}isBatchable(){if(this.points.length>65535*2)return!1;const t=this.batches;for(let e=0;e<t.length;e++)if(t[e].style.native)return!1;return this.points.length<zf.BATCHABLE_SIZE*2}buildDrawCalls(){let t=++nt._globalBatch;for(let u=0;u<this.drawCalls.length;u++)this.drawCalls[u].texArray.clear(),$n.push(this.drawCalls[u]);this.drawCalls.length=0;const e=this.colors,i=this.textureIds;let s=$n.pop();s||(s=new Na,s.texArray=new Xa),s.texArray.count=0,s.start=0,s.size=0,s.type=Fe.TRIANGLES;let n=0,o=null,a=0,l=!1,h=Fe.TRIANGLES,c=0;this.drawCalls.push(s);for(let u=0;u<this.batches.length;u++){const d=this.batches[u],f=8,p=d.style,m=p.texture.baseTexture;l!==!!p.native&&(l=!!p.native,h=l?Fe.LINES:Fe.TRIANGLES,o=null,n=f,t++),o!==m&&(o=m,m._batchEnabled!==t&&(n===f&&(t++,n=0,s.size>0&&(s=$n.pop(),s||(s=new Na,s.texArray=new Xa),this.drawCalls.push(s)),s.start=c,s.size=0,s.texArray.count=0,s.type=h),m.touched=1,m._batchEnabled=t,m._batchLocation=n,m.wrapMode=gr.REPEAT,s.texArray.elements[s.texArray.count++]=m,n++)),s.size+=d.size,c+=d.size,a=m._batchLocation,this.addColors(e,p.color,p.alpha,d.attribSize,d.attribStart),this.addTextureIds(i,a,d.attribSize,d.attribStart)}nt._globalBatch=t,this.packAttributes()}packAttributes(){const t=this.points,e=this.uvs,i=this.colors,s=this.textureIds,n=new ArrayBuffer(t.length*3*4),o=new Float32Array(n),a=new Uint32Array(n);let l=0;for(let h=0;h<t.length/2;h++)o[l++]=t[h*2],o[l++]=t[h*2+1],o[l++]=e[h*2],o[l++]=e[h*2+1],a[l++]=i[h],o[l++]=s[h];this._buffer.update(n),this._indexBuffer.update(this.indicesUint16)}processFill(t){t.holes.length?jd.triangulate(t,this):pl[t.type].triangulate(t,this)}processLine(t){Kd(t,this);for(let e=0;e<t.holes.length;e++)Kd(t.holes[e],this)}processHoles(t){for(let e=0;e<t.length;e++){const i=t[e];pl[i.type].build(i),i.matrix&&this.transformPoints(i.points,i.matrix)}}calculateBounds(){const t=this._bounds;t.clear(),t.addVertexData(this.points,0,this.points.length),t.pad(this.boundsPadding,this.boundsPadding)}transformPoints(t,e){for(let i=0;i<t.length/2;i++){const s=t[i*2],n=t[i*2+1];t[i*2]=e.a*s+e.c*n+e.tx,t[i*2+1]=e.b*s+e.d*n+e.ty}}addColors(t,e,i,s,n=0){const o=bt.shared.setValue(e).toLittleEndianNumber(),a=bt.shared.setValue(o).toPremultiplied(i);t.length=Math.max(t.length,n+s);for(let l=0;l<s;l++)t[n+l]=a}addTextureIds(t,e,i,s=0){t.length=Math.max(t.length,s+i);for(let n=0;n<i;n++)t[s+n]=e}addUvs(t,e,i,s,n,o=null){let a=0;const l=e.length,h=i.frame;for(;a<n;){let u=t[(s+a)*2],d=t[(s+a)*2+1];if(o){const f=o.a*u+o.c*d+o.tx;d=o.b*u+o.d*d+o.ty,u=f}a++,e.push(u/h.width,d/h.height)}const c=i.baseTexture;(h.width<c.width||h.height<c.height)&&this.adjustUvs(e,i,l,n)}adjustUvs(t,e,i,s){const n=e.baseTexture,o=1e-6,a=i+s*2,l=e.frame,h=l.width/n.width,c=l.height/n.height;let u=l.x/l.width,d=l.y/l.height,f=Math.floor(t[i]+o),p=Math.floor(t[i+1]+o);for(let m=i+2;m<a;m+=2)f=Math.min(f,Math.floor(t[m]+o)),p=Math.min(p,Math.floor(t[m+1]+o));u-=f,d-=p;for(let m=i;m<a;m+=2)t[m]=(t[m]+u)*h,t[m+1]=(t[m+1]+d)*c}};Jd.BATCHABLE_SIZE=100;let zb=Jd;class Xn{constructor(){this.color=16777215,this.alpha=1,this.texture=q.WHITE,this.matrix=null,this.visible=!1,this.reset()}clone(){const t=new Xn;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t}reset(){this.color=16777215,this.alpha=1,this.texture=q.WHITE,this.matrix=null,this.visible=!1}destroy(){this.texture=null,this.matrix=null}}class ml extends Xn{constructor(){super(...arguments),this.width=0,this.alignment=.5,this.native=!1,this.cap=Tr.BUTT,this.join=me.MITER,this.miterLimit=10}clone(){const t=new ml;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t.width=this.width,t.alignment=this.alignment,t.native=this.native,t.cap=this.cap,t.join=this.join,t.miterLimit=this.miterLimit,t}reset(){super.reset(),this.color=0,this.alignment=.5,this.width=0,this.native=!1,this.cap=Tr.BUTT,this.join=me.MITER,this.miterLimit=10}}const gl={},yl=class ro extends Te{constructor(t=null){super(),this.shader=null,this.pluginName="batch",this.currentPath=null,this.batches=[],this.batchTint=-1,this.batchDirty=-1,this.vertexData=null,this._fillStyle=new Xn,this._lineStyle=new ml,this._matrix=null,this._holeMode=!1,this.state=Ve.for2d(),this._geometry=t||new zb,this._geometry.refCount++,this._transformID=-1,this._tintColor=new bt(16777215),this.blendMode=tt.NORMAL}get geometry(){return this._geometry}clone(){return this.finishPoly(),new ro(this._geometry)}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t)}get fill(){return this._fillStyle}get line(){return this._lineStyle}lineStyle(t=null,e=0,i,s=.5,n=!1){return typeof t=="number"&&(t={width:t,color:e,alpha:i,alignment:s,native:n}),this.lineTextureStyle(t)}lineTextureStyle(t){const e={width:0,texture:q.WHITE,color:t!=null&&t.texture?16777215:0,matrix:null,alignment:.5,native:!1,cap:Tr.BUTT,join:me.MITER,miterLimit:10};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.width>0&&t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._lineStyle,{visible:i},t)):this._lineStyle.reset(),this}startPoly(){if(this.currentPath){const t=this.currentPath.points,e=this.currentPath.points.length;e>2&&(this.drawShape(this.currentPath),this.currentPath=new Gr,this.currentPath.closeStroke=!1,this.currentPath.points.push(t[e-2],t[e-1]))}else this.currentPath=new Gr,this.currentPath.closeStroke=!1}finishPoly(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)}moveTo(t,e){return this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this}lineTo(t,e){this.currentPath||this.moveTo(0,0);const i=this.currentPath.points,s=i[i.length-2],n=i[i.length-1];return(s!==t||n!==e)&&i.push(t,e),this}_initCurve(t=0,e=0){this.currentPath?this.currentPath.points.length===0&&(this.currentPath.points=[t,e]):this.moveTo(t,e)}quadraticCurveTo(t,e,i,s){this._initCurve();const n=this.currentPath.points;return n.length===0&&this.moveTo(0,0),fl.curveTo(t,e,i,s,n),this}bezierCurveTo(t,e,i,s,n,o){return this._initCurve(),dl.curveTo(t,e,i,s,n,o,this.currentPath.points),this}arcTo(t,e,i,s,n){this._initCurve(t,e);const o=this.currentPath.points,a=Yd.curveTo(t,e,i,s,n,o);if(a){const{cx:l,cy:h,radius:c,startAngle:u,endAngle:d,anticlockwise:f}=a;this.arc(l,h,c,u,d,f)}return this}arc(t,e,i,s,n,o=!1){if(s===n)return this;if(!o&&n<=s?n+=un:o&&s<=n&&(s+=un),n-s===0)return this;const a=t+Math.cos(s)*i,l=e+Math.sin(s)*i,h=this._geometry.closePointEps;let c=this.currentPath?this.currentPath.points:null;if(c){const u=Math.abs(c[c.length-2]-a),d=Math.abs(c[c.length-1]-l);u<h&&d<h||c.push(a,l)}else this.moveTo(a,l),c=this.currentPath.points;return Yd.arc(a,l,t,e,i,s,n,o,c),this}beginFill(t=0,e){return this.beginTextureFill({texture:q.WHITE,color:t,alpha:e})}normalizeColor(t){const e=bt.shared.setValue(t.color??0);t.color=e.toNumber(),t.alpha??(t.alpha=e.alpha)}beginTextureFill(t){const e={texture:q.WHITE,color:16777215,matrix:null};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._fillStyle,{visible:i},t)):this._fillStyle.reset(),this}endFill(){return this.finishPoly(),this._fillStyle.reset(),this}drawRect(t,e,i,s){return this.drawShape(new at(t,e,i,s))}drawRoundedRect(t,e,i,s,n){return this.drawShape(new mn(t,e,i,s,n))}drawCircle(t,e,i){return this.drawShape(new fn(t,e,i))}drawEllipse(t,e,i,s){return this.drawShape(new pn(t,e,i,s))}drawPolygon(...t){let e,i=!0;const s=t[0];s.points?(i=s.closeStroke,e=s.points):Array.isArray(t[0])?e=t[0]:e=t;const n=new Gr(e);return n.closeStroke=i,this.drawShape(n),this}drawShape(t){return this._holeMode?this._geometry.drawHole(t,this._matrix):this._geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone(),this._matrix),this}clear(){return this._geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this._boundsID++,this._matrix=null,this._holeMode=!1,this.currentPath=null,this}isFastRect(){const t=this._geometry.graphicsData;return t.length===1&&t[0].shape.type===Wt.RECT&&!t[0].matrix&&!t[0].holes.length&&!(t[0].lineStyle.visible&&t[0].lineStyle.width)}_render(t){this.finishPoly();const e=this._geometry;e.updateBatches(),e.batchable?(this.batchDirty!==e.batchDirty&&this._populateBatches(),this._renderBatched(t)):(t.batch.flush(),this._renderDirect(t))}_populateBatches(){const t=this._geometry,e=this.blendMode,i=t.batches.length;this.batchTint=-1,this._transformID=-1,this.batchDirty=t.batchDirty,this.batches.length=i,this.vertexData=new Float32Array(t.points);for(let s=0;s<i;s++){const n=t.batches[s],o=n.style.color,a=new Float32Array(this.vertexData.buffer,n.attribStart*4*2,n.attribSize*2),l=new Float32Array(t.uvsFloat32.buffer,n.attribStart*4*2,n.attribSize*2),h=new Uint16Array(t.indicesUint16.buffer,n.start*2,n.size),c={vertexData:a,blendMode:e,indices:h,uvs:l,_batchRGB:bt.shared.setValue(o).toRgbArray(),_tintRGB:o,_texture:n.style.texture,alpha:n.style.alpha,worldAlpha:1};this.batches[s]=c}}_renderBatched(t){if(this.batches.length){t.batch.setObjectRenderer(t.plugins[this.pluginName]),this.calculateVertices(),this.calculateTints();for(let e=0,i=this.batches.length;e<i;e++){const s=this.batches[e];s.worldAlpha=this.worldAlpha*s.alpha,t.plugins[this.pluginName].render(s)}}}_renderDirect(t){const e=this._resolveDirectShader(t),i=this._geometry,s=this.worldAlpha,n=e.uniforms,o=i.drawCalls;n.translationMatrix=this.transform.worldTransform,bt.shared.setValue(this._tintColor).premultiply(s).toArray(n.tint),t.shader.bind(e),t.geometry.bind(i,e),t.state.set(this.state);for(let a=0,l=o.length;a<l;a++)this._renderDrawCallDirect(t,i.drawCalls[a])}_renderDrawCallDirect(t,e){const{texArray:i,type:s,size:n,start:o}=e,a=i.count;for(let l=0;l<a;l++)t.texture.bind(i.elements[l],l);t.geometry.draw(s,n,o)}_resolveDirectShader(t){let e=this.shader;const i=this.pluginName;if(!e){if(!gl[i]){const{maxTextures:s}=t.plugins[i],n=new Int32Array(s);for(let l=0;l<s;l++)n[l]=l;const o={tint:new Float32Array([1,1,1,1]),translationMatrix:new Et,default:Ee.from({uSamplers:n},!0)},a=t.plugins[i]._shader.program;gl[i]=new ze(a,o)}e=gl[i]}return e}_calculateBounds(){this.finishPoly();const t=this._geometry;if(!t.graphicsData.length)return;const{minX:e,minY:i,maxX:s,maxY:n}=t.bounds;this._bounds.addFrame(this.transform,e,i,s,n)}containsPoint(t){return this.worldTransform.applyInverse(t,ro._TEMP_POINT),this._geometry.containsPoint(ro._TEMP_POINT)}calculateTints(){if(this.batchTint!==this.tint){this.batchTint=this._tintColor.toNumber();for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e._tintRGB=bt.shared.setValue(this._tintColor).multiply(e._batchRGB).toLittleEndianNumber()}}}calculateVertices(){const t=this.transform._worldID;if(this._transformID===t)return;this._transformID=t;const e=this.transform.worldTransform,i=e.a,s=e.b,n=e.c,o=e.d,a=e.tx,l=e.ty,h=this._geometry.points,c=this.vertexData;let u=0;for(let d=0;d<h.length;d+=2){const f=h[d],p=h[d+1];c[u++]=i*f+n*p+a,c[u++]=o*p+s*f+l}}closePath(){const t=this.currentPath;return t&&(t.closeStroke=!0,this.finishPoly()),this}setMatrix(t){return this._matrix=t,this}beginHole(){return this.finishPoly(),this._holeMode=!0,this}endHole(){return this.finishPoly(),this._holeMode=!1,this}destroy(t){this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose(),this._matrix=null,this.currentPath=null,this._lineStyle.destroy(),this._lineStyle=null,this._fillStyle.destroy(),this._fillStyle=null,this._geometry=null,this.shader=null,this.vertexData=null,this.batches.length=0,this.batches=null,super.destroy(t)}};yl.curves=Li,yl._TEMP_POINT=new gt;let vs=yl;class Wb{constructor(t,e){this.uvBuffer=t,this.uvMatrix=e,this.data=null,this._bufferUpdateId=-1,this._textureUpdateId=-1,this._updateID=0}update(t){if(!t&&this._bufferUpdateId===this.uvBuffer._updateID&&this._textureUpdateId===this.uvMatrix._updateID)return;this._bufferUpdateId=this.uvBuffer._updateID,this._textureUpdateId=this.uvMatrix._updateID;const e=this.uvBuffer.data;(!this.data||this.data.length!==e.length)&&(this.data=new Float32Array(e.length)),this.uvMatrix.multiplyUvs(e,this.data),this._updateID++}}const _l=new gt,Qd=new Gr,tf=class Wf extends Te{constructor(t,e,i,s=Fe.TRIANGLES){super(),this.geometry=t,this.shader=e,this.state=i||Ve.for2d(),this.drawMode=s,this.start=0,this.size=0,this.uvs=null,this.indices=null,this.vertexData=new Float32Array(1),this.vertexDirty=-1,this._transformID=-1,this._roundPixels=W.ROUND_PIXELS,this.batchUvs=null}get geometry(){return this._geometry}set geometry(t){this._geometry!==t&&(this._geometry&&(this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose()),this._geometry=t,this._geometry&&this._geometry.refCount++,this.vertexDirty=-1)}get uvBuffer(){return this.geometry.buffers[1]}get verticesBuffer(){return this.geometry.buffers[0]}set material(t){this.shader=t}get material(){return this.shader}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get tint(){return"tint"in this.shader?this.shader.tint:null}set tint(t){this.shader.tint=t}get tintValue(){return this.shader.tintValue}get texture(){return"texture"in this.shader?this.shader.texture:null}set texture(t){this.shader.texture=t}_render(t){const e=this.geometry.buffers[0].data;this.shader.batchable&&this.drawMode===Fe.TRIANGLES&&e.length<Wf.BATCHABLE_SIZE*2?this._renderToBatch(t):this._renderDefault(t)}_renderDefault(t){const e=this.shader;e.alpha=this.worldAlpha,e.update&&e.update(),t.batch.flush(),e.uniforms.translationMatrix=this.transform.worldTransform.toArray(!0),t.shader.bind(e),t.state.set(this.state),t.geometry.bind(this.geometry,e),t.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}_renderToBatch(t){const e=this.geometry,i=this.shader;i.uvMatrix&&(i.uvMatrix.update(),this.calculateUvs()),this.calculateVertices(),this.indices=e.indexBuffer.data,this._tintRGB=i._tintRGB,this._texture=i.texture;const s=this.material.pluginName;t.batch.setObjectRenderer(t.plugins[s]),t.plugins[s].render(this)}calculateVertices(){const t=this.geometry.buffers[0],e=t.data,i=t._updateID;if(i===this.vertexDirty&&this._transformID===this.transform._worldID)return;this._transformID=this.transform._worldID,this.vertexData.length!==e.length&&(this.vertexData=new Float32Array(e.length));const s=this.transform.worldTransform,n=s.a,o=s.b,a=s.c,l=s.d,h=s.tx,c=s.ty,u=this.vertexData;for(let d=0;d<u.length/2;d++){const f=e[d*2],p=e[d*2+1];u[d*2]=n*f+a*p+h,u[d*2+1]=o*f+l*p+c}if(this._roundPixels){const d=W.RESOLUTION;for(let f=0;f<u.length;++f)u[f]=Math.round(u[f]*d)/d}this.vertexDirty=i}calculateUvs(){const t=this.geometry.buffers[1],e=this.shader;e.uvMatrix.isSimple?this.uvs=t.data:(this.batchUvs||(this.batchUvs=new Wb(t,e.uvMatrix)),this.batchUvs.update(),this.uvs=this.batchUvs.data)}_calculateBounds(){this.calculateVertices(),this._bounds.addVertexData(this.vertexData,0,this.vertexData.length)}containsPoint(t){if(!this.getBounds().contains(t.x,t.y))return!1;this.worldTransform.applyInverse(t,_l);const e=this.geometry.getBuffer("aVertexPosition").data,i=Qd.points,s=this.geometry.getIndex().data,n=s.length,o=this.drawMode===4?3:1;for(let a=0;a+2<n;a+=o){const l=s[a]*2,h=s[a+1]*2,c=s[a+2]*2;if(i[0]=e[l],i[1]=e[l+1],i[2]=e[h],i[3]=e[h+1],i[4]=e[c],i[5]=e[c+1],Qd.contains(_l.x,_l.y))return!0}return!1}destroy(t){super.destroy(t),this._cachedTexture&&(this._cachedTexture.destroy(),this._cachedTexture=null),this.geometry=null,this.shader=null,this.state=null,this.uvs=null,this.indices=null,this.vertexData=null}};tf.BATCHABLE_SIZE=100;let ef=tf;class jb extends br{constructor(t,e,i){super();const s=new Bt(t),n=new Bt(e,!0),o=new Bt(i,!0,!0);this.addAttribute("aVertexPosition",s,2,!1,J.FLOAT).addAttribute("aTextureCoord",n,2,!1,J.FLOAT).addIndex(o),this._updateId=-1}get vertexDirtyId(){return this.buffers[0]._updateID}}var Yb=`varying vec2 vTextureCoord;
911
+ Please use Assets.add({ alias, src, data, format, loadParser }) instead.`),o.push({alias:t,src:e,data:i,format:s,loadParser:n})):Array.isArray(t)?o.push(...t):o.push(t);let a;a=l=>{this.hasKey(l)&&console.warn(`[Resolver] already has key: ${l} overwriting`)},Se(o).forEach(l=>{const{src:h,srcs:c}=l;let{data:u,format:d,loadParser:f}=l;const p=Se(h||c).map(y=>typeof y=="string"?wx(y):Array.isArray(y)?y:[y]),m=this.getAlias(l);Array.isArray(m)?m.forEach(a):a(m);const _=[];p.forEach(y=>{y.forEach(x=>{let g={};if(typeof x!="object"){g.src=x;for(let v=0;v<this._parsers.length;v++){const w=this._parsers[v];if(w.test(x)){g=w.parse(x);break}}}else u=x.data??u,d=x.format??d,f=x.loadParser??f,g={...g,...x};if(!m)throw new Error(`[Resolver] alias is undefined for this asset: ${g.src}`);g=this.buildResolvedAsset(g,{aliases:m,data:u,format:d,loadParser:f}),_.push(g)})}),m.forEach(y=>{this._assetMap[y]=_})})}resolveBundle(t){const e=Bn(t);t=Se(t);const i={};return t.forEach(s=>{const n=this._bundles[s];if(n){const o=this.resolve(n),a={};for(const l in o){const h=o[l];a[this._extractAssetIdFromBundle(s,l)]=h}i[s]=a}}),e?i[t[0]]:i}resolveUrl(t){const e=this.resolve(t);if(typeof t!="string"){const i={};for(const s in e)i[s]=e[s].src;return i}return e.src}resolve(t){const e=Bn(t);t=Se(t);const i={};return t.forEach(s=>{if(!this._resolverHash[s])if(this._assetMap[s]){let n=this._assetMap[s];const o=n[0],a=this._getPreferredOrder(n);a==null||a.priority.forEach(l=>{a.params[l].forEach(h=>{const c=n.filter(u=>u[l]?u[l]===h:!1);c.length&&(n=c)})}),this._resolverHash[s]=n[0]??o}else this._resolverHash[s]=this.buildResolvedAsset({alias:[s],src:s},{});i[s]=this._resolverHash[s]}),e?i[t[0]]:i}hasKey(t){return!!this._assetMap[t]}hasBundle(t){return!!this._bundles[t]}_getPreferredOrder(t){for(let e=0;e<t.length;e++){const i=t[0],s=this._preferredOrder.find(n=>n.params.format.includes(i.format));if(s)return s}return this._preferredOrder[0]}_appendDefaultSearchParams(t){if(!this._defaultSearchParams)return t;const e=/\?/.test(t)?"&":"?";return`${t}${e}${this._defaultSearchParams}`}buildResolvedAsset(t,e){const{aliases:i,data:s,loadParser:n,format:o}=e;return(this._basePath||this._rootPath)&&(t.src=Gt.toAbsolute(t.src,this._basePath,this._rootPath)),t.alias=i??t.alias??[t.src],t.src=this._appendDefaultSearchParams(t.src),t.data={...s||{},...t.data},t.loadParser=n??t.loadParser,t.format=o??t.format??Gt.extname(t.src).slice(1),t.srcs=t.src,t.name=t.alias,t}}class Jx{constructor(){this._detections=[],this._initialized=!1,this.resolver=new Zx,this.loader=new Tx,this.cache=Kr,this._backgroundLoader=new bx(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(t={}){var n,o;if(this._initialized){console.warn("[Assets]AssetManager already initialized, did you load before calling this Assets.init()?");return}if(this._initialized=!0,t.defaultSearchParams&&this.resolver.setDefaultSearchParams(t.defaultSearchParams),t.basePath&&(this.resolver.basePath=t.basePath),t.bundleIdentifier&&this.resolver.setBundleIdentifier(t.bundleIdentifier),t.manifest){let a=t.manifest;typeof a=="string"&&(a=await this.load(a)),this.resolver.addManifest(a)}const e=((n=t.texturePreference)==null?void 0:n.resolution)??1,i=typeof e=="number"?[e]:e,s=await this._detectFormats({preferredFormats:(o=t.texturePreference)==null?void 0:o.format,skipDetections:t.skipDetections,detections:this._detections});this.resolver.prefer({params:{format:s,resolution:i}}),t.preferences&&this.setPreferences(t.preferences)}add(t,e,i,s,n){this.resolver.add(t,e,i,s,n)}async load(t,e){this._initialized||await this.init();const i=Bn(t),s=Se(t).map(a=>{if(typeof a!="string"){const l=this.resolver.getAlias(a);return l.some(h=>!this.resolver.hasKey(h))&&this.add(a),Array.isArray(l)?l[0]:l}return this.resolver.hasKey(a)||this.add({alias:a,src:a}),a}),n=this.resolver.resolve(s),o=await this._mapLoadToResolve(n,e);return i?o[s[0]]:o}addBundle(t,e){this.resolver.addBundle(t,e)}async loadBundle(t,e){this._initialized||await this.init();let i=!1;typeof t=="string"&&(i=!0,t=[t]);const s=this.resolver.resolveBundle(t),n={},o=Object.keys(s);let a=0,l=0;const h=()=>{e==null||e(++a/l)},c=o.map(u=>{const d=s[u];return l+=Object.keys(d).length,this._mapLoadToResolve(d,h).then(f=>{n[u]=f})});return await Promise.all(c),i?n[t[0]]:n}async backgroundLoad(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolve(t);this._backgroundLoader.add(Object.values(e))}async backgroundLoadBundle(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolveBundle(t);Object.values(e).forEach(i=>{this._backgroundLoader.add(Object.values(i))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(t){if(typeof t=="string")return Kr.get(t);const e={};for(let i=0;i<t.length;i++)e[i]=Kr.get(t[i]);return e}async _mapLoadToResolve(t,e){const i=Object.values(t),s=Object.keys(t);this._backgroundLoader.active=!1;const n=await this.loader.load(i,e);this._backgroundLoader.active=!0;const o={};return i.forEach((a,l)=>{const h=n[a.src],c=[a.src];a.alias&&c.push(...a.alias),o[s[l]]=h,Kr.set(c,h)}),o}async unload(t){this._initialized||await this.init();const e=Se(t).map(s=>typeof s!="string"?s.src:s),i=this.resolver.resolve(e);await this._unloadFromResolved(i)}async unloadBundle(t){this._initialized||await this.init(),t=Se(t);const e=this.resolver.resolveBundle(t),i=Object.keys(e).map(s=>this._unloadFromResolved(e[s]));await Promise.all(i)}async _unloadFromResolved(t){const e=Object.values(t);e.forEach(i=>{Kr.remove(i.src)}),await this.loader.unload(e)}async _detectFormats(t){let e=[];t.preferredFormats&&(e=Array.isArray(t.preferredFormats)?t.preferredFormats:[t.preferredFormats]);for(const i of t.detections)t.skipDetections||await i.test()?e=await i.add(e):t.skipDetections||(e=await i.remove(e));return e=e.filter((i,s)=>e.indexOf(i)===s),e}get detections(){return this._detections}get preferWorkers(){return Dn.config.preferWorkers}set preferWorkers(t){dt("7.2.0","Assets.prefersWorkers is deprecated, use Assets.setPreferences({ preferWorkers: true }) instead."),this.setPreferences({preferWorkers:t})}setPreferences(t){this.loader.parsers.forEach(e=>{e.config&&Object.keys(e.config).filter(i=>i in t).forEach(i=>{e.config[i]=t[i]})})}}const On=new Jx;Y.handleByList(X.LoadParser,On.loader.parsers).handleByList(X.ResolveParser,On.resolver.parsers).handleByList(X.CacheParser,On.cache.parsers).handleByList(X.DetectionParser,On.detections);const Qx={extension:X.CacheParser,test:r=>Array.isArray(r)&&r.every(t=>t instanceof q),getCacheableAssets:(r,t)=>{const e={};return r.forEach(i=>{t.forEach((s,n)=>{e[i+(n===0?"":n+1)]=s})}),e}};Y.add(Qx);async function kd(r){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(r)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const tb={extension:{type:X.DetectionParser,priority:1},test:async()=>kd("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(t=>t!=="avif")};Y.add(tb);const eb={extension:{type:X.DetectionParser,priority:0},test:async()=>kd("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(t=>t!=="webp")};Y.add(eb);const Gd=["png","jpg","jpeg"],rb={extension:{type:X.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Gd],remove:async r=>r.filter(t=>!Gd.includes(t))};Y.add(rb);const ib="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function hl(r){return ib?!1:document.createElement("video").canPlayType(r)!==""}const sb={extension:{type:X.DetectionParser,priority:0},test:async()=>hl("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(t=>t!=="webm")};Y.add(sb);const nb={extension:{type:X.DetectionParser,priority:0},test:async()=>hl("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(t=>t!=="mp4"&&t!=="m4v")};Y.add(nb);const ob={extension:{type:X.DetectionParser,priority:0},test:async()=>hl("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(t=>t!=="ogv")};Y.add(ob);const ab={extension:X.ResolveParser,test:Dn.test,parse:r=>{var t;return{resolution:parseFloat(((t=W.RETINA_PREFIX.exec(r))==null?void 0:t[1])??"1"),format:Gt.extname(r).slice(1),src:r}}};Y.add(ab);var jt=(r=>(r[r.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",r[r.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",r[r.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",r[r.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",r[r.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",r[r.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",r[r.COMPRESSED_RGBA8_ETC2_EAC=37496]="COMPRESSED_RGBA8_ETC2_EAC",r[r.COMPRESSED_SRGB8_ETC2=37493]="COMPRESSED_SRGB8_ETC2",r[r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37497]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",r[r.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37494]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37495]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",r[r.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",r[r.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35987]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",r[r.COMPRESSED_RGBA_BPTC_UNORM_EXT=36492]="COMPRESSED_RGBA_BPTC_UNORM_EXT",r[r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT=36493]="COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT",r[r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT=36494]="COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT",r[r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT=36495]="COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT",r))(jt||{});const Fn={33776:.5,33777:.5,33778:1,33779:1,35916:.5,35917:.5,35918:1,35919:1,37488:.5,37489:.5,37490:1,37491:1,37492:.5,37496:1,37493:.5,37497:1,37494:.5,37495:.5,35840:.5,35842:.5,35841:.25,35843:.25,36196:.5,35986:.5,35987:1,34798:1,37808:1,36492:1,36493:1,36494:1,36495:1};let We,Fi;function $d(){Fi={bptc:We.getExtension("EXT_texture_compression_bptc"),astc:We.getExtension("WEBGL_compressed_texture_astc"),etc:We.getExtension("WEBGL_compressed_texture_etc"),s3tc:We.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:We.getExtension("WEBGL_compressed_texture_s3tc_srgb"),pvrtc:We.getExtension("WEBGL_compressed_texture_pvrtc")||We.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),etc1:We.getExtension("WEBGL_compressed_texture_etc1"),atc:We.getExtension("WEBGL_compressed_texture_atc")}}const lb={extension:{type:X.DetectionParser,priority:2},test:async()=>{const r=W.ADAPTER.createCanvas().getContext("webgl");return r?(We=r,!0):(console.warn("WebGL not available for compressed textures."),!1)},add:async r=>{Fi||$d();const t=[];for(const e in Fi)Fi[e]&&t.push(e);return[...t,...r]},remove:async r=>(Fi||$d(),r.filter(t=>!(t in Fi)))};Y.add(lb);class hb extends hn{constructor(t,e={width:1,height:1,autoLoad:!0}){let i,s;typeof t=="string"?(i=t,s=new Uint8Array):(i=null,s=t),super(s,e),this.origin=i,this.buffer=s?new Ca(s):null,this._load=null,this.loaded=!1,this.origin!==null&&e.autoLoad!==!1&&this.load(),this.origin===null&&this.buffer&&(this._load=Promise.resolve(this),this.loaded=!0,this.onBlobLoaded(this.buffer.rawBinaryData))}onBlobLoaded(t){}load(){return this._load?this._load:(this._load=fetch(this.origin).then(t=>t.blob()).then(t=>t.arrayBuffer()).then(t=>(this.data=new Uint32Array(t),this.buffer=new Ca(t),this.loaded=!0,this.onBlobLoaded(t),this.update(),this)),this._load)}}class Zr extends hb{constructor(t,e){super(t,e),this.format=e.format,this.levels=e.levels||1,this._width=e.width,this._height=e.height,this._extension=Zr._formatToExtension(this.format),(e.levelBuffers||this.buffer)&&(this._levelBuffers=e.levelBuffers||Zr._createLevelBuffers(t instanceof Uint8Array?t:this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height))}upload(t,e,i){const s=t.gl;if(!t.context.extensions[this._extension])throw new Error(`${this._extension} textures are not supported on the current machine`);if(!this._levelBuffers)return!1;s.pixelStorei(s.UNPACK_ALIGNMENT,4);for(let n=0,o=this.levels;n<o;n++){const{levelID:a,levelWidth:l,levelHeight:h,levelBuffer:c}=this._levelBuffers[n];s.compressedTexImage2D(s.TEXTURE_2D,a,this.format,l,h,0,c)}return!0}onBlobLoaded(){this._levelBuffers=Zr._createLevelBuffers(this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height)}static _formatToExtension(t){if(t>=33776&&t<=33779)return"s3tc";if(t>=35916&&t<=35919)return"s3tc_sRGB";if(t>=37488&&t<=37497)return"etc";if(t>=35840&&t<=35843)return"pvrtc";if(t===36196)return"etc1";if(t===35986||t===35987||t===34798)return"atc";if(t>=36492&&t<=36495)return"bptc";if(t===37808)return"astc";throw new Error(`Invalid (compressed) texture format given: ${t}`)}static _createLevelBuffers(t,e,i,s,n,o,a){const l=new Array(i);let h=t.byteOffset,c=o,u=a,d=c+s-1&~(s-1),f=u+n-1&~(n-1),p=d*f*Fn[e];for(let m=0;m<i;m++)l[m]={levelID:m,levelWidth:i>1?c:d,levelHeight:i>1?u:f,levelBuffer:new Uint8Array(t.buffer,h,p)},h+=p,c=c>>1||1,u=u>>1||1,d=c+s-1&~(s-1),f=u+n-1&~(n-1),p=d*f*Fn[e];return l}}const cl=4,Ln=124,cb=32,Hd=20,ub=542327876,Nn={SIZE:1,FLAGS:2,HEIGHT:3,WIDTH:4,MIPMAP_COUNT:7,PIXEL_FORMAT:19},db={SIZE:0,FLAGS:1,FOURCC:2,RGB_BITCOUNT:3,R_BIT_MASK:4,G_BIT_MASK:5,B_BIT_MASK:6,A_BIT_MASK:7},Un={DXGI_FORMAT:0,RESOURCE_DIMENSION:1,MISC_FLAG:2,ARRAY_SIZE:3,MISC_FLAGS2:4},fb=1,pb=2,mb=4,gb=64,yb=512,_b=131072,vb=827611204,xb=861165636,bb=894720068,wb=808540228,Eb=4,Tb={[vb]:jt.COMPRESSED_RGBA_S3TC_DXT1_EXT,[xb]:jt.COMPRESSED_RGBA_S3TC_DXT3_EXT,[bb]:jt.COMPRESSED_RGBA_S3TC_DXT5_EXT},Ab={70:jt.COMPRESSED_RGBA_S3TC_DXT1_EXT,71:jt.COMPRESSED_RGBA_S3TC_DXT1_EXT,73:jt.COMPRESSED_RGBA_S3TC_DXT3_EXT,74:jt.COMPRESSED_RGBA_S3TC_DXT3_EXT,76:jt.COMPRESSED_RGBA_S3TC_DXT5_EXT,77:jt.COMPRESSED_RGBA_S3TC_DXT5_EXT,72:jt.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,75:jt.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,78:jt.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,96:jt.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,95:jt.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,98:jt.COMPRESSED_RGBA_BPTC_UNORM_EXT,99:jt.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT};function Sb(r){const t=new Uint32Array(r);if(t[0]!==ub)throw new Error("Invalid DDS file magic word");const e=new Uint32Array(r,0,Ln/Uint32Array.BYTES_PER_ELEMENT),i=e[Nn.HEIGHT],s=e[Nn.WIDTH],n=e[Nn.MIPMAP_COUNT],o=new Uint32Array(r,Nn.PIXEL_FORMAT*Uint32Array.BYTES_PER_ELEMENT,cb/Uint32Array.BYTES_PER_ELEMENT),a=o[fb];if(a&mb){const l=o[db.FOURCC];if(l!==wb){const x=Tb[l],g=cl+Ln,v=new Uint8Array(r,g);return[new Zr(v,{format:x,width:s,height:i,levels:n})]}const h=cl+Ln,c=new Uint32Array(t.buffer,h,Hd/Uint32Array.BYTES_PER_ELEMENT),u=c[Un.DXGI_FORMAT],d=c[Un.RESOURCE_DIMENSION],f=c[Un.MISC_FLAG],p=c[Un.ARRAY_SIZE],m=Ab[u];if(m===void 0)throw new Error(`DDSParser cannot parse texture data with DXGI format ${u}`);if(f===Eb)throw new Error("DDSParser does not support cubemap textures");if(d===6)throw new Error("DDSParser does not supported 3D texture data");const _=new Array,y=cl+Ln+Hd;if(p===1)_.push(new Uint8Array(r,y));else{const x=Fn[m];let g=0,v=s,w=i;for(let A=0;A<n;A++){const C=Math.max(1,v+3&-4),N=Math.max(1,w+3&-4),S=C*N*x;g+=S,v=v>>>1,w=w>>>1}let I=y;for(let A=0;A<p;A++)_.push(new Uint8Array(r,I,g)),I+=g}return _.map(x=>new Zr(x,{format:m,width:s,height:i,levels:n}))}throw a&gb?new Error("DDSParser does not support uncompressed texture data."):a&yb?new Error("DDSParser does not supported YUV uncompressed texture data."):a&_b?new Error("DDSParser does not support single-channel (lumninance) texture data!"):a&pb?new Error("DDSParser does not support single-channel (alpha) texture data!"):new Error("DDSParser failed to load a texture file due to an unknown reason!")}const Xd=[171,75,84,88,32,49,49,187,13,10,26,10],Ib=67305985,Ce={FILE_IDENTIFIER:0,ENDIANNESS:12,GL_TYPE:16,GL_TYPE_SIZE:20,GL_FORMAT:24,GL_INTERNAL_FORMAT:28,GL_BASE_INTERNAL_FORMAT:32,PIXEL_WIDTH:36,PIXEL_HEIGHT:40,PIXEL_DEPTH:44,NUMBER_OF_ARRAY_ELEMENTS:48,NUMBER_OF_FACES:52,NUMBER_OF_MIPMAP_LEVELS:56,BYTES_OF_KEY_VALUE_DATA:60},ul=64,Vd={[J.UNSIGNED_BYTE]:1,[J.UNSIGNED_SHORT]:2,[J.INT]:4,[J.UNSIGNED_INT]:4,[J.FLOAT]:4,[J.HALF_FLOAT]:8},Cb={[k.RGBA]:4,[k.RGB]:3,[k.RG]:2,[k.RED]:1,[k.LUMINANCE]:1,[k.LUMINANCE_ALPHA]:2,[k.ALPHA]:1},Rb={[J.UNSIGNED_SHORT_4_4_4_4]:2,[J.UNSIGNED_SHORT_5_5_5_1]:2,[J.UNSIGNED_SHORT_5_6_5]:2};function Pb(r,t,e=!1){const i=new DataView(t);if(!Mb(r,i))return null;const s=i.getUint32(Ce.ENDIANNESS,!0)===Ib,n=i.getUint32(Ce.GL_TYPE,s),o=i.getUint32(Ce.GL_FORMAT,s),a=i.getUint32(Ce.GL_INTERNAL_FORMAT,s),l=i.getUint32(Ce.PIXEL_WIDTH,s),h=i.getUint32(Ce.PIXEL_HEIGHT,s)||1,c=i.getUint32(Ce.PIXEL_DEPTH,s)||1,u=i.getUint32(Ce.NUMBER_OF_ARRAY_ELEMENTS,s)||1,d=i.getUint32(Ce.NUMBER_OF_FACES,s),f=i.getUint32(Ce.NUMBER_OF_MIPMAP_LEVELS,s),p=i.getUint32(Ce.BYTES_OF_KEY_VALUE_DATA,s);if(h===0||c!==1)throw new Error("Only 2D textures are supported");if(d!==1)throw new Error("CubeTextures are not supported by KTXLoader yet!");if(u!==1)throw new Error("WebGL does not support array textures");const m=4,_=4,y=l+3&-4,x=h+3&-4,g=new Array(u);let v=l*h;n===0&&(v=y*x);let w;if(n!==0?Vd[n]?w=Vd[n]*Cb[o]:w=Rb[n]:w=Fn[a],w===void 0)throw new Error("Unable to resolve the pixel format stored in the *.ktx file!");const I=e?Db(i,p,s):null;let A=v*w,C=l,N=h,S=y,R=x,E=ul+p;for(let b=0;b<f;b++){const D=i.getUint32(E,s);let F=E+4;for(let G=0;G<u;G++){let $=g[G];$||($=g[G]=new Array(f)),$[b]={levelID:b,levelWidth:f>1||n!==0?C:S,levelHeight:f>1||n!==0?N:R,levelBuffer:new Uint8Array(t,F,A)},F+=A}E+=D+4,E=E%4!==0?E+4-E%4:E,C=C>>1||1,N=N>>1||1,S=C+m-1&~(m-1),R=N+_-1&~(_-1),A=S*R*w}return n!==0?{uncompressed:g.map(b=>{let D=b[0].levelBuffer,F=!1;return n===J.FLOAT?D=new Float32Array(b[0].levelBuffer.buffer,b[0].levelBuffer.byteOffset,b[0].levelBuffer.byteLength/4):n===J.UNSIGNED_INT?(F=!0,D=new Uint32Array(b[0].levelBuffer.buffer,b[0].levelBuffer.byteOffset,b[0].levelBuffer.byteLength/4)):n===J.INT&&(F=!0,D=new Int32Array(b[0].levelBuffer.buffer,b[0].levelBuffer.byteOffset,b[0].levelBuffer.byteLength/4)),{resource:new hn(D,{width:b[0].levelWidth,height:b[0].levelHeight}),type:n,format:F?Bb(o):o}}),kvData:I}:{compressed:g.map(b=>new Zr(null,{format:a,width:l,height:h,levels:f,levelBuffers:b})),kvData:I}}function Mb(r,t){for(let e=0;e<Xd.length;e++)if(t.getUint8(e)!==Xd[e])return console.error(`${r} is not a valid *.ktx file!`),!1;return!0}function Bb(r){switch(r){case k.RGBA:return k.RGBA_INTEGER;case k.RGB:return k.RGB_INTEGER;case k.RG:return k.RG_INTEGER;case k.RED:return k.RED_INTEGER;default:return r}}function Db(r,t,e){const i=new Map;let s=0;for(;s<t;){const n=r.getUint32(ul+s,e),o=ul+s+4,a=3-(n+3)%4;if(n===0||n>t-s){console.error("KTXLoader: keyAndValueByteSize out of bounds");break}let l=0;for(;l<n&&r.getUint8(o+l)!==0;l++);if(l===-1){console.error("KTXLoader: Failed to find null byte terminating kvData key");break}const h=new TextDecoder().decode(new Uint8Array(r.buffer,o,l)),c=new DataView(r.buffer,o+l+1,n-l-1);i.set(h,c),s+=4+n+a}return i}const Ob={extension:{type:X.LoadParser,priority:Ie.High},name:"loadDDS",test(r){return Er(r,".dds")},async load(r,t,e){const i=await(await W.ADAPTER.fetch(r)).arrayBuffer(),s=Sb(i).map(n=>{const o=new nt(n,{mipmap:Le.OFF,alphaMode:ie.NO_PREMULTIPLIED_ALPHA,resolution:hr(r),...t.data});return _s(o,e,r)});return s.length===1?s[0]:s},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};Y.add(Ob);const Fb={extension:{type:X.LoadParser,priority:Ie.High},name:"loadKTX",test(r){return Er(r,".ktx")},async load(r,t,e){const i=await(await W.ADAPTER.fetch(r)).arrayBuffer(),{compressed:s,uncompressed:n,kvData:o}=Pb(r,i),a=s??n,l={mipmap:Le.OFF,alphaMode:ie.NO_PREMULTIPLIED_ALPHA,resolution:hr(r),...t.data},h=a.map(c=>{a===n&&Object.assign(l,{type:c.type,format:c.format});const u=c.resource??c,d=new nt(u,l);return d.ktxKeyValueData=o,_s(d,e,r)});return h.length===1?h[0]:h},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};Y.add(Fb);const Lb=["s3tc","s3tc_sRGB","etc","etc1","pvrtc","atc","astc","bptc"],Nb={extension:X.ResolveParser,test:r=>{const t=Gt.extname(r).slice(1);return["basis","ktx","dds"].includes(t)},parse:r=>{var i,s;const t=r.split("."),e=t.pop();if(["ktx","dds"].includes(e)){const n=t.pop();if(Lb.includes(n))return{resolution:parseFloat(((i=W.RETINA_PREFIX.exec(r))==null?void 0:i[1])??"1"),format:n,src:r}}return{resolution:parseFloat(((s=W.RETINA_PREFIX.exec(r))==null?void 0:s[1])??"1"),format:e,src:r}}};Y.add(Nb);const kn=new at,Ub=4,zd=class As{constructor(t){this.renderer=t,this._rendererPremultipliedAlpha=!1}contextChange(){var e;const t=(e=this.renderer)==null?void 0:e.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(t&&t.alpha&&t.premultipliedAlpha)}async image(t,e,i,s){const n=new Image;return n.src=await this.base64(t,e,i,s),n}async base64(t,e,i,s){const n=this.canvas(t,s);if(n.toBlob!==void 0)return new Promise((o,a)=>{n.toBlob(l=>{if(!l){a(new Error("ICanvas.toBlob failed!"));return}const h=new FileReader;h.onload=()=>o(h.result),h.onerror=a,h.readAsDataURL(l)},e,i)});if(n.toDataURL!==void 0)return n.toDataURL(e,i);if(n.convertToBlob!==void 0){const o=await n.convertToBlob({type:e,quality:i});return new Promise((a,l)=>{const h=new FileReader;h.onload=()=>a(h.result),h.onerror=l,h.readAsDataURL(o)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(t,e){const{pixels:i,width:s,height:n,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);o&&As._flipY(i,s,n),a&&As._unpremultiplyAlpha(i);const l=new _v(s,n,1),h=new ImageData(new Uint8ClampedArray(i.buffer),s,n);return l.context.putImageData(h,0,0),l.canvas}pixels(t,e){const{pixels:i,width:s,height:n,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);return o&&As._flipY(i,s,n),a&&As._unpremultiplyAlpha(i),i}_rawPixels(t,e){const i=this.renderer;if(!i)throw new Error("The Extract has already been destroyed");let s,n=!1,o=!1,a,l=!1;t&&(t instanceof Wr?a=t:(a=i.generateTexture(t,{region:e,resolution:i.resolution,multisample:i.multisample}),l=!0,e&&(kn.width=e.width,kn.height=e.height,e=kn)));const h=i.gl;if(a){if(s=a.baseTexture.resolution,e=e??a.frame,n=!1,o=a.baseTexture.alphaMode>0&&a.baseTexture.format===k.RGBA,!l){i.renderTexture.bind(a);const f=a.framebuffer.glFramebuffers[i.CONTEXT_UID];f.blitFramebuffer&&i.framebuffer.bind(f.blitFramebuffer)}}else s=i.resolution,e||(e=kn,e.width=i.width/s,e.height=i.height/s),n=!0,o=this._rendererPremultipliedAlpha,i.renderTexture.bind();const c=Math.max(Math.round(e.width*s),1),u=Math.max(Math.round(e.height*s),1),d=new Uint8Array(Ub*c*u);return h.readPixels(Math.round(e.x*s),Math.round(e.y*s),c,u,h.RGBA,h.UNSIGNED_BYTE,d),l&&(a==null||a.destroy(!0)),{pixels:d,width:c,height:u,flipY:n,premultipliedAlpha:o}}destroy(){this.renderer=null}static _flipY(t,e,i){const s=e<<2,n=i>>1,o=new Uint8Array(s);for(let a=0;a<n;a++){const l=a*s,h=(i-a-1)*s;o.set(t.subarray(l,l+s)),t.copyWithin(l,h,h+s),t.set(o,h)}}static _unpremultiplyAlpha(t){t instanceof Uint8ClampedArray&&(t=new Uint8Array(t.buffer));const e=t.length;for(let i=0;i<e;i+=4){const s=t[i+3];if(s!==0){const n=255.001/s;t[i]=t[i]*n+.5,t[i+1]=t[i+1]*n+.5,t[i+2]=t[i+2]*n+.5}}}};zd.extension={name:"extract",type:X.RendererSystem};let kb=zd;Y.add(kb);const Gn={build(r){const t=r.points;let e,i,s,n,o,a;if(r.type===Wt.CIRC){const p=r.shape;e=p.x,i=p.y,o=a=p.radius,s=n=0}else if(r.type===Wt.ELIP){const p=r.shape;e=p.x,i=p.y,o=p.width,a=p.height,s=n=0}else{const p=r.shape,m=p.width/2,_=p.height/2;e=p.x+m,i=p.y+_,o=a=Math.max(0,Math.min(p.radius,Math.min(m,_))),s=m-o,n=_-a}if(!(o>=0&&a>=0&&s>=0&&n>=0)){t.length=0;return}const l=Math.ceil(2.3*Math.sqrt(o+a)),h=l*8+(s?4:0)+(n?4:0);if(t.length=h,h===0)return;if(l===0){t.length=8,t[0]=t[6]=e+s,t[1]=t[3]=i+n,t[2]=t[4]=e-s,t[5]=t[7]=i-n;return}let c=0,u=l*4+(s?2:0)+2,d=u,f=h;{const p=s+o,m=n,_=e+p,y=e-p,x=i+m;if(t[c++]=_,t[c++]=x,t[--u]=x,t[--u]=y,n){const g=i-m;t[d++]=y,t[d++]=g,t[--f]=g,t[--f]=_}}for(let p=1;p<l;p++){const m=Math.PI/2*(p/l),_=s+Math.cos(m)*o,y=n+Math.sin(m)*a,x=e+_,g=e-_,v=i+y,w=i-y;t[c++]=x,t[c++]=v,t[--u]=v,t[--u]=g,t[d++]=g,t[d++]=w,t[--f]=w,t[--f]=x}{const p=s,m=n+a,_=e+p,y=e-p,x=i+m,g=i-m;t[c++]=_,t[c++]=x,t[--f]=g,t[--f]=_,s&&(t[c++]=y,t[c++]=x,t[--f]=g,t[--f]=y)}},triangulate(r,t){const e=r.points,i=t.points,s=t.indices;if(e.length===0)return;let n=i.length/2;const o=n;let a,l;if(r.type!==Wt.RREC){const c=r.shape;a=c.x,l=c.y}else{const c=r.shape;a=c.x+c.width/2,l=c.y+c.height/2}const h=r.matrix;i.push(r.matrix?h.a*a+h.c*l+h.tx:a,r.matrix?h.b*a+h.d*l+h.ty:l),n++,i.push(e[0],e[1]);for(let c=2;c<e.length;c+=2)i.push(e[c],e[c+1]),s.push(n++,o,n);s.push(o+1,o,n)}};function Wd(r,t=!1){const e=r.length;if(e<6)return;let i=0;for(let s=0,n=r[e-2],o=r[e-1];s<e;s+=2){const a=r[s],l=r[s+1];i+=(a-n)*(l+o),n=a,o=l}if(!t&&i>0||t&&i<=0){const s=e/2;for(let n=s+s%2;n<e;n+=2){const o=e-n-2,a=e-n-1,l=n,h=n+1;[r[o],r[l]]=[r[l],r[o]],[r[a],r[h]]=[r[h],r[a]]}}}const jd={build(r){r.points=r.shape.points.slice()},triangulate(r,t){let e=r.points;const i=r.holes,s=t.points,n=t.indices;if(e.length>=6){Wd(e,!1);const o=[];for(let h=0;h<i.length;h++){const c=i[h];Wd(c.points,!0),o.push(e.length/2),e=e.concat(c.points)}const a=Ty(e,o,2);if(!a)return;const l=s.length/2;for(let h=0;h<a.length;h+=3)n.push(a[h]+l),n.push(a[h+1]+l),n.push(a[h+2]+l);for(let h=0;h<e.length;h++)s.push(e[h])}}},Gb={build(r){const t=r.shape,e=t.x,i=t.y,s=t.width,n=t.height,o=r.points;o.length=0,s>=0&&n>=0&&o.push(e,i,e+s,i,e+s,i+n,e,i+n)},triangulate(r,t){const e=r.points,i=t.points;if(e.length===0)return;const s=i.length/2;i.push(e[0],e[1],e[2],e[3],e[6],e[7],e[4],e[5]),t.indices.push(s,s+1,s+2,s+1,s+2,s+3)}},$b={build(r){Gn.build(r)},triangulate(r,t){Gn.triangulate(r,t)}};var me=(r=>(r.MITER="miter",r.BEVEL="bevel",r.ROUND="round",r))(me||{}),Tr=(r=>(r.BUTT="butt",r.ROUND="round",r.SQUARE="square",r))(Tr||{});const Li={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount(r,t=20){if(!this.adaptive||!r||isNaN(r))return t;let e=Math.ceil(r/this.maxLength);return e<this.minSegments?e=this.minSegments:e>this.maxSegments&&(e=this.maxSegments),e}};class Yd{static curveTo(t,e,i,s,n,o){const a=o[o.length-2],l=o[o.length-1]-e,h=a-t,c=s-e,u=i-t,d=Math.abs(l*u-h*c);if(d<1e-8||n===0)return(o[o.length-2]!==t||o[o.length-1]!==e)&&o.push(t,e),null;const f=l*l+h*h,p=c*c+u*u,m=l*c+h*u,_=n*Math.sqrt(f)/d,y=n*Math.sqrt(p)/d,x=_*m/f,g=y*m/p,v=_*u+y*h,w=_*c+y*l,I=h*(y+x),A=l*(y+x),C=u*(_+g),N=c*(_+g),S=Math.atan2(A-w,I-v),R=Math.atan2(N-w,C-v);return{cx:v+t,cy:w+e,radius:n,startAngle:S,endAngle:R,anticlockwise:h*c>u*l}}static arc(t,e,i,s,n,o,a,l,h){const c=a-o,u=Li._segmentsCount(Math.abs(c)*n,Math.ceil(Math.abs(c)/un)*40),d=c/(u*2),f=d*2,p=Math.cos(d),m=Math.sin(d),_=u-1,y=_%1/_;for(let x=0;x<=_;++x){const g=x+y*x,v=d+o+f*g,w=Math.cos(v),I=-Math.sin(v);h.push((p*w+m*I)*n+i,(p*-I+m*w)*n+s)}}}class Hb{constructor(){this.reset()}begin(t,e,i){this.reset(),this.style=t,this.start=e,this.attribStart=i}end(t,e){this.attribSize=e-this.attribStart,this.size=t-this.start}reset(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0}}class dl{static curveLength(t,e,i,s,n,o,a,l){let h=0,c=0,u=0,d=0,f=0,p=0,m=0,_=0,y=0,x=0,g=0,v=t,w=e;for(let I=1;I<=10;++I)c=I/10,u=c*c,d=u*c,f=1-c,p=f*f,m=p*f,_=m*t+3*p*c*i+3*f*u*n+d*a,y=m*e+3*p*c*s+3*f*u*o+d*l,x=v-_,g=w-y,v=_,w=y,h+=Math.sqrt(x*x+g*g);return h}static curveTo(t,e,i,s,n,o,a){const l=a[a.length-2],h=a[a.length-1];a.length-=2;const c=Li._segmentsCount(dl.curveLength(l,h,t,e,i,s,n,o));let u=0,d=0,f=0,p=0,m=0;a.push(l,h);for(let _=1,y=0;_<=c;++_)y=_/c,u=1-y,d=u*u,f=d*u,p=y*y,m=p*y,a.push(f*l+3*d*y*t+3*u*p*i+m*n,f*h+3*d*y*e+3*u*p*s+m*o)}}function qd(r,t,e,i,s,n,o,a){const l=r-e*s,h=t-i*s,c=r+e*n,u=t+i*n;let d,f;o?(d=i,f=-e):(d=-i,f=e);const p=l+d,m=h+f,_=c+d,y=u+f;return a.push(p,m,_,y),2}function Jr(r,t,e,i,s,n,o,a){const l=e-r,h=i-t;let c=Math.atan2(l,h),u=Math.atan2(s-r,n-t);a&&c<u?c+=Math.PI*2:!a&&c>u&&(u+=Math.PI*2);let d=c;const f=u-c,p=Math.abs(f),m=Math.sqrt(l*l+h*h),_=(15*p*Math.sqrt(m)/Math.PI>>0)+1,y=f/_;if(d+=y,a){o.push(r,t,e,i);for(let x=1,g=d;x<_;x++,g+=y)o.push(r,t,r+Math.sin(g)*m,t+Math.cos(g)*m);o.push(r,t,s,n)}else{o.push(e,i,r,t);for(let x=1,g=d;x<_;x++,g+=y)o.push(r+Math.sin(g)*m,t+Math.cos(g)*m,r,t);o.push(s,n,r,t)}return _*2}function Xb(r,t){const e=r.shape;let i=r.points||e.points.slice();const s=t.closePointEps;if(i.length===0)return;const n=r.lineStyle,o=new gt(i[0],i[1]),a=new gt(i[i.length-2],i[i.length-1]),l=e.type!==Wt.POLY||e.closeStroke,h=Math.abs(o.x-a.x)<s&&Math.abs(o.y-a.y)<s;if(l){i=i.slice(),h&&(i.pop(),i.pop(),a.set(i[i.length-2],i[i.length-1]));const $=(o.x+a.x)*.5,B=(a.y+o.y)*.5;i.unshift($,B),i.push($,B)}const c=t.points,u=i.length/2;let d=i.length;const f=c.length/2,p=n.width/2,m=p*p,_=n.miterLimit*n.miterLimit;let y=i[0],x=i[1],g=i[2],v=i[3],w=0,I=0,A=-(x-v),C=y-g,N=0,S=0,R=Math.sqrt(A*A+C*C);A/=R,C/=R,A*=p,C*=p;const E=n.alignment,b=(1-E)*2,D=E*2;l||(n.cap===Tr.ROUND?d+=Jr(y-A*(b-D)*.5,x-C*(b-D)*.5,y-A*b,x-C*b,y+A*D,x+C*D,c,!0)+2:n.cap===Tr.SQUARE&&(d+=qd(y,x,A,C,b,D,!0,c))),c.push(y-A*b,x-C*b,y+A*D,x+C*D);for(let $=1;$<u-1;++$){y=i[($-1)*2],x=i[($-1)*2+1],g=i[$*2],v=i[$*2+1],w=i[($+1)*2],I=i[($+1)*2+1],A=-(x-v),C=y-g,R=Math.sqrt(A*A+C*C),A/=R,C/=R,A*=p,C*=p,N=-(v-I),S=g-w,R=Math.sqrt(N*N+S*S),N/=R,S/=R,N*=p,S*=p;const B=g-y,K=x-v,P=g-w,U=I-v,j=B*P+K*U,rt=K*P-U*B,Q=rt<0;if(Math.abs(rt)<.001*Math.abs(j)){c.push(g-A*b,v-C*b,g+A*D,v+C*D),j>=0&&(n.join===me.ROUND?d+=Jr(g,v,g-A*b,v-C*b,g-N*b,v-S*b,c,!1)+4:d+=2,c.push(g-N*D,v-S*D,g+N*b,v+S*b));continue}const H=(-A+y)*(-C+v)-(-A+g)*(-C+x),V=(-N+w)*(-S+v)-(-N+g)*(-S+I),lt=(B*V-P*H)/rt,L=(U*H-K*V)/rt,O=(lt-g)*(lt-g)+(L-v)*(L-v),_t=g+(lt-g)*b,ht=v+(L-v)*b,vt=g-(lt-g)*D,xt=v-(L-v)*D,Ye=Math.min(B*B+K*K,P*P+U*U),qe=Q?b:D,ws=Ye+qe*qe*m,UE=O<=ws;let Zn=n.join;if(Zn===me.MITER&&O/m>_&&(Zn=me.BEVEL),UE)switch(Zn){case me.MITER:{c.push(_t,ht,vt,xt);break}case me.BEVEL:{Q?c.push(_t,ht,g+A*D,v+C*D,_t,ht,g+N*D,v+S*D):c.push(g-A*b,v-C*b,vt,xt,g-N*b,v-S*b,vt,xt),d+=2;break}case me.ROUND:{Q?(c.push(_t,ht,g+A*D,v+C*D),d+=Jr(g,v,g+A*D,v+C*D,g+N*D,v+S*D,c,!0)+4,c.push(_t,ht,g+N*D,v+S*D)):(c.push(g-A*b,v-C*b,vt,xt),d+=Jr(g,v,g-A*b,v-C*b,g-N*b,v-S*b,c,!1)+4,c.push(g-N*b,v-S*b,vt,xt));break}}else{switch(c.push(g-A*b,v-C*b,g+A*D,v+C*D),Zn){case me.MITER:{Q?c.push(vt,xt,vt,xt):c.push(_t,ht,_t,ht),d+=2;break}case me.ROUND:{Q?d+=Jr(g,v,g+A*D,v+C*D,g+N*D,v+S*D,c,!0)+2:d+=Jr(g,v,g-A*b,v-C*b,g-N*b,v-S*b,c,!1)+2;break}}c.push(g-N*b,v-S*b,g+N*D,v+S*D),d+=2}}y=i[(u-2)*2],x=i[(u-2)*2+1],g=i[(u-1)*2],v=i[(u-1)*2+1],A=-(x-v),C=y-g,R=Math.sqrt(A*A+C*C),A/=R,C/=R,A*=p,C*=p,c.push(g-A*b,v-C*b,g+A*D,v+C*D),l||(n.cap===Tr.ROUND?d+=Jr(g-A*(b-D)*.5,v-C*(b-D)*.5,g-A*b,v-C*b,g+A*D,v+C*D,c,!1)+2:n.cap===Tr.SQUARE&&(d+=qd(g,v,A,C,b,D,!1,c)));const F=t.indices,G=Li.epsilon*Li.epsilon;for(let $=f;$<d+f-2;++$)y=c[$*2],x=c[$*2+1],g=c[($+1)*2],v=c[($+1)*2+1],w=c[($+2)*2],I=c[($+2)*2+1],!(Math.abs(y*(v-I)+g*(I-x)+w*(x-v))<G)&&F.push($,$+1,$+2)}function Vb(r,t){let e=0;const i=r.shape,s=r.points||i.points,n=i.type!==Wt.POLY||i.closeStroke;if(s.length===0)return;const o=t.points,a=t.indices,l=s.length/2,h=o.length/2;let c=h;for(o.push(s[0],s[1]),e=1;e<l;e++)o.push(s[e*2],s[e*2+1]),a.push(c,c+1),c++;n&&a.push(c,h)}function Kd(r,t){r.lineStyle.native?Vb(r,t):Xb(r,t)}class fl{static curveLength(t,e,i,s,n,o){const a=t-2*i+n,l=e-2*s+o,h=2*i-2*t,c=2*s-2*e,u=4*(a*a+l*l),d=4*(a*h+l*c),f=h*h+c*c,p=2*Math.sqrt(u+d+f),m=Math.sqrt(u),_=2*u*m,y=2*Math.sqrt(f),x=d/m;return(_*p+m*d*(p-y)+(4*f*u-d*d)*Math.log((2*m+x+p)/(x+y)))/(4*_)}static curveTo(t,e,i,s,n){const o=n[n.length-2],a=n[n.length-1],l=Li._segmentsCount(fl.curveLength(o,a,t,e,i,s));let h=0,c=0;for(let u=1;u<=l;++u){const d=u/l;h=o+(t-o)*d,c=a+(e-a)*d,n.push(h+(t+(i-t)*d-h)*d,c+(e+(s-e)*d-c)*d)}}}const pl={[Wt.POLY]:jd,[Wt.CIRC]:Gn,[Wt.ELIP]:Gn,[Wt.RECT]:Gb,[Wt.RREC]:$b},Zd=[],$n=[];class Hn{constructor(t,e=null,i=null,s=null){this.points=[],this.holes=[],this.shape=t,this.lineStyle=i,this.fillStyle=e,this.matrix=s,this.type=t.type}clone(){return new Hn(this.shape,this.fillStyle,this.lineStyle,this.matrix)}destroy(){this.shape=null,this.holes.length=0,this.holes=null,this.points.length=0,this.points=null,this.lineStyle=null,this.fillStyle=null}}const Ni=new gt,Jd=class zf extends Pu{constructor(){super(),this.closePointEps=1e-4,this.boundsPadding=0,this.uvsFloat32=null,this.indicesUint16=null,this.batchable=!1,this.points=[],this.colors=[],this.uvs=[],this.indices=[],this.textureIds=[],this.graphicsData=[],this.drawCalls=[],this.batchDirty=-1,this.batches=[],this.dirty=0,this.cacheDirty=-1,this.clearDirty=0,this.shapeIndex=0,this._bounds=new Rn,this.boundsDirty=-1}get bounds(){return this.updateBatches(),this.boundsDirty!==this.dirty&&(this.boundsDirty=this.dirty,this.calculateBounds()),this._bounds}invalidate(){this.boundsDirty=-1,this.dirty++,this.batchDirty++,this.shapeIndex=0,this.points.length=0,this.colors.length=0,this.uvs.length=0,this.indices.length=0,this.textureIds.length=0;for(let t=0;t<this.drawCalls.length;t++)this.drawCalls[t].texArray.clear(),$n.push(this.drawCalls[t]);this.drawCalls.length=0;for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e.reset(),Zd.push(e)}this.batches.length=0}clear(){return this.graphicsData.length>0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this}drawShape(t,e=null,i=null,s=null){const n=new Hn(t,e,i,s);return this.graphicsData.push(n),this.dirty++,this}drawHole(t,e=null){if(!this.graphicsData.length)return null;const i=new Hn(t,null,null,e),s=this.graphicsData[this.graphicsData.length-1];return i.lineStyle=s.lineStyle,s.holes.push(i),this.dirty++,this}destroy(){super.destroy();for(let t=0;t<this.graphicsData.length;++t)this.graphicsData[t].destroy();this.points.length=0,this.points=null,this.colors.length=0,this.colors=null,this.uvs.length=0,this.uvs=null,this.indices.length=0,this.indices=null,this.indexBuffer.destroy(),this.indexBuffer=null,this.graphicsData.length=0,this.graphicsData=null,this.drawCalls.length=0,this.drawCalls=null,this.batches.length=0,this.batches=null,this._bounds=null}containsPoint(t){const e=this.graphicsData;for(let i=0;i<e.length;++i){const s=e[i];if(s.fillStyle.visible&&s.shape&&(s.matrix?s.matrix.applyInverse(t,Ni):Ni.copyFrom(t),s.shape.contains(Ni.x,Ni.y))){let n=!1;if(s.holes){for(let o=0;o<s.holes.length;o++)if(s.holes[o].shape.contains(Ni.x,Ni.y)){n=!0;break}}if(!n)return!0}}return!1}updateBatches(){if(!this.graphicsData.length){this.batchable=!0;return}if(!this.validateBatching())return;this.cacheDirty=this.dirty;const t=this.uvs,e=this.graphicsData;let i=null,s=null;this.batches.length>0&&(i=this.batches[this.batches.length-1],s=i.style);for(let l=this.shapeIndex;l<e.length;l++){this.shapeIndex++;const h=e[l],c=h.fillStyle,u=h.lineStyle;pl[h.type].build(h),h.matrix&&this.transformPoints(h.points,h.matrix),(c.visible||u.visible)&&this.processHoles(h.holes);for(let d=0;d<2;d++){const f=d===0?c:u;if(!f.visible)continue;const p=f.texture.baseTexture,m=this.indices.length,_=this.points.length/2;p.wrapMode=gr.REPEAT,d===0?this.processFill(h):this.processLine(h);const y=this.points.length/2-_;y!==0&&(i&&!this._compareStyles(s,f)&&(i.end(m,_),i=null),i||(i=Zd.pop()||new Hb,i.begin(f,m,_),this.batches.push(i),s=f),this.addUvs(this.points,t,f.texture,_,y,f.matrix))}}const n=this.indices.length,o=this.points.length/2;if(i&&i.end(n,o),this.batches.length===0){this.batchable=!0;return}const a=o>65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&a===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=a?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}_compareStyles(t,e){return!(!t||!e||t.texture.baseTexture!==e.texture.baseTexture||t.color+t.alpha!==e.color+e.alpha||!!t.native!=!!e.native)}validateBatching(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(let t=0,e=this.graphicsData.length;t<e;t++){const i=this.graphicsData[t],s=i.fillStyle,n=i.lineStyle;if(s&&!s.texture.baseTexture.valid||n&&!n.texture.baseTexture.valid)return!1}return!0}packBatches(){this.batchDirty++,this.uvsFloat32=new Float32Array(this.uvs);const t=this.batches;for(let e=0,i=t.length;e<i;e++){const s=t[e];for(let n=0;n<s.size;n++){const o=s.start+n;this.indicesUint16[o]=this.indicesUint16[o]-s.attribStart}}}isBatchable(){if(this.points.length>65535*2)return!1;const t=this.batches;for(let e=0;e<t.length;e++)if(t[e].style.native)return!1;return this.points.length<zf.BATCHABLE_SIZE*2}buildDrawCalls(){let t=++nt._globalBatch;for(let u=0;u<this.drawCalls.length;u++)this.drawCalls[u].texArray.clear(),$n.push(this.drawCalls[u]);this.drawCalls.length=0;const e=this.colors,i=this.textureIds;let s=$n.pop();s||(s=new Na,s.texArray=new Xa),s.texArray.count=0,s.start=0,s.size=0,s.type=Fe.TRIANGLES;let n=0,o=null,a=0,l=!1,h=Fe.TRIANGLES,c=0;this.drawCalls.push(s);for(let u=0;u<this.batches.length;u++){const d=this.batches[u],f=8,p=d.style,m=p.texture.baseTexture;l!==!!p.native&&(l=!!p.native,h=l?Fe.LINES:Fe.TRIANGLES,o=null,n=f,t++),o!==m&&(o=m,m._batchEnabled!==t&&(n===f&&(t++,n=0,s.size>0&&(s=$n.pop(),s||(s=new Na,s.texArray=new Xa),this.drawCalls.push(s)),s.start=c,s.size=0,s.texArray.count=0,s.type=h),m.touched=1,m._batchEnabled=t,m._batchLocation=n,m.wrapMode=gr.REPEAT,s.texArray.elements[s.texArray.count++]=m,n++)),s.size+=d.size,c+=d.size,a=m._batchLocation,this.addColors(e,p.color,p.alpha,d.attribSize,d.attribStart),this.addTextureIds(i,a,d.attribSize,d.attribStart)}nt._globalBatch=t,this.packAttributes()}packAttributes(){const t=this.points,e=this.uvs,i=this.colors,s=this.textureIds,n=new ArrayBuffer(t.length*3*4),o=new Float32Array(n),a=new Uint32Array(n);let l=0;for(let h=0;h<t.length/2;h++)o[l++]=t[h*2],o[l++]=t[h*2+1],o[l++]=e[h*2],o[l++]=e[h*2+1],a[l++]=i[h],o[l++]=s[h];this._buffer.update(n),this._indexBuffer.update(this.indicesUint16)}processFill(t){t.holes.length?jd.triangulate(t,this):pl[t.type].triangulate(t,this)}processLine(t){Kd(t,this);for(let e=0;e<t.holes.length;e++)Kd(t.holes[e],this)}processHoles(t){for(let e=0;e<t.length;e++){const i=t[e];pl[i.type].build(i),i.matrix&&this.transformPoints(i.points,i.matrix)}}calculateBounds(){const t=this._bounds;t.clear(),t.addVertexData(this.points,0,this.points.length),t.pad(this.boundsPadding,this.boundsPadding)}transformPoints(t,e){for(let i=0;i<t.length/2;i++){const s=t[i*2],n=t[i*2+1];t[i*2]=e.a*s+e.c*n+e.tx,t[i*2+1]=e.b*s+e.d*n+e.ty}}addColors(t,e,i,s,n=0){const o=bt.shared.setValue(e).toLittleEndianNumber(),a=bt.shared.setValue(o).toPremultiplied(i);t.length=Math.max(t.length,n+s);for(let l=0;l<s;l++)t[n+l]=a}addTextureIds(t,e,i,s=0){t.length=Math.max(t.length,s+i);for(let n=0;n<i;n++)t[s+n]=e}addUvs(t,e,i,s,n,o=null){let a=0;const l=e.length,h=i.frame;for(;a<n;){let u=t[(s+a)*2],d=t[(s+a)*2+1];if(o){const f=o.a*u+o.c*d+o.tx;d=o.b*u+o.d*d+o.ty,u=f}a++,e.push(u/h.width,d/h.height)}const c=i.baseTexture;(h.width<c.width||h.height<c.height)&&this.adjustUvs(e,i,l,n)}adjustUvs(t,e,i,s){const n=e.baseTexture,o=1e-6,a=i+s*2,l=e.frame,h=l.width/n.width,c=l.height/n.height;let u=l.x/l.width,d=l.y/l.height,f=Math.floor(t[i]+o),p=Math.floor(t[i+1]+o);for(let m=i+2;m<a;m+=2)f=Math.min(f,Math.floor(t[m]+o)),p=Math.min(p,Math.floor(t[m+1]+o));u-=f,d-=p;for(let m=i;m<a;m+=2)t[m]=(t[m]+u)*h,t[m+1]=(t[m+1]+d)*c}};Jd.BATCHABLE_SIZE=100;let zb=Jd;class Xn{constructor(){this.color=16777215,this.alpha=1,this.texture=q.WHITE,this.matrix=null,this.visible=!1,this.reset()}clone(){const t=new Xn;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t}reset(){this.color=16777215,this.alpha=1,this.texture=q.WHITE,this.matrix=null,this.visible=!1}destroy(){this.texture=null,this.matrix=null}}class ml extends Xn{constructor(){super(...arguments),this.width=0,this.alignment=.5,this.native=!1,this.cap=Tr.BUTT,this.join=me.MITER,this.miterLimit=10}clone(){const t=new ml;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t.width=this.width,t.alignment=this.alignment,t.native=this.native,t.cap=this.cap,t.join=this.join,t.miterLimit=this.miterLimit,t}reset(){super.reset(),this.color=0,this.alignment=.5,this.width=0,this.native=!1,this.cap=Tr.BUTT,this.join=me.MITER,this.miterLimit=10}}const gl={},yl=class ro extends Te{constructor(t=null){super(),this.shader=null,this.pluginName="batch",this.currentPath=null,this.batches=[],this.batchTint=-1,this.batchDirty=-1,this.vertexData=null,this._fillStyle=new Xn,this._lineStyle=new ml,this._matrix=null,this._holeMode=!1,this.state=Ve.for2d(),this._geometry=t||new zb,this._geometry.refCount++,this._transformID=-1,this._tintColor=new bt(16777215),this.blendMode=tt.NORMAL}get geometry(){return this._geometry}clone(){return this.finishPoly(),new ro(this._geometry)}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t)}get fill(){return this._fillStyle}get line(){return this._lineStyle}lineStyle(t=null,e=0,i,s=.5,n=!1){return typeof t=="number"&&(t={width:t,color:e,alpha:i,alignment:s,native:n}),this.lineTextureStyle(t)}lineTextureStyle(t){const e={width:0,texture:q.WHITE,color:t!=null&&t.texture?16777215:0,matrix:null,alignment:.5,native:!1,cap:Tr.BUTT,join:me.MITER,miterLimit:10};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.width>0&&t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._lineStyle,{visible:i},t)):this._lineStyle.reset(),this}startPoly(){if(this.currentPath){const t=this.currentPath.points,e=this.currentPath.points.length;e>2&&(this.drawShape(this.currentPath),this.currentPath=new Gr,this.currentPath.closeStroke=!1,this.currentPath.points.push(t[e-2],t[e-1]))}else this.currentPath=new Gr,this.currentPath.closeStroke=!1}finishPoly(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)}moveTo(t,e){return this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this}lineTo(t,e){this.currentPath||this.moveTo(0,0);const i=this.currentPath.points,s=i[i.length-2],n=i[i.length-1];return(s!==t||n!==e)&&i.push(t,e),this}_initCurve(t=0,e=0){this.currentPath?this.currentPath.points.length===0&&(this.currentPath.points=[t,e]):this.moveTo(t,e)}quadraticCurveTo(t,e,i,s){this._initCurve();const n=this.currentPath.points;return n.length===0&&this.moveTo(0,0),fl.curveTo(t,e,i,s,n),this}bezierCurveTo(t,e,i,s,n,o){return this._initCurve(),dl.curveTo(t,e,i,s,n,o,this.currentPath.points),this}arcTo(t,e,i,s,n){this._initCurve(t,e);const o=this.currentPath.points,a=Yd.curveTo(t,e,i,s,n,o);if(a){const{cx:l,cy:h,radius:c,startAngle:u,endAngle:d,anticlockwise:f}=a;this.arc(l,h,c,u,d,f)}return this}arc(t,e,i,s,n,o=!1){if(s===n)return this;if(!o&&n<=s?n+=un:o&&s<=n&&(s+=un),n-s===0)return this;const a=t+Math.cos(s)*i,l=e+Math.sin(s)*i,h=this._geometry.closePointEps;let c=this.currentPath?this.currentPath.points:null;if(c){const u=Math.abs(c[c.length-2]-a),d=Math.abs(c[c.length-1]-l);u<h&&d<h||c.push(a,l)}else this.moveTo(a,l),c=this.currentPath.points;return Yd.arc(a,l,t,e,i,s,n,o,c),this}beginFill(t=0,e){return this.beginTextureFill({texture:q.WHITE,color:t,alpha:e})}normalizeColor(t){const e=bt.shared.setValue(t.color??0);t.color=e.toNumber(),t.alpha??(t.alpha=e.alpha)}beginTextureFill(t){const e={texture:q.WHITE,color:16777215,matrix:null};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._fillStyle,{visible:i},t)):this._fillStyle.reset(),this}endFill(){return this.finishPoly(),this._fillStyle.reset(),this}drawRect(t,e,i,s){return this.drawShape(new at(t,e,i,s))}drawRoundedRect(t,e,i,s,n){return this.drawShape(new mn(t,e,i,s,n))}drawCircle(t,e,i){return this.drawShape(new fn(t,e,i))}drawEllipse(t,e,i,s){return this.drawShape(new pn(t,e,i,s))}drawPolygon(...t){let e,i=!0;const s=t[0];s.points?(i=s.closeStroke,e=s.points):Array.isArray(t[0])?e=t[0]:e=t;const n=new Gr(e);return n.closeStroke=i,this.drawShape(n),this}drawShape(t){return this._holeMode?this._geometry.drawHole(t,this._matrix):this._geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone(),this._matrix),this}clear(){return this._geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this._boundsID++,this._matrix=null,this._holeMode=!1,this.currentPath=null,this}isFastRect(){const t=this._geometry.graphicsData;return t.length===1&&t[0].shape.type===Wt.RECT&&!t[0].matrix&&!t[0].holes.length&&!(t[0].lineStyle.visible&&t[0].lineStyle.width)}_render(t){this.finishPoly();const e=this._geometry;e.updateBatches(),e.batchable?(this.batchDirty!==e.batchDirty&&this._populateBatches(),this._renderBatched(t)):(t.batch.flush(),this._renderDirect(t))}_populateBatches(){const t=this._geometry,e=this.blendMode,i=t.batches.length;this.batchTint=-1,this._transformID=-1,this.batchDirty=t.batchDirty,this.batches.length=i,this.vertexData=new Float32Array(t.points);for(let s=0;s<i;s++){const n=t.batches[s],o=n.style.color,a=new Float32Array(this.vertexData.buffer,n.attribStart*4*2,n.attribSize*2),l=new Float32Array(t.uvsFloat32.buffer,n.attribStart*4*2,n.attribSize*2),h=new Uint16Array(t.indicesUint16.buffer,n.start*2,n.size),c={vertexData:a,blendMode:e,indices:h,uvs:l,_batchRGB:bt.shared.setValue(o).toRgbArray(),_tintRGB:o,_texture:n.style.texture,alpha:n.style.alpha,worldAlpha:1};this.batches[s]=c}}_renderBatched(t){if(this.batches.length){t.batch.setObjectRenderer(t.plugins[this.pluginName]),this.calculateVertices(),this.calculateTints();for(let e=0,i=this.batches.length;e<i;e++){const s=this.batches[e];s.worldAlpha=this.worldAlpha*s.alpha,t.plugins[this.pluginName].render(s)}}}_renderDirect(t){const e=this._resolveDirectShader(t),i=this._geometry,s=this.worldAlpha,n=e.uniforms,o=i.drawCalls;n.translationMatrix=this.transform.worldTransform,bt.shared.setValue(this._tintColor).premultiply(s).toArray(n.tint),t.shader.bind(e),t.geometry.bind(i,e),t.state.set(this.state);for(let a=0,l=o.length;a<l;a++)this._renderDrawCallDirect(t,i.drawCalls[a])}_renderDrawCallDirect(t,e){const{texArray:i,type:s,size:n,start:o}=e,a=i.count;for(let l=0;l<a;l++)t.texture.bind(i.elements[l],l);t.geometry.draw(s,n,o)}_resolveDirectShader(t){let e=this.shader;const i=this.pluginName;if(!e){if(!gl[i]){const{maxTextures:s}=t.plugins[i],n=new Int32Array(s);for(let l=0;l<s;l++)n[l]=l;const o={tint:new Float32Array([1,1,1,1]),translationMatrix:new Et,default:Ee.from({uSamplers:n},!0)},a=t.plugins[i]._shader.program;gl[i]=new ze(a,o)}e=gl[i]}return e}_calculateBounds(){this.finishPoly();const t=this._geometry;if(!t.graphicsData.length)return;const{minX:e,minY:i,maxX:s,maxY:n}=t.bounds;this._bounds.addFrame(this.transform,e,i,s,n)}containsPoint(t){return this.worldTransform.applyInverse(t,ro._TEMP_POINT),this._geometry.containsPoint(ro._TEMP_POINT)}calculateTints(){if(this.batchTint!==this.tint){this.batchTint=this._tintColor.toNumber();for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e._tintRGB=bt.shared.setValue(this._tintColor).multiply(e._batchRGB).toLittleEndianNumber()}}}calculateVertices(){const t=this.transform._worldID;if(this._transformID===t)return;this._transformID=t;const e=this.transform.worldTransform,i=e.a,s=e.b,n=e.c,o=e.d,a=e.tx,l=e.ty,h=this._geometry.points,c=this.vertexData;let u=0;for(let d=0;d<h.length;d+=2){const f=h[d],p=h[d+1];c[u++]=i*f+n*p+a,c[u++]=o*p+s*f+l}}closePath(){const t=this.currentPath;return t&&(t.closeStroke=!0,this.finishPoly()),this}setMatrix(t){return this._matrix=t,this}beginHole(){return this.finishPoly(),this._holeMode=!0,this}endHole(){return this.finishPoly(),this._holeMode=!1,this}destroy(t){this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose(),this._matrix=null,this.currentPath=null,this._lineStyle.destroy(),this._lineStyle=null,this._fillStyle.destroy(),this._fillStyle=null,this._geometry=null,this.shader=null,this.vertexData=null,this.batches.length=0,this.batches=null,super.destroy(t)}};yl.curves=Li,yl._TEMP_POINT=new gt;let vs=yl;class Wb{constructor(t,e){this.uvBuffer=t,this.uvMatrix=e,this.data=null,this._bufferUpdateId=-1,this._textureUpdateId=-1,this._updateID=0}update(t){if(!t&&this._bufferUpdateId===this.uvBuffer._updateID&&this._textureUpdateId===this.uvMatrix._updateID)return;this._bufferUpdateId=this.uvBuffer._updateID,this._textureUpdateId=this.uvMatrix._updateID;const e=this.uvBuffer.data;(!this.data||this.data.length!==e.length)&&(this.data=new Float32Array(e.length)),this.uvMatrix.multiplyUvs(e,this.data),this._updateID++}}const _l=new gt,Qd=new Gr,tf=class Wf extends Te{constructor(t,e,i,s=Fe.TRIANGLES){super(),this.geometry=t,this.shader=e,this.state=i||Ve.for2d(),this.drawMode=s,this.start=0,this.size=0,this.uvs=null,this.indices=null,this.vertexData=new Float32Array(1),this.vertexDirty=-1,this._transformID=-1,this._roundPixels=W.ROUND_PIXELS,this.batchUvs=null}get geometry(){return this._geometry}set geometry(t){this._geometry!==t&&(this._geometry&&(this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose()),this._geometry=t,this._geometry&&this._geometry.refCount++,this.vertexDirty=-1)}get uvBuffer(){return this.geometry.buffers[1]}get verticesBuffer(){return this.geometry.buffers[0]}set material(t){this.shader=t}get material(){return this.shader}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get tint(){return"tint"in this.shader?this.shader.tint:null}set tint(t){this.shader.tint=t}get tintValue(){return this.shader.tintValue}get texture(){return"texture"in this.shader?this.shader.texture:null}set texture(t){this.shader.texture=t}_render(t){const e=this.geometry.buffers[0].data;this.shader.batchable&&this.drawMode===Fe.TRIANGLES&&e.length<Wf.BATCHABLE_SIZE*2?this._renderToBatch(t):this._renderDefault(t)}_renderDefault(t){const e=this.shader;e.alpha=this.worldAlpha,e.update&&e.update(),t.batch.flush(),e.uniforms.translationMatrix=this.transform.worldTransform.toArray(!0),t.shader.bind(e),t.state.set(this.state),t.geometry.bind(this.geometry,e),t.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}_renderToBatch(t){const e=this.geometry,i=this.shader;i.uvMatrix&&(i.uvMatrix.update(),this.calculateUvs()),this.calculateVertices(),this.indices=e.indexBuffer.data,this._tintRGB=i._tintRGB,this._texture=i.texture;const s=this.material.pluginName;t.batch.setObjectRenderer(t.plugins[s]),t.plugins[s].render(this)}calculateVertices(){const t=this.geometry.buffers[0],e=t.data,i=t._updateID;if(i===this.vertexDirty&&this._transformID===this.transform._worldID)return;this._transformID=this.transform._worldID,this.vertexData.length!==e.length&&(this.vertexData=new Float32Array(e.length));const s=this.transform.worldTransform,n=s.a,o=s.b,a=s.c,l=s.d,h=s.tx,c=s.ty,u=this.vertexData;for(let d=0;d<u.length/2;d++){const f=e[d*2],p=e[d*2+1];u[d*2]=n*f+a*p+h,u[d*2+1]=o*f+l*p+c}if(this._roundPixels){const d=W.RESOLUTION;for(let f=0;f<u.length;++f)u[f]=Math.round(u[f]*d)/d}this.vertexDirty=i}calculateUvs(){const t=this.geometry.buffers[1],e=this.shader;e.uvMatrix.isSimple?this.uvs=t.data:(this.batchUvs||(this.batchUvs=new Wb(t,e.uvMatrix)),this.batchUvs.update(),this.uvs=this.batchUvs.data)}_calculateBounds(){this.calculateVertices(),this._bounds.addVertexData(this.vertexData,0,this.vertexData.length)}containsPoint(t){if(!this.getBounds().contains(t.x,t.y))return!1;this.worldTransform.applyInverse(t,_l);const e=this.geometry.getBuffer("aVertexPosition").data,i=Qd.points,s=this.geometry.getIndex().data,n=s.length,o=this.drawMode===4?3:1;for(let a=0;a+2<n;a+=o){const l=s[a]*2,h=s[a+1]*2,c=s[a+2]*2;if(i[0]=e[l],i[1]=e[l+1],i[2]=e[h],i[3]=e[h+1],i[4]=e[c],i[5]=e[c+1],Qd.contains(_l.x,_l.y))return!0}return!1}destroy(t){super.destroy(t),this._cachedTexture&&(this._cachedTexture.destroy(),this._cachedTexture=null),this.geometry=null,this.shader=null,this.state=null,this.uvs=null,this.indices=null,this.vertexData=null}};tf.BATCHABLE_SIZE=100;let ef=tf;class jb extends br{constructor(t,e,i){super();const s=new Bt(t),n=new Bt(e,!0),o=new Bt(i,!0,!0);this.addAttribute("aVertexPosition",s,2,!1,J.FLOAT).addAttribute("aTextureCoord",n,2,!1,J.FLOAT).addIndex(o),this._updateId=-1}get vertexDirtyId(){return this.buffers[0]._updateID}}var Yb=`varying vec2 vTextureCoord;
912
912
  uniform vec4 uColor;
913
913
 
914
914
  uniform sampler2D uSampler;
@@ -965,8 +965,8 @@ void main(void){
965
965
  vTextureCoord = aTextureCoord;
966
966
  vColor = aColor * uColor;
967
967
  }
968
- `;class nf extends xn{constructor(t){super(t),this.shader=null,this.properties=null,this.tempMatrix=new Et,this.properties=[{attributeName:"aVertexPosition",size:2,uploadFunction:this.uploadVertices,offset:0},{attributeName:"aPositionCoord",size:2,uploadFunction:this.uploadPosition,offset:0},{attributeName:"aRotation",size:1,uploadFunction:this.uploadRotation,offset:0},{attributeName:"aTextureCoord",size:2,uploadFunction:this.uploadUvs,offset:0},{attributeName:"aColor",size:1,type:J.UNSIGNED_BYTE,uploadFunction:this.uploadTint,offset:0}],this.shader=ze.from(Zb,Kb,{}),this.state=Ve.for2d()}render(t){const e=t.children,i=t._maxSize,s=t._batchSize,n=this.renderer;let o=e.length;if(o===0)return;o>i&&!t.autoResize&&(o=i);let a=t._buffers;a||(a=t._buffers=this.generateBuffers(t));const l=e[0]._texture.baseTexture,h=l.alphaMode>0;this.state.blendMode=vu(t.blendMode,h),n.state.set(this.state);const c=n.gl,u=t.worldTransform.copyTo(this.tempMatrix);u.prepend(n.globalUniforms.uniforms.projectionMatrix),this.shader.uniforms.translationMatrix=u.toArray(!0),this.shader.uniforms.uColor=bt.shared.setValue(t.tintRgb).premultiply(t.worldAlpha,h).toArray(this.shader.uniforms.uColor),this.shader.uniforms.uSampler=l,this.renderer.shader.bind(this.shader);let d=!1;for(let f=0,p=0;f<o;f+=s,p+=1){let m=o-f;m>s&&(m=s),p>=a.length&&a.push(this._generateOneMoreBuffer(t));const _=a[p];_.uploadDynamic(e,f,m);const y=t._bufferUpdateIDs[p]||0;d=d||_._updateID<y,d&&(_._updateID=t._updateID,_.uploadStatic(e,f,m)),n.geometry.bind(_.geometry),c.drawElements(c.TRIANGLES,m*6,c.UNSIGNED_SHORT,0)}}generateBuffers(t){const e=[],i=t._maxSize,s=t._batchSize,n=t._properties;for(let o=0;o<i;o+=s)e.push(new sf(this.properties,n,s));return e}_generateOneMoreBuffer(t){const e=t._batchSize,i=t._properties;return new sf(this.properties,i,e)}uploadVertices(t,e,i,s,n,o){let a=0,l=0,h=0,c=0;for(let u=0;u<i;++u){const d=t[e+u],f=d._texture,p=d.scale.x,m=d.scale.y,_=f.trim,y=f.orig;_?(l=_.x-d.anchor.x*y.width,a=l+_.width,c=_.y-d.anchor.y*y.height,h=c+_.height):(a=y.width*(1-d.anchor.x),l=y.width*-d.anchor.x,h=y.height*(1-d.anchor.y),c=y.height*-d.anchor.y),s[o]=l*p,s[o+1]=c*m,s[o+n]=a*p,s[o+n+1]=c*m,s[o+n*2]=a*p,s[o+n*2+1]=h*m,s[o+n*3]=l*p,s[o+n*3+1]=h*m,o+=n*4}}uploadPosition(t,e,i,s,n,o){for(let a=0;a<i;a++){const l=t[e+a].position;s[o]=l.x,s[o+1]=l.y,s[o+n]=l.x,s[o+n+1]=l.y,s[o+n*2]=l.x,s[o+n*2+1]=l.y,s[o+n*3]=l.x,s[o+n*3+1]=l.y,o+=n*4}}uploadRotation(t,e,i,s,n,o){for(let a=0;a<i;a++){const l=t[e+a].rotation;s[o]=l,s[o+n]=l,s[o+n*2]=l,s[o+n*3]=l,o+=n*4}}uploadUvs(t,e,i,s,n,o){for(let a=0;a<i;++a){const l=t[e+a]._texture._uvs;l?(s[o]=l.x0,s[o+1]=l.y0,s[o+n]=l.x1,s[o+n+1]=l.y1,s[o+n*2]=l.x2,s[o+n*2+1]=l.y2,s[o+n*3]=l.x3,s[o+n*3+1]=l.y3,o+=n*4):(s[o]=0,s[o+1]=0,s[o+n]=0,s[o+n+1]=0,s[o+n*2]=0,s[o+n*2+1]=0,s[o+n*3]=0,s[o+n*3+1]=0,o+=n*4)}}uploadTint(t,e,i,s,n,o){for(let a=0;a<i;++a){const l=t[e+a],h=bt.shared.setValue(l._tintRGB).toPremultiplied(l.alpha,l.texture.baseTexture.alphaMode>0);s[o]=h,s[o+n]=h,s[o+n*2]=h,s[o+n*3]=h,o+=n*4}}destroy(){super.destroy(),this.shader&&(this.shader.destroy(),this.shader=null),this.tempMatrix=null}}nf.extension={name:"particle",type:X.RendererPlugin},Y.add(nf);var Vn=(r=>(r[r.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",r[r.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",r))(Vn||{});const zn={willReadFrequently:!0},je=class K{static get experimentalLetterSpacingSupported(){let t=K._experimentalLetterSpacingSupported;if(t!==void 0){const e=W.ADAPTER.getCanvasRenderingContext2D().prototype;t=K._experimentalLetterSpacingSupported="letterSpacing"in e||"textLetterSpacing"in e}return t}constructor(t,e,i,s,n,o,a,l,h){this.text=t,this.style=e,this.width=i,this.height=s,this.lines=n,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=l,this.fontProperties=h}static measureText(t,e,i,s=K._canvas){i=i??e.wordWrap;const n=e.toFontString(),o=K.measureFont(n);o.fontSize===0&&(o.fontSize=e.fontSize,o.ascent=e.fontSize);const a=s.getContext("2d",zn);a.font=n;const l=(i?K.wordWrap(t,e,s):t).split(/(?:\r\n|\r|\n)/),h=new Array(l.length);let c=0;for(let p=0;p<l.length;p++){const m=K._measureText(l[p],e.letterSpacing,a);h[p]=m,c=Math.max(c,m)}let u=c+e.strokeThickness;e.dropShadow&&(u+=e.dropShadowDistance);const d=e.lineHeight||o.fontSize+e.strokeThickness;let f=Math.max(d,o.fontSize+e.strokeThickness*2)+e.leading+(l.length-1)*(d+e.leading);return e.dropShadow&&(f+=e.dropShadowDistance),new K(t,e,u,f,l,h,d+e.leading,c,o)}static _measureText(t,e,i){let s=!1;K.experimentalLetterSpacingSupported&&(K.experimentalLetterSpacing?(i.letterSpacing=`${e}px`,i.textLetterSpacing=`${e}px`,s=!0):(i.letterSpacing="0px",i.textLetterSpacing="0px"));let n=i.measureText(t).width;return n>0&&(s?n-=e:n+=(K.graphemeSegmenter(t).length-1)*e),n}static wordWrap(t,e,i=K._canvas){const s=i.getContext("2d",zn);let n=0,o="",a="";const l=Object.create(null),{letterSpacing:h,whiteSpace:c}=e,u=K.collapseSpaces(c),d=K.collapseNewlines(c);let f=!u;const p=e.wordWrapWidth+h,m=K.tokenize(t);for(let _=0;_<m.length;_++){let y=m[_];if(K.isNewline(y)){if(!d){a+=K.addLine(o),f=!u,o="",n=0;continue}y=" "}if(u){const g=K.isBreakingSpace(y),v=K.isBreakingSpace(o[o.length-1]);if(g&&v)continue}const x=K.getFromCache(y,h,l,s);if(x>p)if(o!==""&&(a+=K.addLine(o),o="",n=0),K.canBreakWords(y,e.breakWords)){const g=K.wordWrapSplit(y);for(let v=0;v<g.length;v++){let w=g[v],I=w,A=1;for(;g[v+A];){const N=g[v+A];if(!K.canBreakChars(I,N,y,v,e.breakWords))w+=N;else break;I=N,A++}v+=A-1;const C=K.getFromCache(w,h,l,s);C+n>p&&(a+=K.addLine(o),f=!1,o="",n=0),o+=w,n+=C}}else{o.length>0&&(a+=K.addLine(o),o="",n=0);const g=_===m.length-1;a+=K.addLine(y,!g),f=!1,o="",n=0}else x+n>p&&(f=!1,a+=K.addLine(o),o="",n=0),(o.length>0||!K.isBreakingSpace(y)||f)&&(o+=y,n+=x)}return a+=K.addLine(o,!1),a}static addLine(t,e=!0){return t=K.trimRight(t),t=e?`${t}
969
- `:t,t}static getFromCache(t,e,i,s){let n=i[t];return typeof n!="number"&&(n=K._measureText(t,e,s)+e,i[t]=n),n}static collapseSpaces(t){return t==="normal"||t==="pre-line"}static collapseNewlines(t){return t==="normal"}static trimRight(t){if(typeof t!="string")return"";for(let e=t.length-1;e>=0;e--){const i=t[e];if(!K.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static isNewline(t){return typeof t!="string"?!1:K._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:K._breakingSpaces.includes(t.charCodeAt(0))}static tokenize(t){const e=[];let i="";if(typeof t!="string")return e;for(let s=0;s<t.length;s++){const n=t[s],o=t[s+1];if(K.isBreakingSpace(n,o)||K.isNewline(n)){i!==""&&(e.push(i),i=""),e.push(n);continue}i+=n}return i!==""&&e.push(i),e}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,s,n){return!0}static wordWrapSplit(t){return K.graphemeSegmenter(t)}static measureFont(t){if(K._fonts[t])return K._fonts[t];const e={ascent:0,descent:0,fontSize:0},i=K._canvas,s=K._context;s.font=t;const n=K.METRICS_STRING+K.BASELINE_SYMBOL,o=Math.ceil(s.measureText(n).width);let a=Math.ceil(s.measureText(K.BASELINE_SYMBOL).width);const l=Math.ceil(K.HEIGHT_MULTIPLIER*a);if(a=a*K.BASELINE_MULTIPLIER|0,o===0||l===0)return K._fonts[t]=e,e;i.width=o,i.height=l,s.fillStyle="#f00",s.fillRect(0,0,o,l),s.font=t,s.textBaseline="alphabetic",s.fillStyle="#000",s.fillText(n,0,a);const h=s.getImageData(0,0,o,l).data,c=h.length,u=o*4;let d=0,f=0,p=!1;for(d=0;d<a;++d){for(let m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f+=u;else break}for(e.ascent=a-d,f=c-u,p=!1,d=l;d>a;--d){for(let m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f-=u;else break}return e.descent=d-a,e.fontSize=e.ascent+e.descent,K._fonts[t]=e,e}static clearMetrics(t=""){t?delete K._fonts[t]:K._fonts={}}static get _canvas(){var t;if(!K.__canvas){let e;try{const i=new OffscreenCanvas(0,0);if((t=i.getContext("2d",zn))!=null&&t.measureText)return K.__canvas=i,i;e=W.ADAPTER.createCanvas()}catch{e=W.ADAPTER.createCanvas()}e.width=e.height=10,K.__canvas=e}return K.__canvas}static get _context(){return K.__context||(K.__context=K._canvas.getContext("2d",zn)),K.__context}};je.METRICS_STRING="|ÉqÅ",je.BASELINE_SYMBOL="M",je.BASELINE_MULTIPLIER=1.4,je.HEIGHT_MULTIPLIER=2,je.graphemeSegmenter=(()=>{if(typeof(Intl==null?void 0:Intl.Segmenter)=="function"){const r=new Intl.Segmenter;return t=>[...r.segment(t)].map(e=>e.segment)}return r=>[...r]})(),je.experimentalLetterSpacing=!1,je._fonts={},je._newlines=[10,13],je._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let Ar=je;const Jb=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],of=class Ss{constructor(t){this.styleID=0,this.reset(),xl(this,t,t)}clone(){const t={};return xl(t,this,Ss.defaultStyle),new Ss(t)}reset(){xl(this,Ss.defaultStyle,Ss.defaultStyle)}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.styleID++)}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords!==t&&(this._breakWords=t,this.styleID++)}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow!==t&&(this._dropShadow=t,this.styleID++)}get dropShadowAlpha(){return this._dropShadowAlpha}set dropShadowAlpha(t){this._dropShadowAlpha!==t&&(this._dropShadowAlpha=t,this.styleID++)}get dropShadowAngle(){return this._dropShadowAngle}set dropShadowAngle(t){this._dropShadowAngle!==t&&(this._dropShadowAngle=t,this.styleID++)}get dropShadowBlur(){return this._dropShadowBlur}set dropShadowBlur(t){this._dropShadowBlur!==t&&(this._dropShadowBlur=t,this.styleID++)}get dropShadowColor(){return this._dropShadowColor}set dropShadowColor(t){const e=vl(t);this._dropShadowColor!==e&&(this._dropShadowColor=e,this.styleID++)}get dropShadowDistance(){return this._dropShadowDistance}set dropShadowDistance(t){this._dropShadowDistance!==t&&(this._dropShadowDistance=t,this.styleID++)}get fill(){return this._fill}set fill(t){const e=vl(t);this._fill!==e&&(this._fill=e,this.styleID++)}get fillGradientType(){return this._fillGradientType}set fillGradientType(t){this._fillGradientType!==t&&(this._fillGradientType=t,this.styleID++)}get fillGradientStops(){return this._fillGradientStops}set fillGradientStops(t){Qb(this._fillGradientStops,t)||(this._fillGradientStops=t,this.styleID++)}get fontFamily(){return this._fontFamily}set fontFamily(t){this.fontFamily!==t&&(this._fontFamily=t,this.styleID++)}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.styleID++)}get fontStyle(){return this._fontStyle}set fontStyle(t){this._fontStyle!==t&&(this._fontStyle=t,this.styleID++)}get fontVariant(){return this._fontVariant}set fontVariant(t){this._fontVariant!==t&&(this._fontVariant=t,this.styleID++)}get fontWeight(){return this._fontWeight}set fontWeight(t){this._fontWeight!==t&&(this._fontWeight=t,this.styleID++)}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.styleID++)}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight!==t&&(this._lineHeight=t,this.styleID++)}get leading(){return this._leading}set leading(t){this._leading!==t&&(this._leading=t,this.styleID++)}get lineJoin(){return this._lineJoin}set lineJoin(t){this._lineJoin!==t&&(this._lineJoin=t,this.styleID++)}get miterLimit(){return this._miterLimit}set miterLimit(t){this._miterLimit!==t&&(this._miterLimit=t,this.styleID++)}get padding(){return this._padding}set padding(t){this._padding!==t&&(this._padding=t,this.styleID++)}get stroke(){return this._stroke}set stroke(t){const e=vl(t);this._stroke!==e&&(this._stroke=e,this.styleID++)}get strokeThickness(){return this._strokeThickness}set strokeThickness(t){this._strokeThickness!==t&&(this._strokeThickness=t,this.styleID++)}get textBaseline(){return this._textBaseline}set textBaseline(t){this._textBaseline!==t&&(this._textBaseline=t,this.styleID++)}get trim(){return this._trim}set trim(t){this._trim!==t&&(this._trim=t,this.styleID++)}get whiteSpace(){return this._whiteSpace}set whiteSpace(t){this._whiteSpace!==t&&(this._whiteSpace=t,this.styleID++)}get wordWrap(){return this._wordWrap}set wordWrap(t){this._wordWrap!==t&&(this._wordWrap=t,this.styleID++)}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(t){this._wordWrapWidth!==t&&(this._wordWrapWidth=t,this.styleID++)}toFontString(){const t=typeof this.fontSize=="number"?`${this.fontSize}px`:this.fontSize;let e=this.fontFamily;Array.isArray(this.fontFamily)||(e=this.fontFamily.split(","));for(let i=e.length-1;i>=0;i--){let s=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(s)&&!Jb.includes(s)&&(s=`"${s}"`),e[i]=s}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};of.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Vn.LINEAR_VERTICAL,fillGradientStops:[],fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,lineJoin:"miter",miterLimit:10,padding:0,stroke:"black",strokeThickness:0,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let Sr=of;function vl(r){const t=bt.shared,e=i=>{const s=t.setValue(i);return s.alpha===1?s.toHex():s.toRgbaString()};return Array.isArray(r)?r.map(e):e(r)}function Qb(r,t){if(!Array.isArray(r)||!Array.isArray(t)||r.length!==t.length)return!1;for(let e=0;e<r.length;++e)if(r[e]!==t[e])return!1;return!0}function xl(r,t,e){for(const i in e)Array.isArray(t[i])?r[i]=t[i].slice():r[i]=t[i]}const tw={texture:!0,children:!1,baseTexture:!0},af=class Ul extends Pi{constructor(t,e,i){let s=!1;i||(i=W.ADAPTER.createCanvas(),s=!0),i.width=3,i.height=3;const n=q.from(i);n.orig=new at,n.trim=new at,super(n),this._ownCanvas=s,this.canvas=i,this.context=i.getContext("2d",{willReadFrequently:!0}),this._resolution=Ul.defaultResolution??W.RESOLUTION,this._autoResolution=Ul.defaultAutoResolution,this._text=null,this._style=null,this._styleListener=null,this._font="",this.text=t,this.style=e,this.localStyleID=-1}static get experimentalLetterSpacing(){return Ar.experimentalLetterSpacing}static set experimentalLetterSpacing(t){dt("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),Ar.experimentalLetterSpacing=t}updateText(t){const e=this._style;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;this._font=this._style.toFontString();const i=this.context,s=Ar.measureText(this._text||" ",this._style,this._style.wordWrap,this.canvas),n=s.width,o=s.height,a=s.lines,l=s.lineHeight,h=s.lineWidths,c=s.maxLineWidth,u=s.fontProperties;this.canvas.width=Math.ceil(Math.ceil(Math.max(1,n)+e.padding*2)*this._resolution),this.canvas.height=Math.ceil(Math.ceil(Math.max(1,o)+e.padding*2)*this._resolution),i.scale(this._resolution,this._resolution),i.clearRect(0,0,this.canvas.width,this.canvas.height),i.font=this._font,i.lineWidth=e.strokeThickness,i.textBaseline=e.textBaseline,i.lineJoin=e.lineJoin,i.miterLimit=e.miterLimit;let d,f;const p=e.dropShadow?2:1;for(let m=0;m<p;++m){const _=e.dropShadow&&m===0,y=_?Math.ceil(Math.max(1,o)+e.padding*2):0,x=y*this._resolution;if(_){i.fillStyle="black",i.strokeStyle="black";const v=e.dropShadowColor,w=e.dropShadowBlur*this._resolution,I=e.dropShadowDistance*this._resolution;i.shadowColor=bt.shared.setValue(v).setAlpha(e.dropShadowAlpha).toRgbaString(),i.shadowBlur=w,i.shadowOffsetX=Math.cos(e.dropShadowAngle)*I,i.shadowOffsetY=Math.sin(e.dropShadowAngle)*I+x}else i.fillStyle=this._generateFillStyle(e,a,s),i.strokeStyle=e.stroke,i.shadowColor="black",i.shadowBlur=0,i.shadowOffsetX=0,i.shadowOffsetY=0;let g=(l-u.fontSize)/2;l-u.fontSize<0&&(g=0);for(let v=0;v<a.length;v++)d=e.strokeThickness/2,f=e.strokeThickness/2+v*l+u.ascent+g,e.align==="right"?d+=c-h[v]:e.align==="center"&&(d+=(c-h[v])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(a[v],d+e.padding,f+e.padding-y,!0),e.fill&&this.drawLetterSpacing(a[v],d+e.padding,f+e.padding-y)}this.updateTexture()}drawLetterSpacing(t,e,i,s=!1){const n=this._style.letterSpacing;let o=!1;if(Ar.experimentalLetterSpacingSupported&&(Ar.experimentalLetterSpacing?(this.context.letterSpacing=`${n}px`,this.context.textLetterSpacing=`${n}px`,o=!0):(this.context.letterSpacing="0px",this.context.textLetterSpacing="0px")),n===0||o){s?this.context.strokeText(t,e,i):this.context.fillText(t,e,i);return}let a=e;const l=Ar.graphemeSegmenter(t);let h=this.context.measureText(t).width,c=0;for(let u=0;u<l.length;++u){const d=l[u];s?this.context.strokeText(d,a,i):this.context.fillText(d,a,i);let f="";for(let p=u+1;p<l.length;++p)f+=l[p];c=this.context.measureText(f).width,a+=h-c+n,h=c}}updateTexture(){const t=this.canvas;if(this._style.trim){const o=xv(t);o.data&&(t.width=o.width,t.height=o.height,this.context.putImageData(o.data,0,0))}const e=this._texture,i=this._style,s=i.trim?0:i.padding,n=e.baseTexture;e.trim.width=e._frame.width=t.width/this._resolution,e.trim.height=e._frame.height=t.height/this._resolution,e.trim.x=-s,e.trim.y=-s,e.orig.width=e._frame.width-s*2,e.orig.height=e._frame.height-s*2,this._onTextureUpdate(),n.setRealSize(t.width,t.height,this._resolution),e.updateUvs(),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}updateTransform(){this.updateText(!0),super.updateTransform()}getBounds(t,e){return this.updateText(!0),this._textureID===-1&&(t=!1),super.getBounds(t,e)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds.call(this,t)}_calculateBounds(){this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_generateFillStyle(t,e,i){const s=t.fill;if(Array.isArray(s)){if(s.length===1)return s[0]}else return s;let n;const o=t.dropShadow?t.dropShadowDistance:0,a=t.padding||0,l=this.canvas.width/this._resolution-o-a*2,h=this.canvas.height/this._resolution-o-a*2,c=s.slice(),u=t.fillGradientStops.slice();if(!u.length){const d=c.length+1;for(let f=1;f<d;++f)u.push(f/d)}if(c.unshift(s[0]),u.unshift(0),c.push(s[s.length-1]),u.push(1),t.fillGradientType===Vn.LINEAR_VERTICAL){n=this.context.createLinearGradient(l/2,a,l/2,h+a);const d=i.fontProperties.fontSize+t.strokeThickness;for(let f=0;f<e.length;f++){const p=i.lineHeight*(f-1)+d,m=i.lineHeight*f;let _=m;f>0&&p>m&&(_=(m+p)/2);const y=m+d,x=i.lineHeight*(f+1);let g=y;f+1<e.length&&x<y&&(g=(y+x)/2);const v=(g-_)/h;for(let w=0;w<c.length;w++){let I=0;typeof u[w]=="number"?I=u[w]:I=w/c.length;let A=Math.min(1,Math.max(0,_/h+I*v));A=Number(A.toFixed(5)),n.addColorStop(A,c[w])}}}else{n=this.context.createLinearGradient(a,h/2,l+a,h/2);const d=c.length+1;let f=1;for(let p=0;p<c.length;p++){let m;typeof u[p]=="number"?m=u[p]:m=f/d,n.addColorStop(m,c[p]),f++}}return n}destroy(t){typeof t=="boolean"&&(t={children:t}),t=Object.assign({},tw,t),super.destroy(t),this._ownCanvas&&(this.canvas.height=this.canvas.width=0),this.context=null,this.canvas=null,this._style=null}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width}set width(t){this.updateText(!0);const e=vr(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height}set height(t){this.updateText(!0);const e=vr(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get style(){return this._style}set style(t){t=t||{},t instanceof Sr?this._style=t:this._style=new Sr(t),this.localStyleID=-1,this.dirty=!0}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}};af.defaultAutoResolution=!0;let lf=af;class ew{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function rw(r,t){var i;let e=!1;if((i=r==null?void 0:r._textures)!=null&&i.length){for(let s=0;s<r._textures.length;s++)if(r._textures[s]instanceof q){const n=r._textures[s].baseTexture;t.includes(n)||(t.push(n),e=!0)}}return e}function iw(r,t){if(r.baseTexture instanceof nt){const e=r.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function sw(r,t){if(r._texture&&r._texture instanceof q){const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function nw(r,t){return t instanceof lf?(t.updateText(!0),!0):!1}function ow(r,t){if(t instanceof Sr){const e=t.toFontString();return Ar.measureFont(e),!0}return!1}function aw(r,t){if(r instanceof lf){t.includes(r.style)||t.push(r.style),t.includes(r)||t.push(r);const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function lw(r,t){return r instanceof Sr?(t.includes(r)||t.push(r),!0):!1}const hf=class jf{constructor(t){this.limiter=new ew(jf.uploadsPerFrame),this.renderer=t,this.uploadHookHelper=null,this.queue=[],this.addHooks=[],this.uploadHooks=[],this.completes=[],this.ticking=!1,this.delayedTick=()=>{this.queue&&this.prepareItems()},this.registerFindHook(aw),this.registerFindHook(lw),this.registerFindHook(rw),this.registerFindHook(iw),this.registerFindHook(sw),this.registerUploadHook(nw),this.registerUploadHook(ow)}upload(t){return new Promise(e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,le.system.addOnce(this.tick,this,qr.UTILITY))):e()})}tick(){setTimeout(this.delayedTick,0)}prepareItems(){for(this.limiter.beginFrame();this.queue.length&&this.limiter.allowedToUpload();){const t=this.queue[0];let e=!1;if(t&&!t._destroyed){for(let i=0,s=this.uploadHooks.length;i<s;i++)if(this.uploadHooks[i](this.uploadHookHelper,t)){this.queue.shift(),e=!0;break}}e||this.queue.shift()}if(this.queue.length)le.system.addOnce(this.tick,this,qr.UTILITY);else{this.ticking=!1;const t=this.completes.slice(0);this.completes.length=0;for(let e=0,i=t.length;e<i;e++)t[e]()}}registerFindHook(t){return t&&this.addHooks.push(t),this}registerUploadHook(t){return t&&this.uploadHooks.push(t),this}add(t){for(let e=0,i=this.addHooks.length;e<i&&!this.addHooks[e](t,this.queue);e++);if(t instanceof Te)for(let e=t.children.length-1;e>=0;e--)this.add(t.children[e]);return this}destroy(){this.ticking&&le.system.remove(this.tick,this),this.ticking=!1,this.addHooks=null,this.uploadHooks=null,this.renderer=null,this.completes=null,this.queue=null,this.limiter=null,this.uploadHookHelper=null}};hf.uploadsPerFrame=4;let bl=hf;Object.defineProperties(W,{UPLOADS_PER_FRAME:{get(){return bl.uploadsPerFrame},set(r){dt("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),bl.uploadsPerFrame=r}}});function cf(r,t){return t instanceof nt?(t._glTextures[r.CONTEXT_UID]||r.texture.bind(t),!0):!1}function hw(r,t){if(!(t instanceof vs))return!1;const{geometry:e}=t;t.finishPoly(),e.updateBatches();const{batches:i}=e;for(let s=0;s<i.length;s++){const{texture:n}=i[s].style;n&&cf(r,n.baseTexture)}return e.batchable||r.geometry.bind(e,t._resolveDirectShader(r)),!0}function cw(r,t){return r instanceof vs?(t.push(r),!0):!1}class uf extends bl{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(cw),this.registerUploadHook(cf),this.registerUploadHook(hw)}}uf.extension={name:"prepare",type:X.RendererSystem},Y.add(uf);var uw=`#version 300 es
968
+ `;class nf extends xn{constructor(t){super(t),this.shader=null,this.properties=null,this.tempMatrix=new Et,this.properties=[{attributeName:"aVertexPosition",size:2,uploadFunction:this.uploadVertices,offset:0},{attributeName:"aPositionCoord",size:2,uploadFunction:this.uploadPosition,offset:0},{attributeName:"aRotation",size:1,uploadFunction:this.uploadRotation,offset:0},{attributeName:"aTextureCoord",size:2,uploadFunction:this.uploadUvs,offset:0},{attributeName:"aColor",size:1,type:J.UNSIGNED_BYTE,uploadFunction:this.uploadTint,offset:0}],this.shader=ze.from(Zb,Kb,{}),this.state=Ve.for2d()}render(t){const e=t.children,i=t._maxSize,s=t._batchSize,n=this.renderer;let o=e.length;if(o===0)return;o>i&&!t.autoResize&&(o=i);let a=t._buffers;a||(a=t._buffers=this.generateBuffers(t));const l=e[0]._texture.baseTexture,h=l.alphaMode>0;this.state.blendMode=vu(t.blendMode,h),n.state.set(this.state);const c=n.gl,u=t.worldTransform.copyTo(this.tempMatrix);u.prepend(n.globalUniforms.uniforms.projectionMatrix),this.shader.uniforms.translationMatrix=u.toArray(!0),this.shader.uniforms.uColor=bt.shared.setValue(t.tintRgb).premultiply(t.worldAlpha,h).toArray(this.shader.uniforms.uColor),this.shader.uniforms.uSampler=l,this.renderer.shader.bind(this.shader);let d=!1;for(let f=0,p=0;f<o;f+=s,p+=1){let m=o-f;m>s&&(m=s),p>=a.length&&a.push(this._generateOneMoreBuffer(t));const _=a[p];_.uploadDynamic(e,f,m);const y=t._bufferUpdateIDs[p]||0;d=d||_._updateID<y,d&&(_._updateID=t._updateID,_.uploadStatic(e,f,m)),n.geometry.bind(_.geometry),c.drawElements(c.TRIANGLES,m*6,c.UNSIGNED_SHORT,0)}}generateBuffers(t){const e=[],i=t._maxSize,s=t._batchSize,n=t._properties;for(let o=0;o<i;o+=s)e.push(new sf(this.properties,n,s));return e}_generateOneMoreBuffer(t){const e=t._batchSize,i=t._properties;return new sf(this.properties,i,e)}uploadVertices(t,e,i,s,n,o){let a=0,l=0,h=0,c=0;for(let u=0;u<i;++u){const d=t[e+u],f=d._texture,p=d.scale.x,m=d.scale.y,_=f.trim,y=f.orig;_?(l=_.x-d.anchor.x*y.width,a=l+_.width,c=_.y-d.anchor.y*y.height,h=c+_.height):(a=y.width*(1-d.anchor.x),l=y.width*-d.anchor.x,h=y.height*(1-d.anchor.y),c=y.height*-d.anchor.y),s[o]=l*p,s[o+1]=c*m,s[o+n]=a*p,s[o+n+1]=c*m,s[o+n*2]=a*p,s[o+n*2+1]=h*m,s[o+n*3]=l*p,s[o+n*3+1]=h*m,o+=n*4}}uploadPosition(t,e,i,s,n,o){for(let a=0;a<i;a++){const l=t[e+a].position;s[o]=l.x,s[o+1]=l.y,s[o+n]=l.x,s[o+n+1]=l.y,s[o+n*2]=l.x,s[o+n*2+1]=l.y,s[o+n*3]=l.x,s[o+n*3+1]=l.y,o+=n*4}}uploadRotation(t,e,i,s,n,o){for(let a=0;a<i;a++){const l=t[e+a].rotation;s[o]=l,s[o+n]=l,s[o+n*2]=l,s[o+n*3]=l,o+=n*4}}uploadUvs(t,e,i,s,n,o){for(let a=0;a<i;++a){const l=t[e+a]._texture._uvs;l?(s[o]=l.x0,s[o+1]=l.y0,s[o+n]=l.x1,s[o+n+1]=l.y1,s[o+n*2]=l.x2,s[o+n*2+1]=l.y2,s[o+n*3]=l.x3,s[o+n*3+1]=l.y3,o+=n*4):(s[o]=0,s[o+1]=0,s[o+n]=0,s[o+n+1]=0,s[o+n*2]=0,s[o+n*2+1]=0,s[o+n*3]=0,s[o+n*3+1]=0,o+=n*4)}}uploadTint(t,e,i,s,n,o){for(let a=0;a<i;++a){const l=t[e+a],h=bt.shared.setValue(l._tintRGB).toPremultiplied(l.alpha,l.texture.baseTexture.alphaMode>0);s[o]=h,s[o+n]=h,s[o+n*2]=h,s[o+n*3]=h,o+=n*4}}destroy(){super.destroy(),this.shader&&(this.shader.destroy(),this.shader=null),this.tempMatrix=null}}nf.extension={name:"particle",type:X.RendererPlugin},Y.add(nf);var Vn=(r=>(r[r.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",r[r.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",r))(Vn||{});const zn={willReadFrequently:!0},je=class Z{static get experimentalLetterSpacingSupported(){let t=Z._experimentalLetterSpacingSupported;if(t!==void 0){const e=W.ADAPTER.getCanvasRenderingContext2D().prototype;t=Z._experimentalLetterSpacingSupported="letterSpacing"in e||"textLetterSpacing"in e}return t}constructor(t,e,i,s,n,o,a,l,h){this.text=t,this.style=e,this.width=i,this.height=s,this.lines=n,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=l,this.fontProperties=h}static measureText(t,e,i,s=Z._canvas){i=i??e.wordWrap;const n=e.toFontString(),o=Z.measureFont(n);o.fontSize===0&&(o.fontSize=e.fontSize,o.ascent=e.fontSize);const a=s.getContext("2d",zn);a.font=n;const l=(i?Z.wordWrap(t,e,s):t).split(/(?:\r\n|\r|\n)/),h=new Array(l.length);let c=0;for(let p=0;p<l.length;p++){const m=Z._measureText(l[p],e.letterSpacing,a);h[p]=m,c=Math.max(c,m)}let u=c+e.strokeThickness;e.dropShadow&&(u+=e.dropShadowDistance);const d=e.lineHeight||o.fontSize+e.strokeThickness;let f=Math.max(d,o.fontSize+e.strokeThickness*2)+e.leading+(l.length-1)*(d+e.leading);return e.dropShadow&&(f+=e.dropShadowDistance),new Z(t,e,u,f,l,h,d+e.leading,c,o)}static _measureText(t,e,i){let s=!1;Z.experimentalLetterSpacingSupported&&(Z.experimentalLetterSpacing?(i.letterSpacing=`${e}px`,i.textLetterSpacing=`${e}px`,s=!0):(i.letterSpacing="0px",i.textLetterSpacing="0px"));let n=i.measureText(t).width;return n>0&&(s?n-=e:n+=(Z.graphemeSegmenter(t).length-1)*e),n}static wordWrap(t,e,i=Z._canvas){const s=i.getContext("2d",zn);let n=0,o="",a="";const l=Object.create(null),{letterSpacing:h,whiteSpace:c}=e,u=Z.collapseSpaces(c),d=Z.collapseNewlines(c);let f=!u;const p=e.wordWrapWidth+h,m=Z.tokenize(t);for(let _=0;_<m.length;_++){let y=m[_];if(Z.isNewline(y)){if(!d){a+=Z.addLine(o),f=!u,o="",n=0;continue}y=" "}if(u){const g=Z.isBreakingSpace(y),v=Z.isBreakingSpace(o[o.length-1]);if(g&&v)continue}const x=Z.getFromCache(y,h,l,s);if(x>p)if(o!==""&&(a+=Z.addLine(o),o="",n=0),Z.canBreakWords(y,e.breakWords)){const g=Z.wordWrapSplit(y);for(let v=0;v<g.length;v++){let w=g[v],I=w,A=1;for(;g[v+A];){const N=g[v+A];if(!Z.canBreakChars(I,N,y,v,e.breakWords))w+=N;else break;I=N,A++}v+=A-1;const C=Z.getFromCache(w,h,l,s);C+n>p&&(a+=Z.addLine(o),f=!1,o="",n=0),o+=w,n+=C}}else{o.length>0&&(a+=Z.addLine(o),o="",n=0);const g=_===m.length-1;a+=Z.addLine(y,!g),f=!1,o="",n=0}else x+n>p&&(f=!1,a+=Z.addLine(o),o="",n=0),(o.length>0||!Z.isBreakingSpace(y)||f)&&(o+=y,n+=x)}return a+=Z.addLine(o,!1),a}static addLine(t,e=!0){return t=Z.trimRight(t),t=e?`${t}
969
+ `:t,t}static getFromCache(t,e,i,s){let n=i[t];return typeof n!="number"&&(n=Z._measureText(t,e,s)+e,i[t]=n),n}static collapseSpaces(t){return t==="normal"||t==="pre-line"}static collapseNewlines(t){return t==="normal"}static trimRight(t){if(typeof t!="string")return"";for(let e=t.length-1;e>=0;e--){const i=t[e];if(!Z.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static isNewline(t){return typeof t!="string"?!1:Z._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:Z._breakingSpaces.includes(t.charCodeAt(0))}static tokenize(t){const e=[];let i="";if(typeof t!="string")return e;for(let s=0;s<t.length;s++){const n=t[s],o=t[s+1];if(Z.isBreakingSpace(n,o)||Z.isNewline(n)){i!==""&&(e.push(i),i=""),e.push(n);continue}i+=n}return i!==""&&e.push(i),e}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,s,n){return!0}static wordWrapSplit(t){return Z.graphemeSegmenter(t)}static measureFont(t){if(Z._fonts[t])return Z._fonts[t];const e={ascent:0,descent:0,fontSize:0},i=Z._canvas,s=Z._context;s.font=t;const n=Z.METRICS_STRING+Z.BASELINE_SYMBOL,o=Math.ceil(s.measureText(n).width);let a=Math.ceil(s.measureText(Z.BASELINE_SYMBOL).width);const l=Math.ceil(Z.HEIGHT_MULTIPLIER*a);if(a=a*Z.BASELINE_MULTIPLIER|0,o===0||l===0)return Z._fonts[t]=e,e;i.width=o,i.height=l,s.fillStyle="#f00",s.fillRect(0,0,o,l),s.font=t,s.textBaseline="alphabetic",s.fillStyle="#000",s.fillText(n,0,a);const h=s.getImageData(0,0,o,l).data,c=h.length,u=o*4;let d=0,f=0,p=!1;for(d=0;d<a;++d){for(let m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f+=u;else break}for(e.ascent=a-d,f=c-u,p=!1,d=l;d>a;--d){for(let m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f-=u;else break}return e.descent=d-a,e.fontSize=e.ascent+e.descent,Z._fonts[t]=e,e}static clearMetrics(t=""){t?delete Z._fonts[t]:Z._fonts={}}static get _canvas(){var t;if(!Z.__canvas){let e;try{const i=new OffscreenCanvas(0,0);if((t=i.getContext("2d",zn))!=null&&t.measureText)return Z.__canvas=i,i;e=W.ADAPTER.createCanvas()}catch{e=W.ADAPTER.createCanvas()}e.width=e.height=10,Z.__canvas=e}return Z.__canvas}static get _context(){return Z.__context||(Z.__context=Z._canvas.getContext("2d",zn)),Z.__context}};je.METRICS_STRING="|ÉqÅ",je.BASELINE_SYMBOL="M",je.BASELINE_MULTIPLIER=1.4,je.HEIGHT_MULTIPLIER=2,je.graphemeSegmenter=(()=>{if(typeof(Intl==null?void 0:Intl.Segmenter)=="function"){const r=new Intl.Segmenter;return t=>[...r.segment(t)].map(e=>e.segment)}return r=>[...r]})(),je.experimentalLetterSpacing=!1,je._fonts={},je._newlines=[10,13],je._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let Ar=je;const Jb=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],of=class Ss{constructor(t){this.styleID=0,this.reset(),xl(this,t,t)}clone(){const t={};return xl(t,this,Ss.defaultStyle),new Ss(t)}reset(){xl(this,Ss.defaultStyle,Ss.defaultStyle)}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.styleID++)}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords!==t&&(this._breakWords=t,this.styleID++)}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow!==t&&(this._dropShadow=t,this.styleID++)}get dropShadowAlpha(){return this._dropShadowAlpha}set dropShadowAlpha(t){this._dropShadowAlpha!==t&&(this._dropShadowAlpha=t,this.styleID++)}get dropShadowAngle(){return this._dropShadowAngle}set dropShadowAngle(t){this._dropShadowAngle!==t&&(this._dropShadowAngle=t,this.styleID++)}get dropShadowBlur(){return this._dropShadowBlur}set dropShadowBlur(t){this._dropShadowBlur!==t&&(this._dropShadowBlur=t,this.styleID++)}get dropShadowColor(){return this._dropShadowColor}set dropShadowColor(t){const e=vl(t);this._dropShadowColor!==e&&(this._dropShadowColor=e,this.styleID++)}get dropShadowDistance(){return this._dropShadowDistance}set dropShadowDistance(t){this._dropShadowDistance!==t&&(this._dropShadowDistance=t,this.styleID++)}get fill(){return this._fill}set fill(t){const e=vl(t);this._fill!==e&&(this._fill=e,this.styleID++)}get fillGradientType(){return this._fillGradientType}set fillGradientType(t){this._fillGradientType!==t&&(this._fillGradientType=t,this.styleID++)}get fillGradientStops(){return this._fillGradientStops}set fillGradientStops(t){Qb(this._fillGradientStops,t)||(this._fillGradientStops=t,this.styleID++)}get fontFamily(){return this._fontFamily}set fontFamily(t){this.fontFamily!==t&&(this._fontFamily=t,this.styleID++)}get fontSize(){return this._fontSize}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.styleID++)}get fontStyle(){return this._fontStyle}set fontStyle(t){this._fontStyle!==t&&(this._fontStyle=t,this.styleID++)}get fontVariant(){return this._fontVariant}set fontVariant(t){this._fontVariant!==t&&(this._fontVariant=t,this.styleID++)}get fontWeight(){return this._fontWeight}set fontWeight(t){this._fontWeight!==t&&(this._fontWeight=t,this.styleID++)}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.styleID++)}get lineHeight(){return this._lineHeight}set lineHeight(t){this._lineHeight!==t&&(this._lineHeight=t,this.styleID++)}get leading(){return this._leading}set leading(t){this._leading!==t&&(this._leading=t,this.styleID++)}get lineJoin(){return this._lineJoin}set lineJoin(t){this._lineJoin!==t&&(this._lineJoin=t,this.styleID++)}get miterLimit(){return this._miterLimit}set miterLimit(t){this._miterLimit!==t&&(this._miterLimit=t,this.styleID++)}get padding(){return this._padding}set padding(t){this._padding!==t&&(this._padding=t,this.styleID++)}get stroke(){return this._stroke}set stroke(t){const e=vl(t);this._stroke!==e&&(this._stroke=e,this.styleID++)}get strokeThickness(){return this._strokeThickness}set strokeThickness(t){this._strokeThickness!==t&&(this._strokeThickness=t,this.styleID++)}get textBaseline(){return this._textBaseline}set textBaseline(t){this._textBaseline!==t&&(this._textBaseline=t,this.styleID++)}get trim(){return this._trim}set trim(t){this._trim!==t&&(this._trim=t,this.styleID++)}get whiteSpace(){return this._whiteSpace}set whiteSpace(t){this._whiteSpace!==t&&(this._whiteSpace=t,this.styleID++)}get wordWrap(){return this._wordWrap}set wordWrap(t){this._wordWrap!==t&&(this._wordWrap=t,this.styleID++)}get wordWrapWidth(){return this._wordWrapWidth}set wordWrapWidth(t){this._wordWrapWidth!==t&&(this._wordWrapWidth=t,this.styleID++)}toFontString(){const t=typeof this.fontSize=="number"?`${this.fontSize}px`:this.fontSize;let e=this.fontFamily;Array.isArray(this.fontFamily)||(e=this.fontFamily.split(","));for(let i=e.length-1;i>=0;i--){let s=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(s)&&!Jb.includes(s)&&(s=`"${s}"`),e[i]=s}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};of.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Vn.LINEAR_VERTICAL,fillGradientStops:[],fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",leading:0,letterSpacing:0,lineHeight:0,lineJoin:"miter",miterLimit:10,padding:0,stroke:"black",strokeThickness:0,textBaseline:"alphabetic",trim:!1,whiteSpace:"pre",wordWrap:!1,wordWrapWidth:100};let Sr=of;function vl(r){const t=bt.shared,e=i=>{const s=t.setValue(i);return s.alpha===1?s.toHex():s.toRgbaString()};return Array.isArray(r)?r.map(e):e(r)}function Qb(r,t){if(!Array.isArray(r)||!Array.isArray(t)||r.length!==t.length)return!1;for(let e=0;e<r.length;++e)if(r[e]!==t[e])return!1;return!0}function xl(r,t,e){for(const i in e)Array.isArray(t[i])?r[i]=t[i].slice():r[i]=t[i]}const tw={texture:!0,children:!1,baseTexture:!0},af=class Ul extends Pi{constructor(t,e,i){let s=!1;i||(i=W.ADAPTER.createCanvas(),s=!0),i.width=3,i.height=3;const n=q.from(i);n.orig=new at,n.trim=new at,super(n),this._ownCanvas=s,this.canvas=i,this.context=i.getContext("2d",{willReadFrequently:!0}),this._resolution=Ul.defaultResolution??W.RESOLUTION,this._autoResolution=Ul.defaultAutoResolution,this._text=null,this._style=null,this._styleListener=null,this._font="",this.text=t,this.style=e,this.localStyleID=-1}static get experimentalLetterSpacing(){return Ar.experimentalLetterSpacing}static set experimentalLetterSpacing(t){dt("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),Ar.experimentalLetterSpacing=t}updateText(t){const e=this._style;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;this._font=this._style.toFontString();const i=this.context,s=Ar.measureText(this._text||" ",this._style,this._style.wordWrap,this.canvas),n=s.width,o=s.height,a=s.lines,l=s.lineHeight,h=s.lineWidths,c=s.maxLineWidth,u=s.fontProperties;this.canvas.width=Math.ceil(Math.ceil(Math.max(1,n)+e.padding*2)*this._resolution),this.canvas.height=Math.ceil(Math.ceil(Math.max(1,o)+e.padding*2)*this._resolution),i.scale(this._resolution,this._resolution),i.clearRect(0,0,this.canvas.width,this.canvas.height),i.font=this._font,i.lineWidth=e.strokeThickness,i.textBaseline=e.textBaseline,i.lineJoin=e.lineJoin,i.miterLimit=e.miterLimit;let d,f;const p=e.dropShadow?2:1;for(let m=0;m<p;++m){const _=e.dropShadow&&m===0,y=_?Math.ceil(Math.max(1,o)+e.padding*2):0,x=y*this._resolution;if(_){i.fillStyle="black",i.strokeStyle="black";const v=e.dropShadowColor,w=e.dropShadowBlur*this._resolution,I=e.dropShadowDistance*this._resolution;i.shadowColor=bt.shared.setValue(v).setAlpha(e.dropShadowAlpha).toRgbaString(),i.shadowBlur=w,i.shadowOffsetX=Math.cos(e.dropShadowAngle)*I,i.shadowOffsetY=Math.sin(e.dropShadowAngle)*I+x}else i.fillStyle=this._generateFillStyle(e,a,s),i.strokeStyle=e.stroke,i.shadowColor="black",i.shadowBlur=0,i.shadowOffsetX=0,i.shadowOffsetY=0;let g=(l-u.fontSize)/2;l-u.fontSize<0&&(g=0);for(let v=0;v<a.length;v++)d=e.strokeThickness/2,f=e.strokeThickness/2+v*l+u.ascent+g,e.align==="right"?d+=c-h[v]:e.align==="center"&&(d+=(c-h[v])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(a[v],d+e.padding,f+e.padding-y,!0),e.fill&&this.drawLetterSpacing(a[v],d+e.padding,f+e.padding-y)}this.updateTexture()}drawLetterSpacing(t,e,i,s=!1){const n=this._style.letterSpacing;let o=!1;if(Ar.experimentalLetterSpacingSupported&&(Ar.experimentalLetterSpacing?(this.context.letterSpacing=`${n}px`,this.context.textLetterSpacing=`${n}px`,o=!0):(this.context.letterSpacing="0px",this.context.textLetterSpacing="0px")),n===0||o){s?this.context.strokeText(t,e,i):this.context.fillText(t,e,i);return}let a=e;const l=Ar.graphemeSegmenter(t);let h=this.context.measureText(t).width,c=0;for(let u=0;u<l.length;++u){const d=l[u];s?this.context.strokeText(d,a,i):this.context.fillText(d,a,i);let f="";for(let p=u+1;p<l.length;++p)f+=l[p];c=this.context.measureText(f).width,a+=h-c+n,h=c}}updateTexture(){const t=this.canvas;if(this._style.trim){const o=xv(t);o.data&&(t.width=o.width,t.height=o.height,this.context.putImageData(o.data,0,0))}const e=this._texture,i=this._style,s=i.trim?0:i.padding,n=e.baseTexture;e.trim.width=e._frame.width=t.width/this._resolution,e.trim.height=e._frame.height=t.height/this._resolution,e.trim.x=-s,e.trim.y=-s,e.orig.width=e._frame.width-s*2,e.orig.height=e._frame.height-s*2,this._onTextureUpdate(),n.setRealSize(t.width,t.height,this._resolution),e.updateUvs(),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}updateTransform(){this.updateText(!0),super.updateTransform()}getBounds(t,e){return this.updateText(!0),this._textureID===-1&&(t=!1),super.getBounds(t,e)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds.call(this,t)}_calculateBounds(){this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_generateFillStyle(t,e,i){const s=t.fill;if(Array.isArray(s)){if(s.length===1)return s[0]}else return s;let n;const o=t.dropShadow?t.dropShadowDistance:0,a=t.padding||0,l=this.canvas.width/this._resolution-o-a*2,h=this.canvas.height/this._resolution-o-a*2,c=s.slice(),u=t.fillGradientStops.slice();if(!u.length){const d=c.length+1;for(let f=1;f<d;++f)u.push(f/d)}if(c.unshift(s[0]),u.unshift(0),c.push(s[s.length-1]),u.push(1),t.fillGradientType===Vn.LINEAR_VERTICAL){n=this.context.createLinearGradient(l/2,a,l/2,h+a);const d=i.fontProperties.fontSize+t.strokeThickness;for(let f=0;f<e.length;f++){const p=i.lineHeight*(f-1)+d,m=i.lineHeight*f;let _=m;f>0&&p>m&&(_=(m+p)/2);const y=m+d,x=i.lineHeight*(f+1);let g=y;f+1<e.length&&x<y&&(g=(y+x)/2);const v=(g-_)/h;for(let w=0;w<c.length;w++){let I=0;typeof u[w]=="number"?I=u[w]:I=w/c.length;let A=Math.min(1,Math.max(0,_/h+I*v));A=Number(A.toFixed(5)),n.addColorStop(A,c[w])}}}else{n=this.context.createLinearGradient(a,h/2,l+a,h/2);const d=c.length+1;let f=1;for(let p=0;p<c.length;p++){let m;typeof u[p]=="number"?m=u[p]:m=f/d,n.addColorStop(m,c[p]),f++}}return n}destroy(t){typeof t=="boolean"&&(t={children:t}),t=Object.assign({},tw,t),super.destroy(t),this._ownCanvas&&(this.canvas.height=this.canvas.width=0),this.context=null,this.canvas=null,this._style=null}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._texture.orig.width}set width(t){this.updateText(!0);const e=vr(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._texture.orig.height}set height(t){this.updateText(!0);const e=vr(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get style(){return this._style}set style(t){t=t||{},t instanceof Sr?this._style=t:this._style=new Sr(t),this.localStyleID=-1,this.dirty=!0}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}};af.defaultAutoResolution=!0;let lf=af;class ew{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function rw(r,t){var i;let e=!1;if((i=r==null?void 0:r._textures)!=null&&i.length){for(let s=0;s<r._textures.length;s++)if(r._textures[s]instanceof q){const n=r._textures[s].baseTexture;t.includes(n)||(t.push(n),e=!0)}}return e}function iw(r,t){if(r.baseTexture instanceof nt){const e=r.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function sw(r,t){if(r._texture&&r._texture instanceof q){const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function nw(r,t){return t instanceof lf?(t.updateText(!0),!0):!1}function ow(r,t){if(t instanceof Sr){const e=t.toFontString();return Ar.measureFont(e),!0}return!1}function aw(r,t){if(r instanceof lf){t.includes(r.style)||t.push(r.style),t.includes(r)||t.push(r);const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function lw(r,t){return r instanceof Sr?(t.includes(r)||t.push(r),!0):!1}const hf=class jf{constructor(t){this.limiter=new ew(jf.uploadsPerFrame),this.renderer=t,this.uploadHookHelper=null,this.queue=[],this.addHooks=[],this.uploadHooks=[],this.completes=[],this.ticking=!1,this.delayedTick=()=>{this.queue&&this.prepareItems()},this.registerFindHook(aw),this.registerFindHook(lw),this.registerFindHook(rw),this.registerFindHook(iw),this.registerFindHook(sw),this.registerUploadHook(nw),this.registerUploadHook(ow)}upload(t){return new Promise(e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,le.system.addOnce(this.tick,this,qr.UTILITY))):e()})}tick(){setTimeout(this.delayedTick,0)}prepareItems(){for(this.limiter.beginFrame();this.queue.length&&this.limiter.allowedToUpload();){const t=this.queue[0];let e=!1;if(t&&!t._destroyed){for(let i=0,s=this.uploadHooks.length;i<s;i++)if(this.uploadHooks[i](this.uploadHookHelper,t)){this.queue.shift(),e=!0;break}}e||this.queue.shift()}if(this.queue.length)le.system.addOnce(this.tick,this,qr.UTILITY);else{this.ticking=!1;const t=this.completes.slice(0);this.completes.length=0;for(let e=0,i=t.length;e<i;e++)t[e]()}}registerFindHook(t){return t&&this.addHooks.push(t),this}registerUploadHook(t){return t&&this.uploadHooks.push(t),this}add(t){for(let e=0,i=this.addHooks.length;e<i&&!this.addHooks[e](t,this.queue);e++);if(t instanceof Te)for(let e=t.children.length-1;e>=0;e--)this.add(t.children[e]);return this}destroy(){this.ticking&&le.system.remove(this.tick,this),this.ticking=!1,this.addHooks=null,this.uploadHooks=null,this.renderer=null,this.completes=null,this.queue=null,this.limiter=null,this.uploadHookHelper=null}};hf.uploadsPerFrame=4;let bl=hf;Object.defineProperties(W,{UPLOADS_PER_FRAME:{get(){return bl.uploadsPerFrame},set(r){dt("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),bl.uploadsPerFrame=r}}});function cf(r,t){return t instanceof nt?(t._glTextures[r.CONTEXT_UID]||r.texture.bind(t),!0):!1}function hw(r,t){if(!(t instanceof vs))return!1;const{geometry:e}=t;t.finishPoly(),e.updateBatches();const{batches:i}=e;for(let s=0;s<i.length;s++){const{texture:n}=i[s].style;n&&cf(r,n.baseTexture)}return e.batchable||r.geometry.bind(e,t._resolveDirectShader(r)),!0}function cw(r,t){return r instanceof vs?(t.push(r),!0):!1}class uf extends bl{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(cw),this.registerUploadHook(cf),this.registerUploadHook(hw)}}uf.extension={name:"prepare",type:X.RendererSystem},Y.add(uf);var uw=`#version 300 es
970
970
  #define SHADER_NAME Tiling-Sprite-100
971
971
 
972
972
  precision lowp float;
@@ -1137,12 +1137,12 @@ void main(void)\r
1137
1137
  `;const _f=[],vf=[],xf=[],Ew=class Yf extends Te{constructor(t,e={}){super();const{align:i,tint:s,maxWidth:n,letterSpacing:o,fontName:a,fontSize:l}=Object.assign({},Yf.styleDefaults,e);if(!Cr.available[a])throw new Error(`Missing BitmapFont "${a}"`);this._activePagesMeshData=[],this._textWidth=0,this._textHeight=0,this._align=i,this._tintColor=new bt(s),this._font=void 0,this._fontName=a,this._fontSize=l,this.text=t,this._maxWidth=n,this._maxLineHeight=0,this._letterSpacing=o,this._anchor=new cr(()=>{this.dirty=!0},this,0,0),this._roundPixels=W.ROUND_PIXELS,this.dirty=!0,this._resolution=W.RESOLUTION,this._autoResolution=!0,this._textureCache={}}updateText(){var R;const t=Cr.available[this._fontName],e=this.fontSize,i=e/t.size,s=new gt,n=[],o=[],a=[],l=this._text.replace(/(?:\r\n|\r)/g,`
1138
1138
  `)||" ",h=yf(l),c=this._maxWidth*t.size/e,u=t.distanceFieldType==="none"?_f:vf;let d=null,f=0,p=0,m=0,_=-1,y=0,x=0,g=0,v=0;for(let E=0;E<h.length;E++){const b=h[E],D=qn(b);if(/(?:\s)/.test(b)&&(_=E,y=f,v++),b==="\r"||b===`
1139
1139
  `){o.push(f),a.push(-1),p=Math.max(p,f),++m,++x,s.x=0,s.y+=t.lineHeight,d=null,v=0;continue}const F=t.chars[D];if(!F)continue;d&&F.kerning[d]&&(s.x+=F.kerning[d]);const G=xf.pop()||{texture:q.EMPTY,line:0,charCode:0,prevSpaces:0,position:new gt};G.texture=F.texture,G.line=m,G.charCode=D,G.position.x=Math.round(s.x+F.xOffset+this._letterSpacing/2),G.position.y=Math.round(s.y+F.yOffset),G.prevSpaces=v,n.push(G),f=G.position.x+Math.max(F.xAdvance-F.xOffset,F.texture.orig.width),s.x+=F.xAdvance+this._letterSpacing,g=Math.max(g,F.yOffset+F.texture.height),d=D,_!==-1&&c>0&&s.x>c&&(++x,Si(n,1+_-x,1+E-_),E=_,_=-1,o.push(y),a.push(n.length>0?n[n.length-1].prevSpaces:0),p=Math.max(p,y),m++,s.x=0,s.y+=t.lineHeight,d=null,v=0)}const w=h[h.length-1];w!=="\r"&&w!==`
1140
- `&&(/(?:\s)/.test(w)&&(f=y),o.push(f),p=Math.max(p,f),a.push(-1));const I=[];for(let E=0;E<=m;E++){let b=0;this._align==="right"?b=p-o[E]:this._align==="center"?b=(p-o[E])/2:this._align==="justify"&&(b=a[E]<0?0:(p-o[E])/a[E]),I.push(b)}const A=n.length,C={},N=[],S=this._activePagesMeshData;u.push(...S);for(let E=0;E<A;E++){const b=n[E].texture,D=b.baseTexture.uid;if(!C[D]){let F=u.pop();if(!F){const $=new jb;let B,Z;t.distanceFieldType==="none"?(B=new rf(q.EMPTY),Z=tt.NORMAL):(B=new rf(q.EMPTY,{program:ur.from(ww,bw),uniforms:{uFWidth:0}}),Z=tt.NORMAL_NPM);const P=new ef($,B);P.blendMode=Z,F={index:0,indexCount:0,vertexCount:0,uvsCount:0,total:0,mesh:P,vertices:null,uvs:null,indices:null}}F.index=0,F.indexCount=0,F.vertexCount=0,F.uvsCount=0,F.total=0;const{_textureCache:G}=this;G[D]=G[D]||new q(b.baseTexture),F.mesh.texture=G[D],F.mesh.tint=this._tintColor.value,N.push(F),C[D]=F}C[D].total++}for(let E=0;E<S.length;E++)N.includes(S[E])||this.removeChild(S[E].mesh);for(let E=0;E<N.length;E++)N[E].mesh.parent!==this&&this.addChild(N[E].mesh);this._activePagesMeshData=N;for(const E in C){const b=C[E],D=b.total;if(!(((R=b.indices)==null?void 0:R.length)>6*D)||b.vertices.length<ef.BATCHABLE_SIZE*2)b.vertices=new Float32Array(4*2*D),b.uvs=new Float32Array(4*2*D),b.indices=new Uint16Array(6*D);else{const F=b.total,G=b.vertices;for(let $=F*4*2;$<G.length;$++)G[$]=0}b.mesh.size=6*D}for(let E=0;E<A;E++){const b=n[E];let D=b.position.x+I[b.line]*(this._align==="justify"?b.prevSpaces:1);this._roundPixels&&(D=Math.round(D));const F=D*i,G=b.position.y*i,$=b.texture,B=C[$.baseTexture.uid],Z=$.frame,P=$._uvs,U=B.index++;B.indices[U*6+0]=0+U*4,B.indices[U*6+1]=1+U*4,B.indices[U*6+2]=2+U*4,B.indices[U*6+3]=0+U*4,B.indices[U*6+4]=2+U*4,B.indices[U*6+5]=3+U*4,B.vertices[U*8+0]=F,B.vertices[U*8+1]=G,B.vertices[U*8+2]=F+Z.width*i,B.vertices[U*8+3]=G,B.vertices[U*8+4]=F+Z.width*i,B.vertices[U*8+5]=G+Z.height*i,B.vertices[U*8+6]=F,B.vertices[U*8+7]=G+Z.height*i,B.uvs[U*8+0]=P.x0,B.uvs[U*8+1]=P.y0,B.uvs[U*8+2]=P.x1,B.uvs[U*8+3]=P.y1,B.uvs[U*8+4]=P.x2,B.uvs[U*8+5]=P.y2,B.uvs[U*8+6]=P.x3,B.uvs[U*8+7]=P.y3}this._textWidth=p*i,this._textHeight=(s.y+t.lineHeight)*i;for(const E in C){const b=C[E];if(this.anchor.x!==0||this.anchor.y!==0){let $=0;const B=this._textWidth*this.anchor.x,Z=this._textHeight*this.anchor.y;for(let P=0;P<b.total;P++)b.vertices[$++]-=B,b.vertices[$++]-=Z,b.vertices[$++]-=B,b.vertices[$++]-=Z,b.vertices[$++]-=B,b.vertices[$++]-=Z,b.vertices[$++]-=B,b.vertices[$++]-=Z}this._maxLineHeight=g*i;const D=b.mesh.geometry.getBuffer("aVertexPosition"),F=b.mesh.geometry.getBuffer("aTextureCoord"),G=b.mesh.geometry.getIndex();D.data=b.vertices,F.data=b.uvs,G.data=b.indices,D.update(),F.update(),G.update()}for(let E=0;E<n.length;E++)xf.push(n[E]);this._font=t,this.dirty=!1}updateTransform(){this.validate(),this.containerUpdateTransform()}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0);const{distanceFieldRange:e,distanceFieldType:i,size:s}=Cr.available[this._fontName];if(i!=="none"){const{a:n,b:o,c:a,d:l}=this.worldTransform,h=Math.sqrt(n*n+o*o),c=Math.sqrt(a*a+l*l),u=(Math.abs(h)+Math.abs(c))/2,d=this.fontSize/s,f=t._view.resolution;for(const p of this._activePagesMeshData)p.mesh.shader.uniforms.uFWidth=u*e*d*f}super._render(t)}getLocalBounds(){return this.validate(),super.getLocalBounds()}validate(){const t=Cr.available[this._fontName];if(!t)throw new Error(`Missing BitmapFont "${this._fontName}"`);this._font!==t&&(this.dirty=!0),this.dirty&&this.updateText()}get tint(){return this._tintColor.value}set tint(t){if(this.tint!==t){this._tintColor.setValue(t);for(let e=0;e<this._activePagesMeshData.length;e++)this._activePagesMeshData[e].mesh.tint=t}}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.dirty=!0)}get fontName(){return this._fontName}set fontName(t){if(!Cr.available[t])throw new Error(`Missing BitmapFont "${t}"`);this._fontName!==t&&(this._fontName=t,this.dirty=!0)}get fontSize(){return this._fontSize??Cr.available[this._fontName].size}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.dirty=!0)}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get maxWidth(){return this._maxWidth}set maxWidth(t){this._maxWidth!==t&&(this._maxWidth=t,this.dirty=!0)}get maxLineHeight(){return this.validate(),this._maxLineHeight}get textWidth(){return this.validate(),this._textWidth}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.dirty=!0)}get roundPixels(){return this._roundPixels}set roundPixels(t){t!==this._roundPixels&&(this._roundPixels=t,this.dirty=!0)}get textHeight(){return this.validate(),this._textHeight}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}destroy(t){const{_textureCache:e}=this,i=Cr.available[this._fontName].distanceFieldType==="none"?_f:vf;i.push(...this._activePagesMeshData);for(const s of this._activePagesMeshData)this.removeChild(s.mesh);this._activePagesMeshData=[],i.filter(s=>e[s.mesh.texture.baseTexture.uid]).forEach(s=>{s.mesh.texture=q.EMPTY});for(const s in e)e[s].destroy(),delete e[s];this._font=null,this._tintColor=null,this._textureCache=null,super.destroy(t)}};Ew.styleDefaults={align:"left",tint:16777215,maxWidth:0,letterSpacing:0};const Tw=[".xml",".fnt"],Aw={extension:{type:X.LoadParser,priority:Ie.Normal},name:"loadBitmapFont",test(r){return Tw.includes(Gt.extname(r).toLowerCase())},async testParse(r){return Yn.test(r)||El.test(r)},async parse(r,t,e){const i=Yn.test(r)?Yn.parse(r):El.parse(r),{src:s}=t,{page:n}=i,o=[];for(let h=0;h<n.length;++h){const c=n[h].file;let u=Gt.join(Gt.dirname(s),c);u=ol(u,s),o.push(u)}const a=await e.load(o),l=o.map(h=>a[h]);return Cr.install(i,l,!0)},async load(r,t){return(await W.ADAPTER.fetch(r)).text()},unload(r){r.destroy()}};Y.add(Aw);const Al=class $i extends Sr{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new $i(Object.keys($i.defaultOptions).reduce((e,i)=>({...e,[i]:t[i]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete $i.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:i}=$i;if(i[t]){const s=i[t];return this._fonts.push(s),s.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return W.ADAPTER.fetch(t).then(s=>s.blob()).then(async s=>new Promise((n,o)=>{const a=URL.createObjectURL(s),l=new FileReader;l.onload=()=>n([a,l.result]),l.onerror=o,l.readAsDataURL(s)})).then(async([s,n])=>{const o=Object.assign({family:Gt.basename(t,Gt.extname(t)),weight:"normal",style:"normal",display:"auto",src:s,dataSrc:n,refs:1,originalUrl:t,fontFace:null},e);i[t]=o,this._fonts.push(o),this.styleID++;const a=new FontFace(o.family,`url(${o.src})`,{weight:o.weight,style:o.style,display:o.display});o.fontFace=a,await a.load(),document.fonts.add(a),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(i=>!this._overrides.includes(i));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(i=>this._overrides.includes(i));e.length>0&&(this._overrides=this._overrides.filter(i=>!e.includes(i)),this.styleID++)}toCSS(t){return[`transform: scale(${t})`,"transform-origin: top left","display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing}px`,`text-align: ${this.align}`,`padding: ${this.padding}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS()]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t}
1140
+ `&&(/(?:\s)/.test(w)&&(f=y),o.push(f),p=Math.max(p,f),a.push(-1));const I=[];for(let E=0;E<=m;E++){let b=0;this._align==="right"?b=p-o[E]:this._align==="center"?b=(p-o[E])/2:this._align==="justify"&&(b=a[E]<0?0:(p-o[E])/a[E]),I.push(b)}const A=n.length,C={},N=[],S=this._activePagesMeshData;u.push(...S);for(let E=0;E<A;E++){const b=n[E].texture,D=b.baseTexture.uid;if(!C[D]){let F=u.pop();if(!F){const $=new jb;let B,K;t.distanceFieldType==="none"?(B=new rf(q.EMPTY),K=tt.NORMAL):(B=new rf(q.EMPTY,{program:ur.from(ww,bw),uniforms:{uFWidth:0}}),K=tt.NORMAL_NPM);const P=new ef($,B);P.blendMode=K,F={index:0,indexCount:0,vertexCount:0,uvsCount:0,total:0,mesh:P,vertices:null,uvs:null,indices:null}}F.index=0,F.indexCount=0,F.vertexCount=0,F.uvsCount=0,F.total=0;const{_textureCache:G}=this;G[D]=G[D]||new q(b.baseTexture),F.mesh.texture=G[D],F.mesh.tint=this._tintColor.value,N.push(F),C[D]=F}C[D].total++}for(let E=0;E<S.length;E++)N.includes(S[E])||this.removeChild(S[E].mesh);for(let E=0;E<N.length;E++)N[E].mesh.parent!==this&&this.addChild(N[E].mesh);this._activePagesMeshData=N;for(const E in C){const b=C[E],D=b.total;if(!(((R=b.indices)==null?void 0:R.length)>6*D)||b.vertices.length<ef.BATCHABLE_SIZE*2)b.vertices=new Float32Array(4*2*D),b.uvs=new Float32Array(4*2*D),b.indices=new Uint16Array(6*D);else{const F=b.total,G=b.vertices;for(let $=F*4*2;$<G.length;$++)G[$]=0}b.mesh.size=6*D}for(let E=0;E<A;E++){const b=n[E];let D=b.position.x+I[b.line]*(this._align==="justify"?b.prevSpaces:1);this._roundPixels&&(D=Math.round(D));const F=D*i,G=b.position.y*i,$=b.texture,B=C[$.baseTexture.uid],K=$.frame,P=$._uvs,U=B.index++;B.indices[U*6+0]=0+U*4,B.indices[U*6+1]=1+U*4,B.indices[U*6+2]=2+U*4,B.indices[U*6+3]=0+U*4,B.indices[U*6+4]=2+U*4,B.indices[U*6+5]=3+U*4,B.vertices[U*8+0]=F,B.vertices[U*8+1]=G,B.vertices[U*8+2]=F+K.width*i,B.vertices[U*8+3]=G,B.vertices[U*8+4]=F+K.width*i,B.vertices[U*8+5]=G+K.height*i,B.vertices[U*8+6]=F,B.vertices[U*8+7]=G+K.height*i,B.uvs[U*8+0]=P.x0,B.uvs[U*8+1]=P.y0,B.uvs[U*8+2]=P.x1,B.uvs[U*8+3]=P.y1,B.uvs[U*8+4]=P.x2,B.uvs[U*8+5]=P.y2,B.uvs[U*8+6]=P.x3,B.uvs[U*8+7]=P.y3}this._textWidth=p*i,this._textHeight=(s.y+t.lineHeight)*i;for(const E in C){const b=C[E];if(this.anchor.x!==0||this.anchor.y!==0){let $=0;const B=this._textWidth*this.anchor.x,K=this._textHeight*this.anchor.y;for(let P=0;P<b.total;P++)b.vertices[$++]-=B,b.vertices[$++]-=K,b.vertices[$++]-=B,b.vertices[$++]-=K,b.vertices[$++]-=B,b.vertices[$++]-=K,b.vertices[$++]-=B,b.vertices[$++]-=K}this._maxLineHeight=g*i;const D=b.mesh.geometry.getBuffer("aVertexPosition"),F=b.mesh.geometry.getBuffer("aTextureCoord"),G=b.mesh.geometry.getIndex();D.data=b.vertices,F.data=b.uvs,G.data=b.indices,D.update(),F.update(),G.update()}for(let E=0;E<n.length;E++)xf.push(n[E]);this._font=t,this.dirty=!1}updateTransform(){this.validate(),this.containerUpdateTransform()}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0);const{distanceFieldRange:e,distanceFieldType:i,size:s}=Cr.available[this._fontName];if(i!=="none"){const{a:n,b:o,c:a,d:l}=this.worldTransform,h=Math.sqrt(n*n+o*o),c=Math.sqrt(a*a+l*l),u=(Math.abs(h)+Math.abs(c))/2,d=this.fontSize/s,f=t._view.resolution;for(const p of this._activePagesMeshData)p.mesh.shader.uniforms.uFWidth=u*e*d*f}super._render(t)}getLocalBounds(){return this.validate(),super.getLocalBounds()}validate(){const t=Cr.available[this._fontName];if(!t)throw new Error(`Missing BitmapFont "${this._fontName}"`);this._font!==t&&(this.dirty=!0),this.dirty&&this.updateText()}get tint(){return this._tintColor.value}set tint(t){if(this.tint!==t){this._tintColor.setValue(t);for(let e=0;e<this._activePagesMeshData.length;e++)this._activePagesMeshData[e].mesh.tint=t}}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.dirty=!0)}get fontName(){return this._fontName}set fontName(t){if(!Cr.available[t])throw new Error(`Missing BitmapFont "${t}"`);this._fontName!==t&&(this._fontName=t,this.dirty=!0)}get fontSize(){return this._fontSize??Cr.available[this._fontName].size}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.dirty=!0)}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get maxWidth(){return this._maxWidth}set maxWidth(t){this._maxWidth!==t&&(this._maxWidth=t,this.dirty=!0)}get maxLineHeight(){return this.validate(),this._maxLineHeight}get textWidth(){return this.validate(),this._textWidth}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.dirty=!0)}get roundPixels(){return this._roundPixels}set roundPixels(t){t!==this._roundPixels&&(this._roundPixels=t,this.dirty=!0)}get textHeight(){return this.validate(),this._textHeight}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}destroy(t){const{_textureCache:e}=this,i=Cr.available[this._fontName].distanceFieldType==="none"?_f:vf;i.push(...this._activePagesMeshData);for(const s of this._activePagesMeshData)this.removeChild(s.mesh);this._activePagesMeshData=[],i.filter(s=>e[s.mesh.texture.baseTexture.uid]).forEach(s=>{s.mesh.texture=q.EMPTY});for(const s in e)e[s].destroy(),delete e[s];this._font=null,this._tintColor=null,this._textureCache=null,super.destroy(t)}};Ew.styleDefaults={align:"left",tint:16777215,maxWidth:0,letterSpacing:0};const Tw=[".xml",".fnt"],Aw={extension:{type:X.LoadParser,priority:Ie.Normal},name:"loadBitmapFont",test(r){return Tw.includes(Gt.extname(r).toLowerCase())},async testParse(r){return Yn.test(r)||El.test(r)},async parse(r,t,e){const i=Yn.test(r)?Yn.parse(r):El.parse(r),{src:s}=t,{page:n}=i,o=[];for(let h=0;h<n.length;++h){const c=n[h].file;let u=Gt.join(Gt.dirname(s),c);u=ol(u,s),o.push(u)}const a=await e.load(o),l=o.map(h=>a[h]);return Cr.install(i,l,!0)},async load(r,t){return(await W.ADAPTER.fetch(r)).text()},unload(r){r.destroy()}};Y.add(Aw);const Al=class $i extends Sr{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new $i(Object.keys($i.defaultOptions).reduce((e,i)=>({...e,[i]:t[i]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete $i.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:i}=$i;if(i[t]){const s=i[t];return this._fonts.push(s),s.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return W.ADAPTER.fetch(t).then(s=>s.blob()).then(async s=>new Promise((n,o)=>{const a=URL.createObjectURL(s),l=new FileReader;l.onload=()=>n([a,l.result]),l.onerror=o,l.readAsDataURL(s)})).then(async([s,n])=>{const o=Object.assign({family:Gt.basename(t,Gt.extname(t)),weight:"normal",style:"normal",display:"auto",src:s,dataSrc:n,refs:1,originalUrl:t,fontFace:null},e);i[t]=o,this._fonts.push(o),this.styleID++;const a=new FontFace(o.family,`url(${o.src})`,{weight:o.weight,style:o.style,display:o.display});o.fontFace=a,await a.load(),document.fonts.add(a),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(i=>!this._overrides.includes(i));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(i=>this._overrides.includes(i));e.length>0&&(this._overrides=this._overrides.filter(i=>!e.includes(i)),this.styleID++)}toCSS(t){return[`transform: scale(${t})`,"transform-origin: top left","display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing}px`,`text-align: ${this.align}`,`padding: ${this.padding}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS()]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t}
1141
1141
  @font-face {
1142
1142
  font-family: "${e.family}";
1143
1143
  src: url('${e.dataSrc}');
1144
1144
  font-weight: ${e.weight};
1145
1145
  font-style: ${e.style};
1146
1146
  font-display: ${e.display};
1147
- }`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(t){this._stylesheet!==t&&(this._stylesheet=t,this.styleID++)}normalizeColor(t){return Array.isArray(t)&&(t=pv(t)),typeof t=="number"?fv(t):t}dropShadowToCSS(){let t=this.normalizeColor(this.dropShadowColor);const e=this.dropShadowAlpha,i=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),s=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);t.startsWith("#")&&e<1&&(t+=(e*255|0).toString(16).padStart(2,"0"));const n=`${i}px ${s}px`;return this.dropShadowBlur>0?`text-shadow: ${n} ${this.dropShadowBlur}px ${t}`:`text-shadow: ${n} ${t}`}reset(){Object.assign(this,$i.defaultOptions)}onBeforeDraw(){const{fontsDirty:t}=this;return this.fontsDirty=!1,this.isSafari&&this._fonts.length>0&&t?new Promise(e=>setTimeout(e,100)):Promise.resolve()}get isSafari(){const{userAgent:t}=W.ADAPTER.getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}set fillGradientStops(t){console.warn("[HTMLTextStyle] fillGradientStops is not supported by HTMLText")}get fillGradientStops(){return super.fillGradientStops}set fillGradientType(t){console.warn("[HTMLTextStyle] fillGradientType is not supported by HTMLText")}get fillGradientType(){return super.fillGradientType}set miterLimit(t){console.warn("[HTMLTextStyle] miterLimit is not supported by HTMLText")}get miterLimit(){return super.miterLimit}set trim(t){console.warn("[HTMLTextStyle] trim is not supported by HTMLText")}get trim(){return super.trim}set textBaseline(t){console.warn("[HTMLTextStyle] textBaseline is not supported by HTMLText")}get textBaseline(){return super.textBaseline}set leading(t){console.warn("[HTMLTextStyle] leading is not supported by HTMLText")}get leading(){return super.leading}set lineJoin(t){console.warn("[HTMLTextStyle] lineJoin is not supported by HTMLText")}get lineJoin(){return super.lineJoin}};Al.availableFonts={},Al.defaultOptions={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,padding:0,stroke:"black",strokeThickness:0,whiteSpace:"normal",wordWrap:!1,wordWrapWidth:100};let Sl=Al;const Kn=class Hi extends Pi{constructor(t="",e={}){super(q.EMPTY),this._text=null,this._style=null,this._autoResolution=!0,this.localStyleID=-1,this.dirty=!1,this._updateID=0,this.ownsStyle=!1;const i=new Image,s=q.from(i,{scaleMode:W.SCALE_MODE,resourceOptions:{autoLoad:!1}});s.orig=new at,s.trim=new at,this.texture=s;const n="http://www.w3.org/2000/svg",o="http://www.w3.org/1999/xhtml",a=document.createElementNS(n,"svg"),l=document.createElementNS(n,"foreignObject"),h=document.createElementNS(o,"div"),c=document.createElementNS(o,"style");l.setAttribute("width","10000"),l.setAttribute("height","10000"),l.style.overflow="hidden",a.appendChild(l),this.maxWidth=Hi.defaultMaxWidth,this.maxHeight=Hi.defaultMaxHeight,this._domElement=h,this._styleElement=c,this._svgRoot=a,this._foreignObject=l,this._foreignObject.appendChild(c),this._foreignObject.appendChild(h),this._image=i,this._loadImage=new Image,this._autoResolution=Hi.defaultAutoResolution,this._resolution=Hi.defaultResolution??W.RESOLUTION,this.text=t,this.style=e}measureText(t){var c,u;const{text:e,style:i,resolution:s}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:e,style:i.toCSS(s)}),this._styleElement.textContent=i.toGlobalCSS(),document.body.appendChild(this._svgRoot);const n=this._domElement.getBoundingClientRect();this._svgRoot.remove();const{width:o,height:a}=n;(o>this.maxWidth||a>this.maxHeight)&&console.warn("[HTMLText] Large expanse of text, increase HTMLText.maxWidth or HTMLText.maxHeight property.");const l=Math.min(this.maxWidth,Math.ceil(o)),h=Math.min(this.maxHeight,Math.ceil(a));return this._svgRoot.setAttribute("width",l.toString()),this._svgRoot.setAttribute("height",h.toString()),e!==this._text&&(this._domElement.innerHTML=this._text),i!==this._style&&(Object.assign(this._domElement,{style:(c=this._style)==null?void 0:c.toCSS(s)}),this._styleElement.textContent=(u=this._style)==null?void 0:u.toGlobalCSS()),{width:l+i.padding*2,height:h+i.padding*2}}async updateText(t=!0){const{style:e,_image:i,_loadImage:s}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:n,height:o}=this.measureText();i.width=s.width=Math.ceil(Math.max(1,n)),i.height=s.height=Math.ceil(Math.max(1,o)),this._updateID++;const a=this._updateID;await new Promise(l=>{s.onload=async()=>{if(a<this._updateID){l();return}await e.onBeforeDraw(),i.src=s.src,s.onload=null,s.src="",this.updateTexture(),l()};const h=new XMLSerializer().serializeToString(this._svgRoot);s.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(h)}`})}get source(){return this._image}updateTexture(){const{style:t,texture:e,_image:i,resolution:s}=this,{padding:n}=t,{baseTexture:o}=e;e.trim.width=e._frame.width=i.width/s,e.trim.height=e._frame.height=i.height/s,e.trim.x=-n,e.trim.y=-n,e.orig.width=e._frame.width-n*2,e.orig.height=e._frame.height-n*2,this._onTextureUpdate(),o.setRealSize(i.width,i.height,s),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}_renderCanvas(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._renderCanvas(t)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds(t)}_calculateBounds(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_onStyleChange(){this.dirty=!0}destroy(t){var i,s,n,o,a;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},Hi.defaultDestroyOptions,t),super.destroy(t);const e=null;this.ownsStyle&&((i=this._style)==null||i.cleanFonts()),this._style=e,(s=this._svgRoot)==null||s.remove(),this._svgRoot=e,(n=this._domElement)==null||n.remove(),this._domElement=e,(o=this._foreignObject)==null||o.remove(),this._foreignObject=e,(a=this._styleElement)==null||a.remove(),this._styleElement=e,this._loadImage.src="",this._loadImage.onload=null,this._loadImage=e,this._image.src="",this._image=e}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._image.width/this.resolution}set width(t){this.updateText(!0);const e=vr(this.scale.x)||1;this.scale.x=e*t/this._image.width/this.resolution,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._image.height/this.resolution}set height(t){this.updateText(!0);const e=vr(this.scale.y)||1;this.scale.y=e*t/this._image.height/this.resolution,this._height=t}get style(){return this._style}set style(t){this._style!==t&&(t=t||{},t instanceof Sl?(this.ownsStyle=!1,this._style=t):t instanceof Sr?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=Sl.from(t)):(this.ownsStyle=!0,this._style=new Sl(t)),this.localStyleID=-1,this.dirty=!0)}get text(){return this._text}set text(t){t=String(t===""||t===null||t===void 0?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}sanitiseText(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/&nbsp;/gi,"&#160;")}};Kn.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},Kn.defaultMaxWidth=2024,Kn.defaultMaxHeight=2024,Kn.defaultAutoResolution=!0;const Sw=16777215,Iw=.25,Cw=16777215,Rw=1.5;let Rr=!1,xs;const Il=r=>{const t={tint:r!=null&&r.fill?new bt(r.fill).toNumber():Sw,alpha:(r==null?void 0:r.fillOpacity)===void 0?Iw:Math.min(r.fillOpacity,1)},e={tint:r!=null&&r.stroke?new bt(r.stroke).toNumber():Cw,alpha:(r==null?void 0:r.strokeOpacity)===void 0?1:Math.min(r.strokeOpacity,1),lineWidth:(r==null?void 0:r.strokeWidth)===void 0?Rw:r.strokeWidth};return{fillStyle:t,strokeStyle:e}},Cl=r=>(t,e,i)=>{const{fillStyle:s,strokeStyle:n}=Il(i),o=new vs;o.beginFill(16777215),r(e,o),o.endFill(),o.tint=s.tint,o.alpha=s.alpha,t.addChild(o);const a=new vs,l=n.lineWidth===1?1:n.lineWidth/xs;return a.lineStyle(l,16777215,1,.5,n.lineWidth===1),r(e,a),a.tint=n.tint||16777215,a.alpha=n.alpha,t.addChild(a),{fill:o,stroke:a,strokeWidth:n.lineWidth}},Pw=Cl((r,t)=>{const{cx:e,cy:i,rx:s,ry:n}=r.geometry;t.drawEllipse(e,i,s,n)}),Mw=Cl((r,t)=>{const e=r.geometry.points.reduce((i,s)=>[...i,...s],[]);t.drawPolygon(e)}),Bw=Cl((r,t)=>{const{x:e,y:i,w:s,h:n}=r.geometry;t.drawRect(e,i,s,n)}),bf=r=>{const t=r.viewport.getContainerSize().x;return r.viewport.getZoom(!0)*t/r.world.getContentFactor()},wf=(r,t,e,i)=>()=>{const s=r.viewport.viewportToImageRectangle(r.viewport.getBounds(!0)),n=bf(r);(n!==xs||!Rr)&&(Rr=!0,e.forEach(({stroke:d,strokeWidth:f})=>{const{lineStyle:p}=d.geometry.graphicsData[0];f>1?(Rr=n===xs,p.width=f/n,p.native=!1,d.geometry.invalidate()):f===1&&!p.native&&(p.width=1,p.native=!0,d.geometry.invalidate())})),xs=n;const o=r.viewport.getFlip();let a=Math.PI*r.viewport.getRotation(!0)/180;a<0&&(a+=2*Math.PI),a>2*Math.PI&&(a-=2*Math.PI);const l=o?r.viewport._containerInnerSize.x+s.x*n:-s.x*n,h=-s.y*n;let c,u;a>0&&a<=Math.PI/2?(c=s.height*n,u=0):a>Math.PI/2&&a<=Math.PI?(c=s.width*n,u=s.height*n):a>Math.PI&&a<=Math.PI*1.5?(c=0,u=s.width*n):(c=0,u=0),t.position.x=c+l*Math.cos(a)-h*Math.sin(a),t.position.y=u+l*Math.sin(a)+h*Math.cos(a),t.scale.set(o?-n:n,n),t.rotation=a,i.render(t)},Dw=(r,t)=>{const e=new vs,i=yd({width:t.width,height:t.height,backgroundAlpha:0,view:t,antialias:!0,resolution:2}),s=new Map;let n=new Set,o,a;xs=bf(r);const l=(g,v)=>{Rr=!1;const{selector:w}=g.target,I=typeof a=="function"?a(g,v):a;let A;w.type===wt.RECTANGLE?A=Bw(e,w,I):w.type===wt.POLYGON?A=Mw(e,w,I):w.type===wt.ELLIPSE?A=Pw(e,w,I):console.warn(`Unsupported shape type: ${w.type}`),A&&s.set(g.id,{annotation:g,...A})},h=g=>{const v=s.get(g.id);v&&(s.delete(g.id),v.fill.destroy(),v.stroke.destroy())},c=(g,v,w)=>{Rr=!1;const I=s.get(g.id);I&&(s.delete(g.id),I.fill.destroy(),I.stroke.destroy(),l(v,w))},u=(g,v)=>{const w=s.get(g);w&&(s.delete(g),w.fill.destroy(),w.stroke.destroy(),l(w.annotation,v))},d=(g,v)=>{i.resize(g,v),i.render(e)},f=g=>{Rr=!1;const{children:v}=e;s.forEach(({fill:w,stroke:I,annotation:A})=>{const C=g?n.has(A.id)||g(A):!0;C&&!v.includes(w)?(e.addChild(w),e.addChild(I)):!C&&v.includes(w)&&(e.removeChild(w),e.removeChild(I))}),i.render(e)},p=g=>{o!==g&&(o&&u(o,{selected:n.has(o)}),g&&u(g,{selected:n.has(g),hovered:!0}),o=g,i.render(e))},m=g=>{const v=g.selected.map(A=>A.id),w=v.filter(A=>!n.has(A)),I=[...n].filter(A=>!v.includes(A));[...w,...I].forEach(A=>u(A,{selected:v.includes(A),hovered:A===o})),n=new Set(v),i.render(e)},_=g=>{if(typeof g=="function")s.forEach(({annotation:v,fill:w,stroke:I,strokeWidth:A},C)=>{A>1&&(Rr=!1);const N={selected:n.has(v.id),hovered:o===v.id},{fillStyle:S,strokeStyle:R}=Il(g(v,N));w.tint=S.tint,w.alpha=S.alpha,I.tint=R.tint||16777215,I.alpha=R.alpha,s.set(v.id,{annotation:v,fill:w,stroke:I,strokeWidth:R.lineWidth})});else{const{fillStyle:v,strokeStyle:w}=Il(g);w.lineWidth>1&&(Rr=!1),s.forEach(({annotation:I,fill:A,stroke:C,strokeWidth:N},S)=>{A.tint=v.tint,A.alpha=v.alpha,C.tint=w.tint||16777215,C.alpha=w.alpha,s.set(I.id,{annotation:I,fill:A,stroke:C,strokeWidth:w.lineWidth})})}a=g,i.render(e),wf(r,e,s,i)()},y=g=>{g?t.classList.remove("hidden"):t.classList.add("hidden")};return{addAnnotation:l,destroy:()=>i.destroy(),redraw:wf(r,e,s,i),removeAnnotation:h,resize:d,setFilter:f,setHovered:p,setSelected:m,setStyle:_,setVisible:y,updateAnnotation:c}};function Ow(r,t,e){let i,s,{filter:n}=t,{state:o}=t,{style:a}=t,{viewer:l}=t,{visible:h=!0}=t;const{store:c,hover:u,selection:d,viewport:f}=o;Ro(r,u,I=>e(11,i=I)),Ro(r,d,I=>e(8,s=I));const p=Hs();let m,_;const y=I=>{const A=new Nt.Point(I.x,I.y),{x:C,y:N}=l.viewport.pointFromPixel(A);return l.viewport.viewportToImageCoordinates(C,N)},x=I=>{const{x:A,y:C}=I.position;_={x:A,y:C}},g=I=>A=>{const{x:C,y:N}=y(new Nt.Point(A.offsetX,A.offsetY)),S=c.getAt(C,N);S&&(!n||n(S))?(I.classList.add("hover"),i!==S.id&&(u.set(S.id),m.setHovered(S.id))):(I.classList.remove("hover"),i&&(u.set(void 0),m.setHovered(void 0)))},v=I=>{if(!_)return;const A=I.originalEvent,{x:C,y:N}=I.position,S=C-_.x,R=N-_.y;if(Math.sqrt(S*S+R*R)<5){const{x:b,y:D}=y(I.position),F=c.getAt(b,D);F?p("click",{originalEvent:A,annotation:F}):p("click",{originalEvent:A})}_=void 0};let w;return $s(()=>{var F;const{offsetWidth:I,offsetHeight:A}=l.canvas,C=document.createElement("canvas");C.width=I,C.height=A,C.className="a9s-gl-canvas",(F=l.element.querySelector(".openseadragon-canvas"))==null||F.appendChild(C),e(7,m=Dw(l,C));const N=g(C);C.addEventListener("pointermove",N);const S=new ResizeObserver(G=>{try{const{width:$,height:B}=G[0].contentRect;C.width=$,C.height=B,m.resize($,B)}catch{console.warn("WebGL canvas already disposed")}});S.observe(C);const R=()=>{const G=l.viewport.getBounds();w=l.viewport.viewportToImageRectangle(G);const{x:$,y:B,width:Z,height:P}=w,U=c.getIntersecting($,B,Z,P);f.set(U.map(j=>j.id))};l.addHandler("canvas-press",x),l.addHandler("canvas-release",v),l.addHandler("update-viewport",m.redraw),l.addHandler("animation-finish",R);const E=G=>G.filter($=>Je($)),b=G=>Je(G.oldValue)&&Je(G.newValue),D=G=>{const{created:$,updated:B,deleted:Z}=G.changes;if(E($||[]).forEach(P=>m.addAnnotation(P)),E(Z||[]).forEach(P=>m.removeAnnotation(P)),(B||[]).filter(P=>b(P)).forEach(({oldValue:P,newValue:U})=>m.updateAnnotation(P,U)),w){const{x:P,y:U,width:j,height:rt}=w,Q=c.getIntersecting(P,U,j,rt);f.set(Q.map(H=>H.id))}else f.set(c.all().map(P=>P.id));m.redraw()};return c.observe(D),()=>{var G;C.removeEventListener("pointermove",N),S.disconnect(),l.removeHandler("canvas-press",x),l.removeHandler("canvas-release",v),l.removeHandler("update-viewport",m.redraw),l.removeHandler("animation-finish",R),c.unobserve(D),m.destroy(),(G=C.parentNode)==null||G.removeChild(C)}}),r.$$set=I=>{"filter"in I&&e(2,n=I.filter),"state"in I&&e(3,o=I.state),"style"in I&&e(4,a=I.style),"viewer"in I&&e(5,l=I.viewer),"visible"in I&&e(6,h=I.visible)},r.$$.update=()=>{r.$$.dirty&132&&(m==null||m.setFilter(n)),r.$$.dirty&384&&(m==null||m.setSelected(s)),r.$$.dirty&144&&(m==null||m.setStyle(a)),r.$$.dirty&192&&(m==null||m.setVisible(h))},[u,d,n,o,a,l,h,m,s]}class Fw extends ae{constructor(t){super(),oe(this,t,Ow,null,te,{filter:2,state:3,style:4,viewer:5,visible:6})}}const Yt=[];for(let r=0;r<256;++r)Yt.push((r+256).toString(16).slice(1));function Lw(r,t=0){return(Yt[r[t+0]]+Yt[r[t+1]]+Yt[r[t+2]]+Yt[r[t+3]]+"-"+Yt[r[t+4]]+Yt[r[t+5]]+"-"+Yt[r[t+6]]+Yt[r[t+7]]+"-"+Yt[r[t+8]]+Yt[r[t+9]]+"-"+Yt[r[t+10]]+Yt[r[t+11]]+Yt[r[t+12]]+Yt[r[t+13]]+Yt[r[t+14]]+Yt[r[t+15]]).toLowerCase()}let Rl;const Nw=new Uint8Array(16);function Uw(){if(!Rl){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Rl=crypto.getRandomValues.bind(crypto)}return Rl(Nw)}const Ef={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function kw(r,t,e){if(Ef.randomUUID&&!t&&!r)return Ef.randomUUID();r=r||{};const i=r.random||(r.rng||Uw)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Lw(i)}var Ui=(r=>(r.ELLIPSE="ELLIPSE",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(Ui||{});const Pl=(r,t)=>t,Gw=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}},$w={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),c=t-i,u=e-s,d=l*c+h*u,f=h*c-l*u;return d*d/(n*n)+f*f/(o*o)<=1}};Pl(Ui.ELLIPSE,$w);const Hw={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],c=i[o][1];l>e!=c>e&&t<(h-a)*(e-l)/(c-l)+a&&(s=!s)}return s}};Pl(Ui.POLYGON,Hw);const Xw={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};Pl(Ui.RECTANGLE,Xw);function Tf(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function Af(r){let t,e;return t=new bs({props:{x:r[10][0],y:r[10][1],scale:r[3]}}),t.$on("pointerdown",function(){Kt(r[9](`HANDLE-${r[12]}`))&&r[9](`HANDLE-${r[12]}`).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,s){Zt(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||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Vw(r){let t,e,i,s,n,o,a,l,h,c,u,d=ui(r[4].points),f=[];for(let m=0;m<d.length;m+=1)f[m]=Af(Tf(r,d,m));const p=m=>ut(f[m],1,1,()=>{f[m]=null});return{c(){t=Tt("polygon"),s=xe(),n=Tt("polygon"),a=xe();for(let m=0;m<f.length;m+=1)f[m].c();l=er(),M(t,"class","a9s-outer"),M(t,"style",e=r[1]?"display:none;":void 0),M(t,"points",i=r[4].points.map(Sf).join(" ")),M(n,"class","a9s-inner a9s-shape-handle"),M(n,"style",r[1]),M(n,"points",o=r[4].points.map(If).join(" "))},m(m,_){ft(m,t,_),ft(m,s,_),ft(m,n,_),ft(m,a,_);for(let y=0;y<f.length;y+=1)f[y]&&f[y].m(m,_);ft(m,l,_),h=!0,c||(u=[zt(t,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),zt(n,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],c=!0)},p(m,_){if(r=m,(!h||_&2&&e!==(e=r[1]?"display:none;":void 0))&&M(t,"style",e),(!h||_&16&&i!==(i=r[4].points.map(Sf).join(" ")))&&M(t,"points",i),(!h||_&2)&&M(n,"style",r[1]),(!h||_&16&&o!==(o=r[4].points.map(If).join(" ")))&&M(n,"points",o),_&536){d=ui(r[4].points);let y;for(y=0;y<d.length;y+=1){const x=Tf(r,d,y);f[y]?(f[y].p(x,_),st(f[y],1)):(f[y]=Af(x),f[y].c(),st(f[y],1),f[y].m(l.parentNode,l))}for(De(),y=d.length;y<f.length;y+=1)p(y);Oe()}},i(m){if(!h){for(let _=0;_<d.length;_+=1)st(f[_]);h=!0}},o(m){f=f.filter(Boolean);for(let _=0;_<f.length;_+=1)ut(f[_]);h=!1},d(m){m&&(ct(t),ct(s),ct(n),ct(a),ct(l)),Po(f,m),c=!1,Qe(u)}}}function zw(r){let t,e;return t=new Rf({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Vw,({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(){ee(t.$$.fragment)},m(i,s){Zt(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||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const Sf=r=>r.join(","),If=r=>r.join(",");function Ww(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{let m;const _=d.geometry;f==="SHAPE"?m=_.points.map(([x,g])=>[x+p[0],g+p[1]]):m=_.points.map(([x,g],v)=>f===`HANDLE-${v}`?[x+p[0],g+p[1]]:[x,g]);const y=Gw(m);return{...d,geometry:{points:m,bounds:y}}};function h(d){rr.call(this,r,d)}function c(d){rr.call(this,r,d)}function u(d){rr.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,c,u]}class jw extends ae{constructor(t){super(),oe(this,t,Ww,zw,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const Yw=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function qw(r){let t,e,i,s,n,o;return{c(){t=Tt("rect"),M(t,"class",e=ks(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),M(t,"x",i=r[0]-r[5]/2),M(t,"y",s=r[1]-r[5]/2),M(t,"width",r[5]),M(t,"height",r[5])},m(a,l){ft(a,t,l),n||(o=zt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=ks(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&M(t,"class",e),l&33&&i!==(i=a[0]-a[5]/2)&&M(t,"x",i),l&34&&s!==(s=a[1]-a[5]/2)&&M(t,"y",s),l&32&&M(t,"width",a[5]),l&32&&M(t,"height",a[5])},d(a){a&&ct(t),n=!1,o()}}}function Kw(r){let t,e,i,s,n,o,a,l,h;return{c(){t=Tt("g"),e=Tt("circle"),s=Tt("rect"),M(e,"cx",r[0]),M(e,"cy",r[1]),M(e,"r",i=r[3]/r[2]),M(e,"class","a9s-touch-halo svelte-1sgkh33"),Gs(e,"touched",r[4]),M(s,"class",n=ks(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),M(s,"x",o=r[0]-r[5]/2),M(s,"y",a=r[1]-r[5]/2),M(s,"width",r[5]),M(s,"height",r[5]),M(t,"class","a9s-touch-handle")},m(c,u){ft(c,t,u),tr(t,e),tr(t,s),l||(h=[zt(e,"pointerdown",r[10]),zt(e,"pointerdown",r[6]),zt(e,"pointerup",r[7]),zt(s,"pointerdown",r[9]),zt(s,"pointerdown",r[6]),zt(s,"pointerup",r[7])],l=!0)},p(c,u){u&1&&M(e,"cx",c[0]),u&2&&M(e,"cy",c[1]),u&12&&i!==(i=c[3]/c[2])&&M(e,"r",i),u&16&&Gs(e,"touched",c[4]),u&256&&n!==(n=ks(`a9s-handle ${c[8].class||""}`.trim())+" svelte-1sgkh33")&&M(s,"class",n),u&33&&o!==(o=c[0]-c[5]/2)&&M(s,"x",o),u&34&&a!==(a=c[1]-c[5]/2)&&M(s,"y",a),u&32&&M(s,"width",c[5]),u&32&&M(s,"height",c[5])},d(c){c&&ct(t),l=!1,Qe(h)}}}function Zw(r){let t;function e(n,o){return Yw?Kw:qw}let s=e()(r);return{c(){s.c(),t=er()},m(n,o){s.m(n,o),ft(n,t,o)},p(n,[o]){s.p(n,o)},i:Be,o:Be,d(n){n&&ct(t),s.d(n)}}}function Jw(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{radius:a=30}=t,l=!1;const h=p=>{p.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(p){rr.call(this,r,p)}function d(p){rr.call(this,r,p)}function f(p){rr.call(this,r,p)}return r.$$set=p=>{e(8,t=Co(Co({},t),Wh(p))),"x"in p&&e(0,s=p.x),"y"in p&&e(1,n=p.y),"scale"in p&&e(2,o=p.scale),"radius"in p&&e(3,a=p.radius)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=10/o)},t=Wh(t),[s,n,o,a,l,i,h,c,t,u,d,f]}class bs extends ae{constructor(t){super(),oe(this,t,Jw,Zw,te,{x:0,y:1,scale:2,radius:3})}}function Qw(r){let t,e,i,s,n,o,a,l,h,c,u,d,f,p,m,_,y,x,g,v,w,I,A,C,N,S,R,E,b,D,F,G,$,B,Z,P,U,j,rt,Q,H,V,lt;return B=new bs({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),B.$on("pointerdown",function(){Kt(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),P=new bs({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),P.$on("pointerdown",function(){Kt(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),j=new bs({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),j.$on("pointerdown",function(){Kt(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Q=new bs({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Q.$on("pointerdown",function(){Kt(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=Tt("rect"),a=xe(),l=Tt("rect"),f=xe(),p=Tt("rect"),x=xe(),g=Tt("rect"),A=xe(),C=Tt("rect"),E=xe(),b=Tt("rect"),$=xe(),ee(B.$$.fragment),Z=xe(),ee(P.$$.fragment),U=xe(),ee(j.$$.fragment),rt=xe(),ee(Q.$$.fragment),M(t,"class","a9s-outer"),M(t,"style",e=r[1]?"display:none;":void 0),M(t,"x",i=r[4].x),M(t,"y",s=r[4].y),M(t,"width",n=r[4].w),M(t,"height",o=r[4].h),M(l,"class","a9s-inner a9s-shape-handle"),M(l,"style",r[1]),M(l,"x",h=r[4].x),M(l,"y",c=r[4].y),M(l,"width",u=r[4].w),M(l,"height",d=r[4].h),M(p,"class","a9s-edge-handle a9s-edge-handle-top"),M(p,"x",m=r[4].x),M(p,"y",_=r[4].y),M(p,"height",1),M(p,"width",y=r[4].w),M(g,"class","a9s-edge-handle a9s-edge-handle-right"),M(g,"x",v=r[4].x+r[4].w),M(g,"y",w=r[4].y),M(g,"height",I=r[4].h),M(g,"width",1),M(C,"class","a9s-edge-handle a9s-edge-handle-bottom"),M(C,"x",N=r[4].x),M(C,"y",S=r[4].y+r[4].h),M(C,"height",1),M(C,"width",R=r[4].w),M(b,"class","a9s-edge-handle a9s-edge-handle-left"),M(b,"x",D=r[4].x),M(b,"y",F=r[4].y),M(b,"height",G=r[4].h),M(b,"width",1)},m(L,O){ft(L,t,O),ft(L,a,O),ft(L,l,O),ft(L,f,O),ft(L,p,O),ft(L,x,O),ft(L,g,O),ft(L,A,O),ft(L,C,O),ft(L,E,O),ft(L,b,O),ft(L,$,O),Zt(B,L,O),ft(L,Z,O),Zt(P,L,O),ft(L,U,O),Zt(j,L,O),ft(L,rt,O),Zt(Q,L,O),H=!0,V||(lt=[zt(t,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),zt(l,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),zt(p,"pointerdown",function(){Kt(r[9]("TOP"))&&r[9]("TOP").apply(this,arguments)}),zt(g,"pointerdown",function(){Kt(r[9]("RIGHT"))&&r[9]("RIGHT").apply(this,arguments)}),zt(C,"pointerdown",function(){Kt(r[9]("BOTTOM"))&&r[9]("BOTTOM").apply(this,arguments)}),zt(b,"pointerdown",function(){Kt(r[9]("LEFT"))&&r[9]("LEFT").apply(this,arguments)})],V=!0)},p(L,O){r=L,(!H||O&2&&e!==(e=r[1]?"display:none;":void 0))&&M(t,"style",e),(!H||O&16&&i!==(i=r[4].x))&&M(t,"x",i),(!H||O&16&&s!==(s=r[4].y))&&M(t,"y",s),(!H||O&16&&n!==(n=r[4].w))&&M(t,"width",n),(!H||O&16&&o!==(o=r[4].h))&&M(t,"height",o),(!H||O&2)&&M(l,"style",r[1]),(!H||O&16&&h!==(h=r[4].x))&&M(l,"x",h),(!H||O&16&&c!==(c=r[4].y))&&M(l,"y",c),(!H||O&16&&u!==(u=r[4].w))&&M(l,"width",u),(!H||O&16&&d!==(d=r[4].h))&&M(l,"height",d),(!H||O&16&&m!==(m=r[4].x))&&M(p,"x",m),(!H||O&16&&_!==(_=r[4].y))&&M(p,"y",_),(!H||O&16&&y!==(y=r[4].w))&&M(p,"width",y),(!H||O&16&&v!==(v=r[4].x+r[4].w))&&M(g,"x",v),(!H||O&16&&w!==(w=r[4].y))&&M(g,"y",w),(!H||O&16&&I!==(I=r[4].h))&&M(g,"height",I),(!H||O&16&&N!==(N=r[4].x))&&M(C,"x",N),(!H||O&16&&S!==(S=r[4].y+r[4].h))&&M(C,"y",S),(!H||O&16&&R!==(R=r[4].w))&&M(C,"width",R),(!H||O&16&&D!==(D=r[4].x))&&M(b,"x",D),(!H||O&16&&F!==(F=r[4].y))&&M(b,"y",F),(!H||O&16&&G!==(G=r[4].h))&&M(b,"height",G);const _t={};O&16&&(_t.x=r[4].x),O&16&&(_t.y=r[4].y),O&8&&(_t.scale=r[3]),B.$set(_t);const ht={};O&16&&(ht.x=r[4].x+r[4].w),O&16&&(ht.y=r[4].y),O&8&&(ht.scale=r[3]),P.$set(ht);const vt={};O&16&&(vt.x=r[4].x+r[4].w),O&16&&(vt.y=r[4].y+r[4].h),O&8&&(vt.scale=r[3]),j.$set(vt);const xt={};O&16&&(xt.x=r[4].x),O&16&&(xt.y=r[4].y+r[4].h),O&8&&(xt.scale=r[3]),Q.$set(xt)},i(L){H||(st(B.$$.fragment,L),st(P.$$.fragment,L),st(j.$$.fragment,L),st(Q.$$.fragment,L),H=!0)},o(L){ut(B.$$.fragment,L),ut(P.$$.fragment,L),ut(j.$$.fragment,L),ut(Q.$$.fragment,L),H=!1},d(L){L&&(ct(t),ct(a),ct(l),ct(f),ct(p),ct(x),ct(g),ct(A),ct(C),ct(E),ct(b),ct($),ct(Z),ct(U),ct(rt)),Jt(B,L),Jt(P,L),Jt(j,L),Jt(Q,L),V=!1,Qe(lt)}}}function tE(r){let t,e;return t=new Rf({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Qw,({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(){ee(t.$$.fragment)},m(i,s){Zt(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||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function eE(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{const m=d.geometry.bounds;let[_,y]=[m.minX,m.minY],[x,g]=[m.maxX,m.maxY];const[v,w]=p;if(f==="SHAPE")_+=v,x+=v,y+=w,g+=w;else{switch(f){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{y+=w;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=w;break}}switch(f){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{_+=v;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{x+=v;break}}}const I=Math.min(_,x),A=Math.min(y,g),C=Math.abs(x-_),N=Math.abs(g-y);return{...d,geometry:{x:I,y:A,w:C,h:N,bounds:{minX:I,minY:A,maxX:I+C,maxY:A+N}}}};function h(d){rr.call(this,r,d)}function c(d){rr.call(this,r,d)}function u(d){rr.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,c,u]}class rE extends ae{constructor(t){super(),oe(this,t,eE,tE,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}Ui.RECTANGLE,Ui.POLYGON;const iE=r=>({}),Cf=r=>({grab:r[0]});function sE(r){let t,e,i,s;const n=r[7].default,o=$h(n,r,r[6],Cf);return{c(){t=Tt("g"),o&&o.c(),M(t,"class","a9s-annotation selected")},m(a,l){ft(a,t,l),o&&o.m(t,null),e=!0,i||(s=[zt(t,"pointerup",r[2]),zt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&64)&&Vh(o,n,a,a[6],e?Xh(n,a[6],l,iE):zh(a[6]),Cf)},i(a){e||(st(o,a),e=!0)},o(a){ut(o,a),e=!1},d(a){a&&ct(t),o&&o.d(a),i=!1,Qe(s)}}}function nE(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Hs();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,c,u;const d=m=>_=>{h=m,c=l.elementToImage(_.offsetX,_.offsetY),u=o,_.target.setPointerCapture(_.pointerId),n("grab",_)},f=m=>{if(h){const[_,y]=l.elementToImage(m.offsetX,m.offsetY),x=[_-c[0],y-c[1]];e(3,o=a(u,h,x)),n("change",o)}},p=m=>{m.target.releasePointerCapture(m.pointerId),h=void 0,u=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,f,p,o,a,l,s,i]}class Rf extends ae{constructor(t){super(),oe(this,t,nE,sE,te,{shape:3,editor:4,transform:5})}}const oE=(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 aE(r,t,e){let i;const s=Hs();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return $s(()=>(e(6,u=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:c}})),u.$on("change",d=>{u.$$set({shape:d.detail}),s("change",d.detail)}),u.$on("grab",d=>s("grab",d.detail)),u.$on("release",d=>s("release",d.detail)),()=>{u.$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,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=oE(n,a)),r.$$.dirty&65&&n&&(u==null||u.$set({shape:n.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[n,o,a,l,h,c,u,i]}class lE extends ae{constructor(t){super(),oe(this,t,aE,null,te,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1;const hE=r=>({transform:r&2,scale:r&1}),Pf=r=>({transform:r[1],scale:r[0]});function cE(r){let t;const e=r[4].default,i=$h(e,r,r[3],Pf);return{c(){i&&i.c()},m(s,n){i&&i.m(s,n),t=!0},p(s,[n]){i&&i.p&&(!t||n&11)&&Vh(i,e,s,s[3],t?Xh(e,s[3],n,hE):zh(s[3]),Pf)},i(s){t||(st(i,s),t=!0)},o(s){ut(i,s),t=!1},d(s){i&&i.d(s)}}}function uE(r,t,e){let{$$slots:i={},$$scope:s}=t,{viewer:n}=t,o=1,a;const l=()=>{const h=n.viewport.getContainerSize().x,c=n.viewport.getZoom(!0),u=n.viewport.getFlip(),d=n.viewport.pixelFromPoint(new Nt.Point(0,0),!0);u&&(d.x=h-d.x);const f=c*h/n.world.getContentFactor(),p=u?-f:f,m=n.viewport.getRotation(!0);e(1,a=`translate(${d.x}, ${d.y}) scale(${p}, ${f}) rotate(${m})`),e(0,o=c*h/n.world.getContentFactor())};return $s(()=>(n.addHandler("update-viewport",l),()=>{n.removeHandler("update-viewport",l)})),r.$$set=h=>{"viewer"in h&&e(2,n=h.viewer),"$$scope"in h&&e(3,s=h.$$scope)},[o,a,n,s,i]}class Mf extends ae{constructor(t){super(),oe(this,t,uE,cE,te,{viewer:2})}}function dE(r,t,e){const i=Hs();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewer:l}=t,{viewportScale:h}=t,c;return $s(()=>{const u=n.closest("svg"),d=[],f=(p,m,_)=>{if(u==null||u.addEventListener(p,m,_),d.push(()=>u==null?void 0:u.removeEventListener(p,m,_)),p==="pointerup"||p==="dblclick"){const y=g=>{const{originalEvent:v}=g;m(v)},x=p==="pointerup"?"canvas-click":"canvas-double-click";l.addHandler(x,y),d.push(()=>l.removeHandler(x,y))}else if(p==="pointermove"){const y=x=>{const{originalEvent:g}=x;m(g)};l.addHandler("canvas-drag",y),d.push(()=>l.removeHandler("canvas-drag",y))}};return e(6,c=new o({target:n,props:{addEventListener:f,drawingMode:s,transform:a,viewportScale:h}})),c.$on("create",p=>i("create",p.detail)),()=>{d.forEach(p=>p()),c.$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),"viewer"in u&&e(4,l=u.viewer),"viewportScale"in u&&e(5,h=u.viewportScale)},r.$$.update=()=>{r.$$.dirty&72&&c&&c.$set({transform:a}),r.$$.dirty&96&&c&&c.$set({viewportScale:h})},[s,n,o,a,l,h,c]}class fE extends ae{constructor(t){super(),oe(this,t,dE,null,te,{drawingMode:0,target:1,tool:2,transform:3,viewer:4,viewportScale:5})}}function Bf(r,t,e){const i=r.slice();i[33]=t[e];const s=i[14](i[33].target.selector);return i[34]=s,i}function pE(r){let t=r[2],e,i,s=Df(r);return{c(){s.c(),e=er()},m(n,o){s.m(n,o),ft(n,e,o),i=!0},p(n,o){o[0]&4&&te(t,t=n[2])?(De(),ut(s,1,1,Be),Oe(),s=Df(n),s.c(),st(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(st(s),i=!0)},o(n){ut(s),i=!1},d(n){n&&ct(e),s.d(n)}}}function mE(r){let t,e,i=ui(r[6].filter(r[23])),s=[];for(let o=0;o<i.length;o+=1)s[o]=Lf(Bf(r,i,o));const n=o=>ut(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=er()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ft(o,t,a),e=!0},p(o,a){if(a[0]&24162|a[1]&2){i=ui(o[6].filter(o[23]));let l;for(l=0;l<i.length;l+=1){const h=Bf(o,i,l);s[l]?(s[l].p(h,a),st(s[l],1)):(s[l]=Lf(h),s[l].c(),st(s[l],1),s[l].m(t.parentNode,t))}for(De(),l=i.length;l<s.length;l+=1)n(l);Oe()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)st(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)ut(s[a]);e=!1},d(o){o&&ct(t),Po(s,o)}}}function Df(r){let t,e;return t=new fE({props:{target:r[5],tool:r[7],drawingMode:r[4],transform:{elementToImage:r[9]},viewer:r[3],viewportScale:r[32]}}),t.$on("create",r[13]),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s[0]&32&&(n.target=i[5]),s[0]&128&&(n.tool=i[7]),s[0]&16&&(n.drawingMode=i[4]),s[0]&8&&(n.viewer=i[3]),s[1]&2&&(n.viewportScale=i[32]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Of(r){let t=r[33].id,e,i,s=Ff(r);return{c(){s.c(),e=er()},m(n,o){s.m(n,o),ft(n,e,o),i=!0},p(n,o){o[0]&64&&te(t,t=n[33].id)?(De(),ut(s,1,1,Be),Oe(),s=Ff(n),s.c(),st(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(st(s),i=!0)},o(n){ut(s),i=!1},d(n){n&&ct(e),s.d(n)}}}function Ff(r){let t,e;return t=new lE({props:{target:r[5],editor:r[14](r[33].target.selector),annotation:r[33],style:r[1],transform:{elementToImage:r[9]},viewportScale:r[32]}}),t.$on("grab",r[10]),t.$on("change",function(){Kt(r[12](r[33]))&&r[12](r[33]).apply(this,arguments)}),t.$on("release",r[11]),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&32&&(n.target=r[5]),s[0]&64&&(n.editor=r[14](r[33].target.selector)),s[0]&64&&(n.annotation=r[33]),s[0]&2&&(n.style=r[1]),s[1]&2&&(n.viewportScale=r[32]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Lf(r){let t,e,i=r[34]&&Of(r);return{c(){i&&i.c(),t=er()},m(s,n){i&&i.m(s,n),ft(s,t,n),e=!0},p(s,n){s[34]?i?(i.p(s,n),n[0]&64&&st(i,1)):(i=Of(s),i.c(),st(i,1),i.m(t.parentNode,t)):i&&(De(),ut(i,1,1,()=>{i=null}),Oe())},i(s){e||(st(i),e=!0)},o(s){ut(i),e=!1},d(s){s&&ct(t),i&&i.d(s)}}}function gE(r){let t,e,i,s,n,o;const a=[mE,pE],l=[];function h(c,u){return c[5]&&c[6]?0:c[5]&&c[7]&&c[0]?1:-1}return~(i=h(r))&&(s=l[i]=a[i](r)),{c(){t=Tt("svg"),e=Tt("g"),s&&s.c(),M(e,"transform",n=r[31]),M(e,"class","svelte-190cqdf"),M(t,"class","a9s-annotationlayer a9s-osd-drawinglayer svelte-190cqdf"),Gs(t,"drawing",r[0])},m(c,u){ft(c,t,u),tr(t,e),~i&&l[i].m(e,null),r[24](e),o=!0},p(c,u){let d=i;i=h(c),i===d?~i&&l[i].p(c,u):(s&&(De(),ut(l[d],1,1,()=>{l[d]=null}),Oe()),~i?(s=l[i],s?s.p(c,u):(s=l[i]=a[i](c),s.c()),st(s,1),s.m(e,null)):s=null),(!o||u[1]&1&&n!==(n=c[31]))&&M(e,"transform",n),(!o||u[0]&1)&&Gs(t,"drawing",c[0])},i(c){o||(st(s),o=!0)},o(c){ut(s),o=!1},d(c){c&&ct(t),~i&&l[i].d(),r[24](null)}}}function yE(r){let t,e;return t=new Mf({props:{viewer:r[3],$$slots:{default:[gE,({transform:i,scale:s})=>({31:i,32:s}),({transform:i,scale:s})=>[0,(i?1:0)|(s?2:0)]]},$$scope:{ctx:r}}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s[0]&8&&(n.viewer=i[3]),s[0]&255|s[1]&67&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function _E(r,t,e){let i,s,n,o,{drawingEnabled:a}=t,{filter:l}=t,{preferredDrawingMode:h}=t,{state:c}=t,{style:u=void 0}=t,{toolName:d=Fs()[0]}=t,{user:f}=t,{viewer:p}=t;const m=()=>d,_=()=>a,y=navigator.userAgent.match(/firefox|fxios/i);let x;const{store:g,selection:v,hover:w}=c;Ro(r,v,B=>e(22,o=B));let I,A,C;const N=B=>{g.unobserve(I);const Z=B.filter(({editable:P})=>P).map(({id:P})=>P);if(Z.length>0){if(e(6,A=Z.map(P=>g.getAnnotation(P))),I=P=>{const{updated:U}=P.changes;e(6,A=(U||[]).map(j=>j.newValue))},g.observe(I,{annotations:Z}),y){const{width:P}=p.viewport.viewerElementToViewportRectangle(new Nt.Rect(0,0,1,1));p.viewport.panBy(new Nt.Point(Math.abs(P/10),0))}}else e(6,A=void 0)},S=(B,Z)=>{const{x:P,y:U}=p.viewport.viewerElementToImageCoordinates(new Nt.Point(B,Z));return[P,U]},R=B=>{p.setMouseNavEnabled(!1),C=B.timeStamp},E=B=>{if(p.setMouseNavEnabled(!0),performance.now()-(C||0)<300){const{offsetX:P,offsetY:U}=B.detail,[j,rt]=S(P,U),Q=g.getAt(j,rt);Q&&(!l||l(Q))&&!A.find(V=>V.id===Q.id)&&(w.set(Q.id),v.setSelected(Q.id))}},b=B=>Z=>{var rt;const{target:P}=B,U=10*60*1e3,j=((rt=P.creator)==null?void 0:rt.id)!==f.id||!P.created||new Date().getTime()-P.created.getTime()>U;g.updateTarget({...P,selector:Z.detail,created:j?P.created:new Date,updated:j?new Date:void 0,updatedBy:j?f:void 0})},D=B=>{const Z=kw(),P={id:Z,bodies:[],target:{annotation:Z,selector:B.detail,creator:f,created:new Date}};g.addAnnotation(P),v.setSelected(P.id),p.setMouseNavEnabled(!0)},F=B=>dh(B),G=B=>Je(B);function $(B){Xs[B?"unshift":"push"](()=>{x=B,e(5,x)})}return r.$$set=B=>{"drawingEnabled"in B&&e(0,a=B.drawingEnabled),"filter"in B&&e(15,l=B.filter),"preferredDrawingMode"in B&&e(16,h=B.preferredDrawingMode),"state"in B&&e(17,c=B.state),"style"in B&&e(1,u=B.style),"toolName"in B&&e(2,d=B.toolName),"user"in B&&e(18,f=B.user),"viewer"in B&&e(3,p=B.viewer)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(7,{tool:i,opts:s}=Ls(d)||{tool:void 0,opts:void 0},i,(e(21,s),e(2,d))),r.$$.dirty[0]&2162688&&e(4,n=(s==null?void 0:s.drawingMode)||h),r.$$.dirty[0]&25&&(a&&n==="drag"?p.setMouseNavEnabled(!1):p.setMouseNavEnabled(!0)),r.$$.dirty[0]&1&&a&&v.clear(),r.$$.dirty[0]&4194329&&o.selected.length===0&&n==="drag"&&a&&p.setMouseNavEnabled(!1),r.$$.dirty[0]&4194304&&N(o.selected)},[a,u,d,p,n,x,A,i,v,S,R,E,b,D,F,l,h,c,f,m,_,s,o,G,$]}class vE extends ae{constructor(t){super(),oe(this,t,_E,yE,te,{drawingEnabled:0,filter:15,preferredDrawingMode:16,state:17,style:1,toolName:2,user:18,viewer:3,getDrawingTool:19,isDrawingEnabled:20},null,[-1,-1])}get getDrawingTool(){return this.$$.ctx[19]}get isDrawingEnabled(){return this.$$.ctx[20]}}function xE(r){let t,e,i,s,n,o,a,l=r[2].appearance.label+"",h,c,u,d;return{c(){t=Tt("g"),e=Tt("rect"),a=Tt("text"),h=Mo(l),M(e,"class","a9s-presence-label-bg svelte-1rehw2p"),M(e,"x",r[0]),M(e,"y",i=r[1]-18/r[3]),M(e,"height",s=18/r[3]),M(e,"fill",n=r[2].appearance.color),M(e,"stroke",o=r[2].appearance.color),M(a,"font-size",c=12/r[3]),M(a,"x",u=r[0]+Math.round(5/r[3])),M(a,"y",d=r[1]-5/r[3]),M(a,"class","svelte-1rehw2p"),M(t,"class","a9s-presence-label")},m(f,p){ft(f,t,p),tr(t,e),tr(t,a),tr(a,h),r[6](t)},p(f,[p]){p&1&&M(e,"x",f[0]),p&10&&i!==(i=f[1]-18/f[3])&&M(e,"y",i),p&8&&s!==(s=18/f[3])&&M(e,"height",s),p&4&&n!==(n=f[2].appearance.color)&&M(e,"fill",n),p&4&&o!==(o=f[2].appearance.color)&&M(e,"stroke",o),p&4&&l!==(l=f[2].appearance.label+"")&&qg(h,l),p&8&&c!==(c=12/f[3])&&M(a,"font-size",c),p&9&&u!==(u=f[0]+Math.round(5/f[3]))&&M(a,"x",u),p&10&&d!==(d=f[1]-5/f[3])&&M(a,"y",d)},i:Be,o:Be,d(f){f&&ct(t),r[6](null)}}}function bE(r,t,e){let{x:i}=t,{y:s}=t,{user:n}=t,{scale:o}=t,{hAlign:a=null}=t,l;const h=u=>{const d=l.querySelector("text"),f=l.querySelector("rect"),p=d.getBBox().width+10/u;a==="CENTER"&&l.setAttribute("style",`transform: translateX(-${p/2}px)`),f.setAttribute("width",`${p}`)};function c(u){Xs[u?"unshift":"push"](()=>{l=u,e(4,l)})}return r.$$set=u=>{"x"in u&&e(0,i=u.x),"y"in u&&e(1,s=u.y),"user"in u&&e(2,n=u.user),"scale"in u&&e(3,o=u.scale),"hAlign"in u&&e(5,a=u.hAlign)},r.$$.update=()=>{r.$$.dirty&24&&l&&h(o)},[i,s,n,o,l,a,c]}class Nf extends ae{constructor(t){super(),oe(this,t,bE,xE,te,{x:0,y:1,user:2,scale:3,hAlign:5})}}function wE(r){let t,e,i,s,n,o;return e=new Nf({props:{scale:r[1],user:r[0],x:r[3][0],y:r[3][1],hAlign:"CENTER"}}),{c(){t=Tt("g"),ee(e.$$.fragment),i=Tt("polygon"),M(i,"class","a9s-presence-shape a9s-presence-polygon svelte-fgq4n0"),M(i,"stroke",s=r[0].appearance.color),M(i,"fill","transparent"),M(i,"points",n=r[2].points.map(Uf).join(" ")),M(t,"class","a9s-presence-overlay")},m(a,l){ft(a,t,l),Zt(e,t,null),tr(t,i),o=!0},p(a,[l]){const h={};l&2&&(h.scale=a[1]),l&1&&(h.user=a[0]),l&8&&(h.x=a[3][0]),l&8&&(h.y=a[3][1]),e.$set(h),(!o||l&1&&s!==(s=a[0].appearance.color))&&M(i,"stroke",s),(!o||l&4&&n!==(n=a[2].points.map(Uf).join(" ")))&&M(i,"points",n)},i(a){o||(st(e.$$.fragment,a),o=!0)},o(a){ut(e.$$.fragment,a),o=!1},d(a){a&&ct(t),Jt(e)}}}const Uf=r=>r.join(",");function EE(r,t,e){let i,s,{annotation:n}=t,{user:o}=t,{scale:a}=t;const l=h=>{let[c,...u]=h.points;return u.forEach(([d,f])=>{f<c[1]&&(c=[d,f])}),c};return r.$$set=h=>{"annotation"in h&&e(4,n=h.annotation),"user"in h&&e(0,o=h.user),"scale"in h&&e(1,a=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=n.target.selector.geometry),r.$$.dirty&4&&e(3,s=l(i))},[o,a,i,s,n]}class TE extends ae{constructor(t){super(),oe(this,t,EE,wE,te,{annotation:4,user:0,scale:1})}}function AE(r){let t,e,i,s,n,o,a,l,h;return e=new Nf({props:{scale:r[1],user:r[0],x:r[2].x,y:r[2].y}}),{c(){t=Tt("g"),ee(e.$$.fragment),i=Tt("rect"),M(i,"class","a9s-presence-shape a9s-presence-rectangle svelte-gze948"),M(i,"stroke",s=r[0].appearance.color),M(i,"fill","transparent"),M(i,"x",n=r[2].x),M(i,"y",o=r[2].y),M(i,"width",a=r[2].w),M(i,"height",l=r[2].h),M(t,"class","a9s-presence-overlay")},m(c,u){ft(c,t,u),Zt(e,t,null),tr(t,i),h=!0},p(c,[u]){const d={};u&2&&(d.scale=c[1]),u&1&&(d.user=c[0]),u&4&&(d.x=c[2].x),u&4&&(d.y=c[2].y),e.$set(d),(!h||u&1&&s!==(s=c[0].appearance.color))&&M(i,"stroke",s),(!h||u&4&&n!==(n=c[2].x))&&M(i,"x",n),(!h||u&4&&o!==(o=c[2].y))&&M(i,"y",o),(!h||u&4&&a!==(a=c[2].w))&&M(i,"width",a),(!h||u&4&&l!==(l=c[2].h))&&M(i,"height",l)},i(c){h||(st(e.$$.fragment,c),h=!0)},o(c){ut(e.$$.fragment,c),h=!1},d(c){c&&ct(t),Jt(e)}}}function SE(r,t,e){let i,{annotation:s}=t,{user:n}=t,{scale:o}=t;return r.$$set=a=>{"annotation"in a&&e(3,s=a.annotation),"user"in a&&e(0,n=a.user),"scale"in a&&e(1,o=a.scale)},r.$$.update=()=>{r.$$.dirty&8&&e(2,i=s.target.selector.geometry)},[n,o,i,s]}class IE extends ae{constructor(t){super(),oe(this,t,SE,AE,te,{annotation:3,user:0,scale:1})}}const{Boolean:CE}=jg;function kf(r,t,e){const i=r.slice();return i[8]=t[e],i}function Gf(r){let t,e;return t=new Mf({props:{viewer:r[0],$$slots:{default:[ME,({transform:i,scale:s})=>({6:i,7:s}),({transform:i,scale:s})=>(i?64:0)|(s?128:0)]},$$scope:{ctx:r}}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s&1&&(n.viewer=i[0]),s&2244&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function $f(r){let t,e,i=ui(r[2]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Hf(kf(r,i,o));const n=o=>ut(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=er()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ft(o,t,a),e=!0},p(o,a){if(a&132){i=ui(o[2]);let l;for(l=0;l<i.length;l+=1){const h=kf(o,i,l);s[l]?(s[l].p(h,a),st(s[l],1)):(s[l]=Hf(h),s[l].c(),st(s[l],1),s[l].m(t.parentNode,t))}for(De(),l=i.length;l<s.length;l+=1)n(l);Oe()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)st(s[a]);e=!0}},o(o){s=s.filter(CE);for(let a=0;a<s.length;a+=1)ut(s[a]);e=!1},d(o){o&&ct(t),Po(s,o)}}}function RE(r){let t,e;return t=new TE({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s&4&&(n.annotation=i[8].annotation),s&4&&(n.user=i[8].selectedBy),s&128&&(n.scale=i[7]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function PE(r){let t,e;return t=new IE({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s&4&&(n.annotation=i[8].annotation),s&4&&(n.user=i[8].selectedBy),s&128&&(n.scale=i[7]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Hf(r){let t,e,i,s;const n=[PE,RE],o=[];function a(l,h){return l[8].annotation.target.selector.type===wt.RECTANGLE?0:l[8].annotation.target.selector.type===wt.POLYGON?1:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=er()},m(l,h){~t&&o[t].m(l,h),ft(l,i,h),s=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(De(),ut(o[c],1,1,()=>{o[c]=null}),Oe()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),st(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(st(e),s=!0)},o(l){ut(e),s=!1},d(l){l&&ct(i),~t&&o[t].d(l)}}}function ME(r){let t,e,i,s,n=r[2].length>0&&$f(r);return{c(){t=Tt("svg"),e=Tt("g"),n&&n.c(),M(e,"transform",i=r[6]),M(t,"class","a9s-osd-presencelayer svelte-1krwc4m")},m(o,a){ft(o,t,a),tr(t,e),n&&n.m(e,null),s=!0},p(o,a){o[2].length>0?n?(n.p(o,a),a&4&&st(n,1)):(n=$f(o),n.c(),st(n,1),n.m(e,null)):n&&(De(),ut(n,1,1,()=>{n=null}),Oe()),(!s||a&64&&i!==(i=o[6]))&&M(e,"transform",i)},i(o){s||(st(n),s=!0)},o(o){ut(n),s=!1},d(o){o&&ct(t),n&&n.d()}}}function BE(r){let t=!!r[1],e,i,s=t&&Gf(r);return{c(){s&&s.c(),e=er()},m(n,o){s&&s.m(n,o),ft(n,e,o),i=!0},p(n,[o]){o&2&&(t=!!n[1]),t?s?(s.p(n,o),o&2&&st(s,1)):(s=Gf(n),s.c(),st(s,1),s.m(e.parentNode,e)):s&&(De(),ut(s,1,1,()=>{s=null}),Oe())},i(n){i||(st(s),i=!0)},o(n){ut(s),i=!1},d(n){n&&ct(e),s&&s.d(n)}}}function DE(r,t,e){let{store:i}=t,{viewer:s}=t,{provider:n}=t,o=[],a;const l=(h,c)=>{e(2,o=[...o.filter(({selectedBy:u})=>u.presenceKey!==h.presenceKey),...(c||[]).map(u=>({annotation:i.getAnnotation(u),selectedBy:h}))].filter(({annotation:u})=>(u||console.warn("Selection event on unknown annotation"),!!u))),a&&i.unobserve(a),a=u=>{const{deleted:d,updated:f}=u.changes,p=new Set((d||[]).map(_=>_.id)),m=o.filter(({annotation:_})=>!p.has(_.id)).map(_=>{const y=(f||[]).find(x=>x.oldValue.id===_.annotation.id);return y?{selectedBy:_.selectedBy,annotation:y.newValue}:_});e(2,o=m)},i.observe(a,{annotations:o.map(u=>u.annotation.id)})};return Zg(()=>{a&&i.unobserve(a)}),r.$$set=h=>{"store"in h&&e(3,i=h.store),"viewer"in h&&e(0,s=h.viewer),"provider"in h&&e(1,n=h.provider)},r.$$.update=()=>{r.$$.dirty&2&&n&&n.on("selectionChange",l)},[s,n,o,i]}class OE extends ae{constructor(t){super(),oe(this,t,DE,BE,te,{store:3,viewer:0,provider:1})}}const Xf=(r,t)=>{t==="auto"?r.addHandler("open",e=>{const i=r.world.getItemCount();r.world.getItemAt(i-1).addOnceHandler("fully-loaded-change",n=>{const{fullyLoaded:o}=n;if(o){const a=r.canvas.querySelector("canvas"),l=Oh(a);r.element.setAttribute("data-theme",l)}})}):r.element.setAttribute("data-theme",t)},Vf=(r,t,e)=>(i,s={})=>{const n=typeof i=="string"?i:i.id,o=t.getAnnotation(n);if(!o||!Je(o))return;const a=r.container.getBoundingClientRect(),{padding:l}=s;let[h,c,u,d]=l?Array.isArray(l)?l:[l,l,l,l]:[0,0,0,0];h=h/a.height,c=c/a.width,u=u/a.height,d=d/a.width;const{minX:f,minY:p,maxX:m,maxY:_}=o.target.selector.geometry.bounds,y=m-f,x=_-p,g=f-d*y,v=p-h*x,w=y+(c+d)*y,I=x+(h+u)*x,A=r.viewport.imageToViewportRectangle(g,v,w,I);r.viewport[e](A,s.immediately)},FE=(r,t)=>Vf(r,t,"fitBounds"),LE=(r,t)=>Vf(r,t,"fitBoundsWithConstraints"),NE=(r,t={})=>{const e=Lh(t,{drawingEnabled:!1,drawingMode:ch?"drag":"click",userSelectAction:io.EDIT,theme:"light"}),i=Dh(e),{hover:s,selection:n,store:o}=i,a=hp(o),l=cp(i,a,e.adapter,e.autoSave);let h=_p(),c=e.drawingEnabled,u=e.drawingMode;const d=Uh(a,r.element),f=new Fw({target:r.element,props:{state:i,viewer:r,style:e.style,filter:void 0}}),p=new OE({target:r.element.querySelector(".openseadragon-canvas"),props:{provider:void 0,store:o,viewer:r}}),m=new vE({target:r.element.querySelector(".openseadragon-canvas"),props:{drawingEnabled:!!c,filter:void 0,preferredDrawingMode:u,state:i,style:e.style,user:h,viewer:r}});f.$on("click",B=>{const{originalEvent:Z,annotation:P}=B.detail;P&&!(u==="click"&&c)?n.userSelect(P.id,Z):n.isEmpty()||n.clear()}),r.element.addEventListener("pointerdown",B=>{if(s.current){const Z=o.getAnnotation(s.current);l.emit("clickAnnotation",Z,B)}}),Xf(r,e.theme);const _=dp(i,a,e.adapter),y=()=>{m.$set({drawingEnabled:!1}),setTimeout(()=>m.$set({drawingEnabled:!0}),1)},x=()=>{f.$destroy(),p.$destroy(),m.$destroy(),d.destroy(),a.destroy()},g=FE(r,o),v=LE(r,o),w=()=>m.getDrawingTool(),I=()=>h,A=()=>m.isDrawingEnabled(),C=(B,Z,P)=>vh(B,Z,P),N=(B,Z)=>fh(B,Z),S=B=>{if(!Ls(B))throw`No drawing tool named ${B}`;m.$set({toolName:B})},R=B=>{c=B,m.$set({drawingEnabled:c})},E=B=>{f.$set({filter:B}),m.$set({filter:B})},b=B=>{f.$set({style:B}),m.$set({style:B})},D=B=>p.$set({provider:B}),F=B=>Xf(r,B),G=B=>{h=B,m.$set({user:B})},$=B=>f.$set({visible:B});return{..._,cancelDrawing:y,destroy:x,fitBounds:g,fitBoundsWithConstraints:v,getDrawingTool:w,getUser:I,isDrawingEnabled:A,listDrawingTools:Fs,on:l.on,off:l.off,registerDrawingTool:C,registerShapeEditor:N,setDrawingEnabled:R,setDrawingTool:S,setFilter:E,setPresenceProvider:D,setStyle:b,setTheme:F,setUser:G,setVisible:$,state:i,viewer:r}};Mt.ShapeType=wt,Mt.UserSelectAction=io,Mt.W3CImageFormat=Dm,Mt.chainStyles=Em,Mt.computeStyle=wm,Mt.createBody=tp,Mt.createImageAnnotator=Vg,Mt.createOSDAnnotator=NE,Mt.defaultColorProvider=xp,Object.defineProperty(Mt,Symbol.toStringTag,{value:"Module"})});
1147
+ }`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(t){this._stylesheet!==t&&(this._stylesheet=t,this.styleID++)}normalizeColor(t){return Array.isArray(t)&&(t=pv(t)),typeof t=="number"?fv(t):t}dropShadowToCSS(){let t=this.normalizeColor(this.dropShadowColor);const e=this.dropShadowAlpha,i=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),s=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);t.startsWith("#")&&e<1&&(t+=(e*255|0).toString(16).padStart(2,"0"));const n=`${i}px ${s}px`;return this.dropShadowBlur>0?`text-shadow: ${n} ${this.dropShadowBlur}px ${t}`:`text-shadow: ${n} ${t}`}reset(){Object.assign(this,$i.defaultOptions)}onBeforeDraw(){const{fontsDirty:t}=this;return this.fontsDirty=!1,this.isSafari&&this._fonts.length>0&&t?new Promise(e=>setTimeout(e,100)):Promise.resolve()}get isSafari(){const{userAgent:t}=W.ADAPTER.getNavigator();return/^((?!chrome|android).)*safari/i.test(t)}set fillGradientStops(t){console.warn("[HTMLTextStyle] fillGradientStops is not supported by HTMLText")}get fillGradientStops(){return super.fillGradientStops}set fillGradientType(t){console.warn("[HTMLTextStyle] fillGradientType is not supported by HTMLText")}get fillGradientType(){return super.fillGradientType}set miterLimit(t){console.warn("[HTMLTextStyle] miterLimit is not supported by HTMLText")}get miterLimit(){return super.miterLimit}set trim(t){console.warn("[HTMLTextStyle] trim is not supported by HTMLText")}get trim(){return super.trim}set textBaseline(t){console.warn("[HTMLTextStyle] textBaseline is not supported by HTMLText")}get textBaseline(){return super.textBaseline}set leading(t){console.warn("[HTMLTextStyle] leading is not supported by HTMLText")}get leading(){return super.leading}set lineJoin(t){console.warn("[HTMLTextStyle] lineJoin is not supported by HTMLText")}get lineJoin(){return super.lineJoin}};Al.availableFonts={},Al.defaultOptions={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fontFamily:"Arial",fontSize:26,fontStyle:"normal",fontVariant:"normal",fontWeight:"normal",letterSpacing:0,lineHeight:0,padding:0,stroke:"black",strokeThickness:0,whiteSpace:"normal",wordWrap:!1,wordWrapWidth:100};let Sl=Al;const Kn=class Hi extends Pi{constructor(t="",e={}){super(q.EMPTY),this._text=null,this._style=null,this._autoResolution=!0,this.localStyleID=-1,this.dirty=!1,this._updateID=0,this.ownsStyle=!1;const i=new Image,s=q.from(i,{scaleMode:W.SCALE_MODE,resourceOptions:{autoLoad:!1}});s.orig=new at,s.trim=new at,this.texture=s;const n="http://www.w3.org/2000/svg",o="http://www.w3.org/1999/xhtml",a=document.createElementNS(n,"svg"),l=document.createElementNS(n,"foreignObject"),h=document.createElementNS(o,"div"),c=document.createElementNS(o,"style");l.setAttribute("width","10000"),l.setAttribute("height","10000"),l.style.overflow="hidden",a.appendChild(l),this.maxWidth=Hi.defaultMaxWidth,this.maxHeight=Hi.defaultMaxHeight,this._domElement=h,this._styleElement=c,this._svgRoot=a,this._foreignObject=l,this._foreignObject.appendChild(c),this._foreignObject.appendChild(h),this._image=i,this._loadImage=new Image,this._autoResolution=Hi.defaultAutoResolution,this._resolution=Hi.defaultResolution??W.RESOLUTION,this.text=t,this.style=e}measureText(t){var c,u;const{text:e,style:i,resolution:s}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:e,style:i.toCSS(s)}),this._styleElement.textContent=i.toGlobalCSS(),document.body.appendChild(this._svgRoot);const n=this._domElement.getBoundingClientRect();this._svgRoot.remove();const{width:o,height:a}=n;(o>this.maxWidth||a>this.maxHeight)&&console.warn("[HTMLText] Large expanse of text, increase HTMLText.maxWidth or HTMLText.maxHeight property.");const l=Math.min(this.maxWidth,Math.ceil(o)),h=Math.min(this.maxHeight,Math.ceil(a));return this._svgRoot.setAttribute("width",l.toString()),this._svgRoot.setAttribute("height",h.toString()),e!==this._text&&(this._domElement.innerHTML=this._text),i!==this._style&&(Object.assign(this._domElement,{style:(c=this._style)==null?void 0:c.toCSS(s)}),this._styleElement.textContent=(u=this._style)==null?void 0:u.toGlobalCSS()),{width:l+i.padding*2,height:h+i.padding*2}}async updateText(t=!0){const{style:e,_image:i,_loadImage:s}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:n,height:o}=this.measureText();i.width=s.width=Math.ceil(Math.max(1,n)),i.height=s.height=Math.ceil(Math.max(1,o)),this._updateID++;const a=this._updateID;await new Promise(l=>{s.onload=async()=>{if(a<this._updateID){l();return}await e.onBeforeDraw(),i.src=s.src,s.onload=null,s.src="",this.updateTexture(),l()};const h=new XMLSerializer().serializeToString(this._svgRoot);s.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(h)}`})}get source(){return this._image}updateTexture(){const{style:t,texture:e,_image:i,resolution:s}=this,{padding:n}=t,{baseTexture:o}=e;e.trim.width=e._frame.width=i.width/s,e.trim.height=e._frame.height=i.height/s,e.trim.x=-n,e.trim.y=-n,e.orig.width=e._frame.width-n*2,e.orig.height=e._frame.height-n*2,this._onTextureUpdate(),o.setRealSize(i.width,i.height,s),this.dirty=!1}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._render(t)}_renderCanvas(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0),this.updateText(!0),super._renderCanvas(t)}getLocalBounds(t){return this.updateText(!0),super.getLocalBounds(t)}_calculateBounds(){this.updateText(!0),this.calculateVertices(),this._bounds.addQuad(this.vertexData)}_onStyleChange(){this.dirty=!0}destroy(t){var i,s,n,o,a;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},Hi.defaultDestroyOptions,t),super.destroy(t);const e=null;this.ownsStyle&&((i=this._style)==null||i.cleanFonts()),this._style=e,(s=this._svgRoot)==null||s.remove(),this._svgRoot=e,(n=this._domElement)==null||n.remove(),this._domElement=e,(o=this._foreignObject)==null||o.remove(),this._foreignObject=e,(a=this._styleElement)==null||a.remove(),this._styleElement=e,this._loadImage.src="",this._loadImage.onload=null,this._loadImage=e,this._image.src="",this._image=e}get width(){return this.updateText(!0),Math.abs(this.scale.x)*this._image.width/this.resolution}set width(t){this.updateText(!0);const e=vr(this.scale.x)||1;this.scale.x=e*t/this._image.width/this.resolution,this._width=t}get height(){return this.updateText(!0),Math.abs(this.scale.y)*this._image.height/this.resolution}set height(t){this.updateText(!0);const e=vr(this.scale.y)||1;this.scale.y=e*t/this._image.height/this.resolution,this._height=t}get style(){return this._style}set style(t){this._style!==t&&(t=t||{},t instanceof Sl?(this.ownsStyle=!1,this._style=t):t instanceof Sr?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=Sl.from(t)):(this.ownsStyle=!0,this._style=new Sl(t)),this.localStyleID=-1,this.dirty=!0)}get text(){return this._text}set text(t){t=String(t===""||t===null||t===void 0?" ":t),t=this.sanitiseText(t),this._text!==t&&(this._text=t,this.dirty=!0)}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}sanitiseText(t){return t.replace(/<br>/gi,"<br/>").replace(/<hr>/gi,"<hr/>").replace(/&nbsp;/gi,"&#160;")}};Kn.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},Kn.defaultMaxWidth=2024,Kn.defaultMaxHeight=2024,Kn.defaultAutoResolution=!0;const Sw=16777215,Iw=.25,Cw=16777215,Rw=1.5;let Rr=!1,xs;const Il=r=>{const t={tint:r!=null&&r.fill?new bt(r.fill).toNumber():Sw,alpha:(r==null?void 0:r.fillOpacity)===void 0?Iw:Math.min(r.fillOpacity,1)},e={tint:r!=null&&r.stroke?new bt(r.stroke).toNumber():Cw,alpha:(r==null?void 0:r.strokeOpacity)===void 0?1:Math.min(r.strokeOpacity,1),lineWidth:(r==null?void 0:r.strokeWidth)===void 0?Rw:r.strokeWidth};return{fillStyle:t,strokeStyle:e}},Cl=r=>(t,e,i)=>{const{fillStyle:s,strokeStyle:n}=Il(i),o=new vs;o.beginFill(16777215),r(e,o),o.endFill(),o.tint=s.tint,o.alpha=s.alpha,t.addChild(o);const a=new vs,l=n.lineWidth===1?1:n.lineWidth/xs;return a.lineStyle(l,16777215,1,.5,n.lineWidth===1),r(e,a),a.tint=n.tint||16777215,a.alpha=n.alpha,t.addChild(a),{fill:o,stroke:a,strokeWidth:n.lineWidth}},Pw=Cl((r,t)=>{const{cx:e,cy:i,rx:s,ry:n}=r.geometry;t.drawEllipse(e,i,s,n)}),Mw=Cl((r,t)=>{const e=r.geometry.points.reduce((i,s)=>[...i,...s],[]);t.drawPolygon(e)}),Bw=Cl((r,t)=>{const{x:e,y:i,w:s,h:n}=r.geometry;t.drawRect(e,i,s,n)}),bf=r=>{const t=r.viewport.getContainerSize().x;return r.viewport.getZoom(!0)*t/r.world.getContentFactor()},wf=(r,t,e,i)=>()=>{const s=r.viewport.viewportToImageRectangle(r.viewport.getBounds(!0)),n=bf(r);(n!==xs||!Rr)&&(Rr=!0,e.forEach(({stroke:d,strokeWidth:f})=>{const{lineStyle:p}=d.geometry.graphicsData[0];f>1?(Rr=n===xs,p.width=f/n,p.native=!1,d.geometry.invalidate()):f===1&&!p.native&&(p.width=1,p.native=!0,d.geometry.invalidate())})),xs=n;const o=r.viewport.getFlip();let a=Math.PI*r.viewport.getRotation(!0)/180;a<0&&(a+=2*Math.PI),a>2*Math.PI&&(a-=2*Math.PI);const l=o?r.viewport._containerInnerSize.x+s.x*n:-s.x*n,h=-s.y*n;let c,u;a>0&&a<=Math.PI/2?(c=s.height*n,u=0):a>Math.PI/2&&a<=Math.PI?(c=s.width*n,u=s.height*n):a>Math.PI&&a<=Math.PI*1.5?(c=0,u=s.width*n):(c=0,u=0),t.position.x=c+l*Math.cos(a)-h*Math.sin(a),t.position.y=u+l*Math.sin(a)+h*Math.cos(a),t.scale.set(o?-n:n,n),t.rotation=a,i.render(t)},Dw=(r,t)=>{const e=new vs,i=yd({width:t.width,height:t.height,backgroundAlpha:0,view:t,antialias:!0,resolution:2}),s=new Map;let n=new Set,o,a;xs=bf(r);const l=(g,v)=>{Rr=!1;const{selector:w}=g.target,I=typeof a=="function"?a(g,v):a;let A;w.type===wt.RECTANGLE?A=Bw(e,w,I):w.type===wt.POLYGON?A=Mw(e,w,I):w.type===wt.ELLIPSE?A=Pw(e,w,I):console.warn(`Unsupported shape type: ${w.type}`),A&&s.set(g.id,{annotation:g,...A})},h=g=>{const v=s.get(g.id);v&&(s.delete(g.id),v.fill.destroy(),v.stroke.destroy())},c=(g,v,w)=>{Rr=!1;const I=s.get(g.id);I&&(s.delete(g.id),I.fill.destroy(),I.stroke.destroy(),l(v,w))},u=(g,v)=>{const w=s.get(g);w&&(s.delete(g),w.fill.destroy(),w.stroke.destroy(),l(w.annotation,v))},d=(g,v)=>{i.resize(g,v),i.render(e)},f=g=>{Rr=!1;const{children:v}=e;s.forEach(({fill:w,stroke:I,annotation:A})=>{const C=g?n.has(A.id)||g(A):!0;C&&!v.includes(w)?(e.addChild(w),e.addChild(I)):!C&&v.includes(w)&&(e.removeChild(w),e.removeChild(I))}),i.render(e)},p=g=>{o!==g&&(o&&u(o,{selected:n.has(o)}),g&&u(g,{selected:n.has(g),hovered:!0}),o=g,i.render(e))},m=g=>{const v=g.selected.map(A=>A.id),w=v.filter(A=>!n.has(A)),I=[...n].filter(A=>!v.includes(A));[...w,...I].forEach(A=>u(A,{selected:v.includes(A),hovered:A===o})),n=new Set(v),i.render(e)},_=g=>{if(typeof g=="function")s.forEach(({annotation:v,fill:w,stroke:I,strokeWidth:A},C)=>{A>1&&(Rr=!1);const N={selected:n.has(v.id),hovered:o===v.id},{fillStyle:S,strokeStyle:R}=Il(g(v,N));w.tint=S.tint,w.alpha=S.alpha,I.tint=R.tint||16777215,I.alpha=R.alpha,s.set(v.id,{annotation:v,fill:w,stroke:I,strokeWidth:R.lineWidth})});else{const{fillStyle:v,strokeStyle:w}=Il(g);w.lineWidth>1&&(Rr=!1),s.forEach(({annotation:I,fill:A,stroke:C,strokeWidth:N},S)=>{A.tint=v.tint,A.alpha=v.alpha,C.tint=w.tint||16777215,C.alpha=w.alpha,s.set(I.id,{annotation:I,fill:A,stroke:C,strokeWidth:w.lineWidth})})}a=g,i.render(e),wf(r,e,s,i)()},y=g=>{g?t.classList.remove("hidden"):t.classList.add("hidden")};return{addAnnotation:l,destroy:()=>i.destroy(),redraw:wf(r,e,s,i),removeAnnotation:h,resize:d,setFilter:f,setHovered:p,setSelected:m,setStyle:_,setVisible:y,updateAnnotation:c}};function Ow(r,t,e){let i,s,{filter:n}=t,{state:o}=t,{style:a}=t,{viewer:l}=t,{visible:h=!0}=t;const{store:c,hover:u,selection:d,viewport:f}=o;Ro(r,u,I=>e(11,i=I)),Ro(r,d,I=>e(8,s=I));const p=Hs();let m,_;const y=I=>{const A=new Nt.Point(I.x,I.y),{x:C,y:N}=l.viewport.pointFromPixel(A);return l.viewport.viewportToImageCoordinates(C,N)},x=I=>{const{x:A,y:C}=I.position;_={x:A,y:C}},g=I=>A=>{const{x:C,y:N}=y(new Nt.Point(A.offsetX,A.offsetY)),S=c.getAt(C,N);S&&(!n||n(S))?(I.classList.add("hover"),i!==S.id&&(u.set(S.id),m.setHovered(S.id))):(I.classList.remove("hover"),i&&(u.set(void 0),m.setHovered(void 0)))},v=I=>{if(!_)return;const A=I.originalEvent,{x:C,y:N}=I.position,S=C-_.x,R=N-_.y;if(Math.sqrt(S*S+R*R)<5){const{x:b,y:D}=y(I.position),F=c.getAt(b,D);F?p("click",{originalEvent:A,annotation:F}):p("click",{originalEvent:A})}_=void 0};let w;return $s(()=>{var F;const{offsetWidth:I,offsetHeight:A}=l.canvas,C=document.createElement("canvas");C.width=I,C.height=A,C.className="a9s-gl-canvas",(F=l.element.querySelector(".openseadragon-canvas"))==null||F.appendChild(C),e(7,m=Dw(l,C));const N=g(C);C.addEventListener("pointermove",N);const S=new ResizeObserver(G=>{try{const{width:$,height:B}=G[0].contentRect;C.width=$,C.height=B,m.resize($,B)}catch{console.warn("WebGL canvas already disposed")}});S.observe(C);const R=()=>{const G=l.viewport.getBounds();w=l.viewport.viewportToImageRectangle(G);const{x:$,y:B,width:K,height:P}=w,U=c.getIntersecting($,B,K,P);f.set(U.map(j=>j.id))};l.addHandler("canvas-press",x),l.addHandler("canvas-release",v),l.addHandler("update-viewport",m.redraw),l.addHandler("animation-finish",R);const E=G=>G.filter($=>Je($)),b=G=>Je(G.oldValue)&&Je(G.newValue),D=G=>{const{created:$,updated:B,deleted:K}=G.changes;if(E($||[]).forEach(P=>m.addAnnotation(P)),E(K||[]).forEach(P=>m.removeAnnotation(P)),(B||[]).filter(P=>b(P)).forEach(({oldValue:P,newValue:U})=>m.updateAnnotation(P,U)),w){const{x:P,y:U,width:j,height:rt}=w,Q=c.getIntersecting(P,U,j,rt);f.set(Q.map(H=>H.id))}else f.set(c.all().map(P=>P.id));m.redraw()};return c.observe(D),()=>{var G;C.removeEventListener("pointermove",N),S.disconnect(),l.removeHandler("canvas-press",x),l.removeHandler("canvas-release",v),l.removeHandler("update-viewport",m.redraw),l.removeHandler("animation-finish",R),c.unobserve(D),m.destroy(),(G=C.parentNode)==null||G.removeChild(C)}}),r.$$set=I=>{"filter"in I&&e(2,n=I.filter),"state"in I&&e(3,o=I.state),"style"in I&&e(4,a=I.style),"viewer"in I&&e(5,l=I.viewer),"visible"in I&&e(6,h=I.visible)},r.$$.update=()=>{r.$$.dirty&132&&(m==null||m.setFilter(n)),r.$$.dirty&384&&(m==null||m.setSelected(s)),r.$$.dirty&144&&(m==null||m.setStyle(a)),r.$$.dirty&192&&(m==null||m.setVisible(h))},[u,d,n,o,a,l,h,m,s]}class Fw extends ae{constructor(t){super(),oe(this,t,Ow,null,te,{filter:2,state:3,style:4,viewer:5,visible:6})}}const Yt=[];for(let r=0;r<256;++r)Yt.push((r+256).toString(16).slice(1));function Lw(r,t=0){return(Yt[r[t+0]]+Yt[r[t+1]]+Yt[r[t+2]]+Yt[r[t+3]]+"-"+Yt[r[t+4]]+Yt[r[t+5]]+"-"+Yt[r[t+6]]+Yt[r[t+7]]+"-"+Yt[r[t+8]]+Yt[r[t+9]]+"-"+Yt[r[t+10]]+Yt[r[t+11]]+Yt[r[t+12]]+Yt[r[t+13]]+Yt[r[t+14]]+Yt[r[t+15]]).toLowerCase()}let Rl;const Nw=new Uint8Array(16);function Uw(){if(!Rl){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Rl=crypto.getRandomValues.bind(crypto)}return Rl(Nw)}const Ef={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function kw(r,t,e){if(Ef.randomUUID&&!t&&!r)return Ef.randomUUID();r=r||{};const i=r.random||(r.rng||Uw)();return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Lw(i)}var Ui=(r=>(r.ELLIPSE="ELLIPSE",r.POLYGON="POLYGON",r.RECTANGLE="RECTANGLE",r))(Ui||{});const Pl=(r,t)=>t,Gw=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}},$w={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),c=t-i,u=e-s,d=l*c+h*u,f=h*c-l*u;return d*d/(n*n)+f*f/(o*o)<=1}};Pl(Ui.ELLIPSE,$w);const Hw={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],c=i[o][1];l>e!=c>e&&t<(h-a)*(e-l)/(c-l)+a&&(s=!s)}return s}};Pl(Ui.POLYGON,Hw);const Xw={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};Pl(Ui.RECTANGLE,Xw);function Tf(r,t,e){const i=r.slice();return i[10]=t[e],i[12]=e,i}function Af(r){let t,e;return t=new bs({props:{x:r[10][0],y:r[10][1],scale:r[3]}}),t.$on("pointerdown",function(){Kt(r[9](`HANDLE-${r[12]}`))&&r[9](`HANDLE-${r[12]}`).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,s){Zt(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||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Vw(r){let t,e,i,s,n,o,a,l,h,c,u,d=ui(r[4].points),f=[];for(let m=0;m<d.length;m+=1)f[m]=Af(Tf(r,d,m));const p=m=>ut(f[m],1,1,()=>{f[m]=null});return{c(){t=Tt("polygon"),s=xe(),n=Tt("polygon"),a=xe();for(let m=0;m<f.length;m+=1)f[m].c();l=er(),M(t,"class","a9s-outer"),M(t,"style",e=r[1]?"display:none;":void 0),M(t,"points",i=r[4].points.map(Sf).join(" ")),M(n,"class","a9s-inner a9s-shape-handle"),M(n,"style",r[1]),M(n,"points",o=r[4].points.map(If).join(" "))},m(m,_){ft(m,t,_),ft(m,s,_),ft(m,n,_),ft(m,a,_);for(let y=0;y<f.length;y+=1)f[y]&&f[y].m(m,_);ft(m,l,_),h=!0,c||(u=[zt(t,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),zt(n,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)})],c=!0)},p(m,_){if(r=m,(!h||_&2&&e!==(e=r[1]?"display:none;":void 0))&&M(t,"style",e),(!h||_&16&&i!==(i=r[4].points.map(Sf).join(" ")))&&M(t,"points",i),(!h||_&2)&&M(n,"style",r[1]),(!h||_&16&&o!==(o=r[4].points.map(If).join(" ")))&&M(n,"points",o),_&536){d=ui(r[4].points);let y;for(y=0;y<d.length;y+=1){const x=Tf(r,d,y);f[y]?(f[y].p(x,_),st(f[y],1)):(f[y]=Af(x),f[y].c(),st(f[y],1),f[y].m(l.parentNode,l))}for(De(),y=d.length;y<f.length;y+=1)p(y);Oe()}},i(m){if(!h){for(let _=0;_<d.length;_+=1)st(f[_]);h=!0}},o(m){f=f.filter(Boolean);for(let _=0;_<f.length;_+=1)ut(f[_]);h=!1},d(m){m&&(ct(t),ct(s),ct(n),ct(a),ct(l)),Po(f,m),c=!1,Qe(u)}}}function zw(r){let t,e;return t=new Rf({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Vw,({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(){ee(t.$$.fragment)},m(i,s){Zt(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||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const Sf=r=>r.join(","),If=r=>r.join(",");function Ww(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{let m;const _=d.geometry;f==="SHAPE"?m=_.points.map(([x,g])=>[x+p[0],g+p[1]]):m=_.points.map(([x,g],v)=>f===`HANDLE-${v}`?[x+p[0],g+p[1]]:[x,g]);const y=Gw(m);return{...d,geometry:{points:m,bounds:y}}};function h(d){rr.call(this,r,d)}function c(d){rr.call(this,r,d)}function u(d){rr.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,c,u]}class jw extends ae{constructor(t){super(),oe(this,t,Ww,zw,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}const Yw=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0;function qw(r){let t,e,i,s,n,o;return{c(){t=Tt("rect"),M(t,"class",e=ks(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),M(t,"x",i=r[0]-r[5]/2),M(t,"y",s=r[1]-r[5]/2),M(t,"width",r[5]),M(t,"height",r[5])},m(a,l){ft(a,t,l),n||(o=zt(t,"pointerdown",r[11]),n=!0)},p(a,l){l&256&&e!==(e=ks(`a9s-handle ${a[8].class||""}`.trim())+" svelte-1sgkh33")&&M(t,"class",e),l&33&&i!==(i=a[0]-a[5]/2)&&M(t,"x",i),l&34&&s!==(s=a[1]-a[5]/2)&&M(t,"y",s),l&32&&M(t,"width",a[5]),l&32&&M(t,"height",a[5])},d(a){a&&ct(t),n=!1,o()}}}function Kw(r){let t,e,i,s,n,o,a,l,h;return{c(){t=Tt("g"),e=Tt("circle"),s=Tt("rect"),M(e,"cx",r[0]),M(e,"cy",r[1]),M(e,"r",i=r[3]/r[2]),M(e,"class","a9s-touch-halo svelte-1sgkh33"),Gs(e,"touched",r[4]),M(s,"class",n=ks(`a9s-handle ${r[8].class||""}`.trim())+" svelte-1sgkh33"),M(s,"x",o=r[0]-r[5]/2),M(s,"y",a=r[1]-r[5]/2),M(s,"width",r[5]),M(s,"height",r[5]),M(t,"class","a9s-touch-handle")},m(c,u){ft(c,t,u),tr(t,e),tr(t,s),l||(h=[zt(e,"pointerdown",r[10]),zt(e,"pointerdown",r[6]),zt(e,"pointerup",r[7]),zt(s,"pointerdown",r[9]),zt(s,"pointerdown",r[6]),zt(s,"pointerup",r[7])],l=!0)},p(c,u){u&1&&M(e,"cx",c[0]),u&2&&M(e,"cy",c[1]),u&12&&i!==(i=c[3]/c[2])&&M(e,"r",i),u&16&&Gs(e,"touched",c[4]),u&256&&n!==(n=ks(`a9s-handle ${c[8].class||""}`.trim())+" svelte-1sgkh33")&&M(s,"class",n),u&33&&o!==(o=c[0]-c[5]/2)&&M(s,"x",o),u&34&&a!==(a=c[1]-c[5]/2)&&M(s,"y",a),u&32&&M(s,"width",c[5]),u&32&&M(s,"height",c[5])},d(c){c&&ct(t),l=!1,Qe(h)}}}function Zw(r){let t;function e(n,o){return Yw?Kw:qw}let s=e()(r);return{c(){s.c(),t=er()},m(n,o){s.m(n,o),ft(n,t,o)},p(n,[o]){s.p(n,o)},i:Be,o:Be,d(n){n&&ct(t),s.d(n)}}}function Jw(r,t,e){let i,{x:s}=t,{y:n}=t,{scale:o}=t,{radius:a=30}=t,l=!1;const h=p=>{p.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(p){rr.call(this,r,p)}function d(p){rr.call(this,r,p)}function f(p){rr.call(this,r,p)}return r.$$set=p=>{e(8,t=Co(Co({},t),Wh(p))),"x"in p&&e(0,s=p.x),"y"in p&&e(1,n=p.y),"scale"in p&&e(2,o=p.scale),"radius"in p&&e(3,a=p.radius)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=10/o)},t=Wh(t),[s,n,o,a,l,i,h,c,t,u,d,f]}class bs extends ae{constructor(t){super(),oe(this,t,Jw,Zw,te,{x:0,y:1,scale:2,radius:3})}}function Qw(r){let t,e,i,s,n,o,a,l,h,c,u,d,f,p,m,_,y,x,g,v,w,I,A,C,N,S,R,E,b,D,F,G,$,B,K,P,U,j,rt,Q,H,V,lt;return B=new bs({props:{class:"a9s-corner-handle-topleft",x:r[4].x,y:r[4].y,scale:r[3]}}),B.$on("pointerdown",function(){Kt(r[9]("TOP_LEFT"))&&r[9]("TOP_LEFT").apply(this,arguments)}),P=new bs({props:{class:"a9s-corner-handle-topright",x:r[4].x+r[4].w,y:r[4].y,scale:r[3]}}),P.$on("pointerdown",function(){Kt(r[9]("TOP_RIGHT"))&&r[9]("TOP_RIGHT").apply(this,arguments)}),j=new bs({props:{class:"a9s-corner-handle-bottomright",x:r[4].x+r[4].w,y:r[4].y+r[4].h,scale:r[3]}}),j.$on("pointerdown",function(){Kt(r[9]("BOTTOM_RIGHT"))&&r[9]("BOTTOM_RIGHT").apply(this,arguments)}),Q=new bs({props:{class:"a9s-corner-handle-bottomleft",x:r[4].x,y:r[4].y+r[4].h,scale:r[3]}}),Q.$on("pointerdown",function(){Kt(r[9]("BOTTOM_LEFT"))&&r[9]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=Tt("rect"),a=xe(),l=Tt("rect"),f=xe(),p=Tt("rect"),x=xe(),g=Tt("rect"),A=xe(),C=Tt("rect"),E=xe(),b=Tt("rect"),$=xe(),ee(B.$$.fragment),K=xe(),ee(P.$$.fragment),U=xe(),ee(j.$$.fragment),rt=xe(),ee(Q.$$.fragment),M(t,"class","a9s-outer"),M(t,"style",e=r[1]?"display:none;":void 0),M(t,"x",i=r[4].x),M(t,"y",s=r[4].y),M(t,"width",n=r[4].w),M(t,"height",o=r[4].h),M(l,"class","a9s-inner a9s-shape-handle"),M(l,"style",r[1]),M(l,"x",h=r[4].x),M(l,"y",c=r[4].y),M(l,"width",u=r[4].w),M(l,"height",d=r[4].h),M(p,"class","a9s-edge-handle a9s-edge-handle-top"),M(p,"x",m=r[4].x),M(p,"y",_=r[4].y),M(p,"height",1),M(p,"width",y=r[4].w),M(g,"class","a9s-edge-handle a9s-edge-handle-right"),M(g,"x",v=r[4].x+r[4].w),M(g,"y",w=r[4].y),M(g,"height",I=r[4].h),M(g,"width",1),M(C,"class","a9s-edge-handle a9s-edge-handle-bottom"),M(C,"x",N=r[4].x),M(C,"y",S=r[4].y+r[4].h),M(C,"height",1),M(C,"width",R=r[4].w),M(b,"class","a9s-edge-handle a9s-edge-handle-left"),M(b,"x",D=r[4].x),M(b,"y",F=r[4].y),M(b,"height",G=r[4].h),M(b,"width",1)},m(L,O){ft(L,t,O),ft(L,a,O),ft(L,l,O),ft(L,f,O),ft(L,p,O),ft(L,x,O),ft(L,g,O),ft(L,A,O),ft(L,C,O),ft(L,E,O),ft(L,b,O),ft(L,$,O),Zt(B,L,O),ft(L,K,O),Zt(P,L,O),ft(L,U,O),Zt(j,L,O),ft(L,rt,O),Zt(Q,L,O),H=!0,V||(lt=[zt(t,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),zt(l,"pointerdown",function(){Kt(r[9]("SHAPE"))&&r[9]("SHAPE").apply(this,arguments)}),zt(p,"pointerdown",function(){Kt(r[9]("TOP"))&&r[9]("TOP").apply(this,arguments)}),zt(g,"pointerdown",function(){Kt(r[9]("RIGHT"))&&r[9]("RIGHT").apply(this,arguments)}),zt(C,"pointerdown",function(){Kt(r[9]("BOTTOM"))&&r[9]("BOTTOM").apply(this,arguments)}),zt(b,"pointerdown",function(){Kt(r[9]("LEFT"))&&r[9]("LEFT").apply(this,arguments)})],V=!0)},p(L,O){r=L,(!H||O&2&&e!==(e=r[1]?"display:none;":void 0))&&M(t,"style",e),(!H||O&16&&i!==(i=r[4].x))&&M(t,"x",i),(!H||O&16&&s!==(s=r[4].y))&&M(t,"y",s),(!H||O&16&&n!==(n=r[4].w))&&M(t,"width",n),(!H||O&16&&o!==(o=r[4].h))&&M(t,"height",o),(!H||O&2)&&M(l,"style",r[1]),(!H||O&16&&h!==(h=r[4].x))&&M(l,"x",h),(!H||O&16&&c!==(c=r[4].y))&&M(l,"y",c),(!H||O&16&&u!==(u=r[4].w))&&M(l,"width",u),(!H||O&16&&d!==(d=r[4].h))&&M(l,"height",d),(!H||O&16&&m!==(m=r[4].x))&&M(p,"x",m),(!H||O&16&&_!==(_=r[4].y))&&M(p,"y",_),(!H||O&16&&y!==(y=r[4].w))&&M(p,"width",y),(!H||O&16&&v!==(v=r[4].x+r[4].w))&&M(g,"x",v),(!H||O&16&&w!==(w=r[4].y))&&M(g,"y",w),(!H||O&16&&I!==(I=r[4].h))&&M(g,"height",I),(!H||O&16&&N!==(N=r[4].x))&&M(C,"x",N),(!H||O&16&&S!==(S=r[4].y+r[4].h))&&M(C,"y",S),(!H||O&16&&R!==(R=r[4].w))&&M(C,"width",R),(!H||O&16&&D!==(D=r[4].x))&&M(b,"x",D),(!H||O&16&&F!==(F=r[4].y))&&M(b,"y",F),(!H||O&16&&G!==(G=r[4].h))&&M(b,"height",G);const _t={};O&16&&(_t.x=r[4].x),O&16&&(_t.y=r[4].y),O&8&&(_t.scale=r[3]),B.$set(_t);const ht={};O&16&&(ht.x=r[4].x+r[4].w),O&16&&(ht.y=r[4].y),O&8&&(ht.scale=r[3]),P.$set(ht);const vt={};O&16&&(vt.x=r[4].x+r[4].w),O&16&&(vt.y=r[4].y+r[4].h),O&8&&(vt.scale=r[3]),j.$set(vt);const xt={};O&16&&(xt.x=r[4].x),O&16&&(xt.y=r[4].y+r[4].h),O&8&&(xt.scale=r[3]),Q.$set(xt)},i(L){H||(st(B.$$.fragment,L),st(P.$$.fragment,L),st(j.$$.fragment,L),st(Q.$$.fragment,L),H=!0)},o(L){ut(B.$$.fragment,L),ut(P.$$.fragment,L),ut(j.$$.fragment,L),ut(Q.$$.fragment,L),H=!1},d(L){L&&(ct(t),ct(a),ct(l),ct(f),ct(p),ct(x),ct(g),ct(A),ct(C),ct(E),ct(b),ct($),ct(K),ct(U),ct(rt)),Jt(B,L),Jt(P,L),Jt(j,L),Jt(Q,L),V=!1,Qe(lt)}}}function tE(r){let t,e;return t=new Rf({props:{shape:r[0],transform:r[2],editor:r[5],$$slots:{default:[Qw,({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(){ee(t.$$.fragment)},m(i,s){Zt(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||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function eE(r,t,e){let i,{shape:s}=t,{computedStyle:n}=t,{transform:o}=t,{viewportScale:a=1}=t;const l=(d,f,p)=>{const m=d.geometry.bounds;let[_,y]=[m.minX,m.minY],[x,g]=[m.maxX,m.maxY];const[v,w]=p;if(f==="SHAPE")_+=v,x+=v,y+=w,g+=w;else{switch(f){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{y+=w;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{g+=w;break}}switch(f){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{_+=v;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{x+=v;break}}}const I=Math.min(_,x),A=Math.min(y,g),C=Math.abs(x-_),N=Math.abs(g-y);return{...d,geometry:{x:I,y:A,w:C,h:N,bounds:{minX:I,minY:A,maxX:I+C,maxY:A+N}}}};function h(d){rr.call(this,r,d)}function c(d){rr.call(this,r,d)}function u(d){rr.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,c,u]}class rE extends ae{constructor(t){super(),oe(this,t,eE,tE,te,{shape:0,computedStyle:1,transform:2,viewportScale:3})}}Ui.RECTANGLE,Ui.POLYGON;const iE=r=>({}),Cf=r=>({grab:r[0]});function sE(r){let t,e,i,s;const n=r[7].default,o=$h(n,r,r[6],Cf);return{c(){t=Tt("g"),o&&o.c(),M(t,"class","a9s-annotation selected")},m(a,l){ft(a,t,l),o&&o.m(t,null),e=!0,i||(s=[zt(t,"pointerup",r[2]),zt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&64)&&Vh(o,n,a,a[6],e?Xh(n,a[6],l,iE):zh(a[6]),Cf)},i(a){e||(st(o,a),e=!0)},o(a){ut(o,a),e=!1},d(a){a&&ct(t),o&&o.d(a),i=!1,Qe(s)}}}function nE(r,t,e){let{$$slots:i={},$$scope:s}=t;const n=Hs();let{shape:o}=t,{editor:a}=t,{transform:l}=t,h,c,u;const d=m=>_=>{h=m,c=l.elementToImage(_.offsetX,_.offsetY),u=o,_.target.setPointerCapture(_.pointerId),n("grab",_)},f=m=>{if(h){const[_,y]=l.elementToImage(m.offsetX,m.offsetY),x=[_-c[0],y-c[1]];e(3,o=a(u,h,x)),n("change",o)}},p=m=>{m.target.releasePointerCapture(m.pointerId),h=void 0,u=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,f,p,o,a,l,s,i]}class Rf extends ae{constructor(t){super(),oe(this,t,nE,sE,te,{shape:3,editor:4,transform:5})}}const oE=(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 aE(r,t,e){let i;const s=Hs();let{annotation:n}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return $s(()=>(e(6,u=new o({target:l,props:{shape:n.target.selector,computedStyle:i,transform:h,viewportScale:c}})),u.$on("change",d=>{u.$$set({shape:d.detail}),s("change",d.detail)}),u.$on("grab",d=>s("grab",d.detail)),u.$on("release",d=>s("release",d.detail)),()=>{u.$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,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&5&&e(7,i=oE(n,a)),r.$$.dirty&65&&n&&(u==null||u.$set({shape:n.target.selector})),r.$$.dirty&80&&u&&u.$set({transform:h}),r.$$.dirty&96&&u&&u.$set({viewportScale:c}),r.$$.dirty&192&&u&&i&&u.$set({computedStyle:i})},[n,o,a,l,h,c,u,i]}class lE extends ae{constructor(t){super(),oe(this,t,aE,null,te,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1;const hE=r=>({transform:r&2,scale:r&1}),Pf=r=>({transform:r[1],scale:r[0]});function cE(r){let t;const e=r[4].default,i=$h(e,r,r[3],Pf);return{c(){i&&i.c()},m(s,n){i&&i.m(s,n),t=!0},p(s,[n]){i&&i.p&&(!t||n&11)&&Vh(i,e,s,s[3],t?Xh(e,s[3],n,hE):zh(s[3]),Pf)},i(s){t||(st(i,s),t=!0)},o(s){ut(i,s),t=!1},d(s){i&&i.d(s)}}}function uE(r,t,e){let{$$slots:i={},$$scope:s}=t,{viewer:n}=t,o=1,a;const l=()=>{const h=n.viewport.getContainerSize().x,c=n.viewport.getZoom(!0),u=n.viewport.getFlip(),d=n.viewport.pixelFromPoint(new Nt.Point(0,0),!0);u&&(d.x=h-d.x);const f=c*h/n.world.getContentFactor(),p=u?-f:f,m=n.viewport.getRotation(!0);e(1,a=`translate(${d.x}, ${d.y}) scale(${p}, ${f}) rotate(${m})`),e(0,o=c*h/n.world.getContentFactor())};return $s(()=>(n.addHandler("update-viewport",l),()=>{n.removeHandler("update-viewport",l)})),r.$$set=h=>{"viewer"in h&&e(2,n=h.viewer),"$$scope"in h&&e(3,s=h.$$scope)},[o,a,n,s,i]}class Mf extends ae{constructor(t){super(),oe(this,t,uE,cE,te,{viewer:2})}}function dE(r,t,e){const i=Hs();let{drawingMode:s}=t,{target:n}=t,{tool:o}=t,{transform:a}=t,{viewer:l}=t,{viewportScale:h}=t,c;return $s(()=>{const u=n.closest("svg"),d=[],f=(p,m,_)=>{if(u==null||u.addEventListener(p,m,_),d.push(()=>u==null?void 0:u.removeEventListener(p,m,_)),p==="pointerup"||p==="dblclick"){const y=g=>{const{originalEvent:v}=g;m(v)},x=p==="pointerup"?"canvas-click":"canvas-double-click";l.addHandler(x,y),d.push(()=>l.removeHandler(x,y))}else if(p==="pointermove"){const y=x=>{const{originalEvent:g}=x;m(g)};l.addHandler("canvas-drag",y),d.push(()=>l.removeHandler("canvas-drag",y))}};return e(6,c=new o({target:n,props:{addEventListener:f,drawingMode:s,transform:a,viewportScale:h}})),c.$on("create",p=>i("create",p.detail)),()=>{d.forEach(p=>p()),c.$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),"viewer"in u&&e(4,l=u.viewer),"viewportScale"in u&&e(5,h=u.viewportScale)},r.$$.update=()=>{r.$$.dirty&72&&c&&c.$set({transform:a}),r.$$.dirty&96&&c&&c.$set({viewportScale:h})},[s,n,o,a,l,h,c]}class fE extends ae{constructor(t){super(),oe(this,t,dE,null,te,{drawingMode:0,target:1,tool:2,transform:3,viewer:4,viewportScale:5})}}function Bf(r,t,e){const i=r.slice();i[33]=t[e];const s=i[14](i[33].target.selector);return i[34]=s,i}function pE(r){let t=r[2],e,i,s=Df(r);return{c(){s.c(),e=er()},m(n,o){s.m(n,o),ft(n,e,o),i=!0},p(n,o){o[0]&4&&te(t,t=n[2])?(De(),ut(s,1,1,Be),Oe(),s=Df(n),s.c(),st(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(st(s),i=!0)},o(n){ut(s),i=!1},d(n){n&&ct(e),s.d(n)}}}function mE(r){let t,e,i=ui(r[6].filter(r[23])),s=[];for(let o=0;o<i.length;o+=1)s[o]=Lf(Bf(r,i,o));const n=o=>ut(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=er()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ft(o,t,a),e=!0},p(o,a){if(a[0]&24162|a[1]&2){i=ui(o[6].filter(o[23]));let l;for(l=0;l<i.length;l+=1){const h=Bf(o,i,l);s[l]?(s[l].p(h,a),st(s[l],1)):(s[l]=Lf(h),s[l].c(),st(s[l],1),s[l].m(t.parentNode,t))}for(De(),l=i.length;l<s.length;l+=1)n(l);Oe()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)st(s[a]);e=!0}},o(o){s=s.filter(Boolean);for(let a=0;a<s.length;a+=1)ut(s[a]);e=!1},d(o){o&&ct(t),Po(s,o)}}}function Df(r){let t,e;return t=new fE({props:{target:r[5],tool:r[7],drawingMode:r[4],transform:{elementToImage:r[9]},viewer:r[3],viewportScale:r[32]}}),t.$on("create",r[13]),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s[0]&32&&(n.target=i[5]),s[0]&128&&(n.tool=i[7]),s[0]&16&&(n.drawingMode=i[4]),s[0]&8&&(n.viewer=i[3]),s[1]&2&&(n.viewportScale=i[32]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Of(r){let t=r[33].id,e,i,s=Ff(r);return{c(){s.c(),e=er()},m(n,o){s.m(n,o),ft(n,e,o),i=!0},p(n,o){o[0]&64&&te(t,t=n[33].id)?(De(),ut(s,1,1,Be),Oe(),s=Ff(n),s.c(),st(s,1),s.m(e.parentNode,e)):s.p(n,o)},i(n){i||(st(s),i=!0)},o(n){ut(s),i=!1},d(n){n&&ct(e),s.d(n)}}}function Ff(r){let t,e;return t=new lE({props:{target:r[5],editor:r[14](r[33].target.selector),annotation:r[33],style:r[1],transform:{elementToImage:r[9]},viewportScale:r[32]}}),t.$on("grab",r[10]),t.$on("change",function(){Kt(r[12](r[33]))&&r[12](r[33]).apply(this,arguments)}),t.$on("release",r[11]),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){r=i;const n={};s[0]&32&&(n.target=r[5]),s[0]&64&&(n.editor=r[14](r[33].target.selector)),s[0]&64&&(n.annotation=r[33]),s[0]&2&&(n.style=r[1]),s[1]&2&&(n.viewportScale=r[32]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Lf(r){let t,e,i=r[34]&&Of(r);return{c(){i&&i.c(),t=er()},m(s,n){i&&i.m(s,n),ft(s,t,n),e=!0},p(s,n){s[34]?i?(i.p(s,n),n[0]&64&&st(i,1)):(i=Of(s),i.c(),st(i,1),i.m(t.parentNode,t)):i&&(De(),ut(i,1,1,()=>{i=null}),Oe())},i(s){e||(st(i),e=!0)},o(s){ut(i),e=!1},d(s){s&&ct(t),i&&i.d(s)}}}function gE(r){let t,e,i,s,n,o;const a=[mE,pE],l=[];function h(c,u){return c[5]&&c[6]?0:c[5]&&c[7]&&c[0]?1:-1}return~(i=h(r))&&(s=l[i]=a[i](r)),{c(){t=Tt("svg"),e=Tt("g"),s&&s.c(),M(e,"transform",n=r[31]),M(e,"class","svelte-190cqdf"),M(t,"class","a9s-annotationlayer a9s-osd-drawinglayer svelte-190cqdf"),Gs(t,"drawing",r[0])},m(c,u){ft(c,t,u),tr(t,e),~i&&l[i].m(e,null),r[24](e),o=!0},p(c,u){let d=i;i=h(c),i===d?~i&&l[i].p(c,u):(s&&(De(),ut(l[d],1,1,()=>{l[d]=null}),Oe()),~i?(s=l[i],s?s.p(c,u):(s=l[i]=a[i](c),s.c()),st(s,1),s.m(e,null)):s=null),(!o||u[1]&1&&n!==(n=c[31]))&&M(e,"transform",n),(!o||u[0]&1)&&Gs(t,"drawing",c[0])},i(c){o||(st(s),o=!0)},o(c){ut(s),o=!1},d(c){c&&ct(t),~i&&l[i].d(),r[24](null)}}}function yE(r){let t,e;return t=new Mf({props:{viewer:r[3],$$slots:{default:[gE,({transform:i,scale:s})=>({31:i,32:s}),({transform:i,scale:s})=>[0,(i?1:0)|(s?2:0)]]},$$scope:{ctx:r}}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s[0]&8&&(n.viewer=i[3]),s[0]&255|s[1]&67&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function _E(r,t,e){let i,s,n,o,{drawingEnabled:a}=t,{filter:l}=t,{preferredDrawingMode:h}=t,{state:c}=t,{style:u=void 0}=t,{toolName:d=Fs()[0]}=t,{user:f}=t,{viewer:p}=t;const m=()=>d,_=()=>a,y=navigator.userAgent.match(/firefox|fxios/i);let x;const{store:g,selection:v,hover:w}=c;Ro(r,v,B=>e(22,o=B));let I,A,C;const N=B=>{g.unobserve(I);const K=B.filter(({editable:P})=>P).map(({id:P})=>P);if(K.length>0){if(e(6,A=K.map(P=>g.getAnnotation(P))),I=P=>{const{updated:U}=P.changes;e(6,A=(U||[]).map(j=>j.newValue))},g.observe(I,{annotations:K}),y){const{width:P}=p.viewport.viewerElementToViewportRectangle(new Nt.Rect(0,0,1,1));p.viewport.panBy(new Nt.Point(Math.abs(P/10),0))}}else e(6,A=void 0)},S=(B,K)=>{const{x:P,y:U}=p.viewport.viewerElementToImageCoordinates(new Nt.Point(B,K));return[P,U]},R=B=>{p.setMouseNavEnabled(!1),C=B.timeStamp},E=B=>{if(p.setMouseNavEnabled(!0),performance.now()-(C||0)<300){const{offsetX:P,offsetY:U}=B.detail,[j,rt]=S(P,U),Q=g.getAt(j,rt);Q&&(!l||l(Q))&&!A.find(V=>V.id===Q.id)&&(w.set(Q.id),v.setSelected(Q.id))}},b=B=>K=>{var rt;const{target:P}=B,U=10*60*1e3,j=((rt=P.creator)==null?void 0:rt.id)!==f.id||!P.created||new Date().getTime()-P.created.getTime()>U;g.updateTarget({...P,selector:K.detail,created:j?P.created:new Date,updated:j?new Date:void 0,updatedBy:j?f:void 0})},D=B=>{const K=kw(),P={id:K,bodies:[],target:{annotation:K,selector:B.detail,creator:f,created:new Date}};g.addAnnotation(P),v.setSelected(P.id),p.setMouseNavEnabled(!0)},F=B=>dh(B),G=B=>Je(B);function $(B){Xs[B?"unshift":"push"](()=>{x=B,e(5,x)})}return r.$$set=B=>{"drawingEnabled"in B&&e(0,a=B.drawingEnabled),"filter"in B&&e(15,l=B.filter),"preferredDrawingMode"in B&&e(16,h=B.preferredDrawingMode),"state"in B&&e(17,c=B.state),"style"in B&&e(1,u=B.style),"toolName"in B&&e(2,d=B.toolName),"user"in B&&e(18,f=B.user),"viewer"in B&&e(3,p=B.viewer)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(7,{tool:i,opts:s}=Ls(d)||{tool:void 0,opts:void 0},i,(e(21,s),e(2,d))),r.$$.dirty[0]&2162688&&e(4,n=(s==null?void 0:s.drawingMode)||h),r.$$.dirty[0]&25&&(a&&n==="drag"?p.setMouseNavEnabled(!1):p.setMouseNavEnabled(!0)),r.$$.dirty[0]&1&&a&&v.clear(),r.$$.dirty[0]&4194329&&o.selected.length===0&&n==="drag"&&a&&p.setMouseNavEnabled(!1),r.$$.dirty[0]&4194304&&N(o.selected)},[a,u,d,p,n,x,A,i,v,S,R,E,b,D,F,l,h,c,f,m,_,s,o,G,$]}class vE extends ae{constructor(t){super(),oe(this,t,_E,yE,te,{drawingEnabled:0,filter:15,preferredDrawingMode:16,state:17,style:1,toolName:2,user:18,viewer:3,getDrawingTool:19,isDrawingEnabled:20},null,[-1,-1])}get getDrawingTool(){return this.$$.ctx[19]}get isDrawingEnabled(){return this.$$.ctx[20]}}function xE(r){let t,e,i,s,n,o,a,l=r[2].appearance.label+"",h,c,u,d;return{c(){t=Tt("g"),e=Tt("rect"),a=Tt("text"),h=Mo(l),M(e,"class","a9s-presence-label-bg svelte-1rehw2p"),M(e,"x",r[0]),M(e,"y",i=r[1]-18/r[3]),M(e,"height",s=18/r[3]),M(e,"fill",n=r[2].appearance.color),M(e,"stroke",o=r[2].appearance.color),M(a,"font-size",c=12/r[3]),M(a,"x",u=r[0]+Math.round(5/r[3])),M(a,"y",d=r[1]-5/r[3]),M(a,"class","svelte-1rehw2p"),M(t,"class","a9s-presence-label")},m(f,p){ft(f,t,p),tr(t,e),tr(t,a),tr(a,h),r[6](t)},p(f,[p]){p&1&&M(e,"x",f[0]),p&10&&i!==(i=f[1]-18/f[3])&&M(e,"y",i),p&8&&s!==(s=18/f[3])&&M(e,"height",s),p&4&&n!==(n=f[2].appearance.color)&&M(e,"fill",n),p&4&&o!==(o=f[2].appearance.color)&&M(e,"stroke",o),p&4&&l!==(l=f[2].appearance.label+"")&&qg(h,l),p&8&&c!==(c=12/f[3])&&M(a,"font-size",c),p&9&&u!==(u=f[0]+Math.round(5/f[3]))&&M(a,"x",u),p&10&&d!==(d=f[1]-5/f[3])&&M(a,"y",d)},i:Be,o:Be,d(f){f&&ct(t),r[6](null)}}}function bE(r,t,e){let{x:i}=t,{y:s}=t,{user:n}=t,{scale:o}=t,{hAlign:a=null}=t,l;const h=u=>{const d=l.querySelector("text"),f=l.querySelector("rect"),p=d.getBBox().width+10/u;a==="CENTER"&&l.setAttribute("style",`transform: translateX(-${p/2}px)`),f.setAttribute("width",`${p}`)};function c(u){Xs[u?"unshift":"push"](()=>{l=u,e(4,l)})}return r.$$set=u=>{"x"in u&&e(0,i=u.x),"y"in u&&e(1,s=u.y),"user"in u&&e(2,n=u.user),"scale"in u&&e(3,o=u.scale),"hAlign"in u&&e(5,a=u.hAlign)},r.$$.update=()=>{r.$$.dirty&24&&l&&h(o)},[i,s,n,o,l,a,c]}class Nf extends ae{constructor(t){super(),oe(this,t,bE,xE,te,{x:0,y:1,user:2,scale:3,hAlign:5})}}function wE(r){let t,e,i,s,n,o;return e=new Nf({props:{scale:r[1],user:r[0],x:r[3][0],y:r[3][1],hAlign:"CENTER"}}),{c(){t=Tt("g"),ee(e.$$.fragment),i=Tt("polygon"),M(i,"class","a9s-presence-shape a9s-presence-polygon svelte-fgq4n0"),M(i,"stroke",s=r[0].appearance.color),M(i,"fill","transparent"),M(i,"points",n=r[2].points.map(Uf).join(" ")),M(t,"class","a9s-presence-overlay")},m(a,l){ft(a,t,l),Zt(e,t,null),tr(t,i),o=!0},p(a,[l]){const h={};l&2&&(h.scale=a[1]),l&1&&(h.user=a[0]),l&8&&(h.x=a[3][0]),l&8&&(h.y=a[3][1]),e.$set(h),(!o||l&1&&s!==(s=a[0].appearance.color))&&M(i,"stroke",s),(!o||l&4&&n!==(n=a[2].points.map(Uf).join(" ")))&&M(i,"points",n)},i(a){o||(st(e.$$.fragment,a),o=!0)},o(a){ut(e.$$.fragment,a),o=!1},d(a){a&&ct(t),Jt(e)}}}const Uf=r=>r.join(",");function EE(r,t,e){let i,s,{annotation:n}=t,{user:o}=t,{scale:a}=t;const l=h=>{let[c,...u]=h.points;return u.forEach(([d,f])=>{f<c[1]&&(c=[d,f])}),c};return r.$$set=h=>{"annotation"in h&&e(4,n=h.annotation),"user"in h&&e(0,o=h.user),"scale"in h&&e(1,a=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=n.target.selector.geometry),r.$$.dirty&4&&e(3,s=l(i))},[o,a,i,s,n]}class TE extends ae{constructor(t){super(),oe(this,t,EE,wE,te,{annotation:4,user:0,scale:1})}}function AE(r){let t,e,i,s,n,o,a,l,h;return e=new Nf({props:{scale:r[1],user:r[0],x:r[2].x,y:r[2].y}}),{c(){t=Tt("g"),ee(e.$$.fragment),i=Tt("rect"),M(i,"class","a9s-presence-shape a9s-presence-rectangle svelte-gze948"),M(i,"stroke",s=r[0].appearance.color),M(i,"fill","transparent"),M(i,"x",n=r[2].x),M(i,"y",o=r[2].y),M(i,"width",a=r[2].w),M(i,"height",l=r[2].h),M(t,"class","a9s-presence-overlay")},m(c,u){ft(c,t,u),Zt(e,t,null),tr(t,i),h=!0},p(c,[u]){const d={};u&2&&(d.scale=c[1]),u&1&&(d.user=c[0]),u&4&&(d.x=c[2].x),u&4&&(d.y=c[2].y),e.$set(d),(!h||u&1&&s!==(s=c[0].appearance.color))&&M(i,"stroke",s),(!h||u&4&&n!==(n=c[2].x))&&M(i,"x",n),(!h||u&4&&o!==(o=c[2].y))&&M(i,"y",o),(!h||u&4&&a!==(a=c[2].w))&&M(i,"width",a),(!h||u&4&&l!==(l=c[2].h))&&M(i,"height",l)},i(c){h||(st(e.$$.fragment,c),h=!0)},o(c){ut(e.$$.fragment,c),h=!1},d(c){c&&ct(t),Jt(e)}}}function SE(r,t,e){let i,{annotation:s}=t,{user:n}=t,{scale:o}=t;return r.$$set=a=>{"annotation"in a&&e(3,s=a.annotation),"user"in a&&e(0,n=a.user),"scale"in a&&e(1,o=a.scale)},r.$$.update=()=>{r.$$.dirty&8&&e(2,i=s.target.selector.geometry)},[n,o,i,s]}class IE extends ae{constructor(t){super(),oe(this,t,SE,AE,te,{annotation:3,user:0,scale:1})}}const{Boolean:CE}=jg;function kf(r,t,e){const i=r.slice();return i[8]=t[e],i}function Gf(r){let t,e;return t=new Mf({props:{viewer:r[0],$$slots:{default:[ME,({transform:i,scale:s})=>({6:i,7:s}),({transform:i,scale:s})=>(i?64:0)|(s?128:0)]},$$scope:{ctx:r}}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s&1&&(n.viewer=i[0]),s&2244&&(n.$$scope={dirty:s,ctx:i}),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function $f(r){let t,e,i=ui(r[2]),s=[];for(let o=0;o<i.length;o+=1)s[o]=Hf(kf(r,i,o));const n=o=>ut(s[o],1,1,()=>{s[o]=null});return{c(){for(let o=0;o<s.length;o+=1)s[o].c();t=er()},m(o,a){for(let l=0;l<s.length;l+=1)s[l]&&s[l].m(o,a);ft(o,t,a),e=!0},p(o,a){if(a&132){i=ui(o[2]);let l;for(l=0;l<i.length;l+=1){const h=kf(o,i,l);s[l]?(s[l].p(h,a),st(s[l],1)):(s[l]=Hf(h),s[l].c(),st(s[l],1),s[l].m(t.parentNode,t))}for(De(),l=i.length;l<s.length;l+=1)n(l);Oe()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)st(s[a]);e=!0}},o(o){s=s.filter(CE);for(let a=0;a<s.length;a+=1)ut(s[a]);e=!1},d(o){o&&ct(t),Po(s,o)}}}function RE(r){let t,e;return t=new TE({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s&4&&(n.annotation=i[8].annotation),s&4&&(n.user=i[8].selectedBy),s&128&&(n.scale=i[7]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function PE(r){let t,e;return t=new IE({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){ee(t.$$.fragment)},m(i,s){Zt(t,i,s),e=!0},p(i,s){const n={};s&4&&(n.annotation=i[8].annotation),s&4&&(n.user=i[8].selectedBy),s&128&&(n.scale=i[7]),t.$set(n)},i(i){e||(st(t.$$.fragment,i),e=!0)},o(i){ut(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Hf(r){let t,e,i,s;const n=[PE,RE],o=[];function a(l,h){return l[8].annotation.target.selector.type===wt.RECTANGLE?0:l[8].annotation.target.selector.type===wt.POLYGON?1:-1}return~(t=a(r))&&(e=o[t]=n[t](r)),{c(){e&&e.c(),i=er()},m(l,h){~t&&o[t].m(l,h),ft(l,i,h),s=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(De(),ut(o[c],1,1,()=>{o[c]=null}),Oe()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=n[t](l),e.c()),st(e,1),e.m(i.parentNode,i)):e=null)},i(l){s||(st(e),s=!0)},o(l){ut(e),s=!1},d(l){l&&ct(i),~t&&o[t].d(l)}}}function ME(r){let t,e,i,s,n=r[2].length>0&&$f(r);return{c(){t=Tt("svg"),e=Tt("g"),n&&n.c(),M(e,"transform",i=r[6]),M(t,"class","a9s-osd-presencelayer svelte-1krwc4m")},m(o,a){ft(o,t,a),tr(t,e),n&&n.m(e,null),s=!0},p(o,a){o[2].length>0?n?(n.p(o,a),a&4&&st(n,1)):(n=$f(o),n.c(),st(n,1),n.m(e,null)):n&&(De(),ut(n,1,1,()=>{n=null}),Oe()),(!s||a&64&&i!==(i=o[6]))&&M(e,"transform",i)},i(o){s||(st(n),s=!0)},o(o){ut(n),s=!1},d(o){o&&ct(t),n&&n.d()}}}function BE(r){let t=!!r[1],e,i,s=t&&Gf(r);return{c(){s&&s.c(),e=er()},m(n,o){s&&s.m(n,o),ft(n,e,o),i=!0},p(n,[o]){o&2&&(t=!!n[1]),t?s?(s.p(n,o),o&2&&st(s,1)):(s=Gf(n),s.c(),st(s,1),s.m(e.parentNode,e)):s&&(De(),ut(s,1,1,()=>{s=null}),Oe())},i(n){i||(st(s),i=!0)},o(n){ut(s),i=!1},d(n){n&&ct(e),s&&s.d(n)}}}function DE(r,t,e){let{store:i}=t,{viewer:s}=t,{provider:n}=t,o=[],a;const l=(h,c)=>{e(2,o=[...o.filter(({selectedBy:u})=>u.presenceKey!==h.presenceKey),...(c||[]).map(u=>({annotation:i.getAnnotation(u),selectedBy:h}))].filter(({annotation:u})=>(u||console.warn("Selection event on unknown annotation"),!!u))),a&&i.unobserve(a),a=u=>{const{deleted:d,updated:f}=u.changes,p=new Set((d||[]).map(_=>_.id)),m=o.filter(({annotation:_})=>!p.has(_.id)).map(_=>{const y=(f||[]).find(x=>x.oldValue.id===_.annotation.id);return y?{selectedBy:_.selectedBy,annotation:y.newValue}:_});e(2,o=m)},i.observe(a,{annotations:o.map(u=>u.annotation.id)})};return Zg(()=>{a&&i.unobserve(a)}),r.$$set=h=>{"store"in h&&e(3,i=h.store),"viewer"in h&&e(0,s=h.viewer),"provider"in h&&e(1,n=h.provider)},r.$$.update=()=>{r.$$.dirty&2&&n&&n.on("selectionChange",l)},[s,n,o,i]}class OE extends ae{constructor(t){super(),oe(this,t,DE,BE,te,{store:3,viewer:0,provider:1})}}const Xf=(r,t)=>{t==="auto"?r.addHandler("open",e=>{const i=r.world.getItemCount();r.world.getItemAt(i-1).addOnceHandler("fully-loaded-change",n=>{const{fullyLoaded:o}=n;if(o){const a=r.canvas.querySelector("canvas"),l=Oh(a);r.element.setAttribute("data-theme",l)}})}):r.element.setAttribute("data-theme",t)},Vf=(r,t,e)=>(i,s={})=>{const n=typeof i=="string"?i:i.id,o=t.getAnnotation(n);if(!o||!Je(o))return;const a=r.container.getBoundingClientRect(),{padding:l}=s;let[h,c,u,d]=l?Array.isArray(l)?l:[l,l,l,l]:[0,0,0,0];h=h/a.height,c=c/a.width,u=u/a.height,d=d/a.width;const{minX:f,minY:p,maxX:m,maxY:_}=o.target.selector.geometry.bounds,y=m-f,x=_-p,g=f-d*y,v=p-h*x,w=y+(c+d)*y,I=x+(h+u)*x,A=r.viewport.imageToViewportRectangle(g,v,w,I);r.viewport[e](A,s.immediately)},FE=(r,t)=>Vf(r,t,"fitBounds"),LE=(r,t)=>Vf(r,t,"fitBoundsWithConstraints"),NE=(r,t={})=>{const e=Lh(t,{drawingEnabled:!1,drawingMode:ch?"drag":"click",userSelectAction:io.EDIT,theme:"light"}),i=Dh(e),{hover:s,selection:n,store:o}=i,a=hp(o),l=cp(i,a,e.adapter,e.autoSave);let h=_p(),c=e.drawingEnabled,u=e.drawingMode;const d=Uh(a,r.element),f=new Fw({target:r.element,props:{state:i,viewer:r,style:e.style,filter:void 0}}),p=new OE({target:r.element.querySelector(".openseadragon-canvas"),props:{provider:void 0,store:o,viewer:r}}),m=new vE({target:r.element.querySelector(".openseadragon-canvas"),props:{drawingEnabled:!!c,filter:void 0,preferredDrawingMode:u,state:i,style:e.style,user:h,viewer:r}});f.$on("click",B=>{const{originalEvent:K,annotation:P}=B.detail;e.modalSelect?n.isEmpty()&&P&&n.userSelect(P.id,K):P&&!(u==="click"&&c)?n.userSelect(P.id,K):n.isEmpty()||n.clear()}),r.element.addEventListener("pointerdown",B=>{if(s.current){const K=o.getAnnotation(s.current);l.emit("clickAnnotation",K,B)}}),Xf(r,e.theme);const _=dp(i,a,e.adapter),y=()=>{m.$set({drawingEnabled:!1}),setTimeout(()=>m.$set({drawingEnabled:!0}),1)},x=()=>{f.$destroy(),p.$destroy(),m.$destroy(),d.destroy(),a.destroy()},g=FE(r,o),v=LE(r,o),w=()=>m.getDrawingTool(),I=()=>h,A=()=>m.isDrawingEnabled(),C=(B,K,P)=>vh(B,K,P),N=(B,K)=>fh(B,K),S=B=>{if(!Ls(B))throw`No drawing tool named ${B}`;m.$set({toolName:B})},R=B=>{c=B,m.$set({drawingEnabled:c})},E=B=>{f.$set({filter:B}),m.$set({filter:B})},b=B=>{f.$set({style:B}),m.$set({style:B})},D=B=>p.$set({provider:B}),F=B=>Xf(r,B),G=B=>{h=B,m.$set({user:B})},$=B=>f.$set({visible:B});return{..._,cancelDrawing:y,destroy:x,fitBounds:g,fitBoundsWithConstraints:v,getDrawingTool:w,getUser:I,isDrawingEnabled:A,listDrawingTools:Fs,on:l.on,off:l.off,registerDrawingTool:C,registerShapeEditor:N,setDrawingEnabled:R,setDrawingTool:S,setFilter:E,setPresenceProvider:D,setStyle:b,setTheme:F,setUser:G,setVisible:$,state:i,viewer:r}};Mt.ShapeType=wt,Mt.UserSelectAction=io,Mt.W3CImageFormat=Dm,Mt.chainStyles=Em,Mt.computeStyle=wm,Mt.createBody=tp,Mt.createImageAnnotator=Vg,Mt.createOSDAnnotator=NE,Mt.defaultColorProvider=xp,Object.defineProperty(Mt,Symbol.toStringTag,{value:"Module"})});
1148
1148
  //# sourceMappingURL=annotorious-openseadragon.js.map