astraeus 0.1.1 → 0.3.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 (112) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/README.md +76 -7
  3. package/package.json +10 -6
  4. package/src/api/AstraeusScene.d.ts +27 -0
  5. package/src/api/AstraeusScene.js +38 -0
  6. package/src/api/AstraeusScene.node.js +37 -0
  7. package/src/api/activity.d.ts +50 -0
  8. package/src/api/activity.js +62 -0
  9. package/src/api/bodies.d.ts +24 -0
  10. package/src/api/bodies.js +24 -0
  11. package/src/api/errors.d.ts +1 -1
  12. package/src/api/group.d.ts +89 -0
  13. package/src/api/group.js +121 -0
  14. package/src/api/index.d.ts +6 -1
  15. package/src/api/index.js +3 -1
  16. package/src/api/index.node.js +8 -0
  17. package/src/api/mount.d.ts +10 -1
  18. package/src/api/mount.js +15 -4
  19. package/src/api/mount.node.js +36 -0
  20. package/src/api/prepared.d.ts +10 -0
  21. package/src/api/prepared.js +5 -0
  22. package/src/api/scene.d.ts +148 -9
  23. package/src/api/scene.js +563 -59
  24. package/src/api/story.d.ts +69 -0
  25. package/src/api/story.js +63 -0
  26. package/src/api/sunOrbit.d.ts +20 -0
  27. package/src/api/sunOrbit.js +85 -0
  28. package/src/api/switches.d.ts +14 -0
  29. package/src/api/switches.js +19 -0
  30. package/src/api/time.d.ts +4 -0
  31. package/src/api/time.js +8 -0
  32. package/src/app/App.d.ts +6 -2
  33. package/src/app/App.js +43 -21
  34. package/src/app/App.node.js +401 -0
  35. package/src/app/AstraeusScene.d.ts +1 -1
  36. package/src/app/DebugOverlay.d.ts +3 -52
  37. package/src/app/DebugOverlay.js +2 -29
  38. package/src/app/PanelLoadBoundary.d.ts +19 -0
  39. package/src/app/PanelLoadBoundary.js +17 -0
  40. package/src/app/SkyView.d.ts +3 -3
  41. package/src/app/SkyView.js +19 -10
  42. package/src/app/debugReadout.d.ts +53 -0
  43. package/src/app/debugReadout.js +30 -0
  44. package/src/app/developerPanels.d.ts +6 -0
  45. package/src/app/developerPanels.js +11 -0
  46. package/src/app/displaySwitches.d.ts +54 -0
  47. package/src/app/displaySwitches.js +48 -0
  48. package/src/app/experienceDefinition.d.ts +13 -1
  49. package/src/app/listSwitch.d.ts +16 -0
  50. package/src/{experiences/showers/showerChoice.js → app/listSwitch.js} +1 -9
  51. package/src/app/metricReadouts.d.ts +1 -1
  52. package/src/app/metricReadouts.js +1 -1
  53. package/src/app/openClock.d.ts +7 -0
  54. package/src/app/openClock.js +14 -0
  55. package/src/app/sceneContentsHooks.d.ts +3 -3
  56. package/src/app/sceneContentsHooks.js +2 -2
  57. package/src/app/sceneDebug.d.ts +1 -1
  58. package/src/app/sceneDebug.js +1 -1
  59. package/src/app/sceneFrame.js +4 -3
  60. package/src/app/sceneFraming.d.ts +13 -0
  61. package/src/app/sceneFraming.js +22 -0
  62. package/src/app/skyModel.js +3 -1
  63. package/src/app/trackedMetrics.d.ts +53 -0
  64. package/src/{experiences/apollo11/spacecraftMetrics.js → app/trackedMetrics.js} +40 -56
  65. package/src/assets/licence.d.ts +1 -0
  66. package/src/assets/pictures.d.ts +1 -1
  67. package/src/assets/sky.d.ts +4 -4
  68. package/src/assets/sky.js +12 -13
  69. package/src/core/bodies/index.d.ts +3 -0
  70. package/src/core/bodies/index.js +3 -1
  71. package/src/core/bodies/io.js +1 -1
  72. package/src/core/bodies/jupiterData.js +2 -2
  73. package/src/core/bodies/jupiterMoons.js +8 -12
  74. package/src/core/bodies/moon.d.ts +8 -0
  75. package/src/core/bodies/moon.js +28 -5
  76. package/src/core/bodies/outerPlanetData.js +7 -7
  77. package/src/core/bodies/planetMoons.js +18 -27
  78. package/src/core/bodies/swiftTuttle.js +2 -0
  79. package/src/core/elementsBody.d.ts +2 -0
  80. package/src/core/elementsBody.js +3 -0
  81. package/src/core/moonTrajectory.js +3 -5
  82. package/src/core/planetModels.js +1 -1
  83. package/src/core/planetSeries.d.ts +2 -0
  84. package/src/core/planetSeries.js +4 -0
  85. package/src/core/provenance.d.ts +7 -2
  86. package/src/core/provenance.js +3 -1
  87. package/src/core/scalePolicy.d.ts +3 -0
  88. package/src/core/scalePolicy.js +2 -0
  89. package/src/core/state.d.ts +1 -0
  90. package/src/shell/AstraeusShell.d.ts +4 -1
  91. package/src/shell/AstraeusShell.js +12 -6
  92. package/src/shell/AstraeusShell.node.js +225 -0
  93. package/src/shell/DisplaySwitches.d.ts +16 -0
  94. package/src/shell/DisplaySwitches.js +31 -0
  95. package/src/shell/StoryPanelView.js +3 -1
  96. package/src/shell/TimelineBar.css +4 -0
  97. package/src/shell/TimelineBar.node.js +75 -0
  98. package/src/shell/TopBar.css +20 -0
  99. package/src/shell/TopBar.d.ts +4 -1
  100. package/src/shell/TopBar.js +3 -2
  101. package/src/shell/TopBar.node.js +14 -0
  102. package/src/shell/experience.d.ts +4 -0
  103. package/src/shell/infoModel.js +3 -1
  104. package/src/shell/phone.css +4 -1
  105. package/src/shell/topBarIcons.d.ts +1 -0
  106. package/src/shell/topBarIcons.js +1 -0
  107. package/src/shell/useDrawers.js +1 -1
  108. package/src/shell/useZoomThrough.d.ts +7 -0
  109. package/src/shell/useZoomThrough.js +51 -0
  110. package/src/synthetic/syntheticDefinition.js +3 -3
  111. package/src/experiences/apollo11/spacecraftMetrics.d.ts +0 -34
  112. package/src/experiences/showers/showerChoice.d.ts +0 -25
package/CHANGELOG.md CHANGED
@@ -2,6 +2,57 @@
2
2
 
3
3
  Versions follow [semantic versioning](https://semver.org). While the version starts with `0.`, the public API (the names exported from `astraeus`) may still change between minor versions; each change is listed here.
4
4
 
5
+ ## 0.3.0 (2026-10-29)
6
+
7
+ First download of the packed example (`npm run measure:example`): 1,592,336 bytes raw, 453,513 bytes gzip (code and styles loaded on first open).
8
+
9
+ - The Milky Way is a new picture (I-026), no API change. The sky's Milky Way band is now the starless Gaia EDR3 render by Kevinmloch (CC BY-SA 4.0, 3840x1920), softer against the catalogue stars; it replaces the two ESO halves. The picture ships in `astraeus-data` (see its changelog) and is dimmed in the viewer; `milkyWayBrightness` still scales it, and it stays off by default.
10
+
11
+ - Answers for sites (O-045). `Scene.stateOf(id, time)` now answers for every body in the scene (ready-made bodies, moons, elements bodies), not only `addTrajectory` paths; they answer at any date, only a path refuses a moment outside it (`bad-time`), and a planet answers once the planet series are loaded (`missing-data` before). Its unknown-body message now reads "no body or trajectory with that id". New `Scene.provenanceOf(id)` returns the body's `Provenance`, which gains optional `accuracyClass` and `maxErrorFraction`: built-in Swift-Tuttle's is measured (0.00857); an elements body's is the limit of its class (0.01 approximate, 0.05 indicative), an upper bound and not a measured figure. New root exports: `APPROXIMATE_LIMIT_FRACTION`, `INDICATIVE_LIMIT_FRACTION`, `classifyPositionError` and `parseElementsBodyRecord`.
12
+
13
+ - Fit the zoom-out to an orbit (O-045). New `camera.fitOrbit(body)` sets the farthest zoom-out so the body's whole orbit fits the canvas from any direction, and re-fits when the canvas changes shape; the far plane is 2.5 times the reach. `setReach` and `fitOrbit` set the same limit, the later call wins. The opening view is unchanged except that it is clamped to the limit like any other. Labels are not limited in a fitted scene. `SceneError` `bad-camera` for a body that does not circle the Sun.
14
+
15
+ - Event labels (O-045). New provenance source type `"modelled"` (shown as "Modelled"). `addEvents` events take their own `provenance`, which wins over the batch's. Batch and per-event provenance are now validated: a malformed one throws `bad-event` (the batch one was not checked before). A group's info card shows "illustrative" as its source type, with the elements' type in the accuracy sentence (documented).
16
+
17
+ - Visible change (O-045). A body added with `addBodyFromElements` now has a live "Distance from Sun" row on its info card, and in the Geminids demo the Sun's card also lists "Distance to Phaethon".
18
+
19
+ - A better guest in a host page (O-044). `mount` and `AstraeusScene` no longer change `document.title`. The viewer's Escape handlers (story panel, phone drawer, switch panel) ignore a keydown the host already stopped with `preventDefault()`. The mount element and the `AstraeusScene` wrapper get `isolation: isolate`, so the viewer's `z-index` values (0 to 9) stay inside it; a `style` you pass to `AstraeusScene` can override it, and `mount` does not restore the element's old `isolation` on `unmount`.
20
+
21
+ - Node loading (O-044), no API change. The package's JSON imports now carry `with { type: "json" }`, and the root export has a `node` condition (order: types, node, import) that points at copies without the stylesheet import, so Node and Vitest's Node environment import `astraeus` with no inline setting. Bundlers keep the normal build. jsdom and happy-dom Vitest environments also take the `node` condition, so they do not load the viewer's CSS.
22
+
23
+ - Default time (O-044). A scene with no `setTime`, no `setTimeline` window and no trajectory now opens on the current time with a window of a month around it. This includes `setTimeline({ none: true })` with no `at`, which opens on the current time too (new in O-044; it was not changed in O-045).
24
+
25
+ - Phone story panel (O-044). On a phone, a wheel or two-finger pinch over an open story sheet zooms the scene behind it (the sheet has `touch-action: pan-y`).
26
+
27
+ - Documentation (O-044). The README says who needs `astraeus/style.css`, why a plain-JavaScript page still needs React, how story panels open and pause, that `camera.setReach(d)` also sets the far plane to 2.5 times `d`, and how to reload on `vite:preloadError`; `addStoryPanels`, `StoryPanelsInput` and `setReach` doc comments say the same.
28
+
29
+ - The Moon now shows libration (I-091), no API change. Its orientation was a plain tidal lock; it is now the IAU mean-Earth rotation model with its libration terms (Archinal et al. 2009 report, as saved in NAIF pck00011), so the Moon nods and sways by up to about 8 degrees as it does in the sky. Against JPL Horizons at seven dates from 1969 to 2050 the sub-Earth point and pole agree within 0.01 degrees (about 0.3 km on the surface); a surface place can no longer sit up to 8 degrees (254 km at Apollo 11's touchdown) from its true spot. Moon-surface features and mesh textures move accordingly.
30
+
31
+ - Documentation only: `addGroup` states that a `center` that is not a catalogued body throws `unknown-body` (a catalogued one missing from the scene throws `bad-group`), and `setTimeline` states that `loop` is ignored with `{ none: true }` or without a timeline. No behaviour changes.
32
+
33
+ ## 0.2.0
34
+
35
+ The story layer: a scene can now carry your own bodies from orbit elements, orbit lines for any body circling the Sun, timed events, story panels, groups of many objects, an activity curve, display switches and a looping timeline, through `mount` or the new React component `AstraeusScene`. Every public name is documented at <https://astraeus.anipatke.com/api/>. Two changes can affect a 0.1 app: React, react-dom, `@react-three/fiber` and three are now peer dependencies (React 19 needed), and camera preset ids are now `focus-<id>` and `follow-<id>` (both below).
36
+
37
+ - Lighter first download (O-043), no API change. The Developer drawer's panels (settings, debug readout, frame-rate graph) are a separate file loaded only when the Developer switch is turned on: on the packed example the code loaded on first open went from 1,603,283 to 1,589,850 bytes (458,257 to 454,211 gzip). If that file cannot be fetched (offline, or a tab left open across a redeploy), the drawer says so and asks for a reload; the rest of the viewer keeps working.
38
+
39
+ - Gaps found rebuilding a shower (O-042 T-177), no existing call changes. A Sun-centred scene with an enlarged body (`addBody(x, { enlarge })`) now offers the viewer's "solar-system" scale (true distances, the named bodies enlarged) as its second scale choice in place of the readable scale, which does not enlarge; scenes without enlargement are unchanged. A Sun-centred scene with planets (orbit lines, or a group clumped near a planet) now works through `mount`, `AstraeusScene` and `prepareScene` without the caller loading the planet series: the lines and clumped groups are drawn once `prepare` has loaded them. `addGroup`'s `clump.near` accepts a body added with `addBodyFromElements`, and `addGroup` takes `refillSliceMs` (0 or more; `bad-group` otherwise).
40
+
41
+ - Activity, looping and view settings (O-042), no existing call changes. New `Scene.addActivity({ id, label, unit, start, end, samples, peak?, provenance?, ... })` gives the timeline a rate curve (the glow) with its peak and the source of each stretch; a group takes `readouts: [{ kind: "rate" }]` for a live rate bar on its card (unavailable outside the activity). `setTimeline` takes `loop: true`; `camera.follow` and `camera.lookAt` take `up: "ecliptic"`; new `camera.setReach(distance)` sets how far the viewer can zoom out (labels reach as far). New `SceneError` codes `bad-activity` and `bad-camera`; a rate readout naming no activity is `bad-readout`. New exported types `ActivityInput`, `ActivitySampleInput`, `ActivitySourceInput` and `GroupReadoutInput`.
42
+
43
+ - Sun-centred scenes (O-042), no existing call changes. `addBody(x, { orbit: true })` now also draws one full turn round the Sun of any body that circles it when `sun` is in the scene (planets, Earth's year; was `no-orbit` for all but the Moon and Io). New `Scene.addBodyFromElements(record, options?)` adds your own body from published orbit elements with their source and accuracy (`bad-element` names the bad field); `addBody` takes `enlarge` (planet drawn that many times larger in the readable scale; `bad-body` below 1) and `showLabel: false` (label starts off). A scene whose first body is the Sun sets no label reach, so labels do not fade when zoomed out, and refuses `addTrajectory` at `toDefinition` with `bad-trajectory`. New exported type `ElementsBodyRecord`.
44
+
45
+ - Groups of dots (O-042), no existing call changes. New `Scene.addGroup({ id, orbits, ... })` draws a list of orbits (each with its own id, shape and tilt) as one group of dots: one colour (`color`), dot size (`dotSizePx`), menu item, info card, provenance and known limits. The dots are placed along their orbits by an even spread shuffled by `seed`, optionally with a share clumped near a body (`clump: { near, fraction, widthDeg }`); `refillAfterMs` sets how often the dots are placed again. The group's id joins the camera menu (`focus-<id>`, `follow-<id>`) and can be named by a story panel's `object`. New `SceneError` code `bad-group` (empty list, bad or unbound orbit, bad colour or clump, a centre or clump body not in the scene); a repeated id is `duplicate-id`. New exported types `GroupInput`, `GroupOrbitInput` and `GroupClumpInput`. `examples/hello-scene` draws a made-up ring of 40 dots.
46
+
47
+ - Display switches (O-041), no existing call changes. New `Scene.setSwitches({ orbitLines?, labels?, milkyWay? })` places each switch on the top bar, in one switch panel opened from the bar, or only in the Developer drawer, and sets whether it starts on; a bad name, place or `on` throws `bad-switch`. Each placed switch drives the same state as its Developer-drawer buttons. New exported type `SwitchesInput`. With nothing placed the bar is unchanged. `examples/hello-scene` places two.
48
+
49
+ - Story calls (O-041). One visible change to existing behaviour: camera preset ids are now `focus-<id>` and `follow-<id>`, and the camera menu is built automatically, with a Focus and a Follow entry for every body and path; the Sky item is no longer listed in any object menu. `addTrajectory` takes `description`, `knownLimitations`, `anchors` (labelled dots where the data was published; a time outside the path throws `bad-anchor`) and `readouts` (info-card bars: `range`, `speed`, `distance`, `altitude`); `addBody` takes `description`, `color` (a hex colour for the info card and label) and `knownLimitations` (a list of non-empty texts shown with the provenance); a bad `color` or `knownLimitations` throws `bad-body`. New `Scene` methods: `addEvents` (timed events with optional `provenance`; `bad-event`), `addStoryPanels` (panels at a time, event or anchor; `bad-panels`), `setTimeline` (span, speeds, opening speed, or `{ none: true }` for no timeline; `bad-timeline`), `stateOf` (state of a path at a moment) and `camera.lookAt` (opening view without following). `setScale` takes `{ only: true }` to offer one scale. `examples/hello-scene` now uses all of them.
50
+
51
+ - An API reference page is published at <https://astraeus.anipatke.com/api/>, generated from the public types and doc comments; the package `homepage` points at it. Every export now has a doc comment (a test keeps it so). No change to the API.
52
+
53
+ - New export `AstraeusScene` (with its props type `AstraeusSceneProps`): a React component that draws the same viewer as `mount`, `<AstraeusScene scene={scene} data={[...]} onReady onError />`. It rebuilds when the `scene` prop changes and cleans up on unmount.
54
+ - Needs React 19 and `@react-three/fiber` 9.8.2 or later: `react`, `react-dom`, `@react-three/fiber` and `three` are now peer dependencies, not dependencies, so the host app's own copies are used and installed once. Install them beside `astraeus`. No change to the public API.
55
+
5
56
  ## 0.1.1
6
57
 
7
58
  No changes to the code, data or public API. The first version published by the GitHub release workflow, with npm provenance ("Built and signed on GitHub Actions").
package/README.md CHANGED
@@ -2,15 +2,21 @@
2
2
 
3
3
  A 3D solar system for the browser. Place bodies and recorded paths in a scene, mount it, and get time controls, camera, scale choice and body information, with no React and no 3D code of your own.
4
4
 
5
- > **0.1 preview.** The public API below is the promise: it is small on purpose and may still change between `0.x` versions, with every change listed in [CHANGELOG.md](./CHANGELOG.md). Anything not exported from `astraeus` is internal and may change or disappear in any release.
5
+ > **0.2 preview.** The public API below is the promise: it is small on purpose and may still change between `0.x` versions, with every change listed in [CHANGELOG.md](./CHANGELOG.md). Anything not exported from `astraeus` is internal and may change or disappear in any release.
6
6
 
7
7
  ## Install
8
8
 
9
9
  ```sh
10
- npm install astraeus
10
+ npm install astraeus react react-dom @react-three/fiber three
11
11
  ```
12
12
 
13
- You need a bundler. These were each built and run with the packed packages (a scene with Saturn and Titan from `astraeus-data-saturn`): Vite 8, webpack 5 (5.112) and Parcel 2 (2.16, which needs `"@parcel/resolver-default": { "packageExports": true }` in your `package.json` so it reads the package `exports`). Others are untried. The package is plain ES modules that reference their pictures with `new URL(..., import.meta.url)`; loading it straight in Node or from a bare `<script type="module">` will not work.
13
+ `react` (19), `react-dom` (19), `@react-three/fiber` (9.8.2 or later 9.x) and `three` (0.169 or later) are peer dependencies: your app's own copies are used, so install them beside `astraeus` (npm 7 and later installs missing peers for you).
14
+
15
+ A plain-JavaScript page still needs React: `mount` draws the viewer with React and `@react-three/fiber` inside, so all four peers must be installed even if your own code never touches React.
16
+
17
+ `mount` loads the viewer's stylesheet itself. If you use the `AstraeusScene` component instead, add `import "astraeus/style.css";` once in your app.
18
+
19
+ You need a bundler. These were each built and run with the packed packages (a scene with Saturn and Titan from `astraeus-data-saturn`): Vite 8, webpack 5 (5.112) and Parcel 2 (2.16, which needs `"@parcel/resolver-default": { "packageExports": true }` in your `package.json` so it reads the package `exports`). Others are untried. The package is plain ES modules that reference their pictures with `new URL(..., import.meta.url)`; drawing needs a bundler and a browser, so do not load it from a bare `<script type="module">`. Node and Vitest can import it for scene definitions and tests (see "Loading in your build and in tests").
14
20
 
15
21
  ## A scene in about 20 lines
16
22
 
@@ -34,23 +40,86 @@ scene.camera.follow("probe", { distance: 110 });
34
40
  mount(document.getElementById("app"), scene);
35
41
  ```
36
42
 
37
- The element needs a size (for example `height: 100%` all the way up). The probe's circle and the Moon's own orbit (tilted to it, because the circle lies in the reference frame's x-y plane) are both drawn. The finished app is in the repository at `examples/hello-scene`.
43
+ The element needs a size (for example `height: 100%` all the way up). The probe's circle and the Moon's own orbit (tilted to it, because the circle lies in the reference frame's x-y plane) are both drawn. The finished app, grown into a small made-up story with every call below, is in the repository at `examples/hello-scene`.
38
44
 
39
45
  ## The public API
40
46
 
47
+ The full reference, generated from the types and doc comments, is at <https://astraeus.anipatke.com/api/>. The table below is the short form.
48
+
41
49
  | Call | What it does |
42
50
  |---|---|
43
51
  | `new Scene()` | An empty scene. Every method below returns the scene, so calls chain. |
44
- | `scene.addBody(body, { orbit? })` | Adds a catalogued body: a ready-made one (`sun`, `mercury`, `venus`, `earth`, `moon`, `mars`, `jupiter`, `saturn`, `uranus`, `neptune`, `pluto`, and the moons `io`, `europa`, `ganymede`, `callisto`, `mimas`, `enceladus`, `tethys`, `dione`, `rhea`, `titan`, `iapetus`, `triton`, `charon`, `phobos`, `deimos`) or its id. The first body added is the scene's centre. `{ orbit: true }` also draws its orbit line about its parent (the parent must be in the scene); in 0.1 only `moon` (about Earth) and `io` (about Jupiter) have one, others throw `no-orbit`. |
45
- | `scene.addTrajectory({ id, label?, color?, center?, samples })` | A recorded path. Each sample is `{ time, positionKm, velocityKmS? }` measured from `center` (default `"earth"`); `time` is ISO text, a `Date` or Unix milliseconds. Instead of `samples` you may give `provider` (an object with `stateAt(timeUtcMs)`) and `bounds: { start, end }`. |
52
+ | `scene.addBody(body, { orbit?, enlarge?, showLabel?, description?, color?, knownLimitations? })` | Adds a catalogued body: a ready-made one (`sun`, `mercury`, `venus`, `earth`, `moon`, `mars`, `jupiter`, `saturn`, `uranus`, `neptune`, `pluto`, and the moons `io`, `europa`, `ganymede`, `callisto`, `mimas`, `enceladus`, `tethys`, `dione`, `rhea`, `titan`, `iapetus`, `triton`, `charon`, `phobos`, `deimos`) or its id. The first body added is the scene's centre. `{ orbit: true }` also draws its orbit line: `moon` about Earth and `io` about Jupiter (the parent must be in the scene), or, with `sun` in the scene, one full turn round the Sun of any body that circles it (the planets, Earth's year, a body from `addBodyFromElements`), from the opening time; anything else throws `no-orbit`. `enlarge` (a number of at least 1) draws the body that many times larger than life (in a Sun-centred scene the viewer then offers its "Solar system" scale, true distances with the named bodies enlarged, as the second scale in place of Readable); `showLabel: false` starts its label off. A scene whose first body is the Sun sets no label reach, so labels stay when zoomed out, and it cannot hold a tracked path (`addTrajectory`; `bad-trajectory`). `color` (a hex colour such as `"#9fd8ff"`) sets the colour on its info card and label; `knownLimitations` (a list of non-empty texts) replaces the catalogue's limits shown with its provenance; a bad value throws `bad-body`. |
53
+ | `scene.addTrajectory({ id, label?, color?, center?, samples, provenance?, description?, knownLimitations?, anchors?, readouts? })` | A recorded path. Each sample is `{ time, positionKm, velocityKmS? }` measured from `center` (default `"earth"`); `time` is ISO text, a `Date` or Unix milliseconds. Instead of `samples` you may give `provider` (an object with `stateAt(timeUtcMs)`) and `bounds: { start, end }`. `description` and `knownLimitations` (a list of sentences) go on its info card with `provenance`. `anchors: [{ id, time }]` draw labelled dots where the source published a point (the time must fall within the path). `readouts` are bars on the card, in order: `{ kind: "range", marker? }` (distance from the centre; `marker` names a body to mark), `{ kind: "speed" }`, `{ kind: "distance", to }` and `{ kind: "altitude", above }`; a named body must be in the scene. |
54
+ | `scene.addBodyFromElements(record, options?)` | Your own body that circles the Sun, from published orbit elements: `record` is `{ id, label, elements: { semiMajorAxisAu, eccentricity, inclinationDeg, ascendingNodeDeg, argumentOfPerihelionDeg, meanAnomalyDeg or perihelionJdTdb }, epoch: { jd, timeScale, ttMinusUtcSeconds? }, frame: "ecliptic-j2000", source: { name, url, solution, accessed }, radius?, accuracy: { classification, statement, validFromUtc, validToUtc, limitations }, marker?: { color, sizePx } }`. Drawn as a marker on unperturbed two-body motion about the Sun; the source, accuracy and limits show on its info card, with a live "Distance from Sun" row. `options` are `addBody`'s (`{ orbit: true }` draws its whole orbit from periapsis, smooth even for a sharp comet orbit). A bad record throws `bad-element` naming the field; a repeated id throws `duplicate-id`. |
55
+ | `scene.addGroup({ id, orbits, label?, center?, plane?, color?, dotSizePx?, referenceTime?, seed?, clump?, refillAfterMs?, refillSliceMs?, provenance?, description?, knownLimitations? })` | A list of orbits drawn as one group of dots: `orbits` is `[{ id, semiMajorAxisKm, eccentricity, inclinationDeg, raanDeg, argumentOfPeriapsisDeg, time? }]` (bound orbits, ids distinct), measured about `center` (default the scene's centre; it must be in the scene) in `plane` (`"ecliptic-j2000"` default, or `"EQJ"`). One colour (`color`, a hex colour), dot size (`dotSizePx`), menu item, info card, provenance and known limits. Where each dot sits along its orbit is a drawing choice, marked illustrative: an even spread shuffled by `seed`, fixed at `referenceTime` (default the opening time), then two-body motion. `clump: { near, fraction, widthDeg }` draws a share of the dots near a body's place along its orbit (a model; the body must be in the scene and not the centre; it may be one added with `addBodyFromElements` before the group). `refillAfterMs` is how often the dots are placed again; `refillSliceMs` (0 or more) is how much of a frame may go on computing the next fill ahead of time. The group's card shows "illustrative" as its source type, with the elements' own type in the accuracy sentence. The id joins the camera menu (`focus-<id>`, `follow-<id>`) and may be a panel's `object`. A mistake throws `bad-group`. |
46
56
  | `scene.setTime(time)` | The moment the scene opens at. |
47
- | `scene.setScale(trueScale \| readableScale)` | The opening scale; the viewer can switch to the other. |
57
+ | `scene.setScale(trueScale \| readableScale, { only? })` | The opening scale; the viewer can switch to the other unless `{ only: true }` offers that scale alone. |
58
+ | `scene.addEvents(events, { provenance? })` | Timed events on the timeline: `[{ id, label, time, type?, provenance? }]`, ids unique. `provenance` says where the times come from; an event's own `provenance` wins over the batch's. A provenance `sourceType` is `ephemeris`, `observed`, `reconstructed`, `modelled` or `illustrative`; `modelled` is shown as "Modelled". Batch and per-event provenance are checked: a malformed one throws `bad-event`. May be called more than once. |
59
+ | `scene.addStoryPanels({ pauseSeconds?, autoOpen?, panels })` | Story panels that open as playback reaches them: `{ id, at: { utc } \| { event } \| { anchor }, title, body, details?, badge, sources, object? }`. `badge` is `observed`, `modelled` or `illustrative`; `sources` is never empty. A mistake throws `bad-panels` naming the panel and field. |
60
+ | `scene.setTimeline({ start, end, rates?, rate? })` | The timeline's span, the playback speeds offered (simulated seconds per real second) and the one it opens at. `{ none: true, at?, rate? }` draws no timeline bar: time is frozen at `at`, or runs on at `rate`. |
61
+ | `scene.addActivity({ id, label, unit, start, end, samples, peak?, provenance?, type?, peakLabel? })` | A period of activity on the timeline: a rate curve `samples: [{ time, value }]` (at least two, sorted, inside `start` to `end`; straight lines between) that the timeline glows by, with an optional `peak` mark and `provenance: [{ start, end, provenance }]` for where each stretch comes from. A group's `readouts: [{ kind: "rate", activity? }]` shows the live rate (unavailable outside the period) against the peak on its card. Without `setTimeline` the timeline spans the activities. A repeated id or a bad curve, peak or source throws `bad-activity`; a rate readout with no activity is `bad-readout`. |
62
+ | `scene.camera.setReach(distance)` | How far the viewer can zoom out, in Earth radii; labels reach as far. A bad value throws `bad-camera`. `camera.follow` and `camera.lookAt` take `up: "ecliptic"` (default `"equatorial"`) to orbit about the ecliptic's pole; any other value throws `bad-camera`. `setTimeline` takes `loop: true` so playback wraps from the end to the start. |
63
+ | `scene.camera.fitOrbit(body)` | Sets the farthest zoom-out so the whole orbit of a body that circles the Sun (a planet, the built-in comet, or one from `addBodyFromElements`, already added) fits the canvas from any view direction: 1.1 times its farthest Sun distance over the sine of the narrower half field of view. The fit follows the live canvas shape (a phone turning, a window resizing) and the far plane is 2.5 times the reach. The opening view is not moved, except that it is clamped to the limit like any other. Labels are not limited in a fitted scene. It and `setReach` set the same limit; the later call wins. A body that does not circle the Sun throws `bad-camera`; one not in the scene, `unknown-body`. `scene.camera.fitOrbit("c-2025-a1")` |
64
+ | `scene.setSwitches({ orbitLines?, labels?, milkyWay? })` | Where each display switch shows: `{ place: "top-bar" \| "panel" \| "developer", on? }`. A top-bar switch is a button in the bar, a panel switch is a row in one switch panel opened from the bar, and a developer switch is only in the Developer drawer (where every switch stays). `orbitLines` is the orbit ring, trailing arc and moon orbits; `labels` is body and anchor labels; `milkyWay` is the sky picture. `on` is the starting state (default on). Nothing placed: the bar is as before. A bad name, place or `on` throws `bad-switch`. |
65
+ | `scene.stateOf(id, time)` | The state of any body in the scene at a moment, for figures a story quotes. `positionKm` is always there; `velocityKmS` (km/s) only where the body's source gives one, so check it before use: a path from `addTrajectory` whose samples or provider carry velocities, and a moon from fitted data (Io); planets, Earth, the Sun, built-in Swift-Tuttle and elements bodies give position only. Bodies: a path from `addTrajectory` (about its centre), or a ready-made body, moon or elements body (about its parent). Ready-made and elements bodies answer at any date; only a moment outside an `addTrajectory` path throws `bad-time`. A planet's data lives in the planet series, so it answers only once they are loaded (at `mount`), else `missing-data`. `const au = Math.hypot(...scene.stateOf("earth", "2026-08-12T00:00:00Z").positionKm) / 149597870.7;` |
66
+ | `scene.provenanceOf(id)` | Where a body's position comes from, as its info card shows it. Where a comparison with an independent ephemeris exists it carries `accuracyClass` and `maxErrorFraction`. For built-in Swift-Tuttle that fraction is measured (0.00857). For a body from `addBodyFromElements` it is the limit of its class (0.01 `approximate`, 0.05 `indicative`): an upper bound, not a measured figure. Other bodies carry neither field. |
48
67
  | `scene.camera.follow(id, { azimuthDeg?, elevationDeg?, distance? })` | Opens framed on a body or trajectory already added, and already following it. `distance` is in Earth radii. |
68
+ | `scene.camera.lookAt(id, { azimuthDeg?, elevationDeg?, distance? })` | The same opening view without following. The last of `follow` and `lookAt` wins. The viewer's camera menu gets a Focus and a Follow entry for every body and path. |
49
69
  | `mount(element, scene, { data? })` | Draws the scene with the full viewer. Returns `{ ready, unmount() }`. `data` is a list of data packages (below). |
70
+ | `<AstraeusScene scene data? onReady? onError? />` | The same viewer as a React component (below). |
50
71
  | `SceneError` | Thrown for bad input. `error.code` is one of the documented `SceneErrorCode` values (for example `unknown-body`, `bad-time`, `missing-data`, `no-orbit`) and the message says what to do. |
51
72
 
73
+ Checking accuracy and records without a scene: the class limits are root exports (`APPROXIMATE_LIMIT_FRACTION`, `INDICATIVE_LIMIT_FRACTION`), `classifyPositionError(maxFraction)` returns `"approximate"`, `"indicative"` or `null` (neither) for a measured largest error fraction, and `parseElementsBodyRecord(record)` validates an elements record (the same check `addBodyFromElements` makes, throwing `bad-element` naming the field):
74
+
75
+ ```js
76
+ import { classifyPositionError, parseElementsBodyRecord } from "astraeus";
77
+ const accuracyClass = classifyPositionError(0.004); // measured error / distance from the Sun
78
+ const record = parseElementsBodyRecord(myRecord);
79
+ ```
80
+
52
81
  Types (`State`, `Pictures`, `TextureRef`, `AssetLicence`, `DataSource`, `TrajectoryInput` and the like) are exported for TypeScript.
53
82
 
83
+ ## In a React app
84
+
85
+ `AstraeusScene` draws the same viewer as `mount`, as a component. It fills its parent, so give the parent a size:
86
+
87
+ ```jsx
88
+ import { Scene, earth, moon, AstraeusScene } from "astraeus";
89
+
90
+ const scene = new Scene().addBody(earth).addBody(moon, { orbit: true });
91
+
92
+ export const App = () => (
93
+ <div style={{ height: "100vh" }}>
94
+ <AstraeusScene scene={scene} data={[]} onReady={() => console.log("drawn")} onError={(error) => console.error(error)} />
95
+ </div>
96
+ );
97
+ ```
98
+
99
+ Props: `scene`, `data` (as for `mount`), `onReady`, `onError` (a bad scene or failed data load), `className` and `style` for the wrapper. Build the `Scene` once (outside the component or in `useMemo`): a new `Scene` object rebuilds the viewer. It needs React 19 and the peer dependencies (`react`, `react-dom`, `@react-three/fiber`, `three`). See `examples/hello-react` in the repository.
100
+
101
+ ## Inside someone else's page
102
+
103
+ The viewer is built to sit in a host page without taking it over. It never changes `document.title`. It isolates its own layers (`isolation: isolate` on the element given to `mount` and on the `AstraeusScene` wrapper), so its `z-index` values (0 to 9) stay inside the viewer and cannot cover or sit under your page's layers; `mount` does not restore the element's old `isolation` on `unmount`. Its Escape handlers (story panel, phone drawer, switch panel) ignore a keydown your page already stopped with `preventDefault()`. It honours `prefers-reduced-motion`: the viewer's own animations and transitions are switched off.
104
+
105
+ A scene with no `setTime`, `setTimeline` or trajectory opens on the current time, with a window of a month around it.
106
+
107
+ Story panels (`addStoryPanels`): a panel opens only when forward playback crosses its time, so one at the opening instant never opens by itself. `at.utc` may be any instant inside the timeline, in any year. When a panel opens by itself, `pauseSeconds` (default 6) holds playback and then restarts it, unless the visitor pressed Play during the hold. On a phone, a wheel or pinch over an open story sheet zooms the scene behind it. `camera.setReach(d)` sets how far the camera can zoom out and also sets the far plane to 2.5 times `d`.
108
+
109
+ ## Loading in your build and in tests
110
+
111
+ `planetModels` (the planet series), the Developer drawer's panels and `MoonFamilyPanel` are separate files that your build loads later, on demand. After you redeploy, a tab left open may ask for a file name that no longer exists. In a Vite host, reload the page when that happens:
112
+
113
+ ```js
114
+ window.addEventListener("vite:preloadError", () => window.location.reload());
115
+ ```
116
+
117
+ (The Developer drawer also says when its file cannot be fetched and asks for a reload.)
118
+
119
+ For tests, the package has a `node` export condition: Node and Vitest's Node environment import a copy of the package without the stylesheet import, so `new Scene()...toDefinition()` works with no `test.server.deps.inline` setting. The jsdom and happy-dom Vitest environments also take the `node` condition, so the viewer's CSS is not loaded there; this does not matter for tests that check scene definitions or behaviour. Bundlers do not use the `node` condition and load the normal build.
120
+
121
+ First download: the packed `examples/hello-scene` loads 1,589,214 bytes (454,404 gzip) of code and styles, measured at this commit on first open (`npm run measure:example`; pictures and data files are not counted).
122
+
54
123
  ## What `astraeus-data` adds
55
124
 
56
125
  The engine alone draws the Sun, Earth, Moon and the eight planets with their pictures and positions for 2010 to 2030. Everything heavier is a separate, optional package you import and hand to `mount`, so you only download what you use. A moon-position package is thousands of small files; your build copies them as separate files and the page fetches only the ones for the time window on screen (each chunk URL ends `?no-inline`, so Vite does not paste them into your script):
package/package.json CHANGED
@@ -1,19 +1,22 @@
1
1
  {
2
2
  "name": "astraeus",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
4
  "description": "A 3D solar system engine for the browser: place bodies and recorded paths in a scene, mount it, and get time controls, camera, scale choice and body info. Planet positions and the main pictures included.",
5
5
  "license": "MIT",
6
6
  "type": "module",
7
7
  "dependencies": {
8
- "@lizard-isana/orb": "3.1.1",
9
- "@react-three/fiber": "^8.18.0",
10
- "react": "^18.3.1",
11
- "react-dom": "^18.3.1",
12
- "three": "^0.169.0"
8
+ "@lizard-isana/orb": "3.1.1"
9
+ },
10
+ "peerDependencies": {
11
+ "@react-three/fiber": ">=9.8.2 <10",
12
+ "react": ">=19 <19.4",
13
+ "react-dom": ">=19 <19.4",
14
+ "three": ">=0.169.0 <1"
13
15
  },
14
16
  "exports": {
15
17
  ".": {
16
18
  "types": "./src/api/index.d.ts",
19
+ "node": "./src/api/index.node.js",
17
20
  "import": "./src/api/index.js"
18
21
  },
19
22
  "./style.css": "./src/app/style.css"
@@ -21,6 +24,7 @@
21
24
  "sideEffects": [
22
25
  "**/*.css"
23
26
  ],
27
+ "homepage": "https://astraeus.anipatke.com/api/",
24
28
  "repository": {
25
29
  "type": "git",
26
30
  "url": "git+https://github.com/anipatke/Astraeus.git"
@@ -0,0 +1,27 @@
1
+ import { type CSSProperties, type ReactElement } from "react";
2
+ import "../app/style.css";
3
+ import type { DataSource, Scene } from "./scene.js";
4
+ /** Props of `AstraeusScene`. */
5
+ export interface AstraeusSceneProps {
6
+ /** The scene to draw. Passing a different `Scene` object rebuilds the viewer; changing the same object in place does not. */
7
+ readonly scene: Scene;
8
+ /** Data packages the scene's bodies need, such as moon pictures or positions. Read when the scene is built, so a new array alone does not rebuild. */
9
+ readonly data?: readonly DataSource[];
10
+ /** Called once the scene's data has loaded and it is drawn (again after each rebuild). */
11
+ readonly onReady?: () => void;
12
+ /** Called when the scene cannot be built (a `SceneError`) or its data fails to load. */
13
+ readonly onError?: (error: Error) => void;
14
+ /** Class for the wrapper element, which fills its parent's width and height unless `style` says otherwise. */
15
+ readonly className?: string;
16
+ /** Style for the wrapper element. */
17
+ readonly style?: CSSProperties;
18
+ }
19
+ /**
20
+ * The full viewer `mount` draws, as a React component: `<AstraeusScene scene={scene} data={[...]} />`. Waits for the scene's data, then draws; cleans up on unmount.
21
+ * @example
22
+ * const scene = new Scene().addBody(earth).addBody(moon);
23
+ * export function App() {
24
+ * return <div style={{ height: "100vh" }}><AstraeusScene scene={scene} onError={console.error} /></div>;
25
+ * }
26
+ */
27
+ export declare function AstraeusScene({ scene, data, onReady, onError, className, style }: AstraeusSceneProps): ReactElement;
@@ -0,0 +1,38 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import "../app/style.css";
4
+ import { App } from "../app/App.js";
5
+ import { prepareScene } from "./prepared.js";
6
+ const FILL = { width: "100%", height: "100%" };
7
+ const asError = (cause) => (cause instanceof Error ? cause : new Error(String(cause)));
8
+ /**
9
+ * The full viewer `mount` draws, as a React component: `<AstraeusScene scene={scene} data={[...]} />`. Waits for the scene's data, then draws; cleans up on unmount.
10
+ * @example
11
+ * const scene = new Scene().addBody(earth).addBody(moon);
12
+ * export function App() {
13
+ * return <div style={{ height: "100vh" }}><AstraeusScene scene={scene} onError={console.error} /></div>;
14
+ * }
15
+ */
16
+ export function AstraeusScene({ scene, data, onReady, onError, className, style }) {
17
+ const [definition, setDefinition] = useState();
18
+ // The latest data and callbacks, read when the scene is built, so a new array or arrow function each render does not rebuild it.
19
+ const latest = useRef({ data, onReady, onError });
20
+ latest.current = { data, onReady, onError };
21
+ useEffect(() => {
22
+ let open = true;
23
+ setDefinition(undefined);
24
+ try {
25
+ const prepared = prepareScene(scene, latest.current.data);
26
+ prepared.ready.then(() => { if (open) {
27
+ setDefinition(prepared.definition);
28
+ latest.current.onReady?.();
29
+ } }, (cause) => { if (open)
30
+ latest.current.onError?.(asError(cause)); });
31
+ }
32
+ catch (cause) {
33
+ latest.current.onError?.(asError(cause));
34
+ }
35
+ return () => { open = false; };
36
+ }, [scene]);
37
+ return _jsx("div", { className: className, style: { ...FILL, isolation: "isolate", ...style }, children: definition ? _jsx(App, { definition: definition, writeTitle: false }) : null });
38
+ }
@@ -0,0 +1,37 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from "react";
3
+ import { App } from "../app/App.node.js";
4
+ import { prepareScene } from "./prepared.js";
5
+ const FILL = { width: "100%", height: "100%" };
6
+ const asError = (cause) => (cause instanceof Error ? cause : new Error(String(cause)));
7
+ /**
8
+ * The full viewer `mount` draws, as a React component: `<AstraeusScene scene={scene} data={[...]} />`. Waits for the scene's data, then draws; cleans up on unmount.
9
+ * @example
10
+ * const scene = new Scene().addBody(earth).addBody(moon);
11
+ * export function App() {
12
+ * return <div style={{ height: "100vh" }}><AstraeusScene scene={scene} onError={console.error} /></div>;
13
+ * }
14
+ */
15
+ export function AstraeusScene({ scene, data, onReady, onError, className, style }) {
16
+ const [definition, setDefinition] = useState();
17
+ // The latest data and callbacks, read when the scene is built, so a new array or arrow function each render does not rebuild it.
18
+ const latest = useRef({ data, onReady, onError });
19
+ latest.current = { data, onReady, onError };
20
+ useEffect(() => {
21
+ let open = true;
22
+ setDefinition(undefined);
23
+ try {
24
+ const prepared = prepareScene(scene, latest.current.data);
25
+ prepared.ready.then(() => { if (open) {
26
+ setDefinition(prepared.definition);
27
+ latest.current.onReady?.();
28
+ } }, (cause) => { if (open)
29
+ latest.current.onError?.(asError(cause)); });
30
+ }
31
+ catch (cause) {
32
+ latest.current.onError?.(asError(cause));
33
+ }
34
+ return () => { open = false; };
35
+ }, [scene]);
36
+ return _jsx("div", { className: className, style: { ...FILL, isolation: "isolate", ...style }, children: definition ? _jsx(App, { definition: definition, writeTitle: false }) : null });
37
+ }
@@ -0,0 +1,50 @@
1
+ import { type Provenance } from "../core/provenance.js";
2
+ import { type TimelineWindow } from "../core/timeWindow.js";
3
+ import type { RateMetric } from "../shell/metrics.js";
4
+ import { type TimeInput } from "./time.js";
5
+ /** One point of an activity curve: a rate at a moment. Between points the rate is a straight line. */
6
+ export interface ActivitySampleInput {
7
+ readonly time: TimeInput;
8
+ /** How many per unit of time, never negative. */
9
+ readonly value: number;
10
+ }
11
+ /** Where a stretch of the curve comes from; stretches are sorted, do not overlap and lie inside the activity. */
12
+ export interface ActivitySourceInput {
13
+ readonly start: TimeInput;
14
+ readonly end: TimeInput;
15
+ readonly provenance: Provenance;
16
+ }
17
+ /**
18
+ * A period of activity on the timeline: a rate curve (the timeline glows brighter where the rate is higher) with an optional peak, and where each stretch of the curve comes from.
19
+ * The id is unique among the scene's activities and is what a group's `{ kind: "rate" }` readout can name.
20
+ */
21
+ export interface ActivityInput {
22
+ readonly id: string;
23
+ /** Name shown on the timeline and with the rate bar. */
24
+ readonly label: string;
25
+ /** What the rate counts, per unit of time, such as "meteors per hour". */
26
+ readonly unit: string;
27
+ /** The first and last moment of the activity. The curve's samples lie inside it, and the rate is unavailable outside it. */
28
+ readonly start: TimeInput;
29
+ readonly end: TimeInput;
30
+ /** The moment of the peak, marked on the timeline; inside the activity. */
31
+ readonly peak?: TimeInput;
32
+ /** At least two points, sorted by time, one per moment. */
33
+ readonly samples: readonly ActivitySampleInput[];
34
+ /** Where each stretch of the curve comes from, shown with the activity. Absent: no source is stated. */
35
+ readonly provenance?: readonly ActivitySourceInput[];
36
+ /** A free word the timeline may group by, such as "meteor-shower". */
37
+ readonly type?: string;
38
+ /** Name of the peak mark on the rate bar; "Peak" when absent. */
39
+ readonly peakLabel?: string;
40
+ }
41
+ /** A validated activity: the engine's window, and the peak the rate bar compares with. */
42
+ export interface PlannedActivity {
43
+ readonly window: TimelineWindow;
44
+ readonly peakValue: number;
45
+ readonly peakLabel: string;
46
+ }
47
+ /** Checks an activity and builds its window; any fault is a `bad-activity` naming the activity. */
48
+ export declare function planActivity(input: ActivityInput): PlannedActivity;
49
+ /** The live rate bar of an activity at a moment: the rate (unavailable outside the activity) against its peak. */
50
+ export declare function rateMetricOf(groupId: string, activity: PlannedActivity, timeUtcMs: number): RateMetric;
@@ -0,0 +1,62 @@
1
+ import { createProvenance } from "../core/provenance.js";
2
+ import { createWindows, rateAt } from "../core/timeWindow.js";
3
+ import { SceneError } from "./errors.js";
4
+ import { toUtcMs } from "./time.js";
5
+ const bad = (id, message) => new SceneError("bad-activity", `addActivity("${String(id)}"): ${message}`);
6
+ const isText = (value) => typeof value === "string" && value !== "";
7
+ /** Checks the plain fields and returns the id. */
8
+ function checkFields(input) {
9
+ const id = input?.id;
10
+ if (!isText(id))
11
+ throw bad(id, "the activity needs a non-empty id");
12
+ if (!isText(input.label))
13
+ throw bad(id, "the activity needs a non-empty label");
14
+ if (!isText(input.unit))
15
+ throw bad(id, "the activity needs a unit such as \"meteors per hour\"");
16
+ if (!Array.isArray(input.samples) || input.samples.length < 2)
17
+ throw bad(id, "the curve needs at least two samples");
18
+ if (input.peakLabel !== undefined && !isText(input.peakLabel))
19
+ throw bad(id, "peakLabel must be a non-empty text");
20
+ return id;
21
+ }
22
+ /** Checks an activity and builds its window; any fault is a `bad-activity` naming the activity. */
23
+ export function planActivity(input) {
24
+ const id = checkFields(input);
25
+ const moment = (time, what) => toUtcMs(time, `addActivity("${id}") ${what}`);
26
+ const samples = input.samples.map((sample, index) => ({ timeUtcMs: moment(sample?.time, `sample ${index} time`), value: sample?.value }));
27
+ try {
28
+ const peakUtcMs = input.peak === undefined ? undefined : moment(input.peak, "peak");
29
+ const [window] = createWindows([{
30
+ id,
31
+ label: input.label,
32
+ ...(input.type === undefined ? {} : { type: input.type }),
33
+ startUtcMs: moment(input.start, "start"),
34
+ endUtcMs: moment(input.end, "end"),
35
+ ...(peakUtcMs === undefined ? {} : { peakUtcMs }),
36
+ rate: { unit: input.unit, samples },
37
+ ...(input.provenance === undefined ? {} : { provenance: input.provenance.map((span, index) => ({ startUtcMs: moment(span?.start, `provenance ${index} start`), endUtcMs: moment(span?.end, `provenance ${index} end`), provenance: createProvenance(span?.provenance) })) }),
38
+ }]);
39
+ const atPeak = peakUtcMs === undefined ? null : rateAt(window, peakUtcMs);
40
+ return { window: window, peakValue: atPeak ?? Math.max(...samples.map((sample) => sample.value)), peakLabel: input.peakLabel ?? "Peak" };
41
+ }
42
+ catch (error) {
43
+ if (error instanceof SceneError)
44
+ throw error;
45
+ throw bad(id, error instanceof Error ? error.message : String(error));
46
+ }
47
+ }
48
+ /** The live rate bar of an activity at a moment: the rate (unavailable outside the activity) against its peak. */
49
+ export function rateMetricOf(groupId, activity, timeUtcMs) {
50
+ const { window } = activity;
51
+ return {
52
+ kind: "rate",
53
+ id: `${groupId}-rate`,
54
+ label: "Activity rate",
55
+ value: rateAt(window, timeUtcMs),
56
+ unit: window.rate?.unit ?? "",
57
+ digits: activity.peakValue >= 10 ? 0 : 1,
58
+ context: window.label,
59
+ unavailable: "outside the activity",
60
+ peak: { label: activity.peakLabel, value: activity.peakValue },
61
+ };
62
+ }
@@ -7,34 +7,58 @@ export interface BodyRef {
7
7
  }
8
8
  /** Ready-made bodies for `addBody`; the Sun, Earth, Moon and planets have their positions and pictures in the engine. */
9
9
  export declare const sun: BodyRef;
10
+ /** Mercury. */
10
11
  export declare const mercury: BodyRef;
12
+ /** Venus. */
11
13
  export declare const venus: BodyRef;
14
+ /** Earth. */
12
15
  export declare const earth: BodyRef;
16
+ /** Moon. */
13
17
  export declare const moon: BodyRef;
18
+ /** Mars. */
14
19
  export declare const mars: BodyRef;
20
+ /** Jupiter. */
15
21
  export declare const jupiter: BodyRef;
22
+ /** Saturn. */
16
23
  export declare const saturn: BodyRef;
24
+ /** Uranus. */
17
25
  export declare const uranus: BodyRef;
26
+ /** Neptune. */
18
27
  export declare const neptune: BodyRef;
28
+ /** Pluto. */
19
29
  export declare const pluto: BodyRef;
20
30
  /**
21
31
  * Moons need their planet's positions package (`astraeus-data-<planet>`, 120 MB of fits in all, split per planet) passed to `mount`; their maps come from
22
32
  * `astraeus-data` when it is passed too, and without it they are plain coloured spheres. They are not offered without the positions.
23
33
  */
24
34
  export declare const io: BodyRef;
35
+ /** Europa (needs `astraeus-data-jupiter`). */
25
36
  export declare const europa: BodyRef;
37
+ /** Ganymede (needs `astraeus-data-jupiter`). */
26
38
  export declare const ganymede: BodyRef;
39
+ /** Callisto (needs `astraeus-data-jupiter`). */
27
40
  export declare const callisto: BodyRef;
41
+ /** Mimas (needs `astraeus-data-saturn`). */
28
42
  export declare const mimas: BodyRef;
43
+ /** Enceladus (needs `astraeus-data-saturn`). */
29
44
  export declare const enceladus: BodyRef;
45
+ /** Tethys (needs `astraeus-data-saturn`). */
30
46
  export declare const tethys: BodyRef;
47
+ /** Dione (needs `astraeus-data-saturn`). */
31
48
  export declare const dione: BodyRef;
49
+ /** Rhea (needs `astraeus-data-saturn`). */
32
50
  export declare const rhea: BodyRef;
51
+ /** Titan (needs `astraeus-data-saturn`). */
33
52
  export declare const titan: BodyRef;
53
+ /** Iapetus (needs `astraeus-data-saturn`). */
34
54
  export declare const iapetus: BodyRef;
55
+ /** Triton (needs `astraeus-data-neptune`). */
35
56
  export declare const triton: BodyRef;
57
+ /** Charon (needs `astraeus-data-pluto`). */
36
58
  export declare const charon: BodyRef;
59
+ /** Phobos (needs `astraeus-data-mars`). */
37
60
  export declare const phobos: BodyRef;
61
+ /** Deimos (needs `astraeus-data-mars`). */
38
62
  export declare const deimos: BodyRef;
39
63
  /** The ready-made reference for a catalogued id, so `addBody("titan")` knows Titan needs `astraeus-data-saturn`. */
40
64
  export declare const readyMade: (id: BodyId) => BodyRef | undefined;
package/src/api/bodies.js CHANGED
@@ -1,34 +1,58 @@
1
1
  const ref = (id, label, requires) => Object.freeze({ id, label, ...(requires === undefined ? {} : { requires }) });
2
2
  /** Ready-made bodies for `addBody`; the Sun, Earth, Moon and planets have their positions and pictures in the engine. */
3
3
  export const sun = ref("sun", "Sun");
4
+ /** Mercury. */
4
5
  export const mercury = ref("mercury", "Mercury");
6
+ /** Venus. */
5
7
  export const venus = ref("venus", "Venus");
8
+ /** Earth. */
6
9
  export const earth = ref("earth", "Earth");
10
+ /** Moon. */
7
11
  export const moon = ref("moon", "Moon");
12
+ /** Mars. */
8
13
  export const mars = ref("mars", "Mars");
14
+ /** Jupiter. */
9
15
  export const jupiter = ref("jupiter", "Jupiter");
16
+ /** Saturn. */
10
17
  export const saturn = ref("saturn", "Saturn");
18
+ /** Uranus. */
11
19
  export const uranus = ref("uranus", "Uranus");
20
+ /** Neptune. */
12
21
  export const neptune = ref("neptune", "Neptune");
22
+ /** Pluto. */
13
23
  export const pluto = ref("pluto", "Pluto");
14
24
  /**
15
25
  * Moons need their planet's positions package (`astraeus-data-<planet>`, 120 MB of fits in all, split per planet) passed to `mount`; their maps come from
16
26
  * `astraeus-data` when it is passed too, and without it they are plain coloured spheres. They are not offered without the positions.
17
27
  */
18
28
  export const io = ref("io", "Io", "astraeus-data-jupiter");
29
+ /** Europa (needs `astraeus-data-jupiter`). */
19
30
  export const europa = ref("europa", "Europa", "astraeus-data-jupiter");
31
+ /** Ganymede (needs `astraeus-data-jupiter`). */
20
32
  export const ganymede = ref("ganymede", "Ganymede", "astraeus-data-jupiter");
33
+ /** Callisto (needs `astraeus-data-jupiter`). */
21
34
  export const callisto = ref("callisto", "Callisto", "astraeus-data-jupiter");
35
+ /** Mimas (needs `astraeus-data-saturn`). */
22
36
  export const mimas = ref("mimas", "Mimas", "astraeus-data-saturn");
37
+ /** Enceladus (needs `astraeus-data-saturn`). */
23
38
  export const enceladus = ref("enceladus", "Enceladus", "astraeus-data-saturn");
39
+ /** Tethys (needs `astraeus-data-saturn`). */
24
40
  export const tethys = ref("tethys", "Tethys", "astraeus-data-saturn");
41
+ /** Dione (needs `astraeus-data-saturn`). */
25
42
  export const dione = ref("dione", "Dione", "astraeus-data-saturn");
43
+ /** Rhea (needs `astraeus-data-saturn`). */
26
44
  export const rhea = ref("rhea", "Rhea", "astraeus-data-saturn");
45
+ /** Titan (needs `astraeus-data-saturn`). */
27
46
  export const titan = ref("titan", "Titan", "astraeus-data-saturn");
47
+ /** Iapetus (needs `astraeus-data-saturn`). */
28
48
  export const iapetus = ref("iapetus", "Iapetus", "astraeus-data-saturn");
49
+ /** Triton (needs `astraeus-data-neptune`). */
29
50
  export const triton = ref("triton", "Triton", "astraeus-data-neptune");
51
+ /** Charon (needs `astraeus-data-pluto`). */
30
52
  export const charon = ref("charon", "Charon", "astraeus-data-pluto");
53
+ /** Phobos (needs `astraeus-data-mars`). */
31
54
  export const phobos = ref("phobos", "Phobos", "astraeus-data-mars");
55
+ /** Deimos (needs `astraeus-data-mars`). */
32
56
  export const deimos = ref("deimos", "Deimos", "astraeus-data-mars");
33
57
  const READY_MADE = [sun, mercury, venus, earth, moon, mars, jupiter, saturn, uranus, neptune, pluto, io, europa, ganymede, callisto, mimas, enceladus, tethys, dione, rhea, titan, iapetus, triton, charon, phobos, deimos];
34
58
  /** The ready-made reference for a catalogued id, so `addBody("titan")` knows Titan needs `astraeus-data-saturn`. */
@@ -1,5 +1,5 @@
1
1
  /** Why a scene call was refused; `code` is stable so a caller can branch on it. */
2
- export type SceneErrorCode = "unknown-body" | "duplicate-id" | "bad-time" | "bad-trajectory" | "bad-scale" | "missing-data" | "empty-scene" | "bad-element" | "no-orbit";
2
+ export type SceneErrorCode = "unknown-body" | "duplicate-id" | "bad-time" | "bad-trajectory" | "bad-scale" | "missing-data" | "empty-scene" | "bad-element" | "no-orbit" | "bad-anchor" | "bad-readout" | "bad-event" | "bad-panels" | "bad-timeline" | "bad-switch" | "bad-body" | "bad-group" | "bad-activity" | "bad-camera";
3
3
  /** The one error the public API throws for bad input; the message names the offending value. */
4
4
  export declare class SceneError extends RangeError {
5
5
  readonly code: SceneErrorCode;