@arenarium/maps 1.2.12 → 1.2.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.d.ts CHANGED
@@ -2,16 +2,16 @@ import { MapConfiguration, MapMarkerData, MapProvider } from "@arenarium/maps-co
2
2
  declare class MapManager {
3
3
  private apiKey;
4
4
  private mapProvider;
5
- private mapMarkers;
6
- private mapMarkersVisibilityManager;
7
- private mapMarkerElementsManager;
8
- private mapMarkerStatesManager;
9
- private mapMarkerRenderProcessor;
10
- private mapMarkerVisibilityProcessor;
11
- private mapMarkerStateProcessor;
12
- private mapMarkerStatesProcessDelay;
13
- private mapMarkerStatesProcessTimeout;
14
- private mapStateManager;
5
+ private mapEventProvider;
6
+ private markers;
7
+ private markerVisibilityManager;
8
+ private markerElementsManager;
9
+ private markerStatesManager;
10
+ private markerVisibilityProcessor;
11
+ private markerElementsProcessor;
12
+ private markerStateProcessor;
13
+ private markerStatesProcessDelay;
14
+ private markerStatesProcessTimeout;
15
15
  private constructor();
16
16
  static create(apiKey: string, mapProvider: MapProvider, mapConfiguration?: MapConfiguration): Promise<MapManager>;
17
17
  set configuration(configuration: MapConfiguration | undefined);
@@ -19,10 +19,10 @@ declare class MapManager {
19
19
  private detached;
20
20
  private error;
21
21
  private log;
22
- private onMapClick;
23
- private onMapMarkerClick;
24
22
  private onMapMove;
25
23
  private onMapIdle;
24
+ private onMapClick;
25
+ private onMapMarkerClick;
26
26
  private onMapMarkerVisiblityProcess;
27
27
  private onMapMarkerStateProcess;
28
28
  private onMapMarkerRenderProcess;
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}}class N0{viewport=void 0;state="idle";provider;interval;onCancel;onError;onMove;onIdle;constructor(x,j,q,Q,h,G){this.provider=x,this.interval=new y0(this.onInterval.bind(this),j),this.onCancel=q,this.onError=Q,this.onMove=h,this.onIdle=G}start(){this.interval.start()}stop(){this.interval.stop()}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 n0=75,p0=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 n{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 R{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 n(x,j,q,Q),this.blockR=new n(0,0,0,0);else this.blockL=new n(x,-180,q,Q),this.blockR=new n(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 R(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),b=d.project(Q.sw.lat,Q.sw.lng,G),U=d.project(Q.ne.lat,Q.ne.lng,G),Z=Math.max(b.x-q.left,0),X=Math.min(b.y+q.bottom,G),z=Math.min(U.x+q.right,G),w=Math.max(U.y-q.top,0),B=d.unproject(Z,X,G),y=d.unproject(z,w,G);return new R(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 b=x.sw.lat+h*q,U=x.sw.lng+G*Q,Z=b+q,X=U+Q;this.branches.push(new Q0(this.tree,`${this.cell.id}${h*2+G}`,this.zoom+this.tree.depth,{sw:{lat:b,lng:U},ne:{lat:Z,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;mapMarkersVisibilityTree;mapMarkersVisible;mapMarkerTreeCellCapacity=e0;mapMarkerTreeCellZoomDelta=x1;mapMarkerTreeCellSize=j1;mapMarkerTreeLimit=q1;constructor(x){this.mapProvider=x}set configuration(x){this.mapMarkerTreeCellCapacity=x?.process?.visibility?.cell?.capacity??e0,this.mapMarkerTreeCellZoomDelta=x?.process?.visibility?.cell?.depth??x1,this.mapMarkerTreeCellSize=x?.process?.visibility?.cell?.size??j1,this.mapMarkerTreeLimit=x?.process?.visibility?.limit??q1}get markers(){return Array.from(this.mapMarkersVisible??[])}insertMarkers(x){this.mapMarkersVisibilityTree=this.createVisibilityTree(x)}clearMarkers(){this.mapMarkersVisibilityTree=void 0,this.mapMarkersVisible=void 0}updateVisibleMarkers(x,j){if(this.mapMarkersVisibilityTree==null)return;let q=R.bounds(x),Q=[],h=x.zoom;while(h<j.zoomMax&&Q.length<this.mapMarkerTreeLimit)Q=this.mapMarkersVisibilityTree.cells(h,q).flatMap((G)=>G.markers),h++;this.mapMarkersVisible=Q}createVisibilityTree(x){if(x.length<this.mapMarkerTreeLimit){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.mapMarkerTreeCellSize)),q=new G0(j,this.mapMarkerTreeCellZoomDelta,this.mapMarkerTreeCellCapacity);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 y1}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 A{shown;id;lat;lng;rank;marker;constructor(x,j){if(new.target===A)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 z1}from"svelte/easing";class p{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 B1=F.from_html("<div></div>");function f0(x,j){F.push(j,!0);let q=F.rest_props(j,["$$slots","$$events","$$legacy"]),Q=j.id,h=j.style,G=j.content,b={setDisplayed:g,getDisplayed:$,setSuppressed:_,setCollapsed:O,getCollapsed:I,setScale:s};function U(){return b}let Z,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,V=h.colors?.shadow??q0,H=F.state(!1),D=!1,N=!1;function g(W){if(W==F.get(H))return;if(F.set(H,W,!0),W==!0){if(G==null)return;if(N)return;if(D)return;D=!0,G(Q).then((S)=>{if(S instanceof HTMLElement)Z.appendChild(S);else console.error("Failed to load pin content")}).catch((S)=>console.error(S)).finally(()=>{N=!0,D=!1})}if(W==!1)P.end()}function $(){return F.get(H)}let f=F.state(!0);function _(W){if(W==F.get(f))return;if(F.set(f,W,!0),W)m=k,P.set(k)}let Y=F.state(!0);function O(W){if(W==F.get(Y))return;F.set(Y,W,!0),P.target(F.get(Y)?0:m)}function I(){if(!F.get(H))return!0;return P.expired()}let m=k,P=new p({value:k,min:0,max:1,timespan:n0,easing:z1,callback:W0});function s(W){m=W,P.target(W)}function W0(W){Z.style.scale=W.toString(),Z.style.filter=`brightness(${t(W)})`}function t(W){return 0.25+0.75*W}var H0={invoke:U},C=B1();let a;return F.bind_this(C,(W)=>Z=W,()=>Z),F.template_effect((W)=>{F.set_class(C,1,F.clsx(["pin",F.get(H)&&"displayed",F.get(f)&&"suppressed"]),"svelte-e30vfn4rttu1"),a=F.set_style(C,"",a,W)},[()=>({width:`${X}px`,height:`${z}px`,"border-radius":`${w}px`,"border-color":y,"background-color":T,"border-width":`${B}px`,"box-shadow":V,scale:k,filter:`brightness(${t(k)})`})]),F.append(x,C),F.pop(H0)}class C0 extends A{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=y1(f0,{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 w1}from"svelte";import"svelte/internal/disclose-version";import*as J from"svelte/internal/client";import{sineInOut as N1}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 v0 from"@arenarium/maps-core/rectangle";var I1=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,b={setDisplayed:m,getDisplayed:P,setCollapsed:W0,getCollapsed:t,getExpanded:H0,setAngle:W1};function U(){return b}let Z,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,V=h.dimensions.width+2*h.dimensions.margin,H=h.dimensions.height+2*h.dimensions.margin,D=h.dimensions.margin,N,g=h.dimensions.width,$=h.dimensions.height,f=h.dimensions.radius,_=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((v)=>{if(v instanceof HTMLElement)N.appendChild(v);else console.error("Failed to load tooltip content")}).catch((v)=>console.error(v)).finally(()=>{I=!0,O=!1})}if(K==!1)C.end(),b0.end(),Z0.end()}function P(){return J.get(Y)}let s=J.state(!0);function W0(K){if(K==J.get(s))return;J.set(s,K,!0),C.target(J.get(s)?0:1)}function t(){if(!J.get(Y))return!0;return C.expired()}function H0(){if(!J.get(Y))return!1;return C.expired()}let C=new p({value:0,min:0,max:1,timespan:p0,easing:N1,callback:a});function a(K){Z.style.opacity=`${K}`,T.style.scale=`${K}`,z.style.scale=`${K}`}let W=NaN,S=J.state(!1),u0=-V/2,b0=new h0({value:-V/2,min:-V,max:0,precision:1,stiffness:I0,callback:H1}),L0=-H/2,Z0=new h0({value:-H/2,min:-H,max:0,precision:1,stiffness:I0,callback:b1});function W1(K,v){if(Number.isNaN(K)){W=NaN,J.set(S,!1);return}if(J.get(S)==!1||v==!0){J.set(S,!0),W=K;let M=v0.offsets(V,H,K);b0.set(Math.round(M.x)),Z0.set(Math.round(M.y));return}if(W!=K){W=K;let M=v0.offsets(V,H,K);b0.target(Math.round(M.x)),Z0.target(Math.round(M.y));return}}function H1(K){u0=K,d0()}function b1(K){L0=K,d0()}function d0(){let K=u0,v=L0,M=K+V/2,U0=v+H/2,Y0=H<V?M*H/V:M,X0=H>V?U0*V/H:U0,V1=Math.atan2(X0,Y0)/Math.PI*180-45,O0=Math.sqrt(Y0*Y0+X0*X0),l=Math.min(V,H)/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*(M/V)*z0,O1=-D*(U0/H)*z0;T.style.transform=`translate(${Math.round(K)}px, ${Math.round(v)}px)`,z.style.transform=`scale(${Y1}) rotate(${V1}deg) skew(${i0}deg, ${i0}deg)`,N.style.transform=`translate(${X1}px, ${O1}px)`}var Z1={invoke:U},u=I1();let g0;var V0=J.child(u);let m0;J.bind_this(V0,(K)=>z=K,()=>z);var e=J.sibling(V0,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)=>Z=K,()=>Z),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(V0,"",m0,{width:`${w}px`,height:`${w}px`,"background-color":B,"border-radius":`${y}px`}),s0=J.set_style(e,"",s0,{width:`${V}px`,height:`${H}px`,padding:`${D}px`}),r0=J.set_style(l0,"",r0,{width:`${g}px`,height:`${$}px`,"border-radius":`${f}px`,"background-color":_})}),J.append(x,u),J.pop(Z1)}class M0 extends A{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=w1(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 T1}from"svelte";class R0 extends A{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=T1(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 C0(x,j),this.tooltip=new M0(x,j),x.popup!=null)this.popup=new R0(x,j)}}var A0=4;class $0{pins=new Set;pinMaxWidth=0;pinMaxHeight=0;pinFade=!1;pinZoomMax=A0;pinZoomDelta=A0;set configuration(x){this.pinFade=x?.pin?.fade??!0,this.pinZoomMax=x?.pin?.maxZoom??A0,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=R.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 _0{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=R.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 b=G.states.findLast((U)=>U[0]<=q)?.[1];if(b==null)throw Error("Angle not found");G.angle=b,G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setAngle(b),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 P0{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),Z=J0.project(h.ne.lat,h.sw.lng,U),X=J0.project(h.sw.lat,h.ne.lng,U),z=X.x-Z.x,w=X.y-Z.y,B=q.width+q.margin*8,y=q.height+q.margin*8,T=J0.project(q.lat,q.lng,U),V=G1.offsets(B,y,x.tooltip.angle),H=T.x+V.x,D=H+B,N=T.y+V.y,g=N+y,$=H-Z.x,f=X.x-D,_=N-Z.y,Y=X.y-g,O=0;if(z<B)O=($-f)/2;else{if($<0)O=$;if(f<0)O=-f}let I=0;if(w<y)I=(_-Y)/2;else{if(_<0)I=_;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;mapPinManager;mapTooltipManager;mapPopupManager;mapElements;constructor(x){this.mapProvider=x,this.mapPinManager=new $0,this.mapTooltipManager=new _0,this.mapPopupManager=new P0,this.mapElements=new Map}set configuration(x){this.mapPinManager.configuration=x,this.mapPopupManager.configuration=x}clearElements(){this.mapElements.clear(),this.mapPinManager.clear(),this.mapTooltipManager.clear(),this.mapPopupManager.clear()}removeElements(x){for(let j of x){let q=this.mapElements.get(j.data.id);if(q==null)continue;if(this.mapPinManager.remove(q.pin),this.mapTooltipManager.remove(q.tooltip),q.popup!=null)this.mapPopupManager.remove(q.popup)}this.mapPinManager.refresh(),this.mapTooltipManager.refresh()}updateElements(x){for(let j of x){let q=this.mapElements.get(j.data.id);if(q==null)continue;this.mapPinManager.update(q.pin,j.state),this.mapTooltipManager.update(q.tooltip,j.state)}}insertElements(x,j){for(let q of x){let Q=this.mapElements.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.mapElements.set(q.data.id,Q);if(this.mapPinManager.insert(Q.pin,q.state),this.mapTooltipManager.insert(Q.tooltip,q.state),Q.popup!=null)this.mapPopupManager.insert(Q.popup)}this.mapPinManager.refresh(),this.mapTooltipManager.refresh()}renderElements(x,j){this.mapPopupManager.render(),this.mapTooltipManager.render(x,j),this.mapPinManager.render(x,j)}showPopup(x){let j=this.mapElements.values();for(let q of j)if(q.id==x)this.mapPopupManager.show(q,this.mapProvider);else this.mapPopupManager.hide(q)}hidePopup(x){let j=this.mapElements.get(x);if(j==null)return;this.mapPopupManager.hide(j)}hidePopups(){let x=this.mapElements.values();for(let j of x)this.mapPopupManager.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 D1="https://maps.api.arenarium.dev/states",f1=3,C1=500;class E0{apiKey;apiJwt;apiDevEnvironment;mapMarkerStatesStore;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.mapMarkerStatesStore=new Map}clearStates(){this.mapMarkerStatesStore.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,b)=>G.data.id.localeCompare(b.data.id));let q=x.map((G)=>G.input),Q=J1.object(q),h=this.mapMarkerStatesStore.get(Q);if(h==null)h=await this.fetchStates(q,j),this.mapMarkerStatesStore.set(Q,h);for(let G=0;G<x.length;G++){let b=x[G];b.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(D1,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 v1,apiJwtSchema as M1,mapMarkerDataSchema as R1,mapProviderSchema as S1}from"@arenarium/maps-core/schemas";import*as c from"valibot";var F1="1.2.11",A1="https://maps.api.arenarium.dev/auth",$1="https://maps.api.arenarium.dev/log",_1=100,K1=500,P1=500;class c0{apiKey;mapProvider;mapMarkers;mapMarkersVisibilityManager;mapMarkerElementsManager;mapMarkerStatesManager;mapMarkerRenderProcessor;mapMarkerVisibilityProcessor;mapMarkerStateProcessor;mapMarkerStatesProcessDelay=500;mapMarkerStatesProcessTimeout=void 0;mapStateManager;constructor(x,j,q,Q){c.parse(v1,x),c.parse(M1,j),c.parse(S1,q),this.apiKey=x,this.mapProvider=q,this.mapProvider.getContainer().addEventListener("click",this.onMapClick.bind(this)),this.mapMarkers=new Map,this.mapMarkersVisibilityManager=new D0(this.mapProvider),this.mapMarkerElementsManager=new k0(this.mapProvider),this.mapMarkerStatesManager=new E0(x,j),this.mapMarkerRenderProcessor=new r(this.onMapMarkerRenderProcess.bind(this),K1),this.mapMarkerVisibilityProcessor=new r(this.onMapMarkerVisiblityProcess.bind(this),K1),this.mapMarkerStateProcessor=new r(this.onMapMarkerStateProcess.bind(this)),this.mapStateManager=new N0(this.mapProvider,_1/(navigator?.hardwareConcurrency??1),this.detached.bind(this),this.error.bind(this),this.onMapMove.bind(this),this.onMapIdle.bind(this)),this.configuration=Q}static async create(x,j,q){let G=(await K0.post(A1,{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.mapMarkerStatesProcessDelay=x?.process?.states?.delay??P1,this.mapMarkersVisibilityManager.configuration=x,this.mapMarkerElementsManager.configuration=x}clear(){this.mapMarkers.clear(),this.mapMarkersVisibilityManager.clearMarkers(),this.mapMarkerStatesManager.clearStates(),this.mapMarkerElementsManager.clearElements(),this.mapStateManager.stop(),this.mapMarkerVisibilityProcessor.stop(),this.mapMarkerStateProcessor.stop(),this.mapMarkerRenderProcessor.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($1,Q)}catch(Q){console.error(Q)}}onMapClick(){this.hidePopup()}onMapMarkerClick(x,j){x.stopPropagation(),this.showPopup(j)}onMapMove(){this.mapMarkerVisibilityProcessor.start()}onMapIdle(){if(this.mapMarkerStatesProcessTimeout)window.clearTimeout(this.mapMarkerStatesProcessTimeout);this.mapMarkerStatesProcessTimeout=window.setTimeout(()=>{this.mapMarkerStateProcessor.start()},this.mapMarkerStatesProcessDelay)}async onMapMarkerVisiblityProcess(){try{if(this.detached())return!0;let x=this.mapProvider.getViewport(),j=this.mapProvider.getParameters(),q=new Set(this.mapMarkersVisibilityManager.markers);this.mapMarkersVisibilityManager.updateVisibleMarkers(x,j);let Q=new Set(this.mapMarkersVisibilityManager.markers),h=Array.from(q.difference(Q)),G=Array.from(Q.difference(q));return this.mapMarkerStatesManager.resetStates(h),this.mapMarkerElementsManager.removeElements(h),this.mapMarkerElementsManager.insertElements(G,this.onMapMarkerClick.bind(this)),this.mapMarkerRenderProcessor.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.mapMarkersVisibilityManager.markers,j=this.mapProvider.getParameters();return await this.mapMarkerStatesManager.updateStates(x,j),this.mapMarkerElementsManager.updateElements(x),this.mapMarkerRenderProcessor.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.mapMarkerElementsManager.renderElements(x,j),!1}catch(x){return this.clear(),this.error("Failed to process map render",x),!0}}updateMarkers(x){c.parse(c.array(R1),x);try{for(let q of x)if(this.mapMarkers.has(q.id)==!1)this.mapMarkers.set(q.id,new B0(q));let j=Array.from(this.mapMarkers.values());j.sort((q,Q)=>Q.data.rank-q.data.rank),this.mapMarkersVisibilityManager.insertMarkers(j),this.mapStateManager.start(),this.mapMarkerVisibilityProcessor.start(),this.mapMarkerStateProcessor.start(),this.mapMarkerRenderProcessor.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.mapMarkers.size==0)return;try{this.mapMarkerElementsManager.showPopup(x)}catch(j){throw this.mapMarkerElementsManager.hidePopups(),this.error("Failed to show popup",j),j}finally{this.mapMarkerRenderProcessor.start()}}hidePopup(){if(this.detached())return;if(this.mapMarkers.size==0)return;try{this.mapMarkerElementsManager.hidePopups()}catch(x){throw this.error("Failed to hide popup",x),x}finally{this.mapMarkerRenderProcessor.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 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 R{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 R(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),b=d.project(Q.sw.lat,Q.sw.lng,G),U=d.project(Q.ne.lat,Q.ne.lng,G),Z=Math.max(b.x-q.left,0),X=Math.min(b.y+q.bottom,G),z=Math.min(U.x+q.right,G),w=Math.max(U.y-q.top,0),B=d.unproject(Z,X,G),y=d.unproject(z,w,G);return new R(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 b=x.sw.lat+h*q,U=x.sw.lng+G*Q,Z=b+q,X=U+Q;this.branches.push(new Q0(this.tree,`${this.cell.id}${h*2+G}`,this.zoom+this.tree.depth,{sw:{lat:b,lng:U},ne:{lat:Z,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;mapMarkersVisibilityTree;mapMarkersVisible;mapMarkerTreeCellCapacity=e0;mapMarkerTreeCellZoomDelta=x1;mapMarkerTreeCellSize=j1;mapMarkerTreeLimit=q1;constructor(x){this.mapProvider=x}set configuration(x){this.mapMarkerTreeCellCapacity=x?.process?.visibility?.cell?.capacity??e0,this.mapMarkerTreeCellZoomDelta=x?.process?.visibility?.cell?.depth??x1,this.mapMarkerTreeCellSize=x?.process?.visibility?.cell?.size??j1,this.mapMarkerTreeLimit=x?.process?.visibility?.limit??q1}get markers(){return Array.from(this.mapMarkersVisible??[])}insertMarkers(x){this.mapMarkersVisibilityTree=this.createVisibilityTree(x)}clearMarkers(){this.mapMarkersVisibilityTree=void 0,this.mapMarkersVisible=void 0}updateVisibleMarkers(x,j){if(this.mapMarkersVisibilityTree==null)return;let q=R.bounds(x),Q=[],h=x.zoom;while(h<j.zoomMax&&Q.length<this.mapMarkerTreeLimit)Q=this.mapMarkersVisibilityTree.cells(h,q).flatMap((G)=>G.markers),h++;this.mapMarkersVisible=Q}createVisibilityTree(x){if(x.length<this.mapMarkerTreeLimit){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.mapMarkerTreeCellSize)),q=new G0(j,this.mapMarkerTreeCellZoomDelta,this.mapMarkerTreeCellCapacity);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 A{shown;id;lat;lng;rank;marker;constructor(x,j){if(new.target===A)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 f0(x,j){F.push(j,!0);let q=F.rest_props(j,["$$slots","$$events","$$legacy"]),Q=j.id,h=j.style,G=j.content,b={setDisplayed:g,getDisplayed:$,setSuppressed:_,setCollapsed:O,getCollapsed:I,setScale:s};function U(){return b}let Z,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,V=h.colors?.shadow??q0,H=F.state(!1),D=!1,N=!1;function g(W){if(W==F.get(H))return;if(F.set(H,W,!0),W==!0){if(G==null)return;if(N)return;if(D)return;D=!0,G(Q).then((S)=>{if(S instanceof HTMLElement)Z.appendChild(S);else console.error("Failed to load pin content")}).catch((S)=>console.error(S)).finally(()=>{N=!0,D=!1})}if(W==!1)P.end()}function $(){return F.get(H)}let f=F.state(!0);function _(W){if(W==F.get(f))return;if(F.set(f,W,!0),W)m=k,P.set(k)}let Y=F.state(!0);function O(W){if(W==F.get(Y))return;F.set(Y,W,!0),P.target(F.get(Y)?0:m)}function I(){if(!F.get(H))return!0;return P.expired()}let m=k,P=new n({value:k,min:0,max:1,timespan:p0,easing:B1,callback:W0});function s(W){m=W,P.target(W)}function W0(W){Z.style.scale=W.toString(),Z.style.filter=`brightness(${t(W)})`}function t(W){return 0.25+0.75*W}var H0={invoke:U},M=y1();let a;return F.bind_this(M,(W)=>Z=W,()=>Z),F.template_effect((W)=>{F.set_class(M,1,F.clsx(["pin",F.get(H)&&"displayed",F.get(f)&&"suppressed"]),"svelte-e30vfn4rttu1"),a=F.set_style(M,"",a,W)},[()=>({width:`${X}px`,height:`${z}px`,"border-radius":`${w}px`,"border-color":y,"background-color":T,"border-width":`${B}px`,"box-shadow":V,scale:k,filter:`brightness(${t(k)})`})]),F.append(x,M),F.pop(H0)}class M0 extends A{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(f0,{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,b={setDisplayed:m,getDisplayed:P,setCollapsed:W0,getCollapsed:t,getExpanded:H0,setAngle:W1};function U(){return b}let Z,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,V=h.dimensions.width+2*h.dimensions.margin,H=h.dimensions.height+2*h.dimensions.margin,D=h.dimensions.margin,N,g=h.dimensions.width,$=h.dimensions.height,f=h.dimensions.radius,_=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)M.end(),b0.end(),Z0.end()}function P(){return J.get(Y)}let s=J.state(!0);function W0(K){if(K==J.get(s))return;J.set(s,K,!0),M.target(J.get(s)?0:1)}function t(){if(!J.get(Y))return!0;return M.expired()}function H0(){if(!J.get(Y))return!1;return M.expired()}let M=new n({value:0,min:0,max:1,timespan:n0,easing:I1,callback:a});function a(K){Z.style.opacity=`${K}`,T.style.scale=`${K}`,z.style.scale=`${K}`}let W=NaN,S=J.state(!1),u0=-V/2,b0=new h0({value:-V/2,min:-V,max:0,precision:1,stiffness:I0,callback:H1}),L0=-H/2,Z0=new h0({value:-H/2,min:-H,max:0,precision:1,stiffness:I0,callback:b1});function W1(K,C){if(Number.isNaN(K)){W=NaN,J.set(S,!1);return}if(J.get(S)==!1||C==!0){J.set(S,!0),W=K;let v=C0.offsets(V,H,K);b0.set(Math.round(v.x)),Z0.set(Math.round(v.y));return}if(W!=K){W=K;let v=C0.offsets(V,H,K);b0.target(Math.round(v.x)),Z0.target(Math.round(v.y));return}}function H1(K){u0=K,d0()}function b1(K){L0=K,d0()}function d0(){let K=u0,C=L0,v=K+V/2,U0=C+H/2,Y0=H<V?v*H/V:v,X0=H>V?U0*V/H:U0,V1=Math.atan2(X0,Y0)/Math.PI*180-45,O0=Math.sqrt(Y0*Y0+X0*X0),l=Math.min(V,H)/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*(v/V)*z0,O1=-D*(U0/H)*z0;T.style.transform=`translate(${Math.round(K)}px, ${Math.round(C)}px)`,z.style.transform=`scale(${Y1}) rotate(${V1}deg) skew(${i0}deg, ${i0}deg)`,N.style.transform=`translate(${X1}px, ${O1}px)`}var Z1={invoke:U},u=w1();let g0;var V0=J.child(u);let m0;J.bind_this(V0,(K)=>z=K,()=>z);var e=J.sibling(V0,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)=>Z=K,()=>Z),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(V0,"",m0,{width:`${w}px`,height:`${w}px`,"background-color":B,"border-radius":`${y}px`}),s0=J.set_style(e,"",s0,{width:`${V}px`,height:`${H}px`,padding:`${D}px`}),r0=J.set_style(l0,"",r0,{width:`${g}px`,height:`${$}px`,"border-radius":`${f}px`,"background-color":_})}),J.append(x,u),J.pop(Z1)}class v0 extends A{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 R0 extends A{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 M0(x,j),this.tooltip=new v0(x,j),x.popup!=null)this.popup=new R0(x,j)}}var A0=4;class $0{pins=new Set;pinMaxWidth=0;pinMaxHeight=0;pinFade=!1;pinZoomMax=A0;pinZoomDelta=A0;set configuration(x){this.pinFade=x?.pin?.fade??!0,this.pinZoomMax=x?.pin?.maxZoom??A0,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=R.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 _0{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=R.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 b=G.states.findLast((U)=>U[0]<=q)?.[1];if(b==null)throw Error("Angle not found");G.angle=b,G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setAngle(b),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 P0{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),Z=J0.project(h.ne.lat,h.sw.lng,U),X=J0.project(h.sw.lat,h.ne.lng,U),z=X.x-Z.x,w=X.y-Z.y,B=q.width+q.margin*8,y=q.height+q.margin*8,T=J0.project(q.lat,q.lng,U),V=G1.offsets(B,y,x.tooltip.angle),H=T.x+V.x,D=H+B,N=T.y+V.y,g=N+y,$=H-Z.x,f=X.x-D,_=N-Z.y,Y=X.y-g,O=0;if(z<B)O=($-f)/2;else{if($<0)O=$;if(f<0)O=-f}let I=0;if(w<y)I=(_-Y)/2;else{if(_<0)I=_;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;mapPinManager;mapTooltipManager;mapPopupManager;mapElements;constructor(x){this.mapProvider=x,this.mapPinManager=new $0,this.mapTooltipManager=new _0,this.mapPopupManager=new P0,this.mapElements=new Map}set configuration(x){this.mapPinManager.configuration=x,this.mapPopupManager.configuration=x}clearElements(){this.mapElements.clear(),this.mapPinManager.clear(),this.mapTooltipManager.clear(),this.mapPopupManager.clear()}removeElements(x){for(let j of x){let q=this.mapElements.get(j.data.id);if(q==null)continue;if(this.mapPinManager.remove(q.pin),this.mapTooltipManager.remove(q.tooltip),q.popup!=null)this.mapPopupManager.remove(q.popup)}this.mapPinManager.refresh(),this.mapTooltipManager.refresh()}updateElements(x){for(let j of x){let q=this.mapElements.get(j.data.id);if(q==null)continue;this.mapPinManager.update(q.pin,j.state),this.mapTooltipManager.update(q.tooltip,j.state)}}insertElements(x,j){for(let q of x){let Q=this.mapElements.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.mapElements.set(q.data.id,Q);if(this.mapPinManager.insert(Q.pin,q.state),this.mapTooltipManager.insert(Q.tooltip,q.state),Q.popup!=null)this.mapPopupManager.insert(Q.popup)}this.mapPinManager.refresh(),this.mapTooltipManager.refresh()}renderElements(x,j){this.mapPopupManager.render(),this.mapTooltipManager.render(x,j),this.mapPinManager.render(x,j)}showPopup(x){let j=this.mapElements.values();for(let q of j)if(q.id==x)this.mapPopupManager.show(q,this.mapProvider);else this.mapPopupManager.hide(q)}hidePopup(x){let j=this.mapElements.get(x);if(j==null)return;this.mapPopupManager.hide(j)}hidePopups(){let x=this.mapElements.values();for(let j of x)this.mapPopupManager.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 f1="https://maps.api.arenarium.dev/states",M1=3,C1=500;class E0{apiKey;apiJwt;apiDevEnvironment;mapMarkerStatesStore;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.mapMarkerStatesStore=new Map}clearStates(){this.mapMarkerStatesStore.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,b)=>G.data.id.localeCompare(b.data.id));let q=x.map((G)=>G.input),Q=J1.object(q),h=this.mapMarkerStatesStore.get(Q);if(h==null)h=await this.fetchStates(q,j),this.mapMarkerStatesStore.set(Q,h);for(let G=0;G<x.length;G++){let b=x[G];b.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(f1,q,{headers:{"Cache-Control":this.apiDevEnvironment?"no-cache":""}},M1,C1);if(Q.jwt)this.apiJwt=Q.jwt;return Q.states}}import*as K0 from"@arenarium/maps-core/http";import{apiKeySchema as v1,apiJwtSchema as R1,mapMarkerDataSchema as S1,mapProviderSchema as A1}from"@arenarium/maps-core/schemas";import*as c from"valibot";var F1="1.2.12",$1="https://maps.api.arenarium.dev/auth",_1="https://maps.api.arenarium.dev/log",K1=500,P1=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(v1,x),c.parse(R1,j),c.parse(A1,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??P1,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(_1,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.markers);this.markerVisibilityManager.updateVisibleMarkers(x,j);let Q=new Set(this.markerVisibilityManager.markers),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.markers,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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arenarium/maps",
3
- "version": "1.2.12",
3
+ "version": "1.2.13",
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.",
@@ -38,7 +38,7 @@
38
38
  "**/*.css"
39
39
  ],
40
40
  "dependencies": {
41
- "@arenarium/maps-core": "1.0.6",
41
+ "@arenarium/maps-core": "1.0.7",
42
42
  "valibot": "^1.2.0",
43
43
  "svelte": "^5.46.1"
44
44
  },