@arenarium/maps 1.2.10 → 1.2.12

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.css CHANGED
@@ -1 +1 @@
1
- .pin.svelte-e30vfn4rttu1{position:absolute;box-sizing:border-box;transform-origin:0% 0%;backface-visibility:hidden;will-change:scale;border-style:solid;transform:translate(-50%,-50%)}.pin.svelte-e30vfn4rttu1{display:none;content-visibility:hidden}.pin.displayed.svelte-e30vfn4rttu1{display:initial;content-visibility:initial}.pin.svelte-e30vfn4rttu1{opacity:1}.pin.suppressed.svelte-e30vfn4rttu1{opacity:.5;box-shadow:none!important}.element.svelte-vkqe2rkto2oe{box-sizing:border-box}.anchor.svelte-vkqe2rkto2oe{display:block;position:absolute;width:0;height:0;transition:filter .125s ease-in-out}.anchor.svelte-vkqe2rkto2oe>.pointer:where(.svelte-vkqe2rkto2oe){position:absolute;transform-origin:0% 0%;border-radius:1px;top:0;left:0}.anchor.svelte-vkqe2rkto2oe>.tooltip:where(.svelte-vkqe2rkto2oe){position:absolute;top:0;left:0}.anchor.svelte-vkqe2rkto2oe>.tooltip:where(.svelte-vkqe2rkto2oe)>.body:where(.svelte-vkqe2rkto2oe){cursor:pointer}.anchor.svelte-vkqe2rkto2oe{opacity:0;will-change:opacity}.anchor.svelte-vkqe2rkto2oe>.pointer:where(.svelte-vkqe2rkto2oe){transform-origin:0% 0%;will-change:transform,scale;scale:0}.anchor.svelte-vkqe2rkto2oe>.tooltip:where(.svelte-vkqe2rkto2oe){transform-origin:0% 0%;will-change:transform,scale;scale:0}.anchor.svelte-vkqe2rkto2oe{display:none;content-visibility:hidden}.anchor.displayed.svelte-vkqe2rkto2oe{display:initial;content-visibility:initial}.body.svelte-vkqe2rkto2oe{backface-visibility:initial;transform-style:initial}.body.svelte-vkqe2rkto2oe:hover{backface-visibility:hidden;transform-style:preserve-3d}
1
+ .pin.svelte-e30vfn4rttu1{position:absolute;box-sizing:border-box;transform-origin:0% 0%;backface-visibility:hidden;will-change:scale;border-style:solid;transform:translate(-50%,-50%)}.pin.svelte-e30vfn4rttu1{display:none;content-visibility:hidden}.pin.displayed.svelte-e30vfn4rttu1{display:initial;content-visibility:initial}.pin.svelte-e30vfn4rttu1{opacity:1}.pin.suppressed.svelte-e30vfn4rttu1{opacity:.5;box-shadow:none!important}.element.svelte-17e81wb0tdtjd{box-sizing:border-box}.anchor.svelte-17e81wb0tdtjd{display:block;position:absolute;width:0;height:0;transition:filter .125s ease-in-out}.anchor.svelte-17e81wb0tdtjd>.pointer:where(.svelte-17e81wb0tdtjd){position:absolute;transform-origin:0% 0%;top:0;left:0}.anchor.svelte-17e81wb0tdtjd>.tooltip:where(.svelte-17e81wb0tdtjd){position:absolute;top:0;left:0}.anchor.svelte-17e81wb0tdtjd>.tooltip:where(.svelte-17e81wb0tdtjd)>.body:where(.svelte-17e81wb0tdtjd){cursor:pointer}.anchor.svelte-17e81wb0tdtjd{opacity:0;will-change:opacity}.anchor.svelte-17e81wb0tdtjd>.pointer:where(.svelte-17e81wb0tdtjd){transform-origin:0% 0%;will-change:transform,scale;scale:0}.anchor.svelte-17e81wb0tdtjd>.tooltip:where(.svelte-17e81wb0tdtjd){transform-origin:0% 0%;will-change:transform,scale;scale:0}.anchor.svelte-17e81wb0tdtjd>.tooltip:where(.svelte-17e81wb0tdtjd)>.body:where(.svelte-17e81wb0tdtjd){transform-origin:0% 0%;will-change:transform}.anchor.svelte-17e81wb0tdtjd{display:none;content-visibility:hidden}.anchor.displayed.svelte-17e81wb0tdtjd{display:initial;content-visibility:initial}.body.svelte-17e81wb0tdtjd{backface-visibility:initial;transform-style:initial}.body.svelte-17e81wb0tdtjd:hover{backface-visibility:hidden;transform-style:preserve-3d}
package/dist/main.js CHANGED
@@ -1 +1 @@
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};
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};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arenarium/maps",
3
- "version": "1.2.10",
3
+ "version": "1.2.12",
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.5",
41
+ "@arenarium/maps-core": "1.0.6",
42
42
  "valibot": "^1.2.0",
43
- "svelte": "^5.46.0"
43
+ "svelte": "^5.46.1"
44
44
  },
45
45
  "clean-package": {
46
46
  "indent": 2,