@annotorious/openseadragon 3.8.1 → 3.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
- (function(qt,se){typeof exports=="object"&&typeof module<"u"?se(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],se):(qt=typeof globalThis<"u"?globalThis:qt||self,se(qt.AnnotoriousOSD={},qt.OpenSeadragon))})(this,function(qt,se){"use strict";var FC=Object.defineProperty;var kC=(qt,se,si)=>se in qt?FC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:si}):qt[se]=si;var Yh=(qt,se,si)=>kC(qt,typeof se!="symbol"?se+"":se,si);var si=Object.prototype.hasOwnProperty;function oi(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--&&oi(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(si.call(r,e)&&++i&&!si.call(t,e)||!(e in t)||!oi(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0});var ra=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(ra||{});const fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function gg(r,t=0){return(fe[r[t+0]]+fe[r[t+1]]+fe[r[t+2]]+fe[r[t+3]]+"-"+fe[r[t+4]]+fe[r[t+5]]+"-"+fe[r[t+6]]+fe[r[t+7]]+"-"+fe[r[t+8]]+fe[r[t+9]]+"-"+fe[r[t+10]]+fe[r[t+11]]+fe[r[t+12]]+fe[r[t+13]]+fe[r[t+14]]+fe[r[t+15]]).toLowerCase()}const yg=new Uint8Array(16);function _g(){return crypto.getRandomValues(yg)}function vg(r,t,e){return crypto.randomUUID?crypto.randomUUID():bg(r)}function bg(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??_g();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,gg(n)}const ia=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)}},xg=(r,t,e,i)=>({id:vg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),wg=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Eg=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Tg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!oi(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Ag=(r,t)=>!oi(r.target,t.target),Sg=(r,t)=>{const e=wg(r,t),i=Eg(r,t),n=Tg(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:Ag(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Nr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Nr||{});const Cg=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=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=>!s.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=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(g=>g.oldValue.id===f.id).newValue;return Sg(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let Ig=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;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(n=>t!==n)}}});const Pg=250,Rg=(r,t)=>{const e=Ig(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:g}=p,y=performance.now();if(y-o>Pg)i.splice(n+1),i.push(g),n=i.length-1;else{const _=i.length-1;i[_]=Cg(i[_],g)}o=y}s=!1};r.observe(a,{origin:Nr.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:g})=>g)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:g})=>g)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,g)=>e.on(p,g),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:g,deleted:y}=i[n+1];h(p),u(g),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:g,deleted:y}=i[n];l(p),c(g),d(y),e.emit("undo",i[n]),n-=1}}}},Mg=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},f=(_,v)=>{const m=l.get(_);if(m){const x=m.indexOf(v);x!==-1&&m.splice(x,1)}},p=(_,v,m)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=m?m instanceof PointerEvent?m:e.serialize(m):void 0;x(S,R)}else x(v,m)})},1)},g=()=>{const{selected:_}=s,v=(_||[]).map(({id:m})=>o.getAnnotation(m));v.forEach(m=>{const x=h.find(S=>S.id===m.id);(!x||!oi(x,m))&&p("updateAnnotation",m,x)}),h=h.map(m=>v.find(({id:S})=>S===m.id)||m)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const m=o.getAnnotation(v.id);m&&!oi(m,v)&&p("updateAnnotation",m,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),m=new Set(_.map(({id:x})=>x));h.filter(x=>!m.has(x.id)).forEach(x=>{const S=o.getAnnotation(x.id);S&&!oi(S,x)&&p("updateAnnotation",S,x)}),h=[...h.filter(x=>m.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(g,1e3));const{created:v,deleted:m}=_.changes;(v||[]).forEach(x=>p("createAnnotation",x)),(m||[]).forEach(x=>p("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:S})=>{const R=h.find(C=>C.id===x.id)||x;h=h.map(C=>C.id===x.id?S:C),p("updateAnnotation",S,R)})},{origin:Nr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),m=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);m.length>0&&(h=h.map(x=>m.find(R=>R.id===x.id)||x))}},{origin:Nr.REMOTE});const y=_=>v=>{const{updated:m}=v;_?(m||[]).forEach(x=>p("updateAnnotation",x.oldValue,x.newValue)):(m||[]).forEach(x=>p("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},Og=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),Bg=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:m}=e.parse(_);v?i.addAnnotation(v,Nr.REMOTE):console.error(m)}else i.addAnnotation(ia(_),Nr.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(m=>m.id))||[]).map(m=>i.getAnnotation(m)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(m=>m.json()).then(m=>(f(m,v),m)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const m=e.parseAll||Og(e),{parsed:x,failed:S}=m(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(x,v,Nr.REMOTE)}else i.bulkAddAnnotations(_.map(ia),v,Nr.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},g=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,m=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),m}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(ia(_)),v}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:g,undo:t.undo,updateAnnotation:y}};let Lg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",Dg=r=>crypto.getRandomValues(new Uint8Array(r)),Ng=(r,t,e)=>{let i=256-256%r.length;if(i===256){let s=r.length-1;return(o=t)=>{if(!o)return"";let a="";for(;;){let l=e(o),h=o;for(;h--;)if(a+=r[l[h]&s],a.length>=o)return a}}}let n=Math.ceil(1.6*256*t/i);return(s=t)=>{if(!s)return"";let o="";for(;;){let a=e(n),l=n;for(;l--;)if(a[l]<i&&(o+=r[a[l]%r.length],o.length>=s))return o}}},Fg=(r,t=21)=>Ng(r,t|0,Dg),kg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Lg[e[r]&63];return t};const Ug=()=>({isGuest:!0,id:Fg("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Gg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],$g=()=>{const r=[...Gg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};kg();var Hg=Object.defineProperty,Vg=(r,t,e)=>t in r?Hg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ec=(r,t,e)=>Vg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function na(r,t){for(const e in t)r[e]=t[e];return r}function rc(r){return r()}function ic(){return Object.create(null)}function De(r){r.forEach(rc)}function kt(r){return typeof r=="function"}function Kt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Xg(r){return Object.keys(r).length===0}function nc(r,...t){if(r==null){for(const i of t)i(void 0);return Rt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function sa(r,t,e){r.$$.on_destroy.push(nc(t,e))}function jg(r,t,e,i){if(r){const n=sc(r,t,e,i);return r[0](n)}}function sc(r,t,e,i){return r[1]&&i?na(e.ctx.slice(),r[1](i(t))):e.ctx}function Wg(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function Yg(r,t,e,i,n,s){if(n){const o=sc(t,e,i,s);r.p(o,n)}}function zg(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 oc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ki(r){return r??""}function bt(r,t){r.appendChild(t)}function rt(r,t,e){r.insertBefore(t,e||null)}function et(r){r.parentNode&&r.parentNode.removeChild(r)}function ai(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function Y(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ac(r){return document.createTextNode(r)}function Se(){return ac(" ")}function Ne(){return ac("")}function Ct(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function b(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function qg(r){return Array.from(r.childNodes)}function ir(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 Pn;function Rn(r){Pn=r}function lc(){if(!Pn)throw new Error("Function called outside component initialization");return Pn}function Fr(r){lc().$$.on_mount.push(r)}function kr(){const r=lc();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Kg(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function oe(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ui=[],xs=[];let Gi=[];const hc=[],cc=Promise.resolve();let oa=!1;function uc(){oa||(oa=!0,cc.then(fc))}function dc(){return uc(),cc}function aa(r){Gi.push(r)}const la=new Set;let $i=0;function fc(){if($i!==0)return;const r=Pn;do{try{for(;$i<Ui.length;){const t=Ui[$i];$i++,Rn(t),Zg(t.$$)}}catch(t){throw Ui.length=0,$i=0,t}for(Rn(null),Ui.length=0,$i=0;xs.length;)xs.pop()();for(let t=0;t<Gi.length;t+=1){const e=Gi[t];la.has(e)||(la.add(e),e())}Gi.length=0}while(Ui.length);for(;hc.length;)hc.pop()();oa=!1,la.clear(),Rn(r)}function Zg(r){if(r.fragment!==null){r.update(),De(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(aa)}}function Jg(r){const t=[],e=[];Gi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Gi=t}const ws=new Set;let li;function Ce(){li={r:0,c:[],p:li}}function Ie(){li.r||De(li.c),li=li.p}function ht(r,t){r&&r.i&&(ws.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(ws.has(r))return;ws.add(r),li.c.push(()=>{ws.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Oe(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:n}=r.$$;i&&i.m(t,e),aa(()=>{const s=r.$$.on_mount.map(rc).filter(kt);r.$$.on_destroy?r.$$.on_destroy.push(...s):De(s),r.$$.on_mount=[]}),n.forEach(aa)}function Jt(r,t){const e=r.$$;e.fragment!==null&&(Jg(e.after_update),De(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Qg(r,t){r.$$.dirty[0]===-1&&(Ui.push(r),uc(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function pe(r,t,e,i,n,s,o=null,a=[-1]){const l=Pn;Rn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:ic(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:ic(),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&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&Qg(r,u)),d}):[],h.update(),c=!0,De(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=qg(t.target);h.fragment&&h.fragment.l(u),u.forEach(et)}else h.fragment&&h.fragment.c();t.intro&&ht(r.$$.fragment),Zt(r,t.target,t.anchor),fc()}Rn(l)}class me{constructor(){ec(this,"$$"),ec(this,"$$set")}$destroy(){Jt(this,1),this.$destroy=Rt}$on(t,e){if(!kt(e))return Rt;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!Xg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ty="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ty);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),ey={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,f,p=l+1;p<h;p++){var g=e(a[p],a[l],a[h]);g>d&&(f=p,d=g)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(ey);const ha={},Hi=(r,t)=>ha[r]=t,ca=r=>ha[r.type].area(r),ry=(r,t,e,i)=>ha[r.type].intersects(r,t,e,i),ge=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},Es=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Ts=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},iy=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},As=(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))},ny={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Hi(_t.ELLIPSE,ny);const sy={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=As([n,s],[o,a]);return l/h<=i}};Hi(_t.LINE,sy);const oy={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=Es(n.points),a=s.reduce((l,h)=>l+Es(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(Ts(s.points,t,e)){let a=!1;for(const l of o)if(Ts(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},ua=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return ge(t)},je=r=>r.rings.map(t=>iy(t.points)).join(" "),ay=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Hi(_t.MULTIPOLYGON,oy);const ly={area:r=>{const t=r.geometry.points;return Es(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Ts(i,t,e)}};Hi(_t.POLYGON,ly);const hy={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=da(t.points,t.closed);return Es(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=da(n.points,n.closed);return Ts(s,t,e)}else return cy(n,[t,e],i)}},da=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.type==="CURVE"||s.type=="CURVE")){const o=pc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...o.slice(1))}}return e},pc=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},cy=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.type==="CURVE"||s.type==="CURVE"){const o=pc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<o.length-1;a++)if(mc(t,o[a],o[a+1])<=e)return!0}else if(mc(t,n.point,s.point)<=e)return!0}return!1},mc=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u},fa=r=>{if(!r.points||r.points.length===0)return"";const t=[],e=r.points[0];t.push(`M ${e.point[0]} ${e.point[1]}`);for(let i=1;i<r.points.length;i++){const n=r.points[i],s=r.points[i-1];if(n.type==="CURVE"||s.type==="CURVE"){const o=s.type==="CURVE"&&s.outHandle||s.point,a=n.type==="CURVE"&&n.inHandle||n.point,l=n.point;t.push(`C ${o[0]} ${o[1]} ${a[0]} ${a[1]} ${l[0]} ${l[1]}`)}else t.push(`L ${n.point[0]} ${n.point[1]}`)}if(r.closed){const i=r.points[r.points.length-1],n=r.points[0];if(i.type==="CURVE"||n.type==="CURVE"){const s=i.outHandle||i.point,o=n.inHandle||n.point,a=n.point;t.push(`C ${s[0]} ${s[1]} ${o[0]} ${o[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Hi(_t.POLYLINE,hy);const uy={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>{const i=r.geometry;if(i.rot){const n=i.x+i.w/2,s=i.y+i.h/2,o=t-n,a=e-s,l=Math.cos(i.rot),h=Math.sin(i.rot),c=o*l+a*h,u=-o*h+a*l;return c>=-i.w/2&&c<=i.w/2&&u>=-i.h/2&&u<=i.h/2}else return t>=i.x&&t<=i.x+i.w&&e>=i.y&&e<=i.y+i.h}};Hi(_t.RECTANGLE,uy);const Ue=r=>Ss(r.target),Ss=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},dy=r=>(r==null?void 0:r.type)==="FragmentSelector"?!0:typeof r=="string"?r.indexOf("#")<0?!1:/#xywh(?:=(?:pixel:|percent:)?)(.+?),(.+?),(.+?),(.+)$/i.test(r):!1,fy=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(?:(pixel|percent):)?:?(.+?),(.+?),(.+?),(.+)*/g,n=[...e.matchAll(i)][0];if(!n)throw new Error("Not a MediaFragment: "+e);const[s,o,a,l,h,c,u]=n;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,f,p,g]=[l,h,c,u].map(parseFloat);return{type:_t.RECTANGLE,geometry:{x:d,y:f,w:p,h:g,rot:0,bounds:{minX:d,minY:t?f-g:f,maxX:d+p,maxY:t?f:f+g}}}},py=r=>{const{x:t,y:e,w:i,h:n}=r;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${e},${i},${n}`}},gc="http://www.w3.org/2000/svg",yc=r=>{const t=i=>{Array.from(i.attributes).forEach(n=>{n.name.startsWith("on")&&i.removeAttribute(n.name)})},e=r.getElementsByTagName("script");return Array.from(e).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(r.querySelectorAll("*")).forEach(t),r},my=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${gc}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},Mn=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(gc),i=t.lookupNamespaceURI(null);return e||i?yc(t).firstChild:yc(my(t)).firstChild},gy=r=>{const t=_c(r),e=[];let i=[],n=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":i.length>0&&(e.push({points:i}),i=[]),n=[s.args[0],s.args[1]],i.push([...n]);break;case"L":n=[s.args[0],s.args[1]],i.push([...n]);break;case"H":n=[s.args[0],n[1]],i.push([...n]);break;case"V":n=[n[0],s.args[0]],i.push([...n]);break;case"C":n=[s.args[4],s.args[5]],i.push([...n]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(i.length>2&&e.push({points:i}),e.length>0){const s=ge(e[0].points);return{rings:e,bounds:s}}},yy=r=>{const{point:t,inHandle:e,outHandle:i}=r;if(!e||!i)return!1;const n=e[0]-t[0],s=e[1]-t[1],o=i[0]-t[0],a=i[1]-t[1],l=n*a-s*o;return Math.abs(l)<.01},_y=r=>{const t=_c(r);let e=[],i=[0,0],n=!1;for(let o=0;o<t.length;o++){const a=t[o];switch(a.type.toUpperCase()){case"M":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"L":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"C":const l=[a.args[0],a.args[1]],h=[a.args[2],a.args[3]],c=[a.args[4],a.args[5]];if(e.length>0){const d=e[e.length-1];(l[0]!==d.point[0]||l[1]!==d.point[1])&&(d.type="CURVE",d.outHandle=l)}const u={type:h[0]!==c[0]||h[1]!==c[1]?"CURVE":"CORNER",point:c};u.type==="CURVE"&&(u.inHandle=h),e.push(u),i=c;break;case"Z":n=!0;break;default:console.warn(`Unsupported SVG path command: ${a.type}`);break}}e=e.map(o=>yy(o)?{...o,locked:!0}:o);const s=ge(da(e,n));return{points:e,closed:n,bounds:s}},_c=r=>{const t=[],e=r.replace(/,/g," ").trim(),i=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let n;for(;(n=i.exec(e))!==null;){const[,s,o]=n,a=o.trim()===""?[]:o.trim().split(/\s+/).map(Number).filter(l=>!isNaN(l));t.push({type:s,args:a})}return t},vy=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],n=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:_t.POLYGON,geometry:{points:n,bounds:ge(n)}}},by=r=>{const t=Mn(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),n=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),o={minX:e-n,minY:i-s,maxX:e+n,maxY:i+s};return{type:_t.ELLIPSE,geometry:{cx:e,cy:i,rx:n,ry:s,bounds:o}}},xy=r=>{const t=Mn(r),e=parseFloat(t.getAttribute("x1")),i=parseFloat(t.getAttribute("x2")),n=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),o={minX:Math.min(e,i),minY:Math.min(n,s),maxX:Math.max(e,i),maxY:Math.max(n,s)};return{type:_t.LINE,geometry:{points:[[e,n],[i,s]],bounds:o}}},wy=r=>{const t=Mn(r),e=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],i=e==null?void 0:e.getAttribute("d");if(!i)throw new Error("Could not parse SVG path");const n=_y(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},Ey=r=>{const t=Mn(r),e=t.nodeName==="rect"?t:Array.from(t.querySelectorAll("rect"))[0];if(!e)throw new Error("Could not parse SVG rect");const i=parseFloat(e.getAttribute("x")),n=parseFloat(e.getAttribute("y")),s=parseFloat(e.getAttribute("width")),o=parseFloat(e.getAttribute("height")),a=e.getAttribute("transform");let l=0;if(a&&a.startsWith("rotate(")){const f=a.match(/rotate\(([^)]+)\)/);f&&(l=f[1].split(/\s+/).map(parseFloat)[0]*Math.PI/180)}const h=i+s/2,c=n+o/2,u=[[i,n],[i+s,n],[i+s,n+o],[i,n+o]].map(([f,p])=>{const g=f-h,y=p-c,_=Math.cos(l),v=Math.sin(l);return[h+g*_-y*v,c+g*v+y*_]}),d=ge(u);return{type:_t.RECTANGLE,geometry:{x:i,y:n,w:s,h:o,rot:l,bounds:d}}},Ty=r=>{const t=Mn(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>gy(s)).filter(Boolean),i=e.reduce((s,o)=>[...s,...o.rings[0].points],[]),n=ge(i);return e.length===1&&e[0].rings.length===1?{type:_t.POLYGON,geometry:{points:i,bounds:n}}:{type:_t.MULTIPOLYGON,geometry:{polygons:e,bounds:n}}},Ay=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return vy(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return wy(t);if(t.includes("<path "))return Ty(t);if(t.includes("<ellipse "))return by(t);if(t.includes("<line "))return xy(t);if(t.includes("<rect "))return Ey(t);throw"Unsupported SVG shape: "+t},Sy=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${je(t)}" />`).join("")}</g>`,Cy=r=>{let t;switch(r.type){case _t.RECTANGLE:{const e=r.geometry,{x:i,y:n,w:s,h:o,rot:a}=e;if(!a)t=`<svg><rect x="${i}" y="${n}" width="${s}" height="${o}" /></svg>`;else{const l=i+s/2,h=n+o/2,c=(a??0)*180/Math.PI;t=`<svg><rect x="${i}" y="${n}" width="${s}" height="${o}" transform="rotate(${c} ${l} ${h})" /></svg>`}break}case _t.POLYGON:{const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(n=>n.join(",")).join(" ")}" /></svg>`;break}case _t.ELLIPSE:{const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`;break}case _t.MULTIPOLYGON:{const e=r.geometry;t=`<svg>${Sy(e)}</svg>`;break}case _t.LINE:{const e=r.geometry,[[i,n],[s,o]]=e.points;t=`<svg><line x1="${i}" y1="${n}" x2="${s}" y2="${o}" /></svg>`;break}case _t.POLYLINE:t=`<svg><path d="${fa(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ye=[];for(let r=0;r<256;++r)ye.push((r+256).toString(16).slice(1));function Iy(r,t=0){return(ye[r[t+0]]+ye[r[t+1]]+ye[r[t+2]]+ye[r[t+3]]+"-"+ye[r[t+4]]+ye[r[t+5]]+"-"+ye[r[t+6]]+ye[r[t+7]]+"-"+ye[r[t+8]]+ye[r[t+9]]+"-"+ye[r[t+10]]+ye[r[t+11]]+ye[r[t+12]]+ye[r[t+13]]+ye[r[t+14]]+ye[r[t+15]]).toLowerCase()}const Py=new Uint8Array(16);function Ry(){return crypto.getRandomValues(Py)}function vc(r,t,e){return crypto.randomUUID?crypto.randomUUID():My(r)}function My(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Ry();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Iy(n)}var bc=Object.prototype.hasOwnProperty;function Ur(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--&&Ur(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(bc.call(r,e)&&++i&&!bc.call(t,e)||!(e in t)||!Ur(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}let We=[],Gr=0;const Cs=4,Oy=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),pa=r=>{let t=[],e={get(){return e.lc||e.listen(()=>{})(),e.value},init:r,lc:0,listen(i){return e.lc=t.push(i),()=>{for(let s=Gr+Cs;s<We.length;)We[s]===i?We.splice(s,Cs):s+=Cs;let n=t.indexOf(i);~n&&(t.splice(n,1),--e.lc||e.off())}},notify(i,n){Oy.epoch++;let s=!We.length;for(let o of t)We.push(o,e.value,i,n);if(s){for(Gr=0;Gr<We.length;Gr+=Cs)We[Gr](We[Gr+1],We[Gr+2],We[Gr+3]);We.length=0}},off(){},set(i){let n=e.value;n!==i&&(e.value=i,e.notify(n))},subscribe(i){let n=e.listen(i);return i(e.value),n},value:r};return e},By=r=>{const t=pa(null);return r.observe(({changes:e})=>{const i=t.get();if(i){(e.deleted||[]).some(s=>s.id===i)&&t.set(null);const n=(e.updated||[]).find(({oldValue:s})=>s.id===i);n&&t.set(n.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var xc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(xc||{});const ma={selected:[]},Ly=(r,t,e)=>{const i=pa(ma);let n=t;const s=()=>{Ur(i.get(),ma)||i.set(ma)},o=()=>{var f;return((f=i.get().selected)==null?void 0:f.length)===0},a=f=>{if(o())return!1;const p=typeof f=="string"?f:f.id;return i.get().selected.some(g=>g.id===p)},l=(f,p)=>{let g;if(Array.isArray(f)){if(g=f.map(_=>r.getAnnotation(_)).filter(Boolean),g.length<f.length){console.warn("Invalid selection: "+f.filter(_=>!g.some(v=>v.id===_)));return}}else{const _=r.getAnnotation(f);if(!_){console.warn("Invalid selection: "+f);return}g=[_]}const y=g.reduce((_,v)=>{const m=d(v);return m==="EDIT"?[..._,{id:v.id,editable:!0}]:m==="SELECT"?[..._,{id:v.id}]:_},[]);i.set({selected:y,event:p})},h=(f,p)=>{const g=Array.isArray(f)?f:[f],y=g.map(_=>r.getAnnotation(_)).filter(_=>!!_);i.set({selected:y.map(_=>{const v=p===void 0?d(_)==="EDIT":p;return{id:_.id,editable:v}})}),y.length!==g.length&&console.warn("Invalid selection",f)},c=f=>{if(o())return!1;const{selected:p}=i.get();p.some(({id:g})=>f.includes(g))&&i.set({selected:p.filter(({id:g})=>!f.includes(g))})},u=f=>{n=f,h(i.get().selected.map(({id:p})=>p))},d=f=>Dy(f,n,e);return r.observe(({changes:f})=>c((f.deleted||[]).map(p=>p.id))),{get event(){const f=i.get();return f?f.event:null},get selected(){const f=i.get();return f?[...f.selected]:null},get userSelectAction(){return n},clear:s,evalSelectAction:d,isEmpty:o,isSelected:a,setSelected:h,setUserSelectAction:u,subscribe:i.subscribe.bind(i),userSelect:l}},Dy=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},_e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function Ny(r,t=0){return(_e[r[t+0]]+_e[r[t+1]]+_e[r[t+2]]+_e[r[t+3]]+"-"+_e[r[t+4]]+_e[r[t+5]]+"-"+_e[r[t+6]]+_e[r[t+7]]+"-"+_e[r[t+8]]+_e[r[t+9]]+"-"+_e[r[t+10]]+_e[r[t+11]]+_e[r[t+12]]+_e[r[t+13]]+_e[r[t+14]]+_e[r[t+15]]).toLowerCase()}const Fy=new Uint8Array(16);function ky(){return crypto.getRandomValues(Fy)}function Uy(r,t,e){return crypto.randomUUID?crypto.randomUUID():Gy(r)}function Gy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??ky();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ny(n)}const ga=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)}},$y=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Hy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Vy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Ur(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Xy=(r,t)=>!Ur(r.target,t.target),wc=(r,t)=>{const e=$y(r,t),i=Hy(r,t),n=Vy(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:Xy(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Dt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Dt||{});const jy=(r,t)=>{var e,i;const{changes:n,origin:s}=t;if(!(r.options.origin?r.options.origin===s:s!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(n.created)||a(n.deleted))){const l=(e=n.updated)==null?void 0:e.some(c=>a(c.bodiesCreated)||a(c.bodiesDeleted)||a(c.bodiesUpdated)),h=(i=n.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([...(n.created||[]).map(a=>a.id),...(n.deleted||[]).map(a=>a.id),...(n.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},Wy=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=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=>!s.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=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(g=>g.oldValue.id===f.id).newValue;return wc(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},Is=r=>{const t=r.id===void 0?Uy():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Yy=r=>r.id!==void 0,zy=()=>{const r=new Map,t=new Map,e=[],i=(P,T={})=>{e.push({onChange:P,options:T})},n=P=>{const T=e.findIndex(w=>w.onChange==P);T>-1&&e.splice(T,1)},s=(P,T)=>{const w={origin:P,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...r.values()]};e.forEach(A=>{jy(A,w)&&A.onChange(w)})},o=(P,T=Dt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const w=Is(P);r.set(w.id,w),w.bodies.forEach(A=>t.set(A.id,w.id)),s(T,{created:[w]})}},a=(P,T)=>{const w=Is(typeof P=="string"?T:P),A=typeof P=="string"?P:P.id,L=A&&r.get(A);if(L){const O=wc(L,w);return A===w.id?r.set(A,w):(r.delete(A),r.set(w.id,w)),L.bodies.forEach(D=>t.delete(D.id)),w.bodies.forEach(D=>t.set(D.id,w.id)),O}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,T=Dt.LOCAL,w=Dt.LOCAL)=>{const A=Yy(T)?w:T,L=a(P,T);L&&s(A,{updated:[L]})},h=(P,T=Dt.LOCAL)=>{r.get(P.id)?l(P,T):o(P,T)},c=(P,T=Dt.LOCAL)=>{const w=P.reduce((A,L)=>{const O=a(L);return O?[...A,O]:A},[]);w.length>0&&s(T,{updated:w})},u=(P,T=Dt.LOCAL)=>{const w=P.map(Is),{toAdd:A,toUpdate:L}=w.reduce((D,$)=>r.get($.id)?{...D,toUpdate:[...D.toUpdate,$]}:{...D,toAdd:[...D.toAdd,$]},{toAdd:[],toUpdate:[]}),O=L.map(D=>a(D,T)).filter(Boolean);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach($=>t.set($.id,D.id))}),s(T,{created:A,updated:O})},d=(P,T=Dt.LOCAL)=>{const w=r.get(P.annotation);if(w){const A={...w,bodies:[...w.bodies,P]};r.set(w.id,A),t.set(P.id,A.id),s(T,{updated:[{oldValue:w,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},f=()=>[...r.values()],p=(P=Dt.LOCAL)=>{const T=[...r.values()];r.clear(),t.clear(),s(P,{deleted:T})},g=(P,T=!0,w=Dt.LOCAL)=>{const A=P.map(Is);if(T){const L=[...r.values()];r.clear(),t.clear(),A.forEach(O=>{r.set(O.id,O),O.bodies.forEach(D=>t.set(D.id,O.id))}),s(w,{created:A,deleted:L})}else{const L=P.reduce((O,D)=>{const $=D.id&&r.get(D.id);return $?[...O,$]:O},[]);if(L.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${L.map(O=>O.id).join(", ")}`);A.forEach(O=>{r.set(O.id,O),O.bodies.forEach(D=>t.set(D.id,O.id))}),s(w,{created:A})}},y=P=>{const T=typeof P=="string"?P:P.id,w=r.get(T);if(w)return r.delete(T),w.bodies.forEach(A=>t.delete(A.id)),w;console.warn(`Attempt to delete missing annotation: ${T}`)},_=(P,T=Dt.LOCAL)=>{const w=y(P);w&&s(T,{deleted:[w]})},v=(P,T=Dt.LOCAL)=>{const w=P.reduce((A,L)=>{const O=y(L);return O?[...A,O]:A},[]);w.length>0&&s(T,{deleted:w})},m=P=>{const T=r.get(P.annotation);if(T){const w=T.bodies.find(A=>A.id===P.id);if(w){t.delete(w.id);const A={...T,bodies:T.bodies.filter(L=>L.id!==P.id)};return r.set(T.id,A),{oldValue:T,newValue:A,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${P.id} from annotation ${P.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${P.annotation}`)},x=(P,T=Dt.LOCAL)=>{const w=m(P);w&&s(T,{updated:[w]})},S=(P,T=Dt.LOCAL)=>{const w=P.map(A=>m(A)).filter(Boolean);w.length>0&&s(T,{updated:w})},R=P=>{const T=r.get(P);return T?{...T}:void 0},C=P=>{const T=t.get(P);if(T){const w=R(T).bodies.find(A=>A.id===P);if(w)return w;console.error(`Store integrity error: body ${P} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${P}`)},I=(P,T)=>{if(P.annotation!==T.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=r.get(P.annotation);if(w){const A=w.bodies.find(O=>O.id===P.id),L={...w,bodies:w.bodies.map(O=>O.id===A.id?T:O)};return r.set(w.id,L),A.id!==T.id&&(t.delete(A.id),t.set(T.id,L.id)),{oldValue:w,newValue:L,bodiesUpdated:[{oldBody:A,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,T,w=Dt.LOCAL)=>{const A=I(P,T);A&&s(w,{updated:[A]})},F=(P,T=Dt.LOCAL)=>{const w=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(T,{updated:w})},U=P=>{const T=r.get(P.annotation);if(T){const w={...T,target:{...T.target,...P}};return r.set(T.id,w),{oldValue:T,newValue:w,targetUpdated:{oldTarget:T.target,newTarget:P}}}else console.warn(`Attempt to update target on missing annotation: ${P.annotation}`)};return{addAnnotation:o,addBody:d,all:f,bulkAddAnnotations:g,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,T=Dt.LOCAL)=>{const w=P.map(A=>U(A)).filter(Boolean);w.length>0&&s(T,{updated:w})},bulkUpsertAnnotations:u,clear:p,deleteAnnotation:_,deleteBody:x,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,T=Dt.LOCAL)=>{const w=U(P);w&&s(T,{updated:[w]})},upsertAnnotation:h}};let qy=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;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(n=>t!==n)}}});const Ky=250,Zy=(r,t)=>{const e=qy(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:g}=p,y=performance.now();if(y-o>Ky)i.splice(n+1),i.push(g),n=i.length-1;else{const _=i.length-1;i[_]=Wy(i[_],g)}o=y}s=!1};r.observe(a,{origin:Dt.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:g})=>g)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:g})=>g)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,g)=>e.on(p,g),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:g,deleted:y}=i[n+1];h(p),u(g),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:g,deleted:y}=i[n];l(p),c(g),d(y),e.emit("undo",i[n]),n-=1}}}},Jy=()=>{const r=pa([]);return{subscribe:r.subscribe.bind(r),set:r.set.bind(r)}},Qy=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},f=(_,v)=>{const m=l.get(_);if(m){const x=m.indexOf(v);x!==-1&&m.splice(x,1)}},p=(_,v,m)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=m?m instanceof PointerEvent?m:e.serialize(m):void 0;x(S,R)}else x(v,m)})},1)},g=()=>{const{selected:_}=s,v=(_||[]).map(({id:m})=>o.getAnnotation(m));v.forEach(m=>{const x=h.find(S=>S.id===m.id);(!x||!Ur(x,m))&&p("updateAnnotation",m,x)}),h=h.map(m=>v.find(({id:x})=>x===m.id)||m)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const m=o.getAnnotation(v.id);m&&!Ur(m,v)&&p("updateAnnotation",m,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),m=new Set(_.map(({id:x})=>x));h.filter(x=>!m.has(x.id)).forEach(x=>{const S=o.getAnnotation(x.id);S&&!Ur(S,x)&&p("updateAnnotation",S,x)}),h=[...h.filter(x=>m.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(g,1e3));const{created:v,deleted:m}=_.changes;(v||[]).forEach(x=>p("createAnnotation",x)),(m||[]).forEach(x=>p("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:S})=>{const R=h.find(C=>C.id===x.id)||x;h=h.map(C=>C.id===x.id?S:C),p("updateAnnotation",S,R)})},{origin:Dt.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),m=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);m.length>0&&(h=h.map(x=>m.find(S=>S.id===x.id)||x))}},{origin:Dt.REMOTE});const y=_=>v=>{const{updated:m}=v;_?(m||[]).forEach(x=>p("updateAnnotation",x.oldValue,x.newValue)):(m||[]).forEach(x=>p("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},t0=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),e0=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:m}=e.parse(_);v?i.addAnnotation(v,Dt.REMOTE):console.error(m)}else i.addAnnotation(ga(_),Dt.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(m=>m.id))||[]).map(m=>i.getAnnotation(m)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(m=>m.json()).then(m=>(f(m,v),m)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const m=e.parseAll||t0(e),{parsed:x,failed:S}=m(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(x,v,Dt.REMOTE)}else i.bulkAddAnnotations(_.map(ga),v,Dt.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},g=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,m=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),m}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(ga(_)),v}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:g,undo:t.undo,updateAnnotation:y}},r0=(r,t,e)=>typeof t=="function"?t(r,e):t,i0=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const n=typeof r=="function"?r(e,i):r,s=typeof t=="function"?t(e,i):t;return{...n||{},...s||{}}};let n0="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",s0=r=>crypto.getRandomValues(new Uint8Array(r)),o0=(r,t,e)=>{let i=256-256%r.length;if(i===256){let s=r.length-1;return(o=t)=>{if(!o)return"";let a="";for(;;){let l=e(o),h=o;for(;h--;)if(a+=r[l[h]&s],a.length>=o)return a}}}let n=Math.ceil(1.6*256*t/i);return(s=t)=>{if(!s)return"";let o="";for(;;){let a=e(n),l=n;for(;l--;)if(a[l]<i&&(o+=r[a[l]%r.length],o.length>=s))return o}}},a0=(r,t=21)=>o0(r,t|0,s0),l0=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=n0[e[r]&63];return t};const h0=()=>({isGuest:!0,id:a0("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),c0=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,n=t.length;i<n;i++){let s=t.charCodeAt(i);e=(e<<5)-e+s,e|=0}return`${e}`},Ec=r=>r?typeof r=="object"?{...r}:r:void 0,u0=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:n,purpose:s,value:o,created:a,modified:l,creator:h,...c}=e;return{id:i||`temp-${c0(e)}`,annotation:t,type:n,purpose:s,value:o,creator:Ec(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),d0=r=>r.map(t=>{var e;const{annotation:i,created:n,updated:s,...o}=t,a={...o,created:n==null?void 0:n.toISOString(),modified:s==null?void 0:s.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});l0();const f0=(r,t={strict:!0,invertY:!1})=>({parse:e=>p0(e,t),serialize:e=>m0(e,r,t)}),p0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||vc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=u0(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,c=typeof h=="string"?h:Array.isArray(h.selector)?h.selector[0]:h.selector,u=dy(c)?fy(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?Ay(c):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return u||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:n?new Date(n):void 0,creator:Ec(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},m0=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:n,created:s,updated:o,updatedBy:a,...l}=r.target;let h;try{i.type===_t.RECTANGLE&&!i.geometry.rot?h=py(i.geometry):h=Cy(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:d0(r.bodies),created:s==null?void 0:s.toISOString(),creator:n,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:h}};return delete c.bodies,typeof c.target!="string"&&"annotation"in c.target&&delete c.target.annotation,c},Vi=[];function g0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Vi.length;for(const h of i)h[1](),Vi.push(h,r);if(l){for(let h=0;h<Vi.length;h+=2)Vi[h][0](Vi[h+1]);Vi.length=0}}}function s(a){n(a(r))}function o(a,l=Rt){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||Rt),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const y0=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:n,height:s}=r;t.setAttribute("viewBox",`0 0 ${n} ${s}`),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}`)},_0=(r,t)=>{y0(r,t);const{subscribe:e,set:i}=g0(1);let n;return window.ResizeObserver&&(n=new ResizeObserver(()=>{const s=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(s.width/o,s.height/a);i(l)}),n.observe(t.parentElement)),{destroy:()=>{n&&n.disconnect()},subscribe:e}},hi=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},Ps=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},Ge=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,v0=r=>({}),Tc=r=>({grab:r[0]});function b0(r){let t,e,i,n;const s=r[8].default,o=jg(s,r,r[7],Tc);return{c(){t=Y("g"),o&&o.c(),b(t,"class","a9s-annotation selected")},m(a,l){rt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Ct(t,"pointerup",r[2]),Ct(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Yg(o,s,a,a[7],e?Wg(s,a[7],l,v0):zg(a[7]),Tc)},i(a){e||(ht(o,a),e=!0)},o(a){yt(o,a),e=!1},d(a){a&&et(t),o&&o.d(a),i=!1,De(n)}}}function x0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=kr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=y=>_=>{if(c=y,h){const{left:v,top:m}=h.getBoundingClientRect(),x=_.clientX-v,S=_.clientY-m;u=l.elementToImage(x,S)}else{const{offsetX:v,offsetY:m}=_;u=l.elementToImage(v,m)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),m=[_-u[0],v-u[1]];e(3,o=a(d,c,m)),s("change",o)}},g=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[f,p,g,o,a,l,h,n,i]}class ya extends me{constructor(t){super(),pe(this,t,x0,b0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function w0(r){let t,e,i,n,s,o,a,l,h=r[3]&&Ac(r);return{c(){t=Y("g"),e=Y("circle"),h&&h.c(),n=Y("circle"),b(e,"class","a9s-handle-buffer svelte-qtyc7s"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]+6/r[2]),b(e,"role","button"),b(e,"tabindex","0"),b(n,"class",s=ki(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",r[5]),b(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){rt(c,t,u),bt(t,e),h&&h.m(t,null),bt(t,n),a||(l=[Ct(e,"dblclick",r[12]),Ct(e,"pointerenter",r[13]),Ct(e,"pointerleave",r[14]),Ct(e,"pointerdown",r[15]),Ct(e,"pointerdown",r[6]),Ct(e,"pointerup",r[16]),Ct(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&b(e,"cx",c[0]),u&2&&b(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&b(e,"r",i),c[3]?h?h.p(c,u):(h=Ac(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=ki(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&b(n,"class",s),u&1&&b(n,"cx",c[0]),u&2&&b(n,"cy",c[1]),u&32&&b(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&b(t,"class",o)},d(c){c&&et(t),h&&h.d(),a=!1,De(l)}}}function E0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=Y("g"),e=Y("circle"),n=Y("circle"),o=Y("circle"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]*10),b(e,"class","a9s-touch-halo"),ir(e,"touched",r[4]),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",s=r[5]+10/r[2]),b(n,"class","a9s-handle-buffer svelte-qtyc7s"),b(n,"role","button"),b(n,"tabindex","0"),b(o,"class","a9s-handle-dot"),b(o,"cx",r[0]),b(o,"cy",r[1]),b(o,"r",a=r[5]+2/r[2]),b(t,"class","a9s-touch-handle")},m(c,u){rt(c,t,u),bt(t,e),bt(t,n),bt(t,o),l||(h=[Ct(n,"dblclick",r[9]),Ct(n,"pointerdown",r[10]),Ct(n,"pointerdown",r[6]),Ct(n,"pointerup",r[11]),Ct(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&b(e,"cx",c[0]),u&2&&b(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&b(e,"r",i),u&16&&ir(e,"touched",c[4]),u&1&&b(n,"cx",c[0]),u&2&&b(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&b(n,"r",s),u&1&&b(o,"cx",c[0]),u&2&&b(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&b(o,"r",a)},d(c){c&&et(t),l=!1,De(h)}}}function Ac(r){let t,e;return{c(){t=Y("circle"),b(t,"class","a9s-handle-selected"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",e=r[5]+8/r[2])},m(i,n){rt(i,t,n)},p(i,n){n&1&&b(t,"cx",i[0]),n&2&&b(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&b(t,"r",e)},d(i){i&&et(t)}}}function T0(r){let t;function e(n,s){return Ge?E0:w0}let i=e()(r);return{c(){i.c(),t=Ne()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&et(t),i.d(n)}}}function A0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=m=>{m.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(m){oe.call(this,r,m)}function d(m){oe.call(this,r,m)}function f(m){oe.call(this,r,m)}function p(m){oe.call(this,r,m)}function g(m){oe.call(this,r,m)}function y(m){oe.call(this,r,m)}function _(m){oe.call(this,r,m)}function v(m){oe.call(this,r,m)}return r.$$set=m=>{e(8,t=na(na({},t),oc(m))),"x"in m&&e(0,n=m.x),"y"in m&&e(1,s=m.y),"scale"in m&&e(2,o=m.scale),"selected"in m&&e(3,a=m.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=oc(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,g,y,_,v]}class ci extends me{constructor(t){super(),pe(this,t,A0,T0,Kt,{x:0,y:1,scale:2,selected:3})}}function S0(r){let t,e,i,n,s,o,a;return{c(){t=Y("g"),e=Y("circle"),n=Y("circle"),s=Y("circle"),b(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=1.75*r[2]),b(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",r[2]),b(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",r[2]),b(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){rt(l,t,h),bt(t,e),bt(t,n),bt(t,s),o||(a=[Ct(e,"pointerdown",r[5]),Ct(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&b(e,"cx",l[0]),h&2&&b(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&b(e,"r",i),h&1&&b(n,"cx",l[0]),h&2&&b(n,"cy",l[1]),h&4&&b(n,"r",l[2]),h&1&&b(s,"cx",l[0]),h&2&&b(s,"cy",l[1]),h&4&&b(s,"r",l[2])},d(l){l&&et(t),o=!1,De(a)}}}function C0(r){let t;return{c(){t=Y("circle"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",r[2])},m(e,i){rt(e,t,i)},p(e,i){i&1&&b(t,"cx",e[0]),i&2&&b(t,"cy",e[1]),i&4&&b(t,"r",e[2])},d(e){e&&et(t)}}}function I0(r){let t;function e(n,s){return Ge?C0:S0}let i=e()(r);return{c(){i.c(),t=Ne()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&et(t),i.d(n)}}}function P0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){oe.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class Sc extends me{constructor(t){super(),pe(this,t,P0,I0,Kt,{x:0,y:1,scale:4})}}function _a(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Cc(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function va(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ba(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ic(r){let t,e,i,n;return{c(){t=Y("circle"),b(t,"cx",e=r[28][0]),b(t,"cy",i=r[28][1]),b(t,"r",n=On/r[3]),b(t,"class","svelte-1h2slbm")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&b(t,"cy",i),o[0]&8&&n!==(n=On/s[3])&&b(t,"r",n)},d(s){s&&et(t)}}}function Pc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=Y("mask"),e=Y("rect"),a=Y("circle"),b(e,"x",i=r[9].x),b(e,"y",n=r[9].y),b(e,"width",s=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1h2slbm"),b(a,"cx",l=r[28][0]),b(a,"cy",h=r[28][1]),b(a,"r",c=On/r[3]),b(a,"class","svelte-1h2slbm"),b(t,"id",`${r[19]}-inner`),b(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&b(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&b(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&b(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&b(a,"cy",h),d[0]&8&&c!==(c=On/u[3])&&b(a,"r",c)},d(u){u&&et(t)}}}function Rc(r){let t,e;return t=new ci({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){kt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Mc(r){let t,e;return t=new Sc({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){kt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function R0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R=r[6]!==void 0&&!r[7]&&Ic(ba(r)),C=r[6]!==void 0&&!r[7]&&Pc(va(r)),I=Oe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Rc(Cc(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Mc(_a(r));return{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("polygon"),R&&R.c(),C&&C.c(),c=Se(),u=Y("polygon"),f=Se(),p=Y("polygon"),y=Se();for(let P=0;P<M.length;P+=1)M[P].c();_=Se(),U&&U.c(),v=Ne(),b(i,"x",n=r[9].x),b(i,"y",s=r[9].y),b(i,"width",o=r[9].w),b(i,"height",a=r[9].h),b(i,"class","svelte-1h2slbm"),b(l,"points",h=r[5].points.map(Oc).join(" ")),b(l,"class","svelte-1h2slbm"),b(e,"id",`${r[19]}-outer`),b(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),b(u,"class","a9s-outer"),b(u,"mask",`url(#${r[19]}-outer)`),b(u,"points",d=r[5].points.map(Bc).join(" ")),b(p,"class","a9s-inner a9s-shape-handle"),b(p,"mask",`url(#${r[19]}-inner)`),b(p,"style",r[1]),b(p,"points",g=r[5].points.map(Lc).join(" "))},m(P,T){rt(P,t,T),bt(t,e),bt(e,i),bt(e,l),R&&R.m(e,null),C&&C.m(t,null),rt(P,c,T),rt(P,u,T),rt(P,f,T),rt(P,p,T),rt(P,y,T);for(let w=0;w<M.length;w+=1)M[w]&&M[w].m(P,T);rt(P,_,T),U&&U.m(P,T),rt(P,v,T),m=!0,x||(S=[Ct(u,"pointerup",r[14]),Ct(u,"pointerdown",function(){kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Ct(p,"pointermove",r[13]),Ct(p,"pointerup",r[14]),Ct(p,"pointerdown",function(){kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],x=!0)},p(P,T){if(r=P,(!m||T[0]&512&&n!==(n=r[9].x))&&b(i,"x",n),(!m||T[0]&512&&s!==(s=r[9].y))&&b(i,"y",s),(!m||T[0]&512&&o!==(o=r[9].w))&&b(i,"width",o),(!m||T[0]&512&&a!==(a=r[9].h))&&b(i,"height",a),(!m||T[0]&32&&h!==(h=r[5].points.map(Oc).join(" ")))&&b(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(ba(r),T):(R=Ic(ba(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(va(r),T):(C=Pc(va(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!m||T[0]&32&&d!==(d=r[5].points.map(Bc).join(" ")))&&b(u,"points",d),(!m||T[0]&2)&&b(p,"style",r[1]),(!m||T[0]&32&&g!==(g=r[5].points.map(Lc).join(" ")))&&b(p,"points",g),T[0]&134322472){I=Oe(r[5].points);let w;for(w=0;w<I.length;w+=1){const A=Cc(r,I,w);M[w]?(M[w].p(A,T),ht(M[w],1)):(M[w]=Rc(A),M[w].c(),ht(M[w],1),M[w].m(_.parentNode,_))}for(Ce(),w=I.length;w<M.length;w+=1)F(w);Ie()}r[6]!==void 0&&!r[7]?U?(U.p(_a(r),T),T[0]&192&&ht(U,1)):(U=Mc(_a(r)),U.c(),ht(U,1),U.m(v.parentNode,v)):U&&(Ce(),yt(U,1,1,()=>{U=null}),Ie())},i(P){if(!m){for(let T=0;T<I.length;T+=1)ht(M[T]);ht(U),m=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)yt(M[T]);yt(U),m=!1},d(P){P&&(et(t),et(c),et(u),et(f),et(p),et(y),et(_),et(v)),R&&R.d(),C&&C.d(),ai(M,P),U&&U.d(P),x=!1,De(S)}}}function M0(r){let t,e;return t=new ya({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[R0,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const O0=250,B0=1e3,L0=12,On=4.5,Oc=r=>r.join(","),Bc=r=>r.join(","),Lc=r=>r.join(",");function D0(r,t,e){let i,n,s;const o=kr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=w=>{if(g.length>0||!n.some(N=>N.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(w.offsetX,w.offsetY),O=N=>Math.pow(N[0]-A,2)+Math.pow(N[1]-L,2),D=i.points.reduce((N,k)=>O(k)<O(N)?k:N),$=n.filter(N=>N.visible).reduce((N,k)=>O(k.point)<O(N.point)?k:N),B=Math.pow(B0/c,2);O(D)<B||O($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=w=>{e(7,f=!0),w.preventDefault(),w.stopPropagation(),p=performance.now()},R=w=>A=>{if(!p||Ge||performance.now()-p>O0)return;const L=g.includes(w);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,g=g.filter(O=>O!==w)):e(8,g=[...g,w]):L&&g.length>1?e(8,g=[w]):L?e(8,g=[]):e(8,g=[w]),m()},C=(w,A,L)=>{m();let O;const D=w.geometry;g.length>1?O=D.points.map(([B,N],k)=>g.includes(k)?[B+L[0],N+L[1]]:[B,N]):A==="SHAPE"?O=D.points.map(([B,N])=>[B+L[0],N+L[1]]):O=D.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+L[0],N+L[1]]:[B,N]);const $=ge(O);return{...w,geometry:{points:O,bounds:$}}},I=w=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,w+1),n[w].point,...i.points.slice(w+1)],O=ge(L);o("change",{...a,geometry:{points:L,bounds:O}}),await dc();const D=[...document.querySelectorAll(".a9s-handle")][w+1];if(D!=null&&D.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});D.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-g.length<3)return;const w=i.points.filter((L,O)=>!g.includes(O)),A=ge(w);o("change",{...a,geometry:{points:w,bounds:A}}),e(8,g=[])};Fr(()=>{if(Ge)return;const w=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",w),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",w)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(w){oe.call(this,r,w)}function P(w){oe.call(this,r,w)}function T(w){oe.call(this,r,w)}return r.$$set=w=>{"shape"in w&&e(0,a=w.shape),"computedStyle"in w&&e(1,l=w.computedStyle),"transform"in w&&e(2,h=w.transform),"viewportScale"in w&&e(3,c=w.viewportScale),"svgEl"in w&&e(4,u=w.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ge?[]:i.points.map((w,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],O=(w[0]+L[0])/2,D=(w[1]+L[1])/2,$=Math.sqrt(Math.pow(L[0]-O,2)+Math.pow(L[1]-D,2))>L0/c;return{point:[O,D],visible:$}})),r.$$.dirty[0]&40&&e(9,s=Ps(i.bounds,On/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,v,x,S,R,C,I,F,U,P,T]}class N0 extends me{constructor(t){super(),pe(this,t,D0,M0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Dc=(r,t,e)=>{const[i,n]=r,[s,o]=t,a=Math.cos(e),l=Math.sin(e),h=i-s,c=n-o;return[s+h*a-c*l,o+h*l+c*a]},F0=(r,t,e,i,n=0)=>{const s=[[r,t],[r+e,t],[r+e,t+i],[r,t+i]],o=[r+e/2,t+i/2];return s.map(a=>Dc(a,o,n))},Nc=(r,t)=>{const{x:e,y:i,w:n,h:s,rot:o=0}=r,a=[e+n/2,i+s/2];let l=[e+n/2,i-t];return Dc(l,a,o)},k0=(r,t,e)=>{const i=Math.cos(e),n=Math.sin(e);return[r*i+t*n,-r*n+t*i]},U0=(r,t,e)=>{const i=r[0]-e[0],n=r[1]-e[1],s=Math.atan2(n,i),o=t[0]-e[0],a=t[1]-e[1];return Math.atan2(a,o)-s},G0=(r,t=10)=>{const e=t*Math.PI/180;return Math.round(r/e)*e};function $0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R,C,I,M,F,U,P,T,w,A,L,O,D,$,B,N,k,V,j,st,H,at,X,gt,lt,ft,ct,Et,te,Gt,Me,Rr,zt,Li,we,Di,Ee,Ni,Te,Z,Fi,ms;return R=new ci({props:{class:"a9s-rotation-handle",x:r[7][0],y:r[7][1],scale:r[3]}}),R.$on("pointerdown",function(){kt(r[16]("ROTATION"))&&r[16]("ROTATION").apply(this,arguments)}),zt=new ci({props:{class:"a9s-corner-handle-topleft",x:r[6][0][0],y:r[6][0][1],scale:r[3]}}),zt.$on("pointerdown",function(){kt(r[16]("TOP_LEFT"))&&r[16]("TOP_LEFT").apply(this,arguments)}),we=new ci({props:{class:"a9s-corner-handle-topright",x:r[6][1][0],y:r[6][1][1],scale:r[3]}}),we.$on("pointerdown",function(){kt(r[16]("TOP_RIGHT"))&&r[16]("TOP_RIGHT").apply(this,arguments)}),Ee=new ci({props:{class:"a9s-corner-handle-bottomright",x:r[6][2][0],y:r[6][2][1],scale:r[3]}}),Ee.$on("pointerdown",function(){kt(r[16]("BOTTOM_RIGHT"))&&r[16]("BOTTOM_RIGHT").apply(this,arguments)}),Te=new ci({props:{class:"a9s-corner-handle-bottomleft",x:r[6][3][0],y:r[6][3][1],scale:r[3]}}),Te.$on("pointerdown",function(){kt(r[16]("BOTTOM_LEFT"))&&r[16]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("polygon"),c=Se(),u=Y("g"),d=Y("line"),_=Y("line"),ee(R.$$.fragment),C=Se(),I=Y("g"),M=Y("polygon"),U=Y("polygon"),T=Se(),w=Y("line"),$=Se(),B=Y("line"),st=Se(),H=Y("line"),ft=Se(),ct=Y("line"),Rr=Se(),ee(zt.$$.fragment),Li=Se(),ee(we.$$.fragment),Di=Se(),ee(Ee.$$.fragment),Ni=Se(),ee(Te.$$.fragment),b(i,"class","rect-mask-bg svelte-1bwhzbc"),b(i,"x",n=r[5].x),b(i,"y",s=r[5].y),b(i,"width",o=r[5].w),b(i,"height",a=r[5].h),b(l,"class","rect-mask-fg svelte-1bwhzbc"),b(l,"points",h=r[6].map(Fc).join(" ")),b(e,"id",r[9]),b(e,"class","a9s-rectangle-editor-mask svelte-1bwhzbc"),b(d,"class","a9s-rotation-handle-line-bg"),b(d,"x1",f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),b(d,"y1",p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),b(d,"x2",g=r[7][0]),b(d,"y2",y=r[7][1]),b(d,"pointer-events","none"),b(_,"class","a9s-rotation-handle-line-fg"),b(_,"x1",v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),b(_,"y1",m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),b(_,"x2",x=r[7][0]),b(_,"y2",S=r[7][1]),b(_,"pointer-events","none"),b(u,"class","a9s-rotation-handle-group"),b(M,"class","a9s-outer"),b(M,"mask",`url(#${r[9]})`),b(M,"points",F=r[6].map(kc).join(" ")),b(U,"class","a9s-inner a9s-shape-handle"),b(U,"style",r[1]),b(U,"points",P=r[6].map(Uc).join(" ")),b(w,"class","a9s-edge-handle a9s-edge-handle-top"),b(w,"x1",A=r[6][0][0]),b(w,"y1",L=r[6][0][1]),b(w,"x2",O=r[6][1][0]),b(w,"y2",D=r[6][1][1]),b(B,"class","a9s-edge-handle a9s-edge-handle-right"),b(B,"x1",N=r[6][1][0]),b(B,"y1",k=r[6][1][1]),b(B,"x2",V=r[6][2][0]),b(B,"y2",j=r[6][2][1]),b(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),b(H,"x1",at=r[6][2][0]),b(H,"y1",X=r[6][2][1]),b(H,"x2",gt=r[6][3][0]),b(H,"y2",lt=r[6][3][1]),b(ct,"class","a9s-edge-handle a9s-edge-handle-left"),b(ct,"x1",Et=r[6][3][0]),b(ct,"y1",te=r[6][3][1]),b(ct,"x2",Gt=r[6][0][0]),b(ct,"y2",Me=r[6][0][1])},m(z,G){rt(z,t,G),bt(t,e),bt(e,i),bt(e,l),rt(z,c,G),rt(z,u,G),bt(u,d),bt(u,_),Zt(R,u,null),rt(z,C,G),rt(z,I,G),bt(I,M),bt(I,U),rt(z,T,G),rt(z,w,G),rt(z,$,G),rt(z,B,G),rt(z,st,G),rt(z,H,G),rt(z,ft,G),rt(z,ct,G),rt(z,Rr,G),Zt(zt,z,G),rt(z,Li,G),Zt(we,z,G),rt(z,Di,G),Zt(Ee,z,G),rt(z,Ni,G),Zt(Te,z,G),Z=!0,Fi||(ms=[Ct(M,"pointerdown",function(){kt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Ct(U,"pointerdown",function(){kt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Ct(w,"pointerdown",function(){kt(r[16]("TOP"))&&r[16]("TOP").apply(this,arguments)}),Ct(B,"pointerdown",function(){kt(r[16]("RIGHT"))&&r[16]("RIGHT").apply(this,arguments)}),Ct(H,"pointerdown",function(){kt(r[16]("BOTTOM"))&&r[16]("BOTTOM").apply(this,arguments)}),Ct(ct,"pointerdown",function(){kt(r[16]("LEFT"))&&r[16]("LEFT").apply(this,arguments)})],Fi=!0)},p(z,G){r=z,(!Z||G&32&&n!==(n=r[5].x))&&b(i,"x",n),(!Z||G&32&&s!==(s=r[5].y))&&b(i,"y",s),(!Z||G&32&&o!==(o=r[5].w))&&b(i,"width",o),(!Z||G&32&&a!==(a=r[5].h))&&b(i,"height",a),(!Z||G&64&&h!==(h=r[6].map(Fc).join(" ")))&&b(l,"points",h),(!Z||G&64&&f!==(f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&b(d,"x1",f),(!Z||G&64&&p!==(p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&b(d,"y1",p),(!Z||G&128&&g!==(g=r[7][0]))&&b(d,"x2",g),(!Z||G&128&&y!==(y=r[7][1]))&&b(d,"y2",y),(!Z||G&64&&v!==(v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&b(_,"x1",v),(!Z||G&64&&m!==(m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&b(_,"y1",m),(!Z||G&128&&x!==(x=r[7][0]))&&b(_,"x2",x),(!Z||G&128&&S!==(S=r[7][1]))&&b(_,"y2",S);const Mr={};G&128&&(Mr.x=r[7][0]),G&128&&(Mr.y=r[7][1]),G&8&&(Mr.scale=r[3]),R.$set(Mr),(!Z||G&64&&F!==(F=r[6].map(kc).join(" ")))&&b(M,"points",F),(!Z||G&2)&&b(U,"style",r[1]),(!Z||G&64&&P!==(P=r[6].map(Uc).join(" ")))&&b(U,"points",P),(!Z||G&64&&A!==(A=r[6][0][0]))&&b(w,"x1",A),(!Z||G&64&&L!==(L=r[6][0][1]))&&b(w,"y1",L),(!Z||G&64&&O!==(O=r[6][1][0]))&&b(w,"x2",O),(!Z||G&64&&D!==(D=r[6][1][1]))&&b(w,"y2",D),(!Z||G&64&&N!==(N=r[6][1][0]))&&b(B,"x1",N),(!Z||G&64&&k!==(k=r[6][1][1]))&&b(B,"y1",k),(!Z||G&64&&V!==(V=r[6][2][0]))&&b(B,"x2",V),(!Z||G&64&&j!==(j=r[6][2][1]))&&b(B,"y2",j),(!Z||G&64&&at!==(at=r[6][2][0]))&&b(H,"x1",at),(!Z||G&64&&X!==(X=r[6][2][1]))&&b(H,"y1",X),(!Z||G&64&&gt!==(gt=r[6][3][0]))&&b(H,"x2",gt),(!Z||G&64&&lt!==(lt=r[6][3][1]))&&b(H,"y2",lt),(!Z||G&64&&Et!==(Et=r[6][3][0]))&&b(ct,"x1",Et),(!Z||G&64&&te!==(te=r[6][3][1]))&&b(ct,"y1",te),(!Z||G&64&&Gt!==(Gt=r[6][0][0]))&&b(ct,"x2",Gt),(!Z||G&64&&Me!==(Me=r[6][0][1]))&&b(ct,"y2",Me);const Or={};G&64&&(Or.x=r[6][0][0]),G&64&&(Or.y=r[6][0][1]),G&8&&(Or.scale=r[3]),zt.$set(Or);const Br={};G&64&&(Br.x=r[6][1][0]),G&64&&(Br.y=r[6][1][1]),G&8&&(Br.scale=r[3]),we.$set(Br);const Lr={};G&64&&(Lr.x=r[6][2][0]),G&64&&(Lr.y=r[6][2][1]),G&8&&(Lr.scale=r[3]),Ee.$set(Lr);const Dr={};G&64&&(Dr.x=r[6][3][0]),G&64&&(Dr.y=r[6][3][1]),G&8&&(Dr.scale=r[3]),Te.$set(Dr)},i(z){Z||(ht(R.$$.fragment,z),ht(zt.$$.fragment,z),ht(we.$$.fragment,z),ht(Ee.$$.fragment,z),ht(Te.$$.fragment,z),Z=!0)},o(z){yt(R.$$.fragment,z),yt(zt.$$.fragment,z),yt(we.$$.fragment,z),yt(Ee.$$.fragment,z),yt(Te.$$.fragment,z),Z=!1},d(z){z&&(et(t),et(c),et(u),et(C),et(I),et(T),et(w),et($),et(B),et(st),et(H),et(ft),et(ct),et(Rr),et(Li),et(Di),et(Ni)),Jt(R),Jt(zt,z),Jt(we,z),Jt(Ee,z),Jt(Te,z),Fi=!1,De(ms)}}}function H0(r){let t,e;return t=new ya({props:{shape:r[0],transform:r[2],editor:r[8],svgEl:r[4],$$slots:{default:[$0,({grab:i})=>({16:i}),({grab:i})=>i?65536:0]},$$scope:{ctx:r}}}),t.$on("grab",r[12]),t.$on("change",r[13]),t.$on("release",r[14]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&196842&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const Fc=r=>`${r[0]},${r[1]}`,kc=r=>`${r[0]},${r[1]}`,Uc=r=>`${r[0]},${r[1]}`;function V0(r,t,e){let i,n,s,o,a,{shape:l}=t,{computedStyle:h}=t,{transform:c}=t,{viewportScale:u=1}=t,{svgEl:d}=t,f=!1;const p=(m,x,S)=>{let{x:R,y:C,w:I,h:M,rot:F=0}=m.geometry;const[U,P]=S;if(x==="ROTATION"){const w=Nc(m.geometry,i),A=w[0]+U,L=w[1]+P,O=[R+I/2,C+M/2];F+=U0([w[0],w[1]],[A,L],O),f&&(F=G0(F));const D=2*Math.PI;F=(F%D+D)%D}else if(x==="SHAPE")R+=U,C+=P;else{let w=0,A=0,L=I,O=M;const[D,$]=F!==0?k0(U,P,F):[U,P];switch(x){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":A+=$;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":O+=$;break}switch(x){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":w+=D;break;case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":L+=D;break}const B=(w+L)/2,N=(A+O)/2;I=Math.abs(L-w),M=Math.abs(O-A);const k=[R+m.geometry.w/2,C+m.geometry.h/2],V=[B-m.geometry.w/2,N-m.geometry.h/2],j=Math.cos(F),st=Math.sin(F),H=k[0]+V[0]*j-V[1]*st,at=k[1]+V[0]*st+V[1]*j;R=H-I/2,C=at-M/2}const T=ge(s);return{...m,geometry:{x:R,y:C,w:I,h:M,rot:F,bounds:T}}};Fr(()=>{const m=S=>{S.key==="Shift"&&(f=!0)},x=S=>{S.key==="Shift"&&(f=!1)};return window.addEventListener("keydown",m),window.addEventListener("keyup",x),()=>{window.removeEventListener("keydown",m),window.removeEventListener("keyup",x)}});const g=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function y(m){oe.call(this,r,m)}function _(m){oe.call(this,r,m)}function v(m){oe.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,l=m.shape),"computedStyle"in m&&e(1,h=m.computedStyle),"transform"in m&&e(2,c=m.transform),"viewportScale"in m&&e(3,u=m.viewportScale),"svgEl"in m&&e(4,d=m.svgEl)},r.$$.update=()=>{r.$$.dirty&8&&e(11,i=20/u),r.$$.dirty&1&&e(10,n=l.geometry),r.$$.dirty&1024&&e(6,s=F0(n.x,n.y,n.w,n.h,n.rot)),r.$$.dirty&3072&&e(7,o=Nc(n,i)),r.$$.dirty&1032&&e(5,a=Ps(n.bounds,5/u))},[l,h,c,u,d,a,s,o,p,g,n,i,y,_,v]}class X0 extends me{constructor(t){super(),pe(this,t,V0,H0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Gc=Object.prototype.hasOwnProperty;function xa(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--&&xa(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Gc.call(r,e)&&++i&&!Gc.call(t,e)||!(e in t)||!xa(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const j0=12,W0=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,g=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>j0/t;return{point:[f,p],visible:g,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function wa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function $c(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Hc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Vc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Ea(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ta(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Xc(r){let t,e,i,n;return{c(){t=Y("circle"),b(t,"cx",e=r[29][0]),b(t,"cy",i=r[29][1]),b(t,"r",n=Bn/r[3]),b(t,"class","svelte-1vxo6dc")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&b(t,"cy",i),o[0]&8&&n!==(n=Bn/s[3])&&b(t,"r",n)},d(s){s&&et(t)}}}function jc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=Y("mask"),e=Y("rect"),a=Y("circle"),b(e,"x",i=r[9].x),b(e,"y",n=r[9].y),b(e,"width",s=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1vxo6dc"),b(a,"cx",l=r[29][0]),b(a,"cy",h=r[29][1]),b(a,"r",c=Bn/r[3]),b(a,"class","svelte-1vxo6dc"),b(t,"id",`${r[18]}-${r[32]}-inner`),b(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&b(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&b(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&b(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&b(a,"cy",h),d[0]&8&&c!==(c=Bn/u[3])&&b(a,"r",c)},d(u){u&&et(t)}}}function Wc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new ci({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){kt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){ee(t.$$.fragment)},m(n,s){Zt(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(ht(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){Jt(t,n)}}}function Yc(r){let t,e,i=Oe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Wc(Vc(r,i,o));const s=o=>yt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Ne()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Oe(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Vc(o,i,l);n[l]?(n[l].p(h,a),ht(n[l],1)):(n[l]=Wc(h),n[l].c(),ht(n[l],1),n[l].m(t.parentNode,t))}for(Ce(),l=i.length;l<n.length;l+=1)s(l);Ie()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ht(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&et(t),ai(n,o)}}}function zc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v=r[6]!==void 0&&!r[7]&&Xc(Ta(r)),m=r[6]!==void 0&&!r[7]&&jc(Ea(r)),x=Oe(r[30].rings),S=[];for(let C=0;C<x.length;C+=1)S[C]=Yc(Hc(r,x,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=Y("g"),e=Y("defs"),i=Y("mask"),n=Y("rect"),h=Y("path"),v&&v.c(),m&&m.c(),u=Y("path"),f=Y("path");for(let C=0;C<S.length;C+=1)S[C].c();b(n,"x",s=r[9].x),b(n,"y",o=r[9].y),b(n,"width",a=r[9].w),b(n,"height",l=r[9].h),b(n,"class","svelte-1vxo6dc"),b(h,"d",c=je(r[30])),b(h,"class","svelte-1vxo6dc"),b(i,"id",`${r[18]}-${r[32]}-outer`),b(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),b(u,"class","a9s-outer"),b(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),b(u,"fill-rule","evenodd"),b(u,"d",d=je(r[30])),b(f,"class","a9s-inner"),b(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),b(f,"style",r[1]),b(f,"fill-rule","evenodd"),b(f,"d",p=je(r[30]))},m(C,I){rt(C,t,I),bt(t,e),bt(e,i),bt(i,n),bt(i,h),v&&v.m(i,null),m&&m.m(e,null),bt(t,u),bt(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);g=!0,y||(_=[Ct(u,"pointerup",r[13]),Ct(u,"pointerdown",function(){kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Ct(f,"pointerup",r[13]),Ct(f,"pointerdown",function(){kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!g||I[0]&512&&s!==(s=r[9].x))&&b(n,"x",s),(!g||I[0]&512&&o!==(o=r[9].y))&&b(n,"y",o),(!g||I[0]&512&&a!==(a=r[9].w))&&b(n,"width",a),(!g||I[0]&512&&l!==(l=r[9].h))&&b(n,"height",l),(!g||I[0]&32&&c!==(c=je(r[30])))&&b(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Ta(r),I):(v=Xc(Ta(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?m?m.p(Ea(r),I):(m=jc(Ea(r)),m.c(),m.m(e,null)):m&&(m.d(1),m=null),(!g||I[0]&32&&d!==(d=je(r[30])))&&b(u,"d",d),(!g||I[0]&2)&&b(f,"style",r[1]),(!g||I[0]&32&&p!==(p=je(r[30])))&&b(f,"d",p),I[0]&268491048){x=Oe(r[30].rings);let M;for(M=0;M<x.length;M+=1){const F=Hc(r,x,M);S[M]?(S[M].p(F,I),ht(S[M],1)):(S[M]=Yc(F),S[M].c(),ht(S[M],1),S[M].m(t,null))}for(Ce(),M=x.length;M<S.length;M+=1)R(M);Ie()}},i(C){if(!g){for(let I=0;I<x.length;I+=1)ht(S[I]);g=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)yt(S[I]);g=!1},d(C){C&&et(t),v&&v.d(),m&&m.d(),ai(S,C),y=!1,De(_)}}}function qc(r){let t,e;return t=new Sc({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){kt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Y0(r){let t,e,i,n=Oe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=zc($c(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&qc(wa(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Se(),a&&a.c(),e=Ne()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);rt(l,t,h),a&&a.m(l,h),rt(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Oe(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=$c(l,n,c);s[c]?(s[c].p(u,h),ht(s[c],1)):(s[c]=zc(u),s[c].c(),ht(s[c],1),s[c].m(t.parentNode,t))}for(Ce(),c=n.length;c<s.length;c+=1)o(c);Ie()}l[6]!==void 0&&!l[7]?a?(a.p(wa(l),h),h[0]&192&&ht(a,1)):(a=qc(wa(l)),a.c(),ht(a,1),a.m(e.parentNode,e)):a&&(Ce(),yt(a,1,1,()=>{a=null}),Ie())},i(l){if(!i){for(let h=0;h<n.length;h+=1)ht(s[h]);ht(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)yt(s[h]);yt(a),i=!1},d(l){l&&(et(t),et(e)),ai(s,l),a&&a.d(l)}}}function z0(r){let t,e;return t=new ya({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Y0,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const q0=250,K0=1e3,Bn=4.5;function Z0(r,t,e){let i,n,s;const o=kr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(g.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[L,O]=h.elementToImage(A.offsetX,A.offsetY),D=k=>Math.pow(k[0]-L,2)+Math.pow(k[1]-O,2),$=ay(i).reduce((k,V)=>D(V)<D(k)?V:k),B=n.filter(k=>k.visible).reduce((k,V)=>D(V.point)<D(k.point)?V:k),N=Math.pow(K0/c,2);D($)<N||D(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,L,O)=>D=>{if(!p||Ge||performance.now()-p>q0)return;const $=N=>N.polygon===A&&N.ring===L&&N.point===O,B=g.some($);D.metaKey||D.ctrlKey||D.shiftKey?B?e(8,g=g.filter(N=>!$(N))):e(8,g=[...g,{polygon:A,ring:L,point:O}]):B&&g.length>1?e(8,g=[{polygon:A,ring:L,point:O}]):B?e(8,g=[]):e(8,g=[{polygon:A,ring:L,point:O}]),m()},C=(A,L,O)=>{m();const D=A.geometry.polygons;let $;if(L==="SHAPE")$=D.map(B=>{const N=B.rings.map((V,j)=>({points:V.points.map((st,H)=>[st[0]+O[0],st[1]+O[1]])})),k=ge(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,V]=L.split("-").map(j=>parseInt(j));$=D.map((j,st)=>{if(st===N){const H=j.rings.map((X,gt)=>gt===k?{points:X.points.map((lt,ft)=>ft===V?[lt[0]+O[0],lt[1]+O[1]]:lt)}:X),at=ge(H[0].points);return{rings:H,bounds:at}}else return j})}return{...A,geometry:{polygons:$,bounds:ua($)}}},I=A=>async L=>{L.stopPropagation();const O=n[A],D=i.polygons.map((B,N)=>{if(N===O.elementIdx){const k=B.rings.map((j,st)=>st===O.ringIdx?{points:[...j.points.slice(0,O.pointIdx+1),O.point,...j.points.slice(O.pointIdx+1)]}:j),V=ge(k[0].points);return{rings:k,bounds:V}}else return B});o("change",{...a,geometry:{polygons:D,bounds:ua(D)}}),await dc();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((L,O)=>{if(g.some(D=>D.polygon===O)){const D=L.rings.map((B,N)=>{const k=g.filter(V=>V.polygon===O&&V.ring===N);return k.length&&B.points.length-k.length>=3?{points:B.points.filter((V,j)=>!k.some(st=>st.point===j))}:B}),$=ge(D[0].points);return{rings:D,bounds:$}}else return L});!xa(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:ua(A)}}),e(8,g=[]))};Fr(()=>{if(Ge)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,O,{polygon:D,ring:$,point:B})=>D===A&&$===L&&B===O;function P(A){oe.call(this,r,A)}function T(A){oe.call(this,r,A)}function w(A){oe.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ge?[]:W0(i,c)),r.$$.dirty[0]&40&&e(9,s=Ps(i.bounds,Bn/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,x,S,R,C,I,F,U,P,T,w]}class J0 extends me{constructor(t){super(),pe(this,t,Z0,z0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Kc=new Map([[_t.RECTANGLE,X0],[_t.POLYGON,N0],[_t.MULTIPOLYGON,J0]]),Aa=r=>Kc.get(r.type),Zc=(r,t)=>Kc.set(r,t);function Q0(r,t,e){let i;const n=kr();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return Fr(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=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=hi(s,a,{selected:!0,hovered:!0})),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.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})},[s,o,a,l,h,c,u,i]}class t_ extends me{constructor(t){super(),pe(this,t,Q0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function e_(r,t,e){const i=kr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return Fr(()=>{const c=s.closest("svg"),u=[],d=(f,p,g)=>{c==null||c.addEventListener(f,p,g),u.push(()=>c==null?void 0:c.removeEventListener(f,p,g))};return e(5,h=new o({target:s,props:{addEventListener:d,drawingMode:n,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,n=c.drawingMode),"target"in c&&e(1,s=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})},[n,s,o,a,l,h]}class r_ extends me{constructor(t){super(),pe(this,t,e_,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Jc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("rect"),h=Y("rect"),c=Y("rect"),b(i,"class","rect-mask-bg svelte-1a76qe7"),b(i,"x",n=r[1]-r[5]),b(i,"y",s=r[2]-r[5]),b(i,"width",o=r[3]+2*r[5]),b(i,"height",a=r[4]+2*r[5]),b(l,"class","rect-mask-fg svelte-1a76qe7"),b(l,"x",r[1]),b(l,"y",r[2]),b(l,"width",r[3]),b(l,"height",r[4]),b(e,"id",r[6]),b(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),b(h,"class","a9s-outer"),b(h,"mask",`url(#${r[6]})`),b(h,"x",r[1]),b(h,"y",r[2]),b(h,"width",r[3]),b(h,"height",r[4]),b(c,"class","a9s-inner"),b(c,"x",r[1]),b(c,"y",r[2]),b(c,"width",r[3]),b(c,"height",r[4])},m(u,d){rt(u,t,d),bt(t,e),bt(e,i),bt(e,l),rt(u,h,d),rt(u,c,d)},p(u,d){d&34&&n!==(n=u[1]-u[5])&&b(i,"x",n),d&36&&s!==(s=u[2]-u[5])&&b(i,"y",s),d&40&&o!==(o=u[3]+2*u[5])&&b(i,"width",o),d&48&&a!==(a=u[4]+2*u[5])&&b(i,"height",a),d&2&&b(l,"x",u[1]),d&4&&b(l,"y",u[2]),d&8&&b(l,"width",u[3]),d&16&&b(l,"height",u[4]),d&2&&b(h,"x",u[1]),d&4&&b(h,"y",u[2]),d&8&&b(h,"width",u[3]),d&16&&b(h,"height",u[4]),d&2&&b(c,"x",u[1]),d&4&&b(c,"y",u[2]),d&8&&b(c,"width",u[3]),d&16&&b(c,"height",u[4])},d(u){u&&(et(t),et(h),et(c))}}}function i_(r){let t,e=r[0]&&Jc(r);return{c(){t=Y("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Jc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&et(t),e&&e.d()}}}function n_(r,t,e){let i;const n=kr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,f,p,g;const y=S=>{const R=S;h=performance.now(),o==="drag"&&(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,f=c[1]),e(3,p=1),e(4,g=1))},_=S=>{const R=S;c&&(u=a.elementToImage(R.offsetX,R.offsetY),e(1,d=Math.min(u[0],c[0])),e(2,f=Math.min(u[1],c[1])),e(3,p=Math.abs(u[0]-c[0])),e(4,g=Math.abs(u[1]-c[1])))},v=S=>{const R=S,C=performance.now()-h;if(o==="click"){if(C>300)return;c?m():(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,f=c[1]),e(3,p=1),e(4,g=1))}else c&&(C>300||p*g>100?(R.stopPropagation(),m()):(e(0,c=void 0),u=void 0))},m=()=>{if(p*g>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+g},rot:0,x:d,y:f,w:p,h:g}};n("create",S)}e(0,c=void 0),u=void 0};Fr(()=>{s("pointerdown",y),s("pointermove",_),s("pointerup",v,!0)});const x=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=S=>{"addEventListener"in S&&e(7,s=S.addEventListener),"drawingMode"in S&&e(8,o=S.drawingMode),"transform"in S&&e(9,a=S.transform),"viewportScale"in S&&e(10,l=S.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[c,d,f,p,g,i,x,s,o,a,l]}class s_ extends me{constructor(t){super(),pe(this,t,n_,i_,Kt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Sa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function Qc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g=r[1]&&tu(r);return{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("polygon"),c=Y("polygon"),d=Y("polygon"),g&&g.c(),p=Ne(),b(i,"x",n=r[3].x),b(i,"y",s=r[3].y),b(i,"width",o=r[3].w),b(i,"height",a=r[3].h),b(i,"class","svelte-18wrg3t"),b(l,"points",h=r[19]),b(l,"class","svelte-18wrg3t"),b(e,"id",r[5]),b(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),b(c,"class","a9s-outer"),b(c,"mask",`url(#${r[5]})`),b(c,"points",u=r[19]),b(d,"class","a9s-inner"),b(d,"points",f=r[19])},m(y,_){rt(y,t,_),bt(t,e),bt(e,i),bt(e,l),rt(y,c,_),rt(y,d,_),g&&g.m(y,_),rt(y,p,_)},p(y,_){_&8&&n!==(n=y[3].x)&&b(i,"x",n),_&8&&s!==(s=y[3].y)&&b(i,"y",s),_&8&&o!==(o=y[3].w)&&b(i,"width",o),_&8&&a!==(a=y[3].h)&&b(i,"height",a),_&4&&h!==(h=y[19])&&b(l,"points",h),_&4&&u!==(u=y[19])&&b(c,"points",u),_&4&&f!==(f=y[19])&&b(d,"points",f),y[1]?g?g.p(y,_):(g=tu(y),g.c(),g.m(p.parentNode,p)):g&&(g.d(1),g=null)},d(y){y&&(et(t),et(c),et(d),et(p)),g&&g.d(y)}}}function tu(r){let t,e,i;return{c(){t=Y("circle"),b(t,"class","a9s-handle svelte-18wrg3t"),b(t,"cx",e=r[0][0][0]),b(t,"cy",i=r[0][0][1]),b(t,"r",r[4])},m(n,s){rt(n,t,s)},p(n,s){s&1&&e!==(e=n[0][0][0])&&b(t,"cx",e),s&1&&i!==(i=n[0][0][1])&&b(t,"cy",i),s&16&&b(t,"r",n[4])},d(n){n&&et(t)}}}function o_(r){let t,e=r[3]&&Qc(Sa(r));return{c(){t=Y("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(Sa(i),n):(e=Qc(Sa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&et(t),e&&e.d()}}}const a_=20,l_=1500;function h_(r,t,e){let i,n,s;const o=kr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],f,p,g=!1;const y=R=>{const C=R,{timeStamp:I,offsetX:M,offsetY:F}=C;if(u={timeStamp:I,offsetX:M,offsetY:F},l==="drag"&&d.length===0){const U=h.elementToImage(C.offsetX,C.offsetY);d.push(U),e(10,f=U)}},_=R=>{const C=R;if(p&&clearTimeout(p),d.length>0){if(e(10,f=h.elementToImage(C.offsetX,C.offsetY)),d.length>2){const I=As(f,d[0])*c;e(1,g=I<a_)}C.pointerType==="touch"&&(p=setTimeout(()=>{m()},l_))}},v=R=>{const C=R;if(p&&clearTimeout(p),l==="click"){const I=C.timeStamp-u.timeStamp,M=As([u.offsetX,u.offsetY],[C.offsetX,C.offsetY]);if(I>300||M>15)return;if(g)x();else if(d.length===0){const F=h.elementToImage(C.offsetX,C.offsetY);d.push(F),e(10,f=F)}else f&&d.push(f)}else{if(!f)return;if(d.length===1&&As(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}C.stopImmediatePropagation(),g?x():d.push(f)}},m=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:ge(d),points:R}};ca(C)>4&&(e(0,d=[]),e(10,f=void 0),o("create",C))},x=()=>{const R={type:_t.POLYGON,geometry:{bounds:ge(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};Fr(()=>{a("pointerdown",y,!0),a("pointermove",_),a("pointerup",v,!0),a("dblclick",m,!0)});const S=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=R=>{"addEventListener"in R&&e(6,a=R.addEventListener),"drawingMode"in R&&e(7,l=R.drawingMode),"transform"in R&&e(8,h=R.transform),"viewportScale"in R&&e(9,c=R.viewportScale)},r.$$.update=()=>{r.$$.dirty&512&&e(4,i=4/c),r.$$.dirty&1027&&e(2,n=f?g?d:[...d,f]:[]),r.$$.dirty&516&&e(3,s=n.length>0?Ps(ge(n),2/c):void 0)},[d,g,n,s,i,S,a,l,h,c,f]}class c_ extends me{constructor(t){super(),pe(this,t,h_,o_,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Ca=new Map([["rectangle",{tool:s_}],["polygon",{tool:c_}]]),Rs=()=>[...Ca.keys()],Ms=r=>Ca.get(r),eu=(r,t,e={})=>Ca.set(r,{tool:t,opts:e});function u_(r){let t,e,i,n,s;return{c(){t=Y("g"),e=Y("ellipse"),n=Y("ellipse"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"cx",r[2]),b(e,"cy",r[3]),b(e,"rx",r[4]),b(e,"ry",r[5]),b(n,"class","a9s-inner"),b(n,"style",r[1]),b(n,"cx",r[2]),b(n,"cy",r[3]),b(n,"rx",r[4]),b(n,"ry",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&b(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&et(t)}}}function d_(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:c}=s;return r.$$set=u=>{"annotation"in u&&e(0,n=u.annotation),"geom"in u&&e(6,s=u.geom),"style"in u&&e(7,o=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=hi(n,o))},[n,i,a,l,h,c,s,o]}class f_ extends me{constructor(t){super(),pe(this,t,d_,u_,Kt,{annotation:0,geom:6,style:7})}}function p_(r){let t,e,i,n,s;return{c(){t=Y("g"),e=Y("line"),n=Y("line"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"x1",r[2]),b(e,"y1",r[3]),b(e,"x2",r[4]),b(e,"y2",r[5]),b(n,"class","a9s-inner"),b(n,"style",r[1]),b(n,"x1",r[2]),b(n,"y1",r[3]),b(n,"x2",r[4]),b(n,"y2",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&b(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&et(t)}}}function m_(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s,[[l,h],[c,u]]=a;return r.$$set=d=>{"annotation"in d&&e(0,n=d.annotation),"geom"in d&&e(6,s=d.geom),"style"in d&&e(7,o=d.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=hi(n,o))},[n,i,l,h,c,u,s,o]}class g_ extends me{constructor(t){super(),pe(this,t,m_,p_,Kt,{annotation:0,geom:6,style:7})}}function ru(r,t,e){const i=r.slice();return i[5]=t[e],i}function iu(r){let t,e,i;return{c(){t=Y("path"),i=Y("path"),b(t,"class","a9s-outer"),b(t,"style",e=r[1]?"display:none;":void 0),b(t,"fill-rule","evenodd"),b(t,"d",je(r[5])),b(i,"class","a9s-inner"),b(i,"style",r[1]),b(i,"fill-rule","evenodd"),b(i,"d",je(r[5]))},m(n,s){rt(n,t,s),rt(n,i,s)},p(n,s){s&2&&e!==(e=n[1]?"display:none;":void 0)&&b(t,"style",e),s&2&&b(i,"style",n[1])},d(n){n&&(et(t),et(i))}}}function y_(r){let t,e,i=Oe(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=iu(ru(r,i,s));return{c(){t=Y("g");for(let s=0;s<n.length;s+=1)n[s].c();b(t,"class","a9s-annotation"),b(t,"data-id",e=r[0].id)},m(s,o){rt(s,t,o);for(let a=0;a<n.length;a+=1)n[a]&&n[a].m(t,null)},p(s,[o]){if(o&6){i=Oe(s[2]);let a;for(a=0;a<i.length;a+=1){const l=ru(s,i,a);n[a]?n[a].p(l,o):(n[a]=iu(l),n[a].c(),n[a].m(t,null))}for(;a<n.length;a+=1)n[a].d(1);n.length=i.length}o&1&&e!==(e=s[0].id)&&b(t,"data-id",e)},i:Rt,o:Rt,d(s){s&&et(t),ai(n,s)}}}function __(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{polygons:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=hi(n,o))},[n,i,a,s,o]}class v_ extends me{constructor(t){super(),pe(this,t,__,y_,Kt,{annotation:0,geom:3,style:4})}}function b_(r){let t,e,i,n,s;return{c(){t=Y("g"),e=Y("polygon"),n=Y("polygon"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"points",r[2].map(x_).join(" ")),b(n,"class","a9s-inner"),b(n,"style",r[1]),b(n,"points",r[2].map(w_).join(" ")),b(t,"class","a9s-annotation"),b(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&b(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&et(t)}}}const x_=r=>r.join(","),w_=r=>r.join(",");function E_(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=hi(n,o))},[n,i,a,s,o]}class T_ extends me{constructor(t){super(),pe(this,t,E_,b_,Kt,{annotation:0,geom:3,style:4})}}function A_(r){let t,e,i,n,s,o,a;return{c(){t=Y("g"),e=Y("path"),s=Y("path"),b(e,"class",i=ki(`a9s-outer ${r[1]}`)+" svelte-1w0132l"),b(e,"style",n=r[3]?"display:none;":void 0),b(e,"d",r[2]),b(s,"class",o=ki(`a9s-inner ${r[1]}`)+" svelte-1w0132l"),b(s,"style",r[3]),b(s,"d",r[2]),b(t,"class","a9s-annotation"),b(t,"data-id",a=r[0].id)},m(l,h){rt(l,t,h),bt(t,e),bt(t,s)},p(l,[h]){h&2&&i!==(i=ki(`a9s-outer ${l[1]}`)+" svelte-1w0132l")&&b(e,"class",i),h&8&&n!==(n=l[3]?"display:none;":void 0)&&b(e,"style",n),h&4&&b(e,"d",l[2]),h&2&&o!==(o=ki(`a9s-inner ${l[1]}`)+" svelte-1w0132l")&&b(s,"class",o),h&8&&b(s,"style",l[3]),h&4&&b(s,"d",l[2]),h&1&&a!==(a=l[0].id)&&b(t,"data-id",a)},i:Rt,o:Rt,d(l){l&&et(t)}}}function S_(r,t,e){let i,n,s,{annotation:o}=t,{geom:a}=t,{style:l}=t;return r.$$set=h=>{"annotation"in h&&e(0,o=h.annotation),"geom"in h&&e(4,a=h.geom),"style"in h&&e(5,l=h.style)},r.$$.update=()=>{r.$$.dirty&33&&e(3,i=hi(o,l)),r.$$.dirty&16&&e(2,n=fa(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class C_ extends me{constructor(t){super(),pe(this,t,S_,A_,Kt,{annotation:0,geom:4,style:5})}}function I_(r){let t,e,i,n,s,o;return{c(){t=Y("g"),e=Y("g"),i=Y("rect"),s=Y("rect"),b(i,"class","a9s-outer"),b(i,"style",n=r[6]?"display:none;":void 0),b(i,"x",r[4]),b(i,"y",r[2]),b(i,"width",r[3]),b(i,"height",r[1]),b(s,"class","a9s-inner"),b(s,"style",r[6]),b(s,"x",r[4]),b(s,"y",r[2]),b(s,"width",r[3]),b(s,"height",r[1]),b(e,"transform",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",o=r[0].id)},m(a,l){rt(a,t,l),bt(t,e),bt(e,i),bt(e,s)},p(a,[l]){l&64&&n!==(n=a[6]?"display:none;":void 0)&&b(i,"style",n),l&16&&b(i,"x",a[4]),l&4&&b(i,"y",a[2]),l&8&&b(i,"width",a[3]),l&2&&b(i,"height",a[1]),l&64&&b(s,"style",a[6]),l&16&&b(s,"x",a[4]),l&4&&b(s,"y",a[2]),l&8&&b(s,"width",a[3]),l&2&&b(s,"height",a[1]),l&32&&b(e,"transform",a[5]),l&1&&o!==(o=a[0].id)&&b(t,"data-id",o)},i:Rt,o:Rt,d(a){a&&et(t)}}}function P_(r,t,e){let i,n,s,o,a,l,h,{annotation:c}=t,{geom:u}=t,{style:d}=t;return r.$$set=f=>{"annotation"in f&&e(0,c=f.annotation),"geom"in f&&e(7,u=f.geom),"style"in f&&e(8,d=f.style)},r.$$.update=()=>{r.$$.dirty&257&&e(6,i=hi(c,d)),r.$$.dirty&128&&e(4,{x:n,y:s,w:o,h:a,rot:l}=u,n,(e(2,s),e(7,u)),(e(3,o),e(7,u)),(e(1,a),e(7,u)),(e(9,l),e(7,u))),r.$$.dirty&542&&e(5,h=(l??0)!==0?`translate(${n+o/2}, ${s+a/2}) rotate(${(l??0)*180/Math.PI}) translate(${-(n+o/2)}, ${-(s+a/2)})`:void 0)},[c,a,s,o,n,h,i,u,d,l]}class R_ extends me{constructor(t){super(),pe(this,t,P_,I_,Kt,{annotation:0,geom:7,style:8})}}const M_=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),n=r.createSVGPoint();n.x=t+i.x,n.y=e+i.y;const{x:s,y:o}=n.matrixTransform(r.getScreenCTM().inverse());return[s,o]}}),O_=250,B_=(r,t)=>{const e=kr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<O_){const{x:s,y:o}=nu(n,r),a=Ge?10:2,l=t.getAt(s,o,void 0,a);l?e("click",{originalEvent:n,annotation:l}):e("click",{originalEvent:n})}}}},nu=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),n=r.clientX-i.x,s=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=n+o,e.y=s+a,e.matrixTransform(t.getScreenCTM().inverse())};function su(r,t,e){const i=r.slice();return i[39]=t[e],i}function ou(r,t,e){const i=r.slice();return i[42]=t[e],i}function Ia(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function au(r){let t=r[42],e,i,n=lu(r);return{c(){n.c(),e=Ne()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&131072&&Kt(t,t=s[42])?(Ce(),yt(n,1,1,Rt),Ie(),n=lu(s),n.c(),ht(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n.d(s)}}}function L_(r){let t,e;return t=new g_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function D_(r){let t,e;return t=new C_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function N_(r){let t,e;return t=new v_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function F_(r){let t,e;return t=new T_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function k_(r){let t,e;return t=new R_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function U_(r){var t;let e,i;return e=new f_({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){ee(e.$$.fragment)},m(n,s){Zt(e,n,s),i=!0},p(n,s){var o;const a={};s[0]&131072&&(a.annotation=n[42]),s[0]&131072&&(a.geom=(o=n[45])==null?void 0:o.geometry),s[0]&2&&(a.style=n[1]),e.$set(a)},i(n){i||(ht(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){Jt(e,n)}}}function lu(r){let t,e,i,n;const s=[U_,k_,F_,N_,D_,L_],o=[];function a(l,h){var c,u,d,f,p,g;return((c=l[45])==null?void 0:c.type)===_t.ELLIPSE?0:((u=l[45])==null?void 0:u.type)===_t.RECTANGLE?1:((d=l[45])==null?void 0:d.type)===_t.POLYGON?2:((f=l[45])==null?void 0:f.type)===_t.MULTIPOLYGON?3:((p=l[45])==null?void 0:p.type)===_t.POLYLINE?4:((g=l[45])==null?void 0:g.type)===_t.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Ne()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ce(),yt(o[c],1,1,()=>{o[c]=null}),Ie()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),ht(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(ht(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function hu(r){let t=Ue(r[42])&&!r[10](r[42]),e,i,n=t&&au(Ia(r));return{c(){n&&n.c(),e=Ne()},m(s,o){n&&n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Ue(s[42])&&!s[10](s[42])),t?n?(n.p(Ia(s),o),o[0]&132096&&ht(n,1)):(n=au(Ia(s)),n.c(),ht(n,1),n.m(e.parentNode,e)):n&&(Ce(),yt(n,1,1,()=>{n=null}),Ie())},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n&&n.d(s)}}}function cu(r){let t,e,i,n;const s=[$_,G_],o=[];function a(l,h){return l[6]?0:l[15]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Ne()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ce(),yt(o[c],1,1,()=>{o[c]=null}),Ie()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),ht(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(ht(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function G_(r){let t=`${r[2]}-${r[7]}`,e,i,n=uu(r);return{c(){n.c(),e=Ne()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132&&Kt(t,t=`${s[2]}-${s[7]}`)?(Ce(),yt(n,1,1,Rt),Ie(),n=uu(s),n.c(),ht(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n.d(s)}}}function $_(r){let t,e,i=Oe(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=fu(su(r,i,o));const s=o=>yt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Ne()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&8659266){i=Oe(o[6]);let l;for(l=0;l<i.length;l+=1){const h=su(o,i,l);n[l]?(n[l].p(h,a),ht(n[l],1)):(n[l]=fu(h),n[l].c(),ht(n[l],1),n[l].m(t.parentNode,t))}for(Ce(),l=i.length;l<n.length;l+=1)s(l);Ie()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ht(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&et(t),ai(n,o)}}}function uu(r){let t,e;return t=new r_({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&32768&&(s.tool=i[15]),n[0]&16384&&(s.drawingMode=i[14]),n[0]&8192&&(s.transform=i[13]),n[0]&262144&&(s.viewportScale=i[18]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function du(r){let t,e;return t=new t_({props:{target:r[8],editor:r[39].editor,annotation:r[39].annotation,style:r[1],transform:r[13],viewportScale:r[18]}}),t.$on("change",function(){kt(r[23](r[39].annotation))&&r[23](r[39].annotation).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&64&&(s.editor=r[39].editor),n[0]&64&&(s.annotation=r[39].annotation),n[0]&2&&(s.style=r[1]),n[0]&8192&&(s.transform=r[13]),n[0]&262144&&(s.viewportScale=r[18]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function fu(r){let t=r[39].annotation.id,e,i,n=du(r);return{c(){n.c(),e=Ne()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&64&&Kt(t,t=s[39].annotation.id)?(Ce(),yt(n,1,1,Rt),Ie(),n=du(s),n.c(),ht(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n.d(s)}}}function H_(r){let t,e,i,n,s,o,a=Oe(r[17].filter(r[34])),l=[];for(let u=0;u<a.length;u+=1)l[u]=hu(ou(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&cu(r);return{c(){t=Y("svg"),e=Y("g");for(let u=0;u<l.length;u+=1)l[u].c();i=Y("g"),c&&c.c(),b(i,"class","drawing"),b(t,"role","application"),b(t,"tabindex",0),b(t,"class","a9s-annotationlayer"),ir(t,"drawing",r[15]),ir(t,"editing",r[5]),ir(t,"hidden",!r[3]),ir(t,"hover",r[16])},m(u,d){rt(u,t,d),bt(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);bt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[Ct(t,"pointerup",function(){kt(r[11])&&r[11].apply(this,arguments)}),Ct(t,"pointerdown",function(){kt(r[12])&&r[12].apply(this,arguments)}),Ct(t,"pointermove",r[24])],s=!0)},p(u,d){if(r=u,d[0]&132098){a=Oe(r[17].filter(r[34]));let f;for(f=0;f<a.length;f+=1){const p=ou(r,a,f);l[f]?(l[f].p(p,d),ht(l[f],1)):(l[f]=hu(p),l[f].c(),ht(l[f],1),l[f].m(e,null))}for(Ce(),f=a.length;f<l.length;f+=1)h(f);Ie()}r[8]?c?(c.p(r,d),d[0]&256&&ht(c,1)):(c=cu(r),c.c(),ht(c,1),c.m(i,null)):c&&(Ce(),yt(c,1,1,()=>{c=null}),Ie()),(!n||d[0]&32768)&&ir(t,"drawing",r[15]),(!n||d[0]&32)&&ir(t,"editing",r[5]),(!n||d[0]&8)&&ir(t,"hidden",!r[3]),(!n||d[0]&65536)&&ir(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)ht(l[d]);ht(c),n=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)yt(l[d]);yt(c),n=!1},d(u){u&&et(t),ai(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,De(o)}}}function V_(r,t,e){let i,n,s,o,a,l,h,c,u,d,f,p,g=Rt,y=()=>(g(),g=nc(A,X=>e(18,p=X)),A);r.$$.on_destroy.push(()=>g());let{drawingEnabled:_}=t,{image:v}=t,{preferredDrawingMode:m}=t,{state:x}=t,{style:S=void 0}=t,{toolName:R=Rs()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let T,w,A;Fr(()=>y(e(9,A=_0(v,w))));const{hover:L,selection:O,store:D}=x;sa(r,L,X=>e(16,u=X)),sa(r,O,X=>e(33,d=X)),sa(r,D,X=>e(17,f=X));let $,B;const N=X=>{$&&D.unobserve($);const gt=X.filter(({editable:lt})=>lt).map(({id:lt})=>lt);gt.length>0?(e(5,B=gt.map(lt=>D.getAnnotation(lt)).filter(lt=>lt&&Ue(lt))),$=lt=>{const{updated:ft}=lt.changes;e(5,B=ft==null?void 0:ft.map(ct=>ct.newValue))},D.observe($,{annotations:gt})):e(5,B=void 0)},k=X=>{const gt=vc(),lt={id:gt,bodies:[],target:{annotation:gt,selector:X.detail,creator:C,created:new Date}};D.addAnnotation(lt),O.setSelected(lt.id)},V=X=>gt=>{var lt;const{target:ft}=X,ct=10*60*1e3,Et=((lt=ft.creator)==null?void 0:lt.id)!==C.id||!ft.created||new Date().getTime()-ft.created.getTime()>ct;D.updateTarget({...ft,selector:gt.detail,created:Et?ft.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},j=X=>{const{x:gt,y:lt}=nu(X,w),ft=D.getAt(gt,lt,void 0,2);ft?u!==ft.id&&L.set(ft.id):L.set(void 0)},st=X=>Ue(X);function H(X){xs[X?"unshift":"push"](()=>{T=X,e(8,T)})}function at(X){xs[X?"unshift":"push"](()=>{w=X,e(4,w)})}return r.$$set=X=>{"drawingEnabled"in X&&e(0,_=X.drawingEnabled),"image"in X&&e(25,v=X.image),"preferredDrawingMode"in X&&e(26,m=X.preferredDrawingMode),"state"in X&&e(27,x=X.state),"style"in X&&e(1,S=X.style),"toolName"in X&&e(2,R=X.toolName),"user"in X&&e(28,C=X.user),"visible"in X&&e(3,I=X.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=Ms(R)||{tool:void 0,opts:void 0},i,(e(32,n),e(2,R))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(14,s=(n==null?void 0:n.drawingMode)||m),r.$$.dirty[0]&16&&e(13,o=M_(w)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=B_(w,D),a,(e(11,l),e(4,w))),r.$$.dirty[1]&4&&N(d.selected),r.$$.dirty[0]&32&&e(6,h=B?B.map(X=>({annotation:X,editor:Aa(X.target.selector)})).filter(X=>X.editor):void 0),r.$$.dirty[0]&64&&e(10,c=X=>h&&h.some(gt=>gt.annotation.id===X.id))},[_,S,R,I,w,B,h,M,T,A,c,l,a,o,s,i,u,f,p,L,O,D,k,V,j,v,m,x,C,F,U,P,n,d,st,H,at]}class X_ extends me{constructor(t){super(),pe(this,t,V_,H_,Kt,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function pu(r,t,e=0,i=r.length-1,n=j_){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));pu(r,t,f,p,n)}const s=r[t];let o=e,a=i;for(Ln(r,e,t),n(r[i],s)>0&&Ln(r,e,i);o<a;){for(Ln(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?Ln(r,e,a):(a++,Ln(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function Ln(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function j_(r,t){return r<t?-1:r>t?1:0}class W_{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(!Bs(t,e))return i;const n=this.toBBox,s=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?n(a):a;Bs(t,l)&&(e.leaf?i.push(a):Ra(t,l)?this._all(a,i):s.push(a))}e=s.pop()}return i}collides(t){let e=this.data;if(!Bs(t,e))return!1;const i=[];for(;e;){for(let n=0;n<e.children.length;n++){const s=e.children[n],o=e.leaf?this.toBBox(s):s;if(Bs(t,o)){if(e.leaf||Ra(t,o))return!0;i.push(s)}}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=ji([]),this}remove(t,e){if(!t)return this;let i=this.data;const n=this.toBBox(t),s=[],o=[];let a,l,h;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=o.pop(),h=!0),i.leaf){const c=Y_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&Ra(i,n)?(s.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,n){const s=i-e+1;let o=this._maxEntries,a;if(s<=o)return a=ji(t.slice(e,i+1)),Xi(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=ji([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));mu(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);mu(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,n-1))}}return Xi(a,this.toBBox),a}_chooseSubtree(t,e,i,n){for(;n.push(e),!(e.leaf||n.length-1===i);){let s=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],c=Pa(h),u=K_(t,h)-c;u<o?(o=u,s=c<s?c:s,a=h):u===o&&c<s&&(s=c,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const n=i?t:this.toBBox(t),s=[],o=this._chooseSubtree(n,this.data,e,s);for(o.children.push(t),Nn(o,n);e>=0&&s[e].children.length>this._maxEntries;)this._split(s,e),e--;this._adjustParentBBoxes(n,s,e)}_split(t,e){const i=t[e],n=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,n);const o=this._chooseSplitIndex(i,s,n),a=ji(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Xi(i,this.toBBox),Xi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=ji([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Xi(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let n,s=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=Dn(t,0,a,this.toBBox),h=Dn(t,a,i,this.toBBox),c=Z_(l,h),u=Pa(l)+Pa(h);c<s?(s=c,n=a,o=u<o?u:o):c===s&&u<o&&(o=u,n=a)}return n||i-e}_chooseSplitAxis(t,e,i){const n=t.leaf?this.compareMinX:z_,s=t.leaf?this.compareMinY:q_,o=this._allDistMargin(t,e,i,n),a=this._allDistMargin(t,e,i,s);o<a&&t.children.sort(n)}_allDistMargin(t,e,i,n){t.children.sort(n);const s=this.toBBox,o=Dn(t,0,e,s),a=Dn(t,i-e,i,s);let l=Os(o)+Os(a);for(let h=e;h<i-e;h++){const c=t.children[h];Nn(o,t.leaf?s(c):c),l+=Os(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];Nn(a,t.leaf?s(c):c),l+=Os(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)Nn(e[n],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():Xi(t[e],this.toBBox)}}function Y_(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 Xi(r,t){Dn(r,0,r.children.length,t,r)}function Dn(r,t,e,i,n){n||(n=ji(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let s=t;s<e;s++){const o=r.children[s];Nn(n,r.leaf?i(o):o)}return n}function Nn(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 z_(r,t){return r.minX-t.minX}function q_(r,t){return r.minY-t.minY}function Pa(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Os(r){return r.maxX-r.minX+(r.maxY-r.minY)}function K_(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 Z_(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),n=Math.min(r.maxX,t.maxX),s=Math.min(r.maxY,t.maxY);return Math.max(0,n-e)*Math.max(0,s-i)}function Ra(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function Bs(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function ji(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function mu(r,t,e,i,n){const s=[t,e];for(;s.length;){if(e=s.pop(),t=s.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;pu(r,o,t,e,n),s.push(t,o,o,e)}}const J_=()=>{const r=new W_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!Ss(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)},s=o=>{if(!Ss(o))return;const a=t.get(o.annotation);a&&r.remove(a),t.delete(o.annotation)};return{all:e,clear:i,getAt:(o,a,l=0)=>{const h=r.search({minX:o-l,minY:a-l,maxX:o+l,maxY:a+l}).map(c=>c.target).filter(({selector:c})=>ry(c,o,a,l));return h.length>0?(h.sort((c,u)=>ca(c.selector)-ca(u.selector)),h):[]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(c=>c.target),insert:n,remove:s,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,c)=>{if(Ss(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)=>{s(o),n(a)}}},Q_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}}),gu=r=>{const t=zy(),e=J_(),i=Ly(t,r.userSelectAction,r.adapter),n=By(t),s=Jy();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,l,h)=>{const c=e.getAt(o,a,h);if(l)return c.map(u=>t.getAnnotation(u.annotation)).filter(Boolean).filter(l)[0];{const u=c[0];return u?t.getAnnotation(u.annotation):void 0}},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(c=>t.getAnnotation(c.annotation)).filter(Boolean)},selection:i,hover:n,viewport:s}},tv=r=>{const t=gu(r);return{...t,store:Q_(t.store)}},ev=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const n=r;t=document.createElement("canvas"),t.width=n.width,t.height=n.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(n,0,0,n.width,n.height)}let i=0;for(let n=1;n<10;n++)for(let s=1;s<10;s++){const o=Math.round(s*t.width/10),a=Math.round(n*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},yu=r=>{const t=ev(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},_u=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?yu(r):e),vu=(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}),bu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,xu=(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()},n=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},s=()=>{bu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return bu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},rv=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=vu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:xc.EDIT,theme:"light"}),n=tv(i),{selection:s,store:o}=n,a=Zy(o,i.initialHistory),l=Qy(n,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=xu(a);let u=h0();_u(e,h,i.theme);const d=new X_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",T=>{const{originalEvent:w,annotation:A}=T.detail;A?s.userSelect(A.id,w):s.isEmpty()||s.clear()});const f=e0(n,a,i.adapter),p=()=>d.cancelDrawing(),g=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>u,v=()=>d.isDrawingEnabled(),m=(T,w,A)=>eu(T,w,A),x=(T,w)=>Zc(T,w),S=T=>{if(!Ms(T))throw`No drawing tool named ${T}`;d.$set({toolName:T})},R=T=>d.$set({drawingEnabled:T}),C=T=>d.$set({preferredDrawingMode:T}),I=T=>{console.warn("Filter not implemented yet")},M=T=>d.$set({style:T}),F=T=>_u(e,h,T),U=T=>{u=T,d.$set({user:T})},P=T=>d.$set({visible:T});return{...f,cancelDrawing:p,destroy:g,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:Rs,on:l.on,off:l.off,registerDrawingTool:m,registerShapeEditor:x,setDrawingEnabled:R,setDrawingMode:C,setDrawingTool:S,setFilter:I,setStyle:M,setTheme:F,setUser:U,setVisible:P,element:h,state:n}};function Nt(){}function Ma(r,t){for(const e in t)r[e]=t[e];return r}function wu(r){return r()}function Eu(){return Object.create(null)}function $e(r){r.forEach(wu)}function jt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function iv(r){return Object.keys(r).length===0}function nv(r,...t){if(r==null){for(const i of t)i(void 0);return Nt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Fn(r,t,e){r.$$.on_destroy.push(nv(t,e))}function Tu(r,t,e,i){if(r){const n=Au(r,t,e,i);return r[0](n)}}function Au(r,t,e,i){return r[1]&&i?Ma(e.ctx.slice(),r[1](i(t))):e.ctx}function Su(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function Cu(r,t,e,i,n,s){if(n){const o=Au(t,e,i,s);r.p(o,n)}}function Iu(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 Pu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ru(r){return r??""}const Oa=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Tt(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function it(r){r.parentNode&&r.parentNode.removeChild(r)}function $r(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function J(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Ba(r){return document.createTextNode(r)}function Pe(){return Ba(" ")}function Be(){return Ba("")}function Pt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function E(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function sv(r){return Array.from(r.childNodes)}function ov(r,t){t=""+t,r.data!==t&&(r.data=t)}function Hr(r,t,e){r.classList.toggle(t,!!e)}function av(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let kn;function Un(r){kn=r}function La(){if(!kn)throw new Error("Function called outside component initialization");return kn}function Vr(r){La().$$.on_mount.push(r)}function lv(r){La().$$.on_destroy.push(r)}function Wi(){const r=La();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=av(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function ae(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Yi=[],Ls=[];let zi=[];const Mu=[],Ou=Promise.resolve();let Da=!1;function Bu(){Da||(Da=!0,Ou.then(Du))}function Lu(){return Bu(),Ou}function Na(r){zi.push(r)}const Fa=new Set;let qi=0;function Du(){if(qi!==0)return;const r=kn;do{try{for(;qi<Yi.length;){const t=Yi[qi];qi++,Un(t),hv(t.$$)}}catch(t){throw Yi.length=0,qi=0,t}for(Un(null),Yi.length=0,qi=0;Ls.length;)Ls.pop()();for(let t=0;t<zi.length;t+=1){const e=zi[t];Fa.has(e)||(Fa.add(e),e())}zi.length=0}while(Yi.length);for(;Mu.length;)Mu.pop()();Da=!1,Fa.clear(),Un(r)}function hv(r){if(r.fragment!==null){r.update(),$e(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Na)}}function cv(r){const t=[],e=[];zi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),zi=t}const Ds=new Set;let ui;function le(){ui={r:0,c:[],p:ui}}function he(){ui.r||$e(ui.c),ui=ui.p}function q(r,t){r&&r.i&&(Ds.delete(r),r.i(t))}function nt(r,t,e,i){if(r&&r.o){if(Ds.has(r))return;Ds.add(r),ui.c.push(()=>{Ds.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ae(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Lt(r){r&&r.c()}function Ot(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Na(()=>{const s=r.$$.on_mount.map(wu).filter(jt);r.$$.on_destroy?r.$$.on_destroy.push(...s):$e(s),r.$$.on_mount=[]}),n.forEach(Na)}function Bt(r,t){const e=r.$$;e.fragment!==null&&(cv(e.after_update),$e(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function uv(r,t){r.$$.dirty[0]===-1&&(Yi.push(r),Bu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Wt(r,t,e,i,n,s,o=null,a=[-1]){const l=kn;Un(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Nt,not_equal:n,bound:Eu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Eu(),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&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&uv(r,u)),d}):[],h.update(),c=!0,$e(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=sv(t.target);h.fragment&&h.fragment.l(u),u.forEach(it)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Ot(r,t.target,t.anchor),Du()}Un(l)}class Yt{constructor(){Yh(this,"$$");Yh(this,"$$set")}$destroy(){Bt(this,1),this.$destroy=Nt}$on(t,e){if(!jt(e))return Nt;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!iv(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const dv="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(dv);var nr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(nr||{}),Gn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ka(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function fv(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 n=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return r[i]}})}),e}var Nu={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,f,p=l+1;p<h;p++){var g=e(a[p],a[l],a[h]);g>d&&(f=p,d=g)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(Nu);var pv=Nu.exports;const mv=ka(pv),Ki=(r,t)=>t,Ye=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},Ns=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Fs=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},gv=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},Fu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return mv(e,t,!0).map(i=>[i.x,i.y])},yv=(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))},_v={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Ki(nr.ELLIPSE,_v);const vv={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=yv([n,s],[o,a]);return l/h<=i}};Ki(nr.LINE,vv);const bv={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=Ns(n.points),a=s.reduce((l,h)=>l+Ns(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(Fs(s.points,t,e)){let a=!1;for(const l of o)if(Fs(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},ks=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ye(t)},Zi=r=>r.rings.map(e=>gv(e.points)).join(" "),xv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),wv=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Fu(a.points,t);return{...a,points:l}}),o=Ye(s[0].points);return{...n,rings:s,bounds:o}}),i=ks(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Ki(nr.MULTIPOLYGON,bv);const Ev={area:r=>{const t=r.geometry.points;return Ns(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Fs(i,t,e)}},Tv=(r,t=1)=>{const e=Fu(r.geometry.points,t),i=Ye(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Ki(nr.POLYGON,Ev);const Av={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=ku(t.points,t.closed);return Ns(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=ku(n.points,n.closed);return Fs(s,t,e)}else return Sv(n,[t,e],i)}},ku=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.type==="CURVE"||s.type=="CURVE")){const a=Uu(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...a.slice(1))}}return e},Uu=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},Sv=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.type==="CURVE"||s.type==="CURVE"){const a=Uu(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let l=0;l<a.length-1;l++)if(Gu(t,a[l],a[l+1])<=e)return!0}else if(Gu(t,n.point,s.point)<=e)return!0}return!1},Gu=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u};Ki(nr.POLYLINE,Av);const Cv={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>{const i=r.geometry;if(i.rot){const n=i.x+i.w/2,s=i.y+i.h/2,o=t-n,a=e-s,l=Math.cos(i.rot),h=Math.sin(i.rot),c=o*l+a*h,u=-o*h+a*l;return c>=-i.w/2&&c<=i.w/2&&u>=-i.h/2&&u<=i.h/2}else return t>=i.x&&t<=i.x+i.w&&e>=i.y&&e<=i.y+i.h}};Ki(nr.RECTANGLE,Cv);const ve=[];for(let r=0;r<256;++r)ve.push((r+256).toString(16).slice(1));function Iv(r,t=0){return(ve[r[t+0]]+ve[r[t+1]]+ve[r[t+2]]+ve[r[t+3]]+"-"+ve[r[t+4]]+ve[r[t+5]]+"-"+ve[r[t+6]]+ve[r[t+7]]+"-"+ve[r[t+8]]+ve[r[t+9]]+"-"+ve[r[t+10]]+ve[r[t+11]]+ve[r[t+12]]+ve[r[t+13]]+ve[r[t+14]]+ve[r[t+15]]).toLowerCase()}const Pv=new Uint8Array(16);function Rv(){return crypto.getRandomValues(Pv)}function Mv(r,t,e){return crypto.randomUUID?crypto.randomUUID():Ov(r)}function Ov(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??Rv();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Iv(i)}const Bv=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},Ua=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},Xr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Lv=r=>({}),$u=r=>({grab:r[0]});function Dv(r){let t,e,i,n;const s=r[8].default,o=Tu(s,r,r[7],$u);return{c(){t=J("g"),o&&o.c(),E(t,"class","a9s-annotation selected")},m(a,l){ot(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Pt(t,"pointerup",r[2]),Pt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Cu(o,s,a,a[7],e?Su(s,a[7],l,Lv):Iu(a[7]),$u)},i(a){e||(q(o,a),e=!0)},o(a){nt(o,a),e=!1},d(a){a&&it(t),o&&o.d(a),i=!1,$e(n)}}}function Nv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Wi();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=y=>_=>{if(c=y,h){const{left:m,top:x}=h.getBoundingClientRect(),S=_.clientX-m,R=_.clientY-x;u=l.elementToImage(S,R)}else{const{offsetX:m,offsetY:x}=_;u=l.elementToImage(m,x)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),m=[_-u[0],v-u[1]];e(3,o=a(d,c,m)),s("change",o)}},g=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[f,p,g,o,a,l,h,n,i]}class Ga extends Yt{constructor(t){super(),Wt(this,t,Nv,Dv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function Fv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Hu(r);return{c(){t=J("g"),e=J("circle"),h&&h.c(),n=J("circle"),E(e,"class","a9s-handle-buffer svelte-qtyc7s"),E(e,"cx",r[0]),E(e,"cy",r[1]),E(e,"r",i=r[5]+6/r[2]),E(e,"role","button"),E(e,"tabindex","0"),E(n,"class",s=Ru(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),E(n,"cx",r[0]),E(n,"cy",r[1]),E(n,"r",r[5]),E(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){ot(c,t,u),Tt(t,e),h&&h.m(t,null),Tt(t,n),a||(l=[Pt(e,"dblclick",r[12]),Pt(e,"pointerenter",r[13]),Pt(e,"pointerleave",r[14]),Pt(e,"pointerdown",r[15]),Pt(e,"pointerdown",r[6]),Pt(e,"pointerup",r[16]),Pt(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&E(e,"cx",c[0]),u&2&&E(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&E(e,"r",i),c[3]?h?h.p(c,u):(h=Hu(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ru(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&E(n,"class",s),u&1&&E(n,"cx",c[0]),u&2&&E(n,"cy",c[1]),u&32&&E(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&E(t,"class",o)},d(c){c&&it(t),h&&h.d(),a=!1,$e(l)}}}function kv(r){let t,e,i,n,s,o,a,l,h;return{c(){t=J("g"),e=J("circle"),n=J("circle"),o=J("circle"),E(e,"cx",r[0]),E(e,"cy",r[1]),E(e,"r",i=r[5]*10),E(e,"class","a9s-touch-halo"),Hr(e,"touched",r[4]),E(n,"cx",r[0]),E(n,"cy",r[1]),E(n,"r",s=r[5]+10/r[2]),E(n,"class","a9s-handle-buffer svelte-qtyc7s"),E(n,"role","button"),E(n,"tabindex","0"),E(o,"class","a9s-handle-dot"),E(o,"cx",r[0]),E(o,"cy",r[1]),E(o,"r",a=r[5]+2/r[2]),E(t,"class","a9s-touch-handle")},m(c,u){ot(c,t,u),Tt(t,e),Tt(t,n),Tt(t,o),l||(h=[Pt(n,"dblclick",r[9]),Pt(n,"pointerdown",r[10]),Pt(n,"pointerdown",r[6]),Pt(n,"pointerup",r[11]),Pt(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&E(e,"cx",c[0]),u&2&&E(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&E(e,"r",i),u&16&&Hr(e,"touched",c[4]),u&1&&E(n,"cx",c[0]),u&2&&E(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&E(n,"r",s),u&1&&E(o,"cx",c[0]),u&2&&E(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&E(o,"r",a)},d(c){c&&it(t),l=!1,$e(h)}}}function Hu(r){let t,e;return{c(){t=J("circle"),E(t,"class","a9s-handle-selected"),E(t,"cx",r[0]),E(t,"cy",r[1]),E(t,"r",e=r[5]+8/r[2])},m(i,n){ot(i,t,n)},p(i,n){n&1&&E(t,"cx",i[0]),n&2&&E(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&E(t,"r",e)},d(i){i&&it(t)}}}function Uv(r){let t;function e(s,o){return Xr?kv:Fv}let n=e()(r);return{c(){n.c(),t=Be()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Nt,o:Nt,d(s){s&&it(t),n.d(s)}}}function Gv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=m=>{m.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(m){ae.call(this,r,m)}function d(m){ae.call(this,r,m)}function f(m){ae.call(this,r,m)}function p(m){ae.call(this,r,m)}function g(m){ae.call(this,r,m)}function y(m){ae.call(this,r,m)}function _(m){ae.call(this,r,m)}function v(m){ae.call(this,r,m)}return r.$$set=m=>{e(8,t=Ma(Ma({},t),Pu(m))),"x"in m&&e(0,n=m.x),"y"in m&&e(1,s=m.y),"scale"in m&&e(2,o=m.scale),"selected"in m&&e(3,a=m.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Pu(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,g,y,_,v]}class di extends Yt{constructor(t){super(),Wt(this,t,Gv,Uv,Ut,{x:0,y:1,scale:2,selected:3})}}function $v(r){let t,e,i,n,s,o,a;return{c(){t=J("g"),e=J("circle"),n=J("circle"),s=J("circle"),E(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),E(e,"cx",r[0]),E(e,"cy",r[1]),E(e,"r",i=1.75*r[2]),E(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),E(n,"cx",r[0]),E(n,"cy",r[1]),E(n,"r",r[2]),E(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),E(s,"cx",r[0]),E(s,"cy",r[1]),E(s,"r",r[2]),E(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){ot(l,t,h),Tt(t,e),Tt(t,n),Tt(t,s),o||(a=[Pt(e,"pointerdown",r[5]),Pt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&E(e,"cx",l[0]),h&2&&E(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&E(e,"r",i),h&1&&E(n,"cx",l[0]),h&2&&E(n,"cy",l[1]),h&4&&E(n,"r",l[2]),h&1&&E(s,"cx",l[0]),h&2&&E(s,"cy",l[1]),h&4&&E(s,"r",l[2])},d(l){l&&it(t),o=!1,$e(a)}}}function Hv(r){let t;return{c(){t=J("circle"),E(t,"cx",r[0]),E(t,"cy",r[1]),E(t,"r",r[2])},m(e,i){ot(e,t,i)},p(e,i){i&1&&E(t,"cx",e[0]),i&2&&E(t,"cy",e[1]),i&4&&E(t,"r",e[2])},d(e){e&&it(t)}}}function Vv(r){let t;function e(s,o){return Xr?Hv:$v}let n=e()(r);return{c(){n.c(),t=Be()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Nt,o:Nt,d(s){s&&it(t),n.d(s)}}}function Xv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){ae.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class Vu extends Yt{constructor(t){super(),Wt(this,t,Xv,Vv,Ut,{x:0,y:1,scale:4})}}function $a(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Xu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Ha(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Va(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ju(r){let t,e,i,n;return{c(){t=J("circle"),E(t,"cx",e=r[28][0]),E(t,"cy",i=r[28][1]),E(t,"r",n=$n/r[3]),E(t,"class","svelte-1h2slbm")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&E(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&E(t,"cy",i),o[0]&8&&n!==(n=$n/s[3])&&E(t,"r",n)},d(s){s&&it(t)}}}function Wu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=J("mask"),e=J("rect"),a=J("circle"),E(e,"x",i=r[9].x),E(e,"y",n=r[9].y),E(e,"width",s=r[9].w),E(e,"height",o=r[9].h),E(e,"class","svelte-1h2slbm"),E(a,"cx",l=r[28][0]),E(a,"cy",h=r[28][1]),E(a,"r",c=$n/r[3]),E(a,"class","svelte-1h2slbm"),E(t,"id",`${r[19]}-inner`),E(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){ot(u,t,d),Tt(t,e),Tt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&E(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&E(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&E(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&E(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&E(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&E(a,"cy",h),d[0]&8&&c!==(c=$n/u[3])&&E(a,"r",c)},d(u){u&&it(t)}}}function Yu(r){let t,e;return t=new di({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){jt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function zu(r){let t,e;return t=new Vu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){jt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function jv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R=r[6]!==void 0&&!r[7]&&ju(Va(r)),C=r[6]!==void 0&&!r[7]&&Wu(Ha(r)),I=Ae(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Yu(Xu(r,I,P));const F=P=>nt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&zu($a(r));return{c(){t=J("defs"),e=J("mask"),i=J("rect"),l=J("polygon"),R&&R.c(),C&&C.c(),c=Pe(),u=J("polygon"),f=Pe(),p=J("polygon"),y=Pe();for(let P=0;P<M.length;P+=1)M[P].c();_=Pe(),U&&U.c(),v=Be(),E(i,"x",n=r[9].x),E(i,"y",s=r[9].y),E(i,"width",o=r[9].w),E(i,"height",a=r[9].h),E(i,"class","svelte-1h2slbm"),E(l,"points",h=r[5].points.map(qu).join(" ")),E(l,"class","svelte-1h2slbm"),E(e,"id",`${r[19]}-outer`),E(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),E(u,"class","a9s-outer"),E(u,"mask",`url(#${r[19]}-outer)`),E(u,"points",d=r[5].points.map(Ku).join(" ")),E(p,"class","a9s-inner a9s-shape-handle"),E(p,"mask",`url(#${r[19]}-inner)`),E(p,"style",r[1]),E(p,"points",g=r[5].points.map(Zu).join(" "))},m(P,T){ot(P,t,T),Tt(t,e),Tt(e,i),Tt(e,l),R&&R.m(e,null),C&&C.m(t,null),ot(P,c,T),ot(P,u,T),ot(P,f,T),ot(P,p,T),ot(P,y,T);for(let w=0;w<M.length;w+=1)M[w]&&M[w].m(P,T);ot(P,_,T),U&&U.m(P,T),ot(P,v,T),m=!0,x||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){jt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(p,"pointermove",r[13]),Pt(p,"pointerup",r[14]),Pt(p,"pointerdown",function(){jt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],x=!0)},p(P,T){if(r=P,(!m||T[0]&512&&n!==(n=r[9].x))&&E(i,"x",n),(!m||T[0]&512&&s!==(s=r[9].y))&&E(i,"y",s),(!m||T[0]&512&&o!==(o=r[9].w))&&E(i,"width",o),(!m||T[0]&512&&a!==(a=r[9].h))&&E(i,"height",a),(!m||T[0]&32&&h!==(h=r[5].points.map(qu).join(" ")))&&E(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Va(r),T):(R=ju(Va(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Ha(r),T):(C=Wu(Ha(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!m||T[0]&32&&d!==(d=r[5].points.map(Ku).join(" ")))&&E(u,"points",d),(!m||T[0]&2)&&E(p,"style",r[1]),(!m||T[0]&32&&g!==(g=r[5].points.map(Zu).join(" ")))&&E(p,"points",g),T[0]&134322472){I=Ae(r[5].points);let w;for(w=0;w<I.length;w+=1){const A=Xu(r,I,w);M[w]?(M[w].p(A,T),q(M[w],1)):(M[w]=Yu(A),M[w].c(),q(M[w],1),M[w].m(_.parentNode,_))}for(le(),w=I.length;w<M.length;w+=1)F(w);he()}r[6]!==void 0&&!r[7]?U?(U.p($a(r),T),T[0]&192&&q(U,1)):(U=zu($a(r)),U.c(),q(U,1),U.m(v.parentNode,v)):U&&(le(),nt(U,1,1,()=>{U=null}),he())},i(P){if(!m){for(let T=0;T<I.length;T+=1)q(M[T]);q(U),m=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)nt(M[T]);nt(U),m=!1},d(P){P&&(it(t),it(c),it(u),it(f),it(p),it(y),it(_),it(v)),R&&R.d(),C&&C.d(),$r(M,P),U&&U.d(P),x=!1,$e(S)}}}function Wv(r){let t,e;return t=new Ga({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[jv,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}const Yv=250,zv=1e3,qv=12,$n=4.5,qu=r=>r.join(","),Ku=r=>r.join(","),Zu=r=>r.join(",");function Kv(r,t,e){let i,n,s;const o=Wi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=w=>{if(g.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(w.offsetX,w.offsetY),O=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-L,2),D=i.points.reduce((k,V)=>O(V)<O(k)?V:k),$=n.filter(k=>k.visible).reduce((k,V)=>O(V.point)<O(k.point)?V:k),B=Math.pow(zv/c,2);O(D)<B||O($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=w=>{e(7,f=!0),w.preventDefault(),w.stopPropagation(),p=performance.now()},R=w=>A=>{if(!p||Xr||performance.now()-p>Yv)return;const L=g.includes(w);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,g=g.filter(O=>O!==w)):e(8,g=[...g,w]):L&&g.length>1?e(8,g=[w]):L?e(8,g=[]):e(8,g=[w]),m()},C=(w,A,L)=>{m();let O;const D=w.geometry;g.length>1?O=D.points.map(([B,N],k)=>g.includes(k)?[B+L[0],N+L[1]]:[B,N]):A==="SHAPE"?O=D.points.map(([B,N])=>[B+L[0],N+L[1]]):O=D.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+L[0],N+L[1]]:[B,N]);const $=Ye(O);return{...w,geometry:{points:O,bounds:$}}},I=w=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,w+1),n[w].point,...i.points.slice(w+1)],O=Ye(L);o("change",{...a,geometry:{points:L,bounds:O}}),await Lu();const D=[...document.querySelectorAll(".a9s-handle")][w+1];if(D!=null&&D.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});D.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-g.length<3)return;const w=i.points.filter((L,O)=>!g.includes(O)),A=Ye(w);o("change",{...a,geometry:{points:w,bounds:A}}),e(8,g=[])};Vr(()=>{if(Xr)return;const w=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",w),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",w)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(w){ae.call(this,r,w)}function P(w){ae.call(this,r,w)}function T(w){ae.call(this,r,w)}return r.$$set=w=>{"shape"in w&&e(0,a=w.shape),"computedStyle"in w&&e(1,l=w.computedStyle),"transform"in w&&e(2,h=w.transform),"viewportScale"in w&&e(3,c=w.viewportScale),"svgEl"in w&&e(4,u=w.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Xr?[]:i.points.map((w,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],O=(w[0]+L[0])/2,D=(w[1]+L[1])/2,B=Math.sqrt(Math.pow(L[0]-O,2)+Math.pow(L[1]-D,2))>qv/c;return{point:[O,D],visible:B}})),r.$$.dirty[0]&40&&e(9,s=Ua(i.bounds,$n/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,v,x,S,R,C,I,F,U,P,T]}class Zv extends Yt{constructor(t){super(),Wt(this,t,Kv,Wv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Ju=(r,t,e)=>{const[i,n]=r,[s,o]=t,a=Math.cos(e),l=Math.sin(e),h=i-s,c=n-o;return[s+h*a-c*l,o+h*l+c*a]},Jv=(r,t,e,i,n=0)=>{const s=[[r,t],[r+e,t],[r+e,t+i],[r,t+i]],o=[r+e/2,t+i/2];return s.map(a=>Ju(a,o,n))},Qu=(r,t)=>{const{x:e,y:i,w:n,h:s,rot:o=0}=r,a=[e+n/2,i+s/2];let l=[e+n/2,i-t];return Ju(l,a,o)},Qv=(r,t,e)=>{const i=Math.cos(e),n=Math.sin(e);return[r*i+t*n,-r*n+t*i]},t1=(r,t,e)=>{const i=r[0]-e[0],n=r[1]-e[1],s=Math.atan2(n,i),o=t[0]-e[0],a=t[1]-e[1];return Math.atan2(a,o)-s},e1=(r,t=10)=>{const e=t*Math.PI/180;return Math.round(r/e)*e};function r1(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R,C,I,M,F,U,P,T,w,A,L,O,D,$,B,N,k,V,j,st,H,at,X,gt,lt,ft,ct,Et,te,Gt,Me,Rr,zt,Li,we,Di,Ee,Ni,Te,Z,Fi,ms;return R=new di({props:{class:"a9s-rotation-handle",x:r[7][0],y:r[7][1],scale:r[3]}}),R.$on("pointerdown",function(){jt(r[16]("ROTATION"))&&r[16]("ROTATION").apply(this,arguments)}),zt=new di({props:{class:"a9s-corner-handle-topleft",x:r[6][0][0],y:r[6][0][1],scale:r[3]}}),zt.$on("pointerdown",function(){jt(r[16]("TOP_LEFT"))&&r[16]("TOP_LEFT").apply(this,arguments)}),we=new di({props:{class:"a9s-corner-handle-topright",x:r[6][1][0],y:r[6][1][1],scale:r[3]}}),we.$on("pointerdown",function(){jt(r[16]("TOP_RIGHT"))&&r[16]("TOP_RIGHT").apply(this,arguments)}),Ee=new di({props:{class:"a9s-corner-handle-bottomright",x:r[6][2][0],y:r[6][2][1],scale:r[3]}}),Ee.$on("pointerdown",function(){jt(r[16]("BOTTOM_RIGHT"))&&r[16]("BOTTOM_RIGHT").apply(this,arguments)}),Te=new di({props:{class:"a9s-corner-handle-bottomleft",x:r[6][3][0],y:r[6][3][1],scale:r[3]}}),Te.$on("pointerdown",function(){jt(r[16]("BOTTOM_LEFT"))&&r[16]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=J("defs"),e=J("mask"),i=J("rect"),l=J("polygon"),c=Pe(),u=J("g"),d=J("line"),_=J("line"),Lt(R.$$.fragment),C=Pe(),I=J("g"),M=J("polygon"),U=J("polygon"),T=Pe(),w=J("line"),$=Pe(),B=J("line"),st=Pe(),H=J("line"),ft=Pe(),ct=J("line"),Rr=Pe(),Lt(zt.$$.fragment),Li=Pe(),Lt(we.$$.fragment),Di=Pe(),Lt(Ee.$$.fragment),Ni=Pe(),Lt(Te.$$.fragment),E(i,"class","rect-mask-bg svelte-1bwhzbc"),E(i,"x",n=r[5].x),E(i,"y",s=r[5].y),E(i,"width",o=r[5].w),E(i,"height",a=r[5].h),E(l,"class","rect-mask-fg svelte-1bwhzbc"),E(l,"points",h=r[6].map(td).join(" ")),E(e,"id",r[9]),E(e,"class","a9s-rectangle-editor-mask svelte-1bwhzbc"),E(d,"class","a9s-rotation-handle-line-bg"),E(d,"x1",f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),E(d,"y1",p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),E(d,"x2",g=r[7][0]),E(d,"y2",y=r[7][1]),E(d,"pointer-events","none"),E(_,"class","a9s-rotation-handle-line-fg"),E(_,"x1",v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),E(_,"y1",m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),E(_,"x2",x=r[7][0]),E(_,"y2",S=r[7][1]),E(_,"pointer-events","none"),E(u,"class","a9s-rotation-handle-group"),E(M,"class","a9s-outer"),E(M,"mask",`url(#${r[9]})`),E(M,"points",F=r[6].map(ed).join(" ")),E(U,"class","a9s-inner a9s-shape-handle"),E(U,"style",r[1]),E(U,"points",P=r[6].map(rd).join(" ")),E(w,"class","a9s-edge-handle a9s-edge-handle-top"),E(w,"x1",A=r[6][0][0]),E(w,"y1",L=r[6][0][1]),E(w,"x2",O=r[6][1][0]),E(w,"y2",D=r[6][1][1]),E(B,"class","a9s-edge-handle a9s-edge-handle-right"),E(B,"x1",N=r[6][1][0]),E(B,"y1",k=r[6][1][1]),E(B,"x2",V=r[6][2][0]),E(B,"y2",j=r[6][2][1]),E(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),E(H,"x1",at=r[6][2][0]),E(H,"y1",X=r[6][2][1]),E(H,"x2",gt=r[6][3][0]),E(H,"y2",lt=r[6][3][1]),E(ct,"class","a9s-edge-handle a9s-edge-handle-left"),E(ct,"x1",Et=r[6][3][0]),E(ct,"y1",te=r[6][3][1]),E(ct,"x2",Gt=r[6][0][0]),E(ct,"y2",Me=r[6][0][1])},m(z,G){ot(z,t,G),Tt(t,e),Tt(e,i),Tt(e,l),ot(z,c,G),ot(z,u,G),Tt(u,d),Tt(u,_),Ot(R,u,null),ot(z,C,G),ot(z,I,G),Tt(I,M),Tt(I,U),ot(z,T,G),ot(z,w,G),ot(z,$,G),ot(z,B,G),ot(z,st,G),ot(z,H,G),ot(z,ft,G),ot(z,ct,G),ot(z,Rr,G),Ot(zt,z,G),ot(z,Li,G),Ot(we,z,G),ot(z,Di,G),Ot(Ee,z,G),ot(z,Ni,G),Ot(Te,z,G),Z=!0,Fi||(ms=[Pt(M,"pointerdown",function(){jt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Pt(U,"pointerdown",function(){jt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Pt(w,"pointerdown",function(){jt(r[16]("TOP"))&&r[16]("TOP").apply(this,arguments)}),Pt(B,"pointerdown",function(){jt(r[16]("RIGHT"))&&r[16]("RIGHT").apply(this,arguments)}),Pt(H,"pointerdown",function(){jt(r[16]("BOTTOM"))&&r[16]("BOTTOM").apply(this,arguments)}),Pt(ct,"pointerdown",function(){jt(r[16]("LEFT"))&&r[16]("LEFT").apply(this,arguments)})],Fi=!0)},p(z,G){r=z,(!Z||G&32&&n!==(n=r[5].x))&&E(i,"x",n),(!Z||G&32&&s!==(s=r[5].y))&&E(i,"y",s),(!Z||G&32&&o!==(o=r[5].w))&&E(i,"width",o),(!Z||G&32&&a!==(a=r[5].h))&&E(i,"height",a),(!Z||G&64&&h!==(h=r[6].map(td).join(" ")))&&E(l,"points",h),(!Z||G&64&&f!==(f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&E(d,"x1",f),(!Z||G&64&&p!==(p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&E(d,"y1",p),(!Z||G&128&&g!==(g=r[7][0]))&&E(d,"x2",g),(!Z||G&128&&y!==(y=r[7][1]))&&E(d,"y2",y),(!Z||G&64&&v!==(v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&E(_,"x1",v),(!Z||G&64&&m!==(m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&E(_,"y1",m),(!Z||G&128&&x!==(x=r[7][0]))&&E(_,"x2",x),(!Z||G&128&&S!==(S=r[7][1]))&&E(_,"y2",S);const Mr={};G&128&&(Mr.x=r[7][0]),G&128&&(Mr.y=r[7][1]),G&8&&(Mr.scale=r[3]),R.$set(Mr),(!Z||G&64&&F!==(F=r[6].map(ed).join(" ")))&&E(M,"points",F),(!Z||G&2)&&E(U,"style",r[1]),(!Z||G&64&&P!==(P=r[6].map(rd).join(" ")))&&E(U,"points",P),(!Z||G&64&&A!==(A=r[6][0][0]))&&E(w,"x1",A),(!Z||G&64&&L!==(L=r[6][0][1]))&&E(w,"y1",L),(!Z||G&64&&O!==(O=r[6][1][0]))&&E(w,"x2",O),(!Z||G&64&&D!==(D=r[6][1][1]))&&E(w,"y2",D),(!Z||G&64&&N!==(N=r[6][1][0]))&&E(B,"x1",N),(!Z||G&64&&k!==(k=r[6][1][1]))&&E(B,"y1",k),(!Z||G&64&&V!==(V=r[6][2][0]))&&E(B,"x2",V),(!Z||G&64&&j!==(j=r[6][2][1]))&&E(B,"y2",j),(!Z||G&64&&at!==(at=r[6][2][0]))&&E(H,"x1",at),(!Z||G&64&&X!==(X=r[6][2][1]))&&E(H,"y1",X),(!Z||G&64&&gt!==(gt=r[6][3][0]))&&E(H,"x2",gt),(!Z||G&64&&lt!==(lt=r[6][3][1]))&&E(H,"y2",lt),(!Z||G&64&&Et!==(Et=r[6][3][0]))&&E(ct,"x1",Et),(!Z||G&64&&te!==(te=r[6][3][1]))&&E(ct,"y1",te),(!Z||G&64&&Gt!==(Gt=r[6][0][0]))&&E(ct,"x2",Gt),(!Z||G&64&&Me!==(Me=r[6][0][1]))&&E(ct,"y2",Me);const Or={};G&64&&(Or.x=r[6][0][0]),G&64&&(Or.y=r[6][0][1]),G&8&&(Or.scale=r[3]),zt.$set(Or);const Br={};G&64&&(Br.x=r[6][1][0]),G&64&&(Br.y=r[6][1][1]),G&8&&(Br.scale=r[3]),we.$set(Br);const Lr={};G&64&&(Lr.x=r[6][2][0]),G&64&&(Lr.y=r[6][2][1]),G&8&&(Lr.scale=r[3]),Ee.$set(Lr);const Dr={};G&64&&(Dr.x=r[6][3][0]),G&64&&(Dr.y=r[6][3][1]),G&8&&(Dr.scale=r[3]),Te.$set(Dr)},i(z){Z||(q(R.$$.fragment,z),q(zt.$$.fragment,z),q(we.$$.fragment,z),q(Ee.$$.fragment,z),q(Te.$$.fragment,z),Z=!0)},o(z){nt(R.$$.fragment,z),nt(zt.$$.fragment,z),nt(we.$$.fragment,z),nt(Ee.$$.fragment,z),nt(Te.$$.fragment,z),Z=!1},d(z){z&&(it(t),it(c),it(u),it(C),it(I),it(T),it(w),it($),it(B),it(st),it(H),it(ft),it(ct),it(Rr),it(Li),it(Di),it(Ni)),Bt(R),Bt(zt,z),Bt(we,z),Bt(Ee,z),Bt(Te,z),Fi=!1,$e(ms)}}}function i1(r){let t,e;return t=new Ga({props:{shape:r[0],transform:r[2],editor:r[8],svgEl:r[4],$$slots:{default:[r1,({grab:i})=>({16:i}),({grab:i})=>i?65536:0]},$$scope:{ctx:r}}}),t.$on("grab",r[12]),t.$on("change",r[13]),t.$on("release",r[14]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&196842&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}const td=r=>`${r[0]},${r[1]}`,ed=r=>`${r[0]},${r[1]}`,rd=r=>`${r[0]},${r[1]}`;function n1(r,t,e){let i,n,s,o,a,{shape:l}=t,{computedStyle:h}=t,{transform:c}=t,{viewportScale:u=1}=t,{svgEl:d}=t,f=!1;const p=(m,x,S)=>{let{x:R,y:C,w:I,h:M,rot:F=0}=m.geometry;const[U,P]=S;if(x==="ROTATION"){const w=Qu(m.geometry,i),A=w[0]+U,L=w[1]+P,O=[R+I/2,C+M/2];F+=t1([w[0],w[1]],[A,L],O),f&&(F=e1(F));const D=2*Math.PI;F=(F%D+D)%D}else if(x==="SHAPE")R+=U,C+=P;else{let w=0,A=0,L=I,O=M;const[D,$]=F!==0?Qv(U,P,F):[U,P];switch(x){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":A+=$;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":O+=$;break}switch(x){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":w+=D;break;case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":L+=D;break}const B=(w+L)/2,N=(A+O)/2;I=Math.abs(L-w),M=Math.abs(O-A);const k=[R+m.geometry.w/2,C+m.geometry.h/2],V=[B-m.geometry.w/2,N-m.geometry.h/2],j=Math.cos(F),st=Math.sin(F),H=k[0]+V[0]*j-V[1]*st,at=k[1]+V[0]*st+V[1]*j;R=H-I/2,C=at-M/2}const T=Ye(s);return{...m,geometry:{x:R,y:C,w:I,h:M,rot:F,bounds:T}}};Vr(()=>{const m=S=>{S.key==="Shift"&&(f=!0)},x=S=>{S.key==="Shift"&&(f=!1)};return window.addEventListener("keydown",m),window.addEventListener("keyup",x),()=>{window.removeEventListener("keydown",m),window.removeEventListener("keyup",x)}});const g=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function y(m){ae.call(this,r,m)}function _(m){ae.call(this,r,m)}function v(m){ae.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,l=m.shape),"computedStyle"in m&&e(1,h=m.computedStyle),"transform"in m&&e(2,c=m.transform),"viewportScale"in m&&e(3,u=m.viewportScale),"svgEl"in m&&e(4,d=m.svgEl)},r.$$.update=()=>{r.$$.dirty&8&&e(11,i=20/u),r.$$.dirty&1&&e(10,n=l.geometry),r.$$.dirty&1024&&e(6,s=Jv(n.x,n.y,n.w,n.h,n.rot)),r.$$.dirty&3072&&e(7,o=Qu(n,i)),r.$$.dirty&1032&&e(5,a=Ua(n.bounds,5/u))},[l,h,c,u,d,a,s,o,p,g,n,i,y,_,v]}class s1 extends Yt{constructor(t){super(),Wt(this,t,n1,i1,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var id=Object.prototype.hasOwnProperty;function Xa(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--&&Xa(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(id.call(r,e)&&++i&&!id.call(t,e)||!(e in t)||!Xa(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const o1=12,a1=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,y=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>o1/t;return{point:[f,p],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ja(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function nd(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function sd(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function od(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Wa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ya(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function ad(r){let t,e,i,n;return{c(){t=J("circle"),E(t,"cx",e=r[29][0]),E(t,"cy",i=r[29][1]),E(t,"r",n=Hn/r[3]),E(t,"class","svelte-1vxo6dc")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&E(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&E(t,"cy",i),o[0]&8&&n!==(n=Hn/s[3])&&E(t,"r",n)},d(s){s&&it(t)}}}function ld(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=J("mask"),e=J("rect"),a=J("circle"),E(e,"x",i=r[9].x),E(e,"y",n=r[9].y),E(e,"width",s=r[9].w),E(e,"height",o=r[9].h),E(e,"class","svelte-1vxo6dc"),E(a,"cx",l=r[29][0]),E(a,"cy",h=r[29][1]),E(a,"r",c=Hn/r[3]),E(a,"class","svelte-1vxo6dc"),E(t,"id",`${r[18]}-${r[32]}-inner`),E(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){ot(u,t,d),Tt(t,e),Tt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&E(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&E(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&E(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&E(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&E(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&E(a,"cy",h),d[0]&8&&c!==(c=Hn/u[3])&&E(a,"r",c)},d(u){u&&it(t)}}}function hd(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new di({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){jt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){Lt(t.$$.fragment)},m(n,s){Ot(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(q(t.$$.fragment,n),e=!0)},o(n){nt(t.$$.fragment,n),e=!1},d(n){Bt(t,n)}}}function cd(r){let t,e,i=Ae(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=hd(od(r,i,o));const s=o=>nt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Be()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Ae(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=od(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=hd(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)nt(n[a]);e=!1},d(o){o&&it(t),$r(n,o)}}}function ud(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v=r[6]!==void 0&&!r[7]&&ad(Ya(r)),m=r[6]!==void 0&&!r[7]&&ld(Wa(r)),x=Ae(r[30].rings),S=[];for(let C=0;C<x.length;C+=1)S[C]=cd(sd(r,x,C));const R=C=>nt(S[C],1,1,()=>{S[C]=null});return{c(){t=J("g"),e=J("defs"),i=J("mask"),n=J("rect"),h=J("path"),v&&v.c(),m&&m.c(),u=J("path"),f=J("path");for(let C=0;C<S.length;C+=1)S[C].c();E(n,"x",s=r[9].x),E(n,"y",o=r[9].y),E(n,"width",a=r[9].w),E(n,"height",l=r[9].h),E(n,"class","svelte-1vxo6dc"),E(h,"d",c=Zi(r[30])),E(h,"class","svelte-1vxo6dc"),E(i,"id",`${r[18]}-${r[32]}-outer`),E(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),E(u,"class","a9s-outer"),E(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),E(u,"fill-rule","evenodd"),E(u,"d",d=Zi(r[30])),E(f,"class","a9s-inner"),E(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),E(f,"style",r[1]),E(f,"fill-rule","evenodd"),E(f,"d",p=Zi(r[30]))},m(C,I){ot(C,t,I),Tt(t,e),Tt(e,i),Tt(i,n),Tt(i,h),v&&v.m(i,null),m&&m.m(e,null),Tt(t,u),Tt(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);g=!0,y||(_=[Pt(u,"pointerup",r[13]),Pt(u,"pointerdown",function(){jt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Pt(f,"pointerup",r[13]),Pt(f,"pointerdown",function(){jt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!g||I[0]&512&&s!==(s=r[9].x))&&E(n,"x",s),(!g||I[0]&512&&o!==(o=r[9].y))&&E(n,"y",o),(!g||I[0]&512&&a!==(a=r[9].w))&&E(n,"width",a),(!g||I[0]&512&&l!==(l=r[9].h))&&E(n,"height",l),(!g||I[0]&32&&c!==(c=Zi(r[30])))&&E(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Ya(r),I):(v=ad(Ya(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?m?m.p(Wa(r),I):(m=ld(Wa(r)),m.c(),m.m(e,null)):m&&(m.d(1),m=null),(!g||I[0]&32&&d!==(d=Zi(r[30])))&&E(u,"d",d),(!g||I[0]&2)&&E(f,"style",r[1]),(!g||I[0]&32&&p!==(p=Zi(r[30])))&&E(f,"d",p),I[0]&268491048){x=Ae(r[30].rings);let M;for(M=0;M<x.length;M+=1){const F=sd(r,x,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=cd(F),S[M].c(),q(S[M],1),S[M].m(t,null))}for(le(),M=x.length;M<S.length;M+=1)R(M);he()}},i(C){if(!g){for(let I=0;I<x.length;I+=1)q(S[I]);g=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)nt(S[I]);g=!1},d(C){C&&it(t),v&&v.d(),m&&m.d(),$r(S,C),y=!1,$e(_)}}}function dd(r){let t,e;return t=new Vu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){jt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function l1(r){let t,e,i,n=Ae(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=ud(nd(r,n,l));const o=l=>nt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&dd(ja(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Pe(),a&&a.c(),e=Be()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);ot(l,t,h),a&&a.m(l,h),ot(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Ae(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=nd(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=ud(u),s[c].c(),q(s[c],1),s[c].m(t.parentNode,t))}for(le(),c=n.length;c<s.length;c+=1)o(c);he()}l[6]!==void 0&&!l[7]?a?(a.p(ja(l),h),h[0]&192&&q(a,1)):(a=dd(ja(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(le(),nt(a,1,1,()=>{a=null}),he())},i(l){if(!i){for(let h=0;h<n.length;h+=1)q(s[h]);q(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)nt(s[h]);nt(a),i=!1},d(l){l&&(it(t),it(e)),$r(s,l),a&&a.d(l)}}}function h1(r){let t,e;return t=new Ga({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[l1,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}const c1=250,u1=1e3,Hn=4.5;function d1(r,t,e){let i,n,s;const o=Wi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(g.length>0||!n.some(V=>V.visible)){e(6,d=void 0);return}const[L,O]=h.elementToImage(A.offsetX,A.offsetY),D=V=>Math.pow(V[0]-L,2)+Math.pow(V[1]-O,2),$=xv(i).reduce((V,j)=>D(j)<D(V)?j:V),B=n.filter(V=>V.visible).reduce((V,j)=>D(j.point)<D(V.point)?j:V),N=Math.pow(u1/c,2);D($)<N||D(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,L,O)=>D=>{if(!p||Xr||performance.now()-p>c1)return;const $=N=>N.polygon===A&&N.ring===L&&N.point===O,B=g.some($);D.metaKey||D.ctrlKey||D.shiftKey?B?e(8,g=g.filter(N=>!$(N))):e(8,g=[...g,{polygon:A,ring:L,point:O}]):B&&g.length>1?e(8,g=[{polygon:A,ring:L,point:O}]):B?e(8,g=[]):e(8,g=[{polygon:A,ring:L,point:O}]),m()},C=(A,L,O)=>{m();const D=A.geometry.polygons;let $;if(L==="SHAPE")$=D.map(B=>{const N=B.rings.map((V,j)=>({points:V.points.map((H,at)=>[H[0]+O[0],H[1]+O[1]])})),k=Ye(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,V]=L.split("-").map(j=>parseInt(j));$=D.map((j,st)=>{if(st===N){const H=j.rings.map((X,gt)=>gt===k?{points:X.points.map((ft,ct)=>ct===V?[ft[0]+O[0],ft[1]+O[1]]:ft)}:X),at=Ye(H[0].points);return{rings:H,bounds:at}}else return j})}return{...A,geometry:{polygons:$,bounds:ks($)}}},I=A=>async L=>{L.stopPropagation();const O=n[A],D=i.polygons.map((B,N)=>{if(N===O.elementIdx){const k=B.rings.map((j,st)=>st===O.ringIdx?{points:[...j.points.slice(0,O.pointIdx+1),O.point,...j.points.slice(O.pointIdx+1)]}:j),V=Ye(k[0].points);return{rings:k,bounds:V}}else return B});o("change",{...a,geometry:{polygons:D,bounds:ks(D)}}),await Lu();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((O,D)=>{if(g.some(B=>B.polygon===D)){const B=O.rings.map((k,V)=>{const j=g.filter(st=>st.polygon===D&&st.ring===V);return j.length&&k.points.length-j.length>=3?{points:k.points.filter((H,at)=>!j.some(X=>X.point===at))}:k}),N=Ye(B[0].points);return{rings:B,bounds:N}}else return O});!Xa(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:ks(A)}}),e(8,g=[]))};Vr(()=>{if(Xr)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,O,{polygon:D,ring:$,point:B})=>D===A&&$===L&&B===O;function P(A){ae.call(this,r,A)}function T(A){ae.call(this,r,A)}function w(A){ae.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Xr?[]:a1(i,c)),r.$$.dirty[0]&40&&e(9,s=Ua(i.bounds,Hn/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,x,S,R,C,I,F,U,P,T,w]}class f1 extends Yt{constructor(t){super(),Wt(this,t,d1,h1,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}nr.RECTANGLE,nr.POLYGON,nr.MULTIPOLYGON;function p1(r,t,e){let i;const n=Wi();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return Vr(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=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=Bv(s,a,{selected:!0,hovered:!0})),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.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})},[s,o,a,l,h,c,u,i]}class m1 extends Yt{constructor(t){super(),Wt(this,t,p1,null,Ut,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1;var fi=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(fi||{}),fd=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(fd||{}),za=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(za||{}),vt=(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))(vt||{}),sr=(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))(sr||{}),W=(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))(W||{}),Ji=(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))(Ji||{}),mt=(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))(mt||{}),Q=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Q||{}),br=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(br||{}),jr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(jr||{}),or=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(or||{}),Le=(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))(Le||{}),ar=(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))(ar||{}),qa=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(qa||{}),He=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(He||{}),ie=(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))(ie||{}),re=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(re||{}),lr=(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))(lr||{});const tt={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 Ka=/iPhone/i,pd=/iPod/i,md=/iPad/i,gd=/\biOS-universal(?:.+)Mac\b/i,Za=/\bAndroid(?:.+)Mobile\b/i,yd=/Android/i,Qi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Us=/Silk/i,xr=/Windows Phone/i,_d=/\bWindows(?:.+)ARM\b/i,vd=/BlackBerry/i,bd=/BB10/i,xd=/Opera Mini/i,wd=/\b(CriOS|Chrome)(?:.+)Mobile/i,Ed=/Mobile(?:.+)Firefox\b/i,Td=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function g1(r){return function(t){return t.test(r)}}function Ad(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 n=g1(e),s={apple:{phone:n(Ka)&&!n(xr),ipod:n(pd),tablet:!n(Ka)&&(n(md)||Td(t))&&!n(xr),universal:n(gd),device:(n(Ka)||n(pd)||n(md)||n(gd)||Td(t))&&!n(xr)},amazon:{phone:n(Qi),tablet:!n(Qi)&&n(Us),device:n(Qi)||n(Us)},android:{phone:!n(xr)&&n(Qi)||!n(xr)&&n(Za),tablet:!n(xr)&&!n(Qi)&&!n(Za)&&(n(Us)||n(yd)),device:!n(xr)&&(n(Qi)||n(Us)||n(Za)||n(yd))||n(/\bokhttp\b/i)},windows:{phone:n(xr),tablet:n(_d),device:n(xr)||n(_d)},other:{blackberry:n(vd),blackberry10:n(bd),opera:n(xd),firefox:n(Ed),chrome:n(wd),device:n(vd)||n(bd)||n(xd)||n(Ed)||n(wd)},any:!1,phone:!1,tablet:!1};return s.any=s.apple.device||s.android.device||s.windows.device||s.other.device,s.phone=s.apple.phone||s.android.phone||s.windows.phone,s.tablet=s.apple.tablet||s.android.tablet||s.windows.tablet,s}const y1=Ad.default??Ad,wr=y1(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Sd={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function n(l,h,c){this.fn=l,this.context=h,this.once=c||!1}function s(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new n(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 g=e?e+h:h;if(!this._events[g])return!1;var y=this._events[g],_=arguments.length,v,m;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,c),!0;case 3:return y.fn.call(y.context,c,u),!0;case 4:return y.fn.call(y.context,c,u,d),!0;case 5:return y.fn.call(y.context,c,u,d,f),!0;case 6:return y.fn.call(y.context,c,u,d,f,p),!0}for(m=1,v=new Array(_-1);m<_;m++)v[m-1]=arguments[m];y.fn.apply(y.context,v)}else{var x=y.length,S;for(m=0;m<x;m++)switch(y[m].once&&this.removeListener(h,y[m].fn,void 0,!0),_){case 1:y[m].fn.call(y[m].context);break;case 2:y[m].fn.call(y[m].context,c);break;case 3:y[m].fn.call(y[m].context,c,u);break;case 4:y[m].fn.call(y[m].context,c,u,d);break;default:if(!v)for(S=1,v=new Array(_-1);S<_;S++)v[S-1]=arguments[S];y[m].fn.apply(y[m].context,v)}}return!0},a.prototype.on=function(h,c,u){return s(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return s(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 g=0,y=[],_=p.length;g<_;g++)(p[g].fn!==c||d&&!p[g].once||u&&p[g].context!==u)&&y.push(p[g]);y.length?this._events[f]=y.length===1?y[0]:y: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})(Sd);var _1=Sd.exports;const Vn=ka(_1);var Ja={exports:{}};Ja.exports=Gs,Ja.exports.default=Gs;function Gs(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=Cd(r,0,n,e,!0),o=[];if(!s||s.next===s.prev)return o;var a,l,h,c,u,d,f;if(i&&(s=E1(r,t,s,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var p=e;p<n;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 Xn(s,o,e,a,l,f,0),o}function Cd(r,t,e,i,n){var s,o;if(n===el(r,t,e,i)>0)for(s=t;s<e;s+=i)o=Rd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=Rd(s,r[s],r[s+1],o);return o&&$s(o,o.next)&&(Wn(o),o=o.next),o}function pi(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&($s(e,e.next)||$t(e.prev,e,e.next)===0)){if(Wn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Xn(r,t,e,i,n,s,o){if(r){!o&&s&&I1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?b1(r,i,n,s):v1(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Wn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=x1(pi(r),t,e),Xn(r,t,e,i,n,s,2)):o===2&&w1(r,t,e,i,n,s):Xn(pi(r),t,e,i,n,s,1);break}}}}function v1(r){var t=r.prev,e=r,i=r.next;if($t(t,e,i)>=0)return!1;for(var n=t.x,s=e.x,o=i.x,a=t.y,l=e.y,h=i.y,c=n<s?n<o?n:o:s<o?s:o,u=a<l?a<h?a:h:l<h?l:h,d=n>s?n>o?n:o:s>o?s: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&&tn(n,a,s,l,o,h,p.x,p.y)&&$t(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function b1(r,t,e,i){var n=r.prev,s=r,o=r.next;if($t(n,s,o)>=0)return!1;for(var a=n.x,l=s.x,h=o.x,c=n.y,u=s.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,g=a>l?a>h?a:h:l>h?l:h,y=c>u?c>d?c:d:u>d?u:d,_=Qa(f,p,t,e,i),v=Qa(g,y,t,e,i),m=r.prevZ,x=r.nextZ;m&&m.z>=_&&x&&x.z<=v;){if(m.x>=f&&m.x<=g&&m.y>=p&&m.y<=y&&m!==n&&m!==o&&tn(a,c,l,u,h,d,m.x,m.y)&&$t(m.prev,m,m.next)>=0||(m=m.prevZ,x.x>=f&&x.x<=g&&x.y>=p&&x.y<=y&&x!==n&&x!==o&&tn(a,c,l,u,h,d,x.x,x.y)&&$t(x.prev,x,x.next)>=0))return!1;x=x.nextZ}for(;m&&m.z>=_;){if(m.x>=f&&m.x<=g&&m.y>=p&&m.y<=y&&m!==n&&m!==o&&tn(a,c,l,u,h,d,m.x,m.y)&&$t(m.prev,m,m.next)>=0)return!1;m=m.prevZ}for(;x&&x.z<=v;){if(x.x>=f&&x.x<=g&&x.y>=p&&x.y<=y&&x!==n&&x!==o&&tn(a,c,l,u,h,d,x.x,x.y)&&$t(x.prev,x,x.next)>=0)return!1;x=x.nextZ}return!0}function x1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!$s(n,s)&&Id(n,i,i.next,s)&&jn(n,s)&&jn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Wn(i),Wn(i.next),i=r=s),i=i.next}while(i!==r);return pi(i)}function w1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&M1(o,a)){var l=Pd(o,a);o=pi(o,o.next),l=pi(l,l.next),Xn(o,t,e,i,n,s,0),Xn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function E1(r,t,e,i){var n=[],s,o,a,l,h;for(s=0,o=t.length;s<o;s++)a=t[s]*i,l=s<o-1?t[s+1]*i:r.length,h=Cd(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(R1(h));for(n.sort(T1),s=0;s<n.length;s++)e=A1(n[s],e);return e}function T1(r,t){return r.x-t.x}function A1(r,t){var e=S1(r,t);if(!e)return t;var i=Pd(e,r);return pi(i,i.next),pi(e,e.next)}function S1(r,t){var e=t,i=r.x,n=r.y,s=-1/0,o;do{if(n<=e.y&&n>=e.next.y&&e.next.y!==e.y){var a=e.x+(n-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>s&&(s=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&&tn(n<c?i:s,n,h,c,n<c?s:i,n,e.x,e.y)&&(d=Math.abs(n-e.y)/(i-e.x),jn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&C1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function C1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function I1(r,t,e,i){var n=r;do n.z===0&&(n.z=Qa(n.x,n.y,t,e,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==r);n.prevZ.nextZ=null,n.prevZ=null,P1(n)}function P1(r){var t,e,i,n,s,o,a,l,h=1;do{for(e=r,r=null,s=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)?(n=e,e=e.nextZ,a--):(n=i,i=i.nextZ,l--),s?s.nextZ=n:r=n,n.prevZ=s,s=n;e=i}s.nextZ=null,h*=2}while(o>1);return r}function Qa(r,t,e,i,n){return r=(r-e)*n|0,t=(t-i)*n|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 R1(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 tn(r,t,e,i,n,s,o,a){return(n-o)*(t-a)>=(r-o)*(s-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(s-a)>=(n-o)*(i-a)}function M1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!O1(r,t)&&(jn(r,t)&&jn(t,r)&&B1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||$s(r,t)&&$t(r.prev,r,r.next)>0&&$t(t.prev,t,t.next)>0)}function $t(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function $s(r,t){return r.x===t.x&&r.y===t.y}function Id(r,t,e,i){var n=Vs($t(r,t,e)),s=Vs($t(r,t,i)),o=Vs($t(e,i,r)),a=Vs($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Hs(r,e,t)||s===0&&Hs(r,i,t)||o===0&&Hs(e,r,i)||a===0&&Hs(e,t,i))}function Hs(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 Vs(r){return r>0?1:r<0?-1:0}function O1(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&&Id(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function jn(r,t){return $t(r.prev,r,r.next)<0?$t(r,t,r.next)>=0&&$t(r,r.prev,t)>=0:$t(r,t,r.prev)<0||$t(r,r.next,t)<0}function B1(r,t){var e=r,i=!1,n=(r.x+t.x)/2,s=(r.y+t.y)/2;do e.y>s!=e.next.y>s&&e.next.y!==e.y&&n<(e.next.x-e.x)*(s-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function Pd(r,t){var e=new tl(r.i,r.x,r.y),i=new tl(t.i,t.x,t.y),n=r.next,s=t.prev;return r.next=t,t.prev=r,e.next=n,n.prev=e,i.next=e,e.prev=i,s.next=i,i.prev=s,i}function Rd(r,t,e,i){var n=new tl(r,t,e);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function Wn(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 tl(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}Gs.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(el(r,0,s,e));if(n)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(el(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 el(r,t,e,i){for(var n=0,s=t,o=e-i;s<e;s+=i)n+=(r[o]-r[s])*(r[s+1]+r[o+1]),o=s;return n}Gs.flatten=function(r){for(var t=r[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,n=0;n<r.length;n++){for(var s=0;s<r[n].length;s++)for(var o=0;o<t;o++)e.vertices.push(r[n][s][o]);n>0&&(i+=r[n-1].length,e.holes.push(i))}return e};var L1=Ja.exports;const D1=ka(L1);var Xs={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Xs.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof Gn=="object"&&Gn;(s.global===s||s.window===s||s.self===s)&&(e=s);var o,a=2147483647,l=36,h=1,c=26,u=38,d=700,f=72,p=128,g="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,m={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},x=l-h,S=Math.floor,R=String.fromCharCode,C;function I(B){throw new RangeError(m[B])}function M(B,N){for(var k=B.length,V=[];k--;)V[k]=N(B[k]);return V}function F(B,N){var k=B.split("@"),V="";k.length>1&&(V=k[0]+"@",B=k[1]),B=B.replace(v,".");var j=B.split("."),st=M(j,N).join(".");return V+st}function U(B){for(var N=[],k=0,V=B.length,j,st;k<V;)j=B.charCodeAt(k++),j>=55296&&j<=56319&&k<V?(st=B.charCodeAt(k++),(st&64512)==56320?N.push(((j&1023)<<10)+(st&1023)+65536):(N.push(j),k--)):N.push(j);return N}function P(B){return M(B,function(N){var k="";return N>65535&&(N-=65536,k+=R(N>>>10&1023|55296),N=56320|N&1023),k+=R(N),k}).join("")}function T(B){return B-48<10?B-22:B-65<26?B-65:B-97<26?B-97:l}function w(B,N){return B+22+75*(B<26)-((N!=0)<<5)}function A(B,N,k){var V=0;for(B=k?S(B/d):B>>1,B+=S(B/N);B>x*c>>1;V+=l)B=S(B/x);return S(V+(x+1)*B/(B+u))}function L(B){var N=[],k=B.length,V,j=0,st=p,H=f,at,X,gt,lt,ft,ct,Et,te,Gt;for(at=B.lastIndexOf(g),at<0&&(at=0),X=0;X<at;++X)B.charCodeAt(X)>=128&&I("not-basic"),N.push(B.charCodeAt(X));for(gt=at>0?at+1:0;gt<k;){for(lt=j,ft=1,ct=l;gt>=k&&I("invalid-input"),Et=T(B.charCodeAt(gt++)),(Et>=l||Et>S((a-j)/ft))&&I("overflow"),j+=Et*ft,te=ct<=H?h:ct>=H+c?c:ct-H,!(Et<te);ct+=l)Gt=l-te,ft>S(a/Gt)&&I("overflow"),ft*=Gt;V=N.length+1,H=A(j-lt,V,lt==0),S(j/V)>a-st&&I("overflow"),st+=S(j/V),j%=V,N.splice(j++,0,st)}return P(N)}function O(B){var N,k,V,j,st,H,at,X,gt,lt,ft,ct=[],Et,te,Gt,Me;for(B=U(B),Et=B.length,N=p,k=0,st=f,H=0;H<Et;++H)ft=B[H],ft<128&&ct.push(R(ft));for(V=j=ct.length,j&&ct.push(g);V<Et;){for(at=a,H=0;H<Et;++H)ft=B[H],ft>=N&&ft<at&&(at=ft);for(te=V+1,at-N>S((a-k)/te)&&I("overflow"),k+=(at-N)*te,N=at,H=0;H<Et;++H)if(ft=B[H],ft<N&&++k>a&&I("overflow"),ft==N){for(X=k,gt=l;lt=gt<=st?h:gt>=st+c?c:gt-st,!(X<lt);gt+=l)Me=X-lt,Gt=l-lt,ct.push(R(w(lt+Me%Gt,0))),X=S(Me/Gt);ct.push(R(w(X,0))),st=A(k,te,V==j),k=0,++V}++k,++N}return ct.join("")}function D(B){return F(B,function(N){return y.test(N)?L(N.slice(4).toLowerCase()):N})}function $(B){return F(B,function(N){return _.test(N)?"xn--"+O(N):N})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:L,encode:O,toASCII:$,toUnicode:D},i&&n)if(r.exports==i)n.exports=o;else for(C in o)o.hasOwnProperty(C)&&(i[C]=o[C]);else e.punycode=o})(Gn)}(Xs,Xs.exports);var N1=Xs.exports,en=TypeError;const F1=fv(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var rl=typeof Map=="function"&&Map.prototype,il=Object.getOwnPropertyDescriptor&&rl?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,js=rl&&il&&typeof il.get=="function"?il.get:null,Md=rl&&Map.prototype.forEach,nl=typeof Set=="function"&&Set.prototype,sl=Object.getOwnPropertyDescriptor&&nl?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Ws=nl&&sl&&typeof sl.get=="function"?sl.get:null,Od=nl&&Set.prototype.forEach,k1=typeof WeakMap=="function"&&WeakMap.prototype,Yn=k1?WeakMap.prototype.has:null,U1=typeof WeakSet=="function"&&WeakSet.prototype,zn=U1?WeakSet.prototype.has:null,G1=typeof WeakRef=="function"&&WeakRef.prototype,Bd=G1?WeakRef.prototype.deref:null,$1=Boolean.prototype.valueOf,H1=Object.prototype.toString,V1=Function.prototype.toString,X1=String.prototype.match,ol=String.prototype.slice,Wr=String.prototype.replace,j1=String.prototype.toUpperCase,Ld=String.prototype.toLowerCase,Dd=RegExp.prototype.test,Nd=Array.prototype.concat,hr=Array.prototype.join,W1=Array.prototype.slice,Fd=Math.floor,al=typeof BigInt=="function"?BigInt.prototype.valueOf:null,ll=Object.getOwnPropertySymbols,hl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,rn=typeof Symbol=="function"&&typeof Symbol.iterator=="object",qn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===rn||!0)?Symbol.toStringTag:null,kd=Object.prototype.propertyIsEnumerable,Ud=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Gd(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Dd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Fd(-r):Fd(r);if(i!==r){var n=String(i),s=ol.call(t,n.length+1);return Wr.call(n,e,"$&_")+"."+Wr.call(Wr.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Wr.call(t,e,"$&_")}var cl=F1,$d=cl.custom,Hd=Wd($d)?$d:null,Vd={__proto__:null,double:'"',single:"'"},Y1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Ys=function r(t,e,i,n){var s=e||{};if(Er(s,"quoteStyle")&&!Er(Vd,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Er(s,"maxStringLength")&&(typeof s.maxStringLength=="number"?s.maxStringLength<0&&s.maxStringLength!==1/0:s.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=Er(s,"customInspect")?s.customInspect:!0;if(typeof o!="boolean"&&o!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Er(s,"indent")&&s.indent!==null&&s.indent!==" "&&!(parseInt(s.indent,10)===s.indent&&s.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Er(s,"numericSeparator")&&typeof s.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=s.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 zd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Gd(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Gd(t,h):h}var c=typeof s.depth>"u"?5:s.depth;if(typeof i>"u"&&(i=0),i>=c&&c>0&&typeof t=="object")return ul(t)?"[Array]":"[Object]";var u=ub(s,i);if(typeof n>"u")n=[];else if(Yd(n,t)>=0)return"[Circular]";function d(T,w,A){if(w&&(n=W1.call(n),n.push(w)),A){var L={depth:s.depth};return Er(s,"quoteStyle")&&(L.quoteStyle=s.quoteStyle),r(T,L,i+1,n)}return r(T,s,i+1,n)}if(typeof t=="function"&&!jd(t)){var f=rb(t),p=zs(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+hr.call(p,", ")+" }":"")}if(Wd(t)){var g=rn?Wr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):hl.call(t);return typeof t=="object"&&!rn?Kn(g):g}if(lb(t)){for(var y="<"+Ld.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Xd(z1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+Ld.call(String(t.nodeName))+">",y}if(ul(t)){if(t.length===0)return"[]";var m=zs(t,d);return u&&!cb(m)?"["+fl(m,u)+"]":"[ "+hr.call(m,", ")+" ]"}if(K1(t)){var x=zs(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!kd.call(t,"cause")?"{ ["+String(t)+"] "+hr.call(Nd.call("[cause]: "+d(t.cause),x),", ")+" }":x.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+hr.call(x,", ")+" }"}if(typeof t=="object"&&o){if(Hd&&typeof t[Hd]=="function"&&cl)return cl(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(ib(t)){var S=[];return Md&&Md.call(t,function(T,w){S.push(d(w,t,!0)+" => "+d(T,t))}),qd("Map",js.call(t),S,u)}if(ob(t)){var R=[];return Od&&Od.call(t,function(T){R.push(d(T,t))}),qd("Set",Ws.call(t),R,u)}if(nb(t))return dl("WeakMap");if(ab(t))return dl("WeakSet");if(sb(t))return dl("WeakRef");if(J1(t))return Kn(d(Number(t)));if(tb(t))return Kn(d(al.call(t)));if(Q1(t))return Kn($1.call(t));if(Z1(t))return Kn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Gn<"u"&&t===Gn)return"{ [object globalThis] }";if(!q1(t)&&!jd(t)){var C=zs(t,d),I=Ud?Ud(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&qn&&Object(t)===t&&qn in t?ol.call(Yr(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+hr.call(Nd.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+fl(C,u)+"}":P+"{ "+hr.call(C,", ")+" }"}return String(t)};function Xd(r,t,e){var i=e.quoteStyle||t,n=Vd[i];return n+r+n}function z1(r){return Wr.call(String(r),/"/g,"&quot;")}function mi(r){return!qn||!(typeof r=="object"&&(qn in r||typeof r[qn]<"u"))}function ul(r){return Yr(r)==="[object Array]"&&mi(r)}function q1(r){return Yr(r)==="[object Date]"&&mi(r)}function jd(r){return Yr(r)==="[object RegExp]"&&mi(r)}function K1(r){return Yr(r)==="[object Error]"&&mi(r)}function Z1(r){return Yr(r)==="[object String]"&&mi(r)}function J1(r){return Yr(r)==="[object Number]"&&mi(r)}function Q1(r){return Yr(r)==="[object Boolean]"&&mi(r)}function Wd(r){if(rn)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!hl)return!1;try{return hl.call(r),!0}catch{}return!1}function tb(r){if(!r||typeof r!="object"||!al)return!1;try{return al.call(r),!0}catch{}return!1}var eb=Object.prototype.hasOwnProperty||function(r){return r in this};function Er(r,t){return eb.call(r,t)}function Yr(r){return H1.call(r)}function rb(r){if(r.name)return r.name;var t=X1.call(V1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Yd(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 ib(r){if(!js||!r||typeof r!="object")return!1;try{js.call(r);try{Ws.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function nb(r){if(!Yn||!r||typeof r!="object")return!1;try{Yn.call(r,Yn);try{zn.call(r,zn)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function sb(r){if(!Bd||!r||typeof r!="object")return!1;try{return Bd.call(r),!0}catch{}return!1}function ob(r){if(!Ws||!r||typeof r!="object")return!1;try{Ws.call(r);try{js.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function ab(r){if(!zn||!r||typeof r!="object")return!1;try{zn.call(r,zn);try{Yn.call(r,Yn)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function lb(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function zd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return zd(ol.call(r,0,t.maxStringLength),t)+i}var n=Y1[t.quoteStyle||"single"];n.lastIndex=0;var s=Wr.call(Wr.call(r,n,"\\$1"),/[\x00-\x1f]/g,hb);return Xd(s,"single",t)}function hb(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":"")+j1.call(t.toString(16))}function Kn(r){return"Object("+r+")"}function dl(r){return r+" { ? }"}function qd(r,t,e,i){var n=i?fl(e,i):hr.call(e,", ");return r+" ("+t+") {"+n+"}"}function cb(r){for(var t=0;t<r.length;t++)if(Yd(r[t],`
1
+ (function(qt,se){typeof exports=="object"&&typeof module<"u"?se(exports,require("openseadragon")):typeof define=="function"&&define.amd?define(["exports","openseadragon"],se):(qt=typeof globalThis<"u"?globalThis:qt||self,se(qt.AnnotoriousOSD={},qt.OpenSeadragon))})(this,function(qt,se){"use strict";var FC=Object.defineProperty;var kC=(qt,se,si)=>se in qt?FC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:si}):qt[se]=si;var Yh=(qt,se,si)=>kC(qt,typeof se!="symbol"?se+"":se,si);var si=Object.prototype.hasOwnProperty;function oi(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--&&oi(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(si.call(r,e)&&++i&&!si.call(t,e)||!(e in t)||!oi(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0});var ra=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(ra||{});const fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function gg(r,t=0){return(fe[r[t+0]]+fe[r[t+1]]+fe[r[t+2]]+fe[r[t+3]]+"-"+fe[r[t+4]]+fe[r[t+5]]+"-"+fe[r[t+6]]+fe[r[t+7]]+"-"+fe[r[t+8]]+fe[r[t+9]]+"-"+fe[r[t+10]]+fe[r[t+11]]+fe[r[t+12]]+fe[r[t+13]]+fe[r[t+14]]+fe[r[t+15]]).toLowerCase()}const yg=new Uint8Array(16);function _g(){return crypto.getRandomValues(yg)}function vg(r,t,e){return crypto.randomUUID?crypto.randomUUID():bg(r)}function bg(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??_g();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,gg(n)}const ia=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)}},xg=(r,t,e,i)=>({id:vg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),wg=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Eg=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Tg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!oi(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Ag=(r,t)=>!oi(r.target,t.target),Sg=(r,t)=>{const e=wg(r,t),i=Eg(r,t),n=Tg(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:Ag(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Nr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Nr||{});const Cg=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=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=>!s.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=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(g=>g.oldValue.id===f.id).newValue;return Sg(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let Ig=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;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(n=>t!==n)}}});const Pg=250,Rg=(r,t)=>{const e=Ig(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:g}=p,y=performance.now();if(y-o>Pg)i.splice(n+1),i.push(g),n=i.length-1;else{const _=i.length-1;i[_]=Cg(i[_],g)}o=y}s=!1};r.observe(a,{origin:Nr.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:g})=>g)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:g})=>g)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,g)=>e.on(p,g),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:g,deleted:y}=i[n+1];h(p),u(g),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:g,deleted:y}=i[n];l(p),c(g),d(y),e.emit("undo",i[n]),n-=1}}}},Mg=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},f=(_,v)=>{const m=l.get(_);if(m){const x=m.indexOf(v);x!==-1&&m.splice(x,1)}},p=(_,v,m)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=m?m instanceof PointerEvent?m:e.serialize(m):void 0;x(S,R)}else x(v,m)})},1)},g=()=>{const{selected:_}=s,v=(_||[]).map(({id:m})=>o.getAnnotation(m));v.forEach(m=>{const x=h.find(S=>S.id===m.id);(!x||!oi(x,m))&&p("updateAnnotation",m,x)}),h=h.map(m=>v.find(({id:S})=>S===m.id)||m)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const m=o.getAnnotation(v.id);m&&!oi(m,v)&&p("updateAnnotation",m,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),m=new Set(_.map(({id:x})=>x));h.filter(x=>!m.has(x.id)).forEach(x=>{const S=o.getAnnotation(x.id);S&&!oi(S,x)&&p("updateAnnotation",S,x)}),h=[...h.filter(x=>m.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(g,1e3));const{created:v,deleted:m}=_.changes;(v||[]).forEach(x=>p("createAnnotation",x)),(m||[]).forEach(x=>p("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:S})=>{const R=h.find(C=>C.id===x.id)||x;h=h.map(C=>C.id===x.id?S:C),p("updateAnnotation",S,R)})},{origin:Nr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),m=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);m.length>0&&(h=h.map(x=>m.find(R=>R.id===x.id)||x))}},{origin:Nr.REMOTE});const y=_=>v=>{const{updated:m}=v;_?(m||[]).forEach(x=>p("updateAnnotation",x.oldValue,x.newValue)):(m||[]).forEach(x=>p("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},Og=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),Bg=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:m}=e.parse(_);v?i.addAnnotation(v,Nr.REMOTE):console.error(m)}else i.addAnnotation(ia(_),Nr.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(m=>m.id))||[]).map(m=>i.getAnnotation(m)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(m=>m.json()).then(m=>(f(m,v),m)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const m=e.parseAll||Og(e),{parsed:x,failed:S}=m(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(x,v,Nr.REMOTE)}else i.bulkAddAnnotations(_.map(ia),v,Nr.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},g=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,m=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),m}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(ia(_)),v}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:g,undo:t.undo,updateAnnotation:y}};let Lg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",Dg=r=>crypto.getRandomValues(new Uint8Array(r)),Ng=(r,t,e)=>{let i=256-256%r.length;if(i===256){let s=r.length-1;return(o=t)=>{if(!o)return"";let a="";for(;;){let l=e(o),h=o;for(;h--;)if(a+=r[l[h]&s],a.length>=o)return a}}}let n=Math.ceil(1.6*256*t/i);return(s=t)=>{if(!s)return"";let o="";for(;;){let a=e(n),l=n;for(;l--;)if(a[l]<i&&(o+=r[a[l]%r.length],o.length>=s))return o}}},Fg=(r,t=21)=>Ng(r,t|0,Dg),kg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Lg[e[r]&63];return t};const Ug=()=>({isGuest:!0,id:Fg("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Gg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],$g=()=>{const r=[...Gg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};kg();var Hg=Object.defineProperty,Vg=(r,t,e)=>t in r?Hg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,ec=(r,t,e)=>Vg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function na(r,t){for(const e in t)r[e]=t[e];return r}function rc(r){return r()}function ic(){return Object.create(null)}function De(r){r.forEach(rc)}function kt(r){return typeof r=="function"}function Kt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Xg(r){return Object.keys(r).length===0}function nc(r,...t){if(r==null){for(const i of t)i(void 0);return Rt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function sa(r,t,e){r.$$.on_destroy.push(nc(t,e))}function jg(r,t,e,i){if(r){const n=sc(r,t,e,i);return r[0](n)}}function sc(r,t,e,i){return r[1]&&i?na(e.ctx.slice(),r[1](i(t))):e.ctx}function Wg(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function Yg(r,t,e,i,n,s){if(n){const o=sc(t,e,i,s);r.p(o,n)}}function zg(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 oc(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function ki(r){return r??""}function bt(r,t){r.appendChild(t)}function rt(r,t,e){r.insertBefore(t,e||null)}function et(r){r.parentNode&&r.parentNode.removeChild(r)}function ai(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function Y(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function ac(r){return document.createTextNode(r)}function Se(){return ac(" ")}function Ne(){return ac("")}function Ct(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function b(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function qg(r){return Array.from(r.childNodes)}function ir(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 Pn;function Rn(r){Pn=r}function lc(){if(!Pn)throw new Error("Function called outside component initialization");return Pn}function Fr(r){lc().$$.on_mount.push(r)}function kr(){const r=lc();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Kg(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function oe(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Ui=[],xs=[];let Gi=[];const hc=[],cc=Promise.resolve();let oa=!1;function uc(){oa||(oa=!0,cc.then(fc))}function dc(){return uc(),cc}function aa(r){Gi.push(r)}const la=new Set;let $i=0;function fc(){if($i!==0)return;const r=Pn;do{try{for(;$i<Ui.length;){const t=Ui[$i];$i++,Rn(t),Zg(t.$$)}}catch(t){throw Ui.length=0,$i=0,t}for(Rn(null),Ui.length=0,$i=0;xs.length;)xs.pop()();for(let t=0;t<Gi.length;t+=1){const e=Gi[t];la.has(e)||(la.add(e),e())}Gi.length=0}while(Ui.length);for(;hc.length;)hc.pop()();oa=!1,la.clear(),Rn(r)}function Zg(r){if(r.fragment!==null){r.update(),De(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(aa)}}function Jg(r){const t=[],e=[];Gi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Gi=t}const ws=new Set;let li;function Ce(){li={r:0,c:[],p:li}}function Ie(){li.r||De(li.c),li=li.p}function ht(r,t){r&&r.i&&(ws.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(ws.has(r))return;ws.add(r),li.c.push(()=>{ws.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Oe(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:n}=r.$$;i&&i.m(t,e),aa(()=>{const s=r.$$.on_mount.map(rc).filter(kt);r.$$.on_destroy?r.$$.on_destroy.push(...s):De(s),r.$$.on_mount=[]}),n.forEach(aa)}function Jt(r,t){const e=r.$$;e.fragment!==null&&(Jg(e.after_update),De(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Qg(r,t){r.$$.dirty[0]===-1&&(Ui.push(r),uc(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function pe(r,t,e,i,n,s,o=null,a=[-1]){const l=Pn;Rn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:ic(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:ic(),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&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&Qg(r,u)),d}):[],h.update(),c=!0,De(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=qg(t.target);h.fragment&&h.fragment.l(u),u.forEach(et)}else h.fragment&&h.fragment.c();t.intro&&ht(r.$$.fragment),Zt(r,t.target,t.anchor),fc()}Rn(l)}class me{constructor(){ec(this,"$$"),ec(this,"$$set")}$destroy(){Jt(this,1),this.$destroy=Rt}$on(t,e){if(!kt(e))return Rt;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!Xg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const ty="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(ty);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),ey={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,f,p=l+1;p<h;p++){var g=e(a[p],a[l],a[h]);g>d&&(f=p,d=g)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(ey);const ha={},Hi=(r,t)=>ha[r]=t,ca=r=>ha[r.type].area(r),ry=(r,t,e,i)=>ha[r.type].intersects(r,t,e,i),ge=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},Es=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Ts=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},iy=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},As=(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))},ny={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Hi(_t.ELLIPSE,ny);const sy={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=As([n,s],[o,a]);return l/h<=i}};Hi(_t.LINE,sy);const oy={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=Es(n.points),a=s.reduce((l,h)=>l+Es(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(Ts(s.points,t,e)){let a=!1;for(const l of o)if(Ts(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},ua=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return ge(t)},je=r=>r.rings.map(t=>iy(t.points)).join(" "),ay=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Hi(_t.MULTIPOLYGON,oy);const ly={area:r=>{const t=r.geometry.points;return Es(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Ts(i,t,e)}};Hi(_t.POLYGON,ly);const hy={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=da(t.points,t.closed);return Es(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=da(n.points,n.closed);return Ts(s,t,e)}else return cy(n,[t,e],i)}},da=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.type==="CURVE"||s.type=="CURVE")){const o=pc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...o.slice(1))}}return e},pc=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},cy=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.type==="CURVE"||s.type==="CURVE"){const o=pc(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let a=0;a<o.length-1;a++)if(mc(t,o[a],o[a+1])<=e)return!0}else if(mc(t,n.point,s.point)<=e)return!0}return!1},mc=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u},fa=r=>{if(!r.points||r.points.length===0)return"";const t=[],e=r.points[0];t.push(`M ${e.point[0]} ${e.point[1]}`);for(let i=1;i<r.points.length;i++){const n=r.points[i],s=r.points[i-1];if(n.type==="CURVE"||s.type==="CURVE"){const o=s.type==="CURVE"&&s.outHandle||s.point,a=n.type==="CURVE"&&n.inHandle||n.point,l=n.point;t.push(`C ${o[0]} ${o[1]} ${a[0]} ${a[1]} ${l[0]} ${l[1]}`)}else t.push(`L ${n.point[0]} ${n.point[1]}`)}if(r.closed){const i=r.points[r.points.length-1],n=r.points[0];if(i.type==="CURVE"||n.type==="CURVE"){const s=i.outHandle||i.point,o=n.inHandle||n.point,a=n.point;t.push(`C ${s[0]} ${s[1]} ${o[0]} ${o[1]} ${a[0]} ${a[1]}`)}t.push("Z")}return t.join(" ")};Hi(_t.POLYLINE,hy);const uy={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>{const i=r.geometry;if(i.rot){const n=i.x+i.w/2,s=i.y+i.h/2,o=t-n,a=e-s,l=Math.cos(i.rot),h=Math.sin(i.rot),c=o*l+a*h,u=-o*h+a*l;return c>=-i.w/2&&c<=i.w/2&&u>=-i.h/2&&u<=i.h/2}else return t>=i.x&&t<=i.x+i.w&&e>=i.y&&e<=i.y+i.h}};Hi(_t.RECTANGLE,uy);const Ge=r=>Ss(r.target),Ss=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},dy=r=>(r==null?void 0:r.type)==="FragmentSelector"?!0:typeof r=="string"?r.indexOf("#")<0?!1:/#xywh(?:=(?:pixel:|percent:)?)(.+?),(.+?),(.+?),(.+)$/i.test(r):!1,fy=(r,t=!1)=>{const e=typeof r=="string"?r:r.value,i=/(xywh)=(?:(pixel|percent):)?:?(.+?),(.+?),(.+?),(.+)*/g,n=[...e.matchAll(i)][0];if(!n)throw new Error("Not a MediaFragment: "+e);const[s,o,a,l,h,c,u]=n;if(o!=="xywh")throw new Error("Unsupported MediaFragment: "+e);if(a&&a!=="pixel")throw new Error(`Unsupported MediaFragment unit: ${a}`);const[d,f,p,g]=[l,h,c,u].map(parseFloat);return{type:_t.RECTANGLE,geometry:{x:d,y:f,w:p,h:g,rot:0,bounds:{minX:d,minY:t?f-g:f,maxX:d+p,maxY:t?f:f+g}}}},py=r=>{const{x:t,y:e,w:i,h:n}=r;return{type:"FragmentSelector",conformsTo:"http://www.w3.org/TR/media-frags/",value:`xywh=pixel:${t},${e},${i},${n}`}},gc="http://www.w3.org/2000/svg",yc=r=>{const t=i=>{Array.from(i.attributes).forEach(n=>{n.name.startsWith("on")&&i.removeAttribute(n.name)})},e=r.getElementsByTagName("script");return Array.from(e).reverse().forEach(i=>i.parentNode.removeChild(i)),Array.from(r.querySelectorAll("*")).forEach(t),r},my=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${gc}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},Mn=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(gc),i=t.lookupNamespaceURI(null);return e||i?yc(t).firstChild:yc(my(t)).firstChild},gy=r=>{const t=_c(r),e=[];let i=[],n=[0,0];for(const s of t)switch(s.type.toUpperCase()){case"M":i.length>0&&(e.push({points:i}),i=[]),n=[s.args[0],s.args[1]],i.push([...n]);break;case"L":n=[s.args[0],s.args[1]],i.push([...n]);break;case"H":n=[s.args[0],n[1]],i.push([...n]);break;case"V":n=[n[0],s.args[0]],i.push([...n]);break;case"C":n=[s.args[4],s.args[5]],i.push([...n]);break;case"Z":break;default:console.warn(`Unsupported SVG path command: ${s.type}`);break}if(i.length>2&&e.push({points:i}),e.length>0){const s=ge(e[0].points);return{rings:e,bounds:s}}},yy=r=>{const{point:t,inHandle:e,outHandle:i}=r;if(!e||!i)return!1;const n=e[0]-t[0],s=e[1]-t[1],o=i[0]-t[0],a=i[1]-t[1],l=n*a-s*o;return Math.abs(l)<.01},_y=r=>{const t=_c(r);let e=[],i=[0,0],n=!1;for(let o=0;o<t.length;o++){const a=t[o];switch(a.type.toUpperCase()){case"M":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"L":i=[a.args[0],a.args[1]],e.push({type:"CORNER",point:[...i]});break;case"C":const l=[a.args[0],a.args[1]],h=[a.args[2],a.args[3]],c=[a.args[4],a.args[5]];if(e.length>0){const d=e[e.length-1];(l[0]!==d.point[0]||l[1]!==d.point[1])&&(d.type="CURVE",d.outHandle=l)}const u={type:h[0]!==c[0]||h[1]!==c[1]?"CURVE":"CORNER",point:c};u.type==="CURVE"&&(u.inHandle=h),e.push(u),i=c;break;case"Z":n=!0;break;default:console.warn(`Unsupported SVG path command: ${a.type}`);break}}e=e.map(o=>yy(o)?{...o,locked:!0}:o);const s=ge(da(e,n));return{points:e,closed:n,bounds:s}},_c=r=>{const t=[],e=r.replace(/,/g," ").trim(),i=/([MmLlHhVvCcZz])\s*([^MmLlHhVvCcZz]*)/g;let n;for(;(n=i.exec(e))!==null;){const[,s,o]=n,a=o.trim()===""?[]:o.trim().split(/\s+/).map(Number).filter(l=>!isNaN(l));t.push({type:s,args:a})}return t},vy=r=>{const[t,e,i]=r.match(/(<polygon points=["|'])([^("|')]*)/)||[],n=i.split(" ").map(s=>s.split(",").map(parseFloat));return{type:_t.POLYGON,geometry:{points:n,bounds:ge(n)}}},by=r=>{const t=Mn(r),e=parseFloat(t.getAttribute("cx")),i=parseFloat(t.getAttribute("cy")),n=parseFloat(t.getAttribute("rx")),s=parseFloat(t.getAttribute("ry")),o={minX:e-n,minY:i-s,maxX:e+n,maxY:i+s};return{type:_t.ELLIPSE,geometry:{cx:e,cy:i,rx:n,ry:s,bounds:o}}},xy=r=>{const t=Mn(r),e=parseFloat(t.getAttribute("x1")),i=parseFloat(t.getAttribute("x2")),n=parseFloat(t.getAttribute("y1")),s=parseFloat(t.getAttribute("y2")),o={minX:Math.min(e,i),minY:Math.min(n,s),maxX:Math.max(e,i),maxY:Math.max(n,s)};return{type:_t.LINE,geometry:{points:[[e,n],[i,s]],bounds:o}}},wy=r=>{const t=Mn(r),e=t.nodeName==="path"?t:Array.from(t.querySelectorAll("path"))[0],i=e==null?void 0:e.getAttribute("d");if(!i)throw new Error("Could not parse SVG path");const n=_y(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},Ey=r=>{const t=Mn(r),e=t.nodeName==="rect"?t:Array.from(t.querySelectorAll("rect"))[0];if(!e)throw new Error("Could not parse SVG rect");const i=parseFloat(e.getAttribute("x")),n=parseFloat(e.getAttribute("y")),s=parseFloat(e.getAttribute("width")),o=parseFloat(e.getAttribute("height")),a=e.getAttribute("transform");let l=0;if(a&&a.startsWith("rotate(")){const f=a.match(/rotate\(([^)]+)\)/);f&&(l=f[1].split(/\s+/).map(parseFloat)[0]*Math.PI/180)}const h=i+s/2,c=n+o/2,u=[[i,n],[i+s,n],[i+s,n+o],[i,n+o]].map(([f,p])=>{const g=f-h,y=p-c,_=Math.cos(l),v=Math.sin(l);return[h+g*_-y*v,c+g*v+y*_]}),d=ge(u);return{type:_t.RECTANGLE,geometry:{x:i,y:n,w:s,h:o,rot:l,bounds:d}}},Ty=r=>{const t=Mn(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>gy(s)).filter(Boolean),i=e.reduce((s,o)=>[...s,...o.rings[0].points],[]),n=ge(i);return e.length===1&&e[0].rings.length===1?{type:_t.POLYGON,geometry:{points:i,bounds:n}}:{type:_t.MULTIPOLYGON,geometry:{polygons:e,bounds:n}}},Ay=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return vy(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return wy(t);if(t.includes("<path "))return Ty(t);if(t.includes("<ellipse "))return by(t);if(t.includes("<line "))return xy(t);if(t.includes("<rect "))return Ey(t);throw"Unsupported SVG shape: "+t},Sy=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${je(t)}" />`).join("")}</g>`,Cy=r=>{let t;switch(r.type){case _t.RECTANGLE:{const e=r.geometry,{x:i,y:n,w:s,h:o,rot:a}=e;if(!a)t=`<svg><rect x="${i}" y="${n}" width="${s}" height="${o}" /></svg>`;else{const l=i+s/2,h=n+o/2,c=(a??0)*180/Math.PI;t=`<svg><rect x="${i}" y="${n}" width="${s}" height="${o}" transform="rotate(${c} ${l} ${h})" /></svg>`}break}case _t.POLYGON:{const e=r.geometry,{points:i}=e;t=`<svg><polygon points="${i.map(n=>n.join(",")).join(" ")}" /></svg>`;break}case _t.ELLIPSE:{const e=r.geometry;t=`<svg><ellipse cx="${e.cx}" cy="${e.cy}" rx="${e.rx}" ry="${e.ry}" /></svg>`;break}case _t.MULTIPOLYGON:{const e=r.geometry;t=`<svg>${Sy(e)}</svg>`;break}case _t.LINE:{const e=r.geometry,[[i,n],[s,o]]=e.points;t=`<svg><line x1="${i}" y1="${n}" x2="${s}" y2="${o}" /></svg>`;break}case _t.POLYLINE:t=`<svg><path d="${fa(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ye=[];for(let r=0;r<256;++r)ye.push((r+256).toString(16).slice(1));function Iy(r,t=0){return(ye[r[t+0]]+ye[r[t+1]]+ye[r[t+2]]+ye[r[t+3]]+"-"+ye[r[t+4]]+ye[r[t+5]]+"-"+ye[r[t+6]]+ye[r[t+7]]+"-"+ye[r[t+8]]+ye[r[t+9]]+"-"+ye[r[t+10]]+ye[r[t+11]]+ye[r[t+12]]+ye[r[t+13]]+ye[r[t+14]]+ye[r[t+15]]).toLowerCase()}const Py=new Uint8Array(16);function Ry(){return crypto.getRandomValues(Py)}function vc(r,t,e){return crypto.randomUUID?crypto.randomUUID():My(r)}function My(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Ry();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Iy(n)}var bc=Object.prototype.hasOwnProperty;function Ur(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--&&Ur(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(bc.call(r,e)&&++i&&!bc.call(t,e)||!(e in t)||!Ur(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}let We=[],Gr=0;const Cs=4,Oy=globalThis.nanostoresGlobal||(globalThis.nanostoresGlobal={epoch:0}),pa=r=>{let t=[],e={get(){return e.lc||e.listen(()=>{})(),e.value},init:r,lc:0,listen(i){return e.lc=t.push(i),()=>{for(let s=Gr+Cs;s<We.length;)We[s]===i?We.splice(s,Cs):s+=Cs;let n=t.indexOf(i);~n&&(t.splice(n,1),--e.lc||e.off())}},notify(i,n){Oy.epoch++;let s=!We.length;for(let o of t)We.push(o,e.value,i,n);if(s){for(Gr=0;Gr<We.length;Gr+=Cs)We[Gr](We[Gr+1],We[Gr+2],We[Gr+3]);We.length=0}},off(){},set(i){let n=e.value;n!==i&&(e.value=i,e.notify(n))},subscribe(i){let n=e.listen(i);return i(e.value),n},value:r};return e},By=r=>{const t=pa(null);return r.observe(({changes:e})=>{const i=t.get();if(i){(e.deleted||[]).some(s=>s.id===i)&&t.set(null);const n=(e.updated||[]).find(({oldValue:s})=>s.id===i);n&&t.set(n.newValue.id)}}),{get current(){return t.get()},subscribe:t.subscribe.bind(t),set:t.set.bind(t)}};var xc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(xc||{});const ma={selected:[]},Ly=(r,t,e)=>{const i=pa(ma);let n=t;const s=()=>{Ur(i.get(),ma)||i.set(ma)},o=()=>{var f;return((f=i.get().selected)==null?void 0:f.length)===0},a=f=>{if(o())return!1;const p=typeof f=="string"?f:f.id;return i.get().selected.some(g=>g.id===p)},l=(f,p)=>{let g;if(Array.isArray(f)){if(g=f.map(_=>r.getAnnotation(_)).filter(Boolean),g.length<f.length){console.warn("Invalid selection: "+f.filter(_=>!g.some(v=>v.id===_)));return}}else{const _=r.getAnnotation(f);if(!_){console.warn("Invalid selection: "+f);return}g=[_]}const y=g.reduce((_,v)=>{const m=d(v);return m==="EDIT"?[..._,{id:v.id,editable:!0}]:m==="SELECT"?[..._,{id:v.id}]:_},[]);i.set({selected:y,event:p})},h=(f,p)=>{const g=Array.isArray(f)?f:[f],y=g.map(_=>r.getAnnotation(_)).filter(_=>!!_);i.set({selected:y.map(_=>{const v=p===void 0?d(_)==="EDIT":p;return{id:_.id,editable:v}})}),y.length!==g.length&&console.warn("Invalid selection",f)},c=f=>{if(o())return!1;const{selected:p}=i.get();p.some(({id:g})=>f.includes(g))&&i.set({selected:p.filter(({id:g})=>!f.includes(g))})},u=f=>{n=f,h(i.get().selected.map(({id:p})=>p))},d=f=>Dy(f,n,e);return r.observe(({changes:f})=>c((f.deleted||[]).map(p=>p.id))),{get event(){const f=i.get();return f?f.event:null},get selected(){const f=i.get();return f?[...f.selected]:null},get userSelectAction(){return n},clear:s,evalSelectAction:d,isEmpty:o,isSelected:a,setSelected:h,setUserSelectAction:u,subscribe:i.subscribe.bind(i),userSelect:l}},Dy=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},_e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function Ny(r,t=0){return(_e[r[t+0]]+_e[r[t+1]]+_e[r[t+2]]+_e[r[t+3]]+"-"+_e[r[t+4]]+_e[r[t+5]]+"-"+_e[r[t+6]]+_e[r[t+7]]+"-"+_e[r[t+8]]+_e[r[t+9]]+"-"+_e[r[t+10]]+_e[r[t+11]]+_e[r[t+12]]+_e[r[t+13]]+_e[r[t+14]]+_e[r[t+15]]).toLowerCase()}const Fy=new Uint8Array(16);function ky(){return crypto.getRandomValues(Fy)}function Uy(r,t,e){return crypto.randomUUID?crypto.randomUUID():Gy(r)}function Gy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??ky();if(n.length<16)throw new Error("Random bytes length must be >= 16");return n[6]=n[6]&15|64,n[8]=n[8]&63|128,Ny(n)}const ga=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)}},$y=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},Hy=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Vy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Ur(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),Xy=(r,t)=>!Ur(r.target,t.target),wc=(r,t)=>{const e=$y(r,t),i=Hy(r,t),n=Vy(r,t);return{oldValue:r,newValue:t,bodiesCreated:e.length>0?e:void 0,bodiesDeleted:i.length>0?i:void 0,bodiesUpdated:n.length>0?n:void 0,targetUpdated:Xy(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Dt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Dt||{});const jy=(r,t)=>{var e,i;const{changes:n,origin:s}=t;if(!(r.options.origin?r.options.origin===s:s!=="SILENT"))return!1;if(r.options.ignore){const{ignore:o}=r.options,a=l=>l&&l.length>0;if(!(a(n.created)||a(n.deleted))){const l=(e=n.updated)==null?void 0:e.some(c=>a(c.bodiesCreated)||a(c.bodiesDeleted)||a(c.bodiesUpdated)),h=(i=n.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([...(n.created||[]).map(a=>a.id),...(n.deleted||[]).map(a=>a.id),...(n.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},Wy=(r,t)=>{const e=new Set((r.created||[]).map(u=>u.id)),i=new Set((r.updated||[]).map(({newValue:u})=>u.id)),n=new Set((t.created||[]).map(u=>u.id)),s=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=>!s.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=>!n.has(u.id)),...(t.deleted||[]).filter(u=>!e.has(u.id))],c=[...(r.updated||[]).filter(({newValue:u})=>!s.has(u.id)).map(u=>{const{oldValue:d,newValue:f}=u;if(o.has(f.id)){const p=t.updated.find(g=>g.oldValue.id===f.id).newValue;return wc(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},Is=r=>{const t=r.id===void 0?Uy():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Yy=r=>r.id!==void 0,zy=()=>{const r=new Map,t=new Map,e=[],i=(P,T={})=>{e.push({onChange:P,options:T})},n=P=>{const T=e.findIndex(w=>w.onChange==P);T>-1&&e.splice(T,1)},s=(P,T)=>{const w={origin:P,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...r.values()]};e.forEach(A=>{jy(A,w)&&A.onChange(w)})},o=(P,T=Dt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const w=Is(P);r.set(w.id,w),w.bodies.forEach(A=>t.set(A.id,w.id)),s(T,{created:[w]})}},a=(P,T)=>{const w=Is(typeof P=="string"?T:P),A=typeof P=="string"?P:P.id,L=A&&r.get(A);if(L){const O=wc(L,w);return A===w.id?r.set(A,w):(r.delete(A),r.set(w.id,w)),L.bodies.forEach(D=>t.delete(D.id)),w.bodies.forEach(D=>t.set(D.id,w.id)),O}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,T=Dt.LOCAL,w=Dt.LOCAL)=>{const A=Yy(T)?w:T,L=a(P,T);L&&s(A,{updated:[L]})},h=(P,T=Dt.LOCAL)=>{r.get(P.id)?l(P,T):o(P,T)},c=(P,T=Dt.LOCAL)=>{const w=P.reduce((A,L)=>{const O=a(L);return O?[...A,O]:A},[]);w.length>0&&s(T,{updated:w})},u=(P,T=Dt.LOCAL)=>{const w=P.map(Is),{toAdd:A,toUpdate:L}=w.reduce((D,$)=>r.get($.id)?{...D,toUpdate:[...D.toUpdate,$]}:{...D,toAdd:[...D.toAdd,$]},{toAdd:[],toUpdate:[]}),O=L.map(D=>a(D,T)).filter(Boolean);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach($=>t.set($.id,D.id))}),s(T,{created:A,updated:O})},d=(P,T=Dt.LOCAL)=>{const w=r.get(P.annotation);if(w){const A={...w,bodies:[...w.bodies,P]};r.set(w.id,A),t.set(P.id,A.id),s(T,{updated:[{oldValue:w,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},f=()=>[...r.values()],p=(P=Dt.LOCAL)=>{const T=[...r.values()];r.clear(),t.clear(),s(P,{deleted:T})},g=(P,T=!0,w=Dt.LOCAL)=>{const A=P.map(Is);if(T){const L=[...r.values()];r.clear(),t.clear(),A.forEach(O=>{r.set(O.id,O),O.bodies.forEach(D=>t.set(D.id,O.id))}),s(w,{created:A,deleted:L})}else{const L=P.reduce((O,D)=>{const $=D.id&&r.get(D.id);return $?[...O,$]:O},[]);if(L.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${L.map(O=>O.id).join(", ")}`);A.forEach(O=>{r.set(O.id,O),O.bodies.forEach(D=>t.set(D.id,O.id))}),s(w,{created:A})}},y=P=>{const T=typeof P=="string"?P:P.id,w=r.get(T);if(w)return r.delete(T),w.bodies.forEach(A=>t.delete(A.id)),w;console.warn(`Attempt to delete missing annotation: ${T}`)},_=(P,T=Dt.LOCAL)=>{const w=y(P);w&&s(T,{deleted:[w]})},v=(P,T=Dt.LOCAL)=>{const w=P.reduce((A,L)=>{const O=y(L);return O?[...A,O]:A},[]);w.length>0&&s(T,{deleted:w})},m=P=>{const T=r.get(P.annotation);if(T){const w=T.bodies.find(A=>A.id===P.id);if(w){t.delete(w.id);const A={...T,bodies:T.bodies.filter(L=>L.id!==P.id)};return r.set(T.id,A),{oldValue:T,newValue:A,bodiesDeleted:[w]}}else console.warn(`Attempt to delete missing body ${P.id} from annotation ${P.annotation}`)}else console.warn(`Attempt to delete body from missing annotation ${P.annotation}`)},x=(P,T=Dt.LOCAL)=>{const w=m(P);w&&s(T,{updated:[w]})},S=(P,T=Dt.LOCAL)=>{const w=P.map(A=>m(A)).filter(Boolean);w.length>0&&s(T,{updated:w})},R=P=>{const T=r.get(P);return T?{...T}:void 0},C=P=>{const T=t.get(P);if(T){const w=R(T).bodies.find(A=>A.id===P);if(w)return w;console.error(`Store integrity error: body ${P} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${P}`)},I=(P,T)=>{if(P.annotation!==T.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const w=r.get(P.annotation);if(w){const A=w.bodies.find(O=>O.id===P.id),L={...w,bodies:w.bodies.map(O=>O.id===A.id?T:O)};return r.set(w.id,L),A.id!==T.id&&(t.delete(A.id),t.set(T.id,L.id)),{oldValue:w,newValue:L,bodiesUpdated:[{oldBody:A,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,T,w=Dt.LOCAL)=>{const A=I(P,T);A&&s(w,{updated:[A]})},F=(P,T=Dt.LOCAL)=>{const w=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(T,{updated:w})},U=P=>{const T=r.get(P.annotation);if(T){const w={...T,target:{...T.target,...P}};return r.set(T.id,w),{oldValue:T,newValue:w,targetUpdated:{oldTarget:T.target,newTarget:P}}}else console.warn(`Attempt to update target on missing annotation: ${P.annotation}`)};return{addAnnotation:o,addBody:d,all:f,bulkAddAnnotations:g,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,T=Dt.LOCAL)=>{const w=P.map(A=>U(A)).filter(Boolean);w.length>0&&s(T,{updated:w})},bulkUpsertAnnotations:u,clear:p,deleteAnnotation:_,deleteBody:x,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,T=Dt.LOCAL)=>{const w=U(P);w&&s(T,{updated:[w]})},upsertAnnotation:h}};let qy=()=>({emit(r,...t){for(let e=this.events[r]||[],i=0,n=e.length;i<n;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(n=>t!==n)}}});const Ky=250,Zy=(r,t)=>{const e=qy(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:g}=p,y=performance.now();if(y-o>Ky)i.splice(n+1),i.push(g),n=i.length-1;else{const _=i.length-1;i[_]=Wy(i[_],g)}o=y}s=!1};r.observe(a,{origin:Dt.LOCAL});const l=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p),h=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),c=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({oldValue:g})=>g)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:g})=>g)),d=p=>p&&p.length>0&&r.bulkAddAnnotations(p,!1),f=p=>p&&p.length>0&&r.bulkDeleteAnnotations(p);return{canRedo:()=>i.length-1>n,canUndo:()=>n>-1,destroy:()=>r.unobserve(a),getHistory:()=>({changes:[...i],pointer:n}),on:(p,g)=>e.on(p,g),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:g,deleted:y}=i[n+1];h(p),u(g),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:g,deleted:y}=i[n];l(p),c(g),d(y),e.emit("undo",i[n]),n-=1}}}},Jy=()=>{const r=pa([]);return{subscribe:r.subscribe.bind(r),set:r.set.bind(r)}},Qy=(r,t,e,i)=>{const{hover:n,selection:s,store:o,viewport:a}=r,l=new Map;let h=[],c,u;const d=(_,v)=>{l.has(_)?l.get(_).push(v):l.set(_,[v])},f=(_,v)=>{const m=l.get(_);if(m){const x=m.indexOf(v);x!==-1&&m.splice(x,1)}},p=(_,v,m)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(x=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=m?m instanceof PointerEvent?m:e.serialize(m):void 0;x(S,R)}else x(v,m)})},1)},g=()=>{const{selected:_}=s,v=(_||[]).map(({id:m})=>o.getAnnotation(m));v.forEach(m=>{const x=h.find(S=>S.id===m.id);(!x||!Ur(x,m))&&p("updateAnnotation",m,x)}),h=h.map(m=>v.find(({id:x})=>x===m.id)||m)};s.subscribe(({selected:_})=>{if(!(h.length===0&&_.length===0)){if(h.length===0&&_.length>0)h=_.map(({id:v})=>o.getAnnotation(v));else if(h.length>0&&_.length===0)h.forEach(v=>{const m=o.getAnnotation(v.id);m&&!Ur(m,v)&&p("updateAnnotation",m,v)}),h=[];else{const v=new Set(h.map(x=>x.id)),m=new Set(_.map(({id:x})=>x));h.filter(x=>!m.has(x.id)).forEach(x=>{const S=o.getAnnotation(x.id);S&&!Ur(S,x)&&p("updateAnnotation",S,x)}),h=[...h.filter(x=>m.has(x.id)),..._.filter(({id:x})=>!v.has(x)).map(({id:x})=>o.getAnnotation(x))]}p("selectionChanged",h)}}),n.subscribe(_=>{!c&&_?p("mouseEnterAnnotation",o.getAnnotation(_)):c&&!_?p("mouseLeaveAnnotation",o.getAnnotation(c)):c&&_&&(p("mouseLeaveAnnotation",o.getAnnotation(c)),p("mouseEnterAnnotation",o.getAnnotation(_))),c=_}),a==null||a.subscribe(_=>p("viewportIntersect",_.map(v=>o.getAnnotation(v)))),o.observe(_=>{i&&(u&&clearTimeout(u),u=setTimeout(g,1e3));const{created:v,deleted:m}=_.changes;(v||[]).forEach(x=>p("createAnnotation",x)),(m||[]).forEach(x=>p("deleteAnnotation",x)),(_.changes.updated||[]).filter(x=>[...x.bodiesCreated||[],...x.bodiesDeleted||[],...x.bodiesUpdated||[]].length>0).forEach(({oldValue:x,newValue:S})=>{const R=h.find(C=>C.id===x.id)||x;h=h.map(C=>C.id===x.id?S:C),p("updateAnnotation",S,R)})},{origin:Dt.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(x=>x.id)),m=(_.changes.updated||[]).filter(({newValue:x})=>v.has(x.id)).map(({newValue:x})=>x);m.length>0&&(h=h.map(x=>m.find(S=>S.id===x.id)||x))}},{origin:Dt.REMOTE});const y=_=>v=>{const{updated:m}=v;_?(m||[]).forEach(x=>p("updateAnnotation",x.oldValue,x.newValue)):(m||[]).forEach(x=>p("updateAnnotation",x.newValue,x.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},t0=r=>t=>t.reduce((e,i)=>{const{parsed:n,error:s}=r.parse(i);return s?{parsed:e.parsed,failed:[...e.failed,i]}:n?{parsed:[...e.parsed,n],failed:e.failed}:{...e}},{parsed:[],failed:[]}),e0=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:m}=e.parse(_);v?i.addAnnotation(v,Dt.REMOTE):console.error(m)}else i.addAnnotation(ga(_),Dt.REMOTE)},o=()=>n.clear(),a=()=>i.clear(),l=_=>{const v=i.getAnnotation(_);return e&&v?e.serialize(v):v},h=()=>e?i.all().map(e.serialize):i.all(),c=()=>{var _;const v=(((_=n.selected)==null?void 0:_.map(m=>m.id))||[]).map(m=>i.getAnnotation(m)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(m=>m.json()).then(m=>(f(m,v),m)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const m=e.parseAll||t0(e),{parsed:x,failed:S}=m(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(x,v,Dt.REMOTE)}else i.bulkAddAnnotations(_.map(ga),v,Dt.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},g=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,m=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),m}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(ga(_)),v}};return{addAnnotation:s,cancelSelected:o,canRedo:t.canRedo,canUndo:t.canUndo,clearAnnotations:a,getAnnotationById:l,getAnnotations:h,getHistory:t.getHistory,getSelected:c,loadAnnotations:u,redo:t.redo,removeAnnotation:d,setAnnotations:f,setSelected:p,setUserSelectAction:g,undo:t.undo,updateAnnotation:y}},r0=(r,t,e)=>typeof t=="function"?t(r,e):t,i0=(r,t)=>typeof r!="function"&&typeof t!="function"?{...r||{},...t||{}}:(e,i)=>{const n=typeof r=="function"?r(e,i):r,s=typeof t=="function"?t(e,i):t;return{...n||{},...s||{}}};let n0="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict",s0=r=>crypto.getRandomValues(new Uint8Array(r)),o0=(r,t,e)=>{let i=256-256%r.length;if(i===256){let s=r.length-1;return(o=t)=>{if(!o)return"";let a="";for(;;){let l=e(o),h=o;for(;h--;)if(a+=r[l[h]&s],a.length>=o)return a}}}let n=Math.ceil(1.6*256*t/i);return(s=t)=>{if(!s)return"";let o="";for(;;){let a=e(n),l=n;for(;l--;)if(a[l]<i&&(o+=r[a[l]%r.length],o.length>=s))return o}}},a0=(r,t=21)=>o0(r,t|0,s0),l0=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=n0[e[r]&63];return t};const h0=()=>({isGuest:!0,id:a0("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),c0=r=>{const t=JSON.stringify(r);let e=0;for(let i=0,n=t.length;i<n;i++){let s=t.charCodeAt(i);e=(e<<5)-e+s,e|=0}return`${e}`},Ec=r=>r?typeof r=="object"?{...r}:r:void 0,u0=(r,t)=>(Array.isArray(r)?r:[r]).map(e=>{const{id:i,type:n,purpose:s,value:o,created:a,modified:l,creator:h,...c}=e;return{id:i||`temp-${c0(e)}`,annotation:t,type:n,purpose:s,value:o,creator:Ec(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),d0=r=>r.map(t=>{var e;const{annotation:i,created:n,updated:s,...o}=t,a={...o,created:n==null?void 0:n.toISOString(),modified:s==null?void 0:s.toISOString()};return(e=a.id)!=null&&e.startsWith("temp-")&&delete a.id,a});l0();const f0=(r,t={strict:!0,invertY:!1})=>({parse:e=>p0(e,t),serialize:e=>m0(e,r,t)}),p0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||vc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=u0(o||[],e),h=Array.isArray(r.target)?r.target[0]:r.target,c=typeof h=="string"?h:Array.isArray(h.selector)?h.selector[0]:h.selector,u=dy(c)?fy(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?Ay(c):void 0,d=Array.isArray(a.target)?a.target[0]:a.targret;return u||!t.strict?{parsed:{...a,id:e,bodies:l,target:{created:n?new Date(n):void 0,creator:Ec(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},m0=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:n,created:s,updated:o,updatedBy:a,...l}=r.target;let h;try{i.type===_t.RECTANGLE&&!i.geometry.rot?h=py(i.geometry):h=Cy(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:d0(r.bodies),created:s==null?void 0:s.toISOString(),creator:n,modified:o==null?void 0:o.toISOString(),target:{...l,source:t,type:"SpecificResource",selector:h}};return delete c.bodies,typeof c.target!="string"&&"annotation"in c.target&&delete c.target.annotation,c},Vi=[];function g0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Vi.length;for(const h of i)h[1](),Vi.push(h,r);if(l){for(let h=0;h<Vi.length;h+=2)Vi[h][0](Vi[h+1]);Vi.length=0}}}function s(a){n(a(r))}function o(a,l=Rt){const h=[a,l];return i.add(h),i.size===1&&(e=t(n,s)||Rt),a(r),()=>{i.delete(h),i.size===0&&e&&(e(),e=null)}}return{set:n,update:s,subscribe:o}}const y0=(r,t)=>{const{naturalWidth:e,naturalHeight:i}=r;if(!e&&!i){const{width:n,height:s}=r;t.setAttribute("viewBox",`0 0 ${n} ${s}`),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}`)},_0=(r,t)=>{y0(r,t);const{subscribe:e,set:i}=g0(1);let n;return window.ResizeObserver&&(n=new ResizeObserver(()=>{const s=t.getBoundingClientRect(),{width:o,height:a}=t.viewBox.baseVal,l=Math.max(s.width/o,s.height/a);i(l)}),n.observe(t.parentElement)),{destroy:()=>{n&&n.disconnect()},subscribe:e}},hi=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},Ps=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},Fe=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,v0=r=>({}),Tc=r=>({grab:r[0]});function b0(r){let t,e,i,n;const s=r[8].default,o=jg(s,r,r[7],Tc);return{c(){t=Y("g"),o&&o.c(),b(t,"class","a9s-annotation selected")},m(a,l){rt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Ct(t,"pointerup",r[2]),Ct(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Yg(o,s,a,a[7],e?Wg(s,a[7],l,v0):zg(a[7]),Tc)},i(a){e||(ht(o,a),e=!0)},o(a){yt(o,a),e=!1},d(a){a&&et(t),o&&o.d(a),i=!1,De(n)}}}function x0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=kr();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=y=>_=>{if(c=y,h){const{left:v,top:m}=h.getBoundingClientRect(),x=_.clientX-v,S=_.clientY-m;u=l.elementToImage(x,S)}else{const{offsetX:v,offsetY:m}=_;u=l.elementToImage(v,m)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),m=[_-u[0],v-u[1]];e(3,o=a(d,c,m)),s("change",o)}},g=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[f,p,g,o,a,l,h,n,i]}class ya extends me{constructor(t){super(),pe(this,t,x0,b0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function w0(r){let t,e,i,n,s,o,a,l,h=r[3]&&Ac(r);return{c(){t=Y("g"),e=Y("circle"),h&&h.c(),n=Y("circle"),b(e,"class","a9s-handle-buffer svelte-qtyc7s"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]+6/r[2]),b(e,"role","button"),b(e,"tabindex","0"),b(n,"class",s=ki(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",r[5]),b(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){rt(c,t,u),bt(t,e),h&&h.m(t,null),bt(t,n),a||(l=[Ct(e,"dblclick",r[12]),Ct(e,"pointerenter",r[13]),Ct(e,"pointerleave",r[14]),Ct(e,"pointerdown",r[15]),Ct(e,"pointerdown",r[6]),Ct(e,"pointerup",r[16]),Ct(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&b(e,"cx",c[0]),u&2&&b(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&b(e,"r",i),c[3]?h?h.p(c,u):(h=Ac(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=ki(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&b(n,"class",s),u&1&&b(n,"cx",c[0]),u&2&&b(n,"cy",c[1]),u&32&&b(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&b(t,"class",o)},d(c){c&&et(t),h&&h.d(),a=!1,De(l)}}}function E0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=Y("g"),e=Y("circle"),n=Y("circle"),o=Y("circle"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=r[5]*10),b(e,"class","a9s-touch-halo"),ir(e,"touched",r[4]),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",s=r[5]+10/r[2]),b(n,"class","a9s-handle-buffer svelte-qtyc7s"),b(n,"role","button"),b(n,"tabindex","0"),b(o,"class","a9s-handle-dot"),b(o,"cx",r[0]),b(o,"cy",r[1]),b(o,"r",a=r[5]+2/r[2]),b(t,"class","a9s-touch-handle")},m(c,u){rt(c,t,u),bt(t,e),bt(t,n),bt(t,o),l||(h=[Ct(n,"dblclick",r[9]),Ct(n,"pointerdown",r[10]),Ct(n,"pointerdown",r[6]),Ct(n,"pointerup",r[11]),Ct(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&b(e,"cx",c[0]),u&2&&b(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&b(e,"r",i),u&16&&ir(e,"touched",c[4]),u&1&&b(n,"cx",c[0]),u&2&&b(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&b(n,"r",s),u&1&&b(o,"cx",c[0]),u&2&&b(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&b(o,"r",a)},d(c){c&&et(t),l=!1,De(h)}}}function Ac(r){let t,e;return{c(){t=Y("circle"),b(t,"class","a9s-handle-selected"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",e=r[5]+8/r[2])},m(i,n){rt(i,t,n)},p(i,n){n&1&&b(t,"cx",i[0]),n&2&&b(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&b(t,"r",e)},d(i){i&&et(t)}}}function T0(r){let t;function e(n,s){return Fe?E0:w0}let i=e()(r);return{c(){i.c(),t=Ne()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&et(t),i.d(n)}}}function A0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=m=>{m.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(m){oe.call(this,r,m)}function d(m){oe.call(this,r,m)}function f(m){oe.call(this,r,m)}function p(m){oe.call(this,r,m)}function g(m){oe.call(this,r,m)}function y(m){oe.call(this,r,m)}function _(m){oe.call(this,r,m)}function v(m){oe.call(this,r,m)}return r.$$set=m=>{e(8,t=na(na({},t),oc(m))),"x"in m&&e(0,n=m.x),"y"in m&&e(1,s=m.y),"scale"in m&&e(2,o=m.scale),"selected"in m&&e(3,a=m.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=oc(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,g,y,_,v]}class ci extends me{constructor(t){super(),pe(this,t,A0,T0,Kt,{x:0,y:1,scale:2,selected:3})}}function S0(r){let t,e,i,n,s,o,a;return{c(){t=Y("g"),e=Y("circle"),n=Y("circle"),s=Y("circle"),b(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),b(e,"cx",r[0]),b(e,"cy",r[1]),b(e,"r",i=1.75*r[2]),b(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),b(n,"cx",r[0]),b(n,"cy",r[1]),b(n,"r",r[2]),b(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),b(s,"cx",r[0]),b(s,"cy",r[1]),b(s,"r",r[2]),b(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){rt(l,t,h),bt(t,e),bt(t,n),bt(t,s),o||(a=[Ct(e,"pointerdown",r[5]),Ct(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&b(e,"cx",l[0]),h&2&&b(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&b(e,"r",i),h&1&&b(n,"cx",l[0]),h&2&&b(n,"cy",l[1]),h&4&&b(n,"r",l[2]),h&1&&b(s,"cx",l[0]),h&2&&b(s,"cy",l[1]),h&4&&b(s,"r",l[2])},d(l){l&&et(t),o=!1,De(a)}}}function C0(r){let t;return{c(){t=Y("circle"),b(t,"cx",r[0]),b(t,"cy",r[1]),b(t,"r",r[2])},m(e,i){rt(e,t,i)},p(e,i){i&1&&b(t,"cx",e[0]),i&2&&b(t,"cy",e[1]),i&4&&b(t,"r",e[2])},d(e){e&&et(t)}}}function I0(r){let t;function e(n,s){return Fe?C0:S0}let i=e()(r);return{c(){i.c(),t=Ne()},m(n,s){i.m(n,s),rt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&et(t),i.d(n)}}}function P0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){oe.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class Sc extends me{constructor(t){super(),pe(this,t,P0,I0,Kt,{x:0,y:1,scale:4})}}function _a(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Cc(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function va(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ba(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ic(r){let t,e,i,n;return{c(){t=Y("circle"),b(t,"cx",e=r[28][0]),b(t,"cy",i=r[28][1]),b(t,"r",n=On/r[3]),b(t,"class","svelte-1h2slbm")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&b(t,"cy",i),o[0]&8&&n!==(n=On/s[3])&&b(t,"r",n)},d(s){s&&et(t)}}}function Pc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=Y("mask"),e=Y("rect"),a=Y("circle"),b(e,"x",i=r[9].x),b(e,"y",n=r[9].y),b(e,"width",s=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1h2slbm"),b(a,"cx",l=r[28][0]),b(a,"cy",h=r[28][1]),b(a,"r",c=On/r[3]),b(a,"class","svelte-1h2slbm"),b(t,"id",`${r[19]}-inner`),b(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&b(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&b(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&b(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&b(a,"cy",h),d[0]&8&&c!==(c=On/u[3])&&b(a,"r",c)},d(u){u&&et(t)}}}function Rc(r){let t,e;return t=new ci({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){kt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Mc(r){let t,e;return t=new Sc({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){kt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function R0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R=r[6]!==void 0&&!r[7]&&Ic(ba(r)),C=r[6]!==void 0&&!r[7]&&Pc(va(r)),I=Oe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Rc(Cc(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Mc(_a(r));return{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("polygon"),R&&R.c(),C&&C.c(),c=Se(),u=Y("polygon"),f=Se(),p=Y("polygon"),y=Se();for(let P=0;P<M.length;P+=1)M[P].c();_=Se(),U&&U.c(),v=Ne(),b(i,"x",n=r[9].x),b(i,"y",s=r[9].y),b(i,"width",o=r[9].w),b(i,"height",a=r[9].h),b(i,"class","svelte-1h2slbm"),b(l,"points",h=r[5].points.map(Oc).join(" ")),b(l,"class","svelte-1h2slbm"),b(e,"id",`${r[19]}-outer`),b(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),b(u,"class","a9s-outer"),b(u,"mask",`url(#${r[19]}-outer)`),b(u,"points",d=r[5].points.map(Bc).join(" ")),b(p,"class","a9s-inner a9s-shape-handle"),b(p,"mask",`url(#${r[19]}-inner)`),b(p,"style",r[1]),b(p,"points",g=r[5].points.map(Lc).join(" "))},m(P,T){rt(P,t,T),bt(t,e),bt(e,i),bt(e,l),R&&R.m(e,null),C&&C.m(t,null),rt(P,c,T),rt(P,u,T),rt(P,f,T),rt(P,p,T),rt(P,y,T);for(let w=0;w<M.length;w+=1)M[w]&&M[w].m(P,T);rt(P,_,T),U&&U.m(P,T),rt(P,v,T),m=!0,x||(S=[Ct(u,"pointerup",r[14]),Ct(u,"pointerdown",function(){kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Ct(p,"pointermove",r[13]),Ct(p,"pointerup",r[14]),Ct(p,"pointerdown",function(){kt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],x=!0)},p(P,T){if(r=P,(!m||T[0]&512&&n!==(n=r[9].x))&&b(i,"x",n),(!m||T[0]&512&&s!==(s=r[9].y))&&b(i,"y",s),(!m||T[0]&512&&o!==(o=r[9].w))&&b(i,"width",o),(!m||T[0]&512&&a!==(a=r[9].h))&&b(i,"height",a),(!m||T[0]&32&&h!==(h=r[5].points.map(Oc).join(" ")))&&b(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(ba(r),T):(R=Ic(ba(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(va(r),T):(C=Pc(va(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!m||T[0]&32&&d!==(d=r[5].points.map(Bc).join(" ")))&&b(u,"points",d),(!m||T[0]&2)&&b(p,"style",r[1]),(!m||T[0]&32&&g!==(g=r[5].points.map(Lc).join(" ")))&&b(p,"points",g),T[0]&134322472){I=Oe(r[5].points);let w;for(w=0;w<I.length;w+=1){const A=Cc(r,I,w);M[w]?(M[w].p(A,T),ht(M[w],1)):(M[w]=Rc(A),M[w].c(),ht(M[w],1),M[w].m(_.parentNode,_))}for(Ce(),w=I.length;w<M.length;w+=1)F(w);Ie()}r[6]!==void 0&&!r[7]?U?(U.p(_a(r),T),T[0]&192&&ht(U,1)):(U=Mc(_a(r)),U.c(),ht(U,1),U.m(v.parentNode,v)):U&&(Ce(),yt(U,1,1,()=>{U=null}),Ie())},i(P){if(!m){for(let T=0;T<I.length;T+=1)ht(M[T]);ht(U),m=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)yt(M[T]);yt(U),m=!1},d(P){P&&(et(t),et(c),et(u),et(f),et(p),et(y),et(_),et(v)),R&&R.d(),C&&C.d(),ai(M,P),U&&U.d(P),x=!1,De(S)}}}function M0(r){let t,e;return t=new ya({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[R0,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const O0=250,B0=1e3,L0=12,On=4.5,Oc=r=>r.join(","),Bc=r=>r.join(","),Lc=r=>r.join(",");function D0(r,t,e){let i,n,s;const o=kr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=w=>{if(g.length>0||!n.some(N=>N.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(w.offsetX,w.offsetY),O=N=>Math.pow(N[0]-A,2)+Math.pow(N[1]-L,2),D=i.points.reduce((N,k)=>O(k)<O(N)?k:N),$=n.filter(N=>N.visible).reduce((N,k)=>O(k.point)<O(N.point)?k:N),B=Math.pow(B0/c,2);O(D)<B||O($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=w=>{e(7,f=!0),w.preventDefault(),w.stopPropagation(),p=performance.now()},R=w=>A=>{if(!p||Fe||performance.now()-p>O0)return;const L=g.includes(w);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,g=g.filter(O=>O!==w)):e(8,g=[...g,w]):L&&g.length>1?e(8,g=[w]):L?e(8,g=[]):e(8,g=[w]),m()},C=(w,A,L)=>{m();let O;const D=w.geometry;g.length>1?O=D.points.map(([B,N],k)=>g.includes(k)?[B+L[0],N+L[1]]:[B,N]):A==="SHAPE"?O=D.points.map(([B,N])=>[B+L[0],N+L[1]]):O=D.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+L[0],N+L[1]]:[B,N]);const $=ge(O);return{...w,geometry:{points:O,bounds:$}}},I=w=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,w+1),n[w].point,...i.points.slice(w+1)],O=ge(L);o("change",{...a,geometry:{points:L,bounds:O}}),await dc();const D=[...document.querySelectorAll(".a9s-handle")][w+1];if(D!=null&&D.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});D.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-g.length<3)return;const w=i.points.filter((L,O)=>!g.includes(O)),A=ge(w);o("change",{...a,geometry:{points:w,bounds:A}}),e(8,g=[])};Fr(()=>{if(Fe)return;const w=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",w),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",w)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(w){oe.call(this,r,w)}function P(w){oe.call(this,r,w)}function T(w){oe.call(this,r,w)}return r.$$set=w=>{"shape"in w&&e(0,a=w.shape),"computedStyle"in w&&e(1,l=w.computedStyle),"transform"in w&&e(2,h=w.transform),"viewportScale"in w&&e(3,c=w.viewportScale),"svgEl"in w&&e(4,u=w.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Fe?[]:i.points.map((w,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],O=(w[0]+L[0])/2,D=(w[1]+L[1])/2,$=Math.sqrt(Math.pow(L[0]-O,2)+Math.pow(L[1]-D,2))>L0/c;return{point:[O,D],visible:$}})),r.$$.dirty[0]&40&&e(9,s=Ps(i.bounds,On/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,v,x,S,R,C,I,F,U,P,T]}class N0 extends me{constructor(t){super(),pe(this,t,D0,M0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Dc=(r,t,e)=>{const[i,n]=r,[s,o]=t,a=Math.cos(e),l=Math.sin(e),h=i-s,c=n-o;return[s+h*a-c*l,o+h*l+c*a]},F0=(r,t,e,i,n=0)=>{const s=[[r,t],[r+e,t],[r+e,t+i],[r,t+i]],o=[r+e/2,t+i/2];return s.map(a=>Dc(a,o,n))},Nc=(r,t)=>{const{x:e,y:i,w:n,h:s,rot:o=0}=r,a=[e+n/2,i+s/2];let l=[e+n/2,i-t];return Dc(l,a,o)},k0=(r,t,e)=>{const i=Math.cos(e),n=Math.sin(e);return[r*i+t*n,-r*n+t*i]},U0=(r,t,e)=>{const i=r[0]-e[0],n=r[1]-e[1],s=Math.atan2(n,i),o=t[0]-e[0],a=t[1]-e[1];return Math.atan2(a,o)-s},G0=(r,t=10)=>{const e=t*Math.PI/180;return Math.round(r/e)*e};function $0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R,C,I,M,F,U,P,T,w,A,L,O,D,$,B,N,k,V,j,st,H,at,X,gt,lt,ft,ct,Et,te,Gt,Me,Rr,zt,Li,we,Di,Ee,Ni,Te,Z,Fi,ms;return R=new ci({props:{class:"a9s-rotation-handle",x:r[7][0],y:r[7][1],scale:r[3]}}),R.$on("pointerdown",function(){kt(r[16]("ROTATION"))&&r[16]("ROTATION").apply(this,arguments)}),zt=new ci({props:{class:"a9s-corner-handle-topleft",x:r[6][0][0],y:r[6][0][1],scale:r[3]}}),zt.$on("pointerdown",function(){kt(r[16]("TOP_LEFT"))&&r[16]("TOP_LEFT").apply(this,arguments)}),we=new ci({props:{class:"a9s-corner-handle-topright",x:r[6][1][0],y:r[6][1][1],scale:r[3]}}),we.$on("pointerdown",function(){kt(r[16]("TOP_RIGHT"))&&r[16]("TOP_RIGHT").apply(this,arguments)}),Ee=new ci({props:{class:"a9s-corner-handle-bottomright",x:r[6][2][0],y:r[6][2][1],scale:r[3]}}),Ee.$on("pointerdown",function(){kt(r[16]("BOTTOM_RIGHT"))&&r[16]("BOTTOM_RIGHT").apply(this,arguments)}),Te=new ci({props:{class:"a9s-corner-handle-bottomleft",x:r[6][3][0],y:r[6][3][1],scale:r[3]}}),Te.$on("pointerdown",function(){kt(r[16]("BOTTOM_LEFT"))&&r[16]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("polygon"),c=Se(),u=Y("g"),d=Y("line"),_=Y("line"),ee(R.$$.fragment),C=Se(),I=Y("g"),M=Y("polygon"),U=Y("polygon"),T=Se(),w=Y("line"),$=Se(),B=Y("line"),st=Se(),H=Y("line"),ft=Se(),ct=Y("line"),Rr=Se(),ee(zt.$$.fragment),Li=Se(),ee(we.$$.fragment),Di=Se(),ee(Ee.$$.fragment),Ni=Se(),ee(Te.$$.fragment),b(i,"class","rect-mask-bg svelte-1bwhzbc"),b(i,"x",n=r[5].x),b(i,"y",s=r[5].y),b(i,"width",o=r[5].w),b(i,"height",a=r[5].h),b(l,"class","rect-mask-fg svelte-1bwhzbc"),b(l,"points",h=r[6].map(Fc).join(" ")),b(e,"id",r[9]),b(e,"class","a9s-rectangle-editor-mask svelte-1bwhzbc"),b(d,"class","a9s-rotation-handle-line-bg"),b(d,"x1",f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),b(d,"y1",p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),b(d,"x2",g=r[7][0]),b(d,"y2",y=r[7][1]),b(d,"pointer-events","none"),b(_,"class","a9s-rotation-handle-line-fg"),b(_,"x1",v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),b(_,"y1",m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),b(_,"x2",x=r[7][0]),b(_,"y2",S=r[7][1]),b(_,"pointer-events","none"),b(u,"class","a9s-rotation-handle-group"),b(M,"class","a9s-outer"),b(M,"mask",`url(#${r[9]})`),b(M,"points",F=r[6].map(kc).join(" ")),b(U,"class","a9s-inner a9s-shape-handle"),b(U,"style",r[1]),b(U,"points",P=r[6].map(Uc).join(" ")),b(w,"class","a9s-edge-handle a9s-edge-handle-top"),b(w,"x1",A=r[6][0][0]),b(w,"y1",L=r[6][0][1]),b(w,"x2",O=r[6][1][0]),b(w,"y2",D=r[6][1][1]),b(B,"class","a9s-edge-handle a9s-edge-handle-right"),b(B,"x1",N=r[6][1][0]),b(B,"y1",k=r[6][1][1]),b(B,"x2",V=r[6][2][0]),b(B,"y2",j=r[6][2][1]),b(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),b(H,"x1",at=r[6][2][0]),b(H,"y1",X=r[6][2][1]),b(H,"x2",gt=r[6][3][0]),b(H,"y2",lt=r[6][3][1]),b(ct,"class","a9s-edge-handle a9s-edge-handle-left"),b(ct,"x1",Et=r[6][3][0]),b(ct,"y1",te=r[6][3][1]),b(ct,"x2",Gt=r[6][0][0]),b(ct,"y2",Me=r[6][0][1])},m(z,G){rt(z,t,G),bt(t,e),bt(e,i),bt(e,l),rt(z,c,G),rt(z,u,G),bt(u,d),bt(u,_),Zt(R,u,null),rt(z,C,G),rt(z,I,G),bt(I,M),bt(I,U),rt(z,T,G),rt(z,w,G),rt(z,$,G),rt(z,B,G),rt(z,st,G),rt(z,H,G),rt(z,ft,G),rt(z,ct,G),rt(z,Rr,G),Zt(zt,z,G),rt(z,Li,G),Zt(we,z,G),rt(z,Di,G),Zt(Ee,z,G),rt(z,Ni,G),Zt(Te,z,G),Z=!0,Fi||(ms=[Ct(M,"pointerdown",function(){kt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Ct(U,"pointerdown",function(){kt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Ct(w,"pointerdown",function(){kt(r[16]("TOP"))&&r[16]("TOP").apply(this,arguments)}),Ct(B,"pointerdown",function(){kt(r[16]("RIGHT"))&&r[16]("RIGHT").apply(this,arguments)}),Ct(H,"pointerdown",function(){kt(r[16]("BOTTOM"))&&r[16]("BOTTOM").apply(this,arguments)}),Ct(ct,"pointerdown",function(){kt(r[16]("LEFT"))&&r[16]("LEFT").apply(this,arguments)})],Fi=!0)},p(z,G){r=z,(!Z||G&32&&n!==(n=r[5].x))&&b(i,"x",n),(!Z||G&32&&s!==(s=r[5].y))&&b(i,"y",s),(!Z||G&32&&o!==(o=r[5].w))&&b(i,"width",o),(!Z||G&32&&a!==(a=r[5].h))&&b(i,"height",a),(!Z||G&64&&h!==(h=r[6].map(Fc).join(" ")))&&b(l,"points",h),(!Z||G&64&&f!==(f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&b(d,"x1",f),(!Z||G&64&&p!==(p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&b(d,"y1",p),(!Z||G&128&&g!==(g=r[7][0]))&&b(d,"x2",g),(!Z||G&128&&y!==(y=r[7][1]))&&b(d,"y2",y),(!Z||G&64&&v!==(v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&b(_,"x1",v),(!Z||G&64&&m!==(m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&b(_,"y1",m),(!Z||G&128&&x!==(x=r[7][0]))&&b(_,"x2",x),(!Z||G&128&&S!==(S=r[7][1]))&&b(_,"y2",S);const Mr={};G&128&&(Mr.x=r[7][0]),G&128&&(Mr.y=r[7][1]),G&8&&(Mr.scale=r[3]),R.$set(Mr),(!Z||G&64&&F!==(F=r[6].map(kc).join(" ")))&&b(M,"points",F),(!Z||G&2)&&b(U,"style",r[1]),(!Z||G&64&&P!==(P=r[6].map(Uc).join(" ")))&&b(U,"points",P),(!Z||G&64&&A!==(A=r[6][0][0]))&&b(w,"x1",A),(!Z||G&64&&L!==(L=r[6][0][1]))&&b(w,"y1",L),(!Z||G&64&&O!==(O=r[6][1][0]))&&b(w,"x2",O),(!Z||G&64&&D!==(D=r[6][1][1]))&&b(w,"y2",D),(!Z||G&64&&N!==(N=r[6][1][0]))&&b(B,"x1",N),(!Z||G&64&&k!==(k=r[6][1][1]))&&b(B,"y1",k),(!Z||G&64&&V!==(V=r[6][2][0]))&&b(B,"x2",V),(!Z||G&64&&j!==(j=r[6][2][1]))&&b(B,"y2",j),(!Z||G&64&&at!==(at=r[6][2][0]))&&b(H,"x1",at),(!Z||G&64&&X!==(X=r[6][2][1]))&&b(H,"y1",X),(!Z||G&64&&gt!==(gt=r[6][3][0]))&&b(H,"x2",gt),(!Z||G&64&&lt!==(lt=r[6][3][1]))&&b(H,"y2",lt),(!Z||G&64&&Et!==(Et=r[6][3][0]))&&b(ct,"x1",Et),(!Z||G&64&&te!==(te=r[6][3][1]))&&b(ct,"y1",te),(!Z||G&64&&Gt!==(Gt=r[6][0][0]))&&b(ct,"x2",Gt),(!Z||G&64&&Me!==(Me=r[6][0][1]))&&b(ct,"y2",Me);const Or={};G&64&&(Or.x=r[6][0][0]),G&64&&(Or.y=r[6][0][1]),G&8&&(Or.scale=r[3]),zt.$set(Or);const Br={};G&64&&(Br.x=r[6][1][0]),G&64&&(Br.y=r[6][1][1]),G&8&&(Br.scale=r[3]),we.$set(Br);const Lr={};G&64&&(Lr.x=r[6][2][0]),G&64&&(Lr.y=r[6][2][1]),G&8&&(Lr.scale=r[3]),Ee.$set(Lr);const Dr={};G&64&&(Dr.x=r[6][3][0]),G&64&&(Dr.y=r[6][3][1]),G&8&&(Dr.scale=r[3]),Te.$set(Dr)},i(z){Z||(ht(R.$$.fragment,z),ht(zt.$$.fragment,z),ht(we.$$.fragment,z),ht(Ee.$$.fragment,z),ht(Te.$$.fragment,z),Z=!0)},o(z){yt(R.$$.fragment,z),yt(zt.$$.fragment,z),yt(we.$$.fragment,z),yt(Ee.$$.fragment,z),yt(Te.$$.fragment,z),Z=!1},d(z){z&&(et(t),et(c),et(u),et(C),et(I),et(T),et(w),et($),et(B),et(st),et(H),et(ft),et(ct),et(Rr),et(Li),et(Di),et(Ni)),Jt(R),Jt(zt,z),Jt(we,z),Jt(Ee,z),Jt(Te,z),Fi=!1,De(ms)}}}function H0(r){let t,e;return t=new ya({props:{shape:r[0],transform:r[2],editor:r[8],svgEl:r[4],$$slots:{default:[$0,({grab:i})=>({16:i}),({grab:i})=>i?65536:0]},$$scope:{ctx:r}}}),t.$on("grab",r[12]),t.$on("change",r[13]),t.$on("release",r[14]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&196842&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const Fc=r=>`${r[0]},${r[1]}`,kc=r=>`${r[0]},${r[1]}`,Uc=r=>`${r[0]},${r[1]}`;function V0(r,t,e){let i,n,s,o,a,{shape:l}=t,{computedStyle:h}=t,{transform:c}=t,{viewportScale:u=1}=t,{svgEl:d}=t,f=!1;const p=(m,x,S)=>{let{x:R,y:C,w:I,h:M,rot:F=0}=m.geometry;const[U,P]=S;if(x==="ROTATION"){const w=Nc(m.geometry,i),A=w[0]+U,L=w[1]+P,O=[R+I/2,C+M/2];F+=U0([w[0],w[1]],[A,L],O),f&&(F=G0(F));const D=2*Math.PI;F=(F%D+D)%D}else if(x==="SHAPE")R+=U,C+=P;else{let w=0,A=0,L=I,O=M;const[D,$]=F!==0?k0(U,P,F):[U,P];switch(x){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":A+=$;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":O+=$;break}switch(x){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":w+=D;break;case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":L+=D;break}const B=(w+L)/2,N=(A+O)/2;I=Math.abs(L-w),M=Math.abs(O-A);const k=[R+m.geometry.w/2,C+m.geometry.h/2],V=[B-m.geometry.w/2,N-m.geometry.h/2],j=Math.cos(F),st=Math.sin(F),H=k[0]+V[0]*j-V[1]*st,at=k[1]+V[0]*st+V[1]*j;R=H-I/2,C=at-M/2}const T=ge(s);return{...m,geometry:{x:R,y:C,w:I,h:M,rot:F,bounds:T}}};Fr(()=>{const m=S=>{S.key==="Shift"&&(f=!0)},x=S=>{S.key==="Shift"&&(f=!1)};return window.addEventListener("keydown",m),window.addEventListener("keyup",x),()=>{window.removeEventListener("keydown",m),window.removeEventListener("keyup",x)}});const g=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function y(m){oe.call(this,r,m)}function _(m){oe.call(this,r,m)}function v(m){oe.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,l=m.shape),"computedStyle"in m&&e(1,h=m.computedStyle),"transform"in m&&e(2,c=m.transform),"viewportScale"in m&&e(3,u=m.viewportScale),"svgEl"in m&&e(4,d=m.svgEl)},r.$$.update=()=>{r.$$.dirty&8&&e(11,i=20/u),r.$$.dirty&1&&e(10,n=l.geometry),r.$$.dirty&1024&&e(6,s=F0(n.x,n.y,n.w,n.h,n.rot)),r.$$.dirty&3072&&e(7,o=Nc(n,i)),r.$$.dirty&1032&&e(5,a=Ps(n.bounds,5/u))},[l,h,c,u,d,a,s,o,p,g,n,i,y,_,v]}class X0 extends me{constructor(t){super(),pe(this,t,V0,H0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Gc=Object.prototype.hasOwnProperty;function xa(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--&&xa(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Gc.call(r,e)&&++i&&!Gc.call(t,e)||!(e in t)||!xa(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const j0=12,W0=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,g=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>j0/t;return{point:[f,p],visible:g,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function wa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function $c(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Hc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Vc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Ea(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ta(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Xc(r){let t,e,i,n;return{c(){t=Y("circle"),b(t,"cx",e=r[29][0]),b(t,"cy",i=r[29][1]),b(t,"r",n=Bn/r[3]),b(t,"class","svelte-1vxo6dc")},m(s,o){rt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&b(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&b(t,"cy",i),o[0]&8&&n!==(n=Bn/s[3])&&b(t,"r",n)},d(s){s&&et(t)}}}function jc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=Y("mask"),e=Y("rect"),a=Y("circle"),b(e,"x",i=r[9].x),b(e,"y",n=r[9].y),b(e,"width",s=r[9].w),b(e,"height",o=r[9].h),b(e,"class","svelte-1vxo6dc"),b(a,"cx",l=r[29][0]),b(a,"cy",h=r[29][1]),b(a,"r",c=Bn/r[3]),b(a,"class","svelte-1vxo6dc"),b(t,"id",`${r[18]}-${r[32]}-inner`),b(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){rt(u,t,d),bt(t,e),bt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&b(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&b(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&b(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&b(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&b(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&b(a,"cy",h),d[0]&8&&c!==(c=Bn/u[3])&&b(a,"r",c)},d(u){u&&et(t)}}}function Wc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new ci({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){kt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){ee(t.$$.fragment)},m(n,s){Zt(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(ht(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){Jt(t,n)}}}function Yc(r){let t,e,i=Oe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Wc(Vc(r,i,o));const s=o=>yt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Ne()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Oe(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Vc(o,i,l);n[l]?(n[l].p(h,a),ht(n[l],1)):(n[l]=Wc(h),n[l].c(),ht(n[l],1),n[l].m(t.parentNode,t))}for(Ce(),l=i.length;l<n.length;l+=1)s(l);Ie()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ht(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&et(t),ai(n,o)}}}function zc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v=r[6]!==void 0&&!r[7]&&Xc(Ta(r)),m=r[6]!==void 0&&!r[7]&&jc(Ea(r)),x=Oe(r[30].rings),S=[];for(let C=0;C<x.length;C+=1)S[C]=Yc(Hc(r,x,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=Y("g"),e=Y("defs"),i=Y("mask"),n=Y("rect"),h=Y("path"),v&&v.c(),m&&m.c(),u=Y("path"),f=Y("path");for(let C=0;C<S.length;C+=1)S[C].c();b(n,"x",s=r[9].x),b(n,"y",o=r[9].y),b(n,"width",a=r[9].w),b(n,"height",l=r[9].h),b(n,"class","svelte-1vxo6dc"),b(h,"d",c=je(r[30])),b(h,"class","svelte-1vxo6dc"),b(i,"id",`${r[18]}-${r[32]}-outer`),b(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),b(u,"class","a9s-outer"),b(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),b(u,"fill-rule","evenodd"),b(u,"d",d=je(r[30])),b(f,"class","a9s-inner"),b(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),b(f,"style",r[1]),b(f,"fill-rule","evenodd"),b(f,"d",p=je(r[30]))},m(C,I){rt(C,t,I),bt(t,e),bt(e,i),bt(i,n),bt(i,h),v&&v.m(i,null),m&&m.m(e,null),bt(t,u),bt(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);g=!0,y||(_=[Ct(u,"pointerup",r[13]),Ct(u,"pointerdown",function(){kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Ct(f,"pointerup",r[13]),Ct(f,"pointerdown",function(){kt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!g||I[0]&512&&s!==(s=r[9].x))&&b(n,"x",s),(!g||I[0]&512&&o!==(o=r[9].y))&&b(n,"y",o),(!g||I[0]&512&&a!==(a=r[9].w))&&b(n,"width",a),(!g||I[0]&512&&l!==(l=r[9].h))&&b(n,"height",l),(!g||I[0]&32&&c!==(c=je(r[30])))&&b(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Ta(r),I):(v=Xc(Ta(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?m?m.p(Ea(r),I):(m=jc(Ea(r)),m.c(),m.m(e,null)):m&&(m.d(1),m=null),(!g||I[0]&32&&d!==(d=je(r[30])))&&b(u,"d",d),(!g||I[0]&2)&&b(f,"style",r[1]),(!g||I[0]&32&&p!==(p=je(r[30])))&&b(f,"d",p),I[0]&268491048){x=Oe(r[30].rings);let M;for(M=0;M<x.length;M+=1){const F=Hc(r,x,M);S[M]?(S[M].p(F,I),ht(S[M],1)):(S[M]=Yc(F),S[M].c(),ht(S[M],1),S[M].m(t,null))}for(Ce(),M=x.length;M<S.length;M+=1)R(M);Ie()}},i(C){if(!g){for(let I=0;I<x.length;I+=1)ht(S[I]);g=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)yt(S[I]);g=!1},d(C){C&&et(t),v&&v.d(),m&&m.d(),ai(S,C),y=!1,De(_)}}}function qc(r){let t,e;return t=new Sc({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){kt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function Y0(r){let t,e,i,n=Oe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=zc($c(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&qc(wa(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Se(),a&&a.c(),e=Ne()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);rt(l,t,h),a&&a.m(l,h),rt(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Oe(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=$c(l,n,c);s[c]?(s[c].p(u,h),ht(s[c],1)):(s[c]=zc(u),s[c].c(),ht(s[c],1),s[c].m(t.parentNode,t))}for(Ce(),c=n.length;c<s.length;c+=1)o(c);Ie()}l[6]!==void 0&&!l[7]?a?(a.p(wa(l),h),h[0]&192&&ht(a,1)):(a=qc(wa(l)),a.c(),ht(a,1),a.m(e.parentNode,e)):a&&(Ce(),yt(a,1,1,()=>{a=null}),Ie())},i(l){if(!i){for(let h=0;h<n.length;h+=1)ht(s[h]);ht(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)yt(s[h]);yt(a),i=!1},d(l){l&&(et(t),et(e)),ai(s,l),a&&a.d(l)}}}function z0(r){let t,e;return t=new ya({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Y0,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}const q0=250,K0=1e3,Bn=4.5;function Z0(r,t,e){let i,n,s;const o=kr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(g.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[L,O]=h.elementToImage(A.offsetX,A.offsetY),D=k=>Math.pow(k[0]-L,2)+Math.pow(k[1]-O,2),$=ay(i).reduce((k,V)=>D(V)<D(k)?V:k),B=n.filter(k=>k.visible).reduce((k,V)=>D(V.point)<D(k.point)?V:k),N=Math.pow(K0/c,2);D($)<N||D(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,L,O)=>D=>{if(!p||Fe||performance.now()-p>q0)return;const $=N=>N.polygon===A&&N.ring===L&&N.point===O,B=g.some($);D.metaKey||D.ctrlKey||D.shiftKey?B?e(8,g=g.filter(N=>!$(N))):e(8,g=[...g,{polygon:A,ring:L,point:O}]):B&&g.length>1?e(8,g=[{polygon:A,ring:L,point:O}]):B?e(8,g=[]):e(8,g=[{polygon:A,ring:L,point:O}]),m()},C=(A,L,O)=>{m();const D=A.geometry.polygons;let $;if(L==="SHAPE")$=D.map(B=>{const N=B.rings.map((V,j)=>({points:V.points.map((st,H)=>[st[0]+O[0],st[1]+O[1]])})),k=ge(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,V]=L.split("-").map(j=>parseInt(j));$=D.map((j,st)=>{if(st===N){const H=j.rings.map((X,gt)=>gt===k?{points:X.points.map((lt,ft)=>ft===V?[lt[0]+O[0],lt[1]+O[1]]:lt)}:X),at=ge(H[0].points);return{rings:H,bounds:at}}else return j})}return{...A,geometry:{polygons:$,bounds:ua($)}}},I=A=>async L=>{L.stopPropagation();const O=n[A],D=i.polygons.map((B,N)=>{if(N===O.elementIdx){const k=B.rings.map((j,st)=>st===O.ringIdx?{points:[...j.points.slice(0,O.pointIdx+1),O.point,...j.points.slice(O.pointIdx+1)]}:j),V=ge(k[0].points);return{rings:k,bounds:V}}else return B});o("change",{...a,geometry:{polygons:D,bounds:ua(D)}}),await dc();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((L,O)=>{if(g.some(D=>D.polygon===O)){const D=L.rings.map((B,N)=>{const k=g.filter(V=>V.polygon===O&&V.ring===N);return k.length&&B.points.length-k.length>=3?{points:B.points.filter((V,j)=>!k.some(st=>st.point===j))}:B}),$=ge(D[0].points);return{rings:D,bounds:$}}else return L});!xa(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:ua(A)}}),e(8,g=[]))};Fr(()=>{if(Fe)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,O,{polygon:D,ring:$,point:B})=>D===A&&$===L&&B===O;function P(A){oe.call(this,r,A)}function T(A){oe.call(this,r,A)}function w(A){oe.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Fe?[]:W0(i,c)),r.$$.dirty[0]&40&&e(9,s=Ps(i.bounds,Bn/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,x,S,R,C,I,F,U,P,T,w]}class J0 extends me{constructor(t){super(),pe(this,t,Z0,z0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Kc=new Map([[_t.RECTANGLE,X0],[_t.POLYGON,N0],[_t.MULTIPOLYGON,J0]]),Aa=r=>Kc.get(r.type),Zc=(r,t)=>Kc.set(r,t);function Q0(r,t,e){let i;const n=kr();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return Fr(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=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=hi(s,a,{selected:!0,hovered:!0})),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.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})},[s,o,a,l,h,c,u,i]}class t_ extends me{constructor(t){super(),pe(this,t,Q0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function e_(r,t,e){const i=kr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return Fr(()=>{const c=s.closest("svg"),u=[],d=(f,p,g)=>{c==null||c.addEventListener(f,p,g),u.push(()=>c==null?void 0:c.removeEventListener(f,p,g))};return e(5,h=new o({target:s,props:{addEventListener:d,drawingMode:n,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,n=c.drawingMode),"target"in c&&e(1,s=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})},[n,s,o,a,l,h]}class r_ extends me{constructor(t){super(),pe(this,t,e_,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Jc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("rect"),h=Y("rect"),c=Y("rect"),b(i,"class","rect-mask-bg svelte-1a76qe7"),b(i,"x",n=r[1]-r[5]),b(i,"y",s=r[2]-r[5]),b(i,"width",o=r[3]+2*r[5]),b(i,"height",a=r[4]+2*r[5]),b(l,"class","rect-mask-fg svelte-1a76qe7"),b(l,"x",r[1]),b(l,"y",r[2]),b(l,"width",r[3]),b(l,"height",r[4]),b(e,"id",r[6]),b(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),b(h,"class","a9s-outer"),b(h,"mask",`url(#${r[6]})`),b(h,"x",r[1]),b(h,"y",r[2]),b(h,"width",r[3]),b(h,"height",r[4]),b(c,"class","a9s-inner"),b(c,"x",r[1]),b(c,"y",r[2]),b(c,"width",r[3]),b(c,"height",r[4])},m(u,d){rt(u,t,d),bt(t,e),bt(e,i),bt(e,l),rt(u,h,d),rt(u,c,d)},p(u,d){d&34&&n!==(n=u[1]-u[5])&&b(i,"x",n),d&36&&s!==(s=u[2]-u[5])&&b(i,"y",s),d&40&&o!==(o=u[3]+2*u[5])&&b(i,"width",o),d&48&&a!==(a=u[4]+2*u[5])&&b(i,"height",a),d&2&&b(l,"x",u[1]),d&4&&b(l,"y",u[2]),d&8&&b(l,"width",u[3]),d&16&&b(l,"height",u[4]),d&2&&b(h,"x",u[1]),d&4&&b(h,"y",u[2]),d&8&&b(h,"width",u[3]),d&16&&b(h,"height",u[4]),d&2&&b(c,"x",u[1]),d&4&&b(c,"y",u[2]),d&8&&b(c,"width",u[3]),d&16&&b(c,"height",u[4])},d(u){u&&(et(t),et(h),et(c))}}}function i_(r){let t,e=r[0]&&Jc(r);return{c(){t=Y("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Jc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&et(t),e&&e.d()}}}function n_(r,t,e){let i;const n=kr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,f,p,g;const y=S=>{const R=S;h=performance.now(),o==="drag"&&(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,f=c[1]),e(3,p=1),e(4,g=1))},_=S=>{const R=S;c&&(u=a.elementToImage(R.offsetX,R.offsetY),e(1,d=Math.min(u[0],c[0])),e(2,f=Math.min(u[1],c[1])),e(3,p=Math.abs(u[0]-c[0])),e(4,g=Math.abs(u[1]-c[1])))},v=S=>{const R=S,C=performance.now()-h;if(o==="click"){if(C>300)return;c?m():(e(0,c=a.elementToImage(R.offsetX,R.offsetY)),u=c,e(1,d=c[0]),e(2,f=c[1]),e(3,p=1),e(4,g=1))}else c&&(C>300||p*g>100?(R.stopPropagation(),m()):(e(0,c=void 0),u=void 0))},m=()=>{if(p*g>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+g},rot:0,x:d,y:f,w:p,h:g}};n("create",S)}e(0,c=void 0),u=void 0};Fr(()=>{s("pointerdown",y),s("pointermove",_),s("pointerup",v,!0)});const x=`rect-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=S=>{"addEventListener"in S&&e(7,s=S.addEventListener),"drawingMode"in S&&e(8,o=S.drawingMode),"transform"in S&&e(9,a=S.transform),"viewportScale"in S&&e(10,l=S.viewportScale)},r.$$.update=()=>{r.$$.dirty&1024&&e(5,i=2/l)},[c,d,f,p,g,i,x,s,o,a,l]}class s_ extends me{constructor(t){super(),pe(this,t,n_,i_,Kt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function Sa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function Qc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g=r[1]&&tu(r);return{c(){t=Y("defs"),e=Y("mask"),i=Y("rect"),l=Y("polygon"),c=Y("polygon"),d=Y("polygon"),g&&g.c(),p=Ne(),b(i,"x",n=r[3].x),b(i,"y",s=r[3].y),b(i,"width",o=r[3].w),b(i,"height",a=r[3].h),b(i,"class","svelte-18wrg3t"),b(l,"points",h=r[19]),b(l,"class","svelte-18wrg3t"),b(e,"id",r[5]),b(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),b(c,"class","a9s-outer"),b(c,"mask",`url(#${r[5]})`),b(c,"points",u=r[19]),b(d,"class","a9s-inner"),b(d,"points",f=r[19])},m(y,_){rt(y,t,_),bt(t,e),bt(e,i),bt(e,l),rt(y,c,_),rt(y,d,_),g&&g.m(y,_),rt(y,p,_)},p(y,_){_&8&&n!==(n=y[3].x)&&b(i,"x",n),_&8&&s!==(s=y[3].y)&&b(i,"y",s),_&8&&o!==(o=y[3].w)&&b(i,"width",o),_&8&&a!==(a=y[3].h)&&b(i,"height",a),_&4&&h!==(h=y[19])&&b(l,"points",h),_&4&&u!==(u=y[19])&&b(c,"points",u),_&4&&f!==(f=y[19])&&b(d,"points",f),y[1]?g?g.p(y,_):(g=tu(y),g.c(),g.m(p.parentNode,p)):g&&(g.d(1),g=null)},d(y){y&&(et(t),et(c),et(d),et(p)),g&&g.d(y)}}}function tu(r){let t,e,i;return{c(){t=Y("circle"),b(t,"class","a9s-handle svelte-18wrg3t"),b(t,"cx",e=r[0][0][0]),b(t,"cy",i=r[0][0][1]),b(t,"r",r[4])},m(n,s){rt(n,t,s)},p(n,s){s&1&&e!==(e=n[0][0][0])&&b(t,"cx",e),s&1&&i!==(i=n[0][0][1])&&b(t,"cy",i),s&16&&b(t,"r",n[4])},d(n){n&&et(t)}}}function o_(r){let t,e=r[3]&&Qc(Sa(r));return{c(){t=Y("g"),e&&e.c(),b(t,"class","a9s-annotation a9s-rubberband")},m(i,n){rt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(Sa(i),n):(e=Qc(Sa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&et(t),e&&e.d()}}}const a_=20,l_=1500;function h_(r,t,e){let i,n,s;const o=kr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],f,p,g=!1;const y=R=>{const C=R,{timeStamp:I,offsetX:M,offsetY:F}=C;if(u={timeStamp:I,offsetX:M,offsetY:F},l==="drag"&&d.length===0){const U=h.elementToImage(C.offsetX,C.offsetY);d.push(U),e(10,f=U)}},_=R=>{const C=R;if(p&&clearTimeout(p),d.length>0){if(e(10,f=h.elementToImage(C.offsetX,C.offsetY)),d.length>2){const I=As(f,d[0])*c;e(1,g=I<a_)}C.pointerType==="touch"&&(p=setTimeout(()=>{m()},l_))}},v=R=>{const C=R;if(p&&clearTimeout(p),l==="click"){const I=C.timeStamp-u.timeStamp,M=As([u.offsetX,u.offsetY],[C.offsetX,C.offsetY]);if(I>300||M>15)return;if(g)x();else if(d.length===0){const F=h.elementToImage(C.offsetX,C.offsetY);d.push(F),e(10,f=F)}else f&&d.push(f)}else{if(!f)return;if(d.length===1&&As(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}C.stopImmediatePropagation(),g?x():d.push(f)}},m=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:ge(d),points:R}};ca(C)>4&&(e(0,d=[]),e(10,f=void 0),o("create",C))},x=()=>{const R={type:_t.POLYGON,geometry:{bounds:ge(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};Fr(()=>{a("pointerdown",y,!0),a("pointermove",_),a("pointerup",v,!0),a("dblclick",m,!0)});const S=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;return r.$$set=R=>{"addEventListener"in R&&e(6,a=R.addEventListener),"drawingMode"in R&&e(7,l=R.drawingMode),"transform"in R&&e(8,h=R.transform),"viewportScale"in R&&e(9,c=R.viewportScale)},r.$$.update=()=>{r.$$.dirty&512&&e(4,i=4/c),r.$$.dirty&1027&&e(2,n=f?g?d:[...d,f]:[]),r.$$.dirty&516&&e(3,s=n.length>0?Ps(ge(n),2/c):void 0)},[d,g,n,s,i,S,a,l,h,c,f]}class c_ extends me{constructor(t){super(),pe(this,t,h_,o_,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const Ca=new Map([["rectangle",{tool:s_}],["polygon",{tool:c_}]]),Rs=()=>[...Ca.keys()],Ms=r=>Ca.get(r),eu=(r,t,e={})=>Ca.set(r,{tool:t,opts:e});function u_(r){let t,e,i,n,s;return{c(){t=Y("g"),e=Y("ellipse"),n=Y("ellipse"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"cx",r[2]),b(e,"cy",r[3]),b(e,"rx",r[4]),b(e,"ry",r[5]),b(n,"class","a9s-inner"),b(n,"style",r[1]),b(n,"cx",r[2]),b(n,"cy",r[3]),b(n,"rx",r[4]),b(n,"ry",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&b(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&et(t)}}}function d_(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{cx:a,cy:l,rx:h,ry:c}=s;return r.$$set=u=>{"annotation"in u&&e(0,n=u.annotation),"geom"in u&&e(6,s=u.geom),"style"in u&&e(7,o=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=hi(n,o))},[n,i,a,l,h,c,s,o]}class f_ extends me{constructor(t){super(),pe(this,t,d_,u_,Kt,{annotation:0,geom:6,style:7})}}function p_(r){let t,e,i,n,s;return{c(){t=Y("g"),e=Y("line"),n=Y("line"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"x1",r[2]),b(e,"y1",r[3]),b(e,"x2",r[4]),b(e,"y2",r[5]),b(n,"class","a9s-inner"),b(n,"style",r[1]),b(n,"x1",r[2]),b(n,"y1",r[3]),b(n,"x2",r[4]),b(n,"y2",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&b(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&et(t)}}}function m_(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s,[[l,h],[c,u]]=a;return r.$$set=d=>{"annotation"in d&&e(0,n=d.annotation),"geom"in d&&e(6,s=d.geom),"style"in d&&e(7,o=d.style)},r.$$.update=()=>{r.$$.dirty&129&&e(1,i=hi(n,o))},[n,i,l,h,c,u,s,o]}class g_ extends me{constructor(t){super(),pe(this,t,m_,p_,Kt,{annotation:0,geom:6,style:7})}}function ru(r,t,e){const i=r.slice();return i[5]=t[e],i}function iu(r){let t,e,i;return{c(){t=Y("path"),i=Y("path"),b(t,"class","a9s-outer"),b(t,"style",e=r[1]?"display:none;":void 0),b(t,"fill-rule","evenodd"),b(t,"d",je(r[5])),b(i,"class","a9s-inner"),b(i,"style",r[1]),b(i,"fill-rule","evenodd"),b(i,"d",je(r[5]))},m(n,s){rt(n,t,s),rt(n,i,s)},p(n,s){s&2&&e!==(e=n[1]?"display:none;":void 0)&&b(t,"style",e),s&2&&b(i,"style",n[1])},d(n){n&&(et(t),et(i))}}}function y_(r){let t,e,i=Oe(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=iu(ru(r,i,s));return{c(){t=Y("g");for(let s=0;s<n.length;s+=1)n[s].c();b(t,"class","a9s-annotation"),b(t,"data-id",e=r[0].id)},m(s,o){rt(s,t,o);for(let a=0;a<n.length;a+=1)n[a]&&n[a].m(t,null)},p(s,[o]){if(o&6){i=Oe(s[2]);let a;for(a=0;a<i.length;a+=1){const l=ru(s,i,a);n[a]?n[a].p(l,o):(n[a]=iu(l),n[a].c(),n[a].m(t,null))}for(;a<n.length;a+=1)n[a].d(1);n.length=i.length}o&1&&e!==(e=s[0].id)&&b(t,"data-id",e)},i:Rt,o:Rt,d(s){s&&et(t),ai(n,s)}}}function __(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{polygons:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=hi(n,o))},[n,i,a,s,o]}class v_ extends me{constructor(t){super(),pe(this,t,__,y_,Kt,{annotation:0,geom:3,style:4})}}function b_(r){let t,e,i,n,s;return{c(){t=Y("g"),e=Y("polygon"),n=Y("polygon"),b(e,"class","a9s-outer"),b(e,"style",i=r[1]?"display:none;":void 0),b(e,"points",r[2].map(x_).join(" ")),b(n,"class","a9s-inner"),b(n,"style",r[1]),b(n,"points",r[2].map(w_).join(" ")),b(t,"class","a9s-annotation"),b(t,"data-id",s=r[0].id)},m(o,a){rt(o,t,a),bt(t,e),bt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&b(e,"style",i),a&2&&b(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&b(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&et(t)}}}const x_=r=>r.join(","),w_=r=>r.join(",");function E_(r,t,e){let i,{annotation:n}=t,{geom:s}=t,{style:o}=t;const{points:a}=s;return r.$$set=l=>{"annotation"in l&&e(0,n=l.annotation),"geom"in l&&e(3,s=l.geom),"style"in l&&e(4,o=l.style)},r.$$.update=()=>{r.$$.dirty&17&&e(1,i=hi(n,o))},[n,i,a,s,o]}class T_ extends me{constructor(t){super(),pe(this,t,E_,b_,Kt,{annotation:0,geom:3,style:4})}}function A_(r){let t,e,i,n,s,o,a;return{c(){t=Y("g"),e=Y("path"),s=Y("path"),b(e,"class",i=ki(`a9s-outer ${r[1]}`)+" svelte-1w0132l"),b(e,"style",n=r[3]?"display:none;":void 0),b(e,"d",r[2]),b(s,"class",o=ki(`a9s-inner ${r[1]}`)+" svelte-1w0132l"),b(s,"style",r[3]),b(s,"d",r[2]),b(t,"class","a9s-annotation"),b(t,"data-id",a=r[0].id)},m(l,h){rt(l,t,h),bt(t,e),bt(t,s)},p(l,[h]){h&2&&i!==(i=ki(`a9s-outer ${l[1]}`)+" svelte-1w0132l")&&b(e,"class",i),h&8&&n!==(n=l[3]?"display:none;":void 0)&&b(e,"style",n),h&4&&b(e,"d",l[2]),h&2&&o!==(o=ki(`a9s-inner ${l[1]}`)+" svelte-1w0132l")&&b(s,"class",o),h&8&&b(s,"style",l[3]),h&4&&b(s,"d",l[2]),h&1&&a!==(a=l[0].id)&&b(t,"data-id",a)},i:Rt,o:Rt,d(l){l&&et(t)}}}function S_(r,t,e){let i,n,s,{annotation:o}=t,{geom:a}=t,{style:l}=t;return r.$$set=h=>{"annotation"in h&&e(0,o=h.annotation),"geom"in h&&e(4,a=h.geom),"style"in h&&e(5,l=h.style)},r.$$.update=()=>{r.$$.dirty&33&&e(3,i=hi(o,l)),r.$$.dirty&16&&e(2,n=fa(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class C_ extends me{constructor(t){super(),pe(this,t,S_,A_,Kt,{annotation:0,geom:4,style:5})}}function I_(r){let t,e,i,n,s,o;return{c(){t=Y("g"),e=Y("g"),i=Y("rect"),s=Y("rect"),b(i,"class","a9s-outer"),b(i,"style",n=r[6]?"display:none;":void 0),b(i,"x",r[4]),b(i,"y",r[2]),b(i,"width",r[3]),b(i,"height",r[1]),b(s,"class","a9s-inner"),b(s,"style",r[6]),b(s,"x",r[4]),b(s,"y",r[2]),b(s,"width",r[3]),b(s,"height",r[1]),b(e,"transform",r[5]),b(t,"class","a9s-annotation"),b(t,"data-id",o=r[0].id)},m(a,l){rt(a,t,l),bt(t,e),bt(e,i),bt(e,s)},p(a,[l]){l&64&&n!==(n=a[6]?"display:none;":void 0)&&b(i,"style",n),l&16&&b(i,"x",a[4]),l&4&&b(i,"y",a[2]),l&8&&b(i,"width",a[3]),l&2&&b(i,"height",a[1]),l&64&&b(s,"style",a[6]),l&16&&b(s,"x",a[4]),l&4&&b(s,"y",a[2]),l&8&&b(s,"width",a[3]),l&2&&b(s,"height",a[1]),l&32&&b(e,"transform",a[5]),l&1&&o!==(o=a[0].id)&&b(t,"data-id",o)},i:Rt,o:Rt,d(a){a&&et(t)}}}function P_(r,t,e){let i,n,s,o,a,l,h,{annotation:c}=t,{geom:u}=t,{style:d}=t;return r.$$set=f=>{"annotation"in f&&e(0,c=f.annotation),"geom"in f&&e(7,u=f.geom),"style"in f&&e(8,d=f.style)},r.$$.update=()=>{r.$$.dirty&257&&e(6,i=hi(c,d)),r.$$.dirty&128&&e(4,{x:n,y:s,w:o,h:a,rot:l}=u,n,(e(2,s),e(7,u)),(e(3,o),e(7,u)),(e(1,a),e(7,u)),(e(9,l),e(7,u))),r.$$.dirty&542&&e(5,h=(l??0)!==0?`translate(${n+o/2}, ${s+a/2}) rotate(${(l??0)*180/Math.PI}) translate(${-(n+o/2)}, ${-(s+a/2)})`:void 0)},[c,a,s,o,n,h,i,u,d,l]}class R_ extends me{constructor(t){super(),pe(this,t,P_,I_,Kt,{annotation:0,geom:7,style:8})}}const M_=r=>({elementToImage:(t,e)=>{const i=r.getBoundingClientRect(),n=r.createSVGPoint();n.x=t+i.x,n.y=e+i.y;const{x:s,y:o}=n.matrixTransform(r.getScreenCTM().inverse());return[s,o]}}),O_=250,B_=(r,t)=>{const e=kr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<O_){const{x:s,y:o}=nu(n,r),a=Fe?10:2,l=t.getAt(s,o,void 0,a);l?e("click",{originalEvent:n,annotation:l}):e("click",{originalEvent:n})}}}},nu=(r,t)=>{const e=t.createSVGPoint(),i=t.getBoundingClientRect(),n=r.clientX-i.x,s=r.clientY-i.y,{left:o,top:a}=t.getBoundingClientRect();return e.x=n+o,e.y=s+a,e.matrixTransform(t.getScreenCTM().inverse())};function su(r,t,e){const i=r.slice();return i[39]=t[e],i}function ou(r,t,e){const i=r.slice();return i[42]=t[e],i}function Ia(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function au(r){let t=r[42],e,i,n=lu(r);return{c(){n.c(),e=Ne()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&131072&&Kt(t,t=s[42])?(Ce(),yt(n,1,1,Rt),Ie(),n=lu(s),n.c(),ht(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n.d(s)}}}function L_(r){let t,e;return t=new g_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function D_(r){let t,e;return t=new C_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function N_(r){let t,e;return t=new v_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function F_(r){let t,e;return t=new T_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function k_(r){let t,e;return t=new R_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&131072&&(s.annotation=i[42]),n[0]&131072&&(s.geom=i[45].geometry),n[0]&2&&(s.style=i[1]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function U_(r){var t;let e,i;return e=new f_({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){ee(e.$$.fragment)},m(n,s){Zt(e,n,s),i=!0},p(n,s){var o;const a={};s[0]&131072&&(a.annotation=n[42]),s[0]&131072&&(a.geom=(o=n[45])==null?void 0:o.geometry),s[0]&2&&(a.style=n[1]),e.$set(a)},i(n){i||(ht(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){Jt(e,n)}}}function lu(r){let t,e,i,n;const s=[U_,k_,F_,N_,D_,L_],o=[];function a(l,h){var c,u,d,f,p,g;return((c=l[45])==null?void 0:c.type)===_t.ELLIPSE?0:((u=l[45])==null?void 0:u.type)===_t.RECTANGLE?1:((d=l[45])==null?void 0:d.type)===_t.POLYGON?2:((f=l[45])==null?void 0:f.type)===_t.MULTIPOLYGON?3:((p=l[45])==null?void 0:p.type)===_t.POLYLINE?4:((g=l[45])==null?void 0:g.type)===_t.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Ne()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ce(),yt(o[c],1,1,()=>{o[c]=null}),Ie()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),ht(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(ht(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function hu(r){let t=Ge(r[42])&&!r[10](r[42]),e,i,n=t&&au(Ia(r));return{c(){n&&n.c(),e=Ne()},m(s,o){n&&n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Ge(s[42])&&!s[10](s[42])),t?n?(n.p(Ia(s),o),o[0]&132096&&ht(n,1)):(n=au(Ia(s)),n.c(),ht(n,1),n.m(e.parentNode,e)):n&&(Ce(),yt(n,1,1,()=>{n=null}),Ie())},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n&&n.d(s)}}}function cu(r){let t,e,i,n;const s=[$_,G_],o=[];function a(l,h){return l[6]?0:l[15]&&l[0]?1:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Ne()},m(l,h){~t&&o[t].m(l,h),rt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ce(),yt(o[c],1,1,()=>{o[c]=null}),Ie()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),ht(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(ht(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&et(i),~t&&o[t].d(l)}}}function G_(r){let t=`${r[2]}-${r[7]}`,e,i,n=uu(r);return{c(){n.c(),e=Ne()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&132&&Kt(t,t=`${s[2]}-${s[7]}`)?(Ce(),yt(n,1,1,Rt),Ie(),n=uu(s),n.c(),ht(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n.d(s)}}}function $_(r){let t,e,i=Oe(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=fu(su(r,i,o));const s=o=>yt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Ne()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);rt(o,t,a),e=!0},p(o,a){if(a[0]&8659266){i=Oe(o[6]);let l;for(l=0;l<i.length;l+=1){const h=su(o,i,l);n[l]?(n[l].p(h,a),ht(n[l],1)):(n[l]=fu(h),n[l].c(),ht(n[l],1),n[l].m(t.parentNode,t))}for(Ce(),l=i.length;l<n.length;l+=1)s(l);Ie()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)ht(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)yt(n[a]);e=!1},d(o){o&&et(t),ai(n,o)}}}function uu(r){let t,e;return t=new r_({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&32768&&(s.tool=i[15]),n[0]&16384&&(s.drawingMode=i[14]),n[0]&8192&&(s.transform=i[13]),n[0]&262144&&(s.viewportScale=i[18]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function du(r){let t,e;return t=new t_({props:{target:r[8],editor:r[39].editor,annotation:r[39].annotation,style:r[1],transform:r[13],viewportScale:r[18]}}),t.$on("change",function(){kt(r[23](r[39].annotation))&&r[23](r[39].annotation).apply(this,arguments)}),{c(){ee(t.$$.fragment)},m(i,n){Zt(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&64&&(s.editor=r[39].editor),n[0]&64&&(s.annotation=r[39].annotation),n[0]&2&&(s.style=r[1]),n[0]&8192&&(s.transform=r[13]),n[0]&262144&&(s.viewportScale=r[18]),t.$set(s)},i(i){e||(ht(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){Jt(t,i)}}}function fu(r){let t=r[39].annotation.id,e,i,n=du(r);return{c(){n.c(),e=Ne()},m(s,o){n.m(s,o),rt(s,e,o),i=!0},p(s,o){o[0]&64&&Kt(t,t=s[39].annotation.id)?(Ce(),yt(n,1,1,Rt),Ie(),n=du(s),n.c(),ht(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(ht(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&et(e),n.d(s)}}}function H_(r){let t,e,i,n,s,o,a=Oe(r[17].filter(r[34])),l=[];for(let u=0;u<a.length;u+=1)l[u]=hu(ou(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&cu(r);return{c(){t=Y("svg"),e=Y("g");for(let u=0;u<l.length;u+=1)l[u].c();i=Y("g"),c&&c.c(),b(i,"class","drawing"),b(t,"role","application"),b(t,"tabindex",0),b(t,"class","a9s-annotationlayer"),ir(t,"drawing",r[15]),ir(t,"editing",r[5]),ir(t,"hidden",!r[3]),ir(t,"hover",r[16])},m(u,d){rt(u,t,d),bt(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);bt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[Ct(t,"pointerup",function(){kt(r[11])&&r[11].apply(this,arguments)}),Ct(t,"pointerdown",function(){kt(r[12])&&r[12].apply(this,arguments)}),Ct(t,"pointermove",r[24])],s=!0)},p(u,d){if(r=u,d[0]&132098){a=Oe(r[17].filter(r[34]));let f;for(f=0;f<a.length;f+=1){const p=ou(r,a,f);l[f]?(l[f].p(p,d),ht(l[f],1)):(l[f]=hu(p),l[f].c(),ht(l[f],1),l[f].m(e,null))}for(Ce(),f=a.length;f<l.length;f+=1)h(f);Ie()}r[8]?c?(c.p(r,d),d[0]&256&&ht(c,1)):(c=cu(r),c.c(),ht(c,1),c.m(i,null)):c&&(Ce(),yt(c,1,1,()=>{c=null}),Ie()),(!n||d[0]&32768)&&ir(t,"drawing",r[15]),(!n||d[0]&32)&&ir(t,"editing",r[5]),(!n||d[0]&8)&&ir(t,"hidden",!r[3]),(!n||d[0]&65536)&&ir(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)ht(l[d]);ht(c),n=!0}},o(u){l=l.filter(Boolean);for(let d=0;d<l.length;d+=1)yt(l[d]);yt(c),n=!1},d(u){u&&et(t),ai(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,De(o)}}}function V_(r,t,e){let i,n,s,o,a,l,h,c,u,d,f,p,g=Rt,y=()=>(g(),g=nc(A,X=>e(18,p=X)),A);r.$$.on_destroy.push(()=>g());let{drawingEnabled:_}=t,{image:v}=t,{preferredDrawingMode:m}=t,{state:x}=t,{style:S=void 0}=t,{toolName:R=Rs()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let T,w,A;Fr(()=>y(e(9,A=_0(v,w))));const{hover:L,selection:O,store:D}=x;sa(r,L,X=>e(16,u=X)),sa(r,O,X=>e(33,d=X)),sa(r,D,X=>e(17,f=X));let $,B;const N=X=>{$&&D.unobserve($);const gt=X.filter(({editable:lt})=>lt).map(({id:lt})=>lt);gt.length>0?(e(5,B=gt.map(lt=>D.getAnnotation(lt)).filter(lt=>lt&&Ge(lt))),$=lt=>{const{updated:ft}=lt.changes;e(5,B=ft==null?void 0:ft.map(ct=>ct.newValue))},D.observe($,{annotations:gt})):e(5,B=void 0)},k=X=>{const gt=vc(),lt={id:gt,bodies:[],target:{annotation:gt,selector:X.detail,creator:C,created:new Date}};D.addAnnotation(lt),O.setSelected(lt.id)},V=X=>gt=>{var lt;const{target:ft}=X,ct=10*60*1e3,Et=((lt=ft.creator)==null?void 0:lt.id)!==C.id||!ft.created||new Date().getTime()-ft.created.getTime()>ct;D.updateTarget({...ft,selector:gt.detail,created:Et?ft.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},j=X=>{const{x:gt,y:lt}=nu(X,w),ft=D.getAt(gt,lt,void 0,2);ft?u!==ft.id&&L.set(ft.id):L.set(void 0)},st=X=>Ge(X);function H(X){xs[X?"unshift":"push"](()=>{T=X,e(8,T)})}function at(X){xs[X?"unshift":"push"](()=>{w=X,e(4,w)})}return r.$$set=X=>{"drawingEnabled"in X&&e(0,_=X.drawingEnabled),"image"in X&&e(25,v=X.image),"preferredDrawingMode"in X&&e(26,m=X.preferredDrawingMode),"state"in X&&e(27,x=X.state),"style"in X&&e(1,S=X.style),"toolName"in X&&e(2,R=X.toolName),"user"in X&&e(28,C=X.user),"visible"in X&&e(3,I=X.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=Ms(R)||{tool:void 0,opts:void 0},i,(e(32,n),e(2,R))),r.$$.dirty[0]&67108864|r.$$.dirty[1]&2&&e(14,s=(n==null?void 0:n.drawingMode)||m),r.$$.dirty[0]&16&&e(13,o=M_(w)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=B_(w,D),a,(e(11,l),e(4,w))),r.$$.dirty[1]&4&&N(d.selected),r.$$.dirty[0]&32&&e(6,h=B?B.map(X=>({annotation:X,editor:Aa(X.target.selector)})).filter(X=>X.editor):void 0),r.$$.dirty[0]&64&&e(10,c=X=>h&&h.some(gt=>gt.annotation.id===X.id))},[_,S,R,I,w,B,h,M,T,A,c,l,a,o,s,i,u,f,p,L,O,D,k,V,j,v,m,x,C,F,U,P,n,d,st,H,at]}class X_ extends me{constructor(t){super(),pe(this,t,V_,H_,Kt,{drawingEnabled:0,image:25,preferredDrawingMode:26,state:27,style:1,toolName:2,user:28,visible:3,cancelDrawing:29,getDrawingTool:30,isDrawingEnabled:31},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[29]}get getDrawingTool(){return this.$$.ctx[30]}get isDrawingEnabled(){return this.$$.ctx[31]}}function pu(r,t,e=0,i=r.length-1,n=j_){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));pu(r,t,f,p,n)}const s=r[t];let o=e,a=i;for(Ln(r,e,t),n(r[i],s)>0&&Ln(r,e,i);o<a;){for(Ln(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?Ln(r,e,a):(a++,Ln(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function Ln(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function j_(r,t){return r<t?-1:r>t?1:0}class W_{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(!Bs(t,e))return i;const n=this.toBBox,s=[];for(;e;){for(let o=0;o<e.children.length;o++){const a=e.children[o],l=e.leaf?n(a):a;Bs(t,l)&&(e.leaf?i.push(a):Ra(t,l)?this._all(a,i):s.push(a))}e=s.pop()}return i}collides(t){let e=this.data;if(!Bs(t,e))return!1;const i=[];for(;e;){for(let n=0;n<e.children.length;n++){const s=e.children[n],o=e.leaf?this.toBBox(s):s;if(Bs(t,o)){if(e.leaf||Ra(t,o))return!0;i.push(s)}}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=ji([]),this}remove(t,e){if(!t)return this;let i=this.data;const n=this.toBBox(t),s=[],o=[];let a,l,h;for(;i||s.length;){if(i||(i=s.pop(),l=s[s.length-1],a=o.pop(),h=!0),i.leaf){const c=Y_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&Ra(i,n)?(s.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,n){const s=i-e+1;let o=this._maxEntries,a;if(s<=o)return a=ji(t.slice(e,i+1)),Xi(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=ji([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));mu(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);mu(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,n-1))}}return Xi(a,this.toBBox),a}_chooseSubtree(t,e,i,n){for(;n.push(e),!(e.leaf||n.length-1===i);){let s=1/0,o=1/0,a;for(let l=0;l<e.children.length;l++){const h=e.children[l],c=Pa(h),u=K_(t,h)-c;u<o?(o=u,s=c<s?c:s,a=h):u===o&&c<s&&(s=c,a=h)}e=a||e.children[0]}return e}_insert(t,e,i){const n=i?t:this.toBBox(t),s=[],o=this._chooseSubtree(n,this.data,e,s);for(o.children.push(t),Nn(o,n);e>=0&&s[e].children.length>this._maxEntries;)this._split(s,e),e--;this._adjustParentBBoxes(n,s,e)}_split(t,e){const i=t[e],n=i.children.length,s=this._minEntries;this._chooseSplitAxis(i,s,n);const o=this._chooseSplitIndex(i,s,n),a=ji(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Xi(i,this.toBBox),Xi(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=ji([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Xi(this.data,this.toBBox)}_chooseSplitIndex(t,e,i){let n,s=1/0,o=1/0;for(let a=e;a<=i-e;a++){const l=Dn(t,0,a,this.toBBox),h=Dn(t,a,i,this.toBBox),c=Z_(l,h),u=Pa(l)+Pa(h);c<s?(s=c,n=a,o=u<o?u:o):c===s&&u<o&&(o=u,n=a)}return n||i-e}_chooseSplitAxis(t,e,i){const n=t.leaf?this.compareMinX:z_,s=t.leaf?this.compareMinY:q_,o=this._allDistMargin(t,e,i,n),a=this._allDistMargin(t,e,i,s);o<a&&t.children.sort(n)}_allDistMargin(t,e,i,n){t.children.sort(n);const s=this.toBBox,o=Dn(t,0,e,s),a=Dn(t,i-e,i,s);let l=Os(o)+Os(a);for(let h=e;h<i-e;h++){const c=t.children[h];Nn(o,t.leaf?s(c):c),l+=Os(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];Nn(a,t.leaf?s(c):c),l+=Os(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)Nn(e[n],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():Xi(t[e],this.toBBox)}}function Y_(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 Xi(r,t){Dn(r,0,r.children.length,t,r)}function Dn(r,t,e,i,n){n||(n=ji(null)),n.minX=1/0,n.minY=1/0,n.maxX=-1/0,n.maxY=-1/0;for(let s=t;s<e;s++){const o=r.children[s];Nn(n,r.leaf?i(o):o)}return n}function Nn(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 z_(r,t){return r.minX-t.minX}function q_(r,t){return r.minY-t.minY}function Pa(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function Os(r){return r.maxX-r.minX+(r.maxY-r.minY)}function K_(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 Z_(r,t){const e=Math.max(r.minX,t.minX),i=Math.max(r.minY,t.minY),n=Math.min(r.maxX,t.maxX),s=Math.min(r.maxY,t.maxY);return Math.max(0,n-e)*Math.max(0,s-i)}function Ra(r,t){return r.minX<=t.minX&&r.minY<=t.minY&&t.maxX<=r.maxX&&t.maxY<=r.maxY}function Bs(r,t){return t.minX<=r.maxX&&t.minY<=r.maxY&&t.maxX>=r.minX&&t.maxY>=r.minY}function ji(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function mu(r,t,e,i,n){const s=[t,e];for(;s.length;){if(e=s.pop(),t=s.pop(),e-t<=i)continue;const o=t+Math.ceil((e-t)/i/2)*i;pu(r,o,t,e,n),s.push(t,o,o,e)}}const J_=()=>{const r=new W_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!Ss(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)},s=o=>{if(!Ss(o))return;const a=t.get(o.annotation);a&&r.remove(a),t.delete(o.annotation)};return{all:e,clear:i,getAt:(o,a,l=0)=>{const h=r.search({minX:o-l,minY:a-l,maxX:o+l,maxY:a+l}).map(c=>c.target).filter(({selector:c})=>ry(c,o,a,l));return h.length>0?(h.sort((c,u)=>ca(c.selector)-ca(u.selector)),h):[]},getIntersecting:(o,a,l,h)=>r.search({minX:o,minY:a,maxX:o+l,maxY:a+h}).map(c=>c.target),insert:n,remove:s,set:(o,a=!0)=>{a&&i();const l=o.reduce((h,c)=>{if(Ss(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)=>{s(o),n(a)}}},Q_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}}),gu=r=>{const t=zy(),e=J_(),i=Ly(t,r.userSelectAction,r.adapter),n=By(t),s=Jy();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,l,h)=>{const c=e.getAt(o,a,h);if(l)return c.map(u=>t.getAnnotation(u.annotation)).filter(Boolean).filter(l)[0];{const u=c[0];return u?t.getAnnotation(u.annotation):void 0}},getIntersecting:(o,a,l,h)=>e.getIntersecting(o,a,l,h).map(c=>t.getAnnotation(c.annotation)).filter(Boolean)},selection:i,hover:n,viewport:s}},tv=r=>{const t=gu(r);return{...t,store:Q_(t.store)}},ev=r=>{let t,e;if(r.nodeName==="CANVAS")t=r,e=t.getContext("2d",{willReadFrequently:!0});else{const n=r;t=document.createElement("canvas"),t.width=n.width,t.height=n.height,e=t.getContext("2d",{willReadFrequently:!0}),e.drawImage(n,0,0,n.width,n.height)}let i=0;for(let n=1;n<10;n++)for(let s=1;s<10;s++){const o=Math.round(s*t.width/10),a=Math.round(n*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},yu=r=>{const t=ev(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},_u=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?yu(r):e),vu=(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}),bu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,xu=(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()},n=o=>{const a=o;a.key==="z"&&a.metaKey&&(a.shiftKey?r.redo():r.undo())},s=()=>{bu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return bu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},rv=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=vu(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:xc.EDIT,theme:"light"}),n=tv(i),{selection:s,store:o}=n,a=Zy(o,i.initialHistory),l=Qy(n,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=xu(a);let u=h0();_u(e,h,i.theme);const d=new X_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",T=>{const{originalEvent:w,annotation:A}=T.detail;A?s.userSelect(A.id,w):s.isEmpty()||s.clear()});const f=e0(n,a,i.adapter),p=()=>d.cancelDrawing(),g=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>u,v=()=>d.isDrawingEnabled(),m=(T,w,A)=>eu(T,w,A),x=(T,w)=>Zc(T,w),S=T=>{if(!Ms(T))throw`No drawing tool named ${T}`;d.$set({toolName:T})},R=T=>d.$set({drawingEnabled:T}),C=T=>d.$set({preferredDrawingMode:T}),I=T=>{console.warn("Filter not implemented yet")},M=T=>d.$set({style:T}),F=T=>_u(e,h,T),U=T=>{u=T,d.$set({user:T})},P=T=>d.$set({visible:T});return{...f,cancelDrawing:p,destroy:g,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:Rs,on:l.on,off:l.off,registerDrawingTool:m,registerShapeEditor:x,setDrawingEnabled:R,setDrawingMode:C,setDrawingTool:S,setFilter:I,setStyle:M,setTheme:F,setUser:U,setVisible:P,element:h,state:n}};function Nt(){}function Ma(r,t){for(const e in t)r[e]=t[e];return r}function wu(r){return r()}function Eu(){return Object.create(null)}function $e(r){r.forEach(wu)}function jt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function iv(r){return Object.keys(r).length===0}function nv(r,...t){if(r==null){for(const i of t)i(void 0);return Nt}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function Fn(r,t,e){r.$$.on_destroy.push(nv(t,e))}function Tu(r,t,e,i){if(r){const n=Au(r,t,e,i);return r[0](n)}}function Au(r,t,e,i){return r[1]&&i?Ma(e.ctx.slice(),r[1](i(t))):e.ctx}function Su(r,t,e,i){if(r[2]&&i){const n=r[2](i(e));if(t.dirty===void 0)return n;if(typeof n=="object"){const s=[],o=Math.max(t.dirty.length,n.length);for(let a=0;a<o;a+=1)s[a]=t.dirty[a]|n[a];return s}return t.dirty|n}return t.dirty}function Cu(r,t,e,i,n,s){if(n){const o=Au(t,e,i,s);r.p(o,n)}}function Iu(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 Pu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ru(r){return r??""}const Oa=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Tt(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function it(r){r.parentNode&&r.parentNode.removeChild(r)}function $r(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function J(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Ba(r){return document.createTextNode(r)}function Pe(){return Ba(" ")}function Be(){return Ba("")}function Pt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function E(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function sv(r){return Array.from(r.childNodes)}function ov(r,t){t=""+t,r.data!==t&&(r.data=t)}function Hr(r,t,e){r.classList.toggle(t,!!e)}function av(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let kn;function Un(r){kn=r}function La(){if(!kn)throw new Error("Function called outside component initialization");return kn}function Vr(r){La().$$.on_mount.push(r)}function lv(r){La().$$.on_destroy.push(r)}function Wi(){const r=La();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=av(t,e,{cancelable:i});return n.slice().forEach(o=>{o.call(r,s)}),!s.defaultPrevented}return!0}}function ae(r,t){const e=r.$$.callbacks[t.type];e&&e.slice().forEach(i=>i.call(this,t))}const Yi=[],Ls=[];let zi=[];const Mu=[],Ou=Promise.resolve();let Da=!1;function Bu(){Da||(Da=!0,Ou.then(Du))}function Lu(){return Bu(),Ou}function Na(r){zi.push(r)}const Fa=new Set;let qi=0;function Du(){if(qi!==0)return;const r=kn;do{try{for(;qi<Yi.length;){const t=Yi[qi];qi++,Un(t),hv(t.$$)}}catch(t){throw Yi.length=0,qi=0,t}for(Un(null),Yi.length=0,qi=0;Ls.length;)Ls.pop()();for(let t=0;t<zi.length;t+=1){const e=zi[t];Fa.has(e)||(Fa.add(e),e())}zi.length=0}while(Yi.length);for(;Mu.length;)Mu.pop()();Da=!1,Fa.clear(),Un(r)}function hv(r){if(r.fragment!==null){r.update(),$e(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Na)}}function cv(r){const t=[],e=[];zi.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),zi=t}const Ds=new Set;let ui;function le(){ui={r:0,c:[],p:ui}}function he(){ui.r||$e(ui.c),ui=ui.p}function q(r,t){r&&r.i&&(Ds.delete(r),r.i(t))}function nt(r,t,e,i){if(r&&r.o){if(Ds.has(r))return;Ds.add(r),ui.c.push(()=>{Ds.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ae(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Lt(r){r&&r.c()}function Ot(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Na(()=>{const s=r.$$.on_mount.map(wu).filter(jt);r.$$.on_destroy?r.$$.on_destroy.push(...s):$e(s),r.$$.on_mount=[]}),n.forEach(Na)}function Bt(r,t){const e=r.$$;e.fragment!==null&&(cv(e.after_update),$e(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function uv(r,t){r.$$.dirty[0]===-1&&(Yi.push(r),Bu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function Wt(r,t,e,i,n,s,o=null,a=[-1]){const l=kn;Un(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Nt,not_equal:n,bound:Eu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Eu(),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&&n(h.ctx[u],h.ctx[u]=p)&&(!h.skip_bound&&h.bound[u]&&h.bound[u](p),c&&uv(r,u)),d}):[],h.update(),c=!0,$e(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=sv(t.target);h.fragment&&h.fragment.l(u),u.forEach(it)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Ot(r,t.target,t.anchor),Du()}Un(l)}class Yt{constructor(){Yh(this,"$$");Yh(this,"$$set")}$destroy(){Bt(this,1),this.$destroy=Nt}$on(t,e){if(!jt(e))return Nt;const i=this.$$.callbacks[t]||(this.$$.callbacks[t]=[]);return i.push(e),()=>{const n=i.indexOf(e);n!==-1&&i.splice(n,1)}}$set(t){this.$$set&&!iv(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const dv="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(dv);var nr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(nr||{}),Gn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ka(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function fv(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 n=Object.getOwnPropertyDescriptor(r,i);Object.defineProperty(e,i,n.get?n:{enumerable:!0,get:function(){return r[i]}})}),e}var Nu={exports:{}};(function(r){(function(){function t(a,l){var h=a.x-l.x,c=a.y-l.y;return h*h+c*c}function e(a,l,h){var c=l.x,u=l.y,d=h.x-c,f=h.y-u;if(d!==0||f!==0){var p=((a.x-c)*d+(a.y-u)*f)/(d*d+f*f);p>1?(c=h.x,u=h.y):p>0&&(c+=d*p,u+=f*p)}return d=a.x-c,f=a.y-u,d*d+f*f}function i(a,l){for(var h=a[0],c=[h],u,d=1,f=a.length;d<f;d++)u=a[d],t(u,h)>l&&(c.push(u),h=u);return h!==u&&c.push(u),c}function n(a,l,h,c,u){for(var d=c,f,p=l+1;p<h;p++){var g=e(a[p],a[l],a[h]);g>d&&(f=p,d=g)}d>c&&(f-l>1&&n(a,l,f,c,u),u.push(a[f]),h-f>1&&n(a,f,h,c,u))}function s(a,l){var h=a.length-1,c=[a[0]];return n(a,0,h,l,c),c.push(a[h]),c}function o(a,l,h){if(a.length<=2)return a;var c=l!==void 0?l*l:1;return a=h?a:i(a,c),a=s(a,c),a}r.exports=o,r.exports.default=o})()})(Nu);var pv=Nu.exports;const mv=ka(pv),Ki=(r,t)=>t,Ye=r=>{let t=1/0,e=1/0,i=-1/0,n=-1/0;return r.forEach(([s,o])=>{t=Math.min(t,s),e=Math.min(e,o),i=Math.max(i,s),n=Math.max(n,o)}),{minX:t,minY:e,maxX:i,maxY:n}},Ns=r=>{let t=0,e=r.length-1;for(let i=0;i<r.length;i++)t+=(r[e][0]+r[i][0])*(r[e][1]-r[i][1]),e=i;return Math.abs(.5*t)},Fs=(r,t,e)=>{let i=!1;for(let n=0,s=r.length-1;n<r.length;s=n++){const o=r[n][0],a=r[n][1],l=r[s][0],h=r[s][1];a>e!=h>e&&t<(l-o)*(e-a)/(h-a)+o&&(i=!i)}return i},gv=(r,t=!0)=>{let e="M ";return r.forEach(([i,n],s)=>{s===0?e+=`${i},${n}`:e+=` L ${i},${n}`}),t&&(e+=" Z"),e},Fu=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return mv(e,t,!0).map(i=>[i.x,i.y])},yv=(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))},_v={area:r=>Math.PI*r.geometry.rx*r.geometry.ry,intersects:(r,t,e)=>{const{cx:i,cy:n,rx:s,ry:o}=r.geometry,a=0,l=Math.cos(a),h=Math.sin(a),c=t-i,u=e-n,d=l*c+h*u,f=h*c-l*u;return d*d/(s*s)+f*f/(o*o)<=1}};Ki(nr.ELLIPSE,_v);const vv={area:r=>0,intersects:(r,t,e,i=2)=>{const[[n,s],[o,a]]=r.geometry.points,l=Math.abs((a-s)*t-(o-n)*e+o*s-a*n),h=yv([n,s],[o,a]);return l/h<=i}};Ki(nr.LINE,vv);const bv={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=Ns(n.points),a=s.reduce((l,h)=>l+Ns(h.points),0);return e+o-a},0)},intersects:(r,t,e)=>{const{polygons:i}=r.geometry;for(const n of i){const[s,...o]=n.rings;if(Fs(s.points,t,e)){let a=!1;for(const l of o)if(Fs(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},ks=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ye(t)},Zi=r=>r.rings.map(e=>gv(e.points)).join(" "),xv=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),wv=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Fu(a.points,t);return{...a,points:l}}),o=Ye(s[0].points);return{...n,rings:s,bounds:o}}),i=ks(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};Ki(nr.MULTIPOLYGON,bv);const Ev={area:r=>{const t=r.geometry.points;return Ns(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Fs(i,t,e)}},Tv=(r,t=1)=>{const e=Fu(r.geometry.points,t),i=Ye(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};Ki(nr.POLYGON,Ev);const Av={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=ku(t.points,t.closed);return Ns(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=ku(n.points,n.closed);return Fs(s,t,e)}else return Sv(n,[t,e],i)}},ku=(r,t=!1)=>{const e=[];for(let i=0;i<r.length;i++){const n=r[i],s=r[(i+1)%r.length];if(e.push(n.point),(i<r.length-1||t)&&(n.type==="CURVE"||s.type=="CURVE")){const a=Uu(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,10);e.push(...a.slice(1))}}return e},Uu=(r,t,e,i,n=10)=>{const s=[];for(let o=0;o<=n;o++){const a=o/n,l=Math.pow(1-a,3)*r[0]+3*Math.pow(1-a,2)*a*t[0]+3*(1-a)*Math.pow(a,2)*e[0]+Math.pow(a,3)*i[0],h=Math.pow(1-a,3)*r[1]+3*Math.pow(1-a,2)*a*t[1]+3*(1-a)*Math.pow(a,2)*e[1]+Math.pow(a,3)*i[1];s.push([l,h])}return s},Sv=(r,t,e)=>{for(let i=0;i<r.points.length-1;i++){const n=r.points[i],s=r.points[i+1];if(n.type==="CURVE"||s.type==="CURVE"){const a=Uu(n.point,n.type==="CURVE"&&n.outHandle||n.point,s.type==="CURVE"&&s.inHandle||s.point,s.point,20);for(let l=0;l<a.length-1;l++)if(Gu(t,a[l],a[l+1])<=e)return!0}else if(Gu(t,n.point,s.point)<=e)return!0}return!1},Gu=(r,t,e)=>{const[i,n]=r,[s,o]=t,[a,l]=e,h=a-s,c=l-o,u=Math.sqrt(h*h+c*c);if(u===0)return Math.sqrt((i-s)*(i-s)+(n-o)*(n-o));const d=((i-s)*h+(n-o)*c)/(u*u);return d<=0?Math.sqrt((i-s)*(i-s)+(n-o)*(n-o)):d>=1?Math.sqrt((i-a)*(i-a)+(n-l)*(n-l)):Math.abs((l-o)*i-(a-s)*n+a*o-l*s)/u};Ki(nr.POLYLINE,Av);const Cv={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>{const i=r.geometry;if(i.rot){const n=i.x+i.w/2,s=i.y+i.h/2,o=t-n,a=e-s,l=Math.cos(i.rot),h=Math.sin(i.rot),c=o*l+a*h,u=-o*h+a*l;return c>=-i.w/2&&c<=i.w/2&&u>=-i.h/2&&u<=i.h/2}else return t>=i.x&&t<=i.x+i.w&&e>=i.y&&e<=i.y+i.h}};Ki(nr.RECTANGLE,Cv);const ve=[];for(let r=0;r<256;++r)ve.push((r+256).toString(16).slice(1));function Iv(r,t=0){return(ve[r[t+0]]+ve[r[t+1]]+ve[r[t+2]]+ve[r[t+3]]+"-"+ve[r[t+4]]+ve[r[t+5]]+"-"+ve[r[t+6]]+ve[r[t+7]]+"-"+ve[r[t+8]]+ve[r[t+9]]+"-"+ve[r[t+10]]+ve[r[t+11]]+ve[r[t+12]]+ve[r[t+13]]+ve[r[t+14]]+ve[r[t+15]]).toLowerCase()}const Pv=new Uint8Array(16);function Rv(){return crypto.getRandomValues(Pv)}function Mv(r,t,e){return crypto.randomUUID?crypto.randomUUID():Ov(r)}function Ov(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??Rv();if(i.length<16)throw new Error("Random bytes length must be >= 16");return i[6]=i[6]&15|64,i[8]=i[8]&63|128,Iv(i)}const Bv=(r,t,e)=>{const i=typeof t=="function"?t(r,e):t;if(i){const{fill:n,fillOpacity:s,stroke:o,strokeWidth:a,strokeOpacity:l}=i;let h="";return n&&(h+=`fill:${n};`),s||s===0?h+=`fill-opacity:${s};`:n&&(h+="fill-opacity:0.25;"),o&&(h+=`stroke:${o};`,h+=`stroke-width:${a||"1"};`,h+=`stroke-opacity:${l||"1"};`),h}},Ua=(r,t=0)=>{const{minX:e,minY:i,maxX:n,maxY:s}=r;return{x:e-t,y:i-t,w:n-e+2*t,h:s-i+2*t}},Xr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,Lv=r=>({}),$u=r=>({grab:r[0]});function Dv(r){let t,e,i,n;const s=r[8].default,o=Tu(s,r,r[7],$u);return{c(){t=J("g"),o&&o.c(),E(t,"class","a9s-annotation selected")},m(a,l){ot(a,t,l),o&&o.m(t,null),e=!0,i||(n=[Pt(t,"pointerup",r[2]),Pt(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Cu(o,s,a,a[7],e?Su(s,a[7],l,Lv):Iu(a[7]),$u)},i(a){e||(q(o,a),e=!0)},o(a){nt(o,a),e=!1},d(a){a&&it(t),o&&o.d(a),i=!1,$e(n)}}}function Nv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Wi();let{shape:o}=t,{editor:a}=t,{transform:l}=t,{svgEl:h}=t,c,u,d;const f=y=>_=>{if(c=y,h){const{left:m,top:x}=h.getBoundingClientRect(),S=_.clientX-m,R=_.clientY-x;u=l.elementToImage(S,R)}else{const{offsetX:m,offsetY:x}=_;u=l.elementToImage(m,x)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),m=[_-u[0],v-u[1]];e(3,o=a(d,c,m)),s("change",o)}},g=y=>{y.target.releasePointerCapture(y.pointerId),c=void 0,d=o,s("release",y)};return r.$$set=y=>{"shape"in y&&e(3,o=y.shape),"editor"in y&&e(4,a=y.editor),"transform"in y&&e(5,l=y.transform),"svgEl"in y&&e(6,h=y.svgEl),"$$scope"in y&&e(7,n=y.$$scope)},[f,p,g,o,a,l,h,n,i]}class Ga extends Yt{constructor(t){super(),Wt(this,t,Nv,Dv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function Fv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Hu(r);return{c(){t=J("g"),e=J("circle"),h&&h.c(),n=J("circle"),E(e,"class","a9s-handle-buffer svelte-qtyc7s"),E(e,"cx",r[0]),E(e,"cy",r[1]),E(e,"r",i=r[5]+6/r[2]),E(e,"role","button"),E(e,"tabindex","0"),E(n,"class",s=Ru(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),E(n,"cx",r[0]),E(n,"cy",r[1]),E(n,"r",r[5]),E(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){ot(c,t,u),Tt(t,e),h&&h.m(t,null),Tt(t,n),a||(l=[Pt(e,"dblclick",r[12]),Pt(e,"pointerenter",r[13]),Pt(e,"pointerleave",r[14]),Pt(e,"pointerdown",r[15]),Pt(e,"pointerdown",r[6]),Pt(e,"pointerup",r[16]),Pt(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&E(e,"cx",c[0]),u&2&&E(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&E(e,"r",i),c[3]?h?h.p(c,u):(h=Hu(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ru(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&E(n,"class",s),u&1&&E(n,"cx",c[0]),u&2&&E(n,"cy",c[1]),u&32&&E(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&E(t,"class",o)},d(c){c&&it(t),h&&h.d(),a=!1,$e(l)}}}function kv(r){let t,e,i,n,s,o,a,l,h;return{c(){t=J("g"),e=J("circle"),n=J("circle"),o=J("circle"),E(e,"cx",r[0]),E(e,"cy",r[1]),E(e,"r",i=r[5]*10),E(e,"class","a9s-touch-halo"),Hr(e,"touched",r[4]),E(n,"cx",r[0]),E(n,"cy",r[1]),E(n,"r",s=r[5]+10/r[2]),E(n,"class","a9s-handle-buffer svelte-qtyc7s"),E(n,"role","button"),E(n,"tabindex","0"),E(o,"class","a9s-handle-dot"),E(o,"cx",r[0]),E(o,"cy",r[1]),E(o,"r",a=r[5]+2/r[2]),E(t,"class","a9s-touch-handle")},m(c,u){ot(c,t,u),Tt(t,e),Tt(t,n),Tt(t,o),l||(h=[Pt(n,"dblclick",r[9]),Pt(n,"pointerdown",r[10]),Pt(n,"pointerdown",r[6]),Pt(n,"pointerup",r[11]),Pt(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&E(e,"cx",c[0]),u&2&&E(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&E(e,"r",i),u&16&&Hr(e,"touched",c[4]),u&1&&E(n,"cx",c[0]),u&2&&E(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&E(n,"r",s),u&1&&E(o,"cx",c[0]),u&2&&E(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&E(o,"r",a)},d(c){c&&it(t),l=!1,$e(h)}}}function Hu(r){let t,e;return{c(){t=J("circle"),E(t,"class","a9s-handle-selected"),E(t,"cx",r[0]),E(t,"cy",r[1]),E(t,"r",e=r[5]+8/r[2])},m(i,n){ot(i,t,n)},p(i,n){n&1&&E(t,"cx",i[0]),n&2&&E(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&E(t,"r",e)},d(i){i&&it(t)}}}function Uv(r){let t;function e(s,o){return Xr?kv:Fv}let n=e()(r);return{c(){n.c(),t=Be()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Nt,o:Nt,d(s){s&&it(t),n.d(s)}}}function Gv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=m=>{m.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(m){ae.call(this,r,m)}function d(m){ae.call(this,r,m)}function f(m){ae.call(this,r,m)}function p(m){ae.call(this,r,m)}function g(m){ae.call(this,r,m)}function y(m){ae.call(this,r,m)}function _(m){ae.call(this,r,m)}function v(m){ae.call(this,r,m)}return r.$$set=m=>{e(8,t=Ma(Ma({},t),Pu(m))),"x"in m&&e(0,n=m.x),"y"in m&&e(1,s=m.y),"scale"in m&&e(2,o=m.scale),"selected"in m&&e(3,a=m.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Pu(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,g,y,_,v]}class di extends Yt{constructor(t){super(),Wt(this,t,Gv,Uv,Ut,{x:0,y:1,scale:2,selected:3})}}function $v(r){let t,e,i,n,s,o,a;return{c(){t=J("g"),e=J("circle"),n=J("circle"),s=J("circle"),E(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),E(e,"cx",r[0]),E(e,"cy",r[1]),E(e,"r",i=1.75*r[2]),E(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),E(n,"cx",r[0]),E(n,"cy",r[1]),E(n,"r",r[2]),E(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),E(s,"cx",r[0]),E(s,"cy",r[1]),E(s,"r",r[2]),E(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){ot(l,t,h),Tt(t,e),Tt(t,n),Tt(t,s),o||(a=[Pt(e,"pointerdown",r[5]),Pt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&E(e,"cx",l[0]),h&2&&E(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&E(e,"r",i),h&1&&E(n,"cx",l[0]),h&2&&E(n,"cy",l[1]),h&4&&E(n,"r",l[2]),h&1&&E(s,"cx",l[0]),h&2&&E(s,"cy",l[1]),h&4&&E(s,"r",l[2])},d(l){l&&it(t),o=!1,$e(a)}}}function Hv(r){let t;return{c(){t=J("circle"),E(t,"cx",r[0]),E(t,"cy",r[1]),E(t,"r",r[2])},m(e,i){ot(e,t,i)},p(e,i){i&1&&E(t,"cx",e[0]),i&2&&E(t,"cy",e[1]),i&4&&E(t,"r",e[2])},d(e){e&&it(t)}}}function Vv(r){let t;function e(s,o){return Xr?Hv:$v}let n=e()(r);return{c(){n.c(),t=Be()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Nt,o:Nt,d(s){s&&it(t),n.d(s)}}}function Xv(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t;const a=h=>{h.pointerType};function l(h){ae.call(this,r,h)}return r.$$set=h=>{"x"in h&&e(0,n=h.x),"y"in h&&e(1,s=h.y),"scale"in h&&e(4,o=h.scale)},r.$$.update=()=>{r.$$.dirty&16&&e(2,i=4/o)},[n,s,i,a,o,l]}class Vu extends Yt{constructor(t){super(),Wt(this,t,Xv,Vv,Ut,{x:0,y:1,scale:4})}}function $a(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Xu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Ha(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Va(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function ju(r){let t,e,i,n;return{c(){t=J("circle"),E(t,"cx",e=r[28][0]),E(t,"cy",i=r[28][1]),E(t,"r",n=$n/r[3]),E(t,"class","svelte-1h2slbm")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&E(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&E(t,"cy",i),o[0]&8&&n!==(n=$n/s[3])&&E(t,"r",n)},d(s){s&&it(t)}}}function Wu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=J("mask"),e=J("rect"),a=J("circle"),E(e,"x",i=r[9].x),E(e,"y",n=r[9].y),E(e,"width",s=r[9].w),E(e,"height",o=r[9].h),E(e,"class","svelte-1h2slbm"),E(a,"cx",l=r[28][0]),E(a,"cy",h=r[28][1]),E(a,"r",c=$n/r[3]),E(a,"class","svelte-1h2slbm"),E(t,"id",`${r[19]}-inner`),E(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){ot(u,t,d),Tt(t,e),Tt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&E(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&E(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&E(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&E(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&E(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&E(a,"cy",h),d[0]&8&&c!==(c=$n/u[3])&&E(a,"r",c)},d(u){u&&it(t)}}}function Yu(r){let t,e;return t=new di({props:{class:"a9s-corner-handle",x:r[28][0],y:r[28][1],scale:r[3],selected:r[8].includes(r[30])}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[15]),t.$on("pointerdown",function(){jt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&32&&(s.x=r[28][0]),n[0]&32&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),n[0]&256&&(s.selected=r[8].includes(r[30])),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function zu(r){let t,e;return t=new Vu({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){jt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[28][0]),n[0]&1088&&(s.y=r[28][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function jv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R=r[6]!==void 0&&!r[7]&&ju(Va(r)),C=r[6]!==void 0&&!r[7]&&Wu(Ha(r)),I=Ae(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Yu(Xu(r,I,P));const F=P=>nt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&zu($a(r));return{c(){t=J("defs"),e=J("mask"),i=J("rect"),l=J("polygon"),R&&R.c(),C&&C.c(),c=Pe(),u=J("polygon"),f=Pe(),p=J("polygon"),y=Pe();for(let P=0;P<M.length;P+=1)M[P].c();_=Pe(),U&&U.c(),v=Be(),E(i,"x",n=r[9].x),E(i,"y",s=r[9].y),E(i,"width",o=r[9].w),E(i,"height",a=r[9].h),E(i,"class","svelte-1h2slbm"),E(l,"points",h=r[5].points.map(qu).join(" ")),E(l,"class","svelte-1h2slbm"),E(e,"id",`${r[19]}-outer`),E(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),E(u,"class","a9s-outer"),E(u,"mask",`url(#${r[19]}-outer)`),E(u,"points",d=r[5].points.map(Ku).join(" ")),E(p,"class","a9s-inner a9s-shape-handle"),E(p,"mask",`url(#${r[19]}-inner)`),E(p,"style",r[1]),E(p,"points",g=r[5].points.map(Zu).join(" "))},m(P,T){ot(P,t,T),Tt(t,e),Tt(e,i),Tt(e,l),R&&R.m(e,null),C&&C.m(t,null),ot(P,c,T),ot(P,u,T),ot(P,f,T),ot(P,p,T),ot(P,y,T);for(let w=0;w<M.length;w+=1)M[w]&&M[w].m(P,T);ot(P,_,T),U&&U.m(P,T),ot(P,v,T),m=!0,x||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){jt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(p,"pointermove",r[13]),Pt(p,"pointerup",r[14]),Pt(p,"pointerdown",function(){jt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],x=!0)},p(P,T){if(r=P,(!m||T[0]&512&&n!==(n=r[9].x))&&E(i,"x",n),(!m||T[0]&512&&s!==(s=r[9].y))&&E(i,"y",s),(!m||T[0]&512&&o!==(o=r[9].w))&&E(i,"width",o),(!m||T[0]&512&&a!==(a=r[9].h))&&E(i,"height",a),(!m||T[0]&32&&h!==(h=r[5].points.map(qu).join(" ")))&&E(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Va(r),T):(R=ju(Va(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Ha(r),T):(C=Wu(Ha(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!m||T[0]&32&&d!==(d=r[5].points.map(Ku).join(" ")))&&E(u,"points",d),(!m||T[0]&2)&&E(p,"style",r[1]),(!m||T[0]&32&&g!==(g=r[5].points.map(Zu).join(" ")))&&E(p,"points",g),T[0]&134322472){I=Ae(r[5].points);let w;for(w=0;w<I.length;w+=1){const A=Xu(r,I,w);M[w]?(M[w].p(A,T),q(M[w],1)):(M[w]=Yu(A),M[w].c(),q(M[w],1),M[w].m(_.parentNode,_))}for(le(),w=I.length;w<M.length;w+=1)F(w);he()}r[6]!==void 0&&!r[7]?U?(U.p($a(r),T),T[0]&192&&q(U,1)):(U=zu($a(r)),U.c(),q(U,1),U.m(v.parentNode,v)):U&&(le(),nt(U,1,1,()=>{U=null}),he())},i(P){if(!m){for(let T=0;T<I.length;T+=1)q(M[T]);q(U),m=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)nt(M[T]);nt(U),m=!1},d(P){P&&(it(t),it(c),it(u),it(f),it(p),it(y),it(_),it(v)),R&&R.d(),C&&C.d(),$r(M,P),U&&U.d(P),x=!1,$e(S)}}}function Wv(r){let t,e;return t=new Ga({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[jv,({grab:i})=>({27:i}),({grab:i})=>[i?134217728:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&134219754|n[1]&1&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}const Yv=250,zv=1e3,qv=12,$n=4.5,qu=r=>r.join(","),Ku=r=>r.join(","),Zu=r=>r.join(",");function Kv(r,t,e){let i,n,s;const o=Wi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=w=>{if(g.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(w.offsetX,w.offsetY),O=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-L,2),D=i.points.reduce((k,V)=>O(V)<O(k)?V:k),$=n.filter(k=>k.visible).reduce((k,V)=>O(V.point)<O(k.point)?V:k),B=Math.pow(zv/c,2);O(D)<B||O($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=w=>{e(7,f=!0),w.preventDefault(),w.stopPropagation(),p=performance.now()},R=w=>A=>{if(!p||Xr||performance.now()-p>Yv)return;const L=g.includes(w);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,g=g.filter(O=>O!==w)):e(8,g=[...g,w]):L&&g.length>1?e(8,g=[w]):L?e(8,g=[]):e(8,g=[w]),m()},C=(w,A,L)=>{m();let O;const D=w.geometry;g.length>1?O=D.points.map(([B,N],k)=>g.includes(k)?[B+L[0],N+L[1]]:[B,N]):A==="SHAPE"?O=D.points.map(([B,N])=>[B+L[0],N+L[1]]):O=D.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+L[0],N+L[1]]:[B,N]);const $=Ye(O);return{...w,geometry:{points:O,bounds:$}}},I=w=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,w+1),n[w].point,...i.points.slice(w+1)],O=Ye(L);o("change",{...a,geometry:{points:L,bounds:O}}),await Lu();const D=[...document.querySelectorAll(".a9s-handle")][w+1];if(D!=null&&D.firstChild){const $=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:A.clientX,clientY:A.clientY,pointerId:A.pointerId,pointerType:A.pointerType,isPrimary:A.isPrimary,buttons:A.buttons});D.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-g.length<3)return;const w=i.points.filter((L,O)=>!g.includes(O)),A=Ye(w);o("change",{...a,geometry:{points:w,bounds:A}}),e(8,g=[])};Vr(()=>{if(Xr)return;const w=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",w),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",w)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(w){ae.call(this,r,w)}function P(w){ae.call(this,r,w)}function T(w){ae.call(this,r,w)}return r.$$set=w=>{"shape"in w&&e(0,a=w.shape),"computedStyle"in w&&e(1,l=w.computedStyle),"transform"in w&&e(2,h=w.transform),"viewportScale"in w&&e(3,c=w.viewportScale),"svgEl"in w&&e(4,u=w.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Xr?[]:i.points.map((w,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],O=(w[0]+L[0])/2,D=(w[1]+L[1])/2,B=Math.sqrt(Math.pow(L[0]-O,2)+Math.pow(L[1]-D,2))>qv/c;return{point:[O,D],visible:B}})),r.$$.dirty[0]&40&&e(9,s=Ua(i.bounds,$n/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,v,x,S,R,C,I,F,U,P,T]}class Zv extends Yt{constructor(t){super(),Wt(this,t,Kv,Wv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const Ju=(r,t,e)=>{const[i,n]=r,[s,o]=t,a=Math.cos(e),l=Math.sin(e),h=i-s,c=n-o;return[s+h*a-c*l,o+h*l+c*a]},Jv=(r,t,e,i,n=0)=>{const s=[[r,t],[r+e,t],[r+e,t+i],[r,t+i]],o=[r+e/2,t+i/2];return s.map(a=>Ju(a,o,n))},Qu=(r,t)=>{const{x:e,y:i,w:n,h:s,rot:o=0}=r,a=[e+n/2,i+s/2];let l=[e+n/2,i-t];return Ju(l,a,o)},Qv=(r,t,e)=>{const i=Math.cos(e),n=Math.sin(e);return[r*i+t*n,-r*n+t*i]},t1=(r,t,e)=>{const i=r[0]-e[0],n=r[1]-e[1],s=Math.atan2(n,i),o=t[0]-e[0],a=t[1]-e[1];return Math.atan2(a,o)-s},e1=(r,t=10)=>{const e=t*Math.PI/180;return Math.round(r/e)*e};function r1(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v,m,x,S,R,C,I,M,F,U,P,T,w,A,L,O,D,$,B,N,k,V,j,st,H,at,X,gt,lt,ft,ct,Et,te,Gt,Me,Rr,zt,Li,we,Di,Ee,Ni,Te,Z,Fi,ms;return R=new di({props:{class:"a9s-rotation-handle",x:r[7][0],y:r[7][1],scale:r[3]}}),R.$on("pointerdown",function(){jt(r[16]("ROTATION"))&&r[16]("ROTATION").apply(this,arguments)}),zt=new di({props:{class:"a9s-corner-handle-topleft",x:r[6][0][0],y:r[6][0][1],scale:r[3]}}),zt.$on("pointerdown",function(){jt(r[16]("TOP_LEFT"))&&r[16]("TOP_LEFT").apply(this,arguments)}),we=new di({props:{class:"a9s-corner-handle-topright",x:r[6][1][0],y:r[6][1][1],scale:r[3]}}),we.$on("pointerdown",function(){jt(r[16]("TOP_RIGHT"))&&r[16]("TOP_RIGHT").apply(this,arguments)}),Ee=new di({props:{class:"a9s-corner-handle-bottomright",x:r[6][2][0],y:r[6][2][1],scale:r[3]}}),Ee.$on("pointerdown",function(){jt(r[16]("BOTTOM_RIGHT"))&&r[16]("BOTTOM_RIGHT").apply(this,arguments)}),Te=new di({props:{class:"a9s-corner-handle-bottomleft",x:r[6][3][0],y:r[6][3][1],scale:r[3]}}),Te.$on("pointerdown",function(){jt(r[16]("BOTTOM_LEFT"))&&r[16]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=J("defs"),e=J("mask"),i=J("rect"),l=J("polygon"),c=Pe(),u=J("g"),d=J("line"),_=J("line"),Lt(R.$$.fragment),C=Pe(),I=J("g"),M=J("polygon"),U=J("polygon"),T=Pe(),w=J("line"),$=Pe(),B=J("line"),st=Pe(),H=J("line"),ft=Pe(),ct=J("line"),Rr=Pe(),Lt(zt.$$.fragment),Li=Pe(),Lt(we.$$.fragment),Di=Pe(),Lt(Ee.$$.fragment),Ni=Pe(),Lt(Te.$$.fragment),E(i,"class","rect-mask-bg svelte-1bwhzbc"),E(i,"x",n=r[5].x),E(i,"y",s=r[5].y),E(i,"width",o=r[5].w),E(i,"height",a=r[5].h),E(l,"class","rect-mask-fg svelte-1bwhzbc"),E(l,"points",h=r[6].map(td).join(" ")),E(e,"id",r[9]),E(e,"class","a9s-rectangle-editor-mask svelte-1bwhzbc"),E(d,"class","a9s-rotation-handle-line-bg"),E(d,"x1",f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),E(d,"y1",p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),E(d,"x2",g=r[7][0]),E(d,"y2",y=r[7][1]),E(d,"pointer-events","none"),E(_,"class","a9s-rotation-handle-line-fg"),E(_,"x1",v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2),E(_,"y1",m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2),E(_,"x2",x=r[7][0]),E(_,"y2",S=r[7][1]),E(_,"pointer-events","none"),E(u,"class","a9s-rotation-handle-group"),E(M,"class","a9s-outer"),E(M,"mask",`url(#${r[9]})`),E(M,"points",F=r[6].map(ed).join(" ")),E(U,"class","a9s-inner a9s-shape-handle"),E(U,"style",r[1]),E(U,"points",P=r[6].map(rd).join(" ")),E(w,"class","a9s-edge-handle a9s-edge-handle-top"),E(w,"x1",A=r[6][0][0]),E(w,"y1",L=r[6][0][1]),E(w,"x2",O=r[6][1][0]),E(w,"y2",D=r[6][1][1]),E(B,"class","a9s-edge-handle a9s-edge-handle-right"),E(B,"x1",N=r[6][1][0]),E(B,"y1",k=r[6][1][1]),E(B,"x2",V=r[6][2][0]),E(B,"y2",j=r[6][2][1]),E(H,"class","a9s-edge-handle a9s-edge-handle-bottom"),E(H,"x1",at=r[6][2][0]),E(H,"y1",X=r[6][2][1]),E(H,"x2",gt=r[6][3][0]),E(H,"y2",lt=r[6][3][1]),E(ct,"class","a9s-edge-handle a9s-edge-handle-left"),E(ct,"x1",Et=r[6][3][0]),E(ct,"y1",te=r[6][3][1]),E(ct,"x2",Gt=r[6][0][0]),E(ct,"y2",Me=r[6][0][1])},m(z,G){ot(z,t,G),Tt(t,e),Tt(e,i),Tt(e,l),ot(z,c,G),ot(z,u,G),Tt(u,d),Tt(u,_),Ot(R,u,null),ot(z,C,G),ot(z,I,G),Tt(I,M),Tt(I,U),ot(z,T,G),ot(z,w,G),ot(z,$,G),ot(z,B,G),ot(z,st,G),ot(z,H,G),ot(z,ft,G),ot(z,ct,G),ot(z,Rr,G),Ot(zt,z,G),ot(z,Li,G),Ot(we,z,G),ot(z,Di,G),Ot(Ee,z,G),ot(z,Ni,G),Ot(Te,z,G),Z=!0,Fi||(ms=[Pt(M,"pointerdown",function(){jt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Pt(U,"pointerdown",function(){jt(r[16]("SHAPE"))&&r[16]("SHAPE").apply(this,arguments)}),Pt(w,"pointerdown",function(){jt(r[16]("TOP"))&&r[16]("TOP").apply(this,arguments)}),Pt(B,"pointerdown",function(){jt(r[16]("RIGHT"))&&r[16]("RIGHT").apply(this,arguments)}),Pt(H,"pointerdown",function(){jt(r[16]("BOTTOM"))&&r[16]("BOTTOM").apply(this,arguments)}),Pt(ct,"pointerdown",function(){jt(r[16]("LEFT"))&&r[16]("LEFT").apply(this,arguments)})],Fi=!0)},p(z,G){r=z,(!Z||G&32&&n!==(n=r[5].x))&&E(i,"x",n),(!Z||G&32&&s!==(s=r[5].y))&&E(i,"y",s),(!Z||G&32&&o!==(o=r[5].w))&&E(i,"width",o),(!Z||G&32&&a!==(a=r[5].h))&&E(i,"height",a),(!Z||G&64&&h!==(h=r[6].map(td).join(" ")))&&E(l,"points",h),(!Z||G&64&&f!==(f=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&E(d,"x1",f),(!Z||G&64&&p!==(p=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&E(d,"y1",p),(!Z||G&128&&g!==(g=r[7][0]))&&E(d,"x2",g),(!Z||G&128&&y!==(y=r[7][1]))&&E(d,"y2",y),(!Z||G&64&&v!==(v=r[6][0][0]+(r[6][1][0]-r[6][0][0])/2))&&E(_,"x1",v),(!Z||G&64&&m!==(m=r[6][0][1]+(r[6][1][1]-r[6][0][1])/2))&&E(_,"y1",m),(!Z||G&128&&x!==(x=r[7][0]))&&E(_,"x2",x),(!Z||G&128&&S!==(S=r[7][1]))&&E(_,"y2",S);const Mr={};G&128&&(Mr.x=r[7][0]),G&128&&(Mr.y=r[7][1]),G&8&&(Mr.scale=r[3]),R.$set(Mr),(!Z||G&64&&F!==(F=r[6].map(ed).join(" ")))&&E(M,"points",F),(!Z||G&2)&&E(U,"style",r[1]),(!Z||G&64&&P!==(P=r[6].map(rd).join(" ")))&&E(U,"points",P),(!Z||G&64&&A!==(A=r[6][0][0]))&&E(w,"x1",A),(!Z||G&64&&L!==(L=r[6][0][1]))&&E(w,"y1",L),(!Z||G&64&&O!==(O=r[6][1][0]))&&E(w,"x2",O),(!Z||G&64&&D!==(D=r[6][1][1]))&&E(w,"y2",D),(!Z||G&64&&N!==(N=r[6][1][0]))&&E(B,"x1",N),(!Z||G&64&&k!==(k=r[6][1][1]))&&E(B,"y1",k),(!Z||G&64&&V!==(V=r[6][2][0]))&&E(B,"x2",V),(!Z||G&64&&j!==(j=r[6][2][1]))&&E(B,"y2",j),(!Z||G&64&&at!==(at=r[6][2][0]))&&E(H,"x1",at),(!Z||G&64&&X!==(X=r[6][2][1]))&&E(H,"y1",X),(!Z||G&64&&gt!==(gt=r[6][3][0]))&&E(H,"x2",gt),(!Z||G&64&&lt!==(lt=r[6][3][1]))&&E(H,"y2",lt),(!Z||G&64&&Et!==(Et=r[6][3][0]))&&E(ct,"x1",Et),(!Z||G&64&&te!==(te=r[6][3][1]))&&E(ct,"y1",te),(!Z||G&64&&Gt!==(Gt=r[6][0][0]))&&E(ct,"x2",Gt),(!Z||G&64&&Me!==(Me=r[6][0][1]))&&E(ct,"y2",Me);const Or={};G&64&&(Or.x=r[6][0][0]),G&64&&(Or.y=r[6][0][1]),G&8&&(Or.scale=r[3]),zt.$set(Or);const Br={};G&64&&(Br.x=r[6][1][0]),G&64&&(Br.y=r[6][1][1]),G&8&&(Br.scale=r[3]),we.$set(Br);const Lr={};G&64&&(Lr.x=r[6][2][0]),G&64&&(Lr.y=r[6][2][1]),G&8&&(Lr.scale=r[3]),Ee.$set(Lr);const Dr={};G&64&&(Dr.x=r[6][3][0]),G&64&&(Dr.y=r[6][3][1]),G&8&&(Dr.scale=r[3]),Te.$set(Dr)},i(z){Z||(q(R.$$.fragment,z),q(zt.$$.fragment,z),q(we.$$.fragment,z),q(Ee.$$.fragment,z),q(Te.$$.fragment,z),Z=!0)},o(z){nt(R.$$.fragment,z),nt(zt.$$.fragment,z),nt(we.$$.fragment,z),nt(Ee.$$.fragment,z),nt(Te.$$.fragment,z),Z=!1},d(z){z&&(it(t),it(c),it(u),it(C),it(I),it(T),it(w),it($),it(B),it(st),it(H),it(ft),it(ct),it(Rr),it(Li),it(Di),it(Ni)),Bt(R),Bt(zt,z),Bt(we,z),Bt(Ee,z),Bt(Te,z),Fi=!1,$e(ms)}}}function i1(r){let t,e;return t=new Ga({props:{shape:r[0],transform:r[2],editor:r[8],svgEl:r[4],$$slots:{default:[r1,({grab:i})=>({16:i}),({grab:i})=>i?65536:0]},$$scope:{ctx:r}}}),t.$on("grab",r[12]),t.$on("change",r[13]),t.$on("release",r[14]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,[n]){const s={};n&1&&(s.shape=i[0]),n&4&&(s.transform=i[2]),n&16&&(s.svgEl=i[4]),n&196842&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}const td=r=>`${r[0]},${r[1]}`,ed=r=>`${r[0]},${r[1]}`,rd=r=>`${r[0]},${r[1]}`;function n1(r,t,e){let i,n,s,o,a,{shape:l}=t,{computedStyle:h}=t,{transform:c}=t,{viewportScale:u=1}=t,{svgEl:d}=t,f=!1;const p=(m,x,S)=>{let{x:R,y:C,w:I,h:M,rot:F=0}=m.geometry;const[U,P]=S;if(x==="ROTATION"){const w=Qu(m.geometry,i),A=w[0]+U,L=w[1]+P,O=[R+I/2,C+M/2];F+=t1([w[0],w[1]],[A,L],O),f&&(F=e1(F));const D=2*Math.PI;F=(F%D+D)%D}else if(x==="SHAPE")R+=U,C+=P;else{let w=0,A=0,L=I,O=M;const[D,$]=F!==0?Qv(U,P,F):[U,P];switch(x){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":A+=$;break;case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":O+=$;break}switch(x){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":w+=D;break;case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":L+=D;break}const B=(w+L)/2,N=(A+O)/2;I=Math.abs(L-w),M=Math.abs(O-A);const k=[R+m.geometry.w/2,C+m.geometry.h/2],V=[B-m.geometry.w/2,N-m.geometry.h/2],j=Math.cos(F),st=Math.sin(F),H=k[0]+V[0]*j-V[1]*st,at=k[1]+V[0]*st+V[1]*j;R=H-I/2,C=at-M/2}const T=Ye(s);return{...m,geometry:{x:R,y:C,w:I,h:M,rot:F,bounds:T}}};Vr(()=>{const m=S=>{S.key==="Shift"&&(f=!0)},x=S=>{S.key==="Shift"&&(f=!1)};return window.addEventListener("keydown",m),window.addEventListener("keyup",x),()=>{window.removeEventListener("keydown",m),window.removeEventListener("keyup",x)}});const g=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function y(m){ae.call(this,r,m)}function _(m){ae.call(this,r,m)}function v(m){ae.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,l=m.shape),"computedStyle"in m&&e(1,h=m.computedStyle),"transform"in m&&e(2,c=m.transform),"viewportScale"in m&&e(3,u=m.viewportScale),"svgEl"in m&&e(4,d=m.svgEl)},r.$$.update=()=>{r.$$.dirty&8&&e(11,i=20/u),r.$$.dirty&1&&e(10,n=l.geometry),r.$$.dirty&1024&&e(6,s=Jv(n.x,n.y,n.w,n.h,n.rot)),r.$$.dirty&3072&&e(7,o=Qu(n,i)),r.$$.dirty&1032&&e(5,a=Ua(n.bounds,5/u))},[l,h,c,u,d,a,s,o,p,g,n,i,y,_,v]}class s1 extends Yt{constructor(t){super(),Wt(this,t,n1,i1,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var id=Object.prototype.hasOwnProperty;function Xa(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--&&Xa(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(id.call(r,e)&&++i&&!id.call(t,e)||!(e in t)||!Xa(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const o1=12,a1=(r,t)=>r.polygons.reduce((e,i,n)=>{const s=i.rings.reduce((o,a,l)=>{const h=a.points.map((c,u)=>{const d=u===a.points.length-1?a.points[0]:a.points[u+1],f=(c[0]+d[0])/2,p=(c[1]+d[1])/2,y=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>o1/t;return{point:[f,p],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ja(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function nd(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function sd(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function od(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function Wa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Ya(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function ad(r){let t,e,i,n;return{c(){t=J("circle"),E(t,"cx",e=r[29][0]),E(t,"cy",i=r[29][1]),E(t,"r",n=Hn/r[3]),E(t,"class","svelte-1vxo6dc")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&E(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&E(t,"cy",i),o[0]&8&&n!==(n=Hn/s[3])&&E(t,"r",n)},d(s){s&&it(t)}}}function ld(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=J("mask"),e=J("rect"),a=J("circle"),E(e,"x",i=r[9].x),E(e,"y",n=r[9].y),E(e,"width",s=r[9].w),E(e,"height",o=r[9].h),E(e,"class","svelte-1vxo6dc"),E(a,"cx",l=r[29][0]),E(a,"cy",h=r[29][1]),E(a,"r",c=Hn/r[3]),E(a,"class","svelte-1vxo6dc"),E(t,"id",`${r[18]}-${r[32]}-inner`),E(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){ot(u,t,d),Tt(t,e),Tt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&E(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&E(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&E(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&E(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&E(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&E(a,"cy",h),d[0]&8&&c!==(c=Hn/u[3])&&E(a,"r",c)},d(u){u&&it(t)}}}function hd(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new di({props:{class:"a9s-corner-handle",x:r[29][0],y:r[29][1],scale:r[3],selected:r[8].some(i)}}),t.$on("pointerenter",r[11]),t.$on("pointerleave",r[12]),t.$on("pointerdown",r[14]),t.$on("pointerdown",function(){jt(r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`))&&r[28](`HANDLE-${r[32]}-${r[35]}-${r[37]}`).apply(this,arguments)}),t.$on("pointerup",r[15](r[32],r[35],r[37])),{c(){Lt(t.$$.fragment)},m(n,s){Ot(t,n,s),e=!0},p(n,s){r=n;const o={};s[0]&32&&(o.x=r[29][0]),s[0]&32&&(o.y=r[29][1]),s[0]&8&&(o.scale=r[3]),s[0]&256&&(o.selected=r[8].some(i)),t.$set(o)},i(n){e||(q(t.$$.fragment,n),e=!0)},o(n){nt(t.$$.fragment,n),e=!1},d(n){Bt(t,n)}}}function cd(r){let t,e,i=Ae(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=hd(od(r,i,o));const s=o=>nt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Be()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Ae(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=od(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=hd(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(Boolean);for(let a=0;a<n.length;a+=1)nt(n[a]);e=!1},d(o){o&&it(t),$r(n,o)}}}function ud(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v=r[6]!==void 0&&!r[7]&&ad(Ya(r)),m=r[6]!==void 0&&!r[7]&&ld(Wa(r)),x=Ae(r[30].rings),S=[];for(let C=0;C<x.length;C+=1)S[C]=cd(sd(r,x,C));const R=C=>nt(S[C],1,1,()=>{S[C]=null});return{c(){t=J("g"),e=J("defs"),i=J("mask"),n=J("rect"),h=J("path"),v&&v.c(),m&&m.c(),u=J("path"),f=J("path");for(let C=0;C<S.length;C+=1)S[C].c();E(n,"x",s=r[9].x),E(n,"y",o=r[9].y),E(n,"width",a=r[9].w),E(n,"height",l=r[9].h),E(n,"class","svelte-1vxo6dc"),E(h,"d",c=Zi(r[30])),E(h,"class","svelte-1vxo6dc"),E(i,"id",`${r[18]}-${r[32]}-outer`),E(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),E(u,"class","a9s-outer"),E(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),E(u,"fill-rule","evenodd"),E(u,"d",d=Zi(r[30])),E(f,"class","a9s-inner"),E(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),E(f,"style",r[1]),E(f,"fill-rule","evenodd"),E(f,"d",p=Zi(r[30]))},m(C,I){ot(C,t,I),Tt(t,e),Tt(e,i),Tt(i,n),Tt(i,h),v&&v.m(i,null),m&&m.m(e,null),Tt(t,u),Tt(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);g=!0,y||(_=[Pt(u,"pointerup",r[13]),Pt(u,"pointerdown",function(){jt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Pt(f,"pointerup",r[13]),Pt(f,"pointerdown",function(){jt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!g||I[0]&512&&s!==(s=r[9].x))&&E(n,"x",s),(!g||I[0]&512&&o!==(o=r[9].y))&&E(n,"y",o),(!g||I[0]&512&&a!==(a=r[9].w))&&E(n,"width",a),(!g||I[0]&512&&l!==(l=r[9].h))&&E(n,"height",l),(!g||I[0]&32&&c!==(c=Zi(r[30])))&&E(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Ya(r),I):(v=ad(Ya(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?m?m.p(Wa(r),I):(m=ld(Wa(r)),m.c(),m.m(e,null)):m&&(m.d(1),m=null),(!g||I[0]&32&&d!==(d=Zi(r[30])))&&E(u,"d",d),(!g||I[0]&2)&&E(f,"style",r[1]),(!g||I[0]&32&&p!==(p=Zi(r[30])))&&E(f,"d",p),I[0]&268491048){x=Ae(r[30].rings);let M;for(M=0;M<x.length;M+=1){const F=sd(r,x,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=cd(F),S[M].c(),q(S[M],1),S[M].m(t,null))}for(le(),M=x.length;M<S.length;M+=1)R(M);he()}},i(C){if(!g){for(let I=0;I<x.length;I+=1)q(S[I]);g=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)nt(S[I]);g=!1},d(C){C&&it(t),v&&v.d(),m&&m.d(),$r(S,C),y=!1,$e(_)}}}function dd(r){let t,e;return t=new Vu({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){jt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&1088&&(s.x=r[29][0]),n[0]&1088&&(s.y=r[29][1]),n[0]&8&&(s.scale=r[3]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function l1(r){let t,e,i,n=Ae(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=ud(nd(r,n,l));const o=l=>nt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&dd(ja(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Pe(),a&&a.c(),e=Be()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);ot(l,t,h),a&&a.m(l,h),ot(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Ae(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=nd(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=ud(u),s[c].c(),q(s[c],1),s[c].m(t.parentNode,t))}for(le(),c=n.length;c<s.length;c+=1)o(c);he()}l[6]!==void 0&&!l[7]?a?(a.p(ja(l),h),h[0]&192&&q(a,1)):(a=dd(ja(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(le(),nt(a,1,1,()=>{a=null}),he())},i(l){if(!i){for(let h=0;h<n.length;h+=1)q(s[h]);q(a),i=!0}},o(l){s=s.filter(Boolean);for(let h=0;h<s.length;h+=1)nt(s[h]);nt(a),i=!1},d(l){l&&(it(t),it(e)),$r(s,l),a&&a.d(l)}}}function h1(r){let t,e;return t=new Ga({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[l1,({grab:i})=>({28:i}),({grab:i})=>[i?268435456:0]]},$$scope:{ctx:r}}}),t.$on("change",r[20]),t.$on("grab",r[21]),t.$on("release",r[22]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&1&&(s.shape=i[0]),n[0]&4&&(s.transform=i[2]),n[0]&16&&(s.svgEl=i[4]),n[0]&268437482|n[1]&128&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}const c1=250,u1=1e3,Hn=4.5;function d1(r,t,e){let i,n,s;const o=Wi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,g=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(g.length>0||!n.some(V=>V.visible)){e(6,d=void 0);return}const[L,O]=h.elementToImage(A.offsetX,A.offsetY),D=V=>Math.pow(V[0]-L,2)+Math.pow(V[1]-O,2),$=xv(i).reduce((V,j)=>D(j)<D(V)?j:V),B=n.filter(V=>V.visible).reduce((V,j)=>D(j.point)<D(V.point)?j:V),N=Math.pow(u1/c,2);D($)<N||D(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},m=()=>{document.activeElement!==u&&u.focus()},x=()=>{e(8,g=[]),m()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,L,O)=>D=>{if(!p||Xr||performance.now()-p>c1)return;const $=N=>N.polygon===A&&N.ring===L&&N.point===O,B=g.some($);D.metaKey||D.ctrlKey||D.shiftKey?B?e(8,g=g.filter(N=>!$(N))):e(8,g=[...g,{polygon:A,ring:L,point:O}]):B&&g.length>1?e(8,g=[{polygon:A,ring:L,point:O}]):B?e(8,g=[]):e(8,g=[{polygon:A,ring:L,point:O}]),m()},C=(A,L,O)=>{m();const D=A.geometry.polygons;let $;if(L==="SHAPE")$=D.map(B=>{const N=B.rings.map((V,j)=>({points:V.points.map((H,at)=>[H[0]+O[0],H[1]+O[1]])})),k=Ye(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,V]=L.split("-").map(j=>parseInt(j));$=D.map((j,st)=>{if(st===N){const H=j.rings.map((X,gt)=>gt===k?{points:X.points.map((ft,ct)=>ct===V?[ft[0]+O[0],ft[1]+O[1]]:ft)}:X),at=Ye(H[0].points);return{rings:H,bounds:at}}else return j})}return{...A,geometry:{polygons:$,bounds:ks($)}}},I=A=>async L=>{L.stopPropagation();const O=n[A],D=i.polygons.map((B,N)=>{if(N===O.elementIdx){const k=B.rings.map((j,st)=>st===O.ringIdx?{points:[...j.points.slice(0,O.pointIdx+1),O.point,...j.points.slice(O.pointIdx+1)]}:j),V=Ye(k[0].points);return{rings:k,bounds:V}}else return B});o("change",{...a,geometry:{polygons:D,bounds:ks(D)}}),await Lu();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:L.clientX,clientY:L.clientY,pointerId:L.pointerId,pointerType:L.pointerType,isPrimary:L.isPrimary,buttons:L.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((O,D)=>{if(g.some(B=>B.polygon===D)){const B=O.rings.map((k,V)=>{const j=g.filter(st=>st.polygon===D&&st.ring===V);return j.length&&k.points.length-j.length>=3?{points:k.points.filter((H,at)=>!j.some(X=>X.point===at))}:k}),N=Ye(B[0].points);return{rings:B,bounds:N}}else return O});!Xa(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:ks(A)}}),e(8,g=[]))};Vr(()=>{if(Xr)return;const A=L=>{(L.key==="Delete"||L.key==="Backspace")&&(L.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",A),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",A)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`,U=(A,L,O,{polygon:D,ring:$,point:B})=>D===A&&$===L&&B===O;function P(A){ae.call(this,r,A)}function T(A){ae.call(this,r,A)}function w(A){ae.call(this,r,A)}return r.$$set=A=>{"shape"in A&&e(0,a=A.shape),"computedStyle"in A&&e(1,l=A.computedStyle),"transform"in A&&e(2,h=A.transform),"viewportScale"in A&&e(3,c=A.viewportScale),"svgEl"in A&&e(4,u=A.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Xr?[]:a1(i,c)),r.$$.dirty[0]&40&&e(9,s=Ua(i.bounds,Hn/c))},[a,l,h,c,u,i,d,f,g,s,n,y,_,x,S,R,C,I,F,U,P,T,w]}class f1 extends Yt{constructor(t){super(),Wt(this,t,d1,h1,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}nr.RECTANGLE,nr.POLYGON,nr.MULTIPOLYGON;function p1(r,t,e){let i;const n=Wi();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return Vr(()=>(e(6,u=new o({target:l,props:{shape:s.target.selector,computedStyle:i,transform:h,viewportScale:c,svgEl:l.closest("svg")}})),u.$on("change",d=>{u.$$set({shape:d.detail}),n("change",d.detail)}),u.$on("grab",d=>n("grab",d.detail)),u.$on("release",d=>n("release",d.detail)),()=>{u.$destroy()})),r.$$set=d=>{"annotation"in d&&e(0,s=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=Bv(s,a,{selected:!0,hovered:!0})),r.$$.dirty&65&&s&&(u==null||u.$set({shape:s.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})},[s,o,a,l,h,c,u,i]}class m1 extends Yt{constructor(t){super(),Wt(this,t,p1,null,Ut,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1;var fi=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(fi||{}),fd=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(fd||{}),za=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(za||{}),vt=(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))(vt||{}),sr=(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))(sr||{}),W=(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))(W||{}),Ji=(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))(Ji||{}),mt=(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))(mt||{}),Q=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(Q||{}),br=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(br||{}),jr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(jr||{}),or=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(or||{}),Le=(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))(Le||{}),ar=(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))(ar||{}),qa=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(qa||{}),He=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(He||{}),ie=(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))(ie||{}),re=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(re||{}),lr=(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))(lr||{});const tt={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 Ka=/iPhone/i,pd=/iPod/i,md=/iPad/i,gd=/\biOS-universal(?:.+)Mac\b/i,Za=/\bAndroid(?:.+)Mobile\b/i,yd=/Android/i,Qi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Us=/Silk/i,xr=/Windows Phone/i,_d=/\bWindows(?:.+)ARM\b/i,vd=/BlackBerry/i,bd=/BB10/i,xd=/Opera Mini/i,wd=/\b(CriOS|Chrome)(?:.+)Mobile/i,Ed=/Mobile(?:.+)Firefox\b/i,Td=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function g1(r){return function(t){return t.test(r)}}function Ad(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 n=g1(e),s={apple:{phone:n(Ka)&&!n(xr),ipod:n(pd),tablet:!n(Ka)&&(n(md)||Td(t))&&!n(xr),universal:n(gd),device:(n(Ka)||n(pd)||n(md)||n(gd)||Td(t))&&!n(xr)},amazon:{phone:n(Qi),tablet:!n(Qi)&&n(Us),device:n(Qi)||n(Us)},android:{phone:!n(xr)&&n(Qi)||!n(xr)&&n(Za),tablet:!n(xr)&&!n(Qi)&&!n(Za)&&(n(Us)||n(yd)),device:!n(xr)&&(n(Qi)||n(Us)||n(Za)||n(yd))||n(/\bokhttp\b/i)},windows:{phone:n(xr),tablet:n(_d),device:n(xr)||n(_d)},other:{blackberry:n(vd),blackberry10:n(bd),opera:n(xd),firefox:n(Ed),chrome:n(wd),device:n(vd)||n(bd)||n(xd)||n(Ed)||n(wd)},any:!1,phone:!1,tablet:!1};return s.any=s.apple.device||s.android.device||s.windows.device||s.other.device,s.phone=s.apple.phone||s.android.phone||s.windows.phone,s.tablet=s.apple.tablet||s.android.tablet||s.windows.tablet,s}const y1=Ad.default??Ad,wr=y1(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var Sd={exports:{}};(function(r){var t=Object.prototype.hasOwnProperty,e="~";function i(){}Object.create&&(i.prototype=Object.create(null),new i().__proto__||(e=!1));function n(l,h,c){this.fn=l,this.context=h,this.once=c||!1}function s(l,h,c,u,d){if(typeof c!="function")throw new TypeError("The listener must be a function");var f=new n(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 g=e?e+h:h;if(!this._events[g])return!1;var y=this._events[g],_=arguments.length,v,m;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,c),!0;case 3:return y.fn.call(y.context,c,u),!0;case 4:return y.fn.call(y.context,c,u,d),!0;case 5:return y.fn.call(y.context,c,u,d,f),!0;case 6:return y.fn.call(y.context,c,u,d,f,p),!0}for(m=1,v=new Array(_-1);m<_;m++)v[m-1]=arguments[m];y.fn.apply(y.context,v)}else{var x=y.length,S;for(m=0;m<x;m++)switch(y[m].once&&this.removeListener(h,y[m].fn,void 0,!0),_){case 1:y[m].fn.call(y[m].context);break;case 2:y[m].fn.call(y[m].context,c);break;case 3:y[m].fn.call(y[m].context,c,u);break;case 4:y[m].fn.call(y[m].context,c,u,d);break;default:if(!v)for(S=1,v=new Array(_-1);S<_;S++)v[S-1]=arguments[S];y[m].fn.apply(y[m].context,v)}}return!0},a.prototype.on=function(h,c,u){return s(this,h,c,u,!1)},a.prototype.once=function(h,c,u){return s(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 g=0,y=[],_=p.length;g<_;g++)(p[g].fn!==c||d&&!p[g].once||u&&p[g].context!==u)&&y.push(p[g]);y.length?this._events[f]=y.length===1?y[0]:y: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})(Sd);var _1=Sd.exports;const Vn=ka(_1);var Ja={exports:{}};Ja.exports=Gs,Ja.exports.default=Gs;function Gs(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=Cd(r,0,n,e,!0),o=[];if(!s||s.next===s.prev)return o;var a,l,h,c,u,d,f;if(i&&(s=E1(r,t,s,e)),r.length>80*e){a=h=r[0],l=c=r[1];for(var p=e;p<n;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 Xn(s,o,e,a,l,f,0),o}function Cd(r,t,e,i,n){var s,o;if(n===el(r,t,e,i)>0)for(s=t;s<e;s+=i)o=Rd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=Rd(s,r[s],r[s+1],o);return o&&$s(o,o.next)&&(Wn(o),o=o.next),o}function pi(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&($s(e,e.next)||$t(e.prev,e,e.next)===0)){if(Wn(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Xn(r,t,e,i,n,s,o){if(r){!o&&s&&I1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?b1(r,i,n,s):v1(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),Wn(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=x1(pi(r),t,e),Xn(r,t,e,i,n,s,2)):o===2&&w1(r,t,e,i,n,s):Xn(pi(r),t,e,i,n,s,1);break}}}}function v1(r){var t=r.prev,e=r,i=r.next;if($t(t,e,i)>=0)return!1;for(var n=t.x,s=e.x,o=i.x,a=t.y,l=e.y,h=i.y,c=n<s?n<o?n:o:s<o?s:o,u=a<l?a<h?a:h:l<h?l:h,d=n>s?n>o?n:o:s>o?s: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&&tn(n,a,s,l,o,h,p.x,p.y)&&$t(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function b1(r,t,e,i){var n=r.prev,s=r,o=r.next;if($t(n,s,o)>=0)return!1;for(var a=n.x,l=s.x,h=o.x,c=n.y,u=s.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,g=a>l?a>h?a:h:l>h?l:h,y=c>u?c>d?c:d:u>d?u:d,_=Qa(f,p,t,e,i),v=Qa(g,y,t,e,i),m=r.prevZ,x=r.nextZ;m&&m.z>=_&&x&&x.z<=v;){if(m.x>=f&&m.x<=g&&m.y>=p&&m.y<=y&&m!==n&&m!==o&&tn(a,c,l,u,h,d,m.x,m.y)&&$t(m.prev,m,m.next)>=0||(m=m.prevZ,x.x>=f&&x.x<=g&&x.y>=p&&x.y<=y&&x!==n&&x!==o&&tn(a,c,l,u,h,d,x.x,x.y)&&$t(x.prev,x,x.next)>=0))return!1;x=x.nextZ}for(;m&&m.z>=_;){if(m.x>=f&&m.x<=g&&m.y>=p&&m.y<=y&&m!==n&&m!==o&&tn(a,c,l,u,h,d,m.x,m.y)&&$t(m.prev,m,m.next)>=0)return!1;m=m.prevZ}for(;x&&x.z<=v;){if(x.x>=f&&x.x<=g&&x.y>=p&&x.y<=y&&x!==n&&x!==o&&tn(a,c,l,u,h,d,x.x,x.y)&&$t(x.prev,x,x.next)>=0)return!1;x=x.nextZ}return!0}function x1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!$s(n,s)&&Id(n,i,i.next,s)&&jn(n,s)&&jn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),Wn(i),Wn(i.next),i=r=s),i=i.next}while(i!==r);return pi(i)}function w1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&M1(o,a)){var l=Pd(o,a);o=pi(o,o.next),l=pi(l,l.next),Xn(o,t,e,i,n,s,0),Xn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function E1(r,t,e,i){var n=[],s,o,a,l,h;for(s=0,o=t.length;s<o;s++)a=t[s]*i,l=s<o-1?t[s+1]*i:r.length,h=Cd(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(R1(h));for(n.sort(T1),s=0;s<n.length;s++)e=A1(n[s],e);return e}function T1(r,t){return r.x-t.x}function A1(r,t){var e=S1(r,t);if(!e)return t;var i=Pd(e,r);return pi(i,i.next),pi(e,e.next)}function S1(r,t){var e=t,i=r.x,n=r.y,s=-1/0,o;do{if(n<=e.y&&n>=e.next.y&&e.next.y!==e.y){var a=e.x+(n-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(a<=i&&a>s&&(s=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&&tn(n<c?i:s,n,h,c,n<c?s:i,n,e.x,e.y)&&(d=Math.abs(n-e.y)/(i-e.x),jn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&C1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function C1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function I1(r,t,e,i){var n=r;do n.z===0&&(n.z=Qa(n.x,n.y,t,e,i)),n.prevZ=n.prev,n.nextZ=n.next,n=n.next;while(n!==r);n.prevZ.nextZ=null,n.prevZ=null,P1(n)}function P1(r){var t,e,i,n,s,o,a,l,h=1;do{for(e=r,r=null,s=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)?(n=e,e=e.nextZ,a--):(n=i,i=i.nextZ,l--),s?s.nextZ=n:r=n,n.prevZ=s,s=n;e=i}s.nextZ=null,h*=2}while(o>1);return r}function Qa(r,t,e,i,n){return r=(r-e)*n|0,t=(t-i)*n|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 R1(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 tn(r,t,e,i,n,s,o,a){return(n-o)*(t-a)>=(r-o)*(s-a)&&(r-o)*(i-a)>=(e-o)*(t-a)&&(e-o)*(s-a)>=(n-o)*(i-a)}function M1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!O1(r,t)&&(jn(r,t)&&jn(t,r)&&B1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||$s(r,t)&&$t(r.prev,r,r.next)>0&&$t(t.prev,t,t.next)>0)}function $t(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function $s(r,t){return r.x===t.x&&r.y===t.y}function Id(r,t,e,i){var n=Vs($t(r,t,e)),s=Vs($t(r,t,i)),o=Vs($t(e,i,r)),a=Vs($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Hs(r,e,t)||s===0&&Hs(r,i,t)||o===0&&Hs(e,r,i)||a===0&&Hs(e,t,i))}function Hs(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 Vs(r){return r>0?1:r<0?-1:0}function O1(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&&Id(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function jn(r,t){return $t(r.prev,r,r.next)<0?$t(r,t,r.next)>=0&&$t(r,r.prev,t)>=0:$t(r,t,r.prev)<0||$t(r,r.next,t)<0}function B1(r,t){var e=r,i=!1,n=(r.x+t.x)/2,s=(r.y+t.y)/2;do e.y>s!=e.next.y>s&&e.next.y!==e.y&&n<(e.next.x-e.x)*(s-e.y)/(e.next.y-e.y)+e.x&&(i=!i),e=e.next;while(e!==r);return i}function Pd(r,t){var e=new tl(r.i,r.x,r.y),i=new tl(t.i,t.x,t.y),n=r.next,s=t.prev;return r.next=t,t.prev=r,e.next=n,n.prev=e,i.next=e,e.prev=i,s.next=i,i.prev=s,i}function Rd(r,t,e,i){var n=new tl(r,t,e);return i?(n.next=i.next,n.prev=i,i.next.prev=n,i.next=n):(n.prev=n,n.next=n),n}function Wn(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 tl(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}Gs.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(el(r,0,s,e));if(n)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(el(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 el(r,t,e,i){for(var n=0,s=t,o=e-i;s<e;s+=i)n+=(r[o]-r[s])*(r[s+1]+r[o+1]),o=s;return n}Gs.flatten=function(r){for(var t=r[0][0].length,e={vertices:[],holes:[],dimensions:t},i=0,n=0;n<r.length;n++){for(var s=0;s<r[n].length;s++)for(var o=0;o<t;o++)e.vertices.push(r[n][s][o]);n>0&&(i+=r[n-1].length,e.holes.push(i))}return e};var L1=Ja.exports;const D1=ka(L1);var Xs={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Xs.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof Gn=="object"&&Gn;(s.global===s||s.window===s||s.self===s)&&(e=s);var o,a=2147483647,l=36,h=1,c=26,u=38,d=700,f=72,p=128,g="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,m={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},x=l-h,S=Math.floor,R=String.fromCharCode,C;function I(B){throw new RangeError(m[B])}function M(B,N){for(var k=B.length,V=[];k--;)V[k]=N(B[k]);return V}function F(B,N){var k=B.split("@"),V="";k.length>1&&(V=k[0]+"@",B=k[1]),B=B.replace(v,".");var j=B.split("."),st=M(j,N).join(".");return V+st}function U(B){for(var N=[],k=0,V=B.length,j,st;k<V;)j=B.charCodeAt(k++),j>=55296&&j<=56319&&k<V?(st=B.charCodeAt(k++),(st&64512)==56320?N.push(((j&1023)<<10)+(st&1023)+65536):(N.push(j),k--)):N.push(j);return N}function P(B){return M(B,function(N){var k="";return N>65535&&(N-=65536,k+=R(N>>>10&1023|55296),N=56320|N&1023),k+=R(N),k}).join("")}function T(B){return B-48<10?B-22:B-65<26?B-65:B-97<26?B-97:l}function w(B,N){return B+22+75*(B<26)-((N!=0)<<5)}function A(B,N,k){var V=0;for(B=k?S(B/d):B>>1,B+=S(B/N);B>x*c>>1;V+=l)B=S(B/x);return S(V+(x+1)*B/(B+u))}function L(B){var N=[],k=B.length,V,j=0,st=p,H=f,at,X,gt,lt,ft,ct,Et,te,Gt;for(at=B.lastIndexOf(g),at<0&&(at=0),X=0;X<at;++X)B.charCodeAt(X)>=128&&I("not-basic"),N.push(B.charCodeAt(X));for(gt=at>0?at+1:0;gt<k;){for(lt=j,ft=1,ct=l;gt>=k&&I("invalid-input"),Et=T(B.charCodeAt(gt++)),(Et>=l||Et>S((a-j)/ft))&&I("overflow"),j+=Et*ft,te=ct<=H?h:ct>=H+c?c:ct-H,!(Et<te);ct+=l)Gt=l-te,ft>S(a/Gt)&&I("overflow"),ft*=Gt;V=N.length+1,H=A(j-lt,V,lt==0),S(j/V)>a-st&&I("overflow"),st+=S(j/V),j%=V,N.splice(j++,0,st)}return P(N)}function O(B){var N,k,V,j,st,H,at,X,gt,lt,ft,ct=[],Et,te,Gt,Me;for(B=U(B),Et=B.length,N=p,k=0,st=f,H=0;H<Et;++H)ft=B[H],ft<128&&ct.push(R(ft));for(V=j=ct.length,j&&ct.push(g);V<Et;){for(at=a,H=0;H<Et;++H)ft=B[H],ft>=N&&ft<at&&(at=ft);for(te=V+1,at-N>S((a-k)/te)&&I("overflow"),k+=(at-N)*te,N=at,H=0;H<Et;++H)if(ft=B[H],ft<N&&++k>a&&I("overflow"),ft==N){for(X=k,gt=l;lt=gt<=st?h:gt>=st+c?c:gt-st,!(X<lt);gt+=l)Me=X-lt,Gt=l-lt,ct.push(R(w(lt+Me%Gt,0))),X=S(Me/Gt);ct.push(R(w(X,0))),st=A(k,te,V==j),k=0,++V}++k,++N}return ct.join("")}function D(B){return F(B,function(N){return y.test(N)?L(N.slice(4).toLowerCase()):N})}function $(B){return F(B,function(N){return _.test(N)?"xn--"+O(N):N})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:L,encode:O,toASCII:$,toUnicode:D},i&&n)if(r.exports==i)n.exports=o;else for(C in o)o.hasOwnProperty(C)&&(i[C]=o[C]);else e.punycode=o})(Gn)}(Xs,Xs.exports);var N1=Xs.exports,en=TypeError;const F1=fv(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var rl=typeof Map=="function"&&Map.prototype,il=Object.getOwnPropertyDescriptor&&rl?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,js=rl&&il&&typeof il.get=="function"?il.get:null,Md=rl&&Map.prototype.forEach,nl=typeof Set=="function"&&Set.prototype,sl=Object.getOwnPropertyDescriptor&&nl?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Ws=nl&&sl&&typeof sl.get=="function"?sl.get:null,Od=nl&&Set.prototype.forEach,k1=typeof WeakMap=="function"&&WeakMap.prototype,Yn=k1?WeakMap.prototype.has:null,U1=typeof WeakSet=="function"&&WeakSet.prototype,zn=U1?WeakSet.prototype.has:null,G1=typeof WeakRef=="function"&&WeakRef.prototype,Bd=G1?WeakRef.prototype.deref:null,$1=Boolean.prototype.valueOf,H1=Object.prototype.toString,V1=Function.prototype.toString,X1=String.prototype.match,ol=String.prototype.slice,Wr=String.prototype.replace,j1=String.prototype.toUpperCase,Ld=String.prototype.toLowerCase,Dd=RegExp.prototype.test,Nd=Array.prototype.concat,hr=Array.prototype.join,W1=Array.prototype.slice,Fd=Math.floor,al=typeof BigInt=="function"?BigInt.prototype.valueOf:null,ll=Object.getOwnPropertySymbols,hl=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,rn=typeof Symbol=="function"&&typeof Symbol.iterator=="object",qn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===rn||!0)?Symbol.toStringTag:null,kd=Object.prototype.propertyIsEnumerable,Ud=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Gd(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||Dd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-Fd(-r):Fd(r);if(i!==r){var n=String(i),s=ol.call(t,n.length+1);return Wr.call(n,e,"$&_")+"."+Wr.call(Wr.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return Wr.call(t,e,"$&_")}var cl=F1,$d=cl.custom,Hd=Wd($d)?$d:null,Vd={__proto__:null,double:'"',single:"'"},Y1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Ys=function r(t,e,i,n){var s=e||{};if(Er(s,"quoteStyle")&&!Er(Vd,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(Er(s,"maxStringLength")&&(typeof s.maxStringLength=="number"?s.maxStringLength<0&&s.maxStringLength!==1/0:s.maxStringLength!==null))throw new TypeError('option "maxStringLength", if provided, must be a positive integer, Infinity, or `null`');var o=Er(s,"customInspect")?s.customInspect:!0;if(typeof o!="boolean"&&o!=="symbol")throw new TypeError("option \"customInspect\", if provided, must be `true`, `false`, or `'symbol'`");if(Er(s,"indent")&&s.indent!==null&&s.indent!==" "&&!(parseInt(s.indent,10)===s.indent&&s.indent>0))throw new TypeError('option "indent" must be "\\t", an integer > 0, or `null`');if(Er(s,"numericSeparator")&&typeof s.numericSeparator!="boolean")throw new TypeError('option "numericSeparator", if provided, must be `true` or `false`');var a=s.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 zd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Gd(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Gd(t,h):h}var c=typeof s.depth>"u"?5:s.depth;if(typeof i>"u"&&(i=0),i>=c&&c>0&&typeof t=="object")return ul(t)?"[Array]":"[Object]";var u=ub(s,i);if(typeof n>"u")n=[];else if(Yd(n,t)>=0)return"[Circular]";function d(T,w,A){if(w&&(n=W1.call(n),n.push(w)),A){var L={depth:s.depth};return Er(s,"quoteStyle")&&(L.quoteStyle=s.quoteStyle),r(T,L,i+1,n)}return r(T,s,i+1,n)}if(typeof t=="function"&&!jd(t)){var f=rb(t),p=zs(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+hr.call(p,", ")+" }":"")}if(Wd(t)){var g=rn?Wr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):hl.call(t);return typeof t=="object"&&!rn?Kn(g):g}if(lb(t)){for(var y="<"+Ld.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Xd(z1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+Ld.call(String(t.nodeName))+">",y}if(ul(t)){if(t.length===0)return"[]";var m=zs(t,d);return u&&!cb(m)?"["+fl(m,u)+"]":"[ "+hr.call(m,", ")+" ]"}if(K1(t)){var x=zs(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!kd.call(t,"cause")?"{ ["+String(t)+"] "+hr.call(Nd.call("[cause]: "+d(t.cause),x),", ")+" }":x.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+hr.call(x,", ")+" }"}if(typeof t=="object"&&o){if(Hd&&typeof t[Hd]=="function"&&cl)return cl(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(ib(t)){var S=[];return Md&&Md.call(t,function(T,w){S.push(d(w,t,!0)+" => "+d(T,t))}),qd("Map",js.call(t),S,u)}if(ob(t)){var R=[];return Od&&Od.call(t,function(T){R.push(d(T,t))}),qd("Set",Ws.call(t),R,u)}if(nb(t))return dl("WeakMap");if(ab(t))return dl("WeakSet");if(sb(t))return dl("WeakRef");if(J1(t))return Kn(d(Number(t)));if(tb(t))return Kn(d(al.call(t)));if(Q1(t))return Kn($1.call(t));if(Z1(t))return Kn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof Gn<"u"&&t===Gn)return"{ [object globalThis] }";if(!q1(t)&&!jd(t)){var C=zs(t,d),I=Ud?Ud(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&qn&&Object(t)===t&&qn in t?ol.call(Yr(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+hr.call(Nd.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+fl(C,u)+"}":P+"{ "+hr.call(C,", ")+" }"}return String(t)};function Xd(r,t,e){var i=e.quoteStyle||t,n=Vd[i];return n+r+n}function z1(r){return Wr.call(String(r),/"/g,"&quot;")}function mi(r){return!qn||!(typeof r=="object"&&(qn in r||typeof r[qn]<"u"))}function ul(r){return Yr(r)==="[object Array]"&&mi(r)}function q1(r){return Yr(r)==="[object Date]"&&mi(r)}function jd(r){return Yr(r)==="[object RegExp]"&&mi(r)}function K1(r){return Yr(r)==="[object Error]"&&mi(r)}function Z1(r){return Yr(r)==="[object String]"&&mi(r)}function J1(r){return Yr(r)==="[object Number]"&&mi(r)}function Q1(r){return Yr(r)==="[object Boolean]"&&mi(r)}function Wd(r){if(rn)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!hl)return!1;try{return hl.call(r),!0}catch{}return!1}function tb(r){if(!r||typeof r!="object"||!al)return!1;try{return al.call(r),!0}catch{}return!1}var eb=Object.prototype.hasOwnProperty||function(r){return r in this};function Er(r,t){return eb.call(r,t)}function Yr(r){return H1.call(r)}function rb(r){if(r.name)return r.name;var t=X1.call(V1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Yd(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 ib(r){if(!js||!r||typeof r!="object")return!1;try{js.call(r);try{Ws.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function nb(r){if(!Yn||!r||typeof r!="object")return!1;try{Yn.call(r,Yn);try{zn.call(r,zn)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function sb(r){if(!Bd||!r||typeof r!="object")return!1;try{return Bd.call(r),!0}catch{}return!1}function ob(r){if(!Ws||!r||typeof r!="object")return!1;try{Ws.call(r);try{js.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function ab(r){if(!zn||!r||typeof r!="object")return!1;try{zn.call(r,zn);try{Yn.call(r,Yn)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function lb(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function zd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return zd(ol.call(r,0,t.maxStringLength),t)+i}var n=Y1[t.quoteStyle||"single"];n.lastIndex=0;var s=Wr.call(Wr.call(r,n,"\\$1"),/[\x00-\x1f]/g,hb);return Xd(s,"single",t)}function hb(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":"")+j1.call(t.toString(16))}function Kn(r){return"Object("+r+")"}function dl(r){return r+" { ? }"}function qd(r,t,e,i){var n=i?fl(e,i):hr.call(e,", ");return r+" ("+t+") {"+n+"}"}function cb(r){for(var t=0;t<r.length;t++)if(Yd(r[t],`
2
2
  `)>=0)return!1;return!0}function ub(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=hr.call(Array(r.indent+1)," ");else return null;return{base:e,prev:hr.call(Array(t+1),e)}}function fl(r,t){if(r.length===0)return"";var e=`
3
3
  `+t.prev+t.base;return e+hr.call(r,","+e)+`
4
4
  `+t.prev}function zs(r,t){var e=ul(r),i=[];if(e){i.length=r.length;for(var n=0;n<r.length;n++)i[n]=Er(r,n)?t(r[n],r):""}var s=typeof ll=="function"?ll(r):[],o;if(rn){o={};for(var a=0;a<s.length;a++)o["$"+s[a]]=s[a]}for(var l in r)Er(r,l)&&(e&&String(Number(l))===l&&l<r.length||rn&&o["$"+l]instanceof Symbol||(Dd.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof ll=="function")for(var h=0;h<s.length;h++)kd.call(r,s[h])&&i.push("["+t(s[h])+"]: "+t(r[s[h]],r));return i}var db=Ys,fb=en,qs=function(r,t,e){for(var i=r,n;(n=i.next)!=null;i=n)if(n.key===t)return i.next=n.next,e||(n.next=r.next,r.next=n),n},pb=function(r,t){if(r){var e=qs(r,t);return e&&e.value}},mb=function(r,t,e){var i=qs(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},gb=function(r,t){return r?!!qs(r,t):!1},yb=function(r,t){if(r)return qs(r,t,!0)},_b=function(){var t,e={assert:function(i){if(!e.has(i))throw new fb("Side channel does not contain "+db(i))},delete:function(i){var n=yb(t,i);return n&&t&&!t.next&&(t=void 0),!!n},get:function(i){return pb(t,i)},has:function(i){return gb(t,i)},set:function(i,n){t||(t={next:void 0}),mb(t,i,n)}};return e},Kd=Object,vb=Error,bb=EvalError,xb=RangeError,wb=ReferenceError,Eb=SyntaxError,Tb=URIError,Ab=Math.abs,Sb=Math.floor,Cb=Math.max,Ib=Math.min,Pb=Math.pow,Rb=Math.round,Mb=Number.isNaN||function(t){return t!==t},Ob=Mb,Bb=function(t){return Ob(t)||t===0?t:t<0?-1:1},Lb=Object.getOwnPropertyDescriptor,Ks=Lb;if(Ks)try{Ks([],"length")}catch{Ks=null}var Zd=Ks,Zs=Object.defineProperty||!1;if(Zs)try{Zs({},"a",{value:1})}catch{Zs=!1}var Db=Zs,pl,Jd;function Nb(){return Jd||(Jd=1,pl=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 n=42;t[e]=n;for(var s in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var o=Object.getOwnPropertySymbols(t);if(o.length!==1||o[0]!==e||!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var a=Object.getOwnPropertyDescriptor(t,e);if(a.value!==n||a.enumerable!==!0)return!1}return!0}),pl}var ml,Qd;function Fb(){if(Qd)return ml;Qd=1;var r=typeof Symbol<"u"&&Symbol,t=Nb();return ml=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},ml}var gl,tf;function ef(){return tf||(tf=1,gl=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),gl}var yl,rf;function nf(){if(rf)return yl;rf=1;var r=Kd;return yl=r.getPrototypeOf||null,yl}var kb="Function.prototype.bind called on incompatible ",Ub=Object.prototype.toString,Gb=Math.max,$b="[object Function]",sf=function(t,e){for(var i=[],n=0;n<t.length;n+=1)i[n]=t[n];for(var s=0;s<e.length;s+=1)i[s+t.length]=e[s];return i},Hb=function(t,e){for(var i=[],n=e,s=0;n<t.length;n+=1,s+=1)i[s]=t[n];return i},Vb=function(r,t){for(var e="",i=0;i<r.length;i+=1)e+=r[i],i+1<r.length&&(e+=t);return e},Xb=function(t){var e=this;if(typeof e!="function"||Ub.apply(e)!==$b)throw new TypeError(kb+e);for(var i=Hb(arguments,1),n,s=function(){if(this instanceof n){var c=e.apply(this,sf(i,arguments));return Object(c)===c?c:this}return e.apply(t,sf(i,arguments))},o=Gb(0,e.length-i.length),a=[],l=0;l<o;l++)a[l]="$"+l;if(n=Function("binder","return function ("+Vb(a,",")+"){ return binder.apply(this,arguments); }")(s),e.prototype){var h=function(){};h.prototype=e.prototype,n.prototype=new h,h.prototype=null}return n},jb=Xb,Js=Function.prototype.bind||jb,_l=Function.prototype.call,vl,of;function af(){return of||(of=1,vl=Function.prototype.apply),vl}var Wb=typeof Reflect<"u"&&Reflect&&Reflect.apply,Yb=Js,zb=af(),qb=_l,Kb=Wb,Zb=Kb||Yb.call(qb,zb),Jb=Js,Qb=en,tx=_l,ex=Zb,lf=function(t){if(t.length<1||typeof t[0]!="function")throw new Qb("a function is required");return ex(Jb,tx,t)},bl,hf;function rx(){if(hf)return bl;hf=1;var r=lf,t=Zd,e;try{e=[].__proto__===Array.prototype}catch(o){if(!o||typeof o!="object"||!("code"in o)||o.code!=="ERR_PROTO_ACCESS")throw o}var i=!!e&&t&&t(Object.prototype,"__proto__"),n=Object,s=n.getPrototypeOf;return bl=i&&typeof i.get=="function"?r([i.get]):typeof s=="function"?function(a){return s(a==null?a:n(a))}:!1,bl}var xl,cf;function ix(){if(cf)return xl;cf=1;var r=ef(),t=nf(),e=rx();return xl=r?function(n){return r(n)}:t?function(n){if(!n||typeof n!="object"&&typeof n!="function")throw new TypeError("getProto: not an object");return t(n)}:e?function(n){return e(n)}:null,xl}var wl,uf;function nx(){if(uf)return wl;uf=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=Js;return wl=e.call(r,t),wl}var At,sx=Kd,ox=vb,ax=bb,lx=xb,hx=wb,nn=Eb,sn=en,cx=Tb,ux=Ab,dx=Sb,fx=Cb,px=Ib,mx=Pb,gx=Rb,yx=Bb,df=Function,El=function(r){try{return df('"use strict"; return ('+r+").constructor;")()}catch{}},Zn=Zd,_x=Db,Tl=function(){throw new sn},vx=Zn?function(){try{return arguments.callee,Tl}catch{try{return Zn(arguments,"callee").get}catch{return Tl}}}():Tl,on=Fb()(),ce=ix(),bx=nf(),xx=ef(),ff=af(),Jn=_l,an={},wx=typeof Uint8Array>"u"||!ce?At:ce(Uint8Array),gi={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?At:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?At:ArrayBuffer,"%ArrayIteratorPrototype%":on&&ce?ce([][Symbol.iterator]()):At,"%AsyncFromSyncIteratorPrototype%":At,"%AsyncFunction%":an,"%AsyncGenerator%":an,"%AsyncGeneratorFunction%":an,"%AsyncIteratorPrototype%":an,"%Atomics%":typeof Atomics>"u"?At:Atomics,"%BigInt%":typeof BigInt>"u"?At:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?At:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?At:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?At:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":ox,"%eval%":eval,"%EvalError%":ax,"%Float16Array%":typeof Float16Array>"u"?At:Float16Array,"%Float32Array%":typeof Float32Array>"u"?At:Float32Array,"%Float64Array%":typeof Float64Array>"u"?At:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?At:FinalizationRegistry,"%Function%":df,"%GeneratorFunction%":an,"%Int8Array%":typeof Int8Array>"u"?At:Int8Array,"%Int16Array%":typeof Int16Array>"u"?At:Int16Array,"%Int32Array%":typeof Int32Array>"u"?At:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":on&&ce?ce(ce([][Symbol.iterator]())):At,"%JSON%":typeof JSON=="object"?JSON:At,"%Map%":typeof Map>"u"?At:Map,"%MapIteratorPrototype%":typeof Map>"u"||!on||!ce?At:ce(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":sx,"%Object.getOwnPropertyDescriptor%":Zn,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?At:Promise,"%Proxy%":typeof Proxy>"u"?At:Proxy,"%RangeError%":lx,"%ReferenceError%":hx,"%Reflect%":typeof Reflect>"u"?At:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?At:Set,"%SetIteratorPrototype%":typeof Set>"u"||!on||!ce?At:ce(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?At:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":on&&ce?ce(""[Symbol.iterator]()):At,"%Symbol%":on?Symbol:At,"%SyntaxError%":nn,"%ThrowTypeError%":vx,"%TypedArray%":wx,"%TypeError%":sn,"%Uint8Array%":typeof Uint8Array>"u"?At:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?At:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?At:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?At:Uint32Array,"%URIError%":cx,"%WeakMap%":typeof WeakMap>"u"?At:WeakMap,"%WeakRef%":typeof WeakRef>"u"?At:WeakRef,"%WeakSet%":typeof WeakSet>"u"?At:WeakSet,"%Function.prototype.call%":Jn,"%Function.prototype.apply%":ff,"%Object.defineProperty%":_x,"%Object.getPrototypeOf%":bx,"%Math.abs%":ux,"%Math.floor%":dx,"%Math.max%":fx,"%Math.min%":px,"%Math.pow%":mx,"%Math.round%":gx,"%Math.sign%":yx,"%Reflect.getPrototypeOf%":xx};if(ce)try{null.error}catch(r){var Ex=ce(ce(r));gi["%Error.prototype%"]=Ex}var Tx=function r(t){var e;if(t==="%AsyncFunction%")e=El("async function () {}");else if(t==="%GeneratorFunction%")e=El("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=El("async function* () {}");else if(t==="%AsyncGenerator%"){var i=r("%AsyncGeneratorFunction%");i&&(e=i.prototype)}else if(t==="%AsyncIteratorPrototype%"){var n=r("%AsyncGenerator%");n&&ce&&(e=ce(n.prototype))}return gi[t]=e,e},pf={__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"]},Qn=Js,Qs=nx(),Ax=Qn.call(Jn,Array.prototype.concat),Sx=Qn.call(ff,Array.prototype.splice),mf=Qn.call(Jn,String.prototype.replace),to=Qn.call(Jn,String.prototype.slice),Cx=Qn.call(Jn,RegExp.prototype.exec),Ix=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,Px=/\\(\\)?/g,Rx=function(t){var e=to(t,0,1),i=to(t,-1);if(e==="%"&&i!=="%")throw new nn("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new nn("invalid intrinsic syntax, expected opening `%`");var n=[];return mf(t,Ix,function(s,o,a,l){n[n.length]=a?mf(l,Px,"$1"):o||s}),n},Mx=function(t,e){var i=t,n;if(Qs(pf,i)&&(n=pf[i],i="%"+n[0]+"%"),Qs(gi,i)){var s=gi[i];if(s===an&&(s=Tx(i)),typeof s>"u"&&!e)throw new sn("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:s}}throw new nn("intrinsic "+t+" does not exist!")},Al=function(t,e){if(typeof t!="string"||t.length===0)throw new sn("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new sn('"allowMissing" argument must be a boolean');if(Cx(/^%?[^%]*%?$/,t)===null)throw new nn("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=Rx(t),n=i.length>0?i[0]:"",s=Mx("%"+n+"%",e),o=s.name,a=s.value,l=!1,h=s.alias;h&&(n=h[0],Sx(i,Ax([0,1],h)));for(var c=1,u=!0;c<i.length;c+=1){var d=i[c],f=to(d,0,1),p=to(d,-1);if((f==='"'||f==="'"||f==="`"||p==='"'||p==="'"||p==="`")&&f!==p)throw new nn("property names with quotes must have matching quotes");if((d==="constructor"||!u)&&(l=!0),n+="."+d,o="%"+n+"%",Qs(gi,o))a=gi[o];else if(a!=null){if(!(d in a)){if(!e)throw new sn("base intrinsic for "+t+" exists, but the property is not available.");return}if(Zn&&c+1>=i.length){var g=Zn(a,d);u=!!g,u&&"get"in g&&!("originalValue"in g.get)?a=g.get:a=a[d]}else u=Qs(a,d),a=a[d];u&&!l&&(gi[o]=a)}}return a},gf=Al,yf=lf,Ox=yf([gf("%String.prototype.indexOf%")]),_f=function(t,e){var i=gf(t,!!e);return typeof i=="function"&&Ox(t,".prototype.")>-1?yf([i]):i},Bx=Al,ts=_f,Lx=Ys,Dx=en,vf=Bx("%Map%",!0),Nx=ts("Map.prototype.get",!0),Fx=ts("Map.prototype.set",!0),kx=ts("Map.prototype.has",!0),Ux=ts("Map.prototype.delete",!0),Gx=ts("Map.prototype.size",!0),bf=!!vf&&function(){var t,e={assert:function(i){if(!e.has(i))throw new Dx("Side channel does not contain "+Lx(i))},delete:function(i){if(t){var n=Ux(t,i);return Gx(t)===0&&(t=void 0),n}return!1},get:function(i){if(t)return Nx(t,i)},has:function(i){return t?kx(t,i):!1},set:function(i,n){t||(t=new vf),Fx(t,i,n)}};return e},$x=Al,eo=_f,Hx=Ys,ro=bf,Vx=en,ln=$x("%WeakMap%",!0),Xx=eo("WeakMap.prototype.get",!0),jx=eo("WeakMap.prototype.set",!0),Wx=eo("WeakMap.prototype.has",!0),Yx=eo("WeakMap.prototype.delete",!0),zx=ln?function(){var t,e,i={assert:function(n){if(!i.has(n))throw new Vx("Side channel does not contain "+Hx(n))},delete:function(n){if(ln&&n&&(typeof n=="object"||typeof n=="function")){if(t)return Yx(t,n)}else if(ro&&e)return e.delete(n);return!1},get:function(n){return ln&&n&&(typeof n=="object"||typeof n=="function")&&t?Xx(t,n):e&&e.get(n)},has:function(n){return ln&&n&&(typeof n=="object"||typeof n=="function")&&t?Wx(t,n):!!e&&e.has(n)},set:function(n,s){ln&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new ln),jx(t,n,s)):ro&&(e||(e=ro()),e.set(n,s))}};return i}:ro,qx=en,Kx=Ys,Zx=_b,Jx=bf,Qx=zx,tw=Qx||Jx||Zx,xf=function(){var t,e={assert:function(i){if(!e.has(i))throw new qx("Side channel does not contain "+Kx(i))},delete:function(i){return!!t&&t.delete(i)},get:function(i){return t&&t.get(i)},has:function(i){return!!t&&t.has(i)},set:function(i,n){t||(t=tw()),t.set(i,n)}};return e},ew=String.prototype.replace,rw=/%20/g,Sl={RFC1738:"RFC1738",RFC3986:"RFC3986"},Cl={default:Sl.RFC3986,formatters:{RFC1738:function(r){return ew.call(r,rw,"+")},RFC3986:function(r){return String(r)}},RFC1738:Sl.RFC1738,RFC3986:Sl.RFC3986},iw=Cl,nw=xf,Il=Object.prototype.hasOwnProperty,yi=Array.isArray,io=nw(),hn=function(t,e){return io.set(t,e),t},_i=function(t){return io.has(t)},es=function(t){return io.get(t)},Pl=function(t,e){io.set(t,e)},cr=function(){for(var r=[],t=0;t<256;++t)r[r.length]="%"+((t<16?"0":"")+t.toString(16)).toUpperCase();return r}(),sw=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(yi(i)){for(var n=[],s=0;s<i.length;++s)typeof i[s]<"u"&&(n[n.length]=i[s]);e.obj[e.prop]=n}}},rs=function(t,e){for(var i=e&&e.plainObjects?{__proto__:null}:{},n=0;n<t.length;++n)typeof t[n]<"u"&&(i[n]=t[n]);return i},ow=function r(t,e,i){if(!e)return t;if(typeof e!="object"&&typeof e!="function"){if(yi(t)){var n=t.length;if(i&&typeof i.arrayLimit=="number"&&n>i.arrayLimit)return hn(rs(t.concat(e),i),n);t[n]=e}else if(t&&typeof t=="object")if(_i(t)){var s=es(t)+1;t[s]=e,Pl(t,s)}else{if(i&&i.strictMerge)return[t,e];(i&&(i.plainObjects||i.allowPrototypes)||!Il.call(Object.prototype,e))&&(t[e]=!0)}else return[t,e];return t}if(!t||typeof t!="object"){if(_i(e)){for(var o=Object.keys(e),a=i&&i.plainObjects?{__proto__:null,0:t}:{0:t},l=0;l<o.length;l++){var h=parseInt(o[l],10);a[h+1]=e[o[l]]}return hn(a,es(e)+1)}var c=[t].concat(e);return i&&typeof i.arrayLimit=="number"&&c.length>i.arrayLimit?hn(rs(c,i),c.length-1):c}var u=t;return yi(t)&&!yi(e)&&(u=rs(t,i)),yi(t)&&yi(e)?(e.forEach(function(d,f){if(Il.call(t,f)){var p=t[f];p&&typeof p=="object"&&d&&typeof d=="object"?t[f]=r(p,d,i):t[t.length]=d}else t[f]=d}),t):Object.keys(e).reduce(function(d,f){var p=e[f];if(Il.call(d,f)?d[f]=r(d[f],p,i):d[f]=p,_i(e)&&!_i(d)&&hn(d,es(e)),_i(d)){var g=parseInt(f,10);String(g)===f&&g>=0&&g>es(d)&&Pl(d,g)}return d},u)},aw=function(t,e){return Object.keys(e).reduce(function(i,n){return i[n]=e[n],i},t)},lw=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}},Rl=1024,hw=function(t,e,i,n,s){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+=Rl){for(var h=o.length>=Rl?o.slice(l,l+Rl):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||s===iw.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=cr[d];continue}if(d<2048){c[c.length]=cr[192|d>>6]+cr[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=cr[224|d>>12]+cr[128|d>>6&63]+cr[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=cr[240|d>>18]+cr[128|d>>12&63]+cr[128|d>>6&63]+cr[128|d&63]}a+=c.join("")}return a},cw=function(t){for(var e=[{obj:{o:t},prop:"o"}],i=[],n=0;n<e.length;++n)for(var s=e[n],o=s.obj[s.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[e.length]={obj:o,prop:h},i[i.length]=c)}return sw(e),t},uw=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},dw=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},fw=function(t,e,i,n){if(_i(t)){var s=es(t)+1;return t[s]=e,Pl(t,s),t}var o=[].concat(t,e);return o.length>i?hn(rs(o,{plainObjects:n}),o.length-1):o},pw=function(t,e){if(yi(t)){for(var i=[],n=0;n<t.length;n+=1)i[i.length]=e(t[n]);return i}return e(t)},wf={arrayToObject:rs,assign:aw,combine:fw,compact:cw,decode:lw,encode:hw,isBuffer:dw,isOverflow:_i,isRegExp:uw,markOverflow:hn,maybeMap:pw,merge:ow},Ef=xf,no=wf,is=Cl,mw=Object.prototype.hasOwnProperty,Tf={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},ur=Array.isArray,gw=Array.prototype.push,Af=function(r,t){gw.apply(r,ur(t)?t:[t])},yw=Date.prototype.toISOString,Sf=is.default,ne={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:no.encode,encodeValuesOnly:!1,filter:void 0,format:Sf,formatter:is.formatters[Sf],indices:!1,serializeDate:function(t){return yw.call(t)},skipNulls:!1,strictNullHandling:!1},_w=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},Ml={},vw=function r(t,e,i,n,s,o,a,l,h,c,u,d,f,p,g,y,_,v){for(var m=t,x=v,S=0,R=!1;(x=x.get(Ml))!==void 0&&!R;){var C=x.get(t);if(S+=1,typeof C<"u"){if(C===S)throw new RangeError("Cyclic object value");R=!0}typeof x.get(Ml)>"u"&&(S=0)}if(typeof c=="function"?m=c(e,m):m instanceof Date?m=f(m):i==="comma"&&ur(m)&&(m=no.maybeMap(m,function(B){return B instanceof Date?f(B):B})),m===null){if(o)return h&&!y?h(e,ne.encoder,_,"key",p):e;m=""}if(_w(m)||no.isBuffer(m)){if(h){var I=y?e:h(e,ne.encoder,_,"key",p);return[g(I)+"="+g(h(m,ne.encoder,_,"value",p))]}return[g(e)+"="+g(String(m))]}var M=[];if(typeof m>"u")return M;var F;if(i==="comma"&&ur(m))y&&h&&(m=no.maybeMap(m,h)),F=[{value:m.length>0?m.join(",")||null:void 0}];else if(ur(c))F=c;else{var U=Object.keys(m);F=u?U.sort(u):U}var P=l?String(e).replace(/\./g,"%2E"):String(e),T=n&&ur(m)&&m.length===1?P+"[]":P;if(s&&ur(m)&&m.length===0)return T+"[]";for(var w=0;w<F.length;++w){var A=F[w],L=typeof A=="object"&&A&&typeof A.value<"u"?A.value:m[A];if(!(a&&L===null)){var O=d&&l?String(A).replace(/\./g,"%2E"):String(A),D=ur(m)?typeof i=="function"?i(T,O):T:T+(d?"."+O:"["+O+"]");v.set(t,S);var $=Ef();$.set(Ml,v),Af(M,r(L,D,i,n,s,o,a,l,i==="comma"&&y&&ur(m)?null:h,c,u,d,f,p,g,y,_,$))}}return M},bw=function(t){if(!t)return ne;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||ne.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=is.default;if(typeof t.format<"u"){if(!mw.call(is.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var n=is.formatters[i],s=ne.filter;(typeof t.filter=="function"||ur(t.filter))&&(s=t.filter);var o;if(t.arrayFormat in Tf?o=t.arrayFormat:"indices"in t?o=t.indices?"indices":"repeat":o=ne.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:ne.allowDots:!!t.allowDots;return{addQueryPrefix:typeof t.addQueryPrefix=="boolean"?t.addQueryPrefix:ne.addQueryPrefix,allowDots:a,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:ne.allowEmptyArrays,arrayFormat:o,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:ne.charsetSentinel,commaRoundTrip:!!t.commaRoundTrip,delimiter:typeof t.delimiter>"u"?ne.delimiter:t.delimiter,encode:typeof t.encode=="boolean"?t.encode:ne.encode,encodeDotInKeys:typeof t.encodeDotInKeys=="boolean"?t.encodeDotInKeys:ne.encodeDotInKeys,encoder:typeof t.encoder=="function"?t.encoder:ne.encoder,encodeValuesOnly:typeof t.encodeValuesOnly=="boolean"?t.encodeValuesOnly:ne.encodeValuesOnly,filter:s,format:i,formatter:n,serializeDate:typeof t.serializeDate=="function"?t.serializeDate:ne.serializeDate,skipNulls:typeof t.skipNulls=="boolean"?t.skipNulls:ne.skipNulls,sort:typeof t.sort=="function"?t.sort:null,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:ne.strictNullHandling}},xw=function(r,t){var e=r,i=bw(t),n,s;typeof i.filter=="function"?(s=i.filter,e=s("",e)):ur(i.filter)&&(s=i.filter,n=s);var o=[];if(typeof e!="object"||e===null)return"";var a=Tf[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var h=Ef(),c=0;c<n.length;++c){var u=n[c],d=e[u];i.skipNulls&&d===null||Af(o,vw(d,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 f=o.join(i.delimiter),p=i.addQueryPrefix===!0?"?":"";return i.charsetSentinel&&(i.charset==="iso-8859-1"?p+="utf8=%26%2310003%3B&":p+="utf8=%E2%9C%93&"),f.length>0?p+f:""},dr=wf,so=Object.prototype.hasOwnProperty,Ol=Array.isArray,Ht={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:dr.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictMerge:!0,strictNullHandling:!1,throwOnLimitExceeded:!1},ww=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},Cf=function(r,t,e){if(r&&typeof r=="string"&&t.comma&&r.indexOf(",")>-1)return r.split(",");if(t.throwOnLimitExceeded&&e>=t.arrayLimit)throw new RangeError("Array limit exceeded. Only "+t.arrayLimit+" element"+(t.arrayLimit===1?"":"s")+" allowed in an array.");return r},Ew="utf8=%26%2310003%3B",Tw="utf8=%E2%9C%93",Aw=function(t,e){var i={__proto__:null},n=e.ignoreQueryPrefix?t.replace(/^\?/,""):t;n=n.replace(/%5B/gi,"[").replace(/%5D/gi,"]");var s=e.parameterLimit===1/0?void 0:e.parameterLimit,o=n.split(e.delimiter,e.throwOnLimitExceeded&&typeof s<"u"?s+1:s);if(e.throwOnLimitExceeded&&typeof s<"u"&&o.length>s)throw new RangeError("Parameter limit exceeded. Only "+s+" parameter"+(s===1?"":"s")+" allowed.");var a=-1,l,h=e.charset;if(e.charsetSentinel)for(l=0;l<o.length;++l)o[l].indexOf("utf8=")===0&&(o[l]===Tw?h="utf-8":o[l]===Ew&&(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;if(d===-1?(f=e.decoder(c,Ht.decoder,h,"key"),p=e.strictNullHandling?null:""):(f=e.decoder(c.slice(0,d),Ht.decoder,h,"key"),f!==null&&(p=dr.maybeMap(Cf(c.slice(d+1),e,Ol(i[f])?i[f].length:0),function(y){return e.decoder(y,Ht.decoder,h,"value")}))),p&&e.interpretNumericEntities&&h==="iso-8859-1"&&(p=ww(String(p))),c.indexOf("[]=")>-1&&(p=Ol(p)?[p]:p),e.comma&&Ol(p)&&p.length>e.arrayLimit){if(e.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+e.arrayLimit+" element"+(e.arrayLimit===1?"":"s")+" allowed in an array.");p=dr.combine([],p,e.arrayLimit,e.plainObjects)}if(f!==null){var g=so.call(i,f);g&&(e.duplicates==="combine"||c.indexOf("[]=")>-1)?i[f]=dr.combine(i[f],p,e.arrayLimit,e.plainObjects):(!g||e.duplicates==="last")&&(i[f]=p)}}return i},Sw=function(r,t,e,i){var n=0;if(r.length>0&&r[r.length-1]==="[]"){var s=r.slice(0,-1).join("");n=Array.isArray(t)&&t[s]?t[s].length:0}for(var o=i?t:Cf(t,e,n),a=r.length-1;a>=0;--a){var l,h=r[a];if(h==="[]"&&e.parseArrays)dr.isOverflow(o)?l=o:l=e.allowEmptyArrays&&(o===""||e.strictNullHandling&&o===null)?[]:dr.combine([],o,e.arrayLimit,e.plainObjects);else{l=e.plainObjects?{__proto__:null}:{};var c=h.charAt(0)==="["&&h.charAt(h.length-1)==="]"?h.slice(1,-1):h,u=e.decodeDotInKeys?c.replace(/%2E/g,"."):c,d=parseInt(u,10),f=!isNaN(d)&&h!==u&&String(d)===u&&d>=0&&e.parseArrays;if(!e.parseArrays&&u==="")l={0:o};else if(f&&d<e.arrayLimit)l=[],l[d]=o;else{if(f&&e.throwOnLimitExceeded)throw new RangeError("Array limit exceeded. Only "+e.arrayLimit+" element"+(e.arrayLimit===1?"":"s")+" allowed in an array.");f?(l[d]=o,dr.markOverflow(l,d)):u!=="__proto__"&&(l[u]=o)}}o=l}return o},Cw=function(t,e){var i=e.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t;if(e.depth<=0)return!e.plainObjects&&so.call(Object.prototype,i)&&!e.allowPrototypes?void 0:[i];var n=/(\[[^[\]]*])/,s=/(\[[^[\]]*])/g,o=n.exec(i),a=o?i.slice(0,o.index):i,l=[];if(a){if(!e.plainObjects&&so.call(Object.prototype,a)&&!e.allowPrototypes)return;l[l.length]=a}for(var h=0;(o=s.exec(i))!==null&&h<e.depth;){h+=1;var c=o[1].slice(1,-1);if(!e.plainObjects&&so.call(Object.prototype,c)&&!e.allowPrototypes)return;l[l.length]=o[1]}if(o){if(e.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+e.depth+" and strictDepth is true");l[l.length]="["+i.slice(o.index)+"]"}return l},Iw=function(t,e,i,n){if(t){var s=Cw(t,i);if(s)return Sw(s,e,i,n)}},Pw=function(t){if(!t)return Ht;if(typeof t.allowEmptyArrays<"u"&&typeof t.allowEmptyArrays!="boolean")throw new TypeError("`allowEmptyArrays` option can only be `true` or `false`, when provided");if(typeof t.decodeDotInKeys<"u"&&typeof t.decodeDotInKeys!="boolean")throw new TypeError("`decodeDotInKeys` option can only be `true` or `false`, when provided");if(t.decoder!==null&&typeof t.decoder<"u"&&typeof t.decoder!="function")throw new TypeError("Decoder has to be a function.");if(typeof t.charset<"u"&&t.charset!=="utf-8"&&t.charset!=="iso-8859-1")throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");if(typeof t.throwOnLimitExceeded<"u"&&typeof t.throwOnLimitExceeded!="boolean")throw new TypeError("`throwOnLimitExceeded` option must be a boolean");var e=typeof t.charset>"u"?Ht.charset:t.charset,i=typeof t.duplicates>"u"?Ht.duplicates:t.duplicates;if(i!=="combine"&&i!=="first"&&i!=="last")throw new TypeError("The duplicates option must be either combine, first, or last");var n=typeof t.allowDots>"u"?t.decodeDotInKeys===!0?!0:Ht.allowDots:!!t.allowDots;return{allowDots:n,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:Ht.allowEmptyArrays,allowPrototypes:typeof t.allowPrototypes=="boolean"?t.allowPrototypes:Ht.allowPrototypes,allowSparse:typeof t.allowSparse=="boolean"?t.allowSparse:Ht.allowSparse,arrayLimit:typeof t.arrayLimit=="number"?t.arrayLimit:Ht.arrayLimit,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:Ht.charsetSentinel,comma:typeof t.comma=="boolean"?t.comma:Ht.comma,decodeDotInKeys:typeof t.decodeDotInKeys=="boolean"?t.decodeDotInKeys:Ht.decodeDotInKeys,decoder:typeof t.decoder=="function"?t.decoder:Ht.decoder,delimiter:typeof t.delimiter=="string"||dr.isRegExp(t.delimiter)?t.delimiter:Ht.delimiter,depth:typeof t.depth=="number"||t.depth===!1?+t.depth:Ht.depth,duplicates:i,ignoreQueryPrefix:t.ignoreQueryPrefix===!0,interpretNumericEntities:typeof t.interpretNumericEntities=="boolean"?t.interpretNumericEntities:Ht.interpretNumericEntities,parameterLimit:typeof t.parameterLimit=="number"?t.parameterLimit:Ht.parameterLimit,parseArrays:t.parseArrays!==!1,plainObjects:typeof t.plainObjects=="boolean"?t.plainObjects:Ht.plainObjects,strictDepth:typeof t.strictDepth=="boolean"?!!t.strictDepth:Ht.strictDepth,strictMerge:typeof t.strictMerge=="boolean"?!!t.strictMerge:Ht.strictMerge,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:Ht.strictNullHandling,throwOnLimitExceeded:typeof t.throwOnLimitExceeded=="boolean"?t.throwOnLimitExceeded:!1}},Rw=function(r,t){var e=Pw(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?Aw(r,e):r,n=e.plainObjects?{__proto__:null}:{},s=Object.keys(i),o=0;o<s.length;++o){var a=s[o],l=Iw(a,i[a],e,typeof r=="string");n=dr.merge(n,l,e)}return e.allowSparse===!0?n:dr.compact(n)},Mw=xw,Ow=Rw,Bw=Cl,Lw={formats:Bw,parse:Ow,stringify:Mw},Dw=N1;function Tr(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null}var Nw=/^([a-z0-9.+-]+:)/i,Fw=/:[0-9]*$/,kw=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,Uw=["<",">",'"',"`"," ","\r",`
@@ -486,7 +486,7 @@ void main(void)
486
486
  `)}}return s.push(`
487
487
  renderer.buffer.update(buffer);
488
488
  `),{size:n,syncFunc:new Function("ud","uv","renderer","syncData","buffer",s.join(`
489
- `))}}let cT=0;const Ao={textureCount:0,uboCount:0};class Lp{constructor(t){this.destroyed=!1,this.renderer=t,this.systemCheck(),this.gl=null,this.shader=null,this.program=null,this.cache={},this._uboCache={},this.id=cT++}systemCheck(){if(!DE())throw new Error("Current environment does not allow unsafe-eval, please use @pixi/unsafe-eval module to enable support.")}contextChange(t){this.gl=t,this.reset()}bind(t,e){t.disposeRunner.add(this),t.uniforms.globals=this.renderer.globalUniforms;const i=t.program,n=i.glPrograms[this.renderer.CONTEXT_UID]||this.generateProgram(t);return this.shader=t,this.program!==i&&(this.program=i,this.gl.useProgram(n.program)),e||(Ao.textureCount=0,Ao.uboCount=0,this.syncUniformGroup(t.uniformGroup,Ao)),n}setUniforms(t){const e=this.shader.program,i=e.glPrograms[this.renderer.CONTEXT_UID];e.syncUniforms(i.uniformData,t,this.renderer)}syncUniformGroup(t,e){const i=this.getGlProgram();(!t.static||t.dirtyId!==i.uniformDirtyGroups[t.id])&&(i.uniformDirtyGroups[t.id]=t.dirtyId,this.syncUniforms(t,i,e))}syncUniforms(t,e,i){(t.syncUniforms[this.shader.program.id]||this.createSyncGroups(t))(e.uniformData,t.uniforms,this.renderer,i)}createSyncGroups(t){const e=this.getSignature(t,this.shader.program.uniformData,"u");return this.cache[e]||(this.cache[e]=RE(t,this.shader.program.uniformData)),t.syncUniforms[this.shader.program.id]=this.cache[e],t.syncUniforms[this.shader.program.id]}syncUniformBufferGroup(t,e){const i=this.getGlProgram();if(!t.static||t.dirtyId!==0||!i.uniformGroups[t.id]){t.dirtyId=0;const n=i.uniformGroups[t.id]||this.createSyncBufferGroup(t,i,e);t.buffer.update(),n(i.uniformData,t.uniforms,this.renderer,Ao,t.buffer)}this.renderer.buffer.bindBufferBase(t.buffer,i.uniformBufferBindings[e])}createSyncBufferGroup(t,e,i){const{gl:n}=this.renderer;this.renderer.buffer.bind(t.buffer);const s=this.gl.getUniformBlockIndex(e.program,i);e.uniformBufferBindings[i]=this.shader.uniformBindCount,n.uniformBlockBinding(e.program,s,this.shader.uniformBindCount),this.shader.uniformBindCount++;const o=this.getSignature(t,this.shader.program.uniformData,"ubo");let a=this._uboCache[o];if(a||(a=this._uboCache[o]=hT(t,this.shader.program.uniformData)),t.autoManage){const l=new Float32Array(a.size/4);t.buffer.update(l)}return e.uniformGroups[t.id]=a.syncFunc,e.uniformGroups[t.id]}getSignature(t,e,i){const n=t.uniforms,s=[`${i}-`];for(const o in n)s.push(o),e[o]&&s.push(e[o].type);return s.join("-")}getGlProgram(){return this.shader?this.shader.program.glPrograms[this.renderer.CONTEXT_UID]:null}generateProgram(t){const e=this.gl,i=t.program,n=nT(e,i);return i.glPrograms[this.renderer.CONTEXT_UID]=n,n}reset(){this.program=null,this.shader=null}disposeShader(t){this.shader===t&&(this.shader=null)}destroy(){this.renderer=null,this.destroyed=!0}}Lp.extension={type:K.RendererSystem,name:"shader"},ut.add(Lp);class So{constructor(t){this.renderer=t}run(t){const{renderer:e}=this;e.runners.init.emit(e.options),t.hello&&console.log(`PixiJS 7.4.3 - ${e.rendererLogId} - https://pixijs.com`),e.resize(e.screen.width,e.screen.height)}destroy(){}}So.defaultOptions={hello:!1},So.extension={type:[K.RendererSystem,K.CanvasRendererSystem],name:"startup"},ut.add(So);function uT(r,t=[]){return t[vt.NORMAL]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.ADD]=[r.ONE,r.ONE],t[vt.MULTIPLY]=[r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SCREEN]=[r.ONE,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.OVERLAY]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.DARKEN]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.LIGHTEN]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.COLOR_DODGE]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.COLOR_BURN]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.HARD_LIGHT]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SOFT_LIGHT]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.DIFFERENCE]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.EXCLUSION]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.HUE]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SATURATION]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.COLOR]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.LUMINOSITY]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.NONE]=[0,0],t[vt.NORMAL_NPM]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.ADD_NPM]=[r.SRC_ALPHA,r.ONE,r.ONE,r.ONE],t[vt.SCREEN_NPM]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SRC_IN]=[r.DST_ALPHA,r.ZERO],t[vt.SRC_OUT]=[r.ONE_MINUS_DST_ALPHA,r.ZERO],t[vt.SRC_ATOP]=[r.DST_ALPHA,r.ONE_MINUS_SRC_ALPHA],t[vt.DST_OVER]=[r.ONE_MINUS_DST_ALPHA,r.ONE],t[vt.DST_IN]=[r.ZERO,r.SRC_ALPHA],t[vt.DST_OUT]=[r.ZERO,r.ONE_MINUS_SRC_ALPHA],t[vt.DST_ATOP]=[r.ONE_MINUS_DST_ALPHA,r.SRC_ALPHA],t[vt.XOR]=[r.ONE_MINUS_DST_ALPHA,r.ONE_MINUS_SRC_ALPHA],t[vt.SUBTRACT]=[r.ONE,r.ONE,r.ONE,r.ONE,r.FUNC_REVERSE_SUBTRACT,r.FUNC_ADD],t}const dT=0,fT=1,pT=2,mT=3,gT=4,yT=5,Dp=class zh{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode=vt.NONE,this._blendEq=!1,this.map=[],this.map[dT]=this.setBlend,this.map[fT]=this.setOffset,this.map[pT]=this.setCullFace,this.map[mT]=this.setDepthTest,this.map[gT]=this.setFrontFace,this.map[yT]=this.setDepthMask,this.checks=[],this.defaultState=new mr,this.defaultState.blend=!0}contextChange(t){this.gl=t,this.blendModes=uT(t),this.set(this.defaultState),this.reset()}set(t){if(t=t||this.defaultState,this.stateId!==t.data){let e=this.stateId^t.data,i=0;for(;e;)e&1&&this.map[i].call(this,!!(t.data&1<<i)),e=e>>1,i++;this.stateId=t.data}for(let e=0;e<this.checks.length;e++)this.checks[e](this,t)}forceState(t){t=t||this.defaultState;for(let e=0;e<this.map.length;e++)this.map[e].call(this,!!(t.data&1<<e));for(let e=0;e<this.checks.length;e++)this.checks[e](this,t);this.stateId=t.data}setBlend(t){this.updateCheck(zh.checkBlendMode,t),this.gl[t?"enable":"disable"](this.gl.BLEND)}setOffset(t){this.updateCheck(zh.checkPolygonOffset,t),this.gl[t?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(t){this.gl[t?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(t){this.gl.depthMask(t)}setCullFace(t){this.gl[t?"enable":"disable"](this.gl.CULL_FACE)}setFrontFace(t){this.gl.frontFace(this.gl[t?"CW":"CCW"])}setBlendMode(t){if(t===this.blendMode)return;this.blendMode=t;const e=this.blendModes[t],i=this.gl;e.length===2?i.blendFunc(e[0],e[1]):i.blendFuncSeparate(e[0],e[1],e[2],e[3]),e.length===6?(this._blendEq=!0,i.blendEquationSeparate(e[4],e[5])):this._blendEq&&(this._blendEq=!1,i.blendEquationSeparate(i.FUNC_ADD,i.FUNC_ADD))}setPolygonOffset(t,e){this.gl.polygonOffset(t,e)}reset(){this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode=-1,this.setBlendMode(0)}updateCheck(t,e){const i=this.checks.indexOf(t);e&&i===-1?this.checks.push(t):!e&&i!==-1&&this.checks.splice(i,1)}static checkBlendMode(t,e){t.setBlendMode(e.blendMode)}static checkPolygonOffset(t,e){t.setPolygonOffset(1,e.polygonOffset)}destroy(){this.gl=null}};Dp.extension={type:K.RendererSystem,name:"state"};let _T=Dp;ut.add(_T);class vT extends Vn{constructor(){super(...arguments),this.runners={},this._systemsHash={}}setup(t){this.addRunners(...t.runners);const e=(t.priority??[]).filter(n=>t.systems[n]),i=[...e,...Object.keys(t.systems).filter(n=>!e.includes(n))];for(const n of i)this.addSystem(t.systems[n],n)}addRunners(...t){t.forEach(e=>{this.runners[e]=new qe(e)})}addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const n in this.runners)this.runners[n].add(i);return this}emitWithCustomOptions(t,e){const i=Object.keys(this._systemsHash);t.items.forEach(n=>{const s=i.find(o=>this._systemsHash[o]===n);n[t.name](e[s])})}destroy(){Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash={}}}const cs=class Qo{constructor(t){this.renderer=t,this.count=0,this.checkCount=0,this.maxIdle=Qo.defaultMaxIdle,this.checkCountMax=Qo.defaultCheckCountMax,this.mode=Qo.defaultMode}postrender(){this.renderer.objectRenderer.renderingToScreen&&(this.count++,this.mode!==qa.MANUAL&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const t=this.renderer.texture,e=t.managedTextures;let i=!1;for(let n=0;n<e.length;n++){const s=e[n];s.resource&&this.count-s.touched>this.maxIdle&&(t.destroyTexture(s,!0),e[n]=null,i=!0)}if(i){let n=0;for(let s=0;s<e.length;s++)e[s]!==null&&(e[n++]=e[s]);e.length=n}}unload(t){const e=this.renderer.texture,i=t._texture;i&&!i.framebuffer&&e.destroyTexture(i);for(let n=t.children.length-1;n>=0;n--)this.unload(t.children[n])}destroy(){this.renderer=null}};cs.defaultMode=qa.AUTO,cs.defaultMaxIdle=60*60,cs.defaultCheckCountMax=60*10,cs.extension={type:K.RendererSystem,name:"textureGC"};let Ii=cs;ut.add(Ii);class dh{constructor(t){this.texture=t,this.width=-1,this.height=-1,this.dirtyId=-1,this.dirtyStyleId=-1,this.mipmap=!1,this.wrapMode=33071,this.type=mt.UNSIGNED_BYTE,this.internalFormat=W.RGBA,this.samplerType=0}}function bT(r){let t;return"WebGL2RenderingContext"in globalThis&&r instanceof globalThis.WebGL2RenderingContext?t={[r.RGB]:Q.FLOAT,[r.RGBA]:Q.FLOAT,[r.ALPHA]:Q.FLOAT,[r.LUMINANCE]:Q.FLOAT,[r.LUMINANCE_ALPHA]:Q.FLOAT,[r.R8]:Q.FLOAT,[r.R8_SNORM]:Q.FLOAT,[r.RG8]:Q.FLOAT,[r.RG8_SNORM]:Q.FLOAT,[r.RGB8]:Q.FLOAT,[r.RGB8_SNORM]:Q.FLOAT,[r.RGB565]:Q.FLOAT,[r.RGBA4]:Q.FLOAT,[r.RGB5_A1]:Q.FLOAT,[r.RGBA8]:Q.FLOAT,[r.RGBA8_SNORM]:Q.FLOAT,[r.RGB10_A2]:Q.FLOAT,[r.RGB10_A2UI]:Q.FLOAT,[r.SRGB8]:Q.FLOAT,[r.SRGB8_ALPHA8]:Q.FLOAT,[r.R16F]:Q.FLOAT,[r.RG16F]:Q.FLOAT,[r.RGB16F]:Q.FLOAT,[r.RGBA16F]:Q.FLOAT,[r.R32F]:Q.FLOAT,[r.RG32F]:Q.FLOAT,[r.RGB32F]:Q.FLOAT,[r.RGBA32F]:Q.FLOAT,[r.R11F_G11F_B10F]:Q.FLOAT,[r.RGB9_E5]:Q.FLOAT,[r.R8I]:Q.INT,[r.R8UI]:Q.UINT,[r.R16I]:Q.INT,[r.R16UI]:Q.UINT,[r.R32I]:Q.INT,[r.R32UI]:Q.UINT,[r.RG8I]:Q.INT,[r.RG8UI]:Q.UINT,[r.RG16I]:Q.INT,[r.RG16UI]:Q.UINT,[r.RG32I]:Q.INT,[r.RG32UI]:Q.UINT,[r.RGB8I]:Q.INT,[r.RGB8UI]:Q.UINT,[r.RGB16I]:Q.INT,[r.RGB16UI]:Q.UINT,[r.RGB32I]:Q.INT,[r.RGB32UI]:Q.UINT,[r.RGBA8I]:Q.INT,[r.RGBA8UI]:Q.UINT,[r.RGBA16I]:Q.INT,[r.RGBA16UI]:Q.UINT,[r.RGBA32I]:Q.INT,[r.RGBA32UI]:Q.UINT,[r.DEPTH_COMPONENT16]:Q.FLOAT,[r.DEPTH_COMPONENT24]:Q.FLOAT,[r.DEPTH_COMPONENT32F]:Q.FLOAT,[r.DEPTH_STENCIL]:Q.FLOAT,[r.DEPTH24_STENCIL8]:Q.FLOAT,[r.DEPTH32F_STENCIL8]:Q.FLOAT}:t={[r.RGB]:Q.FLOAT,[r.RGBA]:Q.FLOAT,[r.ALPHA]:Q.FLOAT,[r.LUMINANCE]:Q.FLOAT,[r.LUMINANCE_ALPHA]:Q.FLOAT,[r.DEPTH_STENCIL]:Q.FLOAT},t}function xT(r){let t;return"WebGL2RenderingContext"in globalThis&&r instanceof globalThis.WebGL2RenderingContext?t={[mt.UNSIGNED_BYTE]:{[W.RGBA]:r.RGBA8,[W.RGB]:r.RGB8,[W.RG]:r.RG8,[W.RED]:r.R8,[W.RGBA_INTEGER]:r.RGBA8UI,[W.RGB_INTEGER]:r.RGB8UI,[W.RG_INTEGER]:r.RG8UI,[W.RED_INTEGER]:r.R8UI,[W.ALPHA]:r.ALPHA,[W.LUMINANCE]:r.LUMINANCE,[W.LUMINANCE_ALPHA]:r.LUMINANCE_ALPHA},[mt.BYTE]:{[W.RGBA]:r.RGBA8_SNORM,[W.RGB]:r.RGB8_SNORM,[W.RG]:r.RG8_SNORM,[W.RED]:r.R8_SNORM,[W.RGBA_INTEGER]:r.RGBA8I,[W.RGB_INTEGER]:r.RGB8I,[W.RG_INTEGER]:r.RG8I,[W.RED_INTEGER]:r.R8I},[mt.UNSIGNED_SHORT]:{[W.RGBA_INTEGER]:r.RGBA16UI,[W.RGB_INTEGER]:r.RGB16UI,[W.RG_INTEGER]:r.RG16UI,[W.RED_INTEGER]:r.R16UI,[W.DEPTH_COMPONENT]:r.DEPTH_COMPONENT16},[mt.SHORT]:{[W.RGBA_INTEGER]:r.RGBA16I,[W.RGB_INTEGER]:r.RGB16I,[W.RG_INTEGER]:r.RG16I,[W.RED_INTEGER]:r.R16I},[mt.UNSIGNED_INT]:{[W.RGBA_INTEGER]:r.RGBA32UI,[W.RGB_INTEGER]:r.RGB32UI,[W.RG_INTEGER]:r.RG32UI,[W.RED_INTEGER]:r.R32UI,[W.DEPTH_COMPONENT]:r.DEPTH_COMPONENT24},[mt.INT]:{[W.RGBA_INTEGER]:r.RGBA32I,[W.RGB_INTEGER]:r.RGB32I,[W.RG_INTEGER]:r.RG32I,[W.RED_INTEGER]:r.R32I},[mt.FLOAT]:{[W.RGBA]:r.RGBA32F,[W.RGB]:r.RGB32F,[W.RG]:r.RG32F,[W.RED]:r.R32F,[W.DEPTH_COMPONENT]:r.DEPTH_COMPONENT32F},[mt.HALF_FLOAT]:{[W.RGBA]:r.RGBA16F,[W.RGB]:r.RGB16F,[W.RG]:r.RG16F,[W.RED]:r.R16F},[mt.UNSIGNED_SHORT_5_6_5]:{[W.RGB]:r.RGB565},[mt.UNSIGNED_SHORT_4_4_4_4]:{[W.RGBA]:r.RGBA4},[mt.UNSIGNED_SHORT_5_5_5_1]:{[W.RGBA]:r.RGB5_A1},[mt.UNSIGNED_INT_2_10_10_10_REV]:{[W.RGBA]:r.RGB10_A2,[W.RGBA_INTEGER]:r.RGB10_A2UI},[mt.UNSIGNED_INT_10F_11F_11F_REV]:{[W.RGB]:r.R11F_G11F_B10F},[mt.UNSIGNED_INT_5_9_9_9_REV]:{[W.RGB]:r.RGB9_E5},[mt.UNSIGNED_INT_24_8]:{[W.DEPTH_STENCIL]:r.DEPTH24_STENCIL8},[mt.FLOAT_32_UNSIGNED_INT_24_8_REV]:{[W.DEPTH_STENCIL]:r.DEPTH32F_STENCIL8}}:t={[mt.UNSIGNED_BYTE]:{[W.RGBA]:r.RGBA,[W.RGB]:r.RGB,[W.ALPHA]:r.ALPHA,[W.LUMINANCE]:r.LUMINANCE,[W.LUMINANCE_ALPHA]:r.LUMINANCE_ALPHA},[mt.UNSIGNED_SHORT_5_6_5]:{[W.RGB]:r.RGB},[mt.UNSIGNED_SHORT_4_4_4_4]:{[W.RGBA]:r.RGBA},[mt.UNSIGNED_SHORT_5_5_5_1]:{[W.RGBA]:r.RGBA}},t}class Np{constructor(t){this.renderer=t,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new xt,this.hasIntegerTextures=!1}contextChange(){const t=this.gl=this.renderer.gl;this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.webGLVersion=this.renderer.context.webGLVersion,this.internalFormats=xT(t),this.samplerTypes=bT(t);const e=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);this.boundTextures.length=e;for(let n=0;n<e;n++)this.boundTextures[n]=null;this.emptyTextures={};const i=new dh(t.createTexture());t.bindTexture(t.TEXTURE_2D,i.texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array(4)),this.emptyTextures[t.TEXTURE_2D]=i,this.emptyTextures[t.TEXTURE_CUBE_MAP]=new dh(t.createTexture()),t.bindTexture(t.TEXTURE_CUBE_MAP,this.emptyTextures[t.TEXTURE_CUBE_MAP].texture);for(let n=0;n<6;n++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,null);t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR);for(let n=0;n<this.boundTextures.length;n++)this.bind(null,n)}bind(t,e=0){const{gl:i}=this;if(t=t==null?void 0:t.castToBaseTexture(),(t==null?void 0:t.valid)&&!t.parentTextureArray){t.touched=this.renderer.textureGC.count;const n=t._glTextures[this.CONTEXT_UID]||this.initTexture(t);this.boundTextures[e]!==t&&(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(t.target,n.texture)),n.dirtyId!==t.dirtyId?(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),this.updateTexture(t)):n.dirtyStyleId!==t.dirtyStyleId&&this.updateTextureStyle(t),this.boundTextures[e]=t}else this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,this.emptyTextures[i.TEXTURE_2D].texture),this.boundTextures[e]=null}reset(){this._unknownBoundTextures=!0,this.hasIntegerTextures=!1,this.currentLocation=-1;for(let t=0;t<this.boundTextures.length;t++)this.boundTextures[t]=this.unknownTexture}unbind(t){const{gl:e,boundTextures:i}=this;if(this._unknownBoundTextures){this._unknownBoundTextures=!1;for(let n=0;n<i.length;n++)i[n]===this.unknownTexture&&this.bind(null,n)}for(let n=0;n<i.length;n++)i[n]===t&&(this.currentLocation!==n&&(e.activeTexture(e.TEXTURE0+n),this.currentLocation=n),e.bindTexture(t.target,this.emptyTextures[t.target].texture),i[n]=null)}ensureSamplerType(t){const{boundTextures:e,hasIntegerTextures:i,CONTEXT_UID:n}=this;if(i)for(let s=t-1;s>=0;--s){const o=e[s];o&&o._glTextures[n].samplerType!==Q.FLOAT&&this.renderer.texture.unbind(o)}}initTexture(t){const e=new dh(this.gl.createTexture());return e.dirtyId=-1,t._glTextures[this.CONTEXT_UID]=e,this.managedTextures.push(t),t.on("dispose",this.destroyTexture,this),e}initTextureType(t,e){var i;e.internalFormat=((i=this.internalFormats[t.type])==null?void 0:i[t.format])??t.format,e.samplerType=this.samplerTypes[e.internalFormat]??Q.FLOAT,this.webGLVersion===2&&t.type===mt.HALF_FLOAT?e.type=this.gl.HALF_FLOAT:e.type=t.type}updateTexture(t){var n;const e=t._glTextures[this.CONTEXT_UID];if(!e)return;const i=this.renderer;if(this.initTextureType(t,e),(n=t.resource)==null?void 0:n.upload(i,t,e))e.samplerType!==Q.FLOAT&&(this.hasIntegerTextures=!0);else{const s=t.realWidth,o=t.realHeight,a=i.gl;(e.width!==s||e.height!==o||e.dirtyId<0)&&(e.width=s,e.height=o,a.texImage2D(t.target,0,e.internalFormat,s,o,0,t.format,e.type,null))}t.dirtyStyleId!==e.dirtyStyleId&&this.updateTextureStyle(t),e.dirtyId=t.dirtyId}destroyTexture(t,e){const{gl:i}=this;if(t=t.castToBaseTexture(),t._glTextures[this.CONTEXT_UID]&&(this.unbind(t),i.deleteTexture(t._glTextures[this.CONTEXT_UID].texture),t.off("dispose",this.destroyTexture,this),delete t._glTextures[this.CONTEXT_UID],!e)){const n=this.managedTextures.indexOf(t);n!==-1&&dn(this.managedTextures,n,1)}}updateTextureStyle(t){var i;const e=t._glTextures[this.CONTEXT_UID];e&&((t.mipmap===or.POW2||this.webGLVersion!==2)&&!t.isPowerOfTwo?e.mipmap=!1:e.mipmap=t.mipmap>=1,this.webGLVersion!==2&&!t.isPowerOfTwo?e.wrapMode=jr.CLAMP:e.wrapMode=t.wrapMode,(i=t.resource)!=null&&i.style(this.renderer,t,e)||this.setStyle(t,e),e.dirtyStyleId=t.dirtyStyleId)}setStyle(t,e){const i=this.gl;if(e.mipmap&&t.mipmap!==or.ON_MANUAL&&i.generateMipmap(t.target),i.texParameteri(t.target,i.TEXTURE_WRAP_S,e.wrapMode),i.texParameteri(t.target,i.TEXTURE_WRAP_T,e.wrapMode),e.mipmap){i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===br.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);const n=this.renderer.context.extensions.anisotropicFiltering;if(n&&t.anisotropicLevel>0&&t.scaleMode===br.LINEAR){const s=Math.min(t.anisotropicLevel,i.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));i.texParameterf(t.target,n.TEXTURE_MAX_ANISOTROPY_EXT,s)}}else i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===br.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(t.target,i.TEXTURE_MAG_FILTER,t.scaleMode===br.LINEAR?i.LINEAR:i.NEAREST)}destroy(){this.renderer=null}}Np.extension={type:K.RendererSystem,name:"texture"},ut.add(Np);class Fp{constructor(t){this.renderer=t}contextChange(){this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,n=t._glTransformFeedbacks[i]||this.createGLTransformFeedback(t);e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,n)}unbind(){const{gl:t}=this;t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null)}beginTransformFeedback(t,e){const{gl:i,renderer:n}=this;e&&n.shader.bind(e),i.beginTransformFeedback(t)}endTransformFeedback(){const{gl:t}=this;t.endTransformFeedback()}createGLTransformFeedback(t){const{gl:e,renderer:i,CONTEXT_UID:n}=this,s=e.createTransformFeedback();t._glTransformFeedbacks[n]=s,e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,s);for(let o=0;o<t.buffers.length;o++){const a=t.buffers[o];a&&(i.buffer.update(a),a._glBuffers[n].refCount++,e.bindBufferBase(e.TRANSFORM_FEEDBACK_BUFFER,o,a._glBuffers[n].buffer||null))}return e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,null),t.disposeRunner.add(this),s}disposeTransformFeedback(t,e){const i=t._glTransformFeedbacks[this.CONTEXT_UID],n=this.gl;t.disposeRunner.remove(this);const s=this.renderer.buffer;if(s)for(let o=0;o<t.buffers.length;o++){const a=t.buffers[o];if(!a)continue;const l=a._glBuffers[this.CONTEXT_UID];l&&(l.refCount--,l.refCount===0&&!e&&s.dispose(a,e))}i&&(e||n.deleteTransformFeedback(i),delete t._glTransformFeedbacks[this.CONTEXT_UID])}destroy(){this.renderer=null}}Fp.extension={type:K.RendererSystem,name:"transformFeedback"},ut.add(Fp);class Co{constructor(t){this.renderer=t}init(t){this.screen=new wt(0,0,t.width,t.height),this.element=t.view||tt.ADAPTER.createCanvas(),this.resolution=t.resolution||tt.RESOLUTION,this.autoDensity=!!t.autoDensity}resizeView(t,e){this.element.width=Math.round(t*this.resolution),this.element.height=Math.round(e*this.resolution);const i=this.element.width/this.resolution,n=this.element.height/this.resolution;this.screen.width=i,this.screen.height=n,this.autoDensity&&(this.element.style.width=`${i}px`,this.element.style.height=`${n}px`),this.renderer.emit("resize",i,n),this.renderer.runners.resize.emit(this.screen.width,this.screen.height)}destroy(t){var e;t&&((e=this.element.parentNode)==null||e.removeChild(this.element)),this.renderer=null,this.element=null,this.screen=null}}Co.defaultOptions={width:800,height:600,resolution:void 0,autoDensity:!1},Co.extension={type:[K.RendererSystem,K.CanvasRendererSystem],name:"_view"},ut.add(Co),tt.PREFER_ENV=fi.WEBGL2,tt.STRICT_TEXTURE_CACHE=!1,tt.RENDER_OPTIONS={...wo.defaultOptions,...xo.defaultOptions,...Co.defaultOptions,...So.defaultOptions},Object.defineProperties(tt,{WRAP_MODE:{get(){return xt.defaultOptions.wrapMode},set(r){St("7.1.0","settings.WRAP_MODE is deprecated, use BaseTexture.defaultOptions.wrapMode"),xt.defaultOptions.wrapMode=r}},SCALE_MODE:{get(){return xt.defaultOptions.scaleMode},set(r){St("7.1.0","settings.SCALE_MODE is deprecated, use BaseTexture.defaultOptions.scaleMode"),xt.defaultOptions.scaleMode=r}},MIPMAP_TEXTURES:{get(){return xt.defaultOptions.mipmap},set(r){St("7.1.0","settings.MIPMAP_TEXTURES is deprecated, use BaseTexture.defaultOptions.mipmap"),xt.defaultOptions.mipmap=r}},ANISOTROPIC_LEVEL:{get(){return xt.defaultOptions.anisotropicLevel},set(r){St("7.1.0","settings.ANISOTROPIC_LEVEL is deprecated, use BaseTexture.defaultOptions.anisotropicLevel"),xt.defaultOptions.anisotropicLevel=r}},FILTER_RESOLUTION:{get(){return St("7.1.0","settings.FILTER_RESOLUTION is deprecated, use Filter.defaultResolution"),Re.defaultResolution},set(r){Re.defaultResolution=r}},FILTER_MULTISAMPLE:{get(){return St("7.1.0","settings.FILTER_MULTISAMPLE is deprecated, use Filter.defaultMultisample"),Re.defaultMultisample},set(r){Re.defaultMultisample=r}},SPRITE_MAX_TEXTURES:{get(){return Ai.defaultMaxTextures},set(r){St("7.1.0","settings.SPRITE_MAX_TEXTURES is deprecated, use BatchRenderer.defaultMaxTextures"),Ai.defaultMaxTextures=r}},SPRITE_BATCH_SIZE:{get(){return Ai.defaultBatchSize},set(r){St("7.1.0","settings.SPRITE_BATCH_SIZE is deprecated, use BatchRenderer.defaultBatchSize"),Ai.defaultBatchSize=r}},CAN_UPLOAD_SAME_BUFFER:{get(){return Ai.canUploadSameBuffer},set(r){St("7.1.0","settings.CAN_UPLOAD_SAME_BUFFER is deprecated, use BatchRenderer.canUploadSameBuffer"),Ai.canUploadSameBuffer=r}},GC_MODE:{get(){return Ii.defaultMode},set(r){St("7.1.0","settings.GC_MODE is deprecated, use TextureGCSystem.defaultMode"),Ii.defaultMode=r}},GC_MAX_IDLE:{get(){return Ii.defaultMaxIdle},set(r){St("7.1.0","settings.GC_MAX_IDLE is deprecated, use TextureGCSystem.defaultMaxIdle"),Ii.defaultMaxIdle=r}},GC_MAX_CHECK_COUNT:{get(){return Ii.defaultCheckCountMax},set(r){St("7.1.0","settings.GC_MAX_CHECK_COUNT is deprecated, use TextureGCSystem.defaultCheckCountMax"),Ii.defaultCheckCountMax=r}},PRECISION_VERTEX:{get(){return Ir.defaultVertexPrecision},set(r){St("7.1.0","settings.PRECISION_VERTEX is deprecated, use Program.defaultVertexPrecision"),Ir.defaultVertexPrecision=r}},PRECISION_FRAGMENT:{get(){return Ir.defaultFragmentPrecision},set(r){St("7.1.0","settings.PRECISION_FRAGMENT is deprecated, use Program.defaultFragmentPrecision"),Ir.defaultFragmentPrecision=r}}});var Pi=(r=>(r[r.INTERACTION=50]="INTERACTION",r[r.HIGH=25]="HIGH",r[r.NORMAL=0]="NORMAL",r[r.LOW=-25]="LOW",r[r.UTILITY=-50]="UTILITY",r))(Pi||{});class fh{constructor(t,e=null,i=0,n=!1){this.next=null,this.previous=null,this._destroyed=!1,this.fn=t,this.context=e,this.priority=i,this.once=n}match(t,e=null){return this.fn===t&&this.context===e}emit(t){this.fn&&(this.context?this.fn.call(this.context,t):this.fn(t));const e=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),e}connect(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this}destroy(t=!1){this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const e=this.next;return this.next=t?null:e,this.previous=null,e}}const kp=class ke{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new fh(null,null,1/0),this.deltaMS=1/ke.targetFPMS,this.elapsedMS=1/ke.targetFPMS,this._tick=t=>{this._requestId=null,this.started&&(this.update(t),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(t,e,i=Pi.NORMAL){return this._addListener(new fh(t,e,i))}addOnce(t,e,i=Pi.NORMAL){return this._addListener(new fh(t,e,i,!0))}_addListener(t){let e=this._head.next,i=this._head;if(!e)t.connect(i);else{for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}return this._startIfPossible(),this}remove(t,e){let i=this._head.next;for(;i;)i.match(t,e)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let t=0,e=this._head;for(;e=e.next;)t++;return t}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let t=this._head.next;for(;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}}update(t=performance.now()){let e;if(t>this.lastTime){if(e=this.elapsedMS=t-this.lastTime,e>this._maxElapsedMS&&(e=this._maxElapsedMS),e*=this.speed,this._minElapsedMS){const s=t-this._lastFrame|0;if(s<this._minElapsedMS)return;this._lastFrame=t-s%this._minElapsedMS}this.deltaMS=e,this.deltaTime=this.deltaMS*ke.targetFPMS;const i=this._head;let n=i.next;for(;n;)n=n.emit(this.deltaTime);i.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=t}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(t){const e=Math.min(this.maxFPS,t),i=Math.min(Math.max(0,e)/1e3,ke.targetFPMS);this._maxElapsedMS=1/i}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(t){if(t===0)this._minElapsedMS=0;else{const e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}}static get shared(){if(!ke._shared){const t=ke._shared=new ke;t.autoStart=!0,t._protected=!0}return ke._shared}static get system(){if(!ke._system){const t=ke._system=new ke;t.autoStart=!0,t._protected=!0}return ke._system}};kp.targetFPMS=.06;let Fe=kp;Object.defineProperties(tt,{TARGET_FPMS:{get(){return Fe.targetFPMS},set(r){St("7.1.0","settings.TARGET_FPMS is deprecated, use Ticker.targetFPMS"),Fe.targetFPMS=r}}});class Up{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,Pi.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?Fe.shared:new Fe,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}Up.extension=K.Application,ut.add(Up);const Gp=[];ut.handleByList(K.Renderer,Gp);function $p(r){for(const t of Gp)if(t.test(r))return new t(r);throw new Error("Unable to auto-detect a suitable renderer.")}var wT=`attribute vec2 aVertexPosition;
489
+ `))}}let cT=0;const Ao={textureCount:0,uboCount:0};class Lp{constructor(t){this.destroyed=!1,this.renderer=t,this.systemCheck(),this.gl=null,this.shader=null,this.program=null,this.cache={},this._uboCache={},this.id=cT++}systemCheck(){if(!DE())throw new Error("Current environment does not allow unsafe-eval, please use @pixi/unsafe-eval module to enable support.")}contextChange(t){this.gl=t,this.reset()}bind(t,e){t.disposeRunner.add(this),t.uniforms.globals=this.renderer.globalUniforms;const i=t.program,n=i.glPrograms[this.renderer.CONTEXT_UID]||this.generateProgram(t);return this.shader=t,this.program!==i&&(this.program=i,this.gl.useProgram(n.program)),e||(Ao.textureCount=0,Ao.uboCount=0,this.syncUniformGroup(t.uniformGroup,Ao)),n}setUniforms(t){const e=this.shader.program,i=e.glPrograms[this.renderer.CONTEXT_UID];e.syncUniforms(i.uniformData,t,this.renderer)}syncUniformGroup(t,e){const i=this.getGlProgram();(!t.static||t.dirtyId!==i.uniformDirtyGroups[t.id])&&(i.uniformDirtyGroups[t.id]=t.dirtyId,this.syncUniforms(t,i,e))}syncUniforms(t,e,i){(t.syncUniforms[this.shader.program.id]||this.createSyncGroups(t))(e.uniformData,t.uniforms,this.renderer,i)}createSyncGroups(t){const e=this.getSignature(t,this.shader.program.uniformData,"u");return this.cache[e]||(this.cache[e]=RE(t,this.shader.program.uniformData)),t.syncUniforms[this.shader.program.id]=this.cache[e],t.syncUniforms[this.shader.program.id]}syncUniformBufferGroup(t,e){const i=this.getGlProgram();if(!t.static||t.dirtyId!==0||!i.uniformGroups[t.id]){t.dirtyId=0;const n=i.uniformGroups[t.id]||this.createSyncBufferGroup(t,i,e);t.buffer.update(),n(i.uniformData,t.uniforms,this.renderer,Ao,t.buffer)}this.renderer.buffer.bindBufferBase(t.buffer,i.uniformBufferBindings[e])}createSyncBufferGroup(t,e,i){const{gl:n}=this.renderer;this.renderer.buffer.bind(t.buffer);const s=this.gl.getUniformBlockIndex(e.program,i);e.uniformBufferBindings[i]=this.shader.uniformBindCount,n.uniformBlockBinding(e.program,s,this.shader.uniformBindCount),this.shader.uniformBindCount++;const o=this.getSignature(t,this.shader.program.uniformData,"ubo");let a=this._uboCache[o];if(a||(a=this._uboCache[o]=hT(t,this.shader.program.uniformData)),t.autoManage){const l=new Float32Array(a.size/4);t.buffer.update(l)}return e.uniformGroups[t.id]=a.syncFunc,e.uniformGroups[t.id]}getSignature(t,e,i){const n=t.uniforms,s=[`${i}-`];for(const o in n)s.push(o),e[o]&&s.push(e[o].type);return s.join("-")}getGlProgram(){return this.shader?this.shader.program.glPrograms[this.renderer.CONTEXT_UID]:null}generateProgram(t){const e=this.gl,i=t.program,n=nT(e,i);return i.glPrograms[this.renderer.CONTEXT_UID]=n,n}reset(){this.program=null,this.shader=null}disposeShader(t){this.shader===t&&(this.shader=null)}destroy(){this.renderer=null,this.destroyed=!0}}Lp.extension={type:K.RendererSystem,name:"shader"},ut.add(Lp);class So{constructor(t){this.renderer=t}run(t){const{renderer:e}=this;e.runners.init.emit(e.options),t.hello&&console.log(`PixiJS 7.4.3 - ${e.rendererLogId} - https://pixijs.com`),e.resize(e.screen.width,e.screen.height)}destroy(){}}So.defaultOptions={hello:!1},So.extension={type:[K.RendererSystem,K.CanvasRendererSystem],name:"startup"},ut.add(So);function uT(r,t=[]){return t[vt.NORMAL]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.ADD]=[r.ONE,r.ONE],t[vt.MULTIPLY]=[r.DST_COLOR,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SCREEN]=[r.ONE,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.OVERLAY]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.DARKEN]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.LIGHTEN]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.COLOR_DODGE]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.COLOR_BURN]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.HARD_LIGHT]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SOFT_LIGHT]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.DIFFERENCE]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.EXCLUSION]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.HUE]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SATURATION]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.COLOR]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.LUMINOSITY]=[r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.NONE]=[0,0],t[vt.NORMAL_NPM]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_ALPHA,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.ADD_NPM]=[r.SRC_ALPHA,r.ONE,r.ONE,r.ONE],t[vt.SCREEN_NPM]=[r.SRC_ALPHA,r.ONE_MINUS_SRC_COLOR,r.ONE,r.ONE_MINUS_SRC_ALPHA],t[vt.SRC_IN]=[r.DST_ALPHA,r.ZERO],t[vt.SRC_OUT]=[r.ONE_MINUS_DST_ALPHA,r.ZERO],t[vt.SRC_ATOP]=[r.DST_ALPHA,r.ONE_MINUS_SRC_ALPHA],t[vt.DST_OVER]=[r.ONE_MINUS_DST_ALPHA,r.ONE],t[vt.DST_IN]=[r.ZERO,r.SRC_ALPHA],t[vt.DST_OUT]=[r.ZERO,r.ONE_MINUS_SRC_ALPHA],t[vt.DST_ATOP]=[r.ONE_MINUS_DST_ALPHA,r.SRC_ALPHA],t[vt.XOR]=[r.ONE_MINUS_DST_ALPHA,r.ONE_MINUS_SRC_ALPHA],t[vt.SUBTRACT]=[r.ONE,r.ONE,r.ONE,r.ONE,r.FUNC_REVERSE_SUBTRACT,r.FUNC_ADD],t}const dT=0,fT=1,pT=2,mT=3,gT=4,yT=5,Dp=class zh{constructor(){this.gl=null,this.stateId=0,this.polygonOffset=0,this.blendMode=vt.NONE,this._blendEq=!1,this.map=[],this.map[dT]=this.setBlend,this.map[fT]=this.setOffset,this.map[pT]=this.setCullFace,this.map[mT]=this.setDepthTest,this.map[gT]=this.setFrontFace,this.map[yT]=this.setDepthMask,this.checks=[],this.defaultState=new mr,this.defaultState.blend=!0}contextChange(t){this.gl=t,this.blendModes=uT(t),this.set(this.defaultState),this.reset()}set(t){if(t=t||this.defaultState,this.stateId!==t.data){let e=this.stateId^t.data,i=0;for(;e;)e&1&&this.map[i].call(this,!!(t.data&1<<i)),e=e>>1,i++;this.stateId=t.data}for(let e=0;e<this.checks.length;e++)this.checks[e](this,t)}forceState(t){t=t||this.defaultState;for(let e=0;e<this.map.length;e++)this.map[e].call(this,!!(t.data&1<<e));for(let e=0;e<this.checks.length;e++)this.checks[e](this,t);this.stateId=t.data}setBlend(t){this.updateCheck(zh.checkBlendMode,t),this.gl[t?"enable":"disable"](this.gl.BLEND)}setOffset(t){this.updateCheck(zh.checkPolygonOffset,t),this.gl[t?"enable":"disable"](this.gl.POLYGON_OFFSET_FILL)}setDepthTest(t){this.gl[t?"enable":"disable"](this.gl.DEPTH_TEST)}setDepthMask(t){this.gl.depthMask(t)}setCullFace(t){this.gl[t?"enable":"disable"](this.gl.CULL_FACE)}setFrontFace(t){this.gl.frontFace(this.gl[t?"CW":"CCW"])}setBlendMode(t){if(t===this.blendMode)return;this.blendMode=t;const e=this.blendModes[t],i=this.gl;e.length===2?i.blendFunc(e[0],e[1]):i.blendFuncSeparate(e[0],e[1],e[2],e[3]),e.length===6?(this._blendEq=!0,i.blendEquationSeparate(e[4],e[5])):this._blendEq&&(this._blendEq=!1,i.blendEquationSeparate(i.FUNC_ADD,i.FUNC_ADD))}setPolygonOffset(t,e){this.gl.polygonOffset(t,e)}reset(){this.gl.pixelStorei(this.gl.UNPACK_FLIP_Y_WEBGL,!1),this.forceState(this.defaultState),this._blendEq=!0,this.blendMode=-1,this.setBlendMode(0)}updateCheck(t,e){const i=this.checks.indexOf(t);e&&i===-1?this.checks.push(t):!e&&i!==-1&&this.checks.splice(i,1)}static checkBlendMode(t,e){t.setBlendMode(e.blendMode)}static checkPolygonOffset(t,e){t.setPolygonOffset(1,e.polygonOffset)}destroy(){this.gl=null}};Dp.extension={type:K.RendererSystem,name:"state"};let _T=Dp;ut.add(_T);class vT extends Vn{constructor(){super(...arguments),this.runners={},this._systemsHash={}}setup(t){this.addRunners(...t.runners);const e=(t.priority??[]).filter(n=>t.systems[n]),i=[...e,...Object.keys(t.systems).filter(n=>!e.includes(n))];for(const n of i)this.addSystem(t.systems[n],n)}addRunners(...t){t.forEach(e=>{this.runners[e]=new qe(e)})}addSystem(t,e){const i=new t(this);if(this[e])throw new Error(`Whoops! The name "${e}" is already in use`);this[e]=i,this._systemsHash[e]=i;for(const n in this.runners)this.runners[n].add(i);return this}emitWithCustomOptions(t,e){const i=Object.keys(this._systemsHash);t.items.forEach(n=>{const s=i.find(o=>this._systemsHash[o]===n);n[t.name](e[s])})}destroy(){Object.values(this.runners).forEach(t=>{t.destroy()}),this._systemsHash={}}}const cs=class Qo{constructor(t){this.renderer=t,this.count=0,this.checkCount=0,this.maxIdle=Qo.defaultMaxIdle,this.checkCountMax=Qo.defaultCheckCountMax,this.mode=Qo.defaultMode}postrender(){this.renderer.objectRenderer.renderingToScreen&&(this.count++,this.mode!==qa.MANUAL&&(this.checkCount++,this.checkCount>this.checkCountMax&&(this.checkCount=0,this.run())))}run(){const t=this.renderer.texture,e=t.managedTextures;let i=!1;for(let n=0;n<e.length;n++){const s=e[n];s.resource&&this.count-s.touched>this.maxIdle&&(t.destroyTexture(s,!0),e[n]=null,i=!0)}if(i){let n=0;for(let s=0;s<e.length;s++)e[s]!==null&&(e[n++]=e[s]);e.length=n}}unload(t){const e=this.renderer.texture,i=t._texture;i&&!i.framebuffer&&e.destroyTexture(i);for(let n=t.children.length-1;n>=0;n--)this.unload(t.children[n])}destroy(){this.renderer=null}};cs.defaultMode=qa.AUTO,cs.defaultMaxIdle=60*60,cs.defaultCheckCountMax=60*10,cs.extension={type:K.RendererSystem,name:"textureGC"};let Ii=cs;ut.add(Ii);class dh{constructor(t){this.texture=t,this.width=-1,this.height=-1,this.dirtyId=-1,this.dirtyStyleId=-1,this.mipmap=!1,this.wrapMode=33071,this.type=mt.UNSIGNED_BYTE,this.internalFormat=W.RGBA,this.samplerType=0}}function bT(r){let t;return"WebGL2RenderingContext"in globalThis&&r instanceof globalThis.WebGL2RenderingContext?t={[r.RGB]:Q.FLOAT,[r.RGBA]:Q.FLOAT,[r.ALPHA]:Q.FLOAT,[r.LUMINANCE]:Q.FLOAT,[r.LUMINANCE_ALPHA]:Q.FLOAT,[r.R8]:Q.FLOAT,[r.R8_SNORM]:Q.FLOAT,[r.RG8]:Q.FLOAT,[r.RG8_SNORM]:Q.FLOAT,[r.RGB8]:Q.FLOAT,[r.RGB8_SNORM]:Q.FLOAT,[r.RGB565]:Q.FLOAT,[r.RGBA4]:Q.FLOAT,[r.RGB5_A1]:Q.FLOAT,[r.RGBA8]:Q.FLOAT,[r.RGBA8_SNORM]:Q.FLOAT,[r.RGB10_A2]:Q.FLOAT,[r.RGB10_A2UI]:Q.FLOAT,[r.SRGB8]:Q.FLOAT,[r.SRGB8_ALPHA8]:Q.FLOAT,[r.R16F]:Q.FLOAT,[r.RG16F]:Q.FLOAT,[r.RGB16F]:Q.FLOAT,[r.RGBA16F]:Q.FLOAT,[r.R32F]:Q.FLOAT,[r.RG32F]:Q.FLOAT,[r.RGB32F]:Q.FLOAT,[r.RGBA32F]:Q.FLOAT,[r.R11F_G11F_B10F]:Q.FLOAT,[r.RGB9_E5]:Q.FLOAT,[r.R8I]:Q.INT,[r.R8UI]:Q.UINT,[r.R16I]:Q.INT,[r.R16UI]:Q.UINT,[r.R32I]:Q.INT,[r.R32UI]:Q.UINT,[r.RG8I]:Q.INT,[r.RG8UI]:Q.UINT,[r.RG16I]:Q.INT,[r.RG16UI]:Q.UINT,[r.RG32I]:Q.INT,[r.RG32UI]:Q.UINT,[r.RGB8I]:Q.INT,[r.RGB8UI]:Q.UINT,[r.RGB16I]:Q.INT,[r.RGB16UI]:Q.UINT,[r.RGB32I]:Q.INT,[r.RGB32UI]:Q.UINT,[r.RGBA8I]:Q.INT,[r.RGBA8UI]:Q.UINT,[r.RGBA16I]:Q.INT,[r.RGBA16UI]:Q.UINT,[r.RGBA32I]:Q.INT,[r.RGBA32UI]:Q.UINT,[r.DEPTH_COMPONENT16]:Q.FLOAT,[r.DEPTH_COMPONENT24]:Q.FLOAT,[r.DEPTH_COMPONENT32F]:Q.FLOAT,[r.DEPTH_STENCIL]:Q.FLOAT,[r.DEPTH24_STENCIL8]:Q.FLOAT,[r.DEPTH32F_STENCIL8]:Q.FLOAT}:t={[r.RGB]:Q.FLOAT,[r.RGBA]:Q.FLOAT,[r.ALPHA]:Q.FLOAT,[r.LUMINANCE]:Q.FLOAT,[r.LUMINANCE_ALPHA]:Q.FLOAT,[r.DEPTH_STENCIL]:Q.FLOAT},t}function xT(r){let t;return"WebGL2RenderingContext"in globalThis&&r instanceof globalThis.WebGL2RenderingContext?t={[mt.UNSIGNED_BYTE]:{[W.RGBA]:r.RGBA8,[W.RGB]:r.RGB8,[W.RG]:r.RG8,[W.RED]:r.R8,[W.RGBA_INTEGER]:r.RGBA8UI,[W.RGB_INTEGER]:r.RGB8UI,[W.RG_INTEGER]:r.RG8UI,[W.RED_INTEGER]:r.R8UI,[W.ALPHA]:r.ALPHA,[W.LUMINANCE]:r.LUMINANCE,[W.LUMINANCE_ALPHA]:r.LUMINANCE_ALPHA},[mt.BYTE]:{[W.RGBA]:r.RGBA8_SNORM,[W.RGB]:r.RGB8_SNORM,[W.RG]:r.RG8_SNORM,[W.RED]:r.R8_SNORM,[W.RGBA_INTEGER]:r.RGBA8I,[W.RGB_INTEGER]:r.RGB8I,[W.RG_INTEGER]:r.RG8I,[W.RED_INTEGER]:r.R8I},[mt.UNSIGNED_SHORT]:{[W.RGBA_INTEGER]:r.RGBA16UI,[W.RGB_INTEGER]:r.RGB16UI,[W.RG_INTEGER]:r.RG16UI,[W.RED_INTEGER]:r.R16UI,[W.DEPTH_COMPONENT]:r.DEPTH_COMPONENT16},[mt.SHORT]:{[W.RGBA_INTEGER]:r.RGBA16I,[W.RGB_INTEGER]:r.RGB16I,[W.RG_INTEGER]:r.RG16I,[W.RED_INTEGER]:r.R16I},[mt.UNSIGNED_INT]:{[W.RGBA_INTEGER]:r.RGBA32UI,[W.RGB_INTEGER]:r.RGB32UI,[W.RG_INTEGER]:r.RG32UI,[W.RED_INTEGER]:r.R32UI,[W.DEPTH_COMPONENT]:r.DEPTH_COMPONENT24},[mt.INT]:{[W.RGBA_INTEGER]:r.RGBA32I,[W.RGB_INTEGER]:r.RGB32I,[W.RG_INTEGER]:r.RG32I,[W.RED_INTEGER]:r.R32I},[mt.FLOAT]:{[W.RGBA]:r.RGBA32F,[W.RGB]:r.RGB32F,[W.RG]:r.RG32F,[W.RED]:r.R32F,[W.DEPTH_COMPONENT]:r.DEPTH_COMPONENT32F},[mt.HALF_FLOAT]:{[W.RGBA]:r.RGBA16F,[W.RGB]:r.RGB16F,[W.RG]:r.RG16F,[W.RED]:r.R16F},[mt.UNSIGNED_SHORT_5_6_5]:{[W.RGB]:r.RGB565},[mt.UNSIGNED_SHORT_4_4_4_4]:{[W.RGBA]:r.RGBA4},[mt.UNSIGNED_SHORT_5_5_5_1]:{[W.RGBA]:r.RGB5_A1},[mt.UNSIGNED_INT_2_10_10_10_REV]:{[W.RGBA]:r.RGB10_A2,[W.RGBA_INTEGER]:r.RGB10_A2UI},[mt.UNSIGNED_INT_10F_11F_11F_REV]:{[W.RGB]:r.R11F_G11F_B10F},[mt.UNSIGNED_INT_5_9_9_9_REV]:{[W.RGB]:r.RGB9_E5},[mt.UNSIGNED_INT_24_8]:{[W.DEPTH_STENCIL]:r.DEPTH24_STENCIL8},[mt.FLOAT_32_UNSIGNED_INT_24_8_REV]:{[W.DEPTH_STENCIL]:r.DEPTH32F_STENCIL8}}:t={[mt.UNSIGNED_BYTE]:{[W.RGBA]:r.RGBA,[W.RGB]:r.RGB,[W.ALPHA]:r.ALPHA,[W.LUMINANCE]:r.LUMINANCE,[W.LUMINANCE_ALPHA]:r.LUMINANCE_ALPHA},[mt.UNSIGNED_SHORT_5_6_5]:{[W.RGB]:r.RGB},[mt.UNSIGNED_SHORT_4_4_4_4]:{[W.RGBA]:r.RGBA},[mt.UNSIGNED_SHORT_5_5_5_1]:{[W.RGBA]:r.RGBA}},t}class Np{constructor(t){this.renderer=t,this.boundTextures=[],this.currentLocation=-1,this.managedTextures=[],this._unknownBoundTextures=!1,this.unknownTexture=new xt,this.hasIntegerTextures=!1}contextChange(){const t=this.gl=this.renderer.gl;this.CONTEXT_UID=this.renderer.CONTEXT_UID,this.webGLVersion=this.renderer.context.webGLVersion,this.internalFormats=xT(t),this.samplerTypes=bT(t);const e=t.getParameter(t.MAX_TEXTURE_IMAGE_UNITS);this.boundTextures.length=e;for(let n=0;n<e;n++)this.boundTextures[n]=null;this.emptyTextures={};const i=new dh(t.createTexture());t.bindTexture(t.TEXTURE_2D,i.texture),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,new Uint8Array(4)),this.emptyTextures[t.TEXTURE_2D]=i,this.emptyTextures[t.TEXTURE_CUBE_MAP]=new dh(t.createTexture()),t.bindTexture(t.TEXTURE_CUBE_MAP,this.emptyTextures[t.TEXTURE_CUBE_MAP].texture);for(let n=0;n<6;n++)t.texImage2D(t.TEXTURE_CUBE_MAP_POSITIVE_X+n,0,t.RGBA,1,1,0,t.RGBA,t.UNSIGNED_BYTE,null);t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_CUBE_MAP,t.TEXTURE_MIN_FILTER,t.LINEAR);for(let n=0;n<this.boundTextures.length;n++)this.bind(null,n)}bind(t,e=0){const{gl:i}=this;if(t=t==null?void 0:t.castToBaseTexture(),(t==null?void 0:t.valid)&&!t.parentTextureArray){t.touched=this.renderer.textureGC.count;const n=t._glTextures[this.CONTEXT_UID]||this.initTexture(t);this.boundTextures[e]!==t&&(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(t.target,n.texture)),n.dirtyId!==t.dirtyId?(this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),this.updateTexture(t)):n.dirtyStyleId!==t.dirtyStyleId&&this.updateTextureStyle(t),this.boundTextures[e]=t}else this.currentLocation!==e&&(this.currentLocation=e,i.activeTexture(i.TEXTURE0+e)),i.bindTexture(i.TEXTURE_2D,this.emptyTextures[i.TEXTURE_2D].texture),this.boundTextures[e]=null}reset(){this._unknownBoundTextures=!0,this.hasIntegerTextures=!1,this.currentLocation=-1;for(let t=0;t<this.boundTextures.length;t++)this.boundTextures[t]=this.unknownTexture}unbind(t){const{gl:e,boundTextures:i}=this;if(this._unknownBoundTextures){this._unknownBoundTextures=!1;for(let n=0;n<i.length;n++)i[n]===this.unknownTexture&&this.bind(null,n)}for(let n=0;n<i.length;n++)i[n]===t&&(this.currentLocation!==n&&(e.activeTexture(e.TEXTURE0+n),this.currentLocation=n),e.bindTexture(t.target,this.emptyTextures[t.target].texture),i[n]=null)}ensureSamplerType(t){const{boundTextures:e,hasIntegerTextures:i,CONTEXT_UID:n}=this;if(i)for(let s=t-1;s>=0;--s){const o=e[s];o&&o._glTextures[n].samplerType!==Q.FLOAT&&this.renderer.texture.unbind(o)}}initTexture(t){const e=new dh(this.gl.createTexture());return e.dirtyId=-1,t._glTextures[this.CONTEXT_UID]=e,this.managedTextures.push(t),t.on("dispose",this.destroyTexture,this),e}initTextureType(t,e){var i;e.internalFormat=((i=this.internalFormats[t.type])==null?void 0:i[t.format])??t.format,e.samplerType=this.samplerTypes[e.internalFormat]??Q.FLOAT,this.webGLVersion===2&&t.type===mt.HALF_FLOAT?e.type=this.gl.HALF_FLOAT:e.type=t.type}updateTexture(t){var n;const e=t._glTextures[this.CONTEXT_UID];if(!e)return;const i=this.renderer;if(this.initTextureType(t,e),(n=t.resource)==null?void 0:n.upload(i,t,e))e.samplerType!==Q.FLOAT&&(this.hasIntegerTextures=!0);else{const s=t.realWidth,o=t.realHeight,a=i.gl;(e.width!==s||e.height!==o||e.dirtyId<0)&&(e.width=s,e.height=o,a.texImage2D(t.target,0,e.internalFormat,s,o,0,t.format,e.type,null))}t.dirtyStyleId!==e.dirtyStyleId&&this.updateTextureStyle(t),e.dirtyId=t.dirtyId}destroyTexture(t,e){const{gl:i}=this;if(t=t.castToBaseTexture(),t._glTextures[this.CONTEXT_UID]&&(this.unbind(t),i.deleteTexture(t._glTextures[this.CONTEXT_UID].texture),t.off("dispose",this.destroyTexture,this),delete t._glTextures[this.CONTEXT_UID],!e)){const n=this.managedTextures.indexOf(t);n!==-1&&dn(this.managedTextures,n,1)}}updateTextureStyle(t){var i;const e=t._glTextures[this.CONTEXT_UID];e&&((t.mipmap===or.POW2||this.webGLVersion!==2)&&!t.isPowerOfTwo?e.mipmap=!1:e.mipmap=t.mipmap>=1,this.webGLVersion!==2&&!t.isPowerOfTwo?e.wrapMode=jr.CLAMP:e.wrapMode=t.wrapMode,(i=t.resource)!=null&&i.style(this.renderer,t,e)||this.setStyle(t,e),e.dirtyStyleId=t.dirtyStyleId)}setStyle(t,e){const i=this.gl;if(e.mipmap&&t.mipmap!==or.ON_MANUAL&&i.generateMipmap(t.target),i.texParameteri(t.target,i.TEXTURE_WRAP_S,e.wrapMode),i.texParameteri(t.target,i.TEXTURE_WRAP_T,e.wrapMode),e.mipmap){i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===br.LINEAR?i.LINEAR_MIPMAP_LINEAR:i.NEAREST_MIPMAP_NEAREST);const n=this.renderer.context.extensions.anisotropicFiltering;if(n&&t.anisotropicLevel>0&&t.scaleMode===br.LINEAR){const s=Math.min(t.anisotropicLevel,i.getParameter(n.MAX_TEXTURE_MAX_ANISOTROPY_EXT));i.texParameterf(t.target,n.TEXTURE_MAX_ANISOTROPY_EXT,s)}}else i.texParameteri(t.target,i.TEXTURE_MIN_FILTER,t.scaleMode===br.LINEAR?i.LINEAR:i.NEAREST);i.texParameteri(t.target,i.TEXTURE_MAG_FILTER,t.scaleMode===br.LINEAR?i.LINEAR:i.NEAREST)}destroy(){this.renderer=null}}Np.extension={type:K.RendererSystem,name:"texture"},ut.add(Np);class Fp{constructor(t){this.renderer=t}contextChange(){this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,n=t._glTransformFeedbacks[i]||this.createGLTransformFeedback(t);e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,n)}unbind(){const{gl:t}=this;t.bindTransformFeedback(t.TRANSFORM_FEEDBACK,null)}beginTransformFeedback(t,e){const{gl:i,renderer:n}=this;e&&n.shader.bind(e),i.beginTransformFeedback(t)}endTransformFeedback(){const{gl:t}=this;t.endTransformFeedback()}createGLTransformFeedback(t){const{gl:e,renderer:i,CONTEXT_UID:n}=this,s=e.createTransformFeedback();t._glTransformFeedbacks[n]=s,e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,s);for(let o=0;o<t.buffers.length;o++){const a=t.buffers[o];a&&(i.buffer.update(a),a._glBuffers[n].refCount++,e.bindBufferBase(e.TRANSFORM_FEEDBACK_BUFFER,o,a._glBuffers[n].buffer||null))}return e.bindTransformFeedback(e.TRANSFORM_FEEDBACK,null),t.disposeRunner.add(this),s}disposeTransformFeedback(t,e){const i=t._glTransformFeedbacks[this.CONTEXT_UID],n=this.gl;t.disposeRunner.remove(this);const s=this.renderer.buffer;if(s)for(let o=0;o<t.buffers.length;o++){const a=t.buffers[o];if(!a)continue;const l=a._glBuffers[this.CONTEXT_UID];l&&(l.refCount--,l.refCount===0&&!e&&s.dispose(a,e))}i&&(e||n.deleteTransformFeedback(i),delete t._glTransformFeedbacks[this.CONTEXT_UID])}destroy(){this.renderer=null}}Fp.extension={type:K.RendererSystem,name:"transformFeedback"},ut.add(Fp);class Co{constructor(t){this.renderer=t}init(t){this.screen=new wt(0,0,t.width,t.height),this.element=t.view||tt.ADAPTER.createCanvas(),this.resolution=t.resolution||tt.RESOLUTION,this.autoDensity=!!t.autoDensity}resizeView(t,e){this.element.width=Math.round(t*this.resolution),this.element.height=Math.round(e*this.resolution);const i=this.element.width/this.resolution,n=this.element.height/this.resolution;this.screen.width=i,this.screen.height=n,this.autoDensity&&(this.element.style.width=`${i}px`,this.element.style.height=`${n}px`),this.renderer.emit("resize",i,n),this.renderer.runners.resize.emit(this.screen.width,this.screen.height)}destroy(t){var e;t&&((e=this.element.parentNode)==null||e.removeChild(this.element)),this.renderer=null,this.element=null,this.screen=null}}Co.defaultOptions={width:800,height:600,resolution:void 0,autoDensity:!1},Co.extension={type:[K.RendererSystem,K.CanvasRendererSystem],name:"_view"},ut.add(Co),tt.PREFER_ENV=fi.WEBGL2,tt.STRICT_TEXTURE_CACHE=!1,tt.RENDER_OPTIONS={...wo.defaultOptions,...xo.defaultOptions,...Co.defaultOptions,...So.defaultOptions},Object.defineProperties(tt,{WRAP_MODE:{get(){return xt.defaultOptions.wrapMode},set(r){St("7.1.0","settings.WRAP_MODE is deprecated, use BaseTexture.defaultOptions.wrapMode"),xt.defaultOptions.wrapMode=r}},SCALE_MODE:{get(){return xt.defaultOptions.scaleMode},set(r){St("7.1.0","settings.SCALE_MODE is deprecated, use BaseTexture.defaultOptions.scaleMode"),xt.defaultOptions.scaleMode=r}},MIPMAP_TEXTURES:{get(){return xt.defaultOptions.mipmap},set(r){St("7.1.0","settings.MIPMAP_TEXTURES is deprecated, use BaseTexture.defaultOptions.mipmap"),xt.defaultOptions.mipmap=r}},ANISOTROPIC_LEVEL:{get(){return xt.defaultOptions.anisotropicLevel},set(r){St("7.1.0","settings.ANISOTROPIC_LEVEL is deprecated, use BaseTexture.defaultOptions.anisotropicLevel"),xt.defaultOptions.anisotropicLevel=r}},FILTER_RESOLUTION:{get(){return St("7.1.0","settings.FILTER_RESOLUTION is deprecated, use Filter.defaultResolution"),Re.defaultResolution},set(r){Re.defaultResolution=r}},FILTER_MULTISAMPLE:{get(){return St("7.1.0","settings.FILTER_MULTISAMPLE is deprecated, use Filter.defaultMultisample"),Re.defaultMultisample},set(r){Re.defaultMultisample=r}},SPRITE_MAX_TEXTURES:{get(){return Ai.defaultMaxTextures},set(r){St("7.1.0","settings.SPRITE_MAX_TEXTURES is deprecated, use BatchRenderer.defaultMaxTextures"),Ai.defaultMaxTextures=r}},SPRITE_BATCH_SIZE:{get(){return Ai.defaultBatchSize},set(r){St("7.1.0","settings.SPRITE_BATCH_SIZE is deprecated, use BatchRenderer.defaultBatchSize"),Ai.defaultBatchSize=r}},CAN_UPLOAD_SAME_BUFFER:{get(){return Ai.canUploadSameBuffer},set(r){St("7.1.0","settings.CAN_UPLOAD_SAME_BUFFER is deprecated, use BatchRenderer.canUploadSameBuffer"),Ai.canUploadSameBuffer=r}},GC_MODE:{get(){return Ii.defaultMode},set(r){St("7.1.0","settings.GC_MODE is deprecated, use TextureGCSystem.defaultMode"),Ii.defaultMode=r}},GC_MAX_IDLE:{get(){return Ii.defaultMaxIdle},set(r){St("7.1.0","settings.GC_MAX_IDLE is deprecated, use TextureGCSystem.defaultMaxIdle"),Ii.defaultMaxIdle=r}},GC_MAX_CHECK_COUNT:{get(){return Ii.defaultCheckCountMax},set(r){St("7.1.0","settings.GC_MAX_CHECK_COUNT is deprecated, use TextureGCSystem.defaultCheckCountMax"),Ii.defaultCheckCountMax=r}},PRECISION_VERTEX:{get(){return Ir.defaultVertexPrecision},set(r){St("7.1.0","settings.PRECISION_VERTEX is deprecated, use Program.defaultVertexPrecision"),Ir.defaultVertexPrecision=r}},PRECISION_FRAGMENT:{get(){return Ir.defaultFragmentPrecision},set(r){St("7.1.0","settings.PRECISION_FRAGMENT is deprecated, use Program.defaultFragmentPrecision"),Ir.defaultFragmentPrecision=r}}});var Pi=(r=>(r[r.INTERACTION=50]="INTERACTION",r[r.HIGH=25]="HIGH",r[r.NORMAL=0]="NORMAL",r[r.LOW=-25]="LOW",r[r.UTILITY=-50]="UTILITY",r))(Pi||{});class fh{constructor(t,e=null,i=0,n=!1){this.next=null,this.previous=null,this._destroyed=!1,this.fn=t,this.context=e,this.priority=i,this.once=n}match(t,e=null){return this.fn===t&&this.context===e}emit(t){this.fn&&(this.context?this.fn.call(this.context,t):this.fn(t));const e=this.next;return this.once&&this.destroy(!0),this._destroyed&&(this.next=null),e}connect(t){this.previous=t,t.next&&(t.next.previous=this),this.next=t.next,t.next=this}destroy(t=!1){this._destroyed=!0,this.fn=null,this.context=null,this.previous&&(this.previous.next=this.next),this.next&&(this.next.previous=this.previous);const e=this.next;return this.next=t?null:e,this.previous=null,e}}const kp=class Ue{constructor(){this.autoStart=!1,this.deltaTime=1,this.lastTime=-1,this.speed=1,this.started=!1,this._requestId=null,this._maxElapsedMS=100,this._minElapsedMS=0,this._protected=!1,this._lastFrame=-1,this._head=new fh(null,null,1/0),this.deltaMS=1/Ue.targetFPMS,this.elapsedMS=1/Ue.targetFPMS,this._tick=t=>{this._requestId=null,this.started&&(this.update(t),this.started&&this._requestId===null&&this._head.next&&(this._requestId=requestAnimationFrame(this._tick)))}}_requestIfNeeded(){this._requestId===null&&this._head.next&&(this.lastTime=performance.now(),this._lastFrame=this.lastTime,this._requestId=requestAnimationFrame(this._tick))}_cancelIfNeeded(){this._requestId!==null&&(cancelAnimationFrame(this._requestId),this._requestId=null)}_startIfPossible(){this.started?this._requestIfNeeded():this.autoStart&&this.start()}add(t,e,i=Pi.NORMAL){return this._addListener(new fh(t,e,i))}addOnce(t,e,i=Pi.NORMAL){return this._addListener(new fh(t,e,i,!0))}_addListener(t){let e=this._head.next,i=this._head;if(!e)t.connect(i);else{for(;e;){if(t.priority>e.priority){t.connect(i);break}i=e,e=e.next}t.previous||t.connect(i)}return this._startIfPossible(),this}remove(t,e){let i=this._head.next;for(;i;)i.match(t,e)?i=i.destroy():i=i.next;return this._head.next||this._cancelIfNeeded(),this}get count(){if(!this._head)return 0;let t=0,e=this._head;for(;e=e.next;)t++;return t}start(){this.started||(this.started=!0,this._requestIfNeeded())}stop(){this.started&&(this.started=!1,this._cancelIfNeeded())}destroy(){if(!this._protected){this.stop();let t=this._head.next;for(;t;)t=t.destroy(!0);this._head.destroy(),this._head=null}}update(t=performance.now()){let e;if(t>this.lastTime){if(e=this.elapsedMS=t-this.lastTime,e>this._maxElapsedMS&&(e=this._maxElapsedMS),e*=this.speed,this._minElapsedMS){const s=t-this._lastFrame|0;if(s<this._minElapsedMS)return;this._lastFrame=t-s%this._minElapsedMS}this.deltaMS=e,this.deltaTime=this.deltaMS*Ue.targetFPMS;const i=this._head;let n=i.next;for(;n;)n=n.emit(this.deltaTime);i.next||this._cancelIfNeeded()}else this.deltaTime=this.deltaMS=this.elapsedMS=0;this.lastTime=t}get FPS(){return 1e3/this.elapsedMS}get minFPS(){return 1e3/this._maxElapsedMS}set minFPS(t){const e=Math.min(this.maxFPS,t),i=Math.min(Math.max(0,e)/1e3,Ue.targetFPMS);this._maxElapsedMS=1/i}get maxFPS(){return this._minElapsedMS?Math.round(1e3/this._minElapsedMS):0}set maxFPS(t){if(t===0)this._minElapsedMS=0;else{const e=Math.max(this.minFPS,t);this._minElapsedMS=1/(e/1e3)}}static get shared(){if(!Ue._shared){const t=Ue._shared=new Ue;t.autoStart=!0,t._protected=!0}return Ue._shared}static get system(){if(!Ue._system){const t=Ue._system=new Ue;t.autoStart=!0,t._protected=!0}return Ue._system}};kp.targetFPMS=.06;let ke=kp;Object.defineProperties(tt,{TARGET_FPMS:{get(){return ke.targetFPMS},set(r){St("7.1.0","settings.TARGET_FPMS is deprecated, use Ticker.targetFPMS"),ke.targetFPMS=r}}});class Up{static init(t){t=Object.assign({autoStart:!0,sharedTicker:!1},t),Object.defineProperty(this,"ticker",{set(e){this._ticker&&this._ticker.remove(this.render,this),this._ticker=e,e&&e.add(this.render,this,Pi.LOW)},get(){return this._ticker}}),this.stop=()=>{this._ticker.stop()},this.start=()=>{this._ticker.start()},this._ticker=null,this.ticker=t.sharedTicker?ke.shared:new ke,t.autoStart&&this.start()}static destroy(){if(this._ticker){const t=this._ticker;this.ticker=null,t.destroy()}}}Up.extension=K.Application,ut.add(Up);const Gp=[];ut.handleByList(K.Renderer,Gp);function $p(r){for(const t of Gp)if(t.test(r))return new t(r);throw new Error("Unable to auto-detect a suitable renderer.")}var wT=`attribute vec2 aVertexPosition;
490
490
  attribute vec2 aTextureCoord;
491
491
 
492
492
  uniform mat3 projectionMatrix;
@@ -523,7 +523,7 @@ void main(void)
523
523
  gl_Position = filterVertexPosition();
524
524
  vTextureCoord = filterTextureCoord();
525
525
  }
526
- `;const TT=wT,Hp=ET;class Vp{constructor(t){this.renderer=t}contextChange(t){let e;if(this.renderer.context.webGLVersion===1){const i=t.getParameter(t.FRAMEBUFFER_BINDING);t.bindFramebuffer(t.FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.FRAMEBUFFER,i)}else{const i=t.getParameter(t.DRAW_FRAMEBUFFER_BINDING);t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,i)}e>=re.HIGH?this.multisample=re.HIGH:e>=re.MEDIUM?this.multisample=re.MEDIUM:e>=re.LOW?this.multisample=re.LOW:this.multisample=re.NONE}destroy(){}}Vp.extension={type:K.RendererSystem,name:"_multisample"},ut.add(Vp);class AT{constructor(t){this.buffer=t||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}}class Xp{constructor(t){this.renderer=t,this.managedBuffers={},this.boundBufferBases={}}destroy(){this.renderer=null}contextChange(){this.disposeAll(!0),this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,n=t._glBuffers[i]||this.createGLBuffer(t);e.bindBuffer(t.type,n.buffer)}unbind(t){const{gl:e}=this;e.bindBuffer(t,null)}bindBufferBase(t,e){const{gl:i,CONTEXT_UID:n}=this;if(this.boundBufferBases[e]!==t){const s=t._glBuffers[n]||this.createGLBuffer(t);this.boundBufferBases[e]=t,i.bindBufferBase(i.UNIFORM_BUFFER,e,s.buffer)}}bindBufferRange(t,e,i){const{gl:n,CONTEXT_UID:s}=this;i=i||0;const o=t._glBuffers[s]||this.createGLBuffer(t);n.bindBufferRange(n.UNIFORM_BUFFER,e||0,o.buffer,i*256,256)}update(t){const{gl:e,CONTEXT_UID:i}=this,n=t._glBuffers[i]||this.createGLBuffer(t);if(t._updateID!==n.updateID)if(n.updateID=t._updateID,e.bindBuffer(t.type,n.buffer),n.byteLength>=t.data.byteLength)e.bufferSubData(t.type,0,t.data);else{const s=t.static?e.STATIC_DRAW:e.DYNAMIC_DRAW;n.byteLength=t.data.byteLength,e.bufferData(t.type,t.data,s)}}dispose(t,e){if(!this.managedBuffers[t.id])return;delete this.managedBuffers[t.id];const i=t._glBuffers[this.CONTEXT_UID],n=this.gl;t.disposeRunner.remove(this),i&&(e||n.deleteBuffer(i.buffer),delete t._glBuffers[this.CONTEXT_UID])}disposeAll(t){const e=Object.keys(this.managedBuffers);for(let i=0;i<e.length;i++)this.dispose(this.managedBuffers[e[i]],t)}createGLBuffer(t){const{CONTEXT_UID:e,gl:i}=this;return t._glBuffers[e]=new AT(i.createBuffer()),this.managedBuffers[t.id]=t,t.disposeRunner.add(this),t._glBuffers[e]}}Xp.extension={type:K.RendererSystem,name:"buffer"},ut.add(Xp);class jp{constructor(t){this.renderer=t}render(t,e){const i=this.renderer;let n,s,o,a;if(e&&(n=e.renderTexture,s=e.clear,o=e.transform,a=e.skipUpdateTransform),this.renderingToScreen=!n,i.runners.prerender.emit(),i.emit("prerender"),i.projection.transform=o,!i.context.isLost){if(n||(this.lastObjectRendered=t),!a){const l=t.enableTempParent();t.updateTransform(),t.disableTempParent(l)}i.renderTexture.bind(n),i.batch.currentRenderer.start(),(s??i.background.clearBeforeRender)&&i.renderTexture.clear(),t.render(i),i.batch.currentRenderer.flush(),n&&(e.blit&&i.framebuffer.blit(),n.baseTexture.update()),i.runners.postrender.emit(),i.projection.transform=null,i.emit("postrender")}}destroy(){this.renderer=null,this.lastObjectRendered=null}}jp.extension={type:K.RendererSystem,name:"objectRenderer"},ut.add(jp);const Io=class qh extends vT{constructor(t){super(),this.type=fd.WEBGL,t=Object.assign({},tt.RENDER_OPTIONS,t),this.gl=null,this.CONTEXT_UID=0,this.globalUniforms=new Ke({projectionMatrix:new Ft},!0);const e={runners:["init","destroy","contextChange","resolutionChange","reset","update","postrender","prerender","resize"],systems:qh.__systems,priority:["_view","textureGenerator","background","_plugin","startup","context","state","texture","buffer","geometry","framebuffer","transformFeedback","mask","scissor","stencil","projection","textureGC","filter","renderTexture","batch","objectRenderer","_multisample"]};this.setup(e),"useContextAlpha"in t&&(St("7.0.0","options.useContextAlpha is deprecated, use options.premultipliedAlpha and options.backgroundAlpha instead"),t.premultipliedAlpha=t.useContextAlpha&&t.useContextAlpha!=="notMultiplied",t.backgroundAlpha=t.useContextAlpha===!1?1:t.backgroundAlpha),this._plugin.rendererPlugins=qh.__plugins,this.options=t,this.startup.run(this.options)}static test(t){return t!=null&&t.forceCanvas?!1:qw()}render(t,e){this.objectRenderer.render(t,e)}resize(t,e){this._view.resizeView(t,e)}reset(){return this.runners.reset.emit(),this}clear(){this.renderTexture.bind(),this.renderTexture.clear()}destroy(t=!1){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:t}),super.destroy()}get plugins(){return this._plugin.plugins}get multisample(){return this._multisample.multisample}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}set resolution(t){this._view.resolution=t,this.runners.resolutionChange.emit(t)}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get rendererLogId(){return`WebGL ${this.context.webGLVersion}`}get clearBeforeRender(){return St("7.0.0","renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead."),this.background.clearBeforeRender}get useContextAlpha(){return St("7.0.0","renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead."),this.context.useContextAlpha}get preserveDrawingBuffer(){return St("7.0.0","renderer.preserveDrawingBuffer has been deprecated, we cannot truly know this unless pixi created the context"),this.context.preserveDrawingBuffer}get backgroundColor(){return St("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){St("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return St("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){St("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get powerPreference(){return St("7.0.0","renderer.powerPreference has been deprecated, we can only know this if pixi creates the context"),this.context.powerPreference}generateTexture(t,e){return this.textureGenerator.generateTexture(t,e)}};Io.extension={type:K.Renderer,priority:1},Io.__plugins={},Io.__systems={};let ph=Io;ut.handleByMap(K.RendererPlugin,ph.__plugins),ut.handleByMap(K.RendererSystem,ph.__systems),ut.add(ph);class Wp extends os{constructor(t,e){const{width:i,height:n}=e||{};super(i,n),this.items=[],this.itemDirtyIds=[];for(let s=0;s<t;s++){const o=new xt;this.items.push(o),this.itemDirtyIds.push(-2)}this.length=t,this._load=null,this.baseTexture=null}initFromArray(t,e){for(let i=0;i<this.length;i++)t[i]&&(t[i].castToBaseTexture?this.addBaseTextureAt(t[i].castToBaseTexture(),i):t[i]instanceof os?this.addResourceAt(t[i],i):this.addResourceAt(Jf(t[i],e),i))}dispose(){for(let t=0,e=this.length;t<e;t++)this.items[t].destroy();this.items=null,this.itemDirtyIds=null,this._load=null}addResourceAt(t,e){if(!this.items[e])throw new Error(`Index ${e} is out of bounds`);return t.valid&&!this.valid&&this.resize(t.width,t.height),this.items[e].setResource(t),this}bind(t){if(this.baseTexture!==null)throw new Error("Only one base texture per TextureArray is allowed");super.bind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=t,this.items[e].on("update",t.update,t)}unbind(t){super.unbind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=null,this.items[e].off("update",t.update,t)}load(){if(this._load)return this._load;const t=this.items.map(e=>e.resource).filter(e=>e).map(e=>e.load());return this._load=Promise.all(t).then(()=>{const{realWidth:e,realHeight:i}=this.items[0];return this.resize(e,i),this.update(),Promise.resolve(this)}),this._load}}class ST extends Wp{constructor(t,e){const{width:i,height:n}=e||{};let s,o;Array.isArray(t)?(s=t,o=t.length):o=t,super(o,{width:i,height:n}),s&&this.initFromArray(s,e)}addBaseTextureAt(t,e){if(t.resource)this.addResourceAt(t.resource,e);else throw new Error("ArrayResource does not support RenderTexture");return this}bind(t){super.bind(t),t.target=Ji.TEXTURE_2D_ARRAY}upload(t,e,i){const{length:n,itemDirtyIds:s,items:o}=this,{gl:a}=t;i.dirtyId<0&&a.texImage3D(a.TEXTURE_2D_ARRAY,0,i.internalFormat,this._width,this._height,n,0,e.format,i.type,null);for(let l=0;l<n;l++){const h=o[l];s[l]<h.dirtyId&&(s[l]=h.dirtyId,h.valid&&a.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,l,h.resource.width,h.resource.height,1,e.format,i.type,h.resource.source))}return!0}}class CT extends Pr{constructor(t){super(t)}static test(t){const{OffscreenCanvas:e}=globalThis;return e&&t instanceof e?!0:globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement}}const Yp=class ys extends Wp{constructor(t,e){const{width:i,height:n,autoLoad:s,linkBaseTexture:o}=e||{};if(t&&t.length!==ys.SIDES)throw new Error(`Invalid length. Got ${t.length}, expected 6`);super(6,{width:i,height:n});for(let a=0;a<ys.SIDES;a++)this.items[a].target=Ji.TEXTURE_CUBE_MAP_POSITIVE_X+a;this.linkBaseTexture=o!==!1,t&&this.initFromArray(t,e),s!==!1&&this.load()}bind(t){super.bind(t),t.target=Ji.TEXTURE_CUBE_MAP}addBaseTextureAt(t,e,i){if(i===void 0&&(i=this.linkBaseTexture),!this.items[e])throw new Error(`Index ${e} is out of bounds`);if(!this.linkBaseTexture||t.parentTextureArray||Object.keys(t._glTextures).length>0)if(t.resource)this.addResourceAt(t.resource,e);else throw new Error("CubeResource does not support copying of renderTexture.");else t.target=Ji.TEXTURE_CUBE_MAP_POSITIVE_X+e,t.parentTextureArray=this.baseTexture,this.items[e]=t;return t.valid&&!this.valid&&this.resize(t.realWidth,t.realHeight),this.items[e]=t,this}upload(t,e,i){const n=this.itemDirtyIds;for(let s=0;s<ys.SIDES;s++){const o=this.items[s];(n[s]<o.dirtyId||i.dirtyId<e.dirtyId)&&(o.valid&&o.resource?(o.resource.upload(t,o,i),n[s]=o.dirtyId):n[s]<-1&&(t.gl.texImage2D(o.target,0,i.internalFormat,e.realWidth,e.realHeight,0,e.format,i.type,null),n[s]=-1))}return!0}static test(t){return Array.isArray(t)&&t.length===ys.SIDES}};Yp.SIDES=6;let IT=Yp;class mn extends Pr{constructor(t,e){e=e||{};let i,n,s;typeof t=="string"?(i=mn.EMPTY,n=t,s=!0):(i=t,n=null,s=!1),super(i),this.url=n,this.crossOrigin=e.crossOrigin??!0,this.alphaMode=typeof e.alphaMode=="number"?e.alphaMode:null,this.ownsImageBitmap=e.ownsImageBitmap??s,this._load=null,e.autoLoad!==!1&&this.load()}load(){return this._load?this._load:(this._load=new Promise(async(t,e)=>{if(this.url===null){t(this);return}try{const i=await tt.ADAPTER.fetch(this.url,{mode:this.crossOrigin?"cors":"no-cors"});if(this.destroyed)return;const n=await i.blob();if(this.destroyed)return;const s=await createImageBitmap(n,{premultiplyAlpha:this.alphaMode===null||this.alphaMode===Le.UNPACK?"premultiply":"none"});if(this.destroyed){s.close();return}this.source=s,this.update(),t(this)}catch(i){if(this.destroyed)return;e(i),this.onError.emit(i)}}),this._load)}upload(t,e,i){return this.source instanceof ImageBitmap?(typeof this.alphaMode=="number"&&(e.alphaMode=this.alphaMode),super.upload(t,e,i)):(this.load(),!1)}dispose(){this.ownsImageBitmap&&this.source instanceof ImageBitmap&&this.source.close(),super.dispose(),this._load=null}static test(t){return!!globalThis.createImageBitmap&&typeof ImageBitmap<"u"&&(typeof t=="string"||t instanceof ImageBitmap)}static get EMPTY(){return mn._EMPTY=mn._EMPTY??tt.ADAPTER.createCanvas(0,0),mn._EMPTY}}const mh=class ta extends Pr{constructor(t,e){e=e||{},super(tt.ADAPTER.createCanvas()),this._width=0,this._height=0,this.svg=t,this.scale=e.scale||1,this._overrideWidth=e.width,this._overrideHeight=e.height,this._resolve=null,this._crossorigin=e.crossorigin,this._load=null,e.autoLoad!==!1&&this.load()}load(){return this._load?this._load:(this._load=new Promise(t=>{if(this._resolve=()=>{this.update(),t(this)},ta.SVG_XML.test(this.svg.trim())){if(!btoa)throw new Error("Your browser doesn't support base64 conversions.");this.svg=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(this.svg)))}`}this._loadSvg()}),this._load)}_loadSvg(){const t=new Image;Pr.crossOrigin(t,this.svg,this._crossorigin),t.src=this.svg,t.onerror=e=>{this._resolve&&(t.onerror=null,this.onError.emit(e))},t.onload=()=>{if(!this._resolve)return;const e=t.width,i=t.height;if(!e||!i)throw new Error("The SVG image must have width and height defined (in pixels), canvas API needs them.");let n=e*this.scale,s=i*this.scale;(this._overrideWidth||this._overrideHeight)&&(n=this._overrideWidth||this._overrideHeight/i*e,s=this._overrideHeight||this._overrideWidth/e*i),n=Math.round(n),s=Math.round(s);const o=this.source;o.width=n,o.height=s,o._pixiId=`canvas_${vi()}`,o.getContext("2d").drawImage(t,0,0,e,i,0,0,n,s),this._resolve(),this._resolve=null}}static getSize(t){const e=ta.SVG_SIZE.exec(t),i={};return e&&(i[e[1]]=Math.round(parseFloat(e[3])),i[e[5]]=Math.round(parseFloat(e[7]))),i}dispose(){super.dispose(),this._resolve=null,this._crossorigin=null}static test(t,e){return e==="svg"||typeof t=="string"&&t.startsWith("data:image/svg+xml")||typeof t=="string"&&ta.SVG_XML.test(t)}};mh.SVG_XML=/^(<\?xml[^?]+\?>)?\s*(<!--[^(-->)]*-->)?\s*\<svg/m,mh.SVG_SIZE=/<svg[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i;let gh=mh;class PT extends Pr{constructor(t){super(t)}static test(t){return!!globalThis.VideoFrame&&t instanceof globalThis.VideoFrame}}const yh=class Kh extends Pr{constructor(t,e){if(e=e||{},!(t instanceof HTMLVideoElement)){const i=document.createElement("video");e.autoLoad!==!1&&i.setAttribute("preload","auto"),e.playsinline!==!1&&(i.setAttribute("webkit-playsinline",""),i.setAttribute("playsinline","")),e.muted===!0&&(i.setAttribute("muted",""),i.muted=!0),e.loop===!0&&i.setAttribute("loop",""),e.autoPlay!==!1&&i.setAttribute("autoplay",""),typeof t=="string"&&(t=[t]);const n=t[0].src||t[0];Pr.crossOrigin(i,n,e.crossorigin);for(let s=0;s<t.length;++s){const o=document.createElement("source");let{src:a,mime:l}=t[s];if(a=a||t[s],a.startsWith("data:"))l=a.slice(5,a.indexOf(";"));else if(!a.startsWith("blob:")){const h=a.split("?").shift().toLowerCase(),c=h.slice(h.lastIndexOf(".")+1);l=l||Kh.MIME_TYPES[c]||`video/${c}`}o.src=a,l&&(o.type=l),i.appendChild(o)}t=i}super(t),this.noSubImage=!0,this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=e.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=e.autoPlay!==!1,this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),e.autoLoad!==!1&&this.load()}update(t=0){if(!this.destroyed){if(this._updateFPS){const e=Fe.shared.elapsedMS*this.source.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!this._updateFPS||this._msToNextUpdate<=0)&&(super.update(),this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0)}}_videoFrameRequestCallback(){this.update(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback)}load(){if(this._load)return this._load;const t=this.source;return(t.readyState===t.HAVE_ENOUGH_DATA||t.readyState===t.HAVE_FUTURE_DATA)&&t.width&&t.height&&(t.complete=!0),t.addEventListener("play",this._onPlayStart),t.addEventListener("pause",this._onPlayStop),t.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._onCanPlay():(t.addEventListener("canplay",this._onCanPlay),t.addEventListener("canplaythrough",this._onCanPlay),t.addEventListener("error",this._onError,!0)),this._load=new Promise((e,i)=>{this.valid?e(this):(this._resolve=e,this._reject=i,t.load())}),this._load}_onError(t){this.source.removeEventListener("error",this._onError,!0),this.onError.emit(t),this._reject&&(this._reject(t),this._reject=null,this._resolve=null)}_isSourcePlaying(){const t=this.source;return!t.paused&&!t.ended}_isSourceReady(){return this.source.readyState>2}_onPlayStart(){this.valid||this._onCanPlay(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0)}_onCanPlay(){const t=this.source;t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay);const e=this.valid;this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0,!e&&this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&t.play()}dispose(){this._configureAutoUpdate();const t=this.source;t&&(t.removeEventListener("play",this._onPlayStart),t.removeEventListener("pause",this._onPlayStop),t.removeEventListener("seeked",this._onSeeked),t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay),t.removeEventListener("error",this._onError,!0),t.pause(),t.src="",t.load()),super.dispose()}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(t){t!==this._updateFPS&&(this._updateFPS=t,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.source.requestVideoFrameCallback?(this._isConnectedToTicker&&(Fe.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),this._videoFrameRequestCallbackHandle===null&&(this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._videoFrameRequestCallbackHandle!==null&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(Fe.shared.add(this.update,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(Fe.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(t,e){return globalThis.HTMLVideoElement&&t instanceof HTMLVideoElement||Kh.TYPES.includes(e)}};yh.TYPES=["mp4","m4v","webm","ogg","ogv","h264","avi","mov"],yh.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let zp=yh;Jl.push(mn,fp,CT,zp,PT,gh,lo,IT,ST);class Po{constructor(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.rect=null,this.updateID=-1}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}clear(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0}getRectangle(t){return this.minX>this.maxX||this.minY>this.maxY?wt.EMPTY:(t=t||new wt(0,0,1,1),t.x=this.minX,t.y=this.minY,t.width=this.maxX-this.minX,t.height=this.maxY-this.minY,t)}addPoint(t){this.minX=Math.min(this.minX,t.x),this.maxX=Math.max(this.maxX,t.x),this.minY=Math.min(this.minY,t.y),this.maxY=Math.max(this.maxY,t.y)}addPointMatrix(t,e){const{a:i,b:n,c:s,d:o,tx:a,ty:l}=t,h=i*e.x+s*e.y+a,c=n*e.x+o*e.y+l;this.minX=Math.min(this.minX,h),this.maxX=Math.max(this.maxX,h),this.minY=Math.min(this.minY,c),this.maxY=Math.max(this.maxY,c)}addQuad(t){let e=this.minX,i=this.minY,n=this.maxX,s=this.maxY,o=t[0],a=t[1];e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,o=t[2],a=t[3],e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,o=t[4],a=t[5],e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,o=t[6],a=t[7],e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,this.minX=e,this.minY=i,this.maxX=n,this.maxY=s}addFrame(t,e,i,n,s){this.addFrameMatrix(t.worldTransform,e,i,n,s)}addFrameMatrix(t,e,i,n,s){const o=t.a,a=t.b,l=t.c,h=t.d,c=t.tx,u=t.ty;let d=this.minX,f=this.minY,p=this.maxX,g=this.maxY,y=o*e+l*i+c,_=a*e+h*i+u;d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,y=o*n+l*i+c,_=a*n+h*i+u,d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,y=o*e+l*s+c,_=a*e+h*s+u,d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,y=o*n+l*s+c,_=a*n+h*s+u,d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,this.minX=d,this.minY=f,this.maxX=p,this.maxY=g}addVertexData(t,e,i){let n=this.minX,s=this.minY,o=this.maxX,a=this.maxY;for(let l=e;l<i;l+=2){const h=t[l],c=t[l+1];n=h<n?h:n,s=c<s?c:s,o=h>o?h:o,a=c>a?c:a}this.minX=n,this.minY=s,this.maxX=o,this.maxY=a}addVertices(t,e,i,n){this.addVerticesMatrix(t.worldTransform,e,i,n)}addVerticesMatrix(t,e,i,n,s=0,o=s){const a=t.a,l=t.b,h=t.c,c=t.d,u=t.tx,d=t.ty;let f=this.minX,p=this.minY,g=this.maxX,y=this.maxY;for(let _=i;_<n;_+=2){const v=e[_],m=e[_+1],x=a*v+h*m+u,S=c*m+l*v+d;f=Math.min(f,x-s),g=Math.max(g,x+s),p=Math.min(p,S-o),y=Math.max(y,S+o)}this.minX=f,this.minY=p,this.maxX=g,this.maxY=y}addBounds(t){const e=this.minX,i=this.minY,n=this.maxX,s=this.maxY;this.minX=t.minX<e?t.minX:e,this.minY=t.minY<i?t.minY:i,this.maxX=t.maxX>n?t.maxX:n,this.maxY=t.maxY>s?t.maxY:s}addBoundsMask(t,e){const i=t.minX>e.minX?t.minX:e.minX,n=t.minY>e.minY?t.minY:e.minY,s=t.maxX<e.maxX?t.maxX:e.maxX,o=t.maxY<e.maxY?t.maxY:e.maxY;if(i<=s&&n<=o){const a=this.minX,l=this.minY,h=this.maxX,c=this.maxY;this.minX=i<a?i:a,this.minY=n<l?n:l,this.maxX=s>h?s:h,this.maxY=o>c?o:c}}addBoundsMatrix(t,e){this.addFrameMatrix(e,t.minX,t.minY,t.maxX,t.maxY)}addBoundsArea(t,e){const i=t.minX>e.x?t.minX:e.x,n=t.minY>e.y?t.minY:e.y,s=t.maxX<e.x+e.width?t.maxX:e.x+e.width,o=t.maxY<e.y+e.height?t.maxY:e.y+e.height;if(i<=s&&n<=o){const a=this.minX,l=this.minY,h=this.maxX,c=this.maxY;this.minX=i<a?i:a,this.minY=n<l?n:l,this.maxX=s>h?s:h,this.maxY=o>c?o:c}}pad(t=0,e=t){this.isEmpty()||(this.minX-=t,this.maxX+=t,this.minY-=e,this.maxY+=e)}addFramePad(t,e,i,n,s,o){t-=s,e-=o,i+=s,n+=o,this.minX=this.minX<t?this.minX:t,this.maxX=this.maxX>i?this.maxX:i,this.minY=this.minY<e?this.minY:e,this.maxY=this.maxY>n?this.maxY:n}}class Xt extends Vn{constructor(){super(),this.tempDisplayObjectParent=null,this.transform=new ih,this.alpha=1,this.visible=!0,this.renderable=!0,this.cullable=!1,this.cullArea=null,this.parent=null,this.worldAlpha=1,this._lastSortedIndex=0,this._zIndex=0,this.filterArea=null,this.filters=null,this._enabledFilters=null,this._bounds=new Po,this._localBounds=null,this._boundsID=0,this._boundsRect=null,this._localBoundsRect=null,this._mask=null,this._maskRefCount=0,this._destroyed=!1,this.isSprite=!1,this.isMask=!1}static mixin(t){const e=Object.keys(t);for(let i=0;i<e.length;++i){const n=e[i];Object.defineProperty(Xt.prototype,n,Object.getOwnPropertyDescriptor(t,n))}}get destroyed(){return this._destroyed}_recursivePostUpdateTransform(){this.parent?(this.parent._recursivePostUpdateTransform(),this.transform.updateTransform(this.parent.transform)):this.transform.updateTransform(this._tempDisplayObjectParent.transform)}updateTransform(){this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha}getBounds(t,e){return t||(this.parent?(this._recursivePostUpdateTransform(),this.updateTransform()):(this.parent=this._tempDisplayObjectParent,this.updateTransform(),this.parent=null)),this._bounds.updateID!==this._boundsID&&(this.calculateBounds(),this._bounds.updateID=this._boundsID),e||(this._boundsRect||(this._boundsRect=new wt),e=this._boundsRect),this._bounds.getRectangle(e)}getLocalBounds(t){t||(this._localBoundsRect||(this._localBoundsRect=new wt),t=this._localBoundsRect),this._localBounds||(this._localBounds=new Po);const e=this.transform,i=this.parent;this.parent=null,this._tempDisplayObjectParent.worldAlpha=(i==null?void 0:i.worldAlpha)??1,this.transform=this._tempDisplayObjectParent.transform;const n=this._bounds,s=this._boundsID;this._bounds=this._localBounds;const o=this.getBounds(!1,t);return this.parent=i,this.transform=e,this._bounds=n,this._bounds.updateID+=this._boundsID-s,o}toGlobal(t,e,i=!1){return i||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.apply(t,e)}toLocal(t,e,i,n){return e&&(t=e.toGlobal(t,i,n)),n||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.applyInverse(t,i)}setParent(t){if(!t||!t.addChild)throw new Error("setParent: Argument must be a Container");return t.addChild(this),t}removeFromParent(){var t;(t=this.parent)==null||t.removeChild(this)}setTransform(t=0,e=0,i=1,n=1,s=0,o=0,a=0,l=0,h=0){return this.position.x=t,this.position.y=e,this.scale.x=i||1,this.scale.y=n||1,this.rotation=s,this.skew.x=o,this.skew.y=a,this.pivot.x=l,this.pivot.y=h,this}destroy(t){this.removeFromParent(),this._destroyed=!0,this.transform=null,this.parent=null,this._bounds=null,this.mask=null,this.cullArea=null,this.filters=null,this.filterArea=null,this.hitArea=null,this.eventMode="auto",this.interactiveChildren=!1,this.emit("destroyed"),this.removeAllListeners()}get _tempDisplayObjectParent(){return this.tempDisplayObjectParent===null&&(this.tempDisplayObjectParent=new RT),this.tempDisplayObjectParent}enableTempParent(){const t=this.parent;return this.parent=this._tempDisplayObjectParent,t}disableTempParent(t){this.parent=t}get x(){return this.position.x}set x(t){this.transform.position.x=t}get y(){return this.position.y}set y(t){this.transform.position.y=t}get worldTransform(){return this.transform.worldTransform}get localTransform(){return this.transform.localTransform}get position(){return this.transform.position}set position(t){this.transform.position.copyFrom(t)}get scale(){return this.transform.scale}set scale(t){this.transform.scale.copyFrom(t)}get pivot(){return this.transform.pivot}set pivot(t){this.transform.pivot.copyFrom(t)}get skew(){return this.transform.skew}set skew(t){this.transform.skew.copyFrom(t)}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angle(){return this.transform.rotation*EE}set angle(t){this.transform.rotation=t*TE}get zIndex(){return this._zIndex}set zIndex(t){this._zIndex!==t&&(this._zIndex=t,this.parent&&(this.parent.sortDirty=!0))}get worldVisible(){let t=this;do{if(!t.visible)return!1;t=t.parent}while(t);return!0}get mask(){return this._mask}set mask(t){if(this._mask!==t){if(this._mask){const e=this._mask.isMaskData?this._mask.maskObject:this._mask;e&&(e._maskRefCount--,e._maskRefCount===0&&(e.renderable=!0,e.isMask=!1))}if(this._mask=t,this._mask){const e=this._mask.isMaskData?this._mask.maskObject:this._mask;e&&(e._maskRefCount===0&&(e.renderable=!1,e.isMask=!0),e._maskRefCount++)}}}}class RT extends Xt{constructor(){super(...arguments),this.sortDirty=null}}Xt.prototype.displayObjectUpdateTransform=Xt.prototype.updateTransform;const MT=new Ft;function OT(r,t){return r.zIndex===t.zIndex?r._lastSortedIndex-t._lastSortedIndex:r.zIndex-t.zIndex}const qp=class Zh extends Xt{constructor(){super(),this.children=[],this.sortableChildren=Zh.defaultSortableChildren,this.sortDirty=!1}onChildrenChange(t){}addChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.addChild(t[e]);else{const e=t[0];e.parent&&e.parent.removeChild(e),e.parent=this,this.sortDirty=!0,e.transform._parentID=-1,this.children.push(e),this._boundsID++,this.onChildrenChange(this.children.length-1),this.emit("childAdded",e,this,this.children.length-1),e.emit("added",this)}return t[0]}addChildAt(t,e){if(e<0||e>this.children.length)throw new Error(`${t}addChildAt: The index ${e} supplied is out of bounds ${this.children.length}`);return t.parent&&t.parent.removeChild(t),t.parent=this,this.sortDirty=!0,t.transform._parentID=-1,this.children.splice(e,0,t),this._boundsID++,this.onChildrenChange(e),t.emit("added",this),this.emit("childAdded",t,this,e),t}swapChildren(t,e){if(t===e)return;const i=this.getChildIndex(t),n=this.getChildIndex(e);this.children[i]=e,this.children[n]=t,this.onChildrenChange(i<n?i:n)}getChildIndex(t){const e=this.children.indexOf(t);if(e===-1)throw new Error("The supplied DisplayObject must be a child of the caller");return e}setChildIndex(t,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);const i=this.getChildIndex(t);dn(this.children,i,1),this.children.splice(e,0,t),this.onChildrenChange(e)}getChildAt(t){if(t<0||t>=this.children.length)throw new Error(`getChildAt: Index (${t}) does not exist.`);return this.children[t]}removeChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.removeChild(t[e]);else{const e=t[0],i=this.children.indexOf(e);if(i===-1)return null;e.parent=null,e.transform._parentID=-1,dn(this.children,i,1),this._boundsID++,this.onChildrenChange(i),e.emit("removed",this),this.emit("childRemoved",e,this,i)}return t[0]}removeChildAt(t){const e=this.getChildAt(t);return e.parent=null,e.transform._parentID=-1,dn(this.children,t,1),this._boundsID++,this.onChildrenChange(t),e.emit("removed",this),this.emit("childRemoved",e,this,t),e}removeChildren(t=0,e=this.children.length){const i=t,n=e,s=n-i;let o;if(s>0&&s<=n){o=this.children.splice(i,s);for(let a=0;a<o.length;++a)o[a].parent=null,o[a].transform&&(o[a].transform._parentID=-1);this._boundsID++,this.onChildrenChange(t);for(let a=0;a<o.length;++a)o[a].emit("removed",this),this.emit("childRemoved",o[a],this,a);return o}else if(s===0&&this.children.length===0)return[];throw new RangeError("removeChildren: numeric values are outside the acceptable range.")}sortChildren(){let t=!1;for(let e=0,i=this.children.length;e<i;++e){const n=this.children[e];n._lastSortedIndex=e,!t&&n.zIndex!==0&&(t=!0)}t&&this.children.length>1&&this.children.sort(OT),this.sortDirty=!1}updateTransform(){this.sortableChildren&&this.sortDirty&&this.sortChildren(),this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha;for(let t=0,e=this.children.length;t<e;++t){const i=this.children[t];i.visible&&i.updateTransform()}}calculateBounds(){this._bounds.clear(),this._calculateBounds();for(let t=0;t<this.children.length;t++){const e=this.children[t];if(!(!e.visible||!e.renderable))if(e.calculateBounds(),e._mask){const i=e._mask.isMaskData?e._mask.maskObject:e._mask;i?(i.calculateBounds(),this._bounds.addBoundsMask(e._bounds,i._bounds)):this._bounds.addBounds(e._bounds)}else e.filterArea?this._bounds.addBoundsArea(e._bounds,e.filterArea):this._bounds.addBounds(e._bounds)}this._bounds.updateID=this._boundsID}getLocalBounds(t,e=!1){const i=super.getLocalBounds(t);if(!e)for(let n=0,s=this.children.length;n<s;++n){const o=this.children[n];o.visible&&o.updateTransform()}return i}_calculateBounds(){}_renderWithCulling(t){const e=t.renderTexture.sourceFrame;if(!(e.width>0&&e.height>0))return;let i,n;this.cullArea?(i=this.cullArea,n=this.worldTransform):this._render!==Zh.prototype._render&&(i=this.getBounds(!0));const s=t.projection.transform;if(s&&(n?(n=MT.copyFrom(n),n.prepend(s)):n=s),i&&e.intersects(i,n))this._render(t);else if(this.cullArea)return;for(let o=0,a=this.children.length;o<a;++o){const l=this.children[o],h=l.cullable;l.cullable=h||!this.cullArea,l.render(t),l.cullable=h}}render(t){var e;if(!(!this.visible||this.worldAlpha<=0||!this.renderable))if(this._mask||(e=this.filters)!=null&&e.length)this.renderAdvanced(t);else if(this.cullable)this._renderWithCulling(t);else{this._render(t);for(let i=0,n=this.children.length;i<n;++i)this.children[i].render(t)}}renderAdvanced(t){var s,o,a;const e=this.filters,i=this._mask;if(e){this._enabledFilters||(this._enabledFilters=[]),this._enabledFilters.length=0;for(let l=0;l<e.length;l++)e[l].enabled&&this._enabledFilters.push(e[l])}const n=e&&((s=this._enabledFilters)==null?void 0:s.length)||i&&(!i.isMaskData||i.enabled&&(i.autoDetect||i.type!==ie.NONE));if(n&&t.batch.flush(),e&&((o=this._enabledFilters)!=null&&o.length)&&t.filter.push(this,this._enabledFilters),i&&t.mask.push(this,this._mask),this.cullable)this._renderWithCulling(t);else{this._render(t);for(let l=0,h=this.children.length;l<h;++l)this.children[l].render(t)}n&&t.batch.flush(),i&&t.mask.pop(this),e&&((a=this._enabledFilters)!=null&&a.length)&&t.filter.pop()}_render(t){}destroy(t){super.destroy(),this.sortDirty=!1;const e=typeof t=="boolean"?t:t==null?void 0:t.children,i=this.removeChildren(0,this.children.length);if(e)for(let n=0;n<i.length;++n)i[n].destroy(t)}get width(){return this.scale.x*this.getLocalBounds().width}set width(t){const e=this.getLocalBounds().width;e!==0?this.scale.x=t/e:this.scale.x=1,this._width=t}get height(){return this.scale.y*this.getLocalBounds().height}set height(t){const e=this.getLocalBounds().height;e!==0?this.scale.y=t/e:this.scale.y=1,this._height=t}};qp.defaultSortableChildren=!1;let Ze=qp;Ze.prototype.containerUpdateTransform=Ze.prototype.updateTransform,Object.defineProperties(tt,{SORTABLE_CHILDREN:{get(){return Ze.defaultSortableChildren},set(r){St("7.1.0","settings.SORTABLE_CHILDREN is deprecated, use Container.defaultSortableChildren"),Ze.defaultSortableChildren=r}}});const us=new It,BT=new Uint16Array([0,1,2,0,2,3]);class gn extends Ze{constructor(t){super(),this._anchor=new Cr(this._onAnchorUpdate,this,t?t.defaultAnchor.x:0,t?t.defaultAnchor.y:0),this._texture=null,this._width=0,this._height=0,this._tintColor=new Mt(16777215),this._tintRGB=null,this.tint=16777215,this.blendMode=vt.NORMAL,this._cachedTint=16777215,this.uvs=null,this.texture=t||dt.EMPTY,this.vertexData=new Float32Array(8),this.vertexTrimmedData=null,this._transformID=-1,this._textureID=-1,this._transformTrimmedID=-1,this._textureTrimmedID=-1,this.indices=BT,this.pluginName="batch",this.isSprite=!0,this._roundPixels=tt.ROUND_PIXELS}_onTextureUpdate(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=zr(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=zr(this.scale.y)*this._height/this._texture.orig.height)}_onAnchorUpdate(){this._transformID=-1,this._transformTrimmedID=-1}calculateVertices(){const t=this._texture;if(this._transformID===this.transform._worldID&&this._textureID===t._updateID)return;this._textureID!==t._updateID&&(this.uvs=this._texture._uvs.uvsFloat32),this._transformID=this.transform._worldID,this._textureID=t._updateID;const e=this.transform.worldTransform,i=e.a,n=e.b,s=e.c,o=e.d,a=e.tx,l=e.ty,h=this.vertexData,c=t.trim,u=t.orig,d=this._anchor;let f=0,p=0,g=0,y=0;if(c?(p=c.x-d._x*u.width,f=p+c.width,y=c.y-d._y*u.height,g=y+c.height):(p=-d._x*u.width,f=p+u.width,y=-d._y*u.height,g=y+u.height),h[0]=i*p+s*y+a,h[1]=o*y+n*p+l,h[2]=i*f+s*y+a,h[3]=o*y+n*f+l,h[4]=i*f+s*g+a,h[5]=o*g+n*f+l,h[6]=i*p+s*g+a,h[7]=o*g+n*p+l,this._roundPixels){const _=tt.RESOLUTION;for(let v=0;v<h.length;++v)h[v]=Math.round(h[v]*_)/_}}calculateTrimmedVertices(){if(!this.vertexTrimmedData)this.vertexTrimmedData=new Float32Array(8);else if(this._transformTrimmedID===this.transform._worldID&&this._textureTrimmedID===this._texture._updateID)return;this._transformTrimmedID=this.transform._worldID,this._textureTrimmedID=this._texture._updateID;const t=this._texture,e=this.vertexTrimmedData,i=t.orig,n=this._anchor,s=this.transform.worldTransform,o=s.a,a=s.b,l=s.c,h=s.d,c=s.tx,u=s.ty,d=-n._x*i.width,f=d+i.width,p=-n._y*i.height,g=p+i.height;if(e[0]=o*d+l*p+c,e[1]=h*p+a*d+u,e[2]=o*f+l*p+c,e[3]=h*p+a*f+u,e[4]=o*f+l*g+c,e[5]=h*g+a*f+u,e[6]=o*d+l*g+c,e[7]=h*g+a*d+u,this._roundPixels){const y=tt.RESOLUTION;for(let _=0;_<e.length;++_)e[_]=Math.round(e[_]*y)/y}}_render(t){this.calculateVertices(),t.batch.setObjectRenderer(t.plugins[this.pluginName]),t.plugins[this.pluginName].render(this)}_calculateBounds(){const t=this._texture.trim,e=this._texture.orig;!t||t.width===e.width&&t.height===e.height?(this.calculateVertices(),this._bounds.addQuad(this.vertexData)):(this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData))}getLocalBounds(t){return this.children.length===0?(this._localBounds||(this._localBounds=new Po),this._localBounds.minX=this._texture.orig.width*-this._anchor._x,this._localBounds.minY=this._texture.orig.height*-this._anchor._y,this._localBounds.maxX=this._texture.orig.width*(1-this._anchor._x),this._localBounds.maxY=this._texture.orig.height*(1-this._anchor._y),t||(this._localBoundsRect||(this._localBoundsRect=new wt),t=this._localBoundsRect),this._localBounds.getRectangle(t)):super.getLocalBounds.call(this,t)}containsPoint(t){this.worldTransform.applyInverse(t,us);const e=this._texture.orig.width,i=this._texture.orig.height,n=-e*this.anchor.x;let s=0;return us.x>=n&&us.x<n+e&&(s=-i*this.anchor.y,us.y>=s&&us.y<s+i)}destroy(t){if(super.destroy(t),this._texture.off("update",this._onTextureUpdate,this),this._anchor=null,typeof t=="boolean"?t:t==null?void 0:t.texture){const e=typeof t=="boolean"?t:t==null?void 0:t.baseTexture;this._texture.destroy(!!e)}this._texture=null}static from(t,e){const i=t instanceof dt?t:dt.from(t,e);return new gn(i)}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1,this._transformTrimmedID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(t){const e=zr(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(t){const e=zr(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get anchor(){return this._anchor}set anchor(t){this._anchor.copyFrom(t)}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t),this._tintRGB=this._tintColor.toLittleEndianNumber()}get tintValue(){return this._tintColor.toNumber()}get texture(){return this._texture}set texture(t){this._texture!==t&&(this._texture&&this._texture.off("update",this._onTextureUpdate,this),this._texture=t||dt.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,t&&(t.baseTexture.valid?this._onTextureUpdate():t.once("update",this._onTextureUpdate,this)))}}const Kp=new Ft;Xt.prototype._cacheAsBitmap=!1,Xt.prototype._cacheData=null,Xt.prototype._cacheAsBitmapResolution=null,Xt.prototype._cacheAsBitmapMultisample=null;class LT{constructor(){this.textureCacheId=null,this.originalRender=null,this.originalRenderCanvas=null,this.originalCalculateBounds=null,this.originalGetLocalBounds=null,this.originalUpdateTransform=null,this.originalDestroy=null,this.originalMask=null,this.originalFilterArea=null,this.originalContainsPoint=null,this.sprite=null}}Object.defineProperties(Xt.prototype,{cacheAsBitmapResolution:{get(){return this._cacheAsBitmapResolution},set(r){r!==this._cacheAsBitmapResolution&&(this._cacheAsBitmapResolution=r,this.cacheAsBitmap&&(this.cacheAsBitmap=!1,this.cacheAsBitmap=!0))}},cacheAsBitmapMultisample:{get(){return this._cacheAsBitmapMultisample},set(r){r!==this._cacheAsBitmapMultisample&&(this._cacheAsBitmapMultisample=r,this.cacheAsBitmap&&(this.cacheAsBitmap=!1,this.cacheAsBitmap=!0))}},cacheAsBitmap:{get(){return this._cacheAsBitmap},set(r){if(this._cacheAsBitmap===r)return;this._cacheAsBitmap=r;let t;r?(this._cacheData||(this._cacheData=new LT),t=this._cacheData,t.originalRender=this.render,t.originalRenderCanvas=this.renderCanvas,t.originalUpdateTransform=this.updateTransform,t.originalCalculateBounds=this.calculateBounds,t.originalGetLocalBounds=this.getLocalBounds,t.originalDestroy=this.destroy,t.originalContainsPoint=this.containsPoint,t.originalMask=this._mask,t.originalFilterArea=this.filterArea,this.render=this._renderCached,this.renderCanvas=this._renderCachedCanvas,this.destroy=this._cacheAsBitmapDestroy):(t=this._cacheData,t.sprite&&this._destroyCachedDisplayObject(),this.render=t.originalRender,this.renderCanvas=t.originalRenderCanvas,this.calculateBounds=t.originalCalculateBounds,this.getLocalBounds=t.originalGetLocalBounds,this.destroy=t.originalDestroy,this.updateTransform=t.originalUpdateTransform,this.containsPoint=t.originalContainsPoint,this._mask=t.originalMask,this.filterArea=t.originalFilterArea)}}}),Xt.prototype._renderCached=function(r){!this.visible||this.worldAlpha<=0||!this.renderable||(this._initCachedDisplayObject(r),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite.worldAlpha=this.worldAlpha,this._cacheData.sprite._render(r))},Xt.prototype._initCachedDisplayObject=function(r){var d,f;if((d=this._cacheData)!=null&&d.sprite)return;const t=this.alpha;this.alpha=1,r.batch.flush();const e=this.getLocalBounds(new wt,!0);if((f=this.filters)!=null&&f.length){const p=this.filters[0].padding;e.pad(p)}const i=this.cacheAsBitmapResolution||r.resolution;e.ceil(i),e.width=Math.max(e.width,1/i),e.height=Math.max(e.height,1/i);const n=r.renderTexture.current,s=r.renderTexture.sourceFrame.clone(),o=r.renderTexture.destinationFrame.clone(),a=r.projection.transform,l=Si.create({width:e.width,height:e.height,resolution:i,multisample:this.cacheAsBitmapMultisample??r.multisample}),h=`cacheAsBitmap_${vi()}`;this._cacheData.textureCacheId=h,xt.addToCache(l.baseTexture,h),dt.addToCache(l,h);const c=this.transform.localTransform.copyTo(Kp).invert().translate(-e.x,-e.y);this.render=this._cacheData.originalRender,r.render(this,{renderTexture:l,clear:!0,transform:c,skipUpdateTransform:!1}),r.framebuffer.blit(),r.projection.transform=a,r.renderTexture.bind(n,s,o),this.render=this._renderCached,this.updateTransform=this.displayObjectUpdateTransform,this.calculateBounds=this._calculateCachedBounds,this.getLocalBounds=this._getCachedLocalBounds,this._mask=null,this.filterArea=null,this.alpha=t;const u=new gn(l);u.transform.worldTransform=this.transform.worldTransform,u.anchor.x=-(e.x/e.width),u.anchor.y=-(e.y/e.height),u.alpha=t,u._bounds=this._bounds,this._cacheData.sprite=u,this.transform._parentID=-1,this.parent?this.updateTransform():(this.enableTempParent(),this.updateTransform(),this.disableTempParent(null)),this.containsPoint=u.containsPoint.bind(u)},Xt.prototype._renderCachedCanvas=function(r){!this.visible||this.worldAlpha<=0||!this.renderable||(this._initCachedDisplayObjectCanvas(r),this._cacheData.sprite.worldAlpha=this.worldAlpha,this._cacheData.sprite._renderCanvas(r))},Xt.prototype._initCachedDisplayObjectCanvas=function(r){var c;if((c=this._cacheData)!=null&&c.sprite)return;const t=this.getLocalBounds(new wt,!0),e=this.alpha;this.alpha=1;const i=r.canvasContext.activeContext,n=r._projTransform,s=this.cacheAsBitmapResolution||r.resolution;t.ceil(s),t.width=Math.max(t.width,1/s),t.height=Math.max(t.height,1/s);const o=Si.create({width:t.width,height:t.height,resolution:s}),a=`cacheAsBitmap_${vi()}`;this._cacheData.textureCacheId=a,xt.addToCache(o.baseTexture,a),dt.addToCache(o,a);const l=Kp;this.transform.localTransform.copyTo(l),l.invert(),l.tx-=t.x,l.ty-=t.y,this.renderCanvas=this._cacheData.originalRenderCanvas,r.render(this,{renderTexture:o,clear:!0,transform:l,skipUpdateTransform:!1}),r.canvasContext.activeContext=i,r._projTransform=n,this.renderCanvas=this._renderCachedCanvas,this.updateTransform=this.displayObjectUpdateTransform,this.calculateBounds=this._calculateCachedBounds,this.getLocalBounds=this._getCachedLocalBounds,this._mask=null,this.filterArea=null,this.alpha=e;const h=new gn(o);h.transform.worldTransform=this.transform.worldTransform,h.anchor.x=-(t.x/t.width),h.anchor.y=-(t.y/t.height),h.alpha=e,h._bounds=this._bounds,this._cacheData.sprite=h,this.transform._parentID=-1,this.parent?this.updateTransform():(this.parent=r._tempDisplayObjectParent,this.updateTransform(),this.parent=null),this.containsPoint=h.containsPoint.bind(h)},Xt.prototype._calculateCachedBounds=function(){this._bounds.clear(),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite._calculateBounds(),this._bounds.updateID=this._boundsID},Xt.prototype._getCachedLocalBounds=function(){return this._cacheData.sprite.getLocalBounds(null)},Xt.prototype._destroyCachedDisplayObject=function(){this._cacheData.sprite._texture.destroy(!0),this._cacheData.sprite=null,xt.removeFromCache(this._cacheData.textureCacheId),dt.removeFromCache(this._cacheData.textureCacheId),this._cacheData.textureCacheId=null},Xt.prototype._cacheAsBitmapDestroy=function(r){this.cacheAsBitmap=!1,this.destroy(r)},Xt.prototype.name=null,Ze.prototype.getChildByName=function(r,t){for(let e=0,i=this.children.length;e<i;e++)if(this.children[e].name===r)return this.children[e];if(t)for(let e=0,i=this.children.length;e<i;e++){const n=this.children[e];if(!n.getChildByName)continue;const s=n.getChildByName(r,!0);if(s)return s}return null},Xt.prototype.getGlobalPosition=function(r=new It,t=!1){return this.parent?this.parent.toGlobal(this.position,r,t):(r.x=this.position.x,r.y=this.position.y),r};var DT=`varying vec2 vTextureCoord;
526
+ `;const TT=wT,Hp=ET;class Vp{constructor(t){this.renderer=t}contextChange(t){let e;if(this.renderer.context.webGLVersion===1){const i=t.getParameter(t.FRAMEBUFFER_BINDING);t.bindFramebuffer(t.FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.FRAMEBUFFER,i)}else{const i=t.getParameter(t.DRAW_FRAMEBUFFER_BINDING);t.bindFramebuffer(t.DRAW_FRAMEBUFFER,null),e=t.getParameter(t.SAMPLES),t.bindFramebuffer(t.DRAW_FRAMEBUFFER,i)}e>=re.HIGH?this.multisample=re.HIGH:e>=re.MEDIUM?this.multisample=re.MEDIUM:e>=re.LOW?this.multisample=re.LOW:this.multisample=re.NONE}destroy(){}}Vp.extension={type:K.RendererSystem,name:"_multisample"},ut.add(Vp);class AT{constructor(t){this.buffer=t||null,this.updateID=-1,this.byteLength=-1,this.refCount=0}}class Xp{constructor(t){this.renderer=t,this.managedBuffers={},this.boundBufferBases={}}destroy(){this.renderer=null}contextChange(){this.disposeAll(!0),this.gl=this.renderer.gl,this.CONTEXT_UID=this.renderer.CONTEXT_UID}bind(t){const{gl:e,CONTEXT_UID:i}=this,n=t._glBuffers[i]||this.createGLBuffer(t);e.bindBuffer(t.type,n.buffer)}unbind(t){const{gl:e}=this;e.bindBuffer(t,null)}bindBufferBase(t,e){const{gl:i,CONTEXT_UID:n}=this;if(this.boundBufferBases[e]!==t){const s=t._glBuffers[n]||this.createGLBuffer(t);this.boundBufferBases[e]=t,i.bindBufferBase(i.UNIFORM_BUFFER,e,s.buffer)}}bindBufferRange(t,e,i){const{gl:n,CONTEXT_UID:s}=this;i=i||0;const o=t._glBuffers[s]||this.createGLBuffer(t);n.bindBufferRange(n.UNIFORM_BUFFER,e||0,o.buffer,i*256,256)}update(t){const{gl:e,CONTEXT_UID:i}=this,n=t._glBuffers[i]||this.createGLBuffer(t);if(t._updateID!==n.updateID)if(n.updateID=t._updateID,e.bindBuffer(t.type,n.buffer),n.byteLength>=t.data.byteLength)e.bufferSubData(t.type,0,t.data);else{const s=t.static?e.STATIC_DRAW:e.DYNAMIC_DRAW;n.byteLength=t.data.byteLength,e.bufferData(t.type,t.data,s)}}dispose(t,e){if(!this.managedBuffers[t.id])return;delete this.managedBuffers[t.id];const i=t._glBuffers[this.CONTEXT_UID],n=this.gl;t.disposeRunner.remove(this),i&&(e||n.deleteBuffer(i.buffer),delete t._glBuffers[this.CONTEXT_UID])}disposeAll(t){const e=Object.keys(this.managedBuffers);for(let i=0;i<e.length;i++)this.dispose(this.managedBuffers[e[i]],t)}createGLBuffer(t){const{CONTEXT_UID:e,gl:i}=this;return t._glBuffers[e]=new AT(i.createBuffer()),this.managedBuffers[t.id]=t,t.disposeRunner.add(this),t._glBuffers[e]}}Xp.extension={type:K.RendererSystem,name:"buffer"},ut.add(Xp);class jp{constructor(t){this.renderer=t}render(t,e){const i=this.renderer;let n,s,o,a;if(e&&(n=e.renderTexture,s=e.clear,o=e.transform,a=e.skipUpdateTransform),this.renderingToScreen=!n,i.runners.prerender.emit(),i.emit("prerender"),i.projection.transform=o,!i.context.isLost){if(n||(this.lastObjectRendered=t),!a){const l=t.enableTempParent();t.updateTransform(),t.disableTempParent(l)}i.renderTexture.bind(n),i.batch.currentRenderer.start(),(s??i.background.clearBeforeRender)&&i.renderTexture.clear(),t.render(i),i.batch.currentRenderer.flush(),n&&(e.blit&&i.framebuffer.blit(),n.baseTexture.update()),i.runners.postrender.emit(),i.projection.transform=null,i.emit("postrender")}}destroy(){this.renderer=null,this.lastObjectRendered=null}}jp.extension={type:K.RendererSystem,name:"objectRenderer"},ut.add(jp);const Io=class qh extends vT{constructor(t){super(),this.type=fd.WEBGL,t=Object.assign({},tt.RENDER_OPTIONS,t),this.gl=null,this.CONTEXT_UID=0,this.globalUniforms=new Ke({projectionMatrix:new Ft},!0);const e={runners:["init","destroy","contextChange","resolutionChange","reset","update","postrender","prerender","resize"],systems:qh.__systems,priority:["_view","textureGenerator","background","_plugin","startup","context","state","texture","buffer","geometry","framebuffer","transformFeedback","mask","scissor","stencil","projection","textureGC","filter","renderTexture","batch","objectRenderer","_multisample"]};this.setup(e),"useContextAlpha"in t&&(St("7.0.0","options.useContextAlpha is deprecated, use options.premultipliedAlpha and options.backgroundAlpha instead"),t.premultipliedAlpha=t.useContextAlpha&&t.useContextAlpha!=="notMultiplied",t.backgroundAlpha=t.useContextAlpha===!1?1:t.backgroundAlpha),this._plugin.rendererPlugins=qh.__plugins,this.options=t,this.startup.run(this.options)}static test(t){return t!=null&&t.forceCanvas?!1:qw()}render(t,e){this.objectRenderer.render(t,e)}resize(t,e){this._view.resizeView(t,e)}reset(){return this.runners.reset.emit(),this}clear(){this.renderTexture.bind(),this.renderTexture.clear()}destroy(t=!1){this.runners.destroy.items.reverse(),this.emitWithCustomOptions(this.runners.destroy,{_view:t}),super.destroy()}get plugins(){return this._plugin.plugins}get multisample(){return this._multisample.multisample}get width(){return this._view.element.width}get height(){return this._view.element.height}get resolution(){return this._view.resolution}set resolution(t){this._view.resolution=t,this.runners.resolutionChange.emit(t)}get autoDensity(){return this._view.autoDensity}get view(){return this._view.element}get screen(){return this._view.screen}get lastObjectRendered(){return this.objectRenderer.lastObjectRendered}get renderingToScreen(){return this.objectRenderer.renderingToScreen}get rendererLogId(){return`WebGL ${this.context.webGLVersion}`}get clearBeforeRender(){return St("7.0.0","renderer.clearBeforeRender has been deprecated, please use renderer.background.clearBeforeRender instead."),this.background.clearBeforeRender}get useContextAlpha(){return St("7.0.0","renderer.useContextAlpha has been deprecated, please use renderer.context.premultipliedAlpha instead."),this.context.useContextAlpha}get preserveDrawingBuffer(){return St("7.0.0","renderer.preserveDrawingBuffer has been deprecated, we cannot truly know this unless pixi created the context"),this.context.preserveDrawingBuffer}get backgroundColor(){return St("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color}set backgroundColor(t){St("7.0.0","renderer.backgroundColor has been deprecated, use renderer.background.color instead."),this.background.color=t}get backgroundAlpha(){return St("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha}set backgroundAlpha(t){St("7.0.0","renderer.backgroundAlpha has been deprecated, use renderer.background.alpha instead."),this.background.alpha=t}get powerPreference(){return St("7.0.0","renderer.powerPreference has been deprecated, we can only know this if pixi creates the context"),this.context.powerPreference}generateTexture(t,e){return this.textureGenerator.generateTexture(t,e)}};Io.extension={type:K.Renderer,priority:1},Io.__plugins={},Io.__systems={};let ph=Io;ut.handleByMap(K.RendererPlugin,ph.__plugins),ut.handleByMap(K.RendererSystem,ph.__systems),ut.add(ph);class Wp extends os{constructor(t,e){const{width:i,height:n}=e||{};super(i,n),this.items=[],this.itemDirtyIds=[];for(let s=0;s<t;s++){const o=new xt;this.items.push(o),this.itemDirtyIds.push(-2)}this.length=t,this._load=null,this.baseTexture=null}initFromArray(t,e){for(let i=0;i<this.length;i++)t[i]&&(t[i].castToBaseTexture?this.addBaseTextureAt(t[i].castToBaseTexture(),i):t[i]instanceof os?this.addResourceAt(t[i],i):this.addResourceAt(Jf(t[i],e),i))}dispose(){for(let t=0,e=this.length;t<e;t++)this.items[t].destroy();this.items=null,this.itemDirtyIds=null,this._load=null}addResourceAt(t,e){if(!this.items[e])throw new Error(`Index ${e} is out of bounds`);return t.valid&&!this.valid&&this.resize(t.width,t.height),this.items[e].setResource(t),this}bind(t){if(this.baseTexture!==null)throw new Error("Only one base texture per TextureArray is allowed");super.bind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=t,this.items[e].on("update",t.update,t)}unbind(t){super.unbind(t);for(let e=0;e<this.length;e++)this.items[e].parentTextureArray=null,this.items[e].off("update",t.update,t)}load(){if(this._load)return this._load;const t=this.items.map(e=>e.resource).filter(e=>e).map(e=>e.load());return this._load=Promise.all(t).then(()=>{const{realWidth:e,realHeight:i}=this.items[0];return this.resize(e,i),this.update(),Promise.resolve(this)}),this._load}}class ST extends Wp{constructor(t,e){const{width:i,height:n}=e||{};let s,o;Array.isArray(t)?(s=t,o=t.length):o=t,super(o,{width:i,height:n}),s&&this.initFromArray(s,e)}addBaseTextureAt(t,e){if(t.resource)this.addResourceAt(t.resource,e);else throw new Error("ArrayResource does not support RenderTexture");return this}bind(t){super.bind(t),t.target=Ji.TEXTURE_2D_ARRAY}upload(t,e,i){const{length:n,itemDirtyIds:s,items:o}=this,{gl:a}=t;i.dirtyId<0&&a.texImage3D(a.TEXTURE_2D_ARRAY,0,i.internalFormat,this._width,this._height,n,0,e.format,i.type,null);for(let l=0;l<n;l++){const h=o[l];s[l]<h.dirtyId&&(s[l]=h.dirtyId,h.valid&&a.texSubImage3D(a.TEXTURE_2D_ARRAY,0,0,0,l,h.resource.width,h.resource.height,1,e.format,i.type,h.resource.source))}return!0}}class CT extends Pr{constructor(t){super(t)}static test(t){const{OffscreenCanvas:e}=globalThis;return e&&t instanceof e?!0:globalThis.HTMLCanvasElement&&t instanceof HTMLCanvasElement}}const Yp=class ys extends Wp{constructor(t,e){const{width:i,height:n,autoLoad:s,linkBaseTexture:o}=e||{};if(t&&t.length!==ys.SIDES)throw new Error(`Invalid length. Got ${t.length}, expected 6`);super(6,{width:i,height:n});for(let a=0;a<ys.SIDES;a++)this.items[a].target=Ji.TEXTURE_CUBE_MAP_POSITIVE_X+a;this.linkBaseTexture=o!==!1,t&&this.initFromArray(t,e),s!==!1&&this.load()}bind(t){super.bind(t),t.target=Ji.TEXTURE_CUBE_MAP}addBaseTextureAt(t,e,i){if(i===void 0&&(i=this.linkBaseTexture),!this.items[e])throw new Error(`Index ${e} is out of bounds`);if(!this.linkBaseTexture||t.parentTextureArray||Object.keys(t._glTextures).length>0)if(t.resource)this.addResourceAt(t.resource,e);else throw new Error("CubeResource does not support copying of renderTexture.");else t.target=Ji.TEXTURE_CUBE_MAP_POSITIVE_X+e,t.parentTextureArray=this.baseTexture,this.items[e]=t;return t.valid&&!this.valid&&this.resize(t.realWidth,t.realHeight),this.items[e]=t,this}upload(t,e,i){const n=this.itemDirtyIds;for(let s=0;s<ys.SIDES;s++){const o=this.items[s];(n[s]<o.dirtyId||i.dirtyId<e.dirtyId)&&(o.valid&&o.resource?(o.resource.upload(t,o,i),n[s]=o.dirtyId):n[s]<-1&&(t.gl.texImage2D(o.target,0,i.internalFormat,e.realWidth,e.realHeight,0,e.format,i.type,null),n[s]=-1))}return!0}static test(t){return Array.isArray(t)&&t.length===ys.SIDES}};Yp.SIDES=6;let IT=Yp;class mn extends Pr{constructor(t,e){e=e||{};let i,n,s;typeof t=="string"?(i=mn.EMPTY,n=t,s=!0):(i=t,n=null,s=!1),super(i),this.url=n,this.crossOrigin=e.crossOrigin??!0,this.alphaMode=typeof e.alphaMode=="number"?e.alphaMode:null,this.ownsImageBitmap=e.ownsImageBitmap??s,this._load=null,e.autoLoad!==!1&&this.load()}load(){return this._load?this._load:(this._load=new Promise(async(t,e)=>{if(this.url===null){t(this);return}try{const i=await tt.ADAPTER.fetch(this.url,{mode:this.crossOrigin?"cors":"no-cors"});if(this.destroyed)return;const n=await i.blob();if(this.destroyed)return;const s=await createImageBitmap(n,{premultiplyAlpha:this.alphaMode===null||this.alphaMode===Le.UNPACK?"premultiply":"none"});if(this.destroyed){s.close();return}this.source=s,this.update(),t(this)}catch(i){if(this.destroyed)return;e(i),this.onError.emit(i)}}),this._load)}upload(t,e,i){return this.source instanceof ImageBitmap?(typeof this.alphaMode=="number"&&(e.alphaMode=this.alphaMode),super.upload(t,e,i)):(this.load(),!1)}dispose(){this.ownsImageBitmap&&this.source instanceof ImageBitmap&&this.source.close(),super.dispose(),this._load=null}static test(t){return!!globalThis.createImageBitmap&&typeof ImageBitmap<"u"&&(typeof t=="string"||t instanceof ImageBitmap)}static get EMPTY(){return mn._EMPTY=mn._EMPTY??tt.ADAPTER.createCanvas(0,0),mn._EMPTY}}const mh=class ta extends Pr{constructor(t,e){e=e||{},super(tt.ADAPTER.createCanvas()),this._width=0,this._height=0,this.svg=t,this.scale=e.scale||1,this._overrideWidth=e.width,this._overrideHeight=e.height,this._resolve=null,this._crossorigin=e.crossorigin,this._load=null,e.autoLoad!==!1&&this.load()}load(){return this._load?this._load:(this._load=new Promise(t=>{if(this._resolve=()=>{this.update(),t(this)},ta.SVG_XML.test(this.svg.trim())){if(!btoa)throw new Error("Your browser doesn't support base64 conversions.");this.svg=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(this.svg)))}`}this._loadSvg()}),this._load)}_loadSvg(){const t=new Image;Pr.crossOrigin(t,this.svg,this._crossorigin),t.src=this.svg,t.onerror=e=>{this._resolve&&(t.onerror=null,this.onError.emit(e))},t.onload=()=>{if(!this._resolve)return;const e=t.width,i=t.height;if(!e||!i)throw new Error("The SVG image must have width and height defined (in pixels), canvas API needs them.");let n=e*this.scale,s=i*this.scale;(this._overrideWidth||this._overrideHeight)&&(n=this._overrideWidth||this._overrideHeight/i*e,s=this._overrideHeight||this._overrideWidth/e*i),n=Math.round(n),s=Math.round(s);const o=this.source;o.width=n,o.height=s,o._pixiId=`canvas_${vi()}`,o.getContext("2d").drawImage(t,0,0,e,i,0,0,n,s),this._resolve(),this._resolve=null}}static getSize(t){const e=ta.SVG_SIZE.exec(t),i={};return e&&(i[e[1]]=Math.round(parseFloat(e[3])),i[e[5]]=Math.round(parseFloat(e[7]))),i}dispose(){super.dispose(),this._resolve=null,this._crossorigin=null}static test(t,e){return e==="svg"||typeof t=="string"&&t.startsWith("data:image/svg+xml")||typeof t=="string"&&ta.SVG_XML.test(t)}};mh.SVG_XML=/^(<\?xml[^?]+\?>)?\s*(<!--[^(-->)]*-->)?\s*\<svg/m,mh.SVG_SIZE=/<svg[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*(?:\s(width|height)=('|")(\d*(?:\.\d+)?)(?:px)?('|"))[^>]*>/i;let gh=mh;class PT extends Pr{constructor(t){super(t)}static test(t){return!!globalThis.VideoFrame&&t instanceof globalThis.VideoFrame}}const yh=class Kh extends Pr{constructor(t,e){if(e=e||{},!(t instanceof HTMLVideoElement)){const i=document.createElement("video");e.autoLoad!==!1&&i.setAttribute("preload","auto"),e.playsinline!==!1&&(i.setAttribute("webkit-playsinline",""),i.setAttribute("playsinline","")),e.muted===!0&&(i.setAttribute("muted",""),i.muted=!0),e.loop===!0&&i.setAttribute("loop",""),e.autoPlay!==!1&&i.setAttribute("autoplay",""),typeof t=="string"&&(t=[t]);const n=t[0].src||t[0];Pr.crossOrigin(i,n,e.crossorigin);for(let s=0;s<t.length;++s){const o=document.createElement("source");let{src:a,mime:l}=t[s];if(a=a||t[s],a.startsWith("data:"))l=a.slice(5,a.indexOf(";"));else if(!a.startsWith("blob:")){const h=a.split("?").shift().toLowerCase(),c=h.slice(h.lastIndexOf(".")+1);l=l||Kh.MIME_TYPES[c]||`video/${c}`}o.src=a,l&&(o.type=l),i.appendChild(o)}t=i}super(t),this.noSubImage=!0,this._autoUpdate=!0,this._isConnectedToTicker=!1,this._updateFPS=e.updateFPS||0,this._msToNextUpdate=0,this.autoPlay=e.autoPlay!==!1,this._videoFrameRequestCallback=this._videoFrameRequestCallback.bind(this),this._videoFrameRequestCallbackHandle=null,this._load=null,this._resolve=null,this._reject=null,this._onCanPlay=this._onCanPlay.bind(this),this._onError=this._onError.bind(this),this._onPlayStart=this._onPlayStart.bind(this),this._onPlayStop=this._onPlayStop.bind(this),this._onSeeked=this._onSeeked.bind(this),e.autoLoad!==!1&&this.load()}update(t=0){if(!this.destroyed){if(this._updateFPS){const e=ke.shared.elapsedMS*this.source.playbackRate;this._msToNextUpdate=Math.floor(this._msToNextUpdate-e)}(!this._updateFPS||this._msToNextUpdate<=0)&&(super.update(),this._msToNextUpdate=this._updateFPS?Math.floor(1e3/this._updateFPS):0)}}_videoFrameRequestCallback(){this.update(),this.destroyed?this._videoFrameRequestCallbackHandle=null:this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback)}load(){if(this._load)return this._load;const t=this.source;return(t.readyState===t.HAVE_ENOUGH_DATA||t.readyState===t.HAVE_FUTURE_DATA)&&t.width&&t.height&&(t.complete=!0),t.addEventListener("play",this._onPlayStart),t.addEventListener("pause",this._onPlayStop),t.addEventListener("seeked",this._onSeeked),this._isSourceReady()?this._onCanPlay():(t.addEventListener("canplay",this._onCanPlay),t.addEventListener("canplaythrough",this._onCanPlay),t.addEventListener("error",this._onError,!0)),this._load=new Promise((e,i)=>{this.valid?e(this):(this._resolve=e,this._reject=i,t.load())}),this._load}_onError(t){this.source.removeEventListener("error",this._onError,!0),this.onError.emit(t),this._reject&&(this._reject(t),this._reject=null,this._resolve=null)}_isSourcePlaying(){const t=this.source;return!t.paused&&!t.ended}_isSourceReady(){return this.source.readyState>2}_onPlayStart(){this.valid||this._onCanPlay(),this._configureAutoUpdate()}_onPlayStop(){this._configureAutoUpdate()}_onSeeked(){this._autoUpdate&&!this._isSourcePlaying()&&(this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0)}_onCanPlay(){const t=this.source;t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay);const e=this.valid;this._msToNextUpdate=0,this.update(),this._msToNextUpdate=0,!e&&this._resolve&&(this._resolve(this),this._resolve=null,this._reject=null),this._isSourcePlaying()?this._onPlayStart():this.autoPlay&&t.play()}dispose(){this._configureAutoUpdate();const t=this.source;t&&(t.removeEventListener("play",this._onPlayStart),t.removeEventListener("pause",this._onPlayStop),t.removeEventListener("seeked",this._onSeeked),t.removeEventListener("canplay",this._onCanPlay),t.removeEventListener("canplaythrough",this._onCanPlay),t.removeEventListener("error",this._onError,!0),t.pause(),t.src="",t.load()),super.dispose()}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,this._configureAutoUpdate())}get updateFPS(){return this._updateFPS}set updateFPS(t){t!==this._updateFPS&&(this._updateFPS=t,this._configureAutoUpdate())}_configureAutoUpdate(){this._autoUpdate&&this._isSourcePlaying()?!this._updateFPS&&this.source.requestVideoFrameCallback?(this._isConnectedToTicker&&(ke.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0),this._videoFrameRequestCallbackHandle===null&&(this._videoFrameRequestCallbackHandle=this.source.requestVideoFrameCallback(this._videoFrameRequestCallback))):(this._videoFrameRequestCallbackHandle!==null&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker||(ke.shared.add(this.update,this),this._isConnectedToTicker=!0,this._msToNextUpdate=0)):(this._videoFrameRequestCallbackHandle!==null&&(this.source.cancelVideoFrameCallback(this._videoFrameRequestCallbackHandle),this._videoFrameRequestCallbackHandle=null),this._isConnectedToTicker&&(ke.shared.remove(this.update,this),this._isConnectedToTicker=!1,this._msToNextUpdate=0))}static test(t,e){return globalThis.HTMLVideoElement&&t instanceof HTMLVideoElement||Kh.TYPES.includes(e)}};yh.TYPES=["mp4","m4v","webm","ogg","ogv","h264","avi","mov"],yh.MIME_TYPES={ogv:"video/ogg",mov:"video/quicktime",m4v:"video/mp4"};let zp=yh;Jl.push(mn,fp,CT,zp,PT,gh,lo,IT,ST);class Po{constructor(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0,this.rect=null,this.updateID=-1}isEmpty(){return this.minX>this.maxX||this.minY>this.maxY}clear(){this.minX=1/0,this.minY=1/0,this.maxX=-1/0,this.maxY=-1/0}getRectangle(t){return this.minX>this.maxX||this.minY>this.maxY?wt.EMPTY:(t=t||new wt(0,0,1,1),t.x=this.minX,t.y=this.minY,t.width=this.maxX-this.minX,t.height=this.maxY-this.minY,t)}addPoint(t){this.minX=Math.min(this.minX,t.x),this.maxX=Math.max(this.maxX,t.x),this.minY=Math.min(this.minY,t.y),this.maxY=Math.max(this.maxY,t.y)}addPointMatrix(t,e){const{a:i,b:n,c:s,d:o,tx:a,ty:l}=t,h=i*e.x+s*e.y+a,c=n*e.x+o*e.y+l;this.minX=Math.min(this.minX,h),this.maxX=Math.max(this.maxX,h),this.minY=Math.min(this.minY,c),this.maxY=Math.max(this.maxY,c)}addQuad(t){let e=this.minX,i=this.minY,n=this.maxX,s=this.maxY,o=t[0],a=t[1];e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,o=t[2],a=t[3],e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,o=t[4],a=t[5],e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,o=t[6],a=t[7],e=o<e?o:e,i=a<i?a:i,n=o>n?o:n,s=a>s?a:s,this.minX=e,this.minY=i,this.maxX=n,this.maxY=s}addFrame(t,e,i,n,s){this.addFrameMatrix(t.worldTransform,e,i,n,s)}addFrameMatrix(t,e,i,n,s){const o=t.a,a=t.b,l=t.c,h=t.d,c=t.tx,u=t.ty;let d=this.minX,f=this.minY,p=this.maxX,g=this.maxY,y=o*e+l*i+c,_=a*e+h*i+u;d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,y=o*n+l*i+c,_=a*n+h*i+u,d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,y=o*e+l*s+c,_=a*e+h*s+u,d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,y=o*n+l*s+c,_=a*n+h*s+u,d=y<d?y:d,f=_<f?_:f,p=y>p?y:p,g=_>g?_:g,this.minX=d,this.minY=f,this.maxX=p,this.maxY=g}addVertexData(t,e,i){let n=this.minX,s=this.minY,o=this.maxX,a=this.maxY;for(let l=e;l<i;l+=2){const h=t[l],c=t[l+1];n=h<n?h:n,s=c<s?c:s,o=h>o?h:o,a=c>a?c:a}this.minX=n,this.minY=s,this.maxX=o,this.maxY=a}addVertices(t,e,i,n){this.addVerticesMatrix(t.worldTransform,e,i,n)}addVerticesMatrix(t,e,i,n,s=0,o=s){const a=t.a,l=t.b,h=t.c,c=t.d,u=t.tx,d=t.ty;let f=this.minX,p=this.minY,g=this.maxX,y=this.maxY;for(let _=i;_<n;_+=2){const v=e[_],m=e[_+1],x=a*v+h*m+u,S=c*m+l*v+d;f=Math.min(f,x-s),g=Math.max(g,x+s),p=Math.min(p,S-o),y=Math.max(y,S+o)}this.minX=f,this.minY=p,this.maxX=g,this.maxY=y}addBounds(t){const e=this.minX,i=this.minY,n=this.maxX,s=this.maxY;this.minX=t.minX<e?t.minX:e,this.minY=t.minY<i?t.minY:i,this.maxX=t.maxX>n?t.maxX:n,this.maxY=t.maxY>s?t.maxY:s}addBoundsMask(t,e){const i=t.minX>e.minX?t.minX:e.minX,n=t.minY>e.minY?t.minY:e.minY,s=t.maxX<e.maxX?t.maxX:e.maxX,o=t.maxY<e.maxY?t.maxY:e.maxY;if(i<=s&&n<=o){const a=this.minX,l=this.minY,h=this.maxX,c=this.maxY;this.minX=i<a?i:a,this.minY=n<l?n:l,this.maxX=s>h?s:h,this.maxY=o>c?o:c}}addBoundsMatrix(t,e){this.addFrameMatrix(e,t.minX,t.minY,t.maxX,t.maxY)}addBoundsArea(t,e){const i=t.minX>e.x?t.minX:e.x,n=t.minY>e.y?t.minY:e.y,s=t.maxX<e.x+e.width?t.maxX:e.x+e.width,o=t.maxY<e.y+e.height?t.maxY:e.y+e.height;if(i<=s&&n<=o){const a=this.minX,l=this.minY,h=this.maxX,c=this.maxY;this.minX=i<a?i:a,this.minY=n<l?n:l,this.maxX=s>h?s:h,this.maxY=o>c?o:c}}pad(t=0,e=t){this.isEmpty()||(this.minX-=t,this.maxX+=t,this.minY-=e,this.maxY+=e)}addFramePad(t,e,i,n,s,o){t-=s,e-=o,i+=s,n+=o,this.minX=this.minX<t?this.minX:t,this.maxX=this.maxX>i?this.maxX:i,this.minY=this.minY<e?this.minY:e,this.maxY=this.maxY>n?this.maxY:n}}class Xt extends Vn{constructor(){super(),this.tempDisplayObjectParent=null,this.transform=new ih,this.alpha=1,this.visible=!0,this.renderable=!0,this.cullable=!1,this.cullArea=null,this.parent=null,this.worldAlpha=1,this._lastSortedIndex=0,this._zIndex=0,this.filterArea=null,this.filters=null,this._enabledFilters=null,this._bounds=new Po,this._localBounds=null,this._boundsID=0,this._boundsRect=null,this._localBoundsRect=null,this._mask=null,this._maskRefCount=0,this._destroyed=!1,this.isSprite=!1,this.isMask=!1}static mixin(t){const e=Object.keys(t);for(let i=0;i<e.length;++i){const n=e[i];Object.defineProperty(Xt.prototype,n,Object.getOwnPropertyDescriptor(t,n))}}get destroyed(){return this._destroyed}_recursivePostUpdateTransform(){this.parent?(this.parent._recursivePostUpdateTransform(),this.transform.updateTransform(this.parent.transform)):this.transform.updateTransform(this._tempDisplayObjectParent.transform)}updateTransform(){this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha}getBounds(t,e){return t||(this.parent?(this._recursivePostUpdateTransform(),this.updateTransform()):(this.parent=this._tempDisplayObjectParent,this.updateTransform(),this.parent=null)),this._bounds.updateID!==this._boundsID&&(this.calculateBounds(),this._bounds.updateID=this._boundsID),e||(this._boundsRect||(this._boundsRect=new wt),e=this._boundsRect),this._bounds.getRectangle(e)}getLocalBounds(t){t||(this._localBoundsRect||(this._localBoundsRect=new wt),t=this._localBoundsRect),this._localBounds||(this._localBounds=new Po);const e=this.transform,i=this.parent;this.parent=null,this._tempDisplayObjectParent.worldAlpha=(i==null?void 0:i.worldAlpha)??1,this.transform=this._tempDisplayObjectParent.transform;const n=this._bounds,s=this._boundsID;this._bounds=this._localBounds;const o=this.getBounds(!1,t);return this.parent=i,this.transform=e,this._bounds=n,this._bounds.updateID+=this._boundsID-s,o}toGlobal(t,e,i=!1){return i||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.apply(t,e)}toLocal(t,e,i,n){return e&&(t=e.toGlobal(t,i,n)),n||(this._recursivePostUpdateTransform(),this.parent?this.displayObjectUpdateTransform():(this.parent=this._tempDisplayObjectParent,this.displayObjectUpdateTransform(),this.parent=null)),this.worldTransform.applyInverse(t,i)}setParent(t){if(!t||!t.addChild)throw new Error("setParent: Argument must be a Container");return t.addChild(this),t}removeFromParent(){var t;(t=this.parent)==null||t.removeChild(this)}setTransform(t=0,e=0,i=1,n=1,s=0,o=0,a=0,l=0,h=0){return this.position.x=t,this.position.y=e,this.scale.x=i||1,this.scale.y=n||1,this.rotation=s,this.skew.x=o,this.skew.y=a,this.pivot.x=l,this.pivot.y=h,this}destroy(t){this.removeFromParent(),this._destroyed=!0,this.transform=null,this.parent=null,this._bounds=null,this.mask=null,this.cullArea=null,this.filters=null,this.filterArea=null,this.hitArea=null,this.eventMode="auto",this.interactiveChildren=!1,this.emit("destroyed"),this.removeAllListeners()}get _tempDisplayObjectParent(){return this.tempDisplayObjectParent===null&&(this.tempDisplayObjectParent=new RT),this.tempDisplayObjectParent}enableTempParent(){const t=this.parent;return this.parent=this._tempDisplayObjectParent,t}disableTempParent(t){this.parent=t}get x(){return this.position.x}set x(t){this.transform.position.x=t}get y(){return this.position.y}set y(t){this.transform.position.y=t}get worldTransform(){return this.transform.worldTransform}get localTransform(){return this.transform.localTransform}get position(){return this.transform.position}set position(t){this.transform.position.copyFrom(t)}get scale(){return this.transform.scale}set scale(t){this.transform.scale.copyFrom(t)}get pivot(){return this.transform.pivot}set pivot(t){this.transform.pivot.copyFrom(t)}get skew(){return this.transform.skew}set skew(t){this.transform.skew.copyFrom(t)}get rotation(){return this.transform.rotation}set rotation(t){this.transform.rotation=t}get angle(){return this.transform.rotation*EE}set angle(t){this.transform.rotation=t*TE}get zIndex(){return this._zIndex}set zIndex(t){this._zIndex!==t&&(this._zIndex=t,this.parent&&(this.parent.sortDirty=!0))}get worldVisible(){let t=this;do{if(!t.visible)return!1;t=t.parent}while(t);return!0}get mask(){return this._mask}set mask(t){if(this._mask!==t){if(this._mask){const e=this._mask.isMaskData?this._mask.maskObject:this._mask;e&&(e._maskRefCount--,e._maskRefCount===0&&(e.renderable=!0,e.isMask=!1))}if(this._mask=t,this._mask){const e=this._mask.isMaskData?this._mask.maskObject:this._mask;e&&(e._maskRefCount===0&&(e.renderable=!1,e.isMask=!0),e._maskRefCount++)}}}}class RT extends Xt{constructor(){super(...arguments),this.sortDirty=null}}Xt.prototype.displayObjectUpdateTransform=Xt.prototype.updateTransform;const MT=new Ft;function OT(r,t){return r.zIndex===t.zIndex?r._lastSortedIndex-t._lastSortedIndex:r.zIndex-t.zIndex}const qp=class Zh extends Xt{constructor(){super(),this.children=[],this.sortableChildren=Zh.defaultSortableChildren,this.sortDirty=!1}onChildrenChange(t){}addChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.addChild(t[e]);else{const e=t[0];e.parent&&e.parent.removeChild(e),e.parent=this,this.sortDirty=!0,e.transform._parentID=-1,this.children.push(e),this._boundsID++,this.onChildrenChange(this.children.length-1),this.emit("childAdded",e,this,this.children.length-1),e.emit("added",this)}return t[0]}addChildAt(t,e){if(e<0||e>this.children.length)throw new Error(`${t}addChildAt: The index ${e} supplied is out of bounds ${this.children.length}`);return t.parent&&t.parent.removeChild(t),t.parent=this,this.sortDirty=!0,t.transform._parentID=-1,this.children.splice(e,0,t),this._boundsID++,this.onChildrenChange(e),t.emit("added",this),this.emit("childAdded",t,this,e),t}swapChildren(t,e){if(t===e)return;const i=this.getChildIndex(t),n=this.getChildIndex(e);this.children[i]=e,this.children[n]=t,this.onChildrenChange(i<n?i:n)}getChildIndex(t){const e=this.children.indexOf(t);if(e===-1)throw new Error("The supplied DisplayObject must be a child of the caller");return e}setChildIndex(t,e){if(e<0||e>=this.children.length)throw new Error(`The index ${e} supplied is out of bounds ${this.children.length}`);const i=this.getChildIndex(t);dn(this.children,i,1),this.children.splice(e,0,t),this.onChildrenChange(e)}getChildAt(t){if(t<0||t>=this.children.length)throw new Error(`getChildAt: Index (${t}) does not exist.`);return this.children[t]}removeChild(...t){if(t.length>1)for(let e=0;e<t.length;e++)this.removeChild(t[e]);else{const e=t[0],i=this.children.indexOf(e);if(i===-1)return null;e.parent=null,e.transform._parentID=-1,dn(this.children,i,1),this._boundsID++,this.onChildrenChange(i),e.emit("removed",this),this.emit("childRemoved",e,this,i)}return t[0]}removeChildAt(t){const e=this.getChildAt(t);return e.parent=null,e.transform._parentID=-1,dn(this.children,t,1),this._boundsID++,this.onChildrenChange(t),e.emit("removed",this),this.emit("childRemoved",e,this,t),e}removeChildren(t=0,e=this.children.length){const i=t,n=e,s=n-i;let o;if(s>0&&s<=n){o=this.children.splice(i,s);for(let a=0;a<o.length;++a)o[a].parent=null,o[a].transform&&(o[a].transform._parentID=-1);this._boundsID++,this.onChildrenChange(t);for(let a=0;a<o.length;++a)o[a].emit("removed",this),this.emit("childRemoved",o[a],this,a);return o}else if(s===0&&this.children.length===0)return[];throw new RangeError("removeChildren: numeric values are outside the acceptable range.")}sortChildren(){let t=!1;for(let e=0,i=this.children.length;e<i;++e){const n=this.children[e];n._lastSortedIndex=e,!t&&n.zIndex!==0&&(t=!0)}t&&this.children.length>1&&this.children.sort(OT),this.sortDirty=!1}updateTransform(){this.sortableChildren&&this.sortDirty&&this.sortChildren(),this._boundsID++,this.transform.updateTransform(this.parent.transform),this.worldAlpha=this.alpha*this.parent.worldAlpha;for(let t=0,e=this.children.length;t<e;++t){const i=this.children[t];i.visible&&i.updateTransform()}}calculateBounds(){this._bounds.clear(),this._calculateBounds();for(let t=0;t<this.children.length;t++){const e=this.children[t];if(!(!e.visible||!e.renderable))if(e.calculateBounds(),e._mask){const i=e._mask.isMaskData?e._mask.maskObject:e._mask;i?(i.calculateBounds(),this._bounds.addBoundsMask(e._bounds,i._bounds)):this._bounds.addBounds(e._bounds)}else e.filterArea?this._bounds.addBoundsArea(e._bounds,e.filterArea):this._bounds.addBounds(e._bounds)}this._bounds.updateID=this._boundsID}getLocalBounds(t,e=!1){const i=super.getLocalBounds(t);if(!e)for(let n=0,s=this.children.length;n<s;++n){const o=this.children[n];o.visible&&o.updateTransform()}return i}_calculateBounds(){}_renderWithCulling(t){const e=t.renderTexture.sourceFrame;if(!(e.width>0&&e.height>0))return;let i,n;this.cullArea?(i=this.cullArea,n=this.worldTransform):this._render!==Zh.prototype._render&&(i=this.getBounds(!0));const s=t.projection.transform;if(s&&(n?(n=MT.copyFrom(n),n.prepend(s)):n=s),i&&e.intersects(i,n))this._render(t);else if(this.cullArea)return;for(let o=0,a=this.children.length;o<a;++o){const l=this.children[o],h=l.cullable;l.cullable=h||!this.cullArea,l.render(t),l.cullable=h}}render(t){var e;if(!(!this.visible||this.worldAlpha<=0||!this.renderable))if(this._mask||(e=this.filters)!=null&&e.length)this.renderAdvanced(t);else if(this.cullable)this._renderWithCulling(t);else{this._render(t);for(let i=0,n=this.children.length;i<n;++i)this.children[i].render(t)}}renderAdvanced(t){var s,o,a;const e=this.filters,i=this._mask;if(e){this._enabledFilters||(this._enabledFilters=[]),this._enabledFilters.length=0;for(let l=0;l<e.length;l++)e[l].enabled&&this._enabledFilters.push(e[l])}const n=e&&((s=this._enabledFilters)==null?void 0:s.length)||i&&(!i.isMaskData||i.enabled&&(i.autoDetect||i.type!==ie.NONE));if(n&&t.batch.flush(),e&&((o=this._enabledFilters)!=null&&o.length)&&t.filter.push(this,this._enabledFilters),i&&t.mask.push(this,this._mask),this.cullable)this._renderWithCulling(t);else{this._render(t);for(let l=0,h=this.children.length;l<h;++l)this.children[l].render(t)}n&&t.batch.flush(),i&&t.mask.pop(this),e&&((a=this._enabledFilters)!=null&&a.length)&&t.filter.pop()}_render(t){}destroy(t){super.destroy(),this.sortDirty=!1;const e=typeof t=="boolean"?t:t==null?void 0:t.children,i=this.removeChildren(0,this.children.length);if(e)for(let n=0;n<i.length;++n)i[n].destroy(t)}get width(){return this.scale.x*this.getLocalBounds().width}set width(t){const e=this.getLocalBounds().width;e!==0?this.scale.x=t/e:this.scale.x=1,this._width=t}get height(){return this.scale.y*this.getLocalBounds().height}set height(t){const e=this.getLocalBounds().height;e!==0?this.scale.y=t/e:this.scale.y=1,this._height=t}};qp.defaultSortableChildren=!1;let Ze=qp;Ze.prototype.containerUpdateTransform=Ze.prototype.updateTransform,Object.defineProperties(tt,{SORTABLE_CHILDREN:{get(){return Ze.defaultSortableChildren},set(r){St("7.1.0","settings.SORTABLE_CHILDREN is deprecated, use Container.defaultSortableChildren"),Ze.defaultSortableChildren=r}}});const us=new It,BT=new Uint16Array([0,1,2,0,2,3]);class gn extends Ze{constructor(t){super(),this._anchor=new Cr(this._onAnchorUpdate,this,t?t.defaultAnchor.x:0,t?t.defaultAnchor.y:0),this._texture=null,this._width=0,this._height=0,this._tintColor=new Mt(16777215),this._tintRGB=null,this.tint=16777215,this.blendMode=vt.NORMAL,this._cachedTint=16777215,this.uvs=null,this.texture=t||dt.EMPTY,this.vertexData=new Float32Array(8),this.vertexTrimmedData=null,this._transformID=-1,this._textureID=-1,this._transformTrimmedID=-1,this._textureTrimmedID=-1,this.indices=BT,this.pluginName="batch",this.isSprite=!0,this._roundPixels=tt.ROUND_PIXELS}_onTextureUpdate(){this._textureID=-1,this._textureTrimmedID=-1,this._cachedTint=16777215,this._width&&(this.scale.x=zr(this.scale.x)*this._width/this._texture.orig.width),this._height&&(this.scale.y=zr(this.scale.y)*this._height/this._texture.orig.height)}_onAnchorUpdate(){this._transformID=-1,this._transformTrimmedID=-1}calculateVertices(){const t=this._texture;if(this._transformID===this.transform._worldID&&this._textureID===t._updateID)return;this._textureID!==t._updateID&&(this.uvs=this._texture._uvs.uvsFloat32),this._transformID=this.transform._worldID,this._textureID=t._updateID;const e=this.transform.worldTransform,i=e.a,n=e.b,s=e.c,o=e.d,a=e.tx,l=e.ty,h=this.vertexData,c=t.trim,u=t.orig,d=this._anchor;let f=0,p=0,g=0,y=0;if(c?(p=c.x-d._x*u.width,f=p+c.width,y=c.y-d._y*u.height,g=y+c.height):(p=-d._x*u.width,f=p+u.width,y=-d._y*u.height,g=y+u.height),h[0]=i*p+s*y+a,h[1]=o*y+n*p+l,h[2]=i*f+s*y+a,h[3]=o*y+n*f+l,h[4]=i*f+s*g+a,h[5]=o*g+n*f+l,h[6]=i*p+s*g+a,h[7]=o*g+n*p+l,this._roundPixels){const _=tt.RESOLUTION;for(let v=0;v<h.length;++v)h[v]=Math.round(h[v]*_)/_}}calculateTrimmedVertices(){if(!this.vertexTrimmedData)this.vertexTrimmedData=new Float32Array(8);else if(this._transformTrimmedID===this.transform._worldID&&this._textureTrimmedID===this._texture._updateID)return;this._transformTrimmedID=this.transform._worldID,this._textureTrimmedID=this._texture._updateID;const t=this._texture,e=this.vertexTrimmedData,i=t.orig,n=this._anchor,s=this.transform.worldTransform,o=s.a,a=s.b,l=s.c,h=s.d,c=s.tx,u=s.ty,d=-n._x*i.width,f=d+i.width,p=-n._y*i.height,g=p+i.height;if(e[0]=o*d+l*p+c,e[1]=h*p+a*d+u,e[2]=o*f+l*p+c,e[3]=h*p+a*f+u,e[4]=o*f+l*g+c,e[5]=h*g+a*f+u,e[6]=o*d+l*g+c,e[7]=h*g+a*d+u,this._roundPixels){const y=tt.RESOLUTION;for(let _=0;_<e.length;++_)e[_]=Math.round(e[_]*y)/y}}_render(t){this.calculateVertices(),t.batch.setObjectRenderer(t.plugins[this.pluginName]),t.plugins[this.pluginName].render(this)}_calculateBounds(){const t=this._texture.trim,e=this._texture.orig;!t||t.width===e.width&&t.height===e.height?(this.calculateVertices(),this._bounds.addQuad(this.vertexData)):(this.calculateTrimmedVertices(),this._bounds.addQuad(this.vertexTrimmedData))}getLocalBounds(t){return this.children.length===0?(this._localBounds||(this._localBounds=new Po),this._localBounds.minX=this._texture.orig.width*-this._anchor._x,this._localBounds.minY=this._texture.orig.height*-this._anchor._y,this._localBounds.maxX=this._texture.orig.width*(1-this._anchor._x),this._localBounds.maxY=this._texture.orig.height*(1-this._anchor._y),t||(this._localBoundsRect||(this._localBoundsRect=new wt),t=this._localBoundsRect),this._localBounds.getRectangle(t)):super.getLocalBounds.call(this,t)}containsPoint(t){this.worldTransform.applyInverse(t,us);const e=this._texture.orig.width,i=this._texture.orig.height,n=-e*this.anchor.x;let s=0;return us.x>=n&&us.x<n+e&&(s=-i*this.anchor.y,us.y>=s&&us.y<s+i)}destroy(t){if(super.destroy(t),this._texture.off("update",this._onTextureUpdate,this),this._anchor=null,typeof t=="boolean"?t:t==null?void 0:t.texture){const e=typeof t=="boolean"?t:t==null?void 0:t.baseTexture;this._texture.destroy(!!e)}this._texture=null}static from(t,e){const i=t instanceof dt?t:dt.from(t,e);return new gn(i)}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1,this._transformTrimmedID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get width(){return Math.abs(this.scale.x)*this._texture.orig.width}set width(t){const e=zr(this.scale.x)||1;this.scale.x=e*t/this._texture.orig.width,this._width=t}get height(){return Math.abs(this.scale.y)*this._texture.orig.height}set height(t){const e=zr(this.scale.y)||1;this.scale.y=e*t/this._texture.orig.height,this._height=t}get anchor(){return this._anchor}set anchor(t){this._anchor.copyFrom(t)}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t),this._tintRGB=this._tintColor.toLittleEndianNumber()}get tintValue(){return this._tintColor.toNumber()}get texture(){return this._texture}set texture(t){this._texture!==t&&(this._texture&&this._texture.off("update",this._onTextureUpdate,this),this._texture=t||dt.EMPTY,this._cachedTint=16777215,this._textureID=-1,this._textureTrimmedID=-1,t&&(t.baseTexture.valid?this._onTextureUpdate():t.once("update",this._onTextureUpdate,this)))}}const Kp=new Ft;Xt.prototype._cacheAsBitmap=!1,Xt.prototype._cacheData=null,Xt.prototype._cacheAsBitmapResolution=null,Xt.prototype._cacheAsBitmapMultisample=null;class LT{constructor(){this.textureCacheId=null,this.originalRender=null,this.originalRenderCanvas=null,this.originalCalculateBounds=null,this.originalGetLocalBounds=null,this.originalUpdateTransform=null,this.originalDestroy=null,this.originalMask=null,this.originalFilterArea=null,this.originalContainsPoint=null,this.sprite=null}}Object.defineProperties(Xt.prototype,{cacheAsBitmapResolution:{get(){return this._cacheAsBitmapResolution},set(r){r!==this._cacheAsBitmapResolution&&(this._cacheAsBitmapResolution=r,this.cacheAsBitmap&&(this.cacheAsBitmap=!1,this.cacheAsBitmap=!0))}},cacheAsBitmapMultisample:{get(){return this._cacheAsBitmapMultisample},set(r){r!==this._cacheAsBitmapMultisample&&(this._cacheAsBitmapMultisample=r,this.cacheAsBitmap&&(this.cacheAsBitmap=!1,this.cacheAsBitmap=!0))}},cacheAsBitmap:{get(){return this._cacheAsBitmap},set(r){if(this._cacheAsBitmap===r)return;this._cacheAsBitmap=r;let t;r?(this._cacheData||(this._cacheData=new LT),t=this._cacheData,t.originalRender=this.render,t.originalRenderCanvas=this.renderCanvas,t.originalUpdateTransform=this.updateTransform,t.originalCalculateBounds=this.calculateBounds,t.originalGetLocalBounds=this.getLocalBounds,t.originalDestroy=this.destroy,t.originalContainsPoint=this.containsPoint,t.originalMask=this._mask,t.originalFilterArea=this.filterArea,this.render=this._renderCached,this.renderCanvas=this._renderCachedCanvas,this.destroy=this._cacheAsBitmapDestroy):(t=this._cacheData,t.sprite&&this._destroyCachedDisplayObject(),this.render=t.originalRender,this.renderCanvas=t.originalRenderCanvas,this.calculateBounds=t.originalCalculateBounds,this.getLocalBounds=t.originalGetLocalBounds,this.destroy=t.originalDestroy,this.updateTransform=t.originalUpdateTransform,this.containsPoint=t.originalContainsPoint,this._mask=t.originalMask,this.filterArea=t.originalFilterArea)}}}),Xt.prototype._renderCached=function(r){!this.visible||this.worldAlpha<=0||!this.renderable||(this._initCachedDisplayObject(r),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite.worldAlpha=this.worldAlpha,this._cacheData.sprite._render(r))},Xt.prototype._initCachedDisplayObject=function(r){var d,f;if((d=this._cacheData)!=null&&d.sprite)return;const t=this.alpha;this.alpha=1,r.batch.flush();const e=this.getLocalBounds(new wt,!0);if((f=this.filters)!=null&&f.length){const p=this.filters[0].padding;e.pad(p)}const i=this.cacheAsBitmapResolution||r.resolution;e.ceil(i),e.width=Math.max(e.width,1/i),e.height=Math.max(e.height,1/i);const n=r.renderTexture.current,s=r.renderTexture.sourceFrame.clone(),o=r.renderTexture.destinationFrame.clone(),a=r.projection.transform,l=Si.create({width:e.width,height:e.height,resolution:i,multisample:this.cacheAsBitmapMultisample??r.multisample}),h=`cacheAsBitmap_${vi()}`;this._cacheData.textureCacheId=h,xt.addToCache(l.baseTexture,h),dt.addToCache(l,h);const c=this.transform.localTransform.copyTo(Kp).invert().translate(-e.x,-e.y);this.render=this._cacheData.originalRender,r.render(this,{renderTexture:l,clear:!0,transform:c,skipUpdateTransform:!1}),r.framebuffer.blit(),r.projection.transform=a,r.renderTexture.bind(n,s,o),this.render=this._renderCached,this.updateTransform=this.displayObjectUpdateTransform,this.calculateBounds=this._calculateCachedBounds,this.getLocalBounds=this._getCachedLocalBounds,this._mask=null,this.filterArea=null,this.alpha=t;const u=new gn(l);u.transform.worldTransform=this.transform.worldTransform,u.anchor.x=-(e.x/e.width),u.anchor.y=-(e.y/e.height),u.alpha=t,u._bounds=this._bounds,this._cacheData.sprite=u,this.transform._parentID=-1,this.parent?this.updateTransform():(this.enableTempParent(),this.updateTransform(),this.disableTempParent(null)),this.containsPoint=u.containsPoint.bind(u)},Xt.prototype._renderCachedCanvas=function(r){!this.visible||this.worldAlpha<=0||!this.renderable||(this._initCachedDisplayObjectCanvas(r),this._cacheData.sprite.worldAlpha=this.worldAlpha,this._cacheData.sprite._renderCanvas(r))},Xt.prototype._initCachedDisplayObjectCanvas=function(r){var c;if((c=this._cacheData)!=null&&c.sprite)return;const t=this.getLocalBounds(new wt,!0),e=this.alpha;this.alpha=1;const i=r.canvasContext.activeContext,n=r._projTransform,s=this.cacheAsBitmapResolution||r.resolution;t.ceil(s),t.width=Math.max(t.width,1/s),t.height=Math.max(t.height,1/s);const o=Si.create({width:t.width,height:t.height,resolution:s}),a=`cacheAsBitmap_${vi()}`;this._cacheData.textureCacheId=a,xt.addToCache(o.baseTexture,a),dt.addToCache(o,a);const l=Kp;this.transform.localTransform.copyTo(l),l.invert(),l.tx-=t.x,l.ty-=t.y,this.renderCanvas=this._cacheData.originalRenderCanvas,r.render(this,{renderTexture:o,clear:!0,transform:l,skipUpdateTransform:!1}),r.canvasContext.activeContext=i,r._projTransform=n,this.renderCanvas=this._renderCachedCanvas,this.updateTransform=this.displayObjectUpdateTransform,this.calculateBounds=this._calculateCachedBounds,this.getLocalBounds=this._getCachedLocalBounds,this._mask=null,this.filterArea=null,this.alpha=e;const h=new gn(o);h.transform.worldTransform=this.transform.worldTransform,h.anchor.x=-(t.x/t.width),h.anchor.y=-(t.y/t.height),h.alpha=e,h._bounds=this._bounds,this._cacheData.sprite=h,this.transform._parentID=-1,this.parent?this.updateTransform():(this.parent=r._tempDisplayObjectParent,this.updateTransform(),this.parent=null),this.containsPoint=h.containsPoint.bind(h)},Xt.prototype._calculateCachedBounds=function(){this._bounds.clear(),this._cacheData.sprite.transform._worldID=this.transform._worldID,this._cacheData.sprite._calculateBounds(),this._bounds.updateID=this._boundsID},Xt.prototype._getCachedLocalBounds=function(){return this._cacheData.sprite.getLocalBounds(null)},Xt.prototype._destroyCachedDisplayObject=function(){this._cacheData.sprite._texture.destroy(!0),this._cacheData.sprite=null,xt.removeFromCache(this._cacheData.textureCacheId),dt.removeFromCache(this._cacheData.textureCacheId),this._cacheData.textureCacheId=null},Xt.prototype._cacheAsBitmapDestroy=function(r){this.cacheAsBitmap=!1,this.destroy(r)},Xt.prototype.name=null,Ze.prototype.getChildByName=function(r,t){for(let e=0,i=this.children.length;e<i;e++)if(this.children[e].name===r)return this.children[e];if(t)for(let e=0,i=this.children.length;e<i;e++){const n=this.children[e];if(!n.getChildByName)continue;const s=n.getChildByName(r,!0);if(s)return s}return null},Xt.prototype.getGlobalPosition=function(r=new It,t=!1){return this.parent?this.parent.toGlobal(this.position,r,t):(r.x=this.position.x,r.y=this.position.y),r};var DT=`varying vec2 vTextureCoord;
527
527
 
528
528
  uniform sampler2D uSampler;
529
529
  uniform float uAlpha;
@@ -863,7 +863,7 @@ void main()
863
863
 
864
864
  gl_FragColor = color;
865
865
  }
866
- `;class ZT extends Re{constructor(t=.5,e=Math.random()){super(Hp,KT,{uNoise:0,uSeed:0}),this.noise=t,this.seed=e}get noise(){return this.uniforms.uNoise}set noise(t){this.uniforms.uNoise=t}get seed(){return this.uniforms.uSeed}set seed(t){this.uniforms.uSeed=t}}const Zp={AlphaFilter:NT,BlurFilter:HT,BlurFilterPass:_h,ColorMatrixFilter:vh,DisplacementFilter:WT,FXAAFilter:qT,NoiseFilter:ZT};Object.entries(Zp).forEach(([r,t])=>{Object.defineProperty(Zp,r,{get(){return St("7.1.0",`filters.${r} has moved to ${r}`),t}})});class JT{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}init(t){this.removeTickerListener(),this.events=t,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(t){this._pauseUpdate=t}addTickerListener(){this.tickerAdded||!this.domElement||(Fe.system.add(this.tickerUpdate,this,Pi.INTERACTION),this.tickerAdded=!0)}removeTickerListener(){this.tickerAdded&&(Fe.system.remove(this.tickerUpdate,this),this.tickerAdded=!1)}pointerMoved(){this._didMove=!0}update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove){this._didMove=!1;return}const t=this.events.rootPointerEvent;this.events.supportsTouchEvents&&t.pointerType==="touch"||globalThis.document.dispatchEvent(new PointerEvent("pointermove",{clientX:t.clientX,clientY:t.clientY}))}tickerUpdate(t){this._deltaTime+=t,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this.update())}}const Zr=new JT;class ds{constructor(t){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=ds.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new It,this.page=new It,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=t}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(t,e,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(t,e,i,n,s){throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}preventDefault(){this.nativeEvent instanceof Event&&this.nativeEvent.cancelable&&this.nativeEvent.preventDefault(),this.defaultPrevented=!0}stopImmediatePropagation(){this.propagationImmediatelyStopped=!0}stopPropagation(){this.propagationStopped=!0}}class Ro extends ds{constructor(){super(...arguments),this.client=new It,this.movement=new It,this.offset=new It,this.global=new It,this.screen=new It}get clientX(){return this.client.x}get clientY(){return this.client.y}get x(){return this.clientX}get y(){return this.clientY}get movementX(){return this.movement.x}get movementY(){return this.movement.y}get offsetX(){return this.offset.x}get offsetY(){return this.offset.y}get globalX(){return this.global.x}get globalY(){return this.global.y}get screenX(){return this.screen.x}get screenY(){return this.screen.y}getLocalPosition(t,e,i){return t.worldTransform.applyInverse(i||this.global,e)}getModifierState(t){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(t)}initMouseEvent(t,e,i,n,s,o,a,l,h,c,u,d,f,p,g){throw new Error("Method not implemented.")}}class Je extends Ro{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1}getCoalescedEvents(){return this.type==="pointermove"||this.type==="mousemove"||this.type==="touchmove"?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class yn extends Ro{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}yn.DOM_DELTA_PIXEL=0,yn.DOM_DELTA_LINE=1,yn.DOM_DELTA_PAGE=2;const QT=2048,tA=new It,bh=new It;class eA{constructor(t){this.dispatch=new Vn,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=t,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel)}addEventMapping(t,e){this.mappingTable[t]||(this.mappingTable[t]=[]),this.mappingTable[t].push({fn:e,priority:0}),this.mappingTable[t].sort((i,n)=>i.priority-n.priority)}dispatchEvent(t,e){t.propagationStopped=!1,t.propagationImmediatelyStopped=!1,this.propagate(t,e),this.dispatch.emit(e||t.type,t)}mapEvent(t){if(!this.rootTarget)return;const e=this.mappingTable[t.type];if(e)for(let i=0,n=e.length;i<n;i++)e[i].fn(t);else console.warn(`[EventBoundary]: Event mapping not defined for ${t.type}`)}hitTest(t,e){Zr.pauseUpdate=!0;const i=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",n=this[i](this.rootTarget,this.rootTarget.eventMode,tA.set(t,e),this.hitTestFn,this.hitPruneFn);return n&&n[0]}propagate(t,e){if(!t.target)return;const i=t.composedPath();t.eventPhase=t.CAPTURING_PHASE;for(let n=0,s=i.length-1;n<s;n++)if(t.currentTarget=i[n],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return;if(t.eventPhase=t.AT_TARGET,t.currentTarget=t.target,this.notifyTarget(t,e),!(t.propagationStopped||t.propagationImmediatelyStopped)){t.eventPhase=t.BUBBLING_PHASE;for(let n=i.length-2;n>=0;n--)if(t.currentTarget=i[n],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return}}all(t,e,i=this._allInteractiveElements){if(i.length===0)return;t.eventPhase=t.BUBBLING_PHASE;const n=Array.isArray(e)?e:[e];for(let s=i.length-1;s>=0;s--)n.forEach(o=>{t.currentTarget=i[s],this.notifyTarget(t,o)})}propagationPath(t){const e=[t];for(let i=0;i<QT&&t!==this.rootTarget;i++){if(!t.parent)throw new Error("Cannot find propagation path to disconnected target");e.push(t.parent),t=t.parent}return e.reverse(),e}hitTestMoveRecursive(t,e,i,n,s,o=!1){let a=!1;if(this._interactivePrune(t))return null;if((t.eventMode==="dynamic"||e==="dynamic")&&(Zr.pauseUpdate=!1),t.interactiveChildren&&t.children){const c=t.children;for(let u=c.length-1;u>=0;u--){const d=c[u],f=this.hitTestMoveRecursive(d,this._isInteractive(e)?e:d.eventMode,i,n,s,o||s(t,i));if(f){if(f.length>0&&!f[f.length-1].parent)continue;const p=t.isInteractive();(f.length>0||p)&&(p&&this._allInteractiveElements.push(t),f.push(t)),this._hitElements.length===0&&(this._hitElements=f),a=!0}}}const l=this._isInteractive(e),h=t.isInteractive();return l&&h&&this._allInteractiveElements.push(t),o||this._hitElements.length>0?null:a?this._hitElements:l&&!s(t,i)&&n(t,i)?h?[t]:[]:null}hitTestRecursive(t,e,i,n,s){if(this._interactivePrune(t)||s(t,i))return null;if((t.eventMode==="dynamic"||e==="dynamic")&&(Zr.pauseUpdate=!1),t.interactiveChildren&&t.children){const l=t.children;for(let h=l.length-1;h>=0;h--){const c=l[h],u=this.hitTestRecursive(c,this._isInteractive(e)?e:c.eventMode,i,n,s);if(u){if(u.length>0&&!u[u.length-1].parent)continue;const d=t.isInteractive();return(u.length>0||d)&&u.push(t),u}}}const o=this._isInteractive(e),a=t.isInteractive();return o&&n(t,i)?a?[t]:[]:null}_isInteractive(t){return t==="static"||t==="dynamic"}_interactivePrune(t){return!!(!t||t.isMask||!t.visible||!t.renderable||t.eventMode==="none"||t.eventMode==="passive"&&!t.interactiveChildren||t.isMask)}hitPruneFn(t,e){var i;if(t.hitArea&&(t.worldTransform.applyInverse(e,bh),!t.hitArea.contains(bh.x,bh.y)))return!0;if(t._mask){const n=t._mask.isMaskData?t._mask.maskObject:t._mask;if(n&&!((i=n.containsPoint)!=null&&i.call(n,e)))return!0}return!1}hitTestFn(t,e){return t.eventMode==="passive"?!1:t.hitArea?!0:t.containsPoint?t.containsPoint(e):!1}notifyTarget(t,e){var s,o;e=e??t.type;const i=`on${e}`;(o=(s=t.currentTarget)[i])==null||o.call(s,t);const n=t.eventPhase===t.CAPTURING_PHASE||t.eventPhase===t.AT_TARGET?`${e}capture`:e;this.notifyListeners(t,n),t.eventPhase===t.AT_TARGET&&this.notifyListeners(t,e)}mapPointerDown(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.createPointerEvent(t);if(this.dispatchEvent(e,"pointerdown"),e.pointerType==="touch")this.dispatchEvent(e,"touchstart");else if(e.pointerType==="mouse"||e.pointerType==="pen"){const n=e.button===2;this.dispatchEvent(e,n?"rightdown":"mousedown")}const i=this.trackingData(t.pointerId);i.pressTargetsByButton[t.button]=e.composedPath(),this.freeEvent(e)}mapPointerMove(t){var l,h;if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const e=this.createPointerEvent(t);this._isPointerMoveEvent=!1;const i=e.pointerType==="mouse"||e.pointerType==="pen",n=this.trackingData(t.pointerId),s=this.findMountedTarget(n.overTargets);if(((l=n.overTargets)==null?void 0:l.length)>0&&s!==e.target){const c=t.type==="mousemove"?"mouseout":"pointerout",u=this.createPointerEvent(t,c,s);if(this.dispatchEvent(u,"pointerout"),i&&this.dispatchEvent(u,"mouseout"),!e.composedPath().includes(s)){const d=this.createPointerEvent(t,"pointerleave",s);for(d.eventPhase=d.AT_TARGET;d.target&&!e.composedPath().includes(d.target);)d.currentTarget=d.target,this.notifyTarget(d),i&&this.notifyTarget(d,"mouseleave"),d.target=d.target.parent;this.freeEvent(d)}this.freeEvent(u)}if(s!==e.target){const c=t.type==="mousemove"?"mouseover":"pointerover",u=this.clonePointerEvent(e,c);this.dispatchEvent(u,"pointerover"),i&&this.dispatchEvent(u,"mouseover");let d=s==null?void 0:s.parent;for(;d&&d!==this.rootTarget.parent&&d!==e.target;)d=d.parent;if(!d||d===this.rootTarget.parent){const f=this.clonePointerEvent(e,"pointerenter");for(f.eventPhase=f.AT_TARGET;f.target&&f.target!==s&&f.target!==this.rootTarget.parent;)f.currentTarget=f.target,this.notifyTarget(f),i&&this.notifyTarget(f,"mouseenter"),f.target=f.target.parent;this.freeEvent(f)}this.freeEvent(u)}const o=[],a=this.enableGlobalMoveEvents??!0;this.moveOnAll?o.push("pointermove"):this.dispatchEvent(e,"pointermove"),a&&o.push("globalpointermove"),e.pointerType==="touch"&&(this.moveOnAll?o.splice(1,0,"touchmove"):this.dispatchEvent(e,"touchmove"),a&&o.push("globaltouchmove")),i&&(this.moveOnAll?o.splice(1,0,"mousemove"):this.dispatchEvent(e,"mousemove"),a&&o.push("globalmousemove"),this.cursor=(h=e.target)==null?void 0:h.cursor),o.length>0&&this.all(e,o),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=e.composedPath(),this.freeEvent(e)}mapPointerOver(t){var o;if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.trackingData(t.pointerId),i=this.createPointerEvent(t),n=i.pointerType==="mouse"||i.pointerType==="pen";this.dispatchEvent(i,"pointerover"),n&&this.dispatchEvent(i,"mouseover"),i.pointerType==="mouse"&&(this.cursor=(o=i.target)==null?void 0:o.cursor);const s=this.clonePointerEvent(i,"pointerenter");for(s.eventPhase=s.AT_TARGET;s.target&&s.target!==this.rootTarget.parent;)s.currentTarget=s.target,this.notifyTarget(s),n&&this.notifyTarget(s,"mouseenter"),s.target=s.target.parent;e.overTargets=i.composedPath(),this.freeEvent(i),this.freeEvent(s)}mapPointerOut(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.trackingData(t.pointerId);if(e.overTargets){const i=t.pointerType==="mouse"||t.pointerType==="pen",n=this.findMountedTarget(e.overTargets),s=this.createPointerEvent(t,"pointerout",n);this.dispatchEvent(s),i&&this.dispatchEvent(s,"mouseout");const o=this.createPointerEvent(t,"pointerleave",n);for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),i&&this.notifyTarget(o,"mouseleave"),o.target=o.target.parent;e.overTargets=null,this.freeEvent(s),this.freeEvent(o)}this.cursor=null}mapPointerUp(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=performance.now(),i=this.createPointerEvent(t);if(this.dispatchEvent(i,"pointerup"),i.pointerType==="touch")this.dispatchEvent(i,"touchend");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const a=i.button===2;this.dispatchEvent(i,a?"rightup":"mouseup")}const n=this.trackingData(t.pointerId),s=this.findMountedTarget(n.pressTargetsByButton[t.button]);let o=s;if(s&&!i.composedPath().includes(s)){let a=s;for(;a&&!i.composedPath().includes(a);){if(i.currentTarget=a,this.notifyTarget(i,"pointerupoutside"),i.pointerType==="touch")this.notifyTarget(i,"touchendoutside");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const l=i.button===2;this.notifyTarget(i,l?"rightupoutside":"mouseupoutside")}a=a.parent}delete n.pressTargetsByButton[t.button],o=a}if(o){const a=this.clonePointerEvent(i,"click");a.target=o,a.path=null,n.clicksByButton[t.button]||(n.clicksByButton[t.button]={clickCount:0,target:a.target,timeStamp:e});const l=n.clicksByButton[t.button];if(l.target===a.target&&e-l.timeStamp<200?++l.clickCount:l.clickCount=1,l.target=a.target,l.timeStamp=e,a.detail=l.clickCount,a.pointerType==="mouse"){const h=a.button===2;this.dispatchEvent(a,h?"rightclick":"click")}else a.pointerType==="touch"&&this.dispatchEvent(a,"tap");this.dispatchEvent(a,"pointertap"),this.freeEvent(a)}this.freeEvent(i)}mapPointerUpOutside(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.trackingData(t.pointerId),i=this.findMountedTarget(e.pressTargetsByButton[t.button]),n=this.createPointerEvent(t);if(i){let s=i;for(;s;)n.currentTarget=s,this.notifyTarget(n,"pointerupoutside"),n.pointerType==="touch"?this.notifyTarget(n,"touchendoutside"):(n.pointerType==="mouse"||n.pointerType==="pen")&&this.notifyTarget(n,n.button===2?"rightupoutside":"mouseupoutside"),s=s.parent;delete e.pressTargetsByButton[t.button]}this.freeEvent(n)}mapWheel(t){if(!(t instanceof yn)){console.warn("EventBoundary cannot map a non-wheel event as a wheel event");return}const e=this.createWheelEvent(t);this.dispatchEvent(e),this.freeEvent(e)}findMountedTarget(t){if(!t)return null;let e=t[0];for(let i=1;i<t.length&&t[i].parent===e;i++)e=t[i];return e}createPointerEvent(t,e,i){const n=this.allocateEvent(Je);return this.copyPointerData(t,n),this.copyMouseData(t,n),this.copyData(t,n),n.nativeEvent=t.nativeEvent,n.originalEvent=t,n.target=i??this.hitTest(n.global.x,n.global.y)??this._hitElements[0],typeof e=="string"&&(n.type=e),n}createWheelEvent(t){const e=this.allocateEvent(yn);return this.copyWheelData(t,e),this.copyMouseData(t,e),this.copyData(t,e),e.nativeEvent=t.nativeEvent,e.originalEvent=t,e.target=this.hitTest(e.global.x,e.global.y),e}clonePointerEvent(t,e){const i=this.allocateEvent(Je);return i.nativeEvent=t.nativeEvent,i.originalEvent=t.originalEvent,this.copyPointerData(t,i),this.copyMouseData(t,i),this.copyData(t,i),i.target=t.target,i.path=t.composedPath().slice(),i.type=e??i.type,i}copyWheelData(t,e){e.deltaMode=t.deltaMode,e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ}copyPointerData(t,e){t instanceof Je&&e instanceof Je&&(e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist)}copyMouseData(t,e){t instanceof Ro&&e instanceof Ro&&(e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.copyFrom(t.client),e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.copyFrom(t.movement),e.screen.copyFrom(t.screen),e.shiftKey=t.shiftKey,e.global.copyFrom(t.global))}copyData(t,e){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.detail=t.detail,e.view=t.view,e.which=t.which,e.layer.copyFrom(t.layer),e.page.copyFrom(t.page)}trackingData(t){return this.mappingState.trackingData[t]||(this.mappingState.trackingData[t]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[t]}allocateEvent(t){this.eventPool.has(t)||this.eventPool.set(t,[]);const e=this.eventPool.get(t).pop()||new t(this);return e.eventPhase=e.NONE,e.currentTarget=null,e.path=null,e.target=null,e}freeEvent(t){if(t.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const e=t.constructor;this.eventPool.has(e)||this.eventPool.set(e,[]),this.eventPool.get(e).push(t)}notifyListeners(t,e){const i=t.currentTarget._events[e];if(i&&t.currentTarget.isInteractive())if("fn"in i)i.once&&t.currentTarget.removeListener(e,i.fn,void 0,!0),i.fn.call(i.context,t);else for(let n=0,s=i.length;n<s&&!t.propagationImmediatelyStopped;n++)i[n].once&&t.currentTarget.removeListener(e,i[n].fn,void 0,!0),i[n].fn.call(i[n].context,t)}}const rA=1,iA={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},xh=class Jh{constructor(t){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=t,this.rootBoundary=new eA(null),Zr.init(this),this.autoPreventDefault=!0,this.eventsAdded=!1,this.rootPointerEvent=new Je(null),this.rootWheelEvent=new yn(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...Jh.defaultEventFeatures},{set:(e,i,n)=>(i==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=n),e[i]=n,!0)}),this.onPointerDown=this.onPointerDown.bind(this),this.onPointerMove=this.onPointerMove.bind(this),this.onPointerUp=this.onPointerUp.bind(this),this.onPointerOverOut=this.onPointerOverOut.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(t){const{view:e,resolution:i}=this.renderer;this.setTargetElement(e),this.resolution=i,Jh._defaultEventMode=t.eventMode??"auto",Object.assign(this.features,t.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(t){this.resolution=t}destroy(){this.setTargetElement(null),this.renderer=null}setCursor(t){t=t||"default";let e=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(e=!1),this.currentCursor===t)return;this.currentCursor=t;const i=this.cursorStyles[t];if(i)switch(typeof i){case"string":e&&(this.domElement.style.cursor=i);break;case"function":i(t);break;case"object":e&&Object.assign(this.domElement.style,i);break}else e&&typeof t=="string"&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,t)&&(this.domElement.style.cursor=t)}get pointer(){return this.rootPointerEvent}onPointerDown(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);this.autoPreventDefault&&e[0].isNormalized&&(t.cancelable||!("cancelable"in t))&&t.preventDefault();for(let i=0,n=e.length;i<n;i++){const s=e[i],o=this.bootstrapEvent(this.rootPointerEvent,s);this.rootBoundary.mapEvent(o)}this.setCursor(this.rootBoundary.cursor)}onPointerMove(t){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,Zr.pointerMoved();const e=this.normalizeToPointerData(t);for(let i=0,n=e.length;i<n;i++){const s=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onPointerUp(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let e=t.target;t.composedPath&&t.composedPath().length>0&&(e=t.composedPath()[0]);const i=e!==this.domElement?"outside":"",n=this.normalizeToPointerData(t);for(let s=0,o=n.length;s<o;s++){const a=this.bootstrapEvent(this.rootPointerEvent,n[s]);a.type+=i,this.rootBoundary.mapEvent(a)}this.setCursor(this.rootBoundary.cursor)}onPointerOverOut(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);for(let i=0,n=e.length;i<n;i++){const s=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onWheel(t){if(!this.features.wheel)return;const e=this.normalizeWheelEvent(t);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(e)}setTargetElement(t){this.removeEvents(),this.domElement=t,Zr.domElement=t,this.addEvents()}addEvents(){if(this.eventsAdded||!this.domElement)return;Zr.addTickerListener();const t=this.domElement.style;t&&(globalThis.navigator.msPointerEnabled?(t.msContentZooming="none",t.msTouchAction="none"):this.supportsPointerEvents&&(t.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this.onPointerMove,!0),this.domElement.addEventListener("pointerdown",this.onPointerDown,!0),this.domElement.addEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this.onPointerOverOut,!0),globalThis.addEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this.onPointerMove,!0),this.domElement.addEventListener("mousedown",this.onPointerDown,!0),this.domElement.addEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this.onPointerOverOut,!0),globalThis.addEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this.onPointerDown,!0),this.domElement.addEventListener("touchend",this.onPointerUp,!0),this.domElement.addEventListener("touchmove",this.onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this.eventsAdded=!0}removeEvents(){if(!this.eventsAdded||!this.domElement)return;Zr.removeTickerListener();const t=this.domElement.style;globalThis.navigator.msPointerEnabled?(t.msContentZooming="",t.msTouchAction=""):this.supportsPointerEvents&&(t.touchAction=""),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this.onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this.onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this.onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this.onPointerMove,!0),this.domElement.removeEventListener("mousedown",this.onPointerDown,!0),this.domElement.removeEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this.onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this.onPointerDown,!0),this.domElement.removeEventListener("touchend",this.onPointerUp,!0),this.domElement.removeEventListener("touchmove",this.onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement=null,this.eventsAdded=!1}mapPositionToPoint(t,e,i){const n=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},s=1/this.resolution;t.x=(e-n.left)*(this.domElement.width/n.width)*s,t.y=(i-n.top)*(this.domElement.height/n.height)*s}normalizeToPointerData(t){const e=[];if(this.supportsTouchEvents&&t instanceof TouchEvent)for(let i=0,n=t.changedTouches.length;i<n;i++){const s=t.changedTouches[i];typeof s.button>"u"&&(s.button=0),typeof s.buttons>"u"&&(s.buttons=1),typeof s.isPrimary>"u"&&(s.isPrimary=t.touches.length===1&&t.type==="touchstart"),typeof s.width>"u"&&(s.width=s.radiusX||1),typeof s.height>"u"&&(s.height=s.radiusY||1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="touch"),typeof s.pointerId>"u"&&(s.pointerId=s.identifier||0),typeof s.pressure>"u"&&(s.pressure=s.force||.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),typeof s.layerX>"u"&&(s.layerX=s.offsetX=s.clientX),typeof s.layerY>"u"&&(s.layerY=s.offsetY=s.clientY),s.isNormalized=!0,s.type=t.type,e.push(s)}else if(!globalThis.MouseEvent||t instanceof MouseEvent&&(!this.supportsPointerEvents||!(t instanceof globalThis.PointerEvent))){const i=t;typeof i.isPrimary>"u"&&(i.isPrimary=!0),typeof i.width>"u"&&(i.width=1),typeof i.height>"u"&&(i.height=1),typeof i.tiltX>"u"&&(i.tiltX=0),typeof i.tiltY>"u"&&(i.tiltY=0),typeof i.pointerType>"u"&&(i.pointerType="mouse"),typeof i.pointerId>"u"&&(i.pointerId=rA),typeof i.pressure>"u"&&(i.pressure=.5),typeof i.twist>"u"&&(i.twist=0),typeof i.tangentialPressure>"u"&&(i.tangentialPressure=0),i.isNormalized=!0,e.push(i)}else e.push(t);return e}normalizeWheelEvent(t){const e=this.rootWheelEvent;return this.transferMouseData(e,t),e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ,e.deltaMode=t.deltaMode,this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.nativeEvent=t,e.type=t.type,e}bootstrapEvent(t,e){return t.originalEvent=null,t.nativeEvent=e,t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist,this.transferMouseData(t,e),this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.isTrusted=e.isTrusted,t.type==="pointerleave"&&(t.type="pointerout"),t.type.startsWith("mouse")&&(t.type=t.type.replace("mouse","pointer")),t.type.startsWith("touch")&&(t.type=iA[t.type]||t.type),t}transferMouseData(t,e){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.x=e.clientX,t.client.y=e.clientY,t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.x=e.movementX,t.movement.y=e.movementY,t.page.x=e.pageX,t.page.y=e.pageY,t.relatedTarget=null,t.shiftKey=e.shiftKey}};xh.extension={name:"events",type:[K.RendererSystem,K.CanvasRendererSystem]},xh.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let wh=xh;ut.add(wh);function Jp(r){return r==="dynamic"||r==="static"}const nA={onclick:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,_internalInteractive:void 0,get interactive(){return this._internalInteractive??Jp(wh.defaultEventMode)},set interactive(r){St("7.2.0","Setting interactive is deprecated, use eventMode = 'none'/'passive'/'auto'/'static'/'dynamic' instead."),this._internalInteractive=r,this.eventMode=r?"static":"auto"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??wh.defaultEventMode},set eventMode(r){this._internalInteractive=Jp(r),this._internalEventMode=r},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(r,t,e){const i=typeof e=="boolean"&&e||typeof e=="object"&&e.capture,n=typeof e=="object"?e.signal:void 0,s=typeof e=="object"?e.once===!0:!1,o=typeof t=="function"?void 0:t;r=i?`${r}capture`:r;const a=typeof t=="function"?t:t.handleEvent,l=this;n&&n.addEventListener("abort",()=>{l.off(r,a,o)}),s?l.once(r,a,o):l.on(r,a,o)},removeEventListener(r,t,e){const i=typeof e=="boolean"&&e||typeof e=="object"&&e.capture,n=typeof t=="function"?void 0:t;r=i?`${r}capture`:r,t=typeof t=="function"?t:t.handleEvent,this.off(r,t,n)},dispatchEvent(r){if(!(r instanceof ds))throw new Error("DisplayObject cannot propagate events outside of the Federated Events API");return r.defaultPrevented=!1,r.path=null,r.target=this,r.manager.dispatchEvent(r),!r.defaultPrevented}};Xt.mixin(nA);const sA={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,_accessibleActive:!1,_accessibleDiv:null,accessibleType:"button",accessiblePointerEvents:"auto",accessibleChildren:!0,renderId:-1};Xt.mixin(sA);const oA=9,Mo=100,aA=0,lA=0,Qp=2,tm=1,hA=-1e3,cA=-1e3,uA=2;class em{constructor(t){this.debug=!1,this._isActive=!1,this._isMobileAccessibility=!1,this.pool=[],this.renderId=0,this.children=[],this.androidUpdateCount=0,this.androidUpdateFrequency=500,this._hookDiv=null,(wr.tablet||wr.phone)&&this.createTouchHook();const e=document.createElement("div");e.style.width=`${Mo}px`,e.style.height=`${Mo}px`,e.style.position="absolute",e.style.top=`${aA}px`,e.style.left=`${lA}px`,e.style.zIndex=Qp.toString(),this.div=e,this.renderer=t,this._onKeyDown=this._onKeyDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),globalThis.addEventListener("keydown",this._onKeyDown,!1)}get isActive(){return this._isActive}get isMobileAccessibility(){return this._isMobileAccessibility}createTouchHook(){const t=document.createElement("button");t.style.width=`${tm}px`,t.style.height=`${tm}px`,t.style.position="absolute",t.style.top=`${hA}px`,t.style.left=`${cA}px`,t.style.zIndex=uA.toString(),t.style.backgroundColor="#FF0000",t.title="select to enable accessibility for this content",t.addEventListener("focus",()=>{this._isMobileAccessibility=!0,this.activate(),this.destroyTouchHook()}),document.body.appendChild(t),this._hookDiv=t}destroyTouchHook(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)}activate(){var t;this._isActive||(this._isActive=!0,globalThis.document.addEventListener("mousemove",this._onMouseMove,!0),globalThis.removeEventListener("keydown",this._onKeyDown,!1),this.renderer.on("postrender",this.update,this),(t=this.renderer.view.parentNode)==null||t.appendChild(this.div))}deactivate(){var t;!this._isActive||this._isMobileAccessibility||(this._isActive=!1,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),globalThis.addEventListener("keydown",this._onKeyDown,!1),this.renderer.off("postrender",this.update),(t=this.div.parentNode)==null||t.removeChild(this.div))}updateAccessibleObjects(t){if(!t.visible||!t.accessibleChildren)return;t.accessible&&t.isInteractive()&&(t._accessibleActive||this.addChild(t),t.renderId=this.renderId);const e=t.children;if(e)for(let i=0;i<e.length;i++)this.updateAccessibleObjects(e[i])}update(){const t=performance.now();if(wr.android.device&&t<this.androidUpdateCount||(this.androidUpdateCount=t+this.androidUpdateFrequency,!this.renderer.renderingToScreen))return;this.renderer.lastObjectRendered&&this.updateAccessibleObjects(this.renderer.lastObjectRendered);const{x:e,y:i,width:n,height:s}=this.renderer.view.getBoundingClientRect(),{width:o,height:a,resolution:l}=this.renderer,h=n/o*l,c=s/a*l;let u=this.div;u.style.left=`${e}px`,u.style.top=`${i}px`,u.style.width=`${o}px`,u.style.height=`${a}px`;for(let d=0;d<this.children.length;d++){const f=this.children[d];if(f.renderId!==this.renderId)f._accessibleActive=!1,dn(this.children,d,1),this.div.removeChild(f._accessibleDiv),this.pool.push(f._accessibleDiv),f._accessibleDiv=null,d--;else{u=f._accessibleDiv;let p=f.hitArea;const g=f.worldTransform;f.hitArea?(u.style.left=`${(g.tx+p.x*g.a)*h}px`,u.style.top=`${(g.ty+p.y*g.d)*c}px`,u.style.width=`${p.width*g.a*h}px`,u.style.height=`${p.height*g.d*c}px`):(p=f.getBounds(),this.capHitArea(p),u.style.left=`${p.x*h}px`,u.style.top=`${p.y*c}px`,u.style.width=`${p.width*h}px`,u.style.height=`${p.height*c}px`,u.title!==f.accessibleTitle&&f.accessibleTitle!==null&&(u.title=f.accessibleTitle),u.getAttribute("aria-label")!==f.accessibleHint&&f.accessibleHint!==null&&u.setAttribute("aria-label",f.accessibleHint)),(f.accessibleTitle!==u.title||f.tabIndex!==u.tabIndex)&&(u.title=f.accessibleTitle,u.tabIndex=f.tabIndex,this.debug&&this.updateDebugHTML(u))}}this.renderId++}updateDebugHTML(t){t.innerHTML=`type: ${t.type}</br> title : ${t.title}</br> tabIndex: ${t.tabIndex}`}capHitArea(t){t.x<0&&(t.width+=t.x,t.x=0),t.y<0&&(t.height+=t.y,t.y=0);const{width:e,height:i}=this.renderer;t.x+t.width>e&&(t.width=e-t.x),t.y+t.height>i&&(t.height=i-t.y)}addChild(t){let e=this.pool.pop();e||(e=document.createElement("button"),e.style.width=`${Mo}px`,e.style.height=`${Mo}px`,e.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",e.style.position="absolute",e.style.zIndex=Qp.toString(),e.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?e.setAttribute("aria-live","off"):e.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?e.setAttribute("aria-relevant","additions"):e.setAttribute("aria-relevant","text"),e.addEventListener("click",this._onClick.bind(this)),e.addEventListener("focus",this._onFocus.bind(this)),e.addEventListener("focusout",this._onFocusOut.bind(this))),e.style.pointerEvents=t.accessiblePointerEvents,e.type=t.accessibleType,t.accessibleTitle&&t.accessibleTitle!==null?e.title=t.accessibleTitle:(!t.accessibleHint||t.accessibleHint===null)&&(e.title=`displayObject ${t.tabIndex}`),t.accessibleHint&&t.accessibleHint!==null&&e.setAttribute("aria-label",t.accessibleHint),this.debug&&this.updateDebugHTML(e),t._accessibleActive=!0,t._accessibleDiv=e,e.displayObject=t,this.children.push(t),this.div.appendChild(t._accessibleDiv),t._accessibleDiv.tabIndex=t.tabIndex}_dispatchEvent(t,e){const{displayObject:i}=t.target,n=this.renderer.events.rootBoundary,s=Object.assign(new ds(n),{target:i});n.rootTarget=this.renderer.lastObjectRendered,e.forEach(o=>n.dispatchEvent(s,o))}_onClick(t){this._dispatchEvent(t,["click","pointertap","tap"])}_onFocus(t){t.target.getAttribute("aria-live")||t.target.setAttribute("aria-live","assertive"),this._dispatchEvent(t,["mouseover"])}_onFocusOut(t){t.target.getAttribute("aria-live")||t.target.setAttribute("aria-live","polite"),this._dispatchEvent(t,["mouseout"])}_onKeyDown(t){t.keyCode===oA&&this.activate()}_onMouseMove(t){t.movementX===0&&t.movementY===0||this.deactivate()}destroy(){this.destroyTouchHook(),this.div=null,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),globalThis.removeEventListener("keydown",this._onKeyDown),this.pool=null,this.children=null,this.renderer=null}}em.extension={name:"accessibility",type:[K.RendererPlugin,K.CanvasRendererPlugin]},ut.add(em);const rm=class Qh{constructor(t){this.stage=new Ze,t=Object.assign({forceCanvas:!1},t),this.renderer=$p(t),Qh._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render(this.stage)}get view(){var t;return(t=this.renderer)==null?void 0:t.view}get screen(){var t;return(t=this.renderer)==null?void 0:t.screen}destroy(t,e){const i=Qh._plugins.slice(0);i.reverse(),i.forEach(n=>{n.destroy.call(this)}),this.stage.destroy(e),this.stage=null,this.renderer.destroy(t),this.renderer=null}};rm._plugins=[];let dA=rm;ut.handleByList(K.Application,dA._plugins);class im{static init(t){Object.defineProperty(this,"resizeTo",{set(e){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this.cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this.cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this.cancelResize();let e,i;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:n,clientHeight:s}=this._resizeTo;e=n,i=s}this.renderer.resize(e,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this.cancelResize(),this.cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}im.extension=K.Application,ut.add(im);const nm={loader:K.LoadParser,resolver:K.ResolveParser,cache:K.CacheParser,detection:K.DetectionParser};ut.handle(K.Asset,r=>{const t=r.ref;Object.entries(nm).filter(([e])=>!!t[e]).forEach(([e,i])=>ut.add(Object.assign(t[e],{extension:t[e].extension??i})))},r=>{const t=r.ref;Object.keys(nm).filter(e=>!!t[e]).forEach(e=>ut.remove(t[e]))});class fA{constructor(t,e=!1){this._loader=t,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=e}add(t){t.forEach(e=>{this._assetList.push(e)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const t=[],e=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<e;i++)t.push(this._assetList.pop());await this._loader.load(t),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(t){this._isActive!==t&&(this._isActive=t,t&&!this._isLoading&&this._next())}}function _n(r,t){if(Array.isArray(t)){for(const e of t)if(r.startsWith(`data:${e}`))return!0;return!1}return r.startsWith(`data:${t}`)}function Jr(r,t){const e=r.split("?")[0],i=ue.extname(e).toLowerCase();return Array.isArray(t)?t.includes(i):i===t}const Qe=(r,t,e=!1)=>(Array.isArray(r)||(r=[r]),t?r.map(i=>typeof i=="string"||e?t(i):i):r),Eh=(r,t)=>{const e=t.split("?")[1];return e&&(r+=`?${e}`),r};function sm(r,t,e,i,n){const s=t[e];for(let o=0;o<s.length;o++){const a=s[o];e<t.length-1?sm(r.replace(i[e],a),t,e+1,i,n):n.push(r.replace(i[e],a))}}function pA(r){const t=/\{(.*?)\}/g,e=r.match(t),i=[];if(e){const n=[];e.forEach(s=>{const o=s.substring(1,s.length-1).split(",");n.push(o)}),sm(r,n,0,e,i)}else i.push(r);return i}const Oo=r=>!Array.isArray(r);class mA{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(t){return this._cache.has(t)}get(t){const e=this._cache.get(t);return e||console.warn(`[Assets] Asset id ${t} was not found in the Cache`),e}set(t,e){const i=Qe(t);let n;for(let a=0;a<this.parsers.length;a++){const l=this.parsers[a];if(l.test(e)){n=l.getCacheableAssets(i,e);break}}n||(n={},i.forEach(a=>{n[a]=e}));const s=Object.keys(n),o={cacheKeys:s,keys:i};if(i.forEach(a=>{this._cacheMap.set(a,o)}),s.forEach(a=>{const l=n?n[a]:e;this._cache.has(a)&&this._cache.get(a)!==l&&console.warn("[Cache] already has key:",a),this._cache.set(a,n[a])}),e instanceof dt){const a=e;i.forEach(l=>{a.baseTexture!==dt.EMPTY.baseTexture&&xt.addToCache(a.baseTexture,l),dt.addToCache(a,l)})}}remove(t){if(!this._cacheMap.has(t)){console.warn(`[Assets] Asset id ${t} was not found in the Cache`);return}const e=this._cacheMap.get(t);e.cacheKeys.forEach(i=>{this._cache.delete(i)}),e.keys.forEach(i=>{this._cacheMap.delete(i)})}get parsers(){return this._parsers}}const Ri=new mA;class gA{constructor(){this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(t,e,i)=>(this._parsersValidated=!1,t[e]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(t,e){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let n=null,s=null;if(e.loadParser&&(s=this._parserHash[e.loadParser],s||console.warn(`[Assets] specified load parser "${e.loadParser}" not found while loading ${t}`)),!s){for(let l=0;l<this.parsers.length;l++){const h=this.parsers[l];if(h.load&&((o=h.test)!=null&&o.call(h,t,e,this))){s=h;break}}if(!s)return console.warn(`[Assets] ${t} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}n=await s.load(t,e,this),i.parser=s;for(let l=0;l<this.parsers.length;l++){const h=this.parsers[l];h.parse&&h.parse&&await((a=h.testParse)==null?void 0:a.call(h,n,e,this))&&(n=await h.parse(n,e,this)||n,i.parser=h)}return n})(),i}async load(t,e){this._parsersValidated||this._validateParsers();let i=0;const n={},s=Oo(t),o=Qe(t,h=>({alias:[h],src:h})),a=o.length,l=o.map(async h=>{const c=ue.toAbsolute(h.src);if(!n[h.src])try{this.promiseCache[c]||(this.promiseCache[c]=this._getLoadPromiseAndParser(c,h)),n[h.src]=await this.promiseCache[c].promise,e&&e(++i/a)}catch(u){throw delete this.promiseCache[c],delete n[h.src],new Error(`[Loader.load] Failed to load ${c}.
866
+ `;class ZT extends Re{constructor(t=.5,e=Math.random()){super(Hp,KT,{uNoise:0,uSeed:0}),this.noise=t,this.seed=e}get noise(){return this.uniforms.uNoise}set noise(t){this.uniforms.uNoise=t}get seed(){return this.uniforms.uSeed}set seed(t){this.uniforms.uSeed=t}}const Zp={AlphaFilter:NT,BlurFilter:HT,BlurFilterPass:_h,ColorMatrixFilter:vh,DisplacementFilter:WT,FXAAFilter:qT,NoiseFilter:ZT};Object.entries(Zp).forEach(([r,t])=>{Object.defineProperty(Zp,r,{get(){return St("7.1.0",`filters.${r} has moved to ${r}`),t}})});class JT{constructor(){this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}init(t){this.removeTickerListener(),this.events=t,this.interactionFrequency=10,this._deltaTime=0,this._didMove=!1,this.tickerAdded=!1,this._pauseUpdate=!0}get pauseUpdate(){return this._pauseUpdate}set pauseUpdate(t){this._pauseUpdate=t}addTickerListener(){this.tickerAdded||!this.domElement||(ke.system.add(this.tickerUpdate,this,Pi.INTERACTION),this.tickerAdded=!0)}removeTickerListener(){this.tickerAdded&&(ke.system.remove(this.tickerUpdate,this),this.tickerAdded=!1)}pointerMoved(){this._didMove=!0}update(){if(!this.domElement||this._pauseUpdate)return;if(this._didMove){this._didMove=!1;return}const t=this.events.rootPointerEvent;this.events.supportsTouchEvents&&t.pointerType==="touch"||globalThis.document.dispatchEvent(new PointerEvent("pointermove",{clientX:t.clientX,clientY:t.clientY}))}tickerUpdate(t){this._deltaTime+=t,!(this._deltaTime<this.interactionFrequency)&&(this._deltaTime=0,this.update())}}const Zr=new JT;class ds{constructor(t){this.bubbles=!0,this.cancelBubble=!0,this.cancelable=!1,this.composed=!1,this.defaultPrevented=!1,this.eventPhase=ds.prototype.NONE,this.propagationStopped=!1,this.propagationImmediatelyStopped=!1,this.layer=new It,this.page=new It,this.NONE=0,this.CAPTURING_PHASE=1,this.AT_TARGET=2,this.BUBBLING_PHASE=3,this.manager=t}get layerX(){return this.layer.x}get layerY(){return this.layer.y}get pageX(){return this.page.x}get pageY(){return this.page.y}get data(){return this}composedPath(){return this.manager&&(!this.path||this.path[this.path.length-1]!==this.target)&&(this.path=this.target?this.manager.propagationPath(this.target):[]),this.path}initEvent(t,e,i){throw new Error("initEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}initUIEvent(t,e,i,n,s){throw new Error("initUIEvent() is a legacy DOM API. It is not implemented in the Federated Events API.")}preventDefault(){this.nativeEvent instanceof Event&&this.nativeEvent.cancelable&&this.nativeEvent.preventDefault(),this.defaultPrevented=!0}stopImmediatePropagation(){this.propagationImmediatelyStopped=!0}stopPropagation(){this.propagationStopped=!0}}class Ro extends ds{constructor(){super(...arguments),this.client=new It,this.movement=new It,this.offset=new It,this.global=new It,this.screen=new It}get clientX(){return this.client.x}get clientY(){return this.client.y}get x(){return this.clientX}get y(){return this.clientY}get movementX(){return this.movement.x}get movementY(){return this.movement.y}get offsetX(){return this.offset.x}get offsetY(){return this.offset.y}get globalX(){return this.global.x}get globalY(){return this.global.y}get screenX(){return this.screen.x}get screenY(){return this.screen.y}getLocalPosition(t,e,i){return t.worldTransform.applyInverse(i||this.global,e)}getModifierState(t){return"getModifierState"in this.nativeEvent&&this.nativeEvent.getModifierState(t)}initMouseEvent(t,e,i,n,s,o,a,l,h,c,u,d,f,p,g){throw new Error("Method not implemented.")}}class Je extends Ro{constructor(){super(...arguments),this.width=0,this.height=0,this.isPrimary=!1}getCoalescedEvents(){return this.type==="pointermove"||this.type==="mousemove"||this.type==="touchmove"?[this]:[]}getPredictedEvents(){throw new Error("getPredictedEvents is not supported!")}}class yn extends Ro{constructor(){super(...arguments),this.DOM_DELTA_PIXEL=0,this.DOM_DELTA_LINE=1,this.DOM_DELTA_PAGE=2}}yn.DOM_DELTA_PIXEL=0,yn.DOM_DELTA_LINE=1,yn.DOM_DELTA_PAGE=2;const QT=2048,tA=new It,bh=new It;class eA{constructor(t){this.dispatch=new Vn,this.moveOnAll=!1,this.enableGlobalMoveEvents=!0,this.mappingState={trackingData:{}},this.eventPool=new Map,this._allInteractiveElements=[],this._hitElements=[],this._isPointerMoveEvent=!1,this.rootTarget=t,this.hitPruneFn=this.hitPruneFn.bind(this),this.hitTestFn=this.hitTestFn.bind(this),this.mapPointerDown=this.mapPointerDown.bind(this),this.mapPointerMove=this.mapPointerMove.bind(this),this.mapPointerOut=this.mapPointerOut.bind(this),this.mapPointerOver=this.mapPointerOver.bind(this),this.mapPointerUp=this.mapPointerUp.bind(this),this.mapPointerUpOutside=this.mapPointerUpOutside.bind(this),this.mapWheel=this.mapWheel.bind(this),this.mappingTable={},this.addEventMapping("pointerdown",this.mapPointerDown),this.addEventMapping("pointermove",this.mapPointerMove),this.addEventMapping("pointerout",this.mapPointerOut),this.addEventMapping("pointerleave",this.mapPointerOut),this.addEventMapping("pointerover",this.mapPointerOver),this.addEventMapping("pointerup",this.mapPointerUp),this.addEventMapping("pointerupoutside",this.mapPointerUpOutside),this.addEventMapping("wheel",this.mapWheel)}addEventMapping(t,e){this.mappingTable[t]||(this.mappingTable[t]=[]),this.mappingTable[t].push({fn:e,priority:0}),this.mappingTable[t].sort((i,n)=>i.priority-n.priority)}dispatchEvent(t,e){t.propagationStopped=!1,t.propagationImmediatelyStopped=!1,this.propagate(t,e),this.dispatch.emit(e||t.type,t)}mapEvent(t){if(!this.rootTarget)return;const e=this.mappingTable[t.type];if(e)for(let i=0,n=e.length;i<n;i++)e[i].fn(t);else console.warn(`[EventBoundary]: Event mapping not defined for ${t.type}`)}hitTest(t,e){Zr.pauseUpdate=!0;const i=this._isPointerMoveEvent&&this.enableGlobalMoveEvents?"hitTestMoveRecursive":"hitTestRecursive",n=this[i](this.rootTarget,this.rootTarget.eventMode,tA.set(t,e),this.hitTestFn,this.hitPruneFn);return n&&n[0]}propagate(t,e){if(!t.target)return;const i=t.composedPath();t.eventPhase=t.CAPTURING_PHASE;for(let n=0,s=i.length-1;n<s;n++)if(t.currentTarget=i[n],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return;if(t.eventPhase=t.AT_TARGET,t.currentTarget=t.target,this.notifyTarget(t,e),!(t.propagationStopped||t.propagationImmediatelyStopped)){t.eventPhase=t.BUBBLING_PHASE;for(let n=i.length-2;n>=0;n--)if(t.currentTarget=i[n],this.notifyTarget(t,e),t.propagationStopped||t.propagationImmediatelyStopped)return}}all(t,e,i=this._allInteractiveElements){if(i.length===0)return;t.eventPhase=t.BUBBLING_PHASE;const n=Array.isArray(e)?e:[e];for(let s=i.length-1;s>=0;s--)n.forEach(o=>{t.currentTarget=i[s],this.notifyTarget(t,o)})}propagationPath(t){const e=[t];for(let i=0;i<QT&&t!==this.rootTarget;i++){if(!t.parent)throw new Error("Cannot find propagation path to disconnected target");e.push(t.parent),t=t.parent}return e.reverse(),e}hitTestMoveRecursive(t,e,i,n,s,o=!1){let a=!1;if(this._interactivePrune(t))return null;if((t.eventMode==="dynamic"||e==="dynamic")&&(Zr.pauseUpdate=!1),t.interactiveChildren&&t.children){const c=t.children;for(let u=c.length-1;u>=0;u--){const d=c[u],f=this.hitTestMoveRecursive(d,this._isInteractive(e)?e:d.eventMode,i,n,s,o||s(t,i));if(f){if(f.length>0&&!f[f.length-1].parent)continue;const p=t.isInteractive();(f.length>0||p)&&(p&&this._allInteractiveElements.push(t),f.push(t)),this._hitElements.length===0&&(this._hitElements=f),a=!0}}}const l=this._isInteractive(e),h=t.isInteractive();return l&&h&&this._allInteractiveElements.push(t),o||this._hitElements.length>0?null:a?this._hitElements:l&&!s(t,i)&&n(t,i)?h?[t]:[]:null}hitTestRecursive(t,e,i,n,s){if(this._interactivePrune(t)||s(t,i))return null;if((t.eventMode==="dynamic"||e==="dynamic")&&(Zr.pauseUpdate=!1),t.interactiveChildren&&t.children){const l=t.children;for(let h=l.length-1;h>=0;h--){const c=l[h],u=this.hitTestRecursive(c,this._isInteractive(e)?e:c.eventMode,i,n,s);if(u){if(u.length>0&&!u[u.length-1].parent)continue;const d=t.isInteractive();return(u.length>0||d)&&u.push(t),u}}}const o=this._isInteractive(e),a=t.isInteractive();return o&&n(t,i)?a?[t]:[]:null}_isInteractive(t){return t==="static"||t==="dynamic"}_interactivePrune(t){return!!(!t||t.isMask||!t.visible||!t.renderable||t.eventMode==="none"||t.eventMode==="passive"&&!t.interactiveChildren||t.isMask)}hitPruneFn(t,e){var i;if(t.hitArea&&(t.worldTransform.applyInverse(e,bh),!t.hitArea.contains(bh.x,bh.y)))return!0;if(t._mask){const n=t._mask.isMaskData?t._mask.maskObject:t._mask;if(n&&!((i=n.containsPoint)!=null&&i.call(n,e)))return!0}return!1}hitTestFn(t,e){return t.eventMode==="passive"?!1:t.hitArea?!0:t.containsPoint?t.containsPoint(e):!1}notifyTarget(t,e){var s,o;e=e??t.type;const i=`on${e}`;(o=(s=t.currentTarget)[i])==null||o.call(s,t);const n=t.eventPhase===t.CAPTURING_PHASE||t.eventPhase===t.AT_TARGET?`${e}capture`:e;this.notifyListeners(t,n),t.eventPhase===t.AT_TARGET&&this.notifyListeners(t,e)}mapPointerDown(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.createPointerEvent(t);if(this.dispatchEvent(e,"pointerdown"),e.pointerType==="touch")this.dispatchEvent(e,"touchstart");else if(e.pointerType==="mouse"||e.pointerType==="pen"){const n=e.button===2;this.dispatchEvent(e,n?"rightdown":"mousedown")}const i=this.trackingData(t.pointerId);i.pressTargetsByButton[t.button]=e.composedPath(),this.freeEvent(e)}mapPointerMove(t){var l,h;if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}this._allInteractiveElements.length=0,this._hitElements.length=0,this._isPointerMoveEvent=!0;const e=this.createPointerEvent(t);this._isPointerMoveEvent=!1;const i=e.pointerType==="mouse"||e.pointerType==="pen",n=this.trackingData(t.pointerId),s=this.findMountedTarget(n.overTargets);if(((l=n.overTargets)==null?void 0:l.length)>0&&s!==e.target){const c=t.type==="mousemove"?"mouseout":"pointerout",u=this.createPointerEvent(t,c,s);if(this.dispatchEvent(u,"pointerout"),i&&this.dispatchEvent(u,"mouseout"),!e.composedPath().includes(s)){const d=this.createPointerEvent(t,"pointerleave",s);for(d.eventPhase=d.AT_TARGET;d.target&&!e.composedPath().includes(d.target);)d.currentTarget=d.target,this.notifyTarget(d),i&&this.notifyTarget(d,"mouseleave"),d.target=d.target.parent;this.freeEvent(d)}this.freeEvent(u)}if(s!==e.target){const c=t.type==="mousemove"?"mouseover":"pointerover",u=this.clonePointerEvent(e,c);this.dispatchEvent(u,"pointerover"),i&&this.dispatchEvent(u,"mouseover");let d=s==null?void 0:s.parent;for(;d&&d!==this.rootTarget.parent&&d!==e.target;)d=d.parent;if(!d||d===this.rootTarget.parent){const f=this.clonePointerEvent(e,"pointerenter");for(f.eventPhase=f.AT_TARGET;f.target&&f.target!==s&&f.target!==this.rootTarget.parent;)f.currentTarget=f.target,this.notifyTarget(f),i&&this.notifyTarget(f,"mouseenter"),f.target=f.target.parent;this.freeEvent(f)}this.freeEvent(u)}const o=[],a=this.enableGlobalMoveEvents??!0;this.moveOnAll?o.push("pointermove"):this.dispatchEvent(e,"pointermove"),a&&o.push("globalpointermove"),e.pointerType==="touch"&&(this.moveOnAll?o.splice(1,0,"touchmove"):this.dispatchEvent(e,"touchmove"),a&&o.push("globaltouchmove")),i&&(this.moveOnAll?o.splice(1,0,"mousemove"):this.dispatchEvent(e,"mousemove"),a&&o.push("globalmousemove"),this.cursor=(h=e.target)==null?void 0:h.cursor),o.length>0&&this.all(e,o),this._allInteractiveElements.length=0,this._hitElements.length=0,n.overTargets=e.composedPath(),this.freeEvent(e)}mapPointerOver(t){var o;if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.trackingData(t.pointerId),i=this.createPointerEvent(t),n=i.pointerType==="mouse"||i.pointerType==="pen";this.dispatchEvent(i,"pointerover"),n&&this.dispatchEvent(i,"mouseover"),i.pointerType==="mouse"&&(this.cursor=(o=i.target)==null?void 0:o.cursor);const s=this.clonePointerEvent(i,"pointerenter");for(s.eventPhase=s.AT_TARGET;s.target&&s.target!==this.rootTarget.parent;)s.currentTarget=s.target,this.notifyTarget(s),n&&this.notifyTarget(s,"mouseenter"),s.target=s.target.parent;e.overTargets=i.composedPath(),this.freeEvent(i),this.freeEvent(s)}mapPointerOut(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.trackingData(t.pointerId);if(e.overTargets){const i=t.pointerType==="mouse"||t.pointerType==="pen",n=this.findMountedTarget(e.overTargets),s=this.createPointerEvent(t,"pointerout",n);this.dispatchEvent(s),i&&this.dispatchEvent(s,"mouseout");const o=this.createPointerEvent(t,"pointerleave",n);for(o.eventPhase=o.AT_TARGET;o.target&&o.target!==this.rootTarget.parent;)o.currentTarget=o.target,this.notifyTarget(o),i&&this.notifyTarget(o,"mouseleave"),o.target=o.target.parent;e.overTargets=null,this.freeEvent(s),this.freeEvent(o)}this.cursor=null}mapPointerUp(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=performance.now(),i=this.createPointerEvent(t);if(this.dispatchEvent(i,"pointerup"),i.pointerType==="touch")this.dispatchEvent(i,"touchend");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const a=i.button===2;this.dispatchEvent(i,a?"rightup":"mouseup")}const n=this.trackingData(t.pointerId),s=this.findMountedTarget(n.pressTargetsByButton[t.button]);let o=s;if(s&&!i.composedPath().includes(s)){let a=s;for(;a&&!i.composedPath().includes(a);){if(i.currentTarget=a,this.notifyTarget(i,"pointerupoutside"),i.pointerType==="touch")this.notifyTarget(i,"touchendoutside");else if(i.pointerType==="mouse"||i.pointerType==="pen"){const l=i.button===2;this.notifyTarget(i,l?"rightupoutside":"mouseupoutside")}a=a.parent}delete n.pressTargetsByButton[t.button],o=a}if(o){const a=this.clonePointerEvent(i,"click");a.target=o,a.path=null,n.clicksByButton[t.button]||(n.clicksByButton[t.button]={clickCount:0,target:a.target,timeStamp:e});const l=n.clicksByButton[t.button];if(l.target===a.target&&e-l.timeStamp<200?++l.clickCount:l.clickCount=1,l.target=a.target,l.timeStamp=e,a.detail=l.clickCount,a.pointerType==="mouse"){const h=a.button===2;this.dispatchEvent(a,h?"rightclick":"click")}else a.pointerType==="touch"&&this.dispatchEvent(a,"tap");this.dispatchEvent(a,"pointertap"),this.freeEvent(a)}this.freeEvent(i)}mapPointerUpOutside(t){if(!(t instanceof Je)){console.warn("EventBoundary cannot map a non-pointer event as a pointer event");return}const e=this.trackingData(t.pointerId),i=this.findMountedTarget(e.pressTargetsByButton[t.button]),n=this.createPointerEvent(t);if(i){let s=i;for(;s;)n.currentTarget=s,this.notifyTarget(n,"pointerupoutside"),n.pointerType==="touch"?this.notifyTarget(n,"touchendoutside"):(n.pointerType==="mouse"||n.pointerType==="pen")&&this.notifyTarget(n,n.button===2?"rightupoutside":"mouseupoutside"),s=s.parent;delete e.pressTargetsByButton[t.button]}this.freeEvent(n)}mapWheel(t){if(!(t instanceof yn)){console.warn("EventBoundary cannot map a non-wheel event as a wheel event");return}const e=this.createWheelEvent(t);this.dispatchEvent(e),this.freeEvent(e)}findMountedTarget(t){if(!t)return null;let e=t[0];for(let i=1;i<t.length&&t[i].parent===e;i++)e=t[i];return e}createPointerEvent(t,e,i){const n=this.allocateEvent(Je);return this.copyPointerData(t,n),this.copyMouseData(t,n),this.copyData(t,n),n.nativeEvent=t.nativeEvent,n.originalEvent=t,n.target=i??this.hitTest(n.global.x,n.global.y)??this._hitElements[0],typeof e=="string"&&(n.type=e),n}createWheelEvent(t){const e=this.allocateEvent(yn);return this.copyWheelData(t,e),this.copyMouseData(t,e),this.copyData(t,e),e.nativeEvent=t.nativeEvent,e.originalEvent=t,e.target=this.hitTest(e.global.x,e.global.y),e}clonePointerEvent(t,e){const i=this.allocateEvent(Je);return i.nativeEvent=t.nativeEvent,i.originalEvent=t.originalEvent,this.copyPointerData(t,i),this.copyMouseData(t,i),this.copyData(t,i),i.target=t.target,i.path=t.composedPath().slice(),i.type=e??i.type,i}copyWheelData(t,e){e.deltaMode=t.deltaMode,e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ}copyPointerData(t,e){t instanceof Je&&e instanceof Je&&(e.pointerId=t.pointerId,e.width=t.width,e.height=t.height,e.isPrimary=t.isPrimary,e.pointerType=t.pointerType,e.pressure=t.pressure,e.tangentialPressure=t.tangentialPressure,e.tiltX=t.tiltX,e.tiltY=t.tiltY,e.twist=t.twist)}copyMouseData(t,e){t instanceof Ro&&e instanceof Ro&&(e.altKey=t.altKey,e.button=t.button,e.buttons=t.buttons,e.client.copyFrom(t.client),e.ctrlKey=t.ctrlKey,e.metaKey=t.metaKey,e.movement.copyFrom(t.movement),e.screen.copyFrom(t.screen),e.shiftKey=t.shiftKey,e.global.copyFrom(t.global))}copyData(t,e){e.isTrusted=t.isTrusted,e.srcElement=t.srcElement,e.timeStamp=performance.now(),e.type=t.type,e.detail=t.detail,e.view=t.view,e.which=t.which,e.layer.copyFrom(t.layer),e.page.copyFrom(t.page)}trackingData(t){return this.mappingState.trackingData[t]||(this.mappingState.trackingData[t]={pressTargetsByButton:{},clicksByButton:{},overTarget:null}),this.mappingState.trackingData[t]}allocateEvent(t){this.eventPool.has(t)||this.eventPool.set(t,[]);const e=this.eventPool.get(t).pop()||new t(this);return e.eventPhase=e.NONE,e.currentTarget=null,e.path=null,e.target=null,e}freeEvent(t){if(t.manager!==this)throw new Error("It is illegal to free an event not managed by this EventBoundary!");const e=t.constructor;this.eventPool.has(e)||this.eventPool.set(e,[]),this.eventPool.get(e).push(t)}notifyListeners(t,e){const i=t.currentTarget._events[e];if(i&&t.currentTarget.isInteractive())if("fn"in i)i.once&&t.currentTarget.removeListener(e,i.fn,void 0,!0),i.fn.call(i.context,t);else for(let n=0,s=i.length;n<s&&!t.propagationImmediatelyStopped;n++)i[n].once&&t.currentTarget.removeListener(e,i[n].fn,void 0,!0),i[n].fn.call(i[n].context,t)}}const rA=1,iA={touchstart:"pointerdown",touchend:"pointerup",touchendoutside:"pointerupoutside",touchmove:"pointermove",touchcancel:"pointercancel"},xh=class Jh{constructor(t){this.supportsTouchEvents="ontouchstart"in globalThis,this.supportsPointerEvents=!!globalThis.PointerEvent,this.domElement=null,this.resolution=1,this.renderer=t,this.rootBoundary=new eA(null),Zr.init(this),this.autoPreventDefault=!0,this.eventsAdded=!1,this.rootPointerEvent=new Je(null),this.rootWheelEvent=new yn(null),this.cursorStyles={default:"inherit",pointer:"pointer"},this.features=new Proxy({...Jh.defaultEventFeatures},{set:(e,i,n)=>(i==="globalMove"&&(this.rootBoundary.enableGlobalMoveEvents=n),e[i]=n,!0)}),this.onPointerDown=this.onPointerDown.bind(this),this.onPointerMove=this.onPointerMove.bind(this),this.onPointerUp=this.onPointerUp.bind(this),this.onPointerOverOut=this.onPointerOverOut.bind(this),this.onWheel=this.onWheel.bind(this)}static get defaultEventMode(){return this._defaultEventMode}init(t){const{view:e,resolution:i}=this.renderer;this.setTargetElement(e),this.resolution=i,Jh._defaultEventMode=t.eventMode??"auto",Object.assign(this.features,t.eventFeatures??{}),this.rootBoundary.enableGlobalMoveEvents=this.features.globalMove}resolutionChange(t){this.resolution=t}destroy(){this.setTargetElement(null),this.renderer=null}setCursor(t){t=t||"default";let e=!0;if(globalThis.OffscreenCanvas&&this.domElement instanceof OffscreenCanvas&&(e=!1),this.currentCursor===t)return;this.currentCursor=t;const i=this.cursorStyles[t];if(i)switch(typeof i){case"string":e&&(this.domElement.style.cursor=i);break;case"function":i(t);break;case"object":e&&Object.assign(this.domElement.style,i);break}else e&&typeof t=="string"&&!Object.prototype.hasOwnProperty.call(this.cursorStyles,t)&&(this.domElement.style.cursor=t)}get pointer(){return this.rootPointerEvent}onPointerDown(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);this.autoPreventDefault&&e[0].isNormalized&&(t.cancelable||!("cancelable"in t))&&t.preventDefault();for(let i=0,n=e.length;i<n;i++){const s=e[i],o=this.bootstrapEvent(this.rootPointerEvent,s);this.rootBoundary.mapEvent(o)}this.setCursor(this.rootBoundary.cursor)}onPointerMove(t){if(!this.features.move)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,Zr.pointerMoved();const e=this.normalizeToPointerData(t);for(let i=0,n=e.length;i<n;i++){const s=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onPointerUp(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;let e=t.target;t.composedPath&&t.composedPath().length>0&&(e=t.composedPath()[0]);const i=e!==this.domElement?"outside":"",n=this.normalizeToPointerData(t);for(let s=0,o=n.length;s<o;s++){const a=this.bootstrapEvent(this.rootPointerEvent,n[s]);a.type+=i,this.rootBoundary.mapEvent(a)}this.setCursor(this.rootBoundary.cursor)}onPointerOverOut(t){if(!this.features.click)return;this.rootBoundary.rootTarget=this.renderer.lastObjectRendered;const e=this.normalizeToPointerData(t);for(let i=0,n=e.length;i<n;i++){const s=this.bootstrapEvent(this.rootPointerEvent,e[i]);this.rootBoundary.mapEvent(s)}this.setCursor(this.rootBoundary.cursor)}onWheel(t){if(!this.features.wheel)return;const e=this.normalizeWheelEvent(t);this.rootBoundary.rootTarget=this.renderer.lastObjectRendered,this.rootBoundary.mapEvent(e)}setTargetElement(t){this.removeEvents(),this.domElement=t,Zr.domElement=t,this.addEvents()}addEvents(){if(this.eventsAdded||!this.domElement)return;Zr.addTickerListener();const t=this.domElement.style;t&&(globalThis.navigator.msPointerEnabled?(t.msContentZooming="none",t.msTouchAction="none"):this.supportsPointerEvents&&(t.touchAction="none")),this.supportsPointerEvents?(globalThis.document.addEventListener("pointermove",this.onPointerMove,!0),this.domElement.addEventListener("pointerdown",this.onPointerDown,!0),this.domElement.addEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.addEventListener("pointerover",this.onPointerOverOut,!0),globalThis.addEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.addEventListener("mousemove",this.onPointerMove,!0),this.domElement.addEventListener("mousedown",this.onPointerDown,!0),this.domElement.addEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.addEventListener("mouseover",this.onPointerOverOut,!0),globalThis.addEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.addEventListener("touchstart",this.onPointerDown,!0),this.domElement.addEventListener("touchend",this.onPointerUp,!0),this.domElement.addEventListener("touchmove",this.onPointerMove,!0))),this.domElement.addEventListener("wheel",this.onWheel,{passive:!0,capture:!0}),this.eventsAdded=!0}removeEvents(){if(!this.eventsAdded||!this.domElement)return;Zr.removeTickerListener();const t=this.domElement.style;globalThis.navigator.msPointerEnabled?(t.msContentZooming="",t.msTouchAction=""):this.supportsPointerEvents&&(t.touchAction=""),this.supportsPointerEvents?(globalThis.document.removeEventListener("pointermove",this.onPointerMove,!0),this.domElement.removeEventListener("pointerdown",this.onPointerDown,!0),this.domElement.removeEventListener("pointerleave",this.onPointerOverOut,!0),this.domElement.removeEventListener("pointerover",this.onPointerOverOut,!0),globalThis.removeEventListener("pointerup",this.onPointerUp,!0)):(globalThis.document.removeEventListener("mousemove",this.onPointerMove,!0),this.domElement.removeEventListener("mousedown",this.onPointerDown,!0),this.domElement.removeEventListener("mouseout",this.onPointerOverOut,!0),this.domElement.removeEventListener("mouseover",this.onPointerOverOut,!0),globalThis.removeEventListener("mouseup",this.onPointerUp,!0),this.supportsTouchEvents&&(this.domElement.removeEventListener("touchstart",this.onPointerDown,!0),this.domElement.removeEventListener("touchend",this.onPointerUp,!0),this.domElement.removeEventListener("touchmove",this.onPointerMove,!0))),this.domElement.removeEventListener("wheel",this.onWheel,!0),this.domElement=null,this.eventsAdded=!1}mapPositionToPoint(t,e,i){const n=this.domElement.isConnected?this.domElement.getBoundingClientRect():{width:this.domElement.width,height:this.domElement.height,left:0,top:0},s=1/this.resolution;t.x=(e-n.left)*(this.domElement.width/n.width)*s,t.y=(i-n.top)*(this.domElement.height/n.height)*s}normalizeToPointerData(t){const e=[];if(this.supportsTouchEvents&&t instanceof TouchEvent)for(let i=0,n=t.changedTouches.length;i<n;i++){const s=t.changedTouches[i];typeof s.button>"u"&&(s.button=0),typeof s.buttons>"u"&&(s.buttons=1),typeof s.isPrimary>"u"&&(s.isPrimary=t.touches.length===1&&t.type==="touchstart"),typeof s.width>"u"&&(s.width=s.radiusX||1),typeof s.height>"u"&&(s.height=s.radiusY||1),typeof s.tiltX>"u"&&(s.tiltX=0),typeof s.tiltY>"u"&&(s.tiltY=0),typeof s.pointerType>"u"&&(s.pointerType="touch"),typeof s.pointerId>"u"&&(s.pointerId=s.identifier||0),typeof s.pressure>"u"&&(s.pressure=s.force||.5),typeof s.twist>"u"&&(s.twist=0),typeof s.tangentialPressure>"u"&&(s.tangentialPressure=0),typeof s.layerX>"u"&&(s.layerX=s.offsetX=s.clientX),typeof s.layerY>"u"&&(s.layerY=s.offsetY=s.clientY),s.isNormalized=!0,s.type=t.type,e.push(s)}else if(!globalThis.MouseEvent||t instanceof MouseEvent&&(!this.supportsPointerEvents||!(t instanceof globalThis.PointerEvent))){const i=t;typeof i.isPrimary>"u"&&(i.isPrimary=!0),typeof i.width>"u"&&(i.width=1),typeof i.height>"u"&&(i.height=1),typeof i.tiltX>"u"&&(i.tiltX=0),typeof i.tiltY>"u"&&(i.tiltY=0),typeof i.pointerType>"u"&&(i.pointerType="mouse"),typeof i.pointerId>"u"&&(i.pointerId=rA),typeof i.pressure>"u"&&(i.pressure=.5),typeof i.twist>"u"&&(i.twist=0),typeof i.tangentialPressure>"u"&&(i.tangentialPressure=0),i.isNormalized=!0,e.push(i)}else e.push(t);return e}normalizeWheelEvent(t){const e=this.rootWheelEvent;return this.transferMouseData(e,t),e.deltaX=t.deltaX,e.deltaY=t.deltaY,e.deltaZ=t.deltaZ,e.deltaMode=t.deltaMode,this.mapPositionToPoint(e.screen,t.clientX,t.clientY),e.global.copyFrom(e.screen),e.offset.copyFrom(e.screen),e.nativeEvent=t,e.type=t.type,e}bootstrapEvent(t,e){return t.originalEvent=null,t.nativeEvent=e,t.pointerId=e.pointerId,t.width=e.width,t.height=e.height,t.isPrimary=e.isPrimary,t.pointerType=e.pointerType,t.pressure=e.pressure,t.tangentialPressure=e.tangentialPressure,t.tiltX=e.tiltX,t.tiltY=e.tiltY,t.twist=e.twist,this.transferMouseData(t,e),this.mapPositionToPoint(t.screen,e.clientX,e.clientY),t.global.copyFrom(t.screen),t.offset.copyFrom(t.screen),t.isTrusted=e.isTrusted,t.type==="pointerleave"&&(t.type="pointerout"),t.type.startsWith("mouse")&&(t.type=t.type.replace("mouse","pointer")),t.type.startsWith("touch")&&(t.type=iA[t.type]||t.type),t}transferMouseData(t,e){t.isTrusted=e.isTrusted,t.srcElement=e.srcElement,t.timeStamp=performance.now(),t.type=e.type,t.altKey=e.altKey,t.button=e.button,t.buttons=e.buttons,t.client.x=e.clientX,t.client.y=e.clientY,t.ctrlKey=e.ctrlKey,t.metaKey=e.metaKey,t.movement.x=e.movementX,t.movement.y=e.movementY,t.page.x=e.pageX,t.page.y=e.pageY,t.relatedTarget=null,t.shiftKey=e.shiftKey}};xh.extension={name:"events",type:[K.RendererSystem,K.CanvasRendererSystem]},xh.defaultEventFeatures={move:!0,globalMove:!0,click:!0,wheel:!0};let wh=xh;ut.add(wh);function Jp(r){return r==="dynamic"||r==="static"}const nA={onclick:null,onmousedown:null,onmouseenter:null,onmouseleave:null,onmousemove:null,onglobalmousemove:null,onmouseout:null,onmouseover:null,onmouseup:null,onmouseupoutside:null,onpointercancel:null,onpointerdown:null,onpointerenter:null,onpointerleave:null,onpointermove:null,onglobalpointermove:null,onpointerout:null,onpointerover:null,onpointertap:null,onpointerup:null,onpointerupoutside:null,onrightclick:null,onrightdown:null,onrightup:null,onrightupoutside:null,ontap:null,ontouchcancel:null,ontouchend:null,ontouchendoutside:null,ontouchmove:null,onglobaltouchmove:null,ontouchstart:null,onwheel:null,_internalInteractive:void 0,get interactive(){return this._internalInteractive??Jp(wh.defaultEventMode)},set interactive(r){St("7.2.0","Setting interactive is deprecated, use eventMode = 'none'/'passive'/'auto'/'static'/'dynamic' instead."),this._internalInteractive=r,this.eventMode=r?"static":"auto"},_internalEventMode:void 0,get eventMode(){return this._internalEventMode??wh.defaultEventMode},set eventMode(r){this._internalInteractive=Jp(r),this._internalEventMode=r},isInteractive(){return this.eventMode==="static"||this.eventMode==="dynamic"},interactiveChildren:!0,hitArea:null,addEventListener(r,t,e){const i=typeof e=="boolean"&&e||typeof e=="object"&&e.capture,n=typeof e=="object"?e.signal:void 0,s=typeof e=="object"?e.once===!0:!1,o=typeof t=="function"?void 0:t;r=i?`${r}capture`:r;const a=typeof t=="function"?t:t.handleEvent,l=this;n&&n.addEventListener("abort",()=>{l.off(r,a,o)}),s?l.once(r,a,o):l.on(r,a,o)},removeEventListener(r,t,e){const i=typeof e=="boolean"&&e||typeof e=="object"&&e.capture,n=typeof t=="function"?void 0:t;r=i?`${r}capture`:r,t=typeof t=="function"?t:t.handleEvent,this.off(r,t,n)},dispatchEvent(r){if(!(r instanceof ds))throw new Error("DisplayObject cannot propagate events outside of the Federated Events API");return r.defaultPrevented=!1,r.path=null,r.target=this,r.manager.dispatchEvent(r),!r.defaultPrevented}};Xt.mixin(nA);const sA={accessible:!1,accessibleTitle:null,accessibleHint:null,tabIndex:0,_accessibleActive:!1,_accessibleDiv:null,accessibleType:"button",accessiblePointerEvents:"auto",accessibleChildren:!0,renderId:-1};Xt.mixin(sA);const oA=9,Mo=100,aA=0,lA=0,Qp=2,tm=1,hA=-1e3,cA=-1e3,uA=2;class em{constructor(t){this.debug=!1,this._isActive=!1,this._isMobileAccessibility=!1,this.pool=[],this.renderId=0,this.children=[],this.androidUpdateCount=0,this.androidUpdateFrequency=500,this._hookDiv=null,(wr.tablet||wr.phone)&&this.createTouchHook();const e=document.createElement("div");e.style.width=`${Mo}px`,e.style.height=`${Mo}px`,e.style.position="absolute",e.style.top=`${aA}px`,e.style.left=`${lA}px`,e.style.zIndex=Qp.toString(),this.div=e,this.renderer=t,this._onKeyDown=this._onKeyDown.bind(this),this._onMouseMove=this._onMouseMove.bind(this),globalThis.addEventListener("keydown",this._onKeyDown,!1)}get isActive(){return this._isActive}get isMobileAccessibility(){return this._isMobileAccessibility}createTouchHook(){const t=document.createElement("button");t.style.width=`${tm}px`,t.style.height=`${tm}px`,t.style.position="absolute",t.style.top=`${hA}px`,t.style.left=`${cA}px`,t.style.zIndex=uA.toString(),t.style.backgroundColor="#FF0000",t.title="select to enable accessibility for this content",t.addEventListener("focus",()=>{this._isMobileAccessibility=!0,this.activate(),this.destroyTouchHook()}),document.body.appendChild(t),this._hookDiv=t}destroyTouchHook(){this._hookDiv&&(document.body.removeChild(this._hookDiv),this._hookDiv=null)}activate(){var t;this._isActive||(this._isActive=!0,globalThis.document.addEventListener("mousemove",this._onMouseMove,!0),globalThis.removeEventListener("keydown",this._onKeyDown,!1),this.renderer.on("postrender",this.update,this),(t=this.renderer.view.parentNode)==null||t.appendChild(this.div))}deactivate(){var t;!this._isActive||this._isMobileAccessibility||(this._isActive=!1,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),globalThis.addEventListener("keydown",this._onKeyDown,!1),this.renderer.off("postrender",this.update),(t=this.div.parentNode)==null||t.removeChild(this.div))}updateAccessibleObjects(t){if(!t.visible||!t.accessibleChildren)return;t.accessible&&t.isInteractive()&&(t._accessibleActive||this.addChild(t),t.renderId=this.renderId);const e=t.children;if(e)for(let i=0;i<e.length;i++)this.updateAccessibleObjects(e[i])}update(){const t=performance.now();if(wr.android.device&&t<this.androidUpdateCount||(this.androidUpdateCount=t+this.androidUpdateFrequency,!this.renderer.renderingToScreen))return;this.renderer.lastObjectRendered&&this.updateAccessibleObjects(this.renderer.lastObjectRendered);const{x:e,y:i,width:n,height:s}=this.renderer.view.getBoundingClientRect(),{width:o,height:a,resolution:l}=this.renderer,h=n/o*l,c=s/a*l;let u=this.div;u.style.left=`${e}px`,u.style.top=`${i}px`,u.style.width=`${o}px`,u.style.height=`${a}px`;for(let d=0;d<this.children.length;d++){const f=this.children[d];if(f.renderId!==this.renderId)f._accessibleActive=!1,dn(this.children,d,1),this.div.removeChild(f._accessibleDiv),this.pool.push(f._accessibleDiv),f._accessibleDiv=null,d--;else{u=f._accessibleDiv;let p=f.hitArea;const g=f.worldTransform;f.hitArea?(u.style.left=`${(g.tx+p.x*g.a)*h}px`,u.style.top=`${(g.ty+p.y*g.d)*c}px`,u.style.width=`${p.width*g.a*h}px`,u.style.height=`${p.height*g.d*c}px`):(p=f.getBounds(),this.capHitArea(p),u.style.left=`${p.x*h}px`,u.style.top=`${p.y*c}px`,u.style.width=`${p.width*h}px`,u.style.height=`${p.height*c}px`,u.title!==f.accessibleTitle&&f.accessibleTitle!==null&&(u.title=f.accessibleTitle),u.getAttribute("aria-label")!==f.accessibleHint&&f.accessibleHint!==null&&u.setAttribute("aria-label",f.accessibleHint)),(f.accessibleTitle!==u.title||f.tabIndex!==u.tabIndex)&&(u.title=f.accessibleTitle,u.tabIndex=f.tabIndex,this.debug&&this.updateDebugHTML(u))}}this.renderId++}updateDebugHTML(t){t.innerHTML=`type: ${t.type}</br> title : ${t.title}</br> tabIndex: ${t.tabIndex}`}capHitArea(t){t.x<0&&(t.width+=t.x,t.x=0),t.y<0&&(t.height+=t.y,t.y=0);const{width:e,height:i}=this.renderer;t.x+t.width>e&&(t.width=e-t.x),t.y+t.height>i&&(t.height=i-t.y)}addChild(t){let e=this.pool.pop();e||(e=document.createElement("button"),e.style.width=`${Mo}px`,e.style.height=`${Mo}px`,e.style.backgroundColor=this.debug?"rgba(255,255,255,0.5)":"transparent",e.style.position="absolute",e.style.zIndex=Qp.toString(),e.style.borderStyle="none",navigator.userAgent.toLowerCase().includes("chrome")?e.setAttribute("aria-live","off"):e.setAttribute("aria-live","polite"),navigator.userAgent.match(/rv:.*Gecko\//)?e.setAttribute("aria-relevant","additions"):e.setAttribute("aria-relevant","text"),e.addEventListener("click",this._onClick.bind(this)),e.addEventListener("focus",this._onFocus.bind(this)),e.addEventListener("focusout",this._onFocusOut.bind(this))),e.style.pointerEvents=t.accessiblePointerEvents,e.type=t.accessibleType,t.accessibleTitle&&t.accessibleTitle!==null?e.title=t.accessibleTitle:(!t.accessibleHint||t.accessibleHint===null)&&(e.title=`displayObject ${t.tabIndex}`),t.accessibleHint&&t.accessibleHint!==null&&e.setAttribute("aria-label",t.accessibleHint),this.debug&&this.updateDebugHTML(e),t._accessibleActive=!0,t._accessibleDiv=e,e.displayObject=t,this.children.push(t),this.div.appendChild(t._accessibleDiv),t._accessibleDiv.tabIndex=t.tabIndex}_dispatchEvent(t,e){const{displayObject:i}=t.target,n=this.renderer.events.rootBoundary,s=Object.assign(new ds(n),{target:i});n.rootTarget=this.renderer.lastObjectRendered,e.forEach(o=>n.dispatchEvent(s,o))}_onClick(t){this._dispatchEvent(t,["click","pointertap","tap"])}_onFocus(t){t.target.getAttribute("aria-live")||t.target.setAttribute("aria-live","assertive"),this._dispatchEvent(t,["mouseover"])}_onFocusOut(t){t.target.getAttribute("aria-live")||t.target.setAttribute("aria-live","polite"),this._dispatchEvent(t,["mouseout"])}_onKeyDown(t){t.keyCode===oA&&this.activate()}_onMouseMove(t){t.movementX===0&&t.movementY===0||this.deactivate()}destroy(){this.destroyTouchHook(),this.div=null,globalThis.document.removeEventListener("mousemove",this._onMouseMove,!0),globalThis.removeEventListener("keydown",this._onKeyDown),this.pool=null,this.children=null,this.renderer=null}}em.extension={name:"accessibility",type:[K.RendererPlugin,K.CanvasRendererPlugin]},ut.add(em);const rm=class Qh{constructor(t){this.stage=new Ze,t=Object.assign({forceCanvas:!1},t),this.renderer=$p(t),Qh._plugins.forEach(e=>{e.init.call(this,t)})}render(){this.renderer.render(this.stage)}get view(){var t;return(t=this.renderer)==null?void 0:t.view}get screen(){var t;return(t=this.renderer)==null?void 0:t.screen}destroy(t,e){const i=Qh._plugins.slice(0);i.reverse(),i.forEach(n=>{n.destroy.call(this)}),this.stage.destroy(e),this.stage=null,this.renderer.destroy(t),this.renderer=null}};rm._plugins=[];let dA=rm;ut.handleByList(K.Application,dA._plugins);class im{static init(t){Object.defineProperty(this,"resizeTo",{set(e){globalThis.removeEventListener("resize",this.queueResize),this._resizeTo=e,e&&(globalThis.addEventListener("resize",this.queueResize),this.resize())},get(){return this._resizeTo}}),this.queueResize=()=>{this._resizeTo&&(this.cancelResize(),this._resizeId=requestAnimationFrame(()=>this.resize()))},this.cancelResize=()=>{this._resizeId&&(cancelAnimationFrame(this._resizeId),this._resizeId=null)},this.resize=()=>{if(!this._resizeTo)return;this.cancelResize();let e,i;if(this._resizeTo===globalThis.window)e=globalThis.innerWidth,i=globalThis.innerHeight;else{const{clientWidth:n,clientHeight:s}=this._resizeTo;e=n,i=s}this.renderer.resize(e,i),this.render()},this._resizeId=null,this._resizeTo=null,this.resizeTo=t.resizeTo||null}static destroy(){globalThis.removeEventListener("resize",this.queueResize),this.cancelResize(),this.cancelResize=null,this.queueResize=null,this.resizeTo=null,this.resize=null}}im.extension=K.Application,ut.add(im);const nm={loader:K.LoadParser,resolver:K.ResolveParser,cache:K.CacheParser,detection:K.DetectionParser};ut.handle(K.Asset,r=>{const t=r.ref;Object.entries(nm).filter(([e])=>!!t[e]).forEach(([e,i])=>ut.add(Object.assign(t[e],{extension:t[e].extension??i})))},r=>{const t=r.ref;Object.keys(nm).filter(e=>!!t[e]).forEach(e=>ut.remove(t[e]))});class fA{constructor(t,e=!1){this._loader=t,this._assetList=[],this._isLoading=!1,this._maxConcurrent=1,this.verbose=e}add(t){t.forEach(e=>{this._assetList.push(e)}),this.verbose&&console.log("[BackgroundLoader] assets: ",this._assetList),this._isActive&&!this._isLoading&&this._next()}async _next(){if(this._assetList.length&&this._isActive){this._isLoading=!0;const t=[],e=Math.min(this._assetList.length,this._maxConcurrent);for(let i=0;i<e;i++)t.push(this._assetList.pop());await this._loader.load(t),this._isLoading=!1,this._next()}}get active(){return this._isActive}set active(t){this._isActive!==t&&(this._isActive=t,t&&!this._isLoading&&this._next())}}function _n(r,t){if(Array.isArray(t)){for(const e of t)if(r.startsWith(`data:${e}`))return!0;return!1}return r.startsWith(`data:${t}`)}function Jr(r,t){const e=r.split("?")[0],i=ue.extname(e).toLowerCase();return Array.isArray(t)?t.includes(i):i===t}const Qe=(r,t,e=!1)=>(Array.isArray(r)||(r=[r]),t?r.map(i=>typeof i=="string"||e?t(i):i):r),Eh=(r,t)=>{const e=t.split("?")[1];return e&&(r+=`?${e}`),r};function sm(r,t,e,i,n){const s=t[e];for(let o=0;o<s.length;o++){const a=s[o];e<t.length-1?sm(r.replace(i[e],a),t,e+1,i,n):n.push(r.replace(i[e],a))}}function pA(r){const t=/\{(.*?)\}/g,e=r.match(t),i=[];if(e){const n=[];e.forEach(s=>{const o=s.substring(1,s.length-1).split(",");n.push(o)}),sm(r,n,0,e,i)}else i.push(r);return i}const Oo=r=>!Array.isArray(r);class mA{constructor(){this._parsers=[],this._cache=new Map,this._cacheMap=new Map}reset(){this._cacheMap.clear(),this._cache.clear()}has(t){return this._cache.has(t)}get(t){const e=this._cache.get(t);return e||console.warn(`[Assets] Asset id ${t} was not found in the Cache`),e}set(t,e){const i=Qe(t);let n;for(let a=0;a<this.parsers.length;a++){const l=this.parsers[a];if(l.test(e)){n=l.getCacheableAssets(i,e);break}}n||(n={},i.forEach(a=>{n[a]=e}));const s=Object.keys(n),o={cacheKeys:s,keys:i};if(i.forEach(a=>{this._cacheMap.set(a,o)}),s.forEach(a=>{const l=n?n[a]:e;this._cache.has(a)&&this._cache.get(a)!==l&&console.warn("[Cache] already has key:",a),this._cache.set(a,n[a])}),e instanceof dt){const a=e;i.forEach(l=>{a.baseTexture!==dt.EMPTY.baseTexture&&xt.addToCache(a.baseTexture,l),dt.addToCache(a,l)})}}remove(t){if(!this._cacheMap.has(t)){console.warn(`[Assets] Asset id ${t} was not found in the Cache`);return}const e=this._cacheMap.get(t);e.cacheKeys.forEach(i=>{this._cache.delete(i)}),e.keys.forEach(i=>{this._cacheMap.delete(i)})}get parsers(){return this._parsers}}const Ri=new mA;class gA{constructor(){this._parsers=[],this._parsersValidated=!1,this.parsers=new Proxy(this._parsers,{set:(t,e,i)=>(this._parsersValidated=!1,t[e]=i,!0)}),this.promiseCache={}}reset(){this._parsersValidated=!1,this.promiseCache={}}_getLoadPromiseAndParser(t,e){const i={promise:null,parser:null};return i.promise=(async()=>{var o,a;let n=null,s=null;if(e.loadParser&&(s=this._parserHash[e.loadParser],s||console.warn(`[Assets] specified load parser "${e.loadParser}" not found while loading ${t}`)),!s){for(let l=0;l<this.parsers.length;l++){const h=this.parsers[l];if(h.load&&((o=h.test)!=null&&o.call(h,t,e,this))){s=h;break}}if(!s)return console.warn(`[Assets] ${t} could not be loaded as we don't know how to parse it, ensure the correct parser has been added`),null}n=await s.load(t,e,this),i.parser=s;for(let l=0;l<this.parsers.length;l++){const h=this.parsers[l];h.parse&&h.parse&&await((a=h.testParse)==null?void 0:a.call(h,n,e,this))&&(n=await h.parse(n,e,this)||n,i.parser=h)}return n})(),i}async load(t,e){this._parsersValidated||this._validateParsers();let i=0;const n={},s=Oo(t),o=Qe(t,h=>({alias:[h],src:h})),a=o.length,l=o.map(async h=>{const c=ue.toAbsolute(h.src);if(!n[h.src])try{this.promiseCache[c]||(this.promiseCache[c]=this._getLoadPromiseAndParser(c,h)),n[h.src]=await this.promiseCache[c].promise,e&&e(++i/a)}catch(u){throw delete this.promiseCache[c],delete n[h.src],new Error(`[Loader.load] Failed to load ${c}.
867
867
  ${u}`)}});return await Promise.all(l),s?n[o[0].src]:n}async unload(t){const e=Qe(t,i=>({alias:[i],src:i})).map(async i=>{var o,a;const n=ue.toAbsolute(i.src),s=this.promiseCache[n];if(s){const l=await s.promise;delete this.promiseCache[n],(a=(o=s.parser)==null?void 0:o.unload)==null||a.call(o,l,i,this)}});await Promise.all(e)}_validateParsers(){this._parsersValidated=!0,this._parserHash=this._parsers.filter(t=>t.name).reduce((t,e)=>(t[e.name]&&console.warn(`[Assets] loadParser name conflict "${e.name}"`),{...t,[e.name]:e}),{})}}var tr=(r=>(r[r.Low=0]="Low",r[r.Normal=1]="Normal",r[r.High=2]="High",r))(tr||{});const yA=".json",_A="application/json",vA={extension:{type:K.LoadParser,priority:tr.Low},name:"loadJson",test(r){return _n(r,_A)||Jr(r,yA)},async load(r){return await(await tt.ADAPTER.fetch(r)).json()}};ut.add(vA);const bA=".txt",xA="text/plain",wA={name:"loadTxt",extension:{type:K.LoadParser,priority:tr.Low},test(r){return _n(r,xA)||Jr(r,bA)},async load(r){return await(await tt.ADAPTER.fetch(r)).text()}};ut.add(wA);const EA=["normal","bold","100","200","300","400","500","600","700","800","900"],TA=[".ttf",".otf",".woff",".woff2"],AA=["font/ttf","font/otf","font/woff","font/woff2"],SA=/^(--|-?[A-Z_])[0-9A-Z_-]*$/i;function CA(r){const t=ue.extname(r),e=ue.basename(r,t).replace(/(-|_)/g," ").toLowerCase().split(" ").map(s=>s.charAt(0).toUpperCase()+s.slice(1));let i=e.length>0;for(const s of e)if(!s.match(SA)){i=!1;break}let n=e.join(" ");return i||(n=`"${n.replace(/[\\"]/g,"\\$&")}"`),n}const IA=/^[0-9A-Za-z%:/?#\[\]@!\$&'()\*\+,;=\-._~]*$/;function PA(r){return IA.test(r)?r:encodeURI(r)}const RA={extension:{type:K.LoadParser,priority:tr.Low},name:"loadWebFont",test(r){return _n(r,AA)||Jr(r,TA)},async load(r,t){var i,n,s;const e=tt.ADAPTER.getFontFaceSet();if(e){const o=[],a=((i=t.data)==null?void 0:i.family)??CA(r),l=((s=(n=t.data)==null?void 0:n.weights)==null?void 0:s.filter(c=>EA.includes(c)))??["normal"],h=t.data??{};for(let c=0;c<l.length;c++){const u=l[c],d=new FontFace(a,`url(${PA(r)})`,{...h,weight:u});await d.load(),e.add(d),o.push(d)}return o.length===1?o[0]:o}return console.warn("[loadWebFont] FontFace API is not supported. Skipping loading font"),null},unload(r){(Array.isArray(r)?r:[r]).forEach(t=>tt.ADAPTER.getFontFaceSet().delete(t))}};ut.add(RA);const MA=`(function() {
868
868
  "use strict";
869
869
  const WHITE_PNG = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAwMCAO+ip1sAAAAASUVORK5CYII=";
@@ -966,7 +966,7 @@ void main(void){
966
966
  vColor = aColor * uColor;
967
967
  }
968
968
  `;class Im extends bo{constructor(t){super(t),this.shader=null,this.properties=null,this.tempMatrix=new Ft,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:mt.UNSIGNED_BYTE,uploadFunction:this.uploadTint,offset:0}],this.shader=gr.from(VS,HS,{}),this.state=mr.for2d()}render(t){const e=t.children,i=t._maxSize,n=t._batchSize,s=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=Vf(t.blendMode,h),s.state.set(this.state);const c=s.gl,u=t.worldTransform.copyTo(this.tempMatrix);u.prepend(s.globalUniforms.uniforms.projectionMatrix),this.shader.uniforms.translationMatrix=u.toArray(!0),this.shader.uniforms.uColor=Mt.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+=n,p+=1){let g=o-f;g>n&&(g=n),p>=a.length&&a.push(this._generateOneMoreBuffer(t));const y=a[p];y.uploadDynamic(e,f,g);const _=t._bufferUpdateIDs[p]||0;d=d||y._updateID<_,d&&(y._updateID=t._updateID,y.uploadStatic(e,f,g)),s.geometry.bind(y.geometry),c.drawElements(c.TRIANGLES,g*6,c.UNSIGNED_SHORT,0)}}generateBuffers(t){const e=[],i=t._maxSize,n=t._batchSize,s=t._properties;for(let o=0;o<i;o+=n)e.push(new Cm(this.properties,s,n));return e}_generateOneMoreBuffer(t){const e=t._batchSize,i=t._properties;return new Cm(this.properties,i,e)}uploadVertices(t,e,i,n,s,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,g=d.scale.y,y=f.trim,_=f.orig;y?(l=y.x-d.anchor.x*_.width,a=l+y.width,c=y.y-d.anchor.y*_.height,h=c+y.height):(a=_.width*(1-d.anchor.x),l=_.width*-d.anchor.x,h=_.height*(1-d.anchor.y),c=_.height*-d.anchor.y),n[o]=l*p,n[o+1]=c*g,n[o+s]=a*p,n[o+s+1]=c*g,n[o+s*2]=a*p,n[o+s*2+1]=h*g,n[o+s*3]=l*p,n[o+s*3+1]=h*g,o+=s*4}}uploadPosition(t,e,i,n,s,o){for(let a=0;a<i;a++){const l=t[e+a].position;n[o]=l.x,n[o+1]=l.y,n[o+s]=l.x,n[o+s+1]=l.y,n[o+s*2]=l.x,n[o+s*2+1]=l.y,n[o+s*3]=l.x,n[o+s*3+1]=l.y,o+=s*4}}uploadRotation(t,e,i,n,s,o){for(let a=0;a<i;a++){const l=t[e+a].rotation;n[o]=l,n[o+s]=l,n[o+s*2]=l,n[o+s*3]=l,o+=s*4}}uploadUvs(t,e,i,n,s,o){for(let a=0;a<i;++a){const l=t[e+a]._texture._uvs;l?(n[o]=l.x0,n[o+1]=l.y0,n[o+s]=l.x1,n[o+s+1]=l.y1,n[o+s*2]=l.x2,n[o+s*2+1]=l.y2,n[o+s*3]=l.x3,n[o+s*3+1]=l.y3,o+=s*4):(n[o]=0,n[o+1]=0,n[o+s]=0,n[o+s+1]=0,n[o+s*2]=0,n[o+s*2+1]=0,n[o+s*3]=0,n[o+s*3+1]=0,o+=s*4)}}uploadTint(t,e,i,n,s,o){for(let a=0;a<i;++a){const l=t[e+a],h=Mt.shared.setValue(l._tintRGB).toPremultiplied(l.alpha,l.texture.baseTexture.alphaMode>0);n[o]=h,n[o+s]=h,n[o+s*2]=h,n[o+s*3]=h,o+=s*4}}destroy(){super.destroy(),this.shader&&(this.shader.destroy(),this.shader=null),this.tempMatrix=null}}Im.extension={name:"particle",type:K.RendererPlugin},ut.add(Im);var Xo=(r=>(r[r.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",r[r.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",r))(Xo||{});const jo={willReadFrequently:!0},_r=class pt{static get experimentalLetterSpacingSupported(){let t=pt._experimentalLetterSpacingSupported;if(t!==void 0){const e=tt.ADAPTER.getCanvasRenderingContext2D().prototype;t=pt._experimentalLetterSpacingSupported="letterSpacing"in e||"textLetterSpacing"in e}return t}constructor(t,e,i,n,s,o,a,l,h){this.text=t,this.style=e,this.width=i,this.height=n,this.lines=s,this.lineWidths=o,this.lineHeight=a,this.maxLineWidth=l,this.fontProperties=h}static measureText(t,e,i,n=pt._canvas){i=i??e.wordWrap;const s=e.toFontString(),o=pt.measureFont(s);o.fontSize===0&&(o.fontSize=e.fontSize,o.ascent=e.fontSize);const a=n.getContext("2d",jo);a.font=s;const l=(i?pt.wordWrap(t,e,n):t).split(/(?:\r\n|\r|\n)/),h=new Array(l.length);let c=0;for(let p=0;p<l.length;p++){const g=pt._measureText(l[p],e.letterSpacing,a);h[p]=g,c=Math.max(c,g)}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 pt(t,e,u,f,l,h,d+e.leading,c,o)}static _measureText(t,e,i){let n=!1;pt.experimentalLetterSpacingSupported&&(pt.experimentalLetterSpacing?(i.letterSpacing=`${e}px`,i.textLetterSpacing=`${e}px`,n=!0):(i.letterSpacing="0px",i.textLetterSpacing="0px"));let s=i.measureText(t).width;return s>0&&(n?s-=e:s+=(pt.graphemeSegmenter(t).length-1)*e),s}static wordWrap(t,e,i=pt._canvas){const n=i.getContext("2d",jo);let s=0,o="",a="";const l=Object.create(null),{letterSpacing:h,whiteSpace:c}=e,u=pt.collapseSpaces(c),d=pt.collapseNewlines(c);let f=!u;const p=e.wordWrapWidth+h,g=pt.tokenize(t);for(let y=0;y<g.length;y++){let _=g[y];if(pt.isNewline(_)){if(!d){a+=pt.addLine(o),f=!u,o="",s=0;continue}_=" "}if(u){const m=pt.isBreakingSpace(_),x=pt.isBreakingSpace(o[o.length-1]);if(m&&x)continue}const v=pt.getFromCache(_,h,l,n);if(v>p)if(o!==""&&(a+=pt.addLine(o),o="",s=0),pt.canBreakWords(_,e.breakWords)){const m=pt.wordWrapSplit(_);for(let x=0;x<m.length;x++){let S=m[x],R=S,C=1;for(;m[x+C];){const M=m[x+C];if(!pt.canBreakChars(R,M,_,x,e.breakWords))S+=M;else break;R=M,C++}x+=C-1;const I=pt.getFromCache(S,h,l,n);I+s>p&&(a+=pt.addLine(o),f=!1,o="",s=0),o+=S,s+=I}}else{o.length>0&&(a+=pt.addLine(o),o="",s=0);const m=y===g.length-1;a+=pt.addLine(_,!m),f=!1,o="",s=0}else v+s>p&&(f=!1,a+=pt.addLine(o),o="",s=0),(o.length>0||!pt.isBreakingSpace(_)||f)&&(o+=_,s+=v)}return a+=pt.addLine(o,!1),a}static addLine(t,e=!0){return t=pt.trimRight(t),t=e?`${t}
969
- `:t,t}static getFromCache(t,e,i,n){let s=i[t];return typeof s!="number"&&(s=pt._measureText(t,e,n)+e,i[t]=s),s}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(!pt.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static isNewline(t){return typeof t!="string"?!1:pt._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:pt._breakingSpaces.includes(t.charCodeAt(0))}static tokenize(t){const e=[];let i="";if(typeof t!="string")return e;for(let n=0;n<t.length;n++){const s=t[n],o=t[n+1];if(pt.isBreakingSpace(s,o)||pt.isNewline(s)){i!==""&&(e.push(i),i=""),e.push(s);continue}i+=s}return i!==""&&e.push(i),e}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,n,s){return!0}static wordWrapSplit(t){return pt.graphemeSegmenter(t)}static measureFont(t){if(pt._fonts[t])return pt._fonts[t];const e={ascent:0,descent:0,fontSize:0},i=pt._canvas,n=pt._context;n.font=t;const s=pt.METRICS_STRING+pt.BASELINE_SYMBOL,o=Math.ceil(n.measureText(s).width);let a=Math.ceil(n.measureText(pt.BASELINE_SYMBOL).width);const l=Math.ceil(pt.HEIGHT_MULTIPLIER*a);if(a=a*pt.BASELINE_MULTIPLIER|0,o===0||l===0)return pt._fonts[t]=e,e;i.width=o,i.height=l,n.fillStyle="#f00",n.fillRect(0,0,o,l),n.font=t,n.textBaseline="alphabetic",n.fillStyle="#000",n.fillText(s,0,a);const h=n.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 g=0;g<u;g+=4)if(h[f+g]!==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 g=0;g<u;g+=4)if(h[f+g]!==255){p=!0;break}if(!p)f-=u;else break}return e.descent=d-a,e.fontSize=e.ascent+e.descent,pt._fonts[t]=e,e}static clearMetrics(t=""){t?delete pt._fonts[t]:pt._fonts={}}static get _canvas(){var t;if(!pt.__canvas){let e;try{const i=new OffscreenCanvas(0,0);if((t=i.getContext("2d",jo))!=null&&t.measureText)return pt.__canvas=i,i;e=tt.ADAPTER.createCanvas()}catch{e=tt.ADAPTER.createCanvas()}e.width=e.height=10,pt.__canvas=e}return pt.__canvas}static get _context(){return pt.__context||(pt.__context=pt._canvas.getContext("2d",jo)),pt.__context}};_r.METRICS_STRING="|ÉqÅ",_r.BASELINE_SYMBOL="M",_r.BASELINE_MULTIPLIER=1.4,_r.HEIGHT_MULTIPLIER=2,_r.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]})(),_r.experimentalLetterSpacing=!1,_r._fonts={},_r._newlines=[10,13],_r._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let ti=_r;const XS=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],Pm=class vs{constructor(t){this.styleID=0,this.reset(),Fh(this,t,t)}clone(){const t={};return Fh(t,this,vs.defaultStyle),new vs(t)}reset(){Fh(this,vs.defaultStyle,vs.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=Nh(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=Nh(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){jS(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=Nh(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 n=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(n)&&!XS.includes(n)&&(n=`"${n}"`),e[i]=n}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};Pm.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Xo.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 ei=Pm;function Nh(r){const t=Mt.shared,e=i=>{const n=t.setValue(i);return n.alpha===1?n.toHex():n.toRgbaString()};return Array.isArray(r)?r.map(e):e(r)}function jS(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 Fh(r,t,e){for(const i in e)Array.isArray(t[i])?r[i]=t[i].slice():r[i]=t[i]}const WS={texture:!0,children:!1,baseTexture:!0},Rm=class tc extends gn{constructor(t,e,i){let n=!1;i||(i=tt.ADAPTER.createCanvas(),n=!0),i.width=3,i.height=3;const s=dt.from(i);s.orig=new wt,s.trim=new wt,super(s),this._ownCanvas=n,this.canvas=i,this.context=i.getContext("2d",{willReadFrequently:!0}),this._resolution=tc.defaultResolution??tt.RESOLUTION,this._autoResolution=tc.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 ti.experimentalLetterSpacing}static set experimentalLetterSpacing(t){St("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),ti.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,n=ti.measureText(this._text||" ",this._style,this._style.wordWrap,this.canvas),s=n.width,o=n.height,a=n.lines,l=n.lineHeight,h=n.lineWidths,c=n.maxLineWidth,u=n.fontProperties;this.canvas.width=Math.ceil(Math.ceil(Math.max(1,s)+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 g=0;g<p;++g){const y=e.dropShadow&&g===0,_=y?Math.ceil(Math.max(1,o)+e.padding*2):0,v=_*this._resolution;if(y){i.fillStyle="black",i.strokeStyle="black";const x=e.dropShadowColor,S=e.dropShadowBlur*this._resolution,R=e.dropShadowDistance*this._resolution;i.shadowColor=Mt.shared.setValue(x).setAlpha(e.dropShadowAlpha).toRgbaString(),i.shadowBlur=S,i.shadowOffsetX=Math.cos(e.dropShadowAngle)*R,i.shadowOffsetY=Math.sin(e.dropShadowAngle)*R+v}else i.fillStyle=this._generateFillStyle(e,a,n),i.strokeStyle=e.stroke,i.shadowColor="black",i.shadowBlur=0,i.shadowOffsetX=0,i.shadowOffsetY=0;let m=(l-u.fontSize)/2;l-u.fontSize<0&&(m=0);for(let x=0;x<a.length;x++)d=e.strokeThickness/2,f=e.strokeThickness/2+x*l+u.ascent+m,e.align==="right"?d+=c-h[x]:e.align==="center"&&(d+=(c-h[x])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(a[x],d+e.padding,f+e.padding-_,!0),e.fill&&this.drawLetterSpacing(a[x],d+e.padding,f+e.padding-_)}this.updateTexture()}drawLetterSpacing(t,e,i,n=!1){const s=this._style.letterSpacing;let o=!1;if(ti.experimentalLetterSpacingSupported&&(ti.experimentalLetterSpacing?(this.context.letterSpacing=`${s}px`,this.context.textLetterSpacing=`${s}px`,o=!0):(this.context.letterSpacing="0px",this.context.textLetterSpacing="0px")),s===0||o){n?this.context.strokeText(t,e,i):this.context.fillText(t,e,i);return}let a=e;const l=ti.graphemeSegmenter(t);let h=this.context.measureText(t).width,c=0;for(let u=0;u<l.length;++u){const d=l[u];n?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+s,h=c}}updateTexture(){const t=this.canvas;if(this._style.trim){const o=dE(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,n=i.trim?0:i.padding,s=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=-n,e.trim.y=-n,e.orig.width=e._frame.width-n*2,e.orig.height=e._frame.height-n*2,this._onTextureUpdate(),s.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 n=t.fill;if(Array.isArray(n)){if(n.length===1)return n[0]}else return n;let s;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=n.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(n[0]),u.unshift(0),c.push(n[n.length-1]),u.push(1),t.fillGradientType===Xo.LINEAR_VERTICAL){s=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,g=i.lineHeight*f;let y=g;f>0&&p>g&&(y=(g+p)/2);const _=g+d,v=i.lineHeight*(f+1);let m=_;f+1<e.length&&v<_&&(m=(_+v)/2);const x=(m-y)/h;for(let S=0;S<c.length;S++){let R=0;typeof u[S]=="number"?R=u[S]:R=S/c.length;let C=Math.min(1,Math.max(0,y/h+R*x));C=Number(C.toFixed(5)),s.addColorStop(C,c[S])}}}else{s=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 g;typeof u[p]=="number"?g=u[p]:g=f/d,s.addColorStop(g,c[p]),f++}}return s}destroy(t){typeof t=="boolean"&&(t={children:t}),t=Object.assign({},WS,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=zr(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=zr(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 ei?this._style=t:this._style=new ei(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)}};Rm.defaultAutoResolution=!0;let Mm=Rm;class YS{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function zS(r,t){var i;let e=!1;if((i=r==null?void 0:r._textures)!=null&&i.length){for(let n=0;n<r._textures.length;n++)if(r._textures[n]instanceof dt){const s=r._textures[n].baseTexture;t.includes(s)||(t.push(s),e=!0)}}return e}function qS(r,t){if(r.baseTexture instanceof xt){const e=r.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function KS(r,t){if(r._texture&&r._texture instanceof dt){const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function ZS(r,t){return t instanceof Mm?(t.updateText(!0),!0):!1}function JS(r,t){if(t instanceof ei){const e=t.toFontString();return ti.measureFont(e),!0}return!1}function QS(r,t){if(r instanceof Mm){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 t2(r,t){return r instanceof ei?(t.includes(r)||t.push(r),!0):!1}const Om=class pg{constructor(t){this.limiter=new YS(pg.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(QS),this.registerFindHook(t2),this.registerFindHook(zS),this.registerFindHook(qS),this.registerFindHook(KS),this.registerUploadHook(ZS),this.registerUploadHook(JS)}upload(t){return new Promise(e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,Fe.system.addOnce(this.tick,this,Pi.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,n=this.uploadHooks.length;i<n;i++)if(this.uploadHooks[i](this.uploadHookHelper,t)){this.queue.shift(),e=!0;break}}e||this.queue.shift()}if(this.queue.length)Fe.system.addOnce(this.tick,this,Pi.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 Ze)for(let e=t.children.length-1;e>=0;e--)this.add(t.children[e]);return this}destroy(){this.ticking&&Fe.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}};Om.uploadsPerFrame=4;let kh=Om;Object.defineProperties(tt,{UPLOADS_PER_FRAME:{get(){return kh.uploadsPerFrame},set(r){St("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),kh.uploadsPerFrame=r}}});function Bm(r,t){return t instanceof xt?(t._glTextures[r.CONTEXT_UID]||r.texture.bind(t),!0):!1}function e2(r,t){if(!(t instanceof ps))return!1;const{geometry:e}=t;t.finishPoly(),e.updateBatches();const{batches:i}=e;for(let n=0;n<i.length;n++){const{texture:s}=i[n].style;s&&Bm(r,s.baseTexture)}return e.batchable||r.geometry.bind(e,t._resolveDirectShader(r)),!0}function r2(r,t){return r instanceof ps?(t.push(r),!0):!1}class Lm extends kh{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(r2),this.registerUploadHook(Bm),this.registerUploadHook(e2)}}Lm.extension={name:"prepare",type:K.RendererSystem},ut.add(Lm);var i2=`#version 300 es
969
+ `:t,t}static getFromCache(t,e,i,n){let s=i[t];return typeof s!="number"&&(s=pt._measureText(t,e,n)+e,i[t]=s),s}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(!pt.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static isNewline(t){return typeof t!="string"?!1:pt._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:pt._breakingSpaces.includes(t.charCodeAt(0))}static tokenize(t){const e=[];let i="";if(typeof t!="string")return e;for(let n=0;n<t.length;n++){const s=t[n],o=t[n+1];if(pt.isBreakingSpace(s,o)||pt.isNewline(s)){i!==""&&(e.push(i),i=""),e.push(s);continue}i+=s}return i!==""&&e.push(i),e}static canBreakWords(t,e){return e}static canBreakChars(t,e,i,n,s){return!0}static wordWrapSplit(t){return pt.graphemeSegmenter(t)}static measureFont(t){if(pt._fonts[t])return pt._fonts[t];const e={ascent:0,descent:0,fontSize:0},i=pt._canvas,n=pt._context;n.font=t;const s=pt.METRICS_STRING+pt.BASELINE_SYMBOL,o=Math.ceil(n.measureText(s).width);let a=Math.ceil(n.measureText(pt.BASELINE_SYMBOL).width);const l=Math.ceil(pt.HEIGHT_MULTIPLIER*a);if(a=a*pt.BASELINE_MULTIPLIER|0,o===0||l===0)return pt._fonts[t]=e,e;i.width=o,i.height=l,n.fillStyle="#f00",n.fillRect(0,0,o,l),n.font=t,n.textBaseline="alphabetic",n.fillStyle="#000",n.fillText(s,0,a);const h=n.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 g=0;g<u;g+=4)if(h[f+g]!==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 g=0;g<u;g+=4)if(h[f+g]!==255){p=!0;break}if(!p)f-=u;else break}return e.descent=d-a,e.fontSize=e.ascent+e.descent,pt._fonts[t]=e,e}static clearMetrics(t=""){t?delete pt._fonts[t]:pt._fonts={}}static get _canvas(){var t;if(!pt.__canvas){let e;try{const i=new OffscreenCanvas(0,0);if((t=i.getContext("2d",jo))!=null&&t.measureText)return pt.__canvas=i,i;e=tt.ADAPTER.createCanvas()}catch{e=tt.ADAPTER.createCanvas()}e.width=e.height=10,pt.__canvas=e}return pt.__canvas}static get _context(){return pt.__context||(pt.__context=pt._canvas.getContext("2d",jo)),pt.__context}};_r.METRICS_STRING="|ÉqÅ",_r.BASELINE_SYMBOL="M",_r.BASELINE_MULTIPLIER=1.4,_r.HEIGHT_MULTIPLIER=2,_r.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]})(),_r.experimentalLetterSpacing=!1,_r._fonts={},_r._newlines=[10,13],_r._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let ti=_r;const XS=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],Pm=class vs{constructor(t){this.styleID=0,this.reset(),Fh(this,t,t)}clone(){const t={};return Fh(t,this,vs.defaultStyle),new vs(t)}reset(){Fh(this,vs.defaultStyle,vs.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=Nh(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=Nh(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){jS(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=Nh(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 n=e[i].trim();!/([\"\'])[^\'\"]+\1/.test(n)&&!XS.includes(n)&&(n=`"${n}"`),e[i]=n}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};Pm.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Xo.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 ei=Pm;function Nh(r){const t=Mt.shared,e=i=>{const n=t.setValue(i);return n.alpha===1?n.toHex():n.toRgbaString()};return Array.isArray(r)?r.map(e):e(r)}function jS(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 Fh(r,t,e){for(const i in e)Array.isArray(t[i])?r[i]=t[i].slice():r[i]=t[i]}const WS={texture:!0,children:!1,baseTexture:!0},Rm=class tc extends gn{constructor(t,e,i){let n=!1;i||(i=tt.ADAPTER.createCanvas(),n=!0),i.width=3,i.height=3;const s=dt.from(i);s.orig=new wt,s.trim=new wt,super(s),this._ownCanvas=n,this.canvas=i,this.context=i.getContext("2d",{willReadFrequently:!0}),this._resolution=tc.defaultResolution??tt.RESOLUTION,this._autoResolution=tc.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 ti.experimentalLetterSpacing}static set experimentalLetterSpacing(t){St("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),ti.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,n=ti.measureText(this._text||" ",this._style,this._style.wordWrap,this.canvas),s=n.width,o=n.height,a=n.lines,l=n.lineHeight,h=n.lineWidths,c=n.maxLineWidth,u=n.fontProperties;this.canvas.width=Math.ceil(Math.ceil(Math.max(1,s)+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 g=0;g<p;++g){const y=e.dropShadow&&g===0,_=y?Math.ceil(Math.max(1,o)+e.padding*2):0,v=_*this._resolution;if(y){i.fillStyle="black",i.strokeStyle="black";const x=e.dropShadowColor,S=e.dropShadowBlur*this._resolution,R=e.dropShadowDistance*this._resolution;i.shadowColor=Mt.shared.setValue(x).setAlpha(e.dropShadowAlpha).toRgbaString(),i.shadowBlur=S,i.shadowOffsetX=Math.cos(e.dropShadowAngle)*R,i.shadowOffsetY=Math.sin(e.dropShadowAngle)*R+v}else i.fillStyle=this._generateFillStyle(e,a,n),i.strokeStyle=e.stroke,i.shadowColor="black",i.shadowBlur=0,i.shadowOffsetX=0,i.shadowOffsetY=0;let m=(l-u.fontSize)/2;l-u.fontSize<0&&(m=0);for(let x=0;x<a.length;x++)d=e.strokeThickness/2,f=e.strokeThickness/2+x*l+u.ascent+m,e.align==="right"?d+=c-h[x]:e.align==="center"&&(d+=(c-h[x])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(a[x],d+e.padding,f+e.padding-_,!0),e.fill&&this.drawLetterSpacing(a[x],d+e.padding,f+e.padding-_)}this.updateTexture()}drawLetterSpacing(t,e,i,n=!1){const s=this._style.letterSpacing;let o=!1;if(ti.experimentalLetterSpacingSupported&&(ti.experimentalLetterSpacing?(this.context.letterSpacing=`${s}px`,this.context.textLetterSpacing=`${s}px`,o=!0):(this.context.letterSpacing="0px",this.context.textLetterSpacing="0px")),s===0||o){n?this.context.strokeText(t,e,i):this.context.fillText(t,e,i);return}let a=e;const l=ti.graphemeSegmenter(t);let h=this.context.measureText(t).width,c=0;for(let u=0;u<l.length;++u){const d=l[u];n?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+s,h=c}}updateTexture(){const t=this.canvas;if(this._style.trim){const o=dE(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,n=i.trim?0:i.padding,s=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=-n,e.trim.y=-n,e.orig.width=e._frame.width-n*2,e.orig.height=e._frame.height-n*2,this._onTextureUpdate(),s.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 n=t.fill;if(Array.isArray(n)){if(n.length===1)return n[0]}else return n;let s;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=n.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(n[0]),u.unshift(0),c.push(n[n.length-1]),u.push(1),t.fillGradientType===Xo.LINEAR_VERTICAL){s=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,g=i.lineHeight*f;let y=g;f>0&&p>g&&(y=(g+p)/2);const _=g+d,v=i.lineHeight*(f+1);let m=_;f+1<e.length&&v<_&&(m=(_+v)/2);const x=(m-y)/h;for(let S=0;S<c.length;S++){let R=0;typeof u[S]=="number"?R=u[S]:R=S/c.length;let C=Math.min(1,Math.max(0,y/h+R*x));C=Number(C.toFixed(5)),s.addColorStop(C,c[S])}}}else{s=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 g;typeof u[p]=="number"?g=u[p]:g=f/d,s.addColorStop(g,c[p]),f++}}return s}destroy(t){typeof t=="boolean"&&(t={children:t}),t=Object.assign({},WS,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=zr(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=zr(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 ei?this._style=t:this._style=new ei(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)}};Rm.defaultAutoResolution=!0;let Mm=Rm;class YS{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function zS(r,t){var i;let e=!1;if((i=r==null?void 0:r._textures)!=null&&i.length){for(let n=0;n<r._textures.length;n++)if(r._textures[n]instanceof dt){const s=r._textures[n].baseTexture;t.includes(s)||(t.push(s),e=!0)}}return e}function qS(r,t){if(r.baseTexture instanceof xt){const e=r.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function KS(r,t){if(r._texture&&r._texture instanceof dt){const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function ZS(r,t){return t instanceof Mm?(t.updateText(!0),!0):!1}function JS(r,t){if(t instanceof ei){const e=t.toFontString();return ti.measureFont(e),!0}return!1}function QS(r,t){if(r instanceof Mm){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 t2(r,t){return r instanceof ei?(t.includes(r)||t.push(r),!0):!1}const Om=class pg{constructor(t){this.limiter=new YS(pg.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(QS),this.registerFindHook(t2),this.registerFindHook(zS),this.registerFindHook(qS),this.registerFindHook(KS),this.registerUploadHook(ZS),this.registerUploadHook(JS)}upload(t){return new Promise(e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,ke.system.addOnce(this.tick,this,Pi.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,n=this.uploadHooks.length;i<n;i++)if(this.uploadHooks[i](this.uploadHookHelper,t)){this.queue.shift(),e=!0;break}}e||this.queue.shift()}if(this.queue.length)ke.system.addOnce(this.tick,this,Pi.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 Ze)for(let e=t.children.length-1;e>=0;e--)this.add(t.children[e]);return this}destroy(){this.ticking&&ke.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}};Om.uploadsPerFrame=4;let kh=Om;Object.defineProperties(tt,{UPLOADS_PER_FRAME:{get(){return kh.uploadsPerFrame},set(r){St("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),kh.uploadsPerFrame=r}}});function Bm(r,t){return t instanceof xt?(t._glTextures[r.CONTEXT_UID]||r.texture.bind(t),!0):!1}function e2(r,t){if(!(t instanceof ps))return!1;const{geometry:e}=t;t.finishPoly(),e.updateBatches();const{batches:i}=e;for(let n=0;n<i.length;n++){const{texture:s}=i[n].style;s&&Bm(r,s.baseTexture)}return e.batchable||r.geometry.bind(e,t._resolveDirectShader(r)),!0}function r2(r,t){return r instanceof ps?(t.push(r),!0):!1}class Lm extends kh{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(r2),this.registerUploadHook(Bm),this.registerUploadHook(e2)}}Lm.extension={name:"prepare",type:K.RendererSystem},ut.add(Lm);var i2=`#version 300 es
970
970
  #define SHADER_NAME Tiling-Sprite-100
971
971
 
972
972
  precision lowp float;
@@ -1144,5 +1144,5 @@ void main(void)\r
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=oE(t)),typeof t=="number"?sE(t):t}dropShadowToCSS(){let t=this.normalizeColor(this.dropShadowColor);const e=this.dropShadowAlpha,i=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),n=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);t.startsWith("#")&&e<1&&(t+=(e*255|0).toString(16).padStart(2,"0"));const s=`${i}px ${n}px`;return this.dropShadowBlur>0?`text-shadow: ${s} ${this.dropShadowBlur}px ${t}`:`text-shadow: ${s} ${t}`}reset(){Object.assign(this,Cn.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}=tt.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}};Hh.availableFonts={},Hh.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 Vh=Hh;const Ko=class In extends gn{constructor(t="",e={}){super(dt.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,n=dt.from(i,{scaleMode:tt.SCALE_MODE,resourceOptions:{autoLoad:!1}});n.orig=new wt,n.trim=new wt,this.texture=n;const s="http://www.w3.org/2000/svg",o="http://www.w3.org/1999/xhtml",a=document.createElementNS(s,"svg"),l=document.createElementNS(s,"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=In.defaultMaxWidth,this.maxHeight=In.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=In.defaultAutoResolution,this._resolution=In.defaultResolution??tt.RESOLUTION,this.text=t,this.style=e}measureText(t){var c,u;const{text:e,style:i,resolution:n}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:e,style:i.toCSS(n)}),this._styleElement.textContent=i.toGlobalCSS(),document.body.appendChild(this._svgRoot);const s=this._domElement.getBoundingClientRect();this._svgRoot.remove();const{width:o,height:a}=s;(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(n)}),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:n}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:s,height:o}=this.measureText();i.width=n.width=Math.ceil(Math.max(1,s)),i.height=n.height=Math.ceil(Math.max(1,o)),this._updateID++;const a=this._updateID;await new Promise(l=>{n.onload=async()=>{if(a<this._updateID){l();return}await e.onBeforeDraw(),i.src=n.src,n.onload=null,n.src="",this.updateTexture(),l()};const h=new XMLSerializer().serializeToString(this._svgRoot);n.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(h)}`})}get source(){return this._image}updateTexture(){const{style:t,texture:e,_image:i,resolution:n}=this,{padding:s}=t,{baseTexture:o}=e;e.trim.width=e._frame.width=i.width/n,e.trim.height=e._frame.height=i.height/n,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(),o.setRealSize(i.width,i.height,n),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,n,s,o,a;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},In.defaultDestroyOptions,t),super.destroy(t);const e=null;this.ownsStyle&&((i=this._style)==null||i.cleanFonts()),this._style=e,(n=this._svgRoot)==null||n.remove(),this._svgRoot=e,(s=this._domElement)==null||s.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=zr(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=zr(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 Vh?(this.ownsStyle=!1,this._style=t):t instanceof ei?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=Vh.from(t)):(this.ownsStyle=!0,this._style=new Vh(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;")}};Ko.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},Ko.defaultMaxWidth=2024,Ko.defaultMaxHeight=2024,Ko.defaultAutoResolution=!0;const _2=16777215,v2=.25,b2=16777215,x2=1,w2=1.5;let ni=!1,Bi;const Xh=r=>{const t={tint:r!=null&&r.fill?new Mt(r.fill).toNumber():_2,alpha:(r==null?void 0:r.fillOpacity)!==void 0?Math.min(r.fillOpacity,1):String(r==null?void 0:r.fill).toLowerCase().startsWith("rgba(")?new Mt(r==null?void 0:r.fill).alpha:v2},e={tint:r!=null&&r.stroke?new Mt(r.stroke).toNumber():b2,alpha:(r==null?void 0:r.strokeOpacity)!==void 0?Math.min(r.strokeOpacity,1):String(r==null?void 0:r.stroke).toLowerCase().startsWith("rgba(")?new Mt(r==null?void 0:r.stroke).alpha:x2,lineWidth:(r==null?void 0:r.strokeWidth)===void 0?w2:r.strokeWidth};return{fillStyle:t,strokeStyle:e}},Tn=r=>(t,e,i,n={})=>{const{fillStyle:s,strokeStyle:o}=Xh(i),a=new ps;n.strokeOnly||(a.beginFill(16777215),r(e,a),a.endFill(),a.tint=s.tint,a.alpha=s.alpha),t.addChild(a);const l=new ps,h=o.lineWidth===1?1:o.lineWidth/Bi;return l.lineStyle(h,16777215,1,.5,o.lineWidth===1),r(e,l),l.tint=o.tint||16777215,l.alpha=o.alpha,t.addChild(l),{fill:a,stroke:l,strokeWidth:o.lineWidth}},E2=Tn((r,t)=>{const{x:e,y:i,w:n,h:s,rot:o=0}=r.geometry;o===0?t.drawRect(e,i,n,s):(t.position.set(e+n/2,i+s/2),t.rotation=o,t.drawRect(-n/2,-s/2,n,s))}),T2=Tn((r,t)=>{const{cx:e,cy:i,rx:n,ry:s}=r.geometry;t.drawEllipse(e,i,n,s)}),A2=Tn((r,t)=>{const[[e,i],[n,s]]=r.geometry.points;t.moveTo(e,i),t.lineTo(n,s),t.closePath()}),S2=Tn((r,t)=>{const e=r.geometry.points.reduce((i,n)=>[...i,...n],[]);t.drawPolygon(e)}),C2=Tn((r,t)=>{const{points:e,closed:i}=r.geometry;if(e.length===0)return;i||t.beginFill(0,0);const n=(o,a)=>{const[l,h]=o.point,[c,u]=a.point;if(o.type==="CURVE"||a.type==="CURVE"){const d=o.type==="CURVE"&&o.outHandle?o.outHandle[0]:l,f=o.type==="CURVE"&&o.outHandle?o.outHandle[1]:h,p=a.type==="CURVE"&&a.inHandle?a.inHandle[0]:c,g=a.type==="CURVE"&&a.inHandle?a.inHandle[1]:u;t.bezierCurveTo(d,f,p,g,c,u)}else t.lineTo(c,u)},s=e[0];t.moveTo(s.point[0],s.point[1]);for(let o=1;o<e.length;o++){const a=e[o-1],l=e[o];n(a,l)}if(i&&e.length>2){const o=e[e.length-1],a=e[0];n(o,a),t.closePath()}else t.endFill()}),I2=Tn((r,t)=>{const e=i=>i.points.reduce((n,s)=>[...n,...s],[]);r.geometry.polygons.forEach(i=>{const[n,...s]=i.rings;t.drawPolygon(e(n)),s.forEach(o=>{t.beginHole(),t.drawPolygon(e(o)),t.endHole()})})}),jh=r=>{const t=r.viewport.getContainerSize().x;return r.viewport.getZoom(!0)*t/r.world.getContentFactor()},Xm=(r,t,e,i)=>()=>{const n=r.viewport.viewportToImageRectangle(r.viewport.getBounds(!0)),s=jh(r);(s!==Bi||!ni)&&(ni=!0,e.forEach(({stroke:d,strokeWidth:f})=>{const{lineStyle:p}=d.geometry.graphicsData[0];f>1?(ni=s===Bi,p.width=f/s,p.native=!1,d.geometry.invalidate()):f===1&&!p.native&&(p.width=1,p.native=!0,d.geometry.invalidate())})),Bi=s;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+n.x*s:-n.x*s,h=-n.y*s;let c,u;a>0&&a<=Math.PI/2?(c=n.height*s,u=0):a>Math.PI/2&&a<=Math.PI?(c=n.width*s,u=n.height*s):a>Math.PI&&a<=Math.PI*1.5?(c=0,u=n.width*s):(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?-s:s,s),t.rotation=a,i.render(t)},P2=(r,t)=>{const e=new ps,i=$p({width:t.width,height:t.height,backgroundAlpha:0,view:t,antialias:!0,resolution:2}),n=new Map;let s=new Set,o,a;Bi=jh(r);const l=(m,x)=>{Bi=jh(r),ni=!1;const S=n.get(m.id);S&&(S.fill.destroy(),S.stroke.destroy());const{selector:R}=m.target,C=typeof a=="function"?a(m,x):a;let I;if(R.type===_t.RECTANGLE)I=E2(e,R,C);else if(R.type===_t.POLYGON)I=S2(e,R,C);else if(R.type===_t.ELLIPSE)I=T2(e,R,C);else if(R.type===_t.MULTIPOLYGON)I=I2(e,R,C);else if(R.type===_t.POLYLINE){const M=R;I=C2(e,M,C,{strokeOnly:!M.geometry.closed})}else R.type===_t.LINE?I=A2(e,R,C):console.warn(`Unsupported shape type: ${R.type}`);I&&n.set(m.id,{annotation:m,...I})},h=m=>{const x=n.get(m.id);x&&(n.delete(m.id),x.fill.destroy(),x.stroke.destroy())},c=(m,x,S)=>{ni=!1;const R=n.get(m.id);if(R&&(n.delete(m.id),R.fill.destroy(),R.stroke.destroy(),l(x,S),s.has(x.id))){const{fill:C,stroke:I}=n.get(x.id);e.removeChild(C),e.removeChild(I)}},u=(m,x)=>{const S=n.get(m);S&&(n.delete(m),S.fill.destroy(),S.stroke.destroy(),l(S.annotation,x))},d=(m,x)=>{i.resize(m,x),i.render(e)},f=m=>{ni=!1;const{children:x}=e;n.forEach(({fill:S,stroke:R,annotation:C})=>{const I=m?s.has(C.id)||m(C):!0;I&&!x.includes(S)?(e.addChild(S),e.addChild(R)):!I&&x.includes(S)&&(e.removeChild(S),e.removeChild(R))}),i.render(e)},p=m=>{const x=new Set(m.selected.filter(C=>C.editable).map(C=>C.id)),S=m.selected.filter(({id:C})=>!s.has(C)),R=[...s].filter(C=>!x.has(C));S.forEach(({id:C,editable:I})=>{if(I){const M=n.get(C);M&&Aa(M.annotation.target.selector)&&(e.removeChild(M.fill),e.removeChild(M.stroke))}else u(C,{selected:!0,hovered:C===o})}),R.forEach(C=>u(C,{hovered:C===o})),s=x,i.render(e)},g=m=>{o!==m&&(m&&s.has(m)||(o&&!s.has(o)&&u(o,{selected:s.has(o)}),m&&u(m,{selected:s.has(m),hovered:!0}),o=m,i.render(e)))},y=m=>{if(typeof m=="function")n.forEach(({annotation:x,fill:S,stroke:R,strokeWidth:C},I)=>{C>1&&(ni=!1);const M={selected:s.has(x.id),hovered:o===x.id},{fillStyle:F,strokeStyle:U}=Xh(m(x,M));S.tint=F.tint,S.alpha=F.alpha,R.tint=U.tint||16777215,R.alpha=U.alpha,n.set(x.id,{annotation:x,fill:S,stroke:R,strokeWidth:U.lineWidth})});else{const{fillStyle:x,strokeStyle:S}=Xh(m);S.lineWidth>1&&(ni=!1),n.forEach(({annotation:R,fill:C,stroke:I,strokeWidth:M},F)=>{C.tint=x.tint,C.alpha=x.alpha,I.tint=S.tint||16777215,I.alpha=S.alpha,n.set(R.id,{annotation:R,fill:C,stroke:I,strokeWidth:S.lineWidth})})}a=m,i.render(e),Xm(r,e,n,i)()},_=m=>{m?t.classList.remove("hidden"):t.classList.add("hidden")};return{addAnnotation:l,destroy:()=>i.destroy(),getScale:()=>Bi,redraw:Xm(r,e,n,i),removeAnnotation:h,resize:d,setFilter:f,setHovered:g,setSelected:p,setStyle:y,setVisible:_,updateAnnotation:c}};function R2(r,t,e){let i,n,{filter:s}=t,{state:o}=t,{style:a}=t,{viewer:l}=t,{visible:h=!0}=t;const{store:c,hover:u,selection:d,viewport:f}=o;Fn(r,u,I=>e(11,i=I)),Fn(r,d,I=>e(8,n=I));const p=Wi(),g=Ge?10:2;let y,_;const v=I=>{const M=new se.Point(I.x,I.y),{x:F,y:U}=l.viewport.pointFromPixel(M);return l.viewport.viewportToImageCoordinates(F,U)},m=()=>g/y.getScale(),x=I=>{const{x:M,y:F}=I.position;_={x:M,y:F}},S=I=>M=>{const{x:F,y:U}=v(new se.Point(M.offsetX,M.offsetY)),P=m(),T=c.getAt(F,U,s,P);T?(I.classList.add("hover"),i!==T.id&&(u.set(T.id),y.setHovered(T.id))):(I.classList.remove("hover"),i&&(u.set(void 0),y.setHovered(void 0)))},R=I=>{if(!_)return;const M=I.originalEvent,{x:F,y:U}=I.position,P=F-_.x,T=U-_.y;if(Math.sqrt(P*P+T*T)<5){const{x:A,y:L}=v(I.position),O=m(),D=c.getAt(A,L,s,O);D?p("click",{originalEvent:M,annotation:D}):p("click",{originalEvent:M})}_=void 0};let C;return Vr(()=>{var D;const{offsetWidth:I,offsetHeight:M}=l.canvas,F=document.createElement("canvas");F.width=I,F.height=M,F.className="a9s-gl-canvas",(D=l.element.querySelector(".openseadragon-canvas"))==null||D.appendChild(F),e(7,y=P2(l,F));const U=S(F);F.addEventListener("pointermove",U);const P=new ResizeObserver($=>{try{const{width:B,height:N}=$[0].contentRect;F.width=B,F.height=N,y.resize(B,N)}catch{console.warn("WebGL canvas already disposed")}});P.observe(F);const T=()=>{const $=l.viewport.getBounds();C=l.viewport.viewportToImageRectangle($);const{x:B,y:N,width:k,height:V}=C,j=c.getIntersecting(B,N,k,V);f.set(j.map(st=>st.id))};l.addHandler("canvas-press",x),l.addHandler("canvas-release",R),l.addHandler("update-viewport",y.redraw),l.addHandler("animation-finish",T);const w=$=>$.filter(B=>Ue(B)),A=$=>Ue($.oldValue)&&Ue($.newValue),L=$=>{const{selector:B}=$.target;if(B.type===_t.POLYGON){const N=Tv(B);return{...$,target:{...$.target,selector:{...N}}}}else if(B.type===_t.MULTIPOLYGON){const N=wv(B);return{...$,target:{...$.target,selector:{...N}}}}else return $},O=$=>{const{created:B,updated:N,deleted:k}=$.changes,V=(B||[]).filter(j=>Ue(j)).map(L);if(w(k||[]).forEach(j=>y.removeAnnotation(j)),V.forEach(j=>y.addAnnotation(j)),(N||[]).filter(j=>A(j)).map(({oldValue:j,newValue:st})=>({oldValue:j,newValue:L(st)})).forEach(({oldValue:j,newValue:st})=>y.updateAnnotation(j,st)),C){const{x:j,y:st,width:H,height:at}=C,X=c.getIntersecting(j,st,H,at);f.set(X.map(gt=>gt.id))}else f.set(c.all().map(j=>j.id));y.redraw()};return c.observe(O),()=>{var $;F.removeEventListener("pointermove",U),P.disconnect(),l.removeHandler("canvas-press",x),l.removeHandler("canvas-release",R),l.removeHandler("update-viewport",y.redraw),l.removeHandler("animation-finish",T),c.unobserve(O),y.destroy(),($=F.parentNode)==null||$.removeChild(F)}}),r.$$set=I=>{"filter"in I&&e(2,s=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&&(y==null||y.setFilter(s)),r.$$.dirty&384&&(y==null||y.setSelected(n)),r.$$.dirty&144&&(y==null||y.setStyle(a)),r.$$.dirty&192&&(y==null||y.setVisible(h))},[u,d,s,o,a,l,h,y,n]}class M2 extends Yt{constructor(t){super(),Wt(this,t,R2,null,Ut,{filter:2,state:3,style:4,viewer:5,visible:6})}}const jm=(r,t,e,i)=>{if(!i)return r;if(t.shiftKey||t.ctrlKey||t.metaKey){const s=(e.selected||[]).map(o=>o.id);return s.includes(r)?s.filter(o=>o!==r):[...s,r]}else return r},O2=r=>({transform:r&2,scale:r&1}),Wm=r=>({transform:r[1],scale:r[0]});function B2(r){let t;const e=r[4].default,i=Tu(e,r,r[3],Wm);return{c(){i&&i.c()},m(n,s){i&&i.m(n,s),t=!0},p(n,[s]){i&&i.p&&(!t||s&11)&&Cu(i,e,n,n[3],t?Su(e,n[3],s,O2):Iu(n[3]),Wm)},i(n){t||(q(i,n),t=!0)},o(n){nt(i,n),t=!1},d(n){i&&i.d(n)}}}function L2(r,t,e){let{$$slots:i={},$$scope:n}=t,{viewer:s}=t,o=1,a;const l=()=>{const h=s.viewport.getContainerSize().x,c=s.viewport.getZoom(!0),u=s.viewport.getFlip(),d=s.viewport.pixelFromPoint(new se.Point(0,0),!0);u&&(d.x=h-d.x);const f=c*h/s.world.getContentFactor(),p=u?-f:f,g=s.viewport.getRotation(!0);e(1,a=`translate(${d.x}, ${d.y}) scale(${p}, ${f}) rotate(${g})`),e(0,o=c*h/s.world.getContentFactor())};return Vr(()=>(s.addHandler("update-viewport",l),()=>{s.removeHandler("update-viewport",l)})),r.$$set=h=>{"viewer"in h&&e(2,s=h.viewer),"$$scope"in h&&e(3,n=h.$$scope)},[o,a,s,n,i]}class Wh extends Yt{constructor(t){super(),Wt(this,t,L2,B2,Ut,{viewer:2})}}function D2(r,t,e){const i=Wi();let{drawingMode:n}=t,{opts:s}=t,{target:o}=t,{tool:a}=t,{transform:l}=t,{viewer:h}=t,{viewportScale:c}=t,u;return Vr(()=>{const d=o.closest("svg"),f=[],p=(g,y,_)=>{if(d==null||d.addEventListener(g,y,_),f.push(()=>d==null?void 0:d.removeEventListener(g,y,_)),g==="pointerup"||g==="dblclick"){const v=x=>{const{originalEvent:S}=x;y(S)},m=g==="pointerup"?"canvas-click":"canvas-double-click";h.addHandler(m,v),f.push(()=>h.removeHandler(m,v))}else if(g==="pointermove"){const v=m=>{const{originalEvent:x}=m;y(x)};h.addHandler("canvas-drag",v),f.push(()=>h.removeHandler("canvas-drag",v))}};return e(7,u=new a({target:o,props:{addEventListener:p,drawingMode:n,opts:s,transform:l,viewportScale:c,svgEl:d}})),u.$on("create",g=>i("create",g.detail)),()=>{f.forEach(g=>g()),u.$destroy()}}),r.$$set=d=>{"drawingMode"in d&&e(0,n=d.drawingMode),"opts"in d&&e(1,s=d.opts),"target"in d&&e(2,o=d.target),"tool"in d&&e(3,a=d.tool),"transform"in d&&e(4,l=d.transform),"viewer"in d&&e(5,h=d.viewer),"viewportScale"in d&&e(6,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&144&&u&&u.$set({transform:l}),r.$$.dirty&192&&u&&u.$set({viewportScale:c})},[n,s,o,a,l,h,c,u]}class N2 extends Yt{constructor(t){super(),Wt(this,t,D2,null,Ut,{drawingMode:0,opts:1,target:2,tool:3,transform:4,viewer:5,viewportScale:6})}}const{Boolean:F2}=Oa;function Ym(r,t,e){const i=r.slice();i[41]=t[e];const n=i[19](i[41].target.selector);return i[42]=n,i}function k2(r){let t=`${r[2]}-${r[7]}`,e,i,n=zm(r);return{c(){n.c(),e=Be()},m(s,o){n.m(s,o),ot(s,e,o),i=!0},p(s,o){o[0]&132&&Ut(t,t=`${s[2]}-${s[7]}`)?(le(),nt(n,1,1,Nt),he(),n=zm(s),n.c(),q(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n.d(s)}}}function U2(r){let t,e,i=Ae(r[9].filter(r[29])),n=[];for(let o=0;o<i.length;o+=1)n[o]=Zm(Ym(r,i,o));const s=o=>nt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Be()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a[0]&713474|a[1]&512){i=Ae(o[9].filter(o[29]));let l;for(l=0;l<i.length;l+=1){const h=Ym(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=Zm(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(F2);for(let a=0;a<n.length;a+=1)nt(n[a]);e=!1},d(o){o&&it(t),$r(n,o)}}}function zm(r){let t,e;return t=new N2({props:{target:r[8],tool:r[10],drawingMode:r[4],transform:{elementToImage:r[13]},viewer:r[3],viewportScale:r[40],opts:r[5]}}),t.$on("create",r[18]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&1024&&(s.tool=i[10]),n[0]&16&&(s.drawingMode=i[4]),n[0]&8&&(s.viewer=i[3]),n[1]&512&&(s.viewportScale=i[40]),n[0]&32&&(s.opts=i[5]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function qm(r){let t=r[41].id,e,i,n=Km(r);return{c(){n.c(),e=Be()},m(s,o){n.m(s,o),ot(s,e,o),i=!0},p(s,o){o[0]&512&&Ut(t,t=s[41].id)?(le(),nt(n,1,1,Nt),he(),n=Km(s),n.c(),q(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n.d(s)}}}function Km(r){let t,e;return t=new m1({props:{target:r[8],editor:r[19](r[41].target.selector),annotation:r[41],style:r[1],transform:{elementToImage:r[13]},viewportScale:r[40]}}),t.$on("grab",r[14]),t.$on("change",function(){jt(r[17](r[41]))&&r[17](r[41]).apply(this,arguments)}),t.$on("release",r[15]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&512&&(s.editor=r[19](r[41].target.selector)),n[0]&512&&(s.annotation=r[41]),n[0]&2&&(s.style=r[1]),n[1]&512&&(s.viewportScale=r[40]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function Zm(r){let t,e,i=r[42]&&qm(r);return{c(){i&&i.c(),t=Be()},m(n,s){i&&i.m(n,s),ot(n,t,s),e=!0},p(n,s){n[42]?i?(i.p(n,s),s[0]&512&&q(i,1)):(i=qm(n),i.c(),q(i,1),i.m(t.parentNode,t)):i&&(le(),nt(i,1,1,()=>{i=null}),he())},i(n){e||(q(i),e=!0)},o(n){nt(i),e=!1},d(n){n&&it(t),i&&i.d(n)}}}function G2(r){let t,e,i,n,s,o,a,l;const h=[U2,k2],c=[];function u(d,f){var p;return d[8]&&((p=d[9])==null?void 0:p.length)===1?0:d[8]&&d[10]&&d[0]?1:-1}return~(i=u(r))&&(n=c[i]=h[i](r)),{c(){t=J("svg"),e=J("g"),n&&n.c(),E(e,"transform",s=r[39]),E(e,"class","svelte-g4ws1v"),E(t,"tabindex",0),E(t,"class","a9s-annotationlayer a9s-osd-drawinglayer svelte-g4ws1v"),Hr(t,"drawing",r[0]),Hr(t,"editing",r[9]),Hr(t,"hover",r[6])},m(d,f){ot(d,t,f),Tt(t,e),~i&&c[i].m(e,null),r[30](e),o=!0,a||(l=Pt(t,"pointermove",r[16]),a=!0)},p(d,f){let p=i;i=u(d),i===p?~i&&c[i].p(d,f):(n&&(le(),nt(c[p],1,1,()=>{c[p]=null}),he()),~i?(n=c[i],n?n.p(d,f):(n=c[i]=h[i](d),n.c()),q(n,1),n.m(e,null)):n=null),(!o||f[1]&256&&s!==(s=d[39]))&&E(e,"transform",s),(!o||f[0]&1)&&Hr(t,"drawing",d[0]),(!o||f[0]&512)&&Hr(t,"editing",d[9]),(!o||f[0]&64)&&Hr(t,"hover",d[6])},i(d){o||(q(n),o=!0)},o(d){nt(n),o=!1},d(d){d&&it(t),~i&&c[i].d(),r[30](null),a=!1,l()}}}function $2(r){let t,e;return t=new Wh({props:{viewer:r[3],$$slots:{default:[G2,({transform:i,scale:n})=>({39:i,40:n}),({transform:i,scale:n})=>[0,(i?256:0)|(n?512:0)]]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&8&&(s.viewer=i[3]),n[0]&2047|n[1]&17152&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function H2(r,t,e){let i,n,s,o,a,{drawingEnabled:l}=t,{filter:h}=t,{multiSelect:c}=t,{preferredDrawingMode:u}=t,{state:d}=t,{style:f=void 0}=t,{toolName:p=Rs()[0]}=t,{user:g}=t,{viewer:y}=t;const _=Ge?10:2;let v=!1,m=0;const x=()=>e(7,m+=1),S=()=>p,R=()=>l;let C;const{store:I,selection:M,hover:F}=d;Fn(r,M,H=>e(28,o=H)),Fn(r,F,H=>e(33,a=H));let U,P,T;const w=H=>{I.unobserve(U);const at=H.filter(({editable:X})=>X).map(({id:X})=>X);at.length>0?(e(9,P=at.map(X=>I.getAnnotation(X))),U=X=>{const{updated:gt}=X.changes;e(9,P=(gt||[]).map(lt=>lt.newValue))},I.observe(U,{annotations:at}),y.forceRedraw()):e(9,P=void 0)},A=(H,at)=>{const{x:X,y:gt}=y.viewport.viewerElementToImageCoordinates(new se.Point(H,at));return[X,gt]},L=()=>{const H=y.viewport.getContainerSize().x;return y.viewport.getZoom(!0)*H/y.world.getContentFactor()},O=()=>_/L(),D=H=>{y.setMouseNavEnabled(!1),T=H.timeStamp},$=H=>{if(y.setMouseNavEnabled(!0),performance.now()-(T||0)<300){const{offsetX:X,offsetY:gt}=H.detail,[lt,ft]=A(X,gt),ct=O(),Et=I.getAt(lt,ft,void 0,ct);if(Et&&(!h||h(Et))&&!P.find(Gt=>Gt.id===Et.id)){F.set(Et.id);const Gt=jm(Et.id,H.detail,M,c);M.userSelect(Gt)}}},B=H=>{const at=new se.Point(H.offsetX,H.offsetY),X=y.viewport.pointFromPixel(at),{x:gt,y:lt}=y.viewport.viewportToImageCoordinates(X.x,X.y),ft=O(),ct=I.getAt(gt,lt,h,ft);ct?a!==ct.id&&F.set(ct.id):a&&F.set(void 0)},N=H=>at=>{var ft;const{target:X}=H,gt=10*60*1e3,lt=((ft=X.creator)==null?void 0:ft.id)!==g.id||!X.created||new Date().getTime()-X.created.getTime()>gt;I.updateTarget({...X,selector:at.detail,created:lt?X.created:new Date,updated:lt?new Date:void 0,updatedBy:lt?g:void 0})},k=H=>{const at=Mv(),X={id:at,bodies:[],target:{annotation:at,selector:H.detail,creator:g,created:new Date}};I.addAnnotation(X),M.setSelected(X.id),y.setMouseNavEnabled(!0)},V=H=>Aa(H);Vr(()=>{const H=at=>{if(o.selected.length===0)return;const{offsetX:X,offsetY:gt}=at,lt=y.viewport.pointFromPixel(new se.Point(X,gt)),{x:ft,y:ct}=y.viewport.viewportToImageCoordinates(lt.x,lt.y),Et=O();e(6,v=!!I.getAt(ft,ct,h,Et))};return y.element.addEventListener("pointermove",H),()=>{var at;(at=y.element)==null||at.removeEventListener("pointermove",H)}});const j=H=>Ue(H);function st(H){Ls[H?"unshift":"push"](()=>{C=H,e(8,C)})}return r.$$set=H=>{"drawingEnabled"in H&&e(0,l=H.drawingEnabled),"filter"in H&&e(20,h=H.filter),"multiSelect"in H&&e(21,c=H.multiSelect),"preferredDrawingMode"in H&&e(22,u=H.preferredDrawingMode),"state"in H&&e(23,d=H.state),"style"in H&&e(1,f=H.style),"toolName"in H&&e(2,p=H.toolName),"user"in H&&e(24,g=H.user),"viewer"in H&&e(3,y=H.viewer)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(10,{tool:i,opts:n}=Ms(p)||{tool:void 0,opts:void 0},i,(e(5,n),e(2,p))),r.$$.dirty[0]&4194336&&e(4,s=(n==null?void 0:n.drawingMode)||u),r.$$.dirty[0]&25&&(l&&s==="drag"?y.setMouseNavEnabled(!1):y.setMouseNavEnabled(!0)),r.$$.dirty[0]&1&&l&&M.clear(),r.$$.dirty[0]&268435481&&o.selected.length===0&&s==="drag"&&l&&y.setMouseNavEnabled(!1),r.$$.dirty[0]&268435456&&w(o.selected)},[l,f,p,y,s,n,v,m,C,P,i,M,F,A,D,$,B,N,k,V,h,c,u,d,g,x,S,R,o,j,st]}class V2 extends Yt{constructor(t){super(),Wt(this,t,H2,$2,Ut,{drawingEnabled:0,filter:20,multiSelect:21,preferredDrawingMode:22,state:23,style:1,toolName:2,user:24,viewer:3,cancelDrawing:25,getDrawingTool:26,isDrawingEnabled:27},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[25]}get getDrawingTool(){return this.$$.ctx[26]}get isDrawingEnabled(){return this.$$.ctx[27]}}function X2(r){let t,e,i,n,s,o,a,l=r[2].appearance.label+"",h,c,u,d;return{c(){t=J("g"),e=J("rect"),a=J("text"),h=Ba(l),E(e,"class","a9s-presence-label-bg svelte-1rehw2p"),E(e,"x",r[0]),E(e,"y",i=r[1]-18/r[3]),E(e,"height",n=18/r[3]),E(e,"fill",s=r[2].appearance.color),E(e,"stroke",o=r[2].appearance.color),E(a,"font-size",c=12/r[3]),E(a,"x",u=r[0]+Math.round(5/r[3])),E(a,"y",d=r[1]-5/r[3]),E(a,"class","svelte-1rehw2p"),E(t,"class","a9s-presence-label")},m(f,p){ot(f,t,p),Tt(t,e),Tt(t,a),Tt(a,h),r[6](t)},p(f,[p]){p&1&&E(e,"x",f[0]),p&10&&i!==(i=f[1]-18/f[3])&&E(e,"y",i),p&8&&n!==(n=18/f[3])&&E(e,"height",n),p&4&&s!==(s=f[2].appearance.color)&&E(e,"fill",s),p&4&&o!==(o=f[2].appearance.color)&&E(e,"stroke",o),p&4&&l!==(l=f[2].appearance.label+"")&&ov(h,l),p&8&&c!==(c=12/f[3])&&E(a,"font-size",c),p&9&&u!==(u=f[0]+Math.round(5/f[3]))&&E(a,"x",u),p&10&&d!==(d=f[1]-5/f[3])&&E(a,"y",d)},i:Nt,o:Nt,d(f){f&&it(t),r[6](null)}}}function j2(r,t,e){let{x:i}=t,{y:n}=t,{user:s}=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){Ls[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,n=u.y),"user"in u&&e(2,s=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,n,s,o,l,a,c]}class Jm extends Yt{constructor(t){super(),Wt(this,t,j2,X2,Ut,{x:0,y:1,user:2,scale:3,hAlign:5})}}function W2(r){let t,e,i,n,s,o;return e=new Jm({props:{scale:r[1],user:r[0],x:r[3][0],y:r[3][1],hAlign:"CENTER"}}),{c(){t=J("g"),Lt(e.$$.fragment),i=J("polygon"),E(i,"class","a9s-presence-shape a9s-presence-polygon svelte-fgq4n0"),E(i,"stroke",n=r[0].appearance.color),E(i,"fill","transparent"),E(i,"points",s=r[2].points.map(Qm).join(" ")),E(t,"class","a9s-presence-overlay")},m(a,l){ot(a,t,l),Ot(e,t,null),Tt(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&&n!==(n=a[0].appearance.color))&&E(i,"stroke",n),(!o||l&4&&s!==(s=a[2].points.map(Qm).join(" ")))&&E(i,"points",s)},i(a){o||(q(e.$$.fragment,a),o=!0)},o(a){nt(e.$$.fragment,a),o=!1},d(a){a&&it(t),Bt(e)}}}const Qm=r=>r.join(",");function Y2(r,t,e){let i,n,{annotation:s}=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,s=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=s.target.selector.geometry),r.$$.dirty&4&&e(3,n=l(i))},[o,a,i,n,s]}class z2 extends Yt{constructor(t){super(),Wt(this,t,Y2,W2,Ut,{annotation:4,user:0,scale:1})}}function q2(r){let t,e,i,n,s,o,a,l,h;return e=new Jm({props:{scale:r[1],user:r[0],x:r[2].x,y:r[2].y}}),{c(){t=J("g"),Lt(e.$$.fragment),i=J("rect"),E(i,"class","a9s-presence-shape a9s-presence-rectangle svelte-gze948"),E(i,"stroke",n=r[0].appearance.color),E(i,"fill","transparent"),E(i,"x",s=r[2].x),E(i,"y",o=r[2].y),E(i,"width",a=r[2].w),E(i,"height",l=r[2].h),E(t,"class","a9s-presence-overlay")},m(c,u){ot(c,t,u),Ot(e,t,null),Tt(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&&n!==(n=c[0].appearance.color))&&E(i,"stroke",n),(!h||u&4&&s!==(s=c[2].x))&&E(i,"x",s),(!h||u&4&&o!==(o=c[2].y))&&E(i,"y",o),(!h||u&4&&a!==(a=c[2].w))&&E(i,"width",a),(!h||u&4&&l!==(l=c[2].h))&&E(i,"height",l)},i(c){h||(q(e.$$.fragment,c),h=!0)},o(c){nt(e.$$.fragment,c),h=!1},d(c){c&&it(t),Bt(e)}}}function K2(r,t,e){let i,{annotation:n}=t,{user:s}=t,{scale:o}=t;return r.$$set=a=>{"annotation"in a&&e(3,n=a.annotation),"user"in a&&e(0,s=a.user),"scale"in a&&e(1,o=a.scale)},r.$$.update=()=>{r.$$.dirty&8&&e(2,i=n.target.selector.geometry)},[s,o,i,n]}class Z2 extends Yt{constructor(t){super(),Wt(this,t,K2,q2,Ut,{annotation:3,user:0,scale:1})}}const{Boolean:J2}=Oa;function tg(r,t,e){const i=r.slice();return i[8]=t[e],i}function eg(r){let t,e;return t=new Wh({props:{viewer:r[0],$$slots:{default:[eC,({transform:i,scale:n})=>({6:i,7:n}),({transform:i,scale:n})=>(i?64:0)|(n?128:0)]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&1&&(s.viewer=i[0]),n&2244&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function rg(r){let t,e,i=Ae(r[2]),n=[];for(let o=0;o<i.length;o+=1)n[o]=ig(tg(r,i,o));const s=o=>nt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Be()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a&132){i=Ae(o[2]);let l;for(l=0;l<i.length;l+=1){const h=tg(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=ig(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(J2);for(let a=0;a<n.length;a+=1)nt(n[a]);e=!1},d(o){o&&it(t),$r(n,o)}}}function Q2(r){let t,e;return t=new z2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&4&&(s.annotation=i[8].annotation),n&4&&(s.user=i[8].selectedBy),n&128&&(s.scale=i[7]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function tC(r){let t,e;return t=new Z2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&4&&(s.annotation=i[8].annotation),n&4&&(s.user=i[8].selectedBy),n&128&&(s.scale=i[7]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function ig(r){let t,e,i,n;const s=[tC,Q2],o=[];function a(l,h){return l[8].annotation.target.selector.type===_t.RECTANGLE?0:l[8].annotation.target.selector.type===_t.POLYGON?1:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Be()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(le(),nt(o[c],1,1,()=>{o[c]=null}),he()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),q(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(q(e),n=!0)},o(l){nt(e),n=!1},d(l){l&&it(i),~t&&o[t].d(l)}}}function eC(r){let t,e,i,n,s=r[2].length>0&&rg(r);return{c(){t=J("svg"),e=J("g"),s&&s.c(),E(e,"transform",i=r[6]),E(t,"class","a9s-osd-presencelayer svelte-1krwc4m")},m(o,a){ot(o,t,a),Tt(t,e),s&&s.m(e,null),n=!0},p(o,a){o[2].length>0?s?(s.p(o,a),a&4&&q(s,1)):(s=rg(o),s.c(),q(s,1),s.m(e,null)):s&&(le(),nt(s,1,1,()=>{s=null}),he()),(!n||a&64&&i!==(i=o[6]))&&E(e,"transform",i)},i(o){n||(q(s),n=!0)},o(o){nt(s),n=!1},d(o){o&&it(t),s&&s.d()}}}function rC(r){let t=!!r[1],e,i,n=t&&eg(r);return{c(){n&&n.c(),e=Be()},m(s,o){n&&n.m(s,o),ot(s,e,o),i=!0},p(s,[o]){o&2&&(t=!!s[1]),t?n?(n.p(s,o),o&2&&q(n,1)):(n=eg(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),nt(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n&&n.d(s)}}}function iC(r,t,e){let{store:i}=t,{viewer:n}=t,{provider:s}=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(y=>y.id)),g=o.filter(({annotation:y})=>!p.has(y.id)).map(y=>{const _=(f||[]).find(v=>v.oldValue.id===y.annotation.id);return _?{selectedBy:y.selectedBy,annotation:_.newValue}:y});e(2,o=g)},i.observe(a,{annotations:o.map(u=>u.annotation.id)})};return lv(()=>{a&&i.unobserve(a)}),r.$$set=h=>{"store"in h&&e(3,i=h.store),"viewer"in h&&e(0,n=h.viewer),"provider"in h&&e(1,s=h.provider)},r.$$.update=()=>{r.$$.dirty&2&&s&&s.on("selectionChange",l)},[n,s,o,i]}class nC extends Yt{constructor(t){super(),Wt(this,t,iC,rC,Ut,{store:3,viewer:0,provider:1})}}function sC(r){let t,e,i,n,s;return{c(){t=J("ellipse"),E(t,"cx",e=r[0].cx),E(t,"cy",i=r[0].cy),E(t,"rx",n=r[0].rx),E(t,"ry",s=r[0].ry)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].cx)&&E(t,"cx",e),a&1&&i!==(i=o[0].cy)&&E(t,"cy",i),a&1&&n!==(n=o[0].rx)&&E(t,"rx",n),a&1&&s!==(s=o[0].ry)&&E(t,"ry",s)},i:Nt,o:Nt,d(o){o&&it(t)}}}function oC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class aC extends Yt{constructor(t){super(),Wt(this,t,oC,sC,Ut,{annotation:1})}}function lC(r){let t,e,i,n,s;return{c(){t=J("line"),E(t,"x1",e=r[0].points[0][0]),E(t,"y1",i=r[0].points[0][1]),E(t,"x2",n=r[0].points[1][0]),E(t,"y2",s=r[0].points[1][1])},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].points[0][0])&&E(t,"x1",e),a&1&&i!==(i=o[0].points[0][1])&&E(t,"y1",i),a&1&&n!==(n=o[0].points[1][0])&&E(t,"x2",n),a&1&&s!==(s=o[0].points[1][1])&&E(t,"y2",s)},i:Nt,o:Nt,d(o){o&&it(t)}}}function hC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class cC extends Yt{constructor(t){super(),Wt(this,t,hC,lC,Ut,{annotation:1})}}function ng(r,t,e){const i=r.slice();return i[2]=t[e],i}function sg(r){let t,e;return{c(){t=J("path"),e=J("path"),E(t,"fill-rule","evenodd"),E(t,"d",je(r[2])),E(e,"class","a9s-inner"),E(e,"fill-rule","evenodd"),E(e,"d",je(r[2]))},m(i,n){ot(i,t,n),ot(i,e,n)},p:Nt,d(i){i&&(it(t),it(e))}}}function uC(r){let t,e=Ae(r[0]),i=[];for(let n=0;n<e.length;n+=1)i[n]=sg(ng(r,e,n));return{c(){t=J("g");for(let n=0;n<i.length;n+=1)i[n].c()},m(n,s){ot(n,t,s);for(let o=0;o<i.length;o+=1)i[o]&&i[o].m(t,null)},p(n,[s]){if(s&1){e=Ae(n[0]);let o;for(o=0;o<e.length;o+=1){const a=ng(n,e,o);i[o]?i[o].p(a,s):(i[o]=sg(a),i[o].c(),i[o].m(t,null))}for(;o<i.length;o+=1)i[o].d(1);i.length=e.length}},i:Nt,o:Nt,d(n){n&&it(t),$r(i,n)}}}function dC(r,t,e){let{annotation:i}=t;const{polygons:n}=i.target.selector.geometry;return r.$$set=s=>{"annotation"in s&&e(1,i=s.annotation)},[n,i]}class fC extends Yt{constructor(t){super(),Wt(this,t,dC,uC,Ut,{annotation:1})}}function pC(r){let t,e;return{c(){t=J("polygon"),E(t,"points",e=r[0].points.map(og).join(" "))},m(i,n){ot(i,t,n)},p(i,[n]){n&1&&e!==(e=i[0].points.map(og).join(" "))&&E(t,"points",e)},i:Nt,o:Nt,d(i){i&&it(t)}}}const og=r=>r.join(",");function mC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class gC extends Yt{constructor(t){super(),Wt(this,t,mC,pC,Ut,{annotation:1})}}function yC(r){let t;return{c(){t=J("path"),E(t,"d",r[0])},m(e,i){ot(e,t,i)},p(e,[i]){i&1&&E(t,"d",e[0])},i:Nt,o:Nt,d(e){e&&it(t)}}}function _C(r,t,e){let i,n,{annotation:s}=t;return r.$$set=o=>{"annotation"in o&&e(1,s=o.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(2,i=s.target.selector.geometry),r.$$.dirty&4&&e(0,n=fa(i))},[n,s,i]}class vC extends Yt{constructor(t){super(),Wt(this,t,_C,yC,Ut,{annotation:1})}}function bC(r){let t,e,i,n,s;return{c(){t=J("rect"),E(t,"x",e=r[0].x),E(t,"y",i=r[0].y),E(t,"width",n=r[0].w),E(t,"height",s=r[0].h)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].x)&&E(t,"x",e),a&1&&i!==(i=o[0].y)&&E(t,"y",i),a&1&&n!==(n=o[0].w)&&E(t,"width",n),a&1&&s!==(s=o[0].h)&&E(t,"height",s)},i:Nt,o:Nt,d(o){o&&it(t)}}}function xC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class wC extends Yt{constructor(t){super(),Wt(this,t,xC,bC,Ut,{annotation:1})}}const{Boolean:EC}=Oa;function ag(r,t,e){const i=r.slice();return i[10]=t[e],i}function lg(r){let t,e;return t=new Wh({props:{viewer:r[0],$$slots:{default:[RC,({transform:i})=>({9:i}),({transform:i})=>i?512:0]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&1&&(s.viewer=i[0]),n&8710&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function TC(r){let t,e;return t=new cC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function AC(r){let t,e;return t=new aC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function SC(r){let t,e;return t=new vC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function CC(r){let t,e;return t=new fC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function IC(r){let t,e;return t=new gC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function PC(r){let t,e;return t=new wC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function hg(r){let t,e,i,n;const s=[PC,IC,CC,SC,AC,TC],o=[];function a(l,h){return l[10].target.selector.type===_t.RECTANGLE?0:l[10].target.selector.type===_t.POLYGON?1:l[10].target.selector.type===_t.MULTIPOLYGON?2:l[10].target.selector.type===_t.POLYLINE?3:l[10].target.selector.type===_t.ELLIPSE?4:l[10].target.selector.type===_t.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Be()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(le(),nt(o[c],1,1,()=>{o[c]=null}),he()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),q(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(q(e),n=!0)},o(l){nt(e),n=!1},d(l){l&&it(i),~t&&o[t].d(l)}}}function RC(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g=Ae(r[1].filter(r[6])),y=[];for(let v=0;v<g.length;v+=1)y[v]=hg(ag(r,g,v));const _=v=>nt(y[v],1,1,()=>{y[v]=null});return{c(){var v,m,x,S;t=J("svg"),e=J("g"),i=J("rect"),l=J("rect");for(let R=0;R<y.length;R+=1)y[R].c();E(i,"class","a9s-union-bg svelte-jwrce3"),E(i,"x",n=(v=r[2])==null?void 0:v.minX),E(i,"y",s=(m=r[2])==null?void 0:m.minY),E(i,"width",o=r[2]?r[2].maxX-r[2].minX:0),E(i,"height",a=r[2]?r[2].maxY-r[2].minY:0),E(l,"class","a9s-union-fg svelte-jwrce3"),E(l,"x",h=(x=r[2])==null?void 0:x.minX),E(l,"y",c=(S=r[2])==null?void 0:S.minY),E(l,"width",u=r[2]?r[2].maxX-r[2].minX:0),E(l,"height",d=r[2]?r[2].maxY-r[2].minY:0),E(e,"transform",f=r[9]),E(t,"class","a9s-osd-selectionlayer svelte-jwrce3")},m(v,m){ot(v,t,m),Tt(t,e),Tt(e,i),Tt(e,l);for(let x=0;x<y.length;x+=1)y[x]&&y[x].m(e,null);p=!0},p(v,m){var x,S,R,C;if((!p||m&4&&n!==(n=(x=v[2])==null?void 0:x.minX))&&E(i,"x",n),(!p||m&4&&s!==(s=(S=v[2])==null?void 0:S.minY))&&E(i,"y",s),(!p||m&4&&o!==(o=v[2]?v[2].maxX-v[2].minX:0))&&E(i,"width",o),(!p||m&4&&a!==(a=v[2]?v[2].maxY-v[2].minY:0))&&E(i,"height",a),(!p||m&4&&h!==(h=(R=v[2])==null?void 0:R.minX))&&E(l,"x",h),(!p||m&4&&c!==(c=(C=v[2])==null?void 0:C.minY))&&E(l,"y",c),(!p||m&4&&u!==(u=v[2]?v[2].maxX-v[2].minX:0))&&E(l,"width",u),(!p||m&4&&d!==(d=v[2]?v[2].maxY-v[2].minY:0))&&E(l,"height",d),m&2){g=Ae(v[1].filter(v[6]));let I;for(I=0;I<g.length;I+=1){const M=ag(v,g,I);y[I]?(y[I].p(M,m),q(y[I],1)):(y[I]=hg(M),y[I].c(),q(y[I],1),y[I].m(e,null))}for(le(),I=g.length;I<y.length;I+=1)_(I);he()}(!p||m&512&&f!==(f=v[9]))&&E(e,"transform",f)},i(v){if(!p){for(let m=0;m<g.length;m+=1)q(y[m]);p=!0}},o(v){y=y.filter(EC);for(let m=0;m<y.length;m+=1)nt(y[m]);p=!1},d(v){v&&it(t),$r(y,v)}}}function MC(r){let t=!!r[2],e,i,n=t&&lg(r);return{c(){n&&n.c(),e=Be()},m(s,o){n&&n.m(s,o),ot(s,e,o),i=!0},p(s,[o]){o&4&&(t=!!s[2]),t?n?(n.p(s,o),o&4&&q(n,1)):(n=lg(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),nt(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n&&n.d(s)}}}function OC(r,t,e){let i,n,s,{state:o}=t,{viewer:a}=t;const{store:l}=o,{selection:h}=o;Fn(r,h,d=>e(5,s=d));const c=d=>{let f=-1/0,p=-1/0,g=1/0,y=1/0;for(let _ of d.filter(v=>Ue(v))){const{bounds:v}=_.target.selector.geometry;v.maxX>f&&(f=v.maxX),v.maxY>p&&(p=v.maxY),v.minX<g&&(g=v.minX),v.minY<y&&(y=v.minY)}return a.forceRedraw(),{maxX:f,maxY:p,minX:g,minY:y}},u=d=>Ue(d);return r.$$set=d=>{"state"in d&&e(4,o=d.state),"viewer"in d&&e(0,a=d.viewer)},r.$$.update=()=>{r.$$.dirty&32&&e(1,i=s.selected.map(({id:d})=>l.getAnnotation(d))),r.$$.dirty&2&&e(2,n=i.length>1?c(i):void 0)},[a,i,n,h,o,s,u]}class BC extends Yt{constructor(t){super(),Wt(this,t,OC,MC,Ut,{state:4,viewer:0})}}const cg=(r,t)=>{t==="auto"?r.addHandler("open",e=>{const i=r.world.getItemCount();r.world.getItemAt(i-1).addOnceHandler("fully-loaded-change",s=>{const{fullyLoaded:o}=s;if(o){const a=r.canvas.querySelector("canvas"),l=yu(a);r.element.setAttribute("data-theme",l)}})}):r.element.setAttribute("data-theme",t)},ug=(r,t,e)=>(i,n={})=>{const s=typeof i=="string"?i:i.id,o=t.getAnnotation(s);if(!o||!Ue(o))return;const a=r.container.getBoundingClientRect(),{padding:l}=n;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:g,maxY:y}=o.target.selector.geometry.bounds,_=g-f,v=y-p,m=f-d*_,x=p-h*v,S=_+(c+d)*_,R=v+(h+u)*v,C=r.viewport.imageToViewportRectangle(m,x,S,R);r.viewport[e](C,n.immediately)},LC=(r,t)=>ug(r,t,"fitBounds"),DC=(r,t)=>ug(r,t,"fitBoundsWithConstraints"),NC=(r,t={})=>{const e=vu(t,{drawingEnabled:!1,drawingMode:Ge?"drag":"click",userSelectAction:ra.EDIT,theme:"light"}),i=gu(e),{hover:n,selection:s,store:o}=i,a=Rg(o,e.initialHistory),l=Mg(i,a,e.adapter,e.autoSave);let h=Ug(),c=e.drawingEnabled,u=e.drawingMode,d=e.modalSelect;const f=xu(a,r.element),p=new M2({target:r.element,props:{state:i,viewer:r,style:e.style,filter:void 0}}),g=new nC({target:r.element.querySelector(".openseadragon-canvas"),props:{provider:void 0,store:o,viewer:r}}),y=new V2({target:r.element.querySelector(".openseadragon-canvas"),props:{drawingEnabled:!!c,filter:void 0,multiSelect:e.multiSelect,preferredDrawingMode:u,state:i,style:e.style,user:h,viewer:r}}),_=t.multiSelect?new BC({target:r.element.querySelector(".openseadragon-canvas"),props:{state:i,viewer:r}}):void 0;p.$on("click",k=>{const{originalEvent:V,annotation:j}=k.detail,st=H=>jm(H.id,V,s,e.multiSelect);d?s.isEmpty()&&j&&s.userSelect(st(j),V):j&&!(u==="click"&&c)?s.userSelect(st(j),V):s.isEmpty()||(e.multiSelect?V.metaKey||V.shiftKey||V.ctrlKey||s.userSelect([],V):s.userSelect([],V))}),r.element.addEventListener("pointerdown",k=>{if(n.current){const V=o.getAnnotation(n.current);l.emit("clickAnnotation",V,k)}}),cg(r,e.theme);const v=Bg(i,a,e.adapter),m=()=>y.cancelDrawing(),x=()=>{p.$destroy(),g.$destroy(),y.$destroy(),_==null||_.$destroy(),f.destroy(),a.destroy()},S=LC(r,o),R=DC(r,o),C=()=>y.getDrawingTool(),I=()=>h,M=()=>y.isDrawingEnabled(),F=(k,V,j)=>eu(k,V,j),U=(k,V)=>Zc(k,V),P=k=>{if(!Ms(k))throw`No drawing tool named ${k}`;y.$set({toolName:k})},T=k=>{c=k,y.$set({drawingEnabled:k})},w=k=>{u=k,y.$set({preferredDrawingMode:k})},A=k=>{p.$set({filter:k}),y.$set({filter:k})},L=k=>d=k,O=k=>{p.$set({style:k}),y.$set({style:k})},D=k=>g.$set({provider:k}),$=k=>cg(r,k),B=k=>{h=k,y.$set({user:k})},N=k=>p.$set({visible:k});return{...v,cancelDrawing:m,destroy:x,fitBounds:S,fitBoundsWithConstraints:R,getDrawingTool:C,getUser:I,isDrawingEnabled:M,listDrawingTools:Rs,on:l.on,off:l.off,registerDrawingTool:F,registerShapeEditor:U,setDrawingEnabled:T,setDrawingMode:w,setDrawingTool:P,setFilter:A,setModalSelect:L,setPresenceProvider:D,setStyle:O,setTheme:$,setUser:B,setVisible:N,state:i,viewer:r}};qt.ShapeType=_t,qt.UserSelectAction=ra,qt.W3CImageFormat=f0,qt.chainStyles=i0,qt.computeStyle=r0,qt.createBody=xg,qt.createImageAnnotator=rv,qt.createOSDAnnotator=NC,qt.defaultColorProvider=$g,Object.defineProperty(qt,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=oE(t)),typeof t=="number"?sE(t):t}dropShadowToCSS(){let t=this.normalizeColor(this.dropShadowColor);const e=this.dropShadowAlpha,i=Math.round(Math.cos(this.dropShadowAngle)*this.dropShadowDistance),n=Math.round(Math.sin(this.dropShadowAngle)*this.dropShadowDistance);t.startsWith("#")&&e<1&&(t+=(e*255|0).toString(16).padStart(2,"0"));const s=`${i}px ${n}px`;return this.dropShadowBlur>0?`text-shadow: ${s} ${this.dropShadowBlur}px ${t}`:`text-shadow: ${s} ${t}`}reset(){Object.assign(this,Cn.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}=tt.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}};Hh.availableFonts={},Hh.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 Vh=Hh;const Ko=class In extends gn{constructor(t="",e={}){super(dt.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,n=dt.from(i,{scaleMode:tt.SCALE_MODE,resourceOptions:{autoLoad:!1}});n.orig=new wt,n.trim=new wt,this.texture=n;const s="http://www.w3.org/2000/svg",o="http://www.w3.org/1999/xhtml",a=document.createElementNS(s,"svg"),l=document.createElementNS(s,"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=In.defaultMaxWidth,this.maxHeight=In.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=In.defaultAutoResolution,this._resolution=In.defaultResolution??tt.RESOLUTION,this.text=t,this.style=e}measureText(t){var c,u;const{text:e,style:i,resolution:n}=Object.assign({text:this._text,style:this._style,resolution:this._resolution},t);Object.assign(this._domElement,{innerHTML:e,style:i.toCSS(n)}),this._styleElement.textContent=i.toGlobalCSS(),document.body.appendChild(this._svgRoot);const s=this._domElement.getBoundingClientRect();this._svgRoot.remove();const{width:o,height:a}=s;(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(n)}),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:n}=this;if(this.localStyleID!==e.styleID&&(this.dirty=!0,this.localStyleID=e.styleID),!this.dirty&&t)return;const{width:s,height:o}=this.measureText();i.width=n.width=Math.ceil(Math.max(1,s)),i.height=n.height=Math.ceil(Math.max(1,o)),this._updateID++;const a=this._updateID;await new Promise(l=>{n.onload=async()=>{if(a<this._updateID){l();return}await e.onBeforeDraw(),i.src=n.src,n.onload=null,n.src="",this.updateTexture(),l()};const h=new XMLSerializer().serializeToString(this._svgRoot);n.src=`data:image/svg+xml;charset=utf8,${encodeURIComponent(h)}`})}get source(){return this._image}updateTexture(){const{style:t,texture:e,_image:i,resolution:n}=this,{padding:s}=t,{baseTexture:o}=e;e.trim.width=e._frame.width=i.width/n,e.trim.height=e._frame.height=i.height/n,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(),o.setRealSize(i.width,i.height,n),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,n,s,o,a;typeof t=="boolean"&&(t={children:t}),t=Object.assign({},In.defaultDestroyOptions,t),super.destroy(t);const e=null;this.ownsStyle&&((i=this._style)==null||i.cleanFonts()),this._style=e,(n=this._svgRoot)==null||n.remove(),this._svgRoot=e,(s=this._domElement)==null||s.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=zr(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=zr(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 Vh?(this.ownsStyle=!1,this._style=t):t instanceof ei?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=Vh.from(t)):(this.ownsStyle=!0,this._style=new Vh(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;")}};Ko.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},Ko.defaultMaxWidth=2024,Ko.defaultMaxHeight=2024,Ko.defaultAutoResolution=!0;const _2=16777215,v2=.25,b2=16777215,x2=1,w2=1.5;let ni=!1,Bi;const Xh=r=>{const t={tint:r!=null&&r.fill?new Mt(r.fill).toNumber():_2,alpha:(r==null?void 0:r.fillOpacity)!==void 0?Math.min(r.fillOpacity,1):String(r==null?void 0:r.fill).toLowerCase().startsWith("rgba(")?new Mt(r==null?void 0:r.fill).alpha:v2},e={tint:r!=null&&r.stroke?new Mt(r.stroke).toNumber():b2,alpha:(r==null?void 0:r.strokeOpacity)!==void 0?Math.min(r.strokeOpacity,1):String(r==null?void 0:r.stroke).toLowerCase().startsWith("rgba(")?new Mt(r==null?void 0:r.stroke).alpha:x2,lineWidth:(r==null?void 0:r.strokeWidth)===void 0?w2:r.strokeWidth};return{fillStyle:t,strokeStyle:e}},Tn=r=>(t,e,i,n={})=>{const{fillStyle:s,strokeStyle:o}=Xh(i),a=new ps;n.strokeOnly||(a.beginFill(16777215),r(e,a),a.endFill(),a.tint=s.tint,a.alpha=s.alpha),t.addChild(a);const l=new ps,h=o.lineWidth===1?1:o.lineWidth/Bi;return l.lineStyle(h,16777215,1,.5,o.lineWidth===1),r(e,l),l.tint=o.tint||16777215,l.alpha=o.alpha,t.addChild(l),{fill:a,stroke:l,strokeWidth:o.lineWidth}},E2=Tn((r,t)=>{const{x:e,y:i,w:n,h:s,rot:o=0}=r.geometry;o===0?t.drawRect(e,i,n,s):(t.position.set(e+n/2,i+s/2),t.rotation=o,t.drawRect(-n/2,-s/2,n,s))}),T2=Tn((r,t)=>{const{cx:e,cy:i,rx:n,ry:s}=r.geometry;t.drawEllipse(e,i,n,s)}),A2=Tn((r,t)=>{const[[e,i],[n,s]]=r.geometry.points;t.moveTo(e,i),t.lineTo(n,s),t.closePath()}),S2=Tn((r,t)=>{const e=r.geometry.points.reduce((i,n)=>[...i,...n],[]);t.drawPolygon(e)}),C2=Tn((r,t)=>{const{points:e,closed:i}=r.geometry;if(e.length===0)return;i||t.beginFill(0,0);const n=(o,a)=>{const[l,h]=o.point,[c,u]=a.point;if(o.type==="CURVE"||a.type==="CURVE"){const d=o.type==="CURVE"&&o.outHandle?o.outHandle[0]:l,f=o.type==="CURVE"&&o.outHandle?o.outHandle[1]:h,p=a.type==="CURVE"&&a.inHandle?a.inHandle[0]:c,g=a.type==="CURVE"&&a.inHandle?a.inHandle[1]:u;t.bezierCurveTo(d,f,p,g,c,u)}else t.lineTo(c,u)},s=e[0];t.moveTo(s.point[0],s.point[1]);for(let o=1;o<e.length;o++){const a=e[o-1],l=e[o];n(a,l)}if(i&&e.length>2){const o=e[e.length-1],a=e[0];n(o,a),t.closePath()}else t.endFill()}),I2=Tn((r,t)=>{const e=i=>i.points.reduce((n,s)=>[...n,...s],[]);r.geometry.polygons.forEach(i=>{const[n,...s]=i.rings;t.drawPolygon(e(n)),s.forEach(o=>{t.beginHole(),t.drawPolygon(e(o)),t.endHole()})})}),jh=r=>{const t=r.viewport.getContainerSize().x;return r.viewport.getZoom(!0)*t/r.world.getContentFactor()},Xm=(r,t,e,i)=>()=>{const n=r.viewport.viewportToImageRectangle(r.viewport.getBounds(!0)),s=jh(r);(s!==Bi||!ni)&&(ni=!0,e.forEach(({stroke:d,strokeWidth:f})=>{const{lineStyle:p}=d.geometry.graphicsData[0];f>1?(ni=s===Bi,p.width=f/s,p.native=!1,d.geometry.invalidate()):f===1&&!p.native&&(p.width=1,p.native=!0,d.geometry.invalidate())})),Bi=s;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+n.x*s:-n.x*s,h=-n.y*s;let c,u;a>0&&a<=Math.PI/2?(c=n.height*s,u=0):a>Math.PI/2&&a<=Math.PI?(c=n.width*s,u=n.height*s):a>Math.PI&&a<=Math.PI*1.5?(c=0,u=n.width*s):(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?-s:s,s),t.rotation=a,i.render(t)},P2=(r,t)=>{const e=new ps,i=$p({width:t.width,height:t.height,backgroundAlpha:0,view:t,antialias:!0,resolution:2}),n=new Map;let s=new Set,o,a;Bi=jh(r);const l=(m,x)=>{Bi=jh(r),ni=!1;const S=n.get(m.id);S&&(S.fill.destroy(),S.stroke.destroy());const{selector:R}=m.target,C=typeof a=="function"?a(m,x):a;let I;if(R.type===_t.RECTANGLE)I=E2(e,R,C);else if(R.type===_t.POLYGON)I=S2(e,R,C);else if(R.type===_t.ELLIPSE)I=T2(e,R,C);else if(R.type===_t.MULTIPOLYGON)I=I2(e,R,C);else if(R.type===_t.POLYLINE){const M=R;I=C2(e,M,C,{strokeOnly:!M.geometry.closed})}else R.type===_t.LINE?I=A2(e,R,C):console.warn(`Unsupported shape type: ${R.type}`);I&&n.set(m.id,{annotation:m,...I})},h=m=>{const x=n.get(m.id);x&&(n.delete(m.id),x.fill.destroy(),x.stroke.destroy())},c=(m,x,S)=>{ni=!1;const R=n.get(m.id);if(R&&(n.delete(m.id),R.fill.destroy(),R.stroke.destroy(),l(x,S),s.has(x.id))){const{fill:C,stroke:I}=n.get(x.id);e.removeChild(C),e.removeChild(I)}},u=(m,x)=>{const S=n.get(m);S&&(n.delete(m),S.fill.destroy(),S.stroke.destroy(),l(S.annotation,x))},d=(m,x)=>{i.resize(m,x),i.render(e)},f=m=>{ni=!1;const{children:x}=e;n.forEach(({fill:S,stroke:R,annotation:C})=>{const I=m?s.has(C.id)||m(C):!0;I&&!x.includes(S)?(e.addChild(S),e.addChild(R)):!I&&x.includes(S)&&(e.removeChild(S),e.removeChild(R))}),i.render(e)},p=m=>{const x=new Set(m.selected.filter(C=>C.editable).map(C=>C.id)),S=m.selected.filter(({id:C})=>!s.has(C)),R=[...s].filter(C=>!x.has(C));S.forEach(({id:C,editable:I})=>{if(I){const M=n.get(C);M&&Aa(M.annotation.target.selector)&&(e.removeChild(M.fill),e.removeChild(M.stroke))}else u(C,{selected:!0,hovered:C===o})}),R.forEach(C=>u(C,{hovered:C===o})),s=x,i.render(e)},g=m=>{o!==m&&(m&&s.has(m)||(o&&!s.has(o)&&u(o,{selected:s.has(o)}),m&&u(m,{selected:s.has(m),hovered:!0}),o=m,i.render(e)))},y=m=>{if(typeof m=="function")n.forEach(({annotation:x,fill:S,stroke:R,strokeWidth:C},I)=>{C>1&&(ni=!1);const M={selected:s.has(x.id),hovered:o===x.id},{fillStyle:F,strokeStyle:U}=Xh(m(x,M));S.tint=F.tint,S.alpha=F.alpha,R.tint=U.tint||16777215,R.alpha=U.alpha,n.set(x.id,{annotation:x,fill:S,stroke:R,strokeWidth:U.lineWidth})});else{const{fillStyle:x,strokeStyle:S}=Xh(m);S.lineWidth>1&&(ni=!1),n.forEach(({annotation:R,fill:C,stroke:I,strokeWidth:M},F)=>{C.tint=x.tint,C.alpha=x.alpha,I.tint=S.tint||16777215,I.alpha=S.alpha,n.set(R.id,{annotation:R,fill:C,stroke:I,strokeWidth:S.lineWidth})})}a=m,i.render(e),Xm(r,e,n,i)()},_=m=>{m?t.classList.remove("hidden"):t.classList.add("hidden")};return{addAnnotation:l,destroy:()=>i.destroy(),getScale:()=>Bi,redraw:Xm(r,e,n,i),removeAnnotation:h,resize:d,setFilter:f,setHovered:g,setSelected:p,setStyle:y,setVisible:_,updateAnnotation:c}};function R2(r,t,e){let i,n,{filter:s}=t,{state:o}=t,{style:a}=t,{viewer:l}=t,{visible:h=!0}=t;const{store:c,hover:u,selection:d,viewport:f}=o;Fn(r,u,I=>e(11,i=I)),Fn(r,d,I=>e(8,n=I));const p=Wi(),g=Fe?10:2;let y,_;const v=I=>{const M=new se.Point(I.x,I.y),{x:F,y:U}=l.viewport.pointFromPixel(M);return l.viewport.viewportToImageCoordinates(F,U)},m=()=>g/y.getScale(),x=I=>{const{x:M,y:F}=I.position;_={x:M,y:F}},S=I=>M=>{const{x:F,y:U}=v(new se.Point(M.offsetX,M.offsetY)),P=m(),T=c.getAt(F,U,s,P);T?(I.classList.add("hover"),i!==T.id&&(u.set(T.id),y.setHovered(T.id))):(I.classList.remove("hover"),i&&(u.set(void 0),y.setHovered(void 0)))},R=I=>{if(!_)return;const M=I.originalEvent,{x:F,y:U}=I.position,P=F-_.x,T=U-_.y;if(Math.sqrt(P*P+T*T)<5){const{x:A,y:L}=v(I.position),O=m(),D=c.getAt(A,L,s,O);D?p("click",{originalEvent:M,annotation:D}):p("click",{originalEvent:M})}_=void 0};let C;return Vr(()=>{var D;const{offsetWidth:I,offsetHeight:M}=l.canvas,F=document.createElement("canvas");F.width=I,F.height=M,F.className="a9s-gl-canvas",(D=l.element.querySelector(".openseadragon-canvas"))==null||D.appendChild(F),e(7,y=P2(l,F));const U=S(F);F.addEventListener("pointermove",U);const P=new ResizeObserver($=>{try{const{width:B,height:N}=$[0].contentRect;F.width=B,F.height=N,y.resize(B,N)}catch{console.warn("WebGL canvas already disposed")}});P.observe(F);const T=()=>{const $=l.viewport.getBounds();C=l.viewport.viewportToImageRectangle($);const{x:B,y:N,width:k,height:V}=C,j=c.getIntersecting(B,N,k,V);f.set(j.map(st=>st.id))};l.addHandler("canvas-press",x),l.addHandler("canvas-release",R),l.addHandler("update-viewport",y.redraw),l.addHandler("animation-finish",T);const w=$=>$.filter(B=>Ge(B)),A=$=>Ge($.oldValue)&&Ge($.newValue),L=$=>{const{selector:B}=$.target;if(B.type===_t.POLYGON){const N=Tv(B);return{...$,target:{...$.target,selector:{...N}}}}else if(B.type===_t.MULTIPOLYGON){const N=wv(B);return{...$,target:{...$.target,selector:{...N}}}}else return $},O=$=>{const{created:B,updated:N,deleted:k}=$.changes,V=(B||[]).filter(j=>Ge(j)).map(L);if(w(k||[]).forEach(j=>y.removeAnnotation(j)),V.forEach(j=>y.addAnnotation(j)),(N||[]).filter(j=>A(j)).map(({oldValue:j,newValue:st})=>({oldValue:j,newValue:L(st)})).forEach(({oldValue:j,newValue:st})=>y.updateAnnotation(j,st)),C){const{x:j,y:st,width:H,height:at}=C,X=c.getIntersecting(j,st,H,at);f.set(X.map(gt=>gt.id))}else f.set(c.all().map(j=>j.id));y.redraw()};return c.observe(O),()=>{var $;F.removeEventListener("pointermove",U),P.disconnect(),l.removeHandler("canvas-press",x),l.removeHandler("canvas-release",R),l.removeHandler("update-viewport",y.redraw),l.removeHandler("animation-finish",T),c.unobserve(O),y.destroy(),($=F.parentNode)==null||$.removeChild(F)}}),r.$$set=I=>{"filter"in I&&e(2,s=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&&(y==null||y.setFilter(s)),r.$$.dirty&384&&(y==null||y.setSelected(n)),r.$$.dirty&144&&(y==null||y.setStyle(a)),r.$$.dirty&192&&(y==null||y.setVisible(h))},[u,d,s,o,a,l,h,y,n]}class M2 extends Yt{constructor(t){super(),Wt(this,t,R2,null,Ut,{filter:2,state:3,style:4,viewer:5,visible:6})}}const jm=(r,t,e,i)=>{if(!i)return r;if(t.shiftKey||t.ctrlKey||t.metaKey){const s=(e.selected||[]).map(o=>o.id);return s.includes(r)?s.filter(o=>o!==r):[...s,r]}else return r},O2=r=>({transform:r&2,scale:r&1}),Wm=r=>({transform:r[1],scale:r[0]});function B2(r){let t;const e=r[4].default,i=Tu(e,r,r[3],Wm);return{c(){i&&i.c()},m(n,s){i&&i.m(n,s),t=!0},p(n,[s]){i&&i.p&&(!t||s&11)&&Cu(i,e,n,n[3],t?Su(e,n[3],s,O2):Iu(n[3]),Wm)},i(n){t||(q(i,n),t=!0)},o(n){nt(i,n),t=!1},d(n){i&&i.d(n)}}}function L2(r,t,e){let{$$slots:i={},$$scope:n}=t,{viewer:s}=t,o=1,a;const l=()=>{const h=s.viewport.getContainerSize().x,c=s.viewport.getZoom(!0),u=s.viewport.getFlip(),d=s.viewport.pixelFromPoint(new se.Point(0,0),!0);u&&(d.x=h-d.x);const f=c*h/s.world.getContentFactor(),p=u?-f:f,g=s.viewport.getRotation(!0);e(1,a=`translate(${d.x}, ${d.y}) scale(${p}, ${f}) rotate(${g})`),e(0,o=c*h/s.world.getContentFactor())};return Vr(()=>(s.addHandler("update-viewport",l),()=>{s.removeHandler("update-viewport",l)})),r.$$set=h=>{"viewer"in h&&e(2,s=h.viewer),"$$scope"in h&&e(3,n=h.$$scope)},[o,a,s,n,i]}class Wh extends Yt{constructor(t){super(),Wt(this,t,L2,B2,Ut,{viewer:2})}}function D2(r,t,e){const i=Wi();let{drawingMode:n}=t,{opts:s}=t,{target:o}=t,{tool:a}=t,{transform:l}=t,{viewer:h}=t,{viewportScale:c}=t,u;return Vr(()=>{const d=o.closest("svg"),f=[],p=(g,y,_)=>{if(d==null||d.addEventListener(g,y,_),f.push(()=>d==null?void 0:d.removeEventListener(g,y,_)),g==="pointerup"||g==="dblclick"){const v=x=>{const{originalEvent:S}=x;y(S)},m=g==="pointerup"?"canvas-click":"canvas-double-click";h.addHandler(m,v),f.push(()=>h.removeHandler(m,v))}else if(g==="pointermove"){const v=m=>{const{originalEvent:x}=m;y(x)};h.addHandler("canvas-drag",v),f.push(()=>h.removeHandler("canvas-drag",v))}};return e(7,u=new a({target:o,props:{addEventListener:p,drawingMode:n,opts:s,transform:l,viewportScale:c,svgEl:d}})),u.$on("create",g=>i("create",g.detail)),()=>{f.forEach(g=>g()),u.$destroy()}}),r.$$set=d=>{"drawingMode"in d&&e(0,n=d.drawingMode),"opts"in d&&e(1,s=d.opts),"target"in d&&e(2,o=d.target),"tool"in d&&e(3,a=d.tool),"transform"in d&&e(4,l=d.transform),"viewer"in d&&e(5,h=d.viewer),"viewportScale"in d&&e(6,c=d.viewportScale)},r.$$.update=()=>{r.$$.dirty&144&&u&&u.$set({transform:l}),r.$$.dirty&192&&u&&u.$set({viewportScale:c})},[n,s,o,a,l,h,c,u]}class N2 extends Yt{constructor(t){super(),Wt(this,t,D2,null,Ut,{drawingMode:0,opts:1,target:2,tool:3,transform:4,viewer:5,viewportScale:6})}}const{Boolean:F2}=Oa;function Ym(r,t,e){const i=r.slice();i[41]=t[e];const n=i[19](i[41].target.selector);return i[42]=n,i}function k2(r){let t=`${r[2]}-${r[7]}`,e,i,n=zm(r);return{c(){n.c(),e=Be()},m(s,o){n.m(s,o),ot(s,e,o),i=!0},p(s,o){o[0]&132&&Ut(t,t=`${s[2]}-${s[7]}`)?(le(),nt(n,1,1,Nt),he(),n=zm(s),n.c(),q(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n.d(s)}}}function U2(r){let t,e,i=Ae(r[9].filter(r[29])),n=[];for(let o=0;o<i.length;o+=1)n[o]=Zm(Ym(r,i,o));const s=o=>nt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Be()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a[0]&713474|a[1]&512){i=Ae(o[9].filter(o[29]));let l;for(l=0;l<i.length;l+=1){const h=Ym(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=Zm(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(F2);for(let a=0;a<n.length;a+=1)nt(n[a]);e=!1},d(o){o&&it(t),$r(n,o)}}}function zm(r){let t,e;return t=new N2({props:{target:r[8],tool:r[10],drawingMode:r[4],transform:{elementToImage:r[13]},viewer:r[3],viewportScale:r[40],opts:r[5]}}),t.$on("create",r[18]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&256&&(s.target=i[8]),n[0]&1024&&(s.tool=i[10]),n[0]&16&&(s.drawingMode=i[4]),n[0]&8&&(s.viewer=i[3]),n[1]&512&&(s.viewportScale=i[40]),n[0]&32&&(s.opts=i[5]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function qm(r){let t=r[41].id,e,i,n=Km(r);return{c(){n.c(),e=Be()},m(s,o){n.m(s,o),ot(s,e,o),i=!0},p(s,o){o[0]&512&&Ut(t,t=s[41].id)?(le(),nt(n,1,1,Nt),he(),n=Km(s),n.c(),q(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n.d(s)}}}function Km(r){let t,e;return t=new m1({props:{target:r[8],editor:r[19](r[41].target.selector),annotation:r[41],style:r[1],transform:{elementToImage:r[13]},viewportScale:r[40]}}),t.$on("grab",r[14]),t.$on("change",function(){jt(r[17](r[41]))&&r[17](r[41]).apply(this,arguments)}),t.$on("release",r[15]),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){r=i;const s={};n[0]&256&&(s.target=r[8]),n[0]&512&&(s.editor=r[19](r[41].target.selector)),n[0]&512&&(s.annotation=r[41]),n[0]&2&&(s.style=r[1]),n[1]&512&&(s.viewportScale=r[40]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function Zm(r){let t,e,i=r[42]&&qm(r);return{c(){i&&i.c(),t=Be()},m(n,s){i&&i.m(n,s),ot(n,t,s),e=!0},p(n,s){n[42]?i?(i.p(n,s),s[0]&512&&q(i,1)):(i=qm(n),i.c(),q(i,1),i.m(t.parentNode,t)):i&&(le(),nt(i,1,1,()=>{i=null}),he())},i(n){e||(q(i),e=!0)},o(n){nt(i),e=!1},d(n){n&&it(t),i&&i.d(n)}}}function G2(r){let t,e,i,n,s,o,a,l;const h=[U2,k2],c=[];function u(d,f){var p;return d[8]&&((p=d[9])==null?void 0:p.length)===1?0:d[8]&&d[10]&&d[0]?1:-1}return~(i=u(r))&&(n=c[i]=h[i](r)),{c(){t=J("svg"),e=J("g"),n&&n.c(),E(e,"transform",s=r[39]),E(e,"class","svelte-g4ws1v"),E(t,"tabindex",0),E(t,"class","a9s-annotationlayer a9s-osd-drawinglayer svelte-g4ws1v"),Hr(t,"drawing",r[0]),Hr(t,"editing",r[9]),Hr(t,"hover",r[6])},m(d,f){ot(d,t,f),Tt(t,e),~i&&c[i].m(e,null),r[30](e),o=!0,a||(l=Pt(t,"pointermove",r[16]),a=!0)},p(d,f){let p=i;i=u(d),i===p?~i&&c[i].p(d,f):(n&&(le(),nt(c[p],1,1,()=>{c[p]=null}),he()),~i?(n=c[i],n?n.p(d,f):(n=c[i]=h[i](d),n.c()),q(n,1),n.m(e,null)):n=null),(!o||f[1]&256&&s!==(s=d[39]))&&E(e,"transform",s),(!o||f[0]&1)&&Hr(t,"drawing",d[0]),(!o||f[0]&512)&&Hr(t,"editing",d[9]),(!o||f[0]&64)&&Hr(t,"hover",d[6])},i(d){o||(q(n),o=!0)},o(d){nt(n),o=!1},d(d){d&&it(t),~i&&c[i].d(),r[30](null),a=!1,l()}}}function $2(r){let t,e;return t=new Wh({props:{viewer:r[3],$$slots:{default:[G2,({transform:i,scale:n})=>({39:i,40:n}),({transform:i,scale:n})=>[0,(i?256:0)|(n?512:0)]]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n[0]&8&&(s.viewer=i[3]),n[0]&2047|n[1]&17152&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function H2(r,t,e){let i,n,s,o,a,{drawingEnabled:l}=t,{filter:h}=t,{multiSelect:c}=t,{preferredDrawingMode:u}=t,{state:d}=t,{style:f=void 0}=t,{toolName:p=Rs()[0]}=t,{user:g}=t,{viewer:y}=t;const _=Fe?10:2;let v=!1,m=0;const x=()=>e(7,m+=1),S=()=>p,R=()=>l;let C;const{store:I,selection:M,hover:F}=d;Fn(r,M,H=>e(28,o=H)),Fn(r,F,H=>e(33,a=H));let U,P,T;const w=H=>{I.unobserve(U);const at=H.filter(({editable:X})=>X).map(({id:X})=>X);at.length>0?(e(9,P=at.map(X=>I.getAnnotation(X))),U=X=>{const{updated:gt}=X.changes;e(9,P=(gt||[]).map(lt=>lt.newValue))},I.observe(U,{annotations:at}),y.forceRedraw()):e(9,P=void 0)},A=(H,at)=>{const{x:X,y:gt}=y.viewport.viewerElementToImageCoordinates(new se.Point(H,at));return[X,gt]},L=()=>{const H=y.viewport.getContainerSize().x;return y.viewport.getZoom(!0)*H/y.world.getContentFactor()},O=()=>_/L(),D=H=>{y.setMouseNavEnabled(!1),T=H.timeStamp},$=H=>{if(y.setMouseNavEnabled(!0),performance.now()-(T||0)<300){const{offsetX:X,offsetY:gt}=H.detail,[lt,ft]=A(X,gt),ct=O(),Et=I.getAt(lt,ft,void 0,ct);if(Et&&(!h||h(Et))&&!P.find(Gt=>Gt.id===Et.id)){F.set(Et.id);const Gt=jm(Et.id,H.detail,M,c);M.userSelect(Gt)}}},B=H=>{const at=new se.Point(H.offsetX,H.offsetY),X=y.viewport.pointFromPixel(at),{x:gt,y:lt}=y.viewport.viewportToImageCoordinates(X.x,X.y),ft=O(),ct=I.getAt(gt,lt,h,ft);ct?a!==ct.id&&F.set(ct.id):a&&F.set(void 0)},N=H=>at=>{var ft;const{target:X}=H,gt=10*60*1e3,lt=((ft=X.creator)==null?void 0:ft.id)!==g.id||!X.created||new Date().getTime()-X.created.getTime()>gt;I.updateTarget({...X,selector:at.detail,created:lt?X.created:new Date,updated:lt?new Date:void 0,updatedBy:lt?g:void 0})},k=H=>{const at=Mv(),X={id:at,bodies:[],target:{annotation:at,selector:H.detail,creator:g,created:new Date}};I.addAnnotation(X),M.setSelected(X.id),y.setMouseNavEnabled(!0)},V=H=>Aa(H);Vr(()=>{const H=at=>{if(o.selected.length===0)return;const{offsetX:X,offsetY:gt}=at,lt=y.viewport.pointFromPixel(new se.Point(X,gt)),{x:ft,y:ct}=y.viewport.viewportToImageCoordinates(lt.x,lt.y),Et=O();e(6,v=!!I.getAt(ft,ct,h,Et))};return y.element.addEventListener("pointermove",H),()=>{var at;(at=y.element)==null||at.removeEventListener("pointermove",H)}});const j=H=>Ge(H);function st(H){Ls[H?"unshift":"push"](()=>{C=H,e(8,C)})}return r.$$set=H=>{"drawingEnabled"in H&&e(0,l=H.drawingEnabled),"filter"in H&&e(20,h=H.filter),"multiSelect"in H&&e(21,c=H.multiSelect),"preferredDrawingMode"in H&&e(22,u=H.preferredDrawingMode),"state"in H&&e(23,d=H.state),"style"in H&&e(1,f=H.style),"toolName"in H&&e(2,p=H.toolName),"user"in H&&e(24,g=H.user),"viewer"in H&&e(3,y=H.viewer)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(10,{tool:i,opts:n}=Ms(p)||{tool:void 0,opts:void 0},i,(e(5,n),e(2,p))),r.$$.dirty[0]&4194336&&e(4,s=(n==null?void 0:n.drawingMode)||u),r.$$.dirty[0]&25&&(l&&s==="drag"?y.setMouseNavEnabled(!1):y.setMouseNavEnabled(!0)),r.$$.dirty[0]&1&&l&&M.clear(),r.$$.dirty[0]&268435481&&o.selected.length===0&&s==="drag"&&l&&y.setMouseNavEnabled(!1),r.$$.dirty[0]&268435456&&w(o.selected)},[l,f,p,y,s,n,v,m,C,P,i,M,F,A,D,$,B,N,k,V,h,c,u,d,g,x,S,R,o,j,st]}class V2 extends Yt{constructor(t){super(),Wt(this,t,H2,$2,Ut,{drawingEnabled:0,filter:20,multiSelect:21,preferredDrawingMode:22,state:23,style:1,toolName:2,user:24,viewer:3,cancelDrawing:25,getDrawingTool:26,isDrawingEnabled:27},null,[-1,-1])}get cancelDrawing(){return this.$$.ctx[25]}get getDrawingTool(){return this.$$.ctx[26]}get isDrawingEnabled(){return this.$$.ctx[27]}}function X2(r){let t,e,i,n,s,o,a,l=r[2].appearance.label+"",h,c,u,d;return{c(){t=J("g"),e=J("rect"),a=J("text"),h=Ba(l),E(e,"class","a9s-presence-label-bg svelte-1rehw2p"),E(e,"x",r[0]),E(e,"y",i=r[1]-18/r[3]),E(e,"height",n=18/r[3]),E(e,"fill",s=r[2].appearance.color),E(e,"stroke",o=r[2].appearance.color),E(a,"font-size",c=12/r[3]),E(a,"x",u=r[0]+Math.round(5/r[3])),E(a,"y",d=r[1]-5/r[3]),E(a,"class","svelte-1rehw2p"),E(t,"class","a9s-presence-label")},m(f,p){ot(f,t,p),Tt(t,e),Tt(t,a),Tt(a,h),r[6](t)},p(f,[p]){p&1&&E(e,"x",f[0]),p&10&&i!==(i=f[1]-18/f[3])&&E(e,"y",i),p&8&&n!==(n=18/f[3])&&E(e,"height",n),p&4&&s!==(s=f[2].appearance.color)&&E(e,"fill",s),p&4&&o!==(o=f[2].appearance.color)&&E(e,"stroke",o),p&4&&l!==(l=f[2].appearance.label+"")&&ov(h,l),p&8&&c!==(c=12/f[3])&&E(a,"font-size",c),p&9&&u!==(u=f[0]+Math.round(5/f[3]))&&E(a,"x",u),p&10&&d!==(d=f[1]-5/f[3])&&E(a,"y",d)},i:Nt,o:Nt,d(f){f&&it(t),r[6](null)}}}function j2(r,t,e){let{x:i}=t,{y:n}=t,{user:s}=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){Ls[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,n=u.y),"user"in u&&e(2,s=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,n,s,o,l,a,c]}class Jm extends Yt{constructor(t){super(),Wt(this,t,j2,X2,Ut,{x:0,y:1,user:2,scale:3,hAlign:5})}}function W2(r){let t,e,i,n,s,o;return e=new Jm({props:{scale:r[1],user:r[0],x:r[3][0],y:r[3][1],hAlign:"CENTER"}}),{c(){t=J("g"),Lt(e.$$.fragment),i=J("polygon"),E(i,"class","a9s-presence-shape a9s-presence-polygon svelte-fgq4n0"),E(i,"stroke",n=r[0].appearance.color),E(i,"fill","transparent"),E(i,"points",s=r[2].points.map(Qm).join(" ")),E(t,"class","a9s-presence-overlay")},m(a,l){ot(a,t,l),Ot(e,t,null),Tt(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&&n!==(n=a[0].appearance.color))&&E(i,"stroke",n),(!o||l&4&&s!==(s=a[2].points.map(Qm).join(" ")))&&E(i,"points",s)},i(a){o||(q(e.$$.fragment,a),o=!0)},o(a){nt(e.$$.fragment,a),o=!1},d(a){a&&it(t),Bt(e)}}}const Qm=r=>r.join(",");function Y2(r,t,e){let i,n,{annotation:s}=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,s=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=s.target.selector.geometry),r.$$.dirty&4&&e(3,n=l(i))},[o,a,i,n,s]}class z2 extends Yt{constructor(t){super(),Wt(this,t,Y2,W2,Ut,{annotation:4,user:0,scale:1})}}function q2(r){let t,e,i,n,s,o,a,l,h;return e=new Jm({props:{scale:r[1],user:r[0],x:r[2].x,y:r[2].y}}),{c(){t=J("g"),Lt(e.$$.fragment),i=J("rect"),E(i,"class","a9s-presence-shape a9s-presence-rectangle svelte-gze948"),E(i,"stroke",n=r[0].appearance.color),E(i,"fill","transparent"),E(i,"x",s=r[2].x),E(i,"y",o=r[2].y),E(i,"width",a=r[2].w),E(i,"height",l=r[2].h),E(t,"class","a9s-presence-overlay")},m(c,u){ot(c,t,u),Ot(e,t,null),Tt(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&&n!==(n=c[0].appearance.color))&&E(i,"stroke",n),(!h||u&4&&s!==(s=c[2].x))&&E(i,"x",s),(!h||u&4&&o!==(o=c[2].y))&&E(i,"y",o),(!h||u&4&&a!==(a=c[2].w))&&E(i,"width",a),(!h||u&4&&l!==(l=c[2].h))&&E(i,"height",l)},i(c){h||(q(e.$$.fragment,c),h=!0)},o(c){nt(e.$$.fragment,c),h=!1},d(c){c&&it(t),Bt(e)}}}function K2(r,t,e){let i,{annotation:n}=t,{user:s}=t,{scale:o}=t;return r.$$set=a=>{"annotation"in a&&e(3,n=a.annotation),"user"in a&&e(0,s=a.user),"scale"in a&&e(1,o=a.scale)},r.$$.update=()=>{r.$$.dirty&8&&e(2,i=n.target.selector.geometry)},[s,o,i,n]}class Z2 extends Yt{constructor(t){super(),Wt(this,t,K2,q2,Ut,{annotation:3,user:0,scale:1})}}const{Boolean:J2}=Oa;function tg(r,t,e){const i=r.slice();return i[8]=t[e],i}function eg(r){let t,e;return t=new Wh({props:{viewer:r[0],$$slots:{default:[eC,({transform:i,scale:n})=>({6:i,7:n}),({transform:i,scale:n})=>(i?64:0)|(n?128:0)]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&1&&(s.viewer=i[0]),n&2244&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function rg(r){let t,e,i=Ae(r[2]),n=[];for(let o=0;o<i.length;o+=1)n[o]=ig(tg(r,i,o));const s=o=>nt(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Be()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);ot(o,t,a),e=!0},p(o,a){if(a&132){i=Ae(o[2]);let l;for(l=0;l<i.length;l+=1){const h=tg(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=ig(h),n[l].c(),q(n[l],1),n[l].m(t.parentNode,t))}for(le(),l=i.length;l<n.length;l+=1)s(l);he()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)q(n[a]);e=!0}},o(o){n=n.filter(J2);for(let a=0;a<n.length;a+=1)nt(n[a]);e=!1},d(o){o&&it(t),$r(n,o)}}}function Q2(r){let t,e;return t=new z2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&4&&(s.annotation=i[8].annotation),n&4&&(s.user=i[8].selectedBy),n&128&&(s.scale=i[7]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function tC(r){let t,e;return t=new Z2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&4&&(s.annotation=i[8].annotation),n&4&&(s.user=i[8].selectedBy),n&128&&(s.scale=i[7]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function ig(r){let t,e,i,n;const s=[tC,Q2],o=[];function a(l,h){return l[8].annotation.target.selector.type===_t.RECTANGLE?0:l[8].annotation.target.selector.type===_t.POLYGON?1:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Be()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(le(),nt(o[c],1,1,()=>{o[c]=null}),he()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),q(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(q(e),n=!0)},o(l){nt(e),n=!1},d(l){l&&it(i),~t&&o[t].d(l)}}}function eC(r){let t,e,i,n,s=r[2].length>0&&rg(r);return{c(){t=J("svg"),e=J("g"),s&&s.c(),E(e,"transform",i=r[6]),E(t,"class","a9s-osd-presencelayer svelte-1krwc4m")},m(o,a){ot(o,t,a),Tt(t,e),s&&s.m(e,null),n=!0},p(o,a){o[2].length>0?s?(s.p(o,a),a&4&&q(s,1)):(s=rg(o),s.c(),q(s,1),s.m(e,null)):s&&(le(),nt(s,1,1,()=>{s=null}),he()),(!n||a&64&&i!==(i=o[6]))&&E(e,"transform",i)},i(o){n||(q(s),n=!0)},o(o){nt(s),n=!1},d(o){o&&it(t),s&&s.d()}}}function rC(r){let t=!!r[1],e,i,n=t&&eg(r);return{c(){n&&n.c(),e=Be()},m(s,o){n&&n.m(s,o),ot(s,e,o),i=!0},p(s,[o]){o&2&&(t=!!s[1]),t?n?(n.p(s,o),o&2&&q(n,1)):(n=eg(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),nt(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n&&n.d(s)}}}function iC(r,t,e){let{store:i}=t,{viewer:n}=t,{provider:s}=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(y=>y.id)),g=o.filter(({annotation:y})=>!p.has(y.id)).map(y=>{const _=(f||[]).find(v=>v.oldValue.id===y.annotation.id);return _?{selectedBy:y.selectedBy,annotation:_.newValue}:y});e(2,o=g)},i.observe(a,{annotations:o.map(u=>u.annotation.id)})};return lv(()=>{a&&i.unobserve(a)}),r.$$set=h=>{"store"in h&&e(3,i=h.store),"viewer"in h&&e(0,n=h.viewer),"provider"in h&&e(1,s=h.provider)},r.$$.update=()=>{r.$$.dirty&2&&s&&s.on("selectionChange",l)},[n,s,o,i]}class nC extends Yt{constructor(t){super(),Wt(this,t,iC,rC,Ut,{store:3,viewer:0,provider:1})}}function sC(r){let t,e,i,n,s;return{c(){t=J("ellipse"),E(t,"cx",e=r[0].cx),E(t,"cy",i=r[0].cy),E(t,"rx",n=r[0].rx),E(t,"ry",s=r[0].ry)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].cx)&&E(t,"cx",e),a&1&&i!==(i=o[0].cy)&&E(t,"cy",i),a&1&&n!==(n=o[0].rx)&&E(t,"rx",n),a&1&&s!==(s=o[0].ry)&&E(t,"ry",s)},i:Nt,o:Nt,d(o){o&&it(t)}}}function oC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class aC extends Yt{constructor(t){super(),Wt(this,t,oC,sC,Ut,{annotation:1})}}function lC(r){let t,e,i,n,s;return{c(){t=J("line"),E(t,"x1",e=r[0].points[0][0]),E(t,"y1",i=r[0].points[0][1]),E(t,"x2",n=r[0].points[1][0]),E(t,"y2",s=r[0].points[1][1])},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].points[0][0])&&E(t,"x1",e),a&1&&i!==(i=o[0].points[0][1])&&E(t,"y1",i),a&1&&n!==(n=o[0].points[1][0])&&E(t,"x2",n),a&1&&s!==(s=o[0].points[1][1])&&E(t,"y2",s)},i:Nt,o:Nt,d(o){o&&it(t)}}}function hC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class cC extends Yt{constructor(t){super(),Wt(this,t,hC,lC,Ut,{annotation:1})}}function ng(r,t,e){const i=r.slice();return i[2]=t[e],i}function sg(r){let t,e;return{c(){t=J("path"),e=J("path"),E(t,"fill-rule","evenodd"),E(t,"d",je(r[2])),E(e,"class","a9s-inner"),E(e,"fill-rule","evenodd"),E(e,"d",je(r[2]))},m(i,n){ot(i,t,n),ot(i,e,n)},p:Nt,d(i){i&&(it(t),it(e))}}}function uC(r){let t,e=Ae(r[0]),i=[];for(let n=0;n<e.length;n+=1)i[n]=sg(ng(r,e,n));return{c(){t=J("g");for(let n=0;n<i.length;n+=1)i[n].c()},m(n,s){ot(n,t,s);for(let o=0;o<i.length;o+=1)i[o]&&i[o].m(t,null)},p(n,[s]){if(s&1){e=Ae(n[0]);let o;for(o=0;o<e.length;o+=1){const a=ng(n,e,o);i[o]?i[o].p(a,s):(i[o]=sg(a),i[o].c(),i[o].m(t,null))}for(;o<i.length;o+=1)i[o].d(1);i.length=e.length}},i:Nt,o:Nt,d(n){n&&it(t),$r(i,n)}}}function dC(r,t,e){let{annotation:i}=t;const{polygons:n}=i.target.selector.geometry;return r.$$set=s=>{"annotation"in s&&e(1,i=s.annotation)},[n,i]}class fC extends Yt{constructor(t){super(),Wt(this,t,dC,uC,Ut,{annotation:1})}}function pC(r){let t,e;return{c(){t=J("polygon"),E(t,"points",e=r[0].points.map(og).join(" "))},m(i,n){ot(i,t,n)},p(i,[n]){n&1&&e!==(e=i[0].points.map(og).join(" "))&&E(t,"points",e)},i:Nt,o:Nt,d(i){i&&it(t)}}}const og=r=>r.join(",");function mC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class gC extends Yt{constructor(t){super(),Wt(this,t,mC,pC,Ut,{annotation:1})}}function yC(r){let t;return{c(){t=J("path"),E(t,"d",r[0])},m(e,i){ot(e,t,i)},p(e,[i]){i&1&&E(t,"d",e[0])},i:Nt,o:Nt,d(e){e&&it(t)}}}function _C(r,t,e){let i,n,{annotation:s}=t;return r.$$set=o=>{"annotation"in o&&e(1,s=o.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(2,i=s.target.selector.geometry),r.$$.dirty&4&&e(0,n=fa(i))},[n,s,i]}class vC extends Yt{constructor(t){super(),Wt(this,t,_C,yC,Ut,{annotation:1})}}function bC(r){let t,e,i,n,s;return{c(){t=J("rect"),E(t,"x",e=r[0].x),E(t,"y",i=r[0].y),E(t,"width",n=r[0].w),E(t,"height",s=r[0].h)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].x)&&E(t,"x",e),a&1&&i!==(i=o[0].y)&&E(t,"y",i),a&1&&n!==(n=o[0].w)&&E(t,"width",n),a&1&&s!==(s=o[0].h)&&E(t,"height",s)},i:Nt,o:Nt,d(o){o&&it(t)}}}function xC(r,t,e){let i,{annotation:n}=t;return r.$$set=s=>{"annotation"in s&&e(1,n=s.annotation)},r.$$.update=()=>{r.$$.dirty&2&&e(0,i=n.target.selector.geometry)},[i,n]}class wC extends Yt{constructor(t){super(),Wt(this,t,xC,bC,Ut,{annotation:1})}}const{Boolean:EC}=Oa;function ag(r,t,e){const i=r.slice();return i[10]=t[e],i}function lg(r){let t,e;return t=new Wh({props:{viewer:r[0],$$slots:{default:[RC,({transform:i})=>({9:i}),({transform:i})=>i?512:0]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&1&&(s.viewer=i[0]),n&8710&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function TC(r){let t,e;return t=new cC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function AC(r){let t,e;return t=new aC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function SC(r){let t,e;return t=new vC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function CC(r){let t,e;return t=new fC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function IC(r){let t,e;return t=new gC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function PC(r){let t,e;return t=new wC({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Ot(t,i,n),e=!0},p(i,n){const s={};n&2&&(s.annotation=i[10]),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){nt(t.$$.fragment,i),e=!1},d(i){Bt(t,i)}}}function hg(r){let t,e,i,n;const s=[PC,IC,CC,SC,AC,TC],o=[];function a(l,h){return l[10].target.selector.type===_t.RECTANGLE?0:l[10].target.selector.type===_t.POLYGON?1:l[10].target.selector.type===_t.MULTIPOLYGON?2:l[10].target.selector.type===_t.POLYLINE?3:l[10].target.selector.type===_t.ELLIPSE?4:l[10].target.selector.type===_t.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=Be()},m(l,h){~t&&o[t].m(l,h),ot(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(le(),nt(o[c],1,1,()=>{o[c]=null}),he()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),q(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(q(e),n=!0)},o(l){nt(e),n=!1},d(l){l&&it(i),~t&&o[t].d(l)}}}function RC(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,g=Ae(r[1].filter(r[6])),y=[];for(let v=0;v<g.length;v+=1)y[v]=hg(ag(r,g,v));const _=v=>nt(y[v],1,1,()=>{y[v]=null});return{c(){var v,m,x,S;t=J("svg"),e=J("g"),i=J("rect"),l=J("rect");for(let R=0;R<y.length;R+=1)y[R].c();E(i,"class","a9s-union-bg svelte-jwrce3"),E(i,"x",n=(v=r[2])==null?void 0:v.minX),E(i,"y",s=(m=r[2])==null?void 0:m.minY),E(i,"width",o=r[2]?r[2].maxX-r[2].minX:0),E(i,"height",a=r[2]?r[2].maxY-r[2].minY:0),E(l,"class","a9s-union-fg svelte-jwrce3"),E(l,"x",h=(x=r[2])==null?void 0:x.minX),E(l,"y",c=(S=r[2])==null?void 0:S.minY),E(l,"width",u=r[2]?r[2].maxX-r[2].minX:0),E(l,"height",d=r[2]?r[2].maxY-r[2].minY:0),E(e,"transform",f=r[9]),E(t,"class","a9s-osd-selectionlayer svelte-jwrce3")},m(v,m){ot(v,t,m),Tt(t,e),Tt(e,i),Tt(e,l);for(let x=0;x<y.length;x+=1)y[x]&&y[x].m(e,null);p=!0},p(v,m){var x,S,R,C;if((!p||m&4&&n!==(n=(x=v[2])==null?void 0:x.minX))&&E(i,"x",n),(!p||m&4&&s!==(s=(S=v[2])==null?void 0:S.minY))&&E(i,"y",s),(!p||m&4&&o!==(o=v[2]?v[2].maxX-v[2].minX:0))&&E(i,"width",o),(!p||m&4&&a!==(a=v[2]?v[2].maxY-v[2].minY:0))&&E(i,"height",a),(!p||m&4&&h!==(h=(R=v[2])==null?void 0:R.minX))&&E(l,"x",h),(!p||m&4&&c!==(c=(C=v[2])==null?void 0:C.minY))&&E(l,"y",c),(!p||m&4&&u!==(u=v[2]?v[2].maxX-v[2].minX:0))&&E(l,"width",u),(!p||m&4&&d!==(d=v[2]?v[2].maxY-v[2].minY:0))&&E(l,"height",d),m&2){g=Ae(v[1].filter(v[6]));let I;for(I=0;I<g.length;I+=1){const M=ag(v,g,I);y[I]?(y[I].p(M,m),q(y[I],1)):(y[I]=hg(M),y[I].c(),q(y[I],1),y[I].m(e,null))}for(le(),I=g.length;I<y.length;I+=1)_(I);he()}(!p||m&512&&f!==(f=v[9]))&&E(e,"transform",f)},i(v){if(!p){for(let m=0;m<g.length;m+=1)q(y[m]);p=!0}},o(v){y=y.filter(EC);for(let m=0;m<y.length;m+=1)nt(y[m]);p=!1},d(v){v&&it(t),$r(y,v)}}}function MC(r){let t=!!r[2],e,i,n=t&&lg(r);return{c(){n&&n.c(),e=Be()},m(s,o){n&&n.m(s,o),ot(s,e,o),i=!0},p(s,[o]){o&4&&(t=!!s[2]),t?n?(n.p(s,o),o&4&&q(n,1)):(n=lg(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),nt(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){nt(n),i=!1},d(s){s&&it(e),n&&n.d(s)}}}function OC(r,t,e){let i,n,s,{state:o}=t,{viewer:a}=t;const{store:l}=o,{selection:h}=o;Fn(r,h,d=>e(5,s=d));const c=d=>{let f=-1/0,p=-1/0,g=1/0,y=1/0;for(let _ of d.filter(v=>Ge(v))){const{bounds:v}=_.target.selector.geometry;v.maxX>f&&(f=v.maxX),v.maxY>p&&(p=v.maxY),v.minX<g&&(g=v.minX),v.minY<y&&(y=v.minY)}return a.forceRedraw(),{maxX:f,maxY:p,minX:g,minY:y}},u=d=>Ge(d);return r.$$set=d=>{"state"in d&&e(4,o=d.state),"viewer"in d&&e(0,a=d.viewer)},r.$$.update=()=>{r.$$.dirty&32&&e(1,i=s.selected.map(({id:d})=>l.getAnnotation(d))),r.$$.dirty&2&&e(2,n=i.length>1?c(i):void 0)},[a,i,n,h,o,s,u]}class BC extends Yt{constructor(t){super(),Wt(this,t,OC,MC,Ut,{state:4,viewer:0})}}const cg=(r,t)=>{t==="auto"?r.addHandler("open",e=>{const i=r.world.getItemCount();r.world.getItemAt(i-1).addOnceHandler("fully-loaded-change",s=>{const{fullyLoaded:o}=s;if(o){const a=r.canvas.querySelector("canvas"),l=yu(a);r.element.setAttribute("data-theme",l)}})}):r.element.setAttribute("data-theme",t)},ug=(r,t,e)=>(i,n={})=>{const s=typeof i=="string"?i:i.id,o=t.getAnnotation(s);if(!o||!Ge(o))return;const a=r.container.getBoundingClientRect(),{padding:l}=n;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:g,maxY:y}=o.target.selector.geometry.bounds,_=g-f,v=y-p,m=f-d*_,x=p-h*v,S=_+(c+d)*_,R=v+(h+u)*v,C=r.viewport.imageToViewportRectangle(m,x,S,R);r.viewport[e](C,n.immediately)},LC=(r,t)=>ug(r,t,"fitBounds"),DC=(r,t)=>ug(r,t,"fitBoundsWithConstraints"),NC=(r,t={})=>{const e=vu(t,{drawingEnabled:!1,drawingMode:Fe?"drag":"click",userSelectAction:ra.EDIT,theme:"light"}),i=gu(e),{hover:n,selection:s,store:o}=i,a=Rg(o,e.initialHistory),l=Mg(i,a,e.adapter,e.autoSave);let h=Ug(),c=e.drawingEnabled,u=e.drawingMode,d=e.modalSelect;const f=xu(a,r.element),p=new M2({target:r.element,props:{state:i,viewer:r,style:e.style,filter:void 0}}),g=new nC({target:r.element.querySelector(".openseadragon-canvas"),props:{provider:void 0,store:o,viewer:r}}),y=new V2({target:r.element.querySelector(".openseadragon-canvas"),props:{drawingEnabled:!!c,filter:void 0,multiSelect:e.multiSelect,preferredDrawingMode:u,state:i,style:e.style,user:h,viewer:r}}),_=t.multiSelect?new BC({target:r.element.querySelector(".openseadragon-canvas"),props:{state:i,viewer:r}}):void 0;p.$on("click",k=>{const{originalEvent:V,annotation:j}=k.detail,st=H=>jm(H.id,V,s,e.multiSelect);d?s.isEmpty()&&j&&s.userSelect(st(j),V):j&&!(u==="click"&&c)?s.userSelect(st(j),V):s.isEmpty()||(e.multiSelect?V.metaKey||V.shiftKey||V.ctrlKey||s.userSelect([],V):s.userSelect([],V))}),r.element.addEventListener("pointerdown",k=>{if(n.current){const V=o.getAnnotation(n.current);l.emit("clickAnnotation",V,k)}}),cg(r,e.theme);const v=Bg(i,a,e.adapter),m=()=>y.cancelDrawing(),x=()=>{p.$destroy(),g.$destroy(),y.$destroy(),_==null||_.$destroy(),f.destroy(),a.destroy()},S=LC(r,o),R=DC(r,o),C=()=>y.getDrawingTool(),I=()=>h,M=()=>y.isDrawingEnabled(),F=(k,V,j)=>eu(k,V,j),U=(k,V)=>Zc(k,V),P=k=>{if(!Ms(k))throw`No drawing tool named ${k}`;y.$set({toolName:k})},T=k=>{c=k,y.$set({drawingEnabled:k})},w=k=>{u=k||(Fe?"drag":"click"),y.$set({preferredDrawingMode:u})},A=k=>{p.$set({filter:k}),y.$set({filter:k})},L=k=>d=k,O=k=>{p.$set({style:k}),y.$set({style:k})},D=k=>g.$set({provider:k}),$=k=>cg(r,k),B=k=>{h=k,y.$set({user:k})},N=k=>p.$set({visible:k});return{...v,cancelDrawing:m,destroy:x,fitBounds:S,fitBoundsWithConstraints:R,getDrawingTool:C,getUser:I,isDrawingEnabled:M,listDrawingTools:Rs,on:l.on,off:l.off,registerDrawingTool:F,registerShapeEditor:U,setDrawingEnabled:T,setDrawingMode:w,setDrawingTool:P,setFilter:A,setModalSelect:L,setPresenceProvider:D,setStyle:O,setTheme:$,setUser:B,setVisible:N,state:i,viewer:r}};qt.ShapeType=_t,qt.UserSelectAction=ra,qt.W3CImageFormat=f0,qt.chainStyles=i0,qt.computeStyle=r0,qt.createBody=xg,qt.createImageAnnotator=rv,qt.createOSDAnnotator=NC,qt.defaultColorProvider=$g,Object.defineProperty(qt,Symbol.toStringTag,{value:"Module"})});
1148
1148
  //# sourceMappingURL=annotorious-openseadragon.js.map