astraeus 0.2.0 → 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 (59) hide show
  1. package/CHANGELOG.md +28 -0
  2. package/README.md +41 -5
  3. package/package.json +2 -1
  4. package/src/api/AstraeusScene.js +1 -1
  5. package/src/api/AstraeusScene.node.js +37 -0
  6. package/src/api/group.d.ts +7 -1
  7. package/src/api/index.d.ts +1 -0
  8. package/src/api/index.js +1 -0
  9. package/src/api/index.node.js +8 -0
  10. package/src/api/mount.js +3 -1
  11. package/src/api/mount.node.js +36 -0
  12. package/src/api/scene.d.ts +32 -6
  13. package/src/api/scene.js +123 -26
  14. package/src/api/story.d.ts +8 -2
  15. package/src/api/story.js +11 -0
  16. package/src/api/sunOrbit.d.ts +6 -0
  17. package/src/api/sunOrbit.js +24 -0
  18. package/src/app/App.d.ts +6 -2
  19. package/src/app/App.js +8 -4
  20. package/src/app/App.node.js +401 -0
  21. package/src/app/PanelLoadBoundary.d.ts +2 -1
  22. package/src/app/PanelLoadBoundary.js +2 -2
  23. package/src/app/SkyView.d.ts +3 -3
  24. package/src/app/SkyView.js +19 -10
  25. package/src/app/experienceDefinition.d.ts +8 -0
  26. package/src/app/sceneContentsHooks.js +2 -2
  27. package/src/app/sceneFrame.js +4 -3
  28. package/src/app/sceneFraming.d.ts +13 -0
  29. package/src/app/sceneFraming.js +22 -0
  30. package/src/app/skyModel.js +1 -1
  31. package/src/assets/pictures.d.ts +1 -1
  32. package/src/assets/sky.d.ts +4 -4
  33. package/src/assets/sky.js +12 -13
  34. package/src/core/bodies/io.js +1 -1
  35. package/src/core/bodies/jupiterData.js +2 -2
  36. package/src/core/bodies/jupiterMoons.js +8 -12
  37. package/src/core/bodies/moon.d.ts +8 -0
  38. package/src/core/bodies/moon.js +28 -5
  39. package/src/core/bodies/outerPlanetData.js +7 -7
  40. package/src/core/bodies/planetMoons.js +18 -27
  41. package/src/core/bodies/swiftTuttle.js +2 -0
  42. package/src/core/elementsBody.d.ts +2 -0
  43. package/src/core/elementsBody.js +3 -0
  44. package/src/core/moonTrajectory.js +3 -5
  45. package/src/core/planetModels.js +1 -1
  46. package/src/core/provenance.d.ts +6 -2
  47. package/src/core/provenance.js +3 -1
  48. package/src/shell/AstraeusShell.js +5 -3
  49. package/src/shell/AstraeusShell.node.js +225 -0
  50. package/src/shell/DisplaySwitches.js +1 -1
  51. package/src/shell/StoryPanelView.js +3 -1
  52. package/src/shell/TimelineBar.node.js +75 -0
  53. package/src/shell/TopBar.node.js +14 -0
  54. package/src/shell/experience.d.ts +2 -0
  55. package/src/shell/infoModel.js +3 -1
  56. package/src/shell/phone.css +1 -1
  57. package/src/shell/useDrawers.js +1 -1
  58. package/src/shell/useZoomThrough.d.ts +7 -0
  59. package/src/shell/useZoomThrough.js +51 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,34 @@
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
+
5
33
  ## 0.2.0
6
34
 
7
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).
package/README.md CHANGED
@@ -12,7 +12,11 @@ npm install astraeus react react-dom @react-three/fiber three
12
12
 
13
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
14
 
15
- 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.
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").
16
20
 
17
21
  ## A scene in about 20 lines
18
22
 
@@ -47,23 +51,33 @@ The full reference, generated from the types and doc comments, is at <https://as
47
51
  | `new Scene()` | An empty scene. Every method below returns the scene, so calls chain. |
48
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`. |
49
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. |
50
- | `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. `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`. |
51
- | `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 id joins the camera menu (`focus-<id>`, `follow-<id>`) and may be a panel's `object`. A mistake throws `bad-group`. |
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`. |
52
56
  | `scene.setTime(time)` | The moment the scene opens at. |
53
57
  | `scene.setScale(trueScale \| readableScale, { only? })` | The opening scale; the viewer can switch to the other unless `{ only: true }` offers that scale alone. |
54
- | `scene.addEvents(events, { provenance? })` | Timed events on the timeline: `[{ id, label, time, type? }]`, ids unique. `provenance` says where the times come from. May be called more than once. |
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. |
55
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. |
56
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`. |
57
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`. |
58
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")` |
59
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`. |
60
- | `scene.stateOf(id, time)` | The state (position km, velocity km/s) of an added path at a moment, for figures a story quotes. |
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. |
61
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. |
62
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. |
63
69
  | `mount(element, scene, { data? })` | Draws the scene with the full viewer. Returns `{ ready, unmount() }`. `data` is a list of data packages (below). |
64
70
  | `<AstraeusScene scene data? onReady? onError? />` | The same viewer as a React component (below). |
65
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. |
66
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
+
67
81
  Types (`State`, `Pictures`, `TextureRef`, `AssetLicence`, `DataSource`, `TrajectoryInput` and the like) are exported for TypeScript.
68
82
 
69
83
  ## In a React app
@@ -84,6 +98,28 @@ export const App = () => (
84
98
 
85
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.
86
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
+
87
123
  ## What `astraeus-data` adds
88
124
 
89
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,6 +1,6 @@
1
1
  {
2
2
  "name": "astraeus",
3
- "version": "0.2.0",
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",
@@ -16,6 +16,7 @@
16
16
  "exports": {
17
17
  ".": {
18
18
  "types": "./src/api/index.d.ts",
19
+ "node": "./src/api/index.node.js",
19
20
  "import": "./src/api/index.js"
20
21
  },
21
22
  "./style.css": "./src/app/style.css"
@@ -34,5 +34,5 @@ export function AstraeusScene({ scene, data, onReady, onError, className, style
34
34
  }
35
35
  return () => { open = false; };
36
36
  }, [scene]);
37
- return _jsx("div", { className: className, style: { ...FILL, ...style }, children: definition ? _jsx(App, { definition: definition }) : null });
37
+ return _jsx("div", { className: className, style: { ...FILL, isolation: "isolate", ...style }, children: definition ? _jsx(App, { definition: definition, writeTitle: false }) : null });
38
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
+ }
@@ -62,7 +62,13 @@ export interface GroupInput {
62
62
  readonly refillAfterMs?: number;
63
63
  /** Milliseconds of each frame the dots layer may spend computing the next fill ahead of time, so a large group does not hitch; 0 or a positive number. 0 makes every fill whole in one frame. Presentation only. Default 8. */
64
64
  readonly refillSliceMs?: number;
65
- /** Where the orbit list came from. The group still marks the position along each orbit as illustrative. Defaults to an "as supplied" notice. */
65
+ /**
66
+ * Where the orbit list came from. The group's own card always shows `sourceType` "illustrative", because the position along each orbit is a drawing choice;
67
+ * the orbits' `sourceType` here is kept in the accuracy line as "Orbit elements are as listed (<sourceType>); the position along each orbit is illustrative."
68
+ * Your `sources` stay, and the group appends this note to your `notes`: "Each orbit's shape and orientation come from its record, but the records give no
69
+ * position along the orbit: that position is an even spread of mean anomaly at the reference time, a drawing choice (illustrative), advanced by unperturbed
70
+ * two-body motion about the centre." (plus a sentence naming the clump, when `clump` is set). Defaults to an "as supplied" notice.
71
+ */
66
72
  readonly provenance?: Provenance;
67
73
  /** One or two plain sentences for the info card; a count and placement sentence when absent. */
68
74
  readonly description?: string;
@@ -10,3 +10,4 @@ export type { State } from "../core/state.js";
10
10
  export type { Provenance, ProvenanceSourceType } from "../core/provenance.js";
11
11
  export type { Pictures } from "../assets/pictures.js";
12
12
  export type { AssetLicence, TextureRef } from "../assets/licence.js";
13
+ export { APPROXIMATE_LIMIT_FRACTION, INDICATIVE_LIMIT_FRACTION, classifyPositionError, parseElementsBodyRecord, type AccuracyClassification } from "../core/elementsBody.js";
package/src/api/index.js CHANGED
@@ -5,3 +5,4 @@ export { AstraeusScene } from "./AstraeusScene.js";
5
5
  export { SceneError } from "./errors.js";
6
6
  export { 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 } from "./bodies.js";
7
7
  export { trueScale, readableScale } from "../core/scalePolicy.js";
8
+ export { APPROXIMATE_LIMIT_FRACTION, INDICATIVE_LIMIT_FRACTION, classifyPositionError, parseElementsBodyRecord } from "../core/elementsBody.js";
@@ -0,0 +1,8 @@
1
+ // The engine's public API (0.2 preview): everything not exported here is internal.
2
+ export { Scene, SceneCamera } from "./scene.js";
3
+ export { mount } from "./mount.node.js";
4
+ export { AstraeusScene } from "./AstraeusScene.node.js";
5
+ export { SceneError } from "./errors.js";
6
+ export { 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 } from "./bodies.js";
7
+ export { trueScale, readableScale } from "../core/scalePolicy.js";
8
+ export { APPROXIMATE_LIMIT_FRACTION, INDICATIVE_LIMIT_FRACTION, classifyPositionError, parseElementsBodyRecord } from "../core/elementsBody.js";
package/src/api/mount.js CHANGED
@@ -17,11 +17,13 @@ export function mount(element, scene, options = {}) {
17
17
  if (!(element instanceof Object) || typeof element.appendChild !== "function")
18
18
  throw new SceneError("bad-element", "mount: the first argument must be an element of the page");
19
19
  const { definition, ready: loaded } = prepareScene(scene, options.data);
20
+ // Its own stacking context, so the viewer's z-index values cannot rise above the host page's overlays.
21
+ element.style.isolation = "isolate";
20
22
  const root = createRoot(element);
21
23
  let open = true;
22
24
  const ready = loaded.then(() => {
23
25
  if (open)
24
- root.render(createElement(App, { definition }));
26
+ root.render(createElement(App, { definition, writeTitle: false }));
25
27
  });
26
28
  return {
27
29
  ready,
@@ -0,0 +1,36 @@
1
+ import { createElement } from "react";
2
+ import { createRoot } from "react-dom/client";
3
+ import { App } from "../app/App.node.js";
4
+ import { SceneError } from "./errors.js";
5
+ import { prepareScene } from "./prepared.js";
6
+ /**
7
+ * Draws `scene` into `element` with the full viewer. The caller writes no React. The element needs a size.
8
+ * @example
9
+ * import { Scene, earth, moon, mount } from "astraeus";
10
+ * const scene = new Scene().addBody(earth).addBody(moon, { orbit: true });
11
+ * const mounted = mount(document.getElementById("app")!, scene);
12
+ * await mounted.ready; // drawn
13
+ * mounted.unmount(); // removes it again
14
+ */
15
+ export function mount(element, scene, options = {}) {
16
+ if (!(element instanceof Object) || typeof element.appendChild !== "function")
17
+ throw new SceneError("bad-element", "mount: the first argument must be an element of the page");
18
+ const { definition, ready: loaded } = prepareScene(scene, options.data);
19
+ // Its own stacking context, so the viewer's z-index values cannot rise above the host page's overlays.
20
+ element.style.isolation = "isolate";
21
+ const root = createRoot(element);
22
+ let open = true;
23
+ const ready = loaded.then(() => {
24
+ if (open)
25
+ root.render(createElement(App, { definition, writeTitle: false }));
26
+ });
27
+ return {
28
+ ready,
29
+ unmount() {
30
+ if (!open)
31
+ return;
32
+ open = false;
33
+ root.unmount();
34
+ },
35
+ };
36
+ }
@@ -101,16 +101,30 @@ export interface FollowView {
101
101
  /** The scene's camera: what it opens on. */
102
102
  export declare class SceneCamera {
103
103
  #private;
104
- constructor(has: (id: string) => boolean);
104
+ constructor(has: (id: string) => boolean, circlesSun: (id: string) => boolean);
105
105
  /** Opens framed on a body or trajectory already added to the scene and already following it (the viewer's Follow button shows as pressed). */
106
106
  follow(id: string, view?: FollowView): this;
107
107
  /** Opens framed on a body or trajectory already added to the scene, looking at it but not following it (the viewer's Focus button shows as pressed). The last of `follow` and `lookAt` wins. */
108
108
  lookAt(id: string, view?: FollowView): this;
109
109
  /**
110
110
  * Sets how far the viewer can zoom out from what they look at, in Earth radii (the scene's scaled unit); a finite number above 0, else `bad-camera`.
111
+ * Also sets the camera's far plane (where drawing stops) to 2.5 times `distance`, so what lies out to the reach is still drawn.
111
112
  * Labels reach as far: a body's label stays shown at any distance the camera can take. Without this call the camera frames the scene as before.
113
+ * `setReach` and `fitOrbit` set the same limit, so the later call wins and replaces the earlier one.
112
114
  */
113
115
  setReach(distance: number): this;
116
+ /**
117
+ * Sets the farthest zoom-out so the whole orbit of a body circling the Sun (a planet, a built-in comet or one from `addBodyFromElements`, already added to the scene) fits the canvas
118
+ * from any view direction: the orbit's farthest Sun distance divided by the sine of the narrower half field of view of the canvas (vertical 45 degrees, or horizontal from the
119
+ * canvas's width over height), with 10 percent to spare. The viewer fits again whenever the canvas changes shape, such as a phone turning or a window resizing; the far plane follows
120
+ * as for `setReach`. The opening view does not move. Any other body throws `bad-camera` naming it; an id not in the scene throws `unknown-body`. `setReach` and `fitOrbit` set the
121
+ * same limit, so the later call wins and replaces the earlier one.
122
+ * @example
123
+ * scene.camera.fitOrbit("c-2025-a1");
124
+ */
125
+ fitOrbit(body: BodyRef | BodyId): this;
126
+ /** The body `fitOrbit` fits the zoom-out to, if any. */
127
+ get fitted(): string | undefined;
114
128
  /** The farthest zoom-out set with `setReach`, if any. */
115
129
  get reach(): number | undefined;
116
130
  get target(): string | undefined;
@@ -147,7 +161,7 @@ export declare class Scene {
147
161
  addTrajectory(input: TrajectoryInput): this;
148
162
  /**
149
163
  * Adds a group of listed orbits drawn as one set of dots (one colour and dot size, one menu item and info card), with an optional clump near a body.
150
- * The orbits circle the scene's centre unless `center` names another body. A repeated id throws `duplicate-id`; an empty list, a bad orbit, colour, clump or centre throws `bad-group`.
164
+ * The orbits circle the scene's centre unless `center` names another body. A repeated id throws `duplicate-id`; an empty list, a bad orbit, colour or clump throws `bad-group`. A `center` that is not a catalogued body throws `unknown-body`; a catalogued one the finished scene does not hold throws `bad-group` from `toDefinition`.
151
165
  * @example
152
166
  * scene.addGroup({ id: "ring", orbits: [{ id: "a", semiMajorAxisKm: 90_000, eccentricity: 0.1, inclinationDeg: 5, raanDeg: 40, argumentOfPeriapsisDeg: 70 }], color: "#9de3a8" });
153
167
  */
@@ -165,11 +179,14 @@ export declare class Scene {
165
179
  setScale(scale: ScalePolicy, options?: {
166
180
  readonly only?: boolean;
167
181
  }): this;
168
- /** Adds timed events to the timeline, each with an id, a label and a moment; `provenance` says where the times come from and is shown with every event. May be called more than once. */
182
+ /** Adds timed events to the timeline, each with an id, a label and a moment; `provenance` says where the times come from and is shown with every event that has none of its own (`EventInput.provenance`). May be called more than once. Malformed provenance throws "bad-event". */
169
183
  addEvents(events: readonly EventInput[], options?: AddEventsOptions): this;
170
- /** Adds story panels that open as playback reaches them. Their times may name events (`addEvents`) and path anchors, and `object` a body or path; these are checked when the scene is built (`mount`), and a mistake throws `bad-panels` naming the panel and field. */
184
+ /**
185
+ * Adds story panels that open as playback reaches them. A panel opens only when forward playback crosses its time, so one at the opening instant never opens by itself
186
+ * (a panel with an `object` still has its marker on that object). `at.utc` may be any instant inside the timeline, in any year. Their times may name events (`addEvents`) and path anchors, and `object` a body or path; these are checked when the scene is built (`mount`), and a mistake throws `bad-panels` naming the panel and field.
187
+ */
171
188
  addStoryPanels(panels: StoryPanelsInput): this;
172
- /** Sets the timeline: its span (`start`, `end`), the speeds offered (`rates`), the speed it opens at (`rate`) and whether playback wraps from the end to the start (`loop`), or `{ none: true }` for no timeline bar, with time frozen at `at` or running at `rate`. Without this call the span follows the paths and the speeds are 1 minute, 1 hour and 1 day per second. */
189
+ /** Sets the timeline: its span (`start`, `end`), the speeds offered (`rates`), the speed it opens at (`rate`) and whether playback wraps from the end to the start (`loop`; ignored with `{ none: true }`, which has no span to wrap, and when `setTimeline` is not called), or `{ none: true }` for no timeline bar, with time frozen at `at` or running at `rate`. Without this call the span follows the paths and the speeds are 1 minute, 1 hour and 1 day per second. */
173
190
  setTimeline(timeline: TimelineInput): this;
174
191
  /**
175
192
  * Places the display switches: for each of `orbitLines` (orbit ring, trailing arc and moon orbits), `labels` (body and anchor labels) and `milkyWay` (the sky picture), `place` is
@@ -180,8 +197,17 @@ export declare class Scene {
180
197
  * scene.setSwitches({ orbitLines: { place: "top-bar" }, labels: { place: "panel", on: false }, milkyWay: { place: "developer", on: false } });
181
198
  */
182
199
  setSwitches(switches: SwitchesInput): this;
183
- /** The state of a trajectory added with `addTrajectory` at a moment, about its centre body (position in km, velocity in km/s): for figures a story quotes, such as a peak speed. Throws `unknown-body` for any other id and `bad-time` for a moment outside the path. */
200
+ /**
201
+ * The state of a body in the scene at a moment (position in km always; velocity in km/s only where the body's source provides it), the same State the viewer draws: for a path added with `addTrajectory`, about its centre body;
202
+ * for a ready-made body or one from `addBodyFromElements`, about its parent (a planet about the Sun, a moon about its planet). Figures a story quotes, such as a distance from the Sun, come from here. `velocityKmS` is set only for a path whose
203
+ * samples or provider carry velocities and for a moon from fitted data (Io); planets, Earth, the Sun, the built-in comet and elements bodies give position only, so check it before use. An id the scene does not hold throws `unknown-body`. Ready-made and elements bodies answer at any date (they have no data cut-off); only a moment outside an
204
+ * `addTrajectory` path throws `bad-time`. A planet before the planet series have loaded (they load at mount) throws `missing-data`.
205
+ * @example
206
+ * const sunDistanceKm = Math.hypot(...scene.stateOf("earth", "2026-08-12T00:00:00Z").positionKm);
207
+ */
184
208
  stateOf(id: string, time: TimeInput): State;
209
+ /** The Provenance of a body's position, as its info card shows it: for a ready-made or elements body the catalogue's position record, for a path the one passed to `addTrajectory`. Carries `accuracyClass` and `maxErrorFraction` where a comparison with an independent ephemeris exists. An id the scene does not hold throws `unknown-body`. */
210
+ provenanceOf(id: string): Provenance;
185
211
  /** The data packages the added bodies need that `data` does not provide. */
186
212
  missingData(data?: readonly DataSource[]): readonly string[];
187
213
  /** The app's plug-in contract for this scene. Throws if the scene is empty or a body needs a data package not passed in `data`. */