@johnmorrisdotca/wakusei-planets 0.37.2 → 0.39.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 (46) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/NOTICE.md +14 -3
  3. package/README.md +6 -4
  4. package/dist/belts/data.d.ts +2 -0
  5. package/dist/belts/data.js +12 -0
  6. package/dist/belts/index.d.ts +270 -0
  7. package/dist/belts/index.js +308 -0
  8. package/dist/belts/totals.d.ts +43 -0
  9. package/dist/belts/totals.js +25 -0
  10. package/dist/data/orbiters.d.ts +221 -199
  11. package/dist/data/orbiters.js +288 -200
  12. package/dist/data-door.d.ts +2 -0
  13. package/dist/data-door.js +4 -2
  14. package/dist/door/own.js +4 -2
  15. package/dist/door/points.d.ts +14 -5
  16. package/dist/door/points.js +78 -27
  17. package/dist/earth-places.d.ts +40 -0
  18. package/dist/earth-places.js +47 -0
  19. package/dist/embed.d.ts +4 -1
  20. package/dist/embed.js +21 -10
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.js +1 -0
  23. package/dist/orbiter-facts.d.ts +61 -4
  24. package/dist/orbiter-facts.js +17 -3
  25. package/dist/orbiters.d.ts +122 -2
  26. package/dist/orbiters.js +205 -3
  27. package/dist/picture-credits.d.ts +78 -0
  28. package/dist/picture-credits.js +120 -0
  29. package/dist/place-marks.d.ts +76 -0
  30. package/dist/place-marks.js +66 -0
  31. package/dist/places.d.ts +1 -1
  32. package/dist/places.js +1 -1
  33. package/dist/scene/earth-places.d.ts +190 -0
  34. package/dist/scene/earth-places.js +190 -0
  35. package/dist/scene/painter.d.ts +11 -0
  36. package/dist/scene/painter.js +30 -2
  37. package/dist/scene/textures.d.ts +2 -2
  38. package/dist/space/element.d.ts +74 -3
  39. package/dist/space/element.js +293 -8
  40. package/dist/space/ride.d.ts +4 -4
  41. package/dist/space/ride.js +10 -3
  42. package/dist/space/scene.d.ts +44 -2
  43. package/dist/space/scene.js +139 -11
  44. package/dist/version.d.ts +1 -1
  45. package/dist/version.js +1 -1
  46. package/package.json +15 -2
@@ -12,6 +12,7 @@ import { createPainter } from "../scene/painter.js";
12
12
  import { NAME_LABEL_ATTRIBUTES, readNameLabel } from "../scene/name-label.js";
13
13
  import { createDoorHost } from "../door/host.js";
14
14
  import { ownCredit } from "../door/own.js";
15
+ import { BELT_IDS, BELTS, beltFlight, beltNote, beltsSource, beltSpacing, loadBeltBodies, OORT } from "../belts/index.js";
15
16
  import { setThreeLoader, takeRenderer } from "../scene/shared.js";
16
17
  import { texturePaths, tilesBase } from "../scene/textures.js";
17
18
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt, SPACE_DWARFS, SPACE_MINORS, SPACE_PLANETS } from "./frame.js";
@@ -22,11 +23,13 @@ import { besideMoon } from "./beside.js";
22
23
  import { SUN_REGIONS } from "./regions.js";
23
24
  import { travelArrival } from "./travel.js";
24
25
  import { findPlace, PLACE_BODIES } from "../places.js";
25
- import { placeMarks, readPlaceLayers } from "../place-marks.js";
26
+ import { placeMarks, pointUnder, readPlaceLayers, spotView } from "../place-marks.js";
26
27
  import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
28
+ import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
27
29
  import { cross, dot } from "../vec.js";
28
30
  import { createSpaceItem, FIT_DISTANCE, newSpaceModel, SPACE_BODIES } from "./scene.js";
29
31
  export { setPlacesLoader } from "../scene/place-layer.js";
32
+ export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "../scene/earth-places.js";
30
33
  export { setThreeLoader, SPACE_BODIES };
31
34
  /** The words the view says on itself for the scale in use. A page in another language gives its own with `scaleNames`. */
32
35
  const SCALE_WORDS = {
@@ -35,6 +38,17 @@ const SCALE_WORDS = {
35
38
  };
36
39
  /** A body whose disc is smaller than this many CSS pixels across its radius is marked with a ring as well as its name. */
37
40
  const RING_BELOW_PX = 4;
41
+ /** The id of the package's own source of the belts: it is in every view, but is not one of `sources`. */
42
+ const BELTS_SOURCE_ID = "wakusei-belts";
43
+ /** The belts the attribute `belts` names: all of them where it is left out or says `all`, none for `off`, else a list of names separated by commas or spaces. */
44
+ const readBelts = (value) => {
45
+ if (value === null || value.trim() === "" || value.trim() === "all")
46
+ return BELT_IDS;
47
+ if (value.trim() === "off" || value.trim() === "none")
48
+ return [];
49
+ const named = value.split(/[\s,]+/).filter((id) => BELT_IDS.includes(id));
50
+ return BELT_IDS.filter((id) => named.includes(id));
51
+ };
38
52
  const readLight = (value) => (value === "lit" ? "lit" : "sun");
39
53
  /** The kinds of move between two views, as `transition` names them. */
40
54
  const TRAVEL_KINDS = ["turn-travel", "direct", "look-back", "auto", "cut"];
@@ -90,7 +104,8 @@ const readBody = (value) => {
90
104
  * 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.
91
105
  */
92
106
  const CARRIED_LIMITS = { zoomMin: 1e-6, zoomMax: 3.6, tiltMax: 90 };
93
- const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}</style><div id="stage"></div><div id="labels"></div><p class="sp-scale" part="scale" role="status"></p><p class="sp-region" id="region" part="region" role="status" hidden></p>`;
107
+ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden}:host([immersive]){aspect-ratio:auto;width:100%;height:100%;touch-action:none!important;user-select:none;-webkit-user-select:none;-webkit-tap-highlight-color:transparent}#stage,#labels{position:absolute;inset:0}#labels{pointer-events:none;overflow:hidden}.sp-label{position:absolute;left:0;top:0;margin:0;padding:0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-label:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label::before{content:"";display:inline-block;width:5px;height:5px;margin:0 5px 1px -2px;border-radius:50%;background:#fff}.sp-label[hidden]{display:none}.sp-arrow{position:absolute;left:0;top:0;margin:0;padding:0 4px 0 0;border:0;background:none;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.8;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:auto;cursor:pointer}.sp-arrow::before{content:"";display:inline-block;width:0;height:0;margin:0 5px 1px 0;border:5px solid transparent;border-left:7px solid #fff;transform:rotate(var(--turn,0deg));transform-origin:30% 50%}.sp-arrow[hidden]{display:none}.sp-arrow:focus-visible{outline:2px solid #6cd0ff;outline-offset:2px;border-radius:4px}.sp-label[data-far]:not([data-carried]),.sp-ring[data-far]:not([data-carried]){opacity:var(--wakusei-far-opacity,.5)}.sp-arrow[data-far]{opacity:calc(.8*var(--wakusei-far-opacity,.5))}.sp-label,.sp-ring,.sp-arrow{transition:opacity .35s ease}.sp-label[data-carried],.sp-ring[data-carried]{opacity:0;pointer-events:none}@media (prefers-reduced-motion:reduce){.sp-label,.sp-ring,.sp-arrow{transition:none}}.sp-ring{position:absolute;left:0;top:0;width:16px;height:16px;margin:-8px 0 0 -8px;box-sizing:border-box;border:1.5px solid rgba(255,255,255,.85);border-radius:50%;box-shadow:0 0 3px #000;pointer-events:none;will-change:transform}.sp-ring[hidden]{display:none}.sp-scale{position:absolute;left:10px;top:8px;margin:0;padding:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;opacity:.9;text-shadow:0 0 3px #000,0 0 3px #000;pointer-events:none}.sp-region{position:absolute;left:10px;bottom:8px;margin:0;padding:0;font:600 15px/20px system-ui,-apple-system,sans-serif;color:#fff;opacity:.95;text-shadow:0 0 4px #000,0 0 4px #000;pointer-events:none;transition:opacity .35s}.sp-region[hidden]{display:block;opacity:0}@media (prefers-reduced-motion:reduce){.sp-region{transition:none}}.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}</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>`;
108
+ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value : "all");
94
109
  /**
95
110
  * 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`
96
111
  * (`"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`),
@@ -124,7 +139,7 @@ const STYLE = `<style>:host{display:block;aspect-ratio:1/1;position:relative;ove
124
139
  * ```
125
140
  */
126
141
  export class WakuseiSpace extends HTMLElement {
127
- static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "orbiters", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "places", "all-moons", "far-opacity", "transition", "pace", ...NAME_LABEL_ATTRIBUTES];
142
+ static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "places", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "belts", ...NAME_LABEL_ATTRIBUTES];
128
143
  #model = newSpaceModel();
129
144
  #allMoons = false;
130
145
  #catalogue;
@@ -144,6 +159,11 @@ export class WakuseiSpace extends HTMLElement {
144
159
  #scaleNames = {};
145
160
  #rings = new Map();
146
161
  #scaleLine;
162
+ #noteLine;
163
+ #oortLabel;
164
+ /** 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). */
165
+ #flight = null;
166
+ #spacing = new Map();
147
167
  #hint = "choose to look at it";
148
168
  #painter;
149
169
  #door = createDoorHost(this, {
@@ -168,6 +188,11 @@ export class WakuseiSpace extends HTMLElement {
168
188
  #markLoading;
169
189
  #markHeard;
170
190
  #placeGlide = 0;
191
+ #earthLayer;
192
+ #earthSurface = null;
193
+ #earthHeard;
194
+ #earthList;
195
+ #earthOmitted = 0;
171
196
  #surface = null;
172
197
  /** 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. */
173
198
  get controller() {
@@ -183,6 +208,9 @@ export class WakuseiSpace extends HTMLElement {
183
208
  this.#covered = this.getAttribute("covered") === "arrow" ? "arrow" : "name";
184
209
  this.roadster = this.hasAttribute("roadster") && this.getAttribute("roadster") !== "off";
185
210
  this.orbiters = this.hasAttribute("orbiters") && this.getAttribute("orbiters") !== "off";
211
+ this.#model.orbiterChosen = this.getAttribute("orbiter") || null;
212
+ this.#model.orbiterLines = orbiterLines(this.getAttribute("orbiter-lines"));
213
+ this.#model.orbiterTrack = this.hasAttribute("orbiter-track") && this.getAttribute("orbiter-track") !== "off";
186
214
  this.#model.orbits = this.getAttribute("orbits") !== "off";
187
215
  this.#model.arrowCount = arrowCount(this.getAttribute("arrows"));
188
216
  this.#model.help = this.hasAttribute("help") && this.getAttribute("help") !== "off";
@@ -192,6 +220,10 @@ export class WakuseiSpace extends HTMLElement {
192
220
  this.#model.light = readLight(this.getAttribute("light"));
193
221
  this.#relabel();
194
222
  this.#door.book.ownOnly(this.getAttribute("data") === "own");
223
+ this.#model.belts = readBelts(this.getAttribute("belts"));
224
+ if (this.#door.book.get(BELTS_SOURCE_ID) === undefined)
225
+ this.#door.book.addSource(beltsSource());
226
+ this.#door.book.enableSource(BELTS_SOURCE_ID, this.#model.belts.length > 0);
195
227
  this.#model.stepMs = Math.max(1000, Math.abs(this.#clock.speed) * 1000);
196
228
  this.#model.speed = this.#clock.speed;
197
229
  if (!this.hasAttribute("role"))
@@ -206,6 +238,8 @@ export class WakuseiSpace extends HTMLElement {
206
238
  this.#labelBox = root.getElementById("labels");
207
239
  this.#scaleLine = root.querySelector(".sp-scale");
208
240
  this.#regionLine = root.getElementById("region");
241
+ this.#noteLine = root.querySelector(".sp-note");
242
+ this.#oortLabel = root.querySelector(".sp-oort");
209
243
  this.#nameScale();
210
244
  this.#showRegion();
211
245
  this.#pool.clear();
@@ -228,6 +262,7 @@ export class WakuseiSpace extends HTMLElement {
228
262
  advance: () => this.#advance(),
229
263
  onLabels: (places) => {
230
264
  this.#placeLabels(places);
265
+ this.#placeOort();
231
266
  this.#door.announce();
232
267
  },
233
268
  onSight: (bodies, frame) => this.#see(bodies, frame),
@@ -236,6 +271,11 @@ export class WakuseiSpace extends HTMLElement {
236
271
  this.#surface = surface;
237
272
  this.#markSurface();
238
273
  },
274
+ wantEarth: () => this.hasAttribute("earth-places"),
275
+ onEarth: (surface) => {
276
+ this.#earthSurface = surface;
277
+ this.#layEarthPlaces();
278
+ },
239
279
  onMoving: () => this.#gate?.request(),
240
280
  onRideLost: () => this.#rideLost(),
241
281
  onPainterError: (error) => this.dispatchEvent(new CustomEvent("wakusei-bodies-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
@@ -261,6 +301,10 @@ export class WakuseiSpace extends HTMLElement {
261
301
  this.#markList = undefined;
262
302
  this.#markSurface();
263
303
  });
304
+ this.#earthHeard = onEarthPlacesLayout(() => {
305
+ this.#earthList = undefined;
306
+ this.#askEarthPlaces();
307
+ });
264
308
  this.#labelBox.addEventListener("click", this.#labelClick);
265
309
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
266
310
  this.#labelBox.addEventListener("focusout", this.#labelBlur);
@@ -291,6 +335,11 @@ export class WakuseiSpace extends HTMLElement {
291
335
  this.#markLayer = undefined;
292
336
  this.#markHeard?.();
293
337
  this.#markHeard = undefined;
338
+ this.#earthLayer?.dispose();
339
+ this.#earthLayer = undefined;
340
+ this.#earthSurface = null;
341
+ this.#earthHeard?.();
342
+ this.#earthHeard = undefined;
294
343
  }
295
344
  attributeChangedCallback(name, _old, value) {
296
345
  if (name === "center")
@@ -311,6 +360,12 @@ export class WakuseiSpace extends HTMLElement {
311
360
  this.roadster = value !== null && value !== "off";
312
361
  else if (name === "orbiters")
313
362
  this.orbiters = value !== null && value !== "off";
363
+ else if (name === "orbiter")
364
+ this.orbiter = value || null;
365
+ else if (name === "orbiter-lines")
366
+ this.orbiterLines = orbiterLines(value);
367
+ else if (name === "orbiter-track")
368
+ this.orbiterTrack = value !== null && value !== "off";
314
369
  else if (name === "orbits")
315
370
  this.orbits = value !== "off";
316
371
  else if (name === "all-moons")
@@ -333,17 +388,22 @@ export class WakuseiSpace extends HTMLElement {
333
388
  this.light = readLight(value);
334
389
  else if (name === "data")
335
390
  this.#door.book.ownOnly(value === "own");
391
+ else if (name === "belts")
392
+ this.belts = readBelts(value);
336
393
  else if (name === "lang") {
337
394
  for (const [id, button] of this.#pool)
338
395
  this.#nameLabel(button, id);
339
396
  this.#nameScale();
340
397
  this.#showRegion();
398
+ this.#showNote();
341
399
  this.#relabel();
342
400
  }
343
401
  else if (NAME_LABEL_ATTRIBUTES.includes(name))
344
402
  this.#relabel();
345
403
  if (name === "places" || name === "lang")
346
404
  this.#markSurface();
405
+ if (name === "earth-places" || name === "earth-places-look")
406
+ this.#askEarthPlaces();
347
407
  }
348
408
  /**
349
409
  * 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
@@ -362,6 +422,44 @@ export class WakuseiSpace extends HTMLElement {
362
422
  get placesShown() {
363
423
  return this.#markLayer?.shown ?? [];
364
424
  }
425
+ /**
426
+ * The reader's own place and the places they keep, drawn on the Earth wherever the camera looks: a list of `{ id, lon, lat, label, kind, color }` (`kind` is `here` or `favourite`), as JSON in the attribute `earth-places`.
427
+ * Each is a marker standing out of the ground that turns with the Earth, is hidden on the far side, fades at the edge and keeps its size in pixels; a name shows beside it when there is room, never over another name. Setting the property
428
+ * writes the attribute, and an empty list takes it away. It reads as the list chikyu-earth cleaned (a place with a longitude or latitude out of range is left out, at most 5,000). It draws nothing, and reads as empty, until the page has
429
+ * imported `@johnmorrisdotca/wakusei-planets/earth-places`, which brings chikyu-earth's layout (an optional peer).
430
+ *
431
+ * @example
432
+ * ```ts no-run
433
+ * import "@johnmorrisdotca/wakusei-planets/earth-places";
434
+ * import type { WakuseiSpace } from "@johnmorrisdotca/wakusei-planets/space/element";
435
+ *
436
+ * const space = document.querySelector<WakuseiSpace>("wakusei-space")!;
437
+ * space.earthPlaces = [{ id: "me", lon: -79.4, lat: 43.7, label: "You are here", kind: "here" }];
438
+ * ```
439
+ */
440
+ get earthPlaces() {
441
+ return [...this.#readEarthPlaces()];
442
+ }
443
+ set earthPlaces(list) {
444
+ if (list === null || list.length === 0)
445
+ this.removeAttribute("earth-places");
446
+ else
447
+ this.setAttribute("earth-places", JSON.stringify(list));
448
+ }
449
+ /** How the places on the Earth are drawn (the attribute `earth-places-look`): `beam` (the default), `pin` or `ring`. Setting it writes the attribute. */
450
+ get earthPlacesLook() {
451
+ return readEarthPlaceLook(this.getAttribute("earth-places-look"));
452
+ }
453
+ set earthPlacesLook(look) {
454
+ if (look === null)
455
+ this.removeAttribute("earth-places-look");
456
+ else
457
+ this.setAttribute("earth-places-look", look);
458
+ }
459
+ /** 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`. */
460
+ get earthPlacesShown() {
461
+ return { marks: this.#earthLayer?.shown ?? [], omitted: this.#earthOmitted };
462
+ }
365
463
  /**
366
464
  * Go to a place on a body: the view glides to the body (as `goTo` does), or on the body looked at turns round it, and the camera comes to rest straight above the place. The place is an id (`mars/perseverance`) or an English or Japanese name, on the body looked at
367
465
  * unless `body` names another. The zoom stays on the same body and is 1 (the whole body) on another, unless `zoom` is given. Resolves the place, or `undefined` when the body has no place by that name or cannot be looked at.
@@ -421,6 +519,65 @@ export class WakuseiSpace extends HTMLElement {
421
519
  requestAnimationFrame(step);
422
520
  return place;
423
521
  }
522
+ #readEarthPlaces() {
523
+ const text = this.getAttribute("earth-places");
524
+ const using = earthPlacesLayout();
525
+ if (text === null || using === undefined)
526
+ return [];
527
+ if (this.#earthList?.text === text)
528
+ return this.#earthList.list;
529
+ // the places that matter most first: where the reader is, then the rest in the order given
530
+ const list = using.read(text);
531
+ const ordered = [...list.filter((place) => place.kind === "here"), ...list.filter((place) => place.kind !== "here")];
532
+ this.#earthList = { text, list: ordered };
533
+ return ordered;
534
+ }
535
+ /** The places, the look or the layout changed: lay them from the last draw's Earth, or when there was none ask for one draw to learn it. */
536
+ #askEarthPlaces() {
537
+ if (!this.hasAttribute("earth-places")) {
538
+ this.#earthLayer?.dispose();
539
+ this.#earthLayer = undefined;
540
+ this.#earthSurface = null;
541
+ this.#earthOmitted = 0;
542
+ return;
543
+ }
544
+ if (this.#earthSurface !== null)
545
+ this.#layEarthPlaces();
546
+ else
547
+ this.#gate?.request();
548
+ }
549
+ /** Lay the places over the Earth as the last draw left it, or take them away. Draws nothing: it runs inside the draw the view makes anyway. */
550
+ #layEarthPlaces() {
551
+ const surface = this.#earthSurface;
552
+ const root = this.shadowRoot;
553
+ const using = earthPlacesLayout();
554
+ const clear = () => {
555
+ this.#earthLayer?.clear();
556
+ this.#earthOmitted = 0;
557
+ };
558
+ if (surface === null || root === null || using === undefined || !this.hasAttribute("earth-places") || !(surface.radiusPx >= EARTH_PLACES_FROM_PX))
559
+ return clear();
560
+ const places = this.#readEarthPlaces();
561
+ if (places.length === 0)
562
+ return clear();
563
+ this.#earthLayer ??= createEarthPlaceLayer(root);
564
+ const layer = this.#earthLayer;
565
+ const facts = BODIES.earth;
566
+ const scale = [1, 1 - facts.flattening, 1];
567
+ const view = spotView({ ...surface, scale });
568
+ const sun = surface.sun === null ? null : pointUnder(surface.sun, surface.pole, surface.meridian);
569
+ const look = this.earthPlacesLook;
570
+ const laid = using.layout(places, view, look, {
571
+ size: (place) => (place.label === undefined ? null : { width: layer.width(place.label), height: 18 }),
572
+ taken: this.#nameBoxes.map((one) => ({ left: one.x, top: one.y, width: one.width, height: one.height })),
573
+ sun,
574
+ });
575
+ // the first few in sight stand up; the rest are counted, never silently left out
576
+ const marks = { shapes: laid.shapes.slice(0, EARTH_PLACE_MARKS), labels: laid.labels };
577
+ marks.labels = laid.labels.filter((spot) => marks.shapes.some((shape) => shape.index === spot.index));
578
+ this.#earthOmitted = laid.shapes.length - marks.shapes.length;
579
+ layer.set(places, marks, look);
580
+ }
424
581
  async #loadMarks(body) {
425
582
  if (this.#markList?.body === body)
426
583
  return this.#markList.list;
@@ -537,6 +694,9 @@ export class WakuseiSpace extends HTMLElement {
537
694
  }
538
695
  set scale(value) {
539
696
  this.#model.mode = value;
697
+ // a flight through a belt is at true distances: the squeezed scale does not map a camera that moves among the bodies
698
+ if (value !== "true" && this.#flight !== null)
699
+ this.leaveBelt();
540
700
  this.#nameScale();
541
701
  this.#gate?.request();
542
702
  }
@@ -587,7 +747,7 @@ export class WakuseiSpace extends HTMLElement {
587
747
  #orbitersLoading = false;
588
748
  /**
589
749
  * Show the spacecraft in orbit round the Moon and Mars (the attribute `orbiters`; off by default): each a small dot where `/orbiters` puts it on the date shown, scaled with its body, on its orbit line, with its
590
- * name beside it in the page's language, once the body is at least 24 CSS pixels in radius on the screen. A modelled or predicted path is drawn dim; a craft with no path is not drawn. The paths (a 9 kB module)
750
+ * name beside it in the page's language, once the body is at least 24 CSS pixels in radius on the screen. A modelled path is drawn dim, and a predicted one whose measured error is more than 2 per cent of its body's radius (`orbiterDim`); a craft with no path is not drawn. The paths (a 9 kB module)
591
751
  * are loaded the first time they are shown. `stats.orbiters` says what was drawn and each one's status.
592
752
  */
593
753
  get orbiters() {
@@ -604,6 +764,8 @@ export class WakuseiSpace extends HTMLElement {
604
764
  position: (id, ms) => (mod.orbiterElements(id) === undefined ? null : mod.orbiterPosition(id, ms)),
605
765
  path: (id, ms, points) => mod.orbiterPath(id, ms, points),
606
766
  status: (id, ms) => mod.orbiterStatus(id, ms),
767
+ dim: (id, ms) => mod.orbiterDim(id, ms),
768
+ period: (id) => mod.orbiterElements(id)?.periodDays ?? null,
607
769
  name: (id) => ({ ...mod.orbiterFacts(id).name }),
608
770
  };
609
771
  this.#gate?.request();
@@ -635,6 +797,36 @@ export class WakuseiSpace extends HTMLElement {
635
797
  }
636
798
  this.#gate?.request();
637
799
  }
800
+ /**
801
+ * The orbiter picked out (the attribute `orbiter`, an id from `/orbiters` such as `lro`; none by default): its orbit line is drawn brighter, it alone keeps its line when `orbiterLines` is
802
+ * `chosen`, and its ground track is drawn when `orbiterTrack` is on.
803
+ */
804
+ get orbiter() {
805
+ return this.#model.orbiterChosen;
806
+ }
807
+ set orbiter(value) {
808
+ this.#model.orbiterChosen = value;
809
+ this.#gate?.request();
810
+ }
811
+ /** Which orbiters' orbit lines are drawn (the attribute `orbiter-lines`): `all` (the default), `chosen` (the one `orbiter` names) or `none`. Apart from the planets' and moons' lines (`orbits`). */
812
+ get orbiterLines() {
813
+ return this.#model.orbiterLines;
814
+ }
815
+ set orbiterLines(value) {
816
+ this.#model.orbiterLines = orbiterLines(value);
817
+ this.#gate?.request();
818
+ }
819
+ /**
820
+ * Draw the chosen orbiter's ground track (the attribute `orbiter-track`; off by default): the line on its body under the craft from one trip before the moment shown to one trip after, the body
821
+ * turning beneath it, so each trip crosses the equator further west.
822
+ */
823
+ get orbiterTrack() {
824
+ return this.#model.orbiterTrack;
825
+ }
826
+ set orbiterTrack(value) {
827
+ this.#model.orbiterTrack = value;
828
+ this.#gate?.request();
829
+ }
638
830
  #covered = "name";
639
831
  #arrows = new Map();
640
832
  /**
@@ -1145,6 +1337,9 @@ export class WakuseiSpace extends HTMLElement {
1145
1337
  model.focus = this.#focusBeforeRide;
1146
1338
  }
1147
1339
  this.#lostTold = false;
1340
+ // a ride to somewhere other than the belt's own point ends the flight through it
1341
+ if (this.#flight !== null && (model.ride === null || model.ride.target !== this.#flight.point))
1342
+ this.#flight = null;
1148
1343
  const destination = target !== null && typeof target === "string" ? (readBody(target) ?? null) : target === null ? this.#model.focus : null;
1149
1344
  model.transition = this.#startMove(this.#moveKind(options, destination), leaving, destination, options.duration);
1150
1345
  if (model.transition !== null && model.ride?.view === "beside" && typeof model.ride.target === "string") {
@@ -1155,6 +1350,7 @@ export class WakuseiSpace extends HTMLElement {
1155
1350
  }
1156
1351
  model.region = null;
1157
1352
  this.#showRegion();
1353
+ this.#showNote();
1158
1354
  this.#schedule();
1159
1355
  this.#gate?.request();
1160
1356
  this.dispatchEvent(new CustomEvent("wakusei-ride", { detail: this.riding }));
@@ -1204,6 +1400,94 @@ export class WakuseiSpace extends HTMLElement {
1204
1400
  }
1205
1401
  return undefined;
1206
1402
  }
1403
+ /**
1404
+ * The belts drawn, by name (`main`, `hilda`, `trojan`, `centaur`, `classical`, `resonant`, `scattered`): all seven by default, `[]` for none. The attribute `belts` says the same (`belts="off"`, `belts="main trojan"`). Each belt is one instanced draw of its own
1405
+ * colour, from the package's own source of NASA/JPL's Small-Body Database (`@johnmorrisdotca/wakusei-planets/belts`), fetched when the view first draws it.
1406
+ */
1407
+ get belts() {
1408
+ return this.#model.belts;
1409
+ }
1410
+ set belts(list) {
1411
+ this.#model.belts = BELT_IDS.filter((id) => list.includes(id));
1412
+ if (this.#flight !== null && !this.#model.belts.includes(this.#flight.belt))
1413
+ this.leaveBelt();
1414
+ // with no belt shown the source is switched off, so its bodies are neither read nor held (the chunk of them is not fetched)
1415
+ this.#door.book.enableSource(BELTS_SOURCE_ID, this.#model.belts.length > 0);
1416
+ this.#gate?.request();
1417
+ }
1418
+ /**
1419
+ * Fly into a belt: the camera goes to a point on a circular orbit in the middle of the belt, tilted a few degrees to the ecliptic so that it passes through the belt's thickness, looking the way it goes with the ecliptic's north at the top, at true
1420
+ * distances (the squeezed scale is left), and a drag looks about. The dots round it are the belt's bodies; a line on the view says how many bodies there really are, and that neighbours are millions of kilometres apart, which is why the picture is
1421
+ * mostly empty. Time runs as the clock says (`speed`). `leaveBelt()` goes back.
1422
+ *
1423
+ * @param belt - The belt, `main` by default.
1424
+ * @param options - `smooth` (a glide, true by default).
1425
+ */
1426
+ enterBelt(belt = "main", options = {}) {
1427
+ if (!BELT_IDS.includes(belt))
1428
+ throw new RangeError(`belt must be one of ${BELT_IDS.join(", ")}, got ${JSON.stringify(belt)}`);
1429
+ if (this.#model.mode !== "true")
1430
+ this.scale = "true";
1431
+ if (!this.#model.belts.includes(belt))
1432
+ this.belts = [...this.#model.belts, belt];
1433
+ const point = beltFlight(belt);
1434
+ this.#flight = { belt, point };
1435
+ this.ride(point, { around: "sun", view: "from", look: "ahead", smooth: options.smooth ?? true });
1436
+ // the note needs the bodies to know how thickly they lie; the line is shown as soon as they are here
1437
+ void loadBeltBodies().then((bodies) => {
1438
+ this.#spacing.set(belt, beltSpacing(belt, bodies, 2_461_200.5));
1439
+ this.#showNote();
1440
+ });
1441
+ this.#showNote();
1442
+ }
1443
+ /** Come out of a belt: the camera goes back to the body it looked at before. */
1444
+ leaveBelt(options = {}) {
1445
+ if (this.#flight === null)
1446
+ return;
1447
+ this.#flight = null;
1448
+ this.ride(null, { smooth: options.smooth ?? true });
1449
+ this.#showNote();
1450
+ }
1451
+ /** The belt the camera is flying through, or null. */
1452
+ get flyingThrough() {
1453
+ return this.#flight?.belt ?? null;
1454
+ }
1455
+ /** The line about a belt that is on the view while the camera is in one, and the label of the Oort cloud's shell when it is drawn. */
1456
+ #showNote() {
1457
+ if (this.#noteLine === undefined)
1458
+ return;
1459
+ const riding = this.#model.ride;
1460
+ if (this.#flight !== null && (riding === null || riding.target !== this.#flight.point))
1461
+ this.#flight = null;
1462
+ const spacing = this.#flight === null ? undefined : this.#spacing.get(this.#flight.belt);
1463
+ const language = this.getAttribute("lang") === "ja" ? "ja" : "en";
1464
+ if (this.#flight === null) {
1465
+ this.#noteLine.hidden = true;
1466
+ this.#noteLine.textContent = "";
1467
+ }
1468
+ else {
1469
+ this.#noteLine.hidden = false;
1470
+ this.#noteLine.textContent = spacing === undefined ? BELTS[this.#flight.belt].name[language] : beltNote(this.#flight.belt, spacing, language);
1471
+ }
1472
+ if (this.#oortLabel !== undefined)
1473
+ this.#oortLabel.textContent = `${OORT.name[language]} (${language === "ja" ? "内側のふち 約" : "inner edge about "}${OORT.innerAu.toLocaleString(language === "ja" ? "ja-JP" : "en-US")}${language === "ja" ? "天文単位" : " au"})`;
1474
+ }
1475
+ /** Where the Oort label goes: at the point of the shell the scene found, or hidden when the shell is not drawn. */
1476
+ #placeOort() {
1477
+ if (this.#oortLabel === undefined)
1478
+ return;
1479
+ const at = this.#model.oort;
1480
+ if (at === null) {
1481
+ if (!this.#oortLabel.hidden)
1482
+ this.#oortLabel.hidden = true;
1483
+ return;
1484
+ }
1485
+ if (this.#oortLabel.textContent === "")
1486
+ this.#showNote();
1487
+ if (this.#oortLabel.hidden)
1488
+ this.#oortLabel.hidden = false;
1489
+ this.#oortLabel.style.transform = `translate(${Math.round(at.x) + 6}px,${Math.round(at.y) - 8}px)`;
1490
+ }
1207
1491
  /** What the camera is riding along with now, or null. */
1208
1492
  get riding() {
1209
1493
  return this.#model.ride ? { ...this.#model.ride } : null;
@@ -1252,10 +1536,11 @@ export class WakuseiSpace extends HTMLElement {
1252
1536
  * licence and credit. Assign a list to replace them; a source `validateSource` refuses throws a `TypeError` and changes nothing. A property, not an attribute: data is not text.
1253
1537
  */
1254
1538
  get sources() {
1255
- return this.#door.sources();
1539
+ return this.#door.sources().filter((source) => source.info.id !== BELTS_SOURCE_ID);
1256
1540
  }
1257
1541
  set sources(list) {
1258
- this.#door.setSources(list);
1542
+ const own = this.#door.book.get(BELTS_SOURCE_ID);
1543
+ this.#door.setSources(own === undefined ? list : [own, ...list]);
1259
1544
  }
1260
1545
  /** Adds one source (checked at once: a `TypeError` for an empty credit, no licence, a clashing id or a map source with no body). Returns the function that removes it. */
1261
1546
  addSource(source) {
@@ -1291,7 +1576,7 @@ export class WakuseiSpace extends HTMLElement {
1291
1576
  camera: { position: [...this.#model.camera.position], fov: this.#model.camera.fov, up: [...this.#model.camera.up], forward: [...this.#model.camera.forward] },
1292
1577
  bodies: { look: this.#model.look, painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held },
1293
1578
  tiles: { ...this.#model.tiles },
1294
- door: { points: this.#model.door.points, sources: this.#door.book.stats() },
1579
+ door: { points: this.#model.door.points, belts: this.#model.door.belts, draws: this.#model.door.draws, sources: this.#door.book.stats() },
1295
1580
  allMoons: { on: this.#allMoons, loaded: this.#model.allMoons !== null, dots: this.#model.moonDots },
1296
1581
  ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
1297
1582
  travelling: this.#model.travelling === null ? null : { ...this.#model.travelling },
@@ -1301,7 +1586,7 @@ export class WakuseiSpace extends HTMLElement {
1301
1586
  arrowPx: this.#model.arrowPx,
1302
1587
  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,
1303
1588
  bodyLabels: { count: this.#model.labelsDrawn.count, focus: this.#model.labelsDrawn.focus === null ? null : { ...this.#model.labelsDrawn.focus } },
1304
- orbiters: { count: this.#model.orbitersDrawn.count, status: { ...this.#model.orbitersDrawn.status } },
1589
+ orbiters: { count: this.#model.orbitersDrawn.count, status: { ...this.#model.orbitersDrawn.status }, dim: [...this.#model.orbitersDrawn.dim], lines: this.#model.orbitersDrawn.lines, track: this.#model.orbitersDrawn.track },
1305
1590
  roadster: { shown: this.#model.roadsterDrawn.shown, position: this.#model.roadsterDrawn.position === null ? null : [...this.#model.roadsterDrawn.position], radiusPx: this.#model.roadsterDrawn.radiusPx },
1306
1591
  };
1307
1592
  }
@@ -11,18 +11,18 @@ import { type Vec3 } from "../vec.ts";
11
11
  */
12
12
  export declare const RIDE_FOV = 60;
13
13
  /**
14
- * Where a riding camera looks: `down` straight at the centre of the body it goes round (the ground goes by under the camera), or `horizon` tipped forward along the way it is going until the horizon
15
- * is a little above the middle of the view.
14
+ * Where a riding camera looks: `down` straight at the centre of the body it goes round (the ground goes by under the camera), `horizon` tipped forward along the way it is going until the horizon
15
+ * is a little above the middle of the view, or `ahead` along the way it is going with the ecliptic's north at the top, as a pilot looks (for a flight through a belt, where there is no ground).
16
16
  *
17
17
  * @example
18
18
  * ```ts
19
19
  * import type { RideLook } from "@johnmorrisdotca/wakusei-planets/space";
20
20
  *
21
- * const looks: RideLook[] = ["down", "horizon"];
21
+ * const looks: RideLook[] = ["down", "horizon", "ahead"];
22
22
  * console.log(looks.join(" or "));
23
23
  * ```
24
24
  */
25
- export type RideLook = "down" | "horizon";
25
+ export type RideLook = "down" | "horizon" | "ahead";
26
26
  /**
27
27
  * What `ridePose` is asked: the camera's place from the centre of the body it goes round and its way of travel (any length), that body's radius in the unit of the place, where it looks,
28
28
  * and the shared controls' yaw, tilt and zoom.
@@ -1,6 +1,6 @@
1
1
  // Riding along: the camera sits at a moving point (a moon, a planet, a satellite someone else tracks) and looks at the body it goes round. This file is the maths of where it looks, pure,
2
2
  // so a page or a test can ask the same question the space view does. It knows no satellites: any point with a place and a way of going will do, and any central body, by its radius.
3
- import { cross, dot, length, RAD, scale, unit, add } from "../vec.js";
3
+ import { cross, dot, length, OBLIQUITY, RAD, scale, unit, add } from "../vec.js";
4
4
  /** How far the ground moves in the picture for each pixel of a drag at the middle of it: the same pace as the line globe and the Earth from space (about one and a half). */
5
5
  const GRAB = 1.5;
6
6
  /**
@@ -46,8 +46,15 @@ export function ridePose(input) {
46
46
  ahead = unit(ahead);
47
47
  const bodyRadiusDegrees = distance <= radius ? 90 : Math.asin(radius / distance) / RAD;
48
48
  const base = input.look === "horizon" ? Math.max(0, bodyRadiusDegrees - 12) * RAD : 0;
49
- const forward0 = add(scale(nadir, Math.cos(base)), scale(ahead, Math.sin(base)));
50
- const up0 = add(scale(ahead, Math.cos(base)), scale(nadir, -Math.sin(base)));
49
+ let forward0 = add(scale(nadir, Math.cos(base)), scale(ahead, Math.sin(base)));
50
+ let up0 = add(scale(ahead, Math.cos(base)), scale(nadir, -Math.sin(base)));
51
+ if (input.look === "ahead" && length(input.velocity) > 0) {
52
+ // along the way it goes, the ecliptic's north (in the scene's axes) at the top
53
+ forward0 = unit(input.velocity);
54
+ const pole = [0, Math.cos(OBLIQUITY * RAD), Math.sin(OBLIQUITY * RAD)];
55
+ const raised = add(pole, scale(forward0, -dot(pole, forward0)));
56
+ up0 = length(raised) > 1e-9 ? unit(raised) : ahead;
57
+ }
51
58
  const fov = Math.min(100, Math.max(5, RIDE_FOV / Math.max(0.05, input.zoom)));
52
59
  const turn = input.yaw * ((GRAB * fov) / 180) * RAD;
53
60
  const lift = input.tilt * ((GRAB * fov) / 60) * RAD;