@arenarium/maps 1.2.14 → 1.2.16

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.
Files changed (2) hide show
  1. package/dist/main.js +1 -1
  2. package/package.json +2 -2
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- class r{endtime=0;lifespan;paused=!1;enqueued=!1;interval;timeout;callback;constructor(x,j,q){if((j??0)<0)throw Error("Lifespan must be greater than 0");if((q??0)<0)throw Error("Interval must be greater than 0");let Q=navigator?.hardwareConcurrency?200/navigator.hardwareConcurrency:100;this.interval=q??Q;let h=this.interval;this.lifespan=j??h,this.callback=x}async run(){let x=performance.now();if(this.enqueued)this.endtime=x+this.lifespan,this.enqueued=!1;if(this.endtime<x){this.stop();return}if(this.paused==!1){if(await this.callback()&&!this.enqueued){this.stop();return}}this.timeout=window.setTimeout(this.run.bind(this),this.interval)}start(){if(this.enqueued=!0,!this.timeout)this.run()}stop(){if(this.timeout)window.clearTimeout(this.timeout);this.timeout=void 0}pause(){this.paused=!0}resume(){this.paused=!1}}class B0{data;state;constructor(x){this.data=x,this.state=void 0}get input(){return{id:this.data.id,rank:this.data.rank,lat:this.data.lat,lng:this.data.lng,width:this.data.tooltip.style.dimensions.width,height:this.data.tooltip.style.dimensions.height,margin:this.data.tooltip.style.dimensions.margin}}}class y0{callback;timeout;id;constructor(x,j){if(j<=0)throw Error("Timeout must be greater than 0");this.callback=x,this.timeout=j}start(){if(this.id!=null)return;this.id=window.setInterval(this.callback,this.timeout)}stop(){if(this.id==null)return;window.clearInterval(this.id),this.id=void 0}}var z1=100;class N0{viewport=void 0;state="idle";provider;interval;onCancel;onError;onMove;onIdle;onClick;constructor(x,j,q,Q,h,G){this.provider=x,this.interval=new y0(this.onInterval.bind(this),z1/(navigator?.hardwareConcurrency??1)),this.onCancel=j,this.onError=q,this.onMove=Q,this.onIdle=h,this.onClick=G}start(){this.interval.start(),this.provider.getContainer().addEventListener("click",this.onClick.bind(this))}stop(){this.interval.stop(),this.provider.getContainer().removeEventListener("click",this.onClick.bind(this))}onInterval(){try{if(this.onCancel()){this.interval.stop();return}let x=this.provider.getViewport(),j=this.state,q=JSON.stringify(x)!==JSON.stringify(this.viewport)?"move":"idle";if(q=="move")this.onMove();if(q=="idle"&&j=="move")this.onIdle();this.state=q,this.viewport=x}catch(x){this.onError("Failed to process map state interval",x)}}}var p0=75,n0=150,I0=0.00025,o0=1e6,t0=2000000,w0=3000000,x0=10,L=16,j0=2,k=0.5,i="white",a0="darkgreen",q0="0px 2px 2px rgba(0, 0, 0, 0.5)";import*as d from"@arenarium/maps-core/mercator";class p{sw;ne;constructor(x,j,q,Q){if(q<x)throw Error(`Invalid bounds: ${x}, ${j}, ${q}, ${Q}`);if(Q<j)throw Error(`Invalid bounds: ${x}, ${j}, ${q}, ${Q}`);this.sw={lat:x,lng:j},this.ne={lat:q,lng:Q}}contains(x,j){if(x<this.sw.lat||this.ne.lat<x)return!1;if(j<this.sw.lng||this.ne.lng<j)return!1;return!0}intersects(x){if(x.ne.lat<this.sw.lat||this.ne.lat<x.sw.lat)return!1;if(x.ne.lng<this.sw.lng||this.ne.lng<x.sw.lng)return!1;return!0}}class A{blockL;blockR;sw;ne;constructor(x,j,q,Q){if(q<x)throw Error(`Invalid bounds: ${x}, ${j}, ${q}, ${Q}`);if(this.sw={lat:x,lng:j},this.ne={lat:q,lng:Q},j<Q)this.blockL=new p(x,j,q,Q),this.blockR=new p(0,0,0,0);else this.blockL=new p(x,-180,q,Q),this.blockR=new p(x,j,q,180)}static normalize(x){let{bounds:j,center:q}=x;if(Math.abs(j.ne.lng-q.lng)+Math.abs(j.sw.lng-q.lng)>360)j.sw.lng=-180,j.ne.lng=180;if(j.ne.lng-j.sw.lng>360){j.sw.lng=-180,j.ne.lng=180;return}if(j.sw.lng<-180)j.sw.lng+=360;if(j.sw.lng>180)j.sw.lng-=360;if(j.ne.lng<-180)j.ne.lng+=360;if(j.ne.lng>180)j.ne.lng-=360}static bounds(x){this.normalize(x);let j=x.bounds,q=j.sw,Q=j.ne;return new A(q.lat,q.lng,Q.lat,Q.lng)}static offset(x,j,q){this.normalize(x);let{bounds:Q,zoom:h}=x,G=j*Math.pow(2,h),Z=d.project(Q.sw.lat,Q.sw.lng,G),U=d.project(Q.ne.lat,Q.ne.lng,G),H=Math.max(Z.x-q.left,0),X=Math.min(Z.y+q.bottom,G),z=Math.min(U.x+q.right,G),w=Math.max(U.y-q.top,0),B=d.unproject(H,X,G),y=d.unproject(z,w,G);return new A(B.lat,B.lng,y.lat,y.lng)}contains(x,j){return this.blockL.contains(x,j)||this.blockR.contains(x,j)}intersects(x){return this.blockL.intersects(x)||this.blockR.intersects(x)}}class T0{id;bounds;markers;constructor(x,j){this.id=x,this.bounds=j,this.markers=[]}belongs(x){let j=this.bounds.sw;if(x.lat<j.lat)return!1;if(x.lng<j.lng)return!1;let q=this.bounds.ne;if(q.lat<x.lat)return!1;if(q.lng<x.lng)return!1;return!0}neighbours(x,j){let q=Math.abs(x.id.length-this.id.length);if(q>j)return!1;let Q=Math.min(this.id.length,x.id.length)-j+q;for(let h=0;h<Q;h++)if(this.id[h]!=x.id[h])return!1;return!0}}class Q0{tree;zoom;cell;branches;constructor(x,j,q,Q){this.tree=x,this.zoom=q,this.cell=new T0(j,Q),this.branches=[]}split(){let x=this.cell.bounds,j=Math.pow(2,this.tree.depth),q=(x.ne.lat-x.sw.lat)/j,Q=(x.ne.lng-x.sw.lng)/j;for(let h=0;h<j;h++)for(let G=0;G<j;G++){let Z=x.sw.lat+h*q,U=x.sw.lng+G*Q,H=Z+q,X=U+Q;this.branches.push(new Q0(this.tree,`${this.cell.id}${h*2+G}`,this.zoom+this.tree.depth,{sw:{lat:Z,lng:U},ne:{lat:H,lng:X}}))}}add(x){if(this.cell.belongs(x.data)==!1)return!1;if(this.cell.markers.length<this.tree.capacity)return this.cell.markers.push(x),!0;if(this.branches.length==0)this.split();for(let j=0;j<this.branches.length;j++)if(this.branches[j].add(x))return!0;throw Error("Failed to add marker to branch")}compact(){if(this.branches.length==0)return;for(let Q=0;Q<this.branches.length;Q++)this.branches[Q].compact();let x=[],j=[];for(let Q=0;Q<this.branches.length;Q++){let h=this.branches[Q];x.push(...h.branches),j.push(...h.cell.markers)}let q=new Q0(this.tree,this.cell.id,this.zoom+this.tree.depth,this.cell.bounds);q.branches=x,q.cell.markers=j,this.branches=[q]}cells(x,j,q){if(x<this.zoom)return q;if(j.intersects(this.cell.bounds)==!1)return q;q.push(this.cell);for(let Q=0;Q<this.branches.length;Q++)this.branches[Q].cells(x,j,q);return q}print(x){console.log(`${"---".repeat(x)}|${this.cell.id} zoom=[${this.zoom}] markers=[${this.cell.markers.length}]`);for(let j=0;j<this.branches.length;j++)this.branches[j].print(x+1)}count(){return this.cell.markers.length+this.branches.reduce((x,j)=>x+j.count(),0)}}class G0{capacity;depth;root;constructor(x,j,q){this.capacity=q,this.depth=j,this.root=new Q0(this,"R",x,{sw:{lat:-90,lng:-180},ne:{lat:90,lng:180}})}add(x){return this.root.add(x)}compact(){this.root.compact()}cells(x,j){let q=[];return this.root.cells(x,j,q),q}print(){this.root.print(0)}}var e0=2,x1=1,j1=L*4,q1=1024;class D0{mapProvider;markersVisibilityTree;markersVisible;markerTreeCellCapacity=e0;markerTreeCellZoomDelta=x1;markerTreeCellSize=j1;markerTreeLimit=q1;constructor(x){this.mapProvider=x}set configuration(x){this.markerTreeCellCapacity=x?.process?.visibility?.cell?.capacity??e0,this.markerTreeCellZoomDelta=x?.process?.visibility?.cell?.depth??x1,this.markerTreeCellSize=x?.process?.visibility?.cell?.size??j1,this.markerTreeLimit=x?.process?.visibility?.limit??q1}getMarkers(){return Array.from(this.markersVisible??[])}insertMarkers(x){this.markersVisibilityTree=this.createTree(x)}clearMarkers(){this.markersVisibilityTree=void 0,this.markersVisible=void 0}updateMarkers(x,j){if(this.markersVisibilityTree==null)return;let q=A.bounds(x),Q=[],h=x.zoom;while(h<j.zoomMax&&Q.length<this.markerTreeLimit)Q=this.markersVisibilityTree.cells(h,q).flatMap((G)=>G.markers),h++;this.markersVisible=Q}createTree(x){if(x.length<this.markerTreeLimit){let j=new G0(0,0,x.length);for(let q=0;q<x.length;q++){let Q=x[q];if(!j.add(Q))throw Error("Failed to add marker to fill tree")}return j}else{let j=-Math.floor(Math.log2(this.mapProvider.getParameters().mapSize/this.markerTreeCellSize)),q=new G0(j,this.markerTreeCellZoomDelta,this.markerTreeCellCapacity);for(let h=0;h<x.length;h++){let G=x[h];if(!q.add(G))throw Error("Failed to add marker to fill tree")}let Q=-j;for(let h=0;h<Q;h++)q.compact();return q}}}import{mount as N1}from"svelte";class E{div;marker;constructor(x,j,q,Q){this.div=document.createElement("div"),this.marker=x.createMarker(this.div,j,q,Q)}insert(){if(this.marker.inserted()==!0)return;this.marker.insert()}remove(){if(this.marker.inserted()==!1)return;this.marker.remove()}update(x){this.marker.update(x)}}class v{shown;id;lat;lng;rank;marker;constructor(x,j){if(new.target===v)throw Error("Cannot instantiate an abstract class directly.");this.shown=!0,this.id=x.id,this.lat=x.lat,this.lng=x.lng,this.rank=x.rank,this.marker=j}}import"svelte/internal/disclose-version";import*as F from"svelte/internal/client";import{sineInOut as B1}from"svelte/easing";class n{animationEasing;animationRun;animating;value;time;constructor(x){if(x.max<=x.min)throw Error("Min must be less than max");if(x.value<x.min||x.max<x.value)throw Error("Value must be between min and max");this.animationEasing=x.easing,this.animationRun=x.callback,this.animating=!1,this.value={current:x.value,start:x.value,end:x.value,min:x.min,max:x.max},this.time={start:0,end:0,span:x.timespan}}animationFrame(){let x=performance.now();if(x>this.time.end)this.value.current=this.value.end;else{let j=(x-this.time.start)/(this.time.end-this.time.start),q=this.animationEasing(j);this.value.current=this.value.start+(this.value.end-this.value.start)*q}if(this.animationRun(this.value.current),this.value.current===this.value.end){this.animating=!1;return}window.requestAnimationFrame(this.animationFrame.bind(this))}target(x){if(x===this.value.end)return;this.value.start=this.value.current,this.value.end=x;let j=performance.now(),q=Math.abs(this.value.start-this.value.end),Q=this.value.max-this.value.min;if(this.time.start=j,this.time.end=j+this.time.span*Math.sqrt(q/Q),this.animating)return;this.animating=!0,window.requestAnimationFrame(this.animationFrame.bind(this))}set(x){if(x===this.value.end)return;this.value.current=x,this.value.start=x,this.value.end=x;let j=performance.now();this.time.start=j,this.time.end=j,window.requestAnimationFrame(this.animationRun.bind(this,x))}end(){this.set(this.value.end)}expired(){return performance.now()>this.time.end}}var y1=F.from_html("<div></div>");function M0(x,j){F.push(j,!0);let q=F.rest_props(j,["$$slots","$$events","$$legacy"]),Q=j.id,h=j.style,G=j.content,Z={setDisplayed:g,getDisplayed:$,setSuppressed:P,setCollapsed:O,getCollapsed:I,setScale:s};function U(){return Z}let H,X=h.dimensions.width,z=h.dimensions.height,w=h.dimensions.radius,B=h.dimensions.padding??j0,y=h.colors?.border??i,T=h.colors?.background??a0,b=h.colors?.shadow??q0,W=F.state(!1),D=!1,N=!1;function g(V){if(V==F.get(W))return;if(F.set(W,V,!0),V==!0){if(G==null)return;if(N)return;if(D)return;D=!0,G(Q).then((S)=>{if(S instanceof HTMLElement)H.appendChild(S);else console.error("Failed to load pin content")}).catch((S)=>console.error(S)).finally(()=>{N=!0,D=!1})}if(V==!1)_.end()}function $(){return F.get(W)}let M=F.state(!0);function P(V){if(V==F.get(M))return;if(F.set(M,V,!0),V)m=k,_.set(k)}let Y=F.state(!0);function O(V){if(V==F.get(Y))return;F.set(Y,V,!0),_.target(F.get(Y)?0:m)}function I(){if(!F.get(W))return!0;return _.expired()}let m=k,_=new n({value:k,min:0,max:1,timespan:p0,easing:B1,callback:V0});function s(V){m=V,_.target(V)}function V0(V){H.style.scale=V.toString(),H.style.filter=`brightness(${t(V)})`}function t(V){return 0.25+0.75*V}var W0={invoke:U},f=y1();let a;return F.bind_this(f,(V)=>H=V,()=>H),F.template_effect((V)=>{F.set_class(f,1,F.clsx(["pin",F.get(W)&&"displayed",F.get(M)&&"suppressed"]),"svelte-e30vfn4rttu1"),a=F.set_style(f,"",a,V)},[()=>({width:`${X}px`,height:`${z}px`,"border-radius":`${w}px`,"border-color":y,"background-color":T,"border-width":`${B}px`,"box-shadow":b,scale:k,filter:`brightness(${t(k)})`})]),F.append(x,f),F.pop(W0)}class f0 extends v{width;height;zoom;component;constructor(x,j){super(x,new E(j,x.lat,x.lng,x.rank));let q=x.pin?.style.dimensions.width??L,Q=x.pin?.style.dimensions.height??L,h=x.pin?.style.dimensions.padding??j0,G=x.pin?.style.dimensions.radius??L/2;this.width=q,this.height=Q,this.zoom=NaN,this.component=N1(M0,{target:this.marker.div,props:{id:this.id,style:{dimensions:{width:q,height:Q,padding:h,radius:G},colors:x.pin?.style.colors},content:x.pin?.body}})}get zIndex(){if(Number.isNaN(this.zoom))return this.rank;return Math.round(-this.zoom*x0)+o0}}import{mount as T1}from"svelte";import"svelte/internal/disclose-version";import*as J from"svelte/internal/client";import{sineInOut as I1}from"svelte/easing";class h0{animating;animationTimestamp;animationEnd;animationCallback;speed;value;constructor(x){this.animating=!1,this.animationTimestamp=0,this.animationEnd=0,this.animationCallback=x.callback,this.speed={current:0,spring:{stiffness:x.stiffness,damping:2*Math.sqrt(x.stiffness)}},this.value={current:x.value,target:x.value,precision:x.precision,min:x.min,max:x.max}}animationFrame(){try{let x=performance.now(),j=x-this.animationTimestamp;if(this.animationTimestamp=x,x>=this.animationEnd){this.speed.current=0,this.value.current=this.value.target;return}let q=this.value.target-this.value.current;if(Math.abs(q)<this.value.precision){this.speed.current=0,this.value.current=this.value.target;return}let Q=q*this.speed.spring.stiffness-this.speed.spring.damping*this.speed.current;if(this.speed.current+=Q*j,this.value.current+=this.speed.current*j,this.value.current<this.value.min){this.value.current=this.value.target,this.speed.current=0;return}if(this.value.current>this.value.max){this.value.current=this.value.target,this.speed.current=0;return}}finally{if(this.animationCallback(this.value.current),this.value.current===this.value.target){this.animating=!1;return}window.requestAnimationFrame(this.animationFrame.bind(this))}}target(x){if(x===this.value.target)return;let j=Math.sqrt(2*Math.abs(x-this.value.current)/this.speed.spring.stiffness);if(this.animationEnd=performance.now()+j,this.value.target=x,this.animating)return;this.animating=!0,this.animationTimestamp=performance.now(),window.requestAnimationFrame(this.animationFrame.bind(this))}set(x){if(x===this.value.target)return;this.animationEnd=performance.now(),this.value.current=x,this.value.target=x,this.speed.current=0,window.requestAnimationFrame(this.animationCallback.bind(this,x))}end(){this.set(this.value.target)}expired(){return performance.now()>this.animationEnd}}import*as C0 from"@arenarium/maps-core/rectangle";var w1=J.from_html('<div><div class="element pointer svelte-17e81wb0tdtjd"></div> <div class="element tooltip svelte-17e81wb0tdtjd"><div class="element body svelte-17e81wb0tdtjd"></div></div></div>');function o(x,j){J.push(j,!0);let q=J.rest_props(j,["$$slots","$$events","$$legacy"]),Q=j.id,h=j.style,G=j.content,Z={setDisplayed:m,getDisplayed:_,setCollapsed:V0,getCollapsed:t,getExpanded:W0,setAngle:V1};function U(){return Z}let H,X=h.colors?.shadow??q0,z,w=Math.min(h.dimensions.width,h.dimensions.height)/Math.SQRT2-h.dimensions.margin,B=h.colors?.background??i,y=Math.max(1,h.dimensions.radius/w),T,b=h.dimensions.width+2*h.dimensions.margin,W=h.dimensions.height+2*h.dimensions.margin,D=h.dimensions.margin,N,g=h.dimensions.width,$=h.dimensions.height,M=h.dimensions.radius,P=h.colors?.background??i,Y=J.state(!1),O=!1,I=!1;function m(K){if(K==J.get(Y))return;if(J.set(Y,K,!0),K){if(G==null)return;if(I)return;if(O)return;O=!0,G(Q).then((C)=>{if(C instanceof HTMLElement)N.appendChild(C);else console.error("Failed to load tooltip content")}).catch((C)=>console.error(C)).finally(()=>{I=!0,O=!1})}if(K==!1)f.end(),Z0.end(),H0.end()}function _(){return J.get(Y)}let s=J.state(!0);function V0(K){if(K==J.get(s))return;J.set(s,K,!0),f.target(J.get(s)?0:1)}function t(){if(!J.get(Y))return!0;return f.expired()}function W0(){if(!J.get(Y))return!1;return f.expired()}let f=new n({value:0,min:0,max:1,timespan:n0,easing:I1,callback:a});function a(K){H.style.opacity=`${K}`,T.style.scale=`${K}`,z.style.scale=`${K}`}let V=NaN,S=J.state(!1),u0=-b/2,Z0=new h0({value:-b/2,min:-b,max:0,precision:1,stiffness:I0,callback:W1}),L0=-W/2,H0=new h0({value:-W/2,min:-W,max:0,precision:1,stiffness:I0,callback:Z1});function V1(K,C){if(Number.isNaN(K)){V=NaN,J.set(S,!1);return}if(J.get(S)==!1||C==!0){J.set(S,!0),V=K;let R=C0.offsets(b,W,K);Z0.set(Math.round(R.x)),H0.set(Math.round(R.y));return}if(V!=K){V=K;let R=C0.offsets(b,W,K);Z0.target(Math.round(R.x)),H0.target(Math.round(R.y));return}}function W1(K){u0=K,d0()}function Z1(K){L0=K,d0()}function d0(){let K=u0,C=L0,R=K+b/2,U0=C+W/2,Y0=W<b?R*W/b:R,X0=W>b?U0*b/W:U0,b1=Math.atan2(X0,Y0)/Math.PI*180-45,O0=Math.sqrt(Y0*Y0+X0*X0),l=Math.min(b,W)/2,U1=l*Math.SQRT2,z0=(O0-l)/(U1-l),E1=0,c1=22.5,i0=0+z0*22.5,Y1=O0<l?O0/l:1,X1=-D*(R/b)*z0,O1=-D*(U0/W)*z0;T.style.transform=`translate(${Math.round(K)}px, ${Math.round(C)}px)`,z.style.transform=`scale(${Y1}) rotate(${b1}deg) skew(${i0}deg, ${i0}deg)`,N.style.transform=`translate(${X1}px, ${O1}px)`}var H1={invoke:U},u=w1();let g0;var b0=J.child(u);let m0;J.bind_this(b0,(K)=>z=K,()=>z);var e=J.sibling(b0,2);let s0;var l0=J.child(e);let r0;return J.bind_this(l0,(K)=>N=K,()=>N),J.reset(e),J.bind_this(e,(K)=>T=K,()=>T),J.reset(u),J.bind_this(u,(K)=>H=K,()=>H),J.template_effect(()=>{J.set_class(u,1,J.clsx(["element anchor",J.get(Y)&&"displayed"]),"svelte-17e81wb0tdtjd"),g0=J.set_style(u,"",g0,{filter:`drop-shadow(${X})`}),m0=J.set_style(b0,"",m0,{width:`${w}px`,height:`${w}px`,"background-color":B,"border-radius":`${y}px`}),s0=J.set_style(e,"",s0,{width:`${b}px`,height:`${W}px`,padding:`${D}px`}),r0=J.set_style(l0,"",r0,{width:`${g}px`,height:`${$}px`,"border-radius":`${M}px`,"background-color":P})}),J.append(x,u),J.pop(H1)}class R0 extends v{width;height;zoom;angle;states;component;constructor(x,j){super(x,new E(j,x.lat,x.lng,x.rank));this.width=x.tooltip.style.dimensions.width+x.tooltip.style.dimensions.margin*2,this.height=x.tooltip.style.dimensions.height+x.tooltip.style.dimensions.margin*2,this.zoom=NaN,this.angle=NaN,this.states=[],this.component=T1(o,{target:this.marker.div,props:{id:this.id,style:x.tooltip.style,content:x.tooltip.body}})}get zIndex(){if(Number.isNaN(this.zoom))return this.rank;return Math.round(-this.zoom*x0)+t0}}import{mount as D1}from"svelte";class A0 extends v{width;height;margin;angle;component;constructor(x,j){if(x.popup==null)throw Error("Failed to create popup");super(x,new E(j,x.lat,x.lng,w0));this.width=x.popup.style.dimensions.width,this.height=x.popup.style.dimensions.height,this.margin=x.popup.style.dimensions.margin,this.angle=NaN,this.shown=!1,this.component=D1(o,{target:this.marker.div,props:{id:this.id,style:x.popup.style,content:x.popup.body}})}get zIndex(){return w0}}class S0{id;state=void 0;pin;tooltip;popup;constructor(x,j){if(this.id=x.id,this.pin=new f0(x,j),this.tooltip=new R0(x,j),x.popup!=null)this.popup=new A0(x,j)}}var v0=4;class $0{pins=new Set;pinMaxWidth=0;pinMaxHeight=0;pinFade=!1;pinZoomMax=v0;pinZoomDelta=v0;set configuration(x){this.pinFade=x?.pin?.fade??!0,this.pinZoomMax=x?.pin?.maxZoom??v0,this.pinZoomDelta=this.pinZoomMax}insert(x,j){this.update(x,j),this.pins.add(x)}update(x,j){x.zoom=j?j[0]:NaN,x.marker.update(x.zIndex)}remove(x){x.shown=!0,x.zoom=NaN,x.component.invoke().setCollapsed(!1),x.component.invoke().setSuppressed(!0),x.component.invoke().setDisplayed(!1),x.marker.update(x.zIndex),x.marker.remove(),this.pins.delete(x)}clear(){this.pins.forEach((x)=>x.marker.remove()),this.pins.clear()}refresh(){let x=Array.from(this.pins);this.pinMaxWidth=x.reduce((j,q)=>Math.max(j,q.width),0),this.pinMaxHeight=x.reduce((j,q)=>Math.max(j,q.height),0),this.pinZoomDelta=Math.max(1,this.pinZoomMax-Math.log10(x.length))}render(x,j){let q=x.zoom,Q=j.mapSize,h=A.offset(x,Q,{top:this.pinMaxHeight,bottom:this.pinMaxHeight,right:this.pinMaxWidth,left:this.pinMaxWidth});for(let G of this.pins)if(h.contains(G.lat,G.lng)){if(Number.isNaN(G.zoom))G.component.invoke().setDisplayed(!0),G.component.invoke().setSuppressed(!0),G.component.invoke().setCollapsed(!1),G.marker.insert();else if(G.component.invoke().setSuppressed(!1),G.shown&&q<G.zoom&&G.zoom<q+this.pinZoomDelta)G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setScale(this.pinFade?Math.max(0,1-(G.zoom-q)*0.2):1),G.marker.insert();else if(G.component.invoke().setCollapsed(!0),G.component.invoke().getCollapsed())G.component.invoke().setDisplayed(!1),G.marker.remove()}else G.component.invoke().setDisplayed(!1),G.marker.remove()}}import*as Q1 from"@arenarium/maps-core/angles";class P0{tooltips=new Set;tooltipMaxWidth=0;tooltipMaxHeight=0;insert(x,j){this.update(x,j),this.tooltips.add(x)}update(x,j){if(j)x.zoom=j[0],x.states=j[1].map((q)=>[q[0],Q1.values[q[1]]]);else x.zoom=NaN,x.states=[];x.marker.update(x.zIndex)}remove(x){x.shown=!0,x.zoom=NaN,x.angle=NaN,x.states=[],x.component.invoke().setAngle(NaN),x.component.invoke().setCollapsed(!0),x.component.invoke().setDisplayed(!1),x.marker.update(x.zIndex),x.marker.remove(),this.tooltips.delete(x)}clear(){this.tooltips.forEach((x)=>x.marker.remove()),this.tooltips.clear()}refresh(){let x=Array.from(this.tooltips);this.tooltipMaxWidth=x.reduce((j,q)=>Math.max(j,q.width),0),this.tooltipMaxHeight=x.reduce((j,q)=>Math.max(j,q.height),0)}render(x,j){let q=x.zoom,Q=j.mapSize,h=A.offset(x,Q,{top:this.tooltipMaxHeight,bottom:this.tooltipMaxHeight,right:this.tooltipMaxWidth,left:this.tooltipMaxWidth});for(let G of this.tooltips)if(h.contains(G.lat,G.lng)){if(Number.isNaN(G.zoom)==!1&&G.shown&&G.zoom<=q){let Z=G.states.findLast((U)=>U[0]<=q)?.[1];if(Z==null)throw Error("Angle not found");G.angle=Z,G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setAngle(Z),G.marker.insert()}else if(G.component.invoke().setCollapsed(!0),G.component.invoke().getCollapsed())G.component.invoke().setDisplayed(!1),G.marker.remove()}else G.component.invoke().setDisplayed(!1),G.marker.remove()}}import*as J0 from"@arenarium/maps-core/mercator";import*as G1 from"@arenarium/maps-core/rectangle";class _0{popups=new Set;pan=!0;set configuration(x){this.pan=x?.popup?.pan??!0}insert(x){this.popups.add(x)}remove(x){x.angle=NaN,x.shown=!1,x.marker.remove(),x.component.invoke().setAngle(NaN),x.component.invoke().setCollapsed(!0),x.component.invoke().setDisplayed(!1),this.popups.delete(x)}clear(){this.popups.forEach((x)=>x.marker.remove()),this.popups.clear()}show(x,j){if(!x.popup||!x.tooltip||!x.pin)return;if(x.pin.shown=!1,x.tooltip.shown=!1,x.popup.angle=x.tooltip.angle,x.popup.shown=!0,this.pan==!1)return;let q=x.popup,Q=j.getViewport(),h=Q.bounds,G=Q.zoom,U=j.getParameters().mapSize*Math.pow(2,G),H=J0.project(h.ne.lat,h.sw.lng,U),X=J0.project(h.sw.lat,h.ne.lng,U),z=X.x-H.x,w=X.y-H.y,B=q.width+q.margin*8,y=q.height+q.margin*8,T=J0.project(q.lat,q.lng,U),b=G1.offsets(B,y,x.tooltip.angle),W=T.x+b.x,D=W+B,N=T.y+b.y,g=N+y,$=W-H.x,M=X.x-D,P=N-H.y,Y=X.y-g,O=0;if(z<B)O=($-M)/2;else{if($<0)O=$;if(M<0)O=-M}let I=0;if(w<y)I=(P-Y)/2;else{if(P<0)I=P;if(Y<0)I=-Y}if(O!=0||I!=0)j.panBy(O,I)}hide(x){if(!x.popup||!x.tooltip||!x.pin)return;x.pin.shown=!0,x.tooltip.shown=!0,x.popup.shown=!1}render(){for(let x of this.popups)if(x.shown)x.component.invoke().setDisplayed(!0),x.component.invoke().setCollapsed(!1),x.component.invoke().setAngle(x.angle,!0),x.marker.insert();else if(x.component.invoke().setCollapsed(!0),x.component.invoke().getCollapsed())x.component.invoke().setDisplayed(!1),x.marker.remove()}}class k0{mapProvider;pinManager;tooltipManager;popupManager;elementsStore;constructor(x){this.mapProvider=x,this.pinManager=new $0,this.tooltipManager=new P0,this.popupManager=new _0,this.elementsStore=new Map}set configuration(x){this.pinManager.configuration=x,this.popupManager.configuration=x}clearElements(){this.elementsStore.clear(),this.pinManager.clear(),this.tooltipManager.clear(),this.popupManager.clear()}removeElements(x){for(let j of x){let q=this.elementsStore.get(j.data.id);if(q==null)continue;if(this.pinManager.remove(q.pin),this.tooltipManager.remove(q.tooltip),q.popup!=null)this.popupManager.remove(q.popup)}this.pinManager.refresh(),this.tooltipManager.refresh()}updateElements(x){for(let j of x){let q=this.elementsStore.get(j.data.id);if(q==null)continue;this.pinManager.update(q.pin,j.state),this.tooltipManager.update(q.tooltip,j.state)}}insertElements(x,j){for(let q of x){let Q=this.elementsStore.get(q.data.id);if(Q==null)Q=new S0(q.data,this.mapProvider),Q.tooltip.marker.div.addEventListener("click",(h)=>j(h,q.data.id)),this.elementsStore.set(q.data.id,Q);if(this.pinManager.insert(Q.pin,q.state),this.tooltipManager.insert(Q.tooltip,q.state),Q.popup!=null)this.popupManager.insert(Q.popup)}this.pinManager.refresh(),this.tooltipManager.refresh()}renderElements(x,j){this.popupManager.render(),this.tooltipManager.render(x,j),this.pinManager.render(x,j)}showPopup(x){let j=this.elementsStore.values();for(let q of j)if(q.id==x)this.popupManager.show(q,this.mapProvider);else this.popupManager.hide(q)}hidePopup(x){let j=this.elementsStore.get(x);if(j==null)return;this.popupManager.hide(j)}hidePopups(){let x=this.elementsStore.values();for(let j of x)this.popupManager.hide(j)}}import*as h1 from"@arenarium/maps-core/http";import*as J1 from"@arenarium/maps-core/hash";import*as F0 from"@arenarium/maps-core/angles";var M1="https://maps.api.arenarium.dev/states",f1=3,C1=500;class E0{apiKey;apiJwt;apiDevEnvironment;markerStatesStore;constructor(x,j){this.apiKey=x,this.apiJwt=j,this.apiDevEnvironment=window?.location.host.startsWith("localhost")||window?.location.host.startsWith("127.0.0.1"),this.markerStatesStore=new Map}clearStates(){this.markerStatesStore.clear()}resetStates(x){for(let j=0;j<x.length;j++){let q=x[j];q.state=void 0}}async updateStates(x,j){if(x.length==0)return;x.sort((G,Z)=>G.data.id.localeCompare(Z.data.id));let q=x.map((G)=>G.input),Q=J1.object(q),h=this.markerStatesStore.get(Q);if(h==null)h=await this.fetchStates(q,j),this.markerStatesStore.set(Q,h);for(let G=0;G<x.length;G++){let Z=x[G];Z.state=h[G]}}async fetchStates(x,j){if(x.length==0)return[];if(x.length==1)return[[0,[[0,F0.values.indexOf(F0.initial)]]]];let q={key:this.apiKey,jwt:this.apiJwt,input:x,parameters:j},Q=await h1.post(M1,q,{headers:{"Cache-Control":this.apiDevEnvironment?"no-cache":""}},f1,C1);if(Q.jwt)this.apiJwt=Q.jwt;return Q.states}}import*as K0 from"@arenarium/maps-core/http";import{apiKeySchema as R1,apiJwtSchema as A1,mapMarkerDataSchema as S1,mapProviderSchema as v1}from"@arenarium/maps-core/schemas";import*as c from"valibot";var F1="1.2.13",$1="https://maps.api.arenarium.dev/auth",P1="https://maps.api.arenarium.dev/log",K1=500,_1=500;class c0{apiKey;mapProvider;mapEventProvider;markers;markerVisibilityManager;markerElementsManager;markerStatesManager;markerVisibilityProcessor;markerElementsProcessor;markerStateProcessor;markerStatesProcessDelay=500;markerStatesProcessTimeout=void 0;constructor(x,j,q,Q){c.parse(R1,x),c.parse(A1,j),c.parse(v1,q),this.apiKey=x,this.mapProvider=q,this.mapEventProvider=new N0(this.mapProvider,this.detached.bind(this),this.error.bind(this),this.onMapMove.bind(this),this.onMapIdle.bind(this),this.onMapClick.bind(this)),this.markers=new Map,this.markerVisibilityManager=new D0(this.mapProvider),this.markerElementsManager=new k0(this.mapProvider),this.markerStatesManager=new E0(x,j),this.markerVisibilityProcessor=new r(this.onMapMarkerVisiblityProcess.bind(this),K1),this.markerElementsProcessor=new r(this.onMapMarkerRenderProcess.bind(this),K1),this.markerStateProcessor=new r(this.onMapMarkerStateProcess.bind(this)),this.configuration=Q}static async create(x,j,q){let G=(await K0.post($1,{key:x,version:F1})).jwt;if(!G)throw Error("Failed to get api jwt");return new c0(x,G,j,q)}set configuration(x){this.markerStatesProcessDelay=x?.process?.states?.delay??_1,this.markerVisibilityManager.configuration=x,this.markerElementsManager.configuration=x}clear(){this.markers.clear(),this.markerVisibilityManager.clearMarkers(),this.markerStatesManager.clearStates(),this.markerElementsManager.clearElements(),this.mapEventProvider.stop(),this.markerVisibilityProcessor.stop(),this.markerStateProcessor.stop(),this.markerElementsProcessor.stop()}detached(){return this.mapProvider.getContainer().parentElement==null}error(x,j){this.log("error",x,j),this.configuration?.events?.error?.(x,j)}async log(x,j,q){switch(x){case"info":console.info(q);break;case"warning":console.warn(q);break;case"error":console.error(q);break}if(q instanceof Error==!1)return;try{let Q={key:this.apiKey,title:j,level:x,content:{version:F1,name:q.name,message:q.message,cause:q.cause,stack:q.stack}};await K0.put(P1,Q)}catch(Q){console.error(Q)}}onMapMove(){this.markerVisibilityProcessor.start()}onMapIdle(){if(this.markerStatesProcessTimeout)window.clearTimeout(this.markerStatesProcessTimeout);this.markerStatesProcessTimeout=window.setTimeout(()=>{this.markerStateProcessor.start()},this.markerStatesProcessDelay)}onMapClick(){this.hidePopup()}onMapMarkerClick(x,j){x.stopPropagation(),this.showPopup(j)}async onMapMarkerVisiblityProcess(){try{if(this.detached())return!0;let x=this.mapProvider.getViewport(),j=this.mapProvider.getParameters(),q=new Set(this.markerVisibilityManager.getMarkers());this.markerVisibilityManager.updateMarkers(x,j);let Q=new Set(this.markerVisibilityManager.getMarkers()),h=Array.from(q.difference(Q)),G=Array.from(Q.difference(q));return this.markerStatesManager.resetStates(h),this.markerElementsManager.removeElements(h),this.markerElementsManager.insertElements(G,this.onMapMarkerClick.bind(this)),this.markerElementsProcessor.start(),!1}catch(x){return this.clear(),this.error("Failed to process map move",x),!0}}async onMapMarkerStateProcess(){try{if(this.detached())return!0;let x=this.markerVisibilityManager.getMarkers(),j=this.mapProvider.getParameters();return await this.markerStatesManager.updateStates(x,j),this.markerElementsManager.updateElements(x),this.markerElementsProcessor.start(),!1}catch(x){return this.clear(),this.error("Failed to process map idle",x),!0}}async onMapMarkerRenderProcess(){try{if(this.detached())return!0;let x=this.mapProvider.getViewport(),j=this.mapProvider.getParameters();return this.markerElementsManager.renderElements(x,j),!1}catch(x){return this.clear(),this.error("Failed to process map render",x),!0}}updateMarkers(x){c.parse(c.array(S1),x);try{for(let q of x)if(this.markers.has(q.id)==!1)this.markers.set(q.id,new B0(q));let j=Array.from(this.markers.values());j.sort((q,Q)=>Q.data.rank-q.data.rank),this.markerVisibilityManager.insertMarkers(j),this.mapEventProvider.start(),this.markerVisibilityProcessor.start(),this.markerStateProcessor.start(),this.markerElementsProcessor.start()}catch(j){throw this.clear(),this.error("Failed to update markers",j),j}}removeMarkers(){try{this.clear()}catch(x){throw this.error("Failed to remove markers",x),x}}showPopup(x){if(this.detached())return;if(this.markers.size==0)return;try{this.markerElementsManager.showPopup(x)}catch(j){throw this.markerElementsManager.hidePopups(),this.error("Failed to show popup",j),j}finally{this.markerElementsProcessor.start()}}hidePopup(){if(this.detached())return;if(this.markers.size==0)return;try{this.markerElementsManager.hidePopups()}catch(x){throw this.error("Failed to hide popup",x),x}finally{this.markerElementsProcessor.start()}}}export{c0 as MapManager};
1
+ class r{endtime=0;lifespan;paused=!1;enqueued=!1;interval;timeout;callback;constructor(x,j,q){if((j??0)<0)throw Error("Lifespan must be greater than 0");if((q??0)<0)throw Error("Interval must be greater than 0");let Q=navigator?.hardwareConcurrency?200/navigator.hardwareConcurrency:100;this.interval=q??Q;let h=this.interval;this.lifespan=j??h,this.callback=x}async run(){let x=performance.now();if(this.enqueued)this.endtime=x+this.lifespan,this.enqueued=!1;if(this.endtime<x){this.stop();return}if(this.paused==!1){if(await this.callback()&&!this.enqueued){this.stop();return}}this.timeout=window.setTimeout(this.run.bind(this),this.interval)}start(){if(this.enqueued=!0,!this.timeout)this.run()}stop(){if(this.timeout)window.clearTimeout(this.timeout);this.timeout=void 0}pause(){this.paused=!0}resume(){this.paused=!1}}class y0{data;state;constructor(x){this.data=x,this.state=void 0}get input(){return{id:this.data.id,rank:this.data.rank,lat:this.data.lat,lng:this.data.lng,width:this.data.tooltip.style.dimensions.width,height:this.data.tooltip.style.dimensions.height,margin:this.data.tooltip.style.dimensions.margin}}}class z0{callback;timeout;id;constructor(x,j){if(j<=0)throw Error("Timeout must be greater than 0");this.callback=x,this.timeout=j}start(){if(this.id!=null)return;this.id=window.setInterval(this.callback,this.timeout)}stop(){if(this.id==null)return;window.clearInterval(this.id),this.id=void 0}}var B1=100;class N0{viewport=void 0;state="idle";provider;interval;onCancel;onError;onMove;onIdle;onClick;constructor(x,j,q,Q,h,G){this.provider=x,this.interval=new z0(this.onInterval.bind(this),B1/(navigator?.hardwareConcurrency??1)),this.onCancel=j,this.onError=q,this.onMove=Q,this.onIdle=h,this.onClick=G}start(){this.interval.start(),this.provider.getContainer().addEventListener("click",this.onClick.bind(this))}stop(){this.interval.stop(),this.provider.getContainer().removeEventListener("click",this.onClick.bind(this))}onInterval(){try{if(this.onCancel()){this.interval.stop();return}let x=this.provider.getViewport(),j=this.state,q=JSON.stringify(x)!==JSON.stringify(this.viewport)?"move":"idle";if(q=="move")this.onMove();if(q=="idle"&&j=="move")this.onIdle();this.state=q,this.viewport=x}catch(x){this.onError("Failed to process map state interval",x)}}}var p0=75,n0=150,I0=0.00025,o0=1e6,t0=2000000,w0=3000000,x0=10,L=16,j0=2,k=0.5,i="white",a0="darkgreen",q0="0px 2px 2px rgba(0, 0, 0, 0.5)";import*as d from"@arenarium/maps-core/mercator";class p{sw;ne;constructor(x,j,q,Q){if(q<x)throw Error(`Invalid bounds: ${x}, ${j}, ${q}, ${Q}`);if(Q<j)throw Error(`Invalid bounds: ${x}, ${j}, ${q}, ${Q}`);this.sw={lat:x,lng:j},this.ne={lat:q,lng:Q}}contains(x,j){if(x<this.sw.lat||this.ne.lat<x)return!1;if(j<this.sw.lng||this.ne.lng<j)return!1;return!0}intersects(x){if(x.ne.lat<this.sw.lat||this.ne.lat<x.sw.lat)return!1;if(x.ne.lng<this.sw.lng||this.ne.lng<x.sw.lng)return!1;return!0}}class A{blockL;blockR;sw;ne;constructor(x,j,q,Q){if(q<x)throw Error(`Invalid bounds: ${x}, ${j}, ${q}, ${Q}`);if(this.sw={lat:x,lng:j},this.ne={lat:q,lng:Q},j<Q)this.blockL=new p(x,j,q,Q),this.blockR=new p(0,0,0,0);else this.blockL=new p(x,-180,q,Q),this.blockR=new p(x,j,q,180)}static normalize(x){let{bounds:j,center:q}=x;if(Math.abs(j.ne.lng-q.lng)+Math.abs(j.sw.lng-q.lng)>360)j.sw.lng=-180,j.ne.lng=180;if(j.ne.lng-j.sw.lng>360){j.sw.lng=-180,j.ne.lng=180;return}if(j.sw.lng<-180)j.sw.lng+=360;if(j.sw.lng>180)j.sw.lng-=360;if(j.ne.lng<-180)j.ne.lng+=360;if(j.ne.lng>180)j.ne.lng-=360}static bounds(x){this.normalize(x);let j=x.bounds,q=j.sw,Q=j.ne;return new A(q.lat,q.lng,Q.lat,Q.lng)}static offset(x,j,q){this.normalize(x);let{bounds:Q,zoom:h}=x,G=j*Math.pow(2,h),Z=d.project(Q.sw.lat,Q.sw.lng,G),U=d.project(Q.ne.lat,Q.ne.lng,G),H=Math.max(Z.x-q.left,0),X=Math.min(Z.y+q.bottom,G),B=Math.min(U.x+q.right,G),w=Math.max(U.y-q.top,0),y=d.unproject(H,X,G),z=d.unproject(B,w,G);return new A(y.lat,y.lng,z.lat,z.lng)}contains(x,j){return this.blockL.contains(x,j)||this.blockR.contains(x,j)}intersects(x){return this.blockL.intersects(x)||this.blockR.intersects(x)}}class T0{id;bounds;markers;constructor(x,j){this.id=x,this.bounds=j,this.markers=[]}belongs(x){let j=this.bounds.sw;if(x.lat<j.lat)return!1;if(x.lng<j.lng)return!1;let q=this.bounds.ne;if(q.lat<x.lat)return!1;if(q.lng<x.lng)return!1;return!0}neighbours(x,j){let q=Math.abs(x.id.length-this.id.length);if(q>j)return!1;let Q=Math.min(this.id.length,x.id.length)-j+q;for(let h=0;h<Q;h++)if(this.id[h]!=x.id[h])return!1;return!0}}class Q0{tree;zoom;cell;branches;constructor(x,j,q,Q){this.tree=x,this.zoom=q,this.cell=new T0(j,Q),this.branches=[]}split(){let x=this.cell.bounds,j=Math.pow(2,this.tree.depth),q=(x.ne.lat-x.sw.lat)/j,Q=(x.ne.lng-x.sw.lng)/j;for(let h=0;h<j;h++)for(let G=0;G<j;G++){let Z=x.sw.lat+h*q,U=x.sw.lng+G*Q,H=Z+q,X=U+Q;this.branches.push(new Q0(this.tree,`${this.cell.id}${h*2+G}`,this.zoom+this.tree.depth,{sw:{lat:Z,lng:U},ne:{lat:H,lng:X}}))}}add(x){if(this.cell.belongs(x.data)==!1)return!1;if(this.cell.markers.length<this.tree.capacity)return this.cell.markers.push(x),!0;if(this.branches.length==0)this.split();for(let j=0;j<this.branches.length;j++)if(this.branches[j].add(x))return!0;throw Error("Failed to add marker to branch")}compact(){if(this.branches.length==0)return;for(let Q=0;Q<this.branches.length;Q++)this.branches[Q].compact();let x=[],j=[];for(let Q=0;Q<this.branches.length;Q++){let h=this.branches[Q];x.push(...h.branches),j.push(...h.cell.markers)}let q=new Q0(this.tree,this.cell.id,this.zoom+this.tree.depth,this.cell.bounds);q.branches=x,q.cell.markers=j,this.branches=[q]}cells(x,j,q){if(x<this.zoom)return q;if(j.intersects(this.cell.bounds)==!1)return q;q.push(this.cell);for(let Q=0;Q<this.branches.length;Q++)this.branches[Q].cells(x,j,q);return q}print(x){console.log(`${"---".repeat(x)}|${this.cell.id} zoom=[${this.zoom}] markers=[${this.cell.markers.length}]`);for(let j=0;j<this.branches.length;j++)this.branches[j].print(x+1)}count(){return this.cell.markers.length+this.branches.reduce((x,j)=>x+j.count(),0)}}class G0{capacity;depth;root;constructor(x,j,q){this.capacity=q,this.depth=j,this.root=new Q0(this,"R",x,{sw:{lat:-90,lng:-180},ne:{lat:90,lng:180}})}add(x){return this.root.add(x)}compact(){this.root.compact()}cells(x,j){let q=[];return this.root.cells(x,j,q),q}print(){this.root.print(0)}}var e0=2,x1=1,j1=L*4,q1=1024;class D0{mapProvider;markersVisibilityTree;markersVisible;markerTreeCellCapacity=e0;markerTreeCellZoomDelta=x1;markerTreeCellSize=j1;markerTreeLimit=q1;constructor(x){this.mapProvider=x}set configuration(x){this.markerTreeCellCapacity=x?.process?.visibility?.cell?.capacity??e0,this.markerTreeCellZoomDelta=x?.process?.visibility?.cell?.depth??x1,this.markerTreeCellSize=x?.process?.visibility?.cell?.size??j1,this.markerTreeLimit=x?.process?.visibility?.limit??q1}getMarkers(){return Array.from(this.markersVisible??[])}insertMarkers(x){this.markersVisibilityTree=this.createTree(x)}clearMarkers(){this.markersVisibilityTree=void 0,this.markersVisible=void 0}updateMarkers(x,j){if(this.markersVisibilityTree==null)return;let q=A.bounds(x),Q=[],h=x.zoom;while(h<j.zoomMax&&Q.length<this.markerTreeLimit)Q=this.markersVisibilityTree.cells(h,q).flatMap((G)=>G.markers),h++;this.markersVisible=Q}createTree(x){if(x.length<this.markerTreeLimit){let j=new G0(0,0,x.length);for(let q=0;q<x.length;q++){let Q=x[q];if(!j.add(Q))throw Error("Failed to add marker to fill tree")}return j}else{let j=-Math.floor(Math.log2(this.mapProvider.getParameters().mapSize/this.markerTreeCellSize)),q=new G0(j,this.markerTreeCellZoomDelta,this.markerTreeCellCapacity);for(let h=0;h<x.length;h++){let G=x[h];if(!q.add(G))throw Error("Failed to add marker to fill tree")}let Q=-j;for(let h=0;h<Q;h++)q.compact();return q}}}import{mount as N1}from"svelte";class E{div;marker;constructor(x,j,q,Q){this.div=document.createElement("div"),this.marker=x.createMarker(this.div,j,q,Q)}insert(){if(this.marker.inserted()==!0)return;this.marker.insert()}remove(){if(this.marker.inserted()==!1)return;this.marker.remove()}update(x){this.marker.update(x)}}class v{shown;id;lat;lng;rank;marker;constructor(x,j){if(new.target===v)throw Error("Cannot instantiate an abstract class directly.");this.shown=!0,this.id=x.id,this.lat=x.lat,this.lng=x.lng,this.rank=x.rank,this.marker=j}}import"svelte/internal/disclose-version";import*as F from"svelte/internal/client";import{sineInOut as y1}from"svelte/easing";class n{animationEasing;animationRun;animating;value;time;constructor(x){if(x.max<=x.min)throw Error("Min must be less than max");if(x.value<x.min||x.max<x.value)throw Error("Value must be between min and max");this.animationEasing=x.easing,this.animationRun=x.callback,this.animating=!1,this.value={current:x.value,start:x.value,end:x.value,min:x.min,max:x.max},this.time={start:0,end:0,span:x.timespan}}animationFrame(){let x=performance.now();if(x>this.time.end)this.value.current=this.value.end;else{let j=(x-this.time.start)/(this.time.end-this.time.start),q=this.animationEasing(j);this.value.current=this.value.start+(this.value.end-this.value.start)*q}if(this.animationRun(this.value.current),this.value.current===this.value.end){this.animating=!1;return}window.requestAnimationFrame(this.animationFrame.bind(this))}target(x){if(x===this.value.end)return;this.value.start=this.value.current,this.value.end=x;let j=performance.now(),q=Math.abs(this.value.start-this.value.end),Q=this.value.max-this.value.min;if(this.time.start=j,this.time.end=j+this.time.span*Math.sqrt(q/Q),this.animating)return;this.animating=!0,window.requestAnimationFrame(this.animationFrame.bind(this))}set(x){if(x===this.value.end)return;this.value.current=x,this.value.start=x,this.value.end=x;let j=performance.now();this.time.start=j,this.time.end=j,window.requestAnimationFrame(this.animationRun.bind(this,x))}end(){this.set(this.value.end)}expired(){return performance.now()>this.time.end}}var z1=F.from_html("<div></div>");function M0(x,j){F.push(j,!0);let q=F.rest_props(j,["$$slots","$$events","$$legacy"]),Q=j.id,h=j.style,G=j.content,Z={setDisplayed:g,getDisplayed:$,setSuppressed:P,setCollapsed:O,getCollapsed:I,setScale:s};function U(){return Z}let H,X=h.dimensions.width,B=h.dimensions.height,w=h.dimensions.radius,y=h.dimensions.padding??j0,z=h.colors?.border??i,T=h.colors?.background??a0,b=h.colors?.shadow??q0,W=F.state(!1),D=!1,N=!1;function g(V){if(V==F.get(W))return;if(F.set(W,V,!0),V==!0){if(G==null)return;if(N)return;if(D)return;D=!0,G(Q).then((S)=>{if(S instanceof HTMLElement)H.appendChild(S);else console.error("Failed to load pin content")}).catch((S)=>console.error(S)).finally(()=>{N=!0,D=!1})}if(V==!1)_.end()}function $(){return F.get(W)}let M=F.state(!0);function P(V){if(V==F.get(M))return;if(F.set(M,V,!0),V)m=k,_.set(k)}let Y=F.state(!0);function O(V){if(V==F.get(Y))return;F.set(Y,V,!0),_.target(F.get(Y)?0:m)}function I(){if(!F.get(W))return!0;return _.expired()}let m=k,_=new n({value:k,min:0,max:1,timespan:p0,easing:y1,callback:V0});function s(V){m=V,_.target(V)}function V0(V){H.style.scale=V.toString(),H.style.filter=`brightness(${t(V)})`}function t(V){return 0.25+0.75*V}var W0={invoke:U},f=z1();let a;return F.bind_this(f,(V)=>H=V,()=>H),F.template_effect((V)=>{F.set_class(f,1,F.clsx(["pin",F.get(W)&&"displayed",F.get(M)&&"suppressed"]),"svelte-e30vfn4rttu1"),a=F.set_style(f,"",a,V)},[()=>({width:`${X}px`,height:`${B}px`,"border-radius":`${w}px`,"border-color":z,"background-color":T,"border-width":`${y}px`,"box-shadow":b,scale:k,filter:`brightness(${t(k)})`})]),F.append(x,f),F.pop(W0)}class f0 extends v{width;height;zoom;component;constructor(x,j){super(x,new E(j,x.lat,x.lng,x.rank));let q=x.pin?.style.dimensions.width??L,Q=x.pin?.style.dimensions.height??L,h=x.pin?.style.dimensions.padding??j0,G=x.pin?.style.dimensions.radius??L/2;this.width=q,this.height=Q,this.zoom=NaN,this.component=N1(M0,{target:this.marker.div,props:{id:this.id,style:{dimensions:{width:q,height:Q,padding:h,radius:G},colors:x.pin?.style.colors},content:x.pin?.body}})}get zIndex(){if(Number.isNaN(this.zoom))return this.rank;return Math.round(-this.zoom*x0)+o0}}import{mount as T1}from"svelte";import"svelte/internal/disclose-version";import*as J from"svelte/internal/client";import{sineInOut as I1}from"svelte/easing";class h0{animating;animationTimestamp;animationEnd;animationCallback;speed;value;constructor(x){this.animating=!1,this.animationTimestamp=0,this.animationEnd=0,this.animationCallback=x.callback,this.speed={current:0,spring:{stiffness:x.stiffness,damping:2*Math.sqrt(x.stiffness)}},this.value={current:x.value,target:x.value,precision:x.precision,min:x.min,max:x.max}}animationFrame(){try{let x=performance.now(),j=x-this.animationTimestamp;if(this.animationTimestamp=x,x>=this.animationEnd){this.speed.current=0,this.value.current=this.value.target;return}let q=this.value.target-this.value.current;if(Math.abs(q)<this.value.precision){this.speed.current=0,this.value.current=this.value.target;return}let Q=q*this.speed.spring.stiffness-this.speed.spring.damping*this.speed.current;if(this.speed.current+=Q*j,this.value.current+=this.speed.current*j,this.value.current<this.value.min){this.value.current=this.value.target,this.speed.current=0;return}if(this.value.current>this.value.max){this.value.current=this.value.target,this.speed.current=0;return}}finally{if(this.animationCallback(this.value.current),this.value.current===this.value.target){this.animating=!1;return}window.requestAnimationFrame(this.animationFrame.bind(this))}}target(x){if(x===this.value.target)return;let j=Math.sqrt(2*Math.abs(x-this.value.current)/this.speed.spring.stiffness);if(this.animationEnd=performance.now()+j,this.value.target=x,this.animating)return;this.animating=!0,this.animationTimestamp=performance.now(),window.requestAnimationFrame(this.animationFrame.bind(this))}set(x){if(x===this.value.target)return;this.animationEnd=performance.now(),this.value.current=x,this.value.target=x,this.speed.current=0,window.requestAnimationFrame(this.animationCallback.bind(this,x))}end(){this.set(this.value.target)}expired(){return performance.now()>this.animationEnd}}import*as C0 from"@arenarium/maps-core/rectangle";var w1=J.from_html('<div><div class="element pointer svelte-17e81wb0tdtjd"></div> <div class="element tooltip svelte-17e81wb0tdtjd"><div class="element body svelte-17e81wb0tdtjd"></div></div></div>');function o(x,j){J.push(j,!0);let q=J.rest_props(j,["$$slots","$$events","$$legacy"]),Q=j.id,h=j.style,G=j.content,Z={setDisplayed:m,getDisplayed:_,setCollapsed:V0,getCollapsed:t,getExpanded:W0,setAngle:V1};function U(){return Z}let H,X=h.colors?.shadow??q0,B,w=Math.min(h.dimensions.width,h.dimensions.height)/Math.SQRT2-h.dimensions.margin,y=h.colors?.background??i,z=Math.max(1,h.dimensions.radius/w),T,b=h.dimensions.width+2*h.dimensions.margin,W=h.dimensions.height+2*h.dimensions.margin,D=h.dimensions.margin,N,g=h.dimensions.width,$=h.dimensions.height,M=h.dimensions.radius,P=h.colors?.background??i,Y=J.state(!1),O=!1,I=!1;function m(K){if(K==J.get(Y))return;if(J.set(Y,K,!0),K){if(G==null)return;if(I)return;if(O)return;O=!0,G(Q).then((C)=>{if(C instanceof HTMLElement)N.appendChild(C);else console.error("Failed to load tooltip content")}).catch((C)=>console.error(C)).finally(()=>{I=!0,O=!1})}if(K==!1)f.end(),Z0.end(),H0.end()}function _(){return J.get(Y)}let s=J.state(!0);function V0(K){if(K==J.get(s))return;J.set(s,K,!0),f.target(J.get(s)?0:1)}function t(){if(!J.get(Y))return!0;return f.expired()}function W0(){if(!J.get(Y))return!1;return f.expired()}let f=new n({value:0,min:0,max:1,timespan:n0,easing:I1,callback:a});function a(K){H.style.opacity=`${K}`,T.style.scale=`${K}`,B.style.scale=`${K}`}let V=NaN,S=J.state(!1),u0=-b/2,Z0=new h0({value:-b/2,min:-b,max:0,precision:1,stiffness:I0,callback:W1}),L0=-W/2,H0=new h0({value:-W/2,min:-W,max:0,precision:1,stiffness:I0,callback:Z1});function V1(K,C){if(Number.isNaN(K)){V=NaN,J.set(S,!1);return}if(J.get(S)==!1||C==!0){J.set(S,!0),V=K;let R=C0.offsets(b,W,K);Z0.set(Math.round(R.x)),H0.set(Math.round(R.y));return}if(V!=K){V=K;let R=C0.offsets(b,W,K);Z0.target(Math.round(R.x)),H0.target(Math.round(R.y));return}}function W1(K){u0=K,d0()}function Z1(K){L0=K,d0()}function d0(){let K=u0,C=L0,R=K+b/2,U0=C+W/2,Y0=W<b?R*W/b:R,X0=W>b?U0*b/W:U0,b1=Math.atan2(X0,Y0)/Math.PI*180-45,O0=Math.sqrt(Y0*Y0+X0*X0),l=Math.min(b,W)/2,U1=l*Math.SQRT2,B0=(O0-l)/(U1-l),E1=0,c1=22.5,i0=0+B0*22.5,Y1=O0<l?O0/l:1,X1=-D*(R/b)*B0,O1=-D*(U0/W)*B0;T.style.transform=`translate(${Math.round(K)}px, ${Math.round(C)}px)`,B.style.transform=`scale(${Y1}) rotate(${b1}deg) skew(${i0}deg, ${i0}deg)`,N.style.transform=`translate(${X1}px, ${O1}px)`}var H1={invoke:U},u=w1();let g0;var b0=J.child(u);let m0;J.bind_this(b0,(K)=>B=K,()=>B);var e=J.sibling(b0,2);let s0;var l0=J.child(e);let r0;return J.bind_this(l0,(K)=>N=K,()=>N),J.reset(e),J.bind_this(e,(K)=>T=K,()=>T),J.reset(u),J.bind_this(u,(K)=>H=K,()=>H),J.template_effect(()=>{J.set_class(u,1,J.clsx(["element anchor",J.get(Y)&&"displayed"]),"svelte-17e81wb0tdtjd"),g0=J.set_style(u,"",g0,{filter:`drop-shadow(${X})`}),m0=J.set_style(b0,"",m0,{width:`${w}px`,height:`${w}px`,"background-color":y,"border-radius":`${z}px`}),s0=J.set_style(e,"",s0,{width:`${b}px`,height:`${W}px`,padding:`${D}px`}),r0=J.set_style(l0,"",r0,{width:`${g}px`,height:`${$}px`,"border-radius":`${M}px`,"background-color":P})}),J.append(x,u),J.pop(H1)}class R0 extends v{width;height;zoom;angle;states;component;constructor(x,j){super(x,new E(j,x.lat,x.lng,x.rank));this.width=x.tooltip.style.dimensions.width+x.tooltip.style.dimensions.margin*2,this.height=x.tooltip.style.dimensions.height+x.tooltip.style.dimensions.margin*2,this.zoom=NaN,this.angle=NaN,this.states=[],this.component=T1(o,{target:this.marker.div,props:{id:this.id,style:x.tooltip.style,content:x.tooltip.body}})}get zIndex(){if(Number.isNaN(this.zoom))return this.rank;return Math.round(-this.zoom*x0)+t0}}import{mount as D1}from"svelte";class A0 extends v{width;height;margin;angle;component;constructor(x,j){if(x.popup==null)throw Error("Failed to create popup");super(x,new E(j,x.lat,x.lng,w0));this.width=x.popup.style.dimensions.width,this.height=x.popup.style.dimensions.height,this.margin=x.popup.style.dimensions.margin,this.angle=NaN,this.shown=!1,this.component=D1(o,{target:this.marker.div,props:{id:this.id,style:x.popup.style,content:x.popup.body}})}get zIndex(){return w0}}class S0{id;state=void 0;pin;tooltip;popup;constructor(x,j){if(this.id=x.id,this.pin=new f0(x,j),this.tooltip=new R0(x,j),x.popup!=null)this.popup=new A0(x,j)}}var v0=4;class $0{pins=new Set;pinMaxWidth=0;pinMaxHeight=0;pinFade=!1;pinZoomMax=v0;pinZoomDelta=v0;set configuration(x){this.pinFade=x?.pin?.fade??!0,this.pinZoomMax=x?.pin?.maxZoom??v0,this.pinZoomDelta=this.pinZoomMax}insert(x,j){this.update(x,j),this.pins.add(x)}update(x,j){x.zoom=j?j[0]:NaN,x.marker.update(x.zIndex)}remove(x){x.shown=!0,x.zoom=NaN,x.component.invoke().setCollapsed(!1),x.component.invoke().setSuppressed(!0),x.component.invoke().setDisplayed(!1),x.marker.update(x.zIndex),x.marker.remove(),this.pins.delete(x)}clear(){this.pins.forEach((x)=>x.marker.remove()),this.pins.clear()}refresh(){let x=Array.from(this.pins);this.pinMaxWidth=x.reduce((j,q)=>Math.max(j,q.width),0),this.pinMaxHeight=x.reduce((j,q)=>Math.max(j,q.height),0),this.pinZoomDelta=Math.max(1,this.pinZoomMax-Math.log10(x.length))}render(x,j){let q=x.zoom,Q=j.mapSize,h=A.offset(x,Q,{top:this.pinMaxHeight,bottom:this.pinMaxHeight,right:this.pinMaxWidth,left:this.pinMaxWidth});for(let G of this.pins)if(h.contains(G.lat,G.lng)){if(Number.isNaN(G.zoom))G.component.invoke().setDisplayed(!0),G.component.invoke().setSuppressed(!0),G.component.invoke().setCollapsed(!1),G.marker.insert();else if(G.component.invoke().setSuppressed(!1),G.shown&&q<G.zoom&&G.zoom<q+this.pinZoomDelta)G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setScale(this.pinFade?Math.max(0,1-(G.zoom-q)*0.2):1),G.marker.insert();else if(G.component.invoke().setCollapsed(!0),G.component.invoke().getCollapsed())G.component.invoke().setDisplayed(!1),G.marker.remove()}else G.component.invoke().setDisplayed(!1),G.marker.remove()}}import*as Q1 from"@arenarium/maps-core/angles";class P0{tooltips=new Set;tooltipMaxWidth=0;tooltipMaxHeight=0;insert(x,j){this.update(x,j),this.tooltips.add(x)}update(x,j){if(j)x.zoom=j[0],x.states=j[1].map((q)=>[q[0],Q1.values[q[1]]]);else x.zoom=NaN,x.states=[];x.marker.update(x.zIndex)}remove(x){x.shown=!0,x.zoom=NaN,x.angle=NaN,x.states=[],x.component.invoke().setAngle(NaN),x.component.invoke().setCollapsed(!0),x.component.invoke().setDisplayed(!1),x.marker.update(x.zIndex),x.marker.remove(),this.tooltips.delete(x)}clear(){this.tooltips.forEach((x)=>x.marker.remove()),this.tooltips.clear()}refresh(){let x=Array.from(this.tooltips);this.tooltipMaxWidth=x.reduce((j,q)=>Math.max(j,q.width),0),this.tooltipMaxHeight=x.reduce((j,q)=>Math.max(j,q.height),0)}render(x,j){let q=x.zoom,Q=j.mapSize,h=A.offset(x,Q,{top:this.tooltipMaxHeight,bottom:this.tooltipMaxHeight,right:this.tooltipMaxWidth,left:this.tooltipMaxWidth});for(let G of this.tooltips)if(h.contains(G.lat,G.lng)){if(Number.isNaN(G.zoom)==!1&&G.shown&&G.zoom<=q){let Z=G.states.findLast((U)=>U[0]<=q)?.[1];if(Z==null)throw Error("Angle not found");G.angle=Z,G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setAngle(Z),G.marker.insert()}else if(G.component.invoke().setCollapsed(!0),G.component.invoke().getCollapsed())G.component.invoke().setDisplayed(!1),G.marker.remove()}else G.component.invoke().setDisplayed(!1),G.marker.remove()}}import*as J0 from"@arenarium/maps-core/mercator";import*as G1 from"@arenarium/maps-core/rectangle";class _0{popups=new Set;pan=!0;set configuration(x){this.pan=x?.popup?.pan??!0}insert(x){this.popups.add(x)}remove(x){x.angle=NaN,x.shown=!1,x.marker.remove(),x.component.invoke().setAngle(NaN),x.component.invoke().setCollapsed(!0),x.component.invoke().setDisplayed(!1),this.popups.delete(x)}clear(){this.popups.forEach((x)=>x.marker.remove()),this.popups.clear()}show(x,j){if(!x.popup||!x.tooltip||!x.pin)return;if(x.pin.shown=!1,x.tooltip.shown=!1,x.popup.angle=x.tooltip.angle,x.popup.shown=!0,this.pan==!1)return;let q=x.popup,Q=j.getViewport(),h=Q.bounds,G=Q.zoom,U=j.getParameters().mapSize*Math.pow(2,G),H=J0.project(h.ne.lat,h.sw.lng,U),X=J0.project(h.sw.lat,h.ne.lng,U),B=X.x-H.x,w=X.y-H.y,y=q.width+q.margin*8,z=q.height+q.margin*8,T=J0.project(q.lat,q.lng,U),b=G1.offsets(y,z,x.tooltip.angle),W=T.x+b.x,D=W+y,N=T.y+b.y,g=N+z,$=W-H.x,M=X.x-D,P=N-H.y,Y=X.y-g,O=0;if(B<y)O=($-M)/2;else{if($<0)O=$;if(M<0)O=-M}let I=0;if(w<z)I=(P-Y)/2;else{if(P<0)I=P;if(Y<0)I=-Y}if(O!=0||I!=0)j.panBy(O,I)}hide(x){if(!x.popup||!x.tooltip||!x.pin)return;x.pin.shown=!0,x.tooltip.shown=!0,x.popup.shown=!1}render(){for(let x of this.popups)if(x.shown)x.component.invoke().setDisplayed(!0),x.component.invoke().setCollapsed(!1),x.component.invoke().setAngle(x.angle,!0),x.marker.insert();else if(x.component.invoke().setCollapsed(!0),x.component.invoke().getCollapsed())x.component.invoke().setDisplayed(!1),x.marker.remove()}}class k0{mapProvider;pinManager;tooltipManager;popupManager;elementsStore;constructor(x){this.mapProvider=x,this.pinManager=new $0,this.tooltipManager=new P0,this.popupManager=new _0,this.elementsStore=new Map}set configuration(x){this.pinManager.configuration=x,this.popupManager.configuration=x}clearElements(){this.elementsStore.clear(),this.pinManager.clear(),this.tooltipManager.clear(),this.popupManager.clear()}removeElements(x){for(let j of x){let q=this.elementsStore.get(j.data.id);if(q==null)continue;if(this.pinManager.remove(q.pin),this.tooltipManager.remove(q.tooltip),q.popup!=null)this.popupManager.remove(q.popup)}this.pinManager.refresh(),this.tooltipManager.refresh()}updateElements(x){for(let j of x){let q=this.elementsStore.get(j.data.id);if(q==null)continue;this.pinManager.update(q.pin,j.state),this.tooltipManager.update(q.tooltip,j.state)}}insertElements(x,j){for(let q of x){let Q=this.elementsStore.get(q.data.id);if(Q==null)Q=new S0(q.data,this.mapProvider),Q.tooltip.marker.div.addEventListener("click",(h)=>j(h,q.data.id)),this.elementsStore.set(q.data.id,Q);if(this.pinManager.insert(Q.pin,q.state),this.tooltipManager.insert(Q.tooltip,q.state),Q.popup!=null)this.popupManager.insert(Q.popup)}this.pinManager.refresh(),this.tooltipManager.refresh()}renderElements(x,j){this.popupManager.render(),this.tooltipManager.render(x,j),this.pinManager.render(x,j)}showPopup(x){let j=this.elementsStore.values();for(let q of j)if(q.id==x)this.popupManager.show(q,this.mapProvider);else this.popupManager.hide(q)}hidePopup(x){let j=this.elementsStore.get(x);if(j==null)return;this.popupManager.hide(j)}hidePopups(){let x=this.elementsStore.values();for(let j of x)this.popupManager.hide(j)}}import*as h1 from"@arenarium/maps-core/http";import*as J1 from"@arenarium/maps-core/hash";import*as F0 from"@arenarium/maps-core/angles";var M1="https://maps.api.arenarium.dev/states",f1=3,C1=500;class E0{apiKey;apiJwt;apiDevEnvironment;markerStatesStore;constructor(x,j){this.apiKey=x,this.apiJwt=j,this.apiDevEnvironment=window?.location.host.startsWith("localhost")||window?.location.host.startsWith("127.0.0.1"),this.markerStatesStore=new Map}clearStates(){this.markerStatesStore.clear()}resetStates(x){for(let j=0;j<x.length;j++){let q=x[j];q.state=void 0}}async updateStates(x,j){if(x.length==0)return;x.sort((G,Z)=>G.data.id.localeCompare(Z.data.id));let q=x.map((G)=>G.input),Q=J1.object(q),h=this.markerStatesStore.get(Q);if(h==null)h=await this.fetchStates(q,j),this.markerStatesStore.set(Q,h);for(let G=0;G<x.length;G++){let Z=x[G];Z.state=h[G]}}async fetchStates(x,j){if(x.length==0)return[];if(x.length==1)return[[0,[[0,F0.values.indexOf(F0.initial)]]]];let q={key:this.apiKey,jwt:this.apiJwt,input:x,parameters:j},Q={headers:{"Cache-Control":this.apiDevEnvironment?"no-cache":""}},h=await h1.post(M1,q,Q,f1,C1);if(h.jwt)this.apiJwt=h.jwt;return h.states}}import*as K0 from"@arenarium/maps-core/http";import{apiKeySchema as R1,apiJwtSchema as A1,mapMarkerDataSchema as S1,mapProviderSchema as v1}from"@arenarium/maps-core/schemas";import*as c from"valibot";var F1="1.2.15",$1="https://maps.api.arenarium.dev/auth",P1="https://maps.api.arenarium.dev/log",K1=500,_1=500;class c0{apiKey;mapProvider;mapEventProvider;markers;markerVisibilityManager;markerElementsManager;markerStatesManager;markerVisibilityProcessor;markerElementsProcessor;markerStateProcessor;markerStatesProcessDelay=500;markerStatesProcessTimeout=void 0;constructor(x,j,q,Q){c.parse(R1,x),c.parse(A1,j),c.parse(v1,q),this.apiKey=x,this.mapProvider=q,this.mapEventProvider=new N0(this.mapProvider,this.detached.bind(this),this.error.bind(this),this.onMapMove.bind(this),this.onMapIdle.bind(this),this.onMapClick.bind(this)),this.markers=new Map,this.markerVisibilityManager=new D0(this.mapProvider),this.markerElementsManager=new k0(this.mapProvider),this.markerStatesManager=new E0(x,j),this.markerVisibilityProcessor=new r(this.onMapMarkerVisiblityProcess.bind(this),K1),this.markerElementsProcessor=new r(this.onMapMarkerRenderProcess.bind(this),K1),this.markerStateProcessor=new r(this.onMapMarkerStateProcess.bind(this)),this.configuration=Q}static async create(x,j,q){let G=(await K0.post($1,{key:x,version:F1})).jwt;if(!G)throw Error("Failed to get api jwt");return new c0(x,G,j,q)}set configuration(x){this.markerStatesProcessDelay=x?.process?.states?.delay??_1,this.markerVisibilityManager.configuration=x,this.markerElementsManager.configuration=x}clear(){this.markers.clear(),this.markerVisibilityManager.clearMarkers(),this.markerStatesManager.clearStates(),this.markerElementsManager.clearElements(),this.mapEventProvider.stop(),this.markerVisibilityProcessor.stop(),this.markerStateProcessor.stop(),this.markerElementsProcessor.stop()}detached(){return this.mapProvider.getContainer().parentElement==null}error(x,j){this.log("error",x,j),this.configuration?.events?.error?.(x,j)}async log(x,j,q){switch(x){case"info":console.info(q);break;case"warning":console.warn(q);break;case"error":console.error(q);break}if(q instanceof Error==!1)return;try{let Q={key:this.apiKey,title:j,level:x,content:{version:F1,name:q.name,message:q.message,cause:q.cause,stack:q.stack}};await K0.put(P1,Q)}catch(Q){console.error(Q)}}onMapMove(){this.markerVisibilityProcessor.start()}onMapIdle(){if(this.markerStatesProcessTimeout)window.clearTimeout(this.markerStatesProcessTimeout);this.markerStatesProcessTimeout=window.setTimeout(()=>{this.markerStateProcessor.start()},this.markerStatesProcessDelay)}onMapClick(){this.hidePopup()}onMapMarkerClick(x,j){x.stopPropagation(),this.showPopup(j)}async onMapMarkerVisiblityProcess(){try{if(this.detached())return!0;let x=this.mapProvider.getViewport(),j=this.mapProvider.getParameters(),q=new Set(this.markerVisibilityManager.getMarkers());this.markerVisibilityManager.updateMarkers(x,j);let Q=new Set(this.markerVisibilityManager.getMarkers()),h=Array.from(q.difference(Q)),G=Array.from(Q.difference(q));return this.markerStatesManager.resetStates(h),this.markerElementsManager.removeElements(h),this.markerElementsManager.insertElements(G,this.onMapMarkerClick.bind(this)),this.markerElementsProcessor.start(),!1}catch(x){return this.clear(),this.error("Failed to process map move",x),!0}}async onMapMarkerStateProcess(){try{if(this.detached())return!0;let x=this.markerVisibilityManager.getMarkers(),j=this.mapProvider.getParameters();return await this.markerStatesManager.updateStates(x,j),this.markerElementsManager.updateElements(x),this.markerElementsProcessor.start(),!1}catch(x){return this.clear(),this.error("Failed to process map idle",x),!0}}async onMapMarkerRenderProcess(){try{if(this.detached())return!0;let x=this.mapProvider.getViewport(),j=this.mapProvider.getParameters();return this.markerElementsManager.renderElements(x,j),!1}catch(x){return this.clear(),this.error("Failed to process map render",x),!0}}updateMarkers(x){c.parse(c.array(S1),x);try{for(let q of x)if(this.markers.has(q.id)==!1)this.markers.set(q.id,new y0(q));let j=Array.from(this.markers.values());j.sort((q,Q)=>Q.data.rank-q.data.rank),this.markerVisibilityManager.insertMarkers(j),this.mapEventProvider.start(),this.markerVisibilityProcessor.start(),this.markerStateProcessor.start(),this.markerElementsProcessor.start()}catch(j){throw this.clear(),this.error("Failed to update markers",j),j}}removeMarkers(){try{this.clear()}catch(x){throw this.error("Failed to remove markers",x),x}}showPopup(x){if(this.detached())return;if(this.markers.size==0)return;try{this.markerElementsManager.showPopup(x)}catch(j){throw this.markerElementsManager.hidePopups(),this.error("Failed to show popup",j),j}finally{this.markerElementsProcessor.start()}}hidePopup(){if(this.detached())return;if(this.markers.size==0)return;try{this.markerElementsManager.hidePopups()}catch(x){throw this.error("Failed to hide popup",x),x}finally{this.markerElementsProcessor.start()}}}export{c0 as MapManager};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arenarium/maps",
3
- "version": "1.2.14",
3
+ "version": "1.2.16",
4
4
  "license": "MIT",
5
5
  "author": "arenarium",
6
6
  "description": "Visualize complex map markers clearly. A JavaScript library for effective display of map markers, compatible with MapLibre, Mapbox, and Google Maps.",
@@ -40,7 +40,7 @@
40
40
  "dependencies": {
41
41
  "@arenarium/maps-core": "1.0.7",
42
42
  "valibot": "^1.2.0",
43
- "svelte": "^5.46.1"
43
+ "svelte": "^5.49.0"
44
44
  },
45
45
  "clean-package": {
46
46
  "indent": 2,