@johnmorrisdotca/chikyu-earth 0.36.0 → 0.38.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 (44) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/NOTICE.md +6 -1
  3. package/README.md +1 -1
  4. package/dist/catalogue/index.d.ts +1 -0
  5. package/dist/catalogue/index.js +3 -2
  6. package/dist/catalogue/pack.js +3 -0
  7. package/dist/cities/host.js +38 -8
  8. package/dist/markers/place-layer.d.ts +12 -1
  9. package/dist/markers/place-layer.js +88 -18
  10. package/dist/markers/place-sprites.d.ts +5 -0
  11. package/dist/markers/place-sprites.js +8 -0
  12. package/dist/paint/buffer.d.ts +53 -0
  13. package/dist/paint/buffer.js +238 -0
  14. package/dist/paint/math.d.ts +24 -0
  15. package/dist/paint/math.js +94 -0
  16. package/dist/paint/texture.d.ts +24 -0
  17. package/dist/paint/texture.js +33 -0
  18. package/dist/realistic/earth.d.ts +9 -0
  19. package/dist/realistic/earth.js +20 -11
  20. package/dist/realistic/element.d.ts +36 -3
  21. package/dist/realistic/element.js +82 -14
  22. package/dist/realistic/shaders.js +13 -0
  23. package/dist/realistic/textures.d.ts +2 -0
  24. package/dist/satellites/index.d.ts +1 -0
  25. package/dist/satellites/index.js +1 -0
  26. package/dist/satellites/limits.d.ts +1 -1
  27. package/dist/satellites/limits.js +1 -1
  28. package/dist/satellites/owners.d.ts +26 -0
  29. package/dist/satellites/owners.js +164 -0
  30. package/dist/satellites/source.js +3 -0
  31. package/dist/satellites/track.d.ts +5 -0
  32. package/dist/satellites/track.js +146 -3
  33. package/dist/satellites/types.d.ts +22 -1
  34. package/dist/space/element.d.ts +56 -6
  35. package/dist/space/element.js +171 -16
  36. package/dist/space/index.d.ts +1 -1
  37. package/dist/space/index.js +1 -1
  38. package/dist/space/ride.d.ts +42 -0
  39. package/dist/space/ride.js +45 -3
  40. package/dist/space/satellite-layer.d.ts +32 -2
  41. package/dist/space/satellite-layer.js +178 -19
  42. package/dist/space/scene.d.ts +12 -1
  43. package/dist/space/scene.js +27 -16
  44. package/package.json +1 -1
@@ -4,7 +4,7 @@ import { airFor, readAirThickness } from "../realistic/air.js";
4
4
  import { BODY_LABEL_ATTRIBUTES, bodyLabelText, loadMichroma, readBodyLabel } from "../realistic/body-label.js";
5
5
  import { createSkyHost, SKY_ATTRIBUTES, SKY_STYLE } from "../sky/host.js";
6
6
  import { cleanPlaces, readPlaceGroups, readPlaces } from "../markers/places.js";
7
- import { createPlaceLayer, PLACE_STYLE, readPlaceLook } from "../markers/place-layer.js";
7
+ import { createPlaceLayer, PLACE_STYLE, placesLostNotice, readPlaceLook } from "../markers/place-layer.js";
8
8
  import { aimAt, findPlace, glideView } from "../markers/go-to-place.js";
9
9
  import { subsolarPoint } from "../realistic/sun.js";
10
10
  import { SHORT_NAMES } from "../satellites/names.js";
@@ -20,12 +20,12 @@ import { IMMERSIVE_STYLE, immersiveWheel } from "../realistic/immersive.js";
20
20
  import { readMeteorStrength } from "../meteors/strength.js";
21
21
  import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
22
22
  import { MAX_TEXTURE } from "../realistic/tiers.js";
23
- import { MAX_SATELLITE_SPEED } from "../satellites/limits.js";
24
23
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
25
24
  import { MAX_ORBIT_GROUP } from "./satellite-layer.js";
26
- import { rideTiltLimits, rideTurnDegrees } from "./ride.js";
25
+ import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
27
26
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
28
27
  import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
28
+ import { createPaintState, paintedGround } from "../paint/buffer.js";
29
29
  export { BODY_NAMES };
30
30
  let painter;
31
31
  let satellitePainter;
@@ -65,6 +65,7 @@ export function setSatellitePainter(next) {
65
65
  /** Mean radii in kilometres (IAU), for what a click tells. */
66
66
  const RADIUS_KM = { Sun: 695_700, Mercury: 2439.7, Venus: 6051.8, Earth: 6371, Moon: 1737.4, Mars: 3389.5, Jupiter: 69_911, Saturn: 58_232, Uranus: 25_362, Neptune: 24_622, Pluto: 1188.3 };
67
67
  export { setThreeLoader };
68
+ const FACE_KEYS = { w: "ahead", s: "behind", a: "left", d: "right", r: "up", f: "down" };
68
69
  /** A `light` attribute: `lit` or `boost`, else the true sun. */
69
70
  const readLight = (value) => (value === "lit" || value === "boost" ? value : "sun");
70
71
  const RAD = Math.PI / 180;
@@ -131,6 +132,9 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
131
132
  * const space = document.createElement("chikyu-space") as ChikyuSpace;
132
133
  * space.setAttribute("time", "2026-11-02T12:00Z");
133
134
  * space.setAttribute("speed", "86400");
135
+ * space.placeGroups = false; // place-groups="off": every place keeps its own ring
136
+ * space.paint = { id: "25544", length: "1w", swath: "coverage" };
137
+ * space.clearPaint();
134
138
  * space.addEventListener("chikyu-timechange", (event) => {
135
139
  * const { time, running } = (event as CustomEvent<{ time: number; running: boolean }>).detail;
136
140
  * console.log(new Date(time).toISOString(), running ? "running" : "held");
@@ -139,8 +143,9 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
139
143
  * ```
140
144
  */
141
145
  export class ChikyuSpace extends HTMLElement {
142
- static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "bodies-credit"];
146
+ static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "bodies-credit", "satellite-tint"];
143
147
  #model = newSpaceModel();
148
+ #paint = createPaintState();
144
149
  #mode = "now";
145
150
  #speed = 1;
146
151
  #view;
@@ -184,16 +189,24 @@ export class ChikyuSpace extends HTMLElement {
184
189
  #tiers = {};
185
190
  #hands;
186
191
  #ridden = {};
192
+ #toldFacing = null;
187
193
  #placeLayer;
194
+ /** Whether the page has been told that places in sight were left undrawn. */
195
+ #placesLost = { told: false };
188
196
  #placeList = [];
189
197
  /** Counts the turns to a place, so a new one stops the one before. */
190
198
  #placeGlide = 0;
191
199
  #nameBoxes = new Map();
200
+ /** A font that arrives after the names were measured: the boxes are read again on the next layout. The satellites' marks are not touched, or the page would be told again about each one already in view. */
201
+ #onFonts = () => {
202
+ this.#nameBoxes.clear();
203
+ };
192
204
  /** The controller behind the element's own hands (`set`, `fit`, `state`), while it is in a page. */
193
205
  get controller() {
194
206
  return this.#hands?.controller;
195
207
  }
196
208
  connectedCallback() {
209
+ document.fonts?.addEventListener?.("loadingdone", this.#onFonts);
197
210
  this.#model.centre = readCentre(this.getAttribute("center")) ?? this.#model.centre;
198
211
  this.#mode = readTime(this.getAttribute("time"));
199
212
  this.#model.time = this.#mode === "now" ? Date.now() : this.#mode;
@@ -295,6 +308,14 @@ export class ChikyuSpace extends HTMLElement {
295
308
  onRideLost: () => this.#rideLost(),
296
309
  onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
297
310
  onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
311
+ paint: {
312
+ data: this.#paint.data,
313
+ width: this.#paint.width,
314
+ height: this.#paint.height,
315
+ step: (ms) => this.#paint.step(ms, (at) => paintedGround(this.#model.satellites.groups, this.#paint.id, at)),
316
+ span: () => this.#paint.spanMinutes,
317
+ on: () => this.#paint.on,
318
+ },
298
319
  ...(painter ? { painter } : {}),
299
320
  satellitePainter: () => satellitePainter,
300
321
  onPainterError: (error) => this.dispatchEvent(new CustomEvent("chikyu-bodies-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
@@ -314,16 +335,24 @@ export class ChikyuSpace extends HTMLElement {
314
335
  this.addEventListener("pointerdown", this.#down);
315
336
  // before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
316
337
  this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
338
+ this.addEventListener("keydown", this.#faceKey);
339
+ if (!this.hasAttribute("tabindex"))
340
+ this.tabIndex = 0;
317
341
  this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
318
342
  this.#labelBox.addEventListener("click", this.#labelClick);
319
343
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
320
344
  }
321
345
  disconnectedCallback() {
346
+ document.fonts?.removeEventListener?.("loadingdone", this.#onFonts);
347
+ this.#marks = [];
348
+ this.#markSeen.clear();
349
+ this.#nameBoxes.clear();
322
350
  this.#hands?.unbind();
323
351
  this.#hands = undefined;
324
352
  this.#zoomRange(false);
325
353
  this.removeEventListener("pointerdown", this.#down);
326
354
  this.removeEventListener("wheel", this.#wheel, { capture: true });
355
+ this.removeEventListener("keydown", this.#faceKey);
327
356
  window.removeEventListener("pointerup", this.#up, true);
328
357
  clearTimeout(this.#timer);
329
358
  this.#timer = undefined;
@@ -418,6 +447,10 @@ export class ChikyuSpace extends HTMLElement {
418
447
  }
419
448
  else if (COUNTRY_NAMES_ATTRIBUTES.includes(name))
420
449
  this.#countries?.refresh();
450
+ else if (name === "satellite-tint") {
451
+ this.#model.satellites.orbitTint = value === "orbit";
452
+ this.#gate?.request();
453
+ }
421
454
  if (name === "air-thickness" || name === "air-label" || name === "lang")
422
455
  setAirNote(this.#airNote, this, this.#model.airThickness);
423
456
  if (name === "bodies-credit" || name === "lang")
@@ -591,6 +624,17 @@ export class ChikyuSpace extends HTMLElement {
591
624
  }
592
625
  /**
593
626
  * Whether places that crowd are gathered into one ring with their count (the attribute `place-groups`): on by default, `off` leaves every place its own ring. Setting the property writes the attribute.
627
+ *
628
+ * @example
629
+ * ```ts no-run
630
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
631
+ *
632
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
633
+ * space.placeGroups = false;
634
+ * space.getAttribute("place-groups"); // "off"
635
+ * space.placeGroups = true;
636
+ * space.hasAttribute("place-groups"); // false
637
+ * ```
594
638
  */
595
639
  get placeGroups() {
596
640
  return this.#placeLayer?.grouping ?? readPlaceGroups(this.getAttribute("place-groups"));
@@ -601,15 +645,20 @@ export class ChikyuSpace extends HTMLElement {
601
645
  else
602
646
  this.setAttribute("place-groups", "off");
603
647
  }
604
- /** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself and the page is told once, so no place is lost without a word. */
648
+ /** The picture said whether it can draw the rings of the places that are not markers of their own. Without `Points` the places' layer draws them itself. */
605
649
  #ringsDrawn(drawn) {
606
650
  if (!this.#placeLayer || this.#placeLayer.ringsInPicture === drawn)
607
651
  return;
608
652
  this.#placeLayer.ringsInPicture = drawn;
609
- if (!drawn)
610
- this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: { reason: "the three.js parts handed over lack Points: the places' rings are drawn as small circles in the page, at most 600, and stats.places.omitted counts the rest" } }));
611
653
  this.#gate?.request();
612
654
  }
655
+ /** Tell the page once when places in sight had no room among the fallback circles. Missing `Points` alone leaves them drawn, so it says nothing. */
656
+ #notePlacesLost() {
657
+ const notice = placesLostNotice(this.#placesLost, this.#placeLayer?.stats.omitted ?? 0);
658
+ if (!notice)
659
+ return;
660
+ this.dispatchEvent(new CustomEvent("chikyu-places-unavailable", { detail: notice }));
661
+ }
613
662
  /** How the places are drawn (the attribute `places-look`): `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring on the ground). */
614
663
  get placesLook() {
615
664
  return this.#placeLayer?.look ?? readPlaceLook(this.getAttribute("places-look"));
@@ -623,6 +672,7 @@ export class ChikyuSpace extends HTMLElement {
623
672
  if (!layer || (this.#placeList.length === 0 && this.#marks.length === 0 && layer.stats.shown === 0 && layer.stats.rings === 0))
624
673
  return;
625
674
  layer.frame(view, this.#bodyNameBoxes(), this.#marks, this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
675
+ this.#notePlacesLost();
626
676
  }
627
677
  /** Tells the names of cities, then of countries, where the Earth is in the picture just drawn; the countries' names keep clear of the bodies', the places' and the cities'. */
628
678
  #nameFrame(frame) {
@@ -890,6 +940,7 @@ export class ChikyuSpace extends HTMLElement {
890
940
  return;
891
941
  }
892
942
  this.#gate?.request();
943
+ this.#tellFacing();
893
944
  }
894
945
  /**
895
946
  * The controls that are driving this view: a `<kazoku-view-controls for="...">` bound to it (its hands are then the only ones and its controller holds the yaw and tilt), else the element's own hands.
@@ -945,7 +996,15 @@ export class ChikyuSpace extends HTMLElement {
945
996
  const asked = options.view ?? "from";
946
997
  // above a body is meant for a satellite: a body is followed
947
998
  const view = typeof target === "string" && (target === "Earth" || asked === "above") ? "follow" : asked;
948
- model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: options.look ?? "down", distanceKm: Math.max(100, options.distanceKm ?? 3000) };
999
+ // a body followed (a planet, the Moon, the Earth) is looked at from round it as the view turns: it has no ways to face
1000
+ const faceable = !(view === "follow" && typeof target === "string");
1001
+ const face = faceable && options.face && RIDE_FACES.includes(options.face) ? options.face : null;
1002
+ model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000) };
1003
+ if (face) {
1004
+ model.view = { yaw: 0, tilt: 0, zoom: model.view.zoom };
1005
+ model.rideTurn = 0;
1006
+ this.#controls()?.set({ yaw: 0, tilt: 0, zoom: model.view.zoom }, true, "ride");
1007
+ }
949
1008
  if (typeof target === "string" && view === "follow")
950
1009
  model.focus = target;
951
1010
  else if (wasRiding)
@@ -959,7 +1018,71 @@ export class ChikyuSpace extends HTMLElement {
959
1018
  this.#schedule();
960
1019
  this.#gate?.request();
961
1020
  this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
1021
+ this.#tellFacing();
1022
+ }
1023
+ /**
1024
+ * Face one way while riding: `ahead` along the way it goes, `behind`, `left` or `right` (as seen facing ahead), `down` straight at the Earth, `up` straight away from it.
1025
+ * In the `above` view, `down` looks straight down at the satellite and the Earth below it. The camera glides there in half a second (at once for a reader who asked for reduced motion) and keeps the zoom.
1026
+ * The facing stays pressed until the view is turned or tipped. `chikyu-ride-face` is sent with `{ face }` (`null` when it is let go). Keys, while the element is focused: W ahead, S behind, A left, D right, R up, F down. The arrow keys stay with the view controls.
1027
+ *
1028
+ * @param face - The way to face.
1029
+ * Following a body (a planet, the Moon) there is no way to face: it returns `false`. Held keys do not repeat, and keys typed in a field or in editable text are left to it.
1030
+ *
1031
+ * @returns Whether the camera faces that way now (`true` too when it already did, and nothing moves).
1032
+ */
1033
+ face(face) {
1034
+ const model = this.#model;
1035
+ const ride = model.ride;
1036
+ if (!ride || !RIDE_FACES.includes(face))
1037
+ return false;
1038
+ // following a body there is no way to face: only from a body or a satellite, following a satellite, or above it
1039
+ if (ride.view === "follow" && typeof ride.target === "string")
1040
+ return false;
1041
+ // already facing that way: nothing to turn, and no glide started again
1042
+ if (this.facing === face)
1043
+ return true;
1044
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1045
+ const pose = model.pose;
1046
+ const zoom = model.view.zoom;
1047
+ model.ride = { ...ride, look: ride.view === "from" ? "horizon" : ride.look, face };
1048
+ model.view = { yaw: 0, tilt: 0, zoom };
1049
+ model.rideTurn = 0;
1050
+ this.#controls()?.set({ yaw: 0, tilt: 0, zoom }, true, "ride");
1051
+ model.rideTurn = 0;
1052
+ model.view = { yaw: 0, tilt: 0, zoom };
1053
+ model.transition = !reduced && pose.valid ? { start: performance.now(), duration: 500, 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;
1054
+ this.#last = performance.now();
1055
+ this.#schedule();
1056
+ this.#gate?.request();
1057
+ this.#tellFacing();
1058
+ return true;
962
1059
  }
1060
+ /** The facing (`face`), while the view has not been turned or tipped from it; `null` otherwise. */
1061
+ get facing() {
1062
+ const ride = this.#model.ride;
1063
+ const view = this.#model.view;
1064
+ return ride?.face && view.yaw === 0 && view.tilt === 0 ? ride.face : null;
1065
+ }
1066
+ #tellFacing() {
1067
+ const now = this.facing;
1068
+ if (now === this.#toldFacing)
1069
+ return;
1070
+ this.#toldFacing = now;
1071
+ this.dispatchEvent(new CustomEvent("chikyu-ride-face", { detail: { face: now } }));
1072
+ }
1073
+ /** W ahead, S behind, A left, D right, R up, F down, while this element is focused and a ride is on. */
1074
+ #faceKey = (event) => {
1075
+ // a held key repeats: the first press turns, the repeats would only start the glide again and again
1076
+ if (event.ctrlKey || event.metaKey || event.altKey || event.defaultPrevented || event.repeat)
1077
+ return;
1078
+ // typing in a field anywhere on the way to this element (its own shadow root and slots included), or in editable text, is typing, not facing
1079
+ const typing = event.composedPath().some((node) => node instanceof HTMLElement && (node.matches("input, textarea, select") || node.isContentEditable));
1080
+ if (typing)
1081
+ return;
1082
+ const face = FACE_KEYS[event.key.toLowerCase()];
1083
+ if (face && this.face(face))
1084
+ event.preventDefault();
1085
+ };
963
1086
  /** From a body the zoom only narrows the field a little, so the range is 0.5 to 6: the `zoom-min` and `zoom-max` attributes, unless the page set them itself. */
964
1087
  #zoomRange(from) {
965
1088
  for (const name of ["zoom-min", "zoom-max"]) {
@@ -1021,15 +1144,46 @@ export class ChikyuSpace extends HTMLElement {
1021
1144
  this.dispatchEvent(new CustomEvent("chikyu-ride-lost", { detail: this.riding }));
1022
1145
  }
1023
1146
  // --- satellites ---------------------------------------------------------------------------------------------------------------------------------
1147
+ /**
1148
+ * Colour each satellite by its orbit class (low, medium, geostationary, highly elliptical, other). Off by default, so a group keeps the colour it was given. The attribute is `satellite-tint="orbit"`.
1149
+ */
1150
+ get satelliteTint() {
1151
+ return this.#model.satellites.orbitTint ? "orbit" : "off";
1152
+ }
1153
+ set satelliteTint(value) {
1154
+ if (value === "orbit")
1155
+ this.setAttribute("satellite-tint", "orbit");
1156
+ else
1157
+ this.removeAttribute("satellite-tint");
1158
+ }
1024
1159
  /**
1025
1160
  * Show a group of satellites (made by `createSatellites`) under a name, or take the group away with `null`. A group is one draw call however many satellites it holds. Giving the name of a group
1026
1161
  * that is already shown replaces it. `style`: `color` and `size` (CSS pixels) of the dots, and `orbits` to draw every orbit (only for a group of 40 or fewer, such as the stations).
1027
- * The groups are placed by SGP4 about once a second and interpolated between, and are hidden while the clock runs faster than `MAX_SATELLITE_SPEED`.
1162
+ * The groups are placed by SGP4 about once a second and interpolated between. Above `MAX_SATELLITE_SPEED` each satellite is a short streak along its orbit instead of being hidden.
1028
1163
  *
1029
1164
  * @param group - The group's name, for `showSatellites`, `selectSatellite` and the events.
1030
1165
  * @param satellites - The group, or `null` to remove it.
1031
1166
  * @param style - How to draw it.
1032
1167
  */
1168
+ /**
1169
+ * Paint one satellite's path on the Earth. `id` is a NORAD catalogue number or `group:index`. `length` is how long the trail is kept, in simulated time (`1d` when left out, or `1w`, `1m`). `swath` is `track` (the point under the satellite, the default) or `coverage` (where it is at least 10° above the horizon). Setting another satellite clears the trail. `null` clears it.
1170
+ */
1171
+ get paint() {
1172
+ return this.#paint.on ? { id: this.#paint.id, length: this.#paint.length, swath: this.#paint.swath } : null;
1173
+ }
1174
+ set paint(value) {
1175
+ this.#paint.set(value);
1176
+ this.#gate?.request();
1177
+ }
1178
+ /** Take the painted trail off the Earth. */
1179
+ clearPaint() {
1180
+ this.#paint.clear();
1181
+ this.#gate?.request();
1182
+ }
1183
+ /** Texels the trail has painted. 0 after `clearPaint`, and again when the painted satellite changes. */
1184
+ get paintPixels() {
1185
+ return this.#paint.pixels;
1186
+ }
1033
1187
  setSatellites(group, satellites, style = {}) {
1034
1188
  const groups = this.#model.satellites.groups;
1035
1189
  if (satellites === null) {
@@ -1163,7 +1317,7 @@ export class ChikyuSpace extends HTMLElement {
1163
1317
  }
1164
1318
  this.#markSeen = now;
1165
1319
  }
1166
- /** Facts about one satellite at the moment shown (name, number, element age, height, speed, period); undefined if it cannot be placed then. */
1320
+ /** Facts about one satellite at the moment shown (name, number, element age, height, speed, period, and `ownerCountry` when the owner is one country); undefined if it cannot be placed then. */
1167
1321
  satelliteInfo(ref) {
1168
1322
  return this.#model.satellites.groups.get(ref.group)?.satellites.info(ref.index, this.#model.time);
1169
1323
  }
@@ -1227,14 +1381,14 @@ export class ChikyuSpace extends HTMLElement {
1227
1381
  time: this.#model.time,
1228
1382
  lookups: this.#model.lookups,
1229
1383
  satellites: this.#satelliteStats(),
1230
- ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null },
1384
+ ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null, facing: this.facing },
1231
1385
  camera: { position: [this.#model.pose.p[0], this.#model.pose.p[1], this.#model.pose.p[2]], quaternion: [this.#model.pose.q[0], this.#model.pose.q[1], this.#model.pose.q[2], this.#model.pose.q[3]], fov: this.#model.pose.fov },
1232
1386
  bodies: { look: this.#model.bodies || painter?.looks?.[0] || "plain", painted: this.#model.painted.bodies, moons: this.#model.painted.moons, held: this.#model.painted.held, moon: this.#model.painted.moon, tiles: this.#model.painted.tiles },
1233
1387
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
1234
1388
  bodyLabel: { on: this.#model.bodyLabel.settings !== null, text: this.#model.bodyLabel.text, ...this.#model.bodyLabel.drawn },
1235
1389
  sky: this.#sky?.stats ?? { on: false, loaded: false, names: 0, figures: 0, picked: null, pick: null, hover: null, constellations: 0, culture: "iau", renders: 0, lang: "", stars: [] },
1236
1390
  followModel: this.#model.followModel,
1237
- places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, omitted: 0 }) },
1391
+ places: { ...(this.#placeLayer?.stats ?? { places: 0, shown: 0, labels: 0, renders: 0, rings: 0, satelliteNames: 0, marks: 0, groups: 0, sprites: 0, dots: 0, omitted: 0 }) },
1238
1392
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
1239
1393
  borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
1240
1394
  grid: { ...this.#model.grid.stats },
@@ -1251,7 +1405,10 @@ export class ChikyuSpace extends HTMLElement {
1251
1405
  lastBatchMs = Math.max(lastBatchMs, group.satellites.timing.lastBatchMs);
1252
1406
  maxBatchMs = Math.max(maxBatchMs, group.satellites.timing.maxBatchMs);
1253
1407
  }
1254
- return { groups: this.#model.satellites.groups.size, placed: drawn.placed, tooFast: drawn.tooFast, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates };
1408
+ let epochMs = 0;
1409
+ for (const group of this.#model.satellites.groups.values())
1410
+ epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
1411
+ return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates };
1255
1412
  }
1256
1413
  // --- the game clock ----------------------------------------------------------------------------------------------------------------------------
1257
1414
  #readSpeed() {
@@ -1259,10 +1416,8 @@ export class ChikyuSpace extends HTMLElement {
1259
1416
  const value = raw === null || raw === "" ? 1 : Number(raw);
1260
1417
  return Number.isFinite(value) ? value : 1;
1261
1418
  }
1262
- /** Is anything on show that moves faster than the Earth turns: a group of satellites the clock is slow enough to place? */
1419
+ /** Is anything on show that moves faster than the Earth turns: a group of satellites, including above the interpolation limit where they are drawn as streaks? */
1263
1420
  #satellitesMoving() {
1264
- if (Math.abs(this.#speed) > MAX_SATELLITE_SPEED)
1265
- return false;
1266
1421
  for (const group of this.#model.satellites.groups.values())
1267
1422
  if (group.visible && group.satellites.count > 0)
1268
1423
  return true;
@@ -1,6 +1,6 @@
1
1
  export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
2
2
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
3
3
  export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
4
- export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideInput, type RideLook, type RidePose } from "./ride.ts";
4
+ export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose } from "./ride.ts";
5
5
  export type { SatelliteScreen } from "./satellite-layer.ts";
6
6
  export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
@@ -3,5 +3,5 @@
3
3
  export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS } from "./ephemeris.js";
4
4
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
5
5
  export { fitDistance, plainPainter } from "./scene.js";
6
- export { RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
6
+ export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
7
7
  export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
@@ -23,6 +23,46 @@ export declare const RIDE_FOV = 60;
23
23
  * ```
24
24
  */
25
25
  export type RideLook = "down" | "horizon";
26
+ /**
27
+ * A way to face while riding, as from the windows of a plane or a boat: `ahead` along the way it goes, `behind` the opposite, `left` and `right` across that way as seen facing ahead, `down` straight at the Earth and `up` straight away from it.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * import { RIDE_FACES, type RideFace } from "@johnmorrisdotca/chikyu-earth/space";
32
+ *
33
+ * const face: RideFace = "ahead";
34
+ * console.log(RIDE_FACES.includes(face));
35
+ * ```
36
+ */
37
+ export type RideFace = "ahead" | "behind" | "left" | "right" | "down" | "up";
38
+ /**
39
+ * Every facing, in the order of a row of buttons.
40
+ *
41
+ * @example
42
+ * ```ts
43
+ * import { RIDE_FACES } from "@johnmorrisdotca/chikyu-earth/space";
44
+ *
45
+ * console.log(RIDE_FACES.join(" "));
46
+ * ```
47
+ */
48
+ export declare const RIDE_FACES: readonly RideFace[];
49
+ /**
50
+ * Yaw and tilt, in radians, that put a camera looking at a satellite on a facing. `down` is straight above it, looking down at it and the Earth. `ahead` looks along the way it goes.
51
+ *
52
+ * @param face - The facing.
53
+ * @returns The yaw and tilt to give `aboveAxes`.
54
+ *
55
+ * @example
56
+ * ```ts
57
+ * import { faceOffset } from "@johnmorrisdotca/chikyu-earth/space";
58
+ *
59
+ * console.log(faceOffset("down").tilt, faceOffset("ahead").tilt > 1);
60
+ * ```
61
+ */
62
+ export declare function faceOffset(face: RideFace): {
63
+ yaw: number;
64
+ tilt: number;
65
+ };
26
66
  /**
27
67
  * The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 5 and 100.
28
68
  *
@@ -101,6 +141,8 @@ export interface RideInput {
101
141
  * The heading in degrees, accumulated by the caller (see `rideTurnDegrees`): used in place of `yaw` when given, so a turn of more than half a way round is not undone by the controls wrapping their yaw, and a change of zoom does not swing it.
102
142
  */
103
143
  turn?: number;
144
+ /** In the `horizon` look, the facing the yaw and tilt look round from. `ahead` when not given. */
145
+ face?: RideFace;
104
146
  }
105
147
  /**
106
148
  * The camera `ridePose` works out: where it is, which way it looks, which way is up in the picture, its field of view in degrees, and how big the Earth looks from there (its angular radius in degrees).
@@ -14,6 +14,45 @@ const MAX_ABOVE_HORIZON = 20;
14
14
  * ```
15
15
  */
16
16
  export const RIDE_FOV = 60;
17
+ /**
18
+ * Every facing, in the order of a row of buttons.
19
+ *
20
+ * @example
21
+ * ```ts
22
+ * import { RIDE_FACES } from "@johnmorrisdotca/chikyu-earth/space";
23
+ *
24
+ * console.log(RIDE_FACES.join(" "));
25
+ * ```
26
+ */
27
+ export const RIDE_FACES = ["ahead", "behind", "left", "right", "down", "up"];
28
+ /** How far each facing turns from the way it goes, in degrees, to the left, in the view from the body. */
29
+ const FACE_TURN = { ahead: 0, behind: 180, left: 90, right: -90, down: 0, up: 0 };
30
+ /**
31
+ * Yaw and tilt, in radians, that put a camera looking at a satellite on a facing. `down` is straight above it, looking down at it and the Earth. `ahead` looks along the way it goes.
32
+ *
33
+ * @param face - The facing.
34
+ * @returns The yaw and tilt to give `aboveAxes`.
35
+ *
36
+ * @example
37
+ * ```ts
38
+ * import { faceOffset } from "@johnmorrisdotca/chikyu-earth/space";
39
+ *
40
+ * console.log(faceOffset("down").tilt, faceOffset("ahead").tilt > 1);
41
+ * ```
42
+ */
43
+ export function faceOffset(face) {
44
+ if (face === "up")
45
+ return { yaw: 0, tilt: Math.PI };
46
+ if (face === "ahead")
47
+ return { yaw: 0, tilt: Math.PI / 2 };
48
+ if (face === "behind")
49
+ return { yaw: 0, tilt: -Math.PI / 2 };
50
+ if (face === "left")
51
+ return { yaw: Math.PI / 2, tilt: Math.PI / 2 };
52
+ if (face === "right")
53
+ return { yaw: -Math.PI / 2, tilt: Math.PI / 2 };
54
+ return { yaw: 0, tilt: 0 };
55
+ }
17
56
  /**
18
57
  * The field of view, in degrees, of a riding camera at a zoom: the natural 60 divided by the zoom, held between 5 and 100.
19
58
  *
@@ -112,16 +151,19 @@ export function ridePose(input) {
112
151
  }
113
152
  ahead = unit(ahead);
114
153
  const earthRadiusDegrees = distance <= 1 ? 90 : Math.asin(1 / distance) / RAD;
154
+ const faced = input.look === "horizon" && input.face ? FACE_TURN[input.face] : 0;
115
155
  const base = input.look === "horizon" ? Math.max(0, earthRadiusDegrees - 12) * RAD : 0;
116
156
  const fov = rideFov(input.zoom);
117
- const turn = (input.turn ?? input.yaw * (GRAB * fov / 180)) * RAD;
157
+ const turn = ((input.turn ?? input.yaw * (GRAB * fov / 180)) + faced) * RAD;
118
158
  const lift = input.tilt * (GRAB * fov / 60) * RAD;
159
+ const rest = input.face === "down" ? -Math.PI / 2 : input.face === "up" ? Math.PI / 2 : base - Math.PI / 2;
160
+ const cap = Math.max(MAX_ABOVE_HORIZON * RAD, rest);
119
161
  if (input.look === "horizon") {
120
162
  // looking round on the spot: a drag sideways turns the camera about the local vertical, all the way round, and a drag up or down tips it up or down in the vertical plane it faces, from straight down to a little above the horizon,
121
- // so the horizon stays level and nothing rolls
163
+ // so the horizon stays level and nothing rolls. A facing (`up`, `down`, `ahead`, ...) is where that drag starts.
122
164
  const zenith = scale(nadir, -1);
123
165
  const heading = add(scale(ahead, Math.cos(turn)), scale(cross(zenith, ahead), Math.sin(turn)));
124
- const elevation = Math.max(-Math.PI / 2, Math.min(MAX_ABOVE_HORIZON * RAD, base - Math.PI / 2 - lift));
166
+ const elevation = Math.max(-Math.PI / 2, Math.min(cap, rest - lift));
125
167
  const forward = add(scale(heading, Math.cos(elevation)), scale(zenith, Math.sin(elevation)));
126
168
  const up = add(scale(heading, -Math.sin(elevation)), scale(zenith, Math.cos(elevation)));
127
169
  return { position: [input.position[0], input.position[1], input.position[2]], forward, up, fov, earthRadiusDegrees };
@@ -19,9 +19,13 @@ export interface SatelliteState {
19
19
  /** The groups whose members are ringed and named (`labelSatellites`): the scene tells the page where each is, at every draw. */
20
20
  marked: Set<string>;
21
21
  /** Written at each draw: satellites placed, whether the clock is too fast for the groups, and the milliseconds the last update took. */
22
+ /** Colour each dot by its orbit class. Off by default: a group keeps the one colour it was given. */
23
+ orbitTint: boolean;
22
24
  drawn: {
23
25
  placed: number;
26
+ segments: number;
24
27
  tooFast: boolean;
28
+ dotScale: number;
25
29
  updateMs: number;
26
30
  maxUpdateMs: number;
27
31
  updates: number;
@@ -31,6 +35,30 @@ export interface SatelliteState {
31
35
  export declare const newSatelliteState: () => SatelliteState;
32
36
  /** The most orbits a group may draw all at once, one line each. */
33
37
  export declare const MAX_ORBIT_GROUP = 40;
38
+ /** How long, in milliseconds of wall time, a satellite's place is kept before SGP4 places it again when the clock is too fast to interpolate: about once a second. */
39
+ export declare const PIN_PERIOD_MS = 1000;
40
+ /**
41
+ * How many satellites of a group to pin in a frame that comes `elapsedMs` after the last one, so that each is pinned again about once every {@link PIN_PERIOD_MS} and no frame that comes at a lively pace pins them all: a share of the group in
42
+ * proportion to the time since the last frame (a 60 Hz frame pins about a sixtieth, a 30 Hz one a thirtieth), at least one. A frame that comes a second or more after the last one pins the whole group, as one always did: a picture that
43
+ * is drawn that seldom has no frames for a single batch to hitch.
44
+ *
45
+ * @param count - How many satellites the group has.
46
+ * @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
47
+ * @returns How many to pin now, from 0 (an empty group) to `count`. Internal: not exported from the package.
48
+ */
49
+ export declare const pinSliceSize: (count: number, elapsedMs: number) => number;
50
+ /**
51
+ * The slice of a group to pin in this frame: up to two runs of satellites as `[first, count]` (the second when the slice reaches the end and goes on from the start), and where the next slice begins.
52
+ *
53
+ * @param count - How many satellites the group has.
54
+ * @param next - Where the last slice ended (the first satellite of this one).
55
+ * @param elapsedMs - Wall-clock milliseconds since the last frame that pinned a slice.
56
+ * @returns The runs to pin and the start of the next slice. Internal: not exported from the package.
57
+ */
58
+ export declare function pinPlan(count: number, next: number, elapsedMs: number): {
59
+ runs: [number, number][];
60
+ next: number;
61
+ };
34
62
  /**
35
63
  * Where a satellite is on the screen now: in CSS pixels in the view's box, whether it can be seen (inside the box and not behind the Earth) and how high it is.
36
64
  *
@@ -56,8 +84,10 @@ export interface SatelliteLayer {
56
84
  width: number;
57
85
  height: number;
58
86
  }): SatelliteScreen | null;
59
- /** Place every shown group for `model.time` and the chosen satellite exactly. */
60
- update(time: number, speed: number): void;
87
+ /** Place every shown group for `model.time` and the chosen satellite exactly. `earthPx` is the Earth's radius on the screen, so a dot grows as the view zooms in. */
88
+ update(time: number, speed: number, earthPx?: number): void;
89
+ /** Set the dot size from the Earth's radius on the screen for this frame, after the camera is known. */
90
+ resize(earthPx: number): void;
61
91
  /** The satellite nearest to a point of the view (CSS pixels) within `radius`, if one is in front of the Earth. */
62
92
  pick(x: number, y: number, camera: THREE.Camera, size: {
63
93
  width: number;