spacemap 0.1.10 → 0.1.11

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
@@ -4048,8 +4048,8 @@ void main() {
4048
4048
  }
4049
4049
 
4050
4050
  }`,rh=class{constructor(){this.texture=null,this.mesh=null,this.depthNear=0,this.depthFar=0}init(e,t){if(this.texture===null){let n=new Lc(e.texture);(e.depthNear!==t.depthNear||e.depthFar!==t.depthFar)&&(this.depthNear=e.depthNear,this.depthFar=e.depthFar),this.texture=n}}getMesh(e){if(this.texture!==null&&this.mesh===null){let t=e.cameras[0].viewport,n=new pu({vertexShader:th,fragmentShader:nh,uniforms:{depthColor:{value:this.texture},depthWidth:{value:t.z},depthHeight:{value:t.w}}});this.mesh=new js(new eu(20,20),n)}return this.mesh}reset(){this.texture=null,this.mesh=null}getDepthTexture(){return this.texture}},ih=class extends hi{constructor(e,t){super();let n=this,r=null,i=1,a=null,o=`local-floor`,s=1,c=null,l=null,u=null,d=null,f=null,p=null,m=typeof XRWebGLBinding<`u`,h=new rh,g={},_=t.getContextAttributes(),v=null,y=null,b=[],x=[],S=new q,C=null,w=new cd;w.viewport=new ca;let T=new cd;T.viewport=new ca;let E=[w,T],D=new Cd,O=null,k=null;this.cameraAutoUpdate=!0,this.enabled=!1,this.isPresenting=!1,this.getController=function(e){let t=b[e];return t===void 0&&(t=new Ha,b[e]=t),t.getTargetRaySpace()},this.getControllerGrip=function(e){let t=b[e];return t===void 0&&(t=new Ha,b[e]=t),t.getGripSpace()},this.getHand=function(e){let t=b[e];return t===void 0&&(t=new Ha,b[e]=t),t.getHandSpace()};function A(e){let t=x.indexOf(e.inputSource);if(t===-1)return;let n=b[t];n!==void 0&&(n.update(e.inputSource,e.frame,c||a),n.dispatchEvent({type:e.type,data:e.inputSource}))}function j(){r.removeEventListener(`select`,A),r.removeEventListener(`selectstart`,A),r.removeEventListener(`selectend`,A),r.removeEventListener(`squeeze`,A),r.removeEventListener(`squeezestart`,A),r.removeEventListener(`squeezeend`,A),r.removeEventListener(`end`,j),r.removeEventListener(`inputsourceschange`,M);for(let e=0;e<b.length;e++){let t=x[e];t!==null&&(x[e]=null,b[e].disconnect(t))}O=null,k=null,h.reset();for(let e in g)delete g[e];e.setRenderTarget(v),f=null,d=null,u=null,r=null,y=null,ae.stop(),n.isPresenting=!1,e.setPixelRatio(C),e.setSize(S.width,S.height,!1),n.dispatchEvent({type:`sessionend`})}this.setFramebufferScaleFactor=function(e){i=e,n.isPresenting===!0&&K(`WebXRManager: Cannot change framebuffer scale while presenting.`)},this.setReferenceSpaceType=function(e){o=e,n.isPresenting===!0&&K(`WebXRManager: Cannot change reference space type while presenting.`)},this.getReferenceSpace=function(){return c||a},this.setReferenceSpace=function(e){c=e},this.getBaseLayer=function(){return d===null?f:d},this.getBinding=function(){return u===null&&m&&(u=new XRWebGLBinding(r,t)),u},this.getFrame=function(){return p},this.getSession=function(){return r},this.setSession=async function(l){if(r=l,r!==null){if(v=e.getRenderTarget(),r.addEventListener(`select`,A),r.addEventListener(`selectstart`,A),r.addEventListener(`selectend`,A),r.addEventListener(`squeeze`,A),r.addEventListener(`squeezestart`,A),r.addEventListener(`squeezeend`,A),r.addEventListener(`end`,j),r.addEventListener(`inputsourceschange`,M),_.xrCompatible!==!0&&await t.makeXRCompatible(),C=e.getPixelRatio(),e.getSize(S),m&&`createProjectionLayer`in XRWebGLBinding.prototype){let n=null,a=null,o=null;_.depth&&(o=_.stencil?t.DEPTH24_STENCIL8:t.DEPTH_COMPONENT24,n=_.stencil?$n:Qn,a=_.stencil?Kn:Vn);let s={colorFormat:t.RGBA8,depthFormat:o,scaleFactor:i};u=this.getBinding(),d=u.createProjectionLayer(s),r.updateRenderState({layers:[d]}),e.setPixelRatio(1),e.setSize(d.textureWidth,d.textureHeight,!1),y=new ua(d.textureWidth,d.textureHeight,{format:Zn,type:In,depthTexture:new Fc(d.textureWidth,d.textureHeight,a,void 0,void 0,void 0,void 0,void 0,void 0,n),stencilBuffer:_.stencil,colorSpace:e.outputColorSpace,samples:_.antialias?4:0,resolveDepthBuffer:d.ignoreDepthValues===!1,resolveStencilBuffer:d.ignoreDepthValues===!1})}else{let n={antialias:_.antialias,alpha:!0,depth:_.depth,stencil:_.stencil,framebufferScaleFactor:i};f=new XRWebGLLayer(r,t,n),r.updateRenderState({baseLayer:f}),e.setPixelRatio(1),e.setSize(f.framebufferWidth,f.framebufferHeight,!1),y=new ua(f.framebufferWidth,f.framebufferHeight,{format:Zn,type:In,colorSpace:e.outputColorSpace,stencilBuffer:_.stencil,resolveDepthBuffer:f.ignoreDepthValues===!1,resolveStencilBuffer:f.ignoreDepthValues===!1})}y.isXRRenderTarget=!0,this.setFoveation(s),c=null,a=await r.requestReferenceSpace(o),ae.setContext(r),ae.start(),n.isPresenting=!0,n.dispatchEvent({type:`sessionstart`})}},this.getEnvironmentBlendMode=function(){if(r!==null)return r.environmentBlendMode},this.getDepthTexture=function(){return h.getDepthTexture()};function M(e){for(let t=0;t<e.removed.length;t++){let n=e.removed[t],r=x.indexOf(n);r>=0&&(x[r]=null,b[r].disconnect(n))}for(let t=0;t<e.added.length;t++){let n=e.added[t],r=x.indexOf(n);if(r===-1){for(let e=0;e<b.length;e++)if(e>=x.length){x.push(n),r=e;break}else if(x[e]===null){x[e]=n,r=e;break}if(r===-1)break}let i=b[r];i&&i.connect(n)}}let ee=new J,N=new J;function te(e,t,n){ee.setFromMatrixPosition(t.matrixWorld),N.setFromMatrixPosition(n.matrixWorld);let r=ee.distanceTo(N),i=t.projectionMatrix.elements,a=n.projectionMatrix.elements,o=i[14]/(i[10]-1),s=i[14]/(i[10]+1),c=(i[9]+1)/i[5],l=(i[9]-1)/i[5],u=(i[8]-1)/i[0],d=(a[8]+1)/a[0],f=o*u,p=o*d,m=r/(-u+d),h=m*-u;if(t.matrixWorld.decompose(e.position,e.quaternion,e.scale),e.translateX(h),e.translateZ(m),e.matrixWorld.compose(e.position,e.quaternion,e.scale),e.matrixWorldInverse.copy(e.matrixWorld).invert(),i[10]===-1)e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse);else{let t=o+m,n=s+m,i=f-h,a=p+(r-h),u=c*s/n*t,d=l*s/n*t;e.projectionMatrix.makePerspective(i,a,u,d,t,n),e.projectionMatrixInverse.copy(e.projectionMatrix).invert()}}function ne(e,t){t===null?e.matrixWorld.copy(e.matrix):e.matrixWorld.multiplyMatrices(t.matrixWorld,e.matrix),e.matrixWorldInverse.copy(e.matrixWorld).invert()}this.updateCamera=function(e){if(r===null)return;let t=e.near,n=e.far;h.texture!==null&&(h.depthNear>0&&(t=h.depthNear),h.depthFar>0&&(n=h.depthFar)),D.near=T.near=w.near=t,D.far=T.far=w.far=n,(O!==D.near||k!==D.far)&&(r.updateRenderState({depthNear:D.near,depthFar:D.far}),O=D.near,k=D.far),D.layers.mask=e.layers.mask|6,w.layers.mask=D.layers.mask&-5,T.layers.mask=D.layers.mask&-3;let i=e.parent,a=D.cameras;ne(D,i);for(let e=0;e<a.length;e++)ne(a[e],i);a.length===2?te(D,w,T):D.projectionMatrix.copy(w.projectionMatrix),re(e,D,i)};function re(e,t,n){n===null?e.matrix.copy(t.matrixWorld):(e.matrix.copy(n.matrixWorld),e.matrix.invert(),e.matrix.multiply(t.matrixWorld)),e.matrix.decompose(e.position,e.quaternion,e.scale),e.updateMatrixWorld(!0),e.projectionMatrix.copy(t.projectionMatrix),e.projectionMatrixInverse.copy(t.projectionMatrixInverse),e.isPerspectiveCamera&&(e.fov=yi*2*Math.atan(1/e.projectionMatrix.elements[5]),e.zoom=1)}this.getCamera=function(){return D},this.getFoveation=function(){if(!(d===null&&f===null))return s},this.setFoveation=function(e){s=e,d!==null&&(d.fixedFoveation=e),f!==null&&f.fixedFoveation!==void 0&&(f.fixedFoveation=e)},this.hasDepthSensing=function(){return h.texture!==null},this.getDepthSensingMesh=function(){return h.getMesh(D)},this.getCameraTexture=function(e){return g[e]};let P=null;function ie(t,i){if(l=i.getViewerPose(c||a),p=i,l!==null){let t=l.views;f!==null&&(e.setRenderTargetFramebuffer(y,f.framebuffer),e.setRenderTarget(y));let i=!1;t.length!==D.cameras.length&&(D.cameras.length=0,i=!0);for(let n=0;n<t.length;n++){let r=t[n],a=null;if(f!==null)a=f.getViewport(r);else{let t=u.getViewSubImage(d,r);a=t.viewport,n===0&&(e.setRenderTargetTextures(y,t.colorTexture,t.depthStencilTexture),e.setRenderTarget(y))}let o=E[n];o===void 0&&(o=new cd,o.layers.enable(n),o.viewport=new ca,E[n]=o),o.matrix.fromArray(r.transform.matrix),o.matrix.decompose(o.position,o.quaternion,o.scale),o.projectionMatrix.fromArray(r.projectionMatrix),o.projectionMatrixInverse.copy(o.projectionMatrix).invert(),o.viewport.set(a.x,a.y,a.width,a.height),n===0&&(D.matrix.copy(o.matrix),D.matrix.decompose(D.position,D.quaternion,D.scale)),i===!0&&D.cameras.push(o)}let a=r.enabledFeatures;if(a&&a.includes(`depth-sensing`)&&r.depthUsage==`gpu-optimized`&&m){u=n.getBinding();let e=u.getDepthInformation(t[0]);e&&e.isValid&&e.texture&&h.init(e,r.renderState)}if(a&&a.includes(`camera-access`)&&m){e.state.unbindTexture(),u=n.getBinding();for(let e=0;e<t.length;e++){let n=t[e].camera;if(n){let e=g[n];e||(e=new Lc,g[n]=e);let t=u.getCameraImage(n);e.sourceTexture=t}}}}for(let e=0;e<b.length;e++){let t=x[e],n=b[e];t!==null&&n!==void 0&&n.update(t,i,c||a)}P&&P(t,i),i.detectedPlanes&&n.dispatchEvent({type:`planesdetected`,data:i}),p=null}let ae=new Xd;ae.setAnimationLoop(ie),this.setAnimationLoop=function(e){P=e},this.dispose=function(){}}},ah=new Sa,oh=new Y;function sh(e,t){function n(e,t){e.matrixAutoUpdate===!0&&e.updateMatrix(),t.value.copy(e.matrix)}function r(t,n){n.color.getRGB(t.fogColor.value,lu(e)),n.isFog?(t.fogNear.value=n.near,t.fogFar.value=n.far):n.isFogExp2&&(t.fogDensity.value=n.density)}function i(e,t,n,r,i){t.isMeshBasicMaterial?a(e,t):t.isMeshLambertMaterial?(a(e,t),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)):t.isMeshToonMaterial?(a(e,t),d(e,t)):t.isMeshPhongMaterial?(a(e,t),u(e,t),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)):t.isMeshStandardMaterial?(a(e,t),f(e,t),t.isMeshPhysicalMaterial&&p(e,t,i)):t.isMeshMatcapMaterial?(a(e,t),m(e,t)):t.isMeshDepthMaterial?a(e,t):t.isMeshDistanceMaterial?(a(e,t),h(e,t)):t.isMeshNormalMaterial?a(e,t):t.isLineBasicMaterial?(o(e,t),t.isLineDashedMaterial&&s(e,t)):t.isPointsMaterial?c(e,t,n,r):t.isSpriteMaterial?l(e,t):t.isShadowMaterial?(e.color.value.copy(t.color),e.opacity.value=t.opacity):t.isShaderMaterial&&(t.uniformsNeedUpdate=!1)}function a(e,r){e.opacity.value=r.opacity,r.color&&e.diffuse.value.copy(r.color),r.emissive&&e.emissive.value.copy(r.emissive).multiplyScalar(r.emissiveIntensity),r.map&&(e.map.value=r.map,n(r.map,e.mapTransform)),r.alphaMap&&(e.alphaMap.value=r.alphaMap,n(r.alphaMap,e.alphaMapTransform)),r.bumpMap&&(e.bumpMap.value=r.bumpMap,n(r.bumpMap,e.bumpMapTransform),e.bumpScale.value=r.bumpScale,r.side===1&&(e.bumpScale.value*=-1)),r.normalMap&&(e.normalMap.value=r.normalMap,n(r.normalMap,e.normalMapTransform),e.normalScale.value.copy(r.normalScale),r.side===1&&e.normalScale.value.negate()),r.displacementMap&&(e.displacementMap.value=r.displacementMap,n(r.displacementMap,e.displacementMapTransform),e.displacementScale.value=r.displacementScale,e.displacementBias.value=r.displacementBias),r.emissiveMap&&(e.emissiveMap.value=r.emissiveMap,n(r.emissiveMap,e.emissiveMapTransform)),r.specularMap&&(e.specularMap.value=r.specularMap,n(r.specularMap,e.specularMapTransform)),r.alphaTest>0&&(e.alphaTest.value=r.alphaTest);let i=t.get(r),a=i.envMap,o=i.envMapRotation;a&&(e.envMap.value=a,ah.copy(o),ah.x*=-1,ah.y*=-1,ah.z*=-1,a.isCubeTexture&&a.isRenderTargetTexture===!1&&(ah.y*=-1,ah.z*=-1),e.envMapRotation.value.setFromMatrix4(oh.makeRotationFromEuler(ah)),e.flipEnvMap.value=a.isCubeTexture&&a.isRenderTargetTexture===!1?-1:1,e.reflectivity.value=r.reflectivity,e.ior.value=r.ior,e.refractionRatio.value=r.refractionRatio),r.lightMap&&(e.lightMap.value=r.lightMap,e.lightMapIntensity.value=r.lightMapIntensity,n(r.lightMap,e.lightMapTransform)),r.aoMap&&(e.aoMap.value=r.aoMap,e.aoMapIntensity.value=r.aoMapIntensity,n(r.aoMap,e.aoMapTransform))}function o(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform))}function s(e,t){e.dashSize.value=t.dashSize,e.totalSize.value=t.dashSize+t.gapSize,e.scale.value=t.scale}function c(e,t,r,i){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.size.value=t.size*r,e.scale.value=i*.5,t.map&&(e.map.value=t.map,n(t.map,e.uvTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function l(e,t){e.diffuse.value.copy(t.color),e.opacity.value=t.opacity,e.rotation.value=t.rotation,t.map&&(e.map.value=t.map,n(t.map,e.mapTransform)),t.alphaMap&&(e.alphaMap.value=t.alphaMap,n(t.alphaMap,e.alphaMapTransform)),t.alphaTest>0&&(e.alphaTest.value=t.alphaTest)}function u(e,t){e.specular.value.copy(t.specular),e.shininess.value=Math.max(t.shininess,1e-4)}function d(e,t){t.gradientMap&&(e.gradientMap.value=t.gradientMap)}function f(e,t){e.metalness.value=t.metalness,t.metalnessMap&&(e.metalnessMap.value=t.metalnessMap,n(t.metalnessMap,e.metalnessMapTransform)),e.roughness.value=t.roughness,t.roughnessMap&&(e.roughnessMap.value=t.roughnessMap,n(t.roughnessMap,e.roughnessMapTransform)),t.envMap&&(e.envMapIntensity.value=t.envMapIntensity)}function p(e,t,r){e.ior.value=t.ior,t.sheen>0&&(e.sheenColor.value.copy(t.sheenColor).multiplyScalar(t.sheen),e.sheenRoughness.value=t.sheenRoughness,t.sheenColorMap&&(e.sheenColorMap.value=t.sheenColorMap,n(t.sheenColorMap,e.sheenColorMapTransform)),t.sheenRoughnessMap&&(e.sheenRoughnessMap.value=t.sheenRoughnessMap,n(t.sheenRoughnessMap,e.sheenRoughnessMapTransform))),t.clearcoat>0&&(e.clearcoat.value=t.clearcoat,e.clearcoatRoughness.value=t.clearcoatRoughness,t.clearcoatMap&&(e.clearcoatMap.value=t.clearcoatMap,n(t.clearcoatMap,e.clearcoatMapTransform)),t.clearcoatRoughnessMap&&(e.clearcoatRoughnessMap.value=t.clearcoatRoughnessMap,n(t.clearcoatRoughnessMap,e.clearcoatRoughnessMapTransform)),t.clearcoatNormalMap&&(e.clearcoatNormalMap.value=t.clearcoatNormalMap,n(t.clearcoatNormalMap,e.clearcoatNormalMapTransform),e.clearcoatNormalScale.value.copy(t.clearcoatNormalScale),t.side===1&&e.clearcoatNormalScale.value.negate())),t.dispersion>0&&(e.dispersion.value=t.dispersion),t.iridescence>0&&(e.iridescence.value=t.iridescence,e.iridescenceIOR.value=t.iridescenceIOR,e.iridescenceThicknessMinimum.value=t.iridescenceThicknessRange[0],e.iridescenceThicknessMaximum.value=t.iridescenceThicknessRange[1],t.iridescenceMap&&(e.iridescenceMap.value=t.iridescenceMap,n(t.iridescenceMap,e.iridescenceMapTransform)),t.iridescenceThicknessMap&&(e.iridescenceThicknessMap.value=t.iridescenceThicknessMap,n(t.iridescenceThicknessMap,e.iridescenceThicknessMapTransform))),t.transmission>0&&(e.transmission.value=t.transmission,e.transmissionSamplerMap.value=r.texture,e.transmissionSamplerSize.value.set(r.width,r.height),t.transmissionMap&&(e.transmissionMap.value=t.transmissionMap,n(t.transmissionMap,e.transmissionMapTransform)),e.thickness.value=t.thickness,t.thicknessMap&&(e.thicknessMap.value=t.thicknessMap,n(t.thicknessMap,e.thicknessMapTransform)),e.attenuationDistance.value=t.attenuationDistance,e.attenuationColor.value.copy(t.attenuationColor)),t.anisotropy>0&&(e.anisotropyVector.value.set(t.anisotropy*Math.cos(t.anisotropyRotation),t.anisotropy*Math.sin(t.anisotropyRotation)),t.anisotropyMap&&(e.anisotropyMap.value=t.anisotropyMap,n(t.anisotropyMap,e.anisotropyMapTransform))),e.specularIntensity.value=t.specularIntensity,e.specularColor.value.copy(t.specularColor),t.specularColorMap&&(e.specularColorMap.value=t.specularColorMap,n(t.specularColorMap,e.specularColorMapTransform)),t.specularIntensityMap&&(e.specularIntensityMap.value=t.specularIntensityMap,n(t.specularIntensityMap,e.specularIntensityMapTransform))}function m(e,t){t.matcap&&(e.matcap.value=t.matcap)}function h(e,n){let r=t.get(n).light;e.referencePosition.value.setFromMatrixPosition(r.matrixWorld),e.nearDistance.value=r.shadow.camera.near,e.farDistance.value=r.shadow.camera.far}return{refreshFogUniforms:r,refreshMaterialUniforms:i}}function ch(e,t,n,r){let i={},a={},o=[],s=e.getParameter(e.MAX_UNIFORM_BUFFER_BINDINGS);function c(e,t){let n=t.program;r.uniformBlockBinding(e,n)}function l(e,n){let o=i[e.id];o===void 0&&(m(e),o=u(e),i[e.id]=o,e.addEventListener(`dispose`,g));let s=n.program;r.updateUBOMapping(e,s);let c=t.render.frame;a[e.id]!==c&&(f(e),a[e.id]=c)}function u(t){let n=d();t.__bindingPointIndex=n;let r=e.createBuffer(),i=t.__size,a=t.usage;return e.bindBuffer(e.UNIFORM_BUFFER,r),e.bufferData(e.UNIFORM_BUFFER,i,a),e.bindBuffer(e.UNIFORM_BUFFER,null),e.bindBufferBase(e.UNIFORM_BUFFER,n,r),r}function d(){for(let e=0;e<s;e++)if(o.indexOf(e)===-1)return o.push(e),e;return di(`WebGLRenderer: Maximum number of simultaneously usable uniforms groups reached.`),0}function f(t){let n=i[t.id],r=t.uniforms,a=t.__cache;e.bindBuffer(e.UNIFORM_BUFFER,n);for(let t=0,n=r.length;t<n;t++){let n=Array.isArray(r[t])?r[t]:[r[t]];for(let r=0,i=n.length;r<i;r++){let i=n[r];if(p(i,t,r,a)===!0){let t=i.__offset,n=Array.isArray(i.value)?i.value:[i.value],r=0;for(let a=0;a<n.length;a++){let o=n[a],s=h(o);typeof o==`number`||typeof o==`boolean`?(i.__data[0]=o,e.bufferSubData(e.UNIFORM_BUFFER,t+r,i.__data)):o.isMatrix3?(i.__data[0]=o.elements[0],i.__data[1]=o.elements[1],i.__data[2]=o.elements[2],i.__data[3]=0,i.__data[4]=o.elements[3],i.__data[5]=o.elements[4],i.__data[6]=o.elements[5],i.__data[7]=0,i.__data[8]=o.elements[6],i.__data[9]=o.elements[7],i.__data[10]=o.elements[8],i.__data[11]=0):(o.toArray(i.__data,r),r+=s.storage/Float32Array.BYTES_PER_ELEMENT)}e.bufferSubData(e.UNIFORM_BUFFER,t,i.__data)}}}e.bindBuffer(e.UNIFORM_BUFFER,null)}function p(e,t,n,r){let i=e.value,a=t+`_`+n;if(r[a]===void 0)return typeof i==`number`||typeof i==`boolean`?r[a]=i:r[a]=i.clone(),!0;{let e=r[a];if(typeof i==`number`||typeof i==`boolean`){if(e!==i)return r[a]=i,!0}else if(e.equals(i)===!1)return e.copy(i),!0}return!1}function m(e){let t=e.uniforms,n=0;for(let e=0,r=t.length;e<r;e++){let r=Array.isArray(t[e])?t[e]:[t[e]];for(let e=0,t=r.length;e<t;e++){let t=r[e],i=Array.isArray(t.value)?t.value:[t.value];for(let e=0,r=i.length;e<r;e++){let r=i[e],a=h(r),o=n%16,s=o%a.boundary,c=o+s;n+=s,c!==0&&16-c<a.storage&&(n+=16-c),t.__data=new Float32Array(a.storage/Float32Array.BYTES_PER_ELEMENT),t.__offset=n,n+=a.storage}}}let r=n%16;return r>0&&(n+=16-r),e.__size=n,e.__cache={},this}function h(e){let t={boundary:0,storage:0};return typeof e==`number`||typeof e==`boolean`?(t.boundary=4,t.storage=4):e.isVector2?(t.boundary=8,t.storage=8):e.isVector3||e.isColor?(t.boundary=16,t.storage=12):e.isVector4?(t.boundary=16,t.storage=16):e.isMatrix3?(t.boundary=48,t.storage=48):e.isMatrix4?(t.boundary=64,t.storage=64):e.isTexture?K(`WebGLRenderer: Texture samplers can not be part of an uniforms group.`):K(`WebGLRenderer: Unsupported uniform value type.`,e),t}function g(t){let n=t.target;n.removeEventListener(`dispose`,g);let r=o.indexOf(n.__bindingPointIndex);o.splice(r,1),e.deleteBuffer(i[n.id]),delete i[n.id],delete a[n.id]}function _(){for(let t in i)e.deleteBuffer(i[t]);o=[],i={},a={}}return{bind:c,update:l,dispose:_}}var lh=new Uint16Array([12469,15057,12620,14925,13266,14620,13807,14376,14323,13990,14545,13625,14713,13328,14840,12882,14931,12528,14996,12233,15039,11829,15066,11525,15080,11295,15085,10976,15082,10705,15073,10495,13880,14564,13898,14542,13977,14430,14158,14124,14393,13732,14556,13410,14702,12996,14814,12596,14891,12291,14937,11834,14957,11489,14958,11194,14943,10803,14921,10506,14893,10278,14858,9960,14484,14039,14487,14025,14499,13941,14524,13740,14574,13468,14654,13106,14743,12678,14818,12344,14867,11893,14889,11509,14893,11180,14881,10751,14852,10428,14812,10128,14765,9754,14712,9466,14764,13480,14764,13475,14766,13440,14766,13347,14769,13070,14786,12713,14816,12387,14844,11957,14860,11549,14868,11215,14855,10751,14825,10403,14782,10044,14729,9651,14666,9352,14599,9029,14967,12835,14966,12831,14963,12804,14954,12723,14936,12564,14917,12347,14900,11958,14886,11569,14878,11247,14859,10765,14828,10401,14784,10011,14727,9600,14660,9289,14586,8893,14508,8533,15111,12234,15110,12234,15104,12216,15092,12156,15067,12010,15028,11776,14981,11500,14942,11205,14902,10752,14861,10393,14812,9991,14752,9570,14682,9252,14603,8808,14519,8445,14431,8145,15209,11449,15208,11451,15202,11451,15190,11438,15163,11384,15117,11274,15055,10979,14994,10648,14932,10343,14871,9936,14803,9532,14729,9218,14645,8742,14556,8381,14461,8020,14365,7603,15273,10603,15272,10607,15267,10619,15256,10631,15231,10614,15182,10535,15118,10389,15042,10167,14963,9787,14883,9447,14800,9115,14710,8665,14615,8318,14514,7911,14411,7507,14279,7198,15314,9675,15313,9683,15309,9712,15298,9759,15277,9797,15229,9773,15166,9668,15084,9487,14995,9274,14898,8910,14800,8539,14697,8234,14590,7790,14479,7409,14367,7067,14178,6621,15337,8619,15337,8631,15333,8677,15325,8769,15305,8871,15264,8940,15202,8909,15119,8775,15022,8565,14916,8328,14804,8009,14688,7614,14569,7287,14448,6888,14321,6483,14088,6171,15350,7402,15350,7419,15347,7480,15340,7613,15322,7804,15287,7973,15229,8057,15148,8012,15046,7846,14933,7611,14810,7357,14682,7069,14552,6656,14421,6316,14251,5948,14007,5528,15356,5942,15356,5977,15353,6119,15348,6294,15332,6551,15302,6824,15249,7044,15171,7122,15070,7050,14949,6861,14818,6611,14679,6349,14538,6067,14398,5651,14189,5311,13935,4958,15359,4123,15359,4153,15356,4296,15353,4646,15338,5160,15311,5508,15263,5829,15188,6042,15088,6094,14966,6001,14826,5796,14678,5543,14527,5287,14377,4985,14133,4586,13869,4257,15360,1563,15360,1642,15358,2076,15354,2636,15341,3350,15317,4019,15273,4429,15203,4732,15105,4911,14981,4932,14836,4818,14679,4621,14517,4386,14359,4156,14083,3795,13808,3437,15360,122,15360,137,15358,285,15355,636,15344,1274,15322,2177,15281,2765,15215,3223,15120,3451,14995,3569,14846,3567,14681,3466,14511,3305,14344,3121,14037,2800,13753,2467,15360,0,15360,1,15359,21,15355,89,15346,253,15325,479,15287,796,15225,1148,15133,1492,15008,1749,14856,1882,14685,1886,14506,1783,14324,1608,13996,1398,13702,1183]),uh=null;function dh(){return uh===null&&(uh=new Gs(lh,16,16,nr,Un),uh.name=`DFG_LUT`,uh.minFilter=Nn,uh.magFilter=Nn,uh.wrapS=On,uh.wrapT=On,uh.generateMipmaps=!1,uh.needsUpdate=!0),uh}var fh=class{constructor(e={}){let{canvas:t=oi(),context:n=null,depth:r=!0,stencil:i=!1,alpha:a=!1,antialias:o=!1,premultipliedAlpha:s=!0,preserveDrawingBuffer:c=!1,powerPreference:l=`default`,failIfMajorPerformanceCaveat:u=!1,reversedDepthBuffer:d=!1,outputBufferType:f=In}=e;this.isWebGLRenderer=!0;let p;if(n!==null){if(typeof WebGLRenderingContext<`u`&&n instanceof WebGLRenderingContext)throw Error(`THREE.WebGLRenderer: WebGL 1 is not supported since r163.`);p=n.getContextAttributes().alpha}else p=a;let m=f,h=new Set([ir,rr,tr]),g=new Set([In,Vn,zn,Kn,Wn,Gn]),_=new Uint32Array(4),v=new Int32Array(4),y=null,b=null,x=[],S=[],C=null;this.domElement=t,this.debug={checkShaderErrors:!0,onShaderError:null},this.autoClear=!0,this.autoClearColor=!0,this.autoClearDepth=!0,this.autoClearStencil=!0,this.sortObjects=!0,this.clippingPlanes=[],this.localClippingEnabled=!1,this.toneMapping=0,this.toneMappingExposure=1,this.transmissionResolutionScale=1;let w=this,T=!1;this._outputColorSpace=Xr;let E=0,D=0,O=null,k=-1,A=null,j=new ca,M=new ca,ee=null,N=new X(0),te=0,ne=t.width,re=t.height,P=1,ie=null,ae=null,F=new ca(0,0,ne,re),I=new ca(0,0,ne,re),oe=!1,se=new dc,ce=!1,le=!1,ue=new Y,de=new J,fe=new ca,pe={background:null,fog:null,environment:null,overrideMaterial:null,isScene:!0},me=!1;function he(){return O===null?P:1}let L=n;function R(e,n){return t.getContext(e,n)}try{let e={alpha:!0,depth:r,stencil:i,antialias:o,premultipliedAlpha:s,preserveDrawingBuffer:c,powerPreference:l,failIfMajorPerformanceCaveat:u};if(`setAttribute`in t&&t.setAttribute(`data-engine`,`three.js r183`),t.addEventListener(`webglcontextlost`,Ie,!1),t.addEventListener(`webglcontextrestored`,Le,!1),t.addEventListener(`webglcontextcreationerror`,Re,!1),L===null){let t=`webgl2`;if(L=R(t,e),L===null)throw R(t)?Error(`Error creating WebGL context with your selected attributes.`):Error(`Error creating WebGL context.`)}}catch(e){throw di(`WebGLRenderer: `+e.message),e}let z,ge,B,_e,V,H,ve,ye,be,xe,Se,Ce,we,U,Te,Ee,De,Oe,ke,Ae,je,Me,Ne;function Pe(){z=new jf(L),z.init(),je=new eh(L,z),ge=new sf(L,z,e,je),B=new Qm(L,z),ge.reversedDepthBuffer&&d&&B.buffers.depth.setReversed(!0),_e=new Pf(L),V=new Mm,H=new $m(L,z,B,V,ge,je,_e),ve=new Af(w),ye=new Zd(L),Me=new af(L,ye),be=new Mf(L,ye,_e,Me),xe=new If(L,be,ye,Me,_e),Oe=new Ff(L,ge,H),Te=new cf(V),Se=new jm(w,ve,z,ge,Me,Te),Ce=new sh(w,V),we=new Im,U=new Um(z),De=new rf(w,ve,B,xe,p,s),Ee=new Zm(w,xe,ge),Ne=new ch(L,_e,ge,B),ke=new of(L,z,_e),Ae=new Nf(L,z,_e),_e.programs=Se.programs,w.capabilities=ge,w.extensions=z,w.properties=V,w.renderLists=we,w.shadowMap=Ee,w.state=B,w.info=_e}Pe(),m!==1009&&(C=new Rf(m,t.width,t.height,r,i));let Fe=new ih(w,L);this.xr=Fe,this.getContext=function(){return L},this.getContextAttributes=function(){return L.getContextAttributes()},this.forceContextLoss=function(){let e=z.get(`WEBGL_lose_context`);e&&e.loseContext()},this.forceContextRestore=function(){let e=z.get(`WEBGL_lose_context`);e&&e.restoreContext()},this.getPixelRatio=function(){return P},this.setPixelRatio=function(e){e!==void 0&&(P=e,this.setSize(ne,re,!1))},this.getSize=function(e){return e.set(ne,re)},this.setSize=function(e,n,r=!0){if(Fe.isPresenting){K(`WebGLRenderer: Can't change size while VR device is presenting.`);return}ne=e,re=n,t.width=Math.floor(e*P),t.height=Math.floor(n*P),r===!0&&(t.style.width=e+`px`,t.style.height=n+`px`),C!==null&&C.setSize(t.width,t.height),this.setViewport(0,0,e,n)},this.getDrawingBufferSize=function(e){return e.set(ne*P,re*P).floor()},this.setDrawingBufferSize=function(e,n,r){ne=e,re=n,P=r,t.width=Math.floor(e*r),t.height=Math.floor(n*r),this.setViewport(0,0,e,n)},this.setEffects=function(e){if(m===1009){console.error(`THREE.WebGLRenderer: setEffects() requires outputBufferType set to HalfFloatType or FloatType.`);return}if(e){for(let t=0;t<e.length;t++)if(e[t].isOutputPass===!0){console.warn(`THREE.WebGLRenderer: OutputPass is not needed in setEffects(). Tone mapping and color space conversion are applied automatically.`);break}}C.setEffects(e||[])},this.getCurrentViewport=function(e){return e.copy(j)},this.getViewport=function(e){return e.copy(F)},this.setViewport=function(e,t,n,r){e.isVector4?F.set(e.x,e.y,e.z,e.w):F.set(e,t,n,r),B.viewport(j.copy(F).multiplyScalar(P).round())},this.getScissor=function(e){return e.copy(I)},this.setScissor=function(e,t,n,r){e.isVector4?I.set(e.x,e.y,e.z,e.w):I.set(e,t,n,r),B.scissor(M.copy(I).multiplyScalar(P).round())},this.getScissorTest=function(){return oe},this.setScissorTest=function(e){B.setScissorTest(oe=e)},this.setOpaqueSort=function(e){ie=e},this.setTransparentSort=function(e){ae=e},this.getClearColor=function(e){return e.copy(De.getClearColor())},this.setClearColor=function(){De.setClearColor(...arguments)},this.getClearAlpha=function(){return De.getClearAlpha()},this.setClearAlpha=function(){De.setClearAlpha(...arguments)},this.clear=function(e=!0,t=!0,n=!0){let r=0;if(e){let e=!1;if(O!==null){let t=O.texture.format;e=h.has(t)}if(e){let e=O.texture.type,t=g.has(e),n=De.getClearColor(),r=De.getClearAlpha(),i=n.r,a=n.g,o=n.b;t?(_[0]=i,_[1]=a,_[2]=o,_[3]=r,L.clearBufferuiv(L.COLOR,0,_)):(v[0]=i,v[1]=a,v[2]=o,v[3]=r,L.clearBufferiv(L.COLOR,0,v))}else r|=L.COLOR_BUFFER_BIT}t&&(r|=L.DEPTH_BUFFER_BIT),n&&(r|=L.STENCIL_BUFFER_BIT,this.state.buffers.stencil.setMask(4294967295)),r!==0&&L.clear(r)},this.clearColor=function(){this.clear(!0,!1,!1)},this.clearDepth=function(){this.clear(!1,!0,!1)},this.clearStencil=function(){this.clear(!1,!1,!0)},this.dispose=function(){t.removeEventListener(`webglcontextlost`,Ie,!1),t.removeEventListener(`webglcontextrestored`,Le,!1),t.removeEventListener(`webglcontextcreationerror`,Re,!1),De.dispose(),we.dispose(),U.dispose(),V.dispose(),ve.dispose(),xe.dispose(),Me.dispose(),Ne.dispose(),Se.dispose(),Fe.dispose(),Fe.removeEventListener(`sessionstart`,Ge),Fe.removeEventListener(`sessionend`,Ke),qe.stop()};function Ie(e){e.preventDefault(),li(`WebGLRenderer: Context Lost.`),T=!0}function Le(){li(`WebGLRenderer: Context Restored.`),T=!1;let e=_e.autoReset,t=Ee.enabled,n=Ee.autoUpdate,r=Ee.needsUpdate,i=Ee.type;Pe(),_e.autoReset=e,Ee.enabled=t,Ee.autoUpdate=n,Ee.needsUpdate=r,Ee.type=i}function Re(e){di(`WebGLRenderer: A WebGL context could not be created. Reason: `,e.statusMessage)}function ze(e){let t=e.target;t.removeEventListener(`dispose`,ze),Be(t)}function Be(e){Ve(e),V.remove(e)}function Ve(e){let t=V.get(e).programs;t!==void 0&&(t.forEach(function(e){Se.releaseProgram(e)}),e.isShaderMaterial&&Se.releaseShaderCache(e))}this.renderBufferDirect=function(e,t,n,r,i,a){t===null&&(t=pe);let o=i.isMesh&&i.matrixWorld.determinant()<0,s=nt(e,t,n,r,i);B.setMaterial(r,o);let c=n.index,l=1;if(r.wireframe===!0){if(c=be.getWireframeAttribute(n),c===void 0)return;l=2}let u=n.drawRange,d=n.attributes.position,f=u.start*l,p=(u.start+u.count)*l;a!==null&&(f=Math.max(f,a.start*l),p=Math.min(p,(a.start+a.count)*l)),c===null?d!=null&&(f=Math.max(f,0),p=Math.min(p,d.count)):(f=Math.max(f,0),p=Math.min(p,c.count));let m=p-f;if(m<0||m===1/0)return;Me.setup(i,r,s,n,c);let h,g=ke;if(c!==null&&(h=ye.get(c),g=Ae,g.setIndex(h)),i.isMesh)r.wireframe===!0?(B.setLineWidth(r.wireframeLinewidth*he()),g.setMode(L.LINES)):g.setMode(L.TRIANGLES);else if(i.isLine){let e=r.linewidth;e===void 0&&(e=1),B.setLineWidth(e*he()),i.isLineSegments?g.setMode(L.LINES):i.isLineLoop?g.setMode(L.LINE_LOOP):g.setMode(L.LINE_STRIP)}else i.isPoints?g.setMode(L.POINTS):i.isSprite&&g.setMode(L.TRIANGLES);if(i.isBatchedMesh)if(i._multiDrawInstances!==null)fi(`WebGLRenderer: renderMultiDrawInstances has been deprecated and will be removed in r184. Append to renderMultiDraw arguments and use indirection.`),g.renderMultiDrawInstances(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount,i._multiDrawInstances);else if(z.get(`WEBGL_multi_draw`))g.renderMultiDraw(i._multiDrawStarts,i._multiDrawCounts,i._multiDrawCount);else{let e=i._multiDrawStarts,t=i._multiDrawCounts,n=i._multiDrawCount,a=c?ye.get(c).bytesPerElement:1,o=V.get(r).currentProgram.getUniforms();for(let r=0;r<n;r++)o.setValue(L,`_gl_DrawID`,r),g.render(e[r]/a,t[r])}else if(i.isInstancedMesh)g.renderInstances(f,m,i.count);else if(n.isInstancedBufferGeometry){let e=n._maxInstanceCount===void 0?1/0:n._maxInstanceCount,t=Math.min(n.instanceCount,e);g.renderInstances(f,m,t)}else g.render(f,m)};function He(e,t,n){e.transparent===!0&&e.side===2&&e.forceSinglePass===!1?(e.side=1,e.needsUpdate=!0,$e(e,t,n),e.side=0,e.needsUpdate=!0,$e(e,t,n),e.side=2):$e(e,t,n)}this.compile=function(e,t,n=null){n===null&&(n=e),b=U.get(n),b.init(t),S.push(b),n.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(b.pushLight(e),e.castShadow&&b.pushShadow(e))}),e!==n&&e.traverseVisible(function(e){e.isLight&&e.layers.test(t.layers)&&(b.pushLight(e),e.castShadow&&b.pushShadow(e))}),b.setupLights();let r=new Set;return e.traverse(function(e){if(!(e.isMesh||e.isPoints||e.isLine||e.isSprite))return;let t=e.material;if(t)if(Array.isArray(t))for(let i=0;i<t.length;i++){let a=t[i];He(a,n,e),r.add(a)}else He(t,n,e),r.add(t)}),b=S.pop(),r},this.compileAsync=function(e,t,n=null){let r=this.compile(e,t,n);return new Promise(t=>{function n(){if(r.forEach(function(e){V.get(e).currentProgram.isReady()&&r.delete(e)}),r.size===0){t(e);return}setTimeout(n,10)}z.get(`KHR_parallel_shader_compile`)===null?setTimeout(n,10):n()})};let Ue=null;function We(e){Ue&&Ue(e)}function Ge(){qe.stop()}function Ke(){qe.start()}let qe=new Xd;qe.setAnimationLoop(We),typeof self<`u`&&qe.setContext(self),this.setAnimationLoop=function(e){Ue=e,Fe.setAnimationLoop(e),e===null?qe.stop():qe.start()},Fe.addEventListener(`sessionstart`,Ge),Fe.addEventListener(`sessionend`,Ke),this.render=function(e,t){if(t!==void 0&&t.isCamera!==!0){di(`WebGLRenderer.render: camera is not an instance of THREE.Camera.`);return}if(T===!0)return;let n=Fe.enabled===!0&&Fe.isPresenting===!0,r=C!==null&&(O===null||n)&&C.begin(w,O);if(e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),Fe.enabled===!0&&Fe.isPresenting===!0&&(C===null||C.isCompositing()===!1)&&(Fe.cameraAutoUpdate===!0&&Fe.updateCamera(t),t=Fe.getCamera()),e.isScene===!0&&e.onBeforeRender(w,e,t,O),b=U.get(e,S.length),b.init(t),S.push(b),ue.multiplyMatrices(t.projectionMatrix,t.matrixWorldInverse),se.setFromProjectionMatrix(ue,ni,t.reversedDepth),le=this.localClippingEnabled,ce=Te.init(this.clippingPlanes,le),y=we.get(e,x.length),y.init(),x.push(y),Fe.enabled===!0&&Fe.isPresenting===!0){let e=w.xr.getDepthSensingMesh();e!==null&&Je(e,t,-1/0,w.sortObjects)}Je(e,t,0,w.sortObjects),y.finish(),w.sortObjects===!0&&y.sort(ie,ae),me=Fe.enabled===!1||Fe.isPresenting===!1||Fe.hasDepthSensing()===!1,me&&De.addToRenderList(y,e),this.info.render.frame++,ce===!0&&Te.beginShadows();let i=b.state.shadowsArray;if(Ee.render(i,e,t),ce===!0&&Te.endShadows(),this.info.autoReset===!0&&this.info.reset(),(r&&C.hasRenderPass())===!1){let n=y.opaque,r=y.transmissive;if(b.setupLights(),t.isArrayCamera){let i=t.cameras;if(r.length>0)for(let t=0,a=i.length;t<a;t++){let a=i[t];Xe(n,r,e,a)}me&&De.render(e);for(let t=0,n=i.length;t<n;t++){let n=i[t];Ye(y,e,n,n.viewport)}}else r.length>0&&Xe(n,r,e,t),me&&De.render(e),Ye(y,e,t)}O!==null&&D===0&&(H.updateMultisampleRenderTarget(O),H.updateRenderTargetMipmap(O)),r&&C.end(w),e.isScene===!0&&e.onAfterRender(w,e,t),Me.resetDefaultState(),k=-1,A=null,S.pop(),S.length>0?(b=S[S.length-1],ce===!0&&Te.setGlobalState(w.clippingPlanes,b.state.camera)):b=null,x.pop(),y=x.length>0?x[x.length-1]:null};function Je(e,t,n,r){if(e.visible===!1)return;if(e.layers.test(t.layers)){if(e.isGroup)n=e.renderOrder;else if(e.isLOD)e.autoUpdate===!0&&e.update(t);else if(e.isLight)b.pushLight(e),e.castShadow&&b.pushShadow(e);else if(e.isSprite){if(!e.frustumCulled||se.intersectsSprite(e)){r&&fe.setFromMatrixPosition(e.matrixWorld).applyMatrix4(ue);let t=xe.update(e),i=e.material;i.visible&&y.push(e,t,i,n,fe.z,null)}}else if((e.isMesh||e.isLine||e.isPoints)&&(!e.frustumCulled||se.intersectsObject(e))){let t=xe.update(e),i=e.material;if(r&&(e.boundingSphere===void 0?(t.boundingSphere===null&&t.computeBoundingSphere(),fe.copy(t.boundingSphere.center)):(e.boundingSphere===null&&e.computeBoundingSphere(),fe.copy(e.boundingSphere.center)),fe.applyMatrix4(e.matrixWorld).applyMatrix4(ue)),Array.isArray(i)){let r=t.groups;for(let a=0,o=r.length;a<o;a++){let o=r[a],s=i[o.materialIndex];s&&s.visible&&y.push(e,t,s,n,fe.z,o)}}else i.visible&&y.push(e,t,i,n,fe.z,null)}}let i=e.children;for(let e=0,a=i.length;e<a;e++)Je(i[e],t,n,r)}function Ye(e,t,n,r){let{opaque:i,transmissive:a,transparent:o}=e;b.setupLightsView(n),ce===!0&&Te.setGlobalState(w.clippingPlanes,n),r&&B.viewport(j.copy(r)),i.length>0&&Ze(i,t,n),a.length>0&&Ze(a,t,n),o.length>0&&Ze(o,t,n),B.buffers.depth.setTest(!0),B.buffers.depth.setMask(!0),B.buffers.color.setMask(!0),B.setPolygonOffset(!1)}function Xe(e,t,n,r){if((n.isScene===!0?n.overrideMaterial:null)!==null)return;if(b.state.transmissionRenderTarget[r.id]===void 0){let e=z.has(`EXT_color_buffer_half_float`)||z.has(`EXT_color_buffer_float`);b.state.transmissionRenderTarget[r.id]=new ua(1,1,{generateMipmaps:!0,type:e?Un:In,minFilter:Fn,samples:Math.max(4,ge.samples),stencilBuffer:i,resolveDepthBuffer:!1,resolveStencilBuffer:!1,colorSpace:Zi.workingColorSpace})}let a=b.state.transmissionRenderTarget[r.id],o=r.viewport||j;a.setSize(o.z*w.transmissionResolutionScale,o.w*w.transmissionResolutionScale);let s=w.getRenderTarget(),c=w.getActiveCubeFace(),l=w.getActiveMipmapLevel();w.setRenderTarget(a),w.getClearColor(N),te=w.getClearAlpha(),te<1&&w.setClearColor(16777215,.5),w.clear(),me&&De.render(n);let u=w.toneMapping;w.toneMapping=0;let d=r.viewport;if(r.viewport!==void 0&&(r.viewport=void 0),b.setupLightsView(r),ce===!0&&Te.setGlobalState(w.clippingPlanes,r),Ze(e,n,r),H.updateMultisampleRenderTarget(a),H.updateRenderTargetMipmap(a),z.has(`WEBGL_multisampled_render_to_texture`)===!1){let e=!1;for(let i=0,a=t.length;i<a;i++){let{object:a,geometry:o,material:s,group:c}=t[i];if(s.side===2&&a.layers.test(r.layers)){let t=s.side;s.side=1,s.needsUpdate=!0,Qe(a,n,r,o,s,c),s.side=t,s.needsUpdate=!0,e=!0}}e===!0&&(H.updateMultisampleRenderTarget(a),H.updateRenderTargetMipmap(a))}w.setRenderTarget(s,c,l),w.setClearColor(N,te),d!==void 0&&(r.viewport=d),w.toneMapping=u}function Ze(e,t,n){let r=t.isScene===!0?t.overrideMaterial:null;for(let i=0,a=e.length;i<a;i++){let a=e[i],{object:o,geometry:s,group:c}=a,l=a.material;l.allowOverride===!0&&r!==null&&(l=r),o.layers.test(n.layers)&&Qe(o,t,n,s,l,c)}}function Qe(e,t,n,r,i,a){e.onBeforeRender(w,t,n,r,i,a),e.modelViewMatrix.multiplyMatrices(n.matrixWorldInverse,e.matrixWorld),e.normalMatrix.getNormalMatrix(e.modelViewMatrix),i.onBeforeRender(w,t,n,r,e,a),i.transparent===!0&&i.side===2&&i.forceSinglePass===!1?(i.side=1,i.needsUpdate=!0,w.renderBufferDirect(n,t,r,i,e,a),i.side=0,i.needsUpdate=!0,w.renderBufferDirect(n,t,r,i,e,a),i.side=2):w.renderBufferDirect(n,t,r,i,e,a),e.onAfterRender(w,t,n,r,i,a)}function $e(e,t,n){t.isScene!==!0&&(t=pe);let r=V.get(e),i=b.state.lights,a=b.state.shadowsArray,o=i.state.version,s=Se.getParameters(e,i.state,a,t,n),c=Se.getProgramCacheKey(s),l=r.programs;r.environment=e.isMeshStandardMaterial||e.isMeshLambertMaterial||e.isMeshPhongMaterial?t.environment:null,r.fog=t.fog;let u=e.isMeshStandardMaterial||e.isMeshLambertMaterial&&!e.envMap||e.isMeshPhongMaterial&&!e.envMap;r.envMap=ve.get(e.envMap||r.environment,u),r.envMapRotation=r.environment!==null&&e.envMap===null?t.environmentRotation:e.envMapRotation,l===void 0&&(e.addEventListener(`dispose`,ze),l=new Map,r.programs=l);let d=l.get(c);if(d!==void 0){if(r.currentProgram===d&&r.lightsStateVersion===o)return tt(e,s),d}else s.uniforms=Se.getUniforms(e),e.onBeforeCompile(s,w),d=Se.acquireProgram(s,c),l.set(c,d),r.uniforms=s.uniforms;let f=r.uniforms;return(!e.isShaderMaterial&&!e.isRawShaderMaterial||e.clipping===!0)&&(f.clippingPlanes=Te.uniform),tt(e,s),r.needsLights=it(e),r.lightsStateVersion=o,r.needsLights&&(f.ambientLightColor.value=i.state.ambient,f.lightProbe.value=i.state.probe,f.directionalLights.value=i.state.directional,f.directionalLightShadows.value=i.state.directionalShadow,f.spotLights.value=i.state.spot,f.spotLightShadows.value=i.state.spotShadow,f.rectAreaLights.value=i.state.rectArea,f.ltc_1.value=i.state.rectAreaLTC1,f.ltc_2.value=i.state.rectAreaLTC2,f.pointLights.value=i.state.point,f.pointLightShadows.value=i.state.pointShadow,f.hemisphereLights.value=i.state.hemi,f.directionalShadowMatrix.value=i.state.directionalShadowMatrix,f.spotLightMatrix.value=i.state.spotLightMatrix,f.spotLightMap.value=i.state.spotLightMap,f.pointShadowMatrix.value=i.state.pointShadowMatrix),r.currentProgram=d,r.uniformsList=null,d}function et(e){if(e.uniformsList===null){let t=e.currentProgram.getUniforms();e.uniformsList=Gp.seqWithValue(t.seq,e.uniforms)}return e.uniformsList}function tt(e,t){let n=V.get(e);n.outputColorSpace=t.outputColorSpace,n.batching=t.batching,n.batchingColor=t.batchingColor,n.instancing=t.instancing,n.instancingColor=t.instancingColor,n.instancingMorph=t.instancingMorph,n.skinning=t.skinning,n.morphTargets=t.morphTargets,n.morphNormals=t.morphNormals,n.morphColors=t.morphColors,n.morphTargetsCount=t.morphTargetsCount,n.numClippingPlanes=t.numClippingPlanes,n.numIntersection=t.numClipIntersection,n.vertexAlphas=t.vertexAlphas,n.vertexTangents=t.vertexTangents,n.toneMapping=t.toneMapping}function nt(e,t,n,r,i){t.isScene!==!0&&(t=pe),H.resetTextureUnits();let a=t.fog,o=r.isMeshStandardMaterial||r.isMeshLambertMaterial||r.isMeshPhongMaterial?t.environment:null,s=O===null?w.outputColorSpace:O.isXRRenderTarget===!0?O.texture.colorSpace:Zr,c=r.isMeshStandardMaterial||r.isMeshLambertMaterial&&!r.envMap||r.isMeshPhongMaterial&&!r.envMap,l=ve.get(r.envMap||o,c),u=r.vertexColors===!0&&!!n.attributes.color&&n.attributes.color.itemSize===4,d=!!n.attributes.tangent&&(!!r.normalMap||r.anisotropy>0),f=!!n.morphAttributes.position,p=!!n.morphAttributes.normal,m=!!n.morphAttributes.color,h=0;r.toneMapped&&(O===null||O.isXRRenderTarget===!0)&&(h=w.toneMapping);let g=n.morphAttributes.position||n.morphAttributes.normal||n.morphAttributes.color,_=g===void 0?0:g.length,v=V.get(r),y=b.state.lights;if(ce===!0&&(le===!0||e!==A)){let t=e===A&&r.id===k;Te.setState(r,e,t)}let x=!1;r.version===v.__version?v.needsLights&&v.lightsStateVersion!==y.state.version?x=!0:v.outputColorSpace===s?i.isBatchedMesh&&v.batching===!1||!i.isBatchedMesh&&v.batching===!0||i.isBatchedMesh&&v.batchingColor===!0&&i.colorTexture===null||i.isBatchedMesh&&v.batchingColor===!1&&i.colorTexture!==null||i.isInstancedMesh&&v.instancing===!1||!i.isInstancedMesh&&v.instancing===!0||i.isSkinnedMesh&&v.skinning===!1||!i.isSkinnedMesh&&v.skinning===!0||i.isInstancedMesh&&v.instancingColor===!0&&i.instanceColor===null||i.isInstancedMesh&&v.instancingColor===!1&&i.instanceColor!==null||i.isInstancedMesh&&v.instancingMorph===!0&&i.morphTexture===null||i.isInstancedMesh&&v.instancingMorph===!1&&i.morphTexture!==null?x=!0:v.envMap===l?r.fog===!0&&v.fog!==a||v.numClippingPlanes!==void 0&&(v.numClippingPlanes!==Te.numPlanes||v.numIntersection!==Te.numIntersection)?x=!0:v.vertexAlphas===u&&v.vertexTangents===d&&v.morphTargets===f&&v.morphNormals===p&&v.morphColors===m&&v.toneMapping===h?v.morphTargetsCount!==_&&(x=!0):x=!0:x=!0:x=!0:(x=!0,v.__version=r.version);let S=v.currentProgram;x===!0&&(S=$e(r,t,i));let C=!1,T=!1,E=!1,D=S.getUniforms(),j=v.uniforms;if(B.useProgram(S.program)&&(C=!0,T=!0,E=!0),r.id!==k&&(k=r.id,T=!0),C||A!==e){B.buffers.depth.getReversed()&&e.reversedDepth!==!0&&(e._reversedDepth=!0,e.updateProjectionMatrix()),D.setValue(L,`projectionMatrix`,e.projectionMatrix),D.setValue(L,`viewMatrix`,e.matrixWorldInverse);let t=D.map.cameraPosition;t!==void 0&&t.setValue(L,de.setFromMatrixPosition(e.matrixWorld)),ge.logarithmicDepthBuffer&&D.setValue(L,`logDepthBufFC`,2/(Math.log(e.far+1)/Math.LN2)),(r.isMeshPhongMaterial||r.isMeshToonMaterial||r.isMeshLambertMaterial||r.isMeshBasicMaterial||r.isMeshStandardMaterial||r.isShaderMaterial)&&D.setValue(L,`isOrthographic`,e.isOrthographicCamera===!0),A!==e&&(A=e,T=!0,E=!0)}if(v.needsLights&&(y.state.directionalShadowMap.length>0&&D.setValue(L,`directionalShadowMap`,y.state.directionalShadowMap,H),y.state.spotShadowMap.length>0&&D.setValue(L,`spotShadowMap`,y.state.spotShadowMap,H),y.state.pointShadowMap.length>0&&D.setValue(L,`pointShadowMap`,y.state.pointShadowMap,H)),i.isSkinnedMesh){D.setOptional(L,i,`bindMatrix`),D.setOptional(L,i,`bindMatrixInverse`);let e=i.skeleton;e&&(e.boneTexture===null&&e.computeBoneTexture(),D.setValue(L,`boneTexture`,e.boneTexture,H))}i.isBatchedMesh&&(D.setOptional(L,i,`batchingTexture`),D.setValue(L,`batchingTexture`,i._matricesTexture,H),D.setOptional(L,i,`batchingIdTexture`),D.setValue(L,`batchingIdTexture`,i._indirectTexture,H),D.setOptional(L,i,`batchingColorTexture`),i._colorsTexture!==null&&D.setValue(L,`batchingColorTexture`,i._colorsTexture,H));let M=n.morphAttributes;if((M.position!==void 0||M.normal!==void 0||M.color!==void 0)&&Oe.update(i,n,S),(T||v.receiveShadow!==i.receiveShadow)&&(v.receiveShadow=i.receiveShadow,D.setValue(L,`receiveShadow`,i.receiveShadow)),(r.isMeshStandardMaterial||r.isMeshLambertMaterial||r.isMeshPhongMaterial)&&r.envMap===null&&t.environment!==null&&(j.envMapIntensity.value=t.environmentIntensity),j.dfgLUT!==void 0&&(j.dfgLUT.value=dh()),T&&(D.setValue(L,`toneMappingExposure`,w.toneMappingExposure),v.needsLights&&rt(j,E),a&&r.fog===!0&&Ce.refreshFogUniforms(j,a),Ce.refreshMaterialUniforms(j,r,P,re,b.state.transmissionRenderTarget[e.id]),Gp.upload(L,et(v),j,H)),r.isShaderMaterial&&r.uniformsNeedUpdate===!0&&(Gp.upload(L,et(v),j,H),r.uniformsNeedUpdate=!1),r.isSpriteMaterial&&D.setValue(L,`center`,i.center),D.setValue(L,`modelViewMatrix`,i.modelViewMatrix),D.setValue(L,`normalMatrix`,i.normalMatrix),D.setValue(L,`modelMatrix`,i.matrixWorld),r.isShaderMaterial||r.isRawShaderMaterial){let e=r.uniformsGroups;for(let t=0,n=e.length;t<n;t++){let n=e[t];Ne.update(n,S),Ne.bind(n,S)}}return S}function rt(e,t){e.ambientLightColor.needsUpdate=t,e.lightProbe.needsUpdate=t,e.directionalLights.needsUpdate=t,e.directionalLightShadows.needsUpdate=t,e.pointLights.needsUpdate=t,e.pointLightShadows.needsUpdate=t,e.spotLights.needsUpdate=t,e.spotLightShadows.needsUpdate=t,e.rectAreaLights.needsUpdate=t,e.hemisphereLights.needsUpdate=t}function it(e){return e.isMeshLambertMaterial||e.isMeshToonMaterial||e.isMeshPhongMaterial||e.isMeshStandardMaterial||e.isShadowMaterial||e.isShaderMaterial&&e.lights===!0}this.getActiveCubeFace=function(){return E},this.getActiveMipmapLevel=function(){return D},this.getRenderTarget=function(){return O},this.setRenderTargetTextures=function(e,t,n){let r=V.get(e);r.__autoAllocateDepthBuffer=e.resolveDepthBuffer===!1,r.__autoAllocateDepthBuffer===!1&&(r.__useRenderToTexture=!1),V.get(e.texture).__webglTexture=t,V.get(e.depthTexture).__webglTexture=r.__autoAllocateDepthBuffer?void 0:n,r.__hasExternalTextures=!0},this.setRenderTargetFramebuffer=function(e,t){let n=V.get(e);n.__webglFramebuffer=t,n.__useDefaultFramebuffer=t===void 0};let at=L.createFramebuffer();this.setRenderTarget=function(e,t=0,n=0){O=e,E=t,D=n;let r=null,i=!1,a=!1;if(e){let o=V.get(e);if(o.__useDefaultFramebuffer!==void 0){B.bindFramebuffer(L.FRAMEBUFFER,o.__webglFramebuffer),j.copy(e.viewport),M.copy(e.scissor),ee=e.scissorTest,B.viewport(j),B.scissor(M),B.setScissorTest(ee),k=-1;return}else if(o.__webglFramebuffer===void 0)H.setupRenderTarget(e);else if(o.__hasExternalTextures)H.rebindTextures(e,V.get(e.texture).__webglTexture,V.get(e.depthTexture).__webglTexture);else if(e.depthBuffer){let t=e.depthTexture;if(o.__boundDepthTexture!==t){if(t!==null&&V.has(t)&&(e.width!==t.image.width||e.height!==t.image.height))throw Error(`WebGLRenderTarget: Attached DepthTexture is initialized to the incorrect size.`);H.setupDepthRenderbuffer(e)}}let s=e.texture;(s.isData3DTexture||s.isDataArrayTexture||s.isCompressedArrayTexture)&&(a=!0);let c=V.get(e).__webglFramebuffer;e.isWebGLCubeRenderTarget?(r=Array.isArray(c[t])?c[t][n]:c[t],i=!0):r=e.samples>0&&H.useMultisampledRTT(e)===!1?V.get(e).__webglMultisampledFramebuffer:Array.isArray(c)?c[n]:c,j.copy(e.viewport),M.copy(e.scissor),ee=e.scissorTest}else j.copy(F).multiplyScalar(P).floor(),M.copy(I).multiplyScalar(P).floor(),ee=oe;if(n!==0&&(r=at),B.bindFramebuffer(L.FRAMEBUFFER,r)&&B.drawBuffers(e,r),B.viewport(j),B.scissor(M),B.setScissorTest(ee),i){let r=V.get(e.texture);L.framebufferTexture2D(L.FRAMEBUFFER,L.COLOR_ATTACHMENT0,L.TEXTURE_CUBE_MAP_POSITIVE_X+t,r.__webglTexture,n)}else if(a){let r=t;for(let t=0;t<e.textures.length;t++){let i=V.get(e.textures[t]);L.framebufferTextureLayer(L.FRAMEBUFFER,L.COLOR_ATTACHMENT0+t,i.__webglTexture,n,r)}}else if(e!==null&&n!==0){let t=V.get(e.texture);L.framebufferTexture2D(L.FRAMEBUFFER,L.COLOR_ATTACHMENT0,L.TEXTURE_2D,t.__webglTexture,n)}k=-1},this.readRenderTargetPixels=function(e,t,n,r,i,a,o,s=0){if(!(e&&e.isWebGLRenderTarget)){di(`WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);return}let c=V.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(c=c[o]),c){B.bindFramebuffer(L.FRAMEBUFFER,c);try{let o=e.textures[s],c=o.format,l=o.type;if(e.textures.length>1&&L.readBuffer(L.COLOR_ATTACHMENT0+s),!ge.textureFormatReadable(c)){di(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in RGBA or implementation defined format.`);return}if(!ge.textureTypeReadable(l)){di(`WebGLRenderer.readRenderTargetPixels: renderTarget is not in UnsignedByteType or implementation defined type.`);return}t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i&&L.readPixels(t,n,r,i,je.convert(c),je.convert(l),a)}finally{let e=O===null?null:V.get(O).__webglFramebuffer;B.bindFramebuffer(L.FRAMEBUFFER,e)}}},this.readRenderTargetPixelsAsync=async function(e,t,n,r,i,a,o,s=0){if(!(e&&e.isWebGLRenderTarget))throw Error(`THREE.WebGLRenderer.readRenderTargetPixels: renderTarget is not THREE.WebGLRenderTarget.`);let c=V.get(e).__webglFramebuffer;if(e.isWebGLCubeRenderTarget&&o!==void 0&&(c=c[o]),c)if(t>=0&&t<=e.width-r&&n>=0&&n<=e.height-i){B.bindFramebuffer(L.FRAMEBUFFER,c);let o=e.textures[s],l=o.format,u=o.type;if(e.textures.length>1&&L.readBuffer(L.COLOR_ATTACHMENT0+s),!ge.textureFormatReadable(l))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.`);if(!ge.textureTypeReadable(u))throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.`);let d=L.createBuffer();L.bindBuffer(L.PIXEL_PACK_BUFFER,d),L.bufferData(L.PIXEL_PACK_BUFFER,a.byteLength,L.STREAM_READ),L.readPixels(t,n,r,i,je.convert(l),je.convert(u),0);let f=O===null?null:V.get(O).__webglFramebuffer;B.bindFramebuffer(L.FRAMEBUFFER,f);let p=L.fenceSync(L.SYNC_GPU_COMMANDS_COMPLETE,0);return L.flush(),await pi(L,p,4),L.bindBuffer(L.PIXEL_PACK_BUFFER,d),L.getBufferSubData(L.PIXEL_PACK_BUFFER,0,a),L.deleteBuffer(d),L.deleteSync(p),a}else throw Error(`THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.`)},this.copyFramebufferToTexture=function(e,t=null,n=0){let r=2**-n,i=Math.floor(e.image.width*r),a=Math.floor(e.image.height*r),o=t===null?0:t.x,s=t===null?0:t.y;H.setTexture2D(e,0),L.copyTexSubImage2D(L.TEXTURE_2D,n,0,0,o,s,i,a),B.unbindTexture()};let ot=L.createFramebuffer(),st=L.createFramebuffer();this.copyTextureToTexture=function(e,t,n=null,r=null,i=0,a=0){let o,s,c,l,u,d,f,p,m,h=e.isCompressedTexture?e.mipmaps[a]:e.image;if(n!==null)o=n.max.x-n.min.x,s=n.max.y-n.min.y,c=n.isBox3?n.max.z-n.min.z:1,l=n.min.x,u=n.min.y,d=n.isBox3?n.min.z:0;else{let t=2**-i;o=Math.floor(h.width*t),s=Math.floor(h.height*t),c=e.isDataArrayTexture?h.depth:e.isData3DTexture?Math.floor(h.depth*t):1,l=0,u=0,d=0}r===null?(f=0,p=0,m=0):(f=r.x,p=r.y,m=r.z);let g=je.convert(t.format),_=je.convert(t.type),v;t.isData3DTexture?(H.setTexture3D(t,0),v=L.TEXTURE_3D):t.isDataArrayTexture||t.isCompressedArrayTexture?(H.setTexture2DArray(t,0),v=L.TEXTURE_2D_ARRAY):(H.setTexture2D(t,0),v=L.TEXTURE_2D),L.pixelStorei(L.UNPACK_FLIP_Y_WEBGL,t.flipY),L.pixelStorei(L.UNPACK_PREMULTIPLY_ALPHA_WEBGL,t.premultiplyAlpha),L.pixelStorei(L.UNPACK_ALIGNMENT,t.unpackAlignment);let y=L.getParameter(L.UNPACK_ROW_LENGTH),b=L.getParameter(L.UNPACK_IMAGE_HEIGHT),x=L.getParameter(L.UNPACK_SKIP_PIXELS),S=L.getParameter(L.UNPACK_SKIP_ROWS),C=L.getParameter(L.UNPACK_SKIP_IMAGES);L.pixelStorei(L.UNPACK_ROW_LENGTH,h.width),L.pixelStorei(L.UNPACK_IMAGE_HEIGHT,h.height),L.pixelStorei(L.UNPACK_SKIP_PIXELS,l),L.pixelStorei(L.UNPACK_SKIP_ROWS,u),L.pixelStorei(L.UNPACK_SKIP_IMAGES,d);let w=e.isDataArrayTexture||e.isData3DTexture,T=t.isDataArrayTexture||t.isData3DTexture;if(e.isDepthTexture){let n=V.get(e),r=V.get(t),h=V.get(n.__renderTarget),g=V.get(r.__renderTarget);B.bindFramebuffer(L.READ_FRAMEBUFFER,h.__webglFramebuffer),B.bindFramebuffer(L.DRAW_FRAMEBUFFER,g.__webglFramebuffer);for(let n=0;n<c;n++)w&&(L.framebufferTextureLayer(L.READ_FRAMEBUFFER,L.COLOR_ATTACHMENT0,V.get(e).__webglTexture,i,d+n),L.framebufferTextureLayer(L.DRAW_FRAMEBUFFER,L.COLOR_ATTACHMENT0,V.get(t).__webglTexture,a,m+n)),L.blitFramebuffer(l,u,o,s,f,p,o,s,L.DEPTH_BUFFER_BIT,L.NEAREST);B.bindFramebuffer(L.READ_FRAMEBUFFER,null),B.bindFramebuffer(L.DRAW_FRAMEBUFFER,null)}else if(i!==0||e.isRenderTargetTexture||V.has(e)){let n=V.get(e),r=V.get(t);B.bindFramebuffer(L.READ_FRAMEBUFFER,ot),B.bindFramebuffer(L.DRAW_FRAMEBUFFER,st);for(let e=0;e<c;e++)w?L.framebufferTextureLayer(L.READ_FRAMEBUFFER,L.COLOR_ATTACHMENT0,n.__webglTexture,i,d+e):L.framebufferTexture2D(L.READ_FRAMEBUFFER,L.COLOR_ATTACHMENT0,L.TEXTURE_2D,n.__webglTexture,i),T?L.framebufferTextureLayer(L.DRAW_FRAMEBUFFER,L.COLOR_ATTACHMENT0,r.__webglTexture,a,m+e):L.framebufferTexture2D(L.DRAW_FRAMEBUFFER,L.COLOR_ATTACHMENT0,L.TEXTURE_2D,r.__webglTexture,a),i===0?T?L.copyTexSubImage3D(v,a,f,p,m+e,l,u,o,s):L.copyTexSubImage2D(v,a,f,p,l,u,o,s):L.blitFramebuffer(l,u,o,s,f,p,o,s,L.COLOR_BUFFER_BIT,L.NEAREST);B.bindFramebuffer(L.READ_FRAMEBUFFER,null),B.bindFramebuffer(L.DRAW_FRAMEBUFFER,null)}else T?e.isDataTexture||e.isData3DTexture?L.texSubImage3D(v,a,f,p,m,o,s,c,g,_,h.data):t.isCompressedArrayTexture?L.compressedTexSubImage3D(v,a,f,p,m,o,s,c,g,h.data):L.texSubImage3D(v,a,f,p,m,o,s,c,g,_,h):e.isDataTexture?L.texSubImage2D(L.TEXTURE_2D,a,f,p,o,s,g,_,h.data):e.isCompressedTexture?L.compressedTexSubImage2D(L.TEXTURE_2D,a,f,p,h.width,h.height,g,h.data):L.texSubImage2D(L.TEXTURE_2D,a,f,p,o,s,g,_,h);L.pixelStorei(L.UNPACK_ROW_LENGTH,y),L.pixelStorei(L.UNPACK_IMAGE_HEIGHT,b),L.pixelStorei(L.UNPACK_SKIP_PIXELS,x),L.pixelStorei(L.UNPACK_SKIP_ROWS,S),L.pixelStorei(L.UNPACK_SKIP_IMAGES,C),a===0&&t.generateMipmaps&&L.generateMipmap(v),B.unbindTexture()},this.initRenderTarget=function(e){V.get(e).__webglFramebuffer===void 0&&H.setupRenderTarget(e)},this.initTexture=function(e){e.isCubeTexture?H.setTextureCube(e,0):e.isData3DTexture?H.setTexture3D(e,0):e.isDataArrayTexture||e.isCompressedArrayTexture?H.setTexture2DArray(e,0):H.setTexture2D(e,0),B.unbindTexture()},this.resetState=function(){E=0,D=0,O=null,B.reset(),Me.reset()},typeof __THREE_DEVTOOLS__<`u`&&__THREE_DEVTOOLS__.dispatchEvent(new CustomEvent(`observe`,{detail:this}))}get coordinateSystem(){return ni}get outputColorSpace(){return this._outputColorSpace}set outputColorSpace(e){this._outputColorSpace=e;let t=this.getContext();t.drawingBufferColorSpace=Zi._getDrawingBufferColorSpace(e),t.unpackColorSpace=Zi._getUnpackColorSpace()}},ph=-(2**40),mh=8;function hh(e,t){return e<0||e>=mh?ph:t*mh+e}function gh(e){return(e%mh+mh)%mh}function _h(e){return(e-gh(e))/mh}function vh(e){return e===ph?null:ln(gh(e),_h(e))}function yh(e){let t=e.indexOf(`-`);if(t<=0)return null;let n=cn(e.slice(0,t));if(n===void 0)return null;let r=Number(e.slice(t+1));if(!Number.isInteger(r)||r>2147483647||r<-2147483648)return null;let i=hh(n,r);return i===ph?null:i}function bh(e){let t=new Set;for(let n of e){let e=yh(n);e!==null&&t.add(e)}return t}function xh(e){return e+7&-8}function Sh(e){return{subFormat:e.getUint16(24,!0),source:e.getUint8(26),idType:e.getUint8(27),rowCount:e.getUint32(28,!0)}}function Ch(e,t){return ln(e.idType,e.id[t])}function wh(e,t){return hh(e.idType,e.id[t])}function Th(e,t){let n=Zt,r=new Int32Array(e,n,t);n+=xh(t*4);let i=new Uint8Array(e,n,t);n+=xh(t);let a=new Int32Array(e,n,t);n+=xh(t*4);let o=new Uint8Array(e,n,t);return n+=xh(t),{id:r,objectType:i,parentId:a,scale:o,offset:n}}function Eh(e,t,n){let r=n,i=new Float64Array(e,r,t);r+=t*8;let a=new Float32Array(e,r,t);r+=xh(t*4);let o=new Float32Array(e,r,t);r+=xh(t*4);let s=new Float32Array(e,r,t);r+=xh(t*4);let c=new Float32Array(e,r,t);r+=xh(t*4);let l=new Float32Array(e,r,t);r+=xh(t*4);let u=new Float32Array(e,r,t);r+=xh(t*4);let d=new Float32Array(e,r,t);r+=xh(t*4);let f=new Float32Array(e,r,t);return r+=xh(t*4),{epochJd:i,a,e:o,i:s,om:c,w:l,ma:u,n:d,radiusKm:f,offset:r}}function Dh(e,t,n){let{subFormat:r,rowCount:i,source:a,idType:o}=Sh(new DataView(e));if(o===an.UNKNOWN&&i>0&&console.warn(`elements payload has unknown id-type — ${i} row(s) will lack reconstructed IDs`),r===1)return kh(e,i,t,n,a,o);if(r===2)return Oh(e,i,t,n,a,o);if(r!==0)throw Error(`Unknown elements sub-format: ${r}`);let{id:s,objectType:c,parentId:l,scale:u,offset:d}=Th(e,i),f=Eh(e,i,d),p=f.offset,m=new Float32Array(e,p,i);p+=xh(i*4);let h=new Float32Array(e,p,i);p+=xh(i*4);let g=new Uint8Array(e,p,i);p+=xh(i);let _=new Uint8Array(e,p,i);p+=xh(i);let v=new Float32Array(e,p,i),y={validityStart:t,validityEnd:n,source:a,idType:o};return{kind:`keplerian`,id:s,objectType:c,parentId:l,scale:u,epochJd:f.epochJd,a:f.a,e:f.e,i:f.i,om:f.om,w:f.w,ma:f.ma,n:f.n,radiusKm:f.radiusKm,omDot:m,wDot:h,hasLocalized:g,flags:_,visibleFromDays:v,rowCount:i,...y}}function Oh(e,t,n,r,i,a){let{id:o,objectType:s,parentId:c,scale:l,offset:u}=Th(e,t),d=Eh(e,t,u),f=d.offset,p={validityStart:n,validityEnd:r,source:i,idType:a},m=new Float32Array(e,f,t);f+=xh(t*4);let h=new Float32Array(e,f,t);f+=xh(t*4);let g=new Float32Array(e,f,t);f+=xh(t*4);let _=new Int32Array(e,f,t);f+=xh(t*4);let v=new Int32Array(e,f,t);f+=xh(t*4);let y=new Uint8Array(e,f,t);f+=xh(t);let b=new Uint8Array(e,f,t);f+=xh(t);let x=new Float32Array(e,f,t);return{kind:`sgp4`,id:o,objectType:s,parentId:c,scale:l,epochJd:d.epochJd,a:d.a,e:d.e,i:d.i,om:d.om,w:d.w,ma:d.ma,n:d.n,radiusKm:d.radiusKm,bstar:m,meanMotionDot:h,meanMotionDdot:g,elementSetNo:_,revAtEpoch:v,hasLocalized:y,flags:b,visibleFromDays:x,rowCount:t,...p}}function kh(e,t,n,r,i,a){let{id:o,objectType:s,parentId:c,scale:l,offset:u}=Th(e,t),d=u,f={validityStart:n,validityEnd:r,source:i,idType:a},p=new Float64Array(e,d,t);d+=t*8;let m=new Float32Array(e,d,t);d+=xh(t*4);let h=new Float32Array(e,d,t);d+=xh(t*4);let g=new Float32Array(e,d,t);d+=xh(t*4);let _=new Float32Array(e,d,t);d+=xh(t*4);let v=new Float32Array(e,d,t);d+=xh(t*4);let y=new Float64Array(e,d,t);d+=t*8;let b=new Float32Array(e,d,t);d+=xh(t*4);let x=new Uint8Array(e,d,t);d+=xh(t);let S=new Uint8Array(e,d,t);return d+=xh(t),{kind:`parabolic`,id:o,objectType:s,parentId:c,scale:l,epochJd:p,q:m,e:h,i:g,om:_,w:v,tp:y,radiusKm:b,hasLocalized:x,flags:S,visibleFromDays:new Float32Array(e,d,t),rowCount:t,...f}}var Ah=Math.PI,jh=Ah*2,Mh=Ah/180;180/Ah;var Nh=398600.8,Ph=6378.135,Fh=60/Math.sqrt(Ph*Ph*Ph/Nh),Ih=Ph*Fh/60,Lh=1/Fh,Rh=.001082616,zh=-253881e-11,Bh=-165597e-11,Vh=zh/Rh,Hh=2/3,Uh=1440/(2*Ah);function Wh(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 Gh(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 Kh(e,t,n,r,i,a,o=0){if(e instanceof Date){let t=e;return Gh(t.getUTCFullYear(),t.getUTCMonth()+1,t.getUTCDate(),t.getUTCHours(),t.getUTCMinutes(),t.getUTCSeconds(),t.getUTCMilliseconds())}return Gh(e,t,n,r,i,a,o)}function qh(e,t){let{e3:n,ee2:r,peo:i,pgho:a,pho:o,pinco:s,plo:c,se2:l,se3:u,sgh2:d,sgh3:f,sgh4:p,sh2:m,sh3:h,si2:g,si3:_,sl2:v,sl3:y,sl4:b,t:x,xgh2:S,xgh3:C,xgh4:w,xh2:T,xh3:E,xi2:D,xi3:O,xl2:k,xl3:A,xl4:j,zmol:M,zmos:ee}=e,{init:N,opsmode:te}=t,{ep:ne,inclp:re,nodep:P,argpp:ie,mp:ae}=t,F,I,oe,se,ce,le,ue,de,fe,pe,me,he,L,R,z,ge,B,_e,V,H,ve;ve=ee+119459e-10*x,N===`y`&&(ve=ee),H=ve+2*.01675*Math.sin(ve),B=Math.sin(H),pe=.5*B*B-.25,me=-.5*B*Math.cos(H);let ye=l*pe+u*me,be=g*pe+_*me,xe=v*pe+y*me+b*B,Se=d*pe+f*me+p*B,Ce=m*pe+h*me;ve=M+.00015835218*x,N===`y`&&(ve=M),H=ve+2*.0549*Math.sin(ve),B=Math.sin(H),pe=.5*B*B-.25,me=-.5*B*Math.cos(H);let we=r*pe+n*me,U=D*pe+O*me,Te=k*pe+A*me+j*B,Ee=S*pe+C*me+w*B,De=T*pe+E*me;return he=ye+we,z=be+U,ge=xe+Te,L=Se+Ee,R=Ce+De,N===`n`&&(he-=i,z-=s,ge-=c,L-=a,R-=o,re+=z,ne+=he,se=Math.sin(re),oe=Math.cos(re),re>=.2?(R/=se,L-=oe*R,ie+=L,P+=R,ae+=ge):(le=Math.sin(P),ce=Math.cos(P),F=se*le,I=se*ce,ue=R*ce+z*oe*le,de=-R*le+z*oe*ce,F+=ue,I+=de,P%=jh,P<0&&te===`a`&&(P+=jh),_e=ae+ie+oe*P,fe=ge+L-z*P*se,_e+=fe,V=P,P=Math.atan2(F,I),P<0&&te===`a`&&(P+=jh),Math.abs(V-P)>Ah&&(P<V?P+=jh:P-=jh),ae+=ge,ie=_e-ae-oe*P)),{ep:ne,inclp:re,nodep:P,argpp:ie,mp:ae}}function Jh(e){let{epoch:t,ep:n,argpp:r,tc:i,inclp:a,nodep:o,np:s}=e,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,ee,N,te,ne,re,P,ie,ae,F,I,oe,se,ce,le,ue,de,fe,pe,me,he,L,R,z,ge,B,_e,V,H,ve,ye,be,xe,Se,Ce,we,U,Te,Ee,De=.01675,Oe=.0549,ke=s,Ae=n,je=Math.sin(o),Me=Math.cos(o),Ne=Math.sin(r),Pe=Math.cos(r),Fe=Math.sin(a),Ie=Math.cos(a),Le=Ae*Ae,Re=1-Le,ze=Math.sqrt(Re),Be=t+18261.5+i/1440,Ve=(4.523602-.00092422029*Be)%jh,He=Math.sin(Ve),Ue=Math.cos(Ve),We=.91375164-.03568096*Ue,Ge=Math.sqrt(1-We*We),Ke=.089683511*He/Ge,qe=Math.sqrt(1-Ke*Ke),Je=5.8351514+.001944368*Be,Ye=.39785416*He/Ge,Xe=qe*Ue+.91744867*Ke*He;Ye=Math.atan2(Ye,Xe),Ye+=Je-Ve;let Ze=Math.cos(Ye),Qe=Math.sin(Ye);D=.1945905,O=-.98088458,j=.91744867,M=.39785416,k=Me,A=je,v=29864797e-13;let $e=1/ke,et=0;for(;et<2;)et+=1,c=D*k+O*j*A,u=-O*k+D*j*A,m=-D*A+O*j*k,h=O*M,g=O*A+D*j*k,_=D*M,l=Ie*m+Fe*h,d=Ie*g+Fe*_,f=-Fe*m+Ie*h,p=-Fe*g+Ie*_,y=c*Pe+l*Ne,b=u*Pe+d*Ne,x=-c*Ne+l*Pe,S=-u*Ne+d*Pe,C=f*Ne,w=p*Ne,T=f*Pe,E=p*Pe,U=12*y*y-3*x*x,Te=24*y*b-6*x*S,Ee=12*b*b-3*S*S,V=3*(c*c+l*l)+U*Le,H=6*(c*u+l*d)+Te*Le,ve=3*(u*u+d*d)+Ee*Le,ye=-6*c*f+Le*(-24*y*T-6*x*C),be=-6*(c*p+u*f)+Le*(-24*(b*T+y*E)+-6*(x*w+S*C)),xe=-6*u*p+Le*(-24*b*E-6*S*w),Se=6*l*f+Le*(24*y*C-6*x*T),Ce=6*(d*f+l*p)+Le*(24*(b*C+y*w)-6*(S*T+x*E)),we=6*d*p+Le*(24*b*w-6*S*E),V=V+V+Re*U,H=H+H+Re*Te,ve=ve+ve+Re*Ee,R=v*$e,L=-.5*R/ze,z=R*ze,he=-15*Ae*z,ge=y*x+b*S,B=b*x+y*S,_e=b*S-y*x,et===1&&(ee=he,N=L,te=R,ne=z,re=ge,P=B,ie=_e,ae=V,F=H,I=ve,oe=ye,se=be,ce=xe,le=Se,ue=Ce,de=we,fe=U,pe=Te,me=Ee,D=Ze,O=Qe,j=We,M=Ge,k=qe*Me+Ke*je,A=je*qe-Me*Ke,v=4.7968065e-7);let tt=(4.7199672+(.2299715*Be-Je))%jh,nt=(6.2565837+.017201977*Be)%jh,rt=2*ee*P,it=2*ee*ie,at=2*N*se,ot=2*N*(ce-oe),st=-2*te*F,ct=-2*te*(I-ae),lt=-2*te*(-21-9*Le)*De,ut=2*ne*pe,dt=2*ne*(me-fe),ft=-18*ne*De,pt=-2*N*ue,mt=-2*N*(de-le),ht=2*he*B,gt=2*he*_e,_t=2*L*be,vt=2*L*(xe-ye),yt=-2*R*H,bt=-2*R*(ve-V),xt=-2*R*(-21-9*Le)*Oe,St=2*z*Te,Ct=2*z*(Ee-U),wt=-18*z*Oe,Tt=-2*L*Ce,Et=-2*L*(we-Se);return{snodm:je,cnodm:Me,sinim:Fe,cosim:Ie,sinomm:Ne,cosomm:Pe,day:Be,e3:gt,ee2:ht,em:Ae,emsq:Le,gam:Je,peo:0,pgho:0,pho:0,pinco:0,plo:0,rtemsq:ze,se2:rt,se3:it,sgh2:ut,sgh3:dt,sgh4:ft,sh2:pt,sh3:mt,si2:at,si3:ot,sl2:st,sl3:ct,sl4:lt,s1:he,s2:L,s3:R,s4:z,s5:ge,s6:B,s7:_e,ss1:ee,ss2:N,ss3:te,ss4:ne,ss5:re,ss6:P,ss7:ie,sz1:ae,sz2:F,sz3:I,sz11:oe,sz12:se,sz13:ce,sz21:le,sz22:ue,sz23:de,sz31:fe,sz32:pe,sz33:me,xgh2:St,xgh3:Ct,xgh4:wt,xh2:Tt,xh3:Et,xi2:_t,xi3:vt,xl2:yt,xl3:bt,xl4:xt,nm:ke,z1:V,z2:H,z3:ve,z11:ye,z12:be,z13:xe,z21:Se,z22:Ce,z23:we,z31:U,z32:Te,z33:Ee,zmol:tt,zmos:nt}}function Yh(e){let{cosim:t,argpo:n,s1:r,s2:i,s3:a,s4:o,s5:s,sinim:c,ss1:l,ss2:u,ss3:d,ss4:f,ss5:p,sz1:m,sz3:h,sz11:g,sz13:_,sz21:v,sz23:y,sz31:b,sz33:x,t:S,tc:C,gsto:w,mo:T,mdot:E,no:D,nodeo:O,nodedot:k,xpidot:A,z1:j,z3:M,z11:ee,z13:N,z21:te,z23:ne,z31:re,z33:P,ecco:ie,eccsq:ae}=e,{emsq:F,em:I,argpm:oe,inclm:se,mm:ce,nm:le,nodem:ue,irez:de,atime:fe,d2201:pe,d2211:me,d3210:he,d3222:L,d4410:R,d4422:z,d5220:ge,d5232:B,d5421:_e,d5433:V,dedt:H,didt:ve,dmdt:ye,dnodt:be,domdt:xe,del1:Se,del2:Ce,del3:we,xfact:U,xlamo:Te,xli:Ee,xni:De}=e,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,tt,nt,rt,it,at,ot=.0043752690880113,st=.00015835218,ct=119459e-10;de=0,le<.0052359877&&le>.0034906585&&(de=1),le>=.00826&&le<=.00924&&I>=.5&&(de=2);let lt=l*ct*p,ut=u*ct*(g+_),dt=-ct*d*(m+h-14-6*F),ft=f*ct*(b+x-6),pt=-ct*u*(v+y);(se<.052359877||se>Ah-.052359877)&&(pt=0),c!==0&&(pt/=c);let mt=ft-t*pt;H=lt+r*st*s,ve=ut+i*st*(ee+N),ye=dt-st*a*(j+M-14-6*F);let ht=o*st*(re+P-6),gt=-st*i*(te+ne);(se<.052359877||se>Ah-.052359877)&&(gt=0),xe=mt+ht,be=pt,c!==0&&(xe-=t/c*gt,be+=gt/c);let _t=(w+C*ot)%jh;if(I+=H*S,se+=ve*S,oe+=xe*S,ue+=be*S,ce+=ye*S,de!==0){if(rt=(le/Fh)**Hh,de===2){it=t*t;let e=I;I=ie;let n=F;F=ae,at=I*F,Ve=-.306-(I-.64)*.44,I<=.65?(He=3.616-13.247*I+16.29*F,We=-19.302+117.39*I-228.419*F+156.591*at,Ge=-18.9068+109.7927*I-214.6334*F+146.5816*at,Ke=-41.122+242.694*I-471.094*F+313.953*at,qe=-146.407+841.88*I-1629.014*F+1083.435*at,Je=-532.114+3017.977*I-5740.032*F+3708.276*at):(He=-72.099+331.819*I-508.738*F+266.724*at,We=-346.844+1582.851*I-2415.925*F+1246.113*at,Ge=-342.585+1554.908*I-2366.899*F+1215.972*at,Ke=-1052.797+4758.686*I-7193.992*F+3651.957*at,qe=-3581.69+16178.11*I-24462.77*F+12422.52*at,Je=I>.715?-5149.66+29936.92*I-54087.36*F+31324.56*at:1464.74-4664.75*I+3763.64*F),I<.7?(Ze=-919.2277+4988.61*I-9064.77*F+5542.21*at,Ye=-822.71072+4568.6173*I-8491.4146*F+5337.524*at,Xe=-853.666+4690.25*I-8624.77*F+5341.4*at):(Ze=-37995.78+161616.52*I-229838.2*F+109377.94*at,Ye=-51752.104+218913.95*I-309468.16*F+146349.42*at,Xe=-40023.88+170470.89*I-242699.48*F+115605.82*at),Qe=c*c,Oe=.75*(1+2*t+it),ke=1.5*Qe,je=1.875*c*(1-2*t-3*it),Me=-1.875*c*(1+2*t-3*it),Pe=35*Qe*Oe,Fe=39.375*Qe*Qe,Ie=9.84375*c*(Qe*(1-2*t-5*it)+.33333333*(-2+4*t+6*it)),Le=c*(4.92187512*Qe*(-2-4*t+10*it)+6.56250012*(1+2*t-3*it)),Re=29.53125*c*(2-8*t+it*(-12+8*t+10*it)),ze=29.53125*c*(-2-8*t+it*(12+8*t-10*it)),tt=le*le,nt=rt*rt,et=3*tt*nt,$e=et*17891679e-13,pe=$e*Oe*Ve,me=$e*ke*He,et*=rt,$e=et*3.7393792e-7,he=$e*je*We,L=$e*Me*Ge,et*=rt,$e=2*et*7.3636953e-9,R=$e*Pe*Ke,z=$e*Fe*qe,et*=rt,$e=et*1.1428639e-7,ge=$e*Ie*Je,B=$e*Le*Xe,$e=2*et*2.1765803e-9,_e=$e*Re*Ye,V=$e*ze*Ze,Te=(T+O+O-(_t+_t))%jh,U=E+ye+2*(k+be-ot)-D,I=e,F=n}de===1&&(Be=1+F*(-2.5+.8125*F),We=1+2*F,Ue=1+F*(-6+6.60937*F),Oe=.75*(1+t)*(1+t),Ae=.9375*c*c*(1+3*t)-.75*(1+t),Ne=1+t,Ne*=1.875*Ne*Ne,Se=3*le*le*rt*rt,Ce=2*Se*Oe*Be*17891679e-13,we=3*Se*Ne*Ue*2.2123015e-7*rt,Se=Se*Ae*We*21460748e-13*rt,Te=(T+O+n-_t)%jh,U=E+A+ye+xe+be-(D+ot)),Ee=Te,De=D,fe=0,le=D+0}return{em:I,argpm:oe,inclm:se,mm:ce,nm:le,nodem:ue,irez:de,atime:fe,d2201:pe,d2211:me,d3210:he,d3222:L,d4410:R,d4422:z,d5220:ge,d5232:B,d5421:_e,d5433:V,dedt:H,didt:ve,dmdt:ye,dndt:0,dnodt:be,domdt:xe,del1:Se,del2:Ce,del3:we,xfact:U,xlamo:Te,xli:Ee,xni:De}}function Xh(e){let t=(e-2451545)/36525,n=-62e-7*t*t*t+.093104*t*t+3164400184.812866*t+67310.54841;return n=n*Mh/240%jh,n<0&&(n+=jh),n}function Zh(e,t,n,r,i,a,o){return e instanceof Date?Xh(Kh(e)):Xh(t===void 0?e:Kh(e,t,n,r,i,a,o))}function Qh(e){let{ecco:t,epoch:n,inclo:r,opsmode:i}=e,{no:a}=e,o=t*t,s=1-o,c=Math.sqrt(s),l=Math.cos(r),u=l*l,d=(Fh/a)**Hh,f=.75*Rh*(3*u-1)/(c*s),p=f/(d*d),m=d*(1-p*p-p*(1/3+134*p*p/81));p=f/(m*m),a/=1+p;let h=(Fh/a)**Hh,g=Math.sin(r),_=h*s,v=1-5*u,y=-v-u-u,b=1/h,x=_*_,S=h*(1-t),C;if(i===`a`){let e=n-7305,t=Math.floor(e+1e-8),r=e-t,i=.017202791694070362,a=i+jh;C=(1.7321343856509375+i*t+a*r+e*e*5075514194322695e-30)%jh,C<0&&(C+=jh)}else C=Zh(n+2433281.5);return{no:a,method:`n`,ainv:b,ao:h,con41:y,con42:v,cosio:l,cosio2:u,eccsq:o,omeosq:s,posq:x,rp:S,rteosq:c,sinio:g,gsto:C}}function $h(e){let{irez:t,d2201:n,d2211:r,d3210:i,d3222:a,d4410:o,d4422:s,d5220:c,d5232:l,d5421:u,d5433:d,dedt:f,del1:p,del2:m,del3:h,didt:g,dmdt:_,dnodt:v,domdt:y,argpo:b,argpdot:x,t:S,tc:C,gsto:w,xfact:T,xlamo:E,no:D}=e,{atime:O,em:k,argpm:A,inclm:j,xli:M,mm:ee,xni:N,nodem:te,nm:ne}=e,re=.13130908,P=2.8843198,ie=.37448087,ae=5.7686396,F=.95240898,I=1.8014998,oe=1.050833,se=4.4108898,ce=259200,le,ue,de,fe,pe,me,he,L,R=0,z=0,ge=(w+C*.0043752690880113)%jh;if(k+=f*S,j+=g*S,A+=y*S,te+=v*S,ee+=_*S,t!==0){(O===0||S*O<=0||Math.abs(S)<Math.abs(O))&&(O=0,N=D,M=E),le=S>0?720:-720;let e=381;for(;e===381;)t===2?(L=b+x*O,de=L+L,ue=M+M,he=n*Math.sin(de+M-ae)+r*Math.sin(M-ae)+i*Math.sin(L+M-F)+a*Math.sin(-L+M-F)+o*Math.sin(de+ue-I)+s*Math.sin(ue-I)+c*Math.sin(L+M-oe)+l*Math.sin(-L+M-oe)+u*Math.sin(L+ue-se)+d*Math.sin(-L+ue-se),pe=N+T,me=n*Math.cos(de+M-ae)+r*Math.cos(M-ae)+i*Math.cos(L+M-F)+a*Math.cos(-L+M-F)+c*Math.cos(L+M-oe)+l*Math.cos(-L+M-oe)+2*(o*Math.cos(de+ue-I)+s*Math.cos(ue-I)+u*Math.cos(L+ue-se)+d*Math.cos(-L+ue-se)),me*=pe):(he=p*Math.sin(M-re)+m*Math.sin(2*(M-P))+h*Math.sin(3*(M-ie)),pe=N+T,me=p*Math.cos(M-re)+2*m*Math.cos(2*(M-P))+3*h*Math.cos(3*(M-ie)),me*=pe),Math.abs(S-O)>=720?e=381:(z=S-O,e=0),e===381&&(M+=pe*le+he*ce,N+=he*le+me*ce,O+=le);ne=N+he*z+me*z*z*.5,fe=M+pe*z+he*z*z*.5,t===1?(ee=fe-te-A+ge,R=ne-D):(ee=fe-2*te+2*ge,R=ne-D),ne=D+R}return{atime:O,em:k,argpm:A,inclm:j,xli:M,mm:ee,xni:N,nodem:te,dndt:R,nm:ne}}var eg;(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`})(eg||={});function tg(e,t){let n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O;e.t=t,e.error=eg.None;let k=e.mo+e.mdot*e.t,A=e.argpo+e.argpdot*e.t,j=e.nodeo+e.nodedot*e.t;u=A,S=k;let M=e.t*e.t;if(w=j+e.nodecf*M,v=1-e.cc1*e.t,y=e.bstar*e.cc4*e.t,b=e.t2cof*M,e.isimp!==1){c=e.omgcof*e.t;let t=1+e.eta*Math.cos(k);s=e.xmcof*(t*t*t-e.delmo),_=c+s,S=k+_,u=A-_,p=M*e.t,m=p*e.t,v=v-e.d2*M-e.d3*p-e.d4*m,y+=e.bstar*e.cc5*(Math.sin(S)-e.sinmao),b=b+e.t3cof*p+m*(e.t4cof+e.t*e.t5cof)}C=e.no;let ee=e.ecco;if(x=e.inclo,e.method===`d`){h=e.t;let t=$h({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:h,gsto:e.gsto,xfact:e.xfact,xlamo:e.xlamo,no:e.no,atime:e.atime,em:ee,argpm:u,inclm:x,xli:e.xli,mm:S,xni:e.xni,nodem:w,nm:C});({em:ee,argpm:u,inclm:x,mm:S,nodem:w,nm:C}=t)}if(C<=0)return e.error=eg.MeanMotionBelowZero,null;let N=(Fh/C)**Hh*v*v;if(C=Fh/N**1.5,ee-=y,ee>=1||ee<-.001)return e.error=eg.MeanEccentricityOutOfRange,null;ee<1e-6&&(ee=1e-6),S+=e.no*b,E=S+u+w,w%=jh,u%=jh,E%=jh,S=(E-u-w)%jh;let te={am:N,em:ee,im:x,Om:w,om:u,mm:S,nm:C},ne=Math.sin(x),re=Math.cos(x),P=ee;if(T=x,d=u,O=w,D=S,a=ne,i=re,e.method===`d`){let t=qh(e,{inclo:e.inclo,init:`n`,ep:P,inclp:T,nodep:O,argpp:d,mp:D,opsmode:e.operationmode});if({ep:P,nodep:O,argpp:d,mp:D}=t,T=t.inclp,T<0&&(T=-T,O+=Ah,d-=Ah),P<0||P>1)return e.error=eg.PerturbedEccentricityOutOfRange,null}e.method===`d`&&(a=Math.sin(T),i=Math.cos(T),e.aycof=-.5*Vh*a,Math.abs(i+1)>15e-13?e.xlcof=-.25*Vh*a*(3+5*i)/(1+i):e.xlcof=-.25*Vh*a*(3+5*i)/15e-13);let ie=P*Math.cos(d);_=1/(N*(1-P*P));let ae=P*Math.sin(d)+_*e.aycof,F=(D+d+O+_*e.xlcof*ie-O)%jh;l=F,g=9999.9;let I=1;for(;Math.abs(g)>=1e-12&&I<=10;)r=Math.sin(l),n=Math.cos(l),g=1-n*ie-r*ae,g=(F-ae*n+ie*r-l)/g,Math.abs(g)>=.95&&(g=g>0?.95:-.95),l+=g,I+=1;let oe=ie*n+ae*r,se=ie*r-ae*n,ce=ie*ie+ae*ae,le=N*(1-ce);if(le<0)return e.error=eg.SemiLatusRectumBelowZero,null;let ue=N*(1-oe),de=Math.sqrt(N)*se/ue,fe=Math.sqrt(le)/ue,pe=Math.sqrt(1-ce);_=se/(1+pe);let me=N/ue*(r-ae-ie*_),he=N/ue*(n-ie+ae*_);f=Math.atan2(me,he);let L=(he+he)*me,R=1-2*me*me;_=1/le;let z=.5*Rh*_,ge=z*_;e.method===`d`&&(o=i*i,e.con41=3*o-1,e.x1mth2=1-o,e.x7thm1=7*o-1);let B=ue*(1-1.5*ge*pe*e.con41)+.5*z*e.x1mth2*R;if(B<1)return e.error=eg.Decayed,null;f-=.25*ge*e.x7thm1*L;let _e=O+1.5*ge*i*L,V=T+1.5*ge*i*a*R,H=de-C*z*e.x1mth2*L/Fh,ve=fe+C*z*(e.x1mth2*R+1.5*e.con41)/Fh,ye=Math.sin(f),be=Math.cos(f),xe=Math.sin(_e),Se=Math.cos(_e),Ce=Math.sin(V),we=Math.cos(V),U=-xe*we,Te=Se*we,Ee=U*ye+Se*be,De=Te*ye+xe*be,Oe=Ce*ye,ke=U*be-Se*ye,Ae=Te*be-xe*ye,je=Ce*be;return{position:{x:B*Ee*Ph,y:B*De*Ph,z:B*Oe*Ph},velocity:{x:(H*Ee+ve*ke)*Ih,y:(H*De+ve*Ae)*Ih,z:(H*Oe+ve*je)*Ih},meanElements:te}}function ng(e,t){let{opsmode:n,satn:r,epoch:i,xbstar:a,xecco:o,xargpo:s,xinclo:c,xmo:l,xno:u,xnodeo:d}=t,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O,k,A,j,M,ee,N,te,ne,re,P,ie,ae,F,I,oe,se,ce,le,ue,de,fe,pe,me,he,L,R,z,ge,B,_e,V,H,ve,ye,be,xe,Se,Ce,we,U=e;U.isimp=0,U.method=`n`,U.aycof=0,U.con41=0,U.cc1=0,U.cc4=0,U.cc5=0,U.d2=0,U.d3=0,U.d4=0,U.delmo=0,U.eta=0,U.argpdot=0,U.omgcof=0,U.sinmao=0,U.t=0,U.t2cof=0,U.t3cof=0,U.t4cof=0,U.t5cof=0,U.x1mth2=0,U.x7thm1=0,U.mdot=0,U.nodedot=0,U.xlcof=0,U.xmcof=0,U.nodecf=0,U.irez=0,U.d2201=0,U.d2211=0,U.d3210=0,U.d3222=0,U.d4410=0,U.d4422=0,U.d5220=0,U.d5232=0,U.d5421=0,U.d5433=0,U.dedt=0,U.del1=0,U.del2=0,U.del3=0,U.didt=0,U.dmdt=0,U.dnodt=0,U.domdt=0,U.e3=0,U.ee2=0,U.peo=0,U.pgho=0,U.pho=0,U.pinco=0,U.plo=0,U.se2=0,U.se3=0,U.sgh2=0,U.sgh3=0,U.sgh4=0,U.sh2=0,U.sh3=0,U.si2=0,U.si3=0,U.sl2=0,U.sl3=0,U.sl4=0,U.gsto=0,U.xfact=0,U.xgh2=0,U.xgh3=0,U.xgh4=0,U.xh2=0,U.xh3=0,U.xi2=0,U.xi3=0,U.xl2=0,U.xl3=0,U.xl4=0,U.xlamo=0,U.zmol=0,U.zmos=0,U.atime=0,U.xli=0,U.xni=0,U.bstar=a,U.ecco=o,U.argpo=s,U.inclo=c,U.mo=l,U.no=u,U.nodeo=d,U.operationmode=n;let Te=78/Ph+1,Ee=42/Ph,De=Ee*Ee*Ee*Ee;U.init=`y`,U.t=0;let Oe=Qh({satn:r,ecco:U.ecco,epoch:i,inclo:U.inclo,no:U.no,method:U.method,opsmode:U.operationmode}),{ao:ke,con42:Ae,cosio:je,cosio2:Me,eccsq:Ne,omeosq:Pe,posq:Fe,rp:Ie,rteosq:Le,sinio:Re}=Oe;if(U.no=Oe.no,U.con41=Oe.con41,U.gsto=Oe.gsto,U.a=(U.no*Lh)**(-2/3),U.alta=U.a*(1+U.ecco)-1,U.altp=U.a*(1-U.ecco)-1,U.error=0,Pe>=0||U.no>=0){if(U.isimp=0,Ie<1.034492841559484&&(U.isimp=1),P=Te,M=De,k=(Ie-1)*Ph,k<156){P=k-78,k<98&&(P=20);let e=(120-P)/Ph;M=e*e*e*e,P=P/Ph+1}A=1/Fe,B=1/(ke-P),U.eta=ke*U.ecco*B,C=U.eta*U.eta,S=U.ecco*U.eta,j=Math.abs(1-C),_=M*B**4,v=_/j**3.5,h=v*U.no*(ke*(1+1.5*C+S*(4+C))+.375*Rh*B/j*U.con41*(8+3*C*(8+C))),U.cc1=U.bstar*h,g=0,U.ecco>1e-4&&(g=-2*_*B*Vh*U.no*Re/U.ecco),U.x1mth2=1-Me,U.cc4=2*U.no*v*ke*Pe*(U.eta*(2+.5*C)+U.ecco*(.5+2*C)-Rh*B/(ke*j)*(-3*U.con41*(1-2*S+C*(1.5-.5*S))+.75*U.x1mth2*(2*C-S*(1+C))*Math.cos(2*U.argpo))),U.cc5=2*v*ke*Pe*(1+2.75*(C+S)+S*C),y=Me*Me,R=1.5*Rh*A*U.no,z=.5*R*Rh*A,ge=-.46875*Bh*A*A*U.no,U.mdot=U.no+.5*R*Le*U.con41+.0625*z*Le*(13-78*Me+137*y),U.argpdot=-.5*R*Ae+.0625*z*(7-114*Me+395*y)+ge*(3-36*Me+49*y),V=-R*je,U.nodedot=V+(.5*z*(4-19*Me)+2*ge*(3-7*Me))*je,_e=U.argpdot+U.nodedot,U.omgcof=U.bstar*g*Math.cos(U.argpo),U.xmcof=0,U.ecco>1e-4&&(U.xmcof=-Hh*_*U.bstar/S),U.nodecf=3.5*Pe*V*U.cc1,U.t2cof=1.5*U.cc1,Math.abs(je+1)>15e-13?U.xlcof=-.25*Vh*Re*(3+5*je)/(1+je):U.xlcof=-.25*Vh*Re*(3+5*je)/15e-13,U.aycof=-.5*Vh*Re;let e=1+U.eta*Math.cos(U.mo);if(U.delmo=e*e*e,U.sinmao=Math.sin(U.mo),U.x7thm1=7*Me-1,2*Ah/U.no>=225){U.method=`d`,U.isimp=1,he=0,E=U.inclo;let e=Jh({epoch:i,ep:U.ecco,argpp:U.argpo,tc:he,inclp:U.inclo,nodep:U.nodeo,np:U.no,e3:U.e3,ee2:U.ee2,peo:U.peo,pgho:U.pgho,pho:U.pho,pinco:U.pinco,plo:U.plo,se2:U.se2,se3:U.se3,sgh2:U.sgh2,sgh3:U.sgh3,sgh4:U.sgh4,sh2:U.sh2,sh3:U.sh3,si2:U.si2,si3:U.si3,sl2:U.sl2,sl3:U.sl3,sl4:U.sl4,xgh2:U.xgh2,xgh3:U.xgh3,xgh4:U.xgh4,xh2:U.xh2,xh3:U.xh3,xi2:U.xi2,xi3:U.xi3,xl2:U.xl2,xl3:U.xl3,xl4:U.xl4,zmol:U.zmol,zmos:U.zmos});U.e3=e.e3,U.ee2=e.ee2,U.peo=e.peo,U.pgho=e.pgho,U.pho=e.pho,U.pinco=e.pinco,U.plo=e.plo,U.se2=e.se2,U.se3=e.se3,U.sgh2=e.sgh2,U.sgh3=e.sgh3,U.sgh4=e.sgh4,U.sh2=e.sh2,U.sh3=e.sh3,U.si2=e.si2,U.si3=e.si3,U.sl2=e.sl2,U.sl3=e.sl3,U.sl4=e.sl4,{sinim:p,cosim:f,em:b,emsq:x,s1:ee,s2:N,s3:te,s4:ne,s5:re,ss1:ie,ss2:ae,ss3:F,ss4:I,ss5:oe,sz1:se,sz3:ce,sz11:le,sz13:ue,sz21:de,sz23:fe,sz31:pe,sz33:me}=e,U.xgh2=e.xgh2,U.xgh3=e.xgh3,U.xgh4=e.xgh4,U.xh2=e.xh2,U.xh3=e.xh3,U.xi2=e.xi2,U.xi3=e.xi3,U.xl2=e.xl2,U.xl3=e.xl3,U.xl4=e.xl4,U.zmol=e.zmol,U.zmos=e.zmos,{nm:O,z1:H,z3:ve,z11:ye,z13:be,z21:xe,z23:Se,z31:Ce,z33:we}=e;let t=qh(U,{inclo:E,init:U.init,ep:U.ecco,inclp:U.inclo,nodep:U.nodeo,argpp:U.argpo,mp:U.mo,opsmode:U.operationmode});U.ecco=t.ep,U.inclo=t.inclp,U.nodeo=t.nodep,U.argpo=t.argpp,U.mo=t.mp,w=0,T=0,D=0;let n=Yh({cosim:f,emsq:x,argpo:U.argpo,s1:ee,s2:N,s3:te,s4:ne,s5:re,sinim:p,ss1:ie,ss2:ae,ss3:F,ss4:I,ss5:oe,sz1:se,sz3:ce,sz11:le,sz13:ue,sz21:de,sz23:fe,sz31:pe,sz33:me,t:U.t,tc:he,gsto:U.gsto,mo:U.mo,mdot:U.mdot,no:U.no,nodeo:U.nodeo,nodedot:U.nodedot,xpidot:_e,z1:H,z3:ve,z11:ye,z13:be,z21:xe,z23:Se,z31:Ce,z33:we,ecco:U.ecco,eccsq:Ne,em:b,argpm:w,inclm:E,mm:D,nm:O,nodem:T,irez:U.irez,atime:U.atime,d2201:U.d2201,d2211:U.d2211,d3210:U.d3210,d3222:U.d3222,d4410:U.d4410,d4422:U.d4422,d5220:U.d5220,d5232:U.d5232,d5421:U.d5421,d5433:U.d5433,dedt:U.dedt,didt:U.didt,dmdt:U.dmdt,dnodt:U.dnodt,domdt:U.domdt,del1:U.del1,del2:U.del2,del3:U.del3,xfact:U.xfact,xlamo:U.xlamo,xli:U.xli,xni:U.xni});U.irez=n.irez,U.atime=n.atime,U.d2201=n.d2201,U.d2211=n.d2211,U.d3210=n.d3210,U.d3222=n.d3222,U.d4410=n.d4410,U.d4422=n.d4422,U.d5220=n.d5220,U.d5232=n.d5232,U.d5421=n.d5421,U.d5433=n.d5433,U.dedt=n.dedt,U.didt=n.didt,U.dmdt=n.dmdt,U.dnodt=n.dnodt,U.domdt=n.domdt,U.del1=n.del1,U.del2=n.del2,U.del3=n.del3,U.xfact=n.xfact,U.xlamo=n.xlamo,U.xli=n.xli,U.xni=n.xni}U.isimp!==1&&(m=U.cc1*U.cc1,U.d2=4*ke*B*m,L=U.d2*B*U.cc1/3,U.d3=(17*ke+P)*L,U.d4=.5*L*ke*B*(221*ke+31*P)*U.cc1,U.t3cof=U.d2+2*m,U.t4cof=.25*(3*U.d3+U.cc1*(12*U.d2+10*m)),U.t5cof=.2*(3*U.d4+12*U.cc1*U.d3+6*U.d2*U.d2+15*m*(2*U.d2+m)))}tg(U,0),U.init=`n`}function rg(e,t){let n=e.substring(2,7),r=parseInt(e.substring(18,20),10),i=parseFloat(e.substring(20,32)),a=parseFloat(e.substring(33,43)),o=parseFloat(`${e.substring(44,45)}.${e.substring(45,50)}E${e.substring(50,52)}`),s=parseFloat(`${e.substring(53,54)}.${e.substring(54,59)}E${e.substring(59,61)}`),c=parseFloat(t.substring(8,16))*Mh,l=parseFloat(t.substring(17,25))*Mh,u=parseFloat(`.${t.substring(26,33).replace(/\s/g,`0`)}`),d=parseFloat(t.substring(34,42))*Mh,f=parseFloat(t.substring(43,51))*Mh,p=parseFloat(t.substring(52,63))/Uh;a/=Uh*1440,o/=Uh*1440*1440;let m=r<57?r+2e3:r+1900,{mon:h,day:g,hr:_,minute:v,sec:y}=Wh(m,i),b=Kh(m,h,g,_,v,y),x={error:0,satnum:n,epochyr:r,epochdays:i,ndot:a,nddot:o,bstar:s,inclo:c,nodeo:l,ecco:u,argpo:d,mo:f,no:p,jdsatepoch:b};return ng(x,{opsmode:`i`,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}function ig(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,s=Number(e.MEAN_MOTION_DOT),c=Number(e.MEAN_MOTION_DDOT);s/=Uh*1440,c/=Uh*1440*1440;let l=Number(e.BSTAR),u=Number(e.INCLINATION)*Mh,d=Number(e.RA_OF_ASC_NODE)*Mh,f=Number(e.ECCENTRICITY),p=Number(e.ARG_OF_PERICENTER)*Mh,m=Number(e.MEAN_ANOMALY)*Mh,h=Number(e.MEAN_MOTION)/Uh,{mon:g,day:_,hr:v,minute:y,sec:b}=Wh(i,o),x=Kh(i,g,_,v,y,b),S={error:0,satnum:n,epochyr:a,epochdays:o,ndot:s,nddot:c,bstar:l,inclo:u,nodeo:d,ecco:f,argpo:p,mo:m,no:h,jdsatepoch:x};return ng(S,{opsmode:t,satn:S.satnum,epoch:S.jdsatepoch-2433281.5,xbstar:S.bstar,xecco:S.ecco,xargpo:S.argpo,xinclo:S.inclo,xmo:S.mo,xno:S.no,xnodeo:S.nodeo}),S}3*Float64Array.BYTES_PER_ELEMENT;var ag=149597870.7,og=23.4392911,sg=86400**2/ag**3,cg=1/ag;function Q(e){return e/ag*10}function lg(e){return e/10*ag}var ug=Math.cos(Math.PI/180*og),dg=Math.sin(Math.PI/180*og);function fg(e,t,n,r){let i=r??{x:0,y:0,z:0};return i.x=e,i.y=-t*dg+n*ug,i.z=-(t*ug+n*dg),i}var pg=Math.PI/180,mg=Math.cos(og*pg),hg=Math.sin(og*pg),gg=2440587.5;function _g(e){return new Date((e-gg)*864e5).toISOString()}function vg(e,t){let n=ig({OBJECT_NAME:t??String(e.noradCatId),OBJECT_ID:String(e.noradCatId),EPOCH:_g(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===eg.None?n:(console.warn(`buildSatrec: SGP4 init failed for NORAD ${e.noradCatId} (error=${n.error})`),null)}function yg(e,t){let n=tg(e,(t-e.jdsatepoch)*1440);if(!n||e.error!==eg.None)return null;let{x:r,y:i,z:a}=n.position;return[r,i,a]}function bg(e,t,n){let r=10/ag,i=e*r,a=t*r,o=n*r,s=a*mg+o*hg,c=-a*hg+o*mg;return a=s,o=c,[i,o,-a]}function xg(e,t){let n=yg(e,t);return n?bg(n[0],n[1],n[2]):null}function Sg(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}var Cg=700;function wg(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>Cg)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 Tg(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}}var Eg=null,Dg=null;function Og(){if(!Dg){Eg=[];let e=new MessageChannel;e.port1.onmessage=()=>Eg.shift()?.(),Dg=e.port2}return new Promise(e=>{Eg.push(e),Dg.postMessage(null)})}var kg=2451545,Ag=86400,jg=2440587.5,Mg=864e5;function Ng(e){return e/Mg+jg}function Pg(e){return Ng(e.getTime())}function Fg(e){return new Date((e-jg)*Mg)}function Ig(e){return(e-kg)*Ag}function Lg(e){return kg+e/Ag}var Rg=Math.PI/180;Math.cos(og*Rg),Math.sin(og*Rg),10/ag;function zg(e,t,n,r,i,a,o,s,c,l,u,d){e.a[t]=n,e.e[t]=r,e.i[t]=i,e.om[t]=a,e.w[t]=o,e.ma[t]=s,e.n[t]=c,e.epoch[t]=l,e.equatorial[t]=+!!u,e.flags[t]=d}function Bg(e,t,n,r){let i=n.data;if(r?.has(i.id))return e.kind[t]=0,!1;if(i.omm)e.kind[t]=3,e.satnum[t]=i.omm.noradCatId,e.bstar[t]=i.omm.bstar,e.ndot[t]=i.omm.meanMotionDot,e.nddot[t]=i.omm.meanMotionDdot;else if(i.satrec)e.kind[t]=3,e.satrec[t]=i.satrec;else if(i.q!=null&&i.tp!=null&&isFinite(i.q)&&isFinite(i.tp))e.kind[t]=2,e.q[t]=i.q,e.tp[t]=i.tp;else if(i.a!==0&&isFinite(i.a))e.kind[t]=1;else return e.kind[t]=0,!1;return zg(e,t,i.a,i.e,i.i,i.om,i.w,i.ma,i.n,i.epoch,i.equatorial,i.flags??0),!0}async function Vg(e,t,n=!1){let r=e.length,i=Wg(r);i.applyFlagFilter=n;let a=1/0,o=-1/0,s=performance.now();for(let n=0;n<r;n++){if((n&4095)==4095&&performance.now()-s>6&&(await Og(),s=performance.now()),!Bg(i,n,e[n],t))continue;let r=e[n].data;r.validityStart<a&&(a=r.validityStart),r.validityEnd>o&&(o=r.validityEnd)}return i.validityStart=a===1/0?-1/0:a,i.validityEnd=o===-1/0?1/0:o,i}var Hg=[{name:`kind`,make:e=>new Uint8Array(e)},{name:`equatorial`,make:e=>new Uint8Array(e)},{name:`a`,make:e=>new Float64Array(e)},{name:`e`,make:e=>new Float64Array(e)},{name:`i`,make:e=>new Float64Array(e)},{name:`om`,make:e=>new Float64Array(e)},{name:`w`,make:e=>new Float64Array(e)},{name:`ma`,make:e=>new Float64Array(e)},{name:`n`,make:e=>new Float64Array(e)},{name:`epoch`,make:e=>new Float64Array(e)},{name:`q`,make:e=>new Float64Array(e)},{name:`tp`,make:e=>new Float64Array(e)},{name:`flags`,make:e=>new Uint8Array(e)},{name:`visibleFromDays`,make:e=>new Float32Array(e).fill(NaN)},{name:`satnum`,make:e=>new Int32Array(e)},{name:`bstar`,make:e=>new Float64Array(e)},{name:`ndot`,make:e=>new Float64Array(e)},{name:`nddot`,make:e=>new Float64Array(e)},{name:`satrec`,make:e=>Array(e).fill(null),transferable:!1}];function Ug(e){let t=[];for(let n of Hg)n.transferable!==!1&&t.push(e[n.name].buffer);return t}function Wg(e){let t={count:e,applyFlagFilter:!1,validityStart:-1/0,validityEnd:1/0,pickBase:0};for(let n of Hg)t[n.name]=n.make(e);return t}function Gg(e,t){return e.get(t)?.name||null}function Kg(e,t){return e.get(t)?.isMinor??!1}function qg(e,t){let n=e.get(t);return{name:n?.name||null,isMinor:n?.isMinor??!1}}function Jg(e,t,n,r){let i=e.scale[t]===rn.PLANET,a=e.omDot[t],o=e.wDot[t],s=Ch(e,t);if(s===null)return null;let{name:c,isMinor:l}=qg(n,s);return{id:s,name:c,isMinor:l,hasLocalized:e.hasLocalized[t]===1,flags:e.flags[t],objectType:e.objectType[t],parentId:`${r}-${e.parentId[t]}`,radiusKm:e.radiusKm[t],a:i?e.a[t]/ag:e.a[t],e:e.e[t],i:e.i[t],om:e.om[t],w:e.w[t],ma:e.ma[t],n:i?e.n[t]*360:e.n[t],epoch:e.epochJd[t],omDot:a===0?void 0:a,wDot:o===0?void 0:o,equatorial:i,validityStart:e.validityStart,validityEnd:e.validityEnd,orbitalSource:e.source,visibleFromDays:e.visibleFromDays[t]}}function Yg(e,t,n,r){let i=Ch(e,t);if(i===null)return null;let{name:a,isMinor:o}=qg(n,i);return{id:i,name:a,isMinor:o,hasLocalized:e.hasLocalized[t]===1,flags:e.flags[t],objectType:e.objectType[t],parentId:`${r}-${e.parentId[t]}`,radiusKm:e.radiusKm[t],a:0,e:e.e[t],i:e.i[t],om:e.om[t],w:e.w[t],ma:0,n:0,epoch:e.epochJd[t],q:e.q[t],tp:e.tp[t],validityStart:e.validityStart,validityEnd:e.validityEnd,orbitalSource:e.source,visibleFromDays:e.visibleFromDays[t]}}var Xg=new WeakMap,Zg=new WeakMap;function Qg(e,t){return{noradCatId:e.id[t],epochJd:e.epochJd[t],meanMotion:e.n[t],eccentricity:e.e[t],inclination:e.i[t],raOfAscNode:e.om[t],argOfPericenter:e.w[t],meanAnomaly:e.ma[t],bstar:e.bstar[t],meanMotionDot:e.meanMotionDot[t],meanMotionDdot:e.meanMotionDdot[t],elementSetNo:e.elementSetNo[t],revAtEpoch:e.revAtEpoch[t]}}var $g={get omm(){let e=Zg.get(this);return e&&Qg(e[0],e[1])},get satrec(){let e=this,t=Xg.get(e);return t===void 0&&(t=vg(e.omm,e.name??void 0),Xg.set(e,t)),t??void 0}};function e_(e,t,n,r){let i=Ch(e,t);if(i===null)return null;let{name:a,isMinor:o}=qg(n,i),s=Object.assign(Object.create($g),{id:i,name:a,isMinor:o,hasLocalized:e.hasLocalized[t]===1,flags:e.flags[t],objectType:e.objectType[t],parentId:`${r}-${e.parentId[t]}`,radiusKm:e.radiusKm[t],a:e.a[t]/ag,e:e.e[t],i:e.i[t],om:e.om[t],w:e.w[t],ma:e.ma[t],n:e.n[t]*360,epoch:e.epochJd[t],equatorial:!0,validityStart:e.validityStart,validityEnd:e.validityEnd,orbitalSource:e.source,visibleFromDays:e.visibleFromDays[t]});return Zg.set(s,[e,t]),s}function t_(e,t,n,r){return e.kind===`parabolic`?Yg(e,t,n,r):e.kind===`sgp4`?e_(e,t,n,r):Jg(e,t,n,r)}function n_(e,t,n,r,i,a){if(a&&i!==void 0&&a.has(i))return n.kind[r]=0,!1;if(e.kind===`parabolic`){let i=e.q[t],a=e.tp[t];return isFinite(i)&&isFinite(a)?(n.kind[r]=2,n.q[r]=i,n.tp[r]=a,zg(n,r,0,e.e[t],e.i[t],e.om[t],e.w[t],0,0,e.epochJd[t],!1,e.flags[t]),n.visibleFromDays[r]=e.visibleFromDays[t],!0):(n.kind[r]=0,!1)}if(e.kind===`sgp4`)return n.kind[r]=3,n.satrec[r]=null,n.satnum[r]=e.id[t],n.bstar[r]=e.bstar[t],n.ndot[r]=e.meanMotionDot[t],n.nddot[r]=e.meanMotionDdot[t],zg(n,r,e.a[t]/ag,e.e[t],e.i[t],e.om[t],e.w[t],e.ma[t],e.n[t]*360,e.epochJd[t],!0,e.flags[t]),n.visibleFromDays[r]=e.visibleFromDays[t],!0;let o=e.scale[t]===rn.PLANET,s=o?e.a[t]/ag:e.a[t];return s!==0&&isFinite(s)?(n.kind[r]=1,zg(n,r,s,e.e[t],e.i[t],e.om[t],e.w[t],e.ma[t],o?e.n[t]*360:e.n[t],e.epochJd[t],o,e.flags[t]),n.visibleFromDays[r]=e.visibleFromDays[t],!0):(n.kind[r]=0,!1)}var r_={"naif-10":`#ffdd44`,"naif-199":`#b5b5b5`,"naif-299":`#e8cda0`,"naif-399":`#4da6ff`,"naif-301":`#888888`,"naif-499":`#c1440e`,"naif-401":`#aa9988`,"naif-402":`#aa9988`,"naif-599":`#d4a66a`,"naif-501":`#8a762e`,"naif-502":`#7c7f6c`,"naif-503":`#7e6c5e`,"naif-504":`#6c6453`,"naif-699":`#e8d8a0`,"naif-601":`#aba890`,"naif-602":`#71a29f`,"naif-603":`#6c6645`,"naif-604":`#494a2a`,"naif-605":`#5c5a3c`,"naif-606":`#835422`,"naif-608":`#776b60`,"naif-799":`#87ceeb`,"naif-701":`#b0b0b0`,"naif-702":`#a8a8a8`,"naif-703":`#62534c`,"naif-704":`#626a62`,"naif-705":`#625252`,"naif-899":`#3f54ba`,"naif-801":`#7c757c`,"naif-999":`#b48977`,"naif-2000001":`#9b9087`},i_=`#cccccc`,a_=`#fcb493`,o_=`#c7ccda`,s_=`#ffe89e`,c_=`#ccb49a`,l_=`#d8ffe8`,u_=`#e8a85c`,d_=`#bed4ec`,f_=`#d5cfe7`,p_=`naif-10`,m_=`naif-399`,h_=new Set(`naif-0.naif-9.spkid-20000002.spkid-20000003.spkid-20000007.spkid-20000010.spkid-20000015.spkid-20000031.spkid-20000052.spkid-20000065.spkid-20000088.spkid-20000107.spkid-20000130.spkid-20000511.spkid-20000588.spkid-20000704.spkid-20001862.spkid-1000592.spkid-1000616.spkid-1000630.spkid-1000639.spkid-1000648.spkid-1000651.spkid-1000669.spkid-1000690.spkid-1000738.spkid-1000742.spkid-1000749.spkid-1000755.spkid-1000778.spkid-1000845.spkid-1000872.spkid-1000882.spkid-1000899.spkid-1000945.spkid-1000967.spkid-1001121`.split(`.`));function g_(e){if(r_[e.id])return r_[e.id];let{objectType:t,parentId:n}=e;if(t===G.BARYCENTER){if(e.id===`naif-0`)return r_[`naif-10`];if(e.id===`naif-9`)return r_[`naif-999`];let t=`naif-${e.id.replace(`naif-`,``)}99`;if(r_[t])return r_[t]}if(t===G.STAR)return s_;if(t===G.PLANET||t===G.DWARF_PLANET)return a_;if(t===G.MOON)return o_;if(_n(t))return c_;if(t===G.COMET)return l_;if(t===G.DEBRIS)return u_;if(t===G.SPACECRAFT){if(n===`naif-399`)return d_;if(n===`naif-0`||n===`naif-10`)return f_}return i_}var __=`#6b6b6b`;function v_(e){return e.color??__}function y_(e){let t=0;for(let n=0;n<e.length;n++)t=(t<<5)-t+e.charCodeAt(n)|0;return t>>>0}function b_(e,t){let n=Array.from({length:t},()=>[]);for(let r of e)n[y_(r.data.id)%t].push(r);return n}function x_(e,t,n){return{buckets:b_(t,t.length>=n*600?n:1),baseWorker:y_(e)%n}}async function S_(e,t,n){let r=t.length>=n*600?n:1,i=Array.from({length:r},()=>[]),a=performance.now();for(let e=0;e<t.length;e++){(e&16383)==16383&&performance.now()-a>6&&(await Og(),a=performance.now());let n=t[e];i[y_(n.data.id)%r].push(n)}return{buckets:i,baseWorker:y_(e)%n}}function C_(e){let t=e.indexOf(`#`);return t<0?e:e.substring(0,t)}var w_=4096,T_=.75;function E_(e){let t=(e^Math.floor(e/4294967296))>>>0;return t=Math.imul(t^t>>>16,73244475),t=Math.imul(t^t>>>16,73244475),(t^t>>>16)>>>0}var D_=class{table=new Uint32Array(w_);mask=w_-1;count=0;constructor(e){this.keyOfRef=e}get size(){return this.count}slot(e){let t=E_(e)&this.mask;for(;;){let n=this.table[t];if(n===0||this.keyOfRef(n-1)===e)return t;t=t+1&this.mask}}get(e){let t=this.table[this.slot(e)];return t===0?void 0:t-1}has(e){return this.table[this.slot(e)]!==0}set(e,t,n=()=>!0){let r=this.slot(e),i=this.table[r];return i===0?(this.count++,this.count>this.table.length*T_&&(this.grow(),r=this.slot(e)),this.table[r]=t+1,!0):(n(i-1)&&(this.table[r]=t+1),!1)}grow(){let e=this.table;this.table=new Uint32Array(e.length*2),this.mask=this.table.length-1;for(let t of e){if(t===0)continue;let e=E_(this.keyOfRef(t-1))&this.mask;for(;this.table[e]!==0;)e=e+1&this.mask;this.table[e]=t}}*values(){for(let e of this.table)e!==0&&(yield e-1)}*keys(){for(let e of this.values())yield this.keyOfRef(e)}},O_=2**20,k_=4096,A_=6;function j_(e){let t=e>>>0;return t=Math.imul(t^t>>>16,73244475),t=Math.imul(t^t>>>16,73244475),(t^t>>>16)>>>0}var M_=class{chunks=[];rowOf=new D_(e=>this.keyOfRef(e));cache=new Map;placeholders=new Map;parentIdType=`naif`;constructor(e){this.labels=e}async addChunk(e,t,n){if(this.parentIdType=t,e.rowCount>=O_)throw Error(`MinorBucket: chunk too large (${e.rowCount} rows)`);let r=this.chunks.length;this.chunks.push(e);let i=0,a=this.placeholders.size>0,o=performance.now();for(let t=0;t<e.rowCount;t++){t%k_===k_-1&&performance.now()-o>A_&&(await Og(),o=performance.now());let s=wh(e,t);if(!(s===ph||n&&!n.has(s))&&(this.rowOf.set(s,r*O_+t,e=>Math.floor(e/O_)<=r)&&i++,a)){let n=Ch(e,t),r=n===null?void 0:this.placeholders.get(n);if(r){let n=t_(e,t,this.labels,this.parentIdType);n&&Object.assign(r.data,n)}}}return i}addPlaceholder(e){this.placeholders.set(e.data.id,e),this.cache.set(e.data.id,e)}keyOfRef(e){let t=Math.floor(e/O_);return wh(this.chunks[t],e-t*O_)}get size(){let e=0;for(let t of this.placeholders.keys())this.hasRow(t)||e++;return this.rowOf.size+e}hasRow(e){let t=yh(e);return t!==null&&this.rowOf.has(t)}has(e){return this.hasRow(e)||this.placeholders.has(e)}hasKey(e){if(this.rowOf.has(e))return!0;if(this.placeholders.size===0)return!1;let t=vh(e);return t!==null&&this.placeholders.has(t)}*ids(){for(let e of this.rowOf.keys()){let t=vh(e);t!==null&&(yield t)}for(let e of this.placeholders.keys())this.hasRow(e)||(yield e)}*keys(){yield*this.rowOf.keys();for(let e of this.placeholders.keys()){let t=yh(e);t!==null&&!this.rowOf.has(t)&&(yield t)}}get(e){let t=this.cache.get(e);if(t)return t;let n=yh(e),r=n===null?void 0:this.rowOf.get(n);if(r===void 0)return;let i=Math.floor(r/O_),a=t_(this.chunks[i],r-i*O_,this.labels,this.parentIdType);if(!a)return;let o={data:a,position:null};return this.cache.set(e,o),o}getKey(e){let t=vh(e);return t===null?void 0:this.get(t)}*values(){for(let e of this.ids()){let t=this.get(e);t&&(yield t)}}cloudColor(){let e=this.chunks.find(e=>e.rowCount>0);if(!e)return`#888888`;let t=t_(e,0,this.labels,this.parentIdType);return t?g_(t):`#888888`}async buildWorkerGroups(e,t,n,r){let i=this.rowOf.size,a=i>=t*600?t:1,o=new Float64Array(i),s=new Uint8Array(i),c=Array(a).fill(0),l=0,u=performance.now();for(let e of this.rowOf.values()){if(l===i)break;l%16384==0&&performance.now()-u>6&&(await Og(),u=performance.now());let t=Math.floor(e/O_),n=a===1?0:j_(this.chunks[t].id[e-t*O_])%a;o[l]=e,s[l]=n,c[n]++,l++}let d=[];for(let e=0;e<a;e++){let t=Wg(c[e]);t.applyFlagFilter=!1,d.push({cols:t,colors:r?new Float32Array(c[e]*3):null,keys:new Float64Array(c[e]).fill(ph)})}let f=Array(a).fill(1/0),p=Array(a).fill(-1/0),m=Array(a).fill(0),h=r?new X:null;u=performance.now();for(let e=0;e<l;e++){(e&16383)==16383&&performance.now()-u>6&&(await Og(),u=performance.now());let t=o[e],r=Math.floor(t/O_),i=t-r*O_,a=this.chunks[r],c=s[e],l=d[c],g=m[c]++,_=wh(a,i);if(l.keys[g]=_,n_(a,i,l.cols,g,_,n)&&(a.validityStart<f[c]&&(f[c]=a.validityStart),a.validityEnd>p[c]&&(p[c]=a.validityEnd)),l.colors&&h){let e=t_(a,i,this.labels,this.parentIdType);h.set(e?g_(e):`#ffffff`),l.colors[g*3]=h.r,l.colors[g*3+1]=h.g,l.colors[g*3+2]=h.b}}for(let e=0;e<a;e++)d[e].cols.validityStart=f[e]===1/0?-1/0:f[e],d[e].cols.validityEnd=p[e]===-1/0?1/0:p[e];return{groups:d,baseWorker:y_(e)%t}}};function N_(e){return e===`naif-0`||e===`naif-10`}function P_(e){let t=/^naif-([1-9])$/.exec(e);return t?`naif-${t[1]}99`:null}function F_(e){return e===`naif-0`?p_:P_(e)}function I_(e){if(!N_(e))return P_(e)??e}function L_(e,t){e.data=t.data,t.orbitElements!==void 0&&(e.orbitElements=t.orbitElements),e.orbitCenterId=t.orbitCenterId??e.orbitCenterId,e.trailAnchorId=t.trailAnchorId}var R_=class{bodiesById=new Map;majorBodies=[];asteroidBodiesByZone=new Map;spacecraftByParent=new Map;focusFeature=null;dirtyAsteroidZones=new Set;dirtySpacecraftGroups=new Set;minorStreaming=!1;dataVersion=0;#e=Ge(0);get minorBodyVersion(){return Vt(this.#e)}set minorBodyVersion(e){Ke(this.#e,e,!0)}#t=Ge(0);get orientationVersion(){return Vt(this.#t)}set orientationVersion(e){Ke(this.#t,e,!0)}orientationRead=new Set;childrenByParent=new Map;moonMaxAByParent=new Map;addListeners=new Set;onBodiesAdded(e){return this.addListeners.add(e),()=>this.addListeners.delete(e)}notifyBodiesAdded(){this.dataVersion++;for(let e of this.addListeners)e()}getBody(e,t){let n=this.bodiesById.get(e);if(n)return n;if(this.focusFeature?.data.id===e)return this.focusFeature;if(t!==void 0)return this.spacecraftByParent.get(t)?.get(e)??this.asteroidBodiesByZone.get(t)?.get(e);for(let t of this.spacecraftByParent.values()){let n=t.get(e);if(n)return n}for(let t of this.asteroidBodiesByZone.values()){let n=t.get(e);if(n)return n}}addBodies(e){let t=!1;for(let n of e){let e=this.bodiesById.get(n.data.id);e?L_(e,n):(t=!0,this.bodiesById.set(n.data.id,n));let r=this.childrenByParent.get(n.data.parentId)??new Set;if(r.add(n.data.id),this.childrenByParent.set(n.data.parentId,r),n.data.objectType===G.MOON){let e=this.moonMaxAByParent.get(n.data.parentId)??0;n.data.a>e&&this.moonMaxAByParent.set(n.data.parentId,n.data.a)}}this.dataVersion++,t&&this.notifyBodiesAdded()}putSpacecraft(e){let t=e.data.id,n=this.spacecraftBucket(e.data.parentId),r=n.get(t)??this.bodiesById.get(t);if(!r){for(let e of this.spacecraftByParent.values())if(r=e.get(t),r){e.delete(t);break}}return this.dataVersion++,r?(L_(r,e),this.bodiesById.delete(t),n.set(t,r),!1):(n.set(t,e),!0)}asteroidBucket(e,t){let n=this.asteroidBodiesByZone.get(e);return n||this.asteroidBodiesByZone.set(e,n=new M_(t)),n}spacecraftBucket(e){let t=this.spacecraftByParent.get(e);return t||this.spacecraftByParent.set(e,t=new Map),t}flushMinor(e){this.asteroidBodiesByZone=new Map(this.asteroidBodiesByZone),this.spacecraftByParent=new Map(this.spacecraftByParent),this.minorBodyVersion++,this.dataVersion++,e&&this.notifyBodiesAdded()}getChildren(e){return this.childrenByParent.get(e)}findAsteroidZone(e){for(let[t,n]of this.asteroidBodiesByZone)if(n.has(e))return t}elementRow(e){let t=e.data;if(t.orbitalSource!==W.SPICE)return t;let n=this.findAsteroidZone(t.id);return n===void 0?void 0:this.asteroidBodiesByZone.get(n)?.get(t.id)?.data}maxMoonA(e){return this.moonMaxAByParent.get(e)}getSystemExtent(e){return this.moonMaxAByParent.get(e)??.01}isSystemBody(e){return N_(e.data.parentId)?!1:this.bodiesById.get(e.data.parentId)?.data.objectType!==G.BARYCENTER}isInSystem(e,t){return t?e===t?!0:this.childrenByParent.get(t)?.has(e)??!1:!1}getObjectCounts(){let e=0,t=0,n=0;for(let r of this.bodiesById.values()){let i=r.data.objectType;i===G.PLANET||i===G.DWARF_PLANET?e++:i===G.MOON?t++:i===G.SPACECRAFT&&n++}let r=this.spacecraftByParent.get(`naif-399`)?.size??0;r+=this.asteroidBodiesByZone.get(`earth`)?.size??0;for(let[e,t]of this.spacecraftByParent)e!==`naif-399`&&(n+=t.size);let i=0;for(let[e,t]of this.asteroidBodiesByZone)e!==`earth`&&(i+=t.size);for(let e of this.bodiesById.values())(_n(e.data.objectType)||e.data.objectType===G.COMET)&&i++;return{planets:e,moons:t,probes:n,earthSatellites:r,smallBodies:i}}};function z_(e,t,n){return[e[0]+(t[0]-e[0])*n,e[1]+(t[1]-e[1])*n,e[2]+(t[2]-e[2])*n]}function B_(e,t){let n=e[0]-t[0],r=e[1]-t[1],i=e[2]-t[2];return Math.sqrt(n*n+r*r+i*i)}function V_(e,t,n,r){let i=e[0]-n[0],a=e[1]-n[1],o=e[2]-n[2],s=t[0]-n[0],c=t[1]-n[1],l=t[2]-n[2],u=Math.sqrt(i*i+a*a+o*o),d=Math.sqrt(s*s+c*c+l*l);if(u<1e-9||d<1e-9)return z_(e,t,r);let f=i/u,p=a/u,m=o/u,h=s/d,g=c/d,_=l/d,v=Math.max(-1,Math.min(1,f*h+p*g+m*_)),y=Math.acos(v),b=u+(d-u)*r;if(y<1e-4||Math.PI-y<1e-4)return z_(e,t,r);let x=Math.sin(y),S=Math.sin((1-r)*y)/x,C=Math.sin(r*y)/x,w=S*f+C*h,T=S*p+C*g,E=S*m+C*_;return[n[0]+w*b,n[1]+T*b,n[2]+E*b]}var H_={metadata:.12,ephemeris:.55,majors:.8,labels:.92,done:1},U_=[`metadata`,`ephemeris`,`majors`,`labels`,`done`],W_=.9,G_=new class{#e=0;#t=H_.metadata;#n=0;#r=0;#i=!1;#a=Ge(0);get value(){return Vt(this.#a)}set value(e){Ke(this.#a,e,!0)}get active(){return this.#i}#o(){let e=this.#t-this.#e,t=this.#r>0?Math.min(this.#n/this.#r,1):0,n=this.#e+e*t*W_;n>this.value&&(this.value=n)}reset(){this.#e=0,this.#t=H_.metadata,this.#n=0,this.#r=0,this.#i=!0,this.value=0}reach(e){if(!this.#i)return;let t=H_[e];if(t<=this.#e)return;this.#e=t,this.value<t&&(this.value=t);let n=U_[U_.indexOf(e)+1];this.#t=n?H_[n]:t,this.#n=0,this.#r=0,e===`done`&&(this.value=1,this.#i=!1)}announce(e){!this.#i||e<=0||(this.#r+=e,this.#o())}addBytes(e){this.#i&&(this.#n+=e,this.#o())}},K_=3e4;function q_(e,t){if(t||!G_.active||!e.body)return e;let n=Number(e.headers.get(`content-length`));if(!Number.isFinite(n)||n<=0)return e;G_.announce(n);let r=new TransformStream({transform(e,t){G_.addBytes(e.byteLength),t.enqueue(e)}});return new Response(e.body.pipeThrough(r),{status:e.status,statusText:e.statusText,headers:e.headers})}async function J_(e,t={},n=K_){let r=new AbortController,i=setTimeout(()=>r.abort(),n),a=()=>r.abort();t.signal?.addEventListener(`abort`,a,{once:!0});try{return q_(await fetch(e,{...t,signal:r.signal}),t.priority===`low`)}catch(i){throw r.signal.aborted&&!t.signal?.aborted?Error(`Request timed out after ${n} ms: ${e}`,{cause:i}):i}finally{clearTimeout(i),t.signal?.removeEventListener(`abort`,a)}}var Y_=new Map,X_=new Map,Z_=null;function Q_(){if(Z_)return Z_;let e=(async()=>{let e=await J_(`${Wt()}/v1/systems/global.json`);if(!e.ok)return;let t=await e.json();if(t.gm)for(let[e,n]of Object.entries(t.gm))X_.set(parseInt(e,10),n);if(t.nut_prec_angles)for(let[e,n]of Object.entries(t.nut_prec_angles))Y_.set(parseInt(e,10),n)})();return e.catch(()=>{Z_===e&&(Z_=null)}),Z_=e,e}function $_(e){return e>=100?Math.trunc(e/100):e}function ev(e){return Y_.get(e)}function tv(e){return X_.get(e)}var nv=132712440018,rv=86400;function iv(e){if(!N_(e.parentId))return;let t=Number(e.id.replace(/^naif-/,``));if(!Number.isFinite(t))return;let n=tv(t>=1&&t<=9?t*100+99:t),r=e.a*ag;if(!(!n||!(n>0)||!(r>0)))return r*(1-(Number.isFinite(e.e)?Math.min(Math.max(e.e,0),.99):0))*Math.cbrt(n/(3*nv))/ag}var av=`class-`,ov=`flag-`,sv=`cat-`;`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`;var cv=`${sv}asteroids`,lv=`${sv}comets`,uv=`${sv}satellites`,dv=`${sv}debris`;`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`,`${sv}`;var fv={neo:1,pha:2},pv=new Set([`ETc`,`JFc`,`JFC`,`CTc`,`HTC`,`PAR`,`HYP`,`COM`]);function mv(e){return pv.has(e)?`comet`:`asteroid`}function hv(e,t){return e===t?!0:e===null||t===null||e.kind!==t.kind?!1:e.kind===`class`&&t.kind===`class`?e.className===t.className:e.kind===`category`&&t.kind===`category`?e.category===t.category:e.kind===`flag`&&t.kind===`flag`?e.flag===t.flag:!1}var gv=null;function _v(){if(gv)return gv;let e=J_(`${Wt()}/v1/groups/__index__.json`).then(e=>{if(!e.ok)throw Error(`Failed to fetch group index: ${e.status}`);return e.json()});return gv=e,e.catch(()=>{gv===e&&(gv=null)}),gv}var vv=[`planets`,`dwarfPlanets`,`moons`,`asteroids`,`comets`,`spacecraft`,`satellites`,`debris`,`orbits`,`labels`,`halos`,`nomenclature`,`stars`],yv=new Set(vv),bv={[G.PLANET]:`planets`,[G.DWARF_PLANET]:`dwarfPlanets`,[G.MOON]:`moons`,[G.ASTEROID]:`asteroids`,[G.ASTEROID_INNER]:`asteroids`,[G.ASTEROID_MAIN_BELT]:`asteroids`,[G.ASTEROID_TROJAN]:`asteroids`,[G.ASTEROID_CENTAUR]:`asteroids`,[G.ASTEROID_TNO]:`asteroids`,[G.COMET]:`comets`,[G.DEBRIS]:`debris`},xv=`small_bodies/`,Sv=new Set([`COM`,`PAR`,`HYP`,`HYA`,`JFC`,`JFc`,`HTC`,`CTc`]);function Cv(e){return e===`moons`||e.startsWith(`moons/`)||e===`small_body_moons`?`moons`:e.startsWith(`probes/`)?`spacecraft`:e.startsWith(xv)?Sv.has(e.slice(13))?`comets`:`asteroids`:null}function wv(e,t){return e===G.SPACECRAFT?t===`naif-399`?`satellites`:`spacecraft`:bv[e]??null}var Tv=class{skipped;hiddenIds;onChange=null;constructor(e={}){let t=new Set;for(let n of vv)e[n]===!1&&t.add(n);this.skipped=t,this.hiddenIds=new Set(t)}isVisible(e){return!this.hiddenIds.has(e)}setVisible(e,t){t!==this.isVisible(e)&&(t?this.hiddenIds.delete(e):this.hiddenIds.add(e),this.onChange?.())}static has(e){return yv.has(e)}skipsZone(e){if(e===`earth`)return this.skipped.has(`satellites`)&&this.skipped.has(`debris`);let t=Cv(e);return t!==null&&this.skipped.has(t)}hidesZone(e){let t=Cv(e);return t!==null&&!this.isVisible(t)}hidesBody(e,t){let n=wv(e,t);return n!==null&&!this.isVisible(n)}hidesSpacecraftGroup(e){return e===`naif-399`?!this.isVisible(`satellites`)&&!this.isVisible(`debris`):!this.isVisible(`spacecraft`)}};function Ev(e,t,n){return t!==`naif-399`||e.isVisible(`satellites`)===e.isVisible(`debris`)?n:n.filter(t=>!e.hidesBody(t.data.objectType,t.data.parentId))}var Dv=`small_bodies/`;function Ov(e,t){let n=e.findAsteroidZone(t);if(n&&n.startsWith(`small_bodies/`))return n.slice(13);let r=e.bodiesById.get(t);if(r?.data.objectType!==G.DWARF_PLANET)return null;let i=r.data.a,a=r.data.e;if(!N_(r.data.parentId)){let t=e.bodiesById.get(r.data.parentId);t?.data.a&&(i=t.data.a,a=t.data.e)}return fn(i,a)}function kv(e,t,n){if(n.kind===`class`||n.kind===`category`){let r=Ov(e,t);return r===null?!1:n.kind===`class`?r===n.className:mv(r)===n.category}let r=e.getBody(t);return r===void 0?!1:((r.data.flags??0)&n.mask)===n.mask}var $=function(e){return e[e.CLOSE=1]=`CLOSE`,e[e.FULL=2]=`FULL`,e[e.CAPPED=3]=`CAPPED`,e[e.FAR=4]=`FAR`,e[e.HIDE=5]=`HIDE`,e}({}),Av=1503,jv={[$.CLOSE]:.3,[$.FULL]:20,[$.FAR]:100,[$.HIDE]:1/0},Mv={[$.CLOSE]:.01,[$.FULL]:20,[$.FAR]:100,[$.HIDE]:1/0},Nv=1/3;function Pv(e,t,n,r){return e<=t[$.CLOSE]?$.CLOSE:e<=t[$.FULL]*(r?n:1)?$.FULL:e<=t[$.FAR]?$.FAR:$.HIDE}var Fv=new Tv,Iv=3,Lv=4e6/ag;function Rv(e){return _n(e)||e===G.COMET||e===G.DWARF_PLANET}var zv=class{#e=Ge(Ze(p_));get focusedBodyId(){return Vt(this.#e)}set focusedBodyId(e){Ke(this.#e,e,!0)}#t=Ge(null);get focusedSystemId(){return Vt(this.#t)}set focusedSystemId(e){Ke(this.#t,e,!0)}activeSystemId=null;isZoomedIn=!1;focusedBodyIdPlain=p_;focusedSystemIdPlain=null;travelSystemActive=!1;cameraDistThreeJS=0;lastRecomputeDist=-1;currentJd=0;hideThresholdAU=0;scaledPlanetary=jv;scaledSystem=Mv;fullMoonIds=new Set;moonVisibilityCache=new Map;pinned=new Set;constructor(e,t=()=>null,n=()=>null,r=()=>null,i=()=>Fv){this.bodies=e,this.getProbeStore=t,this.getEarthSatGroupFilter=n,this.getSmallBodyFilter=r,this.getLayers=i}getRequiredFlags(){let e=this.getSmallBodyFilter();return e?.kind===`flag`?e.mask:0}updateViewport(e){let t=(e/Av)**1.5,n=e=>({...e,[$.FULL]:e[$.FULL]*t,[$.FAR]:e[$.FAR]*t});this.scaledPlanetary=n(jv),this.scaledSystem=n(Mv)}updateCamera(e,t){this.cameraDistThreeJS=e,this.currentJd=t,this.moonVisibilityCache.clear(),this.travelSystemActive||this.refreshProbeFocusedSystem(),this.hideThresholdAU=this.computeHideThreshold(),this.isZoomedIn=e/10<this.hideThresholdAU,this.activeSystemId=this.isZoomedIn?this.focusedSystemIdPlain:null,Math.abs(e-this.lastRecomputeDist)>this.lastRecomputeDist*.005+.001&&(this.lastRecomputeDist=e,this.recomputeFullMoons())}refreshProbeFocusedSystem(){let e=this.getProbeStore();if(!e)return;let t=this.bodies.bodiesById.get(this.focusedBodyIdPlain);if(!t||t.data.orbitalSource!==W.SPICE_PROBE)return;let n=e.containingSystemAt(t.data.id,this.currentJd),r=n===null?e.stampedFitCenterAt(t.data.id,this.currentJd):`naif-${n}`;r!==this.focusedSystemIdPlain&&(this.focusedSystemId=r,this.focusedSystemIdPlain=r,this.lastRecomputeDist=-1)}resolveSystemId(e){let t=e.data.objectType===G.BARYCENTER&&N_(e.data.parentId)&&!N_(e.data.id),n=e.data.objectType===G.STAR||!t&&N_(e.data.parentId);if(t)return e.data.id;if(n)return Rv(e.data.objectType)?e.data.id:null;let r=this.bodies.bodiesById.get(e.data.parentId);return r&&!N_(r.data.parentId)?r.data.parentId:e.data.parentId}setTravelSystem(e){this.travelSystemActive=!0,e!==this.focusedSystemIdPlain&&(this.focusedSystemId=e,this.focusedSystemIdPlain=e,this.lastRecomputeDist=-1)}clearTravelSystem(){this.travelSystemActive=!1}setFocused(e){if(this.travelSystemActive=!1,e.data.id===this.focusedBodyIdPlain)return;this.focusedBodyId=e.data.id,this.focusedBodyIdPlain=e.data.id;let t=this.resolveSystemId(e);this.focusedSystemId=t,this.focusedSystemIdPlain=t,this.hideThresholdAU=this.computeHideThreshold(),this.isZoomedIn=this.cameraDistThreeJS/10<this.hideThresholdAU,this.activeSystemId=this.isZoomedIn?t:null,this.lastRecomputeDist=-1,this.recomputeFullMoons()}getMoonVisibility(e){if(this.getLayers().hidesBody(e.data.objectType,e.data.parentId))return $.HIDE;let t=this.moonVisibilityCache.get(e.data.id);if(t!==void 0)return t;let n,r=this.bodies.getBody(e.data.parentId),i=r!==void 0&&_n(r.data.objectType);if(!this.isInFocusedSystem(e.data.parentId))n=$.HIDE;else if(i&&!this.matchesSmallBodyClass(e.data.parentId))n=$.HIDE;else{let t=this.cameraDistThreeJS/10/e.data.a,r=e.data.id===this.focusedBodyIdPlain;n=Pv(t,this.scaledPlanetary,5,r),!i&&n===$.FULL&&!this.fullMoonIds.has(e.data.id)&&!r&&(n=$.CAPPED)}return this.moonVisibilityCache.set(e.data.id,n),n}setPinned(e){this.pinned=new Set(e)}isPinned(e){return this.pinned.has(e)}getPlanetVisibility(e,t){let n=this.pinned.has(e.data.id),r=this.ratioVisibility(e,t,n);return n&&r!==$.CLOSE?$.FULL:r}ratioVisibility(e,t,n){if(!n&&this.getLayers().hidesBody(e.data.objectType,e.data.parentId))return $.HIDE;if(e.data.orbitalSource===W.SPICE_PROBE)return this.getProbeVisibility(e,t);let r=this.getEarthSatGroupFilter();if(r&&e.data.parentId===`naif-399`&&!r.has(e.data.id))return $.HIDE;let i=e.data.objectType;if((_n(i)||i===G.COMET||i===G.DWARF_PLANET)&&!this.matchesSmallBodyClass(e.data.id))return $.HIDE;if(this.bodies.isSystemBody(e)){if(!this.isInFocusedSystem(e.data.parentId))return $.HIDE;let n=e.data.a;if(!n||n<=0)return $.FULL;let r=e.data.id===this.focusedBodyIdPlain;return Pv(t/10/n,this.scaledPlanetary,5,r)}let a=e.data.a;if(!N_(e.data.parentId)){let t=this.bodies.bodiesById.get(e.data.parentId);t?.data.a&&(a=t.data.a)}if(!a||a<0)return a===0&&e.data.e<.9&&console.warn(`No semi-major axis available for body ${e.data.id} (${e.data.name}), falling back to FULL visibility`),$.FULL;let o=e.data.id===this.focusedBodyIdPlain,s=Pv(t/10/a,this.scaledSystem,50,o);return s===$.CLOSE?$.FULL:s}getProbeVisibility(e,t){let n=this.getProbeStore();if((n?n.containingSystemAt(e.data.id,this.currentJd):null)===Iv&&this.getEarthSatGroupFilter())return $.HIDE;let r=e.data.id===this.focusedBodyIdPlain;if(!(n&&!n.hasHeliocentricFit(e.data.id,this.currentJd))){let t=this.bodies.bodiesById.get(p_),n=t?.position&&e.position?B_(e.position,t.position)/10:0;if(n===0)return $.FULL;let i=Pv(this.cameraDistThreeJS/10/n,this.scaledSystem,50,r);return i===$.CLOSE?$.FULL:i}if(!this.isProbeInFocusedSystem(e))return $.HIDE;let i=this.bodies.bodiesById.get(e.data.parentId);if(!i?.position||!e.position)return $.FULL;let a=B_(e.position,i.position)/10;return a===0||t/10/a<=this.scaledPlanetary[$.FULL]*(r?5:1)?$.FULL:$.HIDE}isProbeInFocusedSystem(e){let t=e.data.parentId;if(!N_(t)&&this.isInFocusedSystem(t))return!0;let n=this.getProbeStore();if(!n)return!1;let r=n.containingSystemAt(e.data.id,this.currentJd);return r!==null&&this.isInFocusedSystem(`naif-${r}`)}hasFullRendering(e){if(!this.activeSystemId||this.pinned.has(e.data.id)||this.isInActiveSystem(N_(e.data.parentId)?e.data.id:e.data.parentId))return!0;if(e.data.orbitalSource!==W.SPICE_PROBE)return!1;let t=this.getProbeStore();if(!t)return!1;let n=t.containingSystemAt(e.data.id,this.currentJd);return n!==null&&this.isInActiveSystem(`naif-${n}`)}isMoonGroupVisible(e){if(!this.getLayers().isVisible(`moons`)||!this.isInFocusedSystem(e))return!1;let t=this.bodies.maxMoonA(e);return t?this.cameraDistThreeJS/10/t<=this.scaledPlanetary[$.FAR]:!1}isSpacecraftGroupVisible(e){if(this.getLayers().hidesSpacecraftGroup(e))return!1;let t=this.bodies.bodiesById.get(e);if(e!==`naif-0`&&!t?.position)return!1;let n=this.activeSystemId;return N_(e)||t?.data.objectType===G.STAR?!n:n?e===n?!0:this.bodies.getChildren(n)?.has(e)??!1:!1}isAsteroidGroupVisible(e){if(this.getLayers().hidesZone(e)||this.activeSystemId||!this.bodies.bodiesById.get(`naif-10`)?.position)return!1;let t=this.getSmallBodyFilter();if(t&&e.startsWith(`small_bodies/`)){let n=e.slice(Dv.length);if(t.kind===`class`&&n!==t.className||t.kind===`category`&&mv(n)!==t.category)return!1}let n=dn[e];return n?this.cameraDistThreeJS/10/n.maxA<=this.scaledSystem[$.FAR]/3:!0}isInActiveSystem(e){return this.bodies.isInSystem(e,this.activeSystemId)}debugBody(e){let t=this.bodies.getBody(e);if(!t)return{id:e,found:!1};let n=t.data.objectType,r=n===G.MOON,i=this.getProbeStore(),a=r?this.getMoonVisibility(t):this.getPlanetVisibility(t,this.cameraDistThreeJS);return{id:e,name:t.data.name,objectType:G[n],orbitalSource:t.data.orbitalSource,parentId:t.data.parentId,a:t.data.a,jd:this.currentJd,isMoon:r,isSystemBody:this.bodies.isSystemBody(t),isInFocusedSystem_parent:this.isInFocusedSystem(t.data.parentId),focusedBodyId:this.focusedBodyIdPlain,focusedSystemId:this.focusedSystemIdPlain,activeSystemId:this.activeSystemId,isZoomedIn:this.isZoomedIn,hideThresholdAU:this.hideThresholdAU,containingSystemAt:i?i.containingSystemAt(t.data.id,this.currentJd):null,camDistAU:this.cameraDistThreeJS/10,visibility:$[a],hasFullRendering:this.hasFullRendering(t)}}isBodyInSystem(e,t){return e.data.id===t||this.bodies.isInSystem(e.data.parentId,t)}isInFocusedSystem(e){return this.bodies.isInSystem(e,this.focusedSystemIdPlain)}matchesSmallBodyClass(e){let t=this.getSmallBodyFilter();return t===null?!0:kv(this.bodies,e,t)}recomputeFullMoons(){this.fullMoonIds.clear();let e=this.focusedSystemIdPlain;if(!e)return;let t=this.cameraDistThreeJS/10,n=[];for(let r of this.bodies.getChildren(e)??[]){let e=this.bodies.bodiesById.get(r);e&&e.data.objectType===G.MOON&&t/e.data.a<=this.scaledPlanetary[$.FULL]&&n.push(e)}n.sort((e,t)=>e.data.a-t.data.a).slice(0,40).forEach(e=>this.fullMoonIds.add(e.data.id))}computeHideThreshold(){let e=this.focusedSystemIdPlain;return e?this.systemReachAU(e):1/0}systemReachAU(e){let t=this.bodies.maxMoonA(e);if(t)return 2*t;let n=this.bodies.getBody(e);if(!n)return 0;if(Rv(n.data.objectType))return Lv;let r=iv(n.data);return r?r*Nv:0}},Bv=``;function Vv(e){let t=new Map;if(!e)return t;for(let n of e.split(`
4051
- `)){let e=n.indexOf(Bv);if(e===-1)continue;let r=n.slice(0,e),i=n.slice(e+1),a=i.indexOf(Bv),o=a===-1?i:i.slice(0,a),s=a===-1?``:i.slice(a+1);t.set(r,{name:o,isMinor:s.includes(`m`)})}return t}var Hv=new Map;async function Uv(e=s()){let t=Hv.get(e);return t||(t=(async()=>{let t=Qt(e),n=await J_(t,{priority:`high`});if(!n.ok)throw Error(`Failed to fetch ${t}: ${n.status}`);let r=new DecompressionStream(`gzip`);return Vv(await new Response(n.body.pipeThrough(r)).text())})(),Hv.set(e,t),t.catch(()=>{Hv.get(e)===t&&Hv.delete(e)})),t}var Wv=class{map=new Map;constructor(e){this.capacity=e}getOrCompute(e,t){let n=this.map.get(e);if(n)return this.map.delete(e),this.map.set(e,n),n;let r=t();if(this.map.set(e,r),this.map.size>this.capacity){let e=this.map.keys().next().value;e!==void 0&&this.map.delete(e)}return r.catch(()=>{this.map.get(e)===r&&this.map.delete(e)}),r}};function Gv(e,t,n){let r=new DataView(e),i=r.getUint32(24,!0),a=(r.getUint8(28)&1)!=0,o=a?8:4,s=[],c=Zt;for(let t=0;t<i;t++){let n=r.getInt32(c,!0),i=r.getInt32(c+4,!0),l=r.getInt32(c+8,!0),u=r.getFloat32(c+12,!0),d=r.getUint16(c+16,!0),f=r.getUint8(c+18),p=r.getUint8(c+19)===1,m=r.getUint8(c+20),h=r.getUint16(c+22,!0),g=r.getFloat32(c+24,!0);c+=32;let _=ln(f,l)??``;_||console.warn(`chebyshev body[${t}] (naifId=${n}) has unknown id-type ${f}; routing keyed lookups will skip it`);let v=new Float64Array(h),y=new Float64Array(h),b=3*d,x=a?new Float64Array(b*h):new Float32Array(b*h),S=b*o;for(let t=0;t<h;t++){if(v[t]=r.getFloat64(c,!0),y[t]=r.getFloat64(c+8,!0),c+=16,a){let n=new Float64Array(e,c,b);x.set(n,t*b)}else{let n=new Float32Array(e,c,b);x.set(n,t*b)}c+=S}s.push({id:_,naifId:n,parentId:i,hasLocalized:p,objectType:m,radiusKm:u,visibleFromDays:g,coeffsPerAxis:d,startJds:v,endJds:y,coeffs:x})}return{startJd:t,endJd:n,bodies:s}}function Kv(e,t,n,r){let i=n*(r?8:4),a=new(r?Float64Array:Float32Array)(n);if(r&&t%8==0)return a.set(new Float64Array(e,t,n)),a;if(!r&&t%4==0)return a.set(new Float32Array(e,t,n)),a;let o=new DataView(e,t,i);if(r)for(let e=0;e<n;e++)a[e]=o.getFloat64(e*8,!0);else for(let e=0;e<n;e++)a[e]=o.getFloat32(e*4,!0);return a}function qv(e,t,n,r){let i=Kv(e,t,n===1?7:10,r);return n===1?{method:n,aKm:i[0],e:i[1],iRad:i[2],om0:i[3],w0:i[4],m0:i[5],tAnchorOffsetS:i[6]}:{method:n,aKm:i[0],e:i[1],iRad:i[2],om0:i[3],w0:i[4],m0:i[5],omDot:i[6],wDot:i[7],nMeanRadS:i[8],tAnchorOffsetS:i[9]}}var Jv=1e-7,Yv=.001,Xv=1,Zv=2,Qv=16,$v=32;function ey(e,t,n){let r=new DataView(e,t,$v),i=r.getInt32(0,!0),a=r.getUint8(4),o=r.getUint32(8,!0),s=r.getUint32(12,!0),c=r.getInt32(16,!0)*Jv,l=r.getInt32(20,!0)*Jv,u=r.getInt32(24,!0)*Yv,d=r.getUint32(28,!0),f=new Float64Array(d),p=new Float32Array(d),m=new Float32Array(d),h=new Float32Array(d);if(d>0){let r=new DataView(e,t+$v,d*Qv);for(let e=0;e<d;e++){let t=e*Qv;f[e]=n+r.getUint32(t,!0),p[e]=r.getInt32(t+4,!0)*Jv,m[e]=r.getInt32(t+8,!0)*Jv,h[e]=r.getInt32(t+12,!0)*Yv}}return{bodyNaifId:i,isStatic:(a&Xv)!==0,isDestroyed:(a&Zv)!==0,startEt:n+o,endEt:n+s,latRefDeg:c,lngRefDeg:l,altRefM:u,sampleEt:f,sampleLatDeg:p,sampleLngDeg:m,sampleAltM:h}}function ty(e,t,n,r){let i=n/(36*(r?8:4));return{method:3,coeffsPerAxis:12,nSeg:i,coeffs:Kv(e,t,i*3*12,r)}}function ny(e,t,n,r){let i=new DataView(e),a=i.getUint32(24,!0),o=i.getFloat32(28,!0),s=o*Ag,c=Ig(t),l=[],u=Zt;for(let t=0;t<a;t++){let n=i.getInt32(u,!0),a=i.getUint8(u+4),o=i.getUint8(u+5),d=i.getUint8(u+6)===1,f=(i.getUint8(u+7)&1)!=0,p=i.getUint16(u+8,!0),m=i.getUint16(u+10,!0),h=i.getInt32(u+12,!0),g=i.getUint8(u+16),_=i.getUint8(u+17);u+=20;let v=ln(a,n)??``;v||console.warn(`probes payload: probe[${t}] (value=${n}) has unknown id-type ${a}; skipping`);let y=null;if(h!==-1&&g!==255){let e=ln(g,h);e?y={id:e,idType:g,idValue:h}:console.warn(`probes payload: probe[${t}] has unknown fit-center id-type ${g}; falling back to zone default`)}let b=Array(p),x=Array(p),S=Array(p);for(let n=0;n<p;n++){let a=i.getUint8(u),o=i.getUint32(u+4,!0),l=u+8,d=c+(m+n)*s;if(b[n]=d,x[n]=d+s,a===0)S[n]={method:0};else if(a===1||a===2)S[n]=qv(e,l,a,r);else if(a===3)S[n]=ty(e,l,o,r);else throw Error(`Unknown probe sub-chunk method ${a} at probe ${t} sub ${n}`);u=l+o}let C;if(f){let n=i.getUint8(u);if(n!==4)throw Error(`probe ${t}: PROBE_FLAG_HAS_LANDED_RECORD set but trailing record method = ${n}, expected 4`);let r=i.getUint32(u+4,!0),a=u+8;C=ey(e,a,c),u=a+r}let w=Array(_);for(let e=0;e<_;e++)w[e]={startEt:i.getFloat64(u,!0),endEt:i.getFloat64(u+8,!0),systemNaifId:i.getUint8(u+16)},u+=17;l.push({id:v,probeId:n,hasLocalized:d,objectType:o,fitCenter:y,subStartEt:b,subEndEt:x,subChunks:S,landed:C,systemIntervals:w})}return{startJd:t,endJd:n,subchunkDays:o,probes:l}}function ry(e,t={}){let n=new DataView(e),r=n.getUint32(0,!0);if(r!==1346456915)throw Error(`Invalid position file: bad magic 0x${r.toString(16)}`);let i=n.getUint16(4,!0);if(i!==13)throw Error(`Unsupported position file version: ${i}`);let a=n.getUint8(6),o=n.getFloat64(8,!0),s=n.getFloat64(16,!0);if(a===0)return{kind:`elements`,columns:Dh(e,o,s)};if(a===1)return{kind:`chebyshev`,chunk:Gv(e,o,s)};if(a===2)return{kind:`probes`,chunk:ny(e,o,s,t.probesFloat64??!1)};throw Error(`Unknown position-file format: ${a}`)}function iy(e,t,n){let r=e.length;if(r===0||n<e[0]||n>=t[r-1])return-1;let i=0,a=r-1;for(;i<a;){let t=i+a+1>>>1;e[t]<=n?i=t:a=t-1}return n<t[i]?i:-1}function ay(e,t){let n=iy(e.startJds,e.endJds,t);if(n<0)return null;let r=e.startJds[n],i=e.endJds[n],a=2*(t-r)/(i-r)-1,o=e.coeffsPerAxis,s=e.coeffs,c=n*3*o,l=[0,0,0],u=2*a;for(let e=0;e<3;e++){let t=c+e*o;if(o===1){l[e]=s[t];continue}let n=0,r=0;for(let e=o-1;e>=1;e--){let i=s[t+e]+u*n-r;r=n,n=i}l[e]=s[t]+a*n-r}return l}function oy(e,t){let n=ay(e,t);return n===null?null:[Q(n[0]),Q(n[2]),-Q(n[1])]}function sy(e,t){let n=iy(e.startJds,e.endJds,t);if(n<0)return null;let r=e.startJds[n],i=e.endJds[n],a=2*(t-r)/(i-r)-1,o=2/(i-r),s=e.coeffsPerAxis,c=e.coeffs,l=n*3*s,u=[0,0,0],d=[0,0,0],f=2*a;for(let e=0;e<3;e++){let t=l+e*s;if(s===1){u[e]=c[t],d[e]=0;continue}let n=0,r=0;for(let e=s-1;e>=1;e--){let i=c[t+e]+f*n-r;r=n,n=i}u[e]=c[t]+a*n-r;let i=0,p=0;for(let e=s-2;e>=0;e--){let n=c[t+e+1]*(e+1)+f*i-p;p=i,i=n}d[e]=i*o}return{position:u,velocity:d}}Math.PI/180;var cy=180/Math.PI;ag/86400;var ly=1e-9,uy=1e-9;function dy(e,t,n){return e<t?t:e>n?n:e}function fy(e,t,n,r){let[i,a,o]=e,[s,c,l]=t,u=Math.hypot(i,a,o),d=s*s+c*c+l*l;if(u===0||n<=0||!isFinite(u)||!isFinite(d))return null;let f=a*l-o*c,p=o*s-i*l,m=i*c-a*s,h=Math.hypot(f,p,m);if(h===0)return null;let g=Math.acos(dy(m/h,-1,1)),_=Math.sin(g),v=(c*m-l*p)/n-i/u,y=(l*f-s*m)/n-a/u,b=(s*p-c*f)/n-o/u,x=Math.hypot(v,y,b),S=2/u-d/n;if(Math.abs(S)<1e-12)return null;let C=1/S,w=-p,T=f,E=Math.hypot(w,T),D;_<uy||E===0?D=0:(D=Math.acos(dy(w/E,-1,1)),T<0&&(D=2*Math.PI-D));let O;if(x<ly)O=0;else if(_<uy||E===0)O=Math.atan2(y,v),m<0&&(O=-O),O<0&&(O+=2*Math.PI);else{let e=(w*v+T*y)/(E*x);O=Math.acos(dy(e,-1,1)),b<0&&(O=2*Math.PI-O)}let k,A=i*s+a*c+o*l;if(x<ly&&(_<uy||E===0))k=Math.atan2(a,i),m<0&&(k=-k),k<0&&(k+=2*Math.PI);else if(x<ly){let e=(w*i+T*a)/(E*u);k=Math.acos(dy(e,-1,1)),o<0&&(k=2*Math.PI-k)}else{let e=(v*i+y*a+b*o)/(x*u);k=Math.acos(dy(e,-1,1)),A<0&&(k=2*Math.PI-k)}let j;if(x<1){let e=2*Math.atan2(Math.sqrt(1-x)*Math.sin(k/2),Math.sqrt(1+x)*Math.cos(k/2));j=e-x*Math.sin(e)}else if(x>1){let e=2*Math.atanh(Math.sqrt((x-1)/(x+1))*Math.tan(k/2));if(!isFinite(e))return null;j=x*Math.sinh(e)-e}else return null;let M=Math.abs(C),ee=Math.sqrt(n/(M*M*M))*cy;return{a:C,e:x,i:g*cy,om:D*cy,w:O*cy,ma:j*cy,n:ee,epoch:r,equatorial:!1}}function py(e,t){let n=e.subStartEt,r=e.subEndEt,i=n.length;if(i===0||t<n[0]||t>=r[i-1])return-1;let a=0,o=i-1;for(;a<o;){let e=a+o+1>>>1;n[e]<=t?a=e:o=e-1}return t<r[a]?a:-1}function my(e,t,n,r,i){let a=Math.cos(i),o=Math.sin(i),s=Math.cos(r),c=Math.sin(r),l=Math.cos(n),u=Math.sin(n);return[(l*a-u*o*s)*e+(-l*o-u*a*s)*t,(u*a+l*o*s)*e+(-u*o+l*a*s)*t,o*c*e+a*c*t]}function hy(e,t,n,r,i,a){if(t>=1)return null;let o=Sg(a,t),s=Math.sin(o),c=Math.cos(o),l=Math.sqrt(1-t*t)*s/(1-t*c),u=(c-t)/(1-t*c),d=e*(1-t*c),f=d*u,p=d*l;return!isFinite(f)||!isFinite(p)?null:my(f,p,r,n,i)}function gy(e,t,n,r){let i=n-(t+e.tAnchorOffsetS),a=Math.sqrt(r/(e.aKm*e.aKm*e.aKm)),o=e.m0+a*i;return hy(e.aKm,e.e,e.iRad,e.om0,e.w0,o)}function _y(e,t,n){let r=n-(t+e.tAnchorOffsetS),i=e.om0+e.omDot*r,a=e.w0+e.wDot*r,o=e.m0+e.nMeanRadS*r;return hy(e.aKm,e.e,e.iRad,i,a,o)}function vy(e,t,n,r){let{coeffs:i,coeffsPerAxis:a,nSeg:o}=e,s=(n-t)/o,c=Math.floor((r-t)/s);c<0?c=0:c>=o&&(c=o-1);let l=2*(r-(t+c*s))/s-1,u=2*l,d=c*3*a,f=[0,0,0];for(let e=0;e<3;e++){let t=d+e*a;if(a===1){f[e]=i[t];continue}let n=0,r=0;for(let e=a-1;e>=1;e--){let a=i[t+e]+u*n-r;r=n,n=a}f[e]=i[t]+l*n-r}return!isFinite(f[0])||!isFinite(f[1])||!isFinite(f[2])?null:f}function yy(e,t,n,r,i){switch(e.method){case 0:return null;case 1:return gy(e,t,r,i);case 2:return _y(e,t,r);case 3:return vy(e,t,n,r)}}function by(e,t,n){let r=Ig(t),i=py(e,r);return i<0?null:yy(e.subChunks[i],e.subStartEt[i],e.subEndEt[i],r,n)}function xy(e,t,n){let r=by(e,t,n);return r===null?null:[Q(r[0]),Q(r[2]),-Q(r[1])]}function Sy(e){if(!e.landed)return!1;let t=e.subEndEt.length;return t===0||e.subEndEt[t-1]<=e.landed.endEt}function Cy(e,t){if(!e.landed)return!1;let n=Ig(t);return n>=e.landed.startEt&&(n<e.landed.endEt||Sy(e))}function wy(e,t,n=!1){let r=Ig(t);if(r<e.startEt||!n&&r>=e.endEt)return null;let i=e.sampleEt.length;if(i===0||r<e.sampleEt[0])return{latDeg:e.latRefDeg,lngDeg:e.lngRefDeg,altM:e.altRefM};let a=0,o=i-1;for(;a<o;){let t=a+o+1>>>1;e.sampleEt[t]<=r?a=t:o=t-1}return{latDeg:e.sampleLatDeg[a],lngDeg:e.sampleLngDeg[a],altM:e.sampleAltM[a]}}var Ty=30/Ag;function Ey(e,t,n){let r=by(e,t,n);if(r===null)return null;let i=Ty,a=by(e,t+i,n),o=by(e,t-i,n),s,c,l;if(a!==null&&o!==null)s=a,c=o,l=1/(2*i);else if(a!==null)s=a,c=r,l=1/i;else if(o!==null)s=r,c=o,l=1/i;else return null;return{position:r,velocity:[(s[0]-c[0])*l,(s[1]-c[1])*l,(s[2]-c[2])*l]}}var Dy=180/Math.PI;function Oy(e,t,n){if(n<=0)return null;let r=Math.sqrt(n/(e.aKm*e.aKm*e.aKm)),i=Lg(t+e.tAnchorOffsetS);return{a:e.aKm/ag,e:e.e,i:e.iRad*Dy,om:e.om0*Dy,w:e.w0*Dy,ma:e.m0*Dy,n:r*Dy*Ag,epoch:i,equatorial:!1}}function ky(e,t){let n=Lg(t+e.tAnchorOffsetS);return{a:e.aKm/ag,e:e.e,i:e.iRad*Dy,om:e.om0*Dy,w:e.w0*Dy,ma:e.m0*Dy,n:e.nMeanRadS*Dy*Ag,omDot:e.omDot*Dy*Ag,wDot:e.wDot*Dy*Ag,epoch:n,equatorial:!1}}function Ay(e,t,n){if(n<=0)return null;let r=Ey(e,t,n);if(!r)return null;let i=n*sg;return fy([r.position[0]/ag,r.position[1]/ag,r.position[2]/ag],[r.velocity[0]*cg,r.velocity[1]*cg,r.velocity[2]*cg],i,t)}function jy(e,t,n){let r=py(e,Ig(t));if(r<0)return null;let i=e.subChunks[r];switch(i.method){case 0:return null;case 1:return Oy(i,e.subStartEt[r],n);case 2:return ky(i,e.subStartEt[r]);case 3:return Ay(e,t,n)}}function My(e,t,n,r){let i=e.fitCenter;if(!i||i.id===n||!r)return null;let a=r.body(i.id,t),o=r.body(n,t);if(!a||!o)return null;if(a.parentId!==o.parentId)return console.warn(`fit-center override: ${i.id} (parent ${a.parentId}) and zone center ${n} (parent ${o.parentId}) don't share a chebyshev parent; treating the record as unplaceable`),null;let s=sy(a,t),c=sy(o,t);return!s||!c?null:{id:i.id,naifId:a.naifId,positionKm:[s.position[0]-c.position[0],s.position[1]-c.position[1],s.position[2]-c.position[2]],velocityKmDay:[s.velocity[0]-c.velocity[0],s.velocity[1]-c.velocity[1],s.velocity[2]-c.velocity[2]]}}function Ny(e){let t=e-18e6;if(t>=2e6&&t<=2999999){let e=tv(t);if(e!==void 0)return{naifId:t,muKm3S2:e}}return{naifId:e,muKm3S2:tv(e)??0}}function Py(e,t,n,r,i){let a=`naif-${n}`,o=e.fitCenter;if(o&&o.id!==a){let n=My(e,t,a,r);return n?{id:n.id,naifId:n.naifId,muKm3S2:tv(n.naifId)??0}:i?.(o.id)?o.idType===an.SPKID?{id:o.id,...Ny(o.idValue)}:{id:o.id,naifId:o.idValue,muKm3S2:tv(o.idValue)??0}:null}return{id:a,naifId:n,muKm3S2:tv(n)??0}}var Fy=1/256,Iy=class{capacity;stepDays;epsilonScene;spanDays;needsPopulate=!1;positions;jds;head=0;_count=0;constructor(e,t,n=1/0,r){this.capacity=e,this.stepDays=t,this.epsilonScene=n,this.spanDays=r??t*e,this.positions=new Float32Array(e*3),this.jds=new Float64Array(e)}get count(){return this._count}reconfigure(e,t,n){Number.isFinite(e)&&e>0&&(this.stepDays=e),this.epsilonScene=t,this.spanDays=n??this.stepDays*this.capacity}get newestJd(){if(this._count===0)return NaN;let e=(this.head-1+this.capacity)%this.capacity;return this.jds[e]}readNewestPos(e){if(this._count===0)return!1;let t=(this.head-1+this.capacity)%this.capacity*3;return e[0]=this.positions[t],e[1]=this.positions[t+1],e[2]=this.positions[t+2],!0}append(e,t,n,r){let i=this.head;this.jds[i]=e,this.positions[i*3]=t,this.positions[i*3+1]=n,this.positions[i*3+2]=r,this.head=(i+1)%this.capacity,this._count<this.capacity&&this._count++}clear(){this.head=0,this._count=0}writeVertices(e,t,n,r,i){let a=Math.min(this._count,e.length/3|0),o=i?new Float64Array(3):null;for(let s=0;s<a;s++){let a=(this.head-1-s+this.capacity)%this.capacity,c=a*3,l=s*3;if(i&&o){o[0]=this.positions[c],o[1]=this.positions[c+1],o[2]=this.positions[c+2],i(this.jds[a],o),e[l]=o[0]+t,e[l+1]=o[1]+n,e[l+2]=o[2]+r;continue}e[l]=this.positions[c]+t,e[l+1]=this.positions[c+1]+n,e[l+2]=this.positions[c+2]+r}return a}},Ly=200;function Ry(e,t,n,r=!1){if(r)return{stepDays:Ly/n,epsilonScene:1/0,spanDays:Ly};let i=e!==null&&e.n>0,a=i?360/e.n:t,o=a>0?a/n:1,s=e?e.a*(1-e.e):0,c=s>0?s*10*1e-4:1/0;return{stepDays:o,epsilonScene:c,spanDays:!i&&isFinite(c)?1/0:o*n}}function zy(e){let t=Number(e.slice(5));return e=>e===t}function By(e,t,n,r){let i=zy(r);return a=>{let o=e.probeWithCenter(n,a,i);if(!o)return null;let s=Py(o.probe,a,o.fitCenterNaifId,t,e=>e===r);return!s||s.id!==r?null:xy(o.probe,a,s.muKm3S2)}}function Vy(e,t,n,r,i){let a=e((t+r)/2);if(!a)return null;let o=a[0]-(n[0]+i[0])/2,s=a[1]-(n[1]+i[1])/2,c=a[2]-(n[2]+i[2])/2;return Math.sqrt(o*o+s*s+c*c)}var Hy=.005;function Uy(e,t,n,r,i,a,o){let s=(e,t)=>{if(e===null)return!1;let i=Math.hypot(t[0]-n[0],t[1]-n[1],t[2]-n[2]);return e<=Math.max(r,Hy*i)},c=t+o*a,l=e(c);if(l!==null&&s(Vy(e,t,n,c,l),l))return{jd:c,pos:l};let u=i,d=a,f=null,p=i*.25;for(let r=0;r<16;r++){let r=(u+d)/2,i=t+o*r,a=e(i);if(a===null){d=r;continue}if(s(Vy(e,t,n,i,a),a)?(u=r,f={jd:i,pos:a}):d=r,d-u<p)break}if(f)return f;let m=t+o*i,h=e(m);return h?{jd:m,pos:h}:null}function Wy(e,t,n,r,i,a){Gy(e,By(t,n,r,i),a)}function Gy(e,t,n){let r=t(n);if(!r)return;let i=[{jd:n,pos:r}];if(isFinite(e.epsilonScene)){let r=e.stepDays*16,a=e.stepDays*Fy,o=n-e.spanDays;for(;i.length<e.capacity;){let n=i[i.length-1];if(n.jd<=o)break;let s=Uy(t,n.jd,n.pos,e.epsilonScene,a,r,-1);if(!s)break;if(s.jd<o){let e=t(o);e&&i.push({jd:o,pos:e});break}i.push(s)}}else for(let r=1;r<e.capacity;r++){let a=n-r*e.stepDays,o=t(a);o&&i.push({jd:a,pos:o})}for(let t=i.length-1;t>=0;t--){let n=i[t];e.append(n.jd,n.pos[0],n.pos[1],n.pos[2])}}function Ky(e,t,n,r,i){if(!isFinite(e.epsilonScene))return;let a=e.stepDays*16,o=e.stepDays*Fy,s=n,c=r;for(let n=0;n<e.capacity&&!(i-s<=o);n++){let n=Math.min(a,i-s),r=Uy(t,s,c,e.epsilonScene,o,n,1);if(!r||r.jd<=s)break;e.append(r.jd,r.pos[0],r.pos[1],r.pos[2]),s=r.jd,c=r.pos}}function qy(e,t){let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=(e[i][0]-t[0])**2+(e[i][1]-t[1])**2+(e[i][2]-t[2])**2;a<r&&(r=a,n=i)}let i=Math.max(n-1,0),a=Math.min(n+1,e.length-1);return(e[i][0]-t[0])**2+(e[i][1]-t[1])**2+(e[i][2]-t[2])**2<(e[a][0]-t[0])**2+(e[a][1]-t[1])**2+(e[a][2]-t[2])**2?i:n}function Jy(e,t,n,r,i,a,o){if(t.length===0)return[];let s=e.trailAnchor??e.position;if(!s)return[];let c=[s[0]-r,s[1]-i,s[2]-a],l=o??qy(t,c),u=[c];if(n)for(let e=0;e<511;e++){let n=Math.max(l-e,0);if(u.push(t[n]),n===0)break}else{for(let e=0;e<511;e++)u.push(t[((l-e)%512+512)%512]);u.push(c)}return u.filter(e=>e.every(Number.isFinite))}function Yy(e,t,n,r){let i=.55,a=n?0:i/3,o=e.length-1;for(let t=0;t<e.length;t++)e[t]=i-(o>0?t/o:0)*(i-a);if(r){let e=.35;t.fill(0);for(let n=0;n<Math.min(171,t.length);n++)t[n]=e-n/170*e}else t.set(e)}var Xy=0,Zy=10;function Qy(e,t,n,r){let i=tv(t);if(!i)return null;let a=sy(e,n);if(!a)return null;let o=r?sy(r,n):null;if(r&&!o)return null;let s=i*sg;return fy([(a.position[0]-(o?.position[0]??0))/ag,(a.position[1]-(o?.position[1]??0))/ag,(a.position[2]-(o?.position[2]??0))/ag],[(a.velocity[0]-(o?.velocity[0]??0))*cg,(a.velocity[1]-(o?.velocity[1]??0))*cg,(a.velocity[2]-(o?.velocity[2]??0))*cg],s,n)}function $y(e,t,n){return!n||e.parentId!==Xy||e.naifId===Zy?null:Qy(e,Zy,t,n)}function eb(e,t,n,r){return r?tn(e,t,r,n):en(e,t,n)}var tb=new Wv(8);async function nb(e,t,n,r,i){let a=`${e}:${t??``}:${n}:${r??``}`;return tb.getOrCompute(a,async()=>{let a=await J_(eb(e,t,n,r),{priority:i});if(!a.ok)throw Error(`Failed to fetch elements: ${a.status}`);let o=new DecompressionStream(`gzip`),s=ry(await new Response(a.body.pipeThrough(o)).arrayBuffer());if(s.kind!==`elements`)throw Error(`Expected elements payload at ${e}/${t}/${n}, got ${s.kind}`);return s.columns})}var rb=class{static prefetch(e,t,n,r=null){fetch(eb(e,t,n,r))}barycenters=new Map;probeBuffers=new Map;constructor(e){this.cheb=e}processChebyshev(e,t){if(!this.cheb)return[];let n=Pg(e),r=this.barycenters.size===0,i=[],a=new Map,o=Array.from(this.cheb.bodiesAt(n));o.sort((e,t)=>{let n=e=>e.objectType===G.BARYCENTER?0:e.objectType===G.STAR?1:e.naifId%100==99?2:3;return n(e.body)-n(t.body)||e.body.naifId-t.body.naifId});let s=this.cheb,c=s.body(`naif-${Zy}`,n);for(let{body:e,startJd:l,endJd:u}of o){let o=oy(e,n);if(!o)continue;a.set(e.naifId,e);let d=`naif-${e.parentId}`,f=e.objectType,p=f===G.MOON&&e.parentId>=1&&e.parentId<=9?`naif-${e.parentId*100+99}`:null,m=(e,t)=>{if(!p)return Qy(e,e.parentId,t);let n=s.body(p,t);return n?Qy(e,e.parentId,t,n):null},h=m(e,n),g=e.id,_=e=>{let t=s.body(g,e);return t?m(t,e):null},v=Math.hypot(o[0],o[1],o[2])/10,y={id:e.id,name:Gg(t,e.id),isMinor:Kg(t,e.id),hasLocalized:e.hasLocalized,objectType:f,parentId:`naif-${e.parentId}`,radiusKm:e.radiusKm,a:h?Math.abs(h.a):v,e:h?.e??0,i:h?.i??0,om:h?.om??0,w:h?.w??0,ma:h?.ma??0,n:h?.n??0,epoch:h?.epoch??0,equatorial:!1,helioElements:$y(e,n,c)??void 0,validityStart:l,validityEnd:u,orbitalSource:W.SPICE,visibleFromDays:e.visibleFromDays};if(f===G.BARYCENTER||f===G.LAGRANGE_POINT){r&&h&&h.a>0&&h.e<1&&this.barycenters.set(e.id,h),i.push({data:y,position:null,orbitElements:h??void 0,orbitCenterId:d,rederiveElements:_});continue}if(vn(f)){let t=f===G.MOON,n=this.barycenters.get(d),r=t?h:n??h,o=!t&&n!==void 0,c=a.get(e.parentId)?.id,l=o&&c?e=>{let t=s.body(c,e);return t?Qy(t,t.parentId,e):null}:_;i.push({data:y,position:null,orbitElements:r??void 0,orbitCenterId:o?void 0:p??d,trailAnchorId:o?d:void 0,rederiveElements:l})}else i.push({data:y,position:null,orbitElements:h??void 0,orbitCenterId:d,rederiveElements:_})}return i}processProbes(e,t,n){let r=Pg(t),i=[],a=new Map,o=new Set;for(let{id:t,probe:s,zoneCenterNaifId:c,startJd:l,endJd:u}of e.probesAt(r)){if(!t)continue;c===void 0&&o.add(t);let d=`naif-${c}`,f=c===void 0?null:Py(s,r,c,this.cheb,()=>!0),p=f?f.id:d,m=f?.muKm3S2??0;if(m===0){let e=a.get(p);e||a.set(p,e=new Set),e.add(t)}let h={id:t,name:Gg(n,t),isMinor:Kg(n,t),hasLocalized:s.hasLocalized,objectType:s.objectType,parentId:p,loadParentId:p,radiusKm:NaN,a:0,e:0,i:0,om:0,w:0,ma:0,n:0,epoch:0,equatorial:!1,validityStart:l,validityEnd:u,orbitalSource:W.SPICE_PROBE},g=jy(s,r,m),_=t,v=this.cheb,y=t=>{let n=e.probeWithCenter(_,t);if(!n)return null;let r=Py(n.probe,t,n.fitCenterNaifId,v,()=>!0);return r?jy(n.probe,t,r.muKm3S2):null},b;{let{stepDays:e,epsilonScene:n,spanDays:r}=Ry(g,u-l,512),i=this.probeBuffers.get(t);i&&i.parentKey===p?(b=i.buffer,!isFinite(b.epsilonScene)&&isFinite(n)&&b.reconfigure(e,n,r)):(b=new Iy(512,e,n,r),b.needsPopulate=!0,this.probeBuffers.set(t,{buffer:b,parentKey:p}))}i.push({data:h,position:null,orbitElements:g??void 0,orbitCenterId:p,rederiveElements:y,trailBuffer:b})}o.size>0&&console.error(`processProbes: ${o.size} probe(s) have undefined fit_center_naif_id — metadata.json is stale (re-export to pick up fit_center_naif_id field). Affected probe ids: ${Array.from(o).slice(0,10).join(`, `)}`+(o.size>10?` (+${o.size-10} more)`:``));for(let[e,t]of a)console.warn(`processProbes: GM unavailable for ${e} — kepler_pure sub-chunks will use mu=0 (static snapshot); affected ${t.size} probe(s): ${Array.from(t).slice(0,5).join(`, `)}`+(t.size>5?` (+${t.size-5} more)`:``));return i}async fetchMinorColumns(e,t,n,r=null,i){return nb(e,t,n,r,i)}async process(e,t,n,r=null,i=`naif`,a){let o=this.barycenters.size===0,s=[],c=0,[l,u]=await Promise.all([nb(e,t,n,r,a),Uv()]),d=l.kind===`parabolic`,f=l.kind===`sgp4`,p=performance.now();for(let e=0;e<l.rowCount;e++){(e&255)==255&&performance.now()-p>6&&(await Og(),p=performance.now());let t=l.objectType[e];if(!d&&l.a[e]===0&&t!==G.BARYCENTER&&t!==G.LAGRANGE_POINT&&!vn(t)){c++;continue}let n=`${i}-${l.parentId[e]}`,r=d?Yg(l,e,u,i):f?e_(l,e,u,i):Jg(l,e,u,i);if(r){if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){o&&r.a>0&&r.e<1&&this.barycenters.set(r.id,r),s.push({data:r,position:null,orbitElements:r.a>0?r:void 0,orbitCenterId:n});continue}if(vn(t)){let e=t===G.MOON,i=this.barycenters.has(n);s.push({data:r,position:null,orbitElements:e?r:this.barycenters.get(n)??r,orbitCenterId:e||!i?n:void 0})}else s.push({data:r,position:null})}}return c>0&&console.debug(`process(${e}/${t}/${n}): skipped ${c} row(s) with a = 0`),s}},ib=new Map,ab=null,ob=null;function sb(e){if(!e)return;let t=e.ls_deg.length;if(t<2||e.dust_tau_factor.length!==t||e.dust_scale_height_km.length!==t||e.pressure_factor.length!==t){console.warn(`atmospheres: malformed seasonal table — ignored`);return}return{lsDeg:e.ls_deg,dustTauFactor:e.dust_tau_factor,dustScaleHeightKm:e.dust_scale_height_km,pressureFactor:e.pressure_factor}}function cb(e,t,n){if(t){if(!n||n<2||!(t.top_km>0)||t.flux_down.length!==3*n||t.flux_up_ratio.length!==3*n||t.extinction_per_km.length!==3*n){console.warn(`atmospheres: ${e} has a malformed deep column — ignored`);return}return{n,topKm:t.top_km,fluxDown:t.flux_down,fluxUpRatio:t.flux_up_ratio,extinctionPerKm:t.extinction_per_km}}}function lb(){if(ob)return ob;let e=(async()=>{let e=await J_(`${Wt()}/v1/atmospheres.json`);if(!e.ok){console.warn(`atmospheres: fetch failed (${e.status}) — rendering without shells`);return}let t=await e.json();ab=t.sun?.limb_darkening_alpha??null;for(let[e,n]of Object.entries(t.bodies)){let r=t.phases[n.phase];if(!r||r.length!==3*t.phase_n){console.warn(`atmospheres: ${e} has bad phase table "${n.phase}" — skipped`);continue}let i=n.mie_profile;i&&i.length!==t.profile_n&&(console.warn(`atmospheres: ${e} has a bad mie profile — falling back to exponential`),i=void 0),ib.set(e,{topAltitudeKm:n.top_altitude_km,rayleighScatterPerKm:n.rayleigh_scatter_per_km,rayleighScaleHeightKm:n.rayleigh_scale_height_km,mieScatterPerKm:n.mie_scatter_per_km,mieAbsorptionPerKm:n.mie_absorption_per_km,mieScaleHeightKm:n.mie_scale_height_km,miePhase:r,absorptionPerKm:n.absorption_per_km,absorptionCenterKm:n.absorption_center_km,absorptionWidthKm:n.absorption_width_km,bakedCompensation:n.baked_compensation,multiScatterGain:n.multi_scatter_gain,sunIntensity:n.sun_intensity,sunColor:[1,1,1],realisticSunAlways:n.realistic_sun_always,refractivity:n.refractivity,groundAlbedo:n.ground_albedo,mieProfile:i,seasonal:sb(n.seasonal),referenceAltitudeKm:n.reference_altitude_km,deepColumn:cb(e,n.deep_column,t.deep_n)})}})();return e.catch(()=>{ob===e&&(ob=null)}),ob=e,e}function ub(e){return ib.get(e)}function db(){return ab}var fb=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function pb(e,t){return e>>>t|e<<32-t}function mb(e){let t=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),n=Math.ceil((e.length+9)/64),r=new Uint8Array(n*64);r.set(e),r[e.length]=128,new DataView(r.buffer).setUint32(r.length-4,e.length*8,!1);let i=new Uint32Array(64),a=new DataView(r.buffer);for(let e=0;e<n;e++){for(let t=0;t<16;t++)i[t]=a.getUint32(e*64+t*4,!1);for(let e=16;e<64;e++){let t=pb(i[e-15],7)^pb(i[e-15],18)^i[e-15]>>>3,n=pb(i[e-2],17)^pb(i[e-2],19)^i[e-2]>>>10;i[e]=i[e-16]+t+i[e-7]+n|0}let[n,r,o,s,c,l,u,d]=t;for(let e=0;e<64;e++){let t=pb(c,6)^pb(c,11)^pb(c,25),a=c&l^~c&u,f=d+t+a+fb[e]+i[e]|0,p=(pb(n,2)^pb(n,13)^pb(n,22))+(n&r^n&o^r&o)|0;d=u,u=l,l=c,c=s+f|0,s=o,o=r,r=n,n=f+p|0}t[0]=t[0]+n|0,t[1]=t[1]+r|0,t[2]=t[2]+o|0,t[3]=t[3]+s|0,t[4]=t[4]+c|0,t[5]=t[5]+l|0,t[6]=t[6]+u|0,t[7]=t[7]+d|0}let o=new Uint8Array(32),s=new DataView(o.buffer);for(let e=0;e<8;e++)s.setUint32(e*4,t[e],!1);return o}function hb(e){return e.shape===`parted`}function gb(e){return e.shape===`chunked-parted`&&e.label===`date`}function _b(e){return e.shape===`chunked-parted`&&e.label===`index`}function vb(e){return e.shape===`chunked`}function yb(e,t){let n=Math.floor((t-e.start_jd)/e.chunk_days);return Math.max(0,Math.min(e.chunks-1,n))}function bb(e){return`shape`in e&&e.shape===`probes`}function xb(e){return`zooms`in e}function Sb(e){return bb(e)?[]:xb(e)?Object.entries(e.zooms).map(([e,t])=>({zoom:Number(e),data:t})):[{zoom:null,data:e}]}function Cb(e){return!xb(e)&&!bb(e)?e:void 0}var wb=new WeakMap;function Tb(e){let t=wb.get(e);return t||(t=Object.keys(e.parts_by_date).map(e=>Date.parse(`${e}T00:00:00Z`)).sort((e,t)=>e-t),wb.set(e,t)),t}function Eb(e,t){let n=Tb(e),r=t.getTime(),i=e=>new Date(e).toISOString().slice(0,10);if(r<=n[0])return i(n[0]);if(r>=n[n.length-1])return i(n[n.length-1]);let a=0,o=n.length-1;for(;a<o;){let e=a+o>>1;n[e]<r?a=e+1:o=e}let s=n[a-1],c=n[a];return i(r-s<=c-r?s:c)}var Db=14;function Ob(e){let t=Tb(e);return t[t.length-1]+Db*864e5}function kb(e,t){let n=Tb(e),r=t.getTime(),i=Db*864e5,a=n[0],o=n[n.length-1];if(r<a)return{kind:`covered`};if(r>o+i)return{kind:`after`,lastMs:o+i};if(r>=o)return{kind:`covered`};let s=0,c=n.length-1;for(;s<c;){let e=s+c>>1;n[e]<r?s=e+1:c=e}let l=n[s],u=s>0?n[s-1]:l;return Math.min(r-u,l-r)>i?{kind:`gap`}:{kind:`covered`}}function Ab(e,t,n=0){let r=e.parts_by_date[t]??e.parts;return n>0?Math.min(r,n):r}var jb=null;function Mb(){if(jb)return jb;let e=J_(`${Wt()}/v1/metadata.json`).then(e=>{if(!e.ok)throw Error(`Failed to fetch metadata: ${e.status}`);return e.json()}).then(e=>(Jt(e.versions),e));return jb=e,e.catch(()=>{jb===e&&(jb=null)}),jb}function Nb(e){let t=new Map;for(let[n,r]of Object.entries(e.position.zones)){if(bb(r))continue;let e=xb(r)?0:null,i=e===0?r.zooms[0]:r;!i||!vb(i)||t.set(n,{zoom:e,chunks:i.chunks,chunk_days:i.chunk_days,start_jd:i.start_jd,end_jd:i.end_jd})}return t}function Pb(e){let t=new Map,n=Object.entries(e.position.zones).filter(([,e])=>bb(e)).sort(([e],[t])=>(e===`probes/interplanetary`)-+(t===`probes/interplanetary`)||e.localeCompare(t));for(let[e,r]of n)bb(r)&&t.set(e,{chunks:r.chunks,chunk_days:r.chunk_days,start_jd:r.start_jd,end_jd:r.end_jd,float64_coeffs:r.float64_coeffs,fit_center_naif_id:r.fit_center_naif_id,present:r.present});return t}async function Fb(e,t){let n=new TextEncoder().encode(e),r=crypto.subtle?await crypto.subtle.digest(`SHA-256`,n):mb(n).buffer;return new DataView(r).getUint32(0,!1)%t}async function Ib(e,t){let n=await J_(e,{priority:t});if(!n.ok)throw Error(`Failed to fetch ${e}: ${n.status}`);let r=new DecompressionStream(`gzip`);return new Response(n.body.pipeThrough(r)).arrayBuffer()}async function Lb(e,t,n,r){let i=ry(await Ib(nn(e,t,n),r));if(i.kind!==`chebyshev`)throw Error(`Expected chebyshev payload at ${e}/${n}, got ${i.kind}`);let a=new Map;for(let e of i.chunk.bodies)e.id&&a.set(e.id,e);return{...i.chunk,byId:a}}var Rb=1,zb=Promise.resolve();function Bb(e,t){return`${e}:${t}`}var Vb=class{chunks=new Map;inflight=new Map;lastEnsuredJd=NaN;_version=0;constructor(e){this.zoneParams=e}get version(){return this._version}zones(){return Array.from(this.zoneParams.keys())}ensure(e){if(e===this.lastEnsuredJd)return{ready:this.allCurrentChunksLoaded(e),done:this.pendingCurrent(e)};this.lastEnsuredJd=e;let t=[],n=[],r=!0;for(let[i,a]of this.zoneParams){let o=yb(a,e);if(this.isLoadable(a,o)&&!this.isResident(i,o)){r=!1;let e=this.loadChunk(i,a,o,`high`);e&&t.push(e)}for(let e=-Rb;e<=Rb;e++){let t=o+e;e===0||t<0||t>=a.chunks||this.isLoadable(a,t)&&n.push([i,a,t])}this.evictOutsideWindow(i,o)}let i=t.length>0?Promise.all(t).then(()=>void 0):zb;return i.catch(()=>{}).then(()=>{for(let[e,t,r]of n)this.loadChunk(e,t,r,`low`)?.catch(()=>{})}),{ready:r,done:i}}loadingAt(e,t){if(this.inflight.size===0)return!1;for(let[n,r]of this.zoneParams)if(!(t!==void 0&&n!==t)&&this.inflight.has(Bb(n,yb(r,e))))return!0;return!1}pendingCurrent(e){if(this.inflight.size===0)return zb;let t=null;for(let[n,r]of this.zoneParams){let i=this.inflight.get(Bb(n,yb(r,e)));i&&(t??=[]).push(i)}return t?Promise.all(t).then(()=>void 0):zb}allCurrentChunksLoaded(e){for(let[t,n]of this.zoneParams){let r=yb(n,e);if(this.isLoadable(n,r)&&!this.isResident(t,r))return!1}return!0}isResident(e,t){return this.chunks.get(e)?.has(t)??!1}evictOutsideWindow(e,t){let n=this.chunks.get(e);if(n)for(let e of n.keys())(e<t-Rb||e>t+Rb)&&n.delete(e)}loadChunk(e,t,n,r){if(this.isResident(e,n))return null;let i=Bb(e,n),a=this.inflight.get(i);if(a)return a;let o=this.fetchAndStore(e,t,n,r);return this.inflight.set(i,o),o.finally(()=>this.inflight.delete(i)),o}async fetchAndStore(e,t,n,r){let i=await this.fetchChunk(e,t,n,r),a=this.chunks.get(e);a||this.chunks.set(e,a=new Map),a.set(n,i),this._version++,this.afterStore(e,i)}},Hb=class extends Vb{idToZone=new Map;isLoadable(){return!0}fetchChunk(e,t,n,r){return Lb(e,t.zoom,n,r)}afterStore(e,t){for(let n of t.byId.keys())this.idToZone.has(n)||this.idToZone.set(n,e)}has(e){return this.idToZone.has(e)}zoneCoverage(e){let t=this.idToZone.get(e);if(t===void 0)return null;let n=this.zoneParams.get(t);return n?{start:n.start_jd,end:n.end_jd}:null}isLoading(e,t){let n=this.idToZone.get(e);return n!==void 0&&this.loadingAt(t,n)}resolve(e,t){let n=this.idToZone.get(e);if(n===void 0)return null;let r=this.zoneParams.get(n);if(!r)return null;let i=yb(r,t),a=this.chunks.get(n)?.get(i);if(!a)return null;let o=a.byId.get(e);return o?{zone:n,chunkIdx:i,body:o}:null}body(e,t){return this.resolve(e,t)?.body??null}*bodiesAt(e){for(let[t,n]of this.zoneParams){let r=yb(n,e),i=this.chunks.get(t)?.get(r);if(i)for(let e of i.bodies)yield{zone:t,body:e,startJd:i.startJd,endJd:i.endJd}}}positionScene(e,t){let n=this.resolve(e,t);return n?oy(n.body,t):null}};async function Ub(e,t,n,r){let i=nn(e,null,t),a=await J_(i,{priority:r});if(!a.ok)throw Error(`Failed to fetch ${i}: ${a.status}`);let o=new DecompressionStream(`gzip`),s=ry(await new Response(a.body.pipeThrough(o)).arrayBuffer(),{probesFloat64:n});if(s.kind!==`probes`)throw Error(`Expected probes payload at ${e}/${t}, got ${s.kind}`);return{...s.chunk,ids:s.chunk.probes.map(e=>e.id)}}var Wb=24;function Gb(e,t){for(let[n,r]of e){if(t<n)return!1;if(t<=r)return!0}return!1}var Kb=7,qb=class extends Vb{fitCenterUsable=null;warmed=new Map;carried=new Map;zoneCenter(e){return this.zoneParams.get(e)?.fit_center_naif_id}isLoadable(e,t){return Gb(e.present,t)}fetchChunk(e,t,n,r){return Ub(e,n,t.float64_coeffs,r)}afterStore(){}async warmAt(e){let t=[];for(let[n,r]of this.zoneParams){let i=yb(r,e);if(i<0||i>=r.chunks||!Gb(r.present,i)||this.isResident(n,i))continue;let a=Bb(n,i);if(this.warmed.has(a))continue;let o=this.inflight.get(a);if(o){t.push(o);continue}let s=this.fetchAndWarm(a,n,i,r);this.inflight.set(a,s),s.finally(()=>this.inflight.delete(a)),t.push(s)}await Promise.all(t)}async fetchAndWarm(e,t,n,r){let i=await Ub(t,n,r.float64_coeffs,`low`);for(this.warmed.set(e,i);this.warmed.size>Wb;){let e=this.warmed.keys().next().value;if(e===void 0)break;this.warmed.delete(e)}}fitCenterCovered(e){let t=e.fitCenter;return!t||!this.fitCenterUsable?!0:this.fitCenterUsable(t.id)}*probesAt(e,t){let n=new Map,r=new Set;for(let[i,a]of this.zoneParams){let o=yb(a,e),s=this.chunks.get(i)?.get(o)??this.warmed.get(Bb(i,o));if(!s)continue;let c=t?.(a.fit_center_naif_id)??!1;for(let e=0;e<s.probes.length;e++){let t=s.probes[e],o=t.id;if(!o||r.has(o)||!this.fitCenterCovered(t))continue;let l={zone:i,zoneCenterNaifId:a.fit_center_naif_id,id:o,probe:t,startJd:s.startJd,endJd:s.endJd};c?(n.set(o,l),r.add(o)):n.has(o)||n.set(o,l)}}yield*this.withPassengers(n,e).values()}withPassengers(e,t){if(this.carried.size===0)return e;let n=[];for(let[r,{carriedFrom:i}]of this.carried){if(t<i.start_jd||t>=i.end_jd||e.has(r))continue;let a=e.get(i.object_id);a&&n.push([r,a])}for(let[t,r]of n)e.set(t,{...r,id:t});return e}registerCarried(e){this.carried.set(e.id,e)}carrierAt(e,t){if(this.carried.size===0)return null;let n=this.carried.get(e)?.carriedFrom;return!n||t<n.start_jd||t>=n.end_jd+Kb?null:n.object_id}ridesAt(e){let t=[];for(let[n,r]of this.carried){let i=r.carriedFrom;if(e<i.start_jd||e>=i.end_jd+Kb)continue;let a=e<i.end_jd;!a&&this.resolveOwn(n,e)||t.push({passengerId:n,carrierId:i.object_id,carrierName:r.carrierName,attached:a})}return t}resolve(e,t,n){let r=this.resolveOwn(e,t,n);if(r)return r;let i=this.carrierAt(e,t);return i?this.resolveOwn(i,t,n):null}resolveOwn(e,t,n){let r=Ig(t),i=null;for(let[a,o]of this.zoneParams){let s=yb(o,t),c=this.chunks.get(a)?.get(s)??this.warmed.get(Bb(a,s));if(c)for(let t of Zb(c,e)){let e=c.probes[t];if(!this.fitCenterCovered(e))break;let s=py(e,r)>=0,l=e.landed,u=l!==void 0&&r>=l.startEt&&r<l.endEt;if(!s&&!u)continue;let d={zone:a,probe:e,params:o};if(n?.(o.fit_center_naif_id))return d;i??=d;break}}return i}stampedFitCenterAt(e,t){let n=this.stampedFitCenterAtOwn(e,t);if(n!==null)return n;let r=this.carrierAt(e,t);return r?this.stampedFitCenterAtOwn(r,t):null}stampedFitCenterAtOwn(e,t){let n=Ig(t);for(let[r,i]of this.zoneParams){let a=yb(i,t),o=this.chunks.get(r)?.get(a)??this.warmed.get(Bb(r,a));if(o)for(let t of Zb(o,e)){let e=o.probes[t];if(py(e,n)<0)break;return e.fitCenter?.id??null}}return null}probe(e,t,n){return this.resolve(e,t,n)?.probe??null}probeWithCenter(e,t,n){let r=this.resolve(e,t,n);return r?{probe:r.probe,fitCenterNaifId:r.params.fit_center_naif_id}:null}positionKm(e,t,n,r){let i=this.resolve(e,t,r);return i?by(i.probe,t,n):null}positionScene(e,t,n,r){let i=this.resolve(e,t,r);return i?xy(i.probe,t,n):null}containingSystemAt(e,t){let n=this.containingSystemAtOwn(e,t);if(n!==null)return n;let r=this.carrierAt(e,t);return r?this.containingSystemAtOwn(r,t):null}containingSystemAtOwn(e,t){let n=Ig(t),r=this.zoneParams.get(Jb);if(r){let i=yb(r,t),a=this.chunks.get(Jb)?.get(i);if(a)for(let t of Zb(a,e)){let e=a.probes[t];for(let t of e.systemIntervals)if(n>=t.startEt&&n<t.endEt)return t.systemNaifId;return null}}for(let[n,r]of this.zoneParams){if(n===Jb||r.fit_center_naif_id===10)continue;let i=yb(r,t),a=this.chunks.get(n)?.get(i);if(a)for(let t of Zb(a,e))return Math.floor(r.fit_center_naif_id/100)}return null}hasHeliocentricFit(e,t){if(this.hasHeliocentricFitOwn(e,t))return!0;let n=this.carrierAt(e,t);return n!==null&&this.hasHeliocentricFitOwn(n,t)}hasHeliocentricFitOwn(e,t){let n=this.zoneParams.get(Jb);if(!n)return!1;let r=yb(n,t),i=this.chunks.get(Jb)?.get(r);if(!i)return!1;let a=Ig(t);for(let t of Zb(i,e))if(py(i.probes[t],a)>=0)return!0;return!1}},Jb=`probes/interplanetary`,Yb=[],Xb=new WeakMap;function Zb(e,t){let n=Xb.get(e);if(!n){n=new Map;for(let t=0;t<e.ids.length;t++){let r=n.get(e.ids[t]);r?r.push(t):n.set(e.ids[t],[t])}Xb.set(e,n)}return n.get(t)??Yb}async function Qb(e){let t=new DecompressionStream(`gzip`);return await new Response(e.body.pipeThrough(t)).json()}function $b(e,t={}){let{onMissing:n,fetcher:r=e=>fetch(e),error:i=(e,t)=>`memoizedGzJson: ${t} returned ${e.status} ${e.statusText}`}=t,a=null;return()=>{if(a)return a;let t=(async()=>{let t=await e(),a=await r(t);if(!a.ok){if(a.status===404&&n)return n();throw Error(i(a,t))}return Qb(a)})();return a=t,t.catch(()=>{a===t&&(a=null)}),t}}var ex=24,tx=new Map;function nx(e,t){let n=tx.get(e);if(n&&(tx.delete(e),tx.set(e,n)),!n){n=(async()=>{let n=await J_(e,t);if(!n.ok){if(n.status===404)return{};throw Error(`fetchGzipBundle: ${e} returned ${n.status} ${n.statusText}`)}return Qb(n)})(),tx.set(e,n),n.catch(()=>{tx.get(e)===n&&tx.delete(e)});for(let e of tx.keys()){if(tx.size<=ex)break;tx.delete(e)}}return n}var rx={counts:`object_bundles`,globalPath:e=>`/v1/objects/__global__/${e}.json.gz`,localizedPath:(e,t)=>`/v1/objects/${e}/${t}.json.gz`,versionClass:`objects`},ix={counts:`group_bundles`,globalPath:e=>`/v1/groups/__global__/${e}.json.gz`,localizedPath:(e,t)=>`/v1/groups/${e}/${t}.json.gz`},ax=(e,t)=>nx(t?Yt(e,t):`${Wt()}${e}`);async function ox(e,t,{meta:n,lang:r,fetchBundle:i,localized:a=!0}){let o=n[e.counts],s=o?.global??0,c=a?o?.[r]??0:0,[l,u]=await Promise.all([s?Fb(t,s):-1,c?Fb(t,c):-1]),[d,f]=await Promise.all([l>=0?i(e.globalPath(l),e.versionClass):null,u>=0?i(e.localizedPath(r,u),e.versionClass):null]);return{global:d?.[t]??null,localized:f?.[t]??null}}async function sx(e,t,n,r=!0){return ox(e,t,{meta:await Mb(),lang:n,localized:r,fetchBundle:ax})}function cx(e){return e.imagery!==`withheld`&&a(e.distribution)}function lx(e,t=!0,n=s()){return sx(rx,e,n,t)}async function ux(e){if(e?.startsWith(`probe-`))try{let t=(await lx(e,!1)).global,n=t?.coverage?.position_from;return n?{id:e,carriedFrom:n,carrierName:t?.carried_by?.name}:void 0}catch{return}}function dx(e,t,n){let r=new Set,i=new Map;for(let a of e){let e=t===a.passengerId;if(r.add(e?a.carrierId:a.passengerId),!e||!a.attached)continue;let o=n(a.carrierId)??a.carrierName;o&&i.set(a.passengerId,o)}return{hidden:r,credits:i}}var fx=1/1440;function px(e){return(e?.coverage?.windows.length??0)>0}async function mx(){let e=(await Mb()).position.zones.earth,t=e&&Sb(e).find(e=>gb(e.data))?.data;return t&&gb(t)?Ng(Ob(t)):1/0}async function hx(e){let t=(await lx(e,!1)).global?.coverage?.windows??[],n=e.startsWith(`norad_satcat-`)?await mx():1/0;return t.map(([e,t])=>[e??-1/0,t??n]).filter(([e,t])=>t>e)}function gx(e,t){let n=null;for(let[r,i]of e){if(t>r&&t<i)return t;let e=Math.min(fx,(i-r)/2),a=t<=r?r+e:i-e;(n===null||Math.abs(a-t)<Math.abs(n-t))&&(n=a)}return n}function _x(e){return G[e.toUpperCase()]??G.UNDOCUMENTED}var vx={horizons:W.HORIZONS,sbdb:W.SBDB,celestrak:W.CELESTRAK,spacetrack:W.SPACETRACK,spice:W.SPICE,sbdb_moons:W.SBDB_MOON,astersat:W.ASTERSAT};function yx(e){return e?vx[e]??W.UNKNOWN:W.UNKNOWN}var bx=14;function xx(e,t){let n=t.global,r=n?.orbit;if(!n||!r||!px(n))return null;let i=r.q!=null&&r.tp!=null;if(!i&&(r.epoch_jd==null||r.a==null||r.ma==null||r.n==null))return null;let a=r.scale===`planet`,o=n.cross_refs?.norad_cat_id,s=a&&r.bstar!=null&&r.mean_motion_dot!=null&&r.mean_motion_ddot!=null&&r.n!=null&&o!=null?{noradCatId:o,epochJd:r.epoch_jd,meanMotion:r.n,eccentricity:r.e,inclination:r.i,raOfAscNode:r.om,argOfPericenter:r.w,meanAnomaly:r.ma??0,bstar:r.bstar,meanMotionDot:r.mean_motion_dot,meanMotionDdot:r.mean_motion_ddot,elementSetNo:r.element_set_no??0,revAtEpoch:r.rev_at_epoch??0}:void 0,c=s?vg(s,n.name??void 0)??void 0:void 0,l=n.coverage?.windows[0]?.[0];return{id:e,name:t.localized?.name??n.name??n.sbdb_primary_designation??n.provisional_designation??null,objectType:_x(n.type),parentId:r.parent_id,radiusKm:n.sbdb?.diameter?n.sbdb.diameter/2:NaN,hasLocalized:t.localized!=null,a:a?(r.a??0)/ag:r.a??0,e:r.e,i:r.i,om:r.om,w:r.w,ma:r.ma??0,n:a?(r.n??0)*360:r.n??0,epoch:r.epoch_jd,equatorial:a,validityStart:s?r.epoch_jd-bx:-1/0,validityEnd:s?r.epoch_jd+bx:1/0,orbitalSource:yx(r.source),...l==null?{}:{visibleFromDays:l-kg},...i?{q:r.q,tp:r.tp}:{},...s?{omm:s}:{},...c?{satrec:c}:{}}}function Sx(e,t){let n=t.global;return n?{id:e,name:t.localized?.name??n.name??n.sbdb_primary_designation??n.provisional_designation??null,objectType:_x(n.type),parentId:n.host_id??``,radiusKm:n.sbdb?.diameter?n.sbdb.diameter/2:NaN,hasLocalized:t.localized!=null,pageOnly:!0,a:NaN,e:NaN,i:NaN,om:NaN,w:NaN,ma:NaN,n:NaN,epoch:NaN,validityStart:-1/0,validityEnd:1/0,orbitalSource:W.UNKNOWN}:null}async function Cx(e,t,n=new Set){if(n.has(e))return console.warn(`createPlaceholderBody: cycle detected at ${e} — hiding`),[];n.add(e);let r;try{r=await lx(e)}catch{return console.warn(`createPlaceholderBody: failed to fetch global data for ${e} — hiding`),[]}let i=r.global;if(!i)return console.warn(`createPlaceholderBody: no catalogue record for ${e} — hiding`),[];let a=i.sbdb?.class??null,o=xx(e,r)??Sx(e,r);if(!o)return[];let s=o.parentId,c=s===``||s===`naif-0`||t.getBody(s)?[]:await Cx(s,t,n),l=o.pageOnly?{data:o,position:null}:{data:o,position:null,orbitElements:o,orbitCenterId:s};return[...c,{body:l,zone:a}]}function wx(e,t,n){let r=0;for(let i=0;i<t.length;i++){let{body:a,zone:o}=t[i];if(e.getBody(a.data.id))continue;let s=a.data.objectType,c=s===G.SPACECRAFT||s===G.DEBRIS,l=i>0?t[i-1]:null,u=s===G.MOON&&l&&_n(l.body.data.objectType)?`small_body_moons`:o;c&&a.data.parentId!==``?(e.bodies.putSpacecraft(a)&&r++,e.bodies.dirtySpacecraftGroups.add(a.data.parentId)):u&&!a.data.pageOnly?(e.bodies.asteroidBucket(u,n).addPlaceholder(a),e.bodies.dirtyAsteroidZones.add(u),r++):e.bodies.addBodies([a]),e.credits.recordOrbitSources([a])}return r}async function Tx(e,t){if(e.getBody(t))return;let n=await Cx(t,e);if(n.length===0)return;let r=wx(e,n,await Uv());e.bodies.flushMinor(r>0)}var Ex=`spacemap.atmosphere-calibration`;function Dx(){try{let e=localStorage.getItem(Ex);return e?JSON.parse(e):null}catch{return null}}function Ox(e){try{e?localStorage.setItem(Ex,JSON.stringify(e)):localStorage.removeItem(Ex)}catch{}}function kx(){return Ze({resolvedReducedMotion:typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,viewMode:`map`,showClouds:!0,showAtmospheres:!0,atmosphereQuality:`auto`,atmosphereAutoTier:null,atmosphereCalibration:Dx(),atmoQualityOverrides:{},highAmbient:!1,realisticLighting:!1,overexposeRings:!1,showShapeMesh:!0,showSurfaceTexture:!0,showDisplacement:!0,showSelfShadow:!0,showHaloDebug:!1,maxPartsPerZone:0,setAtmosphereCalibration(e){this.atmosphereCalibration=e,Ox(e)},setAtmosphereAutoTier(e){this.atmosphereAutoTier=e}})}var Ax=null;function jx(){return Ax??=kx()}function Mx(e){Ax=e}var Nx=2e3,Px=3,Fx=class{zones=[];latestDate;failureStreak=0;staleNotified=!1;constructor(e,t,n,r){this.ctx=e,this.loader=n,this.latestDate=r;let i=Pg(r),a=jx().maxPartsPerZone;for(let[n,o]of Object.entries(t.position.zones)){if(e.layers.skipsZone(n))continue;let t=o.parent_id_type??`naif`;for(let{zoom:e,data:s}of Sb(o)){if(s.shape===`chunked`||s.shape===`parted`)continue;let o=a>0?Math.min(s.parts,a):s.parts;if(gb(s)){let i={kind:`time`,zone:n,zoom:e,parts:o,parentIdType:t,zoomData:s,currentTime:``,inFlight:null,lastLoadStartMs:-1/0,cap:a};this.zones.push(i),this.prefetchTimeNeighbors(i,r)}else if(_b(s)){let r={kind:`chunk`,zone:n,zoom:e,parts:o,parentIdType:t,zoomData:s,currentIdx:yb(s,i),inFlight:null,preloads:new Map};this.zones.push(r),this.preloadChunkNeighbors(r)}}}}recordSuccess(){this.failureStreak=0}recordFailure(){this.failureStreak++,this.failureStreak>=Px&&!this.staleNotified&&(this.staleNotified=!0,this.ctx.onDataStale?.())}invalidateZone(e){for(let t of this.zones)t.zone!==e||t.kind!==`time`||(t.currentTime=``,t.lastLoadStartMs=-1/0);this.tick(this.latestDate)}satelliteCoverage(e){let t=this.zones.find(e=>e.kind===`time`&&e.zone===`earth`);return t?kb(t.zoomData,Fg(e)):{kind:`covered`}}tick(e){this.latestDate=e;let t=Pg(e);for(let n of this.zones)if(n.kind===`time`){if(n.inFlight)continue;let t=Eb(n.zoomData,e);if(t===n.currentTime)continue;let r=performance.now();if(r-n.lastLoadStartMs<Nx)continue;n.lastLoadStartMs=r,n.inFlight=this.loadTime(n,t,e).finally(()=>{n.inFlight=null})}else{for(;;){let e=yb(n.zoomData,t);if(e===n.currentIdx)break;let r=n.preloads.get(e);if(r?.kind!==`ready`)break;let i=n.currentIdx;n.currentIdx=e,this.applyChunkSwap(n,i,e,r.bodies),this.preloadChunkNeighbors(n)}if(n.inFlight)continue;let e=yb(n.zoomData,t);if(e===n.currentIdx)continue;n.inFlight=this.loadChunk(n,e).finally(()=>{n.inFlight=null})}}async ready(e=this.latestDate){this.latestDate=e;let t=Pg(e),n=this.zones.map(n=>this.zoneReady(n,e,t));this.ctx.chebStore&&n.push(this.ctx.chebStore.ensure(t).done),this.ctx.probeStore&&n.push(this.ctx.probeStore.ensure(t).done),await Promise.all(n)}async zoneReady(e,t,n){for(;e.inFlight;)await e.inFlight;if(e.kind===`time`){let n=Eb(e.zoomData,t);if(n===e.currentTime)return;e.lastLoadStartMs=performance.now(),e.inFlight=this.loadTime(e,n,t).finally(()=>{e.inFlight=null})}else{let t=yb(e.zoomData,n);if(t===e.currentIdx)return;e.inFlight=this.loadChunk(e,t).finally(()=>{e.inFlight=null})}await e.inFlight}wanted=new Set;want(e){this.wanted.add(e)}async ensureBody(e,t){e.startsWith(`probe-`)&&await this.ensureProbe(e,t),!this.ctx.getBody(e)&&(e.startsWith(`norad_satcat-`)&&!this.wanted.has(e)&&(this.want(e),(this.ctx.earthSatFilter||this.ctx.earthTypeFilter)&&(this.invalidateZone(`earth`),await this.ready(t),this.ctx.getBody(e)))||await Tx(this.ctx,e))}async ensureProbe(e,t){let n=this.ctx.probeStore;if(!n)return;let r=Pg(t),i=ux(e);await n.ensure(r).done;let a=await i;a&&n.registerCarried(a);let o=n.stampedFitCenterAt(e,r);if(o&&await Tx(this.ctx,o),this.ctx.getBody(e))return;let s=await Uv(),c=this.loader.processProbes(n,t,s).find(t=>t.data.id===e);c&&(this.ctx.bodies.addBodies([c]),this.ctx.credits.recordOrbitSources([c]))}async loadTime(e,t,n){let r=e.currentTime;try{let i=Ab(e.zoomData,t,e.cap),a=await Promise.all(Array.from({length:i},(n,r)=>this.loader.process(e.zone,e.zoom,r,t,e.parentIdType))),o=e.zone===`earth`,s=o?this.ctx.earthSatFilter:null,c=o?this.ctx.earthTypeFilter:null,l=0,u=new Map;for(let t of a){this.ctx.credits.recordOrbitSources(t);for(let n of t){let t=n.data.objectType;if(t!==G.SPACECRAFT&&t!==G.DEBRIS){console.warn(`zone-refresher: unexpected non-spacecraft body in ${e.zone}: ${n.data.id} (type=${t})`);continue}if(!this.wanted.has(n.data.id)){if(s&&!s.has(n.data.id)){l++;continue}if(c&&!c.has(t)){l++;continue}}let r=n.data.parentId,i=u.get(r);i||u.set(r,i=new Map),i.set(n.data.id,n)}}l>0&&console.log(`zone-refresher: ${e.zone}@${t}: filtered out ${l} non-member bodies`);let d=0,f=0,p=0;for(let[e,t]of u){let n=this.ctx.bodies.spacecraftBucket(e);for(let e of n.keys())t.has(e)||this.ctx.hasMeshBody?.(e)||this.wanted.has(e)||(n.delete(e),p++);for(let e of t.values())this.ctx.bodies.putSpacecraft(e)?d++:f++;this.ctx.bodies.dirtySpacecraftGroups.add(e)}e.currentTime=t,this.ctx.bodies.minorBodyVersion++,d>0&&this.ctx.bodies.notifyBodiesAdded(),e.zone===`earth`&&this.ctx.notifyEarthSatRollover(),console.log(`zone-refresher: ${e.zone}@${r} → ${t} (+${d} ~${f} -${p})`),this.prefetchTimeNeighbors(e,n),this.recordSuccess()}catch(n){console.warn(`zone-refresher: failed to refresh ${e.zone}@${t}:`,n),this.recordFailure()}}async loadChunk(e,t){let n=e.currentIdx;e.currentIdx=t;try{let r=e.preloads.get(t),i;i=r?.kind===`pending`?await r.promise:await Promise.all(Array.from({length:e.parts},(n,r)=>this.loader.process(e.zone,e.zoom,r,String(t),e.parentIdType))),this.applyChunkSwap(e,n,t,i),this.preloadChunkNeighbors(e),this.recordSuccess()}catch(r){console.warn(`zone-refresher: ${e.zone} chunk reload failed (${n} → ${t}):`,r),e.currentIdx=n,this.recordFailure()}}applyChunkSwap(e,t,n,r){let i=0,a=0;for(let e of r){this.ctx.credits.recordOrbitSources(e);for(let t of e){let e=!this.ctx.bodies.bodiesById.has(t.data.id);this.ctx.bodies.addBodies([t]),e?(this.ctx.bodies.majorBodies.push(t),a++):i++}}this.ctx.bodies.minorBodyVersion++,console.log(`zone-refresher: ${e.zone} chunk ${t} → ${n} (+${a} ~${i})`)}preloadChunkNeighbors(e){let t=Math.max(0,e.currentIdx-1),n=Math.min(e.zoomData.chunks-1,e.currentIdx+1);for(let r=t;r<=n;r++){if(e.preloads.has(r))continue;let t=String(r),n=Promise.all(Array.from({length:e.parts},(n,r)=>this.loader.process(e.zone,e.zoom,r,t,e.parentIdType)));e.preloads.set(r,{kind:`pending`,promise:n}),n.then(t=>{e.preloads.get(r)?.kind===`pending`&&e.preloads.set(r,{kind:`ready`,bodies:t})},t=>{console.warn(`zone-refresher: ${e.zone} chunk ${r} preload failed:`,t),e.preloads.get(r)?.kind===`pending`&&e.preloads.delete(r)})}for(let r of e.preloads.keys())(r<t||r>n)&&e.preloads.delete(r)}prefetchTimeNeighbors(e,t){let n=864e5,r=Eb(e.zoomData,new Date(t.getTime()-n)),i=Eb(e.zoomData,new Date(t.getTime()+n));for(let t of new Set([r,i])){if(t===e.currentTime)continue;let n=Ab(e.zoomData,t,e.cap);for(let r=0;r<n;r++)rb.prefetch(e.zone,e.zoom,r,t)}}},Ix,Lx=new Promise(e=>{Ix=e});function Rx(){Ix()}var zx=4;function Bx(){return typeof navigator>`u`?!1:navigator.connection?.saveData===!0}function Vx(){if(typeof navigator>`u`)return!1;if(Bx())return!0;let e=navigator.deviceMemory;return typeof e==`number`&&e>0&&e<=zx}var Hx;function Ux(){return Hx===void 0&&(Hx=typeof window<`u`&&!!window.matchMedia?.(`(pointer: coarse)`).matches),Hx}function Wx(){return typeof window>`u`?1:Math.min(window.devicePixelRatio,2)}var Gx={low:{maxPixelRatio:1.25,shadowMapSize:1024,softShadows:!1,bloomScale:.5,pointBudget:4e5,maxTextureTier:`medium`,tileWindows:3,maxSkyboxFace:2048},medium:{maxPixelRatio:1.5,shadowMapSize:2048,softShadows:!0,bloomScale:.75,pointBudget:9e5,maxTextureTier:`medium`,tileWindows:4,maxSkyboxFace:2048},high:{maxPixelRatio:2,shadowMapSize:4096,softShadows:!0,bloomScale:1,pointBudget:1/0,maxTextureTier:`high`,tileWindows:6,maxSkyboxFace:1/0}};function Kx(){return Vx()?`low`:Yx().maxTextureTier}function qx(){return Vx()?0:Yx().tileWindows}function Jx(){let e=jx().atmosphereCalibration?.tier;return e===`low`||e===`medium`?e:e===`high`||e===`ultra`?`high`:Ux()?Vx()?`low`:`medium`:Vx()?`medium`:`high`}function Yx(){return Gx[Jx()]}function Xx(){return typeof window>`u`?1:Math.min(window.devicePixelRatio,Yx().maxPixelRatio)}var Zx=Math.PI/180*og,Qx=new Ui().setFromAxisAngle(new J(0,0,1),-Math.PI/2).premultiply(new Ui().setFromAxisAngle(new J(0,1,0),Math.PI/2-Zx)).premultiply(new Ui().setFromAxisAngle(new J(1,0,0),-Math.PI/2)),$x=[`px`,`nx`,`py`,`ny`,`pz`,`nz`];function eS(e,t){if(e.tiers.length===0)return null;let n=[...e.tiers].sort((t,n)=>(e.tier_face_size[n]??0)-(e.tier_face_size[t]??0));for(let r of n)if((e.tier_face_size[r]??1/0)<=t)return r;return n[n.length-1]}function tS(e,t,n){return Yt(`/v1/textures/${e}/${t}_${n}.webp`,`textures`)}async function nS(e,t,n){return Promise.all($x.map(async r=>{let i=await fetch(tS(e,t,r),{priority:n});if(!i.ok)throw Error(`Skybox face fetch failed (${i.status}): ${t}_${r}`);let a=await i.blob();return createImageBitmap(a,{imageOrientation:`none`,premultiplyAlpha:`none`})}))}var rS=new Map,iS=new Map;function aS(e,t){return`${e}:${t}`}function oS(e,t,n,r=!0){let i=aS(e,t),a=rS.get(i);if(!a){let r=nS(e,t,n);a=r,rS.set(i,a),r.catch(()=>{rS.get(i)===r&&(rS.delete(i),iS.delete(i))})}return r&&iS.set(i,(iS.get(i)??0)+1),a}function sS(e,t,n){let r=aS(e,t),i=(iS.get(r)??1)-1;if(i>0){iS.set(r,i);return}iS.delete(r),rS.delete(r);for(let e of n)e.close()}function cS(e){let t=new Nc(e);return t.colorSpace=Xr,t.needsUpdate=!0,t}function lS(e){return e.tiers.length===0?null:[...e.tiers].sort((t,n)=>(e.tier_face_size[t]??0)-(e.tier_face_size[n]??0))[0]}function uS(e){let t=lS(e);t&&oS(e.id,t,void 0,!1).catch(()=>{})}var dS=12e3;async function fS(e,t,n,r){let i=eS(n,Math.min(t.capabilities.maxTextureSize,Yx().maxSkyboxFace));if(!i){console.warn(`Skybox ${n.id}: no tiers declared`);return}let a=lS(n),o={cube:null,bitmaps:null},s=!1;a&&a!==i&&oS(n.id,a).then(t=>{if(s||r()){sS(n.id,a,t);return}o.cube=cS(t),o.bitmaps=t,e.background=o.cube,performance.mark(`sm-skybox-low`),c&&l()}).catch(()=>{});let c=!1,l=()=>{!a||!o.cube||!o.bitmaps||(t.initTexture(o.cube),sS(n.id,a,o.bitmaps),o.bitmaps=null)};i!==a&&await Promise.race([Lx,new Promise(e=>setTimeout(e,dS))]);let u;try{u=await oS(n.id,i,i===a?void 0:`low`)}catch(e){throw c=!0,r()?a&&o.bitmaps&&(o.cube?.dispose(),sS(n.id,a,o.bitmaps),o.bitmaps=null):l(),e}if(await new Promise(e=>`requestIdleCallback`in window?requestIdleCallback(()=>e(),{timeout:2e3}):setTimeout(e,500)),r()){s=!0,o.cube?.dispose(),sS(n.id,i,u),a&&a!==i&&o.bitmaps&&sS(n.id,a,o.bitmaps);return}let d=cS(u);t.initTexture(d),s=!0;let f=e.background;e.background=d,performance.mark(`sm-skybox-high`),o.cube?.dispose(),f&&f!==o.cube&&f instanceof Nc&&f.dispose(),sS(n.id,i,u),a&&a!==i&&o.bitmaps&&sS(n.id,a,o.bitmaps)}async function pS(e,t,n,r=()=>!1){if(!n?.layers.skipped.has(`stars`))try{let i=await Mb();if(!i.skybox)return;n&&(n.credits.skybox={source:i.skybox.source,organisation:i.skybox.organisation,license:i.skybox.license,attribution:i.skybox.attribution,description:i.skybox.description}),await fS(e,t,i.skybox,r)}catch(e){console.warn(`Failed to load skybox:`,e)}}var mS=13;function hS(e,t,n){let r=jx().maxPartsPerZone,i=[],a=[];for(let[o,s]of Object.entries(e.position.zones)){if(o===`major`||o===`moons`||o===`spacecraft`||bb(s)||n.skipsZone(o))continue;let e=s.parent_id_type??`naif`;for(let{zoom:n,data:c}of Sb(s)){if(c.shape===`chunked`)continue;let s=gb(c)?Eb(c,t):null,l=gb(c)&&s!==null?Ab(c,s,r):r>0?Math.min(c.parts,r):c.parts;for(let t=0;t<l;t++){let r={zone:o,zoom:n,part:t,time:s,parentIdType:e};n!==null&&n>=1&&t>=mS?a.push(r):i.push(r)}}}return{eager:i,deferred:a}}async function gS(e,t,n){let r=Pb(e);for(let e of r.keys())n.skipsZone(e)&&r.delete(e);if(r.size===0)return null;console.log(`ProbeStore: ${r.size} zone(s) from metadata:\n`+Array.from(r).map(([e,t])=>` ${e}: chunks=${t.chunks} chunk_days=${t.chunk_days} fit_center=naif-${t.fit_center_naif_id} float64=${t.float64_coeffs}`).join(`
4052
- `));let i=Array.from(r).filter(([,e])=>e.fit_center_naif_id===void 0);i.length>0&&console.warn(`ProbeStore: ${i.length} zone(s) missing fit_center_naif_id in metadata — re-export to refresh: ${i.map(([e])=>e).join(`, `)}`);let a=new qb(r);return await a.ensure(t).done,a}async function _S(e,t,n,r,i,a){let o=[],s=null;e.chebStore&&(s=await Uv(),o.push(...t.processChebyshev(r,s))),e.probeStore&&(s??=await Uv(),a&&e.probeStore.registerCarried(a),o.push(...t.processProbes(e.probeStore,r,s)));let c=n.position.zones.major;if(c&&xb(c))for(let e of[1,2]){let n=c.zooms[String(e)];if(n&&hb(n))for(let r=0;r<n.parts;r++)o.push(...await t.process(`major`,e,r))}let l=e.layers.skipsZone(`moons`)?void 0:n.position.zones.moons,u=l?Cb(l):void 0,d=u&&_b(u)?String(yb(u,i)):null;return u&&o.push(...await t.process(`moons`,null,0,d)),vS(o)}function vS(e){let t=new Map,n=[];for(let r of e){let e=r.data.id;t.has(e)?n.push(e):t.set(e,r)}return n.length>0&&console.warn(`majors: ${n.length} duplicate id(s) in phase 1, kept first:`,n),[...t.values()]}async function yS(e,t,n){performance.mark(`sm-load-start`),G_.reset(),Q_().catch(e=>console.warn(`scene-load: systems-global (GMs/nutation) failed to load:`,e));let r=lb().catch(e=>console.warn(`scene-load: atmospheres failed to load — rendering without shells:`,e)),i=Pg(t),a=Mb();Uv().catch(()=>{}),a.then(t=>{let n=t.position.zones.moons;if(!n||e.layers.skipsZone(`moons`))return;let r=Cb(n);r&&hb(r)&&rb.prefetch(`moons`,null,0,null)}),a.then(t=>{t.skybox&&!e.layers.skipped.has(`stars`)&&uS(t.skybox)});let o=a.then(n=>hS(n,t,e.layers)),s=a.then(async t=>{let n=Nb(t);for(let t of n.keys())e.layers.skipsZone(t)&&n.delete(t);if(n.size===0)return null;let r=new Hb(n);return await r.ensure(i).done,r}),c=a.then(t=>gS(t,i,e.layers)),l=ux(n),u=await a;G_.reach(`metadata`),e.chebStore=await s,e.probeStore=await c,G_.reach(`ephemeris`);let d=new rb(e.chebStore);e.probeStore&&(e.probeStore.fitCenterUsable=t=>(e.chebStore?.has(t)??!1)||e.getBody(t)!==void 0);let f=await _S(e,d,u,t,i,await l);G_.reach(`majors`),await r,e.bodies.addBodies(f),e.credits.recordOrbitSources(f);let p=await Uv();G_.reach(`labels`);let m=!1,h=()=>{m=!0},g=()=>{let t=m;m=!1,e.bodies.flushMinor(t)};if(n&&!e.getBody(n)){let t=await Cx(n,e);wx(e,t,p)>0&&h(),t.length>0&&g()}e.bodies.majorBodies=f.filter(e=>e.data.objectType!==G.BARYCENTER&&e.data.objectType!==G.LAGRANGE_POINT&&e.data.orbitalSource!==W.SPICE_PROBE);try{e.refresher=new Fx(e,u,d,t),n&&e.refresher.want(n)}catch(e){console.error(`scene-load: ZoneRefresher init failed; time-segmented zones stay empty:`,e)}G_.reach(`done`),e.loading=!1,performance.mark(`sm-majors-done`);let{eager:_,deferred:v}=await o,y=_.filter(e=>e.zone===`small_body_moons`),b=_.filter(e=>e.zone!==`small_body_moons`);e.bodies.minorStreaming=!0;let x=setInterval(g,500),S=async(t,n,r)=>{e.credits.recordOrbitSource(n.source),n.rowCount!==0&&(await e.bodies.asteroidBucket(t,p).addChunk(n,r)>0&&h(),e.bodies.dirtyAsteroidZones.add(t))},C=(t,n)=>{e.credits.recordOrbitSources(n);let r=e.bodies.asteroidBucket(t,p);for(let e of n)r.addPlaceholder(e),h();e.bodies.dirtyAsteroidZones.add(t)},w=b.filter(e=>e.zone.startsWith(`small_bodies/`)),T=(e,t)=>n=>{console.warn(`scene-load: ${e} part ${t} failed (skipped):`,n)};try{await Promise.all([...w.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>d.fetchMinorColumns(e,t,n,r).then(t=>S(e,t,i)).catch(T(e,n))),e.refresher?.ready().then(()=>{h()})]),await Promise.all(y.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>d.process(e,t,n,r,i).then(t=>C(e,t)).catch(T(e,n))))}finally{clearInterval(x),e.bodies.minorStreaming=!1,g(),performance.mark(`sm-minors-done`),Rx()}if(v.length>0&&Vx())console.info(`Low-end device: skipping ${v.length} deferred minor-belt parts to conserve memory`);else if(v.length>0){e.bodies.minorStreaming=!0;let t=setInterval(g,1e3);try{await Promise.all(v.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>d.fetchMinorColumns(e,t,n,r,`low`).then(t=>S(e,t,i)).catch(T(e,n))))}finally{clearInterval(t),e.bodies.minorStreaming=!1,g(),performance.mark(`sm-deferred-done`)}}}var bS=$b(async()=>(await Mb(),Yt(`/v1/membership/earth.json.gz`,`membership`)),{onMissing:()=>({}),error:e=>`fetchEarthMembership: ${e.status} ${e.statusText}`});async function xS(e){let t=await bS();return new Set(t[e]??[])}function SS(e,t=s()){return sx(ix,e,t)}var CS={[uv]:new Set([G.SPACECRAFT]),[dv]:new Set([G.DEBRIS])},wS=class{bodies=new R_;credits=new Cn;layers=new Tv;visibility=new zv(this.bodies,()=>this.probeStore,()=>this.earthSatFilter,()=>this.smallBodyFilter,()=>this.layers);#e=Ge(!0);get loading(){return Vt(this.#e)}set loading(e){Ke(this.#e,e,!0)}#t=Ge(null);get error(){return Vt(this.#t)}set error(e){Ke(this.#t,e,!0)}onDataStale=null;constructor(){}chebStore=null;probeStore=null;refresher=null;placer=null;hasMeshBody=null;earthSatFilter=null;earthSatFilterSlug=null;earthTypeFilter=null;smallBodyFilter=null;missionMemberIds=null;currentGroupSlug=null;groupFilterListeners=new Set;smallBodyFilterListeners=new Set;earthSatRolloverListeners=new Set;onGroupFilterChange(e){return this.groupFilterListeners.add(e),()=>this.groupFilterListeners.delete(e)}onSmallBodyFilterChange(e){return this.smallBodyFilterListeners.add(e),()=>this.smallBodyFilterListeners.delete(e)}onEarthSatRollover(e){return this.earthSatRolloverListeners.add(e),()=>this.earthSatRolloverListeners.delete(e)}notifyEarthSatRollover(){for(let e of this.earthSatRolloverListeners)e()}getBody(e,t){return this.bodies.getBody(e,t)}place(e,t){return this.placer?.place(e,t)??null}isMemberOfActiveGroup(e){if(this.missionMemberIds?.has(e)===!0||this.earthSatFilter?.has(e)===!0)return!0;let t=this.earthTypeFilter;if(t){let n=this.bodies.getBody(e)?.data.objectType;if(n!==void 0&&t.has(n))return!0}let n=this.smallBodyFilter;return n===null?!1:kv(this.bodies,e,n)}async load(e,t){try{await yS(this,e,t)}catch(e){throw this.loading=!1,this.error=e instanceof Error?e.message:String(e),console.error(`[scene-load]`,e),e}}refreshTick(e){this.refresher?.tick(e)}async ready(e){await this.refresher?.ready(e)}async ensureBody(e,t){await this.refresher?.ensureBody(e,t)}async applyGroupFilter(e){if(e===this.currentGroupSlug)return;if(this.currentGroupSlug=e,e?.startsWith(`mission-`)){let t=await SS(e);if(e!==this.currentGroupSlug)return;this.missionMemberIds=new Set((t.global?.notable_members??[]).map(e=>e.id).filter(e=>!!e))}else this.missionMemberIds=null;let t=e?await this.resolveIndexEntry(e):null;if(e!==this.currentGroupSlug)return;let n=this.resolveSmallBodyFilter(e,t?.applies_to,t?.n),r=t?.applies_to===`earth_sat`?e:null,i=CS[e??``]??null;if(!hv(this.smallBodyFilter,n)){this.smallBodyFilter=n;for(let e of this.smallBodyFilterListeners)e(n)}if(r===this.earthSatFilterSlug&&i===this.earthTypeFilter)return;let a=r?await xS(r):null;if(e===this.currentGroupSlug){this.earthSatFilter=a,this.earthSatFilterSlug=r,this.earthTypeFilter=i;for(let e of this.groupFilterListeners)e(a);this.loading||(this.bodies.spacecraftByParent.delete(m_),this.bodies.dirtySpacecraftGroups.add(m_),this.bodies.minorBodyVersion++,this.refresher?.invalidateZone(`earth`))}}resolveSmallBodyFilter(e,t,n){if(e===cv)return{kind:`category`,category:`asteroid`};if(e===lv)return{kind:`category`,category:`comet`};if(e===null||t!==`small_body`)return null;if(e.startsWith(`class-`))return{kind:`class`,className:e.slice(av.length)};if(e.startsWith(`flag-`)){let t=e.slice(ov.length),r=fv[t];return r===void 0?null:{kind:`flag`,flag:t,mask:r,n:n??0}}return null}async resolveIndexEntry(e){try{return(await _v())[e]??null}catch{return null}}},TS=400,ES=class{#e=Ge(0);get jd(){return Vt(this.#e)}set jd(e){Ke(this.#e,e,!0)}#t=Ge(1);get timeScale(){return Vt(this.#t)}set timeScale(e){Ke(this.#t,e,!0)}#n=Ge(1);get direction(){return Vt(this.#n)}set direction(e){Ke(this.#n,e,!0)}seeked=!1;#r=Ge(0);get jumps(){return Vt(this.#r)}set jumps(e){Ke(this.#r,e,!0)}#i=Ge(0);get settledJd(){return Vt(this.#i)}set settledJd(e){Ke(this.#i,e,!0)}#a=Ge(!1);get live(){return Vt(this.#a)}set live(e){Ke(this.#a,e,!0)}lastRealMs=0;prevScale=1;stops=null;settleTimer=null;constructor(e,t=!1){this.jd=e,this.settledJd=e,this.live=t,this.lastRealMs=performance.now()}tick(e){let t=e-this.lastRealMs;if(this.lastRealMs=e,this.timeScale===0)return;let n=this.jd+t/Mg*this.timeScale,r=this.stops;if(r!==null){if(this.timeScale>0&&r.forwardJd!==null&&n>=r.forwardJd&&this.jd<r.forwardJd){this.jd=r.forwardJd,this.pause(),r.onHit(r.forwardJd);return}if(this.timeScale<0&&r.backwardJd!==null&&n<=r.backwardJd&&this.jd>r.backwardJd){this.jd=r.backwardJd,this.pause(),r.onHit(r.backwardJd);return}}this.jd=n}setBoundaryStops(e){this.stops=e}setTimeScale(e){let t=e*this.direction;t!==0&&(this.prevScale=t),this.timeScale=t,t!==1&&(this.live=!1),this.lastRealMs=performance.now()}toggleDirection(){this.direction=this.direction===1?-1:1,this.timeScale=-this.timeScale,this.prevScale=-this.prevScale,this.live=!1,this.lastRealMs=performance.now()}setJD(e){this.jd=e,this.seeked=!0,this.live=!1,this.lastRealMs=performance.now(),this.settleAfterPause()}jumpTo(e){this.setJD(e),this.jumps++,this.settle()}settle(){this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=null,this.settledJd=this.jd}settleAfterPause(){this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=null,!this.playing&&(this.settleTimer=setTimeout(()=>this.settle(),TS))}sweepTo(e){this.jd=e,this.live=!1,this.lastRealMs=performance.now()}pause(){this.timeScale!==0&&(this.prevScale=this.timeScale),this.timeScale=0,this.live=!1,this.settle()}play(){this.timeScale===0&&(this.timeScale=this.prevScale||1,this.lastRealMs=performance.now())}now(){this.jumpTo(Pg(new Date)),this.live=this.timeScale===1}get playing(){return this.timeScale!==0}get date(){return Fg(this.jd)}setDate(e){this.jumpTo(Pg(e))}},DS={type:`change`},OS={type:`start`},kS={type:`end`},AS=new vs,jS=new sc,MS=Math.cos(70*Hi.DEG2RAD),NS=new J,PS=2*Math.PI,FS={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},IS=1e-6,LS=class extends qd{constructor(e,t=null){super(e,t),this.state=FS.NONE,this.target=new J,this.cursor=new J,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:`ArrowLeft`,UP:`ArrowUp`,RIGHT:`ArrowRight`,BOTTOM:`ArrowDown`},this.mouseButtons={LEFT:wn.ROTATE,MIDDLE:wn.DOLLY,RIGHT:wn.PAN},this.touches={ONE:Tn.ROTATE,TWO:Tn.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle=`auto`,this._domElementKeyEvents=null,this._lastPosition=new J,this._lastQuaternion=new Ui,this._lastTargetPosition=new J,this._quat=new Ui().setFromUnitVectors(e.up,new J(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Hd,this._sphericalDelta=new Hd,this._scale=1,this._panOffset=new J,this._rotateStart=new q,this._rotateEnd=new q,this._rotateDelta=new q,this._panStart=new q,this._panEnd=new q,this._panDelta=new q,this._dollyStart=new q,this._dollyEnd=new q,this._dollyDelta=new q,this._dollyDirection=new J,this._mouse=new q,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=zS.bind(this),this._onPointerDown=RS.bind(this),this._onPointerUp=BS.bind(this),this._onContextMenu=qS.bind(this),this._onMouseWheel=US.bind(this),this._onKeyDown=WS.bind(this),this._onTouchStart=GS.bind(this),this._onTouchMove=KS.bind(this),this._onMouseDown=VS.bind(this),this._onMouseMove=HS.bind(this),this._interceptControlDown=JS.bind(this),this._interceptControlUp=YS.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e===`grab`?this.domElement.style.cursor=`grab`:this.domElement.style.cursor=`auto`}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointercancel`,this._onPointerUp),this.domElement.addEventListener(`contextmenu`,this._onContextMenu),this.domElement.addEventListener(`wheel`,this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener(`keydown`,this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.removeEventListener(`pointercancel`,this._onPointerUp),this.domElement.removeEventListener(`wheel`,this._onMouseWheel),this.domElement.removeEventListener(`contextmenu`,this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener(`keydown`,this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=`auto`}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(DS),this.update(),this.state=FS.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){let t=this.object.position;NS.copy(t).sub(this.target),NS.applyQuaternion(this._quat),this._spherical.setFromVector3(NS),this.autoRotate&&this.state===FS.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,r=this.maxAzimuthAngle;isFinite(n)&&isFinite(r)&&(n<-Math.PI?n+=PS:n>Math.PI&&(n-=PS),r<-Math.PI?r+=PS:r>Math.PI&&(r-=PS),n<=r?this._spherical.theta=Math.max(n,Math.min(r,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+r)/2?Math.max(n,this._spherical.theta):Math.min(r,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let i=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{let e=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),i=e!=this._spherical.radius}if(NS.setFromSpherical(this._spherical),NS.applyQuaternion(this._quatInverse),t.copy(this.target).add(NS),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let e=null;if(this.object.isPerspectiveCamera){let t=NS.length();e=this._clampDistance(t*this._scale);let n=t-e;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),i=!!n}else if(this.object.isOrthographicCamera){let t=new J(this._mouse.x,this._mouse.y,0);t.unproject(this.object);let n=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),i=n!==this.object.zoom;let r=new J(this._mouse.x,this._mouse.y,0);r.unproject(this.object),this.object.position.sub(r).add(t),this.object.updateMatrixWorld(),e=NS.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),this.zoomToCursor=!1;e!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(e).add(this.object.position):(AS.origin.copy(this.object.position),AS.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(AS.direction))<MS?this.object.lookAt(this.target):(jS.setFromNormalAndCoplanarPoint(this.object.up,this.target),AS.intersectPlane(jS,this.target))))}else if(this.object.isOrthographicCamera){let e=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),e!==this.object.zoom&&(this.object.updateProjectionMatrix(),i=!0)}return this._scale=1,this._performCursorZoom=!1,i||this._lastPosition.distanceToSquared(this.object.position)>IS||8*(1-this._lastQuaternion.dot(this.object.quaternion))>IS||this._lastTargetPosition.distanceToSquared(this.target)>IS?(this.dispatchEvent(DS),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?PS/60/60*this.autoRotateSpeed:PS/60*this.autoRotateSpeed*e}_getZoomScale(e){let t=Math.abs(e*.01);return .95**(this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){NS.setFromMatrixColumn(t,0),NS.multiplyScalar(-e),this._panOffset.add(NS)}_panUp(e,t){this.screenSpacePanning===!0?NS.setFromMatrixColumn(t,1):(NS.setFromMatrixColumn(t,0),NS.crossVectors(this.object.up,NS)),NS.multiplyScalar(e),this._panOffset.add(NS)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;NS.copy(r).sub(this.target);let i=NS.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;let n=this.domElement.getBoundingClientRect(),r=e-n.left,i=t-n.top,a=n.width,o=n.height;this._mouse.x=r/a*2-1,this._mouse.y=-(i/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(PS*this._rotateDelta.x/t.clientHeight),this._rotateUp(PS*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateStart.set(n,r)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panStart.set(n,r)}}_handleTouchStartDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateEnd.set(n,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(PS*this._rotateDelta.x/t.clientHeight),this._rotateUp(PS*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panEnd.set(n,r)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyEnd.set(0,i),this._dollyDelta.set(0,(this._dollyEnd.y/this._dollyStart.y)**+this.zoomSpeed),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);let a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new q,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){let t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){let t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}};function RS(e){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(e.pointerId),this.domElement.ownerDocument.addEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.addEventListener(`pointerup`,this._onPointerUp)),!this._isTrackingPointer(e)&&(this._addPointer(e),e.pointerType===`touch`?this._onTouchStart(e):this._onMouseDown(e),this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grabbing`)))}function zS(e){this.enabled!==!1&&(e.pointerType===`touch`?this._onTouchMove(e):this._onMouseMove(e))}function BS(e){switch(this._removePointer(e),this._pointers.length){case 0:this.domElement.releasePointerCapture(e.pointerId),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.dispatchEvent(kS),this.state=FS.NONE,this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grab`);break;case 1:let t=this._pointers[0],n=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:n.x,pageY:n.y});break}}function VS(e){let t;switch(e.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=-1}switch(t){case wn.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(e),this.state=FS.DOLLY;break;case wn.ROTATE:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=FS.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=FS.ROTATE}break;case wn.PAN:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=FS.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=FS.PAN}break;default:this.state=FS.NONE}this.state!==FS.NONE&&this.dispatchEvent(OS)}function HS(e){switch(this.state){case FS.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(e);break;case FS.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(e);break;case FS.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(e);break}}function US(e){this.enabled===!1||this.enableZoom===!1||this.state!==FS.NONE||(e.preventDefault(),this.dispatchEvent(OS),this._handleMouseWheel(this._customWheelEvent(e)),this.dispatchEvent(kS))}function WS(e){this.enabled!==!1&&this._handleKeyDown(e)}function GS(e){switch(this._trackPointer(e),this._pointers.length){case 1:switch(this.touches.ONE){case Tn.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(e),this.state=FS.TOUCH_ROTATE;break;case Tn.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(e),this.state=FS.TOUCH_PAN;break;default:this.state=FS.NONE}break;case 2:switch(this.touches.TWO){case Tn.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(e),this.state=FS.TOUCH_DOLLY_PAN;break;case Tn.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(e),this.state=FS.TOUCH_DOLLY_ROTATE;break;default:this.state=FS.NONE}break;default:this.state=FS.NONE}this.state!==FS.NONE&&this.dispatchEvent(OS)}function KS(e){switch(this._trackPointer(e),this.state){case FS.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(e),this.update();break;case FS.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(e),this.update();break;case FS.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(e),this.update();break;case FS.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(e),this.update();break;default:this.state=FS.NONE}}function qS(e){this.enabled!==!1&&e.preventDefault()}function JS(e){e.key===`Control`&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}function YS(e){e.key===`Control`&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}var{PI:XS,sin:ZS,cos:QS,asin:$S,atan2:eC,sqrt:tC}=Math,nC=180/XS,rC=XS/180;function iC(e,t,n){let[r,i,a]=e,[o,s,c,l]=n?[-t[0],-t[1],-t[2],t[3]]:t,u=l*r+s*a-c*i,d=l*i+c*r-o*a,f=l*a+o*i-s*r,p=-o*r-s*i-c*a;return[u*l+p*-o+d*-c-f*-s,d*l+p*-s+f*-o-u*-c,f*l+p*-c+u*-s-d*-o]}function aC(e,t,n){let r=e[0]-t[0],i=e[1]-t[1],a=e[2]-t[2],o=tC(r*r+i*i+a*a);return n&&([r,i,a]=iC([r,i,a],n,!0)),{latitude:$S(i/o)*nC,longitude:n?eC(-a,r)*nC:eC(r,a)*nC,distance:o}}function oC(e,t,n,r,i){let a=t*rC,o=n*rC,s,c,l;if(i){let e=[r*QS(a)*QS(o),r*ZS(a),-r*QS(a)*ZS(o)];[s,c,l]=iC(e,i,!1)}else s=r*QS(a)*ZS(o),c=r*ZS(a),l=r*QS(a)*QS(o);return[e[0]+s,e[1]+c,e[2]+l]}function sC(e,t,n,r){let i=e[0]-t[0],a=e[2]-t[2],o=tC(i*i+a*a);o>0?(i/=o,a/=o):(i=0,a=1);let s=n*rC,c=QS(s);return[r*c*i,r*ZS(s),r*c*a]}function cC(e){let t=(e+180)%360-180;return t<=-180?t+360:t}function lC(e,t,n){if(t===void 0&&n===void 0)return e;let r=t===void 0?-180:cC(t),i=r===180?-180:r,a=n===void 0?180:cC(n);if(i<=a?e>=i&&e<=a:e>=i||e<=a)return e;let o=(e,t)=>Math.abs(cC(e-t));return o(e,i)<=o(e,a)?i:a}var uC=m_;function dC(e,t){return`feature:${e}:${t}`}function fC(e,t){return{data:{id:dC(e.hostId,e.featureId),name:t,objectType:G.SURFACE_FEATURE,parentId:e.hostId,radiusKm:NaN,hasLocalized:!1,a:0,e:0,i:0,om:0,w:0,ma:0,n:0,epoch:0,validityStart:-1/0,validityEnd:1/0,orbitalSource:W.UNKNOWN},position:null,orbitCenterId:e.hostId,featureAnchor:e}}var pC={name:`CopyShader`,uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
4051
+ `)){let e=n.indexOf(Bv);if(e===-1)continue;let r=n.slice(0,e),i=n.slice(e+1),a=i.indexOf(Bv),o=a===-1?i:i.slice(0,a),s=a===-1?``:i.slice(a+1);t.set(r,{name:o,isMinor:s.includes(`m`)})}return t}var Hv=new Map;async function Uv(e=s()){let t=Hv.get(e);return t||(t=(async()=>{let t=Qt(e),n=await J_(t,{priority:`high`});if(!n.ok)throw Error(`Failed to fetch ${t}: ${n.status}`);let r=new DecompressionStream(`gzip`);return Vv(await new Response(n.body.pipeThrough(r)).text())})(),Hv.set(e,t),t.catch(()=>{Hv.get(e)===t&&Hv.delete(e)})),t}var Wv=class{map=new Map;constructor(e){this.capacity=e}getOrCompute(e,t){let n=this.map.get(e);if(n)return this.map.delete(e),this.map.set(e,n),n;let r=t();if(this.map.set(e,r),this.map.size>this.capacity){let e=this.map.keys().next().value;e!==void 0&&this.map.delete(e)}return r.catch(()=>{this.map.get(e)===r&&this.map.delete(e)}),r}};function Gv(e,t,n){let r=new DataView(e),i=r.getUint32(24,!0),a=(r.getUint8(28)&1)!=0,o=a?8:4,s=[],c=Zt;for(let t=0;t<i;t++){let n=r.getInt32(c,!0),i=r.getInt32(c+4,!0),l=r.getInt32(c+8,!0),u=r.getFloat32(c+12,!0),d=r.getUint16(c+16,!0),f=r.getUint8(c+18),p=r.getUint8(c+19)===1,m=r.getUint8(c+20),h=r.getUint16(c+22,!0),g=r.getFloat32(c+24,!0);c+=32;let _=ln(f,l)??``;_||console.warn(`chebyshev body[${t}] (naifId=${n}) has unknown id-type ${f}; routing keyed lookups will skip it`);let v=new Float64Array(h),y=new Float64Array(h),b=3*d,x=a?new Float64Array(b*h):new Float32Array(b*h),S=b*o;for(let t=0;t<h;t++){if(v[t]=r.getFloat64(c,!0),y[t]=r.getFloat64(c+8,!0),c+=16,a){let n=new Float64Array(e,c,b);x.set(n,t*b)}else{let n=new Float32Array(e,c,b);x.set(n,t*b)}c+=S}s.push({id:_,naifId:n,parentId:i,hasLocalized:p,objectType:m,radiusKm:u,visibleFromDays:g,coeffsPerAxis:d,startJds:v,endJds:y,coeffs:x})}return{startJd:t,endJd:n,bodies:s}}function Kv(e,t,n,r){let i=n*(r?8:4),a=new(r?Float64Array:Float32Array)(n);if(r&&t%8==0)return a.set(new Float64Array(e,t,n)),a;if(!r&&t%4==0)return a.set(new Float32Array(e,t,n)),a;let o=new DataView(e,t,i);if(r)for(let e=0;e<n;e++)a[e]=o.getFloat64(e*8,!0);else for(let e=0;e<n;e++)a[e]=o.getFloat32(e*4,!0);return a}function qv(e,t,n,r){let i=Kv(e,t,n===1?7:10,r);return n===1?{method:n,aKm:i[0],e:i[1],iRad:i[2],om0:i[3],w0:i[4],m0:i[5],tAnchorOffsetS:i[6]}:{method:n,aKm:i[0],e:i[1],iRad:i[2],om0:i[3],w0:i[4],m0:i[5],omDot:i[6],wDot:i[7],nMeanRadS:i[8],tAnchorOffsetS:i[9]}}var Jv=1e-7,Yv=.001,Xv=1,Zv=2,Qv=16,$v=32;function ey(e,t,n){let r=new DataView(e,t,$v),i=r.getInt32(0,!0),a=r.getUint8(4),o=r.getUint32(8,!0),s=r.getUint32(12,!0),c=r.getInt32(16,!0)*Jv,l=r.getInt32(20,!0)*Jv,u=r.getInt32(24,!0)*Yv,d=r.getUint32(28,!0),f=new Float64Array(d),p=new Float32Array(d),m=new Float32Array(d),h=new Float32Array(d);if(d>0){let r=new DataView(e,t+$v,d*Qv);for(let e=0;e<d;e++){let t=e*Qv;f[e]=n+r.getUint32(t,!0),p[e]=r.getInt32(t+4,!0)*Jv,m[e]=r.getInt32(t+8,!0)*Jv,h[e]=r.getInt32(t+12,!0)*Yv}}return{bodyNaifId:i,isStatic:(a&Xv)!==0,isDestroyed:(a&Zv)!==0,startEt:n+o,endEt:n+s,latRefDeg:c,lngRefDeg:l,altRefM:u,sampleEt:f,sampleLatDeg:p,sampleLngDeg:m,sampleAltM:h}}function ty(e,t,n,r){let i=n/(36*(r?8:4));return{method:3,coeffsPerAxis:12,nSeg:i,coeffs:Kv(e,t,i*3*12,r)}}function ny(e,t,n,r){let i=new DataView(e),a=i.getUint32(24,!0),o=i.getFloat32(28,!0),s=o*Ag,c=Ig(t),l=[],u=Zt;for(let t=0;t<a;t++){let n=i.getInt32(u,!0),a=i.getUint8(u+4),o=i.getUint8(u+5),d=i.getUint8(u+6)===1,f=(i.getUint8(u+7)&1)!=0,p=i.getUint16(u+8,!0),m=i.getUint16(u+10,!0),h=i.getInt32(u+12,!0),g=i.getUint8(u+16),_=i.getUint8(u+17);u+=20;let v=ln(a,n)??``;v||console.warn(`probes payload: probe[${t}] (value=${n}) has unknown id-type ${a}; skipping`);let y=null;if(h!==-1&&g!==255){let e=ln(g,h);e?y={id:e,idType:g,idValue:h}:console.warn(`probes payload: probe[${t}] has unknown fit-center id-type ${g}; falling back to zone default`)}let b=Array(p),x=Array(p),S=Array(p);for(let n=0;n<p;n++){let a=i.getUint8(u),o=i.getUint32(u+4,!0),l=u+8,d=c+(m+n)*s;if(b[n]=d,x[n]=d+s,a===0)S[n]={method:0};else if(a===1||a===2)S[n]=qv(e,l,a,r);else if(a===3)S[n]=ty(e,l,o,r);else throw Error(`Unknown probe sub-chunk method ${a} at probe ${t} sub ${n}`);u=l+o}let C;if(f){let n=i.getUint8(u);if(n!==4)throw Error(`probe ${t}: PROBE_FLAG_HAS_LANDED_RECORD set but trailing record method = ${n}, expected 4`);let r=i.getUint32(u+4,!0),a=u+8;C=ey(e,a,c),u=a+r}let w=Array(_);for(let e=0;e<_;e++)w[e]={startEt:i.getFloat64(u,!0),endEt:i.getFloat64(u+8,!0),systemNaifId:i.getUint8(u+16)},u+=17;l.push({id:v,probeId:n,hasLocalized:d,objectType:o,fitCenter:y,subStartEt:b,subEndEt:x,subChunks:S,landed:C,systemIntervals:w})}return{startJd:t,endJd:n,subchunkDays:o,probes:l}}function ry(e,t={}){let n=new DataView(e),r=n.getUint32(0,!0);if(r!==1346456915)throw Error(`Invalid position file: bad magic 0x${r.toString(16)}`);let i=n.getUint16(4,!0);if(i!==13)throw Error(`Unsupported position file version: ${i}`);let a=n.getUint8(6),o=n.getFloat64(8,!0),s=n.getFloat64(16,!0);if(a===0)return{kind:`elements`,columns:Dh(e,o,s)};if(a===1)return{kind:`chebyshev`,chunk:Gv(e,o,s)};if(a===2)return{kind:`probes`,chunk:ny(e,o,s,t.probesFloat64??!1)};throw Error(`Unknown position-file format: ${a}`)}function iy(e,t,n){let r=e.length;if(r===0||n<e[0]||n>=t[r-1])return-1;let i=0,a=r-1;for(;i<a;){let t=i+a+1>>>1;e[t]<=n?i=t:a=t-1}return n<t[i]?i:-1}function ay(e,t){let n=iy(e.startJds,e.endJds,t);if(n<0)return null;let r=e.startJds[n],i=e.endJds[n],a=2*(t-r)/(i-r)-1,o=e.coeffsPerAxis,s=e.coeffs,c=n*3*o,l=[0,0,0],u=2*a;for(let e=0;e<3;e++){let t=c+e*o;if(o===1){l[e]=s[t];continue}let n=0,r=0;for(let e=o-1;e>=1;e--){let i=s[t+e]+u*n-r;r=n,n=i}l[e]=s[t]+a*n-r}return l}function oy(e,t){let n=ay(e,t);return n===null?null:[Q(n[0]),Q(n[2]),-Q(n[1])]}function sy(e,t){let n=iy(e.startJds,e.endJds,t);if(n<0)return null;let r=e.startJds[n],i=e.endJds[n],a=2*(t-r)/(i-r)-1,o=2/(i-r),s=e.coeffsPerAxis,c=e.coeffs,l=n*3*s,u=[0,0,0],d=[0,0,0],f=2*a;for(let e=0;e<3;e++){let t=l+e*s;if(s===1){u[e]=c[t],d[e]=0;continue}let n=0,r=0;for(let e=s-1;e>=1;e--){let i=c[t+e]+f*n-r;r=n,n=i}u[e]=c[t]+a*n-r;let i=0,p=0;for(let e=s-2;e>=0;e--){let n=c[t+e+1]*(e+1)+f*i-p;p=i,i=n}d[e]=i*o}return{position:u,velocity:d}}Math.PI/180;var cy=180/Math.PI;ag/86400;var ly=1e-9,uy=1e-9;function dy(e,t,n){return e<t?t:e>n?n:e}function fy(e,t,n,r){let[i,a,o]=e,[s,c,l]=t,u=Math.hypot(i,a,o),d=s*s+c*c+l*l;if(u===0||n<=0||!isFinite(u)||!isFinite(d))return null;let f=a*l-o*c,p=o*s-i*l,m=i*c-a*s,h=Math.hypot(f,p,m);if(h===0)return null;let g=Math.acos(dy(m/h,-1,1)),_=Math.sin(g),v=(c*m-l*p)/n-i/u,y=(l*f-s*m)/n-a/u,b=(s*p-c*f)/n-o/u,x=Math.hypot(v,y,b),S=2/u-d/n;if(Math.abs(S)<1e-12)return null;let C=1/S,w=-p,T=f,E=Math.hypot(w,T),D;_<uy||E===0?D=0:(D=Math.acos(dy(w/E,-1,1)),T<0&&(D=2*Math.PI-D));let O;if(x<ly)O=0;else if(_<uy||E===0)O=Math.atan2(y,v),m<0&&(O=-O),O<0&&(O+=2*Math.PI);else{let e=(w*v+T*y)/(E*x);O=Math.acos(dy(e,-1,1)),b<0&&(O=2*Math.PI-O)}let k,A=i*s+a*c+o*l;if(x<ly&&(_<uy||E===0))k=Math.atan2(a,i),m<0&&(k=-k),k<0&&(k+=2*Math.PI);else if(x<ly){let e=(w*i+T*a)/(E*u);k=Math.acos(dy(e,-1,1)),o<0&&(k=2*Math.PI-k)}else{let e=(v*i+y*a+b*o)/(x*u);k=Math.acos(dy(e,-1,1)),A<0&&(k=2*Math.PI-k)}let j;if(x<1){let e=2*Math.atan2(Math.sqrt(1-x)*Math.sin(k/2),Math.sqrt(1+x)*Math.cos(k/2));j=e-x*Math.sin(e)}else if(x>1){let e=2*Math.atanh(Math.sqrt((x-1)/(x+1))*Math.tan(k/2));if(!isFinite(e))return null;j=x*Math.sinh(e)-e}else return null;let M=Math.abs(C),ee=Math.sqrt(n/(M*M*M))*cy;return{a:C,e:x,i:g*cy,om:D*cy,w:O*cy,ma:j*cy,n:ee,epoch:r,equatorial:!1}}function py(e,t){let n=e.subStartEt,r=e.subEndEt,i=n.length;if(i===0||t<n[0]||t>=r[i-1])return-1;let a=0,o=i-1;for(;a<o;){let e=a+o+1>>>1;n[e]<=t?a=e:o=e-1}return t<r[a]?a:-1}function my(e,t,n,r,i){let a=Math.cos(i),o=Math.sin(i),s=Math.cos(r),c=Math.sin(r),l=Math.cos(n),u=Math.sin(n);return[(l*a-u*o*s)*e+(-l*o-u*a*s)*t,(u*a+l*o*s)*e+(-u*o+l*a*s)*t,o*c*e+a*c*t]}function hy(e,t,n,r,i,a){if(t>=1)return null;let o=Sg(a,t),s=Math.sin(o),c=Math.cos(o),l=Math.sqrt(1-t*t)*s/(1-t*c),u=(c-t)/(1-t*c),d=e*(1-t*c),f=d*u,p=d*l;return!isFinite(f)||!isFinite(p)?null:my(f,p,r,n,i)}function gy(e,t,n,r){let i=n-(t+e.tAnchorOffsetS),a=Math.sqrt(r/(e.aKm*e.aKm*e.aKm)),o=e.m0+a*i;return hy(e.aKm,e.e,e.iRad,e.om0,e.w0,o)}function _y(e,t,n){let r=n-(t+e.tAnchorOffsetS),i=e.om0+e.omDot*r,a=e.w0+e.wDot*r,o=e.m0+e.nMeanRadS*r;return hy(e.aKm,e.e,e.iRad,i,a,o)}function vy(e,t,n,r){let{coeffs:i,coeffsPerAxis:a,nSeg:o}=e,s=(n-t)/o,c=Math.floor((r-t)/s);c<0?c=0:c>=o&&(c=o-1);let l=2*(r-(t+c*s))/s-1,u=2*l,d=c*3*a,f=[0,0,0];for(let e=0;e<3;e++){let t=d+e*a;if(a===1){f[e]=i[t];continue}let n=0,r=0;for(let e=a-1;e>=1;e--){let a=i[t+e]+u*n-r;r=n,n=a}f[e]=i[t]+l*n-r}return!isFinite(f[0])||!isFinite(f[1])||!isFinite(f[2])?null:f}function yy(e,t,n,r,i){switch(e.method){case 0:return null;case 1:return gy(e,t,r,i);case 2:return _y(e,t,r);case 3:return vy(e,t,n,r)}}function by(e,t,n){let r=Ig(t),i=py(e,r);return i<0?null:yy(e.subChunks[i],e.subStartEt[i],e.subEndEt[i],r,n)}function xy(e,t,n){let r=by(e,t,n);return r===null?null:[Q(r[0]),Q(r[2]),-Q(r[1])]}function Sy(e){if(!e.landed)return!1;let t=e.subEndEt.length;return t===0||e.subEndEt[t-1]<=e.landed.endEt}function Cy(e,t){if(!e.landed)return!1;let n=Ig(t);return n>=e.landed.startEt&&(n<e.landed.endEt||Sy(e))}function wy(e,t,n=!1){let r=Ig(t);if(r<e.startEt||!n&&r>=e.endEt)return null;let i=e.sampleEt.length;if(i===0||r<e.sampleEt[0])return{latDeg:e.latRefDeg,lngDeg:e.lngRefDeg,altM:e.altRefM};let a=0,o=i-1;for(;a<o;){let t=a+o+1>>>1;e.sampleEt[t]<=r?a=t:o=t-1}return{latDeg:e.sampleLatDeg[a],lngDeg:e.sampleLngDeg[a],altM:e.sampleAltM[a]}}var Ty=30/Ag;function Ey(e,t,n){let r=by(e,t,n);if(r===null)return null;let i=Ty,a=by(e,t+i,n),o=by(e,t-i,n),s,c,l;if(a!==null&&o!==null)s=a,c=o,l=1/(2*i);else if(a!==null)s=a,c=r,l=1/i;else if(o!==null)s=r,c=o,l=1/i;else return null;return{position:r,velocity:[(s[0]-c[0])*l,(s[1]-c[1])*l,(s[2]-c[2])*l]}}var Dy=180/Math.PI;function Oy(e,t,n){if(n<=0)return null;let r=Math.sqrt(n/(e.aKm*e.aKm*e.aKm)),i=Lg(t+e.tAnchorOffsetS);return{a:e.aKm/ag,e:e.e,i:e.iRad*Dy,om:e.om0*Dy,w:e.w0*Dy,ma:e.m0*Dy,n:r*Dy*Ag,epoch:i,equatorial:!1}}function ky(e,t){let n=Lg(t+e.tAnchorOffsetS);return{a:e.aKm/ag,e:e.e,i:e.iRad*Dy,om:e.om0*Dy,w:e.w0*Dy,ma:e.m0*Dy,n:e.nMeanRadS*Dy*Ag,omDot:e.omDot*Dy*Ag,wDot:e.wDot*Dy*Ag,epoch:n,equatorial:!1}}function Ay(e,t,n){if(n<=0)return null;let r=Ey(e,t,n);if(!r)return null;let i=n*sg;return fy([r.position[0]/ag,r.position[1]/ag,r.position[2]/ag],[r.velocity[0]*cg,r.velocity[1]*cg,r.velocity[2]*cg],i,t)}function jy(e,t,n){let r=py(e,Ig(t));if(r<0)return null;let i=e.subChunks[r];switch(i.method){case 0:return null;case 1:return Oy(i,e.subStartEt[r],n);case 2:return ky(i,e.subStartEt[r]);case 3:return Ay(e,t,n)}}function My(e,t,n,r){let i=e.fitCenter;if(!i||i.id===n||!r)return null;let a=r.body(i.id,t),o=r.body(n,t);if(!a||!o)return null;if(a.parentId!==o.parentId)return console.warn(`fit-center override: ${i.id} (parent ${a.parentId}) and zone center ${n} (parent ${o.parentId}) don't share a chebyshev parent; treating the record as unplaceable`),null;let s=sy(a,t),c=sy(o,t);return!s||!c?null:{id:i.id,naifId:a.naifId,positionKm:[s.position[0]-c.position[0],s.position[1]-c.position[1],s.position[2]-c.position[2]],velocityKmDay:[s.velocity[0]-c.velocity[0],s.velocity[1]-c.velocity[1],s.velocity[2]-c.velocity[2]]}}function Ny(e){let t=e-18e6;if(t>=2e6&&t<=2999999){let e=tv(t);if(e!==void 0)return{naifId:t,muKm3S2:e}}return{naifId:e,muKm3S2:tv(e)??0}}function Py(e,t,n,r,i){let a=`naif-${n}`,o=e.fitCenter;if(o&&o.id!==a){let n=My(e,t,a,r);return n?{id:n.id,naifId:n.naifId,muKm3S2:tv(n.naifId)??0}:i?.(o.id)?o.idType===an.SPKID?{id:o.id,...Ny(o.idValue)}:{id:o.id,naifId:o.idValue,muKm3S2:tv(o.idValue)??0}:null}return{id:a,naifId:n,muKm3S2:tv(n)??0}}var Fy=1/256,Iy=class{capacity;stepDays;epsilonScene;spanDays;needsPopulate=!1;positions;jds;head=0;_count=0;constructor(e,t,n=1/0,r){this.capacity=e,this.stepDays=t,this.epsilonScene=n,this.spanDays=r??t*e,this.positions=new Float32Array(e*3),this.jds=new Float64Array(e)}get count(){return this._count}reconfigure(e,t,n){Number.isFinite(e)&&e>0&&(this.stepDays=e),this.epsilonScene=t,this.spanDays=n??this.stepDays*this.capacity}get newestJd(){if(this._count===0)return NaN;let e=(this.head-1+this.capacity)%this.capacity;return this.jds[e]}readNewestPos(e){if(this._count===0)return!1;let t=(this.head-1+this.capacity)%this.capacity*3;return e[0]=this.positions[t],e[1]=this.positions[t+1],e[2]=this.positions[t+2],!0}append(e,t,n,r){let i=this.head;this.jds[i]=e,this.positions[i*3]=t,this.positions[i*3+1]=n,this.positions[i*3+2]=r,this.head=(i+1)%this.capacity,this._count<this.capacity&&this._count++}clear(){this.head=0,this._count=0}writeVertices(e,t,n,r,i){let a=Math.min(this._count,e.length/3|0),o=i?new Float64Array(3):null;for(let s=0;s<a;s++){let a=(this.head-1-s+this.capacity)%this.capacity,c=a*3,l=s*3;if(i&&o){o[0]=this.positions[c],o[1]=this.positions[c+1],o[2]=this.positions[c+2],i(this.jds[a],o),e[l]=o[0]+t,e[l+1]=o[1]+n,e[l+2]=o[2]+r;continue}e[l]=this.positions[c]+t,e[l+1]=this.positions[c+1]+n,e[l+2]=this.positions[c+2]+r}return a}},Ly=200;function Ry(e,t,n,r=!1){if(r)return{stepDays:Ly/n,epsilonScene:1/0,spanDays:Ly};let i=e!==null&&e.n>0,a=i?360/e.n:t,o=a>0?a/n:1,s=e?e.a*(1-e.e):0,c=s>0?s*10*1e-4:1/0;return{stepDays:o,epsilonScene:c,spanDays:!i&&isFinite(c)?1/0:o*n}}function zy(e){let t=Number(e.slice(5));return e=>e===t}function By(e,t,n,r){let i=zy(r);return a=>{let o=e.probeWithCenter(n,a,i);if(!o)return null;let s=Py(o.probe,a,o.fitCenterNaifId,t,e=>e===r);return!s||s.id!==r?null:xy(o.probe,a,s.muKm3S2)}}function Vy(e,t,n,r,i){let a=e((t+r)/2);if(!a)return null;let o=a[0]-(n[0]+i[0])/2,s=a[1]-(n[1]+i[1])/2,c=a[2]-(n[2]+i[2])/2;return Math.sqrt(o*o+s*s+c*c)}var Hy=.005;function Uy(e,t,n,r,i,a,o){let s=(e,t)=>{if(e===null)return!1;let i=Math.hypot(t[0]-n[0],t[1]-n[1],t[2]-n[2]);return e<=Math.max(r,Hy*i)},c=t+o*a,l=e(c);if(l!==null&&s(Vy(e,t,n,c,l),l))return{jd:c,pos:l};let u=i,d=a,f=null,p=i*.25;for(let r=0;r<16;r++){let r=(u+d)/2,i=t+o*r,a=e(i);if(a===null){d=r;continue}if(s(Vy(e,t,n,i,a),a)?(u=r,f={jd:i,pos:a}):d=r,d-u<p)break}if(f)return f;let m=t+o*i,h=e(m);return h?{jd:m,pos:h}:null}function Wy(e,t,n,r,i,a){Gy(e,By(t,n,r,i),a)}function Gy(e,t,n){let r=t(n);if(!r)return;let i=[{jd:n,pos:r}];if(isFinite(e.epsilonScene)){let r=e.stepDays*16,a=e.stepDays*Fy,o=n-e.spanDays;for(;i.length<e.capacity;){let n=i[i.length-1];if(n.jd<=o)break;let s=Uy(t,n.jd,n.pos,e.epsilonScene,a,r,-1);if(!s)break;if(s.jd<o){let e=t(o);e&&i.push({jd:o,pos:e});break}i.push(s)}}else for(let r=1;r<e.capacity;r++){let a=n-r*e.stepDays,o=t(a);o&&i.push({jd:a,pos:o})}for(let t=i.length-1;t>=0;t--){let n=i[t];e.append(n.jd,n.pos[0],n.pos[1],n.pos[2])}}function Ky(e,t,n,r,i){if(!isFinite(e.epsilonScene))return;let a=e.stepDays*16,o=e.stepDays*Fy,s=n,c=r;for(let n=0;n<e.capacity&&!(i-s<=o);n++){let n=Math.min(a,i-s),r=Uy(t,s,c,e.epsilonScene,o,n,1);if(!r||r.jd<=s)break;e.append(r.jd,r.pos[0],r.pos[1],r.pos[2]),s=r.jd,c=r.pos}}function qy(e,t){let n=0,r=1/0;for(let i=0;i<e.length;i++){let a=(e[i][0]-t[0])**2+(e[i][1]-t[1])**2+(e[i][2]-t[2])**2;a<r&&(r=a,n=i)}let i=Math.max(n-1,0),a=Math.min(n+1,e.length-1);return(e[i][0]-t[0])**2+(e[i][1]-t[1])**2+(e[i][2]-t[2])**2<(e[a][0]-t[0])**2+(e[a][1]-t[1])**2+(e[a][2]-t[2])**2?i:n}function Jy(e,t,n,r,i,a,o){if(t.length===0)return[];let s=e.trailAnchor??e.position;if(!s)return[];let c=[s[0]-r,s[1]-i,s[2]-a],l=o??qy(t,c),u=[c];if(n)for(let e=0;e<511;e++){let n=Math.max(l-e,0);if(u.push(t[n]),n===0)break}else{for(let e=0;e<511;e++)u.push(t[((l-e)%512+512)%512]);u.push(c)}return u.filter(e=>e.every(Number.isFinite))}function Yy(e,t,n,r){let i=.55,a=n?0:i/3,o=e.length-1;for(let t=0;t<e.length;t++)e[t]=i-(o>0?t/o:0)*(i-a);if(r){let e=.35;t.fill(0);for(let n=0;n<Math.min(171,t.length);n++)t[n]=e-n/170*e}else t.set(e)}var Xy=0,Zy=10;function Qy(e,t,n,r){let i=tv(t);if(!i)return null;let a=sy(e,n);if(!a)return null;let o=r?sy(r,n):null;if(r&&!o)return null;let s=i*sg;return fy([(a.position[0]-(o?.position[0]??0))/ag,(a.position[1]-(o?.position[1]??0))/ag,(a.position[2]-(o?.position[2]??0))/ag],[(a.velocity[0]-(o?.velocity[0]??0))*cg,(a.velocity[1]-(o?.velocity[1]??0))*cg,(a.velocity[2]-(o?.velocity[2]??0))*cg],s,n)}function $y(e,t,n){return!n||e.parentId!==Xy||e.naifId===Zy?null:Qy(e,Zy,t,n)}function eb(e,t,n,r){return r?tn(e,t,r,n):en(e,t,n)}var tb=new Wv(8);async function nb(e,t,n,r,i){let a=`${e}:${t??``}:${n}:${r??``}`;return tb.getOrCompute(a,async()=>{let a=await J_(eb(e,t,n,r),{priority:i});if(!a.ok)throw Error(`Failed to fetch elements: ${a.status}`);let o=new DecompressionStream(`gzip`),s=ry(await new Response(a.body.pipeThrough(o)).arrayBuffer());if(s.kind!==`elements`)throw Error(`Expected elements payload at ${e}/${t}/${n}, got ${s.kind}`);return s.columns})}var rb=class{static prefetch(e,t,n,r=null){fetch(eb(e,t,n,r))}barycenters=new Map;probeBuffers=new Map;constructor(e){this.cheb=e}processChebyshev(e,t){if(!this.cheb)return[];let n=Pg(e),r=this.barycenters.size===0,i=[],a=new Map,o=Array.from(this.cheb.bodiesAt(n));o.sort((e,t)=>{let n=e=>e.objectType===G.BARYCENTER?0:e.objectType===G.STAR?1:e.naifId%100==99?2:3;return n(e.body)-n(t.body)||e.body.naifId-t.body.naifId});let s=this.cheb,c=s.body(`naif-${Zy}`,n);for(let{body:e,startJd:l,endJd:u}of o){let o=oy(e,n);if(!o)continue;a.set(e.naifId,e);let d=`naif-${e.parentId}`,f=e.objectType,p=f===G.MOON&&e.parentId>=1&&e.parentId<=9?`naif-${e.parentId*100+99}`:null,m=(e,t)=>{if(!p)return Qy(e,e.parentId,t);let n=s.body(p,t);return n?Qy(e,e.parentId,t,n):null},h=m(e,n),g=e.id,_=e=>{let t=s.body(g,e);return t?m(t,e):null},v=Math.hypot(o[0],o[1],o[2])/10,y={id:e.id,name:Gg(t,e.id),isMinor:Kg(t,e.id),hasLocalized:e.hasLocalized,objectType:f,parentId:`naif-${e.parentId}`,radiusKm:e.radiusKm,a:h?Math.abs(h.a):v,e:h?.e??0,i:h?.i??0,om:h?.om??0,w:h?.w??0,ma:h?.ma??0,n:h?.n??0,epoch:h?.epoch??0,equatorial:!1,helioElements:$y(e,n,c)??void 0,validityStart:l,validityEnd:u,orbitalSource:W.SPICE,visibleFromDays:e.visibleFromDays};if(f===G.BARYCENTER||f===G.LAGRANGE_POINT){r&&h&&h.a>0&&h.e<1&&this.barycenters.set(e.id,h),i.push({data:y,position:null,orbitElements:h??void 0,orbitCenterId:d,rederiveElements:_});continue}if(vn(f)){let t=f===G.MOON,n=this.barycenters.get(d),r=t?h:n??h,o=!t&&n!==void 0,c=a.get(e.parentId)?.id,l=o&&c?e=>{let t=s.body(c,e);return t?Qy(t,t.parentId,e):null}:_;i.push({data:y,position:null,orbitElements:r??void 0,orbitCenterId:o?void 0:p??d,trailAnchorId:o?d:void 0,rederiveElements:l})}else i.push({data:y,position:null,orbitElements:h??void 0,orbitCenterId:d,rederiveElements:_})}return i}processProbes(e,t,n){let r=Pg(t),i=[],a=new Map,o=new Set;for(let{id:t,probe:s,zoneCenterNaifId:c,startJd:l,endJd:u}of e.probesAt(r)){if(!t)continue;c===void 0&&o.add(t);let d=`naif-${c}`,f=c===void 0?null:Py(s,r,c,this.cheb,()=>!0),p=f?f.id:d,m=f?.muKm3S2??0;if(m===0){let e=a.get(p);e||a.set(p,e=new Set),e.add(t)}let h={id:t,name:Gg(n,t),isMinor:Kg(n,t),hasLocalized:s.hasLocalized,objectType:s.objectType,parentId:p,loadParentId:p,radiusKm:NaN,a:0,e:0,i:0,om:0,w:0,ma:0,n:0,epoch:0,equatorial:!1,validityStart:l,validityEnd:u,orbitalSource:W.SPICE_PROBE},g=jy(s,r,m),_=t,v=this.cheb,y=t=>{let n=e.probeWithCenter(_,t);if(!n)return null;let r=Py(n.probe,t,n.fitCenterNaifId,v,()=>!0);return r?jy(n.probe,t,r.muKm3S2):null},b;{let{stepDays:e,epsilonScene:n,spanDays:r}=Ry(g,u-l,512),i=this.probeBuffers.get(t);i&&i.parentKey===p?(b=i.buffer,!isFinite(b.epsilonScene)&&isFinite(n)&&b.reconfigure(e,n,r)):(b=new Iy(512,e,n,r),b.needsPopulate=!0,this.probeBuffers.set(t,{buffer:b,parentKey:p}))}i.push({data:h,position:null,orbitElements:g??void 0,orbitCenterId:p,rederiveElements:y,trailBuffer:b})}o.size>0&&console.error(`processProbes: ${o.size} probe(s) have undefined fit_center_naif_id — metadata.json is stale (re-export to pick up fit_center_naif_id field). Affected probe ids: ${Array.from(o).slice(0,10).join(`, `)}`+(o.size>10?` (+${o.size-10} more)`:``));for(let[e,t]of a)console.warn(`processProbes: GM unavailable for ${e} — kepler_pure sub-chunks will use mu=0 (static snapshot); affected ${t.size} probe(s): ${Array.from(t).slice(0,5).join(`, `)}`+(t.size>5?` (+${t.size-5} more)`:``));return i}async fetchMinorColumns(e,t,n,r=null,i){return nb(e,t,n,r,i)}async process(e,t,n,r=null,i=`naif`,a){let o=this.barycenters.size===0,s=[],c=0,[l,u]=await Promise.all([nb(e,t,n,r,a),Uv()]),d=l.kind===`parabolic`,f=l.kind===`sgp4`,p=performance.now();for(let e=0;e<l.rowCount;e++){(e&255)==255&&performance.now()-p>6&&(await Og(),p=performance.now());let t=l.objectType[e];if(!d&&l.a[e]===0&&t!==G.BARYCENTER&&t!==G.LAGRANGE_POINT&&!vn(t)){c++;continue}let n=`${i}-${l.parentId[e]}`,r=d?Yg(l,e,u,i):f?e_(l,e,u,i):Jg(l,e,u,i);if(r){if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){o&&r.a>0&&r.e<1&&this.barycenters.set(r.id,r),s.push({data:r,position:null,orbitElements:r.a>0?r:void 0,orbitCenterId:n});continue}if(vn(t)){let e=t===G.MOON,i=this.barycenters.has(n);s.push({data:r,position:null,orbitElements:e?r:this.barycenters.get(n)??r,orbitCenterId:e||!i?n:void 0})}else s.push({data:r,position:null})}}return c>0&&console.debug(`process(${e}/${t}/${n}): skipped ${c} row(s) with a = 0`),s}},ib=new Map,ab=null,ob=null;function sb(e){if(!e)return;let t=e.ls_deg.length;if(t<2||e.dust_tau_factor.length!==t||e.dust_scale_height_km.length!==t||e.pressure_factor.length!==t){console.warn(`atmospheres: malformed seasonal table — ignored`);return}return{lsDeg:e.ls_deg,dustTauFactor:e.dust_tau_factor,dustScaleHeightKm:e.dust_scale_height_km,pressureFactor:e.pressure_factor}}function cb(e,t,n){if(t){if(!n||n<2||!(t.top_km>0)||t.flux_down.length!==3*n||t.flux_up_ratio.length!==3*n||t.extinction_per_km.length!==3*n){console.warn(`atmospheres: ${e} has a malformed deep column — ignored`);return}return{n,topKm:t.top_km,fluxDown:t.flux_down,fluxUpRatio:t.flux_up_ratio,extinctionPerKm:t.extinction_per_km}}}function lb(){if(ob)return ob;let e=(async()=>{let e=await J_(`${Wt()}/v1/atmospheres.json`);if(!e.ok){console.warn(`atmospheres: fetch failed (${e.status}) — rendering without shells`);return}let t=await e.json();ab=t.sun?.limb_darkening_alpha??null;for(let[e,n]of Object.entries(t.bodies)){let r=t.phases[n.phase];if(!r||r.length!==3*t.phase_n){console.warn(`atmospheres: ${e} has bad phase table "${n.phase}" — skipped`);continue}let i=n.mie_profile;i&&i.length!==t.profile_n&&(console.warn(`atmospheres: ${e} has a bad mie profile — falling back to exponential`),i=void 0),ib.set(e,{topAltitudeKm:n.top_altitude_km,rayleighScatterPerKm:n.rayleigh_scatter_per_km,rayleighScaleHeightKm:n.rayleigh_scale_height_km,mieScatterPerKm:n.mie_scatter_per_km,mieAbsorptionPerKm:n.mie_absorption_per_km,mieScaleHeightKm:n.mie_scale_height_km,miePhase:r,absorptionPerKm:n.absorption_per_km,absorptionCenterKm:n.absorption_center_km,absorptionWidthKm:n.absorption_width_km,bakedCompensation:n.baked_compensation,multiScatterGain:n.multi_scatter_gain,sunIntensity:n.sun_intensity,sunColor:[1,1,1],realisticSunAlways:n.realistic_sun_always,refractivity:n.refractivity,groundAlbedo:n.ground_albedo,mieProfile:i,seasonal:sb(n.seasonal),referenceAltitudeKm:n.reference_altitude_km,deepColumn:cb(e,n.deep_column,t.deep_n)})}})();return e.catch(()=>{ob===e&&(ob=null)}),ob=e,e}function ub(e){return ib.get(e)}function db(){return ab}var fb=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]);function pb(e,t){return e>>>t|e<<32-t}function mb(e){let t=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),n=Math.ceil((e.length+9)/64),r=new Uint8Array(n*64);r.set(e),r[e.length]=128,new DataView(r.buffer).setUint32(r.length-4,e.length*8,!1);let i=new Uint32Array(64),a=new DataView(r.buffer);for(let e=0;e<n;e++){for(let t=0;t<16;t++)i[t]=a.getUint32(e*64+t*4,!1);for(let e=16;e<64;e++){let t=pb(i[e-15],7)^pb(i[e-15],18)^i[e-15]>>>3,n=pb(i[e-2],17)^pb(i[e-2],19)^i[e-2]>>>10;i[e]=i[e-16]+t+i[e-7]+n|0}let[n,r,o,s,c,l,u,d]=t;for(let e=0;e<64;e++){let t=pb(c,6)^pb(c,11)^pb(c,25),a=c&l^~c&u,f=d+t+a+fb[e]+i[e]|0,p=(pb(n,2)^pb(n,13)^pb(n,22))+(n&r^n&o^r&o)|0;d=u,u=l,l=c,c=s+f|0,s=o,o=r,r=n,n=f+p|0}t[0]=t[0]+n|0,t[1]=t[1]+r|0,t[2]=t[2]+o|0,t[3]=t[3]+s|0,t[4]=t[4]+c|0,t[5]=t[5]+l|0,t[6]=t[6]+u|0,t[7]=t[7]+d|0}let o=new Uint8Array(32),s=new DataView(o.buffer);for(let e=0;e<8;e++)s.setUint32(e*4,t[e],!1);return o}function hb(e){return e.shape===`parted`}function gb(e){return e.shape===`chunked-parted`&&e.label===`date`}function _b(e){return e.shape===`chunked-parted`&&e.label===`index`}function vb(e){return e.shape===`chunked`}function yb(e,t){let n=Math.floor((t-e.start_jd)/e.chunk_days);return Math.max(0,Math.min(e.chunks-1,n))}function bb(e){return`shape`in e&&e.shape===`probes`}function xb(e){return`zooms`in e}function Sb(e){return bb(e)?[]:xb(e)?Object.entries(e.zooms).map(([e,t])=>({zoom:Number(e),data:t})):[{zoom:null,data:e}]}function Cb(e){return!xb(e)&&!bb(e)?e:void 0}var wb=new WeakMap;function Tb(e){let t=wb.get(e);return t||(t=Object.keys(e.parts_by_date).map(e=>Date.parse(`${e}T00:00:00Z`)).sort((e,t)=>e-t),wb.set(e,t)),t}function Eb(e,t){let n=Tb(e),r=t.getTime(),i=e=>new Date(e).toISOString().slice(0,10);if(r<=n[0])return i(n[0]);if(r>=n[n.length-1])return i(n[n.length-1]);let a=0,o=n.length-1;for(;a<o;){let e=a+o>>1;n[e]<r?a=e+1:o=e}let s=n[a-1],c=n[a];return i(r-s<=c-r?s:c)}var Db=14;function Ob(e){let t=Tb(e);return t[t.length-1]+Db*864e5}function kb(e,t){let n=Tb(e),r=t.getTime(),i=Db*864e5,a=n[0],o=n[n.length-1];if(r<a)return{kind:`covered`};if(r>o+i)return{kind:`after`,lastMs:o+i};if(r>=o)return{kind:`covered`};let s=0,c=n.length-1;for(;s<c;){let e=s+c>>1;n[e]<r?s=e+1:c=e}let l=n[s],u=s>0?n[s-1]:l;return Math.min(r-u,l-r)>i?{kind:`gap`}:{kind:`covered`}}function Ab(e,t,n=0){let r=e.parts_by_date[t]??e.parts;return n>0?Math.min(r,n):r}var jb=null;function Mb(){if(jb)return jb;let e=J_(`${Wt()}/v1/metadata.json`).then(e=>{if(!e.ok)throw Error(`Failed to fetch metadata: ${e.status}`);return e.json()}).then(e=>(Jt(e.versions),e));return jb=e,e.catch(()=>{jb===e&&(jb=null)}),jb}function Nb(e){let t=new Map;for(let[n,r]of Object.entries(e.position.zones)){if(bb(r))continue;let e=xb(r)?0:null,i=e===0?r.zooms[0]:r;!i||!vb(i)||t.set(n,{zoom:e,chunks:i.chunks,chunk_days:i.chunk_days,start_jd:i.start_jd,end_jd:i.end_jd})}return t}function Pb(e){let t=new Map,n=Object.entries(e.position.zones).filter(([,e])=>bb(e)).sort(([e],[t])=>(e===`probes/interplanetary`)-+(t===`probes/interplanetary`)||e.localeCompare(t));for(let[e,r]of n)bb(r)&&t.set(e,{chunks:r.chunks,chunk_days:r.chunk_days,start_jd:r.start_jd,end_jd:r.end_jd,float64_coeffs:r.float64_coeffs,fit_center_naif_id:r.fit_center_naif_id,present:r.present});return t}async function Fb(e,t){let n=new TextEncoder().encode(e),r=crypto.subtle?await crypto.subtle.digest(`SHA-256`,n):mb(n).buffer;return new DataView(r).getUint32(0,!1)%t}async function Ib(e,t){let n=await J_(e,{priority:t});if(!n.ok)throw Error(`Failed to fetch ${e}: ${n.status}`);let r=new DecompressionStream(`gzip`);return new Response(n.body.pipeThrough(r)).arrayBuffer()}async function Lb(e,t,n,r){let i=ry(await Ib(nn(e,t,n),r));if(i.kind!==`chebyshev`)throw Error(`Expected chebyshev payload at ${e}/${n}, got ${i.kind}`);let a=new Map;for(let e of i.chunk.bodies)e.id&&a.set(e.id,e);return{...i.chunk,byId:a}}var Rb=1,zb=Promise.resolve();function Bb(e,t){return`${e}:${t}`}var Vb=class{chunks=new Map;inflight=new Map;lastEnsuredJd=NaN;_version=0;constructor(e){this.zoneParams=e}get version(){return this._version}zones(){return Array.from(this.zoneParams.keys())}ensure(e){if(e===this.lastEnsuredJd)return{ready:this.allCurrentChunksLoaded(e),done:this.pendingCurrent(e)};this.lastEnsuredJd=e;let t=[],n=[],r=!0;for(let[i,a]of this.zoneParams){let o=yb(a,e);if(this.isLoadable(a,o)&&!this.isResident(i,o)){r=!1;let e=this.loadChunk(i,a,o,`high`);e&&t.push(e)}for(let e=-Rb;e<=Rb;e++){let t=o+e;e===0||t<0||t>=a.chunks||this.isLoadable(a,t)&&n.push([i,a,t])}this.evictOutsideWindow(i,o)}let i=t.length>0?Promise.all(t).then(()=>void 0):zb;return i.catch(()=>{}).then(()=>{for(let[e,t,r]of n)this.loadChunk(e,t,r,`low`)?.catch(()=>{})}),{ready:r,done:i}}request(e){for(let[t,n]of this.zoneParams){let r=yb(n,e);this.isLoadable(n,r)&&this.loadChunk(t,n,r,`high`)?.catch(()=>{})}}loadingAt(e,t){if(this.inflight.size===0)return!1;for(let[n,r]of this.zoneParams)if(!(t!==void 0&&n!==t)&&this.inflight.has(Bb(n,yb(r,e))))return!0;return!1}pendingCurrent(e){if(this.inflight.size===0)return zb;let t=null;for(let[n,r]of this.zoneParams){let i=this.inflight.get(Bb(n,yb(r,e)));i&&(t??=[]).push(i)}return t?Promise.all(t).then(()=>void 0):zb}allCurrentChunksLoaded(e){for(let[t,n]of this.zoneParams){let r=yb(n,e);if(this.isLoadable(n,r)&&!this.isResident(t,r))return!1}return!0}isResident(e,t){return this.chunks.get(e)?.has(t)??!1}evictOutsideWindow(e,t){let n=this.chunks.get(e);if(n)for(let e of n.keys())(e<t-Rb||e>t+Rb)&&n.delete(e)}loadChunk(e,t,n,r){if(this.isResident(e,n))return null;let i=Bb(e,n),a=this.inflight.get(i);if(a)return a;let o=this.fetchAndStore(e,t,n,r);return this.inflight.set(i,o),o.finally(()=>this.inflight.delete(i)),o}async fetchAndStore(e,t,n,r){let i=await this.fetchChunk(e,t,n,r),a=this.chunks.get(e);a||this.chunks.set(e,a=new Map),a.set(n,i),this._version++,this.afterStore(e,i)}},Hb=class extends Vb{idToZone=new Map;isLoadable(){return!0}fetchChunk(e,t,n,r){return Lb(e,t.zoom,n,r)}afterStore(e,t){for(let n of t.byId.keys())this.idToZone.has(n)||this.idToZone.set(n,e)}has(e){return this.idToZone.has(e)}zoneCoverage(e){let t=this.idToZone.get(e);if(t===void 0)return null;let n=this.zoneParams.get(t);return n?{start:n.start_jd,end:n.end_jd}:null}isLoading(e,t){let n=this.idToZone.get(e);return n!==void 0&&this.loadingAt(t,n)}resolve(e,t){let n=this.idToZone.get(e);if(n===void 0)return null;let r=this.zoneParams.get(n);if(!r)return null;let i=yb(r,t),a=this.chunks.get(n)?.get(i);if(!a)return null;let o=a.byId.get(e);return o?{zone:n,chunkIdx:i,body:o}:null}body(e,t){return this.resolve(e,t)?.body??null}*bodiesAt(e){for(let[t,n]of this.zoneParams){let r=yb(n,e),i=this.chunks.get(t)?.get(r);if(i)for(let e of i.bodies)yield{zone:t,body:e,startJd:i.startJd,endJd:i.endJd}}}positionScene(e,t){let n=this.resolve(e,t);return n?oy(n.body,t):null}};async function Ub(e,t,n,r){let i=nn(e,null,t),a=await J_(i,{priority:r});if(!a.ok)throw Error(`Failed to fetch ${i}: ${a.status}`);let o=new DecompressionStream(`gzip`),s=ry(await new Response(a.body.pipeThrough(o)).arrayBuffer(),{probesFloat64:n});if(s.kind!==`probes`)throw Error(`Expected probes payload at ${e}/${t}, got ${s.kind}`);return{...s.chunk,ids:s.chunk.probes.map(e=>e.id)}}var Wb=24;function Gb(e,t){for(let[n,r]of e){if(t<n)return!1;if(t<=r)return!0}return!1}var Kb=7,qb=class extends Vb{fitCenterUsable=null;warmed=new Map;carried=new Map;zoneCenter(e){return this.zoneParams.get(e)?.fit_center_naif_id}isLoadable(e,t){return Gb(e.present,t)}fetchChunk(e,t,n,r){return Ub(e,n,t.float64_coeffs,r)}afterStore(){}async warmAt(e){let t=[];for(let[n,r]of this.zoneParams){let i=yb(r,e);if(i<0||i>=r.chunks||!Gb(r.present,i)||this.isResident(n,i))continue;let a=Bb(n,i);if(this.warmed.has(a))continue;let o=this.inflight.get(a);if(o){t.push(o);continue}let s=this.fetchAndWarm(a,n,i,r);this.inflight.set(a,s),s.finally(()=>this.inflight.delete(a)),t.push(s)}await Promise.all(t)}async fetchAndWarm(e,t,n,r){let i=await Ub(t,n,r.float64_coeffs,`low`);for(this.warmed.set(e,i);this.warmed.size>Wb;){let e=this.warmed.keys().next().value;if(e===void 0)break;this.warmed.delete(e)}}fitCenterCovered(e){let t=e.fitCenter;return!t||!this.fitCenterUsable?!0:this.fitCenterUsable(t.id)}*probesAt(e,t){let n=new Map,r=new Set;for(let[i,a]of this.zoneParams){let o=yb(a,e),s=this.chunks.get(i)?.get(o)??this.warmed.get(Bb(i,o));if(!s)continue;let c=t?.(a.fit_center_naif_id)??!1;for(let e=0;e<s.probes.length;e++){let t=s.probes[e],o=t.id;if(!o||r.has(o)||!this.fitCenterCovered(t))continue;let l={zone:i,zoneCenterNaifId:a.fit_center_naif_id,id:o,probe:t,startJd:s.startJd,endJd:s.endJd};c?(n.set(o,l),r.add(o)):n.has(o)||n.set(o,l)}}yield*this.withPassengers(n,e).values()}withPassengers(e,t){if(this.carried.size===0)return e;let n=[];for(let[r,{carriedFrom:i}]of this.carried){if(t<i.start_jd||t>=i.end_jd||e.has(r))continue;let a=e.get(i.object_id);a&&n.push([r,a])}for(let[t,r]of n)e.set(t,{...r,id:t});return e}registerCarried(e){this.carried.set(e.id,e)}carrierAt(e,t){if(this.carried.size===0)return null;let n=this.carried.get(e)?.carriedFrom;return!n||t<n.start_jd||t>=n.end_jd+Kb?null:n.object_id}ridesAt(e){let t=[];for(let[n,r]of this.carried){let i=r.carriedFrom;if(e<i.start_jd||e>=i.end_jd+Kb)continue;let a=e<i.end_jd;!a&&this.resolveOwn(n,e)||t.push({passengerId:n,carrierId:i.object_id,carrierName:r.carrierName,attached:a})}return t}resolve(e,t,n){let r=this.resolveOwn(e,t,n);if(r)return r;let i=this.carrierAt(e,t);return i?this.resolveOwn(i,t,n):null}resolveOwn(e,t,n){let r=Ig(t),i=null;for(let[a,o]of this.zoneParams){let s=yb(o,t),c=this.chunks.get(a)?.get(s)??this.warmed.get(Bb(a,s));if(c)for(let t of Zb(c,e)){let e=c.probes[t];if(!this.fitCenterCovered(e))break;let s=py(e,r)>=0,l=e.landed,u=l!==void 0&&r>=l.startEt&&r<l.endEt;if(!s&&!u)continue;let d={zone:a,probe:e,params:o};if(n?.(o.fit_center_naif_id))return d;i??=d;break}}return i}stampedFitCenterAt(e,t){let n=this.stampedFitCenterAtOwn(e,t);if(n!==null)return n;let r=this.carrierAt(e,t);return r?this.stampedFitCenterAtOwn(r,t):null}stampedFitCenterAtOwn(e,t){let n=Ig(t);for(let[r,i]of this.zoneParams){let a=yb(i,t),o=this.chunks.get(r)?.get(a)??this.warmed.get(Bb(r,a));if(o)for(let t of Zb(o,e)){let e=o.probes[t];if(py(e,n)<0)break;return e.fitCenter?.id??null}}return null}probe(e,t,n){return this.resolve(e,t,n)?.probe??null}probeWithCenter(e,t,n){let r=this.resolve(e,t,n);return r?{probe:r.probe,fitCenterNaifId:r.params.fit_center_naif_id}:null}positionKm(e,t,n,r){let i=this.resolve(e,t,r);return i?by(i.probe,t,n):null}positionScene(e,t,n,r){let i=this.resolve(e,t,r);return i?xy(i.probe,t,n):null}containingSystemAt(e,t){let n=this.containingSystemAtOwn(e,t);if(n!==null)return n;let r=this.carrierAt(e,t);return r?this.containingSystemAtOwn(r,t):null}containingSystemAtOwn(e,t){let n=Ig(t),r=this.zoneParams.get(Jb);if(r){let i=yb(r,t),a=this.chunks.get(Jb)?.get(i);if(a)for(let t of Zb(a,e)){let e=a.probes[t];for(let t of e.systemIntervals)if(n>=t.startEt&&n<t.endEt)return t.systemNaifId;return null}}for(let[n,r]of this.zoneParams){if(n===Jb||r.fit_center_naif_id===10)continue;let i=yb(r,t),a=this.chunks.get(n)?.get(i);if(a)for(let t of Zb(a,e))return Math.floor(r.fit_center_naif_id/100)}return null}hasHeliocentricFit(e,t){if(this.hasHeliocentricFitOwn(e,t))return!0;let n=this.carrierAt(e,t);return n!==null&&this.hasHeliocentricFitOwn(n,t)}hasHeliocentricFitOwn(e,t){let n=this.zoneParams.get(Jb);if(!n)return!1;let r=yb(n,t),i=this.chunks.get(Jb)?.get(r);if(!i)return!1;let a=Ig(t);for(let t of Zb(i,e))if(py(i.probes[t],a)>=0)return!0;return!1}},Jb=`probes/interplanetary`,Yb=[],Xb=new WeakMap;function Zb(e,t){let n=Xb.get(e);if(!n){n=new Map;for(let t=0;t<e.ids.length;t++){let r=n.get(e.ids[t]);r?r.push(t):n.set(e.ids[t],[t])}Xb.set(e,n)}return n.get(t)??Yb}async function Qb(e){let t=new DecompressionStream(`gzip`);return await new Response(e.body.pipeThrough(t)).json()}function $b(e,t={}){let{onMissing:n,fetcher:r=e=>fetch(e),error:i=(e,t)=>`memoizedGzJson: ${t} returned ${e.status} ${e.statusText}`}=t,a=null;return()=>{if(a)return a;let t=(async()=>{let t=await e(),a=await r(t);if(!a.ok){if(a.status===404&&n)return n();throw Error(i(a,t))}return Qb(a)})();return a=t,t.catch(()=>{a===t&&(a=null)}),t}}var ex=24,tx=new Map;function nx(e,t){let n=tx.get(e);if(n&&(tx.delete(e),tx.set(e,n)),!n){n=(async()=>{let n=await J_(e,t);if(!n.ok){if(n.status===404)return{};throw Error(`fetchGzipBundle: ${e} returned ${n.status} ${n.statusText}`)}return Qb(n)})(),tx.set(e,n),n.catch(()=>{tx.get(e)===n&&tx.delete(e)});for(let e of tx.keys()){if(tx.size<=ex)break;tx.delete(e)}}return n}var rx={counts:`object_bundles`,globalPath:e=>`/v1/objects/__global__/${e}.json.gz`,localizedPath:(e,t)=>`/v1/objects/${e}/${t}.json.gz`,versionClass:`objects`},ix={counts:`group_bundles`,globalPath:e=>`/v1/groups/__global__/${e}.json.gz`,localizedPath:(e,t)=>`/v1/groups/${e}/${t}.json.gz`},ax=(e,t)=>nx(t?Yt(e,t):`${Wt()}${e}`);async function ox(e,t,{meta:n,lang:r,fetchBundle:i,localized:a=!0}){let o=n[e.counts],s=o?.global??0,c=a?o?.[r]??0:0,[l,u]=await Promise.all([s?Fb(t,s):-1,c?Fb(t,c):-1]),[d,f]=await Promise.all([l>=0?i(e.globalPath(l),e.versionClass):null,u>=0?i(e.localizedPath(r,u),e.versionClass):null]);return{global:d?.[t]??null,localized:f?.[t]??null}}async function sx(e,t,n,r=!0){return ox(e,t,{meta:await Mb(),lang:n,localized:r,fetchBundle:ax})}function cx(e){return e.imagery!==`withheld`&&a(e.distribution)}function lx(e,t=!0,n=s()){return sx(rx,e,n,t)}async function ux(e){if(e?.startsWith(`probe-`))try{let t=(await lx(e,!1)).global,n=t?.coverage?.position_from;return n?{id:e,carriedFrom:n,carrierName:t?.carried_by?.name}:void 0}catch{return}}function dx(e,t,n){let r=new Set,i=new Map;for(let a of e){let e=t===a.passengerId;if(r.add(e?a.carrierId:a.passengerId),!e||!a.attached)continue;let o=n(a.carrierId)??a.carrierName;o&&i.set(a.passengerId,o)}return{hidden:r,credits:i}}var fx=1/1440;function px(e){return(e?.coverage?.windows.length??0)>0}async function mx(){let e=(await Mb()).position.zones.earth,t=e&&Sb(e).find(e=>gb(e.data))?.data;return t&&gb(t)?Ng(Ob(t)):1/0}async function hx(e){let t=(await lx(e,!1)).global?.coverage?.windows??[],n=e.startsWith(`norad_satcat-`)?await mx():1/0;return t.map(([e,t])=>[e??-1/0,t??n]).filter(([e,t])=>t>e)}function gx(e,t){let n=null;for(let[r,i]of e){if(t>r&&t<i)return t;let e=Math.min(fx,(i-r)/2),a=t<=r?r+e:i-e;(n===null||Math.abs(a-t)<Math.abs(n-t))&&(n=a)}return n}function _x(e){return G[e.toUpperCase()]??G.UNDOCUMENTED}var vx={horizons:W.HORIZONS,sbdb:W.SBDB,celestrak:W.CELESTRAK,spacetrack:W.SPACETRACK,spice:W.SPICE,sbdb_moons:W.SBDB_MOON,astersat:W.ASTERSAT};function yx(e){return e?vx[e]??W.UNKNOWN:W.UNKNOWN}var bx=14;function xx(e,t){let n=t.global,r=n?.orbit;if(!n||!r||!px(n))return null;let i=r.q!=null&&r.tp!=null;if(!i&&(r.epoch_jd==null||r.a==null||r.ma==null||r.n==null))return null;let a=r.scale===`planet`,o=n.cross_refs?.norad_cat_id,s=a&&r.bstar!=null&&r.mean_motion_dot!=null&&r.mean_motion_ddot!=null&&r.n!=null&&o!=null?{noradCatId:o,epochJd:r.epoch_jd,meanMotion:r.n,eccentricity:r.e,inclination:r.i,raOfAscNode:r.om,argOfPericenter:r.w,meanAnomaly:r.ma??0,bstar:r.bstar,meanMotionDot:r.mean_motion_dot,meanMotionDdot:r.mean_motion_ddot,elementSetNo:r.element_set_no??0,revAtEpoch:r.rev_at_epoch??0}:void 0,c=s?vg(s,n.name??void 0)??void 0:void 0,l=n.coverage?.windows[0]?.[0];return{id:e,name:t.localized?.name??n.name??n.sbdb_primary_designation??n.provisional_designation??null,objectType:_x(n.type),parentId:r.parent_id,radiusKm:n.sbdb?.diameter?n.sbdb.diameter/2:NaN,hasLocalized:t.localized!=null,a:a?(r.a??0)/ag:r.a??0,e:r.e,i:r.i,om:r.om,w:r.w,ma:r.ma??0,n:a?(r.n??0)*360:r.n??0,epoch:r.epoch_jd,equatorial:a,validityStart:s?r.epoch_jd-bx:-1/0,validityEnd:s?r.epoch_jd+bx:1/0,orbitalSource:yx(r.source),...l==null?{}:{visibleFromDays:l-kg},...i?{q:r.q,tp:r.tp}:{},...s?{omm:s}:{},...c?{satrec:c}:{}}}function Sx(e,t){let n=t.global;return n?{id:e,name:t.localized?.name??n.name??n.sbdb_primary_designation??n.provisional_designation??null,objectType:_x(n.type),parentId:n.host_id??``,radiusKm:n.sbdb?.diameter?n.sbdb.diameter/2:NaN,hasLocalized:t.localized!=null,pageOnly:!0,a:NaN,e:NaN,i:NaN,om:NaN,w:NaN,ma:NaN,n:NaN,epoch:NaN,validityStart:-1/0,validityEnd:1/0,orbitalSource:W.UNKNOWN}:null}async function Cx(e,t,n=new Set){if(n.has(e))return console.warn(`createPlaceholderBody: cycle detected at ${e} — hiding`),[];n.add(e);let r;try{r=await lx(e)}catch{return console.warn(`createPlaceholderBody: failed to fetch global data for ${e} — hiding`),[]}let i=r.global;if(!i)return console.warn(`createPlaceholderBody: no catalogue record for ${e} — hiding`),[];let a=i.sbdb?.class??null,o=xx(e,r)??Sx(e,r);if(!o)return[];let s=o.parentId,c=s===``||s===`naif-0`||t.getBody(s)?[]:await Cx(s,t,n),l=o.pageOnly?{data:o,position:null}:{data:o,position:null,orbitElements:o,orbitCenterId:s};return[...c,{body:l,zone:a}]}function wx(e,t,n){let r=0;for(let i=0;i<t.length;i++){let{body:a,zone:o}=t[i];if(e.getBody(a.data.id))continue;let s=a.data.objectType,c=s===G.SPACECRAFT||s===G.DEBRIS,l=i>0?t[i-1]:null,u=s===G.MOON&&l&&_n(l.body.data.objectType)?`small_body_moons`:o;c&&a.data.parentId!==``?(e.bodies.putSpacecraft(a)&&r++,e.bodies.dirtySpacecraftGroups.add(a.data.parentId)):u&&!a.data.pageOnly?(e.bodies.asteroidBucket(u,n).addPlaceholder(a),e.bodies.dirtyAsteroidZones.add(u),r++):e.bodies.addBodies([a]),e.credits.recordOrbitSources([a])}return r}async function Tx(e,t){if(e.getBody(t))return;let n=await Cx(t,e);if(n.length===0)return;let r=wx(e,n,await Uv());e.bodies.flushMinor(r>0)}var Ex=`spacemap.atmosphere-calibration`;function Dx(){try{let e=localStorage.getItem(Ex);return e?JSON.parse(e):null}catch{return null}}function Ox(e){try{e?localStorage.setItem(Ex,JSON.stringify(e)):localStorage.removeItem(Ex)}catch{}}function kx(){return Ze({resolvedReducedMotion:typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches,viewMode:`map`,showClouds:!0,showAtmospheres:!0,atmosphereQuality:`auto`,atmosphereAutoTier:null,atmosphereCalibration:Dx(),atmoQualityOverrides:{},highAmbient:!1,realisticLighting:!1,overexposeRings:!1,showShapeMesh:!0,showSurfaceTexture:!0,showDisplacement:!0,showSelfShadow:!0,showHaloDebug:!1,maxPartsPerZone:0,setAtmosphereCalibration(e){this.atmosphereCalibration=e,Ox(e)},setAtmosphereAutoTier(e){this.atmosphereAutoTier=e}})}var Ax=null;function jx(){return Ax??=kx()}function Mx(e){Ax=e}var Nx=2e3,Px=3,Fx=class{zones=[];latestDate;failureStreak=0;staleNotified=!1;constructor(e,t,n,r){this.ctx=e,this.loader=n,this.latestDate=r;let i=Pg(r),a=jx().maxPartsPerZone;for(let[n,o]of Object.entries(t.position.zones)){if(e.layers.skipsZone(n))continue;let t=o.parent_id_type??`naif`;for(let{zoom:e,data:s}of Sb(o)){if(s.shape===`chunked`||s.shape===`parted`)continue;let o=a>0?Math.min(s.parts,a):s.parts;if(gb(s)){let i={kind:`time`,zone:n,zoom:e,parts:o,parentIdType:t,zoomData:s,currentTime:``,inFlight:null,lastLoadStartMs:-1/0,cap:a};this.zones.push(i),this.prefetchTimeNeighbors(i,r)}else if(_b(s)){let r={kind:`chunk`,zone:n,zoom:e,parts:o,parentIdType:t,zoomData:s,currentIdx:yb(s,i),inFlight:null,preloads:new Map};this.zones.push(r),this.preloadChunkNeighbors(r)}}}}recordSuccess(){this.failureStreak=0}recordFailure(){this.failureStreak++,this.failureStreak>=Px&&!this.staleNotified&&(this.staleNotified=!0,this.ctx.onDataStale?.())}invalidateZone(e){for(let t of this.zones)t.zone!==e||t.kind!==`time`||(t.currentTime=``,t.lastLoadStartMs=-1/0);this.tick(this.latestDate)}satelliteCoverage(e){let t=this.zones.find(e=>e.kind===`time`&&e.zone===`earth`);return t?kb(t.zoomData,Fg(e)):{kind:`covered`}}tick(e){this.latestDate=e;let t=Pg(e);for(let n of this.zones)if(n.kind===`time`){if(n.inFlight)continue;let t=Eb(n.zoomData,e);if(t===n.currentTime)continue;let r=performance.now();if(r-n.lastLoadStartMs<Nx)continue;n.lastLoadStartMs=r,n.inFlight=this.loadTime(n,t,e).finally(()=>{n.inFlight=null})}else{for(;;){let e=yb(n.zoomData,t);if(e===n.currentIdx)break;let r=n.preloads.get(e);if(r?.kind!==`ready`)break;let i=n.currentIdx;n.currentIdx=e,this.applyChunkSwap(n,i,e,r.bodies),this.preloadChunkNeighbors(n)}if(n.inFlight)continue;let e=yb(n.zoomData,t);if(e===n.currentIdx)continue;n.inFlight=this.loadChunk(n,e).finally(()=>{n.inFlight=null})}}async ready(e=this.latestDate){this.latestDate=e;let t=Pg(e),n=this.zones.map(n=>this.zoneReady(n,e,t));this.ctx.chebStore&&n.push(this.ctx.chebStore.ensure(t).done),this.ctx.probeStore&&n.push(this.ctx.probeStore.ensure(t).done),await Promise.all(n)}async zoneReady(e,t,n){for(;e.inFlight;)await e.inFlight;if(e.kind===`time`){let n=Eb(e.zoomData,t);if(n===e.currentTime)return;e.lastLoadStartMs=performance.now(),e.inFlight=this.loadTime(e,n,t).finally(()=>{e.inFlight=null})}else{let t=yb(e.zoomData,n);if(t===e.currentIdx)return;e.inFlight=this.loadChunk(e,t).finally(()=>{e.inFlight=null})}await e.inFlight}wanted=new Set;want(e){this.wanted.add(e)}async ensureBody(e,t){e.startsWith(`probe-`)&&await this.ensureProbe(e,t),!this.ctx.getBody(e)&&(e.startsWith(`norad_satcat-`)&&!this.wanted.has(e)&&(this.want(e),(this.ctx.earthSatFilter||this.ctx.earthTypeFilter)&&(this.invalidateZone(`earth`),await this.ready(t),this.ctx.getBody(e)))||await Tx(this.ctx,e))}async ensureProbe(e,t){let n=this.ctx.probeStore;if(!n)return;let r=Pg(t),i=ux(e);await n.ensure(r).done;let a=await i;a&&n.registerCarried(a);let o=n.stampedFitCenterAt(e,r);if(o&&await Tx(this.ctx,o),this.ctx.getBody(e))return;let s=await Uv(),c=this.loader.processProbes(n,t,s).find(t=>t.data.id===e);c&&(this.ctx.bodies.addBodies([c]),this.ctx.credits.recordOrbitSources([c]))}async loadTime(e,t,n){let r=e.currentTime;try{let i=Ab(e.zoomData,t,e.cap),a=await Promise.all(Array.from({length:i},(n,r)=>this.loader.process(e.zone,e.zoom,r,t,e.parentIdType))),o=e.zone===`earth`,s=o?this.ctx.earthSatFilter:null,c=o?this.ctx.earthTypeFilter:null,l=0,u=new Map;for(let t of a){this.ctx.credits.recordOrbitSources(t);for(let n of t){let t=n.data.objectType;if(t!==G.SPACECRAFT&&t!==G.DEBRIS){console.warn(`zone-refresher: unexpected non-spacecraft body in ${e.zone}: ${n.data.id} (type=${t})`);continue}if(!this.wanted.has(n.data.id)){if(s&&!s.has(n.data.id)){l++;continue}if(c&&!c.has(t)){l++;continue}}let r=n.data.parentId,i=u.get(r);i||u.set(r,i=new Map),i.set(n.data.id,n)}}l>0&&console.log(`zone-refresher: ${e.zone}@${t}: filtered out ${l} non-member bodies`);let d=0,f=0,p=0;for(let[e,t]of u){let n=this.ctx.bodies.spacecraftBucket(e);for(let e of n.keys())t.has(e)||this.ctx.hasMeshBody?.(e)||this.wanted.has(e)||(n.delete(e),p++);for(let e of t.values())this.ctx.bodies.putSpacecraft(e)?d++:f++;this.ctx.bodies.dirtySpacecraftGroups.add(e)}e.currentTime=t,this.ctx.bodies.minorBodyVersion++,d>0&&this.ctx.bodies.notifyBodiesAdded(),e.zone===`earth`&&this.ctx.notifyEarthSatRollover(),console.log(`zone-refresher: ${e.zone}@${r} → ${t} (+${d} ~${f} -${p})`),this.prefetchTimeNeighbors(e,n),this.recordSuccess()}catch(n){console.warn(`zone-refresher: failed to refresh ${e.zone}@${t}:`,n),this.recordFailure()}}async loadChunk(e,t){let n=e.currentIdx;e.currentIdx=t;try{let r=e.preloads.get(t),i;i=r?.kind===`pending`?await r.promise:await Promise.all(Array.from({length:e.parts},(n,r)=>this.loader.process(e.zone,e.zoom,r,String(t),e.parentIdType))),this.applyChunkSwap(e,n,t,i),this.preloadChunkNeighbors(e),this.recordSuccess()}catch(r){console.warn(`zone-refresher: ${e.zone} chunk reload failed (${n} → ${t}):`,r),e.currentIdx=n,this.recordFailure()}}applyChunkSwap(e,t,n,r){let i=0,a=0;for(let e of r){this.ctx.credits.recordOrbitSources(e);for(let t of e){let e=!this.ctx.bodies.bodiesById.has(t.data.id);this.ctx.bodies.addBodies([t]),e?(this.ctx.bodies.majorBodies.push(t),a++):i++}}this.ctx.bodies.minorBodyVersion++,console.log(`zone-refresher: ${e.zone} chunk ${t} → ${n} (+${a} ~${i})`)}preloadChunkNeighbors(e){let t=Math.max(0,e.currentIdx-1),n=Math.min(e.zoomData.chunks-1,e.currentIdx+1);for(let r=t;r<=n;r++){if(e.preloads.has(r))continue;let t=String(r),n=Promise.all(Array.from({length:e.parts},(n,r)=>this.loader.process(e.zone,e.zoom,r,t,e.parentIdType)));e.preloads.set(r,{kind:`pending`,promise:n}),n.then(t=>{e.preloads.get(r)?.kind===`pending`&&e.preloads.set(r,{kind:`ready`,bodies:t})},t=>{console.warn(`zone-refresher: ${e.zone} chunk ${r} preload failed:`,t),e.preloads.get(r)?.kind===`pending`&&e.preloads.delete(r)})}for(let r of e.preloads.keys())(r<t||r>n)&&e.preloads.delete(r)}prefetchTimeNeighbors(e,t){let n=864e5,r=Eb(e.zoomData,new Date(t.getTime()-n)),i=Eb(e.zoomData,new Date(t.getTime()+n));for(let t of new Set([r,i])){if(t===e.currentTime)continue;let n=Ab(e.zoomData,t,e.cap);for(let r=0;r<n;r++)rb.prefetch(e.zone,e.zoom,r,t)}}},Ix,Lx=new Promise(e=>{Ix=e});function Rx(){Ix()}var zx=4;function Bx(){return typeof navigator>`u`?!1:navigator.connection?.saveData===!0}function Vx(){if(typeof navigator>`u`)return!1;if(Bx())return!0;let e=navigator.deviceMemory;return typeof e==`number`&&e>0&&e<=zx}var Hx;function Ux(){return Hx===void 0&&(Hx=typeof window<`u`&&!!window.matchMedia?.(`(pointer: coarse)`).matches),Hx}function Wx(){return typeof window>`u`?1:Math.min(window.devicePixelRatio,2)}var Gx={low:{maxPixelRatio:1.25,shadowMapSize:1024,softShadows:!1,bloomScale:.5,pointBudget:4e5,maxTextureTier:`medium`,tileWindows:3,maxSkyboxFace:2048},medium:{maxPixelRatio:1.5,shadowMapSize:2048,softShadows:!0,bloomScale:.75,pointBudget:9e5,maxTextureTier:`medium`,tileWindows:4,maxSkyboxFace:2048},high:{maxPixelRatio:2,shadowMapSize:4096,softShadows:!0,bloomScale:1,pointBudget:1/0,maxTextureTier:`high`,tileWindows:6,maxSkyboxFace:1/0}};function Kx(){return Vx()?`low`:Yx().maxTextureTier}function qx(){return Vx()?0:Yx().tileWindows}function Jx(){let e=jx().atmosphereCalibration?.tier;return e===`low`||e===`medium`?e:e===`high`||e===`ultra`?`high`:Ux()?Vx()?`low`:`medium`:Vx()?`medium`:`high`}function Yx(){return Gx[Jx()]}function Xx(){return typeof window>`u`?1:Math.min(window.devicePixelRatio,Yx().maxPixelRatio)}var Zx=Math.PI/180*og,Qx=new Ui().setFromAxisAngle(new J(0,0,1),-Math.PI/2).premultiply(new Ui().setFromAxisAngle(new J(0,1,0),Math.PI/2-Zx)).premultiply(new Ui().setFromAxisAngle(new J(1,0,0),-Math.PI/2)),$x=[`px`,`nx`,`py`,`ny`,`pz`,`nz`];function eS(e,t){if(e.tiers.length===0)return null;let n=[...e.tiers].sort((t,n)=>(e.tier_face_size[n]??0)-(e.tier_face_size[t]??0));for(let r of n)if((e.tier_face_size[r]??1/0)<=t)return r;return n[n.length-1]}function tS(e,t,n){return Yt(`/v1/textures/${e}/${t}_${n}.webp`,`textures`)}async function nS(e,t,n){return Promise.all($x.map(async r=>{let i=await fetch(tS(e,t,r),{priority:n});if(!i.ok)throw Error(`Skybox face fetch failed (${i.status}): ${t}_${r}`);let a=await i.blob();return createImageBitmap(a,{imageOrientation:`none`,premultiplyAlpha:`none`})}))}var rS=new Map,iS=new Map;function aS(e,t){return`${e}:${t}`}function oS(e,t,n,r=!0){let i=aS(e,t),a=rS.get(i);if(!a){let r=nS(e,t,n);a=r,rS.set(i,a),r.catch(()=>{rS.get(i)===r&&(rS.delete(i),iS.delete(i))})}return r&&iS.set(i,(iS.get(i)??0)+1),a}function sS(e,t,n){let r=aS(e,t),i=(iS.get(r)??1)-1;if(i>0){iS.set(r,i);return}iS.delete(r),rS.delete(r);for(let e of n)e.close()}function cS(e){let t=new Nc(e);return t.colorSpace=Xr,t.needsUpdate=!0,t}function lS(e){return e.tiers.length===0?null:[...e.tiers].sort((t,n)=>(e.tier_face_size[t]??0)-(e.tier_face_size[n]??0))[0]}function uS(e){let t=lS(e);t&&oS(e.id,t,void 0,!1).catch(()=>{})}var dS=12e3;async function fS(e,t,n,r){let i=eS(n,Math.min(t.capabilities.maxTextureSize,Yx().maxSkyboxFace));if(!i){console.warn(`Skybox ${n.id}: no tiers declared`);return}let a=lS(n),o={cube:null,bitmaps:null},s=!1;a&&a!==i&&oS(n.id,a).then(t=>{if(s||r()){sS(n.id,a,t);return}o.cube=cS(t),o.bitmaps=t,e.background=o.cube,performance.mark(`sm-skybox-low`),c&&l()}).catch(()=>{});let c=!1,l=()=>{!a||!o.cube||!o.bitmaps||(t.initTexture(o.cube),sS(n.id,a,o.bitmaps),o.bitmaps=null)};i!==a&&await Promise.race([Lx,new Promise(e=>setTimeout(e,dS))]);let u;try{u=await oS(n.id,i,i===a?void 0:`low`)}catch(e){throw c=!0,r()?a&&o.bitmaps&&(o.cube?.dispose(),sS(n.id,a,o.bitmaps),o.bitmaps=null):l(),e}if(await new Promise(e=>`requestIdleCallback`in window?requestIdleCallback(()=>e(),{timeout:2e3}):setTimeout(e,500)),r()){s=!0,o.cube?.dispose(),sS(n.id,i,u),a&&a!==i&&o.bitmaps&&sS(n.id,a,o.bitmaps);return}let d=cS(u);t.initTexture(d),s=!0;let f=e.background;e.background=d,performance.mark(`sm-skybox-high`),o.cube?.dispose(),f&&f!==o.cube&&f instanceof Nc&&f.dispose(),sS(n.id,i,u),a&&a!==i&&o.bitmaps&&sS(n.id,a,o.bitmaps)}async function pS(e,t,n,r=()=>!1){if(!n?.layers.skipped.has(`stars`))try{let i=await Mb();if(!i.skybox)return;n&&(n.credits.skybox={source:i.skybox.source,organisation:i.skybox.organisation,license:i.skybox.license,attribution:i.skybox.attribution,description:i.skybox.description}),await fS(e,t,i.skybox,r)}catch(e){console.warn(`Failed to load skybox:`,e)}}var mS=13;function hS(e,t,n){let r=jx().maxPartsPerZone,i=[],a=[];for(let[o,s]of Object.entries(e.position.zones)){if(o===`major`||o===`moons`||o===`spacecraft`||bb(s)||n.skipsZone(o))continue;let e=s.parent_id_type??`naif`;for(let{zoom:n,data:c}of Sb(s)){if(c.shape===`chunked`)continue;let s=gb(c)?Eb(c,t):null,l=gb(c)&&s!==null?Ab(c,s,r):r>0?Math.min(c.parts,r):c.parts;for(let t=0;t<l;t++){let r={zone:o,zoom:n,part:t,time:s,parentIdType:e};n!==null&&n>=1&&t>=mS?a.push(r):i.push(r)}}}return{eager:i,deferred:a}}async function gS(e,t,n){let r=Pb(e);for(let e of r.keys())n.skipsZone(e)&&r.delete(e);if(r.size===0)return null;console.log(`ProbeStore: ${r.size} zone(s) from metadata:\n`+Array.from(r).map(([e,t])=>` ${e}: chunks=${t.chunks} chunk_days=${t.chunk_days} fit_center=naif-${t.fit_center_naif_id} float64=${t.float64_coeffs}`).join(`
4052
+ `));let i=Array.from(r).filter(([,e])=>e.fit_center_naif_id===void 0);i.length>0&&console.warn(`ProbeStore: ${i.length} zone(s) missing fit_center_naif_id in metadata — re-export to refresh: ${i.map(([e])=>e).join(`, `)}`);let a=new qb(r);return await a.ensure(t).done,a}async function _S(e,t,n,r,i,a){let o=[],s=null;e.chebStore&&(s=await Uv(),o.push(...t.processChebyshev(r,s))),e.probeStore&&(s??=await Uv(),a&&e.probeStore.registerCarried(a),o.push(...t.processProbes(e.probeStore,r,s)));let c=n.position.zones.major;if(c&&xb(c))for(let e of[1,2]){let n=c.zooms[String(e)];if(n&&hb(n))for(let r=0;r<n.parts;r++)o.push(...await t.process(`major`,e,r))}let l=e.layers.skipsZone(`moons`)?void 0:n.position.zones.moons,u=l?Cb(l):void 0,d=u&&_b(u)?String(yb(u,i)):null;return u&&o.push(...await t.process(`moons`,null,0,d)),vS(o)}function vS(e){let t=new Map,n=[];for(let r of e){let e=r.data.id;t.has(e)?n.push(e):t.set(e,r)}return n.length>0&&console.warn(`majors: ${n.length} duplicate id(s) in phase 1, kept first:`,n),[...t.values()]}async function yS(e,t,n){performance.mark(`sm-load-start`),G_.reset();let r=Q_().catch(e=>console.warn(`scene-load: systems-global (GMs/nutation) failed to load:`,e)),i=lb().catch(e=>console.warn(`scene-load: atmospheres failed to load — rendering without shells:`,e)),a=Pg(t),o=Mb();Uv().catch(()=>{}),o.then(t=>{let n=t.position.zones.moons;if(!n||e.layers.skipsZone(`moons`))return;let r=Cb(n);r&&hb(r)&&rb.prefetch(`moons`,null,0,null)}),o.then(t=>{t.skybox&&!e.layers.skipped.has(`stars`)&&uS(t.skybox)});let s=o.then(n=>hS(n,t,e.layers)),c=o.then(async t=>{let n=Nb(t);for(let t of n.keys())e.layers.skipsZone(t)&&n.delete(t);if(n.size===0)return null;let r=new Hb(n);return await r.ensure(a).done,r}),l=o.then(t=>gS(t,a,e.layers)),u=ux(n),d=await o;G_.reach(`metadata`),e.chebStore=await c,e.probeStore=await l,G_.reach(`ephemeris`);let f=new rb(e.chebStore);e.probeStore&&(e.probeStore.fitCenterUsable=t=>(e.chebStore?.has(t)??!1)||e.getBody(t)!==void 0),await r;let p=await _S(e,f,d,t,a,await u);G_.reach(`majors`),await i,e.bodies.addBodies(p),e.credits.recordOrbitSources(p);let m=await Uv();G_.reach(`labels`);let h=!1,g=()=>{h=!0},_=()=>{let t=h;h=!1,e.bodies.flushMinor(t)};if(n&&!e.getBody(n)){let t=await Cx(n,e);wx(e,t,m)>0&&g(),t.length>0&&_()}e.bodies.majorBodies=p.filter(e=>e.data.objectType!==G.BARYCENTER&&e.data.objectType!==G.LAGRANGE_POINT&&e.data.orbitalSource!==W.SPICE_PROBE);try{e.refresher=new Fx(e,d,f,t),n&&e.refresher.want(n)}catch(e){console.error(`scene-load: ZoneRefresher init failed; time-segmented zones stay empty:`,e)}G_.reach(`done`),e.loading=!1,performance.mark(`sm-majors-done`);let{eager:v,deferred:y}=await s,b=v.filter(e=>e.zone===`small_body_moons`),x=v.filter(e=>e.zone!==`small_body_moons`);e.bodies.minorStreaming=!0;let S=setInterval(_,500),C=async(t,n,r)=>{e.credits.recordOrbitSource(n.source),n.rowCount!==0&&(await e.bodies.asteroidBucket(t,m).addChunk(n,r)>0&&g(),e.bodies.dirtyAsteroidZones.add(t))},w=(t,n)=>{e.credits.recordOrbitSources(n);let r=e.bodies.asteroidBucket(t,m);for(let e of n)r.addPlaceholder(e),g();e.bodies.dirtyAsteroidZones.add(t)},T=x.filter(e=>e.zone.startsWith(`small_bodies/`)),E=(e,t)=>n=>{console.warn(`scene-load: ${e} part ${t} failed (skipped):`,n)};try{await Promise.all([...T.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.fetchMinorColumns(e,t,n,r).then(t=>C(e,t,i)).catch(E(e,n))),e.refresher?.ready().then(()=>{g()})]),await Promise.all(b.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.process(e,t,n,r,i).then(t=>w(e,t)).catch(E(e,n))))}finally{clearInterval(S),e.bodies.minorStreaming=!1,_(),performance.mark(`sm-minors-done`),Rx()}if(y.length>0&&Vx())console.info(`Low-end device: skipping ${y.length} deferred minor-belt parts to conserve memory`);else if(y.length>0){e.bodies.minorStreaming=!0;let t=setInterval(_,1e3);try{await Promise.all(y.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.fetchMinorColumns(e,t,n,r,`low`).then(t=>C(e,t,i)).catch(E(e,n))))}finally{clearInterval(t),e.bodies.minorStreaming=!1,_(),performance.mark(`sm-deferred-done`)}}}var bS=$b(async()=>(await Mb(),Yt(`/v1/membership/earth.json.gz`,`membership`)),{onMissing:()=>({}),error:e=>`fetchEarthMembership: ${e.status} ${e.statusText}`});async function xS(e){let t=await bS();return new Set(t[e]??[])}function SS(e,t=s()){return sx(ix,e,t)}var CS={[uv]:new Set([G.SPACECRAFT]),[dv]:new Set([G.DEBRIS])},wS=class{bodies=new R_;credits=new Cn;layers=new Tv;visibility=new zv(this.bodies,()=>this.probeStore,()=>this.earthSatFilter,()=>this.smallBodyFilter,()=>this.layers);#e=Ge(!0);get loading(){return Vt(this.#e)}set loading(e){Ke(this.#e,e,!0)}#t=Ge(null);get error(){return Vt(this.#t)}set error(e){Ke(this.#t,e,!0)}onDataStale=null;constructor(){}chebStore=null;probeStore=null;refresher=null;placer=null;hasMeshBody=null;earthSatFilter=null;earthSatFilterSlug=null;earthTypeFilter=null;smallBodyFilter=null;missionMemberIds=null;currentGroupSlug=null;groupFilterListeners=new Set;smallBodyFilterListeners=new Set;earthSatRolloverListeners=new Set;onGroupFilterChange(e){return this.groupFilterListeners.add(e),()=>this.groupFilterListeners.delete(e)}onSmallBodyFilterChange(e){return this.smallBodyFilterListeners.add(e),()=>this.smallBodyFilterListeners.delete(e)}onEarthSatRollover(e){return this.earthSatRolloverListeners.add(e),()=>this.earthSatRolloverListeners.delete(e)}notifyEarthSatRollover(){for(let e of this.earthSatRolloverListeners)e()}getBody(e,t){return this.bodies.getBody(e,t)}place(e,t){return this.placer?.place(e,t)??null}isMemberOfActiveGroup(e){if(this.missionMemberIds?.has(e)===!0||this.earthSatFilter?.has(e)===!0)return!0;let t=this.earthTypeFilter;if(t){let n=this.bodies.getBody(e)?.data.objectType;if(n!==void 0&&t.has(n))return!0}let n=this.smallBodyFilter;return n===null?!1:kv(this.bodies,e,n)}async load(e,t){try{await yS(this,e,t)}catch(e){throw this.loading=!1,this.error=e instanceof Error?e.message:String(e),console.error(`[scene-load]`,e),e}}refreshTick(e){this.refresher?.tick(e)}async ready(e){await this.refresher?.ready(e)}async ensureBody(e,t){await this.refresher?.ensureBody(e,t)}async applyGroupFilter(e){if(e===this.currentGroupSlug)return;if(this.currentGroupSlug=e,e?.startsWith(`mission-`)){let t=await SS(e);if(e!==this.currentGroupSlug)return;this.missionMemberIds=new Set((t.global?.notable_members??[]).map(e=>e.id).filter(e=>!!e))}else this.missionMemberIds=null;let t=e?await this.resolveIndexEntry(e):null;if(e!==this.currentGroupSlug)return;let n=this.resolveSmallBodyFilter(e,t?.applies_to,t?.n),r=t?.applies_to===`earth_sat`?e:null,i=CS[e??``]??null;if(!hv(this.smallBodyFilter,n)){this.smallBodyFilter=n;for(let e of this.smallBodyFilterListeners)e(n)}if(r===this.earthSatFilterSlug&&i===this.earthTypeFilter)return;let a=r?await xS(r):null;if(e===this.currentGroupSlug){this.earthSatFilter=a,this.earthSatFilterSlug=r,this.earthTypeFilter=i;for(let e of this.groupFilterListeners)e(a);this.loading||(this.bodies.spacecraftByParent.delete(m_),this.bodies.dirtySpacecraftGroups.add(m_),this.bodies.minorBodyVersion++,this.refresher?.invalidateZone(`earth`))}}resolveSmallBodyFilter(e,t,n){if(e===cv)return{kind:`category`,category:`asteroid`};if(e===lv)return{kind:`category`,category:`comet`};if(e===null||t!==`small_body`)return null;if(e.startsWith(`class-`))return{kind:`class`,className:e.slice(av.length)};if(e.startsWith(`flag-`)){let t=e.slice(ov.length),r=fv[t];return r===void 0?null:{kind:`flag`,flag:t,mask:r,n:n??0}}return null}async resolveIndexEntry(e){try{return(await _v())[e]??null}catch{return null}}},TS=400,ES=class{#e=Ge(0);get jd(){return Vt(this.#e)}set jd(e){Ke(this.#e,e,!0)}#t=Ge(1);get timeScale(){return Vt(this.#t)}set timeScale(e){Ke(this.#t,e,!0)}#n=Ge(1);get direction(){return Vt(this.#n)}set direction(e){Ke(this.#n,e,!0)}seeked=!1;#r=Ge(0);get jumps(){return Vt(this.#r)}set jumps(e){Ke(this.#r,e,!0)}#i=Ge(0);get settledJd(){return Vt(this.#i)}set settledJd(e){Ke(this.#i,e,!0)}#a=Ge(!1);get live(){return Vt(this.#a)}set live(e){Ke(this.#a,e,!0)}lastRealMs=0;prevScale=1;stops=null;settleTimer=null;constructor(e,t=!1){this.jd=e,this.settledJd=e,this.live=t,this.lastRealMs=performance.now()}tick(e){let t=e-this.lastRealMs;if(this.lastRealMs=e,this.timeScale===0)return;let n=this.jd+t/Mg*this.timeScale,r=this.stops;if(r!==null){if(this.timeScale>0&&r.forwardJd!==null&&n>=r.forwardJd&&this.jd<r.forwardJd){this.jd=r.forwardJd,this.pause(),r.onHit(r.forwardJd);return}if(this.timeScale<0&&r.backwardJd!==null&&n<=r.backwardJd&&this.jd>r.backwardJd){this.jd=r.backwardJd,this.pause(),r.onHit(r.backwardJd);return}}this.jd=n}setBoundaryStops(e){this.stops=e}setTimeScale(e){let t=e*this.direction;t!==0&&(this.prevScale=t),this.timeScale=t,t!==1&&(this.live=!1),this.lastRealMs=performance.now()}toggleDirection(){this.direction=this.direction===1?-1:1,this.timeScale=-this.timeScale,this.prevScale=-this.prevScale,this.live=!1,this.lastRealMs=performance.now()}setJD(e){this.jd=e,this.seeked=!0,this.live=!1,this.lastRealMs=performance.now(),this.settleAfterPause()}jumpTo(e){this.setJD(e),this.jumps++,this.settle()}settle(){this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=null,this.settledJd=this.jd}settleAfterPause(){this.settleTimer!==null&&clearTimeout(this.settleTimer),this.settleTimer=null,!this.playing&&(this.settleTimer=setTimeout(()=>this.settle(),TS))}sweepTo(e){this.jd=e,this.live=!1,this.lastRealMs=performance.now()}pause(){this.timeScale!==0&&(this.prevScale=this.timeScale),this.timeScale=0,this.live=!1,this.settle()}play(){this.timeScale===0&&(this.timeScale=this.prevScale||1,this.lastRealMs=performance.now())}now(){this.jumpTo(Pg(new Date)),this.live=this.timeScale===1}get playing(){return this.timeScale!==0}get date(){return Fg(this.jd)}setDate(e){this.jumpTo(Pg(e))}},DS={type:`change`},OS={type:`start`},kS={type:`end`},AS=new vs,jS=new sc,MS=Math.cos(70*Hi.DEG2RAD),NS=new J,PS=2*Math.PI,FS={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},IS=1e-6,LS=class extends qd{constructor(e,t=null){super(e,t),this.state=FS.NONE,this.target=new J,this.cursor=new J,this.minDistance=0,this.maxDistance=1/0,this.minZoom=0,this.maxZoom=1/0,this.minTargetRadius=0,this.maxTargetRadius=1/0,this.minPolarAngle=0,this.maxPolarAngle=Math.PI,this.minAzimuthAngle=-1/0,this.maxAzimuthAngle=1/0,this.enableDamping=!1,this.dampingFactor=.05,this.enableZoom=!0,this.zoomSpeed=1,this.enableRotate=!0,this.rotateSpeed=1,this.keyRotateSpeed=1,this.enablePan=!0,this.panSpeed=1,this.screenSpacePanning=!0,this.keyPanSpeed=7,this.zoomToCursor=!1,this.autoRotate=!1,this.autoRotateSpeed=2,this.keys={LEFT:`ArrowLeft`,UP:`ArrowUp`,RIGHT:`ArrowRight`,BOTTOM:`ArrowDown`},this.mouseButtons={LEFT:wn.ROTATE,MIDDLE:wn.DOLLY,RIGHT:wn.PAN},this.touches={ONE:Tn.ROTATE,TWO:Tn.DOLLY_PAN},this.target0=this.target.clone(),this.position0=this.object.position.clone(),this.zoom0=this.object.zoom,this._cursorStyle=`auto`,this._domElementKeyEvents=null,this._lastPosition=new J,this._lastQuaternion=new Ui,this._lastTargetPosition=new J,this._quat=new Ui().setFromUnitVectors(e.up,new J(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new Hd,this._sphericalDelta=new Hd,this._scale=1,this._panOffset=new J,this._rotateStart=new q,this._rotateEnd=new q,this._rotateDelta=new q,this._panStart=new q,this._panEnd=new q,this._panDelta=new q,this._dollyStart=new q,this._dollyEnd=new q,this._dollyDelta=new q,this._dollyDirection=new J,this._mouse=new q,this._performCursorZoom=!1,this._pointers=[],this._pointerPositions={},this._controlActive=!1,this._onPointerMove=zS.bind(this),this._onPointerDown=RS.bind(this),this._onPointerUp=BS.bind(this),this._onContextMenu=qS.bind(this),this._onMouseWheel=US.bind(this),this._onKeyDown=WS.bind(this),this._onTouchStart=GS.bind(this),this._onTouchMove=KS.bind(this),this._onMouseDown=VS.bind(this),this._onMouseMove=HS.bind(this),this._interceptControlDown=JS.bind(this),this._interceptControlUp=YS.bind(this),this.domElement!==null&&this.connect(this.domElement),this.update()}set cursorStyle(e){this._cursorStyle=e,e===`grab`?this.domElement.style.cursor=`grab`:this.domElement.style.cursor=`auto`}get cursorStyle(){return this._cursorStyle}connect(e){super.connect(e),this.domElement.addEventListener(`pointerdown`,this._onPointerDown),this.domElement.addEventListener(`pointercancel`,this._onPointerUp),this.domElement.addEventListener(`contextmenu`,this._onContextMenu),this.domElement.addEventListener(`wheel`,this._onMouseWheel,{passive:!1}),this.domElement.getRootNode().addEventListener(`keydown`,this._interceptControlDown,{passive:!0,capture:!0}),this.domElement.style.touchAction=`none`}disconnect(){this.domElement.removeEventListener(`pointerdown`,this._onPointerDown),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.domElement.removeEventListener(`pointercancel`,this._onPointerUp),this.domElement.removeEventListener(`wheel`,this._onMouseWheel),this.domElement.removeEventListener(`contextmenu`,this._onContextMenu),this.stopListenToKeyEvents(),this.domElement.getRootNode().removeEventListener(`keydown`,this._interceptControlDown,{capture:!0}),this.domElement.style.touchAction=`auto`}dispose(){this.disconnect()}getPolarAngle(){return this._spherical.phi}getAzimuthalAngle(){return this._spherical.theta}getDistance(){return this.object.position.distanceTo(this.target)}listenToKeyEvents(e){e.addEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=e}stopListenToKeyEvents(){this._domElementKeyEvents!==null&&(this._domElementKeyEvents.removeEventListener(`keydown`,this._onKeyDown),this._domElementKeyEvents=null)}saveState(){this.target0.copy(this.target),this.position0.copy(this.object.position),this.zoom0=this.object.zoom}reset(){this.target.copy(this.target0),this.object.position.copy(this.position0),this.object.zoom=this.zoom0,this.object.updateProjectionMatrix(),this.dispatchEvent(DS),this.update(),this.state=FS.NONE}pan(e,t){this._pan(e,t),this.update()}dollyIn(e){this._dollyIn(e),this.update()}dollyOut(e){this._dollyOut(e),this.update()}rotateLeft(e){this._rotateLeft(e),this.update()}rotateUp(e){this._rotateUp(e),this.update()}update(e=null){let t=this.object.position;NS.copy(t).sub(this.target),NS.applyQuaternion(this._quat),this._spherical.setFromVector3(NS),this.autoRotate&&this.state===FS.NONE&&this._rotateLeft(this._getAutoRotationAngle(e)),this.enableDamping?(this._spherical.theta+=this._sphericalDelta.theta*this.dampingFactor,this._spherical.phi+=this._sphericalDelta.phi*this.dampingFactor):(this._spherical.theta+=this._sphericalDelta.theta,this._spherical.phi+=this._sphericalDelta.phi);let n=this.minAzimuthAngle,r=this.maxAzimuthAngle;isFinite(n)&&isFinite(r)&&(n<-Math.PI?n+=PS:n>Math.PI&&(n-=PS),r<-Math.PI?r+=PS:r>Math.PI&&(r-=PS),n<=r?this._spherical.theta=Math.max(n,Math.min(r,this._spherical.theta)):this._spherical.theta=this._spherical.theta>(n+r)/2?Math.max(n,this._spherical.theta):Math.min(r,this._spherical.theta)),this._spherical.phi=Math.max(this.minPolarAngle,Math.min(this.maxPolarAngle,this._spherical.phi)),this._spherical.makeSafe(),this.enableDamping===!0?this.target.addScaledVector(this._panOffset,this.dampingFactor):this.target.add(this._panOffset),this.target.sub(this.cursor),this.target.clampLength(this.minTargetRadius,this.maxTargetRadius),this.target.add(this.cursor);let i=!1;if(this.zoomToCursor&&this._performCursorZoom||this.object.isOrthographicCamera)this._spherical.radius=this._clampDistance(this._spherical.radius);else{let e=this._spherical.radius;this._spherical.radius=this._clampDistance(this._spherical.radius*this._scale),i=e!=this._spherical.radius}if(NS.setFromSpherical(this._spherical),NS.applyQuaternion(this._quatInverse),t.copy(this.target).add(NS),this.object.lookAt(this.target),this.enableDamping===!0?(this._sphericalDelta.theta*=1-this.dampingFactor,this._sphericalDelta.phi*=1-this.dampingFactor,this._panOffset.multiplyScalar(1-this.dampingFactor)):(this._sphericalDelta.set(0,0,0),this._panOffset.set(0,0,0)),this.zoomToCursor&&this._performCursorZoom){let e=null;if(this.object.isPerspectiveCamera){let t=NS.length();e=this._clampDistance(t*this._scale);let n=t-e;this.object.position.addScaledVector(this._dollyDirection,n),this.object.updateMatrixWorld(),i=!!n}else if(this.object.isOrthographicCamera){let t=new J(this._mouse.x,this._mouse.y,0);t.unproject(this.object);let n=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),this.object.updateProjectionMatrix(),i=n!==this.object.zoom;let r=new J(this._mouse.x,this._mouse.y,0);r.unproject(this.object),this.object.position.sub(r).add(t),this.object.updateMatrixWorld(),e=NS.length()}else console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - zoom to cursor disabled.`),this.zoomToCursor=!1;e!==null&&(this.screenSpacePanning?this.target.set(0,0,-1).transformDirection(this.object.matrix).multiplyScalar(e).add(this.object.position):(AS.origin.copy(this.object.position),AS.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(AS.direction))<MS?this.object.lookAt(this.target):(jS.setFromNormalAndCoplanarPoint(this.object.up,this.target),AS.intersectPlane(jS,this.target))))}else if(this.object.isOrthographicCamera){let e=this.object.zoom;this.object.zoom=Math.max(this.minZoom,Math.min(this.maxZoom,this.object.zoom/this._scale)),e!==this.object.zoom&&(this.object.updateProjectionMatrix(),i=!0)}return this._scale=1,this._performCursorZoom=!1,i||this._lastPosition.distanceToSquared(this.object.position)>IS||8*(1-this._lastQuaternion.dot(this.object.quaternion))>IS||this._lastTargetPosition.distanceToSquared(this.target)>IS?(this.dispatchEvent(DS),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?PS/60/60*this.autoRotateSpeed:PS/60*this.autoRotateSpeed*e}_getZoomScale(e){let t=Math.abs(e*.01);return .95**(this.zoomSpeed*t)}_rotateLeft(e){this._sphericalDelta.theta-=e}_rotateUp(e){this._sphericalDelta.phi-=e}_panLeft(e,t){NS.setFromMatrixColumn(t,0),NS.multiplyScalar(-e),this._panOffset.add(NS)}_panUp(e,t){this.screenSpacePanning===!0?NS.setFromMatrixColumn(t,1):(NS.setFromMatrixColumn(t,0),NS.crossVectors(this.object.up,NS)),NS.multiplyScalar(e),this._panOffset.add(NS)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;NS.copy(r).sub(this.target);let i=NS.length();i*=Math.tan(this.object.fov/2*Math.PI/180),this._panLeft(2*e*i/n.clientHeight,this.object.matrix),this._panUp(2*t*i/n.clientHeight,this.object.matrix)}else this.object.isOrthographicCamera?(this._panLeft(e*(this.object.right-this.object.left)/this.object.zoom/n.clientWidth,this.object.matrix),this._panUp(t*(this.object.top-this.object.bottom)/this.object.zoom/n.clientHeight,this.object.matrix)):(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - pan disabled.`),this.enablePan=!1)}_dollyOut(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale/=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_dollyIn(e){this.object.isPerspectiveCamera||this.object.isOrthographicCamera?this._scale*=e:(console.warn(`WARNING: OrbitControls.js encountered an unknown camera type - dolly/zoom disabled.`),this.enableZoom=!1)}_updateZoomParameters(e,t){if(!this.zoomToCursor)return;this._performCursorZoom=!0;let n=this.domElement.getBoundingClientRect(),r=e-n.left,i=t-n.top,a=n.width,o=n.height;this._mouse.x=r/a*2-1,this._mouse.y=-(i/o)*2+1,this._dollyDirection.set(this._mouse.x,this._mouse.y,1).unproject(this.object).sub(this.object.position).normalize()}_clampDistance(e){return Math.max(this.minDistance,Math.min(this.maxDistance,e))}_handleMouseDownRotate(e){this._rotateStart.set(e.clientX,e.clientY)}_handleMouseDownDolly(e){this._updateZoomParameters(e.clientX,e.clientX),this._dollyStart.set(e.clientX,e.clientY)}_handleMouseDownPan(e){this._panStart.set(e.clientX,e.clientY)}_handleMouseMoveRotate(e){this._rotateEnd.set(e.clientX,e.clientY),this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(PS*this._rotateDelta.x/t.clientHeight),this._rotateUp(PS*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd),this.update()}_handleMouseMoveDolly(e){this._dollyEnd.set(e.clientX,e.clientY),this._dollyDelta.subVectors(this._dollyEnd,this._dollyStart),this._dollyDelta.y>0?this._dollyOut(this._getZoomScale(this._dollyDelta.y)):this._dollyDelta.y<0&&this._dollyIn(this._getZoomScale(this._dollyDelta.y)),this._dollyStart.copy(this._dollyEnd),this.update()}_handleMouseMovePan(e){this._panEnd.set(e.clientX,e.clientY),this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd),this.update()}_handleMouseWheel(e){this._updateZoomParameters(e.clientX,e.clientY),e.deltaY<0?this._dollyIn(this._getZoomScale(e.deltaY)):e.deltaY>0&&this._dollyOut(this._getZoomScale(e.deltaY)),this.update()}_handleKeyDown(e){let t=!1;switch(e.code){case this.keys.UP:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,this.keyPanSpeed),t=!0;break;case this.keys.BOTTOM:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateUp(-PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(0,-this.keyPanSpeed),t=!0;break;case this.keys.LEFT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(this.keyPanSpeed,0),t=!0;break;case this.keys.RIGHT:e.ctrlKey||e.metaKey||e.shiftKey?this.enableRotate&&this._rotateLeft(-PS*this.keyRotateSpeed/this.domElement.clientHeight):this.enablePan&&this._pan(-this.keyPanSpeed,0),t=!0;break}t&&(e.preventDefault(),this.update())}_handleTouchStartRotate(e){if(this._pointers.length===1)this._rotateStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateStart.set(n,r)}}_handleTouchStartPan(e){if(this._pointers.length===1)this._panStart.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panStart.set(n,r)}}_handleTouchStartDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyStart.set(0,i)}_handleTouchStartDollyPan(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enablePan&&this._handleTouchStartPan(e)}_handleTouchStartDollyRotate(e){this.enableZoom&&this._handleTouchStartDolly(e),this.enableRotate&&this._handleTouchStartRotate(e)}_handleTouchMoveRotate(e){if(this._pointers.length==1)this._rotateEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._rotateEnd.set(n,r)}this._rotateDelta.subVectors(this._rotateEnd,this._rotateStart).multiplyScalar(this.rotateSpeed);let t=this.domElement;this._rotateLeft(PS*this._rotateDelta.x/t.clientHeight),this._rotateUp(PS*this._rotateDelta.y/t.clientHeight),this._rotateStart.copy(this._rotateEnd)}_handleTouchMovePan(e){if(this._pointers.length===1)this._panEnd.set(e.pageX,e.pageY);else{let t=this._getSecondPointerPosition(e),n=.5*(e.pageX+t.x),r=.5*(e.pageY+t.y);this._panEnd.set(n,r)}this._panDelta.subVectors(this._panEnd,this._panStart).multiplyScalar(this.panSpeed),this._pan(this._panDelta.x,this._panDelta.y),this._panStart.copy(this._panEnd)}_handleTouchMoveDolly(e){let t=this._getSecondPointerPosition(e),n=e.pageX-t.x,r=e.pageY-t.y,i=Math.sqrt(n*n+r*r);this._dollyEnd.set(0,i),this._dollyDelta.set(0,(this._dollyEnd.y/this._dollyStart.y)**+this.zoomSpeed),this._dollyOut(this._dollyDelta.y),this._dollyStart.copy(this._dollyEnd);let a=(e.pageX+t.x)*.5,o=(e.pageY+t.y)*.5;this._updateZoomParameters(a,o)}_handleTouchMoveDollyPan(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enablePan&&this._handleTouchMovePan(e)}_handleTouchMoveDollyRotate(e){this.enableZoom&&this._handleTouchMoveDolly(e),this.enableRotate&&this._handleTouchMoveRotate(e)}_addPointer(e){this._pointers.push(e.pointerId)}_removePointer(e){delete this._pointerPositions[e.pointerId];for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId){this._pointers.splice(t,1);return}}_isTrackingPointer(e){for(let t=0;t<this._pointers.length;t++)if(this._pointers[t]==e.pointerId)return!0;return!1}_trackPointer(e){let t=this._pointerPositions[e.pointerId];t===void 0&&(t=new q,this._pointerPositions[e.pointerId]=t),t.set(e.pageX,e.pageY)}_getSecondPointerPosition(e){let t=e.pointerId===this._pointers[0]?this._pointers[1]:this._pointers[0];return this._pointerPositions[t]}_customWheelEvent(e){let t=e.deltaMode,n={clientX:e.clientX,clientY:e.clientY,deltaY:e.deltaY};switch(t){case 1:n.deltaY*=16;break;case 2:n.deltaY*=100;break}return e.ctrlKey&&!this._controlActive&&(n.deltaY*=10),n}};function RS(e){this.enabled!==!1&&(this._pointers.length===0&&(this.domElement.setPointerCapture(e.pointerId),this.domElement.ownerDocument.addEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.addEventListener(`pointerup`,this._onPointerUp)),!this._isTrackingPointer(e)&&(this._addPointer(e),e.pointerType===`touch`?this._onTouchStart(e):this._onMouseDown(e),this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grabbing`)))}function zS(e){this.enabled!==!1&&(e.pointerType===`touch`?this._onTouchMove(e):this._onMouseMove(e))}function BS(e){switch(this._removePointer(e),this._pointers.length){case 0:this.domElement.releasePointerCapture(e.pointerId),this.domElement.ownerDocument.removeEventListener(`pointermove`,this._onPointerMove),this.domElement.ownerDocument.removeEventListener(`pointerup`,this._onPointerUp),this.dispatchEvent(kS),this.state=FS.NONE,this._cursorStyle===`grab`&&(this.domElement.style.cursor=`grab`);break;case 1:let t=this._pointers[0],n=this._pointerPositions[t];this._onTouchStart({pointerId:t,pageX:n.x,pageY:n.y});break}}function VS(e){let t;switch(e.button){case 0:t=this.mouseButtons.LEFT;break;case 1:t=this.mouseButtons.MIDDLE;break;case 2:t=this.mouseButtons.RIGHT;break;default:t=-1}switch(t){case wn.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(e),this.state=FS.DOLLY;break;case wn.ROTATE:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=FS.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=FS.ROTATE}break;case wn.PAN:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=FS.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=FS.PAN}break;default:this.state=FS.NONE}this.state!==FS.NONE&&this.dispatchEvent(OS)}function HS(e){switch(this.state){case FS.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(e);break;case FS.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(e);break;case FS.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(e);break}}function US(e){this.enabled===!1||this.enableZoom===!1||this.state!==FS.NONE||(e.preventDefault(),this.dispatchEvent(OS),this._handleMouseWheel(this._customWheelEvent(e)),this.dispatchEvent(kS))}function WS(e){this.enabled!==!1&&this._handleKeyDown(e)}function GS(e){switch(this._trackPointer(e),this._pointers.length){case 1:switch(this.touches.ONE){case Tn.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(e),this.state=FS.TOUCH_ROTATE;break;case Tn.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(e),this.state=FS.TOUCH_PAN;break;default:this.state=FS.NONE}break;case 2:switch(this.touches.TWO){case Tn.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(e),this.state=FS.TOUCH_DOLLY_PAN;break;case Tn.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(e),this.state=FS.TOUCH_DOLLY_ROTATE;break;default:this.state=FS.NONE}break;default:this.state=FS.NONE}this.state!==FS.NONE&&this.dispatchEvent(OS)}function KS(e){switch(this._trackPointer(e),this.state){case FS.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(e),this.update();break;case FS.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(e),this.update();break;case FS.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(e),this.update();break;case FS.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(e),this.update();break;default:this.state=FS.NONE}}function qS(e){this.enabled!==!1&&e.preventDefault()}function JS(e){e.key===`Control`&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}function YS(e){e.key===`Control`&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}var{PI:XS,sin:ZS,cos:QS,asin:$S,atan2:eC,sqrt:tC}=Math,nC=180/XS,rC=XS/180;function iC(e,t,n){let[r,i,a]=e,[o,s,c,l]=n?[-t[0],-t[1],-t[2],t[3]]:t,u=l*r+s*a-c*i,d=l*i+c*r-o*a,f=l*a+o*i-s*r,p=-o*r-s*i-c*a;return[u*l+p*-o+d*-c-f*-s,d*l+p*-s+f*-o-u*-c,f*l+p*-c+u*-s-d*-o]}function aC(e,t,n){let r=e[0]-t[0],i=e[1]-t[1],a=e[2]-t[2],o=tC(r*r+i*i+a*a);return n&&([r,i,a]=iC([r,i,a],n,!0)),{latitude:$S(i/o)*nC,longitude:n?eC(-a,r)*nC:eC(r,a)*nC,distance:o}}function oC(e,t,n,r,i){let a=t*rC,o=n*rC,s,c,l;if(i){let e=[r*QS(a)*QS(o),r*ZS(a),-r*QS(a)*ZS(o)];[s,c,l]=iC(e,i,!1)}else s=r*QS(a)*ZS(o),c=r*ZS(a),l=r*QS(a)*QS(o);return[e[0]+s,e[1]+c,e[2]+l]}function sC(e,t,n,r){let i=e[0]-t[0],a=e[2]-t[2],o=tC(i*i+a*a);o>0?(i/=o,a/=o):(i=0,a=1);let s=n*rC,c=QS(s);return[r*c*i,r*ZS(s),r*c*a]}function cC(e){let t=(e+180)%360-180;return t<=-180?t+360:t}function lC(e,t,n){if(t===void 0&&n===void 0)return e;let r=t===void 0?-180:cC(t),i=r===180?-180:r,a=n===void 0?180:cC(n);if(i<=a?e>=i&&e<=a:e>=i||e<=a)return e;let o=(e,t)=>Math.abs(cC(e-t));return o(e,i)<=o(e,a)?i:a}var uC=m_;function dC(e,t){return`feature:${e}:${t}`}function fC(e,t){return{data:{id:dC(e.hostId,e.featureId),name:t,objectType:G.SURFACE_FEATURE,parentId:e.hostId,radiusKm:NaN,hasLocalized:!1,a:0,e:0,i:0,om:0,w:0,ma:0,n:0,epoch:0,validityStart:-1/0,validityEnd:1/0,orbitalSource:W.UNKNOWN},position:null,orbitCenterId:e.hostId,featureAnchor:e}}var pC={name:`CopyShader`,uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
4053
4053
 
4054
4054
  varying vec2 vUv;
4055
4055
 
@@ -5663,7 +5663,7 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
5663
5663
  <line x1="10" y1="0" x2="23" y2="0" stroke="${r}" stroke-width="1.6"/>
5664
5664
  <line x1="0" y1="-23" x2="0" y2="-10" stroke="${r}" stroke-width="1.6"/>
5665
5665
  <line x1="0" y1="10" x2="0" y2="23" stroke="${r}" stroke-width="1.6"/>
5666
- `;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 PP(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 Uo;c.setAttribute(`position`,new jo(o,3));let l=new Tc(c,new fc({color:r,transparent:!0,opacity:.55}));return l.frustumCulled=!1,l}function FP(){let e=new Ba;e.name=`sky-debug-markers`,e.visible=!1;let t=new J;for(let n of TP){MP(n.raDeg,n.decDeg,t).multiplyScalar(wP);let r=new rO(NP(n));r.center.set(0,.5),r.position.copy(t),e.add(r)}for(let t of jP){let n=PP(t.zero,t.pole,wP*.999,t.color,AP);n.name=t.name,e.add(n)}return e}function IP(e){e.traverse(e=>{e instanceof rO&&e.element.remove(),e instanceof Tc&&(e.geometry.dispose(),e.material.dispose())}),e.parent?.remove(e)}var LP=class{group=null;constructor(e){this.scene=e}setVisible(e){e?(this.group||(this.group=FP(),this.scene.add(this.group)),this.group.visible=!0):this.group&&=(IP(this.group),null)}},RP=new J,zP=new J,BP=new J,VP=[RP,zP,BP];function HP(e,t,n){return RP.set(1,0,0).applyQuaternion(e).transformDirection(t),zP.set(0,1,0).applyQuaternion(e).transformDirection(t),BP.set(0,0,1).applyQuaternion(e).transformDirection(t),{e:VP,a:n}}function UP(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 WP(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 GP(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 KP=class{canvas=null;gfx=null;tmp=new J;tmpQ=new Ui;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,l=o.body.position;if(!e||c<=0||!l)continue;let[u,d,b]=l;this.tmp.set(u-m,d-h,b-g).applyMatrix4(p);let x=this.tmp.x,S=this.tmp.y,C=this.tmp.z;if(C>=0||x*x+S*S+C*C<=c*c)continue;let w=aO(this.items,y++,qP),T=!!(o.semiAxesScene&&o.mesh);if(T){let e=HP(o.mesh.getWorldQuaternion(this.tmpQ),p,o.semiAxesScene);w.e0.copy(e.e[0]),w.e1.copy(e.e[1]),w.e2.copy(e.e[2]),w.sa[0]=e.a[0],w.sa[1]=e.a[1],w.sa[2]=e.a[2],WP(w.occ,x,S,C,e,f,_,v,o.body.data.id,o.cachedDist)}else w.e0.set(1,0,0),w.e1.set(0,1,0),w.e2.set(0,0,1),w.sa[0]=w.sa[1]=w.sa[2]=c,UP(w.occ,x,S,C,c,f,_,v,o.body.data.id,o.cachedDist);let E=C*C-c*c,D=E<=0,O=D?0:c*f/Math.sqrt(E),k=D||O>=16;this.tmp.set(u-m,d-h,b-g).project(t),w.cx=(this.tmp.x*.5+.5)*i,w.cy=(-this.tmp.y*.5+.5)*a,vO(o,t,n,i,a,this.labelRect),w.hx=this.labelRect.x,w.hy=this.labelRect.y,w.id=o.body.data.id,w.camX=x,w.camY=S,w.camZ=C,w.worldR=c,w.dist=o.cachedDist,w.isEllipsoid=T,w.degenerate=D,w.isOccluder=k,w.meshHidden=!s.visible,w.labelVisible=e.visible,w.maximized=o.labelMaximized!==!1,w.focused=o.body.data.id===r,w.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,gO(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(),XP(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)}}YP(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 qP(){return{id:``,camX:0,camY:0,camZ:0,worldR:0,e0:new J,e1:new J,e2:new J,sa:[0,0,0],occ:uO(),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 JP=[[`#1ae5ff`,`label shown`],[`#ffe11a`,`dimmed`],[`#ff3b3b`,`hidden`],[`#ff8c1a`,`occluder silhouette`],[`#7dff7d`,`focused`]];function YP(e,t){let n=t-8-(JP.length-1)*13;e.font=`10px monospace`,e.textBaseline=`middle`;for(let[t,r]of JP)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 XP(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 ZP(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 QP="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",$P=typeof self<`u`&&self.Blob&&new Blob([`URL.revokeObjectURL(import.meta.url);`,QP],{type:`text/javascript;charset=utf-8`});function eF(e){let t;try{if(t=$P&&(self.URL||self.webkitURL).createObjectURL($P),!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(QP),{type:`module`,name:e?.name})}}var tF=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 eF;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 Vg(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}]},Ug(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()}},nF=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 vh(n[e-t]);return null}clear(){this.#t.clear(),this.#e=1}},rF=.01,iF=[`asteroid`,`spacecraft`],aF=.0002959122082855911,oF=.75,sF=Q(8*86400);function cF(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(aF/i*((1+o)/(1-o)));s>t&&(t=s)}return{maxSpeedScene:t*10,alwaysSolve:n}}function lF(e){return e<0?0:e>1?1:e}function uF(e,t){return t===`*`?e.startsWith(`small_bodies/`):e===t}function dF(e){return e===null?{tBright:0,tSize:0}:{tBright:lF((fF-e)/(fF-pF)),tSize:lF((mF-e)/(mF-hF))}}var fF=1e4,pF=500,mF=pF,hF=50,gF=4,_F=.5,vF=10,yF=1,bF=1,xF=3.5,SF=2.5,CF=2,wF=xF,TF=class{orbitPool=new tF;pickRegistry=new nF;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:gF,dim:_F,opacity:bF};emphasizedSmallBodyZone=null;smallBodyEmphasis={sizeMult:1,brightMult:1,opacity:bF};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 iF)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 iF)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)C_(e)===`naif-399`&&this.applyEarthSatEmphasis(t)}computeEarthSatEmphasis(e){let{tBright:t,tSize:n}=dF(e);return{size:gF+(vF-gF)*n,dim:_F+(yF-_F)*t,opacity:bF+(xF-bF)*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)uF(C_(e),n)&&this.resetSmallBodyEmphasis(t);if(e!==null)for(let[t,n]of this.workerPoints.asteroid)uF(C_(t),e)&&this.applySmallBodyEmphasis(n)}computeSmallBodyEmphasis(e){let{tBright:t,tSize:n}=dF(e);return{sizeMult:1+(SF-1)*n,brightMult:1+(CF-1)*t,opacity:bF+(wF-bF)*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=bF,e.userData.smallBodyBaseSize=void 0,e.userData.smallBodyBaseColor=void 0}seedBasis(e){this.basisPos=[...e]}buildInitial(e){let t=mP(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 iF)for(let[t,n]of this.workerPoints[e]){let r=C_(t);n.userData.parentBodyId=this.cloudParentId(e,r),this.emphasiseNewCloud(e,r,n)}this.assignMapLayer()}assignMapLayer(){for(let e of iF)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`?p_:t}emphasiseNewCloud(e,t,n){if(e===`spacecraft`){t===`naif-399`&&this.applyEarthSatEmphasis(n);return}let r=this.emphasizedSmallBodyZone;r!==null&&uF(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=bh(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,cF(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=zN(new Float32Array(l.cols.count*3),0,this.circleTexture,c,LN());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 S_(n,Ev(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=>yh(e.data.id)??ph));await this.orbitPool.rewireOne(c,l,s,(o+r)%t,!1,u),this.armGroupGate(c,{maxSpeedScene:sF,alwaysSolve:!1});let d=this.workerPoints.spacecraft.get(i);if(d){this.resizeGeometryIfNeeded(d.geometry,l);continue}let f=new Float32Array(l.length*3);this.seedColors(f,l);let p=zN(new Float32Array(l.length*3),0,this.circleTexture,`#ffffff`,void 0,f);this.adoptCloud(`spacecraft`,i,c,p,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=C_(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)}seedColors(e,t){let n=new X,r=Math.min(t.length,e.length/3);for(let i=0;i<r;i++)n.set(g_(t[i].data)),e[i*3]=n.r,e[i*3+1]=n.g,e[i*3+2]=n.b}resizeGeometryIfNeeded(e,t){let n=t.length*3;if(e.getAttribute(`position`).array.length!==n){if(e.setAttribute(`position`,new Oo(new Float32Array(n),3)),e.getAttribute(`color`)){let r=new Float32Array(n);this.seedColors(r,t),e.setAttribute(`color`,new Oo(r,3))}e.setDrawRange(0,0)}}resizeGeometryToCount(e,t,n){let r=t*3,i=e.getAttribute(`position`).array;if(n&&e.setAttribute(`color`,new Oo(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 Oo(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 Oo(t.slice(),4,!0))}reposition(){let[e,t,n]=this.focus.focusTruePos,r=this.basisPos;for(let i of iF)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=rF*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(p_)?.position;for(let[i,a]of this.workerPoints.asteroid){if(!r)break;if(!this.ctx.visibility.isAsteroidGroupVisible(C_(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(C_(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;s[0]=o[0],s[1]=o[1],s[2]=o[2],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>=oF}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].position;s[r*3]=a?a[0]-e:NaN,s[r*3+1]=a?a[1]-t:NaN,s[r*3+2]=a?a[2]-n:NaN}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++){let r=n[t].position;i[t*3]=r?r[0]-e[0]:NaN,i[t*3+1]=r?r[1]-e[1]:NaN,i[t*3+2]=r?r[2]-e[2]:NaN}r.geometry.setAttribute(`position`,new jo(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 iF)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()}},EF=Math.PI/180,DF=2451545,OF=1.00000261,kF=.01671123,AF=100.46457166*EF,jF=35999.37244981/36525*EF,MF=102.93768193*EF,NF=.32327364/36525*EF;function PF(e){let t=e-DF,n=MF+NF*t,r=AF+jF*t-n,i=r+(2*kF-kF**3/4)*Math.sin(r)+1.25*kF*kF*Math.sin(2*r);return{lon:n+i,r:OF*(1-kF*kF)/(1+kF*Math.cos(i))}}function FF(e){let t=PF(e).lon;return(e,n)=>{let r=t-PF(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 IF=.01,LF=1/100,RF=1;function zF(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 BF(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 VF(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=zF(c,l,u)}function HF(e,t,n,r,i,a){let o=t.userData,s=o.useTrail,c=o.orbitCenter,l=e.trailAnchor??e.position;if(!l)return;let 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(BF(o,g,u,d,f,p,m,h,a))return;let{posArr:_,trailArr:v,fullArr:y}=oP(t),b=e.lagrangeTrail?FF(i):null,x=cP(e,n,_,c.x,c.y,c.z,r,b??void 0);sP(t,_,v,y,x,!0,s),VF(o,g,u,d,f,p,m,h,_,x,a)}function UF(e,t,n,r,i){let{posArr:a,trailArr:o,fullArr:s,capacity:c}=oP(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){tP(e.geometry,a,o,s,l);return}e.geometry.getAttribute(`position`).needsUpdate=!0}function WF(e,t,n,r,i){let a=t.userData.trailBuffer;if(a){HF(e,t,a,n,r,i);return}let o=t.userData.sourceCurve;if(!o){if(!t.userData.curvePending||!e.orbitElements)return;o=QN(WN(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,p;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=XN(e.data.satrec,r,n,512),t.userData.sourceCurve=o,t.userData.curveJd=a=r),p=o.length-(r<a?2:1)}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*LF,RF)){let n=e.rederiveElements(r);n&&(Object.assign(e.orbitElements,n),o=QN(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)>IF&&(o=QN(WN(e.orbitElements,r),512).points,t.userData.sourceCurve=o,t.userData.curveJd=r)}}let m=e.trailAnchor??e.position;if(!m)return;let h=t.userData,g=u-n[0],_=d-n[1],v=f-n[2],y=m[0]-u,b=m[1]-d,x=m[2]-f;if(BF(h,o,g,_,v,y,b,x,i))return;let S=Jy(e,o,s,u,d,f,p);if(S.length<2)return;let{posArr:C,trailArr:w,fullArr:T,capacity:E}=oP(t),D=u-n[0],O=d-n[1],k=f-n[2],A=Math.min(S.length,E);for(let e=0;e<A;e++)C[e*3]=S[e][0]+D,C[e*3+1]=S[e][1]+O,C[e*3+2]=S[e][2]+k;sP(t,C,w,T,A,s,c),h.trailLocalPositions=S,VF(h,o,g,_,v,y,b,x,C,A,i)}function GF(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 KF(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 qF=4/2,JF=(.1*10)**2,YF=new J,XF=[],ZF=XF;function QF(e){return aO(XF,e,uO)}var $F={x:0,y:0,left:0,right:0,h:0},eI=new Ui,tI={ox:0,oy:0},nI=new J,rI=new J;function iI(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()){let e=n.body.position;if(!e||n.carried){n.cachedDist=1/0;continue}if(n.cachedDist=B_(C,e),n.isCrashed||n.noPhysical){let e=n.noPhysical===`model`,t=lg(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()}KT(n,`missing`,r)}let r=n.label;if(!r)continue;n.labelAnchorOffscreen=!1;let a=n.noPhysical?0:n.radiusScene;if(!a){r.position.set(0,0,0);continue}let[o,s,c]=e;p.set(o-w[0],s-w[1],c-w[2]).applyMatrix4(T);let l=p.x,u=p.y,d=p.z,f=d*d,m=a*a;if(f<=m){r.position.set(0,0,0),n.labelAnchorOffscreen=!0;continue}let h=a/n.cachedDist*S;if(h<1){r.position.set(0,0,0);continue}if(h>=16){let e=n.cachedDist,i=1/e,f=l*i,m=u*i,h=d*i,g=a*i,_=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*e-l,T*e-u,E*e-d).applyQuaternion(t.quaternion),r.position.copy(p),rI.set(o-w[0]+p.x,s-w[1]+p.y,c-w[2]+p.z).project(t),n.labelAnchorOffscreen=Math.abs(rI.x)>1||Math.abs(rI.y)>1;continue}if(n.semiAxesScene&&n.mesh)GP(l,u,d,HP(n.mesh.getWorldQuaternion(eI),T,n.semiAxesScene),S,tI),p.set(tI.ox,tI.oy,0).applyQuaternion(t.quaternion);else{let e=m/(f-m);p.set(e*l,e*u,0).applyQuaternion(t.quaternion)}r.position.copy(p)}let E=XF,D=b*.5,O=x*.5,k=0;for(let t of e.values()){let e=t.noPhysical?0:t.radiusScene,n=t.body.position;if(!e||!n||t.carried)continue;let r=t.cachedDist,[i,a,o]=n,s=t.model?.userData.occluderSpheres;if(t.model&&s?.length){let e=aD(t),n=t.model.position;for(let c of s){let s=c.r*e;if(nI.copy(c.center).applyQuaternion(t.model.quaternion).add(n).multiplyScalar(e),p.set(i-w[0]+nI.x,a-w[1]+nI.y,o-w[2]+nI.z).applyMatrix4(T),p.z>=s||p.lengthSq()<=s*s)continue;let l=p.z*p.z;(l<=s*s||s*S/Math.sqrt(l-s*s)>=16)&&UP(QF(k++),p.x,p.y,p.z,s,S,D,O,t.body.data.id,r)}continue}p.set(i-w[0],a-w[1],o-w[2]).applyMatrix4(T);let c=p.x,l=p.y,u=p.z;if(u>=e)continue;let d=u*u;(d<=e*e||e*S/Math.sqrt(d-e*e)>=16)&&(t.semiAxesScene&&t.mesh?WP(QF(k++),c,l,u,HP(t.mesh.getWorldQuaternion(eI),T,t.semiAxesScene),S,D,O,t.body.data.id,r):UP(QF(k++),c,l,u,e,S,D,O,t.body.data.id,r))}E.length=k;let A=n.visibility.focusedSystemId,j=!1,M=a?oN(n.getBody(a),e):void 0;for(let r of e.values()){let{body:i,group:s,trail:c}=r,l=r.cachedDist,u=sO(r);r.root.visible=u;let d,f,p=i.data.id===a,m=A!==null&&i.data.id===A;if(r.mesh===null&&!vn(i.data.objectType)){let t=i.data.objectType;if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){let t=!0,r=p?void 0:F_(i.data.id);if(r){let a=e.get(r)?.body??n.getBody(r);a?.position&&i.position&&B_(i.position,a.position)/B_(C,a.position)*S<16&&(t=!1)}s.visible=t,c&&(c.visible=t),d=t,f=!1}else{let e=n.visibility.getPlanetVisibility(i,l)!==$.HIDE&&n.visibility.hasFullRendering(i);s.visible=e,c&&(c.visible=e),d=e,f=!1}}else{let e=i.data.objectType===G.MOON,t=e?n.visibility.getMoonVisibility(i):n.visibility.getPlanetVisibility(i,l),r=e?GF(t,o,p):KF(t,n.visibility.hasFullRendering(i),p||m);s.visible=r.groupVisible,c&&(c.visible=r.orbitVisible),d=r.showLabel,f=r.isClose}if(u||(s.visible=!1,d=!1,f=!1),c&&(!u||i.orbitCenter===null)&&(c.visible=!1),r.starPoint&&u){let e=r.radiusScene/l*S,t=e<qF;if(r.starPoint.visible=t,t){let t=r.starPoint.material,n=e/qF,i=Math.max(rA*n*n,3);t.uniforms.uIntensity.value=i}s.visible=!0,f=!t,d=!f}if(r.isMinor&&!p&&c&&!n.visibility.isPinned(i.data.id)&&(c.visible=!1),h&&c?.visible){let e=c.userData.orbitCenter;e&&e.distanceToSquared(YF.set(w[0],w[1],w[2]))>JF&&(c.visible=!1)}_&&c&&(c.visible=!1),s.matrixWorldAutoUpdate=s.visible;let{label:g}=r;if(!s.visible&&g&&g.parent===s?(s.remove(g),g.element.remove()):s.visible&&g&&g.parent!==s&&s.add(g),r.mesh&&r.radiusScene>0){let e=!p&&!m&&r.radiusScene/l*S<.5;e!==r.meshSubPixel&&(r.meshSubPixel=e,e?r.mesh.layers.disable(0):r.mesh.layers.enable(0))}hO(r,d,f,l,S,a)&&(j=!0);let y=r.radiusScene>0?r.radiusScene/l*S:0;ON(r,v&&i.data.id===M,y,t,b,x)}for(let[e,t]of c)t.visible=n.visibility.isAsteroidGroupVisible(C_(e));for(let[e,t]of l)t.visible=n.visibility.isSpacecraftGroupVisible(C_(e));for(let[e,t]of u)t.visible=n.visibility.isMoonGroupVisible(e);if(E.length>0){let n=a?F_(a):null;for(let r of e.values()){if(!r.label?.visible||!vO(r,t,w,b,x,$F))continue;let e=r.body.data.id;gO($F.x,$F.y,r.cachedDist,e,E,e===a?n:null)&&(r.label.visible=!1)}}if((m||j||++d>=3)&&(d=0,jO(e,b,x,t,a,n,s,E,r)),MO(e,b,x,t,r),M){let t=e.get(M);t&&MN(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 aI(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function oI(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function sI(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function cI(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 lI(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-uI(d):p,g=f?m+uI(f):m;if(t<h||t>g)return null;if(a&&d&&t<(c?.jds[0]??n.startJd))return{r:dI(d,t),centerId:a.anchorId};if(c&&t<=c.jds[c.jds.length-1])return{r:fI(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:dI(f,t),centerId:o.anchorId};if(l)return{r:fI(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}=cI(e,v);return{r:fI(y,b,t,x,S),centerId:e.centerId}}function uI(e){return e.jds[e.jds.length-1]-e.jds[0]}function dI(e,t){let n=uI(e),r=e.jds[0],i=n>0?r+((t-r)%n+n)%n:t;return fI(e.points,e.jds,i)}function fI(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 aI(e[a-1],sI(oI(e[a],e[a-1]),s))}var pI=Math.PI/180,mI=Math.cos(og*pI),hI=Math.sin(og*pI);function gI(e,t,n,r){let i=Math.cos(e*pI),a=Math.sin(e*pI),o=Math.cos(t*pI),s=Math.sin(t*pI),c=Math.cos(n*pI),l=Math.sin(n*pI);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 _I(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*mI+a*hI,t=-i*hI+a*mI;i=e,a=t}return[r,i,a]}function vI(e){let t=10/ag;return[e[0]*t,e[2]*t,-e[1]*t]}function yI(e,t,n){let{a:r,e:i,ma:a,n:o,epoch:s,q:c,tp:l}=e,{om:u,w:d}=WN(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=Tg(c,l,t);if(!r)return null;let i=n&&n>0?n:nv,a=r.r*ag,o=2*c*ag;return bI(a,r.nu,o,1,i,d,e.i,u,f)}if(!isFinite(i)||!isFinite(a))return null;let p=r*ag,m=o*pI/rv,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))*pI,_,v;if(i<1||r>0){let e=Math.min(i,.9999999),t=Sg(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=wg(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:bI(v,_,y,i,h,d,e.i,u,f)}function bI(e,t,n,r,i,a,o,s,c){let l=Math.cos(t),u=Math.sin(t),d=Math.sqrt(i/n),f=gI(a,o,s,c),p=_I(e*l,e*u,f),m=_I(-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 xI={cruise:`#7fdbff`,boost:`#ffb454`,brake:`#ff8c69`,spiral:`#c9a0ff`,"spiral-out":`#9b7fd4`,"spiral-in":`#9b7fd4`};xI.cruise,xI.boost,xI.brake,xI.spiral,xI[`spiral-out`],xI[`spiral-in`];var SI={notice:`#8ab4f8`,caution:`#f2b23e`,severe:`#ff6b5a`},CI=3,wI=1,TI=2,EI=.6,DI=1.5,OI=.3,kI=1.5,AI=.85,jI=60,MI=.018,NI=.026,PI=`#ffffff`,FI=4,II=1.5,LI=9,RI=1,zI={notice:FI-3,caution:FI-2,severe:FI-1},BI=[`notice`,`caution`,`severe`],VI=.03,HI=.2;function UI(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 Pc(t)}function WI(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 Pc(t)}function GI(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 KI(e,t){let n=new ls(new Yo({map:e,transparent:!0,sizeAttenuation:!1,depthTest:!1}));return n.scale.setScalar(t),n.renderOrder=FI,n}function qI(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&&(VO(c,i),aN(c,o)),s&&(c.addEventListener(`mouseenter`,()=>s(!0)),c.addEventListener(`mouseleave`,()=>s(!1)));let p=new rO(c);return p.center.set(0,.5),p}function JI(e,t){return e&&[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}var YI=class{group=new Ba;anchored=new Map;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?DI:TI,i?OI:EI,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)=>BI.indexOf(e.severity)-BI.indexOf(t.severity));for(let t of n){let n=SI[t.severity];for(let n of t.bands)e.arcs.forEach((t,r)=>{this.addLine(GI(t,n.startJd,n.endJd,cI(e,r)),SI[n.severity],LI,RI,null,{renderOrder:zI[n.severity]})});if(this.mergeIntoStep(t,n))continue;let r=lI(e,t.startJd);if(!r)continue;let i=vI(r.r),a=r.centerId===e.centerId?null:r.centerId,o=KI(WI(n),VI);this.parentOf(a).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 rO(s);c.center.set(0,.5),this.parentOf(a).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,CI,wI,null,!0),this.addEndOrbits(n),this.addSteps(n,t);for(let e of this.markers)this.parentOf(e.anchorId).add(e.sprite);this.craft={sprite:KI(UI(PI),NI),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=lI(e,n.jd);if(!t)continue;let r=vI(t.r),i=t.centerId===e.centerId?null:t.centerId,a=KI(UI(PI),MI);this.markers.push({sprite:a,local:r,anchorId:i});let o=qI(`step`,n.name,n.when,{canvas:this.canvas,onSelect:n.onPick});this.parentOf(i).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:vI(n.meeting.r),end:e.arrival,color:xI[a?.kind??`cruise`]}];o&&s.push({local:vI(o.r),end:e.departure,color:xI[i?.kind??`cruise`]});for(let{local:n,end:i,color:a}of s){if(!i.name)continue;let o=qI(`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?wI:e.brightness),n.uniforms.uLineWidth.value=t?CI: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?cI(e,s):{from:0,to:a.points.length};this.addLine(a.points.slice(c,l),xI[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),xI.cruise,CI,wI,null,{anchorId:n}),this.addLine(t.approach.slice(i.from,i.to),xI.cruise,CI,wI,null,{anchorId:n,renderOrder:II}),e=i.to;e<t.approach.length&&this.addLine(t.approach.slice(Math.max(0,e-1)),xI.cruise,CI,wI,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,xI.cruise,CI,wI,null,{anchorId:n});this.addLine(t.approach.slice(e>0?e-1:0,r),xI.cruise,kI,AI,null,{anchorId:n})}else this.addLine(t.approach,xI.cruise,CI,wI,null,{anchorId:n});let i=this.addLine(t.points,xI.cruise,kI,AI,null,{anchorId:n});if(!i)continue;let a=n===null?vI(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]=vI(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*HI));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=aP(o,c,l,l,o,t,n,r);d.frustumCulled=!1,d.renderOrder=a.renderOrder??FI,this.parentOf(a.anchorId??null).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=lI(this.path,e);t.sprite.visible=n!==null,n&&(t.local=vI(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],e[1]-t[1],e[2]-t[2]],i=new Map;for(let[e,r]of this.anchored){let a=n(e);i.set(e,JI(a,t)),r.visible=a!==null}let a=e=>e===null?r:i.get(e)??null;for(let e of this.arcs){let t=a(e.anchorId);if(!t)continue;let[n,r,i]=t;for(let t=0;t<e.count;t++)e.positions[t*3]=e.local[t*3]+n,e.positions[t*3+1]=e.local[t*3+1]+r,e.positions[t*3+2]=e.local[t*3+2]+i;tP(e.line.geometry,e.positions,e.alphas,e.alphas,e.count)}for(let e of this.markers){let t=a(e.anchorId);if(!t)continue;let[n,r,i]=t;e.sprite.position.set(e.local[0]+n,e.local[1]+r,e.local[2]+i)}for(let e of this.labels){let t=a(e.anchorId);if(!t)continue;let[n,r,i]=t;e.object.position.set(e.local[0]+n,e.local[1]+r,e.local[2]+i)}if(this.craft){let{sprite:e,local:r,anchorId:i}=this.craft,o=i===null||this.anchored.has(i)?a(i):JI(n(i),t);o?e.position.set(r[0]+o[0],r[1]+o[1],r[2]+o[2]):e.visible=!1}for(let e of this.rings){let t=a(e.arc.anchorId);if(!t)continue;let[n,r,i]=t;e.world.set(e.local[0]+n,e.local[1]+r,e.local[2]+i)}}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*jI}}}setVisible(e){this.group.visible=e}reserveLabelSpace(e,t,n){if(!this.group.visible||this.labels.length===0){kO(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),!AC(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=gO(a,o,s,``,ZF);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++}kO(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))}parentOf(e){if(e===null)return this.group;let t=this.anchored.get(e);return t||(t=new Ba,this.anchored.set(e,t),this.group.add(t)),t}clear(){for(let e of this.arcs)e.line.removeFromParent(),e.line.geometry.dispose(),e.line.material.dispose();for(let e of[...this.markers,...this.craft?[this.craft]:[]]){e.sprite.removeFromParent();let t=e.sprite.material;t.map?.dispose(),t.dispose()}for(let e of this.labels)e.object.removeFromParent(),e.object.element.remove();for(let e of this.anchored.values())this.group.remove(e);this.anchored.clear(),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)}},XI=2,ZI=1,QI=4,$I=200,eL=class{group=new Ba;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,$I);for(let t=0;t<e.count;t++){let[r,i,a]=vI(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($I*3),t=new Float32Array($I).fill(1),n=aP($I,e,t,t,0,xI.cruise,XI,ZI);n.frustumCulled=!1,n.renderOrder=QI,this.layer!==null&&n.layers.set(this.layer),this.group.add(n),this.slots.push({line:n,bodyId:``,local:new Float64Array($I*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;tP(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)}},tL=new Set([`not-yet`,`no-data`,`parent`,`failed`]);function nL(e){let{jd:t,ctx:n,bodyObjects:r,focus:i,focusedBody:a,placer:o,trailView:s,frame:c,outOfRange:l}=e;n.chebStore?.ensure(t),n.probeStore?.ensure(t);let u=[];if(a){let e=new Set([a.data.id]),t=n.getBody(a.data.parentId);for(;t&&!e.has(t.data.id);)e.add(t.data.id),u.push({body:t,oldPos:t.position?[...t.position]:null}),t=n.getBody(t.data.parentId)}o.begin(t,a?.data.id,c);let d=n.visibility.focusedSystemId;for(let e of n.bodies.bodiesById.values())e.data.objectType===G.MOON&&e.data.parentId!==d&&e!==a||o.placeInPass(e);for(let e of r.values())o.placeInPass(e.body);let f=a?o.place(a,t):null,p=a?.unplaced;l.update({jd:t,satellites:n.refresher?.satelliteCoverage(t)??{kind:`covered`},majorBodies:o.noData,focusedOutOfRange:p!==void 0&&tL.has(p)});let m=null,h=performance.now()-i.focusStartTime<i.focusDurationMs;if(a&&!f)for(let e of u){let n=o.place(e.body,t);if(n){if(m=e.body.data.id,h){iL(i.focusTargetWorld,n);let e=i.camTargetOffset;e&&i.camTargetWorld&&aL(i.camTargetWorld,n,e)}else if(e.oldPos)for(let t=0;t<3;t++){let r=n[t]-e.oldPos[t];i.focusTruePos[t]+=r,i.focusTargetWorld[t]+=r}break}}else if(f){iL(i.focusTargetWorld,f);let e=i.camTargetOffset;e&&i.camTargetWorld&&aL(i.camTargetWorld,f,e);let t=i.camOriginOffset;t&&i.camOriginWorld&&aL(i.camOriginWorld,f,t),h||iL(i.focusTruePos,f)}let g=i.focusTruePos;for(let e of r.values()){let n=e.trail;if(n){if(!n.visible){n.userData.refreshDeferred=!0;continue}WF(e.body,n,g,t,s),n.userData.refreshDeferred=!1}}let _=!f&&p===`loading`;return{focusUnplaced:a!==void 0&&!f&&!_,focusLoading:_,anchorId:m}}function rL(e,t,n,r){let i=t.focusTruePos;for(let t of e.values()){let e=t.trail;!e||!e.visible||!e.userData.refreshDeferred||(WF(t.body,e,i,n,r),e.userData.refreshDeferred=!1)}}function iL(e,t){e[0]=t[0],e[1]=t[1],e[2]=t[2]}function aL(e,t,n){e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2]}var oL=Object.freeze([0,0,0]);function sL(e,t,n,r){if(!Number.isFinite(t+n+r))return cL(e,`failed`);let i=e,a=i.position??=[0,0,0];return a[0]=t,a[1]=n,a[2]=r,i.unplaced=void 0,a}function cL(e,t){let n=e;return n.position=null,n.orbitCenter=n.orbitCenterId===void 0?void 0:null,n.unplaced=t,null}function lL(e,t){let n=e;if(!t){n.orbitCenter=null;return}let r=n.orbitCenter??=[0,0,0];r[0]=t[0],r[1]=t[1],r[2]=t[2]}function uL(e,t){let n=e.trailAnchor??=[0,0,0];n[0]=t[0],n[1]=t[1],n[2]=t[2]}var dL=Math.PI/180,fL=120,pL=Q(.001)**2,mL=new WeakMap,hL=new J,gL=new J;function _L(e,t,n){e.distanceToSquared(t)<=pL?e.copy(t):e.lerp(t,n)}function vL(e,t,n,r,i){let a=e.featureAnchor;lL(e,n),gL.set(0,0,0);let o=r?.nomenclatureActiveIndex??-1,s=o>=0?r?.nomenclatureLabels?.[o]??null:null;if(s&&s.element.dataset.featureId===String(a.featureId)){let e=r?.nomenclatureAnchor;e?(hL.copy(s.position),gL.copy(e.position)):(hL.copy(s.position),r?.mesh&&hL.multiply(r.mesh.scale))}else{let e=t.data.radiusKm,n=a.lat*dL,i=a.lon*dL,o=t.orientation&&Number.isFinite(e)&&e>0?nN(r,t.data.id,e,n,i):null;if(o)hL.set(o.pointKm[0],o.pointKm[1],o.pointKm[2]);else{let t=Number.isFinite(e)&&e>0?e:0,[r,a,o]=FM(n,i);hL.set(t*r,t*a,t*o)}hL.multiplyScalar(Q(1))}let c=performance.now(),l=mL.get(e);if(!l)l={fixed:hL.clone(),addend:gL.clone(),t:c},mL.set(e,l);else{let e=1-Math.exp(-(c-l.t)/fL);l.t=c,_L(l.fixed,hL,e),_L(l.addend,gL,e)}return hL.copy(l.fixed),t.orientation&&hL.applyQuaternion(wT(t.orientation,i,t.nutPrec)),sL(e,n[0]+hL.x+l.addend.x,n[1]+hL.y+l.addend.y,n[2]+hL.z+l.addend.z)}var yL=30034e-10,bL=.45,xL=1.6,SL=.85,CL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],wL=e=>Math.hypot(e[0],e[1],e[2]);function TL(e,t,n=yL){let r=wL(t);if(!(r>0))return null;let i=r*Math.cbrt(n/3),a=CL(e,t)/r,o=wL(e);if(Math.sqrt(Math.max(0,o*o-a*a))>SL*i)return null;let s=a/i;return s>=bL&&s<=xL?`EL1`:s<=-bL&&s>=-xL?`EL2`:null}function EL(e,t){return!(e.visibleFromDays!==void 0&&t-2451545<e.visibleFromDays)}function DL(e){return e.a===0&&(e.objectType===G.BARYCENTER||e.objectType===G.LAGRANGE_POINT||vn(e.objectType))}function OL(e,t){if(e.pageOnly)return`never`;if(!EL(e,t))return`not-yet`;if(t<e.validityStart||t>e.validityEnd)return`no-data`;let n,r=e.satrec;return n=r?xg(r,t):e.omm?null:e.q==null?e.a===0?DL(e)?[0,0,0]:null:GN(e,t):KN(e,t),!n||!Number.isFinite(n[0]+n[1]+n[2])?`failed`:n}function kL(){return{count:0,earliestStart:1/0,latestEnd:-1/0}}var AL=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`?Ng(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})}}},jL=new Map,ML=new J;function NL(e,t,n,r,i,a,o){let s=wy(n,r,Sy(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(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=nN(o.get(c),c,d,p,m);h&&jL.set(e.id,h);let g=h??jL.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=wT(l.orientation,r,l.nutPrec),x=new J(_,v,y).applyQuaternion(b),S=g?ML.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 PL=[0,0,0],FL=new Ui,IL=4,LL=0,RL=new Map;function zL(e){return e.primary.target===`velocity`||e.secondary?.target===`velocity`}function BL(e,t,n){let r=RL.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 RL.set(e,{jd:t,pos:[n[0],n[1],n[2]],dir:i}),i??void 0}var VL=class{focusedId;noData=kL();passJd=NaN;frame;settled=new Set;settling=new Set;ride=dx([],void 0,()=>void 0);rideJd=NaN;rideFocus;constructor(e,t,n){this.ctx=e,this.bodyObjects=t,this.diagnostics=n}begin(e,t,n){this.passJd=e,this.focusedId=t,this.frame=n,this.settled.clear(),this.noData=kL()}at(e,t){if(e===`naif-0`)return oL;let n=this.ctx.getBody(e)??this.bodyObjects.get(e)?.body;return n?this.place(n,t):null}placeInPass(e){let t=e.data,n=this.bodyObjects.get(t.id);n&&this.frame!==void 0&&t.id!==this.focusedId&&!n.root.visible&&!n.trail?.visible&&(t.orbitalSource===W.SPICE_PROBE||!vn(t.objectType))&&(n.staggerSlot??=LL++%IL,this.frame%IL!==n.staggerSlot)||this.place(e,this.passJd)}place(e,t){let n=e.data.id;if(t===this.passJd&&this.settled.has(n))return e.position;if(this.settling.has(n))return this.diagnostics.warnOnce(`parent-cycle`,n,()=>`place[${n}]: parent chain loops`),null;this.settling.add(n);let r=un(e)?this.seatFeature(e,t):this.settle(e,t);return this.settling.delete(n),t===this.passJd&&this.settled.add(n),r}under(e){return(this.ctx.getBody(e)??this.bodyObjects.get(e)?.body)?.unplaced===`loading`?`loading`:`parent`}seatFeature(e,t){let n=e.featureAnchor.hostId,r=this.ctx.getBody(n),i=r&&this.place(r,t);return!r||!i?cL(e,this.under(n)):vL(e,r,i,this.bodyObjects.get(n),t)}rideAt(e){return(e!==this.rideJd||this.focusedId!==this.rideFocus)&&(this.rideJd=e,this.rideFocus=this.focusedId,this.ride=dx(this.ctx.probeStore?.ridesAt(e)??[],this.focusedId,e=>this.ctx.getBody(e)?.data.name)),this.ride}rowOffset(e,t,n){let r=this.ctx.bodies.elementRow(e),i=r&&this.at(r.parentId,n);if(!i)return null;let a=OL(r,n);return typeof a==`string`?null:[i[0]-t[0]+a[0],i[1]-t[1]+a[1],i[2]-t[2]+a[2]]}settle(e,t){let{ctx:n,diagnostics:r}=this,i=e.data,a=this.bodyObjects.get(i.id);if(i.pageOnly)return cL(e,`never`);if(i.orbitalSource===W.SPICE_PROBE)return this.settleProbe(e,a,t);let o=this.at(i.parentId,t);if(!o){let t=this.under(i.parentId);return t===`parent`&&r.warnOnce(`missing-parent`,i.id,()=>`place[${i.id}]: parent ${i.parentId} has no place`),cL(e,t)}r.clear(`missing-parent`,i.id);let s;return s=n.chebStore?.has(i.id)?EL(i,t)?n.chebStore.positionScene(i.id,t)??this.rowOffset(e,o,t)??this.chebMiss(i.id,t):`not-yet`:OL(i,t),typeof s==`string`?cL(e,s):this.finish(e,a,o[0]+s[0],o[1]+s[1],o[2]+s[2],o,t)}chebMiss(e,t){let n=this.ctx.chebStore;if(n.isLoading(e,t))return`loading`;let r=n.zoneCoverage(e);return r!==null&&(t<r.start||t>r.end)&&t===this.passJd&&(this.noData.count++,r.start<this.noData.earliestStart&&(this.noData.earliestStart=r.start),r.end>this.noData.latestEnd&&(this.noData.latestEnd=r.end)),this.diagnostics.warnOnce(`cheb-null`,e,()=>{let n=r?`[${r.start.toFixed(1)},${r.end.toFixed(1)}]`:`unknown`;return`chebStore.positionScene[${e}] returned null at jd=${t.toFixed(3)} (coverage=${n})`}),`no-data`}finish(e,t,n,r,i,a,o){let s=e.data,c=sL(e,n,r,i);if(!c)return this.diagnostics.warnOnce(`non-finite`,s.id,()=>`place[${s.id}] non-finite: pos=[${n},${r},${i}] parentId=${s.parentId}`),null;let l=e.orbitCenterId;if(l!==void 0&&lL(e,l===s.parentId?a:this.at(l,o)),e.trailAnchorId!==void 0){let t=this.at(e.trailAnchorId,o);t&&uL(e,t)}if(!t)return c;if(t.trail&&e.orbitCenter){let n=t.trail.userData.orbitCenter;n&&n.set(e.orbitCenter[0],e.orbitCenter[1],e.orbitCenter[2])}if(e.orientation&&(t.mesh||t.model))t.mesh&&TT(t.mesh,e.orientation,o,e.nutPrec),t.model&&TT(t.model,e.orientation,o,e.nutPrec),t.nomenclatureAnchor&&TT(t.nomenclatureAnchor,e.orientation,o,e.nutPrec);else if($E(e)){let n=e.attitudeTrack;if(!e.pointingOverride&&n&&n.orientationAt(o,FL))t.mesh&&t.mesh.quaternion.copy(FL),t.model&&t.model.quaternion.copy(FL);else{let n=e.pointingOverride??e.pointing;if(n){let e=zL(n)?BL(s.id,o,c):void 0,r={bodyPos:c,parentPos:a,sunPos:this.at(`naif-10`,o)??void 0,velocity:e};t.mesh&&UT(t.mesh,n,r),t.model&&UT(t.model,n,r)}else t.mesh&&OT(t.mesh,c,a),t.model&&OT(t.model,c,a)}}if(e.orientation)for(let n of t.rings)TT(n.mesh,e.orientation,o,e.nutPrec);return c}settleProbe(e,t,n){let{ctx:r,bodyObjects:a,diagnostics:o}=this,s=e.data,c=this.rideAt(n);if(t){t.carried=c.hidden.has(s.id);let e=c.credits.get(s.id);KT(t,`carrier`,e?i().messages.carried_by_scene_label({carrier:e}):null)}let l=r.visibility.activeSystemId,u=l?e=>r.bodies.isInSystem(`naif-${e}`,l):void 0,d=r.probeStore?.probeWithCenter(s.id,n,u)??null;if(!d)return r.probeStore?.loadingAt(n)?cL(e,`loading`):(cL(e,`no-data`),o.warnOnce(`probe-unavailable`,s.id,()=>{let e=r.probeStore?`no zone has both a loaded chunk and a sub-chunk covering this jd`:`no ProbeStore`;return`probe ${s.id} (${s.name??`unnamed`}): hidden — ${e}`}),null);let f=d.probe.landed;if(f&&Cy(d.probe,n)){let i=s.parentId,c=NL(s,d.probe,f,n,e=>this.at(e,n),r,a);if(!c)return cL(e,this.under(`naif-${f.bodyNaifId}`));if(o.clear(`probe-unavailable`,s.id),i!==s.parentId&&e.trailBuffer?.clear(),t){let e=f.isDestroyed;t.isLanded||=(FO(t.labelHalo,`landed`),!0),t.isCrashed=e,t.model&&(t.model.visible=!e)}let l=sL(e,c.x,c.y,c.z);if(!l)return null;e.orbitCenterId=s.parentId,lL(e,c.parentPos);let u=c.up;return t?.mesh&&(u?kT(t.mesh,u):OT(t.mesh,l,c.parentPos)),t?.model&&(u?kT(t.model,u):OT(t.model,l,c.parentPos)),l}let p=Py(d.probe,n,d.fitCenterNaifId,r.chebStore??null,e=>this.at(e,n)!==null);if(!p){let t=d.probe.fitCenter?.id;return cL(e,t?this.under(t):`parent`),o.warnOnce(`probe-unavailable`,s.id,()=>`probe ${s.id} (${s.name??`unnamed`}): hidden — stamped fit center is not placeable this frame`),null}let m=p.id,h=p.muKm3S2,g=by(d.probe,n,h);if(!g)return cL(e,`no-data`),o.warnOnce(`probe-unavailable`,s.id,()=>`probe ${s.id} (${s.name??`unnamed`}): hidden — sub-chunk evaluation returned null (uncoverable, non-finite fit, or missing mu for kepler_pure)`),null;o.clear(`probe-unavailable`,s.id),t?.isLanded&&(FO(t.labelHalo,`flying`),t.isLanded=!1,t.isCrashed&&(t.isCrashed=!1,t.model&&(t.model.visible=!0),t.noPhysical||KT(t,`missing`,null)));let _=this.at(m_,n),v=this.at(p_,n),y=m===`naif-399`&&_!==null&&v!==null&&TL([Q(g[0]),Q(g[2]),-Q(g[1])],[v[0]-_[0],v[1]-_[1],v[2]-_[2]])!==null,b=y!==(e.lagrangeTrail??!1);e.lagrangeTrail=y;let x=s.parentId!==m;if((x||b)&&e.trailBuffer&&r.probeStore){let t=e.trailBuffer;t.clear(),t.needsPopulate=!1;let i=Ry(jy(d.probe,n,h),s.validityEnd-s.validityStart,t.capacity,y);t.reconfigure(i.stepDays,i.epsilonScene,i.spanDays),Wy(t,r.probeStore,r.chebStore??null,s.id,m,n)}x&&(s.parentId=m);let S=this.at(m,n);if(!S)return cL(e,this.under(m)),o.warnOnce(`probe-unavailable`,s.id,()=>`probe ${s.id} (${s.name??`unnamed`}): hidden — fit center ${m} has no position this frame`),null;let C=S,w=Q(g[0]),T=Q(g[2]),E=-Q(g[1]),D=C[0]+w,O=C[1]+T,k=C[2]+E,A=e.trailBuffer;if(A?.needsPopulate&&t?.trail?.visible&&r.probeStore&&(A.needsPopulate=!1,A.clear(),Wy(A,r.probeStore,r.chebStore??null,s.id,m,n)),A){let e=A.newestJd,t=n-e,i=A.stepDays*A.capacity,a=isFinite(e)&&(t<0||t>i);if(a&&s.id===this.focusedId&&r.probeStore){A.clear();let e=Ry(jy(d.probe,n,h),s.validityEnd-s.validityStart,A.capacity,y);A.reconfigure(e.stepDays,e.epsilonScene,e.spanDays),Wy(A,r.probeStore,r.chebStore??null,s.id,m,n)}else a?(A.clear(),A.append(n,w,T,E)):isFinite(e)?isFinite(A.epsilonScene)?t>=A.stepDays*.00390625&&r.probeStore&&A.readNewestPos(PL)&&Ky(A,By(r.probeStore,r.chebStore??null,s.id,m),e,[PL[0],PL[1],PL[2]],n):t>=A.stepDays&&A.append(n,w,T,E):A.append(n,w,T,E)}return e.orbitCenterId=s.parentId,this.finish(e,t,D,O,k,C,n)}},HL=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)}},UL=Q(695700),WL=2,GL=new J;function KL(e,t,n,r,i){GL.subVectors(e,t);let a=GL.dot(n),o=Math.sqrt(Math.max(GL.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 qL(e,t,n,r,i,a){let o=e.get(p_)?.body.position;if(!o)return;let[s,c,l]=t;for(let t of e.values()){let e=t.body.position;if(!t.rings.length||!e)continue;let[u,d,f]=e;for(let e of t.rings){let p=r||e.intensityScale>=.000980392156862745;e.mesh.visible=p;let m=r?1:p?e.intensityScale:0;e.material.uniforms.uIntensityScale.value=m;let h=e.material.uniforms.uSunDir.value;h.set(o[0]-u,o[1]-d,o[2]-f);let g=h.length(),_=UL/g;e.material.uniforms.uSunAngularRadius.value=_,e.material.uniforms.uLightScale.value=n?JC(g):1,h.normalize();let v=e.planetShadowOnRing;if(v.uPlanetCenter.value.set(u-s,d-c,f-l),t.mesh&&v.uPlanetPoleDir.value.set(0,1,0).applyQuaternion(t.mesh.quaternion),e.layers){let{dist:t,sinToPole:n}=KL(i,v.uPlanetCenter.value,v.uPlanetPoleDir.value,e.innerScene,e.outerScene),r=e.thicknessScene*n/Math.max(t,1e-9)*a,o=Math.min(Math.max(Math.ceil(r*WL),1),48);e.layers.count!==o&&(e.layers.count=o,e.material.uniforms.uLayerCount.value=o,e.material.uniforms.uLayerAlphaExp.value=1/o)}let y=e.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 JL=Math.PI/180,YL=2451545;function XL(e){let t=e-YL,n=(19.3871+.52402073*t)*JL;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 ZL(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 QL(e,t){let n=e.seasonal;if(!n)return e;let r=ZL(n.lsDeg,n.dustTauFactor,t),i=ZL(n.lsDeg,n.dustScaleHeightKm,t),a=ZL(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 $L=new WeakMap,eR=.25;function tR(e,t){if(!e.seasonal)return e;let n=Math.round(XL(t)/eR),r=$L.get(e);if(r&&r.lsQ===n)return r.params;let i=QL(e,n*eR);return $L.set(e,{lsQ:n,params:i}),i}var nR=new J,rR=new J,iR=[.2126,.7152,.0722];function aR(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 oR(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=aR(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+=iR[t]*Math.exp(-n)}return o}var sR=.4,cR=.05,lR=-.105,uR=.3,dR=.05;function fR(e,t,n){let r=oR(e,t),i=Math.min(1,-Math.log(Math.max(r,.001))/dR),a=Math.min(1,Math.max(0,(n-lR)/uR));return r*(1+(sR+(cR-sR)*a-1)*i)}function pR(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 mR=KC,hR=200,gR=new J,_R=new J,vR=new J,yR=new J;function bR(e,t,n,r){e.uOccluderCount.value=_E(e.uOccluders.value,t,r,n)}function xR(e,t,n,r,i,a,o){let s={insideShell:!1,shellProminent:!1,skyboxIntensity:1,sunTint:gR.set(1,1,1),sunRefraction:null};Hk(n&&a.sunTint);let c=e.get(p_);hA(c?.mesh?.material,db());let l=mA(c?.mesh?.material);l&&(l.uAtmoTEnable.value=0);let u=hR,d=c?.body.position;if(!d)return s;for(let c of e.values()){if(!c.atmosphere)continue;c.atmosphere.mesh.visible=n;let e=c.body.position;if(!n||!e)continue;Pk(c.atmosphere,a);let f=ub(c.body.data.id);if(f?.seasonal){let e=a.seasonal?tR(f,o):f;if(c.atmosphere.params!==e){Fk(c.atmosphere,e);for(let t of c.sunTint??[])Yk(t,e,c.atmosphere.surfaceRadiusScene,c.atmosphere.surfaceRadiusKm)}}let[p,m,h]=e,g=c.atmosphere.material.uniforms;g.uGroundAlbedo.value=a.groundAlbedo?c.atmosphere.params.groundAlbedo??0:0;let _=g.uSunDir.value.set(d[0]-p,d[1]-m,d[2]-h),v=c.atmosphere.params,y=r?JC(_.length()):v.realisticSunAlways?Math.sqrt(JC(_.length())):1;g.uSunIntensity.value=v.sunIntensity*y*i,_.normalize(),c.mesh&&(nR.set(0,1,0).applyQuaternion(c.mesh.quaternion),g.uSpinAxis.value.copy(nR));let b=c.root.position,x=c.atmosphere.geometryRadiusScene*c.atmosphere.mesh.scale.x,S=t.distanceTo(b);x>S*.1&&(s.shellProminent=!0),a.eclipseShadows&&bR(g,b,_,x);let C=a.insideView&&S<x,w=c.atmosphere.planetRadiusKm,T=S*((w+v.topAltitudeKm)/x)-w,E=C&&jk(v,T),D=C?Mk(v,T):0;Ok(c.atmosphere,C,E,D),g.uDeepIrradiance.value=mR*i;for(let e of c.sunTint??[])e.uAtmoTDeepIrradiance.value=mR*i,e.uAtmoTDeepBlend.value=D;if(C){s.insideShell=!0;let e=rR.copy(t).sub(b).divideScalar(S).dot(_),n=fR(v,T,e);if(s.skyboxIntensity*=n*(1-D),a.refraction&&v.refractivity&&!E){let t=pR(v.refractivity[1]*Math.exp(-Math.max(T,0)/v.rayleighScaleHeightKm),Math.asin(Math.min(1,Math.max(-1,e))),v.rayleighScaleHeightKm,c.atmosphere.planetRadiusKm);t>5e-6&&(s.sunRefraction={angleRad:t,up:yR.copy(rR)})}}let O=S/x;if(a.sunTint&&O<hR){let e=x/(1+v.topAltitudeKm/w)*(c.atmosphere.surfaceRadiusKm/w);vR.copy(t).sub(b);let n=g.uSpinAxis.value,r=g.uStretch.value;if(nA(v,vR,_,e,c.atmosphere.surfaceRadiusKm,_R,n,r)){let e=iR[0]*_R.x+iR[1]*_R.y+iR[2]*_R.z;e>1e-4&&s.sunTint.multiply(_R.divideScalar(e))}l&&O<u&&(u=O,Zk(l,v,b,e,c.atmosphere.surfaceRadiusKm,n,r))}}return s}var SR=[];function CR(e,t){let n=hE(),r=e.get(p_),i=r?.body.position;if(!r||!i){n.uSunAngularRadius.value=0,n.uOccluderCount.value=0;return}let[a,o,s]=t,c=i[0]-a,l=i[1]-o,u=i[2]-s,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=SR,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||!sO(t)||(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,i]=t.body.position;m[e].set(n-a,r-o,i-s,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,n=t.body.position;if(!e||!n||t.cachedDist>0&&t.radiusScene<t.cachedDist*1e-4)continue;let[r,i,c]=n,l=e.uEclipseSelfPos.value.set(r-a,i-o,c-s);e.uOccluderCount.value=_E(e.uOccluders.value,l,t.radiusScene,h)}}var wR=10;function TR(e,t,n,r,i,a,o,s,c){let l=n.visibility.activeSystemId;if(!l){r.intensity=0,i&&YC(i,s,c);return}let u=e.get(p_)?.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(wR),r.target.position.set(0,0,0),r.intensity=KC*(s?JC(_):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=wR-b,x.far=wR+b,x.updateProjectionMatrix()}var ER=128,DR=256,OR=.25,kR=.32,AR=.35,jR=300,MR=1.25,NR=.05,PR=4e5,FR=new Y,IR=new J;function LR(e,t,n){let r=e=>t.some(([t,n])=>e>t+1e-9&&e<n-1e-9),i=e/ER,a=[];for(let t=0;t<=ER;t++){let n=t===ER?e:t*i;(t===0||t===ER||!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 RR(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 Uo;return u.setAttribute(`position`,new Oo(a,3)),u.setAttribute(`normal`,new Oo(o,3)),u.setAttribute(`uv`,new Oo(s,2)),u.setIndex(new Oo(c.subarray(0,l),1)),u}function zR(e){e.terrainWindow&&(e.terrainWindow=null,e.currentSegments=void 0)}function BR(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}`),zR(e),!1;r.updateMatrixWorld(),FR.copy(r.matrixWorld).invert(),IR.copy(t.position).applyMatrix4(FR);let a=Q(gn(e.body.data)),o=IR.length(),s=Math.max(o/a-1,1e-6);if(s>(e.terrainWindow?kR:OR))return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: alt=${s.toFixed(4)}`),zR(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*MR/DR),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*DR/2,_=Math.acos(Math.min(1,Math.max(-1,IR.y/o))),v=Math.atan2(IR.z,-IR.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)))<AR*m.angRadius)return!0}if(performance.now()-m.builtAt<jR)return!0}let y=Math.max(0,_-g),b=Math.min(Math.PI,_+g),x=LR(Math.PI,[[y,b]],h),S=Math.min(Math.PI,g/Math.max(Math.sin(_),NR)),C=Math.max(p,Math.ceil(Math.log2(2*S/DR/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=LR(2*Math.PI,D,w);if(x.length*O.length>PR)return console.warn(`terrain window for ${e.body.data.id} would need ${x.length}×${O.length} vertices — keeping the uniform sphere`),zR(e),!1;let k=r.geometry;return r.geometry=RR(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=ER,!0}var VR=[{up:150,segs:128},{up:40,segs:64},{up:0,segs:32}],HR=24;function UR(e,t,n,r){if(!n&&!t)return HR;let i=VR[VR.length-1].segs;for(let t of VR)if(e>=t.up){i=t.segs;break}if(i<r){let t=VR.find(e=>e.segs===r);if(t&&e>=t.up*.85)return r}return i}function WR(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)&&BR(n,t,a===c))continue;let l=UR(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(gn(n.body.data)),d=n.mesh.geometry;n.mesh.geometry=new iu(u,l,l),d.dispose(),n.currentSegments=l}}function GR(e,t){let n=e<1.05?`high`:e<4?`medium`:`low`;if(pM(n)>pM(t))return n;let r=e>7?`low`:e>1.15?`medium`:`high`;return pM(r)<pM(t)?r:t}function KR(e,t,n,r,i,a,o,s,c){s.apply(e,i);let l=t.fov*Math.PI/180,u=n.domElement.clientHeight/(2*Math.tan(l/2)),d=r.visibility.activeSystemId,f=jx(),p=f.showClouds,m=pM(Kx());for(let t of e.values())t.clouds&&(t.clouds.mesh.visible=p);for(let s of e.values()){if(!s.mesh||!s.radiusScene||!s.group.visible||!s.availableTiers?.length||s.cachedDist<=0)continue;let e=s.body.data.id;if(d){if(e!==d&&!r.visibility.isInActiveSystem(s.body.data.parentId))continue}else if(e!==a)continue;let l=s.radiusScene/s.cachedDist*u,p=s.cachedDist/s.radiusScene,h;h=l<256&&p>10?`low`:l<1024&&p>2?`medium`:`high`;let g=pM(s.textureTier),_=mj(s)?Math.min(m,pM(`medium`)):m,v=Math.min(pM(h),_),y=gM(o,s.availableFrames),b=y!==s.textureFrame,x=v>g;if(f.showSurfaceTexture&&!s.textureLoading&&(x||b)){let e=x?mM(v,s.availableTiers):s.textureTier;e&&SM(s,e,y,i)}_j(s,t,n,u*n.getPixelRatio(),f.showSurfaceTexture&&!s.appearance?.surfaceOwned&&!s.model,c);let S=s.displacementMeta?.tiers;if(s.displacementMap&&S?.length&&!s.displacementLoading){let e=n.capabilities.maxTextureSize,t=e>=16383?2:+(e>=8192),r=s.displacementTier??`low`,i=mM(Math.min(pM(GR(p,r)),t,m),S);i&&i!==r&&Kj(s,i)}if(s.clouds&&s.textureTier){let e=mM(pM(s.textureTier),s.clouds.availableTiers),t=Ij(o,s.clouds.availableFrames,s.clouds.availableCoverage);e&&t&&zj(s.clouds,e,t)}}}var qR=JD.refMs,JR=new Y,YR=new J,XR=new J,ZR=new Ui,QR=new Ui,$R=new J,ez=new J;function tz(e,t,n){return YR.set(e[0],e[1],e[2]),XR.set(t[0],t[1],t[2]),JR.lookAt(YR,XR,n),ZR.setFromRotationMatrix(JR).clone()}function nz(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=z_(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=V_(e.camOriginWorld,e.camTargetWorld,e.focusTargetWorld,n);else{let t=r?o*o*o:n;i=z_(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]),QR.copy(t.quaternion),t.quaternion.slerpQuaternions(e.flyQ0,QR,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=z_(e.camOriginWorld,e.camTargetWorld,t)}let i=tz(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 rz(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=tz([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=B_(r,i),s=e.flyQ0.angleTo(a);e.focusDurationMs=Math.max(qD(o,XD),KD(s,ZD))}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(),$R.set(0,0,-1).applyQuaternion(e.flyQ0),ez.set(t[0]-r[0],t[1]-r[1],t[2]-r[2]).normalize(),e.focusDurationMs=KD($R.angleTo(ez),JD);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 iz(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=B_(n,r);$R.set(e.focusTruePos[0]-n[0],e.focusTruePos[1]-n[1],e.focusTruePos[2]-n[2]).normalize(),ez.set(e.focusTruePos[0]-r[0],e.focusTruePos[1]-r[1],e.focusTruePos[2]-r[2]).normalize();let o=$R.angleTo(ez);e.focusDurationMs=Math.max(qD(a,XD),KD(o,ZD)),i&&(e.focusDurationMs=0)}var az={[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},oz=5e-4,sz=new J,cz=new J;function lz(e){return az[e.data.objectType]??gn(e.data)*.25}function uz(e,t){return Q((t??gn(e.data))+lz(e))}function dz(e,t,n,r){let i=t.data.radiusKm,a=t.position;if(!Number.isFinite(i)||i<=0||!a)return;let o=a[0]-n[0],s=a[1]-n[1],c=a[2]-n[2],l=Math.hypot(o,s,c),u=r?.centerOffsetScene,d=o+(u?u[0]:0),f=s+(u?u[1]:0),p=c+(u?u[2]:0),m=e.position.x-d,h=e.position.y-f,g=e.position.z-p,_=Math.hypot(m,h,g);if(r?.seated){if(_<1e-9){e.position.set(d,f+l+Q(oz),p);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]]){cz.set(a,o,s).applyQuaternion(e.quaternion);let t=m+cz.x,n=h+cz.y,c=g+cz.z,u=Math.hypot(t,n,c);if(u<1e-12)continue;sz.set(t/u,n/u,c/u).applyQuaternion(r.invQuat);let d=r.radialKm([sz.x,sz.y,sz.z]),f=(d===null?l:Q(d))+Q(oz);f-u>i&&(i=f-u)}if(i<=0)return;let a=i/_;e.position.set(e.position.x+m*a,e.position.y+h*a,e.position.z+g*a);return}let v=lz(t);if(_>=Q((r?.outerRadiusKm??i)+v))return;let y=i;r&&_>1e-9&&(sz.set(m/_,h/_,g/_).applyQuaternion(r.invQuat),y=r.radialKm([sz.x,sz.y,sz.z])??i);let b=Q(y+v),x=l>0?Math.min(b,l):b;if(!(_>=x)){if(_<1e-9)m=0,h=x,g=0;else{let e=x/_;m*=e,h*=e,g*=e}e.position.set(d+m,f+h,p+g)}}function fz(e,t,n){let r=e.position,{latitude:i,longitude:a,distance:o}=aC([r.x,r.y,r.z],[0,0,0],n),s=Math.min(Math.max(i,t.minLat??-90),t.maxLat??90),c=lC(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]=oC([0,0,0],s,c,l,n);r.set(u,d,f)}var pz=50,mz=20;function hz(e){return e<=0?`none`:e<mz?`full`:e<pz?`half`:`none`}function gz(e,t){return e.data.validityStart<=t&&t<=e.data.validityEnd}var _z=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),Uv().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 h_)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||!_n(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:h_.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;!e.orbitElements&&!e.data.pageOnly&&e.data.orbitalSource!==W.SPICE_PROBE&&(e.orbitElements=e.data,e.orbitCenterId=e.data.parentId),i.place(e,a.jd),xj([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&&bM(d),e.data.objectType===G.SPACECRAFT)i.bodies.dirtySpacecraftGroups.add(e.data.parentId);else if(_n(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(){pP(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(m_),t=this.currentMemberCount(e),n=hz(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)||gz(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),gz(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&&!gz(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||un(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}if(e.label&&(e.label.element.remove(),e.label.removeFromParent()),e.loadingEl?.remove(),fD(e),xM(e),yN(e),i.remove(e.root),e.trail&&i.remove(e.trail),e.mesh){e.mesh.geometry.dispose(),vj(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(),vj(e.atmosphere.mesh.material),null),e.trail&&(e.trail.geometry.dispose(),vj(e.trail.material));let s=e.body.data.objectType;if(s===G.SPACECRAFT)c.add(e.body.data.parentId);else if(_n(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)}},vz=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 _z({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}place(e){return this.deps.ctx.place(e,this.deps.clock.jd)}setPendingInitialView(e){this.pendingInitialView=e}clearPendingInitialView(){this.pendingInitialView=null}focusedBodyQuat(e){let t=e??this.focusedBody;if(!t||$E(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=yz(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&&(Sj(t.body)?wj(t,n,r,i):fD(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}Sj(t)&&(Cj(o,n,r,i),f=!0),t.data.id!==e?.data.id&&c(t)}return f&&(pP(a,n,o.basis(),s.jd),l()),this.upgradeTargetIds=d,d}panCameraToBody(e,t){let n=this.place(e);if(!n)return;let{focus:r,camera:i}=this.deps,a=this.cameraTruePos(),o;if(t!==void 0){let e=this._tmpV3.set(a[0]-n[0],a[1]-n[1],a[2]-n[2]).normalize();o=[n[0]+e.x*t,n[1]+e.y*t,n[2]+e.z*t]}rz(r,[...n],i,a,o,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,rz(n,[...e],r,a,o,jx().resolvedReducedMotion);let s=aC(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}this.setFocusTarget(e);let t=e.position;if(!t)return;let{latitude:n,longitude:r,distance:i}=aC(this.cameraTruePos(),t,this.focusedBodyQuat(e));this.deps.callbacks.onCameraPosition?.(n,r,i)}setFocusTarget(e,t){let{ctx:n,bodyObjects:r,controls:i,callbacks:a,focus:o,camera:s,systemData:c,loadTexture:l}=this.deps;un(e)||this.promotion.ensureBodyObjects(e);let u=this.focusedBody,d=oN(u,r),f=oN(e,r),p=u&&(un(u)?u.featureAnchor.hostId:u.data.id),m=un(e)?e.featureAnchor.hostId:e.data.id,h=this.syncUpgradeTargets(e);if(p&&p!==m&&!h.has(p)){let e=r.get(p);e&&fD(e)}if(d&&d!==f){let e=r.get(d);e&&yN(e)}this.focusedBody=e,un(e)||(n.bodies.focusFeature=null),i.minDistance=uz(e,ND(r.get(e.data.id)));let g=un(e)?n.getBody(e.featureAnchor.hostId):void 0;if(n.visibility.setFocused(g??e),a.onFocusChange(e),un(e)||l(e),f&&f!==e.data.id){let e=n.getBody(f);e&&l(e)}c.syncToFocus();let _=this.place(e);_&&rz(o,[..._],s,this.cameraTruePos(),t,jx().resolvedReducedMotion),this.promotion.emitUserPromotedCount()}focusOnBody(e,t,n,r){let{ctx:i,focus:a,camera:o,callbacks:s,pointClouds:c}=this.deps,l=i.getBody(e);if(!l)return 0;let u=this.place(l);if(!u)return this.setFocusTarget(l),0;let d;if(t!==void 0)if(n!==void 0&&r!==void 0)d=oC(u,n,r,t,this.focusedBodyQuat(l));else{let e=this.cameraTruePos(),n=this._tmpV3.set(u[0]-e[0],u[1]-e[1],u[2]-e[2]).normalize().negate();d=[u[0]+n.x*t,u[1]+n.y*t,u[2]+n.z*t]}let f=aC(d??this.cameraTruePos(),u,this.focusedBodyQuat(l));return s.onCameraPosition?.(f.latitude,f.longitude,f.distance),t!==void 0&&d?this.focusedBody?.data.id===e&&B_(a.focusTruePos,u)<uz(l)?(a.focusTruePos=[...u],this.deps.repositionAll(),c.rebuildBasis(),iz(a,o,this.cameraTruePos(),d,jx().resolvedReducedMotion)):(this.setFocusTarget(l,d),n!==void 0&&r!==void 0&&(a.orbitFly=!0)):this.setFocusTarget(l),a.focusDurationMs}snapToBody(e,t,n,r){let i=this.deps.ctx.getBody(e),a=i&&this.place(i);!i||!a||(this.settleOnBodyInstant(i,a),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),l=i.getBody(t),u=c&&this.place(c),d=l&&this.place(l);if(!c||!u||!d)return;this.settleOnBodyInstant(c,u);let f=sC(u,d,n,r);a.position.set(f[0],f[1],f[2]),o.update();let p=aC(f,[0,0,0]);s.onCameraPosition?.(p.latitude,p.longitude,p.distance),this.pendingInitialView=null}settleOnBodyInstant(e,t){let{focus:n,pointClouds:r}=this.deps;this.setFocusTarget(e),n.focusTruePos=[...t],n.focusOriginWorld=[...t],n.focusTargetWorld=[...t],n.focusStartTime=-qR,n.camOriginWorld=null,n.camTargetWorld=null,n.flyQ0=null,n.orbitFly=!1,n.arcOrbit=!1,n.cameraStaysOnBody=!1,this.deps.repositionAll(),r.rebuildBasis()}snapToBodyFrame(e,t,n){let r=this.focusedBody;if(!r)return;let{camera:i,controls:a,callbacks:o}=this.deps,s=!$E(r),c=s?this.focusedBodyQuat(r)??[0,0,0,1]:void 0,l=oC([0,0,0],e,t,n,c);i.position.set(l[0],l[1],l[2]),a.update();let u=aC(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=oC([0,0,0],e.latitude,e.longitude,e.zoom,t);this.deps.camera.position.set(...n),this.deps.controls.update(),this.pendingInitialView=null}};function yz(e,t){if(!e)return[];if(un(e)){let n=t.getBody(e.featureAnchor.hostId);return n&&Sj(n)?[n]:[]}let n=[];if(Sj(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 bz=1e-6;function xz(e){return e.data.name??e.data.id}var Sz=class{armedProbeId=null;noticeShown=!1;coverage=new Map;pending=new Set;constructor(e,t){this.clock=e,this.notices=t}windowsOf(e){let t=this.coverage.get(e);if(t)return t;this.pending.has(e)||(this.pending.add(e),hx(e).catch(t=>(console.warn(`[coverage] ${e}: no coverage to arm the clock with:`,t),[])).then(t=>this.coverage.set(e,t)).finally(()=>this.pending.delete(e)))}sync(e,t){let n=e?.data.orbitalSource===W.SPICE_PROBE?e:void 0,r=n&&this.windowsOf(n.data.id)?.find(([e,n])=>t>e&&t<n);if(!n||!r){this.disarm();return}this.armedProbeId!==n.data.id&&(this.dismissNotice(),this.armedProbeId=n.data.id);let i=r[1]-bz,a=r[0]+bz;this.noticeShown&&t>a&&t<i&&this.dismissNotice(),this.clock.setBoundaryStops({forwardJd:Number.isFinite(i)?i:null,backwardJd:Number.isFinite(a)?a:null,onHit:e=>this.onHit(n,e,i)})}onHit(e,t,n){this.notices.notify({topic:`coverage-pause`,name:xz(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)}},Cz=class{group=new Ba;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()}},wz=Math.PI/180;function Tz(e){return`latitude`in e}function Ez(e,t){let n=e*wz,r=t*wz;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function Dz(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 Oz(e,t,n){return t.place(e,n)}function kz(e,t,n,r){let[i,a,o]=n;if(Tz(e)){let n=Q(gn(t.data)+(e.altitudeKm??0)),[s,c,l]=Ez(e.latitude,e.longitude),u=t.orientation?wT(t.orientation,r,t.nutPrec):null;if(!u)return[i+s*n,a+c*n,o+l*n];let d=[0,0,0];return Dz(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]=vI(s);return[i+c,a+l,o+u]}function Az(e,t,n){let r=t.getBody(e.body),i=r&&Oz(r,t,n);return i?kz(e,r,i,n):null}function jz(e,t,n,r){let i=n.getBody(e.body),a=i&&Oz(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 Mz(e){let t=ag/10;return[e[0]*t,-e[2]*t,e[1]*t]}function Nz(e,t,n){let r=Az(e.position,t,n),i=Az(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 Pz=.02,Fz=1e-4;function Iz(e){return e?.4:.05}function Lz(e,t,n,r,i){let a=e.position.length();if(!(a>0))return{rotate:1,translate:1};let o=$E(n)?void 0:n,s=a;for(let n of[o,i?void 0:r]){let r=n?.position;if(!n||!r)continue;let i=Q(gn(n.data));if(!(i>0))continue;let a=Math.hypot(e.position.x-(r[0]-t[0]),e.position.y-(r[1]-t[1]),e.position.z-(r[2]-t[2]));s=Math.min(s,a-i)}let c=o?Q(gn(o.data)):0,l=Math.tan(Hi.degToRad(e.getEffectiveFOV())/2);return{rotate:Rz(c>0?(a-c)*l/(Math.PI*c):1,Fz),translate:Rz(s/a,Pz)}}function Rz(e,t){return Math.min(1,Math.max(t,e))}var zz=Math.PI/180;function Bz(e,t){let n=e*zz,r=t*zz;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function Vz(e,t,n,r){let i=document.createElement(`div`);i.className=`user-location-marker`;let a=new rO(i),[o,s,c]=Bz(n,r);return a.position.set(o*t,s*t,c*t),e.add(a),a}function Hz(e){e.parent?.remove(e),e.element.remove()}var Uz=new J;function Wz(e,t,n){if(!e)return;let r=t.get(m_);if(!r?.mesh)return;Uz.copy(e.position).applyQuaternion(r.mesh.quaternion);let i=Uz.x,a=Uz.y,o=Uz.z,s=r.root.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 Gz=-1,Kz=1.2,qz=Q(1e6),Jz=.02,Yz=2,Xz=2.3,Zz=.9,Qz=new J,$z=.25,eB=10,tB=4,nB=4,rB=28,iB=.02,aB=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=IN();pointClouds;systemData;positionDiagnostics=new HL;placer;clickables=[];meshToBody=new Map;hoveredBodyIds=new Set;cullFrameCounter=0;hideCappedMoonLabels=!1;focusController;coverageWatch=null;outOfRange;extensions=new Cz;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 zd;_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:qR};lastUpdatedJd=NaN;get placedJd(){return this.lastUpdatedJd}lastUpdatedSystemId=null;lastSeatConfigKey=null;lastProbeVersion=0;disposed=!1;lastDataVersion=-1;dateHolds=0;focusWasOutOfRange=!1;seekAwaitsData=!1;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 Ui;unsubscribeBodiesAdded=null;_trailView={camX:0,camY:0,camZ:0,tolAngle:0};viewportH=1;tier=Yx();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 Yu;appearances=new CM;shadowLight;ambientLights;get sunPointLight(){return this.bodyObjects.get(p_)?.root.children.find(e=>e instanceof fd)}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 AL(o.notices),this.labelContainer=n;let s=ew(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 Tj(c.x,c.y),this.modelScene=new Ja,this.modelScene.environment=XC(this.renderer),this.modelScene.environmentIntensity=qC,this.modelCamera=new cd(60,1,.01,1e3),this.modelScene.add(this.modelCamera);let l=new gd(16777215,GC);this.modelScene.add(l),this.ambientLights=[s.ambientLight,l],this.modelLight=new hd(16777215,KC),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 js(new eu(40,40),new au({opacity:.55})),this.modelShadowPlane.receiveShadow=!0,this.modelShadowPlane.visible=!1,this.modelScene.add(this.modelShadowPlane),this.skyboxAdjuster=new yP(this.scene),this.skyDebugMarkers=new LP(this.scene),this.haloDebug=new KP(this.canvas),this.travelPath=new YI(this.scene,this.canvas),this.travelPath.setLayer(e.MAP_LAYER),this.orbitPreview=new eL(this.scene),this.orbitPreview.setLayer(e.MAP_LAYER),this.skyboxAdjuster.set(0,0,0),pS(this.scene,this.renderer,r,()=>this.disposed),this.placer=new VL(r,this.bodyObjects,this.positionDiagnostics),r.placer=this.placer;let u=[r.getBody(a.id),r.bodies.majorBodies.find(e=>e.data.id===uC),r.bodies.majorBodies.find(e=>e.data.id===p_)].find(e=>e&&this.placer.place(e,this.clock.jd)),d=u?.position??oL;this.focus.focusTruePos=[...d],this.focus.focusOriginWorld=[...d],this.focus.focusTargetWorld=[...d],this.focus.focusStartTime=-qR,this.pointClouds=new TF(r,this.scene,this.bodyObjects,this.circleTexture,this.focus,e.MAP_LAYER,()=>this.rebuildTrailBasis()),this.pointClouds.seedBasis(d),this.pointClouds.setPointBudget(this.tier.pointBudget),this.controls=new LS(this.camera,t),this.controls.enableDamping=!0,this.controls.dampingFactor=Iz(jx().resolvedReducedMotion),this.controls.minDistance=u?uz(u):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 nO(this.camera,this.controls,r,e=>this.isLanded(e)),this.systemData=new _P(this.scene,r,this.renderer,this.textureLoader,this.bodyObjects,i,()=>this.focusController.reapplyInitialViewIfPending()),this.focusController=new vz({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()},u,this.hoveredBodyIds,this.circleTexture,this.renderer),this.coverageWatch=new Sz(i,o.notices);let f=u?.data.id===a.id?a:{latitude:45,longitude:0,zoom:15},p=oC([0,0,0],f.latitude,f.longitude,f.zoom,this.focusController.focusedBodyQuat());this.camera.position.set(...p),this.focusController.setPendingInitialView({latitude:f.latitude,longitude:f.longitude,zoom:f.zoom}),u&&r.visibility.setFocused(u),r.visibility.updateCamera(f.zoom,this.clock.jd),o.onFocusChange(u),this.buildScene(),u&&this.focusController.promotion.ensureBodyObjects(u),u&&this.focusController.syncUpgradeTargets(u),this.repositionAll(),u&&this.maybeLoadTexture(u),this.systemData.syncToFocus(),this.focusController.readerFocusFilter=this.readerMayFocus,this.gpuPick=new WD(this.renderer,this.camera),this.pointerInteraction=new zD(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(){xj(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)))(()=>{pP(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.whereBody(t);if(!r)return;let i=this.focus.focusTruePos,a=r[0]-i[0]-this.camera.position.x,o=r[1]-i[1]-this.camera.position.y,s=r[2]-i[2]-this.camera.position.z,c=Math.hypot(a,o,s);c>n*1.35&&c<n*45||(this.previewFlyBodyId=e.bodyId,this.focusController.focusOnBody(e.bodyId,n*4))}refreshOrbitPreview(){this.orbitPreview.isEmpty||(this.orbitPreview.reposition(e=>this.where(e),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.where(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,this.focus.focusTruePos,e=>this.where(e)),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.where(e);if(!n)return;let[r,i,a]=vI(t);this.travelFocus={centerId:e,local:[r,i,a]};let o=this.travelFocusWorld(n);o&&this.focusController.focusOnPoint(o)}trackPathPoint(e,t){if(!this.travelFocus){this.focusOnPathPoint(e,t);return}let[n,r,i]=vI(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.where(this.travelFocus.centerId);if(!e)return;let t=this.travelFocusWorld(e);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.where(e.centerId),r=n?this.travelFocusWorld(n):null;if(!r)return;let i=null;for(let e of t.stops){let t=this.ctx.getBody(e.bodyId),n=t&&this.whereBody(t);if(!t||!n)continue;let a=this.ctx.visibility.resolveSystemId(t);if(!a)continue;let o=this.ctx.visibility.systemReachAU(a);if(!(o>0))continue;let s=B_(r,n)/10;!i&&s<=o?i=a:s<=o*2?this.systemData.prefetch(a):this.systemData.discardPrefetch(a)}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()}checkDrawnArePlaced(){for(let e of this.bodyObjects.values()){if(e.body.position)continue;let t=e.root.visible?`root`:e.trail?.visible?`trail`:e.model?.parent===this.modelScene?`model`:null;t&&this.positionDiagnostics.warnOnce(`drawn-unplaced`,e.body.data.id,()=>`[scene] ${e.body.data.id} has no place (${e.body.unplaced}) and its ${t} is drawn`)}}placeOf(e){return this.applyJdUpdate(),this.whereBody(e)}panCameraTo(e,t){return this.disarmLimits(),this.focusController.panCameraToBody(e,t),this.focus.focusDurationMs}where(e){return this.placer.at(e,this.clock.jd)}whereBody(e){return this.placer.place(e,this.clock.jd)}repositionBodies(){let[e,t,n]=this.focus.focusTruePos;for(let r of this.bodyObjects.values()){let i=r.body.position;i&&r.root.position.set(i[0]-e,i[1]-t,i[2]-n)}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){HF(i.body,a,o,e,this.clock.jd);continue}let s=a.userData.trailLocalPositions;if(!s)continue;let c=a.userData.orbitCenter;UF(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():nz(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=I_(a.data.parentId),t=e?this.ctx.getBody(e):void 0,n=!!this.bodyObjects.get(a.data.id)?.isLanded||un(a);t&&dz(this.camera,t,this.focus.focusTruePos,this.surfaceClamp(t,n)),AD(this.bodyObjects.get(a.data.id))&&dz(this.camera,a,this.focus.focusTruePos,this.surfaceClamp(a,!1)),this.setMotionScale(Lz(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=iI(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(),rL(this.bodyObjects,this.focus,this.lastUpdatedJd,this.trailView()),qL(this.bodyObjects,this.focus.focusTruePos,jx().realisticLighting,jx().overexposeRings,this.camera.position,this.pxPerRad()),CR(this.bodyObjects,this.focus.focusTruePos);let s=xR(this.bodyObjects,this.camera.position,jx().showAtmospheres,jx().realisticLighting,this.sunIntensityScale,KO(),this.clock.jd);rk(r,s.shellProminent),this.scene.backgroundIntensity=s.skyboxIntensity,this.applyLayerChrome();let c=this.bodyObjects.get(p_);c&&pA(c.corona,c.starPoint,s.sunTint);let l=jx().highAmbient?1:GC;if(!jx().highAmbient&&jx().realisticLighting){let e=this.bodyObjects.get(p_)?.body.position;if(e&&this.ctx.visibility.activeSystemId){let[t,n,r]=this.focus.focusTruePos;l*=JC(Math.hypot(e[0]-t,e[1]-n,e[2]-r))}}for(let e of this.ambientLights)e.intensity=l;Wz(this.userLocationMarker,this.bodyObjects,this.camera);let u=oN(this.focusController.current,this.bodyObjects);KR(this.bodyObjects,this.camera,this.renderer,this.ctx,this.textureLoader,u,this.clock.jd,this.appearances,this.invalidate),WR(this.bodyObjects,this.camera,this.renderer,this.ctx,u),TR(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(kC())return;let t=this.focusController.current,n=t?oN(t,this.bodyObjects):void 0,r=n?this.bodyObjects.get(n):void 0,i=r?.radiusScene??0,a=e,o=r?.body.position;if(t&&o&&n!==t.data.id){let[e,t,n]=this.focus.focusTruePos,[r,i,s]=o,c=this.camera.position;a=Math.hypot(e+c.x-r,t+c.y-i,n+c.z-s)}let s=this.tightFar?Xz:Yz;this.tightFar=i>0&&this.ctx.visibility.activeSystemId!==null&&a<i*s}updateDepthFar(){if(kC())return;let e=ZC,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(p_);if(this.tightFar){let e=this.bodyObjects.get(t)?.body.position;if(e){let o=Math.hypot(e[0]-n,e[1]-r,e[2]-i)+this.ctx.bodies.getSystemExtent(t)*10*2;a=Math.max(a,o*o)}}else s?.body.position&&o(s.body.position);for(let e of this.bodyObjects.values()){let t=e.body.position;t&&this.ctx.visibility.hasFullRendering(e.body)&&o(t)}e=Math.min(ZC,Math.max(qz,Math.sqrt(a)*Kz))}Math.abs(e-this.camera.far)>this.camera.far*Jz&&(this.camera.far=e,this.camera.updateProjectionMatrix())}updateSunProxy(e){let t=this.bodyObjects.get(p_),n=t?.body.position;if(!t||!n)return;let[r,i,a]=this.focus.focusTruePos,[o,s,c]=n,l=o-r,u=s-i,d=c-a;if(e){let t=this.camera.position,n=this._tmpV3.set(l-t.x,u-t.y,d-t.z),r=n.length();n.divideScalar(r);let i=Qz.copy(e.up).addScaledVector(n,-e.up.dot(n));i.lengthSq()>1e-12&&(n.addScaledVector(i.normalize(),e.angleRad).normalize(),l=t.x+n.x*r,u=t.y+n.y*r,d=t.z+n.z*r)}let f=1;if(this.tightFar){let e=this.camera.far*Zz,t=Math.hypot(l,u,d);t>e&&(f=e/t)}f===1&&this.sunProxyK===1&&!e||(this.sunProxyK===1&&(this.sunBaseMeshScale=t.mesh?.scale.x??1,this.sunBaseCoronaScale=t.corona?.scale.x??0),t.root.position.set(l*f,u*f,d*f),t.mesh?.scale.setScalar(this.sunBaseMeshScale*f),t.corona?.scale.set(this.sunBaseCoronaScale*f,this.sunBaseCoronaScale*f,1),this.sunProxyK=f)}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=FM(t*Math.PI/180,n*Math.PI/180);return rN(this.bodyObjects.get(e),e,gn(r.data),i)}surfaceClamp(e,t){let n=this.bodyObjects.get(e.data.id);if(AD(n))return{invQuat:n.model.quaternion.clone().invert(),seated:t,outerRadiusKm:MD(n),centerOffsetScene:jD(n),radialKm:e=>kD(n,e)};if(!(!t||!e.orientation))return{invQuat:wT(e.orientation,this.clock.jd,e.nutPrec).invert(),seated:t,radialKm:t=>rN(n,e.data.id,e.data.radiusKm,t)}}updateModelMounts(){let e=!1;for(let t of this.bodyObjects.values())if(t.model&&$E(t.body)&&sO(t)){e=!0;break}this.overlayActive=e;for(let t of this.bodyObjects.values()){let n=t.model;if(!n)continue;let r=sO(t),i=t.modelRoot;if(!i){r&&n.parent!==this.modelScene?this.modelScene.add(n):!r&&n.parent&&n.removeFromParent();continue}if(e&&r)n.parent!==this.modelScene&&this.modelScene.add(n);else if(n.parent!==i){i.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=aD(e);t.scale.setScalar(n);let r=this.shadowLight.intensity>0;if(this.shadowLight.castShadow=r,!r)return;let i=this.bodyObjects.get(p_)?.body.position,a=e.body.position;if(!i||!a)return;this._tmpSun.set(i[0]-a[0],i[1]-a[1],i[2]-a[2]).normalize(),this.shadowLight.position.copy(e.root.position).addScaledVector(this._tmpSun,eB*n),this.shadowLight.target.position.copy(e.root.position);let o=this.shadowLight.shadow.camera;o.left=o.bottom=-tB*n,o.right=o.top=tB*n,o.near=nB*n,o.far=rB*n,o.updateProjectionMatrix(),this.shadowLight.shadow.normalBias=iB*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.root.position);let n=this._tmpV3.length(),r=aD(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||!sO(t))continue;let i=aD(t)/r,o=n.userData.fitScale??1;n.scale.setScalar(o*i),n.position.subVectors(t.root.position,e.root.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(p_)?.body.position,s=e.body.position,c=1;if(o&&(this._tmpSun.set(o[0]-s[0],o[1]-s[1],o[2]-s[2]),jx().realisticLighting&&(c=JC(this._tmpSun.length())),this._tmpSun.normalize(),this.modelLight.position.copy(this._tmpSun).multiplyScalar(10)),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 l=vE(this._tmpV3,this._tmpV3)*c;this.modelLight.intensity=KC*l*this.sunIntensityScale,this.modelScene.environmentIntensity=qC*l,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=$z/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 aC([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?Gz:Tn.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||fz(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,r=e?.position;return r?[n.x+t[0]-r[0],n.y+t[1]-r[1],n.z+t[2]-r[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&&Nz(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&&(yM(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&&(TT(t.mesh,e.orientation,this.clock.jd,e.nutPrec),this.focusController.reapplyInitialViewIfPending())}),lD(t,this.modelScene,this.ctx).then(()=>{if(this.focusController.current?.data.id===t.body.data.id&&(this.controls.minDistance=uz(t.body,ND(t))),!this.ctx.layers.skipped.has(`nomenclature`))return mN(t,this.canvas,(e,n,r,i)=>{this.featureSelectEnabled&&this.callbacks.onFeatureSelect?.(t.body.data.id,e,n,r,i)})}).then(()=>{this.selectedFeatureId!==null&&vN(t,this.selectedFeatureId)}))}reapplyBodyLayers(){let e=this.focusController.current;if(!e)return;let t=this.bodyObjects.get(e.data.id);t&&(fD(t),xM(t),this.maybeLoadTexture(e))}setSelectedFeature(e){this.selectedFeatureId=e;let t=oN(this.focusController.current,this.bodyObjects),n=t?this.bodyObjects.get(t):void 0;n&&vN(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&&!un(e))return null;let t=I_(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`}|${WM()}`}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),ux(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,Fg(this.clock.jd));return}this.focusController.promotion.ensureBodyObjects(i),this.focusController.syncUpgradeTargets(e)}holdDate(){this.dateHolds++;let e=!0;return()=>{e&&this.dateHolds--,e=!1}}applyJdUpdate(e=!1){if(this.dateHolds>0)return;this.ensureFocusedProbeTarget();let t=this.ctx.visibility.focusedSystemId,n=this.focusedSeatConfigKey(),r=this.ctx.probeStore?.version??0,i=this.ctx.bodies.dataVersion+(this.ctx.chebStore?.version??0);if(this.clock.jd===this.lastUpdatedJd&&t===this.lastUpdatedSystemId&&n===this.lastSeatConfigKey&&r===this.lastProbeVersion&&i===this.lastDataVersion){this.clock.seeked=!1;return}let a=this.clock.seeked||this.seekAwaitsData;this.clock.seeked=!1,this.lastUpdatedJd=this.clock.jd,this.lastUpdatedSystemId=t,this.lastSeatConfigKey=n,this.lastProbeVersion=r,this.lastDataVersion=i,this.ctx.refreshTick(Fg(this.clock.jd)),this.focusController.promotion.onSimTimeChanged();let o=nL({jd:this.clock.jd,ctx:this.ctx,bodyObjects:this.bodyObjects,focus:this.focus,focusedBody:this.focusController.current,placer:this.placer,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(),this.seekAwaitsData=a&&o.focusLoading;let s=o.focusUnplaced&&!this.focusWasOutOfRange;if(this.focusWasOutOfRange=o.focusUnplaced,e&&a&&s&&o.anchorId){let e=this.ctx.getBody(o.anchorId);e&&this.focusController.panCameraToBody(e)}}setReducedMotion(e){this.controls.dampingFactor=Iz(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),o=a&&this.whereBody(a);if(!a||!o)return 0;this.focusController.clearPendingInitialView();let s=oN(this.focusController.current,this.bodyObjects)===e.hostId,c=fC(e,t);this.ctx.bodies.focusFeature=c;let l=this.bodyObjects.get(a.data.id);this.selectedFeatureId=e.featureId,l&&vN(l,e.featureId);let u=this.whereBody(c);if(!u)return 0;let d=this.focusController.focusedBodyQuat(c);if(r===`pan`){let e=aC(this.focusController.cameraTruePos(),u,d);return this.callbacks.onCameraPosition?.(e.latitude,e.longitude,e.distance),this.focusController.setFocusTarget(c),this.focus.focusDurationMs}let f=u[0]-o[0],p=u[1]-o[1],m=u[2]-o[2],h=Math.hypot(f,p,m);h>1e-9?(f/=h,p/=h,m/=h):(f=0,p=1,m=0);let g=r===`snap`&&i?oC(u,i.latitude,i.longitude,i.zoom,d):[u[0]+f*n,u[1]+p*n,u[2]+m*n],_=aC(g,u,d);if(this.callbacks.onCameraPosition?.(_.latitude,_.longitude,_.distance),r===`snap`){this.focusController.setFocusTarget(c,g);let e=this.focus;return e.focusTruePos=[...u],e.focusOriginWorld=[...u],e.focusTargetWorld=[...u],e.focusStartTime=-qR,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(g[0]-u[0],g[1]-u[1],g[2]-u[2]),this.controls.update(),0}if(s){let e=this.focusController.cameraTruePos();this.focusController.setFocusTarget(c),this.focus.focusTruePos=[...u],this.camera.position.set(e[0]-u[0],e[1]-u[1],e[2]-u[2]),this.repositionAll(),this.pointClouds.rebuildBasis(),iz(this.focus,this.camera,e,g,jx().resolvedReducedMotion)}else this.focusController.setFocusTarget(c,g),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||!sO(e))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=e=>e?.model&&sO(e)?e:null,t=this.focusController.current;if(!t){let t=this.travelFocus?.centerId;return e(t?this.bodyObjects.get(t):void 0)}let n=un(t)?t.featureAnchor.hostId:t.data.id,r=this.bodyObjects.get(n);return e(r)||(t.data.orbitalSource===W.SPICE_PROBE&&!r?.isLanded?e(this.bodyObjects.get(t.data.parentId)):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 ZP({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:$E(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 Ba,t=new J(0,0,0),n=(n,r,i,a)=>{let o=new Kd(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 ls(new Yo({map:new Pc(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=ub(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&&Fk(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(m_);n?.mesh&&(this.userLocationMarker&&Hz(this.userLocationMarker),this.userLocationMarker=Vz(n.mesh,n.radiusScene,e,t))}clearUserLocation(){this.userLocationMarker&&=(Hz(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(Xx()),this.composer.setPixelRatio(Xx()),this.resize(this.canvas.clientWidth,this.canvas.clientHeight),pS(this.scene,this.renderer,this.ctx,()=>this.disposed),this.resume()}recoverWorkersIfDead(e){return this.pointClouds.recoverWorkersIfDead(e)}applyRenderTier(){this.tier=Yx();let e=Xx();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),BC(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&&fD(e);this.pointClouds.dispose(),this.disposeScene(this.scene),this.disposeScene(this.modelScene),oB(this.scene.background),oB(this.scene.environment),oB(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))oB(t);e.dispose()}})}};function oB(e){e&&typeof e==`object`&&e.isTexture&&e.dispose()}var sB=Ze({progress:null,bootPending:!1}),cB=6371;function lB(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 uB={topAltitudeKm:67,rayleighScatterPerKm:[.0058,.0136,.0331],rayleighScaleHeightKm:8.4,mieScatterPerKm:[.004,.004,.004],mieAbsorptionPerKm:[4e-4,4e-4,4e-4],mieScaleHeightKm:1.2,miePhase:lB(.75),absorptionPerKm:[65e-5,.001881,85e-6],absorptionCenterKm:25,absorptionWidthKm:15,bakedCompensation:1,multiScatterGain:.3,sunIntensity:5,sunColor:[1,1,1]},dB=1.6,fB=1.0005,pB=new J(.55,.25,.8).normalize(),mB=[`low`,`medium`,`high`,`ultra`],hB=4,gB=12,_B=10,vB=16,yB=5;function bB(e){return!e.limb&&!e.sky?NaN:Math.max(e.limb?.medianMs??0,e.sky?.medianMs??0)}function xB(e,t){let n=`low`;for(let r of e.tiers){let e=bB(r);!Number.isNaN(e)&&e<=t&&(n=r.tier)}return n}var SB=new Set([`WebKit WebGL`,`Mozilla`,``]);function CB(e){let t=e.getContext(),n=String(t.getParameter(t.RENDERER)??``);if(!SB.has(n))return n;let r=t.getExtension(`WEBGL_debug_renderer_info`);return r?String(t.getParameter(r.UNMASKED_RENDERER_WEBGL)):n}function wB(e,t){let n=e.getContext(),r=new Ja,i=new cd(50,n.drawingBufferWidth/Math.max(n.drawingBufferHeight,1),.005,100),a=new hu({color:7829367,roughness:1,metalness:0}),o=new js(new iu(1,64,64),a);o.renderOrder=1,r.add(o);let s=new hd(16777215,2);s.position.copy(pB),r.add(s);let c=uB,l=Dk(c,1,cB),u=l.material.uniforms;u.uSunDir.value.copy(pB),u.uSunIntensity.value=c.sunIntensity,r.add(l.mesh);let d=e=>{let t=e===`sky`;t?(i.position.set(0,fB,0),i.lookAt(1,fB+.1,0)):(i.position.set(0,0,dB),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}={})=>{Pk(l,UO[e]),d(t);let i=0;for(let e=0;e<hB;e++)r?.(`warmup`,e+1),await p(),i=m(1);let a=Math.min(vB,Math.max(1,Math.ceil(_B/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<gB;e++)if(r?.(`measure`,e+1),await p(),o.push(m(a)),n!==void 0&&o.length>=yB){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(),Rk(l)}}}function TB(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 EB(e,t){let n=t.tiers??mB,{budgetMs:r,signal:i,onProgress:a}=t,o=Math.max(0,n.indexOf(t.startTier??n[n.length-1])),s=wB(e,i),c=hB+gB,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`?hB: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`?gB:hB,fraction:u})}}),f=new Map,p=new Map,m=async e=>{let t=n[e];if(UO[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 TB(e,n,f,p)}var DB=60,OB=100,kB=3e4,AB=25e4,jB=`v1`,MB=!1,NB=null,PB=Promise.resolve();function FB(e){let t=e.getContext(),n=Math.round(t.drawingBufferWidth*t.drawingBufferHeight/AB);return`${CB(e)}|${n}|${jB}`}function IB(){MB||typeof window>`u`||(MB=!0,sB.bootPending=!0,PB=new Promise(e=>{let t=()=>{sB.bootPending=!1,e()};setTimeout(t,kB),setTimeout(()=>void RB(!1).finally(t),OB)}))}function LB(){return PB}function RB(e){return NB??=zB(e).finally(()=>NB=null),NB}async function zB(e){let t=jx();if(!e&&(t.atmosphereQuality!==`auto`||!t.showAtmospheres))return;let n=null;try{n=new fh({canvas:document.createElement(`canvas`),antialias:!0}),n.setPixelRatio(Wx()),n.setSize(window.innerWidth,window.innerHeight,!1);let r=FB(n);if(!e&&t.atmosphereCalibration?.key===r)return;sB.progress=0;let i=await EB(n,{budgetMs:1e3/DB,startTier:WO(),onProgress:e=>sB.progress=e.fraction}),a={};for(let e of i.tiers){let t=bB(e);Number.isNaN(t)||(a[e.tier]=Math.round(t*100)/100)}let o=xB(i,1e3/DB);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{sB.progress=null,n?.dispose(),n?.forceContextLoss()}}var BB=class{object=new Ba;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 rO(e.element);let[n,r]=e.align??[.5,.5];this.label.center.set(n,r),this.object.add(this.label),this.object.matrixAutoUpdate=!1,VO(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?Az(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=jz(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()}},VB=3,HB=new J,UB=new J,WB=new J;function GB(e){let[t,n=t]=(e??``).split(/[\s,]+/).filter(Boolean).map(Number);return t>0&&n>0?[t,n]:null}function KB(e,t){return HB.set(1,0,0).applyQuaternion(e.quaternion),UB.set(0,1,0).applyQuaternion(e.quaternion),WB.set(0,0,-1).applyQuaternion(e.quaternion),t/(2*Math.tan(e.getEffectiveFOV()*Math.PI/360))}function qB(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*HB.x+a*HB.y+o*HB.z,r[1]=i*UB.x+a*UB.y+o*UB.z,r[2]=i*WB.x+a*WB.y+o*WB.z}function JB(e,t,n){WB.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)*WB.x+(e[o*3+1]-i)*WB.y+(e[o*3+2]-a)*WB.z<n.near*2)return!0;return!1}function YB(e,t,n,r,i){let a=KB(n,r),o=[0,0,0],s=0,c=0,l=0,u=!1;for(let r=0;r<t;r++){if(qB(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 XB=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=KB(r,i),o=i*r.aspect*VB/2,s=i*VB/2,c=r.near*2,{a:l,b:u}=this,d=!1,f=0,p=0,m=0;n>0&&qB(e,0,r,l);for(let i=0;i+1<n;i++,[l,u]=[u,l]){qB(e,i+1,r,u);let n=0,h=1;for(let e=0;e<5&&n<=h;e++){let t=ZB(e,l,a,o,s,c),r=ZB(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 ZB(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 QB=1e-9,$B=class{object=new Ba;anchor;color;widthPx;opacity;dash;fade;closed;local;count=0;mesh=null;scratch=new Float32Array;alphas=new Float32Array;seen=new XB;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=GB(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?Az(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])>QB||Math.abs(o[1]-this.lastOrigin[1])>QB||Math.abs(o[2]-this.lastOrigin[2])>QB;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||JB(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),tP(this.mesh.geometry,e.points,e.alphas,e.alphas,e.count),this.dash&&iP(this.mesh.geometry,e.lengths,e.count)}else s&&tP(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=aP(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 eV(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=tV(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,tV(n,a)]}function tV(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 nV(e,t={}){let[n,r]=eV(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 rV(e){if(e.length<3)return[];let[t,n]=eV(iV(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 Zl.triangulateShape(r,[]).flat()}function iV(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 aV(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 oV([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 oV(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 sV(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]]:oV([n,r,i])}function cV(e,t){return new pu({transparent:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:new X(e)},uOpacity:{value:t},uCenterOffset:{value:new J}},vertexShader:`
5666
+ `;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 PP(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 Uo;c.setAttribute(`position`,new jo(o,3));let l=new Tc(c,new fc({color:r,transparent:!0,opacity:.55}));return l.frustumCulled=!1,l}function FP(){let e=new Ba;e.name=`sky-debug-markers`,e.visible=!1;let t=new J;for(let n of TP){MP(n.raDeg,n.decDeg,t).multiplyScalar(wP);let r=new rO(NP(n));r.center.set(0,.5),r.position.copy(t),e.add(r)}for(let t of jP){let n=PP(t.zero,t.pole,wP*.999,t.color,AP);n.name=t.name,e.add(n)}return e}function IP(e){e.traverse(e=>{e instanceof rO&&e.element.remove(),e instanceof Tc&&(e.geometry.dispose(),e.material.dispose())}),e.parent?.remove(e)}var LP=class{group=null;constructor(e){this.scene=e}setVisible(e){e?(this.group||(this.group=FP(),this.scene.add(this.group)),this.group.visible=!0):this.group&&=(IP(this.group),null)}},RP=new J,zP=new J,BP=new J,VP=[RP,zP,BP];function HP(e,t,n){return RP.set(1,0,0).applyQuaternion(e).transformDirection(t),zP.set(0,1,0).applyQuaternion(e).transformDirection(t),BP.set(0,0,1).applyQuaternion(e).transformDirection(t),{e:VP,a:n}}function UP(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 WP(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 GP(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 KP=class{canvas=null;gfx=null;tmp=new J;tmpQ=new Ui;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,l=o.body.position;if(!e||c<=0||!l)continue;let[u,d,b]=l;this.tmp.set(u-m,d-h,b-g).applyMatrix4(p);let x=this.tmp.x,S=this.tmp.y,C=this.tmp.z;if(C>=0||x*x+S*S+C*C<=c*c)continue;let w=aO(this.items,y++,qP),T=!!(o.semiAxesScene&&o.mesh);if(T){let e=HP(o.mesh.getWorldQuaternion(this.tmpQ),p,o.semiAxesScene);w.e0.copy(e.e[0]),w.e1.copy(e.e[1]),w.e2.copy(e.e[2]),w.sa[0]=e.a[0],w.sa[1]=e.a[1],w.sa[2]=e.a[2],WP(w.occ,x,S,C,e,f,_,v,o.body.data.id,o.cachedDist)}else w.e0.set(1,0,0),w.e1.set(0,1,0),w.e2.set(0,0,1),w.sa[0]=w.sa[1]=w.sa[2]=c,UP(w.occ,x,S,C,c,f,_,v,o.body.data.id,o.cachedDist);let E=C*C-c*c,D=E<=0,O=D?0:c*f/Math.sqrt(E),k=D||O>=16;this.tmp.set(u-m,d-h,b-g).project(t),w.cx=(this.tmp.x*.5+.5)*i,w.cy=(-this.tmp.y*.5+.5)*a,vO(o,t,n,i,a,this.labelRect),w.hx=this.labelRect.x,w.hy=this.labelRect.y,w.id=o.body.data.id,w.camX=x,w.camY=S,w.camZ=C,w.worldR=c,w.dist=o.cachedDist,w.isEllipsoid=T,w.degenerate=D,w.isOccluder=k,w.meshHidden=!s.visible,w.labelVisible=e.visible,w.maximized=o.labelMaximized!==!1,w.focused=o.body.data.id===r,w.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,gO(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(),XP(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)}}YP(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 qP(){return{id:``,camX:0,camY:0,camZ:0,worldR:0,e0:new J,e1:new J,e2:new J,sa:[0,0,0],occ:uO(),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 JP=[[`#1ae5ff`,`label shown`],[`#ffe11a`,`dimmed`],[`#ff3b3b`,`hidden`],[`#ff8c1a`,`occluder silhouette`],[`#7dff7d`,`focused`]];function YP(e,t){let n=t-8-(JP.length-1)*13;e.font=`10px monospace`,e.textBaseline=`middle`;for(let[t,r]of JP)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 XP(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 ZP(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 QP="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",$P=typeof self<`u`&&self.Blob&&new Blob([`URL.revokeObjectURL(import.meta.url);`,QP],{type:`text/javascript;charset=utf-8`});function eF(e){let t;try{if(t=$P&&(self.URL||self.webkitURL).createObjectURL($P),!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(QP),{type:`module`,name:e?.name})}}var tF=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 eF;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 Vg(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}]},Ug(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()}},nF=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 vh(n[e-t]);return null}clear(){this.#t.clear(),this.#e=1}},rF=.01,iF=[`asteroid`,`spacecraft`],aF=.0002959122082855911,oF=.75,sF=Q(8*86400);function cF(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(aF/i*((1+o)/(1-o)));s>t&&(t=s)}return{maxSpeedScene:t*10,alwaysSolve:n}}function lF(e){return e<0?0:e>1?1:e}function uF(e,t){return t===`*`?e.startsWith(`small_bodies/`):e===t}function dF(e){return e===null?{tBright:0,tSize:0}:{tBright:lF((fF-e)/(fF-pF)),tSize:lF((mF-e)/(mF-hF))}}var fF=1e4,pF=500,mF=pF,hF=50,gF=4,_F=.5,vF=10,yF=1,bF=1,xF=3.5,SF=2.5,CF=2,wF=xF,TF=class{orbitPool=new tF;pickRegistry=new nF;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:gF,dim:_F,opacity:bF};emphasizedSmallBodyZone=null;smallBodyEmphasis={sizeMult:1,brightMult:1,opacity:bF};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 iF)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 iF)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)C_(e)===`naif-399`&&this.applyEarthSatEmphasis(t)}computeEarthSatEmphasis(e){let{tBright:t,tSize:n}=dF(e);return{size:gF+(vF-gF)*n,dim:_F+(yF-_F)*t,opacity:bF+(xF-bF)*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)uF(C_(e),n)&&this.resetSmallBodyEmphasis(t);if(e!==null)for(let[t,n]of this.workerPoints.asteroid)uF(C_(t),e)&&this.applySmallBodyEmphasis(n)}computeSmallBodyEmphasis(e){let{tBright:t,tSize:n}=dF(e);return{sizeMult:1+(SF-1)*n,brightMult:1+(CF-1)*t,opacity:bF+(wF-bF)*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=bF,e.userData.smallBodyBaseSize=void 0,e.userData.smallBodyBaseColor=void 0}seedBasis(e){this.basisPos=[...e]}buildInitial(e){let t=mP(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 iF)for(let[t,n]of this.workerPoints[e]){let r=C_(t);n.userData.parentBodyId=this.cloudParentId(e,r),this.emphasiseNewCloud(e,r,n)}this.assignMapLayer()}assignMapLayer(){for(let e of iF)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`?p_:t}emphasiseNewCloud(e,t,n){if(e===`spacecraft`){t===`naif-399`&&this.applyEarthSatEmphasis(n);return}let r=this.emphasizedSmallBodyZone;r!==null&&uF(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=bh(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,cF(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=zN(new Float32Array(l.cols.count*3),0,this.circleTexture,c,LN());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 S_(n,Ev(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=>yh(e.data.id)??ph));await this.orbitPool.rewireOne(c,l,s,(o+r)%t,!1,u),this.armGroupGate(c,{maxSpeedScene:sF,alwaysSolve:!1});let d=this.workerPoints.spacecraft.get(i);if(d){this.resizeGeometryIfNeeded(d.geometry,l);continue}let f=new Float32Array(l.length*3);this.seedColors(f,l);let p=zN(new Float32Array(l.length*3),0,this.circleTexture,`#ffffff`,void 0,f);this.adoptCloud(`spacecraft`,i,c,p,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=C_(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)}seedColors(e,t){let n=new X,r=Math.min(t.length,e.length/3);for(let i=0;i<r;i++)n.set(g_(t[i].data)),e[i*3]=n.r,e[i*3+1]=n.g,e[i*3+2]=n.b}resizeGeometryIfNeeded(e,t){let n=t.length*3;if(e.getAttribute(`position`).array.length!==n){if(e.setAttribute(`position`,new Oo(new Float32Array(n),3)),e.getAttribute(`color`)){let r=new Float32Array(n);this.seedColors(r,t),e.setAttribute(`color`,new Oo(r,3))}e.setDrawRange(0,0)}}resizeGeometryToCount(e,t,n){let r=t*3,i=e.getAttribute(`position`).array;if(n&&e.setAttribute(`color`,new Oo(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 Oo(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 Oo(t.slice(),4,!0))}reposition(){let[e,t,n]=this.focus.focusTruePos,r=this.basisPos;for(let i of iF)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=rF*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(p_)?.position;for(let[i,a]of this.workerPoints.asteroid){if(!r)break;if(!this.ctx.visibility.isAsteroidGroupVisible(C_(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(C_(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;s[0]=o[0],s[1]=o[1],s[2]=o[2],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>=oF}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].position;s[r*3]=a?a[0]-e:NaN,s[r*3+1]=a?a[1]-t:NaN,s[r*3+2]=a?a[2]-n:NaN}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++){let r=n[t].position;i[t*3]=r?r[0]-e[0]:NaN,i[t*3+1]=r?r[1]-e[1]:NaN,i[t*3+2]=r?r[2]-e[2]:NaN}r.geometry.setAttribute(`position`,new jo(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 iF)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()}},EF=Math.PI/180,DF=2451545,OF=1.00000261,kF=.01671123,AF=100.46457166*EF,jF=35999.37244981/36525*EF,MF=102.93768193*EF,NF=.32327364/36525*EF;function PF(e){let t=e-DF,n=MF+NF*t,r=AF+jF*t-n,i=r+(2*kF-kF**3/4)*Math.sin(r)+1.25*kF*kF*Math.sin(2*r);return{lon:n+i,r:OF*(1-kF*kF)/(1+kF*Math.cos(i))}}function FF(e){let t=PF(e).lon;return(e,n)=>{let r=t-PF(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 IF=.01,LF=1/100,RF=1;function zF(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 BF(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 VF(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=zF(c,l,u)}function HF(e,t,n,r,i,a){let o=t.userData,s=o.useTrail,c=o.orbitCenter,l=e.trailAnchor??e.position;if(!l)return;let 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(BF(o,g,u,d,f,p,m,h,a))return;let{posArr:_,trailArr:v,fullArr:y}=oP(t),b=e.lagrangeTrail?FF(i):null,x=cP(e,n,_,c.x,c.y,c.z,r,b??void 0);sP(t,_,v,y,x,!0,s),VF(o,g,u,d,f,p,m,h,_,x,a)}function UF(e,t,n,r,i){let{posArr:a,trailArr:o,fullArr:s,capacity:c}=oP(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){tP(e.geometry,a,o,s,l);return}e.geometry.getAttribute(`position`).needsUpdate=!0}function WF(e,t,n,r,i){let a=t.userData.trailBuffer;if(a){HF(e,t,a,n,r,i);return}let o=t.userData.sourceCurve;if(!o){if(!t.userData.curvePending||!e.orbitElements)return;o=QN(WN(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,p;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=XN(e.data.satrec,r,n,512),t.userData.sourceCurve=o,t.userData.curveJd=a=r),p=o.length-(r<a?2:1)}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*LF,RF)){let n=e.rederiveElements(r);n&&(Object.assign(e.orbitElements,n),o=QN(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)>IF&&(o=QN(WN(e.orbitElements,r),512).points,t.userData.sourceCurve=o,t.userData.curveJd=r)}}let m=e.trailAnchor??e.position;if(!m)return;let h=t.userData,g=u-n[0],_=d-n[1],v=f-n[2],y=m[0]-u,b=m[1]-d,x=m[2]-f;if(BF(h,o,g,_,v,y,b,x,i))return;let S=Jy(e,o,s,u,d,f,p);if(S.length<2)return;let{posArr:C,trailArr:w,fullArr:T,capacity:E}=oP(t),D=u-n[0],O=d-n[1],k=f-n[2],A=Math.min(S.length,E);for(let e=0;e<A;e++)C[e*3]=S[e][0]+D,C[e*3+1]=S[e][1]+O,C[e*3+2]=S[e][2]+k;sP(t,C,w,T,A,s,c),h.trailLocalPositions=S,VF(h,o,g,_,v,y,b,x,C,A,i)}function GF(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 KF(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 qF=4/2,JF=(.1*10)**2,YF=new J,XF=[],ZF=XF;function QF(e){return aO(XF,e,uO)}var $F={x:0,y:0,left:0,right:0,h:0},eI=new Ui,tI={ox:0,oy:0},nI=new J,rI=new J;function iI(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()){let e=n.body.position;if(!e||n.carried){n.cachedDist=1/0;continue}if(n.cachedDist=B_(C,e),n.isCrashed||n.noPhysical){let e=n.noPhysical===`model`,t=lg(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()}KT(n,`missing`,r)}let r=n.label;if(!r)continue;n.labelAnchorOffscreen=!1;let a=n.noPhysical?0:n.radiusScene;if(!a){r.position.set(0,0,0);continue}let[o,s,c]=e;p.set(o-w[0],s-w[1],c-w[2]).applyMatrix4(T);let l=p.x,u=p.y,d=p.z,f=d*d,m=a*a;if(f<=m){r.position.set(0,0,0),n.labelAnchorOffscreen=!0;continue}let h=a/n.cachedDist*S;if(h<1){r.position.set(0,0,0);continue}if(h>=16){let e=n.cachedDist,i=1/e,f=l*i,m=u*i,h=d*i,g=a*i,_=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*e-l,T*e-u,E*e-d).applyQuaternion(t.quaternion),r.position.copy(p),rI.set(o-w[0]+p.x,s-w[1]+p.y,c-w[2]+p.z).project(t),n.labelAnchorOffscreen=Math.abs(rI.x)>1||Math.abs(rI.y)>1;continue}if(n.semiAxesScene&&n.mesh)GP(l,u,d,HP(n.mesh.getWorldQuaternion(eI),T,n.semiAxesScene),S,tI),p.set(tI.ox,tI.oy,0).applyQuaternion(t.quaternion);else{let e=m/(f-m);p.set(e*l,e*u,0).applyQuaternion(t.quaternion)}r.position.copy(p)}let E=XF,D=b*.5,O=x*.5,k=0;for(let t of e.values()){let e=t.noPhysical?0:t.radiusScene,n=t.body.position;if(!e||!n||t.carried)continue;let r=t.cachedDist,[i,a,o]=n,s=t.model?.userData.occluderSpheres;if(t.model&&s?.length){let e=aD(t),n=t.model.position;for(let c of s){let s=c.r*e;if(nI.copy(c.center).applyQuaternion(t.model.quaternion).add(n).multiplyScalar(e),p.set(i-w[0]+nI.x,a-w[1]+nI.y,o-w[2]+nI.z).applyMatrix4(T),p.z>=s||p.lengthSq()<=s*s)continue;let l=p.z*p.z;(l<=s*s||s*S/Math.sqrt(l-s*s)>=16)&&UP(QF(k++),p.x,p.y,p.z,s,S,D,O,t.body.data.id,r)}continue}p.set(i-w[0],a-w[1],o-w[2]).applyMatrix4(T);let c=p.x,l=p.y,u=p.z;if(u>=e)continue;let d=u*u;(d<=e*e||e*S/Math.sqrt(d-e*e)>=16)&&(t.semiAxesScene&&t.mesh?WP(QF(k++),c,l,u,HP(t.mesh.getWorldQuaternion(eI),T,t.semiAxesScene),S,D,O,t.body.data.id,r):UP(QF(k++),c,l,u,e,S,D,O,t.body.data.id,r))}E.length=k;let A=n.visibility.focusedSystemId,j=!1,M=a?oN(n.getBody(a),e):void 0;for(let r of e.values()){let{body:i,group:s,trail:c}=r,l=r.cachedDist,u=sO(r);r.root.visible=u;let d,f,p=i.data.id===a,m=A!==null&&i.data.id===A;if(r.mesh===null&&!vn(i.data.objectType)){let t=i.data.objectType;if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){let t=!0,r=p?void 0:F_(i.data.id);if(r){let a=e.get(r)?.body??n.getBody(r);a?.position&&i.position&&B_(i.position,a.position)/B_(C,a.position)*S<16&&(t=!1)}s.visible=t,c&&(c.visible=t),d=t,f=!1}else{let e=n.visibility.getPlanetVisibility(i,l)!==$.HIDE&&n.visibility.hasFullRendering(i);s.visible=e,c&&(c.visible=e),d=e,f=!1}}else{let e=i.data.objectType===G.MOON,t=e?n.visibility.getMoonVisibility(i):n.visibility.getPlanetVisibility(i,l),r=e?GF(t,o,p):KF(t,n.visibility.hasFullRendering(i),p||m);s.visible=r.groupVisible,c&&(c.visible=r.orbitVisible),d=r.showLabel,f=r.isClose}if(u||(s.visible=!1,d=!1,f=!1),c&&(!u||i.orbitCenter===null)&&(c.visible=!1),r.starPoint&&u){let e=r.radiusScene/l*S,t=e<qF;if(r.starPoint.visible=t,t){let t=r.starPoint.material,n=e/qF,i=Math.max(rA*n*n,3);t.uniforms.uIntensity.value=i}s.visible=!0,f=!t,d=!f}if(r.isMinor&&!p&&c&&!n.visibility.isPinned(i.data.id)&&(c.visible=!1),h&&c?.visible){let e=c.userData.orbitCenter;e&&e.distanceToSquared(YF.set(w[0],w[1],w[2]))>JF&&(c.visible=!1)}_&&c&&(c.visible=!1),s.matrixWorldAutoUpdate=s.visible;let{label:g}=r;if(!s.visible&&g&&g.parent===s?(s.remove(g),g.element.remove()):s.visible&&g&&g.parent!==s&&s.add(g),r.mesh&&r.radiusScene>0){let e=!p&&!m&&r.radiusScene/l*S<.5;e!==r.meshSubPixel&&(r.meshSubPixel=e,e?r.mesh.layers.disable(0):r.mesh.layers.enable(0))}hO(r,d,f,l,S,a)&&(j=!0);let y=r.radiusScene>0?r.radiusScene/l*S:0;ON(r,v&&i.data.id===M,y,t,b,x)}for(let[e,t]of c)t.visible=n.visibility.isAsteroidGroupVisible(C_(e));for(let[e,t]of l)t.visible=n.visibility.isSpacecraftGroupVisible(C_(e));for(let[e,t]of u)t.visible=n.visibility.isMoonGroupVisible(e);if(E.length>0){let n=a?F_(a):null;for(let r of e.values()){if(!r.label?.visible||!vO(r,t,w,b,x,$F))continue;let e=r.body.data.id;gO($F.x,$F.y,r.cachedDist,e,E,e===a?n:null)&&(r.label.visible=!1)}}if((m||j||++d>=3)&&(d=0,jO(e,b,x,t,a,n,s,E,r)),MO(e,b,x,t,r),M){let t=e.get(M);t&&MN(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 aI(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function oI(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function sI(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function cI(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 lI(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-uI(d):p,g=f?m+uI(f):m;if(t<h||t>g)return null;if(a&&d&&t<(c?.jds[0]??n.startJd))return{r:dI(d,t),centerId:a.anchorId};if(c&&t<=c.jds[c.jds.length-1])return{r:fI(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:dI(f,t),centerId:o.anchorId};if(l)return{r:fI(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}=cI(e,v);return{r:fI(y,b,t,x,S),centerId:e.centerId}}function uI(e){return e.jds[e.jds.length-1]-e.jds[0]}function dI(e,t){let n=uI(e),r=e.jds[0],i=n>0?r+((t-r)%n+n)%n:t;return fI(e.points,e.jds,i)}function fI(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 aI(e[a-1],sI(oI(e[a],e[a-1]),s))}var pI=Math.PI/180,mI=Math.cos(og*pI),hI=Math.sin(og*pI);function gI(e,t,n,r){let i=Math.cos(e*pI),a=Math.sin(e*pI),o=Math.cos(t*pI),s=Math.sin(t*pI),c=Math.cos(n*pI),l=Math.sin(n*pI);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 _I(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*mI+a*hI,t=-i*hI+a*mI;i=e,a=t}return[r,i,a]}function vI(e){let t=10/ag;return[e[0]*t,e[2]*t,-e[1]*t]}function yI(e,t,n){let{a:r,e:i,ma:a,n:o,epoch:s,q:c,tp:l}=e,{om:u,w:d}=WN(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=Tg(c,l,t);if(!r)return null;let i=n&&n>0?n:nv,a=r.r*ag,o=2*c*ag;return bI(a,r.nu,o,1,i,d,e.i,u,f)}if(!isFinite(i)||!isFinite(a))return null;let p=r*ag,m=o*pI/rv,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))*pI,_,v;if(i<1||r>0){let e=Math.min(i,.9999999),t=Sg(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=wg(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:bI(v,_,y,i,h,d,e.i,u,f)}function bI(e,t,n,r,i,a,o,s,c){let l=Math.cos(t),u=Math.sin(t),d=Math.sqrt(i/n),f=gI(a,o,s,c),p=_I(e*l,e*u,f),m=_I(-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 xI={cruise:`#7fdbff`,boost:`#ffb454`,brake:`#ff8c69`,spiral:`#c9a0ff`,"spiral-out":`#9b7fd4`,"spiral-in":`#9b7fd4`};xI.cruise,xI.boost,xI.brake,xI.spiral,xI[`spiral-out`],xI[`spiral-in`];var SI={notice:`#8ab4f8`,caution:`#f2b23e`,severe:`#ff6b5a`},CI=3,wI=1,TI=2,EI=.6,DI=1.5,OI=.3,kI=1.5,AI=.85,jI=60,MI=.018,NI=.026,PI=`#ffffff`,FI=4,II=1.5,LI=9,RI=1,zI={notice:FI-3,caution:FI-2,severe:FI-1},BI=[`notice`,`caution`,`severe`],VI=.03,HI=.2;function UI(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 Pc(t)}function WI(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 Pc(t)}function GI(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 KI(e,t){let n=new ls(new Yo({map:e,transparent:!0,sizeAttenuation:!1,depthTest:!1}));return n.scale.setScalar(t),n.renderOrder=FI,n}function qI(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&&(VO(c,i),aN(c,o)),s&&(c.addEventListener(`mouseenter`,()=>s(!0)),c.addEventListener(`mouseleave`,()=>s(!1)));let p=new rO(c);return p.center.set(0,.5),p}function JI(e,t){return e&&[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}var YI=class{group=new Ba;anchored=new Map;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?DI:TI,i?OI:EI,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)=>BI.indexOf(e.severity)-BI.indexOf(t.severity));for(let t of n){let n=SI[t.severity];for(let n of t.bands)e.arcs.forEach((t,r)=>{this.addLine(GI(t,n.startJd,n.endJd,cI(e,r)),SI[n.severity],LI,RI,null,{renderOrder:zI[n.severity]})});if(this.mergeIntoStep(t,n))continue;let r=lI(e,t.startJd);if(!r)continue;let i=vI(r.r),a=r.centerId===e.centerId?null:r.centerId,o=KI(WI(n),VI);this.parentOf(a).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 rO(s);c.center.set(0,.5),this.parentOf(a).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,CI,wI,null,!0),this.addEndOrbits(n),this.addSteps(n,t);for(let e of this.markers)this.parentOf(e.anchorId).add(e.sprite);this.craft={sprite:KI(UI(PI),NI),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=lI(e,n.jd);if(!t)continue;let r=vI(t.r),i=t.centerId===e.centerId?null:t.centerId,a=KI(UI(PI),MI);this.markers.push({sprite:a,local:r,anchorId:i});let o=qI(`step`,n.name,n.when,{canvas:this.canvas,onSelect:n.onPick});this.parentOf(i).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:vI(n.meeting.r),end:e.arrival,color:xI[a?.kind??`cruise`]}];o&&s.push({local:vI(o.r),end:e.departure,color:xI[i?.kind??`cruise`]});for(let{local:n,end:i,color:a}of s){if(!i.name)continue;let o=qI(`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?wI:e.brightness),n.uniforms.uLineWidth.value=t?CI: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?cI(e,s):{from:0,to:a.points.length};this.addLine(a.points.slice(c,l),xI[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),xI.cruise,CI,wI,null,{anchorId:n}),this.addLine(t.approach.slice(i.from,i.to),xI.cruise,CI,wI,null,{anchorId:n,renderOrder:II}),e=i.to;e<t.approach.length&&this.addLine(t.approach.slice(Math.max(0,e-1)),xI.cruise,CI,wI,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,xI.cruise,CI,wI,null,{anchorId:n});this.addLine(t.approach.slice(e>0?e-1:0,r),xI.cruise,kI,AI,null,{anchorId:n})}else this.addLine(t.approach,xI.cruise,CI,wI,null,{anchorId:n});let i=this.addLine(t.points,xI.cruise,kI,AI,null,{anchorId:n});if(!i)continue;let a=n===null?vI(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]=vI(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*HI));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=aP(o,c,l,l,o,t,n,r);d.frustumCulled=!1,d.renderOrder=a.renderOrder??FI,this.parentOf(a.anchorId??null).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=lI(this.path,e);t.sprite.visible=n!==null,n&&(t.local=vI(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],e[1]-t[1],e[2]-t[2]],i=new Map;for(let[e,r]of this.anchored){let a=n(e);i.set(e,JI(a,t)),r.visible=a!==null}let a=e=>e===null?r:i.get(e)??null;for(let e of this.arcs){let t=a(e.anchorId);if(!t)continue;let[n,r,i]=t;for(let t=0;t<e.count;t++)e.positions[t*3]=e.local[t*3]+n,e.positions[t*3+1]=e.local[t*3+1]+r,e.positions[t*3+2]=e.local[t*3+2]+i;tP(e.line.geometry,e.positions,e.alphas,e.alphas,e.count)}for(let e of this.markers){let t=a(e.anchorId);if(!t)continue;let[n,r,i]=t;e.sprite.position.set(e.local[0]+n,e.local[1]+r,e.local[2]+i)}for(let e of this.labels){let t=a(e.anchorId);if(!t)continue;let[n,r,i]=t;e.object.position.set(e.local[0]+n,e.local[1]+r,e.local[2]+i)}if(this.craft){let{sprite:e,local:r,anchorId:i}=this.craft,o=i===null||this.anchored.has(i)?a(i):JI(n(i),t);o?e.position.set(r[0]+o[0],r[1]+o[1],r[2]+o[2]):e.visible=!1}for(let e of this.rings){let t=a(e.arc.anchorId);if(!t)continue;let[n,r,i]=t;e.world.set(e.local[0]+n,e.local[1]+r,e.local[2]+i)}}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*jI}}}setVisible(e){this.group.visible=e}reserveLabelSpace(e,t,n){if(!this.group.visible||this.labels.length===0){kO(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),!AC(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=gO(a,o,s,``,ZF);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++}kO(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))}parentOf(e){if(e===null)return this.group;let t=this.anchored.get(e);return t||(t=new Ba,this.anchored.set(e,t),this.group.add(t)),t}clear(){for(let e of this.arcs)e.line.removeFromParent(),e.line.geometry.dispose(),e.line.material.dispose();for(let e of[...this.markers,...this.craft?[this.craft]:[]]){e.sprite.removeFromParent();let t=e.sprite.material;t.map?.dispose(),t.dispose()}for(let e of this.labels)e.object.removeFromParent(),e.object.element.remove();for(let e of this.anchored.values())this.group.remove(e);this.anchored.clear(),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)}},XI=2,ZI=1,QI=4,$I=200,eL=class{group=new Ba;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,$I);for(let t=0;t<e.count;t++){let[r,i,a]=vI(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($I*3),t=new Float32Array($I).fill(1),n=aP($I,e,t,t,0,xI.cruise,XI,ZI);n.frustumCulled=!1,n.renderOrder=QI,this.layer!==null&&n.layers.set(this.layer),this.group.add(n),this.slots.push({line:n,bodyId:``,local:new Float64Array($I*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;tP(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)}},tL=new Set([`not-yet`,`no-data`,`parent`,`failed`]);function nL(e){let{jd:t,ctx:n,bodyObjects:r,focus:i,focusedBody:a,placer:o,trailView:s,frame:c,outOfRange:l}=e;n.chebStore?.ensure(t),n.probeStore?.ensure(t);let u=[];if(a){let e=new Set([a.data.id]),t=n.getBody(a.data.parentId);for(;t&&!e.has(t.data.id);)e.add(t.data.id),u.push({body:t,oldPos:t.position?[...t.position]:null}),t=n.getBody(t.data.parentId)}o.begin(t,a?.data.id,c);let d=n.visibility.focusedSystemId;for(let e of n.bodies.bodiesById.values())e.data.objectType===G.MOON&&e.data.parentId!==d&&e!==a||o.placeInPass(e);for(let e of r.values())o.placeInPass(e.body);let f=a?o.place(a,t):null,p=a?.unplaced;l.update({jd:t,satellites:n.refresher?.satelliteCoverage(t)??{kind:`covered`},majorBodies:o.noData,focusedOutOfRange:p!==void 0&&tL.has(p)});let m=null,h=performance.now()-i.focusStartTime<i.focusDurationMs;if(a&&!f)for(let e of u){let n=o.place(e.body,t);if(n){if(m=e.body.data.id,h){iL(i.focusTargetWorld,n);let e=i.camTargetOffset;e&&i.camTargetWorld&&aL(i.camTargetWorld,n,e)}else if(e.oldPos)for(let t=0;t<3;t++){let r=n[t]-e.oldPos[t];i.focusTruePos[t]+=r,i.focusTargetWorld[t]+=r}break}}else if(f){iL(i.focusTargetWorld,f);let e=i.camTargetOffset;e&&i.camTargetWorld&&aL(i.camTargetWorld,f,e);let t=i.camOriginOffset;t&&i.camOriginWorld&&aL(i.camOriginWorld,f,t),h||iL(i.focusTruePos,f)}let g=i.focusTruePos;for(let e of r.values()){let n=e.trail;if(n){if(!n.visible){n.userData.refreshDeferred=!0;continue}WF(e.body,n,g,t,s),n.userData.refreshDeferred=!1}}let _=!f&&p===`loading`;return{focusUnplaced:a!==void 0&&!f&&!_,focusLoading:_,anchorId:m}}function rL(e,t,n,r){let i=t.focusTruePos;for(let t of e.values()){let e=t.trail;!e||!e.visible||!e.userData.refreshDeferred||(WF(t.body,e,i,n,r),e.userData.refreshDeferred=!1)}}function iL(e,t){e[0]=t[0],e[1]=t[1],e[2]=t[2]}function aL(e,t,n){e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2]}var oL=Object.freeze([0,0,0]);function sL(e,t,n,r){if(!Number.isFinite(t+n+r))return cL(e,`failed`);let i=e,a=i.position??=[0,0,0];return a[0]=t,a[1]=n,a[2]=r,i.unplaced=void 0,a}function cL(e,t){let n=e;return n.position=null,n.orbitCenter=n.orbitCenterId===void 0?void 0:null,n.unplaced=t,null}function lL(e,t){let n=e;if(!t){n.orbitCenter=null;return}let r=n.orbitCenter??=[0,0,0];r[0]=t[0],r[1]=t[1],r[2]=t[2]}function uL(e,t){let n=e.trailAnchor??=[0,0,0];n[0]=t[0],n[1]=t[1],n[2]=t[2]}var dL=Math.PI/180,fL=120,pL=Q(.001)**2,mL=new WeakMap,hL=new J,gL=new J;function _L(e,t,n){e.distanceToSquared(t)<=pL?e.copy(t):e.lerp(t,n)}function vL(e,t,n,r,i){let a=e.featureAnchor;lL(e,n),gL.set(0,0,0);let o=r?.nomenclatureActiveIndex??-1,s=o>=0?r?.nomenclatureLabels?.[o]??null:null;if(s&&s.element.dataset.featureId===String(a.featureId)){let e=r?.nomenclatureAnchor;e?(hL.copy(s.position),gL.copy(e.position)):(hL.copy(s.position),r?.mesh&&hL.multiply(r.mesh.scale))}else{let e=t.data.radiusKm,n=a.lat*dL,i=a.lon*dL,o=t.orientation&&Number.isFinite(e)&&e>0?nN(r,t.data.id,e,n,i):null;if(o)hL.set(o.pointKm[0],o.pointKm[1],o.pointKm[2]);else{let t=Number.isFinite(e)&&e>0?e:0,[r,a,o]=FM(n,i);hL.set(t*r,t*a,t*o)}hL.multiplyScalar(Q(1))}let c=performance.now(),l=mL.get(e);if(!l)l={fixed:hL.clone(),addend:gL.clone(),t:c},mL.set(e,l);else{let e=1-Math.exp(-(c-l.t)/fL);l.t=c,_L(l.fixed,hL,e),_L(l.addend,gL,e)}return hL.copy(l.fixed),t.orientation&&hL.applyQuaternion(wT(t.orientation,i,t.nutPrec)),sL(e,n[0]+hL.x+l.addend.x,n[1]+hL.y+l.addend.y,n[2]+hL.z+l.addend.z)}var yL=30034e-10,bL=.45,xL=1.6,SL=.85,CL=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],wL=e=>Math.hypot(e[0],e[1],e[2]);function TL(e,t,n=yL){let r=wL(t);if(!(r>0))return null;let i=r*Math.cbrt(n/3),a=CL(e,t)/r,o=wL(e);if(Math.sqrt(Math.max(0,o*o-a*a))>SL*i)return null;let s=a/i;return s>=bL&&s<=xL?`EL1`:s<=-bL&&s>=-xL?`EL2`:null}function EL(e,t){return!(e.visibleFromDays!==void 0&&t-2451545<e.visibleFromDays)}function DL(e){return e.a===0&&(e.objectType===G.BARYCENTER||e.objectType===G.LAGRANGE_POINT||vn(e.objectType))}function OL(e,t){if(e.pageOnly)return`never`;if(!EL(e,t))return`not-yet`;if(t<e.validityStart||t>e.validityEnd)return`no-data`;let n,r=e.satrec;return n=r?xg(r,t):e.omm?null:e.q==null?e.a===0?DL(e)?[0,0,0]:null:GN(e,t):KN(e,t),!n||!Number.isFinite(n[0]+n[1]+n[2])?`failed`:n}function kL(){return{count:0,earliestStart:1/0,latestEnd:-1/0}}var AL=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`?Ng(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})}}},jL=new Map,ML=new J;function NL(e,t,n,r,i,a,o){let s=wy(n,r,Sy(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(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=nN(o.get(c),c,d,p,m);h&&jL.set(e.id,h);let g=h??jL.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=wT(l.orientation,r,l.nutPrec),x=new J(_,v,y).applyQuaternion(b),S=g?ML.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 PL=[0,0,0],FL=new Ui,IL=4,LL=0,RL=new Map;function zL(e){return e.primary.target===`velocity`||e.secondary?.target===`velocity`}function BL(e,t,n){let r=RL.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 RL.set(e,{jd:t,pos:[n[0],n[1],n[2]],dir:i}),i??void 0}var VL=class{focusedId;noData=kL();passJd=NaN;frame;settled=new Set;settling=new Set;ride=dx([],void 0,()=>void 0);rideJd=NaN;rideFocus;constructor(e,t,n,r=()=>!1){this.ctx=e,this.bodyObjects=t,this.diagnostics=n,this.held=r}begin(e,t,n){this.passJd=e,this.focusedId=t,this.frame=n,this.settled.clear(),this.noData=kL()}at(e,t){if(e===`naif-0`)return oL;let n=this.ctx.getBody(e)??this.bodyObjects.get(e)?.body;return n?this.place(n,t):null}placeInPass(e){let t=e.data,n=this.bodyObjects.get(t.id);n&&this.frame!==void 0&&t.id!==this.focusedId&&!n.root.visible&&!n.trail?.visible&&(t.orbitalSource===W.SPICE_PROBE||!vn(t.objectType))&&(n.staggerSlot??=LL++%IL,this.frame%IL!==n.staggerSlot)||this.place(e,this.passJd)}place(e,t){t!==this.passJd&&this.held()&&(t=this.passJd);let n=e.data.id;if(t===this.passJd&&this.settled.has(n))return e.position;if(this.settling.has(n))return this.diagnostics.warnOnce(`parent-cycle`,n,()=>`place[${n}]: parent chain loops`),null;this.settling.add(n);let r=un(e)?this.seatFeature(e,t):this.settle(e,t);return this.settling.delete(n),t===this.passJd&&this.settled.add(n),r}under(e){return(this.ctx.getBody(e)??this.bodyObjects.get(e)?.body)?.unplaced===`loading`?`loading`:`parent`}seatFeature(e,t){let n=e.featureAnchor.hostId,r=this.ctx.getBody(n),i=r&&this.place(r,t);return!r||!i?cL(e,this.under(n)):vL(e,r,i,this.bodyObjects.get(n),t)}rideAt(e){return(e!==this.rideJd||this.focusedId!==this.rideFocus)&&(this.rideJd=e,this.rideFocus=this.focusedId,this.ride=dx(this.ctx.probeStore?.ridesAt(e)??[],this.focusedId,e=>this.ctx.getBody(e)?.data.name)),this.ride}rowOffset(e,t,n){let r=this.ctx.bodies.elementRow(e),i=r&&this.at(r.parentId,n);if(!i)return null;let a=OL(r,n);return typeof a==`string`?null:[i[0]-t[0]+a[0],i[1]-t[1]+a[1],i[2]-t[2]+a[2]]}settle(e,t){let{ctx:n,diagnostics:r}=this,i=e.data,a=this.bodyObjects.get(i.id);if(i.pageOnly)return cL(e,`never`);if(i.orbitalSource===W.SPICE_PROBE)return this.settleProbe(e,a,t);let o=this.at(i.parentId,t);if(!o){let t=this.under(i.parentId);return t===`parent`&&r.warnOnce(`missing-parent`,i.id,()=>`place[${i.id}]: parent ${i.parentId} has no place`),cL(e,t)}r.clear(`missing-parent`,i.id);let s;return s=n.chebStore?.has(i.id)?EL(i,t)?n.chebStore.positionScene(i.id,t)??this.rowOffset(e,o,t)??this.chebMiss(i.id,t):`not-yet`:OL(i,t),typeof s==`string`?cL(e,s):this.finish(e,a,o[0]+s[0],o[1]+s[1],o[2]+s[2],o,t)}chebMiss(e,t){let n=this.ctx.chebStore;if(n.isLoading(e,t))return`loading`;let r=n.zoneCoverage(e);return r!==null&&(t<r.start||t>r.end)&&t===this.passJd&&(this.noData.count++,r.start<this.noData.earliestStart&&(this.noData.earliestStart=r.start),r.end>this.noData.latestEnd&&(this.noData.latestEnd=r.end)),this.diagnostics.warnOnce(`cheb-null`,e,()=>{let n=r?`[${r.start.toFixed(1)},${r.end.toFixed(1)}]`:`unknown`;return`chebStore.positionScene[${e}] returned null at jd=${t.toFixed(3)} (coverage=${n})`}),`no-data`}finish(e,t,n,r,i,a,o){let s=e.data,c=sL(e,n,r,i);if(!c)return this.diagnostics.warnOnce(`non-finite`,s.id,()=>`place[${s.id}] non-finite: pos=[${n},${r},${i}] parentId=${s.parentId}`),null;let l=e.orbitCenterId;if(l!==void 0&&lL(e,l===s.parentId?a:this.at(l,o)),e.trailAnchorId!==void 0){let t=this.at(e.trailAnchorId,o);t&&uL(e,t)}if(!t)return c;if(t.trail&&e.orbitCenter){let n=t.trail.userData.orbitCenter;n&&n.set(e.orbitCenter[0],e.orbitCenter[1],e.orbitCenter[2])}if(e.orientation&&(t.mesh||t.model))t.mesh&&TT(t.mesh,e.orientation,o,e.nutPrec),t.model&&TT(t.model,e.orientation,o,e.nutPrec),t.nomenclatureAnchor&&TT(t.nomenclatureAnchor,e.orientation,o,e.nutPrec);else if($E(e)){let n=e.attitudeTrack;if(!e.pointingOverride&&n&&n.orientationAt(o,FL))t.mesh&&t.mesh.quaternion.copy(FL),t.model&&t.model.quaternion.copy(FL);else{let n=e.pointingOverride??e.pointing;if(n){let e=zL(n)?BL(s.id,o,c):void 0,r={bodyPos:c,parentPos:a,sunPos:this.at(`naif-10`,o)??void 0,velocity:e};t.mesh&&UT(t.mesh,n,r),t.model&&UT(t.model,n,r)}else t.mesh&&OT(t.mesh,c,a),t.model&&OT(t.model,c,a)}}if(e.orientation)for(let n of t.rings)TT(n.mesh,e.orientation,o,e.nutPrec);return c}settleProbe(e,t,n){let{ctx:r,bodyObjects:a,diagnostics:o}=this,s=e.data,c=this.rideAt(n);if(t){t.carried=c.hidden.has(s.id);let e=c.credits.get(s.id);KT(t,`carrier`,e?i().messages.carried_by_scene_label({carrier:e}):null)}let l=r.visibility.activeSystemId,u=l?e=>r.bodies.isInSystem(`naif-${e}`,l):void 0,d=r.probeStore?.probeWithCenter(s.id,n,u)??null;if(!d)return r.probeStore?.loadingAt(n)?cL(e,`loading`):(cL(e,`no-data`),o.warnOnce(`probe-unavailable`,s.id,()=>{let e=r.probeStore?`no zone has both a loaded chunk and a sub-chunk covering this jd`:`no ProbeStore`;return`probe ${s.id} (${s.name??`unnamed`}): hidden — ${e}`}),null);let f=d.probe.landed;if(f&&Cy(d.probe,n)){let i=s.parentId,c=NL(s,d.probe,f,n,e=>this.at(e,n),r,a);if(!c)return cL(e,this.under(`naif-${f.bodyNaifId}`));if(o.clear(`probe-unavailable`,s.id),i!==s.parentId&&e.trailBuffer?.clear(),t){let e=f.isDestroyed;t.isLanded||=(FO(t.labelHalo,`landed`),!0),t.isCrashed=e,t.model&&(t.model.visible=!e)}let l=sL(e,c.x,c.y,c.z);if(!l)return null;e.orbitCenterId=s.parentId,lL(e,c.parentPos);let u=c.up;return t?.mesh&&(u?kT(t.mesh,u):OT(t.mesh,l,c.parentPos)),t?.model&&(u?kT(t.model,u):OT(t.model,l,c.parentPos)),l}let p=Py(d.probe,n,d.fitCenterNaifId,r.chebStore??null,e=>this.at(e,n)!==null);if(!p){let t=d.probe.fitCenter?.id;return cL(e,t?this.under(t):`parent`),o.warnOnce(`probe-unavailable`,s.id,()=>`probe ${s.id} (${s.name??`unnamed`}): hidden — stamped fit center is not placeable this frame`),null}let m=p.id,h=p.muKm3S2,g=by(d.probe,n,h);if(!g)return cL(e,`no-data`),o.warnOnce(`probe-unavailable`,s.id,()=>`probe ${s.id} (${s.name??`unnamed`}): hidden — sub-chunk evaluation returned null (uncoverable, non-finite fit, or missing mu for kepler_pure)`),null;o.clear(`probe-unavailable`,s.id),t?.isLanded&&(FO(t.labelHalo,`flying`),t.isLanded=!1,t.isCrashed&&(t.isCrashed=!1,t.model&&(t.model.visible=!0),t.noPhysical||KT(t,`missing`,null)));let _=this.at(m_,n),v=this.at(p_,n),y=m===`naif-399`&&_!==null&&v!==null&&TL([Q(g[0]),Q(g[2]),-Q(g[1])],[v[0]-_[0],v[1]-_[1],v[2]-_[2]])!==null,b=y!==(e.lagrangeTrail??!1);e.lagrangeTrail=y;let x=s.parentId!==m;if((x||b)&&e.trailBuffer&&r.probeStore){let t=e.trailBuffer;t.clear(),t.needsPopulate=!1;let i=Ry(jy(d.probe,n,h),s.validityEnd-s.validityStart,t.capacity,y);t.reconfigure(i.stepDays,i.epsilonScene,i.spanDays),Wy(t,r.probeStore,r.chebStore??null,s.id,m,n)}x&&(s.parentId=m);let S=this.at(m,n);if(!S)return cL(e,this.under(m)),o.warnOnce(`probe-unavailable`,s.id,()=>`probe ${s.id} (${s.name??`unnamed`}): hidden — fit center ${m} has no position this frame`),null;let C=S,w=Q(g[0]),T=Q(g[2]),E=-Q(g[1]),D=C[0]+w,O=C[1]+T,k=C[2]+E,A=e.trailBuffer;if(A?.needsPopulate&&t?.trail?.visible&&r.probeStore&&(A.needsPopulate=!1,A.clear(),Wy(A,r.probeStore,r.chebStore??null,s.id,m,n)),A){let e=A.newestJd,t=n-e,i=A.stepDays*A.capacity,a=isFinite(e)&&(t<0||t>i);if(a&&s.id===this.focusedId&&r.probeStore){A.clear();let e=Ry(jy(d.probe,n,h),s.validityEnd-s.validityStart,A.capacity,y);A.reconfigure(e.stepDays,e.epsilonScene,e.spanDays),Wy(A,r.probeStore,r.chebStore??null,s.id,m,n)}else a?(A.clear(),A.append(n,w,T,E)):isFinite(e)?isFinite(A.epsilonScene)?t>=A.stepDays*.00390625&&r.probeStore&&A.readNewestPos(PL)&&Ky(A,By(r.probeStore,r.chebStore??null,s.id,m),e,[PL[0],PL[1],PL[2]],n):t>=A.stepDays&&A.append(n,w,T,E):A.append(n,w,T,E)}return e.orbitCenterId=s.parentId,this.finish(e,t,D,O,k,C,n)}},HL=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)}},UL=Q(695700),WL=2,GL=new J;function KL(e,t,n,r,i){GL.subVectors(e,t);let a=GL.dot(n),o=Math.sqrt(Math.max(GL.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 qL(e,t,n,r,i,a){let o=e.get(p_)?.body.position;if(!o)return;let[s,c,l]=t;for(let t of e.values()){let e=t.body.position;if(!t.rings.length||!e)continue;let[u,d,f]=e;for(let e of t.rings){let p=r||e.intensityScale>=.000980392156862745;e.mesh.visible=p;let m=r?1:p?e.intensityScale:0;e.material.uniforms.uIntensityScale.value=m;let h=e.material.uniforms.uSunDir.value;h.set(o[0]-u,o[1]-d,o[2]-f);let g=h.length(),_=UL/g;e.material.uniforms.uSunAngularRadius.value=_,e.material.uniforms.uLightScale.value=n?JC(g):1,h.normalize();let v=e.planetShadowOnRing;if(v.uPlanetCenter.value.set(u-s,d-c,f-l),t.mesh&&v.uPlanetPoleDir.value.set(0,1,0).applyQuaternion(t.mesh.quaternion),e.layers){let{dist:t,sinToPole:n}=KL(i,v.uPlanetCenter.value,v.uPlanetPoleDir.value,e.innerScene,e.outerScene),r=e.thicknessScene*n/Math.max(t,1e-9)*a,o=Math.min(Math.max(Math.ceil(r*WL),1),48);e.layers.count!==o&&(e.layers.count=o,e.material.uniforms.uLayerCount.value=o,e.material.uniforms.uLayerAlphaExp.value=1/o)}let y=e.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 JL=Math.PI/180,YL=2451545;function XL(e){let t=e-YL,n=(19.3871+.52402073*t)*JL;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 ZL(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 QL(e,t){let n=e.seasonal;if(!n)return e;let r=ZL(n.lsDeg,n.dustTauFactor,t),i=ZL(n.lsDeg,n.dustScaleHeightKm,t),a=ZL(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 $L=new WeakMap,eR=.25;function tR(e,t){if(!e.seasonal)return e;let n=Math.round(XL(t)/eR),r=$L.get(e);if(r&&r.lsQ===n)return r.params;let i=QL(e,n*eR);return $L.set(e,{lsQ:n,params:i}),i}var nR=new J,rR=new J,iR=[.2126,.7152,.0722];function aR(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 oR(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=aR(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+=iR[t]*Math.exp(-n)}return o}var sR=.4,cR=.05,lR=-.105,uR=.3,dR=.05;function fR(e,t,n){let r=oR(e,t),i=Math.min(1,-Math.log(Math.max(r,.001))/dR),a=Math.min(1,Math.max(0,(n-lR)/uR));return r*(1+(sR+(cR-sR)*a-1)*i)}function pR(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 mR=KC,hR=200,gR=new J,_R=new J,vR=new J,yR=new J;function bR(e,t,n,r){e.uOccluderCount.value=_E(e.uOccluders.value,t,r,n)}function xR(e,t,n,r,i,a,o){let s={insideShell:!1,shellProminent:!1,skyboxIntensity:1,sunTint:gR.set(1,1,1),sunRefraction:null};Hk(n&&a.sunTint);let c=e.get(p_);hA(c?.mesh?.material,db());let l=mA(c?.mesh?.material);l&&(l.uAtmoTEnable.value=0);let u=hR,d=c?.body.position;if(!d)return s;for(let c of e.values()){if(!c.atmosphere)continue;c.atmosphere.mesh.visible=n;let e=c.body.position;if(!n||!e)continue;Pk(c.atmosphere,a);let f=ub(c.body.data.id);if(f?.seasonal){let e=a.seasonal?tR(f,o):f;if(c.atmosphere.params!==e){Fk(c.atmosphere,e);for(let t of c.sunTint??[])Yk(t,e,c.atmosphere.surfaceRadiusScene,c.atmosphere.surfaceRadiusKm)}}let[p,m,h]=e,g=c.atmosphere.material.uniforms;g.uGroundAlbedo.value=a.groundAlbedo?c.atmosphere.params.groundAlbedo??0:0;let _=g.uSunDir.value.set(d[0]-p,d[1]-m,d[2]-h),v=c.atmosphere.params,y=r?JC(_.length()):v.realisticSunAlways?Math.sqrt(JC(_.length())):1;g.uSunIntensity.value=v.sunIntensity*y*i,_.normalize(),c.mesh&&(nR.set(0,1,0).applyQuaternion(c.mesh.quaternion),g.uSpinAxis.value.copy(nR));let b=c.root.position,x=c.atmosphere.geometryRadiusScene*c.atmosphere.mesh.scale.x,S=t.distanceTo(b);x>S*.1&&(s.shellProminent=!0),a.eclipseShadows&&bR(g,b,_,x);let C=a.insideView&&S<x,w=c.atmosphere.planetRadiusKm,T=S*((w+v.topAltitudeKm)/x)-w,E=C&&jk(v,T),D=C?Mk(v,T):0;Ok(c.atmosphere,C,E,D),g.uDeepIrradiance.value=mR*i;for(let e of c.sunTint??[])e.uAtmoTDeepIrradiance.value=mR*i,e.uAtmoTDeepBlend.value=D;if(C){s.insideShell=!0;let e=rR.copy(t).sub(b).divideScalar(S).dot(_),n=fR(v,T,e);if(s.skyboxIntensity*=n*(1-D),a.refraction&&v.refractivity&&!E){let t=pR(v.refractivity[1]*Math.exp(-Math.max(T,0)/v.rayleighScaleHeightKm),Math.asin(Math.min(1,Math.max(-1,e))),v.rayleighScaleHeightKm,c.atmosphere.planetRadiusKm);t>5e-6&&(s.sunRefraction={angleRad:t,up:yR.copy(rR)})}}let O=S/x;if(a.sunTint&&O<hR){let e=x/(1+v.topAltitudeKm/w)*(c.atmosphere.surfaceRadiusKm/w);vR.copy(t).sub(b);let n=g.uSpinAxis.value,r=g.uStretch.value;if(nA(v,vR,_,e,c.atmosphere.surfaceRadiusKm,_R,n,r)){let e=iR[0]*_R.x+iR[1]*_R.y+iR[2]*_R.z;e>1e-4&&s.sunTint.multiply(_R.divideScalar(e))}l&&O<u&&(u=O,Zk(l,v,b,e,c.atmosphere.surfaceRadiusKm,n,r))}}return s}var SR=[];function CR(e,t){let n=hE(),r=e.get(p_),i=r?.body.position;if(!r||!i){n.uSunAngularRadius.value=0,n.uOccluderCount.value=0;return}let[a,o,s]=t,c=i[0]-a,l=i[1]-o,u=i[2]-s,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=SR,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||!sO(t)||(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,i]=t.body.position;m[e].set(n-a,r-o,i-s,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,n=t.body.position;if(!e||!n||t.cachedDist>0&&t.radiusScene<t.cachedDist*1e-4)continue;let[r,i,c]=n,l=e.uEclipseSelfPos.value.set(r-a,i-o,c-s);e.uOccluderCount.value=_E(e.uOccluders.value,l,t.radiusScene,h)}}var wR=10;function TR(e,t,n,r,i,a,o,s,c){let l=n.visibility.activeSystemId;if(!l){r.intensity=0,i&&YC(i,s,c);return}let u=e.get(p_)?.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(wR),r.target.position.set(0,0,0),r.intensity=KC*(s?JC(_):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=wR-b,x.far=wR+b,x.updateProjectionMatrix()}var ER=128,DR=256,OR=.25,kR=.32,AR=.35,jR=300,MR=1.25,NR=.05,PR=4e5,FR=new Y,IR=new J;function LR(e,t,n){let r=e=>t.some(([t,n])=>e>t+1e-9&&e<n-1e-9),i=e/ER,a=[];for(let t=0;t<=ER;t++){let n=t===ER?e:t*i;(t===0||t===ER||!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 RR(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 Uo;return u.setAttribute(`position`,new Oo(a,3)),u.setAttribute(`normal`,new Oo(o,3)),u.setAttribute(`uv`,new Oo(s,2)),u.setIndex(new Oo(c.subarray(0,l),1)),u}function zR(e){e.terrainWindow&&(e.terrainWindow=null,e.currentSegments=void 0)}function BR(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}`),zR(e),!1;r.updateMatrixWorld(),FR.copy(r.matrixWorld).invert(),IR.copy(t.position).applyMatrix4(FR);let a=Q(gn(e.body.data)),o=IR.length(),s=Math.max(o/a-1,1e-6);if(s>(e.terrainWindow?kR:OR))return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: alt=${s.toFixed(4)}`),zR(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*MR/DR),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*DR/2,_=Math.acos(Math.min(1,Math.max(-1,IR.y/o))),v=Math.atan2(IR.z,-IR.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)))<AR*m.angRadius)return!0}if(performance.now()-m.builtAt<jR)return!0}let y=Math.max(0,_-g),b=Math.min(Math.PI,_+g),x=LR(Math.PI,[[y,b]],h),S=Math.min(Math.PI,g/Math.max(Math.sin(_),NR)),C=Math.max(p,Math.ceil(Math.log2(2*S/DR/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=LR(2*Math.PI,D,w);if(x.length*O.length>PR)return console.warn(`terrain window for ${e.body.data.id} would need ${x.length}×${O.length} vertices — keeping the uniform sphere`),zR(e),!1;let k=r.geometry;return r.geometry=RR(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=ER,!0}var VR=[{up:150,segs:128},{up:40,segs:64},{up:0,segs:32}],HR=24;function UR(e,t,n,r){if(!n&&!t)return HR;let i=VR[VR.length-1].segs;for(let t of VR)if(e>=t.up){i=t.segs;break}if(i<r){let t=VR.find(e=>e.segs===r);if(t&&e>=t.up*.85)return r}return i}function WR(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)&&BR(n,t,a===c))continue;let l=UR(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(gn(n.body.data)),d=n.mesh.geometry;n.mesh.geometry=new iu(u,l,l),d.dispose(),n.currentSegments=l}}function GR(e,t){let n=e<1.05?`high`:e<4?`medium`:`low`;if(pM(n)>pM(t))return n;let r=e>7?`low`:e>1.15?`medium`:`high`;return pM(r)<pM(t)?r:t}function KR(e,t,n,r,i,a,o,s,c){s.apply(e,i);let l=t.fov*Math.PI/180,u=n.domElement.clientHeight/(2*Math.tan(l/2)),d=r.visibility.activeSystemId,f=jx(),p=f.showClouds,m=pM(Kx());for(let t of e.values())t.clouds&&(t.clouds.mesh.visible=p);for(let s of e.values()){if(!s.mesh||!s.radiusScene||!s.group.visible||!s.availableTiers?.length||s.cachedDist<=0)continue;let e=s.body.data.id;if(d){if(e!==d&&!r.visibility.isInActiveSystem(s.body.data.parentId))continue}else if(e!==a)continue;let l=s.radiusScene/s.cachedDist*u,p=s.cachedDist/s.radiusScene,h;h=l<256&&p>10?`low`:l<1024&&p>2?`medium`:`high`;let g=pM(s.textureTier),_=mj(s)?Math.min(m,pM(`medium`)):m,v=Math.min(pM(h),_),y=gM(o,s.availableFrames),b=y!==s.textureFrame,x=v>g;if(f.showSurfaceTexture&&!s.textureLoading&&(x||b)){let e=x?mM(v,s.availableTiers):s.textureTier;e&&SM(s,e,y,i)}_j(s,t,n,u*n.getPixelRatio(),f.showSurfaceTexture&&!s.appearance?.surfaceOwned&&!s.model,c);let S=s.displacementMeta?.tiers;if(s.displacementMap&&S?.length&&!s.displacementLoading){let e=n.capabilities.maxTextureSize,t=e>=16383?2:+(e>=8192),r=s.displacementTier??`low`,i=mM(Math.min(pM(GR(p,r)),t,m),S);i&&i!==r&&Kj(s,i)}if(s.clouds&&s.textureTier){let e=mM(pM(s.textureTier),s.clouds.availableTiers),t=Ij(o,s.clouds.availableFrames,s.clouds.availableCoverage);e&&t&&zj(s.clouds,e,t)}}}var qR=JD.refMs,JR=new Y,YR=new J,XR=new J,ZR=new Ui,QR=new Ui,$R=new J,ez=new J;function tz(e,t,n){return YR.set(e[0],e[1],e[2]),XR.set(t[0],t[1],t[2]),JR.lookAt(YR,XR,n),ZR.setFromRotationMatrix(JR).clone()}function nz(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=z_(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=V_(e.camOriginWorld,e.camTargetWorld,e.focusTargetWorld,n);else{let t=r?o*o*o:n;i=z_(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]),QR.copy(t.quaternion),t.quaternion.slerpQuaternions(e.flyQ0,QR,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=z_(e.camOriginWorld,e.camTargetWorld,t)}let i=tz(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 rz(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=tz([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=B_(r,i),s=e.flyQ0.angleTo(a);e.focusDurationMs=Math.max(qD(o,XD),KD(s,ZD))}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(),$R.set(0,0,-1).applyQuaternion(e.flyQ0),ez.set(t[0]-r[0],t[1]-r[1],t[2]-r[2]).normalize(),e.focusDurationMs=KD($R.angleTo(ez),JD);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 iz(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=B_(n,r);$R.set(e.focusTruePos[0]-n[0],e.focusTruePos[1]-n[1],e.focusTruePos[2]-n[2]).normalize(),ez.set(e.focusTruePos[0]-r[0],e.focusTruePos[1]-r[1],e.focusTruePos[2]-r[2]).normalize();let o=$R.angleTo(ez);e.focusDurationMs=Math.max(qD(a,XD),KD(o,ZD)),i&&(e.focusDurationMs=0)}var az={[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},oz=5e-4,sz=new J,cz=new J;function lz(e){return az[e.data.objectType]??gn(e.data)*.25}function uz(e,t){return Q((t??gn(e.data))+lz(e))}function dz(e,t,n,r){let i=t.data.radiusKm,a=t.position;if(!Number.isFinite(i)||i<=0||!a)return;let o=a[0]-n[0],s=a[1]-n[1],c=a[2]-n[2],l=Math.hypot(o,s,c),u=r?.centerOffsetScene,d=o+(u?u[0]:0),f=s+(u?u[1]:0),p=c+(u?u[2]:0),m=e.position.x-d,h=e.position.y-f,g=e.position.z-p,_=Math.hypot(m,h,g);if(r?.seated){if(_<1e-9){e.position.set(d,f+l+Q(oz),p);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]]){cz.set(a,o,s).applyQuaternion(e.quaternion);let t=m+cz.x,n=h+cz.y,c=g+cz.z,u=Math.hypot(t,n,c);if(u<1e-12)continue;sz.set(t/u,n/u,c/u).applyQuaternion(r.invQuat);let d=r.radialKm([sz.x,sz.y,sz.z]),f=(d===null?l:Q(d))+Q(oz);f-u>i&&(i=f-u)}if(i<=0)return;let a=i/_;e.position.set(e.position.x+m*a,e.position.y+h*a,e.position.z+g*a);return}let v=lz(t);if(_>=Q((r?.outerRadiusKm??i)+v))return;let y=i;r&&_>1e-9&&(sz.set(m/_,h/_,g/_).applyQuaternion(r.invQuat),y=r.radialKm([sz.x,sz.y,sz.z])??i);let b=Q(y+v),x=l>0?Math.min(b,l):b;if(!(_>=x)){if(_<1e-9)m=0,h=x,g=0;else{let e=x/_;m*=e,h*=e,g*=e}e.position.set(d+m,f+h,p+g)}}function fz(e,t,n){let r=e.position,{latitude:i,longitude:a,distance:o}=aC([r.x,r.y,r.z],[0,0,0],n),s=Math.min(Math.max(i,t.minLat??-90),t.maxLat??90),c=lC(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]=oC([0,0,0],s,c,l,n);r.set(u,d,f)}var pz=50,mz=20;function hz(e){return e<=0?`none`:e<mz?`full`:e<pz?`half`:`none`}function gz(e,t){return e.data.validityStart<=t&&t<=e.data.validityEnd}var _z=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),Uv().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 h_)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||!_n(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:h_.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;!e.orbitElements&&!e.data.pageOnly&&e.data.orbitalSource!==W.SPICE_PROBE&&(e.orbitElements=e.data,e.orbitCenterId=e.data.parentId),i.place(e,a.jd),xj([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&&bM(d),e.data.objectType===G.SPACECRAFT)i.bodies.dirtySpacecraftGroups.add(e.data.parentId);else if(_n(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(){pP(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(m_),t=this.currentMemberCount(e),n=hz(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)||gz(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),gz(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&&!gz(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||un(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}if(e.label&&(e.label.element.remove(),e.label.removeFromParent()),e.loadingEl?.remove(),fD(e),xM(e),yN(e),i.remove(e.root),e.trail&&i.remove(e.trail),e.mesh){e.mesh.geometry.dispose(),vj(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(),vj(e.atmosphere.mesh.material),null),e.trail&&(e.trail.geometry.dispose(),vj(e.trail.material));let s=e.body.data.objectType;if(s===G.SPACECRAFT)c.add(e.body.data.parentId);else if(_n(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)}},vz=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 _z({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}place(e){return this.deps.ctx.place(e,this.deps.clock.jd)}setPendingInitialView(e){this.pendingInitialView=e}clearPendingInitialView(){this.pendingInitialView=null}focusedBodyQuat(e){let t=e??this.focusedBody;if(!t||$E(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=yz(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&&(Sj(t.body)?wj(t,n,r,i):fD(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}Sj(t)&&(Cj(o,n,r,i),f=!0),t.data.id!==e?.data.id&&c(t)}return f&&(pP(a,n,o.basis(),s.jd),l()),this.upgradeTargetIds=d,d}panCameraToBody(e,t){let n=this.place(e);if(!n)return;let{focus:r,camera:i}=this.deps,a=this.cameraTruePos(),o;if(t!==void 0){let e=this._tmpV3.set(a[0]-n[0],a[1]-n[1],a[2]-n[2]).normalize();o=[n[0]+e.x*t,n[1]+e.y*t,n[2]+e.z*t]}rz(r,[...n],i,a,o,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,rz(n,[...e],r,a,o,jx().resolvedReducedMotion);let s=aC(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}this.setFocusTarget(e);let t=e.position;if(!t)return;let{latitude:n,longitude:r,distance:i}=aC(this.cameraTruePos(),t,this.focusedBodyQuat(e));this.deps.callbacks.onCameraPosition?.(n,r,i)}setFocusTarget(e,t){let{ctx:n,bodyObjects:r,controls:i,callbacks:a,focus:o,camera:s,systemData:c,loadTexture:l}=this.deps;un(e)||this.promotion.ensureBodyObjects(e);let u=this.focusedBody,d=oN(u,r),f=oN(e,r),p=u&&(un(u)?u.featureAnchor.hostId:u.data.id),m=un(e)?e.featureAnchor.hostId:e.data.id,h=this.syncUpgradeTargets(e);if(p&&p!==m&&!h.has(p)){let e=r.get(p);e&&fD(e)}if(d&&d!==f){let e=r.get(d);e&&yN(e)}this.focusedBody=e,un(e)||(n.bodies.focusFeature=null),i.minDistance=uz(e,ND(r.get(e.data.id)));let g=un(e)?n.getBody(e.featureAnchor.hostId):void 0;if(n.visibility.setFocused(g??e),a.onFocusChange(e),un(e)||l(e),f&&f!==e.data.id){let e=n.getBody(f);e&&l(e)}c.syncToFocus();let _=this.place(e);_&&rz(o,[..._],s,this.cameraTruePos(),t,jx().resolvedReducedMotion),this.promotion.emitUserPromotedCount()}focusOnBody(e,t,n,r){let{ctx:i,focus:a,camera:o,callbacks:s,pointClouds:c}=this.deps,l=i.getBody(e);if(!l)return 0;let u=this.place(l);if(!u)return this.setFocusTarget(l),0;let d;if(t!==void 0)if(n!==void 0&&r!==void 0)d=oC(u,n,r,t,this.focusedBodyQuat(l));else{let e=this.cameraTruePos(),n=this._tmpV3.set(u[0]-e[0],u[1]-e[1],u[2]-e[2]).normalize().negate();d=[u[0]+n.x*t,u[1]+n.y*t,u[2]+n.z*t]}let f=aC(d??this.cameraTruePos(),u,this.focusedBodyQuat(l));return s.onCameraPosition?.(f.latitude,f.longitude,f.distance),t!==void 0&&d?this.focusedBody?.data.id===e&&B_(a.focusTruePos,u)<uz(l)?(a.focusTruePos=[...u],this.deps.repositionAll(),c.rebuildBasis(),iz(a,o,this.cameraTruePos(),d,jx().resolvedReducedMotion)):(this.setFocusTarget(l,d),n!==void 0&&r!==void 0&&(a.orbitFly=!0)):this.setFocusTarget(l),a.focusDurationMs}snapToBody(e,t,n,r){let i=this.deps.ctx.getBody(e),a=i&&this.place(i);!i||!a||(this.settleOnBodyInstant(i,a),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),l=i.getBody(t),u=c&&this.place(c),d=l&&this.place(l);if(!c||!u||!d)return;this.settleOnBodyInstant(c,u);let f=sC(u,d,n,r);a.position.set(f[0],f[1],f[2]),o.update();let p=aC(f,[0,0,0]);s.onCameraPosition?.(p.latitude,p.longitude,p.distance),this.pendingInitialView=null}settleOnBodyInstant(e,t){let{focus:n,pointClouds:r}=this.deps;this.setFocusTarget(e),n.focusTruePos=[...t],n.focusOriginWorld=[...t],n.focusTargetWorld=[...t],n.focusStartTime=-qR,n.camOriginWorld=null,n.camTargetWorld=null,n.flyQ0=null,n.orbitFly=!1,n.arcOrbit=!1,n.cameraStaysOnBody=!1,this.deps.repositionAll(),r.rebuildBasis()}snapToBodyFrame(e,t,n){let r=this.focusedBody;if(!r)return;let{camera:i,controls:a,callbacks:o}=this.deps,s=!$E(r),c=s?this.focusedBodyQuat(r)??[0,0,0,1]:void 0,l=oC([0,0,0],e,t,n,c);i.position.set(l[0],l[1],l[2]),a.update();let u=aC(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=oC([0,0,0],e.latitude,e.longitude,e.zoom,t);this.deps.camera.position.set(...n),this.deps.controls.update(),this.pendingInitialView=null}};function yz(e,t){if(!e)return[];if(un(e)){let n=t.getBody(e.featureAnchor.hostId);return n&&Sj(n)?[n]:[]}let n=[];if(Sj(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 bz=1e-6;function xz(e){return e.data.name??e.data.id}var Sz=class{armedProbeId=null;noticeShown=!1;coverage=new Map;pending=new Set;constructor(e,t){this.clock=e,this.notices=t}windowsOf(e){let t=this.coverage.get(e);if(t)return t;this.pending.has(e)||(this.pending.add(e),hx(e).catch(t=>(console.warn(`[coverage] ${e}: no coverage to arm the clock with:`,t),[])).then(t=>this.coverage.set(e,t)).finally(()=>this.pending.delete(e)))}sync(e,t){let n=e?.data.orbitalSource===W.SPICE_PROBE?e:void 0,r=n&&this.windowsOf(n.data.id)?.find(([e,n])=>t>e&&t<n);if(!n||!r){this.disarm();return}this.armedProbeId!==n.data.id&&(this.dismissNotice(),this.armedProbeId=n.data.id);let i=r[1]-bz,a=r[0]+bz;this.noticeShown&&t>a&&t<i&&this.dismissNotice(),this.clock.setBoundaryStops({forwardJd:Number.isFinite(i)?i:null,backwardJd:Number.isFinite(a)?a:null,onHit:e=>this.onHit(n,e,i)})}onHit(e,t,n){this.notices.notify({topic:`coverage-pause`,name:xz(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)}},Cz=class{group=new Ba;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()}},wz=Math.PI/180;function Tz(e){return`latitude`in e}function Ez(e,t){let n=e*wz,r=t*wz;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function Dz(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 Oz(e,t,n){return t.place(e,n)}function kz(e,t,n,r){let[i,a,o]=n;if(Tz(e)){let n=Q(gn(t.data)+(e.altitudeKm??0)),[s,c,l]=Ez(e.latitude,e.longitude),u=t.orientation?wT(t.orientation,r,t.nutPrec):null;if(!u)return[i+s*n,a+c*n,o+l*n];let d=[0,0,0];return Dz(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]=vI(s);return[i+c,a+l,o+u]}function Az(e,t,n){let r=t.getBody(e.body),i=r&&Oz(r,t,n);return i?kz(e,r,i,n):null}function jz(e,t,n,r){let i=n.getBody(e.body),a=i&&Oz(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 Mz(e){let t=ag/10;return[e[0]*t,-e[2]*t,e[1]*t]}function Nz(e,t,n){let r=Az(e.position,t,n),i=Az(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 Pz=.02,Fz=1e-4;function Iz(e){return e?.4:.05}function Lz(e,t,n,r,i){let a=e.position.length();if(!(a>0))return{rotate:1,translate:1};let o=$E(n)?void 0:n,s=a;for(let n of[o,i?void 0:r]){let r=n?.position;if(!n||!r)continue;let i=Q(gn(n.data));if(!(i>0))continue;let a=Math.hypot(e.position.x-(r[0]-t[0]),e.position.y-(r[1]-t[1]),e.position.z-(r[2]-t[2]));s=Math.min(s,a-i)}let c=o?Q(gn(o.data)):0,l=Math.tan(Hi.degToRad(e.getEffectiveFOV())/2);return{rotate:Rz(c>0?(a-c)*l/(Math.PI*c):1,Fz),translate:Rz(s/a,Pz)}}function Rz(e,t){return Math.min(1,Math.max(t,e))}var zz=Math.PI/180;function Bz(e,t){let n=e*zz,r=t*zz;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function Vz(e,t,n,r){let i=document.createElement(`div`);i.className=`user-location-marker`;let a=new rO(i),[o,s,c]=Bz(n,r);return a.position.set(o*t,s*t,c*t),e.add(a),a}function Hz(e){e.parent?.remove(e),e.element.remove()}var Uz=new J;function Wz(e,t,n){if(!e)return;let r=t.get(m_);if(!r?.mesh)return;Uz.copy(e.position).applyQuaternion(r.mesh.quaternion);let i=Uz.x,a=Uz.y,o=Uz.z,s=r.root.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 Gz=-1,Kz=1.2,qz=Q(1e6),Jz=.02,Yz=2,Xz=2.3,Zz=.9,Qz=new J,$z=.25,eB=10,tB=4,nB=4,rB=28,iB=.02,aB=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=IN();pointClouds;systemData;positionDiagnostics=new HL;placer;clickables=[];meshToBody=new Map;hoveredBodyIds=new Set;cullFrameCounter=0;hideCappedMoonLabels=!1;focusController;coverageWatch=null;outOfRange;extensions=new Cz;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 zd;_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:qR};lastUpdatedJd=NaN;get placedJd(){return this.lastUpdatedJd}lastUpdatedSystemId=null;lastSeatConfigKey=null;lastProbeVersion=0;disposed=!1;lastDataVersion=-1;dateHolds=0;seenJumps=0;jumpJd=null;focusWasOutOfRange=!1;seekAwaitsData=!1;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 Ui;unsubscribeBodiesAdded=null;_trailView={camX:0,camY:0,camZ:0,tolAngle:0};viewportH=1;tier=Yx();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 Yu;appearances=new CM;shadowLight;ambientLights;get sunPointLight(){return this.bodyObjects.get(p_)?.root.children.find(e=>e instanceof fd)}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.seenJumps=i.jumps,this.callbacks=o,this.outOfRange=new AL(o.notices),this.labelContainer=n;let s=ew(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 Tj(c.x,c.y),this.modelScene=new Ja,this.modelScene.environment=XC(this.renderer),this.modelScene.environmentIntensity=qC,this.modelCamera=new cd(60,1,.01,1e3),this.modelScene.add(this.modelCamera);let l=new gd(16777215,GC);this.modelScene.add(l),this.ambientLights=[s.ambientLight,l],this.modelLight=new hd(16777215,KC),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 js(new eu(40,40),new au({opacity:.55})),this.modelShadowPlane.receiveShadow=!0,this.modelShadowPlane.visible=!1,this.modelScene.add(this.modelShadowPlane),this.skyboxAdjuster=new yP(this.scene),this.skyDebugMarkers=new LP(this.scene),this.haloDebug=new KP(this.canvas),this.travelPath=new YI(this.scene,this.canvas),this.travelPath.setLayer(e.MAP_LAYER),this.orbitPreview=new eL(this.scene),this.orbitPreview.setLayer(e.MAP_LAYER),this.skyboxAdjuster.set(0,0,0),pS(this.scene,this.renderer,r,()=>this.disposed),this.placer=new VL(r,this.bodyObjects,this.positionDiagnostics,()=>this.dateHeld()),r.placer=this.placer;let u=[r.getBody(a.id),r.bodies.majorBodies.find(e=>e.data.id===uC),r.bodies.majorBodies.find(e=>e.data.id===p_)].find(e=>e&&this.placer.place(e,this.clock.jd)),d=u?.position??oL;this.focus.focusTruePos=[...d],this.focus.focusOriginWorld=[...d],this.focus.focusTargetWorld=[...d],this.focus.focusStartTime=-qR,this.pointClouds=new TF(r,this.scene,this.bodyObjects,this.circleTexture,this.focus,e.MAP_LAYER,()=>this.rebuildTrailBasis()),this.pointClouds.seedBasis(d),this.pointClouds.setPointBudget(this.tier.pointBudget),this.controls=new LS(this.camera,t),this.controls.enableDamping=!0,this.controls.dampingFactor=Iz(jx().resolvedReducedMotion),this.controls.minDistance=u?uz(u):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 nO(this.camera,this.controls,r,e=>this.isLanded(e)),this.systemData=new _P(this.scene,r,this.renderer,this.textureLoader,this.bodyObjects,i,()=>this.focusController.reapplyInitialViewIfPending()),this.focusController=new vz({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()},u,this.hoveredBodyIds,this.circleTexture,this.renderer),this.coverageWatch=new Sz(i,o.notices);let f=u?.data.id===a.id?a:{latitude:45,longitude:0,zoom:15},p=oC([0,0,0],f.latitude,f.longitude,f.zoom,this.focusController.focusedBodyQuat());this.camera.position.set(...p),this.focusController.setPendingInitialView({latitude:f.latitude,longitude:f.longitude,zoom:f.zoom}),u&&r.visibility.setFocused(u),r.visibility.updateCamera(f.zoom,this.clock.jd),o.onFocusChange(u),this.buildScene(),u&&this.focusController.promotion.ensureBodyObjects(u),u&&this.focusController.syncUpgradeTargets(u),this.repositionAll(),u&&this.maybeLoadTexture(u),this.systemData.syncToFocus(),this.focusController.readerFocusFilter=this.readerMayFocus,this.gpuPick=new WD(this.renderer,this.camera),this.pointerInteraction=new zD(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(){xj(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)))(()=>{pP(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.whereBody(t);if(!r)return;let i=this.focus.focusTruePos,a=r[0]-i[0]-this.camera.position.x,o=r[1]-i[1]-this.camera.position.y,s=r[2]-i[2]-this.camera.position.z,c=Math.hypot(a,o,s);c>n*1.35&&c<n*45||(this.previewFlyBodyId=e.bodyId,this.focusController.focusOnBody(e.bodyId,n*4))}refreshOrbitPreview(){this.orbitPreview.isEmpty||(this.orbitPreview.reposition(e=>this.where(e),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.where(e):null;if(!t){this.travelPath.setVisible(!1),this.reserveTravelLabelSpace();return}this.travelPath.setVisible(!0),this.travelPath.setClock(this.sceneJd),this.travelPath.reposition(t,this.focus.focusTruePos,e=>this.where(e)),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.where(e);if(!n)return;let[r,i,a]=vI(t);this.travelFocus={centerId:e,local:[r,i,a]};let o=this.travelFocusWorld(n);o&&this.focusController.focusOnPoint(o)}trackPathPoint(e,t){if(!this.travelFocus){this.focusOnPathPoint(e,t);return}let[n,r,i]=vI(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.where(this.travelFocus.centerId);if(!e)return;let t=this.travelFocusWorld(e);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.where(e.centerId),r=n?this.travelFocusWorld(n):null;if(!r)return;let i=null;for(let e of t.stops){let t=this.ctx.getBody(e.bodyId),n=t&&this.whereBody(t);if(!t||!n)continue;let a=this.ctx.visibility.resolveSystemId(t);if(!a)continue;let o=this.ctx.visibility.systemReachAU(a);if(!(o>0))continue;let s=B_(r,n)/10;!i&&s<=o?i=a:s<=o*2?this.systemData.prefetch(a):this.systemData.discardPrefetch(a)}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()}checkDrawnArePlaced(){for(let e of this.bodyObjects.values()){if(e.body.position)continue;let t=e.root.visible?`root`:e.trail?.visible?`trail`:e.model?.parent===this.modelScene?`model`:null;t&&this.positionDiagnostics.warnOnce(`drawn-unplaced`,e.body.data.id,()=>`[scene] ${e.body.data.id} has no place (${e.body.unplaced}) and its ${t} is drawn`)}}placeOf(e){return this.applyJdUpdate(),this.whereBody(e)}panCameraTo(e,t){return this.disarmLimits(),this.focusController.panCameraToBody(e,t),this.focus.focusDurationMs}where(e){return this.placer.at(e,this.sceneJd)}whereBody(e){return this.placer.place(e,this.sceneJd)}repositionBodies(){let[e,t,n]=this.focus.focusTruePos;for(let r of this.bodyObjects.values()){let i=r.body.position;i&&r.root.position.set(i[0]-e,i[1]-t,i[2]-n)}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){HF(i.body,a,o,e,this.sceneJd);continue}let s=a.userData.trailLocalPositions;if(!s)continue;let c=a.userData.orbitCenter;UF(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.sceneJd),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.sceneJd,r);let i=this.holdingCamera?this.applyHeldCamera():nz(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=I_(a.data.parentId),t=e?this.ctx.getBody(e):void 0,n=!!this.bodyObjects.get(a.data.id)?.isLanded||un(a);t&&dz(this.camera,t,this.focus.focusTruePos,this.surfaceClamp(t,n)),AD(this.bodyObjects.get(a.data.id))&&dz(this.camera,a,this.focus.focusTruePos,this.surfaceClamp(a,!1)),this.setMotionScale(Lz(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.sceneJd),this.updateTightFar(o),this.systemData.syncToFocus(),this.refreshTravelPath(),this.refreshOrbitPreview(),this.extensions.update({jd:this.sceneJd,basis:this.focus.focusTruePos,camera:this.camera,viewportPx:this.viewportH,ctx:this.ctx}),this.cullFrameCounter=iI(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(),rL(this.bodyObjects,this.focus,this.lastUpdatedJd,this.trailView()),qL(this.bodyObjects,this.focus.focusTruePos,jx().realisticLighting,jx().overexposeRings,this.camera.position,this.pxPerRad()),CR(this.bodyObjects,this.focus.focusTruePos);let s=xR(this.bodyObjects,this.camera.position,jx().showAtmospheres,jx().realisticLighting,this.sunIntensityScale,KO(),this.sceneJd);rk(r,s.shellProminent),this.scene.backgroundIntensity=s.skyboxIntensity,this.applyLayerChrome();let c=this.bodyObjects.get(p_);c&&pA(c.corona,c.starPoint,s.sunTint);let l=jx().highAmbient?1:GC;if(!jx().highAmbient&&jx().realisticLighting){let e=this.bodyObjects.get(p_)?.body.position;if(e&&this.ctx.visibility.activeSystemId){let[t,n,r]=this.focus.focusTruePos;l*=JC(Math.hypot(e[0]-t,e[1]-n,e[2]-r))}}for(let e of this.ambientLights)e.intensity=l;Wz(this.userLocationMarker,this.bodyObjects,this.camera);let u=oN(this.focusController.current,this.bodyObjects);KR(this.bodyObjects,this.camera,this.renderer,this.ctx,this.textureLoader,u,this.sceneJd,this.appearances,this.invalidate),WR(this.bodyObjects,this.camera,this.renderer,this.ctx,u),TR(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(kC())return;let t=this.focusController.current,n=t?oN(t,this.bodyObjects):void 0,r=n?this.bodyObjects.get(n):void 0,i=r?.radiusScene??0,a=e,o=r?.body.position;if(t&&o&&n!==t.data.id){let[e,t,n]=this.focus.focusTruePos,[r,i,s]=o,c=this.camera.position;a=Math.hypot(e+c.x-r,t+c.y-i,n+c.z-s)}let s=this.tightFar?Xz:Yz;this.tightFar=i>0&&this.ctx.visibility.activeSystemId!==null&&a<i*s}updateDepthFar(){if(kC())return;let e=ZC,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(p_);if(this.tightFar){let e=this.bodyObjects.get(t)?.body.position;if(e){let o=Math.hypot(e[0]-n,e[1]-r,e[2]-i)+this.ctx.bodies.getSystemExtent(t)*10*2;a=Math.max(a,o*o)}}else s?.body.position&&o(s.body.position);for(let e of this.bodyObjects.values()){let t=e.body.position;t&&this.ctx.visibility.hasFullRendering(e.body)&&o(t)}e=Math.min(ZC,Math.max(qz,Math.sqrt(a)*Kz))}Math.abs(e-this.camera.far)>this.camera.far*Jz&&(this.camera.far=e,this.camera.updateProjectionMatrix())}updateSunProxy(e){let t=this.bodyObjects.get(p_),n=t?.body.position;if(!t||!n)return;let[r,i,a]=this.focus.focusTruePos,[o,s,c]=n,l=o-r,u=s-i,d=c-a;if(e){let t=this.camera.position,n=this._tmpV3.set(l-t.x,u-t.y,d-t.z),r=n.length();n.divideScalar(r);let i=Qz.copy(e.up).addScaledVector(n,-e.up.dot(n));i.lengthSq()>1e-12&&(n.addScaledVector(i.normalize(),e.angleRad).normalize(),l=t.x+n.x*r,u=t.y+n.y*r,d=t.z+n.z*r)}let f=1;if(this.tightFar){let e=this.camera.far*Zz,t=Math.hypot(l,u,d);t>e&&(f=e/t)}f===1&&this.sunProxyK===1&&!e||(this.sunProxyK===1&&(this.sunBaseMeshScale=t.mesh?.scale.x??1,this.sunBaseCoronaScale=t.corona?.scale.x??0),t.root.position.set(l*f,u*f,d*f),t.mesh?.scale.setScalar(this.sunBaseMeshScale*f),t.corona?.scale.set(this.sunBaseCoronaScale*f,this.sunBaseCoronaScale*f,1),this.sunProxyK=f)}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=FM(t*Math.PI/180,n*Math.PI/180);return rN(this.bodyObjects.get(e),e,gn(r.data),i)}surfaceClamp(e,t){let n=this.bodyObjects.get(e.data.id);if(AD(n))return{invQuat:n.model.quaternion.clone().invert(),seated:t,outerRadiusKm:MD(n),centerOffsetScene:jD(n),radialKm:e=>kD(n,e)};if(!(!t||!e.orientation))return{invQuat:wT(e.orientation,this.sceneJd,e.nutPrec).invert(),seated:t,radialKm:t=>rN(n,e.data.id,e.data.radiusKm,t)}}updateModelMounts(){let e=!1;for(let t of this.bodyObjects.values())if(t.model&&$E(t.body)&&sO(t)){e=!0;break}this.overlayActive=e;for(let t of this.bodyObjects.values()){let n=t.model;if(!n)continue;let r=sO(t),i=t.modelRoot;if(!i){r&&n.parent!==this.modelScene?this.modelScene.add(n):!r&&n.parent&&n.removeFromParent();continue}if(e&&r)n.parent!==this.modelScene&&this.modelScene.add(n);else if(n.parent!==i){i.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=aD(e);t.scale.setScalar(n);let r=this.shadowLight.intensity>0;if(this.shadowLight.castShadow=r,!r)return;let i=this.bodyObjects.get(p_)?.body.position,a=e.body.position;if(!i||!a)return;this._tmpSun.set(i[0]-a[0],i[1]-a[1],i[2]-a[2]).normalize(),this.shadowLight.position.copy(e.root.position).addScaledVector(this._tmpSun,eB*n),this.shadowLight.target.position.copy(e.root.position);let o=this.shadowLight.shadow.camera;o.left=o.bottom=-tB*n,o.right=o.top=tB*n,o.near=nB*n,o.far=rB*n,o.updateProjectionMatrix(),this.shadowLight.shadow.normalBias=iB*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.root.position);let n=this._tmpV3.length(),r=aD(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||!sO(t))continue;let i=aD(t)/r,o=n.userData.fitScale??1;n.scale.setScalar(o*i),n.position.subVectors(t.root.position,e.root.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(p_)?.body.position,s=e.body.position,c=1;if(o&&(this._tmpSun.set(o[0]-s[0],o[1]-s[1],o[2]-s[2]),jx().realisticLighting&&(c=JC(this._tmpSun.length())),this._tmpSun.normalize(),this.modelLight.position.copy(this._tmpSun).multiplyScalar(10)),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 l=vE(this._tmpV3,this._tmpV3)*c;this.modelLight.intensity=KC*l*this.sunIntensityScale,this.modelScene.environmentIntensity=qC*l,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=$z/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 aC([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?Gz:Tn.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||fz(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,r=e?.position;return r?[n.x+t[0]-r[0],n.y+t[1]-r[1],n.z+t[2]-r[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&&Nz(e,this.ctx,this.sceneJd);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&&(yM(t,this.textureLoader,this.sceneJd,this.scene,this.renderer.capabilities.maxTextureSize,this.ctx).then(()=>{this.focusController.current?.data.id===e.data.id&&e.orientation&&t.mesh&&(TT(t.mesh,e.orientation,this.sceneJd,e.nutPrec),this.focusController.reapplyInitialViewIfPending())}),lD(t,this.modelScene,this.ctx).then(()=>{if(this.focusController.current?.data.id===t.body.data.id&&(this.controls.minDistance=uz(t.body,ND(t))),!this.ctx.layers.skipped.has(`nomenclature`))return mN(t,this.canvas,(e,n,r,i)=>{this.featureSelectEnabled&&this.callbacks.onFeatureSelect?.(t.body.data.id,e,n,r,i)})}).then(()=>{this.selectedFeatureId!==null&&vN(t,this.selectedFeatureId)}))}reapplyBodyLayers(){let e=this.focusController.current;if(!e)return;let t=this.bodyObjects.get(e.data.id);t&&(fD(t),xM(t),this.maybeLoadTexture(e))}setSelectedFeature(e){this.selectedFeatureId=e;let t=oN(this.focusController.current,this.bodyObjects),n=t?this.bodyObjects.get(t):void 0;n&&vN(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&&!un(e))return null;let t=I_(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`}|${WM()}`}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),ux(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,Fg(this.clock.jd));return}this.focusController.promotion.ensureBodyObjects(i),this.focusController.syncUpgradeTargets(e)}holdDate(){this.dateHolds++;let e=!0;return()=>{e&&this.dateHolds--,e=!1}}jumpLoads(){let{clock:e,ctx:t}=this;e.jumps!==this.seenJumps&&(this.seenJumps=e.jumps,this.jumpJd=e.jd,t.refreshTick(Fg(e.jd)),t.chebStore?.request(e.jd),t.probeStore?.request(e.jd));let n=this.jumpJd;return n===null?!1:!t.chebStore?.loadingAt(n)&&!t.probeStore?.loadingAt(n)?(this.jumpJd=null,!1):(this.invalidate(),!0)}dateHeld(){return!Number.isNaN(this.lastUpdatedJd)&&(this.dateHolds>0||this.jumpLoads())}get sceneJd(){return this.dateHeld()?this.lastUpdatedJd:this.clock.jd}applyJdUpdate(e=!1){if(this.dateHolds>0||this.jumpLoads())return;this.ensureFocusedProbeTarget();let t=this.ctx.visibility.focusedSystemId,n=this.focusedSeatConfigKey(),r=this.ctx.probeStore?.version??0,i=this.ctx.bodies.dataVersion+(this.ctx.chebStore?.version??0);if(this.clock.jd===this.lastUpdatedJd&&t===this.lastUpdatedSystemId&&n===this.lastSeatConfigKey&&r===this.lastProbeVersion&&i===this.lastDataVersion){this.clock.seeked=!1;return}let a=this.clock.seeked||this.seekAwaitsData;this.clock.seeked=!1,this.lastUpdatedJd=this.clock.jd,this.lastUpdatedSystemId=t,this.lastSeatConfigKey=n,this.lastProbeVersion=r,this.lastDataVersion=i,this.ctx.refreshTick(Fg(this.clock.jd)),this.focusController.promotion.onSimTimeChanged();let o=nL({jd:this.clock.jd,ctx:this.ctx,bodyObjects:this.bodyObjects,focus:this.focus,focusedBody:this.focusController.current,placer:this.placer,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(),this.seekAwaitsData=a&&o.focusLoading;let s=o.focusUnplaced&&!this.focusWasOutOfRange;if(this.focusWasOutOfRange=o.focusUnplaced,e&&a&&s&&o.anchorId){let e=this.ctx.getBody(o.anchorId);e&&this.focusController.panCameraToBody(e)}}setReducedMotion(e){this.controls.dampingFactor=Iz(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),o=a&&this.whereBody(a);if(!a||!o)return 0;this.focusController.clearPendingInitialView();let s=oN(this.focusController.current,this.bodyObjects)===e.hostId,c=fC(e,t);this.ctx.bodies.focusFeature=c;let l=this.bodyObjects.get(a.data.id);this.selectedFeatureId=e.featureId,l&&vN(l,e.featureId);let u=this.whereBody(c);if(!u)return 0;let d=this.focusController.focusedBodyQuat(c);if(r===`pan`){let e=aC(this.focusController.cameraTruePos(),u,d);return this.callbacks.onCameraPosition?.(e.latitude,e.longitude,e.distance),this.focusController.setFocusTarget(c),this.focus.focusDurationMs}let f=u[0]-o[0],p=u[1]-o[1],m=u[2]-o[2],h=Math.hypot(f,p,m);h>1e-9?(f/=h,p/=h,m/=h):(f=0,p=1,m=0);let g=r===`snap`&&i?oC(u,i.latitude,i.longitude,i.zoom,d):[u[0]+f*n,u[1]+p*n,u[2]+m*n],_=aC(g,u,d);if(this.callbacks.onCameraPosition?.(_.latitude,_.longitude,_.distance),r===`snap`){this.focusController.setFocusTarget(c,g);let e=this.focus;return e.focusTruePos=[...u],e.focusOriginWorld=[...u],e.focusTargetWorld=[...u],e.focusStartTime=-qR,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(g[0]-u[0],g[1]-u[1],g[2]-u[2]),this.controls.update(),0}if(s){let e=this.focusController.cameraTruePos();this.focusController.setFocusTarget(c),this.focus.focusTruePos=[...u],this.camera.position.set(e[0]-u[0],e[1]-u[1],e[2]-u[2]),this.repositionAll(),this.pointClouds.rebuildBasis(),iz(this.focus,this.camera,e,g,jx().resolvedReducedMotion)}else this.focusController.setFocusTarget(c,g),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||!sO(e))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=e=>e?.model&&sO(e)?e:null,t=this.focusController.current;if(!t){let t=this.travelFocus?.centerId;return e(t?this.bodyObjects.get(t):void 0)}let n=un(t)?t.featureAnchor.hostId:t.data.id,r=this.bodyObjects.get(n);return e(r)||(t.data.orbitalSource===W.SPICE_PROBE&&!r?.isLanded?e(this.bodyObjects.get(t.data.parentId)):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 ZP({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:$E(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 Ba,t=new J(0,0,0),n=(n,r,i,a)=>{let o=new Kd(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 ls(new Yo({map:new Pc(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=ub(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&&Fk(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(m_);n?.mesh&&(this.userLocationMarker&&Hz(this.userLocationMarker),this.userLocationMarker=Vz(n.mesh,n.radiusScene,e,t))}clearUserLocation(){this.userLocationMarker&&=(Hz(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(Xx()),this.composer.setPixelRatio(Xx()),this.resize(this.canvas.clientWidth,this.canvas.clientHeight),pS(this.scene,this.renderer,this.ctx,()=>this.disposed),this.resume()}recoverWorkersIfDead(e){return this.pointClouds.recoverWorkersIfDead(e)}applyRenderTier(){this.tier=Yx();let e=Xx();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),BC(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&&fD(e);this.pointClouds.dispose(),this.disposeScene(this.scene),this.disposeScene(this.modelScene),oB(this.scene.background),oB(this.scene.environment),oB(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))oB(t);e.dispose()}})}};function oB(e){e&&typeof e==`object`&&e.isTexture&&e.dispose()}var sB=Ze({progress:null,bootPending:!1}),cB=6371;function lB(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 uB={topAltitudeKm:67,rayleighScatterPerKm:[.0058,.0136,.0331],rayleighScaleHeightKm:8.4,mieScatterPerKm:[.004,.004,.004],mieAbsorptionPerKm:[4e-4,4e-4,4e-4],mieScaleHeightKm:1.2,miePhase:lB(.75),absorptionPerKm:[65e-5,.001881,85e-6],absorptionCenterKm:25,absorptionWidthKm:15,bakedCompensation:1,multiScatterGain:.3,sunIntensity:5,sunColor:[1,1,1]},dB=1.6,fB=1.0005,pB=new J(.55,.25,.8).normalize(),mB=[`low`,`medium`,`high`,`ultra`],hB=4,gB=12,_B=10,vB=16,yB=5;function bB(e){return!e.limb&&!e.sky?NaN:Math.max(e.limb?.medianMs??0,e.sky?.medianMs??0)}function xB(e,t){let n=`low`;for(let r of e.tiers){let e=bB(r);!Number.isNaN(e)&&e<=t&&(n=r.tier)}return n}var SB=new Set([`WebKit WebGL`,`Mozilla`,``]);function CB(e){let t=e.getContext(),n=String(t.getParameter(t.RENDERER)??``);if(!SB.has(n))return n;let r=t.getExtension(`WEBGL_debug_renderer_info`);return r?String(t.getParameter(r.UNMASKED_RENDERER_WEBGL)):n}function wB(e,t){let n=e.getContext(),r=new Ja,i=new cd(50,n.drawingBufferWidth/Math.max(n.drawingBufferHeight,1),.005,100),a=new hu({color:7829367,roughness:1,metalness:0}),o=new js(new iu(1,64,64),a);o.renderOrder=1,r.add(o);let s=new hd(16777215,2);s.position.copy(pB),r.add(s);let c=uB,l=Dk(c,1,cB),u=l.material.uniforms;u.uSunDir.value.copy(pB),u.uSunIntensity.value=c.sunIntensity,r.add(l.mesh);let d=e=>{let t=e===`sky`;t?(i.position.set(0,fB,0),i.lookAt(1,fB+.1,0)):(i.position.set(0,0,dB),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}={})=>{Pk(l,UO[e]),d(t);let i=0;for(let e=0;e<hB;e++)r?.(`warmup`,e+1),await p(),i=m(1);let a=Math.min(vB,Math.max(1,Math.ceil(_B/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<gB;e++)if(r?.(`measure`,e+1),await p(),o.push(m(a)),n!==void 0&&o.length>=yB){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(),Rk(l)}}}function TB(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 EB(e,t){let n=t.tiers??mB,{budgetMs:r,signal:i,onProgress:a}=t,o=Math.max(0,n.indexOf(t.startTier??n[n.length-1])),s=wB(e,i),c=hB+gB,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`?hB: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`?gB:hB,fraction:u})}}),f=new Map,p=new Map,m=async e=>{let t=n[e];if(UO[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 TB(e,n,f,p)}var DB=60,OB=100,kB=3e4,AB=25e4,jB=`v1`,MB=!1,NB=null,PB=Promise.resolve();function FB(e){let t=e.getContext(),n=Math.round(t.drawingBufferWidth*t.drawingBufferHeight/AB);return`${CB(e)}|${n}|${jB}`}function IB(){MB||typeof window>`u`||(MB=!0,sB.bootPending=!0,PB=new Promise(e=>{let t=()=>{sB.bootPending=!1,e()};setTimeout(t,kB),setTimeout(()=>void RB(!1).finally(t),OB)}))}function LB(){return PB}function RB(e){return NB??=zB(e).finally(()=>NB=null),NB}async function zB(e){let t=jx();if(!e&&(t.atmosphereQuality!==`auto`||!t.showAtmospheres))return;let n=null;try{n=new fh({canvas:document.createElement(`canvas`),antialias:!0}),n.setPixelRatio(Wx()),n.setSize(window.innerWidth,window.innerHeight,!1);let r=FB(n);if(!e&&t.atmosphereCalibration?.key===r)return;sB.progress=0;let i=await EB(n,{budgetMs:1e3/DB,startTier:WO(),onProgress:e=>sB.progress=e.fraction}),a={};for(let e of i.tiers){let t=bB(e);Number.isNaN(t)||(a[e.tier]=Math.round(t*100)/100)}let o=xB(i,1e3/DB);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{sB.progress=null,n?.dispose(),n?.forceContextLoss()}}var BB=class{object=new Ba;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 rO(e.element);let[n,r]=e.align??[.5,.5];this.label.center.set(n,r),this.object.add(this.label),this.object.matrixAutoUpdate=!1,VO(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?Az(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=jz(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()}},VB=3,HB=new J,UB=new J,WB=new J;function GB(e){let[t,n=t]=(e??``).split(/[\s,]+/).filter(Boolean).map(Number);return t>0&&n>0?[t,n]:null}function KB(e,t){return HB.set(1,0,0).applyQuaternion(e.quaternion),UB.set(0,1,0).applyQuaternion(e.quaternion),WB.set(0,0,-1).applyQuaternion(e.quaternion),t/(2*Math.tan(e.getEffectiveFOV()*Math.PI/360))}function qB(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*HB.x+a*HB.y+o*HB.z,r[1]=i*UB.x+a*UB.y+o*UB.z,r[2]=i*WB.x+a*WB.y+o*WB.z}function JB(e,t,n){WB.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)*WB.x+(e[o*3+1]-i)*WB.y+(e[o*3+2]-a)*WB.z<n.near*2)return!0;return!1}function YB(e,t,n,r,i){let a=KB(n,r),o=[0,0,0],s=0,c=0,l=0,u=!1;for(let r=0;r<t;r++){if(qB(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 XB=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=KB(r,i),o=i*r.aspect*VB/2,s=i*VB/2,c=r.near*2,{a:l,b:u}=this,d=!1,f=0,p=0,m=0;n>0&&qB(e,0,r,l);for(let i=0;i+1<n;i++,[l,u]=[u,l]){qB(e,i+1,r,u);let n=0,h=1;for(let e=0;e<5&&n<=h;e++){let t=ZB(e,l,a,o,s,c),r=ZB(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 ZB(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 QB=1e-9,$B=class{object=new Ba;anchor;color;widthPx;opacity;dash;fade;closed;local;count=0;mesh=null;scratch=new Float32Array;alphas=new Float32Array;seen=new XB;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=GB(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?Az(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])>QB||Math.abs(o[1]-this.lastOrigin[1])>QB||Math.abs(o[2]-this.lastOrigin[2])>QB;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||JB(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),tP(this.mesh.geometry,e.points,e.alphas,e.alphas,e.count),this.dash&&iP(this.mesh.geometry,e.lengths,e.count)}else s&&tP(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=aP(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 eV(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=tV(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,tV(n,a)]}function tV(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 nV(e,t={}){let[n,r]=eV(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 rV(e){if(e.length<3)return[];let[t,n]=eV(iV(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 Zl.triangulateShape(r,[]).flat()}function iV(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 aV(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 oV([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 oV(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 sV(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]]:oV([n,r,i])}function cV(e,t){return new pu({transparent:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:new X(e)},uOpacity:{value:t},uCenterOffset:{value:new J}},vertexShader:`
5667
5667
  #include <common>
5668
5668
  #include <logdepthbuf_pars_vertex>
5669
5669
  uniform vec3 uCenterOffset;