@johnmorrisdotca/wakusei-planets 0.35.0 → 0.37.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/NOTICE.md +31 -1
  3. package/README.md +5 -4
  4. package/dist/data/moon-catalogue.d.ts +31 -0
  5. package/dist/data/moon-catalogue.js +471 -0
  6. package/dist/data/orbiters.d.ts +368 -0
  7. package/dist/data/orbiters.js +370 -0
  8. package/dist/data/places-planned.d.ts +3 -0
  9. package/dist/data/places-planned.js +51 -0
  10. package/dist/element.d.ts +28 -0
  11. package/dist/element.js +172 -1
  12. package/dist/moon-catalogue.d.ts +296 -0
  13. package/dist/moon-catalogue.js +234 -0
  14. package/dist/orbiter-facts.d.ts +480 -0
  15. package/dist/orbiter-facts.js +189 -0
  16. package/dist/orbiters.d.ts +256 -0
  17. package/dist/orbiters.js +275 -0
  18. package/dist/place-marks.d.ts +182 -0
  19. package/dist/place-marks.js +194 -0
  20. package/dist/places/mars.d.ts +1 -1
  21. package/dist/places/mars.js +4 -2
  22. package/dist/places/moon.d.ts +1 -1
  23. package/dist/places/moon.js +4 -2
  24. package/dist/places.d.ts +4 -2
  25. package/dist/places.js +2 -0
  26. package/dist/scene/place-layer.d.ts +68 -0
  27. package/dist/scene/place-layer.js +213 -0
  28. package/dist/scene/textures.d.ts +2 -2
  29. package/dist/space/all-moons.d.ts +30 -0
  30. package/dist/space/all-moons.js +61 -0
  31. package/dist/space/bodies.d.ts +18 -0
  32. package/dist/space/bodies.js +18 -0
  33. package/dist/space/element.d.ts +182 -6
  34. package/dist/space/element.js +763 -26
  35. package/dist/space/frame.d.ts +14 -0
  36. package/dist/space/frame.js +16 -0
  37. package/dist/space/index.d.ts +5 -2
  38. package/dist/space/index.js +5 -2
  39. package/dist/space/regions.d.ts +111 -0
  40. package/dist/space/regions.js +84 -0
  41. package/dist/space/scene.d.ts +131 -8
  42. package/dist/space/scene.js +312 -15
  43. package/dist/space/sight.d.ts +106 -0
  44. package/dist/space/sight.js +84 -0
  45. package/dist/space/travel.d.ts +256 -0
  46. package/dist/space/travel.js +597 -0
  47. package/dist/version.d.ts +1 -1
  48. package/dist/version.js +1 -1
  49. package/package.json +13 -2
@@ -1,10 +1,11 @@
1
1
  import { carryControls } from "@johnmorrisdotca/kazoku-ui/view-controls";
2
2
  import "../tables/minor.js";
3
- import { BODIES, MOONS_OF } from "../facts.js";
3
+ import { BODIES, BODY_IDS, MOONS_OF } from "../facts.js";
4
4
  import { createGate, frameCap } from "../gate.js";
5
5
  import { arrowCount } from "./arrows.js";
6
6
  import { createGameClock } from "./clock.js";
7
- import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER } from "./bodies.js";
7
+ import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER, systemOf } from "./bodies.js";
8
+ import { sightChanged, sightOf } from "./sight.js";
8
9
  import { chooseLabels } from "./labels.js";
9
10
  import { coverArrows } from "./covered.js";
10
11
  import { createPainter } from "../scene/painter.js";
@@ -14,9 +15,18 @@ import { ownCredit } from "../door/own.js";
14
15
  import { setThreeLoader, takeRenderer } from "../scene/shared.js";
15
16
  import { texturePaths, tilesBase } from "../scene/textures.js";
16
17
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
17
- import { moonOffset } from "../scene/orient.js";
18
+ import { moonOffset, orientation } from "../scene/orient.js";
18
19
  import { moonDistance, placeBodies, radiusIn } from "./scale.js";
20
+ import { groundDirection } from "./aim.js";
21
+ import { besideMoon } from "./beside.js";
22
+ import { SUN_REGIONS } from "./regions.js";
23
+ import { travelArrival } from "./travel.js";
24
+ import { findPlace, PLACE_BODIES } from "../places.js";
25
+ import { placeMarks, readPlaceLayers } from "../place-marks.js";
26
+ import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
27
+ import { cross, dot } from "../vec.js";
19
28
  import { createSpaceItem, FIT_DISTANCE, newSpaceModel, SPACE_BODIES } from "./scene.js";
29
+ export { setPlacesLoader } from "../scene/place-layer.js";
20
30
  export { setThreeLoader, SPACE_BODIES };
21
31
  /** The words the view says on itself for the scale in use. A page in another language gives its own with `scaleNames`. */
22
32
  const SCALE_WORDS = {
@@ -26,12 +36,35 @@ const SCALE_WORDS = {
26
36
  /** A body whose disc is smaller than this many CSS pixels across its radius is marked with a ring as well as its name. */
27
37
  const RING_BELOW_PX = 4;
28
38
  const readLight = (value) => (value === "lit" ? "lit" : "sun");
39
+ /** The kinds of move between two views, as `transition` names them. */
40
+ const TRAVEL_KINDS = ["turn-travel", "direct", "look-back", "auto", "cut"];
41
+ const readTravel = (value, fallback) => {
42
+ const name = typeof value === "string" ? value.trim().toLowerCase() : "";
43
+ return TRAVEL_KINDS.includes(name) ? name : fallback;
44
+ };
45
+ const readPace = (value, fallback) => {
46
+ const n = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : Number.NaN;
47
+ return Number.isFinite(n) && n > 0 ? Math.min(20, Math.max(0.05, n)) : fallback;
48
+ };
49
+ /** A zoom event less than this many milliseconds after the one before is of the same gesture (the family's own window for a turn of the wheel). */
50
+ const GESTURE_GAP_MS = 300;
51
+ const REGION_IDS = SUN_REGIONS.map((region) => region.id);
52
+ const readRegion = (value) => (typeof value === "string" && REGION_IDS.includes(value.trim().toLowerCase()) ? value.trim().toLowerCase() : undefined);
53
+ /** The far names' strength from the attribute: a number from 0 to 1, or undefined when it is not set or not a number. */
54
+ const readFar = (value) => {
55
+ if (value === null || value.trim() === "")
56
+ return undefined;
57
+ const n = Number(value);
58
+ return Number.isFinite(n) ? Math.min(1, Math.max(0, n)) : undefined;
59
+ };
29
60
  const RAD = Math.PI / 180;
30
61
  const REAL_TIME_TICK_MS = 60_000;
31
62
  /** The plain wheel in an immersive view is passed on as a pinch of this share, so a notch (100) zooms about 1.2 times, as the family's mouse wheel does with Alt. */
32
63
  const WHEEL_AS_PINCH = 0.2;
33
64
  /** The least time between two `wakusei-timechange` events while time runs: a few a second at most, however fast the picture is drawn. */
34
65
  const TIME_EVENT_MS = 250;
66
+ /** The least time between two `wakusei-sight` events while the view moves, in milliseconds. */
67
+ const SIGHT_EVENT_MS = 250;
35
68
  const readCentre = (value) => {
36
69
  if (!value)
37
70
  return null;
@@ -57,13 +90,17 @@ const readBody = (value) => {
57
90
  * 1.05 radii from the surface (`FIT_DISTANCE` over the zoom), so past a zoom of about 3.9 nothing moves; 3.6 is where the finest map tiles of the Earth, Mars and the Moon (16384 pixels round) run out of detail too, so it is the same ceiling for both.
58
91
  */
59
92
  const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
60
- const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#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}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label,.sp-ring{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p>`;
93
+ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#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}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p>`;
61
94
  /**
62
95
  * 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`
63
96
  * (`"lon,lat"`), `time` (`now` or an ISO date), `speed` (1 is real time, 0 holds, 86400 is a day a second, negative runs backwards), `scale` (`compressed` or `true`), `look` (`realistic` or `painted`),
64
- * `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), and `texture-base`, `texture-far-base`, `max-texture` and `tiles` (where the finer map tiles are, for a close zoom; `off` for none). Positions come from this package's own models. It draws
97
+ * `light` (`sun` or `lit`), `lang` (`en` or `ja`: the names), `labels` and `orbits` (`off` hides them), `all-moons` (every other known moon as a dot round its planet, from `/moon-catalogue`, fetched when first asked for), and `texture-base`, `texture-far-base`, `max-texture` and `tiles` (where the finer map tiles are, for a close zoom; `off` for none). Positions come from this package's own models. It draws
65
98
  * only when something changes, and nothing while it is out of sight.
66
99
  *
100
+ * The names and markers of bodies outside the system in the middle of the view are drawn at half strength (`far-opacity`, 0 to 1). A body under the pointer, a finger or the keyboard's focus lights its own system instead and
101
+ * sends `wakusei-body-hover` with the body and its system (`wakusei-body-hover-end` when none is). `sight()` says which bodies are in view and, for the rest, the edge of the picture each lies beyond; `wakusei-sight`
102
+ * fires when that changes. None of these draws the picture again.
103
+ *
67
104
  * `immersive` makes it a full-screen view: it fills the box it is in, whatever the shape (the body looked at is framed by the shorter side), the plain wheel zooms and a drag anywhere on it turns it. Without it Ctrl, Command or Alt with the wheel zooms and the plain wheel scrolls the page.
68
105
  *
69
106
  * 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
@@ -87,8 +124,10 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
87
124
  * ```
88
125
  */
89
126
  export class WakuseiSpace extends HTMLElement {
90
- static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", ...NAME_LABEL_ATTRIBUTES];
127
+ static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "orbiters", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "places", "all-moons", "far-opacity", "transition", "pace", ...NAME_LABEL_ATTRIBUTES];
91
128
  #model = newSpaceModel();
129
+ #allMoons = false;
130
+ #catalogue;
92
131
  #clock = createGameClock("now", 1);
93
132
  #view;
94
133
  #gate;
@@ -124,6 +163,12 @@ export class WakuseiSpace extends HTMLElement {
124
163
  #focusBeforeRide = "earth";
125
164
  #lostTold = false;
126
165
  #hands;
166
+ #markLayer;
167
+ #markList;
168
+ #markLoading;
169
+ #markHeard;
170
+ #placeGlide = 0;
171
+ #surface = null;
127
172
  /** 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. */
128
173
  get controller() {
129
174
  return this.#hands?.controller;
@@ -136,15 +181,19 @@ export class WakuseiSpace extends HTMLElement {
136
181
  this.#model.labels = this.getAttribute("labels") !== "off";
137
182
  this.#labelsAlways = this.hasAttribute("labels-always") && this.getAttribute("labels-always") !== "off";
138
183
  this.#covered = this.getAttribute("covered") === "arrow" ? "arrow" : "name";
184
+ this.roadster = this.hasAttribute("roadster") && this.getAttribute("roadster") !== "off";
185
+ this.orbiters = this.hasAttribute("orbiters") && this.getAttribute("orbiters") !== "off";
139
186
  this.#model.orbits = this.getAttribute("orbits") !== "off";
140
187
  this.#model.arrowCount = arrowCount(this.getAttribute("arrows"));
141
188
  this.#model.help = this.hasAttribute("help") && this.getAttribute("help") !== "off";
142
189
  this.#model.helpThrough = this.hasAttribute("help-through") && this.getAttribute("help-through") !== "off";
190
+ this.#travel = { kind: readTravel(this.getAttribute("transition"), "turn-travel"), pace: readPace(this.getAttribute("pace"), 1) };
143
191
  this.#model.look = this.getAttribute("look") === "painted" ? "painted" : "realistic";
144
192
  this.#model.light = readLight(this.getAttribute("light"));
145
193
  this.#relabel();
146
194
  this.#door.book.ownOnly(this.getAttribute("data") === "own");
147
195
  this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
196
+ this.#model.speed = this.#clock.speed;
148
197
  if (!this.hasAttribute("role"))
149
198
  this.setAttribute("role", "img");
150
199
  if (!this.hasAttribute("tabindex"))
@@ -156,7 +205,9 @@ export class WakuseiSpace extends HTMLElement {
156
205
  this.#stage = root.getElementById("stage");
157
206
  this.#labelBox = root.getElementById("labels");
158
207
  this.#scaleLine = root.querySelector(".sp-scale");
208
+ this.#regionLine = root.getElementById("region");
159
209
  this.#nameScale();
210
+ this.#showRegion();
160
211
  this.#pool.clear();
161
212
  this.#rings.clear();
162
213
  this.#arrows.clear();
@@ -179,6 +230,12 @@ export class WakuseiSpace extends HTMLElement {
179
230
  this.#placeLabels(places);
180
231
  this.#door.announce();
181
232
  },
233
+ onSight: (bodies, frame) => this.#see(bodies, frame),
234
+ wantSight: () => this.#sightAsked || this.#sightListeners.size > 0,
235
+ onSurface: (surface) => {
236
+ this.#surface = surface;
237
+ this.#markSurface();
238
+ },
182
239
  onMoving: () => this.#gate?.request(),
183
240
  onRideLost: () => this.#rideLost(),
184
241
  onPainterError: (error) => this.dispatchEvent(new CustomEvent("wakusei-bodies-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
@@ -195,16 +252,32 @@ export class WakuseiSpace extends HTMLElement {
195
252
  });
196
253
  this.#schedule();
197
254
  this.addEventListener("pointerdown", this.#down);
255
+ this.addEventListener("pointermove", this.#move, { passive: true });
256
+ this.addEventListener("pointerleave", this.#leave);
198
257
  // before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
199
258
  this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
200
259
  this.#hands = carryControls(this, { limits: CARRIED_LIMITS, onChange: (view, info) => this.setView(view, info.final) });
260
+ this.#markHeard = onPlacesLoader(() => {
261
+ this.#markList = undefined;
262
+ this.#markSurface();
263
+ });
201
264
  this.#labelBox.addEventListener("click", this.#labelClick);
202
265
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
266
+ this.#labelBox.addEventListener("focusout", this.#labelBlur);
267
+ this.#farStrength();
203
268
  }
204
269
  disconnectedCallback() {
205
270
  this.#hands?.unbind();
206
271
  this.#hands = undefined;
207
272
  this.removeEventListener("pointerdown", this.#down);
273
+ this.removeEventListener("pointermove", this.#move);
274
+ this.removeEventListener("pointerleave", this.#leave);
275
+ window.removeEventListener("pointerup", this.#lift, true);
276
+ window.removeEventListener("pointercancel", this.#lift, true);
277
+ if (this.#hovered !== null)
278
+ this.#hover(null, this.#hoverBy);
279
+ clearTimeout(this.#sightTimer);
280
+ this.#sightTimer = undefined;
208
281
  this.removeEventListener("wheel", this.#wheel, { capture: true });
209
282
  window.removeEventListener("pointerup", this.#up, true);
210
283
  clearTimeout(this.#timer);
@@ -214,6 +287,10 @@ export class WakuseiSpace extends HTMLElement {
214
287
  this.#view = undefined;
215
288
  this.#taken?.release();
216
289
  this.#taken = undefined;
290
+ this.#markLayer?.dispose();
291
+ this.#markLayer = undefined;
292
+ this.#markHeard?.();
293
+ this.#markHeard = undefined;
217
294
  }
218
295
  attributeChangedCallback(name, _old, value) {
219
296
  if (name === "center")
@@ -230,14 +307,26 @@ export class WakuseiSpace extends HTMLElement {
230
307
  this.labelsAlways = value !== null && value !== "off";
231
308
  else if (name === "covered")
232
309
  this.covered = value === "arrow" ? "arrow" : "name";
310
+ else if (name === "roadster")
311
+ this.roadster = value !== null && value !== "off";
312
+ else if (name === "orbiters")
313
+ this.orbiters = value !== null && value !== "off";
233
314
  else if (name === "orbits")
234
315
  this.orbits = value !== "off";
316
+ else if (name === "all-moons")
317
+ this.allMoons = value !== null && value !== "off";
235
318
  else if (name === "arrows")
236
319
  this.arrows = arrowCount(value);
237
320
  else if (name === "help")
238
321
  this.help = value !== null && value !== "off";
322
+ else if (name === "far-opacity")
323
+ this.#farStrength();
239
324
  else if (name === "help-through")
240
325
  this.helpThrough = value !== null && value !== "off";
326
+ else if (name === "transition")
327
+ this.transition = readTravel(value, "turn-travel");
328
+ else if (name === "pace")
329
+ this.pace = readPace(value, 1);
241
330
  else if (name === "look")
242
331
  this.look = value === "painted" ? "painted" : "realistic";
243
332
  else if (name === "light")
@@ -248,10 +337,143 @@ export class WakuseiSpace extends HTMLElement {
248
337
  for (const [id, button] of this.#pool)
249
338
  this.#nameLabel(button, id);
250
339
  this.#nameScale();
340
+ this.#showRegion();
251
341
  this.#relabel();
252
342
  }
253
343
  else if (NAME_LABEL_ATTRIBUTES.includes(name))
254
344
  this.#relabel();
345
+ if (name === "places" || name === "lang")
346
+ this.#markSurface();
347
+ }
348
+ /**
349
+ * The layers of places marked on the body looked at: any of `landing` (crewed landings, landers and rovers), `crash` (crash, impact and atmospheric-entry sites), `planned` (announced landings) and `feature` (named features), from
350
+ * the `places` attribute (`places="landing crash"`; `places` alone or `all` for every layer). Only a body with places (`PLACE_BODIES` from `/places`) shows any, and only once it is big enough on the screen. Setting it writes the attribute.
351
+ */
352
+ get places() {
353
+ return readPlaceLayers(this.getAttribute("places"));
354
+ }
355
+ set places(layers) {
356
+ if (layers === null || layers.length === 0)
357
+ this.removeAttribute("places");
358
+ else
359
+ this.setAttribute("places", layers.join(" "));
360
+ }
361
+ /** The marks laid on the body looked at now: each place's id, its layer and where its mark is, in CSS pixels from the view's top left. */
362
+ get placesShown() {
363
+ return this.#markLayer?.shown ?? [];
364
+ }
365
+ /**
366
+ * Go to a place on a body: the view glides to the body (as `goTo` does), or on the body looked at turns round it, and the camera comes to rest straight above the place. The place is an id (`mars/perseverance`) or an English or Japanese name, on the body looked at
367
+ * unless `body` names another. The zoom stays on the same body and is 1 (the whole body) on another, unless `zoom` is given. Resolves the place, or `undefined` when the body has no place by that name or cannot be looked at.
368
+ *
369
+ * @param text - The place's id or name.
370
+ * @param options - `body`, `smooth` (true by default) and `zoom`.
371
+ * @returns The place, once the move has started.
372
+ */
373
+ async goToPlace(text, options = {}) {
374
+ const body = options.body === undefined ? this.#model.focus : readBody(options.body);
375
+ if (body === undefined || !PLACE_BODIES.includes(body))
376
+ return undefined;
377
+ const list = await this.#loadMarks(body);
378
+ const place = findPlace(list, text);
379
+ if (place === undefined)
380
+ return undefined;
381
+ const model = this.#model;
382
+ const same = body === model.focus;
383
+ const zoom = options.zoom ?? (same ? model.view.zoom : 1);
384
+ // on another body the view glides there (as goTo does) and arrives over the place; on the same one it turns round the body to it, never through it
385
+ if (!same && !this.goTo(body, { smooth: options.smooth, zoom }))
386
+ return undefined;
387
+ // the camera sits along the place's outward direction, which the view's yaw and tilt give as a place on the Earth's globe at the moment the view was last pointed
388
+ const { pole, meridian } = orientation(body, model.time);
389
+ const east = cross(pole, meridian);
390
+ const c = Math.cos(place.lat * RAD);
391
+ const d = [0, 1, 2].map((i) => c * Math.cos(place.lon * RAD) * meridian[i] + c * Math.sin(place.lon * RAD) * east[i] + Math.sin(place.lat * RAD) * pole[i]);
392
+ model.anchor ??= model.time;
393
+ const earth = orientation("earth", model.anchor);
394
+ const lat = Math.asin(Math.max(-1, Math.min(1, dot(d, earth.pole)))) / RAD;
395
+ const lon = Math.atan2(dot(d, cross(earth.pole, earth.meridian)), dot(d, earth.meridian)) / RAD;
396
+ const from = { ...model.view };
397
+ const to = { yaw: model.centre.lon - lon, tilt: model.centre.lat - lat, zoom };
398
+ to.yaw = from.yaw + ((((to.yaw - from.yaw + 180) % 360) + 360) % 360) - 180;
399
+ const apply = (yaw, tilt, z, final) => {
400
+ if (this.#hands !== undefined && !this.hasAttribute("data-kazoku-bar"))
401
+ this.#hands.controller.set({ yaw, tilt, zoom: z }, final, "place");
402
+ else
403
+ this.setView({ yaw, tilt, zoom: z, roll: from.roll, panX: from.panX, panY: from.panY }, final);
404
+ };
405
+ const glide = (this.#placeGlide += 1);
406
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
407
+ if (!same || options.smooth === false || reduced || typeof requestAnimationFrame !== "function") {
408
+ apply(to.yaw, to.tilt, to.zoom, true);
409
+ return place;
410
+ }
411
+ const start = performance.now();
412
+ const step = () => {
413
+ if (glide !== this.#placeGlide || !this.isConnected)
414
+ return;
415
+ const k = Math.min(1, (performance.now() - start) / 900);
416
+ const ease = k * k * (3 - 2 * k);
417
+ apply(from.yaw + (to.yaw - from.yaw) * ease, from.tilt + (to.tilt - from.tilt) * ease, from.zoom + (to.zoom - from.zoom) * ease, k >= 1);
418
+ if (k < 1)
419
+ requestAnimationFrame(step);
420
+ };
421
+ requestAnimationFrame(step);
422
+ return place;
423
+ }
424
+ async #loadMarks(body) {
425
+ if (this.#markList?.body === body)
426
+ return this.#markList.list;
427
+ const load = placesLoader();
428
+ if (load === undefined)
429
+ return [];
430
+ const list = await load(body);
431
+ this.#markList = { body, list };
432
+ return list;
433
+ }
434
+ /** Lay the marks of the places over the body looked at, as the last draw left it, or take them away. Draws nothing. */
435
+ #markSurface() {
436
+ const layers = this.places;
437
+ const surface = this.#surface;
438
+ const root = this.shadowRoot;
439
+ if (layers.length === 0 || surface === null || root === null || !PLACE_BODIES.includes(surface.id)) {
440
+ if (layers.length === 0 && this.#markLayer !== undefined) {
441
+ this.#markLayer.dispose();
442
+ this.#markLayer = undefined;
443
+ if (this.getAttribute("role") === "group")
444
+ this.setAttribute("role", "img");
445
+ }
446
+ else
447
+ this.#markLayer?.clear();
448
+ return;
449
+ }
450
+ const id = surface.id;
451
+ if (this.#markList?.body !== id) {
452
+ this.#markLayer?.clear();
453
+ if (this.#markLoading !== id && placesLoader() !== undefined) {
454
+ this.#markLoading = id;
455
+ void this.#loadMarks(id).then(() => {
456
+ this.#markLoading = undefined;
457
+ if (this.#markList?.body === id)
458
+ this.#markSurface();
459
+ }, () => {
460
+ this.#markLoading = undefined;
461
+ });
462
+ }
463
+ return;
464
+ }
465
+ if (this.#markLayer === undefined) {
466
+ this.#markLayer = createPlaceLayer(root, {
467
+ lang: () => (this.getAttribute("lang") === "ja" ? "ja" : "en"),
468
+ pick: (place, at) => this.dispatchEvent(new CustomEvent("wakusei-place", { detail: { body: id, place, x: at.x, y: at.y }, bubbles: true, composed: true })),
469
+ });
470
+ if (this.getAttribute("role") === "img")
471
+ this.setAttribute("role", "group");
472
+ }
473
+ const facts = BODIES[id];
474
+ const ax = facts.axesKm;
475
+ const scale = ax ? [ax[1] / facts.radiusKm, ax[2] / facts.radiusKm, ax[0] / facts.radiusKm] : [1, 1 - facts.flattening, 1];
476
+ this.#markLayer.set(placeMarks(this.#markList.list, layers, { ...surface, scale }, facts.radiusKm));
255
477
  }
256
478
  #bodyLabel;
257
479
  /**
@@ -303,6 +525,7 @@ export class WakuseiSpace extends HTMLElement {
303
525
  if (this.isConnected)
304
526
  this.#model.time = this.#clock.time;
305
527
  this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
528
+ this.#model.speed = this.#clock.speed;
306
529
  this.#schedule();
307
530
  this.#gate?.request();
308
531
  if (this.#clock.speed === 0 && was !== 0)
@@ -335,6 +558,83 @@ export class WakuseiSpace extends HTMLElement {
335
558
  label.hidden = true;
336
559
  this.#gate?.request();
337
560
  }
561
+ #travel = { kind: "turn-travel", pace: 1 };
562
+ #regionLine;
563
+ /** When the last zoom event was heard at a stage out from the Sun (ms of the page's clock). The events of one gesture (a pinch, a turn of the wheel) come less than `GESTURE_GAP_MS` apart: one gesture is one step. */
564
+ #regionZoomAt = Number.NEGATIVE_INFINITY;
565
+ /**
566
+ * How the camera moves from one view to the next: `turn-travel` (the default: turn beside the body being left until the next is in the picture, then travel to it, never an empty frame), `direct` (a straight
567
+ * eased glide), `look-back` (straight, watching the body left until the end), `auto` (`turn-travel`), `cut` (no move). The attribute `transition` says the same; `goTo` and `ride` take one for a single move. A
568
+ * reader who asked for reduced motion always gets `cut`.
569
+ */
570
+ get transition() {
571
+ return this.#travel.kind;
572
+ }
573
+ set transition(value) {
574
+ this.#travel = { ...this.#travel, kind: readTravel(value, this.#travel.kind) };
575
+ }
576
+ /** How slow the moves are: the plan's own length times this (1 by default; 2 is twice as slow). The attribute `pace` says the same; `goTo` and `ride` take `duration` in milliseconds for a single move instead. */
577
+ get pace() {
578
+ return this.#travel.pace;
579
+ }
580
+ set pace(value) {
581
+ this.#travel = { ...this.#travel, pace: readPace(value, this.#travel.pace) };
582
+ }
583
+ /** The stage out from the Sun the view is framed on (`inner-planets`, `asteroid-belt`, `outer-planets`, `kuiper-belt`, `whole-system`), or null for a view of a body. */
584
+ get region() {
585
+ return this.#model.region;
586
+ }
587
+ #orbitersLoading = false;
588
+ /**
589
+ * Show the spacecraft in orbit round the Moon and Mars (the attribute `orbiters`; off by default): each a small dot where `/orbiters` puts it on the date shown, scaled with its body, on its orbit line, with its
590
+ * name beside it in the page's language, once the body is at least 24 CSS pixels in radius on the screen. A modelled or predicted path is drawn dim; a craft with no path is not drawn. The paths (a 9 kB module)
591
+ * are loaded the first time they are shown. `stats.orbiters` says what was drawn and each one's status.
592
+ */
593
+ get orbiters() {
594
+ return this.#model.orbiters;
595
+ }
596
+ set orbiters(value) {
597
+ this.#model.orbiters = value;
598
+ if (value && this.#model.orbiterSet === null && !this.#orbitersLoading) {
599
+ this.#orbitersLoading = true;
600
+ void import("../orbiters.js").then((mod) => {
601
+ this.#model.orbiterSet = {
602
+ ids: mod.ORBITER_IDS,
603
+ centre: (id) => mod.orbiterCentre(id),
604
+ position: (id, ms) => (mod.orbiterElements(id) === undefined ? null : mod.orbiterPosition(id, ms)),
605
+ path: (id, ms, points) => mod.orbiterPath(id, ms, points),
606
+ status: (id, ms) => mod.orbiterStatus(id, ms),
607
+ name: (id) => ({ ...mod.orbiterFacts(id).name }),
608
+ };
609
+ this.#gate?.request();
610
+ }, () => {
611
+ this.#orbitersLoading = false;
612
+ });
613
+ }
614
+ this.#gate?.request();
615
+ }
616
+ #roadsterLoading = false;
617
+ /**
618
+ * Show Starman and the Tesla Roadster (the attribute `roadster`; off by default): a small marked body where `/roadster` puts the car on the date shown, on its orbit line (about one trip round the Sun), with its name
619
+ * (`Starman`, `スターマン`) beside it, from the launch in 2018 to the end of 2035. Its path (a 20 kB table) is loaded the first time it is shown, and never when it is not. `stats.roadster` says what was drawn.
620
+ */
621
+ get roadster() {
622
+ return this.#model.roadster;
623
+ }
624
+ set roadster(value) {
625
+ this.#model.roadster = value;
626
+ if (value && this.#model.roadsterPath === null && !this.#roadsterLoading) {
627
+ this.#roadsterLoading = true;
628
+ // the table comes with the module, so it is fetched only when the car is first shown
629
+ void import("../roadster.js").then((mod) => {
630
+ this.#model.roadsterPath = { positionAu: (ms) => mod.roadsterPositionAu(ms), record: { ...mod.ROADSTER.record }, name: { ...mod.ROADSTER.name } };
631
+ this.#gate?.request();
632
+ }, () => {
633
+ this.#roadsterLoading = false;
634
+ });
635
+ }
636
+ this.#gate?.request();
637
+ }
338
638
  #covered = "name";
339
639
  #arrows = new Map();
340
640
  /**
@@ -362,6 +662,61 @@ export class WakuseiSpace extends HTMLElement {
362
662
  if (this.#places)
363
663
  this.#placeLabels(this.#places);
364
664
  }
665
+ /**
666
+ * How strongly the names and markers of bodies outside the system in the middle of the view are drawn, from 0 (not at all) to 1 (as strongly as the others): the attribute `far-opacity`, 0.5 when it is not set
667
+ * (a page may set the CSS property `--wakusei-far-opacity` instead). The system in the middle is the body looked at, the body it goes round, and that body's moons; while a body is under the pointer, a finger or the
668
+ * keyboard's focus, its own system is drawn at full strength instead, and the rest at this strength.
669
+ */
670
+ get farOpacity() {
671
+ return readFar(this.getAttribute("far-opacity")) ?? 0.5;
672
+ }
673
+ set farOpacity(value) {
674
+ this.setAttribute("far-opacity", String(Math.min(1, Math.max(0, value))));
675
+ }
676
+ #farStrength() {
677
+ const far = readFar(this.getAttribute("far-opacity"));
678
+ if (far === undefined)
679
+ this.#labelBox?.style.removeProperty("--wakusei-far-opacity");
680
+ else
681
+ this.#labelBox?.style.setProperty("--wakusei-far-opacity", String(far));
682
+ }
683
+ /** The body under the pointer, a finger or the keyboard's focus now, or null: its system's names are drawn at full strength. */
684
+ get hovered() {
685
+ return this.#hovered;
686
+ }
687
+ /**
688
+ * Where each body is for the picture at the last draw: in view or not, and for one out of view the edge of the picture it lies beyond, the point on that edge, the way to it, and whether it is behind the camera. It
689
+ * covers the Sun, the planets, the dwarf planets and the minor bodies, the moons of the body looked at and any other moon drawn; not the body the camera rides on. `wakusei-sight` fires with the same list whenever a
690
+ * body comes into view or leaves it, changes edge, or moves 8 CSS pixels along its edge, at most four times a second with a last one when the view settles, and never at rest: a page draws its own tabs at the edges
691
+ * from it. The view works it out only once it is asked: the first call (or the first `wakusei-sight` listener) asks for one draw, and the list is there from that draw on.
692
+ */
693
+ sight() {
694
+ if (!this.#sightAsked) {
695
+ this.#sightAsked = true;
696
+ this.#gate?.request();
697
+ }
698
+ return Object.values(this.#sight).map((one) => ({ ...one }));
699
+ }
700
+ #sightAsked = false;
701
+ #sightListeners = new Set();
702
+ addEventListener(type, listener, options) {
703
+ if (listener === null)
704
+ return;
705
+ super.addEventListener(type, listener, options);
706
+ if (type !== "wakusei-sight")
707
+ return;
708
+ const first = this.#sightListeners.size === 0 && !this.#sightAsked;
709
+ this.#sightListeners.add(listener);
710
+ if (first)
711
+ this.#gate?.request();
712
+ }
713
+ removeEventListener(type, listener, options) {
714
+ if (listener === null)
715
+ return;
716
+ super.removeEventListener(type, listener, options);
717
+ if (type === "wakusei-sight")
718
+ this.#sightListeners.delete(listener);
719
+ }
365
720
  get orbits() {
366
721
  return this.#model.orbits;
367
722
  }
@@ -369,6 +724,32 @@ export class WakuseiSpace extends HTMLElement {
369
724
  this.#model.orbits = value;
370
725
  this.#gate?.request();
371
726
  }
727
+ /**
728
+ * Whether every other known moon is drawn as a small dot round its planet (the attribute `all-moons`): the moons of `/moon-catalogue` the view does not draw in full, each at its mean-orbit place. The catalogue is fetched,
729
+ * as a chunk of its own, the first time they are turned on; a view that never turns them on never loads it.
730
+ */
731
+ get allMoons() {
732
+ return this.#allMoons;
733
+ }
734
+ set allMoons(value) {
735
+ this.#allMoons = value;
736
+ if (!value) {
737
+ this.#model.allMoons = null;
738
+ this.#gate?.request();
739
+ return;
740
+ }
741
+ this.#catalogue ??= import("../moon-catalogue.js").then(({ MOON_CATALOGUE, catalogueMoonPosition }) => {
742
+ const hosts = [...SPACE_PLANETS, ...SPACE_DWARFS];
743
+ const shown = MOON_CATALOGUE.filter((m) => !m.full && m.orbit !== null && hosts.includes(m.host));
744
+ return (ms) => shown.map((m) => ({ host: m.host, km: catalogueMoonPosition(m, ms) }));
745
+ });
746
+ void this.#catalogue.then((dots) => {
747
+ if (!this.#allMoons)
748
+ return;
749
+ this.#model.allMoons = dots;
750
+ this.#gate?.request();
751
+ });
752
+ }
372
753
  /** How many small arrowheads each orbit line carries to show which way the body goes: 2 by default, at most 4, 0 for none (the attribute `arrows` says the same). Anything else is made a whole number in that range. */
373
754
  get arrows() {
374
755
  return this.#model.arrowCount;
@@ -424,6 +805,23 @@ export class WakuseiSpace extends HTMLElement {
424
805
  */
425
806
  setView(view, final = true) {
426
807
  const now = this.#model.view;
808
+ if (this.#model.region !== null && view.zoom !== 1) {
809
+ // at a stage out from the Sun a zoom gesture is a step: out to the next stage, in to the one before (or the Sun); one gesture, one step, and the controls go back to holding zoom 1 (the element's own
810
+ // hands are set here; a bar bound to the element hears `wakusei-hop` with zoom 1, which a step or a refused gesture both announce)
811
+ const at = performance.now();
812
+ const fresh = at - this.#regionZoomAt > GESTURE_GAP_MS;
813
+ this.#regionZoomAt = at;
814
+ if (fresh && this.#model.transition === null) {
815
+ if (view.zoom < 1)
816
+ this.stepOut();
817
+ else
818
+ this.stepIn();
819
+ }
820
+ else
821
+ this.#announceHop(1);
822
+ this.#hands?.controller.set({ zoom: 1 }, true, "jump");
823
+ return;
824
+ }
427
825
  const [roll, panX, panY] = [view.roll ?? 0, view.panX ?? 0, view.panY ?? 0];
428
826
  if (view.yaw === now.yaw && view.tilt === now.tilt && view.zoom === now.zoom && roll === now.roll && panX === now.panX && panY === now.panY)
429
827
  return;
@@ -461,35 +859,188 @@ export class WakuseiSpace extends HTMLElement {
461
859
  return { current: this.bodyInfo(here), previous: this.bodyInfo(hopFrom(here, -1, canCentre)), next: this.bodyInfo(hopFrom(here, 1, canCentre)) };
462
860
  }
463
861
  /**
464
- * Go to a body: it becomes the middle of the view and the zoom brings it whole into view (`zoom`, 1 by default; a planet's `-moons` preset for its system), gliding there from where the camera is unless `smooth` is
465
- * false or the reader asked for reduced motion. `wakusei-hop` tells the page where it went and where the next and previous hops lead. A name in any case, in English or Japanese, works.
862
+ * Go to a body: it becomes the middle of the view and the zoom brings it whole into view (`zoom`, 1 by default; a planet's `-moons` preset for its system), travelling there from where the camera is (`transition`,
863
+ * the view's own by default; `duration` in milliseconds, the plan's own by default) unless `smooth` is false or the reader asked for reduced motion. The travel arrives from the side it comes from, moved round
864
+ * towards the Sun where that side would show the body mostly dark, so the way in is straight: the controls' yaw and tilt are set to that side. A stage out from the Sun (`inner-planets`, `asteroid-belt`,
865
+ * `outer-planets`, `kuiper-belt`, `whole-system`) is a target too: the Sun is looked at and the camera stands back until the stage's orbits are all in the picture, with the stage's name shown. `wakusei-hop`
866
+ * tells the page where it went and where the next and previous hops lead. A name in any case, in English or Japanese, works.
466
867
  *
467
- * @param target - A body's name (`"saturn"`, `"Saturn"`, `"土星"`).
468
- * @param options - `smooth` (true by default) and `zoom` (1 by default).
868
+ * @param target - A body's name (`"saturn"`, `"Saturn"`, `"土星"`) or a stage's id.
869
+ * @param options - `smooth` (true by default), `zoom` (1 by default), `transition` and `duration`.
469
870
  * @returns Whether the view can go there.
470
871
  */
471
872
  goTo(target, options = {}) {
873
+ const region = readRegion(target);
874
+ if (region !== undefined) {
875
+ this.#goToRegion(region, options);
876
+ return true;
877
+ }
472
878
  const id = readBody(target);
473
879
  if (!id)
474
880
  return false;
475
881
  const model = this.#model;
476
- const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
477
- const pose = model.pose;
478
- const glide = (options.smooth ?? true) && !reduced && pose.valid && model.ride === null;
882
+ const leaving = this.#leaving();
883
+ const kind = this.#moveKind(options, id);
479
884
  if (model.ride !== null)
480
885
  this.ride(null, { smooth: false });
481
- model.transition = glide ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
886
+ model.transition = this.#startMove(kind, leaving, id, options.duration);
887
+ model.region = null;
888
+ this.#showRegion();
482
889
  this.#selected = id;
483
890
  this.#model.focus = id;
484
891
  const zoom = options.zoom ?? 1;
485
- // a bar bound to the element holds the view's state: it applies the zoom the page hears in the event; without one the element's own hands do
892
+ // the side the camera comes from, as the controls' yaw and tilt: the element's own hands are set to it here, and a bar bound to the element (which holds the view's state) hears it in the event with the zoom
893
+ const side = model.transition !== null ? this.#faceApproach(id) : null;
486
894
  if (!this.hasAttribute("data-kazoku-bar"))
487
- this.#hands?.controller.set({ zoom }, true, "jump");
895
+ this.#hands?.controller.set(side ? { ...side, zoom } : { zoom }, true, "jump");
488
896
  this.#schedule();
489
897
  this.#gate?.request();
490
- this.#announceHop(zoom);
898
+ this.#announceHop(zoom, side ?? undefined);
491
899
  return true;
492
900
  }
901
+ /** The body the camera is at now: the target of the ride, or the body looked at. */
902
+ #leaving() {
903
+ const ride = this.#model.ride;
904
+ if (ride !== null)
905
+ return typeof ride.target === "string" ? ride.target : ride.around;
906
+ return this.#model.focus;
907
+ }
908
+ /**
909
+ * The kind of move a call gets: `cut` for `smooth: false`, for a reader who asked for reduced motion, or before the first draw; else the call's `transition`, or the view's. `auto` is `direct` when the
910
+ * destination is on the screen as the move starts (it stays in view and grows), `turn-travel` when it is not.
911
+ */
912
+ #moveKind(options, destination = null) {
913
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
914
+ if (!(options.smooth ?? true) || reduced || !this.#model.pose.valid)
915
+ return "cut";
916
+ const kind = readTravel(options.transition, this.#travel.kind);
917
+ if (kind !== "auto")
918
+ return kind;
919
+ const place = destination === null ? null : this.placeOf(destination);
920
+ const inView = place !== null && place.x >= 0 && place.y >= 0 && place.x <= this.clientWidth && place.y <= this.clientHeight;
921
+ return inView ? "direct" : "turn-travel";
922
+ }
923
+ /** A move from where the last draw left the camera, or null for a cut. The scene builds its path at the next draw. */
924
+ #startMove(kind, leaving, destination, duration) {
925
+ if (kind === "cut")
926
+ return null;
927
+ const pose = this.#model.pose;
928
+ const leavingReach = this.#model.region !== null && leaving === "sun" ? (this.#model.regionDrawn?.reach ?? 0) : 0;
929
+ return {
930
+ start: performance.now(),
931
+ duration: typeof duration === "number" && Number.isFinite(duration) && duration > 0 ? duration : 0,
932
+ pace: this.#travel.pace,
933
+ kind,
934
+ from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov },
935
+ leaving,
936
+ destination,
937
+ leavingReach,
938
+ input: null,
939
+ plan: null,
940
+ origin: [0, 0, 0],
941
+ };
942
+ }
943
+ /** Where a body is drawn now, in Earth radii from the Earth's centre, and its drawn radius: the places the scene uses, worked out the same way. */
944
+ #site(id) {
945
+ const mode = this.#model.mode;
946
+ const pos = placeBodies(mode, frameAt(this.#model.time));
947
+ if (SPACE_BODIES.includes(id))
948
+ return { at: [...pos[id]], radius: radiusIn(id, mode) };
949
+ const host = (hostOf(id) ?? "earth");
950
+ const real = moonOffset(id, this.#model.time);
951
+ const d = Math.hypot(real[0], real[1], real[2]);
952
+ const k = (d === 0 ? 1 : moonDistance(mode, host, d) / d) * radiusIn(host, mode);
953
+ const centre = pos[host];
954
+ return { at: [centre[0] + real[0] * k, centre[1] + real[1] * k, centre[2] + real[2] * k], radius: Math.max(1e-6, (BODIES[id].radiusKm / BODIES[host].radiusKm) * radiusIn(host, mode)) };
955
+ }
956
+ /**
957
+ * The controls' yaw and tilt that look at a body from the side the camera comes from (moved round towards the Sun where that side would show it mostly dark), so the move in is straight and nothing is turned
958
+ * back on arrival; null when the camera has not drawn yet.
959
+ */
960
+ #faceApproach(id) {
961
+ const model = this.#model;
962
+ if (!model.pose.valid)
963
+ return null;
964
+ const body = this.#site(id);
965
+ const sun = id === "sun" ? undefined : this.#site("sun").at;
966
+ const wanted = travelArrival({ body: body.at, radius: body.radius, from: model.camera.position, sun, aspect: 16 / 9 });
967
+ const side = [wanted.position[0] - body.at[0], wanted.position[1] - body.at[1], wanted.position[2] - body.at[2]];
968
+ const anchor = model.anchor ?? model.time;
969
+ // the scene aims from the ground direction of (lon - yaw, lat - tilt) at the anchor moment: search the pair that lies along the wanted side, coarse then fine
970
+ const score = (yaw, tilt) => {
971
+ const aim = groundDirection(model.centre.lon - yaw, Math.max(-90, Math.min(90, model.centre.lat - tilt)), anchor);
972
+ return aim[0] * side[0] + aim[1] * side[1] + aim[2] * side[2];
973
+ };
974
+ let best = { yaw: model.view.yaw, tilt: model.view.tilt, score: -Infinity };
975
+ for (let yaw = -180; yaw < 180; yaw += 6)
976
+ for (let tilt = -85; tilt <= 85; tilt += 5) {
977
+ const n = score(yaw, tilt);
978
+ if (n > best.score)
979
+ best = { yaw, tilt, score: n };
980
+ }
981
+ for (let yaw = best.yaw - 6; yaw <= best.yaw + 6; yaw += 1)
982
+ for (let tilt = Math.max(-89, best.tilt - 5); tilt <= Math.min(89, best.tilt + 5); tilt += 1) {
983
+ const n = score(yaw, tilt);
984
+ if (n > best.score)
985
+ best = { yaw, tilt, score: n };
986
+ }
987
+ return { yaw: best.yaw, tilt: best.tilt };
988
+ }
989
+ /** Go to a stage out from the Sun: the Sun is looked at and the camera stands back until every orbit of the stage is in the picture; from another stage the move is a straight pull back or push in. */
990
+ #goToRegion(region, options) {
991
+ const model = this.#model;
992
+ const leaving = this.#leaving();
993
+ const kind = this.#moveKind(options, "sun");
994
+ if (model.ride !== null)
995
+ this.ride(null, { smooth: false });
996
+ model.transition = this.#startMove(kind, model.region !== null ? "sun" : leaving, "sun", options.duration);
997
+ model.region = region;
998
+ this.#selected = "sun";
999
+ model.focus = "sun";
1000
+ // at a stage the controls hold zoom 1: a zoom gesture is taken as a step out or in, not as a zoom
1001
+ if (!this.hasAttribute("data-kazoku-bar"))
1002
+ this.#hands?.controller.set({ zoom: 1 }, true, "jump");
1003
+ this.#showRegion();
1004
+ this.#schedule();
1005
+ this.#gate?.request();
1006
+ this.#announceHop(1);
1007
+ this.dispatchEvent(new CustomEvent("wakusei-region", { detail: { region, name: this.#regionName(region) }, bubbles: true, composed: true }));
1008
+ }
1009
+ /** The next stage out from the Sun from where the view is (the first stage from a body), with the same move as `goTo`; null, and nothing done, when the view is already at the widest stage. */
1010
+ stepOut(options = {}) {
1011
+ const here = this.#model.region;
1012
+ const next = here === null ? REGION_IDS[0] : REGION_IDS[REGION_IDS.indexOf(here) + 1];
1013
+ if (next === undefined)
1014
+ return null;
1015
+ this.#goToRegion(next, options);
1016
+ return next;
1017
+ }
1018
+ /** The next stage in towards the Sun from the stage the view is at, or the Sun itself (`"sun"`, zoom 1) from the first stage; null, and nothing done, when the view is not at a stage. */
1019
+ stepIn(options = {}) {
1020
+ const here = this.#model.region;
1021
+ if (here === null)
1022
+ return null;
1023
+ const i = REGION_IDS.indexOf(here);
1024
+ if (i <= 0) {
1025
+ this.goTo("sun", options);
1026
+ return "sun";
1027
+ }
1028
+ this.#goToRegion(REGION_IDS[i - 1], options);
1029
+ return REGION_IDS[i - 1];
1030
+ }
1031
+ #regionName(region) {
1032
+ const name = SUN_REGIONS.find((entry) => entry.id === region).name;
1033
+ return this.getAttribute("lang") === "ja" ? name.ja : name.en;
1034
+ }
1035
+ /** The stage's name in the corner of the view, in the element's language, or nothing at a body. */
1036
+ #showRegion() {
1037
+ const line = this.#regionLine;
1038
+ if (!line)
1039
+ return;
1040
+ const region = this.#model.region;
1041
+ line.textContent = region === null ? "" : this.#regionName(region);
1042
+ line.hidden = region === null;
1043
+ }
493
1044
  /** Go to the next body in the order of `bodyList()` (the Sun, Mercury, Venus, the Earth, the Moon, Mars, Phobos, Deimos, Ceres, Jupiter, its moons, and on), round to the Sun after the last. */
494
1045
  next(options = {}) {
495
1046
  this.goTo(hopFrom(this.#model.focus, 1, canCentre), options);
@@ -511,9 +1062,9 @@ export class WakuseiSpace extends HTMLElement {
511
1062
  set selected(id) {
512
1063
  this.#selected = id;
513
1064
  }
514
- /** `zoom` is the zoom the page should bring the view to: given by `goTo`, left out when the body was only set (the zoom stays). */
515
- #announceHop(zoom) {
516
- this.dispatchEvent(new CustomEvent("wakusei-hop", { detail: { ...this.hopper, zoom }, bubbles: true, composed: true }));
1065
+ /** `zoom` is the zoom the page should bring the view to: given by `goTo`, left out when the body was only set (the zoom stays). `side` is the controls' yaw and tilt that look from the side the camera comes from, given by a `goTo` that travels. */
1066
+ #announceHop(zoom, side) {
1067
+ this.dispatchEvent(new CustomEvent("wakusei-hop", { detail: { ...this.hopper, zoom, ...(side ? { yaw: side.yaw, tilt: side.tilt } : {}) }, bubbles: true, composed: true }));
517
1068
  }
518
1069
  /** The words shown beside each body, for a page in another language (`{ mars: "火星" }`). A body left out keeps its name in the element's `lang`. */
519
1070
  get bodyNames() {
@@ -575,7 +1126,7 @@ export class WakuseiSpace extends HTMLElement {
575
1126
  */
576
1127
  ride(target, options = {}) {
577
1128
  const model = this.#model;
578
- const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1129
+ const leaving = this.#leaving();
579
1130
  const wasRiding = model.ride !== null;
580
1131
  if (target === null) {
581
1132
  model.ride = null;
@@ -594,12 +1145,42 @@ export class WakuseiSpace extends HTMLElement {
594
1145
  model.focus = this.#focusBeforeRide;
595
1146
  }
596
1147
  this.#lostTold = false;
597
- const pose = model.pose;
598
- model.transition = (options.smooth ?? true) && !reduced && pose.valid ? { start: performance.now(), duration: 1200, from: { p: [pose.p[0], pose.p[1], pose.p[2]], q: [pose.q[0], pose.q[1], pose.q[2], pose.q[3]], fov: pose.fov } } : null;
1148
+ const destination = target !== null && typeof target === "string" ? (readBody(target) ?? null) : target === null ? this.#model.focus : null;
1149
+ model.transition = this.#startMove(this.#moveKind(options, destination), leaving, destination, options.duration);
1150
+ if (model.transition !== null && model.ride?.view === "beside" && typeof model.ride.target === "string") {
1151
+ // beside a moon the picture can be swung round the line from its planet by the controls' yaw: take the yaw that puts the camera nearest the side it comes from, so the way in is straight
1152
+ const yaw = this.#besideYaw(model.ride.target);
1153
+ if (yaw !== null && !this.hasAttribute("data-kazoku-bar"))
1154
+ this.#hands?.controller.set({ yaw, tilt: 0 }, true, "jump");
1155
+ }
1156
+ model.region = null;
1157
+ this.#showRegion();
599
1158
  this.#schedule();
600
1159
  this.#gate?.request();
601
1160
  this.dispatchEvent(new CustomEvent("wakusei-ride", { detail: this.riding }));
602
1161
  }
1162
+ /** The controls' yaw for the view from beside a moon that puts the camera nearest the side it comes from, in whole degrees; null before the first draw. */
1163
+ #besideYaw(moon) {
1164
+ const model = this.#model;
1165
+ if (!model.pose.valid)
1166
+ return null;
1167
+ const host = (moon === "moon" ? "earth" : (hostOf(moon) ?? "earth"));
1168
+ const site = this.#site(moon);
1169
+ const planet = this.#site(host);
1170
+ const sun = this.#site("sun").at;
1171
+ const north = orientation(host, model.time).pole;
1172
+ const from = model.camera.position;
1173
+ let best = { yaw: 0, near: -Infinity };
1174
+ for (let yaw = 0; yaw < 360; yaw += 10) {
1175
+ const camera = besideMoon({ moon: site.at, moonRadius: site.radius, host: planet.at, hostRadius: planet.radius, sun, north, aspect: 16 / 9, zoom: 1, yaw, tilt: 0 });
1176
+ const a = [camera.position[0] - site.at[0], camera.position[1] - site.at[1], camera.position[2] - site.at[2]];
1177
+ const b = [from[0] - site.at[0], from[1] - site.at[1], from[2] - site.at[2]];
1178
+ const near = (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) / (Math.hypot(...a) * Math.hypot(...b) || 1);
1179
+ if (near > best.near)
1180
+ best = { yaw, near };
1181
+ }
1182
+ return best.yaw;
1183
+ }
603
1184
  #resolveRide(target, options) {
604
1185
  const look = options.look ?? "down";
605
1186
  const distanceKm = Math.max(100, options.distanceKm ?? 3000);
@@ -711,12 +1292,17 @@ export class WakuseiSpace extends HTMLElement {
711
1292
  bodies: { look: this.#model.look, painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held },
712
1293
  tiles: { ...this.#model.tiles },
713
1294
  door: { points: this.#model.door.points, sources: this.#door.book.stats() },
1295
+ allMoons: { on: this.#allMoons, loaded: this.#model.allMoons !== null, dots: this.#model.moonDots },
714
1296
  ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
1297
+ travelling: this.#model.travelling === null ? null : { ...this.#model.travelling },
1298
+ region: this.#model.region === null ? null : { id: this.#model.region, name: this.#regionName(this.#model.region), reach: this.#model.regionDrawn?.reach ?? 0, distance: this.#model.regionDrawn?.distance ?? 0 },
715
1299
  orbits: { drawn: [...this.#model.rings.drawn], miss: { ...this.#model.rings.miss }, hidden: [...this.#model.rings.hidden] },
716
1300
  arrows: Object.fromEntries(Object.entries(this.#model.arrows).map(([id, list]) => [id, list.map((a) => ({ position: [...a.position], direction: [...a.direction] }))])),
717
1301
  arrowPx: this.#model.arrowPx,
718
1302
  help: this.#model.helpDrawn ? { body: this.#model.helpDrawn.body, axis: [...this.#model.helpDrawn.axis], pole: [...this.#model.helpDrawn.pole], retrograde: this.#model.helpDrawn.retrograde, arcTurn: [...this.#model.helpDrawn.arcTurn] } : null,
719
1303
  bodyLabels: { count: this.#model.labelsDrawn.count, focus: this.#model.labelsDrawn.focus === null ? null : { ...this.#model.labelsDrawn.focus } },
1304
+ orbiters: { count: this.#model.orbitersDrawn.count, status: { ...this.#model.orbitersDrawn.status } },
1305
+ roadster: { shown: this.#model.roadsterDrawn.shown, position: this.#model.roadsterDrawn.position === null ? null : [...this.#model.roadsterDrawn.position], radiusPx: this.#model.roadsterDrawn.radiusPx },
720
1306
  };
721
1307
  }
722
1308
  // --- the game clock ----------------------------------------------------------------------------------------------------------------------------
@@ -761,7 +1347,12 @@ export class WakuseiSpace extends HTMLElement {
761
1347
  };
762
1348
  // --- labels --------------------------------------------------------------------------------------------------------------------------------------
763
1349
  #nameOf(id) {
764
- return this.#names[id] ?? BODIES[id].name[this.getAttribute("lang") === "ja" ? "ja" : "en"];
1350
+ const lang = this.getAttribute("lang") === "ja" ? "ja" : "en";
1351
+ if (id === "roadster")
1352
+ return this.#names[id] ?? this.#model.roadsterPath?.name[lang] ?? "Starman";
1353
+ if (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))
1354
+ return this.#names[id] ?? this.#model.orbiterSet.name(id)[lang];
1355
+ return this.#names[id] ?? BODIES[id].name[lang];
765
1356
  }
766
1357
  #placeLabels(places) {
767
1358
  this.#places = places;
@@ -810,6 +1401,7 @@ export class WakuseiSpace extends HTMLElement {
810
1401
  }
811
1402
  // no two names overlap: a moon gives way to its planet and a planet to the Sun
812
1403
  const shown = chooseLabels(wanted);
1404
+ this.#nameBoxes = wanted.filter((one) => shown.has(one.id));
813
1405
  for (const id of ids) {
814
1406
  const label = this.#pool.get(id);
815
1407
  const ring = this.#rings.get(id);
@@ -846,7 +1438,127 @@ export class WakuseiSpace extends HTMLElement {
846
1438
  ring.style.transform = `translate(${Math.round(places[id].x)}px,${Math.round(places[id].y)}px)`;
847
1439
  }
848
1440
  this.#placeArrows(places);
1441
+ this.#markFar();
1442
+ }
1443
+ // --- far names, and the system under the pointer ---------------------------------------------------------------------------------------------------
1444
+ #hovered = null;
1445
+ #hoverBy = "pointer";
1446
+ #nameBoxes = [];
1447
+ /** The bodies drawn at full strength: the system of the body under the pointer, or else the one in the middle of the view. */
1448
+ #lit() {
1449
+ // the Sun in the middle lights the Sun and the eight planets; a body pointed at, the Sun too, lights its own system
1450
+ if (this.#hovered === null && this.#model.focus === "sun")
1451
+ return new Set(["sun", ...BODY_IDS.filter((id) => BODIES[id].kind === "planet")]);
1452
+ const { host, moons } = systemOf(this.#hovered ?? this.#model.focus);
1453
+ return new Set([host, ...moons]);
1454
+ }
1455
+ /** Mark the names, rings and arrows of the bodies outside the lit system: they are drawn at the far strength. Only what changed is touched, and nothing is drawn again. */
1456
+ #markFar() {
1457
+ const lit = this.#lit();
1458
+ const mark = (el, id) => {
1459
+ const far = id !== undefined && !lit.has(id);
1460
+ if (el.hasAttribute("data-far") !== far)
1461
+ el.toggleAttribute("data-far", far);
1462
+ };
1463
+ for (const [id, label] of this.#pool)
1464
+ mark(label, id);
1465
+ for (const [id, ring] of this.#rings)
1466
+ mark(ring, id);
1467
+ for (const arrow of this.#arrows.values())
1468
+ mark(arrow, arrow.dataset["body"]);
1469
+ }
1470
+ /** A body comes under the pointer, a finger or the keyboard's focus (`wakusei-body-hover`, with its system), or none does (`wakusei-body-hover-end`). */
1471
+ #hover(id, by) {
1472
+ if (id === this.#hovered) {
1473
+ if (id !== null)
1474
+ this.#hoverBy = by;
1475
+ return;
1476
+ }
1477
+ const was = this.#hovered;
1478
+ this.#hovered = id;
1479
+ this.#hoverBy = by;
1480
+ this.#markFar();
1481
+ if (id !== null)
1482
+ this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { ...this.bodyInfo(id), system: systemOf(id) }, bubbles: true, composed: true }));
1483
+ else if (was !== null)
1484
+ this.dispatchEvent(new CustomEvent("wakusei-body-hover-end", { detail: { id: was }, bubbles: true, composed: true }));
1485
+ }
1486
+ /** The body at a point of the element, in CSS pixels: on its disc (at least 14 pixels round its place) or on its name. */
1487
+ #bodyAt(x, y) {
1488
+ if (!this.#places || !this.#model.labels)
1489
+ return null;
1490
+ let best = null;
1491
+ let bestD = Infinity;
1492
+ for (const [id, at] of Object.entries(this.#places)) {
1493
+ if (!at)
1494
+ continue;
1495
+ const d = Math.hypot(x - at.x, y - at.y);
1496
+ if (d <= Math.max(at.r, 14) && d < bestD) {
1497
+ best = id;
1498
+ bestD = d;
1499
+ }
1500
+ }
1501
+ if (best !== null)
1502
+ return best;
1503
+ for (const box of this.#nameBoxes)
1504
+ if (x >= box.x && x <= box.x + box.width && y >= box.y && y <= box.y + box.height)
1505
+ return box.id;
1506
+ return null;
849
1507
  }
1508
+ #pointAt(event) {
1509
+ const rect = this.getBoundingClientRect();
1510
+ return this.#bodyAt(event.clientX - rect.left, event.clientY - rect.top);
1511
+ }
1512
+ // a mouse or a pen that moves over the view with no button down; a drag that turns the view leaves the lit system as it is
1513
+ #move = (event) => {
1514
+ if (event.pointerType === "touch" || event.buttons !== 0)
1515
+ return;
1516
+ if (this.#hoverBy === "focus" && this.#hovered !== null)
1517
+ return;
1518
+ this.#hover(this.#pointAt(event), "pointer");
1519
+ };
1520
+ #leave = (event) => {
1521
+ if (event.pointerType !== "touch" && this.#hoverBy === "pointer")
1522
+ this.#hover(null, "pointer");
1523
+ };
1524
+ #labelBlur = (event) => {
1525
+ const next = event.relatedTarget;
1526
+ if (this.#hoverBy === "focus" && !(next && this.#labelBox?.contains(next)))
1527
+ this.#hover(null, "focus");
1528
+ };
1529
+ /** Where each body is for the picture: kept for `sight()`, and told to the page when it changes enough to matter. */
1530
+ #sight = {};
1531
+ #told = {};
1532
+ #see(bodies, frame) {
1533
+ const now = {};
1534
+ for (const [id, input] of Object.entries(bodies)) {
1535
+ const body = id;
1536
+ const one = { id: body, kind: bodyKindOf(body), ...sightOf(input, frame.width, frame.height, frame.axis) };
1537
+ const host = hostOf(body);
1538
+ if (host !== undefined)
1539
+ one.host = host;
1540
+ now[id] = one;
1541
+ }
1542
+ this.#sight = now;
1543
+ if (this.#sightTimer !== undefined || !sightChanged(this.#told, now))
1544
+ return;
1545
+ // at most four times a second while the view moves; the last change is told when the wait is over
1546
+ const wait = this.#sightSent + SIGHT_EVENT_MS - performance.now();
1547
+ if (wait > 0)
1548
+ this.#sightTimer = setTimeout(this.#tellSight, wait);
1549
+ else
1550
+ this.#tellSight();
1551
+ }
1552
+ #sightSent = -Infinity;
1553
+ #sightTimer;
1554
+ #tellSight = () => {
1555
+ this.#sightTimer = undefined;
1556
+ if (!this.isConnected || !sightChanged(this.#told, this.#sight))
1557
+ return;
1558
+ this.#told = this.#sight;
1559
+ this.#sightSent = performance.now();
1560
+ this.dispatchEvent(new CustomEvent("wakusei-sight", { detail: { bodies: Object.values(this.#sight).map((one) => ({ ...one })) } }));
1561
+ };
850
1562
  /** The quiet arrows for the bodies behind others (`covered="arrow"`): one per covering disc, just outside its edge, named for the surest body behind and counting the rest. */
851
1563
  #placeArrows(places) {
852
1564
  const box = this.#labelBox;
@@ -889,6 +1601,10 @@ export class WakuseiSpace extends HTMLElement {
889
1601
  return 0;
890
1602
  if (id === "sun")
891
1603
  return 1;
1604
+ if (id === "roadster")
1605
+ return 3;
1606
+ if (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))
1607
+ return 5;
892
1608
  const kind = bodyKindOf(id);
893
1609
  return kind === "moon" ? 4 : kind === "planet" || kind === "star" ? 2 : 3;
894
1610
  }
@@ -949,10 +1665,24 @@ export class WakuseiSpace extends HTMLElement {
949
1665
  #down = (event) => {
950
1666
  if (event.button !== 0)
951
1667
  return;
1668
+ if (event.pointerType === "touch") {
1669
+ // a finger lights the system it is on until it lifts
1670
+ this.#hover(this.#pointAt(event), "pointer");
1671
+ window.addEventListener("pointerup", this.#lift, { capture: true });
1672
+ window.addEventListener("pointercancel", this.#lift, { capture: true });
1673
+ }
952
1674
  this.#downX = event.clientX;
953
1675
  this.#downY = event.clientY;
954
1676
  window.addEventListener("pointerup", this.#up, { capture: true, once: true });
955
1677
  };
1678
+ #lift = (event) => {
1679
+ if (event.pointerType !== "touch")
1680
+ return;
1681
+ window.removeEventListener("pointerup", this.#lift, true);
1682
+ window.removeEventListener("pointercancel", this.#lift, true);
1683
+ if (this.#hoverBy === "pointer")
1684
+ this.#hover(null, "pointer");
1685
+ };
956
1686
  #up = (event) => {
957
1687
  if (Math.hypot(event.clientX - this.#downX, event.clientY - this.#downY) > 6)
958
1688
  return;
@@ -995,6 +1725,11 @@ export class WakuseiSpace extends HTMLElement {
995
1725
  * the middle of the view (`goTo`), unless it already is, so a press never sends the view anywhere else.
996
1726
  */
997
1727
  #press(id) {
1728
+ // the Roadster and the orbiters are no bodies of the package: a press on such a name says so and goes nowhere
1729
+ if (id === "roadster" || (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))) {
1730
+ this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: { id, name: this.#nameOf(id), kind: "spacecraft" }, bubbles: true, composed: true }));
1731
+ return;
1732
+ }
998
1733
  this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
999
1734
  if (this.#selected === id) {
1000
1735
  if (canCentre(id) && this.#model.focus !== id)
@@ -1006,8 +1741,10 @@ export class WakuseiSpace extends HTMLElement {
1006
1741
  }
1007
1742
  #labelFocus = (event) => {
1008
1743
  const id = event.target?.dataset?.["body"];
1009
- if (id)
1010
- this.dispatchEvent(new CustomEvent("wakusei-body-focus", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
1744
+ if (!id)
1745
+ return;
1746
+ this.dispatchEvent(new CustomEvent("wakusei-body-focus", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
1747
+ this.#hover(id, "focus");
1011
1748
  };
1012
1749
  // --- the rest --------------------------------------------------------------------------------------------------------------------------------------
1013
1750
  #painterNow() {