spacemap 0.1.7 → 0.1.8

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/spacemap.js CHANGED
@@ -4566,7 +4566,7 @@ varying vec4 vPick;
4566
4566
  void main() {
4567
4567
  gl_FragColor = vPick;
4568
4568
  }
4569
- `,HO=class{target;material;scene=new Ka;pickCamera;size=0;buffer=new Uint8Array;prevClear=new X;proxies=[];constructor(e,t){this.renderer=e,this.target=new ca(1,1,{depthBuffer:!0}),this.target.texture.colorSpace=Yr,this.target.texture.generateMipmaps=!1,this.material=new fu({vertexShader:BO,fragmentShader:VO,uniforms:{uPointSize:{value:RO}},blending:0,depthTest:!0,depthWrite:!0}),this.scene.matrixWorldAutoUpdate=!1,this.pickCamera=t.clone()}ensureSize(e){e!==this.size&&(this.size=e,this.target.setSize(e,e),this.buffer=new Uint8Array(e*e*4))}proxyAt(e,t){let n=this.proxies[e];return n?n.geometry=t.geometry:(n=new kc(t.geometry,this.material),n.frustumCulled=!1,n.matrixAutoUpdate=!1,n.matrixWorldAutoUpdate=!1,this.proxies[e]=n),n.matrixWorld.copy(t.matrixWorld),n}pick(e,t,n,r,i,a){let o=Math.max(1,Math.round(a)),s=o*2+1;this.ensureSize(s);let c=n-i.left,l=r-i.top,u=c-o,d=l-o;this.scene.clear();let f=0;for(let t of e)t.visible&&t.geometry.getAttribute(`pickColor`)&&t.geometry.drawRange.count!==0&&this.scene.add(this.proxyAt(f++,t));if(f===0)return[];this.pickCamera.copy(t),this.pickCamera.setViewOffset(i.width,i.height,u,d,s,s),this.pickCamera.updateProjectionMatrix();let p=this.renderer.getRenderTarget(),m=this.renderer.autoClear;this.renderer.getClearColor(this.prevClear);let h=this.renderer.getClearAlpha();return this.renderer.setRenderTarget(this.target),this.renderer.autoClear=!1,this.renderer.setClearColor(0,0),this.renderer.clear(!0,!0,!1),this.renderer.render(this.scene,this.pickCamera),this.renderer.readRenderTargetPixels(this.target,0,0,s,s,this.buffer),this.renderer.setRenderTarget(p),this.renderer.autoClear=m,this.renderer.setClearColor(this.prevClear,h),this.pickCamera.clearViewOffset(),this.decode(s,o,i,u,d)}decode(e,t,n,r,i){let a=this.buffer,o=new Map;for(let s=0;s<e;s++){let c=e-1-s;for(let l=0;l<e;l++){let u=(s*e+l)*4,d=(a[u]|a[u+1]<<8|a[u+2]<<16|a[u+3]<<24)>>>0;if(d===0)continue;let f=l-t,p=c-t,m=Math.hypot(f,p),h=o.get(d);if(h&&h.pixelDist<=m)continue;let g=r+l+.5,_=i+c+.5;o.set(d,{pickId:d,pixelDist:m,ndcX:g/n.width*2-1,ndcY:-(_/n.height*2-1)})}}return[...o.values()].sort((e,t)=>e.pixelDist-t.pixelDist).slice(0,zO)}dispose(){this.target.dispose(),this.material.dispose(),this.proxies.length=0}};function UO(e,t,n){return Math.min(Math.max(e,t),n)}function WO(e,t){let n=Math.max(e,0);return UO(t.refMs*n/t.refAngleRad,t.minMs,t.maxMs)}function GO(e,t){if(!(e>0))return t.minMs;let n=Math.log10(e/t.refDist);return UO(t.refMs+n*t.msPerDecade,t.minMs,t.maxMs)}var KO={refMs:350,refAngleRad:Math.PI/3,minMs:200,maxMs:700},qO={refMs:400,refAngleRad:Math.PI/2,minMs:200,maxMs:800},JO={refMs:1600,refDist:2,msPerDecade:400,minMs:600,maxMs:2500},YO={refMs:1600,refAngleRad:Math.PI/2,minMs:600,maxMs:2500},XO=new J(0,1,0),ZO=(()=>{let e=Math.PI/180,t=192.85948*e,n=27.12825*e,r=Math.cos(n),i=r*Math.cos(t),a=r*Math.sin(t),o=Math.sin(n),s=ig*e,c=Math.cos(s),l=Math.sin(s),u=i,d=a*c+o*l;return new J(u,-a*l+o*c,-d).normalize()})();function QO(e){return(e??new J).copy(ZO)}function $O(e,t,n,r=!1){let i=n??new J;if(!e.orientation)return r&&e.orbitCenter&&(i.set(e.position[0]-e.orbitCenter[0],e.position[1]-e.orbitCenter[1],e.position[2]-e.orbitCenter[2]),i.lengthSq()>1e-20)?i.normalize():(i.copy(XO),e.modelBaseFrame&&i.applyQuaternion(e.modelBaseFrame).normalize(),i);let a=pC(e.orientation,t,e.nutPrec);return i.copy(XO).applyQuaternion(a).normalize()}var ek=class{refId=null;startVec=new J(0,1,0);targetVec=new J(0,1,0);currentVec=new J(0,1,0);animStartTime=-1/0;animDurationMs=qO.refMs;needsDurationCalc=!1;_quatA=new Vi;_quatB=new Vi;constructor(e,t,n,r){this.camera=e,this.controls=t,this.ctx=n,this.isLanded=r}setNorthReference(e){e!==this.refId&&(this.refId=e,this.startVec.copy(this.currentVec),this.animStartTime=performance.now(),this.needsDurationCalc=!0)}update(e){if(this.refId===`galactic`)QO(this.targetVec);else{let t=this.refId?this.ctx.getBody(this.refId):void 0;if(t){let n=!!t.featureAnchor||this.isLanded(t.data.id);$O(t,e,this.targetVec,n)}else this.targetVec.copy(XO)}if(this.needsDurationCalc){this.needsDurationCalc=!1;let e=this.startVec.angleTo(this.targetVec);this.animDurationMs=WO(e,qO)}let t=performance.now()-this.animStartTime;if(t>=this.animDurationMs)this.currentVec.copy(this.targetVec);else{let e=Math.max(0,t/this.animDurationMs),n=e*e*(3-2*e);this._quatA.setFromUnitVectors(XO,this.startVec),this._quatB.setFromUnitVectors(XO,this.targetVec),this._quatA.slerp(this._quatB,n),this.currentVec.copy(XO).applyQuaternion(this._quatA)}this.camera.up.copy(this.currentVec);let n=this.controls;n._quat.setFromUnitVectors(this.currentVec,XO),n._quatInverse.copy(n._quat).invert()}},tk=class extends La{constructor(e=document.createElement(`div`)){super(),this.isCSS2DObject=!0,this.element=e,this.element.style.position=`absolute`,this.element.style.userSelect=`none`,this.element.setAttribute(`draggable`,!1),this.center=new q(.5,.5),this.addEventListener(`removed`,function(){this.traverse(function(e){e.element&&e.element instanceof e.element.ownerDocument.defaultView.Element&&e.element.parentNode!==null&&e.element.remove()})})}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this.center=e.center,this}};new J,new Y,new Y,new J,new J;function nk(e){return e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey}function rk(e,t,n){let r=e[t];return r||(r=n(),e[t]=r),r}function ik(e){switch(e){case G.STAR:return 0;case G.PLANET:return 1;case G.DWARF_PLANET:return 2;case G.MOON:return 3;default:return 4}}var ak=new J,ok=22;function sk(){return{cx0:0,cy0:0,f:0,gxx:0,gxy:0,gxz:0,gyx:0,gyy:0,gyz:0,gzx:0,gzy:0,gzz:0,cpx:0,cpy:0,cpz:0,K:0,id:``,dist:0,ccx:0,ccy:0,ccz:0}}var ck=new WeakMap;function lk(e){ck.delete(e)}function uk(e,t,n,r=.3,i=null){if(e){let t=`d${r}${+!!n}`;if(ck.get(e)===t)return;ck.set(e,t),e.style.transform=`scale(${r})`,e.parentElement&&(e.parentElement.style.pointerEvents=n?``:`none`)}t&&(t.style.display=`none`,t.style.fontSize=``),i&&(i.style.display=`none`)}function dk(e,t,n,r,i=null){if(e){let t=`r${+!!n}${+!!r}`;if(ck.get(e)===t)return;ck.set(e,t),n||(e.style.transform=``),e.style.border=e.dataset.origBorder??``,e.parentElement&&(e.parentElement.style.pointerEvents=``)}t&&(t.style.display=``,t.style.fontSize=r?`18px`:``),i&&(i.style.display=``)}function fk(e,t,n,r,i,a){let{label:o,labelHalo:s,radiusScene:c}=e;if(!o)return!1;let l=o.visible,u=!e.noPhysical&&c>0?c/r*i:0,d=e.body.data.id===a,f=u>=16;return!t&&n&&(d||u>=1)&&(t=u<320),f&&e.labelAnchorOffscreen&&(t=!1),e.trail&&f&&(e.trail.visible=!1),o.visible=t,s&&e.haloHidden!==f&&(s.style.visibility=f?`hidden`:``,e.haloHidden=f),e.loadingEl&&e.loadingShown!==f&&(e.loadingEl.style.display=f?``:`none`,e.loadingShown=f),o.center.x=f?1-4/32:.5,t&&!l}function pk(e,t,n,r,i){for(let a of i){if(a.id===r)continue;let i=e-a.cx0,o=a.cy0-t,s=-a.f,c=i*a.gxx+o*a.gxy+s*a.gxz,l=i*a.gyx+o*a.gyy+s*a.gyz,u=i*a.gzx+o*a.gzy+s*a.gzz,d=c*a.cpx+l*a.cpy+u*a.cpz;if(!(d<=0)&&!(d*d<=a.K*(c*c+l*l+u*u))&&i*a.ccx+o*a.ccy+s*a.ccz<=n*Math.hypot(i,o,s))return!0}return!1}function mk(e,t){e.left=t.left,e.right=t.right,e.y=t.y,e.h=t.h}function hk(e,t,n,r,i,a){let o=e.label,[s,c,l]=e.body.position,u=o.position;ak.set(s-n[0]+u.x,c-n[1]+u.y,l-n[2]+u.z),ak.project(t),a.x=(ak.x*.5+.5)*r,a.y=(-ak.y*.5+.5)*i;let d=a.x-o.center.x*32;return a.left=d,a.right=d+40+(e.labelTextWidth||50),a.h=ok,iT(ak.z)}var gk=[],_k=0,vk=[],yk=0,bk=[],xk=0,Sk={rects:vk,get count(){return yk}};function Ck(){return{bodyId:``,bo:null,body:null,label:null,labelHalo:null,isCapped:!1,isMinor:!1,isFocused:!1,isSelected:!1,rect:{x:0,left:0,right:0,y:0,h:0},dist:0}}function wk(){return{left:0,right:0,y:0,h:0}}var Tk={x:0,left:0,right:0,y:0,h:0};function Ek(e,t){for(let n=0;n<t;n++)mk(rk(bk,n,wk),e[n]);xk=t}function Dk(){for(let e=0;e<xk;e++)mk(rk(vk,e,wk),bk[e]);return xk}function Ok(e,t,n,r,i,a,o,s,c=[0,0,0]){_k=0,yk=Dk();for(let s of e.values()){let{body:e,label:l,labelHalo:u}=s;if(!l?.visible)continue;if(!s.labelTextWidth&&u){let e=u.nextElementSibling;e&&e.offsetWidth>0&&(s.labelTextWidth=e.offsetWidth)}if(!hk(s,r,c,t,n,Tk))continue;let d=e.data.id===i,f=o.has(e.data.id),p=rk(gk,_k++,Ck);mk(p.rect,Tk),p.rect.x=Tk.x,p.bodyId=e.data.id,p.bo=s,p.body=e,p.label=l,p.labelHalo=u,p.isCapped=e.data.objectType===G.MOON?a.visibility.getMoonVisibility(e)===$.CAPPED:!1,p.isMinor=s.isMinor,p.isFocused=d,p.isSelected=d||f||a.visibility.isPinned(e.data.id),p.dist=s.cachedDist}gk.length=_k,gk.sort((e,t)=>{if(e.isSelected!==t.isSelected)return e.isSelected?-1:1;let n=e.isMinor&&!e.isSelected;if(n!==(t.isMinor&&!t.isSelected))return n?1:-1;let r=ik(e.body.data.objectType),i=ik(t.body.data.objectType);return r===i?e.dist-t.dist:r-i});for(let e=0;e<_k;e++){let t=gk[e],n=t.labelHalo,r=n?.nextElementSibling;if(t.isCapped&&!t.isSelected){uk(n,r,!0,.3,t.bo.labelStack),t.bo.labelMaximized=!1;continue}if(!t.isSelected&&pk(t.rect.x,t.rect.y,t.dist,t.bodyId,s)){t.label.visible=!1,t.bo.labelMaximized=!1;continue}if(t.isMinor&&!t.isSelected){let e=!1;for(let n=0;n<yk;n++){let r=vk[n];if(t.rect.x-8<r.right&&t.rect.x+8>r.left&&Math.abs(t.rect.y-r.y)<ok){e=!0;break}}uk(n,r,!e,e?.3:.5,t.bo.labelStack),t.bo.labelMaximized=!1;continue}let i=!1;for(let e=0;e<yk;e++){let n=vk[e];if(t.rect.left<n.right&&t.rect.right>n.left&&Math.abs(t.rect.y-n.y)<ok){i=!0;break}}i?(uk(n,r,!1,.3,t.bo.labelStack),t.bo.labelMaximized=!1):(mk(rk(vk,yk++,wk),t.rect),dk(n,r,o.has(t.bodyId),t.isFocused,t.bo.labelStack),t.bo.labelMaximized=!0)}for(let e=0;e<_k;e++){let t=gk[e];t.bo=null,t.body=null,t.label=null,t.labelHalo=null}}function kk(e,t,n,r,i){yk=Dk();for(let a of e.values())a.label?.visible&&a.labelMaximized!==!1&&hk(a,r,i,t,n,Tk)&&mk(rk(vk,yk++,wk),Tk)}var Ak=`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,jk={flying:Ak,landed:`M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z`};function Mk(e,t){if(!e)return;let n=e.querySelector(`path`);n&&n.setAttribute(`d`,jk[t])}function Nk(e,t,n,r){let i=document.createElement(`span`);i.className=`scene-label__name scene-label__name--${n}${r?` scene-label__name--large`:``}`,i.dir=`auto`,i.textContent=t;let a=e.firstElementChild;return a?a.after(i):e.appendChild(i),i}function Pk(e,t,n,r){if(n===`none`||!t||!e.label)return;let i=e.label.element,a=i.querySelector(`.scene-label__name`);a?a.textContent=t:Nk(i,t,n,r),tD(e)}function Fk(e){let t=e.data.objectType;return gn(t)||t===G.STAR||hn(t)||t===G.COMET||t===G.BARYCENTER||t===G.LAGRANGE_POINT?`major`:t===G.SPACECRAFT?`spacecraft`:t===G.DEBRIS?`debris`:`none`}function Ik(e,t,n,r,i,a=!1,o,s=!1){if(n===`none`)return null;let c=document.createElement(`a`);c.className=`scene-label scene-label--${n}`,r&&(c.href=r),c.tabIndex=-1,c.draggable=!1,t&&c.setAttribute(`aria-label`,t);let l;if(n===`major`){let t=document.createElement(`div`);t.className=`scene-label__halo scene-label__halo--major`,t.style.border=`2px solid ${e}`,t.style.background=`${e}22`,l=t}else{let t=`http://www.w3.org/2000/svg`,r=document.createElementNS(t,`svg`);r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`fill`,`${e}22`),r.setAttribute(`stroke`,e),r.setAttribute(`stroke-width`,`2`),r.setAttribute(`stroke-linejoin`,`round`),r.classList.add(`scene-label__halo`,`scene-label__halo--${n}`);let i=document.createElementNS(t,`path`);i.setAttribute(`d`,n===`debris`?`M3 5 L21 5 L12 21 Z`:Ak),r.appendChild(i),l=r}c.appendChild(l);let u=0,d=0;c.addEventListener(`pointerdown`,e=>{u=e.clientX,d=e.clientY});let f=e=>{if(e.stopPropagation(),nk(e))return;e.preventDefault();let t=e.clientX-u,n=e.clientY-d;t*t+n*n<=9&&i()};t&&Nk(c,t,n,a),s&&(l.style.transform=`scale(0.3)`),c.addEventListener(`click`,f),c.addEventListener(`mouseenter`,()=>{l.style.transform=`scale(1.15)`,document.body.style.cursor=`pointer`,o?.(!0)}),c.addEventListener(`mouseleave`,()=>{l.style.transform=s?`scale(0.3)`:``,lk(l),document.body.style.cursor=``,o?.(!1)});let p=new tk(c);return p.visible=!1,p}var Lk=3;function Rk(e,t){e.addEventListener(`wheel`,e=>{let n=e;t.dispatchEvent(new WheelEvent(`wheel`,{deltaY:n.deltaY,deltaMode:n.deltaMode,bubbles:!0,cancelable:!0})),n.preventDefault()},{passive:!1}),e.addEventListener(`pointerdown`,e=>{let n=e.clientX,r=e.clientY,i=e,a=e=>{let a=e.clientX-n,o=e.clientY-r;a*a+o*o>Lk*Lk&&(s(),t.dispatchEvent(new PointerEvent(`pointerdown`,i)),t.dispatchEvent(new PointerEvent(`pointermove`,e)))},o=()=>s(),s=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)})}var zk=[`low`,`medium`,`high`,`ultra`],Bk={low:{primarySteps:6,lightSteps:2,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!1,layeredDensity:!1,groundAlbedo:!0,seasonal:!0,refraction:!0},medium:{primarySteps:12,lightSteps:3,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!1,layeredDensity:!1,groundAlbedo:!0,seasonal:!0,refraction:!0},high:{primarySteps:16,lightSteps:4,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!0,layeredDensity:!0,groundAlbedo:!0,seasonal:!0,refraction:!0},ultra:{primarySteps:32,lightSteps:8,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!0,layeredDensity:!0,groundAlbedo:!0,seasonal:!0,refraction:!0}};function Vk(){return Ux()?Vx()?`low`:`medium`:Vx()?`high`:`ultra`}function Hk(e){if(e!==`auto`)return e;let t=jx();return t.atmosphereAutoTier??t.atmosphereCalibration?.tier??Vk()}function Uk(){let e=jx();return{...Bk[Hk(e.atmosphereQuality)],...e.atmoQualityOverrides}}function Wk(e){return`${e.primarySteps}|${e.lightSteps}|${+e.eclipseShadows}|${+e.ringShadows}|${+e.insideView}|${+e.layeredDensity}`}var Gk=30,Kk=45,qk=3e3,Jk=2500,Yk=250,Xk=60,Zk=0,Qk=Jk,$k=``;function eA(e,t){let n=jx();if(n.atmosphereQuality!==`auto`||e<=0||e>Yk)return;let r=Wk(Uk());if(r!==$k&&($k=r,Qk=Jk,Zk=0,Xk=60),Xk+=(1e3/e-Xk)*Math.min(1,e/500),Qk>0){Qk-=e;return}if(!t||Xk>Kk){Zk=Math.max(0,Zk-e);return}if(Xk>=Gk||(Zk+=e,Zk<qk))return;Zk=0;let i=zk[zk.indexOf(Hk(`auto`))-1];i&&n.setAtmosphereAutoTier(i)}var tA=256,nA=96;async function rA(e,t,n){let r=await fetch(e);if(!r.ok)throw Error(`Failed to load ${e}: ${r.status} ${r.statusText}`);let i=await r.blob(),a=await createImageBitmap(i),o=Math.min(a.width,n);o<a.width&&console.info(`Ring strip ${e}: downscaling ${a.width}px → ${o}px to fit GL MAX_TEXTURE_SIZE.`);let s=iA(a,e,n),c={};for(let[n,r]of Object.entries(t)){let t=document.createElement(`canvas`);t.width=o,t.height=2;let i=t.getContext(`2d`);if(!i)throw Error(`Failed to acquire 2D context for ring strip ${e}`);let l=aA(s,a.width,r,o);i.putImageData(l,0,0),i.putImageData(l,0,1);let u=new Mc(t);n===`color`&&(u.colorSpace=Jr),u.minFilter=Nn,u.magFilter=jn,u.generateMipmaps=!0,u.anisotropy=16,u.needsUpdate=!0,c[n]=u}return a.close(),c}function iA(e,t,n){let r=new Uint8ClampedArray(e.width*e.height*4),i=document.createElement(`canvas`);i.width=Math.min(e.width,n),i.height=e.height;let a=i.getContext(`2d`,{willReadFrequently:!0});if(!a)throw Error(`Failed to acquire 2D context for ring strip ${t}`);for(let t=0;t<e.width;t+=i.width){let n=Math.min(i.width,e.width-t);a.clearRect(0,0,n,e.height),a.drawImage(e,t,0,n,e.height,0,0,n,e.height);let o=a.getImageData(0,0,n,e.height).data;for(let i=0;i<e.height;i++)r.set(o.subarray(i*n*4,(i+1)*n*4),(i*e.width+t)*4)}return r}function aA(e,t,n,r){let i=new ImageData(r,1);for(let a=0;a<r;a++){let o=Math.floor(a*t/r),s=Math.max(o+1,Math.floor((a+1)*t/r)),c=0,l=0,u=0;for(let r=o;r<s;r++){let i=(n*t+r)*4;c+=e[i],l+=e[i+1],u+=e[i+2]}let d=s-o,f=a*4;i.data[f]=Math.round(c/d),i.data[f+1]=Math.round(l/d),i.data[f+2]=Math.round(u/d),i.data[f+3]=255}return i}var oA=`
4569
+ `,HO=class{target;material;scene=new Ka;pickCamera;size=0;buffer=new Uint8Array;prevClear=new X;proxies=[];constructor(e,t){this.renderer=e,this.target=new ca(1,1,{depthBuffer:!0}),this.target.texture.colorSpace=Yr,this.target.texture.generateMipmaps=!1,this.material=new fu({vertexShader:BO,fragmentShader:VO,uniforms:{uPointSize:{value:RO}},blending:0,depthTest:!0,depthWrite:!0}),this.scene.matrixWorldAutoUpdate=!1,this.pickCamera=t.clone()}ensureSize(e){e!==this.size&&(this.size=e,this.target.setSize(e,e),this.buffer=new Uint8Array(e*e*4))}proxyAt(e,t){let n=this.proxies[e];return n?n.geometry=t.geometry:(n=new kc(t.geometry,this.material),n.frustumCulled=!1,n.matrixAutoUpdate=!1,n.matrixWorldAutoUpdate=!1,this.proxies[e]=n),n.matrixWorld.copy(t.matrixWorld),n}pick(e,t,n,r,i,a){let o=Math.max(1,Math.round(a)),s=o*2+1;this.ensureSize(s);let c=n-i.left,l=r-i.top,u=c-o,d=l-o;this.scene.clear();let f=0;for(let t of e)t.visible&&t.geometry.getAttribute(`pickColor`)&&t.geometry.drawRange.count!==0&&this.scene.add(this.proxyAt(f++,t));if(f===0)return[];this.pickCamera.copy(t),this.pickCamera.setViewOffset(i.width,i.height,u,d,s,s),this.pickCamera.updateProjectionMatrix();let p=this.renderer.getRenderTarget(),m=this.renderer.autoClear;this.renderer.getClearColor(this.prevClear);let h=this.renderer.getClearAlpha();return this.renderer.setRenderTarget(this.target),this.renderer.autoClear=!1,this.renderer.setClearColor(0,0),this.renderer.clear(!0,!0,!1),this.renderer.render(this.scene,this.pickCamera),this.renderer.readRenderTargetPixels(this.target,0,0,s,s,this.buffer),this.renderer.setRenderTarget(p),this.renderer.autoClear=m,this.renderer.setClearColor(this.prevClear,h),this.pickCamera.clearViewOffset(),this.decode(s,o,i,u,d)}decode(e,t,n,r,i){let a=this.buffer,o=new Map;for(let s=0;s<e;s++){let c=e-1-s;for(let l=0;l<e;l++){let u=(s*e+l)*4,d=(a[u]|a[u+1]<<8|a[u+2]<<16|a[u+3]<<24)>>>0;if(d===0)continue;let f=l-t,p=c-t,m=Math.hypot(f,p),h=o.get(d);if(h&&h.pixelDist<=m)continue;let g=r+l+.5,_=i+c+.5;o.set(d,{pickId:d,pixelDist:m,ndcX:g/n.width*2-1,ndcY:-(_/n.height*2-1)})}}return[...o.values()].sort((e,t)=>e.pixelDist-t.pixelDist).slice(0,zO)}dispose(){this.target.dispose(),this.material.dispose(),this.proxies.length=0}};function UO(e,t,n){return Math.min(Math.max(e,t),n)}function WO(e,t){let n=Math.max(e,0);return UO(t.refMs*n/t.refAngleRad,t.minMs,t.maxMs)}function GO(e,t){if(!(e>0))return t.minMs;let n=Math.log10(e/t.refDist);return UO(t.refMs+n*t.msPerDecade,t.minMs,t.maxMs)}var KO={refMs:350,refAngleRad:Math.PI/3,minMs:200,maxMs:700},qO={refMs:400,refAngleRad:Math.PI/2,minMs:200,maxMs:800},JO={refMs:1600,refDist:2,msPerDecade:400,minMs:600,maxMs:2500},YO={refMs:1600,refAngleRad:Math.PI/2,minMs:600,maxMs:2500},XO=new J(0,1,0),ZO=(()=>{let e=Math.PI/180,t=192.85948*e,n=27.12825*e,r=Math.cos(n),i=r*Math.cos(t),a=r*Math.sin(t),o=Math.sin(n),s=ig*e,c=Math.cos(s),l=Math.sin(s),u=i,d=a*c+o*l;return new J(u,-a*l+o*c,-d).normalize()})();function QO(e){return(e??new J).copy(ZO)}function $O(e,t,n,r=!1){let i=n??new J;if(!e.orientation)return r&&e.orbitCenter&&(i.set(e.position[0]-e.orbitCenter[0],e.position[1]-e.orbitCenter[1],e.position[2]-e.orbitCenter[2]),i.lengthSq()>1e-20)?i.normalize():(i.copy(XO),e.modelBaseFrame&&i.applyQuaternion(e.modelBaseFrame).normalize(),i);let a=pC(e.orientation,t,e.nutPrec);return i.copy(XO).applyQuaternion(a).normalize()}var ek=class{refId=null;startVec=new J(0,1,0);targetVec=new J(0,1,0);currentVec=new J(0,1,0);animStartTime=-1/0;animDurationMs=qO.refMs;needsDurationCalc=!1;_quatA=new Vi;_quatB=new Vi;constructor(e,t,n,r){this.camera=e,this.controls=t,this.ctx=n,this.isLanded=r}setNorthReference(e){e!==this.refId&&(this.refId=e,this.startVec.copy(this.currentVec),this.animStartTime=performance.now(),this.needsDurationCalc=!0)}update(e){if(this.refId===`galactic`)QO(this.targetVec);else{let t=this.refId?this.ctx.getBody(this.refId):void 0;if(t){let n=!!t.featureAnchor||this.isLanded(t.data.id);$O(t,e,this.targetVec,n)}else this.targetVec.copy(XO)}if(this.needsDurationCalc){this.needsDurationCalc=!1;let e=this.startVec.angleTo(this.targetVec);this.animDurationMs=WO(e,qO)}let t=performance.now()-this.animStartTime;if(t>=this.animDurationMs)this.currentVec.copy(this.targetVec);else{let e=Math.max(0,t/this.animDurationMs),n=e*e*(3-2*e);this._quatA.setFromUnitVectors(XO,this.startVec),this._quatB.setFromUnitVectors(XO,this.targetVec),this._quatA.slerp(this._quatB,n),this.currentVec.copy(XO).applyQuaternion(this._quatA)}this.camera.up.copy(this.currentVec);let n=this.controls;n._quat.setFromUnitVectors(this.currentVec,XO),n._quatInverse.copy(n._quat).invert()}},tk=class extends La{constructor(e=document.createElement(`div`)){super(),this.isCSS2DObject=!0,this.element=e,this.element.style.position=`absolute`,this.element.style.userSelect=`none`,this.element.setAttribute(`draggable`,!1),this.center=new q(.5,.5),this.addEventListener(`removed`,function(){this.traverse(function(e){e.element&&e.element instanceof e.element.ownerDocument.defaultView.Element&&e.element.parentNode!==null&&e.element.remove()})})}copy(e,t){return super.copy(e,t),this.element=e.element.cloneNode(!0),this.center=e.center,this}};new J,new Y,new Y,new J,new J;function nk(e){return e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey}function rk(e,t,n){let r=e[t];return r||(r=n(),e[t]=r),r}function ik(e){switch(e){case G.STAR:return 0;case G.PLANET:return 1;case G.DWARF_PLANET:return 2;case G.MOON:return 3;default:return 4}}var ak=new J,ok=22;function sk(){return{cx0:0,cy0:0,f:0,gxx:0,gxy:0,gxz:0,gyx:0,gyy:0,gyz:0,gzx:0,gzy:0,gzz:0,cpx:0,cpy:0,cpz:0,K:0,id:``,dist:0,ccx:0,ccy:0,ccz:0}}var ck=new WeakMap;function lk(e){ck.delete(e)}function uk(e,t,n,r=.3,i=null){if(e){let t=`d${r}${+!!n}`;if(ck.get(e)===t)return;ck.set(e,t),e.style.transform=`scale(${r})`,e.parentElement&&(e.parentElement.style.pointerEvents=n?``:`none`)}t&&(t.style.display=`none`,t.style.fontSize=``),i&&(i.style.display=`none`)}function dk(e,t,n,r,i=null){if(e){let t=`r${+!!n}${+!!r}`;if(ck.get(e)===t)return;ck.set(e,t),n||(e.style.transform=``),e.style.border=e.dataset.origBorder??``,e.parentElement&&(e.parentElement.style.pointerEvents=``)}t&&(t.style.display=``,t.style.fontSize=r?`18px`:``),i&&(i.style.display=``)}function fk(e,t,n,r,i,a){let{label:o,labelHalo:s,radiusScene:c}=e;if(!o)return!1;let l=o.visible,u=!e.noPhysical&&c>0?c/r*i:0,d=e.body.data.id===a,f=u>=16;return!t&&n&&(d||u>=1)&&(t=u<320),f&&e.labelAnchorOffscreen&&(t=!1),e.trail&&f&&(e.trail.visible=!1),o.visible=t,s&&e.haloHidden!==f&&(s.style.visibility=f?`hidden`:``,e.haloHidden=f),e.loadingEl&&e.loadingShown!==f&&(e.loadingEl.style.display=f?``:`none`,e.loadingShown=f),o.center.x=f?1-4/32:.5,t&&!l}function pk(e,t,n,r,i,a=null){for(let o of i){if(o.id===r||o.id===a)continue;let i=e-o.cx0,s=o.cy0-t,c=-o.f,l=i*o.gxx+s*o.gxy+c*o.gxz,u=i*o.gyx+s*o.gyy+c*o.gyz,d=i*o.gzx+s*o.gzy+c*o.gzz,f=l*o.cpx+u*o.cpy+d*o.cpz;if(!(f<=0)&&!(f*f<=o.K*(l*l+u*u+d*d))&&i*o.ccx+s*o.ccy+c*o.ccz<=n*Math.hypot(i,s,c))return!0}return!1}function mk(e,t){e.left=t.left,e.right=t.right,e.y=t.y,e.h=t.h}function hk(e,t,n,r,i,a){let o=e.label,[s,c,l]=e.body.position,u=o.position;ak.set(s-n[0]+u.x,c-n[1]+u.y,l-n[2]+u.z),ak.project(t),a.x=(ak.x*.5+.5)*r,a.y=(-ak.y*.5+.5)*i;let d=a.x-o.center.x*32;return a.left=d,a.right=d+40+(e.labelTextWidth||50),a.h=ok,iT(ak.z)}var gk=[],_k=0,vk=[],yk=0,bk=[],xk=0,Sk={rects:vk,get count(){return yk}};function Ck(){return{bodyId:``,bo:null,body:null,label:null,labelHalo:null,isCapped:!1,isMinor:!1,isFocused:!1,isSelected:!1,rect:{x:0,left:0,right:0,y:0,h:0},dist:0}}function wk(){return{left:0,right:0,y:0,h:0}}var Tk={x:0,left:0,right:0,y:0,h:0};function Ek(e,t){for(let n=0;n<t;n++)mk(rk(bk,n,wk),e[n]);xk=t}function Dk(){for(let e=0;e<xk;e++)mk(rk(vk,e,wk),bk[e]);return xk}function Ok(e,t,n,r,i,a,o,s,c=[0,0,0]){_k=0,yk=Dk();for(let s of e.values()){let{body:e,label:l,labelHalo:u}=s;if(!l?.visible)continue;if(!s.labelTextWidth&&u){let e=u.nextElementSibling;e&&e.offsetWidth>0&&(s.labelTextWidth=e.offsetWidth)}if(!hk(s,r,c,t,n,Tk))continue;let d=e.data.id===i,f=o.has(e.data.id),p=rk(gk,_k++,Ck);mk(p.rect,Tk),p.rect.x=Tk.x,p.bodyId=e.data.id,p.bo=s,p.body=e,p.label=l,p.labelHalo=u,p.isCapped=e.data.objectType===G.MOON?a.visibility.getMoonVisibility(e)===$.CAPPED:!1,p.isMinor=s.isMinor,p.isFocused=d,p.isSelected=d||f||a.visibility.isPinned(e.data.id),p.dist=s.cachedDist}gk.length=_k,gk.sort((e,t)=>{if(e.isSelected!==t.isSelected)return e.isSelected?-1:1;let n=e.isMinor&&!e.isSelected;if(n!==(t.isMinor&&!t.isSelected))return n?1:-1;let r=ik(e.body.data.objectType),i=ik(t.body.data.objectType);return r===i?e.dist-t.dist:r-i});for(let e=0;e<_k;e++){let t=gk[e],n=t.labelHalo,r=n?.nextElementSibling;if(t.isCapped&&!t.isSelected){uk(n,r,!0,.3,t.bo.labelStack),t.bo.labelMaximized=!1;continue}if(!t.isSelected&&pk(t.rect.x,t.rect.y,t.dist,t.bodyId,s)){t.label.visible=!1,t.bo.labelMaximized=!1;continue}if(t.isMinor&&!t.isSelected){let e=!1;for(let n=0;n<yk;n++){let r=vk[n];if(t.rect.x-8<r.right&&t.rect.x+8>r.left&&Math.abs(t.rect.y-r.y)<ok){e=!0;break}}uk(n,r,!e,e?.3:.5,t.bo.labelStack),t.bo.labelMaximized=!1;continue}let i=!1;for(let e=0;e<yk;e++){let n=vk[e];if(t.rect.left<n.right&&t.rect.right>n.left&&Math.abs(t.rect.y-n.y)<ok){i=!0;break}}i?(uk(n,r,!1,.3,t.bo.labelStack),t.bo.labelMaximized=!1):(mk(rk(vk,yk++,wk),t.rect),dk(n,r,o.has(t.bodyId),t.isFocused,t.bo.labelStack),t.bo.labelMaximized=!0)}for(let e=0;e<_k;e++){let t=gk[e];t.bo=null,t.body=null,t.label=null,t.labelHalo=null}}function kk(e,t,n,r,i){yk=Dk();for(let a of e.values())a.label?.visible&&a.labelMaximized!==!1&&hk(a,r,i,t,n,Tk)&&mk(rk(vk,yk++,wk),Tk)}var Ak=`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,jk={flying:Ak,landed:`M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z`};function Mk(e,t){if(!e)return;let n=e.querySelector(`path`);n&&n.setAttribute(`d`,jk[t])}function Nk(e,t,n,r){let i=document.createElement(`span`);i.className=`scene-label__name scene-label__name--${n}${r?` scene-label__name--large`:``}`,i.dir=`auto`,i.textContent=t;let a=e.firstElementChild;return a?a.after(i):e.appendChild(i),i}function Pk(e,t,n,r){if(n===`none`||!t||!e.label)return;let i=e.label.element,a=i.querySelector(`.scene-label__name`);a?a.textContent=t:Nk(i,t,n,r),tD(e)}function Fk(e){let t=e.data.objectType;return gn(t)||t===G.STAR||hn(t)||t===G.COMET||t===G.BARYCENTER||t===G.LAGRANGE_POINT?`major`:t===G.SPACECRAFT?`spacecraft`:t===G.DEBRIS?`debris`:`none`}function Ik(e,t,n,r,i,a=!1,o,s=!1){if(n===`none`)return null;let c=document.createElement(`a`);c.className=`scene-label scene-label--${n}`,r&&(c.href=r),c.tabIndex=-1,c.draggable=!1,t&&c.setAttribute(`aria-label`,t);let l;if(n===`major`){let t=document.createElement(`div`);t.className=`scene-label__halo scene-label__halo--major`,t.style.border=`2px solid ${e}`,t.style.background=`${e}22`,l=t}else{let t=`http://www.w3.org/2000/svg`,r=document.createElementNS(t,`svg`);r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`fill`,`${e}22`),r.setAttribute(`stroke`,e),r.setAttribute(`stroke-width`,`2`),r.setAttribute(`stroke-linejoin`,`round`),r.classList.add(`scene-label__halo`,`scene-label__halo--${n}`);let i=document.createElementNS(t,`path`);i.setAttribute(`d`,n===`debris`?`M3 5 L21 5 L12 21 Z`:Ak),r.appendChild(i),l=r}c.appendChild(l);let u=0,d=0;c.addEventListener(`pointerdown`,e=>{u=e.clientX,d=e.clientY});let f=e=>{if(e.stopPropagation(),nk(e))return;e.preventDefault();let t=e.clientX-u,n=e.clientY-d;t*t+n*n<=9&&i()};t&&Nk(c,t,n,a),s&&(l.style.transform=`scale(0.3)`),c.addEventListener(`click`,f),c.addEventListener(`mouseenter`,()=>{l.style.transform=`scale(1.15)`,document.body.style.cursor=`pointer`,o?.(!0)}),c.addEventListener(`mouseleave`,()=>{l.style.transform=s?`scale(0.3)`:``,lk(l),document.body.style.cursor=``,o?.(!1)});let p=new tk(c);return p.visible=!1,p}var Lk=3;function Rk(e,t){e.addEventListener(`wheel`,e=>{let n=e;t.dispatchEvent(new WheelEvent(`wheel`,{deltaY:n.deltaY,deltaMode:n.deltaMode,bubbles:!0,cancelable:!0})),n.preventDefault()},{passive:!1}),e.addEventListener(`pointerdown`,e=>{let n=e.clientX,r=e.clientY,i=e,a=e=>{let a=e.clientX-n,o=e.clientY-r;a*a+o*o>Lk*Lk&&(s(),t.dispatchEvent(new PointerEvent(`pointerdown`,i)),t.dispatchEvent(new PointerEvent(`pointermove`,e)))},o=()=>s(),s=()=>{window.removeEventListener(`pointermove`,a),window.removeEventListener(`pointerup`,o)};window.addEventListener(`pointermove`,a),window.addEventListener(`pointerup`,o)})}var zk=[`low`,`medium`,`high`,`ultra`],Bk={low:{primarySteps:6,lightSteps:2,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!1,layeredDensity:!1,groundAlbedo:!0,seasonal:!0,refraction:!0},medium:{primarySteps:12,lightSteps:3,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!1,layeredDensity:!1,groundAlbedo:!0,seasonal:!0,refraction:!0},high:{primarySteps:16,lightSteps:4,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!0,layeredDensity:!0,groundAlbedo:!0,seasonal:!0,refraction:!0},ultra:{primarySteps:32,lightSteps:8,eclipseShadows:!0,ringShadows:!0,insideView:!0,sunTint:!0,layeredDensity:!0,groundAlbedo:!0,seasonal:!0,refraction:!0}};function Vk(){return Ux()?Vx()?`low`:`medium`:Vx()?`high`:`ultra`}function Hk(e){if(e!==`auto`)return e;let t=jx();return t.atmosphereAutoTier??t.atmosphereCalibration?.tier??Vk()}function Uk(){let e=jx();return{...Bk[Hk(e.atmosphereQuality)],...e.atmoQualityOverrides}}function Wk(e){return`${e.primarySteps}|${e.lightSteps}|${+e.eclipseShadows}|${+e.ringShadows}|${+e.insideView}|${+e.layeredDensity}`}var Gk=30,Kk=45,qk=3e3,Jk=2500,Yk=250,Xk=60,Zk=0,Qk=Jk,$k=``;function eA(e,t){let n=jx();if(n.atmosphereQuality!==`auto`||e<=0||e>Yk)return;let r=Wk(Uk());if(r!==$k&&($k=r,Qk=Jk,Zk=0,Xk=60),Xk+=(1e3/e-Xk)*Math.min(1,e/500),Qk>0){Qk-=e;return}if(!t||Xk>Kk){Zk=Math.max(0,Zk-e);return}if(Xk>=Gk||(Zk+=e,Zk<qk))return;Zk=0;let i=zk[zk.indexOf(Hk(`auto`))-1];i&&n.setAtmosphereAutoTier(i)}var tA=256,nA=96;async function rA(e,t,n){let r=await fetch(e);if(!r.ok)throw Error(`Failed to load ${e}: ${r.status} ${r.statusText}`);let i=await r.blob(),a=await createImageBitmap(i),o=Math.min(a.width,n);o<a.width&&console.info(`Ring strip ${e}: downscaling ${a.width}px → ${o}px to fit GL MAX_TEXTURE_SIZE.`);let s=iA(a,e,n),c={};for(let[n,r]of Object.entries(t)){let t=document.createElement(`canvas`);t.width=o,t.height=2;let i=t.getContext(`2d`);if(!i)throw Error(`Failed to acquire 2D context for ring strip ${e}`);let l=aA(s,a.width,r,o);i.putImageData(l,0,0),i.putImageData(l,0,1);let u=new Mc(t);n===`color`&&(u.colorSpace=Jr),u.minFilter=Nn,u.magFilter=jn,u.generateMipmaps=!0,u.anisotropy=16,u.needsUpdate=!0,c[n]=u}return a.close(),c}function iA(e,t,n){let r=new Uint8ClampedArray(e.width*e.height*4),i=document.createElement(`canvas`);i.width=Math.min(e.width,n),i.height=e.height;let a=i.getContext(`2d`,{willReadFrequently:!0});if(!a)throw Error(`Failed to acquire 2D context for ring strip ${t}`);for(let t=0;t<e.width;t+=i.width){let n=Math.min(i.width,e.width-t);a.clearRect(0,0,n,e.height),a.drawImage(e,t,0,n,e.height,0,0,n,e.height);let o=a.getImageData(0,0,n,e.height).data;for(let i=0;i<e.height;i++)r.set(o.subarray(i*n*4,(i+1)*n*4),(i*e.width+t)*4)}return r}function aA(e,t,n,r){let i=new ImageData(r,1);for(let a=0;a<r;a++){let o=Math.floor(a*t/r),s=Math.max(o+1,Math.floor((a+1)*t/r)),c=0,l=0,u=0;for(let r=o;r<s;r++){let i=(n*t+r)*4;c+=e[i],l+=e[i+1],u+=e[i+2]}let d=s-o,f=a*4;i.data[f]=Math.round(c/d),i.data[f+1]=Math.round(l/d),i.data[f+2]=Math.round(u/d),i.data[f+3]=255}return i}var oA=`
4570
4570
  #include <common>
4571
4571
  #include <logdepthbuf_pars_vertex>
4572
4572
 
@@ -5547,7 +5547,7 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
5547
5547
  <line x1="10" y1="0" x2="23" y2="0" stroke="${r}" stroke-width="1.6"/>
5548
5548
  <line x1="0" y1="-23" x2="0" y2="-10" stroke="${r}" stroke-width="1.6"/>
5549
5549
  <line x1="0" y1="10" x2="0" y2="23" stroke="${r}" stroke-width="1.6"/>
5550
- `;let i=document.createElement(`span`);return i.textContent=e.label,i.style.color=e.color,i.style.marginInlineStart=`2px`,t.appendChild(n),t.appendChild(i),t}function WN(e,t,n,r,i){let a=new J().crossVectors(t,e).normalize(),o=new Float32Array(i*3),s=new J;for(let t=0;t<i;t++){let r=t/i*Math.PI*2,c=Math.cos(r),l=Math.sin(r);s.copy(e).multiplyScalar(c).addScaledVector(a,l).multiplyScalar(n),o[t*3]=s.x,o[t*3+1]=s.y,o[t*3+2]=s.z}let c=new Vo;c.setAttribute(`position`,new ko(o,3));let l=new Cc(c,new uc({color:r,transparent:!0,opacity:.55}));return l.frustumCulled=!1,l}function GN(){let e=new Ra;e.name=`sky-debug-markers`,e.visible=!1;let t=new J;for(let n of FN){HN(n.raDeg,n.decDeg,t).multiplyScalar(PN);let r=new tk(UN(n));r.center.set(0,.5),r.position.copy(t),e.add(r)}for(let t of VN){let n=WN(t.zero,t.pole,PN*.999,t.color,BN);n.name=t.name,e.add(n)}return e}function KN(e){e.traverse(e=>{e instanceof tk&&e.element.remove(),e instanceof Cc&&(e.geometry.dispose(),e.material.dispose())}),e.parent?.remove(e)}var qN=class{group=null;constructor(e){this.scene=e}setVisible(e){e?(this.group||(this.group=GN(),this.scene.add(this.group)),this.group.visible=!0):this.group&&=(KN(this.group),null)}},JN=new J,YN=new J,XN=new J,ZN=[JN,YN,XN];function QN(e,t,n){return JN.set(1,0,0).applyQuaternion(e).transformDirection(t),YN.set(0,1,0).applyQuaternion(e).transformDirection(t),XN.set(0,0,1).applyQuaternion(e).transformDirection(t),{e:ZN,a:n}}function $N(e,t,n,r,i,a,o,s,c,l){let u=1/i;e.gxx=u,e.gxy=0,e.gxz=0,e.gyx=0,e.gyy=u,e.gyz=0,e.gzx=0,e.gzy=0,e.gzz=u,e.cpx=t*u,e.cpy=n*u,e.cpz=r*u,e.K=(t*t+n*n+r*r)*u*u-1,e.cx0=o,e.cy0=s,e.f=a,e.id=c,e.dist=l,e.ccx=t,e.ccy=n,e.ccz=r}function eP(e,t,n,r,i,a,o,s,c,l){let[u,d,f]=i.e,[p,m,h]=i.a;e.gxx=u.x/p,e.gxy=u.y/p,e.gxz=u.z/p,e.gyx=d.x/m,e.gyy=d.y/m,e.gyz=d.z/m,e.gzx=f.x/h,e.gzy=f.y/h,e.gzz=f.z/h;let g=(t*u.x+n*u.y+r*u.z)/p,_=(t*d.x+n*d.y+r*d.z)/m,v=(t*f.x+n*f.y+r*f.z)/h;e.cpx=g,e.cpy=_,e.cpz=v,e.K=g*g+_*_+v*v-1,e.cx0=o,e.cy0=s,e.f=a,e.id=c,e.dist=l,e.ccx=t,e.ccy=n,e.ccz=r}function tP(e,t,n,r,i,a){let[o,s,c]=r.e,[l,u,d]=r.a,f=1/(l*l),p=1/(u*u),m=1/(d*d),h=f*o.x*o.x+p*s.x*s.x+m*c.x*c.x,g=f*o.x*o.y+p*s.x*s.y+m*c.x*c.y,_=f*o.x*o.z+p*s.x*s.z+m*c.x*c.z,v=f*o.y*o.y+p*s.y*s.y+m*c.y*c.y,y=f*o.y*o.z+p*s.y*s.z+m*c.y*c.z,b=f*o.z*o.z+p*s.z*s.z+m*c.z*c.z,x=h*e+g*t+_*n,S=g*e+v*t+y*n,C=_*e+y*t+b*n,w=e*x+t*S+n*C-1,T=i,E=w*h-x*x,D=2*(w*g-x*S),O=w*v-S*S,k=-2*T*(w*_-x*C),A=-2*T*(w*y-S*C),j=4*E*O-D*D,M=(-2*O*k+D*A)/j,ee=(-2*E*A+D*k)/j,N=-n/T;a.ox=M*N-e,a.oy=ee*N-t}var nP=class{canvas=null;gfx=null;tmp=new J;tmpQ=new Vi;items=[];one=[];labelRect={x:0,left:0,right:0,y:0,h:0};constructor(e){this.anchor=e}get active(){return this.canvas!==null}setVisible(e){if(e){if(this.canvas)return;let e=document.createElement(`canvas`);e.style.cssText=`position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:5`,this.anchor.parentElement?.appendChild(e),this.canvas=e,this.gfx=e.getContext(`2d`)}else this.canvas&&(this.canvas.remove(),this.canvas=null,this.gfx=null)}draw(e,t,n,r,i,a){let o=this.gfx,s=this.canvas;if(!o||!s)return;let c=window.devicePixelRatio||1,l=Math.round(i*c),u=Math.round(a*c);(s.width!==l||s.height!==u)&&(s.width=l,s.height=u),o.setTransform(c,0,0,c,0,0),o.clearRect(0,0,i,a),o.font=`10px monospace`,o.textBaseline=`middle`;let d=t.fov*Math.PI/180,f=a/(2*Math.tan(d/2)),p=t.matrixWorldInverse,[m,h,g]=n,_=i*.5,v=a*.5,y=0;for(let o of e.values()){let{label:e,group:s,radiusScene:c}=o;if(!e||c<=0)continue;let[l,u,d]=o.body.position;this.tmp.set(l-m,u-h,d-g).applyMatrix4(p);let b=this.tmp.x,x=this.tmp.y,S=this.tmp.z;if(S>=0||b*b+x*x+S*S<=c*c)continue;let C=rk(this.items,y++,rP),w=!!(o.semiAxesScene&&o.mesh);if(w){let e=QN(o.mesh.getWorldQuaternion(this.tmpQ),p,o.semiAxesScene);C.e0.copy(e.e[0]),C.e1.copy(e.e[1]),C.e2.copy(e.e[2]),C.sa[0]=e.a[0],C.sa[1]=e.a[1],C.sa[2]=e.a[2],eP(C.occ,b,x,S,e,f,_,v,o.body.data.id,o.cachedDist)}else C.e0.set(1,0,0),C.e1.set(0,1,0),C.e2.set(0,0,1),C.sa[0]=C.sa[1]=C.sa[2]=c,$N(C.occ,b,x,S,c,f,_,v,o.body.data.id,o.cachedDist);let T=S*S-c*c,E=T<=0,D=E?0:c*f/Math.sqrt(T),O=E||D>=16;this.tmp.set(l-m,u-h,d-g).project(t),C.cx=(this.tmp.x*.5+.5)*i,C.cy=(-this.tmp.y*.5+.5)*a,hk(o,t,n,i,a,this.labelRect),C.hx=this.labelRect.x,C.hy=this.labelRect.y,C.id=o.body.data.id,C.camX=b,C.camY=x,C.camZ=S,C.worldR=c,C.dist=o.cachedDist,C.isEllipsoid=w,C.degenerate=E,C.isOccluder=O,C.meshHidden=!s.visible,C.labelVisible=e.visible,C.maximized=o.labelMaximized!==!1,C.focused=o.body.data.id===r,C.occludedBy=-1}for(let e=0;e<y;e++){let t=this.items[e];for(let e=0;e<y;e++){let n=this.items[e];if(!(!n.isOccluder||n.id===t.id)&&(this.one[0]=n.occ,this.one.length=1,pk(t.hx,t.hy,t.dist,t.id,this.one))){t.occludedBy=e;break}}}for(let e=0;e<y;e++){let n=this.items[e];if(n.meshHidden&&!n.isOccluder)continue;let r=n.focused?`#7dff7d`:n.isOccluder?`#ff8c1a`:n.labelVisible?n.maximized?`#1ae5ff`:`#ffe11a`:`#ff3b3b`;if(o.beginPath(),n.meshHidden&&o.setLineDash([5,4]),this.strokeLimb(o,n,t,i,a)&&(o.strokeStyle=r,o.lineWidth=n.isOccluder?2:1,o.stroke(),n.isOccluder&&(o.fillStyle=`rgba(255,140,26,0.08)`,o.fill())),o.setLineDash([]),!n.degenerate){let e=n.hx-n.cx,t=n.hy-n.cy;if(e*e+t*t>1&&(o.beginPath(),o.moveTo(n.cx,n.cy),o.lineTo(n.hx,n.hy),o.strokeStyle=`rgba(255,225,26,0.5)`,o.lineWidth=1,o.stroke(),oP(o,n.cx,n.cy,4,`#ff3ad1`)),n.occludedBy>=0){let e=this.items[n.occludedBy];o.beginPath(),o.setLineDash([4,3]),o.moveTo(n.hx,n.hy),o.lineTo(e.cx,e.cy),o.strokeStyle=`rgba(255,59,59,0.9)`,o.lineWidth=1,o.stroke(),o.setLineDash([])}o.beginPath(),o.arc(n.hx,n.hy,1.5,0,Math.PI*2),o.fillStyle=r,o.fill(),o.fillStyle=`rgba(255,255,255,0.85)`,o.fillText(n.id,n.hx+8,n.hy)}}aP(o,a)}strokeLimb(e,t,n,r,i){let{camX:a,camY:o,camZ:s,e0:c,e1:l,e2:u,sa:d}=t,f=(a*c.x+o*c.y+s*c.z)/d[0],p=(a*l.x+o*l.y+s*l.z)/d[1],m=(a*u.x+o*u.y+s*u.z)/d[2],h=f*f+p*p+m*m;if(h<=1)return!1;let g=Math.sqrt(h),_=(h-1)/h,v=Math.sqrt(h-1)/g,y=f*_,b=p*_,x=m*_,S=f/g,C=p/g,w=m/g,T=0,E=1;Math.abs(w)>.9&&(T=1,E=0);let D=C*E-w*0,O=w*T-S*E,k=S*0-C*T,A=Math.hypot(D,O,k)||1;D/=A,O/=A,k/=A;let j=C*k-w*O,M=w*D-S*k,ee=S*O-C*D,N=n.projectionMatrix.elements,te=!1;for(let t=0;t<=72;t++){let n=t/72*Math.PI*2,a=Math.cos(n),o=Math.sin(n),s=y+v*(a*D+o*j),f=b+v*(a*O+o*M),p=x+v*(a*k+o*ee),m=d[0]*s*c.x+d[1]*f*l.x+d[2]*p*u.x,h=d[0]*s*c.y+d[1]*f*l.y+d[2]*p*u.y,g=d[0]*s*c.z+d[1]*f*l.z+d[2]*p*u.z,_=N[3]*m+N[7]*h+N[11]*g+N[15];if(_<=1e-6){te=!1;continue}let S=(N[0]*m+N[4]*h+N[8]*g+N[12])/_,C=(N[1]*m+N[5]*h+N[9]*g+N[13])/_,w=(S*.5+.5)*r,T=(-C*.5+.5)*i;te?e.lineTo(w,T):(e.moveTo(w,T),te=!0)}return!0}dispose(){this.setVisible(!1)}};function rP(){return{id:``,camX:0,camY:0,camZ:0,worldR:0,e0:new J,e1:new J,e2:new J,sa:[0,0,0],occ:sk(),cx:0,cy:0,hx:0,hy:0,dist:0,isEllipsoid:!1,isOccluder:!1,degenerate:!1,meshHidden:!1,labelVisible:!1,maximized:!1,focused:!1,occludedBy:-1}}var iP=[[`#1ae5ff`,`label shown`],[`#ffe11a`,`dimmed`],[`#ff3b3b`,`hidden`],[`#ff8c1a`,`occluder silhouette`],[`#7dff7d`,`focused`]];function aP(e,t){let n=t-8-(iP.length-1)*13;e.font=`10px monospace`,e.textBaseline=`middle`;for(let[t,r]of iP)e.fillStyle=t,e.fillRect(8,n-4,8,8),e.fillStyle=`rgba(255,255,255,0.9)`,e.fillText(r,20,n),n+=13}function oP(e,t,n,r,i){e.strokeStyle=i,e.lineWidth=1,e.beginPath(),e.moveTo(t-r,n),e.lineTo(t+r,n),e.moveTo(t,n-r),e.lineTo(t,n+r),e.stroke()}function sP(e){let{fps:t,orbitPool:n,renderer:r,bodyObjects:i,focusedBody:a,cameraDistanceScene:o}=e,s=r.info;return{fps:t,workers:n.workerCount,workerGroups:n.groupCount,drawCalls:s.render.calls,triangles:s.render.triangles,geometries:s.memory.geometries,textures:s.memory.textures,programs:s.programs?.length??0,promotedBodies:i.size,focusedId:a?.data.id,focusedName:a?.data.name??void 0,cameraDistanceAU:o/10,viewportW:r.domElement.clientWidth,viewportH:r.domElement.clientHeight,pixelRatio:r.getPixelRatio()}}var cP="function e(e,t,n=1e-10,r=50){let i=e;for(let a=0;a<r;a++){let r=(i-t*Math.sin(i)-e)/(1-t*Math.cos(i));if(i-=Math.max(-1,Math.min(1,r)),Math.abs(r)<n)break}return i}function t(e,t,n=1e-10,r=50){if(e===0)return 0;let i=e<0?-1:1,a=Math.abs(e),o=0,s=1;for(;t*Math.sinh(s)-s<a;)if(s*=2,s>700)return NaN;let c=.5*(o+s);for(let e=0;e<r;e++){let e=t*Math.sinh(c)-c-a;e>0?s=c:o=c;let r=c-e/(t*Math.cosh(c)-1);r>o&&r<s||(r=.5*(o+s));let i=Math.abs(r-c);if(c=r,i<n)break}return i*c}function n(e,t,n){let r=.01720209895*(n-t)/(Math.sqrt(2)*e**1.5),i=Math.cbrt(3*r+Math.sqrt(1+9*r*r)),a=i-1/i,o=2*Math.atan(a),s=e*(1+a*a);return!isFinite(o)||!isFinite(s)||s<=0?null:{nu:o,r:s}}const r=149597870.7,i=23.4392911;86400**2/r**3,1/r,Math.cos(Math.PI/180*i),Math.sin(Math.PI/180*i);const a=Math.PI,o=a*2,s=a/180;180/a;const c=6378.135,l=60/Math.sqrt(c*c*c/398600.8),u=c*l/60,d=1/l,f=.001082616,p=-253881e-11/f,m=2/3,ee=1440/(2*a);function te(e,t){let n=[31,e%4==0?29:28,31,30,31,30,31,31,30,31,30,31],r=Math.floor(t),i=1,a=0;for(;r>a+n[i-1]&&i<12;)a+=n[i-1],i+=1;let o=i,s=r-a,c=(t-r)*24,l=Math.floor(c);c=(c-l)*60;let u=Math.floor(c);return{mon:o,day:s,hr:l,minute:u,sec:(c-u)*60}}function h(e,t,n,r,i,a,o=0){return 367*e-Math.floor(7*(e+Math.floor((t+9)/12))*.25)+Math.floor(275*t/9)+n+1721013.5+((o/6e4+a/60+i)/60+r)/24}function g(e,t,n,r,i,a,o=0){if(e instanceof Date){let t=e;return h(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds())}return h(e,t,n,r,i,a,o)}function ne(e,t){let{e3:n,ee2:r,peo:i,pgho:s,pho:c,pinco:l,plo:u,se2:d,se3:f,sgh2:p,sgh3:m,sgh4:ee,sh2:te,sh3:h,si2:g,si3:ne,sl2:_,sl3:v,sl4:y,t:b,xgh2:re,xgh3:ie,xgh4:x,xh2:ae,xh3:S,xi2:C,xi3:w,xl2:T,xl3:E,xl4:D,zmol:O,zmos:k}=e,{init:A,opsmode:j}=t,{ep:oe,inclp:M,nodep:N,argpp:se,mp:P}=t,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,le,Y,ue,de,X,fe;fe=k+119459e-10*b,A===`y`&&(fe=k),X=fe+2*.01675*Math.sin(fe),Y=Math.sin(X),U=.5*Y*Y-.25,W=-.5*Y*Math.cos(X);let pe=d*U+f*W,me=g*U+ne*W,he=_*U+v*W+y*Y,ge=p*U+m*W+ee*Y,Z=te*U+h*W;fe=O+.00015835218*b,A===`y`&&(fe=O),X=fe+2*.0549*Math.sin(fe),Y=Math.sin(X),U=.5*Y*Y-.25,W=-.5*Y*Math.cos(X);let _e=r*U+n*W,ve=C*U+w*W,ye=T*U+E*W+D*Y,be=re*U+ie*W+x*Y,xe=ae*U+S*W;return G=pe+_e,J=me+ve,le=he+ye,K=ge+be,q=Z+xe,A===`n`&&(G-=i,J-=l,le-=u,K-=s,q-=c,M+=J,oe+=G,R=Math.sin(M),L=Math.cos(M),M>=.2?(q/=R,K-=L*q,se+=K,N+=q,P+=le):(z=Math.sin(N),ce=Math.cos(N),F=R*z,I=R*ce,B=q*ce+J*L*z,V=-q*z+J*L*ce,F+=B,I+=V,N%=o,N<0&&j===`a`&&(N+=o),ue=P+se+L*N,H=le+K-J*N*R,ue+=H,de=N,N=Math.atan2(F,I),N<0&&j===`a`&&(N+=o),Math.abs(de-N)>a&&(N<de?N+=o:N-=o),P+=le,se=ue-P-L*N)),{ep:oe,inclp:M,nodep:N,argpp:se,mp:P}}function _(e){let{epoch:t,ep:n,argpp:r,tc:i,inclp:a,nodep:s,np:c}=e,l,u,d,f,p,m,ee,te,h,g,ne,_,v,y,b,re,ie,x,ae,S,C,w,T,E,D,O,k,A,j,oe,M,N,se,P,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,le,Y,ue,de,X,fe,pe,me,he,ge,Z,_e,ve,ye,be=.01675,xe=.0549,Se=c,Ce=n,we=Math.sin(s),Te=Math.cos(s),Ee=Math.sin(r),Q=Math.cos(r),De=Math.sin(a),Oe=Math.cos(a),$=Ce*Ce,ke=1-$,Ae=Math.sqrt(ke),je=t+18261.5+i/1440,Me=(4.523602-.00092422029*je)%o,Ne=Math.sin(Me),Pe=Math.cos(Me),Fe=.91375164-.03568096*Pe,Ie=Math.sqrt(1-Fe*Fe),Le=.089683511*Ne/Ie,Re=Math.sqrt(1-Le*Le),ze=5.8351514+.001944368*je,Be=.39785416*Ne/Ie,Ve=Re*Pe+.91744867*Le*Ne;Be=Math.atan2(Be,Ve),Be+=ze-Me;let He=Math.cos(Be),Ue=Math.sin(Be);S=.1945905,C=-.98088458,E=.91744867,D=.39785416,w=Te,T=we,ne=29864797e-13;let We=1/Se,Ge=0;for(;Ge<2;)Ge+=1,l=S*w+C*E*T,d=-C*w+S*E*T,ee=-S*T+C*E*w,te=C*D,h=C*T+S*E*w,g=S*D,u=Oe*ee+De*te,f=Oe*h+De*g,p=-De*ee+Oe*te,m=-De*h+Oe*g,_=l*Q+u*Ee,v=d*Q+f*Ee,y=-l*Ee+u*Q,b=-d*Ee+f*Q,re=p*Ee,ie=m*Ee,x=p*Q,ae=m*Q,_e=12*_*_-3*y*y,ve=24*_*v-6*y*b,ye=12*v*v-3*b*b,ue=3*(l*l+u*u)+_e*$,de=6*(l*d+u*f)+ve*$,X=3*(d*d+f*f)+ye*$,fe=-6*l*p+$*(-24*_*x-6*y*re),pe=-6*(l*m+d*p)+$*(-24*(v*x+_*ae)+-6*(y*ie+b*re)),me=-6*d*m+$*(-24*v*ae-6*b*ie),he=6*u*p+$*(24*_*re-6*y*x),ge=6*(f*p+u*m)+$*(24*(v*re+_*ie)-6*(b*x+y*ae)),Z=6*f*m+$*(24*v*ie-6*b*ae),ue=ue+ue+ke*_e,de=de+de+ke*ve,X=X+X+ke*ye,K=ne*We,G=-.5*K/Ae,q=K*Ae,W=-15*Ce*q,J=_*y+v*b,le=v*y+_*b,Y=v*b-_*y,Ge===1&&(O=W,k=G,A=K,j=q,oe=J,M=le,N=Y,se=ue,P=de,F=X,I=fe,L=pe,R=me,ce=he,z=ge,B=Z,V=_e,H=ve,U=ye,S=He,C=Ue,E=Fe,D=Ie,w=Re*Te+Le*we,T=we*Re-Te*Le,ne=4.7968065e-7);let Ke=(4.7199672+(.2299715*je-ze))%o,qe=(6.2565837+.017201977*je)%o,Je=2*O*M,Ye=2*O*N,Xe=2*k*L,Ze=2*k*(R-I),Qe=-2*A*P,$e=-2*A*(F-se),et=-2*A*(-21-9*$)*be,tt=2*j*H,nt=2*j*(U-V),rt=-18*j*be,it=-2*k*z,at=-2*k*(B-ce),ot=2*W*le,st=2*W*Y,ct=2*G*pe,lt=2*G*(me-fe),ut=-2*K*de,dt=-2*K*(X-ue),ft=-2*K*(-21-9*$)*xe,pt=2*q*ve,mt=2*q*(ye-_e),ht=-18*q*xe,gt=-2*G*ge,_t=-2*G*(Z-he);return{snodm:we,cnodm:Te,sinim:De,cosim:Oe,sinomm:Ee,cosomm:Q,day:je,e3:st,ee2:ot,em:Ce,emsq:$,gam:ze,peo:0,pgho:0,pho:0,pinco:0,plo:0,rtemsq:Ae,se2:Je,se3:Ye,sgh2:tt,sgh3:nt,sgh4:rt,sh2:it,sh3:at,si2:Xe,si3:Ze,sl2:Qe,sl3:$e,sl4:et,s1:W,s2:G,s3:K,s4:q,s5:J,s6:le,s7:Y,ss1:O,ss2:k,ss3:A,ss4:j,ss5:oe,ss6:M,ss7:N,sz1:se,sz2:P,sz3:F,sz11:I,sz12:L,sz13:R,sz21:ce,sz22:z,sz23:B,sz31:V,sz32:H,sz33:U,xgh2:pt,xgh3:mt,xgh4:ht,xh2:gt,xh3:_t,xi2:ct,xi3:lt,xl2:ut,xl3:dt,xl4:ft,nm:Se,z1:ue,z2:de,z3:X,z11:fe,z12:pe,z13:me,z21:he,z22:ge,z23:Z,z31:_e,z32:ve,z33:ye,zmol:Ke,zmos:qe}}function v(e){let{cosim:t,argpo:n,s1:r,s2:i,s3:s,s4:c,s5:u,sinim:d,ss1:f,ss2:p,ss3:ee,ss4:te,ss5:h,sz1:g,sz3:ne,sz11:_,sz13:v,sz21:y,sz23:b,sz31:re,sz33:ie,t:x,tc:ae,gsto:S,mo:C,mdot:w,no:T,nodeo:E,nodedot:D,xpidot:O,z1:k,z3:A,z11:j,z13:oe,z21:M,z23:N,z31:se,z33:P,ecco:F,eccsq:I}=e,{emsq:L,em:R,argpm:ce,inclm:z,mm:B,nm:V,nodem:H,irez:U,atime:W,d2201:G,d2211:K,d3210:q,d3222:J,d4410:le,d4422:Y,d5220:ue,d5232:de,d5421:X,d5433:fe,dedt:pe,didt:me,dmdt:he,dnodt:ge,domdt:Z,del1:_e,del2:ve,del3:ye,xfact:be,xlamo:xe,xli:Se,xni:Ce}=e,we,Te,Ee,Q,De,Oe,$,ke,Ae,je,Me,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et=.0043752690880113,tt=.00015835218,nt=119459e-10;U=0,V<.0052359877&&V>.0034906585&&(U=1),V>=.00826&&V<=.00924&&R>=.5&&(U=2);let rt=f*nt*h,it=p*nt*(_+v),at=-nt*ee*(g+ne-14-6*L),ot=te*nt*(re+ie-6),st=-nt*p*(y+b);(z<.052359877||z>a-.052359877)&&(st=0),d!==0&&(st/=d);let ct=ot-t*st;pe=rt+r*tt*u,me=it+i*tt*(j+oe),he=at-tt*s*(k+A-14-6*L);let lt=c*tt*(se+P-6),ut=-tt*i*(M+N);(z<.052359877||z>a-.052359877)&&(ut=0),Z=ct+lt,ge=st,d!==0&&(Z-=t/d*ut,ge+=ut/d);let dt=(S+ae*et)%o;if(R+=pe*x,z+=me*x,ce+=Z*x,H+=ge*x,B+=he*x,U!==0){if(Ze=(V/l)**m,U===2){Qe=t*t;let e=R;R=F;let n=L;L=I,$e=R*L,Fe=-.306-(R-.64)*.44,R<=.65?(Ie=3.616-13.247*R+16.29*L,Re=-19.302+117.39*R-228.419*L+156.591*$e,ze=-18.9068+109.7927*R-214.6334*L+146.5816*$e,Be=-41.122+242.694*R-471.094*L+313.953*$e,Ve=-146.407+841.88*R-1629.014*L+1083.435*$e,He=-532.114+3017.977*R-5740.032*L+3708.276*$e):(Ie=-72.099+331.819*R-508.738*L+266.724*$e,Re=-346.844+1582.851*R-2415.925*L+1246.113*$e,ze=-342.585+1554.908*R-2366.899*L+1215.972*$e,Be=-1052.797+4758.686*R-7193.992*L+3651.957*$e,Ve=-3581.69+16178.11*R-24462.77*L+12422.52*$e,He=R>.715?-5149.66+29936.92*R-54087.36*L+31324.56*$e:1464.74-4664.75*R+3763.64*L),R<.7?(Ge=-919.2277+4988.61*R-9064.77*L+5542.21*$e,Ue=-822.71072+4568.6173*R-8491.4146*L+5337.524*$e,We=-853.666+4690.25*R-8624.77*L+5341.4*$e):(Ge=-37995.78+161616.52*R-229838.2*L+109377.94*$e,Ue=-51752.104+218913.95*R-309468.16*L+146349.42*$e,We=-40023.88+170470.89*R-242699.48*L+115605.82*$e),Ke=d*d,we=.75*(1+2*t+Qe),Te=1.5*Ke,Q=1.875*d*(1-2*t-3*Qe),De=-1.875*d*(1+2*t-3*Qe),$=35*Ke*we,ke=39.375*Ke*Ke,Ae=9.84375*d*(Ke*(1-2*t-5*Qe)+.33333333*(-2+4*t+6*Qe)),je=d*(4.92187512*Ke*(-2-4*t+10*Qe)+6.56250012*(1+2*t-3*Qe)),Me=29.53125*d*(2-8*t+Qe*(-12+8*t+10*Qe)),Ne=29.53125*d*(-2-8*t+Qe*(12+8*t-10*Qe)),Ye=V*V,Xe=Ze*Ze,Je=3*Ye*Xe,qe=Je*17891679e-13,G=qe*we*Fe,K=qe*Te*Ie,Je*=Ze,qe=Je*3.7393792e-7,q=qe*Q*Re,J=qe*De*ze,Je*=Ze,qe=2*Je*7.3636953e-9,le=qe*$*Be,Y=qe*ke*Ve,Je*=Ze,qe=Je*1.1428639e-7,ue=qe*Ae*He,de=qe*je*We,qe=2*Je*2.1765803e-9,X=qe*Me*Ue,fe=qe*Ne*Ge,xe=(C+E+E-(dt+dt))%o,be=w+he+2*(D+ge-et)-T,R=e,L=n}U===1&&(Pe=1+L*(-2.5+.8125*L),Re=1+2*L,Le=1+L*(-6+6.60937*L),we=.75*(1+t)*(1+t),Ee=.9375*d*d*(1+3*t)-.75*(1+t),Oe=1+t,Oe*=1.875*Oe*Oe,_e=3*V*V*Ze*Ze,ve=2*_e*we*Pe*17891679e-13,ye=3*_e*Oe*Le*2.2123015e-7*Ze,_e=_e*Ee*Re*21460748e-13*Ze,xe=(C+E+n-dt)%o,be=w+O+he+Z+ge-(T+et)),Se=xe,Ce=T,W=0,V=T+0}return{em:R,argpm:ce,inclm:z,mm:B,nm:V,nodem:H,irez:U,atime:W,d2201:G,d2211:K,d3210:q,d3222:J,d4410:le,d4422:Y,d5220:ue,d5232:de,d5421:X,d5433:fe,dedt:pe,didt:me,dmdt:he,dndt:0,dnodt:ge,domdt:Z,del1:_e,del2:ve,del3:ye,xfact:be,xlamo:xe,xli:Se,xni:Ce}}function y(e){let t=(e-2451545)/36525,n=-62e-7*t*t*t+.093104*t*t+3164400184.812866*t+67310.54841;return n=n*s/240%o,n<0&&(n+=o),n}function b(e,t,n,r,i,a,o){return e instanceof Date?y(g(e)):y(t===void 0?e:g(e,t,n,r,i,a,o))}function re(e){let{ecco:t,epoch:n,inclo:r,opsmode:i}=e,{no:a}=e,s=t*t,c=1-s,u=Math.sqrt(c),d=Math.cos(r),p=d*d,ee=(l/a)**m,te=.75*f*(3*p-1)/(u*c),h=te/(ee*ee),g=ee*(1-h*h-h*(1/3+134*h*h/81));h=te/(g*g),a/=1+h;let ne=(l/a)**m,_=Math.sin(r),v=ne*c,y=1-5*p,re=-y-p-p,ie=1/ne,x=v*v,ae=ne*(1-t),S;if(i===`a`){let e=n-7305,t=Math.floor(e+1e-8),r=e-t,i=.017202791694070362,a=i+o;S=(1.7321343856509375+i*t+a*r+e*e*5075514194322695e-30)%o,S<0&&(S+=o)}else S=b(n+2433281.5);return{no:a,method:`n`,ainv:ie,ao:ne,con41:re,con42:y,cosio:d,cosio2:p,eccsq:s,omeosq:c,posq:x,rp:ae,rteosq:u,sinio:_,gsto:S}}function ie(e){let{irez:t,d2201:n,d2211:r,d3210:i,d3222:a,d4410:s,d4422:c,d5220:l,d5232:u,d5421:d,d5433:f,dedt:p,del1:m,del2:ee,del3:te,didt:h,dmdt:g,dnodt:ne,domdt:_,argpo:v,argpdot:y,t:b,tc:re,gsto:ie,xfact:x,xlamo:ae,no:S}=e,{atime:C,em:w,argpm:T,inclm:E,xli:D,mm:O,xni:k,nodem:A,nm:j}=e,oe=.13130908,M=2.8843198,N=.37448087,se=5.7686396,P=.95240898,F=1.8014998,I=1.050833,L=4.4108898,R=259200,ce,z,B,V,H,U,W,G,K=0,q=0,J=(ie+re*.0043752690880113)%o;if(w+=p*b,E+=h*b,T+=_*b,A+=ne*b,O+=g*b,t!==0){(C===0||b*C<=0||Math.abs(b)<Math.abs(C))&&(C=0,k=S,D=ae),ce=b>0?720:-720;let e=381;for(;e===381;)t===2?(G=v+y*C,B=G+G,z=D+D,W=n*Math.sin(B+D-se)+r*Math.sin(D-se)+i*Math.sin(G+D-P)+a*Math.sin(-G+D-P)+s*Math.sin(B+z-F)+c*Math.sin(z-F)+l*Math.sin(G+D-I)+u*Math.sin(-G+D-I)+d*Math.sin(G+z-L)+f*Math.sin(-G+z-L),H=k+x,U=n*Math.cos(B+D-se)+r*Math.cos(D-se)+i*Math.cos(G+D-P)+a*Math.cos(-G+D-P)+l*Math.cos(G+D-I)+u*Math.cos(-G+D-I)+2*(s*Math.cos(B+z-F)+c*Math.cos(z-F)+d*Math.cos(G+z-L)+f*Math.cos(-G+z-L)),U*=H):(W=m*Math.sin(D-oe)+ee*Math.sin(2*(D-M))+te*Math.sin(3*(D-N)),H=k+x,U=m*Math.cos(D-oe)+2*ee*Math.cos(2*(D-M))+3*te*Math.cos(3*(D-N)),U*=H),Math.abs(b-C)>=720?e=381:(q=b-C,e=0),e===381&&(D+=H*ce+W*R,k+=W*ce+U*R,C+=ce);j=k+W*q+U*q*q*.5,V=D+H*q+W*q*q*.5,t===1?(O=V-A-T+J,K=j-S):(O=V-2*A+2*J,K=j-S),j=S+K}return{atime:C,em:w,argpm:T,inclm:E,xli:D,mm:O,xni:k,nodem:A,dndt:K,nm:j}}var x;(function(e){e[e.None=0]=`None`,e[e.MeanEccentricityOutOfRange=1]=`MeanEccentricityOutOfRange`,e[e.MeanMotionBelowZero=2]=`MeanMotionBelowZero`,e[e.PerturbedEccentricityOutOfRange=3]=`PerturbedEccentricityOutOfRange`,e[e.SemiLatusRectumBelowZero=4]=`SemiLatusRectumBelowZero`,e[e.Decayed=6]=`Decayed`})(x||={});function ae(e,t){let n,r,i,s,d,ee,te,h,g,_,v,y,b,re,ae,S,C,w,T,E,D,O,k,A,j,oe,M;e.t=t,e.error=x.None;let N=e.mo+e.mdot*e.t,se=e.argpo+e.argpdot*e.t,P=e.nodeo+e.nodedot*e.t;g=se,D=N;let F=e.t*e.t;if(k=P+e.nodecf*F,C=1-e.cc1*e.t,w=e.bstar*e.cc4*e.t,T=e.t2cof*F,e.isimp!==1){te=e.omgcof*e.t;let t=1+e.eta*Math.cos(N);ee=e.xmcof*(t*t*t-e.delmo),S=te+ee,D=N+S,g=se-S,y=F*e.t,b=y*e.t,C=C-e.d2*F-e.d3*y-e.d4*b,w+=e.bstar*e.cc5*(Math.sin(D)-e.sinmao),T=T+e.t3cof*y+b*(e.t4cof+e.t*e.t5cof)}O=e.no;let I=e.ecco;if(E=e.inclo,e.method===`d`){re=e.t;let t=ie({irez:e.irez,d2201:e.d2201,d2211:e.d2211,d3210:e.d3210,d3222:e.d3222,d4410:e.d4410,d4422:e.d4422,d5220:e.d5220,d5232:e.d5232,d5421:e.d5421,d5433:e.d5433,dedt:e.dedt,del1:e.del1,del2:e.del2,del3:e.del3,didt:e.didt,dmdt:e.dmdt,dnodt:e.dnodt,domdt:e.domdt,argpo:e.argpo,argpdot:e.argpdot,t:e.t,tc:re,gsto:e.gsto,xfact:e.xfact,xlamo:e.xlamo,no:e.no,atime:e.atime,em:I,argpm:g,inclm:E,xli:e.xli,mm:D,xni:e.xni,nodem:k,nm:O});({em:I,argpm:g,inclm:E,mm:D,nodem:k,nm:O}=t)}if(O<=0)return e.error=x.MeanMotionBelowZero,null;let L=(l/O)**m*C*C;if(O=l/L**1.5,I-=w,I>=1||I<-.001)return e.error=x.MeanEccentricityOutOfRange,null;I<1e-6&&(I=1e-6),D+=e.no*T,j=D+g+k,k%=o,g%=o,j%=o,D=(j-g-k)%o;let R={am:L,em:I,im:E,Om:k,om:g,mm:D,nm:O},ce=Math.sin(E),z=Math.cos(E),B=I;if(A=E,_=g,M=k,oe=D,s=ce,i=z,e.method===`d`){let t=ne(e,{inclo:e.inclo,init:`n`,ep:B,inclp:A,nodep:M,argpp:_,mp:oe,opsmode:e.operationmode});if({ep:B,nodep:M,argpp:_,mp:oe}=t,A=t.inclp,A<0&&(A=-A,M+=a,_-=a),B<0||B>1)return e.error=x.PerturbedEccentricityOutOfRange,null}e.method===`d`&&(s=Math.sin(A),i=Math.cos(A),e.aycof=-.5*p*s,Math.abs(i+1)>15e-13?e.xlcof=-.25*p*s*(3+5*i)/(1+i):e.xlcof=-.25*p*s*(3+5*i)/15e-13);let V=B*Math.cos(_);S=1/(L*(1-B*B));let H=B*Math.sin(_)+S*e.aycof,U=(oe+_+M+S*e.xlcof*V-M)%o;h=U,ae=9999.9;let W=1;for(;Math.abs(ae)>=1e-12&&W<=10;)r=Math.sin(h),n=Math.cos(h),ae=1-n*V-r*H,ae=(U-H*n+V*r-h)/ae,Math.abs(ae)>=.95&&(ae=ae>0?.95:-.95),h+=ae,W+=1;let G=V*n+H*r,K=V*r-H*n,q=V*V+H*H,J=L*(1-q);if(J<0)return e.error=x.SemiLatusRectumBelowZero,null;let le=L*(1-G),Y=Math.sqrt(L)*K/le,ue=Math.sqrt(J)/le,de=Math.sqrt(1-q);S=K/(1+de);let X=L/le*(r-H-V*S),fe=L/le*(n-V+H*S);v=Math.atan2(X,fe);let pe=(fe+fe)*X,me=1-2*X*X;S=1/J;let he=.5*f*S,ge=he*S;e.method===`d`&&(d=i*i,e.con41=3*d-1,e.x1mth2=1-d,e.x7thm1=7*d-1);let Z=le*(1-1.5*ge*de*e.con41)+.5*he*e.x1mth2*me;if(Z<1)return e.error=x.Decayed,null;v-=.25*ge*e.x7thm1*pe;let _e=M+1.5*ge*i*pe,ve=A+1.5*ge*i*s*me,ye=Y-O*he*e.x1mth2*pe/l,be=ue+O*he*(e.x1mth2*me+1.5*e.con41)/l,xe=Math.sin(v),Se=Math.cos(v),Ce=Math.sin(_e),we=Math.cos(_e),Te=Math.sin(ve),Ee=Math.cos(ve),Q=-Ce*Ee,De=we*Ee,Oe=Q*xe+we*Se,$=De*xe+Ce*Se,ke=Te*xe,Ae=Q*Se-we*xe,je=De*Se-Ce*xe,Me=Te*Se;return{position:{x:Z*Oe*c,y:Z*$*c,z:Z*ke*c},velocity:{x:(ye*Oe+be*Ae)*u,y:(ye*$+be*je)*u,z:(ye*ke+be*Me)*u},meanElements:R}}function S(e,t){let{opsmode:n,satn:r,epoch:i,xbstar:o,xecco:s,xargpo:l,xinclo:u,xmo:ee,xno:te,xnodeo:h}=t,g,y,b,ie,x,S,C,w,T,E,D,O,k,A,j,oe,M,N,se,P,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,le,Y,ue,de,X,fe,pe,me,he,ge,Z,_e,ve,ye,be,xe,Se,Ce,we,Te,Ee,Q=e;Q.isimp=0,Q.method=`n`,Q.aycof=0,Q.con41=0,Q.cc1=0,Q.cc4=0,Q.cc5=0,Q.d2=0,Q.d3=0,Q.d4=0,Q.delmo=0,Q.eta=0,Q.argpdot=0,Q.omgcof=0,Q.sinmao=0,Q.t=0,Q.t2cof=0,Q.t3cof=0,Q.t4cof=0,Q.t5cof=0,Q.x1mth2=0,Q.x7thm1=0,Q.mdot=0,Q.nodedot=0,Q.xlcof=0,Q.xmcof=0,Q.nodecf=0,Q.irez=0,Q.d2201=0,Q.d2211=0,Q.d3210=0,Q.d3222=0,Q.d4410=0,Q.d4422=0,Q.d5220=0,Q.d5232=0,Q.d5421=0,Q.d5433=0,Q.dedt=0,Q.del1=0,Q.del2=0,Q.del3=0,Q.didt=0,Q.dmdt=0,Q.dnodt=0,Q.domdt=0,Q.e3=0,Q.ee2=0,Q.peo=0,Q.pgho=0,Q.pho=0,Q.pinco=0,Q.plo=0,Q.se2=0,Q.se3=0,Q.sgh2=0,Q.sgh3=0,Q.sgh4=0,Q.sh2=0,Q.sh3=0,Q.si2=0,Q.si3=0,Q.sl2=0,Q.sl3=0,Q.sl4=0,Q.gsto=0,Q.xfact=0,Q.xgh2=0,Q.xgh3=0,Q.xgh4=0,Q.xh2=0,Q.xh3=0,Q.xi2=0,Q.xi3=0,Q.xl2=0,Q.xl3=0,Q.xl4=0,Q.xlamo=0,Q.zmol=0,Q.zmos=0,Q.atime=0,Q.xli=0,Q.xni=0,Q.bstar=o,Q.ecco=s,Q.argpo=l,Q.inclo=u,Q.mo=ee,Q.no=te,Q.nodeo=h,Q.operationmode=n,78/c+1;let De=42/c;De*De*De*De,Q.init=`y`,Q.t=0;let Oe=re({satn:r,ecco:Q.ecco,epoch:i,inclo:Q.inclo,no:Q.no,method:Q.method,opsmode:Q.operationmode}),{ao:$,con42:ke,cosio:Ae,cosio2:je,eccsq:Me,omeosq:Ne,posq:Pe,rp:Fe,rteosq:Ie,sinio:Le}=Oe;if(Q.no=Oe.no,Q.con41=Oe.con41,Q.gsto=Oe.gsto,Q.a=(Q.no*d)**(-2/3),Q.alta=Q.a*(1+Q.ecco)-1,Q.altp=Q.a*(1-Q.ecco)-1,Q.error=0,Ne>=0||Q.no>=0){if(Q.isimp=0,Fe<1.034492841559484&&(Q.isimp=1),B=1.0122292801892716,F=1.880279159015271e-9,N=(Fe-1)*c,N<156){B=N-78,N<98&&(B=20);let e=(120-B)/c;F=e*e*e*e,B=B/c+1}se=1/Pe,Z=1/($-B),Q.eta=$*Q.ecco*Z,O=Q.eta*Q.eta,D=Q.ecco*Q.eta,P=Math.abs(1-O),S=F*Z**4,C=S/P**3.5,ie=C*Q.no*($*(1+1.5*O+D*(4+O))+.375*f*Z/P*Q.con41*(8+3*O*(8+O))),Q.cc1=Q.bstar*ie,x=0,Q.ecco>1e-4&&(x=-2*S*Z*p*Q.no*Le/Q.ecco),Q.x1mth2=1-je,Q.cc4=2*Q.no*C*$*Ne*(Q.eta*(2+.5*O)+Q.ecco*(.5+2*O)-f*Z/($*P)*(-3*Q.con41*(1-2*D+O*(1.5-.5*D))+.75*Q.x1mth2*(2*O-D*(1+O))*Math.cos(2*Q.argpo))),Q.cc5=2*C*$*Ne*(1+2.75*(O+D)+D*O),w=je*je,me=1.5*f*se*Q.no,he=.5*me*f*se,ge=-.46875*-165597e-11*se*se*Q.no,Q.mdot=Q.no+.5*me*Ie*Q.con41+.0625*he*Ie*(13-78*je+137*w),Q.argpdot=-.5*me*ke+.0625*he*(7-114*je+395*w)+ge*(3-36*je+49*w),ve=-me*Ae,Q.nodedot=ve+(.5*he*(4-19*je)+2*ge*(3-7*je))*Ae,_e=Q.argpdot+Q.nodedot,Q.omgcof=Q.bstar*x*Math.cos(Q.argpo),Q.xmcof=0,Q.ecco>1e-4&&(Q.xmcof=-m*S*Q.bstar/D),Q.nodecf=3.5*Ne*ve*Q.cc1,Q.t2cof=1.5*Q.cc1,Math.abs(Ae+1)>15e-13?Q.xlcof=-.25*p*Le*(3+5*Ae)/(1+Ae):Q.xlcof=-.25*p*Le*(3+5*Ae)/15e-13,Q.aycof=-.5*p*Le;let e=1+Q.eta*Math.cos(Q.mo);if(Q.delmo=e*e*e,Q.sinmao=Math.sin(Q.mo),Q.x7thm1=7*je-1,2*a/Q.no>=225){Q.method=`d`,Q.isimp=1,fe=0,j=Q.inclo;let e=_({epoch:i,ep:Q.ecco,argpp:Q.argpo,tc:fe,inclp:Q.inclo,nodep:Q.nodeo,np:Q.no,e3:Q.e3,ee2:Q.ee2,peo:Q.peo,pgho:Q.pgho,pho:Q.pho,pinco:Q.pinco,plo:Q.plo,se2:Q.se2,se3:Q.se3,sgh2:Q.sgh2,sgh3:Q.sgh3,sgh4:Q.sgh4,sh2:Q.sh2,sh3:Q.sh3,si2:Q.si2,si3:Q.si3,sl2:Q.sl2,sl3:Q.sl3,sl4:Q.sl4,xgh2:Q.xgh2,xgh3:Q.xgh3,xgh4:Q.xgh4,xh2:Q.xh2,xh3:Q.xh3,xi2:Q.xi2,xi3:Q.xi3,xl2:Q.xl2,xl3:Q.xl3,xl4:Q.xl4,zmol:Q.zmol,zmos:Q.zmos});Q.e3=e.e3,Q.ee2=e.ee2,Q.peo=e.peo,Q.pgho=e.pgho,Q.pho=e.pho,Q.pinco=e.pinco,Q.plo=e.plo,Q.se2=e.se2,Q.se3=e.se3,Q.sgh2=e.sgh2,Q.sgh3=e.sgh3,Q.sgh4=e.sgh4,Q.sh2=e.sh2,Q.sh3=e.sh3,Q.si2=e.si2,Q.si3=e.si3,Q.sl2=e.sl2,Q.sl3=e.sl3,Q.sl4=e.sl4,{sinim:y,cosim:g,em:T,emsq:E,s1:I,s2:L,s3:R,s4:ce,s5:z,ss1:V,ss2:H,ss3:U,ss4:W,ss5:G,sz1:K,sz3:q,sz11:J,sz13:le,sz21:Y,sz23:ue,sz31:de,sz33:X}=e,Q.xgh2=e.xgh2,Q.xgh3=e.xgh3,Q.xgh4=e.xgh4,Q.xh2=e.xh2,Q.xh3=e.xh3,Q.xi2=e.xi2,Q.xi3=e.xi3,Q.xl2=e.xl2,Q.xl3=e.xl3,Q.xl4=e.xl4,Q.zmol=e.zmol,Q.zmos=e.zmos,{nm:M,z1:ye,z3:be,z11:xe,z13:Se,z21:Ce,z23:we,z31:Te,z33:Ee}=e;let t=ne(Q,{inclo:j,init:Q.init,ep:Q.ecco,inclp:Q.inclo,nodep:Q.nodeo,argpp:Q.argpo,mp:Q.mo,opsmode:Q.operationmode});Q.ecco=t.ep,Q.inclo=t.inclp,Q.nodeo=t.nodep,Q.argpo=t.argpp,Q.mo=t.mp,k=0,A=0,oe=0;let n=v({cosim:g,emsq:E,argpo:Q.argpo,s1:I,s2:L,s3:R,s4:ce,s5:z,sinim:y,ss1:V,ss2:H,ss3:U,ss4:W,ss5:G,sz1:K,sz3:q,sz11:J,sz13:le,sz21:Y,sz23:ue,sz31:de,sz33:X,t:Q.t,tc:fe,gsto:Q.gsto,mo:Q.mo,mdot:Q.mdot,no:Q.no,nodeo:Q.nodeo,nodedot:Q.nodedot,xpidot:_e,z1:ye,z3:be,z11:xe,z13:Se,z21:Ce,z23:we,z31:Te,z33:Ee,ecco:Q.ecco,eccsq:Me,em:T,argpm:k,inclm:j,mm:oe,nm:M,nodem:A,irez:Q.irez,atime:Q.atime,d2201:Q.d2201,d2211:Q.d2211,d3210:Q.d3210,d3222:Q.d3222,d4410:Q.d4410,d4422:Q.d4422,d5220:Q.d5220,d5232:Q.d5232,d5421:Q.d5421,d5433:Q.d5433,dedt:Q.dedt,didt:Q.didt,dmdt:Q.dmdt,dnodt:Q.dnodt,domdt:Q.domdt,del1:Q.del1,del2:Q.del2,del3:Q.del3,xfact:Q.xfact,xlamo:Q.xlamo,xli:Q.xli,xni:Q.xni});Q.irez=n.irez,Q.atime=n.atime,Q.d2201=n.d2201,Q.d2211=n.d2211,Q.d3210=n.d3210,Q.d3222=n.d3222,Q.d4410=n.d4410,Q.d4422=n.d4422,Q.d5220=n.d5220,Q.d5232=n.d5232,Q.d5421=n.d5421,Q.d5433=n.d5433,Q.dedt=n.dedt,Q.didt=n.didt,Q.dmdt=n.dmdt,Q.dnodt=n.dnodt,Q.domdt=n.domdt,Q.del1=n.del1,Q.del2=n.del2,Q.del3=n.del3,Q.xfact=n.xfact,Q.xlamo=n.xlamo,Q.xli=n.xli,Q.xni=n.xni}Q.isimp!==1&&(b=Q.cc1*Q.cc1,Q.d2=4*$*Z*b,pe=Q.d2*Z*Q.cc1/3,Q.d3=(17*$+B)*pe,Q.d4=.5*pe*$*Z*(221*$+31*B)*Q.cc1,Q.t3cof=Q.d2+2*b,Q.t4cof=.25*(3*Q.d3+Q.cc1*(12*Q.d2+10*b)),Q.t5cof=.2*(3*Q.d4+12*Q.cc1*Q.d3+6*Q.d2*Q.d2+15*b*(2*Q.d2+b)))}ae(Q,0),Q.init=`n`}function C(e,t=`i`){let n=e.NORAD_CAT_ID.toString(),r=new Date(e.EPOCH.endsWith(`Z`)?e.EPOCH:`${e.EPOCH}Z`),i=r.getUTCFullYear(),a=Number(i.toString().slice(-2)),o=(r.valueOf()-new Date(Date.UTC(i,0,1,0,0,0)).valueOf())/(86400*1e3)+1,c=Number(e.MEAN_MOTION_DOT),l=Number(e.MEAN_MOTION_DDOT);c/=ee*1440,l/=ee*1440*1440;let u=Number(e.BSTAR),d=Number(e.INCLINATION)*s,f=Number(e.RA_OF_ASC_NODE)*s,p=Number(e.ECCENTRICITY),m=Number(e.ARG_OF_PERICENTER)*s,h=Number(e.MEAN_ANOMALY)*s,ne=Number(e.MEAN_MOTION)/ee,{mon:_,day:v,hr:y,minute:b,sec:re}=te(i,o),ie=g(i,_,v,y,b,re),x={error:0,satnum:n,epochyr:a,epochdays:o,ndot:c,nddot:l,bstar:u,inclo:d,nodeo:f,ecco:p,argpo:m,mo:h,no:ne,jdsatepoch:ie};return S(x,{opsmode:t,satn:x.satnum,epoch:x.jdsatepoch-2433281.5,xbstar:x.bstar,xecco:x.ecco,xargpo:x.argpo,xinclo:x.inclo,xmo:x.mo,xno:x.no,xnodeo:x.nodeo}),x}3*Float64Array.BYTES_PER_ELEMENT;const w=Math.PI/180;Math.cos(i*w),Math.sin(i*w);function T(e){return new Date((e-2440587.5)*864e5).toISOString()}function E(e,t){let n=C({OBJECT_NAME:t??String(e.noradCatId),OBJECT_ID:String(e.noradCatId),EPOCH:T(e.epochJd),MEAN_MOTION:e.meanMotion,ECCENTRICITY:e.eccentricity,INCLINATION:e.inclination,RA_OF_ASC_NODE:e.raOfAscNode,ARG_OF_PERICENTER:e.argOfPericenter,MEAN_ANOMALY:e.meanAnomaly,EPHEMERIS_TYPE:0,CLASSIFICATION_TYPE:`U`,NORAD_CAT_ID:e.noradCatId,ELEMENT_SET_NO:e.elementSetNo,REV_AT_EPOCH:e.revAtEpoch,BSTAR:e.bstar,MEAN_MOTION_DOT:e.meanMotionDot,MEAN_MOTION_DDOT:e.meanMotionDdot});return n.error===x.None?n:(console.warn(`buildSatrec: SGP4 init failed for NORAD ${e.noradCatId} (error=${n.error})`),null)}const D=Math.PI/180,O=Math.cos(i*D),k=Math.sin(i*D),A=10/r;function j(e,t,n,r,i){return!isFinite(Math.fround(n))||!isFinite(Math.fround(r))||!isFinite(Math.fround(i))?!1:(e[t*3]=n,e[t*3+1]=r,e[t*3+2]=i,!0)}function oe(r,i,a,o,s,c,l,u,d,f=null,p=0){if(i<r.validityStart||i>r.validityEnd)return 0;let{count:m,kind:ee,equatorial:te,a:h,e:g,i:ne,om:_,w:v,ma:y,n:b,epoch:re,q:ie,tp:S,satrec:C,flags:w,visibleFromDays:T}=r,oe=p!==0&&r.applyFlagFilter,M=r.pickBase,N=d.length/3|0,se=i-2451545,P=0;for(let F=0;F<m&&!(P>=N);F++){let m=ee[F];if(m===0||T[F]>se||oe&&(w[F]&p)!==p)continue;if(m===3){let e=C[F];if(!e){if(e=E({noradCatId:r.satnum[F],epochJd:re[F],meanMotion:b[F]/360,eccentricity:g[F],inclination:ne[F],raOfAscNode:_[F],argOfPericenter:v[F],meanAnomaly:y[F],bstar:r.bstar[F],meanMotionDot:r.ndot[F],meanMotionDdot:r.nddot[F],elementSetNo:0,revAtEpoch:0}),!e){ee[F]=0;continue}C[F]=e}let t=(i-e.jdsatepoch)*1440,n=ae(e,t);if(!n||e.error!==x.None)continue;let p=n.position.x,m=n.position.y,te=n.position.z,h=p*A,ie=m*A,S=te*A,w=ie*O+S*k,T=-ie*k+S*O,D=h,oe=T,N=-w;if(!j(d,P,a+D-c,o+oe-l,s+N-u))continue;if(f){let e=M+F,t=P*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}P++;continue}let N,I,L=g[F],R=ne[F],ce=_[F],z=v[F];if(m===2){let e=n(ie[F],S[F],i);if(!e)continue;N=e.r*Math.cos(e.nu),I=e.r*Math.sin(e.nu)}else{let n=h[F];if(!isFinite(n)||!isFinite(L)||!isFinite(y[F])||!isFinite(b[F]))continue;let r=i-re[F],a=(y[F]+b[F]*r)*D,o,s;if(L<1||n>0){let t=Math.min(L,.9999999),r=e(a,t),i=Math.sqrt(1-t*t)*Math.sin(r)/(1-t*Math.cos(r)),c=(Math.cos(r)-t)/(1-t*Math.cos(r));o=Math.atan2(i,c),s=n*(1-t*Math.cos(r))}else{let e=t(a,L);if(!isFinite(e))continue;let r=L*Math.cosh(e)-1;if(Math.abs(r)<1e-15)continue;let i=Math.sqrt(L*L-1)*Math.sinh(e)/r,c=(L-Math.cosh(e))/r;o=Math.atan2(i,c),s=n*(1-L*Math.cosh(e))}N=s*Math.cos(o),I=s*Math.sin(o)}if(!isFinite(N)||!isFinite(I))continue;let B=Math.cos(z*D),V=Math.sin(z*D),H=Math.cos(R*D),U=Math.sin(R*D),W=Math.cos(ce*D),G=Math.sin(ce*D),K=(W*B-G*V*H)*N+(-W*V-G*B*H)*I,q=(G*B+W*V*H)*N+(-G*V+W*B*H)*I,J=V*U*N+B*U*I;if(te[F]){let e=q*O+J*k,t=-q*k+J*O;q=e,J=t}let le=K*10,Y=J*10,ue=-q*10;if(j(d,P,a+le-c,o+Y-l,s+ue-u)){if(f){let e=M+F,t=P*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}P++}}return P}const M=new Map;self.onmessage=e=>{let t=e.data;if(t.type===`ping`){self.postMessage({type:`pong`});return}if(t.type===`rewireDelta`){if(t.remove)for(let e of t.remove)M.delete(e);for(let e of t.set)M.set(e.id,e.cols);return}if(t.type===`tick`){let e=[],n=[],[r,i,a]=t.basis;for(let o of t.groups){let s=M.get(o.id);if(!s){e.push({id:o.id,count:0,buf:o.out.buffer,idbuf:o.outIds.buffer}),n.push(o.out.buffer,o.outIds.buffer);continue}let c=oe(s,t.jd,o.parent[0],o.parent[1],o.parent[2],r,i,a,o.out,o.outIds,t.requiredFlags??0);e.push({id:o.id,count:c,buf:o.out.buffer,idbuf:o.outIds.buffer}),n.push(o.out.buffer,o.outIds.buffer)}self.postMessage({type:`tickResult`,groups:e},n);return}};\n//# sourceMappingURL=worker-CK5Z1yOu.js.map",lP=typeof self<`u`&&self.Blob&&new Blob([`URL.revokeObjectURL(import.meta.url);`,cP],{type:`text/javascript;charset=utf-8`});function uP(e){let t;try{if(t=lP&&(self.URL||self.webkitURL).createObjectURL(lP),!t)throw``;let n=new Worker(t,{type:`module`,name:e?.name});return n.addEventListener(`error`,()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker(`data:text/javascript;charset=utf-8,`+encodeURIComponent(cP),{type:`module`,name:e?.name})}}var dP=class{workers=[];groups=new Map;onResult=null;size;pendingPing=null;generation=0;constructor(e=navigator.hardwareConcurrency??4){this.size=Math.max(2,Math.min(8,e)),this.spawn()}spawn(){for(let e=0;e<this.size;e++){let e=new uP;e.onmessage=e=>this.onMessage(e.data),this.workers.push(e)}}ping(e=800){if(this.workers.length===0)return Promise.resolve(!1);if(this.pendingPing)return this.pendingPing.promise;let t,n=new Promise(e=>t=e),r={need:this.workers.length,got:0,promise:n,resolve:e=>{this.pendingPing===r&&(this.pendingPing=null,t(e))}};this.pendingPing=r,setTimeout(()=>r.resolve(!1),e);for(let e of this.workers)e.postMessage({type:`ping`});return n}respawn(){this.pendingPing?.resolve(!1);for(let e of this.workers)e.terminate();this.workers=[],this.groups.clear(),this.generation++,this.spawn()}get poolGeneration(){return this.generation}setResultHandler(e){this.onResult=e}get workerCount(){return this.workers.length}get groupCount(){return this.groups.size}async rewireOne(e,t,n,r,i=!1,a=0){if(t.length===0){this.unwireOne(e);return}let o=await zg(t,n,i);o.pickBase=a,this.workers.length!==0&&this.wireCols(e,o,r,t.length)}rewireOneCols(e,t,n){if(this.workers.length!==0){if(t.count===0){this.unwireOne(e);return}this.wireCols(e,t,n,t.count)}}wireCols(e,t,n,r){let i=this.groups.get(e),a=i?.workerIdx??n%this.workers.length,o,s,c,l;if(i&&i.capacity===r)o=i.front,s=i.back,c=i.idFront,l=i.idBack;else if(o=new Float32Array(r*3),s=new Float32Array(r*3),c=new Uint8Array(r*4),l=new Uint8Array(r*4),i){let e=Math.min(i.front.length,o.length);o.set(i.front.subarray(0,e));let t=Math.min(i.idFront.length,c.length);c.set(i.idFront.subarray(0,t))}let u=!!i&&i.back===null;this.groups.set(e,{workerIdx:a,capacity:r,front:o,back:s,idFront:c,idBack:l,count:i?.count??r,pendingBasis:u?i.pendingBasis:null,pendingParent:u?i.pendingParent:null,pendingJd:u?i.pendingJd:null,frontBasis:i?.frontBasis??[0,0,0],frontParent:i?.frontParent??[0,0,0],frontJd:i?.frontJd??NaN}),this.workers[a].postMessage({type:`rewireDelta`,set:[{id:e,cols:t}]},Vg(t))}unwireOne(e){let t=this.groups.get(e);t&&(this.groups.delete(e),this.workers[t.workerIdx].postMessage({type:`rewireDelta`,set:[],remove:[e]}))}tick(e,t,n,r=0){let i=this.workers.map(()=>[]);for(let[r,a]of this.groups){if(!a.back||!a.idBack)continue;let o=n.get(r);o&&(i[a.workerIdx].push({id:r,parent:[o[0],o[1],o[2]],out:a.back,outIds:a.idBack}),a.back=null,a.idBack=null,a.pendingBasis=[t[0],t[1],t[2]],a.pendingParent=[o[0],o[1],o[2]],a.pendingJd=e)}for(let n=0;n<this.workers.length;n++){let a=i[n];if(a.length===0)continue;let o=a.flatMap(e=>[e.out.buffer,e.outIds.buffer]);this.workers[n].postMessage({type:`tick`,jd:e,basis:[t[0],t[1],t[2]],requiredFlags:r,groups:a},o)}}onMessage(e){if(e.type===`pong`){let e=this.pendingPing;e&&++e.got>=e.need&&e.resolve(!0);return}if(e.type===`tickResult`)for(let t of e.groups){let e=this.groups.get(t.id);if(!e)continue;let n=new Float32Array(t.buf),r=e.front;e.front=n,e.back=r;let i=new Uint8Array(t.idbuf),a=e.idFront;e.idFront=i,e.idBack=a,e.count=t.count;let o=e.pendingBasis??e.frontBasis,s=e.pendingParent??e.frontParent,c=e.pendingJd??e.frontJd;e.frontBasis=o,e.frontParent=s,e.frontJd=c,e.pendingBasis=null,e.pendingParent=null,e.pendingJd=null,this.onResult?.(t.id,n,t.count,o,s,c,i)}}destroy(){this.pendingPing?.resolve(!1);for(let e of this.workers)e.terminate();this.workers.length=0,this.groups.clear()}},fP=class{#e=1;#t=new Map;allocate(e,t){let n=this.#e;return this.#e+=t.length,this.#t.set(e,{base:n,keys:t}),n}release(e){this.#t.delete(e)}resolve(e){if(e===0)return null;for(let{base:t,keys:n}of this.#t.values())if(e>=t&&e<t+n.length)return gh(n[e-t]);return null}clear(){this.#t.clear(),this.#e=1}},pP=.01,mP=[`asteroid`,`spacecraft`],hP=.0002959122082855911,gP=.75,_P=Q(8*86400);function vP(e){let t=0,n=!1;for(let r=0;r<e.count;r++){if(e.kind[r]===0)continue;let i=e.a[r],a=e.e[r];if(e.kind[r]!==1||!(i>0)||!(a<1)||!isFinite(i)||!isFinite(a)){n=!0;continue}let o=Math.min(a,.9999999),s=Math.sqrt(hP/i*((1+o)/(1-o)));s>t&&(t=s)}return{maxSpeedScene:t*10,alwaysSolve:n}}function yP(e){return e<0?0:e>1?1:e}function bP(e,t){return t===`*`?e.startsWith(`small_bodies/`):e===t}function xP(e){return e===null?{tBright:0,tSize:0}:{tBright:yP((SP-e)/(SP-CP)),tSize:yP((wP-e)/(wP-TP))}}var SP=1e4,CP=500,wP=CP,TP=50,EP=4,DP=.5,OP=10,kP=1,AP=1,jP=3.5,MP=2.5,NP=2,PP=jP,FP=class{orbitPool=new dP;pickRegistry=new fP;disposed=!1;workerPoints={asteroid:new Map,spacecraft:new Map};moonPoints=new Map;pointBudget=1/0;drawFraction=1;pendingSceneAdds=[];basisPos=[0,0,0];parentAtUpdate=new Map;_parentsScratch=new Map;moonsByParentCache=null;lastPackedSize=new Map;groupKinematics=new Map;lastSolvedJd=new Map;earthSatEmphasis={size:EP,dim:DP,opacity:AP};emphasizedSmallBodyZone=null;smallBodyEmphasis={sizeMult:1,brightMult:1,opacity:AP};constructor(e,t,n,r,i,a,o){this.ctx=e,this.scene=t,this.bodyObjects=n,this.circleTexture=r,this.focus=i,this.mapLayer=a,this.onBasisRebuilt=o,this.orbitPool.setResultHandler(this.onPoolResult)}basis(){return this.basisPos}setPointBudget(e){this.pointBudget=e,this.applyPointBudget()}applyPointBudget(){let e=0;for(let t of mP)for(let n of this.workerPoints[t].values())n.visible&&(e+=n.userData.solvedCount??0);let t=e>this.pointBudget?this.pointBudget/e:1;if(t!==this.drawFraction){this.drawFraction=t;for(let e of mP)for(let n of this.workerPoints[e].values()){let e=n.userData.solvedCount;e!==void 0&&n.geometry.setDrawRange(0,Math.ceil(e*t))}}}setEarthSatEmphasis(e){this.earthSatEmphasis=this.computeEarthSatEmphasis(e);for(let[e,t]of this.workerPoints.spacecraft)x_(e)===`naif-399`&&this.applyEarthSatEmphasis(t)}computeEarthSatEmphasis(e){let{tBright:t,tSize:n}=xP(e);return{size:EP+(OP-EP)*n,dim:DP+(kP-DP)*t,opacity:AP+(jP-AP)*t}}applyEarthSatEmphasis(e){let t=e.material,{size:n,dim:r,opacity:i}=this.earthSatEmphasis;t.size=n,t.color.setRGB(r,r,r),t.opacity=i}setEmphasizedSmallBodyZone(e,t){let n=this.emphasizedSmallBodyZone;if(this.emphasizedSmallBodyZone=e,this.smallBodyEmphasis=this.computeSmallBodyEmphasis(e===null?null:t),n!==null&&n!==e)for(let[e,t]of this.workerPoints.asteroid)bP(x_(e),n)&&this.resetSmallBodyEmphasis(t);if(e!==null)for(let[t,n]of this.workerPoints.asteroid)bP(x_(t),e)&&this.applySmallBodyEmphasis(n)}computeSmallBodyEmphasis(e){let{tBright:t,tSize:n}=xP(e);return{sizeMult:1+(MP-1)*n,brightMult:1+(NP-1)*t,opacity:AP+(PP-AP)*t}}applySmallBodyEmphasis(e){let t=e.material;e.userData.smallBodyBaseSize===void 0&&(e.userData.smallBodyBaseSize=t.size,e.userData.smallBodyBaseColor=t.color.clone());let n=e.userData.smallBodyBaseSize,r=e.userData.smallBodyBaseColor,{sizeMult:i,brightMult:a,opacity:o}=this.smallBodyEmphasis;t.size=n*i,t.color.copy(r).multiplyScalar(a),t.opacity=o}resetSmallBodyEmphasis(e){if(e.userData.smallBodyBaseSize===void 0)return;let t=e.material;t.size=e.userData.smallBodyBaseSize,t.color.copy(e.userData.smallBodyBaseColor),t.opacity=AP,e.userData.smallBodyBaseSize=void 0,e.userData.smallBodyBaseColor=void 0}seedBasis(e){this.basisPos=[...e]}buildInitial(e){let t=wN(this.ctx,this.scene,this.circleTexture,this.basisPos,e,this.orbitPool.workerCount);this.workerPoints.asteroid=t.asteroidPoints,this.workerPoints.spacecraft=t.spacecraftPoints,this.moonPoints=t.moonPoints;for(let e of mP)for(let[t,n]of this.workerPoints[e]){let r=x_(t);n.userData.parentBodyId=this.cloudParentId(e,r),this.emphasiseNewCloud(e,r,n)}this.assignMapLayer()}assignMapLayer(){for(let e of mP)for(let t of this.workerPoints[e].values())t.layers.set(this.mapLayer);for(let e of this.moonPoints.values())e.layers.set(this.mapLayer)}cloudParentId(e,t){return e===`asteroid`?d_:t}emphasiseNewCloud(e,t,n){if(e===`spacecraft`){t===`naif-399`&&this.applyEarthSatEmphasis(n);return}let r=this.emphasizedSmallBodyZone;r!==null&&bP(t,r)&&this.applySmallBodyEmphasis(n)}rebuildRunning=!1;rebuildQueued=!1;rebuildMinor(){if(this.rebuildRunning){this.rebuildQueued=!0;return}this.rebuildRunning=!0,(async()=>{try{do this.rebuildQueued=!1,await this.rebuildMinorPass();while(this.rebuildQueued)}finally{this.rebuildRunning=!1}})()}recovering=null;recoverWorkersIfDead(e){return this.recovering??=this.runRecovery(e).finally(()=>this.recovering=null),this.recovering}async runRecovery(e){if(await this.orbitPool.ping(e))return!1;this.orbitPool.respawn();for(let e of this.ctx.bodies.asteroidBodiesByZone.keys())this.ctx.bodies.dirtyAsteroidZones.add(e);for(let e of this.ctx.bodies.spacecraftByParent.keys())this.ctx.bodies.dirtySpacecraftGroups.add(e);return this.lastPackedSize.clear(),this.rebuildMinor(),!0}async rebuildMinorPass(){if(this.disposed||this.ctx.bodies.dirtyAsteroidZones.size===0&&this.ctx.bodies.dirtySpacecraftGroups.size===0)return;let e=[this.basisPos[0],this.basisPos[1],this.basisPos[2]],t=this.orbitPool.workerCount,n=this.orbitPool.poolGeneration,r=[],i=[];for(let n of[...this.ctx.bodies.dirtyAsteroidZones]){let i=this.ctx.bodies.asteroidBodiesByZone.get(n);if(this.deferPackWhileStreaming(`asteroid:${n}`,i?.size??0))continue;this.ctx.bodies.dirtyAsteroidZones.delete(n),r.push(n);let a=vh(this.bodyObjects.keys()),{groups:o,baseWorker:s}=i?await i.buildWorkerGroups(n,t,a,!1):{groups:[],baseWorker:0};if(this.disposed)return;let c=i&&o.length>0?i.cloudColor():`#888888`;for(let r=0;r<t;r++){let i=`${n}#${r}`,a=`asteroid:${i}`,l=r<o.length?o[r]:null;if(!l||l.cols.count===0){this.unwireGroup(`asteroid`,i,a);continue}this.armGroupGate(a,vP(l.cols)),l.cols.pickBase=this.pickRegistry.allocate(a,l.keys),this.orbitPool.rewireOneCols(a,l.cols,(s+r)%t);let u=this.workerPoints.asteroid.get(i);if(u){this.resizeGeometryToCount(u.geometry,l.cols.count,null);continue}let d=nN(new Float32Array(l.cols.count*3),0,this.circleTexture,c,eN());this.adoptCloud(`asteroid`,i,a,d,e)}}for(let n of[...this.ctx.bodies.dirtySpacecraftGroups]){let r=this.ctx.bodies.spacecraftByParent.get(n);if(this.deferPackWhileStreaming(`spacecraft:${n}`,r?.size??0))continue;this.ctx.bodies.dirtySpacecraftGroups.delete(n),i.push(n);let{buckets:a,baseWorker:o}=await b_(n,Cv(this.ctx.layers,n,r?Array.from(r.values()):[]),t);if(this.disposed)return;let s=new Set(this.bodyObjects.keys());for(let r=0;r<t;r++){let i=`${n}#${r}`,c=`spacecraft:${i}`,l=r<a.length?a[r]:[];if(l.length===0){this.unwireGroup(`spacecraft`,i,c);continue}let u=this.pickRegistry.allocate(c,Float64Array.from(l,e=>_h(e.data.id)??dh));await this.orbitPool.rewireOne(c,l,s,(o+r)%t,!1,u),this.armGroupGate(c,{maxSpeedScene:_P,alwaysSolve:!1});let d=this.workerPoints.spacecraft.get(i);if(d){this.resizeGeometryIfNeeded(d.geometry,l);continue}let f=new Float32Array(l.length*3),p=new Float32Array(l.length*3);this.seedGeometryArray(f,l,p);let m=nN(f,l.length,this.circleTexture,`#ffffff`,void 0,p);this.adoptCloud(`spacecraft`,i,c,m,e)}}if(this.orbitPool.poolGeneration!==n){for(let e of r)this.ctx.bodies.dirtyAsteroidZones.add(e);for(let e of i)this.ctx.bodies.dirtySpacecraftGroups.add(e);this.lastPackedSize.clear(),this.rebuildQueued=!0}}unwireGroup(e,t,n){this.orbitPool.unwireOne(n),this.forgetGroupGate(n),this.pickRegistry.release(n);let r=this.workerPoints[e].get(t);r&&(this.scene.remove(r),this.workerPoints[e].delete(t))}armGroupGate(e,t){this.groupKinematics.set(e,t),this.lastSolvedJd.delete(e)}adoptCloud(e,t,n,r,i){let a=x_(t);r.userData.frontBasis=i,r.userData.groupId=n,r.userData.parentBodyId=this.cloudParentId(e,a),r.userData.parentVec=[0,0,0],this.emphasiseNewCloud(e,a,r),this.workerPoints[e].set(t,r),this.pendingSceneAdds.push(r)}deferPackWhileStreaming(e,t){if(!this.ctx.bodies.minorStreaming)return this.lastPackedSize.set(e,t),!1;let n=this.lastPackedSize.get(e);return n!==void 0&&t>n&&t<n*2?!0:(this.lastPackedSize.set(e,t),!1)}seedGeometryArray(e,t,n=null){let[r,i,a]=this.basisPos,o=Math.min(t.length,e.length/3),s=n?new X:null;for(let c=0;c<o;c++){let o=t[c],l=o.position;e[c*3]=l[0]-r,e[c*3+1]=l[1]-i,e[c*3+2]=l[2]-a,n&&s&&(s.set(m_(o.data)),n[c*3]=s.r,n[c*3+1]=s.g,n[c*3+2]=s.b)}}resizeGeometryIfNeeded(e,t){let n=t.length*3;if(e.getAttribute(`position`).array.length===n){e.setDrawRange(0,t.length);return}let r=!!e.getAttribute(`color`),i=new Float32Array(n),a=r?new Float32Array(n):null;this.seedGeometryArray(i,t,a),e.setAttribute(`position`,new Eo(i,3)),a&&e.setAttribute(`color`,new Eo(a,3)),e.setDrawRange(0,t.length)}resizeGeometryToCount(e,t,n){let r=t*3,i=e.getAttribute(`position`).array;if(n&&e.setAttribute(`color`,new Eo(n,3)),i.length===r)return;let a=new Float32Array(r);a.set(i.subarray(0,Math.min(i.length,r))),e.setAttribute(`position`,new Eo(a,3));let o=Math.min(e.drawRange.count,t);e.setDrawRange(0,Number.isFinite(o)?o:0)}onPoolResult=(e,t,n,r,i,a,o)=>{let[s,c]=e.split(`:`),l=this.workerPoints[s].get(c);if(!l)return;let u=l.geometry.getAttribute(`position`),d=u.array;if(d.length!==t.length)return;d.set(t),u.needsUpdate=!0,this.bindPickIds(l,o),l.userData.solvedCount=n,l.geometry.setDrawRange(0,Math.ceil(n*this.drawFraction)),this.lastSolvedJd.set(e,a),l.userData.frontBasis=[r[0],r[1],r[2]],this.parentAtUpdate.set(e,[i[0],i[1],i[2]]);let[f,p,m]=this.focus.focusTruePos,h=this.ctx.getBody(l.userData.parentBodyId)?.position,g=h?h[0]-i[0]:0,_=h?h[1]-i[1]:0,v=h?h[2]-i[2]:0;l.position.set(r[0]-f+g,r[1]-p+_,r[2]-m+v)};bindPickIds(e,t){let n=e.geometry.getAttribute(`pickColor`);n&&n.array.length===t.length?(n.array.set(t),n.needsUpdate=!0):e.geometry.setAttribute(`pickColor`,new Eo(t.slice(),4,!0))}reposition(){let[e,t,n]=this.focus.focusTruePos,r=this.basisPos;for(let i of mP)for(let a of this.workerPoints[i].values()){let i=a.userData.frontBasis??r,[o,s,c]=this.parentShift(a.userData.groupId,a.userData.parentBodyId);a.position.set(i[0]-e+o,i[1]-t+s,i[2]-n+c)}let[i,a,o]=r,s=i-e,c=a-t,l=o-n;for(let e of this.moonPoints.values())e.position.set(s,c,l)}parentShift(e,t){let n=this.parentAtUpdate.get(e),r=this.ctx.getBody(t)?.position;return!n||!r?[0,0,0]:[r[0]-n[0],r[1]-n[1],r[2]-n[2]]}maybeRebase(){let[e,t,n]=this.focus.focusTruePos,[r,i,a]=this.basisPos,o=e-r,s=t-i,c=n-a,l=o*o+s*s+c*c,u=pP*10;l>u*u&&this.rebuildBasis()}rebuildBasis(){this.basisPos=[...this.focus.focusTruePos],this.rebuildMoons(),this.onBasisRebuilt(),this.reposition()}updateForJd(e,t){this.writeMoons();let n=this._parentsScratch;n.clear();let r=this.ctx.getBody(`naif-10`)?.position??[0,0,0];for(let[i,a]of this.workerPoints.asteroid){if(!this.ctx.visibility.isAsteroidGroupVisible(x_(i)))continue;let o=a.userData.groupId;if(!this.shouldSolveGroup(o,r,e,t))continue;let s=a.userData.parentVec;s[0]=r[0],s[1]=r[1],s[2]=r[2],n.set(o,s)}for(let[r,i]of this.workerPoints.spacecraft){if(!this.ctx.visibility.isSpacecraftGroupVisible(x_(r)))continue;let a=i.userData.groupId,o=this.ctx.getBody(i.userData.parentBodyId)?.position;if(o&&!this.shouldSolveGroup(a,o,e,t))continue;let s=i.userData.parentVec;o?(s[0]=o[0],s[1]=o[1],s[2]=o[2]):(s[0]=0,s[1]=0,s[2]=0),n.set(a,s)}this.orbitPool.tick(e,this.basisPos,n,this.ctx.visibility.getRequiredFlags())}shouldSolveGroup(e,t,n,r){let i=this.groupKinematics.get(e);if(!i||i.alwaysSolve)return!0;let a=this.lastSolvedJd.get(e);if(a===void 0||!isFinite(a))return!0;let[o,s,c]=this.focus.focusTruePos,l=r.camPos[0]-(t[0]-o),u=r.camPos[1]-(t[1]-s),d=r.camPos[2]-(t[2]-c),f=Math.max(1e-6,Math.sqrt(l*l+u*u+d*d)),p=Math.abs(n-a);return i.maxSpeedScene*p/f*r.pxPerRad>=gP}forgetGroupGate(e){this.groupKinematics.delete(e),this.lastSolvedJd.delete(e)}moonsByParent(){let e=this.ctx.bodies.majorBodies.length;if(this.moonsByParentCache?.len===e)return this.moonsByParentCache.map;let t=new Map;for(let e of this.ctx.bodies.majorBodies)if(e.data.objectType===G.MOON){let n=t.get(e.data.parentId)??[];n.push(e),t.set(e.data.parentId,n)}return this.moonsByParentCache={len:e,map:t},t}writeMoons(){let[e,t,n]=this.basisPos;for(let[r,i]of this.moonsByParent()){let a=this.moonPoints.get(r);if(!a||!this.ctx.visibility.isMoonGroupVisible(r))continue;let o=a.geometry.getAttribute(`position`),s=o.array,c=Math.min(i.length,s.length/3);for(let r=0;r<c;r++){let a=i[r];if(this.bodyObjects.get(a.data.id)?.outOfRange){s[r*3]=s[r*3+1]=s[r*3+2]=NaN;continue}s[r*3]=a.position[0]-e,s[r*3+1]=a.position[1]-t,s[r*3+2]=a.position[2]-n}o.needsUpdate=!0}}rebuildMoons(){let e=this.basisPos;for(let[t,n]of this.moonsByParent()){let r=this.moonPoints.get(t);if(!r)continue;let i=new Float32Array(n.length*3);for(let t=0;t<n.length;t++)i[t*3]=n[t].position[0]-e[0],i[t*3+1]=n[t].position[1]-e[1],i[t*3+2]=n[t].position[2]-e[2];r.geometry.setAttribute(`position`,new ko(i,3))}}hasPendingSceneAdds(){return this.pendingSceneAdds.length>0}drainOnePendingSceneAdd(){if(this.pendingSceneAdds.length===0)return;let e=this.pendingSceneAdds.shift();e.layers.set(this.mapLayer),this.scene.add(e)}asteroids(){return this.workerPoints.asteroid}spacecraft(){return this.workerPoints.spacecraft}moons(){return this.moonPoints}dispose(){this.disposed=!0,this.orbitPool.destroy(),this.pickRegistry.clear();for(let e of mP)this.disposeClouds(this.workerPoints[e]);this.disposeClouds(this.moonPoints);for(let e of this.pendingSceneAdds)e.geometry.dispose(),e.material.dispose();this.pendingSceneAdds.length=0}disposeClouds(e){for(let t of e.values())this.scene.remove(t),t.geometry.dispose(),t.material.dispose();e.clear()}},IP=Math.PI/180,LP=2451545,RP=1.00000261,zP=.01671123,BP=100.46457166*IP,VP=35999.37244981/36525*IP,HP=102.93768193*IP,UP=.32327364/36525*IP;function WP(e){let t=e-LP,n=HP+UP*t,r=BP+VP*t-n,i=r+(2*zP-zP**3/4)*Math.sin(r)+1.25*zP*zP*Math.sin(2*r);return{lon:n+i,r:RP*(1-zP*zP)/(1+zP*Math.cos(i))}}function GP(e){let t=WP(e).lon;return(e,n)=>{let r=t-WP(e).lon,i=Math.cos(r),a=Math.sin(r),o=n[0],s=n[2];n[0]=o*i+s*a,n[2]=-o*a+s*i}}var KP=.01,qP=1/100,JP=1;function YP(e,t,n){if(!n)return 0;let r=1/0;for(let i=0;i<t;i++){let t=e[i*3]-n.camX,a=e[i*3+1]-n.camY,o=e[i*3+2]-n.camZ,s=t*t+a*a+o*o;s<r&&(r=s)}return Math.sqrt(r)*n.tolAngle}function XP(e,t,n,r,i,a,o,s,c){if(t!==e.lastVersion||e.lastOffX===void 0)return!1;let l=e.rewriteTol;if(c){let t=c.camX-e.lastCamX,n=c.camY-e.lastCamY,r=c.camZ-e.lastCamZ;l=Math.max(0,l-Math.sqrt(t*t+n*n+r*r)*c.tolAngle)}let u=(n-e.lastOffX)**2+(r-e.lastOffY)**2+(i-e.lastOffZ)**2,d=(a-e.lastHeadX)**2+(o-e.lastHeadY)**2+(s-e.lastHeadZ)**2;return u<=l*l&&d<=l*l}function ZP(e,t,n,r,i,a,o,s,c,l,u){e.lastVersion=t,e.lastOffX=n,e.lastOffY=r,e.lastOffZ=i,e.lastHeadX=a,e.lastHeadY=o,e.lastHeadZ=s,e.lastCamX=u?.camX??0,e.lastCamY=u?.camY??0,e.lastCamZ=u?.camZ??0,e.rewriteTol=YP(c,l,u)}function QP(e,t,n,r,i,a){let o=t.userData,s=o.useTrail,c=o.orbitCenter,l=e.trailAnchor??e.position,u=c.x-r[0],d=c.y-r[1],f=c.z-r[2],p=l[0]-c.x,m=l[1]-c.y,h=l[2]-c.z,g=e.lagrangeTrail?NaN:n.newestJd+n.count*1e-9;if(XP(o,g,u,d,f,p,m,h,a))return;let{posArr:_,trailArr:v,fullArr:y}=gN(t),b=e.lagrangeTrail?GP(i):null,x=vN(e,n,_,c.x,c.y,c.z,r,b??void 0);_N(t,_,v,y,x,!0,s),ZP(o,g,u,d,f,p,m,h,_,x,a)}function $P(e,t,n,r,i){let{posArr:a,trailArr:o,fullArr:s,capacity:c}=gN(e),l=Math.min(t.length,c);for(let e=0;e<l;e++)a[e*3]=t[e][0]+n,a[e*3+1]=t[e][1]+r,a[e*3+2]=t[e][2]+i;if(e.userData.lastOffX=void 0,e.userData.isFatLine){dN(e.geometry,a,o,s,l);return}e.geometry.getAttribute(`position`).needsUpdate=!0}function eF(e,t,n,r,i){let a=t.userData.trailBuffer;if(a){QP(e,t,a,n,r,i);return}let o=t.userData.sourceCurve;if(!o){if(!t.userData.curvePending||!e.orbitElements)return;o=cN(Gv(e.orbitElements,r),512).points,t.userData.sourceCurve=o,t.userData.curveJd=r,t.userData.curvePending=!1}let s=t.userData.isOpenCurve,c=t.userData.useTrail,l=t.userData.orbitCenter,u=l.x,d=l.y,f=l.z;if(e.data.satrec){let n=e.data.n/360,i=n>0?1/n/512:0,a=t.userData.curveJd;(o.length===0||a===void 0||Math.abs(r-a)>=i)&&(o=oN(e.data.satrec,r,n,512),t.userData.sourceCurve=o,t.userData.curveJd=r)}else if(e.orbitElements){if(e.rederiveElements){let n=t.userData.elementsJd??r,i=e.orbitElements.n,a=i>0?360/i:1/0;if(Math.abs(r-n)>Math.min(a*qP,JP)){let n=e.rederiveElements(r);n&&(Object.assign(e.orbitElements,n),o=cN(e.orbitElements,512).points,t.userData.sourceCurve=o,t.userData.curveJd=r,t.userData.elementsJd=r)}}let n=e.orbitElements.omDot??0,i=e.orbitElements.wDot??0,a=Math.max(Math.abs(n),Math.abs(i));if(a>0){let n=t.userData.curveJd??r;a*Math.abs(r-n)>KP&&(o=cN(Gv(e.orbitElements,r),512).points,t.userData.sourceCurve=o,t.userData.curveJd=r)}}let p=e.trailAnchor??e.position,m=t.userData,h=u-n[0],g=d-n[1],_=f-n[2],v=p[0]-u,y=p[1]-d,b=p[2]-f;if(XP(m,o,h,g,_,v,y,b,i))return;let x=$y(e,o,s,u,d,f);if(x.length<2)return;let{posArr:S,trailArr:C,fullArr:w,capacity:T}=gN(t),E=u-n[0],D=d-n[1],O=f-n[2],k=Math.min(x.length,T);for(let e=0;e<k;e++)S[e*3]=x[e][0]+E,S[e*3+1]=x[e][1]+D,S[e*3+2]=x[e][2]+O;_N(t,S,C,w,k,s,c),m.trailLocalPositions=x,ZP(m,o,h,g,_,v,y,b,S,k,i)}function tF(e,t,n){let r=e===$.CAPPED;return{groupVisible:e===$.CLOSE||e===$.FULL||r&&t,orbitVisible:e===$.FULL||e===$.CLOSE&&n,showLabel:e===$.FULL||r&&t,isClose:e===$.CLOSE}}function nF(e,t,n){return{groupVisible:e===$.CLOSE||e===$.FULL,orbitVisible:e===$.FULL&&t||e===$.CLOSE&&n,showLabel:e===$.FULL&&t,isClose:t&&e===$.CLOSE}}var rF=4/2,iF=(.1*10)**2,aF=new J,oF=[],sF=oF;function cF(e){return rk(oF,e,sk)}var lF={x:0,y:0,left:0,right:0,h:0},uF=new Vi,dF={ox:0,oy:0},fF=new J,pF=new J;function mF(e,t,n,r,a,o,s,c,l,u,d,f,p,m,h){let g=n.layers,_=!g.isVisible(`orbits`),v=g.isVisible(`nomenclature`),y=t.fov*Math.PI/180,b=f.domElement.clientWidth,x=f.domElement.clientHeight,S=x/(2*Math.tan(y/2)),C=[r[0]+t.position.x,r[1]+t.position.y,r[2]+t.position.z],w=r,T=t.matrixWorldInverse;for(let n of e.values()){if(n.cachedDist=L_(C,n.body.position),n.isCrashed||n.noPhysical){let e=n.noPhysical===`model`,t=sg(n.cachedDist)<(n.isCrashed||e?.1:1),r=null;if(t){let t=i().messages;r=n.isCrashed?t.body_note_crash_site():e?t.body_note_no_model():t.body_note_no_radius()}eD(n,`missing`,r)}let e=n.label;if(!e)continue;n.labelAnchorOffscreen=!1;let r=n.noPhysical?0:n.radiusScene;if(!r){e.position.set(0,0,0);continue}let[a,o,s]=n.body.position;p.set(a-w[0],o-w[1],s-w[2]).applyMatrix4(T);let c=p.x,l=p.y,u=p.z,d=u*u,f=r*r;if(d<=f){e.position.set(0,0,0),n.labelAnchorOffscreen=!0;continue}let m=r/n.cachedDist*S;if(m<1){e.position.set(0,0,0);continue}if(m>=16){let i=n.cachedDist,d=1/i,f=c*d,m=l*d,h=u*d,g=r*d,_=Math.sqrt(Math.max(1-g*g,0)),v=1-f*f,y=-f*m,b=-f*h,x=Math.hypot(v,y,b);x<1e-4&&(v=-m*f,y=1-m*m,b=-m*h,x=Math.hypot(v,y,b));let S=g/x,C=f*_+v*S,T=m*_+y*S,E=h*_+b*S;p.set(C*i-c,T*i-l,E*i-u).applyQuaternion(t.quaternion),e.position.copy(p),pF.set(a-w[0]+p.x,o-w[1]+p.y,s-w[2]+p.z).project(t),n.labelAnchorOffscreen=Math.abs(pF.x)>1||Math.abs(pF.y)>1;continue}if(n.semiAxesScene&&n.mesh)tP(c,l,u,QN(n.mesh.getWorldQuaternion(uF),T,n.semiAxesScene),S,dF),p.set(dF.ox,dF.oy,0).applyQuaternion(t.quaternion);else{let e=f/(d-f);p.set(e*c,e*l,0).applyQuaternion(t.quaternion)}e.position.copy(p)}let E=oF,D=b*.5,O=x*.5,k=0;for(let t of e.values()){let e=t.noPhysical?0:t.radiusScene;if(!e)continue;let n=t.cachedDist,[r,i,a]=t.body.position,o=t.model?.userData.occluderSpheres;if(t.model&&o?.length){let e=iO(t),s=t.model.position;for(let c of o){let o=c.r*e;if(fF.copy(c.center).applyQuaternion(t.model.quaternion).add(s).multiplyScalar(e),p.set(r-w[0]+fF.x,i-w[1]+fF.y,a-w[2]+fF.z).applyMatrix4(T),p.z>=o||p.lengthSq()<=o*o)continue;let l=p.z*p.z;(l<=o*o||o*S/Math.sqrt(l-o*o)>=16)&&$N(cF(k++),p.x,p.y,p.z,o,S,D,O,t.body.data.id,n)}continue}p.set(r-w[0],i-w[1],a-w[2]).applyMatrix4(T);let s=p.x,c=p.y,l=p.z;if(l>=e)continue;let u=l*l;(u<=e*e||e*S/Math.sqrt(u-e*e)>=16)&&(t.semiAxesScene&&t.mesh?eP(cF(k++),s,c,l,QN(t.mesh.getWorldQuaternion(uF),T,t.semiAxesScene),S,D,O,t.body.data.id,n):$N(cF(k++),s,c,l,e,S,D,O,t.body.data.id,n))}E.length=k;let A=n.visibility.focusedSystemId,j=!1,M=a?CM(n.getBody(a),e):void 0;for(let r of e.values()){let{body:i,group:s,trail:c}=r,l=r.cachedDist,u,d,f=i.data.id===a,p=A!==null&&i.data.id===A;if(r.mesh===null&&!gn(i.data.objectType)){let t=i.data.objectType;if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){let t=!0,r=f?void 0:N_(i.data.id);if(r){let a=e.get(r)?.body??n.getBody(r);a&&L_(i.position,a.position)/L_(C,a.position)*S<16&&(t=!1)}s.visible=t,c&&(c.visible=t),u=t,d=!1}else{let e=n.visibility.getPlanetVisibility(i,l)!==$.HIDE&&n.visibility.hasFullRendering(i);s.visible=e,c&&(c.visible=e),u=e,d=!1}}else{let e=i.data.objectType===G.MOON,t=e?n.visibility.getMoonVisibility(i):n.visibility.getPlanetVisibility(i,l),r=e?tF(t,o,f):nF(t,n.visibility.hasFullRendering(i),f||p);s.visible=r.groupVisible,c&&(c.visible=r.orbitVisible),u=r.showLabel,d=r.isClose}if(r.outOfRange&&(s.visible=!1,c&&(c.visible=!1),u=!1),r.starPoint){let e=r.radiusScene/l*S,t=e<rF;if(r.starPoint.visible=t,t){let t=r.starPoint.material,n=e/rF,i=Math.max(ej*n*n,3);t.uniforms.uIntensity.value=i}s.visible=!0,d=!t,u=!d}if(r.isMinor&&!f&&c&&!n.visibility.isPinned(i.data.id)&&(c.visible=!1),h&&c?.visible){let e=c.userData.orbitCenter;e&&e.distanceToSquared(aF.set(w[0],w[1],w[2]))>iF&&(c.visible=!1)}_&&c&&(c.visible=!1),s.matrixWorldAutoUpdate=s.visible;let{label:m}=r;if(!s.visible&&m&&m.parent===s?(s.remove(m),m.element.remove()):s.visible&&m&&m.parent!==s&&s.add(m),r.mesh&&r.radiusScene>0){let e=!f&&!p&&r.radiusScene/l*S<.5;e!==r.meshSubPixel&&(r.meshSubPixel=e,e?r.mesh.layers.disable(0):r.mesh.layers.enable(0))}fk(r,u,d,l,S,a)&&(j=!0);let g=r.radiusScene>0?r.radiusScene/l*S:0;GM(r,v&&i.data.id===M,g,t,b,x)}for(let[e,t]of c)t.visible=n.visibility.isAsteroidGroupVisible(x_(e));for(let[e,t]of l)t.visible=n.visibility.isSpacecraftGroupVisible(x_(e));for(let[e,t]of u)t.visible=n.visibility.isMoonGroupVisible(e);if(E.length>0)for(let n of e.values())n.label?.visible&&hk(n,t,w,b,x,lF)&&pk(lF.x,lF.y,n.cachedDist,n.body.data.id,E)&&(n.label.visible=!1);if((m||j||++d>=3)&&(d=0,Ok(e,b,x,t,a,n,s,E,r)),kk(e,b,x,t,r),M){let t=e.get(M);t&&YM(t)}for(let n of e.values()){let e=n.trail;if(!e?.visible)continue;let r=e.material;r.uniforms.uCenterOffset.value.set(-t.position.x,-t.position.y,-t.position.z);let i=n.body.data.id===a,o=s.has(n.body.data.id);r.uniforms.uAlphaMultiplier.value=o?2:i?1.75:1;let c=e.userData.isOpenCurve===!1;r.uniforms.uAlphaMin.value=i&&c?.15:0,r.uniforms.uShowFull.value=+!!i}return d}function hF(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function gF(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function _F(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function vF(e,t){let n=e.arcs[t].points.length,r=t=>e.endOrbits.find(e=>e.at===t);return{from:t===0?r(`departure`)?.trimFrom??0:0,to:t===e.arcs.length-1?r(`arrival`)?.trimTo??n:n}}function yF(e,t){let n=e.arcs[0],r=e.arcs[e.arcs.length-1];if(!n||!r)return null;let i=t=>e.endOrbits.find(e=>e.at===t)??null,a=i(`departure`),o=i(`arrival`),s=e=>e&&e.approach.length>1?e:null,c=s(a),l=s(o),u=e=>e&&e.pointJds&&e.points.length>1&&e.pointJds.length===e.points.length?{points:e.points,jds:e.pointJds}:null,d=u(a),f=o?.surfaceJd===void 0?u(o):null,p=Math.min(n.startJd,a?.surfaceJd??1/0),m=Math.max(r.endJd,o?.surfaceJd??l?.jds[l.jds.length-1]??-1/0),h=d?p-bF(d):p,g=f?m+bF(f):m;if(t<h||t>g)return null;if(a&&d&&t<(c?.jds[0]??n.startJd))return{r:xF(d,t),centerId:a.anchorId};if(c&&t<=c.jds[c.jds.length-1])return{r:SF(c.approach,c.jds,t),centerId:c.anchorId};if(o&&t>=(l?.jds[0]??r.endJd)){let e=o.surfaceJd??l?.jds[l.jds.length-1]??r.endJd;if(f&&(!l||t>e))return{r:xF(f,t),centerId:o.anchorId};if(l)return{r:SF(l.approach,l.jds,Math.min(t,e)),centerId:o.anchorId}}let _=e.arcs.findIndex(e=>t>=e.startJd&&t<=e.endJd),v=_>=0?_:e.arcs.length-1,{points:y,jds:b}=e.arcs[v];if(y.length===0)return null;if(y.length===1||b.length!==y.length)return{r:y[0],centerId:e.centerId};let{from:x,to:S}=vF(e,v);return{r:SF(y,b,t,x,S),centerId:e.centerId}}function bF(e){return e.jds[e.jds.length-1]-e.jds[0]}function xF(e,t){let n=bF(e),r=e.jds[0],i=n>0?r+((t-r)%n+n)%n:t;return SF(e.points,e.jds,i)}function SF(e,t,n,r=0,i=e.length){if(i-r<2)return e[r];let a=r+1;for(;a<i-1&&t[a]<n;)a++;let o=t[a]-t[a-1],s=o>0?Math.min(1,Math.max(0,(n-t[a-1])/o)):0;return hF(e[a-1],_F(gF(e[a],e[a-1]),s))}var CF=Math.PI/180,wF=Math.cos(ig*CF),TF=Math.sin(ig*CF);function EF(e,t,n,r){let i=Math.cos(e*CF),a=Math.sin(e*CF),o=Math.cos(t*CF),s=Math.sin(t*CF),c=Math.cos(n*CF),l=Math.sin(n*CF);return{m11:c*i-l*a*o,m12:-c*a-l*i*o,m21:l*i+c*a*o,m22:-l*a+c*i*o,m31:a*s,m32:i*s,equatorial:r}}function DF(e,t,n){let r=n.m11*e+n.m12*t,i=n.m21*e+n.m22*t,a=n.m31*e+n.m32*t;if(n.equatorial){let e=i*wF+a*TF,t=-i*TF+a*wF;i=e,a=t}return[r,i,a]}function OF(e){let t=10/rg;return[e[0]*t,e[2]*t,-e[1]*t]}function kF(e,t,n){let{a:r,e:i,ma:a,n:o,epoch:s,q:c,tp:l}=e,{om:u,w:d}=Gv(e,t),f=e.equatorial??!1;if(!isFinite(r)||r===0||!isFinite(o)||o<=0){if(c==null||l==null||!isFinite(c)||!isFinite(l)||c<=0)return null;let r=Cg(c,l,t);if(!r)return null;let i=n&&n>0?n:$_,a=r.r*rg,o=2*c*rg;return AF(a,r.nu,o,1,i,d,e.i,u,f)}if(!isFinite(i)||!isFinite(a))return null;let p=r*rg,m=o*CF/ev,h=n&&n>0?n:m*m*Math.abs(p)*Math.abs(p)*Math.abs(p);if(!isFinite(h)||h<=0)return null;let g=(a+o*(t-s))*CF,_,v;if(i<1||r>0){let e=Math.min(i,.9999999),t=bg(g,e),n=1-e*Math.cos(t);_=Math.atan2(Math.sqrt(1-e*e)*Math.sin(t),Math.cos(t)-e),v=p*n}else{let e=Sg(g,i);if(!isFinite(e))return null;let t=i*Math.cosh(e)-1;if(Math.abs(t)<1e-15)return null;_=Math.atan2(Math.sqrt(i*i-1)*Math.sinh(e)/t,(i-Math.cosh(e))/t),v=p*(1-i*Math.cosh(e))}if(!isFinite(v)||v<=0)return null;let y=p*(1-i*i);return!isFinite(y)||y<=0?null:AF(v,_,y,i,h,d,e.i,u,f)}function AF(e,t,n,r,i,a,o,s,c){let l=Math.cos(t),u=Math.sin(t),d=Math.sqrt(i/n),f=EF(a,o,s,c),p=DF(e*l,e*u,f),m=DF(-d*u,d*(r+l),f);return!isFinite(p[0]+p[1]+p[2])||!isFinite(m[0]+m[1]+m[2])?null:{r:p,v:m,mu:i}}var jF={cruise:`#7fdbff`,boost:`#ffb454`,brake:`#ff8c69`,spiral:`#c9a0ff`,"spiral-out":`#9b7fd4`,"spiral-in":`#9b7fd4`};jF.cruise,jF.boost,jF.brake,jF.spiral,jF[`spiral-out`],jF[`spiral-in`];var MF={notice:`#8ab4f8`,caution:`#f2b23e`,severe:`#ff6b5a`},NF=3,PF=1,FF=2,IF=.6,LF=1.5,RF=.3,zF=1.5,BF=.85,VF=60,HF=.018,UF=.026,WF=`#ffffff`,GF=4,KF=1.5,qF=9,JF=1,YF={notice:GF-3,caution:GF-2,severe:GF-1},XF=[`notice`,`caution`,`severe`],ZF=.03,QF=.2;function $F(e){let t=document.createElement(`canvas`);t.width=t.height=64;let n=t.getContext(`2d`);return n.beginPath(),n.arc(64/2,64/2,64/2-10,0,Math.PI*2),n.fillStyle=e,n.fill(),n.lineWidth=6,n.strokeStyle=`rgba(0,0,0,0.65)`,n.stroke(),new Mc(t)}function eI(e){let t=document.createElement(`canvas`);t.width=t.height=64;let n=t.getContext(`2d`);return n.beginPath(),n.moveTo(64/2,8),n.lineTo(56,56),n.lineTo(8,56),n.closePath(),n.fillStyle=e,n.fill(),n.lineWidth=6,n.lineJoin=`round`,n.strokeStyle=`rgba(0,0,0,0.65)`,n.stroke(),new Mc(t)}function tI(e,t,n,r){let i=[];for(let a=r.from;a<r.to;a++)e.jds[a]>=t&&e.jds[a]<=n&&i.push(e.points[a]);return i}function nI(e,t){let n=new ss(new qo({map:e,transparent:!0,sizeAttenuation:!1,depthTest:!1}));return n.scale.setScalar(t),n.renderOrder=GF,n}function rI(e,t,n,r){let{canvas:i,color:a,onSelect:o,onHover:s}=r,c=document.createElement(o?`button`:`div`);c instanceof HTMLButtonElement&&(c.type=`button`),c.className=e===`step`?`scene-path-label scene-path-label--step`:`scene-path-label${o?``:` scene-path-label--static`}`,c.setAttribute(`aria-label`,`${t} \u2014 ${n}`);let l=document.createElement(`span`);l.className=`scene-path-label__halo`,a&&(l.style.border=`2px solid ${a}`,l.style.background=`${a}22`);let u=document.createElement(`span`);u.className=`scene-path-label__text`;let d=document.createElement(`span`);d.className=`scene-path-label__name`,d.dir=`auto`,d.textContent=t;let f=document.createElement(`span`);f.className=`scene-path-label__when`,f.dir=`auto`,f.textContent=n,u.append(d,f),c.append(l,u),o&&(Rk(c,i),SM(c,o)),s&&(c.addEventListener(`mouseenter`,()=>s(!0)),c.addEventListener(`mouseleave`,()=>s(!1)));let p=new tk(c);return p.center.set(0,.5),p}var iI=class{group=new Ra;arcs=[];rings=[];markers=[];labels=[];drawnSteps=[];craft=null;path=null;center=null;layer=null;offset=new J;projected=new J;rects=[];order=[];hovered=null;tint=new X;constructor(e,t){this.scene=e,this.canvas=t,this.group.frustumCulled=!1,this.scene.add(this.group)}get centerId(){return this.center}get isEmpty(){return this.center===null}get plan(){return this.path}setLayer(e){this.layer=e,this.group.traverse(t=>t.layers.set(e))}set(e,t=[],n=[],r=[]){this.clear(),this.path=e?.path??null,this.center=e?.path.centerId??t[0]?.path.centerId??null;let i=e!==null;for(let e of t)this.addArcs(e.path,i?LF:FF,i?RF:IF,e.id),this.addEndLabels(e,i);e&&(this.addPlan(e,r),this.addHazards(e.path,n)),this.applyHover(),this.layer!==null&&this.setLayer(this.layer)}addHazards(e,t){let n=[...t].sort((e,t)=>XF.indexOf(e.severity)-XF.indexOf(t.severity));for(let t of n){let n=MF[t.severity];for(let n of t.bands)e.arcs.forEach((t,r)=>{this.addLine(tI(t,n.startJd,n.endJd,vF(e,r)),MF[n.severity],qF,JF,null,{renderOrder:YF[n.severity]})});if(this.mergeIntoStep(t,n))continue;let r=yF(e,t.startJd);if(!r)continue;let i=OF(r.r),a=r.centerId===e.centerId?null:r.centerId,o=nI(eI(n),ZF);this.group.add(o),this.markers.push({sprite:o,local:i,anchorId:a});let s=document.createElement(`div`);s.className=`scene-hazard-label`,s.style.color=n,s.textContent=t.label;let c=new tk(s);c.center.set(0,.5),this.group.add(c),this.labels.push({object:c,local:i,anchorId:a,owner:null,width:0,height:0,dimmed:!1,faint:!0})}}mergeIntoStep(e,t){let n=e.kind===`aeroassist`?`aero-pass`:e.kind===`belt-crossing`?`assist`:null;if(!n)return!1;let r=null,i=1/0;for(let{step:t,label:a}of this.drawnSteps){if(t.kind!==n||e.bodyId&&t.bodyId!==e.bodyId)continue;let o=Math.abs(t.jd-e.peakJd);o<i&&(i=o,r=a)}if(!r)return!1;let a=r.object.element,o=document.createElement(`span`);return o.className=`scene-path-label__hazard`,o.style.color=t,o.dir=`auto`,o.textContent=e.label,a.querySelector(`.scene-path-label__text`)?.append(o),a.setAttribute(`aria-label`,`${a.getAttribute(`aria-label`)} — ${e.label}`),!0}addPlan(e,t){let n=e.path;this.addArcs(n,NF,PF,null,!0),this.addEndOrbits(n),this.addSteps(n,t);for(let e of this.markers)this.group.add(e.sprite);this.craft={sprite:nI($F(WF),UF),local:[0,0,0],anchorId:null},this.craft.sprite.visible=!1,this.group.add(this.craft.sprite)}addSteps(e,t){for(let n of t){let t=yF(e,n.jd);if(!t)continue;let r=OF(t.r),i=t.centerId===e.centerId?null:t.centerId,a=nI($F(WF),HF);this.markers.push({sprite:a,local:r,anchorId:i});let o=rI(`step`,n.name,n.when,{canvas:this.canvas,onSelect:n.onPick});this.group.add(o),this.labels.push({object:o,local:r,anchorId:i,owner:null,width:0,height:0,dimmed:!1,faint:!1,step:!0,sprite:a}),this.drawnSteps.push({step:n,label:this.labels[this.labels.length-1]})}}addEndLabels(e,t=!1){let{path:n,onSelect:r}=e,i=n.arcs[0],a=n.arcs[n.arcs.length-1],o=n.stops.find(e=>e.kind===`departure`),s=[{local:OF(n.meeting.r),end:e.arrival,color:jF[a?.kind??`cruise`]}];o&&s.push({local:OF(o.r),end:e.departure,color:jF[i?.kind??`cruise`]});for(let{local:n,end:i,color:a}of s){if(!i.name)continue;let o=rI(`end`,i.name,i.when,{canvas:this.canvas,color:a,onSelect:r,onHover:e.onHover});t&&o.element.classList.add(`scene-path-label--faint`),this.group.add(o),this.labels.push({object:o,local:n,anchorId:null,owner:r?e.id:null,width:0,height:0,dimmed:!1,faint:t})}}setHovered(e){this.hovered!==e&&(this.hovered=e,this.applyHover())}applyHover(){for(let e of this.arcs){if(e.owner===null)continue;let t=e.owner===this.hovered,n=e.line.material;n.uniforms.uColor.value.set(e.color).multiplyScalar(t?PF:e.brightness),n.uniforms.uLineWidth.value=t?NF:e.width}for(let e of this.labels)e.owner!==null&&e.object.element.classList.toggle(`scene-path-label--lit`,e.owner===this.hovered)}addArcs(e,t,n,r=null,i=!1){let a=i&&e.frame===`planetary`,o=t=>a&&e.endOrbits.some(e=>e.at===t&&e.approach.length>1);e.arcs.forEach((a,s)=>{let{from:c,to:l}=i?vF(e,s):{from:0,to:a.points.length};this.addLine(a.points.slice(c,l),jF[a.kind],t,n,r,{fadeIn:s===0&&o(`departure`),fadeOut:s===e.arcs.length-1&&o(`arrival`)})})}addEndOrbits(e){for(let t of e.endOrbits){let n=this.anchorOf(e,t),r=(t.ground??[]).filter(e=>e.to>e.from);if(r.length>0){let e=0;for(let i of r)i.from>e&&this.addLine(t.approach.slice(Math.max(0,e-1),i.from+1),jF.cruise,NF,PF,null,{anchorId:n}),this.addLine(t.approach.slice(i.from,i.to),jF.cruise,NF,PF,null,{anchorId:n,renderOrder:KF}),e=i.to;e<t.approach.length&&this.addLine(t.approach.slice(Math.max(0,e-1)),jF.cruise,NF,PF,null,{anchorId:n})}else if(t.turn){let{from:e,to:r}=t.turn,i=t.approach.slice(0,e+1),a=t.approach.slice(r-1);for(let e of[i,a])e.length<2||this.addLine(e,jF.cruise,NF,PF,null,{anchorId:n});this.addLine(t.approach.slice(e>0?e-1:0,r),jF.cruise,zF,BF,null,{anchorId:n})}else this.addLine(t.approach,jF.cruise,NF,PF,null,{anchorId:n});let i=this.addLine(t.points,jF.cruise,zF,BF,null,{anchorId:n});if(!i)continue;let a=n===null?OF(t.center):[0,0,0];i.line.visible=!1,this.rings.push({arc:i,local:a,radius:Q(t.radiusKm),world:new J})}}anchorOf(e,t){return t.anchorId===e.centerId?null:t.anchorId}addLine(e,t,n,r,i,a={}){let o=e.length;if(o<2)return null;let s=new Float64Array(o*3);for(let t=0;t<o;t++){let[n,r,i]=OF(e[t]);s[t*3]=n,s[t*3+1]=r,s[t*3+2]=i}let c=new Float32Array(o*3),l=new Float32Array(o).fill(1),u=Math.max(1,Math.round(o*QF));for(let e=0;e<u;e++){let t=(e+1)/(u+1);a.fadeIn&&(l[e]=t),a.fadeOut&&(l[o-1-e]=t)}let d=hN(o,c,l,l,o,t,n,r);d.frustumCulled=!1,d.renderOrder=a.renderOrder??GF,this.group.add(d);let f={line:d,owner:i,anchorId:a.anchorId??null,color:t,brightness:r,width:n,local:s,positions:c,alphas:l,count:o};return this.arcs.push(f),f}setClock(e){let t=this.craft;if(!t||!this.path)return;let n=yF(this.path,e);t.sprite.visible=n!==null,n&&(t.local=OF(n.r),t.anchorId=n.centerId===this.path.centerId?null:n.centerId)}reposition(e,t,n){if(this.center===null)return;let r=e[0]-t[0],i=e[1]-t[1],a=e[2]-t[2],o=new Map,s=e=>{if(e===null)return[r,i,a];let s=o.get(e);if(s)return s;let c=n(e),l=c?[c[0]-t[0],c[1]-t[1],c[2]-t[2]]:[r,i,a];return o.set(e,l),l};for(let e of this.arcs){let[t,n,r]=s(e.anchorId);for(let i=0;i<e.count;i++)e.positions[i*3]=e.local[i*3]+t,e.positions[i*3+1]=e.local[i*3+1]+n,e.positions[i*3+2]=e.local[i*3+2]+r;dN(e.line.geometry,e.positions,e.alphas,e.alphas,e.count)}for(let e of this.markers){let[t,n,r]=s(e.anchorId);e.sprite.position.set(e.local[0]+t,e.local[1]+n,e.local[2]+r)}for(let e of this.labels){let[t,n,r]=s(e.anchorId);e.object.position.set(e.local[0]+t,e.local[1]+n,e.local[2]+r)}if(this.craft){let{sprite:e,local:t,anchorId:n}=this.craft,[r,i,a]=s(n);e.position.set(t[0]+r,t[1]+i,t[2]+a)}for(let e of this.rings){let[t,n,r]=s(e.arc.anchorId);e.world.set(e.local[0]+t,e.local[1]+n,e.local[2]+r)}}updateCameraOffset(e){if(this.arcs.length!==0){this.offset.set(-e.x,-e.y,-e.z);for(let e of this.arcs)e.line.material.uniforms.uCenterOffset.value.copy(this.offset);for(let t of this.rings){let n=t.world.distanceTo(e);t.arc.line.visible=n<t.radius*VF}}}setVisible(e){this.group.visible=e}reserveLabelSpace(e,t,n){if(!this.group.visible||this.labels.length===0){Ek(this.rects,0);return}this.order.length=0;for(let r of this.labels){if(r.faint)continue;let i=r.object.element;if(!r.width&&!r.dimmed&&(r.width=i.offsetWidth,r.height=i.offsetHeight),!r.width||(this.projected.copy(r.object.position).project(e),!iT(this.projected.z)))continue;let a=(this.projected.x*.5+.5)*t,o=(-this.projected.y*.5+.5)*n,s=r.object.position.distanceTo(e.position);if(r.step){let e=pk(a,o,s,``,sF);if(this.setStepVisible(r,!e),e)continue}this.order.push({label:r,left:a-16,y:o,distance:s})}this.order.sort((e,t)=>e.label.step===t.label.step?e.distance-t.distance:e.label.step?1:-1);let r=0;for(let{label:e,left:t,y:n}of this.order){let i=t+16+e.width,a=!1;for(let o=0;o<r;o++){let r=this.rects[o];if(t<r.right&&i>r.left&&Math.abs(n-r.y)<(e.height+r.h)/2){a=!0;break}}if(this.setLabelDimmed(e,a),a)continue;let o=this.rects[r];o||(o={left:0,right:0,y:0,h:0},this.rects[r]=o),o.left=t,o.right=i,o.y=n,o.h=e.height,r++}Ek(this.rects,r)}setStepVisible(e,t){e.object.visible=t,e.sprite&&(e.sprite.visible=t)}setLabelDimmed(e,t){e.dimmed!==t&&(e.dimmed=t,e.object.element.classList.toggle(`scene-path-label--dim`,t))}clear(){for(let e of this.arcs)this.group.remove(e.line),e.line.geometry.dispose(),e.line.material.dispose();for(let e of[...this.markers,...this.craft?[this.craft]:[]]){this.group.remove(e.sprite);let t=e.sprite.material;t.map?.dispose(),t.dispose()}for(let e of this.labels)this.group.remove(e.object),e.object.element.remove();this.arcs=[],this.rings=[],this.markers=[],this.labels=[],this.drawnSteps=[],this.craft=null,this.path=null,this.center=null}dispose(){this.clear(),this.scene.remove(this.group)}},aI=2,oI=1,sI=4,cI=200,lI=class{group=new Ra;slots=[];shown=0;layer=null;constructor(e){this.group.frustumCulled=!1,e.add(this.group)}get isEmpty(){return this.shown===0}set(e){let t=0;for(let n of e){if(n.pointsKm.length<2)continue;let e=this.slot(t++);e.bodyId=n.bodyId,e.count=Math.min(n.pointsKm.length,cI);for(let t=0;t<e.count;t++){let[r,i,a]=OF(n.pointsKm[t]);e.local[t*3]=r,e.local[t*3+1]=i,e.local[t*3+2]=a}}this.shown=t;for(let e=t;e<this.slots.length;e++)this.slots[e].line.visible=!1;this.group.visible=t>0}slot(e){for(;this.slots.length<=e;){let e=new Float32Array(cI*3),t=new Float32Array(cI).fill(1),n=hN(cI,e,t,t,0,jF.cruise,aI,oI);n.frustumCulled=!1,n.renderOrder=sI,this.layer!==null&&n.layers.set(this.layer),this.group.add(n),this.slots.push({line:n,bodyId:``,local:new Float64Array(cI*3),positions:e,alphas:t,count:0})}return this.slots[e]}setLayer(e){this.layer=e,this.group.traverse(t=>t.layers.set(e))}reposition(e,t){for(let n=0;n<this.shown;n++){let r=this.slots[n],i=e(r.bodyId);if(r.line.visible=i!==null,!i)continue;let a=i[0]-t[0],o=i[1]-t[1],s=i[2]-t[2];for(let e=0;e<r.count;e++)r.positions[e*3]=r.local[e*3]+a,r.positions[e*3+1]=r.local[e*3+1]+o,r.positions[e*3+2]=r.local[e*3+2]+s;dN(r.line.geometry,r.positions,r.alphas,r.alphas,r.count)}}updateCameraOffset(e){for(let t of this.slots)t.line.material.uniforms.uCenterOffset.value.set(-e.x,-e.y,-e.z)}},uI=30034e-10,dI=.45,fI=1.6,pI=.85,mI=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],hI=e=>Math.hypot(e[0],e[1],e[2]);function gI(e,t,n=uI){let r=hI(t);if(!(r>0))return null;let i=r*Math.cbrt(n/3),a=mI(e,t)/r,o=hI(e);if(Math.sqrt(Math.max(0,o*o-a*a))>pI*i)return null;let s=a/i;return s>=dI&&s<=fI?`EL1`:s<=-dI&&s>=-fI?`EL2`:null}function _I(){return{count:0,earliestStart:1/0,latestEnd:-1/0}}var vI=class{focused=!1;satSide=null;satJd=NaN;majSide=null;majJd=NaN;constructor(e){this.notices=e}update(e){let{jd:t,majorBodies:n,satellites:r}=e,i=null,a=NaN;n.count>0&&(Number.isFinite(n.latestEnd)&&t>n.latestEnd?(i=`after`,a=n.latestEnd):Number.isFinite(n.earliestStart)&&t<n.earliestStart?(i=`before`,a=n.earliestStart):i=`outside`);let o=r.kind===`covered`?null:r.kind,s=r.kind===`after`?jg(r.lastMs):NaN,c=e.focusedOutOfRange;if(!(c===this.focused&&o===this.satSide&&Object.is(s,this.satJd)&&i===this.majSide&&Object.is(a,this.majJd))){if(Object.assign(this,{focused:c,satSide:o,satJd:s,majSide:i,majJd:a}),!c&&o===null&&i===null){this.notices.dismiss(`out-of-range`);return}this.notices.notify({topic:`out-of-range`,focusedOutOfRange:c,satellites:o===`after`?{side:`after`,jd:s}:o===`gap`?{side:`gap`}:null,majorBodies:i===`after`||i===`before`?{side:i,jd:a}:i===`outside`?{side:`outside`}:null})}}},yI=new Map,bI=new J;function xI(e,t,n,r,i,a,o){let s=Ty(n,r,Cy(t));if(!s)return null;let c=`naif-${n.bodyNaifId}`,l=a.bodies.bodiesById.get(c);if(!l||!l.orientation)return null;let u=i.get(c);if(!u)return null;let d=l.data.radiusKm;if(!Number.isFinite(d)||d<=0)return null;let f=Math.PI/180,p=s.latDeg*f,m=s.lngDeg*f,h=kw(o.get(c),c,d,p,m);h&&yI.set(e.id,h);let g=h??yI.get(e.id),_,v,y;if(g)[_,v,y]=g.pointKm;else{let e=Math.cos(p);_=d*e*Math.cos(m),v=d*Math.sin(p),y=-d*e*Math.sin(m)}let b=pC(l.orientation,r,l.nutPrec),x=new J(_,v,y).applyQuaternion(b),S=g?bI.set(g.normal[0],g.normal[1],g.normal[2]).applyQuaternion(b):null;return e.parentId=c,{x:u[0]+Q(x.x),y:u[1]+Q(x.y),z:u[2]+Q(x.z),parentPos:u,up:S}}var SI=[0,0,0],CI=new Vi,wI=4,TI=0,EI=new Map;function DI(e){return e.primary.target===`velocity`||e.secondary?.target===`velocity`}function OI(e,t,n){let r=EI.get(e),i=r?.dir??null;if(r&&t!==r.jd){let e=Math.sign(t-r.jd),a=(n[0]-r.pos[0])*e,o=(n[1]-r.pos[1])*e,s=(n[2]-r.pos[2])*e,c=Math.hypot(a,o,s);c>1e-12&&(i=[a/c,o/c,s/c])}return EI.set(e,{jd:t,pos:[n[0],n[1],n[2]],dir:i}),i??void 0}function kI(e){let{jd:t,ctx:n,bodyObjects:r,focus:a,focusedBody:o,positionMap:s,diagnostics:c,trailView:l,frame:u,outOfRange:d}=e;n.chebStore?.ensure(t),n.probeStore?.ensure(t);let f=n.visibility.activeSystemId,p=f?e=>n.bodies.isInSystem(`naif-${e}`,f):void 0,m={jd:t,satellites:{kind:`covered`},majorBodies:_I(),focusedOutOfRange:!1},h=o?.data.id,g=gx(n.probeStore?.ridesAt(t)??[],h,e=>n.getBody(e)?.data.name),_=[];if(o){let e=new Set([o.data.id]),t=n.getBody(o.data.parentId);for(;t&&!e.has(t.data.id);)e.add(t.data.id),_.push({id:t.data.id,oldPos:[t.position[0],t.position[1],t.position[2]],bo:r.get(t.data.id)}),t=n.getBody(t.data.parentId)}s.clear(),s.set(`naif-0`,[0,0,0]);for(let e of n.bodies.bodiesById.values())s.set(e.data.id,e.position);for(let e of r.values())n.bodies.bodiesById.has(e.body.data.id)||s.set(e.body.data.id,e.body.position);let v=new Set,y=e=>{if(v.has(e))return;let t=n.bodies.bodiesById.get(e)??r.get(e)?.body;t&&C(t)},b=performance.now(),x=e=>{let t=n.bodies.hostRead.get(e);return t===void 0?!1:b-t<2e3?!0:(n.bodies.hostRead.delete(e),!1)},S=(e,r)=>{let i=n.bodies.elementRow(e),a=i&&s.get(i.parentId);if(!a)return null;let o=i.q==null?qv(i,t):Yv(i,t);return o?[a[0]-r[0]+o[0],a[1]-r[1]+o[1],a[2]-r[2]+o[2]]:null},C=e=>{if(v.has(e.data.id))return;v.add(e.data.id);let a=e.data,o=r.get(a.id);if(o&&u!==void 0&&a.id!==h&&!x(a.id)&&!o.group.visible&&!o.trail?.visible&&(a.orbitalSource===W.SPICE_PROBE||!gn(a.objectType))&&(o.staggerSlot??=TI++%wI,u%wI!==o.staggerSlot))return;let l=(n=!1)=>{o&&(o.outOfRange=!0),e.positionUnknown=!0,e.placedJd=t,!n&&a.id===h&&(m.focusedOutOfRange=!0)};if(a.unplaceable){l(!0);return}let d=n.chebStore?.has(a.id)??!1,f=a.orbitalSource===W.SPICE_PROBE;if(f){if(g.hidden.has(a.id)){l(!0);return}if(o){let e=g.credits.get(a.id);eD(o,`carrier`,e?i().messages.carried_by_scene_label({carrier:e}):null)}}if(a.visibleFromDays!==void 0&&t-2451545<a.visibleFromDays){l();return}let _;if(f)_=s.get(a.parentId)??[0,0,0];else{let e=s.get(a.parentId);if(!e){l(),c.warnOnce(`missing-parent`,a.id,()=>`computePosition[${a.id}]: parent ${a.parentId} not in positionMap — hiding`);return}_=e,c.clear(`missing-parent`,a.id)}let b=a.q!=null;if(!d&&!f&&(t<a.validityStart||t>a.validityEnd)){l(!a.satrec);return}let C,w,T;if(d){let r=n.chebStore.positionScene(a.id,t)??S(e,_);if(!r){l(!0);let e=n.chebStore.zoneCoverage(a.id);e&&(t<e.start||t>e.end)&&(m.majorBodies.count++,e.start<m.majorBodies.earliestStart&&(m.majorBodies.earliestStart=e.start),e.end>m.majorBodies.latestEnd&&(m.majorBodies.latestEnd=e.end),a.id===h&&(m.focusedOutOfRange=!0)),c.warnOnce(`cheb-null`,a.id,()=>{let n=e?t>=e.start&&t<=e.end:void 0,r=e?`[${e.start.toFixed(1)},${e.end.toFixed(1)}]`:`unknown`;return`chebStore.positionScene[${a.id}] returned null at jd=${t.toFixed(3)} (coverage=${r}, insideCoverage=${n}) — children of this body will read stale positionMap entry (pre-seeded) instead of falling to SSB`});return}C=_[0]+r[0],w=_[1]+r[1],T=_[2]+r[2]}else if(f){let i=n.probeStore?.probeWithCenter(a.id,t,p)??null;if(!i){l(),c.warnOnce(`probe-unavailable`,a.id,()=>{let e=n.probeStore?`no zone has both a loaded chunk and a sub-chunk covering this jd`:`no ProbeStore`;return`probe ${a.id} (${a.name??`unnamed`}): hidden — ${e}`});return}let u=i.probe.landed;if(u&&wy(i.probe,t)){let d=a.parentId;y(`naif-${u.bodyNaifId}`);let f=xI(a,i.probe,u,t,s,n,r);if(!f){l();return}if(c.clear(`probe-unavailable`,a.id),e.positionUnknown=!1,e.placedJd=t,d!==a.parentId&&e.trailBuffer?.clear(),o){o.outOfRange=!1;let e=u.isDestroyed;o.isLanded||=(Mk(o.labelHalo,`landed`),!0),o.isCrashed=e,o.model&&(o.model.visible=!e)}e.position[0]=f.x,e.position[1]=f.y,e.position[2]=f.z,e.orbitCenter&&(e.orbitCenter[0]=f.parentPos[0],e.orbitCenter[1]=f.parentPos[1],e.orbitCenter[2]=f.parentPos[2]),e.trailAnchor&&(e.trailAnchor[0]=f.parentPos[0],e.trailAnchor[1]=f.parentPos[1],e.trailAnchor[2]=f.parentPos[2]),s.set(a.id,e.position);let p=f.up;o?.mesh&&(p?vC(o.mesh,p):_C(o.mesh,e.position,f.parentPos)),o?.model&&(p?vC(o.model,p):_C(o.model,e.position,f.parentPos));return}let d=By(i.probe,t,i.fitCenterNaifId,n.chebStore??null,e=>s.has(e));if(!d){l(),c.warnOnce(`probe-unavailable`,a.id,()=>`probe ${a.id} (${a.name??`unnamed`}): hidden — stamped fit center is not placeable this frame`);return}let f=d.id,m=d.muKm3S2,g=xy(i.probe,t,m);if(!g){l(),c.warnOnce(`probe-unavailable`,a.id,()=>`probe ${a.id} (${a.name??`unnamed`}): hidden — sub-chunk evaluation returned null (uncoverable, non-finite fit, or missing mu for kepler_pure)`);return}c.clear(`probe-unavailable`,a.id),o?.isLanded&&(Mk(o.labelHalo,`flying`),o.isLanded=!1,o.isCrashed&&(o.isCrashed=!1,o.model&&(o.model.visible=!0),o.noPhysical||eD(o,`missing`,null)));let v=s.get(f_),b=s.get(d_),x=f===`naif-399`&&v!==void 0&&b!==void 0&&gI([Q(g[0]),Q(g[2]),-Q(g[1])],[b[0]-v[0],b[1]-v[1],b[2]-v[2]])!==null,S=x!==(e.lagrangeTrail??!1);e.lagrangeTrail=x;let E=a.parentId!==f;if((E||S)&&e.trailBuffer&&n.probeStore){let r=e.trailBuffer;r.clear(),r.needsPopulate=!1;let o=Wy(Ly(i.probe,t,m),a.validityEnd-a.validityStart,r.capacity,x);r.reconfigure(o.stepDays,o.epsilonScene,o.spanDays),Xy(r,n.probeStore,n.chebStore??null,a.id,f,t)}E&&(a.parentId=f),y(f);let D=s.get(f);if(!D){l(),c.warnOnce(`probe-unavailable`,a.id,()=>`probe ${a.id} (${a.name??`unnamed`}): hidden — fit center ${f} has no position this frame`);return}_=D;let O=Q(g[0]),k=Q(g[2]),A=-Q(g[1]);C=_[0]+O,w=_[1]+k,T=_[2]+A;let j=e.trailBuffer;if(j?.needsPopulate&&o?.trail?.visible&&n.probeStore&&(j.needsPopulate=!1,j.clear(),Xy(j,n.probeStore,n.chebStore??null,a.id,f,t)),j){let e=j.newestJd,r=t-e,o=j.stepDays*j.capacity,s=isFinite(e)&&(r<0||r>o);if(s&&a.id===h&&n.probeStore){j.clear();let e=Wy(Ly(i.probe,t,m),a.validityEnd-a.validityStart,j.capacity,x);j.reconfigure(e.stepDays,e.epsilonScene,e.spanDays),Xy(j,n.probeStore,n.chebStore??null,a.id,f,t)}else s?(j.clear(),j.append(t,O,k,A)):isFinite(e)?isFinite(j.epsilonScene)?r>=j.stepDays*.00390625&&n.probeStore&&j.readNewestPos(SI)&&Qy(j,Ky(n.probeStore,n.chebStore??null,a.id,f),e,[SI[0],SI[1],SI[2]],t):r>=j.stepDays&&j.append(t,O,k,A):j.append(t,O,k,A)}}else if(a.a===0&&!b&&!a.satrec)[C,w,T]=_;else{let e=a.satrec?yg(a.satrec,t):b?Yv(a,t):qv(a,t);if(!e){l();return}C=_[0]+e[0],w=_[1]+e[1],T=_[2]+e[2]}if(o&&(o.outOfRange=!1),e.positionUnknown=!1,e.placedJd=t,e.position[0]=C,e.position[1]=w,e.position[2]=T,(!Number.isFinite(C)||!Number.isFinite(w)||!Number.isFinite(T))&&c.warnOnce(`non-finite`,a.id,()=>{let e=s.has(a.parentId);return`computePosition[${a.id}] non-finite: pos=[${C},${w},${T}] parentId=${a.parentId} parentInPositionMap=${e} parentPos=[${_[0]},${_[1]},${_[2]}] isChebTracked=${d} isProbe=${f} objectType=${a.objectType}`}),e.orbitCenter&&(e.orbitCenter[0]=_[0],e.orbitCenter[1]=_[1],e.orbitCenter[2]=_[2]),e.trailAnchor&&(e.trailAnchor[0]=_[0],e.trailAnchor[1]=_[1],e.trailAnchor[2]=_[2]),s.set(a.id,e.position),o){if(o.trail&&e.orbitCenter){let e=o.trail.userData.orbitCenter;e&&e.set(_[0],_[1],_[2])}if(e.orientation&&(o.mesh||o.model))o.mesh&&mC(o.mesh,e.orientation,t,e.nutPrec),o.model&&mC(o.model,e.orientation,t,e.nutPrec),o.nomenclatureAnchor&&mC(o.nomenclatureAnchor,e.orientation,t,e.nutPrec);else if(QD(e)){let n=e.attitudeTrack;if(!e.pointingOverride&&n&&n.orientationAt(t,CI))o.mesh&&o.mesh.quaternion.copy(CI),o.model&&o.model.quaternion.copy(CI);else{let n=e.pointingOverride??e.pointing;if(n){let r=DI(n)?OI(a.id,t,e.position):void 0,i={bodyPos:e.position,parentPos:_,sunPos:s.get(d_),velocity:r};o.mesh&&MC(o.mesh,n,i),o.model&&MC(o.model,n,i)}else o.mesh&&_C(o.mesh,e.position,_),o.model&&_C(o.model,e.position,_)}}if(e.orientation)for(let n of o.rings)mC(n.mesh,e.orientation,t,e.nutPrec)}},w=n.visibility.focusedSystemId;for(let e of n.bodies.bodiesById.values()){if(e.data.objectType===G.MOON&&!(w!==null&&e.data.parentId===w)&&e.data.id!==h){s.set(e.data.id,e.position);continue}C(e)}for(let e of r.values())n.bodies.bodiesById.has(e.body.data.id)||C(e.body);if(m.satellites=n.refresher?.satelliteCoverage(t)??{kind:`covered`},d.update(m),o&&cn(o)){let e=n.getBody(o.featureAnchor.hostId);e&&s.has(e.data.id)?Bw(o,e,r.get(e.data.id),t):m.focusedOutOfRange=!0}let T=null;if(o&&m.focusedOutOfRange){let e=_.find(e=>e.bo&&!e.bo.outOfRange);if(e){T=e.id;let t=s.get(e.id)??e.oldPos;if(performance.now()-a.focusStartTime<a.focusDurationMs){a.focusTargetWorld[0]=t[0],a.focusTargetWorld[1]=t[1],a.focusTargetWorld[2]=t[2];let e=a.camTargetOffset;e&&a.camTargetWorld&&(a.camTargetWorld[0]=t[0]+e[0],a.camTargetWorld[1]=t[1]+e[1],a.camTargetWorld[2]=t[2]+e[2])}else{let n=t[0]-e.oldPos[0],r=t[1]-e.oldPos[1],i=t[2]-e.oldPos[2];a.focusTruePos[0]+=n,a.focusTruePos[1]+=r,a.focusTruePos[2]+=i,a.focusTargetWorld[0]=a.focusTruePos[0],a.focusTargetWorld[1]=a.focusTruePos[1],a.focusTargetWorld[2]=a.focusTruePos[2]}}}else if(o){let e=o.position,t=performance.now()-a.focusStartTime<a.focusDurationMs;a.focusTargetWorld[0]=e[0],a.focusTargetWorld[1]=e[1],a.focusTargetWorld[2]=e[2];let n=a.camTargetOffset;n&&a.camTargetWorld&&(a.camTargetWorld[0]=e[0]+n[0],a.camTargetWorld[1]=e[1]+n[1],a.camTargetWorld[2]=e[2]+n[2]);let r=a.camOriginOffset;r&&a.camOriginWorld&&(a.camOriginWorld[0]=e[0]+r[0],a.camOriginWorld[1]=e[1]+r[1],a.camOriginWorld[2]=e[2]+r[2]),t||(a.focusTruePos[0]=e[0],a.focusTruePos[1]=e[1],a.focusTruePos[2]=e[2])}let E=a.focusTruePos;for(let e of r.values()){let n=e.trail;if(n){if(!n.visible){n.userData.refreshDeferred=!0;continue}eF(e.body,n,E,t,l),n.userData.refreshDeferred=!1}}return{focusedOutOfRange:m.focusedOutOfRange,reanchorId:T}}function AI(e,t,n,r){let i=t.focusTruePos;for(let t of e.values()){let e=t.trail;!e||!e.visible||!e.userData.refreshDeferred||(eF(t.body,e,i,n,r),e.userData.refreshDeferred=!1)}}var jI=class{seen=new Map;bucket(e){let t=this.seen.get(e);return t||this.seen.set(e,t=new Set),t}warnOnce(e,t,n){let r=this.bucket(e);r.has(t)||(r.add(t),console.warn(n()))}clear(e,t){this.seen.get(e)?.delete(t)}},MI=Q(695700),NI=2,PI=new J;function FI(e,t,n,r,i){PI.subVectors(e,t);let a=PI.dot(n),o=Math.sqrt(Math.max(PI.lengthSq()-a*a,0)),s=o-Math.min(Math.max(o,r),i),c=Math.sqrt(s*s+a*a);return{dist:c,sinToPole:c>0?Math.abs(s)/c:1}}function II(e,t,n,r,i,a){let o=e.get(d_)?.body.position;if(!o)return;let[s,c,l]=t;for(let t of e.values()){if(!t.rings.length)continue;let[e,u,d]=t.body.position;for(let f of t.rings){let p=r||f.intensityScale>=.000980392156862745;f.mesh.visible=p;let m=r?1:p?f.intensityScale:0;f.material.uniforms.uIntensityScale.value=m;let h=f.material.uniforms.uSunDir.value;h.set(o[0]-e,o[1]-u,o[2]-d);let g=h.length(),_=MI/g;f.material.uniforms.uSunAngularRadius.value=_,f.material.uniforms.uLightScale.value=n?ST(g):1,h.normalize();let v=f.planetShadowOnRing;if(v.uPlanetCenter.value.set(e-s,u-c,d-l),t.mesh&&v.uPlanetPoleDir.value.set(0,1,0).applyQuaternion(t.mesh.quaternion),f.layers){let{dist:e,sinToPole:t}=FI(i,v.uPlanetCenter.value,v.uPlanetPoleDir.value,f.innerScene,f.outerScene),n=f.thicknessScene*t/Math.max(e,1e-9)*a,r=Math.min(Math.max(Math.ceil(n*NI),1),48);f.layers.count!==r&&(f.layers.count=r,f.material.uniforms.uLayerCount.value=r,f.material.uniforms.uLayerAlphaExp.value=1/r)}let y=f.planetShadow;y&&(y.uRingShadowIntensity.value=m,y.uRingShadowSunAngularRadius.value=_,y.uRingShadowSunDir.value.copy(h),y.uRingShadowPoleDir.value.copy(v.uPlanetPoleDir.value),y.uRingShadowCenter.value.copy(v.uPlanetCenter.value))}}}var LI=Math.PI/180,RI=2451545;function zI(e){let t=e-RI,n=(19.3871+.52402073*t)*LI;return((270.3871+.524038496*t+((10.691+3e-7*t)*Math.sin(n)+.623*Math.sin(2*n)+.05*Math.sin(3*n)+.005*Math.sin(4*n)+5e-4*Math.sin(5*n)))%360+360)%360}function BI(e,t,n){let r=e.length,i=r-1;for(let t=0;t<r-1;t++)if(n<e[t+1]){i=t;break}let a=(i+1)%r,o=i===r-1?360-e[i]:e[a]-e[i],s=(n-e[i])/o;return t[i]+(t[a]-t[i])*s}function VI(e,t){let n=e.seasonal;if(!n)return e;let r=BI(n.lsDeg,n.dustTauFactor,t),i=BI(n.lsDeg,n.dustScaleHeightKm,t),a=BI(n.lsDeg,n.pressureFactor,t),o=r*e.mieScaleHeightKm/i,s=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];return{...e,rayleighScatterPerKm:s(e.rayleighScatterPerKm,a),mieScatterPerKm:s(e.mieScatterPerKm,o),mieAbsorptionPerKm:s(e.mieAbsorptionPerKm,o),mieScaleHeightKm:i,seasonal:void 0}}var HI=new WeakMap,UI=.25;function WI(e,t){if(!e.seasonal)return e;let n=Math.round(zI(t)/UI),r=HI.get(e);if(r&&r.lsQ===n)return r.params;let i=VI(e,n*UI);return HI.set(e,{lsQ:n,params:i}),i}var GI=new J,KI=new J,qI=[.2126,.7152,.0722];function JI(e,t,n){return n<=0?0:e<=t-n?n:e>=t+n?0:e<=t?n-(e-(t-n))**2/(2*n):(t+n-e)**2/(2*n)}function YI(e,t){let n=Math.max(t,0),r=e.rayleighScaleHeightKm*Math.exp(-n/e.rayleighScaleHeightKm),i=e.mieScaleHeightKm*Math.exp(-n/e.mieScaleHeightKm),a=JI(n,e.absorptionCenterKm,e.absorptionWidthKm),o=0;for(let t=0;t<3;t++){let n=e.rayleighScatterPerKm[t]*r+(e.mieScatterPerKm[t]+e.mieAbsorptionPerKm[t])*i+e.absorptionPerKm[t]*a;o+=qI[t]*Math.exp(-n)}return o}var XI=.4,ZI=.05,QI=-.105,$I=.3,eL=.05;function tL(e,t,n){let r=YI(e,t),i=Math.min(1,-Math.log(Math.max(r,.001))/eL),a=Math.min(1,Math.max(0,(n-QI)/$I));return r*(1+(XI+(ZI-XI)*a-1)*i)}function nL(e,t,n,r){let i=Math.sqrt(2*n/r),a=Math.sqrt(Math.PI*r/(2*n));return t>=0?e/(Math.tan(t)+1/a):e*a*Math.exp(t/i)}var rL=bT,iL=200,aL=new J,oL=new J,sL=new J,cL=new J;function lL(e,t,n,r){e.uOccluderCount.value=zC(e.uOccluders.value,t,r,n)}function uL(e,t,n,r,i,a,o){let s={insideShell:!1,shellProminent:!1,skyboxIntensity:1,sunTint:aL.set(1,1,1),sunRefraction:null};zA(n&&a.sunTint);let c=e.get(d_);fj(c?.mesh?.material,_b());let l=dj(c?.mesh?.material);l&&(l.uAtmoTEnable.value=0);let u=iL,d=c?.body.position;if(!d)return s;for(let c of e.values()){if(!c.atmosphere||(c.atmosphere.mesh.visible=n,!n))continue;jA(c.atmosphere,a);let e=gb(c.body.data.id);if(e?.seasonal){let t=a.seasonal?WI(e,o):e;if(c.atmosphere.params!==t){MA(c.atmosphere,t);for(let e of c.sunTint??[])KA(e,t,c.atmosphere.surfaceRadiusScene,c.atmosphere.surfaceRadiusKm)}}let[f,p,m]=c.body.position,h=c.atmosphere.material.uniforms;h.uGroundAlbedo.value=a.groundAlbedo?c.atmosphere.params.groundAlbedo??0:0;let g=h.uSunDir.value.set(d[0]-f,d[1]-p,d[2]-m),_=c.atmosphere.params,v=r?ST(g.length()):_.realisticSunAlways?Math.sqrt(ST(g.length())):1;h.uSunIntensity.value=_.sunIntensity*v*i,g.normalize(),c.mesh&&(GI.set(0,1,0).applyQuaternion(c.mesh.quaternion),h.uSpinAxis.value.copy(GI));let y=c.atmosphere.mesh,b=c.atmosphere.geometryRadiusScene*y.scale.x,x=t.distanceTo(y.position);b>x*.1&&(s.shellProminent=!0),a.eclipseShadows&&lL(h,y.position,g,b);let S=a.insideView&&x<b,C=c.atmosphere.planetRadiusKm,w=x*((C+_.topAltitudeKm)/b)-C,T=S&&OA(_,w),E=S?kA(_,w):0;TA(c.atmosphere,S,T,E),h.uDeepIrradiance.value=rL*i;for(let e of c.sunTint??[])e.uAtmoTDeepIrradiance.value=rL*i,e.uAtmoTDeepBlend.value=E;if(S){s.insideShell=!0;let e=KI.copy(t).sub(y.position).divideScalar(x).dot(g),n=tL(_,w,e);if(s.skyboxIntensity*=n*(1-E),a.refraction&&_.refractivity&&!T){let t=nL(_.refractivity[1]*Math.exp(-Math.max(w,0)/_.rayleighScaleHeightKm),Math.asin(Math.min(1,Math.max(-1,e))),_.rayleighScaleHeightKm,c.atmosphere.planetRadiusKm);t>5e-6&&(s.sunRefraction={angleRad:t,up:cL.copy(KI)})}}let D=x/b;if(a.sunTint&&D<iL){let e=b/(1+_.topAltitudeKm/C)*(c.atmosphere.surfaceRadiusKm/C);sL.copy(t).sub(y.position);let n=h.uSpinAxis.value,r=h.uStretch.value;if($A(_,sL,g,e,c.atmosphere.surfaceRadiusKm,oL,n,r)){let e=qI[0]*oL.x+qI[1]*oL.y+qI[2]*oL.z;e>1e-4&&s.sunTint.multiply(oL.divideScalar(e))}l&&D<u&&(u=D,JA(l,_,y.position,e,c.atmosphere.surfaceRadiusKm,n,r))}}return s}var dL=[];function fL(e,t){let n=LC(),r=e.get(d_);if(!r){n.uSunAngularRadius.value=0,n.uOccluderCount.value=0;return}let[i,a,o]=t,s=r.body.position,c=s[0]-i,l=s[1]-a,u=s[2]-o,d=Math.hypot(c,l,u);d>0?(n.uSunDir.value.set(c/d,l/d,u/d),n.uSunAngularRadius.value=Math.asin(Math.min(r.radiusScene/d,1))):n.uSunAngularRadius.value=0;let f=dL,p=0;for(let t of e.values()){if(t.body.data.objectType===G.STAR)continue;let e=t.body.data.radiusKm;!Number.isFinite(e)||e<=0||t.radiusScene<=0||(f[p++]=t)}f.length=p,p>32&&(f.sort((e,t)=>t.radiusScene-e.radiusScene),f.length=32,p=32);let m=n.uOccluders.value;for(let e=0;e<p;e++){let t=f[e],[n,r,s]=t.body.position;m[e].set(n-i,r-a,s-o,t.radiusScene)}n.uOccluderCount.value=p;for(let e=0;e<p;e++)f[e]=void 0;f.length=0;let h=n.uSunDir.value;for(let t of e.values()){let e=t.eclipseShadow;if(!e||t.cachedDist>0&&t.radiusScene<t.cachedDist*1e-4)continue;let[n,r,s]=t.body.position,c=e.uEclipseSelfPos.value.set(n-i,r-a,s-o);e.uOccluderCount.value=zC(e.uOccluders.value,c,t.radiusScene,h)}}var pL=10;function mL(e,t,n,r,i,a,o,s,c){let l=n.visibility.activeSystemId;if(!l){r.intensity=0,i&&CT(i,s,c);return}let u=e.get(d_)?.body.position,[d,f,p]=t,m=(u?.[0]??0)-d,h=(u?.[1]??0)-f,g=(u?.[2]??0)-p,_=Math.hypot(m,h,g),v=o.set(m,h,g).normalize();r.position.copy(v).multiplyScalar(pL),r.target.position.set(0,0,0),r.intensity=bT*(s?ST(_):1)*c,i&&(i.intensity=0);let y=Math.max(a*2,.001),b=n.bodies.getSystemExtent(l)*10*1.2,x=r.shadow.camera;x.left=x.bottom=-y,x.right=x.top=y,x.near=pL-b,x.far=pL+b,x.updateProjectionMatrix()}var hL=128,gL=256,_L=.25,vL=.32,yL=.35,bL=300,xL=1.25,SL=.05,CL=4e5,wL=new Y,TL=new J;function EL(e,t,n){let r=e=>t.some(([t,n])=>e>t+1e-9&&e<n-1e-9),i=e/hL,a=[];for(let t=0;t<=hL;t++){let n=t===hL?e:t*i;(t===0||t===hL||!r(n))&&a.push(n)}for(let[r,i]of t){let t=Math.ceil(Math.max(r,0)/n-1e-9),o=Math.floor(Math.min(i,e)/n+1e-9);for(let e=t;e<=o;e++)a.push(e*n)}a.sort((e,t)=>e-t);let o=n*.25,s=[];for(let e of a)s.length&&e-s[s.length-1]<o||s.push(e);return s[0]=0,s[s.length-1]=e,Float64Array.from(s)}function DL(e,t,n){let r=t.length,i=n.length,a=new Float32Array(r*i*3),o=new Float32Array(r*i*3),s=new Float32Array(r*i*2);for(let c=0;c<r;c++){let r=t[c],l=Math.sin(r),u=Math.cos(r);for(let t=0;t<i;t++){let d=n[t],f=-Math.cos(d)*l,p=u,m=Math.sin(d)*l,h=(c*i+t)*3;a[h]=e*f,a[h+1]=e*p,a[h+2]=e*m,o[h]=f,o[h+1]=p,o[h+2]=m;let g=(c*i+t)*2;s[g]=d/(2*Math.PI),s[g+1]=1-r/Math.PI}}let c=new Uint32Array((r-1)*(i-1)*6),l=0;for(let e=0;e<r-1;e++){let n=t[e]<=0,r=t[e+1]>=Math.PI;for(let t=0;t<i-1;t++){let a=e*i+t+1,o=e*i+t,s=(e+1)*i+t,u=(e+1)*i+t+1;n||(c[l++]=a,c[l++]=o,c[l++]=u),r||(c[l++]=o,c[l++]=s,c[l++]=u)}}let u=new Vo;return u.setAttribute(`position`,new Eo(a,3)),u.setAttribute(`normal`,new Eo(o,3)),u.setAttribute(`uv`,new Eo(s,2)),u.setIndex(new Eo(c.subarray(0,l),1)),u}function OL(e){e.terrainWindow&&(e.terrainWindow=null,e.currentSegments=void 0)}function kL(e,t,n){let r=e.mesh,i=e.displacementMap;if(!n||!r||!i)return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: eligible=${n} mesh=${!!r} tex=${!!i}`),OL(e),!1;r.updateMatrixWorld(),wL.copy(r.matrixWorld).invert(),TL.copy(t.position).applyMatrix4(wL);let a=Q(mn(e.body.data)),o=TL.length(),s=Math.max(o/a-1,1e-6);if(s>(e.terrainWindow?vL:_L))return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: alt=${s.toFixed(4)}`),OL(e),!1;let c=i.image?.width??2048,l=2*Math.PI/c,u=Math.acos(1/(1+s)),d=Math.max(l,2*u*xL/gL),f=Math.log2(d/l),p=Math.max(0,Math.ceil(f-1e-9)),m=e.terrainWindow;m&&m.texWidth===c&&f>m.stepLevel-.85&&f<m.stepLevel+.15&&(p=m.stepLevel);let h=l*2**p,g=h*gL/2,_=Math.acos(Math.min(1,Math.max(-1,TL.y/o))),v=Math.atan2(TL.z,-TL.x);if(v<0&&(v+=2*Math.PI),m&&m.texWidth===c){if(m.stepLevel===p){let e=Math.sin(_)*Math.sin(m.centerTheta)*Math.cos(v-m.centerPhi)+Math.cos(_)*Math.cos(m.centerTheta);if(Math.acos(Math.min(1,Math.max(-1,e)))<yL*m.angRadius)return!0}if(performance.now()-m.builtAt<bL)return!0}let y=Math.max(0,_-g),b=Math.min(Math.PI,_+g),x=EL(Math.PI,[[y,b]],h),S=Math.min(Math.PI,g/Math.max(Math.sin(_),SL)),C=Math.max(p,Math.ceil(Math.log2(2*S/gL/l)-1e-9)),w=l*2**Math.max(0,C),T=v-S,E=v+S,D=S>=Math.PI?[[0,2*Math.PI]]:T<0?[[0,E],[T+2*Math.PI,2*Math.PI]]:E>2*Math.PI?[[0,E-2*Math.PI],[T,2*Math.PI]]:[[T,E]],O=EL(2*Math.PI,D,w);if(x.length*O.length>CL)return console.warn(`terrain window for ${e.body.data.id} would need ${x.length}×${O.length} vertices — keeping the uniform sphere`),OL(e),!1;let k=r.geometry;return r.geometry=DL(a,x,O),k.dispose(),console.debug(`terrain window ${e.body.data.id}: ${x.length}×${O.length} grid, level ${p} (tex ${c})`),e.terrainWindow={thetas:x,phis:O,centerTheta:_,centerPhi:v,angRadius:g,stepLevel:p,texWidth:c,builtAt:performance.now()},e.currentSegments=hL,!0}var AL=[{up:150,segs:128},{up:40,segs:64},{up:0,segs:32}],jL=24;function ML(e,t,n,r){if(!n&&!t)return jL;let i=AL[AL.length-1].segs;for(let t of AL)if(e>=t.up){i=t.segs;break}if(i<r){let t=AL.find(e=>e.segs===r);if(t&&e>=t.up*.85)return r}return i}function NL(e,t,n,r,i){let a=t.fov*Math.PI/180,o=n.domElement.clientHeight/(2*Math.tan(a/2)),s=r.visibility.activeSystemId,c=i;for(let n of e.values()){if(!n.mesh||!n.radiusScene||!n.group.visible||n.cachedDist<=0)continue;let e=n.body.data.objectType===G.STAR,a=n.body.data.id;if((a===c||n.terrainWindow)&&kL(n,t,a===c))continue;let l=ML(n.radiusScene/n.cachedDist*o,e,s?a===s||r.visibility.isInActiveSystem(n.body.data.parentId):a===i,n.currentSegments??64);if(l===n.currentSegments)continue;let u=Q(mn(n.body.data)),d=n.mesh.geometry;n.mesh.geometry=new nu(u,l,l),d.dispose(),n.currentSegments=l}}function PL(e,t){let n=e<1.05?`high`:e<4?`medium`:`low`;if(eM(n)>eM(t))return n;let r=e>7?`low`:e>1.15?`medium`:`high`;return eM(r)<eM(t)?r:t}function FL(e,t,n,r,i,a,o,s){s.apply(e,i);let c=t.fov*Math.PI/180,l=n.domElement.clientHeight/(2*Math.tan(c/2)),u=r.visibility.activeSystemId,d=jx(),f=d.showClouds,p=eM(Kx());for(let t of e.values())t.clouds&&(t.clouds.mesh.visible=f);for(let t of e.values()){if(!t.mesh||!t.radiusScene||!t.group.visible||!t.availableTiers?.length||t.cachedDist<=0)continue;let e=t.body.data.id;if(u){if(e!==u&&!r.visibility.isInActiveSystem(t.body.data.parentId))continue}else if(e!==a)continue;let s=t.radiusScene/t.cachedDist*l,c=t.cachedDist/t.radiusScene,f;f=s<256&&c>10?`low`:s<1024&&c>2?`medium`:`high`;let m=eM(t.textureTier),h=Math.min(eM(f),p),g=rM(o,t.availableFrames),_=g!==t.textureFrame,v=h>m;if(d.showSurfaceTexture&&!t.textureLoading&&(v||_)){let e=v?tM(h,t.availableTiers):t.textureTier;e&&lM(t,e,g,i)}let y=t.displacementMeta?.tiers;if(t.displacementMap&&y?.length&&!t.displacementLoading){let e=n.capabilities.maxTextureSize,r=e>=16383?2:+(e>=8192),i=t.displacementTier??`low`,a=tM(Math.min(eM(PL(c,i)),r,p),y);a&&a!==i&&iw(t,a)}if(t.clouds&&t.textureTier){let e=tM(eM(t.textureTier),t.clouds.availableTiers),n=jj(o,t.clouds.availableFrames,t.clouds.availableCoverage);e&&n&&Pj(t.clouds,e,n)}}}var IL=KO.refMs,LL=new Y,RL=new J,zL=new J,BL=new Vi,VL=new Vi,HL=new J,UL=new J;function WL(e,t,n){return RL.set(e[0],e[1],e[2]),zL.set(t[0],t[1],t[2]),LL.lookAt(RL,zL,n),BL.setFromRotationMatrix(LL).clone()}function GL(e,t,n,r,i){let a=performance.now()-e.focusStartTime,o=e.focusDurationMs>0?Math.min(a/e.focusDurationMs,1):1,s=o<1,c=!!(e.camOriginWorld&&e.camTargetWorld&&e.flyQ0);if(s&&c){let n=o*o*(3-2*o);if(e.focusTruePos=I_(e.focusOriginWorld,e.focusTargetWorld,n),r(),e.orbitFly){let r=e.focusOriginWorld[0]!==e.focusTargetWorld[0]||e.focusOriginWorld[1]!==e.focusTargetWorld[1]||e.focusOriginWorld[2]!==e.focusTargetWorld[2],i;if(e.arcOrbit)i=R_(e.camOriginWorld,e.camTargetWorld,e.focusTargetWorld,n);else{let t=r?o*o*o:n;i=I_(e.camOriginWorld,e.camTargetWorld,t)}t.position.set(i[0]-e.focusTruePos[0],i[1]-e.focusTruePos[1],i[2]-e.focusTruePos[2]),r&&!e.arcOrbit?(t.lookAt(e.focusTargetWorld[0]-e.focusTruePos[0],e.focusTargetWorld[1]-e.focusTruePos[1],e.focusTargetWorld[2]-e.focusTruePos[2]),VL.copy(t.quaternion),t.quaternion.slerpQuaternions(e.flyQ0,VL,n)):t.lookAt(e.focusTargetWorld[0]-e.focusTruePos[0],e.focusTargetWorld[1]-e.focusTruePos[1],e.focusTargetWorld[2]-e.focusTruePos[2])}else{let r;if(e.cameraStaysOnBody)r=e.camTargetWorld;else{let t=o*o*o;r=I_(e.camOriginWorld,e.camTargetWorld,t)}let i=WL(r,e.focusTargetWorld,t.up);t.quaternion.slerpQuaternions(e.flyQ0,i,n),t.position.set(r[0]-e.focusTruePos[0],r[1]-e.focusTruePos[1],r[2]-e.focusTruePos[2])}return!1}if((e.focusTruePos[0]!==e.focusTargetWorld[0]||e.focusTruePos[1]!==e.focusTargetWorld[1]||e.focusTruePos[2]!==e.focusTargetWorld[2])&&(e.focusTruePos=[...e.focusTargetWorld],r(),i()),n.target.set(0,0,0),e.camTargetWorld){let r=e.camTargetWorld[0]-e.focusTruePos[0],i=e.camTargetWorld[1]-e.focusTruePos[1],a=e.camTargetWorld[2]-e.focusTruePos[2];t.position.set(r,i,a),n.enableDamping=!1,n.update(),n.enableDamping=!0,t.position.set(r,i,a),e.camOriginWorld=null,e.camTargetWorld=null,e.camTargetOffset=null,e.camOriginOffset=null,e.flyQ0=null,e.orbitFly=!1,e.arcOrbit=!1,e.cameraStaysOnBody=!1}return!n.update()}function KL(e,t,n,r,i,a=!1){if(e.focusOriginWorld=[...e.focusTruePos],e.focusTargetWorld=[...t],e.focusStartTime=performance.now(),e.arcOrbit=!1,e.camOriginOffset=null,i){e.camOriginWorld=r,e.camTargetWorld=[...i],e.camTargetOffset=[i[0]-t[0],i[1]-t[1],i[2]-t[2]],e.cameraStaysOnBody=!1,e.flyQ0=n.quaternion.clone();let a=WL([i[0]-e.focusTruePos[0],i[1]-e.focusTruePos[1],i[2]-e.focusTruePos[2]],[t[0]-e.focusTruePos[0],t[1]-e.focusTruePos[1],t[2]-e.focusTruePos[2]],n.up),o=L_(r,i),s=e.flyQ0.angleTo(a);e.focusDurationMs=Math.max(GO(o,JO),WO(s,YO))}else e.camOriginWorld=r,e.camTargetWorld=[...r],e.camTargetOffset=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],e.cameraStaysOnBody=!0,e.flyQ0=n.quaternion.clone(),HL.set(0,0,-1).applyQuaternion(e.flyQ0),UL.set(t[0]-r[0],t[1]-r[1],t[2]-r[2]).normalize(),e.focusDurationMs=WO(HL.angleTo(UL),KO);if(a){let t=e.focusOriginWorld[0]!==e.focusTargetWorld[0]||e.focusOriginWorld[1]!==e.focusTargetWorld[1]||e.focusOriginWorld[2]!==e.focusTargetWorld[2];(i||t)&&(e.focusDurationMs=0)}}function qL(e,t,n,r,i=!1){e.camOriginWorld=n,e.camTargetWorld=[...r],e.camTargetOffset=[r[0]-e.focusTruePos[0],r[1]-e.focusTruePos[1],r[2]-e.focusTruePos[2]],e.camOriginOffset=[n[0]-e.focusTruePos[0],n[1]-e.focusTruePos[1],n[2]-e.focusTruePos[2]],e.focusOriginWorld=[...e.focusTruePos],e.focusTargetWorld=[...e.focusTruePos],e.focusStartTime=performance.now(),e.orbitFly=!0,e.arcOrbit=!0,e.cameraStaysOnBody=!1,e.flyQ0=t.quaternion.clone();let a=L_(n,r);HL.set(e.focusTruePos[0]-n[0],e.focusTruePos[1]-n[1],e.focusTruePos[2]-n[2]).normalize(),UL.set(e.focusTruePos[0]-r[0],e.focusTruePos[1]-r[1],e.focusTruePos[2]-r[2]).normalize();let o=HL.angleTo(UL);e.focusDurationMs=Math.max(GO(a,JO),WO(o,YO)),i&&(e.focusDurationMs=0)}var JL={[G.STAR]:1e3,[G.PLANET]:100,[G.DWARF_PLANET]:10,[G.ASTEROID]:.1,[G.ASTEROID_INNER]:.1,[G.ASTEROID_MAIN_BELT]:.1,[G.ASTEROID_CENTAUR]:1,[G.ASTEROID_TROJAN]:1,[G.ASTEROID_TNO]:1,[G.COMET]:1,[G.MOON]:1},YL=5e-4,XL=new J,ZL=new J;function QL(e){return JL[e.data.objectType]??mn(e.data)*.25}function $L(e,t){return Q((t??mn(e.data))+QL(e))}function eR(e,t,n,r){let i=t.data.radiusKm;if(!Number.isFinite(i)||i<=0)return;let a=t.position[0]-n[0],o=t.position[1]-n[1],s=t.position[2]-n[2],c=Math.hypot(a,o,s),l=r?.centerOffsetScene,u=a+(l?l[0]:0),d=o+(l?l[1]:0),f=s+(l?l[2]:0),p=e.position.x-u,m=e.position.y-d,h=e.position.z-f,g=Math.hypot(p,m,h);if(r?.seated){if(g<1e-9){e.position.set(u,d+c+Q(YL),f);return}let t=Math.tan(e.fov*Math.PI/360)*e.near,n=t*e.aspect,i=0;for(let[a,o,s]of[[0,0,0],[-n,-t,-e.near],[n,-t,-e.near],[-n,t,-e.near],[n,t,-e.near]]){ZL.set(a,o,s).applyQuaternion(e.quaternion);let t=p+ZL.x,n=m+ZL.y,l=h+ZL.z,u=Math.hypot(t,n,l);if(u<1e-12)continue;XL.set(t/u,n/u,l/u).applyQuaternion(r.invQuat);let d=r.radialKm([XL.x,XL.y,XL.z]),f=(d===null?c:Q(d))+Q(YL);f-u>i&&(i=f-u)}if(i<=0)return;let a=i/g;e.position.set(e.position.x+p*a,e.position.y+m*a,e.position.z+h*a);return}let _=QL(t);if(g>=Q((r?.outerRadiusKm??i)+_))return;let v=i;r&&g>1e-9&&(XL.set(p/g,m/g,h/g).applyQuaternion(r.invQuat),v=r.radialKm([XL.x,XL.y,XL.z])??i);let y=Q(v+_),b=c>0?Math.min(y,c):y;if(!(g>=b)){if(g<1e-9)p=0,m=b,h=0;else{let e=b/g;p*=e,m*=e,h*=e}e.position.set(u+p,d+m,f+h)}}function tR(e,t,n){let r=e.position,{latitude:i,longitude:a,distance:o}=iC([r.x,r.y,r.z],[0,0,0],n),s=Math.min(Math.max(i,t.minLat??-90),t.maxLat??90),c=cC(a,t.minLon,t.maxLon),l=Math.min(Math.max(o,t.minDistance??0),t.maxDistance??1/0);if(s===i&&c===a&&l===o)return;let[u,d,f]=aC([0,0,0],s,c,l,n);r.set(u,d,f)}var nR=50,rR=20;function iR(e){return e<=0?`none`:e<rR?`full`:e<nR?`half`:`none`}function aR(e,t){return e.data.validityStart<=t&&t<=e.data.validityEnd}var oR=class{pendingDefaults=new Set;defaults=new Set;userPromoted=new Set;autoPromoted=new Set;pinned=new Set;pinPromoted=new Set;groupTargets=null;groupMode=`none`;smallBodyZone=null;countStableLo=1/0;countStableHi=-1/0;constructor(e){this.deps=e,e.ctx.bodies.onBodiesAdded(()=>{this.onBodiesAdded(),this.buildPinned(),this.autoPromoteAsteroidMoons(),this.reevaluateEarthSatMode(),this.smallBodyZone!==null&&this.refreshSmallBodyEmphasis()}),e.ctx.onEarthSatRollover(()=>this.reevaluateEarthSatMode()),e.ctx.onGroupFilterChange(e=>this.applyGroupFilter(e)),this.applyGroupFilter(e.ctx.earthSatFilter),e.ctx.onSmallBodyFilterChange(e=>this.applySmallBodyFilter(e)),this.applySmallBodyFilter(e.ctx.smallBodyFilter),Bv().then(e=>{let t=[],n=e=>{if(!this.defaults.add(e)||this.deps.bodyObjects.has(e))return;let n=this.deps.ctx.getBody(e);if(!n){this.pendingDefaults.add(e);return}this.shouldAutoPromote(n,e)&&t.push(n)};for(let t of e.keys())n(t);for(let e of p_)n(e);this.buildBatch(t),this.autoPromoteAsteroidMoons();let r=!1;for(let e of this.userPromoted)this.defaults.has(e)&&(this.userPromoted.delete(e),r=!0);r&&this.emitUserPromotedCount()})}autoPromoteAsteroidMoons(){let e=this.deps.ctx.bodies.asteroidBodiesByZone.get(`small_body_moons`);if(!e||e.size===0)return;let t=[],n=new Set;for(let r of e.keys()){let i=e.getKey(r);if(!i||i.data.objectType!==G.MOON||!this.isDefault(i.data.parentId))continue;let a=this.deps.ctx.getBody(i.data.parentId);!a||!hn(a.data.objectType)||(!this.deps.bodyObjects.has(a.data.id)&&!n.has(a.data.id)&&(n.add(a.data.id),t.push(a)),this.deps.bodyObjects.has(i.data.id)||t.push(i))}this.buildBatch(t)}onBodiesAdded(){if(this.pendingDefaults.size===0)return;let e=[];for(let t of this.pendingDefaults){let n=this.deps.ctx.getBody(t);n&&(this.pendingDefaults.delete(t),this.shouldAutoPromote(n,t)&&e.push(n))}this.buildBatch(e)}shouldAutoPromote(e,t){return e.data.objectType!==G.BARYCENTER&&e.data.objectType!==G.LAGRANGE_POINT?!0:p_.has(t)}isDefault(e){return this.defaults.has(e)}ensureBodyObjects(e){this.buildBodyInstance(e)&&this.finalizeBuilds()}buildBodyInstance(e,t,n=!1){let{bodyObjects:r,ctx:i,clock:a,scene:o,clickables:s,meshToBody:c,circleTexture:l,renderer:u}=this.deps;if(r.has(e.data.id))return!1;if(kT(e,a.jd,i),!e.orbitElements&&!e.data.unplaceable&&e.data.orbitalSource!==W.SPICE_PROBE){e.orbitElements=e.data;let t=r.get(e.data.parentId);t&&(e.orbitCenter=[...t.body.position])}gj([e],o,s,c,r,l,u.domElement,this.deps.onBodyClick,(e,t)=>t?this.deps.hoveredBodyIds.add(e):this.deps.hoveredBodyIds.delete(e),t);let d=r.get(e.data.id);if(d&&!e.data.name&&sM(d),e.data.objectType===G.SPACECRAFT)i.bodies.dirtySpacecraftGroups.add(e.data.parentId);else if(hn(e.data.objectType)||e.data.objectType===G.COMET){let t=this.deps.ctx.bodies.findAsteroidZone(e.data.id);t&&i.bodies.dirtyAsteroidZones.add(t)}let f=e.data.id;return this.defaults.has(f)||(n?this.autoPromoted.add(f):(this.userPromoted.add(f),this.emitUserPromotedCount())),!0}finalizeBuilds(){CN(this.deps.bodyObjects,this.deps.scene,this.deps.pointClouds.basis(),this.deps.clock.jd),this.deps.assignMapLayerToTrails(),this.deps.repositionAll(),this.deps.pointClouds.rebuildMinor()}buildBatch(e,t,n=!1){let r=!1;for(let i of e)this.buildBodyInstance(i,t,n)&&(r=!0);r&&this.finalizeBuilds()}applyGroupFilter(e){this.groupTargets=e,this.reevaluateEarthSatMode()}applySmallBodyFilter(e){this.smallBodyZone=e?.kind===`class`?`small_bodies/${e.className}`:null,this.refreshSmallBodyEmphasis()}refreshSmallBodyEmphasis(){let e=this.smallBodyZone;if(e===null){this.deps.pointClouds.setEmphasizedSmallBodyZone(null,null);return}let t=this.deps.ctx.bodies.asteroidBodiesByZone.get(e)?.size??0;this.deps.pointClouds.setEmphasizedSmallBodyZone(e,t)}onSimTimeChanged(){let e=this.deps.clock.jd;e>this.countStableLo&&e<this.countStableHi||this.reevaluateEarthSatMode()}reevaluateEarthSatMode(){let e=this.deps.ctx.bodies.spacecraftByParent.get(f_),t=this.currentMemberCount(e),n=iR(t);this.deps.pointClouds.setEarthSatEmphasis(t);let r=n!==this.groupMode;if(this.teardownAutoPromoted(r),this.groupMode=n,n===`none`||!e)return;let i=this.deps.clock.jd,a=[];for(let t of e.values())this.groupTargets&&!this.groupTargets.has(t.data.id)||aR(t,i)&&(this.deps.bodyObjects.has(t.data.id)||a.push(t));if(a.length===0)return;let o=n===`half`?new Set(a.map(e=>e.data.id)):void 0;this.buildBatch(a,o,!0)}currentMemberCount(e){if(this.countStableLo=-1/0,this.countStableHi=1/0,!e)return 0;let t=this.deps.clock.jd,n=0;for(let r of e.values()){if(this.groupTargets&&!this.groupTargets.has(r.data.id))continue;let{validityStart:e,validityEnd:i}=r.data;e<=t?e>this.countStableLo&&(this.countStableLo=e):e<this.countStableHi&&(this.countStableHi=e),i<t?i>this.countStableLo&&(this.countStableLo=i):i<this.countStableHi&&(this.countStableHi=i),aR(r,t)&&n++}return n}teardownAutoPromoted(e){if(this.autoPromoted.size===0)return;let t=this.deps.getFocusedId(),n=this.deps.clock.jd,r=[];for(let i of this.autoPromoted){if(i===t)continue;if(e||this.groupTargets&&!this.groupTargets.has(i)){r.push(i);continue}let a=this.deps.bodyObjects.get(i)?.body;a&&!aR(a,n)&&r.push(i)}r.length!==0&&this.tearDownBodies(r,this.autoPromoted)}setPinned(e){this.pinned=new Set(e);let t=this.deps.getFocusedId(),n=[...this.pinPromoted].filter(e=>!this.pinned.has(e));t&&n.includes(t)&&(this.pinPromoted.delete(t),this.userPromoted.add(t),this.emitUserPromotedCount()),this.tearDownBodies(n.filter(e=>e!==t),this.pinPromoted),this.buildPinned()}buildPinned(){let e=!1;for(let t of this.pinned){let n=this.deps.ctx.getBody(t);!n||cn(n)||n.data.objectType===G.MOON||this.buildBodyInstance(n)&&(e=!0,this.userPromoted.delete(t)&&this.pinPromoted.add(t))}e&&(this.emitUserPromotedCount(),this.finalizeBuilds())}clearUserPromoted(){let e=this.deps.getFocusedId(),t=[...this.userPromoted].filter(t=>t!==e);this.tearDownBodies(t,this.userPromoted),this.emitUserPromotedCount()}tearDownBodies(e,t){if(e.length===0)return;let{bodyObjects:n,ctx:r,scene:i,clickables:a,meshToBody:o,pointClouds:s}=this.deps,c=new Set,l=new Set;for(let r of e){let e=n.get(r);if(!e){t.delete(r);continue}e.label&&(e.label.element.remove(),e.label.removeFromParent()),e.loadingEl?.remove(),dO(e),cM(e),IM(e),i.remove(e.group);for(let t of e.extraObjects)i.remove(t);if(e.trail&&i.remove(e.trail),e.mesh){e.mesh.geometry.dispose(),pj(e.mesh.material);let t=a.indexOf(e.mesh);t>=0&&a.splice(t,1),o.delete(e.mesh)}e.atmosphere&&=(e.atmosphere.mesh.geometry.dispose(),pj(e.atmosphere.mesh.material),null),e.trail&&(e.trail.geometry.dispose(),pj(e.trail.material));let s=e.body.data.objectType;if(s===G.SPACECRAFT)c.add(e.body.data.parentId);else if(hn(s)||s===G.COMET){let e=this.deps.ctx.bodies.findAsteroidZone(r);e&&l.add(e)}n.delete(r),t.delete(r)}for(let e of c)r.bodies.dirtySpacecraftGroups.add(e);for(let e of l)r.bodies.dirtyAsteroidZones.add(e);(c.size>0||l.size>0)&&s.rebuildMinor()}emitUserPromotedCount(){if(!this.deps.onUserPromotedChange)return;let e=this.deps.getFocusedId(),t=this.userPromoted.size;e&&this.userPromoted.has(e)&&t--,this.deps.onUserPromotedChange(t)}},sR=class{promotion;readerFocusFilter=null;focusedBody;_tmpV3=new J;pendingInitialView=null;upgradeTargetIds=new Set;constructor(e,t,n,r,i){this.deps=e,this.focusedBody=t,this.promotion=new oR({scene:e.scene,bodyObjects:e.bodyObjects,ctx:e.ctx,clock:e.clock,renderer:i,circleTexture:r,clickables:e.clickables,meshToBody:e.meshToBody,hoveredBodyIds:n,pointClouds:e.pointClouds,onBodyClick:e=>this.handleFocus(e),assignMapLayerToTrails:e.assignMapLayerToTrails,repositionAll:e.repositionAll,getFocusedId:()=>this.focusedBody?.data.id,onUserPromotedChange:e.callbacks.onUserPromotedChange})}get current(){return this.focusedBody}setPendingInitialView(e){this.pendingInitialView=e}clearPendingInitialView(){this.pendingInitialView=null}focusedBodyQuat(e){let t=e??this.focusedBody;if(!t||QD(t))return;let n=this.deps.bodyObjects.get(t.data.id)?.mesh;if(!n)return;let r=n.quaternion;return[r.x,r.y,r.z,r.w]}cameraTruePos(){let{focus:e,camera:t}=this.deps;return[e.focusTruePos[0]+t.position.x,e.focusTruePos[1]+t.position.y,e.focusTruePos[2]+t.position.z]}syncUpgradeTargets(e){let{ctx:t,scene:n,clickables:r,meshToBody:i,bodyObjects:a,pointClouds:o,clock:s,loadTexture:c,assignMapLayerToTrails:l}=this.deps,u=cR(e,t),d=new Set(u.map(e=>e.data.id));for(let e of this.upgradeTargetIds){if(d.has(e))continue;let t=a.get(e);t&&(_j(t.body)?yj(t,n,r,i):dO(t))}let f=!1;for(let t of u){if(this.upgradeTargetIds.has(t.data.id))continue;this.promotion.ensureBodyObjects(t);let o=a.get(t.data.id);if(!o){d.delete(t.data.id);continue}_j(t)&&(vj(o,n,r,i),f=!0),t.data.id!==e?.data.id&&c(t)}return f&&(CN(a,n,o.basis(),s.jd),l()),this.upgradeTargetIds=d,d}panCameraToBody(e){if(e.positionUnknown)return;let{focus:t,camera:n}=this.deps;KL(t,[...e.position],n,this.cameraTruePos(),void 0,jx().resolvedReducedMotion)}focusOnPoint(e,t){let{focus:n,camera:r,callbacks:i}=this.deps,a=this.cameraTruePos(),o;if(t!==void 0){let n=this._tmpV3.set(e[0]-a[0],e[1]-a[1],e[2]-a[2]).normalize().negate();o=[e[0]+n.x*t,e[1]+n.y*t,e[2]+n.z*t]}this.focusedBody=void 0,KL(n,[...e],r,a,o,jx().resolvedReducedMotion);let s=iC(o??a,e,void 0);i.onCameraPosition?.(s.latitude,s.longitude,s.distance)}handleFocus(e){if(this.readerFocusFilter&&!this.readerFocusFilter(e))return;if(this.focusedBody?.data.id===e.data.id){this.deps.callbacks.onFocusChange(e);return}if(this.setFocusTarget(e),e.positionUnknown)return;let{latitude:t,longitude:n,distance:r}=iC(this.cameraTruePos(),e.position,this.focusedBodyQuat(e));this.deps.callbacks.onCameraPosition?.(t,n,r)}setFocusTarget(e,t){let{ctx:n,bodyObjects:r,controls:i,callbacks:a,focus:o,camera:s,systemData:c,loadTexture:l}=this.deps;cn(e)||this.promotion.ensureBodyObjects(e);let u=this.focusedBody,d=CM(u,r),f=CM(e,r),p=u&&(cn(u)?u.featureAnchor.hostId:u.data.id),m=cn(e)?e.featureAnchor.hostId:e.data.id,h=this.syncUpgradeTargets(e);if(p&&p!==m&&!h.has(p)){let e=r.get(p);e&&dO(e)}if(d&&d!==f){let e=r.get(d);e&&IM(e)}this.focusedBody=e,cn(e)||(n.bodies.focusFeature=null),i.minDistance=$L(e,MO(r.get(e.data.id)));let g=cn(e)?n.getBody(e.featureAnchor.hostId):void 0;if(n.visibility.setFocused(g??e),a.onFocusChange(e),cn(e)||l(e),f&&f!==e.data.id){let e=n.getBody(f);e&&l(e)}c.syncToFocus(),e.positionUnknown||KL(o,[...e.position],s,this.cameraTruePos(),t,jx().resolvedReducedMotion),this.promotion.emitUserPromotedCount()}focusOnBody(e,t,n,r){let{ctx:i,clock:a,focus:o,camera:s,callbacks:c,pointClouds:l}=this.deps,u=i.getBody(e);if(!u)return 0;if(i.bodies.bodiesById.has(e)||kT(u,a.jd,i),u.positionUnknown)return this.setFocusTarget(u),0;let d;if(t!==void 0)if(n!==void 0&&r!==void 0)d=aC(u.position,n,r,t,this.focusedBodyQuat(u));else{let e=this.cameraTruePos(),n=this._tmpV3.set(u.position[0]-e[0],u.position[1]-e[1],u.position[2]-e[2]).normalize().negate();d=[u.position[0]+n.x*t,u.position[1]+n.y*t,u.position[2]+n.z*t]}let f=iC(d??this.cameraTruePos(),u.position,this.focusedBodyQuat(u));return c.onCameraPosition?.(f.latitude,f.longitude,f.distance),t!==void 0&&d?this.focusedBody?.data.id===e&&L_(o.focusTruePos,u.position)<$L(u)?(o.focusTruePos=[...u.position],this.deps.repositionAll(),l.rebuildBasis(),qL(o,s,this.cameraTruePos(),d,jx().resolvedReducedMotion)):(this.setFocusTarget(u,d),n!==void 0&&r!==void 0&&(o.orbitFly=!0)):this.setFocusTarget(u),o.focusDurationMs}snapToBody(e,t,n,r){let i=this.deps.ctx.getBody(e);!i||i.positionUnknown||(this.settleOnBodyInstant(i),this.snapToBodyFrame(t,n,r))}snapToBodyFacing(e,t,n,r){let{ctx:i,camera:a,controls:o,callbacks:s}=this.deps,c=i.getBody(e);if(!c||c.positionUnknown)return;this.settleOnBodyInstant(c);let l=i.getBody(t)?.position??[0,0,0],u=oC(c.position,l,n,r);a.position.set(u[0],u[1],u[2]),o.update();let d=iC(u,[0,0,0]);s.onCameraPosition?.(d.latitude,d.longitude,d.distance),this.pendingInitialView=null}settleOnBodyInstant(e){let{focus:t,pointClouds:n}=this.deps;this.setFocusTarget(e),t.focusTruePos=[...e.position],t.focusOriginWorld=[...e.position],t.focusTargetWorld=[...e.position],t.focusStartTime=-IL,t.camOriginWorld=null,t.camTargetWorld=null,t.flyQ0=null,t.orbitFly=!1,t.arcOrbit=!1,t.cameraStaysOnBody=!1,this.deps.repositionAll(),n.rebuildBasis()}snapToBodyFrame(e,t,n){let r=this.focusedBody;if(!r)return;let{camera:i,controls:a,callbacks:o}=this.deps,s=!QD(r),c=s?this.focusedBodyQuat(r)??[0,0,0,1]:void 0,l=aC([0,0,0],e,t,n,c);i.position.set(l[0],l[1],l[2]),a.update();let u=iC(l,[0,0,0],c);o.onCameraPosition?.(u.latitude,u.longitude,u.distance),s&&c[0]===0&&c[1]===0&&c[2]===0&&c[3]===1&&(this.pendingInitialView={latitude:e,longitude:t,zoom:n})}reapplyInitialViewIfPending(){let e=this.pendingInitialView;if(!e)return;let t=this.focusedBodyQuat();if(!t||t[0]===0&&t[1]===0&&t[2]===0&&t[3]===1){this.pendingInitialView=null;return}let n=aC([0,0,0],e.latitude,e.longitude,e.zoom,t);this.deps.camera.position.set(...n),this.deps.controls.update(),this.pendingInitialView=null}};function cR(e,t){if(!e)return[];if(cn(e)){let n=t.getBody(e.featureAnchor.hostId);return n&&_j(n)?[n]:[]}let n=[];if(_j(e)&&n.push(e),e.data.objectType===G.MOON||e.data.orbitalSource===W.SPICE_PROBE){let r=t.getBody(e.data.parentId);r&&n.push(r)}return n}var lR=1e-6;function uR(e){return e.data.name??e.data.id}var dR=class{armedProbeId=null;noticeShown=!1;coverage=new Map;pending=new Set;constructor(e,t){this.clock=e,this.notices=t}coverageFor(e){let t=this.coverage.get(e);if(t!==void 0)return t??void 0;this.pending.has(e)||(this.pending.add(e),mx(e,!1).then(t=>this.coverage.set(e,t.global?.coverage??null)).catch(()=>this.coverage.set(e,null)).finally(()=>this.pending.delete(e)))}sync(e,t){let n=e?.data.id??null,r=n===null?void 0:this.coverageFor(n);if(!e||!r){this.disarm();return}this.armedProbeId!==n&&(this.dismissNotice(),this.armedProbeId=n);let i=r.end_jd-lR,a=r.start_jd+lR;this.noticeShown&&t>a&&t<i&&this.dismissNotice(),this.clock.setBoundaryStops({forwardJd:i,backwardJd:a,onHit:t=>this.onHit(e,t,i)})}onHit(e,t,n){this.notices.notify({topic:`coverage-pause`,name:uR(e),direction:t>=n?`forward`:`backward`,jd:t}),this.noticeShown=!0}disarm(){this.armedProbeId!==null&&(this.armedProbeId=null,this.dismissNotice(),this.clock.setBoundaryStops(null))}dismissNotice(){this.noticeShown&&=(this.notices.dismiss(`coverage-pause`),!1)}},fR=class{group=new Ra;extensions=new Set;constructor(){this.group.matrixAutoUpdate=!1,this.group.frustumCulled=!1}add(e){this.extensions.add(e),this.group.add(e.object)}remove(e){this.extensions.delete(e)&&(this.group.remove(e.object),e.dispose())}update(e){for(let t of this.extensions)t.update(e)}clear(e){for(let t of[...this.extensions])e?.(t)||(this.extensions.delete(t),this.group.remove(t.object),t.dispose())}dispose(){this.clear()}},pR=Math.PI/180;function mR(e){return`latitude`in e}function hR(e,t){let n=e*pR,r=t*pR;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function gR(e,t,n,r,i,a){let o=2*(e.y*r-e.z*n),s=2*(e.z*t-e.x*r),c=2*(e.x*n-e.y*t);i[a]=t+e.w*o+(e.y*c-e.z*s),i[a+1]=n+e.w*s+(e.z*o-e.x*c),i[a+2]=r+e.w*c+(e.x*s-e.y*o)}function _R(e,t,n){return jT(e,n,t)?e.position:null}function vR(e,t,n,r){let[i,a,o]=n;if(mR(e)){let n=Q(mn(t.data)+(e.altitudeKm??0)),[s,c,l]=hR(e.latitude,e.longitude),u=t.orientation?pC(t.orientation,r,t.nutPrec):null;if(!u)return[i+s*n,a+c*n,o+l*n];let d=[0,0,0];return gR(u,s,c,l,d,0),[i+d[0]*n,a+d[1]*n,o+d[2]*n]}let s=typeof e.offsetKm==`function`?e.offsetKm(r):e.offsetKm;if(s===null)return null;if(s===void 0)return[i,a,o];let[c,l,u]=OF(s);return[i+c,a+l,o+u]}function yR(e,t,n){let r=t.getBody(e.body),i=r&&_R(r,t,n);return i?vR(e,r,i,n):null}function bR(e,t,n,r){let i=n.getBody(e.body),a=i&&_R(i,n,r);if(!a)return null;let o=t[0]-a[0],s=t[1]-a[1],c=t[2]-a[2],l=Math.hypot(o,s,c);return l===0?null:[o/l,s/l,c/l]}function xR(e){let t=rg/10;return[e[0]*t,-e[2]*t,e[1]*t]}function SR(e,t,n){let r=yR(e.position,t,n),i=yR(e.target,t,n);if(!r||!i)return null;let[a,o,s]=e.up??[0,0,1];return{position:r,target:i,up:[a,s,-o]}}var CR=.02,wR=1e-4;function TR(e){return e?.4:.05}function ER(e,t,n,r,i){let a=e.position.length();if(!(a>0))return{rotate:1,translate:1};let o=QD(n)?void 0:n,s=a;for(let n of[o,i?void 0:r]){if(!n)continue;let r=Q(mn(n.data));if(!(r>0))continue;let i=Math.hypot(e.position.x-(n.position[0]-t[0]),e.position.y-(n.position[1]-t[1]),e.position.z-(n.position[2]-t[2]));s=Math.min(s,i-r)}let c=o?Q(mn(o.data)):0,l=Math.tan(Bi.degToRad(e.getEffectiveFOV())/2);return{rotate:DR(c>0?(a-c)*l/(Math.PI*c):1,wR),translate:DR(s/a,CR)}}function DR(e,t){return Math.min(1,Math.max(t,e))}var OR=Math.PI/180;function kR(e,t){let n=e*OR,r=t*OR;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function AR(e,t,n,r){let i=document.createElement(`div`);i.className=`user-location-marker`;let a=new tk(i),[o,s,c]=kR(n,r);return a.position.set(o*t,s*t,c*t),e.add(a),a}function jR(e){e.parent?.remove(e),e.element.remove()}var MR=new J;function NR(e,t,n){if(!e)return;let r=t.get(f_);if(!r?.mesh)return;MR.copy(e.position).applyQuaternion(r.mesh.quaternion);let i=MR.x,a=MR.y,o=MR.z,s=r.mesh.position,c=n.position.x-s.x,l=n.position.y-s.y,u=n.position.z-s.z,d=r.radiusScene,f=d*d;e.visible=c*c+l*l+u*u<=f||i*c+a*l+o*u>f}var PR=-1,FR=1.2,IR=Q(1e6),LR=.02,RR=2,zR=2.3,BR=.9,VR=new J,HR=.25,UR=10,WR=4,GR=4,KR=28,qR=.02,JR=class e{renderer;composer;atmoDepthPass;bloomPass;labelRenderer;scene;camera;controls;motionScale={rotate:1,translate:1};pointerInteraction;gpuPick;canvas;ctx;clock;callbacks;selectedFeatureId=null;bodyObjects=new Map;circleTexture=$M();pointClouds;systemData;positionDiagnostics=new jI;clickables=[];meshToBody=new Map;hoveredBodyIds=new Set;cullFrameCounter=0;hideCappedMoonLabels=!1;focusController;coverageWatch=null;outOfRange;extensions=new fR;cameraHold=null;holdingCamera=!1;_tmpV3=new J;cameraBand=null;focusableBodies=null;limitsArmed=!1;bodySelectEnabled=!0;featureSelectEnabled=!0;modelScene;modelCamera;modelLight;overlayActive=!1;modelShadowPlane=null;_tmpUp=new J;_tmpSun=new J;_planeNormal=new J(0,0,1);_modelRaycaster=new Ld;_pickNdc=new q;showPointingAxes=!1;pointingAxes=null;cameraUp;skyboxAdjuster;skyDebugMarkers;haloDebug;travelPath;orbitPreview;previewFlyBodyId=null;travelFocus=null;focus={focusTruePos:[0,0,0],focusOriginWorld:[0,0,0],focusTargetWorld:[0,0,0],camOriginWorld:null,camTargetWorld:null,camTargetOffset:null,camOriginOffset:null,flyQ0:null,orbitFly:!1,arcOrbit:!1,cameraStaysOnBody:!1,focusStartTime:0,focusDurationMs:IL};lastUpdatedJd=NaN;get placedJd(){return this.lastUpdatedJd}lastUpdatedSystemId=null;lastSeatConfigKey=null;lastProbeVersion=0;disposed=!1;lastHostReadVersion=0;focusWasOutOfRange=!1;_positionMapScratch=new Map;frameIndex=0;static WAKE_FRAMES=30;static IDLE_HEARTBEAT_FRAMES=10;static REALTIME_FRAME_MS=30;wakeUntilFrame=e.WAKE_FRAMES;lastRenderedFrame=0;lastRenderMs=0;lastRenderedJd=NaN;lastRenderedFocusKey=``;lastRenderedCamPos=new J(NaN,NaN,NaN);lastRenderedCamQuat=new Vi;unsubscribeBodiesAdded=null;_trailView={camX:0,camY:0,camZ:0,tolAngle:0};viewportH=1;tier=Jx();landedNomBodyId=null;rafId=0;paused=!1;covered=!1;firstFrame=!0;pendingUrlWrite=!1;lastTickMs=0;static FPS_SAMPLE_FRAMES=30;fpsSamples=[];fpsSampleHead=0;stashedSky=null;namesShown=!0;halosShown=!0;textureLoader=new qu;appearances=new uM;shadowLight;ambientLights;get sunPointLight(){return this.bodyObjects.get(d_)?.extraObjects.find(e=>e instanceof ud)}tightFar=!1;sunProxyK=1;sunBaseMeshScale=1;sunBaseCoronaScale=0;userLocationMarker=null;labelContainer;static MAP_LAYER=1;static ATMO_DEPTH_LAYER=2;constructor(t,n,r,i,a,o){this.canvas=t,this.ctx=r,r.hasMeshBody=e=>this.bodyObjects.has(e),this.clock=i,this.callbacks=o,this.outOfRange=new vI(o.notices),this.labelContainer=n;let s=OT(t,n,r);this.viewportH=t.clientHeight||1,this.renderer=s.renderer,this.labelRenderer=s.labelRenderer,this.scene=s.scene,this.scene.add(this.extensions.group),this.camera=s.camera,this.composer=s.composer,this.bloomPass=s.bloomPass,this.shadowLight=s.shadowLight;let c=this.renderer.getDrawingBufferSize(new q);this.atmoDepthPass=new bj(c.x,c.y),this.modelScene=new Ka,this.modelScene.environment=wT(this.renderer),this.modelScene.environmentIntensity=xT,this.modelCamera=new od(60,1,.01,1e3),this.modelScene.add(this.modelCamera);let l=new md(16777215,yT);this.modelScene.add(l),this.ambientLights=[s.ambientLight,l],this.modelLight=new pd(16777215,bT),this.modelLight.castShadow=!0,this.modelLight.shadow.mapSize.set(this.tier.shadowMapSize,this.tier.shadowMapSize),this.modelLight.shadow.camera.left=-4,this.modelLight.shadow.camera.right=4,this.modelLight.shadow.camera.top=4,this.modelLight.shadow.camera.bottom=-4,this.modelLight.shadow.camera.near=4,this.modelLight.shadow.camera.far=28,this.modelLight.shadow.bias=-1e-4,this.modelLight.shadow.normalBias=.02,this.modelScene.add(this.modelLight),this.modelScene.add(this.modelLight.target),this.modelShadowPlane=new ks(new Ql(40,40),new ru({opacity:.55})),this.modelShadowPlane.receiveShadow=!0,this.modelShadowPlane.visible=!1,this.modelScene.add(this.modelShadowPlane),this.skyboxAdjuster=new kN(this.scene),this.skyDebugMarkers=new qN(this.scene),this.haloDebug=new nP(this.canvas),this.travelPath=new iI(this.scene,this.canvas),this.travelPath.setLayer(e.MAP_LAYER),this.orbitPreview=new lI(this.scene),this.orbitPreview.setLayer(e.MAP_LAYER),this.skyboxAdjuster.set(0,0,0),fS(this.scene,this.renderer,r,()=>this.disposed);let u=r.bodies.majorBodies.find(e=>e.data.id===d_),d=r.getBody(a.id),f=d&&!d.positionUnknown?d:void 0,p=r.bodies.majorBodies.find(e=>e.data.id===lC)||u,m=f??p,h=m?.position??[0,0,0];this.focus.focusTruePos=[...h],this.focus.focusOriginWorld=[...h],this.focus.focusTargetWorld=[...h],this.focus.focusStartTime=-IL,this.pointClouds=new FP(r,this.scene,this.bodyObjects,this.circleTexture,this.focus,e.MAP_LAYER,()=>this.rebuildTrailBasis()),this.pointClouds.seedBasis(h),this.pointClouds.setPointBudget(this.tier.pointBudget),this.controls=new IS(this.camera,t),this.controls.enableDamping=!0,this.controls.dampingFactor=TR(jx().resolvedReducedMotion),this.controls.minDistance=m?$L(m):Q(.01),this.controls.maxDistance=31620.5*10,this.controls.target.set(0,0,0),this.controls.update(),this.controls.addEventListener(`end`,this.onControlsEnd),this.controls.addEventListener(`start`,this.invalidate),this.controls.addEventListener(`start`,this.armLimits),this.controls.addEventListener(`end`,this.invalidate);for(let n of e.INPUT_EVENTS)t.addEventListener(n,this.invalidate,{passive:!0});window.addEventListener(`keydown`,this.invalidate),this.unsubscribeBodiesAdded=r.bodies.onBodiesAdded(this.invalidate),this.cameraUp=new ek(this.camera,this.controls,r,e=>this.isLanded(e)),this.systemData=new DN(this.scene,r,this.renderer,this.textureLoader,this.bodyObjects,i,()=>this.focusController.reapplyInitialViewIfPending()),this.focusController=new sR({ctx:r,clock:i,camera:this.camera,controls:this.controls,scene:this.scene,bodyObjects:this.bodyObjects,clickables:this.clickables,meshToBody:this.meshToBody,callbacks:o,focus:this.focus,pointClouds:this.pointClouds,systemData:this.systemData,loadTexture:e=>this.maybeLoadTexture(e),repositionAll:()=>this.repositionAll(),assignMapLayerToTrails:()=>this.assignMapLayerToTrails()},m,this.hoveredBodyIds,this.circleTexture,this.renderer),this.coverageWatch=new dR(i,o.notices);let g=f?a:{latitude:45,longitude:0,zoom:15},_=aC([0,0,0],g.latitude,g.longitude,g.zoom,this.focusController.focusedBodyQuat());this.camera.position.set(..._),this.focusController.setPendingInitialView({latitude:g.latitude,longitude:g.longitude,zoom:g.zoom}),m&&r.visibility.setFocused(m),r.visibility.updateCamera(g.zoom,this.clock.jd),o.onFocusChange(m),this.buildScene(),m&&this.focusController.promotion.ensureBodyObjects(m),m&&this.focusController.syncUpgradeTargets(m),this.repositionAll(),m&&this.maybeLoadTexture(m),this.systemData.syncToFocus(),this.focusController.readerFocusFilter=this.readerMayFocus,this.gpuPick=new HO(this.renderer,this.camera),this.pointerInteraction=new LO(t,this.camera,r,i,this.focus,this.clickables,this.meshToBody,e=>this.focusController.handleFocus(e),(e,t)=>this.pickFocusedModel(e,t),this.gpuPick,()=>[...this.pointClouds.asteroids().values(),...this.pointClouds.spacecraft().values()],this.pointClouds.pickRegistry),this.pointerInteraction.attach(),this.tick()}buildScene(){gj(this.ctx.bodies.majorBodies,this.scene,this.clickables,this.meshToBody,this.bodyObjects,this.circleTexture,this.renderer.domElement,e=>this.focusController.handleFocus(e),(e,t)=>{t?this.hoveredBodyIds.add(e):this.hoveredBodyIds.delete(e),this.invalidate()}),this.pointClouds.buildInitial(new Set(this.bodyObjects.keys()));let e=this.pointClouds.basis();(globalThis.requestIdleCallback??(e=>setTimeout(e,0)))(()=>{CN(this.bodyObjects,this.scene,e,this.clock.jd),this.assignMapLayerToTrails()})}setTravelPath(e,t=[],n=[],r=[]){this.travelPath.set(e,t,n,r),this.refreshTravelPath()}setTravelHover(e){this.travelPath.setHovered(e)}setOrbitPreview(e,t=null){this.orbitPreview.set(e),this.refreshOrbitPreview(),t&&this.frameOrbitPreview(t)}frameOrbitPreview(e){let t=this.ctx.getBody(e.bodyId);if(!t)return;let n=Q(e.radiusKm);if(!(n>0)||performance.now()-this.focus.focusStartTime<this.focus.focusDurationMs&&this.previewFlyBodyId===e.bodyId)return;let r=this.focus.focusTruePos,i=t.position[0]-r[0]-this.camera.position.x,a=t.position[1]-r[1]-this.camera.position.y,o=t.position[2]-r[2]-this.camera.position.z,s=Math.hypot(i,a,o);s>n*1.35&&s<n*45||(this.previewFlyBodyId=e.bodyId,this.focusController.focusOnBody(e.bodyId,n*4))}refreshOrbitPreview(){this.orbitPreview.isEmpty||(this.orbitPreview.reposition(e=>this.ctx.getBody(e)?.position??null,this.focus.focusTruePos),this.orbitPreview.updateCameraOffset(this.camera.position))}refreshTravelPath(){if(this.travelPath.isEmpty){this.reserveTravelLabelSpace();return}let e=this.travelPath.centerId,t=e?this.ctx.getBody(e):null;if(!t){this.travelPath.setVisible(!1),this.reserveTravelLabelSpace();return}this.travelPath.setVisible(!0),this.travelPath.setClock(this.clock.jd),this.travelPath.reposition(t.position,this.focus.focusTruePos,e=>this.ctx.getBody(e)?.position??null),this.travelPath.updateCameraOffset(this.camera.position),this.reserveTravelLabelSpace()}reserveTravelLabelSpace(){this.travelPath.reserveLabelSpace(this.camera,this.renderer.domElement.clientWidth,this.renderer.domElement.clientHeight)}focusOnPathPoint(e,t){this.disarmLimits();let n=this.ctx.getBody(e);if(!n)return;let[r,i,a]=OF(t);this.travelFocus={centerId:e,local:[r,i,a]};let o=this.travelFocusWorld(n.position);o&&this.focusController.focusOnPoint(o)}trackPathPoint(e,t){if(!this.travelFocus){this.focusOnPathPoint(e,t);return}let[n,r,i]=OF(t);this.travelFocus={centerId:e,local:[n,r,i]}}travelFocusWorld(e){let t=this.travelFocus;return t?[e[0]+t.local[0],e[1]+t.local[1],e[2]+t.local[2]]:null}refreshTravelFocus(){if(!this.travelFocus)return;if(this.focusController.current){this.travelFocus=null;return}let e=this.ctx.getBody(this.travelFocus.centerId);if(!e)return;let t=this.travelFocusWorld(e.position);if(!t)return;let n=this.focus;n.focusTargetWorld=t;let r=n.camTargetOffset;r&&n.camTargetWorld&&(n.camTargetWorld=[t[0]+r[0],t[1]+r[1],t[2]+r[2]]),performance.now()-n.focusStartTime>=n.focusDurationMs&&(n.focusTruePos=[...t])}updateTravelCraftSystem(){let e=this.travelFocus,t=this.travelPath.plan;if(!e||!t){this.ctx.visibility.clearTravelSystem();return}let n=this.ctx.getBody(e.centerId),r=n?this.travelFocusWorld(n.position):null;if(!r)return;let i=null;for(let e of t.stops){let t=this.ctx.getBody(e.bodyId);if(!t)continue;let n=this.ctx.visibility.resolveSystemId(t);if(!n)continue;let a=this.ctx.visibility.systemReachAU(n);if(!(a>0))continue;let o=L_(r,t.position)/10;!i&&o<=a?i=n:o<=a*2?this.systemData.prefetch(n):this.systemData.discardPrefetch(n)}this.ctx.visibility.setTravelSystem(i)}assignMapLayerToTrails(){for(let t of this.bodyObjects.values())t.trail&&t.trail.layers.set(e.MAP_LAYER)}setImmersive(t){t?(this.camera.layers.disable(e.MAP_LAYER),this.labelContainer.style.display=`none`):(this.camera.layers.enable(e.MAP_LAYER),this.labelContainer.style.display=``)}rebuildMinorPointClouds(){this.pointClouds.rebuildMinor()}repositionAll(){this.repositionBodies(),this.rebuildTrailBasis()}repositionBodies(){let[e,t,n]=this.focus.focusTruePos;for(let r of this.bodyObjects.values()){let[i,a,o]=r.body.position,s=i-e,c=a-t,l=o-n;r.group.position.set(s,c,l);for(let e of r.extraObjects)e.position.set(s,c,l)}this.pointClouds.reposition()}rebuildTrailBasis(){let e=this.focus.focusTruePos,[t,n,r]=e;for(let i of this.bodyObjects.values()){let a=i.trail;if(!a)continue;let o=a.userData.trailBuffer;if(o){QP(i.body,a,o,e,this.clock.jd);continue}let s=a.userData.trailLocalPositions;if(!s)continue;let c=a.userData.orbitCenter;$P(a,s,c.x-t,c.y-n,c.z-r)}}tick=()=>{this.rafId=requestAnimationFrame(this.tick),this.frameIndex++;let t=performance.now(),n=this.lastTickMs?t-this.lastTickMs:0;if(this.lastTickMs=t,this.holdingCamera||this.cameraUp.update(this.clock.jd),this.firstFrame&&(this.firstFrame=!1,this.controls.target.set(0,0,0),this.controls.update()),this.coverageWatch?.sync(this.focusController.current,this.clock.jd),this.clock.tick(performance.now()),!this.shouldRender(t)){this.controls.update(),this.applyReaderLimits(t);return}this.fpsSamples.length<e.FPS_SAMPLE_FRAMES?this.fpsSamples.push(t):(this.fpsSamples[this.fpsSampleHead]=t,this.fpsSampleHead=(this.fpsSampleHead+1)%e.FPS_SAMPLE_FRAMES);let r=this.lastRenderedFrame===this.frameIndex-1?n:0;this.lastRenderedFrame=this.frameIndex,this.lastRenderMs=t,this.lastRenderedJd=this.clock.jd,this.lastRenderedFocusKey=this.focusKey(),this.lastRenderedCamPos.copy(this.camera.position),this.lastRenderedCamQuat.copy(this.camera.quaternion),this.applyJdUpdate(!0),this.refreshTravelFocus(),this.callbacks.onFrame?.(this.clock.jd,r);let i=this.holdingCamera?this.applyHeldCamera():GL(this.focus,this.camera,this.controls,()=>this.repositionAll(),()=>this.pointClouds.rebuildBasis());this.applyReaderLimits(t);let a=this.holdingCamera?void 0:this.focusController.current;if(a){let e=P_(a.data.parentId),t=e?this.ctx.getBody(e):void 0,n=!!this.bodyObjects.get(a.data.id)?.isLanded||cn(a);t&&eR(this.camera,t,this.focus.focusTruePos,this.surfaceClamp(t,n)),kO(this.bodyObjects.get(a.data.id))&&eR(this.camera,a,this.focus.focusTruePos,this.surfaceClamp(a,!1)),this.setMotionScale(ER(this.camera,this.focus.focusTruePos,a,t,n))}else this.setMotionScale({rotate:1,translate:1});if(this.pendingUrlWrite&&i){this.pendingUrlWrite=!1;let{latitude:e,longitude:t,distance:n}=this.getCameraState();this.callbacks.onCameraPosition?.(e,t,n)}this.systemData.hasPendingUnloads()&&performance.now()-this.focus.focusStartTime>=this.focus.focusDurationMs&&this.systemData.drainPendingUnloads();let{distance:o}=this.getCameraState();this.updateTravelCraftSystem(),this.ctx.visibility.updateCamera(o,this.clock.jd),this.updateTightFar(o),this.systemData.syncToFocus(),this.refreshTravelPath(),this.refreshOrbitPreview(),this.extensions.update({jd:this.clock.jd,basis:this.focus.focusTruePos,camera:this.camera,viewportPx:this.viewportH,ctx:this.ctx}),this.cullFrameCounter=mF(this.bodyObjects,this.camera,this.ctx,this.focus.focusTruePos,this.focusController.current?.data.id,this.hideCappedMoonLabels,this.hoveredBodyIds,this.pointClouds.asteroids(),this.pointClouds.spacecraft(),this.pointClouds.moons(),this.cullFrameCounter,this.renderer,this._tmpV3,!i,this.tightFar),this.pointClouds.applyPointBudget(),AI(this.bodyObjects,this.focus,this.lastUpdatedJd,this.trailView()),II(this.bodyObjects,this.focus.focusTruePos,jx().realisticLighting,jx().overexposeRings,this.camera.position,this.pxPerRad()),fL(this.bodyObjects,this.focus.focusTruePos);let s=uL(this.bodyObjects,this.camera.position,jx().showAtmospheres,jx().realisticLighting,this.sunIntensityScale,Uk(),this.clock.jd);eA(r,s.shellProminent),this.scene.backgroundIntensity=s.skyboxIntensity,this.applyLayerChrome();let c=this.bodyObjects.get(d_);c&&uj(c.corona,c.starPoint,s.sunTint);let l=jx().highAmbient?1:yT;if(!jx().highAmbient&&jx().realisticLighting){let e=this.bodyObjects.get(d_)?.body.position;if(e&&this.ctx.visibility.activeSystemId){let[t,n,r]=this.focus.focusTruePos;l*=ST(Math.hypot(e[0]-t,e[1]-n,e[2]-r))}}for(let e of this.ambientLights)e.intensity=l;NR(this.userLocationMarker,this.bodyObjects,this.camera);let u=CM(this.focusController.current,this.bodyObjects);FL(this.bodyObjects,this.camera,this.renderer,this.ctx,this.textureLoader,u,this.clock.jd,this.appearances),NL(this.bodyObjects,this.camera,this.renderer,this.ctx,u),mL(this.bodyObjects,this.focus.focusTruePos,this.ctx,this.shadowLight,this.sunPointLight,o,this._tmpV3,jx().realisticLighting,this.sunIntensityScale),this.updateModelMounts(),this.pointClouds.drainOnePendingSceneAdd(),this.updateDepthFar(),this.updateSunProxy(s.sunRefraction),s.insideShell&&this.atmoDepthPass.run(this.renderer,this.scene,this.camera,this.bodyObjects,e.ATMO_DEPTH_LAYER),this.composer.render(),this.renderModelOverlay(),this.labelRenderer.render(this.scene,this.camera),this.haloDebug.active&&this.haloDebug.draw(this.bodyObjects,this.camera,this.focus.focusTruePos,this.focusController.current?.data.id,this.renderer.domElement.clientWidth,this.renderer.domElement.clientHeight)};updateTightFar(e){if(rT())return;let t=this.focusController.current,n=t?CM(t,this.bodyObjects):void 0,r=n?this.bodyObjects.get(n):void 0,i=r?.radiusScene??0,a=e;if(t&&r&&n!==t.data.id){let[e,t,n]=this.focus.focusTruePos,[i,o,s]=r.body.position,c=this.camera.position;a=Math.hypot(e+c.x-i,t+c.y-o,n+c.z-s)}let o=this.tightFar?zR:RR;this.tightFar=i>0&&this.ctx.visibility.activeSystemId!==null&&a<i*o}updateDepthFar(){if(rT())return;let e=TT,t=this.ctx.visibility.activeSystemId;if(t){let[n,r,i]=this.focus.focusTruePos,a=this.camera.position.lengthSq(),o=e=>{let t=e[0]-n,o=e[1]-r,s=e[2]-i,c=t*t+o*o+s*s;c>a&&(a=c)},s=this.bodyObjects.get(d_);if(this.tightFar){let e=this.bodyObjects.get(t)?.body;if(e){let o=Math.hypot(e.position[0]-n,e.position[1]-r,e.position[2]-i)+this.ctx.bodies.getSystemExtent(t)*10*2;a=Math.max(a,o*o)}}else s&&o(s.body.position);for(let e of this.bodyObjects.values())this.ctx.visibility.hasFullRendering(e.body)&&o(e.body.position);e=Math.min(TT,Math.max(IR,Math.sqrt(a)*FR))}Math.abs(e-this.camera.far)>this.camera.far*LR&&(this.camera.far=e,this.camera.updateProjectionMatrix())}updateSunProxy(e){let t=this.bodyObjects.get(d_);if(!t)return;let[n,r,i]=this.focus.focusTruePos,[a,o,s]=t.body.position,c=a-n,l=o-r,u=s-i;if(e){let t=this.camera.position,n=this._tmpV3.set(c-t.x,l-t.y,u-t.z),r=n.length();n.divideScalar(r);let i=VR.copy(e.up).addScaledVector(n,-e.up.dot(n));i.lengthSq()>1e-12&&(n.addScaledVector(i.normalize(),e.angleRad).normalize(),c=t.x+n.x*r,l=t.y+n.y*r,u=t.z+n.z*r)}let d=1;if(this.tightFar){let e=this.camera.far*BR,t=Math.hypot(c,l,u);t>e&&(d=e/t)}if(!(d===1&&this.sunProxyK===1&&!e)){this.sunProxyK===1&&(this.sunBaseMeshScale=t.mesh?.scale.x??1,this.sunBaseCoronaScale=t.corona?.scale.x??0),t.group.position.set(c*d,l*d,u*d);for(let e of t.extraObjects)e.position.set(c*d,l*d,u*d);t.mesh?.scale.setScalar(this.sunBaseMeshScale*d),t.corona?.scale.set(this.sunBaseCoronaScale*d,this.sunBaseCoronaScale*d,1),this.sunProxyK=d}}setMotionScale(e){this.motionScale=e,this.controls.rotateSpeed=e.rotate,this.controls.panSpeed=e.translate,this.controls.zoomSpeed=e.translate}isLanded(e){return!!this.bodyObjects.get(e)?.isLanded}surfaceRadialKm(e,t,n){let r=this.ctx.getBody(e);if(!r)return null;let i=cw(t*Math.PI/180,n*Math.PI/180);return Aw(this.bodyObjects.get(e),e,mn(r.data),i)}surfaceClamp(e,t){let n=this.bodyObjects.get(e.data.id);if(kO(n))return{invQuat:n.model.quaternion.clone().invert(),seated:t,outerRadiusKm:jO(n),centerOffsetScene:AO(n),radialKm:e=>OO(n,e)};if(!(!t||!e.orientation))return{invQuat:pC(e.orientation,this.clock.jd,e.nutPrec).invert(),seated:t,radialKm:t=>Aw(n,e.data.id,e.data.radiusKm,t)}}updateModelMounts(){let e=!1;for(let t of this.bodyObjects.values())if(t.model&&QD(t.body)){e=!0;break}this.overlayActive=e;for(let t of this.bodyObjects.values()){let n=t.model,r=t.modelRoot;if(!(!n||!r)){if(e)n.parent!==this.modelScene&&this.modelScene.add(n);else if(n.parent!==r){r.add(n);let e=n.userData;n.scale.setScalar(e.fitScale??1),n.position.set(0,0,0),e.centerOffset&&n.position.addScaledVector(e.centerOffset,-1)}}}if(e){this.shadowLight.castShadow=!1;return}this.updateFocusedMountedModel()}updateFocusedMountedModel(){let e=this.overlayModelBo(),t=e?.model&&e.model.parent===e.modelRoot?e.modelRoot:null;if(!e||!t){this.shadowLight.castShadow=!1;return}let n=iO(e);t.scale.setScalar(n);let r=this.shadowLight.intensity>0;if(this.shadowLight.castShadow=r,!r)return;let i=this.bodyObjects.get(d_)?.body;if(!i)return;let[a,o,s]=i.position,[c,l,u]=e.body.position;this._tmpSun.set(a-c,o-l,s-u).normalize(),this.shadowLight.position.copy(e.group.position).addScaledVector(this._tmpSun,UR*n),this.shadowLight.target.position.copy(e.group.position);let d=this.shadowLight.shadow.camera;d.left=d.bottom=-WR*n,d.right=d.top=WR*n,d.near=GR*n,d.far=KR*n,d.updateProjectionMatrix(),this.shadowLight.shadow.normalBias=qR*n}renderModelOverlay(){if(!this.overlayActive)return;let e=this.overlayModelBo();if(!e?.model)return;let t=e.model.userData;e.model.scale.setScalar(t.fitScale??1),e.model.position.set(0,0,0),e.isLanded&&t.feetOffset?e.model.position.copy(t.feetOffset).applyQuaternion(e.model.quaternion).multiplyScalar(-1):t.centerOffset&&e.model.position.copy(t.centerOffset).multiplyScalar(-1),this._tmpV3.copy(this.camera.position).sub(e.group.position);let n=this._tmpV3.length(),r=iO(e),i=n/r;this.modelCamera.position.copy(this._tmpV3).normalize().multiplyScalar(i),this.modelCamera.quaternion.copy(this.camera.quaternion),this.modelCamera.aspect=this.camera.aspect;let a=0;for(let t of this.bodyObjects.values()){let n=t.model;if(!n||t===e)continue;let i=iO(t)/r,o=n.userData.fitScale??1;n.scale.setScalar(o*i),n.position.subVectors(t.group.position,e.group.position).divideScalar(r);let s=n.userData;s.centerOffset&&n.position.addScaledVector(s.centerOffset,-i);let c=n.position.length()+i;c>a&&(a=c)}this.modelCamera.near=Math.max(.01,i-5-a),this.modelCamera.far=i+50+a,this.modelCamera.updateProjectionMatrix();let o=this.bodyObjects.get(d_)?.body,s=1;if(o){let[t,n,r]=o.position,[i,a,c]=e.body.position;this._tmpSun.set(t-i,n-a,r-c),jx().realisticLighting&&(s=ST(this._tmpSun.length())),this._tmpSun.normalize(),this.modelLight.position.copy(this._tmpSun).multiplyScalar(10)}if(this.modelShadowPlane){this._tmpUp.set(0,1,0).applyQuaternion(e.model.quaternion);let t=this._tmpSun.dot(this._tmpUp)>.03;this.modelShadowPlane.visible=!!e.isLanded&&!e.isCrashed&&t,this.modelShadowPlane.visible&&this.modelShadowPlane.quaternion.setFromUnitVectors(this._planeNormal,this._tmpUp)}this._tmpV3.set(0,0,0);let c=BC(this._tmpV3,this._tmpV3)*s;this.modelLight.intensity=bT*c*this.sunIntensityScale,this.modelScene.environmentIntensity=xT*c,this.showPointingAxes?(this.pointingAxes||(this.pointingAxes=this.buildPointingAxes(),this.modelScene.add(this.pointingAxes)),this.pointingAxes.quaternion.copy(e.model.quaternion),this.pointingAxes.scale.setScalar(Math.min(.8,.45*i)),this.pointingAxes.visible=!0):this.pointingAxes&&(this.pointingAxes.visible=!1),this.renderer.autoClear=!1,this.renderer.clearDepth(),this.renderer.render(this.modelScene,this.modelCamera),this.renderer.autoClear=!0}pxPerRad(){return this.viewportH/2/Math.tan(this.camera.fov*Math.PI/360)}trailView(){let e=this._trailView,t=this.camera.position;return e.camX=t.x,e.camY=t.y,e.camZ=t.z,e.tolAngle=HR/this.pxPerRad(),e}cloudViewInfo(){let e=this.camera.position;return{camPos:[e.x,e.y,e.z],pxPerRad:this.pxPerRad()}}getCameraState(){let e=this.camera.position;return iC([e.x,e.y,e.z],[0,0,0],this.focusController.focusedBodyQuat())}setDragEnabled(e){this.controls.enableRotate=e,this.controls.enablePan=e}setZoomEnabled(e){this.controls.enableZoom=e}setBodySelectEnabled(e){this.bodySelectEnabled=e}setFeatureSelectEnabled(e){this.featureSelectEnabled=e}readerMayFocus=e=>this.bodySelectEnabled&&(this.focusableBodies?.has(e.data.id)??!0);setCooperativeTouch(e){this.controls.touches.ONE=e?PR:Cn.ROTATE,this.canvas.style.touchAction=e?`pan-x pan-y`:`none`}setCameraLimits(e,t){this.cameraBand=e,this.focusableBodies=t?new Set(t):null}armLimits=()=>{this.limitsArmed=!0};disarmLimits(){this.limitsArmed=!1}applyReaderLimits(e){!this.limitsArmed||!this.cameraBand||this.holdingCamera||e-this.focus.focusStartTime<this.focus.focusDurationMs||tR(this.camera,this.cameraBand,this.focusController.focusedBodyQuat())}static INPUT_EVENTS=[`pointerdown`,`pointermove`,`pointerup`,`wheel`];invalidate=()=>{this.wakeUntilFrame=this.frameIndex+e.WAKE_FRAMES};focusKey(){let e=this.ctx.visibility;return`${this.focusController.current?.data.id??``}|${e.focusedSystemId??``}|${e.activeSystemId??``}`}cameraOffsetFromFocus(){let e=this.focusController.current,t=this.focus.focusTruePos,n=this.camera.position;return e?[n.x+t[0]-e.position[0],n.y+t[1]-e.position[1],n.z+t[2]-e.position[2]]:[n.x,n.y,n.z]}holdCamera(){this.holdingCamera||(this.disarmLimits(),this.holdingCamera=!0,this.controls.enabled=!1,this.focus.camOriginWorld=null,this.focus.camTargetWorld=null,this.focus.camTargetOffset=null,this.focus.camOriginOffset=null,this.focus.flyQ0=null,this.focus.orbitFly=!1,this.focus.arcOrbit=!1,this.focus.cameraStaysOnBody=!1)}setHeldPose(e){this.cameraHold=e}releaseCamera(){this.holdingCamera&&(this.holdingCamera=!1,this.cameraHold=null,this.controls.enabled=!0,this.controls.target.set(0,0,0),this.controls.enableDamping=!1,this.controls.update(),this.controls.enableDamping=!0,this.invalidate())}applyHeldCamera(){let e=this.cameraHold,t=e&&SR(e,this.ctx,this.clock.jd);if(!t)return!0;let n=this.focus.focusTruePos;return this.camera.up.set(t.up[0],t.up[1],t.up[2]).normalize(),this.camera.position.set(t.position[0]-n[0],t.position[1]-n[1],t.position[2]-n[2]),this.camera.lookAt(t.target[0]-n[0],t.target[1]-n[1],t.target[2]-n[2]),!0}shouldRender(t){if(this.holdingCamera||t-this.focus.focusStartTime<this.focus.focusDurationMs||this.focusKey()!==this.lastRenderedFocusKey||this.ctx.bodies.minorStreaming||this.pointClouds.hasPendingSceneAdds()||this.systemData.hasPendingUnloads())return!0;if(this.covered)return!1;if(this.frameIndex-this.lastRenderedFrame>=e.IDLE_HEARTBEAT_FRAMES)return!0;let n=this.camera;return n.position.distanceToSquared(this.lastRenderedCamPos)>n.position.lengthSq()*1e-10||8*(1-Math.abs(n.quaternion.dot(this.lastRenderedCamQuat)))>1e-8||this.frameIndex<this.wakeUntilFrame||this.haloDebug.active?!0:this.clock.jd===this.lastRenderedJd?!1:Math.abs(this.clock.timeScale)>1||t-this.lastRenderMs>=e.REALTIME_FRAME_MS}onControlsEnd=()=>{this.pendingUrlWrite=!0,this.focusController.clearPendingInitialView()};nudgeCamera(e,t,n){this.armLimits();let{rotate:r,translate:i}=this.motionScale;e!==0&&this.controls.rotateLeft(e*r),t!==0&&this.controls.rotateUp(t*r),n!==1&&this.controls.dollyIn(1/n**+i),this.onControlsEnd()}maybeLoadTexture(e){let t=this.bodyObjects.get(e.data.id);t&&(oM(t,this.textureLoader,this.clock.jd,this.scene,this.renderer.capabilities.maxTextureSize,this.ctx).then(()=>{this.focusController.current?.data.id===e.data.id&&e.orientation&&t.mesh&&(mC(t.mesh,e.orientation,this.clock.jd,e.nutPrec),this.focusController.reapplyInitialViewIfPending())}),cO(t,this.modelScene,this.ctx).then(()=>{if(this.focusController.current?.data.id===t.body.data.id&&(this.controls.minDistance=$L(t.body,MO(t))),!this.ctx.layers.skipped.has(`nomenclature`))return jM(t,this.canvas,(e,n,r,i)=>{this.featureSelectEnabled&&this.callbacks.onFeatureSelect?.(t.body.data.id,e,n,r,i)})}).then(()=>{this.selectedFeatureId!==null&&FM(t,this.selectedFeatureId)}))}reapplyBodyLayers(){let e=this.focusController.current;if(!e)return;let t=this.bodyObjects.get(e.data.id);t&&(dO(t),cM(t),this.maybeLoadTexture(e))}setSelectedFeature(e){this.selectedFeatureId=e;let t=CM(this.focusController.current,this.bodyObjects),n=t?this.bodyObjects.get(t):void 0;n&&FM(n,e)}syncLandedNomenclature(){let e=this.focusController.current,t=(e?this.bodyObjects.get(e.data.id):void 0)?.isLanded?e.data.parentId:null;if(t===this.landedNomBodyId||(this.landedNomBodyId=t,!t))return;let n=this.ctx.getBody(t);n&&this.maybeLoadTexture(n)}clearUserPromoted(){this.focusController.promotion.clearUserPromoted()}focusedSeatConfigKey(){let e=this.focusController.current;if(!e||e.data.objectType!==G.SPACECRAFT&&!cn(e))return null;let t=P_(e.data.parentId),n=t?this.bodyObjects.get(t):void 0;if(!n)return null;let r=n.terrainWindow;return`${r?`w${r.stepLevel}x${r.texWidth}@${r.centerTheta.toFixed(6)},${r.centerPhi.toFixed(6)}`:`u${n.currentSegments??128}`}|${n.displacementMap?.uuid??`none`}|${_w()}`}lastProbeTargetCheck=null;requestedProbeTargets=new Set;askedProbeRides=new Set;ensureFocusedProbeTarget(){let e=this.focusController.current,t=this.ctx.probeStore;if(!e||!t?.fitCenterUsable||e.data.orbitalSource!==W.SPICE_PROBE)return;this.askedProbeRides.has(e.data.id)||(this.askedProbeRides.add(e.data.id),hx(e.data.id).then(e=>e&&t.registerCarried(e)));let n=`${e.data.id}@${this.clock.jd}`;if(n===this.lastProbeTargetCheck)return;this.lastProbeTargetCheck=n;let r=t.stampedFitCenterAt(e.data.id,this.clock.jd);if(!r)return;let i=this.ctx.getBody(r);if(!i){if(this.requestedProbeTargets.has(r))return;this.requestedProbeTargets.add(r),this.ctx.ensureBody(r,Ng(this.clock.jd));return}this.focusController.promotion.ensureBodyObjects(i),this.focusController.syncUpgradeTargets(e)}applyJdUpdate(e=!1){this.ensureFocusedProbeTarget();let t=this.ctx.visibility.focusedSystemId,n=this.focusedSeatConfigKey(),r=this.ctx.probeStore?.version??0,i=this.ctx.bodies.hostReadVersion;if(this.clock.jd===this.lastUpdatedJd&&t===this.lastUpdatedSystemId&&n===this.lastSeatConfigKey&&r===this.lastProbeVersion&&i===this.lastHostReadVersion){this.clock.seeked=!1;return}let a=this.clock.seeked;this.clock.seeked=!1,this.lastUpdatedJd=this.clock.jd,this.lastUpdatedSystemId=t,this.lastSeatConfigKey=n,this.lastProbeVersion=r,this.lastHostReadVersion=i,this.ctx.refreshTick(Ng(this.clock.jd)),this.focusController.promotion.onSimTimeChanged();let o=kI({jd:this.clock.jd,ctx:this.ctx,bodyObjects:this.bodyObjects,focus:this.focus,focusedBody:this.focusController.current,positionMap:this._positionMapScratch,diagnostics:this.positionDiagnostics,trailView:this.trailView(),frame:this.frameIndex,outOfRange:this.outOfRange});this.pointClouds.updateForJd(this.clock.jd,this.cloudViewInfo()),this.refreshTravelFocus(),performance.now()-this.focus.focusStartTime>=this.focus.focusDurationMs&&(this.repositionBodies(),this.pointClouds.maybeRebase()),this.syncLandedNomenclature();let s=o.focusedOutOfRange&&!this.focusWasOutOfRange;if(this.focusWasOutOfRange=o.focusedOutOfRange,e&&a&&s&&o.reanchorId){let e=this.ctx.getBody(o.reanchorId);e&&this.focusController.panCameraToBody(e)}}setReducedMotion(e){this.controls.dampingFactor=TR(e)}focusOnBody(e,t,n,r){return this.disarmLimits(),this.applyJdUpdate(),this.focusWasOutOfRange=!1,this.focusController.focusOnBody(e,t,n,r)}focusOnFeature(e,t,n,r=`frame`,i){this.disarmLimits(),this.applyJdUpdate(),this.focusWasOutOfRange=!1;let a=this.ctx.getBody(e.hostId);if(!a)return 0;this.focusController.clearPendingInitialView();let o=CM(this.focusController.current,this.bodyObjects)===e.hostId,s=Nw(e,t);this.ctx.bodies.focusFeature=s;let c=this.bodyObjects.get(a.data.id);this.selectedFeatureId=e.featureId,c&&FM(c,e.featureId),Bw(s,a,c,this.clock.jd);let l=s.position,u=this.focusController.focusedBodyQuat(s);if(r===`pan`){let e=iC(this.focusController.cameraTruePos(),l,u);return this.callbacks.onCameraPosition?.(e.latitude,e.longitude,e.distance),this.focusController.setFocusTarget(s),this.focus.focusDurationMs}let d=l[0]-a.position[0],f=l[1]-a.position[1],p=l[2]-a.position[2],m=Math.hypot(d,f,p);m>1e-9?(d/=m,f/=m,p/=m):(d=0,f=1,p=0);let h=r===`snap`&&i?aC(l,i.latitude,i.longitude,i.zoom,u):[l[0]+d*n,l[1]+f*n,l[2]+p*n],g=iC(h,l,u);if(this.callbacks.onCameraPosition?.(g.latitude,g.longitude,g.distance),r===`snap`){this.focusController.setFocusTarget(s,h);let e=this.focus;return e.focusTruePos=[...l],e.focusOriginWorld=[...l],e.focusTargetWorld=[...l],e.focusStartTime=-IL,e.camOriginWorld=null,e.camTargetWorld=null,e.camTargetOffset=null,e.camOriginOffset=null,e.flyQ0=null,e.orbitFly=!1,e.arcOrbit=!1,e.cameraStaysOnBody=!1,this.repositionAll(),this.pointClouds.rebuildBasis(),this.camera.position.set(h[0]-l[0],h[1]-l[1],h[2]-l[2]),this.controls.update(),0}if(o){let e=this.focusController.cameraTruePos();this.focusController.setFocusTarget(s),this.focus.focusTruePos=[...l],this.camera.position.set(e[0]-l[0],e[1]-l[1],e[2]-l[2]),this.repositionAll(),this.pointClouds.rebuildBasis(),qL(this.focus,this.camera,e,h,jx().resolvedReducedMotion)}else this.focusController.setFocusTarget(s,h),this.focus.orbitFly=!0;return this.focus.focusDurationMs}pickFocusedModel(e,t){if(!this.overlayActive||!this.overlayModelBo()?.model)return null;this._pickNdc.set(e,t),this._modelRaycaster.setFromCamera(this._pickNdc,this.modelCamera);let n=null,r=1/0;for(let e of this.bodyObjects.values()){if(!e.model)continue;let t=this._modelRaycaster.intersectObject(e.model,!0);t.length>0&&t[0].distance<r&&(r=t[0].distance,n=e.body)}return n}overlayModelBo(){let e=this.focusController.current;if(!e){let e=this.travelFocus?.centerId,t=e?this.bodyObjects.get(e):void 0;return t?.model?t:null}let t=cn(e)?e.featureAnchor.hostId:e.data.id,n=this.bodyObjects.get(t);if(n?.model)return n;if(e.data.orbitalSource===W.SPICE_PROBE&&!n?.isLanded){let t=this.bodyObjects.get(e.data.parentId);if(t?.model)return t}return null}snapToBodyFacing(e,t,n,r){this.disarmLimits(),this.focusController.snapToBodyFacing(e,t,n,r)}snapToBody(e,t,n,r){this.disarmLimits(),this.focusController.snapToBody(e,t,n,r)}setFocusTarget(e,t){this.disarmLimits(),this.applyJdUpdate(),this.focusWasOutOfRange=!1,this.focusController.setFocusTarget(e,t)}getFocusedBody(){return this.focusController.current}getDebugStats(){let t=this.fpsSamples,n=0;if(t.length>=2){let r=t.length<e.FPS_SAMPLE_FRAMES?0:this.fpsSampleHead,i=t[r],a=(t[(r-1+t.length)%t.length]-i)/1e3;a>0&&(n=(t.length-1)/a)}return sP({fps:n,orbitPool:this.pointClouds.orbitPool,renderer:this.renderer,bodyObjects:this.bodyObjects,focusedBody:this.focusController.current,cameraDistanceScene:this.getCameraState().distance})}setBodyAppearance(e,t){this.appearances.set(e,t)}setPinnedBodies(e){this.ctx.visibility.setPinned(e),this.focusController.promotion.setPinned(e)}setNorthReference(e){this.cameraUp.setNorthReference(e)}getFocusedPointing(){let e=this.focusController.current;if(!e)return null;let t=e.pointing??{primary:{axis:`-y`,target:`parent`}};return{supported:QD(e),base:t}}setFocusedPointing(e){let t=this.focusController.current;t&&(t.pointingOverride=e??void 0)}setPointingAxesVisible(e){this.showPointingAxes=e}buildPointingAxes(){let e=new Ra,t=new J(0,0,0),n=(n,r,i,a)=>{let o=new Wd(n,t,1,r,.22,.12);o.line.material.depthTest=!1,o.cone.material.depthTest=!1,o.renderOrder=999,e.add(o);let s=this.makeAxisLabel(i,a);s.position.copy(n).multiplyScalar(1.12),e.add(s)};return n(new J(1,0,0),16729156,`+X`,`#ff9999`),n(new J(-1,0,0),8930372,`-X`,`#cc7777`),n(new J(0,1,0),4521796,`+Y`,`#99ff99`),n(new J(0,-1,0),4491332,`-Y`,`#77cc77`),n(new J(0,0,1),4491519,`+Z`,`#99bbff`),n(new J(0,0,-1),4478344,`-Z`,`#7799cc`),e}makeAxisLabel(e,t){let n=document.createElement(`canvas`);n.width=n.height=128;let r=n.getContext(`2d`);r.font=`bold 72px sans-serif`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillStyle=t,r.fillText(e,128/2,128/2);let i=new ss(new qo({map:new Mc(n),depthTest:!1,transparent:!0}));return i.scale.setScalar(.175),i.renderOrder=1e3,i}sunIntensityScale=1;getSunIntensityScale(){return this.sunIntensityScale}setSunIntensityScale(e){this.sunIntensityScale=e}getFocusedAtmosphere(){let e=this.focusController.current?.data.id;if(!e)return null;let t=this.bodyObjects.get(e)?.atmosphere,n=gb(e);return!t||!n?null:{id:e,current:t.params,shipped:n}}setFocusedAtmosphereParams(e){let t=this.focusController.current?.data.id,n=t?this.bodyObjects.get(t)?.atmosphere:void 0;n&&MA(n,e)}getSkyboxAdjust(){return this.skyboxAdjuster.get()}setSkyboxAdjust(e,t,n){this.skyboxAdjuster.set(e,t,n)}setSkyDebugMarkersVisible(e){this.skyDebugMarkers.setVisible(e)}applyLayerChrome(){this.ctx.layers.isVisible(`stars`)?this.stashedSky&&=(this.scene.background=this.stashedSky,null):this.scene.background&&(this.stashedSky=this.scene.background,this.scene.background=null);let e=this.ctx.layers.isVisible(`labels`);e!==this.namesShown&&(this.namesShown=e,this.labelContainer.classList.toggle(`scene-overlay--no-names`,!e));let t=this.ctx.layers.isVisible(`halos`);t!==this.halosShown&&(this.halosShown=t,this.labelContainer.classList.toggle(`scene-overlay--no-halos`,!t))}setHaloDebugVisible(e){this.haloDebug.setVisible(e)}setUserLocation(e,t){let n=this.bodyObjects.get(f_);n?.mesh&&(this.userLocationMarker&&jR(this.userLocationMarker),this.userLocationMarker=AR(n.mesh,n.radiusScene,e,t))}clearUserLocation(){this.userLocationMarker&&=(jR(this.userLocationMarker),null)}pause(){this.paused||(this.paused=!0,cancelAnimationFrame(this.rafId),this.rafId=0)}resume(){this.paused&&(this.paused=!1,this.invalidate(),this.tick())}setCovered(e){this.covered!==e&&(this.covered=e,e||this.invalidate())}isContextLost(){return this.renderer.getContext().isContextLost()}handleContextRestored(){this.renderer.setPixelRatio(Yx()),this.composer.setPixelRatio(Yx()),this.resize(this.canvas.clientWidth,this.canvas.clientHeight),fS(this.scene,this.renderer,this.ctx,()=>this.disposed),this.resume()}recoverWorkersIfDead(e){return this.pointClouds.recoverWorkersIfDead(e)}applyRenderTier(){this.tier=Jx();let e=Yx();e!==this.renderer.getPixelRatio()&&(this.renderer.setPixelRatio(e),this.composer.setPixelRatio(e),this.resize(this.canvas.clientWidth,this.canvas.clientHeight)),this.pointClouds.setPointBudget(this.tier.pointBudget)}resize(e,t){this.invalidate(),this.viewportH=t||1,this.renderer.setSize(e,t,!1),this.composer.setSize(e,t);let n=this.renderer.getDrawingBufferSize(new q);this.atmoDepthPass.setSize(n.x,n.y),this.bloomPass.setSize(e*this.tier.bloomScale,t*this.tier.bloomScale),this.labelRenderer.setSize(e,t),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.ctx.visibility.updateViewport(t),mT(e,t)}dispose(){this.disposed=!0,cancelAnimationFrame(this.rafId),this.pointerInteraction.detach(),this.gpuPick.dispose(),this.controls.removeEventListener(`end`,this.onControlsEnd),this.controls.removeEventListener(`start`,this.invalidate),this.controls.removeEventListener(`start`,this.armLimits),this.controls.removeEventListener(`end`,this.invalidate);for(let t of e.INPUT_EVENTS)this.canvas.removeEventListener(t,this.invalidate);window.removeEventListener(`keydown`,this.invalidate),this.unsubscribeBodiesAdded?.(),this.controls.dispose(),this.haloDebug.dispose(),this.travelPath.dispose(),this.extensions.dispose();for(let e of this.bodyObjects.values())e.model&&dO(e);this.pointClouds.dispose(),this.disposeScene(this.scene),this.disposeScene(this.modelScene),YR(this.scene.background),YR(this.scene.environment),YR(this.modelScene.environment),this.circleTexture.dispose(),this.bodyObjects.clear(),this.composer.dispose(),this.atmoDepthPass.dispose(),this.renderer.dispose()}disposeScene(e){let t=new Set;e.traverse(e=>{let n=e;n.geometry?.dispose();let r=n.material,i=Array.isArray(r)?r:r?[r]:[];for(let e of i)if(!t.has(e)){t.add(e);for(let t of Object.values(e))YR(t);e.dispose()}})}};function YR(e){e&&typeof e==`object`&&e.isTexture&&e.dispose()}var XR=Ze({progress:null,bootPending:!1}),ZR=6371;function QR(e){let t=[];for(let n=0;n<128;n++){let r=Math.PI*(n/127)**2,i=Math.cos(r);t.push(1/(4*Math.PI)*(1-e*e)/(1+e*e-2*e*i)**1.5)}return[...t,...t,...t]}var $R={topAltitudeKm:67,rayleighScatterPerKm:[.0058,.0136,.0331],rayleighScaleHeightKm:8.4,mieScatterPerKm:[.004,.004,.004],mieAbsorptionPerKm:[4e-4,4e-4,4e-4],mieScaleHeightKm:1.2,miePhase:QR(.75),absorptionPerKm:[65e-5,.001881,85e-6],absorptionCenterKm:25,absorptionWidthKm:15,bakedCompensation:1,multiScatterGain:.3,sunIntensity:5,sunColor:[1,1,1]},ez=1.6,tz=1.0005,nz=new J(.55,.25,.8).normalize(),rz=[`low`,`medium`,`high`,`ultra`],iz=4,az=12,oz=10,sz=16,cz=5;function lz(e){return!e.limb&&!e.sky?NaN:Math.max(e.limb?.medianMs??0,e.sky?.medianMs??0)}function uz(e,t){let n=`low`;for(let r of e.tiers){let e=lz(r);!Number.isNaN(e)&&e<=t&&(n=r.tier)}return n}var dz=new Set([`WebKit WebGL`,`Mozilla`,``]);function fz(e){let t=e.getContext(),n=String(t.getParameter(t.RENDERER)??``);if(!dz.has(n))return n;let r=t.getExtension(`WEBGL_debug_renderer_info`);return r?String(t.getParameter(r.UNMASKED_RENDERER_WEBGL)):n}function pz(e,t){let n=e.getContext(),r=new Ka,i=new od(50,n.drawingBufferWidth/Math.max(n.drawingBufferHeight,1),.005,100),a=new pu({color:7829367,roughness:1,metalness:0}),o=new ks(new nu(1,64,64),a);o.renderOrder=1,r.add(o);let s=new pd(16777215,2);s.position.copy(nz),r.add(s);let c=$R,l=wA(c,1,ZR),u=l.material.uniforms;u.uSunDir.value.copy(nz),u.uSunIntensity.value=c.sunIntensity,r.add(l.mesh);let d=e=>{let t=e===`sky`;t?(i.position.set(0,tz,0),i.lookAt(1,tz+.1,0)):(i.position.set(0,0,ez),i.lookAt(0,0,0)),l.material.side=+!!t,l.material.depthWrite=!t,l.material.depthTest=!t},f=new Uint8Array(4),p=()=>new Promise((e,n)=>requestAnimationFrame(()=>t?.aborted?n(Error(`benchmark aborted`)):e())),m=t=>{let a=performance.now();for(let n=0;n<t;n++)e.render(r,i);return n.readPixels(0,0,1,1,n.RGBA,n.UNSIGNED_BYTE,f),(performance.now()-a)/t};return{measure:async(e,t,{decideMs:n,onFrame:r}={})=>{jA(l,Bk[e]),d(t);let i=0;for(let e=0;e<iz;e++)r?.(`warmup`,e+1),await p(),i=m(1);let a=Math.min(sz,Math.max(1,Math.ceil(oz/Math.max(i,.25)))),o=[],s=()=>{let e=[...o].sort((e,t)=>e-t);return{medianMs:e[Math.floor(e.length/2)],p75Ms:e[Math.floor(e.length*.75)]}};for(let e=0;e<az;e++)if(r?.(`measure`,e+1),await p(),o.push(m(a)),n!==void 0&&o.length>=cz){let{medianMs:e,p75Ms:t}=s();if(e>n*1.4||t<n*.7)break}return{...s(),repeats:a}},dispose:()=>{r.remove(o,s,l.mesh),o.geometry.dispose(),a.dispose(),s.dispose(),FA(l)}}}function mz(e,t,n,r){let i=e.getContext();return{tiers:t.map(e=>{let t=n.get(e)??null,i=r.get(e)??null;return{tier:e,limb:t,sky:i,skipped:!t&&!i}}),drawWidth:i.drawingBufferWidth,drawHeight:i.drawingBufferHeight}}async function hz(e,t){let n=t.tiers??rz,{budgetMs:r,signal:i,onProgress:a}=t,o=Math.max(0,n.indexOf(t.startTier??n[n.length-1])),s=pz(e,i),c=iz+az,l=0,u=0,d=(e,t,i)=>s.measure(n[e],t,{decideMs:r,onFrame:(r,o)=>{if(!a)return;l++;let s=c-((r===`measure`?iz:0)+o)+i*c;u=Math.max(u,l/(l+s)),a({tier:n[e],tierIndex:e,tierCount:n.length,scenario:t,phase:r,frame:o,frames:r===`measure`?az:iz,fraction:u})}}),f=new Map,p=new Map,m=async e=>{let t=n[e];if(Bk[t].insideView){let n=await d(e,`sky`,1);if(p.set(t,n),n.medianMs>r)return!1}let i=await d(e,`limb`,0);return f.set(t,i),i.medianMs<=r};try{if(await m(o))for(let e=o+1;e<n.length&&await m(e);e++);else for(let e=o-1;e>=1&&!await m(e);e--);}finally{s.dispose()}return mz(e,n,f,p)}var gz=60,_z=100,vz=3e4,yz=25e4,bz=`v1`,xz=!1,Sz=null,Cz=Promise.resolve();function wz(e){let t=e.getContext(),n=Math.round(t.drawingBufferWidth*t.drawingBufferHeight/yz);return`${fz(e)}|${n}|${bz}`}function Tz(){xz||typeof window>`u`||(xz=!0,XR.bootPending=!0,Cz=new Promise(e=>{let t=()=>{XR.bootPending=!1,e()};setTimeout(t,vz),setTimeout(()=>void Dz(!1).finally(t),_z)}))}function Ez(){return Cz}function Dz(e){return Sz??=Oz(e).finally(()=>Sz=null),Sz}async function Oz(e){let t=jx();if(!e&&(t.atmosphereQuality!==`auto`||!t.showAtmospheres))return;let n=null;try{n=new uh({canvas:document.createElement(`canvas`),antialias:!0}),n.setPixelRatio(Wx()),n.setSize(window.innerWidth,window.innerHeight,!1);let r=wz(n);if(!e&&t.atmosphereCalibration?.key===r)return;XR.progress=0;let i=await hz(n,{budgetMs:1e3/gz,startTier:Vk(),onProgress:e=>XR.progress=e.fraction}),a={};for(let e of i.tiers){let t=lz(e);Number.isNaN(t)||(a[e.tier]=Math.round(t*100)/100)}let o=uz(i,1e3/gz);t.setAtmosphereCalibration({key:r,tier:o,worstMs:a}),t.setAtmosphereAutoTier(null),console.info(`atmosphere calibration: ${o}`,a)}catch(e){console.warn(`atmosphere calibration failed, keeping heuristic tier`,e)}finally{XR.progress=null,n?.dispose(),n?.forceContextLoss()}}var kz=class{object=new Ra;element;label;anchor;occlude;wanted=!0;removeSelf=null;constructor(e,t){this.anchor=e.anchor,this.occlude=e.occlude??!1,this.element=e.element,this.label=new tk(e.element);let[n,r]=e.align??[.5,.5];this.label.center.set(n,r),this.object.add(this.label),this.object.matrixAutoUpdate=!1,Rk(e.element,t)}bind(e){this.removeSelf=e}setAnchor(e){this.anchor=e}setVisible(e){this.wanted=e}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){let{jd:t,basis:n,ctx:r}=e,i=this.wanted?yR(this.anchor,r,t):null;if(!i){this.label.visible=!1;return}let a=i[0]-n[0],o=i[1]-n[1],s=i[2]-n[2];this.label.position.set(a,o,s),this.label.visible=this.occlude?this.facesCamera(i,e):!0,this.object.updateMatrixWorld(!0)}facesCamera(e,{camera:t,ctx:n,jd:r}){let i=bR(this.anchor,e,n,r);if(!i)return!0;let{position:a}=this.label,o=t.position.x-a.x,s=t.position.y-a.y,c=t.position.z-a.z;return i[0]*o+i[1]*s+i[2]*c>0}dispose(){this.label.removeFromParent(),this.element.remove()}},Az=3,jz=new J,Mz=new J,Nz=new J;function Pz(e){let[t,n=t]=(e??``).split(/[\s,]+/).filter(Boolean).map(Number);return t>0&&n>0?[t,n]:null}function Fz(e,t){return jz.set(1,0,0).applyQuaternion(e.quaternion),Mz.set(0,1,0).applyQuaternion(e.quaternion),Nz.set(0,0,-1).applyQuaternion(e.quaternion),t/(2*Math.tan(e.getEffectiveFOV()*Math.PI/360))}function Iz(e,t,n,r){let i=e[t*3]-n.position.x,a=e[t*3+1]-n.position.y,o=e[t*3+2]-n.position.z;r[0]=i*jz.x+a*jz.y+o*jz.z,r[1]=i*Mz.x+a*Mz.y+o*Mz.z,r[2]=i*Nz.x+a*Nz.y+o*Nz.z}function Lz(e,t,n){Nz.set(0,0,-1).applyQuaternion(n.quaternion);let{x:r,y:i,z:a}=n.position;for(let o=0;o<t;o++)if((e[o*3]-r)*Nz.x+(e[o*3+1]-i)*Nz.y+(e[o*3+2]-a)*Nz.z<n.near*2)return!0;return!1}function Rz(e,t,n,r,i){let a=Fz(n,r),o=[0,0,0],s=0,c=0,l=0,u=!1;for(let r=0;r<t;r++){if(Iz(e,r,n,o),o[2]>n.near){let e=o[0]/o[2]*a,t=o[1]/o[2]*a;u&&(s+=Math.hypot(e-c,t-l)),c=e,l=t,u=!0}i[r]=s}}var zz=class{points=new Float32Array;alphas=new Float32Array;lengths=new Float32Array;count=0;a=[0,0,0];b=[0,0,0];see(e,t,n,r,i){this.alphas.length<n*4&&(this.points=new Float32Array(n*12),this.alphas=new Float32Array(n*4),this.lengths=new Float32Array(n*4)),this.count=0;let a=Fz(r,i),o=i*r.aspect*Az/2,s=i*Az/2,c=r.near*2,{a:l,b:u}=this,d=!1,f=0,p=0,m=0;n>0&&Iz(e,0,r,l);for(let i=0;i+1<n;i++,[l,u]=[u,l]){Iz(e,i+1,r,u);let n=0,h=1;for(let e=0;e<5&&n<=h;e++){let t=Bz(e,l,a,o,s,c),r=Bz(e,u,a,o,s,c);t<0&&r<0?h=-1:t<0?n=Math.max(n,t/(t-r)):r<0&&(h=Math.min(h,t/(t-r)))}if(n>h){d=!1;continue}let g=l[2]+(u[2]-l[2])*n,_=(l[0]+(u[0]-l[0])*n)/g*a,v=(l[1]+(u[1]-l[1])*n)/g*a;(!d||n>0)&&(this.count>0&&(this.copy(this.count-1,0),this.put(e,t,i,n,f,0)),this.put(e,t,i,n,f,1),p=_,m=v);let y=l[2]+(u[2]-l[2])*h,b=(l[0]+(u[0]-l[0])*h)/y*a,x=(l[1]+(u[1]-l[1])*h)/y*a;f+=Math.hypot(b-p,x-m),p=b,m=x,this.put(e,t,i,h,f,1),d=h===1}}put(e,t,n,r,i,a){let o=this.count++;for(let t=0;t<3;t++){let i=e[n*3+t];this.points[o*3+t]=i+(e[n*3+3+t]-i)*r}this.alphas[o]=(t[n]+(t[n+1]-t[n])*r)*a,this.lengths[o]=i}copy(e,t){let n=this.count++;this.points.copyWithin(n*3,e*3,e*3+3),this.alphas[n]=this.alphas[e]*t,this.lengths[n]=this.lengths[e]}};function Bz(e,t,n,r,i,a){return e===0?t[2]-a:e===1?r*t[2]-n*t[0]:e===2?r*t[2]+n*t[0]:e===3?i*t[2]-n*t[1]:i*t[2]+n*t[1]}var Vz=1e-9,Hz=class{object=new Ra;anchor;color;widthPx;opacity;dash;fade;closed;local;count=0;mesh=null;scratch=new Float32Array;alphas=new Float32Array;seen=new zz;capacity=0;lastOrigin=[0,0,0];dirty=!0;wanted=!0;removeSelf=null;constructor(e){this.anchor=e.anchor,this.color=e.color??`#ffffff`,this.widthPx=e.widthPx??2,this.opacity=e.opacity??1,this.dash=Pz(e.dash),this.fade=e.fade??!1,this.closed=e.closed??!1,this.local=new Float64Array,this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){let t=e.length+(this.closed&&e.length>2?1:0);this.local.length<t*3&&(this.local=new Float64Array(t*3));for(let t=0;t<e.length;t++){let[n,r,i]=e[t];this.local[t*3]=Q(n),this.local[t*3+1]=Q(i),this.local[t*3+2]=Q(-r)}t>e.length&&this.local.copyWithin(e.length*3,0,3),this.count=t,this.alphas.length<t&&(this.scratch=new Float32Array(t*3),this.alphas=new Float32Array(t)),t>this.capacity&&this.rebuild(t),this.fillAlphas(),this.dirty=!0}fillAlphas(){let e=this.count;for(let t=0;t<e;t++)this.alphas[t]=this.fade&&e>1?this.opacity*(1-t/(e-1)):this.opacity}setAnchor(e){this.anchor=e}setVisible(e){this.wanted=e}remove(){this.removeSelf?.(),this.removeSelf=null}update({jd:e,basis:t,camera:n,viewportPx:r,ctx:i}){let a=this.wanted&&this.count>=2?yR(this.anchor,i,e):null;if(this.mesh&&(this.mesh.visible=a!==null),!this.mesh||!a)return;let o=[a[0]-t[0],a[1]-t[1],a[2]-t[2]],s=this.dirty||Math.abs(o[0]-this.lastOrigin[0])>Vz||Math.abs(o[1]-this.lastOrigin[1])>Vz||Math.abs(o[2]-this.lastOrigin[2])>Vz;if(s){for(let e=0;e<this.count*3;e++)this.scratch[e]=this.local[e]+o[e%3];this.lastOrigin=o}let c=this.dash!==null||Lz(this.scratch,this.count,n);if(c){let{seen:e}=this;e.see(this.scratch,this.alphas,this.count,n,r),e.count>this.capacity&&this.rebuild(e.count),dN(this.mesh.geometry,e.points,e.alphas,e.alphas,e.count),this.dash&&mN(this.mesh.geometry,e.lengths,e.count)}else s&&dN(this.mesh.geometry,this.scratch,this.alphas,this.alphas,this.count);this.dirty=c,this.mesh.material.uniforms.uCenterOffset.value.copy(n.position).negate()}rebuild(e){this.disposeMesh(),this.dirty=!0;let t=hN(e,this.scratch,this.alphas,this.alphas,0,this.color,this.widthPx,1,this.dash??void 0);t.frustumCulled=!1,this.object.add(t),this.mesh=t,this.capacity=e}disposeMesh(){let e=this.mesh;e&&(this.object.remove(e),e.geometry.dispose(),e.material.dispose(),this.mesh=null)}dispose(){this.disposeMesh()}};function Uz(e){let t=Math.hypot(e[0],e[1],e[2]),n=t>0?[e[0]/t,e[1]/t,e[2]/t]:[0,0,1],r=Wz(Math.abs(n[2])<.9?[0,0,1]:[1,0,0],n),i=Math.hypot(r[0],r[1],r[2]),a=[r[0]/i,r[1]/i,r[2]/i];return[a,Wz(n,a)]}function Wz(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function Gz(e,t={}){let[n,r]=Uz(t.normal??[0,0,1]),i=Math.max(3,Math.round(t.steps??128)),a=[];for(let t=0;t<i;t++){let o=2*Math.PI*t/i,s=Math.cos(o)*e,c=Math.sin(o)*e;a.push([n[0]*s+r[0]*c,n[1]*s+r[1]*c,n[2]*s+r[2]*c])}return a}function Kz(e){if(e.length<3)return[];let[t,n]=Uz(qz(e)),r=e.map(e=>new q(e[0]*t[0]+e[1]*t[1]+e[2]*t[2],e[0]*n[0]+e[1]*n[1]+e[2]*n[2]));return Yl.triangulateShape(r,[]).flat()}function qz(e){let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i],o=e[(i+1)%e.length];t+=(a[1]-o[1])*(a[2]+o[2]),n+=(a[2]-o[2])*(a[0]+o[0]),r+=(a[0]-o[0])*(a[1]+o[1])}return Math.hypot(t,n,r)>0?[t,n,r]:[0,0,1]}function Jz(e,t,n){let r=Math.min(1,Math.max(-1,e[0]*t[0]+e[1]*t[1]+e[2]*t[2])),i=Math.acos(r);if(i<1e-9||Math.PI-i<1e-9)return Yz([e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]);let a=Math.sin(i),o=Math.sin((1-n)*i)/a,s=Math.sin(n*i)/a;return[e[0]*o+t[0]*s,e[1]*o+t[1]*s,e[2]*o+t[2]*s]}function Yz(e){let t=Math.hypot(e[0],e[1],e[2]);return t>0?[e[0]/t,e[1]/t,e[2]/t]:[0,0,1]}function Xz(e,t){let n=0,r=0,i=0;for(let a=0;a<t;a++)n+=e[a*3],r+=e[a*3+1],i+=e[a*3+2];return Math.hypot(n,r,i)<1e-9?[e[0],e[1],e[2]]:Yz([n,r,i])}function Zz(e,t){return new du({transparent:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:new X(e)},uOpacity:{value:t},uCenterOffset:{value:new J}},vertexShader:`
5550
+ `;let i=document.createElement(`span`);return i.textContent=e.label,i.style.color=e.color,i.style.marginInlineStart=`2px`,t.appendChild(n),t.appendChild(i),t}function WN(e,t,n,r,i){let a=new J().crossVectors(t,e).normalize(),o=new Float32Array(i*3),s=new J;for(let t=0;t<i;t++){let r=t/i*Math.PI*2,c=Math.cos(r),l=Math.sin(r);s.copy(e).multiplyScalar(c).addScaledVector(a,l).multiplyScalar(n),o[t*3]=s.x,o[t*3+1]=s.y,o[t*3+2]=s.z}let c=new Vo;c.setAttribute(`position`,new ko(o,3));let l=new Cc(c,new uc({color:r,transparent:!0,opacity:.55}));return l.frustumCulled=!1,l}function GN(){let e=new Ra;e.name=`sky-debug-markers`,e.visible=!1;let t=new J;for(let n of FN){HN(n.raDeg,n.decDeg,t).multiplyScalar(PN);let r=new tk(UN(n));r.center.set(0,.5),r.position.copy(t),e.add(r)}for(let t of VN){let n=WN(t.zero,t.pole,PN*.999,t.color,BN);n.name=t.name,e.add(n)}return e}function KN(e){e.traverse(e=>{e instanceof tk&&e.element.remove(),e instanceof Cc&&(e.geometry.dispose(),e.material.dispose())}),e.parent?.remove(e)}var qN=class{group=null;constructor(e){this.scene=e}setVisible(e){e?(this.group||(this.group=GN(),this.scene.add(this.group)),this.group.visible=!0):this.group&&=(KN(this.group),null)}},JN=new J,YN=new J,XN=new J,ZN=[JN,YN,XN];function QN(e,t,n){return JN.set(1,0,0).applyQuaternion(e).transformDirection(t),YN.set(0,1,0).applyQuaternion(e).transformDirection(t),XN.set(0,0,1).applyQuaternion(e).transformDirection(t),{e:ZN,a:n}}function $N(e,t,n,r,i,a,o,s,c,l){let u=1/i;e.gxx=u,e.gxy=0,e.gxz=0,e.gyx=0,e.gyy=u,e.gyz=0,e.gzx=0,e.gzy=0,e.gzz=u,e.cpx=t*u,e.cpy=n*u,e.cpz=r*u,e.K=(t*t+n*n+r*r)*u*u-1,e.cx0=o,e.cy0=s,e.f=a,e.id=c,e.dist=l,e.ccx=t,e.ccy=n,e.ccz=r}function eP(e,t,n,r,i,a,o,s,c,l){let[u,d,f]=i.e,[p,m,h]=i.a;e.gxx=u.x/p,e.gxy=u.y/p,e.gxz=u.z/p,e.gyx=d.x/m,e.gyy=d.y/m,e.gyz=d.z/m,e.gzx=f.x/h,e.gzy=f.y/h,e.gzz=f.z/h;let g=(t*u.x+n*u.y+r*u.z)/p,_=(t*d.x+n*d.y+r*d.z)/m,v=(t*f.x+n*f.y+r*f.z)/h;e.cpx=g,e.cpy=_,e.cpz=v,e.K=g*g+_*_+v*v-1,e.cx0=o,e.cy0=s,e.f=a,e.id=c,e.dist=l,e.ccx=t,e.ccy=n,e.ccz=r}function tP(e,t,n,r,i,a){let[o,s,c]=r.e,[l,u,d]=r.a,f=1/(l*l),p=1/(u*u),m=1/(d*d),h=f*o.x*o.x+p*s.x*s.x+m*c.x*c.x,g=f*o.x*o.y+p*s.x*s.y+m*c.x*c.y,_=f*o.x*o.z+p*s.x*s.z+m*c.x*c.z,v=f*o.y*o.y+p*s.y*s.y+m*c.y*c.y,y=f*o.y*o.z+p*s.y*s.z+m*c.y*c.z,b=f*o.z*o.z+p*s.z*s.z+m*c.z*c.z,x=h*e+g*t+_*n,S=g*e+v*t+y*n,C=_*e+y*t+b*n,w=e*x+t*S+n*C-1,T=i,E=w*h-x*x,D=2*(w*g-x*S),O=w*v-S*S,k=-2*T*(w*_-x*C),A=-2*T*(w*y-S*C),j=4*E*O-D*D,M=(-2*O*k+D*A)/j,ee=(-2*E*A+D*k)/j,N=-n/T;a.ox=M*N-e,a.oy=ee*N-t}var nP=class{canvas=null;gfx=null;tmp=new J;tmpQ=new Vi;items=[];one=[];labelRect={x:0,left:0,right:0,y:0,h:0};constructor(e){this.anchor=e}get active(){return this.canvas!==null}setVisible(e){if(e){if(this.canvas)return;let e=document.createElement(`canvas`);e.style.cssText=`position:absolute;inset:0;width:100%;height:100%;pointer-events:none;z-index:5`,this.anchor.parentElement?.appendChild(e),this.canvas=e,this.gfx=e.getContext(`2d`)}else this.canvas&&(this.canvas.remove(),this.canvas=null,this.gfx=null)}draw(e,t,n,r,i,a){let o=this.gfx,s=this.canvas;if(!o||!s)return;let c=window.devicePixelRatio||1,l=Math.round(i*c),u=Math.round(a*c);(s.width!==l||s.height!==u)&&(s.width=l,s.height=u),o.setTransform(c,0,0,c,0,0),o.clearRect(0,0,i,a),o.font=`10px monospace`,o.textBaseline=`middle`;let d=t.fov*Math.PI/180,f=a/(2*Math.tan(d/2)),p=t.matrixWorldInverse,[m,h,g]=n,_=i*.5,v=a*.5,y=0;for(let o of e.values()){let{label:e,group:s,radiusScene:c}=o;if(!e||c<=0)continue;let[l,u,d]=o.body.position;this.tmp.set(l-m,u-h,d-g).applyMatrix4(p);let b=this.tmp.x,x=this.tmp.y,S=this.tmp.z;if(S>=0||b*b+x*x+S*S<=c*c)continue;let C=rk(this.items,y++,rP),w=!!(o.semiAxesScene&&o.mesh);if(w){let e=QN(o.mesh.getWorldQuaternion(this.tmpQ),p,o.semiAxesScene);C.e0.copy(e.e[0]),C.e1.copy(e.e[1]),C.e2.copy(e.e[2]),C.sa[0]=e.a[0],C.sa[1]=e.a[1],C.sa[2]=e.a[2],eP(C.occ,b,x,S,e,f,_,v,o.body.data.id,o.cachedDist)}else C.e0.set(1,0,0),C.e1.set(0,1,0),C.e2.set(0,0,1),C.sa[0]=C.sa[1]=C.sa[2]=c,$N(C.occ,b,x,S,c,f,_,v,o.body.data.id,o.cachedDist);let T=S*S-c*c,E=T<=0,D=E?0:c*f/Math.sqrt(T),O=E||D>=16;this.tmp.set(l-m,u-h,d-g).project(t),C.cx=(this.tmp.x*.5+.5)*i,C.cy=(-this.tmp.y*.5+.5)*a,hk(o,t,n,i,a,this.labelRect),C.hx=this.labelRect.x,C.hy=this.labelRect.y,C.id=o.body.data.id,C.camX=b,C.camY=x,C.camZ=S,C.worldR=c,C.dist=o.cachedDist,C.isEllipsoid=w,C.degenerate=E,C.isOccluder=O,C.meshHidden=!s.visible,C.labelVisible=e.visible,C.maximized=o.labelMaximized!==!1,C.focused=o.body.data.id===r,C.occludedBy=-1}for(let e=0;e<y;e++){let t=this.items[e];for(let e=0;e<y;e++){let n=this.items[e];if(!(!n.isOccluder||n.id===t.id)&&(this.one[0]=n.occ,this.one.length=1,pk(t.hx,t.hy,t.dist,t.id,this.one))){t.occludedBy=e;break}}}for(let e=0;e<y;e++){let n=this.items[e];if(n.meshHidden&&!n.isOccluder)continue;let r=n.focused?`#7dff7d`:n.isOccluder?`#ff8c1a`:n.labelVisible?n.maximized?`#1ae5ff`:`#ffe11a`:`#ff3b3b`;if(o.beginPath(),n.meshHidden&&o.setLineDash([5,4]),this.strokeLimb(o,n,t,i,a)&&(o.strokeStyle=r,o.lineWidth=n.isOccluder?2:1,o.stroke(),n.isOccluder&&(o.fillStyle=`rgba(255,140,26,0.08)`,o.fill())),o.setLineDash([]),!n.degenerate){let e=n.hx-n.cx,t=n.hy-n.cy;if(e*e+t*t>1&&(o.beginPath(),o.moveTo(n.cx,n.cy),o.lineTo(n.hx,n.hy),o.strokeStyle=`rgba(255,225,26,0.5)`,o.lineWidth=1,o.stroke(),oP(o,n.cx,n.cy,4,`#ff3ad1`)),n.occludedBy>=0){let e=this.items[n.occludedBy];o.beginPath(),o.setLineDash([4,3]),o.moveTo(n.hx,n.hy),o.lineTo(e.cx,e.cy),o.strokeStyle=`rgba(255,59,59,0.9)`,o.lineWidth=1,o.stroke(),o.setLineDash([])}o.beginPath(),o.arc(n.hx,n.hy,1.5,0,Math.PI*2),o.fillStyle=r,o.fill(),o.fillStyle=`rgba(255,255,255,0.85)`,o.fillText(n.id,n.hx+8,n.hy)}}aP(o,a)}strokeLimb(e,t,n,r,i){let{camX:a,camY:o,camZ:s,e0:c,e1:l,e2:u,sa:d}=t,f=(a*c.x+o*c.y+s*c.z)/d[0],p=(a*l.x+o*l.y+s*l.z)/d[1],m=(a*u.x+o*u.y+s*u.z)/d[2],h=f*f+p*p+m*m;if(h<=1)return!1;let g=Math.sqrt(h),_=(h-1)/h,v=Math.sqrt(h-1)/g,y=f*_,b=p*_,x=m*_,S=f/g,C=p/g,w=m/g,T=0,E=1;Math.abs(w)>.9&&(T=1,E=0);let D=C*E-w*0,O=w*T-S*E,k=S*0-C*T,A=Math.hypot(D,O,k)||1;D/=A,O/=A,k/=A;let j=C*k-w*O,M=w*D-S*k,ee=S*O-C*D,N=n.projectionMatrix.elements,te=!1;for(let t=0;t<=72;t++){let n=t/72*Math.PI*2,a=Math.cos(n),o=Math.sin(n),s=y+v*(a*D+o*j),f=b+v*(a*O+o*M),p=x+v*(a*k+o*ee),m=d[0]*s*c.x+d[1]*f*l.x+d[2]*p*u.x,h=d[0]*s*c.y+d[1]*f*l.y+d[2]*p*u.y,g=d[0]*s*c.z+d[1]*f*l.z+d[2]*p*u.z,_=N[3]*m+N[7]*h+N[11]*g+N[15];if(_<=1e-6){te=!1;continue}let S=(N[0]*m+N[4]*h+N[8]*g+N[12])/_,C=(N[1]*m+N[5]*h+N[9]*g+N[13])/_,w=(S*.5+.5)*r,T=(-C*.5+.5)*i;te?e.lineTo(w,T):(e.moveTo(w,T),te=!0)}return!0}dispose(){this.setVisible(!1)}};function rP(){return{id:``,camX:0,camY:0,camZ:0,worldR:0,e0:new J,e1:new J,e2:new J,sa:[0,0,0],occ:sk(),cx:0,cy:0,hx:0,hy:0,dist:0,isEllipsoid:!1,isOccluder:!1,degenerate:!1,meshHidden:!1,labelVisible:!1,maximized:!1,focused:!1,occludedBy:-1}}var iP=[[`#1ae5ff`,`label shown`],[`#ffe11a`,`dimmed`],[`#ff3b3b`,`hidden`],[`#ff8c1a`,`occluder silhouette`],[`#7dff7d`,`focused`]];function aP(e,t){let n=t-8-(iP.length-1)*13;e.font=`10px monospace`,e.textBaseline=`middle`;for(let[t,r]of iP)e.fillStyle=t,e.fillRect(8,n-4,8,8),e.fillStyle=`rgba(255,255,255,0.9)`,e.fillText(r,20,n),n+=13}function oP(e,t,n,r,i){e.strokeStyle=i,e.lineWidth=1,e.beginPath(),e.moveTo(t-r,n),e.lineTo(t+r,n),e.moveTo(t,n-r),e.lineTo(t,n+r),e.stroke()}function sP(e){let{fps:t,orbitPool:n,renderer:r,bodyObjects:i,focusedBody:a,cameraDistanceScene:o}=e,s=r.info;return{fps:t,workers:n.workerCount,workerGroups:n.groupCount,drawCalls:s.render.calls,triangles:s.render.triangles,geometries:s.memory.geometries,textures:s.memory.textures,programs:s.programs?.length??0,promotedBodies:i.size,focusedId:a?.data.id,focusedName:a?.data.name??void 0,cameraDistanceAU:o/10,viewportW:r.domElement.clientWidth,viewportH:r.domElement.clientHeight,pixelRatio:r.getPixelRatio()}}var cP="function e(e,t,n=1e-10,r=50){let i=e;for(let a=0;a<r;a++){let r=(i-t*Math.sin(i)-e)/(1-t*Math.cos(i));if(i-=Math.max(-1,Math.min(1,r)),Math.abs(r)<n)break}return i}function t(e,t,n=1e-10,r=50){if(e===0)return 0;let i=e<0?-1:1,a=Math.abs(e),o=0,s=1;for(;t*Math.sinh(s)-s<a;)if(s*=2,s>700)return NaN;let c=.5*(o+s);for(let e=0;e<r;e++){let e=t*Math.sinh(c)-c-a;e>0?s=c:o=c;let r=c-e/(t*Math.cosh(c)-1);r>o&&r<s||(r=.5*(o+s));let i=Math.abs(r-c);if(c=r,i<n)break}return i*c}function n(e,t,n){let r=.01720209895*(n-t)/(Math.sqrt(2)*e**1.5),i=Math.cbrt(3*r+Math.sqrt(1+9*r*r)),a=i-1/i,o=2*Math.atan(a),s=e*(1+a*a);return!isFinite(o)||!isFinite(s)||s<=0?null:{nu:o,r:s}}const r=149597870.7,i=23.4392911;86400**2/r**3,1/r,Math.cos(Math.PI/180*i),Math.sin(Math.PI/180*i);const a=Math.PI,o=a*2,s=a/180;180/a;const c=6378.135,l=60/Math.sqrt(c*c*c/398600.8),u=c*l/60,d=1/l,f=.001082616,p=-253881e-11/f,m=2/3,ee=1440/(2*a);function te(e,t){let n=[31,e%4==0?29:28,31,30,31,30,31,31,30,31,30,31],r=Math.floor(t),i=1,a=0;for(;r>a+n[i-1]&&i<12;)a+=n[i-1],i+=1;let o=i,s=r-a,c=(t-r)*24,l=Math.floor(c);c=(c-l)*60;let u=Math.floor(c);return{mon:o,day:s,hr:l,minute:u,sec:(c-u)*60}}function h(e,t,n,r,i,a,o=0){return 367*e-Math.floor(7*(e+Math.floor((t+9)/12))*.25)+Math.floor(275*t/9)+n+1721013.5+((o/6e4+a/60+i)/60+r)/24}function g(e,t,n,r,i,a,o=0){if(e instanceof Date){let t=e;return h(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds())}return h(e,t,n,r,i,a,o)}function ne(e,t){let{e3:n,ee2:r,peo:i,pgho:s,pho:c,pinco:l,plo:u,se2:d,se3:f,sgh2:p,sgh3:m,sgh4:ee,sh2:te,sh3:h,si2:g,si3:ne,sl2:_,sl3:v,sl4:y,t:b,xgh2:re,xgh3:ie,xgh4:x,xh2:ae,xh3:S,xi2:C,xi3:w,xl2:T,xl3:E,xl4:D,zmol:O,zmos:k}=e,{init:A,opsmode:j}=t,{ep:oe,inclp:M,nodep:N,argpp:se,mp:P}=t,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,le,Y,ue,de,X,fe;fe=k+119459e-10*b,A===`y`&&(fe=k),X=fe+2*.01675*Math.sin(fe),Y=Math.sin(X),U=.5*Y*Y-.25,W=-.5*Y*Math.cos(X);let pe=d*U+f*W,me=g*U+ne*W,he=_*U+v*W+y*Y,ge=p*U+m*W+ee*Y,Z=te*U+h*W;fe=O+.00015835218*b,A===`y`&&(fe=O),X=fe+2*.0549*Math.sin(fe),Y=Math.sin(X),U=.5*Y*Y-.25,W=-.5*Y*Math.cos(X);let _e=r*U+n*W,ve=C*U+w*W,ye=T*U+E*W+D*Y,be=re*U+ie*W+x*Y,xe=ae*U+S*W;return G=pe+_e,J=me+ve,le=he+ye,K=ge+be,q=Z+xe,A===`n`&&(G-=i,J-=l,le-=u,K-=s,q-=c,M+=J,oe+=G,R=Math.sin(M),L=Math.cos(M),M>=.2?(q/=R,K-=L*q,se+=K,N+=q,P+=le):(z=Math.sin(N),ce=Math.cos(N),F=R*z,I=R*ce,B=q*ce+J*L*z,V=-q*z+J*L*ce,F+=B,I+=V,N%=o,N<0&&j===`a`&&(N+=o),ue=P+se+L*N,H=le+K-J*N*R,ue+=H,de=N,N=Math.atan2(F,I),N<0&&j===`a`&&(N+=o),Math.abs(de-N)>a&&(N<de?N+=o:N-=o),P+=le,se=ue-P-L*N)),{ep:oe,inclp:M,nodep:N,argpp:se,mp:P}}function _(e){let{epoch:t,ep:n,argpp:r,tc:i,inclp:a,nodep:s,np:c}=e,l,u,d,f,p,m,ee,te,h,g,ne,_,v,y,b,re,ie,x,ae,S,C,w,T,E,D,O,k,A,j,oe,M,N,se,P,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,le,Y,ue,de,X,fe,pe,me,he,ge,Z,_e,ve,ye,be=.01675,xe=.0549,Se=c,Ce=n,we=Math.sin(s),Te=Math.cos(s),Ee=Math.sin(r),Q=Math.cos(r),De=Math.sin(a),Oe=Math.cos(a),$=Ce*Ce,ke=1-$,Ae=Math.sqrt(ke),je=t+18261.5+i/1440,Me=(4.523602-.00092422029*je)%o,Ne=Math.sin(Me),Pe=Math.cos(Me),Fe=.91375164-.03568096*Pe,Ie=Math.sqrt(1-Fe*Fe),Le=.089683511*Ne/Ie,Re=Math.sqrt(1-Le*Le),ze=5.8351514+.001944368*je,Be=.39785416*Ne/Ie,Ve=Re*Pe+.91744867*Le*Ne;Be=Math.atan2(Be,Ve),Be+=ze-Me;let He=Math.cos(Be),Ue=Math.sin(Be);S=.1945905,C=-.98088458,E=.91744867,D=.39785416,w=Te,T=we,ne=29864797e-13;let We=1/Se,Ge=0;for(;Ge<2;)Ge+=1,l=S*w+C*E*T,d=-C*w+S*E*T,ee=-S*T+C*E*w,te=C*D,h=C*T+S*E*w,g=S*D,u=Oe*ee+De*te,f=Oe*h+De*g,p=-De*ee+Oe*te,m=-De*h+Oe*g,_=l*Q+u*Ee,v=d*Q+f*Ee,y=-l*Ee+u*Q,b=-d*Ee+f*Q,re=p*Ee,ie=m*Ee,x=p*Q,ae=m*Q,_e=12*_*_-3*y*y,ve=24*_*v-6*y*b,ye=12*v*v-3*b*b,ue=3*(l*l+u*u)+_e*$,de=6*(l*d+u*f)+ve*$,X=3*(d*d+f*f)+ye*$,fe=-6*l*p+$*(-24*_*x-6*y*re),pe=-6*(l*m+d*p)+$*(-24*(v*x+_*ae)+-6*(y*ie+b*re)),me=-6*d*m+$*(-24*v*ae-6*b*ie),he=6*u*p+$*(24*_*re-6*y*x),ge=6*(f*p+u*m)+$*(24*(v*re+_*ie)-6*(b*x+y*ae)),Z=6*f*m+$*(24*v*ie-6*b*ae),ue=ue+ue+ke*_e,de=de+de+ke*ve,X=X+X+ke*ye,K=ne*We,G=-.5*K/Ae,q=K*Ae,W=-15*Ce*q,J=_*y+v*b,le=v*y+_*b,Y=v*b-_*y,Ge===1&&(O=W,k=G,A=K,j=q,oe=J,M=le,N=Y,se=ue,P=de,F=X,I=fe,L=pe,R=me,ce=he,z=ge,B=Z,V=_e,H=ve,U=ye,S=He,C=Ue,E=Fe,D=Ie,w=Re*Te+Le*we,T=we*Re-Te*Le,ne=4.7968065e-7);let Ke=(4.7199672+(.2299715*je-ze))%o,qe=(6.2565837+.017201977*je)%o,Je=2*O*M,Ye=2*O*N,Xe=2*k*L,Ze=2*k*(R-I),Qe=-2*A*P,$e=-2*A*(F-se),et=-2*A*(-21-9*$)*be,tt=2*j*H,nt=2*j*(U-V),rt=-18*j*be,it=-2*k*z,at=-2*k*(B-ce),ot=2*W*le,st=2*W*Y,ct=2*G*pe,lt=2*G*(me-fe),ut=-2*K*de,dt=-2*K*(X-ue),ft=-2*K*(-21-9*$)*xe,pt=2*q*ve,mt=2*q*(ye-_e),ht=-18*q*xe,gt=-2*G*ge,_t=-2*G*(Z-he);return{snodm:we,cnodm:Te,sinim:De,cosim:Oe,sinomm:Ee,cosomm:Q,day:je,e3:st,ee2:ot,em:Ce,emsq:$,gam:ze,peo:0,pgho:0,pho:0,pinco:0,plo:0,rtemsq:Ae,se2:Je,se3:Ye,sgh2:tt,sgh3:nt,sgh4:rt,sh2:it,sh3:at,si2:Xe,si3:Ze,sl2:Qe,sl3:$e,sl4:et,s1:W,s2:G,s3:K,s4:q,s5:J,s6:le,s7:Y,ss1:O,ss2:k,ss3:A,ss4:j,ss5:oe,ss6:M,ss7:N,sz1:se,sz2:P,sz3:F,sz11:I,sz12:L,sz13:R,sz21:ce,sz22:z,sz23:B,sz31:V,sz32:H,sz33:U,xgh2:pt,xgh3:mt,xgh4:ht,xh2:gt,xh3:_t,xi2:ct,xi3:lt,xl2:ut,xl3:dt,xl4:ft,nm:Se,z1:ue,z2:de,z3:X,z11:fe,z12:pe,z13:me,z21:he,z22:ge,z23:Z,z31:_e,z32:ve,z33:ye,zmol:Ke,zmos:qe}}function v(e){let{cosim:t,argpo:n,s1:r,s2:i,s3:s,s4:c,s5:u,sinim:d,ss1:f,ss2:p,ss3:ee,ss4:te,ss5:h,sz1:g,sz3:ne,sz11:_,sz13:v,sz21:y,sz23:b,sz31:re,sz33:ie,t:x,tc:ae,gsto:S,mo:C,mdot:w,no:T,nodeo:E,nodedot:D,xpidot:O,z1:k,z3:A,z11:j,z13:oe,z21:M,z23:N,z31:se,z33:P,ecco:F,eccsq:I}=e,{emsq:L,em:R,argpm:ce,inclm:z,mm:B,nm:V,nodem:H,irez:U,atime:W,d2201:G,d2211:K,d3210:q,d3222:J,d4410:le,d4422:Y,d5220:ue,d5232:de,d5421:X,d5433:fe,dedt:pe,didt:me,dmdt:he,dnodt:ge,domdt:Z,del1:_e,del2:ve,del3:ye,xfact:be,xlamo:xe,xli:Se,xni:Ce}=e,we,Te,Ee,Q,De,Oe,$,ke,Ae,je,Me,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue,We,Ge,Ke,qe,Je,Ye,Xe,Ze,Qe,$e,et=.0043752690880113,tt=.00015835218,nt=119459e-10;U=0,V<.0052359877&&V>.0034906585&&(U=1),V>=.00826&&V<=.00924&&R>=.5&&(U=2);let rt=f*nt*h,it=p*nt*(_+v),at=-nt*ee*(g+ne-14-6*L),ot=te*nt*(re+ie-6),st=-nt*p*(y+b);(z<.052359877||z>a-.052359877)&&(st=0),d!==0&&(st/=d);let ct=ot-t*st;pe=rt+r*tt*u,me=it+i*tt*(j+oe),he=at-tt*s*(k+A-14-6*L);let lt=c*tt*(se+P-6),ut=-tt*i*(M+N);(z<.052359877||z>a-.052359877)&&(ut=0),Z=ct+lt,ge=st,d!==0&&(Z-=t/d*ut,ge+=ut/d);let dt=(S+ae*et)%o;if(R+=pe*x,z+=me*x,ce+=Z*x,H+=ge*x,B+=he*x,U!==0){if(Ze=(V/l)**m,U===2){Qe=t*t;let e=R;R=F;let n=L;L=I,$e=R*L,Fe=-.306-(R-.64)*.44,R<=.65?(Ie=3.616-13.247*R+16.29*L,Re=-19.302+117.39*R-228.419*L+156.591*$e,ze=-18.9068+109.7927*R-214.6334*L+146.5816*$e,Be=-41.122+242.694*R-471.094*L+313.953*$e,Ve=-146.407+841.88*R-1629.014*L+1083.435*$e,He=-532.114+3017.977*R-5740.032*L+3708.276*$e):(Ie=-72.099+331.819*R-508.738*L+266.724*$e,Re=-346.844+1582.851*R-2415.925*L+1246.113*$e,ze=-342.585+1554.908*R-2366.899*L+1215.972*$e,Be=-1052.797+4758.686*R-7193.992*L+3651.957*$e,Ve=-3581.69+16178.11*R-24462.77*L+12422.52*$e,He=R>.715?-5149.66+29936.92*R-54087.36*L+31324.56*$e:1464.74-4664.75*R+3763.64*L),R<.7?(Ge=-919.2277+4988.61*R-9064.77*L+5542.21*$e,Ue=-822.71072+4568.6173*R-8491.4146*L+5337.524*$e,We=-853.666+4690.25*R-8624.77*L+5341.4*$e):(Ge=-37995.78+161616.52*R-229838.2*L+109377.94*$e,Ue=-51752.104+218913.95*R-309468.16*L+146349.42*$e,We=-40023.88+170470.89*R-242699.48*L+115605.82*$e),Ke=d*d,we=.75*(1+2*t+Qe),Te=1.5*Ke,Q=1.875*d*(1-2*t-3*Qe),De=-1.875*d*(1+2*t-3*Qe),$=35*Ke*we,ke=39.375*Ke*Ke,Ae=9.84375*d*(Ke*(1-2*t-5*Qe)+.33333333*(-2+4*t+6*Qe)),je=d*(4.92187512*Ke*(-2-4*t+10*Qe)+6.56250012*(1+2*t-3*Qe)),Me=29.53125*d*(2-8*t+Qe*(-12+8*t+10*Qe)),Ne=29.53125*d*(-2-8*t+Qe*(12+8*t-10*Qe)),Ye=V*V,Xe=Ze*Ze,Je=3*Ye*Xe,qe=Je*17891679e-13,G=qe*we*Fe,K=qe*Te*Ie,Je*=Ze,qe=Je*3.7393792e-7,q=qe*Q*Re,J=qe*De*ze,Je*=Ze,qe=2*Je*7.3636953e-9,le=qe*$*Be,Y=qe*ke*Ve,Je*=Ze,qe=Je*1.1428639e-7,ue=qe*Ae*He,de=qe*je*We,qe=2*Je*2.1765803e-9,X=qe*Me*Ue,fe=qe*Ne*Ge,xe=(C+E+E-(dt+dt))%o,be=w+he+2*(D+ge-et)-T,R=e,L=n}U===1&&(Pe=1+L*(-2.5+.8125*L),Re=1+2*L,Le=1+L*(-6+6.60937*L),we=.75*(1+t)*(1+t),Ee=.9375*d*d*(1+3*t)-.75*(1+t),Oe=1+t,Oe*=1.875*Oe*Oe,_e=3*V*V*Ze*Ze,ve=2*_e*we*Pe*17891679e-13,ye=3*_e*Oe*Le*2.2123015e-7*Ze,_e=_e*Ee*Re*21460748e-13*Ze,xe=(C+E+n-dt)%o,be=w+O+he+Z+ge-(T+et)),Se=xe,Ce=T,W=0,V=T+0}return{em:R,argpm:ce,inclm:z,mm:B,nm:V,nodem:H,irez:U,atime:W,d2201:G,d2211:K,d3210:q,d3222:J,d4410:le,d4422:Y,d5220:ue,d5232:de,d5421:X,d5433:fe,dedt:pe,didt:me,dmdt:he,dndt:0,dnodt:ge,domdt:Z,del1:_e,del2:ve,del3:ye,xfact:be,xlamo:xe,xli:Se,xni:Ce}}function y(e){let t=(e-2451545)/36525,n=-62e-7*t*t*t+.093104*t*t+3164400184.812866*t+67310.54841;return n=n*s/240%o,n<0&&(n+=o),n}function b(e,t,n,r,i,a,o){return e instanceof Date?y(g(e)):y(t===void 0?e:g(e,t,n,r,i,a,o))}function re(e){let{ecco:t,epoch:n,inclo:r,opsmode:i}=e,{no:a}=e,s=t*t,c=1-s,u=Math.sqrt(c),d=Math.cos(r),p=d*d,ee=(l/a)**m,te=.75*f*(3*p-1)/(u*c),h=te/(ee*ee),g=ee*(1-h*h-h*(1/3+134*h*h/81));h=te/(g*g),a/=1+h;let ne=(l/a)**m,_=Math.sin(r),v=ne*c,y=1-5*p,re=-y-p-p,ie=1/ne,x=v*v,ae=ne*(1-t),S;if(i===`a`){let e=n-7305,t=Math.floor(e+1e-8),r=e-t,i=.017202791694070362,a=i+o;S=(1.7321343856509375+i*t+a*r+e*e*5075514194322695e-30)%o,S<0&&(S+=o)}else S=b(n+2433281.5);return{no:a,method:`n`,ainv:ie,ao:ne,con41:re,con42:y,cosio:d,cosio2:p,eccsq:s,omeosq:c,posq:x,rp:ae,rteosq:u,sinio:_,gsto:S}}function ie(e){let{irez:t,d2201:n,d2211:r,d3210:i,d3222:a,d4410:s,d4422:c,d5220:l,d5232:u,d5421:d,d5433:f,dedt:p,del1:m,del2:ee,del3:te,didt:h,dmdt:g,dnodt:ne,domdt:_,argpo:v,argpdot:y,t:b,tc:re,gsto:ie,xfact:x,xlamo:ae,no:S}=e,{atime:C,em:w,argpm:T,inclm:E,xli:D,mm:O,xni:k,nodem:A,nm:j}=e,oe=.13130908,M=2.8843198,N=.37448087,se=5.7686396,P=.95240898,F=1.8014998,I=1.050833,L=4.4108898,R=259200,ce,z,B,V,H,U,W,G,K=0,q=0,J=(ie+re*.0043752690880113)%o;if(w+=p*b,E+=h*b,T+=_*b,A+=ne*b,O+=g*b,t!==0){(C===0||b*C<=0||Math.abs(b)<Math.abs(C))&&(C=0,k=S,D=ae),ce=b>0?720:-720;let e=381;for(;e===381;)t===2?(G=v+y*C,B=G+G,z=D+D,W=n*Math.sin(B+D-se)+r*Math.sin(D-se)+i*Math.sin(G+D-P)+a*Math.sin(-G+D-P)+s*Math.sin(B+z-F)+c*Math.sin(z-F)+l*Math.sin(G+D-I)+u*Math.sin(-G+D-I)+d*Math.sin(G+z-L)+f*Math.sin(-G+z-L),H=k+x,U=n*Math.cos(B+D-se)+r*Math.cos(D-se)+i*Math.cos(G+D-P)+a*Math.cos(-G+D-P)+l*Math.cos(G+D-I)+u*Math.cos(-G+D-I)+2*(s*Math.cos(B+z-F)+c*Math.cos(z-F)+d*Math.cos(G+z-L)+f*Math.cos(-G+z-L)),U*=H):(W=m*Math.sin(D-oe)+ee*Math.sin(2*(D-M))+te*Math.sin(3*(D-N)),H=k+x,U=m*Math.cos(D-oe)+2*ee*Math.cos(2*(D-M))+3*te*Math.cos(3*(D-N)),U*=H),Math.abs(b-C)>=720?e=381:(q=b-C,e=0),e===381&&(D+=H*ce+W*R,k+=W*ce+U*R,C+=ce);j=k+W*q+U*q*q*.5,V=D+H*q+W*q*q*.5,t===1?(O=V-A-T+J,K=j-S):(O=V-2*A+2*J,K=j-S),j=S+K}return{atime:C,em:w,argpm:T,inclm:E,xli:D,mm:O,xni:k,nodem:A,dndt:K,nm:j}}var x;(function(e){e[e.None=0]=`None`,e[e.MeanEccentricityOutOfRange=1]=`MeanEccentricityOutOfRange`,e[e.MeanMotionBelowZero=2]=`MeanMotionBelowZero`,e[e.PerturbedEccentricityOutOfRange=3]=`PerturbedEccentricityOutOfRange`,e[e.SemiLatusRectumBelowZero=4]=`SemiLatusRectumBelowZero`,e[e.Decayed=6]=`Decayed`})(x||={});function ae(e,t){let n,r,i,s,d,ee,te,h,g,_,v,y,b,re,ae,S,C,w,T,E,D,O,k,A,j,oe,M;e.t=t,e.error=x.None;let N=e.mo+e.mdot*e.t,se=e.argpo+e.argpdot*e.t,P=e.nodeo+e.nodedot*e.t;g=se,D=N;let F=e.t*e.t;if(k=P+e.nodecf*F,C=1-e.cc1*e.t,w=e.bstar*e.cc4*e.t,T=e.t2cof*F,e.isimp!==1){te=e.omgcof*e.t;let t=1+e.eta*Math.cos(N);ee=e.xmcof*(t*t*t-e.delmo),S=te+ee,D=N+S,g=se-S,y=F*e.t,b=y*e.t,C=C-e.d2*F-e.d3*y-e.d4*b,w+=e.bstar*e.cc5*(Math.sin(D)-e.sinmao),T=T+e.t3cof*y+b*(e.t4cof+e.t*e.t5cof)}O=e.no;let I=e.ecco;if(E=e.inclo,e.method===`d`){re=e.t;let t=ie({irez:e.irez,d2201:e.d2201,d2211:e.d2211,d3210:e.d3210,d3222:e.d3222,d4410:e.d4410,d4422:e.d4422,d5220:e.d5220,d5232:e.d5232,d5421:e.d5421,d5433:e.d5433,dedt:e.dedt,del1:e.del1,del2:e.del2,del3:e.del3,didt:e.didt,dmdt:e.dmdt,dnodt:e.dnodt,domdt:e.domdt,argpo:e.argpo,argpdot:e.argpdot,t:e.t,tc:re,gsto:e.gsto,xfact:e.xfact,xlamo:e.xlamo,no:e.no,atime:e.atime,em:I,argpm:g,inclm:E,xli:e.xli,mm:D,xni:e.xni,nodem:k,nm:O});({em:I,argpm:g,inclm:E,mm:D,nodem:k,nm:O}=t)}if(O<=0)return e.error=x.MeanMotionBelowZero,null;let L=(l/O)**m*C*C;if(O=l/L**1.5,I-=w,I>=1||I<-.001)return e.error=x.MeanEccentricityOutOfRange,null;I<1e-6&&(I=1e-6),D+=e.no*T,j=D+g+k,k%=o,g%=o,j%=o,D=(j-g-k)%o;let R={am:L,em:I,im:E,Om:k,om:g,mm:D,nm:O},ce=Math.sin(E),z=Math.cos(E),B=I;if(A=E,_=g,M=k,oe=D,s=ce,i=z,e.method===`d`){let t=ne(e,{inclo:e.inclo,init:`n`,ep:B,inclp:A,nodep:M,argpp:_,mp:oe,opsmode:e.operationmode});if({ep:B,nodep:M,argpp:_,mp:oe}=t,A=t.inclp,A<0&&(A=-A,M+=a,_-=a),B<0||B>1)return e.error=x.PerturbedEccentricityOutOfRange,null}e.method===`d`&&(s=Math.sin(A),i=Math.cos(A),e.aycof=-.5*p*s,Math.abs(i+1)>15e-13?e.xlcof=-.25*p*s*(3+5*i)/(1+i):e.xlcof=-.25*p*s*(3+5*i)/15e-13);let V=B*Math.cos(_);S=1/(L*(1-B*B));let H=B*Math.sin(_)+S*e.aycof,U=(oe+_+M+S*e.xlcof*V-M)%o;h=U,ae=9999.9;let W=1;for(;Math.abs(ae)>=1e-12&&W<=10;)r=Math.sin(h),n=Math.cos(h),ae=1-n*V-r*H,ae=(U-H*n+V*r-h)/ae,Math.abs(ae)>=.95&&(ae=ae>0?.95:-.95),h+=ae,W+=1;let G=V*n+H*r,K=V*r-H*n,q=V*V+H*H,J=L*(1-q);if(J<0)return e.error=x.SemiLatusRectumBelowZero,null;let le=L*(1-G),Y=Math.sqrt(L)*K/le,ue=Math.sqrt(J)/le,de=Math.sqrt(1-q);S=K/(1+de);let X=L/le*(r-H-V*S),fe=L/le*(n-V+H*S);v=Math.atan2(X,fe);let pe=(fe+fe)*X,me=1-2*X*X;S=1/J;let he=.5*f*S,ge=he*S;e.method===`d`&&(d=i*i,e.con41=3*d-1,e.x1mth2=1-d,e.x7thm1=7*d-1);let Z=le*(1-1.5*ge*de*e.con41)+.5*he*e.x1mth2*me;if(Z<1)return e.error=x.Decayed,null;v-=.25*ge*e.x7thm1*pe;let _e=M+1.5*ge*i*pe,ve=A+1.5*ge*i*s*me,ye=Y-O*he*e.x1mth2*pe/l,be=ue+O*he*(e.x1mth2*me+1.5*e.con41)/l,xe=Math.sin(v),Se=Math.cos(v),Ce=Math.sin(_e),we=Math.cos(_e),Te=Math.sin(ve),Ee=Math.cos(ve),Q=-Ce*Ee,De=we*Ee,Oe=Q*xe+we*Se,$=De*xe+Ce*Se,ke=Te*xe,Ae=Q*Se-we*xe,je=De*Se-Ce*xe,Me=Te*Se;return{position:{x:Z*Oe*c,y:Z*$*c,z:Z*ke*c},velocity:{x:(ye*Oe+be*Ae)*u,y:(ye*$+be*je)*u,z:(ye*ke+be*Me)*u},meanElements:R}}function S(e,t){let{opsmode:n,satn:r,epoch:i,xbstar:o,xecco:s,xargpo:l,xinclo:u,xmo:ee,xno:te,xnodeo:h}=t,g,y,b,ie,x,S,C,w,T,E,D,O,k,A,j,oe,M,N,se,P,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,le,Y,ue,de,X,fe,pe,me,he,ge,Z,_e,ve,ye,be,xe,Se,Ce,we,Te,Ee,Q=e;Q.isimp=0,Q.method=`n`,Q.aycof=0,Q.con41=0,Q.cc1=0,Q.cc4=0,Q.cc5=0,Q.d2=0,Q.d3=0,Q.d4=0,Q.delmo=0,Q.eta=0,Q.argpdot=0,Q.omgcof=0,Q.sinmao=0,Q.t=0,Q.t2cof=0,Q.t3cof=0,Q.t4cof=0,Q.t5cof=0,Q.x1mth2=0,Q.x7thm1=0,Q.mdot=0,Q.nodedot=0,Q.xlcof=0,Q.xmcof=0,Q.nodecf=0,Q.irez=0,Q.d2201=0,Q.d2211=0,Q.d3210=0,Q.d3222=0,Q.d4410=0,Q.d4422=0,Q.d5220=0,Q.d5232=0,Q.d5421=0,Q.d5433=0,Q.dedt=0,Q.del1=0,Q.del2=0,Q.del3=0,Q.didt=0,Q.dmdt=0,Q.dnodt=0,Q.domdt=0,Q.e3=0,Q.ee2=0,Q.peo=0,Q.pgho=0,Q.pho=0,Q.pinco=0,Q.plo=0,Q.se2=0,Q.se3=0,Q.sgh2=0,Q.sgh3=0,Q.sgh4=0,Q.sh2=0,Q.sh3=0,Q.si2=0,Q.si3=0,Q.sl2=0,Q.sl3=0,Q.sl4=0,Q.gsto=0,Q.xfact=0,Q.xgh2=0,Q.xgh3=0,Q.xgh4=0,Q.xh2=0,Q.xh3=0,Q.xi2=0,Q.xi3=0,Q.xl2=0,Q.xl3=0,Q.xl4=0,Q.xlamo=0,Q.zmol=0,Q.zmos=0,Q.atime=0,Q.xli=0,Q.xni=0,Q.bstar=o,Q.ecco=s,Q.argpo=l,Q.inclo=u,Q.mo=ee,Q.no=te,Q.nodeo=h,Q.operationmode=n,78/c+1;let De=42/c;De*De*De*De,Q.init=`y`,Q.t=0;let Oe=re({satn:r,ecco:Q.ecco,epoch:i,inclo:Q.inclo,no:Q.no,method:Q.method,opsmode:Q.operationmode}),{ao:$,con42:ke,cosio:Ae,cosio2:je,eccsq:Me,omeosq:Ne,posq:Pe,rp:Fe,rteosq:Ie,sinio:Le}=Oe;if(Q.no=Oe.no,Q.con41=Oe.con41,Q.gsto=Oe.gsto,Q.a=(Q.no*d)**(-2/3),Q.alta=Q.a*(1+Q.ecco)-1,Q.altp=Q.a*(1-Q.ecco)-1,Q.error=0,Ne>=0||Q.no>=0){if(Q.isimp=0,Fe<1.034492841559484&&(Q.isimp=1),B=1.0122292801892716,F=1.880279159015271e-9,N=(Fe-1)*c,N<156){B=N-78,N<98&&(B=20);let e=(120-B)/c;F=e*e*e*e,B=B/c+1}se=1/Pe,Z=1/($-B),Q.eta=$*Q.ecco*Z,O=Q.eta*Q.eta,D=Q.ecco*Q.eta,P=Math.abs(1-O),S=F*Z**4,C=S/P**3.5,ie=C*Q.no*($*(1+1.5*O+D*(4+O))+.375*f*Z/P*Q.con41*(8+3*O*(8+O))),Q.cc1=Q.bstar*ie,x=0,Q.ecco>1e-4&&(x=-2*S*Z*p*Q.no*Le/Q.ecco),Q.x1mth2=1-je,Q.cc4=2*Q.no*C*$*Ne*(Q.eta*(2+.5*O)+Q.ecco*(.5+2*O)-f*Z/($*P)*(-3*Q.con41*(1-2*D+O*(1.5-.5*D))+.75*Q.x1mth2*(2*O-D*(1+O))*Math.cos(2*Q.argpo))),Q.cc5=2*C*$*Ne*(1+2.75*(O+D)+D*O),w=je*je,me=1.5*f*se*Q.no,he=.5*me*f*se,ge=-.46875*-165597e-11*se*se*Q.no,Q.mdot=Q.no+.5*me*Ie*Q.con41+.0625*he*Ie*(13-78*je+137*w),Q.argpdot=-.5*me*ke+.0625*he*(7-114*je+395*w)+ge*(3-36*je+49*w),ve=-me*Ae,Q.nodedot=ve+(.5*he*(4-19*je)+2*ge*(3-7*je))*Ae,_e=Q.argpdot+Q.nodedot,Q.omgcof=Q.bstar*x*Math.cos(Q.argpo),Q.xmcof=0,Q.ecco>1e-4&&(Q.xmcof=-m*S*Q.bstar/D),Q.nodecf=3.5*Ne*ve*Q.cc1,Q.t2cof=1.5*Q.cc1,Math.abs(Ae+1)>15e-13?Q.xlcof=-.25*p*Le*(3+5*Ae)/(1+Ae):Q.xlcof=-.25*p*Le*(3+5*Ae)/15e-13,Q.aycof=-.5*p*Le;let e=1+Q.eta*Math.cos(Q.mo);if(Q.delmo=e*e*e,Q.sinmao=Math.sin(Q.mo),Q.x7thm1=7*je-1,2*a/Q.no>=225){Q.method=`d`,Q.isimp=1,fe=0,j=Q.inclo;let e=_({epoch:i,ep:Q.ecco,argpp:Q.argpo,tc:fe,inclp:Q.inclo,nodep:Q.nodeo,np:Q.no,e3:Q.e3,ee2:Q.ee2,peo:Q.peo,pgho:Q.pgho,pho:Q.pho,pinco:Q.pinco,plo:Q.plo,se2:Q.se2,se3:Q.se3,sgh2:Q.sgh2,sgh3:Q.sgh3,sgh4:Q.sgh4,sh2:Q.sh2,sh3:Q.sh3,si2:Q.si2,si3:Q.si3,sl2:Q.sl2,sl3:Q.sl3,sl4:Q.sl4,xgh2:Q.xgh2,xgh3:Q.xgh3,xgh4:Q.xgh4,xh2:Q.xh2,xh3:Q.xh3,xi2:Q.xi2,xi3:Q.xi3,xl2:Q.xl2,xl3:Q.xl3,xl4:Q.xl4,zmol:Q.zmol,zmos:Q.zmos});Q.e3=e.e3,Q.ee2=e.ee2,Q.peo=e.peo,Q.pgho=e.pgho,Q.pho=e.pho,Q.pinco=e.pinco,Q.plo=e.plo,Q.se2=e.se2,Q.se3=e.se3,Q.sgh2=e.sgh2,Q.sgh3=e.sgh3,Q.sgh4=e.sgh4,Q.sh2=e.sh2,Q.sh3=e.sh3,Q.si2=e.si2,Q.si3=e.si3,Q.sl2=e.sl2,Q.sl3=e.sl3,Q.sl4=e.sl4,{sinim:y,cosim:g,em:T,emsq:E,s1:I,s2:L,s3:R,s4:ce,s5:z,ss1:V,ss2:H,ss3:U,ss4:W,ss5:G,sz1:K,sz3:q,sz11:J,sz13:le,sz21:Y,sz23:ue,sz31:de,sz33:X}=e,Q.xgh2=e.xgh2,Q.xgh3=e.xgh3,Q.xgh4=e.xgh4,Q.xh2=e.xh2,Q.xh3=e.xh3,Q.xi2=e.xi2,Q.xi3=e.xi3,Q.xl2=e.xl2,Q.xl3=e.xl3,Q.xl4=e.xl4,Q.zmol=e.zmol,Q.zmos=e.zmos,{nm:M,z1:ye,z3:be,z11:xe,z13:Se,z21:Ce,z23:we,z31:Te,z33:Ee}=e;let t=ne(Q,{inclo:j,init:Q.init,ep:Q.ecco,inclp:Q.inclo,nodep:Q.nodeo,argpp:Q.argpo,mp:Q.mo,opsmode:Q.operationmode});Q.ecco=t.ep,Q.inclo=t.inclp,Q.nodeo=t.nodep,Q.argpo=t.argpp,Q.mo=t.mp,k=0,A=0,oe=0;let n=v({cosim:g,emsq:E,argpo:Q.argpo,s1:I,s2:L,s3:R,s4:ce,s5:z,sinim:y,ss1:V,ss2:H,ss3:U,ss4:W,ss5:G,sz1:K,sz3:q,sz11:J,sz13:le,sz21:Y,sz23:ue,sz31:de,sz33:X,t:Q.t,tc:fe,gsto:Q.gsto,mo:Q.mo,mdot:Q.mdot,no:Q.no,nodeo:Q.nodeo,nodedot:Q.nodedot,xpidot:_e,z1:ye,z3:be,z11:xe,z13:Se,z21:Ce,z23:we,z31:Te,z33:Ee,ecco:Q.ecco,eccsq:Me,em:T,argpm:k,inclm:j,mm:oe,nm:M,nodem:A,irez:Q.irez,atime:Q.atime,d2201:Q.d2201,d2211:Q.d2211,d3210:Q.d3210,d3222:Q.d3222,d4410:Q.d4410,d4422:Q.d4422,d5220:Q.d5220,d5232:Q.d5232,d5421:Q.d5421,d5433:Q.d5433,dedt:Q.dedt,didt:Q.didt,dmdt:Q.dmdt,dnodt:Q.dnodt,domdt:Q.domdt,del1:Q.del1,del2:Q.del2,del3:Q.del3,xfact:Q.xfact,xlamo:Q.xlamo,xli:Q.xli,xni:Q.xni});Q.irez=n.irez,Q.atime=n.atime,Q.d2201=n.d2201,Q.d2211=n.d2211,Q.d3210=n.d3210,Q.d3222=n.d3222,Q.d4410=n.d4410,Q.d4422=n.d4422,Q.d5220=n.d5220,Q.d5232=n.d5232,Q.d5421=n.d5421,Q.d5433=n.d5433,Q.dedt=n.dedt,Q.didt=n.didt,Q.dmdt=n.dmdt,Q.dnodt=n.dnodt,Q.domdt=n.domdt,Q.del1=n.del1,Q.del2=n.del2,Q.del3=n.del3,Q.xfact=n.xfact,Q.xlamo=n.xlamo,Q.xli=n.xli,Q.xni=n.xni}Q.isimp!==1&&(b=Q.cc1*Q.cc1,Q.d2=4*$*Z*b,pe=Q.d2*Z*Q.cc1/3,Q.d3=(17*$+B)*pe,Q.d4=.5*pe*$*Z*(221*$+31*B)*Q.cc1,Q.t3cof=Q.d2+2*b,Q.t4cof=.25*(3*Q.d3+Q.cc1*(12*Q.d2+10*b)),Q.t5cof=.2*(3*Q.d4+12*Q.cc1*Q.d3+6*Q.d2*Q.d2+15*b*(2*Q.d2+b)))}ae(Q,0),Q.init=`n`}function C(e,t=`i`){let n=e.NORAD_CAT_ID.toString(),r=new Date(e.EPOCH.endsWith(`Z`)?e.EPOCH:`${e.EPOCH}Z`),i=r.getUTCFullYear(),a=Number(i.toString().slice(-2)),o=(r.valueOf()-new Date(Date.UTC(i,0,1,0,0,0)).valueOf())/(86400*1e3)+1,c=Number(e.MEAN_MOTION_DOT),l=Number(e.MEAN_MOTION_DDOT);c/=ee*1440,l/=ee*1440*1440;let u=Number(e.BSTAR),d=Number(e.INCLINATION)*s,f=Number(e.RA_OF_ASC_NODE)*s,p=Number(e.ECCENTRICITY),m=Number(e.ARG_OF_PERICENTER)*s,h=Number(e.MEAN_ANOMALY)*s,ne=Number(e.MEAN_MOTION)/ee,{mon:_,day:v,hr:y,minute:b,sec:re}=te(i,o),ie=g(i,_,v,y,b,re),x={error:0,satnum:n,epochyr:a,epochdays:o,ndot:c,nddot:l,bstar:u,inclo:d,nodeo:f,ecco:p,argpo:m,mo:h,no:ne,jdsatepoch:ie};return S(x,{opsmode:t,satn:x.satnum,epoch:x.jdsatepoch-2433281.5,xbstar:x.bstar,xecco:x.ecco,xargpo:x.argpo,xinclo:x.inclo,xmo:x.mo,xno:x.no,xnodeo:x.nodeo}),x}3*Float64Array.BYTES_PER_ELEMENT;const w=Math.PI/180;Math.cos(i*w),Math.sin(i*w);function T(e){return new Date((e-2440587.5)*864e5).toISOString()}function E(e,t){let n=C({OBJECT_NAME:t??String(e.noradCatId),OBJECT_ID:String(e.noradCatId),EPOCH:T(e.epochJd),MEAN_MOTION:e.meanMotion,ECCENTRICITY:e.eccentricity,INCLINATION:e.inclination,RA_OF_ASC_NODE:e.raOfAscNode,ARG_OF_PERICENTER:e.argOfPericenter,MEAN_ANOMALY:e.meanAnomaly,EPHEMERIS_TYPE:0,CLASSIFICATION_TYPE:`U`,NORAD_CAT_ID:e.noradCatId,ELEMENT_SET_NO:e.elementSetNo,REV_AT_EPOCH:e.revAtEpoch,BSTAR:e.bstar,MEAN_MOTION_DOT:e.meanMotionDot,MEAN_MOTION_DDOT:e.meanMotionDdot});return n.error===x.None?n:(console.warn(`buildSatrec: SGP4 init failed for NORAD ${e.noradCatId} (error=${n.error})`),null)}const D=Math.PI/180,O=Math.cos(i*D),k=Math.sin(i*D),A=10/r;function j(e,t,n,r,i){return!isFinite(Math.fround(n))||!isFinite(Math.fround(r))||!isFinite(Math.fround(i))?!1:(e[t*3]=n,e[t*3+1]=r,e[t*3+2]=i,!0)}function oe(r,i,a,o,s,c,l,u,d,f=null,p=0){if(i<r.validityStart||i>r.validityEnd)return 0;let{count:m,kind:ee,equatorial:te,a:h,e:g,i:ne,om:_,w:v,ma:y,n:b,epoch:re,q:ie,tp:S,satrec:C,flags:w,visibleFromDays:T}=r,oe=p!==0&&r.applyFlagFilter,M=r.pickBase,N=d.length/3|0,se=i-2451545,P=0;for(let F=0;F<m&&!(P>=N);F++){let m=ee[F];if(m===0||T[F]>se||oe&&(w[F]&p)!==p)continue;if(m===3){let e=C[F];if(!e){if(e=E({noradCatId:r.satnum[F],epochJd:re[F],meanMotion:b[F]/360,eccentricity:g[F],inclination:ne[F],raOfAscNode:_[F],argOfPericenter:v[F],meanAnomaly:y[F],bstar:r.bstar[F],meanMotionDot:r.ndot[F],meanMotionDdot:r.nddot[F],elementSetNo:0,revAtEpoch:0}),!e){ee[F]=0;continue}C[F]=e}let t=(i-e.jdsatepoch)*1440,n=ae(e,t);if(!n||e.error!==x.None)continue;let p=n.position.x,m=n.position.y,te=n.position.z,h=p*A,ie=m*A,S=te*A,w=ie*O+S*k,T=-ie*k+S*O,D=h,oe=T,N=-w;if(!j(d,P,a+D-c,o+oe-l,s+N-u))continue;if(f){let e=M+F,t=P*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}P++;continue}let N,I,L=g[F],R=ne[F],ce=_[F],z=v[F];if(m===2){let e=n(ie[F],S[F],i);if(!e)continue;N=e.r*Math.cos(e.nu),I=e.r*Math.sin(e.nu)}else{let n=h[F];if(!isFinite(n)||!isFinite(L)||!isFinite(y[F])||!isFinite(b[F]))continue;let r=i-re[F],a=(y[F]+b[F]*r)*D,o,s;if(L<1||n>0){let t=Math.min(L,.9999999),r=e(a,t),i=Math.sqrt(1-t*t)*Math.sin(r)/(1-t*Math.cos(r)),c=(Math.cos(r)-t)/(1-t*Math.cos(r));o=Math.atan2(i,c),s=n*(1-t*Math.cos(r))}else{let e=t(a,L);if(!isFinite(e))continue;let r=L*Math.cosh(e)-1;if(Math.abs(r)<1e-15)continue;let i=Math.sqrt(L*L-1)*Math.sinh(e)/r,c=(L-Math.cosh(e))/r;o=Math.atan2(i,c),s=n*(1-L*Math.cosh(e))}N=s*Math.cos(o),I=s*Math.sin(o)}if(!isFinite(N)||!isFinite(I))continue;let B=Math.cos(z*D),V=Math.sin(z*D),H=Math.cos(R*D),U=Math.sin(R*D),W=Math.cos(ce*D),G=Math.sin(ce*D),K=(W*B-G*V*H)*N+(-W*V-G*B*H)*I,q=(G*B+W*V*H)*N+(-G*V+W*B*H)*I,J=V*U*N+B*U*I;if(te[F]){let e=q*O+J*k,t=-q*k+J*O;q=e,J=t}let le=K*10,Y=J*10,ue=-q*10;if(j(d,P,a+le-c,o+Y-l,s+ue-u)){if(f){let e=M+F,t=P*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}P++}}return P}const M=new Map;self.onmessage=e=>{let t=e.data;if(t.type===`ping`){self.postMessage({type:`pong`});return}if(t.type===`rewireDelta`){if(t.remove)for(let e of t.remove)M.delete(e);for(let e of t.set)M.set(e.id,e.cols);return}if(t.type===`tick`){let e=[],n=[],[r,i,a]=t.basis;for(let o of t.groups){let s=M.get(o.id);if(!s){e.push({id:o.id,count:0,buf:o.out.buffer,idbuf:o.outIds.buffer}),n.push(o.out.buffer,o.outIds.buffer);continue}let c=oe(s,t.jd,o.parent[0],o.parent[1],o.parent[2],r,i,a,o.out,o.outIds,t.requiredFlags??0);e.push({id:o.id,count:c,buf:o.out.buffer,idbuf:o.outIds.buffer}),n.push(o.out.buffer,o.outIds.buffer)}self.postMessage({type:`tickResult`,groups:e},n);return}};\n//# sourceMappingURL=worker-CK5Z1yOu.js.map",lP=typeof self<`u`&&self.Blob&&new Blob([`URL.revokeObjectURL(import.meta.url);`,cP],{type:`text/javascript;charset=utf-8`});function uP(e){let t;try{if(t=lP&&(self.URL||self.webkitURL).createObjectURL(lP),!t)throw``;let n=new Worker(t,{type:`module`,name:e?.name});return n.addEventListener(`error`,()=>{(self.URL||self.webkitURL).revokeObjectURL(t)}),n}catch{return new Worker(`data:text/javascript;charset=utf-8,`+encodeURIComponent(cP),{type:`module`,name:e?.name})}}var dP=class{workers=[];groups=new Map;onResult=null;size;pendingPing=null;generation=0;constructor(e=navigator.hardwareConcurrency??4){this.size=Math.max(2,Math.min(8,e)),this.spawn()}spawn(){for(let e=0;e<this.size;e++){let e=new uP;e.onmessage=e=>this.onMessage(e.data),this.workers.push(e)}}ping(e=800){if(this.workers.length===0)return Promise.resolve(!1);if(this.pendingPing)return this.pendingPing.promise;let t,n=new Promise(e=>t=e),r={need:this.workers.length,got:0,promise:n,resolve:e=>{this.pendingPing===r&&(this.pendingPing=null,t(e))}};this.pendingPing=r,setTimeout(()=>r.resolve(!1),e);for(let e of this.workers)e.postMessage({type:`ping`});return n}respawn(){this.pendingPing?.resolve(!1);for(let e of this.workers)e.terminate();this.workers=[],this.groups.clear(),this.generation++,this.spawn()}get poolGeneration(){return this.generation}setResultHandler(e){this.onResult=e}get workerCount(){return this.workers.length}get groupCount(){return this.groups.size}async rewireOne(e,t,n,r,i=!1,a=0){if(t.length===0){this.unwireOne(e);return}let o=await zg(t,n,i);o.pickBase=a,this.workers.length!==0&&this.wireCols(e,o,r,t.length)}rewireOneCols(e,t,n){if(this.workers.length!==0){if(t.count===0){this.unwireOne(e);return}this.wireCols(e,t,n,t.count)}}wireCols(e,t,n,r){let i=this.groups.get(e),a=i?.workerIdx??n%this.workers.length,o,s,c,l;if(i&&i.capacity===r)o=i.front,s=i.back,c=i.idFront,l=i.idBack;else if(o=new Float32Array(r*3),s=new Float32Array(r*3),c=new Uint8Array(r*4),l=new Uint8Array(r*4),i){let e=Math.min(i.front.length,o.length);o.set(i.front.subarray(0,e));let t=Math.min(i.idFront.length,c.length);c.set(i.idFront.subarray(0,t))}let u=!!i&&i.back===null;this.groups.set(e,{workerIdx:a,capacity:r,front:o,back:s,idFront:c,idBack:l,count:i?.count??r,pendingBasis:u?i.pendingBasis:null,pendingParent:u?i.pendingParent:null,pendingJd:u?i.pendingJd:null,frontBasis:i?.frontBasis??[0,0,0],frontParent:i?.frontParent??[0,0,0],frontJd:i?.frontJd??NaN}),this.workers[a].postMessage({type:`rewireDelta`,set:[{id:e,cols:t}]},Vg(t))}unwireOne(e){let t=this.groups.get(e);t&&(this.groups.delete(e),this.workers[t.workerIdx].postMessage({type:`rewireDelta`,set:[],remove:[e]}))}tick(e,t,n,r=0){let i=this.workers.map(()=>[]);for(let[r,a]of this.groups){if(!a.back||!a.idBack)continue;let o=n.get(r);o&&(i[a.workerIdx].push({id:r,parent:[o[0],o[1],o[2]],out:a.back,outIds:a.idBack}),a.back=null,a.idBack=null,a.pendingBasis=[t[0],t[1],t[2]],a.pendingParent=[o[0],o[1],o[2]],a.pendingJd=e)}for(let n=0;n<this.workers.length;n++){let a=i[n];if(a.length===0)continue;let o=a.flatMap(e=>[e.out.buffer,e.outIds.buffer]);this.workers[n].postMessage({type:`tick`,jd:e,basis:[t[0],t[1],t[2]],requiredFlags:r,groups:a},o)}}onMessage(e){if(e.type===`pong`){let e=this.pendingPing;e&&++e.got>=e.need&&e.resolve(!0);return}if(e.type===`tickResult`)for(let t of e.groups){let e=this.groups.get(t.id);if(!e)continue;let n=new Float32Array(t.buf),r=e.front;e.front=n,e.back=r;let i=new Uint8Array(t.idbuf),a=e.idFront;e.idFront=i,e.idBack=a,e.count=t.count;let o=e.pendingBasis??e.frontBasis,s=e.pendingParent??e.frontParent,c=e.pendingJd??e.frontJd;e.frontBasis=o,e.frontParent=s,e.frontJd=c,e.pendingBasis=null,e.pendingParent=null,e.pendingJd=null,this.onResult?.(t.id,n,t.count,o,s,c,i)}}destroy(){this.pendingPing?.resolve(!1);for(let e of this.workers)e.terminate();this.workers.length=0,this.groups.clear()}},fP=class{#e=1;#t=new Map;allocate(e,t){let n=this.#e;return this.#e+=t.length,this.#t.set(e,{base:n,keys:t}),n}release(e){this.#t.delete(e)}resolve(e){if(e===0)return null;for(let{base:t,keys:n}of this.#t.values())if(e>=t&&e<t+n.length)return gh(n[e-t]);return null}clear(){this.#t.clear(),this.#e=1}},pP=.01,mP=[`asteroid`,`spacecraft`],hP=.0002959122082855911,gP=.75,_P=Q(8*86400);function vP(e){let t=0,n=!1;for(let r=0;r<e.count;r++){if(e.kind[r]===0)continue;let i=e.a[r],a=e.e[r];if(e.kind[r]!==1||!(i>0)||!(a<1)||!isFinite(i)||!isFinite(a)){n=!0;continue}let o=Math.min(a,.9999999),s=Math.sqrt(hP/i*((1+o)/(1-o)));s>t&&(t=s)}return{maxSpeedScene:t*10,alwaysSolve:n}}function yP(e){return e<0?0:e>1?1:e}function bP(e,t){return t===`*`?e.startsWith(`small_bodies/`):e===t}function xP(e){return e===null?{tBright:0,tSize:0}:{tBright:yP((SP-e)/(SP-CP)),tSize:yP((wP-e)/(wP-TP))}}var SP=1e4,CP=500,wP=CP,TP=50,EP=4,DP=.5,OP=10,kP=1,AP=1,jP=3.5,MP=2.5,NP=2,PP=jP,FP=class{orbitPool=new dP;pickRegistry=new fP;disposed=!1;workerPoints={asteroid:new Map,spacecraft:new Map};moonPoints=new Map;pointBudget=1/0;drawFraction=1;pendingSceneAdds=[];basisPos=[0,0,0];parentAtUpdate=new Map;_parentsScratch=new Map;moonsByParentCache=null;lastPackedSize=new Map;groupKinematics=new Map;lastSolvedJd=new Map;earthSatEmphasis={size:EP,dim:DP,opacity:AP};emphasizedSmallBodyZone=null;smallBodyEmphasis={sizeMult:1,brightMult:1,opacity:AP};constructor(e,t,n,r,i,a,o){this.ctx=e,this.scene=t,this.bodyObjects=n,this.circleTexture=r,this.focus=i,this.mapLayer=a,this.onBasisRebuilt=o,this.orbitPool.setResultHandler(this.onPoolResult)}basis(){return this.basisPos}setPointBudget(e){this.pointBudget=e,this.applyPointBudget()}applyPointBudget(){let e=0;for(let t of mP)for(let n of this.workerPoints[t].values())n.visible&&(e+=n.userData.solvedCount??0);let t=e>this.pointBudget?this.pointBudget/e:1;if(t!==this.drawFraction){this.drawFraction=t;for(let e of mP)for(let n of this.workerPoints[e].values()){let e=n.userData.solvedCount;e!==void 0&&n.geometry.setDrawRange(0,Math.ceil(e*t))}}}setEarthSatEmphasis(e){this.earthSatEmphasis=this.computeEarthSatEmphasis(e);for(let[e,t]of this.workerPoints.spacecraft)x_(e)===`naif-399`&&this.applyEarthSatEmphasis(t)}computeEarthSatEmphasis(e){let{tBright:t,tSize:n}=xP(e);return{size:EP+(OP-EP)*n,dim:DP+(kP-DP)*t,opacity:AP+(jP-AP)*t}}applyEarthSatEmphasis(e){let t=e.material,{size:n,dim:r,opacity:i}=this.earthSatEmphasis;t.size=n,t.color.setRGB(r,r,r),t.opacity=i}setEmphasizedSmallBodyZone(e,t){let n=this.emphasizedSmallBodyZone;if(this.emphasizedSmallBodyZone=e,this.smallBodyEmphasis=this.computeSmallBodyEmphasis(e===null?null:t),n!==null&&n!==e)for(let[e,t]of this.workerPoints.asteroid)bP(x_(e),n)&&this.resetSmallBodyEmphasis(t);if(e!==null)for(let[t,n]of this.workerPoints.asteroid)bP(x_(t),e)&&this.applySmallBodyEmphasis(n)}computeSmallBodyEmphasis(e){let{tBright:t,tSize:n}=xP(e);return{sizeMult:1+(MP-1)*n,brightMult:1+(NP-1)*t,opacity:AP+(PP-AP)*t}}applySmallBodyEmphasis(e){let t=e.material;e.userData.smallBodyBaseSize===void 0&&(e.userData.smallBodyBaseSize=t.size,e.userData.smallBodyBaseColor=t.color.clone());let n=e.userData.smallBodyBaseSize,r=e.userData.smallBodyBaseColor,{sizeMult:i,brightMult:a,opacity:o}=this.smallBodyEmphasis;t.size=n*i,t.color.copy(r).multiplyScalar(a),t.opacity=o}resetSmallBodyEmphasis(e){if(e.userData.smallBodyBaseSize===void 0)return;let t=e.material;t.size=e.userData.smallBodyBaseSize,t.color.copy(e.userData.smallBodyBaseColor),t.opacity=AP,e.userData.smallBodyBaseSize=void 0,e.userData.smallBodyBaseColor=void 0}seedBasis(e){this.basisPos=[...e]}buildInitial(e){let t=wN(this.ctx,this.scene,this.circleTexture,this.basisPos,e,this.orbitPool.workerCount);this.workerPoints.asteroid=t.asteroidPoints,this.workerPoints.spacecraft=t.spacecraftPoints,this.moonPoints=t.moonPoints;for(let e of mP)for(let[t,n]of this.workerPoints[e]){let r=x_(t);n.userData.parentBodyId=this.cloudParentId(e,r),this.emphasiseNewCloud(e,r,n)}this.assignMapLayer()}assignMapLayer(){for(let e of mP)for(let t of this.workerPoints[e].values())t.layers.set(this.mapLayer);for(let e of this.moonPoints.values())e.layers.set(this.mapLayer)}cloudParentId(e,t){return e===`asteroid`?d_:t}emphasiseNewCloud(e,t,n){if(e===`spacecraft`){t===`naif-399`&&this.applyEarthSatEmphasis(n);return}let r=this.emphasizedSmallBodyZone;r!==null&&bP(t,r)&&this.applySmallBodyEmphasis(n)}rebuildRunning=!1;rebuildQueued=!1;rebuildMinor(){if(this.rebuildRunning){this.rebuildQueued=!0;return}this.rebuildRunning=!0,(async()=>{try{do this.rebuildQueued=!1,await this.rebuildMinorPass();while(this.rebuildQueued)}finally{this.rebuildRunning=!1}})()}recovering=null;recoverWorkersIfDead(e){return this.recovering??=this.runRecovery(e).finally(()=>this.recovering=null),this.recovering}async runRecovery(e){if(await this.orbitPool.ping(e))return!1;this.orbitPool.respawn();for(let e of this.ctx.bodies.asteroidBodiesByZone.keys())this.ctx.bodies.dirtyAsteroidZones.add(e);for(let e of this.ctx.bodies.spacecraftByParent.keys())this.ctx.bodies.dirtySpacecraftGroups.add(e);return this.lastPackedSize.clear(),this.rebuildMinor(),!0}async rebuildMinorPass(){if(this.disposed||this.ctx.bodies.dirtyAsteroidZones.size===0&&this.ctx.bodies.dirtySpacecraftGroups.size===0)return;let e=[this.basisPos[0],this.basisPos[1],this.basisPos[2]],t=this.orbitPool.workerCount,n=this.orbitPool.poolGeneration,r=[],i=[];for(let n of[...this.ctx.bodies.dirtyAsteroidZones]){let i=this.ctx.bodies.asteroidBodiesByZone.get(n);if(this.deferPackWhileStreaming(`asteroid:${n}`,i?.size??0))continue;this.ctx.bodies.dirtyAsteroidZones.delete(n),r.push(n);let a=vh(this.bodyObjects.keys()),{groups:o,baseWorker:s}=i?await i.buildWorkerGroups(n,t,a,!1):{groups:[],baseWorker:0};if(this.disposed)return;let c=i&&o.length>0?i.cloudColor():`#888888`;for(let r=0;r<t;r++){let i=`${n}#${r}`,a=`asteroid:${i}`,l=r<o.length?o[r]:null;if(!l||l.cols.count===0){this.unwireGroup(`asteroid`,i,a);continue}this.armGroupGate(a,vP(l.cols)),l.cols.pickBase=this.pickRegistry.allocate(a,l.keys),this.orbitPool.rewireOneCols(a,l.cols,(s+r)%t);let u=this.workerPoints.asteroid.get(i);if(u){this.resizeGeometryToCount(u.geometry,l.cols.count,null);continue}let d=nN(new Float32Array(l.cols.count*3),0,this.circleTexture,c,eN());this.adoptCloud(`asteroid`,i,a,d,e)}}for(let n of[...this.ctx.bodies.dirtySpacecraftGroups]){let r=this.ctx.bodies.spacecraftByParent.get(n);if(this.deferPackWhileStreaming(`spacecraft:${n}`,r?.size??0))continue;this.ctx.bodies.dirtySpacecraftGroups.delete(n),i.push(n);let{buckets:a,baseWorker:o}=await b_(n,Cv(this.ctx.layers,n,r?Array.from(r.values()):[]),t);if(this.disposed)return;let s=new Set(this.bodyObjects.keys());for(let r=0;r<t;r++){let i=`${n}#${r}`,c=`spacecraft:${i}`,l=r<a.length?a[r]:[];if(l.length===0){this.unwireGroup(`spacecraft`,i,c);continue}let u=this.pickRegistry.allocate(c,Float64Array.from(l,e=>_h(e.data.id)??dh));await this.orbitPool.rewireOne(c,l,s,(o+r)%t,!1,u),this.armGroupGate(c,{maxSpeedScene:_P,alwaysSolve:!1});let d=this.workerPoints.spacecraft.get(i);if(d){this.resizeGeometryIfNeeded(d.geometry,l);continue}let f=new Float32Array(l.length*3),p=new Float32Array(l.length*3);this.seedGeometryArray(f,l,p);let m=nN(f,l.length,this.circleTexture,`#ffffff`,void 0,p);this.adoptCloud(`spacecraft`,i,c,m,e)}}if(this.orbitPool.poolGeneration!==n){for(let e of r)this.ctx.bodies.dirtyAsteroidZones.add(e);for(let e of i)this.ctx.bodies.dirtySpacecraftGroups.add(e);this.lastPackedSize.clear(),this.rebuildQueued=!0}}unwireGroup(e,t,n){this.orbitPool.unwireOne(n),this.forgetGroupGate(n),this.pickRegistry.release(n);let r=this.workerPoints[e].get(t);r&&(this.scene.remove(r),this.workerPoints[e].delete(t))}armGroupGate(e,t){this.groupKinematics.set(e,t),this.lastSolvedJd.delete(e)}adoptCloud(e,t,n,r,i){let a=x_(t);r.userData.frontBasis=i,r.userData.groupId=n,r.userData.parentBodyId=this.cloudParentId(e,a),r.userData.parentVec=[0,0,0],this.emphasiseNewCloud(e,a,r),this.workerPoints[e].set(t,r),this.pendingSceneAdds.push(r)}deferPackWhileStreaming(e,t){if(!this.ctx.bodies.minorStreaming)return this.lastPackedSize.set(e,t),!1;let n=this.lastPackedSize.get(e);return n!==void 0&&t>n&&t<n*2?!0:(this.lastPackedSize.set(e,t),!1)}seedGeometryArray(e,t,n=null){let[r,i,a]=this.basisPos,o=Math.min(t.length,e.length/3),s=n?new X:null;for(let c=0;c<o;c++){let o=t[c],l=o.position;e[c*3]=l[0]-r,e[c*3+1]=l[1]-i,e[c*3+2]=l[2]-a,n&&s&&(s.set(m_(o.data)),n[c*3]=s.r,n[c*3+1]=s.g,n[c*3+2]=s.b)}}resizeGeometryIfNeeded(e,t){let n=t.length*3;if(e.getAttribute(`position`).array.length===n){e.setDrawRange(0,t.length);return}let r=!!e.getAttribute(`color`),i=new Float32Array(n),a=r?new Float32Array(n):null;this.seedGeometryArray(i,t,a),e.setAttribute(`position`,new Eo(i,3)),a&&e.setAttribute(`color`,new Eo(a,3)),e.setDrawRange(0,t.length)}resizeGeometryToCount(e,t,n){let r=t*3,i=e.getAttribute(`position`).array;if(n&&e.setAttribute(`color`,new Eo(n,3)),i.length===r)return;let a=new Float32Array(r);a.set(i.subarray(0,Math.min(i.length,r))),e.setAttribute(`position`,new Eo(a,3));let o=Math.min(e.drawRange.count,t);e.setDrawRange(0,Number.isFinite(o)?o:0)}onPoolResult=(e,t,n,r,i,a,o)=>{let[s,c]=e.split(`:`),l=this.workerPoints[s].get(c);if(!l)return;let u=l.geometry.getAttribute(`position`),d=u.array;if(d.length!==t.length)return;d.set(t),u.needsUpdate=!0,this.bindPickIds(l,o),l.userData.solvedCount=n,l.geometry.setDrawRange(0,Math.ceil(n*this.drawFraction)),this.lastSolvedJd.set(e,a),l.userData.frontBasis=[r[0],r[1],r[2]],this.parentAtUpdate.set(e,[i[0],i[1],i[2]]);let[f,p,m]=this.focus.focusTruePos,h=this.ctx.getBody(l.userData.parentBodyId)?.position,g=h?h[0]-i[0]:0,_=h?h[1]-i[1]:0,v=h?h[2]-i[2]:0;l.position.set(r[0]-f+g,r[1]-p+_,r[2]-m+v)};bindPickIds(e,t){let n=e.geometry.getAttribute(`pickColor`);n&&n.array.length===t.length?(n.array.set(t),n.needsUpdate=!0):e.geometry.setAttribute(`pickColor`,new Eo(t.slice(),4,!0))}reposition(){let[e,t,n]=this.focus.focusTruePos,r=this.basisPos;for(let i of mP)for(let a of this.workerPoints[i].values()){let i=a.userData.frontBasis??r,[o,s,c]=this.parentShift(a.userData.groupId,a.userData.parentBodyId);a.position.set(i[0]-e+o,i[1]-t+s,i[2]-n+c)}let[i,a,o]=r,s=i-e,c=a-t,l=o-n;for(let e of this.moonPoints.values())e.position.set(s,c,l)}parentShift(e,t){let n=this.parentAtUpdate.get(e),r=this.ctx.getBody(t)?.position;return!n||!r?[0,0,0]:[r[0]-n[0],r[1]-n[1],r[2]-n[2]]}maybeRebase(){let[e,t,n]=this.focus.focusTruePos,[r,i,a]=this.basisPos,o=e-r,s=t-i,c=n-a,l=o*o+s*s+c*c,u=pP*10;l>u*u&&this.rebuildBasis()}rebuildBasis(){this.basisPos=[...this.focus.focusTruePos],this.rebuildMoons(),this.onBasisRebuilt(),this.reposition()}updateForJd(e,t){this.writeMoons();let n=this._parentsScratch;n.clear();let r=this.ctx.getBody(`naif-10`)?.position??[0,0,0];for(let[i,a]of this.workerPoints.asteroid){if(!this.ctx.visibility.isAsteroidGroupVisible(x_(i)))continue;let o=a.userData.groupId;if(!this.shouldSolveGroup(o,r,e,t))continue;let s=a.userData.parentVec;s[0]=r[0],s[1]=r[1],s[2]=r[2],n.set(o,s)}for(let[r,i]of this.workerPoints.spacecraft){if(!this.ctx.visibility.isSpacecraftGroupVisible(x_(r)))continue;let a=i.userData.groupId,o=this.ctx.getBody(i.userData.parentBodyId)?.position;if(o&&!this.shouldSolveGroup(a,o,e,t))continue;let s=i.userData.parentVec;o?(s[0]=o[0],s[1]=o[1],s[2]=o[2]):(s[0]=0,s[1]=0,s[2]=0),n.set(a,s)}this.orbitPool.tick(e,this.basisPos,n,this.ctx.visibility.getRequiredFlags())}shouldSolveGroup(e,t,n,r){let i=this.groupKinematics.get(e);if(!i||i.alwaysSolve)return!0;let a=this.lastSolvedJd.get(e);if(a===void 0||!isFinite(a))return!0;let[o,s,c]=this.focus.focusTruePos,l=r.camPos[0]-(t[0]-o),u=r.camPos[1]-(t[1]-s),d=r.camPos[2]-(t[2]-c),f=Math.max(1e-6,Math.sqrt(l*l+u*u+d*d)),p=Math.abs(n-a);return i.maxSpeedScene*p/f*r.pxPerRad>=gP}forgetGroupGate(e){this.groupKinematics.delete(e),this.lastSolvedJd.delete(e)}moonsByParent(){let e=this.ctx.bodies.majorBodies.length;if(this.moonsByParentCache?.len===e)return this.moonsByParentCache.map;let t=new Map;for(let e of this.ctx.bodies.majorBodies)if(e.data.objectType===G.MOON){let n=t.get(e.data.parentId)??[];n.push(e),t.set(e.data.parentId,n)}return this.moonsByParentCache={len:e,map:t},t}writeMoons(){let[e,t,n]=this.basisPos;for(let[r,i]of this.moonsByParent()){let a=this.moonPoints.get(r);if(!a||!this.ctx.visibility.isMoonGroupVisible(r))continue;let o=a.geometry.getAttribute(`position`),s=o.array,c=Math.min(i.length,s.length/3);for(let r=0;r<c;r++){let a=i[r];if(this.bodyObjects.get(a.data.id)?.outOfRange){s[r*3]=s[r*3+1]=s[r*3+2]=NaN;continue}s[r*3]=a.position[0]-e,s[r*3+1]=a.position[1]-t,s[r*3+2]=a.position[2]-n}o.needsUpdate=!0}}rebuildMoons(){let e=this.basisPos;for(let[t,n]of this.moonsByParent()){let r=this.moonPoints.get(t);if(!r)continue;let i=new Float32Array(n.length*3);for(let t=0;t<n.length;t++)i[t*3]=n[t].position[0]-e[0],i[t*3+1]=n[t].position[1]-e[1],i[t*3+2]=n[t].position[2]-e[2];r.geometry.setAttribute(`position`,new ko(i,3))}}hasPendingSceneAdds(){return this.pendingSceneAdds.length>0}drainOnePendingSceneAdd(){if(this.pendingSceneAdds.length===0)return;let e=this.pendingSceneAdds.shift();e.layers.set(this.mapLayer),this.scene.add(e)}asteroids(){return this.workerPoints.asteroid}spacecraft(){return this.workerPoints.spacecraft}moons(){return this.moonPoints}dispose(){this.disposed=!0,this.orbitPool.destroy(),this.pickRegistry.clear();for(let e of mP)this.disposeClouds(this.workerPoints[e]);this.disposeClouds(this.moonPoints);for(let e of this.pendingSceneAdds)e.geometry.dispose(),e.material.dispose();this.pendingSceneAdds.length=0}disposeClouds(e){for(let t of e.values())this.scene.remove(t),t.geometry.dispose(),t.material.dispose();e.clear()}},IP=Math.PI/180,LP=2451545,RP=1.00000261,zP=.01671123,BP=100.46457166*IP,VP=35999.37244981/36525*IP,HP=102.93768193*IP,UP=.32327364/36525*IP;function WP(e){let t=e-LP,n=HP+UP*t,r=BP+VP*t-n,i=r+(2*zP-zP**3/4)*Math.sin(r)+1.25*zP*zP*Math.sin(2*r);return{lon:n+i,r:RP*(1-zP*zP)/(1+zP*Math.cos(i))}}function GP(e){let t=WP(e).lon;return(e,n)=>{let r=t-WP(e).lon,i=Math.cos(r),a=Math.sin(r),o=n[0],s=n[2];n[0]=o*i+s*a,n[2]=-o*a+s*i}}var KP=.01,qP=1/100,JP=1;function YP(e,t,n){if(!n)return 0;let r=1/0;for(let i=0;i<t;i++){let t=e[i*3]-n.camX,a=e[i*3+1]-n.camY,o=e[i*3+2]-n.camZ,s=t*t+a*a+o*o;s<r&&(r=s)}return Math.sqrt(r)*n.tolAngle}function XP(e,t,n,r,i,a,o,s,c){if(t!==e.lastVersion||e.lastOffX===void 0)return!1;let l=e.rewriteTol;if(c){let t=c.camX-e.lastCamX,n=c.camY-e.lastCamY,r=c.camZ-e.lastCamZ;l=Math.max(0,l-Math.sqrt(t*t+n*n+r*r)*c.tolAngle)}let u=(n-e.lastOffX)**2+(r-e.lastOffY)**2+(i-e.lastOffZ)**2,d=(a-e.lastHeadX)**2+(o-e.lastHeadY)**2+(s-e.lastHeadZ)**2;return u<=l*l&&d<=l*l}function ZP(e,t,n,r,i,a,o,s,c,l,u){e.lastVersion=t,e.lastOffX=n,e.lastOffY=r,e.lastOffZ=i,e.lastHeadX=a,e.lastHeadY=o,e.lastHeadZ=s,e.lastCamX=u?.camX??0,e.lastCamY=u?.camY??0,e.lastCamZ=u?.camZ??0,e.rewriteTol=YP(c,l,u)}function QP(e,t,n,r,i,a){let o=t.userData,s=o.useTrail,c=o.orbitCenter,l=e.trailAnchor??e.position,u=c.x-r[0],d=c.y-r[1],f=c.z-r[2],p=l[0]-c.x,m=l[1]-c.y,h=l[2]-c.z,g=e.lagrangeTrail?NaN:n.newestJd+n.count*1e-9;if(XP(o,g,u,d,f,p,m,h,a))return;let{posArr:_,trailArr:v,fullArr:y}=gN(t),b=e.lagrangeTrail?GP(i):null,x=vN(e,n,_,c.x,c.y,c.z,r,b??void 0);_N(t,_,v,y,x,!0,s),ZP(o,g,u,d,f,p,m,h,_,x,a)}function $P(e,t,n,r,i){let{posArr:a,trailArr:o,fullArr:s,capacity:c}=gN(e),l=Math.min(t.length,c);for(let e=0;e<l;e++)a[e*3]=t[e][0]+n,a[e*3+1]=t[e][1]+r,a[e*3+2]=t[e][2]+i;if(e.userData.lastOffX=void 0,e.userData.isFatLine){dN(e.geometry,a,o,s,l);return}e.geometry.getAttribute(`position`).needsUpdate=!0}function eF(e,t,n,r,i){let a=t.userData.trailBuffer;if(a){QP(e,t,a,n,r,i);return}let o=t.userData.sourceCurve;if(!o){if(!t.userData.curvePending||!e.orbitElements)return;o=cN(Gv(e.orbitElements,r),512).points,t.userData.sourceCurve=o,t.userData.curveJd=r,t.userData.curvePending=!1}let s=t.userData.isOpenCurve,c=t.userData.useTrail,l=t.userData.orbitCenter,u=l.x,d=l.y,f=l.z;if(e.data.satrec){let n=e.data.n/360,i=n>0?1/n/512:0,a=t.userData.curveJd;(o.length===0||a===void 0||Math.abs(r-a)>=i)&&(o=oN(e.data.satrec,r,n,512),t.userData.sourceCurve=o,t.userData.curveJd=r)}else if(e.orbitElements){if(e.rederiveElements){let n=t.userData.elementsJd??r,i=e.orbitElements.n,a=i>0?360/i:1/0;if(Math.abs(r-n)>Math.min(a*qP,JP)){let n=e.rederiveElements(r);n&&(Object.assign(e.orbitElements,n),o=cN(e.orbitElements,512).points,t.userData.sourceCurve=o,t.userData.curveJd=r,t.userData.elementsJd=r)}}let n=e.orbitElements.omDot??0,i=e.orbitElements.wDot??0,a=Math.max(Math.abs(n),Math.abs(i));if(a>0){let n=t.userData.curveJd??r;a*Math.abs(r-n)>KP&&(o=cN(Gv(e.orbitElements,r),512).points,t.userData.sourceCurve=o,t.userData.curveJd=r)}}let p=e.trailAnchor??e.position,m=t.userData,h=u-n[0],g=d-n[1],_=f-n[2],v=p[0]-u,y=p[1]-d,b=p[2]-f;if(XP(m,o,h,g,_,v,y,b,i))return;let x=$y(e,o,s,u,d,f);if(x.length<2)return;let{posArr:S,trailArr:C,fullArr:w,capacity:T}=gN(t),E=u-n[0],D=d-n[1],O=f-n[2],k=Math.min(x.length,T);for(let e=0;e<k;e++)S[e*3]=x[e][0]+E,S[e*3+1]=x[e][1]+D,S[e*3+2]=x[e][2]+O;_N(t,S,C,w,k,s,c),m.trailLocalPositions=x,ZP(m,o,h,g,_,v,y,b,S,k,i)}function tF(e,t,n){let r=e===$.CAPPED;return{groupVisible:e===$.CLOSE||e===$.FULL||r&&t,orbitVisible:e===$.FULL||e===$.CLOSE&&n,showLabel:e===$.FULL||r&&t,isClose:e===$.CLOSE}}function nF(e,t,n){return{groupVisible:e===$.CLOSE||e===$.FULL,orbitVisible:e===$.FULL&&t||e===$.CLOSE&&n,showLabel:e===$.FULL&&t,isClose:t&&e===$.CLOSE}}var rF=4/2,iF=(.1*10)**2,aF=new J,oF=[],sF=oF;function cF(e){return rk(oF,e,sk)}var lF={x:0,y:0,left:0,right:0,h:0},uF=new Vi,dF={ox:0,oy:0},fF=new J,pF=new J;function mF(e,t,n,r,a,o,s,c,l,u,d,f,p,m,h){let g=n.layers,_=!g.isVisible(`orbits`),v=g.isVisible(`nomenclature`),y=t.fov*Math.PI/180,b=f.domElement.clientWidth,x=f.domElement.clientHeight,S=x/(2*Math.tan(y/2)),C=[r[0]+t.position.x,r[1]+t.position.y,r[2]+t.position.z],w=r,T=t.matrixWorldInverse;for(let n of e.values()){if(n.cachedDist=L_(C,n.body.position),n.isCrashed||n.noPhysical){let e=n.noPhysical===`model`,t=sg(n.cachedDist)<(n.isCrashed||e?.1:1),r=null;if(t){let t=i().messages;r=n.isCrashed?t.body_note_crash_site():e?t.body_note_no_model():t.body_note_no_radius()}eD(n,`missing`,r)}let e=n.label;if(!e)continue;n.labelAnchorOffscreen=!1;let r=n.noPhysical?0:n.radiusScene;if(!r){e.position.set(0,0,0);continue}let[a,o,s]=n.body.position;p.set(a-w[0],o-w[1],s-w[2]).applyMatrix4(T);let c=p.x,l=p.y,u=p.z,d=u*u,f=r*r;if(d<=f){e.position.set(0,0,0),n.labelAnchorOffscreen=!0;continue}let m=r/n.cachedDist*S;if(m<1){e.position.set(0,0,0);continue}if(m>=16){let i=n.cachedDist,d=1/i,f=c*d,m=l*d,h=u*d,g=r*d,_=Math.sqrt(Math.max(1-g*g,0)),v=1-f*f,y=-f*m,b=-f*h,x=Math.hypot(v,y,b);x<1e-4&&(v=-m*f,y=1-m*m,b=-m*h,x=Math.hypot(v,y,b));let S=g/x,C=f*_+v*S,T=m*_+y*S,E=h*_+b*S;p.set(C*i-c,T*i-l,E*i-u).applyQuaternion(t.quaternion),e.position.copy(p),pF.set(a-w[0]+p.x,o-w[1]+p.y,s-w[2]+p.z).project(t),n.labelAnchorOffscreen=Math.abs(pF.x)>1||Math.abs(pF.y)>1;continue}if(n.semiAxesScene&&n.mesh)tP(c,l,u,QN(n.mesh.getWorldQuaternion(uF),T,n.semiAxesScene),S,dF),p.set(dF.ox,dF.oy,0).applyQuaternion(t.quaternion);else{let e=f/(d-f);p.set(e*c,e*l,0).applyQuaternion(t.quaternion)}e.position.copy(p)}let E=oF,D=b*.5,O=x*.5,k=0;for(let t of e.values()){let e=t.noPhysical?0:t.radiusScene;if(!e)continue;let n=t.cachedDist,[r,i,a]=t.body.position,o=t.model?.userData.occluderSpheres;if(t.model&&o?.length){let e=iO(t),s=t.model.position;for(let c of o){let o=c.r*e;if(fF.copy(c.center).applyQuaternion(t.model.quaternion).add(s).multiplyScalar(e),p.set(r-w[0]+fF.x,i-w[1]+fF.y,a-w[2]+fF.z).applyMatrix4(T),p.z>=o||p.lengthSq()<=o*o)continue;let l=p.z*p.z;(l<=o*o||o*S/Math.sqrt(l-o*o)>=16)&&$N(cF(k++),p.x,p.y,p.z,o,S,D,O,t.body.data.id,n)}continue}p.set(r-w[0],i-w[1],a-w[2]).applyMatrix4(T);let s=p.x,c=p.y,l=p.z;if(l>=e)continue;let u=l*l;(u<=e*e||e*S/Math.sqrt(u-e*e)>=16)&&(t.semiAxesScene&&t.mesh?eP(cF(k++),s,c,l,QN(t.mesh.getWorldQuaternion(uF),T,t.semiAxesScene),S,D,O,t.body.data.id,n):$N(cF(k++),s,c,l,e,S,D,O,t.body.data.id,n))}E.length=k;let A=n.visibility.focusedSystemId,j=!1,M=a?CM(n.getBody(a),e):void 0;for(let r of e.values()){let{body:i,group:s,trail:c}=r,l=r.cachedDist,u,d,f=i.data.id===a,p=A!==null&&i.data.id===A;if(r.mesh===null&&!gn(i.data.objectType)){let t=i.data.objectType;if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){let t=!0,r=f?void 0:N_(i.data.id);if(r){let a=e.get(r)?.body??n.getBody(r);a&&L_(i.position,a.position)/L_(C,a.position)*S<16&&(t=!1)}s.visible=t,c&&(c.visible=t),u=t,d=!1}else{let e=n.visibility.getPlanetVisibility(i,l)!==$.HIDE&&n.visibility.hasFullRendering(i);s.visible=e,c&&(c.visible=e),u=e,d=!1}}else{let e=i.data.objectType===G.MOON,t=e?n.visibility.getMoonVisibility(i):n.visibility.getPlanetVisibility(i,l),r=e?tF(t,o,f):nF(t,n.visibility.hasFullRendering(i),f||p);s.visible=r.groupVisible,c&&(c.visible=r.orbitVisible),u=r.showLabel,d=r.isClose}if(r.outOfRange&&(s.visible=!1,c&&(c.visible=!1),u=!1),r.starPoint){let e=r.radiusScene/l*S,t=e<rF;if(r.starPoint.visible=t,t){let t=r.starPoint.material,n=e/rF,i=Math.max(ej*n*n,3);t.uniforms.uIntensity.value=i}s.visible=!0,d=!t,u=!d}if(r.isMinor&&!f&&c&&!n.visibility.isPinned(i.data.id)&&(c.visible=!1),h&&c?.visible){let e=c.userData.orbitCenter;e&&e.distanceToSquared(aF.set(w[0],w[1],w[2]))>iF&&(c.visible=!1)}_&&c&&(c.visible=!1),s.matrixWorldAutoUpdate=s.visible;let{label:m}=r;if(!s.visible&&m&&m.parent===s?(s.remove(m),m.element.remove()):s.visible&&m&&m.parent!==s&&s.add(m),r.mesh&&r.radiusScene>0){let e=!f&&!p&&r.radiusScene/l*S<.5;e!==r.meshSubPixel&&(r.meshSubPixel=e,e?r.mesh.layers.disable(0):r.mesh.layers.enable(0))}fk(r,u,d,l,S,a)&&(j=!0);let g=r.radiusScene>0?r.radiusScene/l*S:0;GM(r,v&&i.data.id===M,g,t,b,x)}for(let[e,t]of c)t.visible=n.visibility.isAsteroidGroupVisible(x_(e));for(let[e,t]of l)t.visible=n.visibility.isSpacecraftGroupVisible(x_(e));for(let[e,t]of u)t.visible=n.visibility.isMoonGroupVisible(e);if(E.length>0){let n=a?N_(a):null;for(let r of e.values()){if(!r.label?.visible||!hk(r,t,w,b,x,lF))continue;let e=r.body.data.id;pk(lF.x,lF.y,r.cachedDist,e,E,e===a?n:null)&&(r.label.visible=!1)}}if((m||j||++d>=3)&&(d=0,Ok(e,b,x,t,a,n,s,E,r)),kk(e,b,x,t,r),M){let t=e.get(M);t&&YM(t)}for(let n of e.values()){let e=n.trail;if(!e?.visible)continue;let r=e.material;r.uniforms.uCenterOffset.value.set(-t.position.x,-t.position.y,-t.position.z);let i=n.body.data.id===a,o=s.has(n.body.data.id);r.uniforms.uAlphaMultiplier.value=o?2:i?1.75:1;let c=e.userData.isOpenCurve===!1;r.uniforms.uAlphaMin.value=i&&c?.15:0,r.uniforms.uShowFull.value=+!!i}return d}function hF(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function gF(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function _F(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function vF(e,t){let n=e.arcs[t].points.length,r=t=>e.endOrbits.find(e=>e.at===t);return{from:t===0?r(`departure`)?.trimFrom??0:0,to:t===e.arcs.length-1?r(`arrival`)?.trimTo??n:n}}function yF(e,t){let n=e.arcs[0],r=e.arcs[e.arcs.length-1];if(!n||!r)return null;let i=t=>e.endOrbits.find(e=>e.at===t)??null,a=i(`departure`),o=i(`arrival`),s=e=>e&&e.approach.length>1?e:null,c=s(a),l=s(o),u=e=>e&&e.pointJds&&e.points.length>1&&e.pointJds.length===e.points.length?{points:e.points,jds:e.pointJds}:null,d=u(a),f=o?.surfaceJd===void 0?u(o):null,p=Math.min(n.startJd,a?.surfaceJd??1/0),m=Math.max(r.endJd,o?.surfaceJd??l?.jds[l.jds.length-1]??-1/0),h=d?p-bF(d):p,g=f?m+bF(f):m;if(t<h||t>g)return null;if(a&&d&&t<(c?.jds[0]??n.startJd))return{r:xF(d,t),centerId:a.anchorId};if(c&&t<=c.jds[c.jds.length-1])return{r:SF(c.approach,c.jds,t),centerId:c.anchorId};if(o&&t>=(l?.jds[0]??r.endJd)){let e=o.surfaceJd??l?.jds[l.jds.length-1]??r.endJd;if(f&&(!l||t>e))return{r:xF(f,t),centerId:o.anchorId};if(l)return{r:SF(l.approach,l.jds,Math.min(t,e)),centerId:o.anchorId}}let _=e.arcs.findIndex(e=>t>=e.startJd&&t<=e.endJd),v=_>=0?_:e.arcs.length-1,{points:y,jds:b}=e.arcs[v];if(y.length===0)return null;if(y.length===1||b.length!==y.length)return{r:y[0],centerId:e.centerId};let{from:x,to:S}=vF(e,v);return{r:SF(y,b,t,x,S),centerId:e.centerId}}function bF(e){return e.jds[e.jds.length-1]-e.jds[0]}function xF(e,t){let n=bF(e),r=e.jds[0],i=n>0?r+((t-r)%n+n)%n:t;return SF(e.points,e.jds,i)}function SF(e,t,n,r=0,i=e.length){if(i-r<2)return e[r];let a=r+1;for(;a<i-1&&t[a]<n;)a++;let o=t[a]-t[a-1],s=o>0?Math.min(1,Math.max(0,(n-t[a-1])/o)):0;return hF(e[a-1],_F(gF(e[a],e[a-1]),s))}var CF=Math.PI/180,wF=Math.cos(ig*CF),TF=Math.sin(ig*CF);function EF(e,t,n,r){let i=Math.cos(e*CF),a=Math.sin(e*CF),o=Math.cos(t*CF),s=Math.sin(t*CF),c=Math.cos(n*CF),l=Math.sin(n*CF);return{m11:c*i-l*a*o,m12:-c*a-l*i*o,m21:l*i+c*a*o,m22:-l*a+c*i*o,m31:a*s,m32:i*s,equatorial:r}}function DF(e,t,n){let r=n.m11*e+n.m12*t,i=n.m21*e+n.m22*t,a=n.m31*e+n.m32*t;if(n.equatorial){let e=i*wF+a*TF,t=-i*TF+a*wF;i=e,a=t}return[r,i,a]}function OF(e){let t=10/rg;return[e[0]*t,e[2]*t,-e[1]*t]}function kF(e,t,n){let{a:r,e:i,ma:a,n:o,epoch:s,q:c,tp:l}=e,{om:u,w:d}=Gv(e,t),f=e.equatorial??!1;if(!isFinite(r)||r===0||!isFinite(o)||o<=0){if(c==null||l==null||!isFinite(c)||!isFinite(l)||c<=0)return null;let r=Cg(c,l,t);if(!r)return null;let i=n&&n>0?n:$_,a=r.r*rg,o=2*c*rg;return AF(a,r.nu,o,1,i,d,e.i,u,f)}if(!isFinite(i)||!isFinite(a))return null;let p=r*rg,m=o*CF/ev,h=n&&n>0?n:m*m*Math.abs(p)*Math.abs(p)*Math.abs(p);if(!isFinite(h)||h<=0)return null;let g=(a+o*(t-s))*CF,_,v;if(i<1||r>0){let e=Math.min(i,.9999999),t=bg(g,e),n=1-e*Math.cos(t);_=Math.atan2(Math.sqrt(1-e*e)*Math.sin(t),Math.cos(t)-e),v=p*n}else{let e=Sg(g,i);if(!isFinite(e))return null;let t=i*Math.cosh(e)-1;if(Math.abs(t)<1e-15)return null;_=Math.atan2(Math.sqrt(i*i-1)*Math.sinh(e)/t,(i-Math.cosh(e))/t),v=p*(1-i*Math.cosh(e))}if(!isFinite(v)||v<=0)return null;let y=p*(1-i*i);return!isFinite(y)||y<=0?null:AF(v,_,y,i,h,d,e.i,u,f)}function AF(e,t,n,r,i,a,o,s,c){let l=Math.cos(t),u=Math.sin(t),d=Math.sqrt(i/n),f=EF(a,o,s,c),p=DF(e*l,e*u,f),m=DF(-d*u,d*(r+l),f);return!isFinite(p[0]+p[1]+p[2])||!isFinite(m[0]+m[1]+m[2])?null:{r:p,v:m,mu:i}}var jF={cruise:`#7fdbff`,boost:`#ffb454`,brake:`#ff8c69`,spiral:`#c9a0ff`,"spiral-out":`#9b7fd4`,"spiral-in":`#9b7fd4`};jF.cruise,jF.boost,jF.brake,jF.spiral,jF[`spiral-out`],jF[`spiral-in`];var MF={notice:`#8ab4f8`,caution:`#f2b23e`,severe:`#ff6b5a`},NF=3,PF=1,FF=2,IF=.6,LF=1.5,RF=.3,zF=1.5,BF=.85,VF=60,HF=.018,UF=.026,WF=`#ffffff`,GF=4,KF=1.5,qF=9,JF=1,YF={notice:GF-3,caution:GF-2,severe:GF-1},XF=[`notice`,`caution`,`severe`],ZF=.03,QF=.2;function $F(e){let t=document.createElement(`canvas`);t.width=t.height=64;let n=t.getContext(`2d`);return n.beginPath(),n.arc(64/2,64/2,64/2-10,0,Math.PI*2),n.fillStyle=e,n.fill(),n.lineWidth=6,n.strokeStyle=`rgba(0,0,0,0.65)`,n.stroke(),new Mc(t)}function eI(e){let t=document.createElement(`canvas`);t.width=t.height=64;let n=t.getContext(`2d`);return n.beginPath(),n.moveTo(64/2,8),n.lineTo(56,56),n.lineTo(8,56),n.closePath(),n.fillStyle=e,n.fill(),n.lineWidth=6,n.lineJoin=`round`,n.strokeStyle=`rgba(0,0,0,0.65)`,n.stroke(),new Mc(t)}function tI(e,t,n,r){let i=[];for(let a=r.from;a<r.to;a++)e.jds[a]>=t&&e.jds[a]<=n&&i.push(e.points[a]);return i}function nI(e,t){let n=new ss(new qo({map:e,transparent:!0,sizeAttenuation:!1,depthTest:!1}));return n.scale.setScalar(t),n.renderOrder=GF,n}function rI(e,t,n,r){let{canvas:i,color:a,onSelect:o,onHover:s}=r,c=document.createElement(o?`button`:`div`);c instanceof HTMLButtonElement&&(c.type=`button`),c.className=e===`step`?`scene-path-label scene-path-label--step`:`scene-path-label${o?``:` scene-path-label--static`}`,c.setAttribute(`aria-label`,`${t} \u2014 ${n}`);let l=document.createElement(`span`);l.className=`scene-path-label__halo`,a&&(l.style.border=`2px solid ${a}`,l.style.background=`${a}22`);let u=document.createElement(`span`);u.className=`scene-path-label__text`;let d=document.createElement(`span`);d.className=`scene-path-label__name`,d.dir=`auto`,d.textContent=t;let f=document.createElement(`span`);f.className=`scene-path-label__when`,f.dir=`auto`,f.textContent=n,u.append(d,f),c.append(l,u),o&&(Rk(c,i),SM(c,o)),s&&(c.addEventListener(`mouseenter`,()=>s(!0)),c.addEventListener(`mouseleave`,()=>s(!1)));let p=new tk(c);return p.center.set(0,.5),p}var iI=class{group=new Ra;arcs=[];rings=[];markers=[];labels=[];drawnSteps=[];craft=null;path=null;center=null;layer=null;offset=new J;projected=new J;rects=[];order=[];hovered=null;tint=new X;constructor(e,t){this.scene=e,this.canvas=t,this.group.frustumCulled=!1,this.scene.add(this.group)}get centerId(){return this.center}get isEmpty(){return this.center===null}get plan(){return this.path}setLayer(e){this.layer=e,this.group.traverse(t=>t.layers.set(e))}set(e,t=[],n=[],r=[]){this.clear(),this.path=e?.path??null,this.center=e?.path.centerId??t[0]?.path.centerId??null;let i=e!==null;for(let e of t)this.addArcs(e.path,i?LF:FF,i?RF:IF,e.id),this.addEndLabels(e,i);e&&(this.addPlan(e,r),this.addHazards(e.path,n)),this.applyHover(),this.layer!==null&&this.setLayer(this.layer)}addHazards(e,t){let n=[...t].sort((e,t)=>XF.indexOf(e.severity)-XF.indexOf(t.severity));for(let t of n){let n=MF[t.severity];for(let n of t.bands)e.arcs.forEach((t,r)=>{this.addLine(tI(t,n.startJd,n.endJd,vF(e,r)),MF[n.severity],qF,JF,null,{renderOrder:YF[n.severity]})});if(this.mergeIntoStep(t,n))continue;let r=yF(e,t.startJd);if(!r)continue;let i=OF(r.r),a=r.centerId===e.centerId?null:r.centerId,o=nI(eI(n),ZF);this.group.add(o),this.markers.push({sprite:o,local:i,anchorId:a});let s=document.createElement(`div`);s.className=`scene-hazard-label`,s.style.color=n,s.textContent=t.label;let c=new tk(s);c.center.set(0,.5),this.group.add(c),this.labels.push({object:c,local:i,anchorId:a,owner:null,width:0,height:0,dimmed:!1,faint:!0})}}mergeIntoStep(e,t){let n=e.kind===`aeroassist`?`aero-pass`:e.kind===`belt-crossing`?`assist`:null;if(!n)return!1;let r=null,i=1/0;for(let{step:t,label:a}of this.drawnSteps){if(t.kind!==n||e.bodyId&&t.bodyId!==e.bodyId)continue;let o=Math.abs(t.jd-e.peakJd);o<i&&(i=o,r=a)}if(!r)return!1;let a=r.object.element,o=document.createElement(`span`);return o.className=`scene-path-label__hazard`,o.style.color=t,o.dir=`auto`,o.textContent=e.label,a.querySelector(`.scene-path-label__text`)?.append(o),a.setAttribute(`aria-label`,`${a.getAttribute(`aria-label`)} — ${e.label}`),!0}addPlan(e,t){let n=e.path;this.addArcs(n,NF,PF,null,!0),this.addEndOrbits(n),this.addSteps(n,t);for(let e of this.markers)this.group.add(e.sprite);this.craft={sprite:nI($F(WF),UF),local:[0,0,0],anchorId:null},this.craft.sprite.visible=!1,this.group.add(this.craft.sprite)}addSteps(e,t){for(let n of t){let t=yF(e,n.jd);if(!t)continue;let r=OF(t.r),i=t.centerId===e.centerId?null:t.centerId,a=nI($F(WF),HF);this.markers.push({sprite:a,local:r,anchorId:i});let o=rI(`step`,n.name,n.when,{canvas:this.canvas,onSelect:n.onPick});this.group.add(o),this.labels.push({object:o,local:r,anchorId:i,owner:null,width:0,height:0,dimmed:!1,faint:!1,step:!0,sprite:a}),this.drawnSteps.push({step:n,label:this.labels[this.labels.length-1]})}}addEndLabels(e,t=!1){let{path:n,onSelect:r}=e,i=n.arcs[0],a=n.arcs[n.arcs.length-1],o=n.stops.find(e=>e.kind===`departure`),s=[{local:OF(n.meeting.r),end:e.arrival,color:jF[a?.kind??`cruise`]}];o&&s.push({local:OF(o.r),end:e.departure,color:jF[i?.kind??`cruise`]});for(let{local:n,end:i,color:a}of s){if(!i.name)continue;let o=rI(`end`,i.name,i.when,{canvas:this.canvas,color:a,onSelect:r,onHover:e.onHover});t&&o.element.classList.add(`scene-path-label--faint`),this.group.add(o),this.labels.push({object:o,local:n,anchorId:null,owner:r?e.id:null,width:0,height:0,dimmed:!1,faint:t})}}setHovered(e){this.hovered!==e&&(this.hovered=e,this.applyHover())}applyHover(){for(let e of this.arcs){if(e.owner===null)continue;let t=e.owner===this.hovered,n=e.line.material;n.uniforms.uColor.value.set(e.color).multiplyScalar(t?PF:e.brightness),n.uniforms.uLineWidth.value=t?NF:e.width}for(let e of this.labels)e.owner!==null&&e.object.element.classList.toggle(`scene-path-label--lit`,e.owner===this.hovered)}addArcs(e,t,n,r=null,i=!1){let a=i&&e.frame===`planetary`,o=t=>a&&e.endOrbits.some(e=>e.at===t&&e.approach.length>1);e.arcs.forEach((a,s)=>{let{from:c,to:l}=i?vF(e,s):{from:0,to:a.points.length};this.addLine(a.points.slice(c,l),jF[a.kind],t,n,r,{fadeIn:s===0&&o(`departure`),fadeOut:s===e.arcs.length-1&&o(`arrival`)})})}addEndOrbits(e){for(let t of e.endOrbits){let n=this.anchorOf(e,t),r=(t.ground??[]).filter(e=>e.to>e.from);if(r.length>0){let e=0;for(let i of r)i.from>e&&this.addLine(t.approach.slice(Math.max(0,e-1),i.from+1),jF.cruise,NF,PF,null,{anchorId:n}),this.addLine(t.approach.slice(i.from,i.to),jF.cruise,NF,PF,null,{anchorId:n,renderOrder:KF}),e=i.to;e<t.approach.length&&this.addLine(t.approach.slice(Math.max(0,e-1)),jF.cruise,NF,PF,null,{anchorId:n})}else if(t.turn){let{from:e,to:r}=t.turn,i=t.approach.slice(0,e+1),a=t.approach.slice(r-1);for(let e of[i,a])e.length<2||this.addLine(e,jF.cruise,NF,PF,null,{anchorId:n});this.addLine(t.approach.slice(e>0?e-1:0,r),jF.cruise,zF,BF,null,{anchorId:n})}else this.addLine(t.approach,jF.cruise,NF,PF,null,{anchorId:n});let i=this.addLine(t.points,jF.cruise,zF,BF,null,{anchorId:n});if(!i)continue;let a=n===null?OF(t.center):[0,0,0];i.line.visible=!1,this.rings.push({arc:i,local:a,radius:Q(t.radiusKm),world:new J})}}anchorOf(e,t){return t.anchorId===e.centerId?null:t.anchorId}addLine(e,t,n,r,i,a={}){let o=e.length;if(o<2)return null;let s=new Float64Array(o*3);for(let t=0;t<o;t++){let[n,r,i]=OF(e[t]);s[t*3]=n,s[t*3+1]=r,s[t*3+2]=i}let c=new Float32Array(o*3),l=new Float32Array(o).fill(1),u=Math.max(1,Math.round(o*QF));for(let e=0;e<u;e++){let t=(e+1)/(u+1);a.fadeIn&&(l[e]=t),a.fadeOut&&(l[o-1-e]=t)}let d=hN(o,c,l,l,o,t,n,r);d.frustumCulled=!1,d.renderOrder=a.renderOrder??GF,this.group.add(d);let f={line:d,owner:i,anchorId:a.anchorId??null,color:t,brightness:r,width:n,local:s,positions:c,alphas:l,count:o};return this.arcs.push(f),f}setClock(e){let t=this.craft;if(!t||!this.path)return;let n=yF(this.path,e);t.sprite.visible=n!==null,n&&(t.local=OF(n.r),t.anchorId=n.centerId===this.path.centerId?null:n.centerId)}reposition(e,t,n){if(this.center===null)return;let r=e[0]-t[0],i=e[1]-t[1],a=e[2]-t[2],o=new Map,s=e=>{if(e===null)return[r,i,a];let s=o.get(e);if(s)return s;let c=n(e),l=c?[c[0]-t[0],c[1]-t[1],c[2]-t[2]]:[r,i,a];return o.set(e,l),l};for(let e of this.arcs){let[t,n,r]=s(e.anchorId);for(let i=0;i<e.count;i++)e.positions[i*3]=e.local[i*3]+t,e.positions[i*3+1]=e.local[i*3+1]+n,e.positions[i*3+2]=e.local[i*3+2]+r;dN(e.line.geometry,e.positions,e.alphas,e.alphas,e.count)}for(let e of this.markers){let[t,n,r]=s(e.anchorId);e.sprite.position.set(e.local[0]+t,e.local[1]+n,e.local[2]+r)}for(let e of this.labels){let[t,n,r]=s(e.anchorId);e.object.position.set(e.local[0]+t,e.local[1]+n,e.local[2]+r)}if(this.craft){let{sprite:e,local:t,anchorId:n}=this.craft,[r,i,a]=s(n);e.position.set(t[0]+r,t[1]+i,t[2]+a)}for(let e of this.rings){let[t,n,r]=s(e.arc.anchorId);e.world.set(e.local[0]+t,e.local[1]+n,e.local[2]+r)}}updateCameraOffset(e){if(this.arcs.length!==0){this.offset.set(-e.x,-e.y,-e.z);for(let e of this.arcs)e.line.material.uniforms.uCenterOffset.value.copy(this.offset);for(let t of this.rings){let n=t.world.distanceTo(e);t.arc.line.visible=n<t.radius*VF}}}setVisible(e){this.group.visible=e}reserveLabelSpace(e,t,n){if(!this.group.visible||this.labels.length===0){Ek(this.rects,0);return}this.order.length=0;for(let r of this.labels){if(r.faint)continue;let i=r.object.element;if(!r.width&&!r.dimmed&&(r.width=i.offsetWidth,r.height=i.offsetHeight),!r.width||(this.projected.copy(r.object.position).project(e),!iT(this.projected.z)))continue;let a=(this.projected.x*.5+.5)*t,o=(-this.projected.y*.5+.5)*n,s=r.object.position.distanceTo(e.position);if(r.step){let e=pk(a,o,s,``,sF);if(this.setStepVisible(r,!e),e)continue}this.order.push({label:r,left:a-16,y:o,distance:s})}this.order.sort((e,t)=>e.label.step===t.label.step?e.distance-t.distance:e.label.step?1:-1);let r=0;for(let{label:e,left:t,y:n}of this.order){let i=t+16+e.width,a=!1;for(let o=0;o<r;o++){let r=this.rects[o];if(t<r.right&&i>r.left&&Math.abs(n-r.y)<(e.height+r.h)/2){a=!0;break}}if(this.setLabelDimmed(e,a),a)continue;let o=this.rects[r];o||(o={left:0,right:0,y:0,h:0},this.rects[r]=o),o.left=t,o.right=i,o.y=n,o.h=e.height,r++}Ek(this.rects,r)}setStepVisible(e,t){e.object.visible=t,e.sprite&&(e.sprite.visible=t)}setLabelDimmed(e,t){e.dimmed!==t&&(e.dimmed=t,e.object.element.classList.toggle(`scene-path-label--dim`,t))}clear(){for(let e of this.arcs)this.group.remove(e.line),e.line.geometry.dispose(),e.line.material.dispose();for(let e of[...this.markers,...this.craft?[this.craft]:[]]){this.group.remove(e.sprite);let t=e.sprite.material;t.map?.dispose(),t.dispose()}for(let e of this.labels)this.group.remove(e.object),e.object.element.remove();this.arcs=[],this.rings=[],this.markers=[],this.labels=[],this.drawnSteps=[],this.craft=null,this.path=null,this.center=null}dispose(){this.clear(),this.scene.remove(this.group)}},aI=2,oI=1,sI=4,cI=200,lI=class{group=new Ra;slots=[];shown=0;layer=null;constructor(e){this.group.frustumCulled=!1,e.add(this.group)}get isEmpty(){return this.shown===0}set(e){let t=0;for(let n of e){if(n.pointsKm.length<2)continue;let e=this.slot(t++);e.bodyId=n.bodyId,e.count=Math.min(n.pointsKm.length,cI);for(let t=0;t<e.count;t++){let[r,i,a]=OF(n.pointsKm[t]);e.local[t*3]=r,e.local[t*3+1]=i,e.local[t*3+2]=a}}this.shown=t;for(let e=t;e<this.slots.length;e++)this.slots[e].line.visible=!1;this.group.visible=t>0}slot(e){for(;this.slots.length<=e;){let e=new Float32Array(cI*3),t=new Float32Array(cI).fill(1),n=hN(cI,e,t,t,0,jF.cruise,aI,oI);n.frustumCulled=!1,n.renderOrder=sI,this.layer!==null&&n.layers.set(this.layer),this.group.add(n),this.slots.push({line:n,bodyId:``,local:new Float64Array(cI*3),positions:e,alphas:t,count:0})}return this.slots[e]}setLayer(e){this.layer=e,this.group.traverse(t=>t.layers.set(e))}reposition(e,t){for(let n=0;n<this.shown;n++){let r=this.slots[n],i=e(r.bodyId);if(r.line.visible=i!==null,!i)continue;let a=i[0]-t[0],o=i[1]-t[1],s=i[2]-t[2];for(let e=0;e<r.count;e++)r.positions[e*3]=r.local[e*3]+a,r.positions[e*3+1]=r.local[e*3+1]+o,r.positions[e*3+2]=r.local[e*3+2]+s;dN(r.line.geometry,r.positions,r.alphas,r.alphas,r.count)}}updateCameraOffset(e){for(let t of this.slots)t.line.material.uniforms.uCenterOffset.value.set(-e.x,-e.y,-e.z)}},uI=30034e-10,dI=.45,fI=1.6,pI=.85,mI=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],hI=e=>Math.hypot(e[0],e[1],e[2]);function gI(e,t,n=uI){let r=hI(t);if(!(r>0))return null;let i=r*Math.cbrt(n/3),a=mI(e,t)/r,o=hI(e);if(Math.sqrt(Math.max(0,o*o-a*a))>pI*i)return null;let s=a/i;return s>=dI&&s<=fI?`EL1`:s<=-dI&&s>=-fI?`EL2`:null}function _I(){return{count:0,earliestStart:1/0,latestEnd:-1/0}}var vI=class{focused=!1;satSide=null;satJd=NaN;majSide=null;majJd=NaN;constructor(e){this.notices=e}update(e){let{jd:t,majorBodies:n,satellites:r}=e,i=null,a=NaN;n.count>0&&(Number.isFinite(n.latestEnd)&&t>n.latestEnd?(i=`after`,a=n.latestEnd):Number.isFinite(n.earliestStart)&&t<n.earliestStart?(i=`before`,a=n.earliestStart):i=`outside`);let o=r.kind===`covered`?null:r.kind,s=r.kind===`after`?jg(r.lastMs):NaN,c=e.focusedOutOfRange;if(!(c===this.focused&&o===this.satSide&&Object.is(s,this.satJd)&&i===this.majSide&&Object.is(a,this.majJd))){if(Object.assign(this,{focused:c,satSide:o,satJd:s,majSide:i,majJd:a}),!c&&o===null&&i===null){this.notices.dismiss(`out-of-range`);return}this.notices.notify({topic:`out-of-range`,focusedOutOfRange:c,satellites:o===`after`?{side:`after`,jd:s}:o===`gap`?{side:`gap`}:null,majorBodies:i===`after`||i===`before`?{side:i,jd:a}:i===`outside`?{side:`outside`}:null})}}},yI=new Map,bI=new J;function xI(e,t,n,r,i,a,o){let s=Ty(n,r,Cy(t));if(!s)return null;let c=`naif-${n.bodyNaifId}`,l=a.bodies.bodiesById.get(c);if(!l||!l.orientation)return null;let u=i.get(c);if(!u)return null;let d=l.data.radiusKm;if(!Number.isFinite(d)||d<=0)return null;let f=Math.PI/180,p=s.latDeg*f,m=s.lngDeg*f,h=kw(o.get(c),c,d,p,m);h&&yI.set(e.id,h);let g=h??yI.get(e.id),_,v,y;if(g)[_,v,y]=g.pointKm;else{let e=Math.cos(p);_=d*e*Math.cos(m),v=d*Math.sin(p),y=-d*e*Math.sin(m)}let b=pC(l.orientation,r,l.nutPrec),x=new J(_,v,y).applyQuaternion(b),S=g?bI.set(g.normal[0],g.normal[1],g.normal[2]).applyQuaternion(b):null;return e.parentId=c,{x:u[0]+Q(x.x),y:u[1]+Q(x.y),z:u[2]+Q(x.z),parentPos:u,up:S}}var SI=[0,0,0],CI=new Vi,wI=4,TI=0,EI=new Map;function DI(e){return e.primary.target===`velocity`||e.secondary?.target===`velocity`}function OI(e,t,n){let r=EI.get(e),i=r?.dir??null;if(r&&t!==r.jd){let e=Math.sign(t-r.jd),a=(n[0]-r.pos[0])*e,o=(n[1]-r.pos[1])*e,s=(n[2]-r.pos[2])*e,c=Math.hypot(a,o,s);c>1e-12&&(i=[a/c,o/c,s/c])}return EI.set(e,{jd:t,pos:[n[0],n[1],n[2]],dir:i}),i??void 0}function kI(e){let{jd:t,ctx:n,bodyObjects:r,focus:a,focusedBody:o,positionMap:s,diagnostics:c,trailView:l,frame:u,outOfRange:d}=e;n.chebStore?.ensure(t),n.probeStore?.ensure(t);let f=n.visibility.activeSystemId,p=f?e=>n.bodies.isInSystem(`naif-${e}`,f):void 0,m={jd:t,satellites:{kind:`covered`},majorBodies:_I(),focusedOutOfRange:!1},h=o?.data.id,g=gx(n.probeStore?.ridesAt(t)??[],h,e=>n.getBody(e)?.data.name),_=[];if(o){let e=new Set([o.data.id]),t=n.getBody(o.data.parentId);for(;t&&!e.has(t.data.id);)e.add(t.data.id),_.push({id:t.data.id,oldPos:[t.position[0],t.position[1],t.position[2]],bo:r.get(t.data.id)}),t=n.getBody(t.data.parentId)}s.clear(),s.set(`naif-0`,[0,0,0]);for(let e of n.bodies.bodiesById.values())s.set(e.data.id,e.position);for(let e of r.values())n.bodies.bodiesById.has(e.body.data.id)||s.set(e.body.data.id,e.body.position);let v=new Set,y=e=>{if(v.has(e))return;let t=n.bodies.bodiesById.get(e)??r.get(e)?.body;t&&C(t)},b=performance.now(),x=e=>{let t=n.bodies.hostRead.get(e);return t===void 0?!1:b-t<2e3?!0:(n.bodies.hostRead.delete(e),!1)},S=(e,r)=>{let i=n.bodies.elementRow(e),a=i&&s.get(i.parentId);if(!a)return null;let o=i.q==null?qv(i,t):Yv(i,t);return o?[a[0]-r[0]+o[0],a[1]-r[1]+o[1],a[2]-r[2]+o[2]]:null},C=e=>{if(v.has(e.data.id))return;v.add(e.data.id);let a=e.data,o=r.get(a.id);if(o&&u!==void 0&&a.id!==h&&!x(a.id)&&!o.group.visible&&!o.trail?.visible&&(a.orbitalSource===W.SPICE_PROBE||!gn(a.objectType))&&(o.staggerSlot??=TI++%wI,u%wI!==o.staggerSlot))return;let l=(n=!1)=>{o&&(o.outOfRange=!0),e.positionUnknown=!0,e.placedJd=t,!n&&a.id===h&&(m.focusedOutOfRange=!0)};if(a.unplaceable){l(!0);return}let d=n.chebStore?.has(a.id)??!1,f=a.orbitalSource===W.SPICE_PROBE;if(f){if(g.hidden.has(a.id)){l(!0);return}if(o){let e=g.credits.get(a.id);eD(o,`carrier`,e?i().messages.carried_by_scene_label({carrier:e}):null)}}if(a.visibleFromDays!==void 0&&t-2451545<a.visibleFromDays){l();return}let _;if(f)_=s.get(a.parentId)??[0,0,0];else{let e=s.get(a.parentId);if(!e){l(),c.warnOnce(`missing-parent`,a.id,()=>`computePosition[${a.id}]: parent ${a.parentId} not in positionMap — hiding`);return}_=e,c.clear(`missing-parent`,a.id)}let b=a.q!=null;if(!d&&!f&&(t<a.validityStart||t>a.validityEnd)){l(!a.satrec);return}let C,w,T;if(d){let r=n.chebStore.positionScene(a.id,t)??S(e,_);if(!r){l(!0);let e=n.chebStore.zoneCoverage(a.id);e&&(t<e.start||t>e.end)&&(m.majorBodies.count++,e.start<m.majorBodies.earliestStart&&(m.majorBodies.earliestStart=e.start),e.end>m.majorBodies.latestEnd&&(m.majorBodies.latestEnd=e.end),a.id===h&&(m.focusedOutOfRange=!0)),c.warnOnce(`cheb-null`,a.id,()=>{let n=e?t>=e.start&&t<=e.end:void 0,r=e?`[${e.start.toFixed(1)},${e.end.toFixed(1)}]`:`unknown`;return`chebStore.positionScene[${a.id}] returned null at jd=${t.toFixed(3)} (coverage=${r}, insideCoverage=${n}) — children of this body will read stale positionMap entry (pre-seeded) instead of falling to SSB`});return}C=_[0]+r[0],w=_[1]+r[1],T=_[2]+r[2]}else if(f){let i=n.probeStore?.probeWithCenter(a.id,t,p)??null;if(!i){l(),c.warnOnce(`probe-unavailable`,a.id,()=>{let e=n.probeStore?`no zone has both a loaded chunk and a sub-chunk covering this jd`:`no ProbeStore`;return`probe ${a.id} (${a.name??`unnamed`}): hidden — ${e}`});return}let u=i.probe.landed;if(u&&wy(i.probe,t)){let d=a.parentId;y(`naif-${u.bodyNaifId}`);let f=xI(a,i.probe,u,t,s,n,r);if(!f){l();return}if(c.clear(`probe-unavailable`,a.id),e.positionUnknown=!1,e.placedJd=t,d!==a.parentId&&e.trailBuffer?.clear(),o){o.outOfRange=!1;let e=u.isDestroyed;o.isLanded||=(Mk(o.labelHalo,`landed`),!0),o.isCrashed=e,o.model&&(o.model.visible=!e)}e.position[0]=f.x,e.position[1]=f.y,e.position[2]=f.z,e.orbitCenter&&(e.orbitCenter[0]=f.parentPos[0],e.orbitCenter[1]=f.parentPos[1],e.orbitCenter[2]=f.parentPos[2]),e.trailAnchor&&(e.trailAnchor[0]=f.parentPos[0],e.trailAnchor[1]=f.parentPos[1],e.trailAnchor[2]=f.parentPos[2]),s.set(a.id,e.position);let p=f.up;o?.mesh&&(p?vC(o.mesh,p):_C(o.mesh,e.position,f.parentPos)),o?.model&&(p?vC(o.model,p):_C(o.model,e.position,f.parentPos));return}let d=By(i.probe,t,i.fitCenterNaifId,n.chebStore??null,e=>s.has(e));if(!d){l(),c.warnOnce(`probe-unavailable`,a.id,()=>`probe ${a.id} (${a.name??`unnamed`}): hidden — stamped fit center is not placeable this frame`);return}let f=d.id,m=d.muKm3S2,g=xy(i.probe,t,m);if(!g){l(),c.warnOnce(`probe-unavailable`,a.id,()=>`probe ${a.id} (${a.name??`unnamed`}): hidden — sub-chunk evaluation returned null (uncoverable, non-finite fit, or missing mu for kepler_pure)`);return}c.clear(`probe-unavailable`,a.id),o?.isLanded&&(Mk(o.labelHalo,`flying`),o.isLanded=!1,o.isCrashed&&(o.isCrashed=!1,o.model&&(o.model.visible=!0),o.noPhysical||eD(o,`missing`,null)));let v=s.get(f_),b=s.get(d_),x=f===`naif-399`&&v!==void 0&&b!==void 0&&gI([Q(g[0]),Q(g[2]),-Q(g[1])],[b[0]-v[0],b[1]-v[1],b[2]-v[2]])!==null,S=x!==(e.lagrangeTrail??!1);e.lagrangeTrail=x;let E=a.parentId!==f;if((E||S)&&e.trailBuffer&&n.probeStore){let r=e.trailBuffer;r.clear(),r.needsPopulate=!1;let o=Wy(Ly(i.probe,t,m),a.validityEnd-a.validityStart,r.capacity,x);r.reconfigure(o.stepDays,o.epsilonScene,o.spanDays),Xy(r,n.probeStore,n.chebStore??null,a.id,f,t)}E&&(a.parentId=f),y(f);let D=s.get(f);if(!D){l(),c.warnOnce(`probe-unavailable`,a.id,()=>`probe ${a.id} (${a.name??`unnamed`}): hidden — fit center ${f} has no position this frame`);return}_=D;let O=Q(g[0]),k=Q(g[2]),A=-Q(g[1]);C=_[0]+O,w=_[1]+k,T=_[2]+A;let j=e.trailBuffer;if(j?.needsPopulate&&o?.trail?.visible&&n.probeStore&&(j.needsPopulate=!1,j.clear(),Xy(j,n.probeStore,n.chebStore??null,a.id,f,t)),j){let e=j.newestJd,r=t-e,o=j.stepDays*j.capacity,s=isFinite(e)&&(r<0||r>o);if(s&&a.id===h&&n.probeStore){j.clear();let e=Wy(Ly(i.probe,t,m),a.validityEnd-a.validityStart,j.capacity,x);j.reconfigure(e.stepDays,e.epsilonScene,e.spanDays),Xy(j,n.probeStore,n.chebStore??null,a.id,f,t)}else s?(j.clear(),j.append(t,O,k,A)):isFinite(e)?isFinite(j.epsilonScene)?r>=j.stepDays*.00390625&&n.probeStore&&j.readNewestPos(SI)&&Qy(j,Ky(n.probeStore,n.chebStore??null,a.id,f),e,[SI[0],SI[1],SI[2]],t):r>=j.stepDays&&j.append(t,O,k,A):j.append(t,O,k,A)}}else if(a.a===0&&!b&&!a.satrec)[C,w,T]=_;else{let e=a.satrec?yg(a.satrec,t):b?Yv(a,t):qv(a,t);if(!e){l();return}C=_[0]+e[0],w=_[1]+e[1],T=_[2]+e[2]}if(o&&(o.outOfRange=!1),e.positionUnknown=!1,e.placedJd=t,e.position[0]=C,e.position[1]=w,e.position[2]=T,(!Number.isFinite(C)||!Number.isFinite(w)||!Number.isFinite(T))&&c.warnOnce(`non-finite`,a.id,()=>{let e=s.has(a.parentId);return`computePosition[${a.id}] non-finite: pos=[${C},${w},${T}] parentId=${a.parentId} parentInPositionMap=${e} parentPos=[${_[0]},${_[1]},${_[2]}] isChebTracked=${d} isProbe=${f} objectType=${a.objectType}`}),e.orbitCenter&&(e.orbitCenter[0]=_[0],e.orbitCenter[1]=_[1],e.orbitCenter[2]=_[2]),e.trailAnchor&&(e.trailAnchor[0]=_[0],e.trailAnchor[1]=_[1],e.trailAnchor[2]=_[2]),s.set(a.id,e.position),o){if(o.trail&&e.orbitCenter){let e=o.trail.userData.orbitCenter;e&&e.set(_[0],_[1],_[2])}if(e.orientation&&(o.mesh||o.model))o.mesh&&mC(o.mesh,e.orientation,t,e.nutPrec),o.model&&mC(o.model,e.orientation,t,e.nutPrec),o.nomenclatureAnchor&&mC(o.nomenclatureAnchor,e.orientation,t,e.nutPrec);else if(QD(e)){let n=e.attitudeTrack;if(!e.pointingOverride&&n&&n.orientationAt(t,CI))o.mesh&&o.mesh.quaternion.copy(CI),o.model&&o.model.quaternion.copy(CI);else{let n=e.pointingOverride??e.pointing;if(n){let r=DI(n)?OI(a.id,t,e.position):void 0,i={bodyPos:e.position,parentPos:_,sunPos:s.get(d_),velocity:r};o.mesh&&MC(o.mesh,n,i),o.model&&MC(o.model,n,i)}else o.mesh&&_C(o.mesh,e.position,_),o.model&&_C(o.model,e.position,_)}}if(e.orientation)for(let n of o.rings)mC(n.mesh,e.orientation,t,e.nutPrec)}},w=n.visibility.focusedSystemId;for(let e of n.bodies.bodiesById.values()){if(e.data.objectType===G.MOON&&!(w!==null&&e.data.parentId===w)&&e.data.id!==h){s.set(e.data.id,e.position);continue}C(e)}for(let e of r.values())n.bodies.bodiesById.has(e.body.data.id)||C(e.body);if(m.satellites=n.refresher?.satelliteCoverage(t)??{kind:`covered`},d.update(m),o&&cn(o)){let e=n.getBody(o.featureAnchor.hostId);e&&s.has(e.data.id)?Bw(o,e,r.get(e.data.id),t):m.focusedOutOfRange=!0}let T=null;if(o&&m.focusedOutOfRange){let e=_.find(e=>e.bo&&!e.bo.outOfRange);if(e){T=e.id;let t=s.get(e.id)??e.oldPos;if(performance.now()-a.focusStartTime<a.focusDurationMs){a.focusTargetWorld[0]=t[0],a.focusTargetWorld[1]=t[1],a.focusTargetWorld[2]=t[2];let e=a.camTargetOffset;e&&a.camTargetWorld&&(a.camTargetWorld[0]=t[0]+e[0],a.camTargetWorld[1]=t[1]+e[1],a.camTargetWorld[2]=t[2]+e[2])}else{let n=t[0]-e.oldPos[0],r=t[1]-e.oldPos[1],i=t[2]-e.oldPos[2];a.focusTruePos[0]+=n,a.focusTruePos[1]+=r,a.focusTruePos[2]+=i,a.focusTargetWorld[0]=a.focusTruePos[0],a.focusTargetWorld[1]=a.focusTruePos[1],a.focusTargetWorld[2]=a.focusTruePos[2]}}}else if(o){let e=o.position,t=performance.now()-a.focusStartTime<a.focusDurationMs;a.focusTargetWorld[0]=e[0],a.focusTargetWorld[1]=e[1],a.focusTargetWorld[2]=e[2];let n=a.camTargetOffset;n&&a.camTargetWorld&&(a.camTargetWorld[0]=e[0]+n[0],a.camTargetWorld[1]=e[1]+n[1],a.camTargetWorld[2]=e[2]+n[2]);let r=a.camOriginOffset;r&&a.camOriginWorld&&(a.camOriginWorld[0]=e[0]+r[0],a.camOriginWorld[1]=e[1]+r[1],a.camOriginWorld[2]=e[2]+r[2]),t||(a.focusTruePos[0]=e[0],a.focusTruePos[1]=e[1],a.focusTruePos[2]=e[2])}let E=a.focusTruePos;for(let e of r.values()){let n=e.trail;if(n){if(!n.visible){n.userData.refreshDeferred=!0;continue}eF(e.body,n,E,t,l),n.userData.refreshDeferred=!1}}return{focusedOutOfRange:m.focusedOutOfRange,reanchorId:T}}function AI(e,t,n,r){let i=t.focusTruePos;for(let t of e.values()){let e=t.trail;!e||!e.visible||!e.userData.refreshDeferred||(eF(t.body,e,i,n,r),e.userData.refreshDeferred=!1)}}var jI=class{seen=new Map;bucket(e){let t=this.seen.get(e);return t||this.seen.set(e,t=new Set),t}warnOnce(e,t,n){let r=this.bucket(e);r.has(t)||(r.add(t),console.warn(n()))}clear(e,t){this.seen.get(e)?.delete(t)}},MI=Q(695700),NI=2,PI=new J;function FI(e,t,n,r,i){PI.subVectors(e,t);let a=PI.dot(n),o=Math.sqrt(Math.max(PI.lengthSq()-a*a,0)),s=o-Math.min(Math.max(o,r),i),c=Math.sqrt(s*s+a*a);return{dist:c,sinToPole:c>0?Math.abs(s)/c:1}}function II(e,t,n,r,i,a){let o=e.get(d_)?.body.position;if(!o)return;let[s,c,l]=t;for(let t of e.values()){if(!t.rings.length)continue;let[e,u,d]=t.body.position;for(let f of t.rings){let p=r||f.intensityScale>=.000980392156862745;f.mesh.visible=p;let m=r?1:p?f.intensityScale:0;f.material.uniforms.uIntensityScale.value=m;let h=f.material.uniforms.uSunDir.value;h.set(o[0]-e,o[1]-u,o[2]-d);let g=h.length(),_=MI/g;f.material.uniforms.uSunAngularRadius.value=_,f.material.uniforms.uLightScale.value=n?ST(g):1,h.normalize();let v=f.planetShadowOnRing;if(v.uPlanetCenter.value.set(e-s,u-c,d-l),t.mesh&&v.uPlanetPoleDir.value.set(0,1,0).applyQuaternion(t.mesh.quaternion),f.layers){let{dist:e,sinToPole:t}=FI(i,v.uPlanetCenter.value,v.uPlanetPoleDir.value,f.innerScene,f.outerScene),n=f.thicknessScene*t/Math.max(e,1e-9)*a,r=Math.min(Math.max(Math.ceil(n*NI),1),48);f.layers.count!==r&&(f.layers.count=r,f.material.uniforms.uLayerCount.value=r,f.material.uniforms.uLayerAlphaExp.value=1/r)}let y=f.planetShadow;y&&(y.uRingShadowIntensity.value=m,y.uRingShadowSunAngularRadius.value=_,y.uRingShadowSunDir.value.copy(h),y.uRingShadowPoleDir.value.copy(v.uPlanetPoleDir.value),y.uRingShadowCenter.value.copy(v.uPlanetCenter.value))}}}var LI=Math.PI/180,RI=2451545;function zI(e){let t=e-RI,n=(19.3871+.52402073*t)*LI;return((270.3871+.524038496*t+((10.691+3e-7*t)*Math.sin(n)+.623*Math.sin(2*n)+.05*Math.sin(3*n)+.005*Math.sin(4*n)+5e-4*Math.sin(5*n)))%360+360)%360}function BI(e,t,n){let r=e.length,i=r-1;for(let t=0;t<r-1;t++)if(n<e[t+1]){i=t;break}let a=(i+1)%r,o=i===r-1?360-e[i]:e[a]-e[i],s=(n-e[i])/o;return t[i]+(t[a]-t[i])*s}function VI(e,t){let n=e.seasonal;if(!n)return e;let r=BI(n.lsDeg,n.dustTauFactor,t),i=BI(n.lsDeg,n.dustScaleHeightKm,t),a=BI(n.lsDeg,n.pressureFactor,t),o=r*e.mieScaleHeightKm/i,s=(e,t)=>[e[0]*t,e[1]*t,e[2]*t];return{...e,rayleighScatterPerKm:s(e.rayleighScatterPerKm,a),mieScatterPerKm:s(e.mieScatterPerKm,o),mieAbsorptionPerKm:s(e.mieAbsorptionPerKm,o),mieScaleHeightKm:i,seasonal:void 0}}var HI=new WeakMap,UI=.25;function WI(e,t){if(!e.seasonal)return e;let n=Math.round(zI(t)/UI),r=HI.get(e);if(r&&r.lsQ===n)return r.params;let i=VI(e,n*UI);return HI.set(e,{lsQ:n,params:i}),i}var GI=new J,KI=new J,qI=[.2126,.7152,.0722];function JI(e,t,n){return n<=0?0:e<=t-n?n:e>=t+n?0:e<=t?n-(e-(t-n))**2/(2*n):(t+n-e)**2/(2*n)}function YI(e,t){let n=Math.max(t,0),r=e.rayleighScaleHeightKm*Math.exp(-n/e.rayleighScaleHeightKm),i=e.mieScaleHeightKm*Math.exp(-n/e.mieScaleHeightKm),a=JI(n,e.absorptionCenterKm,e.absorptionWidthKm),o=0;for(let t=0;t<3;t++){let n=e.rayleighScatterPerKm[t]*r+(e.mieScatterPerKm[t]+e.mieAbsorptionPerKm[t])*i+e.absorptionPerKm[t]*a;o+=qI[t]*Math.exp(-n)}return o}var XI=.4,ZI=.05,QI=-.105,$I=.3,eL=.05;function tL(e,t,n){let r=YI(e,t),i=Math.min(1,-Math.log(Math.max(r,.001))/eL),a=Math.min(1,Math.max(0,(n-QI)/$I));return r*(1+(XI+(ZI-XI)*a-1)*i)}function nL(e,t,n,r){let i=Math.sqrt(2*n/r),a=Math.sqrt(Math.PI*r/(2*n));return t>=0?e/(Math.tan(t)+1/a):e*a*Math.exp(t/i)}var rL=bT,iL=200,aL=new J,oL=new J,sL=new J,cL=new J;function lL(e,t,n,r){e.uOccluderCount.value=zC(e.uOccluders.value,t,r,n)}function uL(e,t,n,r,i,a,o){let s={insideShell:!1,shellProminent:!1,skyboxIntensity:1,sunTint:aL.set(1,1,1),sunRefraction:null};zA(n&&a.sunTint);let c=e.get(d_);fj(c?.mesh?.material,_b());let l=dj(c?.mesh?.material);l&&(l.uAtmoTEnable.value=0);let u=iL,d=c?.body.position;if(!d)return s;for(let c of e.values()){if(!c.atmosphere||(c.atmosphere.mesh.visible=n,!n))continue;jA(c.atmosphere,a);let e=gb(c.body.data.id);if(e?.seasonal){let t=a.seasonal?WI(e,o):e;if(c.atmosphere.params!==t){MA(c.atmosphere,t);for(let e of c.sunTint??[])KA(e,t,c.atmosphere.surfaceRadiusScene,c.atmosphere.surfaceRadiusKm)}}let[f,p,m]=c.body.position,h=c.atmosphere.material.uniforms;h.uGroundAlbedo.value=a.groundAlbedo?c.atmosphere.params.groundAlbedo??0:0;let g=h.uSunDir.value.set(d[0]-f,d[1]-p,d[2]-m),_=c.atmosphere.params,v=r?ST(g.length()):_.realisticSunAlways?Math.sqrt(ST(g.length())):1;h.uSunIntensity.value=_.sunIntensity*v*i,g.normalize(),c.mesh&&(GI.set(0,1,0).applyQuaternion(c.mesh.quaternion),h.uSpinAxis.value.copy(GI));let y=c.atmosphere.mesh,b=c.atmosphere.geometryRadiusScene*y.scale.x,x=t.distanceTo(y.position);b>x*.1&&(s.shellProminent=!0),a.eclipseShadows&&lL(h,y.position,g,b);let S=a.insideView&&x<b,C=c.atmosphere.planetRadiusKm,w=x*((C+_.topAltitudeKm)/b)-C,T=S&&OA(_,w),E=S?kA(_,w):0;TA(c.atmosphere,S,T,E),h.uDeepIrradiance.value=rL*i;for(let e of c.sunTint??[])e.uAtmoTDeepIrradiance.value=rL*i,e.uAtmoTDeepBlend.value=E;if(S){s.insideShell=!0;let e=KI.copy(t).sub(y.position).divideScalar(x).dot(g),n=tL(_,w,e);if(s.skyboxIntensity*=n*(1-E),a.refraction&&_.refractivity&&!T){let t=nL(_.refractivity[1]*Math.exp(-Math.max(w,0)/_.rayleighScaleHeightKm),Math.asin(Math.min(1,Math.max(-1,e))),_.rayleighScaleHeightKm,c.atmosphere.planetRadiusKm);t>5e-6&&(s.sunRefraction={angleRad:t,up:cL.copy(KI)})}}let D=x/b;if(a.sunTint&&D<iL){let e=b/(1+_.topAltitudeKm/C)*(c.atmosphere.surfaceRadiusKm/C);sL.copy(t).sub(y.position);let n=h.uSpinAxis.value,r=h.uStretch.value;if($A(_,sL,g,e,c.atmosphere.surfaceRadiusKm,oL,n,r)){let e=qI[0]*oL.x+qI[1]*oL.y+qI[2]*oL.z;e>1e-4&&s.sunTint.multiply(oL.divideScalar(e))}l&&D<u&&(u=D,JA(l,_,y.position,e,c.atmosphere.surfaceRadiusKm,n,r))}}return s}var dL=[];function fL(e,t){let n=LC(),r=e.get(d_);if(!r){n.uSunAngularRadius.value=0,n.uOccluderCount.value=0;return}let[i,a,o]=t,s=r.body.position,c=s[0]-i,l=s[1]-a,u=s[2]-o,d=Math.hypot(c,l,u);d>0?(n.uSunDir.value.set(c/d,l/d,u/d),n.uSunAngularRadius.value=Math.asin(Math.min(r.radiusScene/d,1))):n.uSunAngularRadius.value=0;let f=dL,p=0;for(let t of e.values()){if(t.body.data.objectType===G.STAR)continue;let e=t.body.data.radiusKm;!Number.isFinite(e)||e<=0||t.radiusScene<=0||(f[p++]=t)}f.length=p,p>32&&(f.sort((e,t)=>t.radiusScene-e.radiusScene),f.length=32,p=32);let m=n.uOccluders.value;for(let e=0;e<p;e++){let t=f[e],[n,r,s]=t.body.position;m[e].set(n-i,r-a,s-o,t.radiusScene)}n.uOccluderCount.value=p;for(let e=0;e<p;e++)f[e]=void 0;f.length=0;let h=n.uSunDir.value;for(let t of e.values()){let e=t.eclipseShadow;if(!e||t.cachedDist>0&&t.radiusScene<t.cachedDist*1e-4)continue;let[n,r,s]=t.body.position,c=e.uEclipseSelfPos.value.set(n-i,r-a,s-o);e.uOccluderCount.value=zC(e.uOccluders.value,c,t.radiusScene,h)}}var pL=10;function mL(e,t,n,r,i,a,o,s,c){let l=n.visibility.activeSystemId;if(!l){r.intensity=0,i&&CT(i,s,c);return}let u=e.get(d_)?.body.position,[d,f,p]=t,m=(u?.[0]??0)-d,h=(u?.[1]??0)-f,g=(u?.[2]??0)-p,_=Math.hypot(m,h,g),v=o.set(m,h,g).normalize();r.position.copy(v).multiplyScalar(pL),r.target.position.set(0,0,0),r.intensity=bT*(s?ST(_):1)*c,i&&(i.intensity=0);let y=Math.max(a*2,.001),b=n.bodies.getSystemExtent(l)*10*1.2,x=r.shadow.camera;x.left=x.bottom=-y,x.right=x.top=y,x.near=pL-b,x.far=pL+b,x.updateProjectionMatrix()}var hL=128,gL=256,_L=.25,vL=.32,yL=.35,bL=300,xL=1.25,SL=.05,CL=4e5,wL=new Y,TL=new J;function EL(e,t,n){let r=e=>t.some(([t,n])=>e>t+1e-9&&e<n-1e-9),i=e/hL,a=[];for(let t=0;t<=hL;t++){let n=t===hL?e:t*i;(t===0||t===hL||!r(n))&&a.push(n)}for(let[r,i]of t){let t=Math.ceil(Math.max(r,0)/n-1e-9),o=Math.floor(Math.min(i,e)/n+1e-9);for(let e=t;e<=o;e++)a.push(e*n)}a.sort((e,t)=>e-t);let o=n*.25,s=[];for(let e of a)s.length&&e-s[s.length-1]<o||s.push(e);return s[0]=0,s[s.length-1]=e,Float64Array.from(s)}function DL(e,t,n){let r=t.length,i=n.length,a=new Float32Array(r*i*3),o=new Float32Array(r*i*3),s=new Float32Array(r*i*2);for(let c=0;c<r;c++){let r=t[c],l=Math.sin(r),u=Math.cos(r);for(let t=0;t<i;t++){let d=n[t],f=-Math.cos(d)*l,p=u,m=Math.sin(d)*l,h=(c*i+t)*3;a[h]=e*f,a[h+1]=e*p,a[h+2]=e*m,o[h]=f,o[h+1]=p,o[h+2]=m;let g=(c*i+t)*2;s[g]=d/(2*Math.PI),s[g+1]=1-r/Math.PI}}let c=new Uint32Array((r-1)*(i-1)*6),l=0;for(let e=0;e<r-1;e++){let n=t[e]<=0,r=t[e+1]>=Math.PI;for(let t=0;t<i-1;t++){let a=e*i+t+1,o=e*i+t,s=(e+1)*i+t,u=(e+1)*i+t+1;n||(c[l++]=a,c[l++]=o,c[l++]=u),r||(c[l++]=o,c[l++]=s,c[l++]=u)}}let u=new Vo;return u.setAttribute(`position`,new Eo(a,3)),u.setAttribute(`normal`,new Eo(o,3)),u.setAttribute(`uv`,new Eo(s,2)),u.setIndex(new Eo(c.subarray(0,l),1)),u}function OL(e){e.terrainWindow&&(e.terrainWindow=null,e.currentSegments=void 0)}function kL(e,t,n){let r=e.mesh,i=e.displacementMap;if(!n||!r||!i)return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: eligible=${n} mesh=${!!r} tex=${!!i}`),OL(e),!1;r.updateMatrixWorld(),wL.copy(r.matrixWorld).invert(),TL.copy(t.position).applyMatrix4(wL);let a=Q(mn(e.body.data)),o=TL.length(),s=Math.max(o/a-1,1e-6);if(s>(e.terrainWindow?vL:_L))return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: alt=${s.toFixed(4)}`),OL(e),!1;let c=i.image?.width??2048,l=2*Math.PI/c,u=Math.acos(1/(1+s)),d=Math.max(l,2*u*xL/gL),f=Math.log2(d/l),p=Math.max(0,Math.ceil(f-1e-9)),m=e.terrainWindow;m&&m.texWidth===c&&f>m.stepLevel-.85&&f<m.stepLevel+.15&&(p=m.stepLevel);let h=l*2**p,g=h*gL/2,_=Math.acos(Math.min(1,Math.max(-1,TL.y/o))),v=Math.atan2(TL.z,-TL.x);if(v<0&&(v+=2*Math.PI),m&&m.texWidth===c){if(m.stepLevel===p){let e=Math.sin(_)*Math.sin(m.centerTheta)*Math.cos(v-m.centerPhi)+Math.cos(_)*Math.cos(m.centerTheta);if(Math.acos(Math.min(1,Math.max(-1,e)))<yL*m.angRadius)return!0}if(performance.now()-m.builtAt<bL)return!0}let y=Math.max(0,_-g),b=Math.min(Math.PI,_+g),x=EL(Math.PI,[[y,b]],h),S=Math.min(Math.PI,g/Math.max(Math.sin(_),SL)),C=Math.max(p,Math.ceil(Math.log2(2*S/gL/l)-1e-9)),w=l*2**Math.max(0,C),T=v-S,E=v+S,D=S>=Math.PI?[[0,2*Math.PI]]:T<0?[[0,E],[T+2*Math.PI,2*Math.PI]]:E>2*Math.PI?[[0,E-2*Math.PI],[T,2*Math.PI]]:[[T,E]],O=EL(2*Math.PI,D,w);if(x.length*O.length>CL)return console.warn(`terrain window for ${e.body.data.id} would need ${x.length}×${O.length} vertices — keeping the uniform sphere`),OL(e),!1;let k=r.geometry;return r.geometry=DL(a,x,O),k.dispose(),console.debug(`terrain window ${e.body.data.id}: ${x.length}×${O.length} grid, level ${p} (tex ${c})`),e.terrainWindow={thetas:x,phis:O,centerTheta:_,centerPhi:v,angRadius:g,stepLevel:p,texWidth:c,builtAt:performance.now()},e.currentSegments=hL,!0}var AL=[{up:150,segs:128},{up:40,segs:64},{up:0,segs:32}],jL=24;function ML(e,t,n,r){if(!n&&!t)return jL;let i=AL[AL.length-1].segs;for(let t of AL)if(e>=t.up){i=t.segs;break}if(i<r){let t=AL.find(e=>e.segs===r);if(t&&e>=t.up*.85)return r}return i}function NL(e,t,n,r,i){let a=t.fov*Math.PI/180,o=n.domElement.clientHeight/(2*Math.tan(a/2)),s=r.visibility.activeSystemId,c=i;for(let n of e.values()){if(!n.mesh||!n.radiusScene||!n.group.visible||n.cachedDist<=0)continue;let e=n.body.data.objectType===G.STAR,a=n.body.data.id;if((a===c||n.terrainWindow)&&kL(n,t,a===c))continue;let l=ML(n.radiusScene/n.cachedDist*o,e,s?a===s||r.visibility.isInActiveSystem(n.body.data.parentId):a===i,n.currentSegments??64);if(l===n.currentSegments)continue;let u=Q(mn(n.body.data)),d=n.mesh.geometry;n.mesh.geometry=new nu(u,l,l),d.dispose(),n.currentSegments=l}}function PL(e,t){let n=e<1.05?`high`:e<4?`medium`:`low`;if(eM(n)>eM(t))return n;let r=e>7?`low`:e>1.15?`medium`:`high`;return eM(r)<eM(t)?r:t}function FL(e,t,n,r,i,a,o,s){s.apply(e,i);let c=t.fov*Math.PI/180,l=n.domElement.clientHeight/(2*Math.tan(c/2)),u=r.visibility.activeSystemId,d=jx(),f=d.showClouds,p=eM(Kx());for(let t of e.values())t.clouds&&(t.clouds.mesh.visible=f);for(let t of e.values()){if(!t.mesh||!t.radiusScene||!t.group.visible||!t.availableTiers?.length||t.cachedDist<=0)continue;let e=t.body.data.id;if(u){if(e!==u&&!r.visibility.isInActiveSystem(t.body.data.parentId))continue}else if(e!==a)continue;let s=t.radiusScene/t.cachedDist*l,c=t.cachedDist/t.radiusScene,f;f=s<256&&c>10?`low`:s<1024&&c>2?`medium`:`high`;let m=eM(t.textureTier),h=Math.min(eM(f),p),g=rM(o,t.availableFrames),_=g!==t.textureFrame,v=h>m;if(d.showSurfaceTexture&&!t.textureLoading&&(v||_)){let e=v?tM(h,t.availableTiers):t.textureTier;e&&lM(t,e,g,i)}let y=t.displacementMeta?.tiers;if(t.displacementMap&&y?.length&&!t.displacementLoading){let e=n.capabilities.maxTextureSize,r=e>=16383?2:+(e>=8192),i=t.displacementTier??`low`,a=tM(Math.min(eM(PL(c,i)),r,p),y);a&&a!==i&&iw(t,a)}if(t.clouds&&t.textureTier){let e=tM(eM(t.textureTier),t.clouds.availableTiers),n=jj(o,t.clouds.availableFrames,t.clouds.availableCoverage);e&&n&&Pj(t.clouds,e,n)}}}var IL=KO.refMs,LL=new Y,RL=new J,zL=new J,BL=new Vi,VL=new Vi,HL=new J,UL=new J;function WL(e,t,n){return RL.set(e[0],e[1],e[2]),zL.set(t[0],t[1],t[2]),LL.lookAt(RL,zL,n),BL.setFromRotationMatrix(LL).clone()}function GL(e,t,n,r,i){let a=performance.now()-e.focusStartTime,o=e.focusDurationMs>0?Math.min(a/e.focusDurationMs,1):1,s=o<1,c=!!(e.camOriginWorld&&e.camTargetWorld&&e.flyQ0);if(s&&c){let n=o*o*(3-2*o);if(e.focusTruePos=I_(e.focusOriginWorld,e.focusTargetWorld,n),r(),e.orbitFly){let r=e.focusOriginWorld[0]!==e.focusTargetWorld[0]||e.focusOriginWorld[1]!==e.focusTargetWorld[1]||e.focusOriginWorld[2]!==e.focusTargetWorld[2],i;if(e.arcOrbit)i=R_(e.camOriginWorld,e.camTargetWorld,e.focusTargetWorld,n);else{let t=r?o*o*o:n;i=I_(e.camOriginWorld,e.camTargetWorld,t)}t.position.set(i[0]-e.focusTruePos[0],i[1]-e.focusTruePos[1],i[2]-e.focusTruePos[2]),r&&!e.arcOrbit?(t.lookAt(e.focusTargetWorld[0]-e.focusTruePos[0],e.focusTargetWorld[1]-e.focusTruePos[1],e.focusTargetWorld[2]-e.focusTruePos[2]),VL.copy(t.quaternion),t.quaternion.slerpQuaternions(e.flyQ0,VL,n)):t.lookAt(e.focusTargetWorld[0]-e.focusTruePos[0],e.focusTargetWorld[1]-e.focusTruePos[1],e.focusTargetWorld[2]-e.focusTruePos[2])}else{let r;if(e.cameraStaysOnBody)r=e.camTargetWorld;else{let t=o*o*o;r=I_(e.camOriginWorld,e.camTargetWorld,t)}let i=WL(r,e.focusTargetWorld,t.up);t.quaternion.slerpQuaternions(e.flyQ0,i,n),t.position.set(r[0]-e.focusTruePos[0],r[1]-e.focusTruePos[1],r[2]-e.focusTruePos[2])}return!1}if((e.focusTruePos[0]!==e.focusTargetWorld[0]||e.focusTruePos[1]!==e.focusTargetWorld[1]||e.focusTruePos[2]!==e.focusTargetWorld[2])&&(e.focusTruePos=[...e.focusTargetWorld],r(),i()),n.target.set(0,0,0),e.camTargetWorld){let r=e.camTargetWorld[0]-e.focusTruePos[0],i=e.camTargetWorld[1]-e.focusTruePos[1],a=e.camTargetWorld[2]-e.focusTruePos[2];t.position.set(r,i,a),n.enableDamping=!1,n.update(),n.enableDamping=!0,t.position.set(r,i,a),e.camOriginWorld=null,e.camTargetWorld=null,e.camTargetOffset=null,e.camOriginOffset=null,e.flyQ0=null,e.orbitFly=!1,e.arcOrbit=!1,e.cameraStaysOnBody=!1}return!n.update()}function KL(e,t,n,r,i,a=!1){if(e.focusOriginWorld=[...e.focusTruePos],e.focusTargetWorld=[...t],e.focusStartTime=performance.now(),e.arcOrbit=!1,e.camOriginOffset=null,i){e.camOriginWorld=r,e.camTargetWorld=[...i],e.camTargetOffset=[i[0]-t[0],i[1]-t[1],i[2]-t[2]],e.cameraStaysOnBody=!1,e.flyQ0=n.quaternion.clone();let a=WL([i[0]-e.focusTruePos[0],i[1]-e.focusTruePos[1],i[2]-e.focusTruePos[2]],[t[0]-e.focusTruePos[0],t[1]-e.focusTruePos[1],t[2]-e.focusTruePos[2]],n.up),o=L_(r,i),s=e.flyQ0.angleTo(a);e.focusDurationMs=Math.max(GO(o,JO),WO(s,YO))}else e.camOriginWorld=r,e.camTargetWorld=[...r],e.camTargetOffset=[r[0]-t[0],r[1]-t[1],r[2]-t[2]],e.cameraStaysOnBody=!0,e.flyQ0=n.quaternion.clone(),HL.set(0,0,-1).applyQuaternion(e.flyQ0),UL.set(t[0]-r[0],t[1]-r[1],t[2]-r[2]).normalize(),e.focusDurationMs=WO(HL.angleTo(UL),KO);if(a){let t=e.focusOriginWorld[0]!==e.focusTargetWorld[0]||e.focusOriginWorld[1]!==e.focusTargetWorld[1]||e.focusOriginWorld[2]!==e.focusTargetWorld[2];(i||t)&&(e.focusDurationMs=0)}}function qL(e,t,n,r,i=!1){e.camOriginWorld=n,e.camTargetWorld=[...r],e.camTargetOffset=[r[0]-e.focusTruePos[0],r[1]-e.focusTruePos[1],r[2]-e.focusTruePos[2]],e.camOriginOffset=[n[0]-e.focusTruePos[0],n[1]-e.focusTruePos[1],n[2]-e.focusTruePos[2]],e.focusOriginWorld=[...e.focusTruePos],e.focusTargetWorld=[...e.focusTruePos],e.focusStartTime=performance.now(),e.orbitFly=!0,e.arcOrbit=!0,e.cameraStaysOnBody=!1,e.flyQ0=t.quaternion.clone();let a=L_(n,r);HL.set(e.focusTruePos[0]-n[0],e.focusTruePos[1]-n[1],e.focusTruePos[2]-n[2]).normalize(),UL.set(e.focusTruePos[0]-r[0],e.focusTruePos[1]-r[1],e.focusTruePos[2]-r[2]).normalize();let o=HL.angleTo(UL);e.focusDurationMs=Math.max(GO(a,JO),WO(o,YO)),i&&(e.focusDurationMs=0)}var JL={[G.STAR]:1e3,[G.PLANET]:100,[G.DWARF_PLANET]:10,[G.ASTEROID]:.1,[G.ASTEROID_INNER]:.1,[G.ASTEROID_MAIN_BELT]:.1,[G.ASTEROID_CENTAUR]:1,[G.ASTEROID_TROJAN]:1,[G.ASTEROID_TNO]:1,[G.COMET]:1,[G.MOON]:1},YL=5e-4,XL=new J,ZL=new J;function QL(e){return JL[e.data.objectType]??mn(e.data)*.25}function $L(e,t){return Q((t??mn(e.data))+QL(e))}function eR(e,t,n,r){let i=t.data.radiusKm;if(!Number.isFinite(i)||i<=0)return;let a=t.position[0]-n[0],o=t.position[1]-n[1],s=t.position[2]-n[2],c=Math.hypot(a,o,s),l=r?.centerOffsetScene,u=a+(l?l[0]:0),d=o+(l?l[1]:0),f=s+(l?l[2]:0),p=e.position.x-u,m=e.position.y-d,h=e.position.z-f,g=Math.hypot(p,m,h);if(r?.seated){if(g<1e-9){e.position.set(u,d+c+Q(YL),f);return}let t=Math.tan(e.fov*Math.PI/360)*e.near,n=t*e.aspect,i=0;for(let[a,o,s]of[[0,0,0],[-n,-t,-e.near],[n,-t,-e.near],[-n,t,-e.near],[n,t,-e.near]]){ZL.set(a,o,s).applyQuaternion(e.quaternion);let t=p+ZL.x,n=m+ZL.y,l=h+ZL.z,u=Math.hypot(t,n,l);if(u<1e-12)continue;XL.set(t/u,n/u,l/u).applyQuaternion(r.invQuat);let d=r.radialKm([XL.x,XL.y,XL.z]),f=(d===null?c:Q(d))+Q(YL);f-u>i&&(i=f-u)}if(i<=0)return;let a=i/g;e.position.set(e.position.x+p*a,e.position.y+m*a,e.position.z+h*a);return}let _=QL(t);if(g>=Q((r?.outerRadiusKm??i)+_))return;let v=i;r&&g>1e-9&&(XL.set(p/g,m/g,h/g).applyQuaternion(r.invQuat),v=r.radialKm([XL.x,XL.y,XL.z])??i);let y=Q(v+_),b=c>0?Math.min(y,c):y;if(!(g>=b)){if(g<1e-9)p=0,m=b,h=0;else{let e=b/g;p*=e,m*=e,h*=e}e.position.set(u+p,d+m,f+h)}}function tR(e,t,n){let r=e.position,{latitude:i,longitude:a,distance:o}=iC([r.x,r.y,r.z],[0,0,0],n),s=Math.min(Math.max(i,t.minLat??-90),t.maxLat??90),c=cC(a,t.minLon,t.maxLon),l=Math.min(Math.max(o,t.minDistance??0),t.maxDistance??1/0);if(s===i&&c===a&&l===o)return;let[u,d,f]=aC([0,0,0],s,c,l,n);r.set(u,d,f)}var nR=50,rR=20;function iR(e){return e<=0?`none`:e<rR?`full`:e<nR?`half`:`none`}function aR(e,t){return e.data.validityStart<=t&&t<=e.data.validityEnd}var oR=class{pendingDefaults=new Set;defaults=new Set;userPromoted=new Set;autoPromoted=new Set;pinned=new Set;pinPromoted=new Set;groupTargets=null;groupMode=`none`;smallBodyZone=null;countStableLo=1/0;countStableHi=-1/0;constructor(e){this.deps=e,e.ctx.bodies.onBodiesAdded(()=>{this.onBodiesAdded(),this.buildPinned(),this.autoPromoteAsteroidMoons(),this.reevaluateEarthSatMode(),this.smallBodyZone!==null&&this.refreshSmallBodyEmphasis()}),e.ctx.onEarthSatRollover(()=>this.reevaluateEarthSatMode()),e.ctx.onGroupFilterChange(e=>this.applyGroupFilter(e)),this.applyGroupFilter(e.ctx.earthSatFilter),e.ctx.onSmallBodyFilterChange(e=>this.applySmallBodyFilter(e)),this.applySmallBodyFilter(e.ctx.smallBodyFilter),Bv().then(e=>{let t=[],n=e=>{if(!this.defaults.add(e)||this.deps.bodyObjects.has(e))return;let n=this.deps.ctx.getBody(e);if(!n){this.pendingDefaults.add(e);return}this.shouldAutoPromote(n,e)&&t.push(n)};for(let t of e.keys())n(t);for(let e of p_)n(e);this.buildBatch(t),this.autoPromoteAsteroidMoons();let r=!1;for(let e of this.userPromoted)this.defaults.has(e)&&(this.userPromoted.delete(e),r=!0);r&&this.emitUserPromotedCount()})}autoPromoteAsteroidMoons(){let e=this.deps.ctx.bodies.asteroidBodiesByZone.get(`small_body_moons`);if(!e||e.size===0)return;let t=[],n=new Set;for(let r of e.keys()){let i=e.getKey(r);if(!i||i.data.objectType!==G.MOON||!this.isDefault(i.data.parentId))continue;let a=this.deps.ctx.getBody(i.data.parentId);!a||!hn(a.data.objectType)||(!this.deps.bodyObjects.has(a.data.id)&&!n.has(a.data.id)&&(n.add(a.data.id),t.push(a)),this.deps.bodyObjects.has(i.data.id)||t.push(i))}this.buildBatch(t)}onBodiesAdded(){if(this.pendingDefaults.size===0)return;let e=[];for(let t of this.pendingDefaults){let n=this.deps.ctx.getBody(t);n&&(this.pendingDefaults.delete(t),this.shouldAutoPromote(n,t)&&e.push(n))}this.buildBatch(e)}shouldAutoPromote(e,t){return e.data.objectType!==G.BARYCENTER&&e.data.objectType!==G.LAGRANGE_POINT?!0:p_.has(t)}isDefault(e){return this.defaults.has(e)}ensureBodyObjects(e){this.buildBodyInstance(e)&&this.finalizeBuilds()}buildBodyInstance(e,t,n=!1){let{bodyObjects:r,ctx:i,clock:a,scene:o,clickables:s,meshToBody:c,circleTexture:l,renderer:u}=this.deps;if(r.has(e.data.id))return!1;if(kT(e,a.jd,i),!e.orbitElements&&!e.data.unplaceable&&e.data.orbitalSource!==W.SPICE_PROBE){e.orbitElements=e.data;let t=r.get(e.data.parentId);t&&(e.orbitCenter=[...t.body.position])}gj([e],o,s,c,r,l,u.domElement,this.deps.onBodyClick,(e,t)=>t?this.deps.hoveredBodyIds.add(e):this.deps.hoveredBodyIds.delete(e),t);let d=r.get(e.data.id);if(d&&!e.data.name&&sM(d),e.data.objectType===G.SPACECRAFT)i.bodies.dirtySpacecraftGroups.add(e.data.parentId);else if(hn(e.data.objectType)||e.data.objectType===G.COMET){let t=this.deps.ctx.bodies.findAsteroidZone(e.data.id);t&&i.bodies.dirtyAsteroidZones.add(t)}let f=e.data.id;return this.defaults.has(f)||(n?this.autoPromoted.add(f):(this.userPromoted.add(f),this.emitUserPromotedCount())),!0}finalizeBuilds(){CN(this.deps.bodyObjects,this.deps.scene,this.deps.pointClouds.basis(),this.deps.clock.jd),this.deps.assignMapLayerToTrails(),this.deps.repositionAll(),this.deps.pointClouds.rebuildMinor()}buildBatch(e,t,n=!1){let r=!1;for(let i of e)this.buildBodyInstance(i,t,n)&&(r=!0);r&&this.finalizeBuilds()}applyGroupFilter(e){this.groupTargets=e,this.reevaluateEarthSatMode()}applySmallBodyFilter(e){this.smallBodyZone=e?.kind===`class`?`small_bodies/${e.className}`:null,this.refreshSmallBodyEmphasis()}refreshSmallBodyEmphasis(){let e=this.smallBodyZone;if(e===null){this.deps.pointClouds.setEmphasizedSmallBodyZone(null,null);return}let t=this.deps.ctx.bodies.asteroidBodiesByZone.get(e)?.size??0;this.deps.pointClouds.setEmphasizedSmallBodyZone(e,t)}onSimTimeChanged(){let e=this.deps.clock.jd;e>this.countStableLo&&e<this.countStableHi||this.reevaluateEarthSatMode()}reevaluateEarthSatMode(){let e=this.deps.ctx.bodies.spacecraftByParent.get(f_),t=this.currentMemberCount(e),n=iR(t);this.deps.pointClouds.setEarthSatEmphasis(t);let r=n!==this.groupMode;if(this.teardownAutoPromoted(r),this.groupMode=n,n===`none`||!e)return;let i=this.deps.clock.jd,a=[];for(let t of e.values())this.groupTargets&&!this.groupTargets.has(t.data.id)||aR(t,i)&&(this.deps.bodyObjects.has(t.data.id)||a.push(t));if(a.length===0)return;let o=n===`half`?new Set(a.map(e=>e.data.id)):void 0;this.buildBatch(a,o,!0)}currentMemberCount(e){if(this.countStableLo=-1/0,this.countStableHi=1/0,!e)return 0;let t=this.deps.clock.jd,n=0;for(let r of e.values()){if(this.groupTargets&&!this.groupTargets.has(r.data.id))continue;let{validityStart:e,validityEnd:i}=r.data;e<=t?e>this.countStableLo&&(this.countStableLo=e):e<this.countStableHi&&(this.countStableHi=e),i<t?i>this.countStableLo&&(this.countStableLo=i):i<this.countStableHi&&(this.countStableHi=i),aR(r,t)&&n++}return n}teardownAutoPromoted(e){if(this.autoPromoted.size===0)return;let t=this.deps.getFocusedId(),n=this.deps.clock.jd,r=[];for(let i of this.autoPromoted){if(i===t)continue;if(e||this.groupTargets&&!this.groupTargets.has(i)){r.push(i);continue}let a=this.deps.bodyObjects.get(i)?.body;a&&!aR(a,n)&&r.push(i)}r.length!==0&&this.tearDownBodies(r,this.autoPromoted)}setPinned(e){this.pinned=new Set(e);let t=this.deps.getFocusedId(),n=[...this.pinPromoted].filter(e=>!this.pinned.has(e));t&&n.includes(t)&&(this.pinPromoted.delete(t),this.userPromoted.add(t),this.emitUserPromotedCount()),this.tearDownBodies(n.filter(e=>e!==t),this.pinPromoted),this.buildPinned()}buildPinned(){let e=!1;for(let t of this.pinned){let n=this.deps.ctx.getBody(t);!n||cn(n)||n.data.objectType===G.MOON||this.buildBodyInstance(n)&&(e=!0,this.userPromoted.delete(t)&&this.pinPromoted.add(t))}e&&(this.emitUserPromotedCount(),this.finalizeBuilds())}clearUserPromoted(){let e=this.deps.getFocusedId(),t=[...this.userPromoted].filter(t=>t!==e);this.tearDownBodies(t,this.userPromoted),this.emitUserPromotedCount()}tearDownBodies(e,t){if(e.length===0)return;let{bodyObjects:n,ctx:r,scene:i,clickables:a,meshToBody:o,pointClouds:s}=this.deps,c=new Set,l=new Set;for(let r of e){let e=n.get(r);if(!e){t.delete(r);continue}e.label&&(e.label.element.remove(),e.label.removeFromParent()),e.loadingEl?.remove(),dO(e),cM(e),IM(e),i.remove(e.group);for(let t of e.extraObjects)i.remove(t);if(e.trail&&i.remove(e.trail),e.mesh){e.mesh.geometry.dispose(),pj(e.mesh.material);let t=a.indexOf(e.mesh);t>=0&&a.splice(t,1),o.delete(e.mesh)}e.atmosphere&&=(e.atmosphere.mesh.geometry.dispose(),pj(e.atmosphere.mesh.material),null),e.trail&&(e.trail.geometry.dispose(),pj(e.trail.material));let s=e.body.data.objectType;if(s===G.SPACECRAFT)c.add(e.body.data.parentId);else if(hn(s)||s===G.COMET){let e=this.deps.ctx.bodies.findAsteroidZone(r);e&&l.add(e)}n.delete(r),t.delete(r)}for(let e of c)r.bodies.dirtySpacecraftGroups.add(e);for(let e of l)r.bodies.dirtyAsteroidZones.add(e);(c.size>0||l.size>0)&&s.rebuildMinor()}emitUserPromotedCount(){if(!this.deps.onUserPromotedChange)return;let e=this.deps.getFocusedId(),t=this.userPromoted.size;e&&this.userPromoted.has(e)&&t--,this.deps.onUserPromotedChange(t)}},sR=class{promotion;readerFocusFilter=null;focusedBody;_tmpV3=new J;pendingInitialView=null;upgradeTargetIds=new Set;constructor(e,t,n,r,i){this.deps=e,this.focusedBody=t,this.promotion=new oR({scene:e.scene,bodyObjects:e.bodyObjects,ctx:e.ctx,clock:e.clock,renderer:i,circleTexture:r,clickables:e.clickables,meshToBody:e.meshToBody,hoveredBodyIds:n,pointClouds:e.pointClouds,onBodyClick:e=>this.handleFocus(e),assignMapLayerToTrails:e.assignMapLayerToTrails,repositionAll:e.repositionAll,getFocusedId:()=>this.focusedBody?.data.id,onUserPromotedChange:e.callbacks.onUserPromotedChange})}get current(){return this.focusedBody}setPendingInitialView(e){this.pendingInitialView=e}clearPendingInitialView(){this.pendingInitialView=null}focusedBodyQuat(e){let t=e??this.focusedBody;if(!t||QD(t))return;let n=this.deps.bodyObjects.get(t.data.id)?.mesh;if(!n)return;let r=n.quaternion;return[r.x,r.y,r.z,r.w]}cameraTruePos(){let{focus:e,camera:t}=this.deps;return[e.focusTruePos[0]+t.position.x,e.focusTruePos[1]+t.position.y,e.focusTruePos[2]+t.position.z]}syncUpgradeTargets(e){let{ctx:t,scene:n,clickables:r,meshToBody:i,bodyObjects:a,pointClouds:o,clock:s,loadTexture:c,assignMapLayerToTrails:l}=this.deps,u=cR(e,t),d=new Set(u.map(e=>e.data.id));for(let e of this.upgradeTargetIds){if(d.has(e))continue;let t=a.get(e);t&&(_j(t.body)?yj(t,n,r,i):dO(t))}let f=!1;for(let t of u){if(this.upgradeTargetIds.has(t.data.id))continue;this.promotion.ensureBodyObjects(t);let o=a.get(t.data.id);if(!o){d.delete(t.data.id);continue}_j(t)&&(vj(o,n,r,i),f=!0),t.data.id!==e?.data.id&&c(t)}return f&&(CN(a,n,o.basis(),s.jd),l()),this.upgradeTargetIds=d,d}panCameraToBody(e){if(e.positionUnknown)return;let{focus:t,camera:n}=this.deps;KL(t,[...e.position],n,this.cameraTruePos(),void 0,jx().resolvedReducedMotion)}focusOnPoint(e,t){let{focus:n,camera:r,callbacks:i}=this.deps,a=this.cameraTruePos(),o;if(t!==void 0){let n=this._tmpV3.set(e[0]-a[0],e[1]-a[1],e[2]-a[2]).normalize().negate();o=[e[0]+n.x*t,e[1]+n.y*t,e[2]+n.z*t]}this.focusedBody=void 0,KL(n,[...e],r,a,o,jx().resolvedReducedMotion);let s=iC(o??a,e,void 0);i.onCameraPosition?.(s.latitude,s.longitude,s.distance)}handleFocus(e){if(this.readerFocusFilter&&!this.readerFocusFilter(e))return;if(this.focusedBody?.data.id===e.data.id){this.deps.callbacks.onFocusChange(e);return}if(this.setFocusTarget(e),e.positionUnknown)return;let{latitude:t,longitude:n,distance:r}=iC(this.cameraTruePos(),e.position,this.focusedBodyQuat(e));this.deps.callbacks.onCameraPosition?.(t,n,r)}setFocusTarget(e,t){let{ctx:n,bodyObjects:r,controls:i,callbacks:a,focus:o,camera:s,systemData:c,loadTexture:l}=this.deps;cn(e)||this.promotion.ensureBodyObjects(e);let u=this.focusedBody,d=CM(u,r),f=CM(e,r),p=u&&(cn(u)?u.featureAnchor.hostId:u.data.id),m=cn(e)?e.featureAnchor.hostId:e.data.id,h=this.syncUpgradeTargets(e);if(p&&p!==m&&!h.has(p)){let e=r.get(p);e&&dO(e)}if(d&&d!==f){let e=r.get(d);e&&IM(e)}this.focusedBody=e,cn(e)||(n.bodies.focusFeature=null),i.minDistance=$L(e,MO(r.get(e.data.id)));let g=cn(e)?n.getBody(e.featureAnchor.hostId):void 0;if(n.visibility.setFocused(g??e),a.onFocusChange(e),cn(e)||l(e),f&&f!==e.data.id){let e=n.getBody(f);e&&l(e)}c.syncToFocus(),e.positionUnknown||KL(o,[...e.position],s,this.cameraTruePos(),t,jx().resolvedReducedMotion),this.promotion.emitUserPromotedCount()}focusOnBody(e,t,n,r){let{ctx:i,clock:a,focus:o,camera:s,callbacks:c,pointClouds:l}=this.deps,u=i.getBody(e);if(!u)return 0;if(i.bodies.bodiesById.has(e)||kT(u,a.jd,i),u.positionUnknown)return this.setFocusTarget(u),0;let d;if(t!==void 0)if(n!==void 0&&r!==void 0)d=aC(u.position,n,r,t,this.focusedBodyQuat(u));else{let e=this.cameraTruePos(),n=this._tmpV3.set(u.position[0]-e[0],u.position[1]-e[1],u.position[2]-e[2]).normalize().negate();d=[u.position[0]+n.x*t,u.position[1]+n.y*t,u.position[2]+n.z*t]}let f=iC(d??this.cameraTruePos(),u.position,this.focusedBodyQuat(u));return c.onCameraPosition?.(f.latitude,f.longitude,f.distance),t!==void 0&&d?this.focusedBody?.data.id===e&&L_(o.focusTruePos,u.position)<$L(u)?(o.focusTruePos=[...u.position],this.deps.repositionAll(),l.rebuildBasis(),qL(o,s,this.cameraTruePos(),d,jx().resolvedReducedMotion)):(this.setFocusTarget(u,d),n!==void 0&&r!==void 0&&(o.orbitFly=!0)):this.setFocusTarget(u),o.focusDurationMs}snapToBody(e,t,n,r){let i=this.deps.ctx.getBody(e);!i||i.positionUnknown||(this.settleOnBodyInstant(i),this.snapToBodyFrame(t,n,r))}snapToBodyFacing(e,t,n,r){let{ctx:i,camera:a,controls:o,callbacks:s}=this.deps,c=i.getBody(e);if(!c||c.positionUnknown)return;this.settleOnBodyInstant(c);let l=i.getBody(t)?.position??[0,0,0],u=oC(c.position,l,n,r);a.position.set(u[0],u[1],u[2]),o.update();let d=iC(u,[0,0,0]);s.onCameraPosition?.(d.latitude,d.longitude,d.distance),this.pendingInitialView=null}settleOnBodyInstant(e){let{focus:t,pointClouds:n}=this.deps;this.setFocusTarget(e),t.focusTruePos=[...e.position],t.focusOriginWorld=[...e.position],t.focusTargetWorld=[...e.position],t.focusStartTime=-IL,t.camOriginWorld=null,t.camTargetWorld=null,t.flyQ0=null,t.orbitFly=!1,t.arcOrbit=!1,t.cameraStaysOnBody=!1,this.deps.repositionAll(),n.rebuildBasis()}snapToBodyFrame(e,t,n){let r=this.focusedBody;if(!r)return;let{camera:i,controls:a,callbacks:o}=this.deps,s=!QD(r),c=s?this.focusedBodyQuat(r)??[0,0,0,1]:void 0,l=aC([0,0,0],e,t,n,c);i.position.set(l[0],l[1],l[2]),a.update();let u=iC(l,[0,0,0],c);o.onCameraPosition?.(u.latitude,u.longitude,u.distance),s&&c[0]===0&&c[1]===0&&c[2]===0&&c[3]===1&&(this.pendingInitialView={latitude:e,longitude:t,zoom:n})}reapplyInitialViewIfPending(){let e=this.pendingInitialView;if(!e)return;let t=this.focusedBodyQuat();if(!t||t[0]===0&&t[1]===0&&t[2]===0&&t[3]===1){this.pendingInitialView=null;return}let n=aC([0,0,0],e.latitude,e.longitude,e.zoom,t);this.deps.camera.position.set(...n),this.deps.controls.update(),this.pendingInitialView=null}};function cR(e,t){if(!e)return[];if(cn(e)){let n=t.getBody(e.featureAnchor.hostId);return n&&_j(n)?[n]:[]}let n=[];if(_j(e)&&n.push(e),e.data.objectType===G.MOON||e.data.orbitalSource===W.SPICE_PROBE){let r=t.getBody(e.data.parentId);r&&n.push(r)}return n}var lR=1e-6;function uR(e){return e.data.name??e.data.id}var dR=class{armedProbeId=null;noticeShown=!1;coverage=new Map;pending=new Set;constructor(e,t){this.clock=e,this.notices=t}coverageFor(e){let t=this.coverage.get(e);if(t!==void 0)return t??void 0;this.pending.has(e)||(this.pending.add(e),mx(e,!1).then(t=>this.coverage.set(e,t.global?.coverage??null)).catch(()=>this.coverage.set(e,null)).finally(()=>this.pending.delete(e)))}sync(e,t){let n=e?.data.id??null,r=n===null?void 0:this.coverageFor(n);if(!e||!r){this.disarm();return}this.armedProbeId!==n&&(this.dismissNotice(),this.armedProbeId=n);let i=r.end_jd-lR,a=r.start_jd+lR;this.noticeShown&&t>a&&t<i&&this.dismissNotice(),this.clock.setBoundaryStops({forwardJd:i,backwardJd:a,onHit:t=>this.onHit(e,t,i)})}onHit(e,t,n){this.notices.notify({topic:`coverage-pause`,name:uR(e),direction:t>=n?`forward`:`backward`,jd:t}),this.noticeShown=!0}disarm(){this.armedProbeId!==null&&(this.armedProbeId=null,this.dismissNotice(),this.clock.setBoundaryStops(null))}dismissNotice(){this.noticeShown&&=(this.notices.dismiss(`coverage-pause`),!1)}},fR=class{group=new Ra;extensions=new Set;constructor(){this.group.matrixAutoUpdate=!1,this.group.frustumCulled=!1}add(e){this.extensions.add(e),this.group.add(e.object)}remove(e){this.extensions.delete(e)&&(this.group.remove(e.object),e.dispose())}update(e){for(let t of this.extensions)t.update(e)}clear(e){for(let t of[...this.extensions])e?.(t)||(this.extensions.delete(t),this.group.remove(t.object),t.dispose())}dispose(){this.clear()}},pR=Math.PI/180;function mR(e){return`latitude`in e}function hR(e,t){let n=e*pR,r=t*pR;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function gR(e,t,n,r,i,a){let o=2*(e.y*r-e.z*n),s=2*(e.z*t-e.x*r),c=2*(e.x*n-e.y*t);i[a]=t+e.w*o+(e.y*c-e.z*s),i[a+1]=n+e.w*s+(e.z*o-e.x*c),i[a+2]=r+e.w*c+(e.x*s-e.y*o)}function _R(e,t,n){return jT(e,n,t)?e.position:null}function vR(e,t,n,r){let[i,a,o]=n;if(mR(e)){let n=Q(mn(t.data)+(e.altitudeKm??0)),[s,c,l]=hR(e.latitude,e.longitude),u=t.orientation?pC(t.orientation,r,t.nutPrec):null;if(!u)return[i+s*n,a+c*n,o+l*n];let d=[0,0,0];return gR(u,s,c,l,d,0),[i+d[0]*n,a+d[1]*n,o+d[2]*n]}let s=typeof e.offsetKm==`function`?e.offsetKm(r):e.offsetKm;if(s===null)return null;if(s===void 0)return[i,a,o];let[c,l,u]=OF(s);return[i+c,a+l,o+u]}function yR(e,t,n){let r=t.getBody(e.body),i=r&&_R(r,t,n);return i?vR(e,r,i,n):null}function bR(e,t,n,r){let i=n.getBody(e.body),a=i&&_R(i,n,r);if(!a)return null;let o=t[0]-a[0],s=t[1]-a[1],c=t[2]-a[2],l=Math.hypot(o,s,c);return l===0?null:[o/l,s/l,c/l]}function xR(e){let t=rg/10;return[e[0]*t,-e[2]*t,e[1]*t]}function SR(e,t,n){let r=yR(e.position,t,n),i=yR(e.target,t,n);if(!r||!i)return null;let[a,o,s]=e.up??[0,0,1];return{position:r,target:i,up:[a,s,-o]}}var CR=.02,wR=1e-4;function TR(e){return e?.4:.05}function ER(e,t,n,r,i){let a=e.position.length();if(!(a>0))return{rotate:1,translate:1};let o=QD(n)?void 0:n,s=a;for(let n of[o,i?void 0:r]){if(!n)continue;let r=Q(mn(n.data));if(!(r>0))continue;let i=Math.hypot(e.position.x-(n.position[0]-t[0]),e.position.y-(n.position[1]-t[1]),e.position.z-(n.position[2]-t[2]));s=Math.min(s,i-r)}let c=o?Q(mn(o.data)):0,l=Math.tan(Bi.degToRad(e.getEffectiveFOV())/2);return{rotate:DR(c>0?(a-c)*l/(Math.PI*c):1,wR),translate:DR(s/a,CR)}}function DR(e,t){return Math.min(1,Math.max(t,e))}var OR=Math.PI/180;function kR(e,t){let n=e*OR,r=t*OR;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function AR(e,t,n,r){let i=document.createElement(`div`);i.className=`user-location-marker`;let a=new tk(i),[o,s,c]=kR(n,r);return a.position.set(o*t,s*t,c*t),e.add(a),a}function jR(e){e.parent?.remove(e),e.element.remove()}var MR=new J;function NR(e,t,n){if(!e)return;let r=t.get(f_);if(!r?.mesh)return;MR.copy(e.position).applyQuaternion(r.mesh.quaternion);let i=MR.x,a=MR.y,o=MR.z,s=r.mesh.position,c=n.position.x-s.x,l=n.position.y-s.y,u=n.position.z-s.z,d=r.radiusScene,f=d*d;e.visible=c*c+l*l+u*u<=f||i*c+a*l+o*u>f}var PR=-1,FR=1.2,IR=Q(1e6),LR=.02,RR=2,zR=2.3,BR=.9,VR=new J,HR=.25,UR=10,WR=4,GR=4,KR=28,qR=.02,JR=class e{renderer;composer;atmoDepthPass;bloomPass;labelRenderer;scene;camera;controls;motionScale={rotate:1,translate:1};pointerInteraction;gpuPick;canvas;ctx;clock;callbacks;selectedFeatureId=null;bodyObjects=new Map;circleTexture=$M();pointClouds;systemData;positionDiagnostics=new jI;clickables=[];meshToBody=new Map;hoveredBodyIds=new Set;cullFrameCounter=0;hideCappedMoonLabels=!1;focusController;coverageWatch=null;outOfRange;extensions=new fR;cameraHold=null;holdingCamera=!1;_tmpV3=new J;cameraBand=null;focusableBodies=null;limitsArmed=!1;bodySelectEnabled=!0;featureSelectEnabled=!0;modelScene;modelCamera;modelLight;overlayActive=!1;modelShadowPlane=null;_tmpUp=new J;_tmpSun=new J;_planeNormal=new J(0,0,1);_modelRaycaster=new Ld;_pickNdc=new q;showPointingAxes=!1;pointingAxes=null;cameraUp;skyboxAdjuster;skyDebugMarkers;haloDebug;travelPath;orbitPreview;previewFlyBodyId=null;travelFocus=null;focus={focusTruePos:[0,0,0],focusOriginWorld:[0,0,0],focusTargetWorld:[0,0,0],camOriginWorld:null,camTargetWorld:null,camTargetOffset:null,camOriginOffset:null,flyQ0:null,orbitFly:!1,arcOrbit:!1,cameraStaysOnBody:!1,focusStartTime:0,focusDurationMs:IL};lastUpdatedJd=NaN;get placedJd(){return this.lastUpdatedJd}lastUpdatedSystemId=null;lastSeatConfigKey=null;lastProbeVersion=0;disposed=!1;lastHostReadVersion=0;focusWasOutOfRange=!1;_positionMapScratch=new Map;frameIndex=0;static WAKE_FRAMES=30;static IDLE_HEARTBEAT_FRAMES=10;static REALTIME_FRAME_MS=30;wakeUntilFrame=e.WAKE_FRAMES;lastRenderedFrame=0;lastRenderMs=0;lastRenderedJd=NaN;lastRenderedFocusKey=``;lastRenderedCamPos=new J(NaN,NaN,NaN);lastRenderedCamQuat=new Vi;unsubscribeBodiesAdded=null;_trailView={camX:0,camY:0,camZ:0,tolAngle:0};viewportH=1;tier=Jx();landedNomBodyId=null;rafId=0;paused=!1;covered=!1;firstFrame=!0;pendingUrlWrite=!1;lastTickMs=0;static FPS_SAMPLE_FRAMES=30;fpsSamples=[];fpsSampleHead=0;stashedSky=null;namesShown=!0;halosShown=!0;textureLoader=new qu;appearances=new uM;shadowLight;ambientLights;get sunPointLight(){return this.bodyObjects.get(d_)?.extraObjects.find(e=>e instanceof ud)}tightFar=!1;sunProxyK=1;sunBaseMeshScale=1;sunBaseCoronaScale=0;userLocationMarker=null;labelContainer;static MAP_LAYER=1;static ATMO_DEPTH_LAYER=2;constructor(t,n,r,i,a,o){this.canvas=t,this.ctx=r,r.hasMeshBody=e=>this.bodyObjects.has(e),this.clock=i,this.callbacks=o,this.outOfRange=new vI(o.notices),this.labelContainer=n;let s=OT(t,n,r);this.viewportH=t.clientHeight||1,this.renderer=s.renderer,this.labelRenderer=s.labelRenderer,this.scene=s.scene,this.scene.add(this.extensions.group),this.camera=s.camera,this.composer=s.composer,this.bloomPass=s.bloomPass,this.shadowLight=s.shadowLight;let c=this.renderer.getDrawingBufferSize(new q);this.atmoDepthPass=new bj(c.x,c.y),this.modelScene=new Ka,this.modelScene.environment=wT(this.renderer),this.modelScene.environmentIntensity=xT,this.modelCamera=new od(60,1,.01,1e3),this.modelScene.add(this.modelCamera);let l=new md(16777215,yT);this.modelScene.add(l),this.ambientLights=[s.ambientLight,l],this.modelLight=new pd(16777215,bT),this.modelLight.castShadow=!0,this.modelLight.shadow.mapSize.set(this.tier.shadowMapSize,this.tier.shadowMapSize),this.modelLight.shadow.camera.left=-4,this.modelLight.shadow.camera.right=4,this.modelLight.shadow.camera.top=4,this.modelLight.shadow.camera.bottom=-4,this.modelLight.shadow.camera.near=4,this.modelLight.shadow.camera.far=28,this.modelLight.shadow.bias=-1e-4,this.modelLight.shadow.normalBias=.02,this.modelScene.add(this.modelLight),this.modelScene.add(this.modelLight.target),this.modelShadowPlane=new ks(new Ql(40,40),new ru({opacity:.55})),this.modelShadowPlane.receiveShadow=!0,this.modelShadowPlane.visible=!1,this.modelScene.add(this.modelShadowPlane),this.skyboxAdjuster=new kN(this.scene),this.skyDebugMarkers=new qN(this.scene),this.haloDebug=new nP(this.canvas),this.travelPath=new iI(this.scene,this.canvas),this.travelPath.setLayer(e.MAP_LAYER),this.orbitPreview=new lI(this.scene),this.orbitPreview.setLayer(e.MAP_LAYER),this.skyboxAdjuster.set(0,0,0),fS(this.scene,this.renderer,r,()=>this.disposed);let u=r.bodies.majorBodies.find(e=>e.data.id===d_),d=r.getBody(a.id),f=d&&!d.positionUnknown?d:void 0,p=r.bodies.majorBodies.find(e=>e.data.id===lC)||u,m=f??p,h=m?.position??[0,0,0];this.focus.focusTruePos=[...h],this.focus.focusOriginWorld=[...h],this.focus.focusTargetWorld=[...h],this.focus.focusStartTime=-IL,this.pointClouds=new FP(r,this.scene,this.bodyObjects,this.circleTexture,this.focus,e.MAP_LAYER,()=>this.rebuildTrailBasis()),this.pointClouds.seedBasis(h),this.pointClouds.setPointBudget(this.tier.pointBudget),this.controls=new IS(this.camera,t),this.controls.enableDamping=!0,this.controls.dampingFactor=TR(jx().resolvedReducedMotion),this.controls.minDistance=m?$L(m):Q(.01),this.controls.maxDistance=31620.5*10,this.controls.target.set(0,0,0),this.controls.update(),this.controls.addEventListener(`end`,this.onControlsEnd),this.controls.addEventListener(`start`,this.invalidate),this.controls.addEventListener(`start`,this.armLimits),this.controls.addEventListener(`end`,this.invalidate);for(let n of e.INPUT_EVENTS)t.addEventListener(n,this.invalidate,{passive:!0});window.addEventListener(`keydown`,this.invalidate),this.unsubscribeBodiesAdded=r.bodies.onBodiesAdded(this.invalidate),this.cameraUp=new ek(this.camera,this.controls,r,e=>this.isLanded(e)),this.systemData=new DN(this.scene,r,this.renderer,this.textureLoader,this.bodyObjects,i,()=>this.focusController.reapplyInitialViewIfPending()),this.focusController=new sR({ctx:r,clock:i,camera:this.camera,controls:this.controls,scene:this.scene,bodyObjects:this.bodyObjects,clickables:this.clickables,meshToBody:this.meshToBody,callbacks:o,focus:this.focus,pointClouds:this.pointClouds,systemData:this.systemData,loadTexture:e=>this.maybeLoadTexture(e),repositionAll:()=>this.repositionAll(),assignMapLayerToTrails:()=>this.assignMapLayerToTrails()},m,this.hoveredBodyIds,this.circleTexture,this.renderer),this.coverageWatch=new dR(i,o.notices);let g=f?a:{latitude:45,longitude:0,zoom:15},_=aC([0,0,0],g.latitude,g.longitude,g.zoom,this.focusController.focusedBodyQuat());this.camera.position.set(..._),this.focusController.setPendingInitialView({latitude:g.latitude,longitude:g.longitude,zoom:g.zoom}),m&&r.visibility.setFocused(m),r.visibility.updateCamera(g.zoom,this.clock.jd),o.onFocusChange(m),this.buildScene(),m&&this.focusController.promotion.ensureBodyObjects(m),m&&this.focusController.syncUpgradeTargets(m),this.repositionAll(),m&&this.maybeLoadTexture(m),this.systemData.syncToFocus(),this.focusController.readerFocusFilter=this.readerMayFocus,this.gpuPick=new HO(this.renderer,this.camera),this.pointerInteraction=new LO(t,this.camera,r,i,this.focus,this.clickables,this.meshToBody,e=>this.focusController.handleFocus(e),(e,t)=>this.pickFocusedModel(e,t),this.gpuPick,()=>[...this.pointClouds.asteroids().values(),...this.pointClouds.spacecraft().values()],this.pointClouds.pickRegistry),this.pointerInteraction.attach(),this.tick()}buildScene(){gj(this.ctx.bodies.majorBodies,this.scene,this.clickables,this.meshToBody,this.bodyObjects,this.circleTexture,this.renderer.domElement,e=>this.focusController.handleFocus(e),(e,t)=>{t?this.hoveredBodyIds.add(e):this.hoveredBodyIds.delete(e),this.invalidate()}),this.pointClouds.buildInitial(new Set(this.bodyObjects.keys()));let e=this.pointClouds.basis();(globalThis.requestIdleCallback??(e=>setTimeout(e,0)))(()=>{CN(this.bodyObjects,this.scene,e,this.clock.jd),this.assignMapLayerToTrails()})}setTravelPath(e,t=[],n=[],r=[]){this.travelPath.set(e,t,n,r),this.refreshTravelPath()}setTravelHover(e){this.travelPath.setHovered(e)}setOrbitPreview(e,t=null){this.orbitPreview.set(e),this.refreshOrbitPreview(),t&&this.frameOrbitPreview(t)}frameOrbitPreview(e){let t=this.ctx.getBody(e.bodyId);if(!t)return;let n=Q(e.radiusKm);if(!(n>0)||performance.now()-this.focus.focusStartTime<this.focus.focusDurationMs&&this.previewFlyBodyId===e.bodyId)return;let r=this.focus.focusTruePos,i=t.position[0]-r[0]-this.camera.position.x,a=t.position[1]-r[1]-this.camera.position.y,o=t.position[2]-r[2]-this.camera.position.z,s=Math.hypot(i,a,o);s>n*1.35&&s<n*45||(this.previewFlyBodyId=e.bodyId,this.focusController.focusOnBody(e.bodyId,n*4))}refreshOrbitPreview(){this.orbitPreview.isEmpty||(this.orbitPreview.reposition(e=>this.ctx.getBody(e)?.position??null,this.focus.focusTruePos),this.orbitPreview.updateCameraOffset(this.camera.position))}refreshTravelPath(){if(this.travelPath.isEmpty){this.reserveTravelLabelSpace();return}let e=this.travelPath.centerId,t=e?this.ctx.getBody(e):null;if(!t){this.travelPath.setVisible(!1),this.reserveTravelLabelSpace();return}this.travelPath.setVisible(!0),this.travelPath.setClock(this.clock.jd),this.travelPath.reposition(t.position,this.focus.focusTruePos,e=>this.ctx.getBody(e)?.position??null),this.travelPath.updateCameraOffset(this.camera.position),this.reserveTravelLabelSpace()}reserveTravelLabelSpace(){this.travelPath.reserveLabelSpace(this.camera,this.renderer.domElement.clientWidth,this.renderer.domElement.clientHeight)}focusOnPathPoint(e,t){this.disarmLimits();let n=this.ctx.getBody(e);if(!n)return;let[r,i,a]=OF(t);this.travelFocus={centerId:e,local:[r,i,a]};let o=this.travelFocusWorld(n.position);o&&this.focusController.focusOnPoint(o)}trackPathPoint(e,t){if(!this.travelFocus){this.focusOnPathPoint(e,t);return}let[n,r,i]=OF(t);this.travelFocus={centerId:e,local:[n,r,i]}}travelFocusWorld(e){let t=this.travelFocus;return t?[e[0]+t.local[0],e[1]+t.local[1],e[2]+t.local[2]]:null}refreshTravelFocus(){if(!this.travelFocus)return;if(this.focusController.current){this.travelFocus=null;return}let e=this.ctx.getBody(this.travelFocus.centerId);if(!e)return;let t=this.travelFocusWorld(e.position);if(!t)return;let n=this.focus;n.focusTargetWorld=t;let r=n.camTargetOffset;r&&n.camTargetWorld&&(n.camTargetWorld=[t[0]+r[0],t[1]+r[1],t[2]+r[2]]),performance.now()-n.focusStartTime>=n.focusDurationMs&&(n.focusTruePos=[...t])}updateTravelCraftSystem(){let e=this.travelFocus,t=this.travelPath.plan;if(!e||!t){this.ctx.visibility.clearTravelSystem();return}let n=this.ctx.getBody(e.centerId),r=n?this.travelFocusWorld(n.position):null;if(!r)return;let i=null;for(let e of t.stops){let t=this.ctx.getBody(e.bodyId);if(!t)continue;let n=this.ctx.visibility.resolveSystemId(t);if(!n)continue;let a=this.ctx.visibility.systemReachAU(n);if(!(a>0))continue;let o=L_(r,t.position)/10;!i&&o<=a?i=n:o<=a*2?this.systemData.prefetch(n):this.systemData.discardPrefetch(n)}this.ctx.visibility.setTravelSystem(i)}assignMapLayerToTrails(){for(let t of this.bodyObjects.values())t.trail&&t.trail.layers.set(e.MAP_LAYER)}setImmersive(t){t?(this.camera.layers.disable(e.MAP_LAYER),this.labelContainer.style.display=`none`):(this.camera.layers.enable(e.MAP_LAYER),this.labelContainer.style.display=``)}rebuildMinorPointClouds(){this.pointClouds.rebuildMinor()}repositionAll(){this.repositionBodies(),this.rebuildTrailBasis()}repositionBodies(){let[e,t,n]=this.focus.focusTruePos;for(let r of this.bodyObjects.values()){let[i,a,o]=r.body.position,s=i-e,c=a-t,l=o-n;r.group.position.set(s,c,l);for(let e of r.extraObjects)e.position.set(s,c,l)}this.pointClouds.reposition()}rebuildTrailBasis(){let e=this.focus.focusTruePos,[t,n,r]=e;for(let i of this.bodyObjects.values()){let a=i.trail;if(!a)continue;let o=a.userData.trailBuffer;if(o){QP(i.body,a,o,e,this.clock.jd);continue}let s=a.userData.trailLocalPositions;if(!s)continue;let c=a.userData.orbitCenter;$P(a,s,c.x-t,c.y-n,c.z-r)}}tick=()=>{this.rafId=requestAnimationFrame(this.tick),this.frameIndex++;let t=performance.now(),n=this.lastTickMs?t-this.lastTickMs:0;if(this.lastTickMs=t,this.holdingCamera||this.cameraUp.update(this.clock.jd),this.firstFrame&&(this.firstFrame=!1,this.controls.target.set(0,0,0),this.controls.update()),this.coverageWatch?.sync(this.focusController.current,this.clock.jd),this.clock.tick(performance.now()),!this.shouldRender(t)){this.controls.update(),this.applyReaderLimits(t);return}this.fpsSamples.length<e.FPS_SAMPLE_FRAMES?this.fpsSamples.push(t):(this.fpsSamples[this.fpsSampleHead]=t,this.fpsSampleHead=(this.fpsSampleHead+1)%e.FPS_SAMPLE_FRAMES);let r=this.lastRenderedFrame===this.frameIndex-1?n:0;this.lastRenderedFrame=this.frameIndex,this.lastRenderMs=t,this.lastRenderedJd=this.clock.jd,this.lastRenderedFocusKey=this.focusKey(),this.lastRenderedCamPos.copy(this.camera.position),this.lastRenderedCamQuat.copy(this.camera.quaternion),this.applyJdUpdate(!0),this.refreshTravelFocus(),this.callbacks.onFrame?.(this.clock.jd,r);let i=this.holdingCamera?this.applyHeldCamera():GL(this.focus,this.camera,this.controls,()=>this.repositionAll(),()=>this.pointClouds.rebuildBasis());this.applyReaderLimits(t);let a=this.holdingCamera?void 0:this.focusController.current;if(a){let e=P_(a.data.parentId),t=e?this.ctx.getBody(e):void 0,n=!!this.bodyObjects.get(a.data.id)?.isLanded||cn(a);t&&eR(this.camera,t,this.focus.focusTruePos,this.surfaceClamp(t,n)),kO(this.bodyObjects.get(a.data.id))&&eR(this.camera,a,this.focus.focusTruePos,this.surfaceClamp(a,!1)),this.setMotionScale(ER(this.camera,this.focus.focusTruePos,a,t,n))}else this.setMotionScale({rotate:1,translate:1});if(this.pendingUrlWrite&&i){this.pendingUrlWrite=!1;let{latitude:e,longitude:t,distance:n}=this.getCameraState();this.callbacks.onCameraPosition?.(e,t,n)}this.systemData.hasPendingUnloads()&&performance.now()-this.focus.focusStartTime>=this.focus.focusDurationMs&&this.systemData.drainPendingUnloads();let{distance:o}=this.getCameraState();this.updateTravelCraftSystem(),this.ctx.visibility.updateCamera(o,this.clock.jd),this.updateTightFar(o),this.systemData.syncToFocus(),this.refreshTravelPath(),this.refreshOrbitPreview(),this.extensions.update({jd:this.clock.jd,basis:this.focus.focusTruePos,camera:this.camera,viewportPx:this.viewportH,ctx:this.ctx}),this.cullFrameCounter=mF(this.bodyObjects,this.camera,this.ctx,this.focus.focusTruePos,this.focusController.current?.data.id,this.hideCappedMoonLabels,this.hoveredBodyIds,this.pointClouds.asteroids(),this.pointClouds.spacecraft(),this.pointClouds.moons(),this.cullFrameCounter,this.renderer,this._tmpV3,!i,this.tightFar),this.pointClouds.applyPointBudget(),AI(this.bodyObjects,this.focus,this.lastUpdatedJd,this.trailView()),II(this.bodyObjects,this.focus.focusTruePos,jx().realisticLighting,jx().overexposeRings,this.camera.position,this.pxPerRad()),fL(this.bodyObjects,this.focus.focusTruePos);let s=uL(this.bodyObjects,this.camera.position,jx().showAtmospheres,jx().realisticLighting,this.sunIntensityScale,Uk(),this.clock.jd);eA(r,s.shellProminent),this.scene.backgroundIntensity=s.skyboxIntensity,this.applyLayerChrome();let c=this.bodyObjects.get(d_);c&&uj(c.corona,c.starPoint,s.sunTint);let l=jx().highAmbient?1:yT;if(!jx().highAmbient&&jx().realisticLighting){let e=this.bodyObjects.get(d_)?.body.position;if(e&&this.ctx.visibility.activeSystemId){let[t,n,r]=this.focus.focusTruePos;l*=ST(Math.hypot(e[0]-t,e[1]-n,e[2]-r))}}for(let e of this.ambientLights)e.intensity=l;NR(this.userLocationMarker,this.bodyObjects,this.camera);let u=CM(this.focusController.current,this.bodyObjects);FL(this.bodyObjects,this.camera,this.renderer,this.ctx,this.textureLoader,u,this.clock.jd,this.appearances),NL(this.bodyObjects,this.camera,this.renderer,this.ctx,u),mL(this.bodyObjects,this.focus.focusTruePos,this.ctx,this.shadowLight,this.sunPointLight,o,this._tmpV3,jx().realisticLighting,this.sunIntensityScale),this.updateModelMounts(),this.pointClouds.drainOnePendingSceneAdd(),this.updateDepthFar(),this.updateSunProxy(s.sunRefraction),s.insideShell&&this.atmoDepthPass.run(this.renderer,this.scene,this.camera,this.bodyObjects,e.ATMO_DEPTH_LAYER),this.composer.render(),this.renderModelOverlay(),this.labelRenderer.render(this.scene,this.camera),this.haloDebug.active&&this.haloDebug.draw(this.bodyObjects,this.camera,this.focus.focusTruePos,this.focusController.current?.data.id,this.renderer.domElement.clientWidth,this.renderer.domElement.clientHeight)};updateTightFar(e){if(rT())return;let t=this.focusController.current,n=t?CM(t,this.bodyObjects):void 0,r=n?this.bodyObjects.get(n):void 0,i=r?.radiusScene??0,a=e;if(t&&r&&n!==t.data.id){let[e,t,n]=this.focus.focusTruePos,[i,o,s]=r.body.position,c=this.camera.position;a=Math.hypot(e+c.x-i,t+c.y-o,n+c.z-s)}let o=this.tightFar?zR:RR;this.tightFar=i>0&&this.ctx.visibility.activeSystemId!==null&&a<i*o}updateDepthFar(){if(rT())return;let e=TT,t=this.ctx.visibility.activeSystemId;if(t){let[n,r,i]=this.focus.focusTruePos,a=this.camera.position.lengthSq(),o=e=>{let t=e[0]-n,o=e[1]-r,s=e[2]-i,c=t*t+o*o+s*s;c>a&&(a=c)},s=this.bodyObjects.get(d_);if(this.tightFar){let e=this.bodyObjects.get(t)?.body;if(e){let o=Math.hypot(e.position[0]-n,e.position[1]-r,e.position[2]-i)+this.ctx.bodies.getSystemExtent(t)*10*2;a=Math.max(a,o*o)}}else s&&o(s.body.position);for(let e of this.bodyObjects.values())this.ctx.visibility.hasFullRendering(e.body)&&o(e.body.position);e=Math.min(TT,Math.max(IR,Math.sqrt(a)*FR))}Math.abs(e-this.camera.far)>this.camera.far*LR&&(this.camera.far=e,this.camera.updateProjectionMatrix())}updateSunProxy(e){let t=this.bodyObjects.get(d_);if(!t)return;let[n,r,i]=this.focus.focusTruePos,[a,o,s]=t.body.position,c=a-n,l=o-r,u=s-i;if(e){let t=this.camera.position,n=this._tmpV3.set(c-t.x,l-t.y,u-t.z),r=n.length();n.divideScalar(r);let i=VR.copy(e.up).addScaledVector(n,-e.up.dot(n));i.lengthSq()>1e-12&&(n.addScaledVector(i.normalize(),e.angleRad).normalize(),c=t.x+n.x*r,l=t.y+n.y*r,u=t.z+n.z*r)}let d=1;if(this.tightFar){let e=this.camera.far*BR,t=Math.hypot(c,l,u);t>e&&(d=e/t)}if(!(d===1&&this.sunProxyK===1&&!e)){this.sunProxyK===1&&(this.sunBaseMeshScale=t.mesh?.scale.x??1,this.sunBaseCoronaScale=t.corona?.scale.x??0),t.group.position.set(c*d,l*d,u*d);for(let e of t.extraObjects)e.position.set(c*d,l*d,u*d);t.mesh?.scale.setScalar(this.sunBaseMeshScale*d),t.corona?.scale.set(this.sunBaseCoronaScale*d,this.sunBaseCoronaScale*d,1),this.sunProxyK=d}}setMotionScale(e){this.motionScale=e,this.controls.rotateSpeed=e.rotate,this.controls.panSpeed=e.translate,this.controls.zoomSpeed=e.translate}isLanded(e){return!!this.bodyObjects.get(e)?.isLanded}surfaceRadialKm(e,t,n){let r=this.ctx.getBody(e);if(!r)return null;let i=cw(t*Math.PI/180,n*Math.PI/180);return Aw(this.bodyObjects.get(e),e,mn(r.data),i)}surfaceClamp(e,t){let n=this.bodyObjects.get(e.data.id);if(kO(n))return{invQuat:n.model.quaternion.clone().invert(),seated:t,outerRadiusKm:jO(n),centerOffsetScene:AO(n),radialKm:e=>OO(n,e)};if(!(!t||!e.orientation))return{invQuat:pC(e.orientation,this.clock.jd,e.nutPrec).invert(),seated:t,radialKm:t=>Aw(n,e.data.id,e.data.radiusKm,t)}}updateModelMounts(){let e=!1;for(let t of this.bodyObjects.values())if(t.model&&QD(t.body)){e=!0;break}this.overlayActive=e;for(let t of this.bodyObjects.values()){let n=t.model,r=t.modelRoot;if(!(!n||!r)){if(e)n.parent!==this.modelScene&&this.modelScene.add(n);else if(n.parent!==r){r.add(n);let e=n.userData;n.scale.setScalar(e.fitScale??1),n.position.set(0,0,0),e.centerOffset&&n.position.addScaledVector(e.centerOffset,-1)}}}if(e){this.shadowLight.castShadow=!1;return}this.updateFocusedMountedModel()}updateFocusedMountedModel(){let e=this.overlayModelBo(),t=e?.model&&e.model.parent===e.modelRoot?e.modelRoot:null;if(!e||!t){this.shadowLight.castShadow=!1;return}let n=iO(e);t.scale.setScalar(n);let r=this.shadowLight.intensity>0;if(this.shadowLight.castShadow=r,!r)return;let i=this.bodyObjects.get(d_)?.body;if(!i)return;let[a,o,s]=i.position,[c,l,u]=e.body.position;this._tmpSun.set(a-c,o-l,s-u).normalize(),this.shadowLight.position.copy(e.group.position).addScaledVector(this._tmpSun,UR*n),this.shadowLight.target.position.copy(e.group.position);let d=this.shadowLight.shadow.camera;d.left=d.bottom=-WR*n,d.right=d.top=WR*n,d.near=GR*n,d.far=KR*n,d.updateProjectionMatrix(),this.shadowLight.shadow.normalBias=qR*n}renderModelOverlay(){if(!this.overlayActive)return;let e=this.overlayModelBo();if(!e?.model)return;let t=e.model.userData;e.model.scale.setScalar(t.fitScale??1),e.model.position.set(0,0,0),e.isLanded&&t.feetOffset?e.model.position.copy(t.feetOffset).applyQuaternion(e.model.quaternion).multiplyScalar(-1):t.centerOffset&&e.model.position.copy(t.centerOffset).multiplyScalar(-1),this._tmpV3.copy(this.camera.position).sub(e.group.position);let n=this._tmpV3.length(),r=iO(e),i=n/r;this.modelCamera.position.copy(this._tmpV3).normalize().multiplyScalar(i),this.modelCamera.quaternion.copy(this.camera.quaternion),this.modelCamera.aspect=this.camera.aspect;let a=0;for(let t of this.bodyObjects.values()){let n=t.model;if(!n||t===e)continue;let i=iO(t)/r,o=n.userData.fitScale??1;n.scale.setScalar(o*i),n.position.subVectors(t.group.position,e.group.position).divideScalar(r);let s=n.userData;s.centerOffset&&n.position.addScaledVector(s.centerOffset,-i);let c=n.position.length()+i;c>a&&(a=c)}this.modelCamera.near=Math.max(.01,i-5-a),this.modelCamera.far=i+50+a,this.modelCamera.updateProjectionMatrix();let o=this.bodyObjects.get(d_)?.body,s=1;if(o){let[t,n,r]=o.position,[i,a,c]=e.body.position;this._tmpSun.set(t-i,n-a,r-c),jx().realisticLighting&&(s=ST(this._tmpSun.length())),this._tmpSun.normalize(),this.modelLight.position.copy(this._tmpSun).multiplyScalar(10)}if(this.modelShadowPlane){this._tmpUp.set(0,1,0).applyQuaternion(e.model.quaternion);let t=this._tmpSun.dot(this._tmpUp)>.03;this.modelShadowPlane.visible=!!e.isLanded&&!e.isCrashed&&t,this.modelShadowPlane.visible&&this.modelShadowPlane.quaternion.setFromUnitVectors(this._planeNormal,this._tmpUp)}this._tmpV3.set(0,0,0);let c=BC(this._tmpV3,this._tmpV3)*s;this.modelLight.intensity=bT*c*this.sunIntensityScale,this.modelScene.environmentIntensity=xT*c,this.showPointingAxes?(this.pointingAxes||(this.pointingAxes=this.buildPointingAxes(),this.modelScene.add(this.pointingAxes)),this.pointingAxes.quaternion.copy(e.model.quaternion),this.pointingAxes.scale.setScalar(Math.min(.8,.45*i)),this.pointingAxes.visible=!0):this.pointingAxes&&(this.pointingAxes.visible=!1),this.renderer.autoClear=!1,this.renderer.clearDepth(),this.renderer.render(this.modelScene,this.modelCamera),this.renderer.autoClear=!0}pxPerRad(){return this.viewportH/2/Math.tan(this.camera.fov*Math.PI/360)}trailView(){let e=this._trailView,t=this.camera.position;return e.camX=t.x,e.camY=t.y,e.camZ=t.z,e.tolAngle=HR/this.pxPerRad(),e}cloudViewInfo(){let e=this.camera.position;return{camPos:[e.x,e.y,e.z],pxPerRad:this.pxPerRad()}}getCameraState(){let e=this.camera.position;return iC([e.x,e.y,e.z],[0,0,0],this.focusController.focusedBodyQuat())}setDragEnabled(e){this.controls.enableRotate=e,this.controls.enablePan=e}setZoomEnabled(e){this.controls.enableZoom=e}setBodySelectEnabled(e){this.bodySelectEnabled=e}setFeatureSelectEnabled(e){this.featureSelectEnabled=e}readerMayFocus=e=>this.bodySelectEnabled&&(this.focusableBodies?.has(e.data.id)??!0);setCooperativeTouch(e){this.controls.touches.ONE=e?PR:Cn.ROTATE,this.canvas.style.touchAction=e?`pan-x pan-y`:`none`}setCameraLimits(e,t){this.cameraBand=e,this.focusableBodies=t?new Set(t):null}armLimits=()=>{this.limitsArmed=!0};disarmLimits(){this.limitsArmed=!1}applyReaderLimits(e){!this.limitsArmed||!this.cameraBand||this.holdingCamera||e-this.focus.focusStartTime<this.focus.focusDurationMs||tR(this.camera,this.cameraBand,this.focusController.focusedBodyQuat())}static INPUT_EVENTS=[`pointerdown`,`pointermove`,`pointerup`,`wheel`];invalidate=()=>{this.wakeUntilFrame=this.frameIndex+e.WAKE_FRAMES};focusKey(){let e=this.ctx.visibility;return`${this.focusController.current?.data.id??``}|${e.focusedSystemId??``}|${e.activeSystemId??``}`}cameraOffsetFromFocus(){let e=this.focusController.current,t=this.focus.focusTruePos,n=this.camera.position;return e?[n.x+t[0]-e.position[0],n.y+t[1]-e.position[1],n.z+t[2]-e.position[2]]:[n.x,n.y,n.z]}holdCamera(){this.holdingCamera||(this.disarmLimits(),this.holdingCamera=!0,this.controls.enabled=!1,this.focus.camOriginWorld=null,this.focus.camTargetWorld=null,this.focus.camTargetOffset=null,this.focus.camOriginOffset=null,this.focus.flyQ0=null,this.focus.orbitFly=!1,this.focus.arcOrbit=!1,this.focus.cameraStaysOnBody=!1)}setHeldPose(e){this.cameraHold=e}releaseCamera(){this.holdingCamera&&(this.holdingCamera=!1,this.cameraHold=null,this.controls.enabled=!0,this.controls.target.set(0,0,0),this.controls.enableDamping=!1,this.controls.update(),this.controls.enableDamping=!0,this.invalidate())}applyHeldCamera(){let e=this.cameraHold,t=e&&SR(e,this.ctx,this.clock.jd);if(!t)return!0;let n=this.focus.focusTruePos;return this.camera.up.set(t.up[0],t.up[1],t.up[2]).normalize(),this.camera.position.set(t.position[0]-n[0],t.position[1]-n[1],t.position[2]-n[2]),this.camera.lookAt(t.target[0]-n[0],t.target[1]-n[1],t.target[2]-n[2]),!0}shouldRender(t){if(this.holdingCamera||t-this.focus.focusStartTime<this.focus.focusDurationMs||this.focusKey()!==this.lastRenderedFocusKey||this.ctx.bodies.minorStreaming||this.pointClouds.hasPendingSceneAdds()||this.systemData.hasPendingUnloads())return!0;if(this.covered)return!1;if(this.frameIndex-this.lastRenderedFrame>=e.IDLE_HEARTBEAT_FRAMES)return!0;let n=this.camera;return n.position.distanceToSquared(this.lastRenderedCamPos)>n.position.lengthSq()*1e-10||8*(1-Math.abs(n.quaternion.dot(this.lastRenderedCamQuat)))>1e-8||this.frameIndex<this.wakeUntilFrame||this.haloDebug.active?!0:this.clock.jd===this.lastRenderedJd?!1:Math.abs(this.clock.timeScale)>1||t-this.lastRenderMs>=e.REALTIME_FRAME_MS}onControlsEnd=()=>{this.pendingUrlWrite=!0,this.focusController.clearPendingInitialView()};nudgeCamera(e,t,n){this.armLimits();let{rotate:r,translate:i}=this.motionScale;e!==0&&this.controls.rotateLeft(e*r),t!==0&&this.controls.rotateUp(t*r),n!==1&&this.controls.dollyIn(1/n**+i),this.onControlsEnd()}maybeLoadTexture(e){let t=this.bodyObjects.get(e.data.id);t&&(oM(t,this.textureLoader,this.clock.jd,this.scene,this.renderer.capabilities.maxTextureSize,this.ctx).then(()=>{this.focusController.current?.data.id===e.data.id&&e.orientation&&t.mesh&&(mC(t.mesh,e.orientation,this.clock.jd,e.nutPrec),this.focusController.reapplyInitialViewIfPending())}),cO(t,this.modelScene,this.ctx).then(()=>{if(this.focusController.current?.data.id===t.body.data.id&&(this.controls.minDistance=$L(t.body,MO(t))),!this.ctx.layers.skipped.has(`nomenclature`))return jM(t,this.canvas,(e,n,r,i)=>{this.featureSelectEnabled&&this.callbacks.onFeatureSelect?.(t.body.data.id,e,n,r,i)})}).then(()=>{this.selectedFeatureId!==null&&FM(t,this.selectedFeatureId)}))}reapplyBodyLayers(){let e=this.focusController.current;if(!e)return;let t=this.bodyObjects.get(e.data.id);t&&(dO(t),cM(t),this.maybeLoadTexture(e))}setSelectedFeature(e){this.selectedFeatureId=e;let t=CM(this.focusController.current,this.bodyObjects),n=t?this.bodyObjects.get(t):void 0;n&&FM(n,e)}syncLandedNomenclature(){let e=this.focusController.current,t=(e?this.bodyObjects.get(e.data.id):void 0)?.isLanded?e.data.parentId:null;if(t===this.landedNomBodyId||(this.landedNomBodyId=t,!t))return;let n=this.ctx.getBody(t);n&&this.maybeLoadTexture(n)}clearUserPromoted(){this.focusController.promotion.clearUserPromoted()}focusedSeatConfigKey(){let e=this.focusController.current;if(!e||e.data.objectType!==G.SPACECRAFT&&!cn(e))return null;let t=P_(e.data.parentId),n=t?this.bodyObjects.get(t):void 0;if(!n)return null;let r=n.terrainWindow;return`${r?`w${r.stepLevel}x${r.texWidth}@${r.centerTheta.toFixed(6)},${r.centerPhi.toFixed(6)}`:`u${n.currentSegments??128}`}|${n.displacementMap?.uuid??`none`}|${_w()}`}lastProbeTargetCheck=null;requestedProbeTargets=new Set;askedProbeRides=new Set;ensureFocusedProbeTarget(){let e=this.focusController.current,t=this.ctx.probeStore;if(!e||!t?.fitCenterUsable||e.data.orbitalSource!==W.SPICE_PROBE)return;this.askedProbeRides.has(e.data.id)||(this.askedProbeRides.add(e.data.id),hx(e.data.id).then(e=>e&&t.registerCarried(e)));let n=`${e.data.id}@${this.clock.jd}`;if(n===this.lastProbeTargetCheck)return;this.lastProbeTargetCheck=n;let r=t.stampedFitCenterAt(e.data.id,this.clock.jd);if(!r)return;let i=this.ctx.getBody(r);if(!i){if(this.requestedProbeTargets.has(r))return;this.requestedProbeTargets.add(r),this.ctx.ensureBody(r,Ng(this.clock.jd));return}this.focusController.promotion.ensureBodyObjects(i),this.focusController.syncUpgradeTargets(e)}applyJdUpdate(e=!1){this.ensureFocusedProbeTarget();let t=this.ctx.visibility.focusedSystemId,n=this.focusedSeatConfigKey(),r=this.ctx.probeStore?.version??0,i=this.ctx.bodies.hostReadVersion;if(this.clock.jd===this.lastUpdatedJd&&t===this.lastUpdatedSystemId&&n===this.lastSeatConfigKey&&r===this.lastProbeVersion&&i===this.lastHostReadVersion){this.clock.seeked=!1;return}let a=this.clock.seeked;this.clock.seeked=!1,this.lastUpdatedJd=this.clock.jd,this.lastUpdatedSystemId=t,this.lastSeatConfigKey=n,this.lastProbeVersion=r,this.lastHostReadVersion=i,this.ctx.refreshTick(Ng(this.clock.jd)),this.focusController.promotion.onSimTimeChanged();let o=kI({jd:this.clock.jd,ctx:this.ctx,bodyObjects:this.bodyObjects,focus:this.focus,focusedBody:this.focusController.current,positionMap:this._positionMapScratch,diagnostics:this.positionDiagnostics,trailView:this.trailView(),frame:this.frameIndex,outOfRange:this.outOfRange});this.pointClouds.updateForJd(this.clock.jd,this.cloudViewInfo()),this.refreshTravelFocus(),performance.now()-this.focus.focusStartTime>=this.focus.focusDurationMs&&(this.repositionBodies(),this.pointClouds.maybeRebase()),this.syncLandedNomenclature();let s=o.focusedOutOfRange&&!this.focusWasOutOfRange;if(this.focusWasOutOfRange=o.focusedOutOfRange,e&&a&&s&&o.reanchorId){let e=this.ctx.getBody(o.reanchorId);e&&this.focusController.panCameraToBody(e)}}setReducedMotion(e){this.controls.dampingFactor=TR(e)}focusOnBody(e,t,n,r){return this.disarmLimits(),this.applyJdUpdate(),this.focusWasOutOfRange=!1,this.focusController.focusOnBody(e,t,n,r)}focusOnFeature(e,t,n,r=`frame`,i){this.disarmLimits(),this.applyJdUpdate(),this.focusWasOutOfRange=!1;let a=this.ctx.getBody(e.hostId);if(!a)return 0;this.focusController.clearPendingInitialView();let o=CM(this.focusController.current,this.bodyObjects)===e.hostId,s=Nw(e,t);this.ctx.bodies.focusFeature=s;let c=this.bodyObjects.get(a.data.id);this.selectedFeatureId=e.featureId,c&&FM(c,e.featureId),Bw(s,a,c,this.clock.jd);let l=s.position,u=this.focusController.focusedBodyQuat(s);if(r===`pan`){let e=iC(this.focusController.cameraTruePos(),l,u);return this.callbacks.onCameraPosition?.(e.latitude,e.longitude,e.distance),this.focusController.setFocusTarget(s),this.focus.focusDurationMs}let d=l[0]-a.position[0],f=l[1]-a.position[1],p=l[2]-a.position[2],m=Math.hypot(d,f,p);m>1e-9?(d/=m,f/=m,p/=m):(d=0,f=1,p=0);let h=r===`snap`&&i?aC(l,i.latitude,i.longitude,i.zoom,u):[l[0]+d*n,l[1]+f*n,l[2]+p*n],g=iC(h,l,u);if(this.callbacks.onCameraPosition?.(g.latitude,g.longitude,g.distance),r===`snap`){this.focusController.setFocusTarget(s,h);let e=this.focus;return e.focusTruePos=[...l],e.focusOriginWorld=[...l],e.focusTargetWorld=[...l],e.focusStartTime=-IL,e.camOriginWorld=null,e.camTargetWorld=null,e.camTargetOffset=null,e.camOriginOffset=null,e.flyQ0=null,e.orbitFly=!1,e.arcOrbit=!1,e.cameraStaysOnBody=!1,this.repositionAll(),this.pointClouds.rebuildBasis(),this.camera.position.set(h[0]-l[0],h[1]-l[1],h[2]-l[2]),this.controls.update(),0}if(o){let e=this.focusController.cameraTruePos();this.focusController.setFocusTarget(s),this.focus.focusTruePos=[...l],this.camera.position.set(e[0]-l[0],e[1]-l[1],e[2]-l[2]),this.repositionAll(),this.pointClouds.rebuildBasis(),qL(this.focus,this.camera,e,h,jx().resolvedReducedMotion)}else this.focusController.setFocusTarget(s,h),this.focus.orbitFly=!0;return this.focus.focusDurationMs}pickFocusedModel(e,t){if(!this.overlayActive||!this.overlayModelBo()?.model)return null;this._pickNdc.set(e,t),this._modelRaycaster.setFromCamera(this._pickNdc,this.modelCamera);let n=null,r=1/0;for(let e of this.bodyObjects.values()){if(!e.model)continue;let t=this._modelRaycaster.intersectObject(e.model,!0);t.length>0&&t[0].distance<r&&(r=t[0].distance,n=e.body)}return n}overlayModelBo(){let e=this.focusController.current;if(!e){let e=this.travelFocus?.centerId,t=e?this.bodyObjects.get(e):void 0;return t?.model?t:null}let t=cn(e)?e.featureAnchor.hostId:e.data.id,n=this.bodyObjects.get(t);if(n?.model)return n;if(e.data.orbitalSource===W.SPICE_PROBE&&!n?.isLanded){let t=this.bodyObjects.get(e.data.parentId);if(t?.model)return t}return null}snapToBodyFacing(e,t,n,r){this.disarmLimits(),this.focusController.snapToBodyFacing(e,t,n,r)}snapToBody(e,t,n,r){this.disarmLimits(),this.focusController.snapToBody(e,t,n,r)}setFocusTarget(e,t){this.disarmLimits(),this.applyJdUpdate(),this.focusWasOutOfRange=!1,this.focusController.setFocusTarget(e,t)}getFocusedBody(){return this.focusController.current}getDebugStats(){let t=this.fpsSamples,n=0;if(t.length>=2){let r=t.length<e.FPS_SAMPLE_FRAMES?0:this.fpsSampleHead,i=t[r],a=(t[(r-1+t.length)%t.length]-i)/1e3;a>0&&(n=(t.length-1)/a)}return sP({fps:n,orbitPool:this.pointClouds.orbitPool,renderer:this.renderer,bodyObjects:this.bodyObjects,focusedBody:this.focusController.current,cameraDistanceScene:this.getCameraState().distance})}setBodyAppearance(e,t){this.appearances.set(e,t)}setPinnedBodies(e){this.ctx.visibility.setPinned(e),this.focusController.promotion.setPinned(e)}setNorthReference(e){this.cameraUp.setNorthReference(e)}getFocusedPointing(){let e=this.focusController.current;if(!e)return null;let t=e.pointing??{primary:{axis:`-y`,target:`parent`}};return{supported:QD(e),base:t}}setFocusedPointing(e){let t=this.focusController.current;t&&(t.pointingOverride=e??void 0)}setPointingAxesVisible(e){this.showPointingAxes=e}buildPointingAxes(){let e=new Ra,t=new J(0,0,0),n=(n,r,i,a)=>{let o=new Wd(n,t,1,r,.22,.12);o.line.material.depthTest=!1,o.cone.material.depthTest=!1,o.renderOrder=999,e.add(o);let s=this.makeAxisLabel(i,a);s.position.copy(n).multiplyScalar(1.12),e.add(s)};return n(new J(1,0,0),16729156,`+X`,`#ff9999`),n(new J(-1,0,0),8930372,`-X`,`#cc7777`),n(new J(0,1,0),4521796,`+Y`,`#99ff99`),n(new J(0,-1,0),4491332,`-Y`,`#77cc77`),n(new J(0,0,1),4491519,`+Z`,`#99bbff`),n(new J(0,0,-1),4478344,`-Z`,`#7799cc`),e}makeAxisLabel(e,t){let n=document.createElement(`canvas`);n.width=n.height=128;let r=n.getContext(`2d`);r.font=`bold 72px sans-serif`,r.textAlign=`center`,r.textBaseline=`middle`,r.fillStyle=t,r.fillText(e,128/2,128/2);let i=new ss(new qo({map:new Mc(n),depthTest:!1,transparent:!0}));return i.scale.setScalar(.175),i.renderOrder=1e3,i}sunIntensityScale=1;getSunIntensityScale(){return this.sunIntensityScale}setSunIntensityScale(e){this.sunIntensityScale=e}getFocusedAtmosphere(){let e=this.focusController.current?.data.id;if(!e)return null;let t=this.bodyObjects.get(e)?.atmosphere,n=gb(e);return!t||!n?null:{id:e,current:t.params,shipped:n}}setFocusedAtmosphereParams(e){let t=this.focusController.current?.data.id,n=t?this.bodyObjects.get(t)?.atmosphere:void 0;n&&MA(n,e)}getSkyboxAdjust(){return this.skyboxAdjuster.get()}setSkyboxAdjust(e,t,n){this.skyboxAdjuster.set(e,t,n)}setSkyDebugMarkersVisible(e){this.skyDebugMarkers.setVisible(e)}applyLayerChrome(){this.ctx.layers.isVisible(`stars`)?this.stashedSky&&=(this.scene.background=this.stashedSky,null):this.scene.background&&(this.stashedSky=this.scene.background,this.scene.background=null);let e=this.ctx.layers.isVisible(`labels`);e!==this.namesShown&&(this.namesShown=e,this.labelContainer.classList.toggle(`scene-overlay--no-names`,!e));let t=this.ctx.layers.isVisible(`halos`);t!==this.halosShown&&(this.halosShown=t,this.labelContainer.classList.toggle(`scene-overlay--no-halos`,!t))}setHaloDebugVisible(e){this.haloDebug.setVisible(e)}setUserLocation(e,t){let n=this.bodyObjects.get(f_);n?.mesh&&(this.userLocationMarker&&jR(this.userLocationMarker),this.userLocationMarker=AR(n.mesh,n.radiusScene,e,t))}clearUserLocation(){this.userLocationMarker&&=(jR(this.userLocationMarker),null)}pause(){this.paused||(this.paused=!0,cancelAnimationFrame(this.rafId),this.rafId=0)}resume(){this.paused&&(this.paused=!1,this.invalidate(),this.tick())}setCovered(e){this.covered!==e&&(this.covered=e,e||this.invalidate())}isContextLost(){return this.renderer.getContext().isContextLost()}handleContextRestored(){this.renderer.setPixelRatio(Yx()),this.composer.setPixelRatio(Yx()),this.resize(this.canvas.clientWidth,this.canvas.clientHeight),fS(this.scene,this.renderer,this.ctx,()=>this.disposed),this.resume()}recoverWorkersIfDead(e){return this.pointClouds.recoverWorkersIfDead(e)}applyRenderTier(){this.tier=Jx();let e=Yx();e!==this.renderer.getPixelRatio()&&(this.renderer.setPixelRatio(e),this.composer.setPixelRatio(e),this.resize(this.canvas.clientWidth,this.canvas.clientHeight)),this.pointClouds.setPointBudget(this.tier.pointBudget)}resize(e,t){this.invalidate(),this.viewportH=t||1,this.renderer.setSize(e,t,!1),this.composer.setSize(e,t);let n=this.renderer.getDrawingBufferSize(new q);this.atmoDepthPass.setSize(n.x,n.y),this.bloomPass.setSize(e*this.tier.bloomScale,t*this.tier.bloomScale),this.labelRenderer.setSize(e,t),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.ctx.visibility.updateViewport(t),mT(e,t)}dispose(){this.disposed=!0,cancelAnimationFrame(this.rafId),this.pointerInteraction.detach(),this.gpuPick.dispose(),this.controls.removeEventListener(`end`,this.onControlsEnd),this.controls.removeEventListener(`start`,this.invalidate),this.controls.removeEventListener(`start`,this.armLimits),this.controls.removeEventListener(`end`,this.invalidate);for(let t of e.INPUT_EVENTS)this.canvas.removeEventListener(t,this.invalidate);window.removeEventListener(`keydown`,this.invalidate),this.unsubscribeBodiesAdded?.(),this.controls.dispose(),this.haloDebug.dispose(),this.travelPath.dispose(),this.extensions.dispose();for(let e of this.bodyObjects.values())e.model&&dO(e);this.pointClouds.dispose(),this.disposeScene(this.scene),this.disposeScene(this.modelScene),YR(this.scene.background),YR(this.scene.environment),YR(this.modelScene.environment),this.circleTexture.dispose(),this.bodyObjects.clear(),this.composer.dispose(),this.atmoDepthPass.dispose(),this.renderer.dispose()}disposeScene(e){let t=new Set;e.traverse(e=>{let n=e;n.geometry?.dispose();let r=n.material,i=Array.isArray(r)?r:r?[r]:[];for(let e of i)if(!t.has(e)){t.add(e);for(let t of Object.values(e))YR(t);e.dispose()}})}};function YR(e){e&&typeof e==`object`&&e.isTexture&&e.dispose()}var XR=Ze({progress:null,bootPending:!1}),ZR=6371;function QR(e){let t=[];for(let n=0;n<128;n++){let r=Math.PI*(n/127)**2,i=Math.cos(r);t.push(1/(4*Math.PI)*(1-e*e)/(1+e*e-2*e*i)**1.5)}return[...t,...t,...t]}var $R={topAltitudeKm:67,rayleighScatterPerKm:[.0058,.0136,.0331],rayleighScaleHeightKm:8.4,mieScatterPerKm:[.004,.004,.004],mieAbsorptionPerKm:[4e-4,4e-4,4e-4],mieScaleHeightKm:1.2,miePhase:QR(.75),absorptionPerKm:[65e-5,.001881,85e-6],absorptionCenterKm:25,absorptionWidthKm:15,bakedCompensation:1,multiScatterGain:.3,sunIntensity:5,sunColor:[1,1,1]},ez=1.6,tz=1.0005,nz=new J(.55,.25,.8).normalize(),rz=[`low`,`medium`,`high`,`ultra`],iz=4,az=12,oz=10,sz=16,cz=5;function lz(e){return!e.limb&&!e.sky?NaN:Math.max(e.limb?.medianMs??0,e.sky?.medianMs??0)}function uz(e,t){let n=`low`;for(let r of e.tiers){let e=lz(r);!Number.isNaN(e)&&e<=t&&(n=r.tier)}return n}var dz=new Set([`WebKit WebGL`,`Mozilla`,``]);function fz(e){let t=e.getContext(),n=String(t.getParameter(t.RENDERER)??``);if(!dz.has(n))return n;let r=t.getExtension(`WEBGL_debug_renderer_info`);return r?String(t.getParameter(r.UNMASKED_RENDERER_WEBGL)):n}function pz(e,t){let n=e.getContext(),r=new Ka,i=new od(50,n.drawingBufferWidth/Math.max(n.drawingBufferHeight,1),.005,100),a=new pu({color:7829367,roughness:1,metalness:0}),o=new ks(new nu(1,64,64),a);o.renderOrder=1,r.add(o);let s=new pd(16777215,2);s.position.copy(nz),r.add(s);let c=$R,l=wA(c,1,ZR),u=l.material.uniforms;u.uSunDir.value.copy(nz),u.uSunIntensity.value=c.sunIntensity,r.add(l.mesh);let d=e=>{let t=e===`sky`;t?(i.position.set(0,tz,0),i.lookAt(1,tz+.1,0)):(i.position.set(0,0,ez),i.lookAt(0,0,0)),l.material.side=+!!t,l.material.depthWrite=!t,l.material.depthTest=!t},f=new Uint8Array(4),p=()=>new Promise((e,n)=>requestAnimationFrame(()=>t?.aborted?n(Error(`benchmark aborted`)):e())),m=t=>{let a=performance.now();for(let n=0;n<t;n++)e.render(r,i);return n.readPixels(0,0,1,1,n.RGBA,n.UNSIGNED_BYTE,f),(performance.now()-a)/t};return{measure:async(e,t,{decideMs:n,onFrame:r}={})=>{jA(l,Bk[e]),d(t);let i=0;for(let e=0;e<iz;e++)r?.(`warmup`,e+1),await p(),i=m(1);let a=Math.min(sz,Math.max(1,Math.ceil(oz/Math.max(i,.25)))),o=[],s=()=>{let e=[...o].sort((e,t)=>e-t);return{medianMs:e[Math.floor(e.length/2)],p75Ms:e[Math.floor(e.length*.75)]}};for(let e=0;e<az;e++)if(r?.(`measure`,e+1),await p(),o.push(m(a)),n!==void 0&&o.length>=cz){let{medianMs:e,p75Ms:t}=s();if(e>n*1.4||t<n*.7)break}return{...s(),repeats:a}},dispose:()=>{r.remove(o,s,l.mesh),o.geometry.dispose(),a.dispose(),s.dispose(),FA(l)}}}function mz(e,t,n,r){let i=e.getContext();return{tiers:t.map(e=>{let t=n.get(e)??null,i=r.get(e)??null;return{tier:e,limb:t,sky:i,skipped:!t&&!i}}),drawWidth:i.drawingBufferWidth,drawHeight:i.drawingBufferHeight}}async function hz(e,t){let n=t.tiers??rz,{budgetMs:r,signal:i,onProgress:a}=t,o=Math.max(0,n.indexOf(t.startTier??n[n.length-1])),s=pz(e,i),c=iz+az,l=0,u=0,d=(e,t,i)=>s.measure(n[e],t,{decideMs:r,onFrame:(r,o)=>{if(!a)return;l++;let s=c-((r===`measure`?iz:0)+o)+i*c;u=Math.max(u,l/(l+s)),a({tier:n[e],tierIndex:e,tierCount:n.length,scenario:t,phase:r,frame:o,frames:r===`measure`?az:iz,fraction:u})}}),f=new Map,p=new Map,m=async e=>{let t=n[e];if(Bk[t].insideView){let n=await d(e,`sky`,1);if(p.set(t,n),n.medianMs>r)return!1}let i=await d(e,`limb`,0);return f.set(t,i),i.medianMs<=r};try{if(await m(o))for(let e=o+1;e<n.length&&await m(e);e++);else for(let e=o-1;e>=1&&!await m(e);e--);}finally{s.dispose()}return mz(e,n,f,p)}var gz=60,_z=100,vz=3e4,yz=25e4,bz=`v1`,xz=!1,Sz=null,Cz=Promise.resolve();function wz(e){let t=e.getContext(),n=Math.round(t.drawingBufferWidth*t.drawingBufferHeight/yz);return`${fz(e)}|${n}|${bz}`}function Tz(){xz||typeof window>`u`||(xz=!0,XR.bootPending=!0,Cz=new Promise(e=>{let t=()=>{XR.bootPending=!1,e()};setTimeout(t,vz),setTimeout(()=>void Dz(!1).finally(t),_z)}))}function Ez(){return Cz}function Dz(e){return Sz??=Oz(e).finally(()=>Sz=null),Sz}async function Oz(e){let t=jx();if(!e&&(t.atmosphereQuality!==`auto`||!t.showAtmospheres))return;let n=null;try{n=new uh({canvas:document.createElement(`canvas`),antialias:!0}),n.setPixelRatio(Wx()),n.setSize(window.innerWidth,window.innerHeight,!1);let r=wz(n);if(!e&&t.atmosphereCalibration?.key===r)return;XR.progress=0;let i=await hz(n,{budgetMs:1e3/gz,startTier:Vk(),onProgress:e=>XR.progress=e.fraction}),a={};for(let e of i.tiers){let t=lz(e);Number.isNaN(t)||(a[e.tier]=Math.round(t*100)/100)}let o=uz(i,1e3/gz);t.setAtmosphereCalibration({key:r,tier:o,worstMs:a}),t.setAtmosphereAutoTier(null),console.info(`atmosphere calibration: ${o}`,a)}catch(e){console.warn(`atmosphere calibration failed, keeping heuristic tier`,e)}finally{XR.progress=null,n?.dispose(),n?.forceContextLoss()}}var kz=class{object=new Ra;element;label;anchor;occlude;wanted=!0;removeSelf=null;constructor(e,t){this.anchor=e.anchor,this.occlude=e.occlude??!1,this.element=e.element,this.label=new tk(e.element);let[n,r]=e.align??[.5,.5];this.label.center.set(n,r),this.object.add(this.label),this.object.matrixAutoUpdate=!1,Rk(e.element,t)}bind(e){this.removeSelf=e}setAnchor(e){this.anchor=e}setVisible(e){this.wanted=e}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){let{jd:t,basis:n,ctx:r}=e,i=this.wanted?yR(this.anchor,r,t):null;if(!i){this.label.visible=!1;return}let a=i[0]-n[0],o=i[1]-n[1],s=i[2]-n[2];this.label.position.set(a,o,s),this.label.visible=this.occlude?this.facesCamera(i,e):!0,this.object.updateMatrixWorld(!0)}facesCamera(e,{camera:t,ctx:n,jd:r}){let i=bR(this.anchor,e,n,r);if(!i)return!0;let{position:a}=this.label,o=t.position.x-a.x,s=t.position.y-a.y,c=t.position.z-a.z;return i[0]*o+i[1]*s+i[2]*c>0}dispose(){this.label.removeFromParent(),this.element.remove()}},Az=3,jz=new J,Mz=new J,Nz=new J;function Pz(e){let[t,n=t]=(e??``).split(/[\s,]+/).filter(Boolean).map(Number);return t>0&&n>0?[t,n]:null}function Fz(e,t){return jz.set(1,0,0).applyQuaternion(e.quaternion),Mz.set(0,1,0).applyQuaternion(e.quaternion),Nz.set(0,0,-1).applyQuaternion(e.quaternion),t/(2*Math.tan(e.getEffectiveFOV()*Math.PI/360))}function Iz(e,t,n,r){let i=e[t*3]-n.position.x,a=e[t*3+1]-n.position.y,o=e[t*3+2]-n.position.z;r[0]=i*jz.x+a*jz.y+o*jz.z,r[1]=i*Mz.x+a*Mz.y+o*Mz.z,r[2]=i*Nz.x+a*Nz.y+o*Nz.z}function Lz(e,t,n){Nz.set(0,0,-1).applyQuaternion(n.quaternion);let{x:r,y:i,z:a}=n.position;for(let o=0;o<t;o++)if((e[o*3]-r)*Nz.x+(e[o*3+1]-i)*Nz.y+(e[o*3+2]-a)*Nz.z<n.near*2)return!0;return!1}function Rz(e,t,n,r,i){let a=Fz(n,r),o=[0,0,0],s=0,c=0,l=0,u=!1;for(let r=0;r<t;r++){if(Iz(e,r,n,o),o[2]>n.near){let e=o[0]/o[2]*a,t=o[1]/o[2]*a;u&&(s+=Math.hypot(e-c,t-l)),c=e,l=t,u=!0}i[r]=s}}var zz=class{points=new Float32Array;alphas=new Float32Array;lengths=new Float32Array;count=0;a=[0,0,0];b=[0,0,0];see(e,t,n,r,i){this.alphas.length<n*4&&(this.points=new Float32Array(n*12),this.alphas=new Float32Array(n*4),this.lengths=new Float32Array(n*4)),this.count=0;let a=Fz(r,i),o=i*r.aspect*Az/2,s=i*Az/2,c=r.near*2,{a:l,b:u}=this,d=!1,f=0,p=0,m=0;n>0&&Iz(e,0,r,l);for(let i=0;i+1<n;i++,[l,u]=[u,l]){Iz(e,i+1,r,u);let n=0,h=1;for(let e=0;e<5&&n<=h;e++){let t=Bz(e,l,a,o,s,c),r=Bz(e,u,a,o,s,c);t<0&&r<0?h=-1:t<0?n=Math.max(n,t/(t-r)):r<0&&(h=Math.min(h,t/(t-r)))}if(n>h){d=!1;continue}let g=l[2]+(u[2]-l[2])*n,_=(l[0]+(u[0]-l[0])*n)/g*a,v=(l[1]+(u[1]-l[1])*n)/g*a;(!d||n>0)&&(this.count>0&&(this.copy(this.count-1,0),this.put(e,t,i,n,f,0)),this.put(e,t,i,n,f,1),p=_,m=v);let y=l[2]+(u[2]-l[2])*h,b=(l[0]+(u[0]-l[0])*h)/y*a,x=(l[1]+(u[1]-l[1])*h)/y*a;f+=Math.hypot(b-p,x-m),p=b,m=x,this.put(e,t,i,h,f,1),d=h===1}}put(e,t,n,r,i,a){let o=this.count++;for(let t=0;t<3;t++){let i=e[n*3+t];this.points[o*3+t]=i+(e[n*3+3+t]-i)*r}this.alphas[o]=(t[n]+(t[n+1]-t[n])*r)*a,this.lengths[o]=i}copy(e,t){let n=this.count++;this.points.copyWithin(n*3,e*3,e*3+3),this.alphas[n]=this.alphas[e]*t,this.lengths[n]=this.lengths[e]}};function Bz(e,t,n,r,i,a){return e===0?t[2]-a:e===1?r*t[2]-n*t[0]:e===2?r*t[2]+n*t[0]:e===3?i*t[2]-n*t[1]:i*t[2]+n*t[1]}var Vz=1e-9,Hz=class{object=new Ra;anchor;color;widthPx;opacity;dash;fade;closed;local;count=0;mesh=null;scratch=new Float32Array;alphas=new Float32Array;seen=new zz;capacity=0;lastOrigin=[0,0,0];dirty=!0;wanted=!0;removeSelf=null;constructor(e){this.anchor=e.anchor,this.color=e.color??`#ffffff`,this.widthPx=e.widthPx??2,this.opacity=e.opacity??1,this.dash=Pz(e.dash),this.fade=e.fade??!1,this.closed=e.closed??!1,this.local=new Float64Array,this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){let t=e.length+(this.closed&&e.length>2?1:0);this.local.length<t*3&&(this.local=new Float64Array(t*3));for(let t=0;t<e.length;t++){let[n,r,i]=e[t];this.local[t*3]=Q(n),this.local[t*3+1]=Q(i),this.local[t*3+2]=Q(-r)}t>e.length&&this.local.copyWithin(e.length*3,0,3),this.count=t,this.alphas.length<t&&(this.scratch=new Float32Array(t*3),this.alphas=new Float32Array(t)),t>this.capacity&&this.rebuild(t),this.fillAlphas(),this.dirty=!0}fillAlphas(){let e=this.count;for(let t=0;t<e;t++)this.alphas[t]=this.fade&&e>1?this.opacity*(1-t/(e-1)):this.opacity}setAnchor(e){this.anchor=e}setVisible(e){this.wanted=e}remove(){this.removeSelf?.(),this.removeSelf=null}update({jd:e,basis:t,camera:n,viewportPx:r,ctx:i}){let a=this.wanted&&this.count>=2?yR(this.anchor,i,e):null;if(this.mesh&&(this.mesh.visible=a!==null),!this.mesh||!a)return;let o=[a[0]-t[0],a[1]-t[1],a[2]-t[2]],s=this.dirty||Math.abs(o[0]-this.lastOrigin[0])>Vz||Math.abs(o[1]-this.lastOrigin[1])>Vz||Math.abs(o[2]-this.lastOrigin[2])>Vz;if(s){for(let e=0;e<this.count*3;e++)this.scratch[e]=this.local[e]+o[e%3];this.lastOrigin=o}let c=this.dash!==null||Lz(this.scratch,this.count,n);if(c){let{seen:e}=this;e.see(this.scratch,this.alphas,this.count,n,r),e.count>this.capacity&&this.rebuild(e.count),dN(this.mesh.geometry,e.points,e.alphas,e.alphas,e.count),this.dash&&mN(this.mesh.geometry,e.lengths,e.count)}else s&&dN(this.mesh.geometry,this.scratch,this.alphas,this.alphas,this.count);this.dirty=c,this.mesh.material.uniforms.uCenterOffset.value.copy(n.position).negate()}rebuild(e){this.disposeMesh(),this.dirty=!0;let t=hN(e,this.scratch,this.alphas,this.alphas,0,this.color,this.widthPx,1,this.dash??void 0);t.frustumCulled=!1,this.object.add(t),this.mesh=t,this.capacity=e}disposeMesh(){let e=this.mesh;e&&(this.object.remove(e),e.geometry.dispose(),e.material.dispose(),this.mesh=null)}dispose(){this.disposeMesh()}};function Uz(e){let t=Math.hypot(e[0],e[1],e[2]),n=t>0?[e[0]/t,e[1]/t,e[2]/t]:[0,0,1],r=Wz(Math.abs(n[2])<.9?[0,0,1]:[1,0,0],n),i=Math.hypot(r[0],r[1],r[2]),a=[r[0]/i,r[1]/i,r[2]/i];return[a,Wz(n,a)]}function Wz(e,t){return[e[1]*t[2]-e[2]*t[1],e[2]*t[0]-e[0]*t[2],e[0]*t[1]-e[1]*t[0]]}function Gz(e,t={}){let[n,r]=Uz(t.normal??[0,0,1]),i=Math.max(3,Math.round(t.steps??128)),a=[];for(let t=0;t<i;t++){let o=2*Math.PI*t/i,s=Math.cos(o)*e,c=Math.sin(o)*e;a.push([n[0]*s+r[0]*c,n[1]*s+r[1]*c,n[2]*s+r[2]*c])}return a}function Kz(e){if(e.length<3)return[];let[t,n]=Uz(qz(e)),r=e.map(e=>new q(e[0]*t[0]+e[1]*t[1]+e[2]*t[2],e[0]*n[0]+e[1]*n[1]+e[2]*n[2]));return Yl.triangulateShape(r,[]).flat()}function qz(e){let t=0,n=0,r=0;for(let i=0;i<e.length;i++){let a=e[i],o=e[(i+1)%e.length];t+=(a[1]-o[1])*(a[2]+o[2]),n+=(a[2]-o[2])*(a[0]+o[0]),r+=(a[0]-o[0])*(a[1]+o[1])}return Math.hypot(t,n,r)>0?[t,n,r]:[0,0,1]}function Jz(e,t,n){let r=Math.min(1,Math.max(-1,e[0]*t[0]+e[1]*t[1]+e[2]*t[2])),i=Math.acos(r);if(i<1e-9||Math.PI-i<1e-9)return Yz([e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]);let a=Math.sin(i),o=Math.sin((1-n)*i)/a,s=Math.sin(n*i)/a;return[e[0]*o+t[0]*s,e[1]*o+t[1]*s,e[2]*o+t[2]*s]}function Yz(e){let t=Math.hypot(e[0],e[1],e[2]);return t>0?[e[0]/t,e[1]/t,e[2]/t]:[0,0,1]}function Xz(e,t){let n=0,r=0,i=0;for(let a=0;a<t;a++)n+=e[a*3],r+=e[a*3+1],i+=e[a*3+2];return Math.hypot(n,r,i)<1e-9?[e[0],e[1],e[2]]:Yz([n,r,i])}function Zz(e,t){return new du({transparent:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:new X(e)},uOpacity:{value:t},uCenterOffset:{value:new J}},vertexShader:`
5551
5551
  #include <common>
5552
5552
  #include <logdepthbuf_pars_vertex>
5553
5553
  uniform vec3 uCenterOffset;
@@ -5566,4 +5566,4 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
5566
5566
  }
5567
5567
  `})}var Qz=.25,$z=1e-9,eB=3,tB=class{object=new Ra;anchor;outline;fillColor;fillOpacity;local=new Float64Array;count=0;mesh=null;scratch=new Float32Array;lastOrigin=[0,0,0];dirty=!0;wanted=!0;removeSelf=null;constructor(e){this.anchor=e.anchor;let t=e.widthPx??2;this.fillColor=e.fill??null,this.fillOpacity=e.fillOpacity??Qz,this.outline=t>0?new Hz({anchor:e.anchor,points:e.points,color:e.color,widthPx:t,opacity:e.opacity,closed:!0}):null,this.outline&&this.object.add(this.outline.object),this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){this.outline?.setPoints(e),this.local.length<e.length*3&&(this.local=new Float64Array(e.length*3));for(let t=0;t<e.length;t++){let[n,r,i]=e[t];this.local[t*3]=Q(n),this.local[t*3+1]=Q(i),this.local[t*3+2]=Q(-r)}this.count=e.length,this.rebuild(e)}setAnchor(e){this.anchor=e,this.outline?.setAnchor(e)}setVisible(e){this.wanted=e,this.outline?.setVisible(e)}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){this.outline?.update(e);let t=this.mesh;if(!t)return;let{jd:n,basis:r,camera:i,ctx:a}=e,o=this.wanted?yR(this.anchor,a,n):null;if(t.visible=o!==null,!o)return;let s=[o[0]-r[0],o[1]-r[1],o[2]-r[2]];if(this.dirty||Math.abs(s[0]-this.lastOrigin[0])>$z||Math.abs(s[1]-this.lastOrigin[1])>$z||Math.abs(s[2]-this.lastOrigin[2])>$z){let e=t.geometry.getAttribute(`position`);for(let e=0;e<this.count*3;e+=3)this.scratch[e]=this.local[e]+s[0],this.scratch[e+1]=this.local[e+1]+s[1],this.scratch[e+2]=this.local[e+2]+s[2];e.needsUpdate=!0,this.lastOrigin=s,this.dirty=!1}t.material.uniforms.uCenterOffset.value.copy(i.position).negate()}rebuild(e){this.disposeMesh(),this.dirty=!0;let t=this.fillColor;if(!t)return;let n=Kz(e);if(!n.length)return;let r=new Vo;r.setAttribute(`position`,new ko(new Float32Array(e.length*3),3)),r.setIndex(n),this.scratch=r.getAttribute(`position`).array;let i=new ks(r,Zz(t,this.fillOpacity));i.matrixAutoUpdate=!1,i.renderOrder=eB,i.frustumCulled=!1,this.object.add(i),this.mesh=i}disposeMesh(){let e=this.mesh;e&&(this.object.remove(e),e.geometry.dispose(),e.material.dispose(),this.mesh=null)}dispose(){this.disposeMesh(),this.outline?.dispose()}},nB=class extends tB{normal;steps;constructor(e){let{radiusKm:t,normal:n,steps:r,...i}=e;super({...i,points:Gz(t,{normal:n,steps:r})}),this.normal=n,this.steps=r}setRadiusKm(e){this.setPoints(Gz(e,{normal:this.normal,steps:this.steps}))}},rB=class extends kz{constructor(e,t){let n=document.createElement(`div`);n.className=`sm-drawing-label`,e.interactive&&n.classList.add(`sm-drawing--interactive`),e.className&&n.classList.add(e.className),n.textContent=e.text,e.color&&(n.style.color=e.color),e.fontSizePx!==void 0&&(n.style.fontSize=`${e.fontSizePx}px`),super({anchor:e.anchor,element:n,align:e.align,occlude:e.occlude},t)}setText(e){this.element.textContent=e}},iB=class extends kz{constructor(e,t){let n=document.createElement(`img`);n.className=`sm-drawing-icon`,e.interactive&&n.classList.add(`sm-drawing--interactive`),e.className&&n.classList.add(e.className),n.src=e.url,n.alt=e.alt??``,e.widthPx!==void 0&&(n.style.width=`${e.widthPx}px`),e.heightPx!==void 0&&(n.style.height=`${e.heightPx}px`),e.opacity!==void 0&&(n.style.opacity=String(e.opacity)),super({anchor:e.anchor,element:n,align:e.align,occlude:e.occlude},t)}setUrl(e){this.element.src=e}},aB=Math.PI/180,oB=180/Math.PI;function sB(e){return e>=-180&&e<180?e:((e+180)%360+360)%360-180}function cB(e,t){return(n,r)=>{let i=e(r);return!i||Math.abs(n)>i.maxAbsX+1e-9?null:[sB(n*i.lonPerX+t),i.lat]}}function lB(e){let{minX:t,maxX:n,minY:r,maxY:i}=e.extent;return(n-t)/(i-r)}function uB(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=179.999999999;for(let o=0;o<=720;o++){let s=-90+180*o/720;for(let o=0;o<=720;o++){let c=e(-a+2*a*o/720,s);c&&(c[0]<t&&(t=c[0]),c[0]>r&&(r=c[0]),c[1]<n&&(n=c[1]),c[1]>i&&(i=c[1]))}}return{minX:t,minY:n,maxX:r,maxY:i}}function dB(e){let t=e.centerLon??0,n=e=>Math.abs(e)>Math.PI/2?null:{lat:e*oB,lonPerX:oB,maxAbsX:Math.PI};return{id:`equirectangular`,centerLon:t,cyclic:!0,rectangular:!0,azimuthal:!1,extent:{minX:-Math.PI,minY:-Math.PI/2,maxX:Math.PI,maxY:Math.PI/2},forward:(e,n)=>[sB(e-t)*aB,n*aB],rowInverse:n,inverse:cB(n,t)}}var fB=1.340264,pB=-.081106,mB=893e-6,hB=.003796,gB=Math.sqrt(3),_B=e=>hB*e**9+mB*e**7+pB*e**3+fB*e,vB=e=>9*hB*e**8+7*mB*e**6+3*pB*e**2+fB;function yB(e){let t=e.centerLon??0,n=(e,n)=>{let r=Math.asin(FB(gB/2*Math.sin(n*aB))),i=sB(e-t)*aB;return[2*gB*i*Math.cos(r)/(3*vB(r)),_B(r)]},r=e=>{let t=e;for(let n=0;n<12;n++){let n=(_B(t)-e)/vB(t);if(t-=n,Math.abs(n)<1e-12)break}return t},i=e=>{let t=r(e),n=2/gB*Math.sin(t);if(Math.abs(n)>1)return null;let i=3*vB(t)/(2*gB*Math.cos(t))*oB;return{lat:Math.asin(n)*oB,lonPerX:i,maxAbsX:180/i}};return{id:`equalEarth`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:uB(n),forward:n,rowInverse:i,inverse:cB(i,t)}}var bB=Math.SQRT2;function xB(e){let t=e.centerLon??0,n=e=>{let t=e/bB;if(Math.abs(t)>1)return null;let n=Math.asin(t),r=(2*n+Math.sin(2*n))/Math.PI;if(Math.abs(r)>1)return null;let i=Math.cos(n);if(i<1e-12)return{lat:Math.sign(e)*90,lonPerX:0,maxAbsX:0};let a=Math.PI/(2*bB*i)*oB;return{lat:Math.asin(r)*oB,lonPerX:a,maxAbsX:180/a}};return{id:`mollweide`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-2*bB,minY:-bB,maxX:2*bB,maxY:bB},forward:(e,n)=>{let r=n*aB,i=r;if(Math.abs(Math.abs(r)-Math.PI/2)<1e-9)i=Math.PI/2*Math.sign(r);else{let e=Math.PI*Math.sin(r);for(let t=0;t<20;t++){let t=(2*i+Math.sin(2*i)-e)/(2+2*Math.cos(2*i));if(i-=t,Math.abs(t)<1e-12)break}}let a=sB(e-t)*aB;return[2*bB/Math.PI*a*Math.cos(i),bB*Math.sin(i)]},rowInverse:n,inverse:cB(n,t)}}function SB(e){let t=e.centerLon??0,n=e=>{if(Math.abs(e)>Math.PI/2)return null;let t=Math.cos(e);return t<1e-12?{lat:Math.sign(e)*90,lonPerX:0,maxAbsX:0}:{lat:e*oB,lonPerX:oB/t,maxAbsX:Math.PI*t}};return{id:`sinusoidal`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-Math.PI,minY:-Math.PI/2,maxX:Math.PI,maxY:Math.PI/2},forward:(e,n)=>{let r=n*aB;return[sB(e-t)*aB*Math.cos(r),r]},rowInverse:n,inverse:cB(n,t)}}var CB=[1,.9986,.9954,.99,.9822,.973,.96,.9427,.9216,.8962,.8679,.835,.7986,.7597,.7186,.6732,.6213,.5722,.5322],wB=[0,.062,.124,.186,.248,.31,.372,.434,.4958,.5571,.6176,.6769,.7346,.7903,.8435,.8936,.9394,.9761,1],TB=.8487,EB=1.3523,DB=5;function OB(e,t){let n=e[Math.max(t-1,0)],r=e[t],i=e[t+1],a=e[Math.min(t+2,e.length-1)];return[r,.5*(i-n),.5*(2*n-5*r+4*i-a),.5*(-n+3*r-3*i+a)]}var kB=(e,t)=>e[0]+t*(e[1]+t*(e[2]+t*e[3])),AB=(e,t)=>e[1]+t*(2*e[2]+3*e[3]*t);function jB(e){let t=Math.min(Math.max(Math.floor(e),0),CB.length-2);return[t,e-t]}function MB(e){let[t,n]=jB(e);return TB*kB(OB(CB,t),n)*Math.PI}function NB(e){let t=0,n=wB.length-1;for(;n-t>1;){let r=t+n>>1;wB[r]<=e?t=r:n=r}let r=Math.min(t,wB.length-2),i=OB(wB,r),a=(e-wB[r])/(wB[r+1]-wB[r]);for(let t=0;t<8;t++){let t=AB(i,a);if(t===0)break;let n=(kB(i,a)-e)/t;if(a-=n,Math.abs(n)<1e-14)break}return r+Math.min(Math.max(a,0),1)}function PB(e){let t=e.centerLon??0,n=e=>{let t=Math.abs(e)/EB;if(t>1)return null;let n=NB(t),r=MB(n);return{lat:Math.sign(e)*n*DB,lonPerX:180/r,maxAbsX:r}};return{id:`robinson`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-TB*Math.PI,minY:-EB,maxX:TB*Math.PI,maxY:EB},forward:(e,n)=>{let[r,i]=jB(Math.abs(n)/DB),a=kB(OB(CB,r),i),o=kB(OB(wB,r),i);return[TB*a*sB(e-t)*aB,EB*o*Math.sign(n)]},rowInverse:n,inverse:cB(n,t)}}function FB(e){return e<-1?-1:e>1?1:e}function IB(e,t,n,r,i,a,o){let s=Math.asin(FB(n*a+t*r*o));return[sB(i+Math.atan2(e*r,n*o-t*r*a)*oB),s*oB]}function LB(e){return{minX:-e,minY:-e,maxX:e,maxY:e}}function RB(e,t,n,r){let i=sB(e-n)*aB,a=t*aB;return[Math.cos(a)*Math.sin(i),Math.cos(r)*Math.sin(a)-Math.sin(r)*Math.cos(a)*Math.cos(i)]}function zB(e){let t=e.centerLon??0,n=(e.centerLat??0)*aB,r=Math.min(e.clipAngle??90,90)*aB,i=Math.cos(r),a=Math.sin(r),o=Math.sin(n),s=Math.cos(n);return{id:`orthographic`,centerLon:t,cyclic:!1,rectangular:!1,azimuthal:!0,extent:LB(a),forward:(e,r)=>{let a=sB(e-t)*aB,o=r*aB;return Math.sin(n)*Math.sin(o)+Math.cos(n)*Math.cos(o)*Math.cos(a)<i?null:RB(e,r,t,n)},inverse:(e,n)=>{let r=e*e+n*n;return r>a*a?null:IB(e,n,Math.sqrt(1-r),1,t,o,s)}}}var BB=120;function VB(e){let t=e.centerLon??0,n=(e.centerLat??90)*aB,r=Math.min(e.clipAngle??BB,170)*aB,i=Math.cos(r),a=2*Math.tan(r/2),o=Math.sin(n),s=Math.cos(n);return{id:`stereographic`,centerLon:t,cyclic:!1,rectangular:!1,azimuthal:!0,extent:LB(a),forward:(e,r)=>{let a=sB(e-t)*aB,o=r*aB,s=Math.sin(n)*Math.sin(o)+Math.cos(n)*Math.cos(o)*Math.cos(a);if(s<i)return null;let c=2/(1+s),[l,u]=RB(e,r,t,n);return[c*l,c*u]},inverse:(e,n)=>{let r=e*e+n*n;if(r>a*a)return null;let i=4/(4+r);return IB(e,n,(4-r)*i*.25,i,t,o,s)}}}var HB={equirectangular:dB,equalEarth:yB,mollweide:xB,sinusoidal:SB,robinson:PB,orthographic:zB,stereographic:VB},UB=Object.keys(HB);function WB(e,t={}){let n=HB[e];if(!n)throw Error(`spacemap: unknown projection "${e}"`);return n(t)}var GB=Math.PI/180,KB=2*Math.PI,qB=2*GB,JB=180/Math.PI,YB=512,XB=2;function ZB(e,t){let n=e.lat*GB,r=t.lat*GB,i=r-n,a=sB(t.lon-e.lon)*GB,o=Math.sin(i/2)**2+Math.cos(n)*Math.cos(r)*Math.sin(a/2)**2;return 2*Math.asin(Math.min(1,Math.sqrt(o)))*JB}function QB(e,t,n){let r=ZB(e,t)*GB;if(r<1e-12)return e;let i=Math.sin(r),a=Math.sin((1-n)*r)/i,o=Math.sin(n*r)/i,s=e.lat*GB,c=e.lon*GB,l=t.lat*GB,u=(e.lon+sB(t.lon-e.lon))*GB,d=a*Math.cos(s)*Math.cos(c)+o*Math.cos(l)*Math.cos(u),f=a*Math.cos(s)*Math.sin(c)+o*Math.cos(l)*Math.sin(u),p=a*Math.sin(s)+o*Math.sin(l);return{lon:Math.atan2(f,d)*JB,lat:Math.atan2(p,Math.hypot(d,f))*JB}}function $B(e,t,n){return{lon:e.lon+sB(t.lon-e.lon)*n,lat:e.lat+(t.lat-e.lat)*n}}function eV(e,t={}){let n=t.interpolate??`linear`,r=t.stepDeg??XB,i=n===`geodesic`?QB:$B,a=t.closed&&e.length>2?[...e,e[0]]:e;if(a.length<2)return[...a];let o=[a[0]];for(let e=1;e<a.length;e++){let t=a[e-1],n=a[e],s=Math.min(YB,Math.max(1,Math.ceil(ZB(t,n)/r)));for(let e=1;e<=s;e++)o.push(e===s?n:i(t,n,e/s))}return o}function tV(e,t,n){let r=0,i=1;for(let a=0;a<20;a++){let a=(r+i)/2,o=$B(e,t,a);n.forward(o.lon,o.lat)?r=a:i=a}return $B(e,t,r)}function nV(e,t){let n=t.projection.cyclic?t.worldWidthPx/2:1/0,{projection:r}=t,i=[],a=[],o=null,s=0;for(let c=0;c<e.length;c++){let l=e[c],u=t.project(l.lon,l.lat);if(!u){if(a.length&&c>0){let n=tV(e[c-1],l,r);a.push(t.project(n.lon,n.lat))}a.length>1&&i.push(a),a=[],o=null,s++;continue}if(o&&Math.abs(u[0]-o[0])>n&&(a.length>1&&i.push(a),a=[]),!a.length&&c>0&&!t.project(e[c-1].lon,e[c-1].lat)){let n=tV(l,e[c-1],r);a.push(t.project(n.lon,n.lat))}a.push(u),o=u}return a.length>1&&i.push(a),{runs:i,whole:i.length===1&&s===0}}function rV(e,t){let n=[...e];for(let r of t.repeatShifts)if(r!==0)for(let i of e){let e=1/0,a=-1/0;for(let[t]of i)t<e&&(e=t),t>a&&(a=t);e+r>t.width||a+r<0||n.push(i.map(([e,t])=>[e+r,t]))}return n}function iV(e,t){let n=`M${e[0][0].toFixed(2)} ${e[0][1].toFixed(2)}`;for(let t=1;t<e.length;t++)n+=`L${e[t][0].toFixed(2)} ${e[t][1].toFixed(2)}`;return t?`${n}Z`:n}var aV=179.999999;function oV(e,t){let n=e=>e>aV?aV:e<-aV?-aV:e,r=e.length;if(r<3)return[e];let i=[],a=[],o=sB(e[0].lon-t);a.push({lon:n(o),lat:e[0].lat});for(let t=0;t<r;t++){let s=e[t],c=e[(t+1)%r],l=sB(c.lon-s.lon),u=o+l,d=u>180?1:u<-180?-1:0;if(d!==0){let e=s.lat+(c.lat-s.lat)*((d*180-o)/l);a.push({lon:d*aV,lat:e}),i.push(a),a=[{lon:-d*aV,lat:e}],o=u-d*360}else o=u;t<r-1&&a.push({lon:n(o),lat:c.lat})}return i.length===0?[a.map(e=>({lon:e.lon+t,lat:e.lat}))]:(i[0]=a.concat(i[0]),i.map(e=>e.map(e=>({lon:e.lon+t,lat:e.lat}))))}function sV(e,t,n={}){if(e.length<2)return``;let{projection:r}=t;return(n.closed&&r.cyclic?oV(e,r.centerLon):[e]).map(e=>{let{runs:r,whole:i}=nV(eV(e,n),t),a=!!n.closed&&i;return rV(r,t).map(e=>iV(e,a)).join(``)}).join(``)}function cV(e,t,n={}){let{projection:r}=t;if(!r.azimuthal)return sV(e,t,{...n,closed:!0});if(e.length<2)return``;let i=eV(e,{...n,closed:!0}),a=e.length>2?i.slice(0,-1):i,o=a.map(e=>r.forward(e.lon,e.lat)),s=([e,n])=>t.toScreen(e,n),c=o.filter(Boolean).length;if(c===0)return``;if(c===a.length)return iV(o.map(e=>s(e)),!0);let l=a.length,u=0;for(;!o[u]||o[(u+l-1)%l];)u++;let d=[],f=null;for(let e=0;e<l;e++){let t=(u+e)%l,n=(t+l-1)%l,i=o[t];if(i){if(!f){let e=tV(a[t],a[n],r);f=[r.forward(e.lon,e.lat)]}f.push(i)}else if(f){let e=tV(a[n],a[t],r);f.push(r.forward(e.lon,e.lat)),d.push(f),f=null}}let p=lV(a),m=([e,t])=>Math.atan2(t,e),h=Math.hypot(...d[0][0]),g=[],_=new Set;for(let e=0;e<d.length;e++){if(_.has(e))continue;let t=[],n=e;do{_.add(n),t.push(...d[n]);let r=m(d[n][d[n].length-1]),i=e,a=1/0;for(let e=0;e<d.length;e++){let t=m(d[e][0]),n=((p?t-r:r-t)%KB+KB)%KB;n<a&&(a=n,i=e)}let o=Math.ceil(a/qB);for(let e=1;e<o;e++){let n=r+(p?1:-1)*a*e/o;t.push([h*Math.cos(n),h*Math.sin(n)])}n=i}while(n!==e&&!_.has(n));g.push(t)}return g.map(e=>iV(e.map(s),!0)).join(``)}function lV(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t+=sB(i.lon-r.lon)*GB*(2+Math.sin(r.lat*GB)+Math.sin(i.lat*GB))}let n=-t/2;return n>0?n<KB:n<-KB}function uV(e,t=2){let{projection:n}=e,r=179.999999,i=[],a=(r,a,o)=>{let s=a<o?t:-t;for(let t=a;s>0?t<=o:t>=o;t+=s){let a=n.forward(r,t);a&&i.push(e.toScreen(a[0],a[1]))}};return a(n.centerLon-r,-90,90),a(n.centerLon+r,90,-90),i.length<3?``:rV([i],e).map(e=>iV(e,!0)).join(``)}function dV(e,t,n,r){let i=n+r,a=[],o=(e,t,n)=>{let r=Math.max(1,Math.ceil(Math.abs(n-t)/5));for(let i=0;i<=r;i++)a.push({lon:t+(n-t)*i/r,lat:e})};return o(e,n,i),o(t,i,n),a}function fV(e,t,n=128){let r=e.lat*GB,i=e.lon*GB,a=[Math.cos(r)*Math.cos(i),Math.cos(r)*Math.sin(i),Math.sin(r)],o=[-a[1],a[0],0],s=Math.hypot(o[0],o[1]);o=s<1e-9?[1,0,0]:[o[0]/s,o[1]/s,0];let c=[a[1]*o[2]-a[2]*o[1],a[2]*o[0]-a[0]*o[2],a[0]*o[1]-a[1]*o[0]],l=t*GB,u=Math.sin(l),d=Math.cos(l),f=[];for(let e=0;e<n;e++){let t=2*Math.PI*e/n,r=Math.sin(t)*u,i=Math.cos(t)*u,s=a[0]*d+o[0]*r+c[0]*i,l=a[1]*d+o[1]*r+c[1]*i,p=a[2]*d+o[2]*r+c[2]*i;f.push({lon:sB(Math.atan2(l,s)*JB),lat:Math.atan2(p,Math.hypot(s,l))*JB})}return f}var pV=24;function mV(e=30){let t=[];for(let n=-180;n<180;n+=e)t.push([{lon:n,lat:-90},{lon:n,lat:90}]);let n=179.999999;for(let r=-90+e;r<90;r+=e){let e=[];for(let t=0;t<=pV;t++)e.push({lon:-n+2*n*t/pV,lat:r});t.push(e)}return t}var hV=.005,gV=1.5,_V=5,vV=24,yV=class{object=new Ra;body;altitudeKm;closed;interpolate;stepDeg;color;widthPx;opacity;dash;fillColor;fillOpacity;dirs=new Float64Array;count=0;line=null;scratch=new Float32Array;alphas=new Float32Array;lengths=new Float32Array;fanDirs=new Float64Array;fill=null;fillScratch=new Float32Array;turned=[0,0,0];wanted=!0;removeSelf=null;constructor(e){this.body=e.body,this.altitudeKm=e.altitudeKm??null,this.closed=e.closed??!1,this.interpolate=e.interpolate??`linear`,this.stepDeg=e.stepDeg,this.color=e.color??`#ffffff`,this.widthPx=e.widthPx??2,this.opacity=e.opacity??1,this.dash=Pz(e.dash),this.fillColor=e.fill??null,this.fillOpacity=e.fillOpacity??.25,this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){let t=eV(e,{interpolate:this.interpolate,stepDeg:this.stepDeg,closed:this.closed});this.dirs=new Float64Array(t.length*3);for(let e=0;e<t.length;e++){let[n,r,i]=hR(t[e].lat,t[e].lon);this.dirs[e*3]=n,this.dirs[e*3+1]=r,this.dirs[e*3+2]=i}this.count=t.length,this.buildLine(),this.buildFill()}setVisible(e){this.wanted=e}remove(){this.removeSelf?.(),this.removeSelf=null}update({jd:e,basis:t,camera:n,viewportPx:r,ctx:i}){let a=this.wanted&&this.count>=2?i.getBody(this.body):void 0,o=a&&_R(a,i,e);if(this.line&&(this.line.visible=!!o),this.fill&&(this.fill.visible=!!o),!a||!o)return;let s=mn(a.data),c=Q(s+(this.altitudeKm??s*hV)),l=a.orientation?pC(a.orientation,e,a.nutPrec):null,u=[o[0]-t[0],o[1]-t[1],o[2]-t[2]];if(this.line&&(this.place(this.dirs,this.count,l,c,u,this.scratch),dN(this.line.geometry,this.scratch,this.alphas,this.alphas,this.count),this.dash&&(Rz(this.scratch,this.count,n,r,this.lengths),mN(this.line.geometry,this.lengths,this.count)),this.line.material.uniforms.uCenterOffset.value.copy(n.position).negate()),this.fill){let e=this.fill.geometry.getAttribute(`position`);this.place(this.fanDirs,this.fillScratch.length/3,l,c,u,this.fillScratch),e.needsUpdate=!0,this.fill.material.uniforms.uCenterOffset.value.copy(n.position).negate()}}place(e,t,n,r,i,a){for(let o=0;o<t;o++){let t=o*3;n?gR(n,e[t],e[t+1],e[t+2],this.turned,0):(this.turned[0]=e[t],this.turned[1]=e[t+1],this.turned[2]=e[t+2]),a[t]=this.turned[0]*r+i[0],a[t+1]=this.turned[1]*r+i[1],a[t+2]=this.turned[2]*r+i[2]}}buildLine(){if(this.disposeLine(),this.count<2||this.widthPx<=0)return;this.scratch=new Float32Array(this.count*3),this.alphas=new Float32Array(this.count).fill(this.opacity),this.lengths=new Float32Array(this.count);let e=hN(this.count,this.scratch,this.alphas,this.alphas,this.count,this.color,this.widthPx,1,this.dash??void 0);e.frustumCulled=!1,e.renderOrder=gV,this.object.add(e),this.line=e}buildFill(){if(this.disposeFill(),!this.fillColor||this.count<3)return;let e=Xz(this.dirs,this.count),t=0;for(let n=0;n<this.count;n++){let r=e[0]*this.dirs[n*3]+e[1]*this.dirs[n*3+1]+e[2]*this.dirs[n*3+2];t=Math.max(t,Math.acos(Math.min(1,Math.max(-1,r))))}let n=Math.min(vV,Math.max(1,Math.ceil(t*180/Math.PI/_V))),r=1+n*this.count;this.fanDirs=new Float64Array(r*3),this.fanDirs[0]=e[0],this.fanDirs[1]=e[1],this.fanDirs[2]=e[2];for(let t=1;t<=n;t++)for(let r=0;r<this.count;r++){let[i,a,o]=Jz(e,[this.dirs[r*3],this.dirs[r*3+1],this.dirs[r*3+2]],t/n),s=(1+(t-1)*this.count+r)*3;this.fanDirs[s]=i,this.fanDirs[s+1]=a,this.fanDirs[s+2]=o}let i=[],a=(e,t)=>1+(e-1)*this.count+t;for(let e=0;e<this.count-1;e++)i.push(0,a(1,e),a(1,e+1));for(let e=1;e<n;e++)for(let t=0;t<this.count-1;t++){let n=a(e,t),r=a(e,t+1),o=a(e+1,t),s=a(e+1,t+1);i.push(n,o,r,r,o,s)}let o=new Vo;o.setAttribute(`position`,new ko(new Float32Array(r*3),3)),o.setIndex(i),this.fillScratch=o.getAttribute(`position`).array;let s=new ks(o,Zz(this.fillColor,this.fillOpacity));s.matrixAutoUpdate=!1,s.frustumCulled=!1,s.renderOrder=gV,this.object.add(s),this.fill=s}disposeLine(){this.line&&=(this.object.remove(this.line),this.line.geometry.dispose(),this.line.material.dispose(),null)}disposeFill(){this.fill&&=(this.object.remove(this.fill),this.fill.geometry.dispose(),this.fill.material.dispose(),null)}dispose(){this.disposeLine(),this.disposeFill()}},bV=class{object=new Ra;id;name;anchor;model;trueScale;spanScene;minPx;label;wanted=!0;removeSelf=null;constructor(e,t,n){this.id=t,this.name=e.name??null,this.anchor=e.position,this.object.matrixAutoUpdate=!1,this.object.frustumCulled=!1;let r=e.model;this.model=r?.object3d??null,this.minPx=r?.minPx??0;let i=r?xV(r.object3d):0;this.trueScale=r?.scaleM!==void 0&&i>0?Q(r.scaleM/1e3)/i:1,this.spanScene=i*this.trueScale,this.model&&this.object.add(this.model),this.label=e.label&&this.name?new rB({anchor:e.position,text:this.name,align:[.5,1.4],occlude:e.occludeLabel},n):null,this.label&&this.object.add(this.label.object)}bind(e){this.removeSelf=e}get position(){return this.anchor}positionKm(e){let t=this.anchor;if(`latitude`in t)return null;let n=typeof t.offsetKm==`function`?t.offsetKm(e):t.offsetKm;return n===void 0?[0,0,0]:n}setPosition(e){this.anchor=e,this.label?.setAnchor(e)}setVisible(e){this.wanted=e,this.label?.setVisible(e)}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){let{basis:t,camera:n,jd:r,ctx:i}=e,a=this.model,o=this.wanted?yR(this.anchor,i,r):null;if(this.label?.update(e),!a||(a.visible=o!==null,!o))return;a.position.set(o[0]-t[0],o[1]-t[1],o[2]-t[2]);let s=this.drawnScale(a.position,n,e.viewportPx);a.scale.setScalar(s),a.updateMatrixWorld(!0)}drawnScale(e,t,n){if(this.minPx<=0||this.spanScene<=0)return this.trueScale;let r=t.position.distanceTo(e);if(r<=0)return this.trueScale;let i=n/(2*Math.tan(t.fov*Math.PI/180/2)*r),a=this.spanScene*i;return a>=this.minPx?this.trueScale:this.trueScale*(this.minPx/a)}dispose(){this.label?.dispose(),this.model&&this.object.remove(this.model)}};function xV(e){let t=new so().setFromObject(e).getSize(new J);return Math.max(t.x,t.y,t.z)}var SV=class{byId=new Map;nextId=1;constructor(e,t){this.registry=e,this.canvas=t}add(e){let t=e.id??`object-${this.nextId++}`;this.byId.get(t)?.remove();let n=new bV(e,t,this.canvas()),r=this.registry();return n.bind(()=>{this.byId.delete(t),r.remove(n)}),this.byId.set(t,n),r.add(n),n}get(e){return this.byId.get(e)}all(){return[...this.byId.values()]}clear(){for(let e of[...this.byId.values()])e.remove()}};function CV(e,t,n,r){let i=yR(e,n,r),a=yR(t,n,r);return!i||!a?null:xR([a[0]-i[0],a[1]-i[1],a[2]-i[2]])}function wV(e,t,n,r){let i=CV(e,t,n,r);return i&&Math.hypot(...i)}function TV(e,t,n,r){let i=e.orientation?pC(e.orientation,r,e.nutPrec).toArray():[0,0,0,1],{latitude:a,longitude:o,distance:s}=iC([n[0],n[1],n[2]],[t[0],t[1],t[2]],i);return s>0?{lon:o,lat:a}:null}function EV(e,t,n){let r=t.getBody(e),i=t.getBody(d_);if(!r||!i||r===i||!r.orientation&&!t.bodies.orientationRead.has(e))return null;let a=_R(r,t,n);return a&&TV(r,a,i.position,n)}var DV=class{enabled;apply;constructor(e,t){this.enabled=e,this.apply=t}enable(){this.set(!0)}disable(){this.set(!1)}isEnabled(){return this.enabled}set(e){this.enabled!==e&&(this.enabled=e,this.apply?.(e))}};function OV(e,t){return e??t??!0}var kV=1400,AV=class{enabled;element=document.createElement(`div`);timer;constructor(e,t){this.enabled=t,this.element.className=`sm-cooperative-hint`,this.element.setAttribute(`aria-hidden`,`true`),e.append(this.element)}isEnabled(){return this.enabled}setEnabled(e){this.enabled=e,e||this.hide()}allowsWheel(e){if(!this.enabled||e.ctrlKey||e.metaKey)return!0;let{cooperative_wheel:t,cooperative_wheel_mac:n}=i().messages;return this.show(jV()?n():t()),!1}allowsTouchDrag(e){return!this.enabled||e>1?!0:(this.show(i().messages.cooperative_touch()),!1)}dispose(){clearTimeout(this.timer),this.element.remove()}show(e){this.element.textContent=e,this.element.classList.add(`sm-cooperative-hint--shown`),clearTimeout(this.timer),this.timer=setTimeout(()=>this.hide(),kV)}hide(){clearTimeout(this.timer),this.element.classList.remove(`sm-cooperative-hint--shown`)}};function jV(){return/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent)}var MV={[G.BARYCENTER]:`barycenter`,[G.LAGRANGE_POINT]:`lagrange-point`,[G.STAR]:`star`,[G.PLANET]:`planet`,[G.DWARF_PLANET]:`dwarf-planet`,[G.MOON]:`moon`,[G.ASTEROID]:`asteroid`,[G.ASTEROID_INNER]:`asteroid`,[G.ASTEROID_MAIN_BELT]:`asteroid`,[G.ASTEROID_TROJAN]:`asteroid`,[G.ASTEROID_CENTAUR]:`asteroid`,[G.ASTEROID_TNO]:`asteroid`,[G.COMET]:`comet`,[G.SPACECRAFT]:`spacecraft`,[G.DEBRIS]:`debris`,[G.UNDOCUMENTED]:`unknown`,[G.SURFACE_FEATURE]:`surface-feature`},NV={[G.ASTEROID_INNER]:`inner`,[G.ASTEROID_MAIN_BELT]:`main-belt`,[G.ASTEROID_TROJAN]:`trojan`,[G.ASTEROID_CENTAUR]:`centaur`,[G.ASTEROID_TNO]:`tno`};function PV(e){let{id:t,name:n,objectType:r,parentId:i,radiusKm:a,unplaceable:o}=e.data,s={id:t,name:n,type:MV[r],parentId:i,radiusKm:Number.isFinite(a)&&a>0?a:null,placed:o!==!0&&e.positionUnknown!==!0},c=NV[r];return c&&(s.orbitClass=c),s}var FV=[`top-left`,`top-right`,`bottom-left`,`bottom-right`],IV=class{corners=new Map;added=new Map;constructor(e,t){this.map=e,this.root=t}add(e,t){if(this.added.has(e))return;let n=e.onAdd(this.map);this.added.set(e,n),this.corner(t??e.getDefaultPosition?.()??`top-right`).append(n)}remove(e){let t=this.added.get(e);t&&(this.added.delete(e),e.onRemove?.(this.map),t.remove())}clear(){for(let e of[...this.added.keys()])this.remove(e);for(let e of this.corners.values())e.remove();this.corners.clear()}corner(e){let t=this.corners.get(e);return t||(t=document.createElement(`div`),t.className=`sm-ctrl sm-ctrl--${e}`,this.corners.set(e,t),this.root.append(...FV.map(e=>this.corners.get(e)).filter(e=>e!==void 0)),t)}},LV=[(e,t)=>e.setReducedMotion(t.resolvedReducedMotion),(e,t)=>e.setImmersive(t.viewMode===`immersive`),(e,t)=>e.setHaloDebugVisible(t.showHaloDebug),(e,t)=>{t.atmosphereCalibration,e.applyRenderTier()}],RV=.05,zV=1.15,BV=2e3,VV=4e3,HV=new WeakMap,UV=new WeakMap,WV=class{ctx=new CS;clock;initialView;#e=Ge(null);get renderer(){return Vt(this.#e)}set renderer(e){Ke(this.#e,e)}#t=Ge(!1);get webglError(){return Vt(this.#t)}set webglError(e){Ke(this.#t,e,!0)}#n=Ge(!1);get contextLost(){return Vt(this.#n)}set contextLost(e){Ke(this.#n,e,!0)}#r=Ge();get focusedBody(){return Vt(this.#r)}set focusedBody(e){Ke(this.#r,e)}attribution=null;objects=new SV(()=>this.requireRenderer().extensions,()=>this.requireCanvas());dragRotate;scrollZoom;keyboard;bodySelect;featureSelect;cooperativeGestures;container=null;canvas=null;labelLayer=null;stopWatching=null;controls=null;lostPanelTimer;cooperative=null;limits={};initialFocusPending=!0;pendingFocusId=null;retireCameraHold=null;listeners={focuschange:new Set,camera:new Set,featureselect:new Set,userpromoted:new Set,contextlost:new Set,contextrestored:new Set,clock:new Set,loading:new Set,progress:new Set,error:new Set,datastale:new Set,notice:new Set,noticedismiss:new Set,layerschange:new Set,frame:new Set};constructor(e={}){e.settings&&Mx(e.settings),this.clock=new TS(Mg(e.date??new Date),e.live??e.date===void 0);let t=e.view??{};this.initialView={id:t.body??lC,latitude:t.lat??45,longitude:t.lon??0,zoom:t.distanceKm===void 0?15:Q(t.distanceKm)};let n=t=>new DV(OV(e.interactions?.[t],e.interactive),()=>this.applyGestures());this.dragRotate=n(`dragRotate`),this.scrollZoom=n(`scrollZoom`),this.keyboard=n(`keyboard`),this.bodySelect=n(`bodySelect`),this.featureSelect=n(`featureSelect`),this.cooperativeGestures=new DV(e.cooperativeGestures??!1,()=>this.applyGestures()),e.limits&&(this.limits={...e.limits}),this.ctx.layers=new Sv(e.layers),this.ctx.layers.onChange=()=>this.onLayerChange(),this.ctx.onDataStale=()=>this.emit(`datastale`),Tz()}on(e,t){return this.listeners[e].add(t),()=>this.listeners[e].delete(t)}once(e,t){let n=(...e)=>{r(),t(...e)};UV.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners[e];n.delete(t);for(let e of n)UV.get(e)===t&&n.delete(e)}emit(e,...t){for(let n of this.listeners[e])n(...t)}getBody(e){let t=this.ctx.getBody(e);return t&&PV(t)}getFocusedBody(){let e=this.focusedBody;if(!e)return;let t=cn(e)?this.ctx.getBody(e.featureAnchor.hostId):e;return t&&PV(t)}getChildren(e){return[...this.ctx.bodies.getChildren(e)??[]]}get placedJd(){let e=this.renderer?.placedJd;return e===void 0||Number.isNaN(e)?this.clock.jd:e}distanceKm(e,t){return wV(e,t,this.ctx,this.placedJd)}offsetKm(e,t){return CV(e,t,this.ctx,this.placedJd)}getSubsolarPoint(e){return EV(e,this.ctx,this.placedJd)}load(e=this.initialView.id){return this.ctx.load(Ng(this.clock.jd),e)}async open(e=this.initialView.id){let t=this.load(e);t.catch(()=>{});let n=!0,r=new Promise(t=>{let r=()=>{n&&(this.renderer&&this.ctx.getBody(e)?t():document.hidden?setTimeout(r,100):requestAnimationFrame(r))};r()});try{await Promise.race([t,r])}finally{n=!1}}applyInitialView(){let{id:e,latitude:t,longitude:n,zoom:r}=this.initialView;this.focusedBody||!this.ctx.getBody(e)||this.renderer?.snapToBody(e,t,n,r)}mount(e){if(this.container)throw Error(`SpaceMap is already mounted`);this.container=e,e.classList.add(`sm-map`),HV.set(e,(HV.get(e)??0)+1),this.controls=new IV(this,e);let t=document.createElement(`canvas`);t.className=`sm-map__canvas`,t.tabIndex=0,t.setAttribute(`role`,`application`),t.setAttribute(`aria-label`,i().messages.scene_canvas_label());let n=document.createElement(`div`);n.className=`scene-overlay`,e.append(t,n),this.canvas=t,this.labelLayer=n,this.cooperative=new AV(e,this.cooperativeGestures.isEnabled()),t.addEventListener(`keydown`,this.onKeyDown),t.addEventListener(`touchmove`,this.onTouchMove,{passive:!0}),e.addEventListener(`wheel`,this.onWheelCapture,{capture:!0,passive:!0}),t.addEventListener(`webglcontextlost`,this.onContextLost,!1),t.addEventListener(`webglcontextrestored`,this.onContextRestored,!1),document.addEventListener(`visibilitychange`,this.onVisibility);let r;try{r=new JR(t,n,this.ctx,this.clock,this.initialView,this.callbacks())}catch(e){console.error(`[scene] renderer init failed:`,e),this.webglError=!0;return}this.renderer=r,this.applyGestures(),this.applyLimits(),this.pendingFocusId!==null&&(r.focusOnBody(this.pendingFocusId),this.pendingFocusId=null);let a=new ResizeObserver(()=>r.resize(t.clientWidth,t.clientHeight));a.observe(t);let o=st(()=>this.watch(r));this.stopWatching=()=>{a.disconnect(),o()}}addControl(e,t){if(!this.controls)throw Error(`spacemap: the map is not mounted`);return this.controls.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.unmount()}unmount(){let{container:e,canvas:t}=this;if(!e||!t)return;this.controls?.clear(),this.controls=null,this.stopWatching?.(),this.stopWatching=null,clearTimeout(this.lostPanelTimer),t.removeEventListener(`keydown`,this.onKeyDown),t.removeEventListener(`touchmove`,this.onTouchMove),e.removeEventListener(`wheel`,this.onWheelCapture,{capture:!0}),this.cooperative?.dispose(),this.cooperative=null,t.removeEventListener(`webglcontextlost`,this.onContextLost),t.removeEventListener(`webglcontextrestored`,this.onContextRestored),document.removeEventListener(`visibilitychange`,this.onVisibility),this.retireCameraHold?.(),this.retireCameraHold=null,this.renderer?.dispose(),this.renderer=null,t.remove(),this.labelLayer?.remove();let n=(HV.get(e)??1)-1;HV.set(e,n),n===0&&e.classList.remove(`sm-map`),this.container=this.canvas=this.labelLayer=null}watch(e){at(()=>{this.ctx.bodies.minorBodyVersion,e.rebuildMinorPointClouds()});let t=jx();for(let n of LV)at(()=>n(e,t));let n=this.clock;at(()=>{let{jd:e,playing:t,timeScale:r,direction:i,live:a}=n;this.listeners.clock.size!==0&&this.emit(`clock`,{jd:e,date:Ng(e),playing:t,timeScale:r,direction:i,live:a})}),at(()=>{let e=this.ctx.loading,t=XR.bootPending;this.emit(`loading`,e||t)}),at(()=>this.emit(`progress`,H_.value)),at(()=>{let e=this.ctx.error;e!==null&&this.emit(`error`,e)}),at(()=>{XR.progress===null?e.isContextLost()||e.resume():e.pause()})}applySettings(){let e=this.renderer;if(!e)return;let t=jx();for(let n of LV)n(e,t)}callbacks(){return{notices:{notify:e=>this.emit(`notice`,e),dismiss:e=>this.emit(`noticedismiss`,e)},onFocusChange:e=>{let t=this.initialFocusPending;this.initialFocusPending=!1,this.focusedBody=e;let n=e!==void 0&&cn(e);this.emit(`focuschange`,{body:this.getFocusedBody(),initial:t,feature:n})},onFrame:(e,t)=>{this.listeners.frame.size>0&&this.emit(`frame`,{jd:e,dtMs:t})},onCameraPosition:(e,t,n)=>{let r=this.focusedBody?.data.id;r!==void 0&&this.emit(`camera`,{body:r,lat:e,lon:t,distanceKm:sg(n)})},onUserPromotedChange:e=>this.emit(`userpromoted`,e),onFeatureSelect:(e,t,n,r,i)=>this.emit(`featureselect`,{bodyId:e,featureId:t,lat:n,lon:r,diameterM:i})}}onKeyDown=e=>{if(!this.keyboard.isEnabled()||e.ctrlKey||e.metaKey||e.altKey)return;let t=(e.shiftKey?4:1)*RV,n=0,r=0,i=1;switch(e.key){case`ArrowLeft`:n=t;break;case`ArrowRight`:n=-t;break;case`ArrowUp`:r=t;break;case`ArrowDown`:r=-t;break;case`+`:case`=`:i=zV;break;case`-`:case`_`:i=1/zV;break;default:return}e.preventDefault(),this.renderer?.nudgeCamera(n,r,i)};onContextLost=e=>{e.preventDefault(),console.warn(`[scene] WebGL context lost`),this.renderer?.pause(),clearTimeout(this.lostPanelTimer),this.lostPanelTimer=setTimeout(()=>{this.contextLost=!0,this.emit(`contextlost`)},BV)};onContextRestored=()=>{console.warn(`[scene] WebGL context restored`),clearTimeout(this.lostPanelTimer),this.contextLost=!1,this.renderer?.handleContextRestored(),this.renderer?.recoverWorkersIfDead(VV),this.emit(`contextrestored`)};onVisibility=()=>{document.visibilityState===`visible`&&(this.renderer?.isContextLost()||this.renderer?.recoverWorkersIfDead())};flyTo(e){let t=this.targetBody(e);return e.feature?this.toFeature(t,e.feature,`frame`):this.settled(this.focusOnBody(t,this.framing(e,t),e.lat,e.lon))}panTo(e){return this.toFeature(this.targetBody(e),e.feature,`pan`)}jumpTo(e){let t=this.targetBody(e);if(e.facing!==void 0)return this.snapToBodyFacing(t,e.facing,e.elevationDeg??0,this.framing(e,t)),this;if(e.feature){let{featureId:n,lat:r,lon:i,diameterM:a}=e.feature;return this.focusOnFeature(t,n,r,i,a,null,`snap`),this}let n=this.getCamera();return this.snapToBody(t,e.lat??n?.lat??45,e.lon??n?.lon??0,this.framing(e,t)),this}getCamera(){let e=this.renderer,t=this.focusedBody?.data.id;if(!e||t===void 0)return null;let{latitude:n,longitude:r,distance:i}=e.getCameraState();return{body:t,lat:n,lon:r,distanceKm:sg(i)}}setLayerVisible(e,t){return this.ctx.layers.setVisible(e,t),this}isLayerVisible(e){return this.ctx.layers.isVisible(e)}getLayers(){return[...hv]}onLayerChange(){for(let e of this.ctx.bodies.spacecraftByParent.keys())this.ctx.bodies.dirtySpacecraftGroups.add(e);this.ctx.bodies.minorBodyVersion++,this.emit(`layerschange`,hv.filter(e=>this.ctx.layers.isVisible(e)))}setLimits(e){return this.limits={...e},this.applyLimits(),this}getLimits(){return{...this.limits}}applyLimits(){let e=this.limits,t={};e.minDistanceKm!==void 0&&(t.minDistance=Q(e.minDistanceKm)),e.maxDistanceKm!==void 0&&(t.maxDistance=Q(e.maxDistanceKm)),e.minLat!==void 0&&(t.minLat=e.minLat),e.maxLat!==void 0&&(t.maxLat=e.maxLat),e.minLon!==void 0&&(t.minLon=e.minLon),e.maxLon!==void 0&&(t.maxLon=e.maxLon);let n=Object.keys(t).length>0;this.renderer?.setCameraLimits(n?t:null,e.bodies??null)}applyGestures(){let e=this.cooperativeGestures.isEnabled();this.cooperative?.setEnabled(e);let t=this.renderer;t&&(t.setDragEnabled(this.dragRotate.isEnabled()),t.setZoomEnabled(this.scrollZoom.isEnabled()),t.setBodySelectEnabled(this.bodySelect.isEnabled()),t.setFeatureSelectEnabled(this.featureSelect.isEnabled()),t.setCooperativeTouch(e))}onWheelCapture=e=>{this.scrollZoom.isEnabled()&&this.cooperative&&!this.cooperative.allowsWheel(e)&&e.stopPropagation()};onTouchMove=e=>{this.cooperative?.allowsTouchDrag(e.touches.length)};toFeature(e,t,n){let{featureId:r,lat:i,lon:a,diameterM:o}=t;return this.settled(this.focusOnFeature(e,r,i,a,o,null,n))}settled(e){return new Promise(t=>{setTimeout(()=>requestAnimationFrame(()=>t()),e)})}targetBody(e){let t=e.body??this.focusedBody?.data.id;if(t===void 0)throw Error(`spacemap: no body to move to, and none focused`);return t}framing(e,t){if(e.distanceKm!==void 0)return Q(e.distanceKm);let n=this.ctx.getBody(t);return n&&n.data.radiusKm>0?$L(n)*5:this.renderer?.getCameraState().distance??15}focusOnBody(e,t,n,r){return this.renderer?this.renderer.focusOnBody(e,t,n,r):(this.pendingFocusId=e,0)}snapToBody(e,t,n,r){this.renderer?.snapToBody(e,t,n,r)}snapToBodyFacing(e,t,n,r){this.renderer?.snapToBodyFacing(e,t,n,r)}focusOnFeature(e,t,n,r,i,a,o=`frame`,s=null){let c=this.ctx.getBody(e);if(!c)return 0;let l=Q(i*4/1e3),u=Q(.02),d=Q(mn(c.data)*5),f=Math.min(Math.max(l,u),d),p={hostId:e,featureId:t,lat:n,lon:r,diameterM:i};return this.renderer?.focusOnFeature(p,a,f,o,s)??0}setFocusTarget(e,t){this.renderer?.setFocusTarget(e,t)}getPose(){let e=this.renderer,t=this.focusedBody;if(!e||!t)return null;let n=t.data.id;return{position:{body:n,offsetKm:xR(e.cameraOffsetFromFocus())},target:{body:n}}}holdCamera(){let e=this.renderer;if(!e)throw Error(`SpaceMap is not mounted`);this.retireCameraHold?.(),e.holdCamera();let t=!0,n=()=>{t=!1};return this.retireCameraHold=n,{get held(){return t},set:n=>{t&&e.setHeldPose(n)},release:()=>{t&&(n(),this.retireCameraHold=null,e.releaseCamera())}}}addMarker(e){return this.track(new kz(e,this.requireCanvas()))}addPolyline(e){return this.track(new Hz(e))}addPolygon(e){return this.track(new tB({fill:e.color??`#ffffff`,...e}))}addCircle(e){return this.track(new nB(e))}addLabel(e){return this.track(new rB(e,this.requireCanvas()))}addIcon(e){return this.track(new iB(e,this.requireCanvas()))}addSurfacePolyline(e){return this.track(new yV(e))}addSurfacePolygon(e){return this.track(new yV({fill:e.color??`#ffffff`,...e,closed:!0}))}addSurfaceCircle(e){return this.addSurfacePolygon({...e,points:fV(e.center,this.capRadiusDeg(e),e.steps)})}clearDrawings(){this.renderer?.extensions.clear(e=>e instanceof bV)}setBodyAppearance(e,t){return this.requireRenderer().setBodyAppearance(e,t),this}setPinnedBodies(e){return this.requireRenderer().setPinnedBodies(e),this}capRadiusDeg(e){if(e.radiusDeg!==void 0)return e.radiusDeg;let t=this.getBody(e.body)?.radiusKm;return e.radiusKm!==void 0&&t?e.radiusKm/t*(180/Math.PI):1}track(e){let t=this.requireRenderer();return e.bind(()=>t.extensions.remove(e)),t.extensions.add(e),e}requireCanvas(){let e=this.canvas;if(!e)throw Error(`SpaceMap is not mounted`);return e}requireRenderer(){let e=this.renderer;if(!e)throw Error(`SpaceMap is not mounted`);return e}setNorthReference(e){this.renderer?.setNorthReference(e)}setUserLocation(e,t){this.renderer?.setUserLocation(e,t)}clearUserPromoted(){this.renderer?.clearUserPromoted()}setSelectedFeature(e){this.renderer?.setSelectedFeature(e)}setTravelPath(e,t=[],n=[],r=[]){this.renderer?.setTravelPath(e,t,n,r)}setOrbitPreview(e,t){this.renderer?.setOrbitPreview(e,t)}setTravelHover(e){this.renderer?.setTravelHover(e)}focusOnPathPoint(e,t){this.renderer?.focusOnPathPoint(e,t)}trackPathPoint(e,t){this.renderer?.trackPathPoint(e,t)}setCovered(e){this.renderer?.setCovered(e)}},GV=`http://www.w3.org/2000/svg`;function KV(e){return{id:e.id,label:e.label,kind:e.kind,visible:e.visible,credit:e.credit}}function qV(e){return{organisation:e.organisation,source:e.source,attribution:e.attribution}}function JV(e,t){let n=document.createElementNS(GV,`path`);return n.setAttribute(`d`,e),n.setAttribute(`class`,t),n}function YV(e,t=30){return{kind:`vector`,id:`graticule`,label:e,visible:!1,render(e,n){for(let r of mV(t)){let t=sV(r,e,{stepDeg:2});t&&n.append(JV(t,`sm-flat__graticule`))}if(e.projection.azimuthal){let t=e.toScreen(0,0),r=e.toScreen(e.projection.extent.maxX,0),i=document.createElementNS(GV,`circle`);i.setAttribute(`cx`,String(t[0])),i.setAttribute(`cy`,String(t[1])),i.setAttribute(`r`,String(Math.abs(r[0]-t[0]))),i.setAttribute(`class`,`sm-flat__frame`),n.append(i)}else{let t=uV(e);t&&n.append(JV(t,`sm-flat__frame`))}}}}var XV=120;function ZV(e,t){let n=[];return{kind:`vector`,id:`nomenclature`,label:t,visible:!1,credit:{organisation:`IAU`,source:`https://planetarynames.wr.usgs.gov/`},async prepare(){n.length||(n=[...await bM(e)].sort((e,t)=>t.diameterM-e.diameterM).slice(0,XV))},render(e,t){let r=e.repeatShifts;for(let i of n){let n=e.project(i.lon,i.lat);if(!(!n||n[1]<0||n[1]>e.height))for(let a of r){let r=n[0]+a;if(r<0||r>e.width)continue;let o=document.createElementNS(GV,`circle`);o.setAttribute(`cx`,r.toFixed(1)),o.setAttribute(`cy`,n[1].toFixed(1)),o.setAttribute(`r`,`1.6`),o.setAttribute(`class`,`sm-flat__feature-dot`);let s=document.createElementNS(GV,`text`);s.setAttribute(`x`,(r+4).toFixed(1)),s.setAttribute(`y`,(n[1]+3).toFixed(1)),s.setAttribute(`class`,`sm-flat__feature-label`),s.textContent=i.name,t.append(o,s)}}}}}function QV(e,t){e.setAttribute(`fill`,t.fill??`none`),t.fill&&t.fillOpacity!==void 0&&e.setAttribute(`fill-opacity`,String(t.fillOpacity)),e.setAttribute(`stroke`,t.color??`#ffffff`),e.setAttribute(`stroke-width`,String(t.widthPx??2)),e.setAttribute(`stroke-linejoin`,`round`),e.setAttribute(`stroke-linecap`,`round`),t.opacity!==void 0&&e.setAttribute(`opacity`,String(t.opacity)),t.dash&&e.setAttribute(`stroke-dasharray`,t.dash),t.className&&e.setAttribute(`class`,t.className),e.style.pointerEvents=t.interactive?`auto`:`none`,t.ariaLabel&&(e.setAttribute(`role`,`img`),e.setAttribute(`aria-label`,t.ariaLabel))}function $V(e,t){t.onclick&&e.addEventListener(`click`,t.onclick),t.onpointerenter&&e.addEventListener(`pointerenter`,t.onpointerenter),t.onpointerleave&&e.addEventListener(`pointerleave`,t.onpointerleave)}var eH=class{node;area;edge;points;visible=!0;constructor(e,t,n,r,i,a){this.closed=n,this.interpolate=r,this.onRemove=i,this.onChange=a,this.points=e,this.node=document.createElementNS(GV,`g`),QV(this.node,t),$V(this.node,t),this.area=n?document.createElementNS(GV,`path`):null,this.area?.setAttribute(`stroke`,`none`),this.edge=document.createElementNS(GV,`path`),this.edge.setAttribute(`fill`,`none`),this.area&&this.node.append(this.area),this.node.append(this.edge)}redraw(e){if(!this.visible)return;let t={closed:this.closed,interpolate:this.interpolate};this.edge.setAttribute(`d`,sV(this.points,e,t)),this.area?.setAttribute(`d`,cV(this.points,e,t))}setPoints(e){this.points=e,this.onChange()}setVisible(e){this.visible=e,this.node.style.display=e?``:`none`,this.onChange()}detach(){this.node.remove()}remove(){this.onRemove(this)}},tH=class{element;at;visible=!0;align;constructor(e,t,n){this.onRemove=t,this.onChange=n,this.at=e.at,this.align=e.align??[.5,.5],this.element=e.element??document.createElement(`div`),e.element||(this.element.className=`sm-flat__marker-dot`),e.className&&this.element.classList.add(e.className),this.element.style.position=`absolute`,this.element.style.left=`0`,this.element.style.top=`0`,this.element.style.pointerEvents=e.interactive?`auto`:`none`}redraw(e){let t=this.visible?e.project(this.at.lon,this.at.lat):null;if(this.element.style.display=t?``:`none`,!t)return;let n=e.repeatShifts.find(n=>t[0]+n>=0&&t[0]+n<=e.width)??0;this.element.style.transform=`translate(${t[0]+n}px, ${t[1]}px) translate(${-this.align[0]*100}%, ${-this.align[1]*100}%)`}setPosition(e){this.at=e,this.onChange()}setVisible(e){this.visible=e,this.onChange()}detach(){this.element.remove()}remove(){this.onRemove(this)}},nH=class{drawings=new Set;constructor(e,t,n=()=>{},r=null){this.shapes=e,this.markers=t,this.onChange=n,this.radiusKm=r}setBodyRadiusKm(e){this.radiusKm=e}track(e,t){return this.drawings.add(e),t instanceof HTMLElement?this.markers.append(t):this.shapes.append(t),e}drop=e=>{this.drawings.delete(e)&&e.detach()};addPolyline(e){let t=new eH(e.points,e,e.closed??!1,e.interpolate??`linear`,this.drop,this.onChange);return this.track(t,t.node)}addPolygon(e){let t=new eH(e.points,{fill:`rgb(255 255 255 / 25%)`,...e},!0,e.interpolate??`linear`,this.drop,this.onChange);return this.track(t,t.node)}addBox(e){let t=new eH(dV(e.latMin,e.latMax,e.lonMin,e.lonSpan),{fill:`rgb(255 255 255 / 15%)`,...e},!0,`linear`,this.drop,this.onChange);return this.track(t,t.node)}addCircle(e){let t=this.circleRadiusDeg(e),n=new eH(fV(e.center,t),{fill:`rgb(255 255 255 / 20%)`,...e},!0,`linear`,this.drop,this.onChange);return this.track(n,n.node)}circleRadiusDeg(e){return e.radiusDeg===void 0?e.radiusKm!==void 0&&this.radiusKm?e.radiusKm/this.radiusKm*(180/Math.PI):1:e.radiusDeg}addMarker(e){let t=new tH(e,this.drop,this.onChange);return this.track(t,t.element)}redraw(e){for(let t of this.drawings)t.redraw(e)}clear(){for(let e of this.drawings)e.detach();this.drawings.clear()}};function rH(e){let t=`width`in e?e.width:e.codedWidth,n=`height`in e?e.height:e.codedHeight;return typeof t!=`number`||typeof n!=`number`||!t||!n?null:[t,n]}function iH(e,t){let[n,r]=rH(e)??[t,t/2],i=Math.max(2,Math.min(n,Math.round(t))),a=Math.max(1,Math.round(i*r/n)),o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`,{willReadFrequently:!0});if(!s)return null;s.imageSmoothingEnabled=!0,s.imageSmoothingQuality=`high`,s.drawImage(e,0,0,i,a);try{let{data:e}=s.getImageData(0,0,i,a);return{width:i,height:a,data:e}}catch{return null}}var aH=class{width;height;u;v;inside;constructor(e,t,n){this.width=t,this.height=n;let r=t*n;this.u=new Float32Array(r),this.v=new Float32Array(r),this.inside=new Uint8Array(r);let{projection:i}=e,a=1/e.scale,o=e.view.centerX-e.width/2*a,s=e.view.centerY+e.height/2*a;for(let r=0;r<n;r++){let n=s-(r+.5)*a,c=r*t;i.rowInverse?this.fillRow(i,c,n,o,a,e):this.walkRow(i,c,n,o,a)}}fillRow(e,t,n,r,i,a){let o=e.rowInverse(n);if(!o)return;let{width:s}=this,c=(90-o.lat)/180,{minX:l,maxX:u}=e.extent,d=u-l,f=a.repeatsHorizontally;for(let n=0;n<s;n++){let a=r+(n+.5)*i;if(f)a=((a-l)%d+d)%d+l;else if(a<l||a>u)continue;if(a<-o.maxAbsX||a>o.maxAbsX)continue;let s=(a*o.lonPerX+e.centerLon+180)/360,p=t+n;this.u[p]=s-Math.floor(s),this.v[p]=c,this.inside[p]=1}}walkRow(e,t,n,r,i){let{width:a}=this,o=0,s=a-1;if(e.azimuthal){let t=e.extent.maxX;if(Math.abs(n)>t)return;let c=Math.sqrt(t*t-n*n);o=Math.max(0,Math.ceil((-c-r)/i-.5)),s=Math.min(a-1,Math.floor((c-r)/i-.5))}for(let a=o;a<=s;a++){let o=r+(a+.5)*i,s=e.inverse(o,n);if(!s)continue;let c=t+a;this.u[c]=(s[0]+180)/360,this.v[c]=(90-s[1])/180,this.inside[c]=1}}};function oH(e,t,n){let r=n.data;r.fill(0);let{width:i,height:a,u:o,v:s,inside:c}=e,l=i*a;for(let e of t){let{image:t,opacity:n,blend:i}=e;if(n<=0)continue;let a=t.data,u=t.width,d=t.height,f=i===`add`;for(let e=0;e<l;e++){if(!c[e])continue;let t=Math.floor(o[e]*u),i=Math.floor(s[e]*d);t=t<0?t+u:t>=u?t-u:t,i=i<0?0:i>=d?d-1:i;let l=(i*u+t)*4,p=a[l+3]/255*n;if(p<=0)continue;let m=e*4;if(f){r[m]=Math.min(255,r[m]+a[l]*p),r[m+1]=Math.min(255,r[m+1]+a[l+1]*p),r[m+2]=Math.min(255,r[m+2]+a[l+2]*p);continue}let h=r[m+3]/255,g=p+h*(1-p);if(!(g<=0)){if(p>=1)r[m]=a[l],r[m+1]=a[l+1],r[m+2]=a[l+2];else{let e=h*(1-p);r[m]=(a[l]*p+r[m]*e)/g,r[m+1]=(a[l+1]*p+r[m+1]*e)/g,r[m+2]=(a[l+2]*p+r[m+2]*e)/g}r[m+3]=g*255}}}}function sH(e,t,n){let{minX:r,maxX:i,minY:a,maxY:o}=t.projection.extent,s=t.projection.centerLon*Math.PI/180,[c,l]=t.toScreen(r-s,o),[u,d]=t.toScreen(i-s,a),f=t.repeatsHorizontally?0:t.toScreen(r,o)[0],p=t.repeatsHorizontally?e.canvas.width:t.toScreen(i,o)[0];e.save(),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`;for(let t of n){if(t.opacity<=0)continue;let n=rH(t.image),r=n&&e.createPattern(t.image,`repeat-x`);r&&(r.setTransform(new DOMMatrix().translateSelf(c,l).scaleSelf((u-c)/n[0],(d-l)/n[1])),e.globalAlpha=t.opacity,e.globalCompositeOperation=t.blend===`add`?`lighter`:`source-over`,e.fillStyle=r,e.fillRect(f,l,p-f,d-l))}e.restore()}var cH=[`low`,`medium`,`high`];function lH(e){let t=/^naif-(\d)\d\d$/.exec(e);return t?`naif-${t[1]}`:null}async function uH(e){try{let t=await fetch(e);return t.ok?await t.json():null}catch{return null}}async function dH(e){let t=await Promise.all(cH.map(t=>fetch(qt(`/v1/textures/${e}/${t}.webp`,`textures`),{method:`HEAD`}).then(e=>e.ok).catch(()=>!1)));return cH.filter((e,n)=>t[n])}async function fH(e,t,n=dH){if(!t?.map_texture_available||!t.texture)return{};let r=o([{...t.texture,id:e,tiers:void 0},...t.alternates??[]]);if(!r)return{};let i=r.tiers??await n(r.id);if(i.length===0)return{};let{frames:a,...s}=r,c=t.radii;return{surface:{...s,tiers:i,monthlyFrames:a},radiusKm:c?(c.a+c.b+c.c)/3:void 0}}async function pH(e){return fH(e,(await mx(e,!1).catch(()=>null))?.global)}async function mH(e){let t=lH(e);if(!t)return pH(e);let n=(await uH(`${Wt()}/v1/systems/${t}.json`))?.[e];if(!n?.texture||!n.tiers?.length)return pH(e);let r=o([{...n.texture,id:e,tiers:n.tiers},...n.alternates??[]]);if(!r)return pH(e);let{frames:i,...a}=r,s=n.radii;return{surface:{...a,monthlyFrames:i},clouds:n.clouds,night:n.night,radiusKm:s?(s.a+s.b+s.c)/3:void 0}}var hH={low:2048,medium:8192,high:16383};function gH(e){return cH.find(t=>hH[t]>=e)??cH[cH.length-1]}function _H(e,t){return cH.indexOf(e)<=cH.indexOf(t)?e:t}function vH(e,t){let n=cH.indexOf(t);for(let t=n<0?cH.length-1:n;t>=0;t--)if(e.includes(cH[t]))return cH[t];return e[0]??`low`}function yH(e,t,n){let r=e.id;if(e.frames?.length){let i=jj(n,e.frames,e.coverage);if(i)return qt(`/v1/textures/${r}/${t}_${i}.webp`,`textures`)}let i=rM(n,e.monthlyFrames);return qt(i===void 0?`/v1/textures/${r}/${t}.webp`:`/v1/textures/${r}/${t}_${String(i).padStart(2,`0`)}.webp`,`textures`)}function bH(e,t){return e*t*4}function xH(){let e=navigator.deviceMemory??4;return Math.max(1,Math.min(e,8))*24*1024*1024}var SH=class{entries=new Map;clock=0;constructor(e){this.free=e}claim(e){let t=this.entries.get(e);return t?(t.claims++,t.used=++this.clock,t.value):null}put(e,t,n){let r=this.entries.get(e);return r?(r.value!==t&&this.free(t),r.claims++,r.used=++this.clock,r.value):(this.entries.set(e,{value:t,bytes:n,claims:1,used:++this.clock}),this.evict(),t)}release(e){let t=this.entries.get(e);t&&(t.claims=Math.max(0,t.claims-1),this.evict())}evict(){let e=0;for(let t of this.entries.values())t.claims||(e+=t.bytes);let t=xH();if(e<=t)return;let n=[...this.entries].filter(([,e])=>!e.claims).sort((e,t)=>e[1].used-t[1].used);for(let[r,i]of n){if(e<=t)return;this.entries.delete(r),this.free(i.value),e-=i.bytes}}clear(){for(let e of this.entries.values())this.free(e.value);this.entries.clear()}},CH=new SH(e=>e.close()),wH=new SH(()=>{}),TH=new Map;function EH(e,t){return t?`${e}@${t}`:e}async function DH(e,t){let n=EH(e,t),r=CH.claim(n);if(r)return{key:n,bitmap:r};let i=TH.get(n);i||(i=OH(e,t),TH.set(n,i),i.finally(()=>TH.delete(n)));let a=await i;return a?{key:n,bitmap:CH.put(n,a,bH(a.width,a.height))}:null}async function OH(e,t){let n=await fetch(e);if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.blob();if(!t)return createImageBitmap(r);try{return await createImageBitmap(r,{resizeWidth:t,resizeQuality:`high`})}catch{return createImageBitmap(r)}}function kH(e){CH.release(e)}function AH(e,t,n){let r=EH(e,t),i=wH.claim(r);if(i)return{key:r,raster:i};let a=iH(n,t);return a?{key:r,raster:wH.put(r,a,bH(a.width,a.height))}:null}function jH(e){wH.release(e)}function MH(e,t,n){return[cC(e,n.minLon,n.maxLon),Math.min(Math.max(t,n.minLat??-90),n.maxLat??90)]}var NH=class{projection;width;height;view;scale;constructor(e,t,n,r){this.projection=e,this.width=t,this.height=n,this.view=r;let{minX:i,maxX:a,minY:o,maxY:s}=e.extent,c=Math.min(t/(a-i),n/(s-o));this.scale=c*r.zoom}toScreen(e,t){return[this.width/2+(e-this.view.centerX)*this.scale,this.height/2-(t-this.view.centerY)*this.scale]}fromScreen(e,t){return[this.view.centerX+(e-this.width/2)/this.scale,this.view.centerY-(t-this.height/2)/this.scale]}project(e,t){let n=this.projection.forward(e,t);return n?this.toScreen(n[0],n[1]):null}unproject(e,t){let[n,r]=this.fromScreen(e,t);return this.projection.inverse(n,r)}get worldWidthPx(){let{minX:e,maxX:t}=this.projection.extent;return(t-e)*this.scale}get repeatsHorizontally(){return PH(this.projection,this.worldWidthPx,this.width)}get repeatShifts(){if(!this.repeatsHorizontally)return[0];let e=this.worldWidthPx,t=this.toScreen(this.projection.extent.minX,0)[0];return[0,-e,e].filter(n=>t+n<this.width&&t+n+e>0)}};function PH(e,t,n){return e.cyclic&&e.rectangular&&t>=n-.5}function FH(e,t,n,r,i){let a=Math.min(Math.max(e.zoom,1,i.minZoom??1),i.maxZoom??1/0),o=IH(e,t,i),s=t.extent,c=s.maxX-s.minX,l=s.maxY-s.minY,u=Math.min(n/c,r/l)*a,d=n/2/u,f=r/2/u,p=(s.minX+s.maxX)/2,m=(s.minY+s.maxY)/2,h=(e,t,n,r)=>n>=r/2?t:Math.min(t+r/2-n,Math.max(t-r/2+n,e));return{zoom:a,centerX:PH(t,c*u,n)?((o.centerX-s.minX)%c+c)%c+s.minX:h(o.centerX,p,d,c),centerY:h(o.centerY,m,f,l)}}function IH(e,t,n){if(!(n.minLon!==void 0||n.maxLon!==void 0||n.minLat!==void 0||n.maxLat!==void 0)||t.azimuthal)return e;let r=t.inverse(e.centerX,e.centerY);if(!r)return e;let[i,a]=MH(r[0],r[1],n);if(i===r[0]&&a===r[1])return e;let o=t.forward(i,a);return o?{centerX:o[0],centerY:o[1]}:e}var LH=[[6,`high`],[2.5,`medium`]],RH=22e5,zH=4096,BH=11,VH=.4,HH=.8,UH=140,WH=`naif-399`,GH=[{kind:`surface`,label:e=>e.layer_surface(),visible:!0,opacity:1,blend:`normal`},{kind:`clouds`,label:e=>e.layer_clouds(),visible:!0,opacity:1,blend:`normal`},{kind:`night`,label:e=>e.layer_night(),visible:!1,opacity:.85,blend:`add`}];function KH(e){return e.kind===`raster`}var qH=new WeakMap,JH=class{container=null;root=document.createElement(`div`);canvas=document.createElement(`canvas`);svg=document.createElementNS(GV,`svg`);layerGroup=document.createElementNS(GV,`g`);shapeGroup=document.createElementNS(GV,`g`);markerLayer=document.createElement(`div`);ctx;overlay;bodyId;sources={};layerList=[];projection;projectionId;projectionOptions;view;limits;limitsArmed=!1;jd;cooperative=null;bodyRadiusKm=null;bitmaps=new Map;rasters=new Map;pending=new Set;missing=new Set;generation=0;controls=null;attribution=null;dragPan;scrollZoom;cooperativeGestures;lookup=null;lookupKey=``;buffer=null;frame=0;resizeObserver=null;listeners=new Map;announcedReady=!1;disposed=!1;moving=!1;sharpWidth=0;msPerPixel=0;settleTimer=0;chosenVisibility=new Map;customLayers=[];constructor(e={}){this.bodyId=e.body??WH,this.projectionId=e.projection??`equirectangular`,this.projectionOptions={centerLon:e.centerLon??0,centerLat:e.centerLat,clipAngle:e.clipAngle},this.projection=WB(this.projectionId,this.projectionOptions),this.limits={maxZoom:16,...e.limits},this.view={zoom:e.zoom??1,centerX:0,centerY:0},this.jd=e.jd??Mg(new Date),this.dragPan=new DV(OV(e.interactions?.dragPan,e.interactive),e=>this.root.classList.toggle(`sm-flat--interactive`,e)),this.scrollZoom=new DV(OV(e.interactions?.scrollZoom,e.interactive)),this.cooperativeGestures=new DV(e.cooperativeGestures??!1,e=>this.applyCooperative(e)),this.root.className=`sm-flat`,this.canvas.className=`sm-flat__raster`,this.svg.setAttribute(`class`,`sm-flat__vector`),this.markerLayer.className=`sm-flat__markers`,this.svg.append(this.layerGroup,this.shapeGroup),this.root.append(this.canvas,this.svg,this.markerLayer),this.ctx=this.canvas.getContext(`2d`),this.overlay=new nH(this.shapeGroup,this.markerLayer,()=>this.render()),this.root.classList.toggle(`sm-flat--interactive`,this.dragPan.isEnabled()),this.applyCooperative(this.cooperativeGestures.isEnabled());for(let[t,n]of Object.entries(e.layers??{}))this.chosenVisibility.set(t,n)}mount(e){this.container=e,e.append(this.root),this.controls=new IV(this,this.root),this.cooperative=new AV(this.root,this.cooperativeGestures.isEnabled()),this.resizeObserver=new ResizeObserver(()=>this.renderMoving()),this.resizeObserver.observe(this.root),this.attachInteraction()}addControl(e,t){if(!this.controls)throw Error(`spacemap: the map is not mounted`);return this.controls.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.unmount()}unmount(){this.disposed=!0,this.controls?.clear(),this.controls=null,this.cooperative?.dispose(),this.cooperative=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,cancelAnimationFrame(this.frame),clearTimeout(this.settleTimer);for(let e of this.layerList)KH(e)||e.dispose?.();this.overlay.clear(),this.dropTextures(),this.root.remove(),this.container=null}async load(){await this.adopt(this.bodyId)}async adopt(e){let t=await mH(e);if(!this.disposed){if(!t.surface){let t=Error(`spacemap: no map texture for ${e}`);throw this.emit(`error`,t),t}e!==this.bodyId&&this.release(),this.bodyId=e,this.sources=t,this.bodyRadiusKm=t.radiusKm??null,this.overlay.setBodyRadiusKm(this.bodyRadiusKm),this.buildLayers(),await this.loadVisible(),!this.disposed&&this.render()}}release(){this.generation++,this.dropTextures(),this.missing.clear();for(let e of this.layerList)!KH(e)&&!this.customLayers.includes(e)&&e.dispose?.()}buildLayers(){let{messages:e}=i(),t=[];for(let n of GH){let r=this.sources[n.kind];r&&t.push({kind:`raster`,id:n.kind,label:n.label(e),visible:n.visible,opacity:n.opacity,blend:n.blend,credit:qV(r),tiers:r.tiers,url:(e,t)=>yH(r,t,e)})}t.push(YV(e.layer_graticule())),t.push(ZV(this.bodyId,e.layer_nomenclature())),t.push(...this.customLayers);for(let e of t){let t=this.chosenVisibility.get(e.id);t!==void 0&&(e.visible=t)}this.layerList=t,this.emit(`layerschange`,this.layers)}get layers(){return this.layerList.map(KV)}getLayers(){return this.layerList.map(e=>e.id)}isLayerVisible(e){return this.layerList.find(t=>t.id===e)?.visible??!1}get credits(){let e=new Set,t=[];for(let n of this.layerList)!n.visible||!n.credit||e.has(n.credit.organisation)||(e.add(n.credit.organisation),t.push(n.credit));return t}setLayerVisible(e,t){this.chosenVisibility.set(e,t);let n=this.layerList.find(t=>t.id===e);!n||n.visible===t||(n.visible=t,this.emit(`layerschange`,this.layers),this.loadVisible(),this.render())}setLayerOpacity(e,t){let n=this.layerList.find(t=>t.id===e);!n||!KH(n)||(n.opacity=Math.min(1,Math.max(0,t)),this.render())}addRasterLayer(e){let t={kind:`raster`,id:e.id,label:e.label??e.id,visible:e.visible??!0,opacity:e.opacity??1,blend:e.blend??`normal`,credit:e.credit,tiers:[`low`],url:()=>e.url};this.customLayers.push(t),this.layerList.push(t),this.emit(`layerschange`,this.layers),this.loadVisible()}addVectorLayer(e){let t={kind:`vector`,id:e.id,label:e.label??e.id,visible:e.visible??!0,credit:e.credit,render:e.render,prepare:e.prepare};this.customLayers.push(t),this.layerList.push(t),this.emit(`layerschange`,this.layers),this.loadVisible()}get projectionName(){return this.projectionId}static get projections(){return UB}setProjection(e,t={}){this.limitsArmed=!1,this.projectionId=e,this.projectionOptions={...this.projectionOptions,...t},this.projection=WB(e,this.projectionOptions),this.view={...this.view,centerX:0,centerY:0},this.render(),this.emit(`viewchange`,this.viewState)}get viewState(){let e=this.viewport(),t=e.unproject(e.width/2,e.height/2);return{projection:this.projectionId,zoom:this.view.zoom,centerLon:t?.[0]??this.projectionOptions.centerLon??0,centerLat:t?.[1]??this.projectionOptions.centerLat??0}}setView(e){if(e.projection&&e.projection!==this.projectionId&&this.setProjection(e.projection),this.limitsArmed=!1,e.zoom!==void 0&&(this.view={...this.view,zoom:e.zoom}),e.centerLon!==void 0||e.centerLat!==void 0){let t=this.viewState,n=e.centerLon??t.centerLon,r=e.centerLat??t.centerLat;if(this.projection.azimuthal)this.projectionOptions={...this.projectionOptions,centerLon:n,centerLat:r},this.projection=WB(this.projectionId,this.projectionOptions);else{let e=this.projection.forward(n,r);e&&(this.view={...this.view,centerX:e[0],centerY:e[1]})}}this.loadVisible(),this.render(),this.emit(`viewchange`,this.viewState)}setLimits(e){return this.limits={maxZoom:16,...e},this.render(),this}getLimits(){return{...this.limits}}setTime(e){this.jd=e,this.loadVisible(),this.render()}async setBody(e){e!==this.bodyId&&(this.limitsArmed=!1,await this.adopt(e))}project(e,t){return this.viewport().project(e,t)}unproject(e,t){let n=this.viewport().unproject(e,t);return n?{lon:n[0],lat:n[1]}:null}addPolyline(e){let t=this.overlay.addPolyline(e);return this.render(),t}addPolygon(e){let t=this.overlay.addPolygon(e);return this.render(),t}addBox(e){let t=this.overlay.addBox(e);return this.render(),t}addCircle(e){let t=this.overlay.addCircle(e);return this.render(),t}addMarker(e){let t=this.overlay.addMarker(e);return this.render(),t}clearDrawings(){this.overlay.clear(),this.render()}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=((...e)=>{r(),t(...e)});qH.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners.get(e);if(n){n.delete(t);for(let e of n)qH.get(e)===t&&n.delete(e)}}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of[...n])e(...t)}tier(e){return vH(e,_H(LH.find(([e])=>this.view.zoom>=e)?.[1]??`low`,gH(this.usableSourceWidth())))}usableSourceWidth(){return this.projectionId===`equirectangular`?this.deviceWidth()*this.view.zoom:this.workingWidth()}deviceWidth(){return this.sharpWidth||Math.max(1,this.root.clientWidth)}workingWidth(){let e=this.deviceWidth()*2*this.view.zoom;return Math.min(zH,2**Math.ceil(Math.log2(Math.max(256,e))))}decodeWidth(e){return this.projectionId===`equirectangular`?null:Math.min(this.workingWidth(),hH[e]??zH)}picturesInUse(){return this.layerList.filter(e=>KH(e)&&e.visible).map(e=>{let t=this.tier(e.tiers);return{url:e.url(this.jd,t),tier:t}})}async loadVisible(){let e=this.picturesInUse(),t=this.layerList.filter(e=>!KH(e)&&e.visible&&!!e.prepare).map(e=>e.prepare().then(()=>this.render(),()=>{})),n=e.filter(({url:e,tier:t})=>this.bitmaps.get(e)?.key!==EH(e,this.decodeWidth(t))).filter(({url:e})=>!this.pending.has(e)&&!this.missing.has(e)).map(async({url:e,tier:t})=>{this.pending.add(e);let n=this.generation;try{let r=await DH(e,this.decodeWidth(t));if(!r)return;if(this.disposed||n!==this.generation){kH(r.key);return}this.hold(this.bitmaps,e,r,kH),this.render()}catch(t){if(n!==this.generation)return;this.missing.add(e),this.emit(`error`,Error(`spacemap: could not load ${e}`,{cause:t}))}finally{this.pending.delete(e)}});await Promise.all([...t,...n]),this.dropUnused(new Set(this.picturesInUse().map(({url:e})=>e)))}dropUnused(e){for(let[t,n]of this.bitmaps)e.has(t)||(kH(n.key),this.bitmaps.delete(t));for(let[t,n]of this.rasters)e.has(t)||(jH(n.key),this.rasters.delete(t))}hold(e,t,n,r){let i=e.get(t);i?.key!==n.key&&(i&&r(i.key),e.set(t,n))}rasterFor(e,t){let n=this.rasters.get(e);if(n?.key===EH(e,t))return n.raster;let r=this.bitmaps.get(e)?.bitmap;if(!r)return null;let i=AH(e,t,r);return i?(this.hold(this.rasters,e,i,jH),i.raster):null}dropTextures(){for(let e of this.bitmaps.values())kH(e.key);for(let e of this.rasters.values())jH(e.key);this.bitmaps.clear(),this.rasters.clear()}viewport(e,t){let n=e??this.root.clientWidth??1,r=t??this.root.clientHeight??1;return this.view=FH(this.view,this.projection,n,r,this.limitsArmed?this.limits:{}),new NH(this.projection,Math.max(1,n),Math.max(1,r),this.view)}render(){this.disposed||(cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(()=>this.draw()))}renderMoving(){this.moving=!0,clearTimeout(this.settleTimer),this.settleTimer=window.setTimeout(()=>{this.moving=!1,this.render()},UH),this.render()}draw(){let e=this.root.clientWidth,t=this.root.clientHeight;if(!this.ctx||e===0||t===0)return;let n=Math.min(window.devicePixelRatio||1,2),r=Math.sqrt(RH/(e*t*n*n)),i=n*Math.min(1,r),a=Math.max(1,Math.round(e*i));a!==this.sharpWidth&&(this.sharpWidth=a,this.loadVisible());let o=e*i*t*i,s=i*(this.moving?this.interactionScale(o):1),c=Math.max(1,Math.round(e*s)),l=Math.max(1,Math.round(t*s));(this.canvas.width!==c||this.canvas.height!==l)&&(this.canvas.width=c,this.canvas.height=l,this.buffer=null,this.lookup=null);let u=this.viewport(e,t),d=new NH(this.projection,c,l,this.view);this.clipToDisc(u),this.drawRaster(d,c,l),this.drawVector(u),!this.announcedReady&&this.bitmaps.size>0&&(this.announcedReady=!0,this.emit(`ready`))}record(e,t){if(t<=0)return;let n=e/t;this.msPerPixel=this.msPerPixel===0?n:this.msPerPixel*.7+n*.3}interactionScale(e){if(this.msPerPixel<=0||e<=0)return 1;let t=Math.sqrt(BH/this.msPerPixel/e);return t>HH?1:Math.max(VH,t)}clipToDisc(e){let{projection:t}=e;if(!t.azimuthal){this.canvas.style.clipPath=``;return}let[n,r]=e.toScreen(0,0),i=t.extent.maxX*e.scale;this.canvas.style.clipPath=`circle(${i}px at ${n}px ${r}px)`}drawRaster(e,t,n){let r=this.ctx;r.clearRect(0,0,t,n);let i=this.layerList.filter(e=>KH(e)&&e.visible);if(i.length===0)return;if(this.projectionId===`equirectangular`){let t=i.map(e=>({image:this.bitmaps.get(e.url(this.jd,this.tier(e.tiers)))?.bitmap,opacity:e.opacity,blend:e.blend})).filter(e=>!!e.image);t.length&&sH(r,e,t);return}let a=this.workingWidth(),o=i.map(e=>({image:this.rasterFor(e.url(this.jd,this.tier(e.tiers)),a),opacity:e.opacity,blend:e.blend})).filter(e=>!!e.image);if(o.length===0)return;(!this.buffer||this.buffer.width!==t||this.buffer.height!==n)&&(this.buffer=r.createImageData(t,n));let s=`${this.projectionId}|${JSON.stringify(this.projectionOptions)}|${this.view.zoom}|${this.view.centerX}|${this.view.centerY}|${t}x${n}`,c=!this.lookup||this.lookupKey!==s,l=performance.now();c&&(this.lookup=new aH(e,t,n),this.lookupKey=s),oH(this.lookup,o,this.buffer),r.putImageData(this.buffer,0,0),c&&this.record(performance.now()-l,t*n)}drawVector(e){this.svg.setAttribute(`viewBox`,`0 0 ${e.width} ${e.height}`),this.layerGroup.replaceChildren();for(let t of this.layerList){if(KH(t)||!t.visible)continue;let n=document.createElementNS(GV,`g`);n.setAttribute(`data-layer`,t.id),t.render(e,n),this.layerGroup.append(n)}this.overlay.redraw(e)}applyCooperative(e){this.root.classList.toggle(`sm-flat--cooperative`,e),this.cooperative?.setEnabled(e)}attachInteraction(){let e=!1,t=0,n=0,r=!1,i=!1,a=new Map,o=-1,s=0,c=null,l=()=>{let[e,t]=[...a.values()];if(!t)return null;let n=this.root.getBoundingClientRect();return{gap:Math.hypot(e.x-t.x,e.y-t.y),x:(e.x+t.x)/2-n.left,y:(e.y+t.y)/2-n.top}},u=e=>{let t=this.root.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]};this.root.addEventListener(`pointerdown`,u=>{u.pointerType===`touch`&&a.set(u.pointerId,{x:u.clientX,y:u.clientY}),c=l(),s=c?.gap??0,u.button===0&&(o=u.pointerId,e=!0,r=!1,i=u.pointerType===`touch`&&this.cooperative.isEnabled()&&a.size<2,this.root.setPointerCapture(u.pointerId),t=u.clientX,n=u.clientY,!i&&this.dragPan.isEnabled()&&this.root.classList.add(`sm-flat--dragging`))}),this.root.addEventListener(`pointermove`,d=>{let[f,p]=u(d);a.has(d.pointerId)&&a.set(d.pointerId,{x:d.clientX,y:d.clientY});let m=l();if(m){r=!0,c&&this.dragPan.isEnabled()&&this.drag(m.x-c.x,m.y-c.y),s>0&&this.scrollZoom.isEnabled()&&this.zoomBy(m.gap/s,m.x,m.y),s=m.gap,c=m;return}if(!e){this.emit(`pointermove`,this.unproject(f,p),d);return}if(d.pointerId!==o)return;let h=d.clientX-t,g=d.clientY-n;if(t=d.clientX,n=d.clientY,(Math.abs(h)>1||Math.abs(g)>1)&&(r=!0),i){r&&this.cooperative.allowsTouchDrag(a.size);return}this.dragPan.isEnabled()&&this.drag(h,g)});let d=l=>{a.delete(l.pointerId),s=0,c=null;let[d]=[...a.entries()];if(d&&e){o=d[0],t=d[1].x,n=d[1].y,i=this.cooperative.isEnabled()&&a.size<2;return}if(!(!e||l.pointerId!==o)&&(e=!1,this.root.releasePointerCapture?.(l.pointerId),this.root.classList.remove(`sm-flat--dragging`),!r)){let[e,t]=u(l);this.emit(`click`,this.unproject(e,t),l)}};this.root.addEventListener(`pointerup`,d),this.root.addEventListener(`pointercancel`,d),this.root.addEventListener(`wheel`,e=>{if(!this.scrollZoom.isEnabled()||!this.cooperative.allowsWheel(e))return;e.preventDefault();let[t,n]=u(e);this.zoomBy(Math.exp(-e.deltaY/400),t,n)},{passive:!1})}drag(e,t){this.limitsArmed=!0;let n=this.viewport();if(this.projection.azimuthal){let r=n.scale,i=e=>e/r*(180/Math.PI),[a,o]=MH((this.projectionOptions.centerLon??0)-i(e),Math.max(-90,Math.min(90,(this.projectionOptions.centerLat??0)+i(t))),this.limits);this.projectionOptions={...this.projectionOptions,centerLon:a,centerLat:o},this.projection=WB(this.projectionId,this.projectionOptions)}else this.view={...this.view,centerX:this.view.centerX-e/n.scale,centerY:this.view.centerY+t/n.scale};this.renderMoving(),this.emit(`viewchange`,this.viewState)}zoomBy(e,t,n){this.limitsArmed=!0;let r=this.viewport().fromScreen(t,n),i=Math.min(this.limits.maxZoom??1/0,Math.max(1,this.limits.minZoom??1,this.view.zoom*e));if(i===this.view.zoom)return;this.view={...this.view,zoom:i};let a=this.viewport();if(!this.projection.azimuthal){let e=a.fromScreen(t,n);this.view={...this.view,centerX:this.view.centerX+r[0]-e[0],centerY:this.view.centerY+r[1]-e[1]}}this.loadVisible(),this.renderMoving(),this.emit(`viewchange`,this.viewState)}};function YH(e){let t=e?.radii;if(t)return(t.a+t.b+t.c)/3;let n=e?.wikidata?.radius;if(n)return n.unit===`kilometre`?n.value:n.unit===`metre`?n.value/1e3:null;let r=e?.sbdb?.diameter;return r?r/2:null}function XH(){return typeof window>`u`?`unsupported`:window.isSecureContext?`DeviceOrientationEvent`in window&&window.matchMedia(`(pointer: coarse)`).matches?`available`:`unsupported`:`insecure`}async function ZH(){let e=DeviceOrientationEvent.requestPermission;if(typeof e!=`function`)return!0;try{return await e.call(DeviceOrientationEvent)===`granted`}catch{return!1}}var QH=Math.PI/180,$H=256,eU=128,tU=.05,nU=.25;function rU(e){try{let t=document.createElement(`canvas`);t.width=$H,t.height=eU;let n=t.getContext(`2d`,{willReadFrequently:!0});if(!n)return null;n.drawImage(e,0,0,$H,eU);let{data:r}=n.getImageData(0,0,$H,eU),i=new Uint8Array($H*eU);for(let e=0;e<i.length;e++)i[e]=+(r[e*4+3]>127);return{width:$H,height:eU,covered:i}}catch{return null}}function iU(e,t,n){let{width:r,height:i,covered:a}=e,o=new Float64Array(r);for(let e=0;e<r;e++)o[e]=(e+.5)*360/r;let s=new Float64Array(i);for(let e=0;e<i;e++)s[e]=90-(e+.5)*180/i;let c=0,l=0,u=0;for(let e=0;e<i;e++){let t=Math.cos(s[e]*QH);for(let n=0;n<r;n++)a[e*r+n]&&(c+=t*Math.sin(o[n]*QH),l+=t*Math.cos(o[n]*QH),u+=t)}if(u===0)return t;let d=Math.hypot(c,l)/u<tU?t.heading:aU(Math.atan2(c,l)/QH-n.northOffsetDeg),f=aU(d+n.northOffsetDeg),p=Math.min(180,n.hfovDeg/2),m=new Float64Array(i),h=0;for(let e=0;e<r;e++)if(!(Math.abs((o[e]-f+540)%360-180)>p))for(let t=0;t<i;t++)a[t*r+e]&&(h=Math.max(h,++m[t]));let g=-1/0,_=1/0;for(let e=0;e<i;e++)m[e]<h*nU||(g=Math.max(g,s[e]),_=Math.min(_,s[e]));if(g<_)return{heading:d,pitch:t.pitch};let v=Math.min(n.vfovDeg/3,(g-_)/2);return{heading:d,pitch:Math.max(_+v,Math.min(g-v,t.pitch))}}function aU(e){return(e%360+360)%360}Math.PI/180;function oU(e){return e.orientation!==`unknown`&&e.north_offset_deg!==void 0}function sU(e){return e.id}function cU(e){return`${e.time},${e.lat},${e.lon}`}function lU(e,t){return t?e.find(e=>sU(e)===t||cU(e)===t)??null:null}function uU(e,t,n){let r=e.findIndex(e=>e.id===t.id),i=e=>e&&e.mission===t.mission,a=e=>i(e)?{entry:e,distanceM:fU(t,e,n),bearingDeg:pU(t,e)}:null;return{previous:a(e[r-1]),next:a(e[r+1])}}var dU=Math.PI/180;function fU(e,t,n){return ZB(e,t)*dU*n*1e3}function pU(e,t){let n=e.lat*dU,r=t.lat*dU,i=(t.lon-e.lon)*dU,a=Math.sin(i)*Math.cos(r),o=Math.cos(n)*Math.sin(r)-Math.sin(n)*Math.cos(r)*Math.cos(i);return(Math.atan2(a,o)/dU%360+360)%360}var mU=Math.PI/180,hU=30,gU=110,_U=85,vU=75,yU=-22,bU=9,xU=6,SU=10,CU=1,wU=1,TU=new Vi(-Math.SQRT1_2,0,0,Math.SQRT1_2),EU=new J(0,0,1);function DU(e){return(e%360+360)%360}function OU(e,[t,n]){let r=DU(n-t),i=DU(e-t);return i<=r?DU(e):i-r<360-i?DU(n):DU(t)}function kU(e,t,n){return Math.max(t,Math.min(n,e))}function AU(e,t,n=new J){let r=e*mU,i=t*mU;return n.set(Math.sin(r)*Math.cos(i),Math.sin(i),-Math.cos(r)*Math.cos(i))}function jU(){let e=new ml;return e.moveTo(0,1),e.lineTo(.85,.05),e.lineTo(.38,.05),e.lineTo(.38,-.9),e.lineTo(-.38,-.9),e.lineTo(-.38,.05),e.lineTo(-.85,.05),e.closePath(),e}var MU=class{bodyId;openAt;openingView;interactive;followArrows;limits={};attribution=null;container=null;root=document.createElement(`div`);renderer=null;controls=null;resizeObserver=null;scene=new Ka;camera=new od(vU,1,.1,1e3);sphere;angleCanvas=document.createElement(`canvas`);angleContext=this.angleCanvas.getContext(`2d`);angleGridVisible=!1;arrows=new Ra;arrowGeometry=new eu(jU());raycaster=new Ld;loader=new qu;texture=null;loadToken=0;frame=0;disposed=!1;entries=[];radiusKm=0;current=null;neighbours=null;view;pointers=new Map;pinchDistance=0;dragStart=null;hovered=null;gyroEnabled=!1;gyroOrigin=null;gyroEuler=new ba;gyroQuaternion=new Vi;gyroScreen=new Vi;gyroDirection=new J;lookAt=new J;ndc=new J;gridPoint=new J;viewDirection=new J;listeners={ready:new Set,load:new Set,error:new Set,viewchange:new Set,step:new Set,arrows:new Set};constructor(e){this.bodyId=e.body,this.openAt=e.at,this.interactive=e.interactive??!0,this.arrows.visible=e.arrows??!0,this.followArrows=e.followArrows??!0,this.openingView=e.heading!==void 0||e.pitch!==void 0?{heading:e.heading,pitch:e.pitch}:null,this.view={heading:e.heading??0,pitch:e.pitch??0,fov:e.fov??vU},e.limits&&this.setLimits(e.limits),this.root.className=`sm-panorama`,this.root.style.cssText=`position:relative;width:100%;height:100%;overflow:hidden`,this.scene.background=new X(`#0b0d12`),this.sphere=new ks(new nu(500,96,48).scale(-1,1,1),new _s({transparent:!0,visible:!1,depthWrite:!1})),this.sphere.renderOrder=-2,this.scene.add(this.sphere,this.arrows)}mount(e){this.container=e,e.append(this.root),this.renderer=new uh({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2));let t=this.renderer.domElement;t.style.cssText=`display:block;width:100%;height:100%;touch-action:none`,t.tabIndex=0,this.root.append(t),this.angleCanvas.style.cssText=`position:absolute;inset:0;display:block;width:100%;height:100%;pointer-events:none`,this.angleCanvas.setAttribute(`aria-hidden`,`true`),this.angleCanvas.hidden=!0,this.root.append(this.angleCanvas),this.controls=new IV(this,this.root),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.root),this.resize(),this.interactive?(t.addEventListener(`pointerdown`,this.onPointerDown),t.addEventListener(`pointermove`,this.onPointerMove),t.addEventListener(`pointerup`,this.onPointerUp),t.addEventListener(`pointercancel`,this.onPointerCancel),t.addEventListener(`wheel`,this.onWheel,{passive:!1}),t.addEventListener(`keydown`,this.onKeyDown)):(t.addEventListener(`pointermove`,this.onPointerMove),t.addEventListener(`pointerup`,this.onPointerUp))}async load(){let e=await mx(this.bodyId,!1);if(this.disposed)return;this.entries=(e.global?.panoramas??[]).filter(px),this.radiusKm=YH(e.global)??0,this.emit(`ready`);let t=this.openAt?this.byKey(this.openAt):this.entries[0]??null;if(!t){let e=Error(this.openAt?`spacemap: no panorama ${this.openAt} on ${this.bodyId}`:`spacemap: no panoramas on ${this.bodyId}`);throw this.emit(`error`,e),e}await this.open(t)}addControl(e,t){return this.controls?.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.disposed=!0,this.setGyroEnabled(!1),this.loadToken++,cancelAnimationFrame(this.frame),this.frame=0,this.controls?.clear(),this.resizeObserver?.disconnect();let e=this.renderer?.domElement;e&&(e.removeEventListener(`pointerdown`,this.onPointerDown),e.removeEventListener(`pointermove`,this.onPointerMove),e.removeEventListener(`pointerup`,this.onPointerUp),e.removeEventListener(`pointercancel`,this.onPointerCancel),e.removeEventListener(`wheel`,this.onWheel),e.removeEventListener(`keydown`,this.onKeyDown)),this.setArrowTargets([]),this.texture?.dispose(),this.sphere.geometry.dispose(),this.sphere.material.dispose(),this.arrowGeometry.dispose(),this.renderer?.dispose(),this.renderer=null,this.root.remove(),this.container=null}getPanoramas(){return this.entries}getCurrent(){return this.current}getNeighbours(){return this.neighbours}async open(e){let t=typeof e==`string`?this.byKey(e):e;if(!t){let t=Error(`spacemap: no panorama ${String(e)} on ${this.bodyId}`);throw this.emit(`error`,t),t}this.current=t,this.neighbours=this.radiusKm?uU(this.entries,t,this.radiusKm):null;let n=this.openingView;this.openingView=null,n&&this.setView({heading:n.heading,pitch:n.pitch??0}),this.setArrowTargets(this.neighbours&&oU(t)?[`previous`,`next`].map(e=>({key:e,n:this.neighbours?.[e]??null})).filter(e=>e.n&&e.n.distanceM>=wU).map(e=>({key:e.key,bearingDeg:e.n.bearingDeg})):[]),await this.loadTexture(qt(`/v1/panoramas/${t.id}.webp`,`panoramas`),t.north_offset_deg??0,!n),this.current===t&&this.emit(`load`,t)}async step(e){let t=this.neighbours?.[e];t&&await this.open(t.entry)}byKey(e){return this.entries.find(t=>t.id===e)??lU(this.entries,e)}getView(){return{...this.view}}setView(e){let t=e.heading??this.view.heading,n=e.pitch??this.view.pitch,r=e.fov??this.view.fov,{limits:i}=this;this.view={heading:i.heading?OU(t,i.heading):DU(t),pitch:kU(n,i.pitch?.[0]??-_U,i.pitch?.[1]??_U),fov:kU(r,i.fov?.[0]??hU,i.fov?.[1]??gU)},this.invalidate(),this.emit(`viewchange`,this.getView())}getLimits(){return structuredClone(this.limits)}setLimits(e){let t=(e,t,n)=>e&&[kU(e[0],t,n),kU(e[1],t,n)];this.limits={heading:e.heading&&[DU(e.heading[0]),DU(e.heading[1])],pitch:t(e.pitch,-_U,_U),fov:t(e.fov,hU,gU)},this.setView({})}async setGyroEnabled(e){return e===this.gyroEnabled?this.gyroEnabled:e?XH()!==`available`||!await ZH()||this.disposed?!1:(this.gyroOrigin=null,this.gyroEnabled=!0,window.addEventListener(`deviceorientation`,this.onDeviceOrientation),!0):(window.removeEventListener(`deviceorientation`,this.onDeviceOrientation),this.gyroEnabled=!1,!1)}isGyroEnabled(){return this.gyroEnabled}onDeviceOrientation=e=>{if(e.alpha===null||e.beta===null||e.gamma===null)return;this.gyroEuler.set(e.beta*mU,e.alpha*mU,-e.gamma*mU,`YXZ`),this.gyroQuaternion.setFromEuler(this.gyroEuler).multiply(TU).multiply(this.gyroScreen.setFromAxisAngle(EU,-(screen.orientation?.angle??0)*mU)),this.gyroDirection.set(0,0,-1).applyQuaternion(this.gyroQuaternion);let t=Math.atan2(this.gyroDirection.x,-this.gyroDirection.z)/mU,n=Math.asin(kU(this.gyroDirection.y,-1,1))/mU;this.gyroOrigin===null&&(this.gyroOrigin=DU(t-this.view.heading)),this.setView({heading:t-this.gyroOrigin,pitch:n})};on(e,t){return this.listeners[e].add(t),()=>this.off(e,t)}once(e,t){let n=this.on(e,((...e)=>{n(),t(...e)}));return n}off(e,t){this.listeners[e].delete(t)}emit(e,...t){for(let n of this.listeners[e])n(...t)}faceCoverage(e,t){let n=rU(e);if(!n)return;let r=this.view.fov,i=2*Math.atan(Math.tan(r/2*mU)*this.camera.aspect)/mU;this.setView(iU(n,this.view,{northOffsetDeg:t,hfovDeg:i,vfovDeg:r}))}loadTexture(e,t,n){let r=++this.loadToken;return new Promise((i,a)=>{this.loader.load(e,e=>{if(r!==this.loadToken){e.dispose(),i();return}e.colorSpace=Jr,this.renderer&&(e.anisotropy=this.renderer.capabilities.getMaxAnisotropy()),this.texture?.dispose(),this.texture=e,this.sphere.material.map=e,this.sphere.material.visible=!0,this.sphere.material.needsUpdate=!0,this.sphere.rotation.y=Math.PI/2+t*mU,n&&this.faceCoverage(e.image,t),this.invalidate(),i()},void 0,()=>{if(r!==this.loadToken)return i();let t=Error(`spacemap: panorama failed to load: ${e}`);this.emit(`error`,t),a(t)})})}setArrowTargets(e){for(let e of[...this.arrows.children])this.arrows.remove(e),e.traverse(e=>{e instanceof ks&&e.material.dispose()});for(let t of e){let e=new Ra;e.name=t.key;let n=new ks(this.arrowGeometry,new _s({color:`#000000`,transparent:!0,opacity:.45,side:2,depthWrite:!1}));n.scale.setScalar(1.3);let r=new ks(this.arrowGeometry,new _s({color:`#ffffff`,transparent:!0,opacity:.85,side:2,depthWrite:!1}));r.position.y=.02;for(let e of[n,r])e.rotation.x=-Math.PI/2;e.add(n,r),e.position.copy(AU(t.bearingDeg,yU)).multiplyScalar(bU),e.rotation.y=-t.bearingDeg*mU,this.arrows.add(e)}this.invalidate()}invalidate(){this.disposed||this.frame||!this.renderer||(this.frame=requestAnimationFrame(()=>{this.frame=0,this.render()}))}setAngleGridVisible(e){e!==this.angleGridVisible&&(this.angleGridVisible=e,this.angleCanvas.hidden=!e,this.invalidate())}setArrowsVisible(e){e!==this.arrows.visible&&(this.arrows.visible=e,e||(this.hovered=null,this.renderer&&(this.renderer.domElement.style.cursor=``)),this.invalidate())}resize(){let{clientWidth:e,clientHeight:t}=this.root;if(!e||!t||!this.renderer)return;this.renderer.setSize(e,t,!1);let n=Math.min(window.devicePixelRatio,2);this.angleCanvas.width=Math.round(e*n),this.angleCanvas.height=Math.round(t*n),this.angleContext.setTransform(n,0,0,n,0,0),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.invalidate()}render(){if(!this.renderer)return;this.camera.fov=this.view.fov,this.camera.updateProjectionMatrix(),this.camera.lookAt(AU(this.view.heading,this.view.pitch,this.lookAt)),this.renderer.render(this.scene,this.camera);let{clientWidth:e,clientHeight:t}=this.root;if(this.drawAngleGrid(e,t),this.listeners.arrows.size===0)return;let n={};for(let r of this.arrows.visible?this.arrows.children:[])this.ndc.copy(r.position).project(this.camera),n[r.name]={x:(this.ndc.x+1)/2*e,y:(1-this.ndc.y)/2*t,visible:this.ndc.z<1&&Math.abs(this.ndc.x)<.98&&Math.abs(this.ndc.y)<.98};this.emit(`arrows`,n)}drawAngleGrid(e,t){let n=this.angleContext;if(n.clearRect(0,0,e,t),this.angleGridVisible){this.camera.getWorldDirection(this.viewDirection),n.strokeStyle=`rgba(255, 255, 255, 0.24)`,n.lineWidth=1,n.beginPath();for(let r=0;r<360;r+=SU)this.traceAngleLine(n,e,t,r,!0);for(let r=-80;r<=80;r+=SU)this.traceAngleLine(n,e,t,r,!1);n.stroke(),n.font=`12px system-ui, sans-serif`,n.lineWidth=3,n.strokeStyle=`rgba(0, 0, 0, 0.7)`,n.fillStyle=`rgba(255, 255, 255, 0.85)`,n.textAlign=`center`,n.textBaseline=`bottom`;for(let r=0;r<360;r+=SU){if(!this.projectAngle(r,0,e,t,!0))continue;let i=`${r}°`;n.strokeText(i,this.gridPoint.x,this.gridPoint.y-3),n.fillText(i,this.gridPoint.x,this.gridPoint.y-3)}n.textAlign=`left`,n.textBaseline=`middle`;for(let r of[0,90,180,270])for(let i=-80;i<=80;i+=SU){if(i===0||!this.projectAngle(r,i,e,t,!0))continue;let a=`${i>0?`+`:``}${i}°`;n.strokeText(a,this.gridPoint.x+4,this.gridPoint.y),n.fillText(a,this.gridPoint.x+4,this.gridPoint.y)}}}traceAngleLine(e,t,n,r,i){let a=!1,o=0,s=0,c=Math.max(t,n)*2,l=i?-90:0,u=i?90:360;for(let d=l;d<=u;d+=CU){let l=i?r:d,u=i?d:r;if(!this.projectAngle(l,u,t,n)){a=!1;continue}let{x:f,y:p}=this.gridPoint;!a||Math.hypot(f-o,p-s)>c?e.moveTo(f,p):e.lineTo(f,p),a=!0,o=f,s=p}}projectAngle(e,t,n,r,i=!1){return AU(e,t,this.gridPoint),this.gridPoint.dot(this.viewDirection)<=.001||(this.gridPoint.project(this.camera),!Number.isFinite(this.gridPoint.x)||!Number.isFinite(this.gridPoint.y))||i&&(Math.abs(this.gridPoint.x)>=.98||Math.abs(this.gridPoint.y)>=.98)||Math.abs(this.gridPoint.x)>4||Math.abs(this.gridPoint.y)>4?!1:(this.gridPoint.x=(this.gridPoint.x+1)/2*n,this.gridPoint.y=(1-this.gridPoint.y)/2*r,!0)}degreesPerPixel(){return this.view.fov/Math.max(1,this.root.clientHeight)}arrowAt(e,t){if(!this.renderer||!this.arrows.visible||this.arrows.children.length===0)return null;let n=this.renderer.domElement.getBoundingClientRect(),r=new q((e-n.left)/n.width*2-1,-((t-n.top)/n.height)*2+1);this.raycaster.setFromCamera(r,this.camera);let i=this.raycaster.intersectObjects(this.arrows.children,!0)[0];return i?i.object.parent.name:null}pressArrow(e){let t=this.neighbours?.[e];t&&(this.emit(`step`,{key:e,entry:t.entry}),this.followArrows&&this.open(t.entry).catch(()=>{}))}onPointerDown=e=>{try{this.renderer?.domElement.setPointerCapture(e.pointerId)}catch{}this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.dragStart=this.pointers.size===1?{x:e.clientX,y:e.clientY}:null,this.pointers.size===2&&(this.pinchDistance=this.pinchSpan())};onPointerMove=e=>{let t=this.pointers.get(e.pointerId);if(!t){let t=this.arrowAt(e.clientX,e.clientY);t!==this.hovered&&this.renderer&&(this.hovered=t,this.renderer.domElement.style.cursor=t?`pointer`:``);return}let n=e.clientX-t.x,r=e.clientY-t.y;if(this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.pointers.size===1){if(this.gyroEnabled)return;let e=this.degreesPerPixel();this.setView({heading:this.view.heading-n*e,pitch:this.view.pitch+r*e})}else if(this.pointers.size===2){let e=this.pinchSpan();this.pinchDistance>0&&this.zoom(this.pinchDistance/e),this.pinchDistance=e}};onPointerUp=e=>{this.pointers.delete(e.pointerId);let t=this.dragStart;if(this.dragStart=null,this.pointers.size>0||!(!this.interactive||t!==null&&Math.hypot(e.clientX-t.x,e.clientY-t.y)<xU))return;let n=this.arrowAt(e.clientX,e.clientY);n&&this.pressArrow(n)};onPointerCancel=e=>{this.pointers.delete(e.pointerId),this.dragStart=null};pinchSpan(){let[e,t]=[...this.pointers.values()];return Math.hypot(e.x-t.x,e.y-t.y)}zoom(e){this.setView({fov:this.view.fov*e})}onWheel=e=>{e.preventDefault(),this.zoom(Math.exp(e.deltaY*.0015))};onKeyDown=e=>{let t=this.view.fov/10,{heading:n,pitch:r}=this.view,i={ArrowLeft:()=>this.setView({heading:n-t}),ArrowRight:()=>this.setView({heading:n+t}),ArrowUp:()=>this.setView({pitch:r+t}),ArrowDown:()=>this.setView({pitch:r-t}),"+":()=>this.zoom(.8),"-":()=>this.zoom(1.25)}[e.key];i&&(e.preventDefault(),i())}},NU=ix(()=>`${Wt()}/v1/groups/__planetary_systems_map__.json.gz`,{error:e=>`Failed to fetch planetary systems map: ${e.status}`}),PU=ix(()=>`${Wt()}/v1/groups/__solar_system_map__.json.gz`,{error:e=>`Failed to fetch solar system map: ${e.status}`});function FU({onScrub:e,onEnd:t}){let n=null,r=0,i=!1;function a(){i&&t(),n=null,i=!1}return{onpointerdown(e){e.pointerType!==`mouse`&&(n=e.clientX,r=e.clientY,i=!1)},onpointermove(t){t.pointerType===`mouse`||n===null||!i&&Math.hypot(t.clientX-n,t.clientY-r)<8||(i=!0,e(t.clientX,t.clientY))},onpointerup:a,onpointercancel:a,onpointerleave:a}}var IU=2.2,LU=84,RU=40,zU=4,BU=3,VU=1e4,HU=34,UU=7,WU=.42,GU=30;function KU(e,t,n){let r=1/0;for(let i of n)r=Math.min(r,Math.hypot(i.cx-e,i.cy-t));return r}function qU(e){return e>90?180-e:e}function JU(e){let t=Math.log10(e.domain[0]),n=Math.log10(e.domain[1])-t,r=r=>44+(Math.log10(Math.max(r/e.unitKm,1e-9))-t)/n*656,i=[];for(let t of[...e.bodies].sort((e,t)=>e.aKm-t.aKm)){let n=r(t.aKm),a=Math.max(IU,t.radiusKm*e.pxPerKm),o=120;if(t.tiltDeg>0){let r=Math.min(qU(t.tiltDeg)*e.pxPerDeg,LU),a=120-r,s=120+r;o=KU(n,a,i)>=KU(n,s,i)?a:s}i.push({...t,cx:n,cy:o,r:a})}let a=[];for(let t of i){if(!t.satellites?.length)continue;let n=t.rings?t.r*t.rings.outer*WU:0,r=t.cy-Math.max(t.r,n)-zU,i=[];for(let n of[...t.satellites].sort((e,t)=>t.radiusKm-e.radiusKm)){let a=Math.max(IU,n.radiusKm*e.pxPerKm);r-=a,i.push({...n,cx:t.cx,cy:r,r:a,hitY:0,hitHeight:0}),r-=a+BU}let o=Math.min(...i.map(e=>e.cy-e.r))-UU,s=Math.max(...i.map(e=>e.cy+e.r))+UU;i.forEach((e,t)=>{let n=t===0?s:(i[t-1].cy+e.cy)/2,r=t===i.length-1?o:(i[t+1].cy+e.cy)/2;e.hitY=r,e.hitHeight=n-r}),a.push({parent:t,moons:i,x:t.cx-HU/2,y:o,width:HU,height:s-o,perMoon:!t.grouped&&!t.satellitesLink&&i.some(e=>e.link)})}let o=e.bands.map(e=>{let t=r(e.innerKm),n=r(e.outerKm)-t,i=Math.max(n,GU);return{...e,x:t,width:n,hitX:t+(n-i)/2,hitWidth:i}}).sort((e,t)=>t.width-e.width),s=``;e.cloud?.points.forEach((t,n)=>{let i=t.aKm/e.unitKm;if(i<e.domain[0]||i>e.domain[1])return;let a=Math.min(Math.max(qU(t.tiltDeg),0)*e.pxPerDeg,LU),o=120+(n%2==0?-a:a);s+=`M${r(t.aKm).toFixed(1)} ${o.toFixed(1)}h0.01`});let c=e.primary.radiusKm*e.pxPerKm;return{bodies:i,moonZones:a,bands:o,cloudPath:s,primaryR:c,primaryCx:RU-c,xOf:r}}function YU(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function XU(e,t,n,r){for(let i of[!0,!1]){let a=null,o=r;for(let r of e.bodies){if(!!r.link!==i)continue;let e=Math.hypot(t-r.cx,n-r.cy),s=e<=r.r?e-VU:e-r.r;s>o||(a=r,o=s)}if(a)return a}return null}function ZU(e,t,n){let r=XU(e,t,n,0);if(r)return{kind:`body`,id:r.id};for(let r of e.moonZones){if(!YU(r,t,n))continue;if(r.parent.grouped)return{kind:`body`,id:r.parent.id};if(!r.perMoon)return{kind:`stack`,id:r.parent.id};let e=r.moons.find(e=>n>=e.hitY&&n<=e.hitY+e.hitHeight);if(e)return{kind:`moon`,parent:r.parent.id,id:e.id}}let i=XU(e,t,n,16);if(i)return{kind:`body`,id:i.id};for(let r=e.bands.length-1;r>=0;r--){let i=e.bands[r];if(t>=i.hitX&&t<=i.hitX+i.hitWidth&&n>=26&&n<=206)return{kind:`band`,key:i.key}}return Math.hypot(t-e.primaryCx,n-120)<=e.primaryR?{kind:`primary`}:null}function QU(e,t,n){if(!n)return null;let{text:r}=e;switch(n.kind){case`primary`:return{cx:Math.max(44,t.primaryCx),cy:120-Math.min(t.primaryR,80),title:e.primary.name,sub:r.primary};case`body`:{let e=t.bodies.find(e=>e.id===n.id);if(!e)return null;let i=[r.distance(e.aKm)];return e.tiltDeg>90&&i.push(r.retrograde),e.grouped&&e.satellites?.length&&i.push(r.moons(e.satelliteCount??e.satellites.length)),{cx:e.cx,cy:e.cy-e.r-4,title:e.name,sub:i.join(` · `)}}case`stack`:{let e=t.moonZones.find(e=>e.parent.id===n.id);if(!e)return null;let i=e.x+e.width/2;return e.parent.satellitesTab?{cx:i,cy:e.y,title:e.parent.name,sub:r.moons(e.parent.satelliteCount??e.moons.length)}:{cx:i,cy:e.y,title:e.moons[0].name,sub:e.parent.name}}case`moon`:{let e=t.moonZones.find(e=>e.parent.id===n.parent),r=e?.moons.find(e=>e.id===n.id);return!e||!r?null:{cx:r.cx,cy:r.cy-r.r-4,title:r.name,sub:e.parent.name}}case`band`:{let e=t.bands.find(e=>e.key===n.key);return e?{cx:e.x+e.width/2,cy:44,title:e.name??e.label,sub:e.sub??`${r.distance(e.innerKm)}–${r.distance(e.outerKm)}`}:null}}}var $U=`http://www.w3.org/2000/svg`,eW=10,tW=-18,nW=1.2,rW=28,iW=6,aW=4,oW=18,sW=12,cW=190;function lW(e,t={},...n){let r=document.createElementNS($U,e);for(let[e,n]of Object.entries(t))n!==void 0&&r.setAttribute(e,String(n));for(let e of n)e&&r.append(e);return r}function uW(e,t){return JSON.stringify(e)===JSON.stringify(t)}function dW(e,t){let n=new Map,r=(e,t)=>{(t?.href||t?.onclick)&&n.set(JSON.stringify(e),t)};for(let e of t.bands)r({kind:`band`,key:e.key},e);r({kind:`primary`},e.primary.link);for(let e of t.bodies)r({kind:`body`,id:e.id},e.link);for(let e of t.moonZones)if(!e.parent.grouped)if(!e.perMoon)r({kind:`stack`,id:e.parent.id},e.parent.satellitesLink);else for(let t of e.moons)r({kind:`moon`,parent:e.parent.id,id:t.id},t.link);return n}var fW=0,pW=class{root=document.createElement(`div`);svg=lW(`svg`);tip=document.createElement(`div`);tipTitle=document.createElement(`span`);tipSub=document.createElement(`span`);uid=`sm-system-map-${fW++}`;resize=new ResizeObserver(()=>{this.fitLabels(),this.placeTip()});model=null;placed=null;background=!1;hover=null;highlights=new Map;targets=new Map;links=new Map;shape=``;labels=[];constructor(){this.tip.className=`sm-system-map__tip`,this.tipTitle.className=`sm-system-map__tip-title`,this.tipSub.className=`sm-system-map__tip-sub`,this.tip.append(this.tipTitle,this.tipSub),this.tip.hidden=!0,this.root.append(this.svg,this.tip),this.resize.observe(this.root);let e=FU({onScrub:(e,t)=>this.setHover(this.hitAt(e,t)),onEnd:()=>this.setHover(null)});this.svg.addEventListener(`pointerdown`,e.onpointerdown),this.svg.addEventListener(`pointermove`,e.onpointermove),this.svg.addEventListener(`pointerup`,e.onpointerup),this.svg.addEventListener(`pointercancel`,e.onpointercancel),this.svg.addEventListener(`pointerleave`,e.onpointerleave);let t=[0,0],n=e=>{t=[e.clientX,e.clientY]};this.svg.addEventListener(`pointerdown`,n),this.svg.addEventListener(`pointerup`,n),this.svg.addEventListener(`pointermove`,e=>{n(e),e.pointerType===`mouse`&&this.setHover(this.hitAt(e.clientX,e.clientY))}),this.svg.addEventListener(`pointerleave`,e=>{e.pointerType===`mouse`&&this.setHover(null)}),this.svg.addEventListener(`click`,e=>{if(e.detail===0)return;let n=Math.abs(t[0]-e.clientX)<1&&Math.abs(t[1]-e.clientY)<1?this.hitAt(...t):this.hitAt(e.clientX,e.clientY);if(!n)return;let r=this.targets.get(JSON.stringify(n));r?.contains(e.target)||(e.stopPropagation(),e.preventDefault(),r?.dispatchEvent(new MouseEvent(`click`,{bubbles:!0,cancelable:!0,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,button:e.button})))},!0)}destroy(){this.resize.disconnect(),this.root.remove()}update(e,t){this.model=e,this.placed=JU(e);let n=dW(e,this.placed),r=JSON.stringify([JSON.stringify(e,(e,t)=>e===`href`?void 0:t),t,[...n].map(([e,t])=>[e,!!t.href,!!t.onclick])]);if(this.links=n,r===this.shape){for(let[e,t]of this.targets){let r=n.get(e)?.href;r&&t.setAttribute(`href`,r)}return}this.shape=r,this.background=t.variant===`background`,this.hover=null,this.root.className=this.background?`sm-system-map sm-system-map--background`:`sm-system-map`,this.draw(e,this.placed,t.ariaLabel),this.fitLabels(),this.placeTip()}draw(e,t,n){let r=this.background;this.highlights=new Map,this.targets=new Map,this.labels=[];let i=this.svg;i.replaceChildren(),i.setAttribute(`viewBox`,r&&e.backgroundView||`0 0 720 240`),i.setAttribute(`preserveAspectRatio`,r?e.backgroundFit===`fit`?`xMidYMid meet`:e.backgroundView?`xMinYMid slice`:`xMidYMid slice`:`xMidYMid meet`),i.setAttribute(`class`,`sm-system-map__svg`),i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,n),i.setAttribute(`data-vaul-no-drag`,``);let a=(t,n)=>lW(`stop`,{offset:t,"stop-color":e.primary.color,"stop-opacity":n});i.append(lW(`defs`,{},lW(`radialGradient`,{id:`${this.uid}-primary`,gradientUnits:`userSpaceOnUse`,cx:t.primaryCx,cy:120,r:t.primaryR},a(`0%`,1),a(Math.max(0,1-eW/t.primaryR),.85),a(`100%`,.35)),lW(`pattern`,{id:`${this.uid}-band`,width:9,height:9,patternUnits:`userSpaceOnUse`},lW(`circle`,{cx:2,cy:2,r:.9,fill:`currentColor`,opacity:.55}),lW(`circle`,{cx:6.5,cy:6,r:.9,fill:`currentColor`,opacity:.55})))),r||this.drawAxis(e,t),t.cloudPath&&i.append(lW(`path`,{d:t.cloudPath,stroke:e.cloud?.color,"stroke-width":nW*2,"stroke-linecap":`round`,fill:`none`,opacity:.45,"pointer-events":`none`}));for(let e of t.bands){let t=lW(`rect`,{x:e.x,y:26,width:e.width,height:180,fill:`url(#${this.uid}-band)`,class:`sm-system-map__band sm-system-map__band--${e.tone}`});if(r){i.append(t);continue}let n=lW(`text`,{x:e.x+e.width/2,y:232,"text-anchor":`middle`,"font-size":oW,class:`sm-system-map__band-label sm-system-map__band-label--${e.tone}`});n.textContent=e.label,this.labels.push(n),i.append(this.target(e,e.name??e.label,{kind:`band`,key:e.key},t,lW(`rect`,{x:e.hitX,y:26,width:e.hitWidth,height:180,fill:`transparent`}),n))}let o=lW(`circle`,{cx:t.primaryCx,cy:120,r:t.primaryR,fill:`url(#${this.uid}-primary)`});i.append(r?o:this.target(e.primary.link,e.primary.name,{kind:`primary`},o));for(let e of t.bodies){if(!e.rings)continue;let t=e.r*(e.rings.inner+e.rings.outer)/2;i.append(lW(`ellipse`,{cx:e.cx,cy:e.cy,rx:t,ry:t*WU,transform:`rotate(${tW} ${e.cx} ${e.cy})`,fill:`none`,stroke:`#d9c89f`,"stroke-width":e.r*(e.rings.outer-e.rings.inner),opacity:.45}))}let s=new Map(t.moonZones.map(e=>[e.parent.id,e]));for(let e of t.bodies)i.append(this.body(e,s.get(e.id)));for(let e of t.moonZones)e.parent.grouped||this.stack(e)}drawAxis(e,t){for(let n of e.ticks){let r=t.xOf(n*e.unitKm),i=lW(`text`,{x:r,y:16,"text-anchor":`middle`,"font-size":16,fill:`currentColor`,opacity:.85});i.textContent=String(n),this.svg.append(lW(`line`,{x1:r,x2:r,y1:20,y2:212,stroke:`currentColor`,"stroke-width":.5,opacity:.12}),i)}let n=lW(`text`,{x:700,y:16,"text-anchor":`end`,"font-size":14,fill:`currentColor`,opacity:.65});n.textContent=e.axisLabel,this.svg.append(n)}body(e,t){let n=e.reference?lW(`circle`,{cx:e.cx,cy:e.cy,r:e.r+1,fill:`none`,stroke:e.color,"stroke-width":1.2,class:`sm-system-map__reference`}):lW(`circle`,{cx:e.cx,cy:e.cy,r:e.r,fill:e.color});if(this.background)return!t||!e.grouped?n:lW(`g`,{},n,...this.moonDots(t));let r={kind:`body`,id:e.id},i=this.highlight(r,lW(`circle`,{cx:e.cx,cy:e.cy,r:e.r+3.5,fill:`none`,stroke:`currentColor`,"stroke-width":1,opacity:.8})),a=lW(`circle`,{cx:e.cx,cy:e.cy,r:e.r+16,fill:`transparent`});return!t||!e.grouped?this.target(e.link,e.name,r,i,n,a):this.target(e.link,e.name,r,this.highlight(r,this.zoneWash(t)),i,n,a,...this.moonDots(t),this.zoneHit(t))}stack(e){if(this.background){this.svg.append(...this.moonDots(e));return}let t=e.parent;if(e.perMoon){this.svg.append(...this.moonDots(e));for(let n of e.moons){let r={kind:`moon`,parent:t.id,id:n.id};this.svg.append(this.target(n.link,n.name,r,this.highlight(r,lW(`circle`,{cx:n.cx,cy:n.cy,r:n.r+2.5,fill:`none`,stroke:`currentColor`,"stroke-width":1,opacity:.8})),lW(`rect`,{x:e.x,y:n.hitY,width:e.width,height:n.hitHeight,fill:`transparent`})))}return}let n={kind:`stack`,id:t.id},r=e.moons[0];this.svg.append(this.highlight(n,this.zoneWash(e)),...this.moonDots(e),this.target(t.satellitesLink,t.satellitesTab?`${t.name} · ${this.model.text.moons(t.satelliteCount??e.moons.length)}`:r.name,n,this.zoneHit(e)))}moonDots(e){return e.moons.map(e=>lW(`circle`,{cx:e.cx,cy:e.cy,r:e.r,fill:e.color}))}zoneWash(e){return lW(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:4,fill:`currentColor`,opacity:.1,"pointer-events":`none`})}zoneHit(e){return lW(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,fill:`transparent`})}highlight(e,t){let n=JSON.stringify(e),r=this.highlights.get(n);return r?r.push(t):this.highlights.set(n,[t]),t.style.display=`none`,t}target(e,t,n,...r){let i=!!(e?.href||e?.onclick),a=e?.href?lW(`a`,{href:e.href,"aria-label":t}):i?lW(`g`,{role:`button`,tabindex:0,"aria-label":t,class:`sm-system-map__button`}):lW(`g`);if(a.append(...r),!i)return a;let o=JSON.stringify(n);return this.targets.set(o,a),a.addEventListener(`focus`,()=>this.setHover(n)),a.addEventListener(`blur`,()=>{uW(this.hover,n)&&this.setHover(null)}),a.addEventListener(`click`,e=>this.links.get(o)?.onclick?.(e)),e?.href||a.addEventListener(`keydown`,e=>{let t=e.key;t!==`Enter`&&t!==` `||(e.preventDefault(),a.dispatchEvent(new MouseEvent(`click`,{bubbles:!0})))}),a}setHover(e){if(uW(this.hover,e))return;for(let e of this.highlights.get(JSON.stringify(this.hover))??[])e.style.display=`none`;this.targets.get(JSON.stringify(this.hover))?.removeAttribute(`data-near`),this.hover=e;for(let t of this.highlights.get(JSON.stringify(e))??[])t.style.display=``;let t=this.targets.get(JSON.stringify(e));t?.setAttribute(`data-near`,``),this.svg.classList.toggle(`sm-system-map__svg--near`,!!t),this.placeTip()}hitAt(e,t){if(!this.placed||this.background)return null;let n=this.svg.getBoundingClientRect();if(!n.width||!n.height)return null;let r=(e-n.left)/n.width*720,i=(t-n.top)/n.height*240;return ZU(this.placed,r,i)}fitLabels(){for(let e of this.labels){let t=0;e.setAttribute(`font-size`,String(oW));try{t=e.getComputedTextLength()}catch{}if(!t)continue;if(t>cW){let n=Math.max(sW,oW*cW/t);e.setAttribute(`font-size`,String(n)),t*=n/oW}let n=Number(e.dataset.centre??e.getAttribute(`x`));e.dataset.centre=String(n);let r=t/2,i=Math.min(Math.max(n,r+aW),Math.max(r,720-r-aW));e.setAttribute(`x`,String(i))}}placeTip(){let e=this.model&&this.placed&&!this.background?QU(this.model,this.placed,this.hover):null;if(this.tip.hidden=!e,!e)return;this.tipTitle.textContent=e.title,this.tipSub.textContent=e.sub?` · ${e.sub}`:``;let t=this.root.clientWidth,n=t/720;this.tip.style.maxWidth=`${Math.max(0,t-2*iW)}px`;let r=this.tip.offsetWidth/2,i=Math.min(Math.max(e.cx*n,r+iW),Math.max(r,t-r-iW));this.tip.style.left=`${i}px`,this.tip.style.top=`${Math.max(4,e.cy*n-rW)}px`}};function mW(e,t){return{planetId:e.primary.id,planetName:t,planetRadiusKm:e.primary.radius_km,planetColor:t_[e.primary.id]??`#cccccc`,moons:e.moons.map(e=>({id:e.id,name:e.id,aRp:e.a_rp,tiltDeg:e.tilt_deg,radiusKm:e.radius_km,color:t_[e.id]??e.color??`#cccccc`})),rings:e.rings?{innerRp:e.rings.inner_rp,outerRp:e.rings.outer_rp}:null,moonCount:e.moon_count}}var hW=14,gW=1.001,_W=.62,vW=[1,2,3,5,10,20,30,50,100,200,300,500,1e3,2e3,5e3],yW=`0 96 320 144`,bW=`0 96 720 144`,xW=[1,100];function SW(e,t){let n=Math.min(...e.moons.map(e=>e.aRp)),r=Math.max(...e.moons.map(e=>e.aRp));for(let i of t)n=Math.min(n,i.innerKm/e.planetRadiusKm),r=Math.max(r,i.outerKm/e.planetRadiusKm);return!Number.isFinite(n)||!Number.isFinite(r)?xW:(r<=n&&(n/=2,r*=2),n=n<=gW?1:n,[n>1?10**(Math.log10(n)-.12):1,10**(Math.log10(r)+.12)])}function CW(e,t){let n=e.planetRadiusKm,r=SW(e,t.bands);return{primary:{id:e.planetId,name:e.planetName,radiusKm:n,color:e.planetColor,link:t.primaryLink},bodies:e.moons.map(e=>({id:e.id,name:e.name,aKm:e.aRp*n,tiltDeg:e.tiltDeg,radiusKm:e.radiusKm,color:e.color,link:t.moonLink?.(e)})),bands:t.bands,cloud:t.cloud,unitKm:n,domain:r,ticks:vW.filter(e=>e>=r[0]&&e<=r[1]),axisLabel:t.axisLabel,pxPerKm:hW/Math.max(...e.moons.map(e=>e.radiusKm).filter(e=>e>0),1),pxPerDeg:_W,text:t.text,backgroundView:t.wide?bW:yW,backgroundFit:t.wide?`fit`:`slice`}}var wW=224e-6,TW=1.8,EW=[.3,50],DW=[.3,1,3,10,30],OW=`#ffdd44`;function kW(e){let t=e.replace(/^\d+\s+/,``);return t===t.toUpperCase()&&/[A-Z]/.test(t)?t.charAt(0)+t.slice(1).toLowerCase():t}function AW(e){return e.color||t_[e.id]||`#cccccc`}function jW(e,t){let n=new Map,r=new Map(e.objects.map(e=>[e.id,e]));for(let i of e.objects){if(i.kind!==`moon`||!i.parent)continue;let e=n.get(i.parent)??{satellites:[],count:r.get(i.parent)?.moon_count,tab:!1};e.satellites.push({id:i.id,name:t(i),radiusKm:i.diameter_km/2,color:AW(i)}),e.tab||=!!i.link_parent,n.set(i.parent,e)}return n}function MW(e,t){let n=e.objects.find(e=>e.kind===`star`);if(!n)return null;let r=jW(e,t.name),i=t.stack??(e=>r.get(e.id)),a=e.objects.filter(e=>e.kind!==`moon`&&e.kind!==`star`&&(t.keep?.(e)??!0)).map(e=>{let n=i(e);return{id:e.id,name:t.name(e),aKm:e.a*rg,tiltDeg:e.i,radiusKm:e.diameter_km/2,color:AW(e),rings:e.rings,satellites:n?.satellites,satelliteCount:n?.count,satellitesTab:n?.tab??!1,...t.links(e,n)}});return{primary:{id:n.id,name:t.name(n),radiusKm:n.diameter_km/2,color:OW,link:t.primaryLink},bodies:a,bands:e.belts.map(e=>({key:e.slug,innerKm:e.inner_au*rg,outerKm:e.outer_au*rg,tone:e.kind===`kuiper_belt`?`sky`:`muted`,...t.band(e)})),unitKm:rg,domain:EW,ticks:DW,axisLabel:t.text.axisAu,pxPerKm:wW,pxPerDeg:TW,text:t.text}}function NW(e){return{id:e.id,name:e.name??e.id,moon:e.moon??!1,aAu:e.aAu??0,tiltDeg:e.tiltDeg??0,radiusKm:e.radiusKm??0,color:e.color??t_[e.id]??`#cccccc`,parent:e.parent}}var PW=4,FW=10,IW={inner:[.6,5.5],outer:[4.5,55]},LW=[.1,.2,.3,.5,1,2,3,5,10,20,30,50,100,200,500,1e3],RW=.9,zW=.76;function BW(e,t){return Math.log(e/t[0])/Math.log(t[1]/t[0])}var VW=`naif-599`;function HW(e,t,n,r=[]){if(!n)return[];let i=new Set([...e.objects.map(e=>e.id),...r]);for(let e of Object.values(t)){i.add(e.primary.id);for(let t of e.moons)i.add(t.id)}return[...n].filter(e=>!i.has(e))}function UW(e){let t=e.type===`moon`,n=e.orbit?.parent_id,r=n===void 0||n===`naif-10`||n===`naif-0`?e.orbit?.a??e.orbit?.q:void 0;if(r===void 0&&!t)return null;let i=e.radii;return{id:e.id,name:kW(e.name??e.id),moon:t,aAu:r??0,tiltDeg:e.orbit?.i??0,radiusKm:i?(i.a+i.b+i.c)/3:(e.sbdb?.diameter??0)/2,color:t_[e.id]??e.sbdb?.color??e.color??`#cccccc`,parent:e.orbit?.parent_id}}var WW=.92;function GW(e,t){return e<t*WW?`inner`:`outer`}function KW(e,t){return Object.values(e).find(e=>e.primary.id===t)}function qW(e){return e.kind===`zone`?`zone:${e.zone}`:`${e.kind}:${e.id}`}var JW=class{targets=new Map;constructor(e,t,n){this.data=e,this.options=t,this.pick=n}has(e){return!this.options.bodies||this.options.bodies.has(e)}name(e,t){return this.options.names[e]??(t?kW(t):e)}named(e,t){return this.options.names[e]??t}link(e){return this.targets.set(qW(e),e),{onclick:()=>this.pick(e)}}body(e,t){return this.has(e)?this.link({kind:`body`,id:e,name:t}):void 0}stack(e,t){if(t&&!this.options.bodies)return t;let n=(KW(this.data.systems,e)?.moons??[]).filter(e=>this.has(e.id)).map(e=>({id:e.id,name:this.name(e.id),radiusKm:e.radius_km,color:t_[e.id]??e.color??`#cccccc`}));if(n.length)return n.sort((e,t)=>t.radiusKm-e.radiusKm),{satellites:n.slice(0,PW),count:n.length,tab:!0}}links(e,t,n){if(!n)return{link:this.body(e,t)};let r=()=>this.link({kind:`system`,id:e,name:t});if(this.options.grouping===`systems`)return{link:r(),grouped:!0};let i=n.satellites[0];return{link:this.body(e,t),satellitesLink:n.tab?r():this.body(i.id,i.name)}}built(e,t){return{model:e,targets:[...this.targets.values()],label:t}}};function YW(e,t,n,r){let i=new JW(e,t,r),a=e=>i.name(e.id,e.name),o=jW(e.solar,a),s=new Map(e.solar.objects.map(e=>[e.id,i.stack(e.id,o.get(e.id))])),c=e.solar.objects.find(e=>e.kind===`star`),l=e=>{let t=e===`inner`?n.zoneInner:n.zoneOuter;return{label:t,sub:``,...i.link({kind:`zone`,zone:e,name:t})}},u=MW(e.solar,{text:n,name:a,primaryLink:c&&i.body(c.id,a(c)),keep:e=>i.has(e.id)||!!s.get(e.id),stack:e=>s.get(e.id),links:(e,t)=>i.links(e.id,a(e),t),band:e=>t.zones===`belts`?{label:e.label}:l(e.kind===`kuiper_belt`?`outer`:`inner`)});if(!u)throw Error(`spacemap: the Solar System map names no Sun`);return i.built(u,n.solarSystem)}function XW(e,t,n,r,i,a){let o=KW(e.systems,t);if(!o)throw Error(`spacemap: no planetary system around ${t}`);let s=new JW(e,r,a),c=mW(o,s.name(t,n[t]));c.moons=c.moons.filter(e=>s.has(e.id)).map(e=>({...e,name:s.name(e.id,n[e.id])}));let l=c.planetRadiusKm,u=c.rings?[{key:`rings`,label:i.rings,innerKm:c.rings.innerRp*l,outerKm:c.rings.outerRp*l,tone:`amber`}]:[],d=CW(c,{text:i,axisLabel:i.axisRadii,bands:u,primaryLink:s.body(t,c.planetName),moonLink:e=>s.body(e.id,e.name)});return d.ticks=d.ticks.filter(e=>BW(e,d.domain)<zW),s.built(d,c.planetName)}function ZW(e,t,n,r,i){let a=new JW(e,n,i),{solar:o,extras:s}=e,c=o.objects.find(e=>e.kind===`star`),l=o.objects.find(e=>e.id===VW)?.a;if(!c||l===void 0)throw Error(`spacemap: the Solar System map names no Sun or no Jupiter`);let u=o.objects.filter(e=>e.kind===`dwarf`||e.kind===`asteroid`).map(e=>({id:e.id,name:a.name(e.id,e.name),aAu:e.a,tiltDeg:e.i,radiusKm:e.diameter_km/2,color:AW(e)}));for(let e of s)e.moon||u.some(t=>t.id===e.id)||e.aAu>0&&u.push({...e,name:a.named(e.id,e.name)});let d=[];for(let e of u){if(GW(e.aAu,l)!==t)continue;let n={...e,aKm:e.aAu*rg},r=a.stack(e.id);if(r){d.push({...n,satellites:r.satellites,satelliteCount:r.count,satellitesTab:!0,...a.links(e.id,e.name,r)});continue}let i=s.filter(t=>t.moon&&t.parent===e.id&&a.has(t.id)).map(e=>{let t=a.named(e.id,e.name);return{...e,name:t,link:a.body(e.id,t)}});!a.has(e.id)&&!i.length||d.push({...n,link:a.body(e.id,e.name),satellites:i.length?i:void 0})}let[f,p]=IW[t],m=[Math.min(f,...d.map(e=>e.aKm/rg*.85)),Math.max(p,...d.map(e=>e.aKm/rg*1.15))],h=e=>e>=m[0]&&e<=m[1],g=FW/Math.max(...d.map(e=>e.radiusKm),1);for(let e of o.objects)e.kind!==`planet`||!h(e.a)||d.push({id:e.id,name:a.name(e.id,e.name),aKm:e.a*rg,tiltDeg:0,radiusKm:0,color:AW(e),reference:!0});let _=t===`inner`?r.zoneInner:r.zoneOuter;return a.built({primary:{id:c.id,name:a.name(c.id,c.name),radiusKm:c.diameter_km/2*wW/g,color:OW},bodies:d,bands:o.belts.filter(e=>h(e.inner_au)&&h(e.outer_au)).map(e=>({key:e.slug,label:e.label,innerKm:e.inner_au*rg,outerKm:e.outer_au*rg,tone:e.kind===`kuiper_belt`?`sky`:`muted`})),unitKm:rg,domain:m,ticks:LW.filter(e=>h(e)&&BW(e,m)<RW),axisLabel:r.axisAu,pxPerKm:g,pxPerDeg:TW,text:r},_)}var QW=new WeakMap,$W=.01;function eG(){let{messages:e,locale:t}=i(),n=new Intl.NumberFormat(t(),{maximumSignificantDigits:3}),r=new Intl.NumberFormat(t(),{style:`unit`,unit:`kilometer`,maximumSignificantDigits:3}),a=e.unit_symbol_astronomical_unit();return{primary:e.planetary_system_primary(),retrograde:e.planetary_system_retrograde(),moons:t=>e.system_map_moons({count:t}),distance:e=>{let t=e/rg;return t>0&&t<$W?r.format(e):`${n.format(t)} ${a}`},axisAu:e.system_map_axis_au(),solarSystem:e.system_map_solar_system(),rings:e.tab_rings(),axisRadii:e.planetary_system_axis_unit(),zoneInner:e.system_map_zone_inner(),zoneOuter:e.system_map_zone_outer()}}var tG=class{chart=new pW;listeners=new Map;view;bodies;names;grouping;zones;places;targets=[];extras=new Map;queue=Promise.resolve();disposed=!1;constructor(e={}){this.view=e.view??{kind:`solar-system`},this.bodies=e.bodies?new Set(e.bodies):null,this.names=e.names??{},this.grouping=e.grouping??`bodies`,this.zones=e.zones??`belts`,this.places=(e.places??[]).map(NW)}mount(e){e.append(this.chart.root)}remove(){this.disposed=!0,this.chart.destroy()}load(){return this.draw()}async setView(e){await this.draw(e)}getView(){return this.view}setBodies(e){let t=e?new Set(e):null;return this.draw(void 0,t).catch(()=>{})}getTargets(){return[...this.targets]}draw(e,t){let n=this.queue.then(()=>(t!==void 0&&(this.bodies=t),this.drawNow(e??this.view)));return this.queue=n.catch(()=>{}),n}async drawNow(e){let t;try{t=await this.build(e)}catch(e){let t=e instanceof Error?e:Error(String(e));throw this.disposed||this.emit(`error`,t),t}if(this.disposed)return;let n=JSON.stringify(e)!==JSON.stringify(this.view);this.view=e,this.targets=t.targets,this.chart.update(t.model,{ariaLabel:t.label}),n&&this.emit(`viewchange`,e)}async build(e){let[t,n]=await Promise.all([PU(),NU()]),r={bodies:this.bodies,names:this.names,grouping:this.grouping,zones:this.zones},i=eG(),a=e=>this.emit(`select`,e),o={solar:t,systems:n,extras:[]};switch(e.kind){case`solar-system`:return YW(o,r,i,a);case`system`:return XW(o,e.id,await this.exportedNames(e.id,n),r,i,a);case`zone`:{let s=HW(t,n,this.bodies,this.places.map(e=>e.id)),c=(await Promise.all(s.map(e=>this.extra(e)))).filter(e=>e!==null),l=[...this.places,...c],u=HW(t,n,new Set(l.flatMap(e=>e.moon&&e.parent?[e.parent]:[])),l.map(e=>e.id)),d=await Promise.all(u.map(e=>this.extra(e))),f=[...l,...d.filter(e=>e!==null)];return ZW({...o,extras:f},e.zone,r,i,a)}}}extra(e){let t=this.extras.get(e);return t||(t=mx(e,!1).then(t=>{if(!t.global)throw Error(`spacemap: no such body as ${e}`);return UW(t.global)}).catch(t=>(this.extras.delete(e),this.emit(`error`,t instanceof Error?t:Error(String(t))),null)),this.extras.set(e,t)),t}async exportedNames(e,t){if(![e,...(KW(t,e)?.moons??[]).map(e=>e.id)].some(t=>!(t in this.names)&&(t===e||!this.bodies||this.bodies.has(t))))return{};try{let{global:t,localized:n}=await mx(e,!0,i().locale()),r={};for(let e of t?.notable_moons??[])e.id&&(r[e.id]=e.name);Object.assign(r,n?.notable_moon_names);let a=n?.name??t?.name;return a&&(r[e]=a),r}catch{return{}}}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=((...e)=>{r(),t(...e)});QW.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners.get(e);if(n){n.delete(t);for(let e of n)QW.get(e)===t&&n.delete(e)}}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of[...n])e(...t)}},nG=Object.fromEntries(yn.map(e=>[e,vn[e].label]));function rG(e,t){let n=e.credits.orbitSourceParents.get(t);if(!n)return!0;let r=e.visibility.focusedSystemId;for(let t of n)if(e.bodies.isInSystem(t,r))return!0;return!1}function iG(e){return yn.filter(t=>e.credits.orbitSources.has(t)).filter(t=>!vn[t].scoped||rG(e,t)).map(e=>({source:e,info:vn[e]}))}function aG(e,t){let n=e.visibility.focusedSystemId,r=e.visibility.focusedBodyId;return[...t].filter(e=>e.bodyId===r||n&&e.systemId===n)}function oG(e,t=nG){let n=e.credits;n.imageryVersion,n.modelVersion;let r=[...new Set(iG(e).map(({source:e})=>t[e]))],i=new Set;for(let t of aG(e,n.imagery.values()))i.add(t.organisation);let a=e.visibility.focusedBodyId,o=a?n.model.get(a):void 0;return o&&i.add(o.organisation),{orbits:r,imagery:[...i].sort()}}var sG=`https://spacemap.co`,cG=`https://spacemap.co/credits`;function lG(){let e=document.createElement(`div`);return e.className=`sm-attribution`,e}function uG(){let e=document.createElement(`span`);return e.className=`sm-attribution__group`,e}function dG(e,t,n){let r=document.createElement(`a`);return r.href=e,r.target=`_blank`,r.rel=`noopener noreferrer`,r.textContent=t,n&&(r.className=n),r}var fG=class{stop=null;onAdd(e){let t=lG(),n=uG(),r=uG();return t.append(dG(sG,`spacemap`,`sm-attribution__home`),n,r,dG(cG,i().messages.credits_see_all())),this.stop=st(()=>{at(()=>{let t=oG(e.ctx);pG(n,i().messages.attribution_orbits(),t.orbits),pG(r,i().messages.attribution_imagery(),t.imagery)})}),t}onRemove(){this.stop?.(),this.stop=null}getDefaultPosition(){return`bottom-right`}};function pG(e,t,n){if(e.hidden=n.length===0,e.hidden)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${t}:`,e.replaceChildren(r,` ${n.join(` · `)}`)}var mG=class{off=null;onAdd(e){let t=lG(),n=uG();t.append(dG(sG,`spacemap`,`sm-attribution__home`),n,dG(cG,i().messages.credits_see_all()));let r=()=>{let t=[...new Set(e.credits.map(e=>e.organisation))].filter(Boolean);if(n.hidden=t.length===0,n.hidden)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${i().messages.attribution_imagery()}:`,n.replaceChildren(r,` ${t.join(` · `)}`)};return r(),this.off=e.on(`layerschange`,r),t}onRemove(){this.off?.(),this.off=null}getDefaultPosition(){return`bottom-right`}};function hG(e){if(e)try{let t=typeof window<`u`?window.location.href:`https://spacemap.co`,{protocol:n}=new URL(e,t);return n===`http:`||n===`https:`?e:void 0}catch{return}}var gG=class{off=null;onAdd(e){let t=lG(),n=uG();t.append(dG(sG,`spacemap`,`sm-attribution__home`),n,dG(cG,i().messages.credits_see_all()));let r=()=>{let t=e.getCurrent();if(n.hidden=!t?.credit,!t?.credit)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${i().messages.attribution_imagery()}:`;let a=hG(t.credit_url),o=a?dG(a,t.credit):t.credit;n.replaceChildren(r,` `,o)};return r(),this.off=e.on(`load`,r),t}onRemove(){this.off?.(),this.off=null}getDefaultPosition(){return`bottom-right`}},_G=Math.PI/180,vG=Math.cos(ig*_G),yG=Math.sin(ig*_G);function bG(e){return e}function xG(e){let t=[...e.samples].sort((e,t)=>e.jd-t.jd);return{body:e.body??`naif-10`,offsetKm:e=>TG(t,e)}}function SG(e){return{body:e.body??`naif-10`,offsetKm:t=>kF(e.elements,t)?.r??null}}function CG(e,t){let n=tg(e,t);return n.error!==Qh.None&&console.warn(`spacemap: SGP4 will not take this element set (error=${n.error})`),{body:f_,offsetKm:e=>{if(n.error!==Qh.None)return null;let t=_g(n,e);return t&&wG(t[0],t[1],t[2])}}}function wG(e,t,n){return[e,t*vG+n*yG,-t*yG+n*vG]}function TG(e,t){let n=e.length;if(n<2||t<e[0].jd||t>e[n-1].jd)return null;let r=0,i=n-1;for(;r<i;){let n=r+i>>1;e[n].jd<t?r=n+1:i=n}let a=Math.max(r,1),o=e[a-1],s=e[a],c=s.jd-o.jd;if(c<=0)return s.km;let l=(t-o.jd)/c,u=l*l,d=u*l,f=2*d-3*u+1,p=d-2*u+l,m=-2*d+3*u,h=d-u,g=[0,0,0];for(let t=0;t<3;t++){let n=o.km[t],r=s.km[t],i=EG(e,a-1,t),l=EG(e,a,t);g[t]=f*n+p*c*i+m*r+h*c*l}return g}function EG(e,t,n){let r=e[t-1]??e[t],i=e[t+1]??e[t],a=i.jd-r.jd;return a<=0?0:(i.km[n]-r.km[n])/a}function DG(e){return e/rg}var OG=null,kG=Promise.resolve();function AG(e){let t=kG.then(e,e);return kG=t.catch(()=>{}),t}async function jG(e){let t=Mg(e),n=await Lb();if(!OG){let e=Rb(n);e.size>0&&(OG=new qb(e))}try{await OG?.ensure(t).done}catch(e){throw OG=null,e}return{jd:t,metadata:n,chebyshev:OG}}function MG(e,t){return!(e!==void 0&&t-2451545<e)}async function NG(e,{jd:t,metadata:n}){let r=n.position.zones.moons,i=r&&kb(r);if(!i)return null;let a=await cb(`moons`,null,0,Cb(i)?String(Tb(i,t)):null);for(let t=0;t<a.rowCount;t++)if(xh(a,t)===e)return $g(a,t,new Map,`naif`);return null}function PG(e,t){return!MG(e.visibleFromDays,t)||t<e.validityStart||t>e.validityEnd?null:e.satrec?yg(e.satrec,t):e.q==null?e.a===0?[0,0,0]:qv(e,t):Yv(e,t)}async function FG(e,t){let{jd:n}=t;if(t.chebyshev?.has(e)){let r=t.chebyshev.body(e,n);if(r&&!MG(r.visibleFromDays,n))return null;let i=r&&fy(r,n);if(i){let{radiusKm:e,objectType:t}=r;return{data:{radiusKm:e,objectType:t,orbitalSource:W.SPICE},parentId:`naif-${r.parentId}`,offset:i}}if(e.startsWith(`naif-`))return null}let r=(e.startsWith(`naif-`)?await NG(e,t):null)??xx(e,await mx(e,!1)),i=r&&PG(r,n);return i?{data:r,parentId:r.parentId,offset:i}:null}async function IG(e,t,n=new Set){if(n.has(e))return null;let r=await FG(e,t);if(!r)return null;if(r.parentId===`naif-0`)return{data:r.data,centre:r.offset};let i=await IG(r.parentId,t,new Set(n).add(e));if(!i)return null;let[a,o,s]=i.centre;return{data:r.data,centre:[a+r.offset[0],o+r.offset[1],s+r.offset[2]]}}async function LG(e){let[t]=await Promise.all([mx(e,!1),Y_()]),n=t.global?.orientation,r=t.global?.nut_prec,i=/^naif-(-?\d+)$/.exec(e),a=i?Z_(X_(parseInt(i[1],10))):void 0;return{orientation:n,nutPrec:r&&a?{...r,angles:a}:void 0}}async function RG(e,t){let n=await IG(e.body,t);if(!n)return null;let r=`latitude`in e?await LG(e.body):{};return vR(e,{data:n.data,...r},n.centre,t.jd)}function zG(e,t,n){return AG(async()=>{let r=await jG(n),i=await RG(e,r),a=i&&await RG(t,r);return i&&a?xR([a[0]-i[0],a[1]-i[1],a[2]-i[2]]):null})}async function BG(e,t,n){let r=await zG(e,t,n);return r&&Math.hypot(...r)}function VG(e,t){return AG(async()=>{if(e===`naif-10`)return null;let n=await jG(t),r=await IG(e,n),i=r&&await IG(`naif-10`,n);return!r||!i?null:TV({data:r.data,...await LG(e)},r.centre,i.centre,n.jd)})}var HG=null;function UG(e=G_){return HG||(HG=(async()=>{let t=await e(`${Wt()}/v1/panoramas.json`);if(!t.ok)throw Error(`Failed to load panoramas.json: ${t.status}`);return(await t.json()).bodies??[]})(),HG.catch(()=>HG=null),HG)}async function WG(e){return(await mx(e,!1)).global?.panoramas??[]}async function GG(e){let{container:t,dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o,controls:s,events:c,...l}=e,u=YG(t);XG({dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o});let d=new WV(l);if(d.mount(u),d.webglError)throw d.unmount(),Error(`spacemap: WebGL is not available`);for(let[e,t]of Object.entries(c??{}))d.on(e,t);d.attribution=new fG,d.addControl(d.attribution);for(let e of s??[])d.addControl(e);return await d.open(),d.applyInitialView(),await Ez(),d}async function KG(e){let{container:t,dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o,controls:s,events:c,...l}=e,u=YG(t);XG({dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o});let d=new JH(l);d.mount(u);for(let[e,t]of Object.entries(c??{}))d.on(e,t);d.attribution=new mG,d.addControl(d.attribution);for(let e of s??[])d.addControl(e);return await d.load(),d}async function qG(e){let{container:t,dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o,controls:s,events:c,...l}=e,u=YG(t);XG({dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o});let d=new MU(l);d.mount(u);for(let[e,t]of Object.entries(c??{}))d.on(e,t);d.attribution=new gG,d.addControl(d.attribution);for(let e of s??[])d.addControl(e);return await d.load(),d}async function JG(e){let{container:t,dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o,events:s,...c}=e,l=YG(t);XG({dataUrl:n,imagesUrl:r,locale:i,messages:a,includeNonCommercial:o});let u=new tG(c);u.mount(l);for(let[e,t]of Object.entries(s??{}))u.on(e,t);try{await u.load()}catch(e){throw u.remove(),e}return u}function YG(e){if(typeof e!=`string`)return e;let t=document.querySelector(e);if(!(t instanceof HTMLElement))throw Error(`spacemap: no element matches ${e}`);return t}function XG(e){let t={};e.dataUrl!==void 0&&(t.dataUrl=e.dataUrl),e.imagesUrl!==void 0&&(t.imagesUrl=e.imagesUrl),e.locale!==void 0&&(t.locale=()=>e.locale),e.messages!==void 0&&(t.messages=e.messages),e.includeNonCommercial&&(t.textures=`non-commercial`),r(t)}export{fG as AttributionControl,mG as FlatAttributionControl,JH as FlatMap,DV as GestureHandler,hv as MAP_LAYERS,UB as PROJECTION_IDS,gG as PanoramaAttributionControl,MU as PanoramaView,WV as SpaceMap,tG as SystemMap,NH as Viewport,pU as bearingDeg,dV as boxRing,Gz as circlePoints,r as configureHost,KG as createFlatMap,GG as createMap,qG as createPanorama,WB as createProjection,JG as createSystemMap,Mg as dateToJD,kx as defaultSceneSettings,BG as distanceKm,SG as elements,UG as fetchPanoramaIndex,WG as fetchPanoramas,lU as findPanorama,bG as fixed,mV as graticule,fU as groundDistanceM,px as isViewable,Ng as jdToDate,DG as kmToAu,uU as neighboursOf,zG as offsetKm,sU as panoramaAt,sV as pathFor,Uz as planeBasis,lB as projectionAspect,xG as samples,fV as smallCircle,VG as subsolarPoint,CG as tle};
5568
5568
  //# sourceMappingURL=spacemap.js.map
5569
- (function(){if(typeof document==='undefined')return;var s=document.createElement('style');s.textContent=".scene-label{pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;color:inherit;touch-action:none;z-index:1;width:32px;height:32px;text-decoration:none;display:block;position:relative;left:0}.scene-label__halo{border-radius:50%;width:100%;height:100%;transition:transform .1s}.scene-label__halo--spacecraft,.scene-label__halo--debris{overflow:visible}.scene-label__loader{box-sizing:border-box;pointer-events:none;border:2px solid #fff;border-color:#fff #fff #fff3 #fff3;border-radius:50%;width:32px;height:32px;margin:auto;animation:.9s linear infinite scene-label-loader-spin;position:fixed;inset:0}@keyframes scene-label-loader-spin{to{transform:rotate(360deg)}}.reduce-motion .scene-label__loader{animation-duration:.9s!important;animation-iteration-count:infinite!important}.scene-label__name{white-space:nowrap;pointer-events:auto;cursor:pointer;color:#fff;text-shadow:0 0 4px #000,0 0 4px #000;padding-left:8px;font-size:14px;font-weight:700;text-decoration:none;position:absolute;top:50%;left:32px;transform:translateY(-50%)}.scene-label__name--large{font-size:16px}.scene-label__annotations{top:28px;pointer-events:none;flex-direction:column;padding-inline-start:8px;display:flex;position:absolute;inset-inline-start:32px}.scene-label__annotation{opacity:0;white-space:nowrap;color:#fff9;text-shadow:0 0 3px #000,0 0 3px #000;transition:opacity .15s, display .15s allow-discrete;font-size:11px;line-height:1.3;display:none}.scene-label__annotation--visible{opacity:1;display:block}@starting-style{.scene-label__annotation--visible{opacity:0}}.scene-feature-label{color:#ffffffb3;white-space:nowrap;pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;text-shadow:0 0 2px #000,0 0 2px #000;z-index:0;font-size:12px;transition:color .1s;left:0}.scene-feature-label:hover{color:#fff;text-shadow:0 0 3px #000,0 0 3px #000}.scene-feature-label--active{color:#fff;font-size:14px;font-weight:600}.scene-path-label{color:#fff;font:inherit;white-space:nowrap;text-align:start;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;touch-action:none;z-index:2;background:0 0;border:0;align-items:center;gap:8px;padding:0;line-height:1.15;display:flex;left:0}.scene-path-label--static{pointer-events:none;cursor:default}.scene-path-label__halo{border-radius:50%;flex-shrink:0;width:32px;height:32px;margin-inline-start:-16px;transition:transform .1s}.scene-path-label:hover .scene-path-label__halo{transform:scale(1.15)}.scene-path-label__text{flex-direction:column;gap:1px;display:flex}.scene-path-label__name{font-size:14px;font-weight:700}.scene-path-label__when{opacity:.8;font-variant-numeric:tabular-nums;font-size:12px}.scene-path-label--dim .scene-path-label__text{display:none}.scene-path-label--dim .scene-path-label__halo{transform:scale(.55)}.scene-path-label--dim:hover .scene-path-label__halo{transform:scale(.75)}.scene-path-label--step .scene-path-label__halo{background:0 0;border:0}.scene-path-label--step:hover .scene-path-label__halo{background:#ffffff1f}.scene-path-label--step .scene-path-label__name{font-size:12px;font-weight:600}.scene-path-label--step .scene-path-label__when{font-size:11px}.scene-path-label__hazard{font-size:11px;font-weight:700}.scene-path-label--lit{color:#fff}.scene-path-label--lit .scene-path-label__halo{transform:scale(1.15)}.scene-path-label--lit.scene-path-label--dim .scene-path-label__halo{transform:scale(.75)}.scene-path-label--faint .scene-path-label__text{display:none}.scene-path-label--faint .scene-path-label__halo{opacity:.45;transform:scale(.5)}.scene-path-label--faint:hover .scene-path-label__halo{opacity:1;transform:scale(.75)}.scene-overlay--no-names .scene-label__name,.scene-overlay--no-names .scene-label__annotations{display:none}.scene-overlay--no-halos .scene-label__halo{visibility:hidden}.scene-overlay--no-halos .scene-label{pointer-events:none}.scene-hazard-label{white-space:nowrap;pointer-events:none;-webkit-user-select:none;user-select:none;text-shadow:0 0 4px #000,0 0 4px #000;margin-inline-start:16px;font-size:12px;font-weight:700;position:relative;left:0}.user-location-marker{pointer-events:none;background:#1a73e8;border:2px solid #fff;border-radius:50%;width:16px;height:16px;box-shadow:0 0 6px #0006}.sm-drawing-label{white-space:nowrap;color:#fff;text-shadow:0 0 4px #000,0 0 4px #000;-webkit-user-select:none;user-select:none;pointer-events:none;font:700 14px/1.2 system-ui,sans-serif}.sm-drawing-icon{-webkit-user-select:none;user-select:none;pointer-events:none;display:block}.sm-drawing--interactive{pointer-events:auto;cursor:pointer;touch-action:none}.sm-cooperative-hint{z-index:4;color:#fff;text-align:center;pointer-events:none;opacity:0;background:#0000008c;place-content:center;padding:16px;font:15px/1.4 system-ui,sans-serif;transition:opacity .2s;display:grid;position:absolute;inset:0}.sm-cooperative-hint--shown{opacity:1}@media (prefers-reduced-motion:reduce){.sm-cooperative-hint{transition:none}}.sm-ctrl{z-index:2;pointer-events:none;flex-direction:column;gap:6px;max-width:100%;padding:6px;display:flex;position:absolute}.sm-ctrl>*{pointer-events:auto}.sm-ctrl--top-left{align-items:flex-start;top:0;left:0}.sm-ctrl--top-right{align-items:flex-end;top:0;right:0}.sm-ctrl--bottom-left{align-items:flex-start;bottom:0;left:0}.sm-ctrl--bottom-right{align-items:flex-end;bottom:0;right:0}.sm-map{-webkit-user-select:none;user-select:none}:where(.sm-map){width:100%;height:100%;position:relative}.sm-map__canvas{pointer-events:auto;touch-action:none;width:100%;height:100%;display:block}.sm-map__canvas:focus-visible{outline:2px solid var(--ring,Highlight)}.sm-map .scene-overlay{pointer-events:none;z-index:0;position:absolute;inset:0}.sm-flat{touch-action:none;background:#05070e;width:100%;height:100%;position:relative;overflow:hidden}.sm-flat__raster,.sm-flat__vector,.sm-flat__markers{width:100%;height:100%;position:absolute;inset:0}.sm-flat__raster{display:block}.sm-flat__vector,.sm-flat__markers{pointer-events:none}.sm-flat--interactive{cursor:grab}.sm-flat--cooperative{touch-action:pan-x pan-y}.sm-flat--dragging{cursor:grabbing}.sm-flat__graticule{fill:none;stroke:#ffffff47;stroke-width:1px}.sm-flat__frame{fill:none;stroke:#ffffff73;stroke-width:1px}.sm-flat__feature-dot{fill:#fffc}.sm-flat__feature-label{fill:#ffffffd9;paint-order:stroke;stroke:#000000a6;stroke-width:2.5px;font:10px/1 system-ui,sans-serif}.sm-flat__marker-dot{background:#4ea3ff;border:2px solid #fff;border-radius:50%;width:10px;height:10px;box-shadow:0 0 0 1px #00000073}.sm-system-map{border-radius:var(--sm-system-map-radius,6px);background:var(--sm-system-map-background,#ffffff0d);width:100%;color:var(--sm-system-map-ink,#ffffff9e);position:relative;overflow:hidden}.sm-system-map--background{pointer-events:none;background:0 0;border-radius:0;height:100%}.sm-system-map__svg{touch-action:pan-y;width:100%;height:auto;display:block}.sm-system-map--background .sm-system-map__svg{height:100%}.sm-system-map__svg--near :is(a,.sm-system-map__button):not([data-near]){pointer-events:none}.sm-system-map__button{cursor:pointer}.sm-system-map__button:focus{outline:none}.sm-system-map__reference{opacity:.6}.sm-system-map__band--muted{color:var(--sm-system-map-ink,#ffffff9e)}.sm-system-map__band--sky{color:var(--sm-system-map-sky,oklch(74.6% .16 232.661/.7))}.sm-system-map__band--amber{color:var(--sm-system-map-amber,oklch(92.4% .12 95.746/.8))}.sm-system-map__band-label{font-weight:600}.sm-system-map__band-label--muted{fill:var(--sm-system-map-ink,#ffffff9e)}.sm-system-map__band-label--sky{fill:var(--sm-system-map-sky-label,oklch(74.6% .16 232.661))}.sm-system-map__band-label--amber{fill:var(--sm-system-map-amber-label,oklch(92.4% .12 95.746/.9))}.sm-system-map__tip{z-index:10;background:var(--sm-system-map-tip-background,#0a0c14e6);width:max-content;color:var(--sm-system-map-tip-ink,#fffffff2);white-space:nowrap;pointer-events:none;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border-radius:.25rem;padding:.25rem .5rem;font-size:.75rem;line-height:1.33333;position:absolute;transform:translate(-50%);box-shadow:0 1px 3px #0000001a,0 1px 2px -1px #0000001a}.sm-system-map__tip[hidden]{display:none}.sm-system-map__tip-title{font-weight:500}.sm-system-map__tip-sub{color:var(--sm-system-map-ink,#ffffff9e)}.sm-ctrl:has(>.sm-attribution:only-child){padding:0}.sm-ctrl--top-left:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 0 var(--sm-attribution-radius) 0}.sm-ctrl--top-right:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 0 0 var(--sm-attribution-radius)}.sm-ctrl--bottom-left:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 var(--sm-attribution-radius) 0 0}.sm-ctrl--bottom-right:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:var(--sm-attribution-radius) 0 0 0}.sm-attribution{--sm-attribution-radius:3px;border-radius:var(--sm-attribution-radius);color:#ffffffbf;white-space:nowrap;background:#0006;align-items:center;gap:.5em;max-width:100%;padding:1px 6px;font:11px/1.45 system-ui,sans-serif;display:flex}.sm-attribution a{color:inherit;text-decoration:none}.sm-attribution a:hover{color:#fff;text-decoration:underline}.sm-attribution__home{font-weight:600}.sm-attribution__group{text-overflow:ellipsis;overflow:hidden}.sm-attribution__label{color:#ffffff80}\n/*$vite$:1*/";document.head.appendChild(s);})();
5569
+ (function(){if(typeof document==='undefined')return;var s=document.createElement('style');s.textContent=".scene-label{pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;color:inherit;touch-action:none;z-index:1;width:32px;height:32px;text-decoration:none;display:block;position:relative;left:0}.scene-label__halo{border-radius:50%;width:100%;height:100%;transition:transform .1s}.scene-label__halo--spacecraft,.scene-label__halo--debris{overflow:visible}.scene-label__loader{box-sizing:border-box;pointer-events:none;border:2px solid #fff;border-color:#fff #fff #fff3 #fff3;border-radius:50%;width:32px;height:32px;margin:auto;animation:.9s linear infinite scene-label-loader-spin;position:fixed;inset:0}@keyframes scene-label-loader-spin{to{transform:rotate(360deg)}}.reduce-motion .scene-label__loader{animation-duration:.9s!important;animation-iteration-count:infinite!important}.scene-label__name{white-space:nowrap;pointer-events:auto;cursor:pointer;color:#fff;text-shadow:0 0 4px #000,0 0 4px #000;padding-left:8px;font-size:14px;font-weight:700;text-decoration:none;position:absolute;top:50%;left:32px;transform:translateY(-50%)}.scene-label__name--large{font-size:16px}.scene-label__annotations{top:28px;pointer-events:none;flex-direction:column;padding-inline-start:8px;display:flex;position:absolute;inset-inline-start:32px}.scene-label__annotation{opacity:0;white-space:nowrap;color:#fff9;text-shadow:0 0 3px #000,0 0 3px #000;transition:opacity .15s, display .15s allow-discrete;font-size:11px;line-height:1.3;display:none}.scene-label__annotation--visible{opacity:1;display:block}@starting-style{.scene-label__annotation--visible{opacity:0}}.scene-feature-label{color:#ffffffb3;white-space:nowrap;pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;text-shadow:0 0 2px #000,0 0 2px #000;z-index:0;font-size:12px;transition:color .1s;left:0}.scene-feature-label:hover{color:#fff;text-shadow:0 0 3px #000,0 0 3px #000}.scene-feature-label--active{color:#fff;font-size:14px;font-weight:600}.scene-path-label{color:#fff;font:inherit;white-space:nowrap;text-align:start;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;touch-action:none;z-index:2;background:0 0;border:0;align-items:center;gap:8px;padding:0;line-height:1.15;display:flex;left:0}.scene-path-label--static{pointer-events:none;cursor:default}.scene-path-label__halo{border-radius:50%;flex-shrink:0;width:32px;height:32px;margin-inline-start:-16px;transition:transform .1s}.scene-path-label:hover .scene-path-label__halo{transform:scale(1.15)}.scene-path-label__text{flex-direction:column;gap:1px;display:flex}.scene-path-label__name{font-size:14px;font-weight:700}.scene-path-label__when{opacity:.8;font-variant-numeric:tabular-nums;font-size:12px}.scene-path-label--dim .scene-path-label__text{display:none}.scene-path-label--dim .scene-path-label__halo{transform:scale(.55)}.scene-path-label--dim:hover .scene-path-label__halo{transform:scale(.75)}.scene-path-label--step .scene-path-label__halo{background:0 0;border:0}.scene-path-label--step:hover .scene-path-label__halo{background:#ffffff1f}.scene-path-label--step .scene-path-label__name{font-size:12px;font-weight:600}.scene-path-label--step .scene-path-label__when{font-size:11px}.scene-path-label__hazard{font-size:11px;font-weight:700}.scene-path-label--lit{color:#fff}.scene-path-label--lit .scene-path-label__halo{transform:scale(1.15)}.scene-path-label--lit.scene-path-label--dim .scene-path-label__halo{transform:scale(.75)}.scene-path-label--faint .scene-path-label__text{display:none}.scene-path-label--faint .scene-path-label__halo{opacity:.45;transform:scale(.5)}.scene-path-label--faint:hover .scene-path-label__halo{opacity:1;transform:scale(.75)}.scene-overlay--no-names .scene-label__name,.scene-overlay--no-names .scene-label__annotations{display:none}.scene-overlay--no-halos .scene-label__halo{visibility:hidden}.scene-overlay--no-halos .scene-label{pointer-events:none}.scene-hazard-label{white-space:nowrap;pointer-events:none;-webkit-user-select:none;user-select:none;text-shadow:0 0 4px #000,0 0 4px #000;margin-inline-start:16px;font-size:12px;font-weight:700;position:relative;left:0}.user-location-marker{pointer-events:none;background:#1a73e8;border:2px solid #fff;border-radius:50%;width:16px;height:16px;box-shadow:0 0 6px #0006}.sm-drawing-label{white-space:nowrap;color:#fff;text-shadow:0 0 4px #000,0 0 4px #000;-webkit-user-select:none;user-select:none;pointer-events:none;font:700 14px/1.2 system-ui,sans-serif}.sm-drawing-icon{-webkit-user-select:none;user-select:none;pointer-events:none;display:block}.sm-drawing--interactive{pointer-events:auto;cursor:pointer;touch-action:none}.sm-cooperative-hint{z-index:4;color:#fff;text-align:center;pointer-events:none;opacity:0;background:#0000008c;place-content:center;padding:16px;font:15px/1.4 system-ui,sans-serif;transition:opacity .2s;display:grid;position:absolute;inset:0}.sm-cooperative-hint--shown{opacity:1}@media (prefers-reduced-motion:reduce){.sm-cooperative-hint{transition:none}}.sm-ctrl{z-index:2;box-sizing:border-box;pointer-events:none;flex-direction:column;gap:6px;max-width:100%;padding:6px;display:flex;position:absolute}.sm-ctrl>*{pointer-events:auto}.sm-ctrl--top-left{align-items:flex-start;top:0;left:0}.sm-ctrl--top-right{align-items:flex-end;top:0;right:0}.sm-ctrl--bottom-left{align-items:flex-start;bottom:0;left:0}.sm-ctrl--bottom-right{align-items:flex-end;bottom:0;right:0}.sm-map{-webkit-user-select:none;user-select:none}:where(.sm-map){width:100%;height:100%;position:relative}.sm-map__canvas{pointer-events:auto;touch-action:none;width:100%;height:100%;display:block}.sm-map__canvas:focus-visible{outline:2px solid var(--ring,Highlight)}.sm-map .scene-overlay{pointer-events:none;z-index:0;position:absolute;inset:0}.sm-flat{touch-action:none;background:#05070e;width:100%;height:100%;position:relative;overflow:hidden}.sm-flat__raster,.sm-flat__vector,.sm-flat__markers{width:100%;height:100%;position:absolute;inset:0}.sm-flat__raster{display:block}.sm-flat__vector,.sm-flat__markers{pointer-events:none}.sm-flat--interactive{cursor:grab}.sm-flat--cooperative{touch-action:pan-x pan-y}.sm-flat--dragging{cursor:grabbing}.sm-flat__graticule{fill:none;stroke:#ffffff47;stroke-width:1px}.sm-flat__frame{fill:none;stroke:#ffffff73;stroke-width:1px}.sm-flat__feature-dot{fill:#fffc}.sm-flat__feature-label{fill:#ffffffd9;paint-order:stroke;stroke:#000000a6;stroke-width:2.5px;font:10px/1 system-ui,sans-serif}.sm-flat__marker-dot{background:#4ea3ff;border:2px solid #fff;border-radius:50%;width:10px;height:10px;box-shadow:0 0 0 1px #00000073}.sm-system-map{border-radius:var(--sm-system-map-radius,6px);background:var(--sm-system-map-background,#ffffff0d);width:100%;color:var(--sm-system-map-ink,#ffffff9e);position:relative;overflow:hidden}.sm-system-map--background{pointer-events:none;background:0 0;border-radius:0;height:100%}.sm-system-map__svg{touch-action:pan-y;width:100%;height:auto;display:block}.sm-system-map--background .sm-system-map__svg{height:100%}.sm-system-map__svg--near :is(a,.sm-system-map__button):not([data-near]){pointer-events:none}.sm-system-map__button{cursor:pointer}.sm-system-map__button:focus{outline:none}.sm-system-map__reference{opacity:.6}.sm-system-map__band--muted{color:var(--sm-system-map-ink,#ffffff9e)}.sm-system-map__band--sky{color:var(--sm-system-map-sky,oklch(74.6% .16 232.661/.7))}.sm-system-map__band--amber{color:var(--sm-system-map-amber,oklch(92.4% .12 95.746/.8))}.sm-system-map__band-label{font-weight:600}.sm-system-map__band-label--muted{fill:var(--sm-system-map-ink,#ffffff9e)}.sm-system-map__band-label--sky{fill:var(--sm-system-map-sky-label,oklch(74.6% .16 232.661))}.sm-system-map__band-label--amber{fill:var(--sm-system-map-amber-label,oklch(92.4% .12 95.746/.9))}.sm-system-map__tip{z-index:10;background:var(--sm-system-map-tip-background,#0a0c14e6);width:max-content;color:var(--sm-system-map-tip-ink,#fffffff2);white-space:nowrap;pointer-events:none;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border-radius:.25rem;padding:.25rem .5rem;font-size:.75rem;line-height:1.33333;position:absolute;transform:translate(-50%);box-shadow:0 1px 3px #0000001a,0 1px 2px -1px #0000001a}.sm-system-map__tip[hidden]{display:none}.sm-system-map__tip-title{font-weight:500}.sm-system-map__tip-sub{color:var(--sm-system-map-ink,#ffffff9e)}.sm-ctrl:has(>.sm-attribution:only-child){padding:0}.sm-ctrl--top-left:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 0 var(--sm-attribution-radius) 0}.sm-ctrl--top-right:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 0 0 var(--sm-attribution-radius)}.sm-ctrl--bottom-left:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 var(--sm-attribution-radius) 0 0}.sm-ctrl--bottom-right:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:var(--sm-attribution-radius) 0 0 0}.sm-attribution{--sm-attribution-radius:3px;box-sizing:border-box;border-radius:var(--sm-attribution-radius);color:#ffffffbf;white-space:nowrap;background:#0006;align-items:center;gap:.5em;max-width:100%;padding:1px 6px;font:11px/1.45 system-ui,sans-serif;display:flex}.sm-attribution a{color:inherit;text-decoration:none}.sm-attribution a:hover{color:#fff;text-decoration:underline}.sm-attribution__home{font-weight:600}.sm-attribution__group{text-overflow:ellipsis;overflow:hidden}.sm-attribution__label{color:#ffffff80}\n/*$vite$:1*/";document.head.appendChild(s);})();