@arenarium/maps 1.2.9 → 1.2.10

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
@@ -16,7 +16,7 @@ declare class MapManager {
16
16
  static create(apiKey: string, mapProvider: MapProvider, mapConfiguration?: MapConfiguration): Promise<MapManager>;
17
17
  set configuration(configuration: MapConfiguration | undefined);
18
18
  private clear;
19
- private dettached;
19
+ private detached;
20
20
  private error;
21
21
  private log;
22
22
  private onMapClick;
package/dist/main.js CHANGED
@@ -1 +1 @@
1
- async function s0(x){return new Promise((q)=>setTimeout(q,x))}async function r0(x,q){let J=0,Q=Math.max(1,q?.retry??1);while(J<Q)try{return await x()}catch(F){if(console.log(`[HTTP RETRY] ${J} of ${Q}`),console.log(F),J++,J==Q)throw F;if(q?.delay)await s0(q.delay[J-1]??0)}throw Error("Unreachable code")}async function H2(x,q){let J=await r0(async()=>await fetch(x,q));if(!J.ok)throw Error(J.statusText);return await J.json()}async function O2(x,q,J){let Q=await fetch(x,{method:"POST",body:JSON.stringify(q),headers:{"Content-Type":"application/json",...J?.headers},...J});if(!Q.ok)throw Error(Q.statusText);return await Q.json()}async function z2(x,q,J){let Q=await fetch(x,{method:"PUT",body:JSON.stringify(q),headers:{"Content-Type":"application/json",...J?.headers},...J});if(!Q.ok)throw Error(Q.statusText)}var L={delay:s0,retry:r0,get:H2,post:O2,put:z2};class d{endtime=0;lifespan;paused=!1;enqueued=!1;interval;timeout;callback;constructor(x,q,J){if((q??0)<0)throw Error("Lifespan must be greater than 0");if((J??0)<0)throw Error("Interval must be greater than 0");this.interval=J??(navigator?.hardwareConcurrency?100:200/navigator.hardwareConcurrency),this.lifespan=q??this.interval,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 J0{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 Q0{callback;timeout;id;constructor(x,q){if(q<=0)throw Error("Timeout must be greater than 0");this.callback=x,this.timeout=q}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 G0{viewport=void 0;state="idle";provider;interval;onCancel;onError;onMove;onIdle;constructor(x,q,J,Q,F,G){this.provider=x,this.interval=new Q0(this.onInterval.bind(this),q),this.onCancel=J,this.onError=Q,this.onMove=F,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(),q=this.state,J=JSON.stringify(x)!==JSON.stringify(this.viewport)?"move":"idle";if(J=="move")this.onMove();if(J=="idle"&&q=="move")this.onIdle();this.state=J,this.viewport=x}catch(x){this.onError("Failed to process map state interval",x)}}}var i0=75,n0=150,R0=0.00025,p0=1e6,o0=2000000,k0=3000000,F0=10,g=16,h0=2,$=0.5,n="white",t0="darkgreen",K0="0px 2px 2px rgba(0, 0, 0, 0.5)";import W0 from"@arenarium/maps-core/mercator";class p{sw;ne;constructor(x,q,J,Q){if(J<x)throw Error(`Invalid bounds: ${x}, ${q}, ${J}, ${Q}`);if(Q<q)throw Error(`Invalid bounds: ${x}, ${q}, ${J}, ${Q}`);this.sw={lat:x,lng:q},this.ne={lat:J,lng:Q}}contains(x,q){if(x<this.sw.lat||this.ne.lat<x)return!1;if(q<this.sw.lng||this.ne.lng<q)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 b{blockL;blockR;sw;ne;constructor(x,q,J,Q){if(J<x)throw Error(`Invalid bounds: ${x}, ${q}, ${J}, ${Q}`);if(this.sw={lat:x,lng:q},this.ne={lat:J,lng:Q},q<Q)this.blockL=new p(x,q,J,Q),this.blockR=new p(0,0,0,0);else this.blockL=new p(x,-180,J,Q),this.blockR=new p(x,q,J,180)}static normalize(x){let{bounds:q,center:J}=x;if(Math.abs(q.ne.lng-J.lng)+Math.abs(q.sw.lng-J.lng)>360)q.sw.lng=-180,q.ne.lng=180;if(q.ne.lng-q.sw.lng>360){q.sw.lng=-180,q.ne.lng=180;return}if(q.sw.lng<-180)q.sw.lng+=360;if(q.sw.lng>180)q.sw.lng-=360;if(q.ne.lng<-180)q.ne.lng+=360;if(q.ne.lng>180)q.ne.lng-=360}static bounds(x){this.normalize(x);let q=x.bounds,J=q.sw,Q=q.ne;return new b(J.lat,J.lng,Q.lat,Q.lng)}static offset(x,q,J){this.normalize(x);let{bounds:Q,zoom:F}=x,G=q*Math.pow(2,F),j=W0.project(Q.sw.lat,Q.sw.lng,G),U=W0.project(Q.ne.lat,Q.ne.lng,G),V=Math.max(j.x-J.left,0),O=Math.min(j.y+J.bottom,G),B=Math.min(U.x+J.right,G),S=Math.max(U.y-J.top,0),N=W0.unproject(V,O,G),I=W0.unproject(B,S,G);return new b(N.lat,N.lng,I.lat,I.lng)}contains(x,q){return this.blockL.contains(x,q)||this.blockR.contains(x,q)}intersects(x){return this.blockL.intersects(x)||this.blockR.intersects(x)}}class Y0{id;bounds;markers;constructor(x,q){this.id=x,this.bounds=q,this.markers=[]}belongs(x){let q=this.bounds.sw;if(x.lat<q.lat)return!1;if(x.lng<q.lng)return!1;let J=this.bounds.ne;if(J.lat<x.lat)return!1;if(J.lng<x.lng)return!1;return!0}neighbours(x,q){let J=Math.abs(x.id.length-this.id.length);if(J>q)return!1;let Q=Math.min(this.id.length,x.id.length)-q+J;for(let F=0;F<Q;F++)if(this.id[F]!=x.id[F])return!1;return!0}}class Z0{tree;zoom;cell;branches;constructor(x,q,J,Q){this.tree=x,this.zoom=J,this.cell=new Y0(q,Q),this.branches=[]}split(){let x=this.cell.bounds,q=Math.pow(2,this.tree.depth),J=(x.ne.lat-x.sw.lat)/q,Q=(x.ne.lng-x.sw.lng)/q;for(let F=0;F<q;F++)for(let G=0;G<q;G++){let j=x.sw.lat+F*J,U=x.sw.lng+G*Q,V=j+J,O=U+Q;this.branches.push(new Z0(this.tree,`${this.cell.id}${F*2+G}`,this.zoom+this.tree.depth,{sw:{lat:j,lng:U},ne:{lat:V,lng:O}}))}}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 q=0;q<this.branches.length;q++)if(this.branches[q].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=[],q=[];for(let Q=0;Q<this.branches.length;Q++){let F=this.branches[Q];x.push(...F.branches),q.push(...F.cell.markers)}let J=new Z0(this.tree,this.cell.id,this.zoom+this.tree.depth,this.cell.bounds);J.branches=x,J.cell.markers=q,this.branches=[J]}cells(x,q,J){if(x<this.zoom)return J;if(q.intersects(this.cell.bounds)==!1)return J;J.push(this.cell);for(let Q=0;Q<this.branches.length;Q++)this.branches[Q].cells(x,q,J);return J}print(x){console.log(`${"---".repeat(x)}|${this.cell.id} zoom=[${this.zoom}] markers=[${this.cell.markers.length}]`);for(let q=0;q<this.branches.length;q++)this.branches[q].print(x+1)}count(){return this.cell.markers.length+this.branches.reduce((x,q)=>x+q.count(),0)}}class o{capacity;depth;root;constructor(x,q,J){this.capacity=J,this.depth=q,this.root=new Z0(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,q){let J=[];return this.root.cells(x,q,J),J}print(){this.root.print(0)}}var a0=2,e0=1,x2=g*4,q2=1024;class j0{mapProvider;mapMarkersVisibilityTree;mapMarkersVisible;mapMarkerTreeCellCapacity=a0;mapMarkerTreeCellZoomDelta=e0;mapMarkerTreeCellSize=x2;mapMarkerTreeLimit=q2;constructor(x){this.mapProvider=x}set configuration(x){this.mapMarkerTreeCellCapacity=x?.process?.visibility?.cell?.capacity??a0,this.mapMarkerTreeCellZoomDelta=x?.process?.visibility?.cell?.depth??e0,this.mapMarkerTreeCellSize=x?.process?.visibility?.cell?.size??x2,this.mapMarkerTreeLimit=x?.process?.visibility?.limit??q2}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,q){if(this.mapMarkersVisibilityTree==null)return;let J=b.bounds(x),Q=[],F=x.zoom;while(F<q.zoomMax&&Q.length<this.mapMarkerTreeLimit)Q=this.mapMarkersVisibilityTree.cells(F,J).flatMap((G)=>G.markers),F++;this.mapMarkersVisible=Q}createVisibilityTree(x){if(x.length<this.mapMarkerTreeLimit){let q=new o(0,0,x.length);for(let J=0;J<x.length;J++){let Q=x[J];if(!q.add(Q))throw Error("Failed to add marker to fill tree")}return q}else{let q=-Math.floor(Math.log2(this.mapProvider.getParameters().mapSize/this.mapMarkerTreeCellSize)),J=new o(q,this.mapMarkerTreeCellZoomDelta,this.mapMarkerTreeCellCapacity);for(let F=0;F<x.length;F++){let G=x[F];if(!J.add(G))throw Error("Failed to add marker to fill tree")}let Q=-q;for(let F=0;F<Q;F++)J.compact();return J}}}import{mount as I2}from"svelte";import"svelte/internal/disclose-version";import*as K from"svelte/internal/client";import{sineInOut as B2}from"svelte/easing";class m{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 q=(x-this.time.start)/(this.time.end-this.time.start),J=this.animationEasing(q);this.value.current=this.value.start+(this.value.end-this.value.start)*J}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 q=performance.now(),J=Math.abs(this.value.start-this.value.end),Q=this.value.max-this.value.min;if(this.time.start=q,this.time.end=q+this.time.span*Math.sqrt(J/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 q=performance.now();this.time.start=q,this.time.end=q,window.requestAnimationFrame(this.animationRun.bind(this,x))}end(){this.set(this.value.end)}expired(){return performance.now()>this.time.end}}var N2=K.from_html("<div></div>");function S0(x,q){K.push(q,!0);let J=K.rest_props(q,["$$slots","$$events","$$legacy"]),Q=q.id,F=q.style,G=q.content,j={setDisplayed:l,getDisplayed:A,setSuppressed:P,setCollapsed:z,getCollapsed:y,setScale:r};function U(){return j}let V,O=F.dimensions.width,B=F.dimensions.height,S=F.dimensions.radius,N=F.dimensions.padding??h0,I=F.colors?.border??n,D=F.colors?.background??t0,X=F.colors?.shadow??K0,Z=K.state(!1),M=!1,v=!1;function l(Y){if(Y==K.get(Z))return;if(K.set(Z,Y,!0),Y==!0){if(G==null)return;if(v)return;if(M)return;M=!0,G(Q).then((w)=>{if(w instanceof HTMLElement)V.appendChild(w);else console.error("Failed to load pin content")}).catch((w)=>console.error(w)).finally(()=>{v=!0,M=!1})}if(Y==!1)_.end()}function A(){return K.get(Z)}let C=K.state(!0);function P(Y){if(Y==K.get(C))return;if(K.set(C,Y,!0),Y)s=$,_.set($)}let H=K.state(!0);function z(Y){if(Y==K.get(H))return;K.set(H,Y,!0),_.target(K.get(H)?0:s)}function y(){if(!K.get(Z))return!0;return _.expired()}let s=$,_=new m({value:$,min:0,max:1,timespan:i0,easing:B2,callback:y0});function r(Y){s=Y,_.target(Y)}function y0(Y){V.style.scale=Y.toString(),V.style.filter=`brightness(${e(Y)})`}function e(Y){return 0.25+0.75*Y}var b0={invoke:U},T=N2();let x0;return K.bind_this(T,(Y)=>V=Y,()=>V),K.template_effect((Y)=>{K.set_class(T,1,K.clsx(["pin",K.get(Z)&&"displayed",K.get(C)&&"suppressed"]),"svelte-e30vfn4rttu1"),x0=K.set_style(T,"",x0,Y)},[()=>({width:`${O}px`,height:`${B}px`,"border-radius":`${S}px`,"border-color":I,"background-color":D,"border-width":`${N}px`,"box-shadow":X,scale:$,filter:`brightness(${e($)})`})]),K.append(x,T),K.pop(b0)}class E{div;marker;constructor(x,q,J,Q){this.div=document.createElement("div"),this.marker=x.createMarker(this.div,q,J,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 k{shown;id;lat;lng;rank;marker;constructor(x,q){if(new.target===k)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=q}}class V0 extends k{width;height;zoom;component;constructor(x,q){super(x,new E(q,x.lat,x.lng,x.rank));let J=x.pin?.style.dimensions.width??g,Q=x.pin?.style.dimensions.height??g,F=x.pin?.style.dimensions.padding??h0,G=x.pin?.style.dimensions.radius??g/2;this.width=J,this.height=Q,this.zoom=NaN,this.component=I2(S0,{target:this.marker.div,props:{id:this.id,style:{dimensions:{width:J,height:Q,padding:F,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*F0)+p0}}import{mount as D2}from"svelte";import"svelte/internal/disclose-version";import*as h from"svelte/internal/client";import{sineInOut as y2}from"svelte/easing";class t{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(),q=x-this.animationTimestamp;if(this.animationTimestamp=x,x>=this.animationEnd){this.speed.current=0,this.value.current=this.value.target;return}let J=this.value.target-this.value.current;if(Math.abs(J)<this.value.precision){this.speed.current=0,this.value.current=this.value.target;return}let Q=J*this.speed.spring.stiffness-this.speed.spring.damping*this.speed.current;if(this.speed.current+=Q*q,this.value.current+=this.speed.current*q,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 q=Math.sqrt(2*Math.abs(x-this.value.current)/this.speed.spring.stiffness);if(this.animationEnd=performance.now()+q,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 J2 from"@arenarium/maps-core/rectangle";var b2=h.from_html('<div><div class="element pointer svelte-vkqe2rkto2oe"></div> <div class="element tooltip svelte-vkqe2rkto2oe"><div class="element body svelte-vkqe2rkto2oe"></div></div></div>');function a(x,q){h.push(q,!0);let J=h.rest_props(q,["$$slots","$$events","$$legacy"]),Q=q.id,F=q.style,G=q.content,j={setDisplayed:s,getDisplayed:_,setCollapsed:y0,getCollapsed:e,getExpanded:b0,setAngle:h2};function U(){return j}let V,O=F.colors?.shadow??K0,B,S=Math.min(F.dimensions.width,F.dimensions.height)/Math.SQRT2,N=Math.min(F.dimensions.width,F.dimensions.height)/Math.SQRT2,I=F.colors?.background??n,D,X=F.dimensions.width+2*F.dimensions.margin,Z=F.dimensions.height+2*F.dimensions.margin,M=F.dimensions.margin,v,l=F.dimensions.width,A=F.dimensions.height,C=F.dimensions.radius,P=F.colors?.background??n,H=h.state(!1),z=!1,y=!1;function s(W){if(W==h.get(H))return;if(h.set(H,W,!0),W){if(G==null)return;if(y)return;if(z)return;z=!0,G(Q).then((f)=>{if(f instanceof HTMLElement)v.appendChild(f);else console.error("Failed to load tooltip content")}).catch((f)=>console.error(f)).finally(()=>{y=!0,z=!1})}if(W==!1)T.end(),D0.end(),v0.end()}function _(){return h.get(H)}let r=h.state(!0);function y0(W){if(W==h.get(r))return;h.set(r,W,!0),T.target(h.get(r)?0:1)}function e(){if(!h.get(H))return!0;return T.expired()}function b0(){if(!h.get(H))return!1;return T.expired()}let T=new m({value:0,min:0,max:1,timespan:n0,easing:y2,callback:x0});function x0(W){V.style.opacity=`${W}`,D.style.scale=`${W}`,B.style.scale=`${W}`}let Y=NaN,w=h.state(!1),_0=-X/2,D0=new t({value:-X/2,min:-X,max:0,precision:1,stiffness:R0,callback:K2}),$0=-Z/2,v0=new t({value:-Z/2,min:-Z,max:0,precision:1,stiffness:R0,callback:W2});function h2(W,f){if(Number.isNaN(W)){Y=NaN,h.set(w,!1);return}if(h.get(w)==!1||f==!0){h.set(w,!0),Y=W;let R=J2.getOffsets(X,Z,W);D0.set(Math.round(R.x)),v0.set(Math.round(R.y));return}if(Y!=W){Y=W;let R=J2.getOffsets(X,Z,W);D0.target(Math.round(R.x)),v0.target(Math.round(R.y));return}}function K2(W){_0=W,E0()}function W2(W){$0=W,E0()}function E0(){let W=_0,f=$0,R=W+X/2,m0=f+Z/2,T0=Z<X?R*Z/X:R,f0=Z>X?m0*X/Z:m0,Z2=Math.atan2(f0,T0),u2=0,L2=30,w0=Math.sqrt(T0*T0+f0*f0),i=Math.min(X,Z)/2,j2=i*Math.SQRT2,V2=(w0-i)/(j2-i),X2=Z2/Math.PI*180-45,l0=0+V2*30,U2=w0<i?w0/i:1;D.style.transform=`translate(${Math.round(W)}px, ${Math.round(f)}px)`,B.style.transform=`scale(${U2}) rotate(${X2}deg) skew(${l0}deg, ${l0}deg)`}var Y2={invoke:U},u=b2();let c0;var C0=h.child(u);let u0;h.bind_this(C0,(W)=>B=W,()=>B);var q0=h.sibling(C0,2);let L0;var d0=h.child(q0);let g0;return h.bind_this(d0,(W)=>v=W,()=>v),h.reset(q0),h.bind_this(q0,(W)=>D=W,()=>D),h.reset(u),h.bind_this(u,(W)=>V=W,()=>V),h.template_effect(()=>{h.set_class(u,1,h.clsx(["element anchor",h.get(H)&&"displayed"]),"svelte-vkqe2rkto2oe"),c0=h.set_style(u,"",c0,{filter:`drop-shadow(${O})`}),u0=h.set_style(C0,"",u0,{width:`${S}px`,height:`${N}px`,"background-color":I}),L0=h.set_style(q0,"",L0,{width:`${X}px`,height:`${Z}px`,padding:`${M}px;`}),g0=h.set_style(d0,"",g0,{width:`${l}px`,height:`${A}px`,"border-radius":`${C}px;`,"background-color":P})}),h.append(x,u),h.pop(Y2)}class X0 extends k{width;height;zoom;angle;states;component;constructor(x,q){super(x,new E(q,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=D2(a,{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*F0)+o0}}import{mount as v2}from"svelte";class U0 extends k{width;height;margin;angle;component;constructor(x,q){if(x.popup==null)throw Error("Failed to create popup");super(x,new E(q,x.lat,x.lng,k0));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=v2(a,{target:this.marker.div,props:{id:this.id,style:x.popup.style,content:x.popup.body}})}get zIndex(){return k0}}class H0{id;state=void 0;pin;tooltip;popup;constructor(x,q){if(this.id=x.id,this.pin=new V0(x,q),this.tooltip=new X0(x,q),x.popup!=null)this.popup=new U0(x,q)}}var M0=4;class O0{pins=new Set;pinMaxWidth=0;pinMaxHeight=0;pinFade=!1;pinZoomMax=M0;pinZoomDelta=M0;set configuration(x){this.pinFade=x?.pin?.fade??!0,this.pinZoomMax=x?.pin?.maxZoom??M0,this.pinZoomDelta=this.pinZoomMax}insert(x,q){this.update(x,q),this.pins.add(x)}update(x,q){x.zoom=q?q[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((q,J)=>Math.max(q,J.width),0),this.pinMaxHeight=x.reduce((q,J)=>Math.max(q,J.height),0),this.pinZoomDelta=Math.max(1,this.pinZoomMax-Math.log10(x.length))}render(x,q){let J=x.zoom,Q=q.mapSize,F=b.offset(x,Q,{top:this.pinMaxHeight,bottom:this.pinMaxHeight,right:this.pinMaxWidth,left:this.pinMaxWidth});for(let G of this.pins)if(F.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&&J<G.zoom&&G.zoom<J+this.pinZoomDelta)G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setScale(this.pinFade?Math.max(0,1-(G.zoom-J)*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 C2 from"@arenarium/maps-core/angles";class z0{tooltips=new Set;tooltipMaxWidth=0;tooltipMaxHeight=0;insert(x,q){this.update(x,q),this.tooltips.add(x)}update(x,q){if(q)x.zoom=q[0],x.states=q[1].map((J)=>[J[0],C2.DEGREES[J[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((q,J)=>Math.max(q,J.width),0),this.tooltipMaxHeight=x.reduce((q,J)=>Math.max(q,J.height),0)}render(x,q){let J=x.zoom,Q=q.mapSize,F=b.offset(x,Q,{top:this.tooltipMaxHeight,bottom:this.tooltipMaxHeight,right:this.tooltipMaxWidth,left:this.tooltipMaxWidth});for(let G of this.tooltips)if(F.contains(G.lat,G.lng)){if(Number.isNaN(G.zoom)==!1&&G.shown&&G.zoom<=J){let j=G.states.findLast((U)=>U[0]<=J)?.[1];if(j==null)throw Error("Angle not found");G.angle=j,G.component.invoke().setDisplayed(!0),G.component.invoke().setCollapsed(!1),G.component.invoke().setAngle(j),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 A0 from"@arenarium/maps-core/mercator";import T2 from"@arenarium/maps-core/rectangle";class B0{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,q){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 J=x.popup,Q=q.getViewport(),F=Q.bounds,G=Q.zoom,U=q.getParameters().mapSize*Math.pow(2,G),V=A0.project(F.ne.lat,F.sw.lng,U),O=A0.project(F.sw.lat,F.ne.lng,U),B=O.x-V.x,S=O.y-V.y,N=J.width+J.margin*8,I=J.height+J.margin*8,D=A0.project(J.lat,J.lng,U),X=T2.getOffsets(N,I,x.tooltip.angle),Z=D.x+X.x,M=Z+N,v=D.y+X.y,l=v+I,A=Z-V.x,C=O.x-M,P=v-V.y,H=O.y-l,z=0;if(B<N)z=(A-C)/2;else{if(A<0)z=A;if(C<0)z=-C}let y=0;if(S<I)y=(P-H)/2;else{if(P<0)y=P;if(H<0)y=-H}if(z!=0||y!=0)q.panBy(z,y)}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 N0{mapProvider;mapPinManager;mapTooltipManager;mapPopupManager;mapElements;constructor(x){this.mapProvider=x,this.mapPinManager=new O0,this.mapTooltipManager=new z0,this.mapPopupManager=new B0,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 q of x){let J=this.mapElements.get(q.data.id);if(J==null)continue;if(this.mapPinManager.remove(J.pin),this.mapTooltipManager.remove(J.tooltip),J.popup!=null)this.mapPopupManager.remove(J.popup)}this.mapPinManager.refresh(),this.mapTooltipManager.refresh()}updateElements(x){for(let q of x){let J=this.mapElements.get(q.data.id);if(J==null)continue;this.mapPinManager.update(J.pin,q.state),this.mapTooltipManager.update(J.tooltip,q.state)}}insertElements(x,q){for(let J of x){let Q=this.mapElements.get(J.data.id);if(Q==null)Q=new H0(J.data,this.mapProvider),Q.tooltip.marker.div.addEventListener("click",(F)=>q(F,J.data.id)),this.mapElements.set(J.data.id,Q);if(this.mapPinManager.insert(Q.pin,J.state),this.mapTooltipManager.insert(Q.tooltip,J.state),Q.popup!=null)this.mapPopupManager.insert(Q.popup)}this.mapPinManager.refresh(),this.mapTooltipManager.refresh()}renderElements(x,q){this.mapPopupManager.render(),this.mapTooltipManager.render(x,q),this.mapPinManager.render(x,q)}showPopup(x){let q=this.mapElements.values();for(let J of q)if(J.id==x)this.mapPopupManager.show(J,this.mapProvider);else this.mapPopupManager.hide(J)}hidePopup(x){let q=this.mapElements.get(x);if(q==null)return;this.mapPopupManager.hide(q)}hidePopups(){let x=this.mapElements.values();for(let q of x)this.mapPopupManager.hide(q)}}import f2 from"@arenarium/maps-core/hash";import Q2 from"@arenarium/maps-core/angles";var w2="https://maps.api.arenarium.dev/states",R2=3,k2=[500,1000,2000];class I0{apiKey;apiToken;apiDevEnvironment;mapMarkerStatesStore;constructor(x,q){this.apiKey=x,this.apiToken=q,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 q=0;q<x.length;q++){let J=x[q];J.state=void 0}}async updateStates(x,q){if(x.length==0)return;x.sort((G,j)=>G.data.id.localeCompare(j.data.id));let J=x.map((G)=>G.input),Q=f2.object(J),F=this.mapMarkerStatesStore.get(Q);if(F==null)F=await this.fetchStates(J,q),this.mapMarkerStatesStore.set(Q,F);for(let G=0;G<x.length;G++){let j=x[G];j.state=F[G]}}async fetchStates(x,q){if(x.length==0)return[];if(x.length==1)return[[0,[[0,Q2.DEGREES.indexOf(Q2.DEGREES_DEFAULT)]]]];let J={key:this.apiKey,token:this.apiToken,input:x,parameters:q},Q=await L.retry(async()=>await L.post(w2,J,{headers:{"Cache-Control":this.apiDevEnvironment?"no-cache":""},retry:R2,delay:k2}));if(Q.token)this.apiToken=Q.token;return Q.states}}import{apiKeySchema as S2,apiTokenSchema as M2,mapMarkerDataSchema as A2,mapProviderSchema as P2}from"@arenarium/maps-core/schemas";import*as c from"valibot";var G2="1.2.8",_2="https://maps.api.arenarium.dev/auth",$2="https://maps.api.arenarium.dev/log",E2=100,F2=500,c2=500;class P0{apiKey;mapProvider;mapMarkers;mapMarkersVisibilityManager;mapMarkerElementsManager;mapMarkerStatesManager;mapMarkerRenderProcessor;mapMarkerVisibilityProcessor;mapMarkerStateProcessor;mapMarkerStatesProcessDelay=500;mapMarkerStatesProcessTimeout=void 0;mapStateManager;constructor(x,q,J,Q){c.parse(S2,x),c.parse(M2,q),c.parse(P2,J),this.apiKey=x,this.mapProvider=J,this.mapProvider.getContainer().addEventListener("click",this.onMapClick.bind(this)),this.mapMarkers=new Map,this.mapMarkersVisibilityManager=new j0(this.mapProvider),this.mapMarkerElementsManager=new N0(this.mapProvider),this.mapMarkerStatesManager=new I0(x,q),this.mapMarkerRenderProcessor=new d(this.onMapMarkerRenderProcess.bind(this),F2),this.mapMarkerVisibilityProcessor=new d(this.onMapMarkerVisiblityProcess.bind(this),F2),this.mapMarkerStateProcessor=new d(this.onMapMarkerStateProcess.bind(this)),this.mapStateManager=new G0(this.mapProvider,E2/(navigator?.hardwareConcurrency??1),this.dettached.bind(this),this.error.bind(this),this.onMapMove.bind(this),this.onMapIdle.bind(this)),this.configuration=Q}static async create(x,q,J){let Q={key:x,version:G2},G=(await L.post(_2,Q)).token;if(!G)throw Error("Failed to get api token");return new P0(x,G,q,J)}set configuration(x){this.mapMarkerStatesProcessDelay=x?.process?.states?.delay??c2,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()}dettached(){return this.mapProvider.getContainer().parentElement==null}error(x,q){this.log("error",x,q),this.configuration?.events?.error?.(x,q)}async log(x,q,J){switch(x){case"info":console.info(J);break;case"warning":console.warn(J);break;case"error":console.error(J);break}if(J instanceof Error==!1)return;try{let Q={key:this.apiKey,title:q,level:x,content:{version:G2,...J}};await L.put($2,Q)}catch(Q){console.error(Q)}}onMapClick(){this.hidePopup()}onMapMarkerClick(x,q){x.stopPropagation(),this.showPopup(q)}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.dettached())return!0;let x=this.mapProvider.getViewport(),q=this.mapProvider.getParameters(),J=new Set(this.mapMarkersVisibilityManager.markers);this.mapMarkersVisibilityManager.updateVisibleMarkers(x,q);let Q=new Set(this.mapMarkersVisibilityManager.markers),F=Array.from(J.difference(Q)),G=Array.from(Q.difference(J));return this.mapMarkerStatesManager.resetStates(F),this.mapMarkerElementsManager.removeElements(F),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.dettached())return!0;let x=this.mapMarkersVisibilityManager.markers,q=this.mapProvider.getParameters();return await this.mapMarkerStatesManager.updateStates(x,q),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.dettached())return!0;let x=this.mapProvider.getViewport(),q=this.mapProvider.getParameters();return this.mapMarkerElementsManager.renderElements(x,q),!1}catch(x){return this.clear(),this.error("Failed to process map render",x),!0}}updateMarkers(x){c.parse(c.array(A2),x);try{for(let J of x)if(this.mapMarkers.has(J.id)==!1)this.mapMarkers.set(J.id,new J0(J));let q=Array.from(this.mapMarkers.values());q.sort((J,Q)=>Q.data.rank-J.data.rank),this.mapMarkersVisibilityManager.insertMarkers(q),this.mapStateManager.start(),this.mapMarkerVisibilityProcessor.start(),this.mapMarkerStateProcessor.start(),this.mapMarkerRenderProcessor.start()}catch(q){throw this.clear(),this.error("Failed to update markers",q),q}}removeMarkers(){try{this.clear()}catch(x){throw this.error("Failed to remove markers",x),x}}showPopup(x){try{this.mapMarkerElementsManager.showPopup(x)}catch(q){throw this.mapMarkerElementsManager.hidePopups(),this.error("Failed to show popup",q),q}finally{this.mapMarkerRenderProcessor.start()}}hidePopup(){try{this.mapMarkerElementsManager.hidePopups()}catch(x){throw this.error("Failed to hide popup",x),x}finally{this.mapMarkerRenderProcessor.start()}}}export{P0 as MapManager};
1
+ class r{endtime=0;lifespan;paused=!1;enqueued=!1;interval;timeout;callback;constructor(x,q,Q){if((q??0)<0)throw Error("Lifespan must be greater than 0");if((Q??0)<0)throw Error("Interval must be greater than 0");let G=navigator?.hardwareConcurrency?200/navigator.hardwareConcurrency:100;this.interval=Q??G;let h=this.interval;this.lifespan=q??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 z0{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 B0{callback;timeout;id;constructor(x,q){if(q<=0)throw Error("Timeout must be greater than 0");this.callback=x,this.timeout=q}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 y0{viewport=void 0;state="idle";provider;interval;onCancel;onError;onMove;onIdle;constructor(x,q,Q,G,h,J){this.provider=x,this.interval=new B0(this.onInterval.bind(this),q),this.onCancel=Q,this.onError=G,this.onMove=h,this.onIdle=J}start(){this.interval.start()}stop(){this.interval.stop()}onInterval(){try{if(this.onCancel()){this.interval.stop();return}let x=this.provider.getViewport(),q=this.state,Q=JSON.stringify(x)!==JSON.stringify(this.viewport)?"move":"idle";if(Q=="move")this.onMove();if(Q=="idle"&&q=="move")this.onIdle();this.state=Q,this.viewport=x}catch(x){this.onError("Failed to process map state interval",x)}}}var i0=75,p0=150,b0=0.00025,n0=1e6,o0=2000000,N0=3000000,x0=10,L=16,q0=2,_=0.5,i="white",t0="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,q,Q,G){if(Q<x)throw Error(`Invalid bounds: ${x}, ${q}, ${Q}, ${G}`);if(G<q)throw Error(`Invalid bounds: ${x}, ${q}, ${Q}, ${G}`);this.sw={lat:x,lng:q},this.ne={lat:Q,lng:G}}contains(x,q){if(x<this.sw.lat||this.ne.lat<x)return!1;if(q<this.sw.lng||this.ne.lng<q)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 C{blockL;blockR;sw;ne;constructor(x,q,Q,G){if(Q<x)throw Error(`Invalid bounds: ${x}, ${q}, ${Q}, ${G}`);if(this.sw={lat:x,lng:q},this.ne={lat:Q,lng:G},q<G)this.blockL=new p(x,q,Q,G),this.blockR=new p(0,0,0,0);else this.blockL=new p(x,-180,Q,G),this.blockR=new p(x,q,Q,180)}static normalize(x){let{bounds:q,center:Q}=x;if(Math.abs(q.ne.lng-Q.lng)+Math.abs(q.sw.lng-Q.lng)>360)q.sw.lng=-180,q.ne.lng=180;if(q.ne.lng-q.sw.lng>360){q.sw.lng=-180,q.ne.lng=180;return}if(q.sw.lng<-180)q.sw.lng+=360;if(q.sw.lng>180)q.sw.lng-=360;if(q.ne.lng<-180)q.ne.lng+=360;if(q.ne.lng>180)q.ne.lng-=360}static bounds(x){this.normalize(x);let q=x.bounds,Q=q.sw,G=q.ne;return new C(Q.lat,Q.lng,G.lat,G.lng)}static offset(x,q,Q){this.normalize(x);let{bounds:G,zoom:h}=x,J=q*Math.pow(2,h),Y=d.project(G.sw.lat,G.sw.lng,J),X=d.project(G.ne.lat,G.ne.lng,J),Z=Math.max(Y.x-Q.left,0),O=Math.min(Y.y+Q.bottom,J),B=Math.min(X.x+Q.right,J),S=Math.max(X.y-Q.top,0),y=d.unproject(Z,O,J),b=d.unproject(B,S,J);return new C(y.lat,y.lng,b.lat,b.lng)}contains(x,q){return this.blockL.contains(x,q)||this.blockR.contains(x,q)}intersects(x){return this.blockL.intersects(x)||this.blockR.intersects(x)}}class I0{id;bounds;markers;constructor(x,q){this.id=x,this.bounds=q,this.markers=[]}belongs(x){let q=this.bounds.sw;if(x.lat<q.lat)return!1;if(x.lng<q.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,q){let Q=Math.abs(x.id.length-this.id.length);if(Q>q)return!1;let G=Math.min(this.id.length,x.id.length)-q+Q;for(let h=0;h<G;h++)if(this.id[h]!=x.id[h])return!1;return!0}}class G0{tree;zoom;cell;branches;constructor(x,q,Q,G){this.tree=x,this.zoom=Q,this.cell=new I0(q,G),this.branches=[]}split(){let x=this.cell.bounds,q=Math.pow(2,this.tree.depth),Q=(x.ne.lat-x.sw.lat)/q,G=(x.ne.lng-x.sw.lng)/q;for(let h=0;h<q;h++)for(let J=0;J<q;J++){let Y=x.sw.lat+h*Q,X=x.sw.lng+J*G,Z=Y+Q,O=X+G;this.branches.push(new G0(this.tree,`${this.cell.id}${h*2+J}`,this.zoom+this.tree.depth,{sw:{lat:Y,lng:X},ne:{lat:Z,lng:O}}))}}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 q=0;q<this.branches.length;q++)if(this.branches[q].add(x))return!0;throw Error("Failed to add marker to branch")}compact(){if(this.branches.length==0)return;for(let G=0;G<this.branches.length;G++)this.branches[G].compact();let x=[],q=[];for(let G=0;G<this.branches.length;G++){let h=this.branches[G];x.push(...h.branches),q.push(...h.cell.markers)}let Q=new G0(this.tree,this.cell.id,this.zoom+this.tree.depth,this.cell.bounds);Q.branches=x,Q.cell.markers=q,this.branches=[Q]}cells(x,q,Q){if(x<this.zoom)return Q;if(q.intersects(this.cell.bounds)==!1)return Q;Q.push(this.cell);for(let G=0;G<this.branches.length;G++)this.branches[G].cells(x,q,Q);return Q}print(x){console.log(`${"---".repeat(x)}|${this.cell.id} zoom=[${this.zoom}] markers=[${this.cell.markers.length}]`);for(let q=0;q<this.branches.length;q++)this.branches[q].print(x+1)}count(){return this.cell.markers.length+this.branches.reduce((x,q)=>x+q.count(),0)}}class J0{capacity;depth;root;constructor(x,q,Q){this.capacity=Q,this.depth=q,this.root=new G0(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,q){let Q=[];return this.root.cells(x,q,Q),Q}print(){this.root.print(0)}}var a0=2,e0=1,x2=L*4,q2=1024;class D0{mapProvider;mapMarkersVisibilityTree;mapMarkersVisible;mapMarkerTreeCellCapacity=a0;mapMarkerTreeCellZoomDelta=e0;mapMarkerTreeCellSize=x2;mapMarkerTreeLimit=q2;constructor(x){this.mapProvider=x}set configuration(x){this.mapMarkerTreeCellCapacity=x?.process?.visibility?.cell?.capacity??a0,this.mapMarkerTreeCellZoomDelta=x?.process?.visibility?.cell?.depth??e0,this.mapMarkerTreeCellSize=x?.process?.visibility?.cell?.size??x2,this.mapMarkerTreeLimit=x?.process?.visibility?.limit??q2}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,q){if(this.mapMarkersVisibilityTree==null)return;let Q=C.bounds(x),G=[],h=x.zoom;while(h<q.zoomMax&&G.length<this.mapMarkerTreeLimit)G=this.mapMarkersVisibilityTree.cells(h,Q).flatMap((J)=>J.markers),h++;this.mapMarkersVisible=G}createVisibilityTree(x){if(x.length<this.mapMarkerTreeLimit){let q=new J0(0,0,x.length);for(let Q=0;Q<x.length;Q++){let G=x[Q];if(!q.add(G))throw Error("Failed to add marker to fill tree")}return q}else{let q=-Math.floor(Math.log2(this.mapProvider.getParameters().mapSize/this.mapMarkerTreeCellSize)),Q=new J0(q,this.mapMarkerTreeCellZoomDelta,this.mapMarkerTreeCellCapacity);for(let h=0;h<x.length;h++){let J=x[h];if(!Q.add(J))throw Error("Failed to add marker to fill tree")}let G=-q;for(let h=0;h<G;h++)Q.compact();return Q}}}import{mount as y2}from"svelte";class E{div;marker;constructor(x,q,Q,G){this.div=document.createElement("div"),this.marker=x.createMarker(this.div,q,Q,G)}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 R{shown;id;lat;lng;rank;marker;constructor(x,q){if(new.target===R)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=q}}import"svelte/internal/disclose-version";import*as K from"svelte/internal/client";import{sineInOut as z2}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 q=(x-this.time.start)/(this.time.end-this.time.start),Q=this.animationEasing(q);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 q=performance.now(),Q=Math.abs(this.value.start-this.value.end),G=this.value.max-this.value.min;if(this.time.start=q,this.time.end=q+this.time.span*Math.sqrt(Q/G),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 q=performance.now();this.time.start=q,this.time.end=q,window.requestAnimationFrame(this.animationRun.bind(this,x))}end(){this.set(this.value.end)}expired(){return performance.now()>this.time.end}}var B2=K.from_html("<div></div>");function T0(x,q){K.push(q,!0);let Q=K.rest_props(q,["$$slots","$$events","$$legacy"]),G=q.id,h=q.style,J=q.content,Y={setDisplayed:g,getDisplayed:A,setSuppressed:$,setCollapsed:z,getCollapsed:N,setScale:m};function X(){return Y}let Z,O=h.dimensions.width,B=h.dimensions.height,S=h.dimensions.radius,y=h.dimensions.padding??q0,b=h.colors?.border??i,I=h.colors?.background??t0,V=h.colors?.shadow??Q0,H=K.state(!1),w=!1,D=!1;function g(j){if(j==K.get(H))return;if(K.set(H,j,!0),j==!0){if(J==null)return;if(D)return;if(w)return;w=!0,J(G).then((k)=>{if(k instanceof HTMLElement)Z.appendChild(k);else console.error("Failed to load pin content")}).catch((k)=>console.error(k)).finally(()=>{D=!0,w=!1})}if(j==!1)P.end()}function A(){return K.get(H)}let T=K.state(!0);function $(j){if(j==K.get(T))return;if(K.set(T,j,!0),j)s=_,P.set(_)}let U=K.state(!0);function z(j){if(j==K.get(U))return;K.set(U,j,!0),P.target(K.get(U)?0:s)}function N(){if(!K.get(H))return!0;return P.expired()}let s=_,P=new n({value:_,min:0,max:1,timespan:i0,easing:z2,callback:j0});function m(j){s=j,P.target(j)}function j0(j){Z.style.scale=j.toString(),Z.style.filter=`brightness(${t(j)})`}function t(j){return 0.25+0.75*j}var H0={invoke:X},v=B2();let a;return K.bind_this(v,(j)=>Z=j,()=>Z),K.template_effect((j)=>{K.set_class(v,1,K.clsx(["pin",K.get(H)&&"displayed",K.get(T)&&"suppressed"]),"svelte-e30vfn4rttu1"),a=K.set_style(v,"",a,j)},[()=>({width:`${O}px`,height:`${B}px`,"border-radius":`${S}px`,"border-color":b,"background-color":I,"border-width":`${y}px`,"box-shadow":V,scale:_,filter:`brightness(${t(_)})`})]),K.append(x,v),K.pop(H0)}class v0 extends R{width;height;zoom;component;constructor(x,q){super(x,new E(q,x.lat,x.lng,x.rank));let Q=x.pin?.style.dimensions.width??L,G=x.pin?.style.dimensions.height??L,h=x.pin?.style.dimensions.padding??q0,J=x.pin?.style.dimensions.radius??L/2;this.width=Q,this.height=G,this.zoom=NaN,this.component=y2(T0,{target:this.marker.div,props:{id:this.id,style:{dimensions:{width:Q,height:G,padding:h,radius:J},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)+n0}}import{mount as I2}from"svelte";import"svelte/internal/disclose-version";import*as F from"svelte/internal/client";import{sineInOut as b2}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(),q=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 G=Q*this.speed.spring.stiffness-this.speed.spring.damping*this.speed.current;if(this.speed.current+=G*q,this.value.current+=this.speed.current*q,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 q=Math.sqrt(2*Math.abs(x-this.value.current)/this.speed.spring.stiffness);if(this.animationEnd=performance.now()+q,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 f0 from"@arenarium/maps-core/rectangle";var N2=F.from_html('<div><div class="element pointer svelte-vkqe2rkto2oe"></div> <div class="element tooltip svelte-vkqe2rkto2oe"><div class="element body svelte-vkqe2rkto2oe"></div></div></div>');function o(x,q){F.push(q,!0);let Q=F.rest_props(q,["$$slots","$$events","$$legacy"]),G=q.id,h=q.style,J=q.content,Y={setDisplayed:s,getDisplayed:P,setCollapsed:j0,getCollapsed:t,getExpanded:H0,setAngle:W2};function X(){return Y}let Z,O=h.colors?.shadow??Q0,B,S=Math.min(h.dimensions.width,h.dimensions.height)/Math.SQRT2,y=Math.min(h.dimensions.width,h.dimensions.height)/Math.SQRT2,b=h.colors?.background??i,I,V=h.dimensions.width+2*h.dimensions.margin,H=h.dimensions.height+2*h.dimensions.margin,w=h.dimensions.margin,D,g=h.dimensions.width,A=h.dimensions.height,T=h.dimensions.radius,$=h.colors?.background??i,U=F.state(!1),z=!1,N=!1;function s(W){if(W==F.get(U))return;if(F.set(U,W,!0),W){if(J==null)return;if(N)return;if(z)return;z=!0,J(G).then((f)=>{if(f instanceof HTMLElement)D.appendChild(f);else console.error("Failed to load tooltip content")}).catch((f)=>console.error(f)).finally(()=>{N=!0,z=!1})}if(W==!1)v.end(),Y0.end(),Z0.end()}function P(){return F.get(U)}let m=F.state(!0);function j0(W){if(W==F.get(m))return;F.set(m,W,!0),v.target(F.get(m)?0:1)}function t(){if(!F.get(U))return!0;return v.expired()}function H0(){if(!F.get(U))return!1;return v.expired()}let v=new n({value:0,min:0,max:1,timespan:p0,easing:b2,callback:a});function a(W){Z.style.opacity=`${W}`,I.style.scale=`${W}`,B.style.scale=`${W}`}let j=NaN,k=F.state(!1),E0=-V/2,Y0=new h0({value:-V/2,min:-V,max:0,precision:1,stiffness:b0,callback:j2}),c0=-H/2,Z0=new h0({value:-H/2,min:-H,max:0,precision:1,stiffness:b0,callback:H2});function W2(W,f){if(Number.isNaN(W)){j=NaN,F.set(k,!1);return}if(F.get(k)==!1||f==!0){F.set(k,!0),j=W;let M=f0.offsets(V,H,W);Y0.set(Math.round(M.x)),Z0.set(Math.round(M.y));return}if(j!=W){j=W;let M=f0.offsets(V,H,W);Y0.target(Math.round(M.x)),Z0.target(Math.round(M.y));return}}function j2(W){E0=W,u0()}function H2(W){c0=W,u0()}function u0(){let W=E0,f=c0,M=W+V/2,l0=f+H/2,X0=H<V?M*H/V:M,U0=H>V?l0*V/H:l0,Z2=Math.atan2(U0,X0),P2=0,_2=30,O0=Math.sqrt(X0*X0+U0*U0),l=Math.min(V,H)/2,V2=l*Math.SQRT2,X2=(O0-l)/(V2-l),U2=Z2/Math.PI*180-45,r0=0+X2*30,O2=O0<l?O0/l:1;I.style.transform=`translate(${Math.round(W)}px, ${Math.round(f)}px)`,B.style.transform=`scale(${O2}) rotate(${U2}deg) skew(${r0}deg, ${r0}deg)`}var Y2={invoke:X},u=N2();let L0;var V0=F.child(u);let d0;F.bind_this(V0,(W)=>B=W,()=>B);var e=F.sibling(V0,2);let g0;var s0=F.child(e);let m0;return F.bind_this(s0,(W)=>D=W,()=>D),F.reset(e),F.bind_this(e,(W)=>I=W,()=>I),F.reset(u),F.bind_this(u,(W)=>Z=W,()=>Z),F.template_effect(()=>{F.set_class(u,1,F.clsx(["element anchor",F.get(U)&&"displayed"]),"svelte-vkqe2rkto2oe"),L0=F.set_style(u,"",L0,{filter:`drop-shadow(${O})`}),d0=F.set_style(V0,"",d0,{width:`${S}px`,height:`${y}px`,"background-color":b}),g0=F.set_style(e,"",g0,{width:`${V}px`,height:`${H}px`,padding:`${w}px`}),m0=F.set_style(s0,"",m0,{width:`${g}px`,height:`${A}px`,"border-radius":`${T}px`,"background-color":$})}),F.append(x,u),F.pop(Y2)}class C0 extends R{width;height;zoom;angle;states;component;constructor(x,q){super(x,new E(q,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=I2(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)+o0}}import{mount as D2}from"svelte";class k0 extends R{width;height;margin;angle;component;constructor(x,q){if(x.popup==null)throw Error("Failed to create popup");super(x,new E(q,x.lat,x.lng,N0));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=D2(o,{target:this.marker.div,props:{id:this.id,style:x.popup.style,content:x.popup.body}})}get zIndex(){return N0}}class M0{id;state=void 0;pin;tooltip;popup;constructor(x,q){if(this.id=x.id,this.pin=new v0(x,q),this.tooltip=new C0(x,q),x.popup!=null)this.popup=new k0(x,q)}}var R0=4;class S0{pins=new Set;pinMaxWidth=0;pinMaxHeight=0;pinFade=!1;pinZoomMax=R0;pinZoomDelta=R0;set configuration(x){this.pinFade=x?.pin?.fade??!0,this.pinZoomMax=x?.pin?.maxZoom??R0,this.pinZoomDelta=this.pinZoomMax}insert(x,q){this.update(x,q),this.pins.add(x)}update(x,q){x.zoom=q?q[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((q,Q)=>Math.max(q,Q.width),0),this.pinMaxHeight=x.reduce((q,Q)=>Math.max(q,Q.height),0),this.pinZoomDelta=Math.max(1,this.pinZoomMax-Math.log10(x.length))}render(x,q){let Q=x.zoom,G=q.mapSize,h=C.offset(x,G,{top:this.pinMaxHeight,bottom:this.pinMaxHeight,right:this.pinMaxWidth,left:this.pinMaxWidth});for(let J of this.pins)if(h.contains(J.lat,J.lng)){if(Number.isNaN(J.zoom))J.component.invoke().setDisplayed(!0),J.component.invoke().setSuppressed(!0),J.component.invoke().setCollapsed(!1),J.marker.insert();else if(J.component.invoke().setSuppressed(!1),J.shown&&Q<J.zoom&&J.zoom<Q+this.pinZoomDelta)J.component.invoke().setDisplayed(!0),J.component.invoke().setCollapsed(!1),J.component.invoke().setScale(this.pinFade?Math.max(0,1-(J.zoom-Q)*0.2):1),J.marker.insert();else if(J.component.invoke().setCollapsed(!0),J.component.invoke().getCollapsed())J.component.invoke().setDisplayed(!1),J.marker.remove()}else J.component.invoke().setDisplayed(!1),J.marker.remove()}}import*as Q2 from"@arenarium/maps-core/angles";class w0{tooltips=new Set;tooltipMaxWidth=0;tooltipMaxHeight=0;insert(x,q){this.update(x,q),this.tooltips.add(x)}update(x,q){if(q)x.zoom=q[0],x.states=q[1].map((Q)=>[Q[0],Q2.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((q,Q)=>Math.max(q,Q.width),0),this.tooltipMaxHeight=x.reduce((q,Q)=>Math.max(q,Q.height),0)}render(x,q){let Q=x.zoom,G=q.mapSize,h=C.offset(x,G,{top:this.tooltipMaxHeight,bottom:this.tooltipMaxHeight,right:this.tooltipMaxWidth,left:this.tooltipMaxWidth});for(let J of this.tooltips)if(h.contains(J.lat,J.lng)){if(Number.isNaN(J.zoom)==!1&&J.shown&&J.zoom<=Q){let Y=J.states.findLast((X)=>X[0]<=Q)?.[1];if(Y==null)throw Error("Angle not found");J.angle=Y,J.component.invoke().setDisplayed(!0),J.component.invoke().setCollapsed(!1),J.component.invoke().setAngle(Y),J.marker.insert()}else if(J.component.invoke().setCollapsed(!0),J.component.invoke().getCollapsed())J.component.invoke().setDisplayed(!1),J.marker.remove()}else J.component.invoke().setDisplayed(!1),J.marker.remove()}}import*as F0 from"@arenarium/maps-core/mercator";import*as G2 from"@arenarium/maps-core/rectangle";class A0{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,q){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,G=q.getViewport(),h=G.bounds,J=G.zoom,X=q.getParameters().mapSize*Math.pow(2,J),Z=F0.project(h.ne.lat,h.sw.lng,X),O=F0.project(h.sw.lat,h.ne.lng,X),B=O.x-Z.x,S=O.y-Z.y,y=Q.width+Q.margin*8,b=Q.height+Q.margin*8,I=F0.project(Q.lat,Q.lng,X),V=G2.offsets(y,b,x.tooltip.angle),H=I.x+V.x,w=H+y,D=I.y+V.y,g=D+b,A=H-Z.x,T=O.x-w,$=D-Z.y,U=O.y-g,z=0;if(B<y)z=(A-T)/2;else{if(A<0)z=A;if(T<0)z=-T}let N=0;if(S<b)N=($-U)/2;else{if($<0)N=$;if(U<0)N=-U}if(z!=0||N!=0)q.panBy(z,N)}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 $0{mapProvider;mapPinManager;mapTooltipManager;mapPopupManager;mapElements;constructor(x){this.mapProvider=x,this.mapPinManager=new S0,this.mapTooltipManager=new w0,this.mapPopupManager=new A0,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 q of x){let Q=this.mapElements.get(q.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 q of x){let Q=this.mapElements.get(q.data.id);if(Q==null)continue;this.mapPinManager.update(Q.pin,q.state),this.mapTooltipManager.update(Q.tooltip,q.state)}}insertElements(x,q){for(let Q of x){let G=this.mapElements.get(Q.data.id);if(G==null)G=new M0(Q.data,this.mapProvider),G.tooltip.marker.div.addEventListener("click",(h)=>q(h,Q.data.id)),this.mapElements.set(Q.data.id,G);if(this.mapPinManager.insert(G.pin,Q.state),this.mapTooltipManager.insert(G.tooltip,Q.state),G.popup!=null)this.mapPopupManager.insert(G.popup)}this.mapPinManager.refresh(),this.mapTooltipManager.refresh()}renderElements(x,q){this.mapPopupManager.render(),this.mapTooltipManager.render(x,q),this.mapPinManager.render(x,q)}showPopup(x){let q=this.mapElements.values();for(let Q of q)if(Q.id==x)this.mapPopupManager.show(Q,this.mapProvider);else this.mapPopupManager.hide(Q)}hidePopup(x){let q=this.mapElements.get(x);if(q==null)return;this.mapPopupManager.hide(q)}hidePopups(){let x=this.mapElements.values();for(let q of x)this.mapPopupManager.hide(q)}}import*as J2 from"@arenarium/maps-core/http";import*as h2 from"@arenarium/maps-core/hash";import*as K0 from"@arenarium/maps-core/angles";var T2="https://maps.api.arenarium.dev/states",v2=3,f2=500;class P0{apiKey;apiJwt;apiDevEnvironment;mapMarkerStatesStore;constructor(x,q){this.apiKey=x,this.apiJwt=q,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 q=0;q<x.length;q++){let Q=x[q];Q.state=void 0}}async updateStates(x,q){if(x.length==0)return;x.sort((J,Y)=>J.data.id.localeCompare(Y.data.id));let Q=x.map((J)=>J.input),G=h2.object(Q),h=this.mapMarkerStatesStore.get(G);if(h==null)h=await this.fetchStates(Q,q),this.mapMarkerStatesStore.set(G,h);for(let J=0;J<x.length;J++){let Y=x[J];Y.state=h[J]}}async fetchStates(x,q){if(x.length==0)return[];if(x.length==1)return[[0,[[0,K0.values.indexOf(K0.initial)]]]];let Q={key:this.apiKey,jwt:this.apiJwt,input:x,parameters:q},G=await J2.post(T2,Q,{headers:{"Cache-Control":this.apiDevEnvironment?"no-cache":""}},v2,f2);if(G.jwt)this.apiJwt=G.jwt;return G.states}}import*as W0 from"@arenarium/maps-core/http";import{apiKeySchema as C2,apiJwtSchema as k2,mapMarkerDataSchema as M2,mapProviderSchema as R2}from"@arenarium/maps-core/schemas";import*as c from"valibot";var F2="1.2.9",S2="https://maps.api.arenarium.dev/auth",w2="https://maps.api.arenarium.dev/log",A2=100,K2=500,$2=500;class _0{apiKey;mapProvider;mapMarkers;mapMarkersVisibilityManager;mapMarkerElementsManager;mapMarkerStatesManager;mapMarkerRenderProcessor;mapMarkerVisibilityProcessor;mapMarkerStateProcessor;mapMarkerStatesProcessDelay=500;mapMarkerStatesProcessTimeout=void 0;mapStateManager;constructor(x,q,Q,G){c.parse(C2,x),c.parse(k2,q),c.parse(R2,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 $0(this.mapProvider),this.mapMarkerStatesManager=new P0(x,q),this.mapMarkerRenderProcessor=new r(this.onMapMarkerRenderProcess.bind(this),K2),this.mapMarkerVisibilityProcessor=new r(this.onMapMarkerVisiblityProcess.bind(this),K2),this.mapMarkerStateProcessor=new r(this.onMapMarkerStateProcess.bind(this)),this.mapStateManager=new y0(this.mapProvider,A2/(navigator?.hardwareConcurrency??1),this.detached.bind(this),this.error.bind(this),this.onMapMove.bind(this),this.onMapIdle.bind(this)),this.configuration=G}static async create(x,q,Q){let J=(await W0.post(S2,{key:x,version:F2})).jwt;if(!J)throw Error("Failed to get api jwt");return new _0(x,J,q,Q)}set configuration(x){this.mapMarkerStatesProcessDelay=x?.process?.states?.delay??$2,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,q){this.log("error",x,q),this.configuration?.events?.error?.(x,q)}async log(x,q,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 G={key:this.apiKey,title:q,level:x,content:{version:F2,name:Q.name,message:Q.message,cause:Q.cause,stack:Q.stack}};await W0.put(w2,G)}catch(G){console.error(G)}}onMapClick(){this.hidePopup()}onMapMarkerClick(x,q){x.stopPropagation(),this.showPopup(q)}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(),q=this.mapProvider.getParameters(),Q=new Set(this.mapMarkersVisibilityManager.markers);this.mapMarkersVisibilityManager.updateVisibleMarkers(x,q);let G=new Set(this.mapMarkersVisibilityManager.markers),h=Array.from(Q.difference(G)),J=Array.from(G.difference(Q));return this.mapMarkerStatesManager.resetStates(h),this.mapMarkerElementsManager.removeElements(h),this.mapMarkerElementsManager.insertElements(J,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,q=this.mapProvider.getParameters();return await this.mapMarkerStatesManager.updateStates(x,q),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(),q=this.mapProvider.getParameters();return this.mapMarkerElementsManager.renderElements(x,q),!1}catch(x){return this.clear(),this.error("Failed to process map render",x),!0}}updateMarkers(x){c.parse(c.array(M2),x);try{for(let Q of x)if(this.mapMarkers.has(Q.id)==!1)this.mapMarkers.set(Q.id,new z0(Q));let q=Array.from(this.mapMarkers.values());q.sort((Q,G)=>G.data.rank-Q.data.rank),this.mapMarkersVisibilityManager.insertMarkers(q),this.mapStateManager.start(),this.mapMarkerVisibilityProcessor.start(),this.mapMarkerStateProcessor.start(),this.mapMarkerRenderProcessor.start()}catch(q){throw this.clear(),this.error("Failed to update markers",q),q}}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(q){throw this.mapMarkerElementsManager.hidePopups(),this.error("Failed to show popup",q),q}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{_0 as MapManager};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arenarium/maps",
3
- "version": "1.2.9",
3
+ "version": "1.2.10",
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,9 +38,9 @@
38
38
  "**/*.css"
39
39
  ],
40
40
  "dependencies": {
41
- "@arenarium/maps-core": "1.0.3",
41
+ "@arenarium/maps-core": "1.0.5",
42
42
  "valibot": "^1.2.0",
43
- "svelte": "^5.45.8"
43
+ "svelte": "^5.46.0"
44
44
  },
45
45
  "clean-package": {
46
46
  "indent": 2,