astraeus 0.7.0 → 0.8.1
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/CHANGELOG.md +189 -0
- package/README.md +202 -38
- package/data/ephemerides/planets/planets.json +1 -1
- package/package.json +5 -4
- package/src/api/AstraeusScene.d.ts +21 -5
- package/src/api/AstraeusScene.js +34 -10
- package/src/api/AstraeusScene.node.js +34 -10
- package/src/api/assembleScene.d.ts +36 -0
- package/src/api/assembleScene.js +175 -0
- package/src/api/bodySetChecks.d.ts +10 -0
- package/src/api/bodySetChecks.js +117 -0
- package/src/api/bodySetInput.d.ts +81 -0
- package/src/api/bodySetInput.js +1 -0
- package/src/api/containingBlock.d.ts +6 -0
- package/src/api/containingBlock.js +16 -0
- package/src/api/data.d.ts +17 -5
- package/src/api/data.js +28 -10
- package/src/api/definitionOf.d.ts +16 -0
- package/src/api/definitionOf.js +20 -0
- package/src/api/errors.d.ts +63 -1
- package/src/api/frozenCopy.d.ts +6 -0
- package/src/api/frozenCopy.js +26 -0
- package/src/api/group.d.ts +8 -2
- package/src/api/group.js +24 -5
- package/src/api/index.d.ts +18 -7
- package/src/api/index.js +2 -2
- package/src/api/index.node.js +2 -2
- package/src/api/listeners.d.ts +5 -0
- package/src/api/listeners.js +25 -0
- package/src/api/look.d.ts +47 -0
- package/src/api/look.js +1 -0
- package/src/api/lookInput.d.ts +3 -0
- package/src/api/lookInput.js +41 -0
- package/src/api/moonPanelInput.d.ts +60 -0
- package/src/api/moonPanelInput.js +1 -0
- package/src/api/mount.d.ts +9 -19
- package/src/api/mount.js +27 -13
- package/src/api/mount.node.js +27 -13
- package/src/api/pathProvenance.js +1 -1
- package/src/api/pickerInput.d.ts +25 -0
- package/src/api/pickerInput.js +1 -0
- package/src/api/planBodies.d.ts +72 -0
- package/src/api/planBodies.js +300 -0
- package/src/api/planBodySets.d.ts +68 -0
- package/src/api/planBodySets.js +234 -0
- package/src/api/planCamera.d.ts +83 -0
- package/src/api/planCamera.js +184 -0
- package/src/api/planGroups.d.ts +36 -0
- package/src/api/planGroups.js +103 -0
- package/src/api/planMoonPanel.d.ts +19 -0
- package/src/api/planMoonPanel.js +104 -0
- package/src/api/planPaths.d.ts +40 -0
- package/src/api/planPaths.js +212 -0
- package/src/api/planPicker.d.ts +12 -0
- package/src/api/planPicker.js +40 -0
- package/src/api/planPlaces.d.ts +16 -0
- package/src/api/planPlaces.js +99 -0
- package/src/api/planStory.d.ts +26 -0
- package/src/api/planStory.js +66 -0
- package/src/api/planTimeline.d.ts +27 -0
- package/src/api/planTimeline.js +68 -0
- package/src/api/planViews.d.ts +25 -0
- package/src/api/planViews.js +35 -0
- package/src/api/prepared.js +4 -1
- package/src/api/renamedInputs.d.ts +15 -0
- package/src/api/renamedInputs.js +39 -0
- package/src/api/scene.d.ts +162 -68
- package/src/api/scene.js +247 -793
- package/src/api/sceneFreeze.d.ts +4 -0
- package/src/api/sceneFreeze.js +10 -0
- package/src/api/sceneReads.d.ts +171 -0
- package/src/api/sceneReads.js +6 -0
- package/src/api/story.d.ts +49 -19
- package/src/api/story.js +54 -22
- package/src/api/sunOrbit.js +9 -11
- package/src/api/time.d.ts +2 -1
- package/src/api/time.js +2 -1
- package/src/api/viewerCamera.d.ts +22 -0
- package/src/api/viewerCamera.js +84 -0
- package/src/api/viewerClock.d.ts +30 -0
- package/src/api/viewerClock.js +85 -0
- package/src/api/viewerFirstDraw.d.ts +14 -0
- package/src/api/viewerFirstDraw.js +26 -0
- package/src/api/viewerHandle.d.ts +85 -0
- package/src/api/viewerHandle.js +32 -0
- package/src/api/viewerLink.d.ts +88 -15
- package/src/api/viewerLink.js +117 -75
- package/src/api/viewerLooks.d.ts +19 -0
- package/src/api/viewerLooks.js +37 -0
- package/src/api/viewerPicker.d.ts +22 -0
- package/src/api/viewerPicker.js +49 -0
- package/src/api/viewerSelection.d.ts +30 -0
- package/src/api/viewerSelection.js +46 -0
- package/src/api/viewerViews.d.ts +10 -0
- package/src/api/viewerViews.js +18 -0
- package/src/api/viewerZones.d.ts +20 -0
- package/src/api/viewerZones.js +47 -0
- package/src/api/views.d.ts +7 -6
- package/src/api/views.js +12 -6
- package/src/app/App.d.ts +5 -3
- package/src/app/App.js +211 -82
- package/src/app/App.node.js +211 -82
- package/src/app/AstraeusScene.d.ts +18 -2
- package/src/app/AstraeusScene.js +4 -4
- package/src/app/BodyView.d.ts +4 -1
- package/src/app/BodyView.js +2 -2
- package/src/app/CameraController.d.ts +6 -0
- package/src/app/DeveloperSettings.d.ts +1 -4
- package/src/app/DeveloperSettings.js +6 -10
- package/src/app/FeatureMarkers.d.ts +4 -3
- package/src/app/FeatureMarkers.js +8 -13
- package/src/app/FrameRateSection.js +2 -1
- package/src/app/OrbitSetView.js +1 -1
- package/src/app/SettingControls.d.ts +11 -3
- package/src/app/SettingControls.js +10 -2
- package/src/app/SkyView.d.ts +3 -10
- package/src/app/SkyView.js +6 -28
- package/src/app/address.d.ts +16 -0
- package/src/app/address.js +31 -0
- package/src/app/bodyDraw.d.ts +10 -7
- package/src/app/bodyDraw.js +12 -32
- package/src/app/bodyMetrics.js +2 -2
- package/src/app/bodySet.d.ts +4 -20
- package/src/app/bodySet.js +5 -16
- package/src/app/debugReadout.js +1 -1
- package/src/app/displaySwitches.d.ts +4 -0
- package/src/app/displaySwitches.js +6 -0
- package/src/app/experienceDefinition.d.ts +11 -23
- package/src/app/listSwitch.d.ts +8 -14
- package/src/app/listSwitch.js +3 -10
- package/src/app/liveLook.d.ts +39 -0
- package/src/app/liveLook.js +66 -0
- package/src/app/look.d.ts +36 -0
- package/src/app/look.js +61 -0
- package/src/app/mission.d.ts +1 -1
- package/src/app/mission.js +1 -1
- package/src/app/openClock.d.ts +3 -2
- package/src/app/openClock.js +3 -3
- package/src/app/sceneCamera.d.ts +2 -0
- package/src/app/sceneCamera.js +11 -1
- package/src/app/sceneFrame.d.ts +4 -4
- package/src/app/sceneFrame.js +13 -8
- package/src/app/sceneHooks.js +3 -2
- package/src/app/style.css +114 -139
- package/src/app/trackedMetrics.d.ts +10 -3
- package/src/app/trackedMetrics.js +22 -11
- package/src/app/viewLink.d.ts +10 -32
- package/src/app/viewLink.js +10 -49
- package/src/app/viewerPort.d.ts +52 -0
- package/src/app/views.d.ts +3 -0
- package/src/assets/bodies/galileanMoons.js +1 -2
- package/src/assets/bodies/io.js +2 -2
- package/src/assets/bodies/listedMoons.d.ts +1 -1
- package/src/assets/bodies/listedMoons.js +2 -3
- package/src/assets/bodies/planetSystemMaps.js +2 -3
- package/src/assets/bodies/venus.js +2 -6
- package/src/assets/catalogue.js +1 -2
- package/src/assets/licence.d.ts +3 -3
- package/src/assets/licence.js +3 -3
- package/src/assets/pictures.d.ts +15 -12
- package/src/assets/pictures.js +24 -20
- package/src/assets/sky.d.ts +6 -5
- package/src/assets/sky.js +6 -9
- package/src/assets/visual.d.ts +4 -0
- package/src/core/astronomyAdapter.d.ts +1 -1
- package/src/core/astronomyAdapter.js +3 -3
- package/src/core/bodies/index.d.ts +0 -4
- package/src/core/bodies/index.js +14 -18
- package/src/core/bodies/jupiter.js +1 -1
- package/src/core/bodies/jupiterData.d.ts +0 -1
- package/src/core/bodies/jupiterData.js +2 -5
- package/src/core/bodies/mars.js +1 -1
- package/src/core/bodies/mercury.js +1 -1
- package/src/core/bodies/moonSystem.d.ts +1 -1
- package/src/core/bodies/moonSystem.js +102 -55
- package/src/core/bodies/outerPlanetRingData.js +2 -2
- package/src/core/bodies/outerPlanets.d.ts +2 -3
- package/src/core/bodies/outerPlanets.js +4 -13
- package/src/core/bodies/planetMoons.d.ts +0 -2
- package/src/core/bodies/planetMoons.js +1 -18
- package/src/core/bodies/planetRecords.d.ts +8 -2
- package/src/core/bodies/planetRecords.js +13 -5
- package/src/core/bodies/planetTrajectory.d.ts +21 -4
- package/src/core/bodies/planetTrajectory.js +29 -5
- package/src/core/bodies/venus.js +1 -1
- package/src/core/bodySetFamilies.d.ts +20 -0
- package/src/core/bodySetFamilies.js +14 -0
- package/src/core/chebyshevEphemeris.js +1 -1
- package/src/core/elementsBody.d.ts +8 -4
- package/src/core/elementsBody.js +32 -11
- package/src/core/elementsGroup.d.ts +27 -0
- package/src/core/elementsGroup.js +85 -0
- package/src/core/events.d.ts +2 -0
- package/src/core/events.js +2 -0
- package/src/core/illumination.js +1 -1
- package/src/core/listedOrbitGroup.d.ts +2 -0
- package/src/core/listedOrbitGroup.js +11 -7
- package/src/core/moonListText.d.ts +6 -0
- package/src/core/moonListText.js +19 -0
- package/src/core/moonTrajectory.js +1 -1
- package/src/core/pacing.d.ts +38 -3
- package/src/core/pacing.js +55 -4
- package/src/core/planetModels.d.ts +1 -1
- package/src/core/planetModels.js +3 -3
- package/src/core/planetSeries.d.ts +10 -2
- package/src/core/planetSeries.js +17 -3
- package/src/core/pointGroup.js +1 -1
- package/src/core/provenance.d.ts +2 -1
- package/src/core/provenance.js +2 -2
- package/src/core/referenceCenters.js +5 -5
- package/src/core/sampledTrajectory.js +1 -1
- package/src/core/scalePolicy.d.ts +1 -0
- package/src/core/startView.d.ts +19 -0
- package/src/core/startView.js +28 -0
- package/src/core/state.d.ts +6 -2
- package/src/core/state.js +3 -3
- package/src/core/storyPanels.d.ts +63 -0
- package/src/core/storyPanels.js +111 -0
- package/src/core/sunCentredSources.d.ts +4 -0
- package/src/core/sunCentredSources.js +9 -2
- package/src/core/timeInput.d.ts +4 -0
- package/src/core/timeInput.js +4 -0
- package/src/shell/AstraeusShell.d.ts +18 -2
- package/src/shell/AstraeusShell.js +53 -14
- package/src/shell/AstraeusShell.node.js +53 -14
- package/src/shell/Collapsible.d.ts +4 -3
- package/src/shell/Collapsible.js +5 -5
- package/src/shell/ControlsDrawer.d.ts +1 -1
- package/src/shell/ControlsDrawer.js +3 -1
- package/src/shell/DisplaySwitches.js +2 -1
- package/src/shell/InfoPanel.d.ts +3 -1
- package/src/shell/InfoPanel.js +5 -4
- package/src/shell/MoonFamilyPanel.js +1 -1
- package/src/shell/ObjectControls.d.ts +3 -1
- package/src/shell/ObjectControls.js +2 -2
- package/src/shell/Sources.d.ts +5 -3
- package/src/shell/Sources.js +5 -5
- package/src/shell/StoryPanelView.d.ts +4 -3
- package/src/shell/StoryPanelView.js +8 -6
- package/src/shell/SwitchControl.d.ts +5 -11
- package/src/shell/SwitchControl.js +2 -20
- package/src/shell/TimelineBar.css +81 -81
- package/src/shell/TimelineBar.d.ts +5 -2
- package/src/shell/TimelineBar.js +9 -8
- package/src/shell/TimelineBar.node.js +9 -8
- package/src/shell/TopBar.css +22 -22
- package/src/shell/TopBar.d.ts +5 -1
- package/src/shell/TopBar.js +2 -2
- package/src/shell/TopBar.node.js +2 -2
- package/src/shell/bootLoader.d.ts +4 -10
- package/src/shell/bootLoader.js +6 -52
- package/src/shell/embedded.css +18 -18
- package/src/shell/experience.d.ts +1 -1
- package/src/shell/moonFamilies.d.ts +2 -6
- package/src/shell/moonFamilies.js +2 -18
- package/src/shell/phone.css +58 -58
- package/src/shell/storyPanels.d.ts +2 -53
- package/src/shell/storyPanels.js +1 -106
- package/src/shell/style.css +153 -134
- package/src/shell/useDrawers.d.ts +3 -2
- package/src/shell/useDrawers.js +4 -3
- package/src/shell/viewerKeys.d.ts +8 -0
- package/src/shell/viewerKeys.js +16 -0
- package/src/synthetic/syntheticDefinition.js +20 -24
- package/src/synthetic/syntheticJourneyScene.js +3 -3
- package/src/synthetic/syntheticProbeDefinition.js +2 -1
- package/src/synthetic/syntheticViewsDefinition.d.ts +0 -3
- package/src/synthetic/syntheticViewsDefinition.js +10 -16
- package/data/moons/jupiter.json +0 -3333
- package/data/moons/neptune.json +0 -555
- package/data/moons/pluto.json +0 -205
- package/data/moons/saturn.json +0 -8267
- package/data/moons/uranus.json +0 -887
- package/src/app/addressNavigation.d.ts +0 -17
- package/src/app/addressNavigation.js +0 -16
- package/src/assets/bodies/jupiterMoonCatalogue.d.ts +0 -3
- package/src/assets/bodies/jupiterMoonCatalogue.js +0 -4
- package/src/assets/bodies/outerPlanetCatalogues.d.ts +0 -7
- package/src/assets/bodies/outerPlanetCatalogues.js +0 -8
- package/src/assets/bodies/swiftTuttle.d.ts +0 -12
- package/src/assets/bodies/swiftTuttle.js +0 -13
- package/src/assets/moonCatalogue.d.ts +0 -49
- package/src/assets/moonCatalogue.js +0 -80
- package/src/core/bodies/outerPlanetData.d.ts +0 -4
- package/src/core/bodies/outerPlanetData.js +0 -13
- package/src/core/bodies/swiftTuttle.d.ts +0 -46
- package/src/core/bodies/swiftTuttle.js +0 -106
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import type { BodyId } from "../core/body.js";
|
|
2
|
+
import type { BodyCatalogue } from "../assets/catalogue.js";
|
|
3
|
+
import type { EccentricSampling } from "../core/sunCentredSources.js";
|
|
4
|
+
import type { ExperienceDefinition } from "../app/experienceDefinition.js";
|
|
5
|
+
import type { BodyRef } from "./bodies.js";
|
|
6
|
+
import type { FollowView } from "./scene.js";
|
|
7
|
+
import type { CameraPose } from "./viewerLink.js";
|
|
8
|
+
import type { TimelineSetting } from "./story.js";
|
|
9
|
+
/** The scene's camera: what it opens on. */
|
|
10
|
+
export declare class SceneCamera {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(has: (id: string) => boolean, circlesSun: (id: string) => boolean, editable: () => void);
|
|
13
|
+
/** Opens framed on a body or trajectory already added to the scene and already following it (the viewer's Follow button shows as pressed). */
|
|
14
|
+
follow(id: string, view?: FollowView): this;
|
|
15
|
+
/** Opens framed on a body or trajectory already added to the scene, looking at it but not following it (the viewer's Focus button shows as pressed). The last of `follow` and `focus` wins. */
|
|
16
|
+
focus(id: string, view?: FollowView): this;
|
|
17
|
+
/**
|
|
18
|
+
* Opens at a pose with no camera button pressed (neither Focus nor Follow shows as pressed, and choosing another body moves the camera as it does without a start). The pose is what `ViewerHandle.camera` reads:
|
|
19
|
+
* `{ focus, azimuthDeg, elevationDeg, distance }`, distance in Earth radii. `focus` must be a body or trajectory already added (else `unknown-body`); a bad angle or distance throws `bad-camera`.
|
|
20
|
+
* The last of `follow`, `focus` and `setStartView` wins. Default: none.
|
|
21
|
+
* @example
|
|
22
|
+
* scene.camera.setStartView({ focus: "earth", azimuthDeg: 20, elevationDeg: 30, distance: 40 });
|
|
23
|
+
*/
|
|
24
|
+
setStartView(pose: CameraPose): this;
|
|
25
|
+
/**
|
|
26
|
+
* Chooses the objects whose Follow button the camera menu offers, by body, id, path or group already added to the scene (else `unknown-body`); the others offer Focus only. An empty list offers Follow on none.
|
|
27
|
+
* Default: every body, path and group. A scene whose opening view follows an object (`follow`) must list it, else the scene throws `bad-camera` when it is built.
|
|
28
|
+
* @example
|
|
29
|
+
* scene.camera.setFollowChoices(["moon"]);
|
|
30
|
+
*/
|
|
31
|
+
setFollowChoices(ids: readonly (BodyRef | BodyId)[]): this;
|
|
32
|
+
/**
|
|
33
|
+
* Sets how far the viewer can zoom out from what they look at, in Earth radii (the scene's scaled unit); a finite number above 0, else `bad-camera`.
|
|
34
|
+
* Also sets the camera's far plane (where drawing stops) to 2.5 times `distance`, so what lies out to the reach is still drawn; `farEarthRadii` (a finite number at least `distance`, in Earth radii) sets the far plane itself instead.
|
|
35
|
+
* Labels reach as far: a body's label stays shown at any distance the camera can take. Without this call the camera frames the scene as before.
|
|
36
|
+
* `setReach` and `fitOrbit` set the same limit, so the later call wins and replaces the earlier one.
|
|
37
|
+
*/
|
|
38
|
+
setReach(distance: number, options?: {
|
|
39
|
+
readonly farEarthRadii?: number;
|
|
40
|
+
}): this;
|
|
41
|
+
/**
|
|
42
|
+
* Sets the farthest zoom-out so the whole orbit of a body circling the Sun (a planet, or a comet or asteroid from `addBodyFromElements`, already added to the scene) fits the canvas
|
|
43
|
+
* from any view direction: the orbit's farthest Sun distance divided by the sine of the narrower half field of view of the canvas (vertical 45 degrees, or horizontal from the
|
|
44
|
+
* canvas's width over height), with 10 percent to spare. The viewer fits again whenever the canvas changes shape, such as a phone turning or a window resizing; the far plane follows
|
|
45
|
+
* as for `setReach`. The opening view does not move. Any other body throws `bad-camera` naming it; an id not in the scene throws `unknown-body`. `setReach` and `fitOrbit` set the
|
|
46
|
+
* same limit, so the later call wins and replaces the earlier one.
|
|
47
|
+
* @example
|
|
48
|
+
* scene.camera.fitOrbit("c-2025-a1");
|
|
49
|
+
*/
|
|
50
|
+
fitOrbit(body: BodyRef | BodyId): this;
|
|
51
|
+
/** The body `fitOrbit` fits the zoom-out to, if any. */
|
|
52
|
+
get fitted(): string | undefined;
|
|
53
|
+
/** The farthest zoom-out set with `setReach`, if any. */
|
|
54
|
+
get reachEarthRadii(): number | undefined;
|
|
55
|
+
/** The far plane set with `setReach`'s `farEarthRadii`, if any. */
|
|
56
|
+
get farEarthRadii(): number | undefined;
|
|
57
|
+
/** The pose `setStartView` set, if it is the last opening call. */
|
|
58
|
+
get pose(): CameraPose | undefined;
|
|
59
|
+
/** The objects offering Follow (`setFollowChoices`); undefined: every one. */
|
|
60
|
+
get followChoices(): readonly string[] | undefined;
|
|
61
|
+
get target(): string | undefined;
|
|
62
|
+
/** Whether the opening view follows its target (`follow`) rather than only looking at it (`focus`). */
|
|
63
|
+
get following(): boolean;
|
|
64
|
+
get view(): FollowView;
|
|
65
|
+
}
|
|
66
|
+
/** The fitted body's farthest Sun distance, read once when the viewer first needs it (a planet's reads the planet series, loaded by then); undefined when no orbit is fitted. */
|
|
67
|
+
export declare function fitFarthestKm(camera: SceneCamera, catalogue: BodyCatalogue, own: ReadonlyMap<BodyId, EccentricSampling>, openUtcMs: number): {
|
|
68
|
+
readonly read: () => number;
|
|
69
|
+
readonly settle: () => void;
|
|
70
|
+
} | undefined;
|
|
71
|
+
/** The `startCameraPresetId` entry of the experience: the camera preset the opening view follows or focuses (absent when none was asked for). */
|
|
72
|
+
export declare function startPresetEntry(camera: SceneCamera): {
|
|
73
|
+
startCameraPresetId?: string;
|
|
74
|
+
};
|
|
75
|
+
/** The `startView` entry of the definition: the opening framing of the camera's target (absent when none was asked for). */
|
|
76
|
+
export declare function startViewEntry(camera: SceneCamera): Pick<ExperienceDefinition, "startView">;
|
|
77
|
+
/** The playback and camera settings the scene asked for: looping, the farthest zoom-out and the ecliptic up. */
|
|
78
|
+
export declare function viewEntries(timeline: TimelineSetting | undefined, camera: SceneCamera, farthestKm: (() => number) | undefined, cover: (() => number) | undefined): Pick<ExperienceDefinition, "loop" | "camera" | "viewUp">;
|
|
79
|
+
/** The camera menu: Overview, Focus for every body and path, and Follow for every one unless `setFollowChoices` named fewer. */
|
|
80
|
+
export declare function cameraPresetsOf(objects: readonly {
|
|
81
|
+
readonly id: string;
|
|
82
|
+
readonly label: string;
|
|
83
|
+
}[], followChoices?: readonly string[]): ExperienceDefinition["experience"]["cameraPresets"];
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import { SceneError } from "./errors.js";
|
|
2
|
+
import { frozenCopy } from "./frozenCopy.js";
|
|
3
|
+
import { validateStartView } from "../core/startView.js";
|
|
4
|
+
import { farthestSunDistanceKm } from "./sunOrbit.js";
|
|
5
|
+
import { planetSeriesLoaded } from "../core/planetSeries.js";
|
|
6
|
+
/** The scene's camera: what it opens on. */
|
|
7
|
+
export class SceneCamera {
|
|
8
|
+
#target;
|
|
9
|
+
#following = false;
|
|
10
|
+
#view = {};
|
|
11
|
+
#reach;
|
|
12
|
+
#far;
|
|
13
|
+
#pose;
|
|
14
|
+
#followIds;
|
|
15
|
+
#fit;
|
|
16
|
+
#has;
|
|
17
|
+
#circlesSun;
|
|
18
|
+
#editable;
|
|
19
|
+
constructor(has, circlesSun, editable) {
|
|
20
|
+
this.#editable = editable;
|
|
21
|
+
this.#has = has;
|
|
22
|
+
this.#circlesSun = circlesSun;
|
|
23
|
+
}
|
|
24
|
+
/** Opens framed on a body or trajectory already added to the scene and already following it (the viewer's Follow button shows as pressed). */
|
|
25
|
+
follow(id, view = {}) {
|
|
26
|
+
return this.#open("follow", id, view, true);
|
|
27
|
+
}
|
|
28
|
+
/** Opens framed on a body or trajectory already added to the scene, looking at it but not following it (the viewer's Focus button shows as pressed). The last of `follow` and `focus` wins. */
|
|
29
|
+
focus(id, view = {}) {
|
|
30
|
+
return this.#open("focus", id, view, false);
|
|
31
|
+
}
|
|
32
|
+
#open(call, id, view, following) {
|
|
33
|
+
this.#editable();
|
|
34
|
+
if (!this.#has(id))
|
|
35
|
+
throw new SceneError("unknown-body", `camera.${call}("${id}"): no body or trajectory with that id has been added to the scene`);
|
|
36
|
+
if (view.up !== undefined && view.up !== "equatorial" && view.up !== "ecliptic")
|
|
37
|
+
throw new SceneError("bad-camera", `camera.${call}("${id}"): up "${String(view.up)}" must be "equatorial" or "ecliptic"`);
|
|
38
|
+
this.#target = id;
|
|
39
|
+
this.#pose = undefined;
|
|
40
|
+
this.#following = following;
|
|
41
|
+
this.#view = frozenCopy(view);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Opens at a pose with no camera button pressed (neither Focus nor Follow shows as pressed, and choosing another body moves the camera as it does without a start). The pose is what `ViewerHandle.camera` reads:
|
|
46
|
+
* `{ focus, azimuthDeg, elevationDeg, distance }`, distance in Earth radii. `focus` must be a body or trajectory already added (else `unknown-body`); a bad angle or distance throws `bad-camera`.
|
|
47
|
+
* The last of `follow`, `focus` and `setStartView` wins. Default: none.
|
|
48
|
+
* @example
|
|
49
|
+
* scene.camera.setStartView({ focus: "earth", azimuthDeg: 20, elevationDeg: 30, distance: 40 });
|
|
50
|
+
*/
|
|
51
|
+
setStartView(pose) {
|
|
52
|
+
this.#editable();
|
|
53
|
+
const focus = pose?.focus;
|
|
54
|
+
if (typeof focus === "string" && !this.#has(focus))
|
|
55
|
+
throw new SceneError("unknown-body", `camera.setStartView: "${focus}" has not been added to the scene`);
|
|
56
|
+
try {
|
|
57
|
+
this.#pose = validateStartView(pose, "camera.setStartView pose");
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof RangeError)
|
|
61
|
+
throw new SceneError("bad-camera", error.message);
|
|
62
|
+
throw error;
|
|
63
|
+
}
|
|
64
|
+
this.#target = undefined;
|
|
65
|
+
this.#following = false;
|
|
66
|
+
this.#view = {};
|
|
67
|
+
return this;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Chooses the objects whose Follow button the camera menu offers, by body, id, path or group already added to the scene (else `unknown-body`); the others offer Focus only. An empty list offers Follow on none.
|
|
71
|
+
* Default: every body, path and group. A scene whose opening view follows an object (`follow`) must list it, else the scene throws `bad-camera` when it is built.
|
|
72
|
+
* @example
|
|
73
|
+
* scene.camera.setFollowChoices(["moon"]);
|
|
74
|
+
*/
|
|
75
|
+
setFollowChoices(ids) {
|
|
76
|
+
this.#editable();
|
|
77
|
+
if (!Array.isArray(ids))
|
|
78
|
+
throw new SceneError("bad-camera", "camera.setFollowChoices: give a list of bodies or ids");
|
|
79
|
+
const named = ids.map((item) => (typeof item === "string" ? item : item?.id));
|
|
80
|
+
for (const id of named)
|
|
81
|
+
if (typeof id !== "string" || !this.#has(id))
|
|
82
|
+
throw new SceneError("unknown-body", `camera.setFollowChoices("${String(id)}"): no body or trajectory with that id has been added to the scene`);
|
|
83
|
+
this.#followIds = Object.freeze([...new Set(named)]);
|
|
84
|
+
return this;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Sets how far the viewer can zoom out from what they look at, in Earth radii (the scene's scaled unit); a finite number above 0, else `bad-camera`.
|
|
88
|
+
* Also sets the camera's far plane (where drawing stops) to 2.5 times `distance`, so what lies out to the reach is still drawn; `farEarthRadii` (a finite number at least `distance`, in Earth radii) sets the far plane itself instead.
|
|
89
|
+
* Labels reach as far: a body's label stays shown at any distance the camera can take. Without this call the camera frames the scene as before.
|
|
90
|
+
* `setReach` and `fitOrbit` set the same limit, so the later call wins and replaces the earlier one.
|
|
91
|
+
*/
|
|
92
|
+
setReach(distance, options = {}) {
|
|
93
|
+
this.#editable();
|
|
94
|
+
if (!(typeof distance === "number" && Number.isFinite(distance) && distance > 0))
|
|
95
|
+
throw new SceneError("bad-camera", `camera.setReach: distance must be a finite number above 0, got ${String(distance)}`);
|
|
96
|
+
const far = options.farEarthRadii;
|
|
97
|
+
if (far !== undefined && !(typeof far === "number" && Number.isFinite(far) && far >= distance))
|
|
98
|
+
throw new SceneError("bad-camera", `camera.setReach: farEarthRadii must be a finite number of at least the distance (${distance}), got ${String(far)}`);
|
|
99
|
+
this.#reach = distance;
|
|
100
|
+
this.#far = far;
|
|
101
|
+
this.#fit = undefined;
|
|
102
|
+
return this;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Sets the farthest zoom-out so the whole orbit of a body circling the Sun (a planet, or a comet or asteroid from `addBodyFromElements`, already added to the scene) fits the canvas
|
|
106
|
+
* from any view direction: the orbit's farthest Sun distance divided by the sine of the narrower half field of view of the canvas (vertical 45 degrees, or horizontal from the
|
|
107
|
+
* canvas's width over height), with 10 percent to spare. The viewer fits again whenever the canvas changes shape, such as a phone turning or a window resizing; the far plane follows
|
|
108
|
+
* as for `setReach`. The opening view does not move. Any other body throws `bad-camera` naming it; an id not in the scene throws `unknown-body`. `setReach` and `fitOrbit` set the
|
|
109
|
+
* same limit, so the later call wins and replaces the earlier one.
|
|
110
|
+
* @example
|
|
111
|
+
* scene.camera.fitOrbit("c-2025-a1");
|
|
112
|
+
*/
|
|
113
|
+
fitOrbit(body) {
|
|
114
|
+
this.#editable();
|
|
115
|
+
const id = typeof body === "string" ? body : body.id;
|
|
116
|
+
if (!this.#has(id))
|
|
117
|
+
throw new SceneError("unknown-body", `camera.fitOrbit("${id}"): no body or trajectory with that id has been added to the scene`);
|
|
118
|
+
if (!this.#circlesSun(id))
|
|
119
|
+
throw new SceneError("bad-camera", `camera.fitOrbit("${id}"): "${id}" is not a body that circles the Sun (a planet, a comet or one added with addBodyFromElements)`);
|
|
120
|
+
this.#fit = id;
|
|
121
|
+
this.#reach = undefined;
|
|
122
|
+
this.#far = undefined;
|
|
123
|
+
return this;
|
|
124
|
+
}
|
|
125
|
+
/** The body `fitOrbit` fits the zoom-out to, if any. */
|
|
126
|
+
get fitted() { return this.#fit; }
|
|
127
|
+
/** The farthest zoom-out set with `setReach`, if any. */
|
|
128
|
+
get reachEarthRadii() { return this.#reach; }
|
|
129
|
+
/** The far plane set with `setReach`'s `farEarthRadii`, if any. */
|
|
130
|
+
get farEarthRadii() { return this.#far; }
|
|
131
|
+
/** The pose `setStartView` set, if it is the last opening call. */
|
|
132
|
+
get pose() { return this.#pose; }
|
|
133
|
+
/** The objects offering Follow (`setFollowChoices`); undefined: every one. */
|
|
134
|
+
get followChoices() { return this.#followIds; }
|
|
135
|
+
get target() { return this.#target; }
|
|
136
|
+
/** Whether the opening view follows its target (`follow`) rather than only looking at it (`focus`). */
|
|
137
|
+
get following() { return this.#following; }
|
|
138
|
+
get view() { return this.#view; }
|
|
139
|
+
}
|
|
140
|
+
/** The fitted body's farthest Sun distance, read once when the viewer first needs it (a planet's reads the planet series, loaded by then); undefined when no orbit is fitted. */
|
|
141
|
+
export function fitFarthestKm(camera, catalogue, own, openUtcMs) {
|
|
142
|
+
const id = camera.fitted;
|
|
143
|
+
if (id === undefined)
|
|
144
|
+
return undefined;
|
|
145
|
+
let km;
|
|
146
|
+
const read = () => (km ??= farthestSunDistanceKm(catalogue, id, openUtcMs, own.get(id)));
|
|
147
|
+
if (planetSeriesLoaded())
|
|
148
|
+
read();
|
|
149
|
+
return { read, settle: () => void read() };
|
|
150
|
+
}
|
|
151
|
+
/** The `startCameraPresetId` entry of the experience: the camera preset the opening view follows or focuses (absent when none was asked for). */
|
|
152
|
+
export function startPresetEntry(camera) {
|
|
153
|
+
const target = camera.target;
|
|
154
|
+
return target === undefined ? {} : { startCameraPresetId: `${camera.following ? "follow" : "focus"}-${target}` };
|
|
155
|
+
}
|
|
156
|
+
/** The `startView` entry of the definition: the opening framing of the camera's target (absent when none was asked for). */
|
|
157
|
+
export function startViewEntry(camera) {
|
|
158
|
+
if (camera.pose !== undefined)
|
|
159
|
+
return { startView: { ...camera.pose } };
|
|
160
|
+
const target = camera.target;
|
|
161
|
+
const view = camera.view;
|
|
162
|
+
return target === undefined ? {} : { startView: { focus: target, azimuthDeg: view.azimuthDeg ?? 0, elevationDeg: view.elevationDeg ?? 30, distance: view.distance ?? 40 } };
|
|
163
|
+
}
|
|
164
|
+
/** The playback and camera settings the scene asked for: looping, the farthest zoom-out and the ecliptic up. */
|
|
165
|
+
export function viewEntries(timeline, camera, farthestKm, cover) {
|
|
166
|
+
const { reachEarthRadii: reach, view, target } = camera;
|
|
167
|
+
return {
|
|
168
|
+
...(timeline?.loop === true ? { loop: true } : {}),
|
|
169
|
+
...(reach === undefined ? {} : { camera: { maxFocusDistance: reach, far: camera.farEarthRadii ?? reach * 2.5 } }),
|
|
170
|
+
...(farthestKm === undefined ? {} : { camera: { fitOrbit: { farthestKm } } }),
|
|
171
|
+
...(reach !== undefined || farthestKm !== undefined || cover === undefined ? {} : { camera: { cover: { farthestKm: cover } } }),
|
|
172
|
+
...(view.up === undefined || target === undefined ? {} : { viewUp: view.up }),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
/** The camera menu: Overview, Focus for every body and path, and Follow for every one unless `setFollowChoices` named fewer. */
|
|
176
|
+
export function cameraPresetsOf(objects, followChoices) {
|
|
177
|
+
return [
|
|
178
|
+
{ id: "overview", label: "Overview", request: { kind: "overview" } },
|
|
179
|
+
...objects.flatMap(({ id, label }) => [
|
|
180
|
+
{ id: `focus-${id}`, label: `Focus ${label}`, request: { kind: "focus", target: id } },
|
|
181
|
+
...(followChoices === undefined || followChoices.includes(id) ? [{ id: `follow-${id}`, label: `Follow ${label}`, request: { kind: "follow", target: id } }] : []),
|
|
182
|
+
]),
|
|
183
|
+
];
|
|
184
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { BodyId } from "../core/body.js";
|
|
2
|
+
import type { TimeBounds } from "../core/trajectory.js";
|
|
3
|
+
import type { BodyCatalogue } from "../assets/catalogue.js";
|
|
4
|
+
import type { ExperienceDefinition, GroupLayer } from "../app/experienceDefinition.js";
|
|
5
|
+
import type { Metric } from "../shell/metrics.js";
|
|
6
|
+
import { type ActivityInput, type PlannedActivity } from "./activity.js";
|
|
7
|
+
import { type SceneActivityRead, type SceneGroupRead } from "./sceneReads.js";
|
|
8
|
+
import { type GroupInput, type PlannedGroup } from "./group.js";
|
|
9
|
+
/** Whether a group is built late, in `prepare`: a clump near a body reads its position, so needs the planet series, which are not in yet. */
|
|
10
|
+
export declare function lateGroups(seriesIn: boolean): (plan: PlannedGroup) => boolean;
|
|
11
|
+
/** The scene's layers: the points layer and the groups only when a group was added. */
|
|
12
|
+
export declare function groupLayersEntry(layers: readonly GroupLayer[], hasGroups: boolean, sunCentred: boolean): Pick<ExperienceDefinition, "sceneLayers" | "groups">;
|
|
13
|
+
/** What a `Scene` has planned for its groups and activities. */
|
|
14
|
+
export declare class GroupPlan {
|
|
15
|
+
#private;
|
|
16
|
+
readonly groups: Map<string, PlannedGroup>;
|
|
17
|
+
readonly activities: Map<string, PlannedActivity>;
|
|
18
|
+
/** `catalogue` gives the scene's catalogue as it stands; `taken` says whether the scene already holds an id. */
|
|
19
|
+
constructor(catalogue: () => BodyCatalogue, taken: (id: string) => boolean);
|
|
20
|
+
addGroup(input: GroupInput): void;
|
|
21
|
+
addActivity(input: ActivityInput): void;
|
|
22
|
+
/** Checks the groups against the finished scene: each circles its centre (default the scene's first body), which and whose clump body the scene must hold. */
|
|
23
|
+
check(ids: readonly BodyId[]): void;
|
|
24
|
+
/** The draw layers of the groups chosen by `which` (a clump near a planet reads its position, so needs the planet series). */
|
|
25
|
+
layers(ids: readonly BodyId[], window: TimeBounds, openUtcMs: number, which: (plan: PlannedGroup) => boolean): readonly GroupLayer[];
|
|
26
|
+
/** The activities in the order added, as the public list states them: fresh, frozen, nothing shared with the plan. */
|
|
27
|
+
activityReads(): readonly SceneActivityRead[];
|
|
28
|
+
/** The groups in the order added, as the public list states them; `first` is the scene's first body (the centre of a group that names none). */
|
|
29
|
+
reads(first: BodyId): readonly SceneGroupRead[];
|
|
30
|
+
/** The activity windows, when any were added. */
|
|
31
|
+
windowsEntry(): Pick<ExperienceDefinition["experience"], "windows">;
|
|
32
|
+
/** The bars of a group's info card at a moment. */
|
|
33
|
+
metrics(id: string, timeUtcMs: number): readonly Metric[];
|
|
34
|
+
/** A group's rate readout names an activity the scene holds. */
|
|
35
|
+
checkReadouts(): void;
|
|
36
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { planActivity, rateMetricOf } from "./activity.js";
|
|
2
|
+
import { SceneError } from "./errors.js";
|
|
3
|
+
import { frozenCopy } from "./frozenCopy.js";
|
|
4
|
+
import { frozenList } from "./sceneReads.js";
|
|
5
|
+
import { buildGroupLayer, groupCardProvenance, groupDescription, groupLimitations, planGroup } from "./group.js";
|
|
6
|
+
/** Whether a group is built late, in `prepare`: a clump near a body reads its position, so needs the planet series, which are not in yet. */
|
|
7
|
+
export function lateGroups(seriesIn) {
|
|
8
|
+
return (plan) => !seriesIn && plan.input.clump !== undefined;
|
|
9
|
+
}
|
|
10
|
+
/** The scene's layers: the points layer and the groups only when a group was added. */
|
|
11
|
+
export function groupLayersEntry(layers, hasGroups, sunCentred) {
|
|
12
|
+
const sceneLayers = ["tracked-bodies", ...(hasGroups ? ["points"] : []), ...(sunCentred ? ["sun-centred"] : [])];
|
|
13
|
+
return hasGroups ? { sceneLayers, groups: layers } : { sceneLayers };
|
|
14
|
+
}
|
|
15
|
+
/** What a `Scene` has planned for its groups and activities. */
|
|
16
|
+
export class GroupPlan {
|
|
17
|
+
groups = new Map();
|
|
18
|
+
activities = new Map();
|
|
19
|
+
#catalogue;
|
|
20
|
+
#taken;
|
|
21
|
+
/** `catalogue` gives the scene's catalogue as it stands; `taken` says whether the scene already holds an id. */
|
|
22
|
+
constructor(catalogue, taken) {
|
|
23
|
+
this.#catalogue = catalogue;
|
|
24
|
+
this.#taken = taken;
|
|
25
|
+
}
|
|
26
|
+
addGroup(input) {
|
|
27
|
+
const plan = planGroup(input, this.#catalogue());
|
|
28
|
+
if (this.#taken(plan.id))
|
|
29
|
+
throw new SceneError("duplicate-id", `addGroup("${plan.id}"): that id is already in the scene`);
|
|
30
|
+
this.groups.set(plan.id, plan);
|
|
31
|
+
}
|
|
32
|
+
addActivity(input) {
|
|
33
|
+
const plan = planActivity(input);
|
|
34
|
+
if (this.activities.has(plan.window.id))
|
|
35
|
+
throw new SceneError("duplicate-id", `addActivity("${plan.window.id}"): an activity with that id is already in the scene`);
|
|
36
|
+
this.activities.set(plan.window.id, plan);
|
|
37
|
+
}
|
|
38
|
+
/** Checks the groups against the finished scene: each circles its centre (default the scene's first body), which and whose clump body the scene must hold. */
|
|
39
|
+
check(ids) {
|
|
40
|
+
for (const plan of this.groups.values()) {
|
|
41
|
+
const center = plan.input.center ?? ids[0];
|
|
42
|
+
const clump = plan.input.clump;
|
|
43
|
+
if (!ids.includes(center))
|
|
44
|
+
throw new SceneError("bad-group", `addGroup("${plan.id}"): the orbits circle "${center}", which has not been added to the scene`);
|
|
45
|
+
if (clump !== undefined && !ids.includes(clump.near))
|
|
46
|
+
throw new SceneError("bad-group", `addGroup("${plan.id}"): clump.near "${clump.near}" has not been added to the scene`);
|
|
47
|
+
if (clump !== undefined && clump.near === center)
|
|
48
|
+
throw new SceneError("bad-group", `addGroup("${plan.id}"): the clump cannot be near the body the orbits circle ("${center}")`);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** The draw layers of the groups chosen by `which` (a clump near a planet reads its position, so needs the planet series). */
|
|
52
|
+
layers(ids, window, openUtcMs, which) {
|
|
53
|
+
return [...this.groups.values()].filter(which).map((plan) => buildGroupLayer(plan, this.#catalogue(), plan.input.center ?? ids[0], openUtcMs, window));
|
|
54
|
+
}
|
|
55
|
+
/** The activities in the order added, as the public list states them: fresh, frozen, nothing shared with the plan. */
|
|
56
|
+
activityReads() {
|
|
57
|
+
return frozenList([...this.activities.values()].map(({ window, peakValue, peakLabel }) => ({
|
|
58
|
+
id: window.id,
|
|
59
|
+
label: window.label,
|
|
60
|
+
unit: window.rate?.unit ?? "",
|
|
61
|
+
windowStartUtcMs: window.startUtcMs,
|
|
62
|
+
windowEndUtcMs: window.endUtcMs,
|
|
63
|
+
peak: Object.freeze({ label: peakLabel, value: peakValue, ...(window.peakUtcMs === undefined ? {} : { timeUtcMs: window.peakUtcMs }) }),
|
|
64
|
+
samples: frozenCopy((window.rate?.samples ?? []).map(({ timeUtcMs, value }) => ({ timeUtcMs, value }))),
|
|
65
|
+
...(window.provenance === undefined ? {} : { provenance: frozenCopy(window.provenance.map(({ startUtcMs, endUtcMs, provenance }) => ({ stretchStartUtcMs: startUtcMs, stretchEndUtcMs: endUtcMs, provenance }))) }),
|
|
66
|
+
...(window.type === undefined ? {} : { type: window.type }),
|
|
67
|
+
})));
|
|
68
|
+
}
|
|
69
|
+
/** The groups in the order added, as the public list states them; `first` is the scene's first body (the centre of a group that names none). */
|
|
70
|
+
reads(first) {
|
|
71
|
+
return frozenList([...this.groups.values()].map(({ id, label, input }) => ({
|
|
72
|
+
id,
|
|
73
|
+
label,
|
|
74
|
+
count: input.orbits.length,
|
|
75
|
+
center: input.center ?? first,
|
|
76
|
+
plane: input.plane,
|
|
77
|
+
provenance: groupCardProvenance(input),
|
|
78
|
+
description: groupDescription(input, input.orbits.length),
|
|
79
|
+
knownLimitations: Object.freeze(groupLimitations(input, this.#catalogue())),
|
|
80
|
+
})));
|
|
81
|
+
}
|
|
82
|
+
/** The activity windows, when any were added. */
|
|
83
|
+
windowsEntry() {
|
|
84
|
+
return this.activities.size === 0 ? {} : { windows: [...this.activities.values()].map((activity) => activity.window) };
|
|
85
|
+
}
|
|
86
|
+
/** The bars of a group's info card at a moment. */
|
|
87
|
+
metrics(id, timeUtcMs) {
|
|
88
|
+
return (this.groups.get(id)?.input.readouts ?? []).map((spec) => rateMetricOf(id, this.activities.get(spec.activity ?? this.#firstActivity()), timeUtcMs));
|
|
89
|
+
}
|
|
90
|
+
#firstActivity() {
|
|
91
|
+
return this.activities.keys().next().value;
|
|
92
|
+
}
|
|
93
|
+
/** A group's rate readout names an activity the scene holds. */
|
|
94
|
+
checkReadouts() {
|
|
95
|
+
for (const { id, input } of this.groups.values()) {
|
|
96
|
+
for (const spec of input.readouts ?? []) {
|
|
97
|
+
const named = spec.activity ?? (this.activities.size > 0 ? this.#firstActivity() : undefined);
|
|
98
|
+
if (named === undefined || !this.activities.has(named))
|
|
99
|
+
throw new SceneError("bad-readout", `addGroup("${id}"): readout rate ${named === undefined ? "needs an activity (addActivity)" : `names activity "${named}", which has not been added to the scene`}`);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { BodyCatalogue } from "../assets/catalogue.js";
|
|
2
|
+
import type { ExperienceDefinition } from "../app/experienceDefinition.js";
|
|
3
|
+
import type { MoonPanelInput } from "./moonPanelInput.js";
|
|
4
|
+
import { type SceneMoonPanelRead } from "./sceneReads.js";
|
|
5
|
+
type MoonFamilyList = NonNullable<ExperienceDefinition["experience"]["moonFamilies"]>;
|
|
6
|
+
/** What a `Scene` has planned for its moon panel. */
|
|
7
|
+
export declare class MoonPanelPlan {
|
|
8
|
+
#private;
|
|
9
|
+
set(input: MoonPanelInput): void;
|
|
10
|
+
get input(): MoonPanelInput | undefined;
|
|
11
|
+
/** The moon count and the line "115 moons in the JPL Horizons list of 18 October 2026"; undefined when no panel was set. */
|
|
12
|
+
read(): SceneMoonPanelRead | undefined;
|
|
13
|
+
/**
|
|
14
|
+
* The shell's list: each moon must be a body or body-set member of the scene (`labels` maps those ids to their labels); a moon that is a body gets the
|
|
15
|
+
* picture the viewer's data brings for it (`pictureOf`), a dot none.
|
|
16
|
+
*/
|
|
17
|
+
list(labels: ReadonlyMap<string, string>, bodies: ReadonlySet<string>, catalogue: BodyCatalogue, pictureOf: (picture: string) => string | undefined): MoonFamilyList | undefined;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import { moonListSummary } from "../core/moonListText.js";
|
|
2
|
+
import { SceneError } from "./errors.js";
|
|
3
|
+
import { frozenCopy } from "./frozenCopy.js";
|
|
4
|
+
import { frozenList } from "./sceneReads.js";
|
|
5
|
+
import { toUtcMs } from "./time.js";
|
|
6
|
+
const bad = (message) => new SceneError("bad-moon-panel", `setMoonPanel: ${message}`);
|
|
7
|
+
const isText = (value) => typeof value === "string" && value !== "";
|
|
8
|
+
/** The `YYYY-MM-DD` day of a list date, or throws `bad-moon-panel` when it is not a moment. */
|
|
9
|
+
function dayOf(input) {
|
|
10
|
+
if (input.listDate === undefined)
|
|
11
|
+
return undefined;
|
|
12
|
+
try {
|
|
13
|
+
return new Date(toUtcMs(input.listDate, "listDate")).toISOString().slice(0, 10);
|
|
14
|
+
}
|
|
15
|
+
catch {
|
|
16
|
+
throw bad(`listDate "${String(input.listDate)}" is not a valid moment; use an ISO day such as "2026-10-18", a Date or Unix milliseconds`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
/** Checks one family and its moons; `families` and `moons` collect the ids seen so far. */
|
|
20
|
+
function checkFamily(family, families, moons) {
|
|
21
|
+
if (!isText(family?.id))
|
|
22
|
+
throw bad("every family needs a non-empty id");
|
|
23
|
+
if (families.has(family.id))
|
|
24
|
+
throw bad(`family "${family.id}" appears twice`);
|
|
25
|
+
families.add(family.id);
|
|
26
|
+
if (!isText(family.label))
|
|
27
|
+
throw bad(`family "${family.id}" needs a label`);
|
|
28
|
+
if (!isText(family.description))
|
|
29
|
+
throw bad(`family "${family.id}" needs a one-line description`);
|
|
30
|
+
if (!Array.isArray(family.moons))
|
|
31
|
+
throw bad(`family "${family.id}": moons must be a list`);
|
|
32
|
+
for (const moon of family.moons) {
|
|
33
|
+
if (!isText(moon?.id))
|
|
34
|
+
throw bad(`family "${family.id}": every moon needs a non-empty id`);
|
|
35
|
+
if (moons.has(moon.id))
|
|
36
|
+
throw bad(`moon "${moon.id}" appears twice`);
|
|
37
|
+
moons.add(moon.id);
|
|
38
|
+
if (moon.named !== undefined && typeof moon.named !== "boolean")
|
|
39
|
+
throw bad(`moon "${moon.id}": named must be true or false`);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Checks the panel's words, families, moons and list source and date; returns the list day. */
|
|
43
|
+
function checkInput(input) {
|
|
44
|
+
if (typeof input !== "object" || input === null)
|
|
45
|
+
throw bad("give a { label, families } object");
|
|
46
|
+
if (!isText(input.label))
|
|
47
|
+
throw bad("the panel needs a label");
|
|
48
|
+
if (!Array.isArray(input.families) || input.families.length === 0)
|
|
49
|
+
throw bad("the panel needs at least one family");
|
|
50
|
+
const families = new Set();
|
|
51
|
+
const moons = new Set();
|
|
52
|
+
for (const family of input.families)
|
|
53
|
+
checkFamily(family, families, moons);
|
|
54
|
+
if (input.featuredFamily !== undefined && !families.has(input.featuredFamily))
|
|
55
|
+
throw bad(`featuredFamily "${String(input.featuredFamily)}" is not one of the families`);
|
|
56
|
+
if (input.listSource !== undefined && !isText(input.listSource))
|
|
57
|
+
throw bad("listSource must be a non-empty text");
|
|
58
|
+
return dayOf(input);
|
|
59
|
+
}
|
|
60
|
+
/** What a `Scene` has planned for its moon panel. */
|
|
61
|
+
export class MoonPanelPlan {
|
|
62
|
+
#input;
|
|
63
|
+
#day;
|
|
64
|
+
set(input) {
|
|
65
|
+
this.#day = checkInput(input);
|
|
66
|
+
this.#input = frozenCopy(input);
|
|
67
|
+
}
|
|
68
|
+
get input() { return this.#input; }
|
|
69
|
+
/** The moon count and the line "115 moons in the JPL Horizons list of 18 October 2026"; undefined when no panel was set. */
|
|
70
|
+
read() {
|
|
71
|
+
const input = this.#input;
|
|
72
|
+
if (input === undefined)
|
|
73
|
+
return undefined;
|
|
74
|
+
const count = input.families.reduce((total, family) => total + family.moons.length, 0);
|
|
75
|
+
return Object.freeze({ count, summary: moonListSummary(count, input.listSource, this.#day) });
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* The shell's list: each moon must be a body or body-set member of the scene (`labels` maps those ids to their labels); a moon that is a body gets the
|
|
79
|
+
* picture the viewer's data brings for it (`pictureOf`), a dot none.
|
|
80
|
+
*/
|
|
81
|
+
list(labels, bodies, catalogue, pictureOf) {
|
|
82
|
+
const input = this.#input;
|
|
83
|
+
if (input === undefined)
|
|
84
|
+
return undefined;
|
|
85
|
+
return {
|
|
86
|
+
planetLabel: input.label,
|
|
87
|
+
...(input.featuredFamily === undefined ? {} : { featuredFamilyId: input.featuredFamily }),
|
|
88
|
+
families: frozenList(input.families.map((family) => ({
|
|
89
|
+
id: family.id,
|
|
90
|
+
label: family.label,
|
|
91
|
+
description: family.description,
|
|
92
|
+
moons: frozenList(family.moons.map((moon) => {
|
|
93
|
+
const label = labels.get(moon.id);
|
|
94
|
+
if (label === undefined)
|
|
95
|
+
throw bad(`moon "${moon.id}" in family "${family.id}" is not a body or body-set member of the scene`);
|
|
96
|
+
const picture = bodies.has(moon.id) ? pictureOf(catalogue.has(moon.id) ? catalogue.get(moon.id).visual.picture ?? moon.id : moon.id) : undefined;
|
|
97
|
+
return { id: moon.id, label, named: moon.named ?? true, ...(picture === undefined ? {} : { pictureUrl: picture }) };
|
|
98
|
+
})),
|
|
99
|
+
}))),
|
|
100
|
+
...(input.listSource === undefined ? {} : { listSource: input.listSource }),
|
|
101
|
+
...(this.#day === undefined ? {} : { listDate: this.#day }),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import type { BodyId } from "../core/body.js";
|
|
2
|
+
import type { WindowProvenanceSpan } from "../core/timeWindow.js";
|
|
3
|
+
import { type BodyCatalogue } from "../assets/catalogue.js";
|
|
4
|
+
import { type TrackedBody } from "../app/mission.js";
|
|
5
|
+
import { SceneError } from "./errors.js";
|
|
6
|
+
import type { ReadoutInput, TrajectoryInput } from "./scene.js";
|
|
7
|
+
import { type ScenePathRead } from "./sceneReads.js";
|
|
8
|
+
export interface Tracked {
|
|
9
|
+
readonly body: TrackedBody;
|
|
10
|
+
/** `lineFixedTo: "auto"`: the stretches are resolved from the samples once the planet series are in. */
|
|
11
|
+
readonly auto?: true;
|
|
12
|
+
readonly center: BodyId;
|
|
13
|
+
readonly description?: string;
|
|
14
|
+
readonly knownLimitations?: readonly string[];
|
|
15
|
+
readonly provenanceSpans?: readonly WindowProvenanceSpan[];
|
|
16
|
+
readonly readouts: readonly ReadoutInput[];
|
|
17
|
+
}
|
|
18
|
+
/** The paths in the order added, as the public list states them. */
|
|
19
|
+
export declare function pathReads(tracked: Iterable<Tracked>): readonly ScenePathRead[];
|
|
20
|
+
/** Validates and stores one path about `center`. */
|
|
21
|
+
export declare function buildTracked(input: TrajectoryInput, center: BodyId, labelReaches: Map<string, number>): Tracked;
|
|
22
|
+
/** Throws `error` unless `reach` is a positive finite number. */
|
|
23
|
+
export declare function checkLabelReach(reach: unknown, error: SceneError): void;
|
|
24
|
+
/** Checks each readout's kind and the catalogued body it names; whether the scene holds that body is checked when the definition is built. */
|
|
25
|
+
export declare function readoutsOf(id: string, readouts?: readonly ReadoutInput[], call?: string): readonly ReadoutInput[];
|
|
26
|
+
/**
|
|
27
|
+
* The distance the default zoom-out must cover for the scene's paths about the scene centre (I-114): a path reaching past the planets must fit whole whichever point of it the camera looks at,
|
|
28
|
+
* so twice its farthest distance from the centre (no two points of a path are farther apart than that). Sampled over each path's span; undefined when no path is about the centre.
|
|
29
|
+
*/
|
|
30
|
+
export declare function pathCover(tracked: Iterable<Tracked>, sunCentred: boolean, centre: BodyId): (() => number) | undefined;
|
|
31
|
+
/** The `"auto"` paths' one resolution into `tracked`: `now` runs it (through the caller's guarded read) when the planet series are in; else `later` is true and `settle` runs it in `prepare`. */
|
|
32
|
+
export declare function autoPaths(catalogue: BodyCatalogue, entries: readonly Tracked[], tracked: TrackedBody[], ids: readonly BodyId[]): {
|
|
33
|
+
readonly later: boolean;
|
|
34
|
+
readonly now: (guard: (read: () => void) => void) => void;
|
|
35
|
+
readonly settle: (guard: (read: () => void) => void) => void;
|
|
36
|
+
};
|
|
37
|
+
/** A readout, or the body the line is fixed to, names a body the scene must hold. */
|
|
38
|
+
export declare function checkReadouts(entry: Tracked, ids: readonly BodyId[]): void;
|
|
39
|
+
/** The readouts of a path or a body name only bodies the scene holds. */
|
|
40
|
+
export declare function checkNamedReadouts(id: string, readouts: readonly ReadoutInput[], ids: readonly BodyId[], call: string): void;
|