@johnmorrisdotca/wakusei-planets 0.34.0 → 0.36.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 (215) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/NOTICE.md +64 -0
  3. package/README.md +21 -3
  4. package/dist/approaches.d.ts +276 -0
  5. package/dist/approaches.js +255 -0
  6. package/dist/asteroids.d.ts +397 -0
  7. package/dist/asteroids.js +338 -0
  8. package/dist/comets.d.ts +316 -0
  9. package/dist/comets.js +404 -0
  10. package/dist/craft/bepicolombo.d.ts +1 -0
  11. package/dist/craft/bepicolombo.js +923 -0
  12. package/dist/craft/europaclipper.d.ts +1 -0
  13. package/dist/craft/europaclipper.js +342 -0
  14. package/dist/craft/hayabusa2.d.ts +1 -0
  15. package/dist/craft/hayabusa2.js +73 -0
  16. package/dist/craft/juice.d.ts +1 -0
  17. package/dist/craft/juice.js +40 -0
  18. package/dist/craft/lucy.d.ts +1 -0
  19. package/dist/craft/lucy.js +42 -0
  20. package/dist/craft/osirisapex.d.ts +1 -0
  21. package/dist/craft/osirisapex.js +69 -0
  22. package/dist/craft/psyche.d.ts +1 -0
  23. package/dist/craft/psyche.js +30 -0
  24. package/dist/craft/solarorbiter.d.ts +1 -0
  25. package/dist/craft/solarorbiter.js +94 -0
  26. package/dist/data/approaches.d.ts +17 -0
  27. package/dist/data/approaches.js +4192 -0
  28. package/dist/data/asteroids.d.ts +3 -0
  29. package/dist/data/asteroids.js +107 -0
  30. package/dist/data/comets.d.ts +2 -0
  31. package/dist/data/comets.js +36 -0
  32. package/dist/data/orbiters.d.ts +368 -0
  33. package/dist/data/orbiters.js +370 -0
  34. package/dist/data/places-67p.d.ts +27 -0
  35. package/dist/data/places-67p.js +2 -0
  36. package/dist/data/places-ariel.d.ts +602 -0
  37. package/dist/data/places-ariel.js +27 -0
  38. package/dist/data/places-bennu.d.ts +25 -0
  39. package/dist/data/places-bennu.js +2 -0
  40. package/dist/data/places-callisto.d.ts +3547 -0
  41. package/dist/data/places-callisto.js +155 -0
  42. package/dist/data/places-ceres.d.ts +3436 -0
  43. package/dist/data/places-ceres.js +150 -0
  44. package/dist/data/places-charon.d.ts +349 -0
  45. package/dist/data/places-charon.js +16 -0
  46. package/dist/data/places-dimorphos.d.ts +23 -0
  47. package/dist/data/places-dimorphos.js +2 -0
  48. package/dist/data/places-dione.d.ts +2258 -0
  49. package/dist/data/places-dione.js +99 -0
  50. package/dist/data/places-enceladus.d.ts +2009 -0
  51. package/dist/data/places-enceladus.js +88 -0
  52. package/dist/data/places-eros.d.ts +26 -0
  53. package/dist/data/places-eros.js +2 -0
  54. package/dist/data/places-europa.d.ts +2977 -0
  55. package/dist/data/places-europa.js +130 -0
  56. package/dist/data/places-ganymede.d.ts +4518 -0
  57. package/dist/data/places-ganymede.js +197 -0
  58. package/dist/data/places-iapetus.d.ts +1616 -0
  59. package/dist/data/places-iapetus.js +71 -0
  60. package/dist/data/places-io.d.ts +6012 -0
  61. package/dist/data/places-io.js +262 -0
  62. package/dist/data/places-jupiter.d.ts +46 -0
  63. package/dist/data/places-jupiter.js +3 -0
  64. package/dist/data/places-mars.d.ts +20701 -0
  65. package/dist/data/places-mars.js +942 -0
  66. package/dist/data/places-mercury.d.ts +9256 -0
  67. package/dist/data/places-mercury.js +403 -0
  68. package/dist/data/places-mimas.d.ts +968 -0
  69. package/dist/data/places-mimas.js +43 -0
  70. package/dist/data/places-miranda.d.ts +419 -0
  71. package/dist/data/places-miranda.js +19 -0
  72. package/dist/data/places-moon.d.ts +18849 -0
  73. package/dist/data/places-moon.js +861 -0
  74. package/dist/data/places-oberon.d.ts +235 -0
  75. package/dist/data/places-oberon.js +11 -0
  76. package/dist/data/places-pluto.d.ts +1687 -0
  77. package/dist/data/places-pluto.js +74 -0
  78. package/dist/data/places-rhea.d.ts +3317 -0
  79. package/dist/data/places-rhea.js +145 -0
  80. package/dist/data/places-ryugu.d.ts +87 -0
  81. package/dist/data/places-ryugu.js +5 -0
  82. package/dist/data/places-saturn.d.ts +25 -0
  83. package/dist/data/places-saturn.js +2 -0
  84. package/dist/data/places-tempel-1.d.ts +25 -0
  85. package/dist/data/places-tempel-1.js +2 -0
  86. package/dist/data/places-tethys.d.ts +1222 -0
  87. package/dist/data/places-tethys.js +54 -0
  88. package/dist/data/places-titan.d.ts +7031 -0
  89. package/dist/data/places-titan.js +306 -0
  90. package/dist/data/places-titania.d.ts +418 -0
  91. package/dist/data/places-titania.js +19 -0
  92. package/dist/data/places-triton.d.ts +1457 -0
  93. package/dist/data/places-triton.js +64 -0
  94. package/dist/data/places-umbriel.d.ts +303 -0
  95. package/dist/data/places-umbriel.js +14 -0
  96. package/dist/data/places-venus.d.ts +9290 -0
  97. package/dist/data/places-venus.js +405 -0
  98. package/dist/data/places-vesta.d.ts +2444 -0
  99. package/dist/data/places-vesta.js +107 -0
  100. package/dist/data/roadster.d.ts +8 -0
  101. package/dist/data/roadster.js +686 -0
  102. package/dist/element.js +17 -3
  103. package/dist/orbiter-facts.d.ts +480 -0
  104. package/dist/orbiter-facts.js +189 -0
  105. package/dist/orbiters.d.ts +256 -0
  106. package/dist/orbiters.js +275 -0
  107. package/dist/places/67p.d.ts +13 -0
  108. package/dist/places/67p.js +14 -0
  109. package/dist/places/ariel.d.ts +13 -0
  110. package/dist/places/ariel.js +14 -0
  111. package/dist/places/bennu.d.ts +13 -0
  112. package/dist/places/bennu.js +14 -0
  113. package/dist/places/callisto.d.ts +13 -0
  114. package/dist/places/callisto.js +14 -0
  115. package/dist/places/ceres.d.ts +13 -0
  116. package/dist/places/ceres.js +14 -0
  117. package/dist/places/charon.d.ts +13 -0
  118. package/dist/places/charon.js +14 -0
  119. package/dist/places/dimorphos.d.ts +13 -0
  120. package/dist/places/dimorphos.js +14 -0
  121. package/dist/places/dione.d.ts +13 -0
  122. package/dist/places/dione.js +14 -0
  123. package/dist/places/enceladus.d.ts +13 -0
  124. package/dist/places/enceladus.js +14 -0
  125. package/dist/places/eros.d.ts +13 -0
  126. package/dist/places/eros.js +14 -0
  127. package/dist/places/europa.d.ts +13 -0
  128. package/dist/places/europa.js +14 -0
  129. package/dist/places/ganymede.d.ts +13 -0
  130. package/dist/places/ganymede.js +14 -0
  131. package/dist/places/iapetus.d.ts +13 -0
  132. package/dist/places/iapetus.js +14 -0
  133. package/dist/places/io.d.ts +13 -0
  134. package/dist/places/io.js +14 -0
  135. package/dist/places/jupiter.d.ts +13 -0
  136. package/dist/places/jupiter.js +14 -0
  137. package/dist/places/mars.d.ts +12 -0
  138. package/dist/places/mars.js +13 -0
  139. package/dist/places/mercury.d.ts +13 -0
  140. package/dist/places/mercury.js +14 -0
  141. package/dist/places/mimas.d.ts +13 -0
  142. package/dist/places/mimas.js +14 -0
  143. package/dist/places/miranda.d.ts +13 -0
  144. package/dist/places/miranda.js +14 -0
  145. package/dist/places/moon.d.ts +12 -0
  146. package/dist/places/moon.js +13 -0
  147. package/dist/places/oberon.d.ts +13 -0
  148. package/dist/places/oberon.js +14 -0
  149. package/dist/places/pluto.d.ts +13 -0
  150. package/dist/places/pluto.js +14 -0
  151. package/dist/places/rhea.d.ts +13 -0
  152. package/dist/places/rhea.js +14 -0
  153. package/dist/places/ryugu.d.ts +13 -0
  154. package/dist/places/ryugu.js +14 -0
  155. package/dist/places/saturn.d.ts +13 -0
  156. package/dist/places/saturn.js +14 -0
  157. package/dist/places/tempel-1.d.ts +13 -0
  158. package/dist/places/tempel-1.js +14 -0
  159. package/dist/places/tethys.d.ts +13 -0
  160. package/dist/places/tethys.js +14 -0
  161. package/dist/places/titan.d.ts +13 -0
  162. package/dist/places/titan.js +14 -0
  163. package/dist/places/titania.d.ts +13 -0
  164. package/dist/places/titania.js +14 -0
  165. package/dist/places/triton.d.ts +13 -0
  166. package/dist/places/triton.js +14 -0
  167. package/dist/places/umbriel.d.ts +13 -0
  168. package/dist/places/umbriel.js +14 -0
  169. package/dist/places/venus.d.ts +13 -0
  170. package/dist/places/venus.js +14 -0
  171. package/dist/places/vesta.d.ts +13 -0
  172. package/dist/places/vesta.js +14 -0
  173. package/dist/places.d.ts +354 -0
  174. package/dist/places.js +357 -0
  175. package/dist/plan/element.d.ts +52 -0
  176. package/dist/plan/element.js +258 -0
  177. package/dist/plan/index.d.ts +2 -0
  178. package/dist/plan/index.js +2 -0
  179. package/dist/plan/layout.d.ts +230 -0
  180. package/dist/plan/layout.js +229 -0
  181. package/dist/plan/svg.d.ts +125 -0
  182. package/dist/plan/svg.js +185 -0
  183. package/dist/roadster.d.ts +415 -0
  184. package/dist/roadster.js +496 -0
  185. package/dist/scene/body.js +10 -9
  186. package/dist/scene/painter.d.ts +1 -1
  187. package/dist/scene/painter.js +23 -7
  188. package/dist/scene/textures.d.ts +2 -2
  189. package/dist/space/beside.d.ts +4 -1
  190. package/dist/space/beside.js +47 -6
  191. package/dist/space/covered.d.ts +102 -0
  192. package/dist/space/covered.js +98 -0
  193. package/dist/space/element.d.ts +101 -5
  194. package/dist/space/element.js +474 -30
  195. package/dist/space/frame.d.ts +14 -0
  196. package/dist/space/frame.js +16 -0
  197. package/dist/space/index.d.ts +4 -1
  198. package/dist/space/index.js +4 -1
  199. package/dist/space/regions.d.ts +111 -0
  200. package/dist/space/regions.js +84 -0
  201. package/dist/space/scale.d.ts +2 -1
  202. package/dist/space/scale.js +13 -2
  203. package/dist/space/scene.d.ts +109 -8
  204. package/dist/space/scene.js +313 -37
  205. package/dist/space/travel.d.ts +256 -0
  206. package/dist/space/travel.js +597 -0
  207. package/dist/spacecraft-facts.d.ts +4 -4
  208. package/dist/spacecraft-facts.js +158 -3
  209. package/dist/spacecraft.d.ts +69 -2
  210. package/dist/spacecraft.js +45 -2
  211. package/dist/textures/mimas-1024.webp +0 -0
  212. package/dist/textures/mimas-512.webp +0 -0
  213. package/dist/version.d.ts +1 -1
  214. package/dist/version.js +1 -1
  215. package/package.json +208 -1
@@ -6,6 +6,7 @@ import { arrowCount } from "./arrows.js";
6
6
  import { createGameClock } from "./clock.js";
7
7
  import { bodyKindOf, findBody, hopFrom, hostOf, HOP_ORDER } from "./bodies.js";
8
8
  import { chooseLabels } from "./labels.js";
9
+ import { coverArrows } from "./covered.js";
9
10
  import { createPainter } from "../scene/painter.js";
10
11
  import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
11
12
  import { createDoorHost } from "../door/host.js";
@@ -13,8 +14,12 @@ import { ownCredit } from "../door/own.js";
13
14
  import { setThreeLoader, takeRenderer } from "../scene/shared.js";
14
15
  import { texturePaths, tilesBase } from "../scene/textures.js";
15
16
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
16
- import { moonOffset } from "../scene/orient.js";
17
+ import { moonOffset, orientation } from "../scene/orient.js";
17
18
  import { moonDistance, placeBodies, radiusIn } from "./scale.js";
19
+ import { groundDirection } from "./aim.js";
20
+ import { besideMoon } from "./beside.js";
21
+ import { SUN_REGIONS } from "./regions.js";
22
+ import { travelArrival } from "./travel.js";
18
23
  import { createSpaceItem, FIT_DISTANCE, newSpaceModel, SPACE_BODIES } from "./scene.js";
19
24
  export { setThreeLoader, SPACE_BODIES };
20
25
  /** The words the view says on itself for the scale in use. A page in another language gives its own with `scaleNames`. */
@@ -25,6 +30,20 @@ const SCALE_WORDS = {
25
30
  /** A body whose disc is smaller than this many CSS pixels across its radius is marked with a ring as well as its name. */
26
31
  const RING_BELOW_PX = 4;
27
32
  const readLight = (value) => (value === "lit" ? "lit" : "sun");
33
+ /** The kinds of move between two views, as `transition` names them. */
34
+ const TRAVEL_KINDS = ["turn-travel", "direct", "look-back", "auto", "cut"];
35
+ const readTravel = (value, fallback) => {
36
+ const name = typeof value === "string" ? value.trim().toLowerCase() : "";
37
+ return TRAVEL_KINDS.includes(name) ? name : fallback;
38
+ };
39
+ const readPace = (value, fallback) => {
40
+ const n = typeof value === "number" ? value : typeof value === "string" ? Number.parseFloat(value) : Number.NaN;
41
+ return Number.isFinite(n) && n > 0 ? Math.min(20, Math.max(0.05, n)) : fallback;
42
+ };
43
+ /** 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). */
44
+ const GESTURE_GAP_MS = 300;
45
+ const REGION_IDS = SUN_REGIONS.map((region) => region.id);
46
+ const readRegion = (value) => (typeof value === "string" && REGION_IDS.includes(value.trim().toLowerCase()) ? value.trim().toLowerCase() : undefined);
28
47
  const RAD = Math.PI / 180;
29
48
  const REAL_TIME_TICK_MS = 60_000;
30
49
  /** 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. */
@@ -56,7 +75,7 @@ const readBody = (value) => {
56
75
  * 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.
57
76
  */
58
77
  const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
59
- 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-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>`;
78
+ 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}.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>`;
60
79
  /**
61
80
  * 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`
62
81
  * (`"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`),
@@ -86,7 +105,7 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
86
105
  * ```
87
106
  */
88
107
  export class WakuseiSpace extends HTMLElement {
89
- static observedAttributes = ["center", "time", "speed", "scale", "labels", "orbits", "help", "look", "light", "lang", "data", "arrows", ...NAME_LABEL_ATTRIBUTES];
108
+ static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "orbiters", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "transition", "pace", ...NAME_LABEL_ATTRIBUTES];
90
109
  #model = newSpaceModel();
91
110
  #clock = createGameClock("now", 1);
92
111
  #view;
@@ -133,14 +152,21 @@ export class WakuseiSpace extends HTMLElement {
133
152
  this.#model.time = this.#clock.time;
134
153
  this.#model.mode = this.getAttribute("scale") === "compressed" ? "compressed" : "true";
135
154
  this.#model.labels = this.getAttribute("labels") !== "off";
155
+ this.#labelsAlways = this.hasAttribute("labels-always") && this.getAttribute("labels-always") !== "off";
156
+ this.#covered = this.getAttribute("covered") === "arrow" ? "arrow" : "name";
157
+ this.roadster = this.hasAttribute("roadster") && this.getAttribute("roadster") !== "off";
158
+ this.orbiters = this.hasAttribute("orbiters") && this.getAttribute("orbiters") !== "off";
136
159
  this.#model.orbits = this.getAttribute("orbits") !== "off";
137
160
  this.#model.arrowCount = arrowCount(this.getAttribute("arrows"));
138
161
  this.#model.help = this.hasAttribute("help") && this.getAttribute("help") !== "off";
162
+ this.#model.helpThrough = this.hasAttribute("help-through") && this.getAttribute("help-through") !== "off";
163
+ this.#travel = { kind: readTravel(this.getAttribute("transition"), "turn-travel"), pace: readPace(this.getAttribute("pace"), 1) };
139
164
  this.#model.look = this.getAttribute("look") === "painted" ? "painted" : "realistic";
140
165
  this.#model.light = readLight(this.getAttribute("light"));
141
166
  this.#relabel();
142
167
  this.#door.book.ownOnly(this.getAttribute("data") === "own");
143
168
  this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
169
+ this.#model.speed = this.#clock.speed;
144
170
  if (!this.hasAttribute("role"))
145
171
  this.setAttribute("role", "img");
146
172
  if (!this.hasAttribute("tabindex"))
@@ -152,9 +178,12 @@ export class WakuseiSpace extends HTMLElement {
152
178
  this.#stage = root.getElementById("stage");
153
179
  this.#labelBox = root.getElementById("labels");
154
180
  this.#scaleLine = root.querySelector(".sp-scale");
181
+ this.#regionLine = root.getElementById("region");
155
182
  this.#nameScale();
183
+ this.#showRegion();
156
184
  this.#pool.clear();
157
185
  this.#rings.clear();
186
+ this.#arrows.clear();
158
187
  const nav = navigator;
159
188
  this.#gate = createGate(1000 / frameCap(30, { deviceMemory: nav.deviceMemory, hardwareConcurrency: nav.hardwareConcurrency }), () => this.#view?.invalidate());
160
189
  this.#stage.addEventListener("webglcontextlost", this.#lost, true);
@@ -221,12 +250,26 @@ export class WakuseiSpace extends HTMLElement {
221
250
  this.scale = value === "compressed" ? "compressed" : "true";
222
251
  else if (name === "labels")
223
252
  this.labels = value !== "off";
253
+ else if (name === "labels-always")
254
+ this.labelsAlways = value !== null && value !== "off";
255
+ else if (name === "covered")
256
+ this.covered = value === "arrow" ? "arrow" : "name";
257
+ else if (name === "roadster")
258
+ this.roadster = value !== null && value !== "off";
259
+ else if (name === "orbiters")
260
+ this.orbiters = value !== null && value !== "off";
224
261
  else if (name === "orbits")
225
262
  this.orbits = value !== "off";
226
263
  else if (name === "arrows")
227
264
  this.arrows = arrowCount(value);
228
265
  else if (name === "help")
229
266
  this.help = value !== null && value !== "off";
267
+ else if (name === "help-through")
268
+ this.helpThrough = value !== null && value !== "off";
269
+ else if (name === "transition")
270
+ this.transition = readTravel(value, "turn-travel");
271
+ else if (name === "pace")
272
+ this.pace = readPace(value, 1);
230
273
  else if (name === "look")
231
274
  this.look = value === "painted" ? "painted" : "realistic";
232
275
  else if (name === "light")
@@ -237,6 +280,7 @@ export class WakuseiSpace extends HTMLElement {
237
280
  for (const [id, button] of this.#pool)
238
281
  this.#nameLabel(button, id);
239
282
  this.#nameScale();
283
+ this.#showRegion();
240
284
  this.#relabel();
241
285
  }
242
286
  else if (NAME_LABEL_ATTRIBUTES.includes(name))
@@ -292,6 +336,7 @@ export class WakuseiSpace extends HTMLElement {
292
336
  if (this.isConnected)
293
337
  this.#model.time = this.#clock.time;
294
338
  this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
339
+ this.#model.speed = this.#clock.speed;
295
340
  this.#schedule();
296
341
  this.#gate?.request();
297
342
  if (this.#clock.speed === 0 && was !== 0)
@@ -320,10 +365,114 @@ export class WakuseiSpace extends HTMLElement {
320
365
  set labels(value) {
321
366
  this.#model.labels = value;
322
367
  if (!value)
323
- for (const label of [...this.#pool.values(), ...this.#rings.values()])
368
+ for (const label of [...this.#pool.values(), ...this.#rings.values(), ...this.#arrows.values()])
324
369
  label.hidden = true;
325
370
  this.#gate?.request();
326
371
  }
372
+ #travel = { kind: "turn-travel", pace: 1 };
373
+ #regionLine;
374
+ /** 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. */
375
+ #regionZoomAt = Number.NEGATIVE_INFINITY;
376
+ /**
377
+ * 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
378
+ * 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
379
+ * reader who asked for reduced motion always gets `cut`.
380
+ */
381
+ get transition() {
382
+ return this.#travel.kind;
383
+ }
384
+ set transition(value) {
385
+ this.#travel = { ...this.#travel, kind: readTravel(value, this.#travel.kind) };
386
+ }
387
+ /** 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. */
388
+ get pace() {
389
+ return this.#travel.pace;
390
+ }
391
+ set pace(value) {
392
+ this.#travel = { ...this.#travel, pace: readPace(value, this.#travel.pace) };
393
+ }
394
+ /** 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. */
395
+ get region() {
396
+ return this.#model.region;
397
+ }
398
+ #orbitersLoading = false;
399
+ /**
400
+ * 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
401
+ * 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)
402
+ * are loaded the first time they are shown. `stats.orbiters` says what was drawn and each one's status.
403
+ */
404
+ get orbiters() {
405
+ return this.#model.orbiters;
406
+ }
407
+ set orbiters(value) {
408
+ this.#model.orbiters = value;
409
+ if (value && this.#model.orbiterSet === null && !this.#orbitersLoading) {
410
+ this.#orbitersLoading = true;
411
+ void import("../orbiters.js").then((mod) => {
412
+ this.#model.orbiterSet = {
413
+ ids: mod.ORBITER_IDS,
414
+ centre: (id) => mod.orbiterCentre(id),
415
+ position: (id, ms) => (mod.orbiterElements(id) === undefined ? null : mod.orbiterPosition(id, ms)),
416
+ path: (id, ms, points) => mod.orbiterPath(id, ms, points),
417
+ status: (id, ms) => mod.orbiterStatus(id, ms),
418
+ name: (id) => ({ ...mod.orbiterFacts(id).name }),
419
+ };
420
+ this.#gate?.request();
421
+ }, () => {
422
+ this.#orbitersLoading = false;
423
+ });
424
+ }
425
+ this.#gate?.request();
426
+ }
427
+ #roadsterLoading = false;
428
+ /**
429
+ * 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
430
+ * (`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.
431
+ */
432
+ get roadster() {
433
+ return this.#model.roadster;
434
+ }
435
+ set roadster(value) {
436
+ this.#model.roadster = value;
437
+ if (value && this.#model.roadsterPath === null && !this.#roadsterLoading) {
438
+ this.#roadsterLoading = true;
439
+ // the table comes with the module, so it is fetched only when the car is first shown
440
+ void import("../roadster.js").then((mod) => {
441
+ this.#model.roadsterPath = { positionAu: (ms) => mod.roadsterPositionAu(ms), record: { ...mod.ROADSTER.record }, name: { ...mod.ROADSTER.name } };
442
+ this.#gate?.request();
443
+ }, () => {
444
+ this.#roadsterLoading = false;
445
+ });
446
+ }
447
+ this.#gate?.request();
448
+ }
449
+ #covered = "name";
450
+ #arrows = new Map();
451
+ /**
452
+ * What a body behind another gets (the attribute `covered`): `name` (the default) draws its floating name and ring over the nearer body's disc as always; `arrow` draws instead one small quiet arrow just outside the
453
+ * disc's edge on the side nearest the hidden body, pointing in behind it, with the surest hidden body's name beside it and the others counted (`Uranus +4`); a press on it goes to that body. The arrow goes as the body comes out.
454
+ */
455
+ get covered() {
456
+ return this.#covered;
457
+ }
458
+ set covered(value) {
459
+ this.#covered = value;
460
+ if (this.#places)
461
+ this.#placeLabels(this.#places);
462
+ }
463
+ #labelsAlways = false;
464
+ /**
465
+ * Keep a body's floating name and dot while its name is drawn on its globe (the attribute `labels-always`; off by default). Off, a body that carries its drawn name (`body-label` on, and the body at least 24 CSS pixels in
466
+ * radius) fades its floating name and dot out, and they fade back when it shrinks below that; bodies with no drawn name keep their floating names.
467
+ */
468
+ get labelsAlways() {
469
+ return this.#labelsAlways;
470
+ }
471
+ set labelsAlways(value) {
472
+ this.#labelsAlways = value;
473
+ if (this.#places)
474
+ this.#placeLabels(this.#places);
475
+ }
327
476
  get orbits() {
328
477
  return this.#model.orbits;
329
478
  }
@@ -341,7 +490,7 @@ export class WakuseiSpace extends HTMLElement {
341
490
  }
342
491
  /**
343
492
  * Help mode (the `help` attribute; off by default): on the body looked at, a line along its axis and a curved arrow round it showing which way it spins, by the right-hand rule about the axis it really turns about, so it is
344
- * right for Venus and Uranus, which turn backwards, and for Uranus on its side. It is about learning, so the arrow is drawn over the body.
493
+ * right for Venus and Uranus, which turn backwards, and for Uranus on its side. By default the lines are hidden where the globe covers them (`helpThrough` draws them whole over it).
345
494
  */
346
495
  get help() {
347
496
  return this.#model.help;
@@ -350,6 +499,17 @@ export class WakuseiSpace extends HTMLElement {
350
499
  this.#model.help = value;
351
500
  this.#gate?.request();
352
501
  }
502
+ /**
503
+ * Whether help mode's lines are drawn whole over the globe, as they were (the attribute `help-through`; off by default). Off, they have depth against the body they are on: the axis runs into the near pole and comes out of the
504
+ * far pole only where that end is not behind the globe, and the part of the curved arrow that passes behind the globe is hidden.
505
+ */
506
+ get helpThrough() {
507
+ return this.#model.helpThrough;
508
+ }
509
+ set helpThrough(value) {
510
+ this.#model.helpThrough = value;
511
+ this.#gate?.request();
512
+ }
353
513
  /** How the bodies are drawn: `realistic` (shaded from the body's real colours and features) or `painted` (public-domain surface maps). */
354
514
  get look() {
355
515
  return this.#model.look === "painted" ? "painted" : "realistic";
@@ -375,6 +535,23 @@ export class WakuseiSpace extends HTMLElement {
375
535
  */
376
536
  setView(view, final = true) {
377
537
  const now = this.#model.view;
538
+ if (this.#model.region !== null && view.zoom !== 1) {
539
+ // 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
540
+ // 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)
541
+ const at = performance.now();
542
+ const fresh = at - this.#regionZoomAt > GESTURE_GAP_MS;
543
+ this.#regionZoomAt = at;
544
+ if (fresh && this.#model.transition === null) {
545
+ if (view.zoom < 1)
546
+ this.stepOut();
547
+ else
548
+ this.stepIn();
549
+ }
550
+ else
551
+ this.#announceHop(1);
552
+ this.#hands?.controller.set({ zoom: 1 }, true, "jump");
553
+ return;
554
+ }
378
555
  const [roll, panX, panY] = [view.roll ?? 0, view.panX ?? 0, view.panY ?? 0];
379
556
  if (view.yaw === now.yaw && view.tilt === now.tilt && view.zoom === now.zoom && roll === now.roll && panX === now.panX && panY === now.panY)
380
557
  return;
@@ -412,35 +589,188 @@ export class WakuseiSpace extends HTMLElement {
412
589
  return { current: this.bodyInfo(here), previous: this.bodyInfo(hopFrom(here, -1, canCentre)), next: this.bodyInfo(hopFrom(here, 1, canCentre)) };
413
590
  }
414
591
  /**
415
- * 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
416
- * 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.
592
+ * 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`,
593
+ * 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
594
+ * 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`,
595
+ * `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`
596
+ * tells the page where it went and where the next and previous hops lead. A name in any case, in English or Japanese, works.
417
597
  *
418
- * @param target - A body's name (`"saturn"`, `"Saturn"`, `"土星"`).
419
- * @param options - `smooth` (true by default) and `zoom` (1 by default).
598
+ * @param target - A body's name (`"saturn"`, `"Saturn"`, `"土星"`) or a stage's id.
599
+ * @param options - `smooth` (true by default), `zoom` (1 by default), `transition` and `duration`.
420
600
  * @returns Whether the view can go there.
421
601
  */
422
602
  goTo(target, options = {}) {
603
+ const region = readRegion(target);
604
+ if (region !== undefined) {
605
+ this.#goToRegion(region, options);
606
+ return true;
607
+ }
423
608
  const id = readBody(target);
424
609
  if (!id)
425
610
  return false;
426
611
  const model = this.#model;
427
- const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
428
- const pose = model.pose;
429
- const glide = (options.smooth ?? true) && !reduced && pose.valid && model.ride === null;
612
+ const leaving = this.#leaving();
613
+ const kind = this.#moveKind(options, id);
430
614
  if (model.ride !== null)
431
615
  this.ride(null, { smooth: false });
432
- 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;
616
+ model.transition = this.#startMove(kind, leaving, id, options.duration);
617
+ model.region = null;
618
+ this.#showRegion();
433
619
  this.#selected = id;
434
620
  this.#model.focus = id;
435
621
  const zoom = options.zoom ?? 1;
436
- // 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
622
+ // 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
623
+ const side = model.transition !== null ? this.#faceApproach(id) : null;
437
624
  if (!this.hasAttribute("data-kazoku-bar"))
438
- this.#hands?.controller.set({ zoom }, true, "jump");
625
+ this.#hands?.controller.set(side ? { ...side, zoom } : { zoom }, true, "jump");
439
626
  this.#schedule();
440
627
  this.#gate?.request();
441
- this.#announceHop(zoom);
628
+ this.#announceHop(zoom, side ?? undefined);
442
629
  return true;
443
630
  }
631
+ /** The body the camera is at now: the target of the ride, or the body looked at. */
632
+ #leaving() {
633
+ const ride = this.#model.ride;
634
+ if (ride !== null)
635
+ return typeof ride.target === "string" ? ride.target : ride.around;
636
+ return this.#model.focus;
637
+ }
638
+ /**
639
+ * 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
640
+ * destination is on the screen as the move starts (it stays in view and grows), `turn-travel` when it is not.
641
+ */
642
+ #moveKind(options, destination = null) {
643
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
644
+ if (!(options.smooth ?? true) || reduced || !this.#model.pose.valid)
645
+ return "cut";
646
+ const kind = readTravel(options.transition, this.#travel.kind);
647
+ if (kind !== "auto")
648
+ return kind;
649
+ const place = destination === null ? null : this.placeOf(destination);
650
+ const inView = place !== null && place.x >= 0 && place.y >= 0 && place.x <= this.clientWidth && place.y <= this.clientHeight;
651
+ return inView ? "direct" : "turn-travel";
652
+ }
653
+ /** A move from where the last draw left the camera, or null for a cut. The scene builds its path at the next draw. */
654
+ #startMove(kind, leaving, destination, duration) {
655
+ if (kind === "cut")
656
+ return null;
657
+ const pose = this.#model.pose;
658
+ const leavingReach = this.#model.region !== null && leaving === "sun" ? (this.#model.regionDrawn?.reach ?? 0) : 0;
659
+ return {
660
+ start: performance.now(),
661
+ duration: typeof duration === "number" && Number.isFinite(duration) && duration > 0 ? duration : 0,
662
+ pace: this.#travel.pace,
663
+ kind,
664
+ 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 },
665
+ leaving,
666
+ destination,
667
+ leavingReach,
668
+ input: null,
669
+ plan: null,
670
+ origin: [0, 0, 0],
671
+ };
672
+ }
673
+ /** 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. */
674
+ #site(id) {
675
+ const mode = this.#model.mode;
676
+ const pos = placeBodies(mode, frameAt(this.#model.time));
677
+ if (SPACE_BODIES.includes(id))
678
+ return { at: [...pos[id]], radius: radiusIn(id, mode) };
679
+ const host = (hostOf(id) ?? "earth");
680
+ const real = moonOffset(id, this.#model.time);
681
+ const d = Math.hypot(real[0], real[1], real[2]);
682
+ const k = (d === 0 ? 1 : moonDistance(mode, host, d) / d) * radiusIn(host, mode);
683
+ const centre = pos[host];
684
+ 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)) };
685
+ }
686
+ /**
687
+ * 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
688
+ * back on arrival; null when the camera has not drawn yet.
689
+ */
690
+ #faceApproach(id) {
691
+ const model = this.#model;
692
+ if (!model.pose.valid)
693
+ return null;
694
+ const body = this.#site(id);
695
+ const sun = id === "sun" ? undefined : this.#site("sun").at;
696
+ const wanted = travelArrival({ body: body.at, radius: body.radius, from: model.camera.position, sun, aspect: 16 / 9 });
697
+ const side = [wanted.position[0] - body.at[0], wanted.position[1] - body.at[1], wanted.position[2] - body.at[2]];
698
+ const anchor = model.anchor ?? model.time;
699
+ // 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
700
+ const score = (yaw, tilt) => {
701
+ const aim = groundDirection(model.centre.lon - yaw, Math.max(-90, Math.min(90, model.centre.lat - tilt)), anchor);
702
+ return aim[0] * side[0] + aim[1] * side[1] + aim[2] * side[2];
703
+ };
704
+ let best = { yaw: model.view.yaw, tilt: model.view.tilt, score: -Infinity };
705
+ for (let yaw = -180; yaw < 180; yaw += 6)
706
+ for (let tilt = -85; tilt <= 85; tilt += 5) {
707
+ const n = score(yaw, tilt);
708
+ if (n > best.score)
709
+ best = { yaw, tilt, score: n };
710
+ }
711
+ for (let yaw = best.yaw - 6; yaw <= best.yaw + 6; yaw += 1)
712
+ for (let tilt = Math.max(-89, best.tilt - 5); tilt <= Math.min(89, best.tilt + 5); tilt += 1) {
713
+ const n = score(yaw, tilt);
714
+ if (n > best.score)
715
+ best = { yaw, tilt, score: n };
716
+ }
717
+ return { yaw: best.yaw, tilt: best.tilt };
718
+ }
719
+ /** 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. */
720
+ #goToRegion(region, options) {
721
+ const model = this.#model;
722
+ const leaving = this.#leaving();
723
+ const kind = this.#moveKind(options, "sun");
724
+ if (model.ride !== null)
725
+ this.ride(null, { smooth: false });
726
+ model.transition = this.#startMove(kind, model.region !== null ? "sun" : leaving, "sun", options.duration);
727
+ model.region = region;
728
+ this.#selected = "sun";
729
+ model.focus = "sun";
730
+ // at a stage the controls hold zoom 1: a zoom gesture is taken as a step out or in, not as a zoom
731
+ if (!this.hasAttribute("data-kazoku-bar"))
732
+ this.#hands?.controller.set({ zoom: 1 }, true, "jump");
733
+ this.#showRegion();
734
+ this.#schedule();
735
+ this.#gate?.request();
736
+ this.#announceHop(1);
737
+ this.dispatchEvent(new CustomEvent("wakusei-region", { detail: { region, name: this.#regionName(region) }, bubbles: true, composed: true }));
738
+ }
739
+ /** 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. */
740
+ stepOut(options = {}) {
741
+ const here = this.#model.region;
742
+ const next = here === null ? REGION_IDS[0] : REGION_IDS[REGION_IDS.indexOf(here) + 1];
743
+ if (next === undefined)
744
+ return null;
745
+ this.#goToRegion(next, options);
746
+ return next;
747
+ }
748
+ /** 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. */
749
+ stepIn(options = {}) {
750
+ const here = this.#model.region;
751
+ if (here === null)
752
+ return null;
753
+ const i = REGION_IDS.indexOf(here);
754
+ if (i <= 0) {
755
+ this.goTo("sun", options);
756
+ return "sun";
757
+ }
758
+ this.#goToRegion(REGION_IDS[i - 1], options);
759
+ return REGION_IDS[i - 1];
760
+ }
761
+ #regionName(region) {
762
+ const name = SUN_REGIONS.find((entry) => entry.id === region).name;
763
+ return this.getAttribute("lang") === "ja" ? name.ja : name.en;
764
+ }
765
+ /** The stage's name in the corner of the view, in the element's language, or nothing at a body. */
766
+ #showRegion() {
767
+ const line = this.#regionLine;
768
+ if (!line)
769
+ return;
770
+ const region = this.#model.region;
771
+ line.textContent = region === null ? "" : this.#regionName(region);
772
+ line.hidden = region === null;
773
+ }
444
774
  /** 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. */
445
775
  next(options = {}) {
446
776
  this.goTo(hopFrom(this.#model.focus, 1, canCentre), options);
@@ -462,9 +792,9 @@ export class WakuseiSpace extends HTMLElement {
462
792
  set selected(id) {
463
793
  this.#selected = id;
464
794
  }
465
- /** `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). */
466
- #announceHop(zoom) {
467
- this.dispatchEvent(new CustomEvent("wakusei-hop", { detail: { ...this.hopper, zoom }, bubbles: true, composed: true }));
795
+ /** `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. */
796
+ #announceHop(zoom, side) {
797
+ this.dispatchEvent(new CustomEvent("wakusei-hop", { detail: { ...this.hopper, zoom, ...(side ? { yaw: side.yaw, tilt: side.tilt } : {}) }, bubbles: true, composed: true }));
468
798
  }
469
799
  /** 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`. */
470
800
  get bodyNames() {
@@ -526,7 +856,7 @@ export class WakuseiSpace extends HTMLElement {
526
856
  */
527
857
  ride(target, options = {}) {
528
858
  const model = this.#model;
529
- const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
859
+ const leaving = this.#leaving();
530
860
  const wasRiding = model.ride !== null;
531
861
  if (target === null) {
532
862
  model.ride = null;
@@ -545,12 +875,42 @@ export class WakuseiSpace extends HTMLElement {
545
875
  model.focus = this.#focusBeforeRide;
546
876
  }
547
877
  this.#lostTold = false;
548
- const pose = model.pose;
549
- 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;
878
+ const destination = target !== null && typeof target === "string" ? (readBody(target) ?? null) : target === null ? this.#model.focus : null;
879
+ model.transition = this.#startMove(this.#moveKind(options, destination), leaving, destination, options.duration);
880
+ if (model.transition !== null && model.ride?.view === "beside" && typeof model.ride.target === "string") {
881
+ // 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
882
+ const yaw = this.#besideYaw(model.ride.target);
883
+ if (yaw !== null && !this.hasAttribute("data-kazoku-bar"))
884
+ this.#hands?.controller.set({ yaw, tilt: 0 }, true, "jump");
885
+ }
886
+ model.region = null;
887
+ this.#showRegion();
550
888
  this.#schedule();
551
889
  this.#gate?.request();
552
890
  this.dispatchEvent(new CustomEvent("wakusei-ride", { detail: this.riding }));
553
891
  }
892
+ /** 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. */
893
+ #besideYaw(moon) {
894
+ const model = this.#model;
895
+ if (!model.pose.valid)
896
+ return null;
897
+ const host = (moon === "moon" ? "earth" : (hostOf(moon) ?? "earth"));
898
+ const site = this.#site(moon);
899
+ const planet = this.#site(host);
900
+ const sun = this.#site("sun").at;
901
+ const north = orientation(host, model.time).pole;
902
+ const from = model.camera.position;
903
+ let best = { yaw: 0, near: -Infinity };
904
+ for (let yaw = 0; yaw < 360; yaw += 10) {
905
+ 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 });
906
+ const a = [camera.position[0] - site.at[0], camera.position[1] - site.at[1], camera.position[2] - site.at[2]];
907
+ const b = [from[0] - site.at[0], from[1] - site.at[1], from[2] - site.at[2]];
908
+ const near = (a[0] * b[0] + a[1] * b[1] + a[2] * b[2]) / (Math.hypot(...a) * Math.hypot(...b) || 1);
909
+ if (near > best.near)
910
+ best = { yaw, near };
911
+ }
912
+ return best.yaw;
913
+ }
554
914
  #resolveRide(target, options) {
555
915
  const look = options.look ?? "down";
556
916
  const distanceKm = Math.max(100, options.distanceKm ?? 3000);
@@ -658,16 +1018,20 @@ export class WakuseiSpace extends HTMLElement {
658
1018
  assets: { entries: stats?.assets.entries ?? 0, refs: stats?.assets.refs ?? 0 },
659
1019
  time: this.time,
660
1020
  lookups: this.#model.lookups,
661
- camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov },
1021
+ camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov, up: [...this.#model.camera.up], forward: [...this.#model.camera.forward] },
662
1022
  bodies: { look: this.#model.look, painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held },
663
1023
  tiles: { ...this.#model.tiles },
664
1024
  door: { points: this.#model.door.points, sources: this.#door.book.stats() },
665
1025
  ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
1026
+ travelling: this.#model.travelling === null ? null : { ...this.#model.travelling },
1027
+ 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 },
666
1028
  orbits: { drawn: [...this.#model.rings.drawn], miss: { ...this.#model.rings.miss }, hidden: [...this.#model.rings.hidden] },
667
1029
  arrows: Object.fromEntries(Object.entries(this.#model.arrows).map(([id, list]) => [id, list.map((a) => ({ position: [...a.position], direction: [...a.direction] }))])),
668
1030
  arrowPx: this.#model.arrowPx,
669
1031
  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,
670
1032
  bodyLabels: { count: this.#model.labelsDrawn.count, focus: this.#model.labelsDrawn.focus === null ? null : { ...this.#model.labelsDrawn.focus } },
1033
+ orbiters: { count: this.#model.orbitersDrawn.count, status: { ...this.#model.orbitersDrawn.status } },
1034
+ roadster: { shown: this.#model.roadsterDrawn.shown, position: this.#model.roadsterDrawn.position === null ? null : [...this.#model.roadsterDrawn.position], radiusPx: this.#model.roadsterDrawn.radiusPx },
671
1035
  };
672
1036
  }
673
1037
  // --- the game clock ----------------------------------------------------------------------------------------------------------------------------
@@ -712,7 +1076,12 @@ export class WakuseiSpace extends HTMLElement {
712
1076
  };
713
1077
  // --- labels --------------------------------------------------------------------------------------------------------------------------------------
714
1078
  #nameOf(id) {
715
- return this.#names[id] ?? BODIES[id].name[this.getAttribute("lang") === "ja" ? "ja" : "en"];
1079
+ const lang = this.getAttribute("lang") === "ja" ? "ja" : "en";
1080
+ if (id === "roadster")
1081
+ return this.#names[id] ?? this.#model.roadsterPath?.name[lang] ?? "Starman";
1082
+ if (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))
1083
+ return this.#names[id] ?? this.#model.orbiterSet.name(id)[lang];
1084
+ return this.#names[id] ?? BODIES[id].name[lang];
716
1085
  }
717
1086
  #placeLabels(places) {
718
1087
  this.#places = places;
@@ -750,8 +1119,14 @@ export class WakuseiSpace extends HTMLElement {
750
1119
  continue;
751
1120
  const x = Math.round(at.x + Math.max(4, Math.min(at.r, 40)));
752
1121
  const y = Math.round(at.y - 8);
753
- spots.set(id, { x, y, small: at.r < RING_BELOW_PX });
754
- wanted.push({ id, x, y, width: this.#widthOf(label), height: 16, rank: this.#rank(id), size: at.r });
1122
+ // a body that carries its drawn name gives its floating name up (it fades, and leaves its place to the others) unless the page keeps both; a body behind another gives it up for the arrow
1123
+ const carried = at.named === true && !this.#labelsAlways;
1124
+ const covered = at.behind !== undefined && this.#covered === "arrow";
1125
+ if (covered)
1126
+ continue;
1127
+ spots.set(id, { x, y, small: at.r < RING_BELOW_PX, carried });
1128
+ if (!carried)
1129
+ wanted.push({ id, x, y, width: this.#widthOf(label), height: 16, rank: this.#rank(id), size: at.r });
755
1130
  }
756
1131
  // no two names overlap: a moon gives way to its planet and a planet to the Sun
757
1132
  const shown = chooseLabels(wanted);
@@ -761,15 +1136,28 @@ export class WakuseiSpace extends HTMLElement {
761
1136
  if (!label || !ring)
762
1137
  continue;
763
1138
  const spot = spots.get(id);
764
- if (!spot || !shown.has(id)) {
1139
+ if (!spot || (!spot.carried && !shown.has(id))) {
765
1140
  if (!label.hidden)
766
1141
  label.hidden = true;
767
1142
  if (!ring.hidden)
768
1143
  ring.hidden = true;
1144
+ // a hidden name forgets its fade, so that when it comes back it fades in rather than popping
1145
+ if (label.hasAttribute("data-carried")) {
1146
+ label.removeAttribute("data-carried");
1147
+ ring.removeAttribute("data-carried");
1148
+ label.setAttribute("aria-hidden", "false");
1149
+ label.tabIndex = 0;
1150
+ }
769
1151
  continue;
770
1152
  }
771
1153
  if (label.hidden)
772
1154
  label.hidden = false;
1155
+ if (label.hasAttribute("data-carried") !== spot.carried) {
1156
+ label.toggleAttribute("data-carried", spot.carried);
1157
+ ring.toggleAttribute("data-carried", spot.carried);
1158
+ label.setAttribute("aria-hidden", String(spot.carried));
1159
+ label.tabIndex = spot.carried ? -1 : 0;
1160
+ }
773
1161
  label.style.transform = `translate(${spot.x}px,${spot.y}px)`;
774
1162
  // a body too small to see is marked: a ring round the place it is, as well as its name
775
1163
  if (ring.hidden === spot.small)
@@ -777,6 +1165,43 @@ export class WakuseiSpace extends HTMLElement {
777
1165
  if (spot.small)
778
1166
  ring.style.transform = `translate(${Math.round(places[id].x)}px,${Math.round(places[id].y)}px)`;
779
1167
  }
1168
+ this.#placeArrows(places);
1169
+ }
1170
+ /** 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. */
1171
+ #placeArrows(places) {
1172
+ const box = this.#labelBox;
1173
+ if (!box)
1174
+ return;
1175
+ const arrows = this.#covered === "arrow" && this.#model.labels ? coverArrows(places, (id) => this.#rank(id)) : [];
1176
+ const live = new Set();
1177
+ for (const arrow of arrows) {
1178
+ live.add(arrow.cover);
1179
+ let el = this.#arrows.get(arrow.cover);
1180
+ if (!el) {
1181
+ const button = box.ownerDocument.createElement("button");
1182
+ button.type = "button";
1183
+ el = button;
1184
+ el.className = "sp-arrow";
1185
+ el.dataset["cover"] = arrow.cover;
1186
+ box.append(el);
1187
+ this.#arrows.set(arrow.cover, el);
1188
+ }
1189
+ const text = arrow.bodies.length > 1 ? `${this.#nameOf(arrow.lead)} +${arrow.bodies.length - 1}` : this.#nameOf(arrow.lead);
1190
+ if (el.dataset["body"] !== arrow.lead || el.textContent !== text) {
1191
+ el.dataset["body"] = arrow.lead;
1192
+ el.textContent = text;
1193
+ el.setAttribute("aria-label", `${arrow.bodies.map((id) => this.#nameOf(id)).join(", ")}: ${this.#nameOf(arrow.cover)} ${this.getAttribute("lang") === "ja" ? "の後ろ" : "is in front"}. ${this.#hint}`);
1194
+ }
1195
+ // the tip sits at the arrow's place and points into the disc; the name hangs off the far side, to the right of the tip for an arrow on the right half of the disc and to the left for one on the left
1196
+ const onLeft = Math.cos((arrow.angle * Math.PI) / 180) > 0;
1197
+ el.style.setProperty("--turn", `${Math.round(arrow.angle)}deg`);
1198
+ el.style.transform = `translate(${Math.round(arrow.x)}px,${Math.round(arrow.y - 8)}px)${onLeft ? " translateX(-100%)" : ""}`;
1199
+ if (el.hidden)
1200
+ el.hidden = false;
1201
+ }
1202
+ for (const [cover, el] of this.#arrows)
1203
+ if (!live.has(cover) && !el.hidden)
1204
+ el.hidden = true;
780
1205
  }
781
1206
  /** How sure a body's name is of its place: the body looked at first, then the Sun, the planets, the dwarf planets and minor bodies, and the moons. */
782
1207
  #rank(id) {
@@ -784,6 +1209,10 @@ export class WakuseiSpace extends HTMLElement {
784
1209
  return 0;
785
1210
  if (id === "sun")
786
1211
  return 1;
1212
+ if (id === "roadster")
1213
+ return 3;
1214
+ if (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))
1215
+ return 5;
787
1216
  const kind = bodyKindOf(id);
788
1217
  return kind === "moon" ? 4 : kind === "planet" || kind === "star" ? 2 : 3;
789
1218
  }
@@ -871,15 +1300,30 @@ export class WakuseiSpace extends HTMLElement {
871
1300
  this.#press(best);
872
1301
  };
873
1302
  #labelClick = (event) => {
874
- const id = event.target?.dataset?.["body"];
875
- if (id)
876
- this.#press(id);
1303
+ const target = event.target;
1304
+ const id = target?.dataset?.["body"];
1305
+ if (!id)
1306
+ return;
1307
+ // a press on a quiet arrow (a body behind another) goes to that body at once; a press on a name selects it first, as always
1308
+ if (target?.dataset?.["cover"] !== undefined) {
1309
+ if (canCentre(id))
1310
+ this.goTo(id);
1311
+ else
1312
+ this.#press(id);
1313
+ return;
1314
+ }
1315
+ this.#press(id);
877
1316
  };
878
1317
  /**
879
1318
  * 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
880
1319
  * the middle of the view (`goTo`), unless it already is, so a press never sends the view anywhere else.
881
1320
  */
882
1321
  #press(id) {
1322
+ // the Roadster and the orbiters are no bodies of the package: a press on such a name says so and goes nowhere
1323
+ if (id === "roadster" || (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))) {
1324
+ this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: { id, name: this.#nameOf(id), kind: "spacecraft" }, bubbles: true, composed: true }));
1325
+ return;
1326
+ }
883
1327
  this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
884
1328
  if (this.#selected === id) {
885
1329
  if (canCentre(id) && this.#model.focus !== id)