@johnmorrisdotca/chikyu-earth 0.47.0 → 0.49.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.
@@ -52,6 +52,10 @@ export interface ElementSet {
52
52
  COUNTRY_CODE?: string;
53
53
  /** The owner's code, as the other catalogue writes it (the same codes), when the source carries it. */
54
54
  OWNER?: string;
55
+ /** The day it was launched (`2026-11-02`), as CelesTrak's satellite catalogue writes it, when the source carries it: with `estimateFar` a satellite is never placed before it. */
56
+ LAUNCH_DATE?: string;
57
+ /** The day it decayed or re-entered, when it has: with `estimateFar` a satellite is never placed after it. */
58
+ DECAY_DATE?: string;
55
59
  }
56
60
  /**
57
61
  * What a page can tell a reader about one satellite at a moment: its name, its number, how old its elements are, how high and how fast it is.
@@ -76,6 +80,10 @@ export interface SatelliteInfo {
76
80
  epochMs: number;
77
81
  /** Days between the elements' moment and the moment asked about (negative before it). */
78
82
  ageDays: number;
83
+ /** The moment asked about is beyond `maxAgeDays` from the elements, so the place is an estimate (`estimateFar`): where it would be had its orbit not changed. */
84
+ estimated: boolean;
85
+ /** How far the moment asked about is from the elements' own, in days, whichever way (0 or more): for a card that says "estimated, 36 days from its last tracking". */
86
+ estimatedDays: number;
79
87
  /** Height above the mean Earth radius (6371 km) at that moment. */
80
88
  altitudeKm: number;
81
89
  /** Speed against the stars, kilometres a second. */
@@ -162,6 +170,12 @@ export interface Satellites {
162
170
  visible(index: number): boolean;
163
171
  /** How many of them the last `at` or `arc` placed. */
164
172
  readonly placed: number;
173
+ /** Place satellites beyond `maxAgeDays` from their elements as an estimate (`estimateFar`, off by default). Setting it places everything again at the next draw. */
174
+ estimateFar: boolean;
175
+ /** How many satellites the last `at` or `arc` placed as an estimate. */
176
+ readonly estimatedCount: number;
177
+ /** True if satellite `index` was placed by the last `at` or `arc` as an estimate: its moment is beyond `maxAgeDays` from its elements. */
178
+ estimated(index: number): boolean;
165
179
  /** The newest element epoch in the group, in milliseconds since the Unix epoch, or 0 when it is empty. The date of the data. */
166
180
  readonly newestEpochMs: number;
167
181
  /** Red, green and blue, from 0 to 1, of each satellite's orbit class, 3 numbers a satellite. It does not change. */
@@ -0,0 +1,4 @@
1
+ /** Mark a press as taken. */
2
+ export declare const claimPress: (event: Event) => void;
3
+ /** Whether a press was taken by a dot or a path. */
4
+ export declare const pressClaimed: (event: Event) => boolean;
@@ -0,0 +1,8 @@
1
+ // One press means one thing. A press that a satellite's dot or a path took (see space/path-controls.ts) is marked here, and the sky does not pick a star or a figure from it.
2
+ const claimed = new WeakSet();
3
+ /** Mark a press as taken. */
4
+ export const claimPress = (event) => {
5
+ claimed.add(event);
6
+ };
7
+ /** Whether a press was taken by a dot or a path. */
8
+ export const pressClaimed = (event) => claimed.has(event);
package/dist/sky/host.js CHANGED
@@ -1,3 +1,6 @@
1
+ // The names of the brightest stars and the constellations as faint lines, over the sky an element's page draws (hoshi-stars' `sky-labels`, loaded only when an attribute asks for it). The element tells this where the camera looks and what covers the sky at each draw
2
+ // (`frame`); it draws the names and lines on a canvas and a few labels over the picture, never redraws at rest, and lights the figure under the pointer. Stars are directions, so only the camera's turn matters, never its distance.
3
+ import { pressClaimed } from "./claim.js";
1
4
  import { canvasRatio } from "../markers/project.js";
2
5
  import { boxCovered, pathOutside, touches } from "./cover.js";
3
6
  import { cultureLoaders } from "./culture-source.js";
@@ -260,6 +263,8 @@ export function createSkyHost(options) {
260
263
  down = undefined;
261
264
  if (!start || start.id !== event.pointerId)
262
265
  return;
266
+ if (pressClaimed(event))
267
+ return;
263
268
  const here = place(event);
264
269
  // a press that did not move, and was not held: a click or a tap, not the start of a turn
265
270
  if (Math.hypot(here.x - start.x, here.y - start.y) > 6 || event.timeStamp - start.at > 600)
@@ -19,6 +19,8 @@ import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/type
19
19
  import { type PlanetName } from "./ephemeris.ts";
20
20
  import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts";
21
21
  import { type SatelliteOthers } from "./satellite-focus.ts";
22
+ import { type PathStats } from "./path-controls.ts";
23
+ import { type PathHit, type PathRequest, type PathStyle } from "./paths.ts";
22
24
  import { type RideFace, type RideLook, type RideModelSize, type RideViewpoint } from "./ride.ts";
23
25
  import { type ScaleMode } from "./scale.ts";
24
26
  import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type SatellitePainter } from "./scene.ts";
@@ -171,6 +173,7 @@ type SatelliteStats = {
171
173
  hoverPath: boolean;
172
174
  hoverOpacity: number;
173
175
  selectedOpacity: number;
176
+ estimated: number;
174
177
  };
175
178
  /**
176
179
  * 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.
@@ -710,8 +713,94 @@ export declare class ChikyuSpace extends HTMLElement {
710
713
  set namesOnHover(value: boolean);
711
714
  /** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
712
715
  selectSatellite(ref: SatelliteRef | null): void;
716
+ /**
717
+ * Keep placing satellites that are far from their element sets, as an estimate (the attribute `estimate-far`, off unless set; `estimate-far="off"` is off). A satellite is left out when the moment shown is more than `maxAgeDays` (30) from its elements; on, it is carried forward or back by the same SGP4 code
718
+ * instead, and drawn lighter than a dimmed one. **An estimate is where the satellite would be if its orbit had not changed since the elements were taken.** It is worst for low orbits (drag changes them within days, and a manoeuvre moves the satellite along its path, so after weeks the estimate can be far along the orbit from the truth, and a satellite that has re-entered is not there at all) and for a long time away; a high orbit changes slowly and is close for months. Never before a satellite's launch or after its decay when its elements carry `LAUNCH_DATE` and `DECAY_DATE` (else the year of its `OBJECT_ID` is the earliest);
719
+ * one SGP4 cannot carry that far, or brings down below about 120 km, is left out and is not counted as placed. Each estimated satellite is `estimated: true`, with `estimatedDays`, in `placeSatellite`, `satelliteInfo`, `chikyu-satellite-visibility` and `chikyu-satellite-click`, and `stats.satellites.estimated` counts them.
720
+ * It applies to every group, those the page made with `createSatellites(sets, { estimateFar: true })` too.
721
+ *
722
+ * @example
723
+ * ```ts
724
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
725
+ *
726
+ * const farFromToday = (space: ChikyuSpace): void => {
727
+ * space.estimateFar = true;
728
+ * space.addEventListener("chikyu-satellite-click", (event) => console.log((event as CustomEvent).detail.estimated, (event as CustomEvent).detail.estimatedDays));
729
+ * };
730
+ * console.log(typeof farFromToday);
731
+ * ```
732
+ */
733
+ get estimateFar(): boolean;
734
+ set estimateFar(value: boolean);
713
735
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
714
736
  get selectedSatellite(): SatelliteRef | null;
737
+ /**
738
+ * Draw these satellites' orbits at once, each in a look from the table (`pathStyles`), without a satellite being chosen. One draw call for all of them and the chosen satellite's own orbit, and nothing is drawn at rest. At most 16 are kept, the last of the list.
739
+ * `id` is a NORAD catalogue number or `group:index` (`stations:0`); an id that matches no satellite is skipped (`stats.paths.unresolved`). A satellite asked for twice is drawn once, in the later look. `style` is the name of a look (`selected`, `hovered`, `favourite`, `path`, or one of the page's own)
740
+ * or a partial look over `path`. `[]` takes them all away. Where the pointer is on one, `chikyu-path-hover` and `chikyu-path-click` say which (`path-hit`).
741
+ *
742
+ * @param list - The paths, oldest first.
743
+ *
744
+ * @example
745
+ * ```ts
746
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
747
+ *
748
+ * const show = (space: ChikyuSpace): void => space.setPaths([{ id: 25544, style: "favourite" }, { id: "stations:1", style: { color: "#7fdbff", dash: [8, 4] } }]);
749
+ * console.log(typeof show);
750
+ * ```
751
+ */
752
+ setPaths(list: readonly PathRequest[]): void;
753
+ /** The paths in use, as set (the last 16). Setting it is `setPaths`. */
754
+ get paths(): PathRequest[];
755
+ set paths(list: readonly PathRequest[]);
756
+ /**
757
+ * Change the looks the paths are drawn in, by name. Each entry is a partial look over the built-in one of that name (or over `path`, for a name of the page's own); `null` takes the page's entry away. Without `replace` the entries are added to those already set.
758
+ * The built-in looks differ by width and dash as well as colour: `selected` (white, 2 px, solid, also the look of the chosen satellite's own orbit), `hovered` (white, 1.5 px, dashed), `favourite` (amber, 1.75 px, dotted) and `path` (white, 1.5 px, solid).
759
+ * A look is `{ color, width (0.5 to 8 CSS pixels), opacity (0 to 1), dash ([dash, gap] in CSS pixels, or null) }`.
760
+ *
761
+ * @param table - The entries by name.
762
+ * @param replace - `true` to drop the entries set before.
763
+ *
764
+ * @example
765
+ * ```ts
766
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
767
+ *
768
+ * const quiet = (space: ChikyuSpace): void => space.setPathStyles({ selected: { color: "#ffd166", width: 3, dash: null } });
769
+ * console.log(typeof quiet);
770
+ * ```
771
+ */
772
+ setPathStyles(table: Readonly<Record<string, Partial<PathStyle> | null>>, replace?: boolean): void;
773
+ /** The table of looks in use, whole: the built-in ones with the page's own over them. A copy. */
774
+ get pathStyles(): Record<string, PathStyle>;
775
+ set pathStyles(table: Readonly<Record<string, Partial<PathStyle> | null>>);
776
+ /**
777
+ * Draw the chosen satellite's own orbit (the attribute `selected-path`; on unless `off`). Off, `selectSatellite` still rings and names the satellite and a ride still follows it, but no line is drawn: the page draws it, with `setPaths` and the `selected` look, or its own. The look of the line when it is on is the `selected` entry of `pathStyles`.
778
+ */
779
+ get selectedPath(): boolean;
780
+ set selectedPath(value: boolean);
781
+ /**
782
+ * How near, in CSS pixels, the pointer has to be to a path for the pick and hover events to report it (the attribute `path-hit`; 8 when left out, 0 to 40; `0` or `off` turns the test off). A touch is given twice that, and at least 16.
783
+ * The test covers the page's paths and the chosen satellite's own orbit, not the part of an orbit the Earth hides, and a satellite's dot under the pointer comes first. In a ride from a satellite the test is off unless the attribute is set.
784
+ */
785
+ get pathHit(): number;
786
+ set pathHit(value: number);
787
+ /**
788
+ * The path under a point of the element, from the last draw: its id as given, the satellite (`ref`, the same shape as in `chikyu-satellite-click`), the name of its look, the nearest point on it and the distance to it, or `null`.
789
+ *
790
+ * @param x - CSS pixels from the element's left.
791
+ * @param y - CSS pixels from its top.
792
+ * @param radiusPx - How near the point must be, 0 to 200; `path-hit` when left out.
793
+ * @returns The path, or `null` when none is within reach.
794
+ *
795
+ * @example
796
+ * ```ts
797
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
798
+ *
799
+ * const name = (space: ChikyuSpace, x: number, y: number): string => space.pathAt(x, y, 10)?.style ?? "none";
800
+ * console.log(typeof name);
801
+ * ```
802
+ */
803
+ pathAt(x: number, y: number, radiusPx?: number): PathHit | null;
715
804
  /**
716
805
  * Ring and name every satellite of a group (or stop): a ring round each and its name beside it, in the page's language (the ISS, Tiangong and Hubble by their short names, the rest as their elements name them, or as `satelliteNames` says), never over another name, a place's or a ring's.
717
806
  * Names and rings are drawn with the places, only for satellites that are in the picture and not behind the Earth, and nothing is drawn at rest. `chikyu-satellite-visibility` is sent with `detail: { ref, visible }` when a labelled satellite comes into view or goes out of it (not at every frame).
@@ -769,6 +858,8 @@ export declare class ChikyuSpace extends HTMLElement {
769
858
  time: number;
770
859
  lookups: number;
771
860
  satellites: SatelliteStats;
861
+ /** The page's paths: asked for, drawn (with the chosen satellite's own), left out over the cap of 16, unmatched, whether the chosen satellite's own orbit is drawn, draw calls they took at the last draw (0 or 1), the path under the mouse and the `chikyu-path-click` events sent. */
862
+ paths: PathStats;
772
863
  ride: {
773
864
  riding: boolean;
774
865
  lost: boolean;
@@ -32,6 +32,9 @@ 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 { claimPress } from "../sky/claim.js";
36
+ import { bindPaths, emptyPathStats, pointerOf } from "./path-controls.js";
37
+ import { styleTable } from "./paths.js";
35
38
  import { bindSatelliteHover, hoverPathOn, hoverStyleOf, namesOnHover as namesHoverOn } from "./satellite-hover.js";
36
39
  import { clampFollow, retargetFollow } from "./follow.js";
37
40
  import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
@@ -174,7 +177,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
174
177
  * ```
175
178
  */
176
179
  export class ChikyuSpace extends HTMLElement {
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"];
180
+ 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", "selected-path", "path-hit", "estimate-far", "follow", "follow-ease", "dim-occluded", "ride-model-share", "ride-model-seat", "ride-zoom"];
178
181
  #model = newSpaceModel();
179
182
  /** The finer imagery (NASA's tile service), one source while the attributes stay the same. Off unless `tiles-finer="gibs"`. */
180
183
  #finerHold = createFinerHolder(() => new Date(this.#model.time), () => this.#gate?.request());
@@ -219,6 +222,7 @@ export class ChikyuSpace extends HTMLElement {
219
222
  #chosenLabel;
220
223
  /** The name and the faint orbit while the pointer rests on a satellite. */
221
224
  #hover;
225
+ #pathControls;
222
226
  /** The ease of `follow` from one share to the next, if one is running. */
223
227
  #followTimer;
224
228
  #focusBeforeRide = "Earth";
@@ -407,6 +411,15 @@ export class ChikyuSpace extends HTMLElement {
407
411
  style: () => hoverStyleOf(this),
408
412
  });
409
413
  this.#hover.sync();
414
+ this.#pathControls = bindPaths({
415
+ element: this,
416
+ state: this.#model.satellites,
417
+ request: () => this.#gate?.request(),
418
+ pathAt: (x, y, radius) => this.#model.pathAt?.(x, y, radius) ?? null,
419
+ pick: (x, y) => this.#model.pick?.(x, y, 12) ?? null,
420
+ riding: () => this.#model.ride !== null,
421
+ });
422
+ this.#pathControls.sync();
410
423
  // before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
411
424
  this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
412
425
  this.addEventListener("keydown", this.#faceKey);
@@ -426,6 +439,8 @@ export class ChikyuSpace extends HTMLElement {
426
439
  this.#zoomRange(false);
427
440
  this.#hover?.stop();
428
441
  this.#hover = undefined;
442
+ this.#pathControls?.stop();
443
+ this.#pathControls = undefined;
429
444
  this.removeEventListener("pointerdown", this.#down);
430
445
  this.removeEventListener("wheel", this.#wheel, { capture: true });
431
446
  this.removeEventListener("keydown", this.#faceKey);
@@ -563,6 +578,13 @@ export class ChikyuSpace extends HTMLElement {
563
578
  }
564
579
  else if (name === "hover-path" || name === "names-on-hover")
565
580
  this.#hover?.sync();
581
+ else if (name === "selected-path")
582
+ this.#pathControls?.sync();
583
+ else if (name === "estimate-far")
584
+ this.#applyEstimate();
585
+ else if (name === "path-hit") {
586
+ /* read at each press and move */
587
+ }
566
588
  else if (name === "follow")
567
589
  this.#easeFollow(clampFollow(Number(value)));
568
590
  else if (name === "satellite-streak-max") {
@@ -1879,6 +1901,8 @@ export class ChikyuSpace extends HTMLElement {
1879
1901
  orbits: (style.orbits ?? was?.orbits ?? false) && satellites.count <= MAX_ORBIT_GROUP,
1880
1902
  visible: was?.visible ?? true,
1881
1903
  });
1904
+ if (typeof this.hasAttribute === "function" && this.hasAttribute("estimate-far"))
1905
+ satellites.estimateFar = this.estimateFar;
1882
1906
  }
1883
1907
  // a group's index may now be a different satellite, so a cached name for that ref is no longer its name
1884
1908
  this.#satLabelCache.clear();
@@ -1988,11 +2012,144 @@ export class ChikyuSpace extends HTMLElement {
1988
2012
  this.#chosenLabel.hidden = true;
1989
2013
  this.#gate?.request();
1990
2014
  }
2015
+ /**
2016
+ * Keep placing satellites that are far from their element sets, as an estimate (the attribute `estimate-far`, off unless set; `estimate-far="off"` is off). A satellite is left out when the moment shown is more than `maxAgeDays` (30) from its elements; on, it is carried forward or back by the same SGP4 code
2017
+ * instead, and drawn lighter than a dimmed one. **An estimate is where the satellite would be if its orbit had not changed since the elements were taken.** It is worst for low orbits (drag changes them within days, and a manoeuvre moves the satellite along its path, so after weeks the estimate can be far along the orbit from the truth, and a satellite that has re-entered is not there at all) and for a long time away; a high orbit changes slowly and is close for months. Never before a satellite's launch or after its decay when its elements carry `LAUNCH_DATE` and `DECAY_DATE` (else the year of its `OBJECT_ID` is the earliest);
2018
+ * one SGP4 cannot carry that far, or brings down below about 120 km, is left out and is not counted as placed. Each estimated satellite is `estimated: true`, with `estimatedDays`, in `placeSatellite`, `satelliteInfo`, `chikyu-satellite-visibility` and `chikyu-satellite-click`, and `stats.satellites.estimated` counts them.
2019
+ * It applies to every group, those the page made with `createSatellites(sets, { estimateFar: true })` too.
2020
+ *
2021
+ * @example
2022
+ * ```ts
2023
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
2024
+ *
2025
+ * const farFromToday = (space: ChikyuSpace): void => {
2026
+ * space.estimateFar = true;
2027
+ * space.addEventListener("chikyu-satellite-click", (event) => console.log((event as CustomEvent).detail.estimated, (event as CustomEvent).detail.estimatedDays));
2028
+ * };
2029
+ * console.log(typeof farFromToday);
2030
+ * ```
2031
+ */
2032
+ get estimateFar() {
2033
+ return this.hasAttribute("estimate-far") && this.getAttribute("estimate-far") !== "off";
2034
+ }
2035
+ set estimateFar(value) {
2036
+ if (value)
2037
+ this.setAttribute("estimate-far", "");
2038
+ else
2039
+ this.removeAttribute("estimate-far");
2040
+ }
2041
+ /** What an event says of a satellite's place: whether it is an estimate, and how far the moment shown is from its elements' own, in days. */
2042
+ #estimateOf(ref) {
2043
+ const info = this.#model.satellites.groups.get(ref.group)?.satellites.info(ref.index, this.#model.time);
2044
+ return { estimated: info?.estimated ?? false, estimatedDays: info?.estimatedDays ?? 0 };
2045
+ }
2046
+ #applyEstimate() {
2047
+ const on = this.estimateFar;
2048
+ for (const group of this.#model.satellites.groups.values())
2049
+ group.satellites.estimateFar = on;
2050
+ this.#gate?.request();
2051
+ }
1991
2052
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
1992
2053
  get selectedSatellite() {
1993
2054
  const chosen = this.#model.satellites.selected;
1994
2055
  return chosen ? { ...chosen } : null;
1995
2056
  }
2057
+ // --- paths -------------------------------------------------------------------------------------------------------------------------------------
2058
+ /**
2059
+ * Draw these satellites' orbits at once, each in a look from the table (`pathStyles`), without a satellite being chosen. One draw call for all of them and the chosen satellite's own orbit, and nothing is drawn at rest. At most 16 are kept, the last of the list.
2060
+ * `id` is a NORAD catalogue number or `group:index` (`stations:0`); an id that matches no satellite is skipped (`stats.paths.unresolved`). A satellite asked for twice is drawn once, in the later look. `style` is the name of a look (`selected`, `hovered`, `favourite`, `path`, or one of the page's own)
2061
+ * or a partial look over `path`. `[]` takes them all away. Where the pointer is on one, `chikyu-path-hover` and `chikyu-path-click` say which (`path-hit`).
2062
+ *
2063
+ * @param list - The paths, oldest first.
2064
+ *
2065
+ * @example
2066
+ * ```ts
2067
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
2068
+ *
2069
+ * const show = (space: ChikyuSpace): void => space.setPaths([{ id: 25544, style: "favourite" }, { id: "stations:1", style: { color: "#7fdbff", dash: [8, 4] } }]);
2070
+ * console.log(typeof show);
2071
+ * ```
2072
+ */
2073
+ setPaths(list) {
2074
+ this.#pathControls?.setPaths(list);
2075
+ }
2076
+ /** The paths in use, as set (the last 16). Setting it is `setPaths`. */
2077
+ get paths() {
2078
+ return this.#pathControls?.paths ?? [];
2079
+ }
2080
+ set paths(list) {
2081
+ this.setPaths(list);
2082
+ }
2083
+ /**
2084
+ * Change the looks the paths are drawn in, by name. Each entry is a partial look over the built-in one of that name (or over `path`, for a name of the page's own); `null` takes the page's entry away. Without `replace` the entries are added to those already set.
2085
+ * The built-in looks differ by width and dash as well as colour: `selected` (white, 2 px, solid, also the look of the chosen satellite's own orbit), `hovered` (white, 1.5 px, dashed), `favourite` (amber, 1.75 px, dotted) and `path` (white, 1.5 px, solid).
2086
+ * A look is `{ color, width (0.5 to 8 CSS pixels), opacity (0 to 1), dash ([dash, gap] in CSS pixels, or null) }`.
2087
+ *
2088
+ * @param table - The entries by name.
2089
+ * @param replace - `true` to drop the entries set before.
2090
+ *
2091
+ * @example
2092
+ * ```ts
2093
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
2094
+ *
2095
+ * const quiet = (space: ChikyuSpace): void => space.setPathStyles({ selected: { color: "#ffd166", width: 3, dash: null } });
2096
+ * console.log(typeof quiet);
2097
+ * ```
2098
+ */
2099
+ setPathStyles(table, replace = false) {
2100
+ this.#pathControls?.setStyles(table, replace);
2101
+ }
2102
+ /** The table of looks in use, whole: the built-in ones with the page's own over them. A copy. */
2103
+ get pathStyles() {
2104
+ return this.#pathControls?.styles ?? styleTable({});
2105
+ }
2106
+ set pathStyles(table) {
2107
+ this.setPathStyles(table, true);
2108
+ }
2109
+ /**
2110
+ * Draw the chosen satellite's own orbit (the attribute `selected-path`; on unless `off`). Off, `selectSatellite` still rings and names the satellite and a ride still follows it, but no line is drawn: the page draws it, with `setPaths` and the `selected` look, or its own. The look of the line when it is on is the `selected` entry of `pathStyles`.
2111
+ */
2112
+ get selectedPath() {
2113
+ return this.getAttribute("selected-path") !== "off";
2114
+ }
2115
+ set selectedPath(value) {
2116
+ if (value)
2117
+ this.removeAttribute("selected-path");
2118
+ else
2119
+ this.setAttribute("selected-path", "off");
2120
+ }
2121
+ /**
2122
+ * How near, in CSS pixels, the pointer has to be to a path for the pick and hover events to report it (the attribute `path-hit`; 8 when left out, 0 to 40; `0` or `off` turns the test off). A touch is given twice that, and at least 16.
2123
+ * The test covers the page's paths and the chosen satellite's own orbit, not the part of an orbit the Earth hides, and a satellite's dot under the pointer comes first. In a ride from a satellite the test is off unless the attribute is set.
2124
+ */
2125
+ get pathHit() {
2126
+ return this.#pathControls?.hit ?? 8;
2127
+ }
2128
+ set pathHit(value) {
2129
+ if (Number.isFinite(value) && value >= 0)
2130
+ this.setAttribute("path-hit", String(value));
2131
+ else
2132
+ this.removeAttribute("path-hit");
2133
+ }
2134
+ /**
2135
+ * The path under a point of the element, from the last draw: its id as given, the satellite (`ref`, the same shape as in `chikyu-satellite-click`), the name of its look, the nearest point on it and the distance to it, or `null`.
2136
+ *
2137
+ * @param x - CSS pixels from the element's left.
2138
+ * @param y - CSS pixels from its top.
2139
+ * @param radiusPx - How near the point must be, 0 to 200; `path-hit` when left out.
2140
+ * @returns The path, or `null` when none is within reach.
2141
+ *
2142
+ * @example
2143
+ * ```ts
2144
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
2145
+ *
2146
+ * const name = (space: ChikyuSpace, x: number, y: number): string => space.pathAt(x, y, 10)?.style ?? "none";
2147
+ * console.log(typeof name);
2148
+ * ```
2149
+ */
2150
+ pathAt(x, y, radiusPx) {
2151
+ return this.#pathControls?.at(x, y, radiusPx) ?? null;
2152
+ }
1996
2153
  /**
1997
2154
  * Ring and name every satellite of a group (or stop): a ring round each and its name beside it, in the page's language (the ISS, Tiangong and Hubble by their short names, the rest as their elements name them, or as `satelliteNames` says), never over another name, a place's or a ring's.
1998
2155
  * Names and rings are drawn with the places, only for satellites that are in the picture and not behind the Earth, and nothing is drawn at rest. `chikyu-satellite-visibility` is sent with `detail: { ref, visible }` when a labelled satellite comes into view or goes out of it (not at every frame).
@@ -2080,12 +2237,12 @@ export class ChikyuSpace extends HTMLElement {
2080
2237
  const key = `${m.ref.group}:${m.ref.index}`;
2081
2238
  now.set(key, m.visible);
2082
2239
  if (this.#markSeen.get(key) !== m.visible && (this.#markSeen.has(key) || m.visible))
2083
- this.dispatchEvent(new CustomEvent("chikyu-satellite-visibility", { detail: { ref: m.ref, visible: m.visible }, bubbles: true, composed: true }));
2240
+ this.dispatchEvent(new CustomEvent("chikyu-satellite-visibility", { detail: { ref: m.ref, visible: m.visible, ...this.#estimateOf(m.ref) }, bubbles: true, composed: true }));
2084
2241
  }
2085
2242
  for (const [key, was] of this.#markSeen) {
2086
2243
  if (!now.has(key) && was) {
2087
2244
  const [group, index] = key.split(":");
2088
- this.dispatchEvent(new CustomEvent("chikyu-satellite-visibility", { detail: { ref: { group: group, index: Number(index) }, visible: false }, bubbles: true, composed: true }));
2245
+ this.dispatchEvent(new CustomEvent("chikyu-satellite-visibility", { detail: { ref: { group: group, index: Number(index) }, visible: false, ...this.#estimateOf({ group: group, index: Number(index) }) }, bubbles: true, composed: true }));
2089
2246
  }
2090
2247
  }
2091
2248
  this.#markSeen = now;
@@ -2154,6 +2311,7 @@ export class ChikyuSpace extends HTMLElement {
2154
2311
  time: this.#model.time,
2155
2312
  lookups: this.#model.lookups,
2156
2313
  satellites: this.#satelliteStats(),
2314
+ paths: this.#pathControls?.stats() ?? emptyPathStats(),
2157
2315
  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 },
2158
2316
  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 },
2159
2317
  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 },
@@ -2186,7 +2344,7 @@ export class ChikyuSpace extends HTMLElement {
2186
2344
  let epochMs = 0;
2187
2345
  for (const group of this.#model.satellites.groups.values())
2188
2346
  epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
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 };
2347
+ 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, estimated: drawn.estimated };
2190
2348
  }
2191
2349
  // --- the game clock ----------------------------------------------------------------------------------------------------------------------------
2192
2350
  #readSpeed() {
@@ -2315,7 +2473,12 @@ export class ChikyuSpace extends HTMLElement {
2315
2473
  const y = event.clientY - rect.top;
2316
2474
  const satellite = this.#model.pick?.(x, y, 12);
2317
2475
  if (satellite) {
2318
- this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite) }, bubbles: true, composed: true }));
2476
+ claimPress(event);
2477
+ this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite), ...this.#estimateOf(satellite) }, bubbles: true, composed: true }));
2478
+ return;
2479
+ }
2480
+ if (this.#pathControls?.press(x, y, pointerOf(event))) {
2481
+ claimPress(event);
2319
2482
  return;
2320
2483
  }
2321
2484
  if (!this.#places)
@@ -0,0 +1,56 @@
1
+ import type { SatelliteRef } from "../satellites/types.ts";
2
+ import type { SatelliteState } from "./satellite-layer.ts";
3
+ import { MAX_PATHS, type PathHit, type PathRequest, type PathStyle } from "./paths.ts";
4
+ /** The attributes the paths add to an element. */
5
+ export declare const PATH_ATTRIBUTES: readonly ["selected-path", "path-hit"];
6
+ /** What the element hands the paths. */
7
+ export interface PathHost {
8
+ element: HTMLElement;
9
+ state: SatelliteState;
10
+ /** Ask for a draw. */
11
+ request(): void;
12
+ /** The path under a point of the view within a radius, from the last draw. */
13
+ pathAt(x: number, y: number, radius: number): Omit<PathHit, "pointer"> | null;
14
+ /** The satellite whose dot is under a point, which a path never takes a press from. */
15
+ pick(x: number, y: number): SatelliteRef | null;
16
+ /** The view is a ride from a satellite: the hit test is off there unless `path-hit` is set. */
17
+ riding(): boolean;
18
+ }
19
+ export interface PathStats {
20
+ /** Paths the page asked for. */
21
+ requested: number;
22
+ /** Paths in the one draw (the page's and the chosen satellite's own), as of the last draw. */
23
+ drawn: number;
24
+ /** Asked for beyond {@link MAX_PATHS}, so left out (the earliest). */
25
+ dropped: number;
26
+ /** Asked for but matching no satellite, or with no place. */
27
+ unresolved: number;
28
+ /** The chosen satellite's own orbit is drawn. */
29
+ selectedDrawn: boolean;
30
+ /** Draw calls the paths took at the last draw: 0 or 1. */
31
+ draws: number;
32
+ /** The path the mouse is on, by the id given, or `null`. */
33
+ hover: number | string | null;
34
+ /** `chikyu-path-click` events sent so far. */
35
+ hits: number;
36
+ }
37
+ export interface PathControls {
38
+ setPaths(list: readonly PathRequest[]): void;
39
+ readonly paths: PathRequest[];
40
+ setStyles(table: Readonly<Record<string, Partial<PathStyle> | null>>, replace?: boolean): void;
41
+ readonly styles: Record<string, PathStyle>;
42
+ /** Read `selected-path` and `path-hit` again. */
43
+ sync(): void;
44
+ readonly selectedOn: boolean;
45
+ readonly hit: number;
46
+ at(x: number, y: number, radiusPx?: number, pointer?: PathHit["pointer"]): PathHit | null;
47
+ /** A press that was not a drag, at a point of the element: sends `chikyu-path-click` and answers `true` when a path was under it and no dot was. */
48
+ press(x: number, y: number, pointer: PathHit["pointer"]): boolean;
49
+ stats(): PathStats;
50
+ stop(): void;
51
+ }
52
+ export declare const pointerOf: (event: PointerEvent) => PathHit["pointer"];
53
+ export declare function bindPaths(host: PathHost): PathControls;
54
+ export { MAX_PATHS };
55
+ /** The paths' numbers before the element has bound them. */
56
+ export declare const emptyPathStats: () => PathStats;
@@ -0,0 +1,121 @@
1
+ import { capPaths, hitRadius, MAX_PATHS, readPathHit, styleTable } from "./paths.js";
2
+ /** The attributes the paths add to an element. */
3
+ export const PATH_ATTRIBUTES = ["selected-path", "path-hit"];
4
+ export const pointerOf = (event) => (event.pointerType === "touch" ? "touch" : event.pointerType === "pen" ? "pen" : "mouse");
5
+ export function bindPaths(host) {
6
+ const { element, state } = host;
7
+ let hits = 0;
8
+ let hovered = null;
9
+ let queued = false;
10
+ let point = null;
11
+ const radiusFor = (pointer) => {
12
+ if (host.riding() && !element.hasAttribute("path-hit"))
13
+ return 0;
14
+ return hitRadius(readPathHit(element.getAttribute("path-hit")), pointer);
15
+ };
16
+ const at = (x, y, radiusPx, pointer = "mouse") => {
17
+ const radius = radiusPx === undefined ? radiusFor(pointer) : Math.max(0, Math.min(radiusPx, 200));
18
+ const found = host.pathAt(x, y, radius);
19
+ return found ? { ...found, pointer } : null;
20
+ };
21
+ const detail = (hit) => ({ ...hit, ref: { ...hit.ref } });
22
+ const sameHit = (a, b) => (a === null && b === null) || (a !== null && b !== null && a.id === b.id && a.style === b.style && a.ref.group === b.ref.group && a.ref.index === b.ref.index);
23
+ const apply = () => {
24
+ queued = false;
25
+ if (!point)
26
+ return;
27
+ const dot = host.pick(point.x, point.y);
28
+ const hit = dot ? null : at(point.x, point.y, undefined, "mouse");
29
+ if (sameHit(hit, hovered)) {
30
+ hovered = hit;
31
+ return;
32
+ }
33
+ hovered = hit;
34
+ element.dispatchEvent(new CustomEvent("chikyu-path-hover", { detail: hit ? detail(hit) : null, bubbles: true, composed: true }));
35
+ };
36
+ const move = (event) => {
37
+ if (event.pointerType === "touch" || event.buttons !== 0)
38
+ return;
39
+ if (state.paths.info.length === 0 && hovered === null)
40
+ return;
41
+ const rect = element.getBoundingClientRect();
42
+ point = { x: event.clientX - rect.left, y: event.clientY - rect.top };
43
+ if (queued)
44
+ return;
45
+ queued = true;
46
+ element.ownerDocument.defaultView?.requestAnimationFrame(apply);
47
+ };
48
+ const leave = () => {
49
+ point = null;
50
+ if (hovered === null)
51
+ return;
52
+ hovered = null;
53
+ element.dispatchEvent(new CustomEvent("chikyu-path-hover", { detail: null, bubbles: true, composed: true }));
54
+ };
55
+ element.addEventListener("pointermove", move);
56
+ element.addEventListener("pointerleave", leave);
57
+ element.addEventListener("pointercancel", leave);
58
+ return {
59
+ setPaths(list) {
60
+ state.paths.requests = list.filter((one) => one && (typeof one.id === "number" || typeof one.id === "string")).map((one) => ({ id: one.id, ...(one.style === undefined ? {} : { style: typeof one.style === "string" ? one.style : { ...one.style } }) }));
61
+ state.paths.version += 1;
62
+ host.request();
63
+ },
64
+ get paths() {
65
+ return capPaths(state.paths.requests).kept.map((one) => ({ ...one }));
66
+ },
67
+ setStyles(table, replace = false) {
68
+ const next = replace ? {} : { ...state.paths.overrides };
69
+ for (const [name, style] of Object.entries(table)) {
70
+ if (style === null)
71
+ delete next[name];
72
+ else
73
+ next[name] = { ...style };
74
+ }
75
+ state.paths.overrides = next;
76
+ state.paths.version += 1;
77
+ host.request();
78
+ },
79
+ get styles() {
80
+ return styleTable(state.paths.overrides);
81
+ },
82
+ sync() {
83
+ const on = element.getAttribute("selected-path") !== "off";
84
+ if (on === state.paths.selectedOn)
85
+ return;
86
+ state.paths.selectedOn = on;
87
+ state.paths.version += 1;
88
+ host.request();
89
+ },
90
+ get selectedOn() {
91
+ return state.paths.selectedOn;
92
+ },
93
+ get hit() {
94
+ return readPathHit(element.getAttribute("path-hit"));
95
+ },
96
+ at,
97
+ press(x, y, pointer) {
98
+ if (host.pick(x, y))
99
+ return false;
100
+ const hit = at(x, y, undefined, pointer);
101
+ if (!hit)
102
+ return false;
103
+ hits += 1;
104
+ element.dispatchEvent(new CustomEvent("chikyu-path-click", { detail: detail(hit), bubbles: true, composed: true }));
105
+ return true;
106
+ },
107
+ stats() {
108
+ const info = state.paths;
109
+ return { requested: info.requests.length, drawn: state.drawn.pathsDrawn, dropped: info.dropped, unresolved: info.unresolved, selectedDrawn: state.drawn.selectedOpacity > 0, draws: state.drawn.pathDraws, hover: hovered ? hovered.id : null, hits };
110
+ },
111
+ stop() {
112
+ element.removeEventListener("pointermove", move);
113
+ element.removeEventListener("pointerleave", leave);
114
+ element.removeEventListener("pointercancel", leave);
115
+ hovered = null;
116
+ },
117
+ };
118
+ }
119
+ export { MAX_PATHS };
120
+ /** The paths' numbers before the element has bound them. */
121
+ export const emptyPathStats = () => ({ requested: 0, drawn: 0, dropped: 0, unresolved: 0, selectedDrawn: false, draws: 0, hover: null, hits: 0 });