@johnmorrisdotca/wakusei-planets 0.23.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,10 @@
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
+
5
9
  ## [0.23.0] - 2026-11-08
6
10
 
7
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`.
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.23.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.23.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.23.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
 
@@ -364,6 +362,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
364
362
  | [Why two packages](docs/guides/two-packages.md) | This package and chikyu-earth: which to install, alone or together |
365
363
  | [Moons and time](docs/guides/moons-and-time.md) | The sky on a date, time that runs fast |
366
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 |
367
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 |
368
367
  | [Accuracy](docs/guides/accuracy.md) | How far each body is from JPL Horizons |
369
368
  | [In your own three.js scene](docs/guides/in-your-own-scene.md) | `painter.make` |
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",
@@ -22,6 +22,9 @@ export type PortraitState = "line" | "loading" | "still" | "live" | "lost" | "un
22
22
  * Attributes: `scene` (the scene as the portrait builder writes it in its address), `look` (`line`, `realistic` or `painted`: replaces the scene's), `size` (pixels across), `lang` (`en` or `ja`: the names),
23
23
  * `live` (`always`, `hover` or `off`: when it takes the page's one WebGL context), `texture-base` and `texture-far-base` (where the surface pictures are).
24
24
  *
25
+ * It carries the shared view controls itself: a drag moves the picture, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page at Fit), and the arrow keys, + and - and 0 work once it is focused.
26
+ * `controls="none"` turns them off (the portrait builder does, for it edits the scene by dragging its bodies); `zoom-min` and `zoom-max` set the range (0.1 to 8 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
27
+ *
25
28
  * @example
26
29
  * ```ts no-run
27
30
  * import { WakuseiPortrait } from "@johnmorrisdotca/wakusei-planets/portrait";
@@ -67,6 +70,12 @@ export declare class WakuseiPortrait extends HTMLElement {
67
70
  connectedCallback(): void;
68
71
  disconnectedCallback(): void;
69
72
  attributeChangedCallback(name: string): void;
73
+ /** The shared controllers' camera over the scene's own (and a `wakusei-view` event with the `zoom`, `panX` and `panY`): `zoom` scales the picture about its middle, `panX` and `panY` move it by that many CSS pixels. The scene's camera, and what `portrait` holds, are left as they are. */
74
+ setView(view: {
75
+ zoom?: number;
76
+ panX?: number;
77
+ panY?: number;
78
+ }): void;
70
79
  /** Take the page's one WebGL context and draw the scene on it. Resolves true when it is live; a line scene has nothing to take and resolves false. */
71
80
  goLive(): Promise<boolean>;
72
81
  /** Give the WebGL context back: the picture stays as a still. */
@@ -1,3 +1,4 @@
1
+ import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import { BODIES } from "../facts.js";
2
3
  import { createGate, frameCap } from "../gate.js";
3
4
  import { setThreeLoader, takeRenderer } from "../scene/shared.js";
@@ -10,6 +11,11 @@ import { REDUCED_TURN } from "../live.js";
10
11
  import { poseOf } from "./pose.js";
11
12
  import { createPortraitItem } from "./scene3d.js";
12
13
  export { setThreeLoader };
14
+ /**
15
+ * The zoom range of a portrait that carries its own controls. The floor is arbitrary: a tenth of Fit leaves room to see the whole scene small. The ceiling is the painted maps: the sharpest is 2048 pixels round
16
+ * a body, which stays sharp to a few times the size at Fit and softens after that; 8 times is as far as the bodies' own shader detail goes. A scene of a line look has detail at any scale.
17
+ */
18
+ const CARRIED_LIMITS = { zoomMin: 0.1, zoomMax: 8 };
13
19
  const TEMPLATE = `<style>
14
20
  :host { display: block; width: var(--wakusei-size, 720px); max-width: 100%; aspect-ratio: var(--wakusei-ratio, 16 / 9); position: relative; overflow: hidden; contain: layout style; touch-action: none; user-select: none; }
15
21
  #bg, #stage, #over { position: absolute; inset: 0; width: 100%; height: 100%; }
@@ -26,6 +32,9 @@ const num = (value, fallback) => {
26
32
  * Attributes: `scene` (the scene as the portrait builder writes it in its address), `look` (`line`, `realistic` or `painted`: replaces the scene's), `size` (pixels across), `lang` (`en` or `ja`: the names),
27
33
  * `live` (`always`, `hover` or `off`: when it takes the page's one WebGL context), `texture-base` and `texture-far-base` (where the surface pictures are).
28
34
  *
35
+ * It carries the shared view controls itself: a drag moves the picture, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page at Fit), and the arrow keys, + and - and 0 work once it is focused.
36
+ * `controls="none"` turns them off (the portrait builder does, for it edits the scene by dragging its bodies); `zoom-min` and `zoom-max` set the range (0.1 to 8 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
37
+ *
29
38
  * @example
30
39
  * ```ts no-run
31
40
  * import { WakuseiPortrait } from "@johnmorrisdotca/wakusei-planets/portrait";
@@ -61,6 +70,10 @@ export class WakuseiPortrait extends HTMLElement {
61
70
  #edit = {};
62
71
  #overKey = "";
63
72
  #lineKey = "";
73
+ #zoom = 1;
74
+ #panX = 0;
75
+ #panY = 0;
76
+ #hands;
64
77
  #hover = () => void this.goLive();
65
78
  #onContext = (state) => {
66
79
  if (state === "unavailable")
@@ -147,6 +160,7 @@ export class WakuseiPortrait extends HTMLElement {
147
160
  document.addEventListener("visibilitychange", this.#onHidden);
148
161
  this.#applyHover();
149
162
  this.#readAttributes();
163
+ this.#hands = carryControls(this, { turnable: false, limits: CARRIED_LIMITS, onChange: (view) => this.setView(view) });
150
164
  this.#queue();
151
165
  }
152
166
  disconnectedCallback() {
@@ -154,6 +168,8 @@ export class WakuseiPortrait extends HTMLElement {
154
168
  this.#io?.disconnect();
155
169
  document.removeEventListener("visibilitychange", this.#onHidden);
156
170
  this.#applyHover(false);
171
+ this.#hands?.unbind();
172
+ this.#hands = undefined;
157
173
  this.#disposeView(true);
158
174
  }
159
175
  attributeChangedCallback(name) {
@@ -165,6 +181,24 @@ export class WakuseiPortrait extends HTMLElement {
165
181
  this.#readAttributes();
166
182
  this.#queue();
167
183
  }
184
+ /** The shared controllers' camera over the scene's own (and a `wakusei-view` event with the `zoom`, `panX` and `panY`): `zoom` scales the picture about its middle, `panX` and `panY` move it by that many CSS pixels. The scene's camera, and what `portrait` holds, are left as they are. */
185
+ setView(view) {
186
+ const [zoom, panX, panY] = [Math.max(1e-6, view.zoom ?? 1), view.panX ?? 0, view.panY ?? 0];
187
+ if (zoom === this.#zoom && panX === this.#panX && panY === this.#panY)
188
+ return;
189
+ [this.#zoom, this.#panX, this.#panY] = [zoom, panX, panY];
190
+ this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { zoom: this.#zoom, panX: this.#panX, panY: this.#panY } }));
191
+ this.#changed();
192
+ }
193
+ /** The scene's resolved camera with the view's zoom and pan put over it. */
194
+ #resolveNow() {
195
+ const resolved = resolve(this.#portrait);
196
+ if (this.#zoom === 1 && this.#panX === 0 && this.#panY === 0)
197
+ return resolved;
198
+ const h = resolved.camera.h / this.#zoom;
199
+ const scale = this.#size().height / (2 * h);
200
+ return { ...resolved, camera: { x: resolved.camera.x - this.#panX / scale, y: resolved.camera.y + this.#panY / scale, h } };
201
+ }
168
202
  /** Take the page's one WebGL context and draw the scene on it. Resolves true when it is live; a line scene has nothing to take and resolves false. */
169
203
  async goLive() {
170
204
  if (this.#portrait.look === "line")
@@ -260,7 +294,7 @@ export class WakuseiPortrait extends HTMLElement {
260
294
  if (!this.isConnected)
261
295
  return;
262
296
  if (this.#view?.live === true && !this.#queued) {
263
- this.#resolved = resolve(this.#portrait);
297
+ this.#resolved = this.#resolveNow();
264
298
  this.#style();
265
299
  this.#gate?.request();
266
300
  }
@@ -303,7 +337,7 @@ export class WakuseiPortrait extends HTMLElement {
303
337
  if (!this.isConnected)
304
338
  return;
305
339
  const p = this.#portrait;
306
- this.#resolved = resolve(p);
340
+ this.#resolved = this.#resolveNow();
307
341
  this.#style();
308
342
  this.setAttribute("aria-label", this.#label());
309
343
  const wants3d = p.look !== "line" && this.#state !== "unavailable" && p.items.length > 0;
@@ -360,7 +394,7 @@ export class WakuseiPortrait extends HTMLElement {
360
394
  #drawLine() {
361
395
  const { width, height } = this.#size();
362
396
  const markup = this.#lineBody(width, height);
363
- const key = `${width}x${height}|${markup.length}|${this.#portrait.light.az}`;
397
+ const key = `${width}x${height}|${markup.length}|${this.#portrait.light.az}|${this.#zoom.toFixed(3)},${this.#panX.toFixed(1)},${this.#panY.toFixed(1)}`;
364
398
  if (this.#portrait.look !== "line") {
365
399
  if (this.#stage.firstChild !== null && this.#lineKey !== "")
366
400
  this.#stage.innerHTML = "";
@@ -374,7 +408,7 @@ export class WakuseiPortrait extends HTMLElement {
374
408
  }
375
409
  #key() {
376
410
  const { width } = this.#size();
377
- return `${encodeScene(this.#portrait)}|${width}`;
411
+ return `${encodeScene(this.#portrait)}|${width}|${this.#zoom.toFixed(3)},${this.#panX.toFixed(1)},${this.#panY.toFixed(1)}`;
378
412
  }
379
413
  // Replacing a view keeps the renderer lease; leaving 3D gives it back.
380
414
  #disposeView(releaseRenderer = false) {
@@ -436,7 +470,7 @@ export class WakuseiPortrait extends HTMLElement {
436
470
  }
437
471
  // --- moving -------------------------------------------------------------------------------------------------------------------------------------------
438
472
  #frame() {
439
- this.#resolved = resolve(this.#portrait);
473
+ this.#resolved = this.#resolveNow();
440
474
  this.#paintOver();
441
475
  if (this.#portrait.look === "line") {
442
476
  this.#drawLine();
@@ -9,7 +9,7 @@ import type * as THREE from "three";
9
9
  * console.log(TEXTURE_BASE);
10
10
  * ```
11
11
  */
12
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.23.0/dist/textures/";
12
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.24.0/dist/textures/";
13
13
  /**
14
14
  * Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
15
15
  * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
@@ -21,7 +21,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
21
21
  * console.log(TEXTURE_FAR_BASE);
22
22
  * ```
23
23
  */
24
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.23.0/textures/";
24
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.24.0/textures/";
25
25
  export declare const slash: (base: string) => string;
26
26
  export declare function texturePaths(element: Element): {
27
27
  textureBase(): string;
@@ -1,3 +1,4 @@
1
+ import { type ViewController } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import { setThreeLoader } from "../scene/shared.ts";
2
3
  import { type SpacePlanet } from "./frame.ts";
3
4
  import { type ScaleMode } from "./scale.ts";
@@ -86,6 +87,9 @@ export type Riding = RideState;
86
87
  * `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base` and `max-texture`. Positions come from this package's own models. It draws
87
88
  * only when something changes, and nothing while it is out of sight.
88
89
  *
90
+ * It carries the shared view controls itself: a drag turns the camera round the body, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page), and the arrow keys, + and - and 0 work once it is
91
+ * focused. `controls="none"` turns them off; `zoom-min` and `zoom-max` set the range (a millionth to 3 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
92
+ *
89
93
  * @example
90
94
  * ```ts no-run
91
95
  * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
@@ -99,6 +103,8 @@ export type Riding = RideState;
99
103
  export declare class WakuseiSpace extends HTMLElement {
100
104
  #private;
101
105
  static observedAttributes: string[];
106
+ /** The shared controller behind the element's own hands: for a page that moves the view itself, such as `controller.set({ zoom: space.zoomFor("moon") })`. It is there while the element is connected, whether `controls` is `none` or not. */
107
+ get controller(): ViewController | undefined;
102
108
  connectedCallback(): void;
103
109
  disconnectedCallback(): void;
104
110
  attributeChangedCallback(name: string, _old: string | null, value: string | null): void;
@@ -1,3 +1,4 @@
1
+ import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
1
2
  import { BODIES, MOONS_OF } from "../facts.js";
2
3
  import { createGate, frameCap } from "../gate.js";
3
4
  import { createPainter } from "../scene/painter.js";
@@ -28,6 +29,11 @@ const readBody = (value) => {
28
29
  const id = value.toLowerCase();
29
30
  return SPACE_BODIES.includes(id) ? id : undefined;
30
31
  };
32
+ /**
33
+ * The zoom range of the space view when it carries its own controls. The floor, a millionth, takes the camera out past Neptune in the true scale. The ceiling is where the camera reaches the body: it is held at
34
+ * 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.2 nothing moves; 3 shows the surface as sharp as the painted maps (2048 pixels round) and the shader allow.
35
+ */
36
+ const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3, tiltMax: 90 };
31
37
  const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}</style><div id="stage"></div><div id="labels"></div>`;
32
38
  /**
33
39
  * The `<wakusei-space>` custom element: the Earth, the Moon, the Sun and the planets where they are at a date and time, drawn with three.js through the shared renderer. It takes `center`
@@ -35,6 +41,9 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
35
41
  * `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base` and `max-texture`. Positions come from this package's own models. It draws
36
42
  * only when something changes, and nothing while it is out of sight.
37
43
  *
44
+ * It carries the shared view controls itself: a drag turns the camera round the body, two fingers pinch, Ctrl, Command or Alt with the wheel zooms (the plain wheel scrolls the page), and the arrow keys, + and - and 0 work once it is
45
+ * focused. `controls="none"` turns them off; `zoom-min` and `zoom-max` set the range (a millionth to 3 by default); a `<kazoku-view-controls for="...">` takes over and reads it.
46
+ *
38
47
  * @example
39
48
  * ```ts no-run
40
49
  * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
@@ -65,6 +74,11 @@ export class WakuseiSpace extends HTMLElement {
65
74
  #painter;
66
75
  #focusBeforeRide = "earth";
67
76
  #lostTold = false;
77
+ #hands;
78
+ /** The shared controller behind the element's own hands: for a page that moves the view itself, such as `controller.set({ zoom: space.zoomFor("moon") })`. It is there while the element is connected, whether `controls` is `none` or not. */
79
+ get controller() {
80
+ return this.#hands?.controller;
81
+ }
68
82
  connectedCallback() {
69
83
  this.#model.centre = readCentre(this.getAttribute("center")) ?? this.#model.centre;
70
84
  this.#mode = readTime(this.getAttribute("time"));
@@ -116,10 +130,13 @@ export class WakuseiSpace extends HTMLElement {
116
130
  this.#last = performance.now();
117
131
  this.#schedule();
118
132
  this.addEventListener("pointerdown", this.#down);
133
+ this.#hands = carryControls(this, { limits: CARRIED_LIMITS, initial: { drag: "turn" }, onChange: (view, info) => this.setView(view, info.final) });
119
134
  this.#labelBox.addEventListener("click", this.#labelClick);
120
135
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
121
136
  }
122
137
  disconnectedCallback() {
138
+ this.#hands?.unbind();
139
+ this.#hands = undefined;
123
140
  this.removeEventListener("pointerdown", this.#down);
124
141
  window.removeEventListener("pointerup", this.#up, true);
125
142
  clearTimeout(this.#timer);
@@ -235,6 +252,7 @@ export class WakuseiSpace extends HTMLElement {
235
252
  if (view.yaw === now.yaw && view.tilt === now.tilt && view.zoom === now.zoom)
236
253
  return;
237
254
  this.#model.view = { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom };
255
+ this.dispatchEvent(new CustomEvent("wakusei-view", { detail: { yaw: view.yaw, tilt: view.tilt, zoom: view.zoom } }));
238
256
  const drawn = this.#model.drawnView;
239
257
  if (drawn && !final && view.zoom === drawn.zoom) {
240
258
  const turned = Math.max(Math.abs(view.yaw - drawn.yaw), Math.abs(view.tilt - drawn.tilt)) * RAD;
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.23.0";
1
+ export declare const VERSION = "0.24.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.23.0";
1
+ export const VERSION = "0.24.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.23.0",
3
+ "version": "0.24.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",
@@ -46,6 +46,7 @@
46
46
  "leap-seconds",
47
47
  "sidereal-time",
48
48
  "spaceprogramx",
49
+ "space-program-x",
49
50
  "spx",
50
51
  "suncalc",
51
52
  "sunrise",
@@ -378,7 +379,7 @@
378
379
  },
379
380
  "packageManager": "pnpm@10.28.0",
380
381
  "dependencies": {
381
- "@johnmorrisdotca/kazoku-ui": "^0.20.0"
382
+ "@johnmorrisdotca/kazoku-ui": "^0.21.1"
382
383
  },
383
384
  "peerDependencies": {
384
385
  "@johnmorrisdotca/chikyu-earth": ">=0.10.0",