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.
Files changed (287) hide show
  1. package/CHANGELOG.md +189 -0
  2. package/README.md +202 -38
  3. package/data/ephemerides/planets/planets.json +1 -1
  4. package/package.json +5 -4
  5. package/src/api/AstraeusScene.d.ts +21 -5
  6. package/src/api/AstraeusScene.js +34 -10
  7. package/src/api/AstraeusScene.node.js +34 -10
  8. package/src/api/assembleScene.d.ts +36 -0
  9. package/src/api/assembleScene.js +175 -0
  10. package/src/api/bodySetChecks.d.ts +10 -0
  11. package/src/api/bodySetChecks.js +117 -0
  12. package/src/api/bodySetInput.d.ts +81 -0
  13. package/src/api/bodySetInput.js +1 -0
  14. package/src/api/containingBlock.d.ts +6 -0
  15. package/src/api/containingBlock.js +16 -0
  16. package/src/api/data.d.ts +17 -5
  17. package/src/api/data.js +28 -10
  18. package/src/api/definitionOf.d.ts +16 -0
  19. package/src/api/definitionOf.js +20 -0
  20. package/src/api/errors.d.ts +63 -1
  21. package/src/api/frozenCopy.d.ts +6 -0
  22. package/src/api/frozenCopy.js +26 -0
  23. package/src/api/group.d.ts +8 -2
  24. package/src/api/group.js +24 -5
  25. package/src/api/index.d.ts +18 -7
  26. package/src/api/index.js +2 -2
  27. package/src/api/index.node.js +2 -2
  28. package/src/api/listeners.d.ts +5 -0
  29. package/src/api/listeners.js +25 -0
  30. package/src/api/look.d.ts +47 -0
  31. package/src/api/look.js +1 -0
  32. package/src/api/lookInput.d.ts +3 -0
  33. package/src/api/lookInput.js +41 -0
  34. package/src/api/moonPanelInput.d.ts +60 -0
  35. package/src/api/moonPanelInput.js +1 -0
  36. package/src/api/mount.d.ts +9 -19
  37. package/src/api/mount.js +27 -13
  38. package/src/api/mount.node.js +27 -13
  39. package/src/api/pathProvenance.js +1 -1
  40. package/src/api/pickerInput.d.ts +25 -0
  41. package/src/api/pickerInput.js +1 -0
  42. package/src/api/planBodies.d.ts +72 -0
  43. package/src/api/planBodies.js +300 -0
  44. package/src/api/planBodySets.d.ts +68 -0
  45. package/src/api/planBodySets.js +234 -0
  46. package/src/api/planCamera.d.ts +83 -0
  47. package/src/api/planCamera.js +184 -0
  48. package/src/api/planGroups.d.ts +36 -0
  49. package/src/api/planGroups.js +103 -0
  50. package/src/api/planMoonPanel.d.ts +19 -0
  51. package/src/api/planMoonPanel.js +104 -0
  52. package/src/api/planPaths.d.ts +40 -0
  53. package/src/api/planPaths.js +212 -0
  54. package/src/api/planPicker.d.ts +12 -0
  55. package/src/api/planPicker.js +40 -0
  56. package/src/api/planPlaces.d.ts +16 -0
  57. package/src/api/planPlaces.js +99 -0
  58. package/src/api/planStory.d.ts +26 -0
  59. package/src/api/planStory.js +66 -0
  60. package/src/api/planTimeline.d.ts +27 -0
  61. package/src/api/planTimeline.js +68 -0
  62. package/src/api/planViews.d.ts +25 -0
  63. package/src/api/planViews.js +35 -0
  64. package/src/api/prepared.js +4 -1
  65. package/src/api/renamedInputs.d.ts +15 -0
  66. package/src/api/renamedInputs.js +39 -0
  67. package/src/api/scene.d.ts +162 -68
  68. package/src/api/scene.js +247 -793
  69. package/src/api/sceneFreeze.d.ts +4 -0
  70. package/src/api/sceneFreeze.js +10 -0
  71. package/src/api/sceneReads.d.ts +171 -0
  72. package/src/api/sceneReads.js +6 -0
  73. package/src/api/story.d.ts +49 -19
  74. package/src/api/story.js +54 -22
  75. package/src/api/sunOrbit.js +9 -11
  76. package/src/api/time.d.ts +2 -1
  77. package/src/api/time.js +2 -1
  78. package/src/api/viewerCamera.d.ts +22 -0
  79. package/src/api/viewerCamera.js +84 -0
  80. package/src/api/viewerClock.d.ts +30 -0
  81. package/src/api/viewerClock.js +85 -0
  82. package/src/api/viewerFirstDraw.d.ts +14 -0
  83. package/src/api/viewerFirstDraw.js +26 -0
  84. package/src/api/viewerHandle.d.ts +85 -0
  85. package/src/api/viewerHandle.js +32 -0
  86. package/src/api/viewerLink.d.ts +88 -15
  87. package/src/api/viewerLink.js +117 -75
  88. package/src/api/viewerLooks.d.ts +19 -0
  89. package/src/api/viewerLooks.js +37 -0
  90. package/src/api/viewerPicker.d.ts +22 -0
  91. package/src/api/viewerPicker.js +49 -0
  92. package/src/api/viewerSelection.d.ts +30 -0
  93. package/src/api/viewerSelection.js +46 -0
  94. package/src/api/viewerViews.d.ts +10 -0
  95. package/src/api/viewerViews.js +18 -0
  96. package/src/api/viewerZones.d.ts +20 -0
  97. package/src/api/viewerZones.js +47 -0
  98. package/src/api/views.d.ts +7 -6
  99. package/src/api/views.js +12 -6
  100. package/src/app/App.d.ts +5 -3
  101. package/src/app/App.js +211 -82
  102. package/src/app/App.node.js +211 -82
  103. package/src/app/AstraeusScene.d.ts +18 -2
  104. package/src/app/AstraeusScene.js +4 -4
  105. package/src/app/BodyView.d.ts +4 -1
  106. package/src/app/BodyView.js +2 -2
  107. package/src/app/CameraController.d.ts +6 -0
  108. package/src/app/DeveloperSettings.d.ts +1 -4
  109. package/src/app/DeveloperSettings.js +6 -10
  110. package/src/app/FeatureMarkers.d.ts +4 -3
  111. package/src/app/FeatureMarkers.js +8 -13
  112. package/src/app/FrameRateSection.js +2 -1
  113. package/src/app/OrbitSetView.js +1 -1
  114. package/src/app/SettingControls.d.ts +11 -3
  115. package/src/app/SettingControls.js +10 -2
  116. package/src/app/SkyView.d.ts +3 -10
  117. package/src/app/SkyView.js +6 -28
  118. package/src/app/address.d.ts +16 -0
  119. package/src/app/address.js +31 -0
  120. package/src/app/bodyDraw.d.ts +10 -7
  121. package/src/app/bodyDraw.js +12 -32
  122. package/src/app/bodyMetrics.js +2 -2
  123. package/src/app/bodySet.d.ts +4 -20
  124. package/src/app/bodySet.js +5 -16
  125. package/src/app/debugReadout.js +1 -1
  126. package/src/app/displaySwitches.d.ts +4 -0
  127. package/src/app/displaySwitches.js +6 -0
  128. package/src/app/experienceDefinition.d.ts +11 -23
  129. package/src/app/listSwitch.d.ts +8 -14
  130. package/src/app/listSwitch.js +3 -10
  131. package/src/app/liveLook.d.ts +39 -0
  132. package/src/app/liveLook.js +66 -0
  133. package/src/app/look.d.ts +36 -0
  134. package/src/app/look.js +61 -0
  135. package/src/app/mission.d.ts +1 -1
  136. package/src/app/mission.js +1 -1
  137. package/src/app/openClock.d.ts +3 -2
  138. package/src/app/openClock.js +3 -3
  139. package/src/app/sceneCamera.d.ts +2 -0
  140. package/src/app/sceneCamera.js +11 -1
  141. package/src/app/sceneFrame.d.ts +4 -4
  142. package/src/app/sceneFrame.js +13 -8
  143. package/src/app/sceneHooks.js +3 -2
  144. package/src/app/style.css +114 -139
  145. package/src/app/trackedMetrics.d.ts +10 -3
  146. package/src/app/trackedMetrics.js +22 -11
  147. package/src/app/viewLink.d.ts +10 -32
  148. package/src/app/viewLink.js +10 -49
  149. package/src/app/viewerPort.d.ts +52 -0
  150. package/src/app/views.d.ts +3 -0
  151. package/src/assets/bodies/galileanMoons.js +1 -2
  152. package/src/assets/bodies/io.js +2 -2
  153. package/src/assets/bodies/listedMoons.d.ts +1 -1
  154. package/src/assets/bodies/listedMoons.js +2 -3
  155. package/src/assets/bodies/planetSystemMaps.js +2 -3
  156. package/src/assets/bodies/venus.js +2 -6
  157. package/src/assets/catalogue.js +1 -2
  158. package/src/assets/licence.d.ts +3 -3
  159. package/src/assets/licence.js +3 -3
  160. package/src/assets/pictures.d.ts +15 -12
  161. package/src/assets/pictures.js +24 -20
  162. package/src/assets/sky.d.ts +6 -5
  163. package/src/assets/sky.js +6 -9
  164. package/src/assets/visual.d.ts +4 -0
  165. package/src/core/astronomyAdapter.d.ts +1 -1
  166. package/src/core/astronomyAdapter.js +3 -3
  167. package/src/core/bodies/index.d.ts +0 -4
  168. package/src/core/bodies/index.js +14 -18
  169. package/src/core/bodies/jupiter.js +1 -1
  170. package/src/core/bodies/jupiterData.d.ts +0 -1
  171. package/src/core/bodies/jupiterData.js +2 -5
  172. package/src/core/bodies/mars.js +1 -1
  173. package/src/core/bodies/mercury.js +1 -1
  174. package/src/core/bodies/moonSystem.d.ts +1 -1
  175. package/src/core/bodies/moonSystem.js +102 -55
  176. package/src/core/bodies/outerPlanetRingData.js +2 -2
  177. package/src/core/bodies/outerPlanets.d.ts +2 -3
  178. package/src/core/bodies/outerPlanets.js +4 -13
  179. package/src/core/bodies/planetMoons.d.ts +0 -2
  180. package/src/core/bodies/planetMoons.js +1 -18
  181. package/src/core/bodies/planetRecords.d.ts +8 -2
  182. package/src/core/bodies/planetRecords.js +13 -5
  183. package/src/core/bodies/planetTrajectory.d.ts +21 -4
  184. package/src/core/bodies/planetTrajectory.js +29 -5
  185. package/src/core/bodies/venus.js +1 -1
  186. package/src/core/bodySetFamilies.d.ts +20 -0
  187. package/src/core/bodySetFamilies.js +14 -0
  188. package/src/core/chebyshevEphemeris.js +1 -1
  189. package/src/core/elementsBody.d.ts +8 -4
  190. package/src/core/elementsBody.js +32 -11
  191. package/src/core/elementsGroup.d.ts +27 -0
  192. package/src/core/elementsGroup.js +85 -0
  193. package/src/core/events.d.ts +2 -0
  194. package/src/core/events.js +2 -0
  195. package/src/core/illumination.js +1 -1
  196. package/src/core/listedOrbitGroup.d.ts +2 -0
  197. package/src/core/listedOrbitGroup.js +11 -7
  198. package/src/core/moonListText.d.ts +6 -0
  199. package/src/core/moonListText.js +19 -0
  200. package/src/core/moonTrajectory.js +1 -1
  201. package/src/core/pacing.d.ts +38 -3
  202. package/src/core/pacing.js +55 -4
  203. package/src/core/planetModels.d.ts +1 -1
  204. package/src/core/planetModels.js +3 -3
  205. package/src/core/planetSeries.d.ts +10 -2
  206. package/src/core/planetSeries.js +17 -3
  207. package/src/core/pointGroup.js +1 -1
  208. package/src/core/provenance.d.ts +2 -1
  209. package/src/core/provenance.js +2 -2
  210. package/src/core/referenceCenters.js +5 -5
  211. package/src/core/sampledTrajectory.js +1 -1
  212. package/src/core/scalePolicy.d.ts +1 -0
  213. package/src/core/startView.d.ts +19 -0
  214. package/src/core/startView.js +28 -0
  215. package/src/core/state.d.ts +6 -2
  216. package/src/core/state.js +3 -3
  217. package/src/core/storyPanels.d.ts +63 -0
  218. package/src/core/storyPanels.js +111 -0
  219. package/src/core/sunCentredSources.d.ts +4 -0
  220. package/src/core/sunCentredSources.js +9 -2
  221. package/src/core/timeInput.d.ts +4 -0
  222. package/src/core/timeInput.js +4 -0
  223. package/src/shell/AstraeusShell.d.ts +18 -2
  224. package/src/shell/AstraeusShell.js +53 -14
  225. package/src/shell/AstraeusShell.node.js +53 -14
  226. package/src/shell/Collapsible.d.ts +4 -3
  227. package/src/shell/Collapsible.js +5 -5
  228. package/src/shell/ControlsDrawer.d.ts +1 -1
  229. package/src/shell/ControlsDrawer.js +3 -1
  230. package/src/shell/DisplaySwitches.js +2 -1
  231. package/src/shell/InfoPanel.d.ts +3 -1
  232. package/src/shell/InfoPanel.js +5 -4
  233. package/src/shell/MoonFamilyPanel.js +1 -1
  234. package/src/shell/ObjectControls.d.ts +3 -1
  235. package/src/shell/ObjectControls.js +2 -2
  236. package/src/shell/Sources.d.ts +5 -3
  237. package/src/shell/Sources.js +5 -5
  238. package/src/shell/StoryPanelView.d.ts +4 -3
  239. package/src/shell/StoryPanelView.js +8 -6
  240. package/src/shell/SwitchControl.d.ts +5 -11
  241. package/src/shell/SwitchControl.js +2 -20
  242. package/src/shell/TimelineBar.css +81 -81
  243. package/src/shell/TimelineBar.d.ts +5 -2
  244. package/src/shell/TimelineBar.js +9 -8
  245. package/src/shell/TimelineBar.node.js +9 -8
  246. package/src/shell/TopBar.css +22 -22
  247. package/src/shell/TopBar.d.ts +5 -1
  248. package/src/shell/TopBar.js +2 -2
  249. package/src/shell/TopBar.node.js +2 -2
  250. package/src/shell/bootLoader.d.ts +4 -10
  251. package/src/shell/bootLoader.js +6 -52
  252. package/src/shell/embedded.css +18 -18
  253. package/src/shell/experience.d.ts +1 -1
  254. package/src/shell/moonFamilies.d.ts +2 -6
  255. package/src/shell/moonFamilies.js +2 -18
  256. package/src/shell/phone.css +58 -58
  257. package/src/shell/storyPanels.d.ts +2 -53
  258. package/src/shell/storyPanels.js +1 -106
  259. package/src/shell/style.css +153 -134
  260. package/src/shell/useDrawers.d.ts +3 -2
  261. package/src/shell/useDrawers.js +4 -3
  262. package/src/shell/viewerKeys.d.ts +8 -0
  263. package/src/shell/viewerKeys.js +16 -0
  264. package/src/synthetic/syntheticDefinition.js +20 -24
  265. package/src/synthetic/syntheticJourneyScene.js +3 -3
  266. package/src/synthetic/syntheticProbeDefinition.js +2 -1
  267. package/src/synthetic/syntheticViewsDefinition.d.ts +0 -3
  268. package/src/synthetic/syntheticViewsDefinition.js +10 -16
  269. package/data/moons/jupiter.json +0 -3333
  270. package/data/moons/neptune.json +0 -555
  271. package/data/moons/pluto.json +0 -205
  272. package/data/moons/saturn.json +0 -8267
  273. package/data/moons/uranus.json +0 -887
  274. package/src/app/addressNavigation.d.ts +0 -17
  275. package/src/app/addressNavigation.js +0 -16
  276. package/src/assets/bodies/jupiterMoonCatalogue.d.ts +0 -3
  277. package/src/assets/bodies/jupiterMoonCatalogue.js +0 -4
  278. package/src/assets/bodies/outerPlanetCatalogues.d.ts +0 -7
  279. package/src/assets/bodies/outerPlanetCatalogues.js +0 -8
  280. package/src/assets/bodies/swiftTuttle.d.ts +0 -12
  281. package/src/assets/bodies/swiftTuttle.js +0 -13
  282. package/src/assets/moonCatalogue.d.ts +0 -49
  283. package/src/assets/moonCatalogue.js +0 -80
  284. package/src/core/bodies/outerPlanetData.d.ts +0 -4
  285. package/src/core/bodies/outerPlanetData.js +0 -13
  286. package/src/core/bodies/swiftTuttle.d.ts +0 -46
  287. package/src/core/bodies/swiftTuttle.js +0 -106
@@ -0,0 +1,300 @@
1
+ import { readableScale, solarSystemScale, trueScale } from "../core/scalePolicy.js";
2
+ import { catalogue as builtInCatalogue, extendCatalogue, extendCatalogueWithMoons, rootBodyId } from "../assets/catalogue.js";
3
+ import { buildElementsBody, ElementsBodyError, parseElementsBodyRecord } from "../core/elementsBody.js";
4
+ import { catalogueItem } from "../app/catalogueItem.js";
5
+ import { circlesTheSun, sunOrbitIdOf, sunOrbitLayer } from "./sunOrbit.js";
6
+ import { listedMoonBodyOf } from "../core/bodies/listedMoonBodies.js";
7
+ import { readyMade } from "./bodies.js";
8
+ import { SceneError } from "./errors.js";
9
+ import { rejectRenamed } from "./renamedInputs.js";
10
+ import { checkLabelReach } from "./planPaths.js";
11
+ import { createProvenance } from "../core/provenance.js";
12
+ import { frozenCopy } from "./frozenCopy.js";
13
+ import { readoutsOf } from "./planPaths.js";
14
+ import { frozenList } from "./sceneReads.js";
15
+ /**
16
+ * The orbit line of a catalogued moon, by one rule: one lap of the period its catalogue definition carries (`orbitPeriodDays`, read once from the record or mean
17
+ * elements), drawn about its parent. Undefined where the definition gives no period. A moon closes its loop (Io's look) unless its definition says its line fades (the Moon's, as before).
18
+ */
19
+ function moonOrbitPath(catalogue, id, lap) {
20
+ if (!catalogue.has(id))
21
+ return undefined;
22
+ const { orbitPeriodDays, orbitLineFades, parentId } = catalogue.get(id).definition;
23
+ const days = lap?.lapDays ?? orbitPeriodDays;
24
+ if (days === undefined || parentId === undefined)
25
+ return undefined;
26
+ return { spanMs: days * 86_400_000, ...((lap?.fades ?? orbitLineFades) === true ? {} : { look: { endFadeOn: false } }) };
27
+ }
28
+ /** Whether `orbit` is the lap form `{ lapDays, fades? }`. */
29
+ const isLap = (orbit) => typeof orbit === "object" && orbit !== null;
30
+ /** Checks the card facts, extra sources, label priority, menu flag and lap form given to `addBody`. */
31
+ function checkBodyCard(id, options) {
32
+ const bad = (message) => new SceneError("bad-body", `addBody("${id}"): ${message}`);
33
+ if (options.listed !== undefined && typeof options.listed !== "boolean")
34
+ throw bad("listed must be true or false");
35
+ const { facts, sources, labelPriority, orbit } = options;
36
+ if (facts !== undefined && !(Array.isArray(facts) && facts.every((fact) => typeof fact?.label === "string" && fact.label !== "" && typeof fact.value === "string" && fact.value !== "")))
37
+ throw bad("facts must be a list of { label, value } with both texts non-empty");
38
+ if (sources !== undefined && !(Array.isArray(sources) && sources.every((source) => typeof source === "string" && source !== "")))
39
+ throw bad("sources must be a list of non-empty texts");
40
+ if (labelPriority !== undefined && !(typeof labelPriority === "number" && Number.isFinite(labelPriority)))
41
+ throw bad(`labelPriority ${String(labelPriority)} must be a finite number`);
42
+ checkOrbitOption(bad, orbit);
43
+ }
44
+ /** Checks the `orbit` option: true, false or the lap form. */
45
+ function checkOrbitOption(bad, orbit) {
46
+ if (orbit !== undefined && typeof orbit !== "boolean" && !isLap(orbit))
47
+ throw bad("orbit must be true, false or { lapDays, fades? }");
48
+ if (isLap(orbit)) {
49
+ if (!(typeof orbit.lapDays === "number" && Number.isFinite(orbit.lapDays) && orbit.lapDays > 0))
50
+ throw bad(`orbit.lapDays ${String(orbit.lapDays)} must be a positive finite number of days`);
51
+ if (orbit.fades !== undefined && typeof orbit.fades !== "boolean")
52
+ throw bad("orbit.fades must be true or false");
53
+ }
54
+ }
55
+ /** The enlargements the scene asked for, as the engine's per-body overrides. */
56
+ function visualOverridesEntry(shape) {
57
+ const overrides = {};
58
+ for (const [id, { enlarge }] of shape)
59
+ if (enlarge !== undefined)
60
+ overrides[id] = { exaggeration: enlarge };
61
+ return Object.keys(overrides).length === 0 ? {} : { visualOverrides: overrides };
62
+ }
63
+ /** Parses an elements record, naming the field a mistake is in. */
64
+ function parseRecord(record) {
65
+ try {
66
+ return parseElementsBodyRecord(record, "addBodyFromElements");
67
+ }
68
+ catch (error) {
69
+ if (error instanceof ElementsBodyError)
70
+ throw new SceneError("bad-element", error.message);
71
+ throw error;
72
+ }
73
+ }
74
+ /** Checks the colour, known limits and label reach given to `addBody`. */
75
+ function checkBodyLook(id, options) {
76
+ if (options.labelReachEarthRadii !== undefined)
77
+ checkLabelReach(options.labelReachEarthRadii, new SceneError("bad-body", `addBody("${id}"): labelReachEarthRadii ${String(options.labelReachEarthRadii)} must be a positive finite number`));
78
+ if (options.enlarge !== undefined && !(typeof options.enlarge === "number" && Number.isFinite(options.enlarge) && options.enlarge >= 1))
79
+ throw new SceneError("bad-body", `addBody("${id}"): enlarge ${String(options.enlarge)} must be a number of at least 1`);
80
+ if (options.showLabel !== undefined && typeof options.showLabel !== "boolean")
81
+ throw new SceneError("bad-body", `addBody("${id}"): showLabel must be true or false`);
82
+ if (options.color !== undefined && !(typeof options.color === "string" && /^#[0-9a-fA-F]{3}([0-9a-fA-F]{3})?$/.test(options.color)))
83
+ throw new SceneError("bad-body", `addBody("${id}"): color "${String(options.color)}" is not a hex colour such as "#9fd8ff"`);
84
+ const limits = options.knownLimitations;
85
+ if (limits !== undefined && !(Array.isArray(limits) && limits.every((line) => typeof line === "string" && line !== "")))
86
+ throw new SceneError("bad-body", `addBody("${id}"): knownLimitations must be a list of non-empty texts`);
87
+ }
88
+ /** A provenance with more sources after its own. */
89
+ const withSources = (provenance, sources) => createProvenance({ ...provenance, sources: [...provenance.sources, ...sources] });
90
+ /** What a `Scene` has planned for its bodies: the bodies, their options and the scene's catalogue. */
91
+ export class BodyPlan {
92
+ bodies = new Map();
93
+ orbits = new Set();
94
+ own = new Map();
95
+ labelReaches = new Map();
96
+ shape = new Map();
97
+ notes = new Map();
98
+ readouts = new Map();
99
+ laps = new Map();
100
+ cards = new Map();
101
+ looks = new Map();
102
+ catalogue = builtInCatalogue;
103
+ #taken;
104
+ #firstBody;
105
+ /** `taken` says whether the scene already holds an id; `firstBody` runs when the scene's first body arrives (it is a built-in one). */
106
+ constructor(taken, firstBody) {
107
+ this.#taken = taken;
108
+ this.#firstBody = firstBody;
109
+ }
110
+ addBody(body, input) {
111
+ const options = frozenCopy(input);
112
+ const id = typeof body === "string" ? body : body.id;
113
+ const before = this.catalogue;
114
+ this.#addListedMoon(id);
115
+ try {
116
+ this.#register("addBody", id, typeof body === "string" ? readyMade(id) ?? { id, label: this.catalogue.has(id) ? this.catalogue.get(id).definition.label : id } : body, options);
117
+ }
118
+ catch (error) {
119
+ this.catalogue = before;
120
+ throw error;
121
+ }
122
+ }
123
+ addFromElements(input, inputOptions) {
124
+ const record = frozenCopy(input);
125
+ const options = frozenCopy(inputOptions);
126
+ if (record?.id === "auto")
127
+ throw new SceneError("bad-element", `addBodyFromElements("auto"): "auto" is reserved (it is lineFixedTo's automatic choice) and cannot be a body id`);
128
+ rejectRenamed("ElementsBodyRecord", record, "addBodyFromElements");
129
+ rejectRenamed("ElementsAccuracy", record?.accuracy, "addBodyFromElements: accuracy");
130
+ const parsed = parseRecord(record);
131
+ if (this.#taken(parsed.id) || this.catalogue.has(parsed.id))
132
+ throw new SceneError("duplicate-id", `addBodyFromElements("${parsed.id}"): that id is already in the scene or the catalogue`);
133
+ const root = builtInCatalogue.get(rootBodyId()).definition;
134
+ const before = this.catalogue;
135
+ this.catalogue = extendCatalogue(before, [parsed]);
136
+ try {
137
+ this.#register("addBodyFromElements", parsed.id, { id: parsed.id, label: parsed.label }, options);
138
+ }
139
+ catch (error) {
140
+ this.catalogue = before;
141
+ throw error;
142
+ }
143
+ this.own.set(parsed.id, buildElementsBody(parsed, { id: root.id, gmKm3S2: root.gmKm3S2 }).sampling);
144
+ }
145
+ /** A moon in the listed-moon table that the built-in catalogue does not define by hand is defined now, by the one rule, and joins this scene's catalogue only (an unused moon costs nothing). */
146
+ #addListedMoon(id) {
147
+ if (this.catalogue.has(id))
148
+ return;
149
+ const moon = listedMoonBodyOf(id);
150
+ if (moon !== undefined && this.catalogue.has(moon.definition.parentId))
151
+ this.catalogue = extendCatalogueWithMoons(this.catalogue, [moon]);
152
+ }
153
+ /** Refuses an `orbit` the engine cannot draw: `true` needs a period about a parent or a Sun orbit; the lap form needs a parent that is not the Sun. */
154
+ #checkOrbit(call, id, options) {
155
+ if (options.orbit === true && moonOrbitPath(this.catalogue, id) === undefined && !(circlesTheSun(this.catalogue, id)))
156
+ throw new SceneError("no-orbit", `${call}("${id}", { orbit: true }): the engine draws the orbit line of any catalogued moon whose data give a period about its planet and of any body that circles the Sun (every planet: its own source over a full turn where the source covers one, else the two-body ellipse osculating at the opening time)`);
157
+ const lap = isLap(options.orbit) ? options.orbit : undefined;
158
+ if (lap !== undefined && this.catalogue.has(id) && (this.catalogue.get(id).definition.parentId === undefined || circlesTheSun(this.catalogue, id)))
159
+ throw new SceneError("no-orbit", `${call}("${id}", { orbit: { lapDays } }): the lap form draws a moon's line about its parent; "${id}" has no parent in the catalogue or circles the Sun (use orbit: true)`);
160
+ }
161
+ /** Keeps what `addBody` asked for, option by option. */
162
+ #remember(call, id, options) {
163
+ if (options.readouts !== undefined)
164
+ this.readouts.set(id, readoutsOf(id, options.readouts, call));
165
+ if (options.labelReachEarthRadii !== undefined)
166
+ this.labelReaches.set(id, options.labelReachEarthRadii);
167
+ const lap = isLap(options.orbit) ? options.orbit : undefined;
168
+ if (options.orbit === true || lap !== undefined)
169
+ this.orbits.add(id);
170
+ if (lap !== undefined)
171
+ this.laps.set(id, { lapDays: lap.lapDays, ...(lap.fades === undefined ? {} : { fades: lap.fades }) });
172
+ this.#rememberCard(id, options);
173
+ }
174
+ /** Keeps the card, look, shape and words of one body. */
175
+ #rememberCard(id, options) {
176
+ if (options.listed !== undefined || options.facts !== undefined || options.sources !== undefined || options.labelPriority !== undefined)
177
+ this.cards.set(id, { ...(options.listed === undefined ? {} : { listed: options.listed }), ...(options.facts === undefined ? {} : { facts: options.facts.map(({ label, value }) => Object.freeze({ label, value })) }), ...(options.sources === undefined ? {} : { sources: [...options.sources] }), ...(options.labelPriority === undefined ? {} : { labelPriority: options.labelPriority }) });
178
+ if (options.color !== undefined || options.knownLimitations !== undefined)
179
+ this.looks.set(id, { ...(options.color === undefined ? {} : { color: options.color }), ...(options.knownLimitations === undefined ? {} : { knownLimitations: options.knownLimitations }) });
180
+ if (options.enlarge !== undefined || options.showLabel !== undefined)
181
+ this.shape.set(id, { ...(options.enlarge === undefined ? {} : { enlarge: options.enlarge }), ...(options.showLabel === undefined ? {} : { showLabel: options.showLabel }) });
182
+ if (options.description !== undefined)
183
+ this.notes.set(id, options.description);
184
+ }
185
+ #register(call, id, ref, options) {
186
+ rejectRenamed("AddBodyOptions", options, `${call}("${id}")`);
187
+ checkBodyCard(id, options);
188
+ this.#checkOrbit(call, id, options);
189
+ if (!this.catalogue.has(id))
190
+ throw new SceneError("unknown-body", `${call}("${id}"): not a catalogued body (known: ${builtInCatalogue.ids().join(", ")}; any moon in the moon lists is added by its id, and \`listedMoons(planet)\` names them with the data package each needs)`);
191
+ if (this.#taken(id))
192
+ throw new SceneError("duplicate-id", `${call}("${id}"): already in the scene`);
193
+ checkBodyLook(id, options);
194
+ this.#remember(call, id, options);
195
+ this.bodies.set(id, ref);
196
+ if (this.bodies.size === 1 && builtInCatalogue.has(id))
197
+ this.#firstBody(id);
198
+ }
199
+ /** A body's position provenance as its card shows it: the catalogue's, with the sources `addBody` added after its own. */
200
+ provenanceOf(id) {
201
+ const base = this.catalogue.get(id).definition.accuracy.position;
202
+ const sources = this.cards.get(id)?.sources;
203
+ return sources === undefined ? base : withSources(base, sources);
204
+ }
205
+ /** The data packages the added bodies need that `data` does not provide. */
206
+ missingData(data) {
207
+ const have = new Set(data.flatMap((source) => source.provides));
208
+ const named = new Set(data.map((source) => source.name));
209
+ return [...new Set([...this.bodies.values()].filter((body) => body.requires !== undefined && !have.has(body.id) && !named.has(body.requires)).map((body) => body.requires))];
210
+ }
211
+ /** Throws `missing-data` naming the bodies whose data package was not passed. */
212
+ checkData(data) {
213
+ const missing = this.missingData(data);
214
+ if (missing.length === 0)
215
+ return;
216
+ const names = [...this.bodies.values()].filter((body) => body.requires !== undefined && missing.includes(body.requires)).map((body) => body.id);
217
+ throw new SceneError("missing-data", `${names.join(", ")} needs the ${missing.join(", ")} package: install it and pass it as mount(element, scene, { data: [...] })`);
218
+ }
219
+ /** The engine's own orbit loops (the Moon's and Io's) the scene asked for. */
220
+ moonPaths() {
221
+ return [...this.orbits].filter((id) => moonOrbitPath(this.catalogue, id, this.laps.get(id)) !== undefined).map((id) => {
222
+ const orbit = moonOrbitPath(this.catalogue, id, this.laps.get(id));
223
+ const parent = this.catalogue.get(id).definition.parentId;
224
+ if (parent === undefined || !this.bodies.has(parent))
225
+ throw new SceneError("no-orbit", `addBody("${id}", { orbit: true }): the orbit is drawn about ${parent}, which has not been added to the scene`);
226
+ return { body: id, ...orbit };
227
+ });
228
+ }
229
+ /** The bodies that asked for a Sun-orbit line, checked: the Sun must be in the scene and the line's id free. */
230
+ sunOrbitIds(ids) {
231
+ return [...this.orbits].filter((id) => moonOrbitPath(this.catalogue, id, this.laps.get(id)) === undefined).map((id) => {
232
+ if (!ids.includes(rootBodyId(this.catalogue)))
233
+ throw new SceneError("no-orbit", `addBody("${id}", { orbit: true }): the orbit is drawn about the Sun, which has not been added to the scene`);
234
+ if (this.#taken(sunOrbitIdOf(id)))
235
+ throw new SceneError("duplicate-id", `addBody("${id}", { orbit: true }): the orbit line's id "${sunOrbitIdOf(id)}" is already in the scene`);
236
+ return id;
237
+ });
238
+ }
239
+ /** One Sun-orbit line: one full turn from the opening time (an own body from its periapsis). Reads planet positions, so the planet series must be loaded. */
240
+ sunPath(id, openUtcMs) {
241
+ const layer = sunOrbitLayer(this.catalogue, id, openUtcMs, this.looks.get(id)?.color ?? "", this.own.get(id));
242
+ if (layer === undefined)
243
+ throw new SceneError("no-orbit", `addBody("${id}", { orbit: true }): "${id}" completes no turn within thirty years and its position and the Sun's gravity do not give a bound ellipse; add it with addBodyFromElements to draw its whole orbit`);
244
+ return layer;
245
+ }
246
+ /** The Sun-orbit lines that can be drawn now: `loaded` (the planet series are in) draws all of them, else none (they are drawn in `prepare`). */
247
+ earlySunPaths(orbitIds, openUtcMs, loaded) {
248
+ return loaded ? orbitIds.map((id) => this.sunPath(id, openUtcMs)) : [];
249
+ }
250
+ /** Whether the scene is centred on the Sun. */
251
+ checkSunCentred(ids) {
252
+ return ids[0] === rootBodyId(this.catalogue);
253
+ }
254
+ checkSolarSystemScale(scale, sunCentred) {
255
+ if (scale.id === solarSystemScale.id && !this.enlargedInSun(sunCentred))
256
+ throw new SceneError("bad-scale", "setScale: the Solar system scale needs a Sun-centred scene with an enlarged body (addBody(x, { enlarge }))");
257
+ }
258
+ /** Whether a Sun-centred scene enlarges a body, which the viewer's solar-system scale draws. */
259
+ enlargedInSun(sunCentred) {
260
+ return sunCentred && [...this.shape.values()].some((shape) => shape.enlarge !== undefined);
261
+ }
262
+ /** The bodies in the order added, as the public list states them. */
263
+ reads() {
264
+ return frozenList([...this.bodies.values()].map(({ id, label }) => {
265
+ const parent = this.catalogue.has(id) ? this.catalogue.get(id).definition.parentId : undefined;
266
+ const limits = this.catalogue.has(id) ? catalogueItem(id, { ...this.looks.get(id) }, this.catalogue).knownLimitations : undefined;
267
+ const description = this.notes.get(id);
268
+ const card = this.cards.get(id);
269
+ const texture = this.catalogue.has(id) ? this.catalogue.get(id).visual.texture : undefined;
270
+ return { id, label, listed: card?.listed ?? true, ...(card?.facts === undefined ? {} : { facts: card.facts }), ...(texture === undefined ? {} : { texture }), ...(parent === undefined ? {} : { parent }), orbit: this.orbits.has(id), enlarge: this.shape.get(id)?.enlarge ?? 1, ...(description === undefined ? {} : { description }), knownLimitations: Object.freeze([...(limits ?? [])]) };
271
+ }));
272
+ }
273
+ /**
274
+ * The scale choices offered: the opening one first, then the other unless the caller offered one alone. A Sun-centred scene with an enlarged body (`addBody(x, { enlarge })`)
275
+ * offers `solarSystemScale` (true distances, the named bodies enlarged) in place of the readable scale it would offer second, since the readable scale does not enlarge.
276
+ */
277
+ scaleChoices(scale, only) {
278
+ const offered = [trueScale, this.enlargedInSun(this.checkSunCentred([...this.bodies.keys()])) ? solarSystemScale : readableScale];
279
+ const second = scale.id === readableScale.id ? [trueScale] : offered.filter((other) => other.id !== scale.id);
280
+ return only ? [scale.id] : [scale.id, ...second.map((other) => other.id)];
281
+ }
282
+ visualOverrides() {
283
+ return visualOverridesEntry(this.shape);
284
+ }
285
+ /** How far a label shows, for bodies and paths alike: the item's own `labelReachEarthRadii` if given, else the shared rule: a Sun-centred scene, or one that fits the zoom-out to an orbit (`fitOrbit`, whose limit changes with the canvas), sets no limit; otherwise the camera reach, at least 500. */
286
+ labelReach(id, sunCentred, camera) {
287
+ const own = this.labelReaches.get(id);
288
+ if (own !== undefined)
289
+ return { labelMaxDistance: own };
290
+ return sunCentred || camera.fitted !== undefined ? {} : { labelMaxDistance: Math.max(500, camera.reachEarthRadii ?? 0) };
291
+ }
292
+ /** The shell item of a body: from the catalogue, with the scene's own words, look and label setting. Label reach is `labelReachEarthRadii`. */
293
+ bodyObject(body, ids, sunCentred, camera) {
294
+ const card = this.cards.get(body.id);
295
+ const sources = card?.sources;
296
+ const base = this.catalogue.get(body.id).definition.accuracy.position;
297
+ const own = { labelPriority: card?.labelPriority ?? 100 - ids.indexOf(body.id), ...(card?.listed === undefined ? {} : { listed: card.listed }), ...(card?.facts === undefined ? {} : { facts: card.facts }), ...(sources === undefined ? {} : { provenance: withSources(base, sources) }), ...this.labelReach(body.id, sunCentred, camera), ...(this.shape.get(body.id)?.showLabel === undefined ? {} : { showLabel: this.shape.get(body.id).showLabel }), ...(this.notes.has(body.id) ? { description: this.notes.get(body.id) } : {}), ...this.looks.get(body.id) };
298
+ return { ...catalogueItem(body.id, own, this.catalogue), label: body.label };
299
+ }
300
+ }
@@ -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
+ }