@johnmorrisdotca/chikyu-earth 0.42.0 → 0.45.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 +17 -0
  2. package/NOTICE.md +15 -5
  3. package/README.md +4 -4
  4. package/dist/door/map.js +5 -1
  5. package/dist/element.d.ts +30 -0
  6. package/dist/element.js +82 -2
  7. package/dist/markers/here-city-host.d.ts +3 -1
  8. package/dist/markers/here-city-host.js +67 -5
  9. package/dist/markers/here-city.d.ts +94 -1
  10. package/dist/markers/here-city.js +69 -1
  11. package/dist/markers/index.d.ts +1 -1
  12. package/dist/markers/index.js +1 -1
  13. package/dist/realistic/element-base.d.ts +44 -1
  14. package/dist/realistic/element-base.js +128 -16
  15. package/dist/realistic/index.d.ts +1 -0
  16. package/dist/realistic/index.js +1 -0
  17. package/dist/realistic/zoom-reach.d.ts +29 -0
  18. package/dist/realistic/zoom-reach.js +30 -0
  19. package/dist/satellites/catalogue.d.ts +52 -1
  20. package/dist/satellites/catalogue.js +96 -5
  21. package/dist/satellites/index.d.ts +1 -1
  22. package/dist/satellites/index.js +1 -1
  23. package/dist/sea-names/features.d.ts +12 -0
  24. package/dist/sea-names/features.js +46 -0
  25. package/dist/sea-names/geometry.d.ts +121 -0
  26. package/dist/sea-names/geometry.js +135 -0
  27. package/dist/sea-names/host.d.ts +46 -0
  28. package/dist/sea-names/host.js +111 -0
  29. package/dist/space/element-base.d.ts +58 -11
  30. package/dist/space/element-base.js +153 -13
  31. package/dist/space/generic-satellite.d.ts +46 -0
  32. package/dist/space/generic-satellite.js +96 -0
  33. package/dist/space/index.d.ts +2 -1
  34. package/dist/space/index.js +2 -1
  35. package/dist/space/ride.d.ts +45 -0
  36. package/dist/space/ride.js +38 -0
  37. package/dist/space/satellite-focus.d.ts +90 -0
  38. package/dist/space/satellite-focus.js +109 -0
  39. package/dist/space/satellite-layer.d.ts +32 -3
  40. package/dist/space/satellite-layer.js +95 -29
  41. package/dist/space/scene.d.ts +3 -1
  42. package/dist/space/scene.js +54 -25
  43. package/package.json +3 -3
@@ -10,13 +10,15 @@ import type { BorderData, BorderStats } from "../borders/layer.ts";
10
10
  import { type RouteLeg } from "../route.ts";
11
11
  import type { GridStats } from "../grid/layer.ts";
12
12
  import { type CountryNamesStats, type CountryNamesStyle } from "../country-names/host.ts";
13
+ import { type SeaNamesStats } from "../sea-names/host.ts";
13
14
  import type { TileStats } from "../realistic/tile-set.ts";
14
15
  import { setThreeLoader } from "../realistic/shared.ts";
15
16
  import type { LightMode } from "../realistic/earth.ts";
16
17
  import type { SatelliteInfo, SatelliteRef, Satellites } from "../satellites/types.ts";
17
18
  import { type PlanetName } from "./ephemeris.ts";
18
- import { type SatelliteStyle } from "./satellite-layer.ts";
19
- import { type RideFace, type RideLook } from "./ride.ts";
19
+ import { type SatelliteScreen, type SatelliteStyle } from "./satellite-layer.ts";
20
+ import { type SatelliteOthers } from "./satellite-focus.ts";
21
+ import { type RideFace, type RideLook, type RideViewpoint } from "./ride.ts";
20
22
  import { type ScaleMode } from "./scale.ts";
21
23
  import { BODY_NAMES, type CameraMode, type BodyName, type BodyPainter, type RideTarget, type SatellitePainter } from "./scene.ts";
22
24
  import { type PaintSpec } from "../paint/buffer.ts";
@@ -112,6 +114,8 @@ export interface RideOptions {
112
114
  look?: RideLook;
113
115
  /** Face this way as the ride opens (`face`). */
114
116
  face?: RideFace;
117
+ /** `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
+ viewpoint?: RideViewpoint;
115
119
  distanceKm?: number;
116
120
  smooth?: boolean;
117
121
  }
@@ -132,6 +136,8 @@ export interface Riding {
132
136
  look: RideLook;
133
137
  face: RideFace | null;
134
138
  distanceKm: number;
139
+ /** `outside` or `inside` (see `RideOptions`). */
140
+ viewpoint: RideViewpoint;
135
141
  }
136
142
  type SatelliteStats = {
137
143
  groups: number;
@@ -338,6 +344,21 @@ export declare class ChikyuSpace extends HTMLElement {
338
344
  */
339
345
  get countryNamesStyle(): CountryNamesStyle;
340
346
  set countryNamesStyle(value: CountryNamesStyle);
347
+ /**
348
+ * Names of oceans, seas and continents (the attribute `sea-names`). Off unless set: a bare attribute is on. Oceans and continents from far out, seas once the Earth is large on the screen. A city name keeps the space where both fit only one. Nothing is drawn again at rest.
349
+ *
350
+ * @example
351
+ * ```ts no-run
352
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
353
+ *
354
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
355
+ * space.seaNames = true;
356
+ * console.log(space.seaNames);
357
+ * space.seaNames = false;
358
+ * ```
359
+ */
360
+ get seaNames(): boolean;
361
+ set seaNames(value: boolean);
341
362
  /**
342
363
  * Which borders are drawn on the Earth (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
343
364
  * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
@@ -454,6 +475,12 @@ export declare class ChikyuSpace extends HTMLElement {
454
475
  noradId: number;
455
476
  name: string;
456
477
  } | null;
478
+ /**
479
+ * Where a ride puts the camera: `outside` (the default; the attribute `ride-viewpoint`) shows the satellite, `inside` puts the camera at it. It is the default for the next `ride` and, set while riding, moves the ride there in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock.
480
+ * See `RideOptions.viewpoint`.
481
+ */
482
+ get rideViewpoint(): RideViewpoint;
483
+ set rideViewpoint(value: RideViewpoint);
457
484
  /** What the camera is riding along with now, or null. */
458
485
  get riding(): Riding | null;
459
486
  /**
@@ -482,12 +509,36 @@ export declare class ChikyuSpace extends HTMLElement {
482
509
  setSatellites(group: string, satellites: Satellites | null, style?: Partial<SatelliteStyle>): void;
483
510
  /** Show or hide a group without losing it. */
484
511
  showSatellites(group: string, on: boolean): void;
485
- /** The groups now set, with how many satellites each holds and whether it is shown. */
512
+ /**
513
+ * The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
514
+ */
486
515
  get satelliteGroups(): {
487
516
  name: string;
488
517
  count: number;
489
518
  visible: boolean;
519
+ placed: number;
520
+ emphasis: "focus" | "dim" | "hidden" | "plain";
490
521
  }[];
522
+ /** The group `focusSatelliteGroup` is showing on its own, or `null`. */
523
+ get focusedSatelliteGroup(): string | null;
524
+ /**
525
+ * Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
526
+ *
527
+ * @param name - The group's name, or `null` to clear the focus.
528
+ * @param options - `others` and `frame`.
529
+ * @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
530
+ */
531
+ focusSatelliteGroup(name: string | null, options?: {
532
+ others?: SatelliteOthers;
533
+ frame?: boolean;
534
+ }): {
535
+ ok: true;
536
+ group: string | null;
537
+ count: number;
538
+ } | {
539
+ ok: false;
540
+ reason: "not-set";
541
+ };
491
542
  /** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
492
543
  selectSatellite(ref: SatelliteRef | null): void;
493
544
  /** The satellite marked by `selectSatellite` or by a press on it, if any. */
@@ -515,15 +566,9 @@ export declare class ChikyuSpace extends HTMLElement {
515
566
  get satelliteNames(): Record<number, string>;
516
567
  set satelliteNames(value: Record<number, string>);
517
568
  /**
518
- * 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
519
- * placed (its elements are too old), or it is behind the camera. 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 need not repeat either.
569
+ * 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.
520
570
  */
521
- placeSatellite(ref: SatelliteRef): {
522
- x: number;
523
- y: number;
524
- visible: boolean;
525
- heightKm: number;
526
- } | null;
571
+ placeSatellite(ref: SatelliteRef): SatelliteScreen | null;
527
572
  /** 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. */
528
573
  satelliteInfo(ref: SatelliteRef): SatelliteInfo | undefined;
529
574
  /** The words shown beside each body, for a page in another language (`{ Mars: "火星" }`). A body left out keeps its English name. */
@@ -670,6 +715,8 @@ export declare class ChikyuSpace extends HTMLElement {
670
715
  };
671
716
  /** The names of countries: whether `country-names` is set and the most it asks for, the countries loaded, the names shown at the last draw, how many times they were laid out, and whether the outlines could not be loaded. */
672
717
  countryNames: CountryNamesStats;
718
+ /** The names of oceans, seas and continents: whether `sea-names` is on, the Earth's radius on the screen, the names shown at the last draw, and how many times the layer was laid out. */
719
+ seaNames: SeaNamesStats;
673
720
  };
674
721
  }
675
722
  declare global {
@@ -17,6 +17,8 @@ import { readRoute, routeLeg, routeText } from "../route.js";
17
17
  import { applyRoute } from "../route/layer.js";
18
18
  import { COUNTRY_NAMES_ATTRIBUTES } from "../country-names/geometry.js";
19
19
  import { COUNTRY_NAMES_STYLE, createCountryHost } from "../country-names/host.js";
20
+ import { SEA_NAMES_ATTRIBUTES, readSeaNames } from "../sea-names/geometry.js";
21
+ import { SEA_NAMES_STYLE, createSeaHost } from "../sea-names/host.js";
20
22
  import { createGate, frameCap } from "../realistic/gate.js";
21
23
  import { folderSource } from "../door/map.js";
22
24
  import { setThreeLoader, takeRenderer } from "../realistic/shared.js";
@@ -27,6 +29,7 @@ import { METEOR_NOTE_STYLE, prefersLessMotion, setMeteorNote } from "../meteors/
27
29
  import { MAX_TEXTURE } from "../realistic/tiers.js";
28
30
  import { AU_IN_EARTH_RADII, EARTH_RADIUS_KM, frameAt } from "./ephemeris.js";
29
31
  import { MAX_ORBIT_GROUP } from "./satellite-layer.js";
32
+ import { applySatelliteFocus, satelliteEmphasis, satelliteGroupRows, shellRadiusOf, zoomForPerspectiveShell } from "./satellite-focus.js";
30
33
  import { RIDE_FACES, rideTiltLimits, rideTurnDegrees } from "./ride.js";
31
34
  import { placeAround, placeMoon, placeSun, RADIUS } from "./scale.js";
32
35
  import { BODY_NAMES, createSpaceItem, DEFAULT_EARTH_SIZE, newSpaceModel } from "./scene.js";
@@ -111,7 +114,7 @@ const readTime = (value) => {
111
114
  const ms = Date.parse(value);
112
115
  return Number.isFinite(ms) ? ms : "now";
113
116
  };
114
- 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}${CITY_NAMES_STYLE}${METEOR_NOTE_STYLE}${NOTES_STYLE}`;
117
+ 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}`;
115
118
  /**
116
119
  * 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.
117
120
  *
@@ -153,7 +156,7 @@ const STYLE = `:host{display:block;aspect-ratio:1/1;position:relative;overflow:h
153
156
  * ```
154
157
  */
155
158
  export class ChikyuSpace extends HTMLElement {
156
- static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "tiles"];
159
+ static observedAttributes = ["cloud-drift", "camera", "earth-size", "earth-x", "earth-y", "center", "time", "speed", "scale", "labels", "orbits", "bodies", "light", "meteors", "meteors-label", "meteors-strength", ...BODY_LABEL_ATTRIBUTES, ...SKY_ATTRIBUTES, ...CITY_NAMES_ATTRIBUTES, ...BORDER_ATTRIBUTES, ...GRID_ATTRIBUTES, ...COUNTRY_NAMES_ATTRIBUTES, ...SEA_NAMES_ATTRIBUTES, "air-thickness", "air-label", "lang", "places", "places-look", "place-groups", "here-city", "route", "bodies-credit", "satellite-tint", "tiles", "ride-viewpoint"];
157
160
  #model = newSpaceModel();
158
161
  #paint = createPaintState();
159
162
  #mode = "now";
@@ -171,6 +174,7 @@ export class ChikyuSpace extends HTMLElement {
171
174
  #citiesStyle = {};
172
175
  /** The names of the countries on the Earth (`country-names`), and the look of the names. */
173
176
  #countries;
177
+ #seas;
174
178
  #countriesStyle = {};
175
179
  #satNames = {};
176
180
  /** A ringed satellite's name, by `group:index`, for `#satLabelLang`. The name does not depend on the moment, so a frame reads it and does not propagate the orbit again. */
@@ -193,6 +197,8 @@ export class ChikyuSpace extends HTMLElement {
193
197
  #places;
194
198
  #chosenLabel;
195
199
  #focusBeforeRide = "Earth";
200
+ /** The yaw, tilt and zoom from before a satellite group was framed, put back when the focus is cleared. */
201
+ #focusView = null;
196
202
  #lostTold = false;
197
203
  #names = {};
198
204
  #hint = "choose to look at it";
@@ -280,6 +286,11 @@ export class ChikyuSpace extends HTMLElement {
280
286
  onError: (error) => this.dispatchEvent(new CustomEvent("chikyu-country-names-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
281
287
  });
282
288
  this.#countries.setStyle(this.#countriesStyle);
289
+ this.#seas = createSeaHost({
290
+ root,
291
+ attribute: (name) => this.getAttribute(name),
292
+ language: () => ((this.closest("[lang]")?.getAttribute("lang") ?? "").toLowerCase().startsWith("ja") ? "ja" : "en"),
293
+ });
283
294
  this.#model.airThickness = readAirThickness(this.getAttribute("air-thickness"));
284
295
  this.#applyBodyLabel();
285
296
  setAirNote(this.#airNote, this, this.#model.airThickness);
@@ -387,10 +398,14 @@ export class ChikyuSpace extends HTMLElement {
387
398
  this.#cities?.dispose();
388
399
  this.#countries?.dispose();
389
400
  this.#countries = undefined;
401
+ this.#seas?.dispose();
402
+ this.#seas = undefined;
390
403
  this.#cities = undefined;
391
404
  }
392
405
  attributeChangedCallback(name, _old, value) {
393
- if (name === "center")
406
+ if (name === "ride-viewpoint")
407
+ this.#applyViewpoint();
408
+ else if (name === "center")
394
409
  this.centre = readCentre(value) ?? { lon: 0, lat: 0 };
395
410
  else if (name === "time")
396
411
  this.time = readTime(value);
@@ -434,6 +449,7 @@ export class ChikyuSpace extends HTMLElement {
434
449
  this.#applyBodyLabel();
435
450
  this.#sky?.refresh();
436
451
  this.#cities?.refresh();
452
+ this.#seas?.refresh();
437
453
  this.#countries?.refresh();
438
454
  this.#here?.refresh();
439
455
  }
@@ -464,6 +480,11 @@ export class ChikyuSpace extends HTMLElement {
464
480
  }
465
481
  else if (CITY_NAMES_ATTRIBUTES.includes(name))
466
482
  this.#cities?.refresh();
483
+ else if (SEA_NAMES_ATTRIBUTES.includes(name)) {
484
+ this.#seas?.refresh();
485
+ this.#seaFrame();
486
+ this.#countryFrame();
487
+ }
467
488
  else if (name === "borders") {
468
489
  Object.assign(this.#model.borders, readBorders(value));
469
490
  this.#gate?.request();
@@ -820,6 +841,7 @@ export class ChikyuSpace extends HTMLElement {
820
841
  #relayNames(cities, sky) {
821
842
  if (cities)
822
843
  this.#cities?.frame(this.#lastNameFrame, this.#boxesBeforeCities());
844
+ this.#seaFrame();
823
845
  this.#countryFrame();
824
846
  if (sky)
825
847
  this.#sky?.relayout();
@@ -839,18 +861,26 @@ export class ChikyuSpace extends HTMLElement {
839
861
  out.length = 0;
840
862
  if (!this.#lastNameFrame)
841
863
  return out;
842
- out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []));
864
+ out.push(...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? []));
843
865
  return out;
844
866
  }
845
867
  /** The frame the names were last laid out on. */
846
868
  #lastNameFrame = null;
847
- /** Lays the countries' names out on the last frame, clear of the bodies', the places' and the cities' names as they are now. */
869
+ /** Lays the ocean, sea and continent names out on the last frame, clear of the bodies', the places' and the cities'. A city placed first keeps the space. */
870
+ #seaFrame() {
871
+ const seas = this.#seas;
872
+ if (!seas)
873
+ return;
874
+ const frame = this.#lastNameFrame;
875
+ seas.frame(frame, seas.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
876
+ }
877
+ /** Lays the countries' names out on the last frame, clear of the bodies', the places', the cities' and the sea names as they are now. */
848
878
  #countryFrame() {
849
879
  const countries = this.#countries;
850
880
  if (!countries)
851
881
  return;
852
882
  const frame = this.#lastNameFrame;
853
- countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? [])] : []);
883
+ countries.frame(frame, countries.stats.on && frame ? [...this.#bodyNameBoxes(), ...(this.#placeLayer?.boxes ?? []), ...(this.#cities?.boxes ?? []), ...(this.#seas?.boxes ?? [])] : []);
854
884
  }
855
885
  /** The boxes the bodies' names take beside them in the picture just drawn. */
856
886
  #bodyNameBoxes() {
@@ -905,6 +935,28 @@ export class ChikyuSpace extends HTMLElement {
905
935
  this.#countriesStyle = { ...value };
906
936
  this.#countries?.setStyle(this.#countriesStyle);
907
937
  }
938
+ /**
939
+ * Names of oceans, seas and continents (the attribute `sea-names`). Off unless set: a bare attribute is on. Oceans and continents from far out, seas once the Earth is large on the screen. A city name keeps the space where both fit only one. Nothing is drawn again at rest.
940
+ *
941
+ * @example
942
+ * ```ts no-run
943
+ * import type { ChikyuSpace } from "@johnmorrisdotca/chikyu-earth/space/element";
944
+ *
945
+ * const space = document.querySelector("chikyu-space") as ChikyuSpace;
946
+ * space.seaNames = true;
947
+ * console.log(space.seaNames);
948
+ * space.seaNames = false;
949
+ * ```
950
+ */
951
+ get seaNames() {
952
+ return readSeaNames(this.getAttribute("sea-names"));
953
+ }
954
+ set seaNames(value) {
955
+ if (value)
956
+ this.setAttribute("sea-names", "");
957
+ else
958
+ this.removeAttribute("sea-names");
959
+ }
908
960
  /**
909
961
  * Which borders are drawn on the Earth (the attribute `borders`): the countries' at any size, and the regions' (provinces, states, prefectures) once the Earth is large enough on the screen to tell them apart.
910
962
  * Setting it writes the attribute: both sets as `borders="countries regions"`, one as its own word, none takes the attribute away.
@@ -1161,7 +1213,7 @@ export class ChikyuSpace extends HTMLElement {
1161
1213
  // a body followed (a planet, the Moon, the Earth) is looked at from round it as the view turns: it has no ways to face
1162
1214
  const faceable = !(view === "follow" && typeof target === "string");
1163
1215
  const face = faceable && options.face && RIDE_FACES.includes(options.face) ? options.face : null;
1164
- model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000) };
1216
+ model.ride = { target: typeof target === "string" ? target : { group: target.group, index: target.index }, view, look: face && view === "from" ? "horizon" : (options.look ?? "down"), face, distanceKm: Math.max(100, options.distanceKm ?? 3000), viewpoint: options.viewpoint === "inside" || options.viewpoint === "outside" ? options.viewpoint : this.rideViewpoint };
1165
1217
  if (face) {
1166
1218
  model.view = { yaw: 0, tilt: 0, zoom: model.view.zoom };
1167
1219
  model.rideTurn = 0;
@@ -1294,6 +1346,31 @@ export class ChikyuSpace extends HTMLElement {
1294
1346
  this.ride(next.ref, { view: "follow" });
1295
1347
  return next;
1296
1348
  }
1349
+ /**
1350
+ * Where a ride puts the camera: `outside` (the default; the attribute `ride-viewpoint`) shows the satellite, `inside` puts the camera at it. It is the default for the next `ride` and, set while riding, moves the ride there in one eased glide (a jump for a reader who asked for reduced motion), keeping the ride and the clock.
1351
+ * See `RideOptions.viewpoint`.
1352
+ */
1353
+ get rideViewpoint() {
1354
+ return this.getAttribute("ride-viewpoint") === "inside" ? "inside" : "outside";
1355
+ }
1356
+ set rideViewpoint(value) {
1357
+ this.setAttribute("ride-viewpoint", value === "inside" ? "inside" : "outside");
1358
+ }
1359
+ #applyViewpoint() {
1360
+ const model = this.#model;
1361
+ const ride = model.ride;
1362
+ const next = this.rideViewpoint;
1363
+ if (!ride || ride.viewpoint === next)
1364
+ return;
1365
+ const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
1366
+ const pose = model.pose;
1367
+ model.ride = { ...ride, viewpoint: next };
1368
+ 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;
1369
+ this.#last = performance.now();
1370
+ this.#schedule();
1371
+ this.#gate?.request();
1372
+ this.dispatchEvent(new CustomEvent("chikyu-ride", { detail: this.riding }));
1373
+ }
1297
1374
  /** What the camera is riding along with now, or null. */
1298
1375
  get riding() {
1299
1376
  const ride = this.#model.ride;
@@ -1352,6 +1429,11 @@ export class ChikyuSpace extends HTMLElement {
1352
1429
  groups.delete(group);
1353
1430
  if (this.#model.satellites.selected?.group === group)
1354
1431
  this.#model.satellites.selected = null;
1432
+ if (this.#model.satellites.focus?.name === group) {
1433
+ this.#model.satellites.focus = null;
1434
+ this.#restoreFocusView();
1435
+ this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: null, count: 0 }, bubbles: true, composed: true }));
1436
+ }
1355
1437
  }
1356
1438
  else {
1357
1439
  const was = groups.get(group);
@@ -1378,9 +1460,67 @@ export class ChikyuSpace extends HTMLElement {
1378
1460
  this.#schedule();
1379
1461
  this.#gate?.request();
1380
1462
  }
1381
- /** The groups now set, with how many satellites each holds and whether it is shown. */
1463
+ /**
1464
+ * The groups now set. `count` is how many satellites the group holds, `visible` is the shown state from `showSatellites` (a focus does not change it), `placed` is how many the last draw placed (0 when the group is not drawn) and `emphasis` is how a focus treats it: `focus`, `dim`, `hidden` or `plain` (no focus).
1465
+ */
1382
1466
  get satelliteGroups() {
1383
- return [...this.#model.satellites.groups].map(([name, group]) => ({ name, count: group.satellites.count, visible: group.visible }));
1467
+ return satelliteGroupRows(this.#model.satellites);
1468
+ }
1469
+ /** The group `focusSatelliteGroup` is showing on its own, or `null`. */
1470
+ get focusedSatelliteGroup() {
1471
+ return this.#model.satellites.focus?.name ?? null;
1472
+ }
1473
+ /**
1474
+ * Show one group on its own. The others are drawn dimmer (`others: "dim"`, the default, through the same dimming an old element set uses) or not drawn (`"hide"`). `frame` (true by default) pulls the camera back, by this view's own zoom, until the group's orbits fit: the distance is the greatest apogee of the group, from each satellite's mean motion and eccentricity, and it stops at 8 Earth radii. `null` puts every group back to the shown state it had, and puts the camera back when it was moved. A name that `setSatellites` has not set returns `{ ok: false, reason: "not-set" }` and changes nothing. It does not throw. When the choice changes, `chikyu-satellite-focus` is sent with `{ group, count }`.
1475
+ *
1476
+ * @param name - The group's name, or `null` to clear the focus.
1477
+ * @param options - `others` and `frame`.
1478
+ * @returns `{ ok: true, group, count }` when the group is set (`group` is `null` and `count` is 0 when cleared). `{ ok: false, reason: "not-set" }` when it is not.
1479
+ */
1480
+ focusSatelliteGroup(name, options = {}) {
1481
+ const answer = applySatelliteFocus(this.#model.satellites, name, options);
1482
+ if (!answer.ok || answer.group === undefined || answer.count === undefined)
1483
+ return { ok: false, reason: "not-set" };
1484
+ if (answer.group === null)
1485
+ this.#restoreFocusView();
1486
+ else if (options.frame !== false)
1487
+ this.#frameSatelliteShell(answer.group);
1488
+ if (answer.changed)
1489
+ this.dispatchEvent(new CustomEvent("chikyu-satellite-focus", { detail: { group: answer.group, count: answer.count }, bubbles: true, composed: true }));
1490
+ // which groups are drawn decides how often time is drawn, so the next step is worked out again, as for `showSatellites`
1491
+ this.#schedule();
1492
+ this.#gate?.request();
1493
+ return { ok: true, group: answer.group, count: answer.count };
1494
+ }
1495
+ /** The view's own zoom, far enough that the group's shell fills the picture. A ride is left, because the camera has to look at the Earth to see the shell. */
1496
+ #frameSatelliteShell(name) {
1497
+ const group = this.#model.satellites.groups.get(name);
1498
+ if (!group)
1499
+ return;
1500
+ const box = this.getBoundingClientRect();
1501
+ if (box.width < 2 || box.height < 2)
1502
+ return;
1503
+ if (!this.#focusView)
1504
+ this.#focusView = { yaw: this.#model.view.yaw, tilt: this.#model.view.tilt, zoom: this.#model.view.zoom };
1505
+ if (this.#model.ride)
1506
+ this.ride(null);
1507
+ const zoom = zoomForPerspectiveShell(shellRadiusOf(group.satellites.sets), this.earthSize, box.width / box.height, LIMITS.zoomMin, LIMITS.zoomMax);
1508
+ this.#moveView({ yaw: this.#model.view.yaw, tilt: this.#model.view.tilt, zoom });
1509
+ }
1510
+ /** Put back the yaw, tilt and zoom from before the shell was framed. */
1511
+ #restoreFocusView() {
1512
+ const saved = this.#focusView;
1513
+ this.#focusView = null;
1514
+ if (saved)
1515
+ this.#moveView(saved);
1516
+ }
1517
+ /** Hand a camera to the controls that are driving the view, or to the view itself when those are not there yet. */
1518
+ #moveView(view) {
1519
+ const controls = this.#controls();
1520
+ if (controls)
1521
+ controls.set(view, true, "satellites");
1522
+ else
1523
+ this.setView(view, true);
1384
1524
  }
1385
1525
  /** Mark one satellite: a larger ring round it, its orbit drawn, and its name beside it. `null` lets it go. */
1386
1526
  selectSatellite(ref) {
@@ -1436,8 +1576,7 @@ export class ChikyuSpace extends HTMLElement {
1436
1576
  this.#gate?.request();
1437
1577
  }
1438
1578
  /**
1439
- * 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
1440
- * placed (its elements are too old), or it is behind the camera. 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 need not repeat either.
1579
+ * 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.
1441
1580
  */
1442
1581
  placeSatellite(ref) {
1443
1582
  return this.#model.placeSatellite?.(ref) ?? null;
@@ -1568,6 +1707,7 @@ export class ChikyuSpace extends HTMLElement {
1568
1707
  grid: { ...this.#model.grid.stats },
1569
1708
  route: { ...this.#model.route.stats },
1570
1709
  countryNames: this.#countries?.stats ?? { on: false, max: 0, countries: 0, names: 0, renders: 0, failed: false },
1710
+ seaNames: this.#seas?.stats ?? { on: false, radius: 0, names: 0, renders: 0 },
1571
1711
  };
1572
1712
  }
1573
1713
  #satelliteStats() {
@@ -1593,8 +1733,8 @@ export class ChikyuSpace extends HTMLElement {
1593
1733
  }
1594
1734
  /** Is anything on show that moves faster than the Earth turns: a group of satellites, including above the interpolation limit where they are drawn as streaks? */
1595
1735
  #satellitesMoving() {
1596
- for (const group of this.#model.satellites.groups.values())
1597
- if (group.visible && group.satellites.count > 0)
1736
+ for (const [name, group] of this.#model.satellites.groups)
1737
+ if (satelliteEmphasis(name, group.visible, this.#model.satellites.focus).drawn && group.satellites.count > 0)
1598
1738
  return true;
1599
1739
  return false;
1600
1740
  }
@@ -0,0 +1,46 @@
1
+ import type * as THREE from "three";
2
+ import type { BodyDrawing } from "./scene.ts";
3
+ /**
4
+ * What a generic drawing shows: `bus` a box with two solar panels, `communications` the same with a dish on its nadir face, `flat` a flat panel with one long solar array (the shape of a large constellation's satellites), `station` a row of modules with a truss and panels.
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import type { SatelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
9
+ *
10
+ * const kinds: SatelliteKind[] = ["bus", "communications", "flat", "station"];
11
+ * console.log(kinds.length);
12
+ * ```
13
+ */
14
+ export type SatelliteKind = "bus" | "communications" | "flat" | "station";
15
+ /**
16
+ * Which kind of drawing a satellite gets, from its name: a large constellation (`STARLINK`, `ONEWEB`, `KUIPER`) is `flat`, a station (`ISS`, `ZARYA`, `TIANGONG`, `CSS`) is `station`, a communications satellite (by the common operators' names) has a dish, and anything else is a plain `bus`.
17
+ *
18
+ * @param name - The satellite's name (the element set's `OBJECT_NAME`).
19
+ * @returns The kind.
20
+ *
21
+ * @example
22
+ * ```ts
23
+ * import { satelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
24
+ *
25
+ * console.log(satelliteKind("STARLINK-1007"), satelliteKind("ISS (ZARYA)"), satelliteKind("INTELSAT 39"), satelliteKind("NOAA 19"));
26
+ * ```
27
+ */
28
+ export declare function satelliteKind(name: string): SatelliteKind;
29
+ /**
30
+ * A generic satellite as a drawing of radius 1 about the origin, its long axis along +x (the way it flies), its top along +z and its left along +y, the family's convention for a model, with its own light that `light(toSun)` turns to the Sun. One group of a few meshes, made once and disposed with `dispose`.
31
+ *
32
+ * @param three - three.js (the parts the demo's subset holds: `Group`, `Mesh`, `BoxGeometry`, `CylinderGeometry`, `MeshLambertMaterial`, `DirectionalLight`, `AmbientLight`).
33
+ * @param kind - What to draw.
34
+ * @returns The drawing, with `light` and `dispose`.
35
+ *
36
+ * @example
37
+ * ```ts no-run
38
+ * import { genericSatellite } from "@johnmorrisdotca/chikyu-earth/space";
39
+ *
40
+ * const three = await import("three");
41
+ * const drawing = genericSatellite(three, "communications");
42
+ * console.log(drawing.object.children.length);
43
+ * drawing.dispose();
44
+ * ```
45
+ */
46
+ export declare function genericSatellite(three: typeof THREE, kind: SatelliteKind): BodyDrawing;
@@ -0,0 +1,96 @@
1
+ const COMMS = /(INTELSAT|SES-|EUTELSAT|ASTRA|ECHOSTAR|DIRECTV|TELSTAR|GALAXY|YAMAL|THURAYA|INMARSAT|IRIDIUM|GLOBALSTAR|ORBCOMM|TDRS|VIASAT|ANIK|SKYNET|MILSTAR|SAT-|SATCOM|COMSAT|OPTUS|JCSAT|SUPERBIRD|HISPASAT|ARABSAT|NILESAT|TURKSAT|KOREASAT|ASIASAT|APSTAR|EXPRESS|BADR)/i;
2
+ /**
3
+ * Which kind of drawing a satellite gets, from its name: a large constellation (`STARLINK`, `ONEWEB`, `KUIPER`) is `flat`, a station (`ISS`, `ZARYA`, `TIANGONG`, `CSS`) is `station`, a communications satellite (by the common operators' names) has a dish, and anything else is a plain `bus`.
4
+ *
5
+ * @param name - The satellite's name (the element set's `OBJECT_NAME`).
6
+ * @returns The kind.
7
+ *
8
+ * @example
9
+ * ```ts
10
+ * import { satelliteKind } from "@johnmorrisdotca/chikyu-earth/space";
11
+ *
12
+ * console.log(satelliteKind("STARLINK-1007"), satelliteKind("ISS (ZARYA)"), satelliteKind("INTELSAT 39"), satelliteKind("NOAA 19"));
13
+ * ```
14
+ */
15
+ export function satelliteKind(name) {
16
+ if (/^(STARLINK|ONEWEB|KUIPER)/i.test(name))
17
+ return "flat";
18
+ if (/(ISS|ZARYA|TIANGONG|CSS|TIANHE|WENTIAN|MENGTIAN)/i.test(name))
19
+ return "station";
20
+ if (COMMS.test(name))
21
+ return "communications";
22
+ return "bus";
23
+ }
24
+ /**
25
+ * A generic satellite as a drawing of radius 1 about the origin, its long axis along +x (the way it flies), its top along +z and its left along +y, the family's convention for a model, with its own light that `light(toSun)` turns to the Sun. One group of a few meshes, made once and disposed with `dispose`.
26
+ *
27
+ * @param three - three.js (the parts the demo's subset holds: `Group`, `Mesh`, `BoxGeometry`, `CylinderGeometry`, `MeshLambertMaterial`, `DirectionalLight`, `AmbientLight`).
28
+ * @param kind - What to draw.
29
+ * @returns The drawing, with `light` and `dispose`.
30
+ *
31
+ * @example
32
+ * ```ts no-run
33
+ * import { genericSatellite } from "@johnmorrisdotca/chikyu-earth/space";
34
+ *
35
+ * const three = await import("three");
36
+ * const drawing = genericSatellite(three, "communications");
37
+ * console.log(drawing.object.children.length);
38
+ * drawing.dispose();
39
+ * ```
40
+ */
41
+ export function genericSatellite(three, kind) {
42
+ const group = new three.Group();
43
+ const materials = [];
44
+ const geometries = [];
45
+ const half = Math.PI / 2;
46
+ const add = (geometry, colour, at, spin = [0, 0, 0]) => {
47
+ const material = new three.MeshLambertMaterial({ color: colour });
48
+ const mesh = new three.Mesh(geometry, material);
49
+ mesh.position.set(at[0], at[1], at[2]);
50
+ mesh.rotation.set(spin[0], spin[1], spin[2]);
51
+ group.add(mesh);
52
+ materials.push(material);
53
+ geometries.push(geometry);
54
+ };
55
+ const box = (x, y, z) => new three.BoxGeometry(x, y, z);
56
+ const tube = (radius, length) => new three.CylinderGeometry(radius, radius, length, 16);
57
+ if (kind === "flat") {
58
+ add(box(0.5, 0.36, 0.03), 0xd7dadf, [0, 0, 0]);
59
+ add(box(0.5, 1.1, 0.01), 0x1f3f7a, [0, 0.74, 0]);
60
+ }
61
+ else if (kind === "station") {
62
+ add(tube(0.07, 0.8), 0xd9dde3, [0, 0, 0], [0, 0, half]);
63
+ add(box(0.05, 1.7, 0.05), 0xb7bcc4, [-0.2, 0, 0]);
64
+ for (const y of [-0.75, 0.75])
65
+ add(box(0.3, 0.3, 0.012), 0x274a8c, [-0.2, y, 0]);
66
+ }
67
+ else {
68
+ add(box(0.5, 0.4, 0.4), 0xd7b35a, [0, 0, 0]);
69
+ for (const y of [-1, 1]) {
70
+ add(box(0.18, 0.04, 0.04), 0xb7bcc4, [0, y * 0.4, 0]);
71
+ add(box(0.36, 0.52, 0.012), 0x1f3f7a, [0, y * 0.72, 0]);
72
+ }
73
+ if (kind === "communications") {
74
+ add(tube(0.05, 0.14), 0xb7bcc4, [0.1, 0, 0.27]);
75
+ add(new three.CylinderGeometry(0.2, 0.02, 0.1, 20), 0xe8eaee, [0.1, 0, 0.36]);
76
+ }
77
+ }
78
+ const sun = new three.DirectionalLight(0xfff4e0, 3.2);
79
+ group.add(sun, new three.AmbientLight(0x6f86a8, 0.9));
80
+ return {
81
+ object: group,
82
+ light(toSun) {
83
+ // the model's axes are the columns of the matrix the view set: the direction to the Sun in them is the dot with each
84
+ const m = group.matrix.elements;
85
+ const length = Math.hypot(m[0], m[1], m[2]) || 1;
86
+ sun.position.set((m[0] * toSun[0] + m[1] * toSun[1] + m[2] * toSun[2]) / length, (m[4] * toSun[0] + m[5] * toSun[1] + m[6] * toSun[2]) / length, (m[8] * toSun[0] + m[9] * toSun[1] + m[10] * toSun[2]) / length);
87
+ },
88
+ dispose() {
89
+ for (const material of materials)
90
+ material.dispose();
91
+ for (const geometry of geometries)
92
+ geometry.dispose();
93
+ sun.dispose?.();
94
+ },
95
+ };
96
+ }
@@ -1,6 +1,7 @@
1
1
  export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS, type Frame, type PlanetName, type Vec3 } from "./ephemeris.ts";
2
2
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition, type ScaleMode } from "./scale.ts";
3
3
  export { fitDistance, plainPainter, type BodyDrawing, type BodyMoon, type BodyPainter, type BodyView, type PaintContext, type SatellitePainter } from "./scene.ts";
4
- export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose } from "./ride.ts";
4
+ export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees, type RideFace, type RideInput, type RideLook, type RidePose, type RideViewpoint } from "./ride.ts";
5
5
  export type { SatelliteScreen } from "./satellite-layer.ts";
6
6
  export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.ts";
7
+ export { genericSatellite, satelliteKind, type SatelliteKind } from "./generic-satellite.ts";
@@ -3,5 +3,6 @@
3
3
  export { AU_IN_EARTH_RADII, blend, createTrack, EARTH_RADIUS_KM, frameAt, orbitPath, PLANETS } from "./ephemeris.js";
4
4
  export { compress, MOON_COMPRESSED, placeAround, placeMoon, placeSun, RADIUS, SUN_COMPRESSED, truePosition } from "./scale.js";
5
5
  export { fitDistance, plainPainter } from "./scene.js";
6
- export { faceOffset, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
6
+ export { faceOffset, OUTSIDE_KM, outsidePose, RIDE_FACES, RIDE_FOV, rideFov, ridePose, rideTiltLimits, rideTurnDegrees } from "./ride.js";
7
7
  export { aboveAxes, MODEL_RADIUS_SHARE, modelMatrix, modelRadius, satelliteAxes } from "./satellite-model.js";
8
+ export { genericSatellite, satelliteKind } from "./generic-satellite.js";