@annotorious/openseadragon 3.7.18 → 3.7.19

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,8 +1,8 @@
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 cC=Object.defineProperty;var uC=(qt,se,Zr)=>se in qt?cC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:Zr}):qt[se]=Zr;var Fh=(qt,se,Zr)=>uC(qt,typeof se!="symbol"?se+"":se,Zr);var Zr=Object.prototype.hasOwnProperty;function Qr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Qr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Zr.call(r,e)&&++i&&!Zr.call(t,e)||!(e in t)||!Qr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var $o=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))($o||{});const fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function ng(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()}let Ho;const sg=new Uint8Array(16);function og(){if(!Ho){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ho=crypto.getRandomValues.bind(crypto)}return Ho(sg)}const ag=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),jh={randomUUID:ag};function lg(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??og();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,ng(n)}function hg(r,t,e){return jh.randomUUID&&!r?jh.randomUUID():lg(r)}const Xo=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},cg=(r,t,e,i)=>({id:hg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),ug=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},dg=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},fg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Qr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),pg=(r,t)=>!Qr(r.target,t.target),mg=(r,t)=>{const e=ug(r,t),i=dg(r,t),n=fg(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:pg(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Rr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Rr||{});const gg=(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(m=>m.oldValue.id===f.id).newValue;return mg(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let yg=()=>({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 _g=250,vg=(r,t)=>{const e=yg(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>_g)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=gg(i[_],m)}o=y}s=!1};r.observe(a,{origin:Rr.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:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),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,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},bg=(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 g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Qr(b,g))&&p("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:S})=>S===g.id)||g)};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 g=o.getAnnotation(v.id);g&&!Qr(g,v)&&p("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Qr(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}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(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>p("createAnnotation",b)),(g||[]).forEach(b=>p("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),p("updateAnnotation",S,R)})},{origin:Rr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(R=>R.id===b.id)||b))}},{origin:Rr.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},xg=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:[]}),wg=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Rr.REMOTE):console.error(g)}else i.addAnnotation(Xo(_),Rr.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(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(f(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||xg(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Rr.REMOTE)}else i.bulkAddAnnotations(_.map(Xo),v,Rr.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(Xo(_)),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:m,undo:t.undo,updateAnnotation:y}},Eg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Tg=r=>crypto.getRandomValues(new Uint8Array(r)),Ag=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},Sg=(r,t=21)=>Ag(r,t|0,Tg),Cg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Eg[e[r]&63];return t};const Ig=()=>({isGuest:!0,id:Sg("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Pg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Rg=()=>{const r=[...Pg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Cg();var Mg=Object.defineProperty,Dg=(r,t,e)=>t in r?Mg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Wh=(r,t,e)=>Dg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function Vo(r,t){for(const e in t)r[e]=t[e];return r}function zh(r){return r()}function Yh(){return Object.create(null)}function Me(r){r.forEach(zh)}function Gt(r){return typeof r=="function"}function Kt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Bg(r){return Object.keys(r).length===0}function qh(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 jo(r,t,e){r.$$.on_destroy.push(qh(t,e))}function Og(r,t,e,i){if(r){const n=Kh(r,t,e,i);return r[0](n)}}function Kh(r,t,e,i){return r[1]&&i?Vo(e.ctx.slice(),r[1](i(t))):e.ctx}function Lg(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 Ng(r,t,e,i,n,s){if(n){const o=Kh(t,e,i,s);r.p(o,n)}}function Fg(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 Zh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ai(r){return r??""}function xt(r,t){r.appendChild(t)}function nt(r,t,e){r.insertBefore(t,e||null)}function rt(r){r.parentNode&&r.parentNode.removeChild(r)}function Jr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function z(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Qh(r){return document.createTextNode(r)}function we(){return Qh(" ")}function De(){return Qh("")}function St(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function x(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function kg(r){return Array.from(r.childNodes)}function Je(r,t,e){r.classList.toggle(t,!!e)}function Ug(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let _n;function vn(r){_n=r}function Jh(){if(!_n)throw new Error("Function called outside component initialization");return _n}function ti(r){Jh().$$.on_mount.push(r)}function Mr(){const r=Jh();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Ug(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 Si=[],as=[];let Ci=[];const tc=[],ec=Promise.resolve();let Wo=!1;function rc(){Wo||(Wo=!0,ec.then(nc))}function ic(){return rc(),ec}function zo(r){Ci.push(r)}const Yo=new Set;let Ii=0;function nc(){if(Ii!==0)return;const r=_n;do{try{for(;Ii<Si.length;){const t=Si[Ii];Ii++,vn(t),Gg(t.$$)}}catch(t){throw Si.length=0,Ii=0,t}for(vn(null),Si.length=0,Ii=0;as.length;)as.pop()();for(let t=0;t<Ci.length;t+=1){const e=Ci[t];Yo.has(e)||(Yo.add(e),e())}Ci.length=0}while(Si.length);for(;tc.length;)tc.pop()();Wo=!1,Yo.clear(),vn(r)}function Gg(r){if(r.fragment!==null){r.update(),Me(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(zo)}}function $g(r){const t=[],e=[];Ci.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ci=t}const ls=new Set;let ei;function Ee(){ei={r:0,c:[],p:ei}}function Te(){ei.r||Me(ei.c),ei=ei.p}function lt(r,t){r&&r.i&&(ls.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(ls.has(r))return;ls.add(r),ei.c.push(()=>{ls.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ie(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function re(r){r&&r.c()}function Jt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),zo(()=>{const s=r.$$.on_mount.map(zh).filter(Gt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Me(s),r.$$.on_mount=[]}),n.forEach(zo)}function te(r,t){const e=r.$$;e.fragment!==null&&($g(e.after_update),Me(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Hg(r,t){r.$$.dirty[0]===-1&&(Si.push(r),rc(),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=_n;vn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:Yh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Yh(),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&&Hg(r,u)),d}):[],h.update(),c=!0,Me(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=kg(t.target);h.fragment&&h.fragment.l(u),u.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&lt(r.$$.fragment),Jt(r,t.target,t.anchor),nc()}vn(l)}class me{constructor(){Wh(this,"$$"),Wh(this,"$$set")}$destroy(){te(this,1),this.$destroy=Rt}$on(t,e){if(!Gt(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&&!Bg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Xg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Xg);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),Vg={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 m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}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})()})(Vg);const qo={},Pi=(r,t)=>qo[r]=t,Ko=r=>qo[r.type].area(r),jg=(r,t,e,i)=>qo[r.type].intersects(r,t,e,i),Ae=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}},hs=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)},cs=(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},Wg=(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},us=(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))},zg={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}};Pi(_t.ELLIPSE,zg);const Yg={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=us([n,s],[o,a]);return l/h<=i}};Pi(_t.LINE,Yg);const qg={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=hs(n.points),a=s.reduce((l,h)=>l+hs(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(cs(s.points,t,e)){let a=!1;for(const l of o)if(cs(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Zo=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ae(t)},He=r=>r.rings.map(t=>Wg(t.points)).join(" "),Kg=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Pi(_t.MULTIPOLYGON,qg);const Zg={area:r=>{const t=r.geometry.points;return hs(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return cs(i,t,e)}};Pi(_t.POLYGON,Zg);const Qg={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Qo(t.points,t.closed);return hs(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Qo(n.points,n.closed);return cs(s,t,e)}else return Jg(n,[t,e],i)}},Qo=(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=sc(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},sc=(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},Jg=(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=sc(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(oc(t,o[a],o[a+1])<=e)return!0}else if(oc(t,n.point,s.point)<=e)return!0}return!1},oc=(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},Jo=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(" ")};Pi(_t.POLYLINE,Qg);const ty={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};Pi(_t.RECTANGLE,ty);const Le=r=>ds(r.target),ds=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},ey=r=>(r==null?void 0:r.type)==="FragmentSelector"?!0:typeof r=="string"?r.indexOf("#")<0?!1:/^#xywh(?:=(?:pixel:|percent:)?)\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?$/i.test(r):!1,ry=(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,m]=[l,h,c,u].map(parseFloat);return{type:_t.RECTANGLE,geometry:{x:d,y:f,w:p,h:m,bounds:{minX:d,minY:t?f-m:f,maxX:d+p,maxY:t?f:f+m}}}},iy=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}`}},ac="http://www.w3.org/2000/svg",lc=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},ny=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${ac}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},fs=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(ac),i=t.lookupNamespaceURI(null);return e||i?lc(t).firstChild:lc(ny(t)).firstChild},sy=r=>{const t=hc(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=Ae(e[0].points);return{rings:e,bounds:s}}},oy=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},ay=r=>{const t=hc(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=>oy(o)?{...o,locked:!0}:o);const s=Ae(Qo(e,n));return{points:e,closed:n,bounds:s}},hc=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},ly=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:Ae(n)}}},hy=r=>{const t=fs(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}}},cy=r=>{const t=fs(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}}},uy=r=>{const t=fs(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=ay(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},dy=r=>{const t=fs(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>sy(s)).filter(Boolean),i=e.reduce((s,o)=>[...s,...o.rings[0].points],[]),n=Ae(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}}},fy=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return ly(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return uy(t);if(t.includes("<path "))return dy(t);if(t.includes("<ellipse "))return hy(t);if(t.includes("<line "))return cy(t);throw"Unsupported SVG shape: "+t},py=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${He(t)}" />`).join("")}</g>`,my=r=>{let t;switch(r.type){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>${py(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="${Jo(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ge=[];for(let r=0;r<256;++r)ge.push((r+256).toString(16).slice(1));function gy(r,t=0){return(ge[r[t+0]]+ge[r[t+1]]+ge[r[t+2]]+ge[r[t+3]]+"-"+ge[r[t+4]]+ge[r[t+5]]+"-"+ge[r[t+6]]+ge[r[t+7]]+"-"+ge[r[t+8]]+ge[r[t+9]]+"-"+ge[r[t+10]]+ge[r[t+11]]+ge[r[t+12]]+ge[r[t+13]]+ge[r[t+14]]+ge[r[t+15]]).toLowerCase()}let ta;const yy=new Uint8Array(16);function _y(){if(!ta){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ta=crypto.getRandomValues.bind(crypto)}return ta(yy)}const vy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),cc={randomUUID:vy};function by(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??_y();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,gy(n)}function uc(r,t,e){return cc.randomUUID&&!r?cc.randomUUID():by(r)}var dc=Object.prototype.hasOwnProperty;function Dr(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--&&Dr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(dc.call(r,e)&&++i&&!dc.call(t,e)||!(e in t)||!Dr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}let Xe=[],Br=0;const ps=4;let ea=r=>{let t=[],e={get(){return e.lc||e.listen(()=>{})(),e.value},lc:0,listen(i){return e.lc=t.push(i),()=>{for(let s=Br+ps;s<Xe.length;)Xe[s]===i?Xe.splice(s,ps):s+=ps;let n=t.indexOf(i);~n&&(t.splice(n,1),--e.lc||e.off())}},notify(i,n){let s=!Xe.length;for(let o of t)Xe.push(o,e.value,i,n);if(s){for(Br=0;Br<Xe.length;Br+=ps)Xe[Br](Xe[Br+1],Xe[Br+2],Xe[Br+3]);Xe.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};const xy=r=>{const t=ea(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 fc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(fc||{});const ra={selected:[]},wy=(r,t,e)=>{const i=ea(ra);let n=t;const s=()=>{Dr(i.get(),ra)||i.set(ra)},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(m=>m.id===p)},l=(f,p)=>{let m;if(Array.isArray(f)){if(m=f.map(_=>r.getAnnotation(_)).filter(Boolean),m.length<f.length){console.warn("Invalid selection: "+f.filter(_=>!m.some(v=>v.id===_)));return}}else{const _=r.getAnnotation(f);if(!_){console.warn("Invalid selection: "+f);return}m=[_]}const y=m.reduce((_,v)=>{const g=d(v);return g==="EDIT"?[..._,{id:v.id,editable:!0}]:g==="SELECT"?[..._,{id:v.id}]:_},[]);i.set({selected:y,event:p})},h=(f,p)=>{const m=Array.isArray(f)?f:[f],y=m.map(_=>r.getAnnotation(_)).filter(_=>!!_);i.set({selected:y.map(_=>{const v=p===void 0?d(_)==="EDIT":p;return{id:_.id,editable:v}})}),y.length!==m.length&&console.warn("Invalid selection",f)},c=f=>{if(o())return!1;const{selected:p}=i.get();p.some(({id:m})=>f.includes(m))&&i.set({selected:p.filter(({id:m})=>!f.includes(m))})},u=f=>{n=f,h(i.get().selected.map(({id:p})=>p))},d=f=>Ey(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}},Ey=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},ye=[];for(let r=0;r<256;++r)ye.push((r+256).toString(16).slice(1));function Ty(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()}let ia;const Ay=new Uint8Array(16);function Sy(){if(!ia){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ia=crypto.getRandomValues.bind(crypto)}return ia(Ay)}const Cy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),pc={randomUUID:Cy};function Iy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Sy();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,Ty(n)}function Py(r,t,e){return pc.randomUUID&&!r?pc.randomUUID():Iy(r)}const na=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)}},Ry=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},My=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Dy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Dr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),By=(r,t)=>!Dr(r.target,t.target),mc=(r,t)=>{const e=Ry(r,t),i=My(r,t),n=Dy(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:By(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Nt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Nt||{});const Oy=(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},Ly=(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(m=>m.oldValue.id===f.id).newValue;return mc(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},ms=r=>{const t=r.id===void 0?Py():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Ny=r=>r.id!==void 0,Fy=()=>{const r=new Map,t=new Map,e=[],i=(P,T={})=>{e.push({onChange:P,options:T})},n=P=>{const T=e.findIndex(E=>E.onChange==P);T>-1&&e.splice(T,1)},s=(P,T)=>{const E={origin:P,changes:{created:T.created||[],updated:T.updated||[],deleted:T.deleted||[]},state:[...r.values()]};e.forEach(A=>{Oy(A,E)&&A.onChange(E)})},o=(P,T=Nt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const E=ms(P);r.set(E.id,E),E.bodies.forEach(A=>t.set(A.id,E.id)),s(T,{created:[E]})}},a=(P,T)=>{const E=ms(typeof P=="string"?T:P),A=typeof P=="string"?P:P.id,L=A&&r.get(A);if(L){const D=mc(L,E);return A===E.id?r.set(A,E):(r.delete(A),r.set(E.id,E)),L.bodies.forEach(N=>t.delete(N.id)),E.bodies.forEach(N=>t.set(N.id,E.id)),D}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,T=Nt.LOCAL,E=Nt.LOCAL)=>{const A=Ny(T)?E:T,L=a(P,T);L&&s(A,{updated:[L]})},h=(P,T=Nt.LOCAL)=>{r.get(P.id)?l(P,T):o(P,T)},c=(P,T=Nt.LOCAL)=>{const E=P.reduce((A,L)=>{const D=a(L);return D?[...A,D]:A},[]);E.length>0&&s(T,{updated:E})},u=(P,T=Nt.LOCAL)=>{const E=P.map(ms),{toAdd:A,toUpdate:L}=E.reduce((N,$)=>r.get($.id)?{...N,toUpdate:[...N.toUpdate,$]}:{...N,toAdd:[...N.toAdd,$]},{toAdd:[],toUpdate:[]}),D=L.map(N=>a(N,T)).filter(Boolean);A.forEach(N=>{r.set(N.id,N),N.bodies.forEach($=>t.set($.id,N.id))}),s(T,{created:A,updated:D})},d=(P,T=Nt.LOCAL)=>{const E=r.get(P.annotation);if(E){const A={...E,bodies:[...E.bodies,P]};r.set(E.id,A),t.set(P.id,A.id),s(T,{updated:[{oldValue:E,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},f=()=>[...r.values()],p=(P=Nt.LOCAL)=>{const T=[...r.values()];r.clear(),t.clear(),s(P,{deleted:T})},m=(P,T=!0,E=Nt.LOCAL)=>{const A=P.map(ms);if(T){const L=[...r.values()];r.clear(),t.clear(),A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:A,deleted:L})}else{const L=P.reduce((D,N)=>{const $=N.id&&r.get(N.id);return $?[...D,$]:D},[]);if(L.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${L.map(D=>D.id).join(", ")}`);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(N=>t.set(N.id,D.id))}),s(E,{created:A})}},y=P=>{const T=typeof P=="string"?P:P.id,E=r.get(T);if(E)return r.delete(T),E.bodies.forEach(A=>t.delete(A.id)),E;console.warn(`Attempt to delete missing annotation: ${T}`)},_=(P,T=Nt.LOCAL)=>{const E=y(P);E&&s(T,{deleted:[E]})},v=(P,T=Nt.LOCAL)=>{const E=P.reduce((A,L)=>{const D=y(L);return D?[...A,D]:A},[]);E.length>0&&s(T,{deleted:E})},g=P=>{const T=r.get(P.annotation);if(T){const E=T.bodies.find(A=>A.id===P.id);if(E){t.delete(E.id);const A={...T,bodies:T.bodies.filter(L=>L.id!==P.id)};return r.set(T.id,A),{oldValue:T,newValue:A,bodiesDeleted:[E]}}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}`)},b=(P,T=Nt.LOCAL)=>{const E=g(P);E&&s(T,{updated:[E]})},S=(P,T=Nt.LOCAL)=>{const E=P.map(A=>g(A)).filter(Boolean);E.length>0&&s(T,{updated:E})},R=P=>{const T=r.get(P);return T?{...T}:void 0},C=P=>{const T=t.get(P);if(T){const E=R(T).bodies.find(A=>A.id===P);if(E)return E;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 E=r.get(P.annotation);if(E){const A=E.bodies.find(D=>D.id===P.id),L={...E,bodies:E.bodies.map(D=>D.id===A.id?T:D)};return r.set(E.id,L),A.id!==T.id&&(t.delete(A.id),t.set(T.id,L.id)),{oldValue:E,newValue:L,bodiesUpdated:[{oldBody:A,newBody:T}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,T,E=Nt.LOCAL)=>{const A=I(P,T);A&&s(E,{updated:[A]})},F=(P,T=Nt.LOCAL)=>{const E=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(T,{updated:E})},U=P=>{const T=r.get(P.annotation);if(T){const E={...T,target:{...T.target,...P}};return r.set(T.id,E),{oldValue:T,newValue:E,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:m,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,T=Nt.LOCAL)=>{const E=P.map(A=>U(A)).filter(Boolean);E.length>0&&s(T,{updated:E})},bulkUpsertAnnotations:u,clear:p,deleteAnnotation:_,deleteBody:b,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,T=Nt.LOCAL)=>{const E=U(P);E&&s(T,{updated:[E]})},upsertAnnotation:h}};let ky=()=>({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 Uy=250,Gy=(r,t)=>{const e=ky(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>Uy)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=Ly(i[_],m)}o=y}s=!1};r.observe(a,{origin:Nt.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:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),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,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},$y=()=>{const r=ea([]);return{subscribe:r.subscribe.bind(r),set:r.set.bind(r)}},Hy=(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 g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Dr(b,g))&&p("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:b})=>b===g.id)||g)};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 g=o.getAnnotation(v.id);g&&!Dr(g,v)&&p("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Dr(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}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(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>p("createAnnotation",b)),(g||[]).forEach(b=>p("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),p("updateAnnotation",S,R)})},{origin:Nt.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(S=>S.id===b.id)||b))}},{origin:Nt.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},Xy=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:[]}),Vy=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Nt.REMOTE):console.error(g)}else i.addAnnotation(na(_),Nt.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(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(f(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||Xy(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Nt.REMOTE)}else i.bulkAddAnnotations(_.map(na),v,Nt.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(na(_)),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:m,undo:t.undo,updateAnnotation:y}},jy=(r,t,e)=>typeof t=="function"?t(r,e):t,Wy=(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||{}}},zy="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Yy=r=>crypto.getRandomValues(new Uint8Array(r)),qy=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},Ky=(r,t=21)=>qy(r,t|0,Yy),Zy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=zy[e[r]&63];return t};const Qy=()=>({isGuest:!0,id:Ky("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Jy=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}`},gc=r=>r?typeof r=="object"?{...r}:r:void 0,t0=(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-${Jy(e)}`,annotation:t,type:n,purpose:s,value:o,creator:gc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),e0=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});Zy();const r0=(r,t={strict:!0,invertY:!1})=>({parse:e=>i0(e,t),serialize:e=>n0(e,r,t)}),i0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||uc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=t0(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=ey(c)?ry(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?fy(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:gc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},n0=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:n,created:s,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==_t.RECTANGLE?iy(i.geometry):my(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:e0(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},Ri=[];function s0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Ri.length;for(const h of i)h[1](),Ri.push(h,r);if(l){for(let h=0;h<Ri.length;h+=2)Ri[h][0](Ri[h+1]);Ri.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 o0=(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}`)},a0=(r,t)=>{o0(r,t);const{subscribe:e,set:i}=s0(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}},ri=(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}},gs=(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}},Ne=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,l0=r=>({}),yc=r=>({grab:r[0]});function h0(r){let t,e,i,n;const s=r[8].default,o=Og(s,r,r[7],yc);return{c(){t=z("g"),o&&o.c(),x(t,"class","a9s-annotation selected")},m(a,l){nt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[St(t,"pointerup",r[2]),St(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Ng(o,s,a,a[7],e?Lg(s,a[7],l,l0):Fg(a[7]),yc)},i(a){e||(lt(o,a),e=!0)},o(a){yt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,Me(n)}}}function c0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Mr();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:g}=h.getBoundingClientRect(),b=_.clientX-v,S=_.clientY-g;u=l.elementToImage(b,S)}else{const{offsetX:v,offsetY:g}=_;u=l.elementToImage(v,g)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=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,m,o,a,l,h,n,i]}class sa extends me{constructor(t){super(),pe(this,t,c0,h0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function u0(r){let t,e,i,n,s,o,a,l,h=r[3]&&_c(r);return{c(){t=z("g"),e=z("circle"),h&&h.c(),n=z("circle"),x(e,"class","a9s-handle-buffer svelte-qtyc7s"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]+6/r[2]),x(e,"role","button"),x(e,"tabindex","0"),x(n,"class",s=Ai(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[5]),x(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){nt(c,t,u),xt(t,e),h&&h.m(t,null),xt(t,n),a||(l=[St(e,"dblclick",r[12]),St(e,"pointerenter",r[13]),St(e,"pointerleave",r[14]),St(e,"pointerdown",r[15]),St(e,"pointerdown",r[6]),St(e,"pointerup",r[16]),St(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&x(e,"r",i),c[3]?h?h.p(c,u):(h=_c(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ai(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&x(n,"class",s),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&32&&x(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&x(t,"class",o)},d(c){c&&rt(t),h&&h.d(),a=!1,Me(l)}}}function d0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=z("g"),e=z("circle"),n=z("circle"),o=z("circle"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]*10),x(e,"class","a9s-touch-halo"),Je(e,"touched",r[4]),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",s=r[5]+10/r[2]),x(n,"class","a9s-handle-buffer svelte-qtyc7s"),x(n,"role","button"),x(n,"tabindex","0"),x(o,"class","a9s-handle-dot"),x(o,"cx",r[0]),x(o,"cy",r[1]),x(o,"r",a=r[5]+2/r[2]),x(t,"class","a9s-touch-handle")},m(c,u){nt(c,t,u),xt(t,e),xt(t,n),xt(t,o),l||(h=[St(n,"dblclick",r[9]),St(n,"pointerdown",r[10]),St(n,"pointerdown",r[6]),St(n,"pointerup",r[11]),St(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&x(e,"r",i),u&16&&Je(e,"touched",c[4]),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&x(n,"r",s),u&1&&x(o,"cx",c[0]),u&2&&x(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&x(o,"r",a)},d(c){c&&rt(t),l=!1,Me(h)}}}function _c(r){let t,e;return{c(){t=z("circle"),x(t,"class","a9s-handle-selected"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",e=r[5]+8/r[2])},m(i,n){nt(i,t,n)},p(i,n){n&1&&x(t,"cx",i[0]),n&2&&x(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&x(t,"r",e)},d(i){i&&rt(t)}}}function f0(r){let t;function e(n,s){return Ne?d0:u0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function p0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){oe.call(this,r,g)}function d(g){oe.call(this,r,g)}function f(g){oe.call(this,r,g)}function p(g){oe.call(this,r,g)}function m(g){oe.call(this,r,g)}function y(g){oe.call(this,r,g)}function _(g){oe.call(this,r,g)}function v(g){oe.call(this,r,g)}return r.$$set=g=>{e(8,t=Vo(Vo({},t),Zh(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Zh(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Mi extends me{constructor(t){super(),pe(this,t,p0,f0,Kt,{x:0,y:1,scale:2,selected:3})}}function m0(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("circle"),n=z("circle"),s=z("circle"),x(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=1.75*r[2]),x(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[2]),x(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),x(s,"cx",r[0]),x(s,"cy",r[1]),x(s,"r",r[2]),x(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){nt(l,t,h),xt(t,e),xt(t,n),xt(t,s),o||(a=[St(e,"pointerdown",r[5]),St(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&x(e,"cx",l[0]),h&2&&x(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&x(e,"r",i),h&1&&x(n,"cx",l[0]),h&2&&x(n,"cy",l[1]),h&4&&x(n,"r",l[2]),h&1&&x(s,"cx",l[0]),h&2&&x(s,"cy",l[1]),h&4&&x(s,"r",l[2])},d(l){l&&rt(t),o=!1,Me(a)}}}function g0(r){let t;return{c(){t=z("circle"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",r[2])},m(e,i){nt(e,t,i)},p(e,i){i&1&&x(t,"cx",e[0]),i&2&&x(t,"cy",e[1]),i&4&&x(t,"r",e[2])},d(e){e&&rt(t)}}}function y0(r){let t;function e(n,s){return Ne?g0:m0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function _0(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 vc extends me{constructor(t){super(),pe(this,t,_0,y0,Kt,{x:0,y:1,scale:4})}}function oa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function bc(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function aa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function la(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function xc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[28][0]),x(t,"cy",i=r[28][1]),x(t,"r",n=bn/r[3]),x(t,"class","svelte-1h2slbm")},m(s,o){nt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&x(t,"cy",i),o[0]&8&&n!==(n=bn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function wc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1h2slbm"),x(a,"cx",l=r[28][0]),x(a,"cy",h=r[28][1]),x(a,"r",c=bn/r[3]),x(a,"class","svelte-1h2slbm"),x(t,"id",`${r[19]}-inner`),x(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){nt(u,t,d),xt(t,e),xt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&x(a,"cy",h),d[0]&8&&c!==(c=bn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Ec(r){let t,e;return t=new Mi({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(){Gt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Tc(r){let t,e;return t=new vc({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function v0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&xc(la(r)),C=r[6]!==void 0&&!r[7]&&wc(aa(r)),I=Ie(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Ec(bc(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Tc(oa(r));return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),R&&R.c(),C&&C.c(),c=we(),u=z("polygon"),f=we(),p=z("polygon"),y=we();for(let P=0;P<M.length;P+=1)M[P].c();_=we(),U&&U.c(),v=De(),x(i,"x",n=r[9].x),x(i,"y",s=r[9].y),x(i,"width",o=r[9].w),x(i,"height",a=r[9].h),x(i,"class","svelte-1h2slbm"),x(l,"points",h=r[5].points.map(Ac).join(" ")),x(l,"class","svelte-1h2slbm"),x(e,"id",`${r[19]}-outer`),x(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[19]}-outer)`),x(u,"points",d=r[5].points.map(Sc).join(" ")),x(p,"class","a9s-inner a9s-shape-handle"),x(p,"mask",`url(#${r[19]}-inner)`),x(p,"style",r[1]),x(p,"points",m=r[5].points.map(Cc).join(" "))},m(P,T){nt(P,t,T),xt(t,e),xt(e,i),xt(e,l),R&&R.m(e,null),C&&C.m(t,null),nt(P,c,T),nt(P,u,T),nt(P,f,T),nt(P,p,T),nt(P,y,T);for(let E=0;E<M.length;E+=1)M[E]&&M[E].m(P,T);nt(P,_,T),U&&U.m(P,T),nt(P,v,T),g=!0,b||(S=[St(u,"pointerup",r[14]),St(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),St(p,"pointermove",r[13]),St(p,"pointerup",r[14]),St(p,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,T){if(r=P,(!g||T[0]&512&&n!==(n=r[9].x))&&x(i,"x",n),(!g||T[0]&512&&s!==(s=r[9].y))&&x(i,"y",s),(!g||T[0]&512&&o!==(o=r[9].w))&&x(i,"width",o),(!g||T[0]&512&&a!==(a=r[9].h))&&x(i,"height",a),(!g||T[0]&32&&h!==(h=r[5].points.map(Ac).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(la(r),T):(R=xc(la(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(aa(r),T):(C=wc(aa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||T[0]&32&&d!==(d=r[5].points.map(Sc).join(" ")))&&x(u,"points",d),(!g||T[0]&2)&&x(p,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Cc).join(" ")))&&x(p,"points",m),T[0]&134322472){I=Ie(r[5].points);let E;for(E=0;E<I.length;E+=1){const A=bc(r,I,E);M[E]?(M[E].p(A,T),lt(M[E],1)):(M[E]=Ec(A),M[E].c(),lt(M[E],1),M[E].m(_.parentNode,_))}for(Ee(),E=I.length;E<M.length;E+=1)F(E);Te()}r[6]!==void 0&&!r[7]?U?(U.p(oa(r),T),T[0]&192&&lt(U,1)):(U=Tc(oa(r)),U.c(),lt(U,1),U.m(v.parentNode,v)):U&&(Ee(),yt(U,1,1,()=>{U=null}),Te())},i(P){if(!g){for(let T=0;T<I.length;T+=1)lt(M[T]);lt(U),g=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)yt(M[T]);yt(U),g=!1},d(P){P&&(rt(t),rt(c),rt(u),rt(f),rt(p),rt(y),rt(_),rt(v)),R&&R.d(),C&&C.d(),Jr(M,P),U&&U.d(P),b=!1,Me(S)}}}function b0(r){let t,e;return t=new sa({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[v0,({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(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const x0=250,w0=1e3,E0=12,bn=4.5,Ac=r=>r.join(","),Sc=r=>r.join(","),Cc=r=>r.join(",");function T0(r,t,e){let i,n,s;const o=Mr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=E=>{if(m.length>0||!n.some(B=>B.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(E.offsetX,E.offsetY),D=B=>Math.pow(B[0]-A,2)+Math.pow(B[1]-L,2),N=i.points.reduce((B,k)=>D(k)<D(B)?k:B),$=n.filter(B=>B.visible).reduce((B,k)=>D(k.point)<D(B.point)?k:B),O=Math.pow(w0/c,2);D(N)<O||D($.point)<O?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=E=>{e(7,f=!0),E.preventDefault(),E.stopPropagation(),p=performance.now()},R=E=>A=>{if(!p||Ne||performance.now()-p>x0)return;const L=m.includes(E);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):L&&m.length>1?e(8,m=[E]):L?e(8,m=[]):e(8,m=[E]),g()},C=(E,A,L)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,B],k)=>m.includes(k)?[O+L[0],B+L[1]]:[O,B]):A==="SHAPE"?D=N.points.map(([O,B])=>[O+L[0],B+L[1]]):D=N.points.map(([O,B],k)=>A===`HANDLE-${k}`?[O+L[0],B+L[1]]:[O,B]);const $=Ae(D);return{...E,geometry:{points:D,bounds:$}}},I=E=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=Ae(L);o("change",{...a,geometry:{points:L,bounds:D}}),await ic();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.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});N.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((L,D)=>!m.includes(D)),A=Ae(E);o("change",{...a,geometry:{points:E,bounds:A}}),e(8,m=[])};ti(()=>{if(Ne)return;const E=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",E)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){oe.call(this,r,E)}function P(E){oe.call(this,r,E)}function T(E){oe.call(this,r,E)}return r.$$set=E=>{"shape"in E&&e(0,a=E.shape),"computedStyle"in E&&e(1,l=E.computedStyle),"transform"in E&&e(2,h=E.transform),"viewportScale"in E&&e(3,c=E.viewportScale),"svgEl"in E&&e(4,u=E.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ne?[]:i.points.map((E,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],D=(E[0]+L[0])/2,N=(E[1]+L[1])/2,$=Math.sqrt(Math.pow(L[0]-D,2)+Math.pow(L[1]-N,2))>E0/c;return{point:[D,N],visible:$}})),r.$$.dirty[0]&40&&e(9,s=gs(i.bounds,bn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,T]}class A0 extends me{constructor(t){super(),pe(this,t,T0,b0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function S0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,T,E,A,L,D,N,$,O,B,k,V,j,K,X,ft,H,mt,Q,ut,gt,Et,Dt,Yt,Vt,et,$e,es;return Q=new Mi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Mi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Gt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Mi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Mi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),f=we(),p=z("rect"),g=we(),b=z("rect"),M=we(),F=z("rect"),E=we(),A=z("rect"),$=we(),O=z("rect"),j=we(),K=z("rect"),mt=we(),re(Q.$$.fragment),ut=we(),re(gt.$$.fragment),Et=we(),re(Dt.$$.fragment),Yt=we(),re(Vt.$$.fragment),x(i,"class","rect-mask-bg svelte-1njczvj"),x(i,"x",n=r[6].x),x(i,"y",s=r[6].y),x(i,"width",o=r[6].w),x(i,"height",a=r[6].h),x(l,"class","rect-mask-fg svelte-1njczvj"),x(l,"x",h=r[5].x),x(l,"y",c=r[5].y),x(l,"width",u=r[5].w),x(l,"height",d=r[5].h),x(e,"id",r[8]),x(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),x(p,"class","a9s-outer"),x(p,"mask",`url(#${r[8]})`),x(p,"x",m=r[5].x),x(p,"y",y=r[5].y),x(p,"width",_=r[5].w),x(p,"height",v=r[5].h),x(b,"class","a9s-inner a9s-shape-handle"),x(b,"style",r[1]),x(b,"x",S=r[5].x),x(b,"y",R=r[5].y),x(b,"width",C=r[5].w),x(b,"height",I=r[5].h),x(F,"class","a9s-edge-handle a9s-edge-handle-top"),x(F,"x",U=r[5].x),x(F,"y",P=r[5].y),x(F,"height",1),x(F,"width",T=r[5].w),x(A,"class","a9s-edge-handle a9s-edge-handle-right"),x(A,"x",L=r[5].x+r[5].w),x(A,"y",D=r[5].y),x(A,"height",N=r[5].h),x(A,"width",1),x(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(O,"x",B=r[5].x),x(O,"y",k=r[5].y+r[5].h),x(O,"height",1),x(O,"width",V=r[5].w),x(K,"class","a9s-edge-handle a9s-edge-handle-left"),x(K,"x",X=r[5].x),x(K,"y",ft=r[5].y),x(K,"height",H=r[5].h),x(K,"width",1)},m(Y,G){nt(Y,t,G),xt(t,e),xt(e,i),xt(e,l),nt(Y,f,G),nt(Y,p,G),nt(Y,g,G),nt(Y,b,G),nt(Y,M,G),nt(Y,F,G),nt(Y,E,G),nt(Y,A,G),nt(Y,$,G),nt(Y,O,G),nt(Y,j,G),nt(Y,K,G),nt(Y,mt,G),Jt(Q,Y,G),nt(Y,ut,G),Jt(gt,Y,G),nt(Y,Et,G),Jt(Dt,Y,G),nt(Y,Yt,G),Jt(Vt,Y,G),et=!0,$e||(es=[St(p,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(b,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(F,"pointerdown",function(){Gt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),St(A,"pointerdown",function(){Gt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),St(O,"pointerdown",function(){Gt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),St(K,"pointerdown",function(){Gt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&x(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&x(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&x(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&x(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&x(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&x(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&x(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&x(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&x(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&x(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&x(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&x(p,"height",v),(!et||G&2)&&x(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&x(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&x(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&x(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&x(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&x(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&x(F,"y",P),(!et||G&32&&T!==(T=r[5].w))&&x(F,"width",T),(!et||G&32&&L!==(L=r[5].x+r[5].w))&&x(A,"x",L),(!et||G&32&&D!==(D=r[5].y))&&x(A,"y",D),(!et||G&32&&N!==(N=r[5].h))&&x(A,"height",N),(!et||G&32&&B!==(B=r[5].x))&&x(O,"x",B),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&x(O,"y",k),(!et||G&32&&V!==(V=r[5].w))&&x(O,"width",V),(!et||G&32&&X!==(X=r[5].x))&&x(K,"x",X),(!et||G&32&&ft!==(ft=r[5].y))&&x(K,"y",ft),(!et||G&32&&H!==(H=r[5].h))&&x(K,"height",H);const Sr={};G&32&&(Sr.x=r[5].x),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),Q.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),gt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Dt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Vt.$set(Pr)},i(Y){et||(lt(Q.$$.fragment,Y),lt(gt.$$.fragment,Y),lt(Dt.$$.fragment,Y),lt(Vt.$$.fragment,Y),et=!0)},o(Y){yt(Q.$$.fragment,Y),yt(gt.$$.fragment,Y),yt(Dt.$$.fragment,Y),yt(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(rt(t),rt(f),rt(p),rt(g),rt(b),rt(M),rt(F),rt(E),rt(A),rt($),rt(O),rt(j),rt(K),rt(mt),rt(ut),rt(Et),rt(Yt)),te(Q,Y),te(gt,Y),te(Dt,Y),te(Vt,Y),$e=!1,Me(es)}}}function C0(r){let t,e;return t=new sa({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[S0,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){re(t.$$.fragment)},m(i,n){Jt(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&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function I0(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){oe.call(this,r,m)}function f(m){oe.call(this,r,m)}function p(m){oe.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=gs(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class P0 extends me{constructor(t){super(),pe(this,t,I0,C0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Ic=Object.prototype.hasOwnProperty;function ha(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--&&ha(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Ic.call(r,e)&&++i&&!Ic.call(t,e)||!(e in t)||!ha(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const R0=12,M0=(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,m=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>R0/t;return{point:[f,p],visible:m,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ca(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Pc(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Rc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Mc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function ua(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function da(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Dc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[29][0]),x(t,"cy",i=r[29][1]),x(t,"r",n=xn/r[3]),x(t,"class","svelte-1vxo6dc")},m(s,o){nt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&x(t,"cy",i),o[0]&8&&n!==(n=xn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function Bc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1vxo6dc"),x(a,"cx",l=r[29][0]),x(a,"cy",h=r[29][1]),x(a,"r",c=xn/r[3]),x(a,"class","svelte-1vxo6dc"),x(t,"id",`${r[18]}-${r[32]}-inner`),x(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){nt(u,t,d),xt(t,e),xt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&x(a,"cy",h),d[0]&8&&c!==(c=xn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Oc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Mi({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(){Gt(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(){re(t.$$.fragment)},m(n,s){Jt(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||(lt(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){te(t,n)}}}function Lc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Oc(Mc(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=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);nt(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Ie(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Mc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=Oc(h),n[l].c(),lt(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)lt(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&&rt(t),Jr(n,o)}}}function Nc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&Dc(da(r)),g=r[6]!==void 0&&!r[7]&&Bc(ua(r)),b=Ie(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Lc(Rc(r,b,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=z("g"),e=z("defs"),i=z("mask"),n=z("rect"),h=z("path"),v&&v.c(),g&&g.c(),u=z("path"),f=z("path");for(let C=0;C<S.length;C+=1)S[C].c();x(n,"x",s=r[9].x),x(n,"y",o=r[9].y),x(n,"width",a=r[9].w),x(n,"height",l=r[9].h),x(n,"class","svelte-1vxo6dc"),x(h,"d",c=He(r[30])),x(h,"class","svelte-1vxo6dc"),x(i,"id",`${r[18]}-${r[32]}-outer`),x(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),x(u,"fill-rule","evenodd"),x(u,"d",d=He(r[30])),x(f,"class","a9s-inner"),x(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),x(f,"style",r[1]),x(f,"fill-rule","evenodd"),x(f,"d",p=He(r[30]))},m(C,I){nt(C,t,I),xt(t,e),xt(e,i),xt(i,n),xt(i,h),v&&v.m(i,null),g&&g.m(e,null),xt(t,u),xt(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[St(u,"pointerup",r[13]),St(u,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),St(f,"pointerup",r[13]),St(f,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&x(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&x(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&x(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&x(n,"height",l),(!m||I[0]&32&&c!==(c=He(r[30])))&&x(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(da(r),I):(v=Dc(da(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(ua(r),I):(g=Bc(ua(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=He(r[30])))&&x(u,"d",d),(!m||I[0]&2)&&x(f,"style",r[1]),(!m||I[0]&32&&p!==(p=He(r[30])))&&x(f,"d",p),I[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Rc(r,b,M);S[M]?(S[M].p(F,I),lt(S[M],1)):(S[M]=Lc(F),S[M].c(),lt(S[M],1),S[M].m(t,null))}for(Ee(),M=b.length;M<S.length;M+=1)R(M);Te()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)lt(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)yt(S[I]);m=!1},d(C){C&&rt(t),v&&v.d(),g&&g.d(),Jr(S,C),y=!1,Me(_)}}}function Fc(r){let t,e;return t=new vc({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function D0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Nc(Pc(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Fc(ca(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=we(),a&&a.c(),e=De()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);nt(l,t,h),a&&a.m(l,h),nt(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Ie(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Pc(l,n,c);s[c]?(s[c].p(u,h),lt(s[c],1)):(s[c]=Nc(u),s[c].c(),lt(s[c],1),s[c].m(t.parentNode,t))}for(Ee(),c=n.length;c<s.length;c+=1)o(c);Te()}l[6]!==void 0&&!l[7]?a?(a.p(ca(l),h),h[0]&192&&lt(a,1)):(a=Fc(ca(l)),a.c(),lt(a,1),a.m(e.parentNode,e)):a&&(Ee(),yt(a,1,1,()=>{a=null}),Te())},i(l){if(!i){for(let h=0;h<n.length;h+=1)lt(s[h]);lt(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&&(rt(t),rt(e)),Jr(s,l),a&&a.d(l)}}}function B0(r){let t,e;return t=new sa({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[D0,({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(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const O0=250,L0=1e3,xn=4.5;function N0(r,t,e){let i,n,s;const o=Mr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[L,D]=h.elementToImage(A.offsetX,A.offsetY),N=k=>Math.pow(k[0]-L,2)+Math.pow(k[1]-D,2),$=Kg(i).reduce((k,V)=>N(V)<N(k)?V:k),O=n.filter(k=>k.visible).reduce((k,V)=>N(V.point)<N(k.point)?V:k),B=Math.pow(L0/c,2);N($)<B||N(O.point)<B?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,L,D)=>N=>{if(!p||Ne||performance.now()-p>O0)return;const $=B=>B.polygon===A&&B.ring===L&&B.point===D,O=m.some($);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(B=>!$(B))):e(8,m=[...m,{polygon:A,ring:L,point:D}]):O&&m.length>1?e(8,m=[{polygon:A,ring:L,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:A,ring:L,point:D}]),g()},C=(A,L,D)=>{g();const N=A.geometry.polygons;let $;if(L==="SHAPE")$=N.map(O=>{const B=O.rings.map((V,j)=>({points:V.points.map((K,X)=>[K[0]+D[0],K[1]+D[1]])})),k=Ae(B[0].points);return{rings:B,bounds:k}});else{const[O,B,k,V]=L.split("-").map(j=>parseInt(j));$=N.map((j,K)=>{if(K===B){const X=j.rings.map((H,mt)=>mt===k?{points:H.points.map((Q,ut)=>ut===V?[Q[0]+D[0],Q[1]+D[1]]:Q)}:H),ft=Ae(X[0].points);return{rings:X,bounds:ft}}else return j})}return{...A,geometry:{polygons:$,bounds:Zo($)}}},I=A=>async L=>{L.stopPropagation();const D=n[A],N=i.polygons.map((O,B)=>{if(B===D.elementIdx){const k=O.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),V=Ae(k[0].points);return{rings:k,bounds:V}}else return O});o("change",{...a,geometry:{polygons:N,bounds:Zo(N)}}),await ic();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const O=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(O)}},M=()=>{const A=i.polygons.map((L,D)=>{if(m.some(N=>N.polygon===D)){const N=L.rings.map((O,B)=>{const k=m.filter(V=>V.polygon===D&&V.ring===B);return k.length&&O.points.length-k.length>=3?{points:O.points.filter((V,j)=>!k.some(K=>K.point===j))}:O}),$=Ae(N[0].points);return{rings:N,bounds:$}}else return L});!ha(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Zo(A)}}),e(8,m=[]))};ti(()=>{if(Ne)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,D,{polygon:N,ring:$,point:O})=>N===A&&$===L&&O===D;function P(A){oe.call(this,r,A)}function T(A){oe.call(this,r,A)}function E(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=Ne?[]:M0(i,c)),r.$$.dirty[0]&40&&e(9,s=gs(i.bounds,xn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,T,E]}class F0 extends me{constructor(t){super(),pe(this,t,N0,B0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const kc=new Map([[_t.RECTANGLE,P0],[_t.POLYGON,A0],[_t.MULTIPOLYGON,F0]]),fa=r=>kc.get(r.type),Uc=(r,t)=>kc.set(r,t);function k0(r,t,e){let i;const n=Mr();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ti(()=>(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=ri(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 U0 extends me{constructor(t){super(),pe(this,t,k0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function G0(r,t,e){const i=Mr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return ti(()=>{const c=s.closest("svg"),u=[],d=(f,p,m)=>{c==null||c.addEventListener(f,p,m),u.push(()=>c==null?void 0:c.removeEventListener(f,p,m))};return e(5,h=new o({target: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 $0 extends me{constructor(t){super(),pe(this,t,G0,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Gc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),h=z("rect"),c=z("rect"),x(i,"class","rect-mask-bg svelte-1a76qe7"),x(i,"x",n=r[1]-r[5]),x(i,"y",s=r[2]-r[5]),x(i,"width",o=r[3]+2*r[5]),x(i,"height",a=r[4]+2*r[5]),x(l,"class","rect-mask-fg svelte-1a76qe7"),x(l,"x",r[1]),x(l,"y",r[2]),x(l,"width",r[3]),x(l,"height",r[4]),x(e,"id",r[6]),x(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),x(h,"class","a9s-outer"),x(h,"mask",`url(#${r[6]})`),x(h,"x",r[1]),x(h,"y",r[2]),x(h,"width",r[3]),x(h,"height",r[4]),x(c,"class","a9s-inner"),x(c,"x",r[1]),x(c,"y",r[2]),x(c,"width",r[3]),x(c,"height",r[4])},m(u,d){nt(u,t,d),xt(t,e),xt(e,i),xt(e,l),nt(u,h,d),nt(u,c,d)},p(u,d){d&34&&n!==(n=u[1]-u[5])&&x(i,"x",n),d&36&&s!==(s=u[2]-u[5])&&x(i,"y",s),d&40&&o!==(o=u[3]+2*u[5])&&x(i,"width",o),d&48&&a!==(a=u[4]+2*u[5])&&x(i,"height",a),d&2&&x(l,"x",u[1]),d&4&&x(l,"y",u[2]),d&8&&x(l,"width",u[3]),d&16&&x(l,"height",u[4]),d&2&&x(h,"x",u[1]),d&4&&x(h,"y",u[2]),d&8&&x(h,"width",u[3]),d&16&&x(h,"height",u[4]),d&2&&x(c,"x",u[1]),d&4&&x(c,"y",u[2]),d&8&&x(c,"width",u[3]),d&16&&x(c,"height",u[4])},d(u){u&&(rt(t),rt(h),rt(c))}}}function H0(r){let t,e=r[0]&&Gc(r);return{c(){t=z("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Gc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}function X0(r,t,e){let i;const n=Mr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,f,p,m;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,m=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,m=Math.abs(u[1]-c[1])))},v=S=>{const R=S,C=performance.now()-h;if(o==="click"){if(C>300)return;c?g():(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,m=1))}else c&&(C>300||p*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(p*m>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+m},x:d,y:f,w:p,h:m}};n("create",S)}e(0,c=void 0),u=void 0};ti(()=>{s("pointerdown",y),s("pointermove",_),s("pointerup",v,!0)});const b=`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,m,i,b,s,o,a,l]}class V0 extends me{constructor(t){super(),pe(this,t,X0,H0,Kt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function pa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function $c(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m=r[1]&&Hc(r);return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),c=z("polygon"),d=z("polygon"),m&&m.c(),p=De(),x(i,"x",n=r[3].x),x(i,"y",s=r[3].y),x(i,"width",o=r[3].w),x(i,"height",a=r[3].h),x(i,"class","svelte-18wrg3t"),x(l,"points",h=r[19]),x(l,"class","svelte-18wrg3t"),x(e,"id",r[5]),x(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),x(c,"class","a9s-outer"),x(c,"mask",`url(#${r[5]})`),x(c,"points",u=r[19]),x(d,"class","a9s-inner"),x(d,"points",f=r[19])},m(y,_){nt(y,t,_),xt(t,e),xt(e,i),xt(e,l),nt(y,c,_),nt(y,d,_),m&&m.m(y,_),nt(y,p,_)},p(y,_){_&8&&n!==(n=y[3].x)&&x(i,"x",n),_&8&&s!==(s=y[3].y)&&x(i,"y",s),_&8&&o!==(o=y[3].w)&&x(i,"width",o),_&8&&a!==(a=y[3].h)&&x(i,"height",a),_&4&&h!==(h=y[19])&&x(l,"points",h),_&4&&u!==(u=y[19])&&x(c,"points",u),_&4&&f!==(f=y[19])&&x(d,"points",f),y[1]?m?m.p(y,_):(m=Hc(y),m.c(),m.m(p.parentNode,p)):m&&(m.d(1),m=null)},d(y){y&&(rt(t),rt(c),rt(d),rt(p)),m&&m.d(y)}}}function Hc(r){let t,e,i;return{c(){t=z("circle"),x(t,"class","a9s-handle svelte-18wrg3t"),x(t,"cx",e=r[0][0][0]),x(t,"cy",i=r[0][0][1]),x(t,"r",r[4])},m(n,s){nt(n,t,s)},p(n,s){s&1&&e!==(e=n[0][0][0])&&x(t,"cx",e),s&1&&i!==(i=n[0][0][1])&&x(t,"cy",i),s&16&&x(t,"r",n[4])},d(n){n&&rt(t)}}}function j0(r){let t,e=r[3]&&$c(pa(r));return{c(){t=z("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(pa(i),n):(e=$c(pa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}const W0=20,z0=1500;function Y0(r,t,e){let i,n,s;const o=Mr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],f,p,m=!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=us(f,d[0])*c;e(1,m=I<W0)}C.pointerType==="touch"&&(p=setTimeout(()=>{g()},z0))}},v=R=>{const C=R;if(p&&clearTimeout(p),l==="click"){const I=C.timeStamp-u.timeStamp,M=us([u.offsetX,u.offsetY],[C.offsetX,C.offsetY]);if(I>300||M>15)return;if(m)b();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&&us(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}C.stopImmediatePropagation(),m?b():d.push(f)}},g=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:Ae(d),points:R}};Ko(C)>4&&(e(0,d=[]),e(10,f=void 0),o("create",C))},b=()=>{const R={type:_t.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};ti(()=>{a("pointerdown",y,!0),a("pointermove",_),a("pointerup",v,!0),a("dblclick",g,!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?m?d:[...d,f]:[]),r.$$.dirty&516&&e(3,s=n.length>0?gs(Ae(n),2/c):void 0)},[d,m,n,s,i,S,a,l,h,c,f]}class q0 extends me{constructor(t){super(),pe(this,t,Y0,j0,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const ma=new Map([["rectangle",{tool:V0}],["polygon",{tool:q0}]]),ys=()=>[...ma.keys()],_s=r=>ma.get(r),Xc=(r,t,e={})=>ma.set(r,{tool:t,opts:e});function K0(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("ellipse"),n=z("ellipse"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"cx",r[2]),x(e,"cy",r[3]),x(e,"rx",r[4]),x(e,"ry",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"cx",r[2]),x(n,"cy",r[3]),x(n,"rx",r[4]),x(n,"ry",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}function Z0(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=ri(n,o))},[n,i,a,l,h,c,s,o]}class Q0 extends me{constructor(t){super(),pe(this,t,Z0,K0,Kt,{annotation:0,geom:6,style:7})}}function J0(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("line"),n=z("line"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"x1",r[2]),x(e,"y1",r[3]),x(e,"x2",r[4]),x(e,"y2",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"x1",r[2]),x(n,"y1",r[3]),x(n,"x2",r[4]),x(n,"y2",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}function t_(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=ri(n,o))},[n,i,l,h,c,u,s,o]}class e_ extends me{constructor(t){super(),pe(this,t,t_,J0,Kt,{annotation:0,geom:6,style:7})}}function Vc(r,t,e){const i=r.slice();return i[5]=t[e],i}function jc(r){let t,e,i;return{c(){t=z("path"),i=z("path"),x(t,"class","a9s-outer"),x(t,"style",e=r[1]?"display:none;":void 0),x(t,"fill-rule","evenodd"),x(t,"d",He(r[5])),x(i,"class","a9s-inner"),x(i,"style",r[1]),x(i,"fill-rule","evenodd"),x(i,"d",He(r[5]))},m(n,s){nt(n,t,s),nt(n,i,s)},p(n,s){s&2&&e!==(e=n[1]?"display:none;":void 0)&&x(t,"style",e),s&2&&x(i,"style",n[1])},d(n){n&&(rt(t),rt(i))}}}function r_(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=jc(Vc(r,i,s));return{c(){t=z("g");for(let s=0;s<n.length;s+=1)n[s].c();x(t,"class","a9s-annotation"),x(t,"data-id",e=r[0].id)},m(s,o){nt(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=Ie(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Vc(s,i,a);n[a]?n[a].p(l,o):(n[a]=jc(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)&&x(t,"data-id",e)},i:Rt,o:Rt,d(s){s&&rt(t),Jr(n,s)}}}function i_(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=ri(n,o))},[n,i,a,s,o]}class n_ extends me{constructor(t){super(),pe(this,t,i_,r_,Kt,{annotation:0,geom:3,style:4})}}function s_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("polygon"),n=z("polygon"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"points",r[2].map(o_).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(a_).join(" ")),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}const o_=r=>r.join(","),a_=r=>r.join(",");function l_(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=ri(n,o))},[n,i,a,s,o]}class h_ extends me{constructor(t){super(),pe(this,t,l_,s_,Kt,{annotation:0,geom:3,style:4})}}function c_(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("path"),s=z("path"),x(e,"class",i=Ai(`a9s-outer ${r[1]}`)+" svelte-1w0132l"),x(e,"style",n=r[3]?"display:none;":void 0),x(e,"d",r[2]),x(s,"class",o=Ai(`a9s-inner ${r[1]}`)+" svelte-1w0132l"),x(s,"style",r[3]),x(s,"d",r[2]),x(t,"class","a9s-annotation"),x(t,"data-id",a=r[0].id)},m(l,h){nt(l,t,h),xt(t,e),xt(t,s)},p(l,[h]){h&2&&i!==(i=Ai(`a9s-outer ${l[1]}`)+" svelte-1w0132l")&&x(e,"class",i),h&8&&n!==(n=l[3]?"display:none;":void 0)&&x(e,"style",n),h&4&&x(e,"d",l[2]),h&2&&o!==(o=Ai(`a9s-inner ${l[1]}`)+" svelte-1w0132l")&&x(s,"class",o),h&8&&x(s,"style",l[3]),h&4&&x(s,"d",l[2]),h&1&&a!==(a=l[0].id)&&x(t,"data-id",a)},i:Rt,o:Rt,d(l){l&&rt(t)}}}function u_(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=ri(o,l)),r.$$.dirty&16&&e(2,n=Jo(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class d_ extends me{constructor(t){super(),pe(this,t,u_,c_,Kt,{annotation:0,geom:4,style:5})}}function f_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("rect"),n=z("rect"),x(e,"class","a9s-outer"),x(e,"style",i=r[5]?"display:none;":void 0),x(e,"x",r[4]),x(e,"y",r[3]),x(e,"width",r[2]),x(e,"height",r[1]),x(n,"class","a9s-inner"),x(n,"style",r[5]),x(n,"x",r[4]),x(n,"y",r[3]),x(n,"width",r[2]),x(n,"height",r[1]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&x(e,"style",i),a&16&&x(e,"x",o[4]),a&8&&x(e,"y",o[3]),a&4&&x(e,"width",o[2]),a&2&&x(e,"height",o[1]),a&32&&x(n,"style",o[5]),a&16&&x(n,"x",o[4]),a&8&&x(n,"y",o[3]),a&4&&x(n,"width",o[2]),a&2&&x(n,"height",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}function p_(r,t,e){let i,n,s,o,a,{annotation:l}=t,{geom:h}=t,{style:c}=t;return r.$$set=u=>{"annotation"in u&&e(0,l=u.annotation),"geom"in u&&e(6,h=u.geom),"style"in u&&e(7,c=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=ri(l,c)),r.$$.dirty&64&&e(4,{x:n,y:s,w:o,h:a}=h,n,(e(3,s),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,s,n,i,h,c]}class m_ extends me{constructor(t){super(),pe(this,t,p_,f_,Kt,{annotation:0,geom:6,style:7})}}const g_=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]}}),y_=250,__=(r,t)=>{const e=Mr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<y_){const{x:s,y:o}=Wc(n,r),a=Ne?10:2,l=t.getAt(s,o,void 0,a);l?e("click",{originalEvent:n,annotation:l}):e("click",{originalEvent:n})}}}},Wc=(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 zc(r,t,e){const i=r.slice();return i[39]=t[e],i}function Yc(r,t,e){const i=r.slice();return i[42]=t[e],i}function ga(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function qc(r){let t=r[42],e,i,n=Kc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&131072&&Kt(t,t=s[42])?(Ee(),yt(n,1,1,Rt),Te(),n=Kc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function v_(r){let t,e;return t=new e_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function b_(r){let t,e;return t=new d_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function x_(r){let t,e;return t=new n_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function w_(r){let t,e;return t=new h_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function E_(r){let t,e;return t=new m_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function T_(r){var t;let e,i;return e=new Q0({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){re(e.$$.fragment)},m(n,s){Jt(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||(lt(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){te(e,n)}}}function Kc(r){let t,e,i,n;const s=[T_,E_,w_,x_,b_,v_],o=[];function a(l,h){var c,u,d,f,p,m;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:((m=l[45])==null?void 0:m.type)===_t.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=De()},m(l,h){~t&&o[t].m(l,h),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Zc(r){let t=Le(r[42])&&!r[10](r[42]),e,i,n=t&&qc(ga(r));return{c(){n&&n.c(),e=De()},m(s,o){n&&n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Le(s[42])&&!s[10](s[42])),t?n?(n.p(ga(s),o),o[0]&132096&&lt(n,1)):(n=qc(ga(s)),n.c(),lt(n,1),n.m(e.parentNode,e)):n&&(Ee(),yt(n,1,1,()=>{n=null}),Te())},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n&&n.d(s)}}}function Qc(r){let t,e,i,n;const s=[S_,A_],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=De()},m(l,h){~t&&o[t].m(l,h),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function A_(r){let t=`${r[2]}-${r[7]}`,e,i,n=Jc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132&&Kt(t,t=`${s[2]}-${s[7]}`)?(Ee(),yt(n,1,1,Rt),Te(),n=Jc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function S_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=eu(zc(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=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);nt(o,t,a),e=!0},p(o,a){if(a[0]&8659266){i=Ie(o[6]);let l;for(l=0;l<i.length;l+=1){const h=zc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=eu(h),n[l].c(),lt(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)lt(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&&rt(t),Jr(n,o)}}}function Jc(r){let t,e;return t=new $0({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function tu(r){let t,e;return t=new U0({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(){Gt(r[23](r[39].annotation))&&r[23](r[39].annotation).apply(this,arguments)}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function eu(r){let t=r[39].annotation.id,e,i,n=tu(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&64&&Kt(t,t=s[39].annotation.id)?(Ee(),yt(n,1,1,Rt),Te(),n=tu(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function C_(r){let t,e,i,n,s,o,a=Ie(r[17].filter(r[34])),l=[];for(let u=0;u<a.length;u+=1)l[u]=Zc(Yc(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&Qc(r);return{c(){t=z("svg"),e=z("g");for(let u=0;u<l.length;u+=1)l[u].c();i=z("g"),c&&c.c(),x(i,"class","drawing"),x(t,"role","application"),x(t,"tabindex",0),x(t,"class","a9s-annotationlayer"),Je(t,"drawing",r[15]),Je(t,"editing",r[5]),Je(t,"hidden",!r[3]),Je(t,"hover",r[16])},m(u,d){nt(u,t,d),xt(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);xt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[St(t,"pointerup",function(){Gt(r[11])&&r[11].apply(this,arguments)}),St(t,"pointerdown",function(){Gt(r[12])&&r[12].apply(this,arguments)}),St(t,"pointermove",r[24])],s=!0)},p(u,d){if(r=u,d[0]&132098){a=Ie(r[17].filter(r[34]));let f;for(f=0;f<a.length;f+=1){const p=Yc(r,a,f);l[f]?(l[f].p(p,d),lt(l[f],1)):(l[f]=Zc(p),l[f].c(),lt(l[f],1),l[f].m(e,null))}for(Ee(),f=a.length;f<l.length;f+=1)h(f);Te()}r[8]?c?(c.p(r,d),d[0]&256&&lt(c,1)):(c=Qc(r),c.c(),lt(c,1),c.m(i,null)):c&&(Ee(),yt(c,1,1,()=>{c=null}),Te()),(!n||d[0]&32768)&&Je(t,"drawing",r[15]),(!n||d[0]&32)&&Je(t,"editing",r[5]),(!n||d[0]&8)&&Je(t,"hidden",!r[3]),(!n||d[0]&65536)&&Je(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)lt(l[d]);lt(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&&rt(t),Jr(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function I_(r,t,e){let i,n,s,o,a,l,h,c,u,d,f,p,m=Rt,y=()=>(m(),m=qh(A,H=>e(18,p=H)),A);r.$$.on_destroy.push(()=>m());let{drawingEnabled:_}=t,{image:v}=t,{preferredDrawingMode:g}=t,{state:b}=t,{style:S=void 0}=t,{toolName:R=ys()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let T,E,A;ti(()=>y(e(9,A=a0(v,E))));const{hover:L,selection:D,store:N}=b;jo(r,L,H=>e(16,u=H)),jo(r,D,H=>e(33,d=H)),jo(r,N,H=>e(17,f=H));let $,O;const B=H=>{$&&N.unobserve($);const mt=H.filter(({editable:Q})=>Q).map(({id:Q})=>Q);mt.length>0?(e(5,O=mt.map(Q=>N.getAnnotation(Q)).filter(Q=>Q&&Le(Q))),$=Q=>{const{updated:ut}=Q.changes;e(5,O=ut==null?void 0:ut.map(gt=>gt.newValue))},N.observe($,{annotations:mt})):e(5,O=void 0)},k=H=>{const mt=uc(),Q={id:mt,bodies:[],target:{annotation:mt,selector:H.detail,creator:C,created:new Date}};N.addAnnotation(Q),D.setSelected(Q.id)},V=H=>mt=>{var Q;const{target:ut}=H,gt=10*60*1e3,Et=((Q=ut.creator)==null?void 0:Q.id)!==C.id||!ut.created||new Date().getTime()-ut.created.getTime()>gt;N.updateTarget({...ut,selector:mt.detail,created:Et?ut.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},j=H=>{const{x:mt,y:Q}=Wc(H,E),ut=N.getAt(mt,Q,void 0,2);ut?u!==ut.id&&L.set(ut.id):L.set(void 0)},K=H=>Le(H);function X(H){as[H?"unshift":"push"](()=>{T=H,e(8,T)})}function ft(H){as[H?"unshift":"push"](()=>{E=H,e(4,E)})}return r.$$set=H=>{"drawingEnabled"in H&&e(0,_=H.drawingEnabled),"image"in H&&e(25,v=H.image),"preferredDrawingMode"in H&&e(26,g=H.preferredDrawingMode),"state"in H&&e(27,b=H.state),"style"in H&&e(1,S=H.style),"toolName"in H&&e(2,R=H.toolName),"user"in H&&e(28,C=H.user),"visible"in H&&e(3,I=H.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=_s(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)||g),r.$$.dirty[0]&16&&e(13,o=g_(E)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=__(E,N),a,(e(11,l),e(4,E))),r.$$.dirty[1]&4&&B(d.selected),r.$$.dirty[0]&32&&e(6,h=O?O.map(H=>({annotation:H,editor:fa(H.target.selector)})).filter(H=>H.editor):void 0),r.$$.dirty[0]&64&&e(10,c=H=>h&&h.some(mt=>mt.annotation.id===H.id))},[_,S,R,I,E,O,h,M,T,A,c,l,a,o,s,i,u,f,p,L,D,N,k,V,j,v,g,b,C,F,U,P,n,d,K,X,ft]}class P_ extends me{constructor(t){super(),pe(this,t,I_,C_,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 ru(r,t,e=0,i=r.length-1,n=R_){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));ru(r,t,f,p,n)}const s=r[t];let o=e,a=i;for(wn(r,e,t),n(r[i],s)>0&&wn(r,e,i);o<a;){for(wn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?wn(r,e,a):(a++,wn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function wn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function R_(r,t){return r<t?-1:r>t?1:0}class M_{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):_a(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||_a(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=Bi([]),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=D_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&_a(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=Bi(t.slice(e,i+1)),Di(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Bi([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));iu(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);iu(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 Di(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=ya(h),u=L_(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),Tn(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=Bi(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Di(i,this.toBBox),Di(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Bi([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Di(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=En(t,0,a,this.toBBox),h=En(t,a,i,this.toBBox),c=N_(l,h),u=ya(l)+ya(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:B_,s=t.leaf?this.compareMinY:O_,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=En(t,0,e,s),a=En(t,i-e,i,s);let l=vs(o)+vs(a);for(let h=e;h<i-e;h++){const c=t.children[h];Tn(o,t.leaf?s(c):c),l+=vs(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];Tn(a,t.leaf?s(c):c),l+=vs(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)Tn(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():Di(t[e],this.toBBox)}}function D_(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 Di(r,t){En(r,0,r.children.length,t,r)}function En(r,t,e,i,n){n||(n=Bi(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];Tn(n,r.leaf?i(o):o)}return n}function Tn(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 B_(r,t){return r.minX-t.minX}function O_(r,t){return r.minY-t.minY}function ya(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function vs(r){return r.maxX-r.minX+(r.maxY-r.minY)}function L_(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 N_(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 _a(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 Bi(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function iu(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;ru(r,o,t,e,n),s.push(t,o,o,e)}}const F_=()=>{const r=new M_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!ds(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(!ds(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(c=>c.selector.type===_t.RECTANGLE||jg(c.selector,o,a,l));return h.length>0?(h.sort((c,u)=>Ko(c.selector)-Ko(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(ds(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)}}},k_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}}),nu=r=>{const t=Fy(),e=F_(),i=wy(t,r.userSelectAction,r.adapter),n=xy(t),s=$y();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}},U_=r=>{const t=nu(r);return{...t,store:k_(t.store)}},G_=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},su=r=>{const t=G_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},ou=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?su(r):e),au=(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}),lu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,hu=(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=()=>{lu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return lu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},$_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=au(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:fc.EDIT,theme:"light"}),n=U_(i),{selection:s,store:o}=n,a=Gy(o,i.initialHistory),l=Hy(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=hu(a);let u=Qy();ou(e,h,i.theme);const d=new P_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",P=>{const{originalEvent:T,annotation:E}=P.detail;E?s.userSelect(E.id,T):s.isEmpty()||s.clear()});const f=Vy(n,a,i.adapter),p=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>u,v=()=>d.isDrawingEnabled(),g=(P,T,E)=>Xc(P,T,E),b=(P,T)=>Uc(P,T),S=P=>{if(!_s(P))throw`No drawing tool named ${P}`;d.$set({toolName:P})},R=P=>d.$set({drawingEnabled:P}),C=P=>{console.warn("Filter not implemented yet")},I=P=>d.$set({style:P}),M=P=>ou(e,h,P),F=P=>{u=P,d.$set({user:P})},U=P=>d.$set({visible:P});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:ys,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingTool:S,setFilter:C,setStyle:I,setTheme:M,setUser:F,setVisible:U,element:h,state:n}};function Ft(){}function va(r,t){for(const e in t)r[e]=t[e];return r}function cu(r){return r()}function uu(){return Object.create(null)}function Fe(r){r.forEach(cu)}function Zt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function H_(r){return Object.keys(r).length===0}function X_(r,...t){if(r==null){for(const i of t)i(void 0);return Ft}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function An(r,t,e){r.$$.on_destroy.push(X_(t,e))}function du(r,t,e,i){if(r){const n=fu(r,t,e,i);return r[0](n)}}function fu(r,t,e,i){return r[1]&&i?va(e.ctx.slice(),r[1](i(t))):e.ctx}function pu(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 mu(r,t,e,i,n,s){if(n){const o=fu(t,e,i,s);r.p(o,n)}}function gu(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 yu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function _u(r){return r??""}const ba=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ct(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function st(r){r.parentNode&&r.parentNode.removeChild(r)}function Or(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function it(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function xa(r){return document.createTextNode(r)}function Se(){return xa(" ")}function Pe(){return xa("")}function Pt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function w(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function V_(r){return Array.from(r.childNodes)}function j_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Lr(r,t,e){r.classList.toggle(t,!!e)}function W_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Sn;function Cn(r){Sn=r}function wa(){if(!Sn)throw new Error("Function called outside component initialization");return Sn}function ii(r){wa().$$.on_mount.push(r)}function z_(r){wa().$$.on_destroy.push(r)}function Oi(){const r=wa();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=W_(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 Li=[],xs=[];let Ni=[];const vu=[],bu=Promise.resolve();let Ea=!1;function xu(){Ea||(Ea=!0,bu.then(Eu))}function wu(){return xu(),bu}function Ta(r){Ni.push(r)}const Aa=new Set;let Fi=0;function Eu(){if(Fi!==0)return;const r=Sn;do{try{for(;Fi<Li.length;){const t=Li[Fi];Fi++,Cn(t),Y_(t.$$)}}catch(t){throw Li.length=0,Fi=0,t}for(Cn(null),Li.length=0,Fi=0;xs.length;)xs.pop()();for(let t=0;t<Ni.length;t+=1){const e=Ni[t];Aa.has(e)||(Aa.add(e),e())}Ni.length=0}while(Li.length);for(;vu.length;)vu.pop()();Ea=!1,Aa.clear(),Cn(r)}function Y_(r){if(r.fragment!==null){r.update(),Fe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Ta)}}function q_(r){const t=[],e=[];Ni.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ni=t}const ws=new Set;let ni;function le(){ni={r:0,c:[],p:ni}}function he(){ni.r||Fe(ni.c),ni=ni.p}function q(r,t){r&&r.i&&(ws.delete(r),r.i(t))}function at(r,t,e,i){if(r&&r.o){if(ws.has(r))return;ws.add(r),ni.c.push(()=>{ws.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function xe(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Lt(r){r&&r.c()}function Bt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Ta(()=>{const s=r.$$.on_mount.map(cu).filter(Zt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Fe(s),r.$$.on_mount=[]}),n.forEach(Ta)}function Ot(r,t){const e=r.$$;e.fragment!==null&&(q_(e.after_update),Fe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function K_(r,t){r.$$.dirty[0]===-1&&(Li.push(r),xu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function jt(r,t,e,i,n,s,o=null,a=[-1]){const l=Sn;Cn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:uu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:uu(),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&&K_(r,u)),d}):[],h.update(),c=!0,Fe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=V_(t.target);h.fragment&&h.fragment.l(u),u.forEach(st)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Bt(r,t.target,t.anchor),Eu()}Cn(l)}class Wt{constructor(){Fh(this,"$$");Fh(this,"$$set")}$destroy(){Ot(this,1),this.$destroy=Ft}$on(t,e){if(!Zt(e))return Ft;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&&!H_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Z_="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Z_);var tr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(tr||{}),In=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Sa(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Q_(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 Tu={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 m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}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})()})(Tu);var J_=Tu.exports;const tv=Sa(J_),ki=(r,t)=>t,er=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},ev=(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},Au=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return tv(e,t,!0).map(i=>[i.x,i.y])},rv=(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))},iv={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(tr.ELLIPSE,iv);const nv={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=rv([n,s],[o,a]);return l/h<=i}};ki(tr.LINE,nv);const sv={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}},As=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return er(t)},Ui=r=>r.rings.map(e=>ev(e.points)).join(" "),ov=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),av=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Au(a.points,t);return{...a,points:l}}),o=er(s[0].points);return{...n,rings:s,bounds:o}}),i=As(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};ki(tr.MULTIPOLYGON,sv);const lv={area:r=>{const t=r.geometry.points;return Es(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Ts(i,t,e)}},hv=(r,t=1)=>{const e=Au(r.geometry.points,t),i=er(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};ki(tr.POLYGON,lv);const cv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Su(t.points,t.closed);return Es(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Su(n.points,n.closed);return Ts(s,t,e)}else return uv(n,[t,e],i)}},Su=(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=Cu(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},Cu=(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},uv=(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=Cu(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(Iu(t,a[l],a[l+1])<=e)return!0}else if(Iu(t,n.point,s.point)<=e)return!0}return!1},Iu=(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(tr.POLYLINE,cv);const dv={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};ki(tr.RECTANGLE,dv);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function fv(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()}let Ca;const pv=new Uint8Array(16);function mv(){if(!Ca){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ca=crypto.getRandomValues.bind(crypto)}return Ca(pv)}const Pu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function gv(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??mv();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,fv(i)}function yv(r,t,e){return Pu.randomUUID&&!r?Pu.randomUUID():gv(r)}const _v=(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}},Ia=(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}},Nr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,vv=r=>({}),Ru=r=>({grab:r[0]});function bv(r){let t,e,i,n;const s=r[8].default,o=du(s,r,r[7],Ru);return{c(){t=it("g"),o&&o.c(),w(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)&&mu(o,s,a,a[7],e?pu(s,a[7],l,vv):gu(a[7]),Ru)},i(a){e||(q(o,a),e=!0)},o(a){at(o,a),e=!1},d(a){a&&st(t),o&&o.d(a),i=!1,Fe(n)}}}function xv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Oi();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:g,top:b}=h.getBoundingClientRect(),S=_.clientX-g,R=_.clientY-b;u=l.elementToImage(S,R)}else{const{offsetX:g,offsetY:b}=_;u=l.elementToImage(g,b)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=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,m,o,a,l,h,n,i]}class Pa extends Wt{constructor(t){super(),jt(this,t,xv,bv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function wv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Mu(r);return{c(){t=it("g"),e=it("circle"),h&&h.c(),n=it("circle"),w(e,"class","a9s-handle-buffer svelte-qtyc7s"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]+6/r[2]),w(e,"role","button"),w(e,"tabindex","0"),w(n,"class",s=_u(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[5]),w(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){ot(c,t,u),Ct(t,e),h&&h.m(t,null),Ct(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&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&w(e,"r",i),c[3]?h?h.p(c,u):(h=Mu(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=_u(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&w(n,"class",s),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&32&&w(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&w(t,"class",o)},d(c){c&&st(t),h&&h.d(),a=!1,Fe(l)}}}function Ev(r){let t,e,i,n,s,o,a,l,h;return{c(){t=it("g"),e=it("circle"),n=it("circle"),o=it("circle"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]*10),w(e,"class","a9s-touch-halo"),Lr(e,"touched",r[4]),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",s=r[5]+10/r[2]),w(n,"class","a9s-handle-buffer svelte-qtyc7s"),w(n,"role","button"),w(n,"tabindex","0"),w(o,"class","a9s-handle-dot"),w(o,"cx",r[0]),w(o,"cy",r[1]),w(o,"r",a=r[5]+2/r[2]),w(t,"class","a9s-touch-handle")},m(c,u){ot(c,t,u),Ct(t,e),Ct(t,n),Ct(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&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&w(e,"r",i),u&16&&Lr(e,"touched",c[4]),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&w(n,"r",s),u&1&&w(o,"cx",c[0]),u&2&&w(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&w(o,"r",a)},d(c){c&&st(t),l=!1,Fe(h)}}}function Mu(r){let t,e;return{c(){t=it("circle"),w(t,"class","a9s-handle-selected"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",e=r[5]+8/r[2])},m(i,n){ot(i,t,n)},p(i,n){n&1&&w(t,"cx",i[0]),n&2&&w(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&w(t,"r",e)},d(i){i&&st(t)}}}function Tv(r){let t;function e(s,o){return Nr?Ev:wv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Av(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){ae.call(this,r,g)}function d(g){ae.call(this,r,g)}function f(g){ae.call(this,r,g)}function p(g){ae.call(this,r,g)}function m(g){ae.call(this,r,g)}function y(g){ae.call(this,r,g)}function _(g){ae.call(this,r,g)}function v(g){ae.call(this,r,g)}return r.$$set=g=>{e(8,t=va(va({},t),yu(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=yu(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Gi extends Wt{constructor(t){super(),jt(this,t,Av,Tv,Ut,{x:0,y:1,scale:2,selected:3})}}function Sv(r){let t,e,i,n,s,o,a;return{c(){t=it("g"),e=it("circle"),n=it("circle"),s=it("circle"),w(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=1.75*r[2]),w(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[2]),w(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),w(s,"cx",r[0]),w(s,"cy",r[1]),w(s,"r",r[2]),w(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){ot(l,t,h),Ct(t,e),Ct(t,n),Ct(t,s),o||(a=[Pt(e,"pointerdown",r[5]),Pt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&w(e,"cx",l[0]),h&2&&w(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&w(e,"r",i),h&1&&w(n,"cx",l[0]),h&2&&w(n,"cy",l[1]),h&4&&w(n,"r",l[2]),h&1&&w(s,"cx",l[0]),h&2&&w(s,"cy",l[1]),h&4&&w(s,"r",l[2])},d(l){l&&st(t),o=!1,Fe(a)}}}function Cv(r){let t;return{c(){t=it("circle"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",r[2])},m(e,i){ot(e,t,i)},p(e,i){i&1&&w(t,"cx",e[0]),i&2&&w(t,"cy",e[1]),i&4&&w(t,"r",e[2])},d(e){e&&st(t)}}}function Iv(r){let t;function e(s,o){return Nr?Cv:Sv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Pv(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 Du extends Wt{constructor(t){super(),jt(this,t,Pv,Iv,Ut,{x:0,y:1,scale:4})}}function Ra(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Bu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Ma(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Da(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ou(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[28][0]),w(t,"cy",i=r[28][1]),w(t,"r",n=Pn/r[3]),w(t,"class","svelte-1h2slbm")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Pn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Lu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1h2slbm"),w(a,"cx",l=r[28][0]),w(a,"cy",h=r[28][1]),w(a,"r",c=Pn/r[3]),w(a,"class","svelte-1h2slbm"),w(t,"id",`${r[19]}-inner`),w(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){ot(u,t,d),Ct(t,e),Ct(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Pn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function Nu(r){let t,e;return t=new Gi({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(){Zt(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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Fu(r){let t,e;return t=new Du({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Rv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Ou(Da(r)),C=r[6]!==void 0&&!r[7]&&Lu(Ma(r)),I=xe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Nu(Bu(r,I,P));const F=P=>at(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Fu(Ra(r));return{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("polygon"),R&&R.c(),C&&C.c(),c=Se(),u=it("polygon"),f=Se(),p=it("polygon"),y=Se();for(let P=0;P<M.length;P+=1)M[P].c();_=Se(),U&&U.c(),v=Pe(),w(i,"x",n=r[9].x),w(i,"y",s=r[9].y),w(i,"width",o=r[9].w),w(i,"height",a=r[9].h),w(i,"class","svelte-1h2slbm"),w(l,"points",h=r[5].points.map(ku).join(" ")),w(l,"class","svelte-1h2slbm"),w(e,"id",`${r[19]}-outer`),w(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[19]}-outer)`),w(u,"points",d=r[5].points.map(Uu).join(" ")),w(p,"class","a9s-inner a9s-shape-handle"),w(p,"mask",`url(#${r[19]}-inner)`),w(p,"style",r[1]),w(p,"points",m=r[5].points.map(Gu).join(" "))},m(P,T){ot(P,t,T),Ct(t,e),Ct(e,i),Ct(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 E=0;E<M.length;E+=1)M[E]&&M[E].m(P,T);ot(P,_,T),U&&U.m(P,T),ot(P,v,T),g=!0,b||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(p,"pointermove",r[13]),Pt(p,"pointerup",r[14]),Pt(p,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,T){if(r=P,(!g||T[0]&512&&n!==(n=r[9].x))&&w(i,"x",n),(!g||T[0]&512&&s!==(s=r[9].y))&&w(i,"y",s),(!g||T[0]&512&&o!==(o=r[9].w))&&w(i,"width",o),(!g||T[0]&512&&a!==(a=r[9].h))&&w(i,"height",a),(!g||T[0]&32&&h!==(h=r[5].points.map(ku).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Da(r),T):(R=Ou(Da(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Ma(r),T):(C=Lu(Ma(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||T[0]&32&&d!==(d=r[5].points.map(Uu).join(" ")))&&w(u,"points",d),(!g||T[0]&2)&&w(p,"style",r[1]),(!g||T[0]&32&&m!==(m=r[5].points.map(Gu).join(" ")))&&w(p,"points",m),T[0]&134322472){I=xe(r[5].points);let E;for(E=0;E<I.length;E+=1){const A=Bu(r,I,E);M[E]?(M[E].p(A,T),q(M[E],1)):(M[E]=Nu(A),M[E].c(),q(M[E],1),M[E].m(_.parentNode,_))}for(le(),E=I.length;E<M.length;E+=1)F(E);he()}r[6]!==void 0&&!r[7]?U?(U.p(Ra(r),T),T[0]&192&&q(U,1)):(U=Fu(Ra(r)),U.c(),q(U,1),U.m(v.parentNode,v)):U&&(le(),at(U,1,1,()=>{U=null}),he())},i(P){if(!g){for(let T=0;T<I.length;T+=1)q(M[T]);q(U),g=!0}},o(P){M=M.filter(Boolean);for(let T=0;T<M.length;T+=1)at(M[T]);at(U),g=!1},d(P){P&&(st(t),st(c),st(u),st(f),st(p),st(y),st(_),st(v)),R&&R.d(),C&&C.d(),Or(M,P),U&&U.d(P),b=!1,Fe(S)}}}function Mv(r){let t,e;return t=new Pa({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[Rv,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const Dv=250,Bv=1e3,Ov=12,Pn=4.5,ku=r=>r.join(","),Uu=r=>r.join(","),Gu=r=>r.join(",");function Lv(r,t,e){let i,n,s;const o=Oi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=E=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,L]=h.elementToImage(E.offsetX,E.offsetY),D=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-L,2),N=i.points.reduce((k,V)=>D(V)<D(k)?V:k),$=n.filter(k=>k.visible).reduce((k,V)=>D(V.point)<D(k.point)?V:k),O=Math.pow(Bv/c,2);D(N)<O||D($.point)<O?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=E=>{e(7,f=!0),E.preventDefault(),E.stopPropagation(),p=performance.now()},R=E=>A=>{if(!p||Nr||performance.now()-p>Dv)return;const L=m.includes(E);A.metaKey||A.ctrlKey||A.shiftKey?L?e(8,m=m.filter(D=>D!==E)):e(8,m=[...m,E]):L&&m.length>1?e(8,m=[E]):L?e(8,m=[]):e(8,m=[E]),g()},C=(E,A,L)=>{g();let D;const N=E.geometry;m.length>1?D=N.points.map(([O,B],k)=>m.includes(k)?[O+L[0],B+L[1]]:[O,B]):A==="SHAPE"?D=N.points.map(([O,B])=>[O+L[0],B+L[1]]):D=N.points.map(([O,B],k)=>A===`HANDLE-${k}`?[O+L[0],B+L[1]]:[O,B]);const $=er(D);return{...E,geometry:{points:D,bounds:$}}},I=E=>async A=>{A.stopPropagation();const L=[...i.points.slice(0,E+1),n[E].point,...i.points.slice(E+1)],D=er(L);o("change",{...a,geometry:{points:L,bounds:D}}),await wu();const N=[...document.querySelectorAll(".a9s-handle")][E+1];if(N!=null&&N.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});N.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const E=i.points.filter((L,D)=>!m.includes(D)),A=er(E);o("change",{...a,geometry:{points:E,bounds:A}}),e(8,m=[])};ii(()=>{if(Nr)return;const E=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",E),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",E)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(E){ae.call(this,r,E)}function P(E){ae.call(this,r,E)}function T(E){ae.call(this,r,E)}return r.$$set=E=>{"shape"in E&&e(0,a=E.shape),"computedStyle"in E&&e(1,l=E.computedStyle),"transform"in E&&e(2,h=E.transform),"viewportScale"in E&&e(3,c=E.viewportScale),"svgEl"in E&&e(4,u=E.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Nr?[]:i.points.map((E,A)=>{const L=A===i.points.length-1?i.points[0]:i.points[A+1],D=(E[0]+L[0])/2,N=(E[1]+L[1])/2,O=Math.sqrt(Math.pow(L[0]-D,2)+Math.pow(L[1]-N,2))>Ov/c;return{point:[D,N],visible:O}})),r.$$.dirty[0]&40&&e(9,s=Ia(i.bounds,Pn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,T]}class Nv extends Wt{constructor(t){super(),jt(this,t,Lv,Mv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Fv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,T,E,A,L,D,N,$,O,B,k,V,j,K,X,ft,H,mt,Q,ut,gt,Et,Dt,Yt,Vt,et,$e,es;return Q=new Gi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Zt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Gi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Zt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Gi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Zt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Gi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Zt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("rect"),f=Se(),p=it("rect"),g=Se(),b=it("rect"),M=Se(),F=it("rect"),E=Se(),A=it("rect"),$=Se(),O=it("rect"),j=Se(),K=it("rect"),mt=Se(),Lt(Q.$$.fragment),ut=Se(),Lt(gt.$$.fragment),Et=Se(),Lt(Dt.$$.fragment),Yt=Se(),Lt(Vt.$$.fragment),w(i,"class","rect-mask-bg svelte-1njczvj"),w(i,"x",n=r[6].x),w(i,"y",s=r[6].y),w(i,"width",o=r[6].w),w(i,"height",a=r[6].h),w(l,"class","rect-mask-fg svelte-1njczvj"),w(l,"x",h=r[5].x),w(l,"y",c=r[5].y),w(l,"width",u=r[5].w),w(l,"height",d=r[5].h),w(e,"id",r[8]),w(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),w(p,"class","a9s-outer"),w(p,"mask",`url(#${r[8]})`),w(p,"x",m=r[5].x),w(p,"y",y=r[5].y),w(p,"width",_=r[5].w),w(p,"height",v=r[5].h),w(b,"class","a9s-inner a9s-shape-handle"),w(b,"style",r[1]),w(b,"x",S=r[5].x),w(b,"y",R=r[5].y),w(b,"width",C=r[5].w),w(b,"height",I=r[5].h),w(F,"class","a9s-edge-handle a9s-edge-handle-top"),w(F,"x",U=r[5].x),w(F,"y",P=r[5].y),w(F,"height",1),w(F,"width",T=r[5].w),w(A,"class","a9s-edge-handle a9s-edge-handle-right"),w(A,"x",L=r[5].x+r[5].w),w(A,"y",D=r[5].y),w(A,"height",N=r[5].h),w(A,"width",1),w(O,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(O,"x",B=r[5].x),w(O,"y",k=r[5].y+r[5].h),w(O,"height",1),w(O,"width",V=r[5].w),w(K,"class","a9s-edge-handle a9s-edge-handle-left"),w(K,"x",X=r[5].x),w(K,"y",ft=r[5].y),w(K,"height",H=r[5].h),w(K,"width",1)},m(Y,G){ot(Y,t,G),Ct(t,e),Ct(e,i),Ct(e,l),ot(Y,f,G),ot(Y,p,G),ot(Y,g,G),ot(Y,b,G),ot(Y,M,G),ot(Y,F,G),ot(Y,E,G),ot(Y,A,G),ot(Y,$,G),ot(Y,O,G),ot(Y,j,G),ot(Y,K,G),ot(Y,mt,G),Bt(Q,Y,G),ot(Y,ut,G),Bt(gt,Y,G),ot(Y,Et,G),Bt(Dt,Y,G),ot(Y,Yt,G),Bt(Vt,Y,G),et=!0,$e||(es=[Pt(p,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(b,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(F,"pointerdown",function(){Zt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Pt(A,"pointerdown",function(){Zt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Pt(O,"pointerdown",function(){Zt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Pt(K,"pointerdown",function(){Zt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&w(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&w(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&w(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&w(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&w(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&w(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&w(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&w(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&w(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&w(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&w(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&w(p,"height",v),(!et||G&2)&&w(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&w(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&w(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&w(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&w(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&w(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&w(F,"y",P),(!et||G&32&&T!==(T=r[5].w))&&w(F,"width",T),(!et||G&32&&L!==(L=r[5].x+r[5].w))&&w(A,"x",L),(!et||G&32&&D!==(D=r[5].y))&&w(A,"y",D),(!et||G&32&&N!==(N=r[5].h))&&w(A,"height",N),(!et||G&32&&B!==(B=r[5].x))&&w(O,"x",B),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&w(O,"y",k),(!et||G&32&&V!==(V=r[5].w))&&w(O,"width",V),(!et||G&32&&X!==(X=r[5].x))&&w(K,"x",X),(!et||G&32&&ft!==(ft=r[5].y))&&w(K,"y",ft),(!et||G&32&&H!==(H=r[5].h))&&w(K,"height",H);const Sr={};G&32&&(Sr.x=r[5].x),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),Q.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),gt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Dt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Vt.$set(Pr)},i(Y){et||(q(Q.$$.fragment,Y),q(gt.$$.fragment,Y),q(Dt.$$.fragment,Y),q(Vt.$$.fragment,Y),et=!0)},o(Y){at(Q.$$.fragment,Y),at(gt.$$.fragment,Y),at(Dt.$$.fragment,Y),at(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(st(t),st(f),st(p),st(g),st(b),st(M),st(F),st(E),st(A),st($),st(O),st(j),st(K),st(mt),st(ut),st(Et),st(Yt)),Ot(Q,Y),Ot(gt,Y),Ot(Dt,Y),Ot(Vt,Y),$e=!1,Fe(es)}}}function kv(r){let t,e;return t=new Pa({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Fv,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Uv(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){ae.call(this,r,m)}function f(m){ae.call(this,r,m)}function p(m){ae.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=Ia(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class Gv extends Wt{constructor(t){super(),jt(this,t,Uv,kv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var $u=Object.prototype.hasOwnProperty;function Ba(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--&&Ba(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if($u.call(r,e)&&++i&&!$u.call(t,e)||!(e in t)||!Ba(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const $v=12,Hv=(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))>$v/t;return{point:[f,p],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Oa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Hu(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Xu(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Vu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function La(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Na(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function ju(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[29][0]),w(t,"cy",i=r[29][1]),w(t,"r",n=Rn/r[3]),w(t,"class","svelte-1vxo6dc")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Rn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Wu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1vxo6dc"),w(a,"cx",l=r[29][0]),w(a,"cy",h=r[29][1]),w(a,"r",c=Rn/r[3]),w(a,"class","svelte-1vxo6dc"),w(t,"id",`${r[18]}-${r[32]}-inner`),w(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){ot(u,t,d),Ct(t,e),Ct(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Rn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function zu(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Gi({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(){Zt(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){Bt(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){at(t.$$.fragment,n),e=!1},d(n){Ot(t,n)}}}function Yu(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=zu(Vu(r,i,o));const s=o=>at(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},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=xe(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Vu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=zu(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)at(n[a]);e=!1},d(o){o&&st(t),Or(n,o)}}}function qu(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&ju(Na(r)),g=r[6]!==void 0&&!r[7]&&Wu(La(r)),b=xe(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Yu(Xu(r,b,C));const R=C=>at(S[C],1,1,()=>{S[C]=null});return{c(){t=it("g"),e=it("defs"),i=it("mask"),n=it("rect"),h=it("path"),v&&v.c(),g&&g.c(),u=it("path"),f=it("path");for(let C=0;C<S.length;C+=1)S[C].c();w(n,"x",s=r[9].x),w(n,"y",o=r[9].y),w(n,"width",a=r[9].w),w(n,"height",l=r[9].h),w(n,"class","svelte-1vxo6dc"),w(h,"d",c=Ui(r[30])),w(h,"class","svelte-1vxo6dc"),w(i,"id",`${r[18]}-${r[32]}-outer`),w(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),w(u,"fill-rule","evenodd"),w(u,"d",d=Ui(r[30])),w(f,"class","a9s-inner"),w(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),w(f,"style",r[1]),w(f,"fill-rule","evenodd"),w(f,"d",p=Ui(r[30]))},m(C,I){ot(C,t,I),Ct(t,e),Ct(e,i),Ct(i,n),Ct(i,h),v&&v.m(i,null),g&&g.m(e,null),Ct(t,u),Ct(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[Pt(u,"pointerup",r[13]),Pt(u,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Pt(f,"pointerup",r[13]),Pt(f,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&w(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&w(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&w(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&w(n,"height",l),(!m||I[0]&32&&c!==(c=Ui(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Na(r),I):(v=ju(Na(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(La(r),I):(g=Wu(La(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=Ui(r[30])))&&w(u,"d",d),(!m||I[0]&2)&&w(f,"style",r[1]),(!m||I[0]&32&&p!==(p=Ui(r[30])))&&w(f,"d",p),I[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Xu(r,b,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=Yu(F),S[M].c(),q(S[M],1),S[M].m(t,null))}for(le(),M=b.length;M<S.length;M+=1)R(M);he()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)q(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)at(S[I]);m=!1},d(C){C&&st(t),v&&v.d(),g&&g.d(),Or(S,C),y=!1,Fe(_)}}}function Ku(r){let t,e;return t=new Du({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Xv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=qu(Hu(r,n,l));const o=l=>at(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Ku(Oa(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Se(),a&&a.c(),e=Pe()},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=xe(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Hu(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=qu(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(Oa(l),h),h[0]&192&&q(a,1)):(a=Ku(Oa(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(le(),at(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)at(s[h]);at(a),i=!1},d(l){l&&(st(t),st(e)),Or(s,l),a&&a.d(l)}}}function Vv(r){let t,e;return t=new Pa({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Xv,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const jv=250,Wv=1e3,Rn=4.5;function zv(r,t,e){let i,n,s;const o=Oi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(V=>V.visible)){e(6,d=void 0);return}const[L,D]=h.elementToImage(A.offsetX,A.offsetY),N=V=>Math.pow(V[0]-L,2)+Math.pow(V[1]-D,2),$=ov(i).reduce((V,j)=>N(j)<N(V)?j:V),O=n.filter(V=>V.visible).reduce((V,j)=>N(j.point)<N(V.point)?j:V),B=Math.pow(Wv/c,2);N($)<B||N(O.point)<B?e(6,d=n.indexOf(O)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,L,D)=>N=>{if(!p||Nr||performance.now()-p>jv)return;const $=B=>B.polygon===A&&B.ring===L&&B.point===D,O=m.some($);N.metaKey||N.ctrlKey||N.shiftKey?O?e(8,m=m.filter(B=>!$(B))):e(8,m=[...m,{polygon:A,ring:L,point:D}]):O&&m.length>1?e(8,m=[{polygon:A,ring:L,point:D}]):O?e(8,m=[]):e(8,m=[{polygon:A,ring:L,point:D}]),g()},C=(A,L,D)=>{g();const N=A.geometry.polygons;let $;if(L==="SHAPE")$=N.map(O=>{const B=O.rings.map((V,j)=>({points:V.points.map((X,ft)=>[X[0]+D[0],X[1]+D[1]])})),k=er(B[0].points);return{rings:B,bounds:k}});else{const[O,B,k,V]=L.split("-").map(j=>parseInt(j));$=N.map((j,K)=>{if(K===B){const X=j.rings.map((H,mt)=>mt===k?{points:H.points.map((ut,gt)=>gt===V?[ut[0]+D[0],ut[1]+D[1]]:ut)}:H),ft=er(X[0].points);return{rings:X,bounds:ft}}else return j})}return{...A,geometry:{polygons:$,bounds:As($)}}},I=A=>async L=>{L.stopPropagation();const D=n[A],N=i.polygons.map((O,B)=>{if(B===D.elementIdx){const k=O.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),V=er(k[0].points);return{rings:k,bounds:V}}else return O});o("change",{...a,geometry:{polygons:N,bounds:As(N)}}),await wu();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const O=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(O)}},M=()=>{const A=i.polygons.map((D,N)=>{if(m.some(O=>O.polygon===N)){const O=D.rings.map((k,V)=>{const j=m.filter(K=>K.polygon===N&&K.ring===V);return j.length&&k.points.length-j.length>=3?{points:k.points.filter((X,ft)=>!j.some(H=>H.point===ft))}:k}),B=er(O[0].points);return{rings:O,bounds:B}}else return D});!Ba(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:As(A)}}),e(8,m=[]))};ii(()=>{if(Nr)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,D,{polygon:N,ring:$,point:O})=>N===A&&$===L&&O===D;function P(A){ae.call(this,r,A)}function T(A){ae.call(this,r,A)}function E(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=Nr?[]:Hv(i,c)),r.$$.dirty[0]&40&&e(9,s=Ia(i.bounds,Rn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,T,E]}class Yv extends Wt{constructor(t){super(),jt(this,t,zv,Vv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}tr.RECTANGLE,tr.POLYGON,tr.MULTIPOLYGON;function qv(r,t,e){let i;const n=Oi();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ii(()=>(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=_v(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 Kv extends Wt{constructor(t){super(),jt(this,t,qv,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 si=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(si||{}),Zu=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(Zu||{}),Fa=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Fa||{}),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||{}),rr=(r=>(r[r.POINTS=0]="POINTS",r[r.LINES=1]="LINES",r[r.LINE_LOOP=2]="LINE_LOOP",r[r.LINE_STRIP=3]="LINE_STRIP",r[r.TRIANGLES=4]="TRIANGLES",r[r.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",r[r.TRIANGLE_FAN=6]="TRIANGLE_FAN",r))(rr||{}),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||{}),$i=(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))($i||{}),pt=(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))(pt||{}),J=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(J||{}),gr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(gr||{}),Fr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Fr||{}),ir=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(ir||{}),Re=(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))(Re||{}),nr=(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))(nr||{}),ka=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(ka||{}),ke=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(ke||{}),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||{}),ee=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(ee||{}),sr=(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))(sr||{});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 Ua=/iPhone/i,Qu=/iPod/i,Ju=/iPad/i,td=/\biOS-universal(?:.+)Mac\b/i,Ga=/\bAndroid(?:.+)Mobile\b/i,ed=/Android/i,Hi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ss=/Silk/i,yr=/Windows Phone/i,rd=/\bWindows(?:.+)ARM\b/i,id=/BlackBerry/i,nd=/BB10/i,sd=/Opera Mini/i,od=/\b(CriOS|Chrome)(?:.+)Mobile/i,ad=/Mobile(?:.+)Firefox\b/i,ld=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Zv(r){return function(t){return t.test(r)}}function hd(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=Zv(e),s={apple:{phone:n(Ua)&&!n(yr),ipod:n(Qu),tablet:!n(Ua)&&(n(Ju)||ld(t))&&!n(yr),universal:n(td),device:(n(Ua)||n(Qu)||n(Ju)||n(td)||ld(t))&&!n(yr)},amazon:{phone:n(Hi),tablet:!n(Hi)&&n(Ss),device:n(Hi)||n(Ss)},android:{phone:!n(yr)&&n(Hi)||!n(yr)&&n(Ga),tablet:!n(yr)&&!n(Hi)&&!n(Ga)&&(n(Ss)||n(ed)),device:!n(yr)&&(n(Hi)||n(Ss)||n(Ga)||n(ed))||n(/\bokhttp\b/i)},windows:{phone:n(yr),tablet:n(rd),device:n(yr)||n(rd)},other:{blackberry:n(id),blackberry10:n(nd),opera:n(sd),firefox:n(ad),chrome:n(od),device:n(id)||n(nd)||n(sd)||n(ad)||n(od)},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 Qv=hd.default??hd,_r=Qv(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var cd={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 m=e?e+h:h;if(!this._events[m])return!1;var y=this._events[m],_=arguments.length,v,g;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,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(g=1,v=new Array(_-1);g<_;g++)v[g-1]=arguments[g];y.fn.apply(y.context,v)}else{var b=y.length,S;for(g=0;g<b;g++)switch(y[g].once&&this.removeListener(h,y[g].fn,void 0,!0),_){case 1:y[g].fn.call(y[g].context);break;case 2:y[g].fn.call(y[g].context,c);break;case 3:y[g].fn.call(y[g].context,c,u);break;case 4:y[g].fn.call(y[g].context,c,u,d);break;default:if(!v)for(S=1,v=new Array(_-1);S<_;S++)v[S-1]=arguments[S];y[g].fn.apply(y[g].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 m=0,y=[],_=p.length;m<_;m++)(p[m].fn!==c||d&&!p[m].once||u&&p[m].context!==u)&&y.push(p[m]);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})(cd);var Jv=cd.exports;const Mn=Sa(Jv);var $a={exports:{}};$a.exports=Cs,$a.exports.default=Cs;function Cs(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=ud(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=n1(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 Dn(s,o,e,a,l,f,0),o}function ud(r,t,e,i,n){var s,o;if(n===Va(r,t,e,i)>0)for(s=t;s<e;s+=i)o=pd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=pd(s,r[s],r[s+1],o);return o&&Is(o,o.next)&&(On(o),o=o.next),o}function oi(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(Is(e,e.next)||$t(e.prev,e,e.next)===0)){if(On(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Dn(r,t,e,i,n,s,o){if(r){!o&&s&&h1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?e1(r,i,n,s):t1(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),On(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=r1(oi(r),t,e),Dn(r,t,e,i,n,s,2)):o===2&&i1(r,t,e,i,n,s):Dn(oi(r),t,e,i,n,s,1);break}}}}function t1(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&&Xi(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 e1(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,m=a>l?a>h?a:h:l>h?l:h,y=c>u?c>d?c:d:u>d?u:d,_=Ha(f,p,t,e,i),v=Ha(m,y,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=_&&b&&b.z<=v;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&Xi(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0||(g=g.prevZ,b.x>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&Xi(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;g&&g.z>=_;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&Xi(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;b&&b.z<=v;){if(b.x>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&Xi(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function r1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Is(n,s)&&dd(n,i,i.next,s)&&Bn(n,s)&&Bn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),On(i),On(i.next),i=r=s),i=i.next}while(i!==r);return oi(i)}function i1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&d1(o,a)){var l=fd(o,a);o=oi(o,o.next),l=oi(l,l.next),Dn(o,t,e,i,n,s,0),Dn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function n1(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=ud(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(u1(h));for(n.sort(s1),s=0;s<n.length;s++)e=o1(n[s],e);return e}function s1(r,t){return r.x-t.x}function o1(r,t){var e=a1(r,t);if(!e)return t;var i=fd(e,r);return oi(i,i.next),oi(e,e.next)}function a1(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&&Xi(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),Bn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&l1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function l1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function h1(r,t,e,i){var n=r;do n.z===0&&(n.z=Ha(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,c1(n)}function c1(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 Ha(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 u1(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 Xi(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 d1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!f1(r,t)&&(Bn(r,t)&&Bn(t,r)&&p1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||Is(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 Is(r,t){return r.x===t.x&&r.y===t.y}function dd(r,t,e,i){var n=Rs($t(r,t,e)),s=Rs($t(r,t,i)),o=Rs($t(e,i,r)),a=Rs($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Ps(r,e,t)||s===0&&Ps(r,i,t)||o===0&&Ps(e,r,i)||a===0&&Ps(e,t,i))}function Ps(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 Rs(r){return r>0?1:r<0?-1:0}function f1(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&&dd(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Bn(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 p1(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 fd(r,t){var e=new Xa(r.i,r.x,r.y),i=new Xa(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 pd(r,t,e,i){var n=new Xa(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 On(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 Xa(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}Cs.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(Va(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(Va(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 Va(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}Cs.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 m1=$a.exports;const g1=Sa(m1);var Ms={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Ms.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof In=="object"&&In;(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,m="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},b=l-h,S=Math.floor,R=String.fromCharCode,C;function I(O){throw new RangeError(g[O])}function M(O,B){for(var k=O.length,V=[];k--;)V[k]=B(O[k]);return V}function F(O,B){var k=O.split("@"),V="";k.length>1&&(V=k[0]+"@",O=k[1]),O=O.replace(v,".");var j=O.split("."),K=M(j,B).join(".");return V+K}function U(O){for(var B=[],k=0,V=O.length,j,K;k<V;)j=O.charCodeAt(k++),j>=55296&&j<=56319&&k<V?(K=O.charCodeAt(k++),(K&64512)==56320?B.push(((j&1023)<<10)+(K&1023)+65536):(B.push(j),k--)):B.push(j);return B}function P(O){return M(O,function(B){var k="";return B>65535&&(B-=65536,k+=R(B>>>10&1023|55296),B=56320|B&1023),k+=R(B),k}).join("")}function T(O){return O-48<10?O-22:O-65<26?O-65:O-97<26?O-97:l}function E(O,B){return O+22+75*(O<26)-((B!=0)<<5)}function A(O,B,k){var V=0;for(O=k?S(O/d):O>>1,O+=S(O/B);O>b*c>>1;V+=l)O=S(O/b);return S(V+(b+1)*O/(O+u))}function L(O){var B=[],k=O.length,V,j=0,K=p,X=f,ft,H,mt,Q,ut,gt,Et,Dt,Yt;for(ft=O.lastIndexOf(m),ft<0&&(ft=0),H=0;H<ft;++H)O.charCodeAt(H)>=128&&I("not-basic"),B.push(O.charCodeAt(H));for(mt=ft>0?ft+1:0;mt<k;){for(Q=j,ut=1,gt=l;mt>=k&&I("invalid-input"),Et=T(O.charCodeAt(mt++)),(Et>=l||Et>S((a-j)/ut))&&I("overflow"),j+=Et*ut,Dt=gt<=X?h:gt>=X+c?c:gt-X,!(Et<Dt);gt+=l)Yt=l-Dt,ut>S(a/Yt)&&I("overflow"),ut*=Yt;V=B.length+1,X=A(j-Q,V,Q==0),S(j/V)>a-K&&I("overflow"),K+=S(j/V),j%=V,B.splice(j++,0,K)}return P(B)}function D(O){var B,k,V,j,K,X,ft,H,mt,Q,ut,gt=[],Et,Dt,Yt,Vt;for(O=U(O),Et=O.length,B=p,k=0,K=f,X=0;X<Et;++X)ut=O[X],ut<128&&gt.push(R(ut));for(V=j=gt.length,j&&gt.push(m);V<Et;){for(ft=a,X=0;X<Et;++X)ut=O[X],ut>=B&&ut<ft&&(ft=ut);for(Dt=V+1,ft-B>S((a-k)/Dt)&&I("overflow"),k+=(ft-B)*Dt,B=ft,X=0;X<Et;++X)if(ut=O[X],ut<B&&++k>a&&I("overflow"),ut==B){for(H=k,mt=l;Q=mt<=K?h:mt>=K+c?c:mt-K,!(H<Q);mt+=l)Vt=H-Q,Yt=l-Q,gt.push(R(E(Q+Vt%Yt,0))),H=S(Vt/Yt);gt.push(R(E(H,0))),K=A(k,Dt,V==j),k=0,++V}++k,++B}return gt.join("")}function N(O){return F(O,function(B){return y.test(B)?L(B.slice(4).toLowerCase()):B})}function $(O){return F(O,function(B){return _.test(B)?"xn--"+D(B):B})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:L,encode:D,toASCII:$,toUnicode:N},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})(In)}(Ms,Ms.exports);var y1=Ms.exports,Vi=TypeError;const _1=Q_(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var ja=typeof Map=="function"&&Map.prototype,Wa=Object.getOwnPropertyDescriptor&&ja?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ds=ja&&Wa&&typeof Wa.get=="function"?Wa.get:null,md=ja&&Map.prototype.forEach,za=typeof Set=="function"&&Set.prototype,Ya=Object.getOwnPropertyDescriptor&&za?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Bs=za&&Ya&&typeof Ya.get=="function"?Ya.get:null,gd=za&&Set.prototype.forEach,v1=typeof WeakMap=="function"&&WeakMap.prototype,Ln=v1?WeakMap.prototype.has:null,b1=typeof WeakSet=="function"&&WeakSet.prototype,Nn=b1?WeakSet.prototype.has:null,x1=typeof WeakRef=="function"&&WeakRef.prototype,yd=x1?WeakRef.prototype.deref:null,w1=Boolean.prototype.valueOf,E1=Object.prototype.toString,T1=Function.prototype.toString,A1=String.prototype.match,qa=String.prototype.slice,kr=String.prototype.replace,S1=String.prototype.toUpperCase,_d=String.prototype.toLowerCase,vd=RegExp.prototype.test,bd=Array.prototype.concat,or=Array.prototype.join,C1=Array.prototype.slice,xd=Math.floor,Ka=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Za=Object.getOwnPropertySymbols,Qa=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,ji=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Fn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===ji||!0)?Symbol.toStringTag:null,wd=Object.prototype.propertyIsEnumerable,Ed=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Td(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||vd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-xd(-r):xd(r);if(i!==r){var n=String(i),s=qa.call(t,n.length+1);return kr.call(n,e,"$&_")+"."+kr.call(kr.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return kr.call(t,e,"$&_")}var Ja=_1,Ad=Ja.custom,Sd=Rd(Ad)?Ad:null,Cd={__proto__:null,double:'"',single:"'"},I1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Os=function r(t,e,i,n){var s=e||{};if(vr(s,"quoteStyle")&&!vr(Cd,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(vr(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=vr(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(vr(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(vr(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 Dd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Td(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Td(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 tl(t)?"[Array]":"[Object]";var u=W1(s,i);if(typeof n>"u")n=[];else if(Md(n,t)>=0)return"[Circular]";function d(T,E,A){if(E&&(n=C1.call(n),n.push(E)),A){var L={depth:s.depth};return vr(s,"quoteStyle")&&(L.quoteStyle=s.quoteStyle),r(T,L,i+1,n)}return r(T,s,i+1,n)}if(typeof t=="function"&&!Pd(t)){var f=F1(t),p=Ls(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+or.call(p,", ")+" }":"")}if(Rd(t)){var m=ji?kr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qa.call(t);return typeof t=="object"&&!ji?kn(m):m}if(X1(t)){for(var y="<"+_d.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Id(P1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+_d.call(String(t.nodeName))+">",y}if(tl(t)){if(t.length===0)return"[]";var g=Ls(t,d);return u&&!j1(g)?"["+rl(g,u)+"]":"[ "+or.call(g,", ")+" ]"}if(M1(t)){var b=Ls(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!wd.call(t,"cause")?"{ ["+String(t)+"] "+or.call(bd.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+or.call(b,", ")+" }"}if(typeof t=="object"&&o){if(Sd&&typeof t[Sd]=="function"&&Ja)return Ja(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(k1(t)){var S=[];return md&&md.call(t,function(T,E){S.push(d(E,t,!0)+" => "+d(T,t))}),Bd("Map",Ds.call(t),S,u)}if($1(t)){var R=[];return gd&&gd.call(t,function(T){R.push(d(T,t))}),Bd("Set",Bs.call(t),R,u)}if(U1(t))return el("WeakMap");if(H1(t))return el("WeakSet");if(G1(t))return el("WeakRef");if(B1(t))return kn(d(Number(t)));if(L1(t))return kn(d(Ka.call(t)));if(O1(t))return kn(w1.call(t));if(D1(t))return kn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof In<"u"&&t===In)return"{ [object globalThis] }";if(!R1(t)&&!Pd(t)){var C=Ls(t,d),I=Ed?Ed(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&Fn&&Object(t)===t&&Fn in t?qa.call(Ur(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+or.call(bd.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+rl(C,u)+"}":P+"{ "+or.call(C,", ")+" }"}return String(t)};function Id(r,t,e){var i=e.quoteStyle||t,n=Cd[i];return n+r+n}function P1(r){return kr.call(String(r),/"/g,"&quot;")}function ai(r){return!Fn||!(typeof r=="object"&&(Fn in r||typeof r[Fn]<"u"))}function tl(r){return Ur(r)==="[object Array]"&&ai(r)}function R1(r){return Ur(r)==="[object Date]"&&ai(r)}function Pd(r){return Ur(r)==="[object RegExp]"&&ai(r)}function M1(r){return Ur(r)==="[object Error]"&&ai(r)}function D1(r){return Ur(r)==="[object String]"&&ai(r)}function B1(r){return Ur(r)==="[object Number]"&&ai(r)}function O1(r){return Ur(r)==="[object Boolean]"&&ai(r)}function Rd(r){if(ji)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!Qa)return!1;try{return Qa.call(r),!0}catch{}return!1}function L1(r){if(!r||typeof r!="object"||!Ka)return!1;try{return Ka.call(r),!0}catch{}return!1}var N1=Object.prototype.hasOwnProperty||function(r){return r in this};function vr(r,t){return N1.call(r,t)}function Ur(r){return E1.call(r)}function F1(r){if(r.name)return r.name;var t=A1.call(T1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Md(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 k1(r){if(!Ds||!r||typeof r!="object")return!1;try{Ds.call(r);try{Bs.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function U1(r){if(!Ln||!r||typeof r!="object")return!1;try{Ln.call(r,Ln);try{Nn.call(r,Nn)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function G1(r){if(!yd||!r||typeof r!="object")return!1;try{return yd.call(r),!0}catch{}return!1}function $1(r){if(!Bs||!r||typeof r!="object")return!1;try{Bs.call(r);try{Ds.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function H1(r){if(!Nn||!r||typeof r!="object")return!1;try{Nn.call(r,Nn);try{Ln.call(r,Ln)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function X1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Dd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Dd(qa.call(r,0,t.maxStringLength),t)+i}var n=I1[t.quoteStyle||"single"];n.lastIndex=0;var s=kr.call(kr.call(r,n,"\\$1"),/[\x00-\x1f]/g,V1);return Id(s,"single",t)}function V1(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":"")+S1.call(t.toString(16))}function kn(r){return"Object("+r+")"}function el(r){return r+" { ? }"}function Bd(r,t,e,i){var n=i?rl(e,i):or.call(e,", ");return r+" ("+t+") {"+n+"}"}function j1(r){for(var t=0;t<r.length;t++)if(Md(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 cC=Object.defineProperty;var uC=(qt,se,Zr)=>se in qt?cC(qt,se,{enumerable:!0,configurable:!0,writable:!0,value:Zr}):qt[se]=Zr;var Fh=(qt,se,Zr)=>uC(qt,typeof se!="symbol"?se+"":se,Zr);var Zr=Object.prototype.hasOwnProperty;function Qr(r,t){var e,i;if(r===t)return!0;if(r&&t&&(e=r.constructor)===t.constructor){if(e===Date)return r.getTime()===t.getTime();if(e===RegExp)return r.toString()===t.toString();if(e===Array){if((i=r.length)===t.length)for(;i--&&Qr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Zr.call(r,e)&&++i&&!Zr.call(t,e)||!(e in t)||!Qr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}var $o=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))($o||{});const fe=[];for(let r=0;r<256;++r)fe.push((r+256).toString(16).slice(1));function ng(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()}let Ho;const sg=new Uint8Array(16);function og(){if(!Ho){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ho=crypto.getRandomValues.bind(crypto)}return Ho(sg)}const ag=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),jh={randomUUID:ag};function lg(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??og();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,ng(n)}function hg(r,t,e){return jh.randomUUID&&!r?jh.randomUUID():lg(r)}const Xo=r=>{const t=e=>{const i={...e};return e.created&&typeof e.created=="string"&&(i.created=new Date(e.created)),e.updated&&typeof e.updated=="string"&&(i.updated=new Date(e.updated)),i};return{...r,bodies:(r.bodies||[]).map(t),target:t(r.target)}},cg=(r,t,e,i)=>({id:hg(),annotation:typeof r=="string"?r:r.id,created:e||new Date,creator:i,...t}),ug=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},dg=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},fg=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Qr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),pg=(r,t)=>!Qr(r.target,t.target),mg=(r,t)=>{const e=ug(r,t),i=dg(r,t),n=fg(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:pg(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Rr=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Rr||{});const gg=(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(m=>m.oldValue.id===f.id).newValue;return mg(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}};let yg=()=>({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 _g=250,vg=(r,t)=>{const e=yg(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>_g)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=gg(i[_],m)}o=y}s=!1};r.observe(a,{origin:Rr.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:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),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,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},bg=(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 g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Qr(b,g))&&p("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:S})=>S===g.id)||g)};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 g=o.getAnnotation(v.id);g&&!Qr(g,v)&&p("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Qr(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}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(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>p("createAnnotation",b)),(g||[]).forEach(b=>p("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),p("updateAnnotation",S,R)})},{origin:Rr.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(R=>R.id===b.id)||b))}},{origin:Rr.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},xg=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:[]}),wg=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Rr.REMOTE):console.error(g)}else i.addAnnotation(Xo(_),Rr.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(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(f(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||xg(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Rr.REMOTE)}else i.bulkAddAnnotations(_.map(Xo),v,Rr.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(Xo(_)),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:m,undo:t.undo,updateAnnotation:y}},Eg="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Tg=r=>crypto.getRandomValues(new Uint8Array(r)),Ag=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},Sg=(r,t=21)=>Ag(r,t|0,Tg),Cg=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=Eg[e[r]&63];return t};const Ig=()=>({isGuest:!0,id:Sg("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Pg=["#ff7c00","#1ac938","#e8000b","#8b2be2","#9f4800","#f14cc1","#ffc400","#00d7ff","#023eff"],Rg=()=>{const r=[...Pg];return{assignRandomColor:()=>{const t=Math.floor(Math.random()*r.length),e=r[t];return r.splice(t,1),e},releaseColor:t=>r.push(t)}};Cg();var Mg=Object.defineProperty,Dg=(r,t,e)=>t in r?Mg(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Wh=(r,t,e)=>Dg(r,typeof t!="symbol"?t+"":t,e);function Rt(){}function Vo(r,t){for(const e in t)r[e]=t[e];return r}function zh(r){return r()}function Yh(){return Object.create(null)}function Me(r){r.forEach(zh)}function Gt(r){return typeof r=="function"}function Kt(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function Bg(r){return Object.keys(r).length===0}function qh(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 jo(r,t,e){r.$$.on_destroy.push(qh(t,e))}function Og(r,t,e,i){if(r){const n=Kh(r,t,e,i);return r[0](n)}}function Kh(r,t,e,i){return r[1]&&i?Vo(e.ctx.slice(),r[1](i(t))):e.ctx}function Lg(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 Ng(r,t,e,i,n,s){if(n){const o=Kh(t,e,i,s);r.p(o,n)}}function Fg(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 Zh(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function Ai(r){return r??""}function xt(r,t){r.appendChild(t)}function nt(r,t,e){r.insertBefore(t,e||null)}function rt(r){r.parentNode&&r.parentNode.removeChild(r)}function Jr(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function z(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function Qh(r){return document.createTextNode(r)}function we(){return Qh(" ")}function De(){return Qh("")}function St(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function x(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function kg(r){return Array.from(r.childNodes)}function Je(r,t,e){r.classList.toggle(t,!!e)}function Ug(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let _n;function vn(r){_n=r}function Jh(){if(!_n)throw new Error("Function called outside component initialization");return _n}function ti(r){Jh().$$.on_mount.push(r)}function Mr(){const r=Jh();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=Ug(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 Si=[],as=[];let Ci=[];const tc=[],ec=Promise.resolve();let Wo=!1;function rc(){Wo||(Wo=!0,ec.then(nc))}function ic(){return rc(),ec}function zo(r){Ci.push(r)}const Yo=new Set;let Ii=0;function nc(){if(Ii!==0)return;const r=_n;do{try{for(;Ii<Si.length;){const t=Si[Ii];Ii++,vn(t),Gg(t.$$)}}catch(t){throw Si.length=0,Ii=0,t}for(vn(null),Si.length=0,Ii=0;as.length;)as.pop()();for(let t=0;t<Ci.length;t+=1){const e=Ci[t];Yo.has(e)||(Yo.add(e),e())}Ci.length=0}while(Si.length);for(;tc.length;)tc.pop()();Wo=!1,Yo.clear(),vn(r)}function Gg(r){if(r.fragment!==null){r.update(),Me(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(zo)}}function $g(r){const t=[],e=[];Ci.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ci=t}const ls=new Set;let ei;function Ee(){ei={r:0,c:[],p:ei}}function Te(){ei.r||Me(ei.c),ei=ei.p}function lt(r,t){r&&r.i&&(ls.delete(r),r.i(t))}function yt(r,t,e,i){if(r&&r.o){if(ls.has(r))return;ls.add(r),ei.c.push(()=>{ls.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function Ie(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function re(r){r&&r.c()}function Jt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),zo(()=>{const s=r.$$.on_mount.map(zh).filter(Gt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Me(s),r.$$.on_mount=[]}),n.forEach(zo)}function te(r,t){const e=r.$$;e.fragment!==null&&($g(e.after_update),Me(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function Hg(r,t){r.$$.dirty[0]===-1&&(Si.push(r),rc(),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=_n;vn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Rt,not_equal:n,bound:Yh(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:Yh(),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&&Hg(r,u)),d}):[],h.update(),c=!0,Me(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=kg(t.target);h.fragment&&h.fragment.l(u),u.forEach(rt)}else h.fragment&&h.fragment.c();t.intro&&lt(r.$$.fragment),Jt(r,t.target,t.anchor),nc()}vn(l)}class me{constructor(){Wh(this,"$$"),Wh(this,"$$set")}$destroy(){te(this,1),this.$destroy=Rt}$on(t,e){if(!Gt(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&&!Bg(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Xg="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Xg);var _t=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(_t||{}),Vg={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 m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}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})()})(Vg);const qo={},Pi=(r,t)=>qo[r]=t,Ko=r=>qo[r.type].area(r),jg=(r,t,e,i)=>qo[r.type].intersects(r,t,e,i),Ae=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}},hs=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)},cs=(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},Wg=(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},us=(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))},zg={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}};Pi(_t.ELLIPSE,zg);const Yg={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=us([n,s],[o,a]);return l/h<=i}};Pi(_t.LINE,Yg);const qg={area:r=>{const{polygons:t}=r.geometry;return t.reduce((e,i)=>{const[n,...s]=i.rings,o=hs(n.points),a=s.reduce((l,h)=>l+hs(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(cs(s.points,t,e)){let a=!1;for(const l of o)if(cs(l.points,t,e)){a=!0;break}if(!a)return!0}}return!1}},Zo=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return Ae(t)},He=r=>r.rings.map(t=>Wg(t.points)).join(" "),Kg=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]);Pi(_t.MULTIPOLYGON,qg);const Zg={area:r=>{const t=r.geometry.points;return hs(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return cs(i,t,e)}};Pi(_t.POLYGON,Zg);const Qg={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Qo(t.points,t.closed);return hs(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Qo(n.points,n.closed);return cs(s,t,e)}else return Jg(n,[t,e],i)}},Qo=(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=sc(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},sc=(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},Jg=(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=sc(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(oc(t,o[a],o[a+1])<=e)return!0}else if(oc(t,n.point,s.point)<=e)return!0}return!1},oc=(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},Jo=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(" ")};Pi(_t.POLYLINE,Qg);const ty={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};Pi(_t.RECTANGLE,ty);const Le=r=>ds(r.target),ds=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},ey=r=>(r==null?void 0:r.type)==="FragmentSelector"?!0:typeof r=="string"?r.indexOf("#")<0?!1:/^#xywh(?:=(?:pixel:|percent:)?)\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?,\s*\d+(\.\d*)?$/i.test(r):!1,ry=(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,m]=[l,h,c,u].map(parseFloat);return{type:_t.RECTANGLE,geometry:{x:d,y:f,w:p,h:m,bounds:{minX:d,minY:t?f-m:f,maxX:d+p,maxY:t?f:f+m}}}},iy=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}`}},ac="http://www.w3.org/2000/svg",lc=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},ny=r=>{const t=new XMLSerializer().serializeToString(r.documentElement).replace("<svg>",`<svg xmlns="${ac}">`);return new DOMParser().parseFromString(t,"image/svg+xml").documentElement},fs=r=>{const t=new DOMParser().parseFromString(r,"image/svg+xml"),e=t.lookupPrefix(ac),i=t.lookupNamespaceURI(null);return e||i?lc(t).firstChild:lc(ny(t)).firstChild},sy=r=>{const t=hc(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=Ae(e[0].points);return{rings:e,bounds:s}}},oy=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},ay=r=>{const t=hc(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=>oy(o)?{...o,locked:!0}:o);const s=Ae(Qo(e,n));return{points:e,closed:n,bounds:s}},hc=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},ly=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:Ae(n)}}},hy=r=>{const t=fs(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}}},cy=r=>{const t=fs(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}}},uy=r=>{const t=fs(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=ay(i);if(!n)throw new Error("Could not parse SVG path");return{type:_t.POLYLINE,geometry:n}},dy=r=>{const t=fs(r),e=(t.nodeName==="path"?[t]:Array.from(t.querySelectorAll("path"))).map(s=>s.getAttribute("d")||"").map(s=>sy(s)).filter(Boolean),i=e.reduce((s,o)=>[...s,...o.rings[0].points],[]),n=Ae(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}}},fy=r=>{const t=typeof r=="string"?r:r.value;if(t.includes("<polygon points="))return ly(t);if(t.includes("<path ")&&(t.includes(" C ")||!t.includes("Z")))return uy(t);if(t.includes("<path "))return dy(t);if(t.includes("<ellipse "))return hy(t);if(t.includes("<line "))return cy(t);throw"Unsupported SVG shape: "+t},py=r=>`<g>${r.polygons.map(t=>`<path fill-rule="evenodd" d="${He(t)}" />`).join("")}</g>`,my=r=>{let t;switch(r.type){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>${py(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="${Jo(r.geometry)}" /></svg>`}if(t)return{type:"SvgSelector",value:t};throw`Unsupported shape type: ${r.type}`},ge=[];for(let r=0;r<256;++r)ge.push((r+256).toString(16).slice(1));function gy(r,t=0){return(ge[r[t+0]]+ge[r[t+1]]+ge[r[t+2]]+ge[r[t+3]]+"-"+ge[r[t+4]]+ge[r[t+5]]+"-"+ge[r[t+6]]+ge[r[t+7]]+"-"+ge[r[t+8]]+ge[r[t+9]]+"-"+ge[r[t+10]]+ge[r[t+11]]+ge[r[t+12]]+ge[r[t+13]]+ge[r[t+14]]+ge[r[t+15]]).toLowerCase()}let ta;const yy=new Uint8Array(16);function _y(){if(!ta){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ta=crypto.getRandomValues.bind(crypto)}return ta(yy)}const vy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),cc={randomUUID:vy};function by(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??_y();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,gy(n)}function uc(r,t,e){return cc.randomUUID&&!r?cc.randomUUID():by(r)}var dc=Object.prototype.hasOwnProperty;function Dr(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--&&Dr(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(dc.call(r,e)&&++i&&!dc.call(t,e)||!(e in t)||!Dr(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}let Xe=[],Br=0;const ps=4;let ea=r=>{let t=[],e={get(){return e.lc||e.listen(()=>{})(),e.value},lc:0,listen(i){return e.lc=t.push(i),()=>{for(let s=Br+ps;s<Xe.length;)Xe[s]===i?Xe.splice(s,ps):s+=ps;let n=t.indexOf(i);~n&&(t.splice(n,1),--e.lc||e.off())}},notify(i,n){let s=!Xe.length;for(let o of t)Xe.push(o,e.value,i,n);if(s){for(Br=0;Br<Xe.length;Br+=ps)Xe[Br](Xe[Br+1],Xe[Br+2],Xe[Br+3]);Xe.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};const xy=r=>{const t=ea(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 fc=(r=>(r.EDIT="EDIT",r.SELECT="SELECT",r.NONE="NONE",r))(fc||{});const ra={selected:[]},wy=(r,t,e)=>{const i=ea(ra);let n=t;const s=()=>{Dr(i.get(),ra)||i.set(ra)},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(m=>m.id===p)},l=(f,p)=>{let m;if(Array.isArray(f)){if(m=f.map(_=>r.getAnnotation(_)).filter(Boolean),m.length<f.length){console.warn("Invalid selection: "+f.filter(_=>!m.some(v=>v.id===_)));return}}else{const _=r.getAnnotation(f);if(!_){console.warn("Invalid selection: "+f);return}m=[_]}const y=m.reduce((_,v)=>{const g=d(v);return g==="EDIT"?[..._,{id:v.id,editable:!0}]:g==="SELECT"?[..._,{id:v.id}]:_},[]);i.set({selected:y,event:p})},h=(f,p)=>{const m=Array.isArray(f)?f:[f],y=m.map(_=>r.getAnnotation(_)).filter(_=>!!_);i.set({selected:y.map(_=>{const v=p===void 0?d(_)==="EDIT":p;return{id:_.id,editable:v}})}),y.length!==m.length&&console.warn("Invalid selection",f)},c=f=>{if(o())return!1;const{selected:p}=i.get();p.some(({id:m})=>f.includes(m))&&i.set({selected:p.filter(({id:m})=>!f.includes(m))})},u=f=>{n=f,h(i.get().selected.map(({id:p})=>p))},d=f=>Ey(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}},Ey=(r,t,e)=>{const i=e?e.serialize(r):r;return typeof t=="function"?t(i):t||"EDIT"},ye=[];for(let r=0;r<256;++r)ye.push((r+256).toString(16).slice(1));function Ty(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()}let ia;const Ay=new Uint8Array(16);function Sy(){if(!ia){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");ia=crypto.getRandomValues.bind(crypto)}return ia(Ay)}const Cy=typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto),pc={randomUUID:Cy};function Iy(r,t,e){var i;r=r||{};const n=r.random??((i=r.rng)==null?void 0:i.call(r))??Sy();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,Ty(n)}function Py(r,t,e){return pc.randomUUID&&!r?pc.randomUUID():Iy(r)}const na=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)}},Ry=(r,t)=>{const e=new Set(r.bodies.map(i=>i.id));return t.bodies.filter(i=>!e.has(i.id))},My=(r,t)=>{const e=new Set(t.bodies.map(i=>i.id));return r.bodies.filter(i=>!e.has(i.id))},Dy=(r,t)=>t.bodies.map(e=>{const i=r.bodies.find(n=>n.id===e.id);return{newBody:e,oldBody:i&&!Dr(i,e)?i:void 0}}).filter(({oldBody:e})=>e).map(({oldBody:e,newBody:i})=>({oldBody:e,newBody:i})),By=(r,t)=>!Dr(r.target,t.target),mc=(r,t)=>{const e=Ry(r,t),i=My(r,t),n=Dy(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:By(r,t)?{oldTarget:r.target,newTarget:t.target}:void 0}};var Nt=(r=>(r.LOCAL="LOCAL",r.REMOTE="REMOTE",r.SILENT="SILENT",r))(Nt||{});const Oy=(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},Ly=(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(m=>m.oldValue.id===f.id).newValue;return mc(d,p)}else return u}),...(t.updated||[]).filter(({oldValue:u})=>!a.has(u.id))];return{created:l,deleted:h,updated:c}},ms=r=>{const t=r.id===void 0?Py():r.id;return{...r,id:t,bodies:r.bodies===void 0?[]:r.bodies.map(e=>({...e,annotation:t})),target:{...r.target,annotation:t}}},Ny=r=>r.id!==void 0,Fy=()=>{const r=new Map,t=new Map,e=[],i=(P,E={})=>{e.push({onChange:P,options:E})},n=P=>{const E=e.findIndex(T=>T.onChange==P);E>-1&&e.splice(E,1)},s=(P,E)=>{const T={origin:P,changes:{created:E.created||[],updated:E.updated||[],deleted:E.deleted||[]},state:[...r.values()]};e.forEach(A=>{Oy(A,T)&&A.onChange(T)})},o=(P,E=Nt.LOCAL)=>{if(P.id&&r.get(P.id))throw Error(`Cannot add annotation ${P.id} - exists already`);{const T=ms(P);r.set(T.id,T),T.bodies.forEach(A=>t.set(A.id,T.id)),s(E,{created:[T]})}},a=(P,E)=>{const T=ms(typeof P=="string"?E:P),A=typeof P=="string"?P:P.id,O=A&&r.get(A);if(O){const D=mc(O,T);return A===T.id?r.set(A,T):(r.delete(A),r.set(T.id,T)),O.bodies.forEach(L=>t.delete(L.id)),T.bodies.forEach(L=>t.set(L.id,T.id)),D}else console.warn(`Cannot update annotation ${A} - does not exist`)},l=(P,E=Nt.LOCAL,T=Nt.LOCAL)=>{const A=Ny(E)?T:E,O=a(P,E);O&&s(A,{updated:[O]})},h=(P,E=Nt.LOCAL)=>{r.get(P.id)?l(P,E):o(P,E)},c=(P,E=Nt.LOCAL)=>{const T=P.reduce((A,O)=>{const D=a(O);return D?[...A,D]:A},[]);T.length>0&&s(E,{updated:T})},u=(P,E=Nt.LOCAL)=>{const T=P.map(ms),{toAdd:A,toUpdate:O}=T.reduce((L,$)=>r.get($.id)?{...L,toUpdate:[...L.toUpdate,$]}:{...L,toAdd:[...L.toAdd,$]},{toAdd:[],toUpdate:[]}),D=O.map(L=>a(L,E)).filter(Boolean);A.forEach(L=>{r.set(L.id,L),L.bodies.forEach($=>t.set($.id,L.id))}),s(E,{created:A,updated:D})},d=(P,E=Nt.LOCAL)=>{const T=r.get(P.annotation);if(T){const A={...T,bodies:[...T.bodies,P]};r.set(T.id,A),t.set(P.id,A.id),s(E,{updated:[{oldValue:T,newValue:A,bodiesCreated:[P]}]})}else console.warn(`Attempt to add body to missing annotation: ${P.annotation}`)},f=()=>[...r.values()],p=(P=Nt.LOCAL)=>{const E=[...r.values()];r.clear(),t.clear(),s(P,{deleted:E})},m=(P,E=!0,T=Nt.LOCAL)=>{const A=P.map(ms);if(E){const O=[...r.values()];r.clear(),t.clear(),A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(L=>t.set(L.id,D.id))}),s(T,{created:A,deleted:O})}else{const O=P.reduce((D,L)=>{const $=L.id&&r.get(L.id);return $?[...D,$]:D},[]);if(O.length>0)throw Error(`Bulk insert would overwrite the following annotations: ${O.map(D=>D.id).join(", ")}`);A.forEach(D=>{r.set(D.id,D),D.bodies.forEach(L=>t.set(L.id,D.id))}),s(T,{created:A})}},y=P=>{const E=typeof P=="string"?P:P.id,T=r.get(E);if(T)return r.delete(E),T.bodies.forEach(A=>t.delete(A.id)),T;console.warn(`Attempt to delete missing annotation: ${E}`)},_=(P,E=Nt.LOCAL)=>{const T=y(P);T&&s(E,{deleted:[T]})},v=(P,E=Nt.LOCAL)=>{const T=P.reduce((A,O)=>{const D=y(O);return D?[...A,D]:A},[]);T.length>0&&s(E,{deleted:T})},g=P=>{const E=r.get(P.annotation);if(E){const T=E.bodies.find(A=>A.id===P.id);if(T){t.delete(T.id);const A={...E,bodies:E.bodies.filter(O=>O.id!==P.id)};return r.set(E.id,A),{oldValue:E,newValue:A,bodiesDeleted:[T]}}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}`)},b=(P,E=Nt.LOCAL)=>{const T=g(P);T&&s(E,{updated:[T]})},S=(P,E=Nt.LOCAL)=>{const T=P.map(A=>g(A)).filter(Boolean);T.length>0&&s(E,{updated:T})},R=P=>{const E=r.get(P);return E?{...E}:void 0},C=P=>{const E=t.get(P);if(E){const T=R(E).bodies.find(A=>A.id===P);if(T)return T;console.error(`Store integrity error: body ${P} in index, but not in annotation`)}else console.warn(`Attempt to retrieve missing body: ${P}`)},I=(P,E)=>{if(P.annotation!==E.annotation)throw"Annotation integrity violation: annotation ID must be the same when updating bodies";const T=r.get(P.annotation);if(T){const A=T.bodies.find(D=>D.id===P.id),O={...T,bodies:T.bodies.map(D=>D.id===A.id?E:D)};return r.set(T.id,O),A.id!==E.id&&(t.delete(A.id),t.set(E.id,O.id)),{oldValue:T,newValue:O,bodiesUpdated:[{oldBody:A,newBody:E}]}}else console.warn(`Attempt to add body to missing annotation ${P.annotation}`)},M=(P,E,T=Nt.LOCAL)=>{const A=I(P,E);A&&s(T,{updated:[A]})},F=(P,E=Nt.LOCAL)=>{const T=P.map(A=>I({id:A.id,annotation:A.annotation},A)).filter(Boolean);s(E,{updated:T})},U=P=>{const E=r.get(P.annotation);if(E){const T={...E,target:{...E.target,...P}};return r.set(E.id,T),{oldValue:E,newValue:T,targetUpdated:{oldTarget:E.target,newTarget:P}}}else console.warn(`Attempt to update target on missing annotation: ${P.annotation}`)};return{addAnnotation:o,addBody:d,all:f,bulkAddAnnotations:m,bulkDeleteAnnotations:v,bulkDeleteBodies:S,bulkUpdateAnnotations:c,bulkUpdateBodies:F,bulkUpdateTargets:(P,E=Nt.LOCAL)=>{const T=P.map(A=>U(A)).filter(Boolean);T.length>0&&s(E,{updated:T})},bulkUpsertAnnotations:u,clear:p,deleteAnnotation:_,deleteBody:b,getAnnotation:R,getBody:C,observe:i,unobserve:n,updateAnnotation:l,updateBody:M,updateTarget:(P,E=Nt.LOCAL)=>{const T=U(P);T&&s(E,{updated:[T]})},upsertAnnotation:h}};let ky=()=>({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 Uy=250,Gy=(r,t)=>{const e=ky(),i=(t==null?void 0:t.changes)||[];let n=t?t.pointer:-1,s=!1,o=0;const a=p=>{if(!s){const{changes:m}=p,y=performance.now();if(y-o>Uy)i.splice(n+1),i.push(m),n=i.length-1;else{const _=i.length-1;i[_]=Ly(i[_],m)}o=y}s=!1};r.observe(a,{origin:Nt.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:m})=>m)),u=p=>p&&p.length>0&&r.bulkUpdateAnnotations(p.map(({newValue:m})=>m)),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,m)=>e.on(p,m),redo:()=>{if(i.length-1>n){s=!0;const{created:p,updated:m,deleted:y}=i[n+1];h(p),u(m),f(y),e.emit("redo",i[n+1]),n+=1}},undo:()=>{if(n>-1){s=!0;const{created:p,updated:m,deleted:y}=i[n];l(p),c(m),d(y),e.emit("undo",i[n]),n-=1}}}},$y=()=>{const r=ea([]);return{subscribe:r.subscribe.bind(r),set:r.set.bind(r)}},Hy=(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 g=l.get(_);if(g){const b=g.indexOf(v);b!==-1&&g.splice(b,1)}},p=(_,v,g)=>{l.has(_)&&setTimeout(()=>{l.get(_).forEach(b=>{if(e){const S=Array.isArray(v)?v.map(C=>e.serialize(C)):e.serialize(v),R=g?g instanceof PointerEvent?g:e.serialize(g):void 0;b(S,R)}else b(v,g)})},1)},m=()=>{const{selected:_}=s,v=(_||[]).map(({id:g})=>o.getAnnotation(g));v.forEach(g=>{const b=h.find(S=>S.id===g.id);(!b||!Dr(b,g))&&p("updateAnnotation",g,b)}),h=h.map(g=>v.find(({id:b})=>b===g.id)||g)};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 g=o.getAnnotation(v.id);g&&!Dr(g,v)&&p("updateAnnotation",g,v)}),h=[];else{const v=new Set(h.map(b=>b.id)),g=new Set(_.map(({id:b})=>b));h.filter(b=>!g.has(b.id)).forEach(b=>{const S=o.getAnnotation(b.id);S&&!Dr(S,b)&&p("updateAnnotation",S,b)}),h=[...h.filter(b=>g.has(b.id)),..._.filter(({id:b})=>!v.has(b)).map(({id:b})=>o.getAnnotation(b))]}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(m,1e3));const{created:v,deleted:g}=_.changes;(v||[]).forEach(b=>p("createAnnotation",b)),(g||[]).forEach(b=>p("deleteAnnotation",b)),(_.changes.updated||[]).filter(b=>[...b.bodiesCreated||[],...b.bodiesDeleted||[],...b.bodiesUpdated||[]].length>0).forEach(({oldValue:b,newValue:S})=>{const R=h.find(C=>C.id===b.id)||b;h=h.map(C=>C.id===b.id?S:C),p("updateAnnotation",S,R)})},{origin:Nt.LOCAL}),o.observe(_=>{if(h){const v=new Set(h.map(b=>b.id)),g=(_.changes.updated||[]).filter(({newValue:b})=>v.has(b.id)).map(({newValue:b})=>b);g.length>0&&(h=h.map(b=>g.find(S=>S.id===b.id)||b))}},{origin:Nt.REMOTE});const y=_=>v=>{const{updated:g}=v;_?(g||[]).forEach(b=>p("updateAnnotation",b.oldValue,b.newValue)):(g||[]).forEach(b=>p("updateAnnotation",b.newValue,b.oldValue))};return t.on("undo",y(!0)),t.on("redo",y(!1)),{on:d,off:f,emit:p}},Xy=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:[]}),Vy=(r,t,e)=>{const{store:i,selection:n}=r,s=_=>{if(e){const{parsed:v,error:g}=e.parse(_);v?i.addAnnotation(v,Nt.REMOTE):console.error(g)}else i.addAnnotation(na(_),Nt.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(g=>g.id))||[]).map(g=>i.getAnnotation(g)).filter(Boolean);return e?v.map(e.serialize):v},u=(_,v=!0)=>fetch(_).then(g=>g.json()).then(g=>(f(g,v),g)),d=_=>{if(typeof _=="string"){const v=i.getAnnotation(_);if(i.deleteAnnotation(_),v)return e?e.serialize(v):v}else{const v=e?e.parse(_).parsed:_;if(v)return i.deleteAnnotation(v),_}},f=(_,v=!0)=>{if(e){const g=e.parseAll||Xy(e),{parsed:b,failed:S}=g(_);S.length>0&&console.warn(`Discarded ${S.length} invalid annotations`,S),i.bulkAddAnnotations(b,v,Nt.REMOTE)}else i.bulkAddAnnotations(_.map(na),v,Nt.REMOTE)},p=(_,v)=>{_?n.setSelected(_,v):n.clear()},m=_=>{n.setUserSelectAction(_)},y=_=>{if(e){const v=e.parse(_).parsed,g=e.serialize(i.getAnnotation(v.id));return i.updateAnnotation(v),g}else{const v=i.getAnnotation(_.id);return i.updateAnnotation(na(_)),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:m,undo:t.undo,updateAnnotation:y}},jy=(r,t,e)=>typeof t=="function"?t(r,e):t,Wy=(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||{}}},zy="useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";let Yy=r=>crypto.getRandomValues(new Uint8Array(r)),qy=(r,t,e)=>{let i=(2<<Math.log2(r.length-1))-1,n=-~(1.6*i*t/r.length);return(s=t)=>{let o="";for(;;){let a=e(n),l=n|0;for(;l--;)if(o+=r[a[l]&i]||"",o.length>=s)return o}}},Ky=(r,t=21)=>qy(r,t|0,Yy),Zy=(r=21)=>{let t="",e=crypto.getRandomValues(new Uint8Array(r|=0));for(;r--;)t+=zy[e[r]&63];return t};const Qy=()=>({isGuest:!0,id:Ky("1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_",20)()}),Jy=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}`},gc=r=>r?typeof r=="object"?{...r}:r:void 0,t0=(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-${Jy(e)}`,annotation:t,type:n,purpose:s,value:o,creator:gc(h),created:a?new Date(a):void 0,updated:l?new Date(l):void 0,...c}}),e0=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});Zy();const r0=(r,t={strict:!0,invertY:!1})=>({parse:e=>i0(e,t),serialize:e=>n0(e,r,t)}),i0=(r,t={strict:!0,invertY:!1})=>{const e=r.id||uc(),{creator:i,created:n,modified:s,body:o,...a}=r,l=t0(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=ey(c)?ry(c,t.invertY):(c==null?void 0:c.type)==="SvgSelector"?fy(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:gc(i),updated:s?new Date(s):void 0,...typeof d=="string"?{}:d,annotation:e,selector:u||c}}}:{error:Error(`Invalid selector: ${JSON.stringify(c)}`)}},n0=(r,t,e={strict:!0,invertY:!1})=>{const{selector:i,creator:n,created:s,updated:o,updatedBy:a,...l}=r.target;let h;try{h=i.type==_t.RECTANGLE?iy(i.geometry):my(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:e0(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},Ri=[];function s0(r,t=Rt){let e;const i=new Set;function n(a){if(Kt(r,a)&&(r=a,e)){const l=!Ri.length;for(const h of i)h[1](),Ri.push(h,r);if(l){for(let h=0;h<Ri.length;h+=2)Ri[h][0](Ri[h+1]);Ri.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 o0=(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}`)},a0=(r,t)=>{o0(r,t);const{subscribe:e,set:i}=s0(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}},ri=(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}},gs=(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}},Ne=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,l0=r=>({}),yc=r=>({grab:r[0]});function h0(r){let t,e,i,n;const s=r[8].default,o=Og(s,r,r[7],yc);return{c(){t=z("g"),o&&o.c(),x(t,"class","a9s-annotation selected")},m(a,l){nt(a,t,l),o&&o.m(t,null),e=!0,i||(n=[St(t,"pointerup",r[2]),St(t,"pointermove",r[1])],i=!0)},p(a,[l]){o&&o.p&&(!e||l&128)&&Ng(o,s,a,a[7],e?Lg(s,a[7],l,l0):Fg(a[7]),yc)},i(a){e||(lt(o,a),e=!0)},o(a){yt(o,a),e=!1},d(a){a&&rt(t),o&&o.d(a),i=!1,Me(n)}}}function c0(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Mr();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:g}=h.getBoundingClientRect(),b=_.clientX-v,S=_.clientY-g;u=l.elementToImage(b,S)}else{const{offsetX:v,offsetY:g}=_;u=l.elementToImage(v,g)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=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,m,o,a,l,h,n,i]}class sa extends me{constructor(t){super(),pe(this,t,c0,h0,Kt,{shape:3,editor:4,transform:5,svgEl:6})}}function u0(r){let t,e,i,n,s,o,a,l,h=r[3]&&_c(r);return{c(){t=z("g"),e=z("circle"),h&&h.c(),n=z("circle"),x(e,"class","a9s-handle-buffer svelte-qtyc7s"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]+6/r[2]),x(e,"role","button"),x(e,"tabindex","0"),x(n,"class",s=Ai(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[5]),x(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){nt(c,t,u),xt(t,e),h&&h.m(t,null),xt(t,n),a||(l=[St(e,"dblclick",r[12]),St(e,"pointerenter",r[13]),St(e,"pointerleave",r[14]),St(e,"pointerdown",r[15]),St(e,"pointerdown",r[6]),St(e,"pointerup",r[16]),St(e,"pointerup",r[7])],a=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&x(e,"r",i),c[3]?h?h.p(c,u):(h=_c(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=Ai(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&x(n,"class",s),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&32&&x(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&x(t,"class",o)},d(c){c&&rt(t),h&&h.d(),a=!1,Me(l)}}}function d0(r){let t,e,i,n,s,o,a,l,h;return{c(){t=z("g"),e=z("circle"),n=z("circle"),o=z("circle"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=r[5]*10),x(e,"class","a9s-touch-halo"),Je(e,"touched",r[4]),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",s=r[5]+10/r[2]),x(n,"class","a9s-handle-buffer svelte-qtyc7s"),x(n,"role","button"),x(n,"tabindex","0"),x(o,"class","a9s-handle-dot"),x(o,"cx",r[0]),x(o,"cy",r[1]),x(o,"r",a=r[5]+2/r[2]),x(t,"class","a9s-touch-handle")},m(c,u){nt(c,t,u),xt(t,e),xt(t,n),xt(t,o),l||(h=[St(n,"dblclick",r[9]),St(n,"pointerdown",r[10]),St(n,"pointerdown",r[6]),St(n,"pointerup",r[11]),St(n,"pointerup",r[7])],l=!0)},p(c,u){u&1&&x(e,"cx",c[0]),u&2&&x(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&x(e,"r",i),u&16&&Je(e,"touched",c[4]),u&1&&x(n,"cx",c[0]),u&2&&x(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&x(n,"r",s),u&1&&x(o,"cx",c[0]),u&2&&x(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&x(o,"r",a)},d(c){c&&rt(t),l=!1,Me(h)}}}function _c(r){let t,e;return{c(){t=z("circle"),x(t,"class","a9s-handle-selected"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",e=r[5]+8/r[2])},m(i,n){nt(i,t,n)},p(i,n){n&1&&x(t,"cx",i[0]),n&2&&x(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&x(t,"r",e)},d(i){i&&rt(t)}}}function f0(r){let t;function e(n,s){return Ne?d0:u0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function p0(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){oe.call(this,r,g)}function d(g){oe.call(this,r,g)}function f(g){oe.call(this,r,g)}function p(g){oe.call(this,r,g)}function m(g){oe.call(this,r,g)}function y(g){oe.call(this,r,g)}function _(g){oe.call(this,r,g)}function v(g){oe.call(this,r,g)}return r.$$set=g=>{e(8,t=Vo(Vo({},t),Zh(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=Zh(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Mi extends me{constructor(t){super(),pe(this,t,p0,f0,Kt,{x:0,y:1,scale:2,selected:3})}}function m0(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("circle"),n=z("circle"),s=z("circle"),x(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),x(e,"cx",r[0]),x(e,"cy",r[1]),x(e,"r",i=1.75*r[2]),x(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),x(n,"cx",r[0]),x(n,"cy",r[1]),x(n,"r",r[2]),x(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),x(s,"cx",r[0]),x(s,"cy",r[1]),x(s,"r",r[2]),x(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){nt(l,t,h),xt(t,e),xt(t,n),xt(t,s),o||(a=[St(e,"pointerdown",r[5]),St(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&x(e,"cx",l[0]),h&2&&x(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&x(e,"r",i),h&1&&x(n,"cx",l[0]),h&2&&x(n,"cy",l[1]),h&4&&x(n,"r",l[2]),h&1&&x(s,"cx",l[0]),h&2&&x(s,"cy",l[1]),h&4&&x(s,"r",l[2])},d(l){l&&rt(t),o=!1,Me(a)}}}function g0(r){let t;return{c(){t=z("circle"),x(t,"cx",r[0]),x(t,"cy",r[1]),x(t,"r",r[2])},m(e,i){nt(e,t,i)},p(e,i){i&1&&x(t,"cx",e[0]),i&2&&x(t,"cy",e[1]),i&4&&x(t,"r",e[2])},d(e){e&&rt(t)}}}function y0(r){let t;function e(n,s){return Ne?g0:m0}let i=e()(r);return{c(){i.c(),t=De()},m(n,s){i.m(n,s),nt(n,t,s)},p(n,[s]){i.p(n,s)},i:Rt,o:Rt,d(n){n&&rt(t),i.d(n)}}}function _0(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 vc extends me{constructor(t){super(),pe(this,t,_0,y0,Kt,{x:0,y:1,scale:4})}}function oa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function bc(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function aa(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function la(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function xc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[28][0]),x(t,"cy",i=r[28][1]),x(t,"r",n=bn/r[3]),x(t,"class","svelte-1h2slbm")},m(s,o){nt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&x(t,"cy",i),o[0]&8&&n!==(n=bn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function wc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1h2slbm"),x(a,"cx",l=r[28][0]),x(a,"cy",h=r[28][1]),x(a,"r",c=bn/r[3]),x(a,"class","svelte-1h2slbm"),x(t,"id",`${r[19]}-inner`),x(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){nt(u,t,d),xt(t,e),xt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&x(a,"cy",h),d[0]&8&&c!==(c=bn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Ec(r){let t,e;return t=new Mi({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(){Gt(r[27](`HANDLE-${r[30]}`))&&r[27](`HANDLE-${r[30]}`).apply(this,arguments)}),t.$on("pointerup",r[16](r[30])),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function Tc(r){let t,e;return t=new vc({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function v0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&xc(la(r)),C=r[6]!==void 0&&!r[7]&&wc(aa(r)),I=Ie(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Ec(bc(r,I,P));const F=P=>yt(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Tc(oa(r));return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),R&&R.c(),C&&C.c(),c=we(),u=z("polygon"),f=we(),p=z("polygon"),y=we();for(let P=0;P<M.length;P+=1)M[P].c();_=we(),U&&U.c(),v=De(),x(i,"x",n=r[9].x),x(i,"y",s=r[9].y),x(i,"width",o=r[9].w),x(i,"height",a=r[9].h),x(i,"class","svelte-1h2slbm"),x(l,"points",h=r[5].points.map(Ac).join(" ")),x(l,"class","svelte-1h2slbm"),x(e,"id",`${r[19]}-outer`),x(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[19]}-outer)`),x(u,"points",d=r[5].points.map(Sc).join(" ")),x(p,"class","a9s-inner a9s-shape-handle"),x(p,"mask",`url(#${r[19]}-inner)`),x(p,"style",r[1]),x(p,"points",m=r[5].points.map(Cc).join(" "))},m(P,E){nt(P,t,E),xt(t,e),xt(e,i),xt(e,l),R&&R.m(e,null),C&&C.m(t,null),nt(P,c,E),nt(P,u,E),nt(P,f,E),nt(P,p,E),nt(P,y,E);for(let T=0;T<M.length;T+=1)M[T]&&M[T].m(P,E);nt(P,_,E),U&&U.m(P,E),nt(P,v,E),g=!0,b||(S=[St(u,"pointerup",r[14]),St(u,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),St(p,"pointermove",r[13]),St(p,"pointerup",r[14]),St(p,"pointerdown",function(){Gt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,E){if(r=P,(!g||E[0]&512&&n!==(n=r[9].x))&&x(i,"x",n),(!g||E[0]&512&&s!==(s=r[9].y))&&x(i,"y",s),(!g||E[0]&512&&o!==(o=r[9].w))&&x(i,"width",o),(!g||E[0]&512&&a!==(a=r[9].h))&&x(i,"height",a),(!g||E[0]&32&&h!==(h=r[5].points.map(Ac).join(" ")))&&x(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(la(r),E):(R=xc(la(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(aa(r),E):(C=wc(aa(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||E[0]&32&&d!==(d=r[5].points.map(Sc).join(" ")))&&x(u,"points",d),(!g||E[0]&2)&&x(p,"style",r[1]),(!g||E[0]&32&&m!==(m=r[5].points.map(Cc).join(" ")))&&x(p,"points",m),E[0]&134322472){I=Ie(r[5].points);let T;for(T=0;T<I.length;T+=1){const A=bc(r,I,T);M[T]?(M[T].p(A,E),lt(M[T],1)):(M[T]=Ec(A),M[T].c(),lt(M[T],1),M[T].m(_.parentNode,_))}for(Ee(),T=I.length;T<M.length;T+=1)F(T);Te()}r[6]!==void 0&&!r[7]?U?(U.p(oa(r),E),E[0]&192&&lt(U,1)):(U=Tc(oa(r)),U.c(),lt(U,1),U.m(v.parentNode,v)):U&&(Ee(),yt(U,1,1,()=>{U=null}),Te())},i(P){if(!g){for(let E=0;E<I.length;E+=1)lt(M[E]);lt(U),g=!0}},o(P){M=M.filter(Boolean);for(let E=0;E<M.length;E+=1)yt(M[E]);yt(U),g=!1},d(P){P&&(rt(t),rt(c),rt(u),rt(f),rt(p),rt(y),rt(_),rt(v)),R&&R.d(),C&&C.d(),Jr(M,P),U&&U.d(P),b=!1,Me(S)}}}function b0(r){let t,e;return t=new sa({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[v0,({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(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const x0=250,w0=1e3,E0=12,bn=4.5,Ac=r=>r.join(","),Sc=r=>r.join(","),Cc=r=>r.join(",");function T0(r,t,e){let i,n,s;const o=Mr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=T=>{if(m.length>0||!n.some(N=>N.visible)){e(6,d=void 0);return}const[A,O]=h.elementToImage(T.offsetX,T.offsetY),D=N=>Math.pow(N[0]-A,2)+Math.pow(N[1]-O,2),L=i.points.reduce((N,k)=>D(k)<D(N)?k:N),$=n.filter(N=>N.visible).reduce((N,k)=>D(k.point)<D(N.point)?k:N),B=Math.pow(w0/c,2);D(L)<B||D($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=T=>{e(7,f=!0),T.preventDefault(),T.stopPropagation(),p=performance.now()},R=T=>A=>{if(!p||Ne||performance.now()-p>x0)return;const O=m.includes(T);A.metaKey||A.ctrlKey||A.shiftKey?O?e(8,m=m.filter(D=>D!==T)):e(8,m=[...m,T]):O&&m.length>1?e(8,m=[T]):O?e(8,m=[]):e(8,m=[T]),g()},C=(T,A,O)=>{g();let D;const L=T.geometry;m.length>1?D=L.points.map(([B,N],k)=>m.includes(k)?[B+O[0],N+O[1]]:[B,N]):A==="SHAPE"?D=L.points.map(([B,N])=>[B+O[0],N+O[1]]):D=L.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+O[0],N+O[1]]:[B,N]);const $=Ae(D);return{...T,geometry:{points:D,bounds:$}}},I=T=>async A=>{A.stopPropagation();const O=[...i.points.slice(0,T+1),n[T].point,...i.points.slice(T+1)],D=Ae(O);o("change",{...a,geometry:{points:O,bounds:D}}),await ic();const L=[...document.querySelectorAll(".a9s-handle")][T+1];if(L!=null&&L.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});L.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const T=i.points.filter((O,D)=>!m.includes(D)),A=Ae(T);o("change",{...a,geometry:{points:T,bounds:A}}),e(8,m=[])};ti(()=>{if(Ne)return;const T=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",T),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",T)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(T){oe.call(this,r,T)}function P(T){oe.call(this,r,T)}function E(T){oe.call(this,r,T)}return r.$$set=T=>{"shape"in T&&e(0,a=T.shape),"computedStyle"in T&&e(1,l=T.computedStyle),"transform"in T&&e(2,h=T.transform),"viewportScale"in T&&e(3,c=T.viewportScale),"svgEl"in T&&e(4,u=T.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Ne?[]:i.points.map((T,A)=>{const O=A===i.points.length-1?i.points[0]:i.points[A+1],D=(T[0]+O[0])/2,L=(T[1]+O[1])/2,$=Math.sqrt(Math.pow(O[0]-D,2)+Math.pow(O[1]-L,2))>E0/c;return{point:[D,L],visible:$}})),r.$$.dirty[0]&40&&e(9,s=gs(i.bounds,bn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,E]}class A0 extends me{constructor(t){super(),pe(this,t,T0,b0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function S0(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,E,T,A,O,D,L,$,B,N,k,X,j,K,V,ut,H,mt,Q,dt,gt,Et,Dt,Yt,Vt,et,$e,es;return Q=new Mi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Gt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Mi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Gt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Mi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Mi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Gt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),f=we(),p=z("rect"),g=we(),b=z("rect"),M=we(),F=z("rect"),T=we(),A=z("rect"),$=we(),B=z("rect"),j=we(),K=z("rect"),mt=we(),re(Q.$$.fragment),dt=we(),re(gt.$$.fragment),Et=we(),re(Dt.$$.fragment),Yt=we(),re(Vt.$$.fragment),x(i,"class","rect-mask-bg svelte-1njczvj"),x(i,"x",n=r[6].x),x(i,"y",s=r[6].y),x(i,"width",o=r[6].w),x(i,"height",a=r[6].h),x(l,"class","rect-mask-fg svelte-1njczvj"),x(l,"x",h=r[5].x),x(l,"y",c=r[5].y),x(l,"width",u=r[5].w),x(l,"height",d=r[5].h),x(e,"id",r[8]),x(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),x(p,"class","a9s-outer"),x(p,"mask",`url(#${r[8]})`),x(p,"x",m=r[5].x),x(p,"y",y=r[5].y),x(p,"width",_=r[5].w),x(p,"height",v=r[5].h),x(b,"class","a9s-inner a9s-shape-handle"),x(b,"style",r[1]),x(b,"x",S=r[5].x),x(b,"y",R=r[5].y),x(b,"width",C=r[5].w),x(b,"height",I=r[5].h),x(F,"class","a9s-edge-handle a9s-edge-handle-top"),x(F,"x",U=r[5].x),x(F,"y",P=r[5].y),x(F,"height",1),x(F,"width",E=r[5].w),x(A,"class","a9s-edge-handle a9s-edge-handle-right"),x(A,"x",O=r[5].x+r[5].w),x(A,"y",D=r[5].y),x(A,"height",L=r[5].h),x(A,"width",1),x(B,"class","a9s-edge-handle a9s-edge-handle-bottom"),x(B,"x",N=r[5].x),x(B,"y",k=r[5].y+r[5].h),x(B,"height",1),x(B,"width",X=r[5].w),x(K,"class","a9s-edge-handle a9s-edge-handle-left"),x(K,"x",V=r[5].x),x(K,"y",ut=r[5].y),x(K,"height",H=r[5].h),x(K,"width",1)},m(Y,G){nt(Y,t,G),xt(t,e),xt(e,i),xt(e,l),nt(Y,f,G),nt(Y,p,G),nt(Y,g,G),nt(Y,b,G),nt(Y,M,G),nt(Y,F,G),nt(Y,T,G),nt(Y,A,G),nt(Y,$,G),nt(Y,B,G),nt(Y,j,G),nt(Y,K,G),nt(Y,mt,G),Jt(Q,Y,G),nt(Y,dt,G),Jt(gt,Y,G),nt(Y,Et,G),Jt(Dt,Y,G),nt(Y,Yt,G),Jt(Vt,Y,G),et=!0,$e||(es=[St(p,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(b,"pointerdown",function(){Gt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),St(F,"pointerdown",function(){Gt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),St(A,"pointerdown",function(){Gt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),St(B,"pointerdown",function(){Gt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),St(K,"pointerdown",function(){Gt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&x(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&x(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&x(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&x(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&x(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&x(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&x(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&x(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&x(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&x(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&x(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&x(p,"height",v),(!et||G&2)&&x(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&x(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&x(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&x(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&x(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&x(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&x(F,"y",P),(!et||G&32&&E!==(E=r[5].w))&&x(F,"width",E),(!et||G&32&&O!==(O=r[5].x+r[5].w))&&x(A,"x",O),(!et||G&32&&D!==(D=r[5].y))&&x(A,"y",D),(!et||G&32&&L!==(L=r[5].h))&&x(A,"height",L),(!et||G&32&&N!==(N=r[5].x))&&x(B,"x",N),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&x(B,"y",k),(!et||G&32&&X!==(X=r[5].w))&&x(B,"width",X),(!et||G&32&&V!==(V=r[5].x))&&x(K,"x",V),(!et||G&32&&ut!==(ut=r[5].y))&&x(K,"y",ut),(!et||G&32&&H!==(H=r[5].h))&&x(K,"height",H);const Sr={};G&32&&(Sr.x=r[5].x),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),Q.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),gt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Dt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Vt.$set(Pr)},i(Y){et||(lt(Q.$$.fragment,Y),lt(gt.$$.fragment,Y),lt(Dt.$$.fragment,Y),lt(Vt.$$.fragment,Y),et=!0)},o(Y){yt(Q.$$.fragment,Y),yt(gt.$$.fragment,Y),yt(Dt.$$.fragment,Y),yt(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(rt(t),rt(f),rt(p),rt(g),rt(b),rt(M),rt(F),rt(T),rt(A),rt($),rt(B),rt(j),rt(K),rt(mt),rt(dt),rt(Et),rt(Yt)),te(Q,Y),te(gt,Y),te(Dt,Y),te(Vt,Y),$e=!1,Me(es)}}}function C0(r){let t,e;return t=new sa({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[S0,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){re(t.$$.fragment)},m(i,n){Jt(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&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function I0(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){oe.call(this,r,m)}function f(m){oe.call(this,r,m)}function p(m){oe.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=gs(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class P0 extends me{constructor(t){super(),pe(this,t,I0,C0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var Ic=Object.prototype.hasOwnProperty;function ha(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--&&ha(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if(Ic.call(r,e)&&++i&&!Ic.call(t,e)||!(e in t)||!ha(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const R0=12,M0=(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,m=Math.sqrt(Math.pow(d[0]-f,2)+Math.pow(d[1]-p,2))>R0/t;return{point:[f,p],visible:m,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function ca(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Pc(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Rc(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Mc(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function ua(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function da(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Dc(r){let t,e,i,n;return{c(){t=z("circle"),x(t,"cx",e=r[29][0]),x(t,"cy",i=r[29][1]),x(t,"r",n=xn/r[3]),x(t,"class","svelte-1vxo6dc")},m(s,o){nt(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&x(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&x(t,"cy",i),o[0]&8&&n!==(n=xn/s[3])&&x(t,"r",n)},d(s){s&&rt(t)}}}function Bc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("mask"),e=z("rect"),a=z("circle"),x(e,"x",i=r[9].x),x(e,"y",n=r[9].y),x(e,"width",s=r[9].w),x(e,"height",o=r[9].h),x(e,"class","svelte-1vxo6dc"),x(a,"cx",l=r[29][0]),x(a,"cy",h=r[29][1]),x(a,"r",c=xn/r[3]),x(a,"class","svelte-1vxo6dc"),x(t,"id",`${r[18]}-${r[32]}-inner`),x(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){nt(u,t,d),xt(t,e),xt(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&x(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&x(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&x(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&x(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&x(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&x(a,"cy",h),d[0]&8&&c!==(c=xn/u[3])&&x(a,"r",c)},d(u){u&&rt(t)}}}function Oc(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Mi({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(){Gt(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(){re(t.$$.fragment)},m(n,s){Jt(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||(lt(t.$$.fragment,n),e=!0)},o(n){yt(t.$$.fragment,n),e=!1},d(n){te(t,n)}}}function Lc(r){let t,e,i=Ie(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=Oc(Mc(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=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);nt(o,t,a),e=!0},p(o,a){if(a[0]&268491048){i=Ie(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Mc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=Oc(h),n[l].c(),lt(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)lt(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&&rt(t),Jr(n,o)}}}function Nc(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&Dc(da(r)),g=r[6]!==void 0&&!r[7]&&Bc(ua(r)),b=Ie(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Lc(Rc(r,b,C));const R=C=>yt(S[C],1,1,()=>{S[C]=null});return{c(){t=z("g"),e=z("defs"),i=z("mask"),n=z("rect"),h=z("path"),v&&v.c(),g&&g.c(),u=z("path"),f=z("path");for(let C=0;C<S.length;C+=1)S[C].c();x(n,"x",s=r[9].x),x(n,"y",o=r[9].y),x(n,"width",a=r[9].w),x(n,"height",l=r[9].h),x(n,"class","svelte-1vxo6dc"),x(h,"d",c=He(r[30])),x(h,"class","svelte-1vxo6dc"),x(i,"id",`${r[18]}-${r[32]}-outer`),x(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),x(u,"class","a9s-outer"),x(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),x(u,"fill-rule","evenodd"),x(u,"d",d=He(r[30])),x(f,"class","a9s-inner"),x(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),x(f,"style",r[1]),x(f,"fill-rule","evenodd"),x(f,"d",p=He(r[30]))},m(C,I){nt(C,t,I),xt(t,e),xt(e,i),xt(i,n),xt(i,h),v&&v.m(i,null),g&&g.m(e,null),xt(t,u),xt(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[St(u,"pointerup",r[13]),St(u,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),St(f,"pointerup",r[13]),St(f,"pointerdown",function(){Gt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&x(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&x(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&x(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&x(n,"height",l),(!m||I[0]&32&&c!==(c=He(r[30])))&&x(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(da(r),I):(v=Dc(da(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(ua(r),I):(g=Bc(ua(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=He(r[30])))&&x(u,"d",d),(!m||I[0]&2)&&x(f,"style",r[1]),(!m||I[0]&32&&p!==(p=He(r[30])))&&x(f,"d",p),I[0]&268491048){b=Ie(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Rc(r,b,M);S[M]?(S[M].p(F,I),lt(S[M],1)):(S[M]=Lc(F),S[M].c(),lt(S[M],1),S[M].m(t,null))}for(Ee(),M=b.length;M<S.length;M+=1)R(M);Te()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)lt(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)yt(S[I]);m=!1},d(C){C&&rt(t),v&&v.d(),g&&g.d(),Jr(S,C),y=!1,Me(_)}}}function Fc(r){let t,e;return t=new vc({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Gt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function D0(r){let t,e,i,n=Ie(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=Nc(Pc(r,n,l));const o=l=>yt(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Fc(ca(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=we(),a&&a.c(),e=De()},m(l,h){for(let c=0;c<s.length;c+=1)s[c]&&s[c].m(l,h);nt(l,t,h),a&&a.m(l,h),nt(l,e,h),i=!0},p(l,h){if(h[0]&268763114){n=Ie(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Pc(l,n,c);s[c]?(s[c].p(u,h),lt(s[c],1)):(s[c]=Nc(u),s[c].c(),lt(s[c],1),s[c].m(t.parentNode,t))}for(Ee(),c=n.length;c<s.length;c+=1)o(c);Te()}l[6]!==void 0&&!l[7]?a?(a.p(ca(l),h),h[0]&192&&lt(a,1)):(a=Fc(ca(l)),a.c(),lt(a,1),a.m(e.parentNode,e)):a&&(Ee(),yt(a,1,1,()=>{a=null}),Te())},i(l){if(!i){for(let h=0;h<n.length;h+=1)lt(s[h]);lt(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&&(rt(t),rt(e)),Jr(s,l),a&&a.d(l)}}}function B0(r){let t,e;return t=new sa({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[D0,({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(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}const O0=250,L0=1e3,xn=4.5;function N0(r,t,e){let i,n,s;const o=Mr();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[O,D]=h.elementToImage(A.offsetX,A.offsetY),L=k=>Math.pow(k[0]-O,2)+Math.pow(k[1]-D,2),$=Kg(i).reduce((k,X)=>L(X)<L(k)?X:k),B=n.filter(k=>k.visible).reduce((k,X)=>L(X.point)<L(k.point)?X:k),N=Math.pow(L0/c,2);L($)<N||L(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,O,D)=>L=>{if(!p||Ne||performance.now()-p>O0)return;const $=N=>N.polygon===A&&N.ring===O&&N.point===D,B=m.some($);L.metaKey||L.ctrlKey||L.shiftKey?B?e(8,m=m.filter(N=>!$(N))):e(8,m=[...m,{polygon:A,ring:O,point:D}]):B&&m.length>1?e(8,m=[{polygon:A,ring:O,point:D}]):B?e(8,m=[]):e(8,m=[{polygon:A,ring:O,point:D}]),g()},C=(A,O,D)=>{g();const L=A.geometry.polygons;let $;if(O==="SHAPE")$=L.map(B=>{const N=B.rings.map((X,j)=>({points:X.points.map((K,V)=>[K[0]+D[0],K[1]+D[1]])})),k=Ae(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,X]=O.split("-").map(j=>parseInt(j));$=L.map((j,K)=>{if(K===N){const V=j.rings.map((H,mt)=>mt===k?{points:H.points.map((Q,dt)=>dt===X?[Q[0]+D[0],Q[1]+D[1]]:Q)}:H),ut=Ae(V[0].points);return{rings:V,bounds:ut}}else return j})}return{...A,geometry:{polygons:$,bounds:Zo($)}}},I=A=>async O=>{O.stopPropagation();const D=n[A],L=i.polygons.map((B,N)=>{if(N===D.elementIdx){const k=B.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),X=Ae(k[0].points);return{rings:k,bounds:X}}else return B});o("change",{...a,geometry:{polygons:L,bounds:Zo(L)}}),await ic();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:O.clientX,clientY:O.clientY,pointerId:O.pointerId,pointerType:O.pointerType,isPrimary:O.isPrimary,buttons:O.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((O,D)=>{if(m.some(L=>L.polygon===D)){const L=O.rings.map((B,N)=>{const k=m.filter(X=>X.polygon===D&&X.ring===N);return k.length&&B.points.length-k.length>=3?{points:B.points.filter((X,j)=>!k.some(K=>K.point===j))}:B}),$=Ae(L[0].points);return{rings:L,bounds:$}}else return O});!ha(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:Zo(A)}}),e(8,m=[]))};ti(()=>{if(Ne)return;const A=O=>{(O.key==="Delete"||O.key==="Backspace")&&(O.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,O,D,{polygon:L,ring:$,point:B})=>L===A&&$===O&&B===D;function P(A){oe.call(this,r,A)}function E(A){oe.call(this,r,A)}function T(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=Ne?[]:M0(i,c)),r.$$.dirty[0]&40&&e(9,s=gs(i.bounds,xn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,E,T]}class F0 extends me{constructor(t){super(),pe(this,t,N0,B0,Kt,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}const kc=new Map([[_t.RECTANGLE,P0],[_t.POLYGON,A0],[_t.MULTIPOLYGON,F0]]),fa=r=>kc.get(r.type),Uc=(r,t)=>kc.set(r,t);function k0(r,t,e){let i;const n=Mr();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ti(()=>(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=ri(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 U0 extends me{constructor(t){super(),pe(this,t,k0,null,Kt,{annotation:0,editor:1,style:2,target:3,transform:4,viewportScale:5})}}function G0(r,t,e){const i=Mr();let{drawingMode:n}=t,{target:s}=t,{tool:o}=t,{transform:a}=t,{viewportScale:l}=t,h;return ti(()=>{const c=s.closest("svg"),u=[],d=(f,p,m)=>{c==null||c.addEventListener(f,p,m),u.push(()=>c==null?void 0:c.removeEventListener(f,p,m))};return e(5,h=new o({target: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 $0 extends me{constructor(t){super(),pe(this,t,G0,null,Kt,{drawingMode:0,target:1,tool:2,transform:3,viewportScale:4})}}function Gc(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("rect"),h=z("rect"),c=z("rect"),x(i,"class","rect-mask-bg svelte-1a76qe7"),x(i,"x",n=r[1]-r[5]),x(i,"y",s=r[2]-r[5]),x(i,"width",o=r[3]+2*r[5]),x(i,"height",a=r[4]+2*r[5]),x(l,"class","rect-mask-fg svelte-1a76qe7"),x(l,"x",r[1]),x(l,"y",r[2]),x(l,"width",r[3]),x(l,"height",r[4]),x(e,"id",r[6]),x(e,"class","a9s-rubberband-rectangle-mask svelte-1a76qe7"),x(h,"class","a9s-outer"),x(h,"mask",`url(#${r[6]})`),x(h,"x",r[1]),x(h,"y",r[2]),x(h,"width",r[3]),x(h,"height",r[4]),x(c,"class","a9s-inner"),x(c,"x",r[1]),x(c,"y",r[2]),x(c,"width",r[3]),x(c,"height",r[4])},m(u,d){nt(u,t,d),xt(t,e),xt(e,i),xt(e,l),nt(u,h,d),nt(u,c,d)},p(u,d){d&34&&n!==(n=u[1]-u[5])&&x(i,"x",n),d&36&&s!==(s=u[2]-u[5])&&x(i,"y",s),d&40&&o!==(o=u[3]+2*u[5])&&x(i,"width",o),d&48&&a!==(a=u[4]+2*u[5])&&x(i,"height",a),d&2&&x(l,"x",u[1]),d&4&&x(l,"y",u[2]),d&8&&x(l,"width",u[3]),d&16&&x(l,"height",u[4]),d&2&&x(h,"x",u[1]),d&4&&x(h,"y",u[2]),d&8&&x(h,"width",u[3]),d&16&&x(h,"height",u[4]),d&2&&x(c,"x",u[1]),d&4&&x(c,"y",u[2]),d&8&&x(c,"width",u[3]),d&16&&x(c,"height",u[4])},d(u){u&&(rt(t),rt(h),rt(c))}}}function H0(r){let t,e=r[0]&&Gc(r);return{c(){t=z("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[0]?e?e.p(i,n):(e=Gc(i),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}function X0(r,t,e){let i;const n=Mr();let{addEventListener:s}=t,{drawingMode:o}=t,{transform:a}=t,{viewportScale:l=1}=t,h,c,u,d,f,p,m;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,m=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,m=Math.abs(u[1]-c[1])))},v=S=>{const R=S,C=performance.now()-h;if(o==="click"){if(C>300)return;c?g():(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,m=1))}else c&&(C>300||p*m>100?(R.stopPropagation(),g()):(e(0,c=void 0),u=void 0))},g=()=>{if(p*m>15){const S={type:_t.RECTANGLE,geometry:{bounds:{minX:d,minY:f,maxX:d+p,maxY:f+m},x:d,y:f,w:p,h:m}};n("create",S)}e(0,c=void 0),u=void 0};ti(()=>{s("pointerdown",y),s("pointermove",_),s("pointerup",v,!0)});const b=`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,m,i,b,s,o,a,l]}class V0 extends me{constructor(t){super(),pe(this,t,X0,H0,Kt,{addEventListener:7,drawingMode:8,transform:9,viewportScale:10})}}function pa(r){const t=r.slice(),e=t[2].map(i=>i.join(",")).join(" ");return t[19]=e,t}function $c(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m=r[1]&&Hc(r);return{c(){t=z("defs"),e=z("mask"),i=z("rect"),l=z("polygon"),c=z("polygon"),d=z("polygon"),m&&m.c(),p=De(),x(i,"x",n=r[3].x),x(i,"y",s=r[3].y),x(i,"width",o=r[3].w),x(i,"height",a=r[3].h),x(i,"class","svelte-18wrg3t"),x(l,"points",h=r[19]),x(l,"class","svelte-18wrg3t"),x(e,"id",r[5]),x(e,"class","a9s-rubberband-polygon-mask svelte-18wrg3t"),x(c,"class","a9s-outer"),x(c,"mask",`url(#${r[5]})`),x(c,"points",u=r[19]),x(d,"class","a9s-inner"),x(d,"points",f=r[19])},m(y,_){nt(y,t,_),xt(t,e),xt(e,i),xt(e,l),nt(y,c,_),nt(y,d,_),m&&m.m(y,_),nt(y,p,_)},p(y,_){_&8&&n!==(n=y[3].x)&&x(i,"x",n),_&8&&s!==(s=y[3].y)&&x(i,"y",s),_&8&&o!==(o=y[3].w)&&x(i,"width",o),_&8&&a!==(a=y[3].h)&&x(i,"height",a),_&4&&h!==(h=y[19])&&x(l,"points",h),_&4&&u!==(u=y[19])&&x(c,"points",u),_&4&&f!==(f=y[19])&&x(d,"points",f),y[1]?m?m.p(y,_):(m=Hc(y),m.c(),m.m(p.parentNode,p)):m&&(m.d(1),m=null)},d(y){y&&(rt(t),rt(c),rt(d),rt(p)),m&&m.d(y)}}}function Hc(r){let t,e,i;return{c(){t=z("circle"),x(t,"class","a9s-handle svelte-18wrg3t"),x(t,"cx",e=r[0][0][0]),x(t,"cy",i=r[0][0][1]),x(t,"r",r[4])},m(n,s){nt(n,t,s)},p(n,s){s&1&&e!==(e=n[0][0][0])&&x(t,"cx",e),s&1&&i!==(i=n[0][0][1])&&x(t,"cy",i),s&16&&x(t,"r",n[4])},d(n){n&&rt(t)}}}function j0(r){let t,e=r[3]&&$c(pa(r));return{c(){t=z("g"),e&&e.c(),x(t,"class","a9s-annotation a9s-rubberband")},m(i,n){nt(i,t,n),e&&e.m(t,null)},p(i,[n]){i[3]?e?e.p(pa(i),n):(e=$c(pa(i)),e.c(),e.m(t,null)):e&&(e.d(1),e=null)},i:Rt,o:Rt,d(i){i&&rt(t),e&&e.d()}}}const W0=20,z0=1500;function Y0(r,t,e){let i,n,s;const o=Mr();let{addEventListener:a}=t,{drawingMode:l}=t,{transform:h}=t,{viewportScale:c=1}=t,u,d=[],f,p,m=!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=us(f,d[0])*c;e(1,m=I<W0)}C.pointerType==="touch"&&(p=setTimeout(()=>{g()},z0))}},v=R=>{const C=R;if(p&&clearTimeout(p),l==="click"){const I=C.timeStamp-u.timeStamp,M=us([u.offsetX,u.offsetY],[C.offsetX,C.offsetY]);if(I>300||M>15)return;if(m)b();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&&us(d[0],f)<=4){e(0,d=[]),e(10,f=void 0);return}C.stopImmediatePropagation(),m?b():d.push(f)}},g=()=>{if(!f)return;const R=d.slice(0,-1);if(R.length<3)return;const C={type:_t.POLYGON,geometry:{bounds:Ae(d),points:R}};Ko(C)>4&&(e(0,d=[]),e(10,f=void 0),o("create",C))},b=()=>{const R={type:_t.POLYGON,geometry:{bounds:Ae(d),points:[...d]}};e(0,d=[]),e(10,f=void 0),o("create",R)};ti(()=>{a("pointerdown",y,!0),a("pointermove",_),a("pointerup",v,!0),a("dblclick",g,!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?m?d:[...d,f]:[]),r.$$.dirty&516&&e(3,s=n.length>0?gs(Ae(n),2/c):void 0)},[d,m,n,s,i,S,a,l,h,c,f]}class q0 extends me{constructor(t){super(),pe(this,t,Y0,j0,Kt,{addEventListener:6,drawingMode:7,transform:8,viewportScale:9})}}const ma=new Map([["rectangle",{tool:V0}],["polygon",{tool:q0}]]),ys=()=>[...ma.keys()],_s=r=>ma.get(r),Xc=(r,t,e={})=>ma.set(r,{tool:t,opts:e});function K0(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("ellipse"),n=z("ellipse"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"cx",r[2]),x(e,"cy",r[3]),x(e,"rx",r[4]),x(e,"ry",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"cx",r[2]),x(n,"cy",r[3]),x(n,"rx",r[4]),x(n,"ry",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}function Z0(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=ri(n,o))},[n,i,a,l,h,c,s,o]}class Q0 extends me{constructor(t){super(),pe(this,t,Z0,K0,Kt,{annotation:0,geom:6,style:7})}}function J0(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("line"),n=z("line"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"x1",r[2]),x(e,"y1",r[3]),x(e,"x2",r[4]),x(e,"y2",r[5]),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"x1",r[2]),x(n,"y1",r[3]),x(n,"x2",r[4]),x(n,"y2",r[5]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}function t_(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=ri(n,o))},[n,i,l,h,c,u,s,o]}class e_ extends me{constructor(t){super(),pe(this,t,t_,J0,Kt,{annotation:0,geom:6,style:7})}}function Vc(r,t,e){const i=r.slice();return i[5]=t[e],i}function jc(r){let t,e,i;return{c(){t=z("path"),i=z("path"),x(t,"class","a9s-outer"),x(t,"style",e=r[1]?"display:none;":void 0),x(t,"fill-rule","evenodd"),x(t,"d",He(r[5])),x(i,"class","a9s-inner"),x(i,"style",r[1]),x(i,"fill-rule","evenodd"),x(i,"d",He(r[5]))},m(n,s){nt(n,t,s),nt(n,i,s)},p(n,s){s&2&&e!==(e=n[1]?"display:none;":void 0)&&x(t,"style",e),s&2&&x(i,"style",n[1])},d(n){n&&(rt(t),rt(i))}}}function r_(r){let t,e,i=Ie(r[2]),n=[];for(let s=0;s<i.length;s+=1)n[s]=jc(Vc(r,i,s));return{c(){t=z("g");for(let s=0;s<n.length;s+=1)n[s].c();x(t,"class","a9s-annotation"),x(t,"data-id",e=r[0].id)},m(s,o){nt(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=Ie(s[2]);let a;for(a=0;a<i.length;a+=1){const l=Vc(s,i,a);n[a]?n[a].p(l,o):(n[a]=jc(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)&&x(t,"data-id",e)},i:Rt,o:Rt,d(s){s&&rt(t),Jr(n,s)}}}function i_(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=ri(n,o))},[n,i,a,s,o]}class n_ extends me{constructor(t){super(),pe(this,t,i_,r_,Kt,{annotation:0,geom:3,style:4})}}function s_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("polygon"),n=z("polygon"),x(e,"class","a9s-outer"),x(e,"style",i=r[1]?"display:none;":void 0),x(e,"points",r[2].map(o_).join(" ")),x(n,"class","a9s-inner"),x(n,"style",r[1]),x(n,"points",r[2].map(a_).join(" ")),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&2&&i!==(i=o[1]?"display:none;":void 0)&&x(e,"style",i),a&2&&x(n,"style",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}const o_=r=>r.join(","),a_=r=>r.join(",");function l_(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=ri(n,o))},[n,i,a,s,o]}class h_ extends me{constructor(t){super(),pe(this,t,l_,s_,Kt,{annotation:0,geom:3,style:4})}}function c_(r){let t,e,i,n,s,o,a;return{c(){t=z("g"),e=z("path"),s=z("path"),x(e,"class",i=Ai(`a9s-outer ${r[1]}`)+" svelte-1w0132l"),x(e,"style",n=r[3]?"display:none;":void 0),x(e,"d",r[2]),x(s,"class",o=Ai(`a9s-inner ${r[1]}`)+" svelte-1w0132l"),x(s,"style",r[3]),x(s,"d",r[2]),x(t,"class","a9s-annotation"),x(t,"data-id",a=r[0].id)},m(l,h){nt(l,t,h),xt(t,e),xt(t,s)},p(l,[h]){h&2&&i!==(i=Ai(`a9s-outer ${l[1]}`)+" svelte-1w0132l")&&x(e,"class",i),h&8&&n!==(n=l[3]?"display:none;":void 0)&&x(e,"style",n),h&4&&x(e,"d",l[2]),h&2&&o!==(o=Ai(`a9s-inner ${l[1]}`)+" svelte-1w0132l")&&x(s,"class",o),h&8&&x(s,"style",l[3]),h&4&&x(s,"d",l[2]),h&1&&a!==(a=l[0].id)&&x(t,"data-id",a)},i:Rt,o:Rt,d(l){l&&rt(t)}}}function u_(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=ri(o,l)),r.$$.dirty&16&&e(2,n=Jo(a)),r.$$.dirty&16&&e(1,s=a.closed?"closed":"open")},[o,s,n,i,a,l]}class d_ extends me{constructor(t){super(),pe(this,t,u_,c_,Kt,{annotation:0,geom:4,style:5})}}function f_(r){let t,e,i,n,s;return{c(){t=z("g"),e=z("rect"),n=z("rect"),x(e,"class","a9s-outer"),x(e,"style",i=r[5]?"display:none;":void 0),x(e,"x",r[4]),x(e,"y",r[3]),x(e,"width",r[2]),x(e,"height",r[1]),x(n,"class","a9s-inner"),x(n,"style",r[5]),x(n,"x",r[4]),x(n,"y",r[3]),x(n,"width",r[2]),x(n,"height",r[1]),x(t,"class","a9s-annotation"),x(t,"data-id",s=r[0].id)},m(o,a){nt(o,t,a),xt(t,e),xt(t,n)},p(o,[a]){a&32&&i!==(i=o[5]?"display:none;":void 0)&&x(e,"style",i),a&16&&x(e,"x",o[4]),a&8&&x(e,"y",o[3]),a&4&&x(e,"width",o[2]),a&2&&x(e,"height",o[1]),a&32&&x(n,"style",o[5]),a&16&&x(n,"x",o[4]),a&8&&x(n,"y",o[3]),a&4&&x(n,"width",o[2]),a&2&&x(n,"height",o[1]),a&1&&s!==(s=o[0].id)&&x(t,"data-id",s)},i:Rt,o:Rt,d(o){o&&rt(t)}}}function p_(r,t,e){let i,n,s,o,a,{annotation:l}=t,{geom:h}=t,{style:c}=t;return r.$$set=u=>{"annotation"in u&&e(0,l=u.annotation),"geom"in u&&e(6,h=u.geom),"style"in u&&e(7,c=u.style)},r.$$.update=()=>{r.$$.dirty&129&&e(5,i=ri(l,c)),r.$$.dirty&64&&e(4,{x:n,y:s,w:o,h:a}=h,n,(e(3,s),e(6,h)),(e(2,o),e(6,h)),(e(1,a),e(6,h)))},[l,a,o,s,n,i,h,c]}class m_ extends me{constructor(t){super(),pe(this,t,p_,f_,Kt,{annotation:0,geom:6,style:7})}}const g_=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]}}),y_=250,__=(r,t)=>{const e=Mr();let i;return{onPointerDown:()=>i=performance.now(),onPointerUp:n=>{if(performance.now()-i<y_){const{x:s,y:o}=Wc(n,r),a=Ne?10:2,l=t.getAt(s,o,void 0,a);l?e("click",{originalEvent:n,annotation:l}):e("click",{originalEvent:n})}}}},Wc=(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 zc(r,t,e){const i=r.slice();return i[39]=t[e],i}function Yc(r,t,e){const i=r.slice();return i[42]=t[e],i}function ga(r){const t=r.slice(),e=t[42].target.selector;return t[45]=e,t}function qc(r){let t=r[42],e,i,n=Kc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&131072&&Kt(t,t=s[42])?(Ee(),yt(n,1,1,Rt),Te(),n=Kc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function v_(r){let t,e;return t=new e_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function b_(r){let t,e;return t=new d_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function x_(r){let t,e;return t=new n_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function w_(r){let t,e;return t=new h_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function E_(r){let t,e;return t=new m_({props:{annotation:r[42],geom:r[45].geometry,style:r[1]}}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function T_(r){var t;let e,i;return e=new Q0({props:{annotation:r[42],geom:(t=r[45])==null?void 0:t.geometry,style:r[1]}}),{c(){re(e.$$.fragment)},m(n,s){Jt(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||(lt(e.$$.fragment,n),i=!0)},o(n){yt(e.$$.fragment,n),i=!1},d(n){te(e,n)}}}function Kc(r){let t,e,i,n;const s=[T_,E_,w_,x_,b_,v_],o=[];function a(l,h){var c,u,d,f,p,m;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:((m=l[45])==null?void 0:m.type)===_t.LINE?5:-1}return~(t=a(r))&&(e=o[t]=s[t](r)),{c(){e&&e.c(),i=De()},m(l,h){~t&&o[t].m(l,h),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function Zc(r){let t=Le(r[42])&&!r[10](r[42]),e,i,n=t&&qc(ga(r));return{c(){n&&n.c(),e=De()},m(s,o){n&&n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132096&&(t=Le(s[42])&&!s[10](s[42])),t?n?(n.p(ga(s),o),o[0]&132096&&lt(n,1)):(n=qc(ga(s)),n.c(),lt(n,1),n.m(e.parentNode,e)):n&&(Ee(),yt(n,1,1,()=>{n=null}),Te())},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n&&n.d(s)}}}function Qc(r){let t,e,i,n;const s=[S_,A_],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=De()},m(l,h){~t&&o[t].m(l,h),nt(l,i,h),n=!0},p(l,h){let c=t;t=a(l),t===c?~t&&o[t].p(l,h):(e&&(Ee(),yt(o[c],1,1,()=>{o[c]=null}),Te()),~t?(e=o[t],e?e.p(l,h):(e=o[t]=s[t](l),e.c()),lt(e,1),e.m(i.parentNode,i)):e=null)},i(l){n||(lt(e),n=!0)},o(l){yt(e),n=!1},d(l){l&&rt(i),~t&&o[t].d(l)}}}function A_(r){let t=`${r[2]}-${r[7]}`,e,i,n=Jc(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&132&&Kt(t,t=`${s[2]}-${s[7]}`)?(Ee(),yt(n,1,1,Rt),Te(),n=Jc(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function S_(r){let t,e,i=Ie(r[6]),n=[];for(let o=0;o<i.length;o+=1)n[o]=eu(zc(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=De()},m(o,a){for(let l=0;l<n.length;l+=1)n[l]&&n[l].m(o,a);nt(o,t,a),e=!0},p(o,a){if(a[0]&8659266){i=Ie(o[6]);let l;for(l=0;l<i.length;l+=1){const h=zc(o,i,l);n[l]?(n[l].p(h,a),lt(n[l],1)):(n[l]=eu(h),n[l].c(),lt(n[l],1),n[l].m(t.parentNode,t))}for(Ee(),l=i.length;l<n.length;l+=1)s(l);Te()}},i(o){if(!e){for(let a=0;a<i.length;a+=1)lt(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&&rt(t),Jr(n,o)}}}function Jc(r){let t,e;return t=new $0({props:{target:r[8],tool:r[15],drawingMode:r[14],transform:r[13],viewportScale:r[18]}}),t.$on("create",r[22]),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function tu(r){let t,e;return t=new U0({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(){Gt(r[23](r[39].annotation))&&r[23](r[39].annotation).apply(this,arguments)}),{c(){re(t.$$.fragment)},m(i,n){Jt(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||(lt(t.$$.fragment,i),e=!0)},o(i){yt(t.$$.fragment,i),e=!1},d(i){te(t,i)}}}function eu(r){let t=r[39].annotation.id,e,i,n=tu(r);return{c(){n.c(),e=De()},m(s,o){n.m(s,o),nt(s,e,o),i=!0},p(s,o){o[0]&64&&Kt(t,t=s[39].annotation.id)?(Ee(),yt(n,1,1,Rt),Te(),n=tu(s),n.c(),lt(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(lt(n),i=!0)},o(s){yt(n),i=!1},d(s){s&&rt(e),n.d(s)}}}function C_(r){let t,e,i,n,s,o,a=Ie(r[17].filter(r[34])),l=[];for(let u=0;u<a.length;u+=1)l[u]=Zc(Yc(r,a,u));const h=u=>yt(l[u],1,1,()=>{l[u]=null});let c=r[8]&&Qc(r);return{c(){t=z("svg"),e=z("g");for(let u=0;u<l.length;u+=1)l[u].c();i=z("g"),c&&c.c(),x(i,"class","drawing"),x(t,"role","application"),x(t,"tabindex",0),x(t,"class","a9s-annotationlayer"),Je(t,"drawing",r[15]),Je(t,"editing",r[5]),Je(t,"hidden",!r[3]),Je(t,"hover",r[16])},m(u,d){nt(u,t,d),xt(t,e);for(let f=0;f<l.length;f+=1)l[f]&&l[f].m(e,null);xt(t,i),c&&c.m(i,null),r[35](i),r[36](t),n=!0,s||(o=[St(t,"pointerup",function(){Gt(r[11])&&r[11].apply(this,arguments)}),St(t,"pointerdown",function(){Gt(r[12])&&r[12].apply(this,arguments)}),St(t,"pointermove",r[24])],s=!0)},p(u,d){if(r=u,d[0]&132098){a=Ie(r[17].filter(r[34]));let f;for(f=0;f<a.length;f+=1){const p=Yc(r,a,f);l[f]?(l[f].p(p,d),lt(l[f],1)):(l[f]=Zc(p),l[f].c(),lt(l[f],1),l[f].m(e,null))}for(Ee(),f=a.length;f<l.length;f+=1)h(f);Te()}r[8]?c?(c.p(r,d),d[0]&256&&lt(c,1)):(c=Qc(r),c.c(),lt(c,1),c.m(i,null)):c&&(Ee(),yt(c,1,1,()=>{c=null}),Te()),(!n||d[0]&32768)&&Je(t,"drawing",r[15]),(!n||d[0]&32)&&Je(t,"editing",r[5]),(!n||d[0]&8)&&Je(t,"hidden",!r[3]),(!n||d[0]&65536)&&Je(t,"hover",r[16])},i(u){if(!n){for(let d=0;d<a.length;d+=1)lt(l[d]);lt(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&&rt(t),Jr(l,u),c&&c.d(),r[35](null),r[36](null),s=!1,Me(o)}}}function I_(r,t,e){let i,n,s,o,a,l,h,c,u,d,f,p,m=Rt,y=()=>(m(),m=qh(A,H=>e(18,p=H)),A);r.$$.on_destroy.push(()=>m());let{drawingEnabled:_}=t,{image:v}=t,{preferredDrawingMode:g}=t,{state:b}=t,{style:S=void 0}=t,{toolName:R=ys()[0]}=t,{user:C}=t,{visible:I=!0}=t,M=0;const F=()=>e(7,M+=1),U=()=>R,P=()=>_;let E,T,A;ti(()=>y(e(9,A=a0(v,T))));const{hover:O,selection:D,store:L}=b;jo(r,O,H=>e(16,u=H)),jo(r,D,H=>e(33,d=H)),jo(r,L,H=>e(17,f=H));let $,B;const N=H=>{$&&L.unobserve($);const mt=H.filter(({editable:Q})=>Q).map(({id:Q})=>Q);mt.length>0?(e(5,B=mt.map(Q=>L.getAnnotation(Q)).filter(Q=>Q&&Le(Q))),$=Q=>{const{updated:dt}=Q.changes;e(5,B=dt==null?void 0:dt.map(gt=>gt.newValue))},L.observe($,{annotations:mt})):e(5,B=void 0)},k=H=>{const mt=uc(),Q={id:mt,bodies:[],target:{annotation:mt,selector:H.detail,creator:C,created:new Date}};L.addAnnotation(Q),D.setSelected(Q.id)},X=H=>mt=>{var Q;const{target:dt}=H,gt=10*60*1e3,Et=((Q=dt.creator)==null?void 0:Q.id)!==C.id||!dt.created||new Date().getTime()-dt.created.getTime()>gt;L.updateTarget({...dt,selector:mt.detail,created:Et?dt.created:new Date,updated:Et?new Date:void 0,updatedBy:Et?C:void 0})},j=H=>{const{x:mt,y:Q}=Wc(H,T),dt=L.getAt(mt,Q,void 0,2);dt?u!==dt.id&&O.set(dt.id):O.set(void 0)},K=H=>Le(H);function V(H){as[H?"unshift":"push"](()=>{E=H,e(8,E)})}function ut(H){as[H?"unshift":"push"](()=>{T=H,e(4,T)})}return r.$$set=H=>{"drawingEnabled"in H&&e(0,_=H.drawingEnabled),"image"in H&&e(25,v=H.image),"preferredDrawingMode"in H&&e(26,g=H.preferredDrawingMode),"state"in H&&e(27,b=H.state),"style"in H&&e(1,S=H.style),"toolName"in H&&e(2,R=H.toolName),"user"in H&&e(28,C=H.user),"visible"in H&&e(3,I=H.visible)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(15,{tool:i,opts:n}=_s(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)||g),r.$$.dirty[0]&16&&e(13,o=g_(T)),r.$$.dirty[0]&16&&e(12,{onPointerDown:a,onPointerUp:l}=__(T,L),a,(e(11,l),e(4,T))),r.$$.dirty[1]&4&&N(d.selected),r.$$.dirty[0]&32&&e(6,h=B?B.map(H=>({annotation:H,editor:fa(H.target.selector)})).filter(H=>H.editor):void 0),r.$$.dirty[0]&64&&e(10,c=H=>h&&h.some(mt=>mt.annotation.id===H.id))},[_,S,R,I,T,B,h,M,E,A,c,l,a,o,s,i,u,f,p,O,D,L,k,X,j,v,g,b,C,F,U,P,n,d,K,V,ut]}class P_ extends me{constructor(t){super(),pe(this,t,I_,C_,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 ru(r,t,e=0,i=r.length-1,n=R_){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));ru(r,t,f,p,n)}const s=r[t];let o=e,a=i;for(wn(r,e,t),n(r[i],s)>0&&wn(r,e,i);o<a;){for(wn(r,o,a),o++,a--;n(r[o],s)<0;)o++;for(;n(r[a],s)>0;)a--}n(r[e],s)===0?wn(r,e,a):(a++,wn(r,a,i)),a<=t&&(e=a+1),t<=a&&(i=a-1)}}function wn(r,t,e){const i=r[t];r[t]=r[e],r[e]=i}function R_(r,t){return r<t?-1:r>t?1:0}class M_{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):_a(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||_a(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=Bi([]),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=D_(t,i.children,e);if(c!==-1)return i.children.splice(c,1),s.push(i),this._condense(s),this}!h&&!i.leaf&&_a(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=Bi(t.slice(e,i+1)),Di(a,this.toBBox),a;n||(n=Math.ceil(Math.log(s)/Math.log(o)),o=Math.ceil(s/Math.pow(o,n-1))),a=Bi([]),a.leaf=!1,a.height=n;const l=Math.ceil(s/o),h=l*Math.ceil(Math.sqrt(o));iu(t,e,i,h,this.compareMinX);for(let c=e;c<=i;c+=h){const u=Math.min(c+h-1,i);iu(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 Di(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=ya(h),u=L_(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),Tn(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=Bi(i.children.splice(o,i.children.length-o));a.height=i.height,a.leaf=i.leaf,Di(i,this.toBBox),Di(a,this.toBBox),e?t[e-1].children.push(a):this._splitRoot(i,a)}_splitRoot(t,e){this.data=Bi([t,e]),this.data.height=t.height+1,this.data.leaf=!1,Di(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=En(t,0,a,this.toBBox),h=En(t,a,i,this.toBBox),c=N_(l,h),u=ya(l)+ya(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:B_,s=t.leaf?this.compareMinY:O_,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=En(t,0,e,s),a=En(t,i-e,i,s);let l=vs(o)+vs(a);for(let h=e;h<i-e;h++){const c=t.children[h];Tn(o,t.leaf?s(c):c),l+=vs(o)}for(let h=i-e-1;h>=e;h--){const c=t.children[h];Tn(a,t.leaf?s(c):c),l+=vs(a)}return l}_adjustParentBBoxes(t,e,i){for(let n=i;n>=0;n--)Tn(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():Di(t[e],this.toBBox)}}function D_(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 Di(r,t){En(r,0,r.children.length,t,r)}function En(r,t,e,i,n){n||(n=Bi(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];Tn(n,r.leaf?i(o):o)}return n}function Tn(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 B_(r,t){return r.minX-t.minX}function O_(r,t){return r.minY-t.minY}function ya(r){return(r.maxX-r.minX)*(r.maxY-r.minY)}function vs(r){return r.maxX-r.minX+(r.maxY-r.minY)}function L_(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 N_(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 _a(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 Bi(r){return{children:r,height:1,leaf:!0,minX:1/0,minY:1/0,maxX:-1/0,maxY:-1/0}}function iu(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;ru(r,o,t,e,n),s.push(t,o,o,e)}}const F_=()=>{const r=new M_,t=new Map,e=()=>[...t.values()],i=()=>{r.clear(),t.clear()},n=o=>{if(!ds(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(!ds(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(c=>c.selector.type===_t.RECTANGLE||jg(c.selector,o,a,l));return h.length>0?(h.sort((c,u)=>Ko(c.selector)-Ko(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(ds(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)}}},k_=r=>({...r,subscribe:t=>{const e=i=>t(i.state);return r.observe(e),t(r.all()),()=>r.unobserve(e)}}),nu=r=>{const t=Fy(),e=F_(),i=wy(t,r.userSelectAction,r.adapter),n=xy(t),s=$y();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}},U_=r=>{const t=nu(r);return{...t,store:k_(t.store)}},G_=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},su=r=>{const t=G_(r),e=t>.6?"dark":"light";return console.log(`[Annotorious] Image brightness: ${t.toFixed(1)}. Setting ${e} theme.`),e},ou=(r,t,e)=>t.setAttribute("data-theme",e==="auto"?su(r):e),au=(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}),lu=typeof navigator>"u"?!1:navigator.userAgent.indexOf("Mac OS X")!==-1,hu=(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=()=>{lu?e.removeEventListener("keydown",n):e.removeEventListener("keydown",i)};return lu?e.addEventListener("keydown",n):e.addEventListener("keydown",i),{destroy:s}},$_=(r,t={})=>{if(!r)throw"Missing argument: image";const e=typeof r=="string"?document.getElementById(r):r,i=au(t,{drawingEnabled:!0,drawingMode:"drag",userSelectAction:fc.EDIT,theme:"light"}),n=U_(i),{selection:s,store:o}=n,a=Gy(o,i.initialHistory),l=Hy(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=hu(a);let u=Qy();ou(e,h,i.theme);const d=new P_({target:h,props:{drawingEnabled:!!i.drawingEnabled,image:e,preferredDrawingMode:i.drawingMode,state:n,style:i.style,user:u}});d.$on("click",E=>{const{originalEvent:T,annotation:A}=E.detail;A?s.userSelect(A.id,T):s.isEmpty()||s.clear()});const f=Vy(n,a,i.adapter),p=()=>d.cancelDrawing(),m=()=>{d.$destroy(),h.parentNode.insertBefore(e,h),h.parentNode.removeChild(h),c.destroy(),a.destroy()},y=()=>d.getDrawingTool(),_=()=>u,v=()=>d.isDrawingEnabled(),g=(E,T,A)=>Xc(E,T,A),b=(E,T)=>Uc(E,T),S=E=>{if(!_s(E))throw`No drawing tool named ${E}`;d.$set({toolName:E})},R=E=>d.$set({drawingEnabled:E}),C=E=>d.$set({preferredDrawingMode:E}),I=E=>{console.warn("Filter not implemented yet")},M=E=>d.$set({style:E}),F=E=>ou(e,h,E),U=E=>{u=E,d.$set({user:E})},P=E=>d.$set({visible:E});return{...f,cancelDrawing:p,destroy:m,getDrawingTool:y,getUser:_,isDrawingEnabled:v,listDrawingTools:ys,on:l.on,off:l.off,registerDrawingTool:g,registerShapeEditor:b,setDrawingEnabled:R,setDrawingMode:C,setDrawingTool:S,setFilter:I,setStyle:M,setTheme:F,setUser:U,setVisible:P,element:h,state:n}};function Ft(){}function va(r,t){for(const e in t)r[e]=t[e];return r}function cu(r){return r()}function uu(){return Object.create(null)}function Fe(r){r.forEach(cu)}function Zt(r){return typeof r=="function"}function Ut(r,t){return r!=r?t==t:r!==t||r&&typeof r=="object"||typeof r=="function"}function H_(r){return Object.keys(r).length===0}function X_(r,...t){if(r==null){for(const i of t)i(void 0);return Ft}const e=r.subscribe(...t);return e.unsubscribe?()=>e.unsubscribe():e}function An(r,t,e){r.$$.on_destroy.push(X_(t,e))}function du(r,t,e,i){if(r){const n=fu(r,t,e,i);return r[0](n)}}function fu(r,t,e,i){return r[1]&&i?va(e.ctx.slice(),r[1](i(t))):e.ctx}function pu(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 mu(r,t,e,i,n,s){if(n){const o=fu(t,e,i,s);r.p(o,n)}}function gu(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 yu(r){const t={};for(const e in r)e[0]!=="$"&&(t[e]=r[e]);return t}function _u(r){return r??""}const ba=typeof window<"u"?window:typeof globalThis<"u"?globalThis:global;function Ct(r,t){r.appendChild(t)}function ot(r,t,e){r.insertBefore(t,e||null)}function st(r){r.parentNode&&r.parentNode.removeChild(r)}function Or(r,t){for(let e=0;e<r.length;e+=1)r[e]&&r[e].d(t)}function it(r){return document.createElementNS("http://www.w3.org/2000/svg",r)}function xa(r){return document.createTextNode(r)}function Se(){return xa(" ")}function Pe(){return xa("")}function Pt(r,t,e,i){return r.addEventListener(t,e,i),()=>r.removeEventListener(t,e,i)}function w(r,t,e){e==null?r.removeAttribute(t):r.getAttribute(t)!==e&&r.setAttribute(t,e)}function V_(r){return Array.from(r.childNodes)}function j_(r,t){t=""+t,r.data!==t&&(r.data=t)}function Lr(r,t,e){r.classList.toggle(t,!!e)}function W_(r,t,{bubbles:e=!1,cancelable:i=!1}={}){return new CustomEvent(r,{detail:t,bubbles:e,cancelable:i})}let Sn;function Cn(r){Sn=r}function wa(){if(!Sn)throw new Error("Function called outside component initialization");return Sn}function ii(r){wa().$$.on_mount.push(r)}function z_(r){wa().$$.on_destroy.push(r)}function Oi(){const r=wa();return(t,e,{cancelable:i=!1}={})=>{const n=r.$$.callbacks[t];if(n){const s=W_(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 Li=[],xs=[];let Ni=[];const vu=[],bu=Promise.resolve();let Ea=!1;function xu(){Ea||(Ea=!0,bu.then(Eu))}function wu(){return xu(),bu}function Ta(r){Ni.push(r)}const Aa=new Set;let Fi=0;function Eu(){if(Fi!==0)return;const r=Sn;do{try{for(;Fi<Li.length;){const t=Li[Fi];Fi++,Cn(t),Y_(t.$$)}}catch(t){throw Li.length=0,Fi=0,t}for(Cn(null),Li.length=0,Fi=0;xs.length;)xs.pop()();for(let t=0;t<Ni.length;t+=1){const e=Ni[t];Aa.has(e)||(Aa.add(e),e())}Ni.length=0}while(Li.length);for(;vu.length;)vu.pop()();Ea=!1,Aa.clear(),Cn(r)}function Y_(r){if(r.fragment!==null){r.update(),Fe(r.before_update);const t=r.dirty;r.dirty=[-1],r.fragment&&r.fragment.p(r.ctx,t),r.after_update.forEach(Ta)}}function q_(r){const t=[],e=[];Ni.forEach(i=>r.indexOf(i)===-1?t.push(i):e.push(i)),e.forEach(i=>i()),Ni=t}const ws=new Set;let ni;function le(){ni={r:0,c:[],p:ni}}function he(){ni.r||Fe(ni.c),ni=ni.p}function q(r,t){r&&r.i&&(ws.delete(r),r.i(t))}function at(r,t,e,i){if(r&&r.o){if(ws.has(r))return;ws.add(r),ni.c.push(()=>{ws.delete(r),i&&(e&&r.d(1),i())}),r.o(t)}else i&&i()}function xe(r){return(r==null?void 0:r.length)!==void 0?r:Array.from(r)}function Lt(r){r&&r.c()}function Bt(r,t,e){const{fragment:i,after_update:n}=r.$$;i&&i.m(t,e),Ta(()=>{const s=r.$$.on_mount.map(cu).filter(Zt);r.$$.on_destroy?r.$$.on_destroy.push(...s):Fe(s),r.$$.on_mount=[]}),n.forEach(Ta)}function Ot(r,t){const e=r.$$;e.fragment!==null&&(q_(e.after_update),Fe(e.on_destroy),e.fragment&&e.fragment.d(t),e.on_destroy=e.fragment=null,e.ctx=[])}function K_(r,t){r.$$.dirty[0]===-1&&(Li.push(r),xu(),r.$$.dirty.fill(0)),r.$$.dirty[t/31|0]|=1<<t%31}function jt(r,t,e,i,n,s,o=null,a=[-1]){const l=Sn;Cn(r);const h=r.$$={fragment:null,ctx:[],props:s,update:Ft,not_equal:n,bound:uu(),on_mount:[],on_destroy:[],on_disconnect:[],before_update:[],after_update:[],context:new Map(t.context||(l?l.$$.context:[])),callbacks:uu(),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&&K_(r,u)),d}):[],h.update(),c=!0,Fe(h.before_update),h.fragment=i?i(h.ctx):!1,t.target){if(t.hydrate){const u=V_(t.target);h.fragment&&h.fragment.l(u),u.forEach(st)}else h.fragment&&h.fragment.c();t.intro&&q(r.$$.fragment),Bt(r,t.target,t.anchor),Eu()}Cn(l)}class Wt{constructor(){Fh(this,"$$");Fh(this,"$$set")}$destroy(){Ot(this,1),this.$destroy=Ft}$on(t,e){if(!Zt(e))return Ft;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&&!H_(t)&&(this.$$.skip_bound=!0,this.$$set(t),this.$$.skip_bound=!1)}}const Z_="4";typeof window<"u"&&(window.__svelte||(window.__svelte={v:new Set})).v.add(Z_);var tr=(r=>(r.ELLIPSE="ELLIPSE",r.MULTIPOLYGON="MULTIPOLYGON",r.POLYGON="POLYGON",r.POLYLINE="POLYLINE",r.RECTANGLE="RECTANGLE",r.LINE="LINE",r))(tr||{}),In=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Sa(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Q_(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 Tu={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 m=e(a[p],a[l],a[h]);m>d&&(f=p,d=m)}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})()})(Tu);var J_=Tu.exports;const tv=Sa(J_),ki=(r,t)=>t,er=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},ev=(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},Au=(r,t=1)=>{const e=r.map(([i,n])=>({x:i,y:n}));return tv(e,t,!0).map(i=>[i.x,i.y])},rv=(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))},iv={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(tr.ELLIPSE,iv);const nv={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=rv([n,s],[o,a]);return l/h<=i}};ki(tr.LINE,nv);const sv={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}},As=r=>{const t=r.reduce((e,i)=>[...e,...i.rings[0].points],[]);return er(t)},Ui=r=>r.rings.map(e=>ev(e.points)).join(" "),ov=r=>r.polygons.reduce((t,e)=>[...t,...e.rings.reduce((i,n)=>[...i,...n.points],[])],[]),av=(r,t=1)=>{const e=r.geometry.polygons.map(n=>{const s=n.rings.map(a=>{const l=Au(a.points,t);return{...a,points:l}}),o=er(s[0].points);return{...n,rings:s,bounds:o}}),i=As(e);return{...r,geometry:{...r.geometry,polygons:e,bounds:i}}};ki(tr.MULTIPOLYGON,sv);const lv={area:r=>{const t=r.geometry.points;return Es(t)},intersects:(r,t,e)=>{const i=r.geometry.points;return Ts(i,t,e)}},hv=(r,t=1)=>{const e=Au(r.geometry.points,t),i=er(e);return{...r,geometry:{...r.geometry,bounds:i,points:e}}};ki(tr.POLYGON,lv);const cv={area:r=>{const t=r.geometry;if(!t.closed||t.points.length<3)return 0;const e=Su(t.points,t.closed);return Es(e)},intersects:(r,t,e,i=2)=>{const n=r.geometry;if(n.closed){const s=Su(n.points,n.closed);return Ts(s,t,e)}else return uv(n,[t,e],i)}},Su=(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=Cu(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},Cu=(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},uv=(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=Cu(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(Iu(t,a[l],a[l+1])<=e)return!0}else if(Iu(t,n.point,s.point)<=e)return!0}return!1},Iu=(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(tr.POLYLINE,cv);const dv={area:r=>r.geometry.w*r.geometry.h,intersects:(r,t,e)=>t>=r.geometry.x&&t<=r.geometry.x+r.geometry.w&&e>=r.geometry.y&&e<=r.geometry.y+r.geometry.h};ki(tr.RECTANGLE,dv);const _e=[];for(let r=0;r<256;++r)_e.push((r+256).toString(16).slice(1));function fv(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()}let Ca;const pv=new Uint8Array(16);function mv(){if(!Ca){if(typeof crypto>"u"||!crypto.getRandomValues)throw new Error("crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported");Ca=crypto.getRandomValues.bind(crypto)}return Ca(pv)}const Pu={randomUUID:typeof crypto<"u"&&crypto.randomUUID&&crypto.randomUUID.bind(crypto)};function gv(r,t,e){var n;r=r||{};const i=r.random??((n=r.rng)==null?void 0:n.call(r))??mv();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,fv(i)}function yv(r,t,e){return Pu.randomUUID&&!r?Pu.randomUUID():gv(r)}const _v=(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}},Ia=(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}},Nr=typeof window>"u"||typeof navigator>"u"?!1:"ontouchstart"in window||navigator.maxTouchPoints>0||navigator.msMaxTouchPoints>0,vv=r=>({}),Ru=r=>({grab:r[0]});function bv(r){let t,e,i,n;const s=r[8].default,o=du(s,r,r[7],Ru);return{c(){t=it("g"),o&&o.c(),w(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)&&mu(o,s,a,a[7],e?pu(s,a[7],l,vv):gu(a[7]),Ru)},i(a){e||(q(o,a),e=!0)},o(a){at(o,a),e=!1},d(a){a&&st(t),o&&o.d(a),i=!1,Fe(n)}}}function xv(r,t,e){let{$$slots:i={},$$scope:n}=t;const s=Oi();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:g,top:b}=h.getBoundingClientRect(),S=_.clientX-g,R=_.clientY-b;u=l.elementToImage(S,R)}else{const{offsetX:g,offsetY:b}=_;u=l.elementToImage(g,b)}d=o,_.target.setPointerCapture(_.pointerId),s("grab",_)},p=y=>{if(c){const[_,v]=l.elementToImage(y.offsetX,y.offsetY),g=[_-u[0],v-u[1]];e(3,o=a(d,c,g)),s("change",o)}},m=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,m,o,a,l,h,n,i]}class Pa extends Wt{constructor(t){super(),jt(this,t,xv,bv,Ut,{shape:3,editor:4,transform:5,svgEl:6})}}function wv(r){let t,e,i,n,s,o,a,l,h=r[3]&&Mu(r);return{c(){t=it("g"),e=it("circle"),h&&h.c(),n=it("circle"),w(e,"class","a9s-handle-buffer svelte-qtyc7s"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]+6/r[2]),w(e,"role","button"),w(e,"tabindex","0"),w(n,"class",s=_u(`a9s-handle-dot${r[3]?" selected":""}`)+" svelte-qtyc7s"),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[5]),w(t,"class",o=`a9s-handle ${r[8].class||""}`.trim())},m(c,u){ot(c,t,u),Ct(t,e),h&&h.m(t,null),Ct(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&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&36&&i!==(i=c[5]+6/c[2])&&w(e,"r",i),c[3]?h?h.p(c,u):(h=Mu(c),h.c(),h.m(t,n)):h&&(h.d(1),h=null),u&8&&s!==(s=_u(`a9s-handle-dot${c[3]?" selected":""}`)+" svelte-qtyc7s")&&w(n,"class",s),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&32&&w(n,"r",c[5]),u&256&&o!==(o=`a9s-handle ${c[8].class||""}`.trim())&&w(t,"class",o)},d(c){c&&st(t),h&&h.d(),a=!1,Fe(l)}}}function Ev(r){let t,e,i,n,s,o,a,l,h;return{c(){t=it("g"),e=it("circle"),n=it("circle"),o=it("circle"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=r[5]*10),w(e,"class","a9s-touch-halo"),Lr(e,"touched",r[4]),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",s=r[5]+10/r[2]),w(n,"class","a9s-handle-buffer svelte-qtyc7s"),w(n,"role","button"),w(n,"tabindex","0"),w(o,"class","a9s-handle-dot"),w(o,"cx",r[0]),w(o,"cy",r[1]),w(o,"r",a=r[5]+2/r[2]),w(t,"class","a9s-touch-handle")},m(c,u){ot(c,t,u),Ct(t,e),Ct(t,n),Ct(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&&w(e,"cx",c[0]),u&2&&w(e,"cy",c[1]),u&32&&i!==(i=c[5]*10)&&w(e,"r",i),u&16&&Lr(e,"touched",c[4]),u&1&&w(n,"cx",c[0]),u&2&&w(n,"cy",c[1]),u&36&&s!==(s=c[5]+10/c[2])&&w(n,"r",s),u&1&&w(o,"cx",c[0]),u&2&&w(o,"cy",c[1]),u&36&&a!==(a=c[5]+2/c[2])&&w(o,"r",a)},d(c){c&&st(t),l=!1,Fe(h)}}}function Mu(r){let t,e;return{c(){t=it("circle"),w(t,"class","a9s-handle-selected"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",e=r[5]+8/r[2])},m(i,n){ot(i,t,n)},p(i,n){n&1&&w(t,"cx",i[0]),n&2&&w(t,"cy",i[1]),n&36&&e!==(e=i[5]+8/i[2])&&w(t,"r",e)},d(i){i&&st(t)}}}function Tv(r){let t;function e(s,o){return Nr?Ev:wv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Av(r,t,e){let i,{x:n}=t,{y:s}=t,{scale:o}=t,{selected:a=void 0}=t,l=!1;const h=g=>{g.pointerType==="touch"&&e(4,l=!0)},c=()=>e(4,l=!1);function u(g){ae.call(this,r,g)}function d(g){ae.call(this,r,g)}function f(g){ae.call(this,r,g)}function p(g){ae.call(this,r,g)}function m(g){ae.call(this,r,g)}function y(g){ae.call(this,r,g)}function _(g){ae.call(this,r,g)}function v(g){ae.call(this,r,g)}return r.$$set=g=>{e(8,t=va(va({},t),yu(g))),"x"in g&&e(0,n=g.x),"y"in g&&e(1,s=g.y),"scale"in g&&e(2,o=g.scale),"selected"in g&&e(3,a=g.selected)},r.$$.update=()=>{r.$$.dirty&4&&e(5,i=4/o)},t=yu(t),[n,s,o,a,l,i,h,c,t,u,d,f,p,m,y,_,v]}class Gi extends Wt{constructor(t){super(),jt(this,t,Av,Tv,Ut,{x:0,y:1,scale:2,selected:3})}}function Sv(r){let t,e,i,n,s,o,a;return{c(){t=it("g"),e=it("circle"),n=it("circle"),s=it("circle"),w(e,"class","a9s-polygon-midpoint-buffer svelte-12ykj76"),w(e,"cx",r[0]),w(e,"cy",r[1]),w(e,"r",i=1.75*r[2]),w(n,"class","a9s-polygon-midpoint-outer svelte-12ykj76"),w(n,"cx",r[0]),w(n,"cy",r[1]),w(n,"r",r[2]),w(s,"class","a9s-polygon-midpoint-inner svelte-12ykj76"),w(s,"cx",r[0]),w(s,"cy",r[1]),w(s,"r",r[2]),w(t,"class","a9s-polygon-midpoint svelte-12ykj76")},m(l,h){ot(l,t,h),Ct(t,e),Ct(t,n),Ct(t,s),o||(a=[Pt(e,"pointerdown",r[5]),Pt(e,"pointerdown",r[3])],o=!0)},p(l,h){h&1&&w(e,"cx",l[0]),h&2&&w(e,"cy",l[1]),h&4&&i!==(i=1.75*l[2])&&w(e,"r",i),h&1&&w(n,"cx",l[0]),h&2&&w(n,"cy",l[1]),h&4&&w(n,"r",l[2]),h&1&&w(s,"cx",l[0]),h&2&&w(s,"cy",l[1]),h&4&&w(s,"r",l[2])},d(l){l&&st(t),o=!1,Fe(a)}}}function Cv(r){let t;return{c(){t=it("circle"),w(t,"cx",r[0]),w(t,"cy",r[1]),w(t,"r",r[2])},m(e,i){ot(e,t,i)},p(e,i){i&1&&w(t,"cx",e[0]),i&2&&w(t,"cy",e[1]),i&4&&w(t,"r",e[2])},d(e){e&&st(t)}}}function Iv(r){let t;function e(s,o){return Nr?Cv:Sv}let n=e()(r);return{c(){n.c(),t=Pe()},m(s,o){n.m(s,o),ot(s,t,o)},p(s,[o]){n.p(s,o)},i:Ft,o:Ft,d(s){s&&st(t),n.d(s)}}}function Pv(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 Du extends Wt{constructor(t){super(),jt(this,t,Pv,Iv,Ut,{x:0,y:1,scale:4})}}function Ra(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Bu(r,t,e){const i=r.slice();return i[28]=t[e],i[30]=e,i}function Ma(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Da(r){const t=r.slice(),e=t[10][t[6]];return t[28]=e.point,t}function Ou(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[28][0]),w(t,"cy",i=r[28][1]),w(t,"r",n=Pn/r[3]),w(t,"class","svelte-1h2slbm")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[28][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[28][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Pn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Lu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1h2slbm"),w(a,"cx",l=r[28][0]),w(a,"cy",h=r[28][1]),w(a,"r",c=Pn/r[3]),w(a,"class","svelte-1h2slbm"),w(t,"id",`${r[19]}-inner`),w(t,"class","a9s-polygon-editor-mask svelte-1h2slbm")},m(u,d){ot(u,t,d),Ct(t,e),Ct(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[28][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[28][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Pn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function Nu(r){let t,e;return t=new Gi({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(){Zt(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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Fu(r){let t,e;return t=new Du({props:{x:r[28][0],y:r[28][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[18](r[6]))&&r[18](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Rv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R=r[6]!==void 0&&!r[7]&&Ou(Da(r)),C=r[6]!==void 0&&!r[7]&&Lu(Ma(r)),I=xe(r[5].points),M=[];for(let P=0;P<I.length;P+=1)M[P]=Nu(Bu(r,I,P));const F=P=>at(M[P],1,1,()=>{M[P]=null});let U=r[6]!==void 0&&!r[7]&&Fu(Ra(r));return{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("polygon"),R&&R.c(),C&&C.c(),c=Se(),u=it("polygon"),f=Se(),p=it("polygon"),y=Se();for(let P=0;P<M.length;P+=1)M[P].c();_=Se(),U&&U.c(),v=Pe(),w(i,"x",n=r[9].x),w(i,"y",s=r[9].y),w(i,"width",o=r[9].w),w(i,"height",a=r[9].h),w(i,"class","svelte-1h2slbm"),w(l,"points",h=r[5].points.map(ku).join(" ")),w(l,"class","svelte-1h2slbm"),w(e,"id",`${r[19]}-outer`),w(e,"class","a9s-polygon-editor-mask svelte-1h2slbm"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[19]}-outer)`),w(u,"points",d=r[5].points.map(Uu).join(" ")),w(p,"class","a9s-inner a9s-shape-handle"),w(p,"mask",`url(#${r[19]}-inner)`),w(p,"style",r[1]),w(p,"points",m=r[5].points.map(Gu).join(" "))},m(P,E){ot(P,t,E),Ct(t,e),Ct(e,i),Ct(e,l),R&&R.m(e,null),C&&C.m(t,null),ot(P,c,E),ot(P,u,E),ot(P,f,E),ot(P,p,E),ot(P,y,E);for(let T=0;T<M.length;T+=1)M[T]&&M[T].m(P,E);ot(P,_,E),U&&U.m(P,E),ot(P,v,E),g=!0,b||(S=[Pt(u,"pointerup",r[14]),Pt(u,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)}),Pt(p,"pointermove",r[13]),Pt(p,"pointerup",r[14]),Pt(p,"pointerdown",function(){Zt(r[27]("SHAPE"))&&r[27]("SHAPE").apply(this,arguments)})],b=!0)},p(P,E){if(r=P,(!g||E[0]&512&&n!==(n=r[9].x))&&w(i,"x",n),(!g||E[0]&512&&s!==(s=r[9].y))&&w(i,"y",s),(!g||E[0]&512&&o!==(o=r[9].w))&&w(i,"width",o),(!g||E[0]&512&&a!==(a=r[9].h))&&w(i,"height",a),(!g||E[0]&32&&h!==(h=r[5].points.map(ku).join(" ")))&&w(l,"points",h),r[6]!==void 0&&!r[7]?R?R.p(Da(r),E):(R=Ou(Da(r)),R.c(),R.m(e,null)):R&&(R.d(1),R=null),r[6]!==void 0&&!r[7]?C?C.p(Ma(r),E):(C=Lu(Ma(r)),C.c(),C.m(t,null)):C&&(C.d(1),C=null),(!g||E[0]&32&&d!==(d=r[5].points.map(Uu).join(" ")))&&w(u,"points",d),(!g||E[0]&2)&&w(p,"style",r[1]),(!g||E[0]&32&&m!==(m=r[5].points.map(Gu).join(" ")))&&w(p,"points",m),E[0]&134322472){I=xe(r[5].points);let T;for(T=0;T<I.length;T+=1){const A=Bu(r,I,T);M[T]?(M[T].p(A,E),q(M[T],1)):(M[T]=Nu(A),M[T].c(),q(M[T],1),M[T].m(_.parentNode,_))}for(le(),T=I.length;T<M.length;T+=1)F(T);he()}r[6]!==void 0&&!r[7]?U?(U.p(Ra(r),E),E[0]&192&&q(U,1)):(U=Fu(Ra(r)),U.c(),q(U,1),U.m(v.parentNode,v)):U&&(le(),at(U,1,1,()=>{U=null}),he())},i(P){if(!g){for(let E=0;E<I.length;E+=1)q(M[E]);q(U),g=!0}},o(P){M=M.filter(Boolean);for(let E=0;E<M.length;E+=1)at(M[E]);at(U),g=!1},d(P){P&&(st(t),st(c),st(u),st(f),st(p),st(y),st(_),st(v)),R&&R.d(),C&&C.d(),Or(M,P),U&&U.d(P),b=!1,Fe(S)}}}function Mv(r){let t,e;return t=new Pa({props:{shape:r[0],transform:r[2],editor:r[17],svgEl:r[4],$$slots:{default:[Rv,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const Dv=250,Bv=1e3,Ov=12,Pn=4.5,ku=r=>r.join(","),Uu=r=>r.join(","),Gu=r=>r.join(",");function Lv(r,t,e){let i,n,s;const o=Oi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=T=>{if(m.length>0||!n.some(k=>k.visible)){e(6,d=void 0);return}const[A,O]=h.elementToImage(T.offsetX,T.offsetY),D=k=>Math.pow(k[0]-A,2)+Math.pow(k[1]-O,2),L=i.points.reduce((k,X)=>D(X)<D(k)?X:k),$=n.filter(k=>k.visible).reduce((k,X)=>D(X.point)<D(k.point)?X:k),B=Math.pow(Bv/c,2);D(L)<B||D($.point)<B?e(6,d=n.indexOf($)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=T=>{e(7,f=!0),T.preventDefault(),T.stopPropagation(),p=performance.now()},R=T=>A=>{if(!p||Nr||performance.now()-p>Dv)return;const O=m.includes(T);A.metaKey||A.ctrlKey||A.shiftKey?O?e(8,m=m.filter(D=>D!==T)):e(8,m=[...m,T]):O&&m.length>1?e(8,m=[T]):O?e(8,m=[]):e(8,m=[T]),g()},C=(T,A,O)=>{g();let D;const L=T.geometry;m.length>1?D=L.points.map(([B,N],k)=>m.includes(k)?[B+O[0],N+O[1]]:[B,N]):A==="SHAPE"?D=L.points.map(([B,N])=>[B+O[0],N+O[1]]):D=L.points.map(([B,N],k)=>A===`HANDLE-${k}`?[B+O[0],N+O[1]]:[B,N]);const $=er(D);return{...T,geometry:{points:D,bounds:$}}},I=T=>async A=>{A.stopPropagation();const O=[...i.points.slice(0,T+1),n[T].point,...i.points.slice(T+1)],D=er(O);o("change",{...a,geometry:{points:O,bounds:D}}),await wu();const L=[...document.querySelectorAll(".a9s-handle")][T+1];if(L!=null&&L.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});L.firstChild.dispatchEvent($)}},M=()=>{if(i.points.length-m.length<3)return;const T=i.points.filter((O,D)=>!m.includes(D)),A=er(T);o("change",{...a,geometry:{points:T,bounds:A}}),e(8,m=[])};ii(()=>{if(Nr)return;const T=A=>{(A.key==="Delete"||A.key==="Backspace")&&(A.preventDefault(),M())};return u.addEventListener("pointermove",v),u.addEventListener("keydown",T),()=>{u.removeEventListener("pointermove",v),u.removeEventListener("keydown",T)}});const F=`polygon-mask-${Math.random().toString(36).substring(2,12)}`;function U(T){ae.call(this,r,T)}function P(T){ae.call(this,r,T)}function E(T){ae.call(this,r,T)}return r.$$set=T=>{"shape"in T&&e(0,a=T.shape),"computedStyle"in T&&e(1,l=T.computedStyle),"transform"in T&&e(2,h=T.transform),"viewportScale"in T&&e(3,c=T.viewportScale),"svgEl"in T&&e(4,u=T.svgEl)},r.$$.update=()=>{r.$$.dirty[0]&1&&e(5,i=a.geometry),r.$$.dirty[0]&40&&e(10,n=Nr?[]:i.points.map((T,A)=>{const O=A===i.points.length-1?i.points[0]:i.points[A+1],D=(T[0]+O[0])/2,L=(T[1]+O[1])/2,B=Math.sqrt(Math.pow(O[0]-D,2)+Math.pow(O[1]-L,2))>Ov/c;return{point:[D,L],visible:B}})),r.$$.dirty[0]&40&&e(9,s=Ia(i.bounds,Pn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,v,b,S,R,C,I,F,U,P,E]}class Nv extends Wt{constructor(t){super(),jt(this,t,Lv,Mv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}function Fv(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v,g,b,S,R,C,I,M,F,U,P,E,T,A,O,D,L,$,B,N,k,X,j,K,V,ut,H,mt,Q,dt,gt,Et,Dt,Yt,Vt,et,$e,es;return Q=new Gi({props:{class:"a9s-corner-handle-topleft",x:r[5].x,y:r[5].y,scale:r[3]}}),Q.$on("pointerdown",function(){Zt(r[12]("TOP_LEFT"))&&r[12]("TOP_LEFT").apply(this,arguments)}),gt=new Gi({props:{class:"a9s-corner-handle-topright",x:r[5].x+r[5].w,y:r[5].y,scale:r[3]}}),gt.$on("pointerdown",function(){Zt(r[12]("TOP_RIGHT"))&&r[12]("TOP_RIGHT").apply(this,arguments)}),Dt=new Gi({props:{class:"a9s-corner-handle-bottomright",x:r[5].x+r[5].w,y:r[5].y+r[5].h,scale:r[3]}}),Dt.$on("pointerdown",function(){Zt(r[12]("BOTTOM_RIGHT"))&&r[12]("BOTTOM_RIGHT").apply(this,arguments)}),Vt=new Gi({props:{class:"a9s-corner-handle-bottomleft",x:r[5].x,y:r[5].y+r[5].h,scale:r[3]}}),Vt.$on("pointerdown",function(){Zt(r[12]("BOTTOM_LEFT"))&&r[12]("BOTTOM_LEFT").apply(this,arguments)}),{c(){t=it("defs"),e=it("mask"),i=it("rect"),l=it("rect"),f=Se(),p=it("rect"),g=Se(),b=it("rect"),M=Se(),F=it("rect"),T=Se(),A=it("rect"),$=Se(),B=it("rect"),j=Se(),K=it("rect"),mt=Se(),Lt(Q.$$.fragment),dt=Se(),Lt(gt.$$.fragment),Et=Se(),Lt(Dt.$$.fragment),Yt=Se(),Lt(Vt.$$.fragment),w(i,"class","rect-mask-bg svelte-1njczvj"),w(i,"x",n=r[6].x),w(i,"y",s=r[6].y),w(i,"width",o=r[6].w),w(i,"height",a=r[6].h),w(l,"class","rect-mask-fg svelte-1njczvj"),w(l,"x",h=r[5].x),w(l,"y",c=r[5].y),w(l,"width",u=r[5].w),w(l,"height",d=r[5].h),w(e,"id",r[8]),w(e,"class","a9s-rectangle-editor-mask svelte-1njczvj"),w(p,"class","a9s-outer"),w(p,"mask",`url(#${r[8]})`),w(p,"x",m=r[5].x),w(p,"y",y=r[5].y),w(p,"width",_=r[5].w),w(p,"height",v=r[5].h),w(b,"class","a9s-inner a9s-shape-handle"),w(b,"style",r[1]),w(b,"x",S=r[5].x),w(b,"y",R=r[5].y),w(b,"width",C=r[5].w),w(b,"height",I=r[5].h),w(F,"class","a9s-edge-handle a9s-edge-handle-top"),w(F,"x",U=r[5].x),w(F,"y",P=r[5].y),w(F,"height",1),w(F,"width",E=r[5].w),w(A,"class","a9s-edge-handle a9s-edge-handle-right"),w(A,"x",O=r[5].x+r[5].w),w(A,"y",D=r[5].y),w(A,"height",L=r[5].h),w(A,"width",1),w(B,"class","a9s-edge-handle a9s-edge-handle-bottom"),w(B,"x",N=r[5].x),w(B,"y",k=r[5].y+r[5].h),w(B,"height",1),w(B,"width",X=r[5].w),w(K,"class","a9s-edge-handle a9s-edge-handle-left"),w(K,"x",V=r[5].x),w(K,"y",ut=r[5].y),w(K,"height",H=r[5].h),w(K,"width",1)},m(Y,G){ot(Y,t,G),Ct(t,e),Ct(e,i),Ct(e,l),ot(Y,f,G),ot(Y,p,G),ot(Y,g,G),ot(Y,b,G),ot(Y,M,G),ot(Y,F,G),ot(Y,T,G),ot(Y,A,G),ot(Y,$,G),ot(Y,B,G),ot(Y,j,G),ot(Y,K,G),ot(Y,mt,G),Bt(Q,Y,G),ot(Y,dt,G),Bt(gt,Y,G),ot(Y,Et,G),Bt(Dt,Y,G),ot(Y,Yt,G),Bt(Vt,Y,G),et=!0,$e||(es=[Pt(p,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(b,"pointerdown",function(){Zt(r[12]("SHAPE"))&&r[12]("SHAPE").apply(this,arguments)}),Pt(F,"pointerdown",function(){Zt(r[12]("TOP"))&&r[12]("TOP").apply(this,arguments)}),Pt(A,"pointerdown",function(){Zt(r[12]("RIGHT"))&&r[12]("RIGHT").apply(this,arguments)}),Pt(B,"pointerdown",function(){Zt(r[12]("BOTTOM"))&&r[12]("BOTTOM").apply(this,arguments)}),Pt(K,"pointerdown",function(){Zt(r[12]("LEFT"))&&r[12]("LEFT").apply(this,arguments)})],$e=!0)},p(Y,G){r=Y,(!et||G&64&&n!==(n=r[6].x))&&w(i,"x",n),(!et||G&64&&s!==(s=r[6].y))&&w(i,"y",s),(!et||G&64&&o!==(o=r[6].w))&&w(i,"width",o),(!et||G&64&&a!==(a=r[6].h))&&w(i,"height",a),(!et||G&32&&h!==(h=r[5].x))&&w(l,"x",h),(!et||G&32&&c!==(c=r[5].y))&&w(l,"y",c),(!et||G&32&&u!==(u=r[5].w))&&w(l,"width",u),(!et||G&32&&d!==(d=r[5].h))&&w(l,"height",d),(!et||G&32&&m!==(m=r[5].x))&&w(p,"x",m),(!et||G&32&&y!==(y=r[5].y))&&w(p,"y",y),(!et||G&32&&_!==(_=r[5].w))&&w(p,"width",_),(!et||G&32&&v!==(v=r[5].h))&&w(p,"height",v),(!et||G&2)&&w(b,"style",r[1]),(!et||G&32&&S!==(S=r[5].x))&&w(b,"x",S),(!et||G&32&&R!==(R=r[5].y))&&w(b,"y",R),(!et||G&32&&C!==(C=r[5].w))&&w(b,"width",C),(!et||G&32&&I!==(I=r[5].h))&&w(b,"height",I),(!et||G&32&&U!==(U=r[5].x))&&w(F,"x",U),(!et||G&32&&P!==(P=r[5].y))&&w(F,"y",P),(!et||G&32&&E!==(E=r[5].w))&&w(F,"width",E),(!et||G&32&&O!==(O=r[5].x+r[5].w))&&w(A,"x",O),(!et||G&32&&D!==(D=r[5].y))&&w(A,"y",D),(!et||G&32&&L!==(L=r[5].h))&&w(A,"height",L),(!et||G&32&&N!==(N=r[5].x))&&w(B,"x",N),(!et||G&32&&k!==(k=r[5].y+r[5].h))&&w(B,"y",k),(!et||G&32&&X!==(X=r[5].w))&&w(B,"width",X),(!et||G&32&&V!==(V=r[5].x))&&w(K,"x",V),(!et||G&32&&ut!==(ut=r[5].y))&&w(K,"y",ut),(!et||G&32&&H!==(H=r[5].h))&&w(K,"height",H);const Sr={};G&32&&(Sr.x=r[5].x),G&32&&(Sr.y=r[5].y),G&8&&(Sr.scale=r[3]),Q.$set(Sr);const Cr={};G&32&&(Cr.x=r[5].x+r[5].w),G&32&&(Cr.y=r[5].y),G&8&&(Cr.scale=r[3]),gt.$set(Cr);const Ir={};G&32&&(Ir.x=r[5].x+r[5].w),G&32&&(Ir.y=r[5].y+r[5].h),G&8&&(Ir.scale=r[3]),Dt.$set(Ir);const Pr={};G&32&&(Pr.x=r[5].x),G&32&&(Pr.y=r[5].y+r[5].h),G&8&&(Pr.scale=r[3]),Vt.$set(Pr)},i(Y){et||(q(Q.$$.fragment,Y),q(gt.$$.fragment,Y),q(Dt.$$.fragment,Y),q(Vt.$$.fragment,Y),et=!0)},o(Y){at(Q.$$.fragment,Y),at(gt.$$.fragment,Y),at(Dt.$$.fragment,Y),at(Vt.$$.fragment,Y),et=!1},d(Y){Y&&(st(t),st(f),st(p),st(g),st(b),st(M),st(F),st(T),st(A),st($),st(B),st(j),st(K),st(mt),st(dt),st(Et),st(Yt)),Ot(Q,Y),Ot(gt,Y),Ot(Dt,Y),Ot(Vt,Y),$e=!1,Fe(es)}}}function kv(r){let t,e;return t=new Pa({props:{shape:r[0],transform:r[2],editor:r[7],svgEl:r[4],$$slots:{default:[Fv,({grab:i})=>({12:i}),({grab:i})=>i?4096:0]},$$scope:{ctx:r}}}),t.$on("grab",r[9]),t.$on("change",r[10]),t.$on("release",r[11]),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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&12394&&(s.$$scope={dirty:n,ctx:i}),t.$set(s)},i(i){e||(q(t.$$.fragment,i),e=!0)},o(i){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Uv(r,t,e){let i,n,{shape:s}=t,{computedStyle:o}=t,{transform:a}=t,{viewportScale:l=1}=t,{svgEl:h}=t;const c=(m,y,_)=>{const v=m.geometry.bounds;let[g,b]=[v.minX,v.minY],[S,R]=[v.maxX,v.maxY];const[C,I]=_;if(y==="SHAPE")g+=C,S+=C,b+=I,R+=I;else{switch(y){case"TOP":case"TOP_LEFT":case"TOP_RIGHT":{b+=I;break}case"BOTTOM":case"BOTTOM_LEFT":case"BOTTOM_RIGHT":{R+=I;break}}switch(y){case"LEFT":case"TOP_LEFT":case"BOTTOM_LEFT":{g+=C;break}case"RIGHT":case"TOP_RIGHT":case"BOTTOM_RIGHT":{S+=C;break}}}const M=Math.min(g,S),F=Math.min(b,R),U=Math.abs(S-g),P=Math.abs(R-b);return{...m,geometry:{x:M,y:F,w:U,h:P,bounds:{minX:M,minY:F,maxX:M+U,maxY:F+P}}}},u=`rect-mask-${Math.random().toString(36).substring(2,12)}`;function d(m){ae.call(this,r,m)}function f(m){ae.call(this,r,m)}function p(m){ae.call(this,r,m)}return r.$$set=m=>{"shape"in m&&e(0,s=m.shape),"computedStyle"in m&&e(1,o=m.computedStyle),"transform"in m&&e(2,a=m.transform),"viewportScale"in m&&e(3,l=m.viewportScale),"svgEl"in m&&e(4,h=m.svgEl)},r.$$.update=()=>{r.$$.dirty&1&&e(5,i=s.geometry),r.$$.dirty&40&&e(6,n=Ia(i.bounds,2/l))},[s,o,a,l,h,i,n,c,u,d,f,p]}class Gv extends Wt{constructor(t){super(),jt(this,t,Uv,kv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4})}}var $u=Object.prototype.hasOwnProperty;function Ba(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--&&Ba(r[i],t[i]););return i===-1}if(!e||typeof r=="object"){i=0;for(e in r)if($u.call(r,e)&&++i&&!$u.call(t,e)||!(e in t)||!Ba(r[e],t[e]))return!1;return Object.keys(t).length===i}}return r!==r&&t!==t}const $v=12,Hv=(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))>$v/t;return{point:[f,p],visible:y,elementIdx:n,ringIdx:l,pointIdx:u}});return[...o,...h]},[]);return[...e,...s]},[]);function Oa(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Hu(r,t,e){const i=r.slice();return i[30]=t[e],i[32]=e,i}function Xu(r,t,e){const i=r.slice();return i[33]=t[e],i[35]=e,i}function Vu(r,t,e){const i=r.slice();return i[29]=t[e],i[37]=e,i}function La(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function Na(r){const t=r.slice(),e=t[10][t[6]];return t[29]=e.point,t}function ju(r){let t,e,i,n;return{c(){t=it("circle"),w(t,"cx",e=r[29][0]),w(t,"cy",i=r[29][1]),w(t,"r",n=Rn/r[3]),w(t,"class","svelte-1vxo6dc")},m(s,o){ot(s,t,o)},p(s,o){o[0]&1088&&e!==(e=s[29][0])&&w(t,"cx",e),o[0]&1088&&i!==(i=s[29][1])&&w(t,"cy",i),o[0]&8&&n!==(n=Rn/s[3])&&w(t,"r",n)},d(s){s&&st(t)}}}function Wu(r){let t,e,i,n,s,o,a,l,h,c;return{c(){t=it("mask"),e=it("rect"),a=it("circle"),w(e,"x",i=r[9].x),w(e,"y",n=r[9].y),w(e,"width",s=r[9].w),w(e,"height",o=r[9].h),w(e,"class","svelte-1vxo6dc"),w(a,"cx",l=r[29][0]),w(a,"cy",h=r[29][1]),w(a,"r",c=Rn/r[3]),w(a,"class","svelte-1vxo6dc"),w(t,"id",`${r[18]}-${r[32]}-inner`),w(t,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc")},m(u,d){ot(u,t,d),Ct(t,e),Ct(t,a)},p(u,d){d[0]&512&&i!==(i=u[9].x)&&w(e,"x",i),d[0]&512&&n!==(n=u[9].y)&&w(e,"y",n),d[0]&512&&s!==(s=u[9].w)&&w(e,"width",s),d[0]&512&&o!==(o=u[9].h)&&w(e,"height",o),d[0]&1088&&l!==(l=u[29][0])&&w(a,"cx",l),d[0]&1088&&h!==(h=u[29][1])&&w(a,"cy",h),d[0]&8&&c!==(c=Rn/u[3])&&w(a,"r",c)},d(u){u&&st(t)}}}function zu(r){let t,e;function i(...n){return r[19](r[32],r[35],r[37],...n)}return t=new Gi({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(){Zt(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){Bt(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){at(t.$$.fragment,n),e=!1},d(n){Ot(t,n)}}}function Yu(r){let t,e,i=xe(r[33].points),n=[];for(let o=0;o<i.length;o+=1)n[o]=zu(Vu(r,i,o));const s=o=>at(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},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=xe(o[33].points);let l;for(l=0;l<i.length;l+=1){const h=Vu(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=zu(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)at(n[a]);e=!1},d(o){o&&st(t),Or(n,o)}}}function qu(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v=r[6]!==void 0&&!r[7]&&ju(Na(r)),g=r[6]!==void 0&&!r[7]&&Wu(La(r)),b=xe(r[30].rings),S=[];for(let C=0;C<b.length;C+=1)S[C]=Yu(Xu(r,b,C));const R=C=>at(S[C],1,1,()=>{S[C]=null});return{c(){t=it("g"),e=it("defs"),i=it("mask"),n=it("rect"),h=it("path"),v&&v.c(),g&&g.c(),u=it("path"),f=it("path");for(let C=0;C<S.length;C+=1)S[C].c();w(n,"x",s=r[9].x),w(n,"y",o=r[9].y),w(n,"width",a=r[9].w),w(n,"height",l=r[9].h),w(n,"class","svelte-1vxo6dc"),w(h,"d",c=Ui(r[30])),w(h,"class","svelte-1vxo6dc"),w(i,"id",`${r[18]}-${r[32]}-outer`),w(i,"class","a9s-multipolygon-editor-mask svelte-1vxo6dc"),w(u,"class","a9s-outer"),w(u,"mask",`url(#${r[18]}-${r[32]}-outer)`),w(u,"fill-rule","evenodd"),w(u,"d",d=Ui(r[30])),w(f,"class","a9s-inner"),w(f,"mask",`url(#${r[18]}-${r[32]}-inner)`),w(f,"style",r[1]),w(f,"fill-rule","evenodd"),w(f,"d",p=Ui(r[30]))},m(C,I){ot(C,t,I),Ct(t,e),Ct(e,i),Ct(i,n),Ct(i,h),v&&v.m(i,null),g&&g.m(e,null),Ct(t,u),Ct(t,f);for(let M=0;M<S.length;M+=1)S[M]&&S[M].m(t,null);m=!0,y||(_=[Pt(u,"pointerup",r[13]),Pt(u,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)}),Pt(f,"pointerup",r[13]),Pt(f,"pointerdown",function(){Zt(r[28]("SHAPE"))&&r[28]("SHAPE").apply(this,arguments)})],y=!0)},p(C,I){if(r=C,(!m||I[0]&512&&s!==(s=r[9].x))&&w(n,"x",s),(!m||I[0]&512&&o!==(o=r[9].y))&&w(n,"y",o),(!m||I[0]&512&&a!==(a=r[9].w))&&w(n,"width",a),(!m||I[0]&512&&l!==(l=r[9].h))&&w(n,"height",l),(!m||I[0]&32&&c!==(c=Ui(r[30])))&&w(h,"d",c),r[6]!==void 0&&!r[7]?v?v.p(Na(r),I):(v=ju(Na(r)),v.c(),v.m(i,null)):v&&(v.d(1),v=null),r[6]!==void 0&&!r[7]?g?g.p(La(r),I):(g=Wu(La(r)),g.c(),g.m(e,null)):g&&(g.d(1),g=null),(!m||I[0]&32&&d!==(d=Ui(r[30])))&&w(u,"d",d),(!m||I[0]&2)&&w(f,"style",r[1]),(!m||I[0]&32&&p!==(p=Ui(r[30])))&&w(f,"d",p),I[0]&268491048){b=xe(r[30].rings);let M;for(M=0;M<b.length;M+=1){const F=Xu(r,b,M);S[M]?(S[M].p(F,I),q(S[M],1)):(S[M]=Yu(F),S[M].c(),q(S[M],1),S[M].m(t,null))}for(le(),M=b.length;M<S.length;M+=1)R(M);he()}},i(C){if(!m){for(let I=0;I<b.length;I+=1)q(S[I]);m=!0}},o(C){S=S.filter(Boolean);for(let I=0;I<S.length;I+=1)at(S[I]);m=!1},d(C){C&&st(t),v&&v.d(),g&&g.d(),Or(S,C),y=!1,Fe(_)}}}function Ku(r){let t,e;return t=new Du({props:{x:r[29][0],y:r[29][1],scale:r[3]}}),t.$on("pointerdown",function(){Zt(r[17](r[6]))&&r[17](r[6]).apply(this,arguments)}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Xv(r){let t,e,i,n=xe(r[5].polygons),s=[];for(let l=0;l<n.length;l+=1)s[l]=qu(Hu(r,n,l));const o=l=>at(s[l],1,1,()=>{s[l]=null});let a=r[6]!==void 0&&!r[7]&&Ku(Oa(r));return{c(){for(let l=0;l<s.length;l+=1)s[l].c();t=Se(),a&&a.c(),e=Pe()},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=xe(l[5].polygons);let c;for(c=0;c<n.length;c+=1){const u=Hu(l,n,c);s[c]?(s[c].p(u,h),q(s[c],1)):(s[c]=qu(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(Oa(l),h),h[0]&192&&q(a,1)):(a=Ku(Oa(l)),a.c(),q(a,1),a.m(e.parentNode,e)):a&&(le(),at(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)at(s[h]);at(a),i=!1},d(l){l&&(st(t),st(e)),Or(s,l),a&&a.d(l)}}}function Vv(r){let t,e;return t=new Pa({props:{shape:r[0],transform:r[2],editor:r[16],svgEl:r[4],$$slots:{default:[Xv,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}const jv=250,Wv=1e3,Rn=4.5;function zv(r,t,e){let i,n,s;const o=Oi();let{shape:a}=t,{computedStyle:l}=t,{transform:h}=t,{viewportScale:c=1}=t,{svgEl:u}=t,d,f=!1,p,m=[];const y=()=>e(7,f=!0),_=()=>e(7,f=!1),v=A=>{if(m.length>0||!n.some(X=>X.visible)){e(6,d=void 0);return}const[O,D]=h.elementToImage(A.offsetX,A.offsetY),L=X=>Math.pow(X[0]-O,2)+Math.pow(X[1]-D,2),$=ov(i).reduce((X,j)=>L(j)<L(X)?j:X),B=n.filter(X=>X.visible).reduce((X,j)=>L(j.point)<L(X.point)?j:X),N=Math.pow(Wv/c,2);L($)<N||L(B.point)<N?e(6,d=n.indexOf(B)):e(6,d=void 0)},g=()=>{document.activeElement!==u&&u.focus()},b=()=>{e(8,m=[]),g()},S=A=>{e(7,f=!0),A.preventDefault(),A.stopPropagation(),p=performance.now()},R=(A,O,D)=>L=>{if(!p||Nr||performance.now()-p>jv)return;const $=N=>N.polygon===A&&N.ring===O&&N.point===D,B=m.some($);L.metaKey||L.ctrlKey||L.shiftKey?B?e(8,m=m.filter(N=>!$(N))):e(8,m=[...m,{polygon:A,ring:O,point:D}]):B&&m.length>1?e(8,m=[{polygon:A,ring:O,point:D}]):B?e(8,m=[]):e(8,m=[{polygon:A,ring:O,point:D}]),g()},C=(A,O,D)=>{g();const L=A.geometry.polygons;let $;if(O==="SHAPE")$=L.map(B=>{const N=B.rings.map((X,j)=>({points:X.points.map((V,ut)=>[V[0]+D[0],V[1]+D[1]])})),k=er(N[0].points);return{rings:N,bounds:k}});else{const[B,N,k,X]=O.split("-").map(j=>parseInt(j));$=L.map((j,K)=>{if(K===N){const V=j.rings.map((H,mt)=>mt===k?{points:H.points.map((dt,gt)=>gt===X?[dt[0]+D[0],dt[1]+D[1]]:dt)}:H),ut=er(V[0].points);return{rings:V,bounds:ut}}else return j})}return{...A,geometry:{polygons:$,bounds:As($)}}},I=A=>async O=>{O.stopPropagation();const D=n[A],L=i.polygons.map((B,N)=>{if(N===D.elementIdx){const k=B.rings.map((j,K)=>K===D.ringIdx?{points:[...j.points.slice(0,D.pointIdx+1),D.point,...j.points.slice(D.pointIdx+1)]}:j),X=er(k[0].points);return{rings:k,bounds:X}}else return B});o("change",{...a,geometry:{polygons:L,bounds:As(L)}}),await wu();const $=[...document.querySelectorAll(".a9s-handle")][A+1];if($!=null&&$.firstChild){const B=new PointerEvent("pointerdown",{bubbles:!0,cancelable:!0,clientX:O.clientX,clientY:O.clientY,pointerId:O.pointerId,pointerType:O.pointerType,isPrimary:O.isPrimary,buttons:O.buttons});$.firstChild.dispatchEvent(B)}},M=()=>{const A=i.polygons.map((D,L)=>{if(m.some(B=>B.polygon===L)){const B=D.rings.map((k,X)=>{const j=m.filter(K=>K.polygon===L&&K.ring===X);return j.length&&k.points.length-j.length>=3?{points:k.points.filter((V,ut)=>!j.some(H=>H.point===ut))}:k}),N=er(B[0].points);return{rings:B,bounds:N}}else return D});!Ba(i.polygons,A)&&(o("change",{...a,geometry:{polygons:A,bounds:As(A)}}),e(8,m=[]))};ii(()=>{if(Nr)return;const A=O=>{(O.key==="Delete"||O.key==="Backspace")&&(O.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,O,D,{polygon:L,ring:$,point:B})=>L===A&&$===O&&B===D;function P(A){ae.call(this,r,A)}function E(A){ae.call(this,r,A)}function T(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=Nr?[]:Hv(i,c)),r.$$.dirty[0]&40&&e(9,s=Ia(i.bounds,Rn/c))},[a,l,h,c,u,i,d,f,m,s,n,y,_,b,S,R,C,I,F,U,P,E,T]}class Yv extends Wt{constructor(t){super(),jt(this,t,zv,Vv,Ut,{shape:0,computedStyle:1,transform:2,viewportScale:3,svgEl:4},null,[-1,-1])}}tr.RECTANGLE,tr.POLYGON,tr.MULTIPOLYGON;function qv(r,t,e){let i;const n=Oi();let{annotation:s}=t,{editor:o}=t,{style:a}=t,{target:l}=t,{transform:h}=t,{viewportScale:c}=t,u;return ii(()=>(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=_v(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 Kv extends Wt{constructor(t){super(),jt(this,t,qv,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 si=(r=>(r[r.WEBGL_LEGACY=0]="WEBGL_LEGACY",r[r.WEBGL=1]="WEBGL",r[r.WEBGL2=2]="WEBGL2",r))(si||{}),Zu=(r=>(r[r.UNKNOWN=0]="UNKNOWN",r[r.WEBGL=1]="WEBGL",r[r.CANVAS=2]="CANVAS",r))(Zu||{}),Fa=(r=>(r[r.COLOR=16384]="COLOR",r[r.DEPTH=256]="DEPTH",r[r.STENCIL=1024]="STENCIL",r))(Fa||{}),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||{}),rr=(r=>(r[r.POINTS=0]="POINTS",r[r.LINES=1]="LINES",r[r.LINE_LOOP=2]="LINE_LOOP",r[r.LINE_STRIP=3]="LINE_STRIP",r[r.TRIANGLES=4]="TRIANGLES",r[r.TRIANGLE_STRIP=5]="TRIANGLE_STRIP",r[r.TRIANGLE_FAN=6]="TRIANGLE_FAN",r))(rr||{}),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||{}),$i=(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))($i||{}),pt=(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))(pt||{}),J=(r=>(r[r.FLOAT=0]="FLOAT",r[r.INT=1]="INT",r[r.UINT=2]="UINT",r))(J||{}),gr=(r=>(r[r.NEAREST=0]="NEAREST",r[r.LINEAR=1]="LINEAR",r))(gr||{}),Fr=(r=>(r[r.CLAMP=33071]="CLAMP",r[r.REPEAT=10497]="REPEAT",r[r.MIRRORED_REPEAT=33648]="MIRRORED_REPEAT",r))(Fr||{}),ir=(r=>(r[r.OFF=0]="OFF",r[r.POW2=1]="POW2",r[r.ON=2]="ON",r[r.ON_MANUAL=3]="ON_MANUAL",r))(ir||{}),Re=(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))(Re||{}),nr=(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))(nr||{}),ka=(r=>(r[r.AUTO=0]="AUTO",r[r.MANUAL=1]="MANUAL",r))(ka||{}),ke=(r=>(r.LOW="lowp",r.MEDIUM="mediump",r.HIGH="highp",r))(ke||{}),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||{}),ee=(r=>(r[r.NONE=0]="NONE",r[r.LOW=2]="LOW",r[r.MEDIUM=4]="MEDIUM",r[r.HIGH=8]="HIGH",r))(ee||{}),sr=(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))(sr||{});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 Ua=/iPhone/i,Qu=/iPod/i,Ju=/iPad/i,td=/\biOS-universal(?:.+)Mac\b/i,Ga=/\bAndroid(?:.+)Mobile\b/i,ed=/Android/i,Hi=/(?:SD4930UR|\bSilk(?:.+)Mobile\b)/i,Ss=/Silk/i,yr=/Windows Phone/i,rd=/\bWindows(?:.+)ARM\b/i,id=/BlackBerry/i,nd=/BB10/i,sd=/Opera Mini/i,od=/\b(CriOS|Chrome)(?:.+)Mobile/i,ad=/Mobile(?:.+)Firefox\b/i,ld=function(r){return typeof r<"u"&&r.platform==="MacIntel"&&typeof r.maxTouchPoints=="number"&&r.maxTouchPoints>1&&typeof MSStream>"u"};function Zv(r){return function(t){return t.test(r)}}function hd(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=Zv(e),s={apple:{phone:n(Ua)&&!n(yr),ipod:n(Qu),tablet:!n(Ua)&&(n(Ju)||ld(t))&&!n(yr),universal:n(td),device:(n(Ua)||n(Qu)||n(Ju)||n(td)||ld(t))&&!n(yr)},amazon:{phone:n(Hi),tablet:!n(Hi)&&n(Ss),device:n(Hi)||n(Ss)},android:{phone:!n(yr)&&n(Hi)||!n(yr)&&n(Ga),tablet:!n(yr)&&!n(Hi)&&!n(Ga)&&(n(Ss)||n(ed)),device:!n(yr)&&(n(Hi)||n(Ss)||n(Ga)||n(ed))||n(/\bokhttp\b/i)},windows:{phone:n(yr),tablet:n(rd),device:n(yr)||n(rd)},other:{blackberry:n(id),blackberry10:n(nd),opera:n(sd),firefox:n(ad),chrome:n(od),device:n(id)||n(nd)||n(sd)||n(ad)||n(od)},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 Qv=hd.default??hd,_r=Qv(globalThis.navigator);tt.RETINA_PREFIX=/@([0-9\.]+)x/,tt.FAIL_IF_MAJOR_PERFORMANCE_CAVEAT=!1;var cd={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 m=e?e+h:h;if(!this._events[m])return!1;var y=this._events[m],_=arguments.length,v,g;if(y.fn){switch(y.once&&this.removeListener(h,y.fn,void 0,!0),_){case 1:return y.fn.call(y.context),!0;case 2:return y.fn.call(y.context,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(g=1,v=new Array(_-1);g<_;g++)v[g-1]=arguments[g];y.fn.apply(y.context,v)}else{var b=y.length,S;for(g=0;g<b;g++)switch(y[g].once&&this.removeListener(h,y[g].fn,void 0,!0),_){case 1:y[g].fn.call(y[g].context);break;case 2:y[g].fn.call(y[g].context,c);break;case 3:y[g].fn.call(y[g].context,c,u);break;case 4:y[g].fn.call(y[g].context,c,u,d);break;default:if(!v)for(S=1,v=new Array(_-1);S<_;S++)v[S-1]=arguments[S];y[g].fn.apply(y[g].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 m=0,y=[],_=p.length;m<_;m++)(p[m].fn!==c||d&&!p[m].once||u&&p[m].context!==u)&&y.push(p[m]);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})(cd);var Jv=cd.exports;const Mn=Sa(Jv);var $a={exports:{}};$a.exports=Cs,$a.exports.default=Cs;function Cs(r,t,e){e=e||2;var i=t&&t.length,n=i?t[0]*e:r.length,s=ud(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=n1(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 Dn(s,o,e,a,l,f,0),o}function ud(r,t,e,i,n){var s,o;if(n===Va(r,t,e,i)>0)for(s=t;s<e;s+=i)o=pd(s,r[s],r[s+1],o);else for(s=e-i;s>=t;s-=i)o=pd(s,r[s],r[s+1],o);return o&&Is(o,o.next)&&(On(o),o=o.next),o}function oi(r,t){if(!r)return r;t||(t=r);var e=r,i;do if(i=!1,!e.steiner&&(Is(e,e.next)||$t(e.prev,e,e.next)===0)){if(On(e),e=t=e.prev,e===e.next)break;i=!0}else e=e.next;while(i||e!==t);return t}function Dn(r,t,e,i,n,s,o){if(r){!o&&s&&h1(r,i,n,s);for(var a=r,l,h;r.prev!==r.next;){if(l=r.prev,h=r.next,s?e1(r,i,n,s):t1(r)){t.push(l.i/e|0),t.push(r.i/e|0),t.push(h.i/e|0),On(r),r=h.next,a=h.next;continue}if(r=h,r===a){o?o===1?(r=r1(oi(r),t,e),Dn(r,t,e,i,n,s,2)):o===2&&i1(r,t,e,i,n,s):Dn(oi(r),t,e,i,n,s,1);break}}}}function t1(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&&Xi(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 e1(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,m=a>l?a>h?a:h:l>h?l:h,y=c>u?c>d?c:d:u>d?u:d,_=Ha(f,p,t,e,i),v=Ha(m,y,t,e,i),g=r.prevZ,b=r.nextZ;g&&g.z>=_&&b&&b.z<=v;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&Xi(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0||(g=g.prevZ,b.x>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&Xi(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0))return!1;b=b.nextZ}for(;g&&g.z>=_;){if(g.x>=f&&g.x<=m&&g.y>=p&&g.y<=y&&g!==n&&g!==o&&Xi(a,c,l,u,h,d,g.x,g.y)&&$t(g.prev,g,g.next)>=0)return!1;g=g.prevZ}for(;b&&b.z<=v;){if(b.x>=f&&b.x<=m&&b.y>=p&&b.y<=y&&b!==n&&b!==o&&Xi(a,c,l,u,h,d,b.x,b.y)&&$t(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function r1(r,t,e){var i=r;do{var n=i.prev,s=i.next.next;!Is(n,s)&&dd(n,i,i.next,s)&&Bn(n,s)&&Bn(s,n)&&(t.push(n.i/e|0),t.push(i.i/e|0),t.push(s.i/e|0),On(i),On(i.next),i=r=s),i=i.next}while(i!==r);return oi(i)}function i1(r,t,e,i,n,s){var o=r;do{for(var a=o.next.next;a!==o.prev;){if(o.i!==a.i&&d1(o,a)){var l=fd(o,a);o=oi(o,o.next),l=oi(l,l.next),Dn(o,t,e,i,n,s,0),Dn(l,t,e,i,n,s,0);return}a=a.next}o=o.next}while(o!==r)}function n1(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=ud(r,a,l,i,!1),h===h.next&&(h.steiner=!0),n.push(u1(h));for(n.sort(s1),s=0;s<n.length;s++)e=o1(n[s],e);return e}function s1(r,t){return r.x-t.x}function o1(r,t){var e=a1(r,t);if(!e)return t;var i=fd(e,r);return oi(i,i.next),oi(e,e.next)}function a1(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&&Xi(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),Bn(e,r)&&(d<u||d===u&&(e.x>o.x||e.x===o.x&&l1(o,e)))&&(o=e,u=d)),e=e.next;while(e!==l);return o}function l1(r,t){return $t(r.prev,r,t.prev)<0&&$t(t.next,r,r.next)<0}function h1(r,t,e,i){var n=r;do n.z===0&&(n.z=Ha(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,c1(n)}function c1(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 Ha(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 u1(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 Xi(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 d1(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!f1(r,t)&&(Bn(r,t)&&Bn(t,r)&&p1(r,t)&&($t(r.prev,r,t.prev)||$t(r,t.prev,t))||Is(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 Is(r,t){return r.x===t.x&&r.y===t.y}function dd(r,t,e,i){var n=Rs($t(r,t,e)),s=Rs($t(r,t,i)),o=Rs($t(e,i,r)),a=Rs($t(e,i,t));return!!(n!==s&&o!==a||n===0&&Ps(r,e,t)||s===0&&Ps(r,i,t)||o===0&&Ps(e,r,i)||a===0&&Ps(e,t,i))}function Ps(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 Rs(r){return r>0?1:r<0?-1:0}function f1(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&&dd(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Bn(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 p1(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 fd(r,t){var e=new Xa(r.i,r.x,r.y),i=new Xa(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 pd(r,t,e,i){var n=new Xa(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 On(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 Xa(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}Cs.deviation=function(r,t,e,i){var n=t&&t.length,s=n?t[0]*e:r.length,o=Math.abs(Va(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(Va(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 Va(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}Cs.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 m1=$a.exports;const g1=Sa(m1);var Ms={exports:{}};/*! https://mths.be/punycode v1.4.1 by @mathias */Ms.exports,function(r,t){(function(e){var i=t&&!t.nodeType&&t,n=r&&!r.nodeType&&r,s=typeof In=="object"&&In;(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,m="-",y=/^xn--/,_=/[^\x20-\x7E]/,v=/[\x2E\u3002\uFF0E\uFF61]/g,g={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},b=l-h,S=Math.floor,R=String.fromCharCode,C;function I(B){throw new RangeError(g[B])}function M(B,N){for(var k=B.length,X=[];k--;)X[k]=N(B[k]);return X}function F(B,N){var k=B.split("@"),X="";k.length>1&&(X=k[0]+"@",B=k[1]),B=B.replace(v,".");var j=B.split("."),K=M(j,N).join(".");return X+K}function U(B){for(var N=[],k=0,X=B.length,j,K;k<X;)j=B.charCodeAt(k++),j>=55296&&j<=56319&&k<X?(K=B.charCodeAt(k++),(K&64512)==56320?N.push(((j&1023)<<10)+(K&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 E(B){return B-48<10?B-22:B-65<26?B-65:B-97<26?B-97:l}function T(B,N){return B+22+75*(B<26)-((N!=0)<<5)}function A(B,N,k){var X=0;for(B=k?S(B/d):B>>1,B+=S(B/N);B>b*c>>1;X+=l)B=S(B/b);return S(X+(b+1)*B/(B+u))}function O(B){var N=[],k=B.length,X,j=0,K=p,V=f,ut,H,mt,Q,dt,gt,Et,Dt,Yt;for(ut=B.lastIndexOf(m),ut<0&&(ut=0),H=0;H<ut;++H)B.charCodeAt(H)>=128&&I("not-basic"),N.push(B.charCodeAt(H));for(mt=ut>0?ut+1:0;mt<k;){for(Q=j,dt=1,gt=l;mt>=k&&I("invalid-input"),Et=E(B.charCodeAt(mt++)),(Et>=l||Et>S((a-j)/dt))&&I("overflow"),j+=Et*dt,Dt=gt<=V?h:gt>=V+c?c:gt-V,!(Et<Dt);gt+=l)Yt=l-Dt,dt>S(a/Yt)&&I("overflow"),dt*=Yt;X=N.length+1,V=A(j-Q,X,Q==0),S(j/X)>a-K&&I("overflow"),K+=S(j/X),j%=X,N.splice(j++,0,K)}return P(N)}function D(B){var N,k,X,j,K,V,ut,H,mt,Q,dt,gt=[],Et,Dt,Yt,Vt;for(B=U(B),Et=B.length,N=p,k=0,K=f,V=0;V<Et;++V)dt=B[V],dt<128&&gt.push(R(dt));for(X=j=gt.length,j&&gt.push(m);X<Et;){for(ut=a,V=0;V<Et;++V)dt=B[V],dt>=N&&dt<ut&&(ut=dt);for(Dt=X+1,ut-N>S((a-k)/Dt)&&I("overflow"),k+=(ut-N)*Dt,N=ut,V=0;V<Et;++V)if(dt=B[V],dt<N&&++k>a&&I("overflow"),dt==N){for(H=k,mt=l;Q=mt<=K?h:mt>=K+c?c:mt-K,!(H<Q);mt+=l)Vt=H-Q,Yt=l-Q,gt.push(R(T(Q+Vt%Yt,0))),H=S(Vt/Yt);gt.push(R(T(H,0))),K=A(k,Dt,X==j),k=0,++X}++k,++N}return gt.join("")}function L(B){return F(B,function(N){return y.test(N)?O(N.slice(4).toLowerCase()):N})}function $(B){return F(B,function(N){return _.test(N)?"xn--"+D(N):N})}if(o={version:"1.4.1",ucs2:{decode:U,encode:P},decode:O,encode:D,toASCII:$,toUnicode:L},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})(In)}(Ms,Ms.exports);var y1=Ms.exports,Vi=TypeError;const _1=Q_(Object.freeze(Object.defineProperty({__proto__:null,default:{}},Symbol.toStringTag,{value:"Module"})));var ja=typeof Map=="function"&&Map.prototype,Wa=Object.getOwnPropertyDescriptor&&ja?Object.getOwnPropertyDescriptor(Map.prototype,"size"):null,Ds=ja&&Wa&&typeof Wa.get=="function"?Wa.get:null,md=ja&&Map.prototype.forEach,za=typeof Set=="function"&&Set.prototype,Ya=Object.getOwnPropertyDescriptor&&za?Object.getOwnPropertyDescriptor(Set.prototype,"size"):null,Bs=za&&Ya&&typeof Ya.get=="function"?Ya.get:null,gd=za&&Set.prototype.forEach,v1=typeof WeakMap=="function"&&WeakMap.prototype,Ln=v1?WeakMap.prototype.has:null,b1=typeof WeakSet=="function"&&WeakSet.prototype,Nn=b1?WeakSet.prototype.has:null,x1=typeof WeakRef=="function"&&WeakRef.prototype,yd=x1?WeakRef.prototype.deref:null,w1=Boolean.prototype.valueOf,E1=Object.prototype.toString,T1=Function.prototype.toString,A1=String.prototype.match,qa=String.prototype.slice,kr=String.prototype.replace,S1=String.prototype.toUpperCase,_d=String.prototype.toLowerCase,vd=RegExp.prototype.test,bd=Array.prototype.concat,or=Array.prototype.join,C1=Array.prototype.slice,xd=Math.floor,Ka=typeof BigInt=="function"?BigInt.prototype.valueOf:null,Za=Object.getOwnPropertySymbols,Qa=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?Symbol.prototype.toString:null,ji=typeof Symbol=="function"&&typeof Symbol.iterator=="object",Fn=typeof Symbol=="function"&&Symbol.toStringTag&&(typeof Symbol.toStringTag===ji||!0)?Symbol.toStringTag:null,wd=Object.prototype.propertyIsEnumerable,Ed=(typeof Reflect=="function"?Reflect.getPrototypeOf:Object.getPrototypeOf)||([].__proto__===Array.prototype?function(r){return r.__proto__}:null);function Td(r,t){if(r===1/0||r===-1/0||r!==r||r&&r>-1e3&&r<1e3||vd.call(/e/,t))return t;var e=/[0-9](?=(?:[0-9]{3})+(?![0-9]))/g;if(typeof r=="number"){var i=r<0?-xd(-r):xd(r);if(i!==r){var n=String(i),s=qa.call(t,n.length+1);return kr.call(n,e,"$&_")+"."+kr.call(kr.call(s,/([0-9]{3})/g,"$&_"),/_$/,"")}}return kr.call(t,e,"$&_")}var Ja=_1,Ad=Ja.custom,Sd=Rd(Ad)?Ad:null,Cd={__proto__:null,double:'"',single:"'"},I1={__proto__:null,double:/(["\\])/g,single:/(['\\])/g},Os=function r(t,e,i,n){var s=e||{};if(vr(s,"quoteStyle")&&!vr(Cd,s.quoteStyle))throw new TypeError('option "quoteStyle" must be "single" or "double"');if(vr(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=vr(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(vr(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(vr(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 Dd(t,s);if(typeof t=="number"){if(t===0)return 1/0/t>0?"0":"-0";var l=String(t);return a?Td(t,l):l}if(typeof t=="bigint"){var h=String(t)+"n";return a?Td(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 tl(t)?"[Array]":"[Object]";var u=W1(s,i);if(typeof n>"u")n=[];else if(Md(n,t)>=0)return"[Circular]";function d(E,T,A){if(T&&(n=C1.call(n),n.push(T)),A){var O={depth:s.depth};return vr(s,"quoteStyle")&&(O.quoteStyle=s.quoteStyle),r(E,O,i+1,n)}return r(E,s,i+1,n)}if(typeof t=="function"&&!Pd(t)){var f=F1(t),p=Ls(t,d);return"[Function"+(f?": "+f:" (anonymous)")+"]"+(p.length>0?" { "+or.call(p,", ")+" }":"")}if(Rd(t)){var m=ji?kr.call(String(t),/^(Symbol\(.*\))_[^)]*$/,"$1"):Qa.call(t);return typeof t=="object"&&!ji?kn(m):m}if(X1(t)){for(var y="<"+_d.call(String(t.nodeName)),_=t.attributes||[],v=0;v<_.length;v++)y+=" "+_[v].name+"="+Id(P1(_[v].value),"double",s);return y+=">",t.childNodes&&t.childNodes.length&&(y+="..."),y+="</"+_d.call(String(t.nodeName))+">",y}if(tl(t)){if(t.length===0)return"[]";var g=Ls(t,d);return u&&!j1(g)?"["+rl(g,u)+"]":"[ "+or.call(g,", ")+" ]"}if(M1(t)){var b=Ls(t,d);return!("cause"in Error.prototype)&&"cause"in t&&!wd.call(t,"cause")?"{ ["+String(t)+"] "+or.call(bd.call("[cause]: "+d(t.cause),b),", ")+" }":b.length===0?"["+String(t)+"]":"{ ["+String(t)+"] "+or.call(b,", ")+" }"}if(typeof t=="object"&&o){if(Sd&&typeof t[Sd]=="function"&&Ja)return Ja(t,{depth:c-i});if(o!=="symbol"&&typeof t.inspect=="function")return t.inspect()}if(k1(t)){var S=[];return md&&md.call(t,function(E,T){S.push(d(T,t,!0)+" => "+d(E,t))}),Bd("Map",Ds.call(t),S,u)}if($1(t)){var R=[];return gd&&gd.call(t,function(E){R.push(d(E,t))}),Bd("Set",Bs.call(t),R,u)}if(U1(t))return el("WeakMap");if(H1(t))return el("WeakSet");if(G1(t))return el("WeakRef");if(B1(t))return kn(d(Number(t)));if(L1(t))return kn(d(Ka.call(t)));if(O1(t))return kn(w1.call(t));if(D1(t))return kn(d(String(t)));if(typeof window<"u"&&t===window)return"{ [object Window] }";if(typeof globalThis<"u"&&t===globalThis||typeof In<"u"&&t===In)return"{ [object globalThis] }";if(!R1(t)&&!Pd(t)){var C=Ls(t,d),I=Ed?Ed(t)===Object.prototype:t instanceof Object||t.constructor===Object,M=t instanceof Object?"":"null prototype",F=!I&&Fn&&Object(t)===t&&Fn in t?qa.call(Ur(t),8,-1):M?"Object":"",U=I||typeof t.constructor!="function"?"":t.constructor.name?t.constructor.name+" ":"",P=U+(F||M?"["+or.call(bd.call([],F||[],M||[]),": ")+"] ":"");return C.length===0?P+"{}":u?P+"{"+rl(C,u)+"}":P+"{ "+or.call(C,", ")+" }"}return String(t)};function Id(r,t,e){var i=e.quoteStyle||t,n=Cd[i];return n+r+n}function P1(r){return kr.call(String(r),/"/g,"&quot;")}function ai(r){return!Fn||!(typeof r=="object"&&(Fn in r||typeof r[Fn]<"u"))}function tl(r){return Ur(r)==="[object Array]"&&ai(r)}function R1(r){return Ur(r)==="[object Date]"&&ai(r)}function Pd(r){return Ur(r)==="[object RegExp]"&&ai(r)}function M1(r){return Ur(r)==="[object Error]"&&ai(r)}function D1(r){return Ur(r)==="[object String]"&&ai(r)}function B1(r){return Ur(r)==="[object Number]"&&ai(r)}function O1(r){return Ur(r)==="[object Boolean]"&&ai(r)}function Rd(r){if(ji)return r&&typeof r=="object"&&r instanceof Symbol;if(typeof r=="symbol")return!0;if(!r||typeof r!="object"||!Qa)return!1;try{return Qa.call(r),!0}catch{}return!1}function L1(r){if(!r||typeof r!="object"||!Ka)return!1;try{return Ka.call(r),!0}catch{}return!1}var N1=Object.prototype.hasOwnProperty||function(r){return r in this};function vr(r,t){return N1.call(r,t)}function Ur(r){return E1.call(r)}function F1(r){if(r.name)return r.name;var t=A1.call(T1.call(r),/^function\s*([\w$]+)/);return t?t[1]:null}function Md(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 k1(r){if(!Ds||!r||typeof r!="object")return!1;try{Ds.call(r);try{Bs.call(r)}catch{return!0}return r instanceof Map}catch{}return!1}function U1(r){if(!Ln||!r||typeof r!="object")return!1;try{Ln.call(r,Ln);try{Nn.call(r,Nn)}catch{return!0}return r instanceof WeakMap}catch{}return!1}function G1(r){if(!yd||!r||typeof r!="object")return!1;try{return yd.call(r),!0}catch{}return!1}function $1(r){if(!Bs||!r||typeof r!="object")return!1;try{Bs.call(r);try{Ds.call(r)}catch{return!0}return r instanceof Set}catch{}return!1}function H1(r){if(!Nn||!r||typeof r!="object")return!1;try{Nn.call(r,Nn);try{Ln.call(r,Ln)}catch{return!0}return r instanceof WeakSet}catch{}return!1}function X1(r){return!r||typeof r!="object"?!1:typeof HTMLElement<"u"&&r instanceof HTMLElement?!0:typeof r.nodeName=="string"&&typeof r.getAttribute=="function"}function Dd(r,t){if(r.length>t.maxStringLength){var e=r.length-t.maxStringLength,i="... "+e+" more character"+(e>1?"s":"");return Dd(qa.call(r,0,t.maxStringLength),t)+i}var n=I1[t.quoteStyle||"single"];n.lastIndex=0;var s=kr.call(kr.call(r,n,"\\$1"),/[\x00-\x1f]/g,V1);return Id(s,"single",t)}function V1(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":"")+S1.call(t.toString(16))}function kn(r){return"Object("+r+")"}function el(r){return r+" { ? }"}function Bd(r,t,e,i){var n=i?rl(e,i):or.call(e,", ");return r+" ("+t+") {"+n+"}"}function j1(r){for(var t=0;t<r.length;t++)if(Md(r[t],`
2
2
  `)>=0)return!1;return!0}function W1(r,t){var e;if(r.indent===" ")e=" ";else if(typeof r.indent=="number"&&r.indent>0)e=or.call(Array(r.indent+1)," ");else return null;return{base:e,prev:or.call(Array(t+1),e)}}function rl(r,t){if(r.length===0)return"";var e=`
3
3
  `+t.prev+t.base;return e+or.call(r,","+e)+`
4
- `+t.prev}function Ls(r,t){var e=tl(r),i=[];if(e){i.length=r.length;for(var n=0;n<r.length;n++)i[n]=vr(r,n)?t(r[n],r):""}var s=typeof Za=="function"?Za(r):[],o;if(ji){o={};for(var a=0;a<s.length;a++)o["$"+s[a]]=s[a]}for(var l in r)vr(r,l)&&(e&&String(Number(l))===l&&l<r.length||ji&&o["$"+l]instanceof Symbol||(vd.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof Za=="function")for(var h=0;h<s.length;h++)wd.call(r,s[h])&&i.push("["+t(s[h])+"]: "+t(r[s[h]],r));return i}var z1=Os,Y1=Vi,Ns=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},q1=function(r,t){if(r){var e=Ns(r,t);return e&&e.value}},K1=function(r,t,e){var i=Ns(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},Z1=function(r,t){return r?!!Ns(r,t):!1},Q1=function(r,t){if(r)return Ns(r,t,!0)},J1=function(){var t,e={assert:function(i){if(!e.has(i))throw new Y1("Side channel does not contain "+z1(i))},delete:function(i){var n=t&&t.next,s=Q1(t,i);return s&&n&&n===s&&(t=void 0),!!s},get:function(i){return q1(t,i)},has:function(i){return Z1(t,i)},set:function(i,n){t||(t={next:void 0}),K1(t,i,n)}};return e},Od=Object,tb=Error,eb=EvalError,rb=RangeError,ib=ReferenceError,nb=SyntaxError,sb=URIError,ob=Math.abs,ab=Math.floor,lb=Math.max,hb=Math.min,cb=Math.pow,ub=Math.round,db=Number.isNaN||function(t){return t!==t},fb=db,pb=function(t){return fb(t)||t===0?t:t<0?-1:1},mb=Object.getOwnPropertyDescriptor,Fs=mb;if(Fs)try{Fs([],"length")}catch{Fs=null}var Ld=Fs,ks=Object.defineProperty||!1;if(ks)try{ks({},"a",{value:1})}catch{ks=!1}var gb=ks,il,Nd;function yb(){return Nd||(Nd=1,il=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}),il}var nl,Fd;function _b(){if(Fd)return nl;Fd=1;var r=typeof Symbol<"u"&&Symbol,t=yb();return nl=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},nl}var sl,kd;function Ud(){return kd||(kd=1,sl=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),sl}var ol,Gd;function $d(){if(Gd)return ol;Gd=1;var r=Od;return ol=r.getPrototypeOf||null,ol}var al,Hd;function vb(){if(Hd)return al;Hd=1;var r="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,e=Math.max,i="[object Function]",n=function(l,h){for(var c=[],u=0;u<l.length;u+=1)c[u]=l[u];for(var d=0;d<h.length;d+=1)c[d+l.length]=h[d];return c},s=function(l,h){for(var c=[],u=h,d=0;u<l.length;u+=1,d+=1)c[d]=l[u];return c},o=function(a,l){for(var h="",c=0;c<a.length;c+=1)h+=a[c],c+1<a.length&&(h+=l);return h};return al=function(l){var h=this;if(typeof h!="function"||t.apply(h)!==i)throw new TypeError(r+h);for(var c=s(arguments,1),u,d=function(){if(this instanceof u){var _=h.apply(this,n(c,arguments));return Object(_)===_?_:this}return h.apply(l,n(c,arguments))},f=e(0,h.length-c.length),p=[],m=0;m<f;m++)p[m]="$"+m;if(u=Function("binder","return function ("+o(p,",")+"){ return binder.apply(this,arguments); }")(d),h.prototype){var y=function(){};y.prototype=h.prototype,u.prototype=new y,y.prototype=null}return u},al}var ll,Xd;function Us(){if(Xd)return ll;Xd=1;var r=vb();return ll=Function.prototype.bind||r,ll}var hl,Vd;function cl(){return Vd||(Vd=1,hl=Function.prototype.call),hl}var ul,jd;function Wd(){return jd||(jd=1,ul=Function.prototype.apply),ul}var bb=typeof Reflect<"u"&&Reflect&&Reflect.apply,xb=Us(),wb=Wd(),Eb=cl(),Tb=bb,Ab=Tb||xb.call(Eb,wb),Sb=Us(),Cb=Vi,Ib=cl(),Pb=Ab,zd=function(t){if(t.length<1||typeof t[0]!="function")throw new Cb("a function is required");return Pb(Sb,Ib,t)},dl,Yd;function Rb(){if(Yd)return dl;Yd=1;var r=zd,t=Ld,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 dl=i&&typeof i.get=="function"?r([i.get]):typeof s=="function"?function(a){return s(a==null?a:n(a))}:!1,dl}var fl,qd;function Mb(){if(qd)return fl;qd=1;var r=Ud(),t=$d(),e=Rb();return fl=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,fl}var pl,Kd;function Db(){if(Kd)return pl;Kd=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=Us();return pl=e.call(r,t),pl}var Tt,Bb=Od,Ob=tb,Lb=eb,Nb=rb,Fb=ib,Wi=nb,zi=Vi,kb=sb,Ub=ob,Gb=ab,$b=lb,Hb=hb,Xb=cb,Vb=ub,jb=pb,Zd=Function,ml=function(r){try{return Zd('"use strict"; return ('+r+").constructor;")()}catch{}},Un=Ld,Wb=gb,gl=function(){throw new zi},zb=Un?function(){try{return arguments.callee,gl}catch{try{return Un(arguments,"callee").get}catch{return gl}}}():gl,Yi=_b()(),ce=Mb(),Yb=$d(),qb=Ud(),Qd=Wd(),Gn=cl(),qi={},Kb=typeof Uint8Array>"u"||!ce?Tt:ce(Uint8Array),li={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?Tt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?Tt:ArrayBuffer,"%ArrayIteratorPrototype%":Yi&&ce?ce([][Symbol.iterator]()):Tt,"%AsyncFromSyncIteratorPrototype%":Tt,"%AsyncFunction%":qi,"%AsyncGenerator%":qi,"%AsyncGeneratorFunction%":qi,"%AsyncIteratorPrototype%":qi,"%Atomics%":typeof Atomics>"u"?Tt:Atomics,"%BigInt%":typeof BigInt>"u"?Tt:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?Tt:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?Tt:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?Tt:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Ob,"%eval%":eval,"%EvalError%":Lb,"%Float16Array%":typeof Float16Array>"u"?Tt:Float16Array,"%Float32Array%":typeof Float32Array>"u"?Tt:Float32Array,"%Float64Array%":typeof Float64Array>"u"?Tt:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?Tt:FinalizationRegistry,"%Function%":Zd,"%GeneratorFunction%":qi,"%Int8Array%":typeof Int8Array>"u"?Tt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?Tt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?Tt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Yi&&ce?ce(ce([][Symbol.iterator]())):Tt,"%JSON%":typeof JSON=="object"?JSON:Tt,"%Map%":typeof Map>"u"?Tt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Yi||!ce?Tt:ce(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Bb,"%Object.getOwnPropertyDescriptor%":Un,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?Tt:Promise,"%Proxy%":typeof Proxy>"u"?Tt:Proxy,"%RangeError%":Nb,"%ReferenceError%":Fb,"%Reflect%":typeof Reflect>"u"?Tt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?Tt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Yi||!ce?Tt:ce(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?Tt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Yi&&ce?ce(""[Symbol.iterator]()):Tt,"%Symbol%":Yi?Symbol:Tt,"%SyntaxError%":Wi,"%ThrowTypeError%":zb,"%TypedArray%":Kb,"%TypeError%":zi,"%Uint8Array%":typeof Uint8Array>"u"?Tt:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?Tt:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?Tt:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?Tt:Uint32Array,"%URIError%":kb,"%WeakMap%":typeof WeakMap>"u"?Tt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?Tt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?Tt:WeakSet,"%Function.prototype.call%":Gn,"%Function.prototype.apply%":Qd,"%Object.defineProperty%":Wb,"%Object.getPrototypeOf%":Yb,"%Math.abs%":Ub,"%Math.floor%":Gb,"%Math.max%":$b,"%Math.min%":Hb,"%Math.pow%":Xb,"%Math.round%":Vb,"%Math.sign%":jb,"%Reflect.getPrototypeOf%":qb};if(ce)try{null.error}catch(r){var Zb=ce(ce(r));li["%Error.prototype%"]=Zb}var Qb=function r(t){var e;if(t==="%AsyncFunction%")e=ml("async function () {}");else if(t==="%GeneratorFunction%")e=ml("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=ml("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 li[t]=e,e},Jd={__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"]},$n=Us(),Gs=Db(),Jb=$n.call(Gn,Array.prototype.concat),tx=$n.call(Qd,Array.prototype.splice),tf=$n.call(Gn,String.prototype.replace),$s=$n.call(Gn,String.prototype.slice),ex=$n.call(Gn,RegExp.prototype.exec),rx=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,ix=/\\(\\)?/g,nx=function(t){var e=$s(t,0,1),i=$s(t,-1);if(e==="%"&&i!=="%")throw new Wi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new Wi("invalid intrinsic syntax, expected opening `%`");var n=[];return tf(t,rx,function(s,o,a,l){n[n.length]=a?tf(l,ix,"$1"):o||s}),n},sx=function(t,e){var i=t,n;if(Gs(Jd,i)&&(n=Jd[i],i="%"+n[0]+"%"),Gs(li,i)){var s=li[i];if(s===qi&&(s=Qb(i)),typeof s>"u"&&!e)throw new zi("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:s}}throw new Wi("intrinsic "+t+" does not exist!")},yl=function(t,e){if(typeof t!="string"||t.length===0)throw new zi("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new zi('"allowMissing" argument must be a boolean');if(ex(/^%?[^%]*%?$/,t)===null)throw new Wi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=nx(t),n=i.length>0?i[0]:"",s=sx("%"+n+"%",e),o=s.name,a=s.value,l=!1,h=s.alias;h&&(n=h[0],tx(i,Jb([0,1],h)));for(var c=1,u=!0;c<i.length;c+=1){var d=i[c],f=$s(d,0,1),p=$s(d,-1);if((f==='"'||f==="'"||f==="`"||p==='"'||p==="'"||p==="`")&&f!==p)throw new Wi("property names with quotes must have matching quotes");if((d==="constructor"||!u)&&(l=!0),n+="."+d,o="%"+n+"%",Gs(li,o))a=li[o];else if(a!=null){if(!(d in a)){if(!e)throw new zi("base intrinsic for "+t+" exists, but the property is not available.");return}if(Un&&c+1>=i.length){var m=Un(a,d);u=!!m,u&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else u=Gs(a,d),a=a[d];u&&!l&&(li[o]=a)}}return a},ef=yl,rf=zd,ox=rf([ef("%String.prototype.indexOf%")]),nf=function(t,e){var i=ef(t,!!e);return typeof i=="function"&&ox(t,".prototype.")>-1?rf([i]):i},ax=yl,Hn=nf,lx=Os,hx=Vi,sf=ax("%Map%",!0),cx=Hn("Map.prototype.get",!0),ux=Hn("Map.prototype.set",!0),dx=Hn("Map.prototype.has",!0),fx=Hn("Map.prototype.delete",!0),px=Hn("Map.prototype.size",!0),of=!!sf&&function(){var t,e={assert:function(i){if(!e.has(i))throw new hx("Side channel does not contain "+lx(i))},delete:function(i){if(t){var n=fx(t,i);return px(t)===0&&(t=void 0),n}return!1},get:function(i){if(t)return cx(t,i)},has:function(i){return t?dx(t,i):!1},set:function(i,n){t||(t=new sf),ux(t,i,n)}};return e},mx=yl,Hs=nf,gx=Os,Xs=of,yx=Vi,Ki=mx("%WeakMap%",!0),_x=Hs("WeakMap.prototype.get",!0),vx=Hs("WeakMap.prototype.set",!0),bx=Hs("WeakMap.prototype.has",!0),xx=Hs("WeakMap.prototype.delete",!0),wx=Ki?function(){var t,e,i={assert:function(n){if(!i.has(n))throw new yx("Side channel does not contain "+gx(n))},delete:function(n){if(Ki&&n&&(typeof n=="object"||typeof n=="function")){if(t)return xx(t,n)}else if(Xs&&e)return e.delete(n);return!1},get:function(n){return Ki&&n&&(typeof n=="object"||typeof n=="function")&&t?_x(t,n):e&&e.get(n)},has:function(n){return Ki&&n&&(typeof n=="object"||typeof n=="function")&&t?bx(t,n):!!e&&e.has(n)},set:function(n,s){Ki&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new Ki),vx(t,n,s)):Xs&&(e||(e=Xs()),e.set(n,s))}};return i}:Xs,Ex=Vi,Tx=Os,Ax=J1,Sx=of,Cx=wx,Ix=Cx||Sx||Ax,Px=function(){var t,e={assert:function(i){if(!e.has(i))throw new Ex("Side channel does not contain "+Tx(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=Ix()),t.set(i,n)}};return e},Rx=String.prototype.replace,Mx=/%20/g,_l={RFC1738:"RFC1738",RFC3986:"RFC3986"},vl={default:_l.RFC3986,formatters:{RFC1738:function(r){return Rx.call(r,Mx,"+")},RFC3986:function(r){return String(r)}},RFC1738:_l.RFC1738,RFC3986:_l.RFC3986},Dx=vl,bl=Object.prototype.hasOwnProperty,hi=Array.isArray,ar=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),Bx=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(hi(i)){for(var n=[],s=0;s<i.length;++s)typeof i[s]<"u"&&n.push(i[s]);e.obj[e.prop]=n}}},af=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},Ox=function r(t,e,i){if(!e)return t;if(typeof e!="object"&&typeof e!="function"){if(hi(t))t.push(e);else if(t&&typeof t=="object")(i&&(i.plainObjects||i.allowPrototypes)||!bl.call(Object.prototype,e))&&(t[e]=!0);else return[t,e];return t}if(!t||typeof t!="object")return[t].concat(e);var n=t;return hi(t)&&!hi(e)&&(n=af(t,i)),hi(t)&&hi(e)?(e.forEach(function(s,o){if(bl.call(t,o)){var a=t[o];a&&typeof a=="object"&&s&&typeof s=="object"?t[o]=r(a,s,i):t.push(s)}else t[o]=s}),t):Object.keys(e).reduce(function(s,o){var a=e[o];return bl.call(s,o)?s[o]=r(s[o],a,i):s[o]=a,s},n)},Lx=function(t,e){return Object.keys(e).reduce(function(i,n){return i[n]=e[n],i},t)},Nx=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}},xl=1024,Fx=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+=xl){for(var h=o.length>=xl?o.slice(l,l+xl):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===Dx.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=ar[d];continue}if(d<2048){c[c.length]=ar[192|d>>6]+ar[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=ar[224|d>>12]+ar[128|d>>6&63]+ar[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=ar[240|d>>18]+ar[128|d>>12&63]+ar[128|d>>6&63]+ar[128|d&63]}a+=c.join("")}return a},kx=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.push({obj:o,prop:h}),i.push(c))}return Bx(e),t},Ux=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},Gx=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},$x=function(t,e){return[].concat(t,e)},Hx=function(t,e){if(hi(t)){for(var i=[],n=0;n<t.length;n+=1)i.push(e(t[n]));return i}return e(t)},lf={arrayToObject:af,assign:Lx,combine:$x,compact:kx,decode:Nx,encode:Fx,isBuffer:Gx,isRegExp:Ux,maybeMap:Hx,merge:Ox},hf=Px,Vs=lf,Xn=vl,Xx=Object.prototype.hasOwnProperty,cf={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},lr=Array.isArray,Vx=Array.prototype.push,uf=function(r,t){Vx.apply(r,lr(t)?t:[t])},jx=Date.prototype.toISOString,df=Xn.default,ne={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Vs.encode,encodeValuesOnly:!1,filter:void 0,format:df,formatter:Xn.formatters[df],indices:!1,serializeDate:function(t){return jx.call(t)},skipNulls:!1,strictNullHandling:!1},Wx=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},wl={},zx=function r(t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v){for(var g=t,b=v,S=0,R=!1;(b=b.get(wl))!==void 0&&!R;){var C=b.get(t);if(S+=1,typeof C<"u"){if(C===S)throw new RangeError("Cyclic object value");R=!0}typeof b.get(wl)>"u"&&(S=0)}if(typeof c=="function"?g=c(e,g):g instanceof Date?g=f(g):i==="comma"&&lr(g)&&(g=Vs.maybeMap(g,function(O){return O instanceof Date?f(O):O})),g===null){if(o)return h&&!y?h(e,ne.encoder,_,"key",p):e;g=""}if(Wx(g)||Vs.isBuffer(g)){if(h){var I=y?e:h(e,ne.encoder,_,"key",p);return[m(I)+"="+m(h(g,ne.encoder,_,"value",p))]}return[m(e)+"="+m(String(g))]}var M=[];if(typeof g>"u")return M;var F;if(i==="comma"&&lr(g))y&&h&&(g=Vs.maybeMap(g,h)),F=[{value:g.length>0?g.join(",")||null:void 0}];else if(lr(c))F=c;else{var U=Object.keys(g);F=u?U.sort(u):U}var P=l?String(e).replace(/\./g,"%2E"):String(e),T=n&&lr(g)&&g.length===1?P+"[]":P;if(s&&lr(g)&&g.length===0)return T+"[]";for(var E=0;E<F.length;++E){var A=F[E],L=typeof A=="object"&&A&&typeof A.value<"u"?A.value:g[A];if(!(a&&L===null)){var D=d&&l?String(A).replace(/\./g,"%2E"):String(A),N=lr(g)?typeof i=="function"?i(T,D):T:T+(d?"."+D:"["+D+"]");v.set(t,S);var $=hf();$.set(wl,v),uf(M,r(L,N,i,n,s,o,a,l,i==="comma"&&y&&lr(g)?null:h,c,u,d,f,p,m,y,_,$))}}return M},Yx=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=Xn.default;if(typeof t.format<"u"){if(!Xx.call(Xn.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var n=Xn.formatters[i],s=ne.filter;(typeof t.filter=="function"||lr(t.filter))&&(s=t.filter);var o;if(t.arrayFormat in cf?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}},qx=function(r,t){var e=r,i=Yx(t),n,s;typeof i.filter=="function"?(s=i.filter,e=s("",e)):lr(i.filter)&&(s=i.filter,n=s);var o=[];if(typeof e!="object"||e===null)return"";var a=cf[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var h=hf(),c=0;c<n.length;++c){var u=n[c],d=e[u];i.skipNulls&&d===null||uf(o,zx(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:""},ci=lf,El=Object.prototype.hasOwnProperty,ff=Array.isArray,zt={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:ci.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1,throwOnLimitExceeded:!1},Kx=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},pf=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},Zx="utf8=%26%2310003%3B",Qx="utf8=%E2%9C%93",Jx=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?s+1:s);if(e.throwOnLimitExceeded&&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]===Qx?h="utf-8":o[l]===Zx&&(h="iso-8859-1"),a=l,l=o.length);for(l=0;l<o.length;++l)if(l!==a){var c=o[l],u=c.indexOf("]="),d=u===-1?c.indexOf("="):u+1,f,p;d===-1?(f=e.decoder(c,zt.decoder,h,"key"),p=e.strictNullHandling?null:""):(f=e.decoder(c.slice(0,d),zt.decoder,h,"key"),p=ci.maybeMap(pf(c.slice(d+1),e,ff(i[f])?i[f].length:0),function(y){return e.decoder(y,zt.decoder,h,"value")})),p&&e.interpretNumericEntities&&h==="iso-8859-1"&&(p=Kx(String(p))),c.indexOf("[]=")>-1&&(p=ff(p)?[p]:p);var m=El.call(i,f);m&&e.duplicates==="combine"?i[f]=ci.combine(i[f],p):(!m||e.duplicates==="last")&&(i[f]=p)}return i},tw=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:pf(t,e,n),a=r.length-1;a>=0;--a){var l,h=r[a];if(h==="[]"&&e.parseArrays)l=e.allowEmptyArrays&&(o===""||e.strictNullHandling&&o===null)?[]:ci.combine([],o);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);!e.parseArrays&&u===""?l={0:o}:!isNaN(d)&&h!==u&&String(d)===u&&d>=0&&e.parseArrays&&d<=e.arrayLimit?(l=[],l[d]=o):u!=="__proto__"&&(l[u]=o)}o=l}return o},ew=function(t,e,i,n){if(t){var s=i.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,l=i.depth>0&&o.exec(s),h=l?s.slice(0,l.index):s,c=[];if(h){if(!i.plainObjects&&El.call(Object.prototype,h)&&!i.allowPrototypes)return;c.push(h)}for(var u=0;i.depth>0&&(l=a.exec(s))!==null&&u<i.depth;){if(u+=1,!i.plainObjects&&El.call(Object.prototype,l[1].slice(1,-1))&&!i.allowPrototypes)return;c.push(l[1])}if(l){if(i.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+i.depth+" and strictDepth is true");c.push("["+s.slice(l.index)+"]")}return tw(c,e,i,n)}},rw=function(t){if(!t)return zt;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"?zt.charset:t.charset,i=typeof t.duplicates>"u"?zt.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:zt.allowDots:!!t.allowDots;return{allowDots:n,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:zt.allowEmptyArrays,allowPrototypes:typeof t.allowPrototypes=="boolean"?t.allowPrototypes:zt.allowPrototypes,allowSparse:typeof t.allowSparse=="boolean"?t.allowSparse:zt.allowSparse,arrayLimit:typeof t.arrayLimit=="number"?t.arrayLimit:zt.arrayLimit,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:zt.charsetSentinel,comma:typeof t.comma=="boolean"?t.comma:zt.comma,decodeDotInKeys:typeof t.decodeDotInKeys=="boolean"?t.decodeDotInKeys:zt.decodeDotInKeys,decoder:typeof t.decoder=="function"?t.decoder:zt.decoder,delimiter:typeof t.delimiter=="string"||ci.isRegExp(t.delimiter)?t.delimiter:zt.delimiter,depth:typeof t.depth=="number"||t.depth===!1?+t.depth:zt.depth,duplicates:i,ignoreQueryPrefix:t.ignoreQueryPrefix===!0,interpretNumericEntities:typeof t.interpretNumericEntities=="boolean"?t.interpretNumericEntities:zt.interpretNumericEntities,parameterLimit:typeof t.parameterLimit=="number"?t.parameterLimit:zt.parameterLimit,parseArrays:t.parseArrays!==!1,plainObjects:typeof t.plainObjects=="boolean"?t.plainObjects:zt.plainObjects,strictDepth:typeof t.strictDepth=="boolean"?!!t.strictDepth:zt.strictDepth,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:zt.strictNullHandling,throwOnLimitExceeded:typeof t.throwOnLimitExceeded=="boolean"?t.throwOnLimitExceeded:!1}},iw=function(r,t){var e=rw(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?Jx(r,e):r,n=e.plainObjects?{__proto__:null}:{},s=Object.keys(i),o=0;o<s.length;++o){var a=s[o],l=ew(a,i[a],e,typeof r=="string");n=ci.merge(n,l,e)}return e.allowSparse===!0?n:ci.compact(n)},nw=qx,sw=iw,ow=vl,aw={formats:ow,parse:sw,stringify:nw},lw=y1;function br(){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 hw=/^([a-z0-9.+-]+:)/i,cw=/:[0-9]*$/,uw=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,dw=["<",">",'"',"`"," ","\r",`
5
- `," "],fw=["{","}","|","\\","^","`"].concat(dw),Tl=["'"].concat(fw),mf=["%","/","?",";","#"].concat(Tl),gf=["/","?","#"],pw=255,yf=/^[+a-z0-9A-Z_-]{0,63}$/,mw=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,gw={javascript:!0,"javascript:":!0},Al={javascript:!0,"javascript:":!0},Zi={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},Sl=aw;function yw(r,t,e){if(r&&typeof r=="object"&&r instanceof br)return r;var i=new br;return i.parse(r,t,e),i}br.prototype.parse=function(r,t,e){if(typeof r!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof r);var i=r.indexOf("?"),n=i!==-1&&i<r.indexOf("#")?"?":"#",s=r.split(n),o=/\\/g;s[0]=s[0].replace(o,"/"),r=s.join(n);var a=r;if(a=a.trim(),!e&&r.split("#").length===1){var l=uw.exec(a);if(l)return this.path=a,this.href=a,this.pathname=l[1],l[2]?(this.search=l[2],t?this.query=Sl.parse(this.search.substr(1)):this.query=this.search.substr(1)):t&&(this.search="",this.query={}),this}var h=hw.exec(a);if(h){h=h[0];var c=h.toLowerCase();this.protocol=c,a=a.substr(h.length)}if(e||h||a.match(/^\/\/[^@/]+@[^@/]+/)){var u=a.substr(0,2)==="//";u&&!(h&&Al[h])&&(a=a.substr(2),this.slashes=!0)}if(!Al[h]&&(u||h&&!Zi[h])){for(var d=-1,f=0;f<gf.length;f++){var p=a.indexOf(gf[f]);p!==-1&&(d===-1||p<d)&&(d=p)}var m,y;d===-1?y=a.lastIndexOf("@"):y=a.lastIndexOf("@",d),y!==-1&&(m=a.slice(0,y),a=a.slice(y+1),this.auth=decodeURIComponent(m)),d=-1;for(var f=0;f<mf.length;f++){var p=a.indexOf(mf[f]);p!==-1&&(d===-1||p<d)&&(d=p)}d===-1&&(d=a.length),this.host=a.slice(0,d),a=a.slice(d),this.parseHost(),this.hostname=this.hostname||"";var _=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!_)for(var v=this.hostname.split(/\./),f=0,g=v.length;f<g;f++){var b=v[f];if(b&&!b.match(yf)){for(var S="",R=0,C=b.length;R<C;R++)b.charCodeAt(R)>127?S+="x":S+=b[R];if(!S.match(yf)){var I=v.slice(0,f),M=v.slice(f+1),F=b.match(mw);F&&(I.push(F[1]),M.unshift(F[2])),M.length&&(a="/"+M.join(".")+a),this.hostname=I.join(".");break}}}this.hostname.length>pw?this.hostname="":this.hostname=this.hostname.toLowerCase(),_||(this.hostname=lw.toASCII(this.hostname));var U=this.port?":"+this.port:"",P=this.hostname||"";this.host=P+U,this.href+=this.host,_&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),a[0]!=="/"&&(a="/"+a))}if(!gw[c])for(var f=0,g=Tl.length;f<g;f++){var T=Tl[f];if(a.indexOf(T)!==-1){var E=encodeURIComponent(T);E===T&&(E=escape(T)),a=a.split(T).join(E)}}var A=a.indexOf("#");A!==-1&&(this.hash=a.substr(A),a=a.slice(0,A));var L=a.indexOf("?");if(L!==-1?(this.search=a.substr(L),this.query=a.substr(L+1),t&&(this.query=Sl.parse(this.query)),a=a.slice(0,L)):t&&(this.search="",this.query={}),a&&(this.pathname=a),Zi[c]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var U=this.pathname||"",D=this.search||"";this.path=U+D}return this.href=this.format(),this},br.prototype.format=function(){var r=this.auth||"";r&&(r=encodeURIComponent(r),r=r.replace(/%3A/i,":"),r+="@");var t=this.protocol||"",e=this.pathname||"",i=this.hash||"",n=!1,s="";this.host?n=r+this.host:this.hostname&&(n=r+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]"),this.port&&(n+=":"+this.port)),this.query&&typeof this.query=="object"&&Object.keys(this.query).length&&(s=Sl.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var o=this.search||s&&"?"+s||"";return t&&t.substr(-1)!==":"&&(t+=":"),this.slashes||(!t||Zi[t])&&n!==!1?(n="//"+(n||""),e&&e.charAt(0)!=="/"&&(e="/"+e)):n||(n=""),i&&i.charAt(0)!=="#"&&(i="#"+i),o&&o.charAt(0)!=="?"&&(o="?"+o),e=e.replace(/[?#]/g,function(a){return encodeURIComponent(a)}),o=o.replace("#","%23"),t+n+e+o+i},br.prototype.resolve=function(r){return this.resolveObject(yw(r,!1,!0)).format()},br.prototype.resolveObject=function(r){if(typeof r=="string"){var t=new br;t.parse(r,!1,!0),r=t}for(var e=new br,i=Object.keys(this),n=0;n<i.length;n++){var s=i[n];e[s]=this[s]}if(e.hash=r.hash,r.href==="")return e.href=e.format(),e;if(r.slashes&&!r.protocol){for(var o=Object.keys(r),a=0;a<o.length;a++){var l=o[a];l!=="protocol"&&(e[l]=r[l])}return Zi[e.protocol]&&e.hostname&&!e.pathname&&(e.pathname="/",e.path=e.pathname),e.href=e.format(),e}if(r.protocol&&r.protocol!==e.protocol){if(!Zi[r.protocol]){for(var h=Object.keys(r),c=0;c<h.length;c++){var u=h[c];e[u]=r[u]}return e.href=e.format(),e}if(e.protocol=r.protocol,!r.host&&!Al[r.protocol]){for(var g=(r.pathname||"").split("/");g.length&&!(r.host=g.shift()););r.host||(r.host=""),r.hostname||(r.hostname=""),g[0]!==""&&g.unshift(""),g.length<2&&g.unshift(""),e.pathname=g.join("/")}else e.pathname=r.pathname;if(e.search=r.search,e.query=r.query,e.host=r.host||"",e.auth=r.auth,e.hostname=r.hostname||r.host,e.port=r.port,e.pathname||e.search){var d=e.pathname||"",f=e.search||"";e.path=d+f}return e.slashes=e.slashes||r.slashes,e.href=e.format(),e}var p=e.pathname&&e.pathname.charAt(0)==="/",m=r.host||r.pathname&&r.pathname.charAt(0)==="/",y=m||p||e.host&&r.pathname,_=y,v=e.pathname&&e.pathname.split("/")||[],g=r.pathname&&r.pathname.split("/")||[],b=e.protocol&&!Zi[e.protocol];if(b&&(e.hostname="",e.port=null,e.host&&(v[0]===""?v[0]=e.host:v.unshift(e.host)),e.host="",r.protocol&&(r.hostname=null,r.port=null,r.host&&(g[0]===""?g[0]=r.host:g.unshift(r.host)),r.host=null),y=y&&(g[0]===""||v[0]==="")),m)e.host=r.host||r.host===""?r.host:e.host,e.hostname=r.hostname||r.hostname===""?r.hostname:e.hostname,e.search=r.search,e.query=r.query,v=g;else if(g.length)v||(v=[]),v.pop(),v=v.concat(g),e.search=r.search,e.query=r.query;else if(r.search!=null){if(b){e.host=v.shift(),e.hostname=e.host;var S=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;S&&(e.auth=S.shift(),e.hostname=S.shift(),e.host=e.hostname)}return e.search=r.search,e.query=r.query,(e.pathname!==null||e.search!==null)&&(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.href=e.format(),e}if(!v.length)return e.pathname=null,e.search?e.path="/"+e.search:e.path=null,e.href=e.format(),e;for(var R=v.slice(-1)[0],C=(e.host||r.host||v.length>1)&&(R==="."||R==="..")||R==="",I=0,M=v.length;M>=0;M--)R=v[M],R==="."?v.splice(M,1):R===".."?(v.splice(M,1),I++):I&&(v.splice(M,1),I--);if(!y&&!_)for(;I--;I)v.unshift("..");y&&v[0]!==""&&(!v[0]||v[0].charAt(0)!=="/")&&v.unshift(""),C&&v.join("/").substr(-1)!=="/"&&v.push("");var F=v[0]===""||v[0]&&v[0].charAt(0)==="/";if(b){e.hostname=F?"":v.length?v.shift():"",e.host=e.hostname;var S=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;S&&(e.auth=S.shift(),e.hostname=S.shift(),e.host=e.hostname)}return y=y||e.host&&v.length,y&&!F&&v.unshift(""),v.length>0?e.pathname=v.join("/"):(e.pathname=null,e.path=null),(e.pathname!==null||e.search!==null)&&(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.auth=r.auth||e.auth,e.slashes=e.slashes||r.slashes,e.href=e.format(),e},br.prototype.parseHost=function(){var r=this.host,t=cw.exec(r);t&&(t=t[0],t!==":"&&(this.port=t.substr(1)),r=r.substr(0,r.length-t.length)),r&&(this.hostname=r)};const _f={};function At(r,t,e=3){if(_f[t])return;let i=new Error().stack;typeof i>"u"?console.warn("PixiJS Deprecation Warning: ",`${t}
4
+ `+t.prev}function Ls(r,t){var e=tl(r),i=[];if(e){i.length=r.length;for(var n=0;n<r.length;n++)i[n]=vr(r,n)?t(r[n],r):""}var s=typeof Za=="function"?Za(r):[],o;if(ji){o={};for(var a=0;a<s.length;a++)o["$"+s[a]]=s[a]}for(var l in r)vr(r,l)&&(e&&String(Number(l))===l&&l<r.length||ji&&o["$"+l]instanceof Symbol||(vd.call(/[^\w$]/,l)?i.push(t(l,r)+": "+t(r[l],r)):i.push(l+": "+t(r[l],r))));if(typeof Za=="function")for(var h=0;h<s.length;h++)wd.call(r,s[h])&&i.push("["+t(s[h])+"]: "+t(r[s[h]],r));return i}var z1=Os,Y1=Vi,Ns=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},q1=function(r,t){if(r){var e=Ns(r,t);return e&&e.value}},K1=function(r,t,e){var i=Ns(r,t);i?i.value=e:r.next={key:t,next:r.next,value:e}},Z1=function(r,t){return r?!!Ns(r,t):!1},Q1=function(r,t){if(r)return Ns(r,t,!0)},J1=function(){var t,e={assert:function(i){if(!e.has(i))throw new Y1("Side channel does not contain "+z1(i))},delete:function(i){var n=t&&t.next,s=Q1(t,i);return s&&n&&n===s&&(t=void 0),!!s},get:function(i){return q1(t,i)},has:function(i){return Z1(t,i)},set:function(i,n){t||(t={next:void 0}),K1(t,i,n)}};return e},Od=Object,tb=Error,eb=EvalError,rb=RangeError,ib=ReferenceError,nb=SyntaxError,sb=URIError,ob=Math.abs,ab=Math.floor,lb=Math.max,hb=Math.min,cb=Math.pow,ub=Math.round,db=Number.isNaN||function(t){return t!==t},fb=db,pb=function(t){return fb(t)||t===0?t:t<0?-1:1},mb=Object.getOwnPropertyDescriptor,Fs=mb;if(Fs)try{Fs([],"length")}catch{Fs=null}var Ld=Fs,ks=Object.defineProperty||!1;if(ks)try{ks({},"a",{value:1})}catch{ks=!1}var gb=ks,il,Nd;function yb(){return Nd||(Nd=1,il=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}),il}var nl,Fd;function _b(){if(Fd)return nl;Fd=1;var r=typeof Symbol<"u"&&Symbol,t=yb();return nl=function(){return typeof r!="function"||typeof Symbol!="function"||typeof r("foo")!="symbol"||typeof Symbol("bar")!="symbol"?!1:t()},nl}var sl,kd;function Ud(){return kd||(kd=1,sl=typeof Reflect<"u"&&Reflect.getPrototypeOf||null),sl}var ol,Gd;function $d(){if(Gd)return ol;Gd=1;var r=Od;return ol=r.getPrototypeOf||null,ol}var al,Hd;function vb(){if(Hd)return al;Hd=1;var r="Function.prototype.bind called on incompatible ",t=Object.prototype.toString,e=Math.max,i="[object Function]",n=function(l,h){for(var c=[],u=0;u<l.length;u+=1)c[u]=l[u];for(var d=0;d<h.length;d+=1)c[d+l.length]=h[d];return c},s=function(l,h){for(var c=[],u=h,d=0;u<l.length;u+=1,d+=1)c[d]=l[u];return c},o=function(a,l){for(var h="",c=0;c<a.length;c+=1)h+=a[c],c+1<a.length&&(h+=l);return h};return al=function(l){var h=this;if(typeof h!="function"||t.apply(h)!==i)throw new TypeError(r+h);for(var c=s(arguments,1),u,d=function(){if(this instanceof u){var _=h.apply(this,n(c,arguments));return Object(_)===_?_:this}return h.apply(l,n(c,arguments))},f=e(0,h.length-c.length),p=[],m=0;m<f;m++)p[m]="$"+m;if(u=Function("binder","return function ("+o(p,",")+"){ return binder.apply(this,arguments); }")(d),h.prototype){var y=function(){};y.prototype=h.prototype,u.prototype=new y,y.prototype=null}return u},al}var ll,Xd;function Us(){if(Xd)return ll;Xd=1;var r=vb();return ll=Function.prototype.bind||r,ll}var hl,Vd;function cl(){return Vd||(Vd=1,hl=Function.prototype.call),hl}var ul,jd;function Wd(){return jd||(jd=1,ul=Function.prototype.apply),ul}var bb=typeof Reflect<"u"&&Reflect&&Reflect.apply,xb=Us(),wb=Wd(),Eb=cl(),Tb=bb,Ab=Tb||xb.call(Eb,wb),Sb=Us(),Cb=Vi,Ib=cl(),Pb=Ab,zd=function(t){if(t.length<1||typeof t[0]!="function")throw new Cb("a function is required");return Pb(Sb,Ib,t)},dl,Yd;function Rb(){if(Yd)return dl;Yd=1;var r=zd,t=Ld,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 dl=i&&typeof i.get=="function"?r([i.get]):typeof s=="function"?function(a){return s(a==null?a:n(a))}:!1,dl}var fl,qd;function Mb(){if(qd)return fl;qd=1;var r=Ud(),t=$d(),e=Rb();return fl=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,fl}var pl,Kd;function Db(){if(Kd)return pl;Kd=1;var r=Function.prototype.call,t=Object.prototype.hasOwnProperty,e=Us();return pl=e.call(r,t),pl}var Tt,Bb=Od,Ob=tb,Lb=eb,Nb=rb,Fb=ib,Wi=nb,zi=Vi,kb=sb,Ub=ob,Gb=ab,$b=lb,Hb=hb,Xb=cb,Vb=ub,jb=pb,Zd=Function,ml=function(r){try{return Zd('"use strict"; return ('+r+").constructor;")()}catch{}},Un=Ld,Wb=gb,gl=function(){throw new zi},zb=Un?function(){try{return arguments.callee,gl}catch{try{return Un(arguments,"callee").get}catch{return gl}}}():gl,Yi=_b()(),ce=Mb(),Yb=$d(),qb=Ud(),Qd=Wd(),Gn=cl(),qi={},Kb=typeof Uint8Array>"u"||!ce?Tt:ce(Uint8Array),li={__proto__:null,"%AggregateError%":typeof AggregateError>"u"?Tt:AggregateError,"%Array%":Array,"%ArrayBuffer%":typeof ArrayBuffer>"u"?Tt:ArrayBuffer,"%ArrayIteratorPrototype%":Yi&&ce?ce([][Symbol.iterator]()):Tt,"%AsyncFromSyncIteratorPrototype%":Tt,"%AsyncFunction%":qi,"%AsyncGenerator%":qi,"%AsyncGeneratorFunction%":qi,"%AsyncIteratorPrototype%":qi,"%Atomics%":typeof Atomics>"u"?Tt:Atomics,"%BigInt%":typeof BigInt>"u"?Tt:BigInt,"%BigInt64Array%":typeof BigInt64Array>"u"?Tt:BigInt64Array,"%BigUint64Array%":typeof BigUint64Array>"u"?Tt:BigUint64Array,"%Boolean%":Boolean,"%DataView%":typeof DataView>"u"?Tt:DataView,"%Date%":Date,"%decodeURI%":decodeURI,"%decodeURIComponent%":decodeURIComponent,"%encodeURI%":encodeURI,"%encodeURIComponent%":encodeURIComponent,"%Error%":Ob,"%eval%":eval,"%EvalError%":Lb,"%Float16Array%":typeof Float16Array>"u"?Tt:Float16Array,"%Float32Array%":typeof Float32Array>"u"?Tt:Float32Array,"%Float64Array%":typeof Float64Array>"u"?Tt:Float64Array,"%FinalizationRegistry%":typeof FinalizationRegistry>"u"?Tt:FinalizationRegistry,"%Function%":Zd,"%GeneratorFunction%":qi,"%Int8Array%":typeof Int8Array>"u"?Tt:Int8Array,"%Int16Array%":typeof Int16Array>"u"?Tt:Int16Array,"%Int32Array%":typeof Int32Array>"u"?Tt:Int32Array,"%isFinite%":isFinite,"%isNaN%":isNaN,"%IteratorPrototype%":Yi&&ce?ce(ce([][Symbol.iterator]())):Tt,"%JSON%":typeof JSON=="object"?JSON:Tt,"%Map%":typeof Map>"u"?Tt:Map,"%MapIteratorPrototype%":typeof Map>"u"||!Yi||!ce?Tt:ce(new Map()[Symbol.iterator]()),"%Math%":Math,"%Number%":Number,"%Object%":Bb,"%Object.getOwnPropertyDescriptor%":Un,"%parseFloat%":parseFloat,"%parseInt%":parseInt,"%Promise%":typeof Promise>"u"?Tt:Promise,"%Proxy%":typeof Proxy>"u"?Tt:Proxy,"%RangeError%":Nb,"%ReferenceError%":Fb,"%Reflect%":typeof Reflect>"u"?Tt:Reflect,"%RegExp%":RegExp,"%Set%":typeof Set>"u"?Tt:Set,"%SetIteratorPrototype%":typeof Set>"u"||!Yi||!ce?Tt:ce(new Set()[Symbol.iterator]()),"%SharedArrayBuffer%":typeof SharedArrayBuffer>"u"?Tt:SharedArrayBuffer,"%String%":String,"%StringIteratorPrototype%":Yi&&ce?ce(""[Symbol.iterator]()):Tt,"%Symbol%":Yi?Symbol:Tt,"%SyntaxError%":Wi,"%ThrowTypeError%":zb,"%TypedArray%":Kb,"%TypeError%":zi,"%Uint8Array%":typeof Uint8Array>"u"?Tt:Uint8Array,"%Uint8ClampedArray%":typeof Uint8ClampedArray>"u"?Tt:Uint8ClampedArray,"%Uint16Array%":typeof Uint16Array>"u"?Tt:Uint16Array,"%Uint32Array%":typeof Uint32Array>"u"?Tt:Uint32Array,"%URIError%":kb,"%WeakMap%":typeof WeakMap>"u"?Tt:WeakMap,"%WeakRef%":typeof WeakRef>"u"?Tt:WeakRef,"%WeakSet%":typeof WeakSet>"u"?Tt:WeakSet,"%Function.prototype.call%":Gn,"%Function.prototype.apply%":Qd,"%Object.defineProperty%":Wb,"%Object.getPrototypeOf%":Yb,"%Math.abs%":Ub,"%Math.floor%":Gb,"%Math.max%":$b,"%Math.min%":Hb,"%Math.pow%":Xb,"%Math.round%":Vb,"%Math.sign%":jb,"%Reflect.getPrototypeOf%":qb};if(ce)try{null.error}catch(r){var Zb=ce(ce(r));li["%Error.prototype%"]=Zb}var Qb=function r(t){var e;if(t==="%AsyncFunction%")e=ml("async function () {}");else if(t==="%GeneratorFunction%")e=ml("function* () {}");else if(t==="%AsyncGeneratorFunction%")e=ml("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 li[t]=e,e},Jd={__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"]},$n=Us(),Gs=Db(),Jb=$n.call(Gn,Array.prototype.concat),tx=$n.call(Qd,Array.prototype.splice),tf=$n.call(Gn,String.prototype.replace),$s=$n.call(Gn,String.prototype.slice),ex=$n.call(Gn,RegExp.prototype.exec),rx=/[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g,ix=/\\(\\)?/g,nx=function(t){var e=$s(t,0,1),i=$s(t,-1);if(e==="%"&&i!=="%")throw new Wi("invalid intrinsic syntax, expected closing `%`");if(i==="%"&&e!=="%")throw new Wi("invalid intrinsic syntax, expected opening `%`");var n=[];return tf(t,rx,function(s,o,a,l){n[n.length]=a?tf(l,ix,"$1"):o||s}),n},sx=function(t,e){var i=t,n;if(Gs(Jd,i)&&(n=Jd[i],i="%"+n[0]+"%"),Gs(li,i)){var s=li[i];if(s===qi&&(s=Qb(i)),typeof s>"u"&&!e)throw new zi("intrinsic "+t+" exists, but is not available. Please file an issue!");return{alias:n,name:i,value:s}}throw new Wi("intrinsic "+t+" does not exist!")},yl=function(t,e){if(typeof t!="string"||t.length===0)throw new zi("intrinsic name must be a non-empty string");if(arguments.length>1&&typeof e!="boolean")throw new zi('"allowMissing" argument must be a boolean');if(ex(/^%?[^%]*%?$/,t)===null)throw new Wi("`%` may not be present anywhere but at the beginning and end of the intrinsic name");var i=nx(t),n=i.length>0?i[0]:"",s=sx("%"+n+"%",e),o=s.name,a=s.value,l=!1,h=s.alias;h&&(n=h[0],tx(i,Jb([0,1],h)));for(var c=1,u=!0;c<i.length;c+=1){var d=i[c],f=$s(d,0,1),p=$s(d,-1);if((f==='"'||f==="'"||f==="`"||p==='"'||p==="'"||p==="`")&&f!==p)throw new Wi("property names with quotes must have matching quotes");if((d==="constructor"||!u)&&(l=!0),n+="."+d,o="%"+n+"%",Gs(li,o))a=li[o];else if(a!=null){if(!(d in a)){if(!e)throw new zi("base intrinsic for "+t+" exists, but the property is not available.");return}if(Un&&c+1>=i.length){var m=Un(a,d);u=!!m,u&&"get"in m&&!("originalValue"in m.get)?a=m.get:a=a[d]}else u=Gs(a,d),a=a[d];u&&!l&&(li[o]=a)}}return a},ef=yl,rf=zd,ox=rf([ef("%String.prototype.indexOf%")]),nf=function(t,e){var i=ef(t,!!e);return typeof i=="function"&&ox(t,".prototype.")>-1?rf([i]):i},ax=yl,Hn=nf,lx=Os,hx=Vi,sf=ax("%Map%",!0),cx=Hn("Map.prototype.get",!0),ux=Hn("Map.prototype.set",!0),dx=Hn("Map.prototype.has",!0),fx=Hn("Map.prototype.delete",!0),px=Hn("Map.prototype.size",!0),of=!!sf&&function(){var t,e={assert:function(i){if(!e.has(i))throw new hx("Side channel does not contain "+lx(i))},delete:function(i){if(t){var n=fx(t,i);return px(t)===0&&(t=void 0),n}return!1},get:function(i){if(t)return cx(t,i)},has:function(i){return t?dx(t,i):!1},set:function(i,n){t||(t=new sf),ux(t,i,n)}};return e},mx=yl,Hs=nf,gx=Os,Xs=of,yx=Vi,Ki=mx("%WeakMap%",!0),_x=Hs("WeakMap.prototype.get",!0),vx=Hs("WeakMap.prototype.set",!0),bx=Hs("WeakMap.prototype.has",!0),xx=Hs("WeakMap.prototype.delete",!0),wx=Ki?function(){var t,e,i={assert:function(n){if(!i.has(n))throw new yx("Side channel does not contain "+gx(n))},delete:function(n){if(Ki&&n&&(typeof n=="object"||typeof n=="function")){if(t)return xx(t,n)}else if(Xs&&e)return e.delete(n);return!1},get:function(n){return Ki&&n&&(typeof n=="object"||typeof n=="function")&&t?_x(t,n):e&&e.get(n)},has:function(n){return Ki&&n&&(typeof n=="object"||typeof n=="function")&&t?bx(t,n):!!e&&e.has(n)},set:function(n,s){Ki&&n&&(typeof n=="object"||typeof n=="function")?(t||(t=new Ki),vx(t,n,s)):Xs&&(e||(e=Xs()),e.set(n,s))}};return i}:Xs,Ex=Vi,Tx=Os,Ax=J1,Sx=of,Cx=wx,Ix=Cx||Sx||Ax,Px=function(){var t,e={assert:function(i){if(!e.has(i))throw new Ex("Side channel does not contain "+Tx(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=Ix()),t.set(i,n)}};return e},Rx=String.prototype.replace,Mx=/%20/g,_l={RFC1738:"RFC1738",RFC3986:"RFC3986"},vl={default:_l.RFC3986,formatters:{RFC1738:function(r){return Rx.call(r,Mx,"+")},RFC3986:function(r){return String(r)}},RFC1738:_l.RFC1738,RFC3986:_l.RFC3986},Dx=vl,bl=Object.prototype.hasOwnProperty,hi=Array.isArray,ar=function(){for(var r=[],t=0;t<256;++t)r.push("%"+((t<16?"0":"")+t.toString(16)).toUpperCase());return r}(),Bx=function(t){for(;t.length>1;){var e=t.pop(),i=e.obj[e.prop];if(hi(i)){for(var n=[],s=0;s<i.length;++s)typeof i[s]<"u"&&n.push(i[s]);e.obj[e.prop]=n}}},af=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},Ox=function r(t,e,i){if(!e)return t;if(typeof e!="object"&&typeof e!="function"){if(hi(t))t.push(e);else if(t&&typeof t=="object")(i&&(i.plainObjects||i.allowPrototypes)||!bl.call(Object.prototype,e))&&(t[e]=!0);else return[t,e];return t}if(!t||typeof t!="object")return[t].concat(e);var n=t;return hi(t)&&!hi(e)&&(n=af(t,i)),hi(t)&&hi(e)?(e.forEach(function(s,o){if(bl.call(t,o)){var a=t[o];a&&typeof a=="object"&&s&&typeof s=="object"?t[o]=r(a,s,i):t.push(s)}else t[o]=s}),t):Object.keys(e).reduce(function(s,o){var a=e[o];return bl.call(s,o)?s[o]=r(s[o],a,i):s[o]=a,s},n)},Lx=function(t,e){return Object.keys(e).reduce(function(i,n){return i[n]=e[n],i},t)},Nx=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}},xl=1024,Fx=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+=xl){for(var h=o.length>=xl?o.slice(l,l+xl):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===Dx.RFC1738&&(d===40||d===41)){c[c.length]=h.charAt(u);continue}if(d<128){c[c.length]=ar[d];continue}if(d<2048){c[c.length]=ar[192|d>>6]+ar[128|d&63];continue}if(d<55296||d>=57344){c[c.length]=ar[224|d>>12]+ar[128|d>>6&63]+ar[128|d&63];continue}u+=1,d=65536+((d&1023)<<10|h.charCodeAt(u)&1023),c[c.length]=ar[240|d>>18]+ar[128|d>>12&63]+ar[128|d>>6&63]+ar[128|d&63]}a+=c.join("")}return a},kx=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.push({obj:o,prop:h}),i.push(c))}return Bx(e),t},Ux=function(t){return Object.prototype.toString.call(t)==="[object RegExp]"},Gx=function(t){return!t||typeof t!="object"?!1:!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},$x=function(t,e){return[].concat(t,e)},Hx=function(t,e){if(hi(t)){for(var i=[],n=0;n<t.length;n+=1)i.push(e(t[n]));return i}return e(t)},lf={arrayToObject:af,assign:Lx,combine:$x,compact:kx,decode:Nx,encode:Fx,isBuffer:Gx,isRegExp:Ux,maybeMap:Hx,merge:Ox},hf=Px,Vs=lf,Xn=vl,Xx=Object.prototype.hasOwnProperty,cf={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},lr=Array.isArray,Vx=Array.prototype.push,uf=function(r,t){Vx.apply(r,lr(t)?t:[t])},jx=Date.prototype.toISOString,df=Xn.default,ne={addQueryPrefix:!1,allowDots:!1,allowEmptyArrays:!1,arrayFormat:"indices",charset:"utf-8",charsetSentinel:!1,commaRoundTrip:!1,delimiter:"&",encode:!0,encodeDotInKeys:!1,encoder:Vs.encode,encodeValuesOnly:!1,filter:void 0,format:df,formatter:Xn.formatters[df],indices:!1,serializeDate:function(t){return jx.call(t)},skipNulls:!1,strictNullHandling:!1},Wx=function(t){return typeof t=="string"||typeof t=="number"||typeof t=="boolean"||typeof t=="symbol"||typeof t=="bigint"},wl={},zx=function r(t,e,i,n,s,o,a,l,h,c,u,d,f,p,m,y,_,v){for(var g=t,b=v,S=0,R=!1;(b=b.get(wl))!==void 0&&!R;){var C=b.get(t);if(S+=1,typeof C<"u"){if(C===S)throw new RangeError("Cyclic object value");R=!0}typeof b.get(wl)>"u"&&(S=0)}if(typeof c=="function"?g=c(e,g):g instanceof Date?g=f(g):i==="comma"&&lr(g)&&(g=Vs.maybeMap(g,function(B){return B instanceof Date?f(B):B})),g===null){if(o)return h&&!y?h(e,ne.encoder,_,"key",p):e;g=""}if(Wx(g)||Vs.isBuffer(g)){if(h){var I=y?e:h(e,ne.encoder,_,"key",p);return[m(I)+"="+m(h(g,ne.encoder,_,"value",p))]}return[m(e)+"="+m(String(g))]}var M=[];if(typeof g>"u")return M;var F;if(i==="comma"&&lr(g))y&&h&&(g=Vs.maybeMap(g,h)),F=[{value:g.length>0?g.join(",")||null:void 0}];else if(lr(c))F=c;else{var U=Object.keys(g);F=u?U.sort(u):U}var P=l?String(e).replace(/\./g,"%2E"):String(e),E=n&&lr(g)&&g.length===1?P+"[]":P;if(s&&lr(g)&&g.length===0)return E+"[]";for(var T=0;T<F.length;++T){var A=F[T],O=typeof A=="object"&&A&&typeof A.value<"u"?A.value:g[A];if(!(a&&O===null)){var D=d&&l?String(A).replace(/\./g,"%2E"):String(A),L=lr(g)?typeof i=="function"?i(E,D):E:E+(d?"."+D:"["+D+"]");v.set(t,S);var $=hf();$.set(wl,v),uf(M,r(O,L,i,n,s,o,a,l,i==="comma"&&y&&lr(g)?null:h,c,u,d,f,p,m,y,_,$))}}return M},Yx=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=Xn.default;if(typeof t.format<"u"){if(!Xx.call(Xn.formatters,t.format))throw new TypeError("Unknown format option provided.");i=t.format}var n=Xn.formatters[i],s=ne.filter;(typeof t.filter=="function"||lr(t.filter))&&(s=t.filter);var o;if(t.arrayFormat in cf?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}},qx=function(r,t){var e=r,i=Yx(t),n,s;typeof i.filter=="function"?(s=i.filter,e=s("",e)):lr(i.filter)&&(s=i.filter,n=s);var o=[];if(typeof e!="object"||e===null)return"";var a=cf[i.arrayFormat],l=a==="comma"&&i.commaRoundTrip;n||(n=Object.keys(e)),i.sort&&n.sort(i.sort);for(var h=hf(),c=0;c<n.length;++c){var u=n[c],d=e[u];i.skipNulls&&d===null||uf(o,zx(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:""},ci=lf,El=Object.prototype.hasOwnProperty,ff=Array.isArray,zt={allowDots:!1,allowEmptyArrays:!1,allowPrototypes:!1,allowSparse:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decodeDotInKeys:!1,decoder:ci.decode,delimiter:"&",depth:5,duplicates:"combine",ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictDepth:!1,strictNullHandling:!1,throwOnLimitExceeded:!1},Kx=function(r){return r.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},pf=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},Zx="utf8=%26%2310003%3B",Qx="utf8=%E2%9C%93",Jx=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?s+1:s);if(e.throwOnLimitExceeded&&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]===Qx?h="utf-8":o[l]===Zx&&(h="iso-8859-1"),a=l,l=o.length);for(l=0;l<o.length;++l)if(l!==a){var c=o[l],u=c.indexOf("]="),d=u===-1?c.indexOf("="):u+1,f,p;d===-1?(f=e.decoder(c,zt.decoder,h,"key"),p=e.strictNullHandling?null:""):(f=e.decoder(c.slice(0,d),zt.decoder,h,"key"),p=ci.maybeMap(pf(c.slice(d+1),e,ff(i[f])?i[f].length:0),function(y){return e.decoder(y,zt.decoder,h,"value")})),p&&e.interpretNumericEntities&&h==="iso-8859-1"&&(p=Kx(String(p))),c.indexOf("[]=")>-1&&(p=ff(p)?[p]:p);var m=El.call(i,f);m&&e.duplicates==="combine"?i[f]=ci.combine(i[f],p):(!m||e.duplicates==="last")&&(i[f]=p)}return i},tw=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:pf(t,e,n),a=r.length-1;a>=0;--a){var l,h=r[a];if(h==="[]"&&e.parseArrays)l=e.allowEmptyArrays&&(o===""||e.strictNullHandling&&o===null)?[]:ci.combine([],o);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);!e.parseArrays&&u===""?l={0:o}:!isNaN(d)&&h!==u&&String(d)===u&&d>=0&&e.parseArrays&&d<=e.arrayLimit?(l=[],l[d]=o):u!=="__proto__"&&(l[u]=o)}o=l}return o},ew=function(t,e,i,n){if(t){var s=i.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,o=/(\[[^[\]]*])/,a=/(\[[^[\]]*])/g,l=i.depth>0&&o.exec(s),h=l?s.slice(0,l.index):s,c=[];if(h){if(!i.plainObjects&&El.call(Object.prototype,h)&&!i.allowPrototypes)return;c.push(h)}for(var u=0;i.depth>0&&(l=a.exec(s))!==null&&u<i.depth;){if(u+=1,!i.plainObjects&&El.call(Object.prototype,l[1].slice(1,-1))&&!i.allowPrototypes)return;c.push(l[1])}if(l){if(i.strictDepth===!0)throw new RangeError("Input depth exceeded depth option of "+i.depth+" and strictDepth is true");c.push("["+s.slice(l.index)+"]")}return tw(c,e,i,n)}},rw=function(t){if(!t)return zt;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"?zt.charset:t.charset,i=typeof t.duplicates>"u"?zt.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:zt.allowDots:!!t.allowDots;return{allowDots:n,allowEmptyArrays:typeof t.allowEmptyArrays=="boolean"?!!t.allowEmptyArrays:zt.allowEmptyArrays,allowPrototypes:typeof t.allowPrototypes=="boolean"?t.allowPrototypes:zt.allowPrototypes,allowSparse:typeof t.allowSparse=="boolean"?t.allowSparse:zt.allowSparse,arrayLimit:typeof t.arrayLimit=="number"?t.arrayLimit:zt.arrayLimit,charset:e,charsetSentinel:typeof t.charsetSentinel=="boolean"?t.charsetSentinel:zt.charsetSentinel,comma:typeof t.comma=="boolean"?t.comma:zt.comma,decodeDotInKeys:typeof t.decodeDotInKeys=="boolean"?t.decodeDotInKeys:zt.decodeDotInKeys,decoder:typeof t.decoder=="function"?t.decoder:zt.decoder,delimiter:typeof t.delimiter=="string"||ci.isRegExp(t.delimiter)?t.delimiter:zt.delimiter,depth:typeof t.depth=="number"||t.depth===!1?+t.depth:zt.depth,duplicates:i,ignoreQueryPrefix:t.ignoreQueryPrefix===!0,interpretNumericEntities:typeof t.interpretNumericEntities=="boolean"?t.interpretNumericEntities:zt.interpretNumericEntities,parameterLimit:typeof t.parameterLimit=="number"?t.parameterLimit:zt.parameterLimit,parseArrays:t.parseArrays!==!1,plainObjects:typeof t.plainObjects=="boolean"?t.plainObjects:zt.plainObjects,strictDepth:typeof t.strictDepth=="boolean"?!!t.strictDepth:zt.strictDepth,strictNullHandling:typeof t.strictNullHandling=="boolean"?t.strictNullHandling:zt.strictNullHandling,throwOnLimitExceeded:typeof t.throwOnLimitExceeded=="boolean"?t.throwOnLimitExceeded:!1}},iw=function(r,t){var e=rw(t);if(r===""||r===null||typeof r>"u")return e.plainObjects?{__proto__:null}:{};for(var i=typeof r=="string"?Jx(r,e):r,n=e.plainObjects?{__proto__:null}:{},s=Object.keys(i),o=0;o<s.length;++o){var a=s[o],l=ew(a,i[a],e,typeof r=="string");n=ci.merge(n,l,e)}return e.allowSparse===!0?n:ci.compact(n)},nw=qx,sw=iw,ow=vl,aw={formats:ow,parse:sw,stringify:nw},lw=y1;function br(){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 hw=/^([a-z0-9.+-]+:)/i,cw=/:[0-9]*$/,uw=/^(\/\/?(?!\/)[^?\s]*)(\?[^\s]*)?$/,dw=["<",">",'"',"`"," ","\r",`
5
+ `," "],fw=["{","}","|","\\","^","`"].concat(dw),Tl=["'"].concat(fw),mf=["%","/","?",";","#"].concat(Tl),gf=["/","?","#"],pw=255,yf=/^[+a-z0-9A-Z_-]{0,63}$/,mw=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,gw={javascript:!0,"javascript:":!0},Al={javascript:!0,"javascript:":!0},Zi={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},Sl=aw;function yw(r,t,e){if(r&&typeof r=="object"&&r instanceof br)return r;var i=new br;return i.parse(r,t,e),i}br.prototype.parse=function(r,t,e){if(typeof r!="string")throw new TypeError("Parameter 'url' must be a string, not "+typeof r);var i=r.indexOf("?"),n=i!==-1&&i<r.indexOf("#")?"?":"#",s=r.split(n),o=/\\/g;s[0]=s[0].replace(o,"/"),r=s.join(n);var a=r;if(a=a.trim(),!e&&r.split("#").length===1){var l=uw.exec(a);if(l)return this.path=a,this.href=a,this.pathname=l[1],l[2]?(this.search=l[2],t?this.query=Sl.parse(this.search.substr(1)):this.query=this.search.substr(1)):t&&(this.search="",this.query={}),this}var h=hw.exec(a);if(h){h=h[0];var c=h.toLowerCase();this.protocol=c,a=a.substr(h.length)}if(e||h||a.match(/^\/\/[^@/]+@[^@/]+/)){var u=a.substr(0,2)==="//";u&&!(h&&Al[h])&&(a=a.substr(2),this.slashes=!0)}if(!Al[h]&&(u||h&&!Zi[h])){for(var d=-1,f=0;f<gf.length;f++){var p=a.indexOf(gf[f]);p!==-1&&(d===-1||p<d)&&(d=p)}var m,y;d===-1?y=a.lastIndexOf("@"):y=a.lastIndexOf("@",d),y!==-1&&(m=a.slice(0,y),a=a.slice(y+1),this.auth=decodeURIComponent(m)),d=-1;for(var f=0;f<mf.length;f++){var p=a.indexOf(mf[f]);p!==-1&&(d===-1||p<d)&&(d=p)}d===-1&&(d=a.length),this.host=a.slice(0,d),a=a.slice(d),this.parseHost(),this.hostname=this.hostname||"";var _=this.hostname[0]==="["&&this.hostname[this.hostname.length-1]==="]";if(!_)for(var v=this.hostname.split(/\./),f=0,g=v.length;f<g;f++){var b=v[f];if(b&&!b.match(yf)){for(var S="",R=0,C=b.length;R<C;R++)b.charCodeAt(R)>127?S+="x":S+=b[R];if(!S.match(yf)){var I=v.slice(0,f),M=v.slice(f+1),F=b.match(mw);F&&(I.push(F[1]),M.unshift(F[2])),M.length&&(a="/"+M.join(".")+a),this.hostname=I.join(".");break}}}this.hostname.length>pw?this.hostname="":this.hostname=this.hostname.toLowerCase(),_||(this.hostname=lw.toASCII(this.hostname));var U=this.port?":"+this.port:"",P=this.hostname||"";this.host=P+U,this.href+=this.host,_&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),a[0]!=="/"&&(a="/"+a))}if(!gw[c])for(var f=0,g=Tl.length;f<g;f++){var E=Tl[f];if(a.indexOf(E)!==-1){var T=encodeURIComponent(E);T===E&&(T=escape(E)),a=a.split(E).join(T)}}var A=a.indexOf("#");A!==-1&&(this.hash=a.substr(A),a=a.slice(0,A));var O=a.indexOf("?");if(O!==-1?(this.search=a.substr(O),this.query=a.substr(O+1),t&&(this.query=Sl.parse(this.query)),a=a.slice(0,O)):t&&(this.search="",this.query={}),a&&(this.pathname=a),Zi[c]&&this.hostname&&!this.pathname&&(this.pathname="/"),this.pathname||this.search){var U=this.pathname||"",D=this.search||"";this.path=U+D}return this.href=this.format(),this},br.prototype.format=function(){var r=this.auth||"";r&&(r=encodeURIComponent(r),r=r.replace(/%3A/i,":"),r+="@");var t=this.protocol||"",e=this.pathname||"",i=this.hash||"",n=!1,s="";this.host?n=r+this.host:this.hostname&&(n=r+(this.hostname.indexOf(":")===-1?this.hostname:"["+this.hostname+"]"),this.port&&(n+=":"+this.port)),this.query&&typeof this.query=="object"&&Object.keys(this.query).length&&(s=Sl.stringify(this.query,{arrayFormat:"repeat",addQueryPrefix:!1}));var o=this.search||s&&"?"+s||"";return t&&t.substr(-1)!==":"&&(t+=":"),this.slashes||(!t||Zi[t])&&n!==!1?(n="//"+(n||""),e&&e.charAt(0)!=="/"&&(e="/"+e)):n||(n=""),i&&i.charAt(0)!=="#"&&(i="#"+i),o&&o.charAt(0)!=="?"&&(o="?"+o),e=e.replace(/[?#]/g,function(a){return encodeURIComponent(a)}),o=o.replace("#","%23"),t+n+e+o+i},br.prototype.resolve=function(r){return this.resolveObject(yw(r,!1,!0)).format()},br.prototype.resolveObject=function(r){if(typeof r=="string"){var t=new br;t.parse(r,!1,!0),r=t}for(var e=new br,i=Object.keys(this),n=0;n<i.length;n++){var s=i[n];e[s]=this[s]}if(e.hash=r.hash,r.href==="")return e.href=e.format(),e;if(r.slashes&&!r.protocol){for(var o=Object.keys(r),a=0;a<o.length;a++){var l=o[a];l!=="protocol"&&(e[l]=r[l])}return Zi[e.protocol]&&e.hostname&&!e.pathname&&(e.pathname="/",e.path=e.pathname),e.href=e.format(),e}if(r.protocol&&r.protocol!==e.protocol){if(!Zi[r.protocol]){for(var h=Object.keys(r),c=0;c<h.length;c++){var u=h[c];e[u]=r[u]}return e.href=e.format(),e}if(e.protocol=r.protocol,!r.host&&!Al[r.protocol]){for(var g=(r.pathname||"").split("/");g.length&&!(r.host=g.shift()););r.host||(r.host=""),r.hostname||(r.hostname=""),g[0]!==""&&g.unshift(""),g.length<2&&g.unshift(""),e.pathname=g.join("/")}else e.pathname=r.pathname;if(e.search=r.search,e.query=r.query,e.host=r.host||"",e.auth=r.auth,e.hostname=r.hostname||r.host,e.port=r.port,e.pathname||e.search){var d=e.pathname||"",f=e.search||"";e.path=d+f}return e.slashes=e.slashes||r.slashes,e.href=e.format(),e}var p=e.pathname&&e.pathname.charAt(0)==="/",m=r.host||r.pathname&&r.pathname.charAt(0)==="/",y=m||p||e.host&&r.pathname,_=y,v=e.pathname&&e.pathname.split("/")||[],g=r.pathname&&r.pathname.split("/")||[],b=e.protocol&&!Zi[e.protocol];if(b&&(e.hostname="",e.port=null,e.host&&(v[0]===""?v[0]=e.host:v.unshift(e.host)),e.host="",r.protocol&&(r.hostname=null,r.port=null,r.host&&(g[0]===""?g[0]=r.host:g.unshift(r.host)),r.host=null),y=y&&(g[0]===""||v[0]==="")),m)e.host=r.host||r.host===""?r.host:e.host,e.hostname=r.hostname||r.hostname===""?r.hostname:e.hostname,e.search=r.search,e.query=r.query,v=g;else if(g.length)v||(v=[]),v.pop(),v=v.concat(g),e.search=r.search,e.query=r.query;else if(r.search!=null){if(b){e.host=v.shift(),e.hostname=e.host;var S=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;S&&(e.auth=S.shift(),e.hostname=S.shift(),e.host=e.hostname)}return e.search=r.search,e.query=r.query,(e.pathname!==null||e.search!==null)&&(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.href=e.format(),e}if(!v.length)return e.pathname=null,e.search?e.path="/"+e.search:e.path=null,e.href=e.format(),e;for(var R=v.slice(-1)[0],C=(e.host||r.host||v.length>1)&&(R==="."||R==="..")||R==="",I=0,M=v.length;M>=0;M--)R=v[M],R==="."?v.splice(M,1):R===".."?(v.splice(M,1),I++):I&&(v.splice(M,1),I--);if(!y&&!_)for(;I--;I)v.unshift("..");y&&v[0]!==""&&(!v[0]||v[0].charAt(0)!=="/")&&v.unshift(""),C&&v.join("/").substr(-1)!=="/"&&v.push("");var F=v[0]===""||v[0]&&v[0].charAt(0)==="/";if(b){e.hostname=F?"":v.length?v.shift():"",e.host=e.hostname;var S=e.host&&e.host.indexOf("@")>0?e.host.split("@"):!1;S&&(e.auth=S.shift(),e.hostname=S.shift(),e.host=e.hostname)}return y=y||e.host&&v.length,y&&!F&&v.unshift(""),v.length>0?e.pathname=v.join("/"):(e.pathname=null,e.path=null),(e.pathname!==null||e.search!==null)&&(e.path=(e.pathname?e.pathname:"")+(e.search?e.search:"")),e.auth=r.auth||e.auth,e.slashes=e.slashes||r.slashes,e.href=e.format(),e},br.prototype.parseHost=function(){var r=this.host,t=cw.exec(r);t&&(t=t[0],t!==":"&&(this.port=t.substr(1)),r=r.substr(0,r.length-t.length)),r&&(this.hostname=r)};const _f={};function At(r,t,e=3){if(_f[t])return;let i=new Error().stack;typeof i>"u"?console.warn("PixiJS Deprecation Warning: ",`${t}
6
6
  Deprecated since v${r}`):(i=i.split(`
7
7
  `).splice(e).join(`
8
8
  `),console.groupCollapsed?(console.groupCollapsed("%cPixiJS Deprecation Warning: %c%s","color:#614108;background:#fffbe6","font-weight:normal;color:#614108;background:#fffbe6",`${t}
@@ -908,7 +908,7 @@ ${u}`)}});return await Promise.all(l),s?n[o[0].src]:n}async unload(t){const e=qe
908
908
  };
909
909
  })();
910
910
  `;let ln=null;class zp{constructor(){ln||(ln=URL.createObjectURL(new Blob([sA],{type:"application/javascript"}))),this.worker=new Worker(ln)}}zp.revokeObjectURL=function(){ln&&(URL.revokeObjectURL(ln),ln=null)};let Yp=0,gh;class oA{constructor(){this._initialized=!1,this._createdWorkers=0,this.workerPool=[],this.queue=[],this.resolveHash={}}isImageBitmapSupported(){return this._isImageBitmapSupported!==void 0?this._isImageBitmapSupported:(this._isImageBitmapSupported=new Promise(t=>{const{worker:e}=new mh;e.addEventListener("message",i=>{e.terminate(),mh.revokeObjectURL(),t(i.data)})}),this._isImageBitmapSupported)}loadImageBitmap(t){return this._run("loadImageBitmap",[t])}async _initWorkers(){this._initialized||(this._initialized=!0)}getWorker(){gh===void 0&&(gh=navigator.hardwareConcurrency||4);let t=this.workerPool.pop();return!t&&this._createdWorkers<gh&&(this._createdWorkers++,t=new zp().worker,t.addEventListener("message",e=>{this.complete(e.data),this.returnWorker(e.target),this.next()})),t}returnWorker(t){this.workerPool.push(t)}complete(t){t.error!==void 0?this.resolveHash[t.uuid].reject(t.error):this.resolveHash[t.uuid].resolve(t.data),this.resolveHash[t.uuid]=null}async _run(t,e){await this._initWorkers();const i=new Promise((n,s)=>{this.queue.push({id:t,arguments:e,resolve:n,reject:s})});return this.next(),i}next(){if(!this.queue.length)return;const t=this.getWorker();if(!t)return;const e=this.queue.pop(),i=e.id;this.resolveHash[Yp]={resolve:e.resolve,reject:e.reject},t.postMessage({data:e.arguments,uuid:Yp++,id:i})}}const qp=new oA;function Jn(r,t,e){r.resource.internal=!0;const i=new ct(r),n=()=>{delete t.promiseCache[e],wi.has(e)&&wi.remove(e)};return i.baseTexture.once("destroyed",()=>{e in t.promiseCache&&(console.warn("[Assets] A BaseTexture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the BaseTexture."),n())}),i.once("destroyed",()=>{r.destroyed||(console.warn("[Assets] A Texture managed by Assets was destroyed instead of unloaded! Use Assets.unload() instead of destroying the Texture."),n())}),i}const aA=[".jpeg",".jpg",".png",".webp",".avif"],lA=["image/jpeg","image/png","image/webp","image/avif"];async function hA(r){const t=await tt.ADAPTER.fetch(r);if(!t.ok)throw new Error(`[loadImageBitmap] Failed to fetch ${r}: ${t.status} ${t.statusText}`);const e=await t.blob();return await createImageBitmap(e)}const _o={name:"loadTextures",extension:{type:Z.LoadParser,priority:Ke.High},config:{preferWorkers:!0,preferCreateImageBitmap:!0,crossOrigin:"anonymous"},test(r){return on(r,lA)||Vr(r,aA)},async load(r,t,e){var a;const i=globalThis.createImageBitmap&&this.config.preferCreateImageBitmap;let n;i?this.config.preferWorkers&&await qp.isImageBitmapSupported()?n=await qp.loadImageBitmap(r):n=await hA(r):n=await new Promise((l,h)=>{const c=new Image;c.crossOrigin=this.config.crossOrigin,c.src=r,c.complete?l(c):(c.onload=()=>l(c),c.onerror=u=>h(u))});const s={...t.data};s.resolution??(s.resolution=wr(r)),i&&((a=s.resourceOptions)==null?void 0:a.ownsImageBitmap)===void 0&&(s.resourceOptions={...s.resourceOptions},s.resourceOptions.ownsImageBitmap=!0);const o=new bt(n,s);return o.resource.src=r,Jn(o,e,r)},unload(r){r.destroy(!0)}};ht.add(_o);const cA=".svg",uA="image/svg+xml",dA={extension:{type:Z.LoadParser,priority:Ke.High},name:"loadSVG",test(r){return on(r,uA)||Vr(r,cA)},async testParse(r){return ah.test(r)},async parse(r,t,e){var s;const i=new ah(r,(s=t==null?void 0:t.data)==null?void 0:s.resourceOptions);await i.load();const n=new bt(i,{resolution:wr(r),...t==null?void 0:t.data});return n.resource.src=t.src,Jn(n,e,t.src)},async load(r,t){return(await tt.ADAPTER.fetch(r)).text()},unload:_o.unload};ht.add(dA);const fA=[".mp4",".m4v",".webm",".ogv"],pA=["video/mp4","video/webm","video/ogg"],mA={name:"loadVideo",extension:{type:Z.LoadParser,priority:Ke.High},config:{defaultAutoPlay:!0,defaultUpdateFPS:0,defaultLoop:!1,defaultMuted:!1,defaultPlaysinline:!0},test(r){return on(r,pA)||Vr(r,fA)},async load(r,t,e){var o;let i;const n=await(await tt.ADAPTER.fetch(r)).blob(),s=URL.createObjectURL(n);try{const a={autoPlay:this.config.defaultAutoPlay,updateFPS:this.config.defaultUpdateFPS,loop:this.config.defaultLoop,muted:this.config.defaultMuted,playsinline:this.config.defaultPlaysinline,...(o=t==null?void 0:t.data)==null?void 0:o.resourceOptions,autoLoad:!0},l=new Lp(s,a);await l.load();const h=new bt(l,{alphaMode:await xw(),resolution:wr(r),...t==null?void 0:t.data});h.resource.src=r,i=Jn(h,e,r),i.baseTexture.once("destroyed",()=>{URL.revokeObjectURL(s)})}catch(a){throw URL.revokeObjectURL(s),a}return i},unload(r){r.destroy(!0)}};ht.add(mA);class gA{constructor(){this._defaultBundleIdentifierOptions={connector:"-",createBundleAssetId:(t,e)=>`${t}${this._bundleIdConnector}${e}`,extractAssetIdFromBundle:(t,e)=>e.replace(`${t}${this._bundleIdConnector}`,"")},this._bundleIdConnector=this._defaultBundleIdentifierOptions.connector,this._createBundleAssetId=this._defaultBundleIdentifierOptions.createBundleAssetId,this._extractAssetIdFromBundle=this._defaultBundleIdentifierOptions.extractAssetIdFromBundle,this._assetMap={},this._preferredOrder=[],this._parsers=[],this._resolverHash={},this._bundles={}}setBundleIdentifier(t){if(this._bundleIdConnector=t.connector??this._bundleIdConnector,this._createBundleAssetId=t.createBundleAssetId??this._createBundleAssetId,this._extractAssetIdFromBundle=t.extractAssetIdFromBundle??this._extractAssetIdFromBundle,this._extractAssetIdFromBundle("foo",this._createBundleAssetId("foo","bar"))!=="bar")throw new Error("[Resolver] GenerateBundleAssetId are not working correctly")}prefer(...t){t.forEach(e=>{this._preferredOrder.push(e),e.priority||(e.priority=Object.keys(e.params))}),this._resolverHash={}}set basePath(t){this._basePath=t}get basePath(){return this._basePath}set rootPath(t){this._rootPath=t}get rootPath(){return this._rootPath}get parsers(){return this._parsers}reset(){this.setBundleIdentifier(this._defaultBundleIdentifierOptions),this._assetMap={},this._preferredOrder=[],this._resolverHash={},this._rootPath=null,this._basePath=null,this._manifest=null,this._bundles={},this._defaultSearchParams=null}setDefaultSearchParams(t){if(typeof t=="string")this._defaultSearchParams=t;else{const e=t;this._defaultSearchParams=Object.keys(e).map(i=>`${encodeURIComponent(i)}=${encodeURIComponent(e[i])}`).join("&")}}getAlias(t){const{alias:e,name:i,src:n,srcs:s}=t;return qe(e||i||n||s,o=>typeof o=="string"?o:Array.isArray(o)?o.map(a=>(a==null?void 0:a.src)??(a==null?void 0:a.srcs)??a):o!=null&&o.src||o!=null&&o.srcs?o.src??o.srcs:o,!0)}addManifest(t){this._manifest&&console.warn("[Resolver] Manifest already exists, this will be overwritten"),this._manifest=t,t.bundles.forEach(e=>{this.addBundle(e.name,e.assets)})}addBundle(t,e){const i=[];Array.isArray(e)?e.forEach(n=>{const s=n.src??n.srcs,o=n.alias??n.name;let a;if(typeof o=="string"){const l=this._createBundleAssetId(t,o);i.push(l),a=[o,l]}else{const l=o.map(h=>this._createBundleAssetId(t,h));i.push(...l),a=[...o,...l]}this.add({...n,alias:a,src:s})}):Object.keys(e).forEach(n=>{const s=[n,this._createBundleAssetId(t,n)];if(typeof e[n]=="string")this.add({alias:s,src:e[n]});else if(Array.isArray(e[n]))this.add({alias:s,src:e[n]});else{const o=e[n],a=o.src??o.srcs;this.add({...o,alias:s,src:Array.isArray(a)?a:[a]})}i.push(...s)}),this._bundles[t]=i}add(t,e,i,n,s){const o=[];typeof t=="string"||Array.isArray(t)&&typeof t[0]=="string"?(At("7.2.0",`Assets.add now uses an object instead of individual parameters.
911
- Please use Assets.add({ alias, src, data, format, loadParser }) instead.`),o.push({alias:t,src:e,data:i,format:n,loadParser:s})):Array.isArray(t)?o.push(...t):o.push(t);let a;a=l=>{this.hasKey(l)&&console.warn(`[Resolver] already has key: ${l} overwriting`)},qe(o).forEach(l=>{const{src:h,srcs:c}=l;let{data:u,format:d,loadParser:f}=l;const p=qe(h||c).map(_=>typeof _=="string"?$T(_):Array.isArray(_)?_:[_]),m=this.getAlias(l);Array.isArray(m)?m.forEach(a):a(m);const y=[];p.forEach(_=>{_.forEach(v=>{let g={};if(typeof v!="object"){g.src=v;for(let b=0;b<this._parsers.length;b++){const S=this._parsers[b];if(S.test(v)){g=S.parse(v);break}}}else u=v.data??u,d=v.format??d,f=v.loadParser??f,g={...g,...v};if(!m)throw new Error(`[Resolver] alias is undefined for this asset: ${g.src}`);g=this.buildResolvedAsset(g,{aliases:m,data:u,format:d,loadParser:f}),y.push(g)})}),m.forEach(_=>{this._assetMap[_]=y})})}resolveBundle(t){const e=yo(t);t=qe(t);const i={};return t.forEach(n=>{const s=this._bundles[n];if(s){const o=this.resolve(s),a={};for(const l in o){const h=o[l];a[this._extractAssetIdFromBundle(n,l)]=h}i[n]=a}}),e?i[t[0]]:i}resolveUrl(t){const e=this.resolve(t);if(typeof t!="string"){const i={};for(const n in e)i[n]=e[n].src;return i}return e.src}resolve(t){const e=yo(t);t=qe(t);const i={};return t.forEach(n=>{if(!this._resolverHash[n])if(this._assetMap[n]){let s=this._assetMap[n];const o=s[0],a=this._getPreferredOrder(s);a==null||a.priority.forEach(l=>{a.params[l].forEach(h=>{const c=s.filter(u=>u[l]?u[l]===h:!1);c.length&&(s=c)})}),this._resolverHash[n]=s[0]??o}else this._resolverHash[n]=this.buildResolvedAsset({alias:[n],src:n},{});i[n]=this._resolverHash[n]}),e?i[t[0]]:i}hasKey(t){return!!this._assetMap[t]}hasBundle(t){return!!this._bundles[t]}_getPreferredOrder(t){for(let e=0;e<t.length;e++){const i=t[0],n=this._preferredOrder.find(s=>s.params.format.includes(i.format));if(n)return n}return this._preferredOrder[0]}_appendDefaultSearchParams(t){if(!this._defaultSearchParams)return t;const e=/\?/.test(t)?"&":"?";return`${t}${e}${this._defaultSearchParams}`}buildResolvedAsset(t,e){const{aliases:i,data:n,loadParser:s,format:o}=e;return(this._basePath||this._rootPath)&&(t.src=ue.toAbsolute(t.src,this._basePath,this._rootPath)),t.alias=i??t.alias??[t.src],t.src=this._appendDefaultSearchParams(t.src),t.data={...n||{},...t.data},t.loadParser=s??t.loadParser,t.format=o??t.format??ue.extname(t.src).slice(1),t.srcs=t.src,t.name=t.alias,t}}class yA{constructor(){this._detections=[],this._initialized=!1,this.resolver=new gA,this.loader=new XT,this.cache=wi,this._backgroundLoader=new GT(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(t={}){var s,o;if(this._initialized){console.warn("[Assets]AssetManager already initialized, did you load before calling this Assets.init()?");return}if(this._initialized=!0,t.defaultSearchParams&&this.resolver.setDefaultSearchParams(t.defaultSearchParams),t.basePath&&(this.resolver.basePath=t.basePath),t.bundleIdentifier&&this.resolver.setBundleIdentifier(t.bundleIdentifier),t.manifest){let a=t.manifest;typeof a=="string"&&(a=await this.load(a)),this.resolver.addManifest(a)}const e=((s=t.texturePreference)==null?void 0:s.resolution)??1,i=typeof e=="number"?[e]:e,n=await this._detectFormats({preferredFormats:(o=t.texturePreference)==null?void 0:o.format,skipDetections:t.skipDetections,detections:this._detections});this.resolver.prefer({params:{format:n,resolution:i}}),t.preferences&&this.setPreferences(t.preferences)}add(t,e,i,n,s){this.resolver.add(t,e,i,n,s)}async load(t,e){this._initialized||await this.init();const i=yo(t),n=qe(t).map(a=>{if(typeof a!="string"){const l=this.resolver.getAlias(a);return l.some(h=>!this.resolver.hasKey(h))&&this.add(a),Array.isArray(l)?l[0]:l}return this.resolver.hasKey(a)||this.add({alias:a,src:a}),a}),s=this.resolver.resolve(n),o=await this._mapLoadToResolve(s,e);return i?o[n[0]]:o}addBundle(t,e){this.resolver.addBundle(t,e)}async loadBundle(t,e){this._initialized||await this.init();let i=!1;typeof t=="string"&&(i=!0,t=[t]);const n=this.resolver.resolveBundle(t),s={},o=Object.keys(n);let a=0,l=0;const h=()=>{e==null||e(++a/l)},c=o.map(u=>{const d=n[u];return l+=Object.keys(d).length,this._mapLoadToResolve(d,h).then(f=>{s[u]=f})});return await Promise.all(c),i?s[t[0]]:s}async backgroundLoad(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolve(t);this._backgroundLoader.add(Object.values(e))}async backgroundLoadBundle(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolveBundle(t);Object.values(e).forEach(i=>{this._backgroundLoader.add(Object.values(i))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(t){if(typeof t=="string")return wi.get(t);const e={};for(let i=0;i<t.length;i++)e[i]=wi.get(t[i]);return e}async _mapLoadToResolve(t,e){const i=Object.values(t),n=Object.keys(t);this._backgroundLoader.active=!1;const s=await this.loader.load(i,e);this._backgroundLoader.active=!0;const o={};return i.forEach((a,l)=>{const h=s[a.src],c=[a.src];a.alias&&c.push(...a.alias),o[n[l]]=h,wi.set(c,h)}),o}async unload(t){this._initialized||await this.init();const e=qe(t).map(n=>typeof n!="string"?n.src:n),i=this.resolver.resolve(e);await this._unloadFromResolved(i)}async unloadBundle(t){this._initialized||await this.init(),t=qe(t);const e=this.resolver.resolveBundle(t),i=Object.keys(e).map(n=>this._unloadFromResolved(e[n]));await Promise.all(i)}async _unloadFromResolved(t){const e=Object.values(t);e.forEach(i=>{wi.remove(i.src)}),await this.loader.unload(e)}async _detectFormats(t){let e=[];t.preferredFormats&&(e=Array.isArray(t.preferredFormats)?t.preferredFormats:[t.preferredFormats]);for(const i of t.detections)t.skipDetections||await i.test()?e=await i.add(e):t.skipDetections||(e=await i.remove(e));return e=e.filter((i,n)=>e.indexOf(i)===n),e}get detections(){return this._detections}get preferWorkers(){return _o.config.preferWorkers}set preferWorkers(t){At("7.2.0","Assets.prefersWorkers is deprecated, use Assets.setPreferences({ preferWorkers: true }) instead."),this.setPreferences({preferWorkers:t})}setPreferences(t){this.loader.parsers.forEach(e=>{e.config&&Object.keys(e.config).filter(i=>i in t).forEach(i=>{e.config[i]=t[i]})})}}const vo=new yA;ht.handleByList(Z.LoadParser,vo.loader.parsers).handleByList(Z.ResolveParser,vo.resolver.parsers).handleByList(Z.CacheParser,vo.cache.parsers).handleByList(Z.DetectionParser,vo.detections);const _A={extension:Z.CacheParser,test:r=>Array.isArray(r)&&r.every(t=>t instanceof ct),getCacheableAssets:(r,t)=>{const e={};return r.forEach(i=>{t.forEach((n,s)=>{e[i+(s===0?"":s+1)]=n})}),e}};ht.add(_A);async function Kp(r){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(r)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const vA={extension:{type:Z.DetectionParser,priority:1},test:async()=>Kp("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(t=>t!=="avif")};ht.add(vA);const bA={extension:{type:Z.DetectionParser,priority:0},test:async()=>Kp("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(t=>t!=="webp")};ht.add(bA);const Zp=["png","jpg","jpeg"],xA={extension:{type:Z.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Zp],remove:async r=>r.filter(t=>!Zp.includes(t))};ht.add(xA);const wA="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function yh(r){return wA?!1:document.createElement("video").canPlayType(r)!==""}const EA={extension:{type:Z.DetectionParser,priority:0},test:async()=>yh("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(t=>t!=="webm")};ht.add(EA);const TA={extension:{type:Z.DetectionParser,priority:0},test:async()=>yh("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(t=>t!=="mp4"&&t!=="m4v")};ht.add(TA);const AA={extension:{type:Z.DetectionParser,priority:0},test:async()=>yh("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(t=>t!=="ogv")};ht.add(AA);const SA={extension:Z.ResolveParser,test:_o.test,parse:r=>{var t;return{resolution:parseFloat(((t=tt.RETINA_PREFIX.exec(r))==null?void 0:t[1])??"1"),format:ue.extname(r).slice(1),src:r}}};ht.add(SA);var be=(r=>(r[r.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",r[r.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",r[r.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",r[r.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",r[r.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",r[r.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",r[r.COMPRESSED_RGBA8_ETC2_EAC=37496]="COMPRESSED_RGBA8_ETC2_EAC",r[r.COMPRESSED_SRGB8_ETC2=37493]="COMPRESSED_SRGB8_ETC2",r[r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37497]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",r[r.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37494]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37495]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",r[r.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",r[r.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35987]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",r[r.COMPRESSED_RGBA_BPTC_UNORM_EXT=36492]="COMPRESSED_RGBA_BPTC_UNORM_EXT",r[r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT=36493]="COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT",r[r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT=36494]="COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT",r[r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT=36495]="COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT",r))(be||{});const bo={33776:.5,33777:.5,33778:1,33779:1,35916:.5,35917:.5,35918:1,35919:1,37488:.5,37489:.5,37490:1,37491:1,37492:.5,37496:1,37493:.5,37497:1,37494:.5,37495:.5,35840:.5,35842:.5,35841:.25,35843:.25,36196:.5,35986:.5,35987:1,34798:1,37808:1,36492:1,36493:1,36494:1,36495:1};let fr,hn;function Qp(){hn={bptc:fr.getExtension("EXT_texture_compression_bptc"),astc:fr.getExtension("WEBGL_compressed_texture_astc"),etc:fr.getExtension("WEBGL_compressed_texture_etc"),s3tc:fr.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:fr.getExtension("WEBGL_compressed_texture_s3tc_srgb"),pvrtc:fr.getExtension("WEBGL_compressed_texture_pvrtc")||fr.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),etc1:fr.getExtension("WEBGL_compressed_texture_etc1"),atc:fr.getExtension("WEBGL_compressed_texture_atc")}}const CA={extension:{type:Z.DetectionParser,priority:2},test:async()=>{const r=tt.ADAPTER.createCanvas().getContext("webgl");return r?(fr=r,!0):(console.warn("WebGL not available for compressed textures."),!1)},add:async r=>{hn||Qp();const t=[];for(const e in hn)hn[e]&&t.push(e);return[...t,...r]},remove:async r=>(hn||Qp(),r.filter(t=>!(t in hn)))};ht.add(CA);class IA extends zs{constructor(t,e={width:1,height:1,autoLoad:!0}){let i,n;typeof t=="string"?(i=t,n=new Uint8Array):(i=null,n=t),super(n,e),this.origin=i,this.buffer=n?new Nl(n):null,this._load=null,this.loaded=!1,this.origin!==null&&e.autoLoad!==!1&&this.load(),this.origin===null&&this.buffer&&(this._load=Promise.resolve(this),this.loaded=!0,this.onBlobLoaded(this.buffer.rawBinaryData))}onBlobLoaded(t){}load(){return this._load?this._load:(this._load=fetch(this.origin).then(t=>t.blob()).then(t=>t.arrayBuffer()).then(t=>(this.data=new Uint32Array(t),this.buffer=new Nl(t),this.loaded=!0,this.onBlobLoaded(t),this.update(),this)),this._load)}}class Ei extends IA{constructor(t,e){super(t,e),this.format=e.format,this.levels=e.levels||1,this._width=e.width,this._height=e.height,this._extension=Ei._formatToExtension(this.format),(e.levelBuffers||this.buffer)&&(this._levelBuffers=e.levelBuffers||Ei._createLevelBuffers(t instanceof Uint8Array?t:this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height))}upload(t,e,i){const n=t.gl;if(!t.context.extensions[this._extension])throw new Error(`${this._extension} textures are not supported on the current machine`);if(!this._levelBuffers)return!1;n.pixelStorei(n.UNPACK_ALIGNMENT,4);for(let s=0,o=this.levels;s<o;s++){const{levelID:a,levelWidth:l,levelHeight:h,levelBuffer:c}=this._levelBuffers[s];n.compressedTexImage2D(n.TEXTURE_2D,a,this.format,l,h,0,c)}return!0}onBlobLoaded(){this._levelBuffers=Ei._createLevelBuffers(this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height)}static _formatToExtension(t){if(t>=33776&&t<=33779)return"s3tc";if(t>=35916&&t<=35919)return"s3tc_sRGB";if(t>=37488&&t<=37497)return"etc";if(t>=35840&&t<=35843)return"pvrtc";if(t===36196)return"etc1";if(t===35986||t===35987||t===34798)return"atc";if(t>=36492&&t<=36495)return"bptc";if(t===37808)return"astc";throw new Error(`Invalid (compressed) texture format given: ${t}`)}static _createLevelBuffers(t,e,i,n,s,o,a){const l=new Array(i);let h=t.byteOffset,c=o,u=a,d=c+n-1&~(n-1),f=u+s-1&~(s-1),p=d*f*bo[e];for(let m=0;m<i;m++)l[m]={levelID:m,levelWidth:i>1?c:d,levelHeight:i>1?u:f,levelBuffer:new Uint8Array(t.buffer,h,p)},h+=p,c=c>>1||1,u=u>>1||1,d=c+n-1&~(n-1),f=u+s-1&~(s-1),p=d*f*bo[e];return l}}const _h=4,xo=124,PA=32,Jp=20,RA=542327876,wo={HEIGHT:3,WIDTH:4,MIPMAP_COUNT:7,PIXEL_FORMAT:19},MA={FOURCC:2},Eo={DXGI_FORMAT:0,RESOURCE_DIMENSION:1,MISC_FLAG:2,ARRAY_SIZE:3},DA=1,BA=2,OA=4,LA=64,NA=512,FA=131072,kA=827611204,UA=861165636,GA=894720068,$A=808540228,HA=4,XA={[kA]:be.COMPRESSED_RGBA_S3TC_DXT1_EXT,[UA]:be.COMPRESSED_RGBA_S3TC_DXT3_EXT,[GA]:be.COMPRESSED_RGBA_S3TC_DXT5_EXT},VA={70:be.COMPRESSED_RGBA_S3TC_DXT1_EXT,71:be.COMPRESSED_RGBA_S3TC_DXT1_EXT,73:be.COMPRESSED_RGBA_S3TC_DXT3_EXT,74:be.COMPRESSED_RGBA_S3TC_DXT3_EXT,76:be.COMPRESSED_RGBA_S3TC_DXT5_EXT,77:be.COMPRESSED_RGBA_S3TC_DXT5_EXT,72:be.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,75:be.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,78:be.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,96:be.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,95:be.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,98:be.COMPRESSED_RGBA_BPTC_UNORM_EXT,99:be.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT};function jA(r){const t=new Uint32Array(r);if(t[0]!==RA)throw new Error("Invalid DDS file magic word");const e=new Uint32Array(r,0,xo/Uint32Array.BYTES_PER_ELEMENT),i=e[wo.HEIGHT],n=e[wo.WIDTH],s=e[wo.MIPMAP_COUNT],o=new Uint32Array(r,wo.PIXEL_FORMAT*Uint32Array.BYTES_PER_ELEMENT,PA/Uint32Array.BYTES_PER_ELEMENT),a=o[DA];if(a&OA){const l=o[MA.FOURCC];if(l!==$A){const v=XA[l],g=_h+xo,b=new Uint8Array(r,g);return[new Ei(b,{format:v,width:n,height:i,levels:s})]}const h=_h+xo,c=new Uint32Array(t.buffer,h,Jp/Uint32Array.BYTES_PER_ELEMENT),u=c[Eo.DXGI_FORMAT],d=c[Eo.RESOURCE_DIMENSION],f=c[Eo.MISC_FLAG],p=c[Eo.ARRAY_SIZE],m=VA[u];if(m===void 0)throw new Error(`DDSParser cannot parse texture data with DXGI format ${u}`);if(f===HA)throw new Error("DDSParser does not support cubemap textures");if(d===6)throw new Error("DDSParser does not supported 3D texture data");const y=new Array,_=_h+xo+Jp;if(p===1)y.push(new Uint8Array(r,_));else{const v=bo[m];let g=0,b=n,S=i;for(let C=0;C<s;C++){const I=Math.max(1,b+3&-4),M=Math.max(1,S+3&-4),F=I*M*v;g+=F,b=b>>>1,S=S>>>1}let R=_;for(let C=0;C<p;C++)y.push(new Uint8Array(r,R,g)),R+=g}return y.map(v=>new Ei(v,{format:m,width:n,height:i,levels:s}))}throw a&LA?new Error("DDSParser does not support uncompressed texture data."):a&NA?new Error("DDSParser does not supported YUV uncompressed texture data."):a&FA?new Error("DDSParser does not support single-channel (lumninance) texture data!"):a&BA?new Error("DDSParser does not support single-channel (alpha) texture data!"):new Error("DDSParser failed to load a texture file due to an unknown reason!")}const tm=[171,75,84,88,32,49,49,187,13,10,26,10],WA=67305985,Ze={ENDIANNESS:12,GL_TYPE:16,GL_FORMAT:24,GL_INTERNAL_FORMAT:28,PIXEL_WIDTH:36,PIXEL_HEIGHT:40,PIXEL_DEPTH:44,NUMBER_OF_ARRAY_ELEMENTS:48,NUMBER_OF_FACES:52,NUMBER_OF_MIPMAP_LEVELS:56,BYTES_OF_KEY_VALUE_DATA:60},vh=64,em={[pt.UNSIGNED_BYTE]:1,[pt.UNSIGNED_SHORT]:2,[pt.INT]:4,[pt.UNSIGNED_INT]:4,[pt.FLOAT]:4,[pt.HALF_FLOAT]:8},zA={[W.RGBA]:4,[W.RGB]:3,[W.RG]:2,[W.RED]:1,[W.LUMINANCE]:1,[W.LUMINANCE_ALPHA]:2,[W.ALPHA]:1},YA={[pt.UNSIGNED_SHORT_4_4_4_4]:2,[pt.UNSIGNED_SHORT_5_5_5_1]:2,[pt.UNSIGNED_SHORT_5_6_5]:2};function qA(r,t,e=!1){const i=new DataView(t);if(!KA(r,i))return null;const n=i.getUint32(Ze.ENDIANNESS,!0)===WA,s=i.getUint32(Ze.GL_TYPE,n),o=i.getUint32(Ze.GL_FORMAT,n),a=i.getUint32(Ze.GL_INTERNAL_FORMAT,n),l=i.getUint32(Ze.PIXEL_WIDTH,n),h=i.getUint32(Ze.PIXEL_HEIGHT,n)||1,c=i.getUint32(Ze.PIXEL_DEPTH,n)||1,u=i.getUint32(Ze.NUMBER_OF_ARRAY_ELEMENTS,n)||1,d=i.getUint32(Ze.NUMBER_OF_FACES,n),f=i.getUint32(Ze.NUMBER_OF_MIPMAP_LEVELS,n),p=i.getUint32(Ze.BYTES_OF_KEY_VALUE_DATA,n);if(h===0||c!==1)throw new Error("Only 2D textures are supported");if(d!==1)throw new Error("CubeTextures are not supported by KTXLoader yet!");if(u!==1)throw new Error("WebGL does not support array textures");const m=4,y=4,_=l+3&-4,v=h+3&-4,g=new Array(u);let b=l*h;s===0&&(b=_*v);let S;if(s!==0?em[s]?S=em[s]*zA[o]:S=YA[s]:S=bo[a],S===void 0)throw new Error("Unable to resolve the pixel format stored in the *.ktx file!");const R=e?QA(i,p,n):null;let C=b*S,I=l,M=h,F=_,U=v,P=vh+p;for(let T=0;T<f;T++){const E=i.getUint32(P,n);let A=P+4;for(let L=0;L<u;L++){let D=g[L];D||(D=g[L]=new Array(f)),D[T]={levelID:T,levelWidth:f>1||s!==0?I:F,levelHeight:f>1||s!==0?M:U,levelBuffer:new Uint8Array(t,A,C)},A+=C}P+=E+4,P=P%4!==0?P+4-P%4:P,I=I>>1||1,M=M>>1||1,F=I+m-1&-4,U=M+y-1&-4,C=F*U*S}return s!==0?{uncompressed:g.map(T=>{let E=T[0].levelBuffer,A=!1;return s===pt.FLOAT?E=new Float32Array(T[0].levelBuffer.buffer,T[0].levelBuffer.byteOffset,T[0].levelBuffer.byteLength/4):s===pt.UNSIGNED_INT?(A=!0,E=new Uint32Array(T[0].levelBuffer.buffer,T[0].levelBuffer.byteOffset,T[0].levelBuffer.byteLength/4)):s===pt.INT&&(A=!0,E=new Int32Array(T[0].levelBuffer.buffer,T[0].levelBuffer.byteOffset,T[0].levelBuffer.byteLength/4)),{resource:new zs(E,{width:T[0].levelWidth,height:T[0].levelHeight}),type:s,format:A?ZA(o):o}}),kvData:R}:{compressed:g.map(T=>new Ei(null,{format:a,width:l,height:h,levels:f,levelBuffers:T})),kvData:R}}function KA(r,t){for(let e=0;e<tm.length;e++)if(t.getUint8(e)!==tm[e])return console.error(`${r} is not a valid *.ktx file!`),!1;return!0}function ZA(r){switch(r){case W.RGBA:return W.RGBA_INTEGER;case W.RGB:return W.RGB_INTEGER;case W.RG:return W.RG_INTEGER;case W.RED:return W.RED_INTEGER;default:return r}}function QA(r,t,e){const i=new Map;let n=0;for(;n<t;){const s=r.getUint32(vh+n,e),o=vh+n+4,a=3-(s+3)%4;if(s===0||s>t-n){console.error("KTXLoader: keyAndValueByteSize out of bounds");break}let l=0;for(;l<s&&r.getUint8(o+l)!==0;l++);if(l===-1){console.error("KTXLoader: Failed to find null byte terminating kvData key");break}const h=new TextDecoder().decode(new Uint8Array(r.buffer,o,l)),c=new DataView(r.buffer,o+l+1,s-l-1);i.set(h,c),n+=4+s+a}return i}const JA={extension:{type:Z.LoadParser,priority:Ke.High},name:"loadDDS",test(r){return Vr(r,".dds")},async load(r,t,e){const i=await(await tt.ADAPTER.fetch(r)).arrayBuffer(),n=jA(i).map(s=>{const o=new bt(s,{mipmap:ir.OFF,alphaMode:Re.NO_PREMULTIPLIED_ALPHA,resolution:wr(r),...t.data});return Jn(o,e,r)});return n.length===1?n[0]:n},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};ht.add(JA);const tS={extension:{type:Z.LoadParser,priority:Ke.High},name:"loadKTX",test(r){return Vr(r,".ktx")},async load(r,t,e){const i=await(await tt.ADAPTER.fetch(r)).arrayBuffer(),{compressed:n,uncompressed:s,kvData:o}=qA(r,i),a=n??s,l={mipmap:ir.OFF,alphaMode:Re.NO_PREMULTIPLIED_ALPHA,resolution:wr(r),...t.data},h=a.map(c=>{a===s&&Object.assign(l,{type:c.type,format:c.format});const u=c.resource??c,d=new bt(u,l);return d.ktxKeyValueData=o,Jn(d,e,r)});return h.length===1?h[0]:h},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};ht.add(tS);const eS=["s3tc","s3tc_sRGB","etc","etc1","pvrtc","atc","astc","bptc"],rS={extension:Z.ResolveParser,test:r=>{const t=ue.extname(r).slice(1);return["basis","ktx","dds"].includes(t)},parse:r=>{var i,n;const t=r.split("."),e=t.pop();if(["ktx","dds"].includes(e)){const s=t.pop();if(eS.includes(s))return{resolution:parseFloat(((i=tt.RETINA_PREFIX.exec(r))==null?void 0:i[1])??"1"),format:s,src:r}}return{resolution:parseFloat(((n=tt.RETINA_PREFIX.exec(r))==null?void 0:n[1])??"1"),format:e,src:r}}};ht.add(rS);const To=new wt,iS=4,rm=class ns{constructor(t){this.renderer=t,this._rendererPremultipliedAlpha=!1}contextChange(){var e;const t=(e=this.renderer)==null?void 0:e.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(t&&t.alpha&&t.premultipliedAlpha)}async image(t,e,i,n){const s=new Image;return s.src=await this.base64(t,e,i,n),s}async base64(t,e,i,n){const s=this.canvas(t,n);if(s.toBlob!==void 0)return new Promise((o,a)=>{s.toBlob(l=>{if(!l){a(new Error("ICanvas.toBlob failed!"));return}const h=new FileReader;h.onload=()=>o(h.result),h.onerror=a,h.readAsDataURL(l)},e,i)});if(s.toDataURL!==void 0)return s.toDataURL(e,i);if(s.convertToBlob!==void 0){const o=await s.convertToBlob({type:e,quality:i});return new Promise((a,l)=>{const h=new FileReader;h.onload=()=>a(h.result),h.onerror=l,h.readAsDataURL(o)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(t,e){const{pixels:i,width:n,height:s,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);o&&ns._flipY(i,n,s),a&&ns._unpremultiplyAlpha(i);const l=new Fw(n,s,1),h=new ImageData(new Uint8ClampedArray(i.buffer),n,s);return l.context.putImageData(h,0,0),l.canvas}pixels(t,e){const{pixels:i,width:n,height:s,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);return o&&ns._flipY(i,n,s),a&&ns._unpremultiplyAlpha(i),i}_rawPixels(t,e){const i=this.renderer;if(!i)throw new Error("The Extract has already been destroyed");let n,s=!1,o=!1,a,l=!1;t&&(t instanceof _i?a=t:(a=i.generateTexture(t,{region:e,resolution:i.resolution,multisample:i.multisample}),l=!0,e&&(To.width=e.width,To.height=e.height,e=To)));const h=i.gl;if(a){if(n=a.baseTexture.resolution,e=e??a.frame,s=!1,o=a.baseTexture.alphaMode>0&&a.baseTexture.format===W.RGBA,!l){i.renderTexture.bind(a);const f=a.framebuffer.glFramebuffers[i.CONTEXT_UID];f.blitFramebuffer&&i.framebuffer.bind(f.blitFramebuffer)}}else n=i.resolution,e||(e=To,e.width=i.width/n,e.height=i.height/n),s=!0,o=this._rendererPremultipliedAlpha,i.renderTexture.bind();const c=Math.max(Math.round(e.width*n),1),u=Math.max(Math.round(e.height*n),1),d=new Uint8Array(iS*c*u);return h.readPixels(Math.round(e.x*n),Math.round(e.y*n),c,u,h.RGBA,h.UNSIGNED_BYTE,d),l&&(a==null||a.destroy(!0)),{pixels:d,width:c,height:u,flipY:s,premultipliedAlpha:o}}destroy(){this.renderer=null}static _flipY(t,e,i){const n=e<<2,s=i>>1,o=new Uint8Array(n);for(let a=0;a<s;a++){const l=a*n,h=(i-a-1)*n;o.set(t.subarray(l,l+n)),t.copyWithin(l,h,h+n),t.set(o,h)}}static _unpremultiplyAlpha(t){t instanceof Uint8ClampedArray&&(t=new Uint8Array(t.buffer));const e=t.length;for(let i=0;i<e;i+=4){const n=t[i+3];if(n!==0){const s=255.001/n;t[i]=t[i]*s+.5,t[i+1]=t[i+1]*s+.5,t[i+2]=t[i+2]*s+.5}}}};rm.extension={name:"extract",type:Z.RendererSystem};let nS=rm;ht.add(nS);const Ao={build(r){const t=r.points;let e,i,n,s,o,a;if(r.type===ve.CIRC){const p=r.shape;e=p.x,i=p.y,o=a=p.radius,n=s=0}else if(r.type===ve.ELIP){const p=r.shape;e=p.x,i=p.y,o=p.width,a=p.height,n=s=0}else{const p=r.shape,m=p.width/2,y=p.height/2;e=p.x+m,i=p.y+y,o=a=Math.max(0,Math.min(p.radius,Math.min(m,y))),n=m-o,s=y-a}if(!(o>=0&&a>=0&&n>=0&&s>=0)){t.length=0;return}const l=Math.ceil(2.3*Math.sqrt(o+a)),h=l*8+(n?4:0)+(s?4:0);if(t.length=h,h===0)return;if(l===0){t.length=8,t[0]=t[6]=e+n,t[1]=t[3]=i+s,t[2]=t[4]=e-n,t[5]=t[7]=i-s;return}let c=0,u=l*4+(n?2:0)+2,d=u,f=h;{const p=n+o,m=s,y=e+p,_=e-p,v=i+m;if(t[c++]=y,t[c++]=v,t[--u]=v,t[--u]=_,s){const g=i-m;t[d++]=_,t[d++]=g,t[--f]=g,t[--f]=y}}for(let p=1;p<l;p++){const m=Math.PI/2*(p/l),y=n+Math.cos(m)*o,_=s+Math.sin(m)*a,v=e+y,g=e-y,b=i+_,S=i-_;t[c++]=v,t[c++]=b,t[--u]=b,t[--u]=g,t[d++]=g,t[d++]=S,t[--f]=S,t[--f]=v}{const p=n,m=s+a,y=e+p,_=e-p,v=i+m,g=i-m;t[c++]=y,t[c++]=v,t[--f]=g,t[--f]=y,n&&(t[c++]=_,t[c++]=v,t[--f]=g,t[--f]=_)}},triangulate(r,t){const e=r.points,i=t.points,n=t.indices;if(e.length===0)return;let s=i.length/2;const o=s;let a,l;if(r.type!==ve.RREC){const c=r.shape;a=c.x,l=c.y}else{const c=r.shape;a=c.x+c.width/2,l=c.y+c.height/2}const h=r.matrix;i.push(r.matrix?h.a*a+h.c*l+h.tx:a,r.matrix?h.b*a+h.d*l+h.ty:l),s++,i.push(e[0],e[1]);for(let c=2;c<e.length;c+=2)i.push(e[c],e[c+1]),n.push(s++,o,s);n.push(o+1,o,s)}};function im(r,t=!1){const e=r.length;if(e<6)return;let i=0;for(let n=0,s=r[e-2],o=r[e-1];n<e;n+=2){const a=r[n],l=r[n+1];i+=(a-s)*(l+o),s=a,o=l}if(!t&&i>0||t&&i<=0){const n=e/2;for(let s=n+n%2;s<e;s+=2){const o=e-s-2,a=e-s-1,l=s,h=s+1;[r[o],r[l]]=[r[l],r[o]],[r[a],r[h]]=[r[h],r[a]]}}}const nm={build(r){r.points=r.shape.points.slice()},triangulate(r,t){let e=r.points;const i=r.holes,n=t.points,s=t.indices;if(e.length>=6){im(e,!1);const o=[];for(let h=0;h<i.length;h++){const c=i[h];im(c.points,!0),o.push(e.length/2),e=e.concat(c.points)}const a=g1(e,o,2);if(!a)return;const l=n.length/2;for(let h=0;h<a.length;h+=3)s.push(a[h]+l),s.push(a[h+1]+l),s.push(a[h+2]+l);for(let h=0;h<e.length;h++)n.push(e[h])}}},sS={build(r){const t=r.shape,e=t.x,i=t.y,n=t.width,s=t.height,o=r.points;o.length=0,n>=0&&s>=0&&o.push(e,i,e+n,i,e+n,i+s,e,i+s)},triangulate(r,t){const e=r.points,i=t.points;if(e.length===0)return;const n=i.length/2;i.push(e[0],e[1],e[2],e[3],e[6],e[7],e[4],e[5]),t.indices.push(n,n+1,n+2,n+1,n+2,n+3)}},oS={build(r){Ao.build(r)},triangulate(r,t){Ao.triangulate(r,t)}};var Ge=(r=>(r.MITER="miter",r.BEVEL="bevel",r.ROUND="round",r))(Ge||{}),jr=(r=>(r.BUTT="butt",r.ROUND="round",r.SQUARE="square",r))(jr||{});const cn={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount(r,t=20){if(!this.adaptive||!r||isNaN(r))return t;let e=Math.ceil(r/this.maxLength);return e<this.minSegments?e=this.minSegments:e>this.maxSegments&&(e=this.maxSegments),e}};class sm{static curveTo(t,e,i,n,s,o){const a=o[o.length-2],l=o[o.length-1]-e,h=a-t,c=n-e,u=i-t,d=Math.abs(l*u-h*c);if(d<1e-8||s===0)return(o[o.length-2]!==t||o[o.length-1]!==e)&&o.push(t,e),null;const f=l*l+h*h,p=c*c+u*u,m=l*c+h*u,y=s*Math.sqrt(f)/d,_=s*Math.sqrt(p)/d,v=y*m/f,g=_*m/p,b=y*u+_*h,S=y*c+_*l,R=h*(_+v),C=l*(_+v),I=u*(y+g),M=c*(y+g),F=Math.atan2(C-S,R-b),U=Math.atan2(M-S,I-b);return{cx:b+t,cy:S+e,radius:s,startAngle:F,endAngle:U,anticlockwise:h*c>u*l}}static arc(t,e,i,n,s,o,a,l,h){const c=a-o,u=cn._segmentsCount(Math.abs(c)*s,Math.ceil(Math.abs(c)/qs)*40),d=c/(u*2),f=d*2,p=Math.cos(d),m=Math.sin(d),y=u-1,_=y%1/y;for(let v=0;v<=y;++v){const g=v+_*v,b=d+o+f*g,S=Math.cos(b),R=-Math.sin(b);h.push((p*S+m*R)*s+i,(p*-R+m*S)*s+n)}}}class aS{constructor(){this.reset()}begin(t,e,i){this.reset(),this.style=t,this.start=e,this.attribStart=i}end(t,e){this.attribSize=e-this.attribStart,this.size=t-this.start}reset(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0}}class bh{static curveLength(t,e,i,n,s,o,a,l){let h=0,c=0,u=0,d=0,f=0,p=0,m=0,y=0,_=0,v=0,g=0,b=t,S=e;for(let R=1;R<=10;++R)c=R/10,u=c*c,d=u*c,f=1-c,p=f*f,m=p*f,y=m*t+3*p*c*i+3*f*u*s+d*a,_=m*e+3*p*c*n+3*f*u*o+d*l,v=b-y,g=S-_,b=y,S=_,h+=Math.sqrt(v*v+g*g);return h}static curveTo(t,e,i,n,s,o,a){const l=a[a.length-2],h=a[a.length-1];a.length-=2;const c=cn._segmentsCount(bh.curveLength(l,h,t,e,i,n,s,o));let u=0,d=0,f=0,p=0,m=0;a.push(l,h);for(let y=1,_=0;y<=c;++y)_=y/c,u=1-_,d=u*u,f=d*u,p=_*_,m=p*_,a.push(f*l+3*d*_*t+3*u*p*i+m*s,f*h+3*d*_*e+3*u*p*n+m*o)}}function om(r,t,e,i,n,s,o,a){const l=r-e*n,h=t-i*n,c=r+e*s,u=t+i*s;let d,f;o?(d=i,f=-e):(d=-i,f=e);const p=l+d,m=h+f,y=c+d,_=u+f;return a.push(p,m,y,_),2}function Ti(r,t,e,i,n,s,o,a){const l=e-r,h=i-t;let c=Math.atan2(l,h),u=Math.atan2(n-r,s-t);a&&c<u?c+=Math.PI*2:!a&&c>u&&(u+=Math.PI*2);let d=c;const f=u-c,p=Math.abs(f),m=Math.sqrt(l*l+h*h),y=(15*p*Math.sqrt(m)/Math.PI>>0)+1,_=f/y;if(d+=_,a){o.push(r,t,e,i);for(let v=1,g=d;v<y;v++,g+=_)o.push(r,t,r+Math.sin(g)*m,t+Math.cos(g)*m);o.push(r,t,n,s)}else{o.push(e,i,r,t);for(let v=1,g=d;v<y;v++,g+=_)o.push(r+Math.sin(g)*m,t+Math.cos(g)*m,r,t);o.push(n,s,r,t)}return y*2}function lS(r,t){const e=r.shape;let i=r.points||e.points.slice();const n=t.closePointEps;if(i.length===0)return;const s=r.lineStyle,o=new It(i[0],i[1]),a=new It(i[i.length-2],i[i.length-1]),l=e.type!==ve.POLY||e.closeStroke,h=Math.abs(o.x-a.x)<n&&Math.abs(o.y-a.y)<n;if(l){i=i.slice(),h&&(i.pop(),i.pop(),a.set(i[i.length-2],i[i.length-1]));const D=(o.x+a.x)*.5,N=(a.y+o.y)*.5;i.unshift(D,N),i.push(D,N)}const c=t.points,u=i.length/2;let d=i.length;const f=c.length/2,p=s.width/2,m=p*p,y=s.miterLimit*s.miterLimit;let _=i[0],v=i[1],g=i[2],b=i[3],S=0,R=0,C=-(v-b),I=_-g,M=0,F=0,U=Math.sqrt(C*C+I*I);C/=U,I/=U,C*=p,I*=p;const P=s.alignment,T=(1-P)*2,E=P*2;l||(s.cap===jr.ROUND?d+=Ti(_-C*(T-E)*.5,v-I*(T-E)*.5,_-C*T,v-I*T,_+C*E,v+I*E,c,!0)+2:s.cap===jr.SQUARE&&(d+=om(_,v,C,I,T,E,!0,c))),c.push(_-C*T,v-I*T,_+C*E,v+I*E);for(let D=1;D<u-1;++D){_=i[(D-1)*2],v=i[(D-1)*2+1],g=i[D*2],b=i[D*2+1],S=i[(D+1)*2],R=i[(D+1)*2+1],C=-(v-b),I=_-g,U=Math.sqrt(C*C+I*I),C/=U,I/=U,C*=p,I*=p,M=-(b-R),F=g-S,U=Math.sqrt(M*M+F*F),M/=U,F/=U,M*=p,F*=p;const N=g-_,$=v-b,O=g-S,B=R-b,k=N*O+$*B,V=$*O-B*N,j=V<0;if(Math.abs(V)<.001*Math.abs(k)){c.push(g-C*T,b-I*T,g+C*E,b+I*E),k>=0&&(s.join===Ge.ROUND?d+=Ti(g,b,g-C*T,b-I*T,g-M*T,b-F*T,c,!1)+4:d+=2,c.push(g-M*E,b-F*E,g+M*T,b+F*T));continue}const K=(-C+_)*(-I+b)-(-C+g)*(-I+v),X=(-M+S)*(-F+b)-(-M+g)*(-F+R),ft=(N*X-O*K)/V,H=(B*K-$*X)/V,mt=(ft-g)*(ft-g)+(H-b)*(H-b),Q=g+(ft-g)*T,ut=b+(H-b)*T,gt=g-(ft-g)*E,Et=b-(H-b)*E,Dt=Math.min(N*N+$*$,O*O+B*B),Yt=j?T:E,Vt=Dt+Yt*Yt*m,et=mt<=Vt;let $e=s.join;if($e===Ge.MITER&&mt/m>y&&($e=Ge.BEVEL),et)switch($e){case Ge.MITER:{c.push(Q,ut,gt,Et);break}case Ge.BEVEL:{j?c.push(Q,ut,g+C*E,b+I*E,Q,ut,g+M*E,b+F*E):c.push(g-C*T,b-I*T,gt,Et,g-M*T,b-F*T,gt,Et),d+=2;break}case Ge.ROUND:{j?(c.push(Q,ut,g+C*E,b+I*E),d+=Ti(g,b,g+C*E,b+I*E,g+M*E,b+F*E,c,!0)+4,c.push(Q,ut,g+M*E,b+F*E)):(c.push(g-C*T,b-I*T,gt,Et),d+=Ti(g,b,g-C*T,b-I*T,g-M*T,b-F*T,c,!1)+4,c.push(g-M*T,b-F*T,gt,Et));break}}else{switch(c.push(g-C*T,b-I*T,g+C*E,b+I*E),$e){case Ge.MITER:{j?c.push(gt,Et,gt,Et):c.push(Q,ut,Q,ut),d+=2;break}case Ge.ROUND:{j?d+=Ti(g,b,g+C*E,b+I*E,g+M*E,b+F*E,c,!0)+2:d+=Ti(g,b,g-C*T,b-I*T,g-M*T,b-F*T,c,!1)+2;break}}c.push(g-M*T,b-F*T,g+M*E,b+F*E),d+=2}}_=i[(u-2)*2],v=i[(u-2)*2+1],g=i[(u-1)*2],b=i[(u-1)*2+1],C=-(v-b),I=_-g,U=Math.sqrt(C*C+I*I),C/=U,I/=U,C*=p,I*=p,c.push(g-C*T,b-I*T,g+C*E,b+I*E),l||(s.cap===jr.ROUND?d+=Ti(g-C*(T-E)*.5,b-I*(T-E)*.5,g-C*T,b-I*T,g+C*E,b+I*E,c,!1)+2:s.cap===jr.SQUARE&&(d+=om(g,b,C,I,T,E,!1,c)));const A=t.indices,L=cn.epsilon*cn.epsilon;for(let D=f;D<d+f-2;++D)_=c[D*2],v=c[D*2+1],g=c[(D+1)*2],b=c[(D+1)*2+1],S=c[(D+2)*2],R=c[(D+2)*2+1],!(Math.abs(_*(b-R)+g*(R-v)+S*(v-b))<L)&&A.push(D,D+1,D+2)}function hS(r,t){let e=0;const i=r.shape,n=r.points||i.points,s=i.type!==ve.POLY||i.closeStroke;if(n.length===0)return;const o=t.points,a=t.indices,l=n.length/2,h=o.length/2;let c=h;for(o.push(n[0],n[1]),e=1;e<l;e++)o.push(n[e*2],n[e*2+1]),a.push(c,c+1),c++;s&&a.push(c,h)}function am(r,t){r.lineStyle.native?hS(r,t):lS(r,t)}class xh{static curveLength(t,e,i,n,s,o){const a=t-2*i+s,l=e-2*n+o,h=2*i-2*t,c=2*n-2*e,u=4*(a*a+l*l),d=4*(a*h+l*c),f=h*h+c*c,p=2*Math.sqrt(u+d+f),m=Math.sqrt(u),y=2*u*m,_=2*Math.sqrt(f),v=d/m;return(y*p+m*d*(p-_)+(4*f*u-d*d)*Math.log((2*m+v+p)/(v+_)))/(4*y)}static curveTo(t,e,i,n,s){const o=s[s.length-2],a=s[s.length-1],l=cn._segmentsCount(xh.curveLength(o,a,t,e,i,n));let h=0,c=0;for(let u=1;u<=l;++u){const d=u/l;h=o+(t-o)*d,c=a+(e-a)*d,s.push(h+(t+(i-t)*d-h)*d,c+(e+(n-e)*d-c)*d)}}}const wh={[ve.POLY]:nm,[ve.CIRC]:Ao,[ve.ELIP]:Ao,[ve.RECT]:sS,[ve.RREC]:oS},lm=[],So=[];class Co{constructor(t,e=null,i=null,n=null){this.points=[],this.holes=[],this.shape=t,this.lineStyle=i,this.fillStyle=e,this.matrix=n,this.type=t.type}clone(){return new Co(this.shape,this.fillStyle,this.lineStyle,this.matrix)}destroy(){this.shape=null,this.holes.length=0,this.holes=null,this.points.length=0,this.points=null,this.lineStyle=null,this.fillStyle=null}}const un=new It,hm=class tg extends $f{constructor(){super(),this.closePointEps=1e-4,this.boundsPadding=0,this.uvsFloat32=null,this.indicesUint16=null,this.batchable=!1,this.points=[],this.colors=[],this.uvs=[],this.indices=[],this.textureIds=[],this.graphicsData=[],this.drawCalls=[],this.batchDirty=-1,this.batches=[],this.dirty=0,this.cacheDirty=-1,this.clearDirty=0,this.shapeIndex=0,this._bounds=new po,this.boundsDirty=-1}get bounds(){return this.updateBatches(),this.boundsDirty!==this.dirty&&(this.boundsDirty=this.dirty,this.calculateBounds()),this._bounds}invalidate(){this.boundsDirty=-1,this.dirty++,this.batchDirty++,this.shapeIndex=0,this.points.length=0,this.colors.length=0,this.uvs.length=0,this.indices.length=0,this.textureIds.length=0;for(let t=0;t<this.drawCalls.length;t++)this.drawCalls[t].texArray.clear(),So.push(this.drawCalls[t]);this.drawCalls.length=0;for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e.reset(),lm.push(e)}this.batches.length=0}clear(){return this.graphicsData.length>0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this}drawShape(t,e=null,i=null,n=null){const s=new Co(t,e,i,n);return this.graphicsData.push(s),this.dirty++,this}drawHole(t,e=null){if(!this.graphicsData.length)return null;const i=new Co(t,null,null,e),n=this.graphicsData[this.graphicsData.length-1];return i.lineStyle=n.lineStyle,n.holes.push(i),this.dirty++,this}destroy(){super.destroy();for(let t=0;t<this.graphicsData.length;++t)this.graphicsData[t].destroy();this.points.length=0,this.points=null,this.colors.length=0,this.colors=null,this.uvs.length=0,this.uvs=null,this.indices.length=0,this.indices=null,this.indexBuffer.destroy(),this.indexBuffer=null,this.graphicsData.length=0,this.graphicsData=null,this.drawCalls.length=0,this.drawCalls=null,this.batches.length=0,this.batches=null,this._bounds=null}containsPoint(t){const e=this.graphicsData;for(let i=0;i<e.length;++i){const n=e[i];if(n.fillStyle.visible&&n.shape&&(n.matrix?n.matrix.applyInverse(t,un):un.copyFrom(t),n.shape.contains(un.x,un.y))){let s=!1;if(n.holes){for(let o=0;o<n.holes.length;o++)if(n.holes[o].shape.contains(un.x,un.y)){s=!0;break}}if(!s)return!0}}return!1}updateBatches(){if(!this.graphicsData.length){this.batchable=!0;return}if(!this.validateBatching())return;this.cacheDirty=this.dirty;const t=this.uvs,e=this.graphicsData;let i=null,n=null;this.batches.length>0&&(i=this.batches[this.batches.length-1],n=i.style);for(let l=this.shapeIndex;l<e.length;l++){this.shapeIndex++;const h=e[l],c=h.fillStyle,u=h.lineStyle;wh[h.type].build(h),h.matrix&&this.transformPoints(h.points,h.matrix),(c.visible||u.visible)&&this.processHoles(h.holes);for(let d=0;d<2;d++){const f=d===0?c:u;if(!f.visible)continue;const p=f.texture.baseTexture,m=this.indices.length,y=this.points.length/2;p.wrapMode=Fr.REPEAT,d===0?this.processFill(h):this.processLine(h);const _=this.points.length/2-y;_!==0&&(i&&!this._compareStyles(n,f)&&(i.end(m,y),i=null),i||(i=lm.pop()||new aS,i.begin(f,m,y),this.batches.push(i),n=f),this.addUvs(this.points,t,f.texture,y,_,f.matrix))}}const s=this.indices.length,o=this.points.length/2;if(i&&i.end(s,o),this.batches.length===0){this.batchable=!0;return}const a=o>65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&a===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=a?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}_compareStyles(t,e){return!(!t||!e||t.texture.baseTexture!==e.texture.baseTexture||t.color+t.alpha!==e.color+e.alpha||!!t.native!=!!e.native)}validateBatching(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(let t=0,e=this.graphicsData.length;t<e;t++){const i=this.graphicsData[t],n=i.fillStyle,s=i.lineStyle;if(n&&!n.texture.baseTexture.valid||s&&!s.texture.baseTexture.valid)return!1}return!0}packBatches(){this.batchDirty++,this.uvsFloat32=new Float32Array(this.uvs);const t=this.batches;for(let e=0,i=t.length;e<i;e++){const n=t[e];for(let s=0;s<n.size;s++){const o=n.start+s;this.indicesUint16[o]=this.indicesUint16[o]-n.attribStart}}}isBatchable(){if(this.points.length>65535*2)return!1;const t=this.batches;for(let e=0;e<t.length;e++)if(t[e].style.native)return!1;return this.points.length<tg.BATCHABLE_SIZE*2}buildDrawCalls(){let t=++bt._globalBatch;for(let u=0;u<this.drawCalls.length;u++)this.drawCalls[u].texArray.clear(),So.push(this.drawCalls[u]);this.drawCalls.length=0;const e=this.colors,i=this.textureIds;let n=So.pop();n||(n=new jl,n.texArray=new Zl),n.texArray.count=0,n.start=0,n.size=0,n.type=rr.TRIANGLES;let s=0,o=null,a=0,l=!1,h=rr.TRIANGLES,c=0;this.drawCalls.push(n);for(let u=0;u<this.batches.length;u++){const d=this.batches[u],f=8,p=d.style,m=p.texture.baseTexture;l!==!!p.native&&(l=!!p.native,h=l?rr.LINES:rr.TRIANGLES,o=null,s=f,t++),o!==m&&(o=m,m._batchEnabled!==t&&(s===f&&(t++,s=0,n.size>0&&(n=So.pop(),n||(n=new jl,n.texArray=new Zl),this.drawCalls.push(n)),n.start=c,n.size=0,n.texArray.count=0,n.type=h),m.touched=1,m._batchEnabled=t,m._batchLocation=s,m.wrapMode=Fr.REPEAT,n.texArray.elements[n.texArray.count++]=m,s++)),n.size+=d.size,c+=d.size,a=m._batchLocation,this.addColors(e,p.color,p.alpha,d.attribSize,d.attribStart),this.addTextureIds(i,a,d.attribSize,d.attribStart)}bt._globalBatch=t,this.packAttributes()}packAttributes(){const t=this.points,e=this.uvs,i=this.colors,n=this.textureIds,s=new ArrayBuffer(t.length*3*4),o=new Float32Array(s),a=new Uint32Array(s);let l=0;for(let h=0;h<t.length/2;h++)o[l++]=t[h*2],o[l++]=t[h*2+1],o[l++]=e[h*2],o[l++]=e[h*2+1],a[l++]=i[h],o[l++]=n[h];this._buffer.update(s),this._indexBuffer.update(this.indicesUint16)}processFill(t){t.holes.length?nm.triangulate(t,this):wh[t.type].triangulate(t,this)}processLine(t){am(t,this);for(let e=0;e<t.holes.length;e++)am(t.holes[e],this)}processHoles(t){for(let e=0;e<t.length;e++){const i=t[e];wh[i.type].build(i),i.matrix&&this.transformPoints(i.points,i.matrix)}}calculateBounds(){const t=this._bounds;t.clear(),t.addVertexData(this.points,0,this.points.length),t.pad(this.boundsPadding,this.boundsPadding)}transformPoints(t,e){for(let i=0;i<t.length/2;i++){const n=t[i*2],s=t[i*2+1];t[i*2]=e.a*n+e.c*s+e.tx,t[i*2+1]=e.b*n+e.d*s+e.ty}}addColors(t,e,i,n,s=0){const o=Mt.shared.setValue(e).toLittleEndianNumber(),a=Mt.shared.setValue(o).toPremultiplied(i);t.length=Math.max(t.length,s+n);for(let l=0;l<n;l++)t[s+l]=a}addTextureIds(t,e,i,n=0){t.length=Math.max(t.length,n+i);for(let s=0;s<i;s++)t[n+s]=e}addUvs(t,e,i,n,s,o=null){let a=0;const l=e.length,h=i.frame;for(;a<s;){let u=t[(n+a)*2],d=t[(n+a)*2+1];if(o){const f=o.a*u+o.c*d+o.tx;d=o.b*u+o.d*d+o.ty,u=f}a++,e.push(u/h.width,d/h.height)}const c=i.baseTexture;(h.width<c.width||h.height<c.height)&&this.adjustUvs(e,i,l,s)}adjustUvs(t,e,i,n){const s=e.baseTexture,o=1e-6,a=i+n*2,l=e.frame,h=l.width/s.width,c=l.height/s.height;let u=l.x/l.width,d=l.y/l.height,f=Math.floor(t[i]+o),p=Math.floor(t[i+1]+o);for(let m=i+2;m<a;m+=2)f=Math.min(f,Math.floor(t[m]+o)),p=Math.min(p,Math.floor(t[m+1]+o));u-=f,d-=p;for(let m=i;m<a;m+=2)t[m]=(t[m]+u)*h,t[m+1]=(t[m+1]+d)*c}};hm.BATCHABLE_SIZE=100;let cS=hm;class Io{constructor(){this.color=16777215,this.alpha=1,this.texture=ct.WHITE,this.matrix=null,this.visible=!1,this.reset()}clone(){const t=new Io;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t}reset(){this.color=16777215,this.alpha=1,this.texture=ct.WHITE,this.matrix=null,this.visible=!1}destroy(){this.texture=null,this.matrix=null}}class Eh extends Io{constructor(){super(...arguments),this.width=0,this.alignment=.5,this.native=!1,this.cap=jr.BUTT,this.join=Ge.MITER,this.miterLimit=10}clone(){const t=new Eh;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t.width=this.width,t.alignment=this.alignment,t.native=this.native,t.cap=this.cap,t.join=this.join,t.miterLimit=this.miterLimit,t}reset(){super.reset(),this.color=0,this.alignment=.5,this.width=0,this.native=!1,this.cap=jr.BUTT,this.join=Ge.MITER,this.miterLimit=10}}const Th={},Ah=class Go extends ze{constructor(t=null){super(),this.shader=null,this.pluginName="batch",this.currentPath=null,this.batches=[],this.batchTint=-1,this.batchDirty=-1,this.vertexData=null,this._fillStyle=new Io,this._lineStyle=new Eh,this._matrix=null,this._holeMode=!1,this.state=ur.for2d(),this._geometry=t||new cS,this._geometry.refCount++,this._transformID=-1,this._tintColor=new Mt(16777215),this.blendMode=vt.NORMAL}get geometry(){return this._geometry}clone(){return this.finishPoly(),new Go(this._geometry)}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t)}get fill(){return this._fillStyle}get line(){return this._lineStyle}lineStyle(t=null,e=0,i,n=.5,s=!1){return typeof t=="number"&&(t={width:t,color:e,alpha:i,alignment:n,native:s}),this.lineTextureStyle(t)}lineTextureStyle(t){const e={width:0,texture:ct.WHITE,color:t!=null&&t.texture?16777215:0,matrix:null,alignment:.5,native:!1,cap:jr.BUTT,join:Ge.MITER,miterLimit:10};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.width>0&&t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._lineStyle,{visible:i},t)):this._lineStyle.reset(),this}startPoly(){if(this.currentPath){const t=this.currentPath.points,e=this.currentPath.points.length;e>2&&(this.drawShape(this.currentPath),this.currentPath=new di,this.currentPath.closeStroke=!1,this.currentPath.points.push(t[e-2],t[e-1]))}else this.currentPath=new di,this.currentPath.closeStroke=!1}finishPoly(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)}moveTo(t,e){return this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this}lineTo(t,e){this.currentPath||this.moveTo(0,0);const i=this.currentPath.points,n=i[i.length-2],s=i[i.length-1];return(n!==t||s!==e)&&i.push(t,e),this}_initCurve(t=0,e=0){this.currentPath?this.currentPath.points.length===0&&(this.currentPath.points=[t,e]):this.moveTo(t,e)}quadraticCurveTo(t,e,i,n){this._initCurve();const s=this.currentPath.points;return s.length===0&&this.moveTo(0,0),xh.curveTo(t,e,i,n,s),this}bezierCurveTo(t,e,i,n,s,o){return this._initCurve(),bh.curveTo(t,e,i,n,s,o,this.currentPath.points),this}arcTo(t,e,i,n,s){this._initCurve(t,e);const o=this.currentPath.points,a=sm.curveTo(t,e,i,n,s,o);if(a){const{cx:l,cy:h,radius:c,startAngle:u,endAngle:d,anticlockwise:f}=a;this.arc(l,h,c,u,d,f)}return this}arc(t,e,i,n,s,o=!1){if(n===s)return this;if(!o&&s<=n?s+=qs:o&&n<=s&&(n+=qs),s-n===0)return this;const a=t+Math.cos(n)*i,l=e+Math.sin(n)*i,h=this._geometry.closePointEps;let c=this.currentPath?this.currentPath.points:null;if(c){const u=Math.abs(c[c.length-2]-a),d=Math.abs(c[c.length-1]-l);u<h&&d<h||c.push(a,l)}else this.moveTo(a,l),c=this.currentPath.points;return sm.arc(a,l,t,e,i,n,s,o,c),this}beginFill(t=0,e){return this.beginTextureFill({texture:ct.WHITE,color:t,alpha:e})}normalizeColor(t){const e=Mt.shared.setValue(t.color??0);t.color=e.toNumber(),t.alpha??(t.alpha=e.alpha)}beginTextureFill(t){const e={texture:ct.WHITE,color:16777215,matrix:null};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._fillStyle,{visible:i},t)):this._fillStyle.reset(),this}endFill(){return this.finishPoly(),this._fillStyle.reset(),this}drawRect(t,e,i,n){return this.drawShape(new wt(t,e,i,n))}drawRoundedRect(t,e,i,n,s){return this.drawShape(new Js(t,e,i,n,s))}drawCircle(t,e,i){return this.drawShape(new Zs(t,e,i))}drawEllipse(t,e,i,n){return this.drawShape(new Qs(t,e,i,n))}drawPolygon(...t){let e,i=!0;const n=t[0];n.points?(i=n.closeStroke,e=n.points):Array.isArray(t[0])?e=t[0]:e=t;const s=new di(e);return s.closeStroke=i,this.drawShape(s),this}drawShape(t){return this._holeMode?this._geometry.drawHole(t,this._matrix):this._geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone(),this._matrix),this}clear(){return this._geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this._boundsID++,this._matrix=null,this._holeMode=!1,this.currentPath=null,this}isFastRect(){const t=this._geometry.graphicsData;return t.length===1&&t[0].shape.type===ve.RECT&&!t[0].matrix&&!t[0].holes.length&&!(t[0].lineStyle.visible&&t[0].lineStyle.width)}_render(t){this.finishPoly();const e=this._geometry;e.updateBatches(),e.batchable?(this.batchDirty!==e.batchDirty&&this._populateBatches(),this._renderBatched(t)):(t.batch.flush(),this._renderDirect(t))}_populateBatches(){const t=this._geometry,e=this.blendMode,i=t.batches.length;this.batchTint=-1,this._transformID=-1,this.batchDirty=t.batchDirty,this.batches.length=i,this.vertexData=new Float32Array(t.points);for(let n=0;n<i;n++){const s=t.batches[n],o=s.style.color,a=new Float32Array(this.vertexData.buffer,s.attribStart*4*2,s.attribSize*2),l=new Float32Array(t.uvsFloat32.buffer,s.attribStart*4*2,s.attribSize*2),h=new Uint16Array(t.indicesUint16.buffer,s.start*2,s.size),c={vertexData:a,blendMode:e,indices:h,uvs:l,_batchRGB:Mt.shared.setValue(o).toRgbArray(),_tintRGB:o,_texture:s.style.texture,alpha:s.style.alpha,worldAlpha:1};this.batches[n]=c}}_renderBatched(t){if(this.batches.length){t.batch.setObjectRenderer(t.plugins[this.pluginName]),this.calculateVertices(),this.calculateTints();for(let e=0,i=this.batches.length;e<i;e++){const n=this.batches[e];n.worldAlpha=this.worldAlpha*n.alpha,t.plugins[this.pluginName].render(n)}}}_renderDirect(t){const e=this._resolveDirectShader(t),i=this._geometry,n=this.worldAlpha,s=e.uniforms,o=i.drawCalls;s.translationMatrix=this.transform.worldTransform,Mt.shared.setValue(this._tintColor).premultiply(n).toArray(s.tint),t.shader.bind(e),t.geometry.bind(i,e),t.state.set(this.state);for(let a=0,l=o.length;a<l;a++)this._renderDrawCallDirect(t,i.drawCalls[a])}_renderDrawCallDirect(t,e){const{texArray:i,type:n,size:s,start:o}=e,a=i.count;for(let l=0;l<a;l++)t.texture.bind(i.elements[l],l);t.geometry.draw(n,s,o)}_resolveDirectShader(t){let e=this.shader;const i=this.pluginName;if(!e){if(!Th[i]){const{maxTextures:n}=t.plugins[i],s=new Int32Array(n);for(let l=0;l<n;l++)s[l]=l;const o={tint:new Float32Array([1,1,1,1]),translationMatrix:new kt,default:We.from({uSamplers:s},!0)},a=t.plugins[i]._shader.program;Th[i]=new dr(a,o)}e=Th[i]}return e}_calculateBounds(){this.finishPoly();const t=this._geometry;if(!t.graphicsData.length)return;const{minX:e,minY:i,maxX:n,maxY:s}=t.bounds;this._bounds.addFrame(this.transform,e,i,n,s)}containsPoint(t){return this.worldTransform.applyInverse(t,Go._TEMP_POINT),this._geometry.containsPoint(Go._TEMP_POINT)}calculateTints(){if(this.batchTint!==this.tint){this.batchTint=this._tintColor.toNumber();for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e._tintRGB=Mt.shared.setValue(this._tintColor).multiply(e._batchRGB).toLittleEndianNumber()}}}calculateVertices(){const t=this.transform._worldID;if(this._transformID===t)return;this._transformID=t;const e=this.transform.worldTransform,i=e.a,n=e.b,s=e.c,o=e.d,a=e.tx,l=e.ty,h=this._geometry.points,c=this.vertexData;let u=0;for(let d=0;d<h.length;d+=2){const f=h[d],p=h[d+1];c[u++]=i*f+s*p+a,c[u++]=o*p+n*f+l}}closePath(){const t=this.currentPath;return t&&(t.closeStroke=!0,this.finishPoly()),this}setMatrix(t){return this._matrix=t,this}beginHole(){return this.finishPoly(),this._holeMode=!0,this}endHole(){return this.finishPoly(),this._holeMode=!1,this}destroy(t){this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose(),this._matrix=null,this.currentPath=null,this._lineStyle.destroy(),this._lineStyle=null,this._fillStyle.destroy(),this._fillStyle=null,this._geometry=null,this.shader=null,this.vertexData=null,this.batches.length=0,this.batches=null,super.destroy(t)}};Ah.curves=cn,Ah._TEMP_POINT=new It;let ts=Ah;class uS{constructor(t,e){this.uvBuffer=t,this.uvMatrix=e,this.data=null,this._bufferUpdateId=-1,this._textureUpdateId=-1,this._updateID=0}update(t){if(!t&&this._bufferUpdateId===this.uvBuffer._updateID&&this._textureUpdateId===this.uvMatrix._updateID)return;this._bufferUpdateId=this.uvBuffer._updateID,this._textureUpdateId=this.uvMatrix._updateID;const e=this.uvBuffer.data;(!this.data||this.data.length!==e.length)&&(this.data=new Float32Array(e.length)),this.uvMatrix.multiplyUvs(e,this.data),this._updateID++}}const Sh=new It,cm=new di,um=class eg extends ze{constructor(t,e,i,n=rr.TRIANGLES){super(),this.geometry=t,this.shader=e,this.state=i||ur.for2d(),this.drawMode=n,this.start=0,this.size=0,this.uvs=null,this.indices=null,this.vertexData=new Float32Array(1),this.vertexDirty=-1,this._transformID=-1,this._roundPixels=tt.ROUND_PIXELS,this.batchUvs=null}get geometry(){return this._geometry}set geometry(t){this._geometry!==t&&(this._geometry&&(this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose()),this._geometry=t,this._geometry&&this._geometry.refCount++,this.vertexDirty=-1)}get uvBuffer(){return this.geometry.buffers[1]}get verticesBuffer(){return this.geometry.buffers[0]}set material(t){this.shader=t}get material(){return this.shader}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get tint(){return"tint"in this.shader?this.shader.tint:null}set tint(t){this.shader.tint=t}get tintValue(){return this.shader.tintValue}get texture(){return"texture"in this.shader?this.shader.texture:null}set texture(t){this.shader.texture=t}_render(t){const e=this.geometry.buffers[0].data;this.shader.batchable&&this.drawMode===rr.TRIANGLES&&e.length<eg.BATCHABLE_SIZE*2?this._renderToBatch(t):this._renderDefault(t)}_renderDefault(t){const e=this.shader;e.alpha=this.worldAlpha,e.update&&e.update(),t.batch.flush(),e.uniforms.translationMatrix=this.transform.worldTransform.toArray(!0),t.shader.bind(e),t.state.set(this.state),t.geometry.bind(this.geometry,e),t.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}_renderToBatch(t){const e=this.geometry,i=this.shader;i.uvMatrix&&(i.uvMatrix.update(),this.calculateUvs()),this.calculateVertices(),this.indices=e.indexBuffer.data,this._tintRGB=i._tintRGB,this._texture=i.texture;const n=this.material.pluginName;t.batch.setObjectRenderer(t.plugins[n]),t.plugins[n].render(this)}calculateVertices(){const t=this.geometry.buffers[0],e=t.data,i=t._updateID;if(i===this.vertexDirty&&this._transformID===this.transform._worldID)return;this._transformID=this.transform._worldID,this.vertexData.length!==e.length&&(this.vertexData=new Float32Array(e.length));const n=this.transform.worldTransform,s=n.a,o=n.b,a=n.c,l=n.d,h=n.tx,c=n.ty,u=this.vertexData;for(let d=0;d<u.length/2;d++){const f=e[d*2],p=e[d*2+1];u[d*2]=s*f+a*p+h,u[d*2+1]=o*f+l*p+c}if(this._roundPixels){const d=tt.RESOLUTION;for(let f=0;f<u.length;++f)u[f]=Math.round(u[f]*d)/d}this.vertexDirty=i}calculateUvs(){const t=this.geometry.buffers[1],e=this.shader;e.uvMatrix.isSimple?this.uvs=t.data:(this.batchUvs||(this.batchUvs=new uS(t,e.uvMatrix)),this.batchUvs.update(),this.uvs=this.batchUvs.data)}_calculateBounds(){this.calculateVertices(),this._bounds.addVertexData(this.vertexData,0,this.vertexData.length)}containsPoint(t){if(!this.getBounds().contains(t.x,t.y))return!1;this.worldTransform.applyInverse(t,Sh);const e=this.geometry.getBuffer("aVertexPosition").data,i=cm.points,n=this.geometry.getIndex().data,s=n.length,o=this.drawMode===4?3:1;for(let a=0;a+2<s;a+=o){const l=n[a]*2,h=n[a+1]*2,c=n[a+2]*2;if(i[0]=e[l],i[1]=e[l+1],i[2]=e[h],i[3]=e[h+1],i[4]=e[c],i[5]=e[c+1],cm.contains(Sh.x,Sh.y))return!0}return!1}destroy(t){super.destroy(t),this._cachedTexture&&(this._cachedTexture.destroy(),this._cachedTexture=null),this.geometry=null,this.shader=null,this.state=null,this.uvs=null,this.indices=null,this.vertexData=null}};um.BATCHABLE_SIZE=100;let dm=um;class dS extends Hr{constructor(t,e,i){super();const n=new Qt(t),s=new Qt(e,!0),o=new Qt(i,!0,!0);this.addAttribute("aVertexPosition",n,2,!1,pt.FLOAT).addAttribute("aTextureCoord",s,2,!1,pt.FLOAT).addIndex(o),this._updateId=-1}get vertexDirtyId(){return this.buffers[0]._updateID}}var fS=`varying vec2 vTextureCoord;
911
+ Please use Assets.add({ alias, src, data, format, loadParser }) instead.`),o.push({alias:t,src:e,data:i,format:n,loadParser:s})):Array.isArray(t)?o.push(...t):o.push(t);let a;a=l=>{this.hasKey(l)&&console.warn(`[Resolver] already has key: ${l} overwriting`)},qe(o).forEach(l=>{const{src:h,srcs:c}=l;let{data:u,format:d,loadParser:f}=l;const p=qe(h||c).map(_=>typeof _=="string"?$T(_):Array.isArray(_)?_:[_]),m=this.getAlias(l);Array.isArray(m)?m.forEach(a):a(m);const y=[];p.forEach(_=>{_.forEach(v=>{let g={};if(typeof v!="object"){g.src=v;for(let b=0;b<this._parsers.length;b++){const S=this._parsers[b];if(S.test(v)){g=S.parse(v);break}}}else u=v.data??u,d=v.format??d,f=v.loadParser??f,g={...g,...v};if(!m)throw new Error(`[Resolver] alias is undefined for this asset: ${g.src}`);g=this.buildResolvedAsset(g,{aliases:m,data:u,format:d,loadParser:f}),y.push(g)})}),m.forEach(_=>{this._assetMap[_]=y})})}resolveBundle(t){const e=yo(t);t=qe(t);const i={};return t.forEach(n=>{const s=this._bundles[n];if(s){const o=this.resolve(s),a={};for(const l in o){const h=o[l];a[this._extractAssetIdFromBundle(n,l)]=h}i[n]=a}}),e?i[t[0]]:i}resolveUrl(t){const e=this.resolve(t);if(typeof t!="string"){const i={};for(const n in e)i[n]=e[n].src;return i}return e.src}resolve(t){const e=yo(t);t=qe(t);const i={};return t.forEach(n=>{if(!this._resolverHash[n])if(this._assetMap[n]){let s=this._assetMap[n];const o=s[0],a=this._getPreferredOrder(s);a==null||a.priority.forEach(l=>{a.params[l].forEach(h=>{const c=s.filter(u=>u[l]?u[l]===h:!1);c.length&&(s=c)})}),this._resolverHash[n]=s[0]??o}else this._resolverHash[n]=this.buildResolvedAsset({alias:[n],src:n},{});i[n]=this._resolverHash[n]}),e?i[t[0]]:i}hasKey(t){return!!this._assetMap[t]}hasBundle(t){return!!this._bundles[t]}_getPreferredOrder(t){for(let e=0;e<t.length;e++){const i=t[0],n=this._preferredOrder.find(s=>s.params.format.includes(i.format));if(n)return n}return this._preferredOrder[0]}_appendDefaultSearchParams(t){if(!this._defaultSearchParams)return t;const e=/\?/.test(t)?"&":"?";return`${t}${e}${this._defaultSearchParams}`}buildResolvedAsset(t,e){const{aliases:i,data:n,loadParser:s,format:o}=e;return(this._basePath||this._rootPath)&&(t.src=ue.toAbsolute(t.src,this._basePath,this._rootPath)),t.alias=i??t.alias??[t.src],t.src=this._appendDefaultSearchParams(t.src),t.data={...n||{},...t.data},t.loadParser=s??t.loadParser,t.format=o??t.format??ue.extname(t.src).slice(1),t.srcs=t.src,t.name=t.alias,t}}class yA{constructor(){this._detections=[],this._initialized=!1,this.resolver=new gA,this.loader=new XT,this.cache=wi,this._backgroundLoader=new GT(this.loader),this._backgroundLoader.active=!0,this.reset()}async init(t={}){var s,o;if(this._initialized){console.warn("[Assets]AssetManager already initialized, did you load before calling this Assets.init()?");return}if(this._initialized=!0,t.defaultSearchParams&&this.resolver.setDefaultSearchParams(t.defaultSearchParams),t.basePath&&(this.resolver.basePath=t.basePath),t.bundleIdentifier&&this.resolver.setBundleIdentifier(t.bundleIdentifier),t.manifest){let a=t.manifest;typeof a=="string"&&(a=await this.load(a)),this.resolver.addManifest(a)}const e=((s=t.texturePreference)==null?void 0:s.resolution)??1,i=typeof e=="number"?[e]:e,n=await this._detectFormats({preferredFormats:(o=t.texturePreference)==null?void 0:o.format,skipDetections:t.skipDetections,detections:this._detections});this.resolver.prefer({params:{format:n,resolution:i}}),t.preferences&&this.setPreferences(t.preferences)}add(t,e,i,n,s){this.resolver.add(t,e,i,n,s)}async load(t,e){this._initialized||await this.init();const i=yo(t),n=qe(t).map(a=>{if(typeof a!="string"){const l=this.resolver.getAlias(a);return l.some(h=>!this.resolver.hasKey(h))&&this.add(a),Array.isArray(l)?l[0]:l}return this.resolver.hasKey(a)||this.add({alias:a,src:a}),a}),s=this.resolver.resolve(n),o=await this._mapLoadToResolve(s,e);return i?o[n[0]]:o}addBundle(t,e){this.resolver.addBundle(t,e)}async loadBundle(t,e){this._initialized||await this.init();let i=!1;typeof t=="string"&&(i=!0,t=[t]);const n=this.resolver.resolveBundle(t),s={},o=Object.keys(n);let a=0,l=0;const h=()=>{e==null||e(++a/l)},c=o.map(u=>{const d=n[u];return l+=Object.keys(d).length,this._mapLoadToResolve(d,h).then(f=>{s[u]=f})});return await Promise.all(c),i?s[t[0]]:s}async backgroundLoad(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolve(t);this._backgroundLoader.add(Object.values(e))}async backgroundLoadBundle(t){this._initialized||await this.init(),typeof t=="string"&&(t=[t]);const e=this.resolver.resolveBundle(t);Object.values(e).forEach(i=>{this._backgroundLoader.add(Object.values(i))})}reset(){this.resolver.reset(),this.loader.reset(),this.cache.reset(),this._initialized=!1}get(t){if(typeof t=="string")return wi.get(t);const e={};for(let i=0;i<t.length;i++)e[i]=wi.get(t[i]);return e}async _mapLoadToResolve(t,e){const i=Object.values(t),n=Object.keys(t);this._backgroundLoader.active=!1;const s=await this.loader.load(i,e);this._backgroundLoader.active=!0;const o={};return i.forEach((a,l)=>{const h=s[a.src],c=[a.src];a.alias&&c.push(...a.alias),o[n[l]]=h,wi.set(c,h)}),o}async unload(t){this._initialized||await this.init();const e=qe(t).map(n=>typeof n!="string"?n.src:n),i=this.resolver.resolve(e);await this._unloadFromResolved(i)}async unloadBundle(t){this._initialized||await this.init(),t=qe(t);const e=this.resolver.resolveBundle(t),i=Object.keys(e).map(n=>this._unloadFromResolved(e[n]));await Promise.all(i)}async _unloadFromResolved(t){const e=Object.values(t);e.forEach(i=>{wi.remove(i.src)}),await this.loader.unload(e)}async _detectFormats(t){let e=[];t.preferredFormats&&(e=Array.isArray(t.preferredFormats)?t.preferredFormats:[t.preferredFormats]);for(const i of t.detections)t.skipDetections||await i.test()?e=await i.add(e):t.skipDetections||(e=await i.remove(e));return e=e.filter((i,n)=>e.indexOf(i)===n),e}get detections(){return this._detections}get preferWorkers(){return _o.config.preferWorkers}set preferWorkers(t){At("7.2.0","Assets.prefersWorkers is deprecated, use Assets.setPreferences({ preferWorkers: true }) instead."),this.setPreferences({preferWorkers:t})}setPreferences(t){this.loader.parsers.forEach(e=>{e.config&&Object.keys(e.config).filter(i=>i in t).forEach(i=>{e.config[i]=t[i]})})}}const vo=new yA;ht.handleByList(Z.LoadParser,vo.loader.parsers).handleByList(Z.ResolveParser,vo.resolver.parsers).handleByList(Z.CacheParser,vo.cache.parsers).handleByList(Z.DetectionParser,vo.detections);const _A={extension:Z.CacheParser,test:r=>Array.isArray(r)&&r.every(t=>t instanceof ct),getCacheableAssets:(r,t)=>{const e={};return r.forEach(i=>{t.forEach((n,s)=>{e[i+(s===0?"":s+1)]=n})}),e}};ht.add(_A);async function Kp(r){if("Image"in globalThis)return new Promise(t=>{const e=new Image;e.onload=()=>{t(!0)},e.onerror=()=>{t(!1)},e.src=r});if("createImageBitmap"in globalThis&&"fetch"in globalThis){try{const t=await(await fetch(r)).blob();await createImageBitmap(t)}catch{return!1}return!0}return!1}const vA={extension:{type:Z.DetectionParser,priority:1},test:async()=>Kp("data:image/avif;base64,AAAAIGZ0eXBhdmlmAAAAAGF2aWZtaWYxbWlhZk1BMUIAAADybWV0YQAAAAAAAAAoaGRscgAAAAAAAAAAcGljdAAAAAAAAAAAAAAAAGxpYmF2aWYAAAAADnBpdG0AAAAAAAEAAAAeaWxvYwAAAABEAAABAAEAAAABAAABGgAAAB0AAAAoaWluZgAAAAAAAQAAABppbmZlAgAAAAABAABhdjAxQ29sb3IAAAAAamlwcnAAAABLaXBjbwAAABRpc3BlAAAAAAAAAAIAAAACAAAAEHBpeGkAAAAAAwgICAAAAAxhdjFDgQ0MAAAAABNjb2xybmNseAACAAIAAYAAAAAXaXBtYQAAAAAAAAABAAEEAQKDBAAAACVtZGF0EgAKCBgANogQEAwgMg8f8D///8WfhwB8+ErK42A="),add:async r=>[...r,"avif"],remove:async r=>r.filter(t=>t!=="avif")};ht.add(vA);const bA={extension:{type:Z.DetectionParser,priority:0},test:async()=>Kp("data:image/webp;base64,UklGRh4AAABXRUJQVlA4TBEAAAAvAAAAAAfQ//73v/+BiOh/AAA="),add:async r=>[...r,"webp"],remove:async r=>r.filter(t=>t!=="webp")};ht.add(bA);const Zp=["png","jpg","jpeg"],xA={extension:{type:Z.DetectionParser,priority:-1},test:()=>Promise.resolve(!0),add:async r=>[...r,...Zp],remove:async r=>r.filter(t=>!Zp.includes(t))};ht.add(xA);const wA="WorkerGlobalScope"in globalThis&&globalThis instanceof globalThis.WorkerGlobalScope;function yh(r){return wA?!1:document.createElement("video").canPlayType(r)!==""}const EA={extension:{type:Z.DetectionParser,priority:0},test:async()=>yh("video/webm"),add:async r=>[...r,"webm"],remove:async r=>r.filter(t=>t!=="webm")};ht.add(EA);const TA={extension:{type:Z.DetectionParser,priority:0},test:async()=>yh("video/mp4"),add:async r=>[...r,"mp4","m4v"],remove:async r=>r.filter(t=>t!=="mp4"&&t!=="m4v")};ht.add(TA);const AA={extension:{type:Z.DetectionParser,priority:0},test:async()=>yh("video/ogg"),add:async r=>[...r,"ogv"],remove:async r=>r.filter(t=>t!=="ogv")};ht.add(AA);const SA={extension:Z.ResolveParser,test:_o.test,parse:r=>{var t;return{resolution:parseFloat(((t=tt.RETINA_PREFIX.exec(r))==null?void 0:t[1])??"1"),format:ue.extname(r).slice(1),src:r}}};ht.add(SA);var be=(r=>(r[r.COMPRESSED_RGB_S3TC_DXT1_EXT=33776]="COMPRESSED_RGB_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT1_EXT=33777]="COMPRESSED_RGBA_S3TC_DXT1_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT3_EXT=33778]="COMPRESSED_RGBA_S3TC_DXT3_EXT",r[r.COMPRESSED_RGBA_S3TC_DXT5_EXT=33779]="COMPRESSED_RGBA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT=35917]="COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT=35918]="COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT",r[r.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT=35919]="COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT",r[r.COMPRESSED_SRGB_S3TC_DXT1_EXT=35916]="COMPRESSED_SRGB_S3TC_DXT1_EXT",r[r.COMPRESSED_R11_EAC=37488]="COMPRESSED_R11_EAC",r[r.COMPRESSED_SIGNED_R11_EAC=37489]="COMPRESSED_SIGNED_R11_EAC",r[r.COMPRESSED_RG11_EAC=37490]="COMPRESSED_RG11_EAC",r[r.COMPRESSED_SIGNED_RG11_EAC=37491]="COMPRESSED_SIGNED_RG11_EAC",r[r.COMPRESSED_RGB8_ETC2=37492]="COMPRESSED_RGB8_ETC2",r[r.COMPRESSED_RGBA8_ETC2_EAC=37496]="COMPRESSED_RGBA8_ETC2_EAC",r[r.COMPRESSED_SRGB8_ETC2=37493]="COMPRESSED_SRGB8_ETC2",r[r.COMPRESSED_SRGB8_ALPHA8_ETC2_EAC=37497]="COMPRESSED_SRGB8_ALPHA8_ETC2_EAC",r[r.COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2=37494]="COMPRESSED_RGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2=37495]="COMPRESSED_SRGB8_PUNCHTHROUGH_ALPHA1_ETC2",r[r.COMPRESSED_RGB_PVRTC_4BPPV1_IMG=35840]="COMPRESSED_RGB_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_4BPPV1_IMG=35842]="COMPRESSED_RGBA_PVRTC_4BPPV1_IMG",r[r.COMPRESSED_RGB_PVRTC_2BPPV1_IMG=35841]="COMPRESSED_RGB_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGBA_PVRTC_2BPPV1_IMG=35843]="COMPRESSED_RGBA_PVRTC_2BPPV1_IMG",r[r.COMPRESSED_RGB_ETC1_WEBGL=36196]="COMPRESSED_RGB_ETC1_WEBGL",r[r.COMPRESSED_RGB_ATC_WEBGL=35986]="COMPRESSED_RGB_ATC_WEBGL",r[r.COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL=35987]="COMPRESSED_RGBA_ATC_EXPLICIT_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL=34798]="COMPRESSED_RGBA_ATC_INTERPOLATED_ALPHA_WEBGL",r[r.COMPRESSED_RGBA_ASTC_4x4_KHR=37808]="COMPRESSED_RGBA_ASTC_4x4_KHR",r[r.COMPRESSED_RGBA_BPTC_UNORM_EXT=36492]="COMPRESSED_RGBA_BPTC_UNORM_EXT",r[r.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT=36493]="COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT",r[r.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT=36494]="COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT",r[r.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT=36495]="COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT",r))(be||{});const bo={33776:.5,33777:.5,33778:1,33779:1,35916:.5,35917:.5,35918:1,35919:1,37488:.5,37489:.5,37490:1,37491:1,37492:.5,37496:1,37493:.5,37497:1,37494:.5,37495:.5,35840:.5,35842:.5,35841:.25,35843:.25,36196:.5,35986:.5,35987:1,34798:1,37808:1,36492:1,36493:1,36494:1,36495:1};let fr,hn;function Qp(){hn={bptc:fr.getExtension("EXT_texture_compression_bptc"),astc:fr.getExtension("WEBGL_compressed_texture_astc"),etc:fr.getExtension("WEBGL_compressed_texture_etc"),s3tc:fr.getExtension("WEBGL_compressed_texture_s3tc"),s3tc_sRGB:fr.getExtension("WEBGL_compressed_texture_s3tc_srgb"),pvrtc:fr.getExtension("WEBGL_compressed_texture_pvrtc")||fr.getExtension("WEBKIT_WEBGL_compressed_texture_pvrtc"),etc1:fr.getExtension("WEBGL_compressed_texture_etc1"),atc:fr.getExtension("WEBGL_compressed_texture_atc")}}const CA={extension:{type:Z.DetectionParser,priority:2},test:async()=>{const r=tt.ADAPTER.createCanvas().getContext("webgl");return r?(fr=r,!0):(console.warn("WebGL not available for compressed textures."),!1)},add:async r=>{hn||Qp();const t=[];for(const e in hn)hn[e]&&t.push(e);return[...t,...r]},remove:async r=>(hn||Qp(),r.filter(t=>!(t in hn)))};ht.add(CA);class IA extends zs{constructor(t,e={width:1,height:1,autoLoad:!0}){let i,n;typeof t=="string"?(i=t,n=new Uint8Array):(i=null,n=t),super(n,e),this.origin=i,this.buffer=n?new Nl(n):null,this._load=null,this.loaded=!1,this.origin!==null&&e.autoLoad!==!1&&this.load(),this.origin===null&&this.buffer&&(this._load=Promise.resolve(this),this.loaded=!0,this.onBlobLoaded(this.buffer.rawBinaryData))}onBlobLoaded(t){}load(){return this._load?this._load:(this._load=fetch(this.origin).then(t=>t.blob()).then(t=>t.arrayBuffer()).then(t=>(this.data=new Uint32Array(t),this.buffer=new Nl(t),this.loaded=!0,this.onBlobLoaded(t),this.update(),this)),this._load)}}class Ei extends IA{constructor(t,e){super(t,e),this.format=e.format,this.levels=e.levels||1,this._width=e.width,this._height=e.height,this._extension=Ei._formatToExtension(this.format),(e.levelBuffers||this.buffer)&&(this._levelBuffers=e.levelBuffers||Ei._createLevelBuffers(t instanceof Uint8Array?t:this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height))}upload(t,e,i){const n=t.gl;if(!t.context.extensions[this._extension])throw new Error(`${this._extension} textures are not supported on the current machine`);if(!this._levelBuffers)return!1;n.pixelStorei(n.UNPACK_ALIGNMENT,4);for(let s=0,o=this.levels;s<o;s++){const{levelID:a,levelWidth:l,levelHeight:h,levelBuffer:c}=this._levelBuffers[s];n.compressedTexImage2D(n.TEXTURE_2D,a,this.format,l,h,0,c)}return!0}onBlobLoaded(){this._levelBuffers=Ei._createLevelBuffers(this.buffer.uint8View,this.format,this.levels,4,4,this.width,this.height)}static _formatToExtension(t){if(t>=33776&&t<=33779)return"s3tc";if(t>=35916&&t<=35919)return"s3tc_sRGB";if(t>=37488&&t<=37497)return"etc";if(t>=35840&&t<=35843)return"pvrtc";if(t===36196)return"etc1";if(t===35986||t===35987||t===34798)return"atc";if(t>=36492&&t<=36495)return"bptc";if(t===37808)return"astc";throw new Error(`Invalid (compressed) texture format given: ${t}`)}static _createLevelBuffers(t,e,i,n,s,o,a){const l=new Array(i);let h=t.byteOffset,c=o,u=a,d=c+n-1&~(n-1),f=u+s-1&~(s-1),p=d*f*bo[e];for(let m=0;m<i;m++)l[m]={levelID:m,levelWidth:i>1?c:d,levelHeight:i>1?u:f,levelBuffer:new Uint8Array(t.buffer,h,p)},h+=p,c=c>>1||1,u=u>>1||1,d=c+n-1&~(n-1),f=u+s-1&~(s-1),p=d*f*bo[e];return l}}const _h=4,xo=124,PA=32,Jp=20,RA=542327876,wo={HEIGHT:3,WIDTH:4,MIPMAP_COUNT:7,PIXEL_FORMAT:19},MA={FOURCC:2},Eo={DXGI_FORMAT:0,RESOURCE_DIMENSION:1,MISC_FLAG:2,ARRAY_SIZE:3},DA=1,BA=2,OA=4,LA=64,NA=512,FA=131072,kA=827611204,UA=861165636,GA=894720068,$A=808540228,HA=4,XA={[kA]:be.COMPRESSED_RGBA_S3TC_DXT1_EXT,[UA]:be.COMPRESSED_RGBA_S3TC_DXT3_EXT,[GA]:be.COMPRESSED_RGBA_S3TC_DXT5_EXT},VA={70:be.COMPRESSED_RGBA_S3TC_DXT1_EXT,71:be.COMPRESSED_RGBA_S3TC_DXT1_EXT,73:be.COMPRESSED_RGBA_S3TC_DXT3_EXT,74:be.COMPRESSED_RGBA_S3TC_DXT3_EXT,76:be.COMPRESSED_RGBA_S3TC_DXT5_EXT,77:be.COMPRESSED_RGBA_S3TC_DXT5_EXT,72:be.COMPRESSED_SRGB_ALPHA_S3TC_DXT1_EXT,75:be.COMPRESSED_SRGB_ALPHA_S3TC_DXT3_EXT,78:be.COMPRESSED_SRGB_ALPHA_S3TC_DXT5_EXT,96:be.COMPRESSED_RGB_BPTC_SIGNED_FLOAT_EXT,95:be.COMPRESSED_RGB_BPTC_UNSIGNED_FLOAT_EXT,98:be.COMPRESSED_RGBA_BPTC_UNORM_EXT,99:be.COMPRESSED_SRGB_ALPHA_BPTC_UNORM_EXT};function jA(r){const t=new Uint32Array(r);if(t[0]!==RA)throw new Error("Invalid DDS file magic word");const e=new Uint32Array(r,0,xo/Uint32Array.BYTES_PER_ELEMENT),i=e[wo.HEIGHT],n=e[wo.WIDTH],s=e[wo.MIPMAP_COUNT],o=new Uint32Array(r,wo.PIXEL_FORMAT*Uint32Array.BYTES_PER_ELEMENT,PA/Uint32Array.BYTES_PER_ELEMENT),a=o[DA];if(a&OA){const l=o[MA.FOURCC];if(l!==$A){const v=XA[l],g=_h+xo,b=new Uint8Array(r,g);return[new Ei(b,{format:v,width:n,height:i,levels:s})]}const h=_h+xo,c=new Uint32Array(t.buffer,h,Jp/Uint32Array.BYTES_PER_ELEMENT),u=c[Eo.DXGI_FORMAT],d=c[Eo.RESOURCE_DIMENSION],f=c[Eo.MISC_FLAG],p=c[Eo.ARRAY_SIZE],m=VA[u];if(m===void 0)throw new Error(`DDSParser cannot parse texture data with DXGI format ${u}`);if(f===HA)throw new Error("DDSParser does not support cubemap textures");if(d===6)throw new Error("DDSParser does not supported 3D texture data");const y=new Array,_=_h+xo+Jp;if(p===1)y.push(new Uint8Array(r,_));else{const v=bo[m];let g=0,b=n,S=i;for(let C=0;C<s;C++){const I=Math.max(1,b+3&-4),M=Math.max(1,S+3&-4),F=I*M*v;g+=F,b=b>>>1,S=S>>>1}let R=_;for(let C=0;C<p;C++)y.push(new Uint8Array(r,R,g)),R+=g}return y.map(v=>new Ei(v,{format:m,width:n,height:i,levels:s}))}throw a&LA?new Error("DDSParser does not support uncompressed texture data."):a&NA?new Error("DDSParser does not supported YUV uncompressed texture data."):a&FA?new Error("DDSParser does not support single-channel (lumninance) texture data!"):a&BA?new Error("DDSParser does not support single-channel (alpha) texture data!"):new Error("DDSParser failed to load a texture file due to an unknown reason!")}const tm=[171,75,84,88,32,49,49,187,13,10,26,10],WA=67305985,Ze={ENDIANNESS:12,GL_TYPE:16,GL_FORMAT:24,GL_INTERNAL_FORMAT:28,PIXEL_WIDTH:36,PIXEL_HEIGHT:40,PIXEL_DEPTH:44,NUMBER_OF_ARRAY_ELEMENTS:48,NUMBER_OF_FACES:52,NUMBER_OF_MIPMAP_LEVELS:56,BYTES_OF_KEY_VALUE_DATA:60},vh=64,em={[pt.UNSIGNED_BYTE]:1,[pt.UNSIGNED_SHORT]:2,[pt.INT]:4,[pt.UNSIGNED_INT]:4,[pt.FLOAT]:4,[pt.HALF_FLOAT]:8},zA={[W.RGBA]:4,[W.RGB]:3,[W.RG]:2,[W.RED]:1,[W.LUMINANCE]:1,[W.LUMINANCE_ALPHA]:2,[W.ALPHA]:1},YA={[pt.UNSIGNED_SHORT_4_4_4_4]:2,[pt.UNSIGNED_SHORT_5_5_5_1]:2,[pt.UNSIGNED_SHORT_5_6_5]:2};function qA(r,t,e=!1){const i=new DataView(t);if(!KA(r,i))return null;const n=i.getUint32(Ze.ENDIANNESS,!0)===WA,s=i.getUint32(Ze.GL_TYPE,n),o=i.getUint32(Ze.GL_FORMAT,n),a=i.getUint32(Ze.GL_INTERNAL_FORMAT,n),l=i.getUint32(Ze.PIXEL_WIDTH,n),h=i.getUint32(Ze.PIXEL_HEIGHT,n)||1,c=i.getUint32(Ze.PIXEL_DEPTH,n)||1,u=i.getUint32(Ze.NUMBER_OF_ARRAY_ELEMENTS,n)||1,d=i.getUint32(Ze.NUMBER_OF_FACES,n),f=i.getUint32(Ze.NUMBER_OF_MIPMAP_LEVELS,n),p=i.getUint32(Ze.BYTES_OF_KEY_VALUE_DATA,n);if(h===0||c!==1)throw new Error("Only 2D textures are supported");if(d!==1)throw new Error("CubeTextures are not supported by KTXLoader yet!");if(u!==1)throw new Error("WebGL does not support array textures");const m=4,y=4,_=l+3&-4,v=h+3&-4,g=new Array(u);let b=l*h;s===0&&(b=_*v);let S;if(s!==0?em[s]?S=em[s]*zA[o]:S=YA[s]:S=bo[a],S===void 0)throw new Error("Unable to resolve the pixel format stored in the *.ktx file!");const R=e?QA(i,p,n):null;let C=b*S,I=l,M=h,F=_,U=v,P=vh+p;for(let E=0;E<f;E++){const T=i.getUint32(P,n);let A=P+4;for(let O=0;O<u;O++){let D=g[O];D||(D=g[O]=new Array(f)),D[E]={levelID:E,levelWidth:f>1||s!==0?I:F,levelHeight:f>1||s!==0?M:U,levelBuffer:new Uint8Array(t,A,C)},A+=C}P+=T+4,P=P%4!==0?P+4-P%4:P,I=I>>1||1,M=M>>1||1,F=I+m-1&-4,U=M+y-1&-4,C=F*U*S}return s!==0?{uncompressed:g.map(E=>{let T=E[0].levelBuffer,A=!1;return s===pt.FLOAT?T=new Float32Array(E[0].levelBuffer.buffer,E[0].levelBuffer.byteOffset,E[0].levelBuffer.byteLength/4):s===pt.UNSIGNED_INT?(A=!0,T=new Uint32Array(E[0].levelBuffer.buffer,E[0].levelBuffer.byteOffset,E[0].levelBuffer.byteLength/4)):s===pt.INT&&(A=!0,T=new Int32Array(E[0].levelBuffer.buffer,E[0].levelBuffer.byteOffset,E[0].levelBuffer.byteLength/4)),{resource:new zs(T,{width:E[0].levelWidth,height:E[0].levelHeight}),type:s,format:A?ZA(o):o}}),kvData:R}:{compressed:g.map(E=>new Ei(null,{format:a,width:l,height:h,levels:f,levelBuffers:E})),kvData:R}}function KA(r,t){for(let e=0;e<tm.length;e++)if(t.getUint8(e)!==tm[e])return console.error(`${r} is not a valid *.ktx file!`),!1;return!0}function ZA(r){switch(r){case W.RGBA:return W.RGBA_INTEGER;case W.RGB:return W.RGB_INTEGER;case W.RG:return W.RG_INTEGER;case W.RED:return W.RED_INTEGER;default:return r}}function QA(r,t,e){const i=new Map;let n=0;for(;n<t;){const s=r.getUint32(vh+n,e),o=vh+n+4,a=3-(s+3)%4;if(s===0||s>t-n){console.error("KTXLoader: keyAndValueByteSize out of bounds");break}let l=0;for(;l<s&&r.getUint8(o+l)!==0;l++);if(l===-1){console.error("KTXLoader: Failed to find null byte terminating kvData key");break}const h=new TextDecoder().decode(new Uint8Array(r.buffer,o,l)),c=new DataView(r.buffer,o+l+1,s-l-1);i.set(h,c),n+=4+s+a}return i}const JA={extension:{type:Z.LoadParser,priority:Ke.High},name:"loadDDS",test(r){return Vr(r,".dds")},async load(r,t,e){const i=await(await tt.ADAPTER.fetch(r)).arrayBuffer(),n=jA(i).map(s=>{const o=new bt(s,{mipmap:ir.OFF,alphaMode:Re.NO_PREMULTIPLIED_ALPHA,resolution:wr(r),...t.data});return Jn(o,e,r)});return n.length===1?n[0]:n},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};ht.add(JA);const tS={extension:{type:Z.LoadParser,priority:Ke.High},name:"loadKTX",test(r){return Vr(r,".ktx")},async load(r,t,e){const i=await(await tt.ADAPTER.fetch(r)).arrayBuffer(),{compressed:n,uncompressed:s,kvData:o}=qA(r,i),a=n??s,l={mipmap:ir.OFF,alphaMode:Re.NO_PREMULTIPLIED_ALPHA,resolution:wr(r),...t.data},h=a.map(c=>{a===s&&Object.assign(l,{type:c.type,format:c.format});const u=c.resource??c,d=new bt(u,l);return d.ktxKeyValueData=o,Jn(d,e,r)});return h.length===1?h[0]:h},unload(r){Array.isArray(r)?r.forEach(t=>t.destroy(!0)):r.destroy(!0)}};ht.add(tS);const eS=["s3tc","s3tc_sRGB","etc","etc1","pvrtc","atc","astc","bptc"],rS={extension:Z.ResolveParser,test:r=>{const t=ue.extname(r).slice(1);return["basis","ktx","dds"].includes(t)},parse:r=>{var i,n;const t=r.split("."),e=t.pop();if(["ktx","dds"].includes(e)){const s=t.pop();if(eS.includes(s))return{resolution:parseFloat(((i=tt.RETINA_PREFIX.exec(r))==null?void 0:i[1])??"1"),format:s,src:r}}return{resolution:parseFloat(((n=tt.RETINA_PREFIX.exec(r))==null?void 0:n[1])??"1"),format:e,src:r}}};ht.add(rS);const To=new wt,iS=4,rm=class ns{constructor(t){this.renderer=t,this._rendererPremultipliedAlpha=!1}contextChange(){var e;const t=(e=this.renderer)==null?void 0:e.gl.getContextAttributes();this._rendererPremultipliedAlpha=!!(t&&t.alpha&&t.premultipliedAlpha)}async image(t,e,i,n){const s=new Image;return s.src=await this.base64(t,e,i,n),s}async base64(t,e,i,n){const s=this.canvas(t,n);if(s.toBlob!==void 0)return new Promise((o,a)=>{s.toBlob(l=>{if(!l){a(new Error("ICanvas.toBlob failed!"));return}const h=new FileReader;h.onload=()=>o(h.result),h.onerror=a,h.readAsDataURL(l)},e,i)});if(s.toDataURL!==void 0)return s.toDataURL(e,i);if(s.convertToBlob!==void 0){const o=await s.convertToBlob({type:e,quality:i});return new Promise((a,l)=>{const h=new FileReader;h.onload=()=>a(h.result),h.onerror=l,h.readAsDataURL(o)})}throw new Error("Extract.base64() requires ICanvas.toDataURL, ICanvas.toBlob, or ICanvas.convertToBlob to be implemented")}canvas(t,e){const{pixels:i,width:n,height:s,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);o&&ns._flipY(i,n,s),a&&ns._unpremultiplyAlpha(i);const l=new Fw(n,s,1),h=new ImageData(new Uint8ClampedArray(i.buffer),n,s);return l.context.putImageData(h,0,0),l.canvas}pixels(t,e){const{pixels:i,width:n,height:s,flipY:o,premultipliedAlpha:a}=this._rawPixels(t,e);return o&&ns._flipY(i,n,s),a&&ns._unpremultiplyAlpha(i),i}_rawPixels(t,e){const i=this.renderer;if(!i)throw new Error("The Extract has already been destroyed");let n,s=!1,o=!1,a,l=!1;t&&(t instanceof _i?a=t:(a=i.generateTexture(t,{region:e,resolution:i.resolution,multisample:i.multisample}),l=!0,e&&(To.width=e.width,To.height=e.height,e=To)));const h=i.gl;if(a){if(n=a.baseTexture.resolution,e=e??a.frame,s=!1,o=a.baseTexture.alphaMode>0&&a.baseTexture.format===W.RGBA,!l){i.renderTexture.bind(a);const f=a.framebuffer.glFramebuffers[i.CONTEXT_UID];f.blitFramebuffer&&i.framebuffer.bind(f.blitFramebuffer)}}else n=i.resolution,e||(e=To,e.width=i.width/n,e.height=i.height/n),s=!0,o=this._rendererPremultipliedAlpha,i.renderTexture.bind();const c=Math.max(Math.round(e.width*n),1),u=Math.max(Math.round(e.height*n),1),d=new Uint8Array(iS*c*u);return h.readPixels(Math.round(e.x*n),Math.round(e.y*n),c,u,h.RGBA,h.UNSIGNED_BYTE,d),l&&(a==null||a.destroy(!0)),{pixels:d,width:c,height:u,flipY:s,premultipliedAlpha:o}}destroy(){this.renderer=null}static _flipY(t,e,i){const n=e<<2,s=i>>1,o=new Uint8Array(n);for(let a=0;a<s;a++){const l=a*n,h=(i-a-1)*n;o.set(t.subarray(l,l+n)),t.copyWithin(l,h,h+n),t.set(o,h)}}static _unpremultiplyAlpha(t){t instanceof Uint8ClampedArray&&(t=new Uint8Array(t.buffer));const e=t.length;for(let i=0;i<e;i+=4){const n=t[i+3];if(n!==0){const s=255.001/n;t[i]=t[i]*s+.5,t[i+1]=t[i+1]*s+.5,t[i+2]=t[i+2]*s+.5}}}};rm.extension={name:"extract",type:Z.RendererSystem};let nS=rm;ht.add(nS);const Ao={build(r){const t=r.points;let e,i,n,s,o,a;if(r.type===ve.CIRC){const p=r.shape;e=p.x,i=p.y,o=a=p.radius,n=s=0}else if(r.type===ve.ELIP){const p=r.shape;e=p.x,i=p.y,o=p.width,a=p.height,n=s=0}else{const p=r.shape,m=p.width/2,y=p.height/2;e=p.x+m,i=p.y+y,o=a=Math.max(0,Math.min(p.radius,Math.min(m,y))),n=m-o,s=y-a}if(!(o>=0&&a>=0&&n>=0&&s>=0)){t.length=0;return}const l=Math.ceil(2.3*Math.sqrt(o+a)),h=l*8+(n?4:0)+(s?4:0);if(t.length=h,h===0)return;if(l===0){t.length=8,t[0]=t[6]=e+n,t[1]=t[3]=i+s,t[2]=t[4]=e-n,t[5]=t[7]=i-s;return}let c=0,u=l*4+(n?2:0)+2,d=u,f=h;{const p=n+o,m=s,y=e+p,_=e-p,v=i+m;if(t[c++]=y,t[c++]=v,t[--u]=v,t[--u]=_,s){const g=i-m;t[d++]=_,t[d++]=g,t[--f]=g,t[--f]=y}}for(let p=1;p<l;p++){const m=Math.PI/2*(p/l),y=n+Math.cos(m)*o,_=s+Math.sin(m)*a,v=e+y,g=e-y,b=i+_,S=i-_;t[c++]=v,t[c++]=b,t[--u]=b,t[--u]=g,t[d++]=g,t[d++]=S,t[--f]=S,t[--f]=v}{const p=n,m=s+a,y=e+p,_=e-p,v=i+m,g=i-m;t[c++]=y,t[c++]=v,t[--f]=g,t[--f]=y,n&&(t[c++]=_,t[c++]=v,t[--f]=g,t[--f]=_)}},triangulate(r,t){const e=r.points,i=t.points,n=t.indices;if(e.length===0)return;let s=i.length/2;const o=s;let a,l;if(r.type!==ve.RREC){const c=r.shape;a=c.x,l=c.y}else{const c=r.shape;a=c.x+c.width/2,l=c.y+c.height/2}const h=r.matrix;i.push(r.matrix?h.a*a+h.c*l+h.tx:a,r.matrix?h.b*a+h.d*l+h.ty:l),s++,i.push(e[0],e[1]);for(let c=2;c<e.length;c+=2)i.push(e[c],e[c+1]),n.push(s++,o,s);n.push(o+1,o,s)}};function im(r,t=!1){const e=r.length;if(e<6)return;let i=0;for(let n=0,s=r[e-2],o=r[e-1];n<e;n+=2){const a=r[n],l=r[n+1];i+=(a-s)*(l+o),s=a,o=l}if(!t&&i>0||t&&i<=0){const n=e/2;for(let s=n+n%2;s<e;s+=2){const o=e-s-2,a=e-s-1,l=s,h=s+1;[r[o],r[l]]=[r[l],r[o]],[r[a],r[h]]=[r[h],r[a]]}}}const nm={build(r){r.points=r.shape.points.slice()},triangulate(r,t){let e=r.points;const i=r.holes,n=t.points,s=t.indices;if(e.length>=6){im(e,!1);const o=[];for(let h=0;h<i.length;h++){const c=i[h];im(c.points,!0),o.push(e.length/2),e=e.concat(c.points)}const a=g1(e,o,2);if(!a)return;const l=n.length/2;for(let h=0;h<a.length;h+=3)s.push(a[h]+l),s.push(a[h+1]+l),s.push(a[h+2]+l);for(let h=0;h<e.length;h++)n.push(e[h])}}},sS={build(r){const t=r.shape,e=t.x,i=t.y,n=t.width,s=t.height,o=r.points;o.length=0,n>=0&&s>=0&&o.push(e,i,e+n,i,e+n,i+s,e,i+s)},triangulate(r,t){const e=r.points,i=t.points;if(e.length===0)return;const n=i.length/2;i.push(e[0],e[1],e[2],e[3],e[6],e[7],e[4],e[5]),t.indices.push(n,n+1,n+2,n+1,n+2,n+3)}},oS={build(r){Ao.build(r)},triangulate(r,t){Ao.triangulate(r,t)}};var Ge=(r=>(r.MITER="miter",r.BEVEL="bevel",r.ROUND="round",r))(Ge||{}),jr=(r=>(r.BUTT="butt",r.ROUND="round",r.SQUARE="square",r))(jr||{});const cn={adaptive:!0,maxLength:10,minSegments:8,maxSegments:2048,epsilon:1e-4,_segmentsCount(r,t=20){if(!this.adaptive||!r||isNaN(r))return t;let e=Math.ceil(r/this.maxLength);return e<this.minSegments?e=this.minSegments:e>this.maxSegments&&(e=this.maxSegments),e}};class sm{static curveTo(t,e,i,n,s,o){const a=o[o.length-2],l=o[o.length-1]-e,h=a-t,c=n-e,u=i-t,d=Math.abs(l*u-h*c);if(d<1e-8||s===0)return(o[o.length-2]!==t||o[o.length-1]!==e)&&o.push(t,e),null;const f=l*l+h*h,p=c*c+u*u,m=l*c+h*u,y=s*Math.sqrt(f)/d,_=s*Math.sqrt(p)/d,v=y*m/f,g=_*m/p,b=y*u+_*h,S=y*c+_*l,R=h*(_+v),C=l*(_+v),I=u*(y+g),M=c*(y+g),F=Math.atan2(C-S,R-b),U=Math.atan2(M-S,I-b);return{cx:b+t,cy:S+e,radius:s,startAngle:F,endAngle:U,anticlockwise:h*c>u*l}}static arc(t,e,i,n,s,o,a,l,h){const c=a-o,u=cn._segmentsCount(Math.abs(c)*s,Math.ceil(Math.abs(c)/qs)*40),d=c/(u*2),f=d*2,p=Math.cos(d),m=Math.sin(d),y=u-1,_=y%1/y;for(let v=0;v<=y;++v){const g=v+_*v,b=d+o+f*g,S=Math.cos(b),R=-Math.sin(b);h.push((p*S+m*R)*s+i,(p*-R+m*S)*s+n)}}}class aS{constructor(){this.reset()}begin(t,e,i){this.reset(),this.style=t,this.start=e,this.attribStart=i}end(t,e){this.attribSize=e-this.attribStart,this.size=t-this.start}reset(){this.style=null,this.size=0,this.start=0,this.attribStart=0,this.attribSize=0}}class bh{static curveLength(t,e,i,n,s,o,a,l){let h=0,c=0,u=0,d=0,f=0,p=0,m=0,y=0,_=0,v=0,g=0,b=t,S=e;for(let R=1;R<=10;++R)c=R/10,u=c*c,d=u*c,f=1-c,p=f*f,m=p*f,y=m*t+3*p*c*i+3*f*u*s+d*a,_=m*e+3*p*c*n+3*f*u*o+d*l,v=b-y,g=S-_,b=y,S=_,h+=Math.sqrt(v*v+g*g);return h}static curveTo(t,e,i,n,s,o,a){const l=a[a.length-2],h=a[a.length-1];a.length-=2;const c=cn._segmentsCount(bh.curveLength(l,h,t,e,i,n,s,o));let u=0,d=0,f=0,p=0,m=0;a.push(l,h);for(let y=1,_=0;y<=c;++y)_=y/c,u=1-_,d=u*u,f=d*u,p=_*_,m=p*_,a.push(f*l+3*d*_*t+3*u*p*i+m*s,f*h+3*d*_*e+3*u*p*n+m*o)}}function om(r,t,e,i,n,s,o,a){const l=r-e*n,h=t-i*n,c=r+e*s,u=t+i*s;let d,f;o?(d=i,f=-e):(d=-i,f=e);const p=l+d,m=h+f,y=c+d,_=u+f;return a.push(p,m,y,_),2}function Ti(r,t,e,i,n,s,o,a){const l=e-r,h=i-t;let c=Math.atan2(l,h),u=Math.atan2(n-r,s-t);a&&c<u?c+=Math.PI*2:!a&&c>u&&(u+=Math.PI*2);let d=c;const f=u-c,p=Math.abs(f),m=Math.sqrt(l*l+h*h),y=(15*p*Math.sqrt(m)/Math.PI>>0)+1,_=f/y;if(d+=_,a){o.push(r,t,e,i);for(let v=1,g=d;v<y;v++,g+=_)o.push(r,t,r+Math.sin(g)*m,t+Math.cos(g)*m);o.push(r,t,n,s)}else{o.push(e,i,r,t);for(let v=1,g=d;v<y;v++,g+=_)o.push(r+Math.sin(g)*m,t+Math.cos(g)*m,r,t);o.push(n,s,r,t)}return y*2}function lS(r,t){const e=r.shape;let i=r.points||e.points.slice();const n=t.closePointEps;if(i.length===0)return;const s=r.lineStyle,o=new It(i[0],i[1]),a=new It(i[i.length-2],i[i.length-1]),l=e.type!==ve.POLY||e.closeStroke,h=Math.abs(o.x-a.x)<n&&Math.abs(o.y-a.y)<n;if(l){i=i.slice(),h&&(i.pop(),i.pop(),a.set(i[i.length-2],i[i.length-1]));const D=(o.x+a.x)*.5,L=(a.y+o.y)*.5;i.unshift(D,L),i.push(D,L)}const c=t.points,u=i.length/2;let d=i.length;const f=c.length/2,p=s.width/2,m=p*p,y=s.miterLimit*s.miterLimit;let _=i[0],v=i[1],g=i[2],b=i[3],S=0,R=0,C=-(v-b),I=_-g,M=0,F=0,U=Math.sqrt(C*C+I*I);C/=U,I/=U,C*=p,I*=p;const P=s.alignment,E=(1-P)*2,T=P*2;l||(s.cap===jr.ROUND?d+=Ti(_-C*(E-T)*.5,v-I*(E-T)*.5,_-C*E,v-I*E,_+C*T,v+I*T,c,!0)+2:s.cap===jr.SQUARE&&(d+=om(_,v,C,I,E,T,!0,c))),c.push(_-C*E,v-I*E,_+C*T,v+I*T);for(let D=1;D<u-1;++D){_=i[(D-1)*2],v=i[(D-1)*2+1],g=i[D*2],b=i[D*2+1],S=i[(D+1)*2],R=i[(D+1)*2+1],C=-(v-b),I=_-g,U=Math.sqrt(C*C+I*I),C/=U,I/=U,C*=p,I*=p,M=-(b-R),F=g-S,U=Math.sqrt(M*M+F*F),M/=U,F/=U,M*=p,F*=p;const L=g-_,$=v-b,B=g-S,N=R-b,k=L*B+$*N,X=$*B-N*L,j=X<0;if(Math.abs(X)<.001*Math.abs(k)){c.push(g-C*E,b-I*E,g+C*T,b+I*T),k>=0&&(s.join===Ge.ROUND?d+=Ti(g,b,g-C*E,b-I*E,g-M*E,b-F*E,c,!1)+4:d+=2,c.push(g-M*T,b-F*T,g+M*E,b+F*E));continue}const K=(-C+_)*(-I+b)-(-C+g)*(-I+v),V=(-M+S)*(-F+b)-(-M+g)*(-F+R),ut=(L*V-B*K)/X,H=(N*K-$*V)/X,mt=(ut-g)*(ut-g)+(H-b)*(H-b),Q=g+(ut-g)*E,dt=b+(H-b)*E,gt=g-(ut-g)*T,Et=b-(H-b)*T,Dt=Math.min(L*L+$*$,B*B+N*N),Yt=j?E:T,Vt=Dt+Yt*Yt*m,et=mt<=Vt;let $e=s.join;if($e===Ge.MITER&&mt/m>y&&($e=Ge.BEVEL),et)switch($e){case Ge.MITER:{c.push(Q,dt,gt,Et);break}case Ge.BEVEL:{j?c.push(Q,dt,g+C*T,b+I*T,Q,dt,g+M*T,b+F*T):c.push(g-C*E,b-I*E,gt,Et,g-M*E,b-F*E,gt,Et),d+=2;break}case Ge.ROUND:{j?(c.push(Q,dt,g+C*T,b+I*T),d+=Ti(g,b,g+C*T,b+I*T,g+M*T,b+F*T,c,!0)+4,c.push(Q,dt,g+M*T,b+F*T)):(c.push(g-C*E,b-I*E,gt,Et),d+=Ti(g,b,g-C*E,b-I*E,g-M*E,b-F*E,c,!1)+4,c.push(g-M*E,b-F*E,gt,Et));break}}else{switch(c.push(g-C*E,b-I*E,g+C*T,b+I*T),$e){case Ge.MITER:{j?c.push(gt,Et,gt,Et):c.push(Q,dt,Q,dt),d+=2;break}case Ge.ROUND:{j?d+=Ti(g,b,g+C*T,b+I*T,g+M*T,b+F*T,c,!0)+2:d+=Ti(g,b,g-C*E,b-I*E,g-M*E,b-F*E,c,!1)+2;break}}c.push(g-M*E,b-F*E,g+M*T,b+F*T),d+=2}}_=i[(u-2)*2],v=i[(u-2)*2+1],g=i[(u-1)*2],b=i[(u-1)*2+1],C=-(v-b),I=_-g,U=Math.sqrt(C*C+I*I),C/=U,I/=U,C*=p,I*=p,c.push(g-C*E,b-I*E,g+C*T,b+I*T),l||(s.cap===jr.ROUND?d+=Ti(g-C*(E-T)*.5,b-I*(E-T)*.5,g-C*E,b-I*E,g+C*T,b+I*T,c,!1)+2:s.cap===jr.SQUARE&&(d+=om(g,b,C,I,E,T,!1,c)));const A=t.indices,O=cn.epsilon*cn.epsilon;for(let D=f;D<d+f-2;++D)_=c[D*2],v=c[D*2+1],g=c[(D+1)*2],b=c[(D+1)*2+1],S=c[(D+2)*2],R=c[(D+2)*2+1],!(Math.abs(_*(b-R)+g*(R-v)+S*(v-b))<O)&&A.push(D,D+1,D+2)}function hS(r,t){let e=0;const i=r.shape,n=r.points||i.points,s=i.type!==ve.POLY||i.closeStroke;if(n.length===0)return;const o=t.points,a=t.indices,l=n.length/2,h=o.length/2;let c=h;for(o.push(n[0],n[1]),e=1;e<l;e++)o.push(n[e*2],n[e*2+1]),a.push(c,c+1),c++;s&&a.push(c,h)}function am(r,t){r.lineStyle.native?hS(r,t):lS(r,t)}class xh{static curveLength(t,e,i,n,s,o){const a=t-2*i+s,l=e-2*n+o,h=2*i-2*t,c=2*n-2*e,u=4*(a*a+l*l),d=4*(a*h+l*c),f=h*h+c*c,p=2*Math.sqrt(u+d+f),m=Math.sqrt(u),y=2*u*m,_=2*Math.sqrt(f),v=d/m;return(y*p+m*d*(p-_)+(4*f*u-d*d)*Math.log((2*m+v+p)/(v+_)))/(4*y)}static curveTo(t,e,i,n,s){const o=s[s.length-2],a=s[s.length-1],l=cn._segmentsCount(xh.curveLength(o,a,t,e,i,n));let h=0,c=0;for(let u=1;u<=l;++u){const d=u/l;h=o+(t-o)*d,c=a+(e-a)*d,s.push(h+(t+(i-t)*d-h)*d,c+(e+(n-e)*d-c)*d)}}}const wh={[ve.POLY]:nm,[ve.CIRC]:Ao,[ve.ELIP]:Ao,[ve.RECT]:sS,[ve.RREC]:oS},lm=[],So=[];class Co{constructor(t,e=null,i=null,n=null){this.points=[],this.holes=[],this.shape=t,this.lineStyle=i,this.fillStyle=e,this.matrix=n,this.type=t.type}clone(){return new Co(this.shape,this.fillStyle,this.lineStyle,this.matrix)}destroy(){this.shape=null,this.holes.length=0,this.holes=null,this.points.length=0,this.points=null,this.lineStyle=null,this.fillStyle=null}}const un=new It,hm=class tg extends $f{constructor(){super(),this.closePointEps=1e-4,this.boundsPadding=0,this.uvsFloat32=null,this.indicesUint16=null,this.batchable=!1,this.points=[],this.colors=[],this.uvs=[],this.indices=[],this.textureIds=[],this.graphicsData=[],this.drawCalls=[],this.batchDirty=-1,this.batches=[],this.dirty=0,this.cacheDirty=-1,this.clearDirty=0,this.shapeIndex=0,this._bounds=new po,this.boundsDirty=-1}get bounds(){return this.updateBatches(),this.boundsDirty!==this.dirty&&(this.boundsDirty=this.dirty,this.calculateBounds()),this._bounds}invalidate(){this.boundsDirty=-1,this.dirty++,this.batchDirty++,this.shapeIndex=0,this.points.length=0,this.colors.length=0,this.uvs.length=0,this.indices.length=0,this.textureIds.length=0;for(let t=0;t<this.drawCalls.length;t++)this.drawCalls[t].texArray.clear(),So.push(this.drawCalls[t]);this.drawCalls.length=0;for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e.reset(),lm.push(e)}this.batches.length=0}clear(){return this.graphicsData.length>0&&(this.invalidate(),this.clearDirty++,this.graphicsData.length=0),this}drawShape(t,e=null,i=null,n=null){const s=new Co(t,e,i,n);return this.graphicsData.push(s),this.dirty++,this}drawHole(t,e=null){if(!this.graphicsData.length)return null;const i=new Co(t,null,null,e),n=this.graphicsData[this.graphicsData.length-1];return i.lineStyle=n.lineStyle,n.holes.push(i),this.dirty++,this}destroy(){super.destroy();for(let t=0;t<this.graphicsData.length;++t)this.graphicsData[t].destroy();this.points.length=0,this.points=null,this.colors.length=0,this.colors=null,this.uvs.length=0,this.uvs=null,this.indices.length=0,this.indices=null,this.indexBuffer.destroy(),this.indexBuffer=null,this.graphicsData.length=0,this.graphicsData=null,this.drawCalls.length=0,this.drawCalls=null,this.batches.length=0,this.batches=null,this._bounds=null}containsPoint(t){const e=this.graphicsData;for(let i=0;i<e.length;++i){const n=e[i];if(n.fillStyle.visible&&n.shape&&(n.matrix?n.matrix.applyInverse(t,un):un.copyFrom(t),n.shape.contains(un.x,un.y))){let s=!1;if(n.holes){for(let o=0;o<n.holes.length;o++)if(n.holes[o].shape.contains(un.x,un.y)){s=!0;break}}if(!s)return!0}}return!1}updateBatches(){if(!this.graphicsData.length){this.batchable=!0;return}if(!this.validateBatching())return;this.cacheDirty=this.dirty;const t=this.uvs,e=this.graphicsData;let i=null,n=null;this.batches.length>0&&(i=this.batches[this.batches.length-1],n=i.style);for(let l=this.shapeIndex;l<e.length;l++){this.shapeIndex++;const h=e[l],c=h.fillStyle,u=h.lineStyle;wh[h.type].build(h),h.matrix&&this.transformPoints(h.points,h.matrix),(c.visible||u.visible)&&this.processHoles(h.holes);for(let d=0;d<2;d++){const f=d===0?c:u;if(!f.visible)continue;const p=f.texture.baseTexture,m=this.indices.length,y=this.points.length/2;p.wrapMode=Fr.REPEAT,d===0?this.processFill(h):this.processLine(h);const _=this.points.length/2-y;_!==0&&(i&&!this._compareStyles(n,f)&&(i.end(m,y),i=null),i||(i=lm.pop()||new aS,i.begin(f,m,y),this.batches.push(i),n=f),this.addUvs(this.points,t,f.texture,y,_,f.matrix))}}const s=this.indices.length,o=this.points.length/2;if(i&&i.end(s,o),this.batches.length===0){this.batchable=!0;return}const a=o>65535;this.indicesUint16&&this.indices.length===this.indicesUint16.length&&a===this.indicesUint16.BYTES_PER_ELEMENT>2?this.indicesUint16.set(this.indices):this.indicesUint16=a?new Uint32Array(this.indices):new Uint16Array(this.indices),this.batchable=this.isBatchable(),this.batchable?this.packBatches():this.buildDrawCalls()}_compareStyles(t,e){return!(!t||!e||t.texture.baseTexture!==e.texture.baseTexture||t.color+t.alpha!==e.color+e.alpha||!!t.native!=!!e.native)}validateBatching(){if(this.dirty===this.cacheDirty||!this.graphicsData.length)return!1;for(let t=0,e=this.graphicsData.length;t<e;t++){const i=this.graphicsData[t],n=i.fillStyle,s=i.lineStyle;if(n&&!n.texture.baseTexture.valid||s&&!s.texture.baseTexture.valid)return!1}return!0}packBatches(){this.batchDirty++,this.uvsFloat32=new Float32Array(this.uvs);const t=this.batches;for(let e=0,i=t.length;e<i;e++){const n=t[e];for(let s=0;s<n.size;s++){const o=n.start+s;this.indicesUint16[o]=this.indicesUint16[o]-n.attribStart}}}isBatchable(){if(this.points.length>65535*2)return!1;const t=this.batches;for(let e=0;e<t.length;e++)if(t[e].style.native)return!1;return this.points.length<tg.BATCHABLE_SIZE*2}buildDrawCalls(){let t=++bt._globalBatch;for(let u=0;u<this.drawCalls.length;u++)this.drawCalls[u].texArray.clear(),So.push(this.drawCalls[u]);this.drawCalls.length=0;const e=this.colors,i=this.textureIds;let n=So.pop();n||(n=new jl,n.texArray=new Zl),n.texArray.count=0,n.start=0,n.size=0,n.type=rr.TRIANGLES;let s=0,o=null,a=0,l=!1,h=rr.TRIANGLES,c=0;this.drawCalls.push(n);for(let u=0;u<this.batches.length;u++){const d=this.batches[u],f=8,p=d.style,m=p.texture.baseTexture;l!==!!p.native&&(l=!!p.native,h=l?rr.LINES:rr.TRIANGLES,o=null,s=f,t++),o!==m&&(o=m,m._batchEnabled!==t&&(s===f&&(t++,s=0,n.size>0&&(n=So.pop(),n||(n=new jl,n.texArray=new Zl),this.drawCalls.push(n)),n.start=c,n.size=0,n.texArray.count=0,n.type=h),m.touched=1,m._batchEnabled=t,m._batchLocation=s,m.wrapMode=Fr.REPEAT,n.texArray.elements[n.texArray.count++]=m,s++)),n.size+=d.size,c+=d.size,a=m._batchLocation,this.addColors(e,p.color,p.alpha,d.attribSize,d.attribStart),this.addTextureIds(i,a,d.attribSize,d.attribStart)}bt._globalBatch=t,this.packAttributes()}packAttributes(){const t=this.points,e=this.uvs,i=this.colors,n=this.textureIds,s=new ArrayBuffer(t.length*3*4),o=new Float32Array(s),a=new Uint32Array(s);let l=0;for(let h=0;h<t.length/2;h++)o[l++]=t[h*2],o[l++]=t[h*2+1],o[l++]=e[h*2],o[l++]=e[h*2+1],a[l++]=i[h],o[l++]=n[h];this._buffer.update(s),this._indexBuffer.update(this.indicesUint16)}processFill(t){t.holes.length?nm.triangulate(t,this):wh[t.type].triangulate(t,this)}processLine(t){am(t,this);for(let e=0;e<t.holes.length;e++)am(t.holes[e],this)}processHoles(t){for(let e=0;e<t.length;e++){const i=t[e];wh[i.type].build(i),i.matrix&&this.transformPoints(i.points,i.matrix)}}calculateBounds(){const t=this._bounds;t.clear(),t.addVertexData(this.points,0,this.points.length),t.pad(this.boundsPadding,this.boundsPadding)}transformPoints(t,e){for(let i=0;i<t.length/2;i++){const n=t[i*2],s=t[i*2+1];t[i*2]=e.a*n+e.c*s+e.tx,t[i*2+1]=e.b*n+e.d*s+e.ty}}addColors(t,e,i,n,s=0){const o=Mt.shared.setValue(e).toLittleEndianNumber(),a=Mt.shared.setValue(o).toPremultiplied(i);t.length=Math.max(t.length,s+n);for(let l=0;l<n;l++)t[s+l]=a}addTextureIds(t,e,i,n=0){t.length=Math.max(t.length,n+i);for(let s=0;s<i;s++)t[n+s]=e}addUvs(t,e,i,n,s,o=null){let a=0;const l=e.length,h=i.frame;for(;a<s;){let u=t[(n+a)*2],d=t[(n+a)*2+1];if(o){const f=o.a*u+o.c*d+o.tx;d=o.b*u+o.d*d+o.ty,u=f}a++,e.push(u/h.width,d/h.height)}const c=i.baseTexture;(h.width<c.width||h.height<c.height)&&this.adjustUvs(e,i,l,s)}adjustUvs(t,e,i,n){const s=e.baseTexture,o=1e-6,a=i+n*2,l=e.frame,h=l.width/s.width,c=l.height/s.height;let u=l.x/l.width,d=l.y/l.height,f=Math.floor(t[i]+o),p=Math.floor(t[i+1]+o);for(let m=i+2;m<a;m+=2)f=Math.min(f,Math.floor(t[m]+o)),p=Math.min(p,Math.floor(t[m+1]+o));u-=f,d-=p;for(let m=i;m<a;m+=2)t[m]=(t[m]+u)*h,t[m+1]=(t[m+1]+d)*c}};hm.BATCHABLE_SIZE=100;let cS=hm;class Io{constructor(){this.color=16777215,this.alpha=1,this.texture=ct.WHITE,this.matrix=null,this.visible=!1,this.reset()}clone(){const t=new Io;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t}reset(){this.color=16777215,this.alpha=1,this.texture=ct.WHITE,this.matrix=null,this.visible=!1}destroy(){this.texture=null,this.matrix=null}}class Eh extends Io{constructor(){super(...arguments),this.width=0,this.alignment=.5,this.native=!1,this.cap=jr.BUTT,this.join=Ge.MITER,this.miterLimit=10}clone(){const t=new Eh;return t.color=this.color,t.alpha=this.alpha,t.texture=this.texture,t.matrix=this.matrix,t.visible=this.visible,t.width=this.width,t.alignment=this.alignment,t.native=this.native,t.cap=this.cap,t.join=this.join,t.miterLimit=this.miterLimit,t}reset(){super.reset(),this.color=0,this.alignment=.5,this.width=0,this.native=!1,this.cap=jr.BUTT,this.join=Ge.MITER,this.miterLimit=10}}const Th={},Ah=class Go extends ze{constructor(t=null){super(),this.shader=null,this.pluginName="batch",this.currentPath=null,this.batches=[],this.batchTint=-1,this.batchDirty=-1,this.vertexData=null,this._fillStyle=new Io,this._lineStyle=new Eh,this._matrix=null,this._holeMode=!1,this.state=ur.for2d(),this._geometry=t||new cS,this._geometry.refCount++,this._transformID=-1,this._tintColor=new Mt(16777215),this.blendMode=vt.NORMAL}get geometry(){return this._geometry}clone(){return this.finishPoly(),new Go(this._geometry)}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}get tint(){return this._tintColor.value}set tint(t){this._tintColor.setValue(t)}get fill(){return this._fillStyle}get line(){return this._lineStyle}lineStyle(t=null,e=0,i,n=.5,s=!1){return typeof t=="number"&&(t={width:t,color:e,alpha:i,alignment:n,native:s}),this.lineTextureStyle(t)}lineTextureStyle(t){const e={width:0,texture:ct.WHITE,color:t!=null&&t.texture?16777215:0,matrix:null,alignment:.5,native:!1,cap:jr.BUTT,join:Ge.MITER,miterLimit:10};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.width>0&&t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._lineStyle,{visible:i},t)):this._lineStyle.reset(),this}startPoly(){if(this.currentPath){const t=this.currentPath.points,e=this.currentPath.points.length;e>2&&(this.drawShape(this.currentPath),this.currentPath=new di,this.currentPath.closeStroke=!1,this.currentPath.points.push(t[e-2],t[e-1]))}else this.currentPath=new di,this.currentPath.closeStroke=!1}finishPoly(){this.currentPath&&(this.currentPath.points.length>2?(this.drawShape(this.currentPath),this.currentPath=null):this.currentPath.points.length=0)}moveTo(t,e){return this.startPoly(),this.currentPath.points[0]=t,this.currentPath.points[1]=e,this}lineTo(t,e){this.currentPath||this.moveTo(0,0);const i=this.currentPath.points,n=i[i.length-2],s=i[i.length-1];return(n!==t||s!==e)&&i.push(t,e),this}_initCurve(t=0,e=0){this.currentPath?this.currentPath.points.length===0&&(this.currentPath.points=[t,e]):this.moveTo(t,e)}quadraticCurveTo(t,e,i,n){this._initCurve();const s=this.currentPath.points;return s.length===0&&this.moveTo(0,0),xh.curveTo(t,e,i,n,s),this}bezierCurveTo(t,e,i,n,s,o){return this._initCurve(),bh.curveTo(t,e,i,n,s,o,this.currentPath.points),this}arcTo(t,e,i,n,s){this._initCurve(t,e);const o=this.currentPath.points,a=sm.curveTo(t,e,i,n,s,o);if(a){const{cx:l,cy:h,radius:c,startAngle:u,endAngle:d,anticlockwise:f}=a;this.arc(l,h,c,u,d,f)}return this}arc(t,e,i,n,s,o=!1){if(n===s)return this;if(!o&&s<=n?s+=qs:o&&n<=s&&(n+=qs),s-n===0)return this;const a=t+Math.cos(n)*i,l=e+Math.sin(n)*i,h=this._geometry.closePointEps;let c=this.currentPath?this.currentPath.points:null;if(c){const u=Math.abs(c[c.length-2]-a),d=Math.abs(c[c.length-1]-l);u<h&&d<h||c.push(a,l)}else this.moveTo(a,l),c=this.currentPath.points;return sm.arc(a,l,t,e,i,n,s,o,c),this}beginFill(t=0,e){return this.beginTextureFill({texture:ct.WHITE,color:t,alpha:e})}normalizeColor(t){const e=Mt.shared.setValue(t.color??0);t.color=e.toNumber(),t.alpha??(t.alpha=e.alpha)}beginTextureFill(t){const e={texture:ct.WHITE,color:16777215,matrix:null};t=Object.assign(e,t),this.normalizeColor(t),this.currentPath&&this.startPoly();const i=t.alpha>0;return i?(t.matrix&&(t.matrix=t.matrix.clone(),t.matrix.invert()),Object.assign(this._fillStyle,{visible:i},t)):this._fillStyle.reset(),this}endFill(){return this.finishPoly(),this._fillStyle.reset(),this}drawRect(t,e,i,n){return this.drawShape(new wt(t,e,i,n))}drawRoundedRect(t,e,i,n,s){return this.drawShape(new Js(t,e,i,n,s))}drawCircle(t,e,i){return this.drawShape(new Zs(t,e,i))}drawEllipse(t,e,i,n){return this.drawShape(new Qs(t,e,i,n))}drawPolygon(...t){let e,i=!0;const n=t[0];n.points?(i=n.closeStroke,e=n.points):Array.isArray(t[0])?e=t[0]:e=t;const s=new di(e);return s.closeStroke=i,this.drawShape(s),this}drawShape(t){return this._holeMode?this._geometry.drawHole(t,this._matrix):this._geometry.drawShape(t,this._fillStyle.clone(),this._lineStyle.clone(),this._matrix),this}clear(){return this._geometry.clear(),this._lineStyle.reset(),this._fillStyle.reset(),this._boundsID++,this._matrix=null,this._holeMode=!1,this.currentPath=null,this}isFastRect(){const t=this._geometry.graphicsData;return t.length===1&&t[0].shape.type===ve.RECT&&!t[0].matrix&&!t[0].holes.length&&!(t[0].lineStyle.visible&&t[0].lineStyle.width)}_render(t){this.finishPoly();const e=this._geometry;e.updateBatches(),e.batchable?(this.batchDirty!==e.batchDirty&&this._populateBatches(),this._renderBatched(t)):(t.batch.flush(),this._renderDirect(t))}_populateBatches(){const t=this._geometry,e=this.blendMode,i=t.batches.length;this.batchTint=-1,this._transformID=-1,this.batchDirty=t.batchDirty,this.batches.length=i,this.vertexData=new Float32Array(t.points);for(let n=0;n<i;n++){const s=t.batches[n],o=s.style.color,a=new Float32Array(this.vertexData.buffer,s.attribStart*4*2,s.attribSize*2),l=new Float32Array(t.uvsFloat32.buffer,s.attribStart*4*2,s.attribSize*2),h=new Uint16Array(t.indicesUint16.buffer,s.start*2,s.size),c={vertexData:a,blendMode:e,indices:h,uvs:l,_batchRGB:Mt.shared.setValue(o).toRgbArray(),_tintRGB:o,_texture:s.style.texture,alpha:s.style.alpha,worldAlpha:1};this.batches[n]=c}}_renderBatched(t){if(this.batches.length){t.batch.setObjectRenderer(t.plugins[this.pluginName]),this.calculateVertices(),this.calculateTints();for(let e=0,i=this.batches.length;e<i;e++){const n=this.batches[e];n.worldAlpha=this.worldAlpha*n.alpha,t.plugins[this.pluginName].render(n)}}}_renderDirect(t){const e=this._resolveDirectShader(t),i=this._geometry,n=this.worldAlpha,s=e.uniforms,o=i.drawCalls;s.translationMatrix=this.transform.worldTransform,Mt.shared.setValue(this._tintColor).premultiply(n).toArray(s.tint),t.shader.bind(e),t.geometry.bind(i,e),t.state.set(this.state);for(let a=0,l=o.length;a<l;a++)this._renderDrawCallDirect(t,i.drawCalls[a])}_renderDrawCallDirect(t,e){const{texArray:i,type:n,size:s,start:o}=e,a=i.count;for(let l=0;l<a;l++)t.texture.bind(i.elements[l],l);t.geometry.draw(n,s,o)}_resolveDirectShader(t){let e=this.shader;const i=this.pluginName;if(!e){if(!Th[i]){const{maxTextures:n}=t.plugins[i],s=new Int32Array(n);for(let l=0;l<n;l++)s[l]=l;const o={tint:new Float32Array([1,1,1,1]),translationMatrix:new kt,default:We.from({uSamplers:s},!0)},a=t.plugins[i]._shader.program;Th[i]=new dr(a,o)}e=Th[i]}return e}_calculateBounds(){this.finishPoly();const t=this._geometry;if(!t.graphicsData.length)return;const{minX:e,minY:i,maxX:n,maxY:s}=t.bounds;this._bounds.addFrame(this.transform,e,i,n,s)}containsPoint(t){return this.worldTransform.applyInverse(t,Go._TEMP_POINT),this._geometry.containsPoint(Go._TEMP_POINT)}calculateTints(){if(this.batchTint!==this.tint){this.batchTint=this._tintColor.toNumber();for(let t=0;t<this.batches.length;t++){const e=this.batches[t];e._tintRGB=Mt.shared.setValue(this._tintColor).multiply(e._batchRGB).toLittleEndianNumber()}}}calculateVertices(){const t=this.transform._worldID;if(this._transformID===t)return;this._transformID=t;const e=this.transform.worldTransform,i=e.a,n=e.b,s=e.c,o=e.d,a=e.tx,l=e.ty,h=this._geometry.points,c=this.vertexData;let u=0;for(let d=0;d<h.length;d+=2){const f=h[d],p=h[d+1];c[u++]=i*f+s*p+a,c[u++]=o*p+n*f+l}}closePath(){const t=this.currentPath;return t&&(t.closeStroke=!0,this.finishPoly()),this}setMatrix(t){return this._matrix=t,this}beginHole(){return this.finishPoly(),this._holeMode=!0,this}endHole(){return this.finishPoly(),this._holeMode=!1,this}destroy(t){this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose(),this._matrix=null,this.currentPath=null,this._lineStyle.destroy(),this._lineStyle=null,this._fillStyle.destroy(),this._fillStyle=null,this._geometry=null,this.shader=null,this.vertexData=null,this.batches.length=0,this.batches=null,super.destroy(t)}};Ah.curves=cn,Ah._TEMP_POINT=new It;let ts=Ah;class uS{constructor(t,e){this.uvBuffer=t,this.uvMatrix=e,this.data=null,this._bufferUpdateId=-1,this._textureUpdateId=-1,this._updateID=0}update(t){if(!t&&this._bufferUpdateId===this.uvBuffer._updateID&&this._textureUpdateId===this.uvMatrix._updateID)return;this._bufferUpdateId=this.uvBuffer._updateID,this._textureUpdateId=this.uvMatrix._updateID;const e=this.uvBuffer.data;(!this.data||this.data.length!==e.length)&&(this.data=new Float32Array(e.length)),this.uvMatrix.multiplyUvs(e,this.data),this._updateID++}}const Sh=new It,cm=new di,um=class eg extends ze{constructor(t,e,i,n=rr.TRIANGLES){super(),this.geometry=t,this.shader=e,this.state=i||ur.for2d(),this.drawMode=n,this.start=0,this.size=0,this.uvs=null,this.indices=null,this.vertexData=new Float32Array(1),this.vertexDirty=-1,this._transformID=-1,this._roundPixels=tt.ROUND_PIXELS,this.batchUvs=null}get geometry(){return this._geometry}set geometry(t){this._geometry!==t&&(this._geometry&&(this._geometry.refCount--,this._geometry.refCount===0&&this._geometry.dispose()),this._geometry=t,this._geometry&&this._geometry.refCount++,this.vertexDirty=-1)}get uvBuffer(){return this.geometry.buffers[1]}get verticesBuffer(){return this.geometry.buffers[0]}set material(t){this.shader=t}get material(){return this.shader}set blendMode(t){this.state.blendMode=t}get blendMode(){return this.state.blendMode}set roundPixels(t){this._roundPixels!==t&&(this._transformID=-1),this._roundPixels=t}get roundPixels(){return this._roundPixels}get tint(){return"tint"in this.shader?this.shader.tint:null}set tint(t){this.shader.tint=t}get tintValue(){return this.shader.tintValue}get texture(){return"texture"in this.shader?this.shader.texture:null}set texture(t){this.shader.texture=t}_render(t){const e=this.geometry.buffers[0].data;this.shader.batchable&&this.drawMode===rr.TRIANGLES&&e.length<eg.BATCHABLE_SIZE*2?this._renderToBatch(t):this._renderDefault(t)}_renderDefault(t){const e=this.shader;e.alpha=this.worldAlpha,e.update&&e.update(),t.batch.flush(),e.uniforms.translationMatrix=this.transform.worldTransform.toArray(!0),t.shader.bind(e),t.state.set(this.state),t.geometry.bind(this.geometry,e),t.geometry.draw(this.drawMode,this.size,this.start,this.geometry.instanceCount)}_renderToBatch(t){const e=this.geometry,i=this.shader;i.uvMatrix&&(i.uvMatrix.update(),this.calculateUvs()),this.calculateVertices(),this.indices=e.indexBuffer.data,this._tintRGB=i._tintRGB,this._texture=i.texture;const n=this.material.pluginName;t.batch.setObjectRenderer(t.plugins[n]),t.plugins[n].render(this)}calculateVertices(){const t=this.geometry.buffers[0],e=t.data,i=t._updateID;if(i===this.vertexDirty&&this._transformID===this.transform._worldID)return;this._transformID=this.transform._worldID,this.vertexData.length!==e.length&&(this.vertexData=new Float32Array(e.length));const n=this.transform.worldTransform,s=n.a,o=n.b,a=n.c,l=n.d,h=n.tx,c=n.ty,u=this.vertexData;for(let d=0;d<u.length/2;d++){const f=e[d*2],p=e[d*2+1];u[d*2]=s*f+a*p+h,u[d*2+1]=o*f+l*p+c}if(this._roundPixels){const d=tt.RESOLUTION;for(let f=0;f<u.length;++f)u[f]=Math.round(u[f]*d)/d}this.vertexDirty=i}calculateUvs(){const t=this.geometry.buffers[1],e=this.shader;e.uvMatrix.isSimple?this.uvs=t.data:(this.batchUvs||(this.batchUvs=new uS(t,e.uvMatrix)),this.batchUvs.update(),this.uvs=this.batchUvs.data)}_calculateBounds(){this.calculateVertices(),this._bounds.addVertexData(this.vertexData,0,this.vertexData.length)}containsPoint(t){if(!this.getBounds().contains(t.x,t.y))return!1;this.worldTransform.applyInverse(t,Sh);const e=this.geometry.getBuffer("aVertexPosition").data,i=cm.points,n=this.geometry.getIndex().data,s=n.length,o=this.drawMode===4?3:1;for(let a=0;a+2<s;a+=o){const l=n[a]*2,h=n[a+1]*2,c=n[a+2]*2;if(i[0]=e[l],i[1]=e[l+1],i[2]=e[h],i[3]=e[h+1],i[4]=e[c],i[5]=e[c+1],cm.contains(Sh.x,Sh.y))return!0}return!1}destroy(t){super.destroy(t),this._cachedTexture&&(this._cachedTexture.destroy(),this._cachedTexture=null),this.geometry=null,this.shader=null,this.state=null,this.uvs=null,this.indices=null,this.vertexData=null}};um.BATCHABLE_SIZE=100;let dm=um;class dS extends Hr{constructor(t,e,i){super();const n=new Qt(t),s=new Qt(e,!0),o=new Qt(i,!0,!0);this.addAttribute("aVertexPosition",n,2,!1,pt.FLOAT).addAttribute("aTextureCoord",s,2,!1,pt.FLOAT).addIndex(o),this._updateId=-1}get vertexDirtyId(){return this.buffers[0]._updateID}}var fS=`varying vec2 vTextureCoord;
912
912
  uniform vec4 uColor;
913
913
 
914
914
  uniform sampler2D uSampler;
@@ -965,8 +965,8 @@ void main(void){
965
965
  vTextureCoord = aTextureCoord;
966
966
  vColor = aColor * uColor;
967
967
  }
968
- `;class mm extends no{constructor(t){super(t),this.shader=null,this.properties=null,this.tempMatrix=new kt,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:pt.UNSIGNED_BYTE,uploadFunction:this.uploadTint,offset:0}],this.shader=dr.from(gS,mS,{}),this.state=ur.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=Rf(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 m=o-f;m>n&&(m=n),p>=a.length&&a.push(this._generateOneMoreBuffer(t));const y=a[p];y.uploadDynamic(e,f,m);const _=t._bufferUpdateIDs[p]||0;d=d||y._updateID<_,d&&(y._updateID=t._updateID,y.uploadStatic(e,f,m)),s.geometry.bind(y.geometry),c.drawElements(c.TRIANGLES,m*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 pm(this.properties,s,n));return e}_generateOneMoreBuffer(t){const e=t._batchSize,i=t._properties;return new pm(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,m=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*m,n[o+s]=a*p,n[o+s+1]=c*m,n[o+s*2]=a*p,n[o+s*2+1]=h*m,n[o+s*3]=l*p,n[o+s*3+1]=h*m,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}}mm.extension={name:"particle",type:Z.RendererPlugin},ht.add(mm);var Po=(r=>(r[r.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",r[r.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",r))(Po||{});const Ro={willReadFrequently:!0},pr=class dt{static get experimentalLetterSpacingSupported(){let t=dt._experimentalLetterSpacingSupported;if(t!==void 0){const e=tt.ADAPTER.getCanvasRenderingContext2D().prototype;t=dt._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=dt._canvas){i=i??e.wordWrap;const s=e.toFontString(),o=dt.measureFont(s);o.fontSize===0&&(o.fontSize=e.fontSize,o.ascent=e.fontSize);const a=n.getContext("2d",Ro);a.font=s;const l=(i?dt.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 m=dt._measureText(l[p],e.letterSpacing,a);h[p]=m,c=Math.max(c,m)}let u=c+e.strokeThickness;e.dropShadow&&(u+=e.dropShadowDistance);const d=e.lineHeight||o.fontSize+e.strokeThickness;let f=Math.max(d,o.fontSize+e.strokeThickness*2)+e.leading+(l.length-1)*(d+e.leading);return e.dropShadow&&(f+=e.dropShadowDistance),new dt(t,e,u,f,l,h,d+e.leading,c,o)}static _measureText(t,e,i){let n=!1;dt.experimentalLetterSpacingSupported&&(dt.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+=(dt.graphemeSegmenter(t).length-1)*e),s}static wordWrap(t,e,i=dt._canvas){const n=i.getContext("2d",Ro);let s=0,o="",a="";const l=Object.create(null),{letterSpacing:h,whiteSpace:c}=e,u=dt.collapseSpaces(c),d=dt.collapseNewlines(c);let f=!u;const p=e.wordWrapWidth+h,m=dt.tokenize(t);for(let y=0;y<m.length;y++){let _=m[y];if(dt.isNewline(_)){if(!d){a+=dt.addLine(o),f=!u,o="",s=0;continue}_=" "}if(u){const g=dt.isBreakingSpace(_),b=dt.isBreakingSpace(o[o.length-1]);if(g&&b)continue}const v=dt.getFromCache(_,h,l,n);if(v>p)if(o!==""&&(a+=dt.addLine(o),o="",s=0),dt.canBreakWords(_,e.breakWords)){const g=dt.wordWrapSplit(_);for(let b=0;b<g.length;b++){let S=g[b],R=S,C=1;for(;g[b+C];){const M=g[b+C];if(!dt.canBreakChars(R,M,_,b,e.breakWords))S+=M;else break;R=M,C++}b+=C-1;const I=dt.getFromCache(S,h,l,n);I+s>p&&(a+=dt.addLine(o),f=!1,o="",s=0),o+=S,s+=I}}else{o.length>0&&(a+=dt.addLine(o),o="",s=0);const g=y===m.length-1;a+=dt.addLine(_,!g),f=!1,o="",s=0}else v+s>p&&(f=!1,a+=dt.addLine(o),o="",s=0),(o.length>0||!dt.isBreakingSpace(_)||f)&&(o+=_,s+=v)}return a+=dt.addLine(o,!1),a}static addLine(t,e=!0){return t=dt.trimRight(t),t=e?`${t}
969
- `:t,t}static getFromCache(t,e,i,n){let s=i[t];return typeof s!="number"&&(s=dt._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(!dt.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static isNewline(t){return typeof t!="string"?!1:dt._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:dt._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(dt.isBreakingSpace(s,o)||dt.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 dt.graphemeSegmenter(t)}static measureFont(t){if(dt._fonts[t])return dt._fonts[t];const e={ascent:0,descent:0,fontSize:0},i=dt._canvas,n=dt._context;n.font=t;const s=dt.METRICS_STRING+dt.BASELINE_SYMBOL,o=Math.ceil(n.measureText(s).width);let a=Math.ceil(n.measureText(dt.BASELINE_SYMBOL).width);const l=Math.ceil(dt.HEIGHT_MULTIPLIER*a);if(a=a*dt.BASELINE_MULTIPLIER|0,o===0||l===0)return dt._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 m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f+=u;else break}for(e.ascent=a-d,f=c-u,p=!1,d=l;d>a;--d){for(let m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f-=u;else break}return e.descent=d-a,e.fontSize=e.ascent+e.descent,dt._fonts[t]=e,e}static clearMetrics(t=""){t?delete dt._fonts[t]:dt._fonts={}}static get _canvas(){var t;if(!dt.__canvas){let e;try{const i=new OffscreenCanvas(0,0);if((t=i.getContext("2d",Ro))!=null&&t.measureText)return dt.__canvas=i,i;e=tt.ADAPTER.createCanvas()}catch{e=tt.ADAPTER.createCanvas()}e.width=e.height=10,dt.__canvas=e}return dt.__canvas}static get _context(){return dt.__context||(dt.__context=dt._canvas.getContext("2d",Ro)),dt.__context}};pr.METRICS_STRING="|ÉqÅ",pr.BASELINE_SYMBOL="M",pr.BASELINE_MULTIPLIER=1.4,pr.HEIGHT_MULTIPLIER=2,pr.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]})(),pr.experimentalLetterSpacing=!1,pr._fonts={},pr._newlines=[10,13],pr._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let Wr=pr;const yS=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],gm=class ss{constructor(t){this.styleID=0,this.reset(),Ih(this,t,t)}clone(){const t={};return Ih(t,this,ss.defaultStyle),new ss(t)}reset(){Ih(this,ss.defaultStyle,ss.defaultStyle)}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.styleID++)}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords!==t&&(this._breakWords=t,this.styleID++)}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow!==t&&(this._dropShadow=t,this.styleID++)}get dropShadowAlpha(){return this._dropShadowAlpha}set dropShadowAlpha(t){this._dropShadowAlpha!==t&&(this._dropShadowAlpha=t,this.styleID++)}get dropShadowAngle(){return this._dropShadowAngle}set dropShadowAngle(t){this._dropShadowAngle!==t&&(this._dropShadowAngle=t,this.styleID++)}get dropShadowBlur(){return this._dropShadowBlur}set dropShadowBlur(t){this._dropShadowBlur!==t&&(this._dropShadowBlur=t,this.styleID++)}get dropShadowColor(){return this._dropShadowColor}set dropShadowColor(t){const e=Ch(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=Ch(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){_S(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=Ch(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)&&!yS.includes(n)&&(n=`"${n}"`),e[i]=n}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};gm.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Po.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 zr=gm;function Ch(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 _S(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 Ih(r,t,e){for(const i in e)Array.isArray(t[i])?r[i]=t[i].slice():r[i]=t[i]}const vS={texture:!0,children:!1,baseTexture:!0},ym=class Vh extends nn{constructor(t,e,i){let n=!1;i||(i=tt.ADAPTER.createCanvas(),n=!0),i.width=3,i.height=3;const s=ct.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=Vh.defaultResolution??tt.RESOLUTION,this._autoResolution=Vh.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 Wr.experimentalLetterSpacing}static set experimentalLetterSpacing(t){At("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),Wr.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=Wr.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 m=0;m<p;++m){const y=e.dropShadow&&m===0,_=y?Math.ceil(Math.max(1,o)+e.padding*2):0,v=_*this._resolution;if(y){i.fillStyle="black",i.strokeStyle="black";const b=e.dropShadowColor,S=e.dropShadowBlur*this._resolution,R=e.dropShadowDistance*this._resolution;i.shadowColor=Mt.shared.setValue(b).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 g=(l-u.fontSize)/2;l-u.fontSize<0&&(g=0);for(let b=0;b<a.length;b++)d=e.strokeThickness/2,f=e.strokeThickness/2+b*l+u.ascent+g,e.align==="right"?d+=c-h[b]:e.align==="center"&&(d+=(c-h[b])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(a[b],d+e.padding,f+e.padding-_,!0),e.fill&&this.drawLetterSpacing(a[b],d+e.padding,f+e.padding-_)}this.updateTexture()}drawLetterSpacing(t,e,i,n=!1){const s=this._style.letterSpacing;let o=!1;if(Wr.experimentalLetterSpacingSupported&&(Wr.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=Wr.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=Uw(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===Po.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,m=i.lineHeight*f;let y=m;f>0&&p>m&&(y=(m+p)/2);const _=m+d,v=i.lineHeight*(f+1);let g=_;f+1<e.length&&v<_&&(g=(_+v)/2);const b=(g-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*b));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 m;typeof u[p]=="number"?m=u[p]:m=f/d,s.addColorStop(m,c[p]),f++}}return s}destroy(t){typeof t=="boolean"&&(t={children:t}),t=Object.assign({},vS,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=Gr(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=Gr(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 zr?this._style=t:this._style=new zr(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)}};ym.defaultAutoResolution=!0;let _m=ym;class bS{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function xS(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 ct){const s=r._textures[n].baseTexture;t.includes(s)||(t.push(s),e=!0)}}return e}function wS(r,t){if(r.baseTexture instanceof bt){const e=r.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function ES(r,t){if(r._texture&&r._texture instanceof ct){const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function TS(r,t){return t instanceof _m?(t.updateText(!0),!0):!1}function AS(r,t){if(t instanceof zr){const e=t.toFontString();return Wr.measureFont(e),!0}return!1}function SS(r,t){if(r instanceof _m){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 CS(r,t){return r instanceof zr?(t.includes(r)||t.push(r),!0):!1}const vm=class rg{constructor(t){this.limiter=new bS(rg.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(SS),this.registerFindHook(CS),this.registerFindHook(xS),this.registerFindHook(wS),this.registerFindHook(ES),this.registerUploadHook(TS),this.registerUploadHook(AS)}upload(t){return new Promise(e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,Be.system.addOnce(this.tick,this,xi.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)Be.system.addOnce(this.tick,this,xi.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&&Be.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}};vm.uploadsPerFrame=4;let Ph=vm;Object.defineProperties(tt,{UPLOADS_PER_FRAME:{get(){return Ph.uploadsPerFrame},set(r){At("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),Ph.uploadsPerFrame=r}}});function bm(r,t){return t instanceof bt?(t._glTextures[r.CONTEXT_UID]||r.texture.bind(t),!0):!1}function IS(r,t){if(!(t instanceof ts))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 PS(r,t){return r instanceof ts?(t.push(r),!0):!1}class xm extends Ph{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(PS),this.registerUploadHook(bm),this.registerUploadHook(IS)}}xm.extension={name:"prepare",type:Z.RendererSystem},ht.add(xm);var RS=`#version 300 es
968
+ `;class mm extends no{constructor(t){super(t),this.shader=null,this.properties=null,this.tempMatrix=new kt,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:pt.UNSIGNED_BYTE,uploadFunction:this.uploadTint,offset:0}],this.shader=dr.from(gS,mS,{}),this.state=ur.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=Rf(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 m=o-f;m>n&&(m=n),p>=a.length&&a.push(this._generateOneMoreBuffer(t));const y=a[p];y.uploadDynamic(e,f,m);const _=t._bufferUpdateIDs[p]||0;d=d||y._updateID<_,d&&(y._updateID=t._updateID,y.uploadStatic(e,f,m)),s.geometry.bind(y.geometry),c.drawElements(c.TRIANGLES,m*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 pm(this.properties,s,n));return e}_generateOneMoreBuffer(t){const e=t._batchSize,i=t._properties;return new pm(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,m=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*m,n[o+s]=a*p,n[o+s+1]=c*m,n[o+s*2]=a*p,n[o+s*2+1]=h*m,n[o+s*3]=l*p,n[o+s*3+1]=h*m,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}}mm.extension={name:"particle",type:Z.RendererPlugin},ht.add(mm);var Po=(r=>(r[r.LINEAR_VERTICAL=0]="LINEAR_VERTICAL",r[r.LINEAR_HORIZONTAL=1]="LINEAR_HORIZONTAL",r))(Po||{});const Ro={willReadFrequently:!0},pr=class ft{static get experimentalLetterSpacingSupported(){let t=ft._experimentalLetterSpacingSupported;if(t!==void 0){const e=tt.ADAPTER.getCanvasRenderingContext2D().prototype;t=ft._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=ft._canvas){i=i??e.wordWrap;const s=e.toFontString(),o=ft.measureFont(s);o.fontSize===0&&(o.fontSize=e.fontSize,o.ascent=e.fontSize);const a=n.getContext("2d",Ro);a.font=s;const l=(i?ft.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 m=ft._measureText(l[p],e.letterSpacing,a);h[p]=m,c=Math.max(c,m)}let u=c+e.strokeThickness;e.dropShadow&&(u+=e.dropShadowDistance);const d=e.lineHeight||o.fontSize+e.strokeThickness;let f=Math.max(d,o.fontSize+e.strokeThickness*2)+e.leading+(l.length-1)*(d+e.leading);return e.dropShadow&&(f+=e.dropShadowDistance),new ft(t,e,u,f,l,h,d+e.leading,c,o)}static _measureText(t,e,i){let n=!1;ft.experimentalLetterSpacingSupported&&(ft.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+=(ft.graphemeSegmenter(t).length-1)*e),s}static wordWrap(t,e,i=ft._canvas){const n=i.getContext("2d",Ro);let s=0,o="",a="";const l=Object.create(null),{letterSpacing:h,whiteSpace:c}=e,u=ft.collapseSpaces(c),d=ft.collapseNewlines(c);let f=!u;const p=e.wordWrapWidth+h,m=ft.tokenize(t);for(let y=0;y<m.length;y++){let _=m[y];if(ft.isNewline(_)){if(!d){a+=ft.addLine(o),f=!u,o="",s=0;continue}_=" "}if(u){const g=ft.isBreakingSpace(_),b=ft.isBreakingSpace(o[o.length-1]);if(g&&b)continue}const v=ft.getFromCache(_,h,l,n);if(v>p)if(o!==""&&(a+=ft.addLine(o),o="",s=0),ft.canBreakWords(_,e.breakWords)){const g=ft.wordWrapSplit(_);for(let b=0;b<g.length;b++){let S=g[b],R=S,C=1;for(;g[b+C];){const M=g[b+C];if(!ft.canBreakChars(R,M,_,b,e.breakWords))S+=M;else break;R=M,C++}b+=C-1;const I=ft.getFromCache(S,h,l,n);I+s>p&&(a+=ft.addLine(o),f=!1,o="",s=0),o+=S,s+=I}}else{o.length>0&&(a+=ft.addLine(o),o="",s=0);const g=y===m.length-1;a+=ft.addLine(_,!g),f=!1,o="",s=0}else v+s>p&&(f=!1,a+=ft.addLine(o),o="",s=0),(o.length>0||!ft.isBreakingSpace(_)||f)&&(o+=_,s+=v)}return a+=ft.addLine(o,!1),a}static addLine(t,e=!0){return t=ft.trimRight(t),t=e?`${t}
969
+ `:t,t}static getFromCache(t,e,i,n){let s=i[t];return typeof s!="number"&&(s=ft._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(!ft.isBreakingSpace(i))break;t=t.slice(0,-1)}return t}static isNewline(t){return typeof t!="string"?!1:ft._newlines.includes(t.charCodeAt(0))}static isBreakingSpace(t,e){return typeof t!="string"?!1:ft._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(ft.isBreakingSpace(s,o)||ft.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 ft.graphemeSegmenter(t)}static measureFont(t){if(ft._fonts[t])return ft._fonts[t];const e={ascent:0,descent:0,fontSize:0},i=ft._canvas,n=ft._context;n.font=t;const s=ft.METRICS_STRING+ft.BASELINE_SYMBOL,o=Math.ceil(n.measureText(s).width);let a=Math.ceil(n.measureText(ft.BASELINE_SYMBOL).width);const l=Math.ceil(ft.HEIGHT_MULTIPLIER*a);if(a=a*ft.BASELINE_MULTIPLIER|0,o===0||l===0)return ft._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 m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f+=u;else break}for(e.ascent=a-d,f=c-u,p=!1,d=l;d>a;--d){for(let m=0;m<u;m+=4)if(h[f+m]!==255){p=!0;break}if(!p)f-=u;else break}return e.descent=d-a,e.fontSize=e.ascent+e.descent,ft._fonts[t]=e,e}static clearMetrics(t=""){t?delete ft._fonts[t]:ft._fonts={}}static get _canvas(){var t;if(!ft.__canvas){let e;try{const i=new OffscreenCanvas(0,0);if((t=i.getContext("2d",Ro))!=null&&t.measureText)return ft.__canvas=i,i;e=tt.ADAPTER.createCanvas()}catch{e=tt.ADAPTER.createCanvas()}e.width=e.height=10,ft.__canvas=e}return ft.__canvas}static get _context(){return ft.__context||(ft.__context=ft._canvas.getContext("2d",Ro)),ft.__context}};pr.METRICS_STRING="|ÉqÅ",pr.BASELINE_SYMBOL="M",pr.BASELINE_MULTIPLIER=1.4,pr.HEIGHT_MULTIPLIER=2,pr.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]})(),pr.experimentalLetterSpacing=!1,pr._fonts={},pr._newlines=[10,13],pr._breakingSpaces=[9,32,8192,8193,8194,8195,8196,8197,8198,8200,8201,8202,8287,12288];let Wr=pr;const yS=["serif","sans-serif","monospace","cursive","fantasy","system-ui"],gm=class ss{constructor(t){this.styleID=0,this.reset(),Ih(this,t,t)}clone(){const t={};return Ih(t,this,ss.defaultStyle),new ss(t)}reset(){Ih(this,ss.defaultStyle,ss.defaultStyle)}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.styleID++)}get breakWords(){return this._breakWords}set breakWords(t){this._breakWords!==t&&(this._breakWords=t,this.styleID++)}get dropShadow(){return this._dropShadow}set dropShadow(t){this._dropShadow!==t&&(this._dropShadow=t,this.styleID++)}get dropShadowAlpha(){return this._dropShadowAlpha}set dropShadowAlpha(t){this._dropShadowAlpha!==t&&(this._dropShadowAlpha=t,this.styleID++)}get dropShadowAngle(){return this._dropShadowAngle}set dropShadowAngle(t){this._dropShadowAngle!==t&&(this._dropShadowAngle=t,this.styleID++)}get dropShadowBlur(){return this._dropShadowBlur}set dropShadowBlur(t){this._dropShadowBlur!==t&&(this._dropShadowBlur=t,this.styleID++)}get dropShadowColor(){return this._dropShadowColor}set dropShadowColor(t){const e=Ch(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=Ch(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){_S(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=Ch(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)&&!yS.includes(n)&&(n=`"${n}"`),e[i]=n}return`${this.fontStyle} ${this.fontVariant} ${this.fontWeight} ${t} ${e.join(",")}`}};gm.defaultStyle={align:"left",breakWords:!1,dropShadow:!1,dropShadowAlpha:1,dropShadowAngle:Math.PI/6,dropShadowBlur:0,dropShadowColor:"black",dropShadowDistance:5,fill:"black",fillGradientType:Po.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 zr=gm;function Ch(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 _S(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 Ih(r,t,e){for(const i in e)Array.isArray(t[i])?r[i]=t[i].slice():r[i]=t[i]}const vS={texture:!0,children:!1,baseTexture:!0},ym=class Vh extends nn{constructor(t,e,i){let n=!1;i||(i=tt.ADAPTER.createCanvas(),n=!0),i.width=3,i.height=3;const s=ct.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=Vh.defaultResolution??tt.RESOLUTION,this._autoResolution=Vh.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 Wr.experimentalLetterSpacing}static set experimentalLetterSpacing(t){At("7.1.0","Text.experimentalLetterSpacing is deprecated, use TextMetrics.experimentalLetterSpacing"),Wr.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=Wr.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 m=0;m<p;++m){const y=e.dropShadow&&m===0,_=y?Math.ceil(Math.max(1,o)+e.padding*2):0,v=_*this._resolution;if(y){i.fillStyle="black",i.strokeStyle="black";const b=e.dropShadowColor,S=e.dropShadowBlur*this._resolution,R=e.dropShadowDistance*this._resolution;i.shadowColor=Mt.shared.setValue(b).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 g=(l-u.fontSize)/2;l-u.fontSize<0&&(g=0);for(let b=0;b<a.length;b++)d=e.strokeThickness/2,f=e.strokeThickness/2+b*l+u.ascent+g,e.align==="right"?d+=c-h[b]:e.align==="center"&&(d+=(c-h[b])/2),e.stroke&&e.strokeThickness&&this.drawLetterSpacing(a[b],d+e.padding,f+e.padding-_,!0),e.fill&&this.drawLetterSpacing(a[b],d+e.padding,f+e.padding-_)}this.updateTexture()}drawLetterSpacing(t,e,i,n=!1){const s=this._style.letterSpacing;let o=!1;if(Wr.experimentalLetterSpacingSupported&&(Wr.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=Wr.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=Uw(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===Po.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,m=i.lineHeight*f;let y=m;f>0&&p>m&&(y=(m+p)/2);const _=m+d,v=i.lineHeight*(f+1);let g=_;f+1<e.length&&v<_&&(g=(_+v)/2);const b=(g-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*b));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 m;typeof u[p]=="number"?m=u[p]:m=f/d,s.addColorStop(m,c[p]),f++}}return s}destroy(t){typeof t=="boolean"&&(t={children:t}),t=Object.assign({},vS,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=Gr(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=Gr(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 zr?this._style=t:this._style=new zr(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)}};ym.defaultAutoResolution=!0;let _m=ym;class bS{constructor(t){this.maxItemsPerFrame=t,this.itemsLeft=0}beginFrame(){this.itemsLeft=this.maxItemsPerFrame}allowedToUpload(){return this.itemsLeft-- >0}}function xS(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 ct){const s=r._textures[n].baseTexture;t.includes(s)||(t.push(s),e=!0)}}return e}function wS(r,t){if(r.baseTexture instanceof bt){const e=r.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function ES(r,t){if(r._texture&&r._texture instanceof ct){const e=r._texture.baseTexture;return t.includes(e)||t.push(e),!0}return!1}function TS(r,t){return t instanceof _m?(t.updateText(!0),!0):!1}function AS(r,t){if(t instanceof zr){const e=t.toFontString();return Wr.measureFont(e),!0}return!1}function SS(r,t){if(r instanceof _m){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 CS(r,t){return r instanceof zr?(t.includes(r)||t.push(r),!0):!1}const vm=class rg{constructor(t){this.limiter=new bS(rg.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(SS),this.registerFindHook(CS),this.registerFindHook(xS),this.registerFindHook(wS),this.registerFindHook(ES),this.registerUploadHook(TS),this.registerUploadHook(AS)}upload(t){return new Promise(e=>{t&&this.add(t),this.queue.length?(this.completes.push(e),this.ticking||(this.ticking=!0,Be.system.addOnce(this.tick,this,xi.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)Be.system.addOnce(this.tick,this,xi.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&&Be.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}};vm.uploadsPerFrame=4;let Ph=vm;Object.defineProperties(tt,{UPLOADS_PER_FRAME:{get(){return Ph.uploadsPerFrame},set(r){At("7.1.0","settings.UPLOADS_PER_FRAME is deprecated, use prepare.BasePrepare.uploadsPerFrame"),Ph.uploadsPerFrame=r}}});function bm(r,t){return t instanceof bt?(t._glTextures[r.CONTEXT_UID]||r.texture.bind(t),!0):!1}function IS(r,t){if(!(t instanceof ts))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 PS(r,t){return r instanceof ts?(t.push(r),!0):!1}class xm extends Ph{constructor(t){super(t),this.uploadHookHelper=this.renderer,this.registerFindHook(PS),this.registerUploadHook(bm),this.registerUploadHook(IS)}}xm.extension={name:"prepare",type:Z.RendererSystem},ht.add(xm);var RS=`#version 300 es
970
970
  #define SHADER_NAME Tiling-Sprite-100
971
971
 
972
972
  precision lowp float;
@@ -1080,7 +1080,7 @@ void main(void)
1080
1080
  vec4 texSample = texture2D(uSampler, vTextureCoord);
1081
1081
  gl_FragColor = texSample * uColor;
1082
1082
  }
1083
- `;const Mo=new kt;class Em extends no{constructor(t){super(t),t.runners.contextChange.add(this),this.quad=new ip,this.state=ur.for2d()}contextChange(){const t=this.renderer,e={globals:t.globalUniforms};this.simpleShader=dr.from(wm,BS,e),this.shader=t.context.webGLVersion>1?dr.from(MS,RS,e):dr.from(wm,DS,e)}render(t){const e=this.renderer,i=this.quad;let n=i.vertices;n[0]=n[6]=t._width*-t.anchor.x,n[1]=n[3]=t._height*-t.anchor.y,n[2]=n[4]=t._width*(1-t.anchor.x),n[5]=n[7]=t._height*(1-t.anchor.y);const s=t.uvRespectAnchor?t.anchor.x:0,o=t.uvRespectAnchor?t.anchor.y:0;n=i.uvs,n[0]=n[6]=-s,n[1]=n[3]=-o,n[2]=n[4]=1-s,n[5]=n[7]=1-o,i.invalidate();const a=t._texture,l=a.baseTexture,h=l.alphaMode>0,c=t.tileTransform.localTransform,u=t.uvMatrix;let d=l.isPowerOfTwo&&a.frame.width===l.width&&a.frame.height===l.height;d&&(l._glTextures[e.CONTEXT_UID]?d=l.wrapMode!==Fr.CLAMP:l.wrapMode===Fr.CLAMP&&(l.wrapMode=Fr.REPEAT));const f=d?this.simpleShader:this.shader,p=a.width,m=a.height,y=t._width,_=t._height;Mo.set(c.a*p/y,c.b*p/_,c.c*m/y,c.d*m/_,c.tx/y,c.ty/_),Mo.invert(),d?Mo.prepend(u.mapCoord):(f.uniforms.uMapCoord=u.mapCoord.toArray(!0),f.uniforms.uClampFrame=u.uClampFrame,f.uniforms.uClampOffset=u.uClampOffset),f.uniforms.uTransform=Mo.toArray(!0),f.uniforms.uColor=Mt.shared.setValue(t.tint).premultiply(t.worldAlpha,h).toArray(f.uniforms.uColor),f.uniforms.translationMatrix=t.transform.worldTransform.toArray(!0),f.uniforms.uSampler=a,e.shader.bind(f),e.geometry.bind(i),this.state.blendMode=Rf(t.blendMode,h),e.state.set(this.state),e.geometry.draw(this.renderer.gl.TRIANGLES,6,0)}}Em.extension={name:"tilingSprite",type:Z.RendererPlugin},ht.add(Em);const Tm=class os{constructor(t,e,i){this.linkedSheets=[],(t instanceof bt||t instanceof ct)&&(t={texture:t,data:e,resolutionFilename:i});const{texture:n,data:s,resolutionFilename:o=null,cachePrefix:a=""}=t;this.cachePrefix=a,this._texture=n instanceof ct?n:null,this.baseTexture=n instanceof bt?n:this._texture.baseTexture,this.textures={},this.animations={},this.data=s;const l=this.baseTexture.resource;this.resolution=this._updateResolution(o||(l?l.url:null)),this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}_updateResolution(t=null){const{scale:e}=this.data.meta;let i=wr(t,null);return i===null&&(i=typeof e=="number"?e:parseFloat(e??"1")),i!==1&&this.baseTexture.setResolution(i),i}parse(){return new Promise(t=>{this._callback=t,this._batchIndex=0,this._frameKeys.length<=os.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}_processFrames(t){let e=t;const i=os.BATCH_SIZE;for(;e-t<i&&e<this._frameKeys.length;){const n=this._frameKeys[e],s=this._frames[n],o=s.frame;if(o){let a=null,l=null;const h=s.trimmed!==!1&&s.sourceSize?s.sourceSize:s.frame,c=new wt(0,0,Math.floor(h.w)/this.resolution,Math.floor(h.h)/this.resolution);s.rotated?a=new wt(Math.floor(o.x)/this.resolution,Math.floor(o.y)/this.resolution,Math.floor(o.h)/this.resolution,Math.floor(o.w)/this.resolution):a=new wt(Math.floor(o.x)/this.resolution,Math.floor(o.y)/this.resolution,Math.floor(o.w)/this.resolution,Math.floor(o.h)/this.resolution),s.trimmed!==!1&&s.spriteSourceSize&&(l=new wt(Math.floor(s.spriteSourceSize.x)/this.resolution,Math.floor(s.spriteSourceSize.y)/this.resolution,Math.floor(o.w)/this.resolution,Math.floor(o.h)/this.resolution)),this.textures[n]=new ct(this.baseTexture,a,c,l,s.rotated?2:0,s.anchor,s.borders),ct.addToCache(this.textures[n],this.cachePrefix+n.toString())}e++}}_processAnimations(){const t=this.data.animations||{};for(const e in t){this.animations[e]=[];for(let i=0;i<t[e].length;i++){const n=t[e][i];this.animations[e].push(this.textures[n])}}}_parseComplete(){const t=this._callback;this._callback=null,this._batchIndex=0,t.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*os.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*os.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(t=!1){var e;for(const i in this.textures)this.textures[i].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,t&&((e=this._texture)==null||e.destroy(),this.baseTexture.destroy()),this._texture=null,this.baseTexture=null,this.linkedSheets=[]}};Tm.BATCH_SIZE=1e3;let Am=Tm;const OS=["jpg","png","jpeg","avif","webp","s3tc","s3tc_sRGB","etc","etc1","pvrtc","atc","astc","bptc"];function Sm(r,t,e){const i={};if(r.forEach(n=>{i[n]=t}),Object.keys(t.textures).forEach(n=>{i[`${t.cachePrefix}${n}`]=t.textures[n]}),!e){const n=ue.dirname(r[0]);t.linkedSheets.forEach((s,o)=>{Object.assign(i,Sm([`${n}/${t.data.meta.related_multi_packs[o]}`],s,!0))})}return i}const LS={extension:Z.Asset,cache:{test:r=>r instanceof Am,getCacheableAssets:(r,t)=>Sm(r,t,!1)},resolver:{test:r=>{const t=r.split("?")[0].split("."),e=t.pop(),i=t.pop();return e==="json"&&OS.includes(i)},parse:r=>{var e;const t=r.split(".");return{resolution:parseFloat(((e=tt.RETINA_PREFIX.exec(r))==null?void 0:e[1])??"1"),format:t[t.length-2],src:r}}},loader:{name:"spritesheetLoader",extension:{type:Z.LoadParser,priority:Ke.Normal},async testParse(r,t){return ue.extname(t.src).toLowerCase()===".json"&&!!r.frames},async parse(r,t,e){var c,u;const{texture:i,imageFilename:n,cachePrefix:s}=(t==null?void 0:t.data)??{};let o=ue.dirname(t.src);o&&o.lastIndexOf("/")!==o.length-1&&(o+="/");let a;if(i&&i.baseTexture)a=i;else{const d=ph(o+(n??r.meta.image),t.src);a=(await e.load([d]))[d]}const l=new Am({texture:a.baseTexture,data:r,resolutionFilename:t.src,cachePrefix:s});await l.parse();const h=(c=r==null?void 0:r.meta)==null?void 0:c.related_multi_packs;if(Array.isArray(h)){const d=[];for(const p of h){if(typeof p!="string")continue;let m=o+p;(u=t.data)!=null&&u.ignoreMultiPack||(m=ph(m,t.src),d.push(e.load({src:m,data:{ignoreMultiPack:!0}})))}const f=await Promise.all(d);l.linkedSheets=f,f.forEach(p=>{p.linkedSheets=[l].concat(l.linkedSheets.filter(m=>m!==p))})}return l},unload(r){r.destroy(!0)}}};ht.add(LS);class Do{constructor(){this.info=[],this.common=[],this.page=[],this.char=[],this.kerning=[],this.distanceField=[]}}class Bo{static test(t){return typeof t=="string"&&t.startsWith("info face=")}static parse(t){const e=t.match(/^[a-z]+\s+.+$/gm),i={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const s in e){const o=e[s].match(/^[a-z]+/gm)[0],a=e[s].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),l={};for(const h in a){const c=a[h].split("="),u=c[0],d=c[1].replace(/"/gm,""),f=parseFloat(d),p=isNaN(f)?d:f;l[u]=p}i[o].push(l)}const n=new Do;return i.info.forEach(s=>n.info.push({face:s.face,size:parseInt(s.size,10)})),i.common.forEach(s=>n.common.push({lineHeight:parseInt(s.lineHeight,10)})),i.page.forEach(s=>n.page.push({id:parseInt(s.id,10),file:s.file})),i.char.forEach(s=>n.char.push({id:parseInt(s.id,10),page:parseInt(s.page,10),x:parseInt(s.x,10),y:parseInt(s.y,10),width:parseInt(s.width,10),height:parseInt(s.height,10),xoffset:parseInt(s.xoffset,10),yoffset:parseInt(s.yoffset,10),xadvance:parseInt(s.xadvance,10)})),i.kerning.forEach(s=>n.kerning.push({first:parseInt(s.first,10),second:parseInt(s.second,10),amount:parseInt(s.amount,10)})),i.distanceField.forEach(s=>n.distanceField.push({distanceRange:parseInt(s.distanceRange,10),fieldType:s.fieldType})),n}}class Rh{static test(t){const e=t;return typeof t!="string"&&"getElementsByTagName"in t&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null}static parse(t){const e=new Do,i=t.getElementsByTagName("info"),n=t.getElementsByTagName("common"),s=t.getElementsByTagName("page"),o=t.getElementsByTagName("char"),a=t.getElementsByTagName("kerning"),l=t.getElementsByTagName("distanceField");for(let h=0;h<i.length;h++)e.info.push({face:i[h].getAttribute("face"),size:parseInt(i[h].getAttribute("size"),10)});for(let h=0;h<n.length;h++)e.common.push({lineHeight:parseInt(n[h].getAttribute("lineHeight"),10)});for(let h=0;h<s.length;h++)e.page.push({id:parseInt(s[h].getAttribute("id"),10)||0,file:s[h].getAttribute("file")});for(let h=0;h<o.length;h++){const c=o[h];e.char.push({id:parseInt(c.getAttribute("id"),10),page:parseInt(c.getAttribute("page"),10)||0,x:parseInt(c.getAttribute("x"),10),y:parseInt(c.getAttribute("y"),10),width:parseInt(c.getAttribute("width"),10),height:parseInt(c.getAttribute("height"),10),xoffset:parseInt(c.getAttribute("xoffset"),10),yoffset:parseInt(c.getAttribute("yoffset"),10),xadvance:parseInt(c.getAttribute("xadvance"),10)})}for(let h=0;h<a.length;h++)e.kerning.push({first:parseInt(a[h].getAttribute("first"),10),second:parseInt(a[h].getAttribute("second"),10),amount:parseInt(a[h].getAttribute("amount"),10)});for(let h=0;h<l.length;h++)e.distanceField.push({fieldType:l[h].getAttribute("fieldType"),distanceRange:parseInt(l[h].getAttribute("distanceRange"),10)});return e}}class Mh{static test(t){return typeof t=="string"&&t.includes("<font>")?Rh.test(tt.ADAPTER.parseXML(t)):!1}static parse(t){return Rh.parse(tt.ADAPTER.parseXML(t))}}const Dh=[Bo,Rh,Mh];function NS(r){for(let t=0;t<Dh.length;t++)if(Dh[t].test(r))return Dh[t];return null}function FS(r,t,e,i,n,s){const o=e.fill;if(Array.isArray(o)){if(o.length===1)return o[0]}else return o;let a;const l=e.dropShadow?e.dropShadowDistance:0,h=e.padding||0,c=r.width/i-l-h*2,u=r.height/i-l-h*2,d=o.slice(),f=e.fillGradientStops.slice();if(!f.length){const p=d.length+1;for(let m=1;m<p;++m)f.push(m/p)}if(d.unshift(o[0]),f.unshift(0),d.push(o[o.length-1]),f.push(1),e.fillGradientType===Po.LINEAR_VERTICAL){a=t.createLinearGradient(c/2,h,c/2,u+h);let p=0;const m=(s.fontProperties.fontSize+e.strokeThickness)/u;for(let y=0;y<n.length;y++){const _=s.lineHeight*y;for(let v=0;v<d.length;v++){let g=0;typeof f[v]=="number"?g=f[v]:g=v/d.length;const b=_/u+g*m;let S=Math.max(p,b);S=Math.min(S,1),a.addColorStop(S,d[v]),p=S}}}else{a=t.createLinearGradient(h,u/2,c+h,u/2);const p=d.length+1;let m=1;for(let y=0;y<d.length;y++){let _;typeof f[y]=="number"?_=f[y]:_=m/p,a.addColorStop(_,d[y]),m++}}return a}function kS(r,t,e,i,n,s,o){const a=e.text,l=e.fontProperties;t.translate(i,n),t.scale(s,s);const h=o.strokeThickness/2,c=-(o.strokeThickness/2);if(t.font=o.toFontString(),t.lineWidth=o.strokeThickness,t.textBaseline=o.textBaseline,t.lineJoin=o.lineJoin,t.miterLimit=o.miterLimit,t.fillStyle=FS(r,t,o,s,[a],e),t.strokeStyle=o.stroke,o.dropShadow){const u=o.dropShadowColor,d=o.dropShadowBlur*s,f=o.dropShadowDistance*s;t.shadowColor=Mt.shared.setValue(u).setAlpha(o.dropShadowAlpha).toRgbaString(),t.shadowBlur=d,t.shadowOffsetX=Math.cos(o.dropShadowAngle)*f,t.shadowOffsetY=Math.sin(o.dropShadowAngle)*f}else t.shadowColor="black",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0;o.stroke&&o.strokeThickness&&t.strokeText(a,h,c+e.lineHeight-l.descent),o.fill&&t.fillText(a,h,c+e.lineHeight-l.descent),t.setTransform(1,0,0,1,0,0),t.fillStyle="rgba(0, 0, 0, 0)"}function Oo(r){return r.codePointAt?r.codePointAt(0):r.charCodeAt(0)}function Cm(r){return Array.from?Array.from(r):r.split("")}function US(r){typeof r=="string"&&(r=[r]);const t=[];for(let e=0,i=r.length;e<i;e++){const n=r[e];if(Array.isArray(n)){if(n.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${n.length}.`);const s=n[0].charCodeAt(0),o=n[1].charCodeAt(0);if(o<s)throw new Error("[BitmapFont]: Invalid character range.");for(let a=s,l=o;a<=l;a++)t.push(String.fromCharCode(a))}else t.push(...Cm(n))}if(t.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return t}const Yr=class mr{constructor(t,e,i){var c;const[n]=t.info,[s]=t.common,[o]=t.page,[a]=t.distanceField,l=wr(o.file),h={};this._ownsTextures=i,this.font=n.face,this.size=n.size,this.lineHeight=s.lineHeight/l,this.chars={},this.pageTextures=h;for(let u=0;u<t.page.length;u++){const{id:d,file:f}=t.page[u];h[d]=e instanceof Array?e[u]:e[f],a!=null&&a.fieldType&&a.fieldType!=="none"&&(h[d].baseTexture.alphaMode=Re.NO_PREMULTIPLIED_ALPHA,h[d].baseTexture.mipmap=ir.OFF)}for(let u=0;u<t.char.length;u++){const{id:d,page:f}=t.char[u];let{x:p,y:m,width:y,height:_,xoffset:v,yoffset:g,xadvance:b}=t.char[u];p/=l,m/=l,y/=l,_/=l,v/=l,g/=l,b/=l;const S=new wt(p+h[f].frame.x/l,m+h[f].frame.y/l,y,_);this.chars[d]={xOffset:v,yOffset:g,xAdvance:b,kerning:{},texture:new ct(h[f].baseTexture,S),page:f}}for(let u=0;u<t.kerning.length;u++){let{first:d,second:f,amount:p}=t.kerning[u];d/=l,f/=l,p/=l,this.chars[f]&&(this.chars[f].kerning[d]=p)}this.distanceFieldRange=a==null?void 0:a.distanceRange,this.distanceFieldType=((c=a==null?void 0:a.fieldType)==null?void 0:c.toLowerCase())??"none"}destroy(){for(const t in this.chars)this.chars[t].texture.destroy(),this.chars[t].texture=null;for(const t in this.pageTextures)this._ownsTextures&&this.pageTextures[t].destroy(!0),this.pageTextures[t]=null;this.chars=null,this.pageTextures=null}static install(t,e,i){let n;if(t instanceof Do)n=t;else{const o=NS(t);if(!o)throw new Error("Unrecognized data format for font.");n=o.parse(t)}e instanceof ct&&(e=[e]);const s=new mr(n,e,i);return mr.available[s.font]=s,s}static uninstall(t){const e=mr.available[t];if(!e)throw new Error(`No font found named '${t}'`);e.destroy(),delete mr.available[t]}static from(t,e,i){if(!t)throw new Error("[BitmapFont] Property `name` is required.");const{chars:n,padding:s,resolution:o,textureWidth:a,textureHeight:l,...h}=Object.assign({},mr.defaultOptions,i),c=US(n),u=e instanceof zr?e:new zr(e),d=a,f=new Do;f.info[0]={face:u.fontFamily,size:u.fontSize},f.common[0]={lineHeight:u.fontSize};let p=0,m=0,y,_,v,g=0;const b=[];for(let R=0;R<c.length;R++){y||(y=tt.ADAPTER.createCanvas(),y.width=a,y.height=l,_=y.getContext("2d"),v=new bt(y,{resolution:o,...h}),b.push(new ct(v)),f.page.push({id:b.length-1,file:""}));const C=c[R],I=Wr.measureText(C,u,!1,y),M=I.width,F=Math.ceil(I.height),U=Math.ceil((u.fontStyle==="italic"?2:1)*M);if(m>=l-F*o){if(m===0)throw new Error(`[BitmapFont] textureHeight ${l}px is too small (fontFamily: '${u.fontFamily}', fontSize: ${u.fontSize}px, char: '${C}')`);--R,y=null,_=null,v=null,m=0,p=0,g=0;continue}if(g=Math.max(F+I.fontProperties.descent,g),U*o+p>=d){if(p===0)throw new Error(`[BitmapFont] textureWidth ${a}px is too small (fontFamily: '${u.fontFamily}', fontSize: ${u.fontSize}px, char: '${C}')`);--R,m+=g*o,m=Math.ceil(m),p=0,g=0;continue}kS(y,_,I,p,m,o,u);const P=Oo(I.text);f.char.push({id:P,page:b.length-1,x:p/o,y:m/o,width:U,height:F,xoffset:0,yoffset:0,xadvance:M-(u.dropShadow?u.dropShadowDistance:0)-(u.stroke?u.strokeThickness:0)}),p+=(U+2*s)*o,p=Math.ceil(p)}if(!(i!=null&&i.skipKerning))for(let R=0,C=c.length;R<C;R++){const I=c[R];for(let M=0;M<C;M++){const F=c[M],U=_.measureText(I).width,P=_.measureText(F).width,T=_.measureText(I+F).width-(U+P);T&&f.kerning.push({first:Oo(I),second:Oo(F),amount:T})}}const S=new mr(f,b,!0);return mr.available[t]!==void 0&&mr.uninstall(t),mr.available[t]=S,S}};Yr.ALPHA=[["a","z"],["A","Z"]," "],Yr.NUMERIC=[["0","9"]],Yr.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],Yr.ASCII=[[" ","~"]],Yr.defaultOptions={resolution:1,textureWidth:512,textureHeight:512,padding:4,chars:Yr.ALPHANUMERIC},Yr.available={};let qr=Yr;var GS=`// Pixi texture info\r
1083
+ `;const Mo=new kt;class Em extends no{constructor(t){super(t),t.runners.contextChange.add(this),this.quad=new ip,this.state=ur.for2d()}contextChange(){const t=this.renderer,e={globals:t.globalUniforms};this.simpleShader=dr.from(wm,BS,e),this.shader=t.context.webGLVersion>1?dr.from(MS,RS,e):dr.from(wm,DS,e)}render(t){const e=this.renderer,i=this.quad;let n=i.vertices;n[0]=n[6]=t._width*-t.anchor.x,n[1]=n[3]=t._height*-t.anchor.y,n[2]=n[4]=t._width*(1-t.anchor.x),n[5]=n[7]=t._height*(1-t.anchor.y);const s=t.uvRespectAnchor?t.anchor.x:0,o=t.uvRespectAnchor?t.anchor.y:0;n=i.uvs,n[0]=n[6]=-s,n[1]=n[3]=-o,n[2]=n[4]=1-s,n[5]=n[7]=1-o,i.invalidate();const a=t._texture,l=a.baseTexture,h=l.alphaMode>0,c=t.tileTransform.localTransform,u=t.uvMatrix;let d=l.isPowerOfTwo&&a.frame.width===l.width&&a.frame.height===l.height;d&&(l._glTextures[e.CONTEXT_UID]?d=l.wrapMode!==Fr.CLAMP:l.wrapMode===Fr.CLAMP&&(l.wrapMode=Fr.REPEAT));const f=d?this.simpleShader:this.shader,p=a.width,m=a.height,y=t._width,_=t._height;Mo.set(c.a*p/y,c.b*p/_,c.c*m/y,c.d*m/_,c.tx/y,c.ty/_),Mo.invert(),d?Mo.prepend(u.mapCoord):(f.uniforms.uMapCoord=u.mapCoord.toArray(!0),f.uniforms.uClampFrame=u.uClampFrame,f.uniforms.uClampOffset=u.uClampOffset),f.uniforms.uTransform=Mo.toArray(!0),f.uniforms.uColor=Mt.shared.setValue(t.tint).premultiply(t.worldAlpha,h).toArray(f.uniforms.uColor),f.uniforms.translationMatrix=t.transform.worldTransform.toArray(!0),f.uniforms.uSampler=a,e.shader.bind(f),e.geometry.bind(i),this.state.blendMode=Rf(t.blendMode,h),e.state.set(this.state),e.geometry.draw(this.renderer.gl.TRIANGLES,6,0)}}Em.extension={name:"tilingSprite",type:Z.RendererPlugin},ht.add(Em);const Tm=class os{constructor(t,e,i){this.linkedSheets=[],(t instanceof bt||t instanceof ct)&&(t={texture:t,data:e,resolutionFilename:i});const{texture:n,data:s,resolutionFilename:o=null,cachePrefix:a=""}=t;this.cachePrefix=a,this._texture=n instanceof ct?n:null,this.baseTexture=n instanceof bt?n:this._texture.baseTexture,this.textures={},this.animations={},this.data=s;const l=this.baseTexture.resource;this.resolution=this._updateResolution(o||(l?l.url:null)),this._frames=this.data.frames,this._frameKeys=Object.keys(this._frames),this._batchIndex=0,this._callback=null}_updateResolution(t=null){const{scale:e}=this.data.meta;let i=wr(t,null);return i===null&&(i=typeof e=="number"?e:parseFloat(e??"1")),i!==1&&this.baseTexture.setResolution(i),i}parse(){return new Promise(t=>{this._callback=t,this._batchIndex=0,this._frameKeys.length<=os.BATCH_SIZE?(this._processFrames(0),this._processAnimations(),this._parseComplete()):this._nextBatch()})}_processFrames(t){let e=t;const i=os.BATCH_SIZE;for(;e-t<i&&e<this._frameKeys.length;){const n=this._frameKeys[e],s=this._frames[n],o=s.frame;if(o){let a=null,l=null;const h=s.trimmed!==!1&&s.sourceSize?s.sourceSize:s.frame,c=new wt(0,0,Math.floor(h.w)/this.resolution,Math.floor(h.h)/this.resolution);s.rotated?a=new wt(Math.floor(o.x)/this.resolution,Math.floor(o.y)/this.resolution,Math.floor(o.h)/this.resolution,Math.floor(o.w)/this.resolution):a=new wt(Math.floor(o.x)/this.resolution,Math.floor(o.y)/this.resolution,Math.floor(o.w)/this.resolution,Math.floor(o.h)/this.resolution),s.trimmed!==!1&&s.spriteSourceSize&&(l=new wt(Math.floor(s.spriteSourceSize.x)/this.resolution,Math.floor(s.spriteSourceSize.y)/this.resolution,Math.floor(o.w)/this.resolution,Math.floor(o.h)/this.resolution)),this.textures[n]=new ct(this.baseTexture,a,c,l,s.rotated?2:0,s.anchor,s.borders),ct.addToCache(this.textures[n],this.cachePrefix+n.toString())}e++}}_processAnimations(){const t=this.data.animations||{};for(const e in t){this.animations[e]=[];for(let i=0;i<t[e].length;i++){const n=t[e][i];this.animations[e].push(this.textures[n])}}}_parseComplete(){const t=this._callback;this._callback=null,this._batchIndex=0,t.call(this,this.textures)}_nextBatch(){this._processFrames(this._batchIndex*os.BATCH_SIZE),this._batchIndex++,setTimeout(()=>{this._batchIndex*os.BATCH_SIZE<this._frameKeys.length?this._nextBatch():(this._processAnimations(),this._parseComplete())},0)}destroy(t=!1){var e;for(const i in this.textures)this.textures[i].destroy();this._frames=null,this._frameKeys=null,this.data=null,this.textures=null,t&&((e=this._texture)==null||e.destroy(),this.baseTexture.destroy()),this._texture=null,this.baseTexture=null,this.linkedSheets=[]}};Tm.BATCH_SIZE=1e3;let Am=Tm;const OS=["jpg","png","jpeg","avif","webp","s3tc","s3tc_sRGB","etc","etc1","pvrtc","atc","astc","bptc"];function Sm(r,t,e){const i={};if(r.forEach(n=>{i[n]=t}),Object.keys(t.textures).forEach(n=>{i[`${t.cachePrefix}${n}`]=t.textures[n]}),!e){const n=ue.dirname(r[0]);t.linkedSheets.forEach((s,o)=>{Object.assign(i,Sm([`${n}/${t.data.meta.related_multi_packs[o]}`],s,!0))})}return i}const LS={extension:Z.Asset,cache:{test:r=>r instanceof Am,getCacheableAssets:(r,t)=>Sm(r,t,!1)},resolver:{test:r=>{const t=r.split("?")[0].split("."),e=t.pop(),i=t.pop();return e==="json"&&OS.includes(i)},parse:r=>{var e;const t=r.split(".");return{resolution:parseFloat(((e=tt.RETINA_PREFIX.exec(r))==null?void 0:e[1])??"1"),format:t[t.length-2],src:r}}},loader:{name:"spritesheetLoader",extension:{type:Z.LoadParser,priority:Ke.Normal},async testParse(r,t){return ue.extname(t.src).toLowerCase()===".json"&&!!r.frames},async parse(r,t,e){var c,u;const{texture:i,imageFilename:n,cachePrefix:s}=(t==null?void 0:t.data)??{};let o=ue.dirname(t.src);o&&o.lastIndexOf("/")!==o.length-1&&(o+="/");let a;if(i&&i.baseTexture)a=i;else{const d=ph(o+(n??r.meta.image),t.src);a=(await e.load([d]))[d]}const l=new Am({texture:a.baseTexture,data:r,resolutionFilename:t.src,cachePrefix:s});await l.parse();const h=(c=r==null?void 0:r.meta)==null?void 0:c.related_multi_packs;if(Array.isArray(h)){const d=[];for(const p of h){if(typeof p!="string")continue;let m=o+p;(u=t.data)!=null&&u.ignoreMultiPack||(m=ph(m,t.src),d.push(e.load({src:m,data:{ignoreMultiPack:!0}})))}const f=await Promise.all(d);l.linkedSheets=f,f.forEach(p=>{p.linkedSheets=[l].concat(l.linkedSheets.filter(m=>m!==p))})}return l},unload(r){r.destroy(!0)}}};ht.add(LS);class Do{constructor(){this.info=[],this.common=[],this.page=[],this.char=[],this.kerning=[],this.distanceField=[]}}class Bo{static test(t){return typeof t=="string"&&t.startsWith("info face=")}static parse(t){const e=t.match(/^[a-z]+\s+.+$/gm),i={info:[],common:[],page:[],char:[],chars:[],kerning:[],kernings:[],distanceField:[]};for(const s in e){const o=e[s].match(/^[a-z]+/gm)[0],a=e[s].match(/[a-zA-Z]+=([^\s"']+|"([^"]*)")/gm),l={};for(const h in a){const c=a[h].split("="),u=c[0],d=c[1].replace(/"/gm,""),f=parseFloat(d),p=isNaN(f)?d:f;l[u]=p}i[o].push(l)}const n=new Do;return i.info.forEach(s=>n.info.push({face:s.face,size:parseInt(s.size,10)})),i.common.forEach(s=>n.common.push({lineHeight:parseInt(s.lineHeight,10)})),i.page.forEach(s=>n.page.push({id:parseInt(s.id,10),file:s.file})),i.char.forEach(s=>n.char.push({id:parseInt(s.id,10),page:parseInt(s.page,10),x:parseInt(s.x,10),y:parseInt(s.y,10),width:parseInt(s.width,10),height:parseInt(s.height,10),xoffset:parseInt(s.xoffset,10),yoffset:parseInt(s.yoffset,10),xadvance:parseInt(s.xadvance,10)})),i.kerning.forEach(s=>n.kerning.push({first:parseInt(s.first,10),second:parseInt(s.second,10),amount:parseInt(s.amount,10)})),i.distanceField.forEach(s=>n.distanceField.push({distanceRange:parseInt(s.distanceRange,10),fieldType:s.fieldType})),n}}class Rh{static test(t){const e=t;return typeof t!="string"&&"getElementsByTagName"in t&&e.getElementsByTagName("page").length&&e.getElementsByTagName("info")[0].getAttribute("face")!==null}static parse(t){const e=new Do,i=t.getElementsByTagName("info"),n=t.getElementsByTagName("common"),s=t.getElementsByTagName("page"),o=t.getElementsByTagName("char"),a=t.getElementsByTagName("kerning"),l=t.getElementsByTagName("distanceField");for(let h=0;h<i.length;h++)e.info.push({face:i[h].getAttribute("face"),size:parseInt(i[h].getAttribute("size"),10)});for(let h=0;h<n.length;h++)e.common.push({lineHeight:parseInt(n[h].getAttribute("lineHeight"),10)});for(let h=0;h<s.length;h++)e.page.push({id:parseInt(s[h].getAttribute("id"),10)||0,file:s[h].getAttribute("file")});for(let h=0;h<o.length;h++){const c=o[h];e.char.push({id:parseInt(c.getAttribute("id"),10),page:parseInt(c.getAttribute("page"),10)||0,x:parseInt(c.getAttribute("x"),10),y:parseInt(c.getAttribute("y"),10),width:parseInt(c.getAttribute("width"),10),height:parseInt(c.getAttribute("height"),10),xoffset:parseInt(c.getAttribute("xoffset"),10),yoffset:parseInt(c.getAttribute("yoffset"),10),xadvance:parseInt(c.getAttribute("xadvance"),10)})}for(let h=0;h<a.length;h++)e.kerning.push({first:parseInt(a[h].getAttribute("first"),10),second:parseInt(a[h].getAttribute("second"),10),amount:parseInt(a[h].getAttribute("amount"),10)});for(let h=0;h<l.length;h++)e.distanceField.push({fieldType:l[h].getAttribute("fieldType"),distanceRange:parseInt(l[h].getAttribute("distanceRange"),10)});return e}}class Mh{static test(t){return typeof t=="string"&&t.includes("<font>")?Rh.test(tt.ADAPTER.parseXML(t)):!1}static parse(t){return Rh.parse(tt.ADAPTER.parseXML(t))}}const Dh=[Bo,Rh,Mh];function NS(r){for(let t=0;t<Dh.length;t++)if(Dh[t].test(r))return Dh[t];return null}function FS(r,t,e,i,n,s){const o=e.fill;if(Array.isArray(o)){if(o.length===1)return o[0]}else return o;let a;const l=e.dropShadow?e.dropShadowDistance:0,h=e.padding||0,c=r.width/i-l-h*2,u=r.height/i-l-h*2,d=o.slice(),f=e.fillGradientStops.slice();if(!f.length){const p=d.length+1;for(let m=1;m<p;++m)f.push(m/p)}if(d.unshift(o[0]),f.unshift(0),d.push(o[o.length-1]),f.push(1),e.fillGradientType===Po.LINEAR_VERTICAL){a=t.createLinearGradient(c/2,h,c/2,u+h);let p=0;const m=(s.fontProperties.fontSize+e.strokeThickness)/u;for(let y=0;y<n.length;y++){const _=s.lineHeight*y;for(let v=0;v<d.length;v++){let g=0;typeof f[v]=="number"?g=f[v]:g=v/d.length;const b=_/u+g*m;let S=Math.max(p,b);S=Math.min(S,1),a.addColorStop(S,d[v]),p=S}}}else{a=t.createLinearGradient(h,u/2,c+h,u/2);const p=d.length+1;let m=1;for(let y=0;y<d.length;y++){let _;typeof f[y]=="number"?_=f[y]:_=m/p,a.addColorStop(_,d[y]),m++}}return a}function kS(r,t,e,i,n,s,o){const a=e.text,l=e.fontProperties;t.translate(i,n),t.scale(s,s);const h=o.strokeThickness/2,c=-(o.strokeThickness/2);if(t.font=o.toFontString(),t.lineWidth=o.strokeThickness,t.textBaseline=o.textBaseline,t.lineJoin=o.lineJoin,t.miterLimit=o.miterLimit,t.fillStyle=FS(r,t,o,s,[a],e),t.strokeStyle=o.stroke,o.dropShadow){const u=o.dropShadowColor,d=o.dropShadowBlur*s,f=o.dropShadowDistance*s;t.shadowColor=Mt.shared.setValue(u).setAlpha(o.dropShadowAlpha).toRgbaString(),t.shadowBlur=d,t.shadowOffsetX=Math.cos(o.dropShadowAngle)*f,t.shadowOffsetY=Math.sin(o.dropShadowAngle)*f}else t.shadowColor="black",t.shadowBlur=0,t.shadowOffsetX=0,t.shadowOffsetY=0;o.stroke&&o.strokeThickness&&t.strokeText(a,h,c+e.lineHeight-l.descent),o.fill&&t.fillText(a,h,c+e.lineHeight-l.descent),t.setTransform(1,0,0,1,0,0),t.fillStyle="rgba(0, 0, 0, 0)"}function Oo(r){return r.codePointAt?r.codePointAt(0):r.charCodeAt(0)}function Cm(r){return Array.from?Array.from(r):r.split("")}function US(r){typeof r=="string"&&(r=[r]);const t=[];for(let e=0,i=r.length;e<i;e++){const n=r[e];if(Array.isArray(n)){if(n.length!==2)throw new Error(`[BitmapFont]: Invalid character range length, expecting 2 got ${n.length}.`);const s=n[0].charCodeAt(0),o=n[1].charCodeAt(0);if(o<s)throw new Error("[BitmapFont]: Invalid character range.");for(let a=s,l=o;a<=l;a++)t.push(String.fromCharCode(a))}else t.push(...Cm(n))}if(t.length===0)throw new Error("[BitmapFont]: Empty set when resolving characters.");return t}const Yr=class mr{constructor(t,e,i){var c;const[n]=t.info,[s]=t.common,[o]=t.page,[a]=t.distanceField,l=wr(o.file),h={};this._ownsTextures=i,this.font=n.face,this.size=n.size,this.lineHeight=s.lineHeight/l,this.chars={},this.pageTextures=h;for(let u=0;u<t.page.length;u++){const{id:d,file:f}=t.page[u];h[d]=e instanceof Array?e[u]:e[f],a!=null&&a.fieldType&&a.fieldType!=="none"&&(h[d].baseTexture.alphaMode=Re.NO_PREMULTIPLIED_ALPHA,h[d].baseTexture.mipmap=ir.OFF)}for(let u=0;u<t.char.length;u++){const{id:d,page:f}=t.char[u];let{x:p,y:m,width:y,height:_,xoffset:v,yoffset:g,xadvance:b}=t.char[u];p/=l,m/=l,y/=l,_/=l,v/=l,g/=l,b/=l;const S=new wt(p+h[f].frame.x/l,m+h[f].frame.y/l,y,_);this.chars[d]={xOffset:v,yOffset:g,xAdvance:b,kerning:{},texture:new ct(h[f].baseTexture,S),page:f}}for(let u=0;u<t.kerning.length;u++){let{first:d,second:f,amount:p}=t.kerning[u];d/=l,f/=l,p/=l,this.chars[f]&&(this.chars[f].kerning[d]=p)}this.distanceFieldRange=a==null?void 0:a.distanceRange,this.distanceFieldType=((c=a==null?void 0:a.fieldType)==null?void 0:c.toLowerCase())??"none"}destroy(){for(const t in this.chars)this.chars[t].texture.destroy(),this.chars[t].texture=null;for(const t in this.pageTextures)this._ownsTextures&&this.pageTextures[t].destroy(!0),this.pageTextures[t]=null;this.chars=null,this.pageTextures=null}static install(t,e,i){let n;if(t instanceof Do)n=t;else{const o=NS(t);if(!o)throw new Error("Unrecognized data format for font.");n=o.parse(t)}e instanceof ct&&(e=[e]);const s=new mr(n,e,i);return mr.available[s.font]=s,s}static uninstall(t){const e=mr.available[t];if(!e)throw new Error(`No font found named '${t}'`);e.destroy(),delete mr.available[t]}static from(t,e,i){if(!t)throw new Error("[BitmapFont] Property `name` is required.");const{chars:n,padding:s,resolution:o,textureWidth:a,textureHeight:l,...h}=Object.assign({},mr.defaultOptions,i),c=US(n),u=e instanceof zr?e:new zr(e),d=a,f=new Do;f.info[0]={face:u.fontFamily,size:u.fontSize},f.common[0]={lineHeight:u.fontSize};let p=0,m=0,y,_,v,g=0;const b=[];for(let R=0;R<c.length;R++){y||(y=tt.ADAPTER.createCanvas(),y.width=a,y.height=l,_=y.getContext("2d"),v=new bt(y,{resolution:o,...h}),b.push(new ct(v)),f.page.push({id:b.length-1,file:""}));const C=c[R],I=Wr.measureText(C,u,!1,y),M=I.width,F=Math.ceil(I.height),U=Math.ceil((u.fontStyle==="italic"?2:1)*M);if(m>=l-F*o){if(m===0)throw new Error(`[BitmapFont] textureHeight ${l}px is too small (fontFamily: '${u.fontFamily}', fontSize: ${u.fontSize}px, char: '${C}')`);--R,y=null,_=null,v=null,m=0,p=0,g=0;continue}if(g=Math.max(F+I.fontProperties.descent,g),U*o+p>=d){if(p===0)throw new Error(`[BitmapFont] textureWidth ${a}px is too small (fontFamily: '${u.fontFamily}', fontSize: ${u.fontSize}px, char: '${C}')`);--R,m+=g*o,m=Math.ceil(m),p=0,g=0;continue}kS(y,_,I,p,m,o,u);const P=Oo(I.text);f.char.push({id:P,page:b.length-1,x:p/o,y:m/o,width:U,height:F,xoffset:0,yoffset:0,xadvance:M-(u.dropShadow?u.dropShadowDistance:0)-(u.stroke?u.strokeThickness:0)}),p+=(U+2*s)*o,p=Math.ceil(p)}if(!(i!=null&&i.skipKerning))for(let R=0,C=c.length;R<C;R++){const I=c[R];for(let M=0;M<C;M++){const F=c[M],U=_.measureText(I).width,P=_.measureText(F).width,E=_.measureText(I+F).width-(U+P);E&&f.kerning.push({first:Oo(I),second:Oo(F),amount:E})}}const S=new mr(f,b,!0);return mr.available[t]!==void 0&&mr.uninstall(t),mr.available[t]=S,S}};Yr.ALPHA=[["a","z"],["A","Z"]," "],Yr.NUMERIC=[["0","9"]],Yr.ALPHANUMERIC=[["a","z"],["A","Z"],["0","9"]," "],Yr.ASCII=[[" ","~"]],Yr.defaultOptions={resolution:1,textureWidth:512,textureHeight:512,padding:4,chars:Yr.ALPHANUMERIC},Yr.available={};let qr=Yr;var GS=`// Pixi texture info\r
1084
1084
  varying vec2 vTextureCoord;\r
1085
1085
  uniform sampler2D uSampler;\r
1086
1086
  \r
@@ -1135,14 +1135,14 @@ void main(void)\r
1135
1135
  vTextureCoord = (uTextureMatrix * vec3(aTextureCoord, 1.0)).xy;\r
1136
1136
  }\r
1137
1137
  `;const Im=[],Pm=[],Rm=[],HS=class ig extends ze{constructor(t,e={}){super();const{align:i,tint:n,maxWidth:s,letterSpacing:o,fontName:a,fontSize:l}=Object.assign({},ig.styleDefaults,e);if(!qr.available[a])throw new Error(`Missing BitmapFont "${a}"`);this._activePagesMeshData=[],this._textWidth=0,this._textHeight=0,this._align=i,this._tintColor=new Mt(n),this._font=void 0,this._fontName=a,this._fontSize=l,this.text=t,this._maxWidth=s,this._maxLineHeight=0,this._letterSpacing=o,this._anchor=new Er(()=>{this.dirty=!0},this,0,0),this._roundPixels=tt.ROUND_PIXELS,this.dirty=!0,this._resolution=tt.RESOLUTION,this._autoResolution=!0,this._textureCache={}}updateText(){var U;const t=qr.available[this._fontName],e=this.fontSize,i=e/t.size,n=new It,s=[],o=[],a=[],l=this._text.replace(/(?:\r\n|\r)/g,`
1138
- `)||" ",h=Cm(l),c=this._maxWidth*t.size/e,u=t.distanceFieldType==="none"?Im:Pm;let d=null,f=0,p=0,m=0,y=-1,_=0,v=0,g=0,b=0;for(let P=0;P<h.length;P++){const T=h[P],E=Oo(T);if(/(?:\s)/.test(T)&&(y=P,_=f,b++),T==="\r"||T===`
1139
- `){o.push(f),a.push(-1),p=Math.max(p,f),++m,++v,n.x=0,n.y+=t.lineHeight,d=null,b=0;continue}const A=t.chars[E];if(!A)continue;d&&A.kerning[d]&&(n.x+=A.kerning[d]);const L=Rm.pop()||{texture:ct.EMPTY,line:0,charCode:0,prevSpaces:0,position:new It};L.texture=A.texture,L.line=m,L.charCode=E,L.position.x=Math.round(n.x+A.xOffset+this._letterSpacing/2),L.position.y=Math.round(n.y+A.yOffset),L.prevSpaces=b,s.push(L),f=L.position.x+Math.max(A.xAdvance-A.xOffset,A.texture.orig.width),n.x+=A.xAdvance+this._letterSpacing,g=Math.max(g,A.yOffset+A.texture.height),d=E,y!==-1&&c>0&&n.x>c&&(++v,Ji(s,1+y-v,1+P-y),P=y,y=-1,o.push(_),a.push(s.length>0?s[s.length-1].prevSpaces:0),p=Math.max(p,_),m++,n.x=0,n.y+=t.lineHeight,d=null,b=0)}const S=h[h.length-1];S!=="\r"&&S!==`
1140
- `&&(/(?:\s)/.test(S)&&(f=_),o.push(f),p=Math.max(p,f),a.push(-1));const R=[];for(let P=0;P<=m;P++){let T=0;this._align==="right"?T=p-o[P]:this._align==="center"?T=(p-o[P])/2:this._align==="justify"&&(T=a[P]<0?0:(p-o[P])/a[P]),R.push(T)}const C=s.length,I={},M=[],F=this._activePagesMeshData;u.push(...F);for(let P=0;P<C;P++){const T=s[P].texture,E=T.baseTexture.uid;if(!I[E]){let A=u.pop();if(!A){const D=new dS;let N,$;t.distanceFieldType==="none"?(N=new fm(ct.EMPTY),$=vt.NORMAL):(N=new fm(ct.EMPTY,{program:Tr.from($S,GS),uniforms:{uFWidth:0}}),$=vt.NORMAL_NPM);const O=new dm(D,N);O.blendMode=$,A={index:0,indexCount:0,vertexCount:0,uvsCount:0,total:0,mesh:O,vertices:null,uvs:null,indices:null}}A.index=0,A.indexCount=0,A.vertexCount=0,A.uvsCount=0,A.total=0;const{_textureCache:L}=this;L[E]=L[E]||new ct(T.baseTexture),A.mesh.texture=L[E],A.mesh.tint=this._tintColor.value,M.push(A),I[E]=A}I[E].total++}for(let P=0;P<F.length;P++)M.includes(F[P])||this.removeChild(F[P].mesh);for(let P=0;P<M.length;P++)M[P].mesh.parent!==this&&this.addChild(M[P].mesh);this._activePagesMeshData=M;for(const P in I){const T=I[P],E=T.total;if(!(((U=T.indices)==null?void 0:U.length)>6*E)||T.vertices.length<dm.BATCHABLE_SIZE*2)T.vertices=new Float32Array(4*2*E),T.uvs=new Float32Array(4*2*E),T.indices=new Uint16Array(6*E);else{const A=T.total,L=T.vertices;for(let D=A*4*2;D<L.length;D++)L[D]=0}T.mesh.size=6*E}for(let P=0;P<C;P++){const T=s[P];let E=T.position.x+R[T.line]*(this._align==="justify"?T.prevSpaces:1);this._roundPixels&&(E=Math.round(E));const A=E*i,L=T.position.y*i,D=T.texture,N=I[D.baseTexture.uid],$=D.frame,O=D._uvs,B=N.index++;N.indices[B*6+0]=0+B*4,N.indices[B*6+1]=1+B*4,N.indices[B*6+2]=2+B*4,N.indices[B*6+3]=0+B*4,N.indices[B*6+4]=2+B*4,N.indices[B*6+5]=3+B*4,N.vertices[B*8+0]=A,N.vertices[B*8+1]=L,N.vertices[B*8+2]=A+$.width*i,N.vertices[B*8+3]=L,N.vertices[B*8+4]=A+$.width*i,N.vertices[B*8+5]=L+$.height*i,N.vertices[B*8+6]=A,N.vertices[B*8+7]=L+$.height*i,N.uvs[B*8+0]=O.x0,N.uvs[B*8+1]=O.y0,N.uvs[B*8+2]=O.x1,N.uvs[B*8+3]=O.y1,N.uvs[B*8+4]=O.x2,N.uvs[B*8+5]=O.y2,N.uvs[B*8+6]=O.x3,N.uvs[B*8+7]=O.y3}this._textWidth=p*i,this._textHeight=(n.y+t.lineHeight)*i;for(const P in I){const T=I[P];if(this.anchor.x!==0||this.anchor.y!==0){let D=0;const N=this._textWidth*this.anchor.x,$=this._textHeight*this.anchor.y;for(let O=0;O<T.total;O++)T.vertices[D++]-=N,T.vertices[D++]-=$,T.vertices[D++]-=N,T.vertices[D++]-=$,T.vertices[D++]-=N,T.vertices[D++]-=$,T.vertices[D++]-=N,T.vertices[D++]-=$}this._maxLineHeight=g*i;const E=T.mesh.geometry.getBuffer("aVertexPosition"),A=T.mesh.geometry.getBuffer("aTextureCoord"),L=T.mesh.geometry.getIndex();E.data=T.vertices,A.data=T.uvs,L.data=T.indices,E.update(),A.update(),L.update()}for(let P=0;P<s.length;P++)Rm.push(s[P]);this._font=t,this.dirty=!1}updateTransform(){this.validate(),this.containerUpdateTransform()}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0);const{distanceFieldRange:e,distanceFieldType:i,size:n}=qr.available[this._fontName];if(i!=="none"){const{a:s,b:o,c:a,d:l}=this.worldTransform,h=Math.sqrt(s*s+o*o),c=Math.sqrt(a*a+l*l),u=(Math.abs(h)+Math.abs(c))/2,d=this.fontSize/n,f=t._view.resolution;for(const p of this._activePagesMeshData)p.mesh.shader.uniforms.uFWidth=u*e*d*f}super._render(t)}getLocalBounds(){return this.validate(),super.getLocalBounds()}validate(){const t=qr.available[this._fontName];if(!t)throw new Error(`Missing BitmapFont "${this._fontName}"`);this._font!==t&&(this.dirty=!0),this.dirty&&this.updateText()}get tint(){return this._tintColor.value}set tint(t){if(this.tint!==t){this._tintColor.setValue(t);for(let e=0;e<this._activePagesMeshData.length;e++)this._activePagesMeshData[e].mesh.tint=t}}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.dirty=!0)}get fontName(){return this._fontName}set fontName(t){if(!qr.available[t])throw new Error(`Missing BitmapFont "${t}"`);this._fontName!==t&&(this._fontName=t,this.dirty=!0)}get fontSize(){return this._fontSize??qr.available[this._fontName].size}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.dirty=!0)}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get maxWidth(){return this._maxWidth}set maxWidth(t){this._maxWidth!==t&&(this._maxWidth=t,this.dirty=!0)}get maxLineHeight(){return this.validate(),this._maxLineHeight}get textWidth(){return this.validate(),this._textWidth}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.dirty=!0)}get roundPixels(){return this._roundPixels}set roundPixels(t){t!==this._roundPixels&&(this._roundPixels=t,this.dirty=!0)}get textHeight(){return this.validate(),this._textHeight}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}destroy(t){const{_textureCache:e}=this,i=qr.available[this._fontName].distanceFieldType==="none"?Im:Pm;i.push(...this._activePagesMeshData);for(const n of this._activePagesMeshData)this.removeChild(n.mesh);this._activePagesMeshData=[],i.filter(n=>e[n.mesh.texture.baseTexture.uid]).forEach(n=>{n.mesh.texture=ct.EMPTY});for(const n in e)e[n].destroy(),delete e[n];this._font=null,this._tintColor=null,this._textureCache=null,super.destroy(t)}};HS.styleDefaults={align:"left",tint:16777215,maxWidth:0,letterSpacing:0};const XS=[".xml",".fnt"],VS={extension:{type:Z.LoadParser,priority:Ke.Normal},name:"loadBitmapFont",test(r){return XS.includes(ue.extname(r).toLowerCase())},async testParse(r){return Bo.test(r)||Mh.test(r)},async parse(r,t,e){const i=Bo.test(r)?Bo.parse(r):Mh.parse(r),{src:n}=t,{page:s}=i,o=[];for(let h=0;h<s.length;++h){const c=s[h].file;let u=ue.join(ue.dirname(n),c);u=ph(u,n),o.push(u)}const a=await e.load(o),l=o.map(h=>a[h]);return qr.install(i,l,!0)},async load(r,t){return(await tt.ADAPTER.fetch(r)).text()},unload(r){r.destroy()}};ht.add(VS);const Bh=class gn extends zr{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new gn(Object.keys(gn.defaultOptions).reduce((e,i)=>({...e,[i]:t[i]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete gn.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:i}=gn;if(i[t]){const n=i[t];return this._fonts.push(n),n.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return tt.ADAPTER.fetch(t).then(n=>n.blob()).then(async n=>new Promise((s,o)=>{const a=URL.createObjectURL(n),l=new FileReader;l.onload=()=>s([a,l.result]),l.onerror=o,l.readAsDataURL(n)})).then(async([n,s])=>{const o=Object.assign({family:ue.basename(t,ue.extname(t)),weight:"normal",style:"normal",display:"auto",src:n,dataSrc:s,refs:1,originalUrl:t,fontFace:null},e);i[t]=o,this._fonts.push(o),this.styleID++;const a=new FontFace(o.family,`url(${o.src})`,{weight:o.weight,style:o.style,display:o.display});o.fontFace=a,await a.load(),document.fonts.add(a),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(i=>!this._overrides.includes(i));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(i=>this._overrides.includes(i));e.length>0&&(this._overrides=this._overrides.filter(i=>!e.includes(i)),this.styleID++)}toCSS(t){return[`transform: scale(${t})`,"transform-origin: top left","display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing}px`,`text-align: ${this.align}`,`padding: ${this.padding}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS()]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t}
1138
+ `)||" ",h=Cm(l),c=this._maxWidth*t.size/e,u=t.distanceFieldType==="none"?Im:Pm;let d=null,f=0,p=0,m=0,y=-1,_=0,v=0,g=0,b=0;for(let P=0;P<h.length;P++){const E=h[P],T=Oo(E);if(/(?:\s)/.test(E)&&(y=P,_=f,b++),E==="\r"||E===`
1139
+ `){o.push(f),a.push(-1),p=Math.max(p,f),++m,++v,n.x=0,n.y+=t.lineHeight,d=null,b=0;continue}const A=t.chars[T];if(!A)continue;d&&A.kerning[d]&&(n.x+=A.kerning[d]);const O=Rm.pop()||{texture:ct.EMPTY,line:0,charCode:0,prevSpaces:0,position:new It};O.texture=A.texture,O.line=m,O.charCode=T,O.position.x=Math.round(n.x+A.xOffset+this._letterSpacing/2),O.position.y=Math.round(n.y+A.yOffset),O.prevSpaces=b,s.push(O),f=O.position.x+Math.max(A.xAdvance-A.xOffset,A.texture.orig.width),n.x+=A.xAdvance+this._letterSpacing,g=Math.max(g,A.yOffset+A.texture.height),d=T,y!==-1&&c>0&&n.x>c&&(++v,Ji(s,1+y-v,1+P-y),P=y,y=-1,o.push(_),a.push(s.length>0?s[s.length-1].prevSpaces:0),p=Math.max(p,_),m++,n.x=0,n.y+=t.lineHeight,d=null,b=0)}const S=h[h.length-1];S!=="\r"&&S!==`
1140
+ `&&(/(?:\s)/.test(S)&&(f=_),o.push(f),p=Math.max(p,f),a.push(-1));const R=[];for(let P=0;P<=m;P++){let E=0;this._align==="right"?E=p-o[P]:this._align==="center"?E=(p-o[P])/2:this._align==="justify"&&(E=a[P]<0?0:(p-o[P])/a[P]),R.push(E)}const C=s.length,I={},M=[],F=this._activePagesMeshData;u.push(...F);for(let P=0;P<C;P++){const E=s[P].texture,T=E.baseTexture.uid;if(!I[T]){let A=u.pop();if(!A){const D=new dS;let L,$;t.distanceFieldType==="none"?(L=new fm(ct.EMPTY),$=vt.NORMAL):(L=new fm(ct.EMPTY,{program:Tr.from($S,GS),uniforms:{uFWidth:0}}),$=vt.NORMAL_NPM);const B=new dm(D,L);B.blendMode=$,A={index:0,indexCount:0,vertexCount:0,uvsCount:0,total:0,mesh:B,vertices:null,uvs:null,indices:null}}A.index=0,A.indexCount=0,A.vertexCount=0,A.uvsCount=0,A.total=0;const{_textureCache:O}=this;O[T]=O[T]||new ct(E.baseTexture),A.mesh.texture=O[T],A.mesh.tint=this._tintColor.value,M.push(A),I[T]=A}I[T].total++}for(let P=0;P<F.length;P++)M.includes(F[P])||this.removeChild(F[P].mesh);for(let P=0;P<M.length;P++)M[P].mesh.parent!==this&&this.addChild(M[P].mesh);this._activePagesMeshData=M;for(const P in I){const E=I[P],T=E.total;if(!(((U=E.indices)==null?void 0:U.length)>6*T)||E.vertices.length<dm.BATCHABLE_SIZE*2)E.vertices=new Float32Array(4*2*T),E.uvs=new Float32Array(4*2*T),E.indices=new Uint16Array(6*T);else{const A=E.total,O=E.vertices;for(let D=A*4*2;D<O.length;D++)O[D]=0}E.mesh.size=6*T}for(let P=0;P<C;P++){const E=s[P];let T=E.position.x+R[E.line]*(this._align==="justify"?E.prevSpaces:1);this._roundPixels&&(T=Math.round(T));const A=T*i,O=E.position.y*i,D=E.texture,L=I[D.baseTexture.uid],$=D.frame,B=D._uvs,N=L.index++;L.indices[N*6+0]=0+N*4,L.indices[N*6+1]=1+N*4,L.indices[N*6+2]=2+N*4,L.indices[N*6+3]=0+N*4,L.indices[N*6+4]=2+N*4,L.indices[N*6+5]=3+N*4,L.vertices[N*8+0]=A,L.vertices[N*8+1]=O,L.vertices[N*8+2]=A+$.width*i,L.vertices[N*8+3]=O,L.vertices[N*8+4]=A+$.width*i,L.vertices[N*8+5]=O+$.height*i,L.vertices[N*8+6]=A,L.vertices[N*8+7]=O+$.height*i,L.uvs[N*8+0]=B.x0,L.uvs[N*8+1]=B.y0,L.uvs[N*8+2]=B.x1,L.uvs[N*8+3]=B.y1,L.uvs[N*8+4]=B.x2,L.uvs[N*8+5]=B.y2,L.uvs[N*8+6]=B.x3,L.uvs[N*8+7]=B.y3}this._textWidth=p*i,this._textHeight=(n.y+t.lineHeight)*i;for(const P in I){const E=I[P];if(this.anchor.x!==0||this.anchor.y!==0){let D=0;const L=this._textWidth*this.anchor.x,$=this._textHeight*this.anchor.y;for(let B=0;B<E.total;B++)E.vertices[D++]-=L,E.vertices[D++]-=$,E.vertices[D++]-=L,E.vertices[D++]-=$,E.vertices[D++]-=L,E.vertices[D++]-=$,E.vertices[D++]-=L,E.vertices[D++]-=$}this._maxLineHeight=g*i;const T=E.mesh.geometry.getBuffer("aVertexPosition"),A=E.mesh.geometry.getBuffer("aTextureCoord"),O=E.mesh.geometry.getIndex();T.data=E.vertices,A.data=E.uvs,O.data=E.indices,T.update(),A.update(),O.update()}for(let P=0;P<s.length;P++)Rm.push(s[P]);this._font=t,this.dirty=!1}updateTransform(){this.validate(),this.containerUpdateTransform()}_render(t){this._autoResolution&&this._resolution!==t.resolution&&(this._resolution=t.resolution,this.dirty=!0);const{distanceFieldRange:e,distanceFieldType:i,size:n}=qr.available[this._fontName];if(i!=="none"){const{a:s,b:o,c:a,d:l}=this.worldTransform,h=Math.sqrt(s*s+o*o),c=Math.sqrt(a*a+l*l),u=(Math.abs(h)+Math.abs(c))/2,d=this.fontSize/n,f=t._view.resolution;for(const p of this._activePagesMeshData)p.mesh.shader.uniforms.uFWidth=u*e*d*f}super._render(t)}getLocalBounds(){return this.validate(),super.getLocalBounds()}validate(){const t=qr.available[this._fontName];if(!t)throw new Error(`Missing BitmapFont "${this._fontName}"`);this._font!==t&&(this.dirty=!0),this.dirty&&this.updateText()}get tint(){return this._tintColor.value}set tint(t){if(this.tint!==t){this._tintColor.setValue(t);for(let e=0;e<this._activePagesMeshData.length;e++)this._activePagesMeshData[e].mesh.tint=t}}get align(){return this._align}set align(t){this._align!==t&&(this._align=t,this.dirty=!0)}get fontName(){return this._fontName}set fontName(t){if(!qr.available[t])throw new Error(`Missing BitmapFont "${t}"`);this._fontName!==t&&(this._fontName=t,this.dirty=!0)}get fontSize(){return this._fontSize??qr.available[this._fontName].size}set fontSize(t){this._fontSize!==t&&(this._fontSize=t,this.dirty=!0)}get anchor(){return this._anchor}set anchor(t){typeof t=="number"?this._anchor.set(t):this._anchor.copyFrom(t)}get text(){return this._text}set text(t){t=String(t??""),this._text!==t&&(this._text=t,this.dirty=!0)}get maxWidth(){return this._maxWidth}set maxWidth(t){this._maxWidth!==t&&(this._maxWidth=t,this.dirty=!0)}get maxLineHeight(){return this.validate(),this._maxLineHeight}get textWidth(){return this.validate(),this._textWidth}get letterSpacing(){return this._letterSpacing}set letterSpacing(t){this._letterSpacing!==t&&(this._letterSpacing=t,this.dirty=!0)}get roundPixels(){return this._roundPixels}set roundPixels(t){t!==this._roundPixels&&(this._roundPixels=t,this.dirty=!0)}get textHeight(){return this.validate(),this._textHeight}get resolution(){return this._resolution}set resolution(t){this._autoResolution=!1,this._resolution!==t&&(this._resolution=t,this.dirty=!0)}destroy(t){const{_textureCache:e}=this,i=qr.available[this._fontName].distanceFieldType==="none"?Im:Pm;i.push(...this._activePagesMeshData);for(const n of this._activePagesMeshData)this.removeChild(n.mesh);this._activePagesMeshData=[],i.filter(n=>e[n.mesh.texture.baseTexture.uid]).forEach(n=>{n.mesh.texture=ct.EMPTY});for(const n in e)e[n].destroy(),delete e[n];this._font=null,this._tintColor=null,this._textureCache=null,super.destroy(t)}};HS.styleDefaults={align:"left",tint:16777215,maxWidth:0,letterSpacing:0};const XS=[".xml",".fnt"],VS={extension:{type:Z.LoadParser,priority:Ke.Normal},name:"loadBitmapFont",test(r){return XS.includes(ue.extname(r).toLowerCase())},async testParse(r){return Bo.test(r)||Mh.test(r)},async parse(r,t,e){const i=Bo.test(r)?Bo.parse(r):Mh.parse(r),{src:n}=t,{page:s}=i,o=[];for(let h=0;h<s.length;++h){const c=s[h].file;let u=ue.join(ue.dirname(n),c);u=ph(u,n),o.push(u)}const a=await e.load(o),l=o.map(h=>a[h]);return qr.install(i,l,!0)},async load(r,t){return(await tt.ADAPTER.fetch(r)).text()},unload(r){r.destroy()}};ht.add(VS);const Bh=class gn extends zr{constructor(){super(...arguments),this._fonts=[],this._overrides=[],this._stylesheet="",this.fontsDirty=!1}static from(t){return new gn(Object.keys(gn.defaultOptions).reduce((e,i)=>({...e,[i]:t[i]}),{}))}cleanFonts(){this._fonts.length>0&&(this._fonts.forEach(t=>{URL.revokeObjectURL(t.src),t.refs--,t.refs===0&&(t.fontFace&&document.fonts.delete(t.fontFace),delete gn.availableFonts[t.originalUrl])}),this.fontFamily="Arial",this._fonts.length=0,this.styleID++,this.fontsDirty=!0)}loadFont(t,e={}){const{availableFonts:i}=gn;if(i[t]){const n=i[t];return this._fonts.push(n),n.refs++,this.styleID++,this.fontsDirty=!0,Promise.resolve()}return tt.ADAPTER.fetch(t).then(n=>n.blob()).then(async n=>new Promise((s,o)=>{const a=URL.createObjectURL(n),l=new FileReader;l.onload=()=>s([a,l.result]),l.onerror=o,l.readAsDataURL(n)})).then(async([n,s])=>{const o=Object.assign({family:ue.basename(t,ue.extname(t)),weight:"normal",style:"normal",display:"auto",src:n,dataSrc:s,refs:1,originalUrl:t,fontFace:null},e);i[t]=o,this._fonts.push(o),this.styleID++;const a=new FontFace(o.family,`url(${o.src})`,{weight:o.weight,style:o.style,display:o.display});o.fontFace=a,await a.load(),document.fonts.add(a),await document.fonts.ready,this.styleID++,this.fontsDirty=!0})}addOverride(...t){const e=t.filter(i=>!this._overrides.includes(i));e.length>0&&(this._overrides.push(...e),this.styleID++)}removeOverride(...t){const e=t.filter(i=>this._overrides.includes(i));e.length>0&&(this._overrides=this._overrides.filter(i=>!e.includes(i)),this.styleID++)}toCSS(t){return[`transform: scale(${t})`,"transform-origin: top left","display: inline-block",`color: ${this.normalizeColor(this.fill)}`,`font-size: ${this.fontSize}px`,`font-family: ${this.fontFamily}`,`font-weight: ${this.fontWeight}`,`font-style: ${this.fontStyle}`,`font-variant: ${this.fontVariant}`,`letter-spacing: ${this.letterSpacing}px`,`text-align: ${this.align}`,`padding: ${this.padding}px`,`white-space: ${this.whiteSpace}`,...this.lineHeight?[`line-height: ${this.lineHeight}px`]:[],...this.wordWrap?[`word-wrap: ${this.breakWords?"break-all":"break-word"}`,`max-width: ${this.wordWrapWidth}px`]:[],...this.strokeThickness?[`-webkit-text-stroke-width: ${this.strokeThickness}px`,`-webkit-text-stroke-color: ${this.normalizeColor(this.stroke)}`,`text-stroke-width: ${this.strokeThickness}px`,`text-stroke-color: ${this.normalizeColor(this.stroke)}`,"paint-order: stroke"]:[],...this.dropShadow?[this.dropShadowToCSS()]:[],...this._overrides].join(";")}toGlobalCSS(){return this._fonts.reduce((t,e)=>`${t}
1141
1141
  @font-face {
1142
1142
  font-family: "${e.family}";
1143
1143
  src: url('${e.dataSrc}');
1144
1144
  font-weight: ${e.weight};
1145
1145
  font-style: ${e.style};
1146
1146
  font-display: ${e.display};
1147
- }`,this._stylesheet)}get stylesheet(){return this._stylesheet}set stylesheet(t){this._stylesheet!==t&&(this._stylesheet=t,this.styleID++)}normalizeColor(t){return Array.isArray(t)&&(t=Bw(t)),typeof t=="number"?Dw(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,gn.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}};Bh.availableFonts={},Bh.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 Oh=Bh;const Lo=class yn extends nn{constructor(t="",e={}){super(ct.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=ct.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=yn.defaultMaxWidth,this.maxHeight=yn.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=yn.defaultAutoResolution,this._resolution=yn.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({},yn.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=Gr(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=Gr(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 Oh?(this.ownsStyle=!1,this._style=t):t instanceof zr?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=Oh.from(t)):(this.ownsStyle=!0,this._style=new Oh(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;")}};Lo.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},Lo.defaultMaxWidth=2024,Lo.defaultMaxHeight=2024,Lo.defaultAutoResolution=!0;const jS=16777215,WS=.25,zS=16777215,YS=1,qS=1.5;let Kr=!1,dn;const Lh=r=>{const t={tint:r!=null&&r.fill?new Mt(r.fill).toNumber():jS,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:WS},e={tint:r!=null&&r.stroke?new Mt(r.stroke).toNumber():zS,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:YS,lineWidth:(r==null?void 0:r.strokeWidth)===void 0?qS:r.strokeWidth};return{fillStyle:t,strokeStyle:e}},fn=r=>(t,e,i,n={})=>{const{fillStyle:s,strokeStyle:o}=Lh(i),a=new ts;n.strokeOnly||(a.beginFill(16777215),r(e,a),a.endFill(),a.tint=s.tint,a.alpha=s.alpha),t.addChild(a);const l=new ts,h=o.lineWidth===1?1:o.lineWidth/dn;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}},KS=fn((r,t)=>{const{x:e,y:i,w:n,h:s}=r.geometry;t.drawRect(e,i,n,s)}),ZS=fn((r,t)=>{const{cx:e,cy:i,rx:n,ry:s}=r.geometry;t.drawEllipse(e,i,n,s)}),QS=fn((r,t)=>{const[[e,i],[n,s]]=r.geometry.points;t.moveTo(e,i),t.lineTo(n,s),t.closePath()}),JS=fn((r,t)=>{const e=r.geometry.points.reduce((i,n)=>[...i,...n],[]);t.drawPolygon(e)}),t2=fn((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,m=a.type==="CURVE"&&a.inHandle?a.inHandle[1]:u;t.bezierCurveTo(d,f,p,m,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()}),e2=fn((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()})})}),Mm=r=>{const t=r.viewport.getContainerSize().x;return r.viewport.getZoom(!0)*t/r.world.getContentFactor()},Dm=(r,t,e,i)=>()=>{const n=r.viewport.viewportToImageRectangle(r.viewport.getBounds(!0)),s=Mm(r);(s!==dn||!Kr)&&(Kr=!0,e.forEach(({stroke:d,strokeWidth:f})=>{const{lineStyle:p}=d.geometry.graphicsData[0];f>1?(Kr=s===dn,p.width=f/s,p.native=!1,d.geometry.invalidate()):f===1&&!p.native&&(p.width=1,p.native=!0,d.geometry.invalidate())})),dn=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)},r2=(r,t)=>{const e=new ts,i=Ip({width:t.width,height:t.height,backgroundAlpha:0,view:t,antialias:!0,resolution:2}),n=new Map;let s=new Set,o,a;dn=Mm(r);const l=(g,b)=>{Kr=!1;const S=n.get(g.id);S&&(S.fill.destroy(),S.stroke.destroy());const{selector:R}=g.target,C=typeof a=="function"?a(g,b):a;let I;if(R.type===_t.RECTANGLE)I=KS(e,R,C);else if(R.type===_t.POLYGON)I=JS(e,R,C);else if(R.type===_t.ELLIPSE)I=ZS(e,R,C);else if(R.type===_t.MULTIPOLYGON)I=e2(e,R,C);else if(R.type===_t.POLYLINE){const M=R;I=t2(e,M,C,{strokeOnly:!M.geometry.closed})}else R.type===_t.LINE?I=QS(e,R,C):console.warn(`Unsupported shape type: ${R.type}`);I&&n.set(g.id,{annotation:g,...I})},h=g=>{const b=n.get(g.id);b&&(n.delete(g.id),b.fill.destroy(),b.stroke.destroy())},c=(g,b,S)=>{Kr=!1;const R=n.get(g.id);if(R&&(n.delete(g.id),R.fill.destroy(),R.stroke.destroy(),l(b,S),s.has(b.id))){const{fill:C,stroke:I}=n.get(b.id);e.removeChild(C),e.removeChild(I)}},u=(g,b)=>{const S=n.get(g);S&&(n.delete(g),S.fill.destroy(),S.stroke.destroy(),l(S.annotation,b))},d=(g,b)=>{i.resize(g,b),i.render(e)},f=g=>{Kr=!1;const{children:b}=e;n.forEach(({fill:S,stroke:R,annotation:C})=>{const I=g?s.has(C.id)||g(C):!0;I&&!b.includes(S)?(e.addChild(S),e.addChild(R)):!I&&b.includes(S)&&(e.removeChild(S),e.removeChild(R))}),i.render(e)},p=g=>{const b=new Set(g.selected.map(C=>C.id)),S=g.selected.filter(({id:C})=>!s.has(C)),R=[...s].filter(C=>!b.has(C));S.forEach(({id:C,editable:I})=>{if(I){const M=n.get(C);M&&fa(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=b,i.render(e)},m=g=>{o!==g&&(g&&s.has(g)||(o&&!s.has(o)&&u(o,{selected:s.has(o)}),g&&u(g,{selected:s.has(g),hovered:!0}),o=g,i.render(e)))},y=g=>{if(typeof g=="function")n.forEach(({annotation:b,fill:S,stroke:R,strokeWidth:C},I)=>{C>1&&(Kr=!1);const M={selected:s.has(b.id),hovered:o===b.id},{fillStyle:F,strokeStyle:U}=Lh(g(b,M));S.tint=F.tint,S.alpha=F.alpha,R.tint=U.tint||16777215,R.alpha=U.alpha,n.set(b.id,{annotation:b,fill:S,stroke:R,strokeWidth:U.lineWidth})});else{const{fillStyle:b,strokeStyle:S}=Lh(g);S.lineWidth>1&&(Kr=!1),n.forEach(({annotation:R,fill:C,stroke:I,strokeWidth:M},F)=>{C.tint=b.tint,C.alpha=b.alpha,I.tint=S.tint||16777215,I.alpha=S.alpha,n.set(R.id,{annotation:R,fill:C,stroke:I,strokeWidth:S.lineWidth})})}a=g,i.render(e),Dm(r,e,n,i)()},_=g=>{g?t.classList.remove("hidden"):t.classList.add("hidden")};return{addAnnotation:l,destroy:()=>i.destroy(),getScale:()=>dn,redraw:Dm(r,e,n,i),removeAnnotation:h,resize:d,setFilter:f,setHovered:m,setSelected:p,setStyle:y,setVisible:_,updateAnnotation:c}};function i2(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;An(r,u,I=>e(11,i=I)),An(r,d,I=>e(8,n=I));const p=Oi(),m=Ne?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)},g=()=>m/y.getScale(),b=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=g(),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),D=g(),N=c.getAt(A,L,s,D);N?p("click",{originalEvent:M,annotation:N}):p("click",{originalEvent:M})}_=void 0};let C;return ii(()=>{var N;const{offsetWidth:I,offsetHeight:M}=l.canvas,F=document.createElement("canvas");F.width=I,F.height=M,F.className="a9s-gl-canvas",(N=l.element.querySelector(".openseadragon-canvas"))==null||N.appendChild(F),e(7,y=r2(l,F));const U=S(F);F.addEventListener("pointermove",U);const P=new ResizeObserver($=>{try{const{width:O,height:B}=$[0].contentRect;F.width=O,F.height=B,y.resize(O,B)}catch{console.warn("WebGL canvas already disposed")}});P.observe(F);const T=()=>{const $=l.viewport.getBounds();C=l.viewport.viewportToImageRectangle($);const{x:O,y:B,width:k,height:V}=C,j=c.getIntersecting(O,B,k,V);f.set(j.map(K=>K.id))};l.addHandler("canvas-press",b),l.addHandler("canvas-release",R),l.addHandler("update-viewport",y.redraw),l.addHandler("animation-finish",T);const E=$=>$.filter(O=>Le(O)),A=$=>Le($.oldValue)&&Le($.newValue),L=$=>{const{selector:O}=$.target;if(O.type===_t.POLYGON){const B=hv(O);return{...$,target:{...$.target,selector:{...B}}}}else if(O.type===_t.MULTIPOLYGON){const B=av(O);return{...$,target:{...$.target,selector:{...B}}}}else return $},D=$=>{const{created:O,updated:B,deleted:k}=$.changes,V=(O||[]).filter(j=>Le(j)).map(L);if(E(k||[]).forEach(j=>y.removeAnnotation(j)),V.forEach(j=>y.addAnnotation(j)),(B||[]).filter(j=>A(j)).map(({oldValue:j,newValue:K})=>({oldValue:j,newValue:L(K)})).forEach(({oldValue:j,newValue:K})=>y.updateAnnotation(j,K)),C){const{x:j,y:K,width:X,height:ft}=C,H=c.getIntersecting(j,K,X,ft);f.set(H.map(mt=>mt.id))}else f.set(c.all().map(j=>j.id));y.redraw()};return c.observe(D),()=>{var $;F.removeEventListener("pointermove",U),P.disconnect(),l.removeHandler("canvas-press",b),l.removeHandler("canvas-release",R),l.removeHandler("update-viewport",y.redraw),l.removeHandler("animation-finish",T),c.unobserve(D),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 n2 extends Wt{constructor(t){super(),jt(this,t,i2,null,Ut,{filter:2,state:3,style:4,viewer:5,visible:6})}}const Bm=(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},s2=r=>({transform:r&2,scale:r&1}),Om=r=>({transform:r[1],scale:r[0]});function o2(r){let t;const e=r[4].default,i=du(e,r,r[3],Om);return{c(){i&&i.c()},m(n,s){i&&i.m(n,s),t=!0},p(n,[s]){i&&i.p&&(!t||s&11)&&mu(i,e,n,n[3],t?pu(e,n[3],s,s2):gu(n[3]),Om)},i(n){t||(q(i,n),t=!0)},o(n){at(i,n),t=!1},d(n){i&&i.d(n)}}}function a2(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,m=s.viewport.getRotation(!0);e(1,a=`translate(${d.x}, ${d.y}) scale(${p}, ${f}) rotate(${m})`),e(0,o=c*h/s.world.getContentFactor())};return ii(()=>(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 Nh extends Wt{constructor(t){super(),jt(this,t,a2,o2,Ut,{viewer:2})}}function l2(r,t,e){const i=Oi();let{drawingMode:n}=t,{opts:s}=t,{target:o}=t,{tool:a}=t,{transform:l}=t,{viewer:h}=t,{viewportScale:c}=t,u;return ii(()=>{const d=o.closest("svg"),f=[],p=(m,y,_)=>{if(d==null||d.addEventListener(m,y,_),f.push(()=>d==null?void 0:d.removeEventListener(m,y,_)),m==="pointerup"||m==="dblclick"){const v=b=>{const{originalEvent:S}=b;y(S)},g=m==="pointerup"?"canvas-click":"canvas-double-click";h.addHandler(g,v),f.push(()=>h.removeHandler(g,v))}else if(m==="pointermove"){const v=g=>{const{originalEvent:b}=g;y(b)};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",m=>i("create",m.detail)),()=>{f.forEach(m=>m()),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 h2 extends Wt{constructor(t){super(),jt(this,t,l2,null,Ut,{drawingMode:0,opts:1,target:2,tool:3,transform:4,viewer:5,viewportScale:6})}}const{Boolean:c2}=ba;function Lm(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 u2(r){let t=`${r[2]}-${r[7]}`,e,i,n=Nm(r);return{c(){n.c(),e=Pe()},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(),at(n,1,1,Ft),he(),n=Nm(s),n.c(),q(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(q(n),i=!0)},o(s){at(n),i=!1},d(s){s&&st(e),n.d(s)}}}function d2(r){let t,e,i=xe(r[9].filter(r[29])),n=[];for(let o=0;o<i.length;o+=1)n[o]=Um(Lm(r,i,o));const s=o=>at(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},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=xe(o[9].filter(o[29]));let l;for(l=0;l<i.length;l+=1){const h=Lm(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=Um(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(c2);for(let a=0;a<n.length;a+=1)at(n[a]);e=!1},d(o){o&&st(t),Or(n,o)}}}function Nm(r){let t,e;return t=new h2({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Fm(r){let t=r[41].id,e,i,n=km(r);return{c(){n.c(),e=Pe()},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(),at(n,1,1,Ft),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){at(n),i=!1},d(s){s&&st(e),n.d(s)}}}function km(r){let t,e;return t=new Kv({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(){Zt(r[17](r[41]))&&r[17](r[41]).apply(this,arguments)}),t.$on("release",r[15]),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Um(r){let t,e,i=r[42]&&Fm(r);return{c(){i&&i.c(),t=Pe()},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=Fm(n),i.c(),q(i,1),i.m(t.parentNode,t)):i&&(le(),at(i,1,1,()=>{i=null}),he())},i(n){e||(q(i),e=!0)},o(n){at(i),e=!1},d(n){n&&st(t),i&&i.d(n)}}}function f2(r){let t,e,i,n,s,o,a,l;const h=[d2,u2],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=it("svg"),e=it("g"),n&&n.c(),w(e,"transform",s=r[39]),w(e,"class","svelte-g4ws1v"),w(t,"tabindex",0),w(t,"class","a9s-annotationlayer a9s-osd-drawinglayer svelte-g4ws1v"),Lr(t,"drawing",r[0]),Lr(t,"editing",r[9]),Lr(t,"hover",r[6])},m(d,f){ot(d,t,f),Ct(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(),at(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]))&&w(e,"transform",s),(!o||f[0]&1)&&Lr(t,"drawing",d[0]),(!o||f[0]&512)&&Lr(t,"editing",d[9]),(!o||f[0]&64)&&Lr(t,"hover",d[6])},i(d){o||(q(n),o=!0)},o(d){at(n),o=!1},d(d){d&&st(t),~i&&c[i].d(),r[30](null),a=!1,l()}}}function p2(r){let t,e;return t=new Nh({props:{viewer:r[3],$$slots:{default:[f2,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function m2(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=ys()[0]}=t,{user:m}=t,{viewer:y}=t;const _=Ne?10:2;let v=!1,g=0;const b=()=>e(7,g+=1),S=()=>p,R=()=>l;let C;const{store:I,selection:M,hover:F}=d;An(r,M,X=>e(28,o=X)),An(r,F,X=>e(33,a=X));let U,P,T;const E=X=>{I.unobserve(U);const ft=X.filter(({editable:H})=>H).map(({id:H})=>H);ft.length>0?(e(9,P=ft.map(H=>I.getAnnotation(H))),U=H=>{const{updated:mt}=H.changes;e(9,P=(mt||[]).map(Q=>Q.newValue))},I.observe(U,{annotations:ft}),y.forceRedraw()):e(9,P=void 0)},A=(X,ft)=>{const{x:H,y:mt}=y.viewport.viewerElementToImageCoordinates(new se.Point(X,ft));return[H,mt]},L=()=>{const X=y.viewport.getContainerSize().x;return y.viewport.getZoom(!0)*X/y.world.getContentFactor()},D=()=>_/L(),N=X=>{y.setMouseNavEnabled(!1),T=X.timeStamp},$=X=>{if(y.setMouseNavEnabled(!0),performance.now()-(T||0)<300){const{offsetX:H,offsetY:mt}=X.detail,[Q,ut]=A(H,mt),gt=D(),Et=I.getAt(Q,ut,void 0,gt);if(Et&&(!h||h(Et))&&!P.find(Yt=>Yt.id===Et.id)){F.set(Et.id);const Yt=Bm(Et.id,X.detail,M,c);M.userSelect(Yt)}}},O=X=>{const ft=new se.Point(X.offsetX,X.offsetY),H=y.viewport.pointFromPixel(ft),{x:mt,y:Q}=y.viewport.viewportToImageCoordinates(H.x,H.y),ut=D(),gt=I.getAt(mt,Q,h,ut);gt?a!==gt.id&&F.set(gt.id):a&&F.set(void 0)},B=X=>ft=>{var ut;const{target:H}=X,mt=10*60*1e3,Q=((ut=H.creator)==null?void 0:ut.id)!==m.id||!H.created||new Date().getTime()-H.created.getTime()>mt;I.updateTarget({...H,selector:ft.detail,created:Q?H.created:new Date,updated:Q?new Date:void 0,updatedBy:Q?m:void 0})},k=X=>{const ft=yv(),H={id:ft,bodies:[],target:{annotation:ft,selector:X.detail,creator:m,created:new Date}};I.addAnnotation(H),M.setSelected(H.id),y.setMouseNavEnabled(!0)},V=X=>fa(X);ii(()=>{const X=ft=>{if(o.selected.length===0)return;const{offsetX:H,offsetY:mt}=ft,Q=y.viewport.pointFromPixel(new se.Point(H,mt)),{x:ut,y:gt}=y.viewport.viewportToImageCoordinates(Q.x,Q.y),Et=D();e(6,v=!!I.getAt(ut,gt,h,Et))};return y.element.addEventListener("pointermove",X),()=>{var ft;(ft=y.element)==null||ft.removeEventListener("pointermove",X)}});const j=X=>Le(X);function K(X){xs[X?"unshift":"push"](()=>{C=X,e(8,C)})}return r.$$set=X=>{"drawingEnabled"in X&&e(0,l=X.drawingEnabled),"filter"in X&&e(20,h=X.filter),"multiSelect"in X&&e(21,c=X.multiSelect),"preferredDrawingMode"in X&&e(22,u=X.preferredDrawingMode),"state"in X&&e(23,d=X.state),"style"in X&&e(1,f=X.style),"toolName"in X&&e(2,p=X.toolName),"user"in X&&e(24,m=X.user),"viewer"in X&&e(3,y=X.viewer)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(10,{tool:i,opts:n}=_s(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&&E(o.selected)},[l,f,p,y,s,n,v,g,C,P,i,M,F,A,N,$,O,B,k,V,h,c,u,d,m,b,S,R,o,j,K]}class g2 extends Wt{constructor(t){super(),jt(this,t,m2,p2,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 y2(r){let t,e,i,n,s,o,a,l=r[2].appearance.label+"",h,c,u,d;return{c(){t=it("g"),e=it("rect"),a=it("text"),h=xa(l),w(e,"class","a9s-presence-label-bg svelte-1rehw2p"),w(e,"x",r[0]),w(e,"y",i=r[1]-18/r[3]),w(e,"height",n=18/r[3]),w(e,"fill",s=r[2].appearance.color),w(e,"stroke",o=r[2].appearance.color),w(a,"font-size",c=12/r[3]),w(a,"x",u=r[0]+Math.round(5/r[3])),w(a,"y",d=r[1]-5/r[3]),w(a,"class","svelte-1rehw2p"),w(t,"class","a9s-presence-label")},m(f,p){ot(f,t,p),Ct(t,e),Ct(t,a),Ct(a,h),r[6](t)},p(f,[p]){p&1&&w(e,"x",f[0]),p&10&&i!==(i=f[1]-18/f[3])&&w(e,"y",i),p&8&&n!==(n=18/f[3])&&w(e,"height",n),p&4&&s!==(s=f[2].appearance.color)&&w(e,"fill",s),p&4&&o!==(o=f[2].appearance.color)&&w(e,"stroke",o),p&4&&l!==(l=f[2].appearance.label+"")&&j_(h,l),p&8&&c!==(c=12/f[3])&&w(a,"font-size",c),p&9&&u!==(u=f[0]+Math.round(5/f[3]))&&w(a,"x",u),p&10&&d!==(d=f[1]-5/f[3])&&w(a,"y",d)},i:Ft,o:Ft,d(f){f&&st(t),r[6](null)}}}function _2(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){xs[u?"unshift":"push"](()=>{l=u,e(4,l)})}return r.$$set=u=>{"x"in u&&e(0,i=u.x),"y"in u&&e(1,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 Gm extends Wt{constructor(t){super(),jt(this,t,_2,y2,Ut,{x:0,y:1,user:2,scale:3,hAlign:5})}}function v2(r){let t,e,i,n,s,o;return e=new Gm({props:{scale:r[1],user:r[0],x:r[3][0],y:r[3][1],hAlign:"CENTER"}}),{c(){t=it("g"),Lt(e.$$.fragment),i=it("polygon"),w(i,"class","a9s-presence-shape a9s-presence-polygon svelte-fgq4n0"),w(i,"stroke",n=r[0].appearance.color),w(i,"fill","transparent"),w(i,"points",s=r[2].points.map($m).join(" ")),w(t,"class","a9s-presence-overlay")},m(a,l){ot(a,t,l),Bt(e,t,null),Ct(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))&&w(i,"stroke",n),(!o||l&4&&s!==(s=a[2].points.map($m).join(" ")))&&w(i,"points",s)},i(a){o||(q(e.$$.fragment,a),o=!0)},o(a){at(e.$$.fragment,a),o=!1},d(a){a&&st(t),Ot(e)}}}const $m=r=>r.join(",");function b2(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 x2 extends Wt{constructor(t){super(),jt(this,t,b2,v2,Ut,{annotation:4,user:0,scale:1})}}function w2(r){let t,e,i,n,s,o,a,l,h;return e=new Gm({props:{scale:r[1],user:r[0],x:r[2].x,y:r[2].y}}),{c(){t=it("g"),Lt(e.$$.fragment),i=it("rect"),w(i,"class","a9s-presence-shape a9s-presence-rectangle svelte-gze948"),w(i,"stroke",n=r[0].appearance.color),w(i,"fill","transparent"),w(i,"x",s=r[2].x),w(i,"y",o=r[2].y),w(i,"width",a=r[2].w),w(i,"height",l=r[2].h),w(t,"class","a9s-presence-overlay")},m(c,u){ot(c,t,u),Bt(e,t,null),Ct(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))&&w(i,"stroke",n),(!h||u&4&&s!==(s=c[2].x))&&w(i,"x",s),(!h||u&4&&o!==(o=c[2].y))&&w(i,"y",o),(!h||u&4&&a!==(a=c[2].w))&&w(i,"width",a),(!h||u&4&&l!==(l=c[2].h))&&w(i,"height",l)},i(c){h||(q(e.$$.fragment,c),h=!0)},o(c){at(e.$$.fragment,c),h=!1},d(c){c&&st(t),Ot(e)}}}function E2(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 T2 extends Wt{constructor(t){super(),jt(this,t,E2,w2,Ut,{annotation:3,user:0,scale:1})}}const{Boolean:A2}=ba;function Hm(r,t,e){const i=r.slice();return i[8]=t[e],i}function Xm(r){let t,e;return t=new Nh({props:{viewer:r[0],$$slots:{default:[I2,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Vm(r){let t,e,i=xe(r[2]),n=[];for(let o=0;o<i.length;o+=1)n[o]=jm(Hm(r,i,o));const s=o=>at(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},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=xe(o[2]);let l;for(l=0;l<i.length;l+=1){const h=Hm(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=jm(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(A2);for(let a=0;a<n.length;a+=1)at(n[a]);e=!1},d(o){o&&st(t),Or(n,o)}}}function S2(r){let t,e;return t=new x2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function C2(r){let t,e;return t=new T2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function jm(r){let t,e,i,n;const s=[C2,S2],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=Pe()},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(),at(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){at(e),n=!1},d(l){l&&st(i),~t&&o[t].d(l)}}}function I2(r){let t,e,i,n,s=r[2].length>0&&Vm(r);return{c(){t=it("svg"),e=it("g"),s&&s.c(),w(e,"transform",i=r[6]),w(t,"class","a9s-osd-presencelayer svelte-1krwc4m")},m(o,a){ot(o,t,a),Ct(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=Vm(o),s.c(),q(s,1),s.m(e,null)):s&&(le(),at(s,1,1,()=>{s=null}),he()),(!n||a&64&&i!==(i=o[6]))&&w(e,"transform",i)},i(o){n||(q(s),n=!0)},o(o){at(s),n=!1},d(o){o&&st(t),s&&s.d()}}}function P2(r){let t=!!r[1],e,i,n=t&&Xm(r);return{c(){n&&n.c(),e=Pe()},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=Xm(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),at(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){at(n),i=!1},d(s){s&&st(e),n&&n.d(s)}}}function R2(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)),m=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=m)},i.observe(a,{annotations:o.map(u=>u.annotation.id)})};return z_(()=>{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 M2 extends Wt{constructor(t){super(),jt(this,t,R2,P2,Ut,{store:3,viewer:0,provider:1})}}function D2(r){let t,e,i,n,s;return{c(){t=it("ellipse"),w(t,"cx",e=r[0].cx),w(t,"cy",i=r[0].cy),w(t,"rx",n=r[0].rx),w(t,"ry",s=r[0].ry)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].cx)&&w(t,"cx",e),a&1&&i!==(i=o[0].cy)&&w(t,"cy",i),a&1&&n!==(n=o[0].rx)&&w(t,"rx",n),a&1&&s!==(s=o[0].ry)&&w(t,"ry",s)},i:Ft,o:Ft,d(o){o&&st(t)}}}function B2(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 O2 extends Wt{constructor(t){super(),jt(this,t,B2,D2,Ut,{annotation:1})}}function L2(r){let t,e,i,n,s;return{c(){t=it("line"),w(t,"x1",e=r[0].points[0][0]),w(t,"y1",i=r[0].points[0][1]),w(t,"x2",n=r[0].points[1][0]),w(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])&&w(t,"x1",e),a&1&&i!==(i=o[0].points[0][1])&&w(t,"y1",i),a&1&&n!==(n=o[0].points[1][0])&&w(t,"x2",n),a&1&&s!==(s=o[0].points[1][1])&&w(t,"y2",s)},i:Ft,o:Ft,d(o){o&&st(t)}}}function N2(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 F2 extends Wt{constructor(t){super(),jt(this,t,N2,L2,Ut,{annotation:1})}}function Wm(r,t,e){const i=r.slice();return i[2]=t[e],i}function zm(r){let t,e;return{c(){t=it("path"),e=it("path"),w(t,"fill-rule","evenodd"),w(t,"d",He(r[2])),w(e,"class","a9s-inner"),w(e,"fill-rule","evenodd"),w(e,"d",He(r[2]))},m(i,n){ot(i,t,n),ot(i,e,n)},p:Ft,d(i){i&&(st(t),st(e))}}}function k2(r){let t,e=xe(r[0]),i=[];for(let n=0;n<e.length;n+=1)i[n]=zm(Wm(r,e,n));return{c(){t=it("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=xe(n[0]);let o;for(o=0;o<e.length;o+=1){const a=Wm(n,e,o);i[o]?i[o].p(a,s):(i[o]=zm(a),i[o].c(),i[o].m(t,null))}for(;o<i.length;o+=1)i[o].d(1);i.length=e.length}},i:Ft,o:Ft,d(n){n&&st(t),Or(i,n)}}}function U2(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 G2 extends Wt{constructor(t){super(),jt(this,t,U2,k2,Ut,{annotation:1})}}function $2(r){let t,e;return{c(){t=it("polygon"),w(t,"points",e=r[0].points.map(Ym).join(" "))},m(i,n){ot(i,t,n)},p(i,[n]){n&1&&e!==(e=i[0].points.map(Ym).join(" "))&&w(t,"points",e)},i:Ft,o:Ft,d(i){i&&st(t)}}}const Ym=r=>r.join(",");function H2(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 X2 extends Wt{constructor(t){super(),jt(this,t,H2,$2,Ut,{annotation:1})}}function V2(r){let t;return{c(){t=it("path"),w(t,"d",r[0])},m(e,i){ot(e,t,i)},p(e,[i]){i&1&&w(t,"d",e[0])},i:Ft,o:Ft,d(e){e&&st(t)}}}function j2(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=Jo(i))},[n,s,i]}class W2 extends Wt{constructor(t){super(),jt(this,t,j2,V2,Ut,{annotation:1})}}function z2(r){let t,e,i,n,s;return{c(){t=it("rect"),w(t,"x",e=r[0].x),w(t,"y",i=r[0].y),w(t,"width",n=r[0].w),w(t,"height",s=r[0].h)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].x)&&w(t,"x",e),a&1&&i!==(i=o[0].y)&&w(t,"y",i),a&1&&n!==(n=o[0].w)&&w(t,"width",n),a&1&&s!==(s=o[0].h)&&w(t,"height",s)},i:Ft,o:Ft,d(o){o&&st(t)}}}function Y2(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 q2 extends Wt{constructor(t){super(),jt(this,t,Y2,z2,Ut,{annotation:1})}}const{Boolean:K2}=ba;function qm(r,t,e){const i=r.slice();return i[10]=t[e],i}function Km(r){let t,e;return t=new Nh({props:{viewer:r[0],$$slots:{default:[iC,({transform:i})=>({9:i}),({transform:i})=>i?512:0]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Z2(r){let t,e;return t=new F2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Q2(r){let t,e;return t=new O2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function J2(r){let t,e;return t=new W2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function tC(r){let t,e;return t=new G2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function eC(r){let t,e;return t=new X2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function rC(r){let t,e;return t=new q2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Zm(r){let t,e,i,n;const s=[rC,eC,tC,J2,Q2,Z2],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=Pe()},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(),at(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){at(e),n=!1},d(l){l&&st(i),~t&&o[t].d(l)}}}function iC(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m=xe(r[1].filter(r[6])),y=[];for(let v=0;v<m.length;v+=1)y[v]=Zm(qm(r,m,v));const _=v=>at(y[v],1,1,()=>{y[v]=null});return{c(){var v,g,b,S;t=it("svg"),e=it("g"),i=it("rect"),l=it("rect");for(let R=0;R<y.length;R+=1)y[R].c();w(i,"class","a9s-union-bg svelte-jwrce3"),w(i,"x",n=(v=r[2])==null?void 0:v.minX),w(i,"y",s=(g=r[2])==null?void 0:g.minY),w(i,"width",o=r[2]?r[2].maxX-r[2].minX:0),w(i,"height",a=r[2]?r[2].maxY-r[2].minY:0),w(l,"class","a9s-union-fg svelte-jwrce3"),w(l,"x",h=(b=r[2])==null?void 0:b.minX),w(l,"y",c=(S=r[2])==null?void 0:S.minY),w(l,"width",u=r[2]?r[2].maxX-r[2].minX:0),w(l,"height",d=r[2]?r[2].maxY-r[2].minY:0),w(e,"transform",f=r[9]),w(t,"class","a9s-osd-selectionlayer svelte-jwrce3")},m(v,g){ot(v,t,g),Ct(t,e),Ct(e,i),Ct(e,l);for(let b=0;b<y.length;b+=1)y[b]&&y[b].m(e,null);p=!0},p(v,g){var b,S,R,C;if((!p||g&4&&n!==(n=(b=v[2])==null?void 0:b.minX))&&w(i,"x",n),(!p||g&4&&s!==(s=(S=v[2])==null?void 0:S.minY))&&w(i,"y",s),(!p||g&4&&o!==(o=v[2]?v[2].maxX-v[2].minX:0))&&w(i,"width",o),(!p||g&4&&a!==(a=v[2]?v[2].maxY-v[2].minY:0))&&w(i,"height",a),(!p||g&4&&h!==(h=(R=v[2])==null?void 0:R.minX))&&w(l,"x",h),(!p||g&4&&c!==(c=(C=v[2])==null?void 0:C.minY))&&w(l,"y",c),(!p||g&4&&u!==(u=v[2]?v[2].maxX-v[2].minX:0))&&w(l,"width",u),(!p||g&4&&d!==(d=v[2]?v[2].maxY-v[2].minY:0))&&w(l,"height",d),g&2){m=xe(v[1].filter(v[6]));let I;for(I=0;I<m.length;I+=1){const M=qm(v,m,I);y[I]?(y[I].p(M,g),q(y[I],1)):(y[I]=Zm(M),y[I].c(),q(y[I],1),y[I].m(e,null))}for(le(),I=m.length;I<y.length;I+=1)_(I);he()}(!p||g&512&&f!==(f=v[9]))&&w(e,"transform",f)},i(v){if(!p){for(let g=0;g<m.length;g+=1)q(y[g]);p=!0}},o(v){y=y.filter(K2);for(let g=0;g<y.length;g+=1)at(y[g]);p=!1},d(v){v&&st(t),Or(y,v)}}}function nC(r){let t=!!r[2],e,i,n=t&&Km(r);return{c(){n&&n.c(),e=Pe()},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=Km(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),at(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){at(n),i=!1},d(s){s&&st(e),n&&n.d(s)}}}function sC(r,t,e){let i,n,s,{state:o}=t,{viewer:a}=t;const{store:l}=o,{selection:h}=o;An(r,h,d=>e(5,s=d));const c=d=>{let f=-1/0,p=-1/0,m=1/0,y=1/0;for(let _ of d.filter(v=>Le(v))){const{bounds:v}=_.target.selector.geometry;v.maxX>f&&(f=v.maxX),v.maxY>p&&(p=v.maxY),v.minX<m&&(m=v.minX),v.minY<y&&(y=v.minY)}return a.forceRedraw(),{maxX:f,maxY:p,minX:m,minY:y}},u=d=>Le(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 oC extends Wt{constructor(t){super(),jt(this,t,sC,nC,Ut,{state:4,viewer:0})}}const Qm=(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=su(a);r.element.setAttribute("data-theme",l)}})}):r.element.setAttribute("data-theme",t)},Jm=(r,t,e)=>(i,n={})=>{const s=typeof i=="string"?i:i.id,o=t.getAnnotation(s);if(!o||!Le(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:m,maxY:y}=o.target.selector.geometry.bounds,_=m-f,v=y-p,g=f-d*_,b=p-h*v,S=_+(c+d)*_,R=v+(h+u)*v,C=r.viewport.imageToViewportRectangle(g,b,S,R);r.viewport[e](C,n.immediately)},aC=(r,t)=>Jm(r,t,"fitBounds"),lC=(r,t)=>Jm(r,t,"fitBoundsWithConstraints"),hC=(r,t={})=>{const e=au(t,{drawingEnabled:!1,drawingMode:Ne?"drag":"click",userSelectAction:$o.EDIT,theme:"light"}),i=nu(e),{hover:n,selection:s,store:o}=i,a=vg(o,e.initialHistory),l=bg(i,a,e.adapter,e.autoSave);let h=Ig(),c=e.drawingEnabled,u=e.drawingMode,d=e.modalSelect;const f=hu(a,r.element),p=new n2({target:r.element,props:{state:i,viewer:r,style:e.style,filter:void 0}}),m=new M2({target:r.element.querySelector(".openseadragon-canvas"),props:{provider:void 0,store:o,viewer:r}}),y=new g2({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 oC({target:r.element.querySelector(".openseadragon-canvas"),props:{state:i,viewer:r}}):void 0;p.$on("click",B=>{const{originalEvent:k,annotation:V}=B.detail,j=K=>Bm(K.id,k,s,e.multiSelect);d?s.isEmpty()&&V&&s.userSelect(j(V),k):V&&!(u==="click"&&c)?s.userSelect(j(V),k):s.isEmpty()||(e.multiSelect?k.metaKey||k.shiftKey||k.ctrlKey||s.userSelect([],k):s.userSelect([],k))}),r.element.addEventListener("pointerdown",B=>{if(n.current){const k=o.getAnnotation(n.current);l.emit("clickAnnotation",k,B)}}),Qm(r,e.theme);const v=wg(i,a,e.adapter),g=()=>y.cancelDrawing(),b=()=>{p.$destroy(),m.$destroy(),y.$destroy(),_==null||_.$destroy(),f.destroy(),a.destroy()},S=aC(r,o),R=lC(r,o),C=()=>y.getDrawingTool(),I=()=>h,M=()=>y.isDrawingEnabled(),F=(B,k,V)=>Xc(B,k,V),U=(B,k)=>Uc(B,k),P=B=>{if(!_s(B))throw`No drawing tool named ${B}`;y.$set({toolName:B})},T=B=>{c=B,y.$set({drawingEnabled:B})},E=B=>{p.$set({filter:B}),y.$set({filter:B})},A=B=>d=B,L=B=>{p.$set({style:B}),y.$set({style:B})},D=B=>m.$set({provider:B}),N=B=>Qm(r,B),$=B=>{h=B,y.$set({user:B})},O=B=>p.$set({visible:B});return{...v,cancelDrawing:g,destroy:b,fitBounds:S,fitBoundsWithConstraints:R,getDrawingTool:C,getUser:I,isDrawingEnabled:M,listDrawingTools:ys,on:l.on,off:l.off,registerDrawingTool:F,registerShapeEditor:U,setDrawingEnabled:T,setDrawingTool:P,setFilter:E,setModalSelect:A,setPresenceProvider:D,setStyle:L,setTheme:N,setUser:$,setVisible:O,state:i,viewer:r}};qt.ShapeType=_t,qt.UserSelectAction=$o,qt.W3CImageFormat=r0,qt.chainStyles=Wy,qt.computeStyle=jy,qt.createBody=cg,qt.createImageAnnotator=$_,qt.createOSDAnnotator=hC,qt.defaultColorProvider=Rg,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=Bw(t)),typeof t=="number"?Dw(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,gn.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}};Bh.availableFonts={},Bh.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 Oh=Bh;const Lo=class yn extends nn{constructor(t="",e={}){super(ct.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=ct.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=yn.defaultMaxWidth,this.maxHeight=yn.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=yn.defaultAutoResolution,this._resolution=yn.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({},yn.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=Gr(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=Gr(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 Oh?(this.ownsStyle=!1,this._style=t):t instanceof zr?(console.warn("[HTMLText] Cloning TextStyle, if this is not what you want, use HTMLTextStyle"),this.ownsStyle=!0,this._style=Oh.from(t)):(this.ownsStyle=!0,this._style=new Oh(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;")}};Lo.defaultDestroyOptions={texture:!0,children:!1,baseTexture:!0},Lo.defaultMaxWidth=2024,Lo.defaultMaxHeight=2024,Lo.defaultAutoResolution=!0;const jS=16777215,WS=.25,zS=16777215,YS=1,qS=1.5;let Kr=!1,dn;const Lh=r=>{const t={tint:r!=null&&r.fill?new Mt(r.fill).toNumber():jS,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:WS},e={tint:r!=null&&r.stroke?new Mt(r.stroke).toNumber():zS,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:YS,lineWidth:(r==null?void 0:r.strokeWidth)===void 0?qS:r.strokeWidth};return{fillStyle:t,strokeStyle:e}},fn=r=>(t,e,i,n={})=>{const{fillStyle:s,strokeStyle:o}=Lh(i),a=new ts;n.strokeOnly||(a.beginFill(16777215),r(e,a),a.endFill(),a.tint=s.tint,a.alpha=s.alpha),t.addChild(a);const l=new ts,h=o.lineWidth===1?1:o.lineWidth/dn;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}},KS=fn((r,t)=>{const{x:e,y:i,w:n,h:s}=r.geometry;t.drawRect(e,i,n,s)}),ZS=fn((r,t)=>{const{cx:e,cy:i,rx:n,ry:s}=r.geometry;t.drawEllipse(e,i,n,s)}),QS=fn((r,t)=>{const[[e,i],[n,s]]=r.geometry.points;t.moveTo(e,i),t.lineTo(n,s),t.closePath()}),JS=fn((r,t)=>{const e=r.geometry.points.reduce((i,n)=>[...i,...n],[]);t.drawPolygon(e)}),t2=fn((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,m=a.type==="CURVE"&&a.inHandle?a.inHandle[1]:u;t.bezierCurveTo(d,f,p,m,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()}),e2=fn((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()})})}),Mm=r=>{const t=r.viewport.getContainerSize().x;return r.viewport.getZoom(!0)*t/r.world.getContentFactor()},Dm=(r,t,e,i)=>()=>{const n=r.viewport.viewportToImageRectangle(r.viewport.getBounds(!0)),s=Mm(r);(s!==dn||!Kr)&&(Kr=!0,e.forEach(({stroke:d,strokeWidth:f})=>{const{lineStyle:p}=d.geometry.graphicsData[0];f>1?(Kr=s===dn,p.width=f/s,p.native=!1,d.geometry.invalidate()):f===1&&!p.native&&(p.width=1,p.native=!0,d.geometry.invalidate())})),dn=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)},r2=(r,t)=>{const e=new ts,i=Ip({width:t.width,height:t.height,backgroundAlpha:0,view:t,antialias:!0,resolution:2}),n=new Map;let s=new Set,o,a;dn=Mm(r);const l=(g,b)=>{Kr=!1;const S=n.get(g.id);S&&(S.fill.destroy(),S.stroke.destroy());const{selector:R}=g.target,C=typeof a=="function"?a(g,b):a;let I;if(R.type===_t.RECTANGLE)I=KS(e,R,C);else if(R.type===_t.POLYGON)I=JS(e,R,C);else if(R.type===_t.ELLIPSE)I=ZS(e,R,C);else if(R.type===_t.MULTIPOLYGON)I=e2(e,R,C);else if(R.type===_t.POLYLINE){const M=R;I=t2(e,M,C,{strokeOnly:!M.geometry.closed})}else R.type===_t.LINE?I=QS(e,R,C):console.warn(`Unsupported shape type: ${R.type}`);I&&n.set(g.id,{annotation:g,...I})},h=g=>{const b=n.get(g.id);b&&(n.delete(g.id),b.fill.destroy(),b.stroke.destroy())},c=(g,b,S)=>{Kr=!1;const R=n.get(g.id);if(R&&(n.delete(g.id),R.fill.destroy(),R.stroke.destroy(),l(b,S),s.has(b.id))){const{fill:C,stroke:I}=n.get(b.id);e.removeChild(C),e.removeChild(I)}},u=(g,b)=>{const S=n.get(g);S&&(n.delete(g),S.fill.destroy(),S.stroke.destroy(),l(S.annotation,b))},d=(g,b)=>{i.resize(g,b),i.render(e)},f=g=>{Kr=!1;const{children:b}=e;n.forEach(({fill:S,stroke:R,annotation:C})=>{const I=g?s.has(C.id)||g(C):!0;I&&!b.includes(S)?(e.addChild(S),e.addChild(R)):!I&&b.includes(S)&&(e.removeChild(S),e.removeChild(R))}),i.render(e)},p=g=>{const b=new Set(g.selected.map(C=>C.id)),S=g.selected.filter(({id:C})=>!s.has(C)),R=[...s].filter(C=>!b.has(C));S.forEach(({id:C,editable:I})=>{if(I){const M=n.get(C);M&&fa(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=b,i.render(e)},m=g=>{o!==g&&(g&&s.has(g)||(o&&!s.has(o)&&u(o,{selected:s.has(o)}),g&&u(g,{selected:s.has(g),hovered:!0}),o=g,i.render(e)))},y=g=>{if(typeof g=="function")n.forEach(({annotation:b,fill:S,stroke:R,strokeWidth:C},I)=>{C>1&&(Kr=!1);const M={selected:s.has(b.id),hovered:o===b.id},{fillStyle:F,strokeStyle:U}=Lh(g(b,M));S.tint=F.tint,S.alpha=F.alpha,R.tint=U.tint||16777215,R.alpha=U.alpha,n.set(b.id,{annotation:b,fill:S,stroke:R,strokeWidth:U.lineWidth})});else{const{fillStyle:b,strokeStyle:S}=Lh(g);S.lineWidth>1&&(Kr=!1),n.forEach(({annotation:R,fill:C,stroke:I,strokeWidth:M},F)=>{C.tint=b.tint,C.alpha=b.alpha,I.tint=S.tint||16777215,I.alpha=S.alpha,n.set(R.id,{annotation:R,fill:C,stroke:I,strokeWidth:S.lineWidth})})}a=g,i.render(e),Dm(r,e,n,i)()},_=g=>{g?t.classList.remove("hidden"):t.classList.add("hidden")};return{addAnnotation:l,destroy:()=>i.destroy(),getScale:()=>dn,redraw:Dm(r,e,n,i),removeAnnotation:h,resize:d,setFilter:f,setHovered:m,setSelected:p,setStyle:y,setVisible:_,updateAnnotation:c}};function i2(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;An(r,u,I=>e(11,i=I)),An(r,d,I=>e(8,n=I));const p=Oi(),m=Ne?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)},g=()=>m/y.getScale(),b=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=g(),E=c.getAt(F,U,s,P);E?(I.classList.add("hover"),i!==E.id&&(u.set(E.id),y.setHovered(E.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,E=U-_.y;if(Math.sqrt(P*P+E*E)<5){const{x:A,y:O}=v(I.position),D=g(),L=c.getAt(A,O,s,D);L?p("click",{originalEvent:M,annotation:L}):p("click",{originalEvent:M})}_=void 0};let C;return ii(()=>{var L;const{offsetWidth:I,offsetHeight:M}=l.canvas,F=document.createElement("canvas");F.width=I,F.height=M,F.className="a9s-gl-canvas",(L=l.element.querySelector(".openseadragon-canvas"))==null||L.appendChild(F),e(7,y=r2(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 E=()=>{const $=l.viewport.getBounds();C=l.viewport.viewportToImageRectangle($);const{x:B,y:N,width:k,height:X}=C,j=c.getIntersecting(B,N,k,X);f.set(j.map(K=>K.id))};l.addHandler("canvas-press",b),l.addHandler("canvas-release",R),l.addHandler("update-viewport",y.redraw),l.addHandler("animation-finish",E);const T=$=>$.filter(B=>Le(B)),A=$=>Le($.oldValue)&&Le($.newValue),O=$=>{const{selector:B}=$.target;if(B.type===_t.POLYGON){const N=hv(B);return{...$,target:{...$.target,selector:{...N}}}}else if(B.type===_t.MULTIPOLYGON){const N=av(B);return{...$,target:{...$.target,selector:{...N}}}}else return $},D=$=>{const{created:B,updated:N,deleted:k}=$.changes,X=(B||[]).filter(j=>Le(j)).map(O);if(T(k||[]).forEach(j=>y.removeAnnotation(j)),X.forEach(j=>y.addAnnotation(j)),(N||[]).filter(j=>A(j)).map(({oldValue:j,newValue:K})=>({oldValue:j,newValue:O(K)})).forEach(({oldValue:j,newValue:K})=>y.updateAnnotation(j,K)),C){const{x:j,y:K,width:V,height:ut}=C,H=c.getIntersecting(j,K,V,ut);f.set(H.map(mt=>mt.id))}else f.set(c.all().map(j=>j.id));y.redraw()};return c.observe(D),()=>{var $;F.removeEventListener("pointermove",U),P.disconnect(),l.removeHandler("canvas-press",b),l.removeHandler("canvas-release",R),l.removeHandler("update-viewport",y.redraw),l.removeHandler("animation-finish",E),c.unobserve(D),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 n2 extends Wt{constructor(t){super(),jt(this,t,i2,null,Ut,{filter:2,state:3,style:4,viewer:5,visible:6})}}const Bm=(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},s2=r=>({transform:r&2,scale:r&1}),Om=r=>({transform:r[1],scale:r[0]});function o2(r){let t;const e=r[4].default,i=du(e,r,r[3],Om);return{c(){i&&i.c()},m(n,s){i&&i.m(n,s),t=!0},p(n,[s]){i&&i.p&&(!t||s&11)&&mu(i,e,n,n[3],t?pu(e,n[3],s,s2):gu(n[3]),Om)},i(n){t||(q(i,n),t=!0)},o(n){at(i,n),t=!1},d(n){i&&i.d(n)}}}function a2(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,m=s.viewport.getRotation(!0);e(1,a=`translate(${d.x}, ${d.y}) scale(${p}, ${f}) rotate(${m})`),e(0,o=c*h/s.world.getContentFactor())};return ii(()=>(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 Nh extends Wt{constructor(t){super(),jt(this,t,a2,o2,Ut,{viewer:2})}}function l2(r,t,e){const i=Oi();let{drawingMode:n}=t,{opts:s}=t,{target:o}=t,{tool:a}=t,{transform:l}=t,{viewer:h}=t,{viewportScale:c}=t,u;return ii(()=>{const d=o.closest("svg"),f=[],p=(m,y,_)=>{if(d==null||d.addEventListener(m,y,_),f.push(()=>d==null?void 0:d.removeEventListener(m,y,_)),m==="pointerup"||m==="dblclick"){const v=b=>{const{originalEvent:S}=b;y(S)},g=m==="pointerup"?"canvas-click":"canvas-double-click";h.addHandler(g,v),f.push(()=>h.removeHandler(g,v))}else if(m==="pointermove"){const v=g=>{const{originalEvent:b}=g;y(b)};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",m=>i("create",m.detail)),()=>{f.forEach(m=>m()),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 h2 extends Wt{constructor(t){super(),jt(this,t,l2,null,Ut,{drawingMode:0,opts:1,target:2,tool:3,transform:4,viewer:5,viewportScale:6})}}const{Boolean:c2}=ba;function Lm(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 u2(r){let t=`${r[2]}-${r[7]}`,e,i,n=Nm(r);return{c(){n.c(),e=Pe()},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(),at(n,1,1,Ft),he(),n=Nm(s),n.c(),q(n,1),n.m(e.parentNode,e)):n.p(s,o)},i(s){i||(q(n),i=!0)},o(s){at(n),i=!1},d(s){s&&st(e),n.d(s)}}}function d2(r){let t,e,i=xe(r[9].filter(r[29])),n=[];for(let o=0;o<i.length;o+=1)n[o]=Um(Lm(r,i,o));const s=o=>at(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},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=xe(o[9].filter(o[29]));let l;for(l=0;l<i.length;l+=1){const h=Lm(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=Um(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(c2);for(let a=0;a<n.length;a+=1)at(n[a]);e=!1},d(o){o&&st(t),Or(n,o)}}}function Nm(r){let t,e;return t=new h2({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Fm(r){let t=r[41].id,e,i,n=km(r);return{c(){n.c(),e=Pe()},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(),at(n,1,1,Ft),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){at(n),i=!1},d(s){s&&st(e),n.d(s)}}}function km(r){let t,e;return t=new Kv({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(){Zt(r[17](r[41]))&&r[17](r[41]).apply(this,arguments)}),t.$on("release",r[15]),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Um(r){let t,e,i=r[42]&&Fm(r);return{c(){i&&i.c(),t=Pe()},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=Fm(n),i.c(),q(i,1),i.m(t.parentNode,t)):i&&(le(),at(i,1,1,()=>{i=null}),he())},i(n){e||(q(i),e=!0)},o(n){at(i),e=!1},d(n){n&&st(t),i&&i.d(n)}}}function f2(r){let t,e,i,n,s,o,a,l;const h=[d2,u2],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=it("svg"),e=it("g"),n&&n.c(),w(e,"transform",s=r[39]),w(e,"class","svelte-g4ws1v"),w(t,"tabindex",0),w(t,"class","a9s-annotationlayer a9s-osd-drawinglayer svelte-g4ws1v"),Lr(t,"drawing",r[0]),Lr(t,"editing",r[9]),Lr(t,"hover",r[6])},m(d,f){ot(d,t,f),Ct(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(),at(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]))&&w(e,"transform",s),(!o||f[0]&1)&&Lr(t,"drawing",d[0]),(!o||f[0]&512)&&Lr(t,"editing",d[9]),(!o||f[0]&64)&&Lr(t,"hover",d[6])},i(d){o||(q(n),o=!0)},o(d){at(n),o=!1},d(d){d&&st(t),~i&&c[i].d(),r[30](null),a=!1,l()}}}function p2(r){let t,e;return t=new Nh({props:{viewer:r[3],$$slots:{default:[f2,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function m2(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=ys()[0]}=t,{user:m}=t,{viewer:y}=t;const _=Ne?10:2;let v=!1,g=0;const b=()=>e(7,g+=1),S=()=>p,R=()=>l;let C;const{store:I,selection:M,hover:F}=d;An(r,M,V=>e(28,o=V)),An(r,F,V=>e(33,a=V));let U,P,E;const T=V=>{I.unobserve(U);const ut=V.filter(({editable:H})=>H).map(({id:H})=>H);ut.length>0?(e(9,P=ut.map(H=>I.getAnnotation(H))),U=H=>{const{updated:mt}=H.changes;e(9,P=(mt||[]).map(Q=>Q.newValue))},I.observe(U,{annotations:ut}),y.forceRedraw()):e(9,P=void 0)},A=(V,ut)=>{const{x:H,y:mt}=y.viewport.viewerElementToImageCoordinates(new se.Point(V,ut));return[H,mt]},O=()=>{const V=y.viewport.getContainerSize().x;return y.viewport.getZoom(!0)*V/y.world.getContentFactor()},D=()=>_/O(),L=V=>{y.setMouseNavEnabled(!1),E=V.timeStamp},$=V=>{if(y.setMouseNavEnabled(!0),performance.now()-(E||0)<300){const{offsetX:H,offsetY:mt}=V.detail,[Q,dt]=A(H,mt),gt=D(),Et=I.getAt(Q,dt,void 0,gt);if(Et&&(!h||h(Et))&&!P.find(Yt=>Yt.id===Et.id)){F.set(Et.id);const Yt=Bm(Et.id,V.detail,M,c);M.userSelect(Yt)}}},B=V=>{const ut=new se.Point(V.offsetX,V.offsetY),H=y.viewport.pointFromPixel(ut),{x:mt,y:Q}=y.viewport.viewportToImageCoordinates(H.x,H.y),dt=D(),gt=I.getAt(mt,Q,h,dt);gt?a!==gt.id&&F.set(gt.id):a&&F.set(void 0)},N=V=>ut=>{var dt;const{target:H}=V,mt=10*60*1e3,Q=((dt=H.creator)==null?void 0:dt.id)!==m.id||!H.created||new Date().getTime()-H.created.getTime()>mt;I.updateTarget({...H,selector:ut.detail,created:Q?H.created:new Date,updated:Q?new Date:void 0,updatedBy:Q?m:void 0})},k=V=>{const ut=yv(),H={id:ut,bodies:[],target:{annotation:ut,selector:V.detail,creator:m,created:new Date}};I.addAnnotation(H),M.setSelected(H.id),y.setMouseNavEnabled(!0)},X=V=>fa(V);ii(()=>{const V=ut=>{if(o.selected.length===0)return;const{offsetX:H,offsetY:mt}=ut,Q=y.viewport.pointFromPixel(new se.Point(H,mt)),{x:dt,y:gt}=y.viewport.viewportToImageCoordinates(Q.x,Q.y),Et=D();e(6,v=!!I.getAt(dt,gt,h,Et))};return y.element.addEventListener("pointermove",V),()=>{var ut;(ut=y.element)==null||ut.removeEventListener("pointermove",V)}});const j=V=>Le(V);function K(V){xs[V?"unshift":"push"](()=>{C=V,e(8,C)})}return r.$$set=V=>{"drawingEnabled"in V&&e(0,l=V.drawingEnabled),"filter"in V&&e(20,h=V.filter),"multiSelect"in V&&e(21,c=V.multiSelect),"preferredDrawingMode"in V&&e(22,u=V.preferredDrawingMode),"state"in V&&e(23,d=V.state),"style"in V&&e(1,f=V.style),"toolName"in V&&e(2,p=V.toolName),"user"in V&&e(24,m=V.user),"viewer"in V&&e(3,y=V.viewer)},r.$$.update=()=>{r.$$.dirty[0]&4&&e(10,{tool:i,opts:n}=_s(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&&T(o.selected)},[l,f,p,y,s,n,v,g,C,P,i,M,F,A,L,$,B,N,k,X,h,c,u,d,m,b,S,R,o,j,K]}class g2 extends Wt{constructor(t){super(),jt(this,t,m2,p2,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 y2(r){let t,e,i,n,s,o,a,l=r[2].appearance.label+"",h,c,u,d;return{c(){t=it("g"),e=it("rect"),a=it("text"),h=xa(l),w(e,"class","a9s-presence-label-bg svelte-1rehw2p"),w(e,"x",r[0]),w(e,"y",i=r[1]-18/r[3]),w(e,"height",n=18/r[3]),w(e,"fill",s=r[2].appearance.color),w(e,"stroke",o=r[2].appearance.color),w(a,"font-size",c=12/r[3]),w(a,"x",u=r[0]+Math.round(5/r[3])),w(a,"y",d=r[1]-5/r[3]),w(a,"class","svelte-1rehw2p"),w(t,"class","a9s-presence-label")},m(f,p){ot(f,t,p),Ct(t,e),Ct(t,a),Ct(a,h),r[6](t)},p(f,[p]){p&1&&w(e,"x",f[0]),p&10&&i!==(i=f[1]-18/f[3])&&w(e,"y",i),p&8&&n!==(n=18/f[3])&&w(e,"height",n),p&4&&s!==(s=f[2].appearance.color)&&w(e,"fill",s),p&4&&o!==(o=f[2].appearance.color)&&w(e,"stroke",o),p&4&&l!==(l=f[2].appearance.label+"")&&j_(h,l),p&8&&c!==(c=12/f[3])&&w(a,"font-size",c),p&9&&u!==(u=f[0]+Math.round(5/f[3]))&&w(a,"x",u),p&10&&d!==(d=f[1]-5/f[3])&&w(a,"y",d)},i:Ft,o:Ft,d(f){f&&st(t),r[6](null)}}}function _2(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){xs[u?"unshift":"push"](()=>{l=u,e(4,l)})}return r.$$set=u=>{"x"in u&&e(0,i=u.x),"y"in u&&e(1,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 Gm extends Wt{constructor(t){super(),jt(this,t,_2,y2,Ut,{x:0,y:1,user:2,scale:3,hAlign:5})}}function v2(r){let t,e,i,n,s,o;return e=new Gm({props:{scale:r[1],user:r[0],x:r[3][0],y:r[3][1],hAlign:"CENTER"}}),{c(){t=it("g"),Lt(e.$$.fragment),i=it("polygon"),w(i,"class","a9s-presence-shape a9s-presence-polygon svelte-fgq4n0"),w(i,"stroke",n=r[0].appearance.color),w(i,"fill","transparent"),w(i,"points",s=r[2].points.map($m).join(" ")),w(t,"class","a9s-presence-overlay")},m(a,l){ot(a,t,l),Bt(e,t,null),Ct(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))&&w(i,"stroke",n),(!o||l&4&&s!==(s=a[2].points.map($m).join(" ")))&&w(i,"points",s)},i(a){o||(q(e.$$.fragment,a),o=!0)},o(a){at(e.$$.fragment,a),o=!1},d(a){a&&st(t),Ot(e)}}}const $m=r=>r.join(",");function b2(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 x2 extends Wt{constructor(t){super(),jt(this,t,b2,v2,Ut,{annotation:4,user:0,scale:1})}}function w2(r){let t,e,i,n,s,o,a,l,h;return e=new Gm({props:{scale:r[1],user:r[0],x:r[2].x,y:r[2].y}}),{c(){t=it("g"),Lt(e.$$.fragment),i=it("rect"),w(i,"class","a9s-presence-shape a9s-presence-rectangle svelte-gze948"),w(i,"stroke",n=r[0].appearance.color),w(i,"fill","transparent"),w(i,"x",s=r[2].x),w(i,"y",o=r[2].y),w(i,"width",a=r[2].w),w(i,"height",l=r[2].h),w(t,"class","a9s-presence-overlay")},m(c,u){ot(c,t,u),Bt(e,t,null),Ct(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))&&w(i,"stroke",n),(!h||u&4&&s!==(s=c[2].x))&&w(i,"x",s),(!h||u&4&&o!==(o=c[2].y))&&w(i,"y",o),(!h||u&4&&a!==(a=c[2].w))&&w(i,"width",a),(!h||u&4&&l!==(l=c[2].h))&&w(i,"height",l)},i(c){h||(q(e.$$.fragment,c),h=!0)},o(c){at(e.$$.fragment,c),h=!1},d(c){c&&st(t),Ot(e)}}}function E2(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 T2 extends Wt{constructor(t){super(),jt(this,t,E2,w2,Ut,{annotation:3,user:0,scale:1})}}const{Boolean:A2}=ba;function Hm(r,t,e){const i=r.slice();return i[8]=t[e],i}function Xm(r){let t,e;return t=new Nh({props:{viewer:r[0],$$slots:{default:[I2,({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){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Vm(r){let t,e,i=xe(r[2]),n=[];for(let o=0;o<i.length;o+=1)n[o]=jm(Hm(r,i,o));const s=o=>at(n[o],1,1,()=>{n[o]=null});return{c(){for(let o=0;o<n.length;o+=1)n[o].c();t=Pe()},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=xe(o[2]);let l;for(l=0;l<i.length;l+=1){const h=Hm(o,i,l);n[l]?(n[l].p(h,a),q(n[l],1)):(n[l]=jm(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(A2);for(let a=0;a<n.length;a+=1)at(n[a]);e=!1},d(o){o&&st(t),Or(n,o)}}}function S2(r){let t,e;return t=new x2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function C2(r){let t,e;return t=new T2({props:{annotation:r[8].annotation,user:r[8].selectedBy,scale:r[7]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function jm(r){let t,e,i,n;const s=[C2,S2],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=Pe()},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(),at(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){at(e),n=!1},d(l){l&&st(i),~t&&o[t].d(l)}}}function I2(r){let t,e,i,n,s=r[2].length>0&&Vm(r);return{c(){t=it("svg"),e=it("g"),s&&s.c(),w(e,"transform",i=r[6]),w(t,"class","a9s-osd-presencelayer svelte-1krwc4m")},m(o,a){ot(o,t,a),Ct(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=Vm(o),s.c(),q(s,1),s.m(e,null)):s&&(le(),at(s,1,1,()=>{s=null}),he()),(!n||a&64&&i!==(i=o[6]))&&w(e,"transform",i)},i(o){n||(q(s),n=!0)},o(o){at(s),n=!1},d(o){o&&st(t),s&&s.d()}}}function P2(r){let t=!!r[1],e,i,n=t&&Xm(r);return{c(){n&&n.c(),e=Pe()},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=Xm(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),at(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){at(n),i=!1},d(s){s&&st(e),n&&n.d(s)}}}function R2(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)),m=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=m)},i.observe(a,{annotations:o.map(u=>u.annotation.id)})};return z_(()=>{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 M2 extends Wt{constructor(t){super(),jt(this,t,R2,P2,Ut,{store:3,viewer:0,provider:1})}}function D2(r){let t,e,i,n,s;return{c(){t=it("ellipse"),w(t,"cx",e=r[0].cx),w(t,"cy",i=r[0].cy),w(t,"rx",n=r[0].rx),w(t,"ry",s=r[0].ry)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].cx)&&w(t,"cx",e),a&1&&i!==(i=o[0].cy)&&w(t,"cy",i),a&1&&n!==(n=o[0].rx)&&w(t,"rx",n),a&1&&s!==(s=o[0].ry)&&w(t,"ry",s)},i:Ft,o:Ft,d(o){o&&st(t)}}}function B2(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 O2 extends Wt{constructor(t){super(),jt(this,t,B2,D2,Ut,{annotation:1})}}function L2(r){let t,e,i,n,s;return{c(){t=it("line"),w(t,"x1",e=r[0].points[0][0]),w(t,"y1",i=r[0].points[0][1]),w(t,"x2",n=r[0].points[1][0]),w(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])&&w(t,"x1",e),a&1&&i!==(i=o[0].points[0][1])&&w(t,"y1",i),a&1&&n!==(n=o[0].points[1][0])&&w(t,"x2",n),a&1&&s!==(s=o[0].points[1][1])&&w(t,"y2",s)},i:Ft,o:Ft,d(o){o&&st(t)}}}function N2(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 F2 extends Wt{constructor(t){super(),jt(this,t,N2,L2,Ut,{annotation:1})}}function Wm(r,t,e){const i=r.slice();return i[2]=t[e],i}function zm(r){let t,e;return{c(){t=it("path"),e=it("path"),w(t,"fill-rule","evenodd"),w(t,"d",He(r[2])),w(e,"class","a9s-inner"),w(e,"fill-rule","evenodd"),w(e,"d",He(r[2]))},m(i,n){ot(i,t,n),ot(i,e,n)},p:Ft,d(i){i&&(st(t),st(e))}}}function k2(r){let t,e=xe(r[0]),i=[];for(let n=0;n<e.length;n+=1)i[n]=zm(Wm(r,e,n));return{c(){t=it("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=xe(n[0]);let o;for(o=0;o<e.length;o+=1){const a=Wm(n,e,o);i[o]?i[o].p(a,s):(i[o]=zm(a),i[o].c(),i[o].m(t,null))}for(;o<i.length;o+=1)i[o].d(1);i.length=e.length}},i:Ft,o:Ft,d(n){n&&st(t),Or(i,n)}}}function U2(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 G2 extends Wt{constructor(t){super(),jt(this,t,U2,k2,Ut,{annotation:1})}}function $2(r){let t,e;return{c(){t=it("polygon"),w(t,"points",e=r[0].points.map(Ym).join(" "))},m(i,n){ot(i,t,n)},p(i,[n]){n&1&&e!==(e=i[0].points.map(Ym).join(" "))&&w(t,"points",e)},i:Ft,o:Ft,d(i){i&&st(t)}}}const Ym=r=>r.join(",");function H2(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 X2 extends Wt{constructor(t){super(),jt(this,t,H2,$2,Ut,{annotation:1})}}function V2(r){let t;return{c(){t=it("path"),w(t,"d",r[0])},m(e,i){ot(e,t,i)},p(e,[i]){i&1&&w(t,"d",e[0])},i:Ft,o:Ft,d(e){e&&st(t)}}}function j2(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=Jo(i))},[n,s,i]}class W2 extends Wt{constructor(t){super(),jt(this,t,j2,V2,Ut,{annotation:1})}}function z2(r){let t,e,i,n,s;return{c(){t=it("rect"),w(t,"x",e=r[0].x),w(t,"y",i=r[0].y),w(t,"width",n=r[0].w),w(t,"height",s=r[0].h)},m(o,a){ot(o,t,a)},p(o,[a]){a&1&&e!==(e=o[0].x)&&w(t,"x",e),a&1&&i!==(i=o[0].y)&&w(t,"y",i),a&1&&n!==(n=o[0].w)&&w(t,"width",n),a&1&&s!==(s=o[0].h)&&w(t,"height",s)},i:Ft,o:Ft,d(o){o&&st(t)}}}function Y2(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 q2 extends Wt{constructor(t){super(),jt(this,t,Y2,z2,Ut,{annotation:1})}}const{Boolean:K2}=ba;function qm(r,t,e){const i=r.slice();return i[10]=t[e],i}function Km(r){let t,e;return t=new Nh({props:{viewer:r[0],$$slots:{default:[iC,({transform:i})=>({9:i}),({transform:i})=>i?512:0]},$$scope:{ctx:r}}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Z2(r){let t,e;return t=new F2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Q2(r){let t,e;return t=new O2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function J2(r){let t,e;return t=new W2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function tC(r){let t,e;return t=new G2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function eC(r){let t,e;return t=new X2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function rC(r){let t,e;return t=new q2({props:{annotation:r[10]}}),{c(){Lt(t.$$.fragment)},m(i,n){Bt(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){at(t.$$.fragment,i),e=!1},d(i){Ot(t,i)}}}function Zm(r){let t,e,i,n;const s=[rC,eC,tC,J2,Q2,Z2],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=Pe()},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(),at(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){at(e),n=!1},d(l){l&&st(i),~t&&o[t].d(l)}}}function iC(r){let t,e,i,n,s,o,a,l,h,c,u,d,f,p,m=xe(r[1].filter(r[6])),y=[];for(let v=0;v<m.length;v+=1)y[v]=Zm(qm(r,m,v));const _=v=>at(y[v],1,1,()=>{y[v]=null});return{c(){var v,g,b,S;t=it("svg"),e=it("g"),i=it("rect"),l=it("rect");for(let R=0;R<y.length;R+=1)y[R].c();w(i,"class","a9s-union-bg svelte-jwrce3"),w(i,"x",n=(v=r[2])==null?void 0:v.minX),w(i,"y",s=(g=r[2])==null?void 0:g.minY),w(i,"width",o=r[2]?r[2].maxX-r[2].minX:0),w(i,"height",a=r[2]?r[2].maxY-r[2].minY:0),w(l,"class","a9s-union-fg svelte-jwrce3"),w(l,"x",h=(b=r[2])==null?void 0:b.minX),w(l,"y",c=(S=r[2])==null?void 0:S.minY),w(l,"width",u=r[2]?r[2].maxX-r[2].minX:0),w(l,"height",d=r[2]?r[2].maxY-r[2].minY:0),w(e,"transform",f=r[9]),w(t,"class","a9s-osd-selectionlayer svelte-jwrce3")},m(v,g){ot(v,t,g),Ct(t,e),Ct(e,i),Ct(e,l);for(let b=0;b<y.length;b+=1)y[b]&&y[b].m(e,null);p=!0},p(v,g){var b,S,R,C;if((!p||g&4&&n!==(n=(b=v[2])==null?void 0:b.minX))&&w(i,"x",n),(!p||g&4&&s!==(s=(S=v[2])==null?void 0:S.minY))&&w(i,"y",s),(!p||g&4&&o!==(o=v[2]?v[2].maxX-v[2].minX:0))&&w(i,"width",o),(!p||g&4&&a!==(a=v[2]?v[2].maxY-v[2].minY:0))&&w(i,"height",a),(!p||g&4&&h!==(h=(R=v[2])==null?void 0:R.minX))&&w(l,"x",h),(!p||g&4&&c!==(c=(C=v[2])==null?void 0:C.minY))&&w(l,"y",c),(!p||g&4&&u!==(u=v[2]?v[2].maxX-v[2].minX:0))&&w(l,"width",u),(!p||g&4&&d!==(d=v[2]?v[2].maxY-v[2].minY:0))&&w(l,"height",d),g&2){m=xe(v[1].filter(v[6]));let I;for(I=0;I<m.length;I+=1){const M=qm(v,m,I);y[I]?(y[I].p(M,g),q(y[I],1)):(y[I]=Zm(M),y[I].c(),q(y[I],1),y[I].m(e,null))}for(le(),I=m.length;I<y.length;I+=1)_(I);he()}(!p||g&512&&f!==(f=v[9]))&&w(e,"transform",f)},i(v){if(!p){for(let g=0;g<m.length;g+=1)q(y[g]);p=!0}},o(v){y=y.filter(K2);for(let g=0;g<y.length;g+=1)at(y[g]);p=!1},d(v){v&&st(t),Or(y,v)}}}function nC(r){let t=!!r[2],e,i,n=t&&Km(r);return{c(){n&&n.c(),e=Pe()},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=Km(s),n.c(),q(n,1),n.m(e.parentNode,e)):n&&(le(),at(n,1,1,()=>{n=null}),he())},i(s){i||(q(n),i=!0)},o(s){at(n),i=!1},d(s){s&&st(e),n&&n.d(s)}}}function sC(r,t,e){let i,n,s,{state:o}=t,{viewer:a}=t;const{store:l}=o,{selection:h}=o;An(r,h,d=>e(5,s=d));const c=d=>{let f=-1/0,p=-1/0,m=1/0,y=1/0;for(let _ of d.filter(v=>Le(v))){const{bounds:v}=_.target.selector.geometry;v.maxX>f&&(f=v.maxX),v.maxY>p&&(p=v.maxY),v.minX<m&&(m=v.minX),v.minY<y&&(y=v.minY)}return a.forceRedraw(),{maxX:f,maxY:p,minX:m,minY:y}},u=d=>Le(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 oC extends Wt{constructor(t){super(),jt(this,t,sC,nC,Ut,{state:4,viewer:0})}}const Qm=(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=su(a);r.element.setAttribute("data-theme",l)}})}):r.element.setAttribute("data-theme",t)},Jm=(r,t,e)=>(i,n={})=>{const s=typeof i=="string"?i:i.id,o=t.getAnnotation(s);if(!o||!Le(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:m,maxY:y}=o.target.selector.geometry.bounds,_=m-f,v=y-p,g=f-d*_,b=p-h*v,S=_+(c+d)*_,R=v+(h+u)*v,C=r.viewport.imageToViewportRectangle(g,b,S,R);r.viewport[e](C,n.immediately)},aC=(r,t)=>Jm(r,t,"fitBounds"),lC=(r,t)=>Jm(r,t,"fitBoundsWithConstraints"),hC=(r,t={})=>{const e=au(t,{drawingEnabled:!1,drawingMode:Ne?"drag":"click",userSelectAction:$o.EDIT,theme:"light"}),i=nu(e),{hover:n,selection:s,store:o}=i,a=vg(o,e.initialHistory),l=bg(i,a,e.adapter,e.autoSave);let h=Ig(),c=e.drawingEnabled,u=e.drawingMode,d=e.modalSelect;const f=hu(a,r.element),p=new n2({target:r.element,props:{state:i,viewer:r,style:e.style,filter:void 0}}),m=new M2({target:r.element.querySelector(".openseadragon-canvas"),props:{provider:void 0,store:o,viewer:r}}),y=new g2({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 oC({target:r.element.querySelector(".openseadragon-canvas"),props:{state:i,viewer:r}}):void 0;p.$on("click",k=>{const{originalEvent:X,annotation:j}=k.detail,K=V=>Bm(V.id,X,s,e.multiSelect);d?s.isEmpty()&&j&&s.userSelect(K(j),X):j&&!(u==="click"&&c)?s.userSelect(K(j),X):s.isEmpty()||(e.multiSelect?X.metaKey||X.shiftKey||X.ctrlKey||s.userSelect([],X):s.userSelect([],X))}),r.element.addEventListener("pointerdown",k=>{if(n.current){const X=o.getAnnotation(n.current);l.emit("clickAnnotation",X,k)}}),Qm(r,e.theme);const v=wg(i,a,e.adapter),g=()=>y.cancelDrawing(),b=()=>{p.$destroy(),m.$destroy(),y.$destroy(),_==null||_.$destroy(),f.destroy(),a.destroy()},S=aC(r,o),R=lC(r,o),C=()=>y.getDrawingTool(),I=()=>h,M=()=>y.isDrawingEnabled(),F=(k,X,j)=>Xc(k,X,j),U=(k,X)=>Uc(k,X),P=k=>{if(!_s(k))throw`No drawing tool named ${k}`;y.$set({toolName:k})},E=k=>{c=k,y.$set({drawingEnabled:k})},T=k=>{u=k,y.$set({preferredDrawingMode:k})},A=k=>{p.$set({filter:k}),y.$set({filter:k})},O=k=>d=k,D=k=>{p.$set({style:k}),y.$set({style:k})},L=k=>m.$set({provider:k}),$=k=>Qm(r,k),B=k=>{h=k,y.$set({user:k})},N=k=>p.$set({visible:k});return{...v,cancelDrawing:g,destroy:b,fitBounds:S,fitBoundsWithConstraints:R,getDrawingTool:C,getUser:I,isDrawingEnabled:M,listDrawingTools:ys,on:l.on,off:l.off,registerDrawingTool:F,registerShapeEditor:U,setDrawingEnabled:E,setDrawingMode:T,setDrawingTool:P,setFilter:A,setModalSelect:O,setPresenceProvider:L,setStyle:D,setTheme:$,setUser:B,setVisible:N,state:i,viewer:r}};qt.ShapeType=_t,qt.UserSelectAction=$o,qt.W3CImageFormat=r0,qt.chainStyles=Wy,qt.computeStyle=jy,qt.createBody=cg,qt.createImageAnnotator=$_,qt.createOSDAnnotator=hC,qt.defaultColorProvider=Rg,Object.defineProperty(qt,Symbol.toStringTag,{value:"Module"})});
1148
1148
  //# sourceMappingURL=annotorious-openseadragon.js.map