@johnmorrisdotca/wakusei-planets 0.22.0 → 0.24.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.
package/CHANGELOG.md CHANGED
@@ -2,6 +2,14 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.24.0] - 2026-11-08
6
+
7
+ - **Every view zooms and pans by itself** (MODULES-642). `<wakusei-body>`, `<wakusei-portrait>` and `<wakusei-space>` carry the shared view controls (kazoku-ui 0.21.1, `carryControls`): a drag, a pinch, Ctrl, Command or Alt with the wheel (the plain wheel still scrolls the page at Fit), and the arrows, `+`, `-` and `0` once focused. `controls="none"` turns them off, `live="off"` starts a body without them, `zoom-min` and `zoom-max` set the range. The ranges: the body's line look 0.1x to 50x (vector, detail at any scale), its shaded looks and the portrait 0.1x to 8x (the 2048 pixel painted maps are sharp to about 1.5x and soften after that), the space view a millionth to 3x (the camera is held 1.05 radii from the surface). A `<kazoku-view-controls>` takes over and reads the range; point its `for` at the element itself. `wakusei-view` is sent when the view changes, `space.controller` is the shared controller, and `<wakusei-portrait>` has `setView`. `embed.html` zooms with the drag, pinch, wheel, keys and + and - buttons and keeps the view in its address (`zoom=2`; the view's tilt is `vtilt`), and `embedCode` takes `zoom` for the iframe way. The code builder's picture zooms too. See the new Zoom and pan guide.
8
+
9
+ ## [0.23.0] - 2026-11-08
10
+
11
+ - **`/nearest`: what is nearby, and when bodies come close** (MODULES-651). `nearest(target, { count, within, kind, bodies, by, date, observer })` lists the Sun, planets, dwarf planets and moons nearest to a body on a date, by the angle between them in the sky of the Earth's centre, a place on the Earth (the Moon's parallax counts) or another body (`by: "sky"`, exact near 0 and 180 degrees, astrometric as Horizons' RA and DEC are) or by the distance between their centres (`by: "space"`, km and au); `within(target, radius, options)` lists all inside a radius; `closestApproach(a, b, { from, to })` and `conjunctions({ from, to, within, bodies })` scan a span in coarse steps (the fastest body's period over 40, at most 2 days) and narrow each minimum to about a second of time by golden-section search. Every result carries the accuracy to expect from the theories (`uncertaintyArcseconds` or `uncertaintyKm`, and `uncertaintySeconds` for the moment), with the part of the error that two bodies share cancelled. Against JPL Horizons (`test/data/horizons-approach.json`, `scripts/fetch-horizons-approach.py`): the Jupiter-Saturn great conjunction of 2020-12-21 within 270 s and 0.27 arc-second, Venus and Jupiter of 2023-03-02 within 23 s and 0.54, the Moon's nine closest approaches to the planets in December 2026 within 8 s and 1.5 arc-seconds, and the Moon and Venus from Vancouver within 0.9 arc-second; also against a brute-force scan. `distance(a, b, date)` is the straight-line distance of any two bodies in km and au; `distanceRange(a, b, { from, to })` is the least and the greatest distance over a span, each with its moment, found the same way (the greatest on the negated distance): Earth and Mars come to 0.3727 au on 2003-08-27 and go to 2.676 au in 2066, and the guide tabulates every pair of planets for 1900 to 2100 (`scripts/distance-table.ts`); on three pairs against Horizons (`test/data/horizons-distance.json`, `scripts/fetch-horizons-distance.py`) the distances are within 4,000 km, inside the claimed uncertainty. A year's search of the Sun and the planets takes 18 ms (`scripts/bench-nearest.ts`). A separate entry point that nothing else imports. EN/JA guide `docs/guides/nearest.md`.
12
+
5
13
  ## [0.22.0] - 2026-11-08
6
14
 
7
15
  - **Moons follow published theories, and every planet is measured on 60 dates from 1800 to 2200** (MODULES-528, 511). Io, Europa, Ganymede and Callisto come from L1.2 (Lainey, Duriez and Vienne, IMCCE) and Mimas to Iapetus from TASS1.7 (Vienne and Duriez, IMCCE; the table as Orbiter keeps it, MIT, with its notice in NOTICE.md), as optional entry points `tables/galilean` and `tables/saturn-moons` that `tables` loads and the web component fetches by dynamic import only when it draws Jupiter's or Saturn's moons (its own chunk stays 68 kB gzipped, 68,286 bytes on 0.21.0; `test/lazy-size.test.ts`); on 60 dates Io is 0.11 degree from Horizons (0.19 before), Europa 0.04 (0.15), Ganymede 0.03 (0.36), Callisto 0.014 (0.14), Mimas 1.7 (9.0), Tethys 0.21 (0.61) and Iapetus 0.03 (0.88). The fitted orbits of the other moons now use Horizons for 1800 to 2199 instead of 1950 to 2050 (Phobos 4.0 degrees to 0.4 in 1800, Ariel 1.4 to 0.2, Nereid 13.5 to 4.6). `tables/vsop` is a finer VSOP87B cut (2,581 terms, 32 kB gzipped, not in `tables`): every planet within 2 arc-seconds of Horizons on 60 dates; the default cut stays 13.8 kB and Jupiter and Neptune have their drift from DE441 taken out (Neptune 5.7 to 2.6 arc-seconds). New `test/accuracy-dense.test.ts`, `test/accuracy-fine.test.ts`, `test/moon-theories.test.ts` (the two ports reproduce IMCCE's published check values), `scripts/fetch-horizons-dense.py`, `scripts/compare/dense.mjs`; the accuracy limits only went down. A bundle of every export and optional table is 76,978 bytes gzipped, 11,318 more. GUST86 and ESAPHO/ESADEI are not used: their notice forbids passing on changed files.
package/README.md CHANGED
@@ -5,7 +5,7 @@
5
5
  <p align="center"><strong>The Sun, the planets and their moons, for the web.</strong><br>
6
6
  A clean line drawing, a shaded realistic drawing, or a painted surface map, with each body's real size, axial tilt and rotation as data, and a planet's moons where they are at any date and time.</p>
7
7
 
8
- <p align="center">Part of <strong>SpaceProgramX (SPX)</strong>, the space packages: <a href="https://github.com/johnmorrisdotca/wakusei-planets">Wakusei Planets</a> · <a href="https://github.com/johnmorrisdotca/hoshi-stars">Hoshi Stars</a> · <a href="https://github.com/johnmorrisdotca/chikyu-earth">Chikyu Earth</a> · <a href="https://github.com/johnmorrisdotca/uchusen-rockets">Uchusen Rockets</a></p>
8
+ <p align="center">Part of <strong>Space Program X (SPX)</strong>, the space packages: <a href="https://github.com/johnmorrisdotca/wakusei-planets">Wakusei Planets</a> · <a href="https://github.com/johnmorrisdotca/hoshi-stars">Hoshi Stars</a> · <a href="https://github.com/johnmorrisdotca/chikyu-earth">Chikyu Earth</a> · <a href="https://github.com/johnmorrisdotca/uchusen-rockets">Uchusen Rockets</a></p>
9
9
 
10
10
  <p align="center">
11
11
  <a href="https://github.com/johnmorrisdotca/wakusei-planets/actions/workflows/ci.yml"><img alt="CI" src="https://github.com/johnmorrisdotca/wakusei-planets/actions/workflows/ci.yml/badge.svg"></a>
@@ -15,9 +15,9 @@ A clean line drawing, a shaded realistic drawing, or a painted surface map, with
15
15
 
16
16
  <p align="center"><a href="https://johnmorrisdotca.github.io/wakusei-planets/"><strong>Open the demo →</strong></a> · <a href="https://johnmorrisdotca.github.io/wakusei-planets/embed.html">Embed page</a> · <a href="https://johnmorrisdotca.github.io/wakusei-planets/docs/">Docs</a></p>
17
17
 
18
- <p align="center"><img alt="Jupiter and Saturn drawn in the realistic look, and Saturn as a line drawing" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.22.0/docs/images/hero-desk.png" width="640"></p>
18
+ <p align="center"><img alt="Jupiter and Saturn drawn in the realistic look, and Saturn as a line drawing" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.24.0/docs/images/hero-desk.png" width="640"></p>
19
19
 
20
- <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.22.0/docs/images/lineup-desk.png" width="640"></p>
20
+ <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.24.0/docs/images/lineup-desk.png" width="640"></p>
21
21
 
22
22
  ## One minute
23
23
 
@@ -42,7 +42,7 @@ A page with no build step needs one tag. `look="line"` is an SVG and needs nothi
42
42
  </html>
43
43
  ```
44
44
 
45
- The same tag with the shared [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) controls, which turn, tip, zoom and pan the body:
45
+ Every view already turns, zooms and pans with a drag, a pinch, Ctrl and the wheel and the keys (the plain wheel still scrolls the page). To add the shared [kazoku-ui](https://github.com/johnmorrisdotca/kazoku-ui) bar, with buttons and sliders, point it at the tag:
46
46
 
47
47
  ```html
48
48
  <!doctype html>
@@ -62,10 +62,8 @@ The same tag with the shared [kazoku-ui](https://github.com/johnmorrisdotca/kazo
62
62
  </script>
63
63
  </head>
64
64
  <body>
65
- <div id="view" tabindex="0">
66
- <wakusei-body body="saturn" look="line" size="420"></wakusei-body>
67
- </div>
68
- <kazoku-view-controls for="view" address controls="advanced" tilt-max="90" speed="0"></kazoku-view-controls>
65
+ <wakusei-body id="planet" body="saturn" look="line" size="420" tabindex="0"></wakusei-body>
66
+ <kazoku-view-controls for="planet" address controls="advanced" speed="0"></kazoku-view-controls>
69
67
  </body>
70
68
  </html>
71
69
  ```
@@ -279,7 +277,7 @@ A body that turns by itself and a moving sky, in HTML:
279
277
 
280
278
  ## The portrait builder
281
279
 
282
- <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.22.0/docs/images/portrait-family.png" width="640"></p>
280
+ <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.24.0/docs/images/portrait-family.png" width="640"></p>
283
281
 
284
282
  [The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
285
283
 
@@ -290,6 +288,23 @@ A body that turns by itself and a moving sky, in HTML:
290
288
  <wakusei-portrait scene="look:painted~jupiter_0_0_0.3_0~io_0_0_0.1_0"></wakusei-portrait>
291
289
  ```
292
290
 
291
+ ## What is nearby, and when bodies come close
292
+
293
+ `/nearest` answers "what is next to this?" for the Sun, the planets, the dwarf planets and the moons. `nearest` and `within` list the bodies closest to one on a date, by the angle between them in the sky (of the Earth, a place on it or another body) or by the distance between them in space. `closestApproach` and `conjunctions` search a span of time: coarse steps, then each minimum narrowed to about a second. `distance` and `distanceRange` give two bodies' distance on a date and how near and far they get over a span (Earth and Mars: 0.373 to 2.676 au from 1900 to 2100, the guide has every planet pair). Every result carries the accuracy the theories are held to; against JPL Horizons the great conjunction of 2020 is within 270 s and 0.3 arc-seconds, and the Moon's approaches to the planets within 8 s and 1.5 arc-seconds. [The guide](docs/guides/nearest.md) has the options and the numbers.
294
+
295
+ ```ts
296
+ import { closestApproach, distanceRange, nearest } from "@johnmorrisdotca/wakusei-planets/nearest";
297
+
298
+ const planets = nearest("moon", { kind: "planet", count: 2, date: Date.UTC(2026, 11, 27, 16) });
299
+ console.log(planets.map((row) => `${row.id} ${row.angle.toFixed(2)} degrees`).join(", "));
300
+
301
+ const great = closestApproach("jupiter", "saturn", { from: Date.UTC(2020, 11, 1), to: Date.UTC(2021, 0, 1) });
302
+ console.log(great.time.toISOString(), great.angle?.toFixed(2), "degrees");
303
+
304
+ const mars = distanceRange("earth", "mars", { from: Date.UTC(1900, 0, 1), to: Date.UTC(2100, 0, 1) });
305
+ console.log(mars.min.distanceAu.toFixed(2), "to", mars.max.distanceAu.toFixed(2), "au");
306
+ ```
307
+
293
308
  ## The space view
294
309
 
295
310
  [The space view](https://johnmorrisdotca.github.io/wakusei-planets/space.html) puts the Earth, the Moon, the Sun and the planets in their places for any date and time, in one WebGL context: the Moon's phase and the Earth's day side come out of the real Sun's light. Zoom from the Earth out to the whole solar system, in a compressed scale (every direction real, the distances squeezed) or the true one, and run time forwards or backwards. Positions come from this package's own models.
@@ -318,6 +333,7 @@ The reference is a site, made from the source's own doc comments: every export h
318
333
  | `.../portrait` | `<wakusei-portrait>`: many bodies in one scene. The scene model (`addBody`, `layoutPortrait`, `encodeScene`, `decodeScene`) is in the main entry. |
319
334
  | `.../space` | Where the Sun, the Moon and the planets are for a date, in two scales, and where a camera riding along looks: `frameAt`, `createTrack`, `placeSun`, `placeAround`, `ridePose`. No browser. |
320
335
  | `.../space/element` | `<wakusei-space>`: the Earth, the Moon, the Sun and the planets in their places. |
336
+ | `.../nearest` | The bodies nearest to a body on a date (`nearest`, `within`), when two bodies come closest (`closestApproach`, `conjunctions`) and how far apart they are (`distance`, `distanceRange`). No browser. |
321
337
  | `.../look` | What a body needs to be drawn with three.js. |
322
338
  | `.../painter` | The bodies as objects for a scene of your own. |
323
339
  | `.../all` | Every body's shaded look, at once. |
@@ -346,11 +362,13 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
346
362
  | [Why two packages](docs/guides/two-packages.md) | This package and chikyu-earth: which to install, alone or together |
347
363
  | [Moons and time](docs/guides/moons-and-time.md) | The sky on a date, time that runs fast |
348
364
  | [The space view](docs/guides/space-view.md) | The Earth, Moon, Sun and planets in their places; two scales; time both ways |
365
+ | [Zoom and pan](docs/guides/zoom-and-pan.md) | Every view zooms and moves by itself: the range of each and why it ends there, the bar, the embed page |
349
366
  | [Riding along](docs/guides/ride-along.md) | The camera on a moon, a planet or any moving point, looking at what it goes round |
350
367
  | [Accuracy](docs/guides/accuracy.md) | How far each body is from JPL Horizons |
351
368
  | [In your own three.js scene](docs/guides/in-your-own-scene.md) | `painter.make` |
352
369
  | [Time](docs/guides/time.md) | Julian dates, calendars, time scales, sidereal time, Mars time |
353
370
  | [The stars you can see without a telescope](docs/guides/stars.md) | 5,080 stars with names, positions, proper motion, distance and colour |
371
+ | [What is nearby, and when bodies come close](docs/guides/nearest.md) | The nearest bodies to a body on a date, closest approaches and conjunctions, and how close they are to Horizons |
354
372
  | [Famous spacecraft](docs/guides/spacecraft.md) | Voyager, New Horizons, Pioneer, Cassini, Galileo, Juno, Parker and Webb: where they are and their whole voyage |
355
373
  | [The Sun and Moon from a place](docs/guides/suncalc.md) | Position, sunrise and sunset, Moon rise, set and phase; a drop-in for suncalc |
356
374
  | [Coordinate conversions](docs/guides/coordinates.md) | Pure spherical, ecliptic, equatorial and horizontal coordinate conversions |
package/dist/element.d.ts CHANGED
@@ -25,6 +25,10 @@ export type WakuseiState = "line" | "loading" | "still" | "live" | "lost" | "una
25
25
  * `tilt`, `pitch`, `phase` and `meridian` (a portrait's pose, degrees), `turn` (a portrait turns this many degrees a second; left out, 12 a second, backwards when the body is, and a date keeps its orientation and adds this turn; `live="off"` stays still unless this is set; `0` stays still; reduced motion keeps a quarter of it), `rate` (simulated seconds for each real second), `moons` (draw the planet's moons on their orbits),
26
26
  * `range` (planet radii the moons picture reaches), `scale-to` (draw to scale with another body), `span-km` (draw to scale: the half-width of the picture in kilometres, the same in every picture of a lineup), `live` (`always`, `hover` or `off`: when it takes the page's one WebGL context), `texture-base` (where the surface pictures are) and `lang` (`en` or `ja`).
27
27
  *
28
+ * It carries the shared view controls itself: a drag turns the body, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page at Fit), the arrow keys, + and - and 0 work once it is focused.
29
+ * `controls="none"` turns them off, and `live="off"` (a still, a thumbnail) starts without them (`controls` with no value brings them back). `zoom-min` and `zoom-max` set the range (0.1 to 8 for the shaded looks, 0.1 to 50 for the line drawing); a `<kazoku-view-controls for="...">` takes over and reads it.
30
+ * Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
31
+ *
28
32
  * @example
29
33
  * ```ts no-run
30
34
  * import { WakuseiBody } from "@johnmorrisdotca/wakusei-planets/element";
package/dist/element.js CHANGED
@@ -1,3 +1,4 @@
1
+ import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import "./tables/ceres.js";
2
3
  import "./tables/dwarfs.js";
3
4
  import { loadMoonTheory } from "./tables/lazy.js";
@@ -59,6 +60,13 @@ function clampPan(pan, extent, zoom) {
59
60
  const limit = 1 + 0.5 / half;
60
61
  return Math.max(-limit, Math.min(limit, pan));
61
62
  }
63
+ /**
64
+ * The zoom range of a body that carries its own controls. The floor is arbitrary: a tenth of Fit leaves room to see the whole body small. A line drawing is vector and has detail at any scale, so it goes to 50.
65
+ * The shaded looks stop at 8: the sharpest painted map is 2048 pixels round the body, sharp to about 1.5 times the size at Fit on a picture of the usual size and softening after that, and 8 times is as far as
66
+ * the shader's own detail (bands, craters, ring edges) carries before the map runs out.
67
+ */
68
+ const LINE_LIMITS = { zoomMin: 0.1, zoomMax: 50, tiltMax: 90 };
69
+ const SHADED_LIMITS = { zoomMin: 0.1, zoomMax: 8, tiltMax: 90 };
62
70
  const TEMPLATE = `<style>
63
71
  :host { display: block; width: var(--wakusei-size, 320px); max-width: 100%; aspect-ratio: 1 / 1; position: relative; contain: layout style; }
64
72
  #stage { position: absolute; inset: 0; }
@@ -71,6 +79,10 @@ const TEMPLATE = `<style>
71
79
  * `tilt`, `pitch`, `phase` and `meridian` (a portrait's pose, degrees), `turn` (a portrait turns this many degrees a second; left out, 12 a second, backwards when the body is, and a date keeps its orientation and adds this turn; `live="off"` stays still unless this is set; `0` stays still; reduced motion keeps a quarter of it), `rate` (simulated seconds for each real second), `moons` (draw the planet's moons on their orbits),
72
80
  * `range` (planet radii the moons picture reaches), `scale-to` (draw to scale with another body), `span-km` (draw to scale: the half-width of the picture in kilometres, the same in every picture of a lineup), `live` (`always`, `hover` or `off`: when it takes the page's one WebGL context), `texture-base` (where the surface pictures are) and `lang` (`en` or `ja`).
73
81
  *
82
+ * It carries the shared view controls itself: a drag turns the body, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page at Fit), the arrow keys, + and - and 0 work once it is focused.
83
+ * `controls="none"` turns them off, and `live="off"` (a still, a thumbnail) starts without them (`controls` with no value brings them back). `zoom-min` and `zoom-max` set the range (0.1 to 8 for the shaded looks, 0.1 to 50 for the line drawing); a `<kazoku-view-controls for="...">` takes over and reads it.
84
+ * Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
85
+ *
74
86
  * @example
75
87
  * ```ts no-run
76
88
  * import { WakuseiBody } from "@johnmorrisdotca/wakusei-planets/element";
@@ -117,6 +129,8 @@ export class WakuseiBody extends HTMLElement {
117
129
  #sceneState;
118
130
  #unsub;
119
131
  #reduce = false;
132
+ #hands;
133
+ #handsKey = "";
120
134
  #hover = () => void this.goLive();
121
135
  #onContext = (state) => {
122
136
  if (state === "unavailable")
@@ -179,8 +193,14 @@ export class WakuseiBody extends HTMLElement {
179
193
  this.#io.observe(this);
180
194
  }
181
195
  document.addEventListener("visibilitychange", this.#onHidden);
182
- this.#unsub = onRegister(() => this.#queue());
196
+ this.#unsub = onRegister(() => {
197
+ this.#carry();
198
+ this.#queue();
199
+ });
183
200
  this.#applyHover();
201
+ for (const name of ["pointerdown", "wheel", "keydown"])
202
+ this.addEventListener(name, this.#measure, true);
203
+ this.#carry();
184
204
  this.#queue();
185
205
  }
186
206
  disconnectedCallback() {
@@ -190,6 +210,11 @@ export class WakuseiBody extends HTMLElement {
190
210
  document.removeEventListener("visibilitychange", this.#onHidden);
191
211
  this.#unsub?.();
192
212
  this.#applyHover(false);
213
+ for (const name of ["pointerdown", "wheel", "keydown"])
214
+ this.removeEventListener(name, this.#measure, true);
215
+ this.#hands?.unbind();
216
+ this.#hands = undefined;
217
+ this.#handsKey = "";
193
218
  this.#disposeView(true);
194
219
  }
195
220
  attributeChangedCallback(name) {
@@ -199,6 +224,8 @@ export class WakuseiBody extends HTMLElement {
199
224
  this.#clockFromAttributes();
200
225
  if (name === "live")
201
226
  this.#applyHover();
227
+ if (name === "live" || name === "look" || name === "body")
228
+ this.#carry();
202
229
  this.#lastAnchors = -1;
203
230
  this.#queue();
204
231
  }
@@ -233,14 +260,38 @@ export class WakuseiBody extends HTMLElement {
233
260
  /** The shared controllers' camera: `yaw` turns the body about its pole, `tilt` tips its top away from you as it grows (a drag up moves the surface up), `roll` turns the picture clockwise about the line of sight, `zoom` scales it, and `panX` and `panY` move it by that many CSS pixels from the middle. */
234
261
  setView(view) {
235
262
  const half = Math.max(1, this.clientWidth) / 2;
236
- this.#yaw = view.yaw ?? 0;
237
- this.#tilt = view.tilt ?? 0;
238
- this.#roll = view.roll ?? 0;
239
- this.#zoom = view.zoom ?? 1;
240
- this.#panX = -(view.panX ?? 0) / half;
241
- this.#panY = (view.panY ?? 0) / half;
263
+ const [yaw, tilt, roll, zoom, panX, panY] = [view.yaw ?? 0, view.tilt ?? 0, view.roll ?? 0, view.zoom ?? 1, -(view.panX ?? 0) / half, (view.panY ?? 0) / half];
264
+ if (yaw === this.#yaw && tilt === this.#tilt && roll === this.#roll && zoom === this.#zoom && panX === this.#panX && panY === this.#panY)
265
+ return;
266
+ [this.#yaw, this.#tilt, this.#roll, this.#zoom, this.#panX, this.#panY] = [yaw, tilt, roll, zoom, panX, panY];
267
+ this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { yaw: this.#yaw, tilt: this.#tilt, roll: this.#roll, zoom: this.#zoom, panX: view.panX ?? 0, panY: view.panY ?? 0 } }));
242
268
  this.#queue(true);
243
269
  }
270
+ /** Take the shared hands, unless the picture is a still (`live="off"`) or another package's drawing (the Earth's line look); the look decides the zoom range, so a new look takes new hands. */
271
+ #carry() {
272
+ const on = this.getAttribute("live") !== "off" && !(this.look === "line" && delegates.has(this.body));
273
+ const key = `${on}|${this.look === "line"}`;
274
+ if (this.#handsKey === key)
275
+ return;
276
+ this.#hands?.unbind();
277
+ this.#handsKey = key;
278
+ this.#hands = carryControls(this, { on, limits: this.look === "line" ? LINE_LIMITS : SHADED_LIMITS, grabRadius: this.discRadius, objectSize: { width: this.discRadius * 2, height: this.discRadius * 2 }, onChange: (view) => this.setView(view) });
279
+ if (this.#zoom !== 1 || this.#yaw !== 0 || this.#tilt !== 0 || this.#panX !== 0 || this.#panY !== 0 || this.#roll !== 0) {
280
+ if (!this.hasAttribute("data-kazoku-bar"))
281
+ this.setView({});
282
+ }
283
+ }
284
+ /** The disc is a different size on the screen after the picture or the page is resized: a gesture is told before it starts. */
285
+ #measure = () => {
286
+ const controller = this.#hands?.controller;
287
+ if (controller === undefined)
288
+ return;
289
+ const disc = this.discRadius;
290
+ if (disc <= 0)
291
+ return;
292
+ controller.grabRadius = disc;
293
+ controller.objectSize = { width: disc * 2, height: disc * 2 };
294
+ };
244
295
  // --- the clock ------------------------------------------------------------------------------------------------------------------------------------
245
296
  #clockFromAttributes() {
246
297
  const t = readTime(this.getAttribute("time"));
package/dist/embed.d.ts CHANGED
@@ -44,6 +44,8 @@ export interface EmbedOptions {
44
44
  turn?: number;
45
45
  /** Pixels across. */
46
46
  size?: number;
47
+ /** How far in the embed page starts, as its `zoom` address key has it (1 is the whole body). Left out or 1, the page starts at Fit. Only the iframe way carries it: the element's own start is Fit. */
48
+ zoom?: number;
47
49
  }
48
50
  /**
49
51
  * Where the embed code points: the package's version on jsDelivr, and the published demo, where `embed.html` is.
package/dist/embed.js CHANGED
@@ -68,6 +68,8 @@ export function embedCode(options, kind = "html", settings = {}) {
68
68
  query.set("moons", "1");
69
69
  if (options.turn !== undefined && options.turn > 0)
70
70
  query.set("turn", String(options.turn));
71
+ if (options.zoom !== undefined && options.zoom !== 1 && Number.isFinite(options.zoom) && options.zoom > 0)
72
+ query.set("zoom", String(Math.round(options.zoom * 1000) / 1000));
71
73
  return snippet(kind, {
72
74
  tag: "wakusei-body",
73
75
  element: "element",
@@ -0,0 +1,344 @@
1
+ import { type BodyFacts, type BodyId } from "./facts.ts";
2
+ import type { Observer } from "./sky/types.ts";
3
+ import { type When } from "./when.ts";
4
+ /**
5
+ * What kind of body: the Sun is `"star"`.
6
+ *
7
+ * @example
8
+ * ```ts
9
+ * import { nearest, type NearestKind } from "@johnmorrisdotca/wakusei-planets/nearest";
10
+ *
11
+ * const kind: NearestKind = "planet";
12
+ * console.log(nearest("moon", { kind, count: 1, date: Date.UTC(2026, 10, 8) })[0]?.id);
13
+ * ```
14
+ */
15
+ export type NearestKind = BodyFacts["kind"];
16
+ /**
17
+ * Where the sky is seen from: a body's centre (`"mars"` for the sky of Mars), or a place on the Earth, whose parallax counts (the Moon is up to a degree different from there than from the Earth's centre). The default is the Earth's centre.
18
+ *
19
+ * @example
20
+ * ```ts
21
+ * import { nearest, type Viewpoint } from "@johnmorrisdotca/wakusei-planets/nearest";
22
+ *
23
+ * const vancouver: Viewpoint = { latitude: 49.28, longitude: -123.12 };
24
+ * console.log(nearest("moon", { observer: vancouver, count: 1, date: Date.UTC(2026, 10, 8) })[0]?.id);
25
+ * ```
26
+ */
27
+ export type Viewpoint = BodyId | Observer;
28
+ /**
29
+ * The options of `nearest`, `within`, `closestApproach` and `conjunctions` that mean the same in each.
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * import { nearest, type NearestOptions } from "@johnmorrisdotca/wakusei-planets/nearest";
34
+ *
35
+ * const options: NearestOptions = { count: 3, kind: "planet", date: Date.UTC(2026, 10, 8) };
36
+ * console.log(nearest("moon", options).map((row) => row.id).join(", "));
37
+ * ```
38
+ */
39
+ export interface NearestOptions {
40
+ /** How many to return. Default 5, or all of those inside `within` when `within` is given. */
41
+ count?: number;
42
+ /** Only those this close: degrees for `by: "sky"`, kilometres for `by: "space"`. */
43
+ within?: number;
44
+ /** Only this kind of body, or any of these kinds. */
45
+ kind?: NearestKind | readonly NearestKind[];
46
+ /** Search only these bodies. Default: every body. */
47
+ bodies?: readonly BodyId[];
48
+ /** `"sky"` (default): the angle between the two in the sky of the observer. `"space"`: the distance between their centres. */
49
+ by?: "sky" | "space";
50
+ /** The moment, a `Date` or milliseconds since 1970 (UTC). Default: now. */
51
+ date?: When;
52
+ /** Where the sky is seen from; ignored by `by: "space"`. Default: the Earth's centre. */
53
+ observer?: Viewpoint;
54
+ }
55
+ /**
56
+ * A body near the target in the sky: its angle from the target in degrees (0 to 180) and how far that angle may be off, in arc-seconds.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * import { nearest, type SkyNeighbour } from "@johnmorrisdotca/wakusei-planets/nearest";
61
+ *
62
+ * const next: SkyNeighbour | undefined = nearest("moon", { count: 1, date: Date.UTC(2026, 10, 8) })[0];
63
+ * console.log(next?.id, next?.angle.toFixed(1));
64
+ * ```
65
+ */
66
+ export interface SkyNeighbour {
67
+ id: BodyId;
68
+ kind: NearestKind;
69
+ /** The angle between the target and this body in the observer's sky, degrees. */
70
+ angle: number;
71
+ /** The accuracy to expect of `angle`, in arc-seconds: the limits the accuracy tests hold the theories to, combined. An expectation, not a bound. */
72
+ uncertaintyArcseconds: number;
73
+ }
74
+ /**
75
+ * A body near the target in space: the distance between their centres, and how far that may be off.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * import { nearest, type SpaceNeighbour } from "@johnmorrisdotca/wakusei-planets/nearest";
80
+ *
81
+ * const next: SpaceNeighbour | undefined = nearest("earth", { by: "space", count: 1, date: Date.UTC(2026, 10, 8) })[0];
82
+ * console.log(next?.id, Math.round(next?.distanceKm ?? 0));
83
+ * ```
84
+ */
85
+ export interface SpaceNeighbour {
86
+ id: BodyId;
87
+ kind: NearestKind;
88
+ /** The distance between the two centres at the date, kilometres. */
89
+ distanceKm: number;
90
+ /** The same in astronomical units. */
91
+ distanceAu: number;
92
+ /** The accuracy to expect of `distanceKm`, kilometres: the limits the accuracy tests hold the theories to, combined. An expectation, not a bound. */
93
+ uncertaintyKm: number;
94
+ }
95
+ /**
96
+ * The closest two bodies come in a span: the moment of the minimum and the separation then.
97
+ *
98
+ * @example
99
+ * ```ts
100
+ * import { closestApproach, type Approach } from "@johnmorrisdotca/wakusei-planets/nearest";
101
+ *
102
+ * const found: Approach = closestApproach("jupiter", "saturn", { from: Date.UTC(2020, 11, 1), to: Date.UTC(2021, 0, 1) });
103
+ * console.log(found.time.toISOString(), found.angle?.toFixed(2));
104
+ * ```
105
+ */
106
+ export interface Approach {
107
+ a: BodyId;
108
+ b: BodyId;
109
+ /** The moment of the minimum, to about a second of time. */
110
+ time: Date;
111
+ /** Degrees, for `by: "sky"`. */
112
+ angle?: number;
113
+ /** The accuracy to expect of `angle`, arc-seconds, for `by: "sky"`. */
114
+ uncertaintyArcseconds?: number;
115
+ /** Kilometres, for `by: "space"`. */
116
+ distanceKm?: number;
117
+ /** Astronomical units, for `by: "space"`. */
118
+ distanceAu?: number;
119
+ /** The accuracy to expect of `distanceKm`, for `by: "space"`. */
120
+ uncertaintyKm?: number;
121
+ /** How far the moment may be off, in seconds: the position's accuracy over how fast the two move past each other. */
122
+ uncertaintySeconds: number;
123
+ /** True when the smallest separation in the span is at its start or end, not a minimum inside it. */
124
+ atEdge: boolean;
125
+ }
126
+ /**
127
+ * Where a search looks, and what counts as close.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * import { closestApproach, type ApproachOptions } from "@johnmorrisdotca/wakusei-planets/nearest";
132
+ *
133
+ * const options: ApproachOptions = { from: Date.UTC(2023, 1, 20), to: Date.UTC(2023, 2, 10) };
134
+ * console.log(closestApproach("venus", "jupiter", options).time.toISOString());
135
+ * ```
136
+ */
137
+ export interface ApproachOptions {
138
+ /** The start of the span, a `Date` or milliseconds since 1970 (UTC). */
139
+ from: When;
140
+ /** The end of the span. */
141
+ to: When;
142
+ /** `"sky"` (default) or `"space"`, as in `nearest`. */
143
+ by?: "sky" | "space";
144
+ /** Where the sky is seen from; ignored by `by: "space"`. Default: the Earth's centre. */
145
+ observer?: Viewpoint;
146
+ }
147
+ /**
148
+ * The options of `conjunctions`.
149
+ *
150
+ * @example
151
+ * ```ts
152
+ * import { conjunctions, type ConjunctionOptions } from "@johnmorrisdotca/wakusei-planets/nearest";
153
+ *
154
+ * const options: ConjunctionOptions = { from: Date.UTC(2020, 11, 1), to: Date.UTC(2021, 0, 1), bodies: ["jupiter", "saturn"], within: 1 };
155
+ * console.log(conjunctions(options).length);
156
+ * ```
157
+ */
158
+ export interface ConjunctionOptions extends ApproachOptions {
159
+ /** Only closest approaches this small: degrees for `by: "sky"` (default 5), kilometres for `by: "space"` (default: all). */
160
+ within?: number;
161
+ /** The bodies to pair up. Default: the Sun and Mercury to Neptune, without the Earth's own place. */
162
+ bodies?: readonly BodyId[];
163
+ }
164
+ /**
165
+ * The bodies nearest to a body on a date, nearest first: by the angle between them in the sky of an observer, or by the distance between them in space. The Sun, the planets, the dwarf planets and the moons are searched; the target itself, and the body the sky is seen from, are not in the answer.
166
+ *
167
+ * A sky angle is astrometric: the observer's place at the date, each body where it was when its light left (a second and a half for the Moon, hours for Neptune), with no aberration or light bending. It is the angle between two centres, found with an arc tangent so that it is as exact near 0 and 180 degrees as at 90. A distance is the straight line between the two centres at that instant, with no light time. Every result carries the accuracy to expect from the theories (the accuracy guide's limits, combined).
168
+ *
169
+ * @param target - The body to look around.
170
+ * @param options - `count` (default 5; all inside `within` when that is given), `within` (degrees for `by: "sky"`, kilometres for `by: "space"`), `kind`, `bodies` (search only these), `by`, `date` (default now) and `observer` (default the Earth's centre).
171
+ * @returns The bodies, nearest first, as `{ id, kind, angle, uncertaintyArcseconds }` for the sky and `{ id, kind, distanceKm, distanceAu, uncertaintyKm }` for space.
172
+ * @throws RangeError for a target, kind, body, count, radius or observer that is not valid, and for a sky target that is the observer's own body.
173
+ *
174
+ * @example
175
+ * ```ts
176
+ * import { nearest } from "@johnmorrisdotca/wakusei-planets/nearest";
177
+ *
178
+ * const date = Date.UTC(2020, 11, 21, 18);
179
+ * console.log(nearest("jupiter", { count: 2, kind: "planet", date }).map((row) => `${row.id} ${row.angle.toFixed(2)}`).join(", "));
180
+ * console.log(nearest("earth", { by: "space", kind: "planet", count: 2, date }).map((row) => `${row.id} ${row.distanceAu.toFixed(2)} au`).join(", "));
181
+ * ```
182
+ */
183
+ export declare function nearest(target: BodyId, options: NearestOptions & {
184
+ by: "space";
185
+ }): SpaceNeighbour[];
186
+ export declare function nearest(target: BodyId, options?: NearestOptions & {
187
+ by?: "sky";
188
+ }): SkyNeighbour[];
189
+ export declare function nearest(target: BodyId, options: NearestOptions): SkyNeighbour[] | SpaceNeighbour[];
190
+ /**
191
+ * Every body inside a radius of a body on a date, nearest first: `nearest` with no limit on how many. The radius is degrees for `by: "sky"` and kilometres for `by: "space"`.
192
+ *
193
+ * @param target - The body to look around.
194
+ * @param radius - How close, in degrees (the sky) or kilometres (space).
195
+ * @param options - The same as `nearest`, without `count` and `within`.
196
+ * @returns The bodies inside the radius, nearest first.
197
+ *
198
+ * @example
199
+ * ```ts
200
+ * import { within } from "@johnmorrisdotca/wakusei-planets/nearest";
201
+ *
202
+ * const date = Date.UTC(2023, 2, 2, 0);
203
+ * console.log(within("venus", 1, { date }).map((row) => `${row.id} ${row.angle.toFixed(2)}`).join(", "));
204
+ * console.log(within("jupiter", 1_000_000, { by: "space", kind: "moon", date }).map((row) => row.id).join(", "));
205
+ * ```
206
+ */
207
+ export declare function within(target: BodyId, radius: number, options: Omit<NearestOptions, "count" | "within"> & {
208
+ by: "space";
209
+ }): SpaceNeighbour[];
210
+ export declare function within(target: BodyId, radius: number, options?: Omit<NearestOptions, "count" | "within"> & {
211
+ by?: "sky";
212
+ }): SkyNeighbour[];
213
+ export declare function within(target: BodyId, radius: number, options: Omit<NearestOptions, "count" | "within">): SkyNeighbour[] | SpaceNeighbour[];
214
+ /**
215
+ * When two bodies come closest in a span, and how close: the span is scanned in coarse steps (the fastest body goes round forty times in the step, at most two days), then the smallest minimum is narrowed to about a second of time by golden-section search. If the separation only falls or only rises through the span, the end that is smaller is returned and `atEdge` says so. With `by: "sky"` the separation is the angle in the sky of the observer and a minimum may be an occultation, the angle falling through 0; with `by: "space"` it is the distance between the centres.
216
+ *
217
+ * The result carries `uncertaintyArcseconds` (or `uncertaintyKm`) for the separation, from the accuracy guide's limits, and `uncertaintySeconds` for the moment: that error over how fast the pair moves past each other.
218
+ *
219
+ * @param a - One body.
220
+ * @param b - The other.
221
+ * @param options - `from` and `to` (the span), `by` and `observer` as in `nearest`.
222
+ * @returns The moment, the separation, and the accuracy to expect.
223
+ * @throws RangeError for bodies, a span or an observer that is not valid, or two bodies that are the same, or one of them the observer.
224
+ *
225
+ * @example
226
+ * ```ts
227
+ * import { closestApproach } from "@johnmorrisdotca/wakusei-planets/nearest";
228
+ *
229
+ * const great = closestApproach("jupiter", "saturn", { from: Date.UTC(2020, 11, 1), to: Date.UTC(2021, 0, 1) });
230
+ * console.log(great.time.toISOString(), great.angle?.toFixed(3), "degrees");
231
+ * ```
232
+ */
233
+ export declare function closestApproach(a: BodyId, b: BodyId, options: ApproachOptions): Approach;
234
+ /**
235
+ * The close approaches of every pair of bodies in a span, soonest first: each pair's separation is scanned in coarse steps (the fastest body goes round forty times in the step, at most two days), and every minimum inside the span that is within `within` is narrowed to about a second of time. Each is the same as `closestApproach` would return for that pair and that minimum.
236
+ *
237
+ * @param options - `from` and `to`, `within` (degrees for the sky, default 5; kilometres for space, default all), `bodies` (default the Sun and Mercury to Neptune, less the body the sky is seen from), `by` and `observer`.
238
+ * @returns The approaches, soonest first, each with its moment, separation and the accuracy to expect.
239
+ * @throws RangeError for a span, body or observer that is not valid.
240
+ *
241
+ * @example
242
+ * ```ts
243
+ * import { conjunctions } from "@johnmorrisdotca/wakusei-planets/nearest";
244
+ *
245
+ * const found = conjunctions({ from: Date.UTC(2023, 0, 1), to: Date.UTC(2024, 0, 1), bodies: ["venus", "jupiter"], within: 2 });
246
+ * console.log(found.map((one) => `${one.a}-${one.b} ${one.time.toISOString().slice(0, 10)} ${one.angle?.toFixed(2)}`).join("\n"));
247
+ * ```
248
+ */
249
+ export declare function conjunctions(options: ConjunctionOptions): Approach[];
250
+ /**
251
+ * The distance between two bodies at one instant: their centres, in the Sun's frame, with no light time.
252
+ *
253
+ * @example
254
+ * ```ts
255
+ * import { distance, type Distance } from "@johnmorrisdotca/wakusei-planets/nearest";
256
+ *
257
+ * const found: Distance = distance("earth", "moon", Date.UTC(2026, 10, 8));
258
+ * console.log(Math.round(found.distanceKm), "km");
259
+ * ```
260
+ */
261
+ export interface Distance {
262
+ a: BodyId;
263
+ b: BodyId;
264
+ /** The moment, milliseconds since 1970 (UTC). */
265
+ time: number;
266
+ distanceKm: number;
267
+ distanceAu: number;
268
+ /** The accuracy to expect of `distanceKm`, kilometres: the limits the accuracy tests hold the theories to, combined. An expectation, not a bound. */
269
+ uncertaintyKm: number;
270
+ }
271
+ /**
272
+ * The least or the greatest distance of a pair over a span, and when.
273
+ *
274
+ * @example
275
+ * ```ts
276
+ * import { distanceRange, type DistanceAt } from "@johnmorrisdotca/wakusei-planets/nearest";
277
+ *
278
+ * const least: DistanceAt = distanceRange("earth", "mars", { from: Date.UTC(2003, 0, 1), to: Date.UTC(2004, 0, 1) }).min;
279
+ * console.log(least.time.toISOString().slice(0, 10), least.distanceAu.toFixed(3));
280
+ * ```
281
+ */
282
+ export interface DistanceAt {
283
+ /** The moment, to about a second of time. */
284
+ time: Date;
285
+ distanceKm: number;
286
+ distanceAu: number;
287
+ /** The accuracy to expect of `distanceKm`, kilometres. */
288
+ uncertaintyKm: number;
289
+ /** True when this is the span's start or end, not a turning point inside it. */
290
+ atEdge: boolean;
291
+ }
292
+ /**
293
+ * Where a pair is nearest and farthest over a span.
294
+ *
295
+ * @example
296
+ * ```ts
297
+ * import { distanceRange, type DistanceRange } from "@johnmorrisdotca/wakusei-planets/nearest";
298
+ *
299
+ * const range: DistanceRange = distanceRange("venus", "earth", { from: Date.UTC(2026, 0, 1), to: Date.UTC(2028, 0, 1) });
300
+ * console.log(range.min.distanceAu.toFixed(2), range.max.distanceAu.toFixed(2));
301
+ * ```
302
+ */
303
+ export interface DistanceRange {
304
+ a: BodyId;
305
+ b: BodyId;
306
+ min: DistanceAt;
307
+ max: DistanceAt;
308
+ }
309
+ /**
310
+ * The distance between two bodies on a date: the straight line between their centres at that instant, in kilometres and astronomical units, with no light time. Any two of the Sun, the planets, the dwarf planets and the moons.
311
+ *
312
+ * @param a - One body.
313
+ * @param b - The other.
314
+ * @param date - The moment, a `Date` or milliseconds since 1970 (UTC). Default: now.
315
+ * @returns The distance and the accuracy to expect of it.
316
+ * @throws RangeError for a body or a date that is not valid, or two bodies that are the same.
317
+ *
318
+ * @example
319
+ * ```ts
320
+ * import { distance } from "@johnmorrisdotca/wakusei-planets/nearest";
321
+ *
322
+ * const mars = distance("earth", "mars", Date.UTC(2003, 7, 27, 9));
323
+ * console.log(mars.distanceAu.toFixed(4), Math.round(mars.distanceKm), "km");
324
+ * ```
325
+ */
326
+ export declare function distance(a: BodyId, b: BodyId, date?: When): Distance;
327
+ /**
328
+ * The least and the greatest distance between two bodies over a span, each with its moment: the span is scanned in coarse steps (as `closestApproach` does) and each turning point is narrowed to about a second of time by golden-section search, the greatest on the negated distance. If the distance only falls or only rises through the span, the end that is the extreme is returned and `atEdge` says so.
329
+ *
330
+ * @param a - One body.
331
+ * @param b - The other.
332
+ * @param options - `from` and `to`, the span.
333
+ * @returns `min` and `max`, each `{ time, distanceKm, distanceAu, uncertaintyKm, atEdge }`.
334
+ * @throws RangeError for a body or a span that is not valid, or two bodies that are the same.
335
+ *
336
+ * @example
337
+ * ```ts
338
+ * import { distanceRange } from "@johnmorrisdotca/wakusei-planets/nearest";
339
+ *
340
+ * const { min, max } = distanceRange("earth", "mars", { from: Date.UTC(1990, 0, 1), to: Date.UTC(2020, 0, 1) });
341
+ * console.log(min.time.toISOString().slice(0, 10), min.distanceAu.toFixed(3), "to", max.distanceAu.toFixed(3), "au");
342
+ * ```
343
+ */
344
+ export declare function distanceRange(a: BodyId, b: BodyId, options: Pick<ApproachOptions, "from" | "to">): DistanceRange;