@johnmorrisdotca/chikyu-earth 0.46.6 → 0.48.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +3 -3
  3. package/dist/beam/layer.d.ts +1 -1
  4. package/dist/markers/place-layer.d.ts +4 -0
  5. package/dist/markers/place-layer.js +20 -6
  6. package/dist/place/index.d.ts +230 -0
  7. package/dist/place/index.js +183 -0
  8. package/dist/place/land.d.ts +30 -0
  9. package/dist/place/land.js +177 -0
  10. package/dist/place/water.d.ts +15 -0
  11. package/dist/place/water.js +63 -0
  12. package/dist/realistic/earth.d.ts +12 -1
  13. package/dist/realistic/earth.js +17 -1
  14. package/dist/realistic/element-base.d.ts +92 -0
  15. package/dist/realistic/element-base.js +179 -4
  16. package/dist/sky/claim.d.ts +4 -0
  17. package/dist/sky/claim.js +8 -0
  18. package/dist/sky/host.js +5 -0
  19. package/dist/space/element-base.d.ts +168 -2
  20. package/dist/space/element-base.js +402 -8
  21. package/dist/space/ephemeris.d.ts +1 -1
  22. package/dist/space/ephemeris.js +4 -2
  23. package/dist/space/follow.d.ts +36 -0
  24. package/dist/space/follow.js +46 -0
  25. package/dist/space/index.d.ts +1 -1
  26. package/dist/space/index.js +1 -0
  27. package/dist/space/path-controls.d.ts +56 -0
  28. package/dist/space/path-controls.js +121 -0
  29. package/dist/space/path-ribbons.d.ts +25 -0
  30. package/dist/space/path-ribbons.js +165 -0
  31. package/dist/space/paths.d.ts +119 -0
  32. package/dist/space/paths.js +163 -0
  33. package/dist/space/ride.d.ts +3 -2
  34. package/dist/space/ride.js +6 -4
  35. package/dist/space/satellite-hover.d.ts +47 -0
  36. package/dist/space/satellite-hover.js +183 -0
  37. package/dist/space/satellite-layer.d.ts +83 -2
  38. package/dist/space/satellite-layer.js +231 -52
  39. package/dist/space/satellite-model.d.ts +2 -1
  40. package/dist/space/satellite-model.js +4 -3
  41. package/dist/space/scene.d.ts +41 -0
  42. package/dist/space/scene.js +82 -13
  43. package/package.json +6 -1
@@ -10,6 +10,10 @@ import { cameraCentre, createEarthItem, discRadius, lookAt, newModel } from "./e
10
10
  import { createPaintState, paintedGround, paintedPeriod } from "../paint/buffer.js";
11
11
  import { MAX_ORBIT_GROUP, readStreakMax } from "../space/satellite-layer.js";
12
12
  import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForOrthographicShell } from "../space/satellite-focus.js";
13
+ import { claimPress } from "../sky/claim.js";
14
+ import { bindPaths, emptyPathStats, pointerOf } from "../space/path-controls.js";
15
+ import { styleTable } from "../space/paths.js";
16
+ import { bindSatelliteHover, hoverPathOn, hoverStyleOf, namesOnHover as namesHoverOn } from "../space/satellite-hover.js";
13
17
  import { readMeteorStrength } from "../meteors/strength.js";
14
18
  import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/note.js";
15
19
  import { createDoorHost } from "../door/host.js";
@@ -39,7 +43,7 @@ import { setSharedRenderer, setThreeLoader, takeRenderer } from "./shared.js";
39
43
  export { setSharedRenderer, setThreeLoader };
40
44
  import { MAX_TEXTURE, TIERS } from "./tiers.js";
41
45
  import { mayWriteZoomMax, raisedZoomMax } from "./zoom-reach.js";
42
- const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events:none}" + PLACE_STYLE + SKY_STYLE + COUNTRY_NAMES_STYLE + SEA_NAMES_STYLE + CITY_NAMES_STYLE + METEOR_NOTE_STYLE + NOTES_STYLE;
46
+ const STYLE = ":host{display:block;aspect-ratio:1/1;position:relative;isolation:isolate}" + IMMERSIVE_STYLE + "#stage,#overlay{position:absolute;inset:0}#overlay{pointer-events: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;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;
43
47
  const RAD = Math.PI / 180;
44
48
  /** The Sun and the clouds are re-placed this often at real time: 15 degrees an hour is 0.25 degree a minute. */
45
49
  const LIVE_TICK_MS = 60_000;
@@ -161,7 +165,7 @@ export const readTime = (value) => {
161
165
  * ```
162
166
  */
163
167
  export class ChikyuEarthRealistic extends HTMLElement {
164
- static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "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", "satellite-tint", "satellite-streak-max"];
168
+ static observedAttributes = ["cloud-drift", "center", "time", "speed", "clouds", "lights", "light", "live-seconds", "tiles", "tiles-finer", "tiles-finer-layer", "tiles-finer-date", "tiles-finer-timeout", "data", "camera", "immersive", "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", "satellite-tint", "satellite-streak-max", "hover-path", "names-on-hover", "selected-path", "path-hit"];
165
169
  #model = newModel();
166
170
  #paint = createPaintState();
167
171
  #mode = "now";
@@ -208,6 +212,9 @@ export class ChikyuEarthRealistic extends HTMLElement {
208
212
  #hands;
209
213
  /** The view from before a satellite group was framed, put back when the focus is cleared. */
210
214
  #focusView = null;
215
+ /** The name and the faint orbit while the pointer rests on a satellite. */
216
+ #hover;
217
+ #pathControls;
211
218
  #reach = null;
212
219
  /** The page has set a `speed` since the element came into the page: for a reader who prefers reduced motion, that is the Play that lets meteors start. */
213
220
  #played = false;
@@ -358,6 +365,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
358
365
  },
359
366
  onPlaceRings: (drawn) => this.#ringsDrawn(drawn),
360
367
  onSatellitesError: (error) => this.dispatchEvent(new CustomEvent("chikyu-satellites-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
368
+ onHover: (place) => this.#hover?.follow(place),
361
369
  paint: {
362
370
  data: () => this.#paint.data,
363
371
  width: this.#paint.width,
@@ -389,10 +397,37 @@ export class ChikyuEarthRealistic extends HTMLElement {
389
397
  // before the shared hands (which hear it after this): a plain wheel in an immersive view zooms
390
398
  this.addEventListener("wheel", this.#wheel, { capture: true, passive: false });
391
399
  this.#hands = carryControls(this, { initial: this.#model.view, limits: LIMITS, onChange: (state, info) => this.setView(state, info.final) });
400
+ this.#hover = bindSatelliteHover({
401
+ element: this,
402
+ state: this.#model.satellites,
403
+ pick: (x, y) => this.#model.pick?.(x, y, 12) ?? null,
404
+ place: (ref) => this.placeSatellite(ref),
405
+ name: (ref) => this.satelliteInfo(ref)?.name,
406
+ selected: () => this.selectedSatellite,
407
+ request: () => this.#gate?.soon(),
408
+ labelParent: () => this.#overlay ?? null,
409
+ pathOn: () => hoverPathOn(this.getAttribute("hover-path"), this.getAttribute("names-on-hover")),
410
+ namesOn: () => namesHoverOn(this.getAttribute("names-on-hover")),
411
+ style: () => hoverStyleOf(this),
412
+ });
413
+ this.#hover.sync();
414
+ this.#pathControls = bindPaths({
415
+ element: this,
416
+ state: this.#model.satellites,
417
+ request: () => this.#gate?.soon(),
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: () => false,
421
+ });
422
+ this.#pathControls.sync();
392
423
  this.#startTick();
393
424
  document.addEventListener("visibilitychange", this.#onVisible);
394
425
  }
395
426
  disconnectedCallback() {
427
+ this.#hover?.stop();
428
+ this.#hover = undefined;
429
+ this.#pathControls?.stop();
430
+ this.#pathControls = undefined;
396
431
  this.removeEventListener("pointerdown", this.#take);
397
432
  this.removeEventListener("pointerdown", this.#down);
398
433
  this.removeEventListener("wheel", this.#wheel, { capture: true });
@@ -519,6 +554,11 @@ export class ChikyuEarthRealistic extends HTMLElement {
519
554
  this.#model.satellites.orbitTint = value === "orbit";
520
555
  this.#gate?.soon();
521
556
  }
557
+ else if (name === "hover-path" || name === "names-on-hover")
558
+ this.#hover?.sync();
559
+ else if (name === "selected-path")
560
+ this.#pathControls?.sync();
561
+ else if (name === "path-hit") { /* read at each press and move */ }
522
562
  else if (name === "satellite-streak-max") {
523
563
  this.#model.satellites.streakMax = readStreakMax(value);
524
564
  this.#gate?.soon();
@@ -1177,6 +1217,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
1177
1217
  state: this.#state,
1178
1218
  tiers: { ...this.#tiers },
1179
1219
  satellites: this.#satelliteStats(),
1220
+ paths: this.#pathControls?.stats() ?? emptyPathStats(),
1180
1221
  tiles: this.#model.tiles?.stats ?? { ready: false, level: null, held: 0, shown: 0, loading: 0, failed: 0, requested: 0, heldBytes: 0, refused: 0, used: {}, finer: null, fading: false },
1181
1222
  draws: stats?.draws ?? 0,
1182
1223
  contexts: stats?.contexts ?? 0,
@@ -1286,6 +1327,10 @@ export class ChikyuEarthRealistic extends HTMLElement {
1286
1327
  this.#restoreFocusView();
1287
1328
  this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
1288
1329
  }
1330
+ if (this.#model.satellites.hover.ref?.group === group) {
1331
+ this.#model.satellites.hover.ref = null;
1332
+ this.#model.satellites.hover.fade = 0;
1333
+ }
1289
1334
  }
1290
1335
  else {
1291
1336
  const was = groups.get(group);
@@ -1371,17 +1416,142 @@ export class ChikyuEarthRealistic extends HTMLElement {
1371
1416
  else
1372
1417
  this.setView(view, true);
1373
1418
  }
1419
+ /**
1420
+ * 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.
1421
+ * The colour and the opacity are the custom properties `--chikyu-hover-path` and `--chikyu-hover-path-opacity`.
1422
+ */
1423
+ get hoverPath() {
1424
+ return hoverPathOn(this.getAttribute("hover-path"), this.getAttribute("names-on-hover"));
1425
+ }
1426
+ set hoverPath(value) {
1427
+ if (value)
1428
+ this.setAttribute("hover-path", "");
1429
+ else
1430
+ this.setAttribute("hover-path", "off");
1431
+ }
1432
+ /** 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. */
1433
+ get namesOnHover() {
1434
+ return namesHoverOn(this.getAttribute("names-on-hover"));
1435
+ }
1436
+ set namesOnHover(value) {
1437
+ if (value)
1438
+ this.removeAttribute("names-on-hover");
1439
+ else
1440
+ this.setAttribute("names-on-hover", "off");
1441
+ }
1374
1442
  /** Mark one satellite: a larger ring round it and its orbit drawn. `null` lets it go. */
1375
1443
  selectSatellite(ref) {
1376
1444
  const found = ref ? this.#model.satellites.groups.get(ref.group) : undefined;
1377
1445
  this.#model.satellites.selected = ref && found && ref.index >= 0 && ref.index < found.satellites.count ? { group: ref.group, index: ref.index } : null;
1378
1446
  this.#gate?.soon();
1379
1447
  }
1448
+ /**
1449
+ * Where a satellite is on the screen as of the last draw: `{ x, y, visible, heightKm }` in CSS pixels from the view's top left, `visible` meaning it is inside the box and not behind the Earth. `null` when its group is not set or not shown, it cannot be placed, or it is behind the camera.
1450
+ */
1451
+ placeSatellite(ref) {
1452
+ return this.#model.placeSatellite?.(ref) ?? null;
1453
+ }
1380
1454
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
1381
1455
  get selectedSatellite() {
1382
1456
  const chosen = this.#model.satellites.selected;
1383
1457
  return chosen ? { ...chosen } : null;
1384
1458
  }
1459
+ // --- paths -------------------------------------------------------------------------------------------------------------------------------------
1460
+ /**
1461
+ * 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.
1462
+ * `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)
1463
+ * 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`).
1464
+ *
1465
+ * @param list - The paths, oldest first.
1466
+ *
1467
+ * @example
1468
+ * ```ts
1469
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
1470
+ *
1471
+ * const show = (space: ChikyuSpace): void => space.setPaths([{ id: 25544, style: "favourite" }, { id: "stations:1", style: { color: "#7fdbff", dash: [8, 4] } }]);
1472
+ * console.log(typeof show);
1473
+ * ```
1474
+ */
1475
+ setPaths(list) {
1476
+ this.#pathControls?.setPaths(list);
1477
+ }
1478
+ /** The paths in use, as set (the last 16). Setting it is `setPaths`. */
1479
+ get paths() {
1480
+ return this.#pathControls?.paths ?? [];
1481
+ }
1482
+ set paths(list) {
1483
+ this.setPaths(list);
1484
+ }
1485
+ /**
1486
+ * 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.
1487
+ * 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).
1488
+ * A look is `{ color, width (0.5 to 8 CSS pixels), opacity (0 to 1), dash ([dash, gap] in CSS pixels, or null) }`.
1489
+ *
1490
+ * @param table - The entries by name.
1491
+ * @param replace - `true` to drop the entries set before.
1492
+ *
1493
+ * @example
1494
+ * ```ts
1495
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
1496
+ *
1497
+ * const quiet = (space: ChikyuSpace): void => space.setPathStyles({ selected: { color: "#ffd166", width: 3, dash: null } });
1498
+ * console.log(typeof quiet);
1499
+ * ```
1500
+ */
1501
+ setPathStyles(table, replace = false) {
1502
+ this.#pathControls?.setStyles(table, replace);
1503
+ }
1504
+ /** The table of looks in use, whole: the built-in ones with the page's own over them. A copy. */
1505
+ get pathStyles() {
1506
+ return this.#pathControls?.styles ?? styleTable({});
1507
+ }
1508
+ set pathStyles(table) {
1509
+ this.setPathStyles(table, true);
1510
+ }
1511
+ /**
1512
+ * 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`.
1513
+ */
1514
+ get selectedPath() {
1515
+ return this.getAttribute("selected-path") !== "off";
1516
+ }
1517
+ set selectedPath(value) {
1518
+ if (value)
1519
+ this.removeAttribute("selected-path");
1520
+ else
1521
+ this.setAttribute("selected-path", "off");
1522
+ }
1523
+ /**
1524
+ * 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.
1525
+ * 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.
1526
+ */
1527
+ get pathHit() {
1528
+ return this.#pathControls?.hit ?? 8;
1529
+ }
1530
+ set pathHit(value) {
1531
+ if (Number.isFinite(value) && value >= 0)
1532
+ this.setAttribute("path-hit", String(value));
1533
+ else
1534
+ this.removeAttribute("path-hit");
1535
+ }
1536
+ /**
1537
+ * 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`.
1538
+ *
1539
+ * @param x - CSS pixels from the element's left.
1540
+ * @param y - CSS pixels from its top.
1541
+ * @param radiusPx - How near the point must be, 0 to 200; `path-hit` when left out.
1542
+ * @returns The path, or `null` when none is within reach.
1543
+ *
1544
+ * @example
1545
+ * ```ts
1546
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
1547
+ *
1548
+ * const name = (space: ChikyuSpace, x: number, y: number): string => space.pathAt(x, y, 10)?.style ?? "none";
1549
+ * console.log(typeof name);
1550
+ * ```
1551
+ */
1552
+ pathAt(x, y, radiusPx) {
1553
+ return this.#pathControls?.at(x, y, radiusPx) ?? null;
1554
+ }
1385
1555
  /** 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. */
1386
1556
  satelliteInfo(ref) {
1387
1557
  return this.#model.satellites.groups.get(ref.group)?.satellites.info(ref.index, this.#model.time);
@@ -1399,7 +1569,7 @@ export class ChikyuEarthRealistic extends HTMLElement {
1399
1569
  let epochMs = 0;
1400
1570
  for (const group of this.#model.satellites.groups.values())
1401
1571
  epochMs = Math.max(epochMs, group.satellites.newestEpochMs);
1402
- 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 };
1572
+ 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 };
1403
1573
  }
1404
1574
  // A press that does not turn the view (under 6 pixels) on a satellite tells the page, which chooses it with `selectSatellite` if it likes.
1405
1575
  #downX = 0;
@@ -1416,8 +1586,13 @@ export class ChikyuEarthRealistic extends HTMLElement {
1416
1586
  return;
1417
1587
  const rect = this.getBoundingClientRect();
1418
1588
  const satellite = this.#model.pick?.(event.clientX - rect.left, event.clientY - rect.top, 12);
1419
- if (satellite)
1589
+ if (satellite) {
1590
+ claimPress(event);
1420
1591
  this.dispatchEvent(new CustomEvent("chikyu-satellite-click", { detail: { ...satellite, info: this.satelliteInfo(satellite) }, bubbles: true, composed: true }));
1592
+ return;
1593
+ }
1594
+ if (this.#pathControls?.press(event.clientX - rect.left, event.clientY - rect.top, pointerOf(event)))
1595
+ claimPress(event);
1421
1596
  };
1422
1597
  #wheel = (event) => immersiveWheel(this, event);
1423
1598
  /** The view as it is (for a page that wants to read it back). */
@@ -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";
@@ -115,7 +117,11 @@ export interface RideOptions {
115
117
  look?: RideLook;
116
118
  /** Face this way as the ride opens (`face`). */
117
119
  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. */
120
+ /** 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). */
121
+ modelShare?: number;
122
+ /** 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. */
123
+ modelSeat?: number;
124
+ /** `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
125
  viewpoint?: RideViewpoint;
120
126
  /** `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
127
  modelSize?: RideModelSize;
@@ -164,6 +170,9 @@ type SatelliteStats = {
164
170
  averageUpdateMs: number;
165
171
  updates: number;
166
172
  selectedRing: boolean;
173
+ hoverPath: boolean;
174
+ hoverOpacity: number;
175
+ selectedOpacity: number;
167
176
  };
168
177
  /**
169
178
  * 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 +447,19 @@ export declare class ChikyuSpace extends HTMLElement {
438
447
  */
439
448
  get camera(): CameraMode;
440
449
  set camera(value: CameraMode);
450
+ /**
451
+ * 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.
452
+ * 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.
453
+ */
454
+ get follow(): number;
455
+ set follow(value: number);
456
+ /** Seconds `follow` takes to change. Left out, 0.4. `0` changes at once. */
457
+ get followEase(): number;
458
+ set followEase(value: number);
459
+ /** The longitude, in degrees, under the middle of the view, or null before the first draw. */
460
+ get centreLongitude(): number | null;
461
+ /** The moment of the last draw, in milliseconds, or null before the first. The longitude under the middle belongs to this moment. */
462
+ get shownTime(): number | null;
441
463
  /** 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
464
  get earthSize(): number;
443
465
  set earthSize(value: number);
@@ -463,6 +485,20 @@ export declare class ChikyuSpace extends HTMLElement {
463
485
  */
464
486
  get bodies(): string;
465
487
  set bodies(value: string);
488
+ /**
489
+ * 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.
490
+ *
491
+ * @example
492
+ * ```ts
493
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
494
+ *
495
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
496
+ * space.dimOccluded = false;
497
+ * console.log(space.dimOccluded);
498
+ * ```
499
+ */
500
+ get dimOccluded(): boolean;
501
+ set dimOccluded(value: boolean);
466
502
  /** 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
503
  get light(): LightMode;
468
504
  set light(value: LightMode);
@@ -548,6 +584,51 @@ export declare class ChikyuSpace extends HTMLElement {
548
584
  */
549
585
  get rideModelSize(): RideModelSize;
550
586
  set rideModelSize(value: RideModelSize);
587
+ /**
588
+ * 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).
589
+ * 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.
590
+ *
591
+ * @example
592
+ * ```ts
593
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
594
+ *
595
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
596
+ * space.rideModelShare = 0.4;
597
+ * console.log(space.rideModelShare);
598
+ * ```
599
+ */
600
+ get rideModelShare(): number | null;
601
+ set rideModelShare(value: number | null);
602
+ /**
603
+ * 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.
604
+ * 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.
605
+ *
606
+ * @example
607
+ * ```ts
608
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
609
+ *
610
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
611
+ * space.rideModelSeat = 1;
612
+ * console.log(space.rideModelSeat);
613
+ * ```
614
+ */
615
+ get rideModelSeat(): number | null;
616
+ set rideModelSeat(value: number | null);
617
+ /**
618
+ * 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).
619
+ * 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.
620
+ *
621
+ * @example
622
+ * ```ts
623
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
624
+ *
625
+ * const space = document.createElement("chikyu-space") as ChikyuSpace;
626
+ * space.rideZoom = 8;
627
+ * console.log(space.rideZoom);
628
+ * ```
629
+ */
630
+ get rideZoom(): number;
631
+ set rideZoom(value: number);
551
632
  /** What the camera is riding along with now, or null. */
552
633
  get riding(): Riding | null;
553
634
  /**
@@ -620,10 +701,86 @@ export declare class ChikyuSpace extends HTMLElement {
620
701
  ok: false;
621
702
  reason: "not-set";
622
703
  };
704
+ /**
705
+ * 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.
706
+ * The colour and the opacity are the custom properties `--chikyu-hover-path` and `--chikyu-hover-path-opacity`.
707
+ */
708
+ get hoverPath(): boolean;
709
+ set hoverPath(value: boolean);
710
+ /** 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. */
711
+ get namesOnHover(): boolean;
712
+ set namesOnHover(value: boolean);
623
713
  /** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
624
714
  selectSatellite(ref: SatelliteRef | null): void;
625
715
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
626
716
  get selectedSatellite(): SatelliteRef | null;
717
+ /**
718
+ * 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.
719
+ * `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)
720
+ * 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`).
721
+ *
722
+ * @param list - The paths, oldest first.
723
+ *
724
+ * @example
725
+ * ```ts
726
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
727
+ *
728
+ * const show = (space: ChikyuSpace): void => space.setPaths([{ id: 25544, style: "favourite" }, { id: "stations:1", style: { color: "#7fdbff", dash: [8, 4] } }]);
729
+ * console.log(typeof show);
730
+ * ```
731
+ */
732
+ setPaths(list: readonly PathRequest[]): void;
733
+ /** The paths in use, as set (the last 16). Setting it is `setPaths`. */
734
+ get paths(): PathRequest[];
735
+ set paths(list: readonly PathRequest[]);
736
+ /**
737
+ * 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.
738
+ * 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).
739
+ * A look is `{ color, width (0.5 to 8 CSS pixels), opacity (0 to 1), dash ([dash, gap] in CSS pixels, or null) }`.
740
+ *
741
+ * @param table - The entries by name.
742
+ * @param replace - `true` to drop the entries set before.
743
+ *
744
+ * @example
745
+ * ```ts
746
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
747
+ *
748
+ * const quiet = (space: ChikyuSpace): void => space.setPathStyles({ selected: { color: "#ffd166", width: 3, dash: null } });
749
+ * console.log(typeof quiet);
750
+ * ```
751
+ */
752
+ setPathStyles(table: Readonly<Record<string, Partial<PathStyle> | null>>, replace?: boolean): void;
753
+ /** The table of looks in use, whole: the built-in ones with the page's own over them. A copy. */
754
+ get pathStyles(): Record<string, PathStyle>;
755
+ set pathStyles(table: Readonly<Record<string, Partial<PathStyle> | null>>);
756
+ /**
757
+ * 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`.
758
+ */
759
+ get selectedPath(): boolean;
760
+ set selectedPath(value: boolean);
761
+ /**
762
+ * 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.
763
+ * 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.
764
+ */
765
+ get pathHit(): number;
766
+ set pathHit(value: number);
767
+ /**
768
+ * 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`.
769
+ *
770
+ * @param x - CSS pixels from the element's left.
771
+ * @param y - CSS pixels from its top.
772
+ * @param radiusPx - How near the point must be, 0 to 200; `path-hit` when left out.
773
+ * @returns The path, or `null` when none is within reach.
774
+ *
775
+ * @example
776
+ * ```ts
777
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space";
778
+ *
779
+ * const name = (space: ChikyuSpace, x: number, y: number): string => space.pathAt(x, y, 10)?.style ?? "none";
780
+ * console.log(typeof name);
781
+ * ```
782
+ */
783
+ pathAt(x: number, y: number, radiusPx?: number): PathHit | null;
627
784
  /**
628
785
  * 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.
629
786
  * 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).
@@ -647,7 +804,7 @@ export declare class ChikyuSpace extends HTMLElement {
647
804
  get satelliteNames(): Record<number, string>;
648
805
  set satelliteNames(value: Record<number, string>);
649
806
  /**
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.
807
+ * 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
808
  */
652
809
  placeSatellite(ref: SatelliteRef): SatelliteScreen | null;
653
810
  /** 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. */
@@ -681,11 +838,17 @@ export declare class ChikyuSpace extends HTMLElement {
681
838
  time: number;
682
839
  lookups: number;
683
840
  satellites: SatelliteStats;
841
+ /** 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. */
842
+ paths: PathStats;
684
843
  ride: {
685
844
  riding: boolean;
686
845
  lost: boolean;
687
846
  gliding: boolean;
688
847
  facing: RideFace | null;
848
+ groundKm: {
849
+ across: number;
850
+ tall: number;
851
+ } | null;
689
852
  };
690
853
  /** 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
854
  camera: {
@@ -746,6 +909,9 @@ export declare class ChikyuSpace extends HTMLElement {
746
909
  y: number;
747
910
  shown: boolean;
748
911
  parts: number;
912
+ share: number;
913
+ seat: number;
914
+ weight: number;
749
915
  radiusPx: number;
750
916
  box: {
751
917
  left: number;