@johnmorrisdotca/chikyu-earth 0.46.5 → 0.47.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.
@@ -15,6 +15,7 @@ import { BORDER_ATTRIBUTES, readBorders } from "../borders/lines.js";
15
15
  import { GRID_ATTRIBUTES, readGrid } from "../grid/lines.js";
16
16
  import { readRoute, routeLeg, routeText } from "../route.js";
17
17
  import { applyRoute } from "../route/layer.js";
18
+ import { BEAM_ATTRIBUTES, readBeam } from "../beam/geometry.js";
18
19
  import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
19
20
  import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
20
21
  import { SEA_NAMES_ATTRIBUTES, readSeaNames } from "../sea-names/geometry.js";
@@ -31,6 +32,8 @@ import { MAX_TEXTURE } from "../realistic/tiers.js";
31
32
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
32
33
  import { MAX_ORBIT_GROUP, readStreakMax } from "./satellite-layer.js";
33
34
  import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForPerspectiveShell } from "./satellite-focus.js";
35
+ import { bindSatelliteHover, hoverPathOn, hoverStyleOf, namesOnHover as namesHoverOn } from "./satellite-hover.js";
36
+ import { clampFollow, retargetFollow } from "./follow.js";
34
37
  import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
35
38
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
36
39
  import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
@@ -100,7 +103,18 @@ const TIME_EVENT_MS = 250;
100
103
  * Riding at a body looking at the Earth, the zoom only narrows the camera's field a little either way: 0.5 to 6.
101
104
  */
102
105
  const LIMITS = { tiltMax: 90, zoomMin: 0.000001, zoomMax: 2.5 };
103
- const RIDE_ZOOM = { "zoom-min": "0.5", "zoom-max": "6" };
106
+ /** A number from an attribute, held between `min` and `max`; `null` when it is absent or not a number. */
107
+ function readFrame(value, min, max) {
108
+ if (value === null || value.trim() === "")
109
+ return null;
110
+ const number = Number(value);
111
+ return Number.isFinite(number) ? Math.min(max, Math.max(min, number)) : null;
112
+ }
113
+ /** An option's number held between `min` and `max`, or `undefined` when it is not given. */
114
+ function clampFrame(value, min, max) {
115
+ return typeof value === "number" && Number.isFinite(value) ? Math.min(max, Math.max(min, value)) : undefined;
116
+ }
117
+ const RIDE_ZOOM = { "zoom-min": "0.5", "zoom-max": "40" };
104
118
  const readCentre = (value) => {
105
119
  if (!value)
106
120
  return null;
@@ -115,7 +129,7 @@ const readTime = (value) => {
115
129
  const ms = Date.parse(value);
116
130
  return Number.isFinite(ms) ? ms : "now";
117
131
  };
118
- const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#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-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
132
+ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:hidden;isolation:isolate}${IMMERSIVE_STYLE}#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-sat{position:absolute;left:0;top:0;font:12px/16px system-ui,-apple-system,sans-serif;color:#fff;white-space:nowrap;text-shadow:0 0 3px #000,0 0 3px #000;will-change:transform;pointer-events:none}.sp-sat[hidden]{display:none}.sp-sat[data-hover]{transition:opacity 180ms linear}@media (prefers-reduced-motion: reduce){.sp-sat[data-hover]{transition:none}}${PLACE_STYLE}${SKY_STYLE}${COUNTRY_NAMES_STYLE}${SEA_NAMES_STYLE}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
119
133
  /**
120
134
  * The `<chikyu-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`, `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`), `labels` and `orbits` (`off` hides them); positions are computed in the browser by astronomy-engine, an optional peer dependency. It draws only when something changes, and nothing while it is out of sight.
121
135
  *
@@ -131,6 +145,9 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
131
145
  * `borders` draws the borders on the Earth's land as thin lines that turn with it, as on `<chikyu-earth-realistic>`: `countries`, `regions` (from the page's `borderData.regions`, once the Earth is
132
146
  * large enough), or both with a bare attribute; `chikyu-borders-unavailable` is sent when the shapes cannot be loaded.
133
147
  *
148
+ * `beam` draws a beam of light from the chosen satellite (the one marked, or the one ridden) down to the ground below it: a soft cone ending in a lit footprint, the circle from which the satellite is above
149
+ * `beam-elevation` degrees (25), with `beam-cells` spot cells inside it (an illustration, never an operator's plan), `beam-cell-size`, `beam-color` and `beam-strength` (the property `beam` and its siblings, and `stats.beam`).
150
+ *
134
151
  * `grid` draws the meridians and parallels on the Earth, and `country-names` names its countries, as on `<chikyu-earth-realistic>`: the names keep clear of the bodies', the places' and the
135
152
  * cities' names and stay on the Earth's disc; `chikyu-country-names-unavailable` is sent when the outlines cannot be loaded.
136
153
  *
@@ -157,7 +174,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
157
174
  * ```
158
175
  */
159
176
  export class ChikyuSpace extends HTMLElement {
160
- 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, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-model-size"];
177
+ 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, ...BEAM_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "satellite-streak-max", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "ride-viewpoint", "ride-model-size", "hover-path", "names-on-hover", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom"];
161
178
  #model = newSpaceModel();
162
179
  /** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
163
180
  #finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
@@ -200,6 +217,10 @@ export class ChikyuSpace extends HTMLElement {
200
217
  #pool = new Map();
201
218
  #places;
202
219
  #chosenLabel;
220
+ /** The name and the faint orbit while the pointer rests on a satellite. */
221
+ #hover;
222
+ /** The ease of `follow` from one share to the next, if one is running. */
223
+ #followTimer;
203
224
  #focusBeforeRide = "Earth";
204
225
  /** The yaw, tilt and zoom from before a satellite group was framed, put back when the focus is cleared. */
205
226
  #focusView = null;
@@ -272,6 +293,8 @@ export class ChikyuSpace extends HTMLElement {
272
293
  this.#placeLayer.set(this.#here.named(this.#placeList));
273
294
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
274
295
  this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
296
+ this.#dimOccluded = this.getAttribute("dim-occluded") !== "off";
297
+ this.#placeLayer.dimOccluded = this.#dimOccluded;
275
298
  this.#cities = createCityHost({
276
299
  root,
277
300
  attribute: (name) => this.getAttribute(name),
@@ -283,6 +306,8 @@ export class ChikyuSpace extends HTMLElement {
283
306
  Object.assign(this.#model.borders, readBorders(this.getAttribute("borders")));
284
307
  this.#model.borders.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-borders-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
285
308
  this.#model.grid.on = readGrid(this.getAttribute("grid"));
309
+ this.#applyBeam();
310
+ this.#model.beam.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-beam-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
286
311
  this.#model.grid.onError = (error) => this.dispatchEvent(new CustomEvent("chikyu-grid-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } }));
287
312
  this.#countries = createCountryHost({
288
313
  root,
@@ -335,6 +360,7 @@ export class ChikyuSpace extends HTMLElement {
335
360
  onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
336
361
  onSatelliteMarks: (marks) => this.#showMarks(marks),
337
362
  onSelected: (place) => this.#placeChosen(place),
363
+ onHover: (place) => this.#hover?.follow(place),
338
364
  onMoving: () => this.#gate?.request(),
339
365
  onRideLost: () => this.#rideLost(),
340
366
  onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
@@ -367,6 +393,20 @@ export class ChikyuSpace extends HTMLElement {
367
393
  this.#last = performance.now();
368
394
  this.#schedule();
369
395
  this.addEventListener("pointerdown", this.#down);
396
+ this.#hover = bindSatelliteHover({
397
+ element: this,
398
+ state: this.#model.satellites,
399
+ pick: (x, y) => this.#model.pick?.(x, y, 12) ?? null,
400
+ place: (ref) => this.placeSatellite(ref),
401
+ name: (ref) => this.satelliteInfo(ref)?.name,
402
+ selected: () => this.selectedSatellite,
403
+ request: () => this.#gate?.request(),
404
+ labelParent: () => this.#labelBox ?? null,
405
+ pathOn: () => hoverPathOn(this.getAttribute("hover-path"), this.getAttribute("names-on-hover")),
406
+ namesOn: () => namesHoverOn(this.getAttribute("names-on-hover")),
407
+ style: () => hoverStyleOf(this),
408
+ });
409
+ this.#hover.sync();
370
410
  // before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
371
411
  this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
372
412
  this.addEventListener("keydown", this.#faceKey);
@@ -384,12 +424,16 @@ export class ChikyuSpace extends HTMLElement {
384
424
  this.#hands?.unbind();
385
425
  this.#hands = undefined;
386
426
  this.#zoomRange(false);
427
+ this.#hover?.stop();
428
+ this.#hover = undefined;
387
429
  this.removeEventListener("pointerdown", this.#down);
388
430
  this.removeEventListener("wheel", this.#wheel, { capture: true });
389
431
  this.removeEventListener("keydown", this.#faceKey);
390
432
  window.removeEventListener("pointerup", this.#up, true);
391
433
  clearTimeout(this.#timer);
392
434
  this.#timer = undefined;
435
+ clearTimeout(this.#followTimer);
436
+ this.#followTimer = undefined;
393
437
  this.#gate?.cancel();
394
438
  this.#view?.dispose();
395
439
  this.#view = undefined;
@@ -413,6 +457,10 @@ export class ChikyuSpace extends HTMLElement {
413
457
  this.#applyViewpoint();
414
458
  else if (name === "ride-model-size")
415
459
  this.#applyModelSize();
460
+ else if (name === "ride-model-share" || name === "ride-model-seat")
461
+ this.#applyFrame();
462
+ else if (name === "ride-zoom")
463
+ this.#applyRideZoom();
416
464
  else if (name === "center")
417
465
  this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
418
466
  else if (name === "time")
@@ -429,6 +477,8 @@ export class ChikyuSpace extends HTMLElement {
429
477
  this.bodies = value ?? "";
430
478
  else if (name === "light")
431
479
  this.light = readLight(value);
480
+ else if (name === "dim-occluded")
481
+ this.dimOccluded = value !== "off";
432
482
  else if (name === "camera")
433
483
  this.camera = readCamera(value);
434
484
  else if (name === "cloud-drift") {
@@ -501,12 +551,20 @@ export class ChikyuSpace extends HTMLElement {
501
551
  this.#model.grid.on = readGrid(value);
502
552
  this.#gate?.request();
503
553
  }
554
+ else if (BEAM_ATTRIBUTES.includes(name)) {
555
+ this.#applyBeam();
556
+ this.#gate?.request();
557
+ }
504
558
  else if (COUNTRY_NAMES_ATTRIBUTES.includes(name))
505
559
  this.#countries?.refresh();
506
560
  else if (name === "satellite-tint") {
507
561
  this.#model.satellites.orbitTint = value === "orbit";
508
562
  this.#gate?.request();
509
563
  }
564
+ else if (name === "hover-path" || name === "names-on-hover")
565
+ this.#hover?.sync();
566
+ else if (name === "follow")
567
+ this.#easeFollow(clampFollow(Number(value)));
510
568
  else if (name === "satellite-streak-max") {
511
569
  this.#model.satellites.streakMax = readStreakMax(value);
512
570
  this.#gate?.request();
@@ -866,7 +924,7 @@ export class ChikyuSpace extends HTMLElement {
866
924
  /** Lays the places on the picture just drawn, clear of the bodies' names shown beside it. */
867
925
  #drawPlaces(view) {
868
926
  const layer = this.#placeLayer;
869
- if (!layer || (this.#placeList.length === 0 && this.#marks.length === 0 && layer.stats.shown === 0 && layer.stats.rings === 0))
927
+ if (!layer || (this.#placeList.length === 0 && this.#marks.length === 0 && layer.stats.shown === 0 && layer.stats.rings === 0 && layer.stats.satelliteNames === 0))
870
928
  return;
871
929
  layer.frame(view, this.#bodyNameBoxes(), this.#marks, this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
872
930
  this.#notePlacesLost();
@@ -976,6 +1034,71 @@ export class ChikyuSpace extends HTMLElement {
976
1034
  this.#citiesStyle = { ...value };
977
1035
  this.#cities?.setStyle(this.#citiesStyle);
978
1036
  }
1037
+ /** Read the beam's attributes into the model. */
1038
+ #applyBeam() {
1039
+ const { on, elevation, cells, cellSize, colour, strength } = readBeam((name) => this.getAttribute(name));
1040
+ Object.assign(this.#model.beam, { on, elevation, cells, cellSize, colour, strength });
1041
+ }
1042
+ /**
1043
+ * Whether a beam of light is drawn from the chosen satellite down to the ground below it (the attribute `beam`, off unless set). The chosen satellite is the one marked with `selectSatellite` or a press,
1044
+ * or the one ridden (Ride along and Ride above, where the camera looks down the beam). The beam is a soft cone, brighter at the satellite and fading towards the ground, ending in a lit ring on the
1045
+ * surface: the footprint, the circle from which the satellite stands above `beamElevation` degrees (25), true to its height. Behind the Earth it is cut off by the limb. It is drawn with the draw that
1046
+ * moves the satellite, and nothing is drawn at rest. Setting it writes the attribute, or takes it away; `stats.beam` says the footprint's radius in kilometres.
1047
+ *
1048
+ * @example
1049
+ * ```ts no-run
1050
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1051
+ *
1052
+ * const space = document.querySelector<ChikyuSpace>("chikyu-space")!;
1053
+ * space.beam = true;
1054
+ * space.beamElevation = 30;
1055
+ * console.log(space.stats.beam.radiusKm);
1056
+ * ```
1057
+ */
1058
+ get beam() {
1059
+ return readBeam((name) => this.getAttribute(name)).on;
1060
+ }
1061
+ set beam(value) {
1062
+ if (value)
1063
+ this.setAttribute("beam", "selected");
1064
+ else
1065
+ this.removeAttribute("beam");
1066
+ }
1067
+ /** The least elevation, in degrees, from which the footprint counts the satellite as seen (the attribute `beam-elevation`, 25). Setting it writes the attribute. */
1068
+ get beamElevation() {
1069
+ return readBeam((name) => this.getAttribute(name)).elevation;
1070
+ }
1071
+ set beamElevation(value) {
1072
+ this.setAttribute("beam-elevation", String(value));
1073
+ }
1074
+ /** How many spot cells are drawn inside the footprint, 0 for none (the attribute `beam-cells`, up to 91). They are an illustration of a satellite that serves the ground in cells, not any operator's plan. */
1075
+ get beamCells() {
1076
+ return readBeam((name) => this.getAttribute(name)).cells;
1077
+ }
1078
+ set beamCells(value) {
1079
+ this.setAttribute("beam-cells", String(value));
1080
+ }
1081
+ /** A spot cell's radius on the ground in kilometres, at most what fits (the attribute `beam-cell-size`, 0 for the fit). */
1082
+ get beamCellSize() {
1083
+ return readBeam((name) => this.getAttribute(name)).cellSize;
1084
+ }
1085
+ set beamCellSize(value) {
1086
+ this.setAttribute("beam-cell-size", String(value));
1087
+ }
1088
+ /** The beam's colour, any CSS colour (the attribute `beam-color`, a pale blue). */
1089
+ get beamColor() {
1090
+ return readBeam((name) => this.getAttribute(name)).colour;
1091
+ }
1092
+ set beamColor(value) {
1093
+ this.setAttribute("beam-color", value);
1094
+ }
1095
+ /** How strong the beam is, from 0 to 1 (the attribute `beam-strength`, 0.6). */
1096
+ get beamStrength() {
1097
+ return readBeam((name) => this.getAttribute(name)).strength;
1098
+ }
1099
+ set beamStrength(value) {
1100
+ this.setAttribute("beam-strength", String(value));
1101
+ }
979
1102
  /** Whether the meridians and parallels are drawn on the Earth (the attribute `grid`). Setting it writes the attribute, or takes it away. */
980
1103
  get grid() {
981
1104
  return readGrid(this.getAttribute("grid"));
@@ -1081,6 +1204,81 @@ export class ChikyuSpace extends HTMLElement {
1081
1204
  this.#model.cameraSpin = null;
1082
1205
  this.#gate?.request();
1083
1206
  }
1207
+ /**
1208
+ * How much of the Earth's turn the space camera takes, from 0 to 1. 0, the default, holds the stars: the Earth turns beneath the camera, which is what `camera="space"` already does, so a page that sets nothing keeps that.
1209
+ * 1 turns with the Earth, so the ground under the middle stays. A value between takes that share of the turn. Changing it does not move the longitude under the middle. `follow-ease` is how many seconds the change takes (0.4 when left out, 0 for none; at once when the reader asks for reduced motion). It asks for no frame of its own once the change has settled, and none while the clock is stopped.
1210
+ */
1211
+ get follow() {
1212
+ return clampFollow(Number(this.getAttribute("follow")));
1213
+ }
1214
+ set follow(value) {
1215
+ const next = clampFollow(value);
1216
+ const text = String(next);
1217
+ if (this.getAttribute("follow") === text)
1218
+ this.#easeFollow(next);
1219
+ else
1220
+ this.setAttribute("follow", text);
1221
+ }
1222
+ /** Seconds `follow` takes to change. Left out, 0.4. `0` changes at once. */
1223
+ get followEase() {
1224
+ const raw = this.getAttribute("follow-ease");
1225
+ if (raw === null || raw === "")
1226
+ return 0.4;
1227
+ const value = Number(raw);
1228
+ return Number.isFinite(value) && value > 0 ? value : 0;
1229
+ }
1230
+ set followEase(value) {
1231
+ this.setAttribute("follow-ease", String(value));
1232
+ }
1233
+ /** The longitude, in degrees, under the middle of the view, or null before the first draw. */
1234
+ get centreLongitude() {
1235
+ const base = this.#model.lookBase;
1236
+ if (!base)
1237
+ return null;
1238
+ return ((((base.lon - this.#model.view.yaw) % 360) + 540) % 360) - 180;
1239
+ }
1240
+ /** The moment of the last draw, in milliseconds, or null before the first. The longitude under the middle belongs to this moment. */
1241
+ get shownTime() {
1242
+ return this.#model.drawn?.frame.ms ?? null;
1243
+ }
1244
+ /** Move `follow` to `next`, keeping the longitude under the middle, and ask for the frames of the ease. */
1245
+ #easeFollow(next) {
1246
+ if (this.#followTimer !== undefined) {
1247
+ clearTimeout(this.#followTimer);
1248
+ this.#followTimer = undefined;
1249
+ }
1250
+ const to = clampFollow(next);
1251
+ const from = this.#model.follow;
1252
+ const seconds = prefersLessMotion() ? 0 : this.followEase;
1253
+ if (!(seconds > 0) || to === from) {
1254
+ this.#applyFollow(to);
1255
+ return;
1256
+ }
1257
+ const started = performance.now();
1258
+ const step = () => {
1259
+ const t = Math.min(1, (performance.now() - started) / (seconds * 1000));
1260
+ const eased = t * t * (3 - 2 * t);
1261
+ this.#applyFollow(from + (to - from) * eased);
1262
+ if (t < 1 && this.isConnected)
1263
+ this.#followTimer = setTimeout(step, 32);
1264
+ else
1265
+ this.#followTimer = undefined;
1266
+ };
1267
+ step();
1268
+ }
1269
+ #applyFollow(value) {
1270
+ const spin = this.#model.drawn?.frame.spin;
1271
+ if (this.#model.camera === "space" && this.#model.cameraSpin !== null && spin !== undefined) {
1272
+ const turned = retargetFollow(this.#model.cameraSpin, spin, this.#model.follow, value, this.#model.view.yaw);
1273
+ this.#model.cameraSpin = turned.anchor;
1274
+ if (turned.yaw !== this.#model.view.yaw) {
1275
+ this.#model.view = { ...this.#model.view, yaw: turned.yaw };
1276
+ this.#controls()?.set({ yaw: turned.yaw, tilt: this.#model.view.tilt, zoom: this.#model.view.zoom }, value === this.follow, "follow");
1277
+ }
1278
+ }
1279
+ this.#model.follow = clampFollow(value);
1280
+ this.#gate?.request();
1281
+ }
1084
1282
  /** The share of the view's shorter side the Earth's disc fills at zoom 1 (the `earth-size` attribute): 0.9 by default, so the atmosphere's glow is never cut at any shape of box. Above 1 the Earth is larger than the view. */
1085
1283
  get earthSize() {
1086
1284
  return this.#model.earth.size;
@@ -1166,6 +1364,30 @@ export class ChikyuSpace extends HTMLElement {
1166
1364
  this.#showBodiesCredit();
1167
1365
  this.#gate?.request();
1168
1366
  }
1367
+ #dimOccluded = true;
1368
+ /**
1369
+ * Dim the name of a satellite the Earth hides, and leave its ring off (the attribute `dim-occluded`). On by default. `off` leaves that name out.
1370
+ *
1371
+ * @example
1372
+ * ```ts
1373
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1374
+ *
1375
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
1376
+ * space.dimOccluded = false;
1377
+ * console.log(space.dimOccluded);
1378
+ * ```
1379
+ */
1380
+ get dimOccluded() {
1381
+ return this.#dimOccluded;
1382
+ }
1383
+ set dimOccluded(value) {
1384
+ if (value === this.#dimOccluded)
1385
+ return;
1386
+ this.#dimOccluded = value;
1387
+ if (this.#placeLayer)
1388
+ this.#placeLayer.dimOccluded = value;
1389
+ this.#gate?.request();
1390
+ }
1169
1391
  /** How the Earth is lit: `sun` (true, the default), `lit` (always lit, as if by daylight from the camera's side, so a ride on the night side is never a black frame) or `boost` (the true terminator, with the night side raised). The Sun, the Moon and the planets keep their true places. */
1170
1392
  get light() {
1171
1393
  return this.#model.light;
@@ -1255,6 +1477,10 @@ export class ChikyuSpace extends HTMLElement {
1255
1477
  const model = this.#model;
1256
1478
  const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1257
1479
  const wasRiding = model.ride !== null;
1480
+ model.rideFrame.share = clampFrame(options.modelShare, 0.02, 1.2) ?? this.rideModelShare;
1481
+ model.rideFrame.seat = clampFrame(options.modelSeat, 0.5, 1.4) ?? this.rideModelSeat;
1482
+ model.rideFrame.ms = reduced ? 0 : 400;
1483
+ model.rideFrame.fresh = true;
1258
1484
  if (target === null) {
1259
1485
  model.ride = null;
1260
1486
  model.rideTurn = 0;
@@ -1446,6 +1672,99 @@ export class ChikyuSpace extends HTMLElement {
1446
1672
  this.#gate?.request();
1447
1673
  this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
1448
1674
  }
1675
+ /**
1676
+ * The radius of the ridden satellite's model as a share of the picture's height, 0.02 to 1.2 (the attribute `ride-model-share`), or `null` for the ride's own: 0.22 along the way it goes, 0.17 above the satellite (its size at the lowest height; `ride-model-size="distance"` still shrinks it as the ride rises).
1677
+ * Set while riding it glides in 0.4 s (at once for a reader who asked for less motion). `stats.followModel.share` is the share in use.
1678
+ *
1679
+ * @example
1680
+ * ```ts
1681
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1682
+ *
1683
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
1684
+ * space.rideModelShare = 0.4;
1685
+ * console.log(space.rideModelShare);
1686
+ * ```
1687
+ */
1688
+ get rideModelShare() {
1689
+ return readFrame(this.getAttribute("ride-model-share"), 0.02, 1.2);
1690
+ }
1691
+ set rideModelShare(value) {
1692
+ if (value === null || !Number.isFinite(value))
1693
+ this.removeAttribute("ride-model-share");
1694
+ else
1695
+ this.setAttribute("ride-model-share", String(value));
1696
+ }
1697
+ /**
1698
+ * Where the middle of the ridden model sits in a ride along the way it goes, as a share of the picture's height from the top, 0.5 to 1.4 (the attribute `ride-model-seat`; 0.5 the middle, 1 the bottom edge), or `null` for the ride's own (0.86). The camera moves to keep the satellite there.
1699
+ * Set while riding it glides in 0.4 s (at once for a reader who asked for less motion). `stats.followModel.seat` is the seat in use.
1700
+ *
1701
+ * @example
1702
+ * ```ts
1703
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1704
+ *
1705
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
1706
+ * space.rideModelSeat = 1;
1707
+ * console.log(space.rideModelSeat);
1708
+ * ```
1709
+ */
1710
+ get rideModelSeat() {
1711
+ return readFrame(this.getAttribute("ride-model-seat"), 0.5, 1.4);
1712
+ }
1713
+ set rideModelSeat(value) {
1714
+ if (value === null || !Number.isFinite(value))
1715
+ this.removeAttribute("ride-model-seat");
1716
+ else
1717
+ this.setAttribute("ride-model-seat", String(value));
1718
+ }
1719
+ #applyFrame() {
1720
+ const frame = this.#model.rideFrame;
1721
+ frame.share = this.rideModelShare;
1722
+ frame.seat = this.rideModelSeat;
1723
+ frame.ms = prefersLessMotion() ? 0 : 400;
1724
+ this.#schedule();
1725
+ this.#gate?.request();
1726
+ }
1727
+ /**
1728
+ * The zoom of a ride, 0.5 to 40 (the attribute `ride-zoom`): the field of view is 60 degrees over it from the satellite, so 40 looks at 1.5 degrees of the ground below. Set while riding the view glides in 0.4 s (at once for a reader who asked for less motion).
1729
+ * It is the shared controls' zoom, so their pinch, wheel and keys move it too. `stats.ride.groundKm` says how many kilometres of ground the picture spans, to stop where the tiles stop being sharp.
1730
+ *
1731
+ * @example
1732
+ * ```ts
1733
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
1734
+ *
1735
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
1736
+ * space.rideZoom = 8;
1737
+ * console.log(space.rideZoom);
1738
+ * ```
1739
+ */
1740
+ get rideZoom() {
1741
+ return this.#model.view.zoom;
1742
+ }
1743
+ set rideZoom(value) {
1744
+ if (Number.isFinite(value))
1745
+ this.setAttribute("ride-zoom", String(value));
1746
+ }
1747
+ #applyRideZoom() {
1748
+ const wanted = readFrame(this.getAttribute("ride-zoom"), 0.5, 40);
1749
+ if (wanted === null)
1750
+ return;
1751
+ const model = this.#model;
1752
+ if (Math.abs(wanted - model.view.zoom) < 1e-9)
1753
+ return;
1754
+ const pose = model.pose;
1755
+ const glide = model.ride !== null && !prefersLessMotion() && pose.valid;
1756
+ if (glide)
1757
+ model.transition = { start: performance.now(), duration: 400, 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 } };
1758
+ const next = { yaw: model.view.yaw, tilt: model.view.tilt, zoom: wanted };
1759
+ const controls = this.#controls();
1760
+ if (controls)
1761
+ controls.set(next, true, "ride");
1762
+ else
1763
+ this.setView(next);
1764
+ this.#last = performance.now();
1765
+ this.#schedule();
1766
+ this.#gate?.request();
1767
+ }
1449
1768
  #applyViewpoint() {
1450
1769
  const model = this.#model;
1451
1770
  const ride = model.ride;
@@ -1455,6 +1774,7 @@ export class ChikyuSpace extends HTMLElement {
1455
1774
  const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1456
1775
  const pose = model.pose;
1457
1776
  model.ride = { ...ride, viewpoint: next };
1777
+ model.rideFrame.ms = reduced ? 0 : 400;
1458
1778
  model.transition = !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;
1459
1779
  this.#last = performance.now();
1460
1780
  this.#schedule();
@@ -1545,6 +1865,10 @@ export class ChikyuSpace extends HTMLElement {
1545
1865
  this.#restoreFocusView();
1546
1866
  this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
1547
1867
  }
1868
+ if (this.#model.satellites.hover.ref?.group === group) {
1869
+ this.#model.satellites.hover.ref = null;
1870
+ this.#model.satellites.hover.fade = 0;
1871
+ }
1548
1872
  }
1549
1873
  else {
1550
1874
  const was = groups.get(group);
@@ -1633,6 +1957,29 @@ export class ChikyuSpace extends HTMLElement {
1633
1957
  else
1634
1958
  this.setView(view, true);
1635
1959
  }
1960
+ /**
1961
+ * Draw a faint orbit while the pointer rests on a satellite. On unless `hover-path="off"`. Left unset, it is on when `names-on-hover` is on.
1962
+ * The colour and the opacity are the custom properties `--chikyu-hover-path` and `--chikyu-hover-path-opacity`.
1963
+ */
1964
+ get hoverPath() {
1965
+ return hoverPathOn(this.getAttribute("hover-path"), this.getAttribute("names-on-hover"));
1966
+ }
1967
+ set hoverPath(value) {
1968
+ if (value)
1969
+ this.setAttribute("hover-path", "");
1970
+ else
1971
+ this.setAttribute("hover-path", "off");
1972
+ }
1973
+ /** Show a satellite's name while the pointer rests on it. On unless `names-on-hover="off"`. A touch does not rest, so it shows nothing. */
1974
+ get namesOnHover() {
1975
+ return namesHoverOn(this.getAttribute("names-on-hover"));
1976
+ }
1977
+ set namesOnHover(value) {
1978
+ if (value)
1979
+ this.removeAttribute("names-on-hover");
1980
+ else
1981
+ this.setAttribute("names-on-hover", "off");
1982
+ }
1636
1983
  /** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
1637
1984
  selectSatellite(ref) {
1638
1985
  const found = ref ? this.#model.satellites.groups.get(ref.group) : undefined;
@@ -1687,7 +2034,7 @@ export class ChikyuSpace extends HTMLElement {
1687
2034
  this.#gate?.request();
1688
2035
  }
1689
2036
  /**
1690
- * Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm, edge, behind }` in CSS pixels from the view's top left. `visible` means it is inside the box, in front of the camera and not behind the Earth. `edge` is `top`, `right`, `bottom` or `left` when the place lies beyond that edge, and `null` when it is inside the box. `behind` is true when it is behind the camera (the picture would mirror it, so `edge` is read from the camera's own axes). `x` and `y` may lie outside the box. `null` when its group is not set or not shown, or it cannot be placed (its elements are too old). It is the picture's own camera maths and its own test for the Earth in the way, so a page that draws its own rings, or a mark on the edge, need not repeat either.
2037
+ * Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm, edge, behind, occluded }` in CSS pixels from the view's top left. `visible` means it is inside the box, in front of the camera and not behind the Earth. `edge` is `top`, `right`, `bottom` or `left` when the place lies beyond that edge, and `null` when it is inside the box. `behind` is true when it is behind the camera (the picture would mirror it, so `edge` is read from the camera's own axes). `occluded` is true when the Earth hides the satellite and false at the limb, in front, and when it is only behind the camera. `x` and `y` may lie outside the box. `null` when its group is not set or not shown, or it cannot be placed (its elements are too old). It is the picture's own camera maths and its own test for the Earth in the way, so a page that draws its own rings, or a mark on the edge, need not repeat either.
1691
2038
  */
1692
2039
  placeSatellite(ref) {
1693
2040
  return this.#model.placeSatellite?.(ref) ?? null;
@@ -1727,7 +2074,7 @@ export class ChikyuSpace extends HTMLElement {
1727
2074
  const ridden = this.#model.satellites.modelOver;
1728
2075
  if (ridden)
1729
2076
  marks = marks.filter((m) => !(m.ref.group === ridden.group && m.ref.index === ridden.index));
1730
- this.#marks = marks.map((m) => ({ id: `${m.ref.group}:${m.ref.index}`, label: this.#satelliteName(m.ref), x: m.x, y: m.y, visible: m.visible }));
2077
+ this.#marks = marks.map((m) => ({ id: `${m.ref.group}:${m.ref.index}`, label: this.#satelliteName(m.ref), x: m.x, y: m.y, visible: m.visible, occluded: m.occluded === true }));
1731
2078
  const now = new Map();
1732
2079
  for (const m of marks) {
1733
2080
  const key = `${m.ref.group}:${m.ref.index}`;
@@ -1807,7 +2154,7 @@ export class ChikyuSpace extends HTMLElement {
1807
2154
  time: this.#model.time,
1808
2155
  lookups: this.#model.lookups,
1809
2156
  satellites: this.#satelliteStats(),
1810
- ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null, facing: this.facing },
2157
+ ride: { riding: this.#model.ride !== null, lost: this.#model.rideLost, gliding: this.#model.transition !== null || this.#model.rideFrame.moving, facing: this.facing, groundKm: this.#model.rideFrame.groundKm },
1811
2158
  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 },
1812
2159
  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, mapped: this.#model.painted.mapped, pending: this.#model.painted.pending },
1813
2160
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
@@ -1820,6 +2167,7 @@ export class ChikyuSpace extends HTMLElement {
1820
2167
  cityNames: this.#cities?.stats ?? { on: false, max: 0, radius: 0, tiers: [], cities: 0, names: 0, renders: 0 },
1821
2168
  borders: { ...this.#model.borders.stats, shown: { ...this.#model.borders.stats.shown }, loaded: [...this.#model.borders.stats.loaded] },
1822
2169
  grid: { ...this.#model.grid.stats },
2170
+ beam: { ...this.#model.beam.stats },
1823
2171
  route: { ...this.#model.route.stats },
1824
2172
  countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
1825
2173
  seaNames: this.#seas?.stats ?? { on: false, radius: 0, names: 0, renders: 0 },
@@ -1838,7 +2186,7 @@ export class ChikyuSpace extends HTMLElement {
1838
2186
  let epochMs = 0;
1839
2187
  for (const group of this.#model.satellites.groups.values())
1840
2188
  epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
1841
- return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, longestStreakPx: drawn.longestStreakPx, streakCapPx: drawn.streakCapPx, weight: drawn.weight, fade: drawn.fade, earthPx: drawn.earthPx, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates, selectedRing: drawn.selectedRing };
2189
+ return { groups: this.#model.satellites.groups.size, placed: drawn.placed, segments: drawn.segments, tooFast: drawn.tooFast, dotScale: drawn.dotScale, longestStreakPx: drawn.longestStreakPx, streakCapPx: drawn.streakCapPx, weight: drawn.weight, fade: drawn.fade, earthPx: drawn.earthPx, epochMs, propagations, lastBatchMs, maxBatchMs, updateMs: drawn.updateMs, maxUpdateMs: drawn.maxUpdateMs, averageUpdateMs: drawn.updates ? drawn.totalMs / drawn.updates : 0, updates: drawn.updates, selectedRing: drawn.selectedRing, hoverPath: drawn.hoverPath, hoverOpacity: drawn.hoverOpacity, selectedOpacity: drawn.selectedOpacity };
1842
2190
  }
1843
2191
  // --- the game clock ----------------------------------------------------------------------------------------------------------------------------
1844
2192
  #readSpeed() {
@@ -90,7 +90,7 @@ export declare const AU_IN_EARTH_RADII: number;
90
90
  */
91
91
  export declare function frameAt(ms: number): Frame;
92
92
  /**
93
- * A frame between two others, `t` from 0 to 1. The spin goes the short way round, so a step under half a turn is right.
93
+ * A frame between two others, `t` from 0 to 1. The spin advances by how far the Earth turns in that time, so a step of a second takes the short way and a step of a day is a full turn.
94
94
  *
95
95
  * @param a - The earlier frame.
96
96
  * @param b - The later frame.
@@ -66,7 +66,7 @@ export function frameAt(ms) {
66
66
  }
67
67
  const lerp3 = (a, b, t) => [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t];
68
68
  /**
69
- * A frame between two others, `t` from 0 to 1. The spin goes the short way round, so a step under half a turn is right.
69
+ * A frame between two others, `t` from 0 to 1. The spin advances by how far the Earth turns in that time, so a step of a second takes the short way and a step of a day is a full turn.
70
70
  *
71
71
  * @param a - The earlier frame.
72
72
  * @param b - The later frame.
@@ -87,7 +87,9 @@ export function blend(a, b, t) {
87
87
  for (const name of PLANETS)
88
88
  planets[name] = lerp3(a.planets[name], b.planets[name], t);
89
89
  let turn = b.spin - a.spin;
90
- turn -= 360 * Math.round(turn / 360);
90
+ // The samples are wrapped to a circle. Pick the turn that matches how far the Earth really turns in the time between them, so a step of a day is a full turn and a step of a second is the short way.
91
+ const expected = ((b.ms - a.ms) / 86_164_090.5) * 360;
92
+ turn += 360 * Math.round((expected - turn) / 360);
91
93
  return { ms: a.ms + (b.ms - a.ms) * t, sun: lerp3(a.sun, b.sun, t), moon: lerp3(a.moon, b.moon, t), planets, spin: a.spin + turn * t };
92
94
  }
93
95
  /**
@@ -0,0 +1,36 @@
1
+ /** Keep a share between 0 and 1. Anything that is not a number is 0. */
2
+ export declare const clampFollow: (value: number) => number;
3
+ /**
4
+ * The sidereal angle the camera uses, in degrees. `anchor` is the Earth's turn when the camera was set, `spin` is the turn now.
5
+ *
6
+ * @param anchor - The Earth's turn, in degrees, remembered for the space camera.
7
+ * @param spin - The Earth's turn now, in degrees.
8
+ * @param follow - 0 holds the stars, 1 turns with the Earth.
9
+ * @returns The angle added to the place the camera looks at.
10
+ */
11
+ export declare const followSpin: (anchor: number, spin: number, follow: number) => number;
12
+ /**
13
+ * The longitude, in degrees, under the middle of the view. The same place before and after a change of `follow`.
14
+ *
15
+ * @param anchor - The Earth's turn remembered for the camera.
16
+ * @param spin - The Earth's turn now.
17
+ * @param follow - The share of that turn the camera takes.
18
+ * @param centreLon - The home longitude.
19
+ * @param yaw - The view's yaw, in degrees.
20
+ * @returns Longitude under the middle, in degrees.
21
+ */
22
+ export declare const groundLongitude: (anchor: number, spin: number, follow: number, centreLon: number, yaw: number) => number;
23
+ /**
24
+ * Move the camera's anchor, and the yaw when the share becomes 1, so the longitude under the middle stays put.
25
+ *
26
+ * @param anchor - The anchor before the change.
27
+ * @param spin - The Earth's turn now.
28
+ * @param from - The share before the change.
29
+ * @param to - The share after the change.
30
+ * @param yaw - The view's yaw before the change.
31
+ * @returns The anchor and yaw to use with `to`.
32
+ */
33
+ export declare function retargetFollow(anchor: number, spin: number, from: number, to: number, yaw: number): {
34
+ anchor: number;
35
+ yaw: number;
36
+ };