astraeus 0.7.0 → 0.8.0

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.
Files changed (271) hide show
  1. package/CHANGELOG.md +176 -0
  2. package/README.md +185 -37
  3. package/package.json +5 -4
  4. package/src/api/AstraeusScene.d.ts +21 -5
  5. package/src/api/AstraeusScene.js +34 -10
  6. package/src/api/AstraeusScene.node.js +34 -10
  7. package/src/api/assembleScene.d.ts +36 -0
  8. package/src/api/assembleScene.js +175 -0
  9. package/src/api/bodySetChecks.d.ts +10 -0
  10. package/src/api/bodySetChecks.js +117 -0
  11. package/src/api/bodySetInput.d.ts +81 -0
  12. package/src/api/bodySetInput.js +1 -0
  13. package/src/api/containingBlock.d.ts +6 -0
  14. package/src/api/containingBlock.js +16 -0
  15. package/src/api/data.d.ts +17 -5
  16. package/src/api/data.js +28 -10
  17. package/src/api/definitionOf.d.ts +16 -0
  18. package/src/api/definitionOf.js +20 -0
  19. package/src/api/errors.d.ts +61 -1
  20. package/src/api/frozenCopy.d.ts +6 -0
  21. package/src/api/frozenCopy.js +26 -0
  22. package/src/api/group.d.ts +8 -2
  23. package/src/api/group.js +24 -5
  24. package/src/api/index.d.ts +18 -7
  25. package/src/api/index.js +2 -2
  26. package/src/api/index.node.js +2 -2
  27. package/src/api/listeners.d.ts +5 -0
  28. package/src/api/listeners.js +25 -0
  29. package/src/api/look.d.ts +47 -0
  30. package/src/api/look.js +1 -0
  31. package/src/api/lookInput.d.ts +3 -0
  32. package/src/api/lookInput.js +41 -0
  33. package/src/api/moonPanelInput.d.ts +60 -0
  34. package/src/api/moonPanelInput.js +1 -0
  35. package/src/api/mount.d.ts +9 -19
  36. package/src/api/mount.js +27 -13
  37. package/src/api/mount.node.js +27 -13
  38. package/src/api/pathProvenance.js +1 -1
  39. package/src/api/pickerInput.d.ts +25 -0
  40. package/src/api/pickerInput.js +1 -0
  41. package/src/api/planBodies.d.ts +72 -0
  42. package/src/api/planBodies.js +300 -0
  43. package/src/api/planBodySets.d.ts +68 -0
  44. package/src/api/planBodySets.js +234 -0
  45. package/src/api/planCamera.d.ts +83 -0
  46. package/src/api/planCamera.js +184 -0
  47. package/src/api/planGroups.d.ts +36 -0
  48. package/src/api/planGroups.js +103 -0
  49. package/src/api/planMoonPanel.d.ts +19 -0
  50. package/src/api/planMoonPanel.js +104 -0
  51. package/src/api/planPaths.d.ts +40 -0
  52. package/src/api/planPaths.js +212 -0
  53. package/src/api/planPicker.d.ts +12 -0
  54. package/src/api/planPicker.js +40 -0
  55. package/src/api/planPlaces.d.ts +16 -0
  56. package/src/api/planPlaces.js +99 -0
  57. package/src/api/planStory.d.ts +26 -0
  58. package/src/api/planStory.js +66 -0
  59. package/src/api/planTimeline.d.ts +27 -0
  60. package/src/api/planTimeline.js +68 -0
  61. package/src/api/planViews.d.ts +25 -0
  62. package/src/api/planViews.js +35 -0
  63. package/src/api/prepared.js +4 -1
  64. package/src/api/renamedInputs.d.ts +15 -0
  65. package/src/api/renamedInputs.js +39 -0
  66. package/src/api/scene.d.ts +162 -68
  67. package/src/api/scene.js +247 -793
  68. package/src/api/sceneFreeze.d.ts +4 -0
  69. package/src/api/sceneFreeze.js +10 -0
  70. package/src/api/sceneReads.d.ts +171 -0
  71. package/src/api/sceneReads.js +6 -0
  72. package/src/api/story.d.ts +49 -19
  73. package/src/api/story.js +54 -22
  74. package/src/api/sunOrbit.js +9 -11
  75. package/src/api/time.d.ts +2 -1
  76. package/src/api/time.js +2 -1
  77. package/src/api/viewerCamera.d.ts +22 -0
  78. package/src/api/viewerCamera.js +84 -0
  79. package/src/api/viewerClock.d.ts +30 -0
  80. package/src/api/viewerClock.js +85 -0
  81. package/src/api/viewerFirstDraw.d.ts +14 -0
  82. package/src/api/viewerFirstDraw.js +26 -0
  83. package/src/api/viewerHandle.d.ts +79 -0
  84. package/src/api/viewerHandle.js +31 -0
  85. package/src/api/viewerLink.d.ts +87 -15
  86. package/src/api/viewerLink.js +111 -75
  87. package/src/api/viewerLooks.d.ts +19 -0
  88. package/src/api/viewerLooks.js +37 -0
  89. package/src/api/viewerPicker.d.ts +22 -0
  90. package/src/api/viewerPicker.js +49 -0
  91. package/src/api/viewerSelection.d.ts +25 -0
  92. package/src/api/viewerSelection.js +31 -0
  93. package/src/api/viewerViews.d.ts +10 -0
  94. package/src/api/viewerViews.js +18 -0
  95. package/src/api/viewerZones.d.ts +20 -0
  96. package/src/api/viewerZones.js +47 -0
  97. package/src/api/views.d.ts +4 -5
  98. package/src/api/views.js +7 -5
  99. package/src/app/App.d.ts +5 -3
  100. package/src/app/App.js +191 -82
  101. package/src/app/App.node.js +191 -82
  102. package/src/app/AstraeusScene.d.ts +16 -2
  103. package/src/app/AstraeusScene.js +4 -4
  104. package/src/app/BodyView.d.ts +4 -1
  105. package/src/app/BodyView.js +2 -2
  106. package/src/app/CameraController.d.ts +6 -0
  107. package/src/app/DeveloperSettings.d.ts +1 -4
  108. package/src/app/DeveloperSettings.js +6 -10
  109. package/src/app/FeatureMarkers.d.ts +4 -3
  110. package/src/app/FeatureMarkers.js +8 -13
  111. package/src/app/FrameRateSection.js +2 -1
  112. package/src/app/OrbitSetView.js +1 -1
  113. package/src/app/SettingControls.d.ts +11 -3
  114. package/src/app/SettingControls.js +10 -2
  115. package/src/app/SkyView.d.ts +3 -10
  116. package/src/app/SkyView.js +6 -28
  117. package/src/app/address.d.ts +16 -0
  118. package/src/app/address.js +31 -0
  119. package/src/app/bodyDraw.d.ts +10 -7
  120. package/src/app/bodyDraw.js +12 -32
  121. package/src/app/bodyMetrics.js +2 -2
  122. package/src/app/bodySet.d.ts +4 -20
  123. package/src/app/bodySet.js +5 -16
  124. package/src/app/debugReadout.js +1 -1
  125. package/src/app/displaySwitches.d.ts +4 -0
  126. package/src/app/displaySwitches.js +6 -0
  127. package/src/app/experienceDefinition.d.ts +11 -23
  128. package/src/app/listSwitch.d.ts +8 -14
  129. package/src/app/listSwitch.js +3 -10
  130. package/src/app/liveLook.d.ts +39 -0
  131. package/src/app/liveLook.js +66 -0
  132. package/src/app/look.d.ts +36 -0
  133. package/src/app/look.js +61 -0
  134. package/src/app/mission.d.ts +1 -1
  135. package/src/app/mission.js +1 -1
  136. package/src/app/openClock.d.ts +3 -2
  137. package/src/app/openClock.js +3 -3
  138. package/src/app/sceneCamera.js +9 -0
  139. package/src/app/sceneFrame.d.ts +4 -4
  140. package/src/app/sceneFrame.js +13 -8
  141. package/src/app/sceneHooks.js +3 -2
  142. package/src/app/style.css +114 -139
  143. package/src/app/trackedMetrics.d.ts +10 -3
  144. package/src/app/trackedMetrics.js +22 -11
  145. package/src/app/viewLink.d.ts +10 -32
  146. package/src/app/viewLink.js +10 -49
  147. package/src/app/viewerPort.d.ts +50 -0
  148. package/src/app/views.d.ts +1 -0
  149. package/src/assets/bodies/galileanMoons.js +1 -2
  150. package/src/assets/bodies/io.js +2 -2
  151. package/src/assets/bodies/listedMoons.d.ts +1 -1
  152. package/src/assets/bodies/listedMoons.js +2 -3
  153. package/src/assets/bodies/planetSystemMaps.js +2 -3
  154. package/src/assets/bodies/venus.js +2 -6
  155. package/src/assets/catalogue.js +1 -2
  156. package/src/assets/licence.d.ts +3 -3
  157. package/src/assets/licence.js +3 -3
  158. package/src/assets/pictures.d.ts +15 -12
  159. package/src/assets/pictures.js +24 -20
  160. package/src/assets/sky.d.ts +6 -5
  161. package/src/assets/sky.js +6 -9
  162. package/src/assets/visual.d.ts +4 -0
  163. package/src/core/bodies/index.d.ts +0 -4
  164. package/src/core/bodies/index.js +1 -6
  165. package/src/core/bodies/jupiterData.d.ts +0 -1
  166. package/src/core/bodies/jupiterData.js +2 -5
  167. package/src/core/bodies/moonSystem.d.ts +1 -1
  168. package/src/core/bodies/moonSystem.js +102 -55
  169. package/src/core/bodies/outerPlanetRingData.js +2 -2
  170. package/src/core/bodies/planetTrajectory.js +1 -1
  171. package/src/core/bodySetFamilies.d.ts +20 -0
  172. package/src/core/bodySetFamilies.js +14 -0
  173. package/src/core/chebyshevEphemeris.js +1 -1
  174. package/src/core/elementsBody.d.ts +8 -4
  175. package/src/core/elementsBody.js +32 -11
  176. package/src/core/elementsGroup.d.ts +27 -0
  177. package/src/core/elementsGroup.js +85 -0
  178. package/src/core/events.d.ts +2 -0
  179. package/src/core/events.js +2 -0
  180. package/src/core/illumination.js +1 -1
  181. package/src/core/listedOrbitGroup.d.ts +2 -0
  182. package/src/core/listedOrbitGroup.js +11 -7
  183. package/src/core/moonListText.d.ts +6 -0
  184. package/src/core/moonListText.js +19 -0
  185. package/src/core/moonTrajectory.js +1 -1
  186. package/src/core/pacing.d.ts +38 -3
  187. package/src/core/pacing.js +55 -4
  188. package/src/core/planetModels.js +2 -2
  189. package/src/core/planetSeries.d.ts +8 -0
  190. package/src/core/planetSeries.js +16 -2
  191. package/src/core/pointGroup.js +1 -1
  192. package/src/core/provenance.d.ts +2 -1
  193. package/src/core/provenance.js +2 -2
  194. package/src/core/referenceCenters.js +5 -5
  195. package/src/core/sampledTrajectory.js +1 -1
  196. package/src/core/scalePolicy.d.ts +1 -0
  197. package/src/core/startView.d.ts +19 -0
  198. package/src/core/startView.js +28 -0
  199. package/src/core/state.d.ts +6 -2
  200. package/src/core/state.js +3 -3
  201. package/src/core/storyPanels.d.ts +63 -0
  202. package/src/core/storyPanels.js +111 -0
  203. package/src/core/sunCentredSources.d.ts +4 -0
  204. package/src/core/sunCentredSources.js +9 -2
  205. package/src/core/timeInput.d.ts +4 -0
  206. package/src/core/timeInput.js +4 -0
  207. package/src/shell/AstraeusShell.d.ts +5 -1
  208. package/src/shell/AstraeusShell.js +20 -11
  209. package/src/shell/AstraeusShell.node.js +20 -11
  210. package/src/shell/Collapsible.d.ts +4 -3
  211. package/src/shell/Collapsible.js +5 -5
  212. package/src/shell/ControlsDrawer.d.ts +1 -1
  213. package/src/shell/ControlsDrawer.js +3 -1
  214. package/src/shell/DisplaySwitches.js +2 -1
  215. package/src/shell/InfoPanel.d.ts +3 -1
  216. package/src/shell/InfoPanel.js +5 -4
  217. package/src/shell/MoonFamilyPanel.js +1 -1
  218. package/src/shell/ObjectControls.d.ts +3 -1
  219. package/src/shell/ObjectControls.js +2 -2
  220. package/src/shell/Sources.d.ts +5 -3
  221. package/src/shell/Sources.js +5 -5
  222. package/src/shell/StoryPanelView.d.ts +4 -3
  223. package/src/shell/StoryPanelView.js +8 -6
  224. package/src/shell/SwitchControl.d.ts +5 -11
  225. package/src/shell/SwitchControl.js +2 -20
  226. package/src/shell/TimelineBar.css +81 -81
  227. package/src/shell/TimelineBar.d.ts +5 -2
  228. package/src/shell/TimelineBar.js +9 -8
  229. package/src/shell/TimelineBar.node.js +9 -8
  230. package/src/shell/TopBar.css +22 -22
  231. package/src/shell/TopBar.d.ts +5 -1
  232. package/src/shell/TopBar.js +2 -2
  233. package/src/shell/TopBar.node.js +2 -2
  234. package/src/shell/bootLoader.d.ts +4 -10
  235. package/src/shell/bootLoader.js +6 -52
  236. package/src/shell/embedded.css +18 -18
  237. package/src/shell/experience.d.ts +1 -1
  238. package/src/shell/moonFamilies.d.ts +2 -6
  239. package/src/shell/moonFamilies.js +2 -18
  240. package/src/shell/phone.css +58 -58
  241. package/src/shell/storyPanels.d.ts +2 -53
  242. package/src/shell/storyPanels.js +1 -106
  243. package/src/shell/style.css +153 -134
  244. package/src/shell/useDrawers.d.ts +3 -2
  245. package/src/shell/useDrawers.js +4 -3
  246. package/src/shell/viewerKeys.d.ts +8 -0
  247. package/src/shell/viewerKeys.js +16 -0
  248. package/src/synthetic/syntheticDefinition.js +20 -24
  249. package/src/synthetic/syntheticJourneyScene.js +3 -3
  250. package/src/synthetic/syntheticProbeDefinition.js +2 -1
  251. package/src/synthetic/syntheticViewsDefinition.d.ts +0 -3
  252. package/src/synthetic/syntheticViewsDefinition.js +10 -16
  253. package/data/moons/jupiter.json +0 -3333
  254. package/data/moons/neptune.json +0 -555
  255. package/data/moons/pluto.json +0 -205
  256. package/data/moons/saturn.json +0 -8267
  257. package/data/moons/uranus.json +0 -887
  258. package/src/app/addressNavigation.d.ts +0 -17
  259. package/src/app/addressNavigation.js +0 -16
  260. package/src/assets/bodies/jupiterMoonCatalogue.d.ts +0 -3
  261. package/src/assets/bodies/jupiterMoonCatalogue.js +0 -4
  262. package/src/assets/bodies/outerPlanetCatalogues.d.ts +0 -7
  263. package/src/assets/bodies/outerPlanetCatalogues.js +0 -8
  264. package/src/assets/bodies/swiftTuttle.d.ts +0 -12
  265. package/src/assets/bodies/swiftTuttle.js +0 -13
  266. package/src/assets/moonCatalogue.d.ts +0 -49
  267. package/src/assets/moonCatalogue.js +0 -80
  268. package/src/core/bodies/outerPlanetData.d.ts +0 -4
  269. package/src/core/bodies/outerPlanetData.js +0 -13
  270. package/src/core/bodies/swiftTuttle.d.ts +0 -46
  271. package/src/core/bodies/swiftTuttle.js +0 -106
@@ -0,0 +1,68 @@
1
+ import type { BodyId } from "../core/body.js";
2
+ import { type Provenance } from "../core/provenance.js";
3
+ import type { State } from "../core/state.js";
4
+ import type { TimeBounds } from "../core/trajectory.js";
5
+ import type { BodyCatalogue } from "../assets/catalogue.js";
6
+ import type { ExperienceDefinition } from "../app/experienceDefinition.js";
7
+ type BodySetLayer = NonNullable<ExperienceDefinition["bodySets"]>[number];
8
+ import type { ExperienceObject } from "../shell/experience.js";
9
+ import type { BodySetInput } from "./bodySetInput.js";
10
+ import type { DataSource } from "./data.js";
11
+ import { type SceneBodySetRead } from "./sceneReads.js";
12
+ /** A validated set; its layer is built once the finished scene's centre, window and opening time are known. */
13
+ export interface PlannedBodySet {
14
+ readonly input: BodySetInput;
15
+ /** Whether the members are listed moons (positions through `data`) or made-up ones on two-body motion. */
16
+ readonly kind: "listed" | "elements";
17
+ }
18
+ /** What the finished scene tells a set. */
19
+ export interface BodySetContext {
20
+ /** The scene's bodies, in order added; the first is the scene's centre. */
21
+ readonly ids: readonly BodyId[];
22
+ readonly catalogue: BodyCatalogue;
23
+ /** The bodies that asked for an orbit line of their own (`addBody` `orbit`). */
24
+ readonly orbits: ReadonlySet<BodyId>;
25
+ readonly window: TimeBounds;
26
+ readonly startUtcMs: number;
27
+ }
28
+ /** What `installData` loads for the sets: every listed member with the planet it circles, and how far back each planet's lines reach. */
29
+ export interface BodySetLoad {
30
+ readonly moons: readonly {
31
+ readonly id: BodyId;
32
+ readonly parent: BodyId;
33
+ }[];
34
+ readonly historyMs: ReadonlyMap<BodyId, number>;
35
+ }
36
+ /** What a `Scene` has planned for its body sets. */
37
+ export declare class BodySetPlan {
38
+ #private;
39
+ readonly sets: Map<string, PlannedBodySet>;
40
+ /** `catalogue` gives the scene's catalogue as it stands; `taken` says whether the scene already holds an id (sets and members included). */
41
+ constructor(catalogue: () => BodyCatalogue, taken: (id: string) => boolean);
42
+ /** Whether `id` is a set or one of its members. */
43
+ has(id: string): boolean;
44
+ memberIds(): readonly string[];
45
+ add(input: BodySetInput): void;
46
+ centerOf(set: PlannedBodySet, first: BodyId): BodyId;
47
+ /** Checks the sets against the finished scene: the centre, the listed moons of it, its gravity, the bodies and the balance point. */
48
+ check(ctx: Pick<BodySetContext, "ids" | "catalogue" | "orbits">): void;
49
+ /** The draw layers, one per set. */
50
+ layers(ctx: BodySetContext): readonly BodySetLayer[];
51
+ /** The shell items of the members, in order: selectable, unlisted unless asked, with their own words or the set's provenance. */
52
+ objects(ctx: Pick<BodySetContext, "ids" | "catalogue">): readonly ExperienceObject[];
53
+ /** The data packages the listed members need that `data` does not provide. */
54
+ missingData(data: readonly DataSource[]): readonly string[];
55
+ /** Throws `missing-data` naming the members whose data package was not passed. */
56
+ checkData(data: readonly DataSource[]): void;
57
+ /** What `installData` loads for the sets (see `BodySetLoad`). */
58
+ load(): BodySetLoad;
59
+ /** The sets in the order added, as the public list states them. */
60
+ reads(first: BodyId): readonly SceneBodySetRead[];
61
+ /** The set a member belongs to. */
62
+ setOf(memberId: string): PlannedBodySet | undefined;
63
+ /** A member's centre-relative state: the layer's group answers, so the number is the one the viewer draws. */
64
+ stateOf(memberId: string, timeUtcMs: number, ctx: BodySetContext): State;
65
+ /** A member's position provenance as its card shows it. */
66
+ provenanceOf(memberId: string): Provenance;
67
+ }
68
+ export {};
@@ -0,0 +1,234 @@
1
+ import { createOrbTwoBodyAdapter } from "../core/twoBodyAdapter.js";
2
+ import { NotLoadedError } from "../core/planetSeries.js";
3
+ import { createEphemerisGroup } from "../core/ephemerisGroup.js";
4
+ import { createElementsGroup } from "../core/elementsGroup.js";
5
+ import { MOON_SYSTEMS } from "../core/bodies/listedMoonBodies.js";
6
+ import { listedMoon } from "../core/bodies/listedMoons.js";
7
+ import { createProvenance } from "../core/provenance.js";
8
+ import { familiesWithPalette } from "../core/bodySetFamilies.js";
9
+ import { bad, checkInput, idOf } from "./bodySetChecks.js";
10
+ import { SceneError } from "./errors.js";
11
+ import { frozenCopy } from "./frozenCopy.js";
12
+ import { frozenList } from "./sceneReads.js";
13
+ import { toUtcMs } from "./time.js";
14
+ /** The words on the orbit lines of bodies drawn elsewhere, whose lines this batch draws: kept as one planner constant. */
15
+ const EXTRA_ORBITS_PROVENANCE = { accuracy: "As each moon's own record.", notes: "Orbit lines only: each moon's own path over about one orbit, ending where it is now." };
16
+ /** What a `Scene` has planned for its body sets. */
17
+ export class BodySetPlan {
18
+ sets = 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 (sets and members included). */
22
+ constructor(catalogue, taken) {
23
+ this.#catalogue = catalogue;
24
+ this.#taken = taken;
25
+ }
26
+ /** Whether `id` is a set or one of its members. */
27
+ has(id) {
28
+ return this.sets.has(id) || this.memberIds().includes(id);
29
+ }
30
+ memberIds() {
31
+ return [...this.sets.values()].flatMap(({ input }) => input.members.map((member) => member.id));
32
+ }
33
+ add(input) {
34
+ const kind = checkInput(input);
35
+ for (const id of [input.id, ...input.members.map((member) => member.id)]) {
36
+ if (this.#taken(id) || this.#catalogue().has(id) && kind === "elements")
37
+ throw new SceneError("duplicate-id", `addBodySet("${input.id}"): "${id}" is already in the scene${this.#catalogue().has(id) ? " or the catalogue" : ""}`);
38
+ }
39
+ if (input.center !== undefined && !this.#catalogue().has(idOf(input.center)))
40
+ throw new SceneError("unknown-body", `addBodySet("${input.id}"): centre "${String(idOf(input.center))}" is not a catalogued body`);
41
+ this.sets.set(input.id, { input: frozenCopy(input), kind });
42
+ }
43
+ centerOf(set, first) {
44
+ return set.input.center === undefined ? first : idOf(set.input.center);
45
+ }
46
+ /** The gravity of a set's centre: stated, else the centre's moon system, else its catalogue record. */
47
+ #gmOf(set, center, catalogue) {
48
+ const gm = set.input.centerGmKm3S2 ?? MOON_SYSTEMS[center]?.config.centreGmKm3S2 ?? (catalogue.has(center) ? catalogue.get(center).definition.gmKm3S2 : undefined);
49
+ if (gm === undefined)
50
+ throw bad(set.input.id, `the centre "${center}" has no gravitational parameter (no moon system, no catalogue record); pass centerGmKm3S2`);
51
+ return gm;
52
+ }
53
+ /** The listed moons the set draws as dots, in member order. */
54
+ #dotsOf(set, center) {
55
+ for (const member of set.input.members) {
56
+ if (set.kind === "listed" && listedMoon(member.id).parent !== center)
57
+ throw bad(set.input.id, `member "${member.id}" is a moon of "${listedMoon(member.id).parent}", not of the centre "${center}"`);
58
+ }
59
+ return set.input.members.map((member) => member.id);
60
+ }
61
+ /** Checks the sets against the finished scene: the centre, the listed moons of it, its gravity, the bodies and the balance point. */
62
+ check(ctx) {
63
+ for (const set of this.sets.values()) {
64
+ const center = this.centerOf(set, ctx.ids[0]);
65
+ if (!ctx.ids.includes(center))
66
+ throw bad(set.input.id, `the members circle "${center}", which has not been added to the scene`);
67
+ this.#dotsOf(set, center);
68
+ this.#gmOf(set, center, ctx.catalogue);
69
+ this.#bodiesOf(set, center, ctx);
70
+ this.#balanceOf(set, center, ctx);
71
+ }
72
+ }
73
+ /** The set's bodies, checked: in the scene, circling the centre; the ones without an orbit of their own are listed moons of it. */
74
+ #bodiesOf(set, center, ctx) {
75
+ return (set.input.bodies ?? []).map(({ id: ref, family }) => {
76
+ const id = idOf(ref);
77
+ if (!ctx.ids.includes(id))
78
+ throw bad(set.input.id, `body "${id}" has not been added to the scene`);
79
+ if (ctx.catalogue.get(id).definition.parentId !== center)
80
+ throw bad(set.input.id, `body "${id}" does not circle the centre "${center}"`);
81
+ const own = ctx.orbits.has(id);
82
+ if (!own && (listedMoon(id) === undefined || MOON_SYSTEMS[center] === undefined))
83
+ throw bad(set.input.id, `body "${id}" has no orbit of its own (addBody orbit) and is not a listed moon of "${center}", so this batch cannot draw its line`);
84
+ return { id, family, own };
85
+ });
86
+ }
87
+ /** The balance point: stated (its body is a member or a body without an orbit of its own), else the centre's moon system's when its body is one of those. */
88
+ #balanceOf(set, center, ctx) {
89
+ const drawn = new Set([...set.input.members.map((member) => member.id), ...this.#bodiesOf(set, center, ctx).filter((body) => !body.own).map((body) => body.id)]);
90
+ const stated = set.input.balancePoint;
91
+ if (stated !== undefined) {
92
+ const body = idOf(stated.body);
93
+ if (!drawn.has(body))
94
+ throw bad(set.input.id, `balancePoint.body "${body}" must be a member or a body without an orbit of its own`);
95
+ return { body, gmKm3S2: stated.gmKm3S2 };
96
+ }
97
+ const own = MOON_SYSTEMS[center]?.config.balancePoint;
98
+ return own !== undefined && drawn.has(own.body) ? own : undefined;
99
+ }
100
+ /** The draw layers, one per set. */
101
+ layers(ctx) {
102
+ return [...this.sets.values()].map((set) => this.#layer(set, ctx));
103
+ }
104
+ #layer(set, ctx) {
105
+ const { input } = set;
106
+ const center = this.centerOf(set, ctx.ids[0]);
107
+ const gm = this.#gmOf(set, center, ctx.catalogue);
108
+ const palette = familiesWithPalette(input.families);
109
+ const families = palette.map((family, index) => ({ ...family, color: input.families[index].color ?? family.color, ...(input.families[index].brightness === undefined ? {} : { brightness: input.families[index].brightness }) }));
110
+ const bodies = this.#bodiesOf(set, center, ctx);
111
+ const extra = bodies.filter((body) => !body.own);
112
+ const members = input.members.map((member) => {
113
+ const moon = listedMoon(member.id);
114
+ return { id: member.id, label: member.label ?? moon.label, radiusKm: member.radiusKm ?? moon.meanRadiusKm, family: member.family };
115
+ });
116
+ const balance = this.#balanceOf(set, center, ctx);
117
+ const group = set.kind === "listed"
118
+ ? createEphemerisGroup({ id: input.id, center, ephemeris: MOON_SYSTEMS[center].ephemeris, members: members.map(({ id }) => id), bounds: ctx.window, provenance: input.provenance })
119
+ : this.#elementsGroup(set, center, gm, ctx, input.id, input.provenance, input.members);
120
+ return {
121
+ id: input.id,
122
+ group,
123
+ members,
124
+ families,
125
+ bodyFamilies: Object.fromEntries(bodies.map(({ id, family }) => [id, family])),
126
+ ...(extra.length === 0 ? {} : { extraOrbits: {
127
+ group: createEphemerisGroup({ id: `${input.id}-orbits`, center, ephemeris: MOON_SYSTEMS[center].ephemeris, members: extra.map(({ id }) => id), bounds: ctx.window, provenance: createProvenance({ sourceType: "ephemeris", sources: input.provenance.sources, ...EXTRA_ORBITS_PROVENANCE }) }),
128
+ families: extra.map(({ family }) => family),
129
+ } }),
130
+ centreGmKm3S2: gm,
131
+ ...(balance === undefined ? {} : { balancePoint: balance }),
132
+ };
133
+ }
134
+ #elementsGroup(set, center, gm, ctx, id, provenance, members) {
135
+ try {
136
+ return createElementsGroup({
137
+ id,
138
+ center,
139
+ bounds: ctx.window,
140
+ provenance,
141
+ members: members.map((member) => {
142
+ const elements = member.elements;
143
+ return { id: member.id, elements, epochUtcMs: elements.time === undefined ? ctx.startUtcMs : toUtcMs(elements.time, `addBodySet("${id}") member "${member.id}" elements.time`), plane: elements.plane ?? "EQJ" };
144
+ }),
145
+ }, createOrbTwoBodyAdapter([{ id: center, gmKm3S2: gm }]));
146
+ }
147
+ catch (error) {
148
+ if (error instanceof SceneError)
149
+ throw error;
150
+ throw bad(set.input.id, error instanceof Error ? error.message : String(error));
151
+ }
152
+ }
153
+ /** The shell items of the members, in order: selectable, unlisted unless asked, with their own words or the set's provenance. */
154
+ objects(ctx) {
155
+ return [...this.sets.values()].flatMap((set) => {
156
+ const { input } = set;
157
+ const center = this.centerOf(set, ctx.ids[0]);
158
+ const centreLabel = ctx.catalogue.has(center) ? ctx.catalogue.get(center).definition.label : center;
159
+ return input.members.map((member) => {
160
+ const family = input.families.find(({ id }) => id === member.family);
161
+ return {
162
+ id: member.id,
163
+ label: member.label ?? listedMoon(member.id).label,
164
+ listed: member.listed ?? false,
165
+ description: member.description ?? `A member of ${family.label} about ${centreLabel}.`,
166
+ ...(member.facts === undefined ? {} : { facts: member.facts.map(({ label, value }) => Object.freeze({ label, value })) }),
167
+ provenance: member.provenance ?? input.provenance,
168
+ ...(member.knownLimitations === undefined ? {} : { knownLimitations: member.knownLimitations }),
169
+ };
170
+ });
171
+ });
172
+ }
173
+ /** The data packages the listed members need that `data` does not provide. */
174
+ missingData(data) {
175
+ const have = new Set(data.flatMap((source) => source.provides));
176
+ const named = new Set(data.map((source) => source.name));
177
+ return [...new Set(this.#listed().filter(({ id, requires }) => !have.has(id) && !named.has(requires)).map(({ requires }) => requires))];
178
+ }
179
+ #listed() {
180
+ return [...this.sets.values()].filter(({ kind }) => kind === "listed").flatMap(({ input }) => input.members.map((member) => ({ id: member.id, requires: listedMoon(member.id).dataPackage })));
181
+ }
182
+ /** Throws `missing-data` naming the members whose data package was not passed. */
183
+ checkData(data) {
184
+ const missing = this.missingData(data);
185
+ if (missing.length === 0)
186
+ return;
187
+ const names = this.#listed().filter(({ requires }) => missing.includes(requires)).map(({ id }) => id);
188
+ throw new SceneError("missing-data", `${names.join(", ")} needs the ${missing.join(", ")} package: install it and pass it as mount(element, scene, { data: [...] })`);
189
+ }
190
+ /** What `installData` loads for the sets (see `BodySetLoad`). */
191
+ load() {
192
+ const listed = [...this.sets.values()].filter(({ kind }) => kind === "listed");
193
+ const historyMs = new Map();
194
+ for (const { input } of listed) {
195
+ const parent = listedMoon(input.members[0].id).parent;
196
+ historyMs.set(parent, Math.max(historyMs.get(parent) ?? 0, input.orbitHistoryMs ?? 0));
197
+ }
198
+ return { moons: listed.flatMap(({ input }) => input.members.map(({ id }) => ({ id, parent: listedMoon(id).parent }))), historyMs };
199
+ }
200
+ /** The sets in the order added, as the public list states them. */
201
+ reads(first) {
202
+ return frozenList([...this.sets.values()].map(({ input }) => ({
203
+ id: input.id,
204
+ center: this.centerOf({ input, kind: "listed" }, first),
205
+ count: input.members.length,
206
+ families: Object.freeze(input.families.map(({ id }) => id)),
207
+ })));
208
+ }
209
+ /** The set a member belongs to. */
210
+ setOf(memberId) {
211
+ return [...this.sets.values()].find(({ input }) => input.members.some((member) => member.id === memberId));
212
+ }
213
+ /** A member's centre-relative state: the layer's group answers, so the number is the one the viewer draws. */
214
+ stateOf(memberId, timeUtcMs, ctx) {
215
+ const set = this.setOf(memberId);
216
+ const { window } = ctx;
217
+ if (timeUtcMs < window.startUtcMs || timeUtcMs > window.endUtcMs)
218
+ throw new SceneError("bad-time", `stateOf("${memberId}"): ${new Date(timeUtcMs).toISOString()} is outside the scene's window (${new Date(window.startUtcMs).toISOString()} to ${new Date(window.endUtcMs).toISOString()})`);
219
+ const layer = this.#layer(set, ctx);
220
+ try {
221
+ return layer.group.memberStateAt(layer.group.members.indexOf(memberId), timeUtcMs);
222
+ }
223
+ catch (error) {
224
+ if (error instanceof NotLoadedError)
225
+ throw new SceneError("missing-data", `stateOf("${memberId}"): its data is not loaded yet; await scene.load({ data }) first (or mount the scene and await ready)`);
226
+ throw error;
227
+ }
228
+ }
229
+ /** A member's position provenance as its card shows it. */
230
+ provenanceOf(memberId) {
231
+ const set = this.setOf(memberId);
232
+ return set.input.members.find((member) => member.id === memberId).provenance ?? set.input.provenance;
233
+ }
234
+ }
@@ -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
+ }