@johnmorrisdotca/wakusei-planets 0.68.0 → 0.70.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 (104) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/NOTICE.md +29 -1
  3. package/README.md +7 -7
  4. package/dist/bodies/moons-jupiter.js +2 -0
  5. package/dist/bodies/moons-mars.js +2 -2
  6. package/dist/bodies/moons-neptune.js +2 -1
  7. package/dist/bodies/moons-pluto.js +2 -2
  8. package/dist/bodies/moons-saturn.js +14 -2
  9. package/dist/data/discovery.js +225 -0
  10. package/dist/data/moon-catalogue.js +15 -15
  11. package/dist/data/orbits.js +15 -0
  12. package/dist/data/shapes/amalthea.d.ts +2 -0
  13. package/dist/data/shapes/amalthea.js +1 -0
  14. package/dist/data/shapes/atlas.d.ts +2 -0
  15. package/dist/data/shapes/atlas.js +1 -0
  16. package/dist/data/shapes/calypso.d.ts +2 -0
  17. package/dist/data/shapes/calypso.js +1 -0
  18. package/dist/data/shapes/daphnis.d.ts +2 -0
  19. package/dist/data/shapes/daphnis.js +1 -0
  20. package/dist/data/shapes/deimos.d.ts +2 -0
  21. package/dist/data/shapes/deimos.js +1 -0
  22. package/dist/data/shapes/epimetheus.d.ts +2 -0
  23. package/dist/data/shapes/epimetheus.js +1 -0
  24. package/dist/data/shapes/helene.d.ts +2 -0
  25. package/dist/data/shapes/helene.js +1 -0
  26. package/dist/data/shapes/hydra.d.ts +2 -0
  27. package/dist/data/shapes/hydra.js +1 -0
  28. package/dist/data/shapes/hyperion.d.ts +2 -0
  29. package/dist/data/shapes/hyperion.js +1 -0
  30. package/dist/data/shapes/janus.d.ts +2 -0
  31. package/dist/data/shapes/janus.js +1 -0
  32. package/dist/data/shapes/larissa.d.ts +2 -0
  33. package/dist/data/shapes/larissa.js +1 -0
  34. package/dist/data/shapes/nix.d.ts +2 -0
  35. package/dist/data/shapes/nix.js +1 -0
  36. package/dist/data/shapes/pan.d.ts +2 -0
  37. package/dist/data/shapes/pan.js +1 -0
  38. package/dist/data/shapes/pandora.d.ts +2 -0
  39. package/dist/data/shapes/pandora.js +1 -0
  40. package/dist/data/shapes/phobos.d.ts +2 -0
  41. package/dist/data/shapes/phobos.js +1 -0
  42. package/dist/data/shapes/phoebe.d.ts +2 -0
  43. package/dist/data/shapes/phoebe.js +1 -0
  44. package/dist/data/shapes/prometheus.d.ts +2 -0
  45. package/dist/data/shapes/prometheus.js +1 -0
  46. package/dist/data/shapes/proteus.d.ts +2 -0
  47. package/dist/data/shapes/proteus.js +1 -0
  48. package/dist/data/shapes/telesto.d.ts +2 -0
  49. package/dist/data/shapes/telesto.js +1 -0
  50. package/dist/data/shapes/thebe.d.ts +2 -0
  51. package/dist/data/shapes/thebe.js +1 -0
  52. package/dist/discovery.d.ts +1 -1
  53. package/dist/earth-places.d.ts +23 -6
  54. package/dist/earth-places.js +29 -8
  55. package/dist/facts.d.ts +21 -4
  56. package/dist/facts.js +71 -38
  57. package/dist/index.d.ts +2 -1
  58. package/dist/index.js +2 -1
  59. package/dist/moon-catalogue.d.ts +1 -1
  60. package/dist/nearest.js +2 -0
  61. package/dist/picture-credits.js +3 -0
  62. package/dist/place-search.d.ts +22 -0
  63. package/dist/place-search.js +25 -0
  64. package/dist/places/search.d.ts +19 -2
  65. package/dist/places/search.js +50 -1
  66. package/dist/scene/body-places.d.ts +98 -0
  67. package/dist/scene/body-places.js +112 -0
  68. package/dist/scene/body.js +10 -5
  69. package/dist/scene/earth-places.d.ts +114 -1
  70. package/dist/scene/earth-places.js +200 -7
  71. package/dist/scene/glsl.d.ts +2 -2
  72. package/dist/scene/glsl.js +11 -0
  73. package/dist/scene/look.d.ts +7 -0
  74. package/dist/scene/look.js +1 -0
  75. package/dist/scene/painter.js +18 -3
  76. package/dist/scene/recipes.js +6 -2
  77. package/dist/scene/rings.js +11 -2
  78. package/dist/scene/shape.d.ts +50 -0
  79. package/dist/scene/shape.js +110 -0
  80. package/dist/shape-basis.d.ts +43 -0
  81. package/dist/shape-basis.js +45 -0
  82. package/dist/space/all-moons.d.ts +6 -1
  83. package/dist/space/all-moons.js +5 -1
  84. package/dist/space/element.d.ts +52 -2
  85. package/dist/space/element.js +279 -33
  86. package/dist/space/orbit-lines.d.ts +66 -0
  87. package/dist/space/orbit-lines.js +118 -0
  88. package/dist/space/scale.d.ts +1 -1
  89. package/dist/space/scale.js +20 -5
  90. package/dist/space/scene.d.ts +13 -0
  91. package/dist/space/scene.js +137 -9
  92. package/dist/stops.js +12 -0
  93. package/dist/surface/element.js +3 -3
  94. package/dist/surface/glsl.d.ts +2 -2
  95. package/dist/surface/glsl.js +15 -3
  96. package/dist/surface/height.d.ts +7 -0
  97. package/dist/surface/height.js +10 -0
  98. package/dist/textures/deimos-1024.webp +0 -0
  99. package/dist/textures/deimos-512.webp +0 -0
  100. package/dist/textures/phobos-1024.webp +0 -0
  101. package/dist/textures/phobos-512.webp +0 -0
  102. package/dist/textures/phoebe-1024.webp +0 -0
  103. package/dist/textures/phoebe-512.webp +0 -0
  104. package/package.json +1 -1
@@ -25,17 +25,21 @@ import { besideMoon } from "./beside.js";
25
25
  import { SUN_REGIONS } from "./regions.js";
26
26
  import { travelArrival } from "./travel.js";
27
27
  import { controlsFor, readFrame } from "./hold.js";
28
+ import { nearestLine } from "./orbit-lines.js";
28
29
  import { catalogueMoonIdOf, catalogueMoonKey, hostsShowingAll, MOON_HOSTS, moonSourceOf, readMoonColors, readMoonsChoice, readMoonsOf } from "./moon-settings.js";
29
30
  import { findPlace, PLACE_BODIES } from "../places.js";
30
31
  import { marksToShow, pointUnder, readPlaceLayers, readSurfaceNames, spotView } from "../place-marks.js";
31
32
  import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
32
- import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
33
+ import { createEarthPlaceLayer, earthPlaceClick, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, inMarkOrder, onEarthPlacesLayout, readEarthPlaceLayers, readEarthPlaceLook, shownEarthPlaces } from "../scene/earth-places.js";
34
+ import { layBodyPlaces, bodiesOf, readBodyPlacesWith } from "../scene/body-places.js";
33
35
  import { cross, dot, length, sub, unit } from "../vec.js";
34
36
  import { createSpaceItem, FIT_DISTANCE, framedOf, heldAim, moonScaleFor, newSpaceModel, SPACE_BODIES } from "./scene.js";
35
37
  import { paintLengthOf, paintSwathOf } from "../paint/trail.js";
36
38
  export { setPlacesLoader } from "../scene/place-layer.js";
37
39
  export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "../scene/earth-places.js";
38
40
  export { setThreeLoader, SPACE_BODIES };
41
+ /** The small moons that came with their real shapes (Amalthea, Thebe, Saturn's small moons, Hyperion, Phoebe, Larissa): too small to be a companion that frames a move to their planet, so a move to Jupiter still keeps Io or another of the four and takes the side it always took. */
42
+ const SMALL_MOONS = new Set(["amalthea", "thebe", "pan", "daphnis", "atlas", "prometheus", "pandora", "epimetheus", "janus", "telesto", "calypso", "helene", "hyperion", "phoebe", "larissa"]);
39
43
  /** The words the view says on itself for the scale in use. A page in another language gives its own with `scaleNames`. */
40
44
  const SCALE_WORDS = {
41
45
  en: { true: "True distances", compressed: "Distances squeezed to fit" },
@@ -110,9 +114,12 @@ const readBody = (value) => {
110
114
  * 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.
111
115
  */
112
116
  const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
113
- 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[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.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}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none;transition:opacity .35s ease}.sp-oort[data-covered]{opacity:0}@media (prefers-reduced-motion:reduce){.sp-oort{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><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p>`;
117
+ 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[data-flip]{display:flex;flex-direction:row-reverse}.sp-label[data-flip]::before{margin:0 -2px 1px 5px}.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}}.sp-note{position:absolute;left:10px;right:10px;top:28px;max-width:44em;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.92;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-note[hidden],.sp-oort[hidden]{display:none}.sp-oort{position:absolute;left:0;top:0;margin:0;padding:0;font:italic 12px/16px system-ui,-apple-system,sans-serif;color:#aeb8e6;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none;transition:opacity .35s ease}.sp-oort[data-covered]{opacity:0}@media (prefers-reduced-motion:reduce){.sp-oort{transition:none}}.sp-line{position:absolute;inset:0;width:100%;height:100%;overflow:hidden;pointer-events:none}.sp-line[hidden],.sp-linename[hidden]{display:none}.sp-line path{fill:none;stroke-width:2;stroke-linejoin:round;stroke-linecap:round}.sp-linename{position:absolute;left:0;top:0;margin:0;padding:0;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}</style><div id="stage"></div><svg class="sp-line" part="line" aria-hidden="true" hidden><path/></svg><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><p class="sp-note" part="note" role="status" hidden></p><p class="sp-oort" part="oort" hidden></p><p class="sp-linename" part="line-name" hidden></p>`;
114
118
  /** A dot of a moon of the catalogue answers a press within this many CSS pixels: smaller than a body's, so a crowd of dots can be told apart, and more than the dot is wide. */
115
119
  const MOON_DOT_HIT_PX = 9;
120
+ /** How near an orbit line must be to the pointer to be lit by it, and to a press (a finger is less exact), in CSS pixels. */
121
+ const LINE_HIT_PX = 6;
122
+ const LINE_TOUCH_PX = 8;
116
123
  const orbiterLines = (value) => (value === "chosen" || value === "none" ? value : "all");
117
124
  /**
118
125
  * 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`
@@ -147,7 +154,7 @@ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value
147
154
  * ```
148
155
  */
149
156
  export class WakuseiSpace extends HTMLElement {
150
- static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "asteroids", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "all-moons", "moons", "moons-of", "moon-colors", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
157
+ static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "asteroids", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "earth-place-layers", "body-places", "all-moons", "moons", "moons-of", "moon-colors", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
151
158
  #model = newSpaceModel();
152
159
  #moons = "major";
153
160
  #moonsOf = {};
@@ -173,6 +180,8 @@ export class WakuseiSpace extends HTMLElement {
173
180
  #scaleLine;
174
181
  #noteLine;
175
182
  #oortLabel;
183
+ #lineLayer;
184
+ #lineName;
176
185
  /** The belt the camera is flying through, and the point it flies on (the ride's target, to know the ride is still this one). */
177
186
  #flight = null;
178
187
  #spacing = new Map();
@@ -205,6 +214,12 @@ export class WakuseiSpace extends HTMLElement {
205
214
  #earthHeard;
206
215
  #earthList;
207
216
  #earthOmitted = 0;
217
+ #bodyLayer;
218
+ #bodySurfaces = [];
219
+ #bodyList;
220
+ #bodyOmitted = 0;
221
+ // the pointer event of the last press a beam took, so the body under it is not pressed as well
222
+ #beamPress;
208
223
  #surface = null;
209
224
  /** 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. */
210
225
  get controller() {
@@ -260,6 +275,8 @@ export class WakuseiSpace extends HTMLElement {
260
275
  this.#regionLine = root.getElementById("region");
261
276
  this.#noteLine = root.querySelector(".sp-note");
262
277
  this.#oortLabel = root.querySelector(".sp-oort");
278
+ this.#lineLayer = root.querySelector(".sp-line");
279
+ this.#lineName = root.querySelector(".sp-linename");
263
280
  this.#nameScale();
264
281
  this.#showRegion();
265
282
  this.#pool.clear();
@@ -300,6 +317,11 @@ export class WakuseiSpace extends HTMLElement {
300
317
  this.#earthSurface = surface;
301
318
  this.#layEarthPlaces();
302
319
  },
320
+ wantBodyPlaces: () => this.#bodyWanted(),
321
+ onBodyPlaces: (surfaces) => {
322
+ this.#bodySurfaces = surfaces;
323
+ this.#layBodyPlaces();
324
+ },
303
325
  onMoving: () => this.#gate?.request(),
304
326
  onRideLost: () => this.#rideLost(),
305
327
  onPainterError: (error) => this.dispatchEvent(new CustomEvent("wakusei-bodies-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
@@ -327,7 +349,9 @@ export class WakuseiSpace extends HTMLElement {
327
349
  });
328
350
  this.#earthHeard = onEarthPlacesLayout(() => {
329
351
  this.#earthList = undefined;
352
+ this.#bodyList = undefined;
330
353
  this.#askEarthPlaces();
354
+ this.#askBodyPlaces();
331
355
  });
332
356
  this.#labelBox.addEventListener("click", this.#labelClick);
333
357
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
@@ -344,6 +368,7 @@ export class WakuseiSpace extends HTMLElement {
344
368
  window.removeEventListener("pointercancel", this.#lift, true);
345
369
  if (this.#hovered !== null)
346
370
  this.#hover(null, this.#hoverBy);
371
+ this.#lineKey = null;
347
372
  clearTimeout(this.#sightTimer);
348
373
  this.#sightTimer = undefined;
349
374
  this.removeEventListener("wheel", this.#wheel, { capture: true });
@@ -359,6 +384,9 @@ export class WakuseiSpace extends HTMLElement {
359
384
  this.#markLayer = undefined;
360
385
  this.#markHeard?.();
361
386
  this.#markHeard = undefined;
387
+ this.#bodyLayer?.dispose();
388
+ this.#bodyLayer = undefined;
389
+ this.#bodySurfaces = [];
362
390
  this.#earthLayer?.dispose();
363
391
  this.#earthLayer = undefined;
364
392
  this.#earthSurface = null;
@@ -444,8 +472,10 @@ export class WakuseiSpace extends HTMLElement {
444
472
  this.#relabel();
445
473
  if (name === "places" || name === "site-flags" || name === "lang" || name === "surface-names")
446
474
  this.#markSurface();
447
- if (name === "earth-places" || name === "earth-places-look")
475
+ if (name === "earth-places" || name === "earth-places-look" || name === "earth-place-layers")
448
476
  this.#askEarthPlaces();
477
+ if (name === "body-places" || name === "earth-places-look" || name === "earth-place-layers")
478
+ this.#askBodyPlaces();
449
479
  }
450
480
  /**
451
481
  * 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
@@ -530,9 +560,67 @@ export class WakuseiSpace extends HTMLElement {
530
560
  else
531
561
  this.setAttribute("earth-places-look", look);
532
562
  }
533
- /** The markers laid on the Earth now, as the last draw left them: each place's id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`. */
563
+ /**
564
+ * Which layers of places are shown (the attribute `earth-place-layers`, a JSON object of a layer's name to true or false), for `earthPlaces` and `bodyPlaces` alike: a place whose `layer` is named `false` is left out, with its name, and cannot be pressed; any other place,
565
+ * and any layer not named, is shown. The page hands over every place once and switches the layers, instead of building a list for each switch. Setting the property writes the attribute; an empty object takes it away. `earthPlacesShown.hidden` counts the places left out.
566
+ *
567
+ * @example
568
+ * ```ts no-run
569
+ * import "@johnmorrisdotca/wakusei-planets/earth-places";
570
+ * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
571
+ *
572
+ * const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
573
+ * space.earthPlaceLayers = { harbours: false };
574
+ * space.setEarthPlaceLayer("harbours", true);
575
+ * ```
576
+ */
577
+ get earthPlaceLayers() {
578
+ return readEarthPlaceLayers(this.getAttribute("earth-place-layers"));
579
+ }
580
+ set earthPlaceLayers(layers) {
581
+ if (layers === null || Object.keys(layers).length === 0)
582
+ this.removeAttribute("earth-place-layers");
583
+ else
584
+ this.setAttribute("earth-place-layers", JSON.stringify(layers));
585
+ }
586
+ /** Show or hide one layer of places and leave the others as they are: `earthPlaceLayers` with that layer changed. */
587
+ setEarthPlaceLayer(name, shown) {
588
+ this.earthPlaceLayers = { ...this.earthPlaceLayers, [name]: shown };
589
+ }
590
+ /** The markers laid on the Earth now, as the last draw left them: each place's id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`, and `hidden` the places left out because their layer is off. */
534
591
  get earthPlacesShown() {
535
- return { marks: this.#earthLayer?.shown ?? [], omitted: this.#earthOmitted };
592
+ const all = this.#readEarthPlaces();
593
+ return { marks: this.#earthLayer?.shown ?? [], omitted: this.#earthOmitted, hidden: all.length - shownEarthPlaces(all, this.earthPlaceLayers).length };
594
+ }
595
+ /**
596
+ * The places laid on the bodies other than the Earth wherever the camera looks, drawn as the Earth's are (`earthPlaces`): a list of `{ body, id, lon, lat, label, kind, color }`, `body` being `moon`, `mars`, `ceres` and so on (an entry for `earth` is not drawn:
597
+ * the Earth has `earthPlaces`). Each is a beam, a pin or a ring (`earthPlacesLook`) on the ground of its body, hidden on the far side, named beside it when there is room, never over a body's name. A body smaller than 40 CSS pixels of radius carries none, and at most
598
+ * `EARTH_PLACE_MARKS` stand up in all, the reader's `here` places first. `loadPlaceHits` and `hitToBodyPlace` from `@johnmorrisdotca/wakusei-planets/places/search` make the list from saved ids. Like the Earth's, it needs
599
+ * `@johnmorrisdotca/wakusei-planets/earth-places` imported (chikyu-earth's layout, an optional peer). A press that did not move on a drawn name or a foot ring is the event `wakusei-body-place`. Setting it writes the attribute `body-places`.
600
+ *
601
+ * @example
602
+ * ```ts no-run
603
+ * import "@johnmorrisdotca/wakusei-planets/space/element";
604
+ * import "@johnmorrisdotca/wakusei-planets/earth-places";
605
+ *
606
+ * const space = document.querySelector("wakusei-space")!;
607
+ * space.bodyPlaces = [{ body: "moon", id: "moon/apollo-11-lunar-module", lon: 23.4731, lat: 0.6742, label: "Apollo 11 lunar module" }];
608
+ * space.addEventListener("wakusei-body-place", (event) => console.log((event as CustomEvent).detail));
609
+ * ```
610
+ */
611
+ get bodyPlaces() {
612
+ return [...this.#readBodyPlaces()];
613
+ }
614
+ set bodyPlaces(list) {
615
+ if (list === null || list.length === 0)
616
+ this.removeAttribute("body-places");
617
+ else
618
+ this.setAttribute("body-places", JSON.stringify(list));
619
+ }
620
+ /** The markers laid on the other bodies now, as the last draw left them: each place's body, id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`, and `hidden` the places left out because their layer is off. */
621
+ get bodyPlacesShown() {
622
+ const all = this.#readBodyPlaces();
623
+ return { marks: (this.#bodyLayer?.shown ?? []), omitted: this.#bodyOmitted, hidden: all.length - shownEarthPlaces(all, this.earthPlaceLayers).length };
536
624
  }
537
625
  /**
538
626
  * 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
@@ -704,9 +792,8 @@ export class WakuseiSpace extends HTMLElement {
704
792
  return [];
705
793
  if (this.#earthList?.text === text)
706
794
  return this.#earthList.list;
707
- // the places that matter most first: where the reader is, then the rest in the order given
708
- const list = using.read(text);
709
- const ordered = [...list.filter((place) => place.kind === "here"), ...list.filter((place) => place.kind !== "here")];
795
+ // the places that matter most first: where the reader is, then the rest in the order given, then those whose name is low
796
+ const ordered = inMarkOrder(using.read(text));
710
797
  this.#earthList = { text, list: ordered };
711
798
  return ordered;
712
799
  }
@@ -737,10 +824,10 @@ export class WakuseiSpace extends HTMLElement {
737
824
  return clear();
738
825
  if (surface === null || root === null || using === undefined || !this.hasAttribute("earth-places") || !(surface.radiusPx >= EARTH_PLACES_FROM_PX))
739
826
  return clear();
740
- const places = this.#readEarthPlaces();
827
+ const places = shownEarthPlaces(this.#readEarthPlaces(), this.earthPlaceLayers);
741
828
  if (places.length === 0)
742
829
  return clear();
743
- this.#earthLayer ??= createEarthPlaceLayer(root);
830
+ this.#earthLayer ??= createEarthPlaceLayer(root, { press: (mark, event, place) => this.#pressBeam("earth", mark, event, place) });
744
831
  const layer = this.#earthLayer;
745
832
  const facts = BODIES.earth;
746
833
  const scale = [1, 1 - facts.flattening, 1];
@@ -758,6 +845,72 @@ export class WakuseiSpace extends HTMLElement {
758
845
  this.#earthOmitted = laid.shapes.length - marks.shapes.length;
759
846
  layer.set(places, marks, look);
760
847
  }
848
+ /** The bodies the page has places on (the scene lays their surfaces at each draw), none without the layout, or the Earth's, which `earth-places` draws. */
849
+ #bodyWanted() {
850
+ if (!this.hasAttribute("body-places") || earthPlacesLayout() === undefined)
851
+ return [];
852
+ this.#readBodyPlaces();
853
+ return this.#bodyList?.bodies ?? [];
854
+ }
855
+ #readBodyPlaces() {
856
+ const text = this.getAttribute("body-places");
857
+ const using = earthPlacesLayout();
858
+ if (text === null || using === undefined)
859
+ return [];
860
+ if (this.#bodyList?.text === text)
861
+ return this.#bodyList.list;
862
+ const list = readBodyPlacesWith(text, using.read);
863
+ this.#bodyList = { text, list, bodies: bodiesOf(list) };
864
+ return list;
865
+ }
866
+ /** The places, the look or the layout changed: lay them from the last draw's bodies, or ask for one draw to learn them. */
867
+ #askBodyPlaces() {
868
+ if (!this.hasAttribute("body-places")) {
869
+ this.#bodyLayer?.dispose();
870
+ this.#bodyLayer = undefined;
871
+ this.#bodySurfaces = [];
872
+ this.#bodyOmitted = 0;
873
+ return;
874
+ }
875
+ if (this.#bodySurfaces.length > 0)
876
+ this.#layBodyPlaces();
877
+ this.#gate?.request();
878
+ }
879
+ /** Lay the places over the bodies as the last draw left them, or take them away. Draws nothing: it runs inside the draw the view makes anyway. */
880
+ #layBodyPlaces() {
881
+ const root = this.shadowRoot;
882
+ const using = earthPlacesLayout();
883
+ const clear = () => {
884
+ this.#bodyLayer?.clear();
885
+ this.#bodyOmitted = 0;
886
+ };
887
+ if (root === null || using === undefined || !this.hasAttribute("body-places") || this.#bodySurfaces.length === 0)
888
+ return clear();
889
+ const places = shownEarthPlaces(this.#readBodyPlaces(), this.earthPlaceLayers);
890
+ if (places.length === 0)
891
+ return clear();
892
+ this.#bodyLayer ??= createEarthPlaceLayer(root, { press: (mark, event, place) => this.#pressBeam(mark.body ?? "", mark, event, place) });
893
+ const layer = this.#bodyLayer;
894
+ const look = this.earthPlacesLook;
895
+ const laid = layBodyPlaces(places, this.#bodySurfaces, using, look, {
896
+ width: (text) => layer.width(text),
897
+ taken: this.#nameBoxes.map((one) => ({ left: one.x, top: one.y, width: one.width, height: one.height })),
898
+ // a body under another's disc carries none of its places, as the surface marks and the Earth's places
899
+ covered: (id) => this.#covered !== "name" && this.#places?.[id]?.behind !== undefined,
900
+ });
901
+ this.#bodyOmitted = laid.omitted;
902
+ layer.set(laid.places, laid.layout, look);
903
+ }
904
+ /**
905
+ * A press on a beam's name or foot ring: the event `wakusei-place-click`, `{ body, id, kind, layer, label, lon, lat, x, y }` (chikyu-earth's `chikyu-place-click` with the body; `x` and `y` are the press), and `wakusei-body-place`, `{ body, id, kind, x, y }` with the mark's foot
906
+ * (the same for the Earth's places, `body: "earth"`). The page decides what it does; the body under the press is not pressed as well.
907
+ */
908
+ #pressBeam(body, mark, event, place) {
909
+ this.#beamPress = event;
910
+ const box = this.getBoundingClientRect();
911
+ this.dispatchEvent(new CustomEvent("wakusei-place-click", { detail: earthPlaceClick(body, place, event.clientX - box.left, event.clientY - box.top), bubbles: true, composed: true }));
912
+ this.dispatchEvent(new CustomEvent("wakusei-body-place", { detail: { body, id: mark.id, kind: mark.kind, x: mark.x, y: mark.y }, bubbles: true, composed: true }));
913
+ }
761
914
  async #loadMarks(body) {
762
915
  if (this.#markList?.body === body)
763
916
  return this.#markList.list;
@@ -1846,7 +1999,8 @@ export class WakuseiSpace extends HTMLElement {
1846
1999
  if (host !== undefined)
1847
2000
  add(host, 1);
1848
2001
  for (const moon of MOONS_OF[id] ?? [])
1849
- add(moon, 1);
2002
+ if (!SMALL_MOONS.has(moon))
2003
+ add(moon, 1);
1850
2004
  if (this.#arrivedFrom !== null)
1851
2005
  add(this.#arrivedFrom, 2);
1852
2006
  const here = this.#site(id).at;
@@ -2382,7 +2536,7 @@ export class WakuseiSpace extends HTMLElement {
2382
2536
  ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
2383
2537
  travelling: this.#model.travelling === null ? null : { ...this.#model.travelling },
2384
2538
  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 },
2385
- orbits: { drawn: [...this.#model.rings.drawn], miss: { ...this.#model.rings.miss }, hidden: [...this.#model.rings.hidden], faded: [...this.#model.rings.faded] },
2539
+ orbits: { drawn: [...this.#model.rings.drawn], miss: { ...this.#model.rings.miss }, hidden: [...this.#model.rings.hidden], faded: [...this.#model.rings.faded], fade: { ...this.#model.rings.fade } },
2386
2540
  arrows: Object.fromEntries(Object.entries(this.#model.arrows).map(([id, list]) => [id, list.map((a) => ({ position: [...a.position], direction: [...a.direction] }))])),
2387
2541
  arrowPx: this.#model.arrowPx,
2388
2542
  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,
@@ -2563,6 +2717,7 @@ export class WakuseiSpace extends HTMLElement {
2563
2717
  ring.style.transform = `translate(${Math.round(places[id].x)}px,${Math.round(places[id].y)}px)`;
2564
2718
  }
2565
2719
  this.#placeArrows(places);
2720
+ this.#followLine();
2566
2721
  this.#markFar();
2567
2722
  // the names written on the body keep off the names and dots just placed
2568
2723
  this.#markSurface();
@@ -2621,7 +2776,7 @@ export class WakuseiSpace extends HTMLElement {
2621
2776
  this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: this.#moonDetail(id), bubbles: true, composed: true }));
2622
2777
  else if (id !== null && this.#isAsteroid(id))
2623
2778
  this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { id: asteroidIdOf(id), name: this.#nameOf(id), kind: "small-body" }, bubbles: true, composed: true }));
2624
- else if (id !== null && (id === "roadster" || this.#model.craftIds.includes(id)))
2779
+ else if (id !== null && (id === "roadster" || this.#model.craftIds.includes(id) || this.#model.orbiterSet?.ids.includes(id) === true))
2625
2780
  this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { id, name: this.#nameOf(id), kind: "spacecraft" }, bubbles: true, composed: true }));
2626
2781
  else if (id !== null)
2627
2782
  this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { ...this.bodyInfo(id), system: systemOf(id) }, bubbles: true, composed: true }));
@@ -2671,12 +2826,87 @@ export class WakuseiSpace extends HTMLElement {
2671
2826
  return;
2672
2827
  if (this.#hoverBy === "focus" && this.#hovered !== null)
2673
2828
  return;
2674
- this.#hover(this.#pointAt(event), "pointer");
2829
+ const rect = this.getBoundingClientRect();
2830
+ const x = event.clientX - rect.left;
2831
+ const y = event.clientY - rect.top;
2832
+ // a body is under the pointer before a line is; with the names off nothing is lit
2833
+ const body = this.#bodyAt(x, y);
2834
+ const line = body === null && this.#model.labels && this.#model.orbits ? this.#lineAt(x, y, false) : null;
2835
+ this.#hover(body ?? line?.id ?? null, "pointer");
2836
+ this.#lightLine(line, x, y);
2675
2837
  };
2676
2838
  #leave = (event) => {
2677
- if (event.pointerType !== "touch" && this.#hoverBy === "pointer")
2839
+ if (event.pointerType !== "touch" && this.#hoverBy === "pointer") {
2678
2840
  this.#hover(null, "pointer");
2841
+ this.#lightLine(null);
2842
+ }
2679
2843
  };
2844
+ // --- the orbit line under the pointer ----------------------------------------------------------------------------------------------------------------
2845
+ /** The key of the orbit line lit by the pointer, which is the key of its body, or null. */
2846
+ #lineKey = null;
2847
+ #lineNameWidth = 0;
2848
+ /** The orbit line nearest a point of the element, in CSS pixels, within the reach of a pointer or of a finger. Worked out when asked, never at a draw. */
2849
+ #lineAt(x, y, touch) {
2850
+ return nearestLine(this.#model.orbitPaths(), { x, y }, touch ? LINE_TOUCH_PX : LINE_HIT_PX);
2851
+ }
2852
+ /**
2853
+ * Light an orbit line: its path in full strength over the picture, in a layer of the view's own, so that lighting a line draws nothing; and the name of its body beside the pointer. `null` puts both away.
2854
+ * The lit line is kept up with the pictures that follow (`#followLine`).
2855
+ */
2856
+ #lightLine(line, x = 0, y = 0) {
2857
+ const layer = this.#lineLayer;
2858
+ const name = this.#lineName;
2859
+ if (layer === undefined || name === undefined)
2860
+ return;
2861
+ if (line === null) {
2862
+ this.#lineKey = null;
2863
+ if (!layer.hasAttribute("hidden"))
2864
+ layer.setAttribute("hidden", "");
2865
+ if (!name.hidden)
2866
+ name.hidden = true;
2867
+ return;
2868
+ }
2869
+ if (line.id !== this.#lineKey) {
2870
+ this.#lineKey = line.id;
2871
+ layer.removeAttribute("hidden");
2872
+ layer.querySelector("path").setAttribute("stroke", line.colour);
2873
+ name.textContent = this.#nameOf(line.id);
2874
+ name.hidden = false;
2875
+ this.#lineNameWidth = name.offsetWidth;
2876
+ }
2877
+ this.#drawLine(line);
2878
+ // beside the pointer, on the side that stays inside the view
2879
+ const left = x + 14 + this.#lineNameWidth > this.clientWidth ? x - 14 - this.#lineNameWidth : x + 14;
2880
+ name.style.transform = `translate(${Math.round(Math.max(0, left))}px,${Math.round(Math.max(0, y - 20))}px)`;
2881
+ }
2882
+ /** The line's points as the path of the lit layer: a gap where the line is behind the camera. */
2883
+ #drawLine(line) {
2884
+ let d = "";
2885
+ let drawing = false;
2886
+ for (let i = 0; i + 1 < line.xy.length; i += 2) {
2887
+ const x = line.xy[i];
2888
+ if (x !== x) {
2889
+ drawing = false;
2890
+ continue;
2891
+ }
2892
+ d += `${drawing ? "L" : "M"}${x.toFixed(1)} ${line.xy[i + 1].toFixed(1)}`;
2893
+ drawing = true;
2894
+ }
2895
+ this.#lineLayer.querySelector("path").setAttribute("d", d);
2896
+ }
2897
+ /** After a draw: the lit line is where the draw put it, or gone (its body's line is no longer drawn). Only the lit line is worked out. */
2898
+ #followLine() {
2899
+ if (this.#lineKey === null)
2900
+ return;
2901
+ const line = this.#model.orbitPaths(this.#lineKey)[0];
2902
+ if (line === undefined) {
2903
+ if (this.#hovered === this.#lineKey)
2904
+ this.#hover(null, "pointer");
2905
+ this.#lightLine(null);
2906
+ }
2907
+ else
2908
+ this.#drawLine(line);
2909
+ }
2680
2910
  #labelBlur = (event) => {
2681
2911
  const next = event.relatedTarget;
2682
2912
  if (this.#hoverBy === "focus" && !(next && this.#labelBox?.contains(next)))
@@ -2712,6 +2942,12 @@ export class WakuseiSpace extends HTMLElement {
2712
2942
  #sightTimer;
2713
2943
  #tellSight = () => {
2714
2944
  this.#sightTimer = undefined;
2945
+ // a timer can fire a few milliseconds early (CI heard two events 244 ms apart): the wait is made good, so the least time between two events is the one the property promises
2946
+ const early = this.#sightSent + SIGHT_EVENT_MS - performance.now();
2947
+ if (early > 0.5 && this.isConnected) {
2948
+ this.#sightTimer = setTimeout(this.#tellSight, early);
2949
+ return;
2950
+ }
2715
2951
  if (!this.isConnected || !sightChanged(this.#told, this.#sight))
2716
2952
  return;
2717
2953
  this.#told = this.#sight;
@@ -2867,15 +3103,25 @@ export class WakuseiSpace extends HTMLElement {
2867
3103
  this.#hover(null, "pointer");
2868
3104
  };
2869
3105
  #up = (event) => {
3106
+ if (this.#beamPress === event)
3107
+ return;
2870
3108
  if (Math.hypot(event.clientX - this.#downX, event.clientY - this.#downY) > 6)
2871
3109
  return;
2872
3110
  if (!this.#places)
2873
3111
  return;
2874
3112
  const rect = this.getBoundingClientRect();
2875
3113
  // the one hit test the hover uses: a body's disc (14 pixels at least) or, failing that, a drawn name's box, so a press on a name picks its body
2876
- const best = this.#bodyAt(event.clientX - rect.left, event.clientY - rect.top, true);
2877
- if (best)
3114
+ const x = event.clientX - rect.left;
3115
+ const y = event.clientY - rect.top;
3116
+ const best = this.#bodyAt(x, y, true);
3117
+ if (best) {
2878
3118
  this.#press(best);
3119
+ return;
3120
+ }
3121
+ // failing a body, an orbit line is a press on its body; Ctrl or Command goes there at once
3122
+ const line = this.#model.orbits ? this.#lineAt(x, y, event.pointerType === "touch") : null;
3123
+ if (line !== null)
3124
+ this.#press(line.id, event.ctrlKey || event.metaKey);
2879
3125
  };
2880
3126
  #labelClick = (event) => {
2881
3127
  const target = event.target;
@@ -2894,22 +3140,22 @@ export class WakuseiSpace extends HTMLElement {
2894
3140
  };
2895
3141
  /**
2896
3142
  * A press on a body or its name. `wakusei-body-click` tells the page every time. The first press on a body selects it (`wakusei-body-select`, for the page's card); a second press on the body that is selected makes it
2897
- * the middle of the view (`goTo`), unless it already is, so a press never sends the view anywhere else.
3143
+ * the middle of the view (`goTo`), unless it already is, so a press never sends the view anywhere else. With `teleport` (Ctrl or Command held on an orbit line) the press selects and goes there at once, without the glide.
2898
3144
  */
2899
- #press(id) {
3145
+ #press(id, teleport = false) {
2900
3146
  if (this.#catalogueMoon(id) !== undefined) {
2901
3147
  // a moon of the catalogue is no body of the package: the press says which one, in the body event and in an event of its own; the first press selects it, and a second makes its planet the middle of the view
2902
3148
  const detail = this.#moonDetail(id);
2903
3149
  this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail, bubbles: true, composed: true }));
2904
3150
  this.dispatchEvent(new CustomEvent("wakusei-moon-click", { detail, bubbles: true, composed: true }));
2905
- if (this.#selected === id) {
2906
- const host = detail.host;
2907
- if (canCentre(host) && this.#model.focus !== host)
2908
- this.goTo(host);
2909
- return;
3151
+ const first = this.#selected !== id;
3152
+ if (first) {
3153
+ this.#selected = id;
3154
+ this.dispatchEvent(new CustomEvent("wakusei-body-select", { detail, bubbles: true, composed: true }));
2910
3155
  }
2911
- this.#selected = id;
2912
- this.dispatchEvent(new CustomEvent("wakusei-body-select", { detail, bubbles: true, composed: true }));
3156
+ const host = detail.host;
3157
+ if ((!first || teleport) && canCentre(host) && this.#model.focus !== host)
3158
+ this.goTo(host, teleport ? { smooth: false } : {});
2913
3159
  return;
2914
3160
  }
2915
3161
  // the Roadster and the orbiters are no bodies of the package: a press on such a name says so and goes nowhere
@@ -2927,13 +3173,13 @@ export class WakuseiSpace extends HTMLElement {
2927
3173
  return;
2928
3174
  }
2929
3175
  this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
2930
- if (this.#selected === id) {
2931
- if (canCentre(id) && this.#model.focus !== id)
2932
- this.goTo(id);
2933
- return;
3176
+ const first = this.#selected !== id;
3177
+ if (first) {
3178
+ this.#selected = id;
3179
+ this.dispatchEvent(new CustomEvent("wakusei-body-select", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
2934
3180
  }
2935
- this.#selected = id;
2936
- this.dispatchEvent(new CustomEvent("wakusei-body-select", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
3181
+ if ((!first || teleport) && canCentre(id) && this.#model.focus !== id)
3182
+ this.goTo(id, teleport ? { smooth: false } : {});
2937
3183
  }
2938
3184
  #labelFocus = (event) => {
2939
3185
  const id = event.target?.dataset?.["body"];
@@ -0,0 +1,66 @@
1
+ /** Up to this many lines drawn, none is made fainter for the crowd. */
2
+ export declare const FEW_LINES = 12;
3
+ /** The least share of its opacity a line keeps, however many are drawn and however far out the view is. */
4
+ export declare const LEAST_KEEP = 0.15;
5
+ /** The view is "near" at this many radii of the body it looks at, and "far out" at the second: the share of opacity falls between them on a log scale (the Earth and the Moon from a few hundred radii, the inner planets from the Sun a thousand, the whole system from the Earth a million). */
6
+ export declare const NEAR_RADII = 30;
7
+ export declare const FAR_RADII = 30000;
8
+ /** How much of a line's opacity the farthest view takes away. */
9
+ export declare const FAR_LOSS = 0.5;
10
+ /**
11
+ * How far out the view is: 0 within `NEAR_RADII` of the body it looks at, 1 from `FAR_RADII`, and the log of the distance between.
12
+ *
13
+ * @param radii - The camera's distance from the body looked at, in that body's radii.
14
+ * @returns A number from 0 to 1.
15
+ */
16
+ export declare function outnessOf(radii: number): number;
17
+ /**
18
+ * The share of its opacity an orbit line keeps: all of it while few lines are drawn and the view is near, less as more are drawn (by the square root of how many times over `FEW_LINES` they are) and as the view goes out, never under `LEAST_KEEP`.
19
+ *
20
+ * @param input - `crowd`, how many lines are drawn, and `outness`, from `outnessOf`.
21
+ * @returns The share, from `LEAST_KEEP` to 1.
22
+ */
23
+ export declare function lineKeep(input: {
24
+ crowd: number;
25
+ outness: number;
26
+ }): number;
27
+ /**
28
+ * The opacity to draw an orbit line at.
29
+ *
30
+ * @param input - `base`, the opacity the kind of line has when it is alone, and what `lineKeep` takes.
31
+ * @returns The opacity, from `base * LEAST_KEEP` to `base`.
32
+ */
33
+ export declare const lineAlpha: (input: {
34
+ base: number;
35
+ crowd: number;
36
+ outness: number;
37
+ }) => number;
38
+ /** An orbit line as the screen shows it: `xy` is its points as x, y, x, y in CSS pixels, with NaN, NaN where the line is behind the camera (the line is broken there). */
39
+ export interface ScreenLine {
40
+ /** The view's key of the body the line is of (`moon`, `mars`, a catalogue moon's key, a craft's id). */
41
+ id: string;
42
+ /** `#rrggbb`. */
43
+ colour: string;
44
+ xy: ArrayLike<number>;
45
+ }
46
+ /**
47
+ * How many lines have some of their length in the picture: a line counts when one of its segments has the box it lies in over the picture (a long segment that only crosses a corner counts too).
48
+ *
49
+ * @param lines - The lines, in CSS pixels.
50
+ * @param width - The picture's width, in CSS pixels.
51
+ * @param height - The picture's height.
52
+ * @returns The number of lines in the picture.
53
+ */
54
+ export declare function linesInView(lines: readonly ScreenLine[], width: number, height: number): number;
55
+ /**
56
+ * The line nearest a point of the screen, within a distance. Each line is first measured by the box its points lie in (the box grown by the distance), and only a line the point is in the box of has its segments measured.
57
+ *
58
+ * @param lines - The lines on the screen.
59
+ * @param pointer - The point, in CSS pixels.
60
+ * @param tolerance - The farthest a line may be from the point, in CSS pixels.
61
+ * @returns The nearest line, or `null` when none is within the distance.
62
+ */
63
+ export declare function nearestLine(lines: readonly ScreenLine[], pointer: {
64
+ x: number;
65
+ y: number;
66
+ }, tolerance: number): ScreenLine | null;