@johnmorrisdotca/wakusei-planets 0.27.0 → 0.28.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,11 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.28.0] - 2026-11-09
6
+
7
+ - **The date follows the clock, and Play runs it** (MODULES-759, MODULES-755 wakusei part). John, on the space page: "The date is never reflected by the action in the page" and "Where are the Play controls to see the planets rotate starting from the Date and time selected?" `<wakusei-space>` and `<wakusei-body>` (with a `time` or `moons`) send `wakusei-timechange` with `{ time, running }`: four times a second at most while time runs (once a second at real time; only while the tab is shown), and once with `running: false` when the clock holds. `<wakusei-body>` has a `time` property (the moment shown). A held clock (`rate="0"`) is not "moving" any more, so it draws nothing. In the demo the date box follows the clock (never while the reader is typing in it), a ride along (the Moon, Io) starts the clock, and the loose Speed row is kazoku-ui's `<kazoku-replay-bar>` on the space page and the body page: Play runs the clock from the date shown, Pause holds it, Back returns to the date chosen, and `play=on`, `speed` and the date (`t`, when the clock stops or the reader leaves) stay in the address. Reduced motion leaves Play off. An old address with `speed` alone is paused now (add `play=on`); the speed starts at 3600 (an hour a second). The body page's real sky no longer adds the portrait turn to a dated picture (it turned 12 degrees a second even when held); Play is what moves it. `wakusei-time` is unchanged.
8
+ - **kazoku-ui 0.27 (with 0.26): a plain drag always turns, lighter sheets for children, and the shared renderer draws at most 30 frames a second** (MODULES-743). On the space view and the views that turn, a plain drag (and one finger) now turns at every zoom; the middle or right button, Ctrl or Command and a drag, Space and a drag, and the wheel move; the Move or Turn choice is gone (`initial: { drag: "turn" }` is no longer asked of the shared controls). The colouring sheets draw their outline at kazoku-ui's kid line, 1.2 mm (was 3), and the lines inside at 1 mm (was 2.5), so a sheet is lighter and the names have room.
9
+
5
10
  ## [0.27.0] - 2026-11-09
6
11
 
7
12
  - **Close zoom: every shaded body zooms as far as its detail goes, with finer map tiles** (MODULES-646). `<wakusei-body>` stopped at 8x for every body, because the painted maps are 2048 pixels round; in a moons picture that was Saturn a third of the frame wide, with + greyed. The limit is now worked out for each body from the widest map it has, the size of its picture and how soft its surface is (`src/scene/reach.ts`; the table of all 47 bodies is in the new guide, Close zoom and map tiles): Saturn goes to 36x alone and 1000x in its moons picture, Mars, the Moon and the Earth to 44x alone, ten moons to 22x, and no body below 8x. Behind it: **finer map tiles** (`scripts/make-body-tiles.py`, `pnpm tiles`): the big public-domain maps of 15 bodies (Mars, the Moon, the Earth, Mercury, Io, Callisto, Rhea, Enceladus, Tethys, Dione, Iapetus, Triton, Pluto, Charon, Mimas) cut into 512 pixel tiles up to 16384 pixels round, built by the Pages workflow and served beside the demo (not in git, not in the npm package: 3552 tiles, 76.5 MB); the part in view is laid over the 2048 map as one window of at most 16 tiles (about 22 MB of graphics memory), fetched when the zoom needs it and the view has settled, and let go with every decoded tile 4 seconds after it does not. The new `tiles` attribute says where they are (`off` for none; by default the demo site's, unless `texture-base` names your own pictures), `stats.tiles` and `stats.zoomMax` say what the element is doing. **Generic detail**: where a map is enlarged more than a quarter, the shader adds octaves of noise (grain for a rock, faint streaks along the latitudes for a gas giant, none for the Sun or a star) so a body never goes smooth; it is noise, not a feature of the body, and the guide says so. **Saturn's rings** get generic ringlets where the strip is enlarged; the strip, the gaps and the shadows are as they were. The sphere has 192 by 96 segments (was 128 by 64), so its edge stays round at a deep zoom. `<wakusei-portrait>` (8x) and `<wakusei-space>` (3x) are unchanged. The freeze test's limits are unchanged and it passes.
package/README.md CHANGED
@@ -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.27.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.28.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.27.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.28.0/docs/images/lineup-desk.png" width="640"></p>
21
21
 
22
22
  ## One minute
23
23
 
@@ -180,7 +180,7 @@ A page full of bodies stays light: one WebGL context for the page through kazoku
180
180
  | `size` | The width in pixels. | `320` |
181
181
  | `time` | `now` or an ISO date: the body as the Earth sees it then. Left out, a portrait. | portrait |
182
182
  | `moons` | A planet with its moons on their orbits (with a date). | off |
183
- | `rate` | Simulated seconds for each real second. | `1` |
183
+ | `rate` | Simulated seconds for each real second; `0` holds the clock and draws nothing. A dated picture sends `wakusei-timechange` (`{ time, running }`) while the clock runs and once when it holds. | `1` |
184
184
  | `turn` | A portrait turns this many degrees a second. | `0` |
185
185
  | `tilt`, `pitch`, `phase`, `meridian` | A portrait's pose in degrees. | the body's own |
186
186
  | `scale-to` | Draw to scale with another body. | fills its box |
@@ -290,7 +290,7 @@ A body that turns by itself and a moving sky, in HTML:
290
290
 
291
291
  ## The portrait builder
292
292
 
293
- <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.27.0/docs/images/portrait-family.png" width="640"></p>
293
+ <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.28.0/docs/images/portrait-family.png" width="640"></p>
294
294
 
295
295
  [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.
296
296
 
package/dist/element.d.ts CHANGED
@@ -31,6 +31,9 @@ export type WakuseiState = "line" | "loading" | "still" | "live" | "lost" | "una
31
31
  * `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 50 for the line drawing; for the shaded looks 0.1 up to where the body's detail runs out, 8 at least and 1000 at most: see the close zoom guide); a `<kazoku-view-controls for="...">` takes over and reads it.
32
32
  * Close up, `tiles` is where the finer map tiles are (a folder address; `off` for none; by default the demo site's, unless `texture-base` names your own pictures): a window of them is laid over the painted map for the part in view and let go when it is not, and the zoom range of a body with tiles grows with them.
33
33
  * Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
34
+ * A dated picture (a `time`, or `moons`) has a clock: `rate` is the simulated seconds for each real second, and `rate="0"` holds it, drawing nothing. While it runs (`rate` not 0), `wakusei-timechange` carries
35
+ * `detail: { time, running: true }` (`time` is the moment shown in milliseconds since 1970; four times a second, once a second at real time; only while the tab is shown, whether or not the picture is on screen), and once with
36
+ * `running: false` when the clock is held: a page writes the date into its date box from it. The `time` property reads the moment shown, and `undefined` for a portrait with no date.
34
37
  *
35
38
  * @example
36
39
  * ```ts no-run
@@ -46,6 +49,8 @@ export type WakuseiState = "line" | "loading" | "still" | "live" | "lost" | "una
46
49
  export declare class WakuseiBody extends HTMLElement {
47
50
  #private;
48
51
  static observedAttributes: string[];
52
+ /** The moment the dated picture shows, in milliseconds since 1970, or `undefined` for a portrait with no date. */
53
+ get time(): number | undefined;
49
54
  /** The radius of the body's disc on the screen in CSS pixels, at the picture's own size: what `grab-radius` on the shared view controls wants for a drag that keeps the touched point under the pointer. */
50
55
  get discRadius(): number;
51
56
  get body(): BodyId;
package/dist/element.js CHANGED
@@ -76,6 +76,9 @@ const TEMPLATE = `<style>
76
76
  * `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 50 for the line drawing; for the shaded looks 0.1 up to where the body's detail runs out, 8 at least and 1000 at most: see the close zoom guide); a `<kazoku-view-controls for="...">` takes over and reads it.
77
77
  * Close up, `tiles` is where the finer map tiles are (a folder address; `off` for none; by default the demo site's, unless `texture-base` names your own pictures): a window of them is laid over the painted map for the part in view and let go when it is not, and the zoom range of a body with tiles grows with them.
78
78
  * Whatever moves the view, `setView` sends a `wakusei-view` event with its `yaw`, `tilt`, `roll`, `zoom`, `panX` and `panY`.
79
+ * A dated picture (a `time`, or `moons`) has a clock: `rate` is the simulated seconds for each real second, and `rate="0"` holds it, drawing nothing. While it runs (`rate` not 0), `wakusei-timechange` carries
80
+ * `detail: { time, running: true }` (`time` is the moment shown in milliseconds since 1970; four times a second, once a second at real time; only while the tab is shown, whether or not the picture is on screen), and once with
81
+ * `running: false` when the clock is held: a page writes the date into its date box from it. The `time` property reads the moment shown, and `undefined` for a portrait with no date.
79
82
  *
80
83
  * @example
81
84
  * ```ts no-run
@@ -104,6 +107,8 @@ export class WakuseiBody extends HTMLElement {
104
107
  #visible = typeof IntersectionObserver !== "function";
105
108
  #io;
106
109
  #tick;
110
+ #clockTimer;
111
+ #clockRan = false;
107
112
  #refreshQueued = false;
108
113
  #gate;
109
114
  #live = createLive();
@@ -142,7 +147,13 @@ export class WakuseiBody extends HTMLElement {
142
147
  this.#stopTick();
143
148
  else
144
149
  this.#resume();
150
+ this.#syncClock();
145
151
  };
152
+ /** The moment the dated picture shows, in milliseconds since 1970, or `undefined` for a portrait with no date. */
153
+ get time() {
154
+ const r = this.#request();
155
+ return r.start === undefined ? undefined : r.start + (performance.now() - r.startedAt) * r.rate;
156
+ }
146
157
  /** The radius of the body's disc on the screen in CSS pixels, at the picture's own size: what `grab-radius` on the shared view controls wants for a drag that keeps the touched point under the pointer. */
147
158
  get discRadius() {
148
159
  const { width, height } = this.getBoundingClientRect();
@@ -209,6 +220,7 @@ export class WakuseiBody extends HTMLElement {
209
220
  this.#io.observe(this);
210
221
  }
211
222
  document.addEventListener("visibilitychange", this.#onHidden);
223
+ this.#syncClock();
212
224
  this.#unsub = onRegister(() => {
213
225
  this.#carry();
214
226
  this.#queue();
@@ -220,6 +232,8 @@ export class WakuseiBody extends HTMLElement {
220
232
  this.#queue();
221
233
  }
222
234
  disconnectedCallback() {
235
+ clearTimeout(this.#clockTimer);
236
+ this.#clockTimer = undefined;
223
237
  this.#stopTick();
224
238
  this.#gate?.cancel();
225
239
  this.#io?.disconnect();
@@ -236,8 +250,10 @@ export class WakuseiBody extends HTMLElement {
236
250
  attributeChangedCallback(name) {
237
251
  if (!this.isConnected)
238
252
  return;
239
- if (name === "time" || name === "rate")
253
+ if (name === "time" || name === "rate") {
240
254
  this.#clockFromAttributes();
255
+ this.#syncClock(true);
256
+ }
241
257
  if (name === "live")
242
258
  this.#applyHover();
243
259
  if (name === "live" || name === "look" || name === "body")
@@ -368,6 +384,33 @@ export class WakuseiBody extends HTMLElement {
368
384
  this.#startedAt = performance.now();
369
385
  this.#start = t === "now" ? Date.now() : t;
370
386
  }
387
+ /**
388
+ * Tell the page the moment shown while a dated clock runs (`rate` not 0): `wakusei-timechange` with `{ time, running: true }` four times a second (once a second at real time), only while the
389
+ * tab is shown (the date box is often below the picture), and once with `running: false` when the clock holds. `loud` says the clock was just set (a new `time` or `rate`), so a hold is announced.
390
+ */
391
+ #syncClock(loud = false) {
392
+ clearTimeout(this.#clockTimer);
393
+ this.#clockTimer = undefined;
394
+ const r = this.#request();
395
+ const dated = r.start !== undefined;
396
+ const running = dated && r.rate !== 0;
397
+ if (!this.isConnected)
398
+ return;
399
+ if (!running) {
400
+ if (loud && dated && this.#clockRan)
401
+ this.dispatchEvent(new CustomEvent("wakusei-timechange", { detail: { time: this.time, running: false } }));
402
+ this.#clockRan = false;
403
+ return;
404
+ }
405
+ this.#clockRan = true;
406
+ if (document.visibilityState === "hidden")
407
+ return;
408
+ const step = () => {
409
+ this.dispatchEvent(new CustomEvent("wakusei-timechange", { detail: { time: this.time, running: true } }));
410
+ this.#clockTimer = setTimeout(step, Math.abs(this.#request().rate) === 1 ? 1000 : 250);
411
+ };
412
+ step();
413
+ }
371
414
  #request() {
372
415
  const star = this.#star();
373
416
  const moons = this.hasAttribute("moons") && !this.hasAttribute("star");
@@ -386,10 +429,10 @@ export class WakuseiBody extends HTMLElement {
386
429
  turn: (this.hasAttribute("turn") ? num(this.getAttribute("turn"), 0) : this.getAttribute("live") === "off" ? 0 : star !== undefined ? star.turn.degreesPerSecond : defaultTurn(this.body)) * (this.#reduce ? REDUCED_TURN : 1),
387
430
  };
388
431
  }
389
- /** The picture moves on its own: a turn, or time running faster than the clock. */
432
+ /** The picture moves on its own: a turn, or time running faster (or backwards) than the clock. A held clock (`rate="0"`) moves nothing. */
390
433
  get #moving() {
391
434
  const r = this.#request();
392
- const turning = r.turn !== 0 || (r.start !== undefined && r.rate !== 1);
435
+ const turning = r.turn !== 0 || (r.start !== undefined && r.rate !== 1 && r.rate !== 0);
393
436
  return this.#reduce ? r.turn !== 0 : turning;
394
437
  }
395
438
  // --- the state of the scene --------------------------------------------------------------------------------------------------------------------
@@ -1,8 +1,8 @@
1
1
  import { type BodyId } from "../facts.ts";
2
2
  import type { Pose } from "../ephemeris.ts";
3
3
  /** The thickness of the outline of a body and of every line inside it, in millimetres. */
4
- export declare const OUTLINE_MM = 3;
5
- export declare const LINE_MM = 2.5;
4
+ export declare const OUTLINE_MM = 1.2;
5
+ export declare const LINE_MM = 1;
6
6
  export interface Art {
7
7
  /** The SVG markup, to put inside an `<svg>` measured in millimetres. */
8
8
  markup: string;
@@ -18,8 +18,8 @@ export declare function reach(id: BodyId, pose?: Pose): {
18
18
  y: number;
19
19
  };
20
20
  /**
21
- * A body as a colouring picture: thick black outlines on white (the outline 3 mm, every line inside 2.5 mm), its big features, its rings, and the Sun's rays. The picture is drawn at its centre `(cx, cy)` with `r`
22
- * millimetres for the body's radius. `outline` is the outline's thickness; the lines inside are 2.5 mm or, for a thinner outline, a little less.
21
+ * A body as a colouring picture: thick black outlines on white (the outline 1.2 mm, every line inside 1 mm), its big features, its rings, and the Sun's rays. The picture is drawn at its centre `(cx, cy)` with `r`
22
+ * millimetres for the body's radius. `outline` is the outline's thickness; the lines inside are 1 mm or, for a thinner outline, a little less.
23
23
  * @param id - The body's name.
24
24
  * @param cx - The centre's place, in millimetres.
25
25
  * @param cy - The centre's place, in millimetres.
@@ -5,8 +5,8 @@ import { cross, RAD, DEG } from "../vec.js";
5
5
  import { facing, portrait, silhouette, surfacePoint } from "../pose.js";
6
6
  import { OWN_FEATURES } from "./land.js";
7
7
  /** The thickness of the outline of a body and of every line inside it, in millimetres. */
8
- export const OUTLINE_MM = 3;
9
- export const LINE_MM = 2.5;
8
+ export const OUTLINE_MM = 1.2;
9
+ export const LINE_MM = 1;
10
10
  /** The smallest radius of a shape to colour, in millimetres, and the least between two lines. */
11
11
  const MIN_SHAPE_MM = 8;
12
12
  const MIN_GAP_MM = 12;
@@ -209,8 +209,8 @@ function rays(frame, line) {
209
209
  return stroke(parts.join(""), line);
210
210
  }
211
211
  /**
212
- * A body as a colouring picture: thick black outlines on white (the outline 3 mm, every line inside 2.5 mm), its big features, its rings, and the Sun's rays. The picture is drawn at its centre `(cx, cy)` with `r`
213
- * millimetres for the body's radius. `outline` is the outline's thickness; the lines inside are 2.5 mm or, for a thinner outline, a little less.
212
+ * A body as a colouring picture: thick black outlines on white (the outline 1.2 mm, every line inside 1 mm), its big features, its rings, and the Sun's rays. The picture is drawn at its centre `(cx, cy)` with `r`
213
+ * millimetres for the body's radius. `outline` is the outline's thickness; the lines inside are 1 mm or, for a thinner outline, a little less.
214
214
  * @param id - The body's name.
215
215
  * @param cx - The centre's place, in millimetres.
216
216
  * @param cy - The centre's place, in millimetres.
@@ -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.27.0/dist/textures/";
12
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.28.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.27.0/textures/";
24
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.28.0/textures/";
25
25
  /**
26
26
  * Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
27
27
  * a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
@@ -90,13 +90,20 @@ export type Riding = RideState;
90
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
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
92
  *
93
+ * While time runs (`speed` is not 0) it sends `wakusei-timechange` with `detail: { time, running: true }`, `time` being the moment shown in milliseconds since 1970, at most four times a second however fast the picture is
94
+ * drawn, and once with `running: false` when the clock holds (`speed` set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself. `wakusei-time` is sent at every step the clock takes.
95
+ *
93
96
  * @example
94
97
  * ```ts no-run
95
98
  * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
96
99
  *
97
100
  * const space = document.createElement("wakusei-space") as WakuseiSpace;
98
101
  * space.setAttribute("time", "2026-11-02T12:00Z");
99
- * space.setAttribute("speed", "0");
102
+ * space.setAttribute("speed", "86400");
103
+ * space.addEventListener("wakusei-timechange", (event) => {
104
+ * const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
105
+ * console.log(new Date(time).toISOString(), running ? "running" : "held");
106
+ * });
100
107
  * document.body.append(space);
101
108
  * ```
102
109
  */
@@ -11,6 +11,8 @@ export { setThreeLoader, SPACE_BODIES };
11
11
  const readLight = (value) => (value === "lit" ? "lit" : "sun");
12
12
  const RAD = Math.PI / 180;
13
13
  const REAL_TIME_TICK_MS = 60_000;
14
+ /** The least time between two `wakusei-timechange` events while time runs: a few a second at most, however fast the picture is drawn. */
15
+ const TIME_EVENT_MS = 250;
14
16
  const readCentre = (value) => {
15
17
  if (!value)
16
18
  return null;
@@ -44,13 +46,20 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
44
46
  * 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
47
  * 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
48
  *
49
+ * While time runs (`speed` is not 0) it sends `wakusei-timechange` with `detail: { time, running: true }`, `time` being the moment shown in milliseconds since 1970, at most four times a second however fast the picture is
50
+ * drawn, and once with `running: false` when the clock holds (`speed` set to 0): a page writes the date into its date box from it. It is not sent for a `time` the page sets itself. `wakusei-time` is sent at every step the clock takes.
51
+ *
47
52
  * @example
48
53
  * ```ts no-run
49
54
  * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
50
55
  *
51
56
  * const space = document.createElement("wakusei-space") as WakuseiSpace;
52
57
  * space.setAttribute("time", "2026-11-02T12:00Z");
53
- * space.setAttribute("speed", "0");
58
+ * space.setAttribute("speed", "86400");
59
+ * space.addEventListener("wakusei-timechange", (event) => {
60
+ * const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
61
+ * console.log(new Date(time).toISOString(), running ? "running" : "held");
62
+ * });
54
63
  * document.body.append(space);
55
64
  * ```
56
65
  */
@@ -67,6 +76,7 @@ export class WakuseiSpace extends HTMLElement {
67
76
  #state = "loading";
68
77
  #timer;
69
78
  #last = 0;
79
+ #announced = -Infinity;
70
80
  #pool = new Map();
71
81
  #places;
72
82
  #names = {};
@@ -132,7 +142,7 @@ export class WakuseiSpace extends HTMLElement {
132
142
  this.#last = performance.now();
133
143
  this.#schedule();
134
144
  this.addEventListener("pointerdown", this.#down);
135
- this.#hands = carryControls(this, { limits: CARRIED_LIMITS, initial: { drag: "turn" }, onChange: (view, info) => this.setView(view, info.final) });
145
+ this.#hands = carryControls(this, { limits: CARRIED_LIMITS, onChange: (view, info) => this.setView(view, info.final) });
136
146
  this.#labelBox.addEventListener("click", this.#labelClick);
137
147
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
138
148
  }
@@ -195,11 +205,17 @@ export class WakuseiSpace extends HTMLElement {
195
205
  return this.#speed;
196
206
  }
197
207
  set speed(value) {
208
+ // time up to this moment is worked out at the old speed, so a hold keeps the moment the reader saw last
209
+ if (this.#speed !== 0 && this.isConnected)
210
+ this.#advance(performance.now());
211
+ const was = this.#speed;
198
212
  this.#speed = Number.isFinite(value) ? value : 1;
199
213
  this.#model.stepMs = Math.max(1000, Math.abs(this.#speed) * 1000);
200
214
  this.#last = performance.now();
201
215
  this.#schedule();
202
216
  this.#gate?.request();
217
+ if (this.#speed === 0 && was !== 0)
218
+ this.#announce(false);
203
219
  }
204
220
  /** `compressed` (the default: every direction real, the distances squeezed) or `true` (real distances and sizes). */
205
221
  get scale() {
@@ -423,16 +439,28 @@ export class WakuseiSpace extends HTMLElement {
423
439
  const wait = !riding && this.#speed === 1 ? REAL_TIME_TICK_MS : 1000 / perSecond;
424
440
  this.#timer = setTimeout(this.#tick, wait);
425
441
  }
426
- #tick = () => {
427
- const now = performance.now();
442
+ /** Bring the moment shown up to `now` (the page's own clock, in milliseconds) at the speed it has run at. */
443
+ #advance(now) {
428
444
  if (this.#speed === 1 && this.#mode === "now")
429
445
  this.#model.time = Date.now();
430
446
  else
431
447
  this.#model.time += (now - this.#last) * this.#speed;
432
448
  this.#last = now;
449
+ }
450
+ /** Tell the page the moment shown: at most four times a second while time runs (`running`), and once, at once, when it holds. */
451
+ #announce(running) {
452
+ const now = performance.now();
453
+ if (running && now - this.#announced < TIME_EVENT_MS)
454
+ return;
455
+ this.#announced = running ? now : -Infinity;
456
+ this.dispatchEvent(new CustomEvent("wakusei-timechange", { detail: { time: this.#model.time, running } }));
457
+ }
458
+ #tick = () => {
459
+ this.#advance(performance.now());
433
460
  this.#gate?.request();
434
461
  this.#schedule();
435
462
  this.dispatchEvent(new CustomEvent("wakusei-time", { detail: { time: this.#model.time } }));
463
+ this.#announce(this.#speed !== 0);
436
464
  };
437
465
  // --- labels --------------------------------------------------------------------------------------------------------------------------------------
438
466
  #nameOf(id) {
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.27.0";
1
+ export declare const VERSION = "0.28.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.27.0";
1
+ export const VERSION = "0.28.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.27.0",
3
+ "version": "0.28.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",
@@ -387,7 +387,7 @@
387
387
  },
388
388
  "packageManager": "pnpm@10.28.0",
389
389
  "dependencies": {
390
- "@johnmorrisdotca/kazoku-ui": "^0.24.0"
390
+ "@johnmorrisdotca/kazoku-ui": "^0.27.0"
391
391
  },
392
392
  "peerDependencies": {
393
393
  "@johnmorrisdotca/chikyu-earth": ">=0.10.0",