spacemap 0.1.16 → 0.1.17
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/README.md +2 -1
- package/dist/spacemap.iife.js +74 -74
- package/dist/spacemap.js +74 -74
- package/index.d.ts +6 -0
- package/index.js +81 -18
- package/package.json +1 -1
package/dist/spacemap.js
CHANGED
|
@@ -5069,7 +5069,7 @@ float tileWindowWeight( mat3x2 map, mat3x2 cap, float side, vec4 window, vec4 gr
|
|
|
5069
5069
|
}
|
|
5070
5070
|
|
|
5071
5071
|
#endif
|
|
5072
|
-
`;function jE(e,t=!1){return{kind:e,spread:t,uniforms:{map:{value:null},mask:{value:null},grid:{value:Array.from({length:7},()=>new ha)},window:{value:Array.from({length:7},()=>new ha)},home:{value:Array.from({length:7},()=>new q)},anchor:{value:new J(1,0,0)},loaded:{value:new Int32Array(7)},filter:{value:new q(1,1)}},inflight:0,failures:0,failed:new Set,dead:!1,lastUsed:0}}function ME(e,t,n,r){let i=t*4,a=new va(null,i,i,n);a.source.dataReady=!1,a.format=e.format,a.type=e.type,a.colorSpace=e.colorSpace,a.wrapS=a.wrapT=Pn,a.magFilter=Bn,a.minFilter=Hn,a.generateMipmaps=!1,a.anisotropy=Math.min(16,r.capabilities.getMaxAnisotropy()),a.needsUpdate=!0;let o=new va(new Uint8Array(kE*n),4,4,n);return o.format=sr,o.type=Un,o.minFilter=o.magFilter=Bn,o.wrapS=o.wrapT=Pn,o.unpackAlignment=1,o.needsUpdate=!0,{kind:e,texture:a,mask:o,windows:[],free:Array.from({length:n},(e,t)=>t),tileSize:t}}function NE(e,t,n,r){e.mask.image.data[t*kE+n]=r?255:0,e.mask.needsUpdate=!0}function PE(e,t,n){return e.mask.image.data[t*kE+n]!==0}function FE(e,t,n,r){if(!(t.placement===n&&t.frame===r)){t.placement=n,t.frame=r;for(let i=0;i<kE;i++){let{x:a,y:o}=hE(n,i%4,Math.floor(i/4)),s=`${r??0}/${t.chart}/${t.level}/${a}/${o}`;if(t.wanted[i]===s)continue;t.wanted[i]=s,NE(e,t.layer,i,!1);let c=t.pending.get(i);c&&(c.abort.abort(),t.pending.delete(i))}}}function IE(e,t){for(let{abort:e}of t.pending.values())e.abort();t.pending.clear();for(let n=0;n<kE;n++)NE(e,t.layer,n,!1);e.free.push(t.layer)}function LE(e,t,n){if(!(t.chart!==0||t.level<=e.max_level))return uE(e.patches,t.level,n.x,n.y)}function RE(e,t,n){return t.level<=e.max_level?!0:t.placement?LE(e,t,hE(t.placement,n%4,Math.floor(n/4)))!==void 0:!1}function zE(e,t,n,r){for(let i=0;i<kE;i++){let a=r.wanted[i];if(!a||!(PE(t,r.layer,i)||e.failed.has(a))&&RE(n,r,i))return!1}return!0}var BE=new J,VE=[];function HE(e,t,n,r,i,a,o,s){let c=r.placement;if(!c)return;let l=tE(r.chart,r.level),u=i*l,d=a*nE(r.chart,r.level);VE.length=0;for(let i=0;i<kE;i++){let a=r.wanted[i];if(!a||r.pending.has(i)||e.failed.has(a)||PE(t,r.layer,i)||!RE(n,r,i))continue;let o=hE(c,i%4,Math.floor(i/4)),s=o.x+.5-u;r.chart===0&&(s-=l*Math.round(s/l)),VE.push({slot:i,far:Math.hypot(s,o.y+.5-d)})}VE.sort((e,t)=>e.far-t.far);for(let{slot:i}of VE){if(e.inflight>=wE)return;let a=r.wanted[i],l=i%4,u=Math.floor(i/4),d=hE(c,l,u),f=new AbortController,p=!1,m=setTimeout(()=>{p=!0,f.abort()},EE*1e3);r.pending.set(i,{key:a,abort:f}),e.inflight++;let h=JT[r.chart],g=LE(n,r,d)?.version??(r.chart===0?dE(n,r.level,d.x,d.y):n.version),_={id:n.id,version:g};e.kind.load(Jt(_,h,r.level,d.x,d.y,r.frame),f.signal).then(n=>{r.wanted[i]===a&&!f.signal.aborted&&(BE.set(l*t.tileSize,(3-u)*t.tileSize,r.layer),o.copyTextureToTexture(n.texture,t.texture,null,BE),NE(t,r.layer,i,!0),e.failures=0,s()),n.release()}).catch(()=>{f.signal.aborted&&!p||(e.failed.add(a),++e.failures>=TE&&(e.dead=!0))}).finally(()=>{clearTimeout(m),e.inflight--,r.pending.get(i)?.key===a&&r.pending.delete(i)})}}function UE(e){for(let t of e.uniforms.window.value)t.w=0}function WE(e){UE(e);let t=e.store;if(t){for(let e of t.windows)for(let{abort:t}of e.pending.values())t.abort();t.texture.dispose(),t.mask.dispose(),e.store=void 0,e.uniforms.map.value=null,e.uniforms.mask.value=null}}function GE(e,t){UE(e),t-e.lastUsed>DE*1e3&&WE(e)}var
|
|
5072
|
+
`;function jE(e,t=!1){return{kind:e,spread:t,uniforms:{map:{value:null},mask:{value:null},grid:{value:Array.from({length:7},()=>new ha)},window:{value:Array.from({length:7},()=>new ha)},home:{value:Array.from({length:7},()=>new q)},anchor:{value:new J(1,0,0)},loaded:{value:new Int32Array(7)},filter:{value:new q(1,1)}},inflight:0,failures:0,failed:new Set,dead:!1,lastUsed:0}}function ME(e,t,n,r){let i=t*4,a=new va(null,i,i,n);a.source.dataReady=!1,a.format=e.format,a.type=e.type,a.colorSpace=e.colorSpace,a.wrapS=a.wrapT=Pn,a.magFilter=Bn,a.minFilter=Hn,a.generateMipmaps=!1,a.anisotropy=Math.min(16,r.capabilities.getMaxAnisotropy()),a.needsUpdate=!0;let o=new va(new Uint8Array(kE*n),4,4,n);return o.format=sr,o.type=Un,o.minFilter=o.magFilter=Bn,o.wrapS=o.wrapT=Pn,o.unpackAlignment=1,o.needsUpdate=!0,{kind:e,texture:a,mask:o,windows:[],free:Array.from({length:n},(e,t)=>t),tileSize:t}}function NE(e,t,n,r){e.mask.image.data[t*kE+n]=r?255:0,e.mask.needsUpdate=!0}function PE(e,t,n){return e.mask.image.data[t*kE+n]!==0}function FE(e,t,n,r){if(!(t.placement===n&&t.frame===r)){t.placement=n,t.frame=r;for(let i=0;i<kE;i++){let{x:a,y:o}=hE(n,i%4,Math.floor(i/4)),s=`${r??0}/${t.chart}/${t.level}/${a}/${o}`;if(t.wanted[i]===s)continue;t.wanted[i]=s,NE(e,t.layer,i,!1);let c=t.pending.get(i);c&&(c.abort.abort(),t.pending.delete(i))}}}function IE(e,t){for(let{abort:e}of t.pending.values())e.abort();t.pending.clear();for(let n=0;n<kE;n++)NE(e,t.layer,n,!1);e.free.push(t.layer)}function LE(e,t,n){if(!(t.chart!==0||t.level<=e.max_level))return uE(e.patches,t.level,n.x,n.y)}function RE(e,t,n){return t.level<=e.max_level?!0:t.placement?LE(e,t,hE(t.placement,n%4,Math.floor(n/4)))!==void 0:!1}function zE(e,t,n,r){for(let i=0;i<kE;i++){let a=r.wanted[i];if(!a||!(PE(t,r.layer,i)||e.failed.has(a))&&RE(n,r,i))return!1}return!0}var BE=new J,VE=[];function HE(e,t,n,r,i,a,o,s){let c=r.placement;if(!c)return;let l=tE(r.chart,r.level),u=i*l,d=a*nE(r.chart,r.level);VE.length=0;for(let i=0;i<kE;i++){let a=r.wanted[i];if(!a||r.pending.has(i)||e.failed.has(a)||PE(t,r.layer,i)||!RE(n,r,i))continue;let o=hE(c,i%4,Math.floor(i/4)),s=o.x+.5-u;r.chart===0&&(s-=l*Math.round(s/l)),VE.push({slot:i,far:Math.hypot(s,o.y+.5-d)})}VE.sort((e,t)=>e.far-t.far);for(let{slot:i}of VE){if(e.inflight>=wE)return;let a=r.wanted[i],l=i%4,u=Math.floor(i/4),d=hE(c,l,u),f=new AbortController,p=!1,m=setTimeout(()=>{p=!0,f.abort()},EE*1e3);r.pending.set(i,{key:a,abort:f}),e.inflight++;let h=JT[r.chart],g=LE(n,r,d)?.version??(r.chart===0?dE(n,r.level,d.x,d.y):n.version),_={id:n.id,version:g};e.kind.load(Jt(_,h,r.level,d.x,d.y,r.frame),f.signal).then(n=>{r.wanted[i]===a&&!f.signal.aborted&&(BE.set(l*t.tileSize,(3-u)*t.tileSize,r.layer),o.copyTextureToTexture(n.texture,t.texture,null,BE),NE(t,r.layer,i,!0),e.failures=0,s()),n.release()}).catch(()=>{f.signal.aborted&&!p||(e.failed.add(a),++e.failures>=TE&&(e.dead=!0))}).finally(()=>{clearTimeout(m),e.inflight--,r.pending.get(i)?.key===a&&r.pending.delete(i)})}}function UE(e){for(let t of e.uniforms.window.value)t.w=0}function WE(e){UE(e);let t=e.store;if(t){for(let e of t.windows)for(let{abort:t}of e.pending.values())t.abort();t.texture.dispose(),t.mask.dispose(),e.store=void 0,e.uniforms.map.value=null,e.uniforms.mask.value=null}}function GE(e,t){let n=e.store;return!n||e.dead||e.uniforms.window.value[0].w===0?!0:n.windows.every(r=>zE(e,n,t,r))}function KE(e,t){UE(e),t-e.lastUsed>DE*1e3&&WE(e)}var qE=new Y,JE=new J,YE=new J;function XE(e,t){return JE.copy(t.position).applyMatrix4(qE.copy(e.matrixWorld).invert()).normalize()}function ZE(e,t,n){if(aE(n.y,e?.chart)!==0)return t.max_level;let r=iE(0,n.x,n.y,n.z);return pE(t.max_level,t.patches,r.x,r.y)}function QE(e,t){let n=e.max_level;if(e.patches)for(let t of e.patches)n=Math.max(n,t.max_level);let r=n-3+1;return Math.min(t,6,r+1)}function $E(e,t,n,r,i,a,o,s,c){e.lastUsed=performance.now();let l=e.store;l&&(l.texture.image.depth!==n+1||l.kind!==e.kind)&&WE(e);let u=e.store??=ME(e.kind,t.tile_size,n+1,s);e.uniforms.map.value=u.texture,e.uniforms.mask.value=u.mask,e.uniforms.filter.value.set(u.texture.anisotropy,t.tile_size);let d=i.y>=0?1:2;e.chart=aE(i.y,e.chart);let f=oE(r,n,e.chart,i.y,t.max_level,e.spread);YE.set(Math.fround(i.x*a),Math.fround(i.y*a),Math.fround(i.z*a)),e.uniforms.anchor.value.copy(YE);let p=YE.length(),m=iE(0,YE.x/p,YE.y/p,YE.z/p),h=e=>u.windows.find(t=>t.chart===e.chart&&t.level===e.level);u.windows=u.windows.filter(n=>{if(n.rank=f.findIndex(e=>e.chart===n.chart&&e.level===n.level),n.rank>=0)return!0;n.rank=f.length;let r=f.find(e=>e.level===n.level),i=r&&h(r),a=n.chart===0||n.chart===d;return r&&a&&!(i&&zE(e,u,t,i))?!0:(IE(u,n),!1)});for(let n=f.length-1;n>=0;n--){let r=f[n],a=h(r);if(!a){let e=u.free.pop();if(e===void 0)continue;a={layer:e,...r,rank:n,wanted:Array(kE),pending:new Map},u.windows.push(a)}let l=iE(r.chart,i.x,i.y,i.z);FE(u,a,cE(r.chart,r.level,l.x,l.y,a.placement),o),HE(e,u,t,a,l.x,l.y,s,c)}u.windows.sort((e,t)=>t.level-e.level||e.rank-t.rank);for(let t=0;t<7;t++){let n=u.windows[t],r=e.uniforms.window.value[t];if(!n?.placement){r.w=0;continue}if(e.uniforms.grid.value[t].set(tE(n.chart,n.level),nE(n.chart,n.level),n.placement.tx0,n.placement.ty0),n.chart===0){let r=mE(n.placement,m.x,m.y);e.uniforms.home.value[t].set(r.x,r.y)}r.set(n.chart,n.layer,n.level,1);let i=0;for(let e=0;e<kE;e++)PE(u,n.layer,e)&&(i|=1<<e);e.uniforms.loaded.value[t]=i}}var eD=8,tD=1.5,nD=3,rD=1,iD=.006,aD=`
|
|
5073
5073
|
uniform sampler2DArray uReliefMap;
|
|
5074
5074
|
uniform sampler2DArray uReliefMask;
|
|
5075
5075
|
uniform vec4 uReliefGrid[ 7 ];
|
|
@@ -5152,7 +5152,7 @@ vec3 reliefTileSlope( vec3 dir, mat3x2 map, mat3x2 cap, float side, out float co
|
|
|
5152
5152
|
}
|
|
5153
5153
|
return slope * uReliefScale;
|
|
5154
5154
|
}
|
|
5155
|
-
`;function
|
|
5155
|
+
`;function oD(e){return`
|
|
5156
5156
|
// One window as a shadow ray reads it. The ray is a line on the window's
|
|
5157
5157
|
// chart, so where it is inside the window is worked out once, not at each
|
|
5158
5158
|
// sample. 'sight' holds what a sample reads, as a mat2x4 and not a struct
|
|
@@ -5192,7 +5192,7 @@ void reliefSight( int i, mat3x2 map, mat3x2 cap, float side, vec2 mapStep, vec2
|
|
|
5192
5192
|
slot.x / rows, - slot.y / rows, rate.x / rows, - rate.y / rows,
|
|
5193
5193
|
max( near.x, near.y ), leaves, window.y, float( uReliefLoaded[ i ] )
|
|
5194
5194
|
);
|
|
5195
|
-
widest = ${
|
|
5195
|
+
widest = ${tD.toFixed(2)} * PI / ( uReliefFilter.y * exp2( window.z ) );
|
|
5196
5196
|
// Near a patch the next window can be some levels coarser. The ray then
|
|
5197
5197
|
// stays here until its step is half of what that window holds: too wide
|
|
5198
5198
|
// for these pixels, but they are the same ground as the fragment's. The
|
|
@@ -5202,7 +5202,7 @@ void reliefSight( int i, mat3x2 map, mat3x2 cap, float side, vec2 mapStep, vec2
|
|
|
5202
5202
|
beyond = 0.0;
|
|
5203
5203
|
if ( i + 1 < 7 ) {
|
|
5204
5204
|
float next = PI / ( uReliefFilter.y * exp2( uReliefWindow[ i + 1 ].z ) );
|
|
5205
|
-
hands = max( hands, 0.5 * ${
|
|
5205
|
+
hands = max( hands, 0.5 * ${tD.toFixed(2)} * next );
|
|
5206
5206
|
// Within half a pixel of a window, its height is that of the fragment's
|
|
5207
5207
|
// own pixel, and the fragment stands above or below that by all the
|
|
5208
5208
|
// relief that the pixel averages away.
|
|
@@ -5270,13 +5270,13 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5270
5270
|
// curve under it. Past where it clears the pyramid's range, nothing
|
|
5271
5271
|
// can stand in it.
|
|
5272
5272
|
float clear = sqrt( tanElev * tanElev + 2.0 * uReliefScale * ( 1.0 - own ) ) - tanElev;
|
|
5273
|
-
float reach = min( clear, ${
|
|
5273
|
+
float reach = min( clear, ${eD.toFixed(1)} * uReliefScale );
|
|
5274
5274
|
if ( reach < 1e-7 ) return 1.0;
|
|
5275
5275
|
|
|
5276
5276
|
// The ratio that takes steps from one pixel to the reach: 'rate' is its
|
|
5277
5277
|
// logarithm times the count, and solves rate / ( exp( rate ) - 1 ) = part.
|
|
5278
5278
|
float count = ${e.toFixed(1)};
|
|
5279
|
-
float pixel = widest / ${
|
|
5279
|
+
float pixel = widest / ${tD.toFixed(2)};
|
|
5280
5280
|
float part = count * pixel / reach;
|
|
5281
5281
|
float rate = 0.0;
|
|
5282
5282
|
if ( part < 1.0 ) {
|
|
@@ -5290,7 +5290,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5290
5290
|
|
|
5291
5291
|
// How far the ground stands into the ray is counted in discs of the Sun.
|
|
5292
5292
|
// The disc is an angle, and the ray's rise is a slope.
|
|
5293
|
-
float perDisc = 1.0 / ( max( sunSize, ${
|
|
5293
|
+
float perDisc = 1.0 / ( max( sunSize, ${iD.toFixed(4)} ) * ( 1.0 + tanElev * tanElev ) );
|
|
5294
5294
|
float t = 0.0;
|
|
5295
5295
|
float hidden = - 1e9;
|
|
5296
5296
|
// The sample that hides the most, the step around it and its window.
|
|
@@ -5328,11 +5328,11 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5328
5328
|
// those are far apart. Look for it around the best one, each time at half
|
|
5329
5329
|
// the distance and in a finer window. Not where the best one is so clear
|
|
5330
5330
|
// of the ray that no crest beside it can reach the Sun's disc.
|
|
5331
|
-
float crest = ${(
|
|
5331
|
+
float crest = ${(rD*.5).toFixed(2)} * around / max( worst, 1e-9 ) * perDisc;
|
|
5332
5332
|
if ( hidden < 1.0 && hidden + crest > - 1.0 ) {
|
|
5333
5333
|
w = worstWindow;
|
|
5334
5334
|
reliefSight( w, map, cap, side, mapStep, capStep, sight, widest, hands, beyond );
|
|
5335
|
-
for ( int k = 0; k < ${
|
|
5335
|
+
for ( int k = 0; k < ${nD}; k ++ ) {
|
|
5336
5336
|
around *= 0.5;
|
|
5337
5337
|
if ( w > start && around < widest ) {
|
|
5338
5338
|
w --;
|
|
@@ -5343,7 +5343,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5343
5343
|
float at = centre + ( e == 0 ? - around : around );
|
|
5344
5344
|
// Nearer than a pixel, the window holds no crest: only the slope
|
|
5345
5345
|
// of the fragment's own ground, which is the normal's to light.
|
|
5346
|
-
if ( at < widest * ${(1/
|
|
5346
|
+
if ( at < widest * ${(1/tD).toFixed(4)} ) continue;
|
|
5347
5347
|
float value = reliefSightValue( sight, at );
|
|
5348
5348
|
if ( value < 0.0 ) continue;
|
|
5349
5349
|
float stands = ( ( value - own ) * uReliefScale / at - tanElev - 0.5 * at ) * perDisc;
|
|
@@ -5356,7 +5356,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5356
5356
|
}
|
|
5357
5357
|
return 1.0 - smoothstep( - 1.0, 1.0, hidden );
|
|
5358
5358
|
}
|
|
5359
|
-
`}function
|
|
5359
|
+
`}function sD(e){return e>0?aD+oD(e):aD}function cD(e){let t=e?sr:lr,n=e?Yn:Un;return{format:t,type:n,colorSpace:``,async load(r,i){let a=await KT(r,e,i),o=new rc(a.heights,a.size,a.size,t,n);return{texture:o,release:()=>o.dispose()}}}}var lD=cD(!1),uD=new ha(65280/65535,255/65535,0,0),dD=cD(!0),fD=new ha(1/65535,0,0,0);function pD(e){return!!e&&e.scale_km!==void 0&&e.max_level>=3&&Kt()!==``&&yE()>0&&a(e.distribution)}function mD(e,t,n){if(!pD(t))return;let r=e.userData.reliefTiles;if(r)return r;let i=jE(lD,!0),a={tiles:t,chain:i,shadowSteps:bE(),uniforms:{uReliefMap:i.uniforms.map,uReliefMask:i.uniforms.mask,uReliefGrid:i.uniforms.grid,uReliefWindow:i.uniforms.window,uReliefHome:i.uniforms.home,uReliefAnchor:i.uniforms.anchor,uReliefLoaded:i.uniforms.loaded,uReliefFilter:i.uniforms.filter,uReliefRead:{value:uD},uReliefScale:{value:(t.scale_km??0)/n}}};return e.userData.reliefTiles=a,a}function hD(e){return!!e.reliefTiles&&!e.reliefTiles.chain.dead}function gD(e){e.reliefTiles&&WE(e.reliefTiles.chain)}function _D(e,t,n,r,i){let a=e.reliefTiles;if(!a)return;let o=e.mesh;o&&a.shadowSteps!==bE()&&(a.shadowSteps=bE(),o.material.needsUpdate=!0);let{chain:s,tiles:c}=a,l=o&&e.selfShadow&&!s.dead?XE(o,t):void 0,u=n.extensions.has(`OES_texture_float_linear`),d=l?rE(e.radiusScene,e.cachedDist,r,u?ZE(s,c,l):c.max_level):-1;if(!l||d<3){KE(s,performance.now()),s.store||(s.kind=lD);return}d>c.max_level&&(s.kind=dD);let f=c.max_level;if(u)for(let e of c.patches??[])f=Math.max(f,e.max_level);$E(s,c,Math.min(yE(),f-3+1),d,l,e.radiusScene,void 0,n,i),a.uniforms.uReliefRead.value=s.kind===dD?fD:uD}var vD=32,yD=1,bD=2,xD=1.5,SD=4,CD=.04,wD=.02,TD=-.08,ED=.18,DD=`
|
|
5360
5360
|
if (byTiles > 0.005 && dot(normal, mat3(viewMatrix) * L) > 0.0) {
|
|
5361
5361
|
vec3 sunward = normalize(L * mat3(modelMatrix));
|
|
5362
5362
|
float up = dot(sunward, selfDir);
|
|
@@ -5364,7 +5364,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5364
5364
|
float run = length(along);
|
|
5365
5365
|
if (run > 1e-4) tileLight = reliefTileShadow(selfDir, selfMap, selfCap, selfSide, along / run, up / run, uSelfSunSize, selfFirst);
|
|
5366
5366
|
if (tileLight < 0.0) byTiles = 0.0;
|
|
5367
|
-
}`;function
|
|
5367
|
+
}`;function OD(e,t,n,r,i){let a=t.image,o=new q(1/(a?.width??4096),1/(a?.height??2048)),s=e.userData.selfShadow;if(s)return s.uSelfHeightMap.value=t,s.uSelfScale.value=n,s.uSelfTexel.value.copy(o),s;let c={uSelfHeightMap:{value:t},uSelfScale:{value:n},uSelfTexel:{value:o}};e.userData.selfShadow=c;let l=r??Mw().uSunDir;return HS(e,i?()=>`selfShadowTiles${bE()}`:`selfShadow`,e=>{let t=i?bE():0;Object.assign(e.uniforms,c,{uSelfSunDir:l},i?.uniforms),i&&(e.uniforms.uSelfSunSize=Mw().uSunAngularRadius),e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
|
|
5368
5368
|
varying vec3 vSelfWorldNormal;
|
|
5369
5369
|
varying vec2 vSelfUv;
|
|
5370
5370
|
varying vec3 vSelfDir;
|
|
@@ -5388,7 +5388,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5388
5388
|
vSelfNorthW = normalize(mat3(modelMatrix) * cross(nObj, eastObj));
|
|
5389
5389
|
vSelfRadiusW = length(mat3(modelMatrix) * position);
|
|
5390
5390
|
vSelfCosLat = cl;`),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
|
|
5391
|
-
#define SELF_STEPS ${
|
|
5391
|
+
#define SELF_STEPS ${vD}
|
|
5392
5392
|
uniform sampler2D uSelfHeightMap;
|
|
5393
5393
|
uniform float uSelfScale;
|
|
5394
5394
|
uniform vec2 uSelfTexel;
|
|
@@ -5403,7 +5403,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5403
5403
|
varying vec3 vSelfNorthW;
|
|
5404
5404
|
varying float vSelfRadiusW;
|
|
5405
5405
|
varying float vSelfCosLat;
|
|
5406
|
-
${i?
|
|
5406
|
+
${i?sD(t):``}
|
|
5407
5407
|
|
|
5408
5408
|
float selfHeight(vec2 uv) {
|
|
5409
5409
|
return texture2D(uSelfHeightMap, uv).r * uSelfScale;
|
|
@@ -5420,7 +5420,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5420
5420
|
// Wider-than-one-texel stencil averages out 8-bit terracing, floored
|
|
5421
5421
|
// at the low tier's texel so a higher-res map keeps the same
|
|
5422
5422
|
// physical smoothing width instead of flattening the relief.
|
|
5423
|
-
vec2 d = max(uSelfTexel, vec2(1.0 / 2048.0, 1.0 / 1024.0)) * ${
|
|
5423
|
+
vec2 d = max(uSelfTexel, vec2(1.0 / 2048.0, 1.0 / 1024.0)) * ${bD.toFixed(3)};
|
|
5424
5424
|
float hu = selfHeight(vSelfUv + vec2(d.x, 0.0))
|
|
5425
5425
|
- selfHeight(vSelfUv - vec2(d.x, 0.0));
|
|
5426
5426
|
float hv = selfHeight(vSelfUv + vec2(0.0, d.y))
|
|
@@ -5430,9 +5430,9 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5430
5430
|
float sv = hv / (2.0 * d.y * 3.14159265 * vSelfRadiusW);
|
|
5431
5431
|
// Fade at the poles, where the columns of the map close in and
|
|
5432
5432
|
// blow the east-west slope up into a starburst.
|
|
5433
|
-
float gain = ${
|
|
5434
|
-
su = clamp(su * gain, -${
|
|
5435
|
-
sv = clamp(sv * gain, -${
|
|
5433
|
+
float gain = ${yD.toFixed(3)} * smoothstep(0.0, 0.12, cosLat);
|
|
5434
|
+
su = clamp(su * gain, -${xD.toFixed(3)}, ${xD.toFixed(3)});
|
|
5435
|
+
sv = clamp(sv * gain, -${xD.toFixed(3)}, ${xD.toFixed(3)});
|
|
5436
5436
|
return east * su + north * sv;
|
|
5437
5437
|
}
|
|
5438
5438
|
|
|
@@ -5456,7 +5456,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5456
5456
|
float lv = dot(L, Tv / lenTv);
|
|
5457
5457
|
float lh = sqrt(lu * lu + lv * lv);
|
|
5458
5458
|
if (lh <= 1e-4) return 1.0;
|
|
5459
|
-
float ds = ${
|
|
5459
|
+
float ds = ${SD.toFixed(3)} * uSelfScale / float(SELF_STEPS);
|
|
5460
5460
|
// World step → uv step via the per-axis metric (|Tu|, |Tv|).
|
|
5461
5461
|
vec2 stepUv = ds * vec2((lu / lh) / lenTu, (lv / lh) / lenTv);
|
|
5462
5462
|
float h0 = selfHeight(vSelfUv);
|
|
@@ -5469,8 +5469,8 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5469
5469
|
}
|
|
5470
5470
|
// Fade the march out at grazing angles: a near-horizontal ray
|
|
5471
5471
|
// occludes every away-facing slope, banding the terminator.
|
|
5472
|
-
float marchFade = smoothstep(0.0, ${
|
|
5473
|
-
return 1.0 - marchFade * clamp(block / (${
|
|
5472
|
+
float marchFade = smoothstep(0.0, ${ED.toFixed(3)}, gN);
|
|
5473
|
+
return 1.0 - marchFade * clamp(block / (${CD.toFixed(3)} * uSelfScale), 0.0, 1.0);
|
|
5474
5474
|
}`).replace(`#include <normal_fragment_maps>`,`#include <normal_fragment_maps>
|
|
5475
5475
|
vec3 selfDir = normalize(vSelfDir);
|
|
5476
5476
|
// The part of the fragment that the tiles answer for.
|
|
@@ -5485,7 +5485,7 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5485
5485
|
${i?`slope = reliefTileSlope(selfDir, selfMap, selfCap, selfSide, selfCovered, selfFirst);`:``}
|
|
5486
5486
|
if (selfCovered < 0.995 && uSelfScale > 0.0) slope += (1.0 - selfCovered) * selfMapSlope(selfDir);
|
|
5487
5487
|
float steep = length(slope);
|
|
5488
|
-
if (steep > ${
|
|
5488
|
+
if (steep > ${xD.toFixed(3)}) slope *= ${xD.toFixed(3)} / steep;
|
|
5489
5489
|
normal = normalize(normalMatrix * (selfDir - slope));
|
|
5490
5490
|
}`).replace(`#include <lights_fragment_end>`,`#include <lights_fragment_end>
|
|
5491
5491
|
{
|
|
@@ -5495,21 +5495,21 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5495
5495
|
// Gate on the GEOMETRIC normal: the relief normal can tilt sunward
|
|
5496
5496
|
// past the terminator and light the night side. Fading direct light
|
|
5497
5497
|
// by geometric N·L keeps the night dark regardless.
|
|
5498
|
-
float shadow = smoothstep(${
|
|
5498
|
+
float shadow = smoothstep(${TD.toFixed(3)}, ${wD.toFixed(3)}, gN);
|
|
5499
5499
|
// Local crater self-shadow, lit hemisphere only — the macro gate owns
|
|
5500
5500
|
// the night side; the short march can't see that curvature.
|
|
5501
5501
|
if (shadow > 0.0 && gN > 0.0) {
|
|
5502
5502
|
// The part of the fragment whose shadow the tiles cast.
|
|
5503
5503
|
float byTiles = ${t>0?`selfCovered`:`0.0`};
|
|
5504
5504
|
float tileLight = 1.0;
|
|
5505
|
-
${t>0?
|
|
5505
|
+
${t>0?DD:``}
|
|
5506
5506
|
float mapLight = 1.0;
|
|
5507
5507
|
if (byTiles < 0.995 && uSelfScale > 0.0) mapLight = selfMapLight(L, gN);
|
|
5508
5508
|
shadow *= mix(mapLight, tileLight, byTiles);
|
|
5509
5509
|
}
|
|
5510
5510
|
reflectedLight.directDiffuse *= shadow;
|
|
5511
5511
|
reflectedLight.directSpecular *= shadow;
|
|
5512
|
-
}`)}),c}function OD(e){e&&(e.uSelfHeightMap.value=null,e.uSelfScale.value=0)}async function kD(e,t,n,r,i,a=Q(1)){let o=jD(t,n),s;try{s=await new Promise((e,t)=>{r.load(o,e,void 0,t)})}catch(e){return console.warn(`Failed to load displacement map ${o}:`,e),null}return s.colorSpace=``,e.displacementMap=s,AD(e,t,i,a),e.needsUpdate=!0,s}function AD(e,t,n,r=Q(1)){e.displacementScale=t.scale_km*r,e.displacementBias=t.bias_km*r-(t.absolute_radius?n:0)}function jD(e,t){return Qt(`/v1/textures/${e.id}/${t}.webp`,`textures`)}async function MD(e){try{let t=await fetch(e);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);return await createImageBitmap(await t.blob())}catch(t){return console.warn(`Failed to decode displacement map ${e}:`,t),null}}var ND=4e6;async function PD(e,t,n){let r=e.width,i=Math.max(1,Math.floor(ND/r)),a=document.createElement(`canvas`);a.width=r,a.height=Math.min(i,n-t+1);let o=a.getContext(`2d`,{willReadFrequently:!0});if(!o)return null;let s=new Uint8Array(r*(n-t+1));for(let a=t;a<=n;a+=i){let c=Math.min(i,n-a+1);o.drawImage(e,0,a,r,c,0,0,r,c);let l=o.getImageData(0,0,r,c).data,u=(a-t)*r;for(let e=0;e<r*c;e++)s[u+e]=l[e*4];!document.hidden&&a+i<=n&&await new Promise(e=>setTimeout(e))}return s}var FD=`pyramid`,ID=new WeakSet;function LD(e,t){let n=e.displacementMeta?.tiles;return!!n&&n.scale_km!==void 0&&Kt()!==``&&a(n.distribution)&&t.extensions.has(`OES_texture_float_linear`)&&!ID.has(e)}async function RD(e,t){let n=e.displacementMeta;if(!(!n||!e.mesh||e.displacementLoading||e.displacementTier===t)){e.displacementLoading=!0;try{let r=t===`pyramid`?await BD(e,n):await zD(n,t);if(!r)return;if(!e.mesh||!e.displacementMap){r.dispose();return}let i=e.mesh.material,a=i.displacementMap;i.displacementMap=r,e.displacementMap=r,e.displacementTier=t,e.selfShadow&&DD(i,r,Q(n.scale_km)),a&&a!==r&&a.dispose()}finally{e.displacementLoading=!1}}}async function zD(e,t){let n=await MD(jD(e,t));if(!n)return null;let r=n.width,i=n.height,a=await PD(n,0,i-1);if(n.close(),!a)return null;let o=new Uint8Array(r);for(let e=0;e<i>>1;e++){let t=a.subarray(e*r,(e+1)*r),n=a.subarray((i-1-e)*r,(i-e)*r);o.set(t),t.set(n),n.set(o)}let s=new rc(a,r,i,sr,Un);return s.colorSpace=``,s.magFilter=Bn,s.minFilter=Bn,s.generateMipmaps=!1,s.unpackAlignment=1,s.needsUpdate=!0,s}async function BD(e,t){if(!t.tiles)return null;try{return await VD(t,t.tiles)}catch(n){return console.warn(`Failed to load the height pyramid of ${t.id}:`,n),ID.add(e),null}}async function VD(e,t){let n=new AbortController().signal,r=await Promise.all([0,1].map(e=>KT(Jt(t,``,0,e,0),!0,n))),i=r[0].size,a=2*i,o=new Float32Array(a*i),s=(t.scale_km??0)/65535/e.scale_km,c=((t.bias_km??0)-e.bias_km)/e.scale_km;r.forEach(({heights:e},t)=>{for(let n=0;n<i;n++){let r=n*i,l=n*a+t*i;for(let t=0;t<i;t++)o[l+t]=e[r+t]*s+c}});let l=new rc(o,a,i,sr,Yn);return l.colorSpace=``,l.magFilter=Bn,l.minFilter=Hn,l.generateMipmaps=!1,l.mipmaps=HD(o,a,i),l.needsUpdate=!0,l}function HD(e,t,n){let r=[{data:e,width:t,height:n}];for(;t>1||n>1;){let i=Math.max(1,t>>1),a=Math.max(1,n>>1),o=t/i,s=n/a,c=new Float32Array(i*a);for(let n=0;n<a;n++)for(let r=0;r<i;r++){let a=0;for(let i=0;i<s;i++){let c=(n*s+i)*t+r*o;for(let t=0;t<o;t++)a+=e[c+t]}c[n*i+r]=a/(o*s)}r.push({data:c,width:i,height:a}),e=c,t=i,n=a}return r}function UD(e,t,n,r,i){let a=Math.floor(r),o=Math.floor(i),s=r-a,c=i-o,l=e=>(e%t+t)%t,u=e=>e<0?0:e>n-1?n-1:e,d=l(a),f=l(a+1),p=u(o)*t,m=u(o+1)*t,h=e[p+d]*(1-s)+e[p+f]*s,g=e[m+d]*(1-s)+e[m+f]*s,_=h*(1-c)+g*c;return e instanceof Float32Array?_:_/255}function WD(e){e.displacementMap&&(e.displacementMap.dispose(),e.displacementMap=null,e.displacementScale=1,e.displacementBias=0,e.needsUpdate=!0)}function GD(e,t){let n=0,r=e.length-2;for(;n<r;){let i=n+r+1>>1;e[i]<=t?n=i:r=i-1}return n}function KD(e,t){let n=Math.cos(e);return[n*Math.cos(t),Math.sin(e),-n*Math.sin(t)]}function qD(e,t,n,r,i,a,o){let s=(r+n)/r,[c,l,u]=KD(e,t);return[s*i*c,s*o*l,s*a*u]}function JD(e,t,n){if(e.kind===`uniform`){let r=e.segs,i=(Math.PI/2-t)*r/Math.PI,a=Math.min(Math.max(Math.floor(i),0),r-1),o=Math.min(Math.max(i-a,0),1),s=(n-Math.PI)*r/(2*Math.PI),c=Math.floor(s),l=s-c;return{corners:[[a,c],[a,c+1],[a+1,c],[a+1,c+1]].map(([e,t])=>({latRad:Math.PI/2-Math.min(e,r)*Math.PI/r,lonRad:Math.PI+t*2*Math.PI/r})),tx:l,ty:o}}let{thetas:r,phis:i,riseKm:a}=e,o=Math.PI/2-t,s=(n-Math.PI)%(2*Math.PI);s<0&&(s+=2*Math.PI);let c=GD(r,o),l=GD(i,s),u=Math.min(Math.max((o-r[c])/(r[c+1]-r[c]),0),1),d=Math.min(Math.max((s-i[l])/(i[l+1]-i[l]),0),1);return{corners:[[c,l],[c,l+1],[c+1,l],[c+1,l+1]].map(([e,t])=>({latRad:Math.PI/2-r[e],lonRad:i[t]+Math.PI,riseKm:a?.[e*i.length+t]})),tx:d,ty:u}}function YD(e,t,n){let[r,i,a,o]=e,s=[0,0,0];for(let e=0;e<3;e++)s[e]=t>=n?r[e]+(i[e]-r[e])*t+(o[e]-i[e])*n:r[e]+(o[e]-a[e])*t+(a[e]-r[e])*n;return s}function XD(e,t,n){let[r,i,a]=t>=n?[e[0],e[1],e[3]]:[e[0],e[2],e[3]],o=[i[0]-r[0],i[1]-r[1],i[2]-r[2]],s=[a[0]-r[0],a[1]-r[1],a[2]-r[2]];return{p0:r,n:[o[1]*s[2]-o[2]*s[1],o[2]*s[0]-o[0]*s[2],o[0]*s[1]-o[1]*s[0]]}}function ZD(e,t,n){let{p0:r,n:i}=XD(e,t,n),a=Math.hypot(i[0],i[1],i[2]);if(a<1e-12){let e=Math.hypot(r[0],r[1],r[2]);return[r[0]/e,r[1]/e,r[2]/e]}let o=i[0]*r[0]+i[1]*r[1]+i[2]*r[2]<0?-1/a:1/a;return[i[0]*o,i[1]*o,i[2]*o]}var QD=new Map,$D=new Map,eO=0;function tO(){return eO}var nO=6;function rO(){let e=0;for(let t of QD.values())t!==`failed`&&e++;for(let[t,n]of QD){if(e<=nO)break;n!==`failed`&&(QD.delete(t),e--)}}function iO(e,t){let n=$D.get(e);return n||(n=(async()=>{let n=await MD(jD(t,`low`)),r=n&&await PD(n,0,n.height-1);if(!n||!r)return n?.close(),QD.set(e,`failed`),null;let i={data:r,width:n.width,height:n.height,bottomUp:!1};return n.close(),QD.set(e,i),rO(),eO++,i})(),n.finally(()=>$D.delete(e)),$D.set(e,n),n)}function aO(e,t){let n=e.displacementMap?.image;if(!n)return null;let r=n.data;if((r instanceof Uint8Array||r instanceof Float32Array)&&n.width&&n.height)return{data:r,width:n.width,height:n.height,bottomUp:!0};let i=QD.get(t);if(i&&i!==`failed`)return QD.delete(t),QD.set(t,i),i;let a=e.displacementMeta;return!i&&a&&iO(t,a),null}function oO(e,t,n){let r=.5+n/(2*Math.PI),i=.5+t/Math.PI,a=(r-Math.floor(r))*e.width-.5,o=(e.bottomUp?i:1-i)*e.height-.5;return UD(e.data,e.width,e.height,a,o)}async function sO(e,t,n,r,i){let a=(e&&aO(e,t))??await iO(t,n);if(!a)return null;let o=n.bias_km-(n.absolute_radius?r:0),s=new Float64Array(i.length);for(let e=0;e<i.length;e++)s[e]=oO(a,i[e].latRad,i[e].lonRad)*n.scale_km+o;return s}var cO=new Map,lO=new Set;function uO(e,t){return cO.get(e)||(lO.has(e)||(lO.add(e),(async()=>{try{let n=(await tS(e,!1)).global;cO.set(e,n?.radii??{a:t,b:t,c:t})}catch(n){console.warn(`Failed to load radii for ${e}:`,n),cO.set(e,{a:t,b:t,c:t})}finally{lO.delete(e),eO++}})()),null)}function dO(e){let t=e?.terrainWindow;return t?{kind:`window`,thetas:t.thetas,phis:t.phis,riseKm:t.riseKm}:{kind:`uniform`,segs:e?.currentSegments??128}}function fO(e,t,n,r,i){let a=uO(t,n);if(!a)return null;let o=dO(e),s=null,c=0,l=0,u=e?.displacementMeta,d=o.kind===`window`&&!!o.riseKm;if(u&&e?.displacementMap&&!d){if(s=aO(e,t),!s)return null;c=u.scale_km,l=u.bias_km-(u.absolute_radius?n:0)}let{corners:f,tx:p,ty:m}=JD(o,r,i);return{pts:f.map(e=>{let t=e.riseKm??(s?oO(s,e.latRad,e.lonRad)*c+l:0);return qD(e.latRad,e.lonRad,t,n,a.a,a.b,a.c)}),tx:p,ty:m}}function pO(e,t,n,r,i){let a=fO(e,t,n,r,i);return a?{pointKm:YD(a.pts,a.tx,a.ty),normal:ZD(a.pts,a.tx,a.ty)}:null}function mO(e,t,n,r){let i=uO(t,n);if(!i)return null;let a=fO(e,t,n,Math.atan2(r[1]/i.c,Math.hypot(r[0]/i.a,r[2]/i.b)),Math.atan2(-r[2]/i.b,r[0]/i.a));if(!a)return null;let{p0:o,n:s}=XD(a.pts,a.tx,a.ty),c=r[0]*s[0]+r[1]*s[1]+r[2]*s[2];if(Math.abs(c)<1e-12)return null;let l=(o[0]*s[0]+o[1]*s[1]+o[2]*s[2])/c;return l>0?l:null}function hO(e,t,n){let r=e[t];return r||(r=n(),e[t]=r),r}function gO(e){switch(e){case G.STAR:return 0;case G.PLANET:return 1;case G.DWARF_PLANET:return 2;case G.MOON:return 3;default:return 4}}function _O(e){return e.body.position!==null&&!e.carried}var vO=new J,yO=22;function bO(){return{cx0:0,cy0:0,f:0,gxx:0,gxy:0,gxz:0,gyx:0,gyy:0,gyz:0,gzx:0,gzy:0,gzz:0,cpx:0,cpy:0,cpz:0,K:0,id:``,dist:0,ccx:0,ccy:0,ccz:0}}var xO=new WeakMap;function SO(e){xO.delete(e)}function CO(e,t,n,r=.3,i=null){if(e){let t=`d${r}${+!!n}`;if(xO.get(e)===t)return;xO.set(e,t),e.style.transform=`scale(${r})`,e.parentElement&&(e.parentElement.style.pointerEvents=n?``:`none`)}t&&(t.style.display=`none`,t.style.fontSize=``),i&&(i.style.display=`none`)}function wO(e,t,n,r,i=null){if(e){let t=`r${+!!n}${+!!r}`;if(xO.get(e)===t)return;xO.set(e,t),n||(e.style.transform=``),e.style.border=e.dataset.origBorder??``,e.parentElement&&(e.parentElement.style.pointerEvents=``)}t&&(t.style.display=``,t.style.fontSize=r?`18px`:``),i&&(i.style.display=``)}function TO(e,t,n,r,i,a){let{label:o,labelHalo:s,radiusScene:c}=e;if(!o)return!1;let l=o.visible,u=!e.noPhysical&&c>0?c/r*i:0,d=e.body.data.id===a,f=u>=16;return!t&&n&&(d||u>=1)&&(t=u<320),f&&e.labelAnchorOffscreen&&(t=!1),e.trail&&f&&(e.trail.visible=!1),o.visible=t,s&&e.haloHidden!==f&&(s.style.visibility=f?`hidden`:``,e.haloHidden=f),e.loadingEl&&e.loadingShown!==f&&(e.loadingEl.style.display=f?``:`none`,e.loadingShown=f),o.center.x=f?1-4/32:.5,t&&!l}function EO(e,t,n,r,i,a=null){for(let o of i){if(o.id===r||o.id===a)continue;let i=e-o.cx0,s=o.cy0-t,c=-o.f,l=i*o.gxx+s*o.gxy+c*o.gxz,u=i*o.gyx+s*o.gyy+c*o.gyz,d=i*o.gzx+s*o.gzy+c*o.gzz,f=l*o.cpx+u*o.cpy+d*o.cpz;if(!(f<=0)&&!(f*f<=o.K*(l*l+u*u+d*d))&&i*o.ccx+s*o.ccy+c*o.ccz<=n*Math.hypot(i,s,c))return!0}return!1}function DO(e,t){e.left=t.left,e.right=t.right,e.y=t.y,e.h=t.h}function OO(e,t,n,r,i,a){let o=e.label,s=e.body.position;if(!s)return!1;let[c,l,u]=s,d=o.position;vO.set(c-n[0]+d.x,l-n[1]+d.y,u-n[2]+d.z),vO.project(t),a.x=(vO.x*.5+.5)*r,a.y=(-vO.y*.5+.5)*i;let f=a.x-o.center.x*32;return a.left=f,a.right=f+40+(e.labelTextWidth||50),a.h=yO,bw(vO.z)}var kO=[],AO=0,jO=[],MO=0,NO=[],PO=0,FO={rects:jO,get count(){return MO}};function IO(){return{bodyId:``,bo:null,body:null,label:null,labelHalo:null,isCapped:!1,isMinor:!1,isFocused:!1,isSelected:!1,rect:{x:0,left:0,right:0,y:0,h:0},dist:0}}function LO(){return{left:0,right:0,y:0,h:0}}var RO={x:0,left:0,right:0,y:0,h:0};function zO(e,t){for(let n=0;n<t;n++)DO(hO(NO,n,LO),e[n]);PO=t}function BO(){for(let e=0;e<PO;e++)DO(hO(jO,e,LO),NO[e]);return PO}function VO(e,t,n,r,i,a,o,s,c=[0,0,0]){AO=0,MO=BO();for(let s of e.values()){let{body:e,label:l,labelHalo:u}=s;if(!l?.visible)continue;if(!s.labelTextWidth&&u){let e=u.nextElementSibling;e&&e.offsetWidth>0&&(s.labelTextWidth=e.offsetWidth)}if(!OO(s,r,c,t,n,RO))continue;let d=e.data.id===i,f=o.has(e.data.id),p=hO(kO,AO++,IO);DO(p.rect,RO),p.rect.x=RO.x,p.bodyId=e.data.id,p.bo=s,p.body=e,p.label=l,p.labelHalo=u,p.isCapped=e.data.objectType===G.MOON?a.visibility.getMoonVisibility(e)===$.CAPPED:!1,p.isMinor=s.isMinor,p.isFocused=d,p.isSelected=d||f||a.visibility.isPinned(e.data.id),p.dist=s.cachedDist}kO.length=AO,kO.sort((e,t)=>{if(e.isSelected!==t.isSelected)return e.isSelected?-1:1;let n=e.isMinor&&!e.isSelected;if(n!==(t.isMinor&&!t.isSelected))return n?1:-1;let r=gO(e.body.data.objectType),i=gO(t.body.data.objectType);return r===i?e.dist-t.dist:r-i});for(let e=0;e<AO;e++){let t=kO[e],n=t.labelHalo,r=n?.nextElementSibling;if(t.isCapped&&!t.isSelected){CO(n,r,!0,.3,t.bo.labelStack),t.bo.labelMaximized=!1;continue}if(!t.isSelected&&EO(t.rect.x,t.rect.y,t.dist,t.bodyId,s)){t.label.visible=!1,t.bo.labelMaximized=!1;continue}if(t.isMinor&&!t.isSelected){let e=!1;for(let n=0;n<MO;n++){let r=jO[n];if(t.rect.x-8<r.right&&t.rect.x+8>r.left&&Math.abs(t.rect.y-r.y)<yO){e=!0;break}}CO(n,r,!e,e?.3:.5,t.bo.labelStack),t.bo.labelMaximized=!1;continue}let i=!1;for(let e=0;e<MO;e++){let n=jO[e];if(t.rect.left<n.right&&t.rect.right>n.left&&Math.abs(t.rect.y-n.y)<yO){i=!0;break}}i?(CO(n,r,!1,.3,t.bo.labelStack),t.bo.labelMaximized=!1):(DO(hO(jO,MO++,LO),t.rect),wO(n,r,o.has(t.bodyId),t.isFocused,t.bo.labelStack),t.bo.labelMaximized=!0)}for(let e=0;e<AO;e++){let t=kO[e];t.bo=null,t.body=null,t.label=null,t.labelHalo=null}}function HO(e,t,n,r,i){MO=BO();for(let a of e.values())a.label?.visible&&a.labelMaximized!==!1&&OO(a,r,i,t,n,RO)&&DO(hO(jO,MO++,LO),RO)}function UO(e,t){if(t===0)return console.warn(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.`),e;if(t===2||t===1){let n=e.getIndex();if(n===null){let t=[],r=e.getAttribute(`position`);if(r!==void 0){for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.`),e}let r=n.count-2,i=[];if(t===2)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));i.length/3!==r&&console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.`);let a=e.clone();return a.setIndex(i),a.clearGroups(),a}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:`,t),e}function WO(e){let t=new Map,n=new Map,r=e.clone();return GO(e,r,function(e,r){t.set(r,e),n.set(e,r)}),r.traverse(function(e){if(!e.isSkinnedMesh)return;let r=e,i=t.get(e),a=i.skeleton.bones;r.skeleton=i.skeleton.clone(),r.bindMatrix.copy(i.bindMatrix),r.skeleton.bones=a.map(function(e){return n.get(e)}),r.bind(r.skeleton,r.bindMatrix)}),r}function GO(e,t,n){n(e,t);for(let r=0;r<e.children.length;r++)GO(e.children[r],t.children[r],n)}var KO=class extends td{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new $O(e)}),this.register(function(e){return new ek(e)}),this.register(function(e){return new lk(e)}),this.register(function(e){return new uk(e)}),this.register(function(e){return new dk(e)}),this.register(function(e){return new nk(e)}),this.register(function(e){return new rk(e)}),this.register(function(e){return new ik(e)}),this.register(function(e){return new ak(e)}),this.register(function(e){return new QO(e)}),this.register(function(e){return new ok(e)}),this.register(function(e){return new tk(e)}),this.register(function(e){return new ck(e)}),this.register(function(e){return new sk(e)}),this.register(function(e){return new XO(e)}),this.register(function(e){return new fk(e,YO.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new fk(e,YO.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new pk(e)})}load(e,t,n,r){let i=this,a;if(this.resourcePath!==``)a=this.resourcePath;else if(this.path!==``){let t=kd.extractUrlBase(e);a=kd.resolveURL(t,this.path)}else a=kd.extractUrlBase(e);this.manager.itemStart(e);let o=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},s=new id(this.manager);s.setPath(this.path),s.setResponseType(`arraybuffer`),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,function(n){try{i.parse(n,a,function(n){t(n),i.manager.itemEnd(e)},o)}catch(e){o(e)}},n,o)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i,a={},o={},s=new TextDecoder;if(typeof e==`string`)i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(s.decode(new Uint8Array(e,0,4))===mk){try{a[YO.KHR_BINARY_GLTF]=new _k(e)}catch(e){r&&r(e);return}i=JSON.parse(a[YO.KHR_BINARY_GLTF].content)}else i=JSON.parse(s.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){r&&r(Error(`THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.`));return}let c=new Uk(i,{path:t||this.resourcePath||``,crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){let t=this.pluginCallbacks[e](c);t.name||console.error(`THREE.GLTFLoader: Invalid plugin found: missing name`),o[t.name]=t,a[t.name]=!0}if(i.extensionsUsed)for(let e=0;e<i.extensionsUsed.length;++e){let t=i.extensionsUsed[e],n=i.extensionsRequired||[];switch(t){case YO.KHR_MATERIALS_UNLIT:a[t]=new ZO;break;case YO.KHR_DRACO_MESH_COMPRESSION:a[t]=new vk(i,this.dracoLoader);break;case YO.KHR_TEXTURE_TRANSFORM:a[t]=new yk;break;case YO.KHR_MESH_QUANTIZATION:a[t]=new bk;break;default:n.indexOf(t)>=0&&o[t]===void 0&&console.warn(`THREE.GLTFLoader: Unknown extension "`+t+`".`)}}c.setExtensions(a),c.setPlugins(o),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}};function qO(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}function JO(e,t,n){let r=e.json.materials[t];return r.extensions&&r.extensions[n]?r.extensions[n]:null}var YO={KHR_BINARY_GLTF:`KHR_binary_glTF`,KHR_DRACO_MESH_COMPRESSION:`KHR_draco_mesh_compression`,KHR_LIGHTS_PUNCTUAL:`KHR_lights_punctual`,KHR_MATERIALS_CLEARCOAT:`KHR_materials_clearcoat`,KHR_MATERIALS_DISPERSION:`KHR_materials_dispersion`,KHR_MATERIALS_IOR:`KHR_materials_ior`,KHR_MATERIALS_SHEEN:`KHR_materials_sheen`,KHR_MATERIALS_SPECULAR:`KHR_materials_specular`,KHR_MATERIALS_TRANSMISSION:`KHR_materials_transmission`,KHR_MATERIALS_IRIDESCENCE:`KHR_materials_iridescence`,KHR_MATERIALS_ANISOTROPY:`KHR_materials_anisotropy`,KHR_MATERIALS_UNLIT:`KHR_materials_unlit`,KHR_MATERIALS_VOLUME:`KHR_materials_volume`,KHR_TEXTURE_BASISU:`KHR_texture_basisu`,KHR_TEXTURE_TRANSFORM:`KHR_texture_transform`,KHR_MESH_QUANTIZATION:`KHR_mesh_quantization`,KHR_MATERIALS_EMISSIVE_STRENGTH:`KHR_materials_emissive_strength`,EXT_MATERIALS_BUMP:`EXT_materials_bump`,EXT_TEXTURE_WEBP:`EXT_texture_webp`,EXT_TEXTURE_AVIF:`EXT_texture_avif`,EXT_MESHOPT_COMPRESSION:`EXT_meshopt_compression`,KHR_MESHOPT_COMPRESSION:`KHR_meshopt_compression`,EXT_MESH_GPU_INSTANCING:`EXT_mesh_gpu_instancing`},XO=class{constructor(e){this.parser=e,this.name=YO.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){let t=this.parser,n=`light:`+e,r=t.cache.get(n);if(r)return r;let i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e],o,s=new X(16777215);a.color!==void 0&&s.setRGB(a.color[0],a.color[1],a.color[2],ii);let c=a.range===void 0?0:a.range;switch(a.type){case`directional`:o=new Dd(s),o.target.position.set(0,0,-1),o.add(o.target);break;case`point`:o=new wd(s),o.distance=c;break;case`spot`:o=new Sd(s),o.distance=c,a.spot=a.spot||{},a.spot.innerConeAngle=a.spot.innerConeAngle===void 0?0:a.spot.innerConeAngle,a.spot.outerConeAngle=a.spot.outerConeAngle===void 0?Math.PI/4:a.spot.outerConeAngle,o.angle=a.spot.outerConeAngle,o.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,o.target.position.set(0,0,-1),o.add(o.target);break;default:throw Error(`THREE.GLTFLoader: Unexpected light type: `+a.type)}return o.position.set(0,0,0),Fk(o,a),a.intensity!==void 0&&(o.intensity=a.intensity),o.name=t.createUniqueName(a.name||`light_`+e),r=Promise.resolve(o),t.cache.add(n,r),r}getDependency(e,t){if(e===`light`)return this._loadLight(t)}createNodeAttachment(e){let t=this,n=this.parser,r=n.json.nodes[e],i=(r.extensions&&r.extensions[this.name]||{}).light;return i===void 0?null:this._loadLight(i).then(function(e){return n._getNodeRef(t.cache,i,e)})}},ZO=class{constructor(){this.name=YO.KHR_MATERIALS_UNLIT}getMaterialType(){return js}extendParams(e,t,n){let r=[];e.color=new X(1,1,1),e.opacity=1;let i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){let t=i.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],ii),e.opacity=t[3]}i.baseColorTexture!==void 0&&r.push(n.assignTexture(e,`map`,i.baseColorTexture,ri))}return Promise.all(r)}},QO=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}},$O=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatMap`,n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatRoughnessMap`,n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(this.parser.assignTexture(t,`clearcoatNormalMap`,n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){let e=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new q(e,e)}return Promise.all(r)}},ek=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_DISPERSION}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion===void 0?0:n.dispersion),Promise.resolve()}},tk=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceMap`,n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceThicknessMap`,n.iridescenceThicknessTexture)),Promise.all(r)}},nk=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_SHEEN}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(t.sheenColor=new X(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){let e=n.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],ii)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenColorMap`,n.sheenColorTexture,ri)),n.sheenRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenRoughnessMap`,n.sheenRoughnessTexture)),Promise.all(r)}},rk=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(this.parser.assignTexture(t,`transmissionMap`,n.transmissionTexture)),Promise.all(r)}},ik=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_VOLUME}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.thickness=n.thicknessFactor===void 0?0:n.thicknessFactor,n.thicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`thicknessMap`,n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;let i=n.attenuationColor||[1,1,1];return t.attenuationColor=new X().setRGB(i[0],i[1],i[2],ii),Promise.all(r)}},ak=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_IOR}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);return n===null||(t.ior=n.ior===void 0?1.5:n.ior),Promise.resolve()}},ok=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_SPECULAR}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.specularIntensity=n.specularFactor===void 0?1:n.specularFactor,n.specularTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularIntensityMap`,n.specularTexture));let i=n.specularColorFactor||[1,1,1];return t.specularColor=new X().setRGB(i[0],i[1],i[2],ii),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularColorMap`,n.specularColorTexture,ri)),Promise.all(r)}},sk=class{constructor(e){this.parser=e,this.name=YO.EXT_MATERIALS_BUMP}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.bumpScale=n.bumpFactor===void 0?1:n.bumpFactor,n.bumpTexture!==void 0&&r.push(this.parser.assignTexture(t,`bumpMap`,n.bumpTexture)),Promise.all(r)}},ck=class{constructor(e){this.parser=e,this.name=YO.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return JO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=JO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(this.parser.assignTexture(t,`anisotropyMap`,n.anisotropyTexture)),Promise.all(r)}},lk=class{constructor(e){this.parser=e,this.name=YO.KHR_TEXTURE_BASISU}loadTexture(e){let t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;let i=r.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures`);return null}return t.loadTextureImage(e,i.source,a)}},uk=class{constructor(e){this.parser=e,this.name=YO.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},dk=class{constructor(e){this.parser=e,this.name=YO.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},fk=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let e=n.extensions[this.name],r=this.parser.getDependency(`buffer`,e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files`);return null}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,a=e.count,o=e.byteStride,s=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(a,o,s,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(a*o);return i.decodeGltfBuffer(new Uint8Array(t),a,o,s,e.mode,e.filter),t})})}else return null}},pk=class{constructor(e){this.name=YO.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==wk.TRIANGLES&&e.mode!==wk.TRIANGLE_STRIP&&e.mode!==wk.TRIANGLE_FAN&&e.mode!==void 0)return null;let i=n.extensions[this.name].attributes,a=[],o={};for(let e in i)a.push(this.parser.getDependency(`accessor`,i[e]).then(t=>(o[e]=t,o[e])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new Y,n=new J,a=new Xi,s=new J(1,1,1),c=new hc(e.geometry,e.material,r);for(let e=0;e<r;e++)o.TRANSLATION&&n.fromBufferAttribute(o.TRANSLATION,e),o.ROTATION&&a.fromBufferAttribute(o.ROTATION,e),o.SCALE&&s.fromBufferAttribute(o.SCALE,e),c.setMatrixAt(e,t.compose(n,a,s));for(let t in o)if(t===`_COLOR_0`){let e=o[t];c.instanceColor=new sc(e.array,e.itemSize,e.normalized)}else t!==`TRANSLATION`&&t!==`ROTATION`&&t!==`SCALE`&&e.geometry.setAttribute(t,o[t]);Ka.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),i.push(c)}return t.isGroup?(t.clear(),t.add(...i),t):i[0]}))}},mk=`glTF`,hk=12,gk={JSON:1313821514,BIN:5130562},_k=class{constructor(e){this.name=YO.KHR_BINARY_GLTF,this.content=null,this.body=null;let t=new DataView(e,0,hk),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==mk)throw Error(`THREE.GLTFLoader: Unsupported glTF-Binary header.`);if(this.header.version<2)throw Error(`THREE.GLTFLoader: Legacy binary file detected.`);let r=this.header.length-hk,i=new DataView(e,hk),a=0;for(;a<r;){let t=i.getUint32(a,!0);a+=4;let r=i.getUint32(a,!0);if(a+=4,r===gk.JSON){let r=new Uint8Array(e,hk+a,t);this.content=n.decode(r)}else if(r===gk.BIN){let n=hk+a;this.body=e.slice(n,n+t)}a+=t}if(this.content===null)throw Error(`THREE.GLTFLoader: JSON content not found.`)}},vk=class{constructor(e,t){if(!t)throw Error(`THREE.GLTFLoader: No DRACOLoader instance provided.`);this.name=YO.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){let n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,o={},s={},c={};for(let e in a){let t=kk[e]||e.toLowerCase();o[t]=a[e]}for(let t in e.attributes){let r=kk[t]||t.toLowerCase();if(a[t]!==void 0){let i=n.accessors[e.attributes[t]];c[r]=Tk[i.componentType].name,s[r]=i.normalized===!0}}return t.getDependency(`bufferView`,i).then(function(e){return new Promise(function(t,n){r.decodeDracoFile(e,function(e){for(let t in e.attributes){let n=e.attributes[t],r=s[t];r!==void 0&&(n.normalized=r)}t(e)},o,c,ii,n)})})}},yk=class{constructor(){this.name=YO.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0?e:(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e)}},bk=class{constructor(){this.name=YO.KHR_MESH_QUANTIZATION}},xk=class extends Iu{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let e=0;e!==r;e++)t[e]=n[i+e];return t}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=o*2,c=o*3,l=r-t,u=(n-t)/l,d=u*u,f=d*u,p=e*c,m=p-c,h=-2*f+3*d,g=f-d,_=1-h,v=g-d+u;for(let e=0;e!==o;e++){let t=a[m+e+o],n=a[m+e+s]*l,r=a[p+e+o],c=a[p+e]*l;i[e]=_*t+v*n+h*r+g*c}return i}},Sk=new Xi,Ck=class extends xk{interpolate_(e,t,n,r){let i=super.interpolate_(e,t,n,r);return Sk.fromArray(i).normalize().toArray(i),i}},wk={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},Tk={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Ek={9728:Ln,9729:Bn,9984:Rn,9985:Vn,9986:zn,9987:Hn},Dk={33071:Fn,33648:In,10497:Pn},Ok={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},kk={POSITION:`position`,NORMAL:`normal`,TANGENT:`tangent`,TEXCOORD_0:`uv`,TEXCOORD_1:`uv1`,TEXCOORD_2:`uv2`,TEXCOORD_3:`uv3`,COLOR_0:`color`,WEIGHTS_0:`skinWeight`,JOINTS_0:`skinIndex`},Ak={scale:`scale`,translation:`position`,rotation:`quaternion`,weights:`morphTargetInfluences`},jk={CUBICSPLINE:void 0,LINEAR:Yr,STEP:Jr},Mk={OPAQUE:`OPAQUE`,MASK:`MASK`,BLEND:`BLEND`};function Nk(e){return e.DefaultMaterial===void 0&&(e.DefaultMaterial=new Du({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:0})),e.DefaultMaterial}function Pk(e,t,n){for(let r in n.extensions)e[r]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=n.extensions[r])}function Fk(e,t){t.extras!==void 0&&(typeof t.extras==`object`?Object.assign(e.userData,t.extras):console.warn(`THREE.GLTFLoader: Ignoring primitive type .extras, `+t.extras))}function Ik(e,t,n){let r=!1,i=!1,a=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];if(n.POSITION!==void 0&&(r=!0),n.NORMAL!==void 0&&(i=!0),n.COLOR_0!==void 0&&(a=!0),r&&i&&a)break}if(!r&&!i&&!a)return Promise.resolve(e);let o=[],s=[],c=[];for(let l=0,u=t.length;l<u;l++){let u=t[l];if(r){let t=u.POSITION===void 0?e.attributes.position:n.getDependency(`accessor`,u.POSITION);o.push(t)}if(i){let t=u.NORMAL===void 0?e.attributes.normal:n.getDependency(`accessor`,u.NORMAL);s.push(t)}if(a){let t=u.COLOR_0===void 0?e.attributes.color:n.getDependency(`accessor`,u.COLOR_0);c.push(t)}}return Promise.all([Promise.all(o),Promise.all(s),Promise.all(c)]).then(function(t){let n=t[0],o=t[1],s=t[2];return r&&(e.morphAttributes.position=n),i&&(e.morphAttributes.normal=o),a&&(e.morphAttributes.color=s),e.morphTargetsRelative=!0,e})}function Lk(e,t){if(e.updateMorphTargets(),t.weights!==void 0)for(let n=0,r=t.weights.length;n<r;n++)e.morphTargetInfluences[n]=t.weights[n];if(t.extras&&Array.isArray(t.extras.targetNames)){let n=t.extras.targetNames;if(e.morphTargetInfluences.length===n.length){e.morphTargetDictionary={};for(let t=0,r=n.length;t<r;t++)e.morphTargetDictionary[n[t]]=t}else console.warn(`THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.`)}}function Rk(e){let t,n=e.extensions&&e.extensions[YO.KHR_DRACO_MESH_COMPRESSION];if(t=n?`draco:`+n.bufferView+`:`+n.indices+`:`+zk(n.attributes):e.indices+`:`+zk(e.attributes)+`:`+e.mode,e.targets!==void 0)for(let n=0,r=e.targets.length;n<r;n++)t+=`:`+zk(e.targets[n]);return t}function zk(e){let t=``,n=Object.keys(e).sort();for(let r=0,i=n.length;r<i;r++)t+=n[r]+`:`+e[n[r]]+`;`;return t}function Bk(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw Error(`THREE.GLTFLoader: Unsupported normalized accessor component type.`)}}function Vk(e){return e.search(/\.jpe?g($|\?)/i)>0||e.search(/^data\:image\/jpeg/)===0?`image/jpeg`:e.search(/\.webp($|\?)/i)>0||e.search(/^data\:image\/webp/)===0?`image/webp`:e.search(/\.ktx2($|\?)/i)>0||e.search(/^data\:image\/ktx2/)===0?`image/ktx2`:`image/png`}var Hk=new Y,Uk=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new qO,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,i=!1,a=-1;if(typeof navigator<`u`&&navigator.userAgent!==void 0){let e=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(e)===!0;let t=e.match(/Version\/(\d+)/);r=n&&t?parseInt(t[1],10):-1,i=e.indexOf(`Firefox`)>-1,a=i?e.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>`u`||n&&r<17||i&&a<98?this.textureLoader=new sd(this.options.manager):this.textureLoader=new jd(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new id(this.options.manager),this.fileLoader.setResponseType(`arraybuffer`),this.options.crossOrigin===`use-credentials`&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies(`scene`),n.getDependencies(`animation`),n.getDependencies(`camera`)])}).then(function(t){let a={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return Pk(i,a,r),Fk(a,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(a)})).then(function(){for(let e of a.scenes)e.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n].joints;for(let t=0,n=r.length;t<n;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){let r=e[t];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(n[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;let r=n.clone(),i=(e,t)=>{let n=this.associations.get(e);n!=null&&this.associations.set(t,n);for(let[n,r]of e.children.entries())i(r,t.children[n])};return i(n,r),r.name+=`_instance_`+ e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){let r=e(t[n]);if(r)return r}return null}_invokeAll(e){let t=Object.values(this.plugins);t.unshift(this);let n=[];for(let r=0;r<t.length;r++){let i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){let n=e+`:`+t,r=this.cache.get(n);if(!r){switch(e){case`scene`:r=this.loadScene(t);break;case`node`:r=this._invokeOne(function(e){return e.loadNode&&e.loadNode(t)});break;case`mesh`:r=this._invokeOne(function(e){return e.loadMesh&&e.loadMesh(t)});break;case`accessor`:r=this.loadAccessor(t);break;case`bufferView`:r=this._invokeOne(function(e){return e.loadBufferView&&e.loadBufferView(t)});break;case`buffer`:r=this.loadBuffer(t);break;case`material`:r=this._invokeOne(function(e){return e.loadMaterial&&e.loadMaterial(t)});break;case`texture`:r=this._invokeOne(function(e){return e.loadTexture&&e.loadTexture(t)});break;case`skin`:r=this.loadSkin(t);break;case`animation`:r=this._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case`camera`:r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!r)throw Error(`Unknown type: `+e);break}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){let n=this,r=this.json[e+(e===`mesh`?`es`:`s`)]||[];t=Promise.all(r.map(function(t,r){return n.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){let t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!==`arraybuffer`)throw Error(`THREE.GLTFLoader: `+t.type+` buffer type is not supported.`);if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[YO.KHR_BINARY_GLTF].body);let r=this.options;return new Promise(function(e,i){n.load(kd.resolveURL(t.uri,r.path),e,void 0,function(){i(Error(`THREE.GLTFLoader: Failed to load buffer "`+t.uri+`".`))})})}loadBufferView(e){let t=this.json.bufferViews[e];return this.getDependency(`buffer`,t.buffer).then(function(e){let n=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+n)})}loadAccessor(e){let t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){let e=Ok[r.type],t=Tk[r.componentType],n=r.normalized===!0,i=new t(r.count*e);return Promise.resolve(new Bo(i,e,n))}let i=[];return r.bufferView===void 0?i.push(null):i.push(this.getDependency(`bufferView`,r.bufferView)),r.sparse!==void 0&&(i.push(this.getDependency(`bufferView`,r.sparse.indices.bufferView)),i.push(this.getDependency(`bufferView`,r.sparse.values.bufferView))),Promise.all(i).then(function(e){let i=e[0],a=Ok[r.type],o=Tk[r.componentType],s=o.BYTES_PER_ELEMENT,c=s*a,l=r.byteOffset||0,u=r.bufferView===void 0?void 0:n.bufferViews[r.bufferView].byteStride,d=r.normalized===!0,f,p;if(u&&u!==c){let e=Math.floor(l/u),n=`InterleavedBuffer:`+r.bufferView+`:`+r.componentType+`:`+e+`:`+r.count,c=t.cache.get(n);c||(f=new o(i,e*u,r.count*u/s),c=new ns(f,u/s),t.cache.add(n,c)),p=new is(c,a,l%u/s,d)}else f=i===null?new o(r.count*a):new o(i,l,r.count*a),p=new Bo(f,a,d);if(r.sparse!==void 0){let t=Ok.SCALAR,n=Tk[r.sparse.indices.componentType],s=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,l=new n(e[1],s,r.sparse.count*t),u=new o(e[2],c,r.sparse.count*a);i!==null&&(p=new Bo(p.array.slice(),p.itemSize,p.normalized)),p.normalized=!1;for(let e=0,t=l.length;e<t;e++){let t=l[e];if(p.setX(t,u[e*a]),a>=2&&p.setY(t,u[e*a+1]),a>=3&&p.setZ(t,u[e*a+2]),a>=4&&p.setW(t,u[e*a+3]),a>=5)throw Error(`THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.`)}p.normalized=d}return p})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e].source,i=t.images[r],a=this.textureLoader;if(i.uri){let e=n.manager.getHandler(i.uri);e!==null&&(a=e)}return this.loadTextureImage(e,r,a)}loadTextureImage(e,t,n){let r=this,i=this.json,a=i.textures[e],o=i.images[t],s=(o.uri||o.bufferView)+`:`+a.sampler;if(this.textureCache[s])return this.textureCache[s];let c=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=a.name||o.name||``,t.name===``&&typeof o.uri==`string`&&o.uri.startsWith(`data:image/`)===!1&&(t.name=o.uri);let n=(i.samplers||{})[a.sampler]||{};return t.magFilter=Ek[n.magFilter]||1006,t.minFilter=Ek[n.minFilter]||1008,t.wrapS=Dk[n.wrapS]||1e3,t.wrapT=Dk[n.wrapT]||1e3,t.generateMipmaps=!t.isCompressedTexture&&t.minFilter!==1003&&t.minFilter!==1006,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[s]=c,c}loadImageSource(e,t){let n=this,r=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(e=>e.clone());let a=r.images[e],o=self.URL||self.webkitURL,s=a.uri||``,c=!1;if(a.bufferView!==void 0)s=n.getDependency(`bufferView`,a.bufferView).then(function(e){c=!0;let t=new Blob([e],{type:a.mimeType});return s=o.createObjectURL(t),s});else if(a.uri===void 0)throw Error(`THREE.GLTFLoader: Image `+e+` is missing URI and bufferView`);let l=Promise.resolve(s).then(function(e){return new Promise(function(n,r){let a=n;t.isImageBitmapLoader===!0&&(a=function(e){let t=new ma(e);t.needsUpdate=!0,n(t)}),t.load(kd.resolveURL(e,i.path),a,void 0,r)})}).then(function(e){return c===!0&&o.revokeObjectURL(s),Fk(e,a),e.userData.mimeType=a.mimeType||Vk(a.uri),e}).catch(function(e){throw console.error(`THREE.GLTFLoader: Couldn't load texture`,s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency(`texture`,n.index).then(function(a){if(!a)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(a=a.clone(),a.channel=n.texCoord),i.extensions[YO.KHR_TEXTURE_TRANSFORM]){let e=n.extensions===void 0?void 0:n.extensions[YO.KHR_TEXTURE_TRANSFORM];if(e){let t=i.associations.get(a);a=i.extensions[YO.KHR_TEXTURE_TRANSFORM].extendTexture(a,e),i.associations.set(a,t)}}return r!==void 0&&(a.colorSpace=r),e[t]=a,a})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,a=t.attributes.normal===void 0;if(e.isPoints){let e=`PointsMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new Rc,os.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e=`LineBasicMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new wc,os.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||a){let e=`ClonedMaterial:`+n.uuid+`:`;r&&(e+=`derivative-tangents:`),i&&(e+=`vertex-colors:`),a&&(e+=`flat-shading:`);let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return Du}loadMaterial(e){let t=this,n=this.json,r=this.extensions,i=n.materials[e],a,o={},s=i.extensions||{},c=[];if(s[YO.KHR_MATERIALS_UNLIT]){let e=r[YO.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),c.push(e.extendParams(o,i,t))}else{let n=i.pbrMetallicRoughness||{};if(o.color=new X(1,1,1),o.opacity=1,Array.isArray(n.baseColorFactor)){let e=n.baseColorFactor;o.color.setRGB(e[0],e[1],e[2],ii),o.opacity=e[3]}n.baseColorTexture!==void 0&&c.push(t.assignTexture(o,`map`,n.baseColorTexture,ri)),o.metalness=n.metallicFactor===void 0?1:n.metallicFactor,o.roughness=n.roughnessFactor===void 0?1:n.roughnessFactor,n.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(o,`metalnessMap`,n.metallicRoughnessTexture)),c.push(t.assignTexture(o,`roughnessMap`,n.metallicRoughnessTexture))),a=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,o)})))}i.doubleSided===!0&&(o.side=2);let l=i.alphaMode||Mk.OPAQUE;if(l===Mk.BLEND?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,l===Mk.MASK&&(o.alphaTest=i.alphaCutoff===void 0?.5:i.alphaCutoff)),i.normalTexture!==void 0&&a!==js&&(c.push(t.assignTexture(o,`normalMap`,i.normalTexture)),o.normalScale=new q(1,1),i.normalTexture.scale!==void 0)){let e=i.normalTexture.scale;o.normalScale.set(e,e)}if(i.occlusionTexture!==void 0&&a!==js&&(c.push(t.assignTexture(o,`aoMap`,i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(o.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&a!==js){let e=i.emissiveFactor;o.emissive=new X().setRGB(e[0],e[1],e[2],ii)}return i.emissiveTexture!==void 0&&a!==js&&c.push(t.assignTexture(o,`emissiveMap`,i.emissiveTexture,ri)),Promise.all(c).then(function(){let n=new a(o);return i.name&&(n.name=i.name),Fk(n,i),t.associations.set(n,{materials:e}),i.extensions&&Pk(r,n,i),n})}createUniqueName(e){let t=Yd.sanitizeNodeName(e||``);return t in this.nodeNamesUsed?t+`_`+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[YO.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(n){return Gk(n,e,t)})}let a=[];for(let n=0,o=e.length;n<o;n++){let o=e[n],s=Rk(o),c=r[s];if(c)a.push(c.promise);else{let e;e=o.extensions&&o.extensions[YO.KHR_DRACO_MESH_COMPRESSION]?i(o):Gk(new ts,o,t),r[s]={primitive:o,promise:e},a.push(e)}}return Promise.all(a)}loadMesh(e){let t=this,n=this.json,r=this.extensions,i=n.meshes[e],a=i.primitives,o=[];for(let e=0,t=a.length;e<t;e++){let t=a[e].material===void 0?Nk(this.cache):this.getDependency(`material`,a[e].material);o.push(t)}return o.push(t.loadGeometries(a)),Promise.all(o).then(function(n){let o=n.slice(0,n.length-1),s=n[n.length-1],c=[];for(let n=0,l=s.length;n<l;n++){let l=s[n],u=a[n],d,f=o[n];if(u.mode===wk.TRIANGLES||u.mode===wk.TRIANGLE_STRIP||u.mode===wk.TRIANGLE_FAN||u.mode===void 0)d=i.isSkinnedMesh===!0?new tc(l,f):new Us(l,f),d.isSkinnedMesh===!0&&d.normalizeSkinWeights(),u.mode===wk.TRIANGLE_STRIP?d.geometry=UO(d.geometry,1):u.mode===wk.TRIANGLE_FAN&&(d.geometry=UO(d.geometry,2));else if(u.mode===wk.LINES)d=new Ic(l,f);else if(u.mode===wk.LINE_STRIP)d=new Mc(l,f);else if(u.mode===wk.LINE_LOOP)d=new Lc(l,f);else if(u.mode===wk.POINTS)d=new Uc(l,f);else throw Error(`THREE.GLTFLoader: Primitive mode unsupported: `+u.mode);Object.keys(d.geometry.morphAttributes).length>0&&Lk(d,i),d.name=t.createUniqueName(i.name||`mesh_`+e),Fk(d,i),u.extensions&&Pk(r,d,u),t.assignFinalMaterial(d),c.push(d)}for(let n=0,r=c.length;n<r;n++)t.associations.set(c[n],{meshes:e,primitives:n});if(c.length===1)return i.extensions&&Pk(r,c[0],i),c[0];let l=new qa;i.extensions&&Pk(r,l,i),t.associations.set(l,{meshes:e});for(let e=0,t=c.length;e<t;e++)l.add(c[e]);return l})}loadCamera(e){let t,n=this.json.cameras[e],r=n[n.type];if(!r){console.warn(`THREE.GLTFLoader: Missing camera parameters.`);return}return n.type===`perspective`?t=new bd(Yi.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):n.type===`orthographic`&&(t=new Td(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),Fk(t,n),Promise.resolve(t)}loadSkin(e){let t=this.json.skins[e],n=[];for(let e=0,r=t.joints.length;e<r;e++)n.push(this._loadNodeShallow(t.joints[e]));return t.inverseBindMatrices===void 0?n.push(null):n.push(this.getDependency(`accessor`,t.inverseBindMatrices)),Promise.all(n).then(function(e){let n=e.pop(),r=e,i=[],a=[];for(let e=0,o=r.length;e<o;e++){let o=r[e];if(o){i.push(o);let t=new Y;n!==null&&t.fromArray(n.array,e*16),a.push(t)}else console.warn(`THREE.GLTFLoader: Joint "%s" could not be found.`,t.joints[e])}return new oc(i,a)})}loadAnimation(e){let t=this.json,n=this,r=t.animations[e],i=r.name?r.name:`animation_`+e,a=[],o=[],s=[],c=[],l=[];for(let e=0,t=r.channels.length;e<t;e++){let t=r.channels[e],n=r.samplers[t.sampler],i=t.target,u=i.node,d=r.parameters===void 0?n.input:r.parameters[n.input],f=r.parameters===void 0?n.output:r.parameters[n.output];i.node!==void 0&&(a.push(this.getDependency(`node`,u)),o.push(this.getDependency(`accessor`,d)),s.push(this.getDependency(`accessor`,f)),c.push(n),l.push(i))}return Promise.all([Promise.all(a),Promise.all(o),Promise.all(s),Promise.all(c),Promise.all(l)]).then(function(e){let t=e[0],a=e[1],o=e[2],s=e[3],c=e[4],l=[];for(let e=0,r=t.length;e<r;e++){let r=t[e],i=a[e],u=o[e],d=s[e],f=c[e];if(r===void 0)continue;r.updateMatrix&&r.updateMatrix();let p=n._createAnimationTracks(r,i,u,d,f);if(p)for(let e=0;e<p.length;e++)l.push(p[e])}let u=new Yu(i,void 0,l);return Fk(u,r),u})}createNodeMesh(e){let t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency(`mesh`,r.mesh).then(function(e){let t=n._getNodeRef(n.meshCache,r.mesh,e);return r.weights!==void 0&&t.traverse(function(e){if(e.isMesh)for(let t=0,n=r.weights.length;t<n;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){let t=this.json,n=this,r=t.nodes[e],i=n._loadNodeShallow(e),a=[],o=r.children||[];for(let e=0,t=o.length;e<t;e++)a.push(n.getDependency(`node`,o[e]));let s=r.skin===void 0?Promise.resolve(null):n.getDependency(`skin`,r.skin);return Promise.all([i,Promise.all(a),s]).then(function(e){let t=e[0],n=e[1],r=e[2];r!==null&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(r,Hk)});for(let e=0,r=n.length;e<r;e++)t.add(n[e]);if(t.userData.pivot!==void 0&&n.length>0){let e=t.userData.pivot,r=n[0];t.pivot=new J().fromArray(e),t.position.x-=e[0],t.position.y-=e[1],t.position.z-=e[2],r.position.set(0,0,0),delete t.userData.pivot}return t})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let i=t.nodes[e],a=i.name?r.createUniqueName(i.name):``,o=[],s=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return s&&o.push(s),i.camera!==void 0&&o.push(r.getDependency(`camera`,i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){o.push(e)}),this.nodeCache[e]=Promise.all(o).then(function(t){let o;if(o=i.isBone===!0?new nc:t.length>1?new qa:t.length===1?t[0]:new Ka,o!==t[0])for(let e=0,n=t.length;e<n;e++)o.add(t[e]);if(i.name&&(o.userData.name=i.name,o.name=a),Fk(o,i),i.extensions&&Pk(n,o,i),i.matrix!==void 0){let e=new Y;e.fromArray(i.matrix),o.applyMatrix4(e)}else i.translation!==void 0&&o.position.fromArray(i.translation),i.rotation!==void 0&&o.quaternion.fromArray(i.rotation),i.scale!==void 0&&o.scale.fromArray(i.scale);if(!r.associations.has(o))r.associations.set(o,{});else if(i.mesh!==void 0&&r.meshCache.refs[i.mesh]>1){let e=r.associations.get(o);r.associations.set(o,{...e})}return r.associations.get(o).nodes=e,o}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,i=new qa;n.name&&(i.name=r.createUniqueName(n.name)),Fk(i,n),n.extensions&&Pk(t,i,n);let a=n.nodes||[],o=[];for(let e=0,t=a.length;e<t;e++)o.push(r.getDependency(`node`,a[e]));return Promise.all(o).then(function(e){for(let t=0,n=e.length;t<n;t++){let n=e[t];n.parent===null?i.add(n):i.add(WO(n))}return r.associations=(e=>{let t=new Map;for(let[e,n]of r.associations)(e instanceof os||e instanceof ma)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);n!=null&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let a=[],o=e.name?e.name:e.uuid,s=[];Ak[i.path]===Ak.weights?e.traverse(function(e){e.morphTargetInfluences&&s.push(e.name?e.name:e.uuid)}):s.push(o);let c;switch(Ak[i.path]){case Ak.weights:c=Wu;break;case Ak.rotation:c=Ku;break;case Ak.translation:case Ak.scale:c=Ju;break;default:switch(n.itemSize){case 1:c=Wu;break;default:c=Ju;break}break}let l=r.interpolation===void 0?Yr:jk[r.interpolation],u=this._getArrayFromAccessor(n);for(let e=0,n=s.length;e<n;e++){let n=new c(s[e]+`.`+Ak[i.path],t.array,u,l);r.interpolation===`CUBICSPLINE`&&this._createCubicSplineTrackInterpolant(n),a.push(n)}return a}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){let e=Bk(t.constructor),n=new Float32Array(t.length);for(let r=0,i=t.length;r<i;r++)n[r]=t[r]*e;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof Ku?Ck:xk)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function Wk(e,t,n){let r=t.attributes,i=new _o;if(r.POSITION!==void 0){let e=n.json.accessors[r.POSITION],t=e.min,a=e.max;if(t!==void 0&&a!==void 0){if(i.set(new J(t[0],t[1],t[2]),new J(a[0],a[1],a[2])),e.normalized){let t=Bk(Tk[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}else{console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`);return}}else return;let a=t.targets;if(a!==void 0){let e=new J,t=new J;for(let r=0,i=a.length;r<i;r++){let i=a[r];if(i.POSITION!==void 0){let r=n.json.accessors[i.POSITION],a=r.min,o=r.max;if(a!==void 0&&o!==void 0){if(t.setX(Math.max(Math.abs(a[0]),Math.abs(o[0]))),t.setY(Math.max(Math.abs(a[1]),Math.abs(o[1]))),t.setZ(Math.max(Math.abs(a[2]),Math.abs(o[2]))),r.normalized){let e=Bk(Tk[r.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`)}}i.expandByVector(e)}e.boundingBox=i;let o=new qo;i.getCenter(o.center),o.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=o}function Gk(e,t,n){let r=t.attributes,i=[];function a(t,r){return n.getDependency(`accessor`,t).then(function(t){e.setAttribute(r,t)})}for(let t in r){let n=kk[t]||t.toLowerCase();n in e.attributes||i.push(a(r[t],n))}if(t.indices!==void 0&&!e.index){let r=n.getDependency(`accessor`,t.indices).then(function(t){e.setIndex(t)});i.push(r)}return ia.workingColorSpace!==`srgb-linear`&&`COLOR_0`in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ia.workingColorSpace}" not supported.`),Fk(e,t),Wk(e,t,n),Promise.all(i).then(function(){return t.targets===void 0?e:Ik(e,t.targets,n)})}var Kk=(function(){var e=`b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuixkbeeeddddillviebeoweuec:W:Odkr;Neqo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949WboY9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVJ9V29VVbrl79IV9Rbwq;lZkdbk;jYi5ud9:du8Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnalTmbcuhoaiRbbgrc;WeGc:Ge9hmbarcsGgwce0mbc9:hoalcufadcd4cbawEgDadfgrcKcaawEgqaraq0Egk6mbaicefhxcj;abad9Uc;WFbGcjdadca0EhmaialfgPar9Rgoadfhsavaoadz:jjjjbgzceVhHcbhOdndninaeaO9nmeaPax9RaD6mdamaeaO9RaOamfgoae6EgAcsfglc9WGhCabaOad2fhXaAcethQaxaDfhiaOaeaoaeao6E9RhLalcl4cifcd4hKazcj;cbfaAfhYcbh8AazcjdfhEaHh3incbhodnawTmbaxa8Acd4fRbbhokaocFeGh5cbh8Eazcj;cbfhqinaih8Fdndndndna5a8Ecet4ciGgoc9:fPdebdkaPa8F9RaA6mrazcj;cbfa8EaA2fa8FaAz:jjjjb8Aa8FaAfhixdkazcj;cbfa8EaA2fcbaAz:kjjjb8Aa8FhixekaPa8F9RaK6mva8FaKfhidnaCTmbaPai9RcK6mbaocdtc:q1jjbfcj1jjbawEhaczhrcbhlinargoc9Wfghaqfhrdndndndndndnaaa8Fahco4fRbbalcoG4ciGcdtfydbPDbedvivvvlvkar9cb83bbarcwf9cb83bbxlkarcbaiRbdai8Xbb9c:c:qj:bw9:9c:q;c1:I1e:d9c:b:c:e1z9:gg9cjjjjjz:dg8J9qE86bbaqaofgrcGfag9c8F1:NghcKtc8F91aicdfa8J9c8N1:Nfg8KRbbG86bbarcVfcba8KahcjeGcr4fghRbbag9cjjjjjl:dg8J9qE86bbarc7fcbaha8J9c8L1:NfghRbbag9cjjjjjd:dg8J9qE86bbarctfcbaha8J9c8K1:NfghRbbag9cjjjjje:dg8J9qE86bbarc91fcbaha8J9c8J1:NfghRbbag9cjjjj;ab:dg8J9qE86bbarc4fcbaha8J9cg1:NfghRbbag9cjjjja:dg8J9qE86bbarc93fcbaha8J9ch1:NfghRbbag9cjjjjz:dgg9qE86bbarc94fcbahag9ca1:NfghRbbai8Xbe9c:c:qj:bw9:9c:q;c1:I1e:d9c:b:c:e1z9:gg9cjjjjjz:dg8J9qE86bbarc95fag9c8F1:NgicKtc8F91aha8J9c8N1:NfghRbbG86bbarc96fcbahaicjeGcr4fgiRbbag9cjjjjjl:dg8J9qE86bbarc97fcbaia8J9c8L1:NfgiRbbag9cjjjjjd:dg8J9qE86bbarc98fcbaia8J9c8K1:NfgiRbbag9cjjjjje:dg8J9qE86bbarc99fcbaia8J9c8J1:NfgiRbbag9cjjjj;ab:dg8J9qE86bbarc9:fcbaia8J9cg1:NfgiRbbag9cjjjja:dg8J9qE86bbarcufcbaia8J9ch1:NfgiRbbag9cjjjjz:dgg9qE86bbaiag9ca1:NfhixikaraiRblaiRbbghco4g8Ka8KciSg8KE86bbaqaofgrcGfaiclfa8Kfg8KRbbahcl4ciGg8La8LciSg8LE86bbarcVfa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc7fa8Ka8Lfg8KRbbahciGghahciSghE86bbarctfa8Kahfg8KRbbaiRbeghco4g8La8LciSg8LE86bbarc91fa8Ka8Lfg8KRbbahcl4ciGg8La8LciSg8LE86bbarc4fa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc93fa8Ka8Lfg8KRbbahciGghahciSghE86bbarc94fa8Kahfg8KRbbaiRbdghco4g8La8LciSg8LE86bbarc95fa8Ka8Lfg8KRbbahcl4ciGg8La8LciSg8LE86bbarc96fa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc97fa8Ka8Lfg8KRbbahciGghahciSghE86bbarc98fa8KahfghRbbaiRbigico4g8Ka8KciSg8KE86bbarc99faha8KfghRbbaicl4ciGg8Ka8KciSg8KE86bbarc9:faha8KfghRbbaicd4ciGg8Ka8KciSg8KE86bbarcufaha8KfgrRbbaiciGgiaiciSgiE86bbaraifhixdkaraiRbwaiRbbghcl4g8Ka8KcsSg8KE86bbaqaofgrcGfaicwfa8Kfg8KRbbahcsGghahcsSghE86bbarcVfa8KahfghRbbaiRbeg8Kcl4g8La8LcsSg8LE86bbarc7faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarctfaha8KfghRbbaiRbdg8Kcl4g8La8LcsSg8LE86bbarc91faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc4faha8KfghRbbaiRbig8Kcl4g8La8LcsSg8LE86bbarc93faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc94faha8KfghRbbaiRblg8Kcl4g8La8LcsSg8LE86bbarc95faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc96faha8KfghRbbaiRbvg8Kcl4g8La8LcsSg8LE86bbarc97faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc98faha8KfghRbbaiRbog8Kcl4g8La8LcsSg8LE86bbarc99faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc9:faha8KfghRbbaiRbrgicl4g8Ka8KcsSg8KE86bbarcufaha8KfgrRbbaicsGgiaicsSgiE86bbaraifhixekarai8Pbb83bbarcwfaicwf8Pbb83bbaiczfhikdnaoaC9pmbalcdfhlaoczfhraPai9RcL0mekkaoaC6moaimexokaCmva8FTmvkaqaAfhqa8Ecefg8Ecl9hmbkdndndndnawTmbasa8Acd4fRbbgociGPlbedrbkaATmdaza8Afh8Fazcj;cbfhhcbh8EaEhaina8FRbbhraahocbhlinaoahalfRbbgqce4cbaqceG9R7arfgr86bbaoadfhoaAalcefgl9hmbkaacefhaa8Fcefh8FahaAfhha8Ecefg8Ecl9hmbxikkaATmeaza8Afhaazcj;cbfhhcbhoceh8EaYh8FinaEaofhlaa8Vbbhrcbhoinala8FaofRbbcwtahaofRbbgqVc;:FiGce4cbaqceG9R7arfgr87bbaladfhlaLaocefgofmbka8FaQfh8FcdhoaacdfhaahaQfhha8EceGhlcbh8EalmbxdkkaATmbcbaocl49Rh8Eaza8AfRbbhqcwhoa3hlinalRbbaotaqVhqalcefhlaocwfgoca9hmbkcbhhaEh8FaYhainazcj;cbfahfRbbhrcwhoaahlinalRbbaotarVhralaAfhlaocwfgoca9hmbkara8E93aq7hqcbhoa8Fhlinalaqao486bbalcefhlaocwfgoca9hmbka8Fadfh8FaacefhaahcefghaA9hmbkkaEclfhEa3clfh3a8Aclfg8Aad6mbkaXazcjdfaAad2z:jjjjb8AazazcjdfaAcufad2fadz:jjjjb8AaAaOfhOaihxaimbkc9:hoxdkcbc99aPax9RakSEhoxekc9:hokavcj;kbf8Kjjjjbaok:XseHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:kjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhldnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhoindnalaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfaoaDcu7gPcl4fcsGcitfgsydlhzasydbhHdndnaDcsGgsak9pmbavaiaPfcsGcdtfydbaxasEhDaxasTgOfhxxekdndnascsSmbcehOasc987asamffcefhDxekalcefhDal8SbbgscFeGhPdndnascu9mmbaDhlxekalcvfhlaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhlkcehOaPce4cbaPceG9R7amfhDkaDhmkavc;abfaocitfgsaDBdbasazBdlavaicdtfaDBdbavc;abfaocefcsGcitfgsaHBdbasaDBdlaocdfhoaOaifhidnadcd9hmbabarcetfgsaH87ebasclfaD87ebascdfaz87ebxdkabarcdtfgsaHBdbascwfaDBdbasclfazBdbxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHclfas87ebaHcdfaD87ebxekabarcdtfgHaxBdbaHcwfasBdbaHclfaDBdbkavaicdtfaxBdbavc;abfaocitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfaocefcsGcitfgHasBdbaHaDBdlavaiaPfgicsGcdtfasBdbavc;abfaocdfcsGcitfgDaxBdbaDasBdlaocifhoaiaOfhiazaOfhxxekaxcbalRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbalcefhDxekalcdfhDal8SbegPcFeGhsdnaPcu9kmbalcofhAascFbGhscrhldninaD8SbbgPcFbGaltasVhsaPcu9kmeaDcefhDalcrfglc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbglcFeGhPdnalcu9kmbaDcvfhzaPcFbGhPcrhldninas8SbbgDcFbGaltaPVhPaDcu9kmeascefhsalcrfglc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashlxekascefhlas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninal8SbbgscFbGaDtaPVhPascu9kmealcefhlaDcrfgDc8J9hmbkaOhlxekalcefhlkaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDclfaO87ebaDcdfaz87ebxekabarcdtfgDaABdbaDcwfaOBdbaDclfazBdbkavc;abfaocitfgDazBdbaDaABdlavaicdtfaABdbavc;abfaocefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfaocdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhiaocifhokawcefhwaocsGhoaicsGhiarcifgrae6mbkkcbc99alaqSEhokavc;aef8Kjjjjbaok:clevu8Jjjjjbcz9Rhvdnaecvfal9nmbc9:skdnaiRbbc;:eGc;qeSmbcuskav9cb83iwaicefhoaialfc98fhrdnaeTmbdnadcdSmbcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcdtfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgiBdbalaiBdbawcefgwae9hmbxdkkcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcetfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgi87ebalaiBdbawcefgwae9hmbkkcbc99aoarSEk:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk::ioiue99dud99dud99dnaeTmbcbhiabhlindndnal8Uebgv:YgoJ:ji:1Salcof8UebgrciVgw:Y:vgDNJbbbZJbbb:;avcu9kEMgq:lJbbb9p9DTmbaq:Ohkxekcjjjj94hkkalclf8Uebhvalcdf8UebhxabaiarcefciGfcetfak87ebdndnax:YgqaDNJbbbZJbbb:;axcu9kEMgm:lJbbb9p9DTmbam:Ohxxekcjjjj94hxkabaiarciGfgkcd7cetfax87ebdndnav:YgmaDNJbbbZJbbb:;avcu9kEMgP:lJbbb9p9DTmbaP:Ohvxekcjjjj94hvkabaiarcufciGfcetfav87ebdndnawaw2:ZgPaPMaoaoN:taqaqN:tamamN:tgoJbbbbaoJbbbb9GE:raDNJbbbZMgD:lJbbb9p9DTmbaD:Ohrxekcjjjj94hrkabakcetfar87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2gdTmbinababydbgecwtcw91:Yaece91cjjj98Gcjjj;8if::NUdbabclfhbadcufgdmbkkk:Tvirud99eudndnadcl9hmbaeTmeindndnabRbbgiabcefgl8Sbbgvabcdfgo8Sbbgrf9R:YJbbuJabcifgwRbbgdce4adVgDcd4aDVgDcl4aDVgD:Z:vgqNJbbbZMgk:lJbbb9p9DTmbak:Ohxxekcjjjj94hxkaoax86bbdndnaraif:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohoxekcjjjj94hokalao86bbdndnavaifar9R:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohixekcjjjj94hikabai86bbdndnaDadcetGadceGV:ZaqNJbbbZMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkawad86bbabclfhbaecufgembxdkkaeTmbindndnab8Vebgiabcdfgl8Uebgvabclfgo8Uebgrf9R:YJbFu9habcofgw8Vebgdce4adVgDcd4aDVgDcl4aDVgDcw4aDVgD:Z:vgqNJbbbZMgk:lJbbb9p9DTmbak:Ohxxekcjjjj94hxkaoax87ebdndnaraif:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohoxekcjjjj94hokalao87ebdndnavaifar9R:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohixekcjjjj94hikabai87ebdndnaDadcetGadceGV:ZaqNJbbbZMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkawad87ebabcwfhbaecufgembkkk9teiucbcbyd:K1jjbgeabcifc98GfgbBd:K1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;teeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiaeydlBdlaiaeydwBdwaiaeydxBdxaeczfheaiczfhiadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk:3eedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdxaialBdwaialBdlaialBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkk81dbcjwk8Kbbbbdbbblbbbwbbbbbbbebbbdbbblbbbwbbbbc:Kwkl8WNbb`,t=`b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuixkbbebeeddddilve9Weeeviebeoweuec:q:6dkr;Neqo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949WbwY9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVJ9V29VVbDl79IV9Rbqq:Ctklbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk:183lYud97dur978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnalTmbcuhoaiRbbgrc;WeGc:Ge9hmbarcsGgwce0mbc9:hoalcufadcd4cbawEgDadfgrcKcaawEgqaraq0Egk6mbaicefhxavaialfgmar9Rgoad;8qbbcj;abad9Uc;WFbGcjdadca0EhPdndndnadTmbaoadfhscbhzinaeaz9nmdamax9RaD6miabazad2fhHaxaDfhOaPaeaz9RazaPfae6EgAcsfgocl4cifcd4hCavcj;cbfaoc9WGgXcetfhQavcj;cbfaXci2fhLavcj;cbfaXfhKcbhYaoc;ab6h8AincbhodnawTmbaxaYcd4fRbbhokaocFeGhEcbh3avcj;cbfh5indndndndnaEa3cet4ciGgoc9:fPdebdkamaO9RaX6mwavcj;cbfa3aX2faOaX;8qbbaOaAfhOxdkavcj;cbfa3aX2fcbaX;8kbxekamaO9RaC6moaoclVcbawEhraOaCfhocbhidna8Ambamao9Rc;Gb6mbcbhlina5alfhidndndndndndnaOalco4fRbbgqciGarfPDbedibledibkaipxbbbbbbbbbbbbbbbbpklbxlkaiaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaoclffahc:q:yjjbfRbbfhoxikaiaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaocwffahc:q:yjjbfRbbfhoxdkaiaopbbbpklbaoczfhoxekaiaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaaaocdffahc:q:yjjbfRbbfhokdndndndndndnaqcd4ciGarfPDbedibledibkaiczfpxbbbbbbbbbbbbbbbbpklbxlkaiczfaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaoclffahc:q:yjjbfRbbfhoxikaiczfaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaocwffahc:q:yjjbfRbbfhoxdkaiczfaopbbbpklbaoczfhoxekaiczfaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaaaocdffahc:q:yjjbfRbbfhokdndndndndndnaqcl4ciGarfPDbedibledibkaicafpxbbbbbbbbbbbbbbbbpklbxlkaicafaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaoclffahc:q:yjjbfRbbfhoxikaicafaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaocwffahc:q:yjjbfRbbfhoxdkaicafaopbbbpklbaoczfhoxekaicafaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaaaocdffahc:q:yjjbfRbbfhokdndndndndndnaqco4arfPDbedibledibkaic8Wfpxbbbbbbbbbbbbbbbbpklbxlkaic8Wfaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngicitc:q1jjbfpbibaic:q:yjjbfRbbgipsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Ngqcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaiaoclffaqc:q:yjjbfRbbfhoxikaic8Wfaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngicitc:q1jjbfpbibaic:q:yjjbfRbbgipsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Ngqcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaiaocwffaqc:q:yjjbfRbbfhoxdkaic8Wfaopbbbpklbaoczfhoxekaic8WfaopbbdaoRbbgicitc:q1jjbfpbibaic:q:yjjbfRbbgipsaoRbegqcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaiaocdffaqc:q:yjjbfRbbfhokalc;abfhialcjefaX0meaihlamao9Rc;Fb0mbkkdnaiaX9pmbaici4hlinamao9RcK6mwa5aifhqdndndndndndnaOaico4fRbbalcoG4ciGarfPDbedibledibkaqpxbbbbbbbbbbbbbbbbpkbbxlkaqaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spkbbaaaoclffahc:q:yjjbfRbbfhoxikaqaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spkbbaaaocwffahc:q:yjjbfRbbfhoxdkaqaopbbbpkbbaoczfhoxekaqaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpkbbaaaocdffahc:q:yjjbfRbbfhokalcdfhlaiczfgiaX6mbkkaohOaoTmoka5aXfh5a3cefg3cl9hmbkdndndndnawTmbasaYcd4fRbbglciGPlbedwbkaXTmdavcjdfaYfhlavaYfpbdbhgcbhoinalavcj;cbfaofpblbg8JaKaofpblbg8KpmbzeHdOiAlCvXoQrLg8LaQaofpblbg8MaLaofpblbg8NpmbzeHdOiAlCvXoQrLgypmbezHdiOAlvCXorQLg8Ecep9Ta8Epxeeeeeeeeeeeeeeeeg8Fp9op9Hp9rg8Eagp9Uggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp9Uggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp9Uggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9Abbbaladfglaga8LaypmwDKYqk8AExm35Ps8E8Fg8Ecep9Ta8Ea8Fp9op9Hp9rg8Ep9Uggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp9Uggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp9Uggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9Abbbaladfglaga8Ja8KpmwKDYq8AkEx3m5P8Es8Fg8Ja8Ma8NpmwKDYq8AkEx3m5P8Es8Fg8KpmbezHdiOAlvCXorQLg8Ecep9Ta8Ea8Fp9op9Hp9rg8Ep9Uggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp9Uggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp9Uggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9Abbbaladfglaga8Ja8KpmwDKYqk8AExm35Ps8E8Fg8Ecep9Ta8Ea8Fp9op9Hp9rg8Ep9Ug8Fp9Abbbaladfgla8Fa8Ea8Epmlvorlvorlvorlvorp9Ug8Fp9Abbbaladfgla8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9Ug8Fp9Abbbaladfgla8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9AbbbaladfhlaoczfgoaX6mbxikkaXTmeavcjdfaYfhlavaYfpbdbhgcbhoinalavcj;cbfaofpblbg8JaKaofpblbg8KpmbzeHdOiAlCvXoQrLg8LaQaofpblbg8MaLaofpblbg8NpmbzeHdOiAlCvXoQrLgypmbezHdiOAlvCXorQLg8Ecep:nea8Epxebebebebebebebebg8Fp9op:bep9rg8Eagp:oeggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp:oeggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp:oeggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9Abbbaladfglaga8LaypmwDKYqk8AExm35Ps8E8Fg8Ecep:nea8Ea8Fp9op:bep9rg8Ep:oeggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp:oeggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp:oeggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9Abbbaladfglaga8Ja8KpmwKDYq8AkEx3m5P8Es8Fg8Ja8Ma8NpmwKDYq8AkEx3m5P8Es8Fg8KpmbezHdiOAlvCXorQLg8Ecep:nea8Ea8Fp9op:bep9rg8Ep:oeggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp:oeggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp:oeggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9Abbbaladfglaga8Ja8KpmwDKYqk8AExm35Ps8E8Fg8Ecep:nea8Ea8Fp9op:bep9rg8Ep:oeg8Fp9Abbbaladfgla8Fa8Ea8Epmlvorlvorlvorlvorp:oeg8Fp9Abbbaladfgla8Fa8Ea8EpmwDqkwDqkwDqkwDqkp:oeg8Fp9Abbbaladfgla8Fa8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9AbbbaladfhlaoczfgoaX6mbxdkkaXTmbcbhocbalcl4gl9Rc8FGhiavcjdfaYfhravaYfpbdbh8Finaravcj;cbfaofpblbggaKaofpblbg8JpmbzeHdOiAlCvXoQrLg8KaQaofpblbg8LaLaofpblbg8MpmbzeHdOiAlCvXoQrLg8NpmbezHdiOAlvCXorQLg8Eaip:Rea8Ealp:Sep9qg8Ea8Fp9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9Abbbaradfgra8Fa8Ka8NpmwDKYqk8AExm35Ps8E8Fg8Eaip:Rea8Ealp:Sep9qg8Ep9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9Abbbaradfgra8Faga8JpmwKDYq8AkEx3m5P8Es8Fgga8La8MpmwKDYq8AkEx3m5P8Es8Fg8JpmbezHdiOAlvCXorQLg8Eaip:Rea8Ealp:Sep9qg8Ep9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9Abbbaradfgra8Faga8JpmwDKYqk8AExm35Ps8E8Fg8Eaip:Rea8Ealp:Sep9qg8Ep9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9AbbbaradfhraoczfgoaX6mbkkaYclfgYad6mbkaHavcjdfaAad2;8qbbavavcjdfaAcufad2fad;8qbbaAazfhzc9:hoaOhxaOmbxlkkaeTmbaDalfhrcbhocuhlinaralaD9RglfaD6mdaPaeao9RaoaPfae6Eaofgoae6mbkaial9Rhxkcbc99amax9RakSEhoxekc9:hokavcj;kbf8Kjjjjbaokwbz:bjjjbk:TseHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhldnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhoindnalaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfaoaDcu7gPcl4fcsGcitfgsydlhzasydbhHdndnaDcsGgsak9pmbavaiaPfcsGcdtfydbaxasEhDaxasTgOfhxxekdndnascsSmbcehOasc987asamffcefhDxekalcefhDal8SbbgscFeGhPdndnascu9mmbaDhlxekalcvfhlaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhlkcehOaPce4cbaPceG9R7amfhDkaDhmkavc;abfaocitfgsaDBdbasazBdlavaicdtfaDBdbavc;abfaocefcsGcitfgsaHBdbasaDBdlaocdfhoaOaifhidnadcd9hmbabarcetfgsaH87ebasclfaD87ebascdfaz87ebxdkabarcdtfgsaHBdbascwfaDBdbasclfazBdbxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHclfas87ebaHcdfaD87ebxekabarcdtfgHaxBdbaHcwfasBdbaHclfaDBdbkavaicdtfaxBdbavc;abfaocitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfaocefcsGcitfgHasBdbaHaDBdlavaiaPfgicsGcdtfasBdbavc;abfaocdfcsGcitfgDaxBdbaDasBdlaocifhoaiaOfhiazaOfhxxekaxcbalRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbalcefhDxekalcdfhDal8SbegPcFeGhsdnaPcu9kmbalcofhAascFbGhscrhldninaD8SbbgPcFbGaltasVhsaPcu9kmeaDcefhDalcrfglc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbglcFeGhPdnalcu9kmbaDcvfhzaPcFbGhPcrhldninas8SbbgDcFbGaltaPVhPaDcu9kmeascefhsalcrfglc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashlxekascefhlas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninal8SbbgscFbGaDtaPVhPascu9kmealcefhlaDcrfgDc8J9hmbkaOhlxekalcefhlkaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDclfaO87ebaDcdfaz87ebxekabarcdtfgDaABdbaDcwfaOBdbaDclfazBdbkavc;abfaocitfgDazBdbaDaABdlavaicdtfaABdbavc;abfaocefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfaocdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhiaocifhokawcefhwaocsGhoaicsGhiarcifgrae6mbkkcbc99alaqSEhokavc;aef8Kjjjjbaok:clevu8Jjjjjbcz9Rhvdnaecvfal9nmbc9:skdnaiRbbc;:eGc;qeSmbcuskav9cb83iwaicefhoaialfc98fhrdnaeTmbdnadcdSmbcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcdtfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgiBdbalaiBdbawcefgwae9hmbxdkkcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcetfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgi87ebalaiBdbawcefgwae9hmbkkcbc99aoarSEk:2Pliur97eue978Jjjjjbc8W9Rhiaec98Ghldndnadcl9hmbdnalTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalaeSmeaipxbbbbbbbbbbbbbbbbgqpklbaiabalcdtfgdaeciGglcdtgv;8qbbdnalTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDaqp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkadaiav;8qbbskaipxFubbFubbFubbFubbgxpklbdnalTmbcbhvabhdinadczfgmampbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmbediwDqkzHOAKY8AEgwczp:Reczp:Sep;6egraipblbaDaopmlvorxmPsCXQL358E8Fp9op;6eawczp:Sep;6egwp;Gearp;Gep;Kep;Legopxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgPp9op9rp;Kegrpxb;:FSb;:FSb;:FSb;:FSararp;Meaoaop;MeawaqawaPp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFFbbFFbbFFbbFFbbp9oaoawp;Meaqp;Keczp:Rep9qgoarawp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogrpmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oaoarpmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgval6mbkkalaeSmbaiczfpxbbbbbbbbbbbbbbbbgopklbaiaopklbaiabalcitfgdaeciGglcitgv;8qbbaiaxpkladnalTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmbediwDqkzHOAKY8AEgwczp:Reczp:Sep;6egraipblaaDaopmlvorxmPsCXQL358E8Fp9op;6eawczp:Sep;6egwp;Gearp;Gep;Kep;Legopxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgPp9op9rp;Kegrpxb;:FSb;:FSb;:FSb;:FSararp;Meaoaop;MeawaqawaPp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFFbbFFbbFFbbFFbbp9oaoawp;Meaqp;Keczp:Rep9qgoarawp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogrpmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oaoarpmbezHdiOAlvCXorQLp9qpklbkadaiav;8qbbkk:Iwllue97euo978Jjjjjbca9Rhidnaec98GglTmbcbhvabhoinaocKfpx:ji:1S:ji:1S:ji:1S:ji:1SaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkpxibbbibbbibbbibbbp9qgxp;6ep;Negmaxaxp:1ep;7egxaxp;KearaDpmbediwDqkzHOAKY8AEgxczp:Reczp:Sep;6egrarp;Meaxczp:Sep;6egDaDp;Meaqczp:Reczp:Sep;6egqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jep;Mepxbbn0bbn0bbn0bbn0gxp;KepxFFbbFFbbFFbbFFbbgPp9oamaDp;Meaxp;Keczp:Rep9qgDamarp;Meaxp;KeaPp9oamaqp;Meaxp;Keczp:Rep9qgxpmwDKYqk8AExm35Ps8E8Fgrp5eakclp:RegmpEi:T:j83ibawarp5bampEd:T:j83ibaocwfaDaxpmbezHdiOAlvCXorQLgxp5eampEe:T:j83ibaoaxp5bampEb:T:j83ibaocafhoavclfgval6mbkkdnalaeSmbaiczfpxbbbbbbbbbbbbbbbbgmpklbaiampklbaiabalcitfgoaeciGgvcitgw;8qbbdnavTmbaipx:ji:1S:ji:1S:ji:1S:ji:1SaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkpxibbbibbbibbbibbbp9qgxp;6ep;Negmaxaxp:1ep;7egxaxp;KearaDpmbediwDqkzHOAKY8AEgxczp:Reczp:Sep;6egrarp;Meaxczp:Sep;6egDaDp;Meaqczp:Reczp:Sep;6egqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jep;Mepxbbn0bbn0bbn0bbn0gxp;KepxFFbbFFbbFFbbFFbbgPp9oamaDp;Meaxp;Keczp:Rep9qgDamarp;Meaxp;KeaPp9oamaqp;Meaxp;Keczp:Rep9qgxpmwDKYqk8AExm35Ps8E8Fgrp5eakclp:RegmpEi:T:j83iKaiarp5bampEd:T:j83izaiaDaxpmbezHdiOAlvCXorQLgxp5eampEe:T:j83iwaiaxp5bampEb:T:j83ibkaoaiaw;8qbbkk;uddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbheabhdinadadpbbbgocwp:Recwp:Sep;6eaocep:SepxbbjFbbjFbbjFbbjFp9opxbbjZbbjZbbjZbbjZp:Uep;Mepkbbadczfhdaeclfgeav6mbkkdnavalSmbaic8WfpxbbbbbbbbbbbbbbbbgopklbaicafaopklbaiczfaopklbaiaopklbaiabavcdtfgdalciGgecdtgv;8qbbdnaeTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjFbbjFbbjFbbjFp9opxbbjZbbjZbbjZbbjZp:Uep;Mepklbkadaiav;8qbbkk:CPvdue97euw97eu8Jjjjjbc8W9Rhiaec98Ghldndnadcl9hmbaipxbbbbbbbbbbbbbbbbgvpklbdnalTmbcbhoabhdinadpbbbhradpxbbuJbbuJbbuJbbuJaipblbarcKp:Tep9qgwcep:Seawp9qgDcdp:SeaDp9qgDclp:SeaDp9qgqp;6ep;NegDarcwp:RecKp:SegkarpxFbbbFbbbFbbbFbbbgxp9ogmp:Uep;6ep;Mepxbbn0bbn0bbn0bbn0gPp;Kecwp:RepxbFbbbFbbbFbbbFbbp9oaDamakp:Xearczp:RecKp:Segrp:Uep;6ep;MeaPp;Keaxp9op9qaDamakarp:Uep:Xep;6ep;MeaPp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qaDaqawcep:Rep9oawpxebbbebbbebbbebbbp9op9qp;6ep;MeaPp;KecKp:Rep9qpkbbadczfhdaoclfgoal6mbkkalaeSmeaiavpklaaicafabalcdtfgdaeciGglcdtgo;8qbbaiavpklbdnalTmbaipblahraipxbbuJbbuJbbuJbbuJaipblbarcKp:Tep9qgwcep:Seawp9qgDcdp:SeaDp9qgDclp:SeaDp9qgqp;6ep;NegDarcwp:RecKp:SegkarpxFbbbFbbbFbbbFbbbgxp9ogmp:Uep;6ep;Mepxbbn0bbn0bbn0bbn0gPp;Kecwp:RepxbFbbbFbbbFbbbFbbp9oaDamakp:Xearczp:RecKp:Segrp:Uep;6ep;MeaPp;Keaxp9op9qaDamakarp:Uep:Xep;6ep;MeaPp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qaDaqawcep:Rep9oawpxebbbebbbebbbebbbp9op9qp;6ep;MeaPp;KecKp:Rep9qpklakadaicafao;8qbbskaipxbbbbbbbbbbbbbbbbgvpklbdnalTmbcbhoabhdinadczfgspxbFu9hbFu9hbFu9hbFu9hadpbbbgDaspbbbgPpmlvorxmPsCXQL358E8Fgmczp:Teaipblbp9qgrcep:Searp9qgwcdp:Seawp9qgwclp:Seawp9qgwcwp:Seawp9qgqp;6ep;NegwaDaPpmbediwDqkzHOAKY8AEgDpxFFbbFFbbFFbbFFbbgPp9ogkaDczp:Segxp:Ueamczp:Reczp:Segmp:Xep;6ep;Mepxbbn0bbn0bbn0bbn0gDp;KeaPp9oawakaxamp:Uep:Xep;6ep;MeaDp;Keczp:Rep9qgxawaqarcep:Rep9oarpxebbbebbbebbbebbbp9op9qp;6ep;MeaDp;Keczp:Reawamakp:Uep;6ep;MeaDp;KeaPp9op9qgrpmwDKYqk8AExm35Ps8E8FpkbbadaxarpmbezHdiOAlvCXorQLpkbbadcafhdaoclfgoal6mbkkalaeSmbaiczfpxbbbbbbbbbbbbbbbbgrpklbaiarpklbaiabalcitfgdaeciGglcitgo;8qbbaiavpkladnalTmbaipxbFu9hbFu9hbFu9hbFu9haipblbgDaipblzgPpmlvorxmPsCXQL358E8Fgmczp:Teaipblap9qgrcep:Searp9qgwcdp:Seawp9qgwclp:Seawp9qgwcwp:Seawp9qgqp;6ep;NegwaDaPpmbediwDqkzHOAKY8AEgDpxFFbbFFbbFFbbFFbbgPp9ogkaDczp:Segxp:Ueamczp:Reczp:Segmp:Xep;6ep;Mepxbbn0bbn0bbn0bbn0gDp;KeaPp9oawakaxamp:Uep:Xep;6ep;MeaDp;Keczp:Rep9qgxawaqarcep:Rep9oarpxebbbebbbebbbebbbp9op9qp;6ep;MeaDp;Keczp:Reawamakp:Uep;6ep;MeaDp;KeaPp9op9qgrpmwDKYqk8AExm35Ps8E8FpklzaiaxarpmbezHdiOAlvCXorQLpklbkadaiao;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz:Dbb`,n=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),r=new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);if(typeof WebAssembly!=`object`)return{supported:!1};var i=WebAssembly.validate(n)?s(t):s(e),a,o=WebAssembly.instantiate(i,{}).then(function(e){a=e.instance,a.exports.__wasm_call_ctors()});function s(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;++n){var i=e.charCodeAt(n);t[n]=i>96?i-97:i>64?i-39:i+4}for(var a=0,n=0;n<e.length;++n)t[a++]=t[n]<60?r[t[n]]:(t[n]-60)*64+t[++n];return t.buffer.slice(0,a)}function c(e,t,n,r,i,a,o){var s=e.exports.sbrk,c=r+3&-4,l=s(c*i),u=s(a.length),d=new Uint8Array(e.exports.memory.buffer);d.set(a,u);var f=t(l,r,i,u,a.length);if(f==0&&o&&o(l,c,i),n.set(d.subarray(l,l+r*i)),s(l-s(0)),f!=0)throw Error(`Malformed buffer data: `+f)}var l={NONE:``,OCTAHEDRAL:`meshopt_decodeFilterOct`,QUATERNION:`meshopt_decodeFilterQuat`,EXPONENTIAL:`meshopt_decodeFilterExp`,COLOR:`meshopt_decodeFilterColor`},u={ATTRIBUTES:`meshopt_decodeVertexBuffer`,TRIANGLES:`meshopt_decodeIndexBuffer`,INDICES:`meshopt_decodeIndexSequence`},d=[],f=0;function p(e){var t={object:new Worker(e),pending:0,requests:{}};return t.object.onmessage=function(e){var n=e.data;t.pending-=n.count,t.requests[n.id][n.action](n.value),delete t.requests[n.id]},t}function m(e){for(var t=`self.ready = WebAssembly.instantiate(new Uint8Array([`+new Uint8Array(i)+`]), {}).then(function(result) { result.instance.exports.__wasm_call_ctors(); return result.instance; });self.onmessage = `+g.name+`;`+c.toString()+g.toString(),n=new Blob([t],{type:`text/javascript`}),r=URL.createObjectURL(n),a=d.length;a<e;++a)d[a]=p(r);for(var a=e;a<d.length;++a)d[a].object.postMessage({});d.length=e,URL.revokeObjectURL(r)}function h(e,t,n,r,i){for(var a=d[0],o=1;o<d.length;++o)d[o].pending<a.pending&&(a=d[o]);return new Promise(function(o,s){var c=new Uint8Array(n),l=++f;a.pending+=e,a.requests[l]={resolve:o,reject:s},a.object.postMessage({id:l,count:e,size:t,source:c,mode:r,filter:i},[c.buffer])})}function g(e){var t=e.data;if(!t.id)return self.close();self.ready.then(function(e){try{var n=new Uint8Array(t.count*t.size);c(e,e.exports[t.mode],n,t.count,t.size,t.source,e.exports[t.filter]),self.postMessage({id:t.id,count:t.count,action:`resolve`,value:n},[n.buffer])}catch(e){self.postMessage({id:t.id,count:t.count,action:`reject`,value:e})}})}return{ready:o,supported:!0,useWorkers:function(e){m(e)},decodeVertexBuffer:function(e,t,n,r,i){c(a,a.exports.meshopt_decodeVertexBuffer,e,t,n,r,a.exports[l[i]])},decodeIndexBuffer:function(e,t,n,r){c(a,a.exports.meshopt_decodeIndexBuffer,e,t,n,r)},decodeIndexSequence:function(e,t,n,r){c(a,a.exports.meshopt_decodeIndexSequence,e,t,n,r)},decodeGltfBuffer:function(e,t,n,r,i,o){c(a,a.exports[u[i]],e,t,n,r,a.exports[l[o]])},decodeGltfBufferAsync:function(e,t,n,r,i){return d.length>0?h(e,t,n,u[r],l[i]):o.then(function(){var o=new Uint8Array(e*t);return c(a,a.exports[u[r]],o,e,t,n,a.exports[l[i]]),o})}}})(),qk=1230263361,Jk=2,Yk=16,Xk=11,Zk=32767,Qk=86400;function $k(e){let t=new DataView(e);if(t.getUint32(0,!0)!==qk)throw Error(`attitude: bad file magic (expected ATTI)`);let n=t.getUint16(4,!0);if(n!==Jk)throw Error(`attitude: unsupported version ${n}`);let r=t.getFloat64(8,!0),i=Math.floor((e.byteLength-Yk)/Xk),a=new Float64Array(i),o=new Float32Array(i*4),s=0;for(let e=0;e<i;e++){let n=Yk+e*Xk;e>0&&(s+=t.getFloat32(n,!0)),a[e]=r+s/Qk;let i=t.getUint8(n+4),c=t.getInt16(n+5,!0)/Zk,l=t.getInt16(n+7,!0)/Zk,u=t.getInt16(n+9,!0)/Zk,d=Math.sqrt(Math.max(0,1-c*c-l*l-u*u)),f=e*4,p=0;for(let e=0;e<4;e++)e===i?o[f+e]=d:(o[f+e]=p===0?c:p===1?l:u,p++)}return{times:a,quats:o}}var eA=86400,tA=new Xi().setFromRotationMatrix(new Y().makeBasis(wg(1,0,0,new J),wg(0,1,0,new J),wg(0,0,1,new J))),nA=new Xi,rA=new Xi,iA=new Xi,aA=new J;function oA(e,t,n){let r=t*4;return n.set(e[r+1],e[r+2],e[r+3],e[r])}var sA=class{startJd;endJd;baselines;files;chunks=new Map;inflight=new Set;retries=new Tx;constructor(e,t){this.probeId=e,this.startJd=t.files.length?t.files[0].start_jd:0,this.endJd=t.files.length?t.files[t.files.length-1].end_jd:0,this.baselines=t.baselines,this.files=t.files}covers(e){return this.coversTdb(Ig(e))}coversTdb(e){return e>=this.startJd&&e<=this.endJd&&this.files.length>0}orientationAt(e,t){let n=Ig(e);if(!this.coversTdb(n))return!1;let r=this.fileIndexFor(n),i=this.ensure(r);if(!i)return!1;this.ensure(r-1),this.ensure(r+1),this.sampleChunk(n,r,i);let a=this.baselines?.[this.files[r].baseline_index??0];if(a){let{axis:e,rate_rad_s:t,anchor:r,anchor_jd:i}=a,o=(n-i)*eA;aA.set(e[0],e[1],e[2]),iA.setFromAxisAngle(aA,t*o),rA.set(r[1],r[2],r[3],r[0]),iA.multiply(rA),nA.copy(iA.multiply(nA))}return nA.conjugate(),t.copy(tA).multiply(nA),!0}fileIndexFor(e){let t=this.files;if(e<=t[0].start_jd)return 0;let n=0,r=t.length-1;for(;r-n>1;){let i=n+r>>1;t[i].start_jd<=e?n=i:r=i}return t[r].start_jd<=e?r:n}sampleChunk(e,t,n){let{times:r,quats:i}=n,a=r.length;if(e<=r[0]){oA(i,0,nA);return}if(e>=r[a-1]){let n=this.chunks.get(t+1);if(this.files[t+1]?.baseline_index===this.files[t].baseline_index&&n&&n.times.length>0&&n.times[0]>r[a-1]){let t=n.times[0]-r[a-1],o=Math.min(1,(e-r[a-1])/t);oA(i,a-1,nA),oA(n.quats,0,rA),nA.slerpQuaternions(nA,rA,o)}else oA(i,a-1,nA);return}let o=0,s=a-1;for(;s-o>1;){let t=o+s>>1;r[t]<=e?o=t:s=t}let c=r[s]-r[o],l=c>0?(e-r[o])/c:0;oA(i,o,nA),oA(i,s,rA),nA.slerpQuaternions(nA,rA,l)}ensure(e){if(e<0||e>=this.files.length)return;let t=this.chunks.get(e);if(t)return t;this.inflight.has(e)||this.retries.waiting(e)||(this.inflight.add(e),this.load(e))}async load(e){let t=this.files[e];try{let n=await fetch(`${Gt()}/v1/attitude/${this.probeId}/${t.name}`);if(!n.ok)throw Error(`${n.status}`);let r=new DecompressionStream(`gzip`),i=await new Response(n.body.pipeThrough(r)).arrayBuffer();this.chunks.set(e,$k(i)),this.retries.clear(e)}catch(n){this.retries.fail(e),console.warn(`attitude: chunk ${this.probeId}/${t.name} failed to load:`,n)}finally{this.inflight.delete(e)}}};function cA(e,t){return new sA(e,t)}var lA=[`carrier`,`missing`],uA=`scene-label__annotation--visible`;function dA(e,t,n){let r=e.labelAnnotations?.[t];if(!r){if(!n||!e.label)return;r=document.createElement(`span`),r.className=`scene-label__annotation`,r.dir=`auto`,r.textContent=n,mA(e,r,t),(e.labelAnnotations??={})[t]=r}else if(n===null){if(!r.classList.contains(uA))return}else if(r.textContent===n&&r.classList.contains(uA))return;else r.textContent=n;r.classList.toggle(uA,n!==null),fA(e)}function fA(e){let t=e.label?.element;if(!t)return;let n=[t.querySelector(`.scene-label__name`)?.textContent||e.body.data.name];for(let t of lA){let r=e.labelAnnotations?.[t];r?.classList.contains(uA)&&n.push(r.textContent)}let r=n.filter(Boolean).join(`, `);r?t.setAttribute(`aria-label`,r):t.removeAttribute(`aria-label`)}function pA(e){if(!e.labelStack){let t=document.createElement(`span`);t.className=`scene-label__annotations`,e.label.element.appendChild(t),e.labelStack=t}return e.labelStack}function mA(e,t,n){for(let r of lA.slice(lA.indexOf(n)+1)){let n=e.labelAnnotations?.[r];if(n){n.parentElement.insertBefore(t,n);return}}pA(e).appendChild(t)}function hA(e,t){let n=e.userData,r=t??``;if(n.tintBase&&n.tintKey===r)return n.tintBase;let i=SA(e,t);return n.tintBase=i,n.tintKey=r,i}function gA(e){let t=e.userData;return t.meanColorImage!==e.image&&(t.meanColor=_A(e),t.meanColorImage=e.image),t.meanColor??null}function _A(e){let t=wA(e);if(!t)return null;let n=new X(0,0,0),r=new X,i=0;for(let a=0;a<yA;a++){let o=Math.sin(Math.PI*(a+.5)/yA);for(let i=a*vA*4;i<(a+1)*vA*4;i+=4)r.setRGB(t[i]/255,t[i+1]/255,t[i+2]/255,e.colorSpace),n.r+=o*r.r,n.g+=o*r.g,n.b+=o*r.b;i+=o*vA}return n.multiplyScalar(1/i)}var vA=32,yA=16,bA=.01,xA=.001;function SA(e,t){let n=new X(16777215);if(!t)return n;let r=CA(e);if(r===null||r>bA)return n;let i=new X(t),a=.2126*i.r+.7152*i.g+.0722*i.b;return a<xA?n:new X().setRGB(i.r/a,i.g/a,i.b/a)}function CA(e){let t=wA(e);if(!t)return null;let n=0,r=t.length/4;for(let e=0;e<t.length;e+=4){let r=t[e]/255,i=t[e+1]/255,a=t[e+2]/255;n+=Math.max(r,i,a)-Math.min(r,i,a)}return n/r}function wA(e){let t=e.image;if(!t||!t.width||!t.height)return null;let n=document.createElement(`canvas`);n.width=vA,n.height=yA;let r=n.getContext(`2d`,{willReadFrequently:!0});if(!r)return null;r.drawImage(t,0,0,vA,yA);try{return r.getImageData(0,0,vA,yA).data}catch{return null}}var TA=`
|
|
5512
|
+
}`)}),c}function kD(e){e&&(e.uSelfHeightMap.value=null,e.uSelfScale.value=0)}async function AD(e,t,n,r,i,a=Q(1)){let o=MD(t,n),s;try{s=await new Promise((e,t)=>{r.load(o,e,void 0,t)})}catch(e){return console.warn(`Failed to load displacement map ${o}:`,e),null}return s.colorSpace=``,e.displacementMap=s,jD(e,t,i,a),e.needsUpdate=!0,s}function jD(e,t,n,r=Q(1)){e.displacementScale=t.scale_km*r,e.displacementBias=t.bias_km*r-(t.absolute_radius?n:0)}function MD(e,t){return Qt(`/v1/textures/${e.id}/${t}.webp`,`textures`)}async function ND(e){try{let t=await fetch(e);if(!t.ok)throw Error(`${t.status} ${t.statusText}`);return await createImageBitmap(await t.blob())}catch(t){return console.warn(`Failed to decode displacement map ${e}:`,t),null}}var PD=4e6;async function FD(e,t,n){let r=e.width,i=Math.max(1,Math.floor(PD/r)),a=document.createElement(`canvas`);a.width=r,a.height=Math.min(i,n-t+1);let o=a.getContext(`2d`,{willReadFrequently:!0});if(!o)return null;let s=new Uint8Array(r*(n-t+1));for(let a=t;a<=n;a+=i){let c=Math.min(i,n-a+1);o.drawImage(e,0,a,r,c,0,0,r,c);let l=o.getImageData(0,0,r,c).data,u=(a-t)*r;for(let e=0;e<r*c;e++)s[u+e]=l[e*4];!document.hidden&&a+i<=n&&await new Promise(e=>setTimeout(e))}return s}var ID=`pyramid`,LD=new WeakSet;function RD(e,t){let n=e.displacementMeta?.tiles;return!!n&&n.scale_km!==void 0&&Kt()!==``&&a(n.distribution)&&t.extensions.has(`OES_texture_float_linear`)&&!LD.has(e)}async function zD(e,t){let n=e.displacementMeta;if(!(!n||!e.mesh||e.displacementLoading||e.displacementTier===t)){e.displacementLoading=!0;try{let r=t===`pyramid`?await VD(e,n):await BD(n,t);if(!r)return;if(!e.mesh||!e.displacementMap){r.dispose();return}let i=e.mesh.material,a=i.displacementMap;i.displacementMap=r,e.displacementMap=r,e.displacementTier=t,e.selfShadow&&OD(i,r,Q(n.scale_km)),a&&a!==r&&a.dispose()}finally{e.displacementLoading=!1}}}async function BD(e,t){let n=await ND(MD(e,t));if(!n)return null;let r=n.width,i=n.height,a=await FD(n,0,i-1);if(n.close(),!a)return null;let o=new Uint8Array(r);for(let e=0;e<i>>1;e++){let t=a.subarray(e*r,(e+1)*r),n=a.subarray((i-1-e)*r,(i-e)*r);o.set(t),t.set(n),n.set(o)}let s=new rc(a,r,i,sr,Un);return s.colorSpace=``,s.magFilter=Bn,s.minFilter=Bn,s.generateMipmaps=!1,s.unpackAlignment=1,s.needsUpdate=!0,s}async function VD(e,t){if(!t.tiles)return null;try{return await HD(t,t.tiles)}catch(n){return console.warn(`Failed to load the height pyramid of ${t.id}:`,n),LD.add(e),null}}async function HD(e,t){let n=new AbortController().signal,r=await Promise.all([0,1].map(e=>KT(Jt(t,``,0,e,0),!0,n))),i=r[0].size,a=2*i,o=new Float32Array(a*i),s=(t.scale_km??0)/65535/e.scale_km,c=((t.bias_km??0)-e.bias_km)/e.scale_km;r.forEach(({heights:e},t)=>{for(let n=0;n<i;n++){let r=n*i,l=n*a+t*i;for(let t=0;t<i;t++)o[l+t]=e[r+t]*s+c}});let l=new rc(o,a,i,sr,Yn);return l.colorSpace=``,l.magFilter=Bn,l.minFilter=Hn,l.generateMipmaps=!1,l.mipmaps=UD(o,a,i),l.needsUpdate=!0,l}function UD(e,t,n){let r=[{data:e,width:t,height:n}];for(;t>1||n>1;){let i=Math.max(1,t>>1),a=Math.max(1,n>>1),o=t/i,s=n/a,c=new Float32Array(i*a);for(let n=0;n<a;n++)for(let r=0;r<i;r++){let a=0;for(let i=0;i<s;i++){let c=(n*s+i)*t+r*o;for(let t=0;t<o;t++)a+=e[c+t]}c[n*i+r]=a/(o*s)}r.push({data:c,width:i,height:a}),e=c,t=i,n=a}return r}function WD(e,t,n,r,i){let a=Math.floor(r),o=Math.floor(i),s=r-a,c=i-o,l=e=>(e%t+t)%t,u=e=>e<0?0:e>n-1?n-1:e,d=l(a),f=l(a+1),p=u(o)*t,m=u(o+1)*t,h=e[p+d]*(1-s)+e[p+f]*s,g=e[m+d]*(1-s)+e[m+f]*s,_=h*(1-c)+g*c;return e instanceof Float32Array?_:_/255}function GD(e){e.displacementMap&&(e.displacementMap.dispose(),e.displacementMap=null,e.displacementScale=1,e.displacementBias=0,e.needsUpdate=!0)}function KD(e,t){let n=0,r=e.length-2;for(;n<r;){let i=n+r+1>>1;e[i]<=t?n=i:r=i-1}return n}function qD(e,t){let n=Math.cos(e);return[n*Math.cos(t),Math.sin(e),-n*Math.sin(t)]}function JD(e,t,n,r,i,a,o){let s=(r+n)/r,[c,l,u]=qD(e,t);return[s*i*c,s*o*l,s*a*u]}function YD(e,t,n){if(e.kind===`uniform`){let r=e.segs,i=(Math.PI/2-t)*r/Math.PI,a=Math.min(Math.max(Math.floor(i),0),r-1),o=Math.min(Math.max(i-a,0),1),s=(n-Math.PI)*r/(2*Math.PI),c=Math.floor(s),l=s-c;return{corners:[[a,c],[a,c+1],[a+1,c],[a+1,c+1]].map(([e,t])=>({latRad:Math.PI/2-Math.min(e,r)*Math.PI/r,lonRad:Math.PI+t*2*Math.PI/r})),tx:l,ty:o}}let{thetas:r,phis:i,riseKm:a}=e,o=Math.PI/2-t,s=(n-Math.PI)%(2*Math.PI);s<0&&(s+=2*Math.PI);let c=KD(r,o),l=KD(i,s),u=Math.min(Math.max((o-r[c])/(r[c+1]-r[c]),0),1),d=Math.min(Math.max((s-i[l])/(i[l+1]-i[l]),0),1);return{corners:[[c,l],[c,l+1],[c+1,l],[c+1,l+1]].map(([e,t])=>({latRad:Math.PI/2-r[e],lonRad:i[t]+Math.PI,riseKm:a?.[e*i.length+t]})),tx:d,ty:u}}function XD(e,t,n){let[r,i,a,o]=e,s=[0,0,0];for(let e=0;e<3;e++)s[e]=t>=n?r[e]+(i[e]-r[e])*t+(o[e]-i[e])*n:r[e]+(o[e]-a[e])*t+(a[e]-r[e])*n;return s}function ZD(e,t,n){let[r,i,a]=t>=n?[e[0],e[1],e[3]]:[e[0],e[2],e[3]],o=[i[0]-r[0],i[1]-r[1],i[2]-r[2]],s=[a[0]-r[0],a[1]-r[1],a[2]-r[2]];return{p0:r,n:[o[1]*s[2]-o[2]*s[1],o[2]*s[0]-o[0]*s[2],o[0]*s[1]-o[1]*s[0]]}}function QD(e,t,n){let{p0:r,n:i}=ZD(e,t,n),a=Math.hypot(i[0],i[1],i[2]);if(a<1e-12){let e=Math.hypot(r[0],r[1],r[2]);return[r[0]/e,r[1]/e,r[2]/e]}let o=i[0]*r[0]+i[1]*r[1]+i[2]*r[2]<0?-1/a:1/a;return[i[0]*o,i[1]*o,i[2]*o]}var $D=new Map,eO=new Map,tO=0;function nO(){return tO}var rO=6;function iO(){let e=0;for(let t of $D.values())t!==`failed`&&e++;for(let[t,n]of $D){if(e<=rO)break;n!==`failed`&&($D.delete(t),e--)}}function aO(e,t){let n=eO.get(e);return n||(n=(async()=>{let n=await ND(MD(t,`low`)),r=n&&await FD(n,0,n.height-1);if(!n||!r)return n?.close(),$D.set(e,`failed`),null;let i={data:r,width:n.width,height:n.height,bottomUp:!1};return n.close(),$D.set(e,i),iO(),tO++,i})(),n.finally(()=>eO.delete(e)),eO.set(e,n),n)}function oO(e,t){let n=e.displacementMap?.image;if(!n)return null;let r=n.data;if((r instanceof Uint8Array||r instanceof Float32Array)&&n.width&&n.height)return{data:r,width:n.width,height:n.height,bottomUp:!0};let i=$D.get(t);if(i&&i!==`failed`)return $D.delete(t),$D.set(t,i),i;let a=e.displacementMeta;return!i&&a&&aO(t,a),null}function sO(e,t,n){let r=.5+n/(2*Math.PI),i=.5+t/Math.PI,a=(r-Math.floor(r))*e.width-.5,o=(e.bottomUp?i:1-i)*e.height-.5;return WD(e.data,e.width,e.height,a,o)}async function cO(e,t,n,r,i){let a=(e&&oO(e,t))??await aO(t,n);if(!a)return null;let o=n.bias_km-(n.absolute_radius?r:0),s=new Float64Array(i.length);for(let e=0;e<i.length;e++)s[e]=sO(a,i[e].latRad,i[e].lonRad)*n.scale_km+o;return s}var lO=new Map,uO=new Set;function dO(e,t){return lO.get(e)||(uO.has(e)||(uO.add(e),(async()=>{try{let n=(await tS(e,!1)).global;lO.set(e,n?.radii??{a:t,b:t,c:t})}catch(n){console.warn(`Failed to load radii for ${e}:`,n),lO.set(e,{a:t,b:t,c:t})}finally{uO.delete(e),tO++}})()),null)}function fO(e){let t=e?.terrainWindow;return t?{kind:`window`,thetas:t.thetas,phis:t.phis,riseKm:t.riseKm}:{kind:`uniform`,segs:e?.currentSegments??128}}function pO(e,t,n,r,i){let a=dO(t,n);if(!a)return null;let o=fO(e),s=null,c=0,l=0,u=e?.displacementMeta,d=o.kind===`window`&&!!o.riseKm;if(u&&e?.displacementMap&&!d){if(s=oO(e,t),!s)return null;c=u.scale_km,l=u.bias_km-(u.absolute_radius?n:0)}let{corners:f,tx:p,ty:m}=YD(o,r,i);return{pts:f.map(e=>{let t=e.riseKm??(s?sO(s,e.latRad,e.lonRad)*c+l:0);return JD(e.latRad,e.lonRad,t,n,a.a,a.b,a.c)}),tx:p,ty:m}}function mO(e,t,n,r,i){let a=pO(e,t,n,r,i);return a?{pointKm:XD(a.pts,a.tx,a.ty),normal:QD(a.pts,a.tx,a.ty)}:null}function hO(e,t,n,r){let i=dO(t,n);if(!i)return null;let a=pO(e,t,n,Math.atan2(r[1]/i.c,Math.hypot(r[0]/i.a,r[2]/i.b)),Math.atan2(-r[2]/i.b,r[0]/i.a));if(!a)return null;let{p0:o,n:s}=ZD(a.pts,a.tx,a.ty),c=r[0]*s[0]+r[1]*s[1]+r[2]*s[2];if(Math.abs(c)<1e-12)return null;let l=(o[0]*s[0]+o[1]*s[1]+o[2]*s[2])/c;return l>0?l:null}function gO(e,t,n){let r=e[t];return r||(r=n(),e[t]=r),r}function _O(e){switch(e){case G.STAR:return 0;case G.PLANET:return 1;case G.DWARF_PLANET:return 2;case G.MOON:return 3;default:return 4}}function vO(e){return e.body.position!==null&&!e.carried}var yO=new J,bO=22;function xO(){return{cx0:0,cy0:0,f:0,gxx:0,gxy:0,gxz:0,gyx:0,gyy:0,gyz:0,gzx:0,gzy:0,gzz:0,cpx:0,cpy:0,cpz:0,K:0,id:``,dist:0,ccx:0,ccy:0,ccz:0}}var SO=new WeakMap;function CO(e){SO.delete(e)}function wO(e,t,n,r=.3,i=null){if(e){let t=`d${r}${+!!n}`;if(SO.get(e)===t)return;SO.set(e,t),e.style.transform=`scale(${r})`,e.parentElement&&(e.parentElement.style.pointerEvents=n?``:`none`)}t&&(t.style.display=`none`,t.style.fontSize=``),i&&(i.style.display=`none`)}function TO(e,t,n,r,i=null){if(e){let t=`r${+!!n}${+!!r}`;if(SO.get(e)===t)return;SO.set(e,t),n||(e.style.transform=``),e.style.border=e.dataset.origBorder??``,e.parentElement&&(e.parentElement.style.pointerEvents=``)}t&&(t.style.display=``,t.style.fontSize=r?`18px`:``),i&&(i.style.display=``)}function EO(e,t,n,r,i,a){let{label:o,labelHalo:s,radiusScene:c}=e;if(!o)return!1;let l=o.visible,u=!e.noPhysical&&c>0?c/r*i:0,d=e.body.data.id===a,f=u>=16;return!t&&n&&(d||u>=1)&&(t=u<320),f&&e.labelAnchorOffscreen&&(t=!1),e.trail&&f&&(e.trail.visible=!1),o.visible=t,s&&e.haloHidden!==f&&(s.style.visibility=f?`hidden`:``,e.haloHidden=f),e.loadingEl&&e.loadingShown!==f&&(e.loadingEl.style.display=f?``:`none`,e.loadingShown=f),o.center.x=f?1-4/32:.5,t&&!l}function DO(e,t,n,r,i,a=null){for(let o of i){if(o.id===r||o.id===a)continue;let i=e-o.cx0,s=o.cy0-t,c=-o.f,l=i*o.gxx+s*o.gxy+c*o.gxz,u=i*o.gyx+s*o.gyy+c*o.gyz,d=i*o.gzx+s*o.gzy+c*o.gzz,f=l*o.cpx+u*o.cpy+d*o.cpz;if(!(f<=0)&&!(f*f<=o.K*(l*l+u*u+d*d))&&i*o.ccx+s*o.ccy+c*o.ccz<=n*Math.hypot(i,s,c))return!0}return!1}function OO(e,t){e.left=t.left,e.right=t.right,e.y=t.y,e.h=t.h}function kO(e,t,n,r,i,a){let o=e.label,s=e.body.position;if(!s)return!1;let[c,l,u]=s,d=o.position;yO.set(c-n[0]+d.x,l-n[1]+d.y,u-n[2]+d.z),yO.project(t),a.x=(yO.x*.5+.5)*r,a.y=(-yO.y*.5+.5)*i;let f=a.x-o.center.x*32;return a.left=f,a.right=f+40+(e.labelTextWidth||50),a.h=bO,bw(yO.z)}var AO=[],jO=0,MO=[],NO=0,PO=[],FO=0,IO={rects:MO,get count(){return NO}};function LO(){return{bodyId:``,bo:null,body:null,label:null,labelHalo:null,isCapped:!1,isMinor:!1,isFocused:!1,isSelected:!1,rect:{x:0,left:0,right:0,y:0,h:0},dist:0}}function RO(){return{left:0,right:0,y:0,h:0}}var zO={x:0,left:0,right:0,y:0,h:0};function BO(e,t){for(let n=0;n<t;n++)OO(gO(PO,n,RO),e[n]);FO=t}function VO(){for(let e=0;e<FO;e++)OO(gO(MO,e,RO),PO[e]);return FO}function HO(e,t,n,r,i,a,o,s,c=[0,0,0]){jO=0,NO=VO();for(let s of e.values()){let{body:e,label:l,labelHalo:u}=s;if(!l?.visible)continue;if(!s.labelTextWidth&&u){let e=u.nextElementSibling;e&&e.offsetWidth>0&&(s.labelTextWidth=e.offsetWidth)}if(!kO(s,r,c,t,n,zO))continue;let d=e.data.id===i,f=o.has(e.data.id),p=gO(AO,jO++,LO);OO(p.rect,zO),p.rect.x=zO.x,p.bodyId=e.data.id,p.bo=s,p.body=e,p.label=l,p.labelHalo=u,p.isCapped=e.data.objectType===G.MOON?a.visibility.getMoonVisibility(e)===$.CAPPED:!1,p.isMinor=s.isMinor,p.isFocused=d,p.isSelected=d||f||a.visibility.isPinned(e.data.id),p.dist=s.cachedDist}AO.length=jO,AO.sort((e,t)=>{if(e.isSelected!==t.isSelected)return e.isSelected?-1:1;let n=e.isMinor&&!e.isSelected;if(n!==(t.isMinor&&!t.isSelected))return n?1:-1;let r=_O(e.body.data.objectType),i=_O(t.body.data.objectType);return r===i?e.dist-t.dist:r-i});for(let e=0;e<jO;e++){let t=AO[e],n=t.labelHalo,r=n?.nextElementSibling;if(t.isCapped&&!t.isSelected){wO(n,r,!0,.3,t.bo.labelStack),t.bo.labelMaximized=!1;continue}if(!t.isSelected&&DO(t.rect.x,t.rect.y,t.dist,t.bodyId,s)){t.label.visible=!1,t.bo.labelMaximized=!1;continue}if(t.isMinor&&!t.isSelected){let e=!1;for(let n=0;n<NO;n++){let r=MO[n];if(t.rect.x-8<r.right&&t.rect.x+8>r.left&&Math.abs(t.rect.y-r.y)<bO){e=!0;break}}wO(n,r,!e,e?.3:.5,t.bo.labelStack),t.bo.labelMaximized=!1;continue}let i=!1;for(let e=0;e<NO;e++){let n=MO[e];if(t.rect.left<n.right&&t.rect.right>n.left&&Math.abs(t.rect.y-n.y)<bO){i=!0;break}}i?(wO(n,r,!1,.3,t.bo.labelStack),t.bo.labelMaximized=!1):(OO(gO(MO,NO++,RO),t.rect),TO(n,r,o.has(t.bodyId),t.isFocused,t.bo.labelStack),t.bo.labelMaximized=!0)}for(let e=0;e<jO;e++){let t=AO[e];t.bo=null,t.body=null,t.label=null,t.labelHalo=null}}function UO(e,t,n,r,i){NO=VO();for(let a of e.values())a.label?.visible&&a.labelMaximized!==!1&&kO(a,r,i,t,n,zO)&&OO(gO(MO,NO++,RO),zO)}function WO(e,t){if(t===0)return console.warn(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Geometry already defined as triangles.`),e;if(t===2||t===1){let n=e.getIndex();if(n===null){let t=[],r=e.getAttribute(`position`);if(r!==void 0){for(let e=0;e<r.count;e++)t.push(e);e.setIndex(t),n=e.getIndex()}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Undefined position attribute. Processing not possible.`),e}let r=n.count-2,i=[];if(t===2)for(let e=1;e<=r;e++)i.push(n.getX(0)),i.push(n.getX(e)),i.push(n.getX(e+1));else for(let e=0;e<r;e++)e%2==0?(i.push(n.getX(e)),i.push(n.getX(e+1)),i.push(n.getX(e+2))):(i.push(n.getX(e+2)),i.push(n.getX(e+1)),i.push(n.getX(e)));i.length/3!==r&&console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unable to generate correct amount of triangles.`);let a=e.clone();return a.setIndex(i),a.clearGroups(),a}else return console.error(`THREE.BufferGeometryUtils.toTrianglesDrawMode(): Unknown draw mode:`,t),e}function GO(e){let t=new Map,n=new Map,r=e.clone();return KO(e,r,function(e,r){t.set(r,e),n.set(e,r)}),r.traverse(function(e){if(!e.isSkinnedMesh)return;let r=e,i=t.get(e),a=i.skeleton.bones;r.skeleton=i.skeleton.clone(),r.bindMatrix.copy(i.bindMatrix),r.skeleton.bones=a.map(function(e){return n.get(e)}),r.bind(r.skeleton,r.bindMatrix)}),r}function KO(e,t,n){n(e,t);for(let r=0;r<e.children.length;r++)KO(e.children[r],t.children[r],n)}var qO=class extends td{constructor(e){super(e),this.dracoLoader=null,this.ktx2Loader=null,this.meshoptDecoder=null,this.pluginCallbacks=[],this.register(function(e){return new ek(e)}),this.register(function(e){return new tk(e)}),this.register(function(e){return new uk(e)}),this.register(function(e){return new dk(e)}),this.register(function(e){return new fk(e)}),this.register(function(e){return new rk(e)}),this.register(function(e){return new ik(e)}),this.register(function(e){return new ak(e)}),this.register(function(e){return new ok(e)}),this.register(function(e){return new $O(e)}),this.register(function(e){return new sk(e)}),this.register(function(e){return new nk(e)}),this.register(function(e){return new lk(e)}),this.register(function(e){return new ck(e)}),this.register(function(e){return new ZO(e)}),this.register(function(e){return new pk(e,XO.EXT_MESHOPT_COMPRESSION)}),this.register(function(e){return new pk(e,XO.KHR_MESHOPT_COMPRESSION)}),this.register(function(e){return new mk(e)})}load(e,t,n,r){let i=this,a;if(this.resourcePath!==``)a=this.resourcePath;else if(this.path!==``){let t=kd.extractUrlBase(e);a=kd.resolveURL(t,this.path)}else a=kd.extractUrlBase(e);this.manager.itemStart(e);let o=function(t){r?r(t):console.error(t),i.manager.itemError(e),i.manager.itemEnd(e)},s=new id(this.manager);s.setPath(this.path),s.setResponseType(`arraybuffer`),s.setRequestHeader(this.requestHeader),s.setWithCredentials(this.withCredentials),s.load(e,function(n){try{i.parse(n,a,function(n){t(n),i.manager.itemEnd(e)},o)}catch(e){o(e)}},n,o)}setDRACOLoader(e){return this.dracoLoader=e,this}setKTX2Loader(e){return this.ktx2Loader=e,this}setMeshoptDecoder(e){return this.meshoptDecoder=e,this}register(e){return this.pluginCallbacks.indexOf(e)===-1&&this.pluginCallbacks.push(e),this}unregister(e){return this.pluginCallbacks.indexOf(e)!==-1&&this.pluginCallbacks.splice(this.pluginCallbacks.indexOf(e),1),this}parse(e,t,n,r){let i,a={},o={},s=new TextDecoder;if(typeof e==`string`)i=JSON.parse(e);else if(e instanceof ArrayBuffer)if(s.decode(new Uint8Array(e,0,4))===hk){try{a[XO.KHR_BINARY_GLTF]=new vk(e)}catch(e){r&&r(e);return}i=JSON.parse(a[XO.KHR_BINARY_GLTF].content)}else i=JSON.parse(s.decode(e));else i=e;if(i.asset===void 0||i.asset.version[0]<2){r&&r(Error(`THREE.GLTFLoader: Unsupported asset. glTF versions >=2.0 are supported.`));return}let c=new Wk(i,{path:t||this.resourcePath||``,crossOrigin:this.crossOrigin,requestHeader:this.requestHeader,manager:this.manager,ktx2Loader:this.ktx2Loader,meshoptDecoder:this.meshoptDecoder});c.fileLoader.setRequestHeader(this.requestHeader);for(let e=0;e<this.pluginCallbacks.length;e++){let t=this.pluginCallbacks[e](c);t.name||console.error(`THREE.GLTFLoader: Invalid plugin found: missing name`),o[t.name]=t,a[t.name]=!0}if(i.extensionsUsed)for(let e=0;e<i.extensionsUsed.length;++e){let t=i.extensionsUsed[e],n=i.extensionsRequired||[];switch(t){case XO.KHR_MATERIALS_UNLIT:a[t]=new QO;break;case XO.KHR_DRACO_MESH_COMPRESSION:a[t]=new yk(i,this.dracoLoader);break;case XO.KHR_TEXTURE_TRANSFORM:a[t]=new bk;break;case XO.KHR_MESH_QUANTIZATION:a[t]=new xk;break;default:n.indexOf(t)>=0&&o[t]===void 0&&console.warn(`THREE.GLTFLoader: Unknown extension "`+t+`".`)}}c.setExtensions(a),c.setPlugins(o),c.parse(n,r)}parseAsync(e,t){let n=this;return new Promise(function(r,i){n.parse(e,t,r,i)})}};function JO(){let e={};return{get:function(t){return e[t]},add:function(t,n){e[t]=n},remove:function(t){delete e[t]},removeAll:function(){e={}}}}function YO(e,t,n){let r=e.json.materials[t];return r.extensions&&r.extensions[n]?r.extensions[n]:null}var XO={KHR_BINARY_GLTF:`KHR_binary_glTF`,KHR_DRACO_MESH_COMPRESSION:`KHR_draco_mesh_compression`,KHR_LIGHTS_PUNCTUAL:`KHR_lights_punctual`,KHR_MATERIALS_CLEARCOAT:`KHR_materials_clearcoat`,KHR_MATERIALS_DISPERSION:`KHR_materials_dispersion`,KHR_MATERIALS_IOR:`KHR_materials_ior`,KHR_MATERIALS_SHEEN:`KHR_materials_sheen`,KHR_MATERIALS_SPECULAR:`KHR_materials_specular`,KHR_MATERIALS_TRANSMISSION:`KHR_materials_transmission`,KHR_MATERIALS_IRIDESCENCE:`KHR_materials_iridescence`,KHR_MATERIALS_ANISOTROPY:`KHR_materials_anisotropy`,KHR_MATERIALS_UNLIT:`KHR_materials_unlit`,KHR_MATERIALS_VOLUME:`KHR_materials_volume`,KHR_TEXTURE_BASISU:`KHR_texture_basisu`,KHR_TEXTURE_TRANSFORM:`KHR_texture_transform`,KHR_MESH_QUANTIZATION:`KHR_mesh_quantization`,KHR_MATERIALS_EMISSIVE_STRENGTH:`KHR_materials_emissive_strength`,EXT_MATERIALS_BUMP:`EXT_materials_bump`,EXT_TEXTURE_WEBP:`EXT_texture_webp`,EXT_TEXTURE_AVIF:`EXT_texture_avif`,EXT_MESHOPT_COMPRESSION:`EXT_meshopt_compression`,KHR_MESHOPT_COMPRESSION:`KHR_meshopt_compression`,EXT_MESH_GPU_INSTANCING:`EXT_mesh_gpu_instancing`},ZO=class{constructor(e){this.parser=e,this.name=XO.KHR_LIGHTS_PUNCTUAL,this.cache={refs:{},uses:{}}}_markDefs(){let e=this.parser,t=this.parser.json.nodes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n];r.extensions&&r.extensions[this.name]&&r.extensions[this.name].light!==void 0&&e._addNodeRef(this.cache,r.extensions[this.name].light)}}_loadLight(e){let t=this.parser,n=`light:`+e,r=t.cache.get(n);if(r)return r;let i=t.json,a=((i.extensions&&i.extensions[this.name]||{}).lights||[])[e],o,s=new X(16777215);a.color!==void 0&&s.setRGB(a.color[0],a.color[1],a.color[2],ii);let c=a.range===void 0?0:a.range;switch(a.type){case`directional`:o=new Dd(s),o.target.position.set(0,0,-1),o.add(o.target);break;case`point`:o=new wd(s),o.distance=c;break;case`spot`:o=new Sd(s),o.distance=c,a.spot=a.spot||{},a.spot.innerConeAngle=a.spot.innerConeAngle===void 0?0:a.spot.innerConeAngle,a.spot.outerConeAngle=a.spot.outerConeAngle===void 0?Math.PI/4:a.spot.outerConeAngle,o.angle=a.spot.outerConeAngle,o.penumbra=1-a.spot.innerConeAngle/a.spot.outerConeAngle,o.target.position.set(0,0,-1),o.add(o.target);break;default:throw Error(`THREE.GLTFLoader: Unexpected light type: `+a.type)}return o.position.set(0,0,0),Ik(o,a),a.intensity!==void 0&&(o.intensity=a.intensity),o.name=t.createUniqueName(a.name||`light_`+e),r=Promise.resolve(o),t.cache.add(n,r),r}getDependency(e,t){if(e===`light`)return this._loadLight(t)}createNodeAttachment(e){let t=this,n=this.parser,r=n.json.nodes[e],i=(r.extensions&&r.extensions[this.name]||{}).light;return i===void 0?null:this._loadLight(i).then(function(e){return n._getNodeRef(t.cache,i,e)})}},QO=class{constructor(){this.name=XO.KHR_MATERIALS_UNLIT}getMaterialType(){return js}extendParams(e,t,n){let r=[];e.color=new X(1,1,1),e.opacity=1;let i=t.pbrMetallicRoughness;if(i){if(Array.isArray(i.baseColorFactor)){let t=i.baseColorFactor;e.color.setRGB(t[0],t[1],t[2],ii),e.opacity=t[3]}i.baseColorTexture!==void 0&&r.push(n.assignTexture(e,`map`,i.baseColorTexture,ri))}return Promise.all(r)}},$O=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_EMISSIVE_STRENGTH}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);return n===null||n.emissiveStrength!==void 0&&(t.emissiveIntensity=n.emissiveStrength),Promise.resolve()}},ek=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_CLEARCOAT}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(n.clearcoatFactor!==void 0&&(t.clearcoat=n.clearcoatFactor),n.clearcoatTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatMap`,n.clearcoatTexture)),n.clearcoatRoughnessFactor!==void 0&&(t.clearcoatRoughness=n.clearcoatRoughnessFactor),n.clearcoatRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`clearcoatRoughnessMap`,n.clearcoatRoughnessTexture)),n.clearcoatNormalTexture!==void 0&&(r.push(this.parser.assignTexture(t,`clearcoatNormalMap`,n.clearcoatNormalTexture)),n.clearcoatNormalTexture.scale!==void 0)){let e=n.clearcoatNormalTexture.scale;t.clearcoatNormalScale=new q(e,e)}return Promise.all(r)}},tk=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_DISPERSION}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);return n===null||(t.dispersion=n.dispersion===void 0?0:n.dispersion),Promise.resolve()}},nk=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_IRIDESCENCE}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.iridescenceFactor!==void 0&&(t.iridescence=n.iridescenceFactor),n.iridescenceTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceMap`,n.iridescenceTexture)),n.iridescenceIor!==void 0&&(t.iridescenceIOR=n.iridescenceIor),t.iridescenceThicknessRange===void 0&&(t.iridescenceThicknessRange=[100,400]),n.iridescenceThicknessMinimum!==void 0&&(t.iridescenceThicknessRange[0]=n.iridescenceThicknessMinimum),n.iridescenceThicknessMaximum!==void 0&&(t.iridescenceThicknessRange[1]=n.iridescenceThicknessMaximum),n.iridescenceThicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`iridescenceThicknessMap`,n.iridescenceThicknessTexture)),Promise.all(r)}},rk=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_SHEEN}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];if(t.sheenColor=new X(0,0,0),t.sheenRoughness=0,t.sheen=1,n.sheenColorFactor!==void 0){let e=n.sheenColorFactor;t.sheenColor.setRGB(e[0],e[1],e[2],ii)}return n.sheenRoughnessFactor!==void 0&&(t.sheenRoughness=n.sheenRoughnessFactor),n.sheenColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenColorMap`,n.sheenColorTexture,ri)),n.sheenRoughnessTexture!==void 0&&r.push(this.parser.assignTexture(t,`sheenRoughnessMap`,n.sheenRoughnessTexture)),Promise.all(r)}},ik=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_TRANSMISSION}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.transmissionFactor!==void 0&&(t.transmission=n.transmissionFactor),n.transmissionTexture!==void 0&&r.push(this.parser.assignTexture(t,`transmissionMap`,n.transmissionTexture)),Promise.all(r)}},ak=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_VOLUME}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.thickness=n.thicknessFactor===void 0?0:n.thicknessFactor,n.thicknessTexture!==void 0&&r.push(this.parser.assignTexture(t,`thicknessMap`,n.thicknessTexture)),t.attenuationDistance=n.attenuationDistance||1/0;let i=n.attenuationColor||[1,1,1];return t.attenuationColor=new X().setRGB(i[0],i[1],i[2],ii),Promise.all(r)}},ok=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_IOR}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);return n===null||(t.ior=n.ior===void 0?1.5:n.ior),Promise.resolve()}},sk=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_SPECULAR}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];t.specularIntensity=n.specularFactor===void 0?1:n.specularFactor,n.specularTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularIntensityMap`,n.specularTexture));let i=n.specularColorFactor||[1,1,1];return t.specularColor=new X().setRGB(i[0],i[1],i[2],ii),n.specularColorTexture!==void 0&&r.push(this.parser.assignTexture(t,`specularColorMap`,n.specularColorTexture,ri)),Promise.all(r)}},ck=class{constructor(e){this.parser=e,this.name=XO.EXT_MATERIALS_BUMP}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return t.bumpScale=n.bumpFactor===void 0?1:n.bumpFactor,n.bumpTexture!==void 0&&r.push(this.parser.assignTexture(t,`bumpMap`,n.bumpTexture)),Promise.all(r)}},lk=class{constructor(e){this.parser=e,this.name=XO.KHR_MATERIALS_ANISOTROPY}getMaterialType(e){return YO(this.parser,e,this.name)===null?null:Ou}extendMaterialParams(e,t){let n=YO(this.parser,e,this.name);if(n===null)return Promise.resolve();let r=[];return n.anisotropyStrength!==void 0&&(t.anisotropy=n.anisotropyStrength),n.anisotropyRotation!==void 0&&(t.anisotropyRotation=n.anisotropyRotation),n.anisotropyTexture!==void 0&&r.push(this.parser.assignTexture(t,`anisotropyMap`,n.anisotropyTexture)),Promise.all(r)}},uk=class{constructor(e){this.parser=e,this.name=XO.KHR_TEXTURE_BASISU}loadTexture(e){let t=this.parser,n=t.json,r=n.textures[e];if(!r.extensions||!r.extensions[this.name])return null;let i=r.extensions[this.name],a=t.options.ktx2Loader;if(!a){if(n.extensionsRequired&&n.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setKTX2Loader must be called before loading KTX2 textures`);return null}return t.loadTextureImage(e,i.source,a)}},dk=class{constructor(e){this.parser=e,this.name=XO.EXT_TEXTURE_WEBP}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},fk=class{constructor(e){this.parser=e,this.name=XO.EXT_TEXTURE_AVIF}loadTexture(e){let t=this.name,n=this.parser,r=n.json,i=r.textures[e];if(!i.extensions||!i.extensions[t])return null;let a=i.extensions[t],o=r.images[a.source],s=n.textureLoader;if(o.uri){let e=n.options.manager.getHandler(o.uri);e!==null&&(s=e)}return n.loadTextureImage(e,a.source,s)}},pk=class{constructor(e,t){this.name=t,this.parser=e}loadBufferView(e){let t=this.parser.json,n=t.bufferViews[e];if(n.extensions&&n.extensions[this.name]){let e=n.extensions[this.name],r=this.parser.getDependency(`buffer`,e.buffer),i=this.parser.options.meshoptDecoder;if(!i||!i.supported){if(t.extensionsRequired&&t.extensionsRequired.indexOf(this.name)>=0)throw Error(`THREE.GLTFLoader: setMeshoptDecoder must be called before loading compressed files`);return null}return r.then(function(t){let n=e.byteOffset||0,r=e.byteLength||0,a=e.count,o=e.byteStride,s=new Uint8Array(t,n,r);return i.decodeGltfBufferAsync?i.decodeGltfBufferAsync(a,o,s,e.mode,e.filter).then(function(e){return e.buffer}):i.ready.then(function(){let t=new ArrayBuffer(a*o);return i.decodeGltfBuffer(new Uint8Array(t),a,o,s,e.mode,e.filter),t})})}else return null}},mk=class{constructor(e){this.name=XO.EXT_MESH_GPU_INSTANCING,this.parser=e}createNodeMesh(e){let t=this.parser.json,n=t.nodes[e];if(!n.extensions||!n.extensions[this.name]||n.mesh===void 0)return null;let r=t.meshes[n.mesh];for(let e of r.primitives)if(e.mode!==Tk.TRIANGLES&&e.mode!==Tk.TRIANGLE_STRIP&&e.mode!==Tk.TRIANGLE_FAN&&e.mode!==void 0)return null;let i=n.extensions[this.name].attributes,a=[],o={};for(let e in i)a.push(this.parser.getDependency(`accessor`,i[e]).then(t=>(o[e]=t,o[e])));return a.length<1?null:(a.push(this.parser.createNodeMesh(e)),Promise.all(a).then(e=>{let t=e.pop(),n=t.isGroup?t.children:[t],r=e[0].count,i=[];for(let e of n){let t=new Y,n=new J,a=new Xi,s=new J(1,1,1),c=new hc(e.geometry,e.material,r);for(let e=0;e<r;e++)o.TRANSLATION&&n.fromBufferAttribute(o.TRANSLATION,e),o.ROTATION&&a.fromBufferAttribute(o.ROTATION,e),o.SCALE&&s.fromBufferAttribute(o.SCALE,e),c.setMatrixAt(e,t.compose(n,a,s));for(let t in o)if(t===`_COLOR_0`){let e=o[t];c.instanceColor=new sc(e.array,e.itemSize,e.normalized)}else t!==`TRANSLATION`&&t!==`ROTATION`&&t!==`SCALE`&&e.geometry.setAttribute(t,o[t]);Ka.prototype.copy.call(c,e),this.parser.assignFinalMaterial(c),i.push(c)}return t.isGroup?(t.clear(),t.add(...i),t):i[0]}))}},hk=`glTF`,gk=12,_k={JSON:1313821514,BIN:5130562},vk=class{constructor(e){this.name=XO.KHR_BINARY_GLTF,this.content=null,this.body=null;let t=new DataView(e,0,gk),n=new TextDecoder;if(this.header={magic:n.decode(new Uint8Array(e.slice(0,4))),version:t.getUint32(4,!0),length:t.getUint32(8,!0)},this.header.magic!==hk)throw Error(`THREE.GLTFLoader: Unsupported glTF-Binary header.`);if(this.header.version<2)throw Error(`THREE.GLTFLoader: Legacy binary file detected.`);let r=this.header.length-gk,i=new DataView(e,gk),a=0;for(;a<r;){let t=i.getUint32(a,!0);a+=4;let r=i.getUint32(a,!0);if(a+=4,r===_k.JSON){let r=new Uint8Array(e,gk+a,t);this.content=n.decode(r)}else if(r===_k.BIN){let n=gk+a;this.body=e.slice(n,n+t)}a+=t}if(this.content===null)throw Error(`THREE.GLTFLoader: JSON content not found.`)}},yk=class{constructor(e,t){if(!t)throw Error(`THREE.GLTFLoader: No DRACOLoader instance provided.`);this.name=XO.KHR_DRACO_MESH_COMPRESSION,this.json=e,this.dracoLoader=t,this.dracoLoader.preload()}decodePrimitive(e,t){let n=this.json,r=this.dracoLoader,i=e.extensions[this.name].bufferView,a=e.extensions[this.name].attributes,o={},s={},c={};for(let e in a){let t=Ak[e]||e.toLowerCase();o[t]=a[e]}for(let t in e.attributes){let r=Ak[t]||t.toLowerCase();if(a[t]!==void 0){let i=n.accessors[e.attributes[t]];c[r]=Ek[i.componentType].name,s[r]=i.normalized===!0}}return t.getDependency(`bufferView`,i).then(function(e){return new Promise(function(t,n){r.decodeDracoFile(e,function(e){for(let t in e.attributes){let n=e.attributes[t],r=s[t];r!==void 0&&(n.normalized=r)}t(e)},o,c,ii,n)})})}},bk=class{constructor(){this.name=XO.KHR_TEXTURE_TRANSFORM}extendTexture(e,t){return(t.texCoord===void 0||t.texCoord===e.channel)&&t.offset===void 0&&t.rotation===void 0&&t.scale===void 0?e:(e=e.clone(),t.texCoord!==void 0&&(e.channel=t.texCoord),t.offset!==void 0&&e.offset.fromArray(t.offset),t.rotation!==void 0&&(e.rotation=t.rotation),t.scale!==void 0&&e.repeat.fromArray(t.scale),e.needsUpdate=!0,e)}},xk=class{constructor(){this.name=XO.KHR_MESH_QUANTIZATION}},Sk=class extends Iu{constructor(e,t,n,r){super(e,t,n,r)}copySampleValue_(e){let t=this.resultBuffer,n=this.sampleValues,r=this.valueSize,i=e*r*3+r;for(let e=0;e!==r;e++)t[e]=n[i+e];return t}interpolate_(e,t,n,r){let i=this.resultBuffer,a=this.sampleValues,o=this.valueSize,s=o*2,c=o*3,l=r-t,u=(n-t)/l,d=u*u,f=d*u,p=e*c,m=p-c,h=-2*f+3*d,g=f-d,_=1-h,v=g-d+u;for(let e=0;e!==o;e++){let t=a[m+e+o],n=a[m+e+s]*l,r=a[p+e+o],c=a[p+e]*l;i[e]=_*t+v*n+h*r+g*c}return i}},Ck=new Xi,wk=class extends Sk{interpolate_(e,t,n,r){let i=super.interpolate_(e,t,n,r);return Ck.fromArray(i).normalize().toArray(i),i}},Tk={FLOAT:5126,FLOAT_MAT3:35675,FLOAT_MAT4:35676,FLOAT_VEC2:35664,FLOAT_VEC3:35665,FLOAT_VEC4:35666,LINEAR:9729,REPEAT:10497,SAMPLER_2D:35678,POINTS:0,LINES:1,LINE_LOOP:2,LINE_STRIP:3,TRIANGLES:4,TRIANGLE_STRIP:5,TRIANGLE_FAN:6,UNSIGNED_BYTE:5121,UNSIGNED_SHORT:5123},Ek={5120:Int8Array,5121:Uint8Array,5122:Int16Array,5123:Uint16Array,5125:Uint32Array,5126:Float32Array},Dk={9728:Ln,9729:Bn,9984:Rn,9985:Vn,9986:zn,9987:Hn},Ok={33071:Fn,33648:In,10497:Pn},kk={SCALAR:1,VEC2:2,VEC3:3,VEC4:4,MAT2:4,MAT3:9,MAT4:16},Ak={POSITION:`position`,NORMAL:`normal`,TANGENT:`tangent`,TEXCOORD_0:`uv`,TEXCOORD_1:`uv1`,TEXCOORD_2:`uv2`,TEXCOORD_3:`uv3`,COLOR_0:`color`,WEIGHTS_0:`skinWeight`,JOINTS_0:`skinIndex`},jk={scale:`scale`,translation:`position`,rotation:`quaternion`,weights:`morphTargetInfluences`},Mk={CUBICSPLINE:void 0,LINEAR:Yr,STEP:Jr},Nk={OPAQUE:`OPAQUE`,MASK:`MASK`,BLEND:`BLEND`};function Pk(e){return e.DefaultMaterial===void 0&&(e.DefaultMaterial=new Du({color:16777215,emissive:0,metalness:1,roughness:1,transparent:!1,depthTest:!0,side:0})),e.DefaultMaterial}function Fk(e,t,n){for(let r in n.extensions)e[r]===void 0&&(t.userData.gltfExtensions=t.userData.gltfExtensions||{},t.userData.gltfExtensions[r]=n.extensions[r])}function Ik(e,t){t.extras!==void 0&&(typeof t.extras==`object`?Object.assign(e.userData,t.extras):console.warn(`THREE.GLTFLoader: Ignoring primitive type .extras, `+t.extras))}function Lk(e,t,n){let r=!1,i=!1,a=!1;for(let e=0,n=t.length;e<n;e++){let n=t[e];if(n.POSITION!==void 0&&(r=!0),n.NORMAL!==void 0&&(i=!0),n.COLOR_0!==void 0&&(a=!0),r&&i&&a)break}if(!r&&!i&&!a)return Promise.resolve(e);let o=[],s=[],c=[];for(let l=0,u=t.length;l<u;l++){let u=t[l];if(r){let t=u.POSITION===void 0?e.attributes.position:n.getDependency(`accessor`,u.POSITION);o.push(t)}if(i){let t=u.NORMAL===void 0?e.attributes.normal:n.getDependency(`accessor`,u.NORMAL);s.push(t)}if(a){let t=u.COLOR_0===void 0?e.attributes.color:n.getDependency(`accessor`,u.COLOR_0);c.push(t)}}return Promise.all([Promise.all(o),Promise.all(s),Promise.all(c)]).then(function(t){let n=t[0],o=t[1],s=t[2];return r&&(e.morphAttributes.position=n),i&&(e.morphAttributes.normal=o),a&&(e.morphAttributes.color=s),e.morphTargetsRelative=!0,e})}function Rk(e,t){if(e.updateMorphTargets(),t.weights!==void 0)for(let n=0,r=t.weights.length;n<r;n++)e.morphTargetInfluences[n]=t.weights[n];if(t.extras&&Array.isArray(t.extras.targetNames)){let n=t.extras.targetNames;if(e.morphTargetInfluences.length===n.length){e.morphTargetDictionary={};for(let t=0,r=n.length;t<r;t++)e.morphTargetDictionary[n[t]]=t}else console.warn(`THREE.GLTFLoader: Invalid extras.targetNames length. Ignoring names.`)}}function zk(e){let t,n=e.extensions&&e.extensions[XO.KHR_DRACO_MESH_COMPRESSION];if(t=n?`draco:`+n.bufferView+`:`+n.indices+`:`+Bk(n.attributes):e.indices+`:`+Bk(e.attributes)+`:`+e.mode,e.targets!==void 0)for(let n=0,r=e.targets.length;n<r;n++)t+=`:`+Bk(e.targets[n]);return t}function Bk(e){let t=``,n=Object.keys(e).sort();for(let r=0,i=n.length;r<i;r++)t+=n[r]+`:`+e[n[r]]+`;`;return t}function Vk(e){switch(e){case Int8Array:return 1/127;case Uint8Array:return 1/255;case Int16Array:return 1/32767;case Uint16Array:return 1/65535;default:throw Error(`THREE.GLTFLoader: Unsupported normalized accessor component type.`)}}function Hk(e){return e.search(/\.jpe?g($|\?)/i)>0||e.search(/^data\:image\/jpeg/)===0?`image/jpeg`:e.search(/\.webp($|\?)/i)>0||e.search(/^data\:image\/webp/)===0?`image/webp`:e.search(/\.ktx2($|\?)/i)>0||e.search(/^data\:image\/ktx2/)===0?`image/ktx2`:`image/png`}var Uk=new Y,Wk=class{constructor(e={},t={}){this.json=e,this.extensions={},this.plugins={},this.options=t,this.cache=new JO,this.associations=new Map,this.primitiveCache={},this.nodeCache={},this.meshCache={refs:{},uses:{}},this.cameraCache={refs:{},uses:{}},this.lightCache={refs:{},uses:{}},this.sourceCache={},this.textureCache={},this.nodeNamesUsed={};let n=!1,r=-1,i=!1,a=-1;if(typeof navigator<`u`&&navigator.userAgent!==void 0){let e=navigator.userAgent;n=/^((?!chrome|android).)*safari/i.test(e)===!0;let t=e.match(/Version\/(\d+)/);r=n&&t?parseInt(t[1],10):-1,i=e.indexOf(`Firefox`)>-1,a=i?e.match(/Firefox\/([0-9]+)\./)[1]:-1}typeof createImageBitmap>`u`||n&&r<17||i&&a<98?this.textureLoader=new sd(this.options.manager):this.textureLoader=new jd(this.options.manager),this.textureLoader.setCrossOrigin(this.options.crossOrigin),this.textureLoader.setRequestHeader(this.options.requestHeader),this.fileLoader=new id(this.options.manager),this.fileLoader.setResponseType(`arraybuffer`),this.options.crossOrigin===`use-credentials`&&this.fileLoader.setWithCredentials(!0)}setExtensions(e){this.extensions=e}setPlugins(e){this.plugins=e}parse(e,t){let n=this,r=this.json,i=this.extensions;this.cache.removeAll(),this.nodeCache={},this._invokeAll(function(e){return e._markDefs&&e._markDefs()}),Promise.all(this._invokeAll(function(e){return e.beforeRoot&&e.beforeRoot()})).then(function(){return Promise.all([n.getDependencies(`scene`),n.getDependencies(`animation`),n.getDependencies(`camera`)])}).then(function(t){let a={scene:t[0][r.scene||0],scenes:t[0],animations:t[1],cameras:t[2],asset:r.asset,parser:n,userData:{}};return Fk(i,a,r),Ik(a,r),Promise.all(n._invokeAll(function(e){return e.afterRoot&&e.afterRoot(a)})).then(function(){for(let e of a.scenes)e.updateMatrixWorld();e(a)})}).catch(t)}_markDefs(){let e=this.json.nodes||[],t=this.json.skins||[],n=this.json.meshes||[];for(let n=0,r=t.length;n<r;n++){let r=t[n].joints;for(let t=0,n=r.length;t<n;t++)e[r[t]].isBone=!0}for(let t=0,r=e.length;t<r;t++){let r=e[t];r.mesh!==void 0&&(this._addNodeRef(this.meshCache,r.mesh),r.skin!==void 0&&(n[r.mesh].isSkinnedMesh=!0)),r.camera!==void 0&&this._addNodeRef(this.cameraCache,r.camera)}}_addNodeRef(e,t){t!==void 0&&(e.refs[t]===void 0&&(e.refs[t]=e.uses[t]=0),e.refs[t]++)}_getNodeRef(e,t,n){if(e.refs[t]<=1)return n;let r=n.clone(),i=(e,t)=>{let n=this.associations.get(e);n!=null&&this.associations.set(t,n);for(let[n,r]of e.children.entries())i(r,t.children[n])};return i(n,r),r.name+=`_instance_`+ e.uses[t]++,r}_invokeOne(e){let t=Object.values(this.plugins);t.push(this);for(let n=0;n<t.length;n++){let r=e(t[n]);if(r)return r}return null}_invokeAll(e){let t=Object.values(this.plugins);t.unshift(this);let n=[];for(let r=0;r<t.length;r++){let i=e(t[r]);i&&n.push(i)}return n}getDependency(e,t){let n=e+`:`+t,r=this.cache.get(n);if(!r){switch(e){case`scene`:r=this.loadScene(t);break;case`node`:r=this._invokeOne(function(e){return e.loadNode&&e.loadNode(t)});break;case`mesh`:r=this._invokeOne(function(e){return e.loadMesh&&e.loadMesh(t)});break;case`accessor`:r=this.loadAccessor(t);break;case`bufferView`:r=this._invokeOne(function(e){return e.loadBufferView&&e.loadBufferView(t)});break;case`buffer`:r=this.loadBuffer(t);break;case`material`:r=this._invokeOne(function(e){return e.loadMaterial&&e.loadMaterial(t)});break;case`texture`:r=this._invokeOne(function(e){return e.loadTexture&&e.loadTexture(t)});break;case`skin`:r=this.loadSkin(t);break;case`animation`:r=this._invokeOne(function(e){return e.loadAnimation&&e.loadAnimation(t)});break;case`camera`:r=this.loadCamera(t);break;default:if(r=this._invokeOne(function(n){return n!=this&&n.getDependency&&n.getDependency(e,t)}),!r)throw Error(`Unknown type: `+e);break}this.cache.add(n,r)}return r}getDependencies(e){let t=this.cache.get(e);if(!t){let n=this,r=this.json[e+(e===`mesh`?`es`:`s`)]||[];t=Promise.all(r.map(function(t,r){return n.getDependency(e,r)})),this.cache.add(e,t)}return t}loadBuffer(e){let t=this.json.buffers[e],n=this.fileLoader;if(t.type&&t.type!==`arraybuffer`)throw Error(`THREE.GLTFLoader: `+t.type+` buffer type is not supported.`);if(t.uri===void 0&&e===0)return Promise.resolve(this.extensions[XO.KHR_BINARY_GLTF].body);let r=this.options;return new Promise(function(e,i){n.load(kd.resolveURL(t.uri,r.path),e,void 0,function(){i(Error(`THREE.GLTFLoader: Failed to load buffer "`+t.uri+`".`))})})}loadBufferView(e){let t=this.json.bufferViews[e];return this.getDependency(`buffer`,t.buffer).then(function(e){let n=t.byteLength||0,r=t.byteOffset||0;return e.slice(r,r+n)})}loadAccessor(e){let t=this,n=this.json,r=this.json.accessors[e];if(r.bufferView===void 0&&r.sparse===void 0){let e=kk[r.type],t=Ek[r.componentType],n=r.normalized===!0,i=new t(r.count*e);return Promise.resolve(new Bo(i,e,n))}let i=[];return r.bufferView===void 0?i.push(null):i.push(this.getDependency(`bufferView`,r.bufferView)),r.sparse!==void 0&&(i.push(this.getDependency(`bufferView`,r.sparse.indices.bufferView)),i.push(this.getDependency(`bufferView`,r.sparse.values.bufferView))),Promise.all(i).then(function(e){let i=e[0],a=kk[r.type],o=Ek[r.componentType],s=o.BYTES_PER_ELEMENT,c=s*a,l=r.byteOffset||0,u=r.bufferView===void 0?void 0:n.bufferViews[r.bufferView].byteStride,d=r.normalized===!0,f,p;if(u&&u!==c){let e=Math.floor(l/u),n=`InterleavedBuffer:`+r.bufferView+`:`+r.componentType+`:`+e+`:`+r.count,c=t.cache.get(n);c||(f=new o(i,e*u,r.count*u/s),c=new ns(f,u/s),t.cache.add(n,c)),p=new is(c,a,l%u/s,d)}else f=i===null?new o(r.count*a):new o(i,l,r.count*a),p=new Bo(f,a,d);if(r.sparse!==void 0){let t=kk.SCALAR,n=Ek[r.sparse.indices.componentType],s=r.sparse.indices.byteOffset||0,c=r.sparse.values.byteOffset||0,l=new n(e[1],s,r.sparse.count*t),u=new o(e[2],c,r.sparse.count*a);i!==null&&(p=new Bo(p.array.slice(),p.itemSize,p.normalized)),p.normalized=!1;for(let e=0,t=l.length;e<t;e++){let t=l[e];if(p.setX(t,u[e*a]),a>=2&&p.setY(t,u[e*a+1]),a>=3&&p.setZ(t,u[e*a+2]),a>=4&&p.setW(t,u[e*a+3]),a>=5)throw Error(`THREE.GLTFLoader: Unsupported itemSize in sparse BufferAttribute.`)}p.normalized=d}return p})}loadTexture(e){let t=this.json,n=this.options,r=t.textures[e].source,i=t.images[r],a=this.textureLoader;if(i.uri){let e=n.manager.getHandler(i.uri);e!==null&&(a=e)}return this.loadTextureImage(e,r,a)}loadTextureImage(e,t,n){let r=this,i=this.json,a=i.textures[e],o=i.images[t],s=(o.uri||o.bufferView)+`:`+a.sampler;if(this.textureCache[s])return this.textureCache[s];let c=this.loadImageSource(t,n).then(function(t){t.flipY=!1,t.name=a.name||o.name||``,t.name===``&&typeof o.uri==`string`&&o.uri.startsWith(`data:image/`)===!1&&(t.name=o.uri);let n=(i.samplers||{})[a.sampler]||{};return t.magFilter=Dk[n.magFilter]||1006,t.minFilter=Dk[n.minFilter]||1008,t.wrapS=Ok[n.wrapS]||1e3,t.wrapT=Ok[n.wrapT]||1e3,t.generateMipmaps=!t.isCompressedTexture&&t.minFilter!==1003&&t.minFilter!==1006,r.associations.set(t,{textures:e}),t}).catch(function(){return null});return this.textureCache[s]=c,c}loadImageSource(e,t){let n=this,r=this.json,i=this.options;if(this.sourceCache[e]!==void 0)return this.sourceCache[e].then(e=>e.clone());let a=r.images[e],o=self.URL||self.webkitURL,s=a.uri||``,c=!1;if(a.bufferView!==void 0)s=n.getDependency(`bufferView`,a.bufferView).then(function(e){c=!0;let t=new Blob([e],{type:a.mimeType});return s=o.createObjectURL(t),s});else if(a.uri===void 0)throw Error(`THREE.GLTFLoader: Image `+e+` is missing URI and bufferView`);let l=Promise.resolve(s).then(function(e){return new Promise(function(n,r){let a=n;t.isImageBitmapLoader===!0&&(a=function(e){let t=new ma(e);t.needsUpdate=!0,n(t)}),t.load(kd.resolveURL(e,i.path),a,void 0,r)})}).then(function(e){return c===!0&&o.revokeObjectURL(s),Ik(e,a),e.userData.mimeType=a.mimeType||Hk(a.uri),e}).catch(function(e){throw console.error(`THREE.GLTFLoader: Couldn't load texture`,s),e});return this.sourceCache[e]=l,l}assignTexture(e,t,n,r){let i=this;return this.getDependency(`texture`,n.index).then(function(a){if(!a)return null;if(n.texCoord!==void 0&&n.texCoord>0&&(a=a.clone(),a.channel=n.texCoord),i.extensions[XO.KHR_TEXTURE_TRANSFORM]){let e=n.extensions===void 0?void 0:n.extensions[XO.KHR_TEXTURE_TRANSFORM];if(e){let t=i.associations.get(a);a=i.extensions[XO.KHR_TEXTURE_TRANSFORM].extendTexture(a,e),i.associations.set(a,t)}}return r!==void 0&&(a.colorSpace=r),e[t]=a,a})}assignFinalMaterial(e){let t=e.geometry,n=e.material,r=t.attributes.tangent===void 0,i=t.attributes.color!==void 0,a=t.attributes.normal===void 0;if(e.isPoints){let e=`PointsMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new Rc,os.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,t.sizeAttenuation=!1,this.cache.add(e,t)),n=t}else if(e.isLine){let e=`LineBasicMaterial:`+n.uuid,t=this.cache.get(e);t||(t=new wc,os.prototype.copy.call(t,n),t.color.copy(n.color),t.map=n.map,this.cache.add(e,t)),n=t}if(r||i||a){let e=`ClonedMaterial:`+n.uuid+`:`;r&&(e+=`derivative-tangents:`),i&&(e+=`vertex-colors:`),a&&(e+=`flat-shading:`);let t=this.cache.get(e);t||(t=n.clone(),i&&(t.vertexColors=!0),a&&(t.flatShading=!0),r&&(t.normalScale&&(t.normalScale.y*=-1),t.clearcoatNormalScale&&(t.clearcoatNormalScale.y*=-1)),this.cache.add(e,t),this.associations.set(t,this.associations.get(n))),n=t}e.material=n}getMaterialType(){return Du}loadMaterial(e){let t=this,n=this.json,r=this.extensions,i=n.materials[e],a,o={},s=i.extensions||{},c=[];if(s[XO.KHR_MATERIALS_UNLIT]){let e=r[XO.KHR_MATERIALS_UNLIT];a=e.getMaterialType(),c.push(e.extendParams(o,i,t))}else{let n=i.pbrMetallicRoughness||{};if(o.color=new X(1,1,1),o.opacity=1,Array.isArray(n.baseColorFactor)){let e=n.baseColorFactor;o.color.setRGB(e[0],e[1],e[2],ii),o.opacity=e[3]}n.baseColorTexture!==void 0&&c.push(t.assignTexture(o,`map`,n.baseColorTexture,ri)),o.metalness=n.metallicFactor===void 0?1:n.metallicFactor,o.roughness=n.roughnessFactor===void 0?1:n.roughnessFactor,n.metallicRoughnessTexture!==void 0&&(c.push(t.assignTexture(o,`metalnessMap`,n.metallicRoughnessTexture)),c.push(t.assignTexture(o,`roughnessMap`,n.metallicRoughnessTexture))),a=this._invokeOne(function(t){return t.getMaterialType&&t.getMaterialType(e)}),c.push(Promise.all(this._invokeAll(function(t){return t.extendMaterialParams&&t.extendMaterialParams(e,o)})))}i.doubleSided===!0&&(o.side=2);let l=i.alphaMode||Nk.OPAQUE;if(l===Nk.BLEND?(o.transparent=!0,o.depthWrite=!1):(o.transparent=!1,l===Nk.MASK&&(o.alphaTest=i.alphaCutoff===void 0?.5:i.alphaCutoff)),i.normalTexture!==void 0&&a!==js&&(c.push(t.assignTexture(o,`normalMap`,i.normalTexture)),o.normalScale=new q(1,1),i.normalTexture.scale!==void 0)){let e=i.normalTexture.scale;o.normalScale.set(e,e)}if(i.occlusionTexture!==void 0&&a!==js&&(c.push(t.assignTexture(o,`aoMap`,i.occlusionTexture)),i.occlusionTexture.strength!==void 0&&(o.aoMapIntensity=i.occlusionTexture.strength)),i.emissiveFactor!==void 0&&a!==js){let e=i.emissiveFactor;o.emissive=new X().setRGB(e[0],e[1],e[2],ii)}return i.emissiveTexture!==void 0&&a!==js&&c.push(t.assignTexture(o,`emissiveMap`,i.emissiveTexture,ri)),Promise.all(c).then(function(){let n=new a(o);return i.name&&(n.name=i.name),Ik(n,i),t.associations.set(n,{materials:e}),i.extensions&&Fk(r,n,i),n})}createUniqueName(e){let t=Yd.sanitizeNodeName(e||``);return t in this.nodeNamesUsed?t+`_`+ ++this.nodeNamesUsed[t]:(this.nodeNamesUsed[t]=0,t)}loadGeometries(e){let t=this,n=this.extensions,r=this.primitiveCache;function i(e){return n[XO.KHR_DRACO_MESH_COMPRESSION].decodePrimitive(e,t).then(function(n){return Kk(n,e,t)})}let a=[];for(let n=0,o=e.length;n<o;n++){let o=e[n],s=zk(o),c=r[s];if(c)a.push(c.promise);else{let e;e=o.extensions&&o.extensions[XO.KHR_DRACO_MESH_COMPRESSION]?i(o):Kk(new ts,o,t),r[s]={primitive:o,promise:e},a.push(e)}}return Promise.all(a)}loadMesh(e){let t=this,n=this.json,r=this.extensions,i=n.meshes[e],a=i.primitives,o=[];for(let e=0,t=a.length;e<t;e++){let t=a[e].material===void 0?Pk(this.cache):this.getDependency(`material`,a[e].material);o.push(t)}return o.push(t.loadGeometries(a)),Promise.all(o).then(function(n){let o=n.slice(0,n.length-1),s=n[n.length-1],c=[];for(let n=0,l=s.length;n<l;n++){let l=s[n],u=a[n],d,f=o[n];if(u.mode===Tk.TRIANGLES||u.mode===Tk.TRIANGLE_STRIP||u.mode===Tk.TRIANGLE_FAN||u.mode===void 0)d=i.isSkinnedMesh===!0?new tc(l,f):new Us(l,f),d.isSkinnedMesh===!0&&d.normalizeSkinWeights(),u.mode===Tk.TRIANGLE_STRIP?d.geometry=WO(d.geometry,1):u.mode===Tk.TRIANGLE_FAN&&(d.geometry=WO(d.geometry,2));else if(u.mode===Tk.LINES)d=new Ic(l,f);else if(u.mode===Tk.LINE_STRIP)d=new Mc(l,f);else if(u.mode===Tk.LINE_LOOP)d=new Lc(l,f);else if(u.mode===Tk.POINTS)d=new Uc(l,f);else throw Error(`THREE.GLTFLoader: Primitive mode unsupported: `+u.mode);Object.keys(d.geometry.morphAttributes).length>0&&Rk(d,i),d.name=t.createUniqueName(i.name||`mesh_`+e),Ik(d,i),u.extensions&&Fk(r,d,u),t.assignFinalMaterial(d),c.push(d)}for(let n=0,r=c.length;n<r;n++)t.associations.set(c[n],{meshes:e,primitives:n});if(c.length===1)return i.extensions&&Fk(r,c[0],i),c[0];let l=new qa;i.extensions&&Fk(r,l,i),t.associations.set(l,{meshes:e});for(let e=0,t=c.length;e<t;e++)l.add(c[e]);return l})}loadCamera(e){let t,n=this.json.cameras[e],r=n[n.type];if(!r){console.warn(`THREE.GLTFLoader: Missing camera parameters.`);return}return n.type===`perspective`?t=new bd(Yi.radToDeg(r.yfov),r.aspectRatio||1,r.znear||1,r.zfar||2e6):n.type===`orthographic`&&(t=new Td(-r.xmag,r.xmag,r.ymag,-r.ymag,r.znear,r.zfar)),n.name&&(t.name=this.createUniqueName(n.name)),Ik(t,n),Promise.resolve(t)}loadSkin(e){let t=this.json.skins[e],n=[];for(let e=0,r=t.joints.length;e<r;e++)n.push(this._loadNodeShallow(t.joints[e]));return t.inverseBindMatrices===void 0?n.push(null):n.push(this.getDependency(`accessor`,t.inverseBindMatrices)),Promise.all(n).then(function(e){let n=e.pop(),r=e,i=[],a=[];for(let e=0,o=r.length;e<o;e++){let o=r[e];if(o){i.push(o);let t=new Y;n!==null&&t.fromArray(n.array,e*16),a.push(t)}else console.warn(`THREE.GLTFLoader: Joint "%s" could not be found.`,t.joints[e])}return new oc(i,a)})}loadAnimation(e){let t=this.json,n=this,r=t.animations[e],i=r.name?r.name:`animation_`+e,a=[],o=[],s=[],c=[],l=[];for(let e=0,t=r.channels.length;e<t;e++){let t=r.channels[e],n=r.samplers[t.sampler],i=t.target,u=i.node,d=r.parameters===void 0?n.input:r.parameters[n.input],f=r.parameters===void 0?n.output:r.parameters[n.output];i.node!==void 0&&(a.push(this.getDependency(`node`,u)),o.push(this.getDependency(`accessor`,d)),s.push(this.getDependency(`accessor`,f)),c.push(n),l.push(i))}return Promise.all([Promise.all(a),Promise.all(o),Promise.all(s),Promise.all(c),Promise.all(l)]).then(function(e){let t=e[0],a=e[1],o=e[2],s=e[3],c=e[4],l=[];for(let e=0,r=t.length;e<r;e++){let r=t[e],i=a[e],u=o[e],d=s[e],f=c[e];if(r===void 0)continue;r.updateMatrix&&r.updateMatrix();let p=n._createAnimationTracks(r,i,u,d,f);if(p)for(let e=0;e<p.length;e++)l.push(p[e])}let u=new Yu(i,void 0,l);return Ik(u,r),u})}createNodeMesh(e){let t=this.json,n=this,r=t.nodes[e];return r.mesh===void 0?null:n.getDependency(`mesh`,r.mesh).then(function(e){let t=n._getNodeRef(n.meshCache,r.mesh,e);return r.weights!==void 0&&t.traverse(function(e){if(e.isMesh)for(let t=0,n=r.weights.length;t<n;t++)e.morphTargetInfluences[t]=r.weights[t]}),t})}loadNode(e){let t=this.json,n=this,r=t.nodes[e],i=n._loadNodeShallow(e),a=[],o=r.children||[];for(let e=0,t=o.length;e<t;e++)a.push(n.getDependency(`node`,o[e]));let s=r.skin===void 0?Promise.resolve(null):n.getDependency(`skin`,r.skin);return Promise.all([i,Promise.all(a),s]).then(function(e){let t=e[0],n=e[1],r=e[2];r!==null&&t.traverse(function(e){e.isSkinnedMesh&&e.bind(r,Uk)});for(let e=0,r=n.length;e<r;e++)t.add(n[e]);if(t.userData.pivot!==void 0&&n.length>0){let e=t.userData.pivot,r=n[0];t.pivot=new J().fromArray(e),t.position.x-=e[0],t.position.y-=e[1],t.position.z-=e[2],r.position.set(0,0,0),delete t.userData.pivot}return t})}_loadNodeShallow(e){let t=this.json,n=this.extensions,r=this;if(this.nodeCache[e]!==void 0)return this.nodeCache[e];let i=t.nodes[e],a=i.name?r.createUniqueName(i.name):``,o=[],s=r._invokeOne(function(t){return t.createNodeMesh&&t.createNodeMesh(e)});return s&&o.push(s),i.camera!==void 0&&o.push(r.getDependency(`camera`,i.camera).then(function(e){return r._getNodeRef(r.cameraCache,i.camera,e)})),r._invokeAll(function(t){return t.createNodeAttachment&&t.createNodeAttachment(e)}).forEach(function(e){o.push(e)}),this.nodeCache[e]=Promise.all(o).then(function(t){let o;if(o=i.isBone===!0?new nc:t.length>1?new qa:t.length===1?t[0]:new Ka,o!==t[0])for(let e=0,n=t.length;e<n;e++)o.add(t[e]);if(i.name&&(o.userData.name=i.name,o.name=a),Ik(o,i),i.extensions&&Fk(n,o,i),i.matrix!==void 0){let e=new Y;e.fromArray(i.matrix),o.applyMatrix4(e)}else i.translation!==void 0&&o.position.fromArray(i.translation),i.rotation!==void 0&&o.quaternion.fromArray(i.rotation),i.scale!==void 0&&o.scale.fromArray(i.scale);if(!r.associations.has(o))r.associations.set(o,{});else if(i.mesh!==void 0&&r.meshCache.refs[i.mesh]>1){let e=r.associations.get(o);r.associations.set(o,{...e})}return r.associations.get(o).nodes=e,o}),this.nodeCache[e]}loadScene(e){let t=this.extensions,n=this.json.scenes[e],r=this,i=new qa;n.name&&(i.name=r.createUniqueName(n.name)),Ik(i,n),n.extensions&&Fk(t,i,n);let a=n.nodes||[],o=[];for(let e=0,t=a.length;e<t;e++)o.push(r.getDependency(`node`,a[e]));return Promise.all(o).then(function(e){for(let t=0,n=e.length;t<n;t++){let n=e[t];n.parent===null?i.add(n):i.add(GO(n))}return r.associations=(e=>{let t=new Map;for(let[e,n]of r.associations)(e instanceof os||e instanceof ma)&&t.set(e,n);return e.traverse(e=>{let n=r.associations.get(e);n!=null&&t.set(e,n)}),t})(i),i})}_createAnimationTracks(e,t,n,r,i){let a=[],o=e.name?e.name:e.uuid,s=[];jk[i.path]===jk.weights?e.traverse(function(e){e.morphTargetInfluences&&s.push(e.name?e.name:e.uuid)}):s.push(o);let c;switch(jk[i.path]){case jk.weights:c=Wu;break;case jk.rotation:c=Ku;break;case jk.translation:case jk.scale:c=Ju;break;default:switch(n.itemSize){case 1:c=Wu;break;default:c=Ju;break}break}let l=r.interpolation===void 0?Yr:Mk[r.interpolation],u=this._getArrayFromAccessor(n);for(let e=0,n=s.length;e<n;e++){let n=new c(s[e]+`.`+jk[i.path],t.array,u,l);r.interpolation===`CUBICSPLINE`&&this._createCubicSplineTrackInterpolant(n),a.push(n)}return a}_getArrayFromAccessor(e){let t=e.array;if(e.normalized){let e=Vk(t.constructor),n=new Float32Array(t.length);for(let r=0,i=t.length;r<i;r++)n[r]=t[r]*e;t=n}return t}_createCubicSplineTrackInterpolant(e){e.createInterpolant=function(e){return new(this instanceof Ku?wk:Sk)(this.times,this.values,this.getValueSize()/3,e)},e.createInterpolant.isInterpolantFactoryMethodGLTFCubicSpline=!0}};function Gk(e,t,n){let r=t.attributes,i=new _o;if(r.POSITION!==void 0){let e=n.json.accessors[r.POSITION],t=e.min,a=e.max;if(t!==void 0&&a!==void 0){if(i.set(new J(t[0],t[1],t[2]),new J(a[0],a[1],a[2])),e.normalized){let t=Vk(Ek[e.componentType]);i.min.multiplyScalar(t),i.max.multiplyScalar(t)}}else{console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`);return}}else return;let a=t.targets;if(a!==void 0){let e=new J,t=new J;for(let r=0,i=a.length;r<i;r++){let i=a[r];if(i.POSITION!==void 0){let r=n.json.accessors[i.POSITION],a=r.min,o=r.max;if(a!==void 0&&o!==void 0){if(t.setX(Math.max(Math.abs(a[0]),Math.abs(o[0]))),t.setY(Math.max(Math.abs(a[1]),Math.abs(o[1]))),t.setZ(Math.max(Math.abs(a[2]),Math.abs(o[2]))),r.normalized){let e=Vk(Ek[r.componentType]);t.multiplyScalar(e)}e.max(t)}else console.warn(`THREE.GLTFLoader: Missing min/max properties for accessor POSITION.`)}}i.expandByVector(e)}e.boundingBox=i;let o=new qo;i.getCenter(o.center),o.radius=i.min.distanceTo(i.max)/2,e.boundingSphere=o}function Kk(e,t,n){let r=t.attributes,i=[];function a(t,r){return n.getDependency(`accessor`,t).then(function(t){e.setAttribute(r,t)})}for(let t in r){let n=Ak[t]||t.toLowerCase();n in e.attributes||i.push(a(r[t],n))}if(t.indices!==void 0&&!e.index){let r=n.getDependency(`accessor`,t.indices).then(function(t){e.setIndex(t)});i.push(r)}return ia.workingColorSpace!==`srgb-linear`&&`COLOR_0`in r&&console.warn(`THREE.GLTFLoader: Converting vertex colors from "srgb-linear" to "${ia.workingColorSpace}" not supported.`),Ik(e,t),Gk(e,t,n),Promise.all(i).then(function(){return t.targets===void 0?e:Lk(e,t.targets,n)})}var qk=(function(){var e=`b9H79Tebbbe8Fv9Gbb9Gvuuuuueu9Giuuub9Geueu9Giuuueuixkbeeeddddillviebeoweuec:W:Odkr;Neqo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbeY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVbdE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbiL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtblK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949WboY9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVJ9V29VVbrl79IV9Rbwq;lZkdbk;jYi5ud9:du8Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnalTmbcuhoaiRbbgrc;WeGc:Ge9hmbarcsGgwce0mbc9:hoalcufadcd4cbawEgDadfgrcKcaawEgqaraq0Egk6mbaicefhxcj;abad9Uc;WFbGcjdadca0EhmaialfgPar9Rgoadfhsavaoadz:jjjjbgzceVhHcbhOdndninaeaO9nmeaPax9RaD6mdamaeaO9RaOamfgoae6EgAcsfglc9WGhCabaOad2fhXaAcethQaxaDfhiaOaeaoaeao6E9RhLalcl4cifcd4hKazcj;cbfaAfhYcbh8AazcjdfhEaHh3incbhodnawTmbaxa8Acd4fRbbhokaocFeGh5cbh8Eazcj;cbfhqinaih8Fdndndndna5a8Ecet4ciGgoc9:fPdebdkaPa8F9RaA6mrazcj;cbfa8EaA2fa8FaAz:jjjjb8Aa8FaAfhixdkazcj;cbfa8EaA2fcbaAz:kjjjb8Aa8FhixekaPa8F9RaK6mva8FaKfhidnaCTmbaPai9RcK6mbaocdtc:q1jjbfcj1jjbawEhaczhrcbhlinargoc9Wfghaqfhrdndndndndndnaaa8Fahco4fRbbalcoG4ciGcdtfydbPDbedvivvvlvkar9cb83bbarcwf9cb83bbxlkarcbaiRbdai8Xbb9c:c:qj:bw9:9c:q;c1:I1e:d9c:b:c:e1z9:gg9cjjjjjz:dg8J9qE86bbaqaofgrcGfag9c8F1:NghcKtc8F91aicdfa8J9c8N1:Nfg8KRbbG86bbarcVfcba8KahcjeGcr4fghRbbag9cjjjjjl:dg8J9qE86bbarc7fcbaha8J9c8L1:NfghRbbag9cjjjjjd:dg8J9qE86bbarctfcbaha8J9c8K1:NfghRbbag9cjjjjje:dg8J9qE86bbarc91fcbaha8J9c8J1:NfghRbbag9cjjjj;ab:dg8J9qE86bbarc4fcbaha8J9cg1:NfghRbbag9cjjjja:dg8J9qE86bbarc93fcbaha8J9ch1:NfghRbbag9cjjjjz:dgg9qE86bbarc94fcbahag9ca1:NfghRbbai8Xbe9c:c:qj:bw9:9c:q;c1:I1e:d9c:b:c:e1z9:gg9cjjjjjz:dg8J9qE86bbarc95fag9c8F1:NgicKtc8F91aha8J9c8N1:NfghRbbG86bbarc96fcbahaicjeGcr4fgiRbbag9cjjjjjl:dg8J9qE86bbarc97fcbaia8J9c8L1:NfgiRbbag9cjjjjjd:dg8J9qE86bbarc98fcbaia8J9c8K1:NfgiRbbag9cjjjjje:dg8J9qE86bbarc99fcbaia8J9c8J1:NfgiRbbag9cjjjj;ab:dg8J9qE86bbarc9:fcbaia8J9cg1:NfgiRbbag9cjjjja:dg8J9qE86bbarcufcbaia8J9ch1:NfgiRbbag9cjjjjz:dgg9qE86bbaiag9ca1:NfhixikaraiRblaiRbbghco4g8Ka8KciSg8KE86bbaqaofgrcGfaiclfa8Kfg8KRbbahcl4ciGg8La8LciSg8LE86bbarcVfa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc7fa8Ka8Lfg8KRbbahciGghahciSghE86bbarctfa8Kahfg8KRbbaiRbeghco4g8La8LciSg8LE86bbarc91fa8Ka8Lfg8KRbbahcl4ciGg8La8LciSg8LE86bbarc4fa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc93fa8Ka8Lfg8KRbbahciGghahciSghE86bbarc94fa8Kahfg8KRbbaiRbdghco4g8La8LciSg8LE86bbarc95fa8Ka8Lfg8KRbbahcl4ciGg8La8LciSg8LE86bbarc96fa8Ka8Lfg8KRbbahcd4ciGg8La8LciSg8LE86bbarc97fa8Ka8Lfg8KRbbahciGghahciSghE86bbarc98fa8KahfghRbbaiRbigico4g8Ka8KciSg8KE86bbarc99faha8KfghRbbaicl4ciGg8Ka8KciSg8KE86bbarc9:faha8KfghRbbaicd4ciGg8Ka8KciSg8KE86bbarcufaha8KfgrRbbaiciGgiaiciSgiE86bbaraifhixdkaraiRbwaiRbbghcl4g8Ka8KcsSg8KE86bbaqaofgrcGfaicwfa8Kfg8KRbbahcsGghahcsSghE86bbarcVfa8KahfghRbbaiRbeg8Kcl4g8La8LcsSg8LE86bbarc7faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarctfaha8KfghRbbaiRbdg8Kcl4g8La8LcsSg8LE86bbarc91faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc4faha8KfghRbbaiRbig8Kcl4g8La8LcsSg8LE86bbarc93faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc94faha8KfghRbbaiRblg8Kcl4g8La8LcsSg8LE86bbarc95faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc96faha8KfghRbbaiRbvg8Kcl4g8La8LcsSg8LE86bbarc97faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc98faha8KfghRbbaiRbog8Kcl4g8La8LcsSg8LE86bbarc99faha8LfghRbba8KcsGg8Ka8KcsSg8KE86bbarc9:faha8KfghRbbaiRbrgicl4g8Ka8KcsSg8KE86bbarcufaha8KfgrRbbaicsGgiaicsSgiE86bbaraifhixekarai8Pbb83bbarcwfaicwf8Pbb83bbaiczfhikdnaoaC9pmbalcdfhlaoczfhraPai9RcL0mekkaoaC6moaimexokaCmva8FTmvkaqaAfhqa8Ecefg8Ecl9hmbkdndndndnawTmbasa8Acd4fRbbgociGPlbedrbkaATmdaza8Afh8Fazcj;cbfhhcbh8EaEhaina8FRbbhraahocbhlinaoahalfRbbgqce4cbaqceG9R7arfgr86bbaoadfhoaAalcefgl9hmbkaacefhaa8Fcefh8FahaAfhha8Ecefg8Ecl9hmbxikkaATmeaza8Afhaazcj;cbfhhcbhoceh8EaYh8FinaEaofhlaa8Vbbhrcbhoinala8FaofRbbcwtahaofRbbgqVc;:FiGce4cbaqceG9R7arfgr87bbaladfhlaLaocefgofmbka8FaQfh8FcdhoaacdfhaahaQfhha8EceGhlcbh8EalmbxdkkaATmbcbaocl49Rh8Eaza8AfRbbhqcwhoa3hlinalRbbaotaqVhqalcefhlaocwfgoca9hmbkcbhhaEh8FaYhainazcj;cbfahfRbbhrcwhoaahlinalRbbaotarVhralaAfhlaocwfgoca9hmbkara8E93aq7hqcbhoa8Fhlinalaqao486bbalcefhlaocwfgoca9hmbka8Fadfh8FaacefhaahcefghaA9hmbkkaEclfhEa3clfh3a8Aclfg8Aad6mbkaXazcjdfaAad2z:jjjjb8AazazcjdfaAcufad2fadz:jjjjb8AaAaOfhOaihxaimbkc9:hoxdkcbc99aPax9RakSEhoxekc9:hokavcj;kbf8Kjjjjbaok:XseHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecjez:kjjjb8AavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhldnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhoindnalaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfaoaDcu7gPcl4fcsGcitfgsydlhzasydbhHdndnaDcsGgsak9pmbavaiaPfcsGcdtfydbaxasEhDaxasTgOfhxxekdndnascsSmbcehOasc987asamffcefhDxekalcefhDal8SbbgscFeGhPdndnascu9mmbaDhlxekalcvfhlaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhlkcehOaPce4cbaPceG9R7amfhDkaDhmkavc;abfaocitfgsaDBdbasazBdlavaicdtfaDBdbavc;abfaocefcsGcitfgsaHBdbasaDBdlaocdfhoaOaifhidnadcd9hmbabarcetfgsaH87ebasclfaD87ebascdfaz87ebxdkabarcdtfgsaHBdbascwfaDBdbasclfazBdbxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHclfas87ebaHcdfaD87ebxekabarcdtfgHaxBdbaHcwfasBdbaHclfaDBdbkavaicdtfaxBdbavc;abfaocitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfaocefcsGcitfgHasBdbaHaDBdlavaiaPfgicsGcdtfasBdbavc;abfaocdfcsGcitfgDaxBdbaDasBdlaocifhoaiaOfhiazaOfhxxekaxcbalRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbalcefhDxekalcdfhDal8SbegPcFeGhsdnaPcu9kmbalcofhAascFbGhscrhldninaD8SbbgPcFbGaltasVhsaPcu9kmeaDcefhDalcrfglc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbglcFeGhPdnalcu9kmbaDcvfhzaPcFbGhPcrhldninas8SbbgDcFbGaltaPVhPaDcu9kmeascefhsalcrfglc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashlxekascefhlas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninal8SbbgscFbGaDtaPVhPascu9kmealcefhlaDcrfgDc8J9hmbkaOhlxekalcefhlkaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDclfaO87ebaDcdfaz87ebxekabarcdtfgDaABdbaDcwfaOBdbaDclfazBdbkavc;abfaocitfgDazBdbaDaABdlavaicdtfaABdbavc;abfaocefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfaocdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhiaocifhokawcefhwaocsGhoaicsGhiarcifgrae6mbkkcbc99alaqSEhokavc;aef8Kjjjjbaok:clevu8Jjjjjbcz9Rhvdnaecvfal9nmbc9:skdnaiRbbc;:eGc;qeSmbcuskav9cb83iwaicefhoaialfc98fhrdnaeTmbdnadcdSmbcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcdtfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgiBdbalaiBdbawcefgwae9hmbxdkkcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcetfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgi87ebalaiBdbawcefgwae9hmbkkcbc99aoarSEk:Lvoeue99dud99eud99dndnadcl9hmbaeTmeindndnabcdfgd8Sbb:Yab8Sbbgi:Ygl:l:tabcefgv8Sbbgo:Ygr:l:tgwJbb;:9cawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai86bbdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad86bbdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad86bbabclfhbaecufgembxdkkaeTmbindndnabclfgd8Ueb:Yab8Uebgi:Ygl:l:tabcdfgv8Uebgo:Ygr:l:tgwJb;:FSawawNJbbbbawawJbbbb9GgDEgq:mgkaqaicb9iEalMgwawNakaqaocb9iEarMgqaqNMM:r:vglNJbbbZJbbb:;aDEMgr:lJbbb9p9DTmbar:Ohixekcjjjj94hikadai87ebdndnaqalNJbbbZJbbb:;aqJbbbb9GEMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkavad87ebdndnawalNJbbbZJbbb:;awJbbbb9GEMgw:lJbbb9p9DTmbaw:Ohdxekcjjjj94hdkabad87ebabcwfhbaecufgembkkk::ioiue99dud99dud99dnaeTmbcbhiabhlindndnal8Uebgv:YgoJ:ji:1Salcof8UebgrciVgw:Y:vgDNJbbbZJbbb:;avcu9kEMgq:lJbbb9p9DTmbaq:Ohkxekcjjjj94hkkalclf8Uebhvalcdf8UebhxabaiarcefciGfcetfak87ebdndnax:YgqaDNJbbbZJbbb:;axcu9kEMgm:lJbbb9p9DTmbam:Ohxxekcjjjj94hxkabaiarciGfgkcd7cetfax87ebdndnav:YgmaDNJbbbZJbbb:;avcu9kEMgP:lJbbb9p9DTmbaP:Ohvxekcjjjj94hvkabaiarcufciGfcetfav87ebdndnawaw2:ZgPaPMaoaoN:taqaqN:tamamN:tgoJbbbbaoJbbbb9GE:raDNJbbbZMgD:lJbbb9p9DTmbaD:Ohrxekcjjjj94hrkabakcetfar87ebalcwfhlaiclfhiaecufgembkkk9mbdnadcd4ae2gdTmbinababydbgecwtcw91:Yaece91cjjj98Gcjjj;8if::NUdbabclfhbadcufgdmbkkk:Tvirud99eudndnadcl9hmbaeTmeindndnabRbbgiabcefgl8Sbbgvabcdfgo8Sbbgrf9R:YJbbuJabcifgwRbbgdce4adVgDcd4aDVgDcl4aDVgD:Z:vgqNJbbbZMgk:lJbbb9p9DTmbak:Ohxxekcjjjj94hxkaoax86bbdndnaraif:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohoxekcjjjj94hokalao86bbdndnavaifar9R:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohixekcjjjj94hikabai86bbdndnaDadcetGadceGV:ZaqNJbbbZMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkawad86bbabclfhbaecufgembxdkkaeTmbindndnab8Vebgiabcdfgl8Uebgvabclfgo8Uebgrf9R:YJbFu9habcofgw8Vebgdce4adVgDcd4aDVgDcl4aDVgDcw4aDVgD:Z:vgqNJbbbZMgk:lJbbb9p9DTmbak:Ohxxekcjjjj94hxkaoax87ebdndnaraif:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohoxekcjjjj94hokalao87ebdndnavaifar9R:YaqNJbbbZMgk:lJbbb9p9DTmbak:Ohixekcjjjj94hikabai87ebdndnaDadcetGadceGV:ZaqNJbbbZMgq:lJbbb9p9DTmbaq:Ohdxekcjjjj94hdkawad87ebabcwfhbaecufgembkkk9teiucbcbyd:K1jjbgeabcifc98GfgbBd:K1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaik;teeeudndnaeabVciGTmbabhixekdndnadcz9pmbabhixekabhiinaiaeydbBdbaiaeydlBdlaiaeydwBdwaiaeydxBdxaeczfheaiczfhiadc9Wfgdcs0mbkkadcl6mbinaiaeydbBdbaeclfheaiclfhiadc98fgdci0mbkkdnadTmbinaiaeRbb86bbaicefhiaecefheadcufgdmbkkabk:3eedudndnabciGTmbabhixekaecFeGc:b:c:ew2hldndnadcz9pmbabhixekabhiinaialBdxaialBdwaialBdlaialBdbaiczfhiadc9Wfgdcs0mbkkadcl6mbinaialBdbaiclfhiadc98fgdci0mbkkdnadTmbinaiae86bbaicefhiadcufgdmbkkabkk81dbcjwk8Kbbbbdbbblbbbwbbbbbbbebbbdbbblbbbwbbbbc:Kwkl8WNbb`,t=`b9H79TebbbeKl9Gbb9Gvuuuuueu9Giuuub9Geueuixkbbebeeddddilve9Weeeviebeoweuec:q:6dkr;Neqo9TW9T9VV95dbH9F9F939H79T9F9J9H229F9Jt9VV7bb8A9TW79O9V9Wt9F9KW9J9V9KW9wWVtW949c919M9MWVbdY9TW79O9V9Wt9F9KW9J9V9KW69U9KW949c919M9MWVblE9TW79O9V9Wt9F9KW9J9V9KW69U9KW949tWG91W9U9JWbvL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9p9JtboK9TW79O9V9Wt9F9KW9J9V9KWS9P2tWV9r919HtbrL9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVT949WbwY9TW79O9V9Wt9F9KW9J9V9KWS9P2tWVJ9V29VVbDl79IV9Rbqq:Ctklbzik9:evu8Jjjjjbcz9Rhbcbheincbhdcbhiinabcwfadfaicjuaead4ceGglE86bbaialfhiadcefgdcw9hmbkaec:q:yjjbfai86bbaecitc:q1jjbfab8Piw83ibaecefgecjd9hmbkk:183lYud97dur978Jjjjjbcj;kb9Rgv8Kjjjjbc9:hodnalTmbcuhoaiRbbgrc;WeGc:Ge9hmbarcsGgwce0mbc9:hoalcufadcd4cbawEgDadfgrcKcaawEgqaraq0Egk6mbaicefhxavaialfgmar9Rgoad;8qbbcj;abad9Uc;WFbGcjdadca0EhPdndndnadTmbaoadfhscbhzinaeaz9nmdamax9RaD6miabazad2fhHaxaDfhOaPaeaz9RazaPfae6EgAcsfgocl4cifcd4hCavcj;cbfaoc9WGgXcetfhQavcj;cbfaXci2fhLavcj;cbfaXfhKcbhYaoc;ab6h8AincbhodnawTmbaxaYcd4fRbbhokaocFeGhEcbh3avcj;cbfh5indndndndnaEa3cet4ciGgoc9:fPdebdkamaO9RaX6mwavcj;cbfa3aX2faOaX;8qbbaOaAfhOxdkavcj;cbfa3aX2fcbaX;8kbxekamaO9RaC6moaoclVcbawEhraOaCfhocbhidna8Ambamao9Rc;Gb6mbcbhlina5alfhidndndndndndnaOalco4fRbbgqciGarfPDbedibledibkaipxbbbbbbbbbbbbbbbbpklbxlkaiaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaoclffahc:q:yjjbfRbbfhoxikaiaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaocwffahc:q:yjjbfRbbfhoxdkaiaopbbbpklbaoczfhoxekaiaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaaaocdffahc:q:yjjbfRbbfhokdndndndndndnaqcd4ciGarfPDbedibledibkaiczfpxbbbbbbbbbbbbbbbbpklbxlkaiczfaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaoclffahc:q:yjjbfRbbfhoxikaiczfaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaocwffahc:q:yjjbfRbbfhoxdkaiczfaopbbbpklbaoczfhoxekaiczfaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaaaocdffahc:q:yjjbfRbbfhokdndndndndndnaqcl4ciGarfPDbedibledibkaicafpxbbbbbbbbbbbbbbbbpklbxlkaicafaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaoclffahc:q:yjjbfRbbfhoxikaicafaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaaaocwffahc:q:yjjbfRbbfhoxdkaicafaopbbbpklbaoczfhoxekaicafaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaaaocdffahc:q:yjjbfRbbfhokdndndndndndnaqco4arfPDbedibledibkaic8Wfpxbbbbbbbbbbbbbbbbpklbxlkaic8Wfaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngicitc:q1jjbfpbibaic:q:yjjbfRbbgipsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Ngqcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaiaoclffaqc:q:yjjbfRbbfhoxikaic8Wfaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngicitc:q1jjbfpbibaic:q:yjjbfRbbgipsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Ngqcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spklbaiaocwffaqc:q:yjjbfRbbfhoxdkaic8Wfaopbbbpklbaoczfhoxekaic8WfaopbbdaoRbbgicitc:q1jjbfpbibaic:q:yjjbfRbbgipsaoRbegqcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpklbaiaocdffaqc:q:yjjbfRbbfhokalc;abfhialcjefaX0meaihlamao9Rc;Fb0mbkkdnaiaX9pmbaici4hlinamao9RcK6mwa5aifhqdndndndndndnaOaico4fRbbalcoG4ciGarfPDbedibledibkaqpxbbbbbbbbbbbbbbbbpkbbxlkaqaopbblaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLg8Ecdp:mea8EpmbzeHdOiAlCvXoQrLpxiiiiiiiiiiiiiiiip9og8Fpxiiiiiiiiiiiiiiiip8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spkbbaaaoclffahc:q:yjjbfRbbfhoxikaqaopbbwaopbbbg8Eclp:mea8EpmbzeHdOiAlCvXoQrLpxssssssssssssssssp9og8Fpxssssssssssssssssp8Jg8Ep5b9cjF;8;4;W;G;ab9:9cU1:Ngacitc:q1jjbfpbibaac:q:yjjbfRbbgapsa8Ep5e9cjF;8;4;W;G;ab9:9cU1:Nghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPa8Fa8Ep9spkbbaaaocwffahc:q:yjjbfRbbfhoxdkaqaopbbbpkbbaoczfhoxekaqaopbbdaoRbbgacitc:q1jjbfpbibaac:q:yjjbfRbbgapsaoRbeghcitc:q1jjbfpbibp9UpmbedilvorzHOACXQLpPpkbbaaaocdffahc:q:yjjbfRbbfhokalcdfhlaiczfgiaX6mbkkaohOaoTmoka5aXfh5a3cefg3cl9hmbkdndndndnawTmbasaYcd4fRbbglciGPlbedwbkaXTmdavcjdfaYfhlavaYfpbdbhgcbhoinalavcj;cbfaofpblbg8JaKaofpblbg8KpmbzeHdOiAlCvXoQrLg8LaQaofpblbg8MaLaofpblbg8NpmbzeHdOiAlCvXoQrLgypmbezHdiOAlvCXorQLg8Ecep9Ta8Epxeeeeeeeeeeeeeeeeg8Fp9op9Hp9rg8Eagp9Uggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp9Uggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp9Uggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9Abbbaladfglaga8LaypmwDKYqk8AExm35Ps8E8Fg8Ecep9Ta8Ea8Fp9op9Hp9rg8Ep9Uggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp9Uggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp9Uggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9Abbbaladfglaga8Ja8KpmwKDYq8AkEx3m5P8Es8Fg8Ja8Ma8NpmwKDYq8AkEx3m5P8Es8Fg8KpmbezHdiOAlvCXorQLg8Ecep9Ta8Ea8Fp9op9Hp9rg8Ep9Uggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp9Uggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp9Uggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9Abbbaladfglaga8Ja8KpmwDKYqk8AExm35Ps8E8Fg8Ecep9Ta8Ea8Fp9op9Hp9rg8Ep9Ug8Fp9Abbbaladfgla8Fa8Ea8Epmlvorlvorlvorlvorp9Ug8Fp9Abbbaladfgla8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9Ug8Fp9Abbbaladfgla8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9Uggp9AbbbaladfhlaoczfgoaX6mbxikkaXTmeavcjdfaYfhlavaYfpbdbhgcbhoinalavcj;cbfaofpblbg8JaKaofpblbg8KpmbzeHdOiAlCvXoQrLg8LaQaofpblbg8MaLaofpblbg8NpmbzeHdOiAlCvXoQrLgypmbezHdiOAlvCXorQLg8Ecep:nea8Epxebebebebebebebebg8Fp9op:bep9rg8Eagp:oeggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp:oeggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp:oeggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9Abbbaladfglaga8LaypmwDKYqk8AExm35Ps8E8Fg8Ecep:nea8Ea8Fp9op:bep9rg8Ep:oeggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp:oeggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp:oeggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9Abbbaladfglaga8Ja8KpmwKDYq8AkEx3m5P8Es8Fg8Ja8Ma8NpmwKDYq8AkEx3m5P8Es8Fg8KpmbezHdiOAlvCXorQLg8Ecep:nea8Ea8Fp9op:bep9rg8Ep:oeggp9Abbbaladfglaga8Ea8Epmlvorlvorlvorlvorp:oeggp9Abbbaladfglaga8Ea8EpmwDqkwDqkwDqkwDqkp:oeggp9Abbbaladfglaga8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9Abbbaladfglaga8Ja8KpmwDKYqk8AExm35Ps8E8Fg8Ecep:nea8Ea8Fp9op:bep9rg8Ep:oeg8Fp9Abbbaladfgla8Fa8Ea8Epmlvorlvorlvorlvorp:oeg8Fp9Abbbaladfgla8Fa8Ea8EpmwDqkwDqkwDqkwDqkp:oeg8Fp9Abbbaladfgla8Fa8Ea8EpmxmPsxmPsxmPsxmPsp:oeggp9AbbbaladfhlaoczfgoaX6mbxdkkaXTmbcbhocbalcl4gl9Rc8FGhiavcjdfaYfhravaYfpbdbh8Finaravcj;cbfaofpblbggaKaofpblbg8JpmbzeHdOiAlCvXoQrLg8KaQaofpblbg8LaLaofpblbg8MpmbzeHdOiAlCvXoQrLg8NpmbezHdiOAlvCXorQLg8Eaip:Rea8Ealp:Sep9qg8Ea8Fp9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9Abbbaradfgra8Fa8Ka8NpmwDKYqk8AExm35Ps8E8Fg8Eaip:Rea8Ealp:Sep9qg8Ep9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9Abbbaradfgra8Faga8JpmwKDYq8AkEx3m5P8Es8Fgga8La8MpmwKDYq8AkEx3m5P8Es8Fg8JpmbezHdiOAlvCXorQLg8Eaip:Rea8Ealp:Sep9qg8Ep9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9Abbbaradfgra8Faga8JpmwDKYqk8AExm35Ps8E8Fg8Eaip:Rea8Ealp:Sep9qg8Ep9rg8Fp9Abbbaradfgra8Fa8Ea8Epmlvorlvorlvorlvorp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmwDqkwDqkwDqkwDqkp9rg8Fp9Abbbaradfgra8Fa8Ea8EpmxmPsxmPsxmPsxmPsp9rg8Fp9AbbbaradfhraoczfgoaX6mbkkaYclfgYad6mbkaHavcjdfaAad2;8qbbavavcjdfaAcufad2fad;8qbbaAazfhzc9:hoaOhxaOmbxlkkaeTmbaDalfhrcbhocuhlinaralaD9RglfaD6mdaPaeao9RaoaPfae6Eaofgoae6mbkaial9Rhxkcbc99amax9RakSEhoxekc9:hokavcj;kbf8Kjjjjbaokwbz:bjjjbk:TseHu8Jjjjjbc;ae9Rgv8Kjjjjbc9:hodnaeci9UgrcHfal0mbcuhoaiRbbgwc;WeGc;Ge9hmbawcsGgDce0mbavc;abfcFecje;8kbavcUf9cu83ibavc8Wf9cu83ibavcyf9cu83ibavcaf9cu83ibavcKf9cu83ibavczf9cu83ibav9cu83iwav9cu83ibaialfc9WfhqaicefgwarfhldnaeTmbcmcsaDceSEhkcbhxcbhmcbhrcbhicbhoindnalaq9nmbc9:hoxikdndnawRbbgDc;Ve0mbavc;abfaoaDcu7gPcl4fcsGcitfgsydlhzasydbhHdndnaDcsGgsak9pmbavaiaPfcsGcdtfydbaxasEhDaxasTgOfhxxekdndnascsSmbcehOasc987asamffcefhDxekalcefhDal8SbbgscFeGhPdndnascu9mmbaDhlxekalcvfhlaPcFbGhPcrhsdninaD8SbbgOcFbGastaPVhPaOcu9kmeaDcefhDascrfgsc8J9hmbxdkkaDcefhlkcehOaPce4cbaPceG9R7amfhDkaDhmkavc;abfaocitfgsaDBdbasazBdlavaicdtfaDBdbavc;abfaocefcsGcitfgsaHBdbasaDBdlaocdfhoaOaifhidnadcd9hmbabarcetfgsaH87ebasclfaD87ebascdfaz87ebxdkabarcdtfgsaHBdbascwfaDBdbasclfazBdbxekdnaDcpe0mbaxcefgOavaiaqaDcsGfRbbgscl49RcsGcdtfydbascz6gPEhDavaias9RcsGcdtfydbaOaPfgzascsGgOEhsaOThOdndnadcd9hmbabarcetfgHax87ebaHclfas87ebaHcdfaD87ebxekabarcdtfgHaxBdbaHcwfasBdbaHclfaDBdbkavaicdtfaxBdbavc;abfaocitfgHaDBdbaHaxBdlavaicefgicsGcdtfaDBdbavc;abfaocefcsGcitfgHasBdbaHaDBdlavaiaPfgicsGcdtfasBdbavc;abfaocdfcsGcitfgDaxBdbaDasBdlaocifhoaiaOfhiazaOfhxxekaxcbalRbbgHEgAaDc;:eSgDfhzaHcsGhCaHcl4hXdndnaHcs0mbazcefhOxekazhOavaiaX9RcsGcdtfydbhzkdndnaCmbaOcefhxxekaOhxavaiaH9RcsGcdtfydbhOkdndnaDTmbalcefhDxekalcdfhDal8SbegPcFeGhsdnaPcu9kmbalcofhAascFbGhscrhldninaD8SbbgPcFbGaltasVhsaPcu9kmeaDcefhDalcrfglc8J9hmbkaAhDxekaDcefhDkasce4cbasceG9R7amfgmhAkdndnaXcsSmbaDhsxekaDcefhsaD8SbbglcFeGhPdnalcu9kmbaDcvfhzaPcFbGhPcrhldninas8SbbgDcFbGaltaPVhPaDcu9kmeascefhsalcrfglc8J9hmbkazhsxekascefhskaPce4cbaPceG9R7amfgmhzkdndnaCcsSmbashlxekascefhlas8SbbgDcFeGhPdnaDcu9kmbascvfhOaPcFbGhPcrhDdninal8SbbgscFbGaDtaPVhPascu9kmealcefhlaDcrfgDc8J9hmbkaOhlxekalcefhlkaPce4cbaPceG9R7amfgmhOkdndnadcd9hmbabarcetfgDaA87ebaDclfaO87ebaDcdfaz87ebxekabarcdtfgDaABdbaDcwfaOBdbaDclfazBdbkavc;abfaocitfgDazBdbaDaABdlavaicdtfaABdbavc;abfaocefcsGcitfgDaOBdbaDazBdlavaicefgicsGcdtfazBdbavc;abfaocdfcsGcitfgDaABdbaDaOBdlavaiaHcz6aXcsSVfgicsGcdtfaOBdbaiaCTaCcsSVfhiaocifhokawcefhwaocsGhoaicsGhiarcifgrae6mbkkcbc99alaqSEhokavc;aef8Kjjjjbaok:clevu8Jjjjjbcz9Rhvdnaecvfal9nmbc9:skdnaiRbbc;:eGc;qeSmbcuskav9cb83iwaicefhoaialfc98fhrdnaeTmbdnadcdSmbcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcdtfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgiBdbalaiBdbawcefgwae9hmbxdkkcbhwindnaoar6mbc9:skaocefhlao8SbbgicFeGhddndnaicu9mmbalhoxekaocvfhoadcFbGhdcrhidninal8SbbgDcFbGaitadVhdaDcu9kmealcefhlaicrfgic8J9hmbxdkkalcefhokabawcetfadc8Etc8F91adcd47avcwfadceGcdtVglydbfgi87ebalaiBdbawcefgwae9hmbkkcbc99aoarSEk:2Pliur97eue978Jjjjjbc8W9Rhiaec98Ghldndnadcl9hmbdnalTmbcbhvabhdinadadpbbbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDpxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpkbbadczfhdavclfgval6mbkkalaeSmeaipxbbbbbbbbbbbbbbbbgqpklbaiabalcdtfgdaeciGglcdtgv;8qbbdnalTmbaiaipblbgocKp:RecKp:Sep;6egraocwp:RecKp:Sep;6earp;Geaoczp:RecKp:Sep;6egwp;Gep;Kep;LegDaqp:2egqarpxbbbjbbbjbbbjbbbjgkp9op9rp;Kegrpxbb;:9cbb;:9cbb;:9cbb;:9cararp;MeaDaDp;Meawaqawakp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFbbbFbbbFbbbFbbbp9oaopxbbbFbbbFbbbFbbbFp9op9qarawp;Meaqp;Kecwp:RepxbFbbbFbbbFbbbFbbp9op9qaDawp;Meaqp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qpklbkadaiav;8qbbskaipxFubbFubbFubbFubbgxpklbdnalTmbcbhvabhdinadczfgmampbbbgopxbbbbbbFFbbbbbbFFgkp9oadpbbbgDaopmbediwDqkzHOAKY8AEgwczp:Reczp:Sep;6egraipblbaDaopmlvorxmPsCXQL358E8Fp9op;6eawczp:Sep;6egwp;Gearp;Gep;Kep;Legopxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgPp9op9rp;Kegrpxb;:FSb;:FSb;:FSb;:FSararp;Meaoaop;MeawaqawaPp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFFbbFFbbFFbbFFbbp9oaoawp;Meaqp;Keczp:Rep9qgoarawp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogrpmwDKYqk8AExm35Ps8E8Fp9qpkbbadaDakp9oaoarpmbezHdiOAlvCXorQLp9qpkbbadcafhdavclfgval6mbkkalaeSmbaiczfpxbbbbbbbbbbbbbbbbgopklbaiaopklbaiabalcitfgdaeciGglcitgv;8qbbaiaxpkladnalTmbaiaipblzgopxbbbbbbFFbbbbbbFFgkp9oaipblbgDaopmbediwDqkzHOAKY8AEgwczp:Reczp:Sep;6egraipblaaDaopmlvorxmPsCXQL358E8Fp9op;6eawczp:Sep;6egwp;Gearp;Gep;Kep;Legopxbbbbbbbbbbbbbbbbp:2egqarpxbbbjbbbjbbbjbbbjgPp9op9rp;Kegrpxb;:FSb;:FSb;:FSb;:FSararp;Meaoaop;MeawaqawaPp9op9rp;Kegrarp;Mep;Kep;Kep;Jep;Negwp;Mepxbbn0bbn0bbn0bbn0gqp;KepxFFbbFFbbFFbbFFbbp9oaoawp;Meaqp;Keczp:Rep9qgoarawp;Meaqp;KepxFFbbFFbbFFbbFFbbp9ogrpmwDKYqk8AExm35Ps8E8Fp9qpklzaiaDakp9oaoarpmbezHdiOAlvCXorQLp9qpklbkadaiav;8qbbkk:Iwllue97euo978Jjjjjbca9Rhidnaec98GglTmbcbhvabhoinaocKfpx:ji:1S:ji:1S:ji:1S:ji:1SaopbbbgraoczfgwpbbbgDpmlvorxmPsCXQL358E8Fgqczp:Segkpxibbbibbbibbbibbbp9qgxp;6ep;Negmaxaxp:1ep;7egxaxp;KearaDpmbediwDqkzHOAKY8AEgxczp:Reczp:Sep;6egrarp;Meaxczp:Sep;6egDaDp;Meaqczp:Reczp:Sep;6egqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jep;Mepxbbn0bbn0bbn0bbn0gxp;KepxFFbbFFbbFFbbFFbbgPp9oamaDp;Meaxp;Keczp:Rep9qgDamarp;Meaxp;KeaPp9oamaqp;Meaxp;Keczp:Rep9qgxpmwDKYqk8AExm35Ps8E8Fgrp5eakclp:RegmpEi:T:j83ibawarp5bampEd:T:j83ibaocwfaDaxpmbezHdiOAlvCXorQLgxp5eampEe:T:j83ibaoaxp5bampEb:T:j83ibaocafhoavclfgval6mbkkdnalaeSmbaiczfpxbbbbbbbbbbbbbbbbgmpklbaiampklbaiabalcitfgoaeciGgvcitgw;8qbbdnavTmbaipx:ji:1S:ji:1S:ji:1S:ji:1SaipblbgraipblzgDpmlvorxmPsCXQL358E8Fgqczp:Segkpxibbbibbbibbbibbbp9qgxp;6ep;Negmaxaxp:1ep;7egxaxp;KearaDpmbediwDqkzHOAKY8AEgxczp:Reczp:Sep;6egrarp;Meaxczp:Sep;6egDaDp;Meaqczp:Reczp:Sep;6egqaqp;Mep;Kep;Kep;Lepxbbbbbbbbbbbbbbbbp:4ep;Jep;Mepxbbn0bbn0bbn0bbn0gxp;KepxFFbbFFbbFFbbFFbbgPp9oamaDp;Meaxp;Keczp:Rep9qgDamarp;Meaxp;KeaPp9oamaqp;Meaxp;Keczp:Rep9qgxpmwDKYqk8AExm35Ps8E8Fgrp5eakclp:RegmpEi:T:j83iKaiarp5bampEd:T:j83izaiaDaxpmbezHdiOAlvCXorQLgxp5eampEe:T:j83iwaiaxp5bampEb:T:j83ibkaoaiaw;8qbbkk;uddiue978Jjjjjbc;ab9Rhidnadcd4ae2glc98GgvTmbcbheabhdinadadpbbbgocwp:Recwp:Sep;6eaocep:SepxbbjFbbjFbbjFbbjFp9opxbbjZbbjZbbjZbbjZp:Uep;Mepkbbadczfhdaeclfgeav6mbkkdnavalSmbaic8WfpxbbbbbbbbbbbbbbbbgopklbaicafaopklbaiczfaopklbaiaopklbaiabavcdtfgdalciGgecdtgv;8qbbdnaeTmbaiaipblbgocwp:Recwp:Sep;6eaocep:SepxbbjFbbjFbbjFbbjFp9opxbbjZbbjZbbjZbbjZp:Uep;Mepklbkadaiav;8qbbkk:CPvdue97euw97eu8Jjjjjbc8W9Rhiaec98Ghldndnadcl9hmbaipxbbbbbbbbbbbbbbbbgvpklbdnalTmbcbhoabhdinadpbbbhradpxbbuJbbuJbbuJbbuJaipblbarcKp:Tep9qgwcep:Seawp9qgDcdp:SeaDp9qgDclp:SeaDp9qgqp;6ep;NegDarcwp:RecKp:SegkarpxFbbbFbbbFbbbFbbbgxp9ogmp:Uep;6ep;Mepxbbn0bbn0bbn0bbn0gPp;Kecwp:RepxbFbbbFbbbFbbbFbbp9oaDamakp:Xearczp:RecKp:Segrp:Uep;6ep;MeaPp;Keaxp9op9qaDamakarp:Uep:Xep;6ep;MeaPp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qaDaqawcep:Rep9oawpxebbbebbbebbbebbbp9op9qp;6ep;MeaPp;KecKp:Rep9qpkbbadczfhdaoclfgoal6mbkkalaeSmeaiavpklaaicafabalcdtfgdaeciGglcdtgo;8qbbaiavpklbdnalTmbaipblahraipxbbuJbbuJbbuJbbuJaipblbarcKp:Tep9qgwcep:Seawp9qgDcdp:SeaDp9qgDclp:SeaDp9qgqp;6ep;NegDarcwp:RecKp:SegkarpxFbbbFbbbFbbbFbbbgxp9ogmp:Uep;6ep;Mepxbbn0bbn0bbn0bbn0gPp;Kecwp:RepxbFbbbFbbbFbbbFbbp9oaDamakp:Xearczp:RecKp:Segrp:Uep;6ep;MeaPp;Keaxp9op9qaDamakarp:Uep:Xep;6ep;MeaPp;Keczp:RepxbbFbbbFbbbFbbbFbp9op9qaDaqawcep:Rep9oawpxebbbebbbebbbebbbp9op9qp;6ep;MeaPp;KecKp:Rep9qpklakadaicafao;8qbbskaipxbbbbbbbbbbbbbbbbgvpklbdnalTmbcbhoabhdinadczfgspxbFu9hbFu9hbFu9hbFu9hadpbbbgDaspbbbgPpmlvorxmPsCXQL358E8Fgmczp:Teaipblbp9qgrcep:Searp9qgwcdp:Seawp9qgwclp:Seawp9qgwcwp:Seawp9qgqp;6ep;NegwaDaPpmbediwDqkzHOAKY8AEgDpxFFbbFFbbFFbbFFbbgPp9ogkaDczp:Segxp:Ueamczp:Reczp:Segmp:Xep;6ep;Mepxbbn0bbn0bbn0bbn0gDp;KeaPp9oawakaxamp:Uep:Xep;6ep;MeaDp;Keczp:Rep9qgxawaqarcep:Rep9oarpxebbbebbbebbbebbbp9op9qp;6ep;MeaDp;Keczp:Reawamakp:Uep;6ep;MeaDp;KeaPp9op9qgrpmwDKYqk8AExm35Ps8E8FpkbbadaxarpmbezHdiOAlvCXorQLpkbbadcafhdaoclfgoal6mbkkalaeSmbaiczfpxbbbbbbbbbbbbbbbbgrpklbaiarpklbaiabalcitfgdaeciGglcitgo;8qbbaiavpkladnalTmbaipxbFu9hbFu9hbFu9hbFu9haipblbgDaipblzgPpmlvorxmPsCXQL358E8Fgmczp:Teaipblap9qgrcep:Searp9qgwcdp:Seawp9qgwclp:Seawp9qgwcwp:Seawp9qgqp;6ep;NegwaDaPpmbediwDqkzHOAKY8AEgDpxFFbbFFbbFFbbFFbbgPp9ogkaDczp:Segxp:Ueamczp:Reczp:Segmp:Xep;6ep;Mepxbbn0bbn0bbn0bbn0gDp;KeaPp9oawakaxamp:Uep:Xep;6ep;MeaDp;Keczp:Rep9qgxawaqarcep:Rep9oarpxebbbebbbebbbebbbp9op9qp;6ep;MeaDp;Keczp:Reawamakp:Uep;6ep;MeaDp;KeaPp9op9qgrpmwDKYqk8AExm35Ps8E8FpklzaiaxarpmbezHdiOAlvCXorQLpklbkadaiao;8qbbkk9teiucbcbydj1jjbgeabcifc98GfgbBdj1jjbdndnabZbcztgd9nmbcuhiabad9RcFFifcz4nbcuSmekaehikaikkkebcjwklz:Dbb`,n=new Uint8Array([0,97,115,109,1,0,0,0,1,4,1,96,0,0,3,3,2,0,0,5,3,1,0,1,12,1,0,10,22,2,12,0,65,0,65,0,65,0,252,10,0,0,11,7,0,65,0,253,15,26,11]),r=new Uint8Array([32,0,65,2,1,106,34,33,3,128,11,4,13,64,6,253,10,7,15,116,127,5,8,12,40,16,19,54,20,9,27,255,113,17,42,67,24,23,146,148,18,14,22,45,70,69,56,114,101,21,25,63,75,136,108,28,118,29,73,115]);if(typeof WebAssembly!=`object`)return{supported:!1};var i=WebAssembly.validate(n)?s(t):s(e),a,o=WebAssembly.instantiate(i,{}).then(function(e){a=e.instance,a.exports.__wasm_call_ctors()});function s(e){for(var t=new Uint8Array(e.length),n=0;n<e.length;++n){var i=e.charCodeAt(n);t[n]=i>96?i-97:i>64?i-39:i+4}for(var a=0,n=0;n<e.length;++n)t[a++]=t[n]<60?r[t[n]]:(t[n]-60)*64+t[++n];return t.buffer.slice(0,a)}function c(e,t,n,r,i,a,o){var s=e.exports.sbrk,c=r+3&-4,l=s(c*i),u=s(a.length),d=new Uint8Array(e.exports.memory.buffer);d.set(a,u);var f=t(l,r,i,u,a.length);if(f==0&&o&&o(l,c,i),n.set(d.subarray(l,l+r*i)),s(l-s(0)),f!=0)throw Error(`Malformed buffer data: `+f)}var l={NONE:``,OCTAHEDRAL:`meshopt_decodeFilterOct`,QUATERNION:`meshopt_decodeFilterQuat`,EXPONENTIAL:`meshopt_decodeFilterExp`,COLOR:`meshopt_decodeFilterColor`},u={ATTRIBUTES:`meshopt_decodeVertexBuffer`,TRIANGLES:`meshopt_decodeIndexBuffer`,INDICES:`meshopt_decodeIndexSequence`},d=[],f=0;function p(e){var t={object:new Worker(e),pending:0,requests:{}};return t.object.onmessage=function(e){var n=e.data;t.pending-=n.count,t.requests[n.id][n.action](n.value),delete t.requests[n.id]},t}function m(e){for(var t=`self.ready = WebAssembly.instantiate(new Uint8Array([`+new Uint8Array(i)+`]), {}).then(function(result) { result.instance.exports.__wasm_call_ctors(); return result.instance; });self.onmessage = `+g.name+`;`+c.toString()+g.toString(),n=new Blob([t],{type:`text/javascript`}),r=URL.createObjectURL(n),a=d.length;a<e;++a)d[a]=p(r);for(var a=e;a<d.length;++a)d[a].object.postMessage({});d.length=e,URL.revokeObjectURL(r)}function h(e,t,n,r,i){for(var a=d[0],o=1;o<d.length;++o)d[o].pending<a.pending&&(a=d[o]);return new Promise(function(o,s){var c=new Uint8Array(n),l=++f;a.pending+=e,a.requests[l]={resolve:o,reject:s},a.object.postMessage({id:l,count:e,size:t,source:c,mode:r,filter:i},[c.buffer])})}function g(e){var t=e.data;if(!t.id)return self.close();self.ready.then(function(e){try{var n=new Uint8Array(t.count*t.size);c(e,e.exports[t.mode],n,t.count,t.size,t.source,e.exports[t.filter]),self.postMessage({id:t.id,count:t.count,action:`resolve`,value:n},[n.buffer])}catch(e){self.postMessage({id:t.id,count:t.count,action:`reject`,value:e})}})}return{ready:o,supported:!0,useWorkers:function(e){m(e)},decodeVertexBuffer:function(e,t,n,r,i){c(a,a.exports.meshopt_decodeVertexBuffer,e,t,n,r,a.exports[l[i]])},decodeIndexBuffer:function(e,t,n,r){c(a,a.exports.meshopt_decodeIndexBuffer,e,t,n,r)},decodeIndexSequence:function(e,t,n,r){c(a,a.exports.meshopt_decodeIndexSequence,e,t,n,r)},decodeGltfBuffer:function(e,t,n,r,i,o){c(a,a.exports[u[i]],e,t,n,r,a.exports[l[o]])},decodeGltfBufferAsync:function(e,t,n,r,i){return d.length>0?h(e,t,n,u[r],l[i]):o.then(function(){var o=new Uint8Array(e*t);return c(a,a.exports[u[r]],o,e,t,n,a.exports[l[i]]),o})}}})(),Jk=1230263361,Yk=2,Xk=16,Zk=11,Qk=32767,$k=86400;function eA(e){let t=new DataView(e);if(t.getUint32(0,!0)!==Jk)throw Error(`attitude: bad file magic (expected ATTI)`);let n=t.getUint16(4,!0);if(n!==Yk)throw Error(`attitude: unsupported version ${n}`);let r=t.getFloat64(8,!0),i=Math.floor((e.byteLength-Xk)/Zk),a=new Float64Array(i),o=new Float32Array(i*4),s=0;for(let e=0;e<i;e++){let n=Xk+e*Zk;e>0&&(s+=t.getFloat32(n,!0)),a[e]=r+s/$k;let i=t.getUint8(n+4),c=t.getInt16(n+5,!0)/Qk,l=t.getInt16(n+7,!0)/Qk,u=t.getInt16(n+9,!0)/Qk,d=Math.sqrt(Math.max(0,1-c*c-l*l-u*u)),f=e*4,p=0;for(let e=0;e<4;e++)e===i?o[f+e]=d:(o[f+e]=p===0?c:p===1?l:u,p++)}return{times:a,quats:o}}var tA=86400,nA=new Xi().setFromRotationMatrix(new Y().makeBasis(wg(1,0,0,new J),wg(0,1,0,new J),wg(0,0,1,new J))),rA=new Xi,iA=new Xi,aA=new Xi,oA=new J;function sA(e,t,n){let r=t*4;return n.set(e[r+1],e[r+2],e[r+3],e[r])}var cA=class{startJd;endJd;baselines;files;chunks=new Map;inflight=new Set;retries=new Tx;constructor(e,t){this.probeId=e,this.startJd=t.files.length?t.files[0].start_jd:0,this.endJd=t.files.length?t.files[t.files.length-1].end_jd:0,this.baselines=t.baselines,this.files=t.files}covers(e){return this.coversTdb(Ig(e))}coversTdb(e){return e>=this.startJd&&e<=this.endJd&&this.files.length>0}orientationAt(e,t){let n=Ig(e);if(!this.coversTdb(n))return!1;let r=this.fileIndexFor(n),i=this.ensure(r);if(!i)return!1;this.ensure(r-1),this.ensure(r+1),this.sampleChunk(n,r,i);let a=this.baselines?.[this.files[r].baseline_index??0];if(a){let{axis:e,rate_rad_s:t,anchor:r,anchor_jd:i}=a,o=(n-i)*tA;oA.set(e[0],e[1],e[2]),aA.setFromAxisAngle(oA,t*o),iA.set(r[1],r[2],r[3],r[0]),aA.multiply(iA),rA.copy(aA.multiply(rA))}return rA.conjugate(),t.copy(nA).multiply(rA),!0}fileIndexFor(e){let t=this.files;if(e<=t[0].start_jd)return 0;let n=0,r=t.length-1;for(;r-n>1;){let i=n+r>>1;t[i].start_jd<=e?n=i:r=i}return t[r].start_jd<=e?r:n}sampleChunk(e,t,n){let{times:r,quats:i}=n,a=r.length;if(e<=r[0]){sA(i,0,rA);return}if(e>=r[a-1]){let n=this.chunks.get(t+1);if(this.files[t+1]?.baseline_index===this.files[t].baseline_index&&n&&n.times.length>0&&n.times[0]>r[a-1]){let t=n.times[0]-r[a-1],o=Math.min(1,(e-r[a-1])/t);sA(i,a-1,rA),sA(n.quats,0,iA),rA.slerpQuaternions(rA,iA,o)}else sA(i,a-1,rA);return}let o=0,s=a-1;for(;s-o>1;){let t=o+s>>1;r[t]<=e?o=t:s=t}let c=r[s]-r[o],l=c>0?(e-r[o])/c:0;sA(i,o,rA),sA(i,s,iA),rA.slerpQuaternions(rA,iA,l)}ensure(e){if(e<0||e>=this.files.length)return;let t=this.chunks.get(e);if(t)return t;this.inflight.has(e)||this.retries.waiting(e)||(this.inflight.add(e),this.load(e))}async load(e){let t=this.files[e];try{let n=await fetch(`${Gt()}/v1/attitude/${this.probeId}/${t.name}`);if(!n.ok)throw Error(`${n.status}`);let r=new DecompressionStream(`gzip`),i=await new Response(n.body.pipeThrough(r)).arrayBuffer();this.chunks.set(e,eA(i)),this.retries.clear(e)}catch(n){this.retries.fail(e),console.warn(`attitude: chunk ${this.probeId}/${t.name} failed to load:`,n)}finally{this.inflight.delete(e)}}};function lA(e,t){return new cA(e,t)}var uA=[`carrier`,`missing`],dA=`scene-label__annotation--visible`;function fA(e,t,n){let r=e.labelAnnotations?.[t];if(!r){if(!n||!e.label)return;r=document.createElement(`span`),r.className=`scene-label__annotation`,r.dir=`auto`,r.textContent=n,hA(e,r,t),(e.labelAnnotations??={})[t]=r}else if(n===null){if(!r.classList.contains(dA))return}else if(r.textContent===n&&r.classList.contains(dA))return;else r.textContent=n;r.classList.toggle(dA,n!==null),pA(e)}function pA(e){let t=e.label?.element;if(!t)return;let n=[t.querySelector(`.scene-label__name`)?.textContent||e.body.data.name];for(let t of uA){let r=e.labelAnnotations?.[t];r?.classList.contains(dA)&&n.push(r.textContent)}let r=n.filter(Boolean).join(`, `);r?t.setAttribute(`aria-label`,r):t.removeAttribute(`aria-label`)}function mA(e){if(!e.labelStack){let t=document.createElement(`span`);t.className=`scene-label__annotations`,e.label.element.appendChild(t),e.labelStack=t}return e.labelStack}function hA(e,t,n){for(let r of uA.slice(uA.indexOf(n)+1)){let n=e.labelAnnotations?.[r];if(n){n.parentElement.insertBefore(t,n);return}}mA(e).appendChild(t)}function gA(e,t){let n=e.userData,r=t??``;if(n.tintBase&&n.tintKey===r)return n.tintBase;let i=CA(e,t);return n.tintBase=i,n.tintKey=r,i}function _A(e){let t=e.userData;return t.meanColorImage!==e.image&&(t.meanColor=vA(e),t.meanColorImage=e.image),t.meanColor??null}function vA(e){let t=TA(e);if(!t)return null;let n=new X(0,0,0),r=new X,i=0;for(let a=0;a<bA;a++){let o=Math.sin(Math.PI*(a+.5)/bA);for(let i=a*yA*4;i<(a+1)*yA*4;i+=4)r.setRGB(t[i]/255,t[i+1]/255,t[i+2]/255,e.colorSpace),n.r+=o*r.r,n.g+=o*r.g,n.b+=o*r.b;i+=o*yA}return n.multiplyScalar(1/i)}var yA=32,bA=16,xA=.01,SA=.001;function CA(e,t){let n=new X(16777215);if(!t)return n;let r=wA(e);if(r===null||r>xA)return n;let i=new X(t),a=.2126*i.r+.7152*i.g+.0722*i.b;return a<SA?n:new X().setRGB(i.r/a,i.g/a,i.b/a)}function wA(e){let t=TA(e);if(!t)return null;let n=0,r=t.length/4;for(let e=0;e<t.length;e+=4){let r=t[e]/255,i=t[e+1]/255,a=t[e+2]/255;n+=Math.max(r,i,a)-Math.min(r,i,a)}return n/r}function TA(e){let t=e.image;if(!t||!t.width||!t.height)return null;let n=document.createElement(`canvas`);n.width=yA,n.height=bA;let r=n.getContext(`2d`,{willReadFrequently:!0});if(!r)return null;r.drawImage(t,0,0,yA,bA);try{return r.getImageData(0,0,yA,bA).data}catch{return null}}var EA=`
|
|
5513
5513
|
#ifdef USE_MAP
|
|
5514
5514
|
vec3 bodyDir = normalize( vBodyDir );
|
|
5515
5515
|
float lon = atan( -bodyDir.z, bodyDir.x );
|
|
@@ -5521,16 +5521,16 @@ float reliefTileShadow( vec3 dir, mat3x2 map, mat3x2 cap, float side, vec3 toSun
|
|
|
5521
5521
|
vec4 sampledDiffuseColor = textureGrad( map, euv, seam ? dxB : dxA, seam ? dyB : dyA );
|
|
5522
5522
|
diffuseColor *= sampledDiffuseColor;
|
|
5523
5523
|
#endif
|
|
5524
|
-
`;function
|
|
5524
|
+
`;function DA(e){let t=new Du({color:e,roughness:1,metalness:0});return t.onBeforeCompile=e=>{e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
|
|
5525
5525
|
varying vec3 vBodyDir;`).replace(`#include <begin_vertex>`,`#include <begin_vertex>
|
|
5526
5526
|
vBodyDir = position;`),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
|
|
5527
|
-
varying vec3 vBodyDir;`).replace(`#include <map_fragment>`,
|
|
5527
|
+
varying vec3 vBodyDir;`).replace(`#include <map_fragment>`,EA).replace(`#include <envmap_physical_pars_fragment>`,`
|
|
5528
5528
|
#ifdef USE_ENVMAP
|
|
5529
5529
|
vec3 getIBLIrradiance( const in vec3 normal ) { return vec3( 0.0 ); }
|
|
5530
5530
|
vec3 getIBLRadiance( const in vec3 viewDir, const in vec3 normal, const in float roughness ) { return vec3( 0.0 ); }
|
|
5531
|
-
#endif`)},VS(t,`shapeModel`),t}function
|
|
5531
|
+
#endif`)},VS(t,`shapeModel`),t}function OA(e,t){e.traverse(e=>{if(!(e instanceof Us))return;let n=e.material;e.material=t;let r=Array.isArray(n)?n:[n];for(let e of r)e?.dispose()})}function kA(e,t,n,r){e.traverse(e=>{!(e instanceof Us)||!(e.material instanceof Du)||(e.material.map=t,t?e.material.color.copy(gA(t,r)):e.material.color.set(n),e.material.needsUpdate=!0)})}function AA(e,t,n){e.map&&e.map!==t&&e.map.dispose(),t.colorSpace=ri,t.anisotropy=16,e.map=t,e.color.copy(gA(t,n)),e.needsUpdate=!0}var jA=[-.019,242e-6,-146e-8],MA=`
|
|
5532
5532
|
float lunarLambertWeight(float phaseDeg, float scale) {
|
|
5533
|
-
return min(scale * clamp(1.0 + phaseDeg * (${
|
|
5533
|
+
return min(scale * clamp(1.0 + phaseDeg * (${jA[0].toFixed(8)} + phaseDeg * (${jA[1].toFixed(8)} + phaseDeg * ${jA[2].toFixed(8)})), 0.0, 1.0), 1.0);
|
|
5534
5534
|
}
|
|
5535
5535
|
|
|
5536
5536
|
float lunarLambertGain(float phaseDeg, float mu0, float mu, float scale) {
|
|
@@ -5538,13 +5538,13 @@ varying vec3 vBodyDir;`).replace(`#include <map_fragment>`,TA).replace(`#include
|
|
|
5538
5538
|
float sun = max(mu0, 0.0);
|
|
5539
5539
|
return 2.0 * weight / max(sun + max(mu, sun), ${.05.toFixed(3)}) + 1.0 - weight;
|
|
5540
5540
|
}
|
|
5541
|
-
`;function
|
|
5541
|
+
`;function NA(e){return{uLunarWeightScale:{value:e??1}}}function PA(e,t){let[n,r,i]=jA,a=Math.min(1,Math.max(0,1+e*(n+e*(r+e*i))));return Math.min(1,t*a)}var FA=`
|
|
5542
5542
|
#ifdef USE_ROUGHNESSMAP
|
|
5543
5543
|
reflectedLight.directSpecular *= texelRoughness.g;
|
|
5544
5544
|
#else
|
|
5545
5545
|
reflectedLight.directSpecular = vec3(0.0);
|
|
5546
5546
|
#endif
|
|
5547
|
-
`,
|
|
5547
|
+
`,IA=`
|
|
5548
5548
|
{
|
|
5549
5549
|
vec3 sunView = mat3(viewMatrix) * uPhotometrySunDir;
|
|
5550
5550
|
#if NUM_POINT_LIGHTS > 0
|
|
@@ -5559,7 +5559,7 @@ varying vec3 vBodyDir;`).replace(`#include <map_fragment>`,TA).replace(`#include
|
|
|
5559
5559
|
uLunarWeightScale
|
|
5560
5560
|
);
|
|
5561
5561
|
}
|
|
5562
|
-
`;function IA(e,t,n,r){let i=!Jb(t);HS(e,i?`photometryAirless`:`photometry`,e=>{let t=``,a=PA;i&&(e.uniforms.uPhotometrySunDir=r??Mw().uSunDir,Object.assign(e.uniforms,n),t=`uniform vec3 uPhotometrySunDir;\nuniform float uLunarWeightScale;\n${jA}`,a+=FA),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>\n${t}`).replace(`#include <lights_fragment_end>`,`#include <lights_fragment_end>\n${a}`)})}var LA=`#6b6b6b`;function RA(e){return .2126*e.r+.7152*e.g+.0722*e.b}function zA(e,t){return e?(2+NA(0,t??1))/3:2/3}var BA=new X;function VA(e){return e.color?(e.geometricAlbedo??RA(BA.set(e.color)))/zA(!Jb(e.id),e.lunarWeightScale):null}function HA(e,t=new X){let n=VA(e);return n===null?t.set(LA):(t.set(e.color),t.multiplyScalar(n/RA(t)))}function UA(e,t,n){if(e.color)n.set(e.color);else if(e.geometricAlbedo===void 0)return null;else{let e=t&&gA(t);e?n.copy(e):n.setRGB(1,1,1)}let r=e.geometricAlbedo??RA(n);return n.multiplyScalar(1.5*r/RA(n))}var WA=new Set([]);function GA(e){return e?.model_name?WC()&&e.render_quality!==`high`?`low-end-device`:e.displacement&&!WA.has(e.id)?`dem-preferred`:null:`no-bundle`}function KA(e,t,n,r,i){e.orientation=t,e.nutPrec=Rv(e.data.id,n),r&&r.bodies.dataVersion++,r?.credits.registerOrientation({bodyId:e.data.id,systemId:i??e.data.id,source:t.source,reference:t.reference})}var qA=48,JA=96,YA=qA*JA,XA=1<<24,ZA=Math.PI*2;function QA(e){let t=Math.floor((e+1)/2*qA);return Math.min(qA-1,Math.max(0,t))}function $A(e,t){let n=Math.atan2(-t,e);return(Math.floor((n+Math.PI)/ZA*JA)%JA+JA)%JA}var ej=new J;function tj(e){let t=e.verts.length/3,n=new Int32Array(t),r=new Float32Array(t*3);for(let i=0;i<t;i++)ej.set(e.verts[i*3],e.verts[i*3+1],e.verts[i*3+2]).normalize(),r[i*3]=ej.x,r[i*3+1]=ej.y,r[i*3+2]=ej.z,n[i]=QA(ej.y)*JA+$A(ej.x,ej.z);return{cells:n,dirs:r}}function nj(e,t){let n=e.geometry.attributes.position,r=new Y().multiplyMatrices(t,e.matrixWorld),i=new Float32Array(n.count*3);for(let e=0;e<n.count;e++)ej.set(n.getX(e),n.getY(e),n.getZ(e)).applyMatrix4(r),i[e*3]=ej.x,i[e*3+1]=ej.y,i[e*3+2]=ej.z;return i}var rj=new J,ij=new J,aj=new J,oj=new J,sj=new J,cj=new J;function lj(e,t,n){return n.set(e[t*3],e[t*3+1],e[t*3+2])}function uj(e,t,n,r){return cj.crossVectors(e,n).dot(r)>=0&&cj.crossVectors(n,t).dot(r)>=0}function dj(e,t,n){oj.crossVectors(e,t);let r=oj.lengthSq();r<1e-18||(sj.set(0,1,0).addScaledVector(oj,-oj.y/r).normalize(),uj(e,t,sj,oj)&&(n.hi=Math.max(n.hi,QA(sj.y))),sj.negate(),uj(e,t,sj,oj)&&(n.lo=Math.min(n.lo,QA(sj.y))))}function fj(e,t,n,r){let i=(e.z*t.x-e.x*t.z)*r,a=(t.z*n.x-t.x*n.z)*r,o=(n.z*e.x-n.x*e.z)*r;return i>0&&a>0&&o>0||i<0&&a<0&&o<0}function pj(e,t){let n={lo:0,hi:0},r=[];for(let i=0;i<e.length;i++){let a=e[i],{cells:o,dirs:s}=t[i],c=new Int32Array(a.faces*4);r.push(c);for(let e=0;e<a.faces;e++){let t=a.idx?a.idx[e*3]:e*3,r=a.idx?a.idx[e*3+1]:e*3+1,i=a.idx?a.idx[e*3+2]:e*3+2,l=o[t],u=o[r],d=o[i],f=l/JA|0,p=u/JA|0,m=d/JA|0,h=l%JA,g=u%JA,_=d%JA,v=Math.min(f,p,m),y=Math.max(f,p,m),b=Math.min(h,g,_),x=Math.max(h,g,_),S=h+g+_-b-x,C=b+JA-x,w=b,T=x;S-b>=x-S&&S-b>C?(w=S,T=b+JA):x-S>C&&(w=x,T=S+JA),(y-v>1||T-w>1)&&(lj(s,t,rj),lj(s,r,ij),lj(s,i,aj),fj(rj,ij,aj,1)?(y=qA-1,w=0,T=JA-1):fj(rj,ij,aj,-1)?(v=0,w=0,T=JA-1):(n.lo=v,n.hi=y,dj(rj,ij,n),dj(ij,aj,n),dj(aj,rj,n),v=n.lo,y=n.hi)),c[e*4]=v,c[e*4+1]=y,c[e*4+2]=w,c[e*4+3]=T}}return r}function mj(e,t){for(let n=0;n<e.length;n++){let r=e[n];for(let e=0;e*4<r.length;e++){let i=n*XA+e;for(let n=r[e*4];n<=r[e*4+1];n++)for(let a=r[e*4+2];a<=r[e*4+3];a++)t(n*JA+a%JA,i)}}}function hj(e){e.updateMatrixWorld(!0);let t=new Y().makeTranslation(-e.position.x,-e.position.y,-e.position.z),n=[];if(e.traverse(e=>{if(!(e instanceof Us))return;let r=e.geometry.attributes.position;if(!r)return;let i=e.geometry.index,a=(i?i.count:r.count)/3;a<1||a>=XA||n.push({verts:nj(e,t),idx:i?i.array:null,faces:Math.floor(a)})}),!n.length)return null;let r=pj(n,n.map(tj)),i=new Int32Array(YA+1);mj(r,e=>i[e+1]++);for(let e=0;e<YA;e++)i[e+1]+=i[e];let a=new Int32Array(i[YA]),o=i.slice(0,YA);return mj(r,(e,t)=>{a[o[e]++]=t}),{meshes:n,start:i,slots:a}}var gj=new J,_j=new J,vj=new J,yj=new J,bj=new J,xj=new J,Sj=new J;function Cj(e,t,n){let r=e.idx?e.idx[t*3]:t*3,i=e.idx?e.idx[t*3+1]:t*3+1,a=e.idx?e.idx[t*3+2]:t*3+2;gj.set(e.verts[r*3],e.verts[r*3+1],e.verts[r*3+2]),_j.set(e.verts[i*3],e.verts[i*3+1],e.verts[i*3+2]),vj.set(e.verts[a*3],e.verts[a*3+1],e.verts[a*3+2]),yj.subVectors(_j,gj),bj.subVectors(vj,gj),xj.crossVectors(n,bj);let o=yj.dot(xj);if(Math.abs(o)<1e-12)return 0;let s=1/o,c=-gj.dot(xj)*s;if(c<0||c>1)return 0;Sj.crossVectors(gj,yj).negate();let l=n.dot(Sj)*s;if(l<0||c+l>1)return 0;let u=bj.dot(Sj)*s;return u>0?u:0}function wj(e,t,n,r){let{start:i,slots:a,meshes:o}=e;for(let e=i[t];e<i[t+1];e++){let t=a[e],i=Cj(o[t/XA|0],t%XA,n);i>r&&(r=i)}return r}function Tj(e,t){let n=QA(t.y),r=$A(t.x,t.z),i=wj(e,n*JA+r,t,0);if(i>0)return i;for(let a=-1;a<=1;a++){let o=n+a;if(!(o<0||o>=qA))for(let n=-1;n<=1;n++)i=wj(e,o*JA+(r+n+JA)%JA,t,i)}if(i===0&&(n===0||n===qA-1)){let r=n===0?0:qA-2;for(let n=r;n<r+2;n++)for(let r=0;r<JA;r++)i=wj(e,n*JA+r,t,i)}return i>0?i:null}function Ej(e){let t=e.data.objectType;return t===G.SPACECRAFT||t===G.DEBRIS||e.data.orbitalSource===W.SPICE_PROBE}var Dj=new KO;Dj.setMeshoptDecoder(Kk);var Oj=Dj,kj=new Map;function Aj(e){let t=kj.get(e);return t||(t=fetch(Qt(`/v1/models/${e}/metadata.json`,`models`)).then(e=>e.json()),kj.set(e,t),t.catch(()=>kj.delete(e))),t}function jj(e){if(a(e.exports.high.distribution))return`high`;if(e.exports.low&&a(e.exports.low.distribution))return`low`}function Mj(e){return e.credit??e.exports.high.credit}function Nj(e,t){return e.exports[t]?.credit??e.exports.high.credit}function Pj(e){return e.modelUnitOverride??e.radiusScene}var Fj=new Set;function Ij(e,t){let n=new qa;n.scale.setScalar(Pj(e)),n.userData.pickBody=e.body,n.add(t),e.group.add(n),e.modelRoot=n,e.model=t,Fj.add(n)}function Lj(e,t){let n=new Set;t.traverse(t=>{if(!(t instanceof Us))return;let r=Array.isArray(t.material)?t.material:[t.material];for(let t of r)!(t instanceof Du)||n.has(t)||(n.add(t),e.eclipseShadow=Ww(t,e.eclipseShadow??void 0))})}function Rj(e,t,n){if(e.model)return Promise.resolve();if(e.modelLoadPromise)return e.modelLoadPromise;let r=(Ej(e.body)?zj(e,t,n):Bj(e,n)).finally(()=>{e.modelLoadPromise===r&&(e.modelLoadPromise=void 0)});return e.modelLoadPromise=r,r}async function zj(e,t,n){let r=e.modelLoadEpoch??0;e.mesh&&(e.mesh.visible=!1);try{let i=await tS(e.body.data.id,!1);e.body.pointing=i.global?.pointing;let a=i.global?.attitude;if(a&&(e.modelLoadEpoch??0)===r){let t=e.body.data.id.replace(/^probe-/,``);e.body.attitudeTrack=cA(t,a)}let o=i.global?.model_name;if(!o){e.noPhysical=`model`;return}if((e.modelLoadEpoch??0)!==r)return;e.mesh&&(e.mesh.visible=!1),Hj(e,!0);let s=await Aj(o),c=jj(s);if(!c){e.noPhysical=`model`;return}let l=await Oj.loadAsync(Qt(`/v1/models/${o}/${c}.glb`,`models`));if((e.modelLoadEpoch??0)!==r||!e.mesh){uM(l.scene);return}let u=s.frame_map?OS(s.frame_map):null;e.body.modelBaseFrame=u??void 0;let d=Uj(l.scene,u),f=s.model_anchor?new J(...s.model_anchor):null;if(!Wj(d,f&&u?f.applyQuaternion(u):f)){uM(l.scene),e.noPhysical=`model`;return}if(lM(d),t.add(d),d.visible=!e.isCrashed,e.model=d,e.modelName=o,Hj(e,!1),s.scale_meters){let t=s.scale_meters/2e3;e.body.data.radiusKm=t*(s.body_span_ratio??1),e.radiusScene=Q(bn(e.body.data)),e.modelUnitOverride=s.body_span_ratio?Q(t):void 0}let p=Nj(s,c);n?.credits.registerModel({bodyId:e.body.data.id,source:p.url,organisation:p.name,license:p.license})}finally{e.model||Hj(e,!1)}}async function Bj(e,t){if(!$C().showShapeMesh)return;let n=e.modelLoadEpoch??0;try{let r=await tS(e.body.data.id,!1),i=r.global?.model_name;if(!i)return;let a=GA(r.global);if(a){console.info(`Skipping ${r.global?.render_quality??`unrated`} shape mesh for ${e.body.data.id}: ${a}`);return}r.global?.orientation&&!e.body.orientation&&KA(e.body,r.global.orientation,r.global.nut_prec,t);let o=Aj(i),s=await Oj.loadAsync(Qt(`/v1/models/${i}/high.glb`,`models`));if((e.modelLoadEpoch??0)!==n){uM(s.scene);return}let c;try{c=await o}catch(e){uM(s.scene),console.warn(`Failed to load shape-model metadata for ${i}:`,e);return}if(c.kind!==`shape_model`){uM(s.scene);return}let l=s.scene;if(!Wj(l)){uM(s.scene);return}l.userData.radialIndex=hj(l);let u=EA(HA(e.body.data));e.photometry??=MA(e.body.data.lunarWeightScale),IA(u,e.body.data.id,e.photometry),e.planetshine=bT(u,e.planetshine??void 0),DA(l,u);let d=e.mesh?e.mesh.material.map:null;d&&OA(l,d,HA(e.body.data),e.body.data.color),lM(l),Lj(e,l),c.true_scale&&(e.radiusScene=Q(c.true_scale.max_extent_km/2),Number.isFinite(e.body.data.radiusKm)&&e.body.data.radiusKm>0||(e.body.data.radiusKm=c.true_scale.max_extent_km/2),e.noPhysical&&(e.noPhysical=void 0,dA(e,`missing`,null))),Ij(e,l),e.modelName=i,e.mesh&&(e.mesh.visible=!1);let f=Mj(c),p=r.global?.model_source;t?.credits.registerModel({bodyId:e.body.data.id,source:f.url,organisation:f.name,license:f.license,provenance:p?.provenance,technique:p?.technique,archive:p?.archive,archiveUrl:p?.archive_url,mission:p?.mission&&{name:p.mission.name,id:p.mission.primary_id}})}finally{!e.model&&e.mesh&&(e.mesh.visible=!0)}}function Vj(e){e.modelLoadEpoch=(e.modelLoadEpoch??0)+1,e.modelLoadPromise=void 0,Hj(e,!1);let t=!Ej(e.body),n=e.model;if(!n){e.mesh&&t&&(e.mesh.visible=!0);return}e.modelRoot&&=(Fj.delete(e.modelRoot),e.modelRoot.removeFromParent(),null),n.parent?.remove(n),uM(n),e.model=null,e.modelName=void 0,e.body.pointing=void 0,e.body.attitudeTrack=void 0,e.body.modelBaseFrame=void 0,e.mesh&&t&&(e.mesh.visible=!0)}function Hj(e,t){if(t){if(e.loadingEl)return;let t=document.createElement(`div`);t.className=`scene-label__loader`,t.style.display=`none`,document.body.appendChild(t),e.loadingEl=t,e.loadingShown=!1}else e.loadingEl&&(e.loadingEl.remove(),e.loadingEl=null,e.loadingShown=void 0)}function Uj(e,t){if(!t)return e;let n=new qa;return e.quaternion.copy(t),n.add(e),n}function Wj(e,t=null){e.updateMatrixWorld(!0);let n=new _o().setFromObject(e,!0),r=n.getSize(new J),i=n.getCenter(new J),a=Math.max(r.x,r.y,r.z);if(a<=0)return!1;let o=2/a;e.userData.boxCenter=i.clone().multiplyScalar(o),t&&i.addScaledVector(t,a/2),e.scale.multiplyScalar(o),e.userData.fitScale=e.scale.x,e.position.copy(i).multiplyScalar(-o),e.userData.centerOffset=i.clone().multiplyScalar(o),e.userData.feetOffset=new J(i.x,n.min.y,i.z).multiplyScalar(o),e.userData.halfExtents=r.clone().multiplyScalar(o*.5);let s=qj(e,r,o,e.userData.centerOffset);e.userData.occluderSpheres=s.spheres;let c=e.userData.centerOffset.length();return e.userData.minRadius=Math.max(0,s.minRadius-c),e.userData.maxRadius=e.userData.halfExtents.length()+c,!0}var Gj=8,Kj=4096;function qj(e,t,n,r){e.updateMatrixWorld(!0);let i=t.x>=t.y&&t.x>=t.z?0:t.y>=t.z?1:2,a=0;if(e.traverse(e=>{e instanceof Us&&(a+=e.geometry.attributes.position?.count??0)}),!a)return{spheres:[],minRadius:0};let o=Math.max(1,Math.floor(a/Kj)),s=[],c=new J;e.traverse(t=>{if(!(t instanceof Us))return;let n=t.geometry.attributes.position;if(n)for(let r=0;r<n.count;r+=o)c.fromBufferAttribute(n,r).applyMatrix4(t.matrixWorld).sub(e.position),s.push(c.clone())});let l=t.getComponent(i)*n/2+Math.abs(r.getComponent(i)),u=Array.from({length:Gj},()=>[]);for(let e of s){let t=(e.getComponent(i)+l)/(2*l);u[Math.min(Gj-1,Math.max(0,Math.floor(t*Gj)))].push(e)}let d=1/0;for(let e of s)d=Math.min(d,e.length());let f=[];for(let e of u){if(e.length<3)continue;let t=new J;for(let n of e)t.add(n);t.divideScalar(e.length);let n=0;for(let r of e)n=Math.max(n,t.distanceToSquared(r));f.push({center:t,r:Math.sqrt(n)})}return{spheres:f,minRadius:Number.isFinite(d)?d:0}}var Jj=4,Yj=.05,Xj=new J,Zj=new J,Qj=new J,$j=new J,eM=new Xi,tM=new J,nM=new Zd;function rM(e,t,n,r){let i=e.parent;if(!i)return null;i.updateMatrixWorld(!0);let a=i.getWorldScale($j).x;if(!(a>0))return null;let o=Math.cos(t);Xj.set(o*Math.cos(n),Math.sin(t),-o*Math.sin(n)),Zj.copy(Xj).applyQuaternion(e.quaternion),Qj.copy(e.position).addScaledVector(Zj,Jj),i.localToWorld(Qj),nM.set(Qj,Zj.negate());let s=nM.intersectObject(e,!0)[0];return s?(r&&s.face&&r.copy(s.face.normal).transformDirection(s.object.matrixWorld).applyQuaternion(eM.copy(e.quaternion).invert()),Math.max(Jj-s.distance/a,Yj)):null}function iM(e,t){let n=e?.model?.userData.radialIndex;if(!n)return null;let r=Tj(n,tM.set(t[0],t[1],t[2]));return r===null?null:xg(r*Pj(e))}function aM(e){return!!e?.model?.userData.radialIndex&&e.model.parent===e.modelRoot}function oM(e){if(!aM(e))return;let t=e.model.position,n=Pj(e);return[t.x*n,t.y*n,t.z*n]}function sM(e){if(aM(e))return xg(e.model.userData.maxRadius*Pj(e))}function cM(e){if(aM(e))return xg(e.model.userData.minRadius*Pj(e))}function lM(e){e.traverse(e=>{e instanceof Us&&(e.castShadow=!0,e.receiveShadow=!0)})}function uM(e){e.traverse(e=>{if(!(e instanceof Us))return;e.geometry?.dispose();let t=e.material,n=Array.isArray(t)?t:[t];for(let e of n)if(e){for(let t of Object.values(e))t instanceof ma&&t.dispose();e.dispose()}})}var dM=3;function fM(e,t,n=dM){let r=0,i=0;e.addEventListener(`pointerdown`,e=>{r=e.clientX,i=e.clientY}),e.addEventListener(`click`,e=>{e.stopPropagation();let a=e.clientX-r,o=e.clientY-i;a*a+o*o<=n*n&&t(e)})}function pM(e,t){if(e)return mn(e)?e.featureAnchor.hostId:t.get(e.data.id)?.isLanded?e.data.parentId:e.data.id}var mM=Math.PI/180,hM=.9,gM=24,_M=.2,vM=100,yM=16,bM=new Set([`CA`,`CH`,`DO`,`FL`,`FO`,`LI`,`RI`,`RU`,`VA`]);async function xM(e,t,n){if(e.nomenclatureLabels||!e.mesh&&!e.model)return;let r=await tS(e.body.data.id,!1);if(!r.global?.has_nomenclature||e.nomenclatureLabels)return;let i=await NT(e.body.data.id);if(e.nomenclatureLabels)return;let a=i.filter(e=>!bM.has(e.typeCode));a.sort((e,t)=>{let n=e.diameterM>0?e.diameterM:vM;return(t.diameterM>0?t.diameterM:vM)-n});let o=a.length,s=e.model,c=new Float32Array(o),l;if(s){let t=await wM(s,a);if(e.nomenclatureLabels||e.model!==s)return;let n=Pj(e);for(let e=0;e<o;e++)c[e]=t.radii[e]*n;e.nomenclatureNormals=t.normals;let r=new qa,i=s.userData.centerOffset;i&&r.position.copy(i).multiplyScalar(-n),r.quaternion.copy(s.quaternion),e.group.add(r),e.nomenclatureAnchor=r,l=r}else{let t=e.mesh.geometry.parameters?.radius;if(!t)return;let n=null;if(r.global.displacement&&(n=await sO(e,e.body.data.id,r.global.displacement,bn(e.body.data),a.map(e=>({latRad:e.lat*mM,lonRad:e.lon*mM}))),e.nomenclatureLabels||!e.mesh))return;for(let e=0;e<o;e++)c[e]=t+(n?Q(n[e]):0);l=e.mesh}let u=Array(o),d=new Float32Array(o),f=new Float32Array(o).fill(-1),p=new Float32Array(o).fill(NaN),m=new Float32Array(o).fill(NaN),h=0;for(let e=0;e<o;e++){let r=a[e],i=r.diameterM>0?r.diameterM:vM;r.diameterM<=0&&h++;let o=document.createElement(`div`);o.className=`scene-feature-label`,o.dir=`auto`,o.textContent=r.name,o.dataset.featureId=String(r.featureId),FT(o,t),n&&fM(o,()=>n(r.featureId,r.lat,r.lon,i));let[s,f,p]=KD(r.lat*mM,r.lon*mM),m=c[e],g=new DT(o);g.position.set(m*s,m*f,m*p),l.add(g),u[e]=g,d[e]=i}h>0&&console.log(`[nomenclature] ${e.body.data.id}: ${h}/${o} features have no diameter — using ${vM}m fallback`),e.nomenclatureLabels=u,e.nomenclatureDiamsM=d,e.nomenclatureWidths=f,e.nomenclatureSX=p,e.nomenclatureSY=m,e.nomenclatureActiveIndex=-1}var SM=8,CM=new J;async function wM(e,t){let n=t.length,r=new Float32Array(n),i=new Float32Array(n*3),a=e.userData.halfExtents;for(let o=0;o<n;o++){o>0&&o%SM===0&&await new Promise(e=>setTimeout(e));let n=t[o].lat*mM,s=t[o].lon*mM,c=rM(e,n,s,CM);if(c!==null)r[o]=c;else{let[e,t,i]=KD(n,s),c=Math.max(a?.x??1,.001),l=Math.max(a?.y??1,.001),u=Math.max(a?.z??1,.001);r[o]=1/Math.sqrt((e/c)**2+(t/l)**2+(i/u)**2),CM.set(e/(c*c),t/(l*l),i/(u*u)).normalize()}i[o*3]=CM.x,i[o*3+1]=CM.y,i[o*3+2]=CM.z}return{radii:r,normals:i}}function TM(e,t){let n=e.nomenclatureLabels;if(!n)return;let r=t===null?null:String(t),i=-1;for(let e=0;e<n.length;e++){let t=n[e].element,a=t.dataset.featureId===r;t.classList.toggle(`scene-feature-label--active`,a),a&&(i=e)}e.nomenclatureActiveIndex=i}function EM(e){if(e.nomenclatureLabels){for(let t of e.nomenclatureLabels)t.element.remove(),t.parent?.remove(t);e.nomenclatureAnchor&&=(e.nomenclatureAnchor.parent?.remove(e.nomenclatureAnchor),null),e.nomenclatureNormals=void 0,e.nomenclatureLabels=null,e.nomenclatureDiamsM=void 0,e.nomenclatureWidths=void 0,e.nomenclatureSX=void 0,e.nomenclatureSY=void 0,e.nomenclatureActiveIndex=void 0}}var DM=new J,OM=new J,kM=new J,AM=new J,jM=new J,MM=new Xi,NM=new J,PM=.12;function FM(e,t,n,r,i,a){let o=e.nomenclatureLabels;if(!o)return;if(!t||n<128){for(let e of o)e.visible=!1;return}let s=e.nomenclatureDiamsM,c=e.nomenclatureSX,l=e.nomenclatureSY,u=e.nomenclatureActiveIndex??-1,d=o.length,f=!!e.clouds?.mesh.visible,p=n/(bn(e.body.data)*1e3),m=_M*Math.min(i,a);if(u<0&&(d===0||f||s[0]*p<gM)){for(let e of o)e.visible=!1;return}e.group.getWorldPosition(DM),r.getWorldPosition(OM);let h=OM.x-DM.x,g=OM.y-DM.y,_=OM.z-DM.z;AM.copy(DM).project(r);let v=h*h+g*g+_*_,y=e.radiusScene*e.radiusScene,b=(hM*(n/Math.sqrt(Math.max(1-y/v,1e-6))))**2,x=.5*i,S=.5*a,C=e.nomenclatureNormals;C&&e.nomenclatureAnchor&&e.nomenclatureAnchor.getWorldQuaternion(MM);for(let e=0;e<d;e++){let t=o[e],n=e===u,d=s[e]*p;if(f&&!n||!n&&(d<gM||d>m)){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}t.getWorldPosition(kM);let v=kM.x-DM.x,y=kM.y-DM.y,w=kM.z-DM.z;if(v*h+y*g+w*_<=v*v+y*y+w*w){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}if(C){NM.set(C[e*3],C[e*3+1],C[e*3+2]).applyQuaternion(MM);let n=h-v,r=g-y,i=_-w,a=Math.sqrt(n*n+r*r+i*i);if(NM.x*n+NM.y*r+NM.z*i<PM*a){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}}jM.copy(kM).project(r);let T=(jM.x-AM.x)*x,E=(jM.y-AM.y)*S;if(!n&&T*T+E*E>=b){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}t.visible=!0,c[e]=(jM.x*.5+.5)*i,l[e]=(-jM.y*.5+.5)*a}}var IM=[];function LM(e){let t=IM[e];return t||(t={left:0,right:0,y:0,h:0},IM[e]=t),t}function RM(e,t,n,r){let i=e.nomenclatureLabels[t];if(!i.visible)return r;let a=e.nomenclatureSX[t],o=e.nomenclatureSY[t];if(Number.isNaN(a)||Number.isNaN(o))return r;let s=e.nomenclatureWidths,c=s[t];if(c<0){let e=i.element.offsetWidth;e>0?(s[t]=e,c=e):c=60}let l=c*.5,u=a-l,d=a+l;if(!n)for(let e=0;e<r;e++){let t=IM[e],n=(t.h+yM)*.5;if(u<t.right&&d>t.left&&Math.abs(o-t.y)<n)return i.visible=!1,r}let f=LM(r);return f.left=u,f.right=d,f.y=o,f.h=yM,r+1}function zM(e){let t=e.nomenclatureLabels;if(!t)return;let n=e.nomenclatureActiveIndex??-1,r=0,i=FO,a=i.count;for(let e=0;e<a;e++){let t=i.rects[e],n=LM(r++);n.left=t.left,n.right=t.right,n.y=t.y,n.h=t.h}n>=0&&(r=RM(e,n,!0,r));for(let i=0;i<t.length;i++)i!==n&&(r=RM(e,i,!1,r))}var BM=1.002;function VM(e,t){let n=e?.referenceAltitudeKm??0;return n>0?1+n/t:BM}var HM=1e3;function UM(e,t,n){return Qt(`/v1/textures/${e}/${t}_${n}.webp`,`textures`)}async function WM(e,t,n){try{let r=await fetch(UM(e,t,n));if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.blob(),a=new ma(await createImageBitmap(i,{imageOrientation:`flipY`}));return a.flipY=!1,a.colorSpace=ri,a.anisotropy=16,a.needsUpdate=!0,a}catch(r){return console.warn(`Failed to load ${t} cloud texture for ${e} @ ${n}:`,r),null}}function GM(e){let t=parseInt(e.slice(0,4),10),n=parseInt(e.slice(4,6),10)-1,r=parseInt(e.slice(6,8),10),i=parseInt(e.slice(8,10),10);return Date.UTC(t,n,r,i)}var KM=10800*1e3;function qM(e,t,n){return n?n.some(([t,n])=>e>=GM(t)&&e<GM(n)+KM):e>=GM(t[0])&&e<=GM(t[t.length-1])}function JM(e,t,n){if(t.length===0)return;let r=jg(e).getTime(),i=GM(t[0]);if(qM(r,t,n)){let e=0,n=t.length;for(;e<n;){let i=e+n>>>1;GM(t[i])<=r?e=i+1:n=i}return t[Math.max(0,e-1)]}let a=jg(e).getUTCHours(),o=Math.round(a/3)*3%24,s=String(o).padStart(2,`0`),c=t.filter(e=>e.slice(8,10)===s);return c.length===0?r<i?t[0]:t[t.length-1]:r<i?c[0]:c[c.length-1]}async function YM(e,t,n,r,i=BM){let a=await WM(n.id,`low`,r);if(!a)return null;let o=XM(e,t,a,i);return o.id=n.id,o.availableTiers=n.tiers,o.availableFrames=n.frames,o.availableCoverage=n.coverage,o.textureTier=`low`,o.textureFrame=r,o}function XM(e,t,n,r=BM){let i=new Du({map:n,transparent:!0,depthWrite:!1}),a=new Us(new gu(t,64,64),i);return a.scale.setScalar(r),a.renderOrder=1,e.add(a),{mesh:a,material:i,id:``,availableTiers:[],availableFrames:[]}}async function ZM(e,t,n){if(e.textureLoading||e.textureTier===t&&e.textureFrame===n||!e.availableTiers.includes(t)||!e.availableFrames.includes(n))return;let r=performance.now();if(!(e.lastSwapMs!==void 0&&r-e.lastSwapMs<HM)){e.lastSwapMs=r,e.textureLoading=!0;try{let r=await WM(e.id,t,n);r&&(e.material.map?.dispose(),e.material.map=r,e.material.needsUpdate=!0,e.textureTier=t,e.textureFrame=n)}finally{e.textureLoading=!1}}}function QM(e){e.mesh.geometry.dispose(),e.material.map?.dispose(),e.material.dispose(),e.mesh.parent?.remove(e.mesh)}var $M=.2,eN=-.125,tN=.1,nN=Symbol(`night-lights-hook`);async function rN(e,t,n,r){let i=Qt(`/v1/textures/${t.id}/${n}.webp`,`textures`),a;try{a=await new Promise((e,t)=>{r.load(i,e,void 0,t)})}catch(e){return console.warn(`Failed to load night-lights map ${i}:`,e),null}return a.colorSpace=ri,iN(e,a),a}function iN(e,t){t.anisotropy=16,e.emissiveMap=t,e.emissive=new X(16777215);let n=e;if(!n[nN]){n[nN]=!0;let t=Mw();HS(e,`nightLights`,e=>{e.uniforms.uSunDir=t.uSunDir,e.uniforms.uNightIntensity={value:$M},e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
|
|
5562
|
+
`;function LA(e,t,n,r){let i=!Jb(t);HS(e,i?`photometryAirless`:`photometry`,e=>{let t=``,a=FA;i&&(e.uniforms.uPhotometrySunDir=r??Mw().uSunDir,Object.assign(e.uniforms,n),t=`uniform vec3 uPhotometrySunDir;\nuniform float uLunarWeightScale;\n${MA}`,a+=IA),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>\n${t}`).replace(`#include <lights_fragment_end>`,`#include <lights_fragment_end>\n${a}`)})}var RA=`#6b6b6b`;function zA(e){return .2126*e.r+.7152*e.g+.0722*e.b}function BA(e,t){return e?(2+PA(0,t??1))/3:2/3}var VA=new X;function HA(e){return e.color?(e.geometricAlbedo??zA(VA.set(e.color)))/BA(!Jb(e.id),e.lunarWeightScale):null}function UA(e,t=new X){let n=HA(e);return n===null?t.set(RA):(t.set(e.color),t.multiplyScalar(n/zA(t)))}function WA(e,t,n){if(e.color)n.set(e.color);else if(e.geometricAlbedo===void 0)return null;else{let e=t&&_A(t);e?n.copy(e):n.setRGB(1,1,1)}let r=e.geometricAlbedo??zA(n);return n.multiplyScalar(1.5*r/zA(n))}var GA=new Set([]);function KA(e){return e?.model_name?WC()&&e.render_quality!==`high`?`low-end-device`:e.displacement&&!GA.has(e.id)?`dem-preferred`:null:`no-bundle`}function qA(e,t,n,r,i){e.orientation=t,e.nutPrec=Rv(e.data.id,n),r&&r.bodies.dataVersion++,r?.credits.registerOrientation({bodyId:e.data.id,systemId:i??e.data.id,source:t.source,reference:t.reference})}var JA=48,YA=96,XA=JA*YA,ZA=1<<24,QA=Math.PI*2;function $A(e){let t=Math.floor((e+1)/2*JA);return Math.min(JA-1,Math.max(0,t))}function ej(e,t){let n=Math.atan2(-t,e);return(Math.floor((n+Math.PI)/QA*YA)%YA+YA)%YA}var tj=new J;function nj(e){let t=e.verts.length/3,n=new Int32Array(t),r=new Float32Array(t*3);for(let i=0;i<t;i++)tj.set(e.verts[i*3],e.verts[i*3+1],e.verts[i*3+2]).normalize(),r[i*3]=tj.x,r[i*3+1]=tj.y,r[i*3+2]=tj.z,n[i]=$A(tj.y)*YA+ej(tj.x,tj.z);return{cells:n,dirs:r}}function rj(e,t){let n=e.geometry.attributes.position,r=new Y().multiplyMatrices(t,e.matrixWorld),i=new Float32Array(n.count*3);for(let e=0;e<n.count;e++)tj.set(n.getX(e),n.getY(e),n.getZ(e)).applyMatrix4(r),i[e*3]=tj.x,i[e*3+1]=tj.y,i[e*3+2]=tj.z;return i}var ij=new J,aj=new J,oj=new J,sj=new J,cj=new J,lj=new J;function uj(e,t,n){return n.set(e[t*3],e[t*3+1],e[t*3+2])}function dj(e,t,n,r){return lj.crossVectors(e,n).dot(r)>=0&&lj.crossVectors(n,t).dot(r)>=0}function fj(e,t,n){sj.crossVectors(e,t);let r=sj.lengthSq();r<1e-18||(cj.set(0,1,0).addScaledVector(sj,-sj.y/r).normalize(),dj(e,t,cj,sj)&&(n.hi=Math.max(n.hi,$A(cj.y))),cj.negate(),dj(e,t,cj,sj)&&(n.lo=Math.min(n.lo,$A(cj.y))))}function pj(e,t,n,r){let i=(e.z*t.x-e.x*t.z)*r,a=(t.z*n.x-t.x*n.z)*r,o=(n.z*e.x-n.x*e.z)*r;return i>0&&a>0&&o>0||i<0&&a<0&&o<0}function mj(e,t){let n={lo:0,hi:0},r=[];for(let i=0;i<e.length;i++){let a=e[i],{cells:o,dirs:s}=t[i],c=new Int32Array(a.faces*4);r.push(c);for(let e=0;e<a.faces;e++){let t=a.idx?a.idx[e*3]:e*3,r=a.idx?a.idx[e*3+1]:e*3+1,i=a.idx?a.idx[e*3+2]:e*3+2,l=o[t],u=o[r],d=o[i],f=l/YA|0,p=u/YA|0,m=d/YA|0,h=l%YA,g=u%YA,_=d%YA,v=Math.min(f,p,m),y=Math.max(f,p,m),b=Math.min(h,g,_),x=Math.max(h,g,_),S=h+g+_-b-x,C=b+YA-x,w=b,T=x;S-b>=x-S&&S-b>C?(w=S,T=b+YA):x-S>C&&(w=x,T=S+YA),(y-v>1||T-w>1)&&(uj(s,t,ij),uj(s,r,aj),uj(s,i,oj),pj(ij,aj,oj,1)?(y=JA-1,w=0,T=YA-1):pj(ij,aj,oj,-1)?(v=0,w=0,T=YA-1):(n.lo=v,n.hi=y,fj(ij,aj,n),fj(aj,oj,n),fj(oj,ij,n),v=n.lo,y=n.hi)),c[e*4]=v,c[e*4+1]=y,c[e*4+2]=w,c[e*4+3]=T}}return r}function hj(e,t){for(let n=0;n<e.length;n++){let r=e[n];for(let e=0;e*4<r.length;e++){let i=n*ZA+e;for(let n=r[e*4];n<=r[e*4+1];n++)for(let a=r[e*4+2];a<=r[e*4+3];a++)t(n*YA+a%YA,i)}}}function gj(e){e.updateMatrixWorld(!0);let t=new Y().makeTranslation(-e.position.x,-e.position.y,-e.position.z),n=[];if(e.traverse(e=>{if(!(e instanceof Us))return;let r=e.geometry.attributes.position;if(!r)return;let i=e.geometry.index,a=(i?i.count:r.count)/3;a<1||a>=ZA||n.push({verts:rj(e,t),idx:i?i.array:null,faces:Math.floor(a)})}),!n.length)return null;let r=mj(n,n.map(nj)),i=new Int32Array(XA+1);hj(r,e=>i[e+1]++);for(let e=0;e<XA;e++)i[e+1]+=i[e];let a=new Int32Array(i[XA]),o=i.slice(0,XA);return hj(r,(e,t)=>{a[o[e]++]=t}),{meshes:n,start:i,slots:a}}var _j=new J,vj=new J,yj=new J,bj=new J,xj=new J,Sj=new J,Cj=new J;function wj(e,t,n){let r=e.idx?e.idx[t*3]:t*3,i=e.idx?e.idx[t*3+1]:t*3+1,a=e.idx?e.idx[t*3+2]:t*3+2;_j.set(e.verts[r*3],e.verts[r*3+1],e.verts[r*3+2]),vj.set(e.verts[i*3],e.verts[i*3+1],e.verts[i*3+2]),yj.set(e.verts[a*3],e.verts[a*3+1],e.verts[a*3+2]),bj.subVectors(vj,_j),xj.subVectors(yj,_j),Sj.crossVectors(n,xj);let o=bj.dot(Sj);if(Math.abs(o)<1e-12)return 0;let s=1/o,c=-_j.dot(Sj)*s;if(c<0||c>1)return 0;Cj.crossVectors(_j,bj).negate();let l=n.dot(Cj)*s;if(l<0||c+l>1)return 0;let u=xj.dot(Cj)*s;return u>0?u:0}function Tj(e,t,n,r){let{start:i,slots:a,meshes:o}=e;for(let e=i[t];e<i[t+1];e++){let t=a[e],i=wj(o[t/ZA|0],t%ZA,n);i>r&&(r=i)}return r}function Ej(e,t){let n=$A(t.y),r=ej(t.x,t.z),i=Tj(e,n*YA+r,t,0);if(i>0)return i;for(let a=-1;a<=1;a++){let o=n+a;if(!(o<0||o>=JA))for(let n=-1;n<=1;n++)i=Tj(e,o*YA+(r+n+YA)%YA,t,i)}if(i===0&&(n===0||n===JA-1)){let r=n===0?0:JA-2;for(let n=r;n<r+2;n++)for(let r=0;r<YA;r++)i=Tj(e,n*YA+r,t,i)}return i>0?i:null}function Dj(e){let t=e.data.objectType;return t===G.SPACECRAFT||t===G.DEBRIS||e.data.orbitalSource===W.SPICE_PROBE}var Oj=new qO;Oj.setMeshoptDecoder(qk);var kj=Oj,Aj=new Map;function jj(e){let t=Aj.get(e);return t||(t=fetch(Qt(`/v1/models/${e}/metadata.json`,`models`)).then(e=>e.json()),Aj.set(e,t),t.catch(()=>Aj.delete(e))),t}function Mj(e){if(a(e.exports.high.distribution))return`high`;if(e.exports.low&&a(e.exports.low.distribution))return`low`}function Nj(e){return e.credit??e.exports.high.credit}function Pj(e,t){return e.exports[t]?.credit??e.exports.high.credit}function Fj(e){return e.modelUnitOverride??e.radiusScene}var Ij=new Set;function Lj(e,t){let n=new qa;n.scale.setScalar(Fj(e)),n.userData.pickBody=e.body,n.add(t),e.group.add(n),e.modelRoot=n,e.model=t,Ij.add(n)}function Rj(e,t){let n=new Set;t.traverse(t=>{if(!(t instanceof Us))return;let r=Array.isArray(t.material)?t.material:[t.material];for(let t of r)!(t instanceof Du)||n.has(t)||(n.add(t),e.eclipseShadow=Ww(t,e.eclipseShadow??void 0))})}function zj(e,t,n){if(e.model)return Promise.resolve();if(e.modelLoadPromise)return e.modelLoadPromise;let r=(Dj(e.body)?Bj(e,t,n):Vj(e,n)).finally(()=>{e.modelLoadPromise===r&&(e.modelLoadPromise=void 0)});return e.modelLoadPromise=r,r}async function Bj(e,t,n){let r=e.modelLoadEpoch??0;e.mesh&&(e.mesh.visible=!1);try{let i=await tS(e.body.data.id,!1);e.body.pointing=i.global?.pointing;let a=i.global?.attitude;if(a&&(e.modelLoadEpoch??0)===r){let t=e.body.data.id.replace(/^probe-/,``);e.body.attitudeTrack=lA(t,a)}let o=i.global?.model_name;if(!o){e.noPhysical=`model`;return}if((e.modelLoadEpoch??0)!==r)return;e.mesh&&(e.mesh.visible=!1),Uj(e,!0);let s=await jj(o),c=Mj(s);if(!c){e.noPhysical=`model`;return}let l=await kj.loadAsync(Qt(`/v1/models/${o}/${c}.glb`,`models`));if((e.modelLoadEpoch??0)!==r||!e.mesh){dM(l.scene);return}let u=s.frame_map?OS(s.frame_map):null;e.body.modelBaseFrame=u??void 0;let d=Wj(l.scene,u),f=s.model_anchor?new J(...s.model_anchor):null;if(!Gj(d,f&&u?f.applyQuaternion(u):f)){dM(l.scene),e.noPhysical=`model`;return}if(uM(d),t.add(d),d.visible=!e.isCrashed,e.model=d,e.modelName=o,Uj(e,!1),s.scale_meters){let t=s.scale_meters/2e3;e.body.data.radiusKm=t*(s.body_span_ratio??1),e.radiusScene=Q(bn(e.body.data)),e.modelUnitOverride=s.body_span_ratio?Q(t):void 0}let p=Pj(s,c);n?.credits.registerModel({bodyId:e.body.data.id,source:p.url,organisation:p.name,license:p.license})}finally{e.model||Uj(e,!1)}}async function Vj(e,t){if(!$C().showShapeMesh)return;let n=e.modelLoadEpoch??0;try{let r=await tS(e.body.data.id,!1),i=r.global?.model_name;if(!i)return;let a=KA(r.global);if(a){console.info(`Skipping ${r.global?.render_quality??`unrated`} shape mesh for ${e.body.data.id}: ${a}`);return}r.global?.orientation&&!e.body.orientation&&qA(e.body,r.global.orientation,r.global.nut_prec,t);let o=jj(i),s=await kj.loadAsync(Qt(`/v1/models/${i}/high.glb`,`models`));if((e.modelLoadEpoch??0)!==n){dM(s.scene);return}let c;try{c=await o}catch(e){dM(s.scene),console.warn(`Failed to load shape-model metadata for ${i}:`,e);return}if(c.kind!==`shape_model`){dM(s.scene);return}let l=s.scene;if(!Gj(l)){dM(s.scene);return}l.userData.radialIndex=gj(l);let u=DA(UA(e.body.data));e.photometry??=NA(e.body.data.lunarWeightScale),LA(u,e.body.data.id,e.photometry),e.planetshine=bT(u,e.planetshine??void 0),OA(l,u);let d=e.mesh?e.mesh.material.map:null;d&&kA(l,d,UA(e.body.data),e.body.data.color),uM(l),Rj(e,l),c.true_scale&&(e.radiusScene=Q(c.true_scale.max_extent_km/2),Number.isFinite(e.body.data.radiusKm)&&e.body.data.radiusKm>0||(e.body.data.radiusKm=c.true_scale.max_extent_km/2),e.noPhysical&&(e.noPhysical=void 0,fA(e,`missing`,null))),Lj(e,l),e.modelName=i,e.mesh&&(e.mesh.visible=!1);let f=Nj(c),p=r.global?.model_source;t?.credits.registerModel({bodyId:e.body.data.id,source:f.url,organisation:f.name,license:f.license,provenance:p?.provenance,technique:p?.technique,archive:p?.archive,archiveUrl:p?.archive_url,mission:p?.mission&&{name:p.mission.name,id:p.mission.primary_id}})}finally{!e.model&&e.mesh&&(e.mesh.visible=!0)}}function Hj(e){e.modelLoadEpoch=(e.modelLoadEpoch??0)+1,e.modelLoadPromise=void 0,Uj(e,!1);let t=!Dj(e.body),n=e.model;if(!n){e.mesh&&t&&(e.mesh.visible=!0);return}e.modelRoot&&=(Ij.delete(e.modelRoot),e.modelRoot.removeFromParent(),null),n.parent?.remove(n),dM(n),e.model=null,e.modelName=void 0,e.body.pointing=void 0,e.body.attitudeTrack=void 0,e.body.modelBaseFrame=void 0,e.mesh&&t&&(e.mesh.visible=!0)}function Uj(e,t){if(t){if(e.loadingEl)return;let t=document.createElement(`div`);t.className=`scene-label__loader`,t.style.display=`none`,document.body.appendChild(t),e.loadingEl=t,e.loadingShown=!1}else e.loadingEl&&(e.loadingEl.remove(),e.loadingEl=null,e.loadingShown=void 0)}function Wj(e,t){if(!t)return e;let n=new qa;return e.quaternion.copy(t),n.add(e),n}function Gj(e,t=null){e.updateMatrixWorld(!0);let n=new _o().setFromObject(e,!0),r=n.getSize(new J),i=n.getCenter(new J),a=Math.max(r.x,r.y,r.z);if(a<=0)return!1;let o=2/a;e.userData.boxCenter=i.clone().multiplyScalar(o),t&&i.addScaledVector(t,a/2),e.scale.multiplyScalar(o),e.userData.fitScale=e.scale.x,e.position.copy(i).multiplyScalar(-o),e.userData.centerOffset=i.clone().multiplyScalar(o),e.userData.feetOffset=new J(i.x,n.min.y,i.z).multiplyScalar(o),e.userData.halfExtents=r.clone().multiplyScalar(o*.5);let s=Jj(e,r,o,e.userData.centerOffset);e.userData.occluderSpheres=s.spheres;let c=e.userData.centerOffset.length();return e.userData.minRadius=Math.max(0,s.minRadius-c),e.userData.maxRadius=e.userData.halfExtents.length()+c,!0}var Kj=8,qj=4096;function Jj(e,t,n,r){e.updateMatrixWorld(!0);let i=t.x>=t.y&&t.x>=t.z?0:t.y>=t.z?1:2,a=0;if(e.traverse(e=>{e instanceof Us&&(a+=e.geometry.attributes.position?.count??0)}),!a)return{spheres:[],minRadius:0};let o=Math.max(1,Math.floor(a/qj)),s=[],c=new J;e.traverse(t=>{if(!(t instanceof Us))return;let n=t.geometry.attributes.position;if(n)for(let r=0;r<n.count;r+=o)c.fromBufferAttribute(n,r).applyMatrix4(t.matrixWorld).sub(e.position),s.push(c.clone())});let l=t.getComponent(i)*n/2+Math.abs(r.getComponent(i)),u=Array.from({length:Kj},()=>[]);for(let e of s){let t=(e.getComponent(i)+l)/(2*l);u[Math.min(Kj-1,Math.max(0,Math.floor(t*Kj)))].push(e)}let d=1/0;for(let e of s)d=Math.min(d,e.length());let f=[];for(let e of u){if(e.length<3)continue;let t=new J;for(let n of e)t.add(n);t.divideScalar(e.length);let n=0;for(let r of e)n=Math.max(n,t.distanceToSquared(r));f.push({center:t,r:Math.sqrt(n)})}return{spheres:f,minRadius:Number.isFinite(d)?d:0}}var Yj=4,Xj=.05,Zj=new J,Qj=new J,$j=new J,eM=new J,tM=new Xi,nM=new J,rM=new Zd;function iM(e,t,n,r){let i=e.parent;if(!i)return null;i.updateMatrixWorld(!0);let a=i.getWorldScale(eM).x;if(!(a>0))return null;let o=Math.cos(t);Zj.set(o*Math.cos(n),Math.sin(t),-o*Math.sin(n)),Qj.copy(Zj).applyQuaternion(e.quaternion),$j.copy(e.position).addScaledVector(Qj,Yj),i.localToWorld($j),rM.set($j,Qj.negate());let s=rM.intersectObject(e,!0)[0];return s?(r&&s.face&&r.copy(s.face.normal).transformDirection(s.object.matrixWorld).applyQuaternion(tM.copy(e.quaternion).invert()),Math.max(Yj-s.distance/a,Xj)):null}function aM(e,t){let n=e?.model?.userData.radialIndex;if(!n)return null;let r=Ej(n,nM.set(t[0],t[1],t[2]));return r===null?null:xg(r*Fj(e))}function oM(e){return!!e?.model?.userData.radialIndex&&e.model.parent===e.modelRoot}function sM(e){if(!oM(e))return;let t=e.model.position,n=Fj(e);return[t.x*n,t.y*n,t.z*n]}function cM(e){if(oM(e))return xg(e.model.userData.maxRadius*Fj(e))}function lM(e){if(oM(e))return xg(e.model.userData.minRadius*Fj(e))}function uM(e){e.traverse(e=>{e instanceof Us&&(e.castShadow=!0,e.receiveShadow=!0)})}function dM(e){e.traverse(e=>{if(!(e instanceof Us))return;e.geometry?.dispose();let t=e.material,n=Array.isArray(t)?t:[t];for(let e of n)if(e){for(let t of Object.values(e))t instanceof ma&&t.dispose();e.dispose()}})}var fM=3;function pM(e,t,n=fM){let r=0,i=0;e.addEventListener(`pointerdown`,e=>{r=e.clientX,i=e.clientY}),e.addEventListener(`click`,e=>{e.stopPropagation();let a=e.clientX-r,o=e.clientY-i;a*a+o*o<=n*n&&t(e)})}function mM(e,t){if(e)return mn(e)?e.featureAnchor.hostId:t.get(e.data.id)?.isLanded?e.data.parentId:e.data.id}var hM=Math.PI/180,gM=.9,_M=24,vM=.2,yM=100,bM=16,xM=new Set([`CA`,`CH`,`DO`,`FL`,`FO`,`LI`,`RI`,`RU`,`VA`]);async function SM(e,t,n){if(e.nomenclatureLabels||!e.mesh&&!e.model)return;let r=await tS(e.body.data.id,!1);if(!r.global?.has_nomenclature||e.nomenclatureLabels)return;let i=await NT(e.body.data.id);if(e.nomenclatureLabels)return;let a=i.filter(e=>!xM.has(e.typeCode));a.sort((e,t)=>{let n=e.diameterM>0?e.diameterM:yM;return(t.diameterM>0?t.diameterM:yM)-n});let o=a.length,s=e.model,c=new Float32Array(o),l;if(s){let t=await TM(s,a);if(e.nomenclatureLabels||e.model!==s)return;let n=Fj(e);for(let e=0;e<o;e++)c[e]=t.radii[e]*n;e.nomenclatureNormals=t.normals;let r=new qa,i=s.userData.centerOffset;i&&r.position.copy(i).multiplyScalar(-n),r.quaternion.copy(s.quaternion),e.group.add(r),e.nomenclatureAnchor=r,l=r}else{let t=e.mesh.geometry.parameters?.radius;if(!t)return;let n=null;if(r.global.displacement&&(n=await cO(e,e.body.data.id,r.global.displacement,bn(e.body.data),a.map(e=>({latRad:e.lat*hM,lonRad:e.lon*hM}))),e.nomenclatureLabels||!e.mesh))return;for(let e=0;e<o;e++)c[e]=t+(n?Q(n[e]):0);l=e.mesh}let u=Array(o),d=new Float32Array(o),f=new Float32Array(o).fill(-1),p=new Float32Array(o).fill(NaN),m=new Float32Array(o).fill(NaN),h=0;for(let e=0;e<o;e++){let r=a[e],i=r.diameterM>0?r.diameterM:yM;r.diameterM<=0&&h++;let o=document.createElement(`div`);o.className=`scene-feature-label`,o.dir=`auto`,o.textContent=r.name,o.dataset.featureId=String(r.featureId),FT(o,t),n&&pM(o,()=>n(r.featureId,r.lat,r.lon,i));let[s,f,p]=qD(r.lat*hM,r.lon*hM),m=c[e],g=new DT(o);g.position.set(m*s,m*f,m*p),l.add(g),u[e]=g,d[e]=i}h>0&&console.log(`[nomenclature] ${e.body.data.id}: ${h}/${o} features have no diameter — using ${yM}m fallback`),e.nomenclatureLabels=u,e.nomenclatureDiamsM=d,e.nomenclatureWidths=f,e.nomenclatureSX=p,e.nomenclatureSY=m,e.nomenclatureActiveIndex=-1}var CM=8,wM=new J;async function TM(e,t){let n=t.length,r=new Float32Array(n),i=new Float32Array(n*3),a=e.userData.halfExtents;for(let o=0;o<n;o++){o>0&&o%CM===0&&await new Promise(e=>setTimeout(e));let n=t[o].lat*hM,s=t[o].lon*hM,c=iM(e,n,s,wM);if(c!==null)r[o]=c;else{let[e,t,i]=qD(n,s),c=Math.max(a?.x??1,.001),l=Math.max(a?.y??1,.001),u=Math.max(a?.z??1,.001);r[o]=1/Math.sqrt((e/c)**2+(t/l)**2+(i/u)**2),wM.set(e/(c*c),t/(l*l),i/(u*u)).normalize()}i[o*3]=wM.x,i[o*3+1]=wM.y,i[o*3+2]=wM.z}return{radii:r,normals:i}}function EM(e,t){let n=e.nomenclatureLabels;if(!n)return;let r=t===null?null:String(t),i=-1;for(let e=0;e<n.length;e++){let t=n[e].element,a=t.dataset.featureId===r;t.classList.toggle(`scene-feature-label--active`,a),a&&(i=e)}e.nomenclatureActiveIndex=i}function DM(e){if(e.nomenclatureLabels){for(let t of e.nomenclatureLabels)t.element.remove(),t.parent?.remove(t);e.nomenclatureAnchor&&=(e.nomenclatureAnchor.parent?.remove(e.nomenclatureAnchor),null),e.nomenclatureNormals=void 0,e.nomenclatureLabels=null,e.nomenclatureDiamsM=void 0,e.nomenclatureWidths=void 0,e.nomenclatureSX=void 0,e.nomenclatureSY=void 0,e.nomenclatureActiveIndex=void 0}}var OM=new J,kM=new J,AM=new J,jM=new J,MM=new J,NM=new Xi,PM=new J,FM=.12;function IM(e,t,n,r,i,a){let o=e.nomenclatureLabels;if(!o)return;if(!t||n<128){for(let e of o)e.visible=!1;return}let s=e.nomenclatureDiamsM,c=e.nomenclatureSX,l=e.nomenclatureSY,u=e.nomenclatureActiveIndex??-1,d=o.length,f=!!e.clouds?.mesh.visible,p=n/(bn(e.body.data)*1e3),m=vM*Math.min(i,a);if(u<0&&(d===0||f||s[0]*p<_M)){for(let e of o)e.visible=!1;return}e.group.getWorldPosition(OM),r.getWorldPosition(kM);let h=kM.x-OM.x,g=kM.y-OM.y,_=kM.z-OM.z;jM.copy(OM).project(r);let v=h*h+g*g+_*_,y=e.radiusScene*e.radiusScene,b=(gM*(n/Math.sqrt(Math.max(1-y/v,1e-6))))**2,x=.5*i,S=.5*a,C=e.nomenclatureNormals;C&&e.nomenclatureAnchor&&e.nomenclatureAnchor.getWorldQuaternion(NM);for(let e=0;e<d;e++){let t=o[e],n=e===u,d=s[e]*p;if(f&&!n||!n&&(d<_M||d>m)){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}t.getWorldPosition(AM);let v=AM.x-OM.x,y=AM.y-OM.y,w=AM.z-OM.z;if(v*h+y*g+w*_<=v*v+y*y+w*w){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}if(C){PM.set(C[e*3],C[e*3+1],C[e*3+2]).applyQuaternion(NM);let n=h-v,r=g-y,i=_-w,a=Math.sqrt(n*n+r*r+i*i);if(PM.x*n+PM.y*r+PM.z*i<FM*a){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}}MM.copy(AM).project(r);let T=(MM.x-jM.x)*x,E=(MM.y-jM.y)*S;if(!n&&T*T+E*E>=b){t.visible=!1,c[e]=NaN,l[e]=NaN;continue}t.visible=!0,c[e]=(MM.x*.5+.5)*i,l[e]=(-MM.y*.5+.5)*a}}var LM=[];function RM(e){let t=LM[e];return t||(t={left:0,right:0,y:0,h:0},LM[e]=t),t}function zM(e,t,n,r){let i=e.nomenclatureLabels[t];if(!i.visible)return r;let a=e.nomenclatureSX[t],o=e.nomenclatureSY[t];if(Number.isNaN(a)||Number.isNaN(o))return r;let s=e.nomenclatureWidths,c=s[t];if(c<0){let e=i.element.offsetWidth;e>0?(s[t]=e,c=e):c=60}let l=c*.5,u=a-l,d=a+l;if(!n)for(let e=0;e<r;e++){let t=LM[e],n=(t.h+bM)*.5;if(u<t.right&&d>t.left&&Math.abs(o-t.y)<n)return i.visible=!1,r}let f=RM(r);return f.left=u,f.right=d,f.y=o,f.h=bM,r+1}function BM(e){let t=e.nomenclatureLabels;if(!t)return;let n=e.nomenclatureActiveIndex??-1,r=0,i=IO,a=i.count;for(let e=0;e<a;e++){let t=i.rects[e],n=RM(r++);n.left=t.left,n.right=t.right,n.y=t.y,n.h=t.h}n>=0&&(r=zM(e,n,!0,r));for(let i=0;i<t.length;i++)i!==n&&(r=zM(e,i,!1,r))}var VM=1.002;function HM(e,t){let n=e?.referenceAltitudeKm??0;return n>0?1+n/t:VM}var UM=1e3;function WM(e,t,n){return Qt(`/v1/textures/${e}/${t}_${n}.webp`,`textures`)}async function GM(e,t,n){try{let r=await fetch(WM(e,t,n));if(!r.ok)throw Error(`HTTP ${r.status}`);let i=await r.blob(),a=new ma(await createImageBitmap(i,{imageOrientation:`flipY`}));return a.flipY=!1,a.colorSpace=ri,a.anisotropy=16,a.needsUpdate=!0,a}catch(r){return console.warn(`Failed to load ${t} cloud texture for ${e} @ ${n}:`,r),null}}function KM(e){let t=parseInt(e.slice(0,4),10),n=parseInt(e.slice(4,6),10)-1,r=parseInt(e.slice(6,8),10),i=parseInt(e.slice(8,10),10);return Date.UTC(t,n,r,i)}var qM=10800*1e3;function JM(e,t,n){return n?n.some(([t,n])=>e>=KM(t)&&e<KM(n)+qM):e>=KM(t[0])&&e<=KM(t[t.length-1])}function YM(e,t,n){if(t.length===0)return;let r=jg(e).getTime(),i=KM(t[0]);if(JM(r,t,n)){let e=0,n=t.length;for(;e<n;){let i=e+n>>>1;KM(t[i])<=r?e=i+1:n=i}return t[Math.max(0,e-1)]}let a=jg(e).getUTCHours(),o=Math.round(a/3)*3%24,s=String(o).padStart(2,`0`),c=t.filter(e=>e.slice(8,10)===s);return c.length===0?r<i?t[0]:t[t.length-1]:r<i?c[0]:c[c.length-1]}async function XM(e,t,n,r,i=VM){let a=await GM(n.id,`low`,r);if(!a)return null;let o=ZM(e,t,a,i);return o.id=n.id,o.availableTiers=n.tiers,o.availableFrames=n.frames,o.availableCoverage=n.coverage,o.textureTier=`low`,o.textureFrame=r,o}function ZM(e,t,n,r=VM){let i=new Du({map:n,transparent:!0,depthWrite:!1}),a=new Us(new gu(t,64,64),i);return a.scale.setScalar(r),a.renderOrder=1,e.add(a),{mesh:a,material:i,id:``,availableTiers:[],availableFrames:[]}}async function QM(e,t,n){if(e.textureLoading||e.textureTier===t&&e.textureFrame===n||!e.availableTiers.includes(t)||!e.availableFrames.includes(n))return;let r=performance.now();if(!(e.lastSwapMs!==void 0&&r-e.lastSwapMs<UM)){e.lastSwapMs=r,e.textureLoading=!0;try{let r=await GM(e.id,t,n);r&&(e.material.map?.dispose(),e.material.map=r,e.material.needsUpdate=!0,e.textureTier=t,e.textureFrame=n)}finally{e.textureLoading=!1}}}function $M(e){e.mesh.geometry.dispose(),e.material.map?.dispose(),e.material.dispose(),e.mesh.parent?.remove(e.mesh)}var eN=.2,tN=-.125,nN=.1,rN=Symbol(`night-lights-hook`);async function iN(e,t,n,r){let i=Qt(`/v1/textures/${t.id}/${n}.webp`,`textures`),a;try{a=await new Promise((e,t)=>{r.load(i,e,void 0,t)})}catch(e){return console.warn(`Failed to load night-lights map ${i}:`,e),null}return a.colorSpace=ri,aN(e,a),a}function aN(e,t){t.anisotropy=16,e.emissiveMap=t,e.emissive=new X(16777215);let n=e;if(!n[rN]){n[rN]=!0;let t=Mw();HS(e,`nightLights`,e=>{e.uniforms.uSunDir=t.uSunDir,e.uniforms.uNightIntensity={value:eN},e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
|
|
5563
5563
|
varying vec3 vNightOutwardWorld;`).replace(`#include <begin_vertex>`,`#include <begin_vertex>
|
|
5564
5564
|
vNightOutwardWorld = mat3(modelMatrix) * position;`),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
|
|
5565
5565
|
uniform float uNightIntensity;
|
|
@@ -5568,9 +5568,9 @@ vNightOutwardWorld = mat3(modelMatrix) * position;`),e.fragmentShader=e.fragment
|
|
|
5568
5568
|
// Modulate by unlit-side factor: 1 night, 0 day.
|
|
5569
5569
|
vec3 nightOutward = normalize(vNightOutwardWorld);
|
|
5570
5570
|
float nightDot = dot(nightOutward, uSunDir);
|
|
5571
|
-
float nightFactor = 1.0 - smoothstep(${
|
|
5571
|
+
float nightFactor = 1.0 - smoothstep(${tN.toFixed(2)}, ${nN.toFixed(2)}, nightDot);
|
|
5572
5572
|
totalEmissiveRadiance *= nightFactor * uNightIntensity;
|
|
5573
|
-
#endif`)})}e.needsUpdate=!0}function
|
|
5573
|
+
#endif`)})}e.needsUpdate=!0}function oN(e){e.emissiveMap&&(e.emissiveMap.dispose(),e.emissiveMap=null,e.emissive.setRGB(0,0,0),e.needsUpdate=!0)}var sN=.55,cN=Symbol(`specular-hook`);async function lN(e,t,n,r){let i=Qt(`/v1/textures/${t.id}/${n}.webp`,`textures`),a;try{a=await new Promise((e,t)=>{r.load(i,e,void 0,t)})}catch(e){return console.warn(`Failed to load specular map ${i}:`,e),null}a.anisotropy=16,e.roughnessMap=a;let o=e;return o[cN]||(o[cN]=!0,HS(e,`specular`,e=>{e.uniforms.uOceanRoughness={value:sN},e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>
|
|
5574
5574
|
uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`float roughnessFactor = roughness;
|
|
5575
5575
|
#ifdef USE_ROUGHNESSMAP
|
|
5576
5576
|
// Mask carries the fraction of the texel under water, so a
|
|
@@ -5579,7 +5579,7 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5579
5579
|
// roughnessmap sample.
|
|
5580
5580
|
vec4 texelRoughness = texture2D(roughnessMap, vRoughnessMapUv);
|
|
5581
5581
|
roughnessFactor = mix(roughness, uOceanRoughness, texelRoughness.g);
|
|
5582
|
-
#endif`)})),e.needsUpdate=!0,a}function
|
|
5582
|
+
#endif`)})),e.needsUpdate=!0,a}function uN(e){e.roughnessMap&&(e.roughnessMap.dispose(),e.roughnessMap=null,e.needsUpdate=!0)}var dN=6,fN=16,pN=1/Math.sqrt(Math.PI),mN={uAtmoTEnable:{value:1}};function hN(e){mN.uAtmoTEnable.value=+!!e}var gN=`
|
|
5583
5583
|
uniform vec3 uAtmoTBetaR; // Rayleigh β, per planet radius, (R,G,B)
|
|
5584
5584
|
uniform vec3 uAtmoTBetaMExt; // Mie extinction β, per planet radius
|
|
5585
5585
|
uniform vec3 uAtmoTBetaA; // absorber band β, per planet radius
|
|
@@ -5629,11 +5629,11 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5629
5629
|
vec3 atmoTSquash(vec3 v) {
|
|
5630
5630
|
return v + (uAtmoTStretch - 1.0) * dot(v, uAtmoTSpinAxis) * uAtmoTSpinAxis;
|
|
5631
5631
|
}
|
|
5632
|
-
`,
|
|
5632
|
+
`,_N=`
|
|
5633
5633
|
// Eclipse's uSunDir/uEclipseSelfPos are declared after this chunk's
|
|
5634
5634
|
// insertion point — same value refs re-bound under own names.
|
|
5635
5635
|
uniform vec3 uAtmoTSunDir;
|
|
5636
|
-
${
|
|
5636
|
+
${gN}
|
|
5637
5637
|
|
|
5638
5638
|
// Column (∫density above h) of the linear-tent absorber, in radii of
|
|
5639
5639
|
// surface-density-equivalent path — mirrors tentColumnAboveKm.
|
|
@@ -5683,9 +5683,9 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5683
5683
|
float tFar = -b + sqrt(d);
|
|
5684
5684
|
if (tFar <= 0.0) return vec3(1.0);
|
|
5685
5685
|
// Fragment sits inside the shell → the segment starts at the fragment.
|
|
5686
|
-
float dt = tFar / ${
|
|
5686
|
+
float dt = tFar / ${dN.toFixed(1)};
|
|
5687
5687
|
vec3 od = vec3(0.0);
|
|
5688
|
-
for (int i = 0; i < ${
|
|
5688
|
+
for (int i = 0; i < ${dN}; i++) {
|
|
5689
5689
|
float h = max(length(p + sd * (dt * (float(i) + 0.5))) - 1.0, 0.0);
|
|
5690
5690
|
od += vec3(
|
|
5691
5691
|
exp(-h / uAtmoTRayleighH),
|
|
@@ -5735,7 +5735,7 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5735
5735
|
// Sun height and airmass over a column of scale height h, in radii.
|
|
5736
5736
|
vec2 atmoTSkySun(float s, float h) {
|
|
5737
5737
|
float delta = sqrt(2.0 * h);
|
|
5738
|
-
float muH = ${
|
|
5738
|
+
float muH = ${pN.toFixed(7)} * delta;
|
|
5739
5739
|
float day = sqrt(s * s + muH * muH);
|
|
5740
5740
|
float night = muH * exp(-(s * s) / (delta * delta));
|
|
5741
5741
|
return s > 0.0 ? vec2(day, 1.0 / day) : vec2(night, 1.0 / muH);
|
|
@@ -5768,8 +5768,8 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5768
5768
|
vec3 atmoSkyDirect() {
|
|
5769
5769
|
return uAtmoTEnable < 0.5 ? vec3(1.0) : uAtmoTSkyDirect;
|
|
5770
5770
|
}
|
|
5771
|
-
`,
|
|
5772
|
-
${
|
|
5771
|
+
`,vN=`
|
|
5772
|
+
${gN}
|
|
5773
5773
|
|
|
5774
5774
|
vec3 atmoViewTint(vec3 worldPos) {
|
|
5775
5775
|
if (uAtmoTEnable < 0.5) return vec3(1.0);
|
|
@@ -5787,9 +5787,9 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5787
5787
|
float t1 = -b + s;
|
|
5788
5788
|
if (t1 <= 0.0) return vec3(1.0);
|
|
5789
5789
|
float t0 = max(-b - s, 0.0);
|
|
5790
|
-
float dt = (t1 - t0) / ${
|
|
5790
|
+
float dt = (t1 - t0) / ${dN.toFixed(1)};
|
|
5791
5791
|
vec3 od = vec3(0.0);
|
|
5792
|
-
for (int i = 0; i < ${
|
|
5792
|
+
for (int i = 0; i < ${dN}; i++) {
|
|
5793
5793
|
float h = max(length(p + rd * (t0 + dt * (float(i) + 0.5))) - 1.0, 0.0);
|
|
5794
5794
|
od += vec3(
|
|
5795
5795
|
exp(-h / uAtmoTRayleighH),
|
|
@@ -5802,7 +5802,7 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5802
5802
|
float lum = dot(t, vec3(0.2126, 0.7152, 0.0722));
|
|
5803
5803
|
return t / max(lum, 1e-4);
|
|
5804
5804
|
}
|
|
5805
|
-
`;function
|
|
5805
|
+
`;function yN(e){return{uAtmoTBetaR:{value:new J},uAtmoTBetaMExt:{value:new J},uAtmoTBetaA:{value:new J},uAtmoTRayleighH:{value:0},uAtmoTMieH:{value:0},uAtmoTAbsCenter:{value:0},uAtmoTAbsWidth:{value:0},uAtmoTTopR:{value:0},uAtmoTBlockR:{value:0},uAtmoTBakedComp:{value:0},uAtmoTRadiusScene:{value:0},uAtmoTEnable:e,uAtmoTSpinAxis:{value:new J(0,1,0)},uAtmoTStretch:{value:1},uAtmoTMeshR:{value:1},uAtmoTDeepTex:{value:xN()},uAtmoTDeepN:{value:1},uAtmoTDeepBaseR:{value:1},uAtmoTDeepSpanR:{value:0},uAtmoTDeepKmPerRadius:{value:1},uAtmoTDeepIrradiance:{value:0},uAtmoTDeepBlend:{value:0},uAtmoTBetaMScat:{value:new J},uAtmoTMieG:{value:new J},uAtmoTSkyDirect:{value:new J(1,1,1)},uAtmoTSkyGain:{value:new J}}}var bN=null;function xN(){return bN||(bN=new rc(new Uint8Array([255,255,255,255]),1,1),bN.needsUpdate=!0),bN}function SN(e,t,n,r){let i=r;r=$w(t,i),n=n*r/i;let a=e=>e*r,o=t.rayleighScatterPerKm,s=t.mieScatterPerKm,c=t.mieAbsorptionPerKm,l=t.absorptionPerKm;e.uAtmoTBetaR.value.set(a(o[0]),a(o[1]),a(o[2])),e.uAtmoTBetaMExt.value.set(a(s[0]+c[0]),a(s[1]+c[1]),a(s[2]+c[2])),e.uAtmoTBetaA.value.set(a(l[0]),a(l[1]),a(l[2])),e.uAtmoTRayleighH.value=t.rayleighScaleHeightKm/r,e.uAtmoTMieH.value=t.mieScaleHeightKm/r,e.uAtmoTAbsCenter.value=t.absorptionCenterKm/r,e.uAtmoTAbsWidth.value=t.absorptionWidthKm/r,e.uAtmoTTopR.value=1+t.topAltitudeKm/r,e.uAtmoTBlockR.value=1-6/r-.015,e.uAtmoTBakedComp.value=t.bakedCompensation,e.uAtmoTRadiusScene.value=n;let u=t.deepColumn;e.uAtmoTDeepTex.value=u?Zw(u):xN(),e.uAtmoTDeepN.value=u?.n??1,e.uAtmoTDeepBaseR.value=i/r,e.uAtmoTDeepSpanR.value=u?u.topKm/r:0,e.uAtmoTDeepKmPerRadius.value=r,e.uAtmoTBetaMScat.value.set(a(s[0]),a(s[1]),a(s[2])),e.uAtmoTMieG.value.fromArray(TN(t.miePhase)),ON(t,Math.max(e.uAtmoTMeshR.value-1,0)*r,r,e.uAtmoTSkyDirect.value,e.uAtmoTSkyGain.value)}function CN(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)}var wN=new WeakMap;function TN(e){let t=wN.get(e);if(t)return t;let n=e.length/3,r=[0,0,0];for(let t=0;t<3;t++){let i=0,a=0;for(let r=0;r<n-1;r++){let o=Math.PI*(r/(n-1))**2,s=Math.PI*((r+1)/(n-1))**2,c=e[t*n+r]*Math.sin(o),l=e[t*n+r+1]*Math.sin(s);i+=.5*(c+l)*(s-o),a+=.5*(c*Math.cos(o)+l*Math.cos(s))*(s-o)}r[t]=a/i}return wN.set(e,r),r}function EN(e,t){let n=Math.sqrt(2*t),r=pN*n;if(e>0){let t=Math.hypot(e,r);return[t,1/t]}return[r*Math.exp(-(e*e)/(n*n)),1/r]}function DN(e,t,n,r){let i=e.rayleighScaleHeightKm,a=e.mieScaleHeightKm,[o,s]=EN(r,i/n),[c,l]=EN(r,a/n),u=i*Math.exp(-t/i),d=a*Math.exp(-t/a),f=CN(t,e.absorptionCenterKm,e.absorptionWidthKm),p=TN(e.miePhase),m=[0,0,0];for(let t=0;t<3;t++){let n=e.rayleighScatterPerKm[t]*u,r=Math.exp(-(e.mieAbsorptionPerKm[t]*d*l+e.absorptionPerKm[t]*f*s)),i=Math.log(1-p[t]),a=i*(1.459+i*(.1595+i*.4129)),h=i*(.0783+i*(-.3824-i*.5874)),g=1-.5*Math.exp((a+h*c)*c);m[t]=(.5*o*(1-Math.exp(-.95*s*n))+c*g*Math.exp(-1.5*s*n)*(1-Math.exp(-l*d*e.mieScatterPerKm[t])))*r}return m}function ON(e,t,n,r,i){if(e.deepColumn||!e.groundAlbedo){r.set(1,1,1),i.set(0,0,0);return}let a=DN(e,t,n,1),o=e.rayleighScaleHeightKm*Math.exp(-t/e.rayleighScaleHeightKm),s=e.mieScaleHeightKm*Math.exp(-t/e.mieScaleHeightKm),c=CN(t,e.absorptionCenterKm,e.absorptionWidthKm);for(let t=0;t<3;t++){let n=e.rayleighScatterPerKm[t]*o+(e.mieScatterPerKm[t]+e.mieAbsorptionPerKm[t])*s+e.absorptionPerKm[t]*c,l=Math.exp(-n),u=Math.exp(-(1-e.bakedCompensation)*n);r.setComponent(t,l/(l+a[t])),i.setComponent(t,u/(l+a[t]))}}function kN(){return{...yN({value:0}),uAtmoTCenter:{value:new J}}}function AN(e,t,n,r,i,a,o=1){SN(e,t,r,i),e.uAtmoTCenter.value.copy(n),a?e.uAtmoTSpinAxis.value.copy(a):e.uAtmoTSpinAxis.value.set(0,1,0),e.uAtmoTStretch.value=o,e.uAtmoTEnable.value=1}function jN(e,t,n,r,i,a,o=1){let s={...yN(mN.uAtmoTEnable),uAtmoTSunDir:Mw().uSunDir,uAtmoTCenter:i.uEclipseSelfPos};return s.uAtmoTMeshR.value=o*r/$w(t,r),a&&(s.uAtmoTSpinAxis=a.material.uniforms.uSpinAxis,s.uAtmoTStretch=a.material.uniforms.uStretch),SN(s,t,n,r),HS(e,`sunTint`,e=>{Object.assign(e.uniforms,s),e.fragmentShader=e.fragmentShader.replace(`#include <common>`,`#include <common>\n${_N}`).replace(`#include <lights_fragment_end>`,`#include <lights_fragment_end>
|
|
5806
5806
|
vec3 atmoSunDir = uAtmoTSunDir;
|
|
5807
5807
|
vec3 atmoSunLight = vec3(0.0);
|
|
5808
5808
|
#if NUM_DIR_LIGHTS > 0
|
|
@@ -5829,7 +5829,7 @@ uniform float uOceanRoughness;`).replace(`#include <roughnessmap_fragment>`,`flo
|
|
|
5829
5829
|
#endif
|
|
5830
5830
|
if (atmoSky.g > 0.0) atmoSky *= eclipseFactorAt(vEclipseWorldPos, uEclipseSelfPos, uSunDir);
|
|
5831
5831
|
reflectedLight.indirectDiffuse += atmoSky * BRDF_Lambert(diffuseColor.rgb);
|
|
5832
|
-
#include <aomap_fragment>`)}),s}var
|
|
5832
|
+
#include <aomap_fragment>`)}),s}var MN=new J,NN=new J;function PN(e,t,n){return!t||n===1?e:e.addScaledVector(t,(n-1)*e.dot(t))}function FN(e,t,n,r,i,a,o,s=1){let c=i;i=$w(e,c),r=r*i/c;let l=PN(MN.copy(t).divideScalar(r),o,s),u=PN(NN.copy(n),o,s),d=u.length();u.divideScalar(d);let f=1+e.topAltitudeKm/i,p=1-6/i-.015,m=l.dot(u),h=l.lengthSq(),g=m*m-(h-p*p);if(g>0&&-m-Math.sqrt(g)>0||(g=m*m-(h-f*f),g<=0))return!1;let _=Math.sqrt(g),v=-m+_;if(v<=0)return!1;let y=Math.max(-m-_,0),b=(v-y)/fN,x=b*i/d,S=0,C=0,w=0;for(let t=0;t<fN;t++){let n=y+b*(t+.5),r=Math.max((Math.hypot(l.x+u.x*n,l.y+u.y*n,l.z+u.z*n)-1)*i,0);S+=Math.exp(-r/e.rayleighScaleHeightKm)*x,C+=Math.exp(-r/e.mieScaleHeightKm)*x,w+=Math.max(0,1-Math.abs(r-e.absorptionCenterKm)/e.absorptionWidthKm)*x}let T=e.rayleighScatterPerKm,E=e.mieScatterPerKm,D=e.mieAbsorptionPerKm,O=e.absorptionPerKm;return a.set(Math.exp(-(T[0]*S+(E[0]+D[0])*C+O[0]*w)),Math.exp(-(T[1]*S+(E[1]+D[1])*C+O[1]*w)),Math.exp(-(T[2]*S+(E[2]+D[2])*C+O[2]*w))),!0}var IN={specular:{meta:e=>e.specular,loaded:e=>e.specularMap!==null,async load(e,t,n,r){let i=await lN(n.material,t,`low`,r.textureLoader);if(i){if(e.specularMap){i.dispose();return}e.specularMap=i}},unload(e,t){t&&(uN(t.material),e.specularMap=null)}},night:{meta:e=>e.night,loaded:e=>e.emissiveMap!==null,async load(e,t,n,r){let i=await iN(n.material,t,`low`,r.textureLoader);if(i){if(e.emissiveMap){i.dispose();return}e.emissiveMap=i}},unload(e,t){t&&(oN(t.material),e.emissiveMap=null)}},topography:{meta:e=>e.displacement,loaded:e=>e.displacementMap!==null,enabled(e){return WC()?(console.info(`Low-end device: skipping DEM relief for ${e}`),!1):$C().showDisplacement},async load(e,t,n,r){let i=n.material,a=await AD(i,t,`low`,r.textureLoader,e.radiusScene);if(a){if(e.displacementMap){a.dispose();return}if(e.displacementMap=a,e.displacementMeta=t,e.displacementTier=`low`,!$C().showSelfShadow){e.selfShadow=null;return}e.reliefTiles=mD(i,t.tiles,bn(e.body.data)),e.selfShadow=OD(i,a,Q(t.scale_km),void 0,e.reliefTiles)}},unload(e,t){t&&(GD(t.material),e.displacementMap=null,e.displacementTier=void 0,kD(e.selfShadow),e.selfShadow=null,gD(e),e.reliefTiles=void 0)}},clouds:{meta:e=>e.clouds,loaded:e=>e.clouds!==null,async load(e,t,n,r){let i=YM(r.currentJd,t.frames,t.coverage);if(!i)return;let a=HM(e.atmosphere?.params,e.atmosphere?.surfaceRadiusKm??1),o=a===1.002?1:a,s=await XM(n,e.radiusScene,t,i,a);if(s){if(e.clouds){$M(s);return}e.eclipseShadow&&(Ww(s.material,e.eclipseShadow),e.atmosphere&&(e.sunTint??=[]).push(jN(s.material,e.atmosphere.params,e.radiusScene,e.atmosphere.surfaceRadiusKm,e.eclipseShadow,e.atmosphere,VM*o))),e.clouds=s}},unload(e){e.clouds&&=($M(e.clouds),null)}}},LN=Object.keys(IN);function RN(e,t,n,r,i,a){let o=IN[e],s=o.meta(r);return!s||!i.mesh||o.loaded(i)||o.enabled&&!o.enabled(t)?null:(a.ctx?.credits.registerImagery(e,t,n,s),o.load(i,s,i.mesh,a))}function zN(e,t,n,r,i){let a=[];for(let o of LN){let s=RN(o,e,t,n,r,i);s&&a.push(s)}return a}function BN(e,t){let n=IN[e];n.loaded(t)&&n.unload(t,t.mesh)}function VN(e){for(let t of LN)BN(t,e)}function HN(e){return e.button!==0||e.metaKey||e.ctrlKey||e.shiftKey||e.altKey}var UN=`M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z`,WN={flying:UN,landed:`M2.586 16.726A2 2 0 0 1 2 15.312V8.688a2 2 0 0 1 .586-1.414l4.688-4.688A2 2 0 0 1 8.688 2h6.624a2 2 0 0 1 1.414.586l4.688 4.688A2 2 0 0 1 22 8.688v6.624a2 2 0 0 1-.586 1.414l-4.688 4.688a2 2 0 0 1-1.414.586H8.688a2 2 0 0 1-1.414-.586z`};function GN(e,t){if(!e)return;let n=e.querySelector(`path`);n&&n.setAttribute(`d`,WN[t])}function KN(e,t,n,r){let i=document.createElement(`span`);i.className=`scene-label__name scene-label__name--${n}${r?` scene-label__name--large`:``}`,i.dir=`auto`,i.textContent=t;let a=e.firstElementChild;return a?a.after(i):e.appendChild(i),i}function qN(e,t,n,r){if(n===`none`||!t||!e.label)return;let i=e.label.element,a=i.querySelector(`.scene-label__name`);a?a.textContent=t:KN(i,t,n,r),pA(e)}function JN(e){let t=e.data.objectType;return Sn(t)||t===G.STAR||xn(t)||t===G.COMET||t===G.BARYCENTER||t===G.LAGRANGE_POINT?`major`:t===G.SPACECRAFT?`spacecraft`:t===G.DEBRIS?`debris`:`none`}function YN(e,t,n,r,i,a=!1,o,s=!1){if(n===`none`)return null;let c=document.createElement(`a`);c.className=`scene-label scene-label--${n}`,r&&(c.href=r),c.tabIndex=-1,c.draggable=!1,t&&c.setAttribute(`aria-label`,t);let l;if(n===`major`){let t=document.createElement(`div`);t.className=`scene-label__halo scene-label__halo--major`,t.style.border=`2px solid ${e}`,t.style.background=`${e}22`,l=t}else{let t=`http://www.w3.org/2000/svg`,r=document.createElementNS(t,`svg`);r.setAttribute(`viewBox`,`0 0 24 24`),r.setAttribute(`fill`,`${e}22`),r.setAttribute(`stroke`,e),r.setAttribute(`stroke-width`,`2`),r.setAttribute(`stroke-linejoin`,`round`),r.classList.add(`scene-label__halo`,`scene-label__halo--${n}`);let i=document.createElementNS(t,`path`);i.setAttribute(`d`,n===`debris`?`M3 5 L21 5 L12 21 Z`:UN),r.appendChild(i),l=r}c.appendChild(l);let u=0,d=0;c.addEventListener(`pointerdown`,e=>{u=e.clientX,d=e.clientY});let f=e=>{if(e.stopPropagation(),HN(e))return;e.preventDefault();let t=e.clientX-u,n=e.clientY-d;t*t+n*n<=9&&i()};t&&KN(c,t,n,a),s&&(l.style.transform=`scale(0.3)`),c.addEventListener(`click`,f),c.addEventListener(`mouseenter`,()=>{l.style.transform=`scale(1.15)`,document.body.style.cursor=`pointer`,o?.(!0)}),c.addEventListener(`mouseleave`,()=>{l.style.transform=s?`scale(0.3)`:``,CO(l),document.body.style.cursor=``,o?.(!1)});let p=new DT(c);return p.visible=!1,p}var XN=`
|
|
5833
5833
|
varying vec3 vTileOff;
|
|
5834
5834
|
uniform sampler2DArray uTileMap;
|
|
5835
5835
|
uniform sampler2DArray uTileMask;
|
|
@@ -5869,17 +5869,17 @@ vec3 tileColour( vec3 below ) {
|
|
|
5869
5869
|
}
|
|
5870
5870
|
return colour + ( 1.0 - covered ) * below;
|
|
5871
5871
|
}
|
|
5872
|
-
`,
|
|
5872
|
+
`,ZN=`
|
|
5873
5873
|
#ifdef USE_MAP
|
|
5874
5874
|
vec4 sampledDiffuseColor = texture2D( map, vMapUv );
|
|
5875
5875
|
sampledDiffuseColor.rgb = tileColour( sampledDiffuseColor.rgb );
|
|
5876
5876
|
diffuseColor *= sampledDiffuseColor;
|
|
5877
5877
|
#endif
|
|
5878
|
-
`;async function
|
|
5878
|
+
`;async function QN(e,t){let n=await fetch(e,{signal:t});if(!n.ok)throw Error(`tile ${n.status}`);let r=await createImageBitmap(await n.blob(),{imageOrientation:`flipY`,premultiplyAlpha:`none`,colorSpaceConversion:`none`}),i=new ma(r);return i.colorSpace=ri,i.flipY=!1,i.generateMipmaps=!1,{texture:i,release(){i.dispose(),r.close()}}}var $N={format:ir,type:Un,colorSpace:ri,load:QN};function eP(e){let t=jE($N);return HS(e,`surfaceTiles`,e=>{Object.assign(e.uniforms,{uTileMap:t.uniforms.map,uTileMask:t.uniforms.mask,uTileGrid:t.uniforms.grid,uTileWindow:t.uniforms.window,uTileHome:t.uniforms.home,uTileAnchor:t.uniforms.anchor,uTileFilter:t.uniforms.filter}),e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>
|
|
5879
5879
|
varying vec3 vTileOff;
|
|
5880
5880
|
uniform vec3 uTileAnchor;`).replace(`#include <begin_vertex>`,`#include <begin_vertex>
|
|
5881
|
-
vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`#include <map_pars_fragment>`,`#include <map_pars_fragment>\n${YN}`).replace(`#include <map_fragment>`,XN)}),{material:e,chain:t}}function eP(e){e.tileOverlay&&WE(e.tileOverlay.chain)}function tP(){return Kt()!==``&&vE()>0}function nP(e){return!!e&&e.max_level>=3&&tP()&&a(e.distribution)}function rP(e){return nP(e.surfaceTiles)&&!e.model&&!e.tileOverlay?.chain.dead}function iP(e,t,n,r,i,a){let o=e.surfaceTiles,s=e.mesh,c=s?.material,l,u=-1;if(o&&s&&c?.map&&i&&rP(e)){l=YE(s,t);let n=XE(e.tileOverlay?.chain,o,l);u=rE(e.radiusScene,e.cachedDist,r,n)}if(!o||!l||!c||u<3){e.tileOverlay&&GE(e.tileOverlay.chain,performance.now());return}e.tileOverlay&&e.tileOverlay.material!==c&&(eP(e),e.tileOverlay=void 0),QE((e.tileOverlay??=$N(c)).chain,o,ZE(o,vE()),u,l,e.radiusScene,o.frames?e.textureFrame:void 0,n,a)}var aP=[`low`,`medium`,`high`];function oP(e){return e===void 0?-1:aP.indexOf(e)}function sP(e,t){for(let n=e;n>=0;n--){let e=aP[n];if(t.includes(e))return e}}function cP(e,t,n){return Qt(n===void 0?`/v1/textures/${e}/${t}.webp`:`/v1/textures/${e}/${t}_${String(n).padStart(2,`0`)}.webp`,`textures`)}function lP(e,t){if(!(!t||t<2))return t===12?jg(e).getUTCMonth()+1:1}async function uP(e,t,n,r){if(!e.mesh||e.appearance?.surfaceOwned)return;let i=e.textureBundleId??e.body.data.id,a=e.textureLoadGen??=0;e.textureLoading=!0;try{let o=await new Promise((e,a)=>{r.load(cP(i,t,n),e,void 0,a)});if(!e.mesh||e.textureLoadGen!==a){o.dispose();return}let s=e.mesh.material,c=e.body.data;kA(s,o,c.color),e.model&&OA(e.model,o,HA(c),c.color),e.textureTier=t,e.textureFrame=n}catch(e){console.warn(`Failed to load ${t} texture for ${i}:`,e)}finally{e.textureLoading=!1}}function dP(e){if(!e.mesh||!e.photometry||Ej(e.body)||e.appearance?.surfaceOwned)return;let t=e.mesh.material;t.map||(HA(e.body.data,t.color),e.model&&OA(e.model,null,t.color))}function fP(e,t){if(!e.mesh)return;let{a:n,b:r,c:i}=t,a=Q(1)/e.radiusScene;if(e.mesh.scale.set(n*a,i*a,r*a),e.radiusScene=Q(Math.max(n,r,i)),e.semiAxesScene=[Q(n),Q(i),Q(r)],e.body.drawnRadii={a:n,b:r,c:i},e.atmosphere){let t=Math.max(n,r);fT(e.atmosphere,t,i,Q(t));for(let n of e.sunTint??[])xN(n,e.atmosphere.params,Q(t),t)}e.radiiApplied=!0}async function pP(e,t,n,r,i,a){if(e.textureTier||e.textureLoading)return;let s=await tS(e.body.data.id,!1);if(a?.bodies.orientationRead.add(e.body.data.id),!s.global)return;s.global.orientation&&!e.body.orientation&&KA(e.body,s.global.orientation,s.global.nut_prec,a),s.global.radii&&e.radiusScene>0&&!e.radiiApplied&&!s.global.displacement?.absolute_radius&&fP(e,s.global.radii),s.global.rings?.length&&await Promise.allSettled(TT(e.body.data.id,e.body.data.id,s.global.rings,s.global.radii,e,r,i,a));let c=e.body.data;if(c.color=s.global.sbdb?.color??s.global.color,c.geometricAlbedo=s.global.sbdb?.geometric_albedo??s.global.geometric_albedo,c.lunarWeightScale=s.global.lunar_weight_scale,e.photometry&&(e.photometry.uLunarWeightScale.value=c.lunarWeightScale??1),dP(e),!s.global.map_texture_available)return;let l=e.body.data.id,u=o([s.global.texture&&{...s.global.texture,id:l,tiers:void 0},...s.global.alternates??[]]);a&&u&&a.credits.registerImagery(`surface`,l,l,u),await LN(`topography`,l,l,s.global,e,{textureLoader:t,currentJd:n,ctx:a}),!(e.textureTier||e.textureLoading)&&$C().showSurfaceTexture&&u&&(e.textureBundleId=u.id===l?void 0:u.id,e.surfaceTiles=u.tiles,e.availableTiers??=u.tiers??[...aP],e.availableFrames=u.frames,await uP(e,`low`,lP(n,e.availableFrames),t))}async function mP(e){if(!e.label)return;let t=e.body.data;if(t.name)return;let n=await tS(t.id,t.hasLocalized),r=n.localized?.name??n.global?.name;r&&(t.name??=r,KN(e,r,qN(e.body),t.objectType===G.STAR||t.objectType===G.PLANET))}function hP(e){if(!e.mesh)return;e.textureLoadGen=(e.textureLoadGen??0)+1;let t=e.mesh.material;zN(`topography`,e),eP(e),t.map&&(t.map.dispose(),t.map=null,HA(e.body.data,t.color),t.needsUpdate=!0,e.model&&OA(e.model,null,t.color),e.textureTier=void 0)}async function gP(e,t,n,r){e.textureLoading||e.availableTiers?.includes(t)&&(e.textureTier===t&&e.textureFrame===n||await uP(e,t,n,r))}var _P=new Map;function vP(e){let t=_P.get(e);return t||(t=yP(e).finally(()=>_P.delete(e)),_P.set(e,t)),t}async function yP(e){let t=await Nv(`${Gt()}/v1/systems/${e}.json`);if(t.status===404)return null;if(!t.ok)throw Error(`systems/${e}.json: ${t.status}`);return t.json()}async function bP(e,t){let n=e.data.id,r=()=>!!e.orientation||t.bodies.orientationRead.has(n);if(r())return;let i=t.visibility.resolveSystemId(e),a=i?t.getBody(i):void 0,o=a?.data.objectType===G.BARYCENTER?a.data.id:null,s=o?(await vP(o))?.[n]:void 0,c=s?.orientation?null:await tS(n,!1);r()||(s?.orientation?KA(e,s.orientation,s.nut_prec,t,o):c?.global?.orientation&&KA(e,c.global.orientation,c.global.nut_prec,t),t.bodies.orientationRead.add(n),e.orientation&&t.bodies.orientationVersion++)}async function xP(e,t,n){let r=n.probeStore?.landingBodyAt(e,t),i=r?n.getBody(r):void 0;i&&await bP(i,n)}async function SP(e,t,n,r,i,a,s){let c=await vP(e).catch(()=>null);if(!c)return;let l=[];for(let[u,d]of Object.entries(c)){let c=o([d.texture&&{...d.texture,id:u,tiers:d.tiers},...d.alternates??[]]);c&&s?.credits.registerImagery(`surface`,u,e,c);let f=t.get(u);if(!f?.mesh)continue;s?.bodies.orientationRead.add(u);let p=f.body.data;if(p.color??=d.color,p.geometricAlbedo??=d.geometric_albedo,p.lunarWeightScale??=d.lunar_weight_scale,f.photometry&&(f.photometry.uLunarWeightScale.value=p.lunarWeightScale??1),dP(f),d.orientation&&(KA(f.body,d.orientation,d.nut_prec,s,e),SS(f.mesh,d.orientation,i,f.body.nutPrec)),d.radii&&f.radiusScene>0&&!f.radiiApplied&&!d.displacement?.absolute_radius&&fP(f,d.radii),c?.tiers?.length&&(f.availableTiers=c.tiers,f.availableFrames=c.frames,f.textureBundleId=c.id===u?void 0:c.id,f.surfaceTiles=c.tiles,!f.textureTier)){let e=lP(i,f.availableFrames);l.push(gP(f,`low`,e,r))}l.push(...RN(u,e,d,f,{textureLoader:r,currentJd:i,ctx:s})),d.rings?.length&&l.push(...TT(u,e,d.rings,d.radii,f,n,a,s))}await Promise.allSettled(l)}function CP(e,t,n,r){for(let n of t.values())if(r.visibility.isBodyInSystem(n.body,e)){if(hP(n),BN(n),n.terrainWindow&&n.mesh){n.terrainWindow=null;let e=Q(bn(n.body.data)),t=n.mesh.geometry;n.mesh.geometry=new gu(e,24,24),t.dispose(),n.currentSegments=24}for(let e of n.rings)e.planetShadow?.disable(),e.ringshine?.disable(),e.mesh.removeFromParent(),VC(e);n.rings=[],EM(n)}}var wP=2e3,TP=3;function EP(e,t){return`${e.zone}:${e.zoom??``}:${t}`}var DP=class{zones=[];latestDate;failureStreak=0;staleNotified=!1;staleCheckRunning=!1;retries=new Tx(()=>this.wakes++);wakes=0;wakeTimer;constructor(e,t,n,r){this.ctx=e,this.loader=n,this.latestDate=r;let i=Ag(r),a=$C().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 ox(o)){if(s.shape===`chunked`||s.shape===`parted`)continue;let o=a>0?Math.min(s.parts,a):s.parts;if(ex(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(tx(s)){let r={kind:`chunk`,zone:n,zoom:e,parts:o,parentIdType:t,zoomData:s,currentIdx:rx(s,i),inFlight:null,preloads:new Map};this.zones.push(r),this.preloadChunkNeighbors(r)}}}}recordSuccess(e){this.retries.clear(e),this.failureStreak=0}recordFailure(e){this.retries.fail(e),this.failureStreak++,!(this.failureStreak<TP||this.staleNotified||this.staleCheckRunning)&&(this.staleCheckRunning=!0,Vx().then(e=>{if(this.staleCheckRunning=!1,!e){this.failureStreak=0;return}this.staleNotified=!0,this.ctx.onDataStale?.()}))}wakeIn(e){this.wakeTimer??=setTimeout(()=>{this.wakeTimer=void 0,this.wakes++},e)}start(e,t){return e.inFlight=t.catch(()=>{}).finally(()=>{e.inFlight=null}),t}invalidateZone(e){for(let t of this.zones)t.zone!==e||t.kind!==`time`||(t.currentTime=``,t.lastLoadStartMs=-1/0,this.retries.clear(EP(t,ux(t.zoomData,this.latestDate))));this.tick(this.latestDate)}satelliteCoverage(e){let t=this.zones.find(e=>e.kind===`time`&&e.zone===`earth`);return t?px(t.zoomData,jg(e)):{kind:`covered`}}tick(e){this.latestDate=e;let t=Ag(e);for(let n of this.zones)if(n.kind===`time`){if(n.inFlight)continue;let t=ux(n.zoomData,e);if(t===n.currentTime||this.retries.waiting(EP(n,t)))continue;let r=performance.now(),i=n.lastLoadStartMs+wP-r;if(i>0){this.wakeIn(i);continue}n.lastLoadStartMs=r,this.start(n,this.loadTime(n,t,e))}else{for(;;){let e=rx(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=rx(n.zoomData,t);if(e===n.currentIdx||this.retries.waiting(EP(n,e)))continue;this.start(n,this.loadChunk(n,e))}}async ready(e=this.latestDate){this.latestDate=e;let t=Ag(e),n=this.zones.map(n=>this.zoneReady(n,e,t));this.ctx.chebStore&&n.push(this.ctx.chebStore.load(t)),this.ctx.probeStore&&n.push(this.ctx.probeStore.load(t));let r=(await Promise.allSettled(n)).find(e=>e.status===`rejected`);if(r)throw r.reason}async zoneReady(e,t,n){for(;e.inFlight;)await e.inFlight;if(e.kind===`time`){let n=ux(e.zoomData,t);if(n===e.currentTime)return;e.lastLoadStartMs=performance.now(),await this.start(e,this.loadTime(e,n,t))}else{let t=rx(e.zoomData,n);if(t===e.currentIdx)return;await this.start(e,this.loadChunk(e,t))}}wanted=new Set;want(e){this.wanted.add(e)}async ensureBody(e,t){let n=e.startsWith(`probe-`)?await this.ensureProbe(e,t):null;if(await this.ensureListed(e,t),n)throw n.error}async ensureListed(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).catch(()=>{}),this.ctx.getBody(e)))||await _S(this.ctx,e)}async ensureProbe(e,t){let n=this.ctx.probeStore;if(!n)return null;let r=Ag(t),i=nS(e);await n.load(r).catch(()=>{});let a=await i;a&&n.registerCarried(a);let o=n.stampedFitCenterAt(e,r),s=e=>e.then(()=>null,e=>({error:e})),c=o?await s(_S(this.ctx,o)):null,l=await s(xP(e,r,this.ctx)),u=c??l;if(this.ctx.getBody(e))return u;let d=await Dy(),f=this.loader.processProbes(n,t,d).find(t=>t.data.id===e);return f&&(this.ctx.bodies.addBodies([f]),this.ctx.credits.recordOrbitSources([f])),u}async loadTime(e,t,n){let r=e.currentTime;try{let i=mx(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(EP(e,t))}catch(n){throw console.warn(`zone-refresher: failed to refresh ${e.zone}@${t}:`,n),this.recordFailure(EP(e,t)),n}}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(EP(e,t))}catch(r){throw console.warn(`zone-refresher: ${e.zone} chunk reload failed (${n} → ${t}):`,r),e.currentIdx=n,this.recordFailure(EP(e,t)),r}}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=ux(e.zoomData,new Date(t.getTime()-n)),i=ux(e.zoomData,new Date(t.getTime()+n));for(let t of new Set([r,i])){if(t===e.currentTime)continue;let n=mx(e.zoomData,t,e.cap);for(let r=0;r<n;r++)Vb.prefetch(e.zone,e.zoom,r,t)}}},OP,kP=new Promise(e=>{OP=e});function AP(){OP()}var jP=Math.PI/180*vg,MP=new Xi().setFromAxisAngle(new J(0,0,1),-Math.PI/2).premultiply(new Xi().setFromAxisAngle(new J(0,1,0),Math.PI/2-jP)).premultiply(new Xi().setFromAxisAngle(new J(1,0,0),-Math.PI/2)),NP=[`px`,`nx`,`py`,`ny`,`pz`,`nz`];function PP(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 FP(e,t,n){return Qt(`/v1/textures/${e}/${t}_${n}.webp`,`textures`)}async function IP(e,t,n){return Promise.all(NP.map(async r=>{let i=await fetch(FP(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 LP=new Map,RP=new Map;function zP(e,t){return`${e}:${t}`}function BP(e,t,n,r=!0){let i=zP(e,t),a=LP.get(i);if(!a){let r=IP(e,t,n);a=r,LP.set(i,a),r.catch(()=>{LP.get(i)===r&&(LP.delete(i),RP.delete(i))})}return r&&RP.set(i,(RP.get(i)??0)+1),a}function VP(e,t,n){let r=zP(e,t),i=(RP.get(r)??1)-1;if(i>0){RP.set(r,i);return}RP.delete(r),LP.delete(r);for(let e of n)e.close()}function HP(e){let t=new Gc(e);return t.colorSpace=ri,t.needsUpdate=!0,t}function UP(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 WP(e){let t=UP(e);t&&BP(e.id,t,void 0,!1).catch(()=>{})}var GP=12e3;async function KP(e,t,n,r){let i=PP(n,Math.min(t.capabilities.maxTextureSize,SE().maxSkyboxFace));if(!i){console.warn(`Skybox ${n.id}: no tiers declared`);return}let a=UP(n),o={cube:null,bitmaps:null},s=!1;a&&a!==i&&BP(n.id,a).then(t=>{if(s||r()){VP(n.id,a,t);return}o.cube=HP(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),VP(n.id,a,o.bitmaps),o.bitmaps=null)};i!==a&&await Promise.race([kP,new Promise(e=>setTimeout(e,GP))]);let u;try{u=await BP(n.id,i,i===a?void 0:`low`)}catch(e){throw c=!0,r()?a&&o.bitmaps&&(o.cube?.dispose(),VP(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(),VP(n.id,i,u),a&&a!==i&&o.bitmaps&&VP(n.id,a,o.bitmaps);return}let d=HP(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 Gc&&f.dispose(),VP(n.id,i,u),a&&a!==i&&o.bitmaps&&VP(n.id,a,o.bitmaps)}async function qP(e,t,n,r=()=>!1){if(!n?.layers.skipped.has(`stars`))try{let i=await gx();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 KP(e,t,i.skybox,r)}catch(e){console.warn(`Failed to load skybox:`,e)}}var JP=13;function YP(e,t,n){let r=$C().maxPartsPerZone,i=[],a=[];for(let[o,s]of Object.entries(e.position.zones)){if(o===`major`||o===`moons`||o===`spacecraft`||ix(s)||n.skipsZone(o))continue;let e=s.parent_id_type??`naif`;for(let{zoom:n,data:c}of ox(s)){if(c.shape===`chunked`)continue;let s=ex(c)?ux(c,t):null,l=ex(c)&&s!==null?mx(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>=JP?a.push(r):i.push(r)}}}return{eager:i,deferred:a}}async function XP(e,t,n){let r=vx(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(`
|
|
5882
|
-
`));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 Fx(r);return await a.load(t),a}async function ZP(e,t,n,r,i,a){let o=[],s=null;e.chebStore&&(s=await Dy(),o.push(...t.processChebyshev(r,s))),e.probeStore&&(s??=await Dy(),a&&e.probeStore.registerCarried(a),o.push(...t.processProbes(e.probeStore,r,s)));let c=n.position.zones.major;if(c&&ax(c))for(let e of[1,2]){let n=c.zooms[String(e)];if(n&&$b(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?sx(l):void 0,d=u&&tx(u)?String(rx(u,i)):null;return u&&o.push(...await t.process(`moons`,null,0,d)),QP(o)}function QP(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 $P(e,t,n){performance.mark(`sm-load-start`),Av.reset();let r=Lv().catch(e=>console.warn(`scene-load: systems-global (GMs/nutation) failed to load:`,e)),i=qb().catch(e=>console.warn(`scene-load: atmospheres failed to load — rendering without shells:`,e)),a=Ag(t),o=gx();Dy().catch(()=>{}),o.then(t=>{let n=t.position.zones.moons;if(!n||e.layers.skipsZone(`moons`))return;let r=sx(n);r&&$b(r)&&Vb.prefetch(`moons`,null,0,null)}),o.then(t=>{t.skybox&&!e.layers.skipped.has(`stars`)&&WP(t.skybox)});let s=o.then(n=>YP(n,t,e.layers)),c=o.then(async t=>{let n=_x(t);for(let t of n.keys())e.layers.skipsZone(t)&&n.delete(t);if(n.size===0)return null;let r=new Ax(n);return await r.load(a),r}),l=o.then(t=>XP(t,a,e.layers)),u=nS(n),d=await o;Av.reach(`metadata`),e.chebStore=await c,e.probeStore=await l,Av.reach(`ephemeris`);let f=new Vb(e.chebStore);e.probeStore&&(e.probeStore.fitCenterUsable=t=>(e.chebStore?.has(t)??!1)||e.getBody(t)!==void 0),await r;let p=await ZP(e,f,d,t,a,await u);Av.reach(`majors`),await i,e.bodies.addBodies(p),e.credits.recordOrbitSources(p);let m=n?xP(n,a,e).catch(()=>{}):void 0,h=await Dy();Av.reach(`labels`);let g=!1,_=()=>{g=!0},v=()=>{let t=g;g=!1,e.bodies.flushMinor(t)};if(n&&!e.getBody(n)){let t=await hS(n,e);gS(e,t,h)>0&&_(),t.length>0&&v()}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 DP(e,d,f,t),n&&e.refresher.want(n)}catch(e){console.error(`scene-load: ZoneRefresher init failed; time-segmented zones stay empty:`,e)}await m,Av.reach(`done`),e.loading=!1,performance.mark(`sm-majors-done`);let{eager:y,deferred:b}=await s,x=y.filter(e=>e.zone===`small_body_moons`),S=y.filter(e=>e.zone!==`small_body_moons`);e.bodies.minorStreaming=!0;let C=setInterval(v,500),w=async(t,n,r)=>{e.credits.recordOrbitSource(n.source),n.rowCount!==0&&(await e.bodies.asteroidBucket(t,h).addChunk(n,r)>0&&_(),e.bodies.dirtyAsteroidZones.add(t))},T=(t,n)=>{e.credits.recordOrbitSources(n);let r=e.bodies.asteroidBucket(t,h);for(let e of n)r.addPlaceholder(e),_();e.bodies.dirtyAsteroidZones.add(t)},E=S.filter(e=>e.zone.startsWith(`small_bodies/`)),D=(e,t)=>n=>{console.warn(`scene-load: ${e} part ${t} failed (skipped):`,n)};try{await Promise.all([...E.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.fetchMinorColumns(e,t,n,r).then(t=>w(e,t,i)).catch(D(e,n))),e.refresher?.ready().then(_,e=>{console.warn(`scene-load: the data of the opening date is not all in:`,e)})]),await Promise.all(x.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.process(e,t,n,r,i).then(t=>T(e,t)).catch(D(e,n))))}finally{clearInterval(C),e.bodies.minorStreaming=!1,v(),performance.mark(`sm-minors-done`),AP()}if(b.length>0&&WC())console.info(`Low-end device: skipping ${b.length} deferred minor-belt parts to conserve memory`);else if(b.length>0){e.bodies.minorStreaming=!0;let t=setInterval(v,1e3);try{await Promise.all(b.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.fetchMinorColumns(e,t,n,r,`low`).then(t=>w(e,t,i)).catch(D(e,n))))}finally{clearInterval(t),e.bodies.minorStreaming=!1,v(),performance.mark(`sm-deferred-done`)}}}var eF=Wx(async()=>(await gx(),Qt(`/v1/membership/earth.json.gz`,`membership`)),{fetcher:Nv,onMissing:()=>({}),error:e=>`fetchEarthMembership: ${e.status} ${e.statusText}`});async function tF(e){let t=await eF();return new Set(t[e]??[])}function nF(e,t=s()){return $x(Yx,e,t)}var rF={[Jv]:new Set([G.SPACECRAFT]),[Yv]:new Set([G.DEBRIS])},iF=class{bodies=new Cv;credits=new An;layers=new ly;visibility=new Cy(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;groupFilterJob=Promise.resolve();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:py(this.bodies,e,n)}async load(e,t){try{await $P(this,e,t)}catch(e){throw this.fail(e),e}}fail(e){this.loading=!1,this.error=e instanceof Error?e.message:String(e),console.error(`[scene-load]`,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)}applyGroupFilter(e){if(e===this.currentGroupSlug)return this.groupFilterJob;this.currentGroupSlug=e;let t=this.installGroupFilter(e);return this.groupFilterJob=t,t.catch(()=>{this.groupFilterJob===t&&(this.currentGroupSlug=void 0)}),t}async installGroupFilter(e){if(e?.startsWith(`mission-`)){let t=await nF(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 ty())[e]??null: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=rF[e??``]??null;if(!$v(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 tF(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(ev),this.bodies.dirtySpacecraftGroups.add(ev),this.bodies.minorBodyVersion++,this.refresher?.invalidateZone(`earth`))}}resolveSmallBodyFilter(e,t,n){if(e===Kv)return{kind:`category`,category:`asteroid`};if(e===qv)return{kind:`category`,category:`comet`};if(e===null||t!==`small_body`)return null;if(e.startsWith(`class-`))return{kind:`class`,className:e.slice(Uv.length)};if(e.startsWith(`flag-`)){let t=e.slice(Wv.length),r=Xv[t];return r===void 0?null:{kind:`flag`,flag:t,mask:r,n:n??0}}return null}},aF=400,oF=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/Og*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(),aF))}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(Ag(new Date)),this.live=this.timeScale===1}get playing(){return this.timeScale!==0}get date(){return jg(this.jd)}setDate(e){this.jumpTo(Ag(e))}},sF={type:`change`},cF={type:`start`},lF={type:`end`},uF=new As,dF=new yc,fF=Math.cos(70*Yi.DEG2RAD),pF=new J,mF=2*Math.PI,hF={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},gF=1e-6,_F=class extends of{constructor(e,t=null){super(e,t),this.state=hF.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:jn.ROTATE,MIDDLE:jn.DOLLY,RIGHT:jn.PAN},this.touches={ONE:Mn.ROTATE,TWO:Mn.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 Xi,this._lastTargetPosition=new J,this._quat=new Xi().setFromUnitVectors(e.up,new J(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new ef,this._sphericalDelta=new ef,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=yF.bind(this),this._onPointerDown=vF.bind(this),this._onPointerUp=bF.bind(this),this._onContextMenu=DF.bind(this),this._onMouseWheel=CF.bind(this),this._onKeyDown=wF.bind(this),this._onTouchStart=TF.bind(this),this._onTouchMove=EF.bind(this),this._onMouseDown=xF.bind(this),this._onMouseMove=SF.bind(this),this._interceptControlDown=OF.bind(this),this._interceptControlUp=kF.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(sF),this.update(),this.state=hF.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;pF.copy(t).sub(this.target),pF.applyQuaternion(this._quat),this._spherical.setFromVector3(pF),this.autoRotate&&this.state===hF.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+=mF:n>Math.PI&&(n-=mF),r<-Math.PI?r+=mF:r>Math.PI&&(r-=mF),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(pF.setFromSpherical(this._spherical),pF.applyQuaternion(this._quatInverse),t.copy(this.target).add(pF),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=pF.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=pF.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):(uF.origin.copy(this.object.position),uF.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(uF.direction))<fF?this.object.lookAt(this.target):(dF.setFromNormalAndCoplanarPoint(this.object.up,this.target),uF.intersectPlane(dF,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)>gF||8*(1-this._lastQuaternion.dot(this.object.quaternion))>gF||this._lastTargetPosition.distanceToSquared(this.target)>gF?(this.dispatchEvent(sF),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?mF/60/60*this.autoRotateSpeed:mF/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){pF.setFromMatrixColumn(t,0),pF.multiplyScalar(-e),this._panOffset.add(pF)}_panUp(e,t){this.screenSpacePanning===!0?pF.setFromMatrixColumn(t,1):(pF.setFromMatrixColumn(t,0),pF.crossVectors(this.object.up,pF)),pF.multiplyScalar(e),this._panOffset.add(pF)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;pF.copy(r).sub(this.target);let i=pF.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(mF*this._rotateDelta.x/t.clientHeight),this._rotateUp(mF*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(mF*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(-mF*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(mF*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(-mF*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(mF*this._rotateDelta.x/t.clientHeight),this._rotateUp(mF*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 vF(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 yF(e){this.enabled!==!1&&(e.pointerType===`touch`?this._onTouchMove(e):this._onMouseMove(e))}function bF(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(lF),this.state=hF.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 xF(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 jn.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(e),this.state=hF.DOLLY;break;case jn.ROTATE:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=hF.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=hF.ROTATE}break;case jn.PAN:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=hF.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=hF.PAN}break;default:this.state=hF.NONE}this.state!==hF.NONE&&this.dispatchEvent(cF)}function SF(e){switch(this.state){case hF.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(e);break;case hF.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(e);break;case hF.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(e);break}}function CF(e){this.enabled===!1||this.enableZoom===!1||this.state!==hF.NONE||(e.preventDefault(),this.dispatchEvent(cF),this._handleMouseWheel(this._customWheelEvent(e)),this.dispatchEvent(lF))}function wF(e){this.enabled!==!1&&this._handleKeyDown(e)}function TF(e){switch(this._trackPointer(e),this._pointers.length){case 1:switch(this.touches.ONE){case Mn.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(e),this.state=hF.TOUCH_ROTATE;break;case Mn.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(e),this.state=hF.TOUCH_PAN;break;default:this.state=hF.NONE}break;case 2:switch(this.touches.TWO){case Mn.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(e),this.state=hF.TOUCH_DOLLY_PAN;break;case Mn.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(e),this.state=hF.TOUCH_DOLLY_ROTATE;break;default:this.state=hF.NONE}break;default:this.state=hF.NONE}this.state!==hF.NONE&&this.dispatchEvent(cF)}function EF(e){switch(this._trackPointer(e),this.state){case hF.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(e),this.update();break;case hF.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(e),this.update();break;case hF.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(e),this.update();break;case hF.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(e),this.update();break;default:this.state=hF.NONE}}function DF(e){this.enabled!==!1&&e.preventDefault()}function OF(e){e.key===`Control`&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}function kF(e){e.key===`Control`&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}var{PI:AF,sin:jF,cos:MF,asin:NF,atan2:PF,sqrt:FF}=Math,IF=180/AF,LF=AF/180;function RF(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 zF(e,t,n){let r=e[0]-t[0],i=e[1]-t[1],a=e[2]-t[2],o=FF(r*r+i*i+a*a);return n&&([r,i,a]=RF([r,i,a],n,!0)),{latitude:NF(i/o)*IF,longitude:n?PF(-a,r)*IF:PF(r,a)*IF,distance:o}}function BF(e,t,n,r,i){let a=t*LF,o=n*LF,s,c,l;if(i){let e=[r*MF(a)*MF(o),r*jF(a),-r*MF(a)*jF(o)];[s,c,l]=RF(e,i,!1)}else s=r*MF(a)*jF(o),c=r*jF(a),l=r*MF(a)*MF(o);return[e[0]+s,e[1]+c,e[2]+l]}function VF(e,t,n,r){let i=e[0]-t[0],a=e[2]-t[2],o=FF(i*i+a*a);o>0?(i/=o,a/=o):(i=0,a=1);let s=n*LF,c=MF(s);return[r*c*i,r*jF(s),r*c*a]}function HF(e){let t=(e+180)%360-180;return t<=-180?t+360:t}function UF(e,t,n){if(t===void 0&&n===void 0)return e;let r=t===void 0?-180:HF(t),i=r===180?-180:r,a=n===void 0?180:HF(n);if(i<=a?e>=i&&e<=a:e>=i||e<=a)return e;let o=(e,t)=>Math.abs(HF(e-t));return o(e,i)<=o(e,a)?i:a}var WF=ev;function GF(e,t){return`feature:${e}:${t}`}function KF(e,t){return{data:{id:GF(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 qF={name:`CopyShader`,uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
|
|
5881
|
+
vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`#include <map_pars_fragment>`,`#include <map_pars_fragment>\n${XN}`).replace(`#include <map_fragment>`,ZN)}),{material:e,chain:t}}function tP(e){e.tileOverlay&&WE(e.tileOverlay.chain)}function nP(){return Kt()!==``&&vE()>0}function rP(e){return!!e&&e.max_level>=3&&nP()&&a(e.distribution)}function iP(e){return rP(e.surfaceTiles)&&!e.model&&!e.tileOverlay?.chain.dead}function aP(e,t,n,r,i,a){let o=e.surfaceTiles,s=e.mesh,c=s?.material,l,u=-1;if(o&&s&&c?.map&&i&&iP(e)){l=XE(s,t);let n=ZE(e.tileOverlay?.chain,o,l);u=rE(e.radiusScene,e.cachedDist,r,n)}if(!o||!l||!c||u<3){e.tileOverlay&&KE(e.tileOverlay.chain,performance.now());return}e.tileOverlay&&e.tileOverlay.material!==c&&(tP(e),e.tileOverlay=void 0),$E((e.tileOverlay??=eP(c)).chain,o,QE(o,vE()),u,l,e.radiusScene,o.frames?e.textureFrame:void 0,n,a)}var oP=[`low`,`medium`,`high`];function sP(e){return e===void 0?-1:oP.indexOf(e)}function cP(e,t){for(let n=e;n>=0;n--){let e=oP[n];if(t.includes(e))return e}}function lP(e,t,n){return Qt(n===void 0?`/v1/textures/${e}/${t}.webp`:`/v1/textures/${e}/${t}_${String(n).padStart(2,`0`)}.webp`,`textures`)}function uP(e,t){if(!(!t||t<2))return t===12?jg(e).getUTCMonth()+1:1}async function dP(e,t,n,r){if(!e.mesh||e.appearance?.surfaceOwned)return;let i=e.textureBundleId??e.body.data.id,a=e.textureLoadGen??=0;e.textureLoading=!0;try{let o=await new Promise((e,a)=>{r.load(lP(i,t,n),e,void 0,a)});if(!e.mesh||e.textureLoadGen!==a){o.dispose();return}let s=e.mesh.material,c=e.body.data;AA(s,o,c.color),e.model&&kA(e.model,o,UA(c),c.color),e.textureTier=t,e.textureFrame=n}catch(e){console.warn(`Failed to load ${t} texture for ${i}:`,e)}finally{e.textureLoading=!1}}function fP(e){if(!e.mesh||!e.photometry||Dj(e.body)||e.appearance?.surfaceOwned)return;let t=e.mesh.material;t.map||(UA(e.body.data,t.color),e.model&&kA(e.model,null,t.color))}function pP(e,t){if(!e.mesh)return;let{a:n,b:r,c:i}=t,a=Q(1)/e.radiusScene;if(e.mesh.scale.set(n*a,i*a,r*a),e.radiusScene=Q(Math.max(n,r,i)),e.semiAxesScene=[Q(n),Q(i),Q(r)],e.body.drawnRadii={a:n,b:r,c:i},e.atmosphere){let t=Math.max(n,r);fT(e.atmosphere,t,i,Q(t));for(let n of e.sunTint??[])SN(n,e.atmosphere.params,Q(t),t)}e.radiiApplied=!0}async function mP(e,t,n,r,i,a){if(e.textureTier||e.textureLoading)return;let s=await tS(e.body.data.id,!1);if(a?.bodies.orientationRead.add(e.body.data.id),!s.global)return;s.global.orientation&&!e.body.orientation&&qA(e.body,s.global.orientation,s.global.nut_prec,a),s.global.radii&&e.radiusScene>0&&!e.radiiApplied&&!s.global.displacement?.absolute_radius&&pP(e,s.global.radii),s.global.rings?.length&&await Promise.allSettled(TT(e.body.data.id,e.body.data.id,s.global.rings,s.global.radii,e,r,i,a));let c=e.body.data;if(c.color=s.global.sbdb?.color??s.global.color,c.geometricAlbedo=s.global.sbdb?.geometric_albedo??s.global.geometric_albedo,c.lunarWeightScale=s.global.lunar_weight_scale,e.photometry&&(e.photometry.uLunarWeightScale.value=c.lunarWeightScale??1),fP(e),!s.global.map_texture_available)return;let l=e.body.data.id,u=o([s.global.texture&&{...s.global.texture,id:l,tiers:void 0},...s.global.alternates??[]]);a&&u&&a.credits.registerImagery(`surface`,l,l,u),await RN(`topography`,l,l,s.global,e,{textureLoader:t,currentJd:n,ctx:a}),!(e.textureTier||e.textureLoading)&&$C().showSurfaceTexture&&u&&(e.textureBundleId=u.id===l?void 0:u.id,e.surfaceTiles=u.tiles,e.availableTiers??=u.tiers??[...oP],e.availableFrames=u.frames,await dP(e,`low`,uP(n,e.availableFrames),t))}async function hP(e){if(!e.label)return;let t=e.body.data;if(t.name)return;let n=await tS(t.id,t.hasLocalized),r=n.localized?.name??n.global?.name;r&&(t.name??=r,qN(e,r,JN(e.body),t.objectType===G.STAR||t.objectType===G.PLANET))}function gP(e){if(!e.mesh)return;e.textureLoadGen=(e.textureLoadGen??0)+1;let t=e.mesh.material;BN(`topography`,e),tP(e),t.map&&(t.map.dispose(),t.map=null,UA(e.body.data,t.color),t.needsUpdate=!0,e.model&&kA(e.model,null,t.color),e.textureTier=void 0)}async function _P(e,t,n,r){e.textureLoading||e.availableTiers?.includes(t)&&(e.textureTier===t&&e.textureFrame===n||await dP(e,t,n,r))}var vP=new Map;function yP(e){let t=vP.get(e);return t||(t=bP(e).finally(()=>vP.delete(e)),vP.set(e,t)),t}async function bP(e){let t=await Nv(`${Gt()}/v1/systems/${e}.json`);if(t.status===404)return null;if(!t.ok)throw Error(`systems/${e}.json: ${t.status}`);return t.json()}async function xP(e,t){let n=e.data.id,r=()=>!!e.orientation||t.bodies.orientationRead.has(n);if(r())return;let i=t.visibility.resolveSystemId(e),a=i?t.getBody(i):void 0,o=a?.data.objectType===G.BARYCENTER?a.data.id:null,s=o?(await yP(o))?.[n]:void 0,c=s?.orientation?null:await tS(n,!1);r()||(s?.orientation?qA(e,s.orientation,s.nut_prec,t,o):c?.global?.orientation&&qA(e,c.global.orientation,c.global.nut_prec,t),t.bodies.orientationRead.add(n),e.orientation&&t.bodies.orientationVersion++)}async function SP(e,t,n){let r=n.probeStore?.landingBodyAt(e,t),i=r?n.getBody(r):void 0;i&&await xP(i,n)}async function CP(e,t,n,r,i,a,s){let c=await yP(e).catch(()=>null);if(!c)return;let l=[];for(let[u,d]of Object.entries(c)){let c=o([d.texture&&{...d.texture,id:u,tiers:d.tiers},...d.alternates??[]]);c&&s?.credits.registerImagery(`surface`,u,e,c);let f=t.get(u);if(!f?.mesh)continue;s?.bodies.orientationRead.add(u);let p=f.body.data;if(p.color??=d.color,p.geometricAlbedo??=d.geometric_albedo,p.lunarWeightScale??=d.lunar_weight_scale,f.photometry&&(f.photometry.uLunarWeightScale.value=p.lunarWeightScale??1),fP(f),d.orientation&&(qA(f.body,d.orientation,d.nut_prec,s,e),SS(f.mesh,d.orientation,i,f.body.nutPrec)),d.radii&&f.radiusScene>0&&!f.radiiApplied&&!d.displacement?.absolute_radius&&pP(f,d.radii),c?.tiers?.length&&(f.availableTiers=c.tiers,f.availableFrames=c.frames,f.textureBundleId=c.id===u?void 0:c.id,f.surfaceTiles=c.tiles,!f.textureTier)){let e=uP(i,f.availableFrames);l.push(_P(f,`low`,e,r))}l.push(...zN(u,e,d,f,{textureLoader:r,currentJd:i,ctx:s})),d.rings?.length&&l.push(...TT(u,e,d.rings,d.radii,f,n,a,s))}await Promise.allSettled(l)}function wP(e,t,n,r){for(let n of t.values())if(r.visibility.isBodyInSystem(n.body,e)){if(gP(n),VN(n),n.terrainWindow&&n.mesh){n.terrainWindow=null;let e=Q(bn(n.body.data)),t=n.mesh.geometry;n.mesh.geometry=new gu(e,24,24),t.dispose(),n.currentSegments=24}for(let e of n.rings)e.planetShadow?.disable(),e.ringshine?.disable(),e.mesh.removeFromParent(),VC(e);n.rings=[],DM(n)}}var TP=2e3,EP=3;function DP(e,t){return`${e.zone}:${e.zoom??``}:${t}`}var OP=class{zones=[];latestDate;failureStreak=0;staleNotified=!1;staleCheckRunning=!1;retries=new Tx(()=>this.wakes++);wakes=0;wakeTimer;constructor(e,t,n,r){this.ctx=e,this.loader=n,this.latestDate=r;let i=Ag(r),a=$C().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 ox(o)){if(s.shape===`chunked`||s.shape===`parted`)continue;let o=a>0?Math.min(s.parts,a):s.parts;if(ex(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(tx(s)){let r={kind:`chunk`,zone:n,zoom:e,parts:o,parentIdType:t,zoomData:s,currentIdx:rx(s,i),inFlight:null,preloads:new Map};this.zones.push(r),this.preloadChunkNeighbors(r)}}}}recordSuccess(e){this.retries.clear(e),this.failureStreak=0}recordFailure(e){this.retries.fail(e),this.failureStreak++,!(this.failureStreak<EP||this.staleNotified||this.staleCheckRunning)&&(this.staleCheckRunning=!0,Vx().then(e=>{if(this.staleCheckRunning=!1,!e){this.failureStreak=0;return}this.staleNotified=!0,this.ctx.onDataStale?.()}))}wakeIn(e){this.wakeTimer??=setTimeout(()=>{this.wakeTimer=void 0,this.wakes++},e)}start(e,t){return e.inFlight=t.catch(()=>{}).finally(()=>{e.inFlight=null}),t}invalidateZone(e){for(let t of this.zones)t.zone!==e||t.kind!==`time`||(t.currentTime=``,t.lastLoadStartMs=-1/0,this.retries.clear(DP(t,ux(t.zoomData,this.latestDate))));this.tick(this.latestDate)}satelliteCoverage(e){let t=this.zones.find(e=>e.kind===`time`&&e.zone===`earth`);return t?px(t.zoomData,jg(e)):{kind:`covered`}}tick(e){this.latestDate=e;let t=Ag(e);for(let n of this.zones)if(n.kind===`time`){if(n.inFlight)continue;let t=ux(n.zoomData,e);if(t===n.currentTime||this.retries.waiting(DP(n,t)))continue;let r=performance.now(),i=n.lastLoadStartMs+TP-r;if(i>0){this.wakeIn(i);continue}n.lastLoadStartMs=r,this.start(n,this.loadTime(n,t,e))}else{for(;;){let e=rx(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=rx(n.zoomData,t);if(e===n.currentIdx||this.retries.waiting(DP(n,e)))continue;this.start(n,this.loadChunk(n,e))}}async ready(e=this.latestDate){this.latestDate=e;let t=Ag(e),n=this.zones.map(n=>this.zoneReady(n,e,t));this.ctx.chebStore&&n.push(this.ctx.chebStore.load(t)),this.ctx.probeStore&&n.push(this.ctx.probeStore.load(t));let r=(await Promise.allSettled(n)).find(e=>e.status===`rejected`);if(r)throw r.reason}async zoneReady(e,t,n){for(;e.inFlight;)await e.inFlight;if(e.kind===`time`){let n=ux(e.zoomData,t);if(n===e.currentTime)return;e.lastLoadStartMs=performance.now(),await this.start(e,this.loadTime(e,n,t))}else{let t=rx(e.zoomData,n);if(t===e.currentIdx)return;await this.start(e,this.loadChunk(e,t))}}wanted=new Set;want(e){this.wanted.add(e)}async ensureBody(e,t){let n=e.startsWith(`probe-`)?await this.ensureProbe(e,t):null;if(await this.ensureListed(e,t),n)throw n.error}async ensureListed(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).catch(()=>{}),this.ctx.getBody(e)))||await _S(this.ctx,e)}async ensureProbe(e,t){let n=this.ctx.probeStore;if(!n)return null;let r=Ag(t),i=nS(e);await n.load(r).catch(()=>{});let a=await i;a&&n.registerCarried(a);let o=n.stampedFitCenterAt(e,r),s=e=>e.then(()=>null,e=>({error:e})),c=o?await s(_S(this.ctx,o)):null,l=await s(SP(e,r,this.ctx)),u=c??l;if(this.ctx.getBody(e))return u;let d=await Dy(),f=this.loader.processProbes(n,t,d).find(t=>t.data.id===e);return f&&(this.ctx.bodies.addBodies([f]),this.ctx.credits.recordOrbitSources([f])),u}async loadTime(e,t,n){let r=e.currentTime;try{let i=mx(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(DP(e,t))}catch(n){throw console.warn(`zone-refresher: failed to refresh ${e.zone}@${t}:`,n),this.recordFailure(DP(e,t)),n}}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(DP(e,t))}catch(r){throw console.warn(`zone-refresher: ${e.zone} chunk reload failed (${n} → ${t}):`,r),e.currentIdx=n,this.recordFailure(DP(e,t)),r}}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=ux(e.zoomData,new Date(t.getTime()-n)),i=ux(e.zoomData,new Date(t.getTime()+n));for(let t of new Set([r,i])){if(t===e.currentTime)continue;let n=mx(e.zoomData,t,e.cap);for(let r=0;r<n;r++)Vb.prefetch(e.zone,e.zoom,r,t)}}},kP,AP=new Promise(e=>{kP=e});function jP(){kP()}var MP=Math.PI/180*vg,NP=new Xi().setFromAxisAngle(new J(0,0,1),-Math.PI/2).premultiply(new Xi().setFromAxisAngle(new J(0,1,0),Math.PI/2-MP)).premultiply(new Xi().setFromAxisAngle(new J(1,0,0),-Math.PI/2)),PP=[`px`,`nx`,`py`,`ny`,`pz`,`nz`];function FP(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 IP(e,t,n){return Qt(`/v1/textures/${e}/${t}_${n}.webp`,`textures`)}async function LP(e,t,n){return Promise.all(PP.map(async r=>{let i=await fetch(IP(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 RP=new Map,zP=new Map;function BP(e,t){return`${e}:${t}`}function VP(e,t,n,r=!0){let i=BP(e,t),a=RP.get(i);if(!a){let r=LP(e,t,n);a=r,RP.set(i,a),r.catch(()=>{RP.get(i)===r&&(RP.delete(i),zP.delete(i))})}return r&&zP.set(i,(zP.get(i)??0)+1),a}function HP(e,t,n){let r=BP(e,t),i=(zP.get(r)??1)-1;if(i>0){zP.set(r,i);return}zP.delete(r),RP.delete(r);for(let e of n)e.close()}function UP(e){let t=new Gc(e);return t.colorSpace=ri,t.needsUpdate=!0,t}function WP(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 GP(e){let t=WP(e);t&&VP(e.id,t,void 0,!1).catch(()=>{})}var KP=12e3;async function qP(e,t,n,r){let i=FP(n,Math.min(t.capabilities.maxTextureSize,SE().maxSkyboxFace));if(!i){console.warn(`Skybox ${n.id}: no tiers declared`);return}let a=WP(n),o={cube:null,bitmaps:null},s=!1;a&&a!==i&&VP(n.id,a).then(t=>{if(s||r()){HP(n.id,a,t);return}o.cube=UP(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),HP(n.id,a,o.bitmaps),o.bitmaps=null)};i!==a&&await Promise.race([AP,new Promise(e=>setTimeout(e,KP))]);let u;try{u=await VP(n.id,i,i===a?void 0:`low`)}catch(e){throw c=!0,r()?a&&o.bitmaps&&(o.cube?.dispose(),HP(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(),HP(n.id,i,u),a&&a!==i&&o.bitmaps&&HP(n.id,a,o.bitmaps);return}let d=UP(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 Gc&&f.dispose(),HP(n.id,i,u),a&&a!==i&&o.bitmaps&&HP(n.id,a,o.bitmaps)}async function JP(e,t,n,r=()=>!1){if(!n?.layers.skipped.has(`stars`))try{let i=await gx();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 qP(e,t,i.skybox,r)}catch(e){console.warn(`Failed to load skybox:`,e)}}var YP=13;function XP(e,t,n){let r=$C().maxPartsPerZone,i=[],a=[];for(let[o,s]of Object.entries(e.position.zones)){if(o===`major`||o===`moons`||o===`spacecraft`||ix(s)||n.skipsZone(o))continue;let e=s.parent_id_type??`naif`;for(let{zoom:n,data:c}of ox(s)){if(c.shape===`chunked`)continue;let s=ex(c)?ux(c,t):null,l=ex(c)&&s!==null?mx(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>=YP?a.push(r):i.push(r)}}}return{eager:i,deferred:a}}async function ZP(e,t,n){let r=vx(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(`
|
|
5882
|
+
`));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 Fx(r);return await a.load(t),a}async function QP(e,t,n,r,i,a){let o=[],s=null;e.chebStore&&(s=await Dy(),o.push(...t.processChebyshev(r,s))),e.probeStore&&(s??=await Dy(),a&&e.probeStore.registerCarried(a),o.push(...t.processProbes(e.probeStore,r,s)));let c=n.position.zones.major;if(c&&ax(c))for(let e of[1,2]){let n=c.zooms[String(e)];if(n&&$b(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?sx(l):void 0,d=u&&tx(u)?String(rx(u,i)):null;return u&&o.push(...await t.process(`moons`,null,0,d)),$P(o)}function $P(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 eF(e,t,n){performance.mark(`sm-load-start`),Av.reset();let r=Lv().catch(e=>console.warn(`scene-load: systems-global (GMs/nutation) failed to load:`,e)),i=qb().catch(e=>console.warn(`scene-load: atmospheres failed to load — rendering without shells:`,e)),a=Ag(t),o=gx();Dy().catch(()=>{}),o.then(t=>{let n=t.position.zones.moons;if(!n||e.layers.skipsZone(`moons`))return;let r=sx(n);r&&$b(r)&&Vb.prefetch(`moons`,null,0,null)}),o.then(t=>{t.skybox&&!e.layers.skipped.has(`stars`)&&GP(t.skybox)});let s=o.then(n=>XP(n,t,e.layers)),c=o.then(async t=>{let n=_x(t);for(let t of n.keys())e.layers.skipsZone(t)&&n.delete(t);if(n.size===0)return null;let r=new Ax(n);return await r.load(a),r}),l=o.then(t=>ZP(t,a,e.layers)),u=nS(n),d=await o;Av.reach(`metadata`),e.chebStore=await c,e.probeStore=await l,Av.reach(`ephemeris`);let f=new Vb(e.chebStore);e.probeStore&&(e.probeStore.fitCenterUsable=t=>(e.chebStore?.has(t)??!1)||e.getBody(t)!==void 0),await r;let p=await QP(e,f,d,t,a,await u);Av.reach(`majors`),await i,e.bodies.addBodies(p),e.credits.recordOrbitSources(p);let m=n?SP(n,a,e).catch(()=>{}):void 0,h=await Dy();Av.reach(`labels`);let g=!1,_=()=>{g=!0},v=()=>{let t=g;g=!1,e.bodies.flushMinor(t)};if(n&&!e.getBody(n)){let t=await hS(n,e);gS(e,t,h)>0&&_(),t.length>0&&v()}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 OP(e,d,f,t),n&&e.refresher.want(n)}catch(e){console.error(`scene-load: ZoneRefresher init failed; time-segmented zones stay empty:`,e)}await m,Av.reach(`done`),e.loading=!1,performance.mark(`sm-majors-done`);let{eager:y,deferred:b}=await s,x=y.filter(e=>e.zone===`small_body_moons`),S=y.filter(e=>e.zone!==`small_body_moons`);e.bodies.minorStreaming=!0;let C=setInterval(v,500),w=async(t,n,r)=>{e.credits.recordOrbitSource(n.source),n.rowCount!==0&&(await e.bodies.asteroidBucket(t,h).addChunk(n,r)>0&&_(),e.bodies.dirtyAsteroidZones.add(t))},T=(t,n)=>{e.credits.recordOrbitSources(n);let r=e.bodies.asteroidBucket(t,h);for(let e of n)r.addPlaceholder(e),_();e.bodies.dirtyAsteroidZones.add(t)},E=S.filter(e=>e.zone.startsWith(`small_bodies/`)),D=(e,t)=>n=>{console.warn(`scene-load: ${e} part ${t} failed (skipped):`,n)};try{await Promise.all([...E.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.fetchMinorColumns(e,t,n,r).then(t=>w(e,t,i)).catch(D(e,n))),e.refresher?.ready().then(_,e=>{console.warn(`scene-load: the data of the opening date is not all in:`,e)})]),await Promise.all(x.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.process(e,t,n,r,i).then(t=>T(e,t)).catch(D(e,n))))}finally{clearInterval(C),e.bodies.minorStreaming=!1,v(),performance.mark(`sm-minors-done`),jP()}if(b.length>0&&WC())console.info(`Low-end device: skipping ${b.length} deferred minor-belt parts to conserve memory`);else if(b.length>0){e.bodies.minorStreaming=!0;let t=setInterval(v,1e3);try{await Promise.all(b.map(({zone:e,zoom:t,part:n,time:r,parentIdType:i})=>f.fetchMinorColumns(e,t,n,r,`low`).then(t=>w(e,t,i)).catch(D(e,n))))}finally{clearInterval(t),e.bodies.minorStreaming=!1,v(),performance.mark(`sm-deferred-done`)}}}var tF=Wx(async()=>(await gx(),Qt(`/v1/membership/earth.json.gz`,`membership`)),{fetcher:Nv,onMissing:()=>({}),error:e=>`fetchEarthMembership: ${e.status} ${e.statusText}`});async function nF(e){let t=await tF();return new Set(t[e]??[])}function rF(e,t=s()){return $x(Yx,e,t)}var iF={[Jv]:new Set([G.SPACECRAFT]),[Yv]:new Set([G.DEBRIS])},aF=class{bodies=new Cv;credits=new An;layers=new ly;visibility=new Cy(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;groupFilterJob=Promise.resolve();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:py(this.bodies,e,n)}async load(e,t){try{await eF(this,e,t)}catch(e){throw this.fail(e),e}}fail(e){this.loading=!1,this.error=e instanceof Error?e.message:String(e),console.error(`[scene-load]`,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)}applyGroupFilter(e){if(e===this.currentGroupSlug)return this.groupFilterJob;this.currentGroupSlug=e;let t=this.installGroupFilter(e);return this.groupFilterJob=t,t.catch(()=>{this.groupFilterJob===t&&(this.currentGroupSlug=void 0)}),t}async installGroupFilter(e){if(e?.startsWith(`mission-`)){let t=await rF(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 ty())[e]??null: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=iF[e??``]??null;if(!$v(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 nF(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(ev),this.bodies.dirtySpacecraftGroups.add(ev),this.bodies.minorBodyVersion++,this.refresher?.invalidateZone(`earth`))}}resolveSmallBodyFilter(e,t,n){if(e===Kv)return{kind:`category`,category:`asteroid`};if(e===qv)return{kind:`category`,category:`comet`};if(e===null||t!==`small_body`)return null;if(e.startsWith(`class-`))return{kind:`class`,className:e.slice(Uv.length)};if(e.startsWith(`flag-`)){let t=e.slice(Wv.length),r=Xv[t];return r===void 0?null:{kind:`flag`,flag:t,mask:r,n:n??0}}return null}},oF=400,sF=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/Og*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(),oF))}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(Ag(new Date)),this.live=this.timeScale===1}get playing(){return this.timeScale!==0}get date(){return jg(this.jd)}setDate(e){this.jumpTo(Ag(e))}},cF={type:`change`},lF={type:`start`},uF={type:`end`},dF=new As,fF=new yc,pF=Math.cos(70*Yi.DEG2RAD),mF=new J,hF=2*Math.PI,gF={NONE:-1,ROTATE:0,DOLLY:1,PAN:2,TOUCH_ROTATE:3,TOUCH_PAN:4,TOUCH_DOLLY_PAN:5,TOUCH_DOLLY_ROTATE:6},_F=1e-6,vF=class extends of{constructor(e,t=null){super(e,t),this.state=gF.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:jn.ROTATE,MIDDLE:jn.DOLLY,RIGHT:jn.PAN},this.touches={ONE:Mn.ROTATE,TWO:Mn.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 Xi,this._lastTargetPosition=new J,this._quat=new Xi().setFromUnitVectors(e.up,new J(0,1,0)),this._quatInverse=this._quat.clone().invert(),this._spherical=new ef,this._sphericalDelta=new ef,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=bF.bind(this),this._onPointerDown=yF.bind(this),this._onPointerUp=xF.bind(this),this._onContextMenu=OF.bind(this),this._onMouseWheel=wF.bind(this),this._onKeyDown=TF.bind(this),this._onTouchStart=EF.bind(this),this._onTouchMove=DF.bind(this),this._onMouseDown=SF.bind(this),this._onMouseMove=CF.bind(this),this._interceptControlDown=kF.bind(this),this._interceptControlUp=AF.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(cF),this.update(),this.state=gF.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;mF.copy(t).sub(this.target),mF.applyQuaternion(this._quat),this._spherical.setFromVector3(mF),this.autoRotate&&this.state===gF.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+=hF:n>Math.PI&&(n-=hF),r<-Math.PI?r+=hF:r>Math.PI&&(r-=hF),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(mF.setFromSpherical(this._spherical),mF.applyQuaternion(this._quatInverse),t.copy(this.target).add(mF),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=mF.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=mF.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):(dF.origin.copy(this.object.position),dF.direction.set(0,0,-1).transformDirection(this.object.matrix),Math.abs(this.object.up.dot(dF.direction))<pF?this.object.lookAt(this.target):(fF.setFromNormalAndCoplanarPoint(this.object.up,this.target),dF.intersectPlane(fF,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)>_F||8*(1-this._lastQuaternion.dot(this.object.quaternion))>_F||this._lastTargetPosition.distanceToSquared(this.target)>_F?(this.dispatchEvent(cF),this._lastPosition.copy(this.object.position),this._lastQuaternion.copy(this.object.quaternion),this._lastTargetPosition.copy(this.target),!0):!1}_getAutoRotationAngle(e){return e===null?hF/60/60*this.autoRotateSpeed:hF/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){mF.setFromMatrixColumn(t,0),mF.multiplyScalar(-e),this._panOffset.add(mF)}_panUp(e,t){this.screenSpacePanning===!0?mF.setFromMatrixColumn(t,1):(mF.setFromMatrixColumn(t,0),mF.crossVectors(this.object.up,mF)),mF.multiplyScalar(e),this._panOffset.add(mF)}_pan(e,t){let n=this.domElement;if(this.object.isPerspectiveCamera){let r=this.object.position;mF.copy(r).sub(this.target);let i=mF.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(hF*this._rotateDelta.x/t.clientHeight),this._rotateUp(hF*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(hF*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(-hF*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(hF*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(-hF*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(hF*this._rotateDelta.x/t.clientHeight),this._rotateUp(hF*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 yF(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 bF(e){this.enabled!==!1&&(e.pointerType===`touch`?this._onTouchMove(e):this._onMouseMove(e))}function xF(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(uF),this.state=gF.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 SF(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 jn.DOLLY:if(this.enableZoom===!1)return;this._handleMouseDownDolly(e),this.state=gF.DOLLY;break;case jn.ROTATE:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=gF.PAN}else{if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=gF.ROTATE}break;case jn.PAN:if(e.ctrlKey||e.metaKey||e.shiftKey){if(this.enableRotate===!1)return;this._handleMouseDownRotate(e),this.state=gF.ROTATE}else{if(this.enablePan===!1)return;this._handleMouseDownPan(e),this.state=gF.PAN}break;default:this.state=gF.NONE}this.state!==gF.NONE&&this.dispatchEvent(lF)}function CF(e){switch(this.state){case gF.ROTATE:if(this.enableRotate===!1)return;this._handleMouseMoveRotate(e);break;case gF.DOLLY:if(this.enableZoom===!1)return;this._handleMouseMoveDolly(e);break;case gF.PAN:if(this.enablePan===!1)return;this._handleMouseMovePan(e);break}}function wF(e){this.enabled===!1||this.enableZoom===!1||this.state!==gF.NONE||(e.preventDefault(),this.dispatchEvent(lF),this._handleMouseWheel(this._customWheelEvent(e)),this.dispatchEvent(uF))}function TF(e){this.enabled!==!1&&this._handleKeyDown(e)}function EF(e){switch(this._trackPointer(e),this._pointers.length){case 1:switch(this.touches.ONE){case Mn.ROTATE:if(this.enableRotate===!1)return;this._handleTouchStartRotate(e),this.state=gF.TOUCH_ROTATE;break;case Mn.PAN:if(this.enablePan===!1)return;this._handleTouchStartPan(e),this.state=gF.TOUCH_PAN;break;default:this.state=gF.NONE}break;case 2:switch(this.touches.TWO){case Mn.DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchStartDollyPan(e),this.state=gF.TOUCH_DOLLY_PAN;break;case Mn.DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchStartDollyRotate(e),this.state=gF.TOUCH_DOLLY_ROTATE;break;default:this.state=gF.NONE}break;default:this.state=gF.NONE}this.state!==gF.NONE&&this.dispatchEvent(lF)}function DF(e){switch(this._trackPointer(e),this.state){case gF.TOUCH_ROTATE:if(this.enableRotate===!1)return;this._handleTouchMoveRotate(e),this.update();break;case gF.TOUCH_PAN:if(this.enablePan===!1)return;this._handleTouchMovePan(e),this.update();break;case gF.TOUCH_DOLLY_PAN:if(this.enableZoom===!1&&this.enablePan===!1)return;this._handleTouchMoveDollyPan(e),this.update();break;case gF.TOUCH_DOLLY_ROTATE:if(this.enableZoom===!1&&this.enableRotate===!1)return;this._handleTouchMoveDollyRotate(e),this.update();break;default:this.state=gF.NONE}}function OF(e){this.enabled!==!1&&e.preventDefault()}function kF(e){e.key===`Control`&&(this._controlActive=!0,this.domElement.getRootNode().addEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}function AF(e){e.key===`Control`&&(this._controlActive=!1,this.domElement.getRootNode().removeEventListener(`keyup`,this._interceptControlUp,{passive:!0,capture:!0}))}var{PI:jF,sin:MF,cos:NF,asin:PF,atan2:FF,sqrt:IF}=Math,LF=180/jF,RF=jF/180;function zF(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 BF(e,t,n){let r=e[0]-t[0],i=e[1]-t[1],a=e[2]-t[2],o=IF(r*r+i*i+a*a);return n&&([r,i,a]=zF([r,i,a],n,!0)),{latitude:PF(i/o)*LF,longitude:n?FF(-a,r)*LF:FF(r,a)*LF,distance:o}}function VF(e,t,n,r,i){let a=t*RF,o=n*RF,s,c,l;if(i){let e=[r*NF(a)*NF(o),r*MF(a),-r*NF(a)*MF(o)];[s,c,l]=zF(e,i,!1)}else s=r*NF(a)*MF(o),c=r*MF(a),l=r*NF(a)*NF(o);return[e[0]+s,e[1]+c,e[2]+l]}function HF(e,t,n,r){let i=e[0]-t[0],a=e[2]-t[2],o=IF(i*i+a*a);o>0?(i/=o,a/=o):(i=0,a=1);let s=n*RF,c=NF(s);return[r*c*i,r*MF(s),r*c*a]}function UF(e){let t=(e+180)%360-180;return t<=-180?t+360:t}function WF(e,t,n){if(t===void 0&&n===void 0)return e;let r=t===void 0?-180:UF(t),i=r===180?-180:r,a=n===void 0?180:UF(n);if(i<=a?e>=i&&e<=a:e>=i||e<=a)return e;let o=(e,t)=>Math.abs(UF(e-t));return o(e,i)<=o(e,a)?i:a}var GF=ev;function KF(e,t){return`feature:${e}:${t}`}function qF(e,t){return{data:{id:KF(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 JF={name:`CopyShader`,uniforms:{tDiffuse:{value:null},opacity:{value:1}},vertexShader:`
|
|
5883
5883
|
|
|
5884
5884
|
varying vec2 vUv;
|
|
5885
5885
|
|
|
@@ -5902,7 +5902,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
5902
5902
|
gl_FragColor = opacity * texel;
|
|
5903
5903
|
|
|
5904
5904
|
|
|
5905
|
-
}`},
|
|
5905
|
+
}`},YF=class{constructor(){this.isPass=!0,this.enabled=!0,this.needsSwap=!0,this.clear=!1,this.renderToScreen=!1}setSize(){}render(){console.error(`THREE.Pass: .render() must be implemented in derived pass.`)}dispose(){}},XF=new Td(-1,1,1,-1,0,1),ZF=new class extends ts{constructor(){super(),this.setAttribute(`position`,new Uo([-1,3,0,-1,-1,0,3,-1,0],3)),this.setAttribute(`uv`,new Uo([0,2,0,0,2,0],2))}},QF=class{constructor(e){this._mesh=new Us(ZF,e)}dispose(){this._mesh.geometry.dispose()}render(e){e.render(this._mesh,XF)}get material(){return this._mesh.material}set material(e){this._mesh.material=e}},$F=class extends YF{constructor(e,t=`tDiffuse`){super(),this.textureID=t,this.uniforms=null,this.material=null,e instanceof Tu?(this.uniforms=e.uniforms,this.material=e):e&&(this.uniforms=Su.clone(e.uniforms),this.material=new Tu({name:e.name===void 0?`unspecified`:e.name,defines:Object.assign({},e.defines),uniforms:this.uniforms,vertexShader:e.vertexShader,fragmentShader:e.fragmentShader})),this._fsQuad=new QF(this.material)}render(e,t,n){this.uniforms[this.textureID]&&(this.uniforms[this.textureID].value=n.texture),this._fsQuad.material=this.material,this.renderToScreen?(e.setRenderTarget(null),this._fsQuad.render(e)):(e.setRenderTarget(t),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),this._fsQuad.render(e))}dispose(){this.material.dispose(),this._fsQuad.dispose()}},eI=class extends YF{constructor(e,t){super(),this.scene=e,this.camera=t,this.clear=!0,this.needsSwap=!1,this.inverse=!1}render(e,t,n){let r=e.getContext(),i=e.state;i.buffers.color.setMask(!1),i.buffers.depth.setMask(!1),i.buffers.color.setLocked(!0),i.buffers.depth.setLocked(!0);let a,o;this.inverse?(a=0,o=1):(a=1,o=0),i.buffers.stencil.setTest(!0),i.buffers.stencil.setOp(r.REPLACE,r.REPLACE,r.REPLACE),i.buffers.stencil.setFunc(r.ALWAYS,a,4294967295),i.buffers.stencil.setClear(o),i.buffers.stencil.setLocked(!0),e.setRenderTarget(n),this.clear&&e.clear(),e.render(this.scene,this.camera),e.setRenderTarget(t),this.clear&&e.clear(),e.render(this.scene,this.camera),i.buffers.color.setLocked(!1),i.buffers.depth.setLocked(!1),i.buffers.color.setMask(!0),i.buffers.depth.setMask(!0),i.buffers.stencil.setLocked(!1),i.buffers.stencil.setFunc(r.EQUAL,1,4294967295),i.buffers.stencil.setOp(r.KEEP,r.KEEP,r.KEEP),i.buffers.stencil.setLocked(!0)}},tI=class extends YF{constructor(){super(),this.needsSwap=!1}render(e){e.state.buffers.stencil.setLocked(!1),e.state.buffers.stencil.setTest(!1)}},nI=class{constructor(e,t){if(this.renderer=e,this._pixelRatio=e.getPixelRatio(),t===void 0){let n=e.getSize(new q);this._width=n.width,this._height=n.height,t=new _a(this._width*this._pixelRatio,this._height*this._pixelRatio,{type:Xn}),t.texture.name=`EffectComposer.rt1`}else this._width=t.width,this._height=t.height;this.renderTarget1=t,this.renderTarget2=t.clone(),this.renderTarget2.texture.name=`EffectComposer.rt2`,this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2,this.renderToScreen=!0,this.passes=[],this.copyPass=new $F(JF),this.copyPass.material.blending=0,this.timer=new Id}swapBuffers(){let e=this.readBuffer;this.readBuffer=this.writeBuffer,this.writeBuffer=e}addPass(e){this.passes.push(e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}insertPass(e,t){this.passes.splice(t,0,e),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}removePass(e){let t=this.passes.indexOf(e);t!==-1&&this.passes.splice(t,1)}isLastEnabledPass(e){for(let t=e+1;t<this.passes.length;t++)if(this.passes[t].enabled)return!1;return!0}render(e){this.timer.update(),e===void 0&&(e=this.timer.getDelta());let t=this.renderer.getRenderTarget(),n=!1;for(let t=0,r=this.passes.length;t<r;t++){let r=this.passes[t];if(r.enabled!==!1){if(r.renderToScreen=this.renderToScreen&&this.isLastEnabledPass(t),r.render(this.renderer,this.writeBuffer,this.readBuffer,e,n),r.needsSwap){if(n){let t=this.renderer.getContext(),n=this.renderer.state.buffers.stencil;n.setFunc(t.NOTEQUAL,1,4294967295),this.copyPass.render(this.renderer,this.writeBuffer,this.readBuffer,e),n.setFunc(t.EQUAL,1,4294967295)}this.swapBuffers()}eI!==void 0&&(r instanceof eI?n=!0:r instanceof tI&&(n=!1))}}this.renderer.setRenderTarget(t)}reset(e){if(e===void 0){let t=this.renderer.getSize(new q);this._pixelRatio=this.renderer.getPixelRatio(),this._width=t.width,this._height=t.height,e=this.renderTarget1.clone(),e.setSize(this._width*this._pixelRatio,this._height*this._pixelRatio)}this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.renderTarget1=e,this.renderTarget2=e.clone(),this.writeBuffer=this.renderTarget1,this.readBuffer=this.renderTarget2}setSize(e,t){this._width=e,this._height=t;let n=this._width*this._pixelRatio,r=this._height*this._pixelRatio;this.renderTarget1.setSize(n,r),this.renderTarget2.setSize(n,r);for(let e=0;e<this.passes.length;e++)this.passes[e].setSize(n,r)}setPixelRatio(e){this._pixelRatio=e,this.setSize(this._width,this._height)}dispose(){this.renderTarget1.dispose(),this.renderTarget2.dispose(),this.copyPass.dispose()}},rI=class extends YF{constructor(e,t,n=null,r=null,i=null){super(),this.scene=e,this.camera=t,this.overrideMaterial=n,this.clearColor=r,this.clearAlpha=i,this.clear=!0,this.clearDepth=!1,this.needsSwap=!1,this.isRenderPass=!0,this._oldClearColor=new X}render(e,t,n){let r=e.autoClear;e.autoClear=!1;let i,a;this.overrideMaterial!==null&&(a=this.scene.overrideMaterial,this.scene.overrideMaterial=this.overrideMaterial),this.clearColor!==null&&(e.getClearColor(this._oldClearColor),e.setClearColor(this.clearColor,e.getClearAlpha())),this.clearAlpha!==null&&(i=e.getClearAlpha(),e.setClearAlpha(this.clearAlpha)),this.clearDepth==1&&e.clearDepth(),e.setRenderTarget(this.renderToScreen?null:n),this.clear===!0&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),e.render(this.scene,this.camera),this.clearColor!==null&&e.setClearColor(this._oldClearColor),this.clearAlpha!==null&&e.setClearAlpha(i),this.overrideMaterial!==null&&(this.scene.overrideMaterial=a),e.autoClear=r}},iI={name:`LuminosityHighPassShader`,uniforms:{tDiffuse:{value:null},luminosityThreshold:{value:1},smoothWidth:{value:1},defaultColor:{value:new X(0)},defaultOpacity:{value:0}},vertexShader:`
|
|
5906
5906
|
|
|
5907
5907
|
varying vec2 vUv;
|
|
5908
5908
|
|
|
@@ -5934,7 +5934,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
5934
5934
|
|
|
5935
5935
|
gl_FragColor = mix( outputColor, texel, alpha );
|
|
5936
5936
|
|
|
5937
|
-
}`},
|
|
5937
|
+
}`},aI=class e extends YF{constructor(e,t=1,n,r){super(),this.strength=t,this.radius=n,this.threshold=r,this.resolution=e===void 0?new q(256,256):new q(e.x,e.y),this.clearColor=new X(0,0,0),this.needsSwap=!1,this.renderTargetsHorizontal=[],this.renderTargetsVertical=[],this.nMips=5;let i=Math.round(this.resolution.x/2),a=Math.round(this.resolution.y/2);this.renderTargetBright=new _a(i,a,{type:Xn}),this.renderTargetBright.texture.name=`UnrealBloomPass.bright`,this.renderTargetBright.texture.generateMipmaps=!1;for(let e=0;e<this.nMips;e++){let t=new _a(i,a,{type:Xn});t.texture.name=`UnrealBloomPass.h`+e,t.texture.generateMipmaps=!1,this.renderTargetsHorizontal.push(t);let n=new _a(i,a,{type:Xn});n.texture.name=`UnrealBloomPass.v`+e,n.texture.generateMipmaps=!1,this.renderTargetsVertical.push(n),i=Math.round(i/2),a=Math.round(a/2)}let o=iI;this.highPassUniforms=Su.clone(o.uniforms),this.highPassUniforms.luminosityThreshold.value=r,this.highPassUniforms.smoothWidth.value=.01,this.materialHighPassFilter=new Tu({uniforms:this.highPassUniforms,vertexShader:o.vertexShader,fragmentShader:o.fragmentShader}),this.separableBlurMaterials=[];let s=[6,10,14,18,22];i=Math.round(this.resolution.x/2),a=Math.round(this.resolution.y/2);for(let e=0;e<this.nMips;e++)this.separableBlurMaterials.push(this._getSeparableBlurMaterial(s[e])),this.separableBlurMaterials[e].uniforms.invSize.value=new q(1/i,1/a),i=Math.round(i/2),a=Math.round(a/2);this.compositeMaterial=this._getCompositeMaterial(this.nMips),this.compositeMaterial.uniforms.blurTexture1.value=this.renderTargetsVertical[0].texture,this.compositeMaterial.uniforms.blurTexture2.value=this.renderTargetsVertical[1].texture,this.compositeMaterial.uniforms.blurTexture3.value=this.renderTargetsVertical[2].texture,this.compositeMaterial.uniforms.blurTexture4.value=this.renderTargetsVertical[3].texture,this.compositeMaterial.uniforms.blurTexture5.value=this.renderTargetsVertical[4].texture,this.compositeMaterial.uniforms.bloomStrength.value=t,this.compositeMaterial.uniforms.bloomRadius.value=.1;let c=[1,.8,.6,.4,.2];this.compositeMaterial.uniforms.bloomFactors.value=c,this.bloomTintColors=[new J(1,1,1),new J(1,1,1),new J(1,1,1),new J(1,1,1),new J(1,1,1)],this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,this.copyUniforms=Su.clone(JF.uniforms),this.blendMaterial=new Tu({uniforms:this.copyUniforms,vertexShader:JF.vertexShader,fragmentShader:JF.fragmentShader,premultipliedAlpha:!0,blending:2,depthTest:!1,depthWrite:!1,transparent:!0}),this._oldClearColor=new X,this._oldClearAlpha=1,this._basic=new js,this._fsQuad=new QF(null)}dispose(){for(let e=0;e<this.renderTargetsHorizontal.length;e++)this.renderTargetsHorizontal[e].dispose();for(let e=0;e<this.renderTargetsVertical.length;e++)this.renderTargetsVertical[e].dispose();this.renderTargetBright.dispose();for(let e=0;e<this.separableBlurMaterials.length;e++)this.separableBlurMaterials[e].dispose();this.compositeMaterial.dispose(),this.blendMaterial.dispose(),this._basic.dispose(),this._fsQuad.dispose()}setSize(e,t){let n=Math.round(e/2),r=Math.round(t/2);this.renderTargetBright.setSize(n,r);for(let e=0;e<this.nMips;e++)this.renderTargetsHorizontal[e].setSize(n,r),this.renderTargetsVertical[e].setSize(n,r),this.separableBlurMaterials[e].uniforms.invSize.value=new q(1/n,1/r),n=Math.round(n/2),r=Math.round(r/2)}render(t,n,r,i,a){t.getClearColor(this._oldClearColor),this._oldClearAlpha=t.getClearAlpha();let o=t.autoClear;t.autoClear=!1,t.setClearColor(this.clearColor,0),a&&t.state.buffers.stencil.setTest(!1),this.renderToScreen&&(this._fsQuad.material=this._basic,this._basic.map=r.texture,t.setRenderTarget(null),t.clear(),this._fsQuad.render(t)),this.highPassUniforms.tDiffuse.value=r.texture,this.highPassUniforms.luminosityThreshold.value=this.threshold,this._fsQuad.material=this.materialHighPassFilter,t.setRenderTarget(this.renderTargetBright),t.clear(),this._fsQuad.render(t);let s=this.renderTargetBright;for(let n=0;n<this.nMips;n++)this._fsQuad.material=this.separableBlurMaterials[n],this.separableBlurMaterials[n].uniforms.colorTexture.value=s.texture,this.separableBlurMaterials[n].uniforms.direction.value=e.BlurDirectionX,t.setRenderTarget(this.renderTargetsHorizontal[n]),t.clear(),this._fsQuad.render(t),this.separableBlurMaterials[n].uniforms.colorTexture.value=this.renderTargetsHorizontal[n].texture,this.separableBlurMaterials[n].uniforms.direction.value=e.BlurDirectionY,t.setRenderTarget(this.renderTargetsVertical[n]),t.clear(),this._fsQuad.render(t),s=this.renderTargetsVertical[n];this._fsQuad.material=this.compositeMaterial,this.compositeMaterial.uniforms.bloomStrength.value=this.strength,this.compositeMaterial.uniforms.bloomRadius.value=this.radius,this.compositeMaterial.uniforms.bloomTintColors.value=this.bloomTintColors,t.setRenderTarget(this.renderTargetsHorizontal[0]),t.clear(),this._fsQuad.render(t),this._fsQuad.material=this.blendMaterial,this.copyUniforms.tDiffuse.value=this.renderTargetsHorizontal[0].texture,a&&t.state.buffers.stencil.setTest(!0),this.renderToScreen?(t.setRenderTarget(null),this._fsQuad.render(t)):(t.setRenderTarget(r),this._fsQuad.render(t)),t.setClearColor(this._oldClearColor,this._oldClearAlpha),t.autoClear=o}_getSeparableBlurMaterial(e){let t=[],n=e/3;for(let r=0;r<e;r++)t.push(.39894*Math.exp(-.5*r*r/(n*n))/n);return new Tu({defines:{KERNEL_RADIUS:e},uniforms:{colorTexture:{value:null},invSize:{value:new q(.5,.5)},direction:{value:new q(.5,.5)},gaussianCoefficients:{value:t}},vertexShader:`
|
|
5938
5938
|
|
|
5939
5939
|
varying vec2 vUv;
|
|
5940
5940
|
|
|
@@ -6016,7 +6016,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
6016
6016
|
float bloomAlpha = max( bloom.r, max( bloom.g, bloom.b ) );
|
|
6017
6017
|
gl_FragColor = vec4( bloom, bloomAlpha );
|
|
6018
6018
|
|
|
6019
|
-
}`})}};
|
|
6019
|
+
}`})}};aI.BlurDirectionX=new q(1,0),aI.BlurDirectionY=new q(0,1);var oI={name:`OutputShader`,uniforms:{tDiffuse:{value:null},toneMappingExposure:{value:1}},vertexShader:`
|
|
6020
6020
|
precision highp float;
|
|
6021
6021
|
|
|
6022
6022
|
uniform mat4 modelViewMatrix;
|
|
@@ -6087,7 +6087,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
6087
6087
|
|
|
6088
6088
|
#endif
|
|
6089
6089
|
|
|
6090
|
-
}`},
|
|
6090
|
+
}`},sI=class extends YF{constructor(){super(),this.isOutputPass=!0,this.uniforms=Su.clone(oI.uniforms),this.material=new Eu({name:oI.name,uniforms:this.uniforms,vertexShader:oI.vertexShader,fragmentShader:oI.fragmentShader}),this._fsQuad=new QF(this.material),this._outputColorSpace=null,this._toneMapping=null}render(e,t,n){this.uniforms.tDiffuse.value=n.texture,this.uniforms.toneMappingExposure.value=e.toneMappingExposure,(this._outputColorSpace!==e.outputColorSpace||this._toneMapping!==e.toneMapping)&&(this._outputColorSpace=e.outputColorSpace,this._toneMapping=e.toneMapping,this.material.defines={},ia.getTransfer(this._outputColorSpace)===`srgb`&&(this.material.defines.SRGB_TRANSFER=``),this._toneMapping===1?this.material.defines.LINEAR_TONE_MAPPING=``:this._toneMapping===2?this.material.defines.REINHARD_TONE_MAPPING=``:this._toneMapping===3?this.material.defines.CINEON_TONE_MAPPING=``:this._toneMapping===4?this.material.defines.ACES_FILMIC_TONE_MAPPING=``:this._toneMapping===6?this.material.defines.AGX_TONE_MAPPING=``:this._toneMapping===7?this.material.defines.NEUTRAL_TONE_MAPPING=``:this._toneMapping===5&&(this.material.defines.CUSTOM_TONE_MAPPING=``),this.material.needsUpdate=!0),this.renderToScreen===!0?(e.setRenderTarget(null),this._fsQuad.render(e)):(e.setRenderTarget(t),this.clear&&e.clear(e.autoClearColor,e.autoClearDepth,e.autoClearStencil),this._fsQuad.render(e))}dispose(){this.material.dispose(),this._fsQuad.dispose()}};function cI(e){return e.isCSS2DObject===!0}var lI=NaN,uI=class{domElement;sortObjects=!0;_w=0;_h=0;_wHalf=0;_hHalf=0;_viewMatrix=new Y;_viewProjectionMatrix=new Y;_vector=new J;_a=new J;_b=new J;_cache=new WeakMap;_visibleBuf=[];_visibleCount=0;constructor(e={}){this.domElement=e.element??document.createElement(`div`),this.domElement.style.overflow=`hidden`}getSize(){return{width:this._w,height:this._h}}setSize(e,t){this._w=e,this._h=t,this._wHalf=e/2,this._hHalf=t/2,this.domElement.style.width=e+`px`,this.domElement.style.height=t+`px`}render(e,t){e.matrixWorldAutoUpdate===!0&&e.updateMatrixWorld(),t.parent===null&&t.matrixWorldAutoUpdate===!0&&t.updateMatrixWorld(),this._viewMatrix.copy(t.matrixWorldInverse),this._viewProjectionMatrix.multiplyMatrices(t.projectionMatrix,this._viewMatrix),this._visibleCount=0,this.renderObject(e,t),this.sortObjects&&this.zOrder();for(let e=this._visibleCount;e<this._visibleBuf.length;e++)this._visibleBuf[e]=void 0;this._visibleBuf.length=this._visibleCount}renderObject(e,t){if(e.visible===!1){e.userData.css2dHidden!==!0&&(this.hideObject(e),e.userData.css2dHidden=!0);return}if(e.userData.css2dHidden===!0&&(e.userData.css2dHidden=!1),cI(e)){let n=e.element;this._vector.setFromMatrixPosition(e.matrixWorld),this._vector.applyMatrix4(this._viewProjectionMatrix);let r=this._vector.z,i=bw(r),a=e.layers.test(t.layers),o=i&&a,s=this.cacheFor(n),c=o?``:`none`;if(s.display!==c&&(n.style.display=c,s.display=c),o){let r=Math.round((this._vector.x*this._wHalf+this._wHalf)*2)/2,i=Math.round((-this._vector.y*this._hHalf+this._hHalf)*2)/2,a=e.center.x,o=e.center.y;(s.tx!==r||s.ty!==i||s.cx!==a||s.cy!==o)&&(n.style.transform=`translate(`+-100*a+`%,`+-100*o+`%) translate(`+r+`px,`+i+`px)`,s.tx=r,s.ty=i,s.cx=a,s.cy=o),n.parentNode!==this.domElement&&this.domElement.appendChild(n),s.dist2=this.distanceToCameraSquared(t,e),this._visibleBuf[this._visibleCount++]=e}}let n=e.children;for(let e=0;e<n.length;e++)this.renderObject(n[e],t)}cacheFor(e){let t=this._cache.get(e);return t||(t={tx:lI,ty:lI,cx:lI,cy:lI,display:`__init__`,zIndex:lI,dist2:0},this._cache.set(e,t)),t}hideObject(e){if(cI(e)){let t=e.element,n=this.cacheFor(t);n.display!==`none`&&(t.style.display=`none`,n.display=`none`)}let t=e.children;for(let e=0;e<t.length;e++)this.hideObject(t[e])}distanceToCameraSquared(e,t){return this._a.setFromMatrixPosition(e.matrixWorld),this._b.setFromMatrixPosition(t.matrixWorld),this._a.distanceToSquared(this._b)}zOrder(){let e=this._visibleBuf,t=this._visibleCount;if(t===0)return;e.sort((e,t)=>e.renderOrder===t.renderOrder?this._cache.get(e.element).dist2-this._cache.get(t.element).dist2:t.renderOrder-e.renderOrder);let n=t;for(let r=0;r<t;r++){let t=e[r],i=n-r,a=this._cache.get(t.element);a.zIndex!==i&&(t.element.style.zIndex=String(i),a.zIndex=i)}}},dI=.5;function fI(e,t){return new X(e).multiplyScalar(t)}var pI=new q(1,1);function mI(e,t){pI.set(e,t)}function hI(e,t=dI){return new Tu({transparent:!0,depthWrite:!1,uniforms:{uColor:{value:fI(e,t)},uCenterOffset:{value:new J},uAlphaMultiplier:{value:1},uAlphaMin:{value:0},uShowFull:{value:0}},vertexShader:`
|
|
6091
6091
|
#include <common>
|
|
6092
6092
|
#include <logdepthbuf_pars_vertex>
|
|
6093
6093
|
uniform vec3 uCenterOffset;
|
|
@@ -6111,7 +6111,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
6111
6111
|
gl_FragColor = vec4(uColor, clamp(max(vAlpha * uAlphaMultiplier, uAlphaMin), 0.0, 1.0));
|
|
6112
6112
|
#include <logdepthbuf_fragment>
|
|
6113
6113
|
}
|
|
6114
|
-
`})}function
|
|
6114
|
+
`})}function gI(e,t,n=dI,r){return new Tu({defines:r?{DASHED:``}:{},transparent:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:fI(e,n)},uCenterOffset:{value:new J},uAlphaMultiplier:{value:1},uAlphaMin:{value:0},uShowFull:{value:0},uLineWidth:{value:t},uResolution:{value:pI},uDash:{value:new q(r?.[0]??0,r?.[1]??0)}},vertexShader:`
|
|
6115
6115
|
#include <common>
|
|
6116
6116
|
#include <logdepthbuf_pars_vertex>
|
|
6117
6117
|
uniform vec3 uCenterOffset;
|
|
@@ -6171,7 +6171,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
6171
6171
|
gl_FragColor = vec4(uColor, clamp(max(vAlpha * uAlphaMultiplier, uAlphaMin), 0.0, 1.0));
|
|
6172
6172
|
#include <logdepthbuf_fragment>
|
|
6173
6173
|
}
|
|
6174
|
-
`})}var
|
|
6174
|
+
`})}var _I=16;function vI(e){e.materialHighPassFilter.dispose(),e.materialHighPassFilter=new Tu({uniforms:e.highPassUniforms,vertexShader:`
|
|
6175
6175
|
varying vec2 vUv;
|
|
6176
6176
|
void main() {
|
|
6177
6177
|
vUv = uv;
|
|
@@ -6190,7 +6190,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
6190
6190
|
// A sliver of a pixel is rounding, not light.
|
|
6191
6191
|
ivec2 first = max(ivec2(floor(lo + 0.001)), ivec2(0));
|
|
6192
6192
|
ivec2 last = min(ivec2(ceil(hi - 0.001)) - 1, ivec2(size) - 1);
|
|
6193
|
-
last = min(last, first + ${
|
|
6193
|
+
last = min(last, first + ${_I-1});
|
|
6194
6194
|
vec3 sum = vec3(0.0);
|
|
6195
6195
|
for (int y = first.y; y <= last.y; y++) {
|
|
6196
6196
|
float wy = min(float(y) + 1.0, hi.y) - max(float(y), lo.y);
|
|
@@ -6204,7 +6204,7 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
6204
6204
|
}
|
|
6205
6205
|
gl_FragColor = vec4(sum / (span.x * span.y), 1.0);
|
|
6206
6206
|
}
|
|
6207
|
-
`})}var
|
|
6207
|
+
`})}var yI=`
|
|
6208
6208
|
vec3 outputDither(vec3 color) {
|
|
6209
6209
|
// ES 1.00 gives gl_FragCoord at medium precision. Copy it before the arithmetic.
|
|
6210
6210
|
vec3 p3 = gl_FragCoord.xyx;
|
|
@@ -6217,8 +6217,8 @@ vTileOff = position - uTileAnchor;`),e.fragmentShader=e.fragmentShader.replace(`
|
|
|
6217
6217
|
vec3 amplitude = clamp(min(color, 1.0 - color) * 255.0, 0.0, 1.0);
|
|
6218
6218
|
return color + noise * amplitude / 255.0;
|
|
6219
6219
|
}
|
|
6220
|
-
`;function
|
|
6221
|
-
}`)}var
|
|
6220
|
+
`;function bI(e){e.material.fragmentShader=e.material.fragmentShader.replace(`#include <colorspace_pars_fragment>`,`#include <colorspace_pars_fragment>\n${yI}`).replace(/}\s*$/,`gl_FragColor.rgb = outputDither(gl_FragColor.rgb);
|
|
6221
|
+
}`)}var xI=1e5;function SI(){try{return!!document.createElement(`canvas`).getContext(`webgl2`)?.getExtension(`EXT_clip_control`)}catch{return!1}}var CI=class extends Error{constructor(e){super(`WebGL is unavailable on this device.`,{cause:e}),this.name=`WebGLUnavailableError`}};function wI(e,t,n){let r,i=SI();i||Sw();try{r=new wh(i?{canvas:e,reversedDepthBuffer:!0,antialias:!0}:{canvas:e,logarithmicDepthBuffer:!0,antialias:!0})}catch(e){throw new CI(e)}i&&!r.capabilities.reversedDepthBuffer&&console.warn(`EXT_clip_control probe mismatch: reversed depth unavailable on main context`),vw(r.capabilities.reversedDepthBuffer);let a=SE();r.setPixelRatio(CE()),r.setSize(e.clientWidth,e.clientHeight,!1),r.shadowMap.enabled=!0,r.shadowMap.type=a.softShadows?2:1,r.toneMapping=4,r.toneMappingExposure=1,mI(e.clientWidth,e.clientHeight);let o=new uI({element:t});o.setSize(e.clientWidth,e.clientHeight),n.visibility.updateViewport(e.clientHeight);let s=new to,c=new Od(16777215,GS);s.add(c);let l=new Dd(16777215,0);l.castShadow=!1,l.shadow.mapSize.set(a.shadowMapSize,a.shadowMapSize),l.shadow.bias=-1e-4,s.add(l),s.add(l.target);let u=new bd(60,e.clientWidth/e.clientHeight,Q(.001),xI),d=new _a(e.clientWidth,e.clientHeight,{type:Xn,resolveDepthBuffer:!1,depthTexture:new qc(e.clientWidth,e.clientHeight,Yn)}),f=r.getContext(),p=f.getInternalformatParameter(f.RENDERBUFFER,f.RGBA16F,f.SAMPLES),m=new nI(r,d);m.setPixelRatio(CE()),m.setSize(e.clientWidth,e.clientHeight),m.addPass(new rI(s,u));let h=new aI(new q(e.clientWidth*a.bloomScale,e.clientHeight*a.bloomScale),.3,.5,1);vI(h),m.addPass(h);let g=new sI;return bI(g),g.needsSwap=!1,m.addPass(g),{renderer:r,labelRenderer:o,scene:s,camera:u,composer:m,maxSceneSamples:p?.[0]??0,bloomPass:h,ambientLight:c,shadowLight:l}}function TI(e,t,n,r,i,a,o,s,c,l){let u=c===`touch`||c===`pen`?48:24,d=(e.x+1)*.5*i,f=(1-e.y)*.5*a,p=o,[m,h,g]=r,_=t.position,v,y=u,b=1/0,x=e=>{let r=n.place(e,s);if(!r)return;p.set(r[0]-m,r[1]-h,r[2]-g);let o=Math.hypot(p.x-_.x,p.y-_.y,p.z-_.z);if(p.project(t),!bw(p.z))return;let c=(p.x+1)*.5*i,u=(1-p.y)*.5*a,x=Math.hypot(c-d,u-f);(x<y||x===y&&o<b)&&(l&&!l(p.x,p.y,o)||(y=x,b=o,v=e))};for(let e of n.bodies.majorBodies)e.data.objectType===G.MOON&&n.visibility.isMoonGroupVisible(e.data.parentId)&&x(e);return v?{body:v,distance:b,screenDist:y}:null}var EI=9;function DI(e){let t=e;for(;t.parent?.parent;)t=t.parent;return!t.visible}var OI=class{downPos=new q;pointer=new q;_tmpPointer=new q;raycaster=new Zd;_tmpV3=new J;constructor(e,t,n,r,i,a,o,s,c,l,u,d){this.canvas=e,this.camera=t,this.ctx=n,this.clock=r,this.focus=i,this.clickables=a,this.meshToBody=o,this.onPick=s,this.modelPick=c,this.gpuPick=l,this.getClouds=u,this.pickRegistry=d}attach(){this.canvas.addEventListener(`pointerdown`,this.onDown),this.canvas.addEventListener(`pointerup`,this.onUp)}detach(){this.canvas.removeEventListener(`pointerdown`,this.onDown),this.canvas.removeEventListener(`pointerup`,this.onUp)}onDown=e=>{this.downPos.set(e.clientX,e.clientY)};onUp=e=>{let t=e.clientX-this.downPos.x,n=e.clientY-this.downPos.y;if(t*t+n*n>EI)return;let r=this.canvas.getBoundingClientRect();this.pointer.set((e.clientX-r.left)/r.width*2-1,-((e.clientY-r.top)/r.height)*2+1);let i=this.modelPick(this.pointer.x,this.pointer.y);if(i){this.onPick(i);return}this.raycaster.setFromCamera(this.pointer,this.camera);let a=this.resolveMeshHit(this.raycaster.intersectObjects([...this.clickables,...Ij]))?.body,o=TI(this.pointer,this.camera,this.ctx,this.focus.focusTruePos,this.canvas.clientWidth,this.canvas.clientHeight,this._tmpV3,this.clock.jd,e.pointerType,this.isDotVisible),s=this.gpuPickCloud(e,r),c=this.nearer(o,s)?.body??a;c&&this.onPick(c)};nearer(e,t){return e?t&&(t.screenDist<e.screenDist||t.screenDist===e.screenDist&&t.distance<e.distance)?t:e:t}gpuPickCloud(e,t){let n=e.pointerType===`touch`||e.pointerType===`pen`?48:24,r=this.clock.jd,i=this.gpuPick.pick(this.getClouds(),this.camera,e.clientX,e.clientY,t,n);for(let e of i){let t=this.pickRegistry.resolve(e.pickId);if(!t)continue;let n=this.ctx.getBody(t);if(!n)continue;let i=this.ctx.place(n,r);if(!i)continue;let a=this.worldDistOf(i);if(this.isDotVisible(e.ndcX,e.ndcY,a))return{body:n,distance:a,screenDist:e.pixelDist}}return null}worldDistOf(e){let[t,n,r]=this.focus.focusTruePos,i=this.camera.position;return Math.hypot(e[0]-t-i.x,e[1]-n-i.y,e[2]-r-i.z)}resolveMeshHit(e){for(let t of e){if(DI(t.object))continue;let e=t.object;for(;e;){let n=this.meshToBody.get(e)??e.userData.pickBody;if(n)return{body:n,distance:t.distance};e=e.parent}}}isDotVisible=(e,t,n)=>{if(this.modelPick(e,t))return!1;if(this.clickables.length===0&&Ij.size===0)return!0;this._tmpPointer.set(e,t),this.raycaster.setFromCamera(this._tmpPointer,this.camera);let r=this.raycaster.intersectObjects(this.clickables,!1);Ij.size>0&&r.push(...this.raycaster.intersectObjects([...Ij],!0));let i=1/0;for(let e of r)e.distance<i&&!DI(e.object)&&(i=e.distance);return i>=n*.999}},kI=4,AI=16,jI=`
|
|
6222
6222
|
uniform mat4 modelViewMatrix;
|
|
6223
6223
|
uniform mat4 projectionMatrix;
|
|
6224
6224
|
uniform float uPointSize;
|
|
@@ -6230,13 +6230,13 @@ void main() {
|
|
|
6230
6230
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
6231
6231
|
gl_PointSize = uPointSize;
|
|
6232
6232
|
}
|
|
6233
|
-
`,
|
|
6233
|
+
`,MI=`
|
|
6234
6234
|
precision highp float;
|
|
6235
6235
|
varying vec4 vPick;
|
|
6236
6236
|
void main() {
|
|
6237
6237
|
gl_FragColor = vPick;
|
|
6238
6238
|
}
|
|
6239
|
-
`,
|
|
6239
|
+
`,NI=class{target;material;scene=new to;pickCamera;size=0;buffer=new Uint8Array;prevClear=new X;proxies=[];constructor(e,t){this.renderer=e,this.target=new _a(1,1,{depthBuffer:!0}),this.target.texture.colorSpace=ii,this.target.texture.generateMipmaps=!1,this.material=new Eu({vertexShader:jI,fragmentShader:MI,uniforms:{uPointSize:{value:kI}},blending:0,depthTest:!0,depthWrite:!0}),this.scene.matrixWorldAutoUpdate=!1,this.pickCamera=t.clone()}ensureSize(e){e!==this.size&&(this.size=e,this.target.setSize(e,e),this.buffer=new Uint8Array(e*e*4))}proxyAt(e,t){let n=this.proxies[e];return n?n.geometry=t.geometry:(n=new Uc(t.geometry,this.material),n.frustumCulled=!1,n.matrixAutoUpdate=!1,n.matrixWorldAutoUpdate=!1,this.proxies[e]=n),n.matrixWorld.copy(t.matrixWorld),n}pick(e,t,n,r,i,a){let o=Math.max(1,Math.round(a)),s=o*2+1;this.ensureSize(s);let c=n-i.left,l=r-i.top,u=c-o,d=l-o;this.scene.clear();let f=0;for(let t of e)t.visible&&t.geometry.getAttribute(`pickColor`)&&t.geometry.drawRange.count!==0&&this.scene.add(this.proxyAt(f++,t));if(f===0)return[];this.pickCamera.copy(t),this.pickCamera.setViewOffset(i.width,i.height,u,d,s,s),this.pickCamera.updateProjectionMatrix();let p=this.renderer.getRenderTarget(),m=this.renderer.autoClear;this.renderer.getClearColor(this.prevClear);let h=this.renderer.getClearAlpha();return this.renderer.setRenderTarget(this.target),this.renderer.autoClear=!1,this.renderer.setClearColor(0,0),this.renderer.clear(!0,!0,!1),this.renderer.render(this.scene,this.pickCamera),this.renderer.readRenderTargetPixels(this.target,0,0,s,s,this.buffer),this.renderer.setRenderTarget(p),this.renderer.autoClear=m,this.renderer.setClearColor(this.prevClear,h),this.pickCamera.clearViewOffset(),this.decode(s,o,i,u,d)}decode(e,t,n,r,i){let a=this.buffer,o=new Map;for(let s=0;s<e;s++){let c=e-1-s;for(let l=0;l<e;l++){let u=(s*e+l)*4,d=(a[u]|a[u+1]<<8|a[u+2]<<16|a[u+3]<<24)>>>0;if(d===0)continue;let f=l-t,p=c-t,m=Math.hypot(f,p),h=o.get(d);if(h&&h.pixelDist<=m)continue;let g=r+l+.5,_=i+c+.5;o.set(d,{pickId:d,pixelDist:m,ndcX:g/n.width*2-1,ndcY:-(_/n.height*2-1)})}}return[...o.values()].sort((e,t)=>e.pixelDist-t.pixelDist).slice(0,AI)}dispose(){this.target.dispose(),this.material.dispose(),this.proxies.length=0}};function PI(e,t,n){return Math.min(Math.max(e,t),n)}function FI(e,t){let n=Math.max(e,0);return PI(t.refMs*n/t.refAngleRad,t.minMs,t.maxMs)}function II(e,t){if(!(e>0))return t.minMs;let n=Math.log10(e/t.refDist);return PI(t.refMs+n*t.msPerDecade,t.minMs,t.maxMs)}var LI={refMs:350,refAngleRad:Math.PI/3,minMs:200,maxMs:700},RI={refMs:400,refAngleRad:Math.PI/2,minMs:200,maxMs:800},zI={refMs:1600,refDist:2,msPerDecade:400,minMs:600,maxMs:2500},BI={refMs:1600,refAngleRad:Math.PI/2,minMs:600,maxMs:2500},VI=new J(0,1,0),HI=(()=>{let e=Math.PI/180,t=192.85948*e,n=27.12825*e,r=Math.cos(n),i=r*Math.cos(t),a=r*Math.sin(t),o=Math.sin(n),s=vg*e,c=Math.cos(s),l=Math.sin(s),u=i,d=a*c+o*l;return new J(u,-a*l+o*c,-d).normalize()})();function UI(e){return(e??new J).copy(HI)}function WI(e,t,n,r=!1){let i=n??new J;if(!e.orientation)return r&&e.orbitCenter&&e.position&&(i.set(e.position[0]-e.orbitCenter[0],e.position[1]-e.orbitCenter[1],e.position[2]-e.orbitCenter[2]),i.lengthSq()>1e-20)?i.normalize():(i.copy(VI),e.modelBaseFrame&&i.applyQuaternion(e.modelBaseFrame).normalize(),i);let a=xS(e.orientation,t,e.nutPrec);return i.copy(VI).applyQuaternion(a).normalize()}var GI=class{refId=null;startVec=new J(0,1,0);targetVec=new J(0,1,0);currentVec=new J(0,1,0);animStartTime=-1/0;animDurationMs=RI.refMs;needsDurationCalc=!1;_quatA=new Xi;_quatB=new Xi;constructor(e,t,n,r){this.camera=e,this.controls=t,this.ctx=n,this.isLanded=r}setNorthReference(e){e!==this.refId&&(this.refId=e,this.startVec.copy(this.currentVec),this.animStartTime=performance.now(),this.needsDurationCalc=!0)}update(e){if(this.refId===`galactic`)UI(this.targetVec);else{let t=this.refId?this.ctx.getBody(this.refId):void 0;if(t){let n=!!t.featureAnchor||this.isLanded(t.data.id);WI(t,e,this.targetVec,n)}else this.targetVec.copy(VI)}if(this.needsDurationCalc){this.needsDurationCalc=!1;let e=this.startVec.angleTo(this.targetVec);this.animDurationMs=FI(e,RI)}let t=performance.now()-this.animStartTime;if(t>=this.animDurationMs)this.currentVec.copy(this.targetVec);else{let e=Math.max(0,t/this.animDurationMs),n=e*e*(3-2*e);this._quatA.setFromUnitVectors(VI,this.startVec),this._quatB.setFromUnitVectors(VI,this.targetVec),this._quatA.slerp(this._quatB,n),this.currentVec.copy(VI).applyQuaternion(this._quatA)}this.camera.up.copy(this.currentVec);let n=this.controls;n._quat.setFromUnitVectors(this.currentVec,VI),n._quatInverse.copy(n._quat).invert()}},KI=6*.8*Math.PI*(4/2)**2,qI=.9,JI=.125,YI=.6,XI=1.5;function ZI(e,t=256){let n=document.createElement(`canvas`);n.width=t,n.height=t;let r=n.getContext(`2d`),i=t/2,a=r.createRadialGradient(i,i,0,i,i,i);return a.addColorStop(0,$I(e,1)),a.addColorStop(.15,$I(e,1)),a.addColorStop(.4,$I(e,.3)),a.addColorStop(1,$I(e,0)),r.fillStyle=a,r.fillRect(0,0,t,t),new Kc(n)}function QI(e){return`rgb(${parseInt(e.slice(1,3),16)}, ${parseInt(e.slice(3,5),16)}, ${parseInt(e.slice(5,7),16)})`}function $I(e,t){return e.replace(`)`,`, ${t})`).replace(`rgb(`,`rgba(`)}var eL=`#fff5eb`,tL=`#ffd9a8`;function nL(){let e=new X(eL),t=new X(tL);return new Tu({uniforms:{uCentreColor:{value:new J(e.r,e.g,e.b)},uLimbColor:{value:new J(t.r,t.g,t.b)},uLimbAlpha:{value:new J(.5,.5,.5)},...kN()},vertexShader:`
|
|
6240
6240
|
#include <common>
|
|
6241
6241
|
#include <logdepthbuf_pars_vertex>
|
|
6242
6242
|
varying vec3 vNormalView;
|
|
@@ -6259,7 +6259,7 @@ void main() {
|
|
|
6259
6259
|
varying vec3 vNormalView;
|
|
6260
6260
|
varying vec3 vViewDir;
|
|
6261
6261
|
varying vec3 vWorldPos;
|
|
6262
|
-
${
|
|
6262
|
+
${vN}
|
|
6263
6263
|
void main() {
|
|
6264
6264
|
#include <logdepthbuf_fragment>
|
|
6265
6265
|
float mu = max(dot(normalize(vNormalView), normalize(vViewDir)), 0.0);
|
|
@@ -6274,7 +6274,7 @@ void main() {
|
|
|
6274
6274
|
vec3 hdr = tint * darkening * ${6 .toFixed(1)};
|
|
6275
6275
|
gl_FragColor = vec4(atmoViewTint(vWorldPos) * hdr, 1.0);
|
|
6276
6276
|
}
|
|
6277
|
-
`})}function
|
|
6277
|
+
`})}function rL(e,t){let n=new xs(new ss({map:ZI(t.startsWith(`#`)?QI(t):t),blending:2,transparent:!0,opacity:YI,depthWrite:!1,depthTest:!0})),r=e*6;return n.scale.set(r,r,1),n}function iL(e){let t=Math.ceil(e/2),n=0;for(let r=-t;r<t;r++)for(let i=-t;i<t;i++)(i+.5)**2+(r+.5)**2<=e*e/4&&n++;return n}function aL(e){let t=new ts;t.setAttribute(`position`,new Uo(new Float32Array(3),3));let n=new X(e),r=new X(eL),i=new ha(0,0,1,1),a=4 .toFixed(1),o={uColor:{value:new J(n.r,n.g,n.b)},uDiscColor:{value:new J(r.r,r.g,r.b)},uFlux:{value:1},uPixelRatio:{value:1},uPixels:{value:iL(4)},uViewport:{value:i},uTint:{value:new J(1,1,1)}},s=new Uc(t,new Tu({uniforms:o,vertexShader:`
|
|
6278
6278
|
#include <common>
|
|
6279
6279
|
#include <logdepthbuf_pars_vertex>
|
|
6280
6280
|
uniform float uPixelRatio;
|
|
@@ -6283,7 +6283,7 @@ void main() {
|
|
|
6283
6283
|
void main() {
|
|
6284
6284
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
|
|
6285
6285
|
vec2 halfView = 0.5 * uViewport.zw;
|
|
6286
|
-
vec2 seat = floor((gl_Position.xy / gl_Position.w + 1.0) * halfView + ${(.5+
|
|
6286
|
+
vec2 seat = floor((gl_Position.xy / gl_Position.w + 1.0) * halfView + ${(.5+JI).toFixed(3)});
|
|
6287
6287
|
gl_Position.xy = (seat / halfView - 1.0) * gl_Position.w;
|
|
6288
6288
|
vSeat = uViewport.xy + seat;
|
|
6289
6289
|
// A margin: the square of the point must not cut the dot.
|
|
@@ -6314,9 +6314,9 @@ void main() {
|
|
|
6314
6314
|
// The disc's light at the handoff, on all the pixels. With too little
|
|
6315
6315
|
// for all, the four at the centre have it: the glow goes on for a
|
|
6316
6316
|
// fainter star.
|
|
6317
|
-
float all = ${
|
|
6317
|
+
float all = ${KI.toFixed(3)} * uFlux * uPixelRatio * uPixelRatio / uPixels;
|
|
6318
6318
|
float four = all * uPixels / 4.0;
|
|
6319
|
-
float value = clamp(all, ${
|
|
6319
|
+
float value = clamp(all, ${qI.toFixed(1)}, under);
|
|
6320
6320
|
if (all >= over) {
|
|
6321
6321
|
value = all;
|
|
6322
6322
|
} else if (four >= over && max(abs(p.x), abs(p.y)) < 1.0) {
|
|
@@ -6324,17 +6324,17 @@ void main() {
|
|
|
6324
6324
|
}
|
|
6325
6325
|
gl_FragColor = vec4(colour * value, 1.0);
|
|
6326
6326
|
}
|
|
6327
|
-
`,transparent:!0,depthTest:!0,depthWrite:!1}));return s.frustumCulled=!1,s.onBeforeRender=e=>{e.getCurrentViewport(i).floor();let t=e.getPixelRatio();t!==o.uPixelRatio.value&&(o.uPixelRatio.value=t,o.uPixels.value=
|
|
6327
|
+
`,transparent:!0,depthTest:!0,depthWrite:!1}));return s.frustumCulled=!1,s.onBeforeRender=e=>{e.getCurrentViewport(i).floor();let t=e.getPixelRatio();t!==o.uPixelRatio.value&&(o.uPixelRatio.value=t,o.uPixels.value=iL(4*t))},s}function oL(e,t,n){let r=new wd(16777215,KS,0,0);e.add(r);let i=rL(t,n);e.add(i);let a=aL(n);return e.add(a),{light:r,corona:i,starPoint:a}}function sL(e,t,n){e&&e.material.color.setRGB(n.x,n.y,n.z),t&&t.material.uniforms.uTint.value.copy(n)}function cL(e,t){if(!e)return;let n=Math.min(Math.max((t-1)/(XI-1),0),1);e.visible=n>0,e.material.opacity=YI*n}function lL(e){let t=e?.uniforms;return t?.uAtmoTEnable?t:null}function uL(e,t){let n=e?.uniforms;t&&n?.uLimbAlpha&&n.uLimbAlpha.value.set(t[0],t[1],t[2])}var dL=`
|
|
6328
6328
|
uniform vec3 uEyeAnchor;
|
|
6329
6329
|
uniform vec3 uEyeAnchorView;
|
|
6330
|
-
`,
|
|
6330
|
+
`,fL=`
|
|
6331
6331
|
vec4 mvPosition = vec4( mat3( modelViewMatrix ) * ( transformed - uEyeAnchor ) + uEyeAnchorView, 1.0 );
|
|
6332
6332
|
gl_Position = projectionMatrix * mvPosition;
|
|
6333
|
-
`,
|
|
6333
|
+
`,pL=new WeakMap,mL=new Y,hL=new Y,gL=new J;function _L(e,t){HS(e,`cameraRelative`,e=>{e.uniforms.uEyeAnchor=t.local,e.uniforms.uEyeAnchorView=t.view,e.vertexShader=e.vertexShader.replace(`#include <common>`,`#include <common>\n${dL}`).replace(`#include <project_vertex>`,fL)})}function vL(e,t){let n={local:{value:new J},view:{value:new J}};pL.set(t,n),_L(t,n),e.onBeforeRender=(t,r,i)=>{mL.multiplyMatrices(i.matrixWorldInverse,e.matrixWorld),gL.setFromMatrixPosition(hL.copy(mL).invert()),n.local.value.set(Math.fround(gL.x),Math.fround(gL.y),Math.fround(gL.z)),n.view.value.copy(n.local.value).applyMatrix4(mL)}}function yL(e,t){let n=pL.get(e);n&&_L(t,n)}function bL(e){if(Array.isArray(e))for(let t of e)t.dispose();else e.dispose()}var xL=96,SL=24;function CL(e,t,n,r,a,o,s,c,l){for(let u of e){let e=u.data.id,d=l?.has(e)??!1,f=u.data.objectType,p=d||f===G.BARYCENTER||f===G.LAGRANGE_POINT||f===G.COMET||xn(f)||u.data.orbitalSource===W.SPICE_PROBE,m=iv(u.data),h=Q(bn(u.data)),g=f===G.STAR,_=Dj(u),v=Number.isFinite(u.data.radiusKm)&&u.data.radiusKm>0,y=!_&&Cn(f)&&!v?`radius`:void 0,b=new qa;b.visible=!1;let x=new qa;b.add(x);let S=null,C=null,w=null,T=null,E=null,D=null,O;if(!p&&!y){g&&(C=oL(b,h,m));let t=g?xL:SL,i=new gu(h,t,t),a=g?nL():new Du({color:UA(u.data)});S=new Us(i,a),_&&(S.visible=!1),g||(w=Ww(a),vL(S,a),E=NA(u.data.lunarWeightScale),LA(a,e,E),_||(T=bT(a))),b.add(S),n.push(S),r.set(S,u);let o=g?void 0:Jb(e);o&&(D=rT(o,h,bn(u.data)),b.add(D.mesh),w&&(O=[jN(a,o,h,bn(u.data),w,D)]))}let k=JN(u),A=g||f===G.PLANET,j=d||rv.has(e)||u.data.isMinor===!0,M=YN(m,u.data.name??``,k,i().bodyHref(e,u.data.name??``),()=>s(u),A,c?t=>c(e,t):void 0,j);M&&(FT(M.element,o),x.add(M)),t.add(b);let ee=M?M.element.firstElementChild:null;ee&&(ee.dataset.origBorder=ee.style.border),a.set(e,{body:u,root:b,group:x,mesh:S,label:M,labelHalo:ee,labelStack:null,loadingEl:null,corona:C?.corona??null,starPoint:C?.starPoint??null,trail:null,radiusScene:h,cachedDist:0,currentSegments:p||y?void 0:g?xL:SL,isMinor:j,noPhysical:y,rings:[],clouds:null,atmosphere:D,sunTint:O,specularMap:null,emissiveMap:null,displacementMap:null,selfShadow:null,eclipseShadow:w,planetshine:T,photometry:E,nomenclatureLabels:null,model:null})}}function wL(e){let t=e.data.objectType;return t===G.COMET||xn(t)||e.data.orbitalSource===W.SPICE_PROBE}function TL(e,t,n,r){if(e.mesh!==null)return;let{body:i,radiusScene:a}=e;e.focusUpgraded=!0;let o=Dj(i);if(!o&&!(Number.isFinite(i.data.radiusKm)&&i.data.radiusKm>0)){e.noPhysical=`radius`;return}let s=SL,c=new gu(a,s,s),l=new Du({color:UA(i.data)}),u=new Us(c,l);o&&(u.visible=!1),e.root.add(u),e.mesh=u,n.push(u),r.set(u,i),e.eclipseShadow=Ww(l),vL(u,l),e.photometry=NA(i.data.lunarWeightScale),LA(l,i.data.id,e.photometry),o||(e.planetshine=bT(l)),e.currentSegments=s;let d=Jb(i.data.id);d&&(e.atmosphere=rT(d,a,bn(i.data)),e.root.add(e.atmosphere.mesh),e.sunTint=[jN(l,d,a,bn(i.data),e.eclipseShadow,e.atmosphere)])}function EL(e,t,n,r){e.focusUpgraded=!1,Hj(e);let i=e.mesh;if(i){e.displacementMap&&(e.displacementMap.dispose(),e.displacementMap=null,e.displacementTier=void 0,kD(e.selfShadow),e.selfShadow=null),tP(e),e.tileOverlay=void 0,gD(e),e.reliefTiles=void 0,e.terrainWindow=null,i.removeFromParent(),i.geometry.dispose(),bL(i.material);let t=n.indexOf(i);t>=0&&n.splice(t,1),r.delete(i),e.mesh=null,e.currentSegments=void 0,e.eclipseShadow=null,e.planetshine=null,e.photometry=null,e.sunTint=void 0,e.radiiApplied=!1,e.semiAxesScene=void 0}if(e.atmosphere){let t=e.atmosphere.mesh;t.removeFromParent(),t.geometry.dispose(),bL(t.material),e.atmosphere=null}let a=e.body.data.orbitalSource===W.SPICE_PROBE;e.trail&&!a&&(t.remove(e.trail),e.trail.geometry.dispose(),bL(e.trail.material),e.trail=null)}var DL=class{#e;#t=new J;#n=new q;#r=new WeakMap;#i=[];constructor(e,t){this.#e=OL(e,t)}setSize(e,t){this.#e.dispose(),this.#e.depthTexture?.dispose(),this.#e=OL(e,t)}run(e,t,n,r,i){let a=this.#i;for(let e of r.values())e.atmosphere?.material.side===1&&(e.mesh&&this.#a(e.mesh,i),e.model&&e.model.parent===e.modelRoot&&e.model.traverse(e=>{e.isMesh&&this.#a(e,i)}));let o=e.getRenderTarget(),s=n.layers.mask,c=t.background;n.layers.set(i),t.background=null,e.setRenderTarget(this.#e),e.clear(),e.render(t,n),e.setRenderTarget(o),t.background=c,n.layers.mask=s;for(let{mesh:e,material:t}of a)e.material=t,e.layers.disable(i);a.length=0,n.getWorldDirection(this.#t),e.getDrawingBufferSize(this.#n);for(let e of r.values()){let t=e.atmosphere?.material.uniforms;t&&(t.uSceneDepth.value=this.#e.depthTexture,t.uCamForward.value.copy(this.#t),t.uReversedDepth.value=+!!yw(),t.uCameraNear.value=n.near,t.uCameraFar.value=n.far,t.uResolution.value.copy(this.#n))}}#a(e,t){if(!e.visible)return;let n=e.material;if(Array.isArray(n))return;let r=this.#r.get(n);r||(r=new Au,yL(n,r),this.#r.set(n,r));let i=n;(r.displacementMap??null)!==(i.displacementMap??null)&&(r.displacementMap=i.displacementMap??null,r.needsUpdate=!0),r.displacementScale=i.displacementScale??1,r.displacementBias=i.displacementBias??0,r.side=i.side,this.#i.push({mesh:e,material:n}),e.material=r,e.layers.enable(t)}dispose(){this.#e.depthTexture?.dispose(),this.#e.dispose()}};function OL(e,t){let n=new _a(e,t);return n.depthTexture=new qc(e,t,Yn),n}var kL=class{wanted=new Map;reverting=new Set;set(e,t){let n={...t};n.surface===void 0&&n.night===void 0&&n.clouds===void 0?this.wanted.delete(e):this.wanted.set(e,n),this.reverting.add(e)}get(e){let t=this.wanted.get(e);return t&&{...t}}ownsSurface(e){return this.wanted.get(e)?.surface!==void 0}apply(e,t){if(!(this.wanted.size===0&&this.reverting.size===0)){for(let t of this.reverting){let n=e.get(t);n&&AL(n,this.wanted.get(t))}this.reverting.clear();for(let[n,r]of this.wanted){let i=e.get(n);i?.mesh&&(r.surface!==void 0&&((i.appearance??={}).surfaceOwned=!0),jL(i,r,t,()=>this.wanted.get(n)))}}}};function AL(e,t){let n=e.appearance;if(!n||!e.mesh)return;let r=e.mesh.material;if(n.surfaceOwned&&t?.surface===void 0&&(n.surfaceMap?.dispose(),r.map=null,UA(e.body.data,r.color),r.needsUpdate=!0,e.model&&kA(e.model,null,r.color),n.surfaceOwned=void 0,n.surfaceUrl=void 0,n.surfaceMap=void 0,e.textureTier=void 0),n.nightUrl!==void 0&&t?.night===void 0){let e=n.displacedNight;n.nightMap?.dispose(),e?aN(r,e):oN(r),n.nightUrl=void 0,n.nightMap=void 0,n.displacedNight=void 0}if(n.cloudsUrl!==void 0&&t?.clouds===void 0){n.cloudsMap?.dispose();let t=e.clouds;t&&n.ownCloudNode?(t.mesh.geometry.dispose(),t.material.dispose(),t.mesh.parent?.remove(t.mesh),e.clouds=null):t&&(t.material.map=n.displacedClouds??null,t.material.needsUpdate=!0,t.availableTiers=n.displacedCloudTiers??[],t.availableFrames=n.displacedCloudFrames??[]),n.cloudsUrl=void 0,n.cloudsMap=void 0,n.displacedClouds=void 0,n.ownCloudNode=void 0}}async function jL(e,t,n,r){let i=e.appearance??={};if(i.loading)return;let a=NL(e);if(!a)return;let o=t.surface!==void 0&&(t.surface!==i.surfaceUrl||a.map!==i.surfaceMap),s=t.night!==void 0&&(t.night!==i.nightUrl||a.emissiveMap!==i.nightMap),c=t.clouds!==void 0&&(t.clouds!==i.cloudsUrl||e.clouds?.material.map!==i.cloudsMap);if(!(!o&&!s&&!c)){i.loading=!0;try{if(o){let a=await PL(t.surface,n);if(r()!==t)return void a?.dispose();let o=NL(e);a&&o&&(AA(o,a),e.model&&kA(e.model,a,UA(e.body.data)),i.surfaceUrl=t.surface,i.surfaceMap=a)}if(s){let a=await PL(t.night,n);if(r()!==t)return void a?.dispose();let o=NL(e);a&&o&&(i.displacedNight??=o.emissiveMap,aN(o,a),i.nightUrl=t.night,i.nightMap=a)}if(c){let a=await PL(t.clouds,n);if(r()!==t)return void a?.dispose();a&&e.mesh&&ML(e,i,a,t.clouds)}}finally{i.loading=!1}}}function ML(e,t,n,r){n.anisotropy=16;let i=e.clouds;if(i)t.ownCloudNode||(t.displacedClouds??=i.material.map,t.displacedCloudTiers??=i.availableTiers,t.displacedCloudFrames??=i.availableFrames),i.material.map=n,i.material.needsUpdate=!0;else{if(!e.mesh)return;i=ZM(e.mesh,e.radiusScene,n),e.clouds=i,t.ownCloudNode=!0}i.availableTiers=[],i.availableFrames=[],t.cloudsUrl=r,t.cloudsMap=n}function NL(e){return e.mesh?e.mesh.material:null}async function PL(e,t){try{let n=await new Promise((n,r)=>{t.load(e,n,void 0,r)});return n.colorSpace=ri,n}catch(t){return console.warn(`spacemap: could not load the picture at ${e}:`,t),null}}var FL=`
|
|
6334
6334
|
void main() {
|
|
6335
6335
|
gl_Position = vec4(position.xy, 0.0, 1.0);
|
|
6336
6336
|
}
|
|
6337
|
-
`,
|
|
6337
|
+
`,IL=`
|
|
6338
6338
|
uniform sampler2D uSceneDepth;
|
|
6339
6339
|
uniform vec2 uResolution;
|
|
6340
6340
|
uniform float uReversed;
|
|
@@ -6357,13 +6357,13 @@ void main() {
|
|
|
6357
6357
|
? uNear * (uFar - w) / (w * (uFar - uNear))
|
|
6358
6358
|
: ${ww(`w`,`uFar`)};
|
|
6359
6359
|
}
|
|
6360
|
-
`,IL=class{#e=new Tu({uniforms:{uSceneDepth:{value:null},uResolution:{value:new q(1,1)},uReversed:{value:0},uSceneNear:{value:1},uSceneFar:{value:2},uNear:{value:1},uFar:{value:2},uUnit:{value:1},uFront:{value:0}},vertexShader:PL,fragmentShader:FL,colorWrite:!1});#t=new ZF(this.#e);run(e,t,n,r,i,a){let o=this.#e.uniforms;o.uSceneDepth.value=t,e.getDrawingBufferSize(o.uResolution.value),o.uReversed.value=+!!yw(),o.uSceneNear.value=n.near,o.uSceneFar.value=n.far,o.uNear.value=r.near,o.uFar.value=r.far,o.uUnit.value=i,o.uFront.value=a,this.#t.render(e)}dispose(){this.#t.dispose(),this.#e.dispose()}},LL=34028235e31,RL=3;function zL(e){return new X(e).multiplyScalar(.5)}function BL(){let e=document.createElement(`canvas`);e.width=32,e.height=32;let t=e.getContext(`2d`);return t.beginPath(),t.arc(32/2,32/2,32/2-2,0,Math.PI*2),t.fillStyle=`#aaaaaa`,t.globalAlpha=.3,t.fill(),new Kc(e)}function VL(){return typeof window>`u`?3:window.matchMedia(`(max-width: 768px)`).matches?2:3}function HL(e,t,n,r=[0,0,0],i=4,a=null){let o=[];for(let t of e){let e=t.position;e&&Math.max(Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2]))<=LL&&o.push({body:t,at:e})}let s=new Float32Array(o.length*3),c=a?new Float32Array(o.length*3):null,l=c?new X:null;for(let e=0;e<o.length;e++){let{body:t,at:n}=o[e];s[e*3]=n[0]-r[0],s[e*3+1]=n[1]-r[1],s[e*3+2]=n[2]-r[2],c&&l&&a&&(l.set(a(t)),c[e*3]=l.r,c[e*3+1]=l.g,c[e*3+2]=l.b)}let u=new ts;u.setAttribute(`position`,new Uo(s,3)),c&&u.setAttribute(`color`,new Uo(c,3));let d=new Uc(u,new Rc({map:t,color:c?new X(.5,.5,.5):zL(n),vertexColors:!!c,transparent:!0,size:i,sizeAttenuation:!1,depthTest:!0,depthWrite:!1}));return d.frustumCulled=!1,d.renderOrder=RL,d}function UL(e,t,n,r,i=4,a=null){let o=new ts;o.setAttribute(`position`,new Bo(e,3)),a&&o.setAttribute(`color`,new Bo(a,3)),o.setDrawRange(0,t);let s=new Uc(o,new Rc({map:n,color:a?new X(.5,.5,.5):zL(r),vertexColors:!!a,transparent:!0,size:i,sizeAttenuation:!1,depthTest:!0,depthWrite:!1}));return s.frustumCulled=!1,s.renderOrder=RL,s}function WL(e,t=512,n=50){let r=e.q??e.a;if(!isFinite(r)||r<=0)return[];let i=Math.max(2*r/n-1,-.999),a=Math.acos(i),o=[];for(let n=0;n<=t;n++){let i=-a+2*a*n/t,s=2*r/(1+Math.cos(i)),c=s*Math.cos(i),l=s*Math.sin(i);o.push(__(c,l,e.w,e.i,e.om,e.equatorial))}return o}function GL(e,t=128){let{a:n,i:r,om:i,w:a}=e,o=Math.min(e.e,.9999999),s=1+3*o,c=Math.sqrt(1-o*o),l=[];for(let u=0;u<=t;u++){let d=2*u/t-1,f=Math.PI*Math.sign(d)*Math.abs(d)**+s,p=Math.cos(f),m=Math.sin(f),h=1-o*p,g=c*m/h,_=(p-o)/h,v=Math.atan2(g,_),y=n*h,b=y*Math.cos(v),x=y*Math.sin(v);!isFinite(b)||!isFinite(x)||l.push(__(b,x,a,r,i,e.equatorial))}return l}function KL(e,t=512,n=50){let r=Math.abs(e.a),i=r>0?(n/r+1)/e.e:100,a=Math.min(Math.acosh(Math.max(i,1)),6),o=[];for(let n=0;n<=t;n++){let r=-a+2*a*n/t,i=e.e*Math.cosh(r)-1;if(Math.abs(i)<1e-15)continue;let s=Math.sqrt(e.e*e.e-1)*Math.sinh(r)/i,c=(e.e-Math.cosh(r))/i,l=Math.atan2(s,c),u=e.a*(1-e.e*Math.cosh(r)),d=u*Math.cos(l),f=u*Math.sin(l);o.push(__(d,f,e.w,e.i,e.om,e.equatorial))}return o}function qL(e,t,n,r=128){if(!isFinite(n)||n<=0)return[];let i=1/n,a=[];for(let n=0;n<=r;n++){let o=o_(e,t-i+i*n/r);o&&a.push(o)}return a}function JL(e){return!(isFinite(e.a)&&e.a>0)&&(e.q!=null||e.e>=1)}function YL(e,t=512){let n=isFinite(e.a)&&e.a>0;return!n&&e.q!=null?{points:WL(e,t),isOpen:!0}:!n&&e.e>=1?{points:KL(e,t),isOpen:!0}:{points:GL(e,t),isOpen:!1}}var XL=3;function ZL(e){let t=2*e,n=new Float32Array(t*3),r=new Float32Array(t*3),i=new Float32Array(t),a=new Float32Array(t),o=new Float32Array(t);for(let t=0;t<e;t++)i[2*t]=-1,i[2*t+1]=1;let s=new Uint16Array(Math.max(0,6*(e-1)));for(let t=0;t<e-1;t++){let e=2*t,n=2*t+1,r=2*(t+1),i=2*(t+1)+1,a=t*6;s[a]=e,s[a+1]=n,s[a+2]=r,s[a+3]=r,s[a+4]=n,s[a+5]=i}let c=new ts;return c.setAttribute(`position`,new Uo(n,3)),c.setAttribute(`nextPosition`,new Uo(r,3)),c.setAttribute(`side`,new Uo(i,1)),c.setAttribute(`trailAlpha`,new Uo(a,1)),c.setAttribute(`fullAlpha`,new Uo(o,1)),c.setIndex(new Vo(s,1)),c}function QL(e,t,n,r,i){let a=e.getAttribute(`position`),o=e.getAttribute(`nextPosition`),s=e.getAttribute(`trailAlpha`),c=e.getAttribute(`fullAlpha`),l=a.array,u=o.array,d=s.array,f=c.array,p=d.length/2,m=Math.min(i,p);for(let e=0;e<m;e++){let i=t[e*3],a=t[e*3+1],o=t[e*3+2],s=e<m-1?e+1:e,c=t[s*3],p=t[s*3+1],h=t[s*3+2],g=2*e*3;l[g]=i,l[g+1]=a,l[g+2]=o,l[g+3]=i,l[g+4]=a,l[g+5]=o,u[g]=c,u[g+1]=p,u[g+2]=h,u[g+3]=c,u[g+4]=p,u[g+5]=h;let _=n[e],v=r[e];d[2*e]=_,d[2*e+1]=_,f[2*e]=v,f[2*e+1]=v}a.needsUpdate=!0,o.needsUpdate=!0,s.needsUpdate=!0,c.needsUpdate=!0,e.setDrawRange(0,Math.max(0,6*(m-1)))}function $L(){let e=new ts;e.setAttribute(`position`,new Uo(new Float32Array(6),3));let t=new Mc(e,new Tu({transparent:!0}));return t.matrixAutoUpdate=!1,t.visible=!1,t.renderOrder=XL,t}function eR(e,t,n,r,i){let a=new ts;a.setAttribute(`position`,new Uo(e,3)),a.setAttribute(`trailAlpha`,new Uo(t,1)),a.setAttribute(`fullAlpha`,new Uo(n,1)),a.setDrawRange(0,r);let o=new Mc(a,mI(i));return o.matrixAutoUpdate=!1,o.renderOrder=XL,o}function tR(e,t,n){let r=e.getAttribute(`lineDistance`),i=r.array,a=Math.min(n,i.length/2);for(let e=0;e<a;e++)i[2*e]=i[2*e+1]=t[e];r.needsUpdate=!0}function nR(e,t,n,r,i,a,o,s,c){let l=ZL(e);c&&l.setAttribute(`lineDistance`,new Uo(new Float32Array(2*e),1)),QL(l,t,n,r,i);let u=new Us(l,hI(a,o,s,c));return u.matrixAutoUpdate=!1,u.renderOrder=XL,u}function rR(e){if(e.userData.isFatLine){let t=e.userData.thinPositions;return{posArr:t,trailArr:e.userData.thinTrailAlphas,fullArr:e.userData.thinFullAlphas,capacity:t.length/3}}let t=e.geometry.getAttribute(`position`);return{posArr:t.array,trailArr:e.geometry.getAttribute(`trailAlpha`).array,fullArr:e.geometry.getAttribute(`fullAlpha`).array,capacity:t.count}}function iR(e,t,n,r,i,a,o){if(i<2){e.geometry.setDrawRange(0,0),e.userData.isFatLine||(e.geometry.getAttribute(`position`).needsUpdate=!0);return}if(Nb(r.subarray(0,i),n.subarray(0,i),a,o),e.userData.isFatLine){QL(e.geometry,t,n,r,i);return}e.geometry.setDrawRange(0,i),e.geometry.getAttribute(`position`).needsUpdate=!0,e.geometry.getAttribute(`trailAlpha`).needsUpdate=!0,e.geometry.getAttribute(`fullAlpha`).needsUpdate=!0}var aR=1.5;function oR(e){return e>1||CE()>=aR}function sR(e,t,n,r,i,a,o,s){let c=e.trailAnchor??e.position;if(!c)return 0;n[0]=c[0]-o[0],n[1]=c[1]-o[1],n[2]=c[2]-o[2];let l=r-o[0],u=i-o[1],d=a-o[2];return 1+t.writeVertices(n.subarray(3),l,u,d,s)}function cR(e,t,n,r,i){let{orbitCenter:a,data:o}=e,s=a?.[0]??0,c=a?.[1]??0,l=a?.[2]??0,u=o.objectType===G.SPACECRAFT||o.objectType===G.DWARF_PLANET||o.objectType===G.MOON||o.objectType===G.COMET||xn(o.objectType),d=t.capacity+1,f=new Float32Array(d*3),p=sR(e,t,f,s,c,l,r),m=new Float32Array(d),h=new Float32Array(d);p>0&&Nb(m.subarray(0,p),h.subarray(0,p),!0,u);let g=oR(i),_=g?nR(d,f,h,m,p,n,i):eR(f,h,m,p,n);return _.frustumCulled=!1,_.visible=!1,_.userData.orbitCenter=new J(s,c,l),_.userData.trailBuffer=t,_.userData.useTrail=u,g&&(_.userData.isFatLine=!0,_.userData.thinPositions=f,_.userData.thinTrailAlphas=h,_.userData.thinFullAlphas=m),_}function lR(e,t,n=[0,0,0],r=Ag(new Date),i=1){if(e.trailBuffer)return cR(e,e.trailBuffer,t,n,i);let{orbitElements:a,orbitCenter:o,data:s}=e,c,l,u;if(s.satrec)c=qL(s.satrec,r,s.n/360,512),l=!0,u=c.length-1;else{if(!a)throw Error(`makeTrail called without orbitElements`);c=null,l=JL(a)}let d=o?.[0]??0,f=o?.[1]??0,p=o?.[2]??0,m=l||s.objectType===G.DWARF_PLANET||s.objectType===G.MOON||s.objectType===G.SPACECRAFT||s.objectType===G.COMET||xn(s.objectType),h=c?Mb(e,c,l,d,f,p,u):[];if(c&&h.length<2)return $L();let g=c?Math.max(h.length,c.length):513,_=new Float32Array(g),v=new Float32Array(g);Nb(_.subarray(0,h.length),v.subarray(0,h.length),l,m);let y=d-n[0],b=f-n[1],x=p-n[2],S=new Float32Array(g*3);for(let e=0;e<h.length;e++)S[e*3]=h[e][0]+y,S[e*3+1]=h[e][1]+b,S[e*3+2]=h[e][2]+x;let C=oR(i),w=C?nR(g,S,v,_,h.length,t,i):eR(S,v,_,h.length,t);return w.frustumCulled=!1,w.visible=!1,w.userData.orbitCenter=new J(d,f,p),w.userData.trailLocalPositions=c?h:void 0,w.userData.sourceCurve=c??void 0,w.userData.curvePending=c===null,w.userData.isOpenCurve=l,w.userData.useTrail=m,w.userData.curveJd=r,w.userData.elementsJd=a?.epoch??r,C&&(w.userData.isFatLine=!0,w.userData.thinPositions=S,w.userData.thinTrailAlphas=v,w.userData.thinFullAlphas=_),w}function uR(e,t){if(!t||t.size===0)return[...e];let n=[];for(let r of e)t.has(r.data.id)||n.push(r);return n}function dR(e){return e.data.objectType===G.PLANET?4:(e.data.objectType===G.MOON||e.data.objectType===G.DWARF_PLANET)&&U_[e.data.id]?3:1}function fR(e,t,n=[0,0,0],r){for(let[,i]of e){if(i.trail!==null)continue;let{body:e}=i;if(e.data.objectType===G.STAR)continue;if(e.data.orbitalSource===W.SPICE_PROBE){if(i.isMinor&&!i.mesh)continue}else if(!i.mesh&&!i.focusUpgraded&&CL(e))continue;if(!e.orbitElements&&e.rederiveElements&&r!==void 0){let t=e.rederiveElements(r);t&&(e.orbitElements=t)}if(!e.orbitElements&&!e.trailBuffer)continue;let a=lR(e,iv(e.data),n,r,dR(e));t.add(a),i.trail=a}}function pR(e,t,n,r=[0,0,0],i,a){let o=new Map,s=new Map,c=new Map,l=VL();for(let[s,c]of e.bodies.asteroidBodiesByZone){let e=uR(c.values(),i);if(e.length===0)continue;let u=iv(e[0].data),{buckets:d}=sv(s,e,a);for(let e=0;e<d.length;e++){let i=d[e];if(i.length===0)continue;let a=HL(i,n,u,r,l);a.userData.groupId=`asteroid:${s}#${e}`,a.userData.parentVec=[0,0,0],o.set(`${s}#${e}`,a),t.add(a)}}for(let[o,c]of e.bodies.spacecraftByParent.entries()){let l=uy(e.layers,o,uR(c.values(),i));if(l.length===0)continue;let{buckets:u}=sv(o,l,a);for(let e=0;e<u.length;e++){let i=u[e];if(i.length===0)continue;let a=HL(i,n,`#ffffff`,r,void 0,e=>iv(e.data));a.userData.groupId=`spacecraft:${o}#${e}`,a.userData.parentBodyId=o,a.userData.parentVec=[0,0,0],s.set(`${o}#${e}`,a),t.add(a)}}let u=new Map;for(let t of e.bodies.majorBodies)if(t.data.objectType===G.MOON){let e=u.get(t.data.parentId)??[];e.push(t),u.set(t.data.parentId,e)}for(let[e,i]of u){let a=HL(i,n,iv(i[0].data),r),o=a.material;o.transparent=!1,o.alphaTest=.5,o.depthTest=!0,o.depthWrite=!0,a.visible=!1,c.set(e,a),t.add(a)}return{asteroidPoints:o,spacecraftPoints:s,moonPoints:c}}var mR=class{lastBaryId=null;pendingUnloads=new Set;prefetched=new Set;constructor(e,t,n,r,i,a,o){this.scene=e,this.ctx=t,this.renderer=n,this.textureLoader=r,this.bodyObjects=i,this.clock=a,this.onLoaded=o}syncToFocus(){let e=this.ctx.visibility.focusedSystemId,t=e?this.resolveBaryId(e):null;if(!t){this.lastBaryId&&=(this.pendingUnloads.add(this.lastBaryId),null);return}t!==this.lastBaryId&&(this.lastBaryId&&this.pendingUnloads.add(this.lastBaryId),this.pendingUnloads.delete(t),this.prefetched.delete(t),this.lastBaryId=t,this.load(t))}prefetch(e){let t=this.resolveBaryId(e);!t||t===this.lastBaryId||this.prefetched.has(t)||(this.prefetched.add(t),this.pendingUnloads.delete(t),this.load(t))}discardPrefetch(e){let t=this.resolveBaryId(e);!t||!this.prefetched.delete(t)||t!==this.lastBaryId&&this.pendingUnloads.add(t)}resolveBaryId(e){let t=this.ctx.getBody(e);if(t?.data.objectType===G.BARYCENTER)return e;let n=t?.data.parentId??e;return yv(n)?null:n}load(e){SP(e,this.bodyObjects,this.scene,this.textureLoader,this.clock.jd,this.renderer.capabilities.maxTextureSize,this.ctx).then(()=>{this.onLoaded(),this.ctx.bodies.orientationVersion++})}drainPendingUnloads(){if(this.pendingUnloads.size!==0){for(let e of this.pendingUnloads)CP(e,this.bodyObjects,this.scene,this.ctx);this.pendingUnloads.clear()}}hasPendingUnloads(){return this.pendingUnloads.size>0}},hR=Math.PI/180,gR=class{adjust={rxDeg:0,ryDeg:0,rzDeg:0};_q=new Xi;_adjustQ=new Xi;_tmpQ=new Xi;_axisX=new J(1,0,0);_axisY=new J(0,1,0);_axisZ=new J(0,0,1);constructor(e){this.scene=e}get(){return{...this.adjust}}set(e,t,n){this.adjust.rxDeg=e,this.adjust.ryDeg=t,this.adjust.rzDeg=n,this._adjustQ.setFromAxisAngle(this._axisX,e*hR).premultiply(this._tmpQ.setFromAxisAngle(this._axisY,t*hR)).premultiply(this._tmpQ.setFromAxisAngle(this._axisZ,n*hR)),this._q.copy(MP).multiply(this._adjustQ),this.scene.backgroundRotation.setFromQuaternion(this._q)}},_R=Math.PI/180,vR=vg*_R,yR=Math.cos(vR),bR=Math.sin(vR),xR=5e3,SR=[{id:`galactic-center`,label:`Galactic Center`,raDeg:266.41683,decDeg:-29.00781,color:`#ff6b35`},{id:`galactic-anticenter`,label:`Galactic Anticenter`,raDeg:86.4,decDeg:28.93785,color:`#ff6b35`},{id:`galactic-np`,label:`Galactic NP`,raDeg:192.85948,decDeg:27.12825,color:`#ffb84d`},{id:`galactic-sp`,label:`Galactic SP`,raDeg:12.85948,decDeg:-27.12825,color:`#ffb84d`},{id:`ncp`,label:`NCP (Polaris ≈)`,raDeg:37.9542,decDeg:89.2641,color:`#4dd0ff`},{id:`scp`,label:`SCP`,raDeg:0,decDeg:-90,color:`#4dd0ff`},{id:`vernal`,label:`Vernal Equinox (γ)`,raDeg:0,decDeg:0,color:`#9d8cff`},{id:`autumnal`,label:`Autumnal Equinox`,raDeg:180,decDeg:0,color:`#9d8cff`},{id:`m31`,label:`M31 (Andromeda)`,raDeg:10.6847,decDeg:41.2692,color:`#ffffff`},{id:`lmc`,label:`LMC (Large Magellanic Cloud)`,raDeg:80.8942,decDeg:-69.7561,color:`#ffffff`},{id:`smc`,label:`SMC (Small Magellanic Cloud)`,raDeg:13.1583,decDeg:-72.8003,color:`#ffffff`},{id:`sirius`,label:`Sirius`,raDeg:101.2872,decDeg:-16.7161,color:`#ffffff`}],CR=192.85948,wR=27.12825,TR=266.40499,ER=-28.93617,DR=256,OR=[{name:`galactic-plane`,zero:kR(TR,ER,new J).normalize(),pole:kR(CR,wR,new J).normalize(),color:16739125},{name:`ecliptic-plane`,zero:new J(1,0,0),pole:new J(0,1,0),color:5099775},{name:`celestial-equator`,zero:kR(0,0,new J).normalize(),pole:kR(0,90,new J).normalize(),color:10325247}];function kR(e,t,n){let r=e*_R,i=t*_R,a=Math.cos(i),o=a*Math.cos(r),s=a*Math.sin(r),c=Math.sin(i),l=o,u=s*yR+c*bR,d=-s*bR+c*yR;return n.set(l,d,-u)}function AR(e){let t=document.createElement(`div`);t.className=`sky-debug-marker`,t.style.cssText=[`display:flex`,`align-items:center`,`gap:4px`,`font:11px/1 monospace`,`text-shadow:0 0 3px #000, 0 0 3px #000`,`pointer-events:none`,`white-space:nowrap`].join(`;`);let n=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);n.setAttribute(`width`,`48`),n.setAttribute(`height`,`48`),n.setAttribute(`viewBox`,`-24 -24 48 48`),n.style.cssText=`flex:0 0 auto;filter:drop-shadow(0 0 2px #000);margin-inline-start:-24px`;let r=e.color;n.innerHTML=`
|
|
6360
|
+
`,LL=class{#e=new Tu({uniforms:{uSceneDepth:{value:null},uResolution:{value:new q(1,1)},uReversed:{value:0},uSceneNear:{value:1},uSceneFar:{value:2},uNear:{value:1},uFar:{value:2},uUnit:{value:1},uFront:{value:0}},vertexShader:FL,fragmentShader:IL,colorWrite:!1});#t=new QF(this.#e);run(e,t,n,r,i,a){let o=this.#e.uniforms;o.uSceneDepth.value=t,e.getDrawingBufferSize(o.uResolution.value),o.uReversed.value=+!!yw(),o.uSceneNear.value=n.near,o.uSceneFar.value=n.far,o.uNear.value=r.near,o.uFar.value=r.far,o.uUnit.value=i,o.uFront.value=a,this.#t.render(e)}dispose(){this.#t.dispose(),this.#e.dispose()}},RL=34028235e31,zL=3;function BL(e){return new X(e).multiplyScalar(.5)}function VL(){let e=document.createElement(`canvas`);e.width=32,e.height=32;let t=e.getContext(`2d`);return t.beginPath(),t.arc(32/2,32/2,32/2-2,0,Math.PI*2),t.fillStyle=`#aaaaaa`,t.globalAlpha=.3,t.fill(),new Kc(e)}function HL(){return typeof window>`u`?3:window.matchMedia(`(max-width: 768px)`).matches?2:3}function UL(e,t,n,r=[0,0,0],i=4,a=null){let o=[];for(let t of e){let e=t.position;e&&Math.max(Math.abs(e[0]),Math.abs(e[1]),Math.abs(e[2]))<=RL&&o.push({body:t,at:e})}let s=new Float32Array(o.length*3),c=a?new Float32Array(o.length*3):null,l=c?new X:null;for(let e=0;e<o.length;e++){let{body:t,at:n}=o[e];s[e*3]=n[0]-r[0],s[e*3+1]=n[1]-r[1],s[e*3+2]=n[2]-r[2],c&&l&&a&&(l.set(a(t)),c[e*3]=l.r,c[e*3+1]=l.g,c[e*3+2]=l.b)}let u=new ts;u.setAttribute(`position`,new Uo(s,3)),c&&u.setAttribute(`color`,new Uo(c,3));let d=new Uc(u,new Rc({map:t,color:c?new X(.5,.5,.5):BL(n),vertexColors:!!c,transparent:!0,size:i,sizeAttenuation:!1,depthTest:!0,depthWrite:!1}));return d.frustumCulled=!1,d.renderOrder=zL,d}function WL(e,t,n,r,i=4,a=null){let o=new ts;o.setAttribute(`position`,new Bo(e,3)),a&&o.setAttribute(`color`,new Bo(a,3)),o.setDrawRange(0,t);let s=new Uc(o,new Rc({map:n,color:a?new X(.5,.5,.5):BL(r),vertexColors:!!a,transparent:!0,size:i,sizeAttenuation:!1,depthTest:!0,depthWrite:!1}));return s.frustumCulled=!1,s.renderOrder=zL,s}function GL(e,t=512,n=50){let r=e.q??e.a;if(!isFinite(r)||r<=0)return[];let i=Math.max(2*r/n-1,-.999),a=Math.acos(i),o=[];for(let n=0;n<=t;n++){let i=-a+2*a*n/t,s=2*r/(1+Math.cos(i)),c=s*Math.cos(i),l=s*Math.sin(i);o.push(__(c,l,e.w,e.i,e.om,e.equatorial))}return o}function KL(e,t=128){let{a:n,i:r,om:i,w:a}=e,o=Math.min(e.e,.9999999),s=1+3*o,c=Math.sqrt(1-o*o),l=[];for(let u=0;u<=t;u++){let d=2*u/t-1,f=Math.PI*Math.sign(d)*Math.abs(d)**+s,p=Math.cos(f),m=Math.sin(f),h=1-o*p,g=c*m/h,_=(p-o)/h,v=Math.atan2(g,_),y=n*h,b=y*Math.cos(v),x=y*Math.sin(v);!isFinite(b)||!isFinite(x)||l.push(__(b,x,a,r,i,e.equatorial))}return l}function qL(e,t=512,n=50){let r=Math.abs(e.a),i=r>0?(n/r+1)/e.e:100,a=Math.min(Math.acosh(Math.max(i,1)),6),o=[];for(let n=0;n<=t;n++){let r=-a+2*a*n/t,i=e.e*Math.cosh(r)-1;if(Math.abs(i)<1e-15)continue;let s=Math.sqrt(e.e*e.e-1)*Math.sinh(r)/i,c=(e.e-Math.cosh(r))/i,l=Math.atan2(s,c),u=e.a*(1-e.e*Math.cosh(r)),d=u*Math.cos(l),f=u*Math.sin(l);o.push(__(d,f,e.w,e.i,e.om,e.equatorial))}return o}function JL(e,t,n,r=128){if(!isFinite(n)||n<=0)return[];let i=1/n,a=[];for(let n=0;n<=r;n++){let o=o_(e,t-i+i*n/r);o&&a.push(o)}return a}function YL(e){return!(isFinite(e.a)&&e.a>0)&&(e.q!=null||e.e>=1)}function XL(e,t=512){let n=isFinite(e.a)&&e.a>0;return!n&&e.q!=null?{points:GL(e,t),isOpen:!0}:!n&&e.e>=1?{points:qL(e,t),isOpen:!0}:{points:KL(e,t),isOpen:!1}}var ZL=3;function QL(e){let t=2*e,n=new Float32Array(t*3),r=new Float32Array(t*3),i=new Float32Array(t),a=new Float32Array(t),o=new Float32Array(t);for(let t=0;t<e;t++)i[2*t]=-1,i[2*t+1]=1;let s=new Uint16Array(Math.max(0,6*(e-1)));for(let t=0;t<e-1;t++){let e=2*t,n=2*t+1,r=2*(t+1),i=2*(t+1)+1,a=t*6;s[a]=e,s[a+1]=n,s[a+2]=r,s[a+3]=r,s[a+4]=n,s[a+5]=i}let c=new ts;return c.setAttribute(`position`,new Uo(n,3)),c.setAttribute(`nextPosition`,new Uo(r,3)),c.setAttribute(`side`,new Uo(i,1)),c.setAttribute(`trailAlpha`,new Uo(a,1)),c.setAttribute(`fullAlpha`,new Uo(o,1)),c.setIndex(new Vo(s,1)),c}function $L(e,t,n,r,i){let a=e.getAttribute(`position`),o=e.getAttribute(`nextPosition`),s=e.getAttribute(`trailAlpha`),c=e.getAttribute(`fullAlpha`),l=a.array,u=o.array,d=s.array,f=c.array,p=d.length/2,m=Math.min(i,p);for(let e=0;e<m;e++){let i=t[e*3],a=t[e*3+1],o=t[e*3+2],s=e<m-1?e+1:e,c=t[s*3],p=t[s*3+1],h=t[s*3+2],g=2*e*3;l[g]=i,l[g+1]=a,l[g+2]=o,l[g+3]=i,l[g+4]=a,l[g+5]=o,u[g]=c,u[g+1]=p,u[g+2]=h,u[g+3]=c,u[g+4]=p,u[g+5]=h;let _=n[e],v=r[e];d[2*e]=_,d[2*e+1]=_,f[2*e]=v,f[2*e+1]=v}a.needsUpdate=!0,o.needsUpdate=!0,s.needsUpdate=!0,c.needsUpdate=!0,e.setDrawRange(0,Math.max(0,6*(m-1)))}function eR(){let e=new ts;e.setAttribute(`position`,new Uo(new Float32Array(6),3));let t=new Mc(e,new Tu({transparent:!0}));return t.matrixAutoUpdate=!1,t.visible=!1,t.renderOrder=ZL,t}function tR(e,t,n,r,i){let a=new ts;a.setAttribute(`position`,new Uo(e,3)),a.setAttribute(`trailAlpha`,new Uo(t,1)),a.setAttribute(`fullAlpha`,new Uo(n,1)),a.setDrawRange(0,r);let o=new Mc(a,hI(i));return o.matrixAutoUpdate=!1,o.renderOrder=ZL,o}function nR(e,t,n){let r=e.getAttribute(`lineDistance`),i=r.array,a=Math.min(n,i.length/2);for(let e=0;e<a;e++)i[2*e]=i[2*e+1]=t[e];r.needsUpdate=!0}function rR(e,t,n,r,i,a,o,s,c){let l=QL(e);c&&l.setAttribute(`lineDistance`,new Uo(new Float32Array(2*e),1)),$L(l,t,n,r,i);let u=new Us(l,gI(a,o,s,c));return u.matrixAutoUpdate=!1,u.renderOrder=ZL,u}function iR(e){if(e.userData.isFatLine){let t=e.userData.thinPositions;return{posArr:t,trailArr:e.userData.thinTrailAlphas,fullArr:e.userData.thinFullAlphas,capacity:t.length/3}}let t=e.geometry.getAttribute(`position`);return{posArr:t.array,trailArr:e.geometry.getAttribute(`trailAlpha`).array,fullArr:e.geometry.getAttribute(`fullAlpha`).array,capacity:t.count}}function aR(e,t,n,r,i,a,o){if(i<2){e.geometry.setDrawRange(0,0),e.userData.isFatLine||(e.geometry.getAttribute(`position`).needsUpdate=!0);return}if(Nb(r.subarray(0,i),n.subarray(0,i),a,o),e.userData.isFatLine){$L(e.geometry,t,n,r,i);return}e.geometry.setDrawRange(0,i),e.geometry.getAttribute(`position`).needsUpdate=!0,e.geometry.getAttribute(`trailAlpha`).needsUpdate=!0,e.geometry.getAttribute(`fullAlpha`).needsUpdate=!0}var oR=1.5;function sR(e){return e>1||CE()>=oR}function cR(e,t,n,r,i,a,o,s){let c=e.trailAnchor??e.position;if(!c)return 0;n[0]=c[0]-o[0],n[1]=c[1]-o[1],n[2]=c[2]-o[2];let l=r-o[0],u=i-o[1],d=a-o[2];return 1+t.writeVertices(n.subarray(3),l,u,d,s)}function lR(e,t,n,r,i){let{orbitCenter:a,data:o}=e,s=a?.[0]??0,c=a?.[1]??0,l=a?.[2]??0,u=o.objectType===G.SPACECRAFT||o.objectType===G.DWARF_PLANET||o.objectType===G.MOON||o.objectType===G.COMET||xn(o.objectType),d=t.capacity+1,f=new Float32Array(d*3),p=cR(e,t,f,s,c,l,r),m=new Float32Array(d),h=new Float32Array(d);p>0&&Nb(m.subarray(0,p),h.subarray(0,p),!0,u);let g=sR(i),_=g?rR(d,f,h,m,p,n,i):tR(f,h,m,p,n);return _.frustumCulled=!1,_.visible=!1,_.userData.orbitCenter=new J(s,c,l),_.userData.trailBuffer=t,_.userData.useTrail=u,g&&(_.userData.isFatLine=!0,_.userData.thinPositions=f,_.userData.thinTrailAlphas=h,_.userData.thinFullAlphas=m),_}function uR(e,t,n=[0,0,0],r=Ag(new Date),i=1){if(e.trailBuffer)return lR(e,e.trailBuffer,t,n,i);let{orbitElements:a,orbitCenter:o,data:s}=e,c,l,u;if(s.satrec)c=JL(s.satrec,r,s.n/360,512),l=!0,u=c.length-1;else{if(!a)throw Error(`makeTrail called without orbitElements`);c=null,l=YL(a)}let d=o?.[0]??0,f=o?.[1]??0,p=o?.[2]??0,m=l||s.objectType===G.DWARF_PLANET||s.objectType===G.MOON||s.objectType===G.SPACECRAFT||s.objectType===G.COMET||xn(s.objectType),h=c?Mb(e,c,l,d,f,p,u):[];if(c&&h.length<2)return eR();let g=c?Math.max(h.length,c.length):513,_=new Float32Array(g),v=new Float32Array(g);Nb(_.subarray(0,h.length),v.subarray(0,h.length),l,m);let y=d-n[0],b=f-n[1],x=p-n[2],S=new Float32Array(g*3);for(let e=0;e<h.length;e++)S[e*3]=h[e][0]+y,S[e*3+1]=h[e][1]+b,S[e*3+2]=h[e][2]+x;let C=sR(i),w=C?rR(g,S,v,_,h.length,t,i):tR(S,v,_,h.length,t);return w.frustumCulled=!1,w.visible=!1,w.userData.orbitCenter=new J(d,f,p),w.userData.trailLocalPositions=c?h:void 0,w.userData.sourceCurve=c??void 0,w.userData.curvePending=c===null,w.userData.isOpenCurve=l,w.userData.useTrail=m,w.userData.curveJd=r,w.userData.elementsJd=a?.epoch??r,C&&(w.userData.isFatLine=!0,w.userData.thinPositions=S,w.userData.thinTrailAlphas=v,w.userData.thinFullAlphas=_),w}function dR(e,t){if(!t||t.size===0)return[...e];let n=[];for(let r of e)t.has(r.data.id)||n.push(r);return n}function fR(e){return e.data.objectType===G.PLANET?4:(e.data.objectType===G.MOON||e.data.objectType===G.DWARF_PLANET)&&U_[e.data.id]?3:1}function pR(e,t,n=[0,0,0],r){for(let[,i]of e){if(i.trail!==null)continue;let{body:e}=i;if(e.data.objectType===G.STAR)continue;if(e.data.orbitalSource===W.SPICE_PROBE){if(i.isMinor&&!i.mesh)continue}else if(!i.mesh&&!i.focusUpgraded&&wL(e))continue;if(!e.orbitElements&&e.rederiveElements&&r!==void 0){let t=e.rederiveElements(r);t&&(e.orbitElements=t)}if(!e.orbitElements&&!e.trailBuffer)continue;let a=uR(e,iv(e.data),n,r,fR(e));t.add(a),i.trail=a}}function mR(e,t,n,r=[0,0,0],i,a){let o=new Map,s=new Map,c=new Map,l=HL();for(let[s,c]of e.bodies.asteroidBodiesByZone){let e=dR(c.values(),i);if(e.length===0)continue;let u=iv(e[0].data),{buckets:d}=sv(s,e,a);for(let e=0;e<d.length;e++){let i=d[e];if(i.length===0)continue;let a=UL(i,n,u,r,l);a.userData.groupId=`asteroid:${s}#${e}`,a.userData.parentVec=[0,0,0],o.set(`${s}#${e}`,a),t.add(a)}}for(let[o,c]of e.bodies.spacecraftByParent.entries()){let l=uy(e.layers,o,dR(c.values(),i));if(l.length===0)continue;let{buckets:u}=sv(o,l,a);for(let e=0;e<u.length;e++){let i=u[e];if(i.length===0)continue;let a=UL(i,n,`#ffffff`,r,void 0,e=>iv(e.data));a.userData.groupId=`spacecraft:${o}#${e}`,a.userData.parentBodyId=o,a.userData.parentVec=[0,0,0],s.set(`${o}#${e}`,a),t.add(a)}}let u=new Map;for(let t of e.bodies.majorBodies)if(t.data.objectType===G.MOON){let e=u.get(t.data.parentId)??[];e.push(t),u.set(t.data.parentId,e)}for(let[e,i]of u){let a=UL(i,n,iv(i[0].data),r),o=a.material;o.transparent=!1,o.alphaTest=.5,o.depthTest=!0,o.depthWrite=!0,a.visible=!1,c.set(e,a),t.add(a)}return{asteroidPoints:o,spacecraftPoints:s,moonPoints:c}}var hR=class{lastBaryId=null;pendingUnloads=new Set;prefetched=new Set;loads=0;constructor(e,t,n,r,i,a,o){this.scene=e,this.ctx=t,this.renderer=n,this.textureLoader=r,this.bodyObjects=i,this.clock=a,this.onLoaded=o}syncToFocus(){let e=this.ctx.visibility.focusedSystemId,t=e?this.resolveBaryId(e):null;if(!t){this.lastBaryId&&=(this.pendingUnloads.add(this.lastBaryId),null);return}t!==this.lastBaryId&&(this.lastBaryId&&this.pendingUnloads.add(this.lastBaryId),this.pendingUnloads.delete(t),this.prefetched.delete(t),this.lastBaryId=t,this.load(t))}prefetch(e){let t=this.resolveBaryId(e);!t||t===this.lastBaryId||this.prefetched.has(t)||(this.prefetched.add(t),this.pendingUnloads.delete(t),this.load(t))}discardPrefetch(e){let t=this.resolveBaryId(e);!t||!this.prefetched.delete(t)||t!==this.lastBaryId&&this.pendingUnloads.add(t)}resolveBaryId(e){let t=this.ctx.getBody(e);if(t?.data.objectType===G.BARYCENTER)return e;let n=t?.data.parentId??e;return yv(n)?null:n}load(e){this.loads++,CP(e,this.bodyObjects,this.scene,this.textureLoader,this.clock.jd,this.renderer.capabilities.maxTextureSize,this.ctx).then(()=>{this.onLoaded(),this.ctx.bodies.orientationVersion++}).finally(()=>this.loads--)}isLoading(){return this.loads>0}drainPendingUnloads(){if(this.pendingUnloads.size!==0){for(let e of this.pendingUnloads)wP(e,this.bodyObjects,this.scene,this.ctx);this.pendingUnloads.clear()}}hasPendingUnloads(){return this.pendingUnloads.size>0}},gR=Math.PI/180,_R=class{adjust={rxDeg:0,ryDeg:0,rzDeg:0};_q=new Xi;_adjustQ=new Xi;_tmpQ=new Xi;_axisX=new J(1,0,0);_axisY=new J(0,1,0);_axisZ=new J(0,0,1);constructor(e){this.scene=e}get(){return{...this.adjust}}set(e,t,n){this.adjust.rxDeg=e,this.adjust.ryDeg=t,this.adjust.rzDeg=n,this._adjustQ.setFromAxisAngle(this._axisX,e*gR).premultiply(this._tmpQ.setFromAxisAngle(this._axisY,t*gR)).premultiply(this._tmpQ.setFromAxisAngle(this._axisZ,n*gR)),this._q.copy(NP).multiply(this._adjustQ),this.scene.backgroundRotation.setFromQuaternion(this._q)}},vR=Math.PI/180,yR=vg*vR,bR=Math.cos(yR),xR=Math.sin(yR),SR=5e3,CR=[{id:`galactic-center`,label:`Galactic Center`,raDeg:266.41683,decDeg:-29.00781,color:`#ff6b35`},{id:`galactic-anticenter`,label:`Galactic Anticenter`,raDeg:86.4,decDeg:28.93785,color:`#ff6b35`},{id:`galactic-np`,label:`Galactic NP`,raDeg:192.85948,decDeg:27.12825,color:`#ffb84d`},{id:`galactic-sp`,label:`Galactic SP`,raDeg:12.85948,decDeg:-27.12825,color:`#ffb84d`},{id:`ncp`,label:`NCP (Polaris ≈)`,raDeg:37.9542,decDeg:89.2641,color:`#4dd0ff`},{id:`scp`,label:`SCP`,raDeg:0,decDeg:-90,color:`#4dd0ff`},{id:`vernal`,label:`Vernal Equinox (γ)`,raDeg:0,decDeg:0,color:`#9d8cff`},{id:`autumnal`,label:`Autumnal Equinox`,raDeg:180,decDeg:0,color:`#9d8cff`},{id:`m31`,label:`M31 (Andromeda)`,raDeg:10.6847,decDeg:41.2692,color:`#ffffff`},{id:`lmc`,label:`LMC (Large Magellanic Cloud)`,raDeg:80.8942,decDeg:-69.7561,color:`#ffffff`},{id:`smc`,label:`SMC (Small Magellanic Cloud)`,raDeg:13.1583,decDeg:-72.8003,color:`#ffffff`},{id:`sirius`,label:`Sirius`,raDeg:101.2872,decDeg:-16.7161,color:`#ffffff`}],wR=192.85948,TR=27.12825,ER=266.40499,DR=-28.93617,OR=256,kR=[{name:`galactic-plane`,zero:AR(ER,DR,new J).normalize(),pole:AR(wR,TR,new J).normalize(),color:16739125},{name:`ecliptic-plane`,zero:new J(1,0,0),pole:new J(0,1,0),color:5099775},{name:`celestial-equator`,zero:AR(0,0,new J).normalize(),pole:AR(0,90,new J).normalize(),color:10325247}];function AR(e,t,n){let r=e*vR,i=t*vR,a=Math.cos(i),o=a*Math.cos(r),s=a*Math.sin(r),c=Math.sin(i),l=o,u=s*bR+c*xR,d=-s*xR+c*bR;return n.set(l,d,-u)}function jR(e){let t=document.createElement(`div`);t.className=`sky-debug-marker`,t.style.cssText=[`display:flex`,`align-items:center`,`gap:4px`,`font:11px/1 monospace`,`text-shadow:0 0 3px #000, 0 0 3px #000`,`pointer-events:none`,`white-space:nowrap`].join(`;`);let n=document.createElementNS(`http://www.w3.org/2000/svg`,`svg`);n.setAttribute(`width`,`48`),n.setAttribute(`height`,`48`),n.setAttribute(`viewBox`,`-24 -24 48 48`),n.style.cssText=`flex:0 0 auto;filter:drop-shadow(0 0 2px #000);margin-inline-start:-24px`;let r=e.color;n.innerHTML=`
|
|
6361
6361
|
<circle cx="0" cy="0" r="14" fill="none" stroke="${r}" stroke-width="1.6"/>
|
|
6362
6362
|
<line x1="-23" y1="0" x2="-10" y2="0" stroke="${r}" stroke-width="1.6"/>
|
|
6363
6363
|
<line x1="10" y1="0" x2="23" y2="0" stroke="${r}" stroke-width="1.6"/>
|
|
6364
6364
|
<line x1="0" y1="-23" x2="0" y2="-10" stroke="${r}" stroke-width="1.6"/>
|
|
6365
6365
|
<line x1="0" y1="10" x2="0" y2="23" stroke="${r}" stroke-width="1.6"/>
|
|
6366
|
-
`;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 jR(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 ts;c.setAttribute(`position`,new Uo(o,3));let l=new Lc(c,new wc({color:r,transparent:!0,opacity:.55}));return l.frustumCulled=!1,l}function MR(){let e=new qa;e.name=`sky-debug-markers`,e.visible=!1;let t=new J;for(let n of SR){kR(n.raDeg,n.decDeg,t).multiplyScalar(xR);let r=new DT(AR(n));r.center.set(0,.5),r.position.copy(t),e.add(r)}for(let t of OR){let n=jR(t.zero,t.pole,xR*.999,t.color,DR);n.name=t.name,e.add(n)}return e}function NR(e){e.traverse(e=>{e instanceof DT&&e.element.remove(),e instanceof Lc&&(e.geometry.dispose(),e.material.dispose())}),e.parent?.remove(e)}var PR=class{group=null;constructor(e){this.scene=e}setVisible(e){e?(this.group||(this.group=MR(),this.scene.add(this.group)),this.group.visible=!0):this.group&&=(NR(this.group),null)}},FR=new J,IR=new J,LR=new J,RR=[FR,IR,LR];function zR(e,t,n){return FR.set(1,0,0).applyQuaternion(e).transformDirection(t),IR.set(0,1,0).applyQuaternion(e).transformDirection(t),LR.set(0,0,1).applyQuaternion(e).transformDirection(t),{e:RR,a:n}}function BR(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 VR(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 HR(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 UR=class{canvas=null;gfx=null;tmp=new J;tmpQ=new Xi;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=hO(this.items,y++,WR),T=!!(o.semiAxesScene&&o.mesh);if(T){let e=zR(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],VR(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,BR(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,OO(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,EO(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(),qR(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)}}KR(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 WR(){return{id:``,camX:0,camY:0,camZ:0,worldR:0,e0:new J,e1:new J,e2:new J,sa:[0,0,0],occ:bO(),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 GR=[[`#1ae5ff`,`label shown`],[`#ffe11a`,`dimmed`],[`#ff3b3b`,`hidden`],[`#ff8c1a`,`occluder silhouette`],[`#7dff7d`,`focused`]];function KR(e,t){let n=t-8-(GR.length-1)*13;e.font=`10px monospace`,e.textBaseline=`middle`;for(let[t,r]of GR)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 qR(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 JR(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 YR="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:P,mp:se}=t,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,Y,X,le,ue,de,fe;fe=k+119459e-10*b,A===`y`&&(fe=k),de=fe+2*.01675*Math.sin(fe),X=Math.sin(de),U=.5*X*X-.25,W=-.5*X*Math.cos(de);let pe=d*U+f*W,me=g*U+ne*W,he=_*U+v*W+y*X,ge=p*U+m*W+ee*X,Z=te*U+h*W;fe=O+.00015835218*b,A===`y`&&(fe=O),de=fe+2*.0549*Math.sin(fe),X=Math.sin(de),U=.5*X*X-.25,W=-.5*X*Math.cos(de);let _e=r*U+n*W,ve=C*U+w*W,ye=T*U+E*W+D*X,be=re*U+ie*W+x*X,xe=ae*U+S*W;return G=pe+_e,J=me+ve,Y=he+ye,K=ge+be,q=Z+xe,A===`n`&&(G-=i,J-=l,Y-=u,K-=s,q-=c,M+=J,oe+=G,R=Math.sin(M),L=Math.cos(M),M>=.2?(q/=R,K-=L*q,P+=K,N+=q,se+=Y):(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),le=se+P+L*N,H=Y+K-J*N*R,le+=H,ue=N,N=Math.atan2(F,I),N<0&&j===`a`&&(N+=o),Math.abs(ue-N)>a&&(N<ue?N+=o:N-=o),se+=Y,P=le-se-L*N)),{ep:oe,inclp:M,nodep:N,argpp:P,mp:se}}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,P,se,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,Y,X,le,ue,de,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,le=3*(l*l+u*u)+_e*$,ue=6*(l*d+u*f)+ve*$,de=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),le=le+le+ke*_e,ue=ue+ue+ke*ve,de=de+de+ke*ye,K=ne*We,G=-.5*K/Ae,q=K*Ae,W=-15*Ce*q,J=_*y+v*b,Y=v*y+_*b,X=v*b-_*y,Ge===1&&(O=W,k=G,A=K,j=q,oe=J,M=Y,N=X,P=le,se=ue,F=de,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*se,$e=-2*A*(F-P),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*Y,st=2*W*X,ct=2*G*pe,lt=2*G*(me-fe),ut=-2*K*ue,dt=-2*K*(de-le),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:Y,s7:X,ss1:O,ss2:k,ss3:A,ss4:j,ss5:oe,ss6:M,ss7:N,sz1:P,sz2:se,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:le,z2:ue,z3:de,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:P,z33:se,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:Y,d4422:X,d5220:le,d5232:ue,d5421:de,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*(P+se-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,Y=qe*$*Be,X=qe*ke*Ve,Je*=Ze,qe=Je*1.1428639e-7,le=qe*Ae*He,ue=qe*je*We,qe=2*Je*2.1765803e-9,de=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:Y,d4422:X,d5220:le,d5232:ue,d5421:de,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,P=5.7686396,se=.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-P)+r*Math.sin(D-P)+i*Math.sin(G+D-se)+a*Math.sin(-G+D-se)+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-P)+r*Math.cos(D-P)+i*Math.cos(G+D-se)+a*Math.cos(-G+D-se)+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,P=e.argpo+e.argpdot*e.t,se=e.nodeo+e.nodedot*e.t;g=P,D=N;let F=e.t*e.t;if(k=se+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=P-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 Y=L*(1-G),X=Math.sqrt(L)*K/Y,le=Math.sqrt(J)/Y,ue=Math.sqrt(1-q);S=K/(1+ue);let de=L/Y*(r-H-V*S),fe=L/Y*(n-V+H*S);v=Math.atan2(de,fe);let pe=(fe+fe)*de,me=1-2*de*de;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=Y*(1-1.5*ge*ue*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=X-O*he*e.x1mth2*pe/l,be=le+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,P,se,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,Y,X,le,ue,de,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}P=1/Pe,Z=1/($-B),Q.eta=$*Q.ecco*Z,O=Q.eta*Q.eta,D=Q.ecco*Q.eta,se=Math.abs(1-O),S=F*Z**4,C=S/se**3.5,ie=C*Q.no*($*(1+1.5*O+D*(4+O))+.375*f*Z/se*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/($*se)*(-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*P*Q.no,he=.5*me*f*P,ge=-.46875*-165597e-11*P*P*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:Y,sz21:X,sz23:le,sz31:ue,sz33:de}=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:Y,sz21:X,sz23:le,sz31:ue,sz33:de,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=2451545,T=86400,E=[[2441317.5,10],[2441499.5,11],[2441683.5,12],[2442048.5,13],[2442413.5,14],[2442778.5,15],[2443144.5,16],[2443509.5,17],[2443874.5,18],[2444239.5,19],[2444786.5,20],[2445151.5,21],[2445516.5,22],[2446247.5,23],[2447161.5,24],[2447892.5,25],[2448257.5,26],[2448804.5,27],[2449169.5,28],[2449534.5,29],[2450083.5,30],[2450630.5,31],[2451179.5,32],[2453736.5,33],[2454832.5,34],[2456109.5,35],[2457204.5,36],[2457754.5,37]];function D(e){for(let t=E.length-1;t>=0;t--)if(e>=E[t][0])return E[t][1];return E[0][1]-1}function O(e){let t=6.239996+1.99096871e-7*(e-w)*T;return .001657*Math.sin(t+.01671*Math.sin(t))}function k(e){if(!Number.isFinite(e))return e;let t=e+(D(e)+32.184)/T;return t+O(t)/T}const A=Math.PI/180,j=A/3600,oe=1e-4*j,M=[[0,0,0,0,1,-171996,-174.2,92025,8.9],[0,0,2,-2,2,-13187,-1.6,5736,-3.1],[0,0,2,0,2,-2274,-.2,977,-.5],[0,0,0,0,2,2062,.2,-895,.5],[0,1,0,0,0,1426,-3.4,54,-.1],[1,0,0,0,0,712,.1,-7,0],[0,1,2,-2,2,-517,1.2,224,-.6],[0,0,2,0,1,-386,-.4,200,0],[1,0,2,0,2,-301,0,129,-.1],[0,-1,2,-2,2,217,-.5,-95,.3],[1,0,0,-2,0,-158,0,-1,0],[0,0,2,-2,1,129,.1,-70,0],[-1,0,2,0,2,123,0,-53,0],[1,0,0,0,1,63,.1,-33,0],[0,0,0,2,0,63,0,-2,0],[-1,0,2,2,2,-59,0,26,0],[-1,0,0,0,1,-58,-.1,32,0],[1,0,2,0,1,-51,0,27,0]];function N(e,t){let n=Array(9);for(let r=0;r<3;r++)for(let i=0;i<3;i++)n[3*r+i]=e[3*r]*t[i]+e[3*r+1]*t[3+i]+e[3*r+2]*t[6+i];return n}function P(e){let t=Math.cos(e),n=Math.sin(e);return[1,0,0,0,t,n,0,-n,t]}function se(e){let t=Math.cos(e),n=Math.sin(e);return[t,0,-n,0,1,0,n,0,t]}function F(e){let t=Math.cos(e),n=Math.sin(e);return[t,n,0,-n,t,0,0,0,1]}function I(e){let t=(e-w)/36525,n=(2306.2181*t+.30188*t*t+.017998*t**3)*j,r=(2004.3109*t-.42665*t*t-.041833*t**3)*j,a=(2306.2181*t+1.09468*t*t+.018203*t**3)*j,o=134.96298139+477198.8673981*t+.0086972*t*t,s=357.52772333+35999.05034*t-1603e-7*t*t,c=93.27191028+483202.0175381*t-.0036825*t*t,l=297.85036306+445267.11148*t-.0019142*t*t,u=125.04452222-1934.1362608*t+.0020708*t*t,d=0,f=0;for(let[e,n,r,i,a,p,m,ee,te]of M){let h=(e*o+n*s+r*c+i*l+a*u)*A;d+=(p+m*t)*Math.sin(h),f+=(ee+te*t)*Math.cos(h)}d*=oe,f*=oe;let p=(84381.448-46.815*t-59e-5*t*t+.001813*t**3)*j,m=d*Math.cos(p),ee=N(N(N(N(F(n),se(-r)),F(a)),N(N(P(-p),F(d)),P(p+f))),F(-m));return N(P(i*A),ee)}let L=NaN,R=[1,0,0,0,1,0,0,0,1];function ce(e){return Math.abs(e-L)<=.01||(R=I(e),L=e),R}function z(e){return new Date((e-2440587.5)*864e5).toISOString()}function B(e,t){let n=C({OBJECT_NAME:t??String(e.noradCatId),OBJECT_ID:String(e.noradCatId),EPOCH:z(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 V=Math.PI/180;Math.cos(i*V),Math.sin(i*V);const H=Math.PI/180,U=Math.cos(i*H),W=Math.sin(i*H),G=10/r;function K(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 q(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:T,visibleFromDays:E}=r,D=p!==0&&r.applyFlagFilter,O=r.pickBase,A=d.length/3|0,j=i-w,oe=k(i),M=ce(i),N=0;for(let w=0;w<m&&!(N>=A);w++){let m=ee[w];if(m===0||E[w]>j||D&&(T[w]&p)!==p)continue;if(m===3){let e=C[w];if(!e){if(e=B({noradCatId:r.satnum[w],epochJd:re[w],meanMotion:b[w]/360,eccentricity:g[w],inclination:ne[w],raOfAscNode:_[w],argOfPericenter:v[w],meanAnomaly:y[w],bstar:r.bstar[w],meanMotionDot:r.ndot[w],meanMotionDdot:r.nddot[w],elementSetNo:0,revAtEpoch:0}),!e){ee[w]=0;continue}C[w]=e}let t=(i-e.jdsatepoch)*1440,n=ae(e,t);if(!n||e.error!==x.None)continue;let p=n.position.x*G,m=n.position.y*G,te=n.position.z*G,h=M[0]*p+M[1]*m+M[2]*te,ie=M[3]*p+M[4]*m+M[5]*te,S=M[6]*p+M[7]*m+M[8]*te,T=-ie;if(!K(d,N,a+h-c,o+S-l,s+T-u))continue;if(f){let e=O+w,t=N*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}N++;continue}let k,A,P=g[w],se=ne[w],F=_[w],I=v[w];if(m===2){let e=n(ie[w],S[w],te[w]?i:oe);if(!e)continue;k=e.r*Math.cos(e.nu),A=e.r*Math.sin(e.nu)}else{let n=h[w];if(!isFinite(n)||!isFinite(P)||!isFinite(y[w])||!isFinite(b[w]))continue;let r=(te[w]?i:oe)-re[w],a=(y[w]+b[w]*r)*H,o,s;if(P<1||n>0){let t=Math.min(P,.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,P);if(!isFinite(e))continue;let r=P*Math.cosh(e)-1;if(Math.abs(r)<1e-15)continue;let i=Math.sqrt(P*P-1)*Math.sinh(e)/r,c=(P-Math.cosh(e))/r;o=Math.atan2(i,c),s=n*(1-P*Math.cosh(e))}k=s*Math.cos(o),A=s*Math.sin(o)}if(!isFinite(k)||!isFinite(A))continue;let L=Math.cos(I*H),R=Math.sin(I*H),ce=Math.cos(se*H),z=Math.sin(se*H),V=Math.cos(F*H),q=Math.sin(F*H),J=(V*L-q*R*ce)*k+(-V*R-q*L*ce)*A,Y=(q*L+V*R*ce)*k+(-q*R+V*L*ce)*A,X=R*z*k+L*z*A;if(te[w]){let e=Y*U+X*W,t=-Y*W+X*U;Y=e,X=t}let le=J*10,ue=X*10,de=-Y*10;if(K(d,N,a+le-c,o+ue-l,s+de-u)){if(f){let e=O+w,t=N*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}N++}}return N}const J=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)J.delete(e);for(let e of t.set)J.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=J.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=q(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-D2PB8gf5.js.map",XR=typeof self<`u`&&self.Blob&&new Blob([`URL.revokeObjectURL(import.meta.url);`,YR],{type:`text/javascript;charset=utf-8`});function ZR(e){let t;try{if(t=XR&&(self.URL||self.webkitURL).createObjectURL(XR),!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(YR),{type:`module`,name:e?.name})}}var QR=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 ZR;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 D_(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}]},k_(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()}},$R=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 Ah(n[e-t]);return null}clear(){this.#t.clear(),this.#e=1}},ez=.01,tz=[`asteroid`,`spacecraft`],nz=.0002959122082855911,rz=.75,iz=Q(8*86400);function az(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(nz/i*((1+o)/(1-o)));s>t&&(t=s)}return{maxSpeedScene:t*10,alwaysSolve:n}}function oz(e){return e<0?0:e>1?1:e}function sz(e,t){return t===`*`?e.startsWith(`small_bodies/`):e===t}function cz(e){return e===null?{tBright:0,tSize:0}:{tBright:oz((lz-e)/(lz-uz)),tSize:oz((dz-e)/(dz-fz))}}var lz=1e4,uz=500,dz=uz,fz=50,pz=4,mz=.5,hz=10,gz=1,_z=1,vz=3.5,yz=2.5,bz=2,xz=vz,Sz=class{orbitPool=new QR;pickRegistry=new $R;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:pz,dim:mz,opacity:_z};emphasizedSmallBodyZone=null;smallBodyEmphasis={sizeMult:1,brightMult:1,opacity:_z};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 tz)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 tz)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)lv(e)===`naif-399`&&this.applyEarthSatEmphasis(t)}computeEarthSatEmphasis(e){let{tBright:t,tSize:n}=cz(e);return{size:pz+(hz-pz)*n,dim:mz+(gz-mz)*t,opacity:_z+(vz-_z)*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)sz(lv(e),n)&&this.resetSmallBodyEmphasis(t);if(e!==null)for(let[t,n]of this.workerPoints.asteroid)sz(lv(t),e)&&this.applySmallBodyEmphasis(n)}computeSmallBodyEmphasis(e){let{tBright:t,tSize:n}=cz(e);return{sizeMult:1+(yz-1)*n,brightMult:1+(bz-1)*t,opacity:_z+(xz-_z)*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=_z,e.userData.smallBodyBaseSize=void 0,e.userData.smallBodyBaseColor=void 0}seedBasis(e){this.basisPos=[...e]}buildInitial(e){let t=pR(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 tz)for(let[t,n]of this.workerPoints[e]){let r=lv(t);n.userData.parentBodyId=this.cloudParentId(e,r),this.emphasiseNewCloud(e,r,n)}this.assignMapLayer()}assignMapLayer(){for(let e of tz)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`?$_:t}emphasiseNewCloud(e,t,n){if(e===`spacecraft`){t===`naif-399`&&this.applyEarthSatEmphasis(n);return}let r=this.emphasizedSmallBodyZone;r!==null&&sz(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=Mh(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,az(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=UL(new Float32Array(l.cols.count*3),0,this.circleTexture,c,VL());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 cv(n,uy(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=>jh(e.data.id)??Th));await this.orbitPool.rewireOne(c,l,s,(o+r)%t,!1,u),this.armGroupGate(c,{maxSpeedScene:iz,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=UL(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=lv(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(iv(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 Bo(new Float32Array(n),3)),e.getAttribute(`color`)){let r=new Float32Array(n);this.seedColors(r,t),e.setAttribute(`color`,new Bo(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 Bo(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 Bo(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 Bo(t.slice(),4,!0))}reposition(){let[e,t,n]=this.focus.focusTruePos,r=this.basisPos;for(let i of tz)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=ez*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($_)?.position;for(let[i,a]of this.workerPoints.asteroid){if(!r)break;if(!this.ctx.visibility.isAsteroidGroupVisible(lv(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(lv(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>=rz}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 Uo(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 tz)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()}},Cz=Math.PI/180,wz=2451545,Tz=1.00000261,Ez=.01671123,Dz=100.46457166*Cz,Oz=35999.37244981/36525*Cz,kz=102.93768193*Cz,Az=.32327364/36525*Cz;function jz(e){let t=e-wz,n=kz+Az*t,r=Dz+Oz*t-n,i=r+(2*Ez-Ez**3/4)*Math.sin(r)+1.25*Ez*Ez*Math.sin(2*r);return{lon:n+i,r:Tz*(1-Ez*Ez)/(1+Ez*Math.cos(i))}}function Mz(e){let t=jz(e).lon;return(e,n)=>{let r=t-jz(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 Nz=.01,Pz=1/100,Fz=1;function Iz(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 Lz(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 Rz(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=Iz(c,l,u)}function zz(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(Lz(o,g,u,d,f,p,m,h,a))return;let{posArr:_,trailArr:v,fullArr:y}=rR(t),b=e.lagrangeTrail?Mz(i):null,x=sR(e,n,_,c.x,c.y,c.z,r,b??void 0);iR(t,_,v,y,x,!0,s),Rz(o,g,u,d,f,p,m,h,_,x,a)}function Bz(e,t,n,r,i){let{posArr:a,trailArr:o,fullArr:s,capacity:c}=rR(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){QL(e.geometry,a,o,s,l);return}e.geometry.getAttribute(`position`).needsUpdate=!0}function Vz(e,t,n,r,i){let a=t.userData.trailBuffer;if(a){zz(e,t,a,n,r,i);return}let o=t.userData.sourceCurve;if(!o){if(!t.userData.curvePending||!e.orbitElements)return;o=YL(b_(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=qL(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*Pz,Fz)){let n=e.rederiveElements(r);n&&(Object.assign(e.orbitElements,n),o=YL(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)>Nz&&(o=YL(b_(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(Lz(h,o,g,_,v,y,b,x,i))return;let S=Mb(e,o,s,u,d,f,p);if(S.length<2)return;let{posArr:C,trailArr:w,fullArr:T,capacity:E}=rR(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;iR(t,C,w,T,A,s,c),h.trailLocalPositions=S,Rz(h,o,g,_,v,y,b,x,C,A,i)}function Hz(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 Uz(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 Wz=4/2,Gz=(.1*10)**2,Kz=new J,qz=[],Jz=qz;function Yz(e){return hO(qz,e,bO)}var Xz={x:0,y:0,left:0,right:0,h:0},Zz=new Xi,Qz={ox:0,oy:0},$z=new J,eB=new J;function tB(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=Tv(C,e),n.isCrashed||n.noPhysical){let e=n.noPhysical===`model`,t=xg(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()}dA(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),eB.set(o-w[0]+p.x,s-w[1]+p.y,c-w[2]+p.z).project(t),n.labelAnchorOffscreen=Math.abs(eB.x)>1||Math.abs(eB.y)>1;continue}if(n.semiAxesScene&&n.mesh)HR(l,u,d,zR(n.mesh.getWorldQuaternion(Zz),T,n.semiAxesScene),S,Qz),p.set(Qz.ox,Qz.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=qz,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=Pj(t),n=t.model.position;for(let c of s){let s=c.r*e;if($z.copy(c.center).applyQuaternion(t.model.quaternion).add(n).multiplyScalar(e),p.set(i-w[0]+$z.x,a-w[1]+$z.y,o-w[2]+$z.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)&&BR(Yz(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?VR(Yz(k++),c,l,u,zR(t.mesh.getWorldQuaternion(Zz),T,t.semiAxesScene),S,D,O,t.body.data.id,r):BR(Yz(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?pM(n.getBody(a),e):void 0;for(let r of e.values()){let{body:i,group:s,trail:c}=r,l=r.cachedDist,u=_O(r);r.root.visible=u;let d,f,p=i.data.id===a,m=A!==null&&i.data.id===A;if(r.mesh===null&&!Sn(i.data.objectType)){let t=i.data.objectType;if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){let t=!0,r=p?void 0:bv(i.data.id);if(r){let a=e.get(r)?.body??n.getBody(r);a?.position&&i.position&&Tv(i.position,a.position)/Tv(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?Hz(t,o,p):Uz(t,n.visibility.hasFullRendering(i),p||m);s.visible=r.groupVisible,c&&(c.visible=r.orbitVisible),d=r.showLabel,f=r.isClose}u||(s.visible=!1,d=!1,f=!1),c&&(!u||i.orbitCenter===null)&&(c.visible=!1);let g=!1;if(r.starPoint&&u){let e=r.radiusScene/l*S/Wz;g=e<1,r.starPoint.visible=g,g&&(r.starPoint.material.uniforms.uFlux.value=e*e),sL(r.corona,e),s.visible=!0,f=!g,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(Kz.set(w[0],w[1],w[2]))>Gz&&(c.visible=!1)}_&&c&&(c.visible=!1),s.matrixWorldAutoUpdate=s.visible;let{label:y}=r;if(!s.visible&&y&&y.parent===s?(s.remove(y),y.element.remove()):s.visible&&y&&y.parent!==s&&s.add(y),r.mesh&&r.radiusScene>0){let e=g||!p&&!m&&r.radiusScene/l*S<.5;e!==r.meshSubPixel&&(r.meshSubPixel=e,e?r.mesh.layers.disable(0):r.mesh.layers.enable(0))}TO(r,d,f,l,S,a)&&(j=!0);let T=r.radiusScene>0?r.radiusScene/l*S:0;FM(r,v&&i.data.id===M,T,t,b,x)}for(let[e,t]of c)t.visible=n.visibility.isAsteroidGroupVisible(lv(e));for(let[e,t]of l)t.visible=n.visibility.isSpacecraftGroupVisible(lv(e));for(let[e,t]of u)t.visible=n.visibility.isMoonGroupVisible(e);if(E.length>0){let n=a?bv(a):null;for(let r of e.values()){if(!r.label?.visible||!OO(r,t,w,b,x,Xz))continue;let e=r.body.data.id;EO(Xz.x,Xz.y,r.cachedDist,e,E,e===a?n:null)&&(r.label.visible=!1)}}if((m||j||++d>=3)&&(d=0,VO(e,b,x,t,a,n,s,E,r)),HO(e,b,x,t,r),M){let t=e.get(M);t&&zM(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 nB(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function rB(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function iB(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function aB(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 oB(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-sB(d):p,g=f?m+sB(f):m;if(t<h||t>g)return null;if(a&&d&&t<(c?.jds[0]??n.startJd))return{r:cB(d,t),centerId:a.anchorId};if(c&&t<=c.jds[c.jds.length-1])return{r:lB(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:cB(f,t),centerId:o.anchorId};if(l)return{r:lB(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}=aB(e,v);return{r:lB(y,b,t,x,S),centerId:e.centerId}}function sB(e){return e.jds[e.jds.length-1]-e.jds[0]}function cB(e,t){let n=sB(e),r=e.jds[0],i=n>0?r+((t-r)%n+n)%n:t;return lB(e.points,e.jds,i)}function lB(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 nB(e[a-1],iB(rB(e[a],e[a-1]),s))}var uB=Math.PI/180,dB=Math.cos(vg*uB),fB=Math.sin(vg*uB);function pB(e,t,n,r){let i=Math.cos(e*uB),a=Math.sin(e*uB),o=Math.cos(t*uB),s=Math.sin(t*uB),c=Math.cos(n*uB),l=Math.sin(n*uB);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 mB(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*dB+a*fB,t=-i*fB+a*dB;i=e,a=t}return[r,i,a]}function hB(e){let t=10/_g;return[e[0]*t,e[2]*t,-e[1]*t]}function gB(e,t,n){let{a:r,e:i,ma:a,n:o,epoch:s,q:c,tp:l}=e,u=v_(e,t),{om:d,w:f}=b_(e,t),p=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 t=u_(c,l,u);if(!t)return null;let r=n&&n>0?n:Bv,i=t.r*_g,a=2*c*_g;return _B(i,t.nu,a,1,r,f,e.i,d,p)}if(!isFinite(i)||!isFinite(a))return null;let m=r*_g,h=o*uB/Vv,g=n&&n>0?n:h*h*Math.abs(m)*Math.abs(m)*Math.abs(m);if(!isFinite(g)||g<=0)return null;let _=(a+o*(u-s))*uB,v,y;if(i<1||r>0){let e=Math.min(i,.9999999),t=s_(_,e),n=1-e*Math.cos(t);v=Math.atan2(Math.sqrt(1-e*e)*Math.sin(t),Math.cos(t)-e),y=m*n}else{let e=l_(_,i);if(!isFinite(e))return null;let t=i*Math.cosh(e)-1;if(Math.abs(t)<1e-15)return null;v=Math.atan2(Math.sqrt(i*i-1)*Math.sinh(e)/t,(i-Math.cosh(e))/t),y=m*(1-i*Math.cosh(e))}if(!isFinite(y)||y<=0)return null;let b=m*(1-i*i);return!isFinite(b)||b<=0?null:_B(y,v,b,i,g,f,e.i,d,p)}function _B(e,t,n,r,i,a,o,s,c){let l=Math.cos(t),u=Math.sin(t),d=Math.sqrt(i/n),f=pB(a,o,s,c),p=mB(e*l,e*u,f),m=mB(-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 vB={cruise:`#7fdbff`,boost:`#ffb454`,brake:`#ff8c69`,spiral:`#c9a0ff`,"spiral-out":`#9b7fd4`,"spiral-in":`#9b7fd4`};vB.cruise,vB.boost,vB.brake,vB.spiral,vB[`spiral-out`],vB[`spiral-in`];var yB={notice:`#8ab4f8`,caution:`#f2b23e`,severe:`#ff6b5a`},bB=3,xB=1,SB=2,CB=.6,wB=1.5,TB=.3,EB=1.5,DB=.85,OB=60,kB=.018,AB=.026,jB=`#ffffff`,MB=4,NB=1.5,PB=9,FB=1,IB={notice:MB-3,caution:MB-2,severe:MB-1},LB=[`notice`,`caution`,`severe`],RB=.03,zB=.2;function BB(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 Kc(t)}function VB(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 Kc(t)}function HB(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 UB(e,t){let n=new xs(new ss({map:e,transparent:!0,sizeAttenuation:!1,depthTest:!1}));return n.scale.setScalar(t),n.renderOrder=MB,n}function WB(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&&(FT(c,i),fM(c,o)),s&&(c.addEventListener(`mouseenter`,()=>s(!0)),c.addEventListener(`mouseleave`,()=>s(!1)));let p=new DT(c);return p.center.set(0,.5),p}function GB(e,t){return e&&[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}var KB=class{group=new qa;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?wB:SB,i?TB:CB,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)=>LB.indexOf(e.severity)-LB.indexOf(t.severity));for(let t of n){let n=yB[t.severity];for(let n of t.bands)e.arcs.forEach((t,r)=>{this.addLine(HB(t,n.startJd,n.endJd,aB(e,r)),yB[n.severity],PB,FB,null,{renderOrder:IB[n.severity]})});if(this.mergeIntoStep(t,n))continue;let r=oB(e,t.startJd);if(!r)continue;let i=hB(r.r),a=r.centerId===e.centerId?null:r.centerId,o=UB(VB(n),RB);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 DT(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,bB,xB,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:UB(BB(jB),AB),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=oB(e,n.jd);if(!t)continue;let r=hB(t.r),i=t.centerId===e.centerId?null:t.centerId,a=UB(BB(jB),kB);this.markers.push({sprite:a,local:r,anchorId:i});let o=WB(`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:hB(n.meeting.r),end:e.arrival,color:vB[a?.kind??`cruise`]}];o&&s.push({local:hB(o.r),end:e.departure,color:vB[i?.kind??`cruise`]});for(let{local:n,end:i,color:a}of s){if(!i.name)continue;let o=WB(`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?xB:e.brightness),n.uniforms.uLineWidth.value=t?bB: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?aB(e,s):{from:0,to:a.points.length};this.addLine(a.points.slice(c,l),vB[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),vB.cruise,bB,xB,null,{anchorId:n}),this.addLine(t.approach.slice(i.from,i.to),vB.cruise,bB,xB,null,{anchorId:n,renderOrder:NB}),e=i.to;e<t.approach.length&&this.addLine(t.approach.slice(Math.max(0,e-1)),vB.cruise,bB,xB,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,vB.cruise,bB,xB,null,{anchorId:n});this.addLine(t.approach.slice(e>0?e-1:0,r),vB.cruise,EB,DB,null,{anchorId:n})}else this.addLine(t.approach,vB.cruise,bB,xB,null,{anchorId:n});let i=this.addLine(t.points,vB.cruise,EB,DB,null,{anchorId:n});if(!i)continue;let a=n===null?hB(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]=hB(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*zB));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=nR(o,c,l,l,o,t,n,r);d.frustumCulled=!1,d.renderOrder=a.renderOrder??MB,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=oB(this.path,e);t.sprite.visible=n!==null,n&&(t.local=hB(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,GB(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;QL(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):GB(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*OB}}}setVisible(e){this.group.visible=e}reserveLabelSpace(e,t,n){if(!this.group.visible||this.labels.length===0){zO(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),!bw(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=EO(a,o,s,``,Jz);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++}zO(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 qa,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)}},qB=2,JB=1,YB=4,XB=200,ZB=class{group=new qa;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,XB);for(let t=0;t<e.count;t++){let[r,i,a]=hB(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(XB*3),t=new Float32Array(XB).fill(1),n=nR(XB,e,t,t,0,vB.cruise,qB,JB);n.frustumCulled=!1,n.renderOrder=YB,this.layer!==null&&n.layers.set(this.layer),this.group.add(n),this.slots.push({line:n,bodyId:``,local:new Float64Array(XB*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;QL(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)}},QB=new Set([`not-yet`,`no-data`,`parent`,`failed`]);function $B(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&&QB.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){tV(i.focusTargetWorld,n);let e=i.camTargetOffset;e&&i.camTargetWorld&&nV(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){tV(i.focusTargetWorld,f);let e=i.camTargetOffset;e&&i.camTargetWorld&&nV(i.camTargetWorld,f,e);let t=i.camOriginOffset;t&&i.camOriginWorld&&nV(i.camOriginWorld,f,t),h||tV(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}Vz(e.body,n,g,t,s),n.userData.refreshDeferred=!1}}let _=!f&&p===`loading`;return{focusUnplaced:a!==void 0&&!f&&!_,focusLoading:_,anchorId:m}}function eV(e,t,n,r){let i=t.focusTruePos;for(let t of e.values()){let e=t.trail;!e||!e.visible||!e.userData.refreshDeferred||(Vz(t.body,e,i,n,r),e.userData.refreshDeferred=!1)}}function tV(e,t){e[0]=t[0],e[1]=t[1],e[2]=t[2]}function nV(e,t,n){e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2]}var rV=Object.freeze([0,0,0]);function iV(e,t,n,r){if(!Number.isFinite(t+n+r))return aV(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 aV(e,t){let n=e;return n.position=null,n.orbitCenter=n.orbitCenterId===void 0?void 0:null,n.unplaced=t,null}function oV(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 sV(e,t){let n=e.trailAnchor??=[0,0,0];n[0]=t[0],n[1]=t[1],n[2]=t[2]}var cV=Math.PI/180,lV=120,uV=Q(.001)**2,dV=new WeakMap,fV=new J,pV=new J;function mV(e,t,n){e.distanceToSquared(t)<=uV?e.copy(t):e.lerp(t,n)}function hV(e,t,n,r,i){let a=e.featureAnchor;oV(e,n),pV.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?(fV.copy(s.position),pV.copy(e.position)):(fV.copy(s.position),r?.mesh&&fV.multiply(r.mesh.scale))}else{let e=t.data.radiusKm,n=a.lat*cV,i=a.lon*cV,o=t.orientation&&Number.isFinite(e)&&e>0?pO(r,t.data.id,e,n,i):null;if(o)fV.set(o.pointKm[0],o.pointKm[1],o.pointKm[2]);else{let t=Number.isFinite(e)&&e>0?e:0,[r,a,o]=KD(n,i);fV.set(t*r,t*a,t*o)}fV.multiplyScalar(Q(1))}let c=performance.now(),l=dV.get(e);if(!l)l={fixed:fV.clone(),addend:pV.clone(),t:c},dV.set(e,l);else{let e=1-Math.exp(-(c-l.t)/lV);l.t=c,mV(l.fixed,fV,e),mV(l.addend,pV,e)}return fV.copy(l.fixed),t.orientation&&fV.applyQuaternion(xS(t.orientation,i,t.nutPrec)),iV(e,n[0]+fV.x+l.addend.x,n[1]+fV.y+l.addend.y,n[2]+fV.z+l.addend.z)}var gV=30034e-10,_V=.45,vV=1.6,yV=.85,bV=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],xV=e=>Math.hypot(e[0],e[1],e[2]);function SV(e,t,n=gV){let r=xV(t);if(!(r>0))return null;let i=r*Math.cbrt(n/3),a=bV(e,t)/r,o=xV(e);if(Math.sqrt(Math.max(0,o*o-a*a))>yV*i)return null;let s=a/i;return s>=_V&&s<=vV?`EL1`:s<=-_V&&s>=-vV?`EL2`:null}function CV(e,t){return!(e.visibleFromDays!==void 0&&t-2451545<e.visibleFromDays)}function wV(e,t){let n=v_(e,t);return n>=e.validityStart&&n<=e.validityEnd}function TV(e){return e.a===0&&(e.objectType===G.BARYCENTER||e.objectType===G.LAGRANGE_POINT||Sn(e.objectType))}function EV(e,t){if(e.pageOnly)return`never`;if(!CV(e,t))return`not-yet`;if(!wV(e,t))return`no-data`;let n,r=e.satrec;return n=r?o_(r,t):e.omm?null:e.q==null?e.a===0?TV(e)?[0,0,0]:null:S_(e,t):C_(e,t),!n||!Number.isFinite(n[0]+n[1]+n[2])?`failed`:n}function DV(){return{count:0,earliestStart:1/0,latestEnd:-1/0}}var OV=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`?kg(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})}}},kV=new Map,AV=new J;function jV(e,t,n,r,i,a,o){let s=cb(n,r,ob(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=pO(o.get(c),c,d,p,m);h&&kV.set(e.id,h);let g=h??kV.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=xS(l.orientation,r,l.nutPrec),x=new J(_,v,y).applyQuaternion(b),S=g?AV.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 MV=[0,0,0],NV=new Xi,PV=4,FV=0,IV=new Map;function LV(e){return e.primary.target===`velocity`||e.secondary?.target===`velocity`}function RV(e,t,n){let r=IV.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 IV.set(e,{jd:t,pos:[n[0],n[1],n[2]],dir:i}),i??void 0}var zV=class{focusedId;noData=DV();passJd=NaN;frame;settled=new Set;settling=new Set;ride=rS([],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=DV()}at(e,t){if(e===`naif-0`)return rV;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||!Sn(t.objectType))&&(n.staggerSlot??=FV++%PV,this.frame%PV!==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=mn(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?aV(e,this.under(n)):hV(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=rS(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=EV(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 aV(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`),aV(e,t)}r.clear(`missing-parent`,i.id);let s;return s=n.chebStore?.has(i.id)?CV(i,t)?n.chebStore.positionScene(i.id,t)??this.rowOffset(e,o,t)??this.chebMiss(i.id,t):`not-yet`:EV(i,t),typeof s==`string`?aV(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.isAwaited(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=iV(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&&oV(e,l===s.parentId?a:this.at(l,o)),e.trailAnchorId!==void 0){let t=this.at(e.trailAnchorId,o);t&&sV(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&&SS(t.mesh,e.orientation,o,e.nutPrec),t.model&&SS(t.model,e.orientation,o,e.nutPrec),t.nomenclatureAnchor&&SS(t.nomenclatureAnchor,e.orientation,o,e.nutPrec);else if(Ej(e)){let n=e.attitudeTrack;if(!e.pointingOverride&&n&&n.orientationAt(o,NV))t.mesh&&t.mesh.quaternion.copy(NV),t.model&&t.model.quaternion.copy(NV);else{let n=e.pointingOverride??e.pointing;if(n){let e=LV(n)?RV(s.id,o,c):void 0,r={bodyPos:c,parentPos:a,sunPos:this.at(`naif-10`,o)??void 0,velocity:e};t.mesh&&BS(t.mesh,n,r),t.model&&BS(t.model,n,r)}else t.mesh&&TS(t.mesh,c,a),t.model&&TS(t.model,c,a)}}if(e.orientation)for(let n of t.rings)SS(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);dA(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?.awaitedAt(n)?aV(e,`loading`):(aV(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&&sb(d.probe,n)){let i=s.parentId,c=jV(s,d.probe,f,n,e=>this.at(e,n),r,a);if(!c)return aV(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||=(WN(t.labelHalo,`landed`),!0),t.isCrashed=e,t.model&&(t.model.visible=!e)}let l=iV(e,c.x,c.y,c.z);if(!l)return null;e.orbitCenterId=s.parentId,oV(e,c.parentPos);let u=c.up;return t?.mesh&&(u?ES(t.mesh,u):TS(t.mesh,l,c.parentPos)),t?.model&&(u?ES(t.model,u):TS(t.model,l,c.parentPos)),l}let p=vb(d.probe,n,d.fitCenterNaifId,r.chebStore??null,e=>this.at(e,n)!==null);if(!p){let t=d.probe.fitCenter?.id;return aV(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=ib(d.probe,n,h);if(!g)return aV(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&&(WN(t.labelHalo,`flying`),t.isLanded=!1,t.isCrashed&&(t.isCrashed=!1,t.model&&(t.model.visible=!0),t.noPhysical||dA(t,`missing`,null)));let _=this.at(ev,n),v=this.at($_,n),y=m===`naif-399`&&_!==null&&v!==null&&SV([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=Sb(hb(d.probe,n,h),s.validityEnd-s.validityStart,t.capacity,y);t.reconfigure(i.stepDays,i.epsilonScene,i.spanDays),Ob(t,r.probeStore,r.chebStore??null,s.id,m,n)}x&&(s.parentId=m);let S=this.at(m,n);if(!S)return aV(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(),Ob(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=Sb(hb(d.probe,n,h),s.validityEnd-s.validityStart,A.capacity,y);A.reconfigure(e.stepDays,e.epsilonScene,e.spanDays),Ob(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(MV)&&Ab(A,wb(r.probeStore,r.chebStore??null,s.id,m),e,[MV[0],MV[1],MV[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)}},BV=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)}},VV=[],HV=new WeakMap;function UV(e,t){let{color:n,geometricAlbedo:r}=e.body.data,i=HV.get(e);return(!i||i.color!==n||i.geometricAlbedo!==r||i.map!==t)&&(i={color:n,geometricAlbedo:r,map:t,albedo:UA(e.body.data,t,new X)},HV.set(e,i)),i.albedo}function WV(e,t,n){let r=UV(e,t.map);if(r)return n.copy(r);n.copy(t.color);let i=t.map&&gA(t.map);return i?n.multiply(i):n}function GV(e,t,n,r){let i=e.get($_)?.body.position,a=0;if(i)for(let e of t){if(!e.mesh)continue;let t=e.mesh.material,[o,s,c]=e.body.position,l=i[0]-o,u=i[1]-s,d=i[2]-c,f=Math.hypot(l,u,d),p=VV[a++]??={x:0,y:0,z:0,radius:0,sunX:0,sunY:0,sunZ:0,sunlight:0,albedo:new X};p.x=o,p.y=s,p.z=c,p.radius=e.radiusScene,p.sunX=l/f,p.sunY=u/f,p.sunZ=d/f,p.sunlight=KS*r*(n?JS(f):1),WV(e,t,p.albedo)}for(let t of e.values()){let e=t.planetshine,n=t.body.position;!e||!n||t.cachedDist>0&&t.radiusScene<t.cachedDist*1e-4||wT(e,n[0],n[1],n[2],VV,a)}}var KV=Q(695700),qV=2,JV=1e-4,YV=2,XV=new J,ZV=new J,QV=new J,$V=new Xi;function eH(e,t,n,r,i){XV.subVectors(e,t);let a=XV.dot(n),o=Math.sqrt(Math.max(XV.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 tH(e,t,n,r,i,a){let o=e.get($_)?.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(),_=KV/g;e.material.uniforms.uSunAngularRadius.value=_,e.material.uniforms.uLightScale.value=n?JS(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}=eH(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*qV),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))}nH(t,i,a)}}function nH(e,t,n){let r=e.rings.reduce((e,t)=>t.intensityScale>e.intensityScale?t:e),i=r.material.uniforms,a=i.uSunDir.value,o=r.planetShadowOnRing.uPlanetPoleDir.value,s=r.planetShadowOnRing.uPlanetCenter.value,c=Math.min(Math.max(a.dot(o),-1),1),l=r.light,u=r.outerScene/Math.max(t.distanceTo(s),1e-12)*n>=YV;u&&!(Math.abs(c-l.patchesSinB)<JV)&&(vC(l.patches,l.profile,c,l.planet),l.patchesSinB=c),ZV.copy(a).addScaledVector(o,-c),ZV.lengthSq()<1e-12&&ZV.set(+(Math.abs(o.x)<.9),Math.abs(o.x)<.9?0:1,0).cross(o),ZV.normalize(),r.ringshine&&AC(r.ringshine,l,ZV,c,i.uLightScale.value),QV.copy(ZV).applyQuaternion($V.copy(r.mesh.quaternion).invert());for(let t of e.rings){if(!t.mesh.visible)continue;u&&t.light.planetLightSinB!==l.patchesSinB&&TC(t.light,l.patchesSinB,l);let n=t.material.uniforms;n.uSunAzimuth.value.set(QV.x,QV.z).normalize();let r=n.uPlanetAlbedo.value;e.mesh?WV(e,e.mesh.material,r):r.setRGB(0,0,0)}}var rH=Math.PI/180,iH=2451545;function aH(e){let t=e-iH,n=(19.3871+.52402073*t)*rH;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 oH(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 sH(e,t){let n=e.seasonal;if(!n)return e;let r=oH(n.lsDeg,n.dustTauFactor,t),i=oH(n.lsDeg,n.dustScaleHeightKm,t),a=oH(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 cH=new WeakMap,lH=.25;function uH(e,t){if(!e.seasonal)return e;let n=Math.round(aH(t)/lH),r=cH.get(e);if(r&&r.lsQ===n)return r.params;let i=sH(e,n*lH);return cH.set(e,{lsQ:n,params:i}),i}var dH=new J,fH=new J,pH=[.2126,.7152,.0722];function mH(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=SN(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+=pH[t]*Math.exp(-n)}return o}var hH=.4,gH=.05,_H=-.105,vH=.3,yH=.05;function bH(e,t,n){let r=mH(e,t),i=Math.min(1,-Math.log(Math.max(r,.001))/yH),a=Math.min(1,Math.max(0,(n-_H)/vH));return r*(1+(hH+(gH-hH)*a-1)*i)}function xH(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 SH=KS,CH=200,wH=new J,TH=new J,EH=new J,DH=new J;function OH(e,t,n,r){e.uOccluderCount.value=Lw(e.uOccluders.value,t,r,n)}function kH(e,t,n,r,i,a,o){let s={insideShell:!1,shellProminent:!1,skyboxIntensity:1,sunTint:wH.set(1,1,1),sunRefraction:null};mN(n&&a.sunTint);let c=e.get($_);lL(c?.mesh?.material,Yb());let l=cL(c?.mesh?.material);l&&(l.uAtmoTEnable.value=0);let u=CH,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;uT(c.atmosphere,a);let f=Jb(c.body.data.id);if(f?.seasonal){let e=a.seasonal?uH(f,o):f;if(c.atmosphere.params!==e){dT(c.atmosphere,e);for(let t of c.sunTint??[])xN(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?JS(_.length()):v.realisticSunAlways?Math.sqrt(JS(_.length())):1;g.uSunIntensity.value=v.sunIntensity*y*i,_.normalize(),c.mesh&&(dH.set(0,1,0).applyQuaternion(c.mesh.quaternion),g.uSpinAxis.value.copy(dH));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&&OH(g,b,_,x);let C=a.insideView&&S<x,w=c.atmosphere.planetRadiusKm,T=S*((w+v.topAltitudeKm)/x)-w,E=C&&sT(v,T),D=C?cT(v,T):0;iT(c.atmosphere,C,E,D),g.uDeepIrradiance.value=SH*i;for(let e of c.sunTint??[])e.uAtmoTDeepIrradiance.value=SH*i,e.uAtmoTDeepBlend.value=D;if(C){s.insideShell=!0;let e=fH.copy(t).sub(b).divideScalar(S).dot(_),n=bH(v,T,e);if(s.skyboxIntensity*=n*(1-D),a.refraction&&v.refractivity&&!E){let t=xH(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:DH.copy(fH)})}}let O=S/x;if(a.sunTint&&O<CH){let e=x/(1+v.topAltitudeKm/w)*(c.atmosphere.surfaceRadiusKm/w);EH.copy(t).sub(b);let n=g.uSpinAxis.value,r=g.uStretch.value;if(PN(v,EH,_,e,c.atmosphere.surfaceRadiusKm,TH,n,r)){let e=pH[0]*TH.x+pH[1]*TH.y+pH[2]*TH.z;e>1e-4&&s.sunTint.multiply(TH.divideScalar(e))}l&&O<u&&(u=O,kN(l,v,b,e,c.atmosphere.surfaceRadiusKm,n,r))}}return s}var AH=new J;function jH(e,t){let n=0;for(let r of e.values()){if(r.body.data.objectType===G.STAR)continue;let e=r.body.data.radiusKm;!Number.isFinite(e)||e<=0||r.radiusScene<=0||!_O(r)||(t[n++]=r)}return t.length=n,t}function MH(e,t,n,r,i){let a=Mw(),o=kw(),s=e.get($_),c=s?.body.position;if(!s||!c){a.uSunAngularRadius.value=0,a.uOccluderCount.value=0,o.count=0;return}let[l,u,d]=n,f=c[0]-l,p=c[1]-u,m=c[2]-d,h=Math.hypot(f,p,m);h>0?(a.uSunDir.value.set(f/h,p/h,m/h),a.uSunAngularRadius.value=Math.asin(Math.min(s.radiusScene/h,1))):a.uSunAngularRadius.value=0;let g=t.length;for(;o.occluders.length<g;)o.occluders.push(new ha),o.leaks.push(new ha);for(let e=0;e<g;e++){let n=t[e],[r,a,s]=n.body.position;o.occluders[e].set(r-l,a-u,s-d,n.radiusScene),i&&n.atmosphere?Bw(n.atmosphere.params,n.atmosphere.planetRadiusKm,o.leaks[e]):o.leaks[e].set(0,0,0,0)}o.count=g;let _=a.uSunDir.value;a.uOccluderCount.value=Lw(a.uOccluders.value,AH,r,_,a.uOccluderLeak.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,a]=n,o=e.uEclipseSelfPos.value.set(r-l,i-u,a-d);e.uOccluderCount.value=Lw(e.uOccluders.value,o,t.radiusScene,_,e.uOccluderLeak.value)}}var NH=10;function PH(e,t,n,r,i,a,o,s,c){let l=n.visibility.activeSystemId;if(!l){r.intensity=0,i&&YS(i,s,c);return}let u=e.get($_)?.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(NH),r.target.position.set(0,0,0),r.intensity=KS*(s?JS(_):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=NH-b,x.far=NH+b,x.updateProjectionMatrix()}var FH=1.25,IH=.05,LH=2048;function RH(e,t,n){let r=(e,t)=>!!e&&e.intervals.some(([e,n])=>t>e+1e-9&&t<n-1e-9),i=[],a=Math.round(e/n);for(let o=0;o<=a;o++){let s=o===a?e:o*n;(o===0||o===a||!r(t[t.length-1],s))&&i.push({p:s,level:0})}t.forEach((n,a)=>{for(let[o,s]of n.intervals){let c=Math.ceil(Math.max(o,0)/n.step-1e-9),l=Math.floor(Math.min(s,e)/n.step+1e-9);for(let e=c;e<=l;e++){let o=e*n.step;r(t[a-1],o)||i.push({p:o,level:n.level})}}}),i.sort((e,t)=>e.p-t.p||t.level-e.level);let o=(t[0]?.step??n)*.25,s=[];for(let e of i){let t=s[s.length-1];t&&e.p-t.p<o?t.level=Math.max(t.level,e.level):s.push(e)}return s[0].p=0,s[s.length-1].p=e,{at:Float64Array.from(s,e=>e.p),level:Int8Array.from(s,e=>e.level)}}function zH(e,t){let n=2*Math.PI;if(t>=Math.PI)return[[0,n]];let r=e-t,i=e+t;return r<0?[[0,i],[r+n,n]]:i>n?[[0,i-n],[r,n]]:[[r,i]]}function BH(e){return 2*Math.PI/(LH*2**e)}function VH(e,t,n,r){let i=BH(t),a=Math.log2(Math.max(e/n,i)/i);return r!==void 0&&a>r-.85&&a<r+.15?r:Math.max(0,Math.ceil(a-1e-9))}function HH(e,t,n,r,i,a,o){let s=BH(i),c=Math.PI/128,l=2*Math.PI/128,u=e=>Math.acos(1/(1+Math.max(e,0))),d=FH*(u(n)+u(r)),f=Math.max(Math.sin(e),IH),p=Math.round(Math.log2(1/f)),m=[],h=[],g=0;for(let n=o;g<d;n++){let r=s*2**n;if(r>=c)break;g+=a*r;let o=Math.max(i-n,0);m.push({intervals:[[Math.max(e-g,0),Math.min(e+g,Math.PI)]],step:r,level:o});let u=Math.min(g/f,Math.PI),d=Math.ceil(Math.log2(2*u/(4*a)/s)-1e-9),_=Math.max(n+p,d),v=s*2**_;v>=l||h.push({intervals:zH(t,u),step:v,level:Math.max(i-(_-p),0)})}return{rows:RH(Math.PI,m,c),columns:RH(2*Math.PI,h,l),stepLevel:o,innerRadius:a*s*2**o}}function UH(e,t,n,r,i=1){let a=t.length,o=n.length,s=new Float32Array(a*o*3),c=new Float32Array(a*o*3),l=new Float32Array(a*o*2),u=Float64Array.from(n,Math.sin),d=Float64Array.from(n,Math.cos);for(let f=0;f<a;f++){let a=t[f],p=Math.sin(a),m=Math.cos(a);for(let t=0;t<o;t++){let h=f*o+t,g=-d[t]*p,_=m,v=u[t]*p,y=e+(r?r[h]*i:0),b=h*3;s[b]=y*g,s[b+1]=y*_,s[b+2]=y*v,c[b]=g,c[b+1]=_,c[b+2]=v;let x=h*2;l[x]=n[t]/(2*Math.PI),l[x+1]=1-a/Math.PI}}let f=new Uint32Array((a-1)*(o-1)*6),p=0;for(let e=0;e<a-1;e++){let n=t[e]<=0,r=t[e+1]>=Math.PI;for(let t=0;t<o-1;t++){let i=e*o+t+1,a=e*o+t,s=(e+1)*o+t,c=(e+1)*o+t+1;n||(f[p++]=i,f[p++]=a,f[p++]=c),r||(f[p++]=a,f[p++]=s,f[p++]=c)}}return{positions:s,normals:c,uvs:l,indices:f.subarray(0,p)}}var WH=256,GH=.25,KH=.32,qH=.35,JH=300,YH=4e5,XH=16,ZH=8,QH=new Y,$H=new J;function eU(e,t,n){let r=e=>t.some(([t,n])=>e>t+1e-9&&e<n-1e-9),i=e/128,a=[];for(let t=0;t<=128;t++){let n=t===128?e:t*i;(t===0||t===128||!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 tU(e){let t=new ts;return t.setAttribute(`position`,new Bo(e.positions,3)),t.setAttribute(`normal`,new Bo(e.normals,3)),t.setAttribute(`uv`,new Bo(e.uvs,2)),t.setIndex(new Bo(e.indices,1)),t}var nU=new WeakMap,rU=2;function iU(e){let t=e.displacementMeta?.tiles;return fD(t)&&!nU.get(e)?.dead?t:void 0}function aU(e,t,n,r){let i=pE(e.max_level,e.patches,n/(2*Math.PI),t/Math.PI);if(i===e.max_level)return i;let a=2**(Math.floor(Math.log2(r))-23),o=2*Math.PI*r/(ZH*a);return Math.max(e.max_level,Math.min(i,Math.floor(Math.log2(o/LH))))}function oU(e){!e.mesh||!e.displacementMeta||AD(e.mesh.material,e.displacementMeta,e.radiusScene)}function sU(e){let t=nU.get(e);t?.abort?.abort(),t&&(t.abort=void 0),e.terrainWindow&&(e.terrainWindow.riseKm&&oU(e),e.terrainWindow=null,e.currentSegments=void 0)}function cU(e,t,n,r){let i=Math.sin(e)*Math.sin(n)*Math.cos(t-r)+Math.cos(e)*Math.cos(n);return Math.acos(Math.min(1,Math.max(-1,i)))}function lU(e,t,n,r,i,a,o){let s=e.terrainWindow?.riseKm?e.terrainWindow:void 0,c=t.material;s&&(c.displacementScale=0,c.displacementBias=0);let l=nU.get(e)??{failures:0,dead:!1};if(nU.set(e,l),l.abort)return!!s;let u=e.displacementMeta;if(!u)return!!s;let d=bn(e.body.data),f=aU(n,i,a,Q(d)),p=LH*2**f,m=SE().terrainBandCells,h=f>n.max_level?Math.min(m,XH):m,g=s?.texWidth===p?s.stepLevel:void 0,_=VH(r,f,h,g);if(s){let e=cU(i,a,s.centerTheta,s.centerPhi);if(g===_&&e<qH*s.angRadius||performance.now()-s.builtAt<JH)return!0}let v=HH(i,a,r,.5*u.scale_km/d,f,h,_),y=v.rows.at,b=v.columns.at;if(y.length*b.length>YH)return console.warn(`terrain grid for ${e.body.data.id} would need ${y.length}×${b.length} vertices: left to the shader`),l.dead=!0,!!s;let x=new AbortController;l.abort=x;let S=performance.now();return qT({root:qt(n),version:n.version,maxLevel:n.max_level,patches:(n.patches??[]).map(({max_level:e,x:t,y:n,version:r})=>({max_level:e,x:t,y:n,version:r})),tileSize:n.tile_size,scaleKm:n.scale_km??0,biasKm:(n.bias_km??0)-(u.absolute_radius?d:0),radius:Q(d),unitsPerKm:Q(1),rows:v.rows,columns:v.columns},x.signal).then(n=>{if(l.abort!==x||(l.abort=void 0,l.failures=0,e.mesh!==t||!e.displacementMap))return;let r=t.geometry;t.geometry=tU(n),r.dispose(),c.displacementScale=0,c.displacementBias=0,e.terrainWindow={thetas:y,phis:b,centerTheta:i,centerPhi:a,angRadius:v.innerRadius,stepLevel:_,texWidth:p,builtAt:performance.now(),riseKm:n.riseKm},e.currentSegments=128,console.debug(`terrain grid ${e.body.data.id}: ${y.length}×${b.length}, level ${_}, ${Math.round(performance.now()-S)} ms`),o()}).catch(()=>{l.abort===x&&(l.abort=void 0,++l.failures>=rU&&(l.dead=!0))}),!!s}function uU(e,t,n,r){let i=e.mesh,a=e.displacementMap;if(!n||!i||!a)return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: eligible=${n} mesh=${!!i} tex=${!!a}`),sU(e),!1;i.updateMatrixWorld(),QH.copy(i.matrixWorld).invert(),$H.copy(t.position).applyMatrix4(QH);let o=Q(bn(e.body.data)),s=$H.length(),c=Math.max(s/o-1,1e-6);if(c>(e.terrainWindow?KH:GH))return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: alt=${c.toFixed(4)}`),sU(e),!1;let l=Math.acos(Math.min(1,Math.max(-1,$H.y/s))),u=Math.atan2($H.z,-$H.x);u<0&&(u+=2*Math.PI);let d=iU(e);if(d)return lU(e,i,d,c,l,u,r);e.terrainWindow?.riseKm&&oU(e);let f=a.image?.width??2048,p=2*Math.PI/f,m=Math.acos(1/(1+c)),h=Math.max(p,2*m*FH/WH),g=Math.log2(h/p),_=Math.max(0,Math.ceil(g-1e-9)),v=e.terrainWindow;v&&v.texWidth===f&&g>v.stepLevel-.85&&g<v.stepLevel+.15&&(_=v.stepLevel);let y=p*2**_,b=y*WH/2;if(v&&v.texWidth===f&&(v.stepLevel===_&&cU(l,u,v.centerTheta,v.centerPhi)<qH*v.angRadius||performance.now()-v.builtAt<JH))return!0;let x=Math.max(0,l-b),S=Math.min(Math.PI,l+b),C=eU(Math.PI,[[x,S]],y),w=Math.min(Math.PI,b/Math.max(Math.sin(l),IH)),T=Math.max(_,Math.ceil(Math.log2(2*w/WH/p)-1e-9)),E=p*2**Math.max(0,T),D=u-w,O=u+w,k=w>=Math.PI?[[0,2*Math.PI]]:D<0?[[0,O],[D+2*Math.PI,2*Math.PI]]:O>2*Math.PI?[[0,O-2*Math.PI],[D,2*Math.PI]]:[[D,O]],A=eU(2*Math.PI,k,E);if(C.length*A.length>YH)return console.warn(`terrain window for ${e.body.data.id} would need ${C.length}×${A.length} vertices — keeping the uniform sphere`),sU(e),!1;let j=i.geometry;return i.geometry=tU(UH(o,C,A)),j.dispose(),console.debug(`terrain window ${e.body.data.id}: ${C.length}×${A.length} grid, level ${_} (tex ${f})`),e.terrainWindow={thetas:C,phis:A,centerTheta:l,centerPhi:u,angRadius:b,stepLevel:_,texWidth:f,builtAt:performance.now()},e.currentSegments=128,!0}var dU=[{up:150,segs:128},{up:40,segs:64},{up:0,segs:32}],fU=24;function pU(e,t,n,r){if(!n&&!t)return fU;let i=dU[dU.length-1].segs;for(let t of dU)if(e>=t.up){i=t.segs;break}if(i<r){let t=dU.find(e=>e.segs===r);if(t&&e>=t.up*.85)return r}return i}function mU(e,t,n,r,i,a){let o=t.fov*Math.PI/180,s=n.domElement.clientHeight/(2*Math.tan(o/2)),c=r.visibility.activeSystemId,l=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,o=n.body.data.id;if((o===l||n.terrainWindow)&&uU(n,t,o===l,a))continue;let u=pU(n.radiusScene/n.cachedDist*s,e,c?o===c||r.visibility.isInActiveSystem(n.body.data.parentId):o===i,n.currentSegments??64);if(u===n.currentSegments)continue;let d=Q(bn(n.body.data)),f=n.mesh.geometry;n.mesh.geometry=new gu(d,u,u),f.dispose(),n.currentSegments=u}}function hU(e,t){let n=e<1.05?`high`:e<4?`medium`:`low`;if(oP(n)>oP(t))return n;let r=e>7?`low`:e>1.15?`medium`:`high`;return oP(r)<oP(t)?r:t}function gU(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=$C(),p=f.showClouds,m=oP(_E());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=oP(s.textureTier),_=rP(s)?Math.min(m,oP(`medium`)):m,v=Math.min(oP(h),_),y=lP(o,s.availableFrames),b=y!==s.textureFrame,x=v>g;if(f.showSurfaceTexture&&!s.textureLoading&&(x||b)){let e=x?sP(v,s.availableTiers):s.textureTier;e&&gP(s,e,y,i)}let S=u*n.getPixelRatio();iP(s,t,n,S,f.showSurfaceTexture&&!s.appearance?.surfaceOwned,c),gD(s,t,n,S,c);let C=s.displacementMeta?.tiers;if(s.displacementMap&&!s.displacementLoading&&LD(s,n))s.displacementTier!==`pyramid`&&RD(s,FD);else if(s.displacementMap&&C?.length&&!s.displacementLoading){let e=n.capabilities.maxTextureSize,t=e>=16383&&!mD(s)?2:+(e>=8192),r=s.displacementTier??`low`,i=sP(Math.min(oP(hU(p,r)),t,m),C);i&&i!==r&&RD(s,i)}if(s.clouds&&s.textureTier){let e=sP(oP(s.textureTier),s.clouds.availableTiers),t=JM(o,s.clouds.availableFrames,s.clouds.availableCoverage);e&&t&&ZM(s.clouds,e,t)}}}var _U=II.refMs,vU=new Y,yU=new J,bU=new J,xU=new Xi,SU=new Xi,CU=new J,wU=new J;function TU(e,t,n){return yU.set(e[0],e[1],e[2]),bU.set(t[0],t[1],t[2]),vU.lookAt(yU,bU,n),xU.setFromRotationMatrix(vU).clone()}function EU(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=wv(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=Ev(e.camOriginWorld,e.camTargetWorld,e.focusTargetWorld,n);else{let t=r?o*o*o:n;i=wv(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]),SU.copy(t.quaternion),t.quaternion.slerpQuaternions(e.flyQ0,SU,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=wv(e.camOriginWorld,e.camTargetWorld,t)}let i=TU(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 DU(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=TU([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=Tv(r,i),s=e.flyQ0.angleTo(a);e.focusDurationMs=Math.max(FI(o,RI),PI(s,zI))}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(),CU.set(0,0,-1).applyQuaternion(e.flyQ0),wU.set(t[0]-r[0],t[1]-r[1],t[2]-r[2]).normalize(),e.focusDurationMs=PI(CU.angleTo(wU),II);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 OU(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=Tv(n,r);CU.set(e.focusTruePos[0]-n[0],e.focusTruePos[1]-n[1],e.focusTruePos[2]-n[2]).normalize(),wU.set(e.focusTruePos[0]-r[0],e.focusTruePos[1]-r[1],e.focusTruePos[2]-r[2]).normalize();let o=CU.angleTo(wU);e.focusDurationMs=Math.max(FI(a,RI),PI(o,zI)),i&&(e.focusDurationMs=0)}var kU={[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},AU=5e-4,jU=new J,MU=new J;function NU(e){return kU[e.data.objectType]??bn(e.data)*.25}function PU(e,t){return Q((t??bn(e.data))+NU(e))}function FU(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(AU),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]]){MU.set(a,o,s).applyQuaternion(e.quaternion);let t=m+MU.x,n=h+MU.y,c=g+MU.z,u=Math.hypot(t,n,c);if(u<1e-12)continue;jU.set(t/u,n/u,c/u).applyQuaternion(r.invQuat);let d=r.radialKm([jU.x,jU.y,jU.z]),f=(d===null?l:Q(d))+Q(AU);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=NU(t);if(_>=Q((r?.outerRadiusKm??i)+v))return;let y=i;r&&_>1e-9&&(jU.set(m/_,h/_,g/_).applyQuaternion(r.invQuat),y=r.radialKm([jU.x,jU.y,jU.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 IU(e,t,n){let r=e.position,{latitude:i,longitude:a,distance:o}=zF([r.x,r.y,r.z],[0,0,0],n),s=Math.min(Math.max(i,t.minLat??-90),t.maxLat??90),c=UF(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]=BF([0,0,0],s,c,l,n);r.set(u,d,f)}var LU=50,RU=20;function zU(e){return e<=0?`none`:e<RU?`full`:e<LU?`half`:`none`}function BU(e,t){return wV(e.data,t)}var VU=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),Dy().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 rv)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||!xn(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:rv.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,renderer:l}=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),SL([e],o,s,c,r,l.domElement,this.deps.onBodyClick,(e,t)=>t?this.deps.hoveredBodyIds.add(e):this.deps.hoveredBodyIds.delete(e),t);let u=r.get(e.data.id);if(u&&!e.data.name&&mP(u),e.data.objectType===G.SPACECRAFT)i.bodies.dirtySpacecraftGroups.add(e.data.parentId);else if(xn(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 d=e.data.id;return this.defaults.has(d)||(n?this.autoPromoted.add(d):(this.userPromoted.add(d),this.emitUserPromotedCount())),!0}finalizeBuilds(){fR(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(ev),t=this.currentMemberCount(e),n=zU(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)||BU(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 e=y_(r.data,r.data.validityStart),i=y_(r.data,r.data.validityEnd);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),BU(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&&!BU(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||mn(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(),Vj(e),hP(e),EM(e),i.remove(e.root),e.trail&&i.remove(e.trail),e.mesh){e.mesh.geometry.dispose(),yL(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(),yL(e.atmosphere.mesh.material),null),e.trail&&(e.trail.geometry.dispose(),yL(e.trail.material));let s=e.body.data.objectType;if(s===G.SPACECRAFT)c.add(e.body.data.parentId);else if(xn(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)}},HU=class{promotion;readerFocusFilter=null;focusedBody;_tmpV3=new J;pendingInitialView=null;upgradeTargetIds=new Set;constructor(e,t,n,r){this.deps=e,this.focusedBody=t,this.promotion=new VU({scene:e.scene,bodyObjects:e.bodyObjects,ctx:e.ctx,clock:e.clock,renderer: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||Ej(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=WU(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&&(CL(t.body)?TL(t,n,r,i):Vj(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}CL(t)&&(wL(o,n,r,i),f=!0),t.data.id!==e?.data.id&&c(t)}return f&&(fR(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]}DU(r,[...n],i,a,o,$C().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,DU(n,[...e],r,a,o,$C().resolvedReducedMotion);let s=zF(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}=zF(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;mn(e)||this.promotion.ensureBodyObjects(e);let u=this.focusedBody,d=pM(u,r),f=pM(e,r),p=u&&(mn(u)?u.featureAnchor.hostId:u.data.id),m=mn(e)?e.featureAnchor.hostId:e.data.id,h=this.syncUpgradeTargets(e);if(p&&p!==m&&!h.has(p)){let e=r.get(p);e&&Vj(e)}if(d&&d!==f){let e=r.get(d);e&&EM(e)}e.data.id!==u?.data.id&&(this.pendingInitialView=null),this.focusedBody=e,mn(e)||(n.bodies.focusFeature=null),i.minDistance=PU(e,cM(r.get(e.data.id)));let g=mn(e)?n.getBody(e.featureAnchor.hostId):void 0;if(n.visibility.setFocused(g??e),a.onFocusChange(e),mn(e)||l(e),f&&f!==e.data.id){let e=n.getBody(f);e&&l(e)}c.syncToFocus();let _=this.place(e);_&&DU(o,[..._],s,this.cameraTruePos(),t,$C().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=BF(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=zF(d??this.cameraTruePos(),u,this.focusedBodyQuat(l));return s.onCameraPosition?.(f.latitude,f.longitude,f.distance),t!==void 0&&d?(this.pendingInitialView=null,this.focusedBody?.data.id===e&&Tv(a.focusTruePos,u)<PU(l)?(a.focusTruePos=[...u],this.deps.repositionAll(),c.rebuildBasis(),OU(a,o,this.cameraTruePos(),d,$C().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=VF(u,d,n,r);a.position.set(f[0],f[1],f[2]),o.update();let p=zF(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=-_U,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=!Ej(r),c=s?this.focusedBodyQuat(r)??[0,0,0,1]:void 0,l=BF([0,0,0],e,t,n,c);i.position.set(l[0],l[1],l[2]),a.update();let u=zF(l,[0,0,0],c);o.onCameraPosition?.(u.latitude,u.longitude,u.distance),this.pendingInitialView=s&&UU(c)?{latitude:e,longitude:t,zoom:n}:null}reapplyInitialViewIfPending(){let e=this.pendingInitialView;if(!e)return;let t=this.focusedBodyQuat();if(!t||UU(t)){this.pendingInitialView=null;return}let n=BF([0,0,0],e.latitude,e.longitude,e.zoom,t);this.deps.camera.position.set(...n),this.deps.controls.update(),this.pendingInitialView=null}};function UU(e){return e[0]===0&&e[1]===0&&e[2]===0&&e[3]===1}function WU(e,t){if(!e)return[];if(mn(e)){let n=t.getBody(e.featureAnchor.hostId);return n&&CL(n)?[n]:[]}let n=[];if(CL(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 GU=1e-6;function KU(e){return e.data.name??e.data.id}var qU=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),sS(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]-GU,a=r[0]+GU;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:KU(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)}},JU=class{group=new qa;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()}},YU=Math.PI/180;function XU(e){return`latitude`in e}function ZU(e,t,n){let r=e*YU,i=t*YU,a=[Math.cos(r)*Math.cos(i),Math.sin(r),-Math.cos(r)*Math.sin(i)];return n&&QU(n,a,0,a,0),a}function QU(e,t,n,r,i){let a=t[n]*e.a,o=t[n+1]*e.c,s=t[n+2]*e.b,c=Math.hypot(a,o,s);r[i]=a/c,r[i+1]=o/c,r[i+2]=s/c}var $U=class{source=null;radii;out=new Float64Array;of(e,t){if(!t)return e;if(e!==this.source||t!==this.radii){this.out.length!==e.length&&(this.out=new Float64Array(e.length));for(let n=0;n<e.length;n+=3)QU(t,e,n,this.out,n);this.source=e,this.radii=t}return this.out}};function eW(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 tW(e,t,n){return t.place(e,n)}function nW(e,t,n,r){let[i,a,o]=n;if(XU(e)){let n=Q(bn(t.data)+(e.altitudeKm??0)),[s,c,l]=ZU(e.latitude,e.longitude,t.drawnRadii),u=t.orientation?xS(t.orientation,r,t.nutPrec):null;if(!u)return[i+s*n,a+c*n,o+l*n];let d=[0,0,0];return eW(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]=hB(s);return[i+c,a+l,o+u]}function rW(e,t,n){let r=t.getBody(e.body),i=r&&tW(r,t,n);return i?nW(e,r,i,n):null}function iW(e,t,n,r){let i=n.getBody(e.body),a=i&&tW(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 aW(e){let t=_g/10;return[e[0]*t,-e[2]*t,e[1]*t]}function oW(e,t,n){let r=rW(e.position,t,n),i=rW(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 sW=.02,cW=1e-4,lW=1e3/60;function uW(e){return e?.4:.05}function dW(e,t){return 1-(1-e)**(t/lW)}function fW(e,t,n,r,i){let a=e.position.length();if(!(a>0))return{rotate:1,translate:1};let o=Ej(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(bn(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(bn(o.data)):0,l=Math.tan(Yi.degToRad(e.getEffectiveFOV())/2);return{rotate:pW(c>0?(a-c)*l/(Math.PI*c):1,cW),translate:pW(s/a,sW)}}function pW(e,t){return Math.min(1,Math.max(t,e))}var mW=Math.PI/180;function hW(e,t){let n=e*mW,r=t*mW;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function gW(e,t,n,r){let i=document.createElement(`div`);i.className=`user-location-marker`;let a=new DT(i),[o,s,c]=hW(n,r);return a.position.set(o*t,s*t,c*t),e.add(a),a}function _W(e){e.parent?.remove(e),e.element.remove()}var vW=new J;function yW(e,t,n){if(!e)return;let r=t.get(ev);if(!r?.mesh)return;vW.copy(e.position).applyQuaternion(r.mesh.quaternion);let i=vW.x,a=vW.y,o=vW.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 bW=-1,xW=1.2,SW=Q(1e6),CW=.02,wW=2,TW=2.3,EW=.9,DW=new J,OW=.25,kW=10,AW=4,jW=4,MW=28,NW=.02,PW=class e{renderer;composer;maxSceneSamples;atmoDepthPass;modelDepthPass=new IL;bloomPass;labelRenderer;scene;camera;controls;motionScale={rotate:1,translate:1};pointerInteraction;gpuPick;canvas;ctx;clock;callbacks;selectedFeatureId=null;bodyObjects=new Map;circleTexture=BL();pointClouds;systemData;positionDiagnostics=new BV;placer;clickables=[];meshToBody=new Map;hoveredBodyIds=new Set;cullFrameCounter=0;hideCappedMoonLabels=!1;focusController;coverageWatch=null;outOfRange;extensions=new JU;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;_tmpFwd=new J;_tmpSun=new J;_tmpLeak=new J;_occluders=[];_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:_U};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 Xi;unsubscribeBodiesAdded=null;_trailView={camX:0,camY:0,camZ:0,tolAngle:0};viewportH=1;tier=SE();landedNomBodyId=null;rafId=0;paused=!1;covered=!1;firstFrame=!0;pendingUrlWrite=!1;lastTickMs=0;orbitDampingFactor;static FPS_SAMPLE_FRAMES=30;fpsSamples=[];fpsSampleHead=0;stashedSky=null;namesShown=!0;halosShown=!0;textureLoader=new sd;appearances=new OL;shadowLight;ambientLights;get sunPointLight(){return this.bodyObjects.get($_)?.root.children.find(e=>e instanceof wd)}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 OV(o.notices),this.labelContainer=n;let s=CI(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.maxSceneSamples=s.maxSceneSamples,this.bloomPass=s.bloomPass,this.shadowLight=s.shadowLight;let c=this.renderer.getDrawingBufferSize(new q);this.atmoDepthPass=new EL(c.x,c.y),this.modelScene=new to,this.modelScene.environment=XS(this.renderer),this.modelScene.environmentIntensity=qS,this.modelCamera=new bd(60,1,.01,1e3),this.modelScene.add(this.modelCamera);let l=new Od(16777215,GS);this.modelScene.add(l),this.ambientLights=[s.ambientLight,l],this.modelLight=new Dd(16777215,KS),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 Us(new fu(40,40),new _u({opacity:.55})),this.modelShadowPlane.receiveShadow=!0,this.modelShadowPlane.visible=!1,this.modelScene.add(this.modelShadowPlane),this.skyboxAdjuster=new gR(this.scene),this.skyDebugMarkers=new PR(this.scene),this.haloDebug=new UR(this.canvas),this.travelPath=new KB(this.scene,this.canvas),this.travelPath.setLayer(e.MAP_LAYER),this.orbitPreview=new ZB(this.scene),this.orbitPreview.setLayer(e.MAP_LAYER),this.skyboxAdjuster.set(0,0,0),qP(this.scene,this.renderer,r,()=>this.disposed),this.placer=new zV(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===WF),r.bodies.majorBodies.find(e=>e.data.id===$_)].find(e=>e&&this.placer.place(e,this.clock.jd)),d=u?.position??rV;this.focus.focusTruePos=[...d],this.focus.focusOriginWorld=[...d],this.focus.focusTargetWorld=[...d],this.focus.focusStartTime=-_U,this.pointClouds=new Sz(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 _F(this.camera,t),this.controls.enableDamping=!0,this.orbitDampingFactor=uW($C().resolvedReducedMotion),this.controls.minDistance=u?PU(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 WI(this.camera,this.controls,r,e=>this.isLanded(e)),this.systemData=new mR(this.scene,r,this.renderer,this.textureLoader,this.bodyObjects,i,()=>this.focusController.reapplyInitialViewIfPending()),this.focusController=new HU({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.renderer),this.coverageWatch=new qU(i,o.notices);let f=u?.data.id===a.id?a:{latitude:45,longitude:0,zoom:15},p=BF([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 MI(this.renderer,this.camera),this.pointerInteraction=new DI(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(){SL(this.ctx.bodies.majorBodies,this.scene,this.clickables,this.meshToBody,this.bodyObjects,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)))(()=>{fR(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]=hB(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]=hB(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=Tv(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){zz(i.body,a,o,e,this.sceneJd);continue}let s=a.userData.trailLocalPositions;if(!s)continue;let c=a.userData.orbitCenter;Bz(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.controls.dampingFactor=dW(this.orbitDampingFactor,n||16.666666666666668),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():EU(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=xv(a.data.parentId),t=e?this.ctx.getBody(e):void 0,n=!!this.bodyObjects.get(a.data.id)?.isLanded||mn(a);t&&FU(this.camera,t,this.focus.focusTruePos,this.surfaceClamp(t,n)),aM(this.bodyObjects.get(a.data.id))&&FU(this.camera,a,this.focus.focusTruePos,this.surfaceClamp(a,!1)),this.setMotionScale(fW(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=tB(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(),eV(this.bodyObjects,this.focus,this.lastUpdatedJd,this.trailView()),tH(this.bodyObjects,this.focus.focusTruePos,$C().realisticLighting,$C().overexposeRings,this.camera.position,this.pxPerRad());let s=jH(this.bodyObjects,this._occluders);MH(this.bodyObjects,s,this.focus.focusTruePos,this.camera.position.length(),$C().showAtmospheres),GV(this.bodyObjects,s,$C().realisticLighting,this.sunIntensityScale),s.length=0;let c=kH(this.bodyObjects,this.camera.position,$C().showAtmospheres,$C().realisticLighting,this.sunIntensityScale,aw(),this.sceneJd);gw(r,c.shellProminent),this.scene.backgroundIntensity=c.skyboxIntensity,this.applyLayerChrome();let l=this.bodyObjects.get($_);l&&oL(l.corona,l.starPoint,c.sunTint);let u=$C().highAmbient?1:GS;if(!$C().highAmbient&&$C().realisticLighting){let e=this.bodyObjects.get($_)?.body.position;if(e&&this.ctx.visibility.activeSystemId){let[t,n,r]=this.focus.focusTruePos;u*=JS(Math.hypot(e[0]-t,e[1]-n,e[2]-r))}}for(let e of this.ambientLights)e.intensity=u;yW(this.userLocationMarker,this.bodyObjects,this.camera);let d=pM(this.focusController.current,this.bodyObjects);gU(this.bodyObjects,this.camera,this.renderer,this.ctx,this.textureLoader,d,this.sceneJd,this.appearances,this.invalidate),mU(this.bodyObjects,this.camera,this.renderer,this.ctx,d,this.invalidate),PH(this.bodyObjects,this.focus.focusTruePos,this.ctx,this.shadowLight,this.sunPointLight,o,this._tmpV3,$C().realisticLighting,this.sunIntensityScale),this.updateModelMounts(),this.pointClouds.drainOnePendingSceneAdd(),this.updateDepthFar(),this.updateSunProxy(c.sunRefraction),c.insideShell&&this.atmoDepthPass.run(this.renderer,this.scene,this.camera,this.bodyObjects,e.ATMO_DEPTH_LAYER),this.syncSceneSamples(c.insideShell),this.composer.readBuffer.resolveDepthBuffer=this.overlayActive,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)};syncSceneSamples(e){let t=this.composer.readBuffer,n=e?0:Math.min(this.tier.sceneSamples,this.maxSceneSamples);t.samples!==n&&(t.samples=n,t.dispose())}updateTightFar(e){if(yw())return;let t=this.focusController.current,n=t?pM(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?TW:wW;this.tightFar=i>0&&this.ctx.visibility.activeSystemId!==null&&a<i*s}updateDepthFar(){if(yw())return;let e=bI,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($_);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(bI,Math.max(SW,Math.sqrt(a)*xW))}Math.abs(e-this.camera.far)>this.camera.far*CW&&(this.camera.far=e,this.camera.updateProjectionMatrix())}updateSunProxy(e){let t=this.bodyObjects.get($_),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=DW.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*EW,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}tilesFailed(e){return!!this.bodyObjects.get(e)?.tileOverlay?.chain.dead}surfaceRadialKm(e,t,n){let r=this.ctx.getBody(e);if(!r)return null;let i=ZU(t,n,r.drawnRadii);return mO(this.bodyObjects.get(e),e,bn(r.data),i)}surfaceClamp(e,t){let n=this.bodyObjects.get(e.data.id);if(aM(n))return{invQuat:n.model.quaternion.clone().invert(),seated:t,outerRadiusKm:sM(n),centerOffsetScene:oM(n),radialKm:e=>iM(n,e)};if(!(!t||!e.orientation))return{invQuat:xS(e.orientation,this.sceneJd,e.nutPrec).invert(),seated:t,radialKm:t=>mO(n,e.data.id,e.data.radiusKm,t)}}updateModelMounts(){let e=!1;for(let t of this.bodyObjects.values())if(t.model&&Ej(t.body)&&_O(t)){e=!0;break}this.overlayActive=e;for(let t of this.bodyObjects.values()){let n=t.model;if(!n)continue;let r=_O(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=Pj(e);t.scale.setScalar(n);let r=this.shadowLight.intensity>0;if(this.shadowLight.castShadow=r,!r)return;let i=this.bodyObjects.get($_)?.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,kW*n),this.shadowLight.target.position.copy(e.root.position);let o=this.shadowLight.shadow.camera;o.left=o.bottom=-AW*n,o.right=o.top=AW*n,o.near=jW*n,o.far=MW*n,o.updateProjectionMatrix(),this.shadowLight.shadow.normalBias=NW*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=Pj(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||!_O(t))continue;let i=Pj(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($_)?.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]),$C().realisticLighting&&(c=JS(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=zw(this._tmpV3,this._tmpV3),u=Uw(this._tmpV3,this._tmpV3,this._tmpLeak);this.modelLight.color.setRGB(l+u.x,l+u.y,l+u.z),this.modelLight.intensity=KS*c*this.sunIntensityScale,this.modelScene.environmentIntensity=qS*l*c,this.showPointingAxes?(this.pointingAxes||(this.pointingAxes=this.buildPointingAxes(),this.modelScene.add(this.pointingAxes)),this.pointingAxes.quaternion.copy(e.model.quaternion),this.pointingAxes.scale.setScalar(Math.min(.8,.45*i)),this.pointingAxes.visible=!0):this.pointingAxes&&(this.pointingAxes.visible=!1);let d=e.model.userData;this._tmpV3.copy(d.boxCenter).applyQuaternion(e.model.quaternion).add(e.model.position),this.modelCamera.getWorldDirection(this._tmpFwd);let f=this._tmpV3.sub(this.modelCamera.position).dot(this._tmpFwd)-d.halfExtents.length();this.renderer.autoClear=!1,this.renderer.clearDepth(),this.modelDepthPass.run(this.renderer,this.composer.readBuffer.depthTexture,this.camera,this.modelCamera,r,f),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=OW/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 zF([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?bW:Mn.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||IU(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&&oW(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&&(pP(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&&(SS(t.mesh,e.orientation,this.sceneJd,e.nutPrec),this.focusController.reapplyInitialViewIfPending())}),Rj(t,this.modelScene,this.ctx).then(()=>{if(this.focusController.current?.data.id===t.body.data.id&&(this.controls.minDistance=PU(t.body,cM(t))),!this.ctx.layers.skipped.has(`nomenclature`))return xM(t,this.canvas,(e,n,r,i)=>{this.featureSelectEnabled&&this.callbacks.onFeatureSelect?.(t.body.data.id,e,n,r,i)})}).then(()=>{this.selectedFeatureId!==null&&TM(t,this.selectedFeatureId)}))}reapplyBodyLayers(){let e=this.focusController.current;if(!e)return;let t=this.bodyObjects.get(e.data.id);t&&(Vj(t),hP(t),this.maybeLoadTexture(e))}setSelectedFeature(e){this.selectedFeatureId=e;let t=pM(this.focusController.current,this.bodyObjects),n=t?this.bodyObjects.get(t):void 0;n&&TM(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&&!mn(e))return null;let t=xv(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`}|${tO()}`}lastProbeTargetCheck=null;requestedProbeTargets=new Set;probeTargetRetries=new Tx(()=>{this.lastProbeTargetCheck=null,this.invalidate()});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),nS(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)||this.probeTargetRetries.waiting(r))return;this.requestedProbeTargets.add(r),this.ctx.ensureBody(r,jg(this.clock.jd)).then(()=>this.probeTargetRetries.clear(r),e=>{console.warn(`[renderer] the body ${r} a craft is fit to did not load:`,e),this.requestedProbeTargets.delete(r),this.probeTargetRetries.fail(r)});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(jg(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)+(this.ctx.refresher?.wakes??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(jg(this.clock.jd)),this.focusController.promotion.onSimTimeChanged();let o=$B({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.orbitDampingFactor=uW(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=pM(this.focusController.current,this.bodyObjects)===e.hostId,c=KF(e,t);this.ctx.bodies.focusFeature=c;let l=this.bodyObjects.get(a.data.id);this.selectedFeatureId=e.featureId,l&&TM(l,e.featureId);let u=this.whereBody(c);if(!u)return 0;let d=this.focusController.focusedBodyQuat(c);if(r===`pan`){let e=zF(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?BF(u,i.latitude,i.longitude,i.zoom,d):[u[0]+f*n,u[1]+p*n,u[2]+m*n],_=zF(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=-_U,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(),OU(this.focus,this.camera,e,g,$C().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||!_O(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&&_O(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=mn(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 JR({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:Ej(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 qa,t=new J(0,0,0),n=(n,r,i,a)=>{let o=new af(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 xs(new ss({map:new Kc(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=Jb(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&&dT(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(ev);n?.mesh&&(this.userLocationMarker&&_W(this.userLocationMarker),this.userLocationMarker=gW(n.mesh,n.radiusScene,e,t))}clearUserLocation(){this.userLocationMarker&&=(_W(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(CE()),this.composer.setPixelRatio(CE()),this.resize(this.canvas.clientWidth,this.canvas.clientHeight),qP(this.scene,this.renderer,this.ctx,()=>this.disposed),this.resume()}recoverWorkersIfDead(e){return this.pointClouds.recoverWorkersIfDead(e)}applyRenderTier(){this.tier=SE();let e=CE();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),pI(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&&Vj(e);for(let e of this.bodyObjects.values())eP(e),hD(e);this.pointClouds.dispose(),this.disposeScene(this.scene),this.disposeScene(this.modelScene),FW(this.scene.background),FW(this.scene.environment),FW(this.modelScene.environment),this.circleTexture.dispose(),this.bodyObjects.clear(),this.composer.dispose(),this.atmoDepthPass.dispose(),this.modelDepthPass.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))FW(t);e.dispose()}})}};function FW(e){e&&typeof e==`object`&&e.isTexture&&e.dispose()}var IW=Ze({progress:null,bootPending:!1}),LW=6371;function RW(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 zW={topAltitudeKm:67,rayleighScatterPerKm:[.0058,.0136,.0331],rayleighScaleHeightKm:8.4,mieScatterPerKm:[.004,.004,.004],mieAbsorptionPerKm:[4e-4,4e-4,4e-4],mieScaleHeightKm:1.2,miePhase:RW(.75),absorptionPerKm:[65e-5,.001881,85e-6],absorptionCenterKm:25,absorptionWidthKm:15,bakedCompensation:1,multiScatterGain:.3,sunIntensity:5,sunColor:[1,1,1]},BW=1.6,VW=1.0005,HW=new J(.55,.25,.8).normalize(),UW=[`low`,`medium`,`high`,`ultra`],WW=4,GW=12,KW=10,qW=16,JW=5;function YW(e){return!e.limb&&!e.sky?NaN:Math.max(e.limb?.medianMs??0,e.sky?.medianMs??0)}function XW(e,t){let n=`low`;for(let r of e.tiers){let e=YW(r);!Number.isNaN(e)&&e<=t&&(n=r.tier)}return n}var ZW=new Set([`WebKit WebGL`,`Mozilla`,``]);function QW(e){let t=e.getContext(),n=String(t.getParameter(t.RENDERER)??``);if(!ZW.has(n))return n;let r=t.getExtension(`WEBGL_debug_renderer_info`);return r?String(t.getParameter(r.UNMASKED_RENDERER_WEBGL)):n}function $W(e,t){let n=e.getContext(),r=new to,i=new bd(50,n.drawingBufferWidth/Math.max(n.drawingBufferHeight,1),.005,100),a=new Du({color:7829367,roughness:1,metalness:0}),o=new Us(new gu(1,64,64),a);o.renderOrder=1,r.add(o);let s=new Dd(16777215,2);s.position.copy(HW),r.add(s);let c=zW,l=rT(c,1,LW),u=l.material.uniforms;u.uSunDir.value.copy(HW),u.uSunIntensity.value=c.sunIntensity,r.add(l.mesh);let d=e=>{let t=e===`sky`;t?(i.position.set(0,VW,0),i.lookAt(1,VW+.1,0)):(i.position.set(0,0,BW),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}={})=>{uT(l,nw[e]),d(t);let i=0;for(let e=0;e<WW;e++)r?.(`warmup`,e+1),await p(),i=m(1);let a=Math.min(qW,Math.max(1,Math.ceil(KW/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<GW;e++)if(r?.(`measure`,e+1),await p(),o.push(m(a)),n!==void 0&&o.length>=JW){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(),mT(l)}}}function eG(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 tG(e,t){let n=t.tiers??UW,{budgetMs:r,signal:i,onProgress:a}=t,o=Math.max(0,n.indexOf(t.startTier??n[n.length-1])),s=$W(e,i),c=WW+GW,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`?WW: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`?GW:WW,fraction:u})}}),f=new Map,p=new Map,m=async e=>{let t=n[e];if(nw[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 eG(e,n,f,p)}var nG=60,rG=100,iG=3e4,aG=25e4,oG=`v1`,sG=!1,cG=null,lG=Promise.resolve();function uG(e){let t=e.getContext(),n=Math.round(t.drawingBufferWidth*t.drawingBufferHeight/aG);return`${QW(e)}|${n}|${oG}`}function dG(){sG||typeof window>`u`||(sG=!0,IW.bootPending=!0,lG=new Promise(e=>{let t=()=>{IW.bootPending=!1,e()};setTimeout(t,iG),setTimeout(()=>void pG(!1).finally(t),rG)}))}function fG(){return lG}function pG(e){return cG??=mG(e).finally(()=>cG=null),cG}async function mG(e){let t=$C();if(!e&&(t.atmosphereQuality!==`auto`||!t.showAtmospheres))return;let n=null;try{n=new wh({canvas:document.createElement(`canvas`),antialias:!0}),n.setPixelRatio(qC()),n.setSize(window.innerWidth,window.innerHeight,!1);let r=uG(n);if(!e&&t.atmosphereCalibration?.key===r)return;IW.progress=0;let i=await tG(n,{budgetMs:1e3/nG,startTier:rw(),onProgress:e=>IW.progress=e.fraction}),a={};for(let e of i.tiers){let t=YW(e);Number.isNaN(t)||(a[e.tier]=Math.round(t*100)/100)}let o=XW(i,1e3/nG);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{IW.progress=null,n?.dispose(),n?.forceContextLoss()}}var hG=class{object=new qa;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 DT(e.element);let[n,r]=e.align??[.5,.5];this.label.center.set(n,r),this.object.add(this.label),this.object.matrixAutoUpdate=!1,FT(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?rW(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=iW(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()}},gG=3,_G=new J,vG=new J,yG=new J;function bG(e){let[t,n=t]=(e??``).split(/[\s,]+/).filter(Boolean).map(Number);return t>0&&n>0?[t,n]:null}function xG(e,t){return _G.set(1,0,0).applyQuaternion(e.quaternion),vG.set(0,1,0).applyQuaternion(e.quaternion),yG.set(0,0,-1).applyQuaternion(e.quaternion),t/(2*Math.tan(e.getEffectiveFOV()*Math.PI/360))}function SG(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*_G.x+a*_G.y+o*_G.z,r[1]=i*vG.x+a*vG.y+o*vG.z,r[2]=i*yG.x+a*yG.y+o*yG.z}function CG(e,t,n){yG.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)*yG.x+(e[o*3+1]-i)*yG.y+(e[o*3+2]-a)*yG.z<n.near*2)return!0;return!1}function wG(e,t,n,r,i){let a=xG(n,r),o=[0,0,0],s=0,c=0,l=0,u=!1;for(let r=0;r<t;r++){if(SG(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 TG=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=xG(r,i),o=i*r.aspect*gG/2,s=i*gG/2,c=r.near*2,{a:l,b:u}=this,d=!1,f=0,p=0,m=0;n>0&&SG(e,0,r,l);for(let i=0;i+1<n;i++,[l,u]=[u,l]){SG(e,i+1,r,u);let n=0,h=1;for(let e=0;e<5&&n<=h;e++){let t=EG(e,l,a,o,s,c),r=EG(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 EG(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 DG=1e-9,OG=class{object=new qa;anchor;color;widthPx;opacity;dash;fade;closed;local;count=0;mesh=null;scratch=new Float32Array;alphas=new Float32Array;seen=new TG;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=bG(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?rW(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])>DG||Math.abs(o[1]-this.lastOrigin[1])>DG||Math.abs(o[2]-this.lastOrigin[2])>DG;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||CG(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),QL(this.mesh.geometry,e.points,e.alphas,e.alphas,e.count),this.dash&&tR(this.mesh.geometry,e.lengths,e.count)}else s&&QL(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=nR(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 kG(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=AG(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,AG(n,a)]}function AG(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 jG(e,t={}){let[n,r]=kG(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 MG(e){if(e.length<3)return[];let[t,n]=kG(NG(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 lu.triangulateShape(r,[]).flat()}function NG(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 PG(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 FG([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 FG(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 IG(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]]:FG([n,r,i])}function LG(e,t){return new Tu({transparent:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:new X(e)},uOpacity:{value:t},uCenterOffset:{value:new J}},vertexShader:`
|
|
6366
|
+
`;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 MR(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 ts;c.setAttribute(`position`,new Uo(o,3));let l=new Lc(c,new wc({color:r,transparent:!0,opacity:.55}));return l.frustumCulled=!1,l}function NR(){let e=new qa;e.name=`sky-debug-markers`,e.visible=!1;let t=new J;for(let n of CR){AR(n.raDeg,n.decDeg,t).multiplyScalar(SR);let r=new DT(jR(n));r.center.set(0,.5),r.position.copy(t),e.add(r)}for(let t of kR){let n=MR(t.zero,t.pole,SR*.999,t.color,OR);n.name=t.name,e.add(n)}return e}function PR(e){e.traverse(e=>{e instanceof DT&&e.element.remove(),e instanceof Lc&&(e.geometry.dispose(),e.material.dispose())}),e.parent?.remove(e)}var FR=class{group=null;constructor(e){this.scene=e}setVisible(e){e?(this.group||(this.group=NR(),this.scene.add(this.group)),this.group.visible=!0):this.group&&=(PR(this.group),null)}},IR=new J,LR=new J,RR=new J,zR=[IR,LR,RR];function BR(e,t,n){return IR.set(1,0,0).applyQuaternion(e).transformDirection(t),LR.set(0,1,0).applyQuaternion(e).transformDirection(t),RR.set(0,0,1).applyQuaternion(e).transformDirection(t),{e:zR,a:n}}function VR(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 HR(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 UR(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 WR=class{canvas=null;gfx=null;tmp=new J;tmpQ=new Xi;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=gO(this.items,y++,GR),T=!!(o.semiAxesScene&&o.mesh);if(T){let e=BR(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],HR(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,VR(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,kO(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,DO(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(),JR(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)}}qR(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 GR(){return{id:``,camX:0,camY:0,camZ:0,worldR:0,e0:new J,e1:new J,e2:new J,sa:[0,0,0],occ:xO(),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 KR=[[`#1ae5ff`,`label shown`],[`#ffe11a`,`dimmed`],[`#ff3b3b`,`hidden`],[`#ff8c1a`,`occluder silhouette`],[`#7dff7d`,`focused`]];function qR(e,t){let n=t-8-(KR.length-1)*13;e.font=`10px monospace`,e.textBaseline=`middle`;for(let[t,r]of KR)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 JR(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 YR(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 XR="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:P,mp:se}=t,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,Y,X,le,ue,de,fe;fe=k+119459e-10*b,A===`y`&&(fe=k),de=fe+2*.01675*Math.sin(fe),X=Math.sin(de),U=.5*X*X-.25,W=-.5*X*Math.cos(de);let pe=d*U+f*W,me=g*U+ne*W,he=_*U+v*W+y*X,ge=p*U+m*W+ee*X,Z=te*U+h*W;fe=O+.00015835218*b,A===`y`&&(fe=O),de=fe+2*.0549*Math.sin(fe),X=Math.sin(de),U=.5*X*X-.25,W=-.5*X*Math.cos(de);let _e=r*U+n*W,ve=C*U+w*W,ye=T*U+E*W+D*X,be=re*U+ie*W+x*X,xe=ae*U+S*W;return G=pe+_e,J=me+ve,Y=he+ye,K=ge+be,q=Z+xe,A===`n`&&(G-=i,J-=l,Y-=u,K-=s,q-=c,M+=J,oe+=G,R=Math.sin(M),L=Math.cos(M),M>=.2?(q/=R,K-=L*q,P+=K,N+=q,se+=Y):(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),le=se+P+L*N,H=Y+K-J*N*R,le+=H,ue=N,N=Math.atan2(F,I),N<0&&j===`a`&&(N+=o),Math.abs(ue-N)>a&&(N<ue?N+=o:N-=o),se+=Y,P=le-se-L*N)),{ep:oe,inclp:M,nodep:N,argpp:P,mp:se}}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,P,se,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,Y,X,le,ue,de,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,le=3*(l*l+u*u)+_e*$,ue=6*(l*d+u*f)+ve*$,de=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),le=le+le+ke*_e,ue=ue+ue+ke*ve,de=de+de+ke*ye,K=ne*We,G=-.5*K/Ae,q=K*Ae,W=-15*Ce*q,J=_*y+v*b,Y=v*y+_*b,X=v*b-_*y,Ge===1&&(O=W,k=G,A=K,j=q,oe=J,M=Y,N=X,P=le,se=ue,F=de,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*se,$e=-2*A*(F-P),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*Y,st=2*W*X,ct=2*G*pe,lt=2*G*(me-fe),ut=-2*K*ue,dt=-2*K*(de-le),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:Y,s7:X,ss1:O,ss2:k,ss3:A,ss4:j,ss5:oe,ss6:M,ss7:N,sz1:P,sz2:se,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:le,z2:ue,z3:de,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:P,z33:se,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:Y,d4422:X,d5220:le,d5232:ue,d5421:de,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*(P+se-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,Y=qe*$*Be,X=qe*ke*Ve,Je*=Ze,qe=Je*1.1428639e-7,le=qe*Ae*He,ue=qe*je*We,qe=2*Je*2.1765803e-9,de=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:Y,d4422:X,d5220:le,d5232:ue,d5421:de,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,P=5.7686396,se=.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-P)+r*Math.sin(D-P)+i*Math.sin(G+D-se)+a*Math.sin(-G+D-se)+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-P)+r*Math.cos(D-P)+i*Math.cos(G+D-se)+a*Math.cos(-G+D-se)+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,P=e.argpo+e.argpdot*e.t,se=e.nodeo+e.nodedot*e.t;g=P,D=N;let F=e.t*e.t;if(k=se+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=P-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 Y=L*(1-G),X=Math.sqrt(L)*K/Y,le=Math.sqrt(J)/Y,ue=Math.sqrt(1-q);S=K/(1+ue);let de=L/Y*(r-H-V*S),fe=L/Y*(n-V+H*S);v=Math.atan2(de,fe);let pe=(fe+fe)*de,me=1-2*de*de;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=Y*(1-1.5*ge*ue*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=X-O*he*e.x1mth2*pe/l,be=le+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,P,se,F,I,L,R,ce,z,B,V,H,U,W,G,K,q,J,Y,X,le,ue,de,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}P=1/Pe,Z=1/($-B),Q.eta=$*Q.ecco*Z,O=Q.eta*Q.eta,D=Q.ecco*Q.eta,se=Math.abs(1-O),S=F*Z**4,C=S/se**3.5,ie=C*Q.no*($*(1+1.5*O+D*(4+O))+.375*f*Z/se*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/($*se)*(-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*P*Q.no,he=.5*me*f*P,ge=-.46875*-165597e-11*P*P*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:Y,sz21:X,sz23:le,sz31:ue,sz33:de}=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:Y,sz21:X,sz23:le,sz31:ue,sz33:de,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=2451545,T=86400,E=[[2441317.5,10],[2441499.5,11],[2441683.5,12],[2442048.5,13],[2442413.5,14],[2442778.5,15],[2443144.5,16],[2443509.5,17],[2443874.5,18],[2444239.5,19],[2444786.5,20],[2445151.5,21],[2445516.5,22],[2446247.5,23],[2447161.5,24],[2447892.5,25],[2448257.5,26],[2448804.5,27],[2449169.5,28],[2449534.5,29],[2450083.5,30],[2450630.5,31],[2451179.5,32],[2453736.5,33],[2454832.5,34],[2456109.5,35],[2457204.5,36],[2457754.5,37]];function D(e){for(let t=E.length-1;t>=0;t--)if(e>=E[t][0])return E[t][1];return E[0][1]-1}function O(e){let t=6.239996+1.99096871e-7*(e-w)*T;return .001657*Math.sin(t+.01671*Math.sin(t))}function k(e){if(!Number.isFinite(e))return e;let t=e+(D(e)+32.184)/T;return t+O(t)/T}const A=Math.PI/180,j=A/3600,oe=1e-4*j,M=[[0,0,0,0,1,-171996,-174.2,92025,8.9],[0,0,2,-2,2,-13187,-1.6,5736,-3.1],[0,0,2,0,2,-2274,-.2,977,-.5],[0,0,0,0,2,2062,.2,-895,.5],[0,1,0,0,0,1426,-3.4,54,-.1],[1,0,0,0,0,712,.1,-7,0],[0,1,2,-2,2,-517,1.2,224,-.6],[0,0,2,0,1,-386,-.4,200,0],[1,0,2,0,2,-301,0,129,-.1],[0,-1,2,-2,2,217,-.5,-95,.3],[1,0,0,-2,0,-158,0,-1,0],[0,0,2,-2,1,129,.1,-70,0],[-1,0,2,0,2,123,0,-53,0],[1,0,0,0,1,63,.1,-33,0],[0,0,0,2,0,63,0,-2,0],[-1,0,2,2,2,-59,0,26,0],[-1,0,0,0,1,-58,-.1,32,0],[1,0,2,0,1,-51,0,27,0]];function N(e,t){let n=Array(9);for(let r=0;r<3;r++)for(let i=0;i<3;i++)n[3*r+i]=e[3*r]*t[i]+e[3*r+1]*t[3+i]+e[3*r+2]*t[6+i];return n}function P(e){let t=Math.cos(e),n=Math.sin(e);return[1,0,0,0,t,n,0,-n,t]}function se(e){let t=Math.cos(e),n=Math.sin(e);return[t,0,-n,0,1,0,n,0,t]}function F(e){let t=Math.cos(e),n=Math.sin(e);return[t,n,0,-n,t,0,0,0,1]}function I(e){let t=(e-w)/36525,n=(2306.2181*t+.30188*t*t+.017998*t**3)*j,r=(2004.3109*t-.42665*t*t-.041833*t**3)*j,a=(2306.2181*t+1.09468*t*t+.018203*t**3)*j,o=134.96298139+477198.8673981*t+.0086972*t*t,s=357.52772333+35999.05034*t-1603e-7*t*t,c=93.27191028+483202.0175381*t-.0036825*t*t,l=297.85036306+445267.11148*t-.0019142*t*t,u=125.04452222-1934.1362608*t+.0020708*t*t,d=0,f=0;for(let[e,n,r,i,a,p,m,ee,te]of M){let h=(e*o+n*s+r*c+i*l+a*u)*A;d+=(p+m*t)*Math.sin(h),f+=(ee+te*t)*Math.cos(h)}d*=oe,f*=oe;let p=(84381.448-46.815*t-59e-5*t*t+.001813*t**3)*j,m=d*Math.cos(p),ee=N(N(N(N(F(n),se(-r)),F(a)),N(N(P(-p),F(d)),P(p+f))),F(-m));return N(P(i*A),ee)}let L=NaN,R=[1,0,0,0,1,0,0,0,1];function ce(e){return Math.abs(e-L)<=.01||(R=I(e),L=e),R}function z(e){return new Date((e-2440587.5)*864e5).toISOString()}function B(e,t){let n=C({OBJECT_NAME:t??String(e.noradCatId),OBJECT_ID:String(e.noradCatId),EPOCH:z(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 V=Math.PI/180;Math.cos(i*V),Math.sin(i*V);const H=Math.PI/180,U=Math.cos(i*H),W=Math.sin(i*H),G=10/r;function K(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 q(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:T,visibleFromDays:E}=r,D=p!==0&&r.applyFlagFilter,O=r.pickBase,A=d.length/3|0,j=i-w,oe=k(i),M=ce(i),N=0;for(let w=0;w<m&&!(N>=A);w++){let m=ee[w];if(m===0||E[w]>j||D&&(T[w]&p)!==p)continue;if(m===3){let e=C[w];if(!e){if(e=B({noradCatId:r.satnum[w],epochJd:re[w],meanMotion:b[w]/360,eccentricity:g[w],inclination:ne[w],raOfAscNode:_[w],argOfPericenter:v[w],meanAnomaly:y[w],bstar:r.bstar[w],meanMotionDot:r.ndot[w],meanMotionDdot:r.nddot[w],elementSetNo:0,revAtEpoch:0}),!e){ee[w]=0;continue}C[w]=e}let t=(i-e.jdsatepoch)*1440,n=ae(e,t);if(!n||e.error!==x.None)continue;let p=n.position.x*G,m=n.position.y*G,te=n.position.z*G,h=M[0]*p+M[1]*m+M[2]*te,ie=M[3]*p+M[4]*m+M[5]*te,S=M[6]*p+M[7]*m+M[8]*te,T=-ie;if(!K(d,N,a+h-c,o+S-l,s+T-u))continue;if(f){let e=O+w,t=N*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}N++;continue}let k,A,P=g[w],se=ne[w],F=_[w],I=v[w];if(m===2){let e=n(ie[w],S[w],te[w]?i:oe);if(!e)continue;k=e.r*Math.cos(e.nu),A=e.r*Math.sin(e.nu)}else{let n=h[w];if(!isFinite(n)||!isFinite(P)||!isFinite(y[w])||!isFinite(b[w]))continue;let r=(te[w]?i:oe)-re[w],a=(y[w]+b[w]*r)*H,o,s;if(P<1||n>0){let t=Math.min(P,.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,P);if(!isFinite(e))continue;let r=P*Math.cosh(e)-1;if(Math.abs(r)<1e-15)continue;let i=Math.sqrt(P*P-1)*Math.sinh(e)/r,c=(P-Math.cosh(e))/r;o=Math.atan2(i,c),s=n*(1-P*Math.cosh(e))}k=s*Math.cos(o),A=s*Math.sin(o)}if(!isFinite(k)||!isFinite(A))continue;let L=Math.cos(I*H),R=Math.sin(I*H),ce=Math.cos(se*H),z=Math.sin(se*H),V=Math.cos(F*H),q=Math.sin(F*H),J=(V*L-q*R*ce)*k+(-V*R-q*L*ce)*A,Y=(q*L+V*R*ce)*k+(-q*R+V*L*ce)*A,X=R*z*k+L*z*A;if(te[w]){let e=Y*U+X*W,t=-Y*W+X*U;Y=e,X=t}let le=J*10,ue=X*10,de=-Y*10;if(K(d,N,a+le-c,o+ue-l,s+de-u)){if(f){let e=O+w,t=N*4;f[t]=e&255,f[t+1]=e>>>8&255,f[t+2]=e>>>16&255,f[t+3]=e>>>24&255}N++}}return N}const J=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)J.delete(e);for(let e of t.set)J.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=J.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=q(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-D2PB8gf5.js.map",ZR=typeof self<`u`&&self.Blob&&new Blob([`URL.revokeObjectURL(import.meta.url);`,XR],{type:`text/javascript;charset=utf-8`});function QR(e){let t;try{if(t=ZR&&(self.URL||self.webkitURL).createObjectURL(ZR),!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(XR),{type:`module`,name:e?.name})}}var $R=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 QR;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 D_(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}]},k_(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()}},ez=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 Ah(n[e-t]);return null}clear(){this.#t.clear(),this.#e=1}},tz=.01,nz=[`asteroid`,`spacecraft`],rz=.0002959122082855911,iz=.75,az=Q(8*86400);function oz(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(rz/i*((1+o)/(1-o)));s>t&&(t=s)}return{maxSpeedScene:t*10,alwaysSolve:n}}function sz(e){return e<0?0:e>1?1:e}function cz(e,t){return t===`*`?e.startsWith(`small_bodies/`):e===t}function lz(e){return e===null?{tBright:0,tSize:0}:{tBright:sz((uz-e)/(uz-dz)),tSize:sz((fz-e)/(fz-pz))}}var uz=1e4,dz=500,fz=dz,pz=50,mz=4,hz=.5,gz=10,_z=1,vz=1,yz=3.5,bz=2.5,xz=2,Sz=yz,Cz=class{orbitPool=new $R;pickRegistry=new ez;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:mz,dim:hz,opacity:vz};emphasizedSmallBodyZone=null;smallBodyEmphasis={sizeMult:1,brightMult:1,opacity:vz};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 nz)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 nz)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)lv(e)===`naif-399`&&this.applyEarthSatEmphasis(t)}computeEarthSatEmphasis(e){let{tBright:t,tSize:n}=lz(e);return{size:mz+(gz-mz)*n,dim:hz+(_z-hz)*t,opacity:vz+(yz-vz)*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)cz(lv(e),n)&&this.resetSmallBodyEmphasis(t);if(e!==null)for(let[t,n]of this.workerPoints.asteroid)cz(lv(t),e)&&this.applySmallBodyEmphasis(n)}computeSmallBodyEmphasis(e){let{tBright:t,tSize:n}=lz(e);return{sizeMult:1+(bz-1)*n,brightMult:1+(xz-1)*t,opacity:vz+(Sz-vz)*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=vz,e.userData.smallBodyBaseSize=void 0,e.userData.smallBodyBaseColor=void 0}seedBasis(e){this.basisPos=[...e]}buildInitial(e){let t=mR(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 nz)for(let[t,n]of this.workerPoints[e]){let r=lv(t);n.userData.parentBodyId=this.cloudParentId(e,r),this.emphasiseNewCloud(e,r,n)}this.assignMapLayer()}assignMapLayer(){for(let e of nz)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`?$_:t}emphasiseNewCloud(e,t,n){if(e===`spacecraft`){t===`naif-399`&&this.applyEarthSatEmphasis(n);return}let r=this.emphasizedSmallBodyZone;r!==null&&cz(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=Mh(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,oz(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=WL(new Float32Array(l.cols.count*3),0,this.circleTexture,c,HL());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 cv(n,uy(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=>jh(e.data.id)??Th));await this.orbitPool.rewireOne(c,l,s,(o+r)%t,!1,u),this.armGroupGate(c,{maxSpeedScene:az,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=WL(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=lv(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(iv(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 Bo(new Float32Array(n),3)),e.getAttribute(`color`)){let r=new Float32Array(n);this.seedColors(r,t),e.setAttribute(`color`,new Bo(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 Bo(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 Bo(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 Bo(t.slice(),4,!0))}reposition(){let[e,t,n]=this.focus.focusTruePos,r=this.basisPos;for(let i of nz)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=tz*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($_)?.position;for(let[i,a]of this.workerPoints.asteroid){if(!r)break;if(!this.ctx.visibility.isAsteroidGroupVisible(lv(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(lv(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>=iz}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 Uo(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 nz)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()}},wz=Math.PI/180,Tz=2451545,Ez=1.00000261,Dz=.01671123,Oz=100.46457166*wz,kz=35999.37244981/36525*wz,Az=102.93768193*wz,jz=.32327364/36525*wz;function Mz(e){let t=e-Tz,n=Az+jz*t,r=Oz+kz*t-n,i=r+(2*Dz-Dz**3/4)*Math.sin(r)+1.25*Dz*Dz*Math.sin(2*r);return{lon:n+i,r:Ez*(1-Dz*Dz)/(1+Dz*Math.cos(i))}}function Nz(e){let t=Mz(e).lon;return(e,n)=>{let r=t-Mz(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 Pz=.01,Fz=1/100,Iz=1;function Lz(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 Rz(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 zz(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=Lz(c,l,u)}function Bz(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(Rz(o,g,u,d,f,p,m,h,a))return;let{posArr:_,trailArr:v,fullArr:y}=iR(t),b=e.lagrangeTrail?Nz(i):null,x=cR(e,n,_,c.x,c.y,c.z,r,b??void 0);aR(t,_,v,y,x,!0,s),zz(o,g,u,d,f,p,m,h,_,x,a)}function Vz(e,t,n,r,i){let{posArr:a,trailArr:o,fullArr:s,capacity:c}=iR(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){$L(e.geometry,a,o,s,l);return}e.geometry.getAttribute(`position`).needsUpdate=!0}function Hz(e,t,n,r,i){let a=t.userData.trailBuffer;if(a){Bz(e,t,a,n,r,i);return}let o=t.userData.sourceCurve;if(!o){if(!t.userData.curvePending||!e.orbitElements)return;o=XL(b_(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=JL(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*Fz,Iz)){let n=e.rederiveElements(r);n&&(Object.assign(e.orbitElements,n),o=XL(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)>Pz&&(o=XL(b_(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(Rz(h,o,g,_,v,y,b,x,i))return;let S=Mb(e,o,s,u,d,f,p);if(S.length<2)return;let{posArr:C,trailArr:w,fullArr:T,capacity:E}=iR(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;aR(t,C,w,T,A,s,c),h.trailLocalPositions=S,zz(h,o,g,_,v,y,b,x,C,A,i)}function Uz(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 Wz(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 Gz=4/2,Kz=(.1*10)**2,qz=new J,Jz=[],Yz=Jz;function Xz(e){return gO(Jz,e,xO)}var Zz={x:0,y:0,left:0,right:0,h:0},Qz=new Xi,$z={ox:0,oy:0},eB=new J,tB=new J;function nB(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=Tv(C,e),n.isCrashed||n.noPhysical){let e=n.noPhysical===`model`,t=xg(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()}fA(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),tB.set(o-w[0]+p.x,s-w[1]+p.y,c-w[2]+p.z).project(t),n.labelAnchorOffscreen=Math.abs(tB.x)>1||Math.abs(tB.y)>1;continue}if(n.semiAxesScene&&n.mesh)UR(l,u,d,BR(n.mesh.getWorldQuaternion(Qz),T,n.semiAxesScene),S,$z),p.set($z.ox,$z.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=Jz,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=Fj(t),n=t.model.position;for(let c of s){let s=c.r*e;if(eB.copy(c.center).applyQuaternion(t.model.quaternion).add(n).multiplyScalar(e),p.set(i-w[0]+eB.x,a-w[1]+eB.y,o-w[2]+eB.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)&&VR(Xz(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?HR(Xz(k++),c,l,u,BR(t.mesh.getWorldQuaternion(Qz),T,t.semiAxesScene),S,D,O,t.body.data.id,r):VR(Xz(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?mM(n.getBody(a),e):void 0;for(let r of e.values()){let{body:i,group:s,trail:c}=r,l=r.cachedDist,u=vO(r);r.root.visible=u;let d,f,p=i.data.id===a,m=A!==null&&i.data.id===A;if(r.mesh===null&&!Sn(i.data.objectType)){let t=i.data.objectType;if(t===G.BARYCENTER||t===G.LAGRANGE_POINT){let t=!0,r=p?void 0:bv(i.data.id);if(r){let a=e.get(r)?.body??n.getBody(r);a?.position&&i.position&&Tv(i.position,a.position)/Tv(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?Uz(t,o,p):Wz(t,n.visibility.hasFullRendering(i),p||m);s.visible=r.groupVisible,c&&(c.visible=r.orbitVisible),d=r.showLabel,f=r.isClose}u||(s.visible=!1,d=!1,f=!1),c&&(!u||i.orbitCenter===null)&&(c.visible=!1);let g=!1;if(r.starPoint&&u){let e=r.radiusScene/l*S/Gz;g=e<1,r.starPoint.visible=g,g&&(r.starPoint.material.uniforms.uFlux.value=e*e),cL(r.corona,e),s.visible=!0,f=!g,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(qz.set(w[0],w[1],w[2]))>Kz&&(c.visible=!1)}_&&c&&(c.visible=!1),s.matrixWorldAutoUpdate=s.visible;let{label:y}=r;if(!s.visible&&y&&y.parent===s?(s.remove(y),y.element.remove()):s.visible&&y&&y.parent!==s&&s.add(y),r.mesh&&r.radiusScene>0){let e=g||!p&&!m&&r.radiusScene/l*S<.5;e!==r.meshSubPixel&&(r.meshSubPixel=e,e?r.mesh.layers.disable(0):r.mesh.layers.enable(0))}EO(r,d,f,l,S,a)&&(j=!0);let T=r.radiusScene>0?r.radiusScene/l*S:0;IM(r,v&&i.data.id===M,T,t,b,x)}for(let[e,t]of c)t.visible=n.visibility.isAsteroidGroupVisible(lv(e));for(let[e,t]of l)t.visible=n.visibility.isSpacecraftGroupVisible(lv(e));for(let[e,t]of u)t.visible=n.visibility.isMoonGroupVisible(e);if(E.length>0){let n=a?bv(a):null;for(let r of e.values()){if(!r.label?.visible||!kO(r,t,w,b,x,Zz))continue;let e=r.body.data.id;DO(Zz.x,Zz.y,r.cachedDist,e,E,e===a?n:null)&&(r.label.visible=!1)}}if((m||j||++d>=3)&&(d=0,HO(e,b,x,t,a,n,s,E,r)),UO(e,b,x,t,r),M){let t=e.get(M);t&&BM(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 rB(e,t){return[e[0]+t[0],e[1]+t[1],e[2]+t[2]]}function iB(e,t){return[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}function aB(e,t){return[e[0]*t,e[1]*t,e[2]*t]}function oB(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 sB(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-cB(d):p,g=f?m+cB(f):m;if(t<h||t>g)return null;if(a&&d&&t<(c?.jds[0]??n.startJd))return{r:lB(d,t),centerId:a.anchorId};if(c&&t<=c.jds[c.jds.length-1])return{r:uB(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:lB(f,t),centerId:o.anchorId};if(l)return{r:uB(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}=oB(e,v);return{r:uB(y,b,t,x,S),centerId:e.centerId}}function cB(e){return e.jds[e.jds.length-1]-e.jds[0]}function lB(e,t){let n=cB(e),r=e.jds[0],i=n>0?r+((t-r)%n+n)%n:t;return uB(e.points,e.jds,i)}function uB(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 rB(e[a-1],aB(iB(e[a],e[a-1]),s))}var dB=Math.PI/180,fB=Math.cos(vg*dB),pB=Math.sin(vg*dB);function mB(e,t,n,r){let i=Math.cos(e*dB),a=Math.sin(e*dB),o=Math.cos(t*dB),s=Math.sin(t*dB),c=Math.cos(n*dB),l=Math.sin(n*dB);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 hB(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*fB+a*pB,t=-i*pB+a*fB;i=e,a=t}return[r,i,a]}function gB(e){let t=10/_g;return[e[0]*t,e[2]*t,-e[1]*t]}function _B(e,t,n){let{a:r,e:i,ma:a,n:o,epoch:s,q:c,tp:l}=e,u=v_(e,t),{om:d,w:f}=b_(e,t),p=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 t=u_(c,l,u);if(!t)return null;let r=n&&n>0?n:Bv,i=t.r*_g,a=2*c*_g;return vB(i,t.nu,a,1,r,f,e.i,d,p)}if(!isFinite(i)||!isFinite(a))return null;let m=r*_g,h=o*dB/Vv,g=n&&n>0?n:h*h*Math.abs(m)*Math.abs(m)*Math.abs(m);if(!isFinite(g)||g<=0)return null;let _=(a+o*(u-s))*dB,v,y;if(i<1||r>0){let e=Math.min(i,.9999999),t=s_(_,e),n=1-e*Math.cos(t);v=Math.atan2(Math.sqrt(1-e*e)*Math.sin(t),Math.cos(t)-e),y=m*n}else{let e=l_(_,i);if(!isFinite(e))return null;let t=i*Math.cosh(e)-1;if(Math.abs(t)<1e-15)return null;v=Math.atan2(Math.sqrt(i*i-1)*Math.sinh(e)/t,(i-Math.cosh(e))/t),y=m*(1-i*Math.cosh(e))}if(!isFinite(y)||y<=0)return null;let b=m*(1-i*i);return!isFinite(b)||b<=0?null:vB(y,v,b,i,g,f,e.i,d,p)}function vB(e,t,n,r,i,a,o,s,c){let l=Math.cos(t),u=Math.sin(t),d=Math.sqrt(i/n),f=mB(a,o,s,c),p=hB(e*l,e*u,f),m=hB(-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 yB={cruise:`#7fdbff`,boost:`#ffb454`,brake:`#ff8c69`,spiral:`#c9a0ff`,"spiral-out":`#9b7fd4`,"spiral-in":`#9b7fd4`};yB.cruise,yB.boost,yB.brake,yB.spiral,yB[`spiral-out`],yB[`spiral-in`];var bB={notice:`#8ab4f8`,caution:`#f2b23e`,severe:`#ff6b5a`},xB=3,SB=1,CB=2,wB=.6,TB=1.5,EB=.3,DB=1.5,OB=.85,kB=60,AB=.018,jB=.026,MB=`#ffffff`,NB=4,PB=1.5,FB=9,IB=1,LB={notice:NB-3,caution:NB-2,severe:NB-1},RB=[`notice`,`caution`,`severe`],zB=.03,BB=.2;function VB(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 Kc(t)}function HB(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 Kc(t)}function UB(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 WB(e,t){let n=new xs(new ss({map:e,transparent:!0,sizeAttenuation:!1,depthTest:!1}));return n.scale.setScalar(t),n.renderOrder=NB,n}function GB(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&&(FT(c,i),pM(c,o)),s&&(c.addEventListener(`mouseenter`,()=>s(!0)),c.addEventListener(`mouseleave`,()=>s(!1)));let p=new DT(c);return p.center.set(0,.5),p}function KB(e,t){return e&&[e[0]-t[0],e[1]-t[1],e[2]-t[2]]}var qB=class{group=new qa;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?TB:CB,i?EB:wB,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)=>RB.indexOf(e.severity)-RB.indexOf(t.severity));for(let t of n){let n=bB[t.severity];for(let n of t.bands)e.arcs.forEach((t,r)=>{this.addLine(UB(t,n.startJd,n.endJd,oB(e,r)),bB[n.severity],FB,IB,null,{renderOrder:LB[n.severity]})});if(this.mergeIntoStep(t,n))continue;let r=sB(e,t.startJd);if(!r)continue;let i=gB(r.r),a=r.centerId===e.centerId?null:r.centerId,o=WB(HB(n),zB);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 DT(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,xB,SB,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:WB(VB(MB),jB),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=sB(e,n.jd);if(!t)continue;let r=gB(t.r),i=t.centerId===e.centerId?null:t.centerId,a=WB(VB(MB),AB);this.markers.push({sprite:a,local:r,anchorId:i});let o=GB(`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:gB(n.meeting.r),end:e.arrival,color:yB[a?.kind??`cruise`]}];o&&s.push({local:gB(o.r),end:e.departure,color:yB[i?.kind??`cruise`]});for(let{local:n,end:i,color:a}of s){if(!i.name)continue;let o=GB(`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?SB:e.brightness),n.uniforms.uLineWidth.value=t?xB: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?oB(e,s):{from:0,to:a.points.length};this.addLine(a.points.slice(c,l),yB[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),yB.cruise,xB,SB,null,{anchorId:n}),this.addLine(t.approach.slice(i.from,i.to),yB.cruise,xB,SB,null,{anchorId:n,renderOrder:PB}),e=i.to;e<t.approach.length&&this.addLine(t.approach.slice(Math.max(0,e-1)),yB.cruise,xB,SB,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,yB.cruise,xB,SB,null,{anchorId:n});this.addLine(t.approach.slice(e>0?e-1:0,r),yB.cruise,DB,OB,null,{anchorId:n})}else this.addLine(t.approach,yB.cruise,xB,SB,null,{anchorId:n});let i=this.addLine(t.points,yB.cruise,DB,OB,null,{anchorId:n});if(!i)continue;let a=n===null?gB(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]=gB(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*BB));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=rR(o,c,l,l,o,t,n,r);d.frustumCulled=!1,d.renderOrder=a.renderOrder??NB,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=sB(this.path,e);t.sprite.visible=n!==null,n&&(t.local=gB(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,KB(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;$L(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):KB(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*kB}}}setVisible(e){this.group.visible=e}reserveLabelSpace(e,t,n){if(!this.group.visible||this.labels.length===0){BO(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),!bw(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=DO(a,o,s,``,Yz);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++}BO(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 qa,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)}},JB=2,YB=1,XB=4,ZB=200,QB=class{group=new qa;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,ZB);for(let t=0;t<e.count;t++){let[r,i,a]=gB(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(ZB*3),t=new Float32Array(ZB).fill(1),n=rR(ZB,e,t,t,0,yB.cruise,JB,YB);n.frustumCulled=!1,n.renderOrder=XB,this.layer!==null&&n.layers.set(this.layer),this.group.add(n),this.slots.push({line:n,bodyId:``,local:new Float64Array(ZB*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;$L(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)}},$B=new Set([`not-yet`,`no-data`,`parent`,`failed`]);function eV(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&&$B.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){nV(i.focusTargetWorld,n);let e=i.camTargetOffset;e&&i.camTargetWorld&&rV(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){nV(i.focusTargetWorld,f);let e=i.camTargetOffset;e&&i.camTargetWorld&&rV(i.camTargetWorld,f,e);let t=i.camOriginOffset;t&&i.camOriginWorld&&rV(i.camOriginWorld,f,t),h||nV(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}Hz(e.body,n,g,t,s),n.userData.refreshDeferred=!1}}let _=!f&&p===`loading`;return{focusUnplaced:a!==void 0&&!f&&!_,focusLoading:_,anchorId:m}}function tV(e,t,n,r){let i=t.focusTruePos;for(let t of e.values()){let e=t.trail;!e||!e.visible||!e.userData.refreshDeferred||(Hz(t.body,e,i,n,r),e.userData.refreshDeferred=!1)}}function nV(e,t){e[0]=t[0],e[1]=t[1],e[2]=t[2]}function rV(e,t,n){e[0]=t[0]+n[0],e[1]=t[1]+n[1],e[2]=t[2]+n[2]}var iV=Object.freeze([0,0,0]);function aV(e,t,n,r){if(!Number.isFinite(t+n+r))return oV(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 oV(e,t){let n=e;return n.position=null,n.orbitCenter=n.orbitCenterId===void 0?void 0:null,n.unplaced=t,null}function sV(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 cV(e,t){let n=e.trailAnchor??=[0,0,0];n[0]=t[0],n[1]=t[1],n[2]=t[2]}var lV=Math.PI/180,uV=120,dV=Q(.001)**2,fV=new WeakMap,pV=new J,mV=new J;function hV(e,t,n){e.distanceToSquared(t)<=dV?e.copy(t):e.lerp(t,n)}function gV(e,t,n,r,i){let a=e.featureAnchor;sV(e,n),mV.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?(pV.copy(s.position),mV.copy(e.position)):(pV.copy(s.position),r?.mesh&&pV.multiply(r.mesh.scale))}else{let e=t.data.radiusKm,n=a.lat*lV,i=a.lon*lV,o=t.orientation&&Number.isFinite(e)&&e>0?mO(r,t.data.id,e,n,i):null;if(o)pV.set(o.pointKm[0],o.pointKm[1],o.pointKm[2]);else{let t=Number.isFinite(e)&&e>0?e:0,[r,a,o]=qD(n,i);pV.set(t*r,t*a,t*o)}pV.multiplyScalar(Q(1))}let c=performance.now(),l=fV.get(e);if(!l)l={fixed:pV.clone(),addend:mV.clone(),t:c},fV.set(e,l);else{let e=1-Math.exp(-(c-l.t)/uV);l.t=c,hV(l.fixed,pV,e),hV(l.addend,mV,e)}return pV.copy(l.fixed),t.orientation&&pV.applyQuaternion(xS(t.orientation,i,t.nutPrec)),aV(e,n[0]+pV.x+l.addend.x,n[1]+pV.y+l.addend.y,n[2]+pV.z+l.addend.z)}var _V=30034e-10,vV=.45,yV=1.6,bV=.85,xV=(e,t)=>e[0]*t[0]+e[1]*t[1]+e[2]*t[2],SV=e=>Math.hypot(e[0],e[1],e[2]);function CV(e,t,n=_V){let r=SV(t);if(!(r>0))return null;let i=r*Math.cbrt(n/3),a=xV(e,t)/r,o=SV(e);if(Math.sqrt(Math.max(0,o*o-a*a))>bV*i)return null;let s=a/i;return s>=vV&&s<=yV?`EL1`:s<=-vV&&s>=-yV?`EL2`:null}function wV(e,t){return!(e.visibleFromDays!==void 0&&t-2451545<e.visibleFromDays)}function TV(e,t){let n=v_(e,t);return n>=e.validityStart&&n<=e.validityEnd}function EV(e){return e.a===0&&(e.objectType===G.BARYCENTER||e.objectType===G.LAGRANGE_POINT||Sn(e.objectType))}function DV(e,t){if(e.pageOnly)return`never`;if(!wV(e,t))return`not-yet`;if(!TV(e,t))return`no-data`;let n,r=e.satrec;return n=r?o_(r,t):e.omm?null:e.q==null?e.a===0?EV(e)?[0,0,0]:null:S_(e,t):C_(e,t),!n||!Number.isFinite(n[0]+n[1]+n[2])?`failed`:n}function OV(){return{count:0,earliestStart:1/0,latestEnd:-1/0}}var kV=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`?kg(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})}}},AV=new Map,jV=new J;function MV(e,t,n,r,i,a,o){let s=cb(n,r,ob(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=mO(o.get(c),c,d,p,m);h&&AV.set(e.id,h);let g=h??AV.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=xS(l.orientation,r,l.nutPrec),x=new J(_,v,y).applyQuaternion(b),S=g?jV.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 NV=[0,0,0],PV=new Xi,FV=4,IV=0,LV=new Map;function RV(e){return e.primary.target===`velocity`||e.secondary?.target===`velocity`}function zV(e,t,n){let r=LV.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 LV.set(e,{jd:t,pos:[n[0],n[1],n[2]],dir:i}),i??void 0}var BV=class{focusedId;noData=OV();passJd=NaN;frame;settled=new Set;settling=new Set;ride=rS([],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=OV()}at(e,t){if(e===`naif-0`)return iV;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||!Sn(t.objectType))&&(n.staggerSlot??=IV++%FV,this.frame%FV!==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=mn(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?oV(e,this.under(n)):gV(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=rS(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=DV(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 oV(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`),oV(e,t)}r.clear(`missing-parent`,i.id);let s;return s=n.chebStore?.has(i.id)?wV(i,t)?n.chebStore.positionScene(i.id,t)??this.rowOffset(e,o,t)??this.chebMiss(i.id,t):`not-yet`:DV(i,t),typeof s==`string`?oV(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.isAwaited(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=aV(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&&sV(e,l===s.parentId?a:this.at(l,o)),e.trailAnchorId!==void 0){let t=this.at(e.trailAnchorId,o);t&&cV(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&&SS(t.mesh,e.orientation,o,e.nutPrec),t.model&&SS(t.model,e.orientation,o,e.nutPrec),t.nomenclatureAnchor&&SS(t.nomenclatureAnchor,e.orientation,o,e.nutPrec);else if(Dj(e)){let n=e.attitudeTrack;if(!e.pointingOverride&&n&&n.orientationAt(o,PV))t.mesh&&t.mesh.quaternion.copy(PV),t.model&&t.model.quaternion.copy(PV);else{let n=e.pointingOverride??e.pointing;if(n){let e=RV(n)?zV(s.id,o,c):void 0,r={bodyPos:c,parentPos:a,sunPos:this.at(`naif-10`,o)??void 0,velocity:e};t.mesh&&BS(t.mesh,n,r),t.model&&BS(t.model,n,r)}else t.mesh&&TS(t.mesh,c,a),t.model&&TS(t.model,c,a)}}if(e.orientation)for(let n of t.rings)SS(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);fA(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?.awaitedAt(n)?oV(e,`loading`):(oV(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&&sb(d.probe,n)){let i=s.parentId,c=MV(s,d.probe,f,n,e=>this.at(e,n),r,a);if(!c)return oV(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||=(GN(t.labelHalo,`landed`),!0),t.isCrashed=e,t.model&&(t.model.visible=!e)}let l=aV(e,c.x,c.y,c.z);if(!l)return null;e.orbitCenterId=s.parentId,sV(e,c.parentPos);let u=c.up;return t?.mesh&&(u?ES(t.mesh,u):TS(t.mesh,l,c.parentPos)),t?.model&&(u?ES(t.model,u):TS(t.model,l,c.parentPos)),l}let p=vb(d.probe,n,d.fitCenterNaifId,r.chebStore??null,e=>this.at(e,n)!==null);if(!p){let t=d.probe.fitCenter?.id;return oV(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=ib(d.probe,n,h);if(!g)return oV(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&&(GN(t.labelHalo,`flying`),t.isLanded=!1,t.isCrashed&&(t.isCrashed=!1,t.model&&(t.model.visible=!0),t.noPhysical||fA(t,`missing`,null)));let _=this.at(ev,n),v=this.at($_,n),y=m===`naif-399`&&_!==null&&v!==null&&CV([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=Sb(hb(d.probe,n,h),s.validityEnd-s.validityStart,t.capacity,y);t.reconfigure(i.stepDays,i.epsilonScene,i.spanDays),Ob(t,r.probeStore,r.chebStore??null,s.id,m,n)}x&&(s.parentId=m);let S=this.at(m,n);if(!S)return oV(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(),Ob(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=Sb(hb(d.probe,n,h),s.validityEnd-s.validityStart,A.capacity,y);A.reconfigure(e.stepDays,e.epsilonScene,e.spanDays),Ob(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(NV)&&Ab(A,wb(r.probeStore,r.chebStore??null,s.id,m),e,[NV[0],NV[1],NV[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)}},VV=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)}},HV=[],UV=new WeakMap;function WV(e,t){let{color:n,geometricAlbedo:r}=e.body.data,i=UV.get(e);return(!i||i.color!==n||i.geometricAlbedo!==r||i.map!==t)&&(i={color:n,geometricAlbedo:r,map:t,albedo:WA(e.body.data,t,new X)},UV.set(e,i)),i.albedo}function GV(e,t,n){let r=WV(e,t.map);if(r)return n.copy(r);n.copy(t.color);let i=t.map&&_A(t.map);return i?n.multiply(i):n}function KV(e,t,n,r){let i=e.get($_)?.body.position,a=0;if(i)for(let e of t){if(!e.mesh)continue;let t=e.mesh.material,[o,s,c]=e.body.position,l=i[0]-o,u=i[1]-s,d=i[2]-c,f=Math.hypot(l,u,d),p=HV[a++]??={x:0,y:0,z:0,radius:0,sunX:0,sunY:0,sunZ:0,sunlight:0,albedo:new X};p.x=o,p.y=s,p.z=c,p.radius=e.radiusScene,p.sunX=l/f,p.sunY=u/f,p.sunZ=d/f,p.sunlight=KS*r*(n?JS(f):1),GV(e,t,p.albedo)}for(let t of e.values()){let e=t.planetshine,n=t.body.position;!e||!n||t.cachedDist>0&&t.radiusScene<t.cachedDist*1e-4||wT(e,n[0],n[1],n[2],HV,a)}}var qV=Q(695700),JV=2,YV=1e-4,XV=2,ZV=new J,QV=new J,$V=new J,eH=new Xi;function tH(e,t,n,r,i){ZV.subVectors(e,t);let a=ZV.dot(n),o=Math.sqrt(Math.max(ZV.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 nH(e,t,n,r,i,a){let o=e.get($_)?.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(),_=qV/g;e.material.uniforms.uSunAngularRadius.value=_,e.material.uniforms.uLightScale.value=n?JS(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}=tH(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*JV),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))}rH(t,i,a)}}function rH(e,t,n){let r=e.rings.reduce((e,t)=>t.intensityScale>e.intensityScale?t:e),i=r.material.uniforms,a=i.uSunDir.value,o=r.planetShadowOnRing.uPlanetPoleDir.value,s=r.planetShadowOnRing.uPlanetCenter.value,c=Math.min(Math.max(a.dot(o),-1),1),l=r.light,u=r.outerScene/Math.max(t.distanceTo(s),1e-12)*n>=XV;u&&!(Math.abs(c-l.patchesSinB)<YV)&&(vC(l.patches,l.profile,c,l.planet),l.patchesSinB=c),QV.copy(a).addScaledVector(o,-c),QV.lengthSq()<1e-12&&QV.set(+(Math.abs(o.x)<.9),Math.abs(o.x)<.9?0:1,0).cross(o),QV.normalize(),r.ringshine&&AC(r.ringshine,l,QV,c,i.uLightScale.value),$V.copy(QV).applyQuaternion(eH.copy(r.mesh.quaternion).invert());for(let t of e.rings){if(!t.mesh.visible)continue;u&&t.light.planetLightSinB!==l.patchesSinB&&TC(t.light,l.patchesSinB,l);let n=t.material.uniforms;n.uSunAzimuth.value.set($V.x,$V.z).normalize();let r=n.uPlanetAlbedo.value;e.mesh?GV(e,e.mesh.material,r):r.setRGB(0,0,0)}}var iH=Math.PI/180,aH=2451545;function oH(e){let t=e-aH,n=(19.3871+.52402073*t)*iH;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 sH(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 cH(e,t){let n=e.seasonal;if(!n)return e;let r=sH(n.lsDeg,n.dustTauFactor,t),i=sH(n.lsDeg,n.dustScaleHeightKm,t),a=sH(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 lH=new WeakMap,uH=.25;function dH(e,t){if(!e.seasonal)return e;let n=Math.round(oH(t)/uH),r=lH.get(e);if(r&&r.lsQ===n)return r.params;let i=cH(e,n*uH);return lH.set(e,{lsQ:n,params:i}),i}var fH=new J,pH=new J,mH=[.2126,.7152,.0722];function hH(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=CN(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+=mH[t]*Math.exp(-n)}return o}var gH=.4,_H=.05,vH=-.105,yH=.3,bH=.05;function xH(e,t,n){let r=hH(e,t),i=Math.min(1,-Math.log(Math.max(r,.001))/bH),a=Math.min(1,Math.max(0,(n-vH)/yH));return r*(1+(gH+(_H-gH)*a-1)*i)}function SH(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 CH=KS,wH=200,TH=new J,EH=new J,DH=new J,OH=new J;function kH(e,t,n,r){e.uOccluderCount.value=Lw(e.uOccluders.value,t,r,n)}function AH(e,t,n,r,i,a,o){let s={insideShell:!1,shellProminent:!1,skyboxIntensity:1,sunTint:TH.set(1,1,1),sunRefraction:null};hN(n&&a.sunTint);let c=e.get($_);uL(c?.mesh?.material,Yb());let l=lL(c?.mesh?.material);l&&(l.uAtmoTEnable.value=0);let u=wH,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;uT(c.atmosphere,a);let f=Jb(c.body.data.id);if(f?.seasonal){let e=a.seasonal?dH(f,o):f;if(c.atmosphere.params!==e){dT(c.atmosphere,e);for(let t of c.sunTint??[])SN(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?JS(_.length()):v.realisticSunAlways?Math.sqrt(JS(_.length())):1;g.uSunIntensity.value=v.sunIntensity*y*i,_.normalize(),c.mesh&&(fH.set(0,1,0).applyQuaternion(c.mesh.quaternion),g.uSpinAxis.value.copy(fH));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&&kH(g,b,_,x);let C=a.insideView&&S<x,w=c.atmosphere.planetRadiusKm,T=S*((w+v.topAltitudeKm)/x)-w,E=C&&sT(v,T),D=C?cT(v,T):0;iT(c.atmosphere,C,E,D),g.uDeepIrradiance.value=CH*i;for(let e of c.sunTint??[])e.uAtmoTDeepIrradiance.value=CH*i,e.uAtmoTDeepBlend.value=D;if(C){s.insideShell=!0;let e=pH.copy(t).sub(b).divideScalar(S).dot(_),n=xH(v,T,e);if(s.skyboxIntensity*=n*(1-D),a.refraction&&v.refractivity&&!E){let t=SH(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:OH.copy(pH)})}}let O=S/x;if(a.sunTint&&O<wH){let e=x/(1+v.topAltitudeKm/w)*(c.atmosphere.surfaceRadiusKm/w);DH.copy(t).sub(b);let n=g.uSpinAxis.value,r=g.uStretch.value;if(FN(v,DH,_,e,c.atmosphere.surfaceRadiusKm,EH,n,r)){let e=mH[0]*EH.x+mH[1]*EH.y+mH[2]*EH.z;e>1e-4&&s.sunTint.multiply(EH.divideScalar(e))}l&&O<u&&(u=O,AN(l,v,b,e,c.atmosphere.surfaceRadiusKm,n,r))}}return s}var jH=new J;function MH(e,t){let n=0;for(let r of e.values()){if(r.body.data.objectType===G.STAR)continue;let e=r.body.data.radiusKm;!Number.isFinite(e)||e<=0||r.radiusScene<=0||!vO(r)||(t[n++]=r)}return t.length=n,t}function NH(e,t,n,r,i){let a=Mw(),o=kw(),s=e.get($_),c=s?.body.position;if(!s||!c){a.uSunAngularRadius.value=0,a.uOccluderCount.value=0,o.count=0;return}let[l,u,d]=n,f=c[0]-l,p=c[1]-u,m=c[2]-d,h=Math.hypot(f,p,m);h>0?(a.uSunDir.value.set(f/h,p/h,m/h),a.uSunAngularRadius.value=Math.asin(Math.min(s.radiusScene/h,1))):a.uSunAngularRadius.value=0;let g=t.length;for(;o.occluders.length<g;)o.occluders.push(new ha),o.leaks.push(new ha);for(let e=0;e<g;e++){let n=t[e],[r,a,s]=n.body.position;o.occluders[e].set(r-l,a-u,s-d,n.radiusScene),i&&n.atmosphere?Bw(n.atmosphere.params,n.atmosphere.planetRadiusKm,o.leaks[e]):o.leaks[e].set(0,0,0,0)}o.count=g;let _=a.uSunDir.value;a.uOccluderCount.value=Lw(a.uOccluders.value,jH,r,_,a.uOccluderLeak.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,a]=n,o=e.uEclipseSelfPos.value.set(r-l,i-u,a-d);e.uOccluderCount.value=Lw(e.uOccluders.value,o,t.radiusScene,_,e.uOccluderLeak.value)}}var PH=10;function FH(e,t,n,r,i,a,o,s,c){let l=n.visibility.activeSystemId;if(!l){r.intensity=0,i&&YS(i,s,c);return}let u=e.get($_)?.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(PH),r.target.position.set(0,0,0),r.intensity=KS*(s?JS(_):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=PH-b,x.far=PH+b,x.updateProjectionMatrix()}var IH=1.25,LH=.05,RH=2048;function zH(e,t,n){let r=(e,t)=>!!e&&e.intervals.some(([e,n])=>t>e+1e-9&&t<n-1e-9),i=[],a=Math.round(e/n);for(let o=0;o<=a;o++){let s=o===a?e:o*n;(o===0||o===a||!r(t[t.length-1],s))&&i.push({p:s,level:0})}t.forEach((n,a)=>{for(let[o,s]of n.intervals){let c=Math.ceil(Math.max(o,0)/n.step-1e-9),l=Math.floor(Math.min(s,e)/n.step+1e-9);for(let e=c;e<=l;e++){let o=e*n.step;r(t[a-1],o)||i.push({p:o,level:n.level})}}}),i.sort((e,t)=>e.p-t.p||t.level-e.level);let o=(t[0]?.step??n)*.25,s=[];for(let e of i){let t=s[s.length-1];t&&e.p-t.p<o?t.level=Math.max(t.level,e.level):s.push(e)}return s[0].p=0,s[s.length-1].p=e,{at:Float64Array.from(s,e=>e.p),level:Int8Array.from(s,e=>e.level)}}function BH(e,t){let n=2*Math.PI;if(t>=Math.PI)return[[0,n]];let r=e-t,i=e+t;return r<0?[[0,i],[r+n,n]]:i>n?[[0,i-n],[r,n]]:[[r,i]]}function VH(e){return 2*Math.PI/(RH*2**e)}function HH(e,t,n,r){let i=VH(t),a=Math.log2(Math.max(e/n,i)/i);return r!==void 0&&a>r-.85&&a<r+.15?r:Math.max(0,Math.ceil(a-1e-9))}function UH(e,t,n,r,i,a,o){let s=VH(i),c=Math.PI/128,l=2*Math.PI/128,u=e=>Math.acos(1/(1+Math.max(e,0))),d=IH*(u(n)+u(r)),f=Math.max(Math.sin(e),LH),p=Math.round(Math.log2(1/f)),m=[],h=[],g=0;for(let n=o;g<d;n++){let r=s*2**n;if(r>=c)break;g+=a*r;let o=Math.max(i-n,0);m.push({intervals:[[Math.max(e-g,0),Math.min(e+g,Math.PI)]],step:r,level:o});let u=Math.min(g/f,Math.PI),d=Math.ceil(Math.log2(2*u/(4*a)/s)-1e-9),_=Math.max(n+p,d),v=s*2**_;v>=l||h.push({intervals:BH(t,u),step:v,level:Math.max(i-(_-p),0)})}return{rows:zH(Math.PI,m,c),columns:zH(2*Math.PI,h,l),stepLevel:o,innerRadius:a*s*2**o}}function WH(e,t,n,r,i=1){let a=t.length,o=n.length,s=new Float32Array(a*o*3),c=new Float32Array(a*o*3),l=new Float32Array(a*o*2),u=Float64Array.from(n,Math.sin),d=Float64Array.from(n,Math.cos);for(let f=0;f<a;f++){let a=t[f],p=Math.sin(a),m=Math.cos(a);for(let t=0;t<o;t++){let h=f*o+t,g=-d[t]*p,_=m,v=u[t]*p,y=e+(r?r[h]*i:0),b=h*3;s[b]=y*g,s[b+1]=y*_,s[b+2]=y*v,c[b]=g,c[b+1]=_,c[b+2]=v;let x=h*2;l[x]=n[t]/(2*Math.PI),l[x+1]=1-a/Math.PI}}let f=new Uint32Array((a-1)*(o-1)*6),p=0;for(let e=0;e<a-1;e++){let n=t[e]<=0,r=t[e+1]>=Math.PI;for(let t=0;t<o-1;t++){let i=e*o+t+1,a=e*o+t,s=(e+1)*o+t,c=(e+1)*o+t+1;n||(f[p++]=i,f[p++]=a,f[p++]=c),r||(f[p++]=a,f[p++]=s,f[p++]=c)}}return{positions:s,normals:c,uvs:l,indices:f.subarray(0,p)}}var GH=256,KH=.25,qH=.32,JH=.35,YH=300,XH=4e5,ZH=16,QH=8,$H=new Y,eU=new J;function tU(e,t,n){let r=e=>t.some(([t,n])=>e>t+1e-9&&e<n-1e-9),i=e/128,a=[];for(let t=0;t<=128;t++){let n=t===128?e:t*i;(t===0||t===128||!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 nU(e){let t=new ts;return t.setAttribute(`position`,new Bo(e.positions,3)),t.setAttribute(`normal`,new Bo(e.normals,3)),t.setAttribute(`uv`,new Bo(e.uvs,2)),t.setIndex(new Bo(e.indices,1)),t}var rU=new WeakMap,iU=new WeakSet;function aU(e){return!rU.get(e)?.abort&&!iU.has(e)}var oU=2;function sU(e){let t=e.displacementMeta?.tiles;return pD(t)&&!rU.get(e)?.dead?t:void 0}function cU(e,t,n,r){let i=pE(e.max_level,e.patches,n/(2*Math.PI),t/Math.PI);if(i===e.max_level)return i;let a=2**(Math.floor(Math.log2(r))-23),o=2*Math.PI*r/(QH*a);return Math.max(e.max_level,Math.min(i,Math.floor(Math.log2(o/RH))))}function lU(e){!e.mesh||!e.displacementMeta||jD(e.mesh.material,e.displacementMeta,e.radiusScene)}function uU(e){let t=rU.get(e);t?.abort?.abort(),t&&(t.abort=void 0),e.terrainWindow&&(e.terrainWindow.riseKm&&lU(e),e.terrainWindow=null,e.currentSegments=void 0)}function dU(e,t,n,r){let i=Math.sin(e)*Math.sin(n)*Math.cos(t-r)+Math.cos(e)*Math.cos(n);return Math.acos(Math.min(1,Math.max(-1,i)))}function fU(e,t,n,r,i,a,o){let s=e.terrainWindow?.riseKm?e.terrainWindow:void 0,c=t.material;s&&(c.displacementScale=0,c.displacementBias=0);let l=rU.get(e)??{failures:0,dead:!1};if(rU.set(e,l),l.abort)return!!s;let u=e.displacementMeta;if(!u)return!!s;let d=bn(e.body.data),f=cU(n,i,a,Q(d)),p=RH*2**f,m=SE().terrainBandCells,h=f>n.max_level?Math.min(m,ZH):m,g=s?.texWidth===p?s.stepLevel:void 0,_=HH(r,f,h,g);if(s){let t=dU(i,a,s.centerTheta,s.centerPhi);if(g===_&&t<JH*s.angRadius)return!0;if(performance.now()-s.builtAt<YH)return iU.add(e),!0}let v=UH(i,a,r,.5*u.scale_km/d,f,h,_),y=v.rows.at,b=v.columns.at;if(y.length*b.length>XH)return console.warn(`terrain grid for ${e.body.data.id} would need ${y.length}×${b.length} vertices: left to the shader`),l.dead=!0,!!s;let x=new AbortController;l.abort=x;let S=performance.now();return qT({root:qt(n),version:n.version,maxLevel:n.max_level,patches:(n.patches??[]).map(({max_level:e,x:t,y:n,version:r})=>({max_level:e,x:t,y:n,version:r})),tileSize:n.tile_size,scaleKm:n.scale_km??0,biasKm:(n.bias_km??0)-(u.absolute_radius?d:0),radius:Q(d),unitsPerKm:Q(1),rows:v.rows,columns:v.columns},x.signal).then(n=>{if(l.abort!==x||(l.abort=void 0,l.failures=0,e.mesh!==t||!e.displacementMap))return;let r=t.geometry;t.geometry=nU(n),r.dispose(),c.displacementScale=0,c.displacementBias=0,e.terrainWindow={thetas:y,phis:b,centerTheta:i,centerPhi:a,angRadius:v.innerRadius,stepLevel:_,texWidth:p,builtAt:performance.now(),riseKm:n.riseKm},e.currentSegments=128,console.debug(`terrain grid ${e.body.data.id}: ${y.length}×${b.length}, level ${_}, ${Math.round(performance.now()-S)} ms`),o()}).catch(()=>{l.abort===x&&(l.abort=void 0,++l.failures>=oU&&(l.dead=!0))}),!!s}function pU(e,t,n,r){iU.delete(e);let i=e.mesh,a=e.displacementMap;if(!n||!i||!a)return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: eligible=${n} mesh=${!!i} tex=${!!a}`),uU(e),!1;i.updateMatrixWorld(),$H.copy(i.matrixWorld).invert(),eU.copy(t.position).applyMatrix4($H);let o=Q(bn(e.body.data)),s=eU.length(),c=Math.max(s/o-1,1e-6);if(c>(e.terrainWindow?qH:KH))return e.terrainWindow&&console.debug(`terrain window exit ${e.body.data.id}: alt=${c.toFixed(4)}`),uU(e),!1;let l=Math.acos(Math.min(1,Math.max(-1,eU.y/s))),u=Math.atan2(eU.z,-eU.x);u<0&&(u+=2*Math.PI);let d=sU(e);if(d)return fU(e,i,d,c,l,u,r);e.terrainWindow?.riseKm&&lU(e);let f=a.image?.width??2048,p=2*Math.PI/f,m=Math.acos(1/(1+c)),h=Math.max(p,2*m*IH/GH),g=Math.log2(h/p),_=Math.max(0,Math.ceil(g-1e-9)),v=e.terrainWindow;v&&v.texWidth===f&&g>v.stepLevel-.85&&g<v.stepLevel+.15&&(_=v.stepLevel);let y=p*2**_,b=y*GH/2;if(v&&v.texWidth===f){if(v.stepLevel===_&&dU(l,u,v.centerTheta,v.centerPhi)<JH*v.angRadius)return!0;if(performance.now()-v.builtAt<YH)return iU.add(e),!0}let x=Math.max(0,l-b),S=Math.min(Math.PI,l+b),C=tU(Math.PI,[[x,S]],y),w=Math.min(Math.PI,b/Math.max(Math.sin(l),LH)),T=Math.max(_,Math.ceil(Math.log2(2*w/GH/p)-1e-9)),E=p*2**Math.max(0,T),D=u-w,O=u+w,k=w>=Math.PI?[[0,2*Math.PI]]:D<0?[[0,O],[D+2*Math.PI,2*Math.PI]]:O>2*Math.PI?[[0,O-2*Math.PI],[D,2*Math.PI]]:[[D,O]],A=tU(2*Math.PI,k,E);if(C.length*A.length>XH)return console.warn(`terrain window for ${e.body.data.id} would need ${C.length}×${A.length} vertices — keeping the uniform sphere`),uU(e),!1;let j=i.geometry;return i.geometry=nU(WH(o,C,A)),j.dispose(),console.debug(`terrain window ${e.body.data.id}: ${C.length}×${A.length} grid, level ${_} (tex ${f})`),e.terrainWindow={thetas:C,phis:A,centerTheta:l,centerPhi:u,angRadius:b,stepLevel:_,texWidth:f,builtAt:performance.now()},e.currentSegments=128,!0}var mU=[{up:150,segs:128},{up:40,segs:64},{up:0,segs:32}],hU=24;function gU(e,t,n,r){if(!n&&!t)return hU;let i=mU[mU.length-1].segs;for(let t of mU)if(e>=t.up){i=t.segs;break}if(i<r){let t=mU.find(e=>e.segs===r);if(t&&e>=t.up*.85)return r}return i}function _U(e,t,n,r,i,a){let o=t.fov*Math.PI/180,s=n.domElement.clientHeight/(2*Math.tan(o/2)),c=r.visibility.activeSystemId,l=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,o=n.body.data.id;if((o===l||n.terrainWindow)&&pU(n,t,o===l,a))continue;let u=gU(n.radiusScene/n.cachedDist*s,e,c?o===c||r.visibility.isInActiveSystem(n.body.data.parentId):o===i,n.currentSegments??64);if(u===n.currentSegments)continue;let d=Q(bn(n.body.data)),f=n.mesh.geometry;n.mesh.geometry=new gu(d,u,u),f.dispose(),n.currentSegments=u}}function vU(e,t){let n=e<1.05?`high`:e<4?`medium`:`low`;if(sP(n)>sP(t))return n;let r=e>7?`low`:e>1.15?`medium`:`high`;return sP(r)<sP(t)?r:t}function yU(e){if(e.textureLoading||e.displacementLoading||e.clouds?.textureLoading||e.appearance?.loading||e.modelLoadPromise)return!0;let t=e.tileOverlay;if(t&&e.surfaceTiles&&!GE(t.chain,e.surfaceTiles))return!0;let n=e.reliefTiles;return n&&!GE(n.chain,n.tiles)?!0:!aU(e)}function bU(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=$C(),p=f.showClouds,m=sP(_E());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=sP(s.textureTier),_=iP(s)?Math.min(m,sP(`medium`)):m,v=Math.min(sP(h),_),y=uP(o,s.availableFrames),b=y!==s.textureFrame,x=v>g;if(f.showSurfaceTexture&&!s.textureLoading&&(x||b)){let e=x?cP(v,s.availableTiers):s.textureTier;e&&_P(s,e,y,i)}let S=u*n.getPixelRatio();aP(s,t,n,S,f.showSurfaceTexture&&!s.appearance?.surfaceOwned,c),_D(s,t,n,S,c);let C=s.displacementMeta?.tiers;if(s.displacementMap&&!s.displacementLoading&&RD(s,n))s.displacementTier!==`pyramid`&&zD(s,ID);else if(s.displacementMap&&C?.length&&!s.displacementLoading){let e=n.capabilities.maxTextureSize,t=e>=16383&&!hD(s)?2:+(e>=8192),r=s.displacementTier??`low`,i=cP(Math.min(sP(vU(p,r)),t,m),C);i&&i!==r&&zD(s,i)}if(s.clouds&&s.textureTier){let e=cP(sP(s.textureTier),s.clouds.availableTiers),t=YM(o,s.clouds.availableFrames,s.clouds.availableCoverage);e&&t&&QM(s.clouds,e,t)}}}var xU=Ze({progress:null,bootPending:!1}),SU=LI.refMs,CU=new Y,wU=new J,TU=new J,EU=new Xi,DU=new Xi,OU=new J,kU=new J;function AU(e,t,n){return wU.set(e[0],e[1],e[2]),TU.set(t[0],t[1],t[2]),CU.lookAt(wU,TU,n),EU.setFromRotationMatrix(CU).clone()}function jU(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=wv(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=Ev(e.camOriginWorld,e.camTargetWorld,e.focusTargetWorld,n);else{let t=r?o*o*o:n;i=wv(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]),DU.copy(t.quaternion),t.quaternion.slerpQuaternions(e.flyQ0,DU,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=wv(e.camOriginWorld,e.camTargetWorld,t)}let i=AU(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 MU(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=AU([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=Tv(r,i),s=e.flyQ0.angleTo(a);e.focusDurationMs=Math.max(II(o,zI),FI(s,BI))}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(),OU.set(0,0,-1).applyQuaternion(e.flyQ0),kU.set(t[0]-r[0],t[1]-r[1],t[2]-r[2]).normalize(),e.focusDurationMs=FI(OU.angleTo(kU),LI);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 NU(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=Tv(n,r);OU.set(e.focusTruePos[0]-n[0],e.focusTruePos[1]-n[1],e.focusTruePos[2]-n[2]).normalize(),kU.set(e.focusTruePos[0]-r[0],e.focusTruePos[1]-r[1],e.focusTruePos[2]-r[2]).normalize();let o=OU.angleTo(kU);e.focusDurationMs=Math.max(II(a,zI),FI(o,BI)),i&&(e.focusDurationMs=0)}var PU={[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},FU=5e-4,IU=new J,LU=new J;function RU(e){return PU[e.data.objectType]??bn(e.data)*.25}function zU(e,t){return Q((t??bn(e.data))+RU(e))}function BU(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(FU),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]]){LU.set(a,o,s).applyQuaternion(e.quaternion);let t=m+LU.x,n=h+LU.y,c=g+LU.z,u=Math.hypot(t,n,c);if(u<1e-12)continue;IU.set(t/u,n/u,c/u).applyQuaternion(r.invQuat);let d=r.radialKm([IU.x,IU.y,IU.z]),f=(d===null?l:Q(d))+Q(FU);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=RU(t);if(_>=Q((r?.outerRadiusKm??i)+v))return;let y=i;r&&_>1e-9&&(IU.set(m/_,h/_,g/_).applyQuaternion(r.invQuat),y=r.radialKm([IU.x,IU.y,IU.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 VU(e,t,n){let r=e.position,{latitude:i,longitude:a,distance:o}=BF([r.x,r.y,r.z],[0,0,0],n),s=Math.min(Math.max(i,t.minLat??-90),t.maxLat??90),c=WF(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]=VF([0,0,0],s,c,l,n);r.set(u,d,f)}var HU=50,UU=20;function WU(e){return e<=0?`none`:e<UU?`full`:e<HU?`half`:`none`}function GU(e,t){return TV(e.data,t)}var KU=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),Dy().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 rv)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||!xn(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:rv.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,renderer:l}=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),CL([e],o,s,c,r,l.domElement,this.deps.onBodyClick,(e,t)=>t?this.deps.hoveredBodyIds.add(e):this.deps.hoveredBodyIds.delete(e),t);let u=r.get(e.data.id);if(u&&!e.data.name&&hP(u),e.data.objectType===G.SPACECRAFT)i.bodies.dirtySpacecraftGroups.add(e.data.parentId);else if(xn(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 d=e.data.id;return this.defaults.has(d)||(n?this.autoPromoted.add(d):(this.userPromoted.add(d),this.emitUserPromotedCount())),!0}finalizeBuilds(){pR(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(ev),t=this.currentMemberCount(e),n=WU(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)||GU(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 e=y_(r.data,r.data.validityStart),i=y_(r.data,r.data.validityEnd);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),GU(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&&!GU(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||mn(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(),Hj(e),gP(e),DM(e),i.remove(e.root),e.trail&&i.remove(e.trail),e.mesh){e.mesh.geometry.dispose(),bL(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(),bL(e.atmosphere.mesh.material),null),e.trail&&(e.trail.geometry.dispose(),bL(e.trail.material));let s=e.body.data.objectType;if(s===G.SPACECRAFT)c.add(e.body.data.parentId);else if(xn(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)}},qU=class{promotion;readerFocusFilter=null;focusedBody;_tmpV3=new J;pendingInitialView=null;upgradeTargetIds=new Set;constructor(e,t,n,r){this.deps=e,this.focusedBody=t,this.promotion=new KU({scene:e.scene,bodyObjects:e.bodyObjects,ctx:e.ctx,clock:e.clock,renderer: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||Dj(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=YU(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&&(wL(t.body)?EL(t,n,r,i):Hj(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}wL(t)&&(TL(o,n,r,i),f=!0),t.data.id!==e?.data.id&&c(t)}return f&&(pR(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]}MU(r,[...n],i,a,o,$C().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,MU(n,[...e],r,a,o,$C().resolvedReducedMotion);let s=BF(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}=BF(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;mn(e)||this.promotion.ensureBodyObjects(e);let u=this.focusedBody,d=mM(u,r),f=mM(e,r),p=u&&(mn(u)?u.featureAnchor.hostId:u.data.id),m=mn(e)?e.featureAnchor.hostId:e.data.id,h=this.syncUpgradeTargets(e);if(p&&p!==m&&!h.has(p)){let e=r.get(p);e&&Hj(e)}if(d&&d!==f){let e=r.get(d);e&&DM(e)}e.data.id!==u?.data.id&&(this.pendingInitialView=null),this.focusedBody=e,mn(e)||(n.bodies.focusFeature=null),i.minDistance=zU(e,lM(r.get(e.data.id)));let g=mn(e)?n.getBody(e.featureAnchor.hostId):void 0;if(n.visibility.setFocused(g??e),a.onFocusChange(e),mn(e)||l(e),f&&f!==e.data.id){let e=n.getBody(f);e&&l(e)}c.syncToFocus();let _=this.place(e);_&&MU(o,[..._],s,this.cameraTruePos(),t,$C().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=VF(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=BF(d??this.cameraTruePos(),u,this.focusedBodyQuat(l));return s.onCameraPosition?.(f.latitude,f.longitude,f.distance),t!==void 0&&d?(this.pendingInitialView=null,this.focusedBody?.data.id===e&&Tv(a.focusTruePos,u)<zU(l)?(a.focusTruePos=[...u],this.deps.repositionAll(),c.rebuildBasis(),NU(a,o,this.cameraTruePos(),d,$C().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=HF(u,d,n,r);a.position.set(f[0],f[1],f[2]),o.update();let p=BF(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=-SU,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=!Dj(r),c=s?this.focusedBodyQuat(r)??[0,0,0,1]:void 0,l=VF([0,0,0],e,t,n,c);i.position.set(l[0],l[1],l[2]),a.update();let u=BF(l,[0,0,0],c);o.onCameraPosition?.(u.latitude,u.longitude,u.distance),this.pendingInitialView=s&&JU(c)?{latitude:e,longitude:t,zoom:n}:null}reapplyInitialViewIfPending(){let e=this.pendingInitialView;if(!e)return;let t=this.focusedBodyQuat();if(!t||JU(t)){this.pendingInitialView=null;return}let n=VF([0,0,0],e.latitude,e.longitude,e.zoom,t);this.deps.camera.position.set(...n),this.deps.controls.update(),this.pendingInitialView=null}};function JU(e){return e[0]===0&&e[1]===0&&e[2]===0&&e[3]===1}function YU(e,t){if(!e)return[];if(mn(e)){let n=t.getBody(e.featureAnchor.hostId);return n&&wL(n)?[n]:[]}let n=[];if(wL(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 XU=1e-6;function ZU(e){return e.data.name??e.data.id}var QU=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),sS(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]-XU,a=r[0]+XU;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:ZU(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)}},$U=class{group=new qa;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()}},eW=Math.PI/180;function tW(e){return`latitude`in e}function nW(e,t,n){let r=e*eW,i=t*eW,a=[Math.cos(r)*Math.cos(i),Math.sin(r),-Math.cos(r)*Math.sin(i)];return n&&rW(n,a,0,a,0),a}function rW(e,t,n,r,i){let a=t[n]*e.a,o=t[n+1]*e.c,s=t[n+2]*e.b,c=Math.hypot(a,o,s);r[i]=a/c,r[i+1]=o/c,r[i+2]=s/c}var iW=class{source=null;radii;out=new Float64Array;of(e,t){if(!t)return e;if(e!==this.source||t!==this.radii){this.out.length!==e.length&&(this.out=new Float64Array(e.length));for(let n=0;n<e.length;n+=3)rW(t,e,n,this.out,n);this.source=e,this.radii=t}return this.out}};function aW(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 oW(e,t,n){return t.place(e,n)}function sW(e,t,n,r){let[i,a,o]=n;if(tW(e)){let n=Q(bn(t.data)+(e.altitudeKm??0)),[s,c,l]=nW(e.latitude,e.longitude,t.drawnRadii),u=t.orientation?xS(t.orientation,r,t.nutPrec):null;if(!u)return[i+s*n,a+c*n,o+l*n];let d=[0,0,0];return aW(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]=gB(s);return[i+c,a+l,o+u]}function cW(e,t,n){let r=t.getBody(e.body),i=r&&oW(r,t,n);return i?sW(e,r,i,n):null}function lW(e,t,n,r){let i=n.getBody(e.body),a=i&&oW(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 uW(e){let t=_g/10;return[e[0]*t,-e[2]*t,e[1]*t]}function dW(e,t,n){let r=cW(e.position,t,n),i=cW(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 fW=.02,pW=1e-4,mW=1e3/60;function hW(e){return e?.4:.05}function gW(e,t){return 1-(1-e)**(t/mW)}function _W(e,t,n,r,i){let a=e.position.length();if(!(a>0))return{rotate:1,translate:1};let o=Dj(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(bn(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(bn(o.data)):0,l=Math.tan(Yi.degToRad(e.getEffectiveFOV())/2);return{rotate:vW(c>0?(a-c)*l/(Math.PI*c):1,pW),translate:vW(s/a,fW)}}function vW(e,t){return Math.min(1,Math.max(t,e))}var yW=Math.PI/180;function bW(e,t){let n=e*yW,r=t*yW;return[Math.cos(n)*Math.cos(r),Math.sin(n),-Math.cos(n)*Math.sin(r)]}function xW(e,t,n,r){let i=document.createElement(`div`);i.className=`user-location-marker`;let a=new DT(i),[o,s,c]=bW(n,r);return a.position.set(o*t,s*t,c*t),e.add(a),a}function SW(e){e.parent?.remove(e),e.element.remove()}var CW=new J;function wW(e,t,n){if(!e)return;let r=t.get(ev);if(!r?.mesh)return;CW.copy(e.position).applyQuaternion(r.mesh.quaternion);let i=CW.x,a=CW.y,o=CW.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 TW=-1,EW=1.2,DW=Q(1e6),OW=.02,kW=2,AW=2.3,jW=.9,MW=new J,NW=.25,PW=10,FW=4,IW=4,LW=28,RW=.02,zW=class e{renderer;composer;maxSceneSamples;atmoDepthPass;modelDepthPass=new LL;bloomPass;labelRenderer;scene;camera;controls;motionScale={rotate:1,translate:1};pointerInteraction;gpuPick;canvas;ctx;clock;callbacks;selectedFeatureId=null;bodyObjects=new Map;circleTexture=VL();pointClouds;systemData;positionDiagnostics=new VV;placer;clickables=[];meshToBody=new Map;hoveredBodyIds=new Set;cullFrameCounter=0;hideCappedMoonLabels=!1;focusController;coverageWatch=null;outOfRange;extensions=new $U;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;_tmpFwd=new J;_tmpSun=new J;_tmpLeak=new J;_occluders=[];_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:SU};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 Xi;restCamPos=new J(NaN,NaN,NaN);restCamQuat=new Xi;restFocusKey=``;atRest=!1;focusLoads=0;unsubscribeBodiesAdded=null;_trailView={camX:0,camY:0,camZ:0,tolAngle:0};viewportH=1;tier=SE();landedNomBodyId=null;rafId=0;paused=!1;covered=!1;firstFrame=!0;pendingUrlWrite=!1;lastTickMs=0;orbitDampingFactor;static FPS_SAMPLE_FRAMES=30;fpsSamples=[];fpsSampleHead=0;stashedSky=null;namesShown=!0;halosShown=!0;textureLoader=new sd;appearances=new kL;shadowLight;ambientLights;get sunPointLight(){return this.bodyObjects.get($_)?.root.children.find(e=>e instanceof wd)}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 kV(o.notices),this.labelContainer=n;let s=wI(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.maxSceneSamples=s.maxSceneSamples,this.bloomPass=s.bloomPass,this.shadowLight=s.shadowLight;let c=this.renderer.getDrawingBufferSize(new q);this.atmoDepthPass=new DL(c.x,c.y),this.modelScene=new to,this.modelScene.environment=XS(this.renderer),this.modelScene.environmentIntensity=qS,this.modelCamera=new bd(60,1,.01,1e3),this.modelScene.add(this.modelCamera);let l=new Od(16777215,GS);this.modelScene.add(l),this.ambientLights=[s.ambientLight,l],this.modelLight=new Dd(16777215,KS),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 Us(new fu(40,40),new _u({opacity:.55})),this.modelShadowPlane.receiveShadow=!0,this.modelShadowPlane.visible=!1,this.modelScene.add(this.modelShadowPlane),this.skyboxAdjuster=new _R(this.scene),this.skyDebugMarkers=new FR(this.scene),this.haloDebug=new WR(this.canvas),this.travelPath=new qB(this.scene,this.canvas),this.travelPath.setLayer(e.MAP_LAYER),this.orbitPreview=new QB(this.scene),this.orbitPreview.setLayer(e.MAP_LAYER),this.skyboxAdjuster.set(0,0,0),JP(this.scene,this.renderer,r,()=>this.disposed),this.placer=new BV(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===GF),r.bodies.majorBodies.find(e=>e.data.id===$_)].find(e=>e&&this.placer.place(e,this.clock.jd)),d=u?.position??iV;this.focus.focusTruePos=[...d],this.focus.focusOriginWorld=[...d],this.focus.focusTargetWorld=[...d],this.focus.focusStartTime=-SU,this.pointClouds=new Cz(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 vF(this.camera,t),this.controls.enableDamping=!0,this.orbitDampingFactor=hW($C().resolvedReducedMotion),this.controls.minDistance=u?zU(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 GI(this.camera,this.controls,r,e=>this.isLanded(e)),this.systemData=new hR(this.scene,r,this.renderer,this.textureLoader,this.bodyObjects,i,()=>this.focusController.reapplyInitialViewIfPending()),this.focusController=new qU({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.renderer),this.coverageWatch=new QU(i,o.notices);let f=u?.data.id===a.id?a:{latitude:45,longitude:0,zoom:15},p=VF([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 NI(this.renderer,this.camera),this.pointerInteraction=new OI(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(){CL(this.ctx.bodies.majorBodies,this.scene,this.clickables,this.meshToBody,this.bodyObjects,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)))(()=>{pR(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]=gB(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]=gB(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=Tv(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){Bz(i.body,a,o,e,this.sceneJd);continue}let s=a.userData.trailLocalPositions;if(!s)continue;let c=a.userData.orbitCenter;Vz(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.controls.dampingFactor=gW(this.orbitDampingFactor,n||16.666666666666668),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():jU(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=xv(a.data.parentId),t=e?this.ctx.getBody(e):void 0,n=!!this.bodyObjects.get(a.data.id)?.isLanded||mn(a);t&&BU(this.camera,t,this.focus.focusTruePos,this.surfaceClamp(t,n)),oM(this.bodyObjects.get(a.data.id))&&BU(this.camera,a,this.focus.focusTruePos,this.surfaceClamp(a,!1)),this.setMotionScale(_W(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=nB(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(),tV(this.bodyObjects,this.focus,this.lastUpdatedJd,this.trailView()),nH(this.bodyObjects,this.focus.focusTruePos,$C().realisticLighting,$C().overexposeRings,this.camera.position,this.pxPerRad());let s=MH(this.bodyObjects,this._occluders);NH(this.bodyObjects,s,this.focus.focusTruePos,this.camera.position.length(),$C().showAtmospheres),KV(this.bodyObjects,s,$C().realisticLighting,this.sunIntensityScale),s.length=0;let c=AH(this.bodyObjects,this.camera.position,$C().showAtmospheres,$C().realisticLighting,this.sunIntensityScale,aw(),this.sceneJd);gw(r,c.shellProminent),this.scene.backgroundIntensity=c.skyboxIntensity,this.applyLayerChrome();let l=this.bodyObjects.get($_);l&&sL(l.corona,l.starPoint,c.sunTint);let u=$C().highAmbient?1:GS;if(!$C().highAmbient&&$C().realisticLighting){let e=this.bodyObjects.get($_)?.body.position;if(e&&this.ctx.visibility.activeSystemId){let[t,n,r]=this.focus.focusTruePos;u*=JS(Math.hypot(e[0]-t,e[1]-n,e[2]-r))}}for(let e of this.ambientLights)e.intensity=u;wW(this.userLocationMarker,this.bodyObjects,this.camera);let d=mM(this.focusController.current,this.bodyObjects);bU(this.bodyObjects,this.camera,this.renderer,this.ctx,this.textureLoader,d,this.sceneJd,this.appearances,this.invalidate),_U(this.bodyObjects,this.camera,this.renderer,this.ctx,d,this.invalidate),FH(this.bodyObjects,this.focus.focusTruePos,this.ctx,this.shadowLight,this.sunPointLight,o,this._tmpV3,$C().realisticLighting,this.sunIntensityScale),this.updateModelMounts(),this.pointClouds.drainOnePendingSceneAdd(),this.updateDepthFar(),this.updateSunProxy(c.sunRefraction),c.insideShell&&this.atmoDepthPass.run(this.renderer,this.scene,this.camera,this.bodyObjects,e.ATMO_DEPTH_LAYER),this.syncSceneSamples(c.insideShell),this.composer.readBuffer.resolveDepthBuffer=this.overlayActive,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),this.checkRest(t)};checkRest(e){let t=this.cameraMovedFrom(this.restCamPos,this.restCamQuat)||this.focusKey()!==this.restFocusKey;this.restCamPos.copy(this.camera.position),this.restCamQuat.copy(this.camera.quaternion),this.restFocusKey=this.focusKey(),t||this.settling(e)?this.atRest=!1:this.atRest||(this.atRest=!0,this.callbacks.onIdle?.())}settling(e){if(this.covered||this.ctx.loading||xU.bootPending||e-this.focus.focusStartTime<this.focus.focusDurationMs||this.jumpJd!==null||this.seekAwaitsData||this.focusLoads>0||this.systemData.isLoading())return!0;for(let e of this.bodyObjects.values())if(e.group.visible&&yU(e))return!0;return!1}syncSceneSamples(e){let t=this.composer.readBuffer,n=e?0:Math.min(this.tier.sceneSamples,this.maxSceneSamples);t.samples!==n&&(t.samples=n,t.dispose())}updateTightFar(e){if(yw())return;let t=this.focusController.current,n=t?mM(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?AW:kW;this.tightFar=i>0&&this.ctx.visibility.activeSystemId!==null&&a<i*s}updateDepthFar(){if(yw())return;let e=xI,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($_);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(xI,Math.max(DW,Math.sqrt(a)*EW))}Math.abs(e-this.camera.far)>this.camera.far*OW&&(this.camera.far=e,this.camera.updateProjectionMatrix())}updateSunProxy(e){let t=this.bodyObjects.get($_),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=MW.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*jW,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}tilesFailed(e){return!!this.bodyObjects.get(e)?.tileOverlay?.chain.dead}surfaceRadialKm(e,t,n){let r=this.ctx.getBody(e);if(!r)return null;let i=nW(t,n,r.drawnRadii);return hO(this.bodyObjects.get(e),e,bn(r.data),i)}surfaceClamp(e,t){let n=this.bodyObjects.get(e.data.id);if(oM(n))return{invQuat:n.model.quaternion.clone().invert(),seated:t,outerRadiusKm:cM(n),centerOffsetScene:sM(n),radialKm:e=>aM(n,e)};if(!(!t||!e.orientation))return{invQuat:xS(e.orientation,this.sceneJd,e.nutPrec).invert(),seated:t,radialKm:t=>hO(n,e.data.id,e.data.radiusKm,t)}}updateModelMounts(){let e=!1;for(let t of this.bodyObjects.values())if(t.model&&Dj(t.body)&&vO(t)){e=!0;break}this.overlayActive=e;for(let t of this.bodyObjects.values()){let n=t.model;if(!n)continue;let r=vO(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=Fj(e);t.scale.setScalar(n);let r=this.shadowLight.intensity>0;if(this.shadowLight.castShadow=r,!r)return;let i=this.bodyObjects.get($_)?.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,PW*n),this.shadowLight.target.position.copy(e.root.position);let o=this.shadowLight.shadow.camera;o.left=o.bottom=-FW*n,o.right=o.top=FW*n,o.near=IW*n,o.far=LW*n,o.updateProjectionMatrix(),this.shadowLight.shadow.normalBias=RW*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=Fj(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||!vO(t))continue;let i=Fj(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($_)?.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]),$C().realisticLighting&&(c=JS(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=zw(this._tmpV3,this._tmpV3),u=Uw(this._tmpV3,this._tmpV3,this._tmpLeak);this.modelLight.color.setRGB(l+u.x,l+u.y,l+u.z),this.modelLight.intensity=KS*c*this.sunIntensityScale,this.modelScene.environmentIntensity=qS*l*c,this.showPointingAxes?(this.pointingAxes||(this.pointingAxes=this.buildPointingAxes(),this.modelScene.add(this.pointingAxes)),this.pointingAxes.quaternion.copy(e.model.quaternion),this.pointingAxes.scale.setScalar(Math.min(.8,.45*i)),this.pointingAxes.visible=!0):this.pointingAxes&&(this.pointingAxes.visible=!1);let d=e.model.userData;this._tmpV3.copy(d.boxCenter).applyQuaternion(e.model.quaternion).add(e.model.position),this.modelCamera.getWorldDirection(this._tmpFwd);let f=this._tmpV3.sub(this.modelCamera.position).dot(this._tmpFwd)-d.halfExtents.length();this.renderer.autoClear=!1,this.renderer.clearDepth(),this.modelDepthPass.run(this.renderer,this.composer.readBuffer.depthTexture,this.camera,this.modelCamera,r,f),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=NW/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 BF([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?TW:Mn.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||VU(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&&dW(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){return this.holdingCamera||t-this.focus.focusStartTime<this.focus.focusDurationMs||this.focusKey()!==this.lastRenderedFocusKey||this.ctx.bodies.minorStreaming||this.pointClouds.hasPendingSceneAdds()||this.systemData.hasPendingUnloads()?!0:this.covered?!1:this.frameIndex-this.lastRenderedFrame>=e.IDLE_HEARTBEAT_FRAMES||this.cameraMovedFrom(this.lastRenderedCamPos,this.lastRenderedCamQuat)||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}cameraMovedFrom(e,t){let n=this.camera;return!(n.position.distanceToSquared(e)<=n.position.lengthSq()*1e-10&&8*(1-Math.abs(n.quaternion.dot(t)))<=1e-8)}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);if(!t)return;this.focusLoads+=2;let n=()=>this.focusLoads--;mP(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&&(SS(t.mesh,e.orientation,this.sceneJd,e.nutPrec),this.focusController.reapplyInitialViewIfPending())}).finally(n),zj(t,this.modelScene,this.ctx).then(()=>{if(this.focusController.current?.data.id===t.body.data.id&&(this.controls.minDistance=zU(t.body,lM(t))),!this.ctx.layers.skipped.has(`nomenclature`))return SM(t,this.canvas,(e,n,r,i)=>{this.featureSelectEnabled&&this.callbacks.onFeatureSelect?.(t.body.data.id,e,n,r,i)})}).then(()=>{this.selectedFeatureId!==null&&EM(t,this.selectedFeatureId)}).finally(n)}reapplyBodyLayers(){let e=this.focusController.current;if(!e)return;let t=this.bodyObjects.get(e.data.id);t&&(Hj(t),gP(t),this.maybeLoadTexture(e))}setSelectedFeature(e){this.selectedFeatureId=e;let t=mM(this.focusController.current,this.bodyObjects),n=t?this.bodyObjects.get(t):void 0;n&&EM(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&&!mn(e))return null;let t=xv(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`}|${nO()}`}lastProbeTargetCheck=null;requestedProbeTargets=new Set;probeTargetRetries=new Tx(()=>{this.lastProbeTargetCheck=null,this.invalidate()});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),nS(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)||this.probeTargetRetries.waiting(r))return;this.requestedProbeTargets.add(r),this.ctx.ensureBody(r,jg(this.clock.jd)).then(()=>this.probeTargetRetries.clear(r),e=>{console.warn(`[renderer] the body ${r} a craft is fit to did not load:`,e),this.requestedProbeTargets.delete(r),this.probeTargetRetries.fail(r)});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(jg(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)+(this.ctx.refresher?.wakes??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(jg(this.clock.jd)),this.focusController.promotion.onSimTimeChanged();let o=eV({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.orbitDampingFactor=hW(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=mM(this.focusController.current,this.bodyObjects)===e.hostId,c=qF(e,t);this.ctx.bodies.focusFeature=c;let l=this.bodyObjects.get(a.data.id);this.selectedFeatureId=e.featureId,l&&EM(l,e.featureId);let u=this.whereBody(c);if(!u)return 0;let d=this.focusController.focusedBodyQuat(c);if(r===`pan`){let e=BF(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?VF(u,i.latitude,i.longitude,i.zoom,d):[u[0]+f*n,u[1]+p*n,u[2]+m*n],_=BF(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=-SU,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(),NU(this.focus,this.camera,e,g,$C().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||!vO(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&&vO(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=mn(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 YR({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:Dj(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 qa,t=new J(0,0,0),n=(n,r,i,a)=>{let o=new af(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 xs(new ss({map:new Kc(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=Jb(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&&dT(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(ev);n?.mesh&&(this.userLocationMarker&&SW(this.userLocationMarker),this.userLocationMarker=xW(n.mesh,n.radiusScene,e,t))}clearUserLocation(){this.userLocationMarker&&=(SW(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.atRest=!1:this.invalidate())}isContextLost(){return this.renderer.getContext().isContextLost()}handleContextRestored(){this.renderer.setPixelRatio(CE()),this.composer.setPixelRatio(CE()),this.resize(this.canvas.clientWidth,this.canvas.clientHeight),JP(this.scene,this.renderer,this.ctx,()=>this.disposed),this.resume()}recoverWorkersIfDead(e){return this.pointClouds.recoverWorkersIfDead(e)}applyRenderTier(){this.tier=SE();let e=CE();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),mI(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&&Hj(e);for(let e of this.bodyObjects.values())tP(e),gD(e);this.pointClouds.dispose(),this.disposeScene(this.scene),this.disposeScene(this.modelScene),BW(this.scene.background),BW(this.scene.environment),BW(this.modelScene.environment),this.circleTexture.dispose(),this.bodyObjects.clear(),this.composer.dispose(),this.atmoDepthPass.dispose(),this.modelDepthPass.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))BW(t);e.dispose()}})}};function BW(e){e&&typeof e==`object`&&e.isTexture&&e.dispose()}var VW=6371;function HW(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 UW={topAltitudeKm:67,rayleighScatterPerKm:[.0058,.0136,.0331],rayleighScaleHeightKm:8.4,mieScatterPerKm:[.004,.004,.004],mieAbsorptionPerKm:[4e-4,4e-4,4e-4],mieScaleHeightKm:1.2,miePhase:HW(.75),absorptionPerKm:[65e-5,.001881,85e-6],absorptionCenterKm:25,absorptionWidthKm:15,bakedCompensation:1,multiScatterGain:.3,sunIntensity:5,sunColor:[1,1,1]},WW=1.6,GW=1.0005,KW=new J(.55,.25,.8).normalize(),qW=[`low`,`medium`,`high`,`ultra`],JW=4,YW=12,XW=10,ZW=16,QW=5;function $W(e){return!e.limb&&!e.sky?NaN:Math.max(e.limb?.medianMs??0,e.sky?.medianMs??0)}function eG(e,t){let n=`low`;for(let r of e.tiers){let e=$W(r);!Number.isNaN(e)&&e<=t&&(n=r.tier)}return n}var tG=new Set([`WebKit WebGL`,`Mozilla`,``]);function nG(e){let t=e.getContext(),n=String(t.getParameter(t.RENDERER)??``);if(!tG.has(n))return n;let r=t.getExtension(`WEBGL_debug_renderer_info`);return r?String(t.getParameter(r.UNMASKED_RENDERER_WEBGL)):n}function rG(e,t){let n=e.getContext(),r=new to,i=new bd(50,n.drawingBufferWidth/Math.max(n.drawingBufferHeight,1),.005,100),a=new Du({color:7829367,roughness:1,metalness:0}),o=new Us(new gu(1,64,64),a);o.renderOrder=1,r.add(o);let s=new Dd(16777215,2);s.position.copy(KW),r.add(s);let c=UW,l=rT(c,1,VW),u=l.material.uniforms;u.uSunDir.value.copy(KW),u.uSunIntensity.value=c.sunIntensity,r.add(l.mesh);let d=e=>{let t=e===`sky`;t?(i.position.set(0,GW,0),i.lookAt(1,GW+.1,0)):(i.position.set(0,0,WW),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}={})=>{uT(l,nw[e]),d(t);let i=0;for(let e=0;e<JW;e++)r?.(`warmup`,e+1),await p(),i=m(1);let a=Math.min(ZW,Math.max(1,Math.ceil(XW/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<YW;e++)if(r?.(`measure`,e+1),await p(),o.push(m(a)),n!==void 0&&o.length>=QW){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(),mT(l)}}}function iG(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 aG(e,t){let n=t.tiers??qW,{budgetMs:r,signal:i,onProgress:a}=t,o=Math.max(0,n.indexOf(t.startTier??n[n.length-1])),s=rG(e,i),c=JW+YW,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`?JW: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`?YW:JW,fraction:u})}}),f=new Map,p=new Map,m=async e=>{let t=n[e];if(nw[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 iG(e,n,f,p)}var oG=60,sG=100,cG=3e4,lG=25e4,uG=`v1`,dG=!1,fG=null,pG=Promise.resolve();function mG(e){let t=e.getContext(),n=Math.round(t.drawingBufferWidth*t.drawingBufferHeight/lG);return`${nG(e)}|${n}|${uG}`}function hG(){dG||typeof window>`u`||(dG=!0,xU.bootPending=!0,pG=new Promise(e=>{let t=()=>{xU.bootPending=!1,e()};setTimeout(t,cG),setTimeout(()=>void _G(!1).finally(t),sG)}))}function gG(){return pG}function _G(e){return fG??=vG(e).finally(()=>fG=null),fG}async function vG(e){let t=$C();if(!e&&(t.atmosphereQuality!==`auto`||!t.showAtmospheres))return;let n=null;try{n=new wh({canvas:document.createElement(`canvas`),antialias:!0}),n.setPixelRatio(qC()),n.setSize(window.innerWidth,window.innerHeight,!1);let r=mG(n);if(!e&&t.atmosphereCalibration?.key===r)return;xU.progress=0;let i=await aG(n,{budgetMs:1e3/oG,startTier:rw(),onProgress:e=>xU.progress=e.fraction}),a={};for(let e of i.tiers){let t=$W(e);Number.isNaN(t)||(a[e.tier]=Math.round(t*100)/100)}let o=eG(i,1e3/oG);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{xU.progress=null,n?.dispose(),n?.forceContextLoss()}}var yG=class{object=new qa;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 DT(e.element);let[n,r]=e.align??[.5,.5];this.label.center.set(n,r),this.object.add(this.label),this.object.matrixAutoUpdate=!1,FT(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?cW(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=lW(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()}},bG=3,xG=new J,SG=new J,CG=new J;function wG(e){let[t,n=t]=(e??``).split(/[\s,]+/).filter(Boolean).map(Number);return t>0&&n>0?[t,n]:null}function TG(e,t){return xG.set(1,0,0).applyQuaternion(e.quaternion),SG.set(0,1,0).applyQuaternion(e.quaternion),CG.set(0,0,-1).applyQuaternion(e.quaternion),t/(2*Math.tan(e.getEffectiveFOV()*Math.PI/360))}function EG(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*xG.x+a*xG.y+o*xG.z,r[1]=i*SG.x+a*SG.y+o*SG.z,r[2]=i*CG.x+a*CG.y+o*CG.z}function DG(e,t,n){CG.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)*CG.x+(e[o*3+1]-i)*CG.y+(e[o*3+2]-a)*CG.z<n.near*2)return!0;return!1}function OG(e,t,n,r,i){let a=TG(n,r),o=[0,0,0],s=0,c=0,l=0,u=!1;for(let r=0;r<t;r++){if(EG(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 kG=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=TG(r,i),o=i*r.aspect*bG/2,s=i*bG/2,c=r.near*2,{a:l,b:u}=this,d=!1,f=0,p=0,m=0;n>0&&EG(e,0,r,l);for(let i=0;i+1<n;i++,[l,u]=[u,l]){EG(e,i+1,r,u);let n=0,h=1;for(let e=0;e<5&&n<=h;e++){let t=AG(e,l,a,o,s,c),r=AG(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 AG(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 jG=1e-9,MG=class{object=new qa;anchor;color;widthPx;opacity;dash;fade;closed;local;count=0;mesh=null;scratch=new Float32Array;alphas=new Float32Array;seen=new kG;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=wG(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?cW(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])>jG||Math.abs(o[1]-this.lastOrigin[1])>jG||Math.abs(o[2]-this.lastOrigin[2])>jG;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||DG(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),$L(this.mesh.geometry,e.points,e.alphas,e.alphas,e.count),this.dash&&nR(this.mesh.geometry,e.lengths,e.count)}else s&&$L(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=rR(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 NG(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=PG(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,PG(n,a)]}function PG(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 FG(e,t={}){let[n,r]=NG(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 IG(e){if(e.length<3)return[];let[t,n]=NG(LG(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 lu.triangulateShape(r,[]).flat()}function LG(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 RG(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 zG([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 zG(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 BG(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]]:zG([n,r,i])}function VG(e,t){return new Tu({transparent:!0,depthWrite:!1,side:2,uniforms:{uColor:{value:new X(e)},uOpacity:{value:t},uCenterOffset:{value:new J}},vertexShader:`
|
|
6367
6367
|
#include <common>
|
|
6368
6368
|
#include <logdepthbuf_pars_vertex>
|
|
6369
6369
|
uniform vec3 uCenterOffset;
|
|
@@ -6380,6 +6380,6 @@ void main() {
|
|
|
6380
6380
|
gl_FragColor = vec4(uColor, uOpacity);
|
|
6381
6381
|
#include <logdepthbuf_fragment>
|
|
6382
6382
|
}
|
|
6383
|
-
`})}var RG=.25,zG=1e-9,BG=3,VG=class{object=new qa;anchor;outline;fillColor;fillOpacity;local=new Float64Array;count=0;mesh=null;scratch=new Float32Array;lastOrigin=[0,0,0];dirty=!0;wanted=!0;removeSelf=null;constructor(e){this.anchor=e.anchor;let t=e.widthPx??2;this.fillColor=e.fill??null,this.fillOpacity=e.fillOpacity??RG,this.outline=t>0?new OG({anchor:e.anchor,points:e.points,color:e.color,widthPx:t,opacity:e.opacity,closed:!0}):null,this.outline&&this.object.add(this.outline.object),this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){this.outline?.setPoints(e),this.local.length<e.length*3&&(this.local=new Float64Array(e.length*3));for(let t=0;t<e.length;t++){let[n,r,i]=e[t];this.local[t*3]=Q(n),this.local[t*3+1]=Q(i),this.local[t*3+2]=Q(-r)}this.count=e.length,this.rebuild(e)}setAnchor(e){this.anchor=e,this.outline?.setAnchor(e)}setVisible(e){this.wanted=e,this.outline?.setVisible(e)}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){this.outline?.update(e);let t=this.mesh;if(!t)return;let{jd:n,basis:r,camera:i,ctx:a}=e,o=this.wanted?rW(this.anchor,a,n):null;if(t.visible=o!==null,!o)return;let s=[o[0]-r[0],o[1]-r[1],o[2]-r[2]];if(this.dirty||Math.abs(s[0]-this.lastOrigin[0])>zG||Math.abs(s[1]-this.lastOrigin[1])>zG||Math.abs(s[2]-this.lastOrigin[2])>zG){let e=t.geometry.getAttribute(`position`);for(let e=0;e<this.count*3;e+=3)this.scratch[e]=this.local[e]+s[0],this.scratch[e+1]=this.local[e+1]+s[1],this.scratch[e+2]=this.local[e+2]+s[2];e.needsUpdate=!0,this.lastOrigin=s,this.dirty=!1}t.material.uniforms.uCenterOffset.value.copy(i.position).negate()}rebuild(e){this.disposeMesh(),this.dirty=!0;let t=this.fillColor;if(!t)return;let n=MG(e);if(!n.length)return;let r=new ts;r.setAttribute(`position`,new Uo(new Float32Array(e.length*3),3)),r.setIndex(n),this.scratch=r.getAttribute(`position`).array;let i=new Us(r,LG(t,this.fillOpacity));i.matrixAutoUpdate=!1,i.renderOrder=BG,i.frustumCulled=!1,this.object.add(i),this.mesh=i}disposeMesh(){let e=this.mesh;e&&(this.object.remove(e),e.geometry.dispose(),e.material.dispose(),this.mesh=null)}dispose(){this.disposeMesh(),this.outline?.dispose()}},HG=class extends VG{normal;steps;constructor(e){let{radiusKm:t,normal:n,steps:r,...i}=e;super({...i,points:jG(t,{normal:n,steps:r})}),this.normal=n,this.steps=r}setRadiusKm(e){this.setPoints(jG(e,{normal:this.normal,steps:this.steps}))}},UG=class extends hG{constructor(e,t){let n=document.createElement(`div`);n.className=`sm-drawing-label`,e.interactive&&n.classList.add(`sm-drawing--interactive`),e.className&&n.classList.add(e.className),n.textContent=e.text,e.color&&(n.style.color=e.color),e.fontSizePx!==void 0&&(n.style.fontSize=`${e.fontSizePx}px`),super({anchor:e.anchor,element:n,align:e.align,occlude:e.occlude},t)}setText(e){this.element.textContent=e}},WG=class extends hG{constructor(e,t){let n=document.createElement(`img`);n.className=`sm-drawing-icon`,e.interactive&&n.classList.add(`sm-drawing--interactive`),e.className&&n.classList.add(e.className),n.src=e.url,n.alt=e.alt??``,e.widthPx!==void 0&&(n.style.width=`${e.widthPx}px`),e.heightPx!==void 0&&(n.style.height=`${e.heightPx}px`),e.opacity!==void 0&&(n.style.opacity=String(e.opacity)),super({anchor:e.anchor,element:n,align:e.align,occlude:e.occlude},t)}setUrl(e){this.element.src=e}},GG=Math.PI/180,KG=180/Math.PI;function qG(e){return e>=-180&&e<180?e:((e+180)%360+360)%360-180}function JG(e,t){return(n,r)=>{let i=e(r);return!i||Math.abs(n)>i.maxAbsX+1e-9?null:[qG(n*i.lonPerX+t),i.lat]}}function YG(e){let{minX:t,maxX:n,minY:r,maxY:i}=e.extent;return(n-t)/(i-r)}function XG(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=179.999999999;for(let o=0;o<=720;o++){let s=-90+180*o/720;for(let o=0;o<=720;o++){let c=e(-a+2*a*o/720,s);c&&(c[0]<t&&(t=c[0]),c[0]>r&&(r=c[0]),c[1]<n&&(n=c[1]),c[1]>i&&(i=c[1]))}}return{minX:t,minY:n,maxX:r,maxY:i}}function ZG(e){let t=e.centerLon??0,n=e=>Math.abs(e)>Math.PI/2?null:{lat:e*KG,lonPerX:KG,maxAbsX:Math.PI};return{id:`equirectangular`,centerLon:t,cyclic:!0,rectangular:!0,azimuthal:!1,extent:{minX:-Math.PI,minY:-Math.PI/2,maxX:Math.PI,maxY:Math.PI/2},forward:(e,n)=>[qG(e-t)*GG,n*GG],rowInverse:n,inverse:JG(n,t)}}var QG=1.340264,$G=-.081106,eK=893e-6,tK=.003796,nK=Math.sqrt(3),rK=e=>tK*e**9+eK*e**7+$G*e**3+QG*e,iK=e=>9*tK*e**8+7*eK*e**6+3*$G*e**2+QG;function aK(e){let t=e.centerLon??0,n=(e,n)=>{let r=Math.asin(xK(nK/2*Math.sin(n*GG))),i=qG(e-t)*GG;return[2*nK*i*Math.cos(r)/(3*iK(r)),rK(r)]},r=e=>{let t=e;for(let n=0;n<12;n++){let n=(rK(t)-e)/iK(t);if(t-=n,Math.abs(n)<1e-12)break}return t},i=e=>{let t=r(e),n=2/nK*Math.sin(t);if(Math.abs(n)>1)return null;let i=3*iK(t)/(2*nK*Math.cos(t))*KG;return{lat:Math.asin(n)*KG,lonPerX:i,maxAbsX:180/i}};return{id:`equalEarth`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:XG(n),forward:n,rowInverse:i,inverse:JG(i,t)}}var oK=Math.SQRT2;function sK(e){let t=e.centerLon??0,n=e=>{let t=e/oK;if(Math.abs(t)>1)return null;let n=Math.asin(t),r=(2*n+Math.sin(2*n))/Math.PI;if(Math.abs(r)>1)return null;let i=Math.cos(n);if(i<1e-12)return{lat:Math.sign(e)*90,lonPerX:0,maxAbsX:0};let a=Math.PI/(2*oK*i)*KG;return{lat:Math.asin(r)*KG,lonPerX:a,maxAbsX:180/a}};return{id:`mollweide`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-2*oK,minY:-oK,maxX:2*oK,maxY:oK},forward:(e,n)=>{let r=n*GG,i=r;if(Math.abs(Math.abs(r)-Math.PI/2)<1e-9)i=Math.PI/2*Math.sign(r);else{let e=Math.PI*Math.sin(r);for(let t=0;t<20;t++){let t=(2*i+Math.sin(2*i)-e)/(2+2*Math.cos(2*i));if(i-=t,Math.abs(t)<1e-12)break}}let a=qG(e-t)*GG;return[2*oK/Math.PI*a*Math.cos(i),oK*Math.sin(i)]},rowInverse:n,inverse:JG(n,t)}}function cK(e){let t=e.centerLon??0,n=e=>{if(Math.abs(e)>Math.PI/2)return null;let t=Math.cos(e);return t<1e-12?{lat:Math.sign(e)*90,lonPerX:0,maxAbsX:0}:{lat:e*KG,lonPerX:KG/t,maxAbsX:Math.PI*t}};return{id:`sinusoidal`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-Math.PI,minY:-Math.PI/2,maxX:Math.PI,maxY:Math.PI/2},forward:(e,n)=>{let r=n*GG;return[qG(e-t)*GG*Math.cos(r),r]},rowInverse:n,inverse:JG(n,t)}}var lK=[1,.9986,.9954,.99,.9822,.973,.96,.9427,.9216,.8962,.8679,.835,.7986,.7597,.7186,.6732,.6213,.5722,.5322],uK=[0,.062,.124,.186,.248,.31,.372,.434,.4958,.5571,.6176,.6769,.7346,.7903,.8435,.8936,.9394,.9761,1],dK=.8487,fK=1.3523,pK=5;function mK(e,t){let n=e[Math.max(t-1,0)],r=e[t],i=e[t+1],a=e[Math.min(t+2,e.length-1)];return[r,.5*(i-n),.5*(2*n-5*r+4*i-a),.5*(-n+3*r-3*i+a)]}var hK=(e,t)=>e[0]+t*(e[1]+t*(e[2]+t*e[3])),gK=(e,t)=>e[1]+t*(2*e[2]+3*e[3]*t);function _K(e){let t=Math.min(Math.max(Math.floor(e),0),lK.length-2);return[t,e-t]}function vK(e){let[t,n]=_K(e);return dK*hK(mK(lK,t),n)*Math.PI}function yK(e){let t=0,n=uK.length-1;for(;n-t>1;){let r=t+n>>1;uK[r]<=e?t=r:n=r}let r=Math.min(t,uK.length-2),i=mK(uK,r),a=(e-uK[r])/(uK[r+1]-uK[r]);for(let t=0;t<8;t++){let t=gK(i,a);if(t===0)break;let n=(hK(i,a)-e)/t;if(a-=n,Math.abs(n)<1e-14)break}return r+Math.min(Math.max(a,0),1)}function bK(e){let t=e.centerLon??0,n=e=>{let t=Math.abs(e)/fK;if(t>1)return null;let n=yK(t),r=vK(n);return{lat:Math.sign(e)*n*pK,lonPerX:180/r,maxAbsX:r}};return{id:`robinson`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-dK*Math.PI,minY:-fK,maxX:dK*Math.PI,maxY:fK},forward:(e,n)=>{let[r,i]=_K(Math.abs(n)/pK),a=hK(mK(lK,r),i),o=hK(mK(uK,r),i);return[dK*a*qG(e-t)*GG,fK*o*Math.sign(n)]},rowInverse:n,inverse:JG(n,t)}}function xK(e){return e<-1?-1:e>1?1:e}function SK(e,t,n,r,i,a,o){let s=Math.asin(xK(n*a+t*r*o));return[qG(i+Math.atan2(e*r,n*o-t*r*a)*KG),s*KG]}function CK(e){return{minX:-e,minY:-e,maxX:e,maxY:e}}function wK(e,t,n,r){let i=qG(e-n)*GG,a=t*GG;return[Math.cos(a)*Math.sin(i),Math.cos(r)*Math.sin(a)-Math.sin(r)*Math.cos(a)*Math.cos(i)]}function TK(e){let t=e.centerLon??0,n=(e.centerLat??0)*GG,r=Math.min(e.clipAngle??90,90)*GG,i=Math.cos(r),a=Math.sin(r),o=Math.sin(n),s=Math.cos(n);return{id:`orthographic`,centerLon:t,cyclic:!1,rectangular:!1,azimuthal:!0,extent:CK(a),forward:(e,r)=>{let a=qG(e-t)*GG,o=r*GG;return Math.sin(n)*Math.sin(o)+Math.cos(n)*Math.cos(o)*Math.cos(a)<i?null:wK(e,r,t,n)},inverse:(e,n)=>{let r=e*e+n*n;return r>a*a?null:SK(e,n,Math.sqrt(1-r),1,t,o,s)}}}var EK=120;function DK(e){let t=e.centerLon??0,n=(e.centerLat??90)*GG,r=Math.min(e.clipAngle??EK,170)*GG,i=Math.cos(r),a=2*Math.tan(r/2),o=Math.sin(n),s=Math.cos(n);return{id:`stereographic`,centerLon:t,cyclic:!1,rectangular:!1,azimuthal:!0,extent:CK(a),forward:(e,r)=>{let a=qG(e-t)*GG,o=r*GG,s=Math.sin(n)*Math.sin(o)+Math.cos(n)*Math.cos(o)*Math.cos(a);if(s<i)return null;let c=2/(1+s),[l,u]=wK(e,r,t,n);return[c*l,c*u]},inverse:(e,n)=>{let r=e*e+n*n;if(r>a*a)return null;let i=4/(4+r);return SK(e,n,(4-r)*i*.25,i,t,o,s)}}}var OK={equirectangular:ZG,equalEarth:aK,mollweide:sK,sinusoidal:cK,robinson:bK,orthographic:TK,stereographic:DK},kK=Object.keys(OK);function AK(e,t={}){let n=OK[e];if(!n)throw Error(`spacemap: unknown projection "${e}"`);return n(t)}var jK=Math.PI/180,MK=2*Math.PI,NK=2*jK,PK=180/Math.PI,FK=512,IK=2;function LK(e,t){let n=e.lat*jK,r=t.lat*jK,i=r-n,a=qG(t.lon-e.lon)*jK,o=Math.sin(i/2)**2+Math.cos(n)*Math.cos(r)*Math.sin(a/2)**2;return 2*Math.asin(Math.min(1,Math.sqrt(o)))*PK}function RK(e,t,n){let r=LK(e,t)*jK;if(r<1e-12)return e;let i=Math.sin(r),a=Math.sin((1-n)*r)/i,o=Math.sin(n*r)/i,s=e.lat*jK,c=e.lon*jK,l=t.lat*jK,u=(e.lon+qG(t.lon-e.lon))*jK,d=a*Math.cos(s)*Math.cos(c)+o*Math.cos(l)*Math.cos(u),f=a*Math.cos(s)*Math.sin(c)+o*Math.cos(l)*Math.sin(u),p=a*Math.sin(s)+o*Math.sin(l);return{lon:Math.atan2(f,d)*PK,lat:Math.atan2(p,Math.hypot(d,f))*PK}}function zK(e,t,n){return{lon:e.lon+qG(t.lon-e.lon)*n,lat:e.lat+(t.lat-e.lat)*n}}function BK(e,t={}){let n=t.interpolate??`linear`,r=t.stepDeg??IK,i=n===`geodesic`?RK:zK,a=t.closed&&e.length>2?[...e,e[0]]:e;if(a.length<2)return[...a];let o=[a[0]];for(let e=1;e<a.length;e++){let t=a[e-1],n=a[e],s=Math.min(FK,Math.max(1,Math.ceil(LK(t,n)/r)));for(let e=1;e<=s;e++)o.push(e===s?n:i(t,n,e/s))}return o}function VK(e,t,n){let r=0,i=1;for(let a=0;a<20;a++){let a=(r+i)/2,o=zK(e,t,a);n.forward(o.lon,o.lat)?r=a:i=a}return zK(e,t,r)}function HK(e,t){let n=t.projection.cyclic?t.worldWidthPx/2:1/0,{projection:r}=t,i=[],a=[],o=null,s=0;for(let c=0;c<e.length;c++){let l=e[c],u=t.project(l.lon,l.lat);if(!u){if(a.length&&c>0){let n=VK(e[c-1],l,r);a.push(t.project(n.lon,n.lat))}a.length>1&&i.push(a),a=[],o=null,s++;continue}if(o&&Math.abs(u[0]-o[0])>n&&(a.length>1&&i.push(a),a=[]),!a.length&&c>0&&!t.project(e[c-1].lon,e[c-1].lat)){let n=VK(l,e[c-1],r);a.push(t.project(n.lon,n.lat))}a.push(u),o=u}return a.length>1&&i.push(a),{runs:i,whole:i.length===1&&s===0}}function UK(e,t){let n=[...e];for(let r of t.repeatShifts)if(r!==0)for(let i of e){let e=1/0,a=-1/0;for(let[t]of i)t<e&&(e=t),t>a&&(a=t);e+r>t.width||a+r<0||n.push(i.map(([e,t])=>[e+r,t]))}return n}function WK(e,t){let n=`M${e[0][0].toFixed(2)} ${e[0][1].toFixed(2)}`;for(let t=1;t<e.length;t++)n+=`L${e[t][0].toFixed(2)} ${e[t][1].toFixed(2)}`;return t?`${n}Z`:n}var GK=179.999999;function KK(e,t){let n=e=>e>GK?GK:e<-GK?-GK:e,r=e.length;if(r<3)return[e];let i=[],a=[],o=qG(e[0].lon-t);a.push({lon:n(o),lat:e[0].lat});for(let t=0;t<r;t++){let s=e[t],c=e[(t+1)%r],l=qG(c.lon-s.lon),u=o+l,d=u>180?1:u<-180?-1:0;if(d!==0){let e=s.lat+(c.lat-s.lat)*((d*180-o)/l);a.push({lon:d*GK,lat:e}),i.push(a),a=[{lon:-d*GK,lat:e}],o=u-d*360}else o=u;t<r-1&&a.push({lon:n(o),lat:c.lat})}return i.length===0?[a.map(e=>({lon:e.lon+t,lat:e.lat}))]:(i[0]=a.concat(i[0]),i.map(e=>e.map(e=>({lon:e.lon+t,lat:e.lat}))))}function qK(e,t,n={}){if(e.length<2)return``;let{projection:r}=t;return(n.closed&&r.cyclic?KK(e,r.centerLon):[e]).map(e=>{let{runs:r,whole:i}=HK(BK(e,n),t),a=!!n.closed&&i;return UK(r,t).map(e=>WK(e,a)).join(``)}).join(``)}function JK(e,t,n={}){let{projection:r}=t;if(!r.azimuthal)return qK(e,t,{...n,closed:!0});if(e.length<2)return``;let i=BK(e,{...n,closed:!0}),a=e.length>2?i.slice(0,-1):i,o=a.map(e=>r.forward(e.lon,e.lat)),s=([e,n])=>t.toScreen(e,n),c=o.filter(Boolean).length;if(c===0)return``;if(c===a.length)return WK(o.map(e=>s(e)),!0);let l=a.length,u=0;for(;!o[u]||o[(u+l-1)%l];)u++;let d=[],f=null;for(let e=0;e<l;e++){let t=(u+e)%l,n=(t+l-1)%l,i=o[t];if(i){if(!f){let e=VK(a[t],a[n],r);f=[r.forward(e.lon,e.lat)]}f.push(i)}else if(f){let e=VK(a[n],a[t],r);f.push(r.forward(e.lon,e.lat)),d.push(f),f=null}}let p=YK(a),m=([e,t])=>Math.atan2(t,e),h=Math.hypot(...d[0][0]),g=[],_=new Set;for(let e=0;e<d.length;e++){if(_.has(e))continue;let t=[],n=e;do{_.add(n),t.push(...d[n]);let r=m(d[n][d[n].length-1]),i=e,a=1/0;for(let e=0;e<d.length;e++){let t=m(d[e][0]),n=((p?t-r:r-t)%MK+MK)%MK;n<a&&(a=n,i=e)}let o=Math.ceil(a/NK);for(let e=1;e<o;e++){let n=r+(p?1:-1)*a*e/o;t.push([h*Math.cos(n),h*Math.sin(n)])}n=i}while(n!==e&&!_.has(n));g.push(t)}return g.map(e=>WK(e.map(s),!0)).join(``)}function YK(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t+=qG(i.lon-r.lon)*jK*(2+Math.sin(r.lat*jK)+Math.sin(i.lat*jK))}let n=-t/2;return n>0?n<MK:n<-MK}function XK(e,t=2){let{projection:n}=e,r=179.999999,i=[],a=(r,a,o)=>{let s=a<o?t:-t;for(let t=a;s>0?t<=o:t>=o;t+=s){let a=n.forward(r,t);a&&i.push(e.toScreen(a[0],a[1]))}};return a(n.centerLon-r,-90,90),a(n.centerLon+r,90,-90),i.length<3?``:UK([i],e).map(e=>WK(e,!0)).join(``)}function ZK(e,t,n,r){let i=n+r,a=[],o=(e,t,n)=>{let r=Math.max(1,Math.ceil(Math.abs(n-t)/5));for(let i=0;i<=r;i++)a.push({lon:t+(n-t)*i/r,lat:e})};return o(e,n,i),o(t,i,n),a}function QK(e,t,n=128){let r=e.lat*jK,i=e.lon*jK,a=[Math.cos(r)*Math.cos(i),Math.cos(r)*Math.sin(i),Math.sin(r)],o=[-a[1],a[0],0],s=Math.hypot(o[0],o[1]);o=s<1e-9?[1,0,0]:[o[0]/s,o[1]/s,0];let c=[a[1]*o[2]-a[2]*o[1],a[2]*o[0]-a[0]*o[2],a[0]*o[1]-a[1]*o[0]],l=t*jK,u=Math.sin(l),d=Math.cos(l),f=[];for(let e=0;e<n;e++){let t=2*Math.PI*e/n,r=Math.sin(t)*u,i=Math.cos(t)*u,s=a[0]*d+o[0]*r+c[0]*i,l=a[1]*d+o[1]*r+c[1]*i,p=a[2]*d+o[2]*r+c[2]*i;f.push({lon:qG(Math.atan2(l,s)*PK),lat:Math.atan2(p,Math.hypot(s,l))*PK})}return f}var $K=24;function eq(e=30){let t=[];for(let n=-180;n<180;n+=e)t.push([{lon:n,lat:-90},{lon:n,lat:90}]);let n=179.999999;for(let r=-90+e;r<90;r+=e){let e=[];for(let t=0;t<=$K;t++)e.push({lon:-n+2*n*t/$K,lat:r});t.push(e)}return t}var tq=.005,nq=1.5,rq=5,iq=24,aq=class{object=new qa;body;altitudeKm;closed;interpolate;stepDeg;color;widthPx;opacity;dash;fillColor;fillOpacity;dirs=new Float64Array;count=0;line=null;scratch=new Float32Array;alphas=new Float32Array;lengths=new Float32Array;fanDirs=new Float64Array;groundDirs=new $U;groundFanDirs=new $U;fill=null;fillScratch=new Float32Array;turned=[0,0,0];wanted=!0;removeSelf=null;constructor(e){this.body=e.body,this.altitudeKm=e.altitudeKm??null,this.closed=e.closed??!1,this.interpolate=e.interpolate??`linear`,this.stepDeg=e.stepDeg,this.color=e.color??`#ffffff`,this.widthPx=e.widthPx??2,this.opacity=e.opacity??1,this.dash=bG(e.dash),this.fillColor=e.fill??null,this.fillOpacity=e.fillOpacity??.25,this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){let t=BK(e,{interpolate:this.interpolate,stepDeg:this.stepDeg,closed:this.closed});this.dirs=new Float64Array(t.length*3);for(let e=0;e<t.length;e++){let[n,r,i]=ZU(t[e].lat,t[e].lon);this.dirs[e*3]=n,this.dirs[e*3+1]=r,this.dirs[e*3+2]=i}this.count=t.length,this.buildLine(),this.buildFill()}setVisible(e){this.wanted=e}remove(){this.removeSelf?.(),this.removeSelf=null}update({jd:e,basis:t,camera:n,viewportPx:r,ctx:i}){let a=this.wanted&&this.count>=2?i.getBody(this.body):void 0,o=a&&tW(a,i,e);if(this.line&&(this.line.visible=!!o),this.fill&&(this.fill.visible=!!o),!a||!o)return;let s=bn(a.data),c=Q(s+(this.altitudeKm??s*tq)),l=a.orientation?xS(a.orientation,e,a.nutPrec):null,u=[o[0]-t[0],o[1]-t[1],o[2]-t[2]];if(this.line){let e=this.groundDirs.of(this.dirs,a.drawnRadii);this.place(e,this.count,l,c,u,this.scratch),QL(this.line.geometry,this.scratch,this.alphas,this.alphas,this.count),this.dash&&(wG(this.scratch,this.count,n,r,this.lengths),tR(this.line.geometry,this.lengths,this.count)),this.line.material.uniforms.uCenterOffset.value.copy(n.position).negate()}if(this.fill){let e=this.fill.geometry.getAttribute(`position`),t=this.groundFanDirs.of(this.fanDirs,a.drawnRadii);this.place(t,this.fillScratch.length/3,l,c,u,this.fillScratch),e.needsUpdate=!0,this.fill.material.uniforms.uCenterOffset.value.copy(n.position).negate()}}place(e,t,n,r,i,a){for(let o=0;o<t;o++){let t=o*3;n?eW(n,e[t],e[t+1],e[t+2],this.turned,0):(this.turned[0]=e[t],this.turned[1]=e[t+1],this.turned[2]=e[t+2]),a[t]=this.turned[0]*r+i[0],a[t+1]=this.turned[1]*r+i[1],a[t+2]=this.turned[2]*r+i[2]}}buildLine(){if(this.disposeLine(),this.count<2||this.widthPx<=0)return;this.scratch=new Float32Array(this.count*3),this.alphas=new Float32Array(this.count).fill(this.opacity),this.lengths=new Float32Array(this.count);let e=nR(this.count,this.scratch,this.alphas,this.alphas,this.count,this.color,this.widthPx,1,this.dash??void 0);e.frustumCulled=!1,e.renderOrder=nq,this.object.add(e),this.line=e}buildFill(){if(this.disposeFill(),!this.fillColor||this.count<3)return;let e=IG(this.dirs,this.count),t=0;for(let n=0;n<this.count;n++){let r=e[0]*this.dirs[n*3]+e[1]*this.dirs[n*3+1]+e[2]*this.dirs[n*3+2];t=Math.max(t,Math.acos(Math.min(1,Math.max(-1,r))))}let n=Math.min(iq,Math.max(1,Math.ceil(t*180/Math.PI/rq))),r=1+n*this.count;this.fanDirs=new Float64Array(r*3),this.fanDirs[0]=e[0],this.fanDirs[1]=e[1],this.fanDirs[2]=e[2];for(let t=1;t<=n;t++)for(let r=0;r<this.count;r++){let[i,a,o]=PG(e,[this.dirs[r*3],this.dirs[r*3+1],this.dirs[r*3+2]],t/n),s=(1+(t-1)*this.count+r)*3;this.fanDirs[s]=i,this.fanDirs[s+1]=a,this.fanDirs[s+2]=o}let i=[],a=(e,t)=>1+(e-1)*this.count+t;for(let e=0;e<this.count-1;e++)i.push(0,a(1,e),a(1,e+1));for(let e=1;e<n;e++)for(let t=0;t<this.count-1;t++){let n=a(e,t),r=a(e,t+1),o=a(e+1,t),s=a(e+1,t+1);i.push(n,o,r,r,o,s)}let o=new ts;o.setAttribute(`position`,new Uo(new Float32Array(r*3),3)),o.setIndex(i),this.fillScratch=o.getAttribute(`position`).array;let s=new Us(o,LG(this.fillColor,this.fillOpacity));s.matrixAutoUpdate=!1,s.frustumCulled=!1,s.renderOrder=nq,this.object.add(s),this.fill=s}disposeLine(){this.line&&=(this.object.remove(this.line),this.line.geometry.dispose(),this.line.material.dispose(),null)}disposeFill(){this.fill&&=(this.object.remove(this.fill),this.fill.geometry.dispose(),this.fill.material.dispose(),null)}dispose(){this.disposeLine(),this.disposeFill()}},oq=class{object=new qa;id;name;anchor;model;trueScale;spanScene;minPx;label;wanted=!0;removeSelf=null;constructor(e,t,n){this.id=t,this.name=e.name??null,this.anchor=e.position,this.object.matrixAutoUpdate=!1,this.object.frustumCulled=!1;let r=e.model;this.model=r?.object3d??null,this.minPx=r?.minPx??0;let i=r?sq(r.object3d):0;this.trueScale=r?.scaleM!==void 0&&i>0?Q(r.scaleM/1e3)/i:1,this.spanScene=i*this.trueScale,this.model&&this.object.add(this.model),this.label=e.label&&this.name?new UG({anchor:e.position,text:this.name,align:[.5,1.4],occlude:e.occludeLabel},n):null,this.label&&this.object.add(this.label.object)}bind(e){this.removeSelf=e}get position(){return this.anchor}positionKm(e){let t=this.anchor;if(`latitude`in t)return null;let n=typeof t.offsetKm==`function`?t.offsetKm(e):t.offsetKm;return n===void 0?[0,0,0]:n}setPosition(e){this.anchor=e,this.label?.setAnchor(e)}setVisible(e){this.wanted=e,this.label?.setVisible(e)}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){let{basis:t,camera:n,jd:r,ctx:i}=e,a=this.model,o=this.wanted?rW(this.anchor,i,r):null;if(this.label?.update(e),!a||(a.visible=o!==null,!o))return;a.position.set(o[0]-t[0],o[1]-t[1],o[2]-t[2]);let s=this.drawnScale(a.position,n,e.viewportPx);a.scale.setScalar(s),a.updateMatrixWorld(!0)}drawnScale(e,t,n){if(this.minPx<=0||this.spanScene<=0)return this.trueScale;let r=t.position.distanceTo(e);if(r<=0)return this.trueScale;let i=n/(2*Math.tan(t.fov*Math.PI/180/2)*r),a=this.spanScene*i;return a>=this.minPx?this.trueScale:this.trueScale*(this.minPx/a)}dispose(){this.label?.dispose(),this.model&&this.object.remove(this.model)}};function sq(e){let t=new _o().setFromObject(e).getSize(new J);return Math.max(t.x,t.y,t.z)}var cq=class{byId=new Map;nextId=1;constructor(e,t){this.registry=e,this.canvas=t}add(e){let t=e.id??`object-${this.nextId++}`;this.byId.get(t)?.remove();let n=new oq(e,t,this.canvas()),r=this.registry();return n.bind(()=>{this.byId.delete(t),r.remove(n)}),this.byId.set(t,n),r.add(n),n}get(e){return this.byId.get(e)}all(){return[...this.byId.values()]}clear(){for(let e of[...this.byId.values()])e.remove()}};function lq(e,t,n,r){let i=rW(e,n,r),a=rW(t,n,r);return!i||!a?null:aW([a[0]-i[0],a[1]-i[1],a[2]-i[2]])}function uq(e,t,n,r){let i=lq(e,t,n,r);return i&&Math.hypot(...i)}function dq(e,t,n,r){let i=e.orientation?xS(e.orientation,r,e.nutPrec).toArray():[0,0,0,1],{latitude:a,longitude:o,distance:s}=zF([n[0],n[1],n[2]],[t[0],t[1],t[2]],i);return s>0?{lon:o,lat:a}:null}function fq(e,t,n){let r=t.getBody(e),i=t.getBody($_);if(!r||!i||r===i||!r.orientation&&!t.bodies.orientationRead.has(e))return null;let a=tW(r,t,n),o=tW(i,t,n);return a&&o&&dq(r,a,o,n)}var pq=1024,mq=Math.PI*(3-Math.sqrt(5));function hq(e,t,n){let r=Math.hypot(...t.centre),i=Math.asin(Math.min(t.radiusKm/r,1));if(!(i>0))return 1;let a=t.centre.map(e=>e/r),o=e=>e[0]*a[0]+e[1]*a[1]+e[2]*a[2],s=n.filter(({centre:t,radiusKm:n})=>{let r=o(t),a=Math.sqrt(Math.max(Math.hypot(...t)**2-r**2,0));return r>-(e+n)&&a<e+n+2*i*(r+e)});if(s.length===0)return 1;let[c,l]=kG(t.centre),u=0;for(let t=0;t<pq;t++){let n=Math.sqrt((t+.5)/pq),r=e*n*Math.cos(t*mq),d=e*n*Math.sin(t*mq),f=e*Math.sqrt(1-n*n),p=1;for(let{centre:e,radiusKm:t}of s){let n=[e[0]-r*c[0]-d*l[0]-f*a[0],e[1]-r*c[1]-d*l[1]-f*a[1],e[2]-r*c[2]-d*l[2]-f*a[2]],s=Math.hypot(...n),u=Math.acos(Math.max(-1,Math.min(1,o(n)/s)));if(p*=Rw(i,Math.asin(Math.min(t/s,1)),u),p===0)break}u+=p}return u/pq}var gq=class{enabled;apply;constructor(e,t){this.enabled=e,this.apply=t}enable(){this.set(!0)}disable(){this.set(!1)}isEnabled(){return this.enabled}set(e){this.enabled!==e&&(this.enabled=e,this.apply?.(e))}};function _q(e,t){return e??t??!0}var vq=1400,yq=class{enabled;element=document.createElement(`div`);timer;constructor(e,t){this.enabled=t,this.element.className=`sm-cooperative-hint`,this.element.setAttribute(`aria-hidden`,`true`),e.append(this.element)}isEnabled(){return this.enabled}setEnabled(e){this.enabled=e,e||this.hide()}allowsWheel(e){if(!this.enabled||e.ctrlKey||e.metaKey)return!0;let{cooperative_wheel:t,cooperative_wheel_mac:n}=i().messages;return this.show(bq()?n():t()),!1}allowsTouchDrag(e){return!this.enabled||e>1?!0:(this.show(i().messages.cooperative_touch()),!1)}dispose(){clearTimeout(this.timer),this.element.remove()}show(e){this.element.textContent=e,this.element.classList.add(`sm-cooperative-hint--shown`),clearTimeout(this.timer),this.timer=setTimeout(()=>this.hide(),vq)}hide(){clearTimeout(this.timer),this.element.classList.remove(`sm-cooperative-hint--shown`)}};function bq(){return/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent)}var xq={[G.BARYCENTER]:`barycenter`,[G.LAGRANGE_POINT]:`lagrange-point`,[G.STAR]:`star`,[G.PLANET]:`planet`,[G.DWARF_PLANET]:`dwarf-planet`,[G.MOON]:`moon`,[G.ASTEROID]:`asteroid`,[G.ASTEROID_INNER]:`asteroid`,[G.ASTEROID_MAIN_BELT]:`asteroid`,[G.ASTEROID_TROJAN]:`asteroid`,[G.ASTEROID_CENTAUR]:`asteroid`,[G.ASTEROID_TNO]:`asteroid`,[G.COMET]:`comet`,[G.SPACECRAFT]:`spacecraft`,[G.DEBRIS]:`debris`,[G.UNDOCUMENTED]:`unknown`,[G.SURFACE_FEATURE]:`surface-feature`},Sq={[G.ASTEROID_INNER]:`inner`,[G.ASTEROID_MAIN_BELT]:`main-belt`,[G.ASTEROID_TROJAN]:`trojan`,[G.ASTEROID_CENTAUR]:`centaur`,[G.ASTEROID_TNO]:`tno`};function Cq(e){let{id:t,name:n,objectType:r,parentId:i,radiusKm:a}=e.data,o={id:t,name:n,type:xq[r],parentId:i,radiusKm:Number.isFinite(a)&&a>0?a:null,placed:e.position!==null},s=Sq[r];return s&&(o.orbitClass=s),o}var wq=[`top-left`,`top-right`,`bottom-left`,`bottom-right`],Tq=class{corners=new Map;added=new Map;constructor(e,t){this.map=e,this.root=t}add(e,t){if(this.added.has(e))return;let n=e.onAdd(this.map);this.added.set(e,n),this.corner(t??e.getDefaultPosition?.()??`top-right`).append(n)}remove(e){let t=this.added.get(e);t&&(this.added.delete(e),e.onRemove?.(this.map),t.remove())}clear(){for(let e of[...this.added.keys()])this.remove(e);for(let e of this.corners.values())e.remove();this.corners.clear()}corner(e){let t=this.corners.get(e);return t||(t=document.createElement(`div`),t.className=`sm-ctrl sm-ctrl--${e}`,this.corners.set(e,t),this.root.append(...wq.map(e=>this.corners.get(e)).filter(e=>e!==void 0)),t)}},Eq=[(e,t)=>e.setReducedMotion(t.resolvedReducedMotion),(e,t)=>e.setImmersive(t.viewMode===`immersive`),(e,t)=>e.setHaloDebugVisible(t.showHaloDebug),(e,t)=>{t.atmosphereCalibration,e.applyRenderTier()}],Dq=.05,Oq=1.15,kq=2e3,Aq=4e3,jq=new WeakMap,Mq=new WeakMap,Nq=class{ctx=new iF;clock;initialView;#e=Ge(null);get renderer(){return Vt(this.#e)}set renderer(e){Ke(this.#e,e)}#t=Ge(!1);get webglError(){return Vt(this.#t)}set webglError(e){Ke(this.#t,e,!0)}#n=Ge(!1);get contextLost(){return Vt(this.#n)}set contextLost(e){Ke(this.#n,e,!0)}#r=Ge();get focusedBody(){return Vt(this.#r)}set focusedBody(e){Ke(this.#r,e)}attribution=null;objects=new cq(()=>this.requireRenderer().extensions,()=>this.requireCanvas());dragRotate;scrollZoom;keyboard;bodySelect;featureSelect;cooperativeGestures;container=null;canvas=null;labelLayer=null;stopWatching=null;controls=null;lostPanelTimer;cooperative=null;limits={};initialFocusPending=!0;pendingFocusId=null;opening=null;navigation=0;retireCameraHold=null;listeners={focuschange:new Set,camera:new Set,featureselect:new Set,userpromoted:new Set,contextlost:new Set,contextrestored:new Set,clock:new Set,loading:new Set,progress:new Set,error:new Set,datastale:new Set,notice:new Set,noticedismiss:new Set,layerschange:new Set,frame:new Set};constructor(e={}){e.settings&&ew(e.settings),this.clock=new oF(Ag(e.date??new Date),e.live??e.date===void 0);let t=e.view??{};this.initialView={id:t.body??WF,latitude:t.lat??45,longitude:t.lon??0,zoom:t.distanceKm===void 0?15:Q(t.distanceKm)};let n=t=>new gq(_q(e.interactions?.[t],e.interactive),()=>this.applyGestures());this.dragRotate=n(`dragRotate`),this.scrollZoom=n(`scrollZoom`),this.keyboard=n(`keyboard`),this.bodySelect=n(`bodySelect`),this.featureSelect=n(`featureSelect`),this.cooperativeGestures=new gq(e.cooperativeGestures??!1,()=>this.applyGestures()),e.limits&&(this.limits={...e.limits}),this.ctx.layers=new ly(e.layers),this.ctx.layers.onChange=()=>this.onLayerChange(),this.ctx.onDataStale=()=>this.emit(`datastale`),dG()}on(e,t){return this.listeners[e].add(t),()=>this.listeners[e].delete(t)}once(e,t){let n=(...e)=>{r(),t(...e)};Mq.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners[e];n.delete(t);for(let e of n)Mq.get(e)===t&&n.delete(e)}emit(e,...t){for(let n of this.listeners[e])n(...t)}getBody(e){let t=this.ctx.getBody(e);return t&&Cq(t)}getFocusedBody(){let e=this.focusedBody;if(!e)return;let t=mn(e)?this.ctx.getBody(e.featureAnchor.hostId):e;return t&&Cq(t)}getChildren(e){return[...this.ctx.bodies.getChildren(e)??[]]}get placedJd(){let e=this.renderer?.placedJd;return e===void 0||Number.isNaN(e)?this.clock.jd:e}distanceKm(e,t){return uq(e,t,this.ctx,this.placedJd)}offsetKm(e,t){return lq(e,t,this.ctx,this.placedJd)}getSubsolarPoint(e){return fq(e,this.ctx,this.placedJd)}tilesEnabled(){return tP()}async hasTiles(e){let t=(await tS(e,!1).catch(()=>null))?.global;return!t?.map_texture_available||GA(t)===null?!1:nP(o([t.texture&&{...t.texture,id:e},...t.alternates??[]])?.tiles)&&!this.renderer?.tilesFailed(e)}load(e=this.initialView.id){return this.ctx.load(jg(this.clock.jd),e)}open(e=this.initialView.id){return this.opening??=this.openOnce(e)}async openOnce(e){let t=this.load(e);t.catch(()=>{});let n=!0,r=new Promise(t=>{let r=()=>{n&&(this.renderer&&!this.ctx.loading&&this.ctx.getBody(e)?t():document.hidden?setTimeout(r,100):requestAnimationFrame(r))};r()});try{await Promise.race([t,r])}finally{n=!1}}applyInitialView(){let{id:e,latitude:t,longitude:n,zoom:r}=this.initialView;this.focusedBody||!this.ctx.getBody(e)||this.renderer?.snapToBody(e,t,n,r)}mount(e){if(this.container)throw Error(`SpaceMap is already mounted`);this.container=e,e.classList.add(`sm-map`),jq.set(e,(jq.get(e)??0)+1),this.controls=new Tq(this,e);let t=document.createElement(`canvas`);t.className=`sm-map__canvas`,t.tabIndex=0,t.setAttribute(`role`,`application`),t.setAttribute(`aria-label`,i().messages.scene_canvas_label());let n=document.createElement(`div`);n.className=`scene-overlay`,e.append(t,n),this.canvas=t,this.labelLayer=n,this.cooperative=new yq(e,this.cooperativeGestures.isEnabled()),t.addEventListener(`keydown`,this.onKeyDown),t.addEventListener(`touchmove`,this.onTouchMove,{passive:!0}),e.addEventListener(`wheel`,this.onWheelCapture,{capture:!0,passive:!0}),t.addEventListener(`webglcontextlost`,this.onContextLost,!1),t.addEventListener(`webglcontextrestored`,this.onContextRestored,!1),document.addEventListener(`visibilitychange`,this.onVisibility);let r;try{r=new PW(t,n,this.ctx,this.clock,this.initialView,this.callbacks())}catch(e){console.error(`[scene] renderer init failed:`,e),this.webglError=!0;return}this.renderer=r,this.applyGestures(),this.applyLimits(),this.pendingFocusId!==null&&(r.focusOnBody(this.pendingFocusId),this.pendingFocusId=null);let a=new ResizeObserver(()=>r.resize(t.clientWidth,t.clientHeight));a.observe(t);let o=st(()=>this.watch(r));this.stopWatching=()=>{a.disconnect(),o()}}addControl(e,t){if(!this.controls)throw Error(`spacemap: the map is not mounted`);return this.controls.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.unmount()}unmount(){let{container:e,canvas:t}=this;if(!e||!t)return;this.controls?.clear(),this.controls=null,this.stopWatching?.(),this.stopWatching=null,clearTimeout(this.lostPanelTimer),t.removeEventListener(`keydown`,this.onKeyDown),t.removeEventListener(`touchmove`,this.onTouchMove),e.removeEventListener(`wheel`,this.onWheelCapture,{capture:!0}),this.cooperative?.dispose(),this.cooperative=null,t.removeEventListener(`webglcontextlost`,this.onContextLost),t.removeEventListener(`webglcontextrestored`,this.onContextRestored),document.removeEventListener(`visibilitychange`,this.onVisibility),this.retireCameraHold?.(),this.retireCameraHold=null,this.renderer?.dispose(),this.renderer=null,t.remove(),this.labelLayer?.remove();let n=(jq.get(e)??1)-1;jq.set(e,n),n===0&&e.classList.remove(`sm-map`),this.container=this.canvas=this.labelLayer=null}watch(e){at(()=>{this.ctx.bodies.minorBodyVersion,e.rebuildMinorPointClouds()});let t=$C();for(let n of Eq)at(()=>n(e,t));let n=this.clock;at(()=>{let{jd:e,playing:t,timeScale:r,direction:i,live:a}=n;this.listeners.clock.size!==0&&this.emit(`clock`,{jd:e,date:jg(e),playing:t,timeScale:r,direction:i,live:a})}),at(()=>{let e=this.ctx.loading,t=IW.bootPending;this.emit(`loading`,e||t)}),at(()=>this.emit(`progress`,Av.value)),at(()=>{let e=this.ctx.error;e!==null&&this.emit(`error`,e)}),at(()=>{IW.progress===null?e.isContextLost()||e.resume():e.pause()})}applySettings(){let e=this.renderer;if(!e)return;let t=$C();for(let n of Eq)n(e,t)}callbacks(){return{notices:{notify:e=>this.emit(`notice`,e),dismiss:e=>this.emit(`noticedismiss`,e)},onFocusChange:e=>{let t=this.initialFocusPending;this.initialFocusPending=!1,this.focusedBody=e;let n=e!==void 0&&mn(e);this.emit(`focuschange`,{body:this.getFocusedBody(),initial:t,feature:n})},onFrame:(e,t)=>{this.listeners.frame.size>0&&this.emit(`frame`,{jd:e,dtMs:t})},onCameraPosition:(e,t,n)=>{let r=this.focusedBody?.data.id;r!==void 0&&this.emit(`camera`,{body:r,lat:e,lon:t,distanceKm:xg(n)})},onUserPromotedChange:e=>this.emit(`userpromoted`,e),onFeatureSelect:(e,t,n,r,i)=>this.emit(`featureselect`,{bodyId:e,featureId:t,lat:n,lon:r,diameterM:i})}}onKeyDown=e=>{if(!this.keyboard.isEnabled()||e.ctrlKey||e.metaKey||e.altKey)return;let t=(e.shiftKey?4:1)*Dq,n=0,r=0,i=1;switch(e.key){case`ArrowLeft`:n=t;break;case`ArrowRight`:n=-t;break;case`ArrowUp`:r=t;break;case`ArrowDown`:r=-t;break;case`+`:case`=`:i=Oq;break;case`-`:case`_`:i=1/Oq;break;default:return}e.preventDefault(),this.renderer?.nudgeCamera(n,r,i)};onContextLost=e=>{e.preventDefault(),console.warn(`[scene] WebGL context lost`),this.renderer?.pause(),clearTimeout(this.lostPanelTimer),this.lostPanelTimer=setTimeout(()=>{this.contextLost=!0,this.emit(`contextlost`)},kq)};onContextRestored=()=>{console.warn(`[scene] WebGL context restored`),clearTimeout(this.lostPanelTimer),this.contextLost=!1,this.renderer?.handleContextRestored(),this.renderer?.recoverWorkersIfDead(Aq),this.emit(`contextrestored`)};onVisibility=()=>{document.visibilityState===`visible`&&(this.renderer?.isContextLost()||this.renderer?.recoverWorkersIfDead())};async flyTo(e){let t=this.targetBody(e);if(e.feature)return this.toFeature(t,e.feature,`frame`);let n=await this.goTo(t,{clock:`keep`,view:()=>({distance:this.framing(e,t),latitude:e.lat,longitude:e.lon})});if(n.outcome===`failed`)throw n.error;return this.settled(n.flightMs)}async goTo(e,t={}){let n=++this.navigation,r=()=>n!==this.navigation,i={outcome:`superseded`,flightMs:0},a=()=>sS(e).catch(t=>(console.warn(`[map] goTo ${e}: no coverage to read, the clock stays:`,t),[])),o=this.cameraDistance(),s,c=null,l=()=>{};if(t.clock!==`keep`){if(c=await a(),r())return i;let e=this.clock.jd,t=cS(c,e);t!==null&&t!==e&&(l=this.renderer?.holdDate()??l,this.clock.jumpTo(t),s={from:e,to:t})}let u,d,f=e=>{d??=e},p=()=>(console.warn(`[map] goTo ${e}: its data did not load:`,d),{outcome:`failed`,error:d,clockMoved:s,flightMs:0});try{await this.open(e).catch(()=>{});let t=jg(this.clock.jd);await this.ctx.ready(t).catch(f),await this.ctx.ensureBody(e,t).catch(f),u=await this.rendering()}finally{l()}if(r())return i;let m=this.ctx.getBody(e);if(!m||!u)return d===void 0?(console.warn(`[map] goTo ${e}: not an object of this map`),{outcome:`missing`,clockMoved:s,flightMs:0}):p();let h=u.placeOf(m)!==null;if(!h&&d!==void 0){if(c??=await a(),r())return i;if(cS(c,this.clock.jd)===this.clock.jd)return p()}if(t.commit?.(m),h){let n=t.view?.(m)??{},r=n.distance??(m.data.radiusKm>0?this.framing({},e):o),i=0;switch(t.camera??`fly`){case`fly`:i=u.focusOnBody(e,r,n.latitude,n.longitude);break;case`cut`:u.snapToBody(e,n.latitude??45,n.longitude??0,r);break;case`pan`:i=u.focusOnBody(e);break;case`none`:}return{outcome:`placed`,body:m,clockMoved:s,flightMs:i}}if(u.focusOnBody(e),c??=await a(),c.length>0)return t.clock!==`keep`&&console.error(`[map] goTo ${e}: no place at jd ${this.clock.jd} (${m.unplaced}), inside its coverage`),{outcome:`unplaced`,body:m,clockMoved:s,flightMs:0};let g=this.placedAncestor(m,u);if(!g)return{outcome:`nowhere`,body:m,clockMoved:s,flightMs:0};let _=u.panCameraTo(g,this.framing({},g.data.id));return{outcome:`host`,body:m,host:g,clockMoved:s,flightMs:_}}placedAncestor(e,t){let n=new Set([e.data.id]),r=this.ctx.getBody(e.data.parentId);for(;r&&!n.has(r.data.id);){if(t.placeOf(r))return r;n.add(r.data.id),r=this.ctx.getBody(r.data.parentId)}return null}rendering(){return new Promise(e=>{let t=()=>{this.renderer?e(this.renderer):this.webglError||this.ctx.error?e(null):document.hidden?setTimeout(t,100):requestAnimationFrame(t)};t()})}panTo(e){return this.toFeature(this.targetBody(e),e.feature,`pan`)}jumpTo(e){let t=this.targetBody(e);if(e.facing!==void 0)return this.snapToBodyFacing(t,e.facing,e.elevationDeg??0,this.framing(e,t)),this;if(e.feature){let{featureId:n,lat:r,lon:i,diameterM:a}=e.feature;return this.focusOnFeature(t,n,r,i,a,null,`snap`),this}let n=this.getCamera();return this.snapToBody(t,e.lat??n?.lat??45,e.lon??n?.lon??0,this.framing(e,t)),this}getCamera(){let e=this.renderer,t=this.focusedBody?.data.id;if(!e||t===void 0)return null;let{latitude:n,longitude:r,distance:i}=e.getCameraState();return{body:t,lat:n,lon:r,distanceKm:xg(i)}}setLayerVisible(e,t){return this.ctx.layers.setVisible(e,t),this}isLayerVisible(e){return this.ctx.layers.isVisible(e)}getLayers(){return[...ny]}onLayerChange(){for(let e of this.ctx.bodies.spacecraftByParent.keys())this.ctx.bodies.dirtySpacecraftGroups.add(e);this.ctx.bodies.minorBodyVersion++,this.emit(`layerschange`,ny.filter(e=>this.ctx.layers.isVisible(e)))}setLimits(e){return this.limits={...e},this.applyLimits(),this}getLimits(){return{...this.limits}}applyLimits(){let e=this.limits,t={};e.minDistanceKm!==void 0&&(t.minDistance=Q(e.minDistanceKm)),e.maxDistanceKm!==void 0&&(t.maxDistance=Q(e.maxDistanceKm)),e.minLat!==void 0&&(t.minLat=e.minLat),e.maxLat!==void 0&&(t.maxLat=e.maxLat),e.minLon!==void 0&&(t.minLon=e.minLon),e.maxLon!==void 0&&(t.maxLon=e.maxLon);let n=Object.keys(t).length>0;this.renderer?.setCameraLimits(n?t:null,e.bodies??null)}applyGestures(){let e=this.cooperativeGestures.isEnabled();this.cooperative?.setEnabled(e);let t=this.renderer;t&&(t.setDragEnabled(this.dragRotate.isEnabled()),t.setZoomEnabled(this.scrollZoom.isEnabled()),t.setBodySelectEnabled(this.bodySelect.isEnabled()),t.setFeatureSelectEnabled(this.featureSelect.isEnabled()),t.setCooperativeTouch(e))}onWheelCapture=e=>{this.scrollZoom.isEnabled()&&this.cooperative&&!this.cooperative.allowsWheel(e)&&e.stopPropagation()};onTouchMove=e=>{this.cooperative?.allowsTouchDrag(e.touches.length)};toFeature(e,t,n){let{featureId:r,lat:i,lon:a,diameterM:o}=t;return this.settled(this.focusOnFeature(e,r,i,a,o,null,n))}settled(e){return new Promise(t=>{setTimeout(()=>requestAnimationFrame(()=>t()),e)})}targetBody(e){let t=e.body??this.focusedBody?.data.id;if(t===void 0)throw Error(`spacemap: no body to move to, and none focused`);return t}framing(e,t){if(e.distanceKm!==void 0)return Q(e.distanceKm);let n=this.ctx.getBody(t);return n&&n.data.radiusKm>0?PU(n)*5:this.cameraDistance()}cameraDistance(){return this.renderer?.getCameraState().distance??15}focusOnBody(e,t,n,r){return this.renderer?this.renderer.focusOnBody(e,t,n,r):(this.pendingFocusId=e,0)}snapToBody(e,t,n,r){this.renderer?.snapToBody(e,t,n,r)}snapToBodyFacing(e,t,n,r){this.renderer?.snapToBodyFacing(e,t,n,r)}focusOnFeature(e,t,n,r,i,a,o=`frame`,s=null){let c=this.ctx.getBody(e);if(!c)return 0;let l=Q(i*4/1e3),u=Q(.02),d=Q(bn(c.data)*5),f=Math.min(Math.max(l,u),d),p={hostId:e,featureId:t,lat:n,lon:r,diameterM:i};return this.renderer?.focusOnFeature(p,a,f,o,s)??0}setFocusTarget(e,t){this.renderer?.setFocusTarget(e,t)}getPose(){let e=this.renderer,t=this.focusedBody;if(!e||!t)return null;let n=t.data.id;return{position:{body:n,offsetKm:aW(e.cameraOffsetFromFocus())},target:{body:n}}}holdCamera(){let e=this.renderer;if(!e)throw Error(`SpaceMap is not mounted`);this.retireCameraHold?.(),e.holdCamera();let t=!0,n=()=>{t=!1};return this.retireCameraHold=n,{get held(){return t},set:n=>{t&&e.setHeldPose(n)},release:()=>{t&&(n(),this.retireCameraHold=null,e.releaseCamera())}}}addMarker(e){return this.track(new hG(e,this.requireCanvas()))}addPolyline(e){return this.track(new OG(e))}addPolygon(e){return this.track(new VG({fill:e.color??`#ffffff`,...e}))}addCircle(e){return this.track(new HG(e))}addLabel(e){return this.track(new UG(e,this.requireCanvas()))}addIcon(e){return this.track(new WG(e,this.requireCanvas()))}addSurfacePolyline(e){return this.track(new aq(e))}addSurfacePolygon(e){return this.track(new aq({fill:e.color??`#ffffff`,...e,closed:!0}))}addSurfaceCircle(e){return this.addSurfacePolygon({...e,points:QK(e.center,this.capRadiusDeg(e),e.steps)})}clearDrawings(){this.renderer?.extensions.clear(e=>e instanceof oq)}setBodyAppearance(e,t){return this.requireRenderer().setBodyAppearance(e,t),this}setPinnedBodies(e){return this.requireRenderer().setPinnedBodies(e),this}capRadiusDeg(e){if(e.radiusDeg!==void 0)return e.radiusDeg;let t=this.getBody(e.body)?.radiusKm;return e.radiusKm!==void 0&&t?e.radiusKm/t*(180/Math.PI):1}track(e){let t=this.requireRenderer();return e.bind(()=>t.extensions.remove(e)),t.extensions.add(e),e}requireCanvas(){let e=this.canvas;if(!e)throw Error(`SpaceMap is not mounted`);return e}requireRenderer(){let e=this.renderer;if(!e)throw Error(`SpaceMap is not mounted`);return e}setNorthReference(e){this.renderer?.setNorthReference(e)}setUserLocation(e,t){this.renderer?.setUserLocation(e,t)}clearUserPromoted(){this.renderer?.clearUserPromoted()}setSelectedFeature(e){this.renderer?.setSelectedFeature(e)}setTravelPath(e,t=[],n=[],r=[]){this.renderer?.setTravelPath(e,t,n,r)}setOrbitPreview(e,t){this.renderer?.setOrbitPreview(e,t)}setTravelHover(e){this.renderer?.setTravelHover(e)}focusOnPathPoint(e,t){this.renderer?.focusOnPathPoint(e,t)}trackPathPoint(e,t){this.renderer?.trackPathPoint(e,t)}setCovered(e){this.renderer?.setCovered(e)}},Pq=`http://www.w3.org/2000/svg`;function Fq(e){return{id:e.id,label:e.label,kind:e.kind,visible:e.visible,credit:e.credit}}function Iq(e){return{organisation:e.organisation,source:e.source,attribution:e.attribution}}function Lq(e,t){let n=document.createElementNS(Pq,`path`);return n.setAttribute(`d`,e),n.setAttribute(`class`,t),n}function Rq(e,t=30){return{kind:`vector`,id:`graticule`,label:e,visible:!1,render(e,n){for(let r of eq(t)){let t=qK(r,e,{stepDeg:2});t&&n.append(Lq(t,`sm-flat__graticule`))}if(e.projection.azimuthal){let t=e.toScreen(0,0),r=e.toScreen(e.projection.extent.maxX,0),i=document.createElementNS(Pq,`circle`);i.setAttribute(`cx`,String(t[0])),i.setAttribute(`cy`,String(t[1])),i.setAttribute(`r`,String(Math.abs(r[0]-t[0]))),i.setAttribute(`class`,`sm-flat__frame`),n.append(i)}else{let t=XK(e);t&&n.append(Lq(t,`sm-flat__frame`))}}}}var zq=120;function Bq(e,t){let n=[];return{kind:`vector`,id:`nomenclature`,label:t,visible:!1,credit:{organisation:`IAU`,source:`https://planetarynames.wr.usgs.gov/`},async prepare(){n.length||(n=[...await NT(e)].sort((e,t)=>t.diameterM-e.diameterM).slice(0,zq))},render(e,t){let r=e.repeatShifts;for(let i of n){let n=e.project(i.lon,i.lat);if(!(!n||n[1]<0||n[1]>e.height))for(let a of r){let r=n[0]+a;if(r<0||r>e.width)continue;let o=document.createElementNS(Pq,`circle`);o.setAttribute(`cx`,r.toFixed(1)),o.setAttribute(`cy`,n[1].toFixed(1)),o.setAttribute(`r`,`1.6`),o.setAttribute(`class`,`sm-flat__feature-dot`);let s=document.createElementNS(Pq,`text`);s.setAttribute(`x`,(r+4).toFixed(1)),s.setAttribute(`y`,(n[1]+3).toFixed(1)),s.setAttribute(`class`,`sm-flat__feature-label`),s.textContent=i.name,t.append(o,s)}}}}}function Vq(e,t){e.setAttribute(`fill`,t.fill??`none`),t.fill&&t.fillOpacity!==void 0&&e.setAttribute(`fill-opacity`,String(t.fillOpacity)),e.setAttribute(`stroke`,t.color??`#ffffff`),e.setAttribute(`stroke-width`,String(t.widthPx??2)),e.setAttribute(`stroke-linejoin`,`round`),e.setAttribute(`stroke-linecap`,`round`),t.opacity!==void 0&&e.setAttribute(`opacity`,String(t.opacity)),t.dash&&e.setAttribute(`stroke-dasharray`,t.dash),t.className&&e.setAttribute(`class`,t.className),e.style.pointerEvents=t.interactive?`auto`:`none`,t.ariaLabel&&(e.setAttribute(`role`,`img`),e.setAttribute(`aria-label`,t.ariaLabel))}function Hq(e,t){t.onclick&&e.addEventListener(`click`,t.onclick),t.onpointerenter&&e.addEventListener(`pointerenter`,t.onpointerenter),t.onpointerleave&&e.addEventListener(`pointerleave`,t.onpointerleave)}var Uq=class{node;area;edge;points;visible=!0;constructor(e,t,n,r,i,a){this.closed=n,this.interpolate=r,this.onRemove=i,this.onChange=a,this.points=e,this.node=document.createElementNS(Pq,`g`),Vq(this.node,t),Hq(this.node,t),this.area=n?document.createElementNS(Pq,`path`):null,this.area?.setAttribute(`stroke`,`none`),this.edge=document.createElementNS(Pq,`path`),this.edge.setAttribute(`fill`,`none`),this.area&&this.node.append(this.area),this.node.append(this.edge)}redraw(e){if(!this.visible)return;let t={closed:this.closed,interpolate:this.interpolate};this.edge.setAttribute(`d`,qK(this.points,e,t)),this.area?.setAttribute(`d`,JK(this.points,e,t))}setPoints(e){this.points=e,this.onChange()}setVisible(e){this.visible=e,this.node.style.display=e?``:`none`,this.onChange()}detach(){this.node.remove()}remove(){this.onRemove(this)}},Wq=class{element;at;visible=!0;align;constructor(e,t,n){this.onRemove=t,this.onChange=n,this.at=e.at,this.align=e.align??[.5,.5],this.element=e.element??document.createElement(`div`),e.element||(this.element.className=`sm-flat__marker-dot`),e.className&&this.element.classList.add(e.className),this.element.style.position=`absolute`,this.element.style.left=`0`,this.element.style.top=`0`,this.element.style.pointerEvents=e.interactive?`auto`:`none`}redraw(e){let t=this.visible?e.project(this.at.lon,this.at.lat):null;if(this.element.style.display=t?``:`none`,!t)return;let n=e.repeatShifts.find(n=>t[0]+n>=0&&t[0]+n<=e.width)??0;this.element.style.transform=`translate(${t[0]+n}px, ${t[1]}px) translate(${-this.align[0]*100}%, ${-this.align[1]*100}%)`}setPosition(e){this.at=e,this.onChange()}setVisible(e){this.visible=e,this.onChange()}detach(){this.element.remove()}remove(){this.onRemove(this)}},Gq=class{drawings=new Set;constructor(e,t,n=()=>{},r=null){this.shapes=e,this.markers=t,this.onChange=n,this.radiusKm=r}setBodyRadiusKm(e){this.radiusKm=e}track(e,t){return this.drawings.add(e),t instanceof HTMLElement?this.markers.append(t):this.shapes.append(t),e}drop=e=>{this.drawings.delete(e)&&e.detach()};addPolyline(e){let t=new Uq(e.points,e,e.closed??!1,e.interpolate??`linear`,this.drop,this.onChange);return this.track(t,t.node)}addPolygon(e){let t=new Uq(e.points,{fill:`rgb(255 255 255 / 25%)`,...e},!0,e.interpolate??`linear`,this.drop,this.onChange);return this.track(t,t.node)}addBox(e){let t=new Uq(ZK(e.latMin,e.latMax,e.lonMin,e.lonSpan),{fill:`rgb(255 255 255 / 15%)`,...e},!0,`linear`,this.drop,this.onChange);return this.track(t,t.node)}addCircle(e){let t=this.circleRadiusDeg(e),n=new Uq(QK(e.center,t),{fill:`rgb(255 255 255 / 20%)`,...e},!0,`linear`,this.drop,this.onChange);return this.track(n,n.node)}circleRadiusDeg(e){return e.radiusDeg===void 0?e.radiusKm!==void 0&&this.radiusKm?e.radiusKm/this.radiusKm*(180/Math.PI):1:e.radiusDeg}addMarker(e){let t=new Wq(e,this.drop,this.onChange);return this.track(t,t.element)}redraw(e){for(let t of this.drawings)t.redraw(e)}clear(){for(let e of this.drawings)e.detach();this.drawings.clear()}},Kq=Math.PI/180,qq=1.25,Jq=17,Yq=.15,Xq=.75;function Zq(e,t,n){if(e===0)return[(t+180)/360,(90-n)/180];let r=e===1?1:-1,i=.5*Math.tan((90-r*n)*Kq/2)/ZT;return[.5+i*Math.cos(t*Kq),.5-r*i*Math.sin(t*Kq)]}function Qq(e,t){return Math.ceil(Math.log2(2*Math.PI/(e*qq*2*t)))}function $q(e,t){return 2*Math.PI/(2*t*2**e)}function eJ(e,t,n){let[r,i]=Zq(0,t,n),a=r-Math.floor(r),o=e.max_level;for(let t of e.patches??[]){if(t.max_level<=o)continue;let e=Math.floor(a*tE(0,t.max_level)),n=Math.floor(i*nE(0,t.max_level));uE([t],t.max_level,e,n)&&(o=t.max_level)}return o}function tJ(e,t,n,r){let[i]=Zq(0,r[0],r[1]),a={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(let[t,r]of n){let[n,o]=Zq(e,t,r);if(e!==0&&(n<0||n>1||o<0||o>1))return null;let s=e===0?n-Math.round(n-i):n;a.minX=Math.min(a.minX,s),a.maxX=Math.max(a.maxX,s),a.minY=Math.min(a.minY,o),a.maxY=Math.max(a.maxY,o)}let o=(a.maxX-a.minX)/(Jq-1),s=(a.maxY-a.minY)/(Jq-1);return a.minX-=o,a.maxX+=o,a.minY-=s,a.maxY+=s,e===0&&(t.north||t.south)&&(a.minX=i-.5,a.maxX=i+.5,t.north&&(a.minY=0),t.south&&(a.maxY=1)),a}function nJ(e,t,n,r,i){let a=tE(e,t)*n,o=nE(e,t)*n,s=t=>{let n=(r.maxX-r.minX)*t,i=(r.maxY-r.minY)*t,s=Math.floor((r.minX-n)*a),c=Math.ceil((r.maxX+n)*a);e===0?c-s>a&&(s=Math.round((r.minX+r.maxX)/2*a-a/2),c=s+a):(s=Math.max(s,0),c=Math.min(c,a));let l=Math.max(Math.floor((r.minY-i)*o),0),u=Math.min(Math.ceil((r.maxY+i)*o),o);return[s,l,c,u]},[c,l,u,d]=s(i),f=s(0);return{chart:e,level:t,x0:c,y0:l,width:Math.max(u-c,1),height:Math.max(d-l,1),inner:[f[0],f[1],f[2]-1,f[3]-1]}}function rJ(e,t,n,r,i){for(let a of[i,0]){let i=nJ(e,t,n,r,a);if(i.width*i.height<=8e6)return i}}function iJ(e,t){let n=tE(0,e.max_level),r=nE(0,e.max_level),i=(e.y[1]+1)/r;if(e.y[0]/r>t.maxY||i<t.minY)return!1;let a=e.x[0]/n;a-=Math.round(a-(t.minX+t.maxX)/2);let o=a+(e.x[1]+1-e.x[0])/n;return a<=t.maxX&&o>=t.minX}function aJ(e,t,n,r=!0){let i=r?Yq:0,a=t.place(.5,.5);if(!a||!(t.step>0))return[];let o=[];for(let e=0;e<Jq;e++)for(let n=0;n<Jq;n++){let r=t.place(n/(Jq-1),e/(Jq-1));r&&o.push(r)}let s=tJ(0,t,o,a),c=Qq(t.step,e.tile_size),l=[],u=e.max_level;for(let t of e.patches??[])t.max_level>u&&iJ(t,s)&&(u=t.max_level);for(let t=Math.min(c,u);t>e.max_level;t--){let n=rJ(0,t,e.tile_size,s,i);if(n){l.push(n);break}}let d=a[1]>=0?1:2,f=tJ(d,t,o,a);for(let t=Math.min(c,e.max_level);t>=n;t--){let n=rJ(0,t,e.tile_size,s,i),r=f&&t>=1?rJ(d,t,e.tile_size,f,i):void 0,a=n?n.width*n.height:1/0,o=r&&r.width*r.height<=a*Xq?r:n??r;if(o){l.push(o);break}}return l}function oJ(e,t){let n=t.tile_size,r=tE(e.chart,e.level),i=nE(e.chart,e.level),a=[],o=Math.min(Math.floor((e.y0+e.height-1)/n),i-1),s=Math.floor((e.x0+e.width-1)/n);for(let i=Math.max(Math.floor(e.y0/n),0);i<=o;i++)for(let o=Math.floor(e.x0/n);o<=s;o++){if(e.chart!==0&&(o<0||o>=r))continue;let s=(o%r+r)%r,c=e.level>t.max_level?uE(t.patches,e.level,s,i):void 0;e.level>t.max_level&&!c||a.push({cap:JT[e.chart],level:e.level,x:s,y:i,dx:o*n-e.x0,dy:i*n-e.y0,patch:c})}let c=e.width/2-n/2,l=e.height/2-n/2,u=e=>Math.hypot(e.dx-c,e.dy-l);return a.sort((e,t)=>u(e)-u(t))}function sJ(e,t,n){if(e.chart!==t.chart||e.level!==t.level)return!1;let r=0;if(t.chart===0){let i=tE(0,t.level)*n;r=i*Math.round((t.inner[0]-e.x0)/i)}return e.x0+r<=t.inner[0]&&e.x0+r+e.width>t.inner[2]&&e.y0<=t.inner[1]&&e.y0+e.height>t.inner[3]}var cJ=8;function lJ(e){return tE(e.chart,e.level)*e.tileSize}function uJ(e){let t=`width`in e?e.width:e.codedWidth,n=`height`in e?e.height:e.codedHeight;return typeof t!=`number`||typeof n!=`number`||!t||!n?null:[t,n]}function dJ(e,t){let[n,r]=uJ(e)??[t,t/2],i=Math.max(2,Math.min(n,Math.round(t))),a=Math.max(1,Math.round(i*r/n)),o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`,{willReadFrequently:!0});if(!s)return null;s.imageSmoothingEnabled=!0,s.imageSmoothingQuality=`high`,s.drawImage(e,0,0,i,a);try{let{data:e}=s.getImageData(0,0,i,a);return{width:i,height:a,data:e}}catch{return null}}var fJ=class{width;height;refU;refV;u;v;inside;caps=new Map;constructor(e,t,n){this.width=t,this.height=n;let r=t*n;this.u=new Float32Array(r),this.v=new Float32Array(r),this.inside=new Uint8Array(r);let{projection:i}=e,a=i.inverse(e.view.centerX,e.view.centerY);[this.refU,this.refV]=a?Zq(0,a[0],a[1]):[.5,.5];let o=1/e.scale,s=e.view.centerX-e.width/2*o,c=e.view.centerY+e.height/2*o;for(let r=0;r<n;r++){let n=c-(r+.5)*o,a=r*t;i.rowInverse?this.fillRow(i,a,n,s,o,e):this.walkRow(i,a,n,s,o)}}fillRow(e,t,n,r,i,a){let o=e.rowInverse(n);if(!o)return;let{width:s,refU:c}=this,l=(90-o.lat)/180-this.refV,{minX:u,maxX:d}=e.extent,f=d-u,p=a.repeatsHorizontally;for(let n=0;n<s;n++){let a=r+(n+.5)*i;if(p)a=((a-u)%f+f)%f+u;else if(a<u||a>d)continue;if(a<-o.maxAbsX||a>o.maxAbsX)continue;let s=(a*o.lonPerX+e.centerLon+180)/360-c,m=t+n;this.u[m]=s-Math.round(s),this.v[m]=l,this.inside[m]=1}}walkRow(e,t,n,r,i){let{width:a}=this,o=0,s=a-1;if(e.azimuthal){let t=e.extent.maxX;if(Math.abs(n)>t)return;let c=Math.sqrt(t*t-n*n);o=Math.max(0,Math.ceil((-c-r)/i-.5)),s=Math.min(a-1,Math.floor((c-r)/i-.5))}for(let a=o;a<=s;a++){let o=r+(a+.5)*i,s=e.inverse(o,n);if(!s)continue;let c=t+a,l=(s[0]+180)/360-this.refU;this.u[c]=l-Math.round(l),this.v[c]=(90-s[1])/180-this.refV,this.inside[c]=1}}offsets(e){if(e===0)return{refX:this.refU,refY:this.refV,x:this.u,y:this.v};let t=this.caps.get(e);return t||(t=this.capOffsets(e),this.caps.set(e,t)),t}capOffsets(e){let{u:t,v:n,inside:r,refU:i,refV:a,width:o,height:s}=this,c=e===1?1:-1,[l,u]=Zq(e,i*360-180,90-a*180),d=new Float32Array(t.length),f=new Float32Array(t.length),p=e=>{let r=c>0?a+n[e]:1-a-n[e],o=.5*Math.tan(r*Math.PI/2)/ZT,s=(i+t[e])*2*Math.PI-Math.PI;d[e]=.5+o*Math.cos(s)-l,f[e]=.5-c*o*Math.sin(s)-u},m=pJ(o),h=pJ(s);if(m.length<2||h.length<2){for(let e=0;e<t.length;e++)r[e]&&p(e);return{refX:l,refY:u,x:d,y:f}}for(let e of h)for(let t of m)r[e*o+t]&&p(e*o+t);for(let e=0;e<h.length-1;e++){let t=h[e],n=h[e+1],i=e===h.length-2?n:n-1;for(let e=0;e<m.length-1;e++){let a=m[e],s=m[e+1],c=e===m.length-2?s:s-1,l=t*o+a,u=t*o+s,h=n*o+a,g=n*o+s;if(!(r[l]&&r[u]&&r[h]&&r[g])){for(let e=t;e<=i;e++)for(let t=e*o+a;t<=e*o+c;t++)r[t]&&p(t);continue}for(let e=t;e<=i;e++){let r=(e-t)/(n-t),i=d[l]+r*(d[h]-d[l]),p=f[l]+r*(f[h]-f[l]),m=(d[u]+r*(d[g]-d[u])-i)/(s-a),_=(f[u]+r*(f[g]-f[u])-p)/(s-a),v=e===t||e===n;for(let t=a;t<=c;t++)v&&(t===a||t===s)||(d[e*o+t]=i,f[e*o+t]=p),i+=m,p+=_}}}return{refX:l,refY:u,x:d,y:f}}};function pJ(e){let t=[];for(let n=0;n<e-1;n+=cJ)t.push(n);return t.push(e-1),t}function mJ(e,t,n){let r=n.data;r.fill(0);let{width:i,height:a,u:o,v:s,inside:c,refU:l,refV:u}=e,d=i*a;for(let n of t){let{image:t,opacity:i,blend:a}=n;if(i<=0)continue;let f=t.data,p=t.width,m=t.height,h=a===`add`,g=(n.detail??[]).map(t=>{let n=e.offsets(t.chart),r=lJ(t),i=t.chart===0?r/2:r,a=n.refX*r-t.x0;return t.chart===0&&(a-=r*Math.round((a-t.width/2)/r)),{xs:n.x,ys:n.y,left:a,top:n.refY*i-t.y0,across:r,down:i,width:t.width,height:t.height,data:t.data}});for(let e=0;e<d;e++){if(!c[e])continue;let t=f,n=-1;for(let r=0;r<g.length;r++){let i=g[r],a=i.left+i.xs[e]*i.across;if(!(a>=0&&a<i.width))continue;let o=i.top+i.ys[e]*i.down;if(!(o>=0&&o<i.height))continue;let s=((o|0)*i.width+(a|0))*4;if(i.data[s+3]!==0){t=i.data,n=s;break}}if(n<0){let t=l+o[e];t-=Math.floor(t);let r=Math.floor(t*p),i=Math.floor((u+s[e])*m);r=r<0?r+p:r>=p?r-p:r,i=i<0?0:i>=m?m-1:i,n=(i*p+r)*4}let a=t[n+3]/255*i;if(a<=0)continue;let d=e*4;if(h){r[d]=Math.min(255,r[d]+t[n]*a),r[d+1]=Math.min(255,r[d+1]+t[n+1]*a),r[d+2]=Math.min(255,r[d+2]+t[n+2]*a);continue}let _=r[d+3]/255,v=a+_*(1-a);if(!(v<=0)){if(a>=1)r[d]=t[n],r[d+1]=t[n+1],r[d+2]=t[n+2];else{let e=_*(1-a);r[d]=(t[n]*a+r[d]*e)/v,r[d+1]=(t[n+1]*a+r[d+1]*e)/v,r[d+2]=(t[n+2]*a+r[d+2]*e)/v}r[d+3]=v*255}}}}function hJ(e,t,n){let{minX:r,maxX:i,minY:a,maxY:o}=t.projection.extent,s=t.projection.centerLon*Math.PI/180,[c,l]=t.toScreen(r-s,o),[u,d]=t.toScreen(i-s,a),f=t.repeatsHorizontally?0:t.toScreen(r,o)[0],p=t.repeatsHorizontally?e.canvas.width:t.toScreen(i,o)[0],m=(e,t,n)=>{let r=e.createPattern(t.image,`repeat-x`);if(!r)return;r.setTransform(new DOMMatrix().translateSelf(c,l).scaleSelf((u-c)/n[0],(d-l)/n[1])),e.save(),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.fillStyle=r,e.fillRect(f,l,p-f,d-l);let i=t.detail??[];i.length&&(e.beginPath(),e.rect(f,l,p-f,d-l),e.clip());for(let t=i.length-1;t>=0;t--){let n=i[t],r=(u-c)/lJ(n),a=c+n.x0*r,o=a+n.width*r/2;a+=(u-c)*Math.round((e.canvas.width/2-o)/(u-c)),e.drawImage(n.canvas,a,l+n.y0*r,n.width*r,n.height*r)}e.restore()};e.save();for(let t of n){if(t.opacity<=0)continue;let n=uJ(t.image);if(!n)continue;e.globalAlpha=t.opacity,e.globalCompositeOperation=t.blend===`add`?`lighter`:`source-over`;let r=t.detail?.length&&(t.opacity<1||t.blend===`add`)?_J(e.canvas.width,e.canvas.height):null;r?(m(r,t,n),e.drawImage(r.canvas,0,0)):m(e,t,n)}e.restore()}var gJ=null;function _J(e,t){return gJ??=document.createElement(`canvas`).getContext(`2d`),gJ?(gJ.canvas.width!==e||gJ.canvas.height!==t?(gJ.canvas.width=e,gJ.canvas.height=t):gJ.clearRect(0,0,e,t),gJ):null}var vJ=[`low`,`medium`,`high`];function yJ(e){let t=/^naif-(\d)\d\d$/.exec(e);return t?`naif-${t[1]}`:null}async function bJ(e){try{let t=await fetch(e);return t.ok?await t.json():null}catch{return null}}async function xJ(e){let t=await Promise.all(vJ.map(t=>fetch(Qt(`/v1/textures/${e}/${t}.webp`,`textures`),{method:`HEAD`}).then(e=>e.ok).catch(()=>!1)));return vJ.filter((e,n)=>t[n])}async function SJ(e,t,n=xJ){if(!t?.map_texture_available||!t.texture)return{};let r=o([{...t.texture,id:e,tiers:void 0},...t.alternates??[]]);if(!r)return{};let i=r.tiers??await n(r.id);if(i.length===0)return{};let{frames:a,...s}=r,c=t.radii;return{surface:{...s,tiers:i,monthlyFrames:a},radiusKm:c?(c.a+c.b+c.c)/3:void 0}}async function CJ(e){return SJ(e,(await tS(e,!1).catch(()=>null))?.global)}async function wJ(e){let t=yJ(e);if(!t)return CJ(e);let n=(await bJ(`${Gt()}/v1/systems/${t}.json`))?.[e];if(!n?.texture||!n.tiers?.length)return CJ(e);let r=o([{...n.texture,id:e,tiers:n.tiers},...n.alternates??[]]);if(!r)return CJ(e);let{frames:i,...a}=r,s=n.radii;return{surface:{...a,monthlyFrames:i},clouds:n.clouds,night:n.night,radiusKm:s?(s.a+s.b+s.c)/3:void 0}}var TJ={low:2048,medium:8192,high:16383};function EJ(e){return vJ.find(t=>TJ[t]>=e)??vJ[vJ.length-1]}function DJ(e,t){return vJ.indexOf(e)<=vJ.indexOf(t)?e:t}function OJ(e,t){let n=vJ.indexOf(t);for(let t=n<0?vJ.length-1:n;t>=0;t--)if(e.includes(vJ[t]))return vJ[t];return e[0]??`low`}function kJ(e,t,n){let r=e.id;if(e.frames?.length){let i=JM(n,e.frames,e.coverage);if(i)return Qt(`/v1/textures/${r}/${t}_${i}.webp`,`textures`)}let i=lP(n,e.monthlyFrames);return Qt(i===void 0?`/v1/textures/${r}/${t}.webp`:`/v1/textures/${r}/${t}_${String(i).padStart(2,`0`)}.webp`,`textures`)}function AJ(e,t){return e*t*4}function jJ(){let e=navigator.deviceMemory??4;return Math.max(1,Math.min(e,8))*24*1024*1024}var MJ=class{entries=new Map;clock=0;constructor(e){this.free=e}claim(e){let t=this.entries.get(e);return t?(t.claims++,t.used=++this.clock,t.value):null}put(e,t,n){let r=this.entries.get(e);return r?(r.value!==t&&this.free(t),r.claims++,r.used=++this.clock,r.value):(this.entries.set(e,{value:t,bytes:n,claims:1,used:++this.clock}),this.evict(),t)}release(e,t=!0){let n=this.entries.get(e);n&&(n.claims=Math.max(0,n.claims-1),!t&&!n.claims&&(this.entries.delete(e),this.free(n.value)),this.evict())}evict(){let e=0;for(let t of this.entries.values())t.claims||(e+=t.bytes);let t=jJ();if(e<=t)return;let n=[...this.entries].filter(([,e])=>!e.claims).sort((e,t)=>e[1].used-t[1].used);for(let[r,i]of n){if(e<=t)return;this.entries.delete(r),this.free(i.value),e-=i.bytes}}clear(){for(let e of this.entries.values())this.free(e.value);this.entries.clear()}},NJ=new MJ(e=>e.close()),PJ=new MJ(()=>{}),FJ=new Map;function IJ(e,t){return t?`${e}@${t}`:e}async function LJ(e,t){let n=IJ(e,t),r=NJ.claim(n);if(r)return{key:n,bitmap:r};let i=FJ.get(n);if(!i){i=RJ(e,t),FJ.set(n,i);let r=()=>FJ.delete(n);i.then(r,r)}let a=await i;return a?{key:n,bitmap:NJ.put(n,a,AJ(a.width,a.height))}:null}async function RJ(e,t){let n=await fetch(e);if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.blob();if(!t)return createImageBitmap(r);try{return await createImageBitmap(r,{resizeWidth:t,resizeQuality:`high`})}catch{return createImageBitmap(r)}}function zJ(e,t=!0){NJ.release(e,t)}function BJ(e,t,n){let r=IJ(e,t),i=PJ.claim(r);if(i)return{key:r,raster:i};let a=dJ(n,t);return a?{key:r,raster:PJ.put(r,a,AJ(a.width,a.height))}:null}function VJ(e){PJ.release(e)}var HJ=4,UJ=2,WJ=null;function GJ(e,t,n,r){let i=Math.max(n,0),a=Math.max(r,0),o=Math.min(n+t.width,e.width)-i,s=Math.min(r+t.height,e.height)-a;if(o<=0||s<=0||(WJ??=document.createElement(`canvas`).getContext(`2d`,{willReadFrequently:!0}),!WJ))return;(WJ.canvas.width<t.width||WJ.canvas.height<t.height)&&(WJ.canvas.width=t.width,WJ.canvas.height=t.height),WJ.globalCompositeOperation=`copy`,WJ.drawImage(t,i-n,a-r,o,s,0,0,o,s);let c=WJ.getImageData(0,0,o,s).data,l=o*4;for(let t=0;t<s;t++)e.data.set(c.subarray(t*l,(t+1)*l),((a+t)*e.width+i)*4)}var KJ=class{windows=[];kind=`pixels`;failures=0;failed=new Set;dead=!1;constructor(e,t,n){this.block=e,this.changed=t,this.moves=n}plan(e,t,n){t!==this.kind&&(this.clear(),this.kind=t);for(let e of this.windows)e.wanted=!1;for(let t of this.dead?[]:e){let e=this.windows.find(e=>e.frame===n&&sJ(e,t,this.block.tile_size));e?e.wanted=!0:this.windows.push(this.open(t,n))}this.prune()}rasters(){return this.ordered().filter(e=>!!e.data)}canvases(){return this.ordered().flatMap(e=>e.ctx?[{...e,canvas:e.ctx.canvas}]:[])}clear(){for(let e of this.windows)this.drop(e);this.windows=[]}drop(e){e.dropped=!0,e.data=void 0,e.ctx&&(e.ctx.canvas.width=0)}ordered(){return[...this.windows].sort((e,t)=>t.level-e.level||Number(t.wanted)-Number(e.wanted))}open(e,t){let n={...e,tileSize:this.block.tile_size,frame:t,pending:0,wanted:!0,dropped:!1};if(this.kind===`canvas`){let t=document.createElement(`canvas`);t.width=e.width,t.height=e.height,n.ctx=t.getContext(`2d`)??void 0}else n.data=new Uint8ClampedArray(e.width*e.height*4);for(let r of oJ(e,this.block)){let e=r.patch?.version??(r.cap===``?dE(this.block,r.level,r.x,r.y):this.block.version),i=Jt({id:this.block.id,version:e},r.cap,r.level,r.x,r.y,t);this.failed.has(i)||(n.pending++,this.load(n,i,r.dx,r.dy))}return n}async load(e,t,n,r){try{let i=await LJ(t,null);if(i)try{e.ctx&&!e.dropped?e.ctx.drawImage(i.bitmap,n,r):e.dropped||GJ(e,i.bitmap,n,r)}finally{zJ(i.key,this.moves())}this.failures=0}catch{this.failed.add(t),++this.failures>=HJ&&(this.dead=!0)}if(e.pending--,this.dead)this.clear();else if(e.dropped)return;else e.pending===0&&this.prune();this.changed()}prune(){let e=this.windows.some(e=>e.wanted&&e.pending>0),t=this.windows.filter(e=>!e.wanted),n=e?t.slice(-UJ):[];for(let e of t)n.includes(e)||this.drop(e);this.windows=this.windows.filter(e=>!e.dropped)}};function qJ(e,t,n){return[UF(e,n.minLon,n.maxLon),Math.min(Math.max(t,n.minLat??-90),n.maxLat??90)]}var JJ=class{projection;width;height;view;scale;constructor(e,t,n,r){this.projection=e,this.width=t,this.height=n,this.view=r;let{minX:i,maxX:a,minY:o,maxY:s}=e.extent,c=Math.min(t/(a-i),n/(s-o));this.scale=c*r.zoom}toScreen(e,t){return[this.width/2+(e-this.view.centerX)*this.scale,this.height/2-(t-this.view.centerY)*this.scale]}fromScreen(e,t){return[this.view.centerX+(e-this.width/2)/this.scale,this.view.centerY-(t-this.height/2)/this.scale]}project(e,t){let n=this.projection.forward(e,t);return n?this.toScreen(n[0],n[1]):null}unproject(e,t){let[n,r]=this.fromScreen(e,t);return this.projection.inverse(n,r)}get worldWidthPx(){let{minX:e,maxX:t}=this.projection.extent;return(t-e)*this.scale}get repeatsHorizontally(){return YJ(this.projection,this.worldWidthPx,this.width)}get repeatShifts(){if(!this.repeatsHorizontally)return[0];let e=this.worldWidthPx,t=this.toScreen(this.projection.extent.minX,0)[0];return[0,-e,e].filter(n=>t+n<this.width&&t+n+e>0)}};function YJ(e,t,n){return e.cyclic&&e.rectangular&&t>=n-.5}function XJ(e,t,n,r,i){let a=Math.min(Math.max(e.zoom,1,i.minZoom??1),i.maxZoom??1/0),o=ZJ(e,t,i),s=t.extent,c=s.maxX-s.minX,l=s.maxY-s.minY,u=Math.min(n/c,r/l)*a,d=n/2/u,f=r/2/u,p=(s.minX+s.maxX)/2,m=(s.minY+s.maxY)/2,h=(e,t,n,r)=>n>=r/2?t:Math.min(t+r/2-n,Math.max(t-r/2+n,e));return{zoom:a,centerX:YJ(t,c*u,n)?((o.centerX-s.minX)%c+c)%c+s.minX:h(o.centerX,p,d,c),centerY:h(o.centerY,m,f,l)}}function ZJ(e,t,n){if(!(n.minLon!==void 0||n.maxLon!==void 0||n.minLat!==void 0||n.maxLat!==void 0)||t.azimuthal)return e;let r=t.inverse(e.centerX,e.centerY);if(!r)return e;let[i,a]=qJ(r[0],r[1],n);if(i===r[0]&&a===r[1])return e;let o=t.forward(i,a);return o?{centerX:o[0],centerY:o[1]}:e}var QJ=[[6,`high`],[2.5,`medium`]],$J=22e5,eY=4096,tY=11,nY=.4,rY=.8,iY=140,aY=`medium`,oY=250,sY=2,cY=`naif-399`,lY=[{kind:`surface`,label:e=>e.layer_surface(),visible:!0,opacity:1,blend:`normal`},{kind:`clouds`,label:e=>e.layer_clouds(),visible:!0,opacity:1,blend:`normal`},{kind:`night`,label:e=>e.layer_night(),visible:!1,opacity:.85,blend:`add`}];function uY(e){return e.kind===`raster`}var dY=new WeakMap,fY=class{container=null;root=document.createElement(`div`);canvas=document.createElement(`canvas`);svg=document.createElementNS(Pq,`svg`);layerGroup=document.createElementNS(Pq,`g`);shapeGroup=document.createElementNS(Pq,`g`);markerLayer=document.createElement(`div`);ctx;overlay;bodyId;sources={};layerList=[];projection;projectionId;projectionOptions;view;limits;ownMaxZoom;limitsArmed=!1;jd;cooperative=null;bodyRadiusKm=null;bitmaps=new Map;rasters=new Map;pending=new Set;missing=new Set;tiles=new Map;plannedAt=0;generation=0;controls=null;attribution=null;dragPan;scrollZoom;cooperativeGestures;lookup=null;lookupKey=``;buffer=null;frame=0;resizeObserver=null;listeners=new Map;announcedReady=!1;disposed=!1;moving=!1;sharpWidth=0;msPerPixel=0;settleTimer=0;chosenVisibility=new Map;customLayers=[];constructor(e={}){this.bodyId=e.body??cY,this.projectionId=e.projection??`equirectangular`,this.projectionOptions={centerLon:e.centerLon??0,centerLat:e.centerLat,clipAngle:e.clipAngle},this.projection=AK(this.projectionId,this.projectionOptions),this.limits={maxZoom:16,...e.limits},this.ownMaxZoom=e.limits?.maxZoom===void 0,this.view={zoom:e.zoom??1,centerX:0,centerY:0},this.jd=e.jd??Ag(new Date),this.dragPan=new gq(_q(e.interactions?.dragPan,e.interactive),e=>this.root.classList.toggle(`sm-flat--interactive`,e)),this.scrollZoom=new gq(_q(e.interactions?.scrollZoom,e.interactive)),this.cooperativeGestures=new gq(e.cooperativeGestures??!1,e=>this.applyCooperative(e)),this.root.className=`sm-flat`,this.canvas.className=`sm-flat__raster`,this.svg.setAttribute(`class`,`sm-flat__vector`),this.markerLayer.className=`sm-flat__markers`,this.svg.append(this.layerGroup,this.shapeGroup),this.root.append(this.canvas,this.svg,this.markerLayer),this.ctx=this.canvas.getContext(`2d`),this.overlay=new Gq(this.shapeGroup,this.markerLayer,()=>this.render()),this.root.classList.toggle(`sm-flat--interactive`,this.dragPan.isEnabled()),this.applyCooperative(this.cooperativeGestures.isEnabled());for(let[t,n]of Object.entries(e.layers??{}))this.chosenVisibility.set(t,n)}mount(e){this.container=e,e.append(this.root),this.controls=new Tq(this,this.root),this.cooperative=new yq(this.root,this.cooperativeGestures.isEnabled()),this.resizeObserver=new ResizeObserver(()=>this.renderMoving()),this.resizeObserver.observe(this.root),this.attachInteraction()}addControl(e,t){if(!this.controls)throw Error(`spacemap: the map is not mounted`);return this.controls.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.unmount()}unmount(){this.disposed=!0,this.controls?.clear(),this.controls=null,this.cooperative?.dispose(),this.cooperative=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,cancelAnimationFrame(this.frame),clearTimeout(this.settleTimer);for(let e of this.layerList)uY(e)||e.dispose?.();this.overlay.clear(),this.dropTextures(),this.dropTiles(),this.root.remove(),this.container=null}async load(){await this.adopt(this.bodyId)}async adopt(e){let t=await wJ(e);if(!this.disposed){if(!t.surface){let t=Error(`spacemap: no map texture for ${e}`);throw this.emit(`error`,t),t}e!==this.bodyId&&this.release(),this.bodyId=e,this.sources=t,this.bodyRadiusKm=t.radiusKm??null,this.overlay.setBodyRadiusKm(this.bodyRadiusKm),this.buildLayers(),await this.loadVisible(),!this.disposed&&this.render()}}release(){this.generation++,this.dropTextures(),this.dropTiles(),this.missing.clear();for(let e of this.layerList)!uY(e)&&!this.customLayers.includes(e)&&e.dispose?.()}buildLayers(){let{messages:e}=i(),t=[];this.dropTiles();for(let n of lY){let r=this.sources[n.kind];if(!r)continue;let i={kind:`raster`,id:n.kind,label:n.label(e),visible:n.visible,opacity:n.opacity,blend:n.blend,credit:Iq(r),tiers:r.tiers,url:(e,t)=>kJ(r,t,e)};if(t.push(i),!r.tiles)continue;let a=new KJ(r.tiles,()=>{a.dead&&(this.loadVisible(),this.emit(`layerschange`,this.layers)),this.render()},()=>this.moves());this.tiles.set(i,a)}t.push(Rq(e.layer_graticule())),t.push(Bq(this.bodyId,e.layer_nomenclature())),t.push(...this.customLayers);for(let e of t){let t=this.chosenVisibility.get(e.id);t!==void 0&&(e.visible=t)}this.layerList=t,this.emit(`layerschange`,this.layers)}get layers(){return this.layerList.map(Fq)}getLayers(){return this.layerList.map(e=>e.id)}isLayerVisible(e){return this.layerList.find(t=>t.id===e)?.visible??!1}get credits(){let e=new Set,t=[],n=n=>{e.has(n.organisation)||(e.add(n.organisation),t.push(n))};for(let e of this.layerList){if(!e.visible||!e.credit)continue;n(e.credit);let t=this.tilesOf(e);if(!t)continue;let r={...e.credit,tiles:t.block},i=On(r);i&&n(i);for(let e of kn(r))n(e)}return t}setLayerVisible(e,t){this.chosenVisibility.set(e,t);let n=this.layerList.find(t=>t.id===e);!n||n.visible===t||(n.visible=t,this.emit(`layerschange`,this.layers),this.loadVisible(),this.render())}setLayerOpacity(e,t){let n=this.layerList.find(t=>t.id===e);!n||!uY(n)||(n.opacity=Math.min(1,Math.max(0,t)),this.render())}addRasterLayer(e){let t={kind:`raster`,id:e.id,label:e.label??e.id,visible:e.visible??!0,opacity:e.opacity??1,blend:e.blend??`normal`,credit:e.credit,tiers:[`low`],url:()=>e.url};this.customLayers.push(t),this.layerList.push(t),this.emit(`layerschange`,this.layers),this.loadVisible()}addVectorLayer(e){let t={kind:`vector`,id:e.id,label:e.label??e.id,visible:e.visible??!0,credit:e.credit,render:e.render,prepare:e.prepare};this.customLayers.push(t),this.layerList.push(t),this.emit(`layerschange`,this.layers),this.loadVisible()}get projectionName(){return this.projectionId}static get projections(){return kK}setProjection(e,t={}){this.limitsArmed=!1,this.projectionId=e,this.projectionOptions={...this.projectionOptions,...t},this.projection=AK(e,this.projectionOptions),this.view={...this.view,centerX:0,centerY:0},this.render(),this.emit(`viewchange`,this.viewState)}get viewState(){let e=this.viewport(),t=e.unproject(e.width/2,e.height/2);return{projection:this.projectionId,zoom:this.view.zoom,centerLon:t?.[0]??this.projectionOptions.centerLon??0,centerLat:t?.[1]??this.projectionOptions.centerLat??0}}setView(e){if(e.projection&&e.projection!==this.projectionId&&this.setProjection(e.projection),this.limitsArmed=!1,e.zoom!==void 0&&(this.view={...this.view,zoom:e.zoom}),e.centerLon!==void 0||e.centerLat!==void 0){let t=this.viewState,n=e.centerLon??t.centerLon,r=e.centerLat??t.centerLat;if(this.projection.azimuthal)this.projectionOptions={...this.projectionOptions,centerLon:n,centerLat:r},this.projection=AK(this.projectionId,this.projectionOptions);else{let e=this.projection.forward(n,r);e&&(this.view={...this.view,centerX:e[0],centerY:e[1]})}}this.loadVisible(),this.render(),this.emit(`viewchange`,this.viewState)}setLimits(e){return this.limits={maxZoom:16,...e},this.ownMaxZoom=e.maxZoom===void 0,this.render(),this}getLimits(){return this.ownMaxZoom?{...this.limits,maxZoom:this.pictureMaxZoom()}:{...this.limits}}setTime(e){this.jd=e,this.loadVisible(),this.render()}async setBody(e){e!==this.bodyId&&(this.limitsArmed=!1,await this.adopt(e))}project(e,t){return this.viewport().project(e,t)}unproject(e,t){let n=this.viewport().unproject(e,t);return n?{lon:n[0],lat:n[1]}:null}addPolyline(e){let t=this.overlay.addPolyline(e);return this.render(),t}addPolygon(e){let t=this.overlay.addPolygon(e);return this.render(),t}addBox(e){let t=this.overlay.addBox(e);return this.render(),t}addCircle(e){let t=this.overlay.addCircle(e);return this.render(),t}addMarker(e){let t=this.overlay.addMarker(e);return this.render(),t}clearDrawings(){this.overlay.clear(),this.render()}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=((...e)=>{r(),t(...e)});dY.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners.get(e);if(n){n.delete(t);for(let e of n)dY.get(e)===t&&n.delete(e)}}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of[...n])e(...t)}tier(e){let t=QJ.find(([e])=>this.view.zoom>=e)?.[1]??`low`;return this.tilesOf(e)&&(t=DJ(t,aY)),OJ(e.tiers,DJ(t,EJ(this.usableSourceWidth())))}usableSourceWidth(){return this.projectionId===`equirectangular`?this.deviceWidth()*this.view.zoom:this.workingWidth()}deviceWidth(){return this.sharpWidth||Math.max(1,this.root.clientWidth)}workingWidth(){let e=this.deviceWidth()*2*this.view.zoom;return Math.min(eY,2**Math.ceil(Math.log2(Math.max(256,e))))}decodeWidth(e){return this.projectionId===`equirectangular`?null:Math.min(this.workingWidth(),TJ[e]??eY)}picturesInUse(){return this.layerList.filter(e=>uY(e)&&e.visible).map(e=>{let t=this.tier(e);return{url:e.url(this.jd,t),tier:t}})}async loadVisible(){let e=this.picturesInUse(),t=this.layerList.filter(e=>!uY(e)&&e.visible&&!!e.prepare).map(e=>e.prepare().then(()=>this.render(),()=>{})),n=e.filter(({url:e,tier:t})=>this.bitmaps.get(e)?.key!==IJ(e,this.decodeWidth(t))).filter(({url:e})=>!this.pending.has(e)&&!this.missing.has(e)).map(async({url:e,tier:t})=>{this.pending.add(e);let n=this.generation;try{let r=await LJ(e,this.decodeWidth(t));if(!r)return;if(this.disposed||n!==this.generation){zJ(r.key);return}this.hold(this.bitmaps,e,r,zJ),this.render()}catch(t){if(n!==this.generation)return;this.missing.add(e),this.emit(`error`,Error(`spacemap: could not load ${e}`,{cause:t}))}finally{this.pending.delete(e)}});await Promise.all([...t,...n]),this.dropUnused(new Set(this.picturesInUse().map(({url:e})=>e)))}dropUnused(e){for(let[t,n]of this.bitmaps)e.has(t)||(zJ(n.key),this.bitmaps.delete(t));for(let[t,n]of this.rasters)e.has(t)||(VJ(n.key),this.rasters.delete(t))}hold(e,t,n,r){let i=e.get(t);i?.key!==n.key&&(i&&r(i.key),e.set(t,n))}rasterFor(e,t){let n=this.rasters.get(e);if(n?.key===IJ(e,t))return n.raster;let r=this.bitmaps.get(e)?.bitmap;if(!r)return null;let i=BJ(e,t,r);return i?(this.hold(this.rasters,e,i,VJ),i.raster):null}dropTextures(){for(let e of this.bitmaps.values())zJ(e.key);for(let e of this.rasters.values())VJ(e.key);this.bitmaps.clear(),this.rasters.clear()}tilesOf(e){let t=this.tiles.get(e);if(!(!t||!uY(e)||t.dead||Kt()===``)&&a(t.block.distribution))return Math.max(t.block.max_level,...(t.block.patches??[]).map(e=>e.max_level))>=this.firstTileLevel(e,t)?t:void 0}firstTileLevel(e,t){let n=TJ[OJ(e.tiers,aY)]??eY,r=this.projectionId===`equirectangular`?n:Math.min(n,eY);return Math.floor(Math.log2(r/(2*t.block.tile_size)))+1}frameSample(e,t){let{width:n,height:r,projection:i}=e,a=(t,n)=>e.unproject(t,n),o=a(n/2,r/2),s=a(n/2+1,r/2),c=a(n/2,r/2+1);if(!o||!s||!c)return;let l={lon:o[0],lat:o[1]},u=Math.min(LK(l,{lon:s[0],lat:s[1]}),LK(l,{lon:c[0],lat:c[1]})),d=t=>{let a=i.azimuthal?e.project(0,t):null;return!!a&&a[0]>=0&&a[0]<=n&&a[1]>=0&&a[1]<=r};return{place:(e,t)=>a(e*n,t*r),step:u*Math.PI/180/t,north:d(90),south:d(-90)}}planTiles(e,t){let n=this.projectionId===`equirectangular`?`canvas`:`pixels`,r;for(let[i,a]of this.tiles){let o=uY(i)&&i.visible&&i.opacity>0&&this.tilesOf(i);r??=o?this.frameSample(e,t):void 0;let s=o&&r?this.firstTileLevel(i,a):0,c=o&&r?aJ(a.block,r,s,this.moves()):[];a.plan(c,n,lP(this.jd,a.block.frames))}}moves(){return this.dragPan.isEnabled()||this.scrollZoom.isEnabled()}dropTiles(){for(let e of this.tiles.values())e.clear();this.tiles.clear()}pictureMaxZoom(){let e=16,{clientWidth:t,clientHeight:n}=this.root;if(!t||!n)return e;let r=new JJ(this.projection,t,n,this.view),i=this.frameSample(r,1),a=i?.place(.5,.5);if(!i||!a)return e;for(let t of this.layerList){let n=t.visible?this.tilesOf(t):void 0;if(!n)continue;let r=$q(eJ(n.block,a[0],a[1]),n.block.tile_size)/sY;e=Math.max(e,this.view.zoom*i.step/r)}return e}heldLimits(){return this.ownMaxZoom&&this.layerList.some(e=>e.visible&&this.tilesOf(e))?{...this.limits,maxZoom:void 0}:this.limits}tileStepDeg(e,t){let n=this.layerList.find(e=>e.id===`surface`),r=n&&this.tilesOf(n);return r?$q(eJ(r.block,e,t),r.block.tile_size)*180/Math.PI:null}viewport(e,t){let n=e??this.root.clientWidth??1,r=t??this.root.clientHeight??1,i=this.limitsArmed?this.heldLimits():{};return this.view=XJ(this.view,this.projection,n,r,i),new JJ(this.projection,Math.max(1,n),Math.max(1,r),this.view)}render(){this.disposed||(cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(()=>this.draw()))}renderMoving(){this.moving=!0,clearTimeout(this.settleTimer),this.settleTimer=window.setTimeout(()=>{this.moving=!1,this.render()},iY),this.render()}draw(){let e=this.root.clientWidth,t=this.root.clientHeight;if(!this.ctx||e===0||t===0)return;let n=Math.min(window.devicePixelRatio||1,2),r=Math.sqrt($J/(e*t*n*n)),i=n*Math.min(1,r),a=Math.max(1,Math.round(e*i));a!==this.sharpWidth&&(this.sharpWidth=a,this.loadVisible());let o=e*i*t*i,s=i*(this.moving?this.interactionScale(o):1),c=Math.max(1,Math.round(e*s)),l=Math.max(1,Math.round(t*s));(this.canvas.width!==c||this.canvas.height!==l)&&(this.canvas.width=c,this.canvas.height=l,this.buffer=null,this.lookup=null);let u=this.viewport(e,t),d=new JJ(this.projection,c,l,this.view),f=performance.now();(!this.moving||f-this.plannedAt>oY)&&(this.plannedAt=f,this.planTiles(u,i)),this.clipToDisc(u),this.drawRaster(d,c,l),this.drawVector(u),!this.announcedReady&&this.bitmaps.size>0&&(this.announcedReady=!0,this.emit(`ready`))}record(e,t){if(t<=0)return;let n=e/t;this.msPerPixel=this.msPerPixel===0?n:this.msPerPixel*.7+n*.3}interactionScale(e){if(this.msPerPixel<=0||e<=0)return 1;let t=Math.sqrt(tY/this.msPerPixel/e);return t>rY?1:Math.max(nY,t)}clipToDisc(e){let{projection:t}=e;if(!t.azimuthal){this.canvas.style.clipPath=``;return}let[n,r]=e.toScreen(0,0),i=t.extent.maxX*e.scale;this.canvas.style.clipPath=`circle(${i}px at ${n}px ${r}px)`}drawRaster(e,t,n){let r=this.ctx;r.clearRect(0,0,t,n);let i=this.layerList.filter(e=>uY(e)&&e.visible);if(i.length===0)return;if(this.projectionId===`equirectangular`){let t=i.map(e=>({image:this.bitmaps.get(e.url(this.jd,this.tier(e)))?.bitmap,opacity:e.opacity,blend:e.blend,detail:this.tilesOf(e)?.canvases()})).filter(e=>!!e.image);t.length&&hJ(r,e,t);return}let a=this.workingWidth(),o=i.map(e=>({image:this.rasterFor(e.url(this.jd,this.tier(e)),a),opacity:e.opacity,blend:e.blend,detail:this.tilesOf(e)?.rasters()})).filter(e=>!!e.image);if(o.length===0)return;(!this.buffer||this.buffer.width!==t||this.buffer.height!==n)&&(this.buffer=r.createImageData(t,n));let s=`${this.projectionId}|${JSON.stringify(this.projectionOptions)}|${this.view.zoom}|${this.view.centerX}|${this.view.centerY}|${t}x${n}`,c=!this.lookup||this.lookupKey!==s,l=performance.now();c&&(this.lookup=new fJ(e,t,n),this.lookupKey=s),mJ(this.lookup,o,this.buffer),r.putImageData(this.buffer,0,0),c&&this.record(performance.now()-l,t*n)}drawVector(e){this.svg.setAttribute(`viewBox`,`0 0 ${e.width} ${e.height}`),this.layerGroup.replaceChildren();for(let t of this.layerList){if(uY(t)||!t.visible)continue;let n=document.createElementNS(Pq,`g`);n.setAttribute(`data-layer`,t.id),t.render(e,n),this.layerGroup.append(n)}this.overlay.redraw(e)}applyCooperative(e){this.root.classList.toggle(`sm-flat--cooperative`,e),this.cooperative?.setEnabled(e)}attachInteraction(){let e=!1,t=0,n=0,r=!1,i=!1,a=new Map,o=-1,s=0,c=null,l=()=>{let[e,t]=[...a.values()];if(!t)return null;let n=this.root.getBoundingClientRect();return{gap:Math.hypot(e.x-t.x,e.y-t.y),x:(e.x+t.x)/2-n.left,y:(e.y+t.y)/2-n.top}},u=e=>{let t=this.root.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]};this.root.addEventListener(`pointerdown`,u=>{u.pointerType===`touch`&&a.set(u.pointerId,{x:u.clientX,y:u.clientY}),c=l(),s=c?.gap??0,u.button===0&&(o=u.pointerId,e=!0,r=!1,i=u.pointerType===`touch`&&this.cooperative.isEnabled()&&a.size<2,this.root.setPointerCapture(u.pointerId),t=u.clientX,n=u.clientY,!i&&this.dragPan.isEnabled()&&this.root.classList.add(`sm-flat--dragging`))}),this.root.addEventListener(`pointermove`,d=>{let[f,p]=u(d);a.has(d.pointerId)&&a.set(d.pointerId,{x:d.clientX,y:d.clientY});let m=l();if(m){r=!0,c&&this.dragPan.isEnabled()&&this.drag(m.x-c.x,m.y-c.y),s>0&&this.scrollZoom.isEnabled()&&this.zoomBy(m.gap/s,m.x,m.y),s=m.gap,c=m;return}if(!e){this.emit(`pointermove`,this.unproject(f,p),d);return}if(d.pointerId!==o)return;let h=d.clientX-t,g=d.clientY-n;if(t=d.clientX,n=d.clientY,(Math.abs(h)>1||Math.abs(g)>1)&&(r=!0),i){r&&this.cooperative.allowsTouchDrag(a.size);return}this.dragPan.isEnabled()&&this.drag(h,g)});let d=l=>{a.delete(l.pointerId),s=0,c=null;let[d]=[...a.entries()];if(d&&e){o=d[0],t=d[1].x,n=d[1].y,i=this.cooperative.isEnabled()&&a.size<2;return}if(!(!e||l.pointerId!==o)&&(e=!1,this.root.releasePointerCapture?.(l.pointerId),this.root.classList.remove(`sm-flat--dragging`),!r)){let[e,t]=u(l);this.emit(`click`,this.unproject(e,t),l)}};this.root.addEventListener(`pointerup`,d),this.root.addEventListener(`pointercancel`,d),this.root.addEventListener(`wheel`,e=>{if(!this.scrollZoom.isEnabled()||!this.cooperative.allowsWheel(e))return;e.preventDefault();let[t,n]=u(e);this.zoomBy(Math.exp(-e.deltaY/400),t,n)},{passive:!1})}drag(e,t){this.limitsArmed=!0;let n=this.viewport();if(this.projection.azimuthal){let r=n.scale,i=e=>e/r*(180/Math.PI),[a,o]=qJ((this.projectionOptions.centerLon??0)-i(e),Math.max(-90,Math.min(90,(this.projectionOptions.centerLat??0)+i(t))),this.limits);this.projectionOptions={...this.projectionOptions,centerLon:a,centerLat:o},this.projection=AK(this.projectionId,this.projectionOptions)}else this.view={...this.view,centerX:this.view.centerX-e/n.scale,centerY:this.view.centerY+t/n.scale};this.renderMoving(),this.emit(`viewchange`,this.viewState)}zoomBy(e,t,n){this.limitsArmed=!0;let r=this.viewport().fromScreen(t,n),i=this.ownMaxZoom?Math.max(this.pictureMaxZoom(),this.view.zoom):this.limits.maxZoom??1/0,a=Math.min(i,Math.max(1,this.limits.minZoom??1,this.view.zoom*e));if(a===this.view.zoom)return;this.view={...this.view,zoom:a};let o=this.viewport();if(!this.projection.azimuthal){let e=o.fromScreen(t,n);this.view={...this.view,centerX:this.view.centerX+r[0]-e[0],centerY:this.view.centerY+r[1]-e[1]}}this.loadVisible(),this.renderMoving(),this.emit(`viewchange`,this.viewState)}};function pY(e){let t=e?.radii;if(t)return(t.a+t.b+t.c)/3;let n=e?.wikidata?.radius;if(n)return n.unit===`kilometre`?n.value:n.unit===`metre`?n.value/1e3:null;let r=e?.sbdb?.diameter;return r?r/2:null}function mY(){return typeof window>`u`?`unsupported`:window.isSecureContext?`DeviceOrientationEvent`in window&&window.matchMedia(`(pointer: coarse)`).matches?`available`:`unsupported`:`insecure`}async function hY(){let e=DeviceOrientationEvent.requestPermission;if(typeof e!=`function`)return!0;try{return await e.call(DeviceOrientationEvent)===`granted`}catch{return!1}}var gY=Math.PI/180,_Y=256,vY=128,yY=.05,bY=.25;function xY(e){try{let t=document.createElement(`canvas`);t.width=_Y,t.height=vY;let n=t.getContext(`2d`,{willReadFrequently:!0});if(!n)return null;n.drawImage(e,0,0,_Y,vY);let{data:r}=n.getImageData(0,0,_Y,vY),i=new Uint8Array(_Y*vY);for(let e=0;e<i.length;e++)i[e]=+(r[e*4+3]>127);return{width:_Y,height:vY,covered:i}}catch{return null}}function SY(e,t,n){let{width:r,height:i,covered:a}=e,o=new Float64Array(r);for(let e=0;e<r;e++)o[e]=(e+.5)*360/r;let s=new Float64Array(i);for(let e=0;e<i;e++)s[e]=90-(e+.5)*180/i;let c=0,l=0,u=0;for(let e=0;e<i;e++){let t=Math.cos(s[e]*gY);for(let n=0;n<r;n++)a[e*r+n]&&(c+=t*Math.sin(o[n]*gY),l+=t*Math.cos(o[n]*gY),u+=t)}if(u===0)return t;let d=Math.hypot(c,l)/u<yY?t.heading:CY(Math.atan2(c,l)/gY-n.northOffsetDeg),f=CY(d+n.northOffsetDeg),p=Math.min(180,n.hfovDeg/2),m=new Float64Array(i),h=0;for(let e=0;e<r;e++)if(!(Math.abs((o[e]-f+540)%360-180)>p))for(let t=0;t<i;t++)a[t*r+e]&&(h=Math.max(h,++m[t]));let g=-1/0,_=1/0;for(let e=0;e<i;e++)m[e]<h*bY||(g=Math.max(g,s[e]),_=Math.min(_,s[e]));if(g<_)return{heading:d,pitch:t.pitch};let v=Math.min(n.vfovDeg/3,(g-_)/2);return{heading:d,pitch:Math.max(_+v,Math.min(g-v,t.pitch))}}function CY(e){return(e%360+360)%360}Math.PI/180;function wY(e){return e.orientation!==`unknown`}function TY(e){return e.id}function EY(e){return`${e.time},${e.lat},${e.lon}`}function DY(e,t){return t?e.find(e=>TY(e)===t||EY(e)===t)??null:null}var OY=1;function kY(e,t,n){let r=e.findIndex(e=>e.id===t.id),i=i=>{for(let a=r+i;a>=0&&a<e.length;a+=i){let r=e[a];if(r.mission!==t.mission)return null;let i=jY(t,r,n);if(i>=OY)return{entry:r,distanceM:i,bearingDeg:MY(t,r)}}return null};return{previous:i(-1),next:i(1)}}var AY=Math.PI/180;function jY(e,t,n){return LK(e,t)*AY*n*1e3}function MY(e,t){let n=e.lat*AY,r=t.lat*AY,i=(t.lon-e.lon)*AY,a=Math.sin(i)*Math.cos(r),o=Math.cos(n)*Math.sin(r)-Math.sin(n)*Math.cos(r)*Math.cos(i);return(Math.atan2(a,o)/AY%360+360)%360}var NY=Math.PI/180,PY=30,FY=110,IY=85,LY=75,RY=-22,zY=9,BY=6,VY=10,HY=1,UY=new Xi(-Math.SQRT1_2,0,0,Math.SQRT1_2),WY=new J(0,0,1);function GY(e){return(e%360+360)%360}function KY(e,[t,n]){let r=GY(n-t),i=GY(e-t);return i<=r?GY(e):i-r<360-i?GY(n):GY(t)}function qY(e,t,n){return Math.max(t,Math.min(n,e))}function JY(e,t,n=new J){let r=e*NY,i=t*NY;return n.set(Math.sin(r)*Math.cos(i),Math.sin(i),-Math.cos(r)*Math.cos(i))}function YY(){let e=new Ol;return e.moveTo(0,1),e.lineTo(.85,.05),e.lineTo(.38,.05),e.lineTo(.38,-.9),e.lineTo(-.38,-.9),e.lineTo(-.38,.05),e.lineTo(-.85,.05),e.closePath(),e}var XY=class{bodyId;openAt;openingView;interactive;followArrows;limits={};attribution=null;container=null;root=document.createElement(`div`);renderer=null;controls=null;resizeObserver=null;scene=new to;camera=new bd(LY,1,.1,1e3);sphere;angleCanvas=document.createElement(`canvas`);angleContext=this.angleCanvas.getContext(`2d`);angleGridVisible=!1;arrows=new qa;arrowGeometry=new mu(YY());raycaster=new Zd;loader=new sd;texture=null;loadToken=0;frame=0;disposed=!1;entries=[];radiusKm=0;current=null;neighbours=null;view;pointers=new Map;pinchDistance=0;dragStart=null;hovered=null;gyroEnabled=!1;gyroOrigin=null;gyroEuler=new ka;gyroQuaternion=new Xi;gyroScreen=new Xi;gyroDirection=new J;lookAt=new J;ndc=new J;gridPoint=new J;viewDirection=new J;listeners={ready:new Set,load:new Set,error:new Set,viewchange:new Set,step:new Set,arrows:new Set};constructor(e){this.bodyId=e.body,this.openAt=e.at,this.interactive=e.interactive??!0,this.arrows.visible=e.arrows??!0,this.followArrows=e.followArrows??!0,this.openingView=e.heading!==void 0||e.pitch!==void 0?{heading:e.heading,pitch:e.pitch}:null,this.view={heading:e.heading??0,pitch:e.pitch??0,fov:e.fov??LY},e.limits&&this.setLimits(e.limits),this.root.className=`sm-panorama`,this.root.style.cssText=`position:relative;width:100%;height:100%;overflow:hidden`,this.scene.background=new X(`#0b0d12`),this.sphere=new Us(new gu(500,96,48).scale(-1,1,1),new js({transparent:!0,visible:!1,depthWrite:!1})),this.sphere.renderOrder=-2,this.scene.add(this.sphere,this.arrows)}mount(e){this.container=e,e.append(this.root),this.renderer=new wh({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2));let t=this.renderer.domElement;t.style.cssText=`display:block;width:100%;height:100%;touch-action:none`,t.tabIndex=0,this.root.append(t),this.angleCanvas.style.cssText=`position:absolute;inset:0;display:block;width:100%;height:100%;pointer-events:none`,this.angleCanvas.setAttribute(`aria-hidden`,`true`),this.angleCanvas.hidden=!0,this.root.append(this.angleCanvas),this.controls=new Tq(this,this.root),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.root),this.resize(),this.interactive?(t.addEventListener(`pointerdown`,this.onPointerDown),t.addEventListener(`pointermove`,this.onPointerMove),t.addEventListener(`pointerup`,this.onPointerUp),t.addEventListener(`pointercancel`,this.onPointerCancel),t.addEventListener(`wheel`,this.onWheel,{passive:!1}),t.addEventListener(`keydown`,this.onKeyDown)):(t.addEventListener(`pointermove`,this.onPointerMove),t.addEventListener(`pointerup`,this.onPointerUp))}async load(){let e=await tS(this.bodyId,!1);if(this.disposed)return;this.entries=(e.global?.panoramas??[]).filter(eS),this.radiusKm=pY(e.global)??0,this.emit(`ready`);let t=this.openAt?this.byKey(this.openAt):this.entries[0]??null;if(!t){let e=Error(this.openAt?`spacemap: no panorama ${this.openAt} on ${this.bodyId}`:`spacemap: no panoramas on ${this.bodyId}`);throw this.emit(`error`,e),e}await this.open(t)}addControl(e,t){return this.controls?.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.disposed=!0,this.setGyroEnabled(!1),this.loadToken++,cancelAnimationFrame(this.frame),this.frame=0,this.controls?.clear(),this.resizeObserver?.disconnect();let e=this.renderer?.domElement;e&&(e.removeEventListener(`pointerdown`,this.onPointerDown),e.removeEventListener(`pointermove`,this.onPointerMove),e.removeEventListener(`pointerup`,this.onPointerUp),e.removeEventListener(`pointercancel`,this.onPointerCancel),e.removeEventListener(`wheel`,this.onWheel),e.removeEventListener(`keydown`,this.onKeyDown)),this.setArrowTargets([]),this.texture?.dispose(),this.sphere.geometry.dispose(),this.sphere.material.dispose(),this.arrowGeometry.dispose(),this.renderer?.dispose(),this.renderer=null,this.root.remove(),this.container=null}getPanoramas(){return this.entries}getCurrent(){return this.current}getNeighbours(){return this.neighbours}async open(e){let t=typeof e==`string`?this.byKey(e):e;if(!t){let t=Error(`spacemap: no panorama ${String(e)} on ${this.bodyId}`);throw this.emit(`error`,t),t}this.current=t,this.neighbours=this.radiusKm?kY(this.entries,t,this.radiusKm):null;let n=this.openingView;this.openingView=null,n&&this.setView({heading:n.heading,pitch:n.pitch??0}),this.setArrowTargets(this.neighbours&&wY(t)?[`previous`,`next`].map(e=>({key:e,n:this.neighbours?.[e]??null})).filter(e=>e.n).map(e=>({key:e.key,bearingDeg:e.n.bearingDeg})):[]),await this.loadTexture(Qt(`/v1/panoramas/${t.id}.webp`,`panoramas`),t.north_offset_deg,!n),this.current===t&&this.emit(`load`,t)}async step(e){let t=this.neighbours?.[e];t&&await this.open(t.entry)}byKey(e){return this.entries.find(t=>t.id===e)??DY(this.entries,e)}getView(){return{...this.view}}setView(e){let t=e.heading??this.view.heading,n=e.pitch??this.view.pitch,r=e.fov??this.view.fov,{limits:i}=this;this.view={heading:i.heading?KY(t,i.heading):GY(t),pitch:qY(n,i.pitch?.[0]??-IY,i.pitch?.[1]??IY),fov:qY(r,i.fov?.[0]??PY,i.fov?.[1]??FY)},this.invalidate(),this.emit(`viewchange`,this.getView())}getLimits(){return structuredClone(this.limits)}setLimits(e){let t=(e,t,n)=>e&&[qY(e[0],t,n),qY(e[1],t,n)];this.limits={heading:e.heading&&[GY(e.heading[0]),GY(e.heading[1])],pitch:t(e.pitch,-IY,IY),fov:t(e.fov,PY,FY)},this.setView({})}async setGyroEnabled(e){return e===this.gyroEnabled?this.gyroEnabled:e?mY()!==`available`||!await hY()||this.disposed?!1:(this.gyroOrigin=null,this.gyroEnabled=!0,window.addEventListener(`deviceorientation`,this.onDeviceOrientation),!0):(window.removeEventListener(`deviceorientation`,this.onDeviceOrientation),this.gyroEnabled=!1,!1)}isGyroEnabled(){return this.gyroEnabled}onDeviceOrientation=e=>{if(e.alpha===null||e.beta===null||e.gamma===null)return;this.gyroEuler.set(e.beta*NY,e.alpha*NY,-e.gamma*NY,`YXZ`),this.gyroQuaternion.setFromEuler(this.gyroEuler).multiply(UY).multiply(this.gyroScreen.setFromAxisAngle(WY,-(screen.orientation?.angle??0)*NY)),this.gyroDirection.set(0,0,-1).applyQuaternion(this.gyroQuaternion);let t=Math.atan2(this.gyroDirection.x,-this.gyroDirection.z)/NY,n=Math.asin(qY(this.gyroDirection.y,-1,1))/NY;this.gyroOrigin===null&&(this.gyroOrigin=GY(t-this.view.heading)),this.setView({heading:t-this.gyroOrigin,pitch:n})};on(e,t){return this.listeners[e].add(t),()=>this.off(e,t)}once(e,t){let n=this.on(e,((...e)=>{n(),t(...e)}));return n}off(e,t){this.listeners[e].delete(t)}emit(e,...t){for(let n of this.listeners[e])n(...t)}faceCoverage(e,t){let n=xY(e);if(!n)return;let r=this.view.fov,i=2*Math.atan(Math.tan(r/2*NY)*this.camera.aspect)/NY;this.setView(SY(n,this.view,{northOffsetDeg:t,hfovDeg:i,vfovDeg:r}))}loadTexture(e,t,n){let r=++this.loadToken;return new Promise((i,a)=>{this.loader.load(e,e=>{if(r!==this.loadToken){e.dispose(),i();return}e.colorSpace=ri,this.renderer&&(e.anisotropy=this.renderer.capabilities.getMaxAnisotropy()),this.texture?.dispose(),this.texture=e,this.sphere.material.map=e,this.sphere.material.visible=!0,this.sphere.material.needsUpdate=!0,this.sphere.rotation.y=Math.PI/2+t*NY,n&&this.faceCoverage(e.image,t),this.invalidate(),i()},void 0,()=>{if(r!==this.loadToken)return i();let t=Error(`spacemap: panorama failed to load: ${e}`);this.emit(`error`,t),a(t)})})}setArrowTargets(e){for(let e of[...this.arrows.children])this.arrows.remove(e),e.traverse(e=>{e instanceof Us&&e.material.dispose()});for(let t of e){let e=new qa;e.name=t.key;let n=new Us(this.arrowGeometry,new js({color:`#000000`,transparent:!0,opacity:.45,side:2,depthWrite:!1}));n.scale.setScalar(1.3);let r=new Us(this.arrowGeometry,new js({color:`#ffffff`,transparent:!0,opacity:.85,side:2,depthWrite:!1}));r.position.y=.02;for(let e of[n,r])e.rotation.x=-Math.PI/2;e.add(n,r),e.position.copy(JY(t.bearingDeg,RY)).multiplyScalar(zY),e.rotation.y=-t.bearingDeg*NY,this.arrows.add(e)}this.invalidate()}invalidate(){this.disposed||this.frame||!this.renderer||(this.frame=requestAnimationFrame(()=>{this.frame=0,this.render()}))}setAngleGridVisible(e){e!==this.angleGridVisible&&(this.angleGridVisible=e,this.angleCanvas.hidden=!e,this.invalidate())}setArrowsVisible(e){e!==this.arrows.visible&&(this.arrows.visible=e,e||(this.hovered=null,this.renderer&&(this.renderer.domElement.style.cursor=``)),this.invalidate())}resize(){let{clientWidth:e,clientHeight:t}=this.root;if(!e||!t||!this.renderer)return;this.renderer.setSize(e,t,!1);let n=Math.min(window.devicePixelRatio,2);this.angleCanvas.width=Math.round(e*n),this.angleCanvas.height=Math.round(t*n),this.angleContext.setTransform(n,0,0,n,0,0),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.invalidate()}render(){if(!this.renderer)return;this.camera.fov=this.view.fov,this.camera.updateProjectionMatrix(),this.camera.lookAt(JY(this.view.heading,this.view.pitch,this.lookAt)),this.renderer.render(this.scene,this.camera);let{clientWidth:e,clientHeight:t}=this.root;if(this.drawAngleGrid(e,t),this.listeners.arrows.size===0)return;let n={};for(let r of this.arrows.visible?this.arrows.children:[])this.ndc.copy(r.position).project(this.camera),n[r.name]={x:(this.ndc.x+1)/2*e,y:(1-this.ndc.y)/2*t,visible:this.ndc.z<1&&Math.abs(this.ndc.x)<.98&&Math.abs(this.ndc.y)<.98};this.emit(`arrows`,n)}drawAngleGrid(e,t){let n=this.angleContext;if(n.clearRect(0,0,e,t),this.angleGridVisible){this.camera.getWorldDirection(this.viewDirection),n.strokeStyle=`rgba(255, 255, 255, 0.24)`,n.lineWidth=1,n.beginPath();for(let r=0;r<360;r+=VY)this.traceAngleLine(n,e,t,r,!0);for(let r=-80;r<=80;r+=VY)this.traceAngleLine(n,e,t,r,!1);n.stroke(),n.font=`12px system-ui, sans-serif`,n.lineWidth=3,n.strokeStyle=`rgba(0, 0, 0, 0.7)`,n.fillStyle=`rgba(255, 255, 255, 0.85)`,n.textAlign=`center`,n.textBaseline=`bottom`;for(let r=0;r<360;r+=VY){if(!this.projectAngle(r,0,e,t,!0))continue;let i=`${r}°`;n.strokeText(i,this.gridPoint.x,this.gridPoint.y-3),n.fillText(i,this.gridPoint.x,this.gridPoint.y-3)}n.textAlign=`left`,n.textBaseline=`middle`;for(let r of[0,90,180,270])for(let i=-80;i<=80;i+=VY){if(i===0||!this.projectAngle(r,i,e,t,!0))continue;let a=`${i>0?`+`:``}${i}°`;n.strokeText(a,this.gridPoint.x+4,this.gridPoint.y),n.fillText(a,this.gridPoint.x+4,this.gridPoint.y)}}}traceAngleLine(e,t,n,r,i){let a=!1,o=0,s=0,c=Math.max(t,n)*2,l=i?-90:0,u=i?90:360;for(let d=l;d<=u;d+=HY){let l=i?r:d,u=i?d:r;if(!this.projectAngle(l,u,t,n)){a=!1;continue}let{x:f,y:p}=this.gridPoint;!a||Math.hypot(f-o,p-s)>c?e.moveTo(f,p):e.lineTo(f,p),a=!0,o=f,s=p}}projectAngle(e,t,n,r,i=!1){return JY(e,t,this.gridPoint),this.gridPoint.dot(this.viewDirection)<=.001||(this.gridPoint.project(this.camera),!Number.isFinite(this.gridPoint.x)||!Number.isFinite(this.gridPoint.y))||i&&(Math.abs(this.gridPoint.x)>=.98||Math.abs(this.gridPoint.y)>=.98)||Math.abs(this.gridPoint.x)>4||Math.abs(this.gridPoint.y)>4?!1:(this.gridPoint.x=(this.gridPoint.x+1)/2*n,this.gridPoint.y=(1-this.gridPoint.y)/2*r,!0)}degreesPerPixel(){return this.view.fov/Math.max(1,this.root.clientHeight)}arrowAt(e,t){if(!this.renderer||!this.arrows.visible||this.arrows.children.length===0)return null;let n=this.renderer.domElement.getBoundingClientRect(),r=new q((e-n.left)/n.width*2-1,-((t-n.top)/n.height)*2+1);this.raycaster.setFromCamera(r,this.camera);let i=this.raycaster.intersectObjects(this.arrows.children,!0)[0];return i?i.object.parent.name:null}pressArrow(e){let t=this.neighbours?.[e];t&&(this.emit(`step`,{key:e,entry:t.entry}),this.followArrows&&this.open(t.entry).catch(()=>{}))}onPointerDown=e=>{try{this.renderer?.domElement.setPointerCapture(e.pointerId)}catch{}this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.dragStart=this.pointers.size===1?{x:e.clientX,y:e.clientY}:null,this.pointers.size===2&&(this.pinchDistance=this.pinchSpan())};onPointerMove=e=>{let t=this.pointers.get(e.pointerId);if(!t){let t=this.arrowAt(e.clientX,e.clientY);t!==this.hovered&&this.renderer&&(this.hovered=t,this.renderer.domElement.style.cursor=t?`pointer`:``);return}let n=e.clientX-t.x,r=e.clientY-t.y;if(this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.pointers.size===1){if(this.gyroEnabled)return;let e=this.degreesPerPixel();this.setView({heading:this.view.heading-n*e,pitch:this.view.pitch+r*e})}else if(this.pointers.size===2){let e=this.pinchSpan();this.pinchDistance>0&&this.zoom(this.pinchDistance/e),this.pinchDistance=e}};onPointerUp=e=>{this.pointers.delete(e.pointerId);let t=this.dragStart;if(this.dragStart=null,this.pointers.size>0||!(!this.interactive||t!==null&&Math.hypot(e.clientX-t.x,e.clientY-t.y)<BY))return;let n=this.arrowAt(e.clientX,e.clientY);n&&this.pressArrow(n)};onPointerCancel=e=>{this.pointers.delete(e.pointerId),this.dragStart=null};pinchSpan(){let[e,t]=[...this.pointers.values()];return Math.hypot(e.x-t.x,e.y-t.y)}zoom(e){this.setView({fov:this.view.fov*e})}onWheel=e=>{e.preventDefault(),this.zoom(Math.exp(e.deltaY*.0015))};onKeyDown=e=>{let t=this.view.fov/10,{heading:n,pitch:r}=this.view,i={ArrowLeft:()=>this.setView({heading:n-t}),ArrowRight:()=>this.setView({heading:n+t}),ArrowUp:()=>this.setView({pitch:r+t}),ArrowDown:()=>this.setView({pitch:r-t}),"+":()=>this.zoom(.8),"-":()=>this.zoom(1.25)}[e.key];i&&(e.preventDefault(),i())}},ZY=Wx(()=>`${Gt()}/v1/groups/__planetary_systems_map__.json.gz`,{error:e=>`Failed to fetch planetary systems map: ${e.status}`}),QY=Wx(()=>`${Gt()}/v1/groups/__solar_system_map__.json.gz`,{error:e=>`Failed to fetch solar system map: ${e.status}`}),$Y=new Map;function eX(e,t,n){return .2126*e+.7152*t+.0722*n}async function tX(e,t){let n=t.strip_rows;if(n.transparency===void 0||n.color===void 0)return console.warn(`Ring strip ${e}/${t.strip} has no transparency or color row, no profile drawn:`,n),null;let r=await fetch(Qt(`/v1/rings/${e}/${t.strip}`,`rings`));if(!r.ok)throw Error(`${r.status} ${r.statusText}`);let i=await createImageBitmap(await r.blob()),a=document.createElement(`canvas`);a.width=i.width,a.height=i.height;let o=a.getContext(`2d`,{willReadFrequently:!0});if(!o)return console.warn(`Ring strip ${e}/${t.strip}: no 2D context, no profile drawn`),null;o.drawImage(i,0,0);let s=i.width,c=o.getImageData(0,0,s,i.height).data;i.close();let l=t.intensity_scale||1,u=new Float32Array(s),d=new Uint8ClampedArray(s*3),f=n.backscattered??n.color,p=new Float32Array(s),m=0;for(let e=0;e<s;e++){let t=(n.transparency*s+e)*4,r=(f*s+e)*4,i=Math.min(1,(1-c[t]/255)*l);u[e]=i>=1?1/0:-Math.log(1-i),p[e]=eX(c[r],c[r+1],c[r+2])/255,p[e]>m&&(m=p[e])}let h=.35;for(let e=0;e<s;e++){let t=(n.color*s+e)*4,r=m>0?h+(1-h)*(p[e]/m):1;d[e*3]=c[t]*r,d[e*3+1]=c[t+1]*r,d[e*3+2]=c[t+2]*r}return{inner:t.inner_radius_km,outer:t.outer_radius_km,tau:u,rgb:d}}async function nX(e){let t=(await tS(e,!1)).global?.rings??[];t.length||console.warn(`Ring strips for ${e}: no ring bundles on the object`);let n=[];for(let r of t)try{let t=await tX(e,r);t&&n.push(t)}catch(t){console.warn(`Ring strip ${e}/${r.strip} unavailable:`,t)}return n}var rX=-Math.log1p(-.02);function iX(e){let t=1/0,n=-1/0;for(let r of e){let e=r.tau.length,i=(r.outer-r.inner)/(e-1);for(let a=0;a<e;a++){if(r.tau[a]<rX)continue;let e=r.inner+a*i;e<t&&(t=e),e>n&&(n=e)}}return n>=t?{inner:t,outer:n}:null}function aX(e){let t=$Y.get(e);return t||(t=nX(e).catch(t=>(console.warn(`Ring strips for ${e} unavailable:`,t),$Y.delete(e),[])),$Y.set(e,t)),t}function oX({onScrub:e,onEnd:t}){let n=null,r=0,i=!1;function a(){i&&t(),n=null,i=!1}return{onpointerdown(e){e.pointerType!==`mouse`&&(n=e.clientX,r=e.clientY,i=!1)},onpointermove(t){t.pointerType===`mouse`||n===null||!i&&Math.hypot(t.clientX-n,t.clientY-r)<8||(i=!0,e(t.clientX,t.clientY))},onpointerup:a,onpointercancel:a,onpointerleave:a}}var sX=2.2,cX=84,lX=40,uX=4,dX=3,fX=1e4,pX=34,mX=7,hX=.42,gX=30;function _X(e,t,n){let r=1/0;for(let i of n)r=Math.min(r,Math.hypot(i.cx-e,i.cy-t));return r}function vX(e){return e>90?180-e:e}function yX(e){let t=Math.log10(e.domain[0]),n=Math.log10(e.domain[1])-t,r=r=>44+(Math.log10(Math.max(r/e.unitKm,1e-9))-t)/n*656,i=[];for(let t of[...e.bodies].sort((e,t)=>e.aKm-t.aKm)){let n=r(t.aKm),a=Math.max(sX,t.radiusKm*e.pxPerKm),o=120;if(t.tiltDeg>0){let r=Math.min(vX(t.tiltDeg)*e.pxPerDeg,cX),a=120-r,s=120+r;o=_X(n,a,i)>=_X(n,s,i)?a:s}i.push({...t,cx:n,cy:o,r:a})}let a=[];for(let t of i){if(!t.satellites?.length)continue;let n=t.rings?t.r*t.rings.outer*hX:0,r=t.cy-Math.max(t.r,n)-uX,i=[];for(let n of[...t.satellites].sort((e,t)=>t.radiusKm-e.radiusKm)){let a=Math.max(sX,n.radiusKm*e.pxPerKm);r-=a,i.push({...n,cx:t.cx,cy:r,r:a,hitY:0,hitHeight:0}),r-=a+dX}let o=Math.min(...i.map(e=>e.cy-e.r))-mX,s=Math.max(...i.map(e=>e.cy+e.r))+mX;i.forEach((e,t)=>{let n=t===0?s:(i[t-1].cy+e.cy)/2,r=t===i.length-1?o:(i[t+1].cy+e.cy)/2;e.hitY=r,e.hitHeight=n-r}),a.push({parent:t,moons:i,x:t.cx-pX/2,y:o,width:pX,height:s-o,perMoon:!t.grouped&&!t.satellitesLink&&i.some(e=>e.link)})}let o=e.bands.map(e=>{let t=r(e.innerKm),n=r(e.outerKm)-t,i=Math.max(n,gX);return{...e,x:t,width:n,hitX:t+(n-i)/2,hitWidth:i}}).sort((e,t)=>t.width-e.width),s=``;e.cloud?.points.forEach((t,n)=>{let i=t.aKm/e.unitKm;if(i<e.domain[0]||i>e.domain[1])return;let a=Math.min(Math.max(vX(t.tiltDeg),0)*e.pxPerDeg,cX),o=120+(n%2==0?-a:a);s+=`M${r(t.aKm).toFixed(1)} ${o.toFixed(1)}h0.01`});let c=e.primary.radiusKm*e.pxPerKm;return{bodies:i,moonZones:a,bands:o,cloudPath:s,primaryR:c,primaryCx:lX-c,xOf:r}}function bX(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function xX(e,t,n,r){for(let i of[!0,!1]){let a=null,o=r;for(let r of e.bodies){if(!!r.link!==i)continue;let e=Math.hypot(t-r.cx,n-r.cy),s=e<=r.r?e-fX:e-r.r;s>o||(a=r,o=s)}if(a)return a}return null}function SX(e,t,n){let r=xX(e,t,n,0);if(r)return{kind:`body`,id:r.id};for(let r of e.moonZones){if(!bX(r,t,n))continue;if(r.parent.grouped)return{kind:`body`,id:r.parent.id};if(!r.perMoon)return{kind:`stack`,id:r.parent.id};let e=r.moons.find(e=>n>=e.hitY&&n<=e.hitY+e.hitHeight);if(e)return{kind:`moon`,parent:r.parent.id,id:e.id}}let i=xX(e,t,n,16);if(i)return{kind:`body`,id:i.id};for(let r=e.bands.length-1;r>=0;r--){let i=e.bands[r];if(t>=i.hitX&&t<=i.hitX+i.hitWidth&&n>=26&&n<=206)return{kind:`band`,key:i.key}}return Math.hypot(t-e.primaryCx,n-120)<=e.primaryR?{kind:`primary`}:null}function CX(e,t,n){if(!n)return null;let{text:r}=e;switch(n.kind){case`primary`:return{cx:Math.max(44,t.primaryCx),cy:120-Math.min(t.primaryR,80),title:e.primary.name,sub:r.primary};case`body`:{let e=t.bodies.find(e=>e.id===n.id);if(!e)return null;let i=[r.distance(e.aKm)];return e.tiltDeg>90&&i.push(r.retrograde),e.grouped&&e.satellites?.length&&i.push(r.moons(e.satelliteCount??e.satellites.length)),{cx:e.cx,cy:e.cy-e.r-4,title:e.name,sub:i.join(` · `)}}case`stack`:{let e=t.moonZones.find(e=>e.parent.id===n.id);if(!e)return null;let i=e.x+e.width/2;return e.parent.satellitesTab?{cx:i,cy:e.y,title:e.parent.name,sub:r.moons(e.parent.satelliteCount??e.moons.length)}:{cx:i,cy:e.y,title:e.moons[0].name,sub:e.parent.name}}case`moon`:{let e=t.moonZones.find(e=>e.parent.id===n.parent),r=e?.moons.find(e=>e.id===n.id);return!e||!r?null:{cx:r.cx,cy:r.cy-r.r-4,title:r.name,sub:e.parent.name}}case`band`:{let e=t.bands.find(e=>e.key===n.key);return e?{cx:e.x+e.width/2,cy:44,title:e.name??e.label,sub:e.sub??`${r.distance(e.innerKm)}–${r.distance(e.outerKm)}`}:null}}}var wX=`http://www.w3.org/2000/svg`,TX=10,EX=-18,DX=1.2,OX=28,kX=6,AX=4,jX=18,MX=12,NX=190;function PX(e,t={},...n){let r=document.createElementNS(wX,e);for(let[e,n]of Object.entries(t))n!==void 0&&r.setAttribute(e,String(n));for(let e of n)e&&r.append(e);return r}function FX(e,t){return JSON.stringify(e)===JSON.stringify(t)}function IX(e,t){let n=new Map,r=(e,t)=>{(t?.href||t?.onclick)&&n.set(JSON.stringify(e),t)};for(let e of t.bands)r({kind:`band`,key:e.key},e);r({kind:`primary`},e.primary.link);for(let e of t.bodies)r({kind:`body`,id:e.id},e.link);for(let e of t.moonZones)if(!e.parent.grouped)if(!e.perMoon)r({kind:`stack`,id:e.parent.id},e.parent.satellitesLink);else for(let t of e.moons)r({kind:`moon`,parent:e.parent.id,id:t.id},t.link);return n}var LX=0,RX=class{root=document.createElement(`div`);svg=PX(`svg`);tip=document.createElement(`div`);tipTitle=document.createElement(`span`);tipSub=document.createElement(`span`);uid=`sm-system-map-${LX++}`;resize=new ResizeObserver(()=>{this.fitLabels(),this.placeTip()});model=null;placed=null;background=!1;hover=null;highlights=new Map;targets=new Map;links=new Map;shape=``;labels=[];constructor(){this.tip.className=`sm-system-map__tip`,this.tipTitle.className=`sm-system-map__tip-title`,this.tipSub.className=`sm-system-map__tip-sub`,this.tip.append(this.tipTitle,this.tipSub),this.tip.hidden=!0,this.root.append(this.svg,this.tip),this.resize.observe(this.root);let e=oX({onScrub:(e,t)=>this.setHover(this.hitAt(e,t)),onEnd:()=>this.setHover(null)});this.svg.addEventListener(`pointerdown`,e.onpointerdown),this.svg.addEventListener(`pointermove`,e.onpointermove),this.svg.addEventListener(`pointerup`,e.onpointerup),this.svg.addEventListener(`pointercancel`,e.onpointercancel),this.svg.addEventListener(`pointerleave`,e.onpointerleave);let t=[0,0],n=e=>{t=[e.clientX,e.clientY]};this.svg.addEventListener(`pointerdown`,n),this.svg.addEventListener(`pointerup`,n),this.svg.addEventListener(`pointermove`,e=>{n(e),e.pointerType===`mouse`&&this.setHover(this.hitAt(e.clientX,e.clientY))}),this.svg.addEventListener(`pointerleave`,e=>{e.pointerType===`mouse`&&this.setHover(null)}),this.svg.addEventListener(`click`,e=>{if(e.detail===0)return;let n=Math.abs(t[0]-e.clientX)<1&&Math.abs(t[1]-e.clientY)<1?this.hitAt(...t):this.hitAt(e.clientX,e.clientY);if(!n)return;let r=this.targets.get(JSON.stringify(n));r?.contains(e.target)||(e.stopPropagation(),e.preventDefault(),r?.dispatchEvent(new MouseEvent(`click`,{bubbles:!0,cancelable:!0,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,button:e.button})))},!0)}destroy(){this.resize.disconnect(),this.root.remove()}update(e,t){this.model=e,this.placed=yX(e);let n=IX(e,this.placed),r=JSON.stringify([JSON.stringify(e,(e,t)=>e===`href`?void 0:t),t,[...n].map(([e,t])=>[e,!!t.href,!!t.onclick])]);if(this.links=n,r===this.shape){for(let[e,t]of this.targets){let r=n.get(e)?.href;r&&t.setAttribute(`href`,r)}return}this.shape=r,this.background=t.variant===`background`,this.hover=null,this.root.className=this.background?`sm-system-map sm-system-map--background`:`sm-system-map`,this.draw(e,this.placed,t.ariaLabel),this.fitLabels(),this.placeTip()}draw(e,t,n){let r=this.background;this.highlights=new Map,this.targets=new Map,this.labels=[];let i=this.svg;i.replaceChildren(),i.setAttribute(`viewBox`,r&&e.backgroundView||`0 0 720 240`),i.setAttribute(`preserveAspectRatio`,r?e.backgroundFit===`fit`?`xMidYMid meet`:e.backgroundView?`xMinYMid slice`:`xMidYMid slice`:`xMidYMid meet`),i.setAttribute(`class`,`sm-system-map__svg`),i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,n),i.setAttribute(`data-vaul-no-drag`,``);let a=(t,n)=>PX(`stop`,{offset:t,"stop-color":e.primary.color,"stop-opacity":n});i.append(PX(`defs`,{},PX(`radialGradient`,{id:`${this.uid}-primary`,gradientUnits:`userSpaceOnUse`,cx:t.primaryCx,cy:120,r:t.primaryR},a(`0%`,1),a(Math.max(0,1-TX/t.primaryR),.85),a(`100%`,.35)),PX(`pattern`,{id:`${this.uid}-band`,width:9,height:9,patternUnits:`userSpaceOnUse`},PX(`circle`,{cx:2,cy:2,r:.9,fill:`currentColor`,opacity:.55}),PX(`circle`,{cx:6.5,cy:6,r:.9,fill:`currentColor`,opacity:.55})))),r||this.drawAxis(e,t),t.cloudPath&&i.append(PX(`path`,{d:t.cloudPath,stroke:e.cloud?.color,"stroke-width":DX*2,"stroke-linecap":`round`,fill:`none`,opacity:.45,"pointer-events":`none`}));for(let e of t.bands){let t=PX(`rect`,{x:e.x,y:26,width:e.width,height:180,fill:`url(#${this.uid}-band)`,class:`sm-system-map__band sm-system-map__band--${e.tone}`});if(r){i.append(t);continue}let n=PX(`text`,{x:e.x+e.width/2,y:232,"text-anchor":`middle`,"font-size":jX,class:`sm-system-map__band-label sm-system-map__band-label--${e.tone}`});n.textContent=e.label,this.labels.push(n),i.append(this.target(e,e.name??e.label,{kind:`band`,key:e.key},t,PX(`rect`,{x:e.hitX,y:26,width:e.hitWidth,height:180,fill:`transparent`}),n))}let o=PX(`circle`,{cx:t.primaryCx,cy:120,r:t.primaryR,fill:`url(#${this.uid}-primary)`});i.append(r?o:this.target(e.primary.link,e.primary.name,{kind:`primary`},o));for(let e of t.bodies){if(!e.rings)continue;let t=e.r*(e.rings.inner+e.rings.outer)/2;i.append(PX(`ellipse`,{cx:e.cx,cy:e.cy,rx:t,ry:t*hX,transform:`rotate(${EX} ${e.cx} ${e.cy})`,fill:`none`,stroke:`#d9c89f`,"stroke-width":e.r*(e.rings.outer-e.rings.inner),opacity:.45}))}let s=new Map(t.moonZones.map(e=>[e.parent.id,e]));for(let e of t.bodies)i.append(this.body(e,s.get(e.id)));for(let e of t.moonZones)e.parent.grouped||this.stack(e)}drawAxis(e,t){for(let n of e.ticks){let r=t.xOf(n*e.unitKm),i=PX(`text`,{x:r,y:16,"text-anchor":`middle`,"font-size":16,fill:`currentColor`,opacity:.85});i.textContent=String(n),this.svg.append(PX(`line`,{x1:r,x2:r,y1:20,y2:212,stroke:`currentColor`,"stroke-width":.5,opacity:.12}),i)}let n=PX(`text`,{x:700,y:16,"text-anchor":`end`,"font-size":14,fill:`currentColor`,opacity:.65});n.textContent=e.axisLabel,this.svg.append(n)}body(e,t){let n=e.reference?PX(`circle`,{cx:e.cx,cy:e.cy,r:e.r+1,fill:`none`,stroke:e.color,"stroke-width":1.2,class:`sm-system-map__reference`}):PX(`circle`,{cx:e.cx,cy:e.cy,r:e.r,fill:e.color});if(this.background)return!t||!e.grouped?n:PX(`g`,{},n,...this.moonDots(t));let r={kind:`body`,id:e.id},i=this.highlight(r,PX(`circle`,{cx:e.cx,cy:e.cy,r:e.r+3.5,fill:`none`,stroke:`currentColor`,"stroke-width":1,opacity:.8})),a=PX(`circle`,{cx:e.cx,cy:e.cy,r:e.r+16,fill:`transparent`});return!t||!e.grouped?this.target(e.link,e.name,r,i,n,a):this.target(e.link,e.name,r,this.highlight(r,this.zoneWash(t)),i,n,a,...this.moonDots(t),this.zoneHit(t))}stack(e){if(this.background){this.svg.append(...this.moonDots(e));return}let t=e.parent;if(e.perMoon){this.svg.append(...this.moonDots(e));for(let n of e.moons){let r={kind:`moon`,parent:t.id,id:n.id};this.svg.append(this.target(n.link,n.name,r,this.highlight(r,PX(`circle`,{cx:n.cx,cy:n.cy,r:n.r+2.5,fill:`none`,stroke:`currentColor`,"stroke-width":1,opacity:.8})),PX(`rect`,{x:e.x,y:n.hitY,width:e.width,height:n.hitHeight,fill:`transparent`})))}return}let n={kind:`stack`,id:t.id},r=e.moons[0];this.svg.append(this.highlight(n,this.zoneWash(e)),...this.moonDots(e),this.target(t.satellitesLink,t.satellitesTab?`${t.name} · ${this.model.text.moons(t.satelliteCount??e.moons.length)}`:r.name,n,this.zoneHit(e)))}moonDots(e){return e.moons.map(e=>PX(`circle`,{cx:e.cx,cy:e.cy,r:e.r,fill:e.color}))}zoneWash(e){return PX(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:4,fill:`currentColor`,opacity:.1,"pointer-events":`none`})}zoneHit(e){return PX(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,fill:`transparent`})}highlight(e,t){let n=JSON.stringify(e),r=this.highlights.get(n);return r?r.push(t):this.highlights.set(n,[t]),t.style.display=`none`,t}target(e,t,n,...r){let i=!!(e?.href||e?.onclick),a=e?.href?PX(`a`,{href:e.href,"aria-label":t}):i?PX(`g`,{role:`button`,tabindex:0,"aria-label":t,class:`sm-system-map__button`}):PX(`g`);if(a.append(...r),!i)return a;let o=JSON.stringify(n);return this.targets.set(o,a),a.addEventListener(`focus`,()=>this.setHover(n)),a.addEventListener(`blur`,()=>{FX(this.hover,n)&&this.setHover(null)}),a.addEventListener(`click`,e=>this.links.get(o)?.onclick?.(e)),e?.href||a.addEventListener(`keydown`,e=>{let t=e.key;t!==`Enter`&&t!==` `||(e.preventDefault(),a.dispatchEvent(new MouseEvent(`click`,{bubbles:!0})))}),a}setHover(e){if(FX(this.hover,e))return;for(let e of this.highlights.get(JSON.stringify(this.hover))??[])e.style.display=`none`;this.targets.get(JSON.stringify(this.hover))?.removeAttribute(`data-near`),this.hover=e;for(let t of this.highlights.get(JSON.stringify(e))??[])t.style.display=``;let t=this.targets.get(JSON.stringify(e));t?.setAttribute(`data-near`,``),this.svg.classList.toggle(`sm-system-map__svg--near`,!!t),this.placeTip()}hitAt(e,t){if(!this.placed||this.background)return null;let n=this.svg.getBoundingClientRect();if(!n.width||!n.height)return null;let r=(e-n.left)/n.width*720,i=(t-n.top)/n.height*240;return SX(this.placed,r,i)}fitLabels(){for(let e of this.labels){let t=0;e.setAttribute(`font-size`,String(jX));try{t=e.getComputedTextLength()}catch{}if(!t)continue;if(t>NX){let n=Math.max(MX,jX*NX/t);e.setAttribute(`font-size`,String(n)),t*=n/jX}let n=Number(e.dataset.centre??e.getAttribute(`x`));e.dataset.centre=String(n);let r=t/2,i=Math.min(Math.max(n,r+AX),Math.max(r,720-r-AX));e.setAttribute(`x`,String(i))}}placeTip(){let e=this.model&&this.placed&&!this.background?CX(this.model,this.placed,this.hover):null;if(this.tip.hidden=!e,!e)return;this.tipTitle.textContent=e.title,this.tipSub.textContent=e.sub?` · ${e.sub}`:``;let t=this.root.clientWidth,n=t/720;this.tip.style.maxWidth=`${Math.max(0,t-2*kX)}px`;let r=this.tip.offsetWidth/2,i=Math.min(Math.max(e.cx*n,r+kX),Math.max(r,t-r-kX));this.tip.style.left=`${i}px`,this.tip.style.top=`${Math.max(4,e.cy*n-OX)}px`}};function zX(e,t){return{planetId:e.primary.id,planetName:t,planetRadiusKm:e.primary.radius_km,planetColor:U_[e.primary.id]??`#cccccc`,moons:e.moons.map(e=>({id:e.id,name:e.id,aRp:e.a_rp,tiltDeg:e.tilt_deg,radiusKm:e.radius_km,color:U_[e.id]??e.color??`#cccccc`})),rings:e.rings?{innerRp:e.rings.inner_rp,outerRp:e.rings.outer_rp}:null,moonCount:e.moon_count}}function BX(e,t){if(!e.rings||!t.length)return e.rings;let n=iX(t),r=e.planetRadiusKm;return n&&{innerRp:n.inner/r,outerRp:n.outer/r}}var VX=14,HX=1.001,UX=.62,WX=[1,2,3,5,10,20,30,50,100,200,300,500,1e3,2e3,5e3],GX=`0 96 320 144`,KX=`0 96 720 144`,qX=[1,100];function JX(e,t){let n=Math.min(...e.moons.map(e=>e.aRp)),r=Math.max(...e.moons.map(e=>e.aRp));for(let i of t)n=Math.min(n,i.innerKm/e.planetRadiusKm),r=Math.max(r,i.outerKm/e.planetRadiusKm);return!Number.isFinite(n)||!Number.isFinite(r)?qX:(r<=n&&(n/=2,r*=2),n=n<=HX?1:n,[n>1?10**(Math.log10(n)-.12):1,10**(Math.log10(r)+.12)])}function YX(e,t){let n=e.planetRadiusKm,r=JX(e,t.bands);return{primary:{id:e.planetId,name:e.planetName,radiusKm:n,color:e.planetColor,link:t.primaryLink},bodies:e.moons.map(e=>({id:e.id,name:e.name,aKm:e.aRp*n,tiltDeg:e.tiltDeg,radiusKm:e.radiusKm,color:e.color,link:t.moonLink?.(e)})),bands:t.bands,cloud:t.cloud,unitKm:n,domain:r,ticks:WX.filter(e=>e>=r[0]&&e<=r[1]),axisLabel:t.axisLabel,pxPerKm:VX/Math.max(...e.moons.map(e=>e.radiusKm).filter(e=>e>0),1),pxPerDeg:UX,text:t.text,backgroundView:t.wide?KX:GX,backgroundFit:t.wide?`fit`:`slice`}}var XX=224e-6,ZX=1.8,QX=[.3,50],$X=[.3,1,3,10,30],eZ=`#ffdd44`;function tZ(e){let t=e.replace(/^\d+\s+/,``);return t===t.toUpperCase()&&/[A-Z]/.test(t)?t.charAt(0)+t.slice(1).toLowerCase():t}function nZ(e){return e.color||U_[e.id]||`#cccccc`}function rZ(e,t){let n=new Map,r=new Map(e.objects.map(e=>[e.id,e]));for(let i of e.objects){if(i.kind!==`moon`||!i.parent)continue;let e=n.get(i.parent)??{satellites:[],count:r.get(i.parent)?.moon_count,tab:!1};e.satellites.push({id:i.id,name:t(i),radiusKm:i.diameter_km/2,color:nZ(i)}),e.tab||=!!i.link_parent,n.set(i.parent,e)}return n}function iZ(e,t){let n=e.objects.find(e=>e.kind===`star`);if(!n)return null;let r=rZ(e,t.name),i=t.stack??(e=>r.get(e.id)),a=e.objects.filter(e=>e.kind!==`moon`&&e.kind!==`star`&&(t.keep?.(e)??!0)).map(e=>{let n=i(e);return{id:e.id,name:t.name(e),aKm:e.a*_g,tiltDeg:e.i,radiusKm:e.diameter_km/2,color:nZ(e),rings:e.rings,satellites:n?.satellites,satelliteCount:n?.count,satellitesTab:n?.tab??!1,...t.links(e,n)}});return{primary:{id:n.id,name:t.name(n),radiusKm:n.diameter_km/2,color:eZ,link:t.primaryLink},bodies:a,bands:e.belts.map(e=>({key:e.slug,innerKm:e.inner_au*_g,outerKm:e.outer_au*_g,tone:e.kind===`kuiper_belt`?`sky`:`muted`,...t.band(e)})),unitKm:_g,domain:QX,ticks:$X,axisLabel:t.text.axisAu,pxPerKm:XX,pxPerDeg:ZX,text:t.text}}function aZ(e){return{id:e.id,name:e.name??e.id,moon:e.moon??!1,aAu:e.aAu??0,tiltDeg:e.tiltDeg??0,radiusKm:e.radiusKm??0,color:e.color??U_[e.id]??`#cccccc`,parent:e.parent}}var oZ=4,sZ=10,cZ={inner:[.6,5.5],outer:[4.5,55]},lZ=[.1,.2,.3,.5,1,2,3,5,10,20,30,50,100,200,500,1e3],uZ=.9,dZ=.76;function fZ(e,t){return Math.log(e/t[0])/Math.log(t[1]/t[0])}var pZ=`naif-599`;function mZ(e,t,n,r=[]){if(!n)return[];let i=new Set([...e.objects.map(e=>e.id),...r]);for(let e of Object.values(t)){i.add(e.primary.id);for(let t of e.moons)i.add(t.id)}return[...n].filter(e=>!i.has(e))}function hZ(e){let t=e.type===`moon`,n=e.orbit?.parent_id,r=n===void 0||n===`naif-10`||n===`naif-0`?e.orbit?.a??e.orbit?.q:void 0;if(r===void 0&&!t)return null;let i=e.radii;return{id:e.id,name:tZ(e.name??e.id),moon:t,aAu:r??0,tiltDeg:e.orbit?.i??0,radiusKm:i?(i.a+i.b+i.c)/3:(e.sbdb?.diameter??0)/2,color:U_[e.id]??e.sbdb?.color??e.color??`#cccccc`,parent:e.orbit?.parent_id}}var gZ=.92;function _Z(e,t){return e<t*gZ?`inner`:`outer`}function vZ(e,t){return Object.values(e).find(e=>e.primary.id===t)}function yZ(e){return e.kind===`zone`?`zone:${e.zone}`:`${e.kind}:${e.id}`}var bZ=class{targets=new Map;constructor(e,t,n){this.data=e,this.options=t,this.pick=n}has(e){return!this.options.bodies||this.options.bodies.has(e)}name(e,t){return this.options.names[e]??(t?tZ(t):e)}named(e,t){return this.options.names[e]??t}link(e){return this.targets.set(yZ(e),e),{onclick:()=>this.pick(e)}}body(e,t){return this.has(e)?this.link({kind:`body`,id:e,name:t}):void 0}stack(e,t){if(t&&!this.options.bodies)return t;let n=(vZ(this.data.systems,e)?.moons??[]).filter(e=>this.has(e.id)).map(e=>({id:e.id,name:this.name(e.id),radiusKm:e.radius_km,color:U_[e.id]??e.color??`#cccccc`}));if(n.length)return n.sort((e,t)=>t.radiusKm-e.radiusKm),{satellites:n.slice(0,oZ),count:n.length,tab:!0}}links(e,t,n){if(!n)return{link:this.body(e,t)};let r=()=>this.link({kind:`system`,id:e,name:t});if(this.options.grouping===`systems`)return{link:r(),grouped:!0};let i=n.satellites[0];return{link:this.body(e,t),satellitesLink:n.tab?r():this.body(i.id,i.name)}}built(e,t){return{model:e,targets:[...this.targets.values()],label:t}}};function xZ(e,t,n,r){let i=new bZ(e,t,r),a=e=>i.name(e.id,e.name),o=rZ(e.solar,a),s=new Map(e.solar.objects.map(e=>[e.id,i.stack(e.id,o.get(e.id))])),c=e.solar.objects.find(e=>e.kind===`star`),l=e=>{let t=e===`inner`?n.zoneInner:n.zoneOuter;return{label:t,sub:``,...i.link({kind:`zone`,zone:e,name:t})}},u=iZ(e.solar,{text:n,name:a,primaryLink:c&&i.body(c.id,a(c)),keep:e=>i.has(e.id)||!!s.get(e.id),stack:e=>s.get(e.id),links:(e,t)=>i.links(e.id,a(e),t),band:e=>t.zones===`belts`?{label:e.label}:l(e.kind===`kuiper_belt`?`outer`:`inner`)});if(!u)throw Error(`spacemap: the Solar System map names no Sun`);return i.built(u,n.solarSystem)}function SZ(e,t,n,r,i,a){let o=vZ(e.systems,t);if(!o)throw Error(`spacemap: no planetary system around ${t}`);let s=new bZ(e,r,a),c=zX(o,s.name(t,n[t]));c.moons=c.moons.filter(e=>s.has(e.id)).map(e=>({...e,name:s.name(e.id,n[e.id])}));let l=c.planetRadiusKm,u=e.ringProfiles?BX(c,e.ringProfiles):c.rings,d=u?[{key:`rings`,label:i.rings,innerKm:u.innerRp*l,outerKm:u.outerRp*l,tone:`amber`}]:[],f=YX(c,{text:i,axisLabel:i.axisRadii,bands:d,primaryLink:s.body(t,c.planetName),moonLink:e=>s.body(e.id,e.name)});return f.ticks=f.ticks.filter(e=>fZ(e,f.domain)<dZ),s.built(f,c.planetName)}function CZ(e,t,n,r,i){let a=new bZ(e,n,i),{solar:o,extras:s}=e,c=o.objects.find(e=>e.kind===`star`),l=o.objects.find(e=>e.id===pZ)?.a;if(!c||l===void 0)throw Error(`spacemap: the Solar System map names no Sun or no Jupiter`);let u=o.objects.filter(e=>e.kind===`dwarf`||e.kind===`asteroid`).map(e=>({id:e.id,name:a.name(e.id,e.name),aAu:e.a,tiltDeg:e.i,radiusKm:e.diameter_km/2,color:nZ(e)}));for(let e of s)e.moon||u.some(t=>t.id===e.id)||e.aAu>0&&u.push({...e,name:a.named(e.id,e.name)});let d=[];for(let e of u){if(_Z(e.aAu,l)!==t)continue;let n={...e,aKm:e.aAu*_g},r=a.stack(e.id);if(r){d.push({...n,satellites:r.satellites,satelliteCount:r.count,satellitesTab:!0,...a.links(e.id,e.name,r)});continue}let i=s.filter(t=>t.moon&&t.parent===e.id&&a.has(t.id)).map(e=>{let t=a.named(e.id,e.name);return{...e,name:t,link:a.body(e.id,t)}});!a.has(e.id)&&!i.length||d.push({...n,link:a.body(e.id,e.name),satellites:i.length?i:void 0})}let[f,p]=cZ[t],m=[Math.min(f,...d.map(e=>e.aKm/_g*.85)),Math.max(p,...d.map(e=>e.aKm/_g*1.15))],h=e=>e>=m[0]&&e<=m[1],g=sZ/Math.max(...d.map(e=>e.radiusKm),1);for(let e of o.objects)e.kind!==`planet`||!h(e.a)||d.push({id:e.id,name:a.name(e.id,e.name),aKm:e.a*_g,tiltDeg:0,radiusKm:0,color:nZ(e),reference:!0});let _=t===`inner`?r.zoneInner:r.zoneOuter;return a.built({primary:{id:c.id,name:a.name(c.id,c.name),radiusKm:c.diameter_km/2*XX/g,color:eZ},bodies:d,bands:o.belts.filter(e=>h(e.inner_au)&&h(e.outer_au)).map(e=>({key:e.slug,label:e.label,innerKm:e.inner_au*_g,outerKm:e.outer_au*_g,tone:e.kind===`kuiper_belt`?`sky`:`muted`})),unitKm:_g,domain:m,ticks:lZ.filter(e=>h(e)&&fZ(e,m)<uZ),axisLabel:r.axisAu,pxPerKm:g,pxPerDeg:ZX,text:r},_)}var wZ=new WeakMap,TZ=.01;function EZ(){let{messages:e,locale:t}=i(),n=new Intl.NumberFormat(t(),{maximumSignificantDigits:3}),r=new Intl.NumberFormat(t(),{style:`unit`,unit:`kilometer`,maximumSignificantDigits:3}),a=e.unit_symbol_astronomical_unit();return{primary:e.planetary_system_primary(),retrograde:e.planetary_system_retrograde(),moons:t=>e.system_map_moons({count:t}),distance:e=>{let t=e/_g;return t>0&&t<TZ?r.format(e):`${n.format(t)} ${a}`},axisAu:e.system_map_axis_au(),solarSystem:e.system_map_solar_system(),rings:e.tab_rings(),axisRadii:e.planetary_system_axis_unit(),zoneInner:e.system_map_zone_inner(),zoneOuter:e.system_map_zone_outer()}}var DZ=class{chart=new RX;listeners=new Map;view;bodies;names;grouping;zones;rings;places;targets=[];extras=new Map;queue=Promise.resolve();disposed=!1;constructor(e={}){this.view=e.view??{kind:`solar-system`},this.bodies=e.bodies?new Set(e.bodies):null,this.names=e.names??{},this.grouping=e.grouping??`bodies`,this.zones=e.zones??`belts`,this.rings=e.rings??`all`,this.places=(e.places??[]).map(aZ)}mount(e){e.append(this.chart.root)}remove(){this.disposed=!0,this.chart.destroy()}load(){return this.draw()}async setView(e){await this.draw(e)}getView(){return this.view}setBodies(e){let t=e?new Set(e):null;return this.draw(void 0,t).catch(()=>{})}getTargets(){return[...this.targets]}draw(e,t){let n=this.queue.then(()=>(t!==void 0&&(this.bodies=t),this.drawNow(e??this.view)));return this.queue=n.catch(()=>{}),n}async drawNow(e){let t;try{t=await this.build(e)}catch(e){let t=e instanceof Error?e:Error(String(e));throw this.disposed||this.emit(`error`,t),t}if(this.disposed)return;let n=JSON.stringify(e)!==JSON.stringify(this.view);this.view=e,this.targets=t.targets,this.chart.update(t.model,{ariaLabel:t.label}),n&&this.emit(`viewchange`,e)}async build(e){let[t,n]=await Promise.all([QY(),ZY()]),r={bodies:this.bodies,names:this.names,grouping:this.grouping,zones:this.zones},i=EZ(),a=e=>this.emit(`select`,e),o={solar:t,systems:n,extras:[]};switch(e.kind){case`solar-system`:return xZ(o,r,i,a);case`system`:{let t=this.rings===`visible`&&!!vZ(n,e.id)?.rings,[s,c]=await Promise.all([this.exportedNames(e.id,n),t?aX(e.id):void 0]);return SZ({...o,ringProfiles:c},e.id,s,r,i,a)}case`zone`:{let s=mZ(t,n,this.bodies,this.places.map(e=>e.id)),c=(await Promise.all(s.map(e=>this.extra(e)))).filter(e=>e!==null),l=[...this.places,...c],u=mZ(t,n,new Set(l.flatMap(e=>e.moon&&e.parent?[e.parent]:[])),l.map(e=>e.id)),d=await Promise.all(u.map(e=>this.extra(e))),f=[...l,...d.filter(e=>e!==null)];return CZ({...o,extras:f},e.zone,r,i,a)}}}extra(e){let t=this.extras.get(e);return t||(t=tS(e,!1).then(t=>{if(!t.global)throw Error(`spacemap: no such body as ${e}`);return hZ(t.global)}).catch(t=>(this.extras.delete(e),this.emit(`error`,t instanceof Error?t:Error(String(t))),null)),this.extras.set(e,t)),t}async exportedNames(e,t){if(![e,...(vZ(t,e)?.moons??[]).map(e=>e.id)].some(t=>!(t in this.names)&&(t===e||!this.bodies||this.bodies.has(t))))return{};try{let{global:t,localized:n}=await tS(e,!0,i().locale()),r={};for(let e of t?.notable_moons??[])e.id&&(r[e.id]=e.name);Object.assign(r,n?.notable_moon_names);let a=n?.name??t?.name;return a&&(r[e]=a),r}catch{return{}}}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=((...e)=>{r(),t(...e)});wZ.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners.get(e);if(n){n.delete(t);for(let e of n)wZ.get(e)===t&&n.delete(e)}}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of[...n])e(...t)}};function OZ(e,t){let n=e.credits.orbitSourceParents.get(t);if(!n)return!0;let r=e.visibility.focusedSystemId;for(let t of n)if(e.bodies.isInSystem(t,r))return!0;return!1}function kZ(e){let t=e.credits,n=new Set;for(let r of Tn){if(!t.orbitSources.has(r))continue;let{archive:i,scoped:a}=wn[r];if(!(a&&!OZ(e,r)))if(i)n.add(i);else for(let e of cn)e&&t.probeArchives.has(e)&&n.add(e)}return[...n]}function AZ(e,t){let n=e.visibility.focusedSystemId,r=e.visibility.focusedBodyId;return[...t].filter(e=>e.bodyId===r||n&&e.systemId===n)}function jZ(e,t=En){let n=e.credits;n.imageryVersion,n.modelVersion;let r=[...new Set(kZ(e).map(e=>t[e]))],i=new Set;for(let t of AZ(e,n.imagery.values()))i.add(t.organisation);let a=e.visibility.focusedBodyId,o=a?n.model.get(a):void 0;return o&&i.add(o.organisation),{orbits:r,imagery:[...i].sort()}}var MZ=`https://spacemap.co`,NZ=`https://spacemap.co/credits`;function PZ(){let e=document.createElement(`div`);return e.className=`sm-attribution`,e}function FZ(){let e=document.createElement(`span`);return e.className=`sm-attribution__group`,e}function IZ(e,t,n){let r=document.createElement(`a`);return r.href=e,r.target=`_blank`,r.rel=`noopener noreferrer`,r.textContent=t,n&&(r.className=n),r}var LZ=class{stop=null;onAdd(e){let t=PZ(),n=FZ(),r=FZ();return t.append(IZ(MZ,`spacemap`,`sm-attribution__home`),n,r,IZ(NZ,i().messages.credits_see_all())),this.stop=st(()=>{at(()=>{let t=jZ(e.ctx);RZ(n,i().messages.attribution_orbits(),t.orbits),RZ(r,i().messages.attribution_imagery(),t.imagery)})}),t}onRemove(){this.stop?.(),this.stop=null}getDefaultPosition(){return`bottom-right`}};function RZ(e,t,n){if(e.hidden=n.length===0,e.hidden)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${t}:`,e.replaceChildren(r,` ${n.join(` · `)}`)}var zZ=class{off=null;onAdd(e){let t=PZ(),n=FZ();t.append(IZ(MZ,`spacemap`,`sm-attribution__home`),n,IZ(NZ,i().messages.credits_see_all()));let r=()=>{let t=[...new Set(e.credits.map(e=>e.organisation))].filter(Boolean);if(n.hidden=t.length===0,n.hidden)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${i().messages.attribution_imagery()}:`,n.replaceChildren(r,` ${t.join(` · `)}`)};return r(),this.off=e.on(`layerschange`,r),t}onRemove(){this.off?.(),this.off=null}getDefaultPosition(){return`bottom-right`}};function BZ(e){if(e)try{let t=typeof window<`u`?window.location.href:`https://spacemap.co`,{protocol:n}=new URL(e,t);return n===`http:`||n===`https:`?e:void 0}catch{return}}var VZ=class{off=null;onAdd(e){let t=PZ(),n=FZ();t.append(IZ(MZ,`spacemap`,`sm-attribution__home`),n,IZ(NZ,i().messages.credits_see_all()));let r=()=>{let t=e.getCurrent();if(n.hidden=!t?.credit,!t?.credit)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${i().messages.attribution_imagery()}:`;let a=BZ(t.credit_url),o=a?IZ(a,t.credit):t.credit;n.replaceChildren(r,` `,o)};return r(),this.off=e.on(`load`,r),t}onRemove(){this.off?.(),this.off=null}getDefaultPosition(){return`bottom-right`}};function HZ(e){return e}function UZ(e){let t=[...e.samples].sort((e,t)=>e.jd-t.jd);return{body:e.body??`naif-10`,offsetKm:e=>KZ(t,e)}}function WZ(e){return{body:e.body??`naif-10`,offsetKm:t=>gB(e.elements,t)?.r??null}}function GZ(e,t){let n=hg(e,t);return n.error!==fg.None&&console.warn(`spacemap: SGP4 will not take this element set (error=${n.error})`),{body:ev,offsetKm:e=>{if(n.error!==fg.None)return null;let t=i_(n,e);return t&&e_(t[0],t[1],t[2],e)}}}function KZ(e,t){let n=e.length;if(n<2||t<e[0].jd||t>e[n-1].jd)return null;let r=0,i=n-1;for(;r<i;){let n=r+i>>1;e[n].jd<t?r=n+1:i=n}let a=Math.max(r,1),o=e[a-1],s=e[a],c=s.jd-o.jd;if(c<=0)return s.km;let l=(t-o.jd)/c,u=l*l,d=u*l,f=2*d-3*u+1,p=d-2*u+l,m=-2*d+3*u,h=d-u,g=[0,0,0];for(let t=0;t<3;t++){let n=o.km[t],r=s.km[t],i=qZ(e,a-1,t),l=qZ(e,a,t);g[t]=f*n+p*c*i+m*r+h*c*l}return g}function qZ(e,t,n){let r=e[t-1]??e[t],i=e[t+1]??e[t],a=i.jd-r.jd;return a<=0?0:(i.km[n]-r.km[n])/a}function JZ(e){return e/_g}var YZ=null,XZ=Promise.resolve();function ZZ(e){let t=XZ.then(e,e);return XZ=t.catch(()=>{}),t}async function QZ(e){let t=Ag(e),n=await gx();if(!YZ){let e=_x(n);e.size>0&&(YZ=new Ax(e))}return await YZ?.load(t),{jd:t,metadata:n,chebyshev:YZ}}function $Z(e,t){return!(e!==void 0&&t-2451545<e)}async function eQ(e,{jd:t,metadata:n}){let r=n.position.zones.moons,i=r&&sx(r);if(!i)return null;let a=await Bb(`moons`,null,0,tx(i)?String(rx(i,t)):null);for(let t=0;t<a.rowCount;t++)if(Fh(a,t)===e)return V_(a,t,new Map,`naif`);return null}function tQ(e,t){return!$Z(e.visibleFromDays,t)||!wV(e,t)?null:e.satrec?o_(e.satrec,t):e.q==null?e.a===0?[0,0,0]:S_(e,t):C_(e,t)}async function nQ(e,t){let{jd:n}=t;if(t.chebyshev?.has(e)){let r=t.chebyshev.body(e,n);if(r&&!$Z(r.visibleFromDays,n))return null;let i=r&&Wy(r,n);if(i){let{radiusKm:e,objectType:t}=r;return{data:{radiusKm:e,objectType:t,orbitalSource:W.SPICE},parentId:`naif-${r.parentId}`,offset:i}}if(e.startsWith(`naif-`))return null}let r=(e.startsWith(`naif-`)?await eQ(e,t):null)??pS(e,await tS(e,!1)),i=r&&tQ(r,n);return i?{data:r,parentId:r.parentId,offset:i}:null}async function rQ(e,t,n=new Set){if(n.has(e))return null;let r=await nQ(e,t);if(!r)return null;if(r.parentId===`naif-0`)return{data:r.data,centre:r.offset,parents:[]};let i=await rQ(r.parentId,t,new Set(n).add(e));if(!i)return null;let[a,o,s]=i.centre;return{data:r.data,centre:[a+r.offset[0],o+r.offset[1],s+r.offset[2]],parents:[r.parentId,...i.parents]}}function iQ(e,{parents:t},n){let r=new Set(t);for(let{body:e}of n.chebyshev?.bodiesAt(n.jd)??[])t.includes(`naif-${e.parentId}`)&&r.add(e.id);return r.delete(e),[...r]}async function aQ(e){let[t]=await Promise.all([tS(e,!1),Lv()]);return{orientation:t.global?.orientation,nutPrec:Rv(e,t.global?.nut_prec)}}async function oQ(e,t){let n=await rQ(e.body,t);if(!n)return null;let r=`latitude`in e?await aQ(e.body):{};return nW(e,{data:n.data,...r},n.centre,t.jd)}function sQ(e,t,n){return ZZ(async()=>{let r=await QZ(n),i=await oQ(e,r),a=i&&await oQ(t,r);return i&&a?aW([a[0]-i[0],a[1]-i[1],a[2]-i[2]]):null})}async function cQ(e,t,n){let r=await sQ(e,t,n);return r&&Math.hypot(...r)}function lQ(e,t){return ZZ(async()=>{if(e===`naif-10`)return null;let n=await QZ(t),r=await rQ(e,n),i=r&&await rQ(`naif-10`,n);return!r||!i?null:dq({data:r.data,...await aQ(e)},r.centre,i.centre,n.jd)})}function uQ(e,t){return ZZ(async()=>{if(e===`naif-10`)return null;let n=await QZ(t),r=await rQ(e,n),i=r&&await rQ(`naif-10`,n);if(!r||!i)return null;let a=({data:e,centre:t})=>({centre:aW([t[0]-r.centre[0],t[1]-r.centre[1],t[2]-r.centre[2]]),radiusKm:e.radiusKm}),o=[];for(let t of iQ(e,r,n)){let e=await rQ(t,n);e&&e.data.radiusKm>0&&o.push(a(e))}return hq(r.data.radiusKm>0?r.data.radiusKm:0,a(i),o)})}var dQ=null;function fQ(e=Nv){return dQ||(dQ=(async()=>{let t=await e(`${Gt()}/v1/panoramas.json`);if(!t.ok)throw Error(`Failed to load panoramas.json: ${t.status}`);return(await t.json()).bodies??[]})(),dQ.catch(()=>dQ=null),dQ)}async function pQ(e){return(await tS(e,!1)).global?.panoramas??[]}async function mQ(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,controls:l,events:u,...d}=e,f=vQ(t);yQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let p=new Nq(d);if(p.mount(f),p.webglError)throw p.unmount(),Error(`spacemap: WebGL is not available`);for(let[e,t]of Object.entries(u??{}))p.on(e,t);p.attribution=new LZ,p.addControl(p.attribution);for(let e of l??[])p.addControl(e);return await p.open(),p.applyInitialView(),await fG(),p}async function hQ(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,controls:l,events:u,...d}=e,f=vQ(t);yQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let p=new fY(d);p.mount(f);for(let[e,t]of Object.entries(u??{}))p.on(e,t);p.attribution=new zZ,p.addControl(p.attribution);for(let e of l??[])p.addControl(e);return await p.load(),p}async function gQ(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,controls:l,events:u,...d}=e,f=vQ(t);yQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let p=new XY(d);p.mount(f);for(let[e,t]of Object.entries(u??{}))p.on(e,t);p.attribution=new VZ,p.addControl(p.attribution);for(let e of l??[])p.addControl(e);return await p.load(),p}async function _Q(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,events:l,...u}=e,d=vQ(t);yQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let f=new DZ(u);f.mount(d);for(let[e,t]of Object.entries(l??{}))f.on(e,t);try{await f.load()}catch(e){throw f.remove(),e}return f}function vQ(e){if(typeof e!=`string`)return e;let t=document.querySelector(e);if(!(t instanceof HTMLElement))throw Error(`spacemap: no element matches ${e}`);return t}function yQ(e){let t={};e.dataUrl!==void 0&&(t.dataUrl=e.dataUrl),e.imagesUrl!==void 0&&(t.imagesUrl=e.imagesUrl),e.liveUrl!==void 0&&(t.liveUrl=e.liveUrl),e.tilesUrl!==void 0&&(t.tilesUrl=e.tilesUrl),e.locale!==void 0&&(t.locale=()=>e.locale),e.messages!==void 0&&(t.messages=e.messages),e.includeNonCommercial&&(t.textures=`non-commercial`),r(t)}export{LZ as AttributionControl,zZ as FlatAttributionControl,fY as FlatMap,gq as GestureHandler,ny as MAP_LAYERS,kK as PROJECTION_IDS,VZ as PanoramaAttributionControl,XY as PanoramaView,Nq as SpaceMap,DZ as SystemMap,JJ as Viewport,MY as bearingDeg,ZK as boxRing,jG as circlePoints,r as configureHost,hQ as createFlatMap,mQ as createMap,gQ as createPanorama,AK as createProjection,_Q as createSystemMap,Ag as dateToJD,ZC as defaultSceneSettings,cQ as distanceKm,WZ as elements,fQ as fetchPanoramaIndex,pQ as fetchPanoramas,DY as findPanorama,HZ as fixed,eq as graticule,jY as groundDistanceM,eS as isViewable,jg as jdToDate,JZ as kmToAu,kY as neighboursOf,sQ as offsetKm,TY as panoramaAt,qK as pathFor,kG as planeBasis,YG as projectionAspect,UZ as samples,QK as smallCircle,lQ as subsolarPoint,uQ as sunlight,GZ as tle};
|
|
6383
|
+
`})}var HG=.25,UG=1e-9,WG=3,GG=class{object=new qa;anchor;outline;fillColor;fillOpacity;local=new Float64Array;count=0;mesh=null;scratch=new Float32Array;lastOrigin=[0,0,0];dirty=!0;wanted=!0;removeSelf=null;constructor(e){this.anchor=e.anchor;let t=e.widthPx??2;this.fillColor=e.fill??null,this.fillOpacity=e.fillOpacity??HG,this.outline=t>0?new MG({anchor:e.anchor,points:e.points,color:e.color,widthPx:t,opacity:e.opacity,closed:!0}):null,this.outline&&this.object.add(this.outline.object),this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){this.outline?.setPoints(e),this.local.length<e.length*3&&(this.local=new Float64Array(e.length*3));for(let t=0;t<e.length;t++){let[n,r,i]=e[t];this.local[t*3]=Q(n),this.local[t*3+1]=Q(i),this.local[t*3+2]=Q(-r)}this.count=e.length,this.rebuild(e)}setAnchor(e){this.anchor=e,this.outline?.setAnchor(e)}setVisible(e){this.wanted=e,this.outline?.setVisible(e)}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){this.outline?.update(e);let t=this.mesh;if(!t)return;let{jd:n,basis:r,camera:i,ctx:a}=e,o=this.wanted?cW(this.anchor,a,n):null;if(t.visible=o!==null,!o)return;let s=[o[0]-r[0],o[1]-r[1],o[2]-r[2]];if(this.dirty||Math.abs(s[0]-this.lastOrigin[0])>UG||Math.abs(s[1]-this.lastOrigin[1])>UG||Math.abs(s[2]-this.lastOrigin[2])>UG){let e=t.geometry.getAttribute(`position`);for(let e=0;e<this.count*3;e+=3)this.scratch[e]=this.local[e]+s[0],this.scratch[e+1]=this.local[e+1]+s[1],this.scratch[e+2]=this.local[e+2]+s[2];e.needsUpdate=!0,this.lastOrigin=s,this.dirty=!1}t.material.uniforms.uCenterOffset.value.copy(i.position).negate()}rebuild(e){this.disposeMesh(),this.dirty=!0;let t=this.fillColor;if(!t)return;let n=IG(e);if(!n.length)return;let r=new ts;r.setAttribute(`position`,new Uo(new Float32Array(e.length*3),3)),r.setIndex(n),this.scratch=r.getAttribute(`position`).array;let i=new Us(r,VG(t,this.fillOpacity));i.matrixAutoUpdate=!1,i.renderOrder=WG,i.frustumCulled=!1,this.object.add(i),this.mesh=i}disposeMesh(){let e=this.mesh;e&&(this.object.remove(e),e.geometry.dispose(),e.material.dispose(),this.mesh=null)}dispose(){this.disposeMesh(),this.outline?.dispose()}},KG=class extends GG{normal;steps;constructor(e){let{radiusKm:t,normal:n,steps:r,...i}=e;super({...i,points:FG(t,{normal:n,steps:r})}),this.normal=n,this.steps=r}setRadiusKm(e){this.setPoints(FG(e,{normal:this.normal,steps:this.steps}))}},qG=class extends yG{constructor(e,t){let n=document.createElement(`div`);n.className=`sm-drawing-label`,e.interactive&&n.classList.add(`sm-drawing--interactive`),e.className&&n.classList.add(e.className),n.textContent=e.text,e.color&&(n.style.color=e.color),e.fontSizePx!==void 0&&(n.style.fontSize=`${e.fontSizePx}px`),super({anchor:e.anchor,element:n,align:e.align,occlude:e.occlude},t)}setText(e){this.element.textContent=e}},JG=class extends yG{constructor(e,t){let n=document.createElement(`img`);n.className=`sm-drawing-icon`,e.interactive&&n.classList.add(`sm-drawing--interactive`),e.className&&n.classList.add(e.className),n.src=e.url,n.alt=e.alt??``,e.widthPx!==void 0&&(n.style.width=`${e.widthPx}px`),e.heightPx!==void 0&&(n.style.height=`${e.heightPx}px`),e.opacity!==void 0&&(n.style.opacity=String(e.opacity)),super({anchor:e.anchor,element:n,align:e.align,occlude:e.occlude},t)}setUrl(e){this.element.src=e}},YG=Math.PI/180,XG=180/Math.PI;function ZG(e){return e>=-180&&e<180?e:((e+180)%360+360)%360-180}function QG(e,t){return(n,r)=>{let i=e(r);return!i||Math.abs(n)>i.maxAbsX+1e-9?null:[ZG(n*i.lonPerX+t),i.lat]}}function $G(e){let{minX:t,maxX:n,minY:r,maxY:i}=e.extent;return(n-t)/(i-r)}function eK(e){let t=1/0,n=1/0,r=-1/0,i=-1/0,a=179.999999999;for(let o=0;o<=720;o++){let s=-90+180*o/720;for(let o=0;o<=720;o++){let c=e(-a+2*a*o/720,s);c&&(c[0]<t&&(t=c[0]),c[0]>r&&(r=c[0]),c[1]<n&&(n=c[1]),c[1]>i&&(i=c[1]))}}return{minX:t,minY:n,maxX:r,maxY:i}}function tK(e){let t=e.centerLon??0,n=e=>Math.abs(e)>Math.PI/2?null:{lat:e*XG,lonPerX:XG,maxAbsX:Math.PI};return{id:`equirectangular`,centerLon:t,cyclic:!0,rectangular:!0,azimuthal:!1,extent:{minX:-Math.PI,minY:-Math.PI/2,maxX:Math.PI,maxY:Math.PI/2},forward:(e,n)=>[ZG(e-t)*YG,n*YG],rowInverse:n,inverse:QG(n,t)}}var nK=1.340264,rK=-.081106,iK=893e-6,aK=.003796,oK=Math.sqrt(3),sK=e=>aK*e**9+iK*e**7+rK*e**3+nK*e,cK=e=>9*aK*e**8+7*iK*e**6+3*rK*e**2+nK;function lK(e){let t=e.centerLon??0,n=(e,n)=>{let r=Math.asin(TK(oK/2*Math.sin(n*YG))),i=ZG(e-t)*YG;return[2*oK*i*Math.cos(r)/(3*cK(r)),sK(r)]},r=e=>{let t=e;for(let n=0;n<12;n++){let n=(sK(t)-e)/cK(t);if(t-=n,Math.abs(n)<1e-12)break}return t},i=e=>{let t=r(e),n=2/oK*Math.sin(t);if(Math.abs(n)>1)return null;let i=3*cK(t)/(2*oK*Math.cos(t))*XG;return{lat:Math.asin(n)*XG,lonPerX:i,maxAbsX:180/i}};return{id:`equalEarth`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:eK(n),forward:n,rowInverse:i,inverse:QG(i,t)}}var uK=Math.SQRT2;function dK(e){let t=e.centerLon??0,n=e=>{let t=e/uK;if(Math.abs(t)>1)return null;let n=Math.asin(t),r=(2*n+Math.sin(2*n))/Math.PI;if(Math.abs(r)>1)return null;let i=Math.cos(n);if(i<1e-12)return{lat:Math.sign(e)*90,lonPerX:0,maxAbsX:0};let a=Math.PI/(2*uK*i)*XG;return{lat:Math.asin(r)*XG,lonPerX:a,maxAbsX:180/a}};return{id:`mollweide`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-2*uK,minY:-uK,maxX:2*uK,maxY:uK},forward:(e,n)=>{let r=n*YG,i=r;if(Math.abs(Math.abs(r)-Math.PI/2)<1e-9)i=Math.PI/2*Math.sign(r);else{let e=Math.PI*Math.sin(r);for(let t=0;t<20;t++){let t=(2*i+Math.sin(2*i)-e)/(2+2*Math.cos(2*i));if(i-=t,Math.abs(t)<1e-12)break}}let a=ZG(e-t)*YG;return[2*uK/Math.PI*a*Math.cos(i),uK*Math.sin(i)]},rowInverse:n,inverse:QG(n,t)}}function fK(e){let t=e.centerLon??0,n=e=>{if(Math.abs(e)>Math.PI/2)return null;let t=Math.cos(e);return t<1e-12?{lat:Math.sign(e)*90,lonPerX:0,maxAbsX:0}:{lat:e*XG,lonPerX:XG/t,maxAbsX:Math.PI*t}};return{id:`sinusoidal`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-Math.PI,minY:-Math.PI/2,maxX:Math.PI,maxY:Math.PI/2},forward:(e,n)=>{let r=n*YG;return[ZG(e-t)*YG*Math.cos(r),r]},rowInverse:n,inverse:QG(n,t)}}var pK=[1,.9986,.9954,.99,.9822,.973,.96,.9427,.9216,.8962,.8679,.835,.7986,.7597,.7186,.6732,.6213,.5722,.5322],mK=[0,.062,.124,.186,.248,.31,.372,.434,.4958,.5571,.6176,.6769,.7346,.7903,.8435,.8936,.9394,.9761,1],hK=.8487,gK=1.3523,_K=5;function vK(e,t){let n=e[Math.max(t-1,0)],r=e[t],i=e[t+1],a=e[Math.min(t+2,e.length-1)];return[r,.5*(i-n),.5*(2*n-5*r+4*i-a),.5*(-n+3*r-3*i+a)]}var yK=(e,t)=>e[0]+t*(e[1]+t*(e[2]+t*e[3])),bK=(e,t)=>e[1]+t*(2*e[2]+3*e[3]*t);function xK(e){let t=Math.min(Math.max(Math.floor(e),0),pK.length-2);return[t,e-t]}function SK(e){let[t,n]=xK(e);return hK*yK(vK(pK,t),n)*Math.PI}function CK(e){let t=0,n=mK.length-1;for(;n-t>1;){let r=t+n>>1;mK[r]<=e?t=r:n=r}let r=Math.min(t,mK.length-2),i=vK(mK,r),a=(e-mK[r])/(mK[r+1]-mK[r]);for(let t=0;t<8;t++){let t=bK(i,a);if(t===0)break;let n=(yK(i,a)-e)/t;if(a-=n,Math.abs(n)<1e-14)break}return r+Math.min(Math.max(a,0),1)}function wK(e){let t=e.centerLon??0,n=e=>{let t=Math.abs(e)/gK;if(t>1)return null;let n=CK(t),r=SK(n);return{lat:Math.sign(e)*n*_K,lonPerX:180/r,maxAbsX:r}};return{id:`robinson`,centerLon:t,cyclic:!0,rectangular:!1,azimuthal:!1,extent:{minX:-hK*Math.PI,minY:-gK,maxX:hK*Math.PI,maxY:gK},forward:(e,n)=>{let[r,i]=xK(Math.abs(n)/_K),a=yK(vK(pK,r),i),o=yK(vK(mK,r),i);return[hK*a*ZG(e-t)*YG,gK*o*Math.sign(n)]},rowInverse:n,inverse:QG(n,t)}}function TK(e){return e<-1?-1:e>1?1:e}function EK(e,t,n,r,i,a,o){let s=Math.asin(TK(n*a+t*r*o));return[ZG(i+Math.atan2(e*r,n*o-t*r*a)*XG),s*XG]}function DK(e){return{minX:-e,minY:-e,maxX:e,maxY:e}}function OK(e,t,n,r){let i=ZG(e-n)*YG,a=t*YG;return[Math.cos(a)*Math.sin(i),Math.cos(r)*Math.sin(a)-Math.sin(r)*Math.cos(a)*Math.cos(i)]}function kK(e){let t=e.centerLon??0,n=(e.centerLat??0)*YG,r=Math.min(e.clipAngle??90,90)*YG,i=Math.cos(r),a=Math.sin(r),o=Math.sin(n),s=Math.cos(n);return{id:`orthographic`,centerLon:t,cyclic:!1,rectangular:!1,azimuthal:!0,extent:DK(a),forward:(e,r)=>{let a=ZG(e-t)*YG,o=r*YG;return Math.sin(n)*Math.sin(o)+Math.cos(n)*Math.cos(o)*Math.cos(a)<i?null:OK(e,r,t,n)},inverse:(e,n)=>{let r=e*e+n*n;return r>a*a?null:EK(e,n,Math.sqrt(1-r),1,t,o,s)}}}var AK=120;function jK(e){let t=e.centerLon??0,n=(e.centerLat??90)*YG,r=Math.min(e.clipAngle??AK,170)*YG,i=Math.cos(r),a=2*Math.tan(r/2),o=Math.sin(n),s=Math.cos(n);return{id:`stereographic`,centerLon:t,cyclic:!1,rectangular:!1,azimuthal:!0,extent:DK(a),forward:(e,r)=>{let a=ZG(e-t)*YG,o=r*YG,s=Math.sin(n)*Math.sin(o)+Math.cos(n)*Math.cos(o)*Math.cos(a);if(s<i)return null;let c=2/(1+s),[l,u]=OK(e,r,t,n);return[c*l,c*u]},inverse:(e,n)=>{let r=e*e+n*n;if(r>a*a)return null;let i=4/(4+r);return EK(e,n,(4-r)*i*.25,i,t,o,s)}}}var MK={equirectangular:tK,equalEarth:lK,mollweide:dK,sinusoidal:fK,robinson:wK,orthographic:kK,stereographic:jK},NK=Object.keys(MK);function PK(e,t={}){let n=MK[e];if(!n)throw Error(`spacemap: unknown projection "${e}"`);return n(t)}var FK=Math.PI/180,IK=2*Math.PI,LK=2*FK,RK=180/Math.PI,zK=512,BK=2;function VK(e,t){let n=e.lat*FK,r=t.lat*FK,i=r-n,a=ZG(t.lon-e.lon)*FK,o=Math.sin(i/2)**2+Math.cos(n)*Math.cos(r)*Math.sin(a/2)**2;return 2*Math.asin(Math.min(1,Math.sqrt(o)))*RK}function HK(e,t,n){let r=VK(e,t)*FK;if(r<1e-12)return e;let i=Math.sin(r),a=Math.sin((1-n)*r)/i,o=Math.sin(n*r)/i,s=e.lat*FK,c=e.lon*FK,l=t.lat*FK,u=(e.lon+ZG(t.lon-e.lon))*FK,d=a*Math.cos(s)*Math.cos(c)+o*Math.cos(l)*Math.cos(u),f=a*Math.cos(s)*Math.sin(c)+o*Math.cos(l)*Math.sin(u),p=a*Math.sin(s)+o*Math.sin(l);return{lon:Math.atan2(f,d)*RK,lat:Math.atan2(p,Math.hypot(d,f))*RK}}function UK(e,t,n){return{lon:e.lon+ZG(t.lon-e.lon)*n,lat:e.lat+(t.lat-e.lat)*n}}function WK(e,t={}){let n=t.interpolate??`linear`,r=t.stepDeg??BK,i=n===`geodesic`?HK:UK,a=t.closed&&e.length>2?[...e,e[0]]:e;if(a.length<2)return[...a];let o=[a[0]];for(let e=1;e<a.length;e++){let t=a[e-1],n=a[e],s=Math.min(zK,Math.max(1,Math.ceil(VK(t,n)/r)));for(let e=1;e<=s;e++)o.push(e===s?n:i(t,n,e/s))}return o}function GK(e,t,n){let r=0,i=1;for(let a=0;a<20;a++){let a=(r+i)/2,o=UK(e,t,a);n.forward(o.lon,o.lat)?r=a:i=a}return UK(e,t,r)}function KK(e,t){let n=t.projection.cyclic?t.worldWidthPx/2:1/0,{projection:r}=t,i=[],a=[],o=null,s=0;for(let c=0;c<e.length;c++){let l=e[c],u=t.project(l.lon,l.lat);if(!u){if(a.length&&c>0){let n=GK(e[c-1],l,r);a.push(t.project(n.lon,n.lat))}a.length>1&&i.push(a),a=[],o=null,s++;continue}if(o&&Math.abs(u[0]-o[0])>n&&(a.length>1&&i.push(a),a=[]),!a.length&&c>0&&!t.project(e[c-1].lon,e[c-1].lat)){let n=GK(l,e[c-1],r);a.push(t.project(n.lon,n.lat))}a.push(u),o=u}return a.length>1&&i.push(a),{runs:i,whole:i.length===1&&s===0}}function qK(e,t){let n=[...e];for(let r of t.repeatShifts)if(r!==0)for(let i of e){let e=1/0,a=-1/0;for(let[t]of i)t<e&&(e=t),t>a&&(a=t);e+r>t.width||a+r<0||n.push(i.map(([e,t])=>[e+r,t]))}return n}function JK(e,t){let n=`M${e[0][0].toFixed(2)} ${e[0][1].toFixed(2)}`;for(let t=1;t<e.length;t++)n+=`L${e[t][0].toFixed(2)} ${e[t][1].toFixed(2)}`;return t?`${n}Z`:n}var YK=179.999999;function XK(e,t){let n=e=>e>YK?YK:e<-YK?-YK:e,r=e.length;if(r<3)return[e];let i=[],a=[],o=ZG(e[0].lon-t);a.push({lon:n(o),lat:e[0].lat});for(let t=0;t<r;t++){let s=e[t],c=e[(t+1)%r],l=ZG(c.lon-s.lon),u=o+l,d=u>180?1:u<-180?-1:0;if(d!==0){let e=s.lat+(c.lat-s.lat)*((d*180-o)/l);a.push({lon:d*YK,lat:e}),i.push(a),a=[{lon:-d*YK,lat:e}],o=u-d*360}else o=u;t<r-1&&a.push({lon:n(o),lat:c.lat})}return i.length===0?[a.map(e=>({lon:e.lon+t,lat:e.lat}))]:(i[0]=a.concat(i[0]),i.map(e=>e.map(e=>({lon:e.lon+t,lat:e.lat}))))}function ZK(e,t,n={}){if(e.length<2)return``;let{projection:r}=t;return(n.closed&&r.cyclic?XK(e,r.centerLon):[e]).map(e=>{let{runs:r,whole:i}=KK(WK(e,n),t),a=!!n.closed&&i;return qK(r,t).map(e=>JK(e,a)).join(``)}).join(``)}function QK(e,t,n={}){let{projection:r}=t;if(!r.azimuthal)return ZK(e,t,{...n,closed:!0});if(e.length<2)return``;let i=WK(e,{...n,closed:!0}),a=e.length>2?i.slice(0,-1):i,o=a.map(e=>r.forward(e.lon,e.lat)),s=([e,n])=>t.toScreen(e,n),c=o.filter(Boolean).length;if(c===0)return``;if(c===a.length)return JK(o.map(e=>s(e)),!0);let l=a.length,u=0;for(;!o[u]||o[(u+l-1)%l];)u++;let d=[],f=null;for(let e=0;e<l;e++){let t=(u+e)%l,n=(t+l-1)%l,i=o[t];if(i){if(!f){let e=GK(a[t],a[n],r);f=[r.forward(e.lon,e.lat)]}f.push(i)}else if(f){let e=GK(a[n],a[t],r);f.push(r.forward(e.lon,e.lat)),d.push(f),f=null}}let p=$K(a),m=([e,t])=>Math.atan2(t,e),h=Math.hypot(...d[0][0]),g=[],_=new Set;for(let e=0;e<d.length;e++){if(_.has(e))continue;let t=[],n=e;do{_.add(n),t.push(...d[n]);let r=m(d[n][d[n].length-1]),i=e,a=1/0;for(let e=0;e<d.length;e++){let t=m(d[e][0]),n=((p?t-r:r-t)%IK+IK)%IK;n<a&&(a=n,i=e)}let o=Math.ceil(a/LK);for(let e=1;e<o;e++){let n=r+(p?1:-1)*a*e/o;t.push([h*Math.cos(n),h*Math.sin(n)])}n=i}while(n!==e&&!_.has(n));g.push(t)}return g.map(e=>JK(e.map(s),!0)).join(``)}function $K(e){let t=0;for(let n=0;n<e.length;n++){let r=e[n],i=e[(n+1)%e.length];t+=ZG(i.lon-r.lon)*FK*(2+Math.sin(r.lat*FK)+Math.sin(i.lat*FK))}let n=-t/2;return n>0?n<IK:n<-IK}function eq(e,t=2){let{projection:n}=e,r=179.999999,i=[],a=(r,a,o)=>{let s=a<o?t:-t;for(let t=a;s>0?t<=o:t>=o;t+=s){let a=n.forward(r,t);a&&i.push(e.toScreen(a[0],a[1]))}};return a(n.centerLon-r,-90,90),a(n.centerLon+r,90,-90),i.length<3?``:qK([i],e).map(e=>JK(e,!0)).join(``)}function tq(e,t,n,r){let i=n+r,a=[],o=(e,t,n)=>{let r=Math.max(1,Math.ceil(Math.abs(n-t)/5));for(let i=0;i<=r;i++)a.push({lon:t+(n-t)*i/r,lat:e})};return o(e,n,i),o(t,i,n),a}function nq(e,t,n=128){let r=e.lat*FK,i=e.lon*FK,a=[Math.cos(r)*Math.cos(i),Math.cos(r)*Math.sin(i),Math.sin(r)],o=[-a[1],a[0],0],s=Math.hypot(o[0],o[1]);o=s<1e-9?[1,0,0]:[o[0]/s,o[1]/s,0];let c=[a[1]*o[2]-a[2]*o[1],a[2]*o[0]-a[0]*o[2],a[0]*o[1]-a[1]*o[0]],l=t*FK,u=Math.sin(l),d=Math.cos(l),f=[];for(let e=0;e<n;e++){let t=2*Math.PI*e/n,r=Math.sin(t)*u,i=Math.cos(t)*u,s=a[0]*d+o[0]*r+c[0]*i,l=a[1]*d+o[1]*r+c[1]*i,p=a[2]*d+o[2]*r+c[2]*i;f.push({lon:ZG(Math.atan2(l,s)*RK),lat:Math.atan2(p,Math.hypot(s,l))*RK})}return f}var rq=24;function iq(e=30){let t=[];for(let n=-180;n<180;n+=e)t.push([{lon:n,lat:-90},{lon:n,lat:90}]);let n=179.999999;for(let r=-90+e;r<90;r+=e){let e=[];for(let t=0;t<=rq;t++)e.push({lon:-n+2*n*t/rq,lat:r});t.push(e)}return t}var aq=.005,oq=1.5,sq=5,cq=24,lq=class{object=new qa;body;altitudeKm;closed;interpolate;stepDeg;color;widthPx;opacity;dash;fillColor;fillOpacity;dirs=new Float64Array;count=0;line=null;scratch=new Float32Array;alphas=new Float32Array;lengths=new Float32Array;fanDirs=new Float64Array;groundDirs=new iW;groundFanDirs=new iW;fill=null;fillScratch=new Float32Array;turned=[0,0,0];wanted=!0;removeSelf=null;constructor(e){this.body=e.body,this.altitudeKm=e.altitudeKm??null,this.closed=e.closed??!1,this.interpolate=e.interpolate??`linear`,this.stepDeg=e.stepDeg,this.color=e.color??`#ffffff`,this.widthPx=e.widthPx??2,this.opacity=e.opacity??1,this.dash=wG(e.dash),this.fillColor=e.fill??null,this.fillOpacity=e.fillOpacity??.25,this.object.matrixAutoUpdate=!1,this.setPoints(e.points)}bind(e){this.removeSelf=e}setPoints(e){let t=WK(e,{interpolate:this.interpolate,stepDeg:this.stepDeg,closed:this.closed});this.dirs=new Float64Array(t.length*3);for(let e=0;e<t.length;e++){let[n,r,i]=nW(t[e].lat,t[e].lon);this.dirs[e*3]=n,this.dirs[e*3+1]=r,this.dirs[e*3+2]=i}this.count=t.length,this.buildLine(),this.buildFill()}setVisible(e){this.wanted=e}remove(){this.removeSelf?.(),this.removeSelf=null}update({jd:e,basis:t,camera:n,viewportPx:r,ctx:i}){let a=this.wanted&&this.count>=2?i.getBody(this.body):void 0,o=a&&oW(a,i,e);if(this.line&&(this.line.visible=!!o),this.fill&&(this.fill.visible=!!o),!a||!o)return;let s=bn(a.data),c=Q(s+(this.altitudeKm??s*aq)),l=a.orientation?xS(a.orientation,e,a.nutPrec):null,u=[o[0]-t[0],o[1]-t[1],o[2]-t[2]];if(this.line){let e=this.groundDirs.of(this.dirs,a.drawnRadii);this.place(e,this.count,l,c,u,this.scratch),$L(this.line.geometry,this.scratch,this.alphas,this.alphas,this.count),this.dash&&(OG(this.scratch,this.count,n,r,this.lengths),nR(this.line.geometry,this.lengths,this.count)),this.line.material.uniforms.uCenterOffset.value.copy(n.position).negate()}if(this.fill){let e=this.fill.geometry.getAttribute(`position`),t=this.groundFanDirs.of(this.fanDirs,a.drawnRadii);this.place(t,this.fillScratch.length/3,l,c,u,this.fillScratch),e.needsUpdate=!0,this.fill.material.uniforms.uCenterOffset.value.copy(n.position).negate()}}place(e,t,n,r,i,a){for(let o=0;o<t;o++){let t=o*3;n?aW(n,e[t],e[t+1],e[t+2],this.turned,0):(this.turned[0]=e[t],this.turned[1]=e[t+1],this.turned[2]=e[t+2]),a[t]=this.turned[0]*r+i[0],a[t+1]=this.turned[1]*r+i[1],a[t+2]=this.turned[2]*r+i[2]}}buildLine(){if(this.disposeLine(),this.count<2||this.widthPx<=0)return;this.scratch=new Float32Array(this.count*3),this.alphas=new Float32Array(this.count).fill(this.opacity),this.lengths=new Float32Array(this.count);let e=rR(this.count,this.scratch,this.alphas,this.alphas,this.count,this.color,this.widthPx,1,this.dash??void 0);e.frustumCulled=!1,e.renderOrder=oq,this.object.add(e),this.line=e}buildFill(){if(this.disposeFill(),!this.fillColor||this.count<3)return;let e=BG(this.dirs,this.count),t=0;for(let n=0;n<this.count;n++){let r=e[0]*this.dirs[n*3]+e[1]*this.dirs[n*3+1]+e[2]*this.dirs[n*3+2];t=Math.max(t,Math.acos(Math.min(1,Math.max(-1,r))))}let n=Math.min(cq,Math.max(1,Math.ceil(t*180/Math.PI/sq))),r=1+n*this.count;this.fanDirs=new Float64Array(r*3),this.fanDirs[0]=e[0],this.fanDirs[1]=e[1],this.fanDirs[2]=e[2];for(let t=1;t<=n;t++)for(let r=0;r<this.count;r++){let[i,a,o]=RG(e,[this.dirs[r*3],this.dirs[r*3+1],this.dirs[r*3+2]],t/n),s=(1+(t-1)*this.count+r)*3;this.fanDirs[s]=i,this.fanDirs[s+1]=a,this.fanDirs[s+2]=o}let i=[],a=(e,t)=>1+(e-1)*this.count+t;for(let e=0;e<this.count-1;e++)i.push(0,a(1,e),a(1,e+1));for(let e=1;e<n;e++)for(let t=0;t<this.count-1;t++){let n=a(e,t),r=a(e,t+1),o=a(e+1,t),s=a(e+1,t+1);i.push(n,o,r,r,o,s)}let o=new ts;o.setAttribute(`position`,new Uo(new Float32Array(r*3),3)),o.setIndex(i),this.fillScratch=o.getAttribute(`position`).array;let s=new Us(o,VG(this.fillColor,this.fillOpacity));s.matrixAutoUpdate=!1,s.frustumCulled=!1,s.renderOrder=oq,this.object.add(s),this.fill=s}disposeLine(){this.line&&=(this.object.remove(this.line),this.line.geometry.dispose(),this.line.material.dispose(),null)}disposeFill(){this.fill&&=(this.object.remove(this.fill),this.fill.geometry.dispose(),this.fill.material.dispose(),null)}dispose(){this.disposeLine(),this.disposeFill()}},uq=class{object=new qa;id;name;anchor;model;trueScale;spanScene;minPx;label;wanted=!0;removeSelf=null;constructor(e,t,n){this.id=t,this.name=e.name??null,this.anchor=e.position,this.object.matrixAutoUpdate=!1,this.object.frustumCulled=!1;let r=e.model;this.model=r?.object3d??null,this.minPx=r?.minPx??0;let i=r?dq(r.object3d):0;this.trueScale=r?.scaleM!==void 0&&i>0?Q(r.scaleM/1e3)/i:1,this.spanScene=i*this.trueScale,this.model&&this.object.add(this.model),this.label=e.label&&this.name?new qG({anchor:e.position,text:this.name,align:[.5,1.4],occlude:e.occludeLabel},n):null,this.label&&this.object.add(this.label.object)}bind(e){this.removeSelf=e}get position(){return this.anchor}positionKm(e){let t=this.anchor;if(`latitude`in t)return null;let n=typeof t.offsetKm==`function`?t.offsetKm(e):t.offsetKm;return n===void 0?[0,0,0]:n}setPosition(e){this.anchor=e,this.label?.setAnchor(e)}setVisible(e){this.wanted=e,this.label?.setVisible(e)}remove(){this.removeSelf?.(),this.removeSelf=null}update(e){let{basis:t,camera:n,jd:r,ctx:i}=e,a=this.model,o=this.wanted?cW(this.anchor,i,r):null;if(this.label?.update(e),!a||(a.visible=o!==null,!o))return;a.position.set(o[0]-t[0],o[1]-t[1],o[2]-t[2]);let s=this.drawnScale(a.position,n,e.viewportPx);a.scale.setScalar(s),a.updateMatrixWorld(!0)}drawnScale(e,t,n){if(this.minPx<=0||this.spanScene<=0)return this.trueScale;let r=t.position.distanceTo(e);if(r<=0)return this.trueScale;let i=n/(2*Math.tan(t.fov*Math.PI/180/2)*r),a=this.spanScene*i;return a>=this.minPx?this.trueScale:this.trueScale*(this.minPx/a)}dispose(){this.label?.dispose(),this.model&&this.object.remove(this.model)}};function dq(e){let t=new _o().setFromObject(e).getSize(new J);return Math.max(t.x,t.y,t.z)}var fq=class{byId=new Map;nextId=1;constructor(e,t){this.registry=e,this.canvas=t}add(e){let t=e.id??`object-${this.nextId++}`;this.byId.get(t)?.remove();let n=new uq(e,t,this.canvas()),r=this.registry();return n.bind(()=>{this.byId.delete(t),r.remove(n)}),this.byId.set(t,n),r.add(n),n}get(e){return this.byId.get(e)}all(){return[...this.byId.values()]}clear(){for(let e of[...this.byId.values()])e.remove()}};function pq(e,t,n,r){let i=cW(e,n,r),a=cW(t,n,r);return!i||!a?null:uW([a[0]-i[0],a[1]-i[1],a[2]-i[2]])}function mq(e,t,n,r){let i=pq(e,t,n,r);return i&&Math.hypot(...i)}function hq(e,t,n,r){let i=e.orientation?xS(e.orientation,r,e.nutPrec).toArray():[0,0,0,1],{latitude:a,longitude:o,distance:s}=BF([n[0],n[1],n[2]],[t[0],t[1],t[2]],i);return s>0?{lon:o,lat:a}:null}function gq(e,t,n){let r=t.getBody(e),i=t.getBody($_);if(!r||!i||r===i||!r.orientation&&!t.bodies.orientationRead.has(e))return null;let a=oW(r,t,n),o=oW(i,t,n);return a&&o&&hq(r,a,o,n)}var _q=1024,vq=Math.PI*(3-Math.sqrt(5));function yq(e,t,n){let r=Math.hypot(...t.centre),i=Math.asin(Math.min(t.radiusKm/r,1));if(!(i>0))return 1;let a=t.centre.map(e=>e/r),o=e=>e[0]*a[0]+e[1]*a[1]+e[2]*a[2],s=n.filter(({centre:t,radiusKm:n})=>{let r=o(t),a=Math.sqrt(Math.max(Math.hypot(...t)**2-r**2,0));return r>-(e+n)&&a<e+n+2*i*(r+e)});if(s.length===0)return 1;let[c,l]=NG(t.centre),u=0;for(let t=0;t<_q;t++){let n=Math.sqrt((t+.5)/_q),r=e*n*Math.cos(t*vq),d=e*n*Math.sin(t*vq),f=e*Math.sqrt(1-n*n),p=1;for(let{centre:e,radiusKm:t}of s){let n=[e[0]-r*c[0]-d*l[0]-f*a[0],e[1]-r*c[1]-d*l[1]-f*a[1],e[2]-r*c[2]-d*l[2]-f*a[2]],s=Math.hypot(...n),u=Math.acos(Math.max(-1,Math.min(1,o(n)/s)));if(p*=Rw(i,Math.asin(Math.min(t/s,1)),u),p===0)break}u+=p}return u/_q}var bq=class{enabled;apply;constructor(e,t){this.enabled=e,this.apply=t}enable(){this.set(!0)}disable(){this.set(!1)}isEnabled(){return this.enabled}set(e){this.enabled!==e&&(this.enabled=e,this.apply?.(e))}};function xq(e,t){return e??t??!0}var Sq=1400,Cq=class{enabled;element=document.createElement(`div`);timer;constructor(e,t){this.enabled=t,this.element.className=`sm-cooperative-hint`,this.element.setAttribute(`aria-hidden`,`true`),e.append(this.element)}isEnabled(){return this.enabled}setEnabled(e){this.enabled=e,e||this.hide()}allowsWheel(e){if(!this.enabled||e.ctrlKey||e.metaKey)return!0;let{cooperative_wheel:t,cooperative_wheel_mac:n}=i().messages;return this.show(wq()?n():t()),!1}allowsTouchDrag(e){return!this.enabled||e>1?!0:(this.show(i().messages.cooperative_touch()),!1)}dispose(){clearTimeout(this.timer),this.element.remove()}show(e){this.element.textContent=e,this.element.classList.add(`sm-cooperative-hint--shown`),clearTimeout(this.timer),this.timer=setTimeout(()=>this.hide(),Sq)}hide(){clearTimeout(this.timer),this.element.classList.remove(`sm-cooperative-hint--shown`)}};function wq(){return/Mac|iPhone|iPad|iPod/.test(navigator.platform||navigator.userAgent)}var Tq={[G.BARYCENTER]:`barycenter`,[G.LAGRANGE_POINT]:`lagrange-point`,[G.STAR]:`star`,[G.PLANET]:`planet`,[G.DWARF_PLANET]:`dwarf-planet`,[G.MOON]:`moon`,[G.ASTEROID]:`asteroid`,[G.ASTEROID_INNER]:`asteroid`,[G.ASTEROID_MAIN_BELT]:`asteroid`,[G.ASTEROID_TROJAN]:`asteroid`,[G.ASTEROID_CENTAUR]:`asteroid`,[G.ASTEROID_TNO]:`asteroid`,[G.COMET]:`comet`,[G.SPACECRAFT]:`spacecraft`,[G.DEBRIS]:`debris`,[G.UNDOCUMENTED]:`unknown`,[G.SURFACE_FEATURE]:`surface-feature`},Eq={[G.ASTEROID_INNER]:`inner`,[G.ASTEROID_MAIN_BELT]:`main-belt`,[G.ASTEROID_TROJAN]:`trojan`,[G.ASTEROID_CENTAUR]:`centaur`,[G.ASTEROID_TNO]:`tno`};function Dq(e){let{id:t,name:n,objectType:r,parentId:i,radiusKm:a}=e.data,o={id:t,name:n,type:Tq[r],parentId:i,radiusKm:Number.isFinite(a)&&a>0?a:null,placed:e.position!==null},s=Eq[r];return s&&(o.orbitClass=s),o}var Oq=[`top-left`,`top-right`,`bottom-left`,`bottom-right`],kq=class{corners=new Map;added=new Map;constructor(e,t){this.map=e,this.root=t}add(e,t){if(this.added.has(e))return;let n=e.onAdd(this.map);this.added.set(e,n),this.corner(t??e.getDefaultPosition?.()??`top-right`).append(n)}remove(e){let t=this.added.get(e);t&&(this.added.delete(e),e.onRemove?.(this.map),t.remove())}clear(){for(let e of[...this.added.keys()])this.remove(e);for(let e of this.corners.values())e.remove();this.corners.clear()}corner(e){let t=this.corners.get(e);return t||(t=document.createElement(`div`),t.className=`sm-ctrl sm-ctrl--${e}`,this.corners.set(e,t),this.root.append(...Oq.map(e=>this.corners.get(e)).filter(e=>e!==void 0)),t)}},Aq=[(e,t)=>e.setReducedMotion(t.resolvedReducedMotion),(e,t)=>e.setImmersive(t.viewMode===`immersive`),(e,t)=>e.setHaloDebugVisible(t.showHaloDebug),(e,t)=>{t.atmosphereCalibration,e.applyRenderTier()}],jq=.05,Mq=1.15,Nq=2e3,Pq=4e3,Fq=new WeakMap,Iq=new WeakMap,Lq=class{ctx=new aF;clock;initialView;#e=Ge(null);get renderer(){return Vt(this.#e)}set renderer(e){Ke(this.#e,e)}#t=Ge(!1);get webglError(){return Vt(this.#t)}set webglError(e){Ke(this.#t,e,!0)}#n=Ge(!1);get contextLost(){return Vt(this.#n)}set contextLost(e){Ke(this.#n,e,!0)}#r=Ge();get focusedBody(){return Vt(this.#r)}set focusedBody(e){Ke(this.#r,e)}attribution=null;objects=new fq(()=>this.requireRenderer().extensions,()=>this.requireCanvas());dragRotate;scrollZoom;keyboard;bodySelect;featureSelect;cooperativeGestures;container=null;canvas=null;labelLayer=null;stopWatching=null;controls=null;lostPanelTimer;cooperative=null;limits={};initialFocusPending=!0;pendingFocusId=null;opening=null;navigation=0;retireCameraHold=null;listeners={focuschange:new Set,camera:new Set,featureselect:new Set,userpromoted:new Set,contextlost:new Set,contextrestored:new Set,clock:new Set,loading:new Set,progress:new Set,idle:new Set,error:new Set,datastale:new Set,notice:new Set,noticedismiss:new Set,layerschange:new Set,frame:new Set};constructor(e={}){e.settings&&ew(e.settings),this.clock=new sF(Ag(e.date??new Date),e.live??e.date===void 0);let t=e.view??{};this.initialView={id:t.body??GF,latitude:t.lat??45,longitude:t.lon??0,zoom:t.distanceKm===void 0?15:Q(t.distanceKm)};let n=t=>new bq(xq(e.interactions?.[t],e.interactive),()=>this.applyGestures());this.dragRotate=n(`dragRotate`),this.scrollZoom=n(`scrollZoom`),this.keyboard=n(`keyboard`),this.bodySelect=n(`bodySelect`),this.featureSelect=n(`featureSelect`),this.cooperativeGestures=new bq(e.cooperativeGestures??!1,()=>this.applyGestures()),e.limits&&(this.limits={...e.limits}),this.ctx.layers=new ly(e.layers),this.ctx.layers.onChange=()=>this.onLayerChange(),this.ctx.onDataStale=()=>this.emit(`datastale`),hG()}on(e,t){return this.listeners[e].add(t),()=>this.listeners[e].delete(t)}once(e,t){let n=(...e)=>{r(),t(...e)};Iq.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners[e];n.delete(t);for(let e of n)Iq.get(e)===t&&n.delete(e)}emit(e,...t){for(let n of this.listeners[e])n(...t)}getBody(e){let t=this.ctx.getBody(e);return t&&Dq(t)}getFocusedBody(){let e=this.focusedBody;if(!e)return;let t=mn(e)?this.ctx.getBody(e.featureAnchor.hostId):e;return t&&Dq(t)}getChildren(e){return[...this.ctx.bodies.getChildren(e)??[]]}get placedJd(){let e=this.renderer?.placedJd;return e===void 0||Number.isNaN(e)?this.clock.jd:e}distanceKm(e,t){return mq(e,t,this.ctx,this.placedJd)}offsetKm(e,t){return pq(e,t,this.ctx,this.placedJd)}getSubsolarPoint(e){return gq(e,this.ctx,this.placedJd)}tilesEnabled(){return nP()}async hasTiles(e){let t=(await tS(e,!1).catch(()=>null))?.global;return!t?.map_texture_available||KA(t)===null?!1:rP(o([t.texture&&{...t.texture,id:e},...t.alternates??[]])?.tiles)&&!this.renderer?.tilesFailed(e)}load(e=this.initialView.id){return this.ctx.load(jg(this.clock.jd),e)}open(e=this.initialView.id){return this.opening??=this.openOnce(e)}async openOnce(e){let t=this.load(e);t.catch(()=>{});let n=!0,r=new Promise(t=>{let r=()=>{n&&(this.renderer&&!this.ctx.loading&&this.ctx.getBody(e)?t():document.hidden?setTimeout(r,100):requestAnimationFrame(r))};r()});try{await Promise.race([t,r])}finally{n=!1}}applyInitialView(){let{id:e,latitude:t,longitude:n,zoom:r}=this.initialView;this.focusedBody||!this.ctx.getBody(e)||this.renderer?.snapToBody(e,t,n,r)}mount(e){if(this.container)throw Error(`SpaceMap is already mounted`);this.container=e,e.classList.add(`sm-map`),Fq.set(e,(Fq.get(e)??0)+1),this.controls=new kq(this,e);let t=document.createElement(`canvas`);t.className=`sm-map__canvas`,t.tabIndex=0,t.setAttribute(`role`,`application`),t.setAttribute(`aria-label`,i().messages.scene_canvas_label());let n=document.createElement(`div`);n.className=`scene-overlay`,e.append(t,n),this.canvas=t,this.labelLayer=n,this.cooperative=new Cq(e,this.cooperativeGestures.isEnabled()),t.addEventListener(`keydown`,this.onKeyDown),t.addEventListener(`touchmove`,this.onTouchMove,{passive:!0}),e.addEventListener(`wheel`,this.onWheelCapture,{capture:!0,passive:!0}),t.addEventListener(`webglcontextlost`,this.onContextLost,!1),t.addEventListener(`webglcontextrestored`,this.onContextRestored,!1),document.addEventListener(`visibilitychange`,this.onVisibility);let r;try{r=new zW(t,n,this.ctx,this.clock,this.initialView,this.callbacks())}catch(e){console.error(`[scene] renderer init failed:`,e),this.webglError=!0;return}this.renderer=r,this.applyGestures(),this.applyLimits(),this.pendingFocusId!==null&&(r.focusOnBody(this.pendingFocusId),this.pendingFocusId=null);let a=new ResizeObserver(()=>r.resize(t.clientWidth,t.clientHeight));a.observe(t);let o=st(()=>this.watch(r));this.stopWatching=()=>{a.disconnect(),o()}}addControl(e,t){if(!this.controls)throw Error(`spacemap: the map is not mounted`);return this.controls.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.unmount()}unmount(){let{container:e,canvas:t}=this;if(!e||!t)return;this.controls?.clear(),this.controls=null,this.stopWatching?.(),this.stopWatching=null,clearTimeout(this.lostPanelTimer),t.removeEventListener(`keydown`,this.onKeyDown),t.removeEventListener(`touchmove`,this.onTouchMove),e.removeEventListener(`wheel`,this.onWheelCapture,{capture:!0}),this.cooperative?.dispose(),this.cooperative=null,t.removeEventListener(`webglcontextlost`,this.onContextLost),t.removeEventListener(`webglcontextrestored`,this.onContextRestored),document.removeEventListener(`visibilitychange`,this.onVisibility),this.retireCameraHold?.(),this.retireCameraHold=null,this.renderer?.dispose(),this.renderer=null,t.remove(),this.labelLayer?.remove();let n=(Fq.get(e)??1)-1;Fq.set(e,n),n===0&&e.classList.remove(`sm-map`),this.container=this.canvas=this.labelLayer=null}watch(e){at(()=>{this.ctx.bodies.minorBodyVersion,e.rebuildMinorPointClouds()});let t=$C();for(let n of Aq)at(()=>n(e,t));let n=this.clock;at(()=>{let{jd:e,playing:t,timeScale:r,direction:i,live:a}=n;this.listeners.clock.size!==0&&this.emit(`clock`,{jd:e,date:jg(e),playing:t,timeScale:r,direction:i,live:a})}),at(()=>{let e=this.ctx.loading,t=xU.bootPending;this.emit(`loading`,e||t)}),at(()=>this.emit(`progress`,Av.value)),at(()=>{let e=this.ctx.error;e!==null&&this.emit(`error`,e)}),at(()=>{xU.progress===null?e.isContextLost()||e.resume():e.pause()})}applySettings(){let e=this.renderer;if(!e)return;let t=$C();for(let n of Aq)n(e,t)}callbacks(){return{notices:{notify:e=>this.emit(`notice`,e),dismiss:e=>this.emit(`noticedismiss`,e)},onFocusChange:e=>{let t=this.initialFocusPending;this.initialFocusPending=!1,this.focusedBody=e;let n=e!==void 0&&mn(e);this.emit(`focuschange`,{body:this.getFocusedBody(),initial:t,feature:n})},onFrame:(e,t)=>{this.listeners.frame.size>0&&this.emit(`frame`,{jd:e,dtMs:t})},onIdle:()=>this.emit(`idle`),onCameraPosition:(e,t,n)=>{let r=this.focusedBody?.data.id;r!==void 0&&this.emit(`camera`,{body:r,lat:e,lon:t,distanceKm:xg(n)})},onUserPromotedChange:e=>this.emit(`userpromoted`,e),onFeatureSelect:(e,t,n,r,i)=>this.emit(`featureselect`,{bodyId:e,featureId:t,lat:n,lon:r,diameterM:i})}}onKeyDown=e=>{if(!this.keyboard.isEnabled()||e.ctrlKey||e.metaKey||e.altKey)return;let t=(e.shiftKey?4:1)*jq,n=0,r=0,i=1;switch(e.key){case`ArrowLeft`:n=t;break;case`ArrowRight`:n=-t;break;case`ArrowUp`:r=t;break;case`ArrowDown`:r=-t;break;case`+`:case`=`:i=Mq;break;case`-`:case`_`:i=1/Mq;break;default:return}e.preventDefault(),this.renderer?.nudgeCamera(n,r,i)};onContextLost=e=>{e.preventDefault(),console.warn(`[scene] WebGL context lost`),this.renderer?.pause(),clearTimeout(this.lostPanelTimer),this.lostPanelTimer=setTimeout(()=>{this.contextLost=!0,this.emit(`contextlost`)},Nq)};onContextRestored=()=>{console.warn(`[scene] WebGL context restored`),clearTimeout(this.lostPanelTimer),this.contextLost=!1,this.renderer?.handleContextRestored(),this.renderer?.recoverWorkersIfDead(Pq),this.emit(`contextrestored`)};onVisibility=()=>{document.visibilityState===`visible`&&(this.renderer?.isContextLost()||this.renderer?.recoverWorkersIfDead())};async flyTo(e){let t=this.targetBody(e);if(e.feature)return this.toFeature(t,e.feature,`frame`);let n=await this.goTo(t,{clock:`keep`,view:()=>({distance:this.framing(e,t),latitude:e.lat,longitude:e.lon})});if(n.outcome===`failed`)throw n.error;return this.settled(n.flightMs)}async goTo(e,t={}){let n=++this.navigation,r=()=>n!==this.navigation,i={outcome:`superseded`,flightMs:0},a=()=>sS(e).catch(t=>(console.warn(`[map] goTo ${e}: no coverage to read, the clock stays:`,t),[])),o=this.cameraDistance(),s,c=null,l=()=>{};if(t.clock!==`keep`){if(c=await a(),r())return i;let e=this.clock.jd,t=cS(c,e);t!==null&&t!==e&&(l=this.renderer?.holdDate()??l,this.clock.jumpTo(t),s={from:e,to:t})}let u,d,f=e=>{d??=e},p=()=>(console.warn(`[map] goTo ${e}: its data did not load:`,d),{outcome:`failed`,error:d,clockMoved:s,flightMs:0});try{await this.open(e).catch(()=>{});let t=jg(this.clock.jd);await this.ctx.ready(t).catch(f),await this.ctx.ensureBody(e,t).catch(f),u=await this.rendering()}finally{l()}if(r())return i;let m=this.ctx.getBody(e);if(!m||!u)return d===void 0?(console.warn(`[map] goTo ${e}: not an object of this map`),{outcome:`missing`,clockMoved:s,flightMs:0}):p();let h=u.placeOf(m)!==null;if(!h&&d!==void 0){if(c??=await a(),r())return i;if(cS(c,this.clock.jd)===this.clock.jd)return p()}if(t.commit?.(m),h){let n=t.view?.(m)??{},r=n.distance??(m.data.radiusKm>0?this.framing({},e):o),i=0;switch(t.camera??`fly`){case`fly`:i=u.focusOnBody(e,r,n.latitude,n.longitude);break;case`cut`:u.snapToBody(e,n.latitude??45,n.longitude??0,r);break;case`pan`:i=u.focusOnBody(e);break;case`none`:}return{outcome:`placed`,body:m,clockMoved:s,flightMs:i}}if(u.focusOnBody(e),c??=await a(),c.length>0)return t.clock!==`keep`&&console.error(`[map] goTo ${e}: no place at jd ${this.clock.jd} (${m.unplaced}), inside its coverage`),{outcome:`unplaced`,body:m,clockMoved:s,flightMs:0};let g=this.placedAncestor(m,u);if(!g)return{outcome:`nowhere`,body:m,clockMoved:s,flightMs:0};let _=u.panCameraTo(g,this.framing({},g.data.id));return{outcome:`host`,body:m,host:g,clockMoved:s,flightMs:_}}placedAncestor(e,t){let n=new Set([e.data.id]),r=this.ctx.getBody(e.data.parentId);for(;r&&!n.has(r.data.id);){if(t.placeOf(r))return r;n.add(r.data.id),r=this.ctx.getBody(r.data.parentId)}return null}rendering(){return new Promise(e=>{let t=()=>{this.renderer?e(this.renderer):this.webglError||this.ctx.error?e(null):document.hidden?setTimeout(t,100):requestAnimationFrame(t)};t()})}panTo(e){return this.toFeature(this.targetBody(e),e.feature,`pan`)}jumpTo(e){let t=this.targetBody(e);if(e.facing!==void 0)return this.snapToBodyFacing(t,e.facing,e.elevationDeg??0,this.framing(e,t)),this;if(e.feature){let{featureId:n,lat:r,lon:i,diameterM:a}=e.feature;return this.focusOnFeature(t,n,r,i,a,null,`snap`),this}let n=this.getCamera();return this.snapToBody(t,e.lat??n?.lat??45,e.lon??n?.lon??0,this.framing(e,t)),this}getCamera(){let e=this.renderer,t=this.focusedBody?.data.id;if(!e||t===void 0)return null;let{latitude:n,longitude:r,distance:i}=e.getCameraState();return{body:t,lat:n,lon:r,distanceKm:xg(i)}}setLayerVisible(e,t){return this.ctx.layers.setVisible(e,t),this}isLayerVisible(e){return this.ctx.layers.isVisible(e)}getLayers(){return[...ny]}onLayerChange(){for(let e of this.ctx.bodies.spacecraftByParent.keys())this.ctx.bodies.dirtySpacecraftGroups.add(e);this.ctx.bodies.minorBodyVersion++,this.emit(`layerschange`,ny.filter(e=>this.ctx.layers.isVisible(e)))}setLimits(e){return this.limits={...e},this.applyLimits(),this}getLimits(){return{...this.limits}}applyLimits(){let e=this.limits,t={};e.minDistanceKm!==void 0&&(t.minDistance=Q(e.minDistanceKm)),e.maxDistanceKm!==void 0&&(t.maxDistance=Q(e.maxDistanceKm)),e.minLat!==void 0&&(t.minLat=e.minLat),e.maxLat!==void 0&&(t.maxLat=e.maxLat),e.minLon!==void 0&&(t.minLon=e.minLon),e.maxLon!==void 0&&(t.maxLon=e.maxLon);let n=Object.keys(t).length>0;this.renderer?.setCameraLimits(n?t:null,e.bodies??null)}applyGestures(){let e=this.cooperativeGestures.isEnabled();this.cooperative?.setEnabled(e);let t=this.renderer;t&&(t.setDragEnabled(this.dragRotate.isEnabled()),t.setZoomEnabled(this.scrollZoom.isEnabled()),t.setBodySelectEnabled(this.bodySelect.isEnabled()),t.setFeatureSelectEnabled(this.featureSelect.isEnabled()),t.setCooperativeTouch(e))}onWheelCapture=e=>{this.scrollZoom.isEnabled()&&this.cooperative&&!this.cooperative.allowsWheel(e)&&e.stopPropagation()};onTouchMove=e=>{this.cooperative?.allowsTouchDrag(e.touches.length)};toFeature(e,t,n){let{featureId:r,lat:i,lon:a,diameterM:o}=t;return this.settled(this.focusOnFeature(e,r,i,a,o,null,n))}settled(e){return new Promise(t=>{setTimeout(()=>requestAnimationFrame(()=>t()),e)})}targetBody(e){let t=e.body??this.focusedBody?.data.id;if(t===void 0)throw Error(`spacemap: no body to move to, and none focused`);return t}framing(e,t){if(e.distanceKm!==void 0)return Q(e.distanceKm);let n=this.ctx.getBody(t);return n&&n.data.radiusKm>0?zU(n)*5:this.cameraDistance()}cameraDistance(){return this.renderer?.getCameraState().distance??15}focusOnBody(e,t,n,r){return this.renderer?this.renderer.focusOnBody(e,t,n,r):(this.pendingFocusId=e,0)}snapToBody(e,t,n,r){this.renderer?.snapToBody(e,t,n,r)}snapToBodyFacing(e,t,n,r){this.renderer?.snapToBodyFacing(e,t,n,r)}focusOnFeature(e,t,n,r,i,a,o=`frame`,s=null){let c=this.ctx.getBody(e);if(!c)return 0;let l=Q(i*4/1e3),u=Q(.02),d=Q(bn(c.data)*5),f=Math.min(Math.max(l,u),d),p={hostId:e,featureId:t,lat:n,lon:r,diameterM:i};return this.renderer?.focusOnFeature(p,a,f,o,s)??0}setFocusTarget(e,t){this.renderer?.setFocusTarget(e,t)}getPose(){let e=this.renderer,t=this.focusedBody;if(!e||!t)return null;let n=t.data.id;return{position:{body:n,offsetKm:uW(e.cameraOffsetFromFocus())},target:{body:n}}}holdCamera(){let e=this.renderer;if(!e)throw Error(`SpaceMap is not mounted`);this.retireCameraHold?.(),e.holdCamera();let t=!0,n=()=>{t=!1};return this.retireCameraHold=n,{get held(){return t},set:n=>{t&&e.setHeldPose(n)},release:()=>{t&&(n(),this.retireCameraHold=null,e.releaseCamera())}}}addMarker(e){return this.track(new yG(e,this.requireCanvas()))}addPolyline(e){return this.track(new MG(e))}addPolygon(e){return this.track(new GG({fill:e.color??`#ffffff`,...e}))}addCircle(e){return this.track(new KG(e))}addLabel(e){return this.track(new qG(e,this.requireCanvas()))}addIcon(e){return this.track(new JG(e,this.requireCanvas()))}addSurfacePolyline(e){return this.track(new lq(e))}addSurfacePolygon(e){return this.track(new lq({fill:e.color??`#ffffff`,...e,closed:!0}))}addSurfaceCircle(e){return this.addSurfacePolygon({...e,points:nq(e.center,this.capRadiusDeg(e),e.steps)})}clearDrawings(){this.renderer?.extensions.clear(e=>e instanceof uq)}setBodyAppearance(e,t){return this.requireRenderer().setBodyAppearance(e,t),this}setPinnedBodies(e){return this.requireRenderer().setPinnedBodies(e),this}capRadiusDeg(e){if(e.radiusDeg!==void 0)return e.radiusDeg;let t=this.getBody(e.body)?.radiusKm;return e.radiusKm!==void 0&&t?e.radiusKm/t*(180/Math.PI):1}track(e){let t=this.requireRenderer();return e.bind(()=>t.extensions.remove(e)),t.extensions.add(e),e}requireCanvas(){let e=this.canvas;if(!e)throw Error(`SpaceMap is not mounted`);return e}requireRenderer(){let e=this.renderer;if(!e)throw Error(`SpaceMap is not mounted`);return e}setNorthReference(e){this.renderer?.setNorthReference(e)}setUserLocation(e,t){this.renderer?.setUserLocation(e,t)}clearUserPromoted(){this.renderer?.clearUserPromoted()}setSelectedFeature(e){this.renderer?.setSelectedFeature(e)}setTravelPath(e,t=[],n=[],r=[]){this.renderer?.setTravelPath(e,t,n,r)}setOrbitPreview(e,t){this.renderer?.setOrbitPreview(e,t)}setTravelHover(e){this.renderer?.setTravelHover(e)}focusOnPathPoint(e,t){this.renderer?.focusOnPathPoint(e,t)}trackPathPoint(e,t){this.renderer?.trackPathPoint(e,t)}setCovered(e){this.renderer?.setCovered(e)}},Rq=`http://www.w3.org/2000/svg`;function zq(e){return{id:e.id,label:e.label,kind:e.kind,visible:e.visible,credit:e.credit}}function Bq(e){return{organisation:e.organisation,source:e.source,attribution:e.attribution}}function Vq(e,t){let n=document.createElementNS(Rq,`path`);return n.setAttribute(`d`,e),n.setAttribute(`class`,t),n}function Hq(e,t=30){return{kind:`vector`,id:`graticule`,label:e,visible:!1,render(e,n){for(let r of iq(t)){let t=ZK(r,e,{stepDeg:2});t&&n.append(Vq(t,`sm-flat__graticule`))}if(e.projection.azimuthal){let t=e.toScreen(0,0),r=e.toScreen(e.projection.extent.maxX,0),i=document.createElementNS(Rq,`circle`);i.setAttribute(`cx`,String(t[0])),i.setAttribute(`cy`,String(t[1])),i.setAttribute(`r`,String(Math.abs(r[0]-t[0]))),i.setAttribute(`class`,`sm-flat__frame`),n.append(i)}else{let t=eq(e);t&&n.append(Vq(t,`sm-flat__frame`))}}}}var Uq=120;function Wq(e,t){let n=[];return{kind:`vector`,id:`nomenclature`,label:t,visible:!1,credit:{organisation:`IAU`,source:`https://planetarynames.wr.usgs.gov/`},async prepare(){n.length||(n=[...await NT(e)].sort((e,t)=>t.diameterM-e.diameterM).slice(0,Uq))},render(e,t){let r=e.repeatShifts;for(let i of n){let n=e.project(i.lon,i.lat);if(!(!n||n[1]<0||n[1]>e.height))for(let a of r){let r=n[0]+a;if(r<0||r>e.width)continue;let o=document.createElementNS(Rq,`circle`);o.setAttribute(`cx`,r.toFixed(1)),o.setAttribute(`cy`,n[1].toFixed(1)),o.setAttribute(`r`,`1.6`),o.setAttribute(`class`,`sm-flat__feature-dot`);let s=document.createElementNS(Rq,`text`);s.setAttribute(`x`,(r+4).toFixed(1)),s.setAttribute(`y`,(n[1]+3).toFixed(1)),s.setAttribute(`class`,`sm-flat__feature-label`),s.textContent=i.name,t.append(o,s)}}}}}function Gq(e,t){e.setAttribute(`fill`,t.fill??`none`),t.fill&&t.fillOpacity!==void 0&&e.setAttribute(`fill-opacity`,String(t.fillOpacity)),e.setAttribute(`stroke`,t.color??`#ffffff`),e.setAttribute(`stroke-width`,String(t.widthPx??2)),e.setAttribute(`stroke-linejoin`,`round`),e.setAttribute(`stroke-linecap`,`round`),t.opacity!==void 0&&e.setAttribute(`opacity`,String(t.opacity)),t.dash&&e.setAttribute(`stroke-dasharray`,t.dash),t.className&&e.setAttribute(`class`,t.className),e.style.pointerEvents=t.interactive?`auto`:`none`,t.ariaLabel&&(e.setAttribute(`role`,`img`),e.setAttribute(`aria-label`,t.ariaLabel))}function Kq(e,t){t.onclick&&e.addEventListener(`click`,t.onclick),t.onpointerenter&&e.addEventListener(`pointerenter`,t.onpointerenter),t.onpointerleave&&e.addEventListener(`pointerleave`,t.onpointerleave)}var qq=class{node;area;edge;points;visible=!0;constructor(e,t,n,r,i,a){this.closed=n,this.interpolate=r,this.onRemove=i,this.onChange=a,this.points=e,this.node=document.createElementNS(Rq,`g`),Gq(this.node,t),Kq(this.node,t),this.area=n?document.createElementNS(Rq,`path`):null,this.area?.setAttribute(`stroke`,`none`),this.edge=document.createElementNS(Rq,`path`),this.edge.setAttribute(`fill`,`none`),this.area&&this.node.append(this.area),this.node.append(this.edge)}redraw(e){if(!this.visible)return;let t={closed:this.closed,interpolate:this.interpolate};this.edge.setAttribute(`d`,ZK(this.points,e,t)),this.area?.setAttribute(`d`,QK(this.points,e,t))}setPoints(e){this.points=e,this.onChange()}setVisible(e){this.visible=e,this.node.style.display=e?``:`none`,this.onChange()}detach(){this.node.remove()}remove(){this.onRemove(this)}},Jq=class{element;at;visible=!0;align;constructor(e,t,n){this.onRemove=t,this.onChange=n,this.at=e.at,this.align=e.align??[.5,.5],this.element=e.element??document.createElement(`div`),e.element||(this.element.className=`sm-flat__marker-dot`),e.className&&this.element.classList.add(e.className),this.element.style.position=`absolute`,this.element.style.left=`0`,this.element.style.top=`0`,this.element.style.pointerEvents=e.interactive?`auto`:`none`}redraw(e){let t=this.visible?e.project(this.at.lon,this.at.lat):null;if(this.element.style.display=t?``:`none`,!t)return;let n=e.repeatShifts.find(n=>t[0]+n>=0&&t[0]+n<=e.width)??0;this.element.style.transform=`translate(${t[0]+n}px, ${t[1]}px) translate(${-this.align[0]*100}%, ${-this.align[1]*100}%)`}setPosition(e){this.at=e,this.onChange()}setVisible(e){this.visible=e,this.onChange()}detach(){this.element.remove()}remove(){this.onRemove(this)}},Yq=class{drawings=new Set;constructor(e,t,n=()=>{},r=null){this.shapes=e,this.markers=t,this.onChange=n,this.radiusKm=r}setBodyRadiusKm(e){this.radiusKm=e}track(e,t){return this.drawings.add(e),t instanceof HTMLElement?this.markers.append(t):this.shapes.append(t),e}drop=e=>{this.drawings.delete(e)&&e.detach()};addPolyline(e){let t=new qq(e.points,e,e.closed??!1,e.interpolate??`linear`,this.drop,this.onChange);return this.track(t,t.node)}addPolygon(e){let t=new qq(e.points,{fill:`rgb(255 255 255 / 25%)`,...e},!0,e.interpolate??`linear`,this.drop,this.onChange);return this.track(t,t.node)}addBox(e){let t=new qq(tq(e.latMin,e.latMax,e.lonMin,e.lonSpan),{fill:`rgb(255 255 255 / 15%)`,...e},!0,`linear`,this.drop,this.onChange);return this.track(t,t.node)}addCircle(e){let t=this.circleRadiusDeg(e),n=new qq(nq(e.center,t),{fill:`rgb(255 255 255 / 20%)`,...e},!0,`linear`,this.drop,this.onChange);return this.track(n,n.node)}circleRadiusDeg(e){return e.radiusDeg===void 0?e.radiusKm!==void 0&&this.radiusKm?e.radiusKm/this.radiusKm*(180/Math.PI):1:e.radiusDeg}addMarker(e){let t=new Jq(e,this.drop,this.onChange);return this.track(t,t.element)}redraw(e){for(let t of this.drawings)t.redraw(e)}clear(){for(let e of this.drawings)e.detach();this.drawings.clear()}},Xq=Math.PI/180,Zq=1.25,Qq=17,$q=.15,eJ=.75;function tJ(e,t,n){if(e===0)return[(t+180)/360,(90-n)/180];let r=e===1?1:-1,i=.5*Math.tan((90-r*n)*Xq/2)/ZT;return[.5+i*Math.cos(t*Xq),.5-r*i*Math.sin(t*Xq)]}function nJ(e,t){return Math.ceil(Math.log2(2*Math.PI/(e*Zq*2*t)))}function rJ(e,t){return 2*Math.PI/(2*t*2**e)}function iJ(e,t,n){let[r,i]=tJ(0,t,n),a=r-Math.floor(r),o=e.max_level;for(let t of e.patches??[]){if(t.max_level<=o)continue;let e=Math.floor(a*tE(0,t.max_level)),n=Math.floor(i*nE(0,t.max_level));uE([t],t.max_level,e,n)&&(o=t.max_level)}return o}function aJ(e,t,n,r){let[i]=tJ(0,r[0],r[1]),a={minX:1/0,maxX:-1/0,minY:1/0,maxY:-1/0};for(let[t,r]of n){let[n,o]=tJ(e,t,r);if(e!==0&&(n<0||n>1||o<0||o>1))return null;let s=e===0?n-Math.round(n-i):n;a.minX=Math.min(a.minX,s),a.maxX=Math.max(a.maxX,s),a.minY=Math.min(a.minY,o),a.maxY=Math.max(a.maxY,o)}let o=(a.maxX-a.minX)/(Qq-1),s=(a.maxY-a.minY)/(Qq-1);return a.minX-=o,a.maxX+=o,a.minY-=s,a.maxY+=s,e===0&&(t.north||t.south)&&(a.minX=i-.5,a.maxX=i+.5,t.north&&(a.minY=0),t.south&&(a.maxY=1)),a}function oJ(e,t,n,r,i){let a=tE(e,t)*n,o=nE(e,t)*n,s=t=>{let n=(r.maxX-r.minX)*t,i=(r.maxY-r.minY)*t,s=Math.floor((r.minX-n)*a),c=Math.ceil((r.maxX+n)*a);e===0?c-s>a&&(s=Math.round((r.minX+r.maxX)/2*a-a/2),c=s+a):(s=Math.max(s,0),c=Math.min(c,a));let l=Math.max(Math.floor((r.minY-i)*o),0),u=Math.min(Math.ceil((r.maxY+i)*o),o);return[s,l,c,u]},[c,l,u,d]=s(i),f=s(0);return{chart:e,level:t,x0:c,y0:l,width:Math.max(u-c,1),height:Math.max(d-l,1),inner:[f[0],f[1],f[2]-1,f[3]-1]}}function sJ(e,t,n,r,i){for(let a of[i,0]){let i=oJ(e,t,n,r,a);if(i.width*i.height<=8e6)return i}}function cJ(e,t){let n=tE(0,e.max_level),r=nE(0,e.max_level),i=(e.y[1]+1)/r;if(e.y[0]/r>t.maxY||i<t.minY)return!1;let a=e.x[0]/n;a-=Math.round(a-(t.minX+t.maxX)/2);let o=a+(e.x[1]+1-e.x[0])/n;return a<=t.maxX&&o>=t.minX}function lJ(e,t,n,r=!0){let i=r?$q:0,a=t.place(.5,.5);if(!a||!(t.step>0))return[];let o=[];for(let e=0;e<Qq;e++)for(let n=0;n<Qq;n++){let r=t.place(n/(Qq-1),e/(Qq-1));r&&o.push(r)}let s=aJ(0,t,o,a),c=nJ(t.step,e.tile_size),l=[],u=e.max_level;for(let t of e.patches??[])t.max_level>u&&cJ(t,s)&&(u=t.max_level);for(let t=Math.min(c,u);t>e.max_level;t--){let n=sJ(0,t,e.tile_size,s,i);if(n){l.push(n);break}}let d=a[1]>=0?1:2,f=aJ(d,t,o,a);for(let t=Math.min(c,e.max_level);t>=n;t--){let n=sJ(0,t,e.tile_size,s,i),r=f&&t>=1?sJ(d,t,e.tile_size,f,i):void 0,a=n?n.width*n.height:1/0,o=r&&r.width*r.height<=a*eJ?r:n??r;if(o){l.push(o);break}}return l}function uJ(e,t){let n=t.tile_size,r=tE(e.chart,e.level),i=nE(e.chart,e.level),a=[],o=Math.min(Math.floor((e.y0+e.height-1)/n),i-1),s=Math.floor((e.x0+e.width-1)/n);for(let i=Math.max(Math.floor(e.y0/n),0);i<=o;i++)for(let o=Math.floor(e.x0/n);o<=s;o++){if(e.chart!==0&&(o<0||o>=r))continue;let s=(o%r+r)%r,c=e.level>t.max_level?uE(t.patches,e.level,s,i):void 0;e.level>t.max_level&&!c||a.push({cap:JT[e.chart],level:e.level,x:s,y:i,dx:o*n-e.x0,dy:i*n-e.y0,patch:c})}let c=e.width/2-n/2,l=e.height/2-n/2,u=e=>Math.hypot(e.dx-c,e.dy-l);return a.sort((e,t)=>u(e)-u(t))}function dJ(e,t,n){if(e.chart!==t.chart||e.level!==t.level)return!1;let r=0;if(t.chart===0){let i=tE(0,t.level)*n;r=i*Math.round((t.inner[0]-e.x0)/i)}return e.x0+r<=t.inner[0]&&e.x0+r+e.width>t.inner[2]&&e.y0<=t.inner[1]&&e.y0+e.height>t.inner[3]}var fJ=8;function pJ(e){return tE(e.chart,e.level)*e.tileSize}function mJ(e){let t=`width`in e?e.width:e.codedWidth,n=`height`in e?e.height:e.codedHeight;return typeof t!=`number`||typeof n!=`number`||!t||!n?null:[t,n]}function hJ(e,t){let[n,r]=mJ(e)??[t,t/2],i=Math.max(2,Math.min(n,Math.round(t))),a=Math.max(1,Math.round(i*r/n)),o=document.createElement(`canvas`);o.width=i,o.height=a;let s=o.getContext(`2d`,{willReadFrequently:!0});if(!s)return null;s.imageSmoothingEnabled=!0,s.imageSmoothingQuality=`high`,s.drawImage(e,0,0,i,a);try{let{data:e}=s.getImageData(0,0,i,a);return{width:i,height:a,data:e}}catch{return null}}var gJ=class{width;height;refU;refV;u;v;inside;caps=new Map;constructor(e,t,n){this.width=t,this.height=n;let r=t*n;this.u=new Float32Array(r),this.v=new Float32Array(r),this.inside=new Uint8Array(r);let{projection:i}=e,a=i.inverse(e.view.centerX,e.view.centerY);[this.refU,this.refV]=a?tJ(0,a[0],a[1]):[.5,.5];let o=1/e.scale,s=e.view.centerX-e.width/2*o,c=e.view.centerY+e.height/2*o;for(let r=0;r<n;r++){let n=c-(r+.5)*o,a=r*t;i.rowInverse?this.fillRow(i,a,n,s,o,e):this.walkRow(i,a,n,s,o)}}fillRow(e,t,n,r,i,a){let o=e.rowInverse(n);if(!o)return;let{width:s,refU:c}=this,l=(90-o.lat)/180-this.refV,{minX:u,maxX:d}=e.extent,f=d-u,p=a.repeatsHorizontally;for(let n=0;n<s;n++){let a=r+(n+.5)*i;if(p)a=((a-u)%f+f)%f+u;else if(a<u||a>d)continue;if(a<-o.maxAbsX||a>o.maxAbsX)continue;let s=(a*o.lonPerX+e.centerLon+180)/360-c,m=t+n;this.u[m]=s-Math.round(s),this.v[m]=l,this.inside[m]=1}}walkRow(e,t,n,r,i){let{width:a}=this,o=0,s=a-1;if(e.azimuthal){let t=e.extent.maxX;if(Math.abs(n)>t)return;let c=Math.sqrt(t*t-n*n);o=Math.max(0,Math.ceil((-c-r)/i-.5)),s=Math.min(a-1,Math.floor((c-r)/i-.5))}for(let a=o;a<=s;a++){let o=r+(a+.5)*i,s=e.inverse(o,n);if(!s)continue;let c=t+a,l=(s[0]+180)/360-this.refU;this.u[c]=l-Math.round(l),this.v[c]=(90-s[1])/180-this.refV,this.inside[c]=1}}offsets(e){if(e===0)return{refX:this.refU,refY:this.refV,x:this.u,y:this.v};let t=this.caps.get(e);return t||(t=this.capOffsets(e),this.caps.set(e,t)),t}capOffsets(e){let{u:t,v:n,inside:r,refU:i,refV:a,width:o,height:s}=this,c=e===1?1:-1,[l,u]=tJ(e,i*360-180,90-a*180),d=new Float32Array(t.length),f=new Float32Array(t.length),p=e=>{let r=c>0?a+n[e]:1-a-n[e],o=.5*Math.tan(r*Math.PI/2)/ZT,s=(i+t[e])*2*Math.PI-Math.PI;d[e]=.5+o*Math.cos(s)-l,f[e]=.5-c*o*Math.sin(s)-u},m=_J(o),h=_J(s);if(m.length<2||h.length<2){for(let e=0;e<t.length;e++)r[e]&&p(e);return{refX:l,refY:u,x:d,y:f}}for(let e of h)for(let t of m)r[e*o+t]&&p(e*o+t);for(let e=0;e<h.length-1;e++){let t=h[e],n=h[e+1],i=e===h.length-2?n:n-1;for(let e=0;e<m.length-1;e++){let a=m[e],s=m[e+1],c=e===m.length-2?s:s-1,l=t*o+a,u=t*o+s,h=n*o+a,g=n*o+s;if(!(r[l]&&r[u]&&r[h]&&r[g])){for(let e=t;e<=i;e++)for(let t=e*o+a;t<=e*o+c;t++)r[t]&&p(t);continue}for(let e=t;e<=i;e++){let r=(e-t)/(n-t),i=d[l]+r*(d[h]-d[l]),p=f[l]+r*(f[h]-f[l]),m=(d[u]+r*(d[g]-d[u])-i)/(s-a),_=(f[u]+r*(f[g]-f[u])-p)/(s-a),v=e===t||e===n;for(let t=a;t<=c;t++)v&&(t===a||t===s)||(d[e*o+t]=i,f[e*o+t]=p),i+=m,p+=_}}}return{refX:l,refY:u,x:d,y:f}}};function _J(e){let t=[];for(let n=0;n<e-1;n+=fJ)t.push(n);return t.push(e-1),t}function vJ(e,t,n){let r=n.data;r.fill(0);let{width:i,height:a,u:o,v:s,inside:c,refU:l,refV:u}=e,d=i*a;for(let n of t){let{image:t,opacity:i,blend:a}=n;if(i<=0)continue;let f=t.data,p=t.width,m=t.height,h=a===`add`,g=(n.detail??[]).map(t=>{let n=e.offsets(t.chart),r=pJ(t),i=t.chart===0?r/2:r,a=n.refX*r-t.x0;return t.chart===0&&(a-=r*Math.round((a-t.width/2)/r)),{xs:n.x,ys:n.y,left:a,top:n.refY*i-t.y0,across:r,down:i,width:t.width,height:t.height,data:t.data}});for(let e=0;e<d;e++){if(!c[e])continue;let t=f,n=-1;for(let r=0;r<g.length;r++){let i=g[r],a=i.left+i.xs[e]*i.across;if(!(a>=0&&a<i.width))continue;let o=i.top+i.ys[e]*i.down;if(!(o>=0&&o<i.height))continue;let s=((o|0)*i.width+(a|0))*4;if(i.data[s+3]!==0){t=i.data,n=s;break}}if(n<0){let t=l+o[e];t-=Math.floor(t);let r=Math.floor(t*p),i=Math.floor((u+s[e])*m);r=r<0?r+p:r>=p?r-p:r,i=i<0?0:i>=m?m-1:i,n=(i*p+r)*4}let a=t[n+3]/255*i;if(a<=0)continue;let d=e*4;if(h){r[d]=Math.min(255,r[d]+t[n]*a),r[d+1]=Math.min(255,r[d+1]+t[n+1]*a),r[d+2]=Math.min(255,r[d+2]+t[n+2]*a);continue}let _=r[d+3]/255,v=a+_*(1-a);if(!(v<=0)){if(a>=1)r[d]=t[n],r[d+1]=t[n+1],r[d+2]=t[n+2];else{let e=_*(1-a);r[d]=(t[n]*a+r[d]*e)/v,r[d+1]=(t[n+1]*a+r[d+1]*e)/v,r[d+2]=(t[n+2]*a+r[d+2]*e)/v}r[d+3]=v*255}}}}function yJ(e,t,n){let{minX:r,maxX:i,minY:a,maxY:o}=t.projection.extent,s=t.projection.centerLon*Math.PI/180,[c,l]=t.toScreen(r-s,o),[u,d]=t.toScreen(i-s,a),f=t.repeatsHorizontally?0:t.toScreen(r,o)[0],p=t.repeatsHorizontally?e.canvas.width:t.toScreen(i,o)[0],m=(e,t,n)=>{let r=e.createPattern(t.image,`repeat-x`);if(!r)return;r.setTransform(new DOMMatrix().translateSelf(c,l).scaleSelf((u-c)/n[0],(d-l)/n[1])),e.save(),e.imageSmoothingEnabled=!0,e.imageSmoothingQuality=`high`,e.fillStyle=r,e.fillRect(f,l,p-f,d-l);let i=t.detail??[];i.length&&(e.beginPath(),e.rect(f,l,p-f,d-l),e.clip());for(let t=i.length-1;t>=0;t--){let n=i[t],r=(u-c)/pJ(n),a=c+n.x0*r,o=a+n.width*r/2;a+=(u-c)*Math.round((e.canvas.width/2-o)/(u-c)),e.drawImage(n.canvas,a,l+n.y0*r,n.width*r,n.height*r)}e.restore()};e.save();for(let t of n){if(t.opacity<=0)continue;let n=mJ(t.image);if(!n)continue;e.globalAlpha=t.opacity,e.globalCompositeOperation=t.blend===`add`?`lighter`:`source-over`;let r=t.detail?.length&&(t.opacity<1||t.blend===`add`)?xJ(e.canvas.width,e.canvas.height):null;r?(m(r,t,n),e.drawImage(r.canvas,0,0)):m(e,t,n)}e.restore()}var bJ=null;function xJ(e,t){return bJ??=document.createElement(`canvas`).getContext(`2d`),bJ?(bJ.canvas.width!==e||bJ.canvas.height!==t?(bJ.canvas.width=e,bJ.canvas.height=t):bJ.clearRect(0,0,e,t),bJ):null}var SJ=[`low`,`medium`,`high`];function CJ(e){let t=/^naif-(\d)\d\d$/.exec(e);return t?`naif-${t[1]}`:null}async function wJ(e){try{let t=await fetch(e);return t.ok?await t.json():null}catch{return null}}async function TJ(e){let t=await Promise.all(SJ.map(t=>fetch(Qt(`/v1/textures/${e}/${t}.webp`,`textures`),{method:`HEAD`}).then(e=>e.ok).catch(()=>!1)));return SJ.filter((e,n)=>t[n])}async function EJ(e,t,n=TJ){if(!t?.map_texture_available||!t.texture)return{};let r=o([{...t.texture,id:e,tiers:void 0},...t.alternates??[]]);if(!r)return{};let i=r.tiers??await n(r.id);if(i.length===0)return{};let{frames:a,...s}=r,c=t.radii;return{surface:{...s,tiers:i,monthlyFrames:a},radiusKm:c?(c.a+c.b+c.c)/3:void 0}}async function DJ(e){return EJ(e,(await tS(e,!1).catch(()=>null))?.global)}async function OJ(e){let t=CJ(e);if(!t)return DJ(e);let n=(await wJ(`${Gt()}/v1/systems/${t}.json`))?.[e];if(!n?.texture||!n.tiers?.length)return DJ(e);let r=o([{...n.texture,id:e,tiers:n.tiers},...n.alternates??[]]);if(!r)return DJ(e);let{frames:i,...a}=r,s=n.radii;return{surface:{...a,monthlyFrames:i},clouds:n.clouds,night:n.night,radiusKm:s?(s.a+s.b+s.c)/3:void 0}}var kJ={low:2048,medium:8192,high:16383};function AJ(e){return SJ.find(t=>kJ[t]>=e)??SJ[SJ.length-1]}function jJ(e,t){return SJ.indexOf(e)<=SJ.indexOf(t)?e:t}function MJ(e,t){let n=SJ.indexOf(t);for(let t=n<0?SJ.length-1:n;t>=0;t--)if(e.includes(SJ[t]))return SJ[t];return e[0]??`low`}function NJ(e,t,n){let r=e.id;if(e.frames?.length){let i=YM(n,e.frames,e.coverage);if(i)return Qt(`/v1/textures/${r}/${t}_${i}.webp`,`textures`)}let i=uP(n,e.monthlyFrames);return Qt(i===void 0?`/v1/textures/${r}/${t}.webp`:`/v1/textures/${r}/${t}_${String(i).padStart(2,`0`)}.webp`,`textures`)}function PJ(e,t){return e*t*4}function FJ(){let e=navigator.deviceMemory??4;return Math.max(1,Math.min(e,8))*24*1024*1024}var IJ=class{entries=new Map;clock=0;constructor(e){this.free=e}claim(e){let t=this.entries.get(e);return t?(t.claims++,t.used=++this.clock,t.value):null}put(e,t,n){let r=this.entries.get(e);return r?(r.value!==t&&this.free(t),r.claims++,r.used=++this.clock,r.value):(this.entries.set(e,{value:t,bytes:n,claims:1,used:++this.clock}),this.evict(),t)}release(e,t=!0){let n=this.entries.get(e);n&&(n.claims=Math.max(0,n.claims-1),!t&&!n.claims&&(this.entries.delete(e),this.free(n.value)),this.evict())}evict(){let e=0;for(let t of this.entries.values())t.claims||(e+=t.bytes);let t=FJ();if(e<=t)return;let n=[...this.entries].filter(([,e])=>!e.claims).sort((e,t)=>e[1].used-t[1].used);for(let[r,i]of n){if(e<=t)return;this.entries.delete(r),this.free(i.value),e-=i.bytes}}clear(){for(let e of this.entries.values())this.free(e.value);this.entries.clear()}},LJ=new IJ(e=>e.close()),RJ=new IJ(()=>{}),zJ=new Map;function BJ(e,t){return t?`${e}@${t}`:e}async function VJ(e,t){let n=BJ(e,t),r=LJ.claim(n);if(r)return{key:n,bitmap:r};let i=zJ.get(n);if(!i){i=HJ(e,t),zJ.set(n,i);let r=()=>zJ.delete(n);i.then(r,r)}let a=await i;return a?{key:n,bitmap:LJ.put(n,a,PJ(a.width,a.height))}:null}async function HJ(e,t){let n=await fetch(e);if(!n.ok)throw Error(`HTTP ${n.status}`);let r=await n.blob();if(!t)return createImageBitmap(r);try{return await createImageBitmap(r,{resizeWidth:t,resizeQuality:`high`})}catch{return createImageBitmap(r)}}function UJ(e,t=!0){LJ.release(e,t)}function WJ(e,t,n){let r=BJ(e,t),i=RJ.claim(r);if(i)return{key:r,raster:i};let a=hJ(n,t);return a?{key:r,raster:RJ.put(r,a,PJ(a.width,a.height))}:null}function GJ(e){RJ.release(e)}var KJ=4,qJ=2,JJ=null;function YJ(e,t,n,r){let i=Math.max(n,0),a=Math.max(r,0),o=Math.min(n+t.width,e.width)-i,s=Math.min(r+t.height,e.height)-a;if(o<=0||s<=0||(JJ??=document.createElement(`canvas`).getContext(`2d`,{willReadFrequently:!0}),!JJ))return;(JJ.canvas.width<t.width||JJ.canvas.height<t.height)&&(JJ.canvas.width=t.width,JJ.canvas.height=t.height),JJ.globalCompositeOperation=`copy`,JJ.drawImage(t,i-n,a-r,o,s,0,0,o,s);let c=JJ.getImageData(0,0,o,s).data,l=o*4;for(let t=0;t<s;t++)e.data.set(c.subarray(t*l,(t+1)*l),((a+t)*e.width+i)*4)}var XJ=class{windows=[];kind=`pixels`;failures=0;failed=new Set;dead=!1;constructor(e,t,n){this.block=e,this.changed=t,this.moves=n}plan(e,t,n){t!==this.kind&&(this.clear(),this.kind=t);for(let e of this.windows)e.wanted=!1;for(let t of this.dead?[]:e){let e=this.windows.find(e=>e.frame===n&&dJ(e,t,this.block.tile_size));e?e.wanted=!0:this.windows.push(this.open(t,n))}this.prune()}rasters(){return this.ordered().filter(e=>!!e.data)}canvases(){return this.ordered().flatMap(e=>e.ctx?[{...e,canvas:e.ctx.canvas}]:[])}clear(){for(let e of this.windows)this.drop(e);this.windows=[]}drop(e){e.dropped=!0,e.data=void 0,e.ctx&&(e.ctx.canvas.width=0)}ordered(){return[...this.windows].sort((e,t)=>t.level-e.level||Number(t.wanted)-Number(e.wanted))}open(e,t){let n={...e,tileSize:this.block.tile_size,frame:t,pending:0,wanted:!0,dropped:!1};if(this.kind===`canvas`){let t=document.createElement(`canvas`);t.width=e.width,t.height=e.height,n.ctx=t.getContext(`2d`)??void 0}else n.data=new Uint8ClampedArray(e.width*e.height*4);for(let r of uJ(e,this.block)){let e=r.patch?.version??(r.cap===``?dE(this.block,r.level,r.x,r.y):this.block.version),i=Jt({id:this.block.id,version:e},r.cap,r.level,r.x,r.y,t);this.failed.has(i)||(n.pending++,this.load(n,i,r.dx,r.dy))}return n}async load(e,t,n,r){try{let i=await VJ(t,null);if(i)try{e.ctx&&!e.dropped?e.ctx.drawImage(i.bitmap,n,r):e.dropped||YJ(e,i.bitmap,n,r)}finally{UJ(i.key,this.moves())}this.failures=0}catch{this.failed.add(t),++this.failures>=KJ&&(this.dead=!0)}if(e.pending--,this.dead)this.clear();else if(e.dropped)return;else e.pending===0&&this.prune();this.changed()}prune(){let e=this.windows.some(e=>e.wanted&&e.pending>0),t=this.windows.filter(e=>!e.wanted),n=e?t.slice(-qJ):[];for(let e of t)n.includes(e)||this.drop(e);this.windows=this.windows.filter(e=>!e.dropped)}};function ZJ(e,t,n){return[WF(e,n.minLon,n.maxLon),Math.min(Math.max(t,n.minLat??-90),n.maxLat??90)]}var QJ=class{projection;width;height;view;scale;constructor(e,t,n,r){this.projection=e,this.width=t,this.height=n,this.view=r;let{minX:i,maxX:a,minY:o,maxY:s}=e.extent,c=Math.min(t/(a-i),n/(s-o));this.scale=c*r.zoom}toScreen(e,t){return[this.width/2+(e-this.view.centerX)*this.scale,this.height/2-(t-this.view.centerY)*this.scale]}fromScreen(e,t){return[this.view.centerX+(e-this.width/2)/this.scale,this.view.centerY-(t-this.height/2)/this.scale]}project(e,t){let n=this.projection.forward(e,t);return n?this.toScreen(n[0],n[1]):null}unproject(e,t){let[n,r]=this.fromScreen(e,t);return this.projection.inverse(n,r)}get worldWidthPx(){let{minX:e,maxX:t}=this.projection.extent;return(t-e)*this.scale}get repeatsHorizontally(){return $J(this.projection,this.worldWidthPx,this.width)}get repeatShifts(){if(!this.repeatsHorizontally)return[0];let e=this.worldWidthPx,t=this.toScreen(this.projection.extent.minX,0)[0];return[0,-e,e].filter(n=>t+n<this.width&&t+n+e>0)}};function $J(e,t,n){return e.cyclic&&e.rectangular&&t>=n-.5}function eY(e,t,n,r,i){let a=Math.min(Math.max(e.zoom,1,i.minZoom??1),i.maxZoom??1/0),o=tY(e,t,i),s=t.extent,c=s.maxX-s.minX,l=s.maxY-s.minY,u=Math.min(n/c,r/l)*a,d=n/2/u,f=r/2/u,p=(s.minX+s.maxX)/2,m=(s.minY+s.maxY)/2,h=(e,t,n,r)=>n>=r/2?t:Math.min(t+r/2-n,Math.max(t-r/2+n,e));return{zoom:a,centerX:$J(t,c*u,n)?((o.centerX-s.minX)%c+c)%c+s.minX:h(o.centerX,p,d,c),centerY:h(o.centerY,m,f,l)}}function tY(e,t,n){if(!(n.minLon!==void 0||n.maxLon!==void 0||n.minLat!==void 0||n.maxLat!==void 0)||t.azimuthal)return e;let r=t.inverse(e.centerX,e.centerY);if(!r)return e;let[i,a]=ZJ(r[0],r[1],n);if(i===r[0]&&a===r[1])return e;let o=t.forward(i,a);return o?{centerX:o[0],centerY:o[1]}:e}var nY=[[6,`high`],[2.5,`medium`]],rY=22e5,iY=4096,aY=11,oY=.4,sY=.8,cY=140,lY=`medium`,uY=250,dY=2,fY=`naif-399`,pY=[{kind:`surface`,label:e=>e.layer_surface(),visible:!0,opacity:1,blend:`normal`},{kind:`clouds`,label:e=>e.layer_clouds(),visible:!0,opacity:1,blend:`normal`},{kind:`night`,label:e=>e.layer_night(),visible:!1,opacity:.85,blend:`add`}];function mY(e){return e.kind===`raster`}var hY=new WeakMap,gY=class{container=null;root=document.createElement(`div`);canvas=document.createElement(`canvas`);svg=document.createElementNS(Rq,`svg`);layerGroup=document.createElementNS(Rq,`g`);shapeGroup=document.createElementNS(Rq,`g`);markerLayer=document.createElement(`div`);ctx;overlay;bodyId;sources={};layerList=[];projection;projectionId;projectionOptions;view;limits;ownMaxZoom;limitsArmed=!1;jd;cooperative=null;bodyRadiusKm=null;bitmaps=new Map;rasters=new Map;pending=new Set;missing=new Set;tiles=new Map;plannedAt=0;generation=0;controls=null;attribution=null;dragPan;scrollZoom;cooperativeGestures;lookup=null;lookupKey=``;buffer=null;frame=0;resizeObserver=null;listeners=new Map;announcedReady=!1;disposed=!1;moving=!1;sharpWidth=0;msPerPixel=0;settleTimer=0;chosenVisibility=new Map;customLayers=[];constructor(e={}){this.bodyId=e.body??fY,this.projectionId=e.projection??`equirectangular`,this.projectionOptions={centerLon:e.centerLon??0,centerLat:e.centerLat,clipAngle:e.clipAngle},this.projection=PK(this.projectionId,this.projectionOptions),this.limits={maxZoom:16,...e.limits},this.ownMaxZoom=e.limits?.maxZoom===void 0,this.view={zoom:e.zoom??1,centerX:0,centerY:0},this.jd=e.jd??Ag(new Date),this.dragPan=new bq(xq(e.interactions?.dragPan,e.interactive),e=>this.root.classList.toggle(`sm-flat--interactive`,e)),this.scrollZoom=new bq(xq(e.interactions?.scrollZoom,e.interactive)),this.cooperativeGestures=new bq(e.cooperativeGestures??!1,e=>this.applyCooperative(e)),this.root.className=`sm-flat`,this.canvas.className=`sm-flat__raster`,this.svg.setAttribute(`class`,`sm-flat__vector`),this.markerLayer.className=`sm-flat__markers`,this.svg.append(this.layerGroup,this.shapeGroup),this.root.append(this.canvas,this.svg,this.markerLayer),this.ctx=this.canvas.getContext(`2d`),this.overlay=new Yq(this.shapeGroup,this.markerLayer,()=>this.render()),this.root.classList.toggle(`sm-flat--interactive`,this.dragPan.isEnabled()),this.applyCooperative(this.cooperativeGestures.isEnabled());for(let[t,n]of Object.entries(e.layers??{}))this.chosenVisibility.set(t,n)}mount(e){this.container=e,e.append(this.root),this.controls=new kq(this,this.root),this.cooperative=new Cq(this.root,this.cooperativeGestures.isEnabled()),this.resizeObserver=new ResizeObserver(()=>this.renderMoving()),this.resizeObserver.observe(this.root),this.attachInteraction()}addControl(e,t){if(!this.controls)throw Error(`spacemap: the map is not mounted`);return this.controls.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.unmount()}unmount(){this.disposed=!0,this.controls?.clear(),this.controls=null,this.cooperative?.dispose(),this.cooperative=null,this.resizeObserver?.disconnect(),this.resizeObserver=null,cancelAnimationFrame(this.frame),clearTimeout(this.settleTimer);for(let e of this.layerList)mY(e)||e.dispose?.();this.overlay.clear(),this.dropTextures(),this.dropTiles(),this.root.remove(),this.container=null}async load(){await this.adopt(this.bodyId)}async adopt(e){let t=await OJ(e);if(!this.disposed){if(!t.surface){let t=Error(`spacemap: no map texture for ${e}`);throw this.emit(`error`,t),t}e!==this.bodyId&&this.release(),this.bodyId=e,this.sources=t,this.bodyRadiusKm=t.radiusKm??null,this.overlay.setBodyRadiusKm(this.bodyRadiusKm),this.buildLayers(),await this.loadVisible(),!this.disposed&&this.render()}}release(){this.generation++,this.dropTextures(),this.dropTiles(),this.missing.clear();for(let e of this.layerList)!mY(e)&&!this.customLayers.includes(e)&&e.dispose?.()}buildLayers(){let{messages:e}=i(),t=[];this.dropTiles();for(let n of pY){let r=this.sources[n.kind];if(!r)continue;let i={kind:`raster`,id:n.kind,label:n.label(e),visible:n.visible,opacity:n.opacity,blend:n.blend,credit:Bq(r),tiers:r.tiers,url:(e,t)=>NJ(r,t,e)};if(t.push(i),!r.tiles)continue;let a=new XJ(r.tiles,()=>{a.dead&&(this.loadVisible(),this.emit(`layerschange`,this.layers)),this.render()},()=>this.moves());this.tiles.set(i,a)}t.push(Hq(e.layer_graticule())),t.push(Wq(this.bodyId,e.layer_nomenclature())),t.push(...this.customLayers);for(let e of t){let t=this.chosenVisibility.get(e.id);t!==void 0&&(e.visible=t)}this.layerList=t,this.emit(`layerschange`,this.layers)}get layers(){return this.layerList.map(zq)}getLayers(){return this.layerList.map(e=>e.id)}isLayerVisible(e){return this.layerList.find(t=>t.id===e)?.visible??!1}get credits(){let e=new Set,t=[],n=n=>{e.has(n.organisation)||(e.add(n.organisation),t.push(n))};for(let e of this.layerList){if(!e.visible||!e.credit)continue;n(e.credit);let t=this.tilesOf(e);if(!t)continue;let r={...e.credit,tiles:t.block},i=On(r);i&&n(i);for(let e of kn(r))n(e)}return t}setLayerVisible(e,t){this.chosenVisibility.set(e,t);let n=this.layerList.find(t=>t.id===e);!n||n.visible===t||(n.visible=t,this.emit(`layerschange`,this.layers),this.loadVisible(),this.render())}setLayerOpacity(e,t){let n=this.layerList.find(t=>t.id===e);!n||!mY(n)||(n.opacity=Math.min(1,Math.max(0,t)),this.render())}addRasterLayer(e){let t={kind:`raster`,id:e.id,label:e.label??e.id,visible:e.visible??!0,opacity:e.opacity??1,blend:e.blend??`normal`,credit:e.credit,tiers:[`low`],url:()=>e.url};this.customLayers.push(t),this.layerList.push(t),this.emit(`layerschange`,this.layers),this.loadVisible()}addVectorLayer(e){let t={kind:`vector`,id:e.id,label:e.label??e.id,visible:e.visible??!0,credit:e.credit,render:e.render,prepare:e.prepare};this.customLayers.push(t),this.layerList.push(t),this.emit(`layerschange`,this.layers),this.loadVisible()}get projectionName(){return this.projectionId}static get projections(){return NK}setProjection(e,t={}){this.limitsArmed=!1,this.projectionId=e,this.projectionOptions={...this.projectionOptions,...t},this.projection=PK(e,this.projectionOptions),this.view={...this.view,centerX:0,centerY:0},this.render(),this.emit(`viewchange`,this.viewState)}get viewState(){let e=this.viewport(),t=e.unproject(e.width/2,e.height/2);return{projection:this.projectionId,zoom:this.view.zoom,centerLon:t?.[0]??this.projectionOptions.centerLon??0,centerLat:t?.[1]??this.projectionOptions.centerLat??0}}setView(e){if(e.projection&&e.projection!==this.projectionId&&this.setProjection(e.projection),this.limitsArmed=!1,e.zoom!==void 0&&(this.view={...this.view,zoom:e.zoom}),e.centerLon!==void 0||e.centerLat!==void 0){let t=this.viewState,n=e.centerLon??t.centerLon,r=e.centerLat??t.centerLat;if(this.projection.azimuthal)this.projectionOptions={...this.projectionOptions,centerLon:n,centerLat:r},this.projection=PK(this.projectionId,this.projectionOptions);else{let e=this.projection.forward(n,r);e&&(this.view={...this.view,centerX:e[0],centerY:e[1]})}}this.loadVisible(),this.render(),this.emit(`viewchange`,this.viewState)}setLimits(e){return this.limits={maxZoom:16,...e},this.ownMaxZoom=e.maxZoom===void 0,this.render(),this}getLimits(){return this.ownMaxZoom?{...this.limits,maxZoom:this.pictureMaxZoom()}:{...this.limits}}setTime(e){this.jd=e,this.loadVisible(),this.render()}async setBody(e){e!==this.bodyId&&(this.limitsArmed=!1,await this.adopt(e))}project(e,t){return this.viewport().project(e,t)}unproject(e,t){let n=this.viewport().unproject(e,t);return n?{lon:n[0],lat:n[1]}:null}addPolyline(e){let t=this.overlay.addPolyline(e);return this.render(),t}addPolygon(e){let t=this.overlay.addPolygon(e);return this.render(),t}addBox(e){let t=this.overlay.addBox(e);return this.render(),t}addCircle(e){let t=this.overlay.addCircle(e);return this.render(),t}addMarker(e){let t=this.overlay.addMarker(e);return this.render(),t}clearDrawings(){this.overlay.clear(),this.render()}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=((...e)=>{r(),t(...e)});hY.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners.get(e);if(n){n.delete(t);for(let e of n)hY.get(e)===t&&n.delete(e)}}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of[...n])e(...t)}tier(e){let t=nY.find(([e])=>this.view.zoom>=e)?.[1]??`low`;return this.tilesOf(e)&&(t=jJ(t,lY)),MJ(e.tiers,jJ(t,AJ(this.usableSourceWidth())))}usableSourceWidth(){return this.projectionId===`equirectangular`?this.deviceWidth()*this.view.zoom:this.workingWidth()}deviceWidth(){return this.sharpWidth||Math.max(1,this.root.clientWidth)}workingWidth(){let e=this.deviceWidth()*2*this.view.zoom;return Math.min(iY,2**Math.ceil(Math.log2(Math.max(256,e))))}decodeWidth(e){return this.projectionId===`equirectangular`?null:Math.min(this.workingWidth(),kJ[e]??iY)}picturesInUse(){return this.layerList.filter(e=>mY(e)&&e.visible).map(e=>{let t=this.tier(e);return{url:e.url(this.jd,t),tier:t}})}async loadVisible(){let e=this.picturesInUse(),t=this.layerList.filter(e=>!mY(e)&&e.visible&&!!e.prepare).map(e=>e.prepare().then(()=>this.render(),()=>{})),n=e.filter(({url:e,tier:t})=>this.bitmaps.get(e)?.key!==BJ(e,this.decodeWidth(t))).filter(({url:e})=>!this.pending.has(e)&&!this.missing.has(e)).map(async({url:e,tier:t})=>{this.pending.add(e);let n=this.generation;try{let r=await VJ(e,this.decodeWidth(t));if(!r)return;if(this.disposed||n!==this.generation){UJ(r.key);return}this.hold(this.bitmaps,e,r,UJ),this.render()}catch(t){if(n!==this.generation)return;this.missing.add(e),this.emit(`error`,Error(`spacemap: could not load ${e}`,{cause:t}))}finally{this.pending.delete(e)}});await Promise.all([...t,...n]),this.dropUnused(new Set(this.picturesInUse().map(({url:e})=>e)))}dropUnused(e){for(let[t,n]of this.bitmaps)e.has(t)||(UJ(n.key),this.bitmaps.delete(t));for(let[t,n]of this.rasters)e.has(t)||(GJ(n.key),this.rasters.delete(t))}hold(e,t,n,r){let i=e.get(t);i?.key!==n.key&&(i&&r(i.key),e.set(t,n))}rasterFor(e,t){let n=this.rasters.get(e);if(n?.key===BJ(e,t))return n.raster;let r=this.bitmaps.get(e)?.bitmap;if(!r)return null;let i=WJ(e,t,r);return i?(this.hold(this.rasters,e,i,GJ),i.raster):null}dropTextures(){for(let e of this.bitmaps.values())UJ(e.key);for(let e of this.rasters.values())GJ(e.key);this.bitmaps.clear(),this.rasters.clear()}tilesOf(e){let t=this.tiles.get(e);if(!(!t||!mY(e)||t.dead||Kt()===``)&&a(t.block.distribution))return Math.max(t.block.max_level,...(t.block.patches??[]).map(e=>e.max_level))>=this.firstTileLevel(e,t)?t:void 0}firstTileLevel(e,t){let n=kJ[MJ(e.tiers,lY)]??iY,r=this.projectionId===`equirectangular`?n:Math.min(n,iY);return Math.floor(Math.log2(r/(2*t.block.tile_size)))+1}frameSample(e,t){let{width:n,height:r,projection:i}=e,a=(t,n)=>e.unproject(t,n),o=a(n/2,r/2),s=a(n/2+1,r/2),c=a(n/2,r/2+1);if(!o||!s||!c)return;let l={lon:o[0],lat:o[1]},u=Math.min(VK(l,{lon:s[0],lat:s[1]}),VK(l,{lon:c[0],lat:c[1]})),d=t=>{let a=i.azimuthal?e.project(0,t):null;return!!a&&a[0]>=0&&a[0]<=n&&a[1]>=0&&a[1]<=r};return{place:(e,t)=>a(e*n,t*r),step:u*Math.PI/180/t,north:d(90),south:d(-90)}}planTiles(e,t){let n=this.projectionId===`equirectangular`?`canvas`:`pixels`,r;for(let[i,a]of this.tiles){let o=mY(i)&&i.visible&&i.opacity>0&&this.tilesOf(i);r??=o?this.frameSample(e,t):void 0;let s=o&&r?this.firstTileLevel(i,a):0,c=o&&r?lJ(a.block,r,s,this.moves()):[];a.plan(c,n,uP(this.jd,a.block.frames))}}moves(){return this.dragPan.isEnabled()||this.scrollZoom.isEnabled()}dropTiles(){for(let e of this.tiles.values())e.clear();this.tiles.clear()}pictureMaxZoom(){let e=16,{clientWidth:t,clientHeight:n}=this.root;if(!t||!n)return e;let r=new QJ(this.projection,t,n,this.view),i=this.frameSample(r,1),a=i?.place(.5,.5);if(!i||!a)return e;for(let t of this.layerList){let n=t.visible?this.tilesOf(t):void 0;if(!n)continue;let r=rJ(iJ(n.block,a[0],a[1]),n.block.tile_size)/dY;e=Math.max(e,this.view.zoom*i.step/r)}return e}heldLimits(){return this.ownMaxZoom&&this.layerList.some(e=>e.visible&&this.tilesOf(e))?{...this.limits,maxZoom:void 0}:this.limits}tileStepDeg(e,t){let n=this.layerList.find(e=>e.id===`surface`),r=n&&this.tilesOf(n);return r?rJ(iJ(r.block,e,t),r.block.tile_size)*180/Math.PI:null}viewport(e,t){let n=e??this.root.clientWidth??1,r=t??this.root.clientHeight??1,i=this.limitsArmed?this.heldLimits():{};return this.view=eY(this.view,this.projection,n,r,i),new QJ(this.projection,Math.max(1,n),Math.max(1,r),this.view)}render(){this.disposed||(cancelAnimationFrame(this.frame),this.frame=requestAnimationFrame(()=>this.draw()))}renderMoving(){this.moving=!0,clearTimeout(this.settleTimer),this.settleTimer=window.setTimeout(()=>{this.moving=!1,this.render()},cY),this.render()}draw(){let e=this.root.clientWidth,t=this.root.clientHeight;if(!this.ctx||e===0||t===0)return;let n=Math.min(window.devicePixelRatio||1,2),r=Math.sqrt(rY/(e*t*n*n)),i=n*Math.min(1,r),a=Math.max(1,Math.round(e*i));a!==this.sharpWidth&&(this.sharpWidth=a,this.loadVisible());let o=e*i*t*i,s=i*(this.moving?this.interactionScale(o):1),c=Math.max(1,Math.round(e*s)),l=Math.max(1,Math.round(t*s));(this.canvas.width!==c||this.canvas.height!==l)&&(this.canvas.width=c,this.canvas.height=l,this.buffer=null,this.lookup=null);let u=this.viewport(e,t),d=new QJ(this.projection,c,l,this.view),f=performance.now();(!this.moving||f-this.plannedAt>uY)&&(this.plannedAt=f,this.planTiles(u,i)),this.clipToDisc(u),this.drawRaster(d,c,l),this.drawVector(u),!this.announcedReady&&this.bitmaps.size>0&&(this.announcedReady=!0,this.emit(`ready`))}record(e,t){if(t<=0)return;let n=e/t;this.msPerPixel=this.msPerPixel===0?n:this.msPerPixel*.7+n*.3}interactionScale(e){if(this.msPerPixel<=0||e<=0)return 1;let t=Math.sqrt(aY/this.msPerPixel/e);return t>sY?1:Math.max(oY,t)}clipToDisc(e){let{projection:t}=e;if(!t.azimuthal){this.canvas.style.clipPath=``;return}let[n,r]=e.toScreen(0,0),i=t.extent.maxX*e.scale;this.canvas.style.clipPath=`circle(${i}px at ${n}px ${r}px)`}drawRaster(e,t,n){let r=this.ctx;r.clearRect(0,0,t,n);let i=this.layerList.filter(e=>mY(e)&&e.visible);if(i.length===0)return;if(this.projectionId===`equirectangular`){let t=i.map(e=>({image:this.bitmaps.get(e.url(this.jd,this.tier(e)))?.bitmap,opacity:e.opacity,blend:e.blend,detail:this.tilesOf(e)?.canvases()})).filter(e=>!!e.image);t.length&&yJ(r,e,t);return}let a=this.workingWidth(),o=i.map(e=>({image:this.rasterFor(e.url(this.jd,this.tier(e)),a),opacity:e.opacity,blend:e.blend,detail:this.tilesOf(e)?.rasters()})).filter(e=>!!e.image);if(o.length===0)return;(!this.buffer||this.buffer.width!==t||this.buffer.height!==n)&&(this.buffer=r.createImageData(t,n));let s=`${this.projectionId}|${JSON.stringify(this.projectionOptions)}|${this.view.zoom}|${this.view.centerX}|${this.view.centerY}|${t}x${n}`,c=!this.lookup||this.lookupKey!==s,l=performance.now();c&&(this.lookup=new gJ(e,t,n),this.lookupKey=s),vJ(this.lookup,o,this.buffer),r.putImageData(this.buffer,0,0),c&&this.record(performance.now()-l,t*n)}drawVector(e){this.svg.setAttribute(`viewBox`,`0 0 ${e.width} ${e.height}`),this.layerGroup.replaceChildren();for(let t of this.layerList){if(mY(t)||!t.visible)continue;let n=document.createElementNS(Rq,`g`);n.setAttribute(`data-layer`,t.id),t.render(e,n),this.layerGroup.append(n)}this.overlay.redraw(e)}applyCooperative(e){this.root.classList.toggle(`sm-flat--cooperative`,e),this.cooperative?.setEnabled(e)}attachInteraction(){let e=!1,t=0,n=0,r=!1,i=!1,a=new Map,o=-1,s=0,c=null,l=()=>{let[e,t]=[...a.values()];if(!t)return null;let n=this.root.getBoundingClientRect();return{gap:Math.hypot(e.x-t.x,e.y-t.y),x:(e.x+t.x)/2-n.left,y:(e.y+t.y)/2-n.top}},u=e=>{let t=this.root.getBoundingClientRect();return[e.clientX-t.left,e.clientY-t.top]};this.root.addEventListener(`pointerdown`,u=>{u.pointerType===`touch`&&a.set(u.pointerId,{x:u.clientX,y:u.clientY}),c=l(),s=c?.gap??0,u.button===0&&(o=u.pointerId,e=!0,r=!1,i=u.pointerType===`touch`&&this.cooperative.isEnabled()&&a.size<2,this.root.setPointerCapture(u.pointerId),t=u.clientX,n=u.clientY,!i&&this.dragPan.isEnabled()&&this.root.classList.add(`sm-flat--dragging`))}),this.root.addEventListener(`pointermove`,d=>{let[f,p]=u(d);a.has(d.pointerId)&&a.set(d.pointerId,{x:d.clientX,y:d.clientY});let m=l();if(m){r=!0,c&&this.dragPan.isEnabled()&&this.drag(m.x-c.x,m.y-c.y),s>0&&this.scrollZoom.isEnabled()&&this.zoomBy(m.gap/s,m.x,m.y),s=m.gap,c=m;return}if(!e){this.emit(`pointermove`,this.unproject(f,p),d);return}if(d.pointerId!==o)return;let h=d.clientX-t,g=d.clientY-n;if(t=d.clientX,n=d.clientY,(Math.abs(h)>1||Math.abs(g)>1)&&(r=!0),i){r&&this.cooperative.allowsTouchDrag(a.size);return}this.dragPan.isEnabled()&&this.drag(h,g)});let d=l=>{a.delete(l.pointerId),s=0,c=null;let[d]=[...a.entries()];if(d&&e){o=d[0],t=d[1].x,n=d[1].y,i=this.cooperative.isEnabled()&&a.size<2;return}if(!(!e||l.pointerId!==o)&&(e=!1,this.root.releasePointerCapture?.(l.pointerId),this.root.classList.remove(`sm-flat--dragging`),!r)){let[e,t]=u(l);this.emit(`click`,this.unproject(e,t),l)}};this.root.addEventListener(`pointerup`,d),this.root.addEventListener(`pointercancel`,d),this.root.addEventListener(`wheel`,e=>{if(!this.scrollZoom.isEnabled()||!this.cooperative.allowsWheel(e))return;e.preventDefault();let[t,n]=u(e);this.zoomBy(Math.exp(-e.deltaY/400),t,n)},{passive:!1})}drag(e,t){this.limitsArmed=!0;let n=this.viewport();if(this.projection.azimuthal){let r=n.scale,i=e=>e/r*(180/Math.PI),[a,o]=ZJ((this.projectionOptions.centerLon??0)-i(e),Math.max(-90,Math.min(90,(this.projectionOptions.centerLat??0)+i(t))),this.limits);this.projectionOptions={...this.projectionOptions,centerLon:a,centerLat:o},this.projection=PK(this.projectionId,this.projectionOptions)}else this.view={...this.view,centerX:this.view.centerX-e/n.scale,centerY:this.view.centerY+t/n.scale};this.renderMoving(),this.emit(`viewchange`,this.viewState)}zoomBy(e,t,n){this.limitsArmed=!0;let r=this.viewport().fromScreen(t,n),i=this.ownMaxZoom?Math.max(this.pictureMaxZoom(),this.view.zoom):this.limits.maxZoom??1/0,a=Math.min(i,Math.max(1,this.limits.minZoom??1,this.view.zoom*e));if(a===this.view.zoom)return;this.view={...this.view,zoom:a};let o=this.viewport();if(!this.projection.azimuthal){let e=o.fromScreen(t,n);this.view={...this.view,centerX:this.view.centerX+r[0]-e[0],centerY:this.view.centerY+r[1]-e[1]}}this.loadVisible(),this.renderMoving(),this.emit(`viewchange`,this.viewState)}};function _Y(e){let t=e?.radii;if(t)return(t.a+t.b+t.c)/3;let n=e?.wikidata?.radius;if(n)return n.unit===`kilometre`?n.value:n.unit===`metre`?n.value/1e3:null;let r=e?.sbdb?.diameter;return r?r/2:null}function vY(){return typeof window>`u`?`unsupported`:window.isSecureContext?`DeviceOrientationEvent`in window&&window.matchMedia(`(pointer: coarse)`).matches?`available`:`unsupported`:`insecure`}async function yY(){let e=DeviceOrientationEvent.requestPermission;if(typeof e!=`function`)return!0;try{return await e.call(DeviceOrientationEvent)===`granted`}catch{return!1}}var bY=Math.PI/180,xY=256,SY=128,CY=.05,wY=.25;function TY(e){try{let t=document.createElement(`canvas`);t.width=xY,t.height=SY;let n=t.getContext(`2d`,{willReadFrequently:!0});if(!n)return null;n.drawImage(e,0,0,xY,SY);let{data:r}=n.getImageData(0,0,xY,SY),i=new Uint8Array(xY*SY);for(let e=0;e<i.length;e++)i[e]=+(r[e*4+3]>127);return{width:xY,height:SY,covered:i}}catch{return null}}function EY(e,t,n){let{width:r,height:i,covered:a}=e,o=new Float64Array(r);for(let e=0;e<r;e++)o[e]=(e+.5)*360/r;let s=new Float64Array(i);for(let e=0;e<i;e++)s[e]=90-(e+.5)*180/i;let c=0,l=0,u=0;for(let e=0;e<i;e++){let t=Math.cos(s[e]*bY);for(let n=0;n<r;n++)a[e*r+n]&&(c+=t*Math.sin(o[n]*bY),l+=t*Math.cos(o[n]*bY),u+=t)}if(u===0)return t;let d=Math.hypot(c,l)/u<CY?t.heading:DY(Math.atan2(c,l)/bY-n.northOffsetDeg),f=DY(d+n.northOffsetDeg),p=Math.min(180,n.hfovDeg/2),m=new Float64Array(i),h=0;for(let e=0;e<r;e++)if(!(Math.abs((o[e]-f+540)%360-180)>p))for(let t=0;t<i;t++)a[t*r+e]&&(h=Math.max(h,++m[t]));let g=-1/0,_=1/0;for(let e=0;e<i;e++)m[e]<h*wY||(g=Math.max(g,s[e]),_=Math.min(_,s[e]));if(g<_)return{heading:d,pitch:t.pitch};let v=Math.min(n.vfovDeg/3,(g-_)/2);return{heading:d,pitch:Math.max(_+v,Math.min(g-v,t.pitch))}}function DY(e){return(e%360+360)%360}Math.PI/180;function OY(e){return e.orientation!==`unknown`}function kY(e){return e.id}function AY(e){return`${e.time},${e.lat},${e.lon}`}function jY(e,t){return t?e.find(e=>kY(e)===t||AY(e)===t)??null:null}var MY=1;function NY(e,t,n){let r=e.findIndex(e=>e.id===t.id),i=i=>{for(let a=r+i;a>=0&&a<e.length;a+=i){let r=e[a];if(r.mission!==t.mission)return null;let i=FY(t,r,n);if(i>=MY)return{entry:r,distanceM:i,bearingDeg:IY(t,r)}}return null};return{previous:i(-1),next:i(1)}}var PY=Math.PI/180;function FY(e,t,n){return VK(e,t)*PY*n*1e3}function IY(e,t){let n=e.lat*PY,r=t.lat*PY,i=(t.lon-e.lon)*PY,a=Math.sin(i)*Math.cos(r),o=Math.cos(n)*Math.sin(r)-Math.sin(n)*Math.cos(r)*Math.cos(i);return(Math.atan2(a,o)/PY%360+360)%360}var LY=Math.PI/180,RY=30,zY=110,BY=85,VY=75,HY=-22,UY=9,WY=6,GY=10,KY=1,qY=new Xi(-Math.SQRT1_2,0,0,Math.SQRT1_2),JY=new J(0,0,1);function YY(e){return(e%360+360)%360}function XY(e,[t,n]){let r=YY(n-t),i=YY(e-t);return i<=r?YY(e):i-r<360-i?YY(n):YY(t)}function ZY(e,t,n){return Math.max(t,Math.min(n,e))}function QY(e,t,n=new J){let r=e*LY,i=t*LY;return n.set(Math.sin(r)*Math.cos(i),Math.sin(i),-Math.cos(r)*Math.cos(i))}function $Y(){let e=new Ol;return e.moveTo(0,1),e.lineTo(.85,.05),e.lineTo(.38,.05),e.lineTo(.38,-.9),e.lineTo(-.38,-.9),e.lineTo(-.38,.05),e.lineTo(-.85,.05),e.closePath(),e}var eX=class{bodyId;openAt;openingView;interactive;followArrows;limits={};attribution=null;container=null;root=document.createElement(`div`);renderer=null;controls=null;resizeObserver=null;scene=new to;camera=new bd(VY,1,.1,1e3);sphere;angleCanvas=document.createElement(`canvas`);angleContext=this.angleCanvas.getContext(`2d`);angleGridVisible=!1;arrows=new qa;arrowGeometry=new mu($Y());raycaster=new Zd;loader=new sd;texture=null;loadToken=0;frame=0;disposed=!1;entries=[];radiusKm=0;current=null;neighbours=null;view;pointers=new Map;pinchDistance=0;dragStart=null;hovered=null;gyroEnabled=!1;gyroOrigin=null;gyroEuler=new ka;gyroQuaternion=new Xi;gyroScreen=new Xi;gyroDirection=new J;lookAt=new J;ndc=new J;gridPoint=new J;viewDirection=new J;listeners={ready:new Set,load:new Set,error:new Set,viewchange:new Set,step:new Set,arrows:new Set};constructor(e){this.bodyId=e.body,this.openAt=e.at,this.interactive=e.interactive??!0,this.arrows.visible=e.arrows??!0,this.followArrows=e.followArrows??!0,this.openingView=e.heading!==void 0||e.pitch!==void 0?{heading:e.heading,pitch:e.pitch}:null,this.view={heading:e.heading??0,pitch:e.pitch??0,fov:e.fov??VY},e.limits&&this.setLimits(e.limits),this.root.className=`sm-panorama`,this.root.style.cssText=`position:relative;width:100%;height:100%;overflow:hidden`,this.scene.background=new X(`#0b0d12`),this.sphere=new Us(new gu(500,96,48).scale(-1,1,1),new js({transparent:!0,visible:!1,depthWrite:!1})),this.sphere.renderOrder=-2,this.scene.add(this.sphere,this.arrows)}mount(e){this.container=e,e.append(this.root),this.renderer=new wh({antialias:!0}),this.renderer.setPixelRatio(Math.min(window.devicePixelRatio,2));let t=this.renderer.domElement;t.style.cssText=`display:block;width:100%;height:100%;touch-action:none`,t.tabIndex=0,this.root.append(t),this.angleCanvas.style.cssText=`position:absolute;inset:0;display:block;width:100%;height:100%;pointer-events:none`,this.angleCanvas.setAttribute(`aria-hidden`,`true`),this.angleCanvas.hidden=!0,this.root.append(this.angleCanvas),this.controls=new kq(this,this.root),this.resizeObserver=new ResizeObserver(()=>this.resize()),this.resizeObserver.observe(this.root),this.resize(),this.interactive?(t.addEventListener(`pointerdown`,this.onPointerDown),t.addEventListener(`pointermove`,this.onPointerMove),t.addEventListener(`pointerup`,this.onPointerUp),t.addEventListener(`pointercancel`,this.onPointerCancel),t.addEventListener(`wheel`,this.onWheel,{passive:!1}),t.addEventListener(`keydown`,this.onKeyDown)):(t.addEventListener(`pointermove`,this.onPointerMove),t.addEventListener(`pointerup`,this.onPointerUp))}async load(){let e=await tS(this.bodyId,!1);if(this.disposed)return;this.entries=(e.global?.panoramas??[]).filter(eS),this.radiusKm=_Y(e.global)??0,this.emit(`ready`);let t=this.openAt?this.byKey(this.openAt):this.entries[0]??null;if(!t){let e=Error(this.openAt?`spacemap: no panorama ${this.openAt} on ${this.bodyId}`:`spacemap: no panoramas on ${this.bodyId}`);throw this.emit(`error`,e),e}await this.open(t)}addControl(e,t){return this.controls?.add(e,t),this}removeControl(e){if(e===this.attribution)throw Error(`spacemap: the attribution control cannot be removed`);return this.controls?.remove(e),this}remove(){this.disposed=!0,this.setGyroEnabled(!1),this.loadToken++,cancelAnimationFrame(this.frame),this.frame=0,this.controls?.clear(),this.resizeObserver?.disconnect();let e=this.renderer?.domElement;e&&(e.removeEventListener(`pointerdown`,this.onPointerDown),e.removeEventListener(`pointermove`,this.onPointerMove),e.removeEventListener(`pointerup`,this.onPointerUp),e.removeEventListener(`pointercancel`,this.onPointerCancel),e.removeEventListener(`wheel`,this.onWheel),e.removeEventListener(`keydown`,this.onKeyDown)),this.setArrowTargets([]),this.texture?.dispose(),this.sphere.geometry.dispose(),this.sphere.material.dispose(),this.arrowGeometry.dispose(),this.renderer?.dispose(),this.renderer=null,this.root.remove(),this.container=null}getPanoramas(){return this.entries}getCurrent(){return this.current}getNeighbours(){return this.neighbours}async open(e){let t=typeof e==`string`?this.byKey(e):e;if(!t){let t=Error(`spacemap: no panorama ${String(e)} on ${this.bodyId}`);throw this.emit(`error`,t),t}this.current=t,this.neighbours=this.radiusKm?NY(this.entries,t,this.radiusKm):null;let n=this.openingView;this.openingView=null,n&&this.setView({heading:n.heading,pitch:n.pitch??0}),this.setArrowTargets(this.neighbours&&OY(t)?[`previous`,`next`].map(e=>({key:e,n:this.neighbours?.[e]??null})).filter(e=>e.n).map(e=>({key:e.key,bearingDeg:e.n.bearingDeg})):[]),await this.loadTexture(Qt(`/v1/panoramas/${t.id}.webp`,`panoramas`),t.north_offset_deg,!n),this.current===t&&this.emit(`load`,t)}async step(e){let t=this.neighbours?.[e];t&&await this.open(t.entry)}byKey(e){return this.entries.find(t=>t.id===e)??jY(this.entries,e)}getView(){return{...this.view}}setView(e){let t=e.heading??this.view.heading,n=e.pitch??this.view.pitch,r=e.fov??this.view.fov,{limits:i}=this;this.view={heading:i.heading?XY(t,i.heading):YY(t),pitch:ZY(n,i.pitch?.[0]??-BY,i.pitch?.[1]??BY),fov:ZY(r,i.fov?.[0]??RY,i.fov?.[1]??zY)},this.invalidate(),this.emit(`viewchange`,this.getView())}getLimits(){return structuredClone(this.limits)}setLimits(e){let t=(e,t,n)=>e&&[ZY(e[0],t,n),ZY(e[1],t,n)];this.limits={heading:e.heading&&[YY(e.heading[0]),YY(e.heading[1])],pitch:t(e.pitch,-BY,BY),fov:t(e.fov,RY,zY)},this.setView({})}async setGyroEnabled(e){return e===this.gyroEnabled?this.gyroEnabled:e?vY()!==`available`||!await yY()||this.disposed?!1:(this.gyroOrigin=null,this.gyroEnabled=!0,window.addEventListener(`deviceorientation`,this.onDeviceOrientation),!0):(window.removeEventListener(`deviceorientation`,this.onDeviceOrientation),this.gyroEnabled=!1,!1)}isGyroEnabled(){return this.gyroEnabled}onDeviceOrientation=e=>{if(e.alpha===null||e.beta===null||e.gamma===null)return;this.gyroEuler.set(e.beta*LY,e.alpha*LY,-e.gamma*LY,`YXZ`),this.gyroQuaternion.setFromEuler(this.gyroEuler).multiply(qY).multiply(this.gyroScreen.setFromAxisAngle(JY,-(screen.orientation?.angle??0)*LY)),this.gyroDirection.set(0,0,-1).applyQuaternion(this.gyroQuaternion);let t=Math.atan2(this.gyroDirection.x,-this.gyroDirection.z)/LY,n=Math.asin(ZY(this.gyroDirection.y,-1,1))/LY;this.gyroOrigin===null&&(this.gyroOrigin=YY(t-this.view.heading)),this.setView({heading:t-this.gyroOrigin,pitch:n})};on(e,t){return this.listeners[e].add(t),()=>this.off(e,t)}once(e,t){let n=this.on(e,((...e)=>{n(),t(...e)}));return n}off(e,t){this.listeners[e].delete(t)}emit(e,...t){for(let n of this.listeners[e])n(...t)}faceCoverage(e,t){let n=TY(e);if(!n)return;let r=this.view.fov,i=2*Math.atan(Math.tan(r/2*LY)*this.camera.aspect)/LY;this.setView(EY(n,this.view,{northOffsetDeg:t,hfovDeg:i,vfovDeg:r}))}loadTexture(e,t,n){let r=++this.loadToken;return new Promise((i,a)=>{this.loader.load(e,e=>{if(r!==this.loadToken){e.dispose(),i();return}e.colorSpace=ri,this.renderer&&(e.anisotropy=this.renderer.capabilities.getMaxAnisotropy()),this.texture?.dispose(),this.texture=e,this.sphere.material.map=e,this.sphere.material.visible=!0,this.sphere.material.needsUpdate=!0,this.sphere.rotation.y=Math.PI/2+t*LY,n&&this.faceCoverage(e.image,t),this.invalidate(),i()},void 0,()=>{if(r!==this.loadToken)return i();let t=Error(`spacemap: panorama failed to load: ${e}`);this.emit(`error`,t),a(t)})})}setArrowTargets(e){for(let e of[...this.arrows.children])this.arrows.remove(e),e.traverse(e=>{e instanceof Us&&e.material.dispose()});for(let t of e){let e=new qa;e.name=t.key;let n=new Us(this.arrowGeometry,new js({color:`#000000`,transparent:!0,opacity:.45,side:2,depthWrite:!1}));n.scale.setScalar(1.3);let r=new Us(this.arrowGeometry,new js({color:`#ffffff`,transparent:!0,opacity:.85,side:2,depthWrite:!1}));r.position.y=.02;for(let e of[n,r])e.rotation.x=-Math.PI/2;e.add(n,r),e.position.copy(QY(t.bearingDeg,HY)).multiplyScalar(UY),e.rotation.y=-t.bearingDeg*LY,this.arrows.add(e)}this.invalidate()}invalidate(){this.disposed||this.frame||!this.renderer||(this.frame=requestAnimationFrame(()=>{this.frame=0,this.render()}))}setAngleGridVisible(e){e!==this.angleGridVisible&&(this.angleGridVisible=e,this.angleCanvas.hidden=!e,this.invalidate())}setArrowsVisible(e){e!==this.arrows.visible&&(this.arrows.visible=e,e||(this.hovered=null,this.renderer&&(this.renderer.domElement.style.cursor=``)),this.invalidate())}resize(){let{clientWidth:e,clientHeight:t}=this.root;if(!e||!t||!this.renderer)return;this.renderer.setSize(e,t,!1);let n=Math.min(window.devicePixelRatio,2);this.angleCanvas.width=Math.round(e*n),this.angleCanvas.height=Math.round(t*n),this.angleContext.setTransform(n,0,0,n,0,0),this.camera.aspect=e/t,this.camera.updateProjectionMatrix(),this.invalidate()}render(){if(!this.renderer)return;this.camera.fov=this.view.fov,this.camera.updateProjectionMatrix(),this.camera.lookAt(QY(this.view.heading,this.view.pitch,this.lookAt)),this.renderer.render(this.scene,this.camera);let{clientWidth:e,clientHeight:t}=this.root;if(this.drawAngleGrid(e,t),this.listeners.arrows.size===0)return;let n={};for(let r of this.arrows.visible?this.arrows.children:[])this.ndc.copy(r.position).project(this.camera),n[r.name]={x:(this.ndc.x+1)/2*e,y:(1-this.ndc.y)/2*t,visible:this.ndc.z<1&&Math.abs(this.ndc.x)<.98&&Math.abs(this.ndc.y)<.98};this.emit(`arrows`,n)}drawAngleGrid(e,t){let n=this.angleContext;if(n.clearRect(0,0,e,t),this.angleGridVisible){this.camera.getWorldDirection(this.viewDirection),n.strokeStyle=`rgba(255, 255, 255, 0.24)`,n.lineWidth=1,n.beginPath();for(let r=0;r<360;r+=GY)this.traceAngleLine(n,e,t,r,!0);for(let r=-80;r<=80;r+=GY)this.traceAngleLine(n,e,t,r,!1);n.stroke(),n.font=`12px system-ui, sans-serif`,n.lineWidth=3,n.strokeStyle=`rgba(0, 0, 0, 0.7)`,n.fillStyle=`rgba(255, 255, 255, 0.85)`,n.textAlign=`center`,n.textBaseline=`bottom`;for(let r=0;r<360;r+=GY){if(!this.projectAngle(r,0,e,t,!0))continue;let i=`${r}°`;n.strokeText(i,this.gridPoint.x,this.gridPoint.y-3),n.fillText(i,this.gridPoint.x,this.gridPoint.y-3)}n.textAlign=`left`,n.textBaseline=`middle`;for(let r of[0,90,180,270])for(let i=-80;i<=80;i+=GY){if(i===0||!this.projectAngle(r,i,e,t,!0))continue;let a=`${i>0?`+`:``}${i}°`;n.strokeText(a,this.gridPoint.x+4,this.gridPoint.y),n.fillText(a,this.gridPoint.x+4,this.gridPoint.y)}}}traceAngleLine(e,t,n,r,i){let a=!1,o=0,s=0,c=Math.max(t,n)*2,l=i?-90:0,u=i?90:360;for(let d=l;d<=u;d+=KY){let l=i?r:d,u=i?d:r;if(!this.projectAngle(l,u,t,n)){a=!1;continue}let{x:f,y:p}=this.gridPoint;!a||Math.hypot(f-o,p-s)>c?e.moveTo(f,p):e.lineTo(f,p),a=!0,o=f,s=p}}projectAngle(e,t,n,r,i=!1){return QY(e,t,this.gridPoint),this.gridPoint.dot(this.viewDirection)<=.001||(this.gridPoint.project(this.camera),!Number.isFinite(this.gridPoint.x)||!Number.isFinite(this.gridPoint.y))||i&&(Math.abs(this.gridPoint.x)>=.98||Math.abs(this.gridPoint.y)>=.98)||Math.abs(this.gridPoint.x)>4||Math.abs(this.gridPoint.y)>4?!1:(this.gridPoint.x=(this.gridPoint.x+1)/2*n,this.gridPoint.y=(1-this.gridPoint.y)/2*r,!0)}degreesPerPixel(){return this.view.fov/Math.max(1,this.root.clientHeight)}arrowAt(e,t){if(!this.renderer||!this.arrows.visible||this.arrows.children.length===0)return null;let n=this.renderer.domElement.getBoundingClientRect(),r=new q((e-n.left)/n.width*2-1,-((t-n.top)/n.height)*2+1);this.raycaster.setFromCamera(r,this.camera);let i=this.raycaster.intersectObjects(this.arrows.children,!0)[0];return i?i.object.parent.name:null}pressArrow(e){let t=this.neighbours?.[e];t&&(this.emit(`step`,{key:e,entry:t.entry}),this.followArrows&&this.open(t.entry).catch(()=>{}))}onPointerDown=e=>{try{this.renderer?.domElement.setPointerCapture(e.pointerId)}catch{}this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.dragStart=this.pointers.size===1?{x:e.clientX,y:e.clientY}:null,this.pointers.size===2&&(this.pinchDistance=this.pinchSpan())};onPointerMove=e=>{let t=this.pointers.get(e.pointerId);if(!t){let t=this.arrowAt(e.clientX,e.clientY);t!==this.hovered&&this.renderer&&(this.hovered=t,this.renderer.domElement.style.cursor=t?`pointer`:``);return}let n=e.clientX-t.x,r=e.clientY-t.y;if(this.pointers.set(e.pointerId,{x:e.clientX,y:e.clientY}),this.pointers.size===1){if(this.gyroEnabled)return;let e=this.degreesPerPixel();this.setView({heading:this.view.heading-n*e,pitch:this.view.pitch+r*e})}else if(this.pointers.size===2){let e=this.pinchSpan();this.pinchDistance>0&&this.zoom(this.pinchDistance/e),this.pinchDistance=e}};onPointerUp=e=>{this.pointers.delete(e.pointerId);let t=this.dragStart;if(this.dragStart=null,this.pointers.size>0||!(!this.interactive||t!==null&&Math.hypot(e.clientX-t.x,e.clientY-t.y)<WY))return;let n=this.arrowAt(e.clientX,e.clientY);n&&this.pressArrow(n)};onPointerCancel=e=>{this.pointers.delete(e.pointerId),this.dragStart=null};pinchSpan(){let[e,t]=[...this.pointers.values()];return Math.hypot(e.x-t.x,e.y-t.y)}zoom(e){this.setView({fov:this.view.fov*e})}onWheel=e=>{e.preventDefault(),this.zoom(Math.exp(e.deltaY*.0015))};onKeyDown=e=>{let t=this.view.fov/10,{heading:n,pitch:r}=this.view,i={ArrowLeft:()=>this.setView({heading:n-t}),ArrowRight:()=>this.setView({heading:n+t}),ArrowUp:()=>this.setView({pitch:r+t}),ArrowDown:()=>this.setView({pitch:r-t}),"+":()=>this.zoom(.8),"-":()=>this.zoom(1.25)}[e.key];i&&(e.preventDefault(),i())}},tX=Wx(()=>`${Gt()}/v1/groups/__planetary_systems_map__.json.gz`,{error:e=>`Failed to fetch planetary systems map: ${e.status}`}),nX=Wx(()=>`${Gt()}/v1/groups/__solar_system_map__.json.gz`,{error:e=>`Failed to fetch solar system map: ${e.status}`}),rX=new Map;function iX(e,t,n){return .2126*e+.7152*t+.0722*n}async function aX(e,t){let n=t.strip_rows;if(n.transparency===void 0||n.color===void 0)return console.warn(`Ring strip ${e}/${t.strip} has no transparency or color row, no profile drawn:`,n),null;let r=await fetch(Qt(`/v1/rings/${e}/${t.strip}`,`rings`));if(!r.ok)throw Error(`${r.status} ${r.statusText}`);let i=await createImageBitmap(await r.blob()),a=document.createElement(`canvas`);a.width=i.width,a.height=i.height;let o=a.getContext(`2d`,{willReadFrequently:!0});if(!o)return console.warn(`Ring strip ${e}/${t.strip}: no 2D context, no profile drawn`),null;o.drawImage(i,0,0);let s=i.width,c=o.getImageData(0,0,s,i.height).data;i.close();let l=t.intensity_scale||1,u=new Float32Array(s),d=new Uint8ClampedArray(s*3),f=n.backscattered??n.color,p=new Float32Array(s),m=0;for(let e=0;e<s;e++){let t=(n.transparency*s+e)*4,r=(f*s+e)*4,i=Math.min(1,(1-c[t]/255)*l);u[e]=i>=1?1/0:-Math.log(1-i),p[e]=iX(c[r],c[r+1],c[r+2])/255,p[e]>m&&(m=p[e])}let h=.35;for(let e=0;e<s;e++){let t=(n.color*s+e)*4,r=m>0?h+(1-h)*(p[e]/m):1;d[e*3]=c[t]*r,d[e*3+1]=c[t+1]*r,d[e*3+2]=c[t+2]*r}return{inner:t.inner_radius_km,outer:t.outer_radius_km,tau:u,rgb:d}}async function oX(e){let t=(await tS(e,!1)).global?.rings??[];t.length||console.warn(`Ring strips for ${e}: no ring bundles on the object`);let n=[];for(let r of t)try{let t=await aX(e,r);t&&n.push(t)}catch(t){console.warn(`Ring strip ${e}/${r.strip} unavailable:`,t)}return n}var sX=-Math.log1p(-.02);function cX(e){let t=1/0,n=-1/0;for(let r of e){let e=r.tau.length,i=(r.outer-r.inner)/(e-1);for(let a=0;a<e;a++){if(r.tau[a]<sX)continue;let e=r.inner+a*i;e<t&&(t=e),e>n&&(n=e)}}return n>=t?{inner:t,outer:n}:null}function lX(e){let t=rX.get(e);return t||(t=oX(e).catch(t=>(console.warn(`Ring strips for ${e} unavailable:`,t),rX.delete(e),[])),rX.set(e,t)),t}function uX({onScrub:e,onEnd:t}){let n=null,r=0,i=!1;function a(){i&&t(),n=null,i=!1}return{onpointerdown(e){e.pointerType!==`mouse`&&(n=e.clientX,r=e.clientY,i=!1)},onpointermove(t){t.pointerType===`mouse`||n===null||!i&&Math.hypot(t.clientX-n,t.clientY-r)<8||(i=!0,e(t.clientX,t.clientY))},onpointerup:a,onpointercancel:a,onpointerleave:a}}var dX=2.2,fX=84,pX=40,mX=4,hX=3,gX=1e4,_X=34,vX=7,yX=.42,bX=30;function xX(e,t,n){let r=1/0;for(let i of n)r=Math.min(r,Math.hypot(i.cx-e,i.cy-t));return r}function SX(e){return e>90?180-e:e}function CX(e){let t=Math.log10(e.domain[0]),n=Math.log10(e.domain[1])-t,r=r=>44+(Math.log10(Math.max(r/e.unitKm,1e-9))-t)/n*656,i=[];for(let t of[...e.bodies].sort((e,t)=>e.aKm-t.aKm)){let n=r(t.aKm),a=Math.max(dX,t.radiusKm*e.pxPerKm),o=120;if(t.tiltDeg>0){let r=Math.min(SX(t.tiltDeg)*e.pxPerDeg,fX),a=120-r,s=120+r;o=xX(n,a,i)>=xX(n,s,i)?a:s}i.push({...t,cx:n,cy:o,r:a})}let a=[];for(let t of i){if(!t.satellites?.length)continue;let n=t.rings?t.r*t.rings.outer*yX:0,r=t.cy-Math.max(t.r,n)-mX,i=[];for(let n of[...t.satellites].sort((e,t)=>t.radiusKm-e.radiusKm)){let a=Math.max(dX,n.radiusKm*e.pxPerKm);r-=a,i.push({...n,cx:t.cx,cy:r,r:a,hitY:0,hitHeight:0}),r-=a+hX}let o=Math.min(...i.map(e=>e.cy-e.r))-vX,s=Math.max(...i.map(e=>e.cy+e.r))+vX;i.forEach((e,t)=>{let n=t===0?s:(i[t-1].cy+e.cy)/2,r=t===i.length-1?o:(i[t+1].cy+e.cy)/2;e.hitY=r,e.hitHeight=n-r}),a.push({parent:t,moons:i,x:t.cx-_X/2,y:o,width:_X,height:s-o,perMoon:!t.grouped&&!t.satellitesLink&&i.some(e=>e.link)})}let o=e.bands.map(e=>{let t=r(e.innerKm),n=r(e.outerKm)-t,i=Math.max(n,bX);return{...e,x:t,width:n,hitX:t+(n-i)/2,hitWidth:i}}).sort((e,t)=>t.width-e.width),s=``;e.cloud?.points.forEach((t,n)=>{let i=t.aKm/e.unitKm;if(i<e.domain[0]||i>e.domain[1])return;let a=Math.min(Math.max(SX(t.tiltDeg),0)*e.pxPerDeg,fX),o=120+(n%2==0?-a:a);s+=`M${r(t.aKm).toFixed(1)} ${o.toFixed(1)}h0.01`});let c=e.primary.radiusKm*e.pxPerKm;return{bodies:i,moonZones:a,bands:o,cloudPath:s,primaryR:c,primaryCx:pX-c,xOf:r}}function wX(e,t,n){return t>=e.x&&t<=e.x+e.width&&n>=e.y&&n<=e.y+e.height}function TX(e,t,n,r){for(let i of[!0,!1]){let a=null,o=r;for(let r of e.bodies){if(!!r.link!==i)continue;let e=Math.hypot(t-r.cx,n-r.cy),s=e<=r.r?e-gX:e-r.r;s>o||(a=r,o=s)}if(a)return a}return null}function EX(e,t,n){let r=TX(e,t,n,0);if(r)return{kind:`body`,id:r.id};for(let r of e.moonZones){if(!wX(r,t,n))continue;if(r.parent.grouped)return{kind:`body`,id:r.parent.id};if(!r.perMoon)return{kind:`stack`,id:r.parent.id};let e=r.moons.find(e=>n>=e.hitY&&n<=e.hitY+e.hitHeight);if(e)return{kind:`moon`,parent:r.parent.id,id:e.id}}let i=TX(e,t,n,16);if(i)return{kind:`body`,id:i.id};for(let r=e.bands.length-1;r>=0;r--){let i=e.bands[r];if(t>=i.hitX&&t<=i.hitX+i.hitWidth&&n>=26&&n<=206)return{kind:`band`,key:i.key}}return Math.hypot(t-e.primaryCx,n-120)<=e.primaryR?{kind:`primary`}:null}function DX(e,t,n){if(!n)return null;let{text:r}=e;switch(n.kind){case`primary`:return{cx:Math.max(44,t.primaryCx),cy:120-Math.min(t.primaryR,80),title:e.primary.name,sub:r.primary};case`body`:{let e=t.bodies.find(e=>e.id===n.id);if(!e)return null;let i=[r.distance(e.aKm)];return e.tiltDeg>90&&i.push(r.retrograde),e.grouped&&e.satellites?.length&&i.push(r.moons(e.satelliteCount??e.satellites.length)),{cx:e.cx,cy:e.cy-e.r-4,title:e.name,sub:i.join(` · `)}}case`stack`:{let e=t.moonZones.find(e=>e.parent.id===n.id);if(!e)return null;let i=e.x+e.width/2;return e.parent.satellitesTab?{cx:i,cy:e.y,title:e.parent.name,sub:r.moons(e.parent.satelliteCount??e.moons.length)}:{cx:i,cy:e.y,title:e.moons[0].name,sub:e.parent.name}}case`moon`:{let e=t.moonZones.find(e=>e.parent.id===n.parent),r=e?.moons.find(e=>e.id===n.id);return!e||!r?null:{cx:r.cx,cy:r.cy-r.r-4,title:r.name,sub:e.parent.name}}case`band`:{let e=t.bands.find(e=>e.key===n.key);return e?{cx:e.x+e.width/2,cy:44,title:e.name??e.label,sub:e.sub??`${r.distance(e.innerKm)}–${r.distance(e.outerKm)}`}:null}}}var OX=`http://www.w3.org/2000/svg`,kX=10,AX=-18,jX=1.2,MX=28,NX=6,PX=4,FX=18,IX=12,LX=190;function RX(e,t={},...n){let r=document.createElementNS(OX,e);for(let[e,n]of Object.entries(t))n!==void 0&&r.setAttribute(e,String(n));for(let e of n)e&&r.append(e);return r}function zX(e,t){return JSON.stringify(e)===JSON.stringify(t)}function BX(e,t){let n=new Map,r=(e,t)=>{(t?.href||t?.onclick)&&n.set(JSON.stringify(e),t)};for(let e of t.bands)r({kind:`band`,key:e.key},e);r({kind:`primary`},e.primary.link);for(let e of t.bodies)r({kind:`body`,id:e.id},e.link);for(let e of t.moonZones)if(!e.parent.grouped)if(!e.perMoon)r({kind:`stack`,id:e.parent.id},e.parent.satellitesLink);else for(let t of e.moons)r({kind:`moon`,parent:e.parent.id,id:t.id},t.link);return n}var VX=0,HX=class{root=document.createElement(`div`);svg=RX(`svg`);tip=document.createElement(`div`);tipTitle=document.createElement(`span`);tipSub=document.createElement(`span`);uid=`sm-system-map-${VX++}`;resize=new ResizeObserver(()=>{this.fitLabels(),this.placeTip()});model=null;placed=null;background=!1;hover=null;highlights=new Map;targets=new Map;links=new Map;shape=``;labels=[];constructor(){this.tip.className=`sm-system-map__tip`,this.tipTitle.className=`sm-system-map__tip-title`,this.tipSub.className=`sm-system-map__tip-sub`,this.tip.append(this.tipTitle,this.tipSub),this.tip.hidden=!0,this.root.append(this.svg,this.tip),this.resize.observe(this.root);let e=uX({onScrub:(e,t)=>this.setHover(this.hitAt(e,t)),onEnd:()=>this.setHover(null)});this.svg.addEventListener(`pointerdown`,e.onpointerdown),this.svg.addEventListener(`pointermove`,e.onpointermove),this.svg.addEventListener(`pointerup`,e.onpointerup),this.svg.addEventListener(`pointercancel`,e.onpointercancel),this.svg.addEventListener(`pointerleave`,e.onpointerleave);let t=[0,0],n=e=>{t=[e.clientX,e.clientY]};this.svg.addEventListener(`pointerdown`,n),this.svg.addEventListener(`pointerup`,n),this.svg.addEventListener(`pointermove`,e=>{n(e),e.pointerType===`mouse`&&this.setHover(this.hitAt(e.clientX,e.clientY))}),this.svg.addEventListener(`pointerleave`,e=>{e.pointerType===`mouse`&&this.setHover(null)}),this.svg.addEventListener(`click`,e=>{if(e.detail===0)return;let n=Math.abs(t[0]-e.clientX)<1&&Math.abs(t[1]-e.clientY)<1?this.hitAt(...t):this.hitAt(e.clientX,e.clientY);if(!n)return;let r=this.targets.get(JSON.stringify(n));r?.contains(e.target)||(e.stopPropagation(),e.preventDefault(),r?.dispatchEvent(new MouseEvent(`click`,{bubbles:!0,cancelable:!0,ctrlKey:e.ctrlKey,metaKey:e.metaKey,shiftKey:e.shiftKey,altKey:e.altKey,button:e.button})))},!0)}destroy(){this.resize.disconnect(),this.root.remove()}update(e,t){this.model=e,this.placed=CX(e);let n=BX(e,this.placed),r=JSON.stringify([JSON.stringify(e,(e,t)=>e===`href`?void 0:t),t,[...n].map(([e,t])=>[e,!!t.href,!!t.onclick])]);if(this.links=n,r===this.shape){for(let[e,t]of this.targets){let r=n.get(e)?.href;r&&t.setAttribute(`href`,r)}return}this.shape=r,this.background=t.variant===`background`,this.hover=null,this.root.className=this.background?`sm-system-map sm-system-map--background`:`sm-system-map`,this.draw(e,this.placed,t.ariaLabel),this.fitLabels(),this.placeTip()}draw(e,t,n){let r=this.background;this.highlights=new Map,this.targets=new Map,this.labels=[];let i=this.svg;i.replaceChildren(),i.setAttribute(`viewBox`,r&&e.backgroundView||`0 0 720 240`),i.setAttribute(`preserveAspectRatio`,r?e.backgroundFit===`fit`?`xMidYMid meet`:e.backgroundView?`xMinYMid slice`:`xMidYMid slice`:`xMidYMid meet`),i.setAttribute(`class`,`sm-system-map__svg`),i.setAttribute(`role`,`group`),i.setAttribute(`aria-label`,n),i.setAttribute(`data-vaul-no-drag`,``);let a=(t,n)=>RX(`stop`,{offset:t,"stop-color":e.primary.color,"stop-opacity":n});i.append(RX(`defs`,{},RX(`radialGradient`,{id:`${this.uid}-primary`,gradientUnits:`userSpaceOnUse`,cx:t.primaryCx,cy:120,r:t.primaryR},a(`0%`,1),a(Math.max(0,1-kX/t.primaryR),.85),a(`100%`,.35)),RX(`pattern`,{id:`${this.uid}-band`,width:9,height:9,patternUnits:`userSpaceOnUse`},RX(`circle`,{cx:2,cy:2,r:.9,fill:`currentColor`,opacity:.55}),RX(`circle`,{cx:6.5,cy:6,r:.9,fill:`currentColor`,opacity:.55})))),r||this.drawAxis(e,t),t.cloudPath&&i.append(RX(`path`,{d:t.cloudPath,stroke:e.cloud?.color,"stroke-width":jX*2,"stroke-linecap":`round`,fill:`none`,opacity:.45,"pointer-events":`none`}));for(let e of t.bands){let t=RX(`rect`,{x:e.x,y:26,width:e.width,height:180,fill:`url(#${this.uid}-band)`,class:`sm-system-map__band sm-system-map__band--${e.tone}`});if(r){i.append(t);continue}let n=RX(`text`,{x:e.x+e.width/2,y:232,"text-anchor":`middle`,"font-size":FX,class:`sm-system-map__band-label sm-system-map__band-label--${e.tone}`});n.textContent=e.label,this.labels.push(n),i.append(this.target(e,e.name??e.label,{kind:`band`,key:e.key},t,RX(`rect`,{x:e.hitX,y:26,width:e.hitWidth,height:180,fill:`transparent`}),n))}let o=RX(`circle`,{cx:t.primaryCx,cy:120,r:t.primaryR,fill:`url(#${this.uid}-primary)`});i.append(r?o:this.target(e.primary.link,e.primary.name,{kind:`primary`},o));for(let e of t.bodies){if(!e.rings)continue;let t=e.r*(e.rings.inner+e.rings.outer)/2;i.append(RX(`ellipse`,{cx:e.cx,cy:e.cy,rx:t,ry:t*yX,transform:`rotate(${AX} ${e.cx} ${e.cy})`,fill:`none`,stroke:`#d9c89f`,"stroke-width":e.r*(e.rings.outer-e.rings.inner),opacity:.45}))}let s=new Map(t.moonZones.map(e=>[e.parent.id,e]));for(let e of t.bodies)i.append(this.body(e,s.get(e.id)));for(let e of t.moonZones)e.parent.grouped||this.stack(e)}drawAxis(e,t){for(let n of e.ticks){let r=t.xOf(n*e.unitKm),i=RX(`text`,{x:r,y:16,"text-anchor":`middle`,"font-size":16,fill:`currentColor`,opacity:.85});i.textContent=String(n),this.svg.append(RX(`line`,{x1:r,x2:r,y1:20,y2:212,stroke:`currentColor`,"stroke-width":.5,opacity:.12}),i)}let n=RX(`text`,{x:700,y:16,"text-anchor":`end`,"font-size":14,fill:`currentColor`,opacity:.65});n.textContent=e.axisLabel,this.svg.append(n)}body(e,t){let n=e.reference?RX(`circle`,{cx:e.cx,cy:e.cy,r:e.r+1,fill:`none`,stroke:e.color,"stroke-width":1.2,class:`sm-system-map__reference`}):RX(`circle`,{cx:e.cx,cy:e.cy,r:e.r,fill:e.color});if(this.background)return!t||!e.grouped?n:RX(`g`,{},n,...this.moonDots(t));let r={kind:`body`,id:e.id},i=this.highlight(r,RX(`circle`,{cx:e.cx,cy:e.cy,r:e.r+3.5,fill:`none`,stroke:`currentColor`,"stroke-width":1,opacity:.8})),a=RX(`circle`,{cx:e.cx,cy:e.cy,r:e.r+16,fill:`transparent`});return!t||!e.grouped?this.target(e.link,e.name,r,i,n,a):this.target(e.link,e.name,r,this.highlight(r,this.zoneWash(t)),i,n,a,...this.moonDots(t),this.zoneHit(t))}stack(e){if(this.background){this.svg.append(...this.moonDots(e));return}let t=e.parent;if(e.perMoon){this.svg.append(...this.moonDots(e));for(let n of e.moons){let r={kind:`moon`,parent:t.id,id:n.id};this.svg.append(this.target(n.link,n.name,r,this.highlight(r,RX(`circle`,{cx:n.cx,cy:n.cy,r:n.r+2.5,fill:`none`,stroke:`currentColor`,"stroke-width":1,opacity:.8})),RX(`rect`,{x:e.x,y:n.hitY,width:e.width,height:n.hitHeight,fill:`transparent`})))}return}let n={kind:`stack`,id:t.id},r=e.moons[0];this.svg.append(this.highlight(n,this.zoneWash(e)),...this.moonDots(e),this.target(t.satellitesLink,t.satellitesTab?`${t.name} · ${this.model.text.moons(t.satelliteCount??e.moons.length)}`:r.name,n,this.zoneHit(e)))}moonDots(e){return e.moons.map(e=>RX(`circle`,{cx:e.cx,cy:e.cy,r:e.r,fill:e.color}))}zoneWash(e){return RX(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,rx:4,fill:`currentColor`,opacity:.1,"pointer-events":`none`})}zoneHit(e){return RX(`rect`,{x:e.x,y:e.y,width:e.width,height:e.height,fill:`transparent`})}highlight(e,t){let n=JSON.stringify(e),r=this.highlights.get(n);return r?r.push(t):this.highlights.set(n,[t]),t.style.display=`none`,t}target(e,t,n,...r){let i=!!(e?.href||e?.onclick),a=e?.href?RX(`a`,{href:e.href,"aria-label":t}):i?RX(`g`,{role:`button`,tabindex:0,"aria-label":t,class:`sm-system-map__button`}):RX(`g`);if(a.append(...r),!i)return a;let o=JSON.stringify(n);return this.targets.set(o,a),a.addEventListener(`focus`,()=>this.setHover(n)),a.addEventListener(`blur`,()=>{zX(this.hover,n)&&this.setHover(null)}),a.addEventListener(`click`,e=>this.links.get(o)?.onclick?.(e)),e?.href||a.addEventListener(`keydown`,e=>{let t=e.key;t!==`Enter`&&t!==` `||(e.preventDefault(),a.dispatchEvent(new MouseEvent(`click`,{bubbles:!0})))}),a}setHover(e){if(zX(this.hover,e))return;for(let e of this.highlights.get(JSON.stringify(this.hover))??[])e.style.display=`none`;this.targets.get(JSON.stringify(this.hover))?.removeAttribute(`data-near`),this.hover=e;for(let t of this.highlights.get(JSON.stringify(e))??[])t.style.display=``;let t=this.targets.get(JSON.stringify(e));t?.setAttribute(`data-near`,``),this.svg.classList.toggle(`sm-system-map__svg--near`,!!t),this.placeTip()}hitAt(e,t){if(!this.placed||this.background)return null;let n=this.svg.getBoundingClientRect();if(!n.width||!n.height)return null;let r=(e-n.left)/n.width*720,i=(t-n.top)/n.height*240;return EX(this.placed,r,i)}fitLabels(){for(let e of this.labels){let t=0;e.setAttribute(`font-size`,String(FX));try{t=e.getComputedTextLength()}catch{}if(!t)continue;if(t>LX){let n=Math.max(IX,FX*LX/t);e.setAttribute(`font-size`,String(n)),t*=n/FX}let n=Number(e.dataset.centre??e.getAttribute(`x`));e.dataset.centre=String(n);let r=t/2,i=Math.min(Math.max(n,r+PX),Math.max(r,720-r-PX));e.setAttribute(`x`,String(i))}}placeTip(){let e=this.model&&this.placed&&!this.background?DX(this.model,this.placed,this.hover):null;if(this.tip.hidden=!e,!e)return;this.tipTitle.textContent=e.title,this.tipSub.textContent=e.sub?` · ${e.sub}`:``;let t=this.root.clientWidth,n=t/720;this.tip.style.maxWidth=`${Math.max(0,t-2*NX)}px`;let r=this.tip.offsetWidth/2,i=Math.min(Math.max(e.cx*n,r+NX),Math.max(r,t-r-NX));this.tip.style.left=`${i}px`,this.tip.style.top=`${Math.max(4,e.cy*n-MX)}px`}};function UX(e,t){return{planetId:e.primary.id,planetName:t,planetRadiusKm:e.primary.radius_km,planetColor:U_[e.primary.id]??`#cccccc`,moons:e.moons.map(e=>({id:e.id,name:e.id,aRp:e.a_rp,tiltDeg:e.tilt_deg,radiusKm:e.radius_km,color:U_[e.id]??e.color??`#cccccc`})),rings:e.rings?{innerRp:e.rings.inner_rp,outerRp:e.rings.outer_rp}:null,moonCount:e.moon_count}}function WX(e,t){if(!e.rings||!t.length)return e.rings;let n=cX(t),r=e.planetRadiusKm;return n&&{innerRp:n.inner/r,outerRp:n.outer/r}}var GX=14,KX=1.001,qX=.62,JX=[1,2,3,5,10,20,30,50,100,200,300,500,1e3,2e3,5e3],YX=`0 96 320 144`,XX=`0 96 720 144`,ZX=[1,100];function QX(e,t){let n=Math.min(...e.moons.map(e=>e.aRp)),r=Math.max(...e.moons.map(e=>e.aRp));for(let i of t)n=Math.min(n,i.innerKm/e.planetRadiusKm),r=Math.max(r,i.outerKm/e.planetRadiusKm);return!Number.isFinite(n)||!Number.isFinite(r)?ZX:(r<=n&&(n/=2,r*=2),n=n<=KX?1:n,[n>1?10**(Math.log10(n)-.12):1,10**(Math.log10(r)+.12)])}function $X(e,t){let n=e.planetRadiusKm,r=QX(e,t.bands);return{primary:{id:e.planetId,name:e.planetName,radiusKm:n,color:e.planetColor,link:t.primaryLink},bodies:e.moons.map(e=>({id:e.id,name:e.name,aKm:e.aRp*n,tiltDeg:e.tiltDeg,radiusKm:e.radiusKm,color:e.color,link:t.moonLink?.(e)})),bands:t.bands,cloud:t.cloud,unitKm:n,domain:r,ticks:JX.filter(e=>e>=r[0]&&e<=r[1]),axisLabel:t.axisLabel,pxPerKm:GX/Math.max(...e.moons.map(e=>e.radiusKm).filter(e=>e>0),1),pxPerDeg:qX,text:t.text,backgroundView:t.wide?XX:YX,backgroundFit:t.wide?`fit`:`slice`}}var eZ=224e-6,tZ=1.8,nZ=[.3,50],rZ=[.3,1,3,10,30],iZ=`#ffdd44`;function aZ(e){let t=e.replace(/^\d+\s+/,``);return t===t.toUpperCase()&&/[A-Z]/.test(t)?t.charAt(0)+t.slice(1).toLowerCase():t}function oZ(e){return e.color||U_[e.id]||`#cccccc`}function sZ(e,t){let n=new Map,r=new Map(e.objects.map(e=>[e.id,e]));for(let i of e.objects){if(i.kind!==`moon`||!i.parent)continue;let e=n.get(i.parent)??{satellites:[],count:r.get(i.parent)?.moon_count,tab:!1};e.satellites.push({id:i.id,name:t(i),radiusKm:i.diameter_km/2,color:oZ(i)}),e.tab||=!!i.link_parent,n.set(i.parent,e)}return n}function cZ(e,t){let n=e.objects.find(e=>e.kind===`star`);if(!n)return null;let r=sZ(e,t.name),i=t.stack??(e=>r.get(e.id)),a=e.objects.filter(e=>e.kind!==`moon`&&e.kind!==`star`&&(t.keep?.(e)??!0)).map(e=>{let n=i(e);return{id:e.id,name:t.name(e),aKm:e.a*_g,tiltDeg:e.i,radiusKm:e.diameter_km/2,color:oZ(e),rings:e.rings,satellites:n?.satellites,satelliteCount:n?.count,satellitesTab:n?.tab??!1,...t.links(e,n)}});return{primary:{id:n.id,name:t.name(n),radiusKm:n.diameter_km/2,color:iZ,link:t.primaryLink},bodies:a,bands:e.belts.map(e=>({key:e.slug,innerKm:e.inner_au*_g,outerKm:e.outer_au*_g,tone:e.kind===`kuiper_belt`?`sky`:`muted`,...t.band(e)})),unitKm:_g,domain:nZ,ticks:rZ,axisLabel:t.text.axisAu,pxPerKm:eZ,pxPerDeg:tZ,text:t.text}}function lZ(e){return{id:e.id,name:e.name??e.id,moon:e.moon??!1,aAu:e.aAu??0,tiltDeg:e.tiltDeg??0,radiusKm:e.radiusKm??0,color:e.color??U_[e.id]??`#cccccc`,parent:e.parent}}var uZ=4,dZ=10,fZ={inner:[.6,5.5],outer:[4.5,55]},pZ=[.1,.2,.3,.5,1,2,3,5,10,20,30,50,100,200,500,1e3],mZ=.9,hZ=.76;function gZ(e,t){return Math.log(e/t[0])/Math.log(t[1]/t[0])}var _Z=`naif-599`;function vZ(e,t,n,r=[]){if(!n)return[];let i=new Set([...e.objects.map(e=>e.id),...r]);for(let e of Object.values(t)){i.add(e.primary.id);for(let t of e.moons)i.add(t.id)}return[...n].filter(e=>!i.has(e))}function yZ(e){let t=e.type===`moon`,n=e.orbit?.parent_id,r=n===void 0||n===`naif-10`||n===`naif-0`?e.orbit?.a??e.orbit?.q:void 0;if(r===void 0&&!t)return null;let i=e.radii;return{id:e.id,name:aZ(e.name??e.id),moon:t,aAu:r??0,tiltDeg:e.orbit?.i??0,radiusKm:i?(i.a+i.b+i.c)/3:(e.sbdb?.diameter??0)/2,color:U_[e.id]??e.sbdb?.color??e.color??`#cccccc`,parent:e.orbit?.parent_id}}var bZ=.92;function xZ(e,t){return e<t*bZ?`inner`:`outer`}function SZ(e,t){return Object.values(e).find(e=>e.primary.id===t)}function CZ(e){return e.kind===`zone`?`zone:${e.zone}`:`${e.kind}:${e.id}`}var wZ=class{targets=new Map;constructor(e,t,n){this.data=e,this.options=t,this.pick=n}has(e){return!this.options.bodies||this.options.bodies.has(e)}name(e,t){return this.options.names[e]??(t?aZ(t):e)}named(e,t){return this.options.names[e]??t}link(e){return this.targets.set(CZ(e),e),{onclick:()=>this.pick(e)}}body(e,t){return this.has(e)?this.link({kind:`body`,id:e,name:t}):void 0}stack(e,t){if(t&&!this.options.bodies)return t;let n=(SZ(this.data.systems,e)?.moons??[]).filter(e=>this.has(e.id)).map(e=>({id:e.id,name:this.name(e.id),radiusKm:e.radius_km,color:U_[e.id]??e.color??`#cccccc`}));if(n.length)return n.sort((e,t)=>t.radiusKm-e.radiusKm),{satellites:n.slice(0,uZ),count:n.length,tab:!0}}links(e,t,n){if(!n)return{link:this.body(e,t)};let r=()=>this.link({kind:`system`,id:e,name:t});if(this.options.grouping===`systems`)return{link:r(),grouped:!0};let i=n.satellites[0];return{link:this.body(e,t),satellitesLink:n.tab?r():this.body(i.id,i.name)}}built(e,t){return{model:e,targets:[...this.targets.values()],label:t}}};function TZ(e,t,n,r){let i=new wZ(e,t,r),a=e=>i.name(e.id,e.name),o=sZ(e.solar,a),s=new Map(e.solar.objects.map(e=>[e.id,i.stack(e.id,o.get(e.id))])),c=e.solar.objects.find(e=>e.kind===`star`),l=e=>{let t=e===`inner`?n.zoneInner:n.zoneOuter;return{label:t,sub:``,...i.link({kind:`zone`,zone:e,name:t})}},u=cZ(e.solar,{text:n,name:a,primaryLink:c&&i.body(c.id,a(c)),keep:e=>i.has(e.id)||!!s.get(e.id),stack:e=>s.get(e.id),links:(e,t)=>i.links(e.id,a(e),t),band:e=>t.zones===`belts`?{label:e.label}:l(e.kind===`kuiper_belt`?`outer`:`inner`)});if(!u)throw Error(`spacemap: the Solar System map names no Sun`);return i.built(u,n.solarSystem)}function EZ(e,t,n,r,i,a){let o=SZ(e.systems,t);if(!o)throw Error(`spacemap: no planetary system around ${t}`);let s=new wZ(e,r,a),c=UX(o,s.name(t,n[t]));c.moons=c.moons.filter(e=>s.has(e.id)).map(e=>({...e,name:s.name(e.id,n[e.id])}));let l=c.planetRadiusKm,u=e.ringProfiles?WX(c,e.ringProfiles):c.rings,d=u?[{key:`rings`,label:i.rings,innerKm:u.innerRp*l,outerKm:u.outerRp*l,tone:`amber`}]:[],f=$X(c,{text:i,axisLabel:i.axisRadii,bands:d,primaryLink:s.body(t,c.planetName),moonLink:e=>s.body(e.id,e.name)});return f.ticks=f.ticks.filter(e=>gZ(e,f.domain)<hZ),s.built(f,c.planetName)}function DZ(e,t,n,r,i){let a=new wZ(e,n,i),{solar:o,extras:s}=e,c=o.objects.find(e=>e.kind===`star`),l=o.objects.find(e=>e.id===_Z)?.a;if(!c||l===void 0)throw Error(`spacemap: the Solar System map names no Sun or no Jupiter`);let u=o.objects.filter(e=>e.kind===`dwarf`||e.kind===`asteroid`).map(e=>({id:e.id,name:a.name(e.id,e.name),aAu:e.a,tiltDeg:e.i,radiusKm:e.diameter_km/2,color:oZ(e)}));for(let e of s)e.moon||u.some(t=>t.id===e.id)||e.aAu>0&&u.push({...e,name:a.named(e.id,e.name)});let d=[];for(let e of u){if(xZ(e.aAu,l)!==t)continue;let n={...e,aKm:e.aAu*_g},r=a.stack(e.id);if(r){d.push({...n,satellites:r.satellites,satelliteCount:r.count,satellitesTab:!0,...a.links(e.id,e.name,r)});continue}let i=s.filter(t=>t.moon&&t.parent===e.id&&a.has(t.id)).map(e=>{let t=a.named(e.id,e.name);return{...e,name:t,link:a.body(e.id,t)}});!a.has(e.id)&&!i.length||d.push({...n,link:a.body(e.id,e.name),satellites:i.length?i:void 0})}let[f,p]=fZ[t],m=[Math.min(f,...d.map(e=>e.aKm/_g*.85)),Math.max(p,...d.map(e=>e.aKm/_g*1.15))],h=e=>e>=m[0]&&e<=m[1],g=dZ/Math.max(...d.map(e=>e.radiusKm),1);for(let e of o.objects)e.kind!==`planet`||!h(e.a)||d.push({id:e.id,name:a.name(e.id,e.name),aKm:e.a*_g,tiltDeg:0,radiusKm:0,color:oZ(e),reference:!0});let _=t===`inner`?r.zoneInner:r.zoneOuter;return a.built({primary:{id:c.id,name:a.name(c.id,c.name),radiusKm:c.diameter_km/2*eZ/g,color:iZ},bodies:d,bands:o.belts.filter(e=>h(e.inner_au)&&h(e.outer_au)).map(e=>({key:e.slug,label:e.label,innerKm:e.inner_au*_g,outerKm:e.outer_au*_g,tone:e.kind===`kuiper_belt`?`sky`:`muted`})),unitKm:_g,domain:m,ticks:pZ.filter(e=>h(e)&&gZ(e,m)<mZ),axisLabel:r.axisAu,pxPerKm:g,pxPerDeg:tZ,text:r},_)}var OZ=new WeakMap,kZ=.01;function AZ(){let{messages:e,locale:t}=i(),n=new Intl.NumberFormat(t(),{maximumSignificantDigits:3}),r=new Intl.NumberFormat(t(),{style:`unit`,unit:`kilometer`,maximumSignificantDigits:3}),a=e.unit_symbol_astronomical_unit();return{primary:e.planetary_system_primary(),retrograde:e.planetary_system_retrograde(),moons:t=>e.system_map_moons({count:t}),distance:e=>{let t=e/_g;return t>0&&t<kZ?r.format(e):`${n.format(t)} ${a}`},axisAu:e.system_map_axis_au(),solarSystem:e.system_map_solar_system(),rings:e.tab_rings(),axisRadii:e.planetary_system_axis_unit(),zoneInner:e.system_map_zone_inner(),zoneOuter:e.system_map_zone_outer()}}var jZ=class{chart=new HX;listeners=new Map;view;bodies;names;grouping;zones;rings;places;targets=[];extras=new Map;queue=Promise.resolve();disposed=!1;constructor(e={}){this.view=e.view??{kind:`solar-system`},this.bodies=e.bodies?new Set(e.bodies):null,this.names=e.names??{},this.grouping=e.grouping??`bodies`,this.zones=e.zones??`belts`,this.rings=e.rings??`all`,this.places=(e.places??[]).map(lZ)}mount(e){e.append(this.chart.root)}remove(){this.disposed=!0,this.chart.destroy()}load(){return this.draw()}async setView(e){await this.draw(e)}getView(){return this.view}setBodies(e){let t=e?new Set(e):null;return this.draw(void 0,t).catch(()=>{})}getTargets(){return[...this.targets]}draw(e,t){let n=this.queue.then(()=>(t!==void 0&&(this.bodies=t),this.drawNow(e??this.view)));return this.queue=n.catch(()=>{}),n}async drawNow(e){let t;try{t=await this.build(e)}catch(e){let t=e instanceof Error?e:Error(String(e));throw this.disposed||this.emit(`error`,t),t}if(this.disposed)return;let n=JSON.stringify(e)!==JSON.stringify(this.view);this.view=e,this.targets=t.targets,this.chart.update(t.model,{ariaLabel:t.label}),n&&this.emit(`viewchange`,e)}async build(e){let[t,n]=await Promise.all([nX(),tX()]),r={bodies:this.bodies,names:this.names,grouping:this.grouping,zones:this.zones},i=AZ(),a=e=>this.emit(`select`,e),o={solar:t,systems:n,extras:[]};switch(e.kind){case`solar-system`:return TZ(o,r,i,a);case`system`:{let t=this.rings===`visible`&&!!SZ(n,e.id)?.rings,[s,c]=await Promise.all([this.exportedNames(e.id,n),t?lX(e.id):void 0]);return EZ({...o,ringProfiles:c},e.id,s,r,i,a)}case`zone`:{let s=vZ(t,n,this.bodies,this.places.map(e=>e.id)),c=(await Promise.all(s.map(e=>this.extra(e)))).filter(e=>e!==null),l=[...this.places,...c],u=vZ(t,n,new Set(l.flatMap(e=>e.moon&&e.parent?[e.parent]:[])),l.map(e=>e.id)),d=await Promise.all(u.map(e=>this.extra(e))),f=[...l,...d.filter(e=>e!==null)];return DZ({...o,extras:f},e.zone,r,i,a)}}}extra(e){let t=this.extras.get(e);return t||(t=tS(e,!1).then(t=>{if(!t.global)throw Error(`spacemap: no such body as ${e}`);return yZ(t.global)}).catch(t=>(this.extras.delete(e),this.emit(`error`,t instanceof Error?t:Error(String(t))),null)),this.extras.set(e,t)),t}async exportedNames(e,t){if(![e,...(SZ(t,e)?.moons??[]).map(e=>e.id)].some(t=>!(t in this.names)&&(t===e||!this.bodies||this.bodies.has(t))))return{};try{let{global:t,localized:n}=await tS(e,!0,i().locale()),r={};for(let e of t?.notable_moons??[])e.id&&(r[e.id]=e.name);Object.assign(r,n?.notable_moon_names);let a=n?.name??t?.name;return a&&(r[e]=a),r}catch{return{}}}on(e,t){let n=this.listeners.get(e);return n||(n=new Set,this.listeners.set(e,n)),n.add(t),()=>n.delete(t)}once(e,t){let n=((...e)=>{r(),t(...e)});OZ.set(n,t);let r=this.on(e,n);return r}off(e,t){let n=this.listeners.get(e);if(n){n.delete(t);for(let e of n)OZ.get(e)===t&&n.delete(e)}}emit(e,...t){let n=this.listeners.get(e);if(n)for(let e of[...n])e(...t)}};function MZ(e,t){let n=e.credits.orbitSourceParents.get(t);if(!n)return!0;let r=e.visibility.focusedSystemId;for(let t of n)if(e.bodies.isInSystem(t,r))return!0;return!1}function NZ(e){let t=e.credits,n=new Set;for(let r of Tn){if(!t.orbitSources.has(r))continue;let{archive:i,scoped:a}=wn[r];if(!(a&&!MZ(e,r)))if(i)n.add(i);else for(let e of cn)e&&t.probeArchives.has(e)&&n.add(e)}return[...n]}function PZ(e,t){let n=e.visibility.focusedSystemId,r=e.visibility.focusedBodyId;return[...t].filter(e=>e.bodyId===r||n&&e.systemId===n)}function FZ(e,t=En){let n=e.credits;n.imageryVersion,n.modelVersion;let r=[...new Set(NZ(e).map(e=>t[e]))],i=new Set;for(let t of PZ(e,n.imagery.values()))i.add(t.organisation);let a=e.visibility.focusedBodyId,o=a?n.model.get(a):void 0;return o&&i.add(o.organisation),{orbits:r,imagery:[...i].sort()}}var IZ=`https://spacemap.co`,LZ=`https://spacemap.co/credits`;function RZ(){let e=document.createElement(`div`);return e.className=`sm-attribution`,e}function zZ(){let e=document.createElement(`span`);return e.className=`sm-attribution__group`,e}function BZ(e,t,n){let r=document.createElement(`a`);return r.href=e,r.target=`_blank`,r.rel=`noopener noreferrer`,r.textContent=t,n&&(r.className=n),r}var VZ=class{stop=null;onAdd(e){let t=RZ(),n=zZ(),r=zZ();return t.append(BZ(IZ,`spacemap`,`sm-attribution__home`),n,r,BZ(LZ,i().messages.credits_see_all())),this.stop=st(()=>{at(()=>{let t=FZ(e.ctx);HZ(n,i().messages.attribution_orbits(),t.orbits),HZ(r,i().messages.attribution_imagery(),t.imagery)})}),t}onRemove(){this.stop?.(),this.stop=null}getDefaultPosition(){return`bottom-right`}};function HZ(e,t,n){if(e.hidden=n.length===0,e.hidden)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${t}:`,e.replaceChildren(r,` ${n.join(` · `)}`)}var UZ=class{off=null;onAdd(e){let t=RZ(),n=zZ();t.append(BZ(IZ,`spacemap`,`sm-attribution__home`),n,BZ(LZ,i().messages.credits_see_all()));let r=()=>{let t=[...new Set(e.credits.map(e=>e.organisation))].filter(Boolean);if(n.hidden=t.length===0,n.hidden)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${i().messages.attribution_imagery()}:`,n.replaceChildren(r,` ${t.join(` · `)}`)};return r(),this.off=e.on(`layerschange`,r),t}onRemove(){this.off?.(),this.off=null}getDefaultPosition(){return`bottom-right`}};function WZ(e){if(e)try{let t=typeof window<`u`?window.location.href:`https://spacemap.co`,{protocol:n}=new URL(e,t);return n===`http:`||n===`https:`?e:void 0}catch{return}}var GZ=class{off=null;onAdd(e){let t=RZ(),n=zZ();t.append(BZ(IZ,`spacemap`,`sm-attribution__home`),n,BZ(LZ,i().messages.credits_see_all()));let r=()=>{let t=e.getCurrent();if(n.hidden=!t?.credit,!t?.credit)return;let r=document.createElement(`span`);r.className=`sm-attribution__label`,r.textContent=`${i().messages.attribution_imagery()}:`;let a=WZ(t.credit_url),o=a?BZ(a,t.credit):t.credit;n.replaceChildren(r,` `,o)};return r(),this.off=e.on(`load`,r),t}onRemove(){this.off?.(),this.off=null}getDefaultPosition(){return`bottom-right`}};function KZ(e){return e}function qZ(e){let t=[...e.samples].sort((e,t)=>e.jd-t.jd);return{body:e.body??`naif-10`,offsetKm:e=>XZ(t,e)}}function JZ(e){return{body:e.body??`naif-10`,offsetKm:t=>_B(e.elements,t)?.r??null}}function YZ(e,t){let n=hg(e,t);return n.error!==fg.None&&console.warn(`spacemap: SGP4 will not take this element set (error=${n.error})`),{body:ev,offsetKm:e=>{if(n.error!==fg.None)return null;let t=i_(n,e);return t&&e_(t[0],t[1],t[2],e)}}}function XZ(e,t){let n=e.length;if(n<2||t<e[0].jd||t>e[n-1].jd)return null;let r=0,i=n-1;for(;r<i;){let n=r+i>>1;e[n].jd<t?r=n+1:i=n}let a=Math.max(r,1),o=e[a-1],s=e[a],c=s.jd-o.jd;if(c<=0)return s.km;let l=(t-o.jd)/c,u=l*l,d=u*l,f=2*d-3*u+1,p=d-2*u+l,m=-2*d+3*u,h=d-u,g=[0,0,0];for(let t=0;t<3;t++){let n=o.km[t],r=s.km[t],i=ZZ(e,a-1,t),l=ZZ(e,a,t);g[t]=f*n+p*c*i+m*r+h*c*l}return g}function ZZ(e,t,n){let r=e[t-1]??e[t],i=e[t+1]??e[t],a=i.jd-r.jd;return a<=0?0:(i.km[n]-r.km[n])/a}function QZ(e){return e/_g}var $Z=null,eQ=Promise.resolve();function tQ(e){let t=eQ.then(e,e);return eQ=t.catch(()=>{}),t}async function nQ(e){let t=Ag(e),n=await gx();if(!$Z){let e=_x(n);e.size>0&&($Z=new Ax(e))}return await $Z?.load(t),{jd:t,metadata:n,chebyshev:$Z}}function rQ(e,t){return!(e!==void 0&&t-2451545<e)}async function iQ(e,{jd:t,metadata:n}){let r=n.position.zones.moons,i=r&&sx(r);if(!i)return null;let a=await Bb(`moons`,null,0,tx(i)?String(rx(i,t)):null);for(let t=0;t<a.rowCount;t++)if(Fh(a,t)===e)return V_(a,t,new Map,`naif`);return null}function aQ(e,t){return!rQ(e.visibleFromDays,t)||!TV(e,t)?null:e.satrec?o_(e.satrec,t):e.q==null?e.a===0?[0,0,0]:S_(e,t):C_(e,t)}async function oQ(e,t){let{jd:n}=t;if(t.chebyshev?.has(e)){let r=t.chebyshev.body(e,n);if(r&&!rQ(r.visibleFromDays,n))return null;let i=r&&Wy(r,n);if(i){let{radiusKm:e,objectType:t}=r;return{data:{radiusKm:e,objectType:t,orbitalSource:W.SPICE},parentId:`naif-${r.parentId}`,offset:i}}if(e.startsWith(`naif-`))return null}let r=(e.startsWith(`naif-`)?await iQ(e,t):null)??pS(e,await tS(e,!1)),i=r&&aQ(r,n);return i?{data:r,parentId:r.parentId,offset:i}:null}async function sQ(e,t,n=new Set){if(n.has(e))return null;let r=await oQ(e,t);if(!r)return null;if(r.parentId===`naif-0`)return{data:r.data,centre:r.offset,parents:[]};let i=await sQ(r.parentId,t,new Set(n).add(e));if(!i)return null;let[a,o,s]=i.centre;return{data:r.data,centre:[a+r.offset[0],o+r.offset[1],s+r.offset[2]],parents:[r.parentId,...i.parents]}}function cQ(e,{parents:t},n){let r=new Set(t);for(let{body:e}of n.chebyshev?.bodiesAt(n.jd)??[])t.includes(`naif-${e.parentId}`)&&r.add(e.id);return r.delete(e),[...r]}async function lQ(e){let[t]=await Promise.all([tS(e,!1),Lv()]);return{orientation:t.global?.orientation,nutPrec:Rv(e,t.global?.nut_prec)}}async function uQ(e,t){let n=await sQ(e.body,t);if(!n)return null;let r=`latitude`in e?await lQ(e.body):{};return sW(e,{data:n.data,...r},n.centre,t.jd)}function dQ(e,t,n){return tQ(async()=>{let r=await nQ(n),i=await uQ(e,r),a=i&&await uQ(t,r);return i&&a?uW([a[0]-i[0],a[1]-i[1],a[2]-i[2]]):null})}async function fQ(e,t,n){let r=await dQ(e,t,n);return r&&Math.hypot(...r)}function pQ(e,t){return tQ(async()=>{if(e===`naif-10`)return null;let n=await nQ(t),r=await sQ(e,n),i=r&&await sQ(`naif-10`,n);return!r||!i?null:hq({data:r.data,...await lQ(e)},r.centre,i.centre,n.jd)})}function mQ(e,t){return tQ(async()=>{if(e===`naif-10`)return null;let n=await nQ(t),r=await sQ(e,n),i=r&&await sQ(`naif-10`,n);if(!r||!i)return null;let a=({data:e,centre:t})=>({centre:uW([t[0]-r.centre[0],t[1]-r.centre[1],t[2]-r.centre[2]]),radiusKm:e.radiusKm}),o=[];for(let t of cQ(e,r,n)){let e=await sQ(t,n);e&&e.data.radiusKm>0&&o.push(a(e))}return yq(r.data.radiusKm>0?r.data.radiusKm:0,a(i),o)})}var hQ=null;function gQ(e=Nv){return hQ||(hQ=(async()=>{let t=await e(`${Gt()}/v1/panoramas.json`);if(!t.ok)throw Error(`Failed to load panoramas.json: ${t.status}`);return(await t.json()).bodies??[]})(),hQ.catch(()=>hQ=null),hQ)}async function _Q(e){return(await tS(e,!1)).global?.panoramas??[]}async function vQ(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,controls:l,events:u,...d}=e,f=SQ(t);CQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let p=new Lq(d);if(p.mount(f),p.webglError)throw p.unmount(),Error(`spacemap: WebGL is not available`);for(let[e,t]of Object.entries(u??{}))p.on(e,t);p.attribution=new VZ,p.addControl(p.attribution);for(let e of l??[])p.addControl(e);return await p.open(),p.applyInitialView(),await gG(),p}async function yQ(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,controls:l,events:u,...d}=e,f=SQ(t);CQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let p=new gY(d);p.mount(f);for(let[e,t]of Object.entries(u??{}))p.on(e,t);p.attribution=new UZ,p.addControl(p.attribution);for(let e of l??[])p.addControl(e);return await p.load(),p}async function bQ(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,controls:l,events:u,...d}=e,f=SQ(t);CQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let p=new eX(d);p.mount(f);for(let[e,t]of Object.entries(u??{}))p.on(e,t);p.attribution=new GZ,p.addControl(p.attribution);for(let e of l??[])p.addControl(e);return await p.load(),p}async function xQ(e){let{container:t,dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c,events:l,...u}=e,d=SQ(t);CQ({dataUrl:n,imagesUrl:r,liveUrl:i,tilesUrl:a,locale:o,messages:s,includeNonCommercial:c});let f=new jZ(u);f.mount(d);for(let[e,t]of Object.entries(l??{}))f.on(e,t);try{await f.load()}catch(e){throw f.remove(),e}return f}function SQ(e){if(typeof e!=`string`)return e;let t=document.querySelector(e);if(!(t instanceof HTMLElement))throw Error(`spacemap: no element matches ${e}`);return t}function CQ(e){let t={};e.dataUrl!==void 0&&(t.dataUrl=e.dataUrl),e.imagesUrl!==void 0&&(t.imagesUrl=e.imagesUrl),e.liveUrl!==void 0&&(t.liveUrl=e.liveUrl),e.tilesUrl!==void 0&&(t.tilesUrl=e.tilesUrl),e.locale!==void 0&&(t.locale=()=>e.locale),e.messages!==void 0&&(t.messages=e.messages),e.includeNonCommercial&&(t.textures=`non-commercial`),r(t)}export{VZ as AttributionControl,UZ as FlatAttributionControl,gY as FlatMap,bq as GestureHandler,ny as MAP_LAYERS,NK as PROJECTION_IDS,GZ as PanoramaAttributionControl,eX as PanoramaView,Lq as SpaceMap,jZ as SystemMap,QJ as Viewport,IY as bearingDeg,tq as boxRing,FG as circlePoints,r as configureHost,yQ as createFlatMap,vQ as createMap,bQ as createPanorama,PK as createProjection,xQ as createSystemMap,Ag as dateToJD,ZC as defaultSceneSettings,fQ as distanceKm,JZ as elements,gQ as fetchPanoramaIndex,_Q as fetchPanoramas,jY as findPanorama,KZ as fixed,iq as graticule,FY as groundDistanceM,eS as isViewable,jg as jdToDate,QZ as kmToAu,NY as neighboursOf,dQ as offsetKm,kY as panoramaAt,ZK as pathFor,NG as planeBasis,$G as projectionAspect,qZ as samples,nq as smallCircle,pQ as subsolarPoint,mQ as sunlight,YZ as tle};
|
|
6384
6384
|
//# sourceMappingURL=spacemap.js.map
|
|
6385
6385
|
(function(){if(typeof document==='undefined')return;var s=document.createElement('style');s.textContent=".scene-label{pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;color:inherit;touch-action:none;z-index:1;width:32px;height:32px;text-decoration:none;display:block;position:relative;left:0}.scene-label__halo{border-radius:50%;width:100%;height:100%;transition:transform .1s}.scene-label__halo--spacecraft,.scene-label__halo--debris{overflow:visible}.scene-label__loader{box-sizing:border-box;pointer-events:none;border:2px solid #fff;border-color:#fff #fff #fff3 #fff3;border-radius:50%;width:32px;height:32px;margin:auto;animation:.9s linear infinite scene-label-loader-spin;position:fixed;inset:0}@keyframes scene-label-loader-spin{to{transform:rotate(360deg)}}.reduce-motion .scene-label__loader{animation-duration:.9s!important;animation-iteration-count:infinite!important}.scene-label__name{white-space:nowrap;pointer-events:auto;cursor:pointer;color:#fff;text-shadow:0 0 4px #000,0 0 4px #000;padding-left:8px;font-size:14px;font-weight:700;text-decoration:none;position:absolute;top:50%;left:32px;transform:translateY(-50%)}.scene-label__name--large{font-size:16px}.scene-label__annotations{top:28px;pointer-events:none;flex-direction:column;padding-inline-start:8px;display:flex;position:absolute;inset-inline-start:32px}.scene-label__annotation{opacity:0;white-space:nowrap;color:#fff9;text-shadow:0 0 3px #000,0 0 3px #000;transition:opacity .15s, display .15s allow-discrete;font-size:11px;line-height:1.3;display:none}.scene-label__annotation--visible{opacity:1;display:block}@starting-style{.scene-label__annotation--visible{opacity:0}}.scene-feature-label{color:#ffffffb3;white-space:nowrap;pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;text-shadow:0 0 2px #000,0 0 2px #000;z-index:0;font-size:12px;transition:color .1s;left:0}.scene-feature-label:hover{color:#fff;text-shadow:0 0 3px #000,0 0 3px #000}.scene-feature-label--active{color:#fff;font-size:14px;font-weight:600}.scene-path-label{color:#fff;font:inherit;white-space:nowrap;text-align:start;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:auto;cursor:pointer;-webkit-user-select:none;user-select:none;touch-action:none;z-index:2;background:0 0;border:0;align-items:center;gap:8px;padding:0;line-height:1.15;display:flex;left:0}.scene-path-label--static{pointer-events:none;cursor:default}.scene-path-label__halo{border-radius:50%;flex-shrink:0;width:32px;height:32px;margin-inline-start:-16px;transition:transform .1s}.scene-path-label:hover .scene-path-label__halo{transform:scale(1.15)}.scene-path-label__text{flex-direction:column;gap:1px;display:flex}.scene-path-label__name{font-size:14px;font-weight:700}.scene-path-label__when{opacity:.8;font-variant-numeric:tabular-nums;font-size:12px}.scene-path-label--dim .scene-path-label__text{display:none}.scene-path-label--dim .scene-path-label__halo{transform:scale(.55)}.scene-path-label--dim:hover .scene-path-label__halo{transform:scale(.75)}.scene-path-label--step .scene-path-label__halo{background:0 0;border:0}.scene-path-label--step:hover .scene-path-label__halo{background:#ffffff1f}.scene-path-label--step .scene-path-label__name{font-size:12px;font-weight:600}.scene-path-label--step .scene-path-label__when{font-size:11px}.scene-path-label__hazard{font-size:11px;font-weight:700}.scene-path-label--lit{color:#fff}.scene-path-label--lit .scene-path-label__halo{transform:scale(1.15)}.scene-path-label--lit.scene-path-label--dim .scene-path-label__halo{transform:scale(.75)}.scene-path-label--faint .scene-path-label__text{display:none}.scene-path-label--faint .scene-path-label__halo{opacity:.45;transform:scale(.5)}.scene-path-label--faint:hover .scene-path-label__halo{opacity:1;transform:scale(.75)}.scene-overlay--no-names .scene-label__name,.scene-overlay--no-names .scene-label__annotations{display:none}.scene-overlay--no-halos .scene-label__halo{visibility:hidden}.scene-overlay--no-halos .scene-label{pointer-events:none}.scene-hazard-label{white-space:nowrap;pointer-events:none;-webkit-user-select:none;user-select:none;text-shadow:0 0 4px #000,0 0 4px #000;margin-inline-start:16px;font-size:12px;font-weight:700;position:relative;left:0}.user-location-marker{pointer-events:none;background:#1a73e8;border:2px solid #fff;border-radius:50%;width:16px;height:16px;box-shadow:0 0 6px #0006}.sm-drawing-label{white-space:nowrap;color:#fff;text-shadow:0 0 4px #000,0 0 4px #000;-webkit-user-select:none;user-select:none;pointer-events:none;font:700 14px/1.2 system-ui,sans-serif}.sm-drawing-icon{-webkit-user-select:none;user-select:none;pointer-events:none;display:block}.sm-drawing--interactive{pointer-events:auto;cursor:pointer;touch-action:none}.sm-cooperative-hint{z-index:4;color:#fff;text-align:center;pointer-events:none;opacity:0;background:#0000008c;place-content:center;padding:16px;font:15px/1.4 system-ui,sans-serif;transition:opacity .2s;display:grid;position:absolute;inset:0}.sm-cooperative-hint--shown{opacity:1}@media (prefers-reduced-motion:reduce){.sm-cooperative-hint{transition:none}}.sm-ctrl{z-index:2;box-sizing:border-box;pointer-events:none;flex-direction:column;gap:6px;max-width:100%;padding:6px;display:flex;position:absolute}.sm-ctrl>*{pointer-events:auto}.sm-ctrl--top-left{align-items:flex-start;top:0;left:0}.sm-ctrl--top-right{align-items:flex-end;top:0;right:0}.sm-ctrl--bottom-left{align-items:flex-start;bottom:0;left:0}.sm-ctrl--bottom-right{align-items:flex-end;bottom:0;right:0}.sm-map{-webkit-user-select:none;user-select:none}:where(.sm-map){width:100%;height:100%;position:relative}.sm-map__canvas{pointer-events:auto;touch-action:none;width:100%;height:100%;display:block}.sm-map__canvas:focus-visible{outline:2px solid var(--ring,Highlight)}.sm-map .scene-overlay{pointer-events:none;z-index:0;position:absolute;inset:0}.sm-flat{touch-action:none;background:#05070e;width:100%;height:100%;position:relative;overflow:hidden}.sm-flat__raster,.sm-flat__vector,.sm-flat__markers{width:100%;height:100%;position:absolute;inset:0}.sm-flat__raster{display:block}.sm-flat__vector,.sm-flat__markers{pointer-events:none}.sm-flat--interactive{cursor:grab}.sm-flat--cooperative{touch-action:pan-x pan-y}.sm-flat--dragging{cursor:grabbing}.sm-flat__graticule{fill:none;stroke:#ffffff47;stroke-width:1px}.sm-flat__frame{fill:none;stroke:#ffffff73;stroke-width:1px}.sm-flat__feature-dot{fill:#fffc}.sm-flat__feature-label{fill:#ffffffd9;paint-order:stroke;stroke:#000000a6;stroke-width:2.5px;font:10px/1 system-ui,sans-serif}.sm-flat__marker-dot{background:#4ea3ff;border:2px solid #fff;border-radius:50%;width:10px;height:10px;box-shadow:0 0 0 1px #00000073}.sm-system-map{border-radius:var(--sm-system-map-radius,6px);background:var(--sm-system-map-background,#ffffff0d);width:100%;color:var(--sm-system-map-ink,#ffffff9e);position:relative;overflow:hidden}.sm-system-map--background{pointer-events:none;background:0 0;border-radius:0;height:100%}.sm-system-map__svg{touch-action:pan-y;width:100%;height:auto;display:block}.sm-system-map--background .sm-system-map__svg{height:100%}.sm-system-map__svg--near :is(a,.sm-system-map__button):not([data-near]){pointer-events:none}.sm-system-map__button{cursor:pointer}.sm-system-map__button:focus{outline:none}.sm-system-map__reference{opacity:.6}.sm-system-map__band--muted{color:var(--sm-system-map-ink,#ffffff9e)}.sm-system-map__band--sky{color:var(--sm-system-map-sky,oklch(74.6% .16 232.661/.7))}.sm-system-map__band--amber{color:var(--sm-system-map-amber,oklch(92.4% .12 95.746/.8))}.sm-system-map__band-label{font-weight:600}.sm-system-map__band-label--muted{fill:var(--sm-system-map-ink,#ffffff9e)}.sm-system-map__band-label--sky{fill:var(--sm-system-map-sky-label,oklch(74.6% .16 232.661))}.sm-system-map__band-label--amber{fill:var(--sm-system-map-amber-label,oklch(92.4% .12 95.746/.9))}.sm-system-map__tip{z-index:10;background:var(--sm-system-map-tip-background,#0a0c14e6);width:max-content;color:var(--sm-system-map-tip-ink,#fffffff2);white-space:nowrap;pointer-events:none;-webkit-backdrop-filter:blur(8px);backdrop-filter:blur(8px);border-radius:.25rem;padding:.25rem .5rem;font-size:.75rem;line-height:1.33333;position:absolute;transform:translate(-50%);box-shadow:0 1px 3px #0000001a,0 1px 2px -1px #0000001a}.sm-system-map__tip[hidden]{display:none}.sm-system-map__tip-title{font-weight:500}.sm-system-map__tip-sub{color:var(--sm-system-map-ink,#ffffff9e)}.sm-ctrl:has(>.sm-attribution:only-child){padding:0}.sm-ctrl--top-left:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 0 var(--sm-attribution-radius) 0}.sm-ctrl--top-right:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 0 0 var(--sm-attribution-radius)}.sm-ctrl--bottom-left:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:0 var(--sm-attribution-radius) 0 0}.sm-ctrl--bottom-right:has(>.sm-attribution:only-child)>.sm-attribution{border-radius:var(--sm-attribution-radius) 0 0 0}.sm-attribution{--sm-attribution-radius:3px;box-sizing:border-box;border-radius:var(--sm-attribution-radius);color:#ffffffbf;white-space:nowrap;background:#0006;align-items:center;gap:.5em;max-width:100%;padding:1px 6px;font:11px/1.45 system-ui,sans-serif;display:flex}.sm-attribution a{color:inherit;text-decoration:none}.sm-attribution a:hover{color:#fff;text-decoration:underline}.sm-attribution__home{font-weight:600}.sm-attribution__group{text-overflow:ellipsis;overflow:hidden}.sm-attribution__label{color:#ffffff80}\n/*$vite$:1*/";document.head.appendChild(s);})();
|