@johnmorrisdotca/chikyu-earth 0.46.6 → 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.
@@ -115,7 +115,11 @@ export interface RideOptions {
115
115
  look?: RideLook;
116
116
  /** Face this way as the ride opens (`face`). */
117
117
  face?: RideFace;
118
- /** `outside` (the default, or the element's `ride-viewpoint`) shows the satellite: with `view: "from"` the camera is a little behind and above it (straight above it with `look: "down"`), and a satellite the page has no model for is drawn small from the package's own sketch of its kind. `inside` is the camera at the satellite, as before, and no sketch. A body is always ridden from inside. */
118
+ /** The radius of the ridden satellite's model as a share of the picture's height (0.02 to 1.2), for this ride: the element's `ride-model-share` when not given. Along the way it goes the default is 0.22, above the satellite 0.17 (its size at the lowest height). */
119
+ modelShare?: number;
120
+ /** Where the model's middle sits, as a share of the picture's height from the top (0.5 to 1.4: 0.5 the middle, 1 the bottom edge), for this ride along the way it goes: the element's `ride-model-seat` when not given; 0.86 by default. */
121
+ modelSeat?: number;
122
+ /** `outside` (the default, or the element\'s `ride-viewpoint`) shows the satellite: with `view: "from"` the camera is a little behind and above it (straight above it with `look: "down"`), and a satellite the page has no model for is drawn small from the package's own sketch of its kind. `inside` is the camera at the satellite, as before, and no sketch. A body is always ridden from inside. */
119
123
  viewpoint?: RideViewpoint;
120
124
  /** `distance` (the default, or the element's `ride-model-size`) lets the model of a satellite seen from above shrink as the camera rises and hand over to the ordinary mark, ring and name, between 1,000 and 2,000 km; `fixed` keeps one share of the picture at every height. */
121
125
  modelSize?: RideModelSize;
@@ -164,6 +168,9 @@ type SatelliteStats = {
164
168
  averageUpdateMs: number;
165
169
  updates: number;
166
170
  selectedRing: boolean;
171
+ hoverPath: boolean;
172
+ hoverOpacity: number;
173
+ selectedOpacity: number;
167
174
  };
168
175
  /**
169
176
  * 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.
@@ -438,6 +445,19 @@ export declare class ChikyuSpace extends HTMLElement {
438
445
  */
439
446
  get camera(): CameraMode;
440
447
  set camera(value: CameraMode);
448
+ /**
449
+ * 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.
450
+ * 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.
451
+ */
452
+ get follow(): number;
453
+ set follow(value: number);
454
+ /** Seconds `follow` takes to change. Left out, 0.4. `0` changes at once. */
455
+ get followEase(): number;
456
+ set followEase(value: number);
457
+ /** The longitude, in degrees, under the middle of the view, or null before the first draw. */
458
+ get centreLongitude(): number | null;
459
+ /** The moment of the last draw, in milliseconds, or null before the first. The longitude under the middle belongs to this moment. */
460
+ get shownTime(): number | null;
441
461
  /** 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. */
442
462
  get earthSize(): number;
443
463
  set earthSize(value: number);
@@ -463,6 +483,20 @@ export declare class ChikyuSpace extends HTMLElement {
463
483
  */
464
484
  get bodies(): string;
465
485
  set bodies(value: string);
486
+ /**
487
+ * 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.
488
+ *
489
+ * @example
490
+ * ```ts
491
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
492
+ *
493
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
494
+ * space.dimOccluded = false;
495
+ * console.log(space.dimOccluded);
496
+ * ```
497
+ */
498
+ get dimOccluded(): boolean;
499
+ set dimOccluded(value: boolean);
466
500
  /** 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. */
467
501
  get light(): LightMode;
468
502
  set light(value: LightMode);
@@ -548,6 +582,51 @@ export declare class ChikyuSpace extends HTMLElement {
548
582
  */
549
583
  get rideModelSize(): RideModelSize;
550
584
  set rideModelSize(value: RideModelSize);
585
+ /**
586
+ * 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).
587
+ * 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.
588
+ *
589
+ * @example
590
+ * ```ts
591
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
592
+ *
593
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
594
+ * space.rideModelShare = 0.4;
595
+ * console.log(space.rideModelShare);
596
+ * ```
597
+ */
598
+ get rideModelShare(): number | null;
599
+ set rideModelShare(value: number | null);
600
+ /**
601
+ * 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.
602
+ * 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.
603
+ *
604
+ * @example
605
+ * ```ts
606
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
607
+ *
608
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
609
+ * space.rideModelSeat = 1;
610
+ * console.log(space.rideModelSeat);
611
+ * ```
612
+ */
613
+ get rideModelSeat(): number | null;
614
+ set rideModelSeat(value: number | null);
615
+ /**
616
+ * 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).
617
+ * 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.
618
+ *
619
+ * @example
620
+ * ```ts
621
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
622
+ *
623
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
624
+ * space.rideZoom = 8;
625
+ * console.log(space.rideZoom);
626
+ * ```
627
+ */
628
+ get rideZoom(): number;
629
+ set rideZoom(value: number);
551
630
  /** What the camera is riding along with now, or null. */
552
631
  get riding(): Riding | null;
553
632
  /**
@@ -620,6 +699,15 @@ export declare class ChikyuSpace extends HTMLElement {
620
699
  ok: false;
621
700
  reason: "not-set";
622
701
  };
702
+ /**
703
+ * 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.
704
+ * The colour and the opacity are the custom properties `--chikyu-hover-path` and `--chikyu-hover-path-opacity`.
705
+ */
706
+ get hoverPath(): boolean;
707
+ set hoverPath(value: boolean);
708
+ /** 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. */
709
+ get namesOnHover(): boolean;
710
+ set namesOnHover(value: boolean);
623
711
  /** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
624
712
  selectSatellite(ref: SatelliteRef | null): void;
625
713
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
@@ -647,7 +735,7 @@ export declare class ChikyuSpace extends HTMLElement {
647
735
  get satelliteNames(): Record<number, string>;
648
736
  set satelliteNames(value: Record<number, string>);
649
737
  /**
650
- * 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.
738
+ * 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.
651
739
  */
652
740
  placeSatellite(ref: SatelliteRef): SatelliteScreen | null;
653
741
  /** 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. */
@@ -686,6 +774,10 @@ export declare class ChikyuSpace extends HTMLElement {
686
774
  lost: boolean;
687
775
  gliding: boolean;
688
776
  facing: RideFace | null;
777
+ groundKm: {
778
+ across: number;
779
+ tall: number;
780
+ } | null;
689
781
  };
690
782
  /** The camera as the last draw left it: its place in Earth radii from the Earth's centre, the way it is turned (a unit quaternion, x y z w) and its field of view in degrees. */
691
783
  camera: {
@@ -746,6 +838,9 @@ export declare class ChikyuSpace extends HTMLElement {
746
838
  y: number;
747
839
  shown: boolean;
748
840
  parts: number;
841
+ share: number;
842
+ seat: number;
843
+ weight: number;
749
844
  radiusPx: number;
750
845
  box: {
751
846
  left: number;
@@ -32,6 +32,8 @@ import { MAX_TEXTURE } from "../realistic/tiers.js";
32
32
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
33
33
  import { MAX_ORBIT_GROUP, readStreakMax } from "./satellite-layer.js";
34
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";
35
37
  import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
36
38
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
37
39
  import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
@@ -101,7 +103,18 @@ const TIME_EVENT_MS = 250;
101
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.
102
104
  */
103
105
  const LIMITS = { tiltMax: 90, zoomMin: 0.000001, zoomMax: 2.5 };
104
- 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" };
105
118
  const readCentre = (value) => {
106
119
  if (!value)
107
120
  return null;
@@ -116,7 +129,7 @@ const readTime = (value) => {
116
129
  const ms = Date.parse(value);
117
130
  return Number.isFinite(ms) ? ms : "now";
118
131
  };
119
- 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}`;
120
133
  /**
121
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.
122
135
  *
@@ -161,7 +174,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
161
174
  * ```
162
175
  */
163
176
  export class ChikyuSpace extends HTMLElement {
164
- 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"];
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"];
165
178
  #model = newSpaceModel();
166
179
  /** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
167
180
  #finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
@@ -204,6 +217,10 @@ export class ChikyuSpace extends HTMLElement {
204
217
  #pool = new Map();
205
218
  #places;
206
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;
207
224
  #focusBeforeRide = "Earth";
208
225
  /** The yaw, tilt and zoom from before a satellite group was framed, put back when the focus is cleared. */
209
226
  #focusView = null;
@@ -276,6 +293,8 @@ export class ChikyuSpace extends HTMLElement {
276
293
  this.#placeLayer.set(this.#here.named(this.#placeList));
277
294
  this.#placeLayer.look = readPlaceLook(this.getAttribute("places-look"));
278
295
  this.#placeLayer.grouping = readPlaceGroups(this.getAttribute("place-groups"));
296
+ this.#dimOccluded = this.getAttribute("dim-occluded") !== "off";
297
+ this.#placeLayer.dimOccluded = this.#dimOccluded;
279
298
  this.#cities = createCityHost({
280
299
  root,
281
300
  attribute: (name) => this.getAttribute(name),
@@ -341,6 +360,7 @@ export class ChikyuSpace extends HTMLElement {
341
360
  onLabelError: (error) => this.dispatchEvent(new CustomEvent("chikyu-body-label-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
342
361
  onSatelliteMarks: (marks) => this.#showMarks(marks),
343
362
  onSelected: (place) => this.#placeChosen(place),
363
+ onHover: (place) => this.#hover?.follow(place),
344
364
  onMoving: () => this.#gate?.request(),
345
365
  onRideLost: () => this.#rideLost(),
346
366
  onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
@@ -373,6 +393,20 @@ export class ChikyuSpace extends HTMLElement {
373
393
  this.#last = performance.now();
374
394
  this.#schedule();
375
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();
376
410
  // before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
377
411
  this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
378
412
  this.addEventListener("keydown", this.#faceKey);
@@ -390,12 +424,16 @@ export class ChikyuSpace extends HTMLElement {
390
424
  this.#hands?.unbind();
391
425
  this.#hands = undefined;
392
426
  this.#zoomRange(false);
427
+ this.#hover?.stop();
428
+ this.#hover = undefined;
393
429
  this.removeEventListener("pointerdown", this.#down);
394
430
  this.removeEventListener("wheel", this.#wheel, { capture: true });
395
431
  this.removeEventListener("keydown", this.#faceKey);
396
432
  window.removeEventListener("pointerup", this.#up, true);
397
433
  clearTimeout(this.#timer);
398
434
  this.#timer = undefined;
435
+ clearTimeout(this.#followTimer);
436
+ this.#followTimer = undefined;
399
437
  this.#gate?.cancel();
400
438
  this.#view?.dispose();
401
439
  this.#view = undefined;
@@ -419,6 +457,10 @@ export class ChikyuSpace extends HTMLElement {
419
457
  this.#applyViewpoint();
420
458
  else if (name === "ride-model-size")
421
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();
422
464
  else if (name === "center")
423
465
  this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
424
466
  else if (name === "time")
@@ -435,6 +477,8 @@ export class ChikyuSpace extends HTMLElement {
435
477
  this.bodies = value ?? "";
436
478
  else if (name === "light")
437
479
  this.light = readLight(value);
480
+ else if (name === "dim-occluded")
481
+ this.dimOccluded = value !== "off";
438
482
  else if (name === "camera")
439
483
  this.camera = readCamera(value);
440
484
  else if (name === "cloud-drift") {
@@ -517,6 +561,10 @@ export class ChikyuSpace extends HTMLElement {
517
561
  this.#model.satellites.orbitTint = value === "orbit";
518
562
  this.#gate?.request();
519
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)));
520
568
  else if (name === "satellite-streak-max") {
521
569
  this.#model.satellites.streakMax = readStreakMax(value);
522
570
  this.#gate?.request();
@@ -876,7 +924,7 @@ export class ChikyuSpace extends HTMLElement {
876
924
  /** Lays the places on the picture just drawn, clear of the bodies' names shown beside it. */
877
925
  #drawPlaces(view) {
878
926
  const layer = this.#placeLayer;
879
- 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))
880
928
  return;
881
929
  layer.frame(view, this.#bodyNameBoxes(), this.#marks, this.#model.light === "lit" ? null : subsolarPoint(this.#model.time));
882
930
  this.#notePlacesLost();
@@ -1156,6 +1204,81 @@ export class ChikyuSpace extends HTMLElement {
1156
1204
  this.#model.cameraSpin = null;
1157
1205
  this.#gate?.request();
1158
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
+ }
1159
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. */
1160
1283
  get earthSize() {
1161
1284
  return this.#model.earth.size;
@@ -1241,6 +1364,30 @@ export class ChikyuSpace extends HTMLElement {
1241
1364
  this.#showBodiesCredit();
1242
1365
  this.#gate?.request();
1243
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
+ }
1244
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. */
1245
1392
  get light() {
1246
1393
  return this.#model.light;
@@ -1330,6 +1477,10 @@ export class ChikyuSpace extends HTMLElement {
1330
1477
  const model = this.#model;
1331
1478
  const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1332
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;
1333
1484
  if (target === null) {
1334
1485
  model.ride = null;
1335
1486
  model.rideTurn = 0;
@@ -1521,6 +1672,99 @@ export class ChikyuSpace extends HTMLElement {
1521
1672
  this.#gate?.request();
1522
1673
  this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
1523
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
+ }
1524
1768
  #applyViewpoint() {
1525
1769
  const model = this.#model;
1526
1770
  const ride = model.ride;
@@ -1530,6 +1774,7 @@ export class ChikyuSpace extends HTMLElement {
1530
1774
  const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1531
1775
  const pose = model.pose;
1532
1776
  model.ride = { ...ride, viewpoint: next };
1777
+ model.rideFrame.ms = reduced ? 0 : 400;
1533
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;
1534
1779
  this.#last = performance.now();
1535
1780
  this.#schedule();
@@ -1620,6 +1865,10 @@ export class ChikyuSpace extends HTMLElement {
1620
1865
  this.#restoreFocusView();
1621
1866
  this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
1622
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
+ }
1623
1872
  }
1624
1873
  else {
1625
1874
  const was = groups.get(group);
@@ -1708,6 +1957,29 @@ export class ChikyuSpace extends HTMLElement {
1708
1957
  else
1709
1958
  this.setView(view, true);
1710
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
+ }
1711
1983
  /** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
1712
1984
  selectSatellite(ref) {
1713
1985
  const found = ref ? this.#model.satellites.groups.get(ref.group) : undefined;
@@ -1762,7 +2034,7 @@ export class ChikyuSpace extends HTMLElement {
1762
2034
  this.#gate?.request();
1763
2035
  }
1764
2036
  /**
1765
- * 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.
1766
2038
  */
1767
2039
  placeSatellite(ref) {
1768
2040
  return this.#model.placeSatellite?.(ref) ?? null;
@@ -1802,7 +2074,7 @@ export class ChikyuSpace extends HTMLElement {
1802
2074
  const ridden = this.#model.satellites.modelOver;
1803
2075
  if (ridden)
1804
2076
  marks = marks.filter((m) => !(m.ref.group === ridden.group && m.ref.index === ridden.index));
1805
- 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 }));
1806
2078
  const now = new Map();
1807
2079
  for (const m of marks) {
1808
2080
  const key = `${m.ref.group}:${m.ref.index}`;
@@ -1882,7 +2154,7 @@ export class ChikyuSpace extends HTMLElement {
1882
2154
  time: this.#model.time,
1883
2155
  lookups: this.#model.lookups,
1884
2156
  satellites: this.#satelliteStats(),
1885
- 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 },
1886
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 },
1887
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 },
1888
2160
  meteors: { on: this.#model.meteors.on, strength: this.#model.meteors.strength, ...this.#model.meteors.drawn },
@@ -1914,7 +2186,7 @@ export class ChikyuSpace extends HTMLElement {
1914
2186
  let epochMs = 0;
1915
2187
  for (const group of this.#model.satellites.groups.values())
1916
2188
  epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
1917
- 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 };
1918
2190
  }
1919
2191
  // --- the game clock ----------------------------------------------------------------------------------------------------------------------------
1920
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.