@johnmorrisdotca/chikyu-earth 0.46.5 → 0.47.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,18 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.47.0 - 2026-11-13
4
+
5
+ - **The demo's Find box keeps a Japanese query.** A name in kana or kanji used to be dropped before the catalogue was asked, so `ハッブル` found nothing. It now asks the catalogue, and a satellite the package knows by a short name is listed by that name (Hubble, not only HST).
6
+ - **A satellite hidden by the Earth** (MODULES-1243). `placeSatellite` adds `occluded`: true when the line from the camera meets the Earth before the satellite, false in front, false at the limb, and false when the satellite is only behind the camera (`behind` is unchanged). The package's own satellite names, stations included, are drawn at 45 percent opacity with no ring while occluded, and restored as the satellite comes out. `dim-occluded="off"` (the property `dimOccluded`, on by default) leaves those names out. `earthHides` is the same test, for a page that places its own names.
7
+ - **A share of the Earth's turn on the space view** (MODULES-1223). `follow` on `<chikyu-space>` is a number from 0 to 1. 0, the default, holds the stars, which is what `camera="space"` already does, so a page that sets nothing changes nothing. 1 turns with the Earth. A number between takes that share. Changing it keeps the longitude under the middle of the view. `follow-ease` is how many seconds the change takes (0.4 when left out, 0 for none, and at once when the reader asks for reduced motion). It follows a fast, reversed or paused clock, and nothing is drawn while the clock is stopped and `follow` is not changing. A step of the clock longer than half a turn now keeps the Earth's real turn (a day is a full turn), so a fast clock moves the ground at the Earth's own rate. `centreLongitude` reads the longitude under the middle, and `shownTime` is the moment of the draw it belongs to.
8
+ - **The place under a point** (MODULES-1265). `placeOf(lon, lat)` in `@johnmorrisdotca/chikyu-earth/place` returns the country, a country the point is only near, the sea or ocean, the continent and the nearest city. The countries are the line globe's outlines, Natural Earth at 1:110m, indexed on a 15° grid. A point inside an outline is `country`. A point outside every outline and within 50 km (`PLACE_COAST_KM`) is `near`, because that coarse coast is the wrong place to claim a country. The sea is the nearest named sea, gulf, bay or ocean within its reach (`SEA_REACH_KM`); nothing is named when none reaches. The continent follows the country's group, named as on the sea-names list. Australia the country is that continent. A point at least 2,500 km closer to another continent's point (eastern Russia, French Guiana) uses the nearer one. Pacific island countries the outlines group as Oceania are `oceania`, which is not one of those seven. The nearest city is the caller's lists, the same three tiers as `here-city`, and towns under 100,000 only when `towns` is passed. `alongTrack` reports each change of country, nearby country or sea along a ground track, at the sample that entered it. A call is about 0.14 ms once the grid is built.
9
+ - **A faint orbit while the pointer rests on a satellite** (MODULES-1234). On `<chikyu-space>` and `<chikyu-earth-realistic>`, resting on a satellite shows its name and draws its orbit at about a third of the brightness of a chosen satellite's orbit (`hover-path`, on when `names-on-hover` is on; `hover-path="off"` turns the orbit off, `names-on-hover="off"` turns the name off). The colour and the opacity are `--chikyu-hover-path` and `--chikyu-hover-path-opacity`. The path is worked out once from the elements already loaded. It fades out when the pointer leaves (at once when the reader asks for reduced motion). A chosen orbit is unchanged. A touch does not rest, so nothing new is drawn, and nothing is drawn while the pointer is still and no satellite is under it.
10
+ - **Frame the ridden satellite, zoom inside a ride, and a viewpoint switch that fades** (MODULES-1316). `ride-model-share` (property `rideModelShare`, option `modelShare`, 0.02 to 1.2: the model's radius as a share of the picture's height; 0.22 along the way it goes, up from 0.17, 0.17 above, 0.10 looking down) and `ride-model-seat` (`rideModelSeat`, `modelSeat`, 0.5 to 1.4: where its middle sits from the top; 0.86 along the way it goes, down from 0.90) frame the model, so with the defaults the body and a good part of a wing are in view in Ride along, and a page can go to a close framing (1 and 1). `ride-zoom` (`rideZoom`, 0.5 to 40; the field of view is 60 degrees over it, the least `rideFov` now allows is 1.5) zooms in a ride, and `stats.ride.groundKm` (`{ across, tall }`, kilometres of ground below the satellite) says how much ground the picture spans. All are settable while riding, glide in 0.4 s (a jump under reduced motion), cost one draw for the change and nothing at rest. Switching `ride-viewpoint` between `outside` and `inside` now fades the model over 0.4 s as the camera closes on it (and back), and `stats.followModel` reports `share`, `seat` and `weight`.
11
+
12
+ ## 0.46.6 - 2026-11-13
13
+
14
+ - **A beam from the chosen satellite to the ground below it** (MODULES-1309). `beam` on `<chikyu-space>` (off unless set; the property `beam`) draws a soft, additive cone of light from the satellite marked with `selectSatellite`, or the one ridden, down to its footprint on the ground: a lit ring and a faint fill, the circle from which the satellite is above `beam-elevation` degrees (25), worked from its height (`footprintAngle`, `footprintKm`), cut off by the limb, in Ride along and Ride above as well. `beam-cells` (up to 91) adds spot cells in a hexagonal pack, each with a thin shaft of light (an illustration, not any operator's plan), `beam-cell-size`, `beam-color` and `beam-strength` set the look; `stats.beam` says the footprint's radius in kilometres. It is part of the draw that moves the satellite: nothing at rest, nothing rebuilt on a clock step, no shimmer. Guide: `docs/guides/beam.md` (and its Japanese twin), and a "Satellite beam" button in the demo.
15
+
3
16
  ## 0.46.5 - 2026-11-13
4
17
 
5
18
  - **The ridden satellite's model shrinks as a ride above it rises, and the package's drawings are better** (MODULES-1306). In a ride above (`view: "above"`) the model was a fixed 17 per cent of the picture at any height, so from 6,000 km it was a huge block. The new option `modelSize: "distance" | "fixed"` (attribute `ride-model-size`, property `rideModelSize`; `distance` is the default) keeps the model at that size up to 150 km, shrinks it as one over the height, lets it down smoothly from 1,000 km to nothing at 2,000 km, where the ordinary mark (ring and name) takes over (`aboveModelShare`, `MODEL_HANDOVER_PX`); `fixed` is the old size at every height. A page's painter is told the size through `update({ radiusPx })` and `stats.followModel` reports it. The chosen satellite's ring and name stay off its model in both modes while it is drawn and return at the hand-over or when the ride ends (`modelOver`, `stats.satellites.selectedRing`). The generic drawings are redrawn with framed thin panels, a bus with a radiator and a camera, a dish, a long panel for a constellation, and a new `cubesat` kind (FLOCK, DOVE, LEMUR, SPIRE and similar names); every part of every kind is inside the model's disc (the flat kind's panel was not, which was the stray slab), tested in `test/generic-satellite.test.ts` and, pixel by pixel outside the reported box, in `e2e/ride-size.gl.ts`. Names under the model: while the model is drawn the package's own names (places, cities, seas, countries, stars) keep clear of its box, and `chikyu-ride-model` (`detail: { box, radiusPx, x, y }`, `box` null when none) tells the page when the box has moved by more than a pixel or has come or gone, for its own labels. **Behaviour change:** `distance` is the default; set `ride-model-size="fixed"` for the old size (upgrading guide).
package/README.md CHANGED
@@ -359,7 +359,7 @@ Passes are only as good as the orbit data are new: each pass says how old its el
359
359
  <p align="center"><img alt="Riding along with the ISS, tipped towards the horizon: the Earth's curve and atmosphere, and the orbits of the other stations in the sky" src="docs/images/space-ride-horizon.png" width="420"></p>
360
360
 
361
361
  `space.ride({ group: "stations", index: 0 }, { look: "horizon" })` puts the camera on the ISS (or a Starlink satellite, the Moon, a planet) at its real place for the moment shown and looks at the Earth, which goes by beneath
362
- as the body moves along its orbit; switch to another body and the camera glides there. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. It animates continuously, so it keeps to the
362
+ as the body moves along its orbit; switch to another body and the camera glides there. Straight down or toward the horizon, from the body or following it at a distance, time faster or slower. A ridden satellite is in the picture by default (the camera a little behind and above it, a small drawing of it where the page has no model, not to scale); `ride-viewpoint="inside"` (property `rideViewpoint`, option `viewpoint`) puts the camera at the satellite instead. Seen from above, the model shrinks as the ride rises and hands over to the ordinary mark by 2,000 km; `ride-model-size="fixed"` (property `rideModelSize`, option `modelSize`) keeps one size at every height. `ride-model-share`, `ride-model-seat` and `ride-zoom` frame and zoom the ridden satellite (properties `rideModelShare`, `rideModelSeat`, `rideZoom`). It animates continuously, so it keeps to the
363
363
  same budget: at most 30 frames a second (one a second for reduced motion), nothing drawn while paused, out of sight or hidden. [Ride along guide](docs/guides/ride-along.md), [docs/ride-along.md](docs/ride-along.md).
364
364
 
365
365
  ## Printable sheets
@@ -399,7 +399,7 @@ rotate or drag controls.
399
399
  | --- | --- | --- |
400
400
  | `<chikyu-earth>` | 0.1 to 20 times | Natural Earth 1:110m outlines, redrawn at each zoom; at 20 times the view is about 640 km across and a coast is a few straight segments |
401
401
  | `<chikyu-earth-realistic>` | 0.1 to 5 times; 40 with `tiles` found (20 for a set that stops at level 4) | the package's pictures are 4096 pixels across at most; the finest tile level is up to 8 times that |
402
- | `<chikyu-space>` | a millionth to 2.5 times; 0.5 to 6 riding from a body | the zoom is the camera's distance (the whole solar system needs a millionth); close in, the Earth's picture and the textures stay sharp to 2.5 |
402
+ | `<chikyu-space>` | a millionth to 2.5 times; 0.5 to 40 riding from a body | the zoom is the camera's distance (the whole solar system needs a millionth); close in, the Earth's picture and the textures stay sharp to 2.5 |
403
403
 
404
404
  [Zoom, pan and turn](docs/guides/zoom-and-pan.md) says more. For buttons, a slider, Auto-turn and the address, add the
405
405
  bar for the element (give it an `id` and a `tabindex`); it takes the hands over and the page applies its events:
@@ -578,6 +578,7 @@ Each guide has a Japanese twin in [docs/guides/ja](docs/guides/ja/getting-starte
578
578
  | [City names on the Earth](docs/guides/city-names.md) | Cities named from kuni's list, more as the Earth grows on the screen, in the page's language |
579
579
  | [Borders on the Earth](docs/guides/borders.md) | The borders between countries, and a page's own regions once the Earth is large enough |
580
580
  | [The grid and country names on the Earth](docs/guides/grid-and-country-names.md) | Meridians and parallels with the special lines picked out, and the countries in sight named in the page's language |
581
+ | [A beam from a satellite to the ground](docs/guides/beam.md) | A soft cone of light from the chosen satellite to a lit footprint, true to its height, with optional spot cells, in a ride too |
581
582
  | [A name on the Earth](docs/guides/body-label.md) | The Earth's name written on the globe, in the family's plain attribute names |
582
583
  | [You are here, and places on the Earth](docs/guides/places.md) | The reader's place and favourite places as markers standing out of the Earth, asked for only on a press, kept on the device |
583
584
  | [Meteors seen from space](docs/guides/meteors.md) | Streaks over the night side, the shower table, what is real and what is illustration |
@@ -611,7 +612,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
611
612
 
612
613
  ## How to cite
613
614
 
614
- > Morris, J. (2026). *Chikyu Earth* (version 0.46.5) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
615
+ > Morris, J. (2026). *Chikyu Earth* (version 0.47.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
615
616
 
616
617
  GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
617
618
 
@@ -0,0 +1,131 @@
1
+ /**
2
+ * The elevation, in degrees, above which a satellite counts as seen from the ground: the footprint is the circle from which it stands at least this high.
3
+ *
4
+ * @example
5
+ * ```ts
6
+ * import { BEAM_ELEVATION } from "@johnmorrisdotca/chikyu-earth/space";
7
+ *
8
+ * console.log(BEAM_ELEVATION);
9
+ * ```
10
+ */
11
+ export declare const BEAM_ELEVATION = 25;
12
+ /**
13
+ * The angle at the Earth's centre between the point below a satellite and the edge of its footprint, in radians: the ground circle from which the satellite is above `elevation`.
14
+ * It is `acos(R cos(e) / (R + h)) - e` for the Earth's radius R, the height h and the elevation e. A satellite on or under the ground, or an elevation of 90 degrees or more, has none.
15
+ *
16
+ * @param heightKm - The satellite's height above the ground, in kilometres.
17
+ * @param elevation - The least elevation, in degrees. 25 when left out.
18
+ * @returns The angle, in radians, from 0 up to a quarter of a turn.
19
+ * @example
20
+ * ```ts
21
+ * import { footprintAngle } from "@johnmorrisdotca/chikyu-earth/space";
22
+ *
23
+ * console.log((footprintAngle(420) * 180) / Math.PI);
24
+ * ```
25
+ */
26
+ export declare function footprintAngle(heightKm: number, elevation?: number): number;
27
+ /**
28
+ * The radius of a satellite's footprint along the ground, in kilometres: the Earth's radius times {@link footprintAngle}.
29
+ *
30
+ * @param heightKm - The satellite's height above the ground, in kilometres.
31
+ * @param elevation - The least elevation, in degrees. 25 when left out.
32
+ * @returns The radius in kilometres.
33
+ * @example
34
+ * ```ts
35
+ * import { footprintKm } from "@johnmorrisdotca/chikyu-earth/space";
36
+ *
37
+ * console.log(Math.round(footprintKm(550)));
38
+ * ```
39
+ */
40
+ export declare const footprintKm: (heightKm: number, elevation?: number) => number;
41
+ /**
42
+ * The spot cells inside a footprint: where each one's middle is, and how large they are, in the footprint's own units (the footprint's radius is 1).
43
+ *
44
+ * @example
45
+ * ```ts no-run
46
+ * import type { BeamCells } from "@johnmorrisdotca/chikyu-earth/space";
47
+ *
48
+ * const none: BeamCells = { lattice: [], pitch: 0, radius: 0 };
49
+ * console.log(none.lattice.length);
50
+ * ```
51
+ */
52
+ export interface BeamCells {
53
+ /** Each cell's middle on the lattice, in units of the distance between neighbours (the hexagonal pack: one at the middle, then rings of six, twelve, eighteen). */
54
+ lattice: number[][];
55
+ /** The distance between neighbouring cells as a share of the footprint's radius. */
56
+ pitch: number;
57
+ /** A cell's radius as a share of the footprint's radius. */
58
+ radius: number;
59
+ }
60
+ /**
61
+ * The spot cells of a footprint: `count` circles in a hexagonal pack (the middle one, then the nearest to it), drawn to fit inside the footprint, or at most `cellKm` in radius when that is smaller.
62
+ * It is an illustration of a satellite that serves the ground in cells; it is not the pattern of any operator's beam plan.
63
+ *
64
+ * @param count - How many cells (0 for none; the most is 91, six rings).
65
+ * @param radiusKm - The footprint's radius along the ground, in kilometres.
66
+ * @param cellKm - A cell's radius in kilometres, when the page wants it smaller than the fit; 0 for the fit.
67
+ * @returns The cells.
68
+ * @example
69
+ * ```ts
70
+ * import { beamCells } from "@johnmorrisdotca/chikyu-earth/space";
71
+ *
72
+ * console.log(beamCells(19, 2200, 0).lattice.length);
73
+ * ```
74
+ */
75
+ export declare function beamCells(count: number, radiusKm: number, cellKm?: number): BeamCells;
76
+ /**
77
+ * The attributes the beam reads: `beam`, `beam-elevation`, `beam-cells`, `beam-cell-size`, `beam-color` and `beam-strength`.
78
+ *
79
+ * @example
80
+ * ```ts
81
+ * import { BEAM_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/space";
82
+ *
83
+ * console.log(BEAM_ATTRIBUTES.join(" "));
84
+ * ```
85
+ */
86
+ export declare const BEAM_ATTRIBUTES: readonly ["beam", "beam-elevation", "beam-cells", "beam-cell-size", "beam-color", "beam-strength"];
87
+ /**
88
+ * What the attributes say: whether the beam is on, and its options.
89
+ *
90
+ * @example
91
+ * ```ts no-run
92
+ * import type { BeamOptions } from "@johnmorrisdotca/chikyu-earth/space";
93
+ *
94
+ * const options: BeamOptions = { on: true, elevation: 25, cells: 19, cellSize: 0, colour: "#8fd1ff", strength: 0.6 };
95
+ * console.log(options.cells);
96
+ * ```
97
+ */
98
+ export interface BeamOptions {
99
+ on: boolean;
100
+ elevation: number;
101
+ cells: number;
102
+ cellSize: number;
103
+ colour: string;
104
+ strength: number;
105
+ }
106
+ /**
107
+ * The beam's colour when the page names none: a pale blue that reads on the day side and the night side.
108
+ *
109
+ * @example
110
+ * ```ts
111
+ * import { BEAM_COLOUR } from "@johnmorrisdotca/chikyu-earth/space";
112
+ *
113
+ * console.log(BEAM_COLOUR);
114
+ * ```
115
+ */
116
+ export declare const BEAM_COLOUR = "#8fd1ff";
117
+ /**
118
+ * What the beam's attributes say. `beam` is off when it is missing, `off` or `false`; a bare attribute, `selected` or `on` switches it on for the chosen satellite. The strength is from 0 to 1 (0.6 when left out),
119
+ * the elevation from 0 to 80 degrees (25), the cells from 0 to 91 (none) and the cell size in kilometres (0 for the fit).
120
+ *
121
+ * @param get - Reads an attribute by name, `null` when it is missing.
122
+ * @returns The options.
123
+ * @example
124
+ * ```ts
125
+ * import { readBeam } from "@johnmorrisdotca/chikyu-earth/space";
126
+ *
127
+ * const read = readBeam((name) => ({ beam: "selected", "beam-cells": "19" })[name] ?? null);
128
+ * console.log(read.on, read.cells);
129
+ * ```
130
+ */
131
+ export declare function readBeam(get: (name: string) => string | null): BeamOptions;
@@ -0,0 +1,141 @@
1
+ // The beam from a satellite to the ground below it: the true size of the footprint, and the pattern of spot cells drawn inside it. Pure: numbers in, numbers out.
2
+ // The footprint is the circle on the ground from which the satellite stands above a stated elevation; the cells are an illustration, never an operator's beam plan.
3
+ const RAD = Math.PI / 180;
4
+ /** The Earth's mean radius in kilometres, as the space view measures: the same 6,371. */
5
+ const EARTH_KM = 6371;
6
+ /**
7
+ * The elevation, in degrees, above which a satellite counts as seen from the ground: the footprint is the circle from which it stands at least this high.
8
+ *
9
+ * @example
10
+ * ```ts
11
+ * import { BEAM_ELEVATION } from "@johnmorrisdotca/chikyu-earth/space";
12
+ *
13
+ * console.log(BEAM_ELEVATION);
14
+ * ```
15
+ */
16
+ export const BEAM_ELEVATION = 25;
17
+ /**
18
+ * The angle at the Earth's centre between the point below a satellite and the edge of its footprint, in radians: the ground circle from which the satellite is above `elevation`.
19
+ * It is `acos(R cos(e) / (R + h)) - e` for the Earth's radius R, the height h and the elevation e. A satellite on or under the ground, or an elevation of 90 degrees or more, has none.
20
+ *
21
+ * @param heightKm - The satellite's height above the ground, in kilometres.
22
+ * @param elevation - The least elevation, in degrees. 25 when left out.
23
+ * @returns The angle, in radians, from 0 up to a quarter of a turn.
24
+ * @example
25
+ * ```ts
26
+ * import { footprintAngle } from "@johnmorrisdotca/chikyu-earth/space";
27
+ *
28
+ * console.log((footprintAngle(420) * 180) / Math.PI);
29
+ * ```
30
+ */
31
+ export function footprintAngle(heightKm, elevation = BEAM_ELEVATION) {
32
+ if (!(heightKm > 0) || !(elevation < 90))
33
+ return 0;
34
+ const e = Math.max(0, elevation) * RAD;
35
+ const cosine = (EARTH_KM * Math.cos(e)) / (EARTH_KM + heightKm);
36
+ return Math.max(0, Math.acos(Math.min(1, cosine)) - e);
37
+ }
38
+ /**
39
+ * The radius of a satellite's footprint along the ground, in kilometres: the Earth's radius times {@link footprintAngle}.
40
+ *
41
+ * @param heightKm - The satellite's height above the ground, in kilometres.
42
+ * @param elevation - The least elevation, in degrees. 25 when left out.
43
+ * @returns The radius in kilometres.
44
+ * @example
45
+ * ```ts
46
+ * import { footprintKm } from "@johnmorrisdotca/chikyu-earth/space";
47
+ *
48
+ * console.log(Math.round(footprintKm(550)));
49
+ * ```
50
+ */
51
+ export const footprintKm = (heightKm, elevation = BEAM_ELEVATION) => EARTH_KM * footprintAngle(heightKm, elevation);
52
+ /** A cell's radius as a share of the distance between neighbours: a little under a half, so the rings of neighbours do not touch. */
53
+ const CELL_SHARE = 0.46;
54
+ /** How far out the outer edge of the outermost cell may reach, as a share of the footprint's radius. */
55
+ const FIT = 0.97;
56
+ /**
57
+ * The spot cells of a footprint: `count` circles in a hexagonal pack (the middle one, then the nearest to it), drawn to fit inside the footprint, or at most `cellKm` in radius when that is smaller.
58
+ * It is an illustration of a satellite that serves the ground in cells; it is not the pattern of any operator's beam plan.
59
+ *
60
+ * @param count - How many cells (0 for none; the most is 91, six rings).
61
+ * @param radiusKm - The footprint's radius along the ground, in kilometres.
62
+ * @param cellKm - A cell's radius in kilometres, when the page wants it smaller than the fit; 0 for the fit.
63
+ * @returns The cells.
64
+ * @example
65
+ * ```ts
66
+ * import { beamCells } from "@johnmorrisdotca/chikyu-earth/space";
67
+ *
68
+ * console.log(beamCells(19, 2200, 0).lattice.length);
69
+ * ```
70
+ */
71
+ export function beamCells(count, radiusKm, cellKm = 0) {
72
+ const wanted = Math.max(0, Math.min(91, Math.floor(Number.isFinite(count) ? count : 0)));
73
+ const lattice = [];
74
+ const reach = 6;
75
+ for (let j = -reach; j <= reach; j += 1)
76
+ for (let i = -reach; i <= reach; i += 1)
77
+ lattice.push([i + j / 2, (j * Math.sqrt(3)) / 2]);
78
+ lattice.sort((a, b) => Math.hypot(a[0], a[1]) - Math.hypot(b[0], b[1]) || Math.atan2(a[1], a[0]) - Math.atan2(b[1], b[0]));
79
+ const taken = lattice.slice(0, wanted);
80
+ const far = taken.reduce((most, point) => Math.max(most, Math.hypot(point[0], point[1])), 0);
81
+ let pitch = FIT / (far + CELL_SHARE);
82
+ let radius = CELL_SHARE * pitch;
83
+ if (cellKm > 0 && radiusKm > 0 && cellKm / radiusKm < radius) {
84
+ radius = cellKm / radiusKm;
85
+ pitch = radius / CELL_SHARE;
86
+ }
87
+ return { lattice: taken, pitch, radius };
88
+ }
89
+ /**
90
+ * The attributes the beam reads: `beam`, `beam-elevation`, `beam-cells`, `beam-cell-size`, `beam-color` and `beam-strength`.
91
+ *
92
+ * @example
93
+ * ```ts
94
+ * import { BEAM_ATTRIBUTES } from "@johnmorrisdotca/chikyu-earth/space";
95
+ *
96
+ * console.log(BEAM_ATTRIBUTES.join(" "));
97
+ * ```
98
+ */
99
+ export const BEAM_ATTRIBUTES = ["beam", "beam-elevation", "beam-cells", "beam-cell-size", "beam-color", "beam-strength"];
100
+ /**
101
+ * The beam's colour when the page names none: a pale blue that reads on the day side and the night side.
102
+ *
103
+ * @example
104
+ * ```ts
105
+ * import { BEAM_COLOUR } from "@johnmorrisdotca/chikyu-earth/space";
106
+ *
107
+ * console.log(BEAM_COLOUR);
108
+ * ```
109
+ */
110
+ export const BEAM_COLOUR = "#8fd1ff";
111
+ const number = (value, fallback, least, most) => {
112
+ const read = value === null || value.trim() === "" ? Number.NaN : Number(value);
113
+ return Number.isFinite(read) ? Math.min(most, Math.max(least, read)) : fallback;
114
+ };
115
+ /**
116
+ * What the beam's attributes say. `beam` is off when it is missing, `off` or `false`; a bare attribute, `selected` or `on` switches it on for the chosen satellite. The strength is from 0 to 1 (0.6 when left out),
117
+ * the elevation from 0 to 80 degrees (25), the cells from 0 to 91 (none) and the cell size in kilometres (0 for the fit).
118
+ *
119
+ * @param get - Reads an attribute by name, `null` when it is missing.
120
+ * @returns The options.
121
+ * @example
122
+ * ```ts
123
+ * import { readBeam } from "@johnmorrisdotca/chikyu-earth/space";
124
+ *
125
+ * const read = readBeam((name) => ({ beam: "selected", "beam-cells": "19" })[name] ?? null);
126
+ * console.log(read.on, read.cells);
127
+ * ```
128
+ */
129
+ export function readBeam(get) {
130
+ const word = get("beam");
131
+ const on = word !== null && !["off", "false", "none"].includes(word.trim().toLowerCase());
132
+ const colour = (get("beam-color") ?? "").trim();
133
+ return {
134
+ on,
135
+ elevation: number(get("beam-elevation"), BEAM_ELEVATION, 0, 80),
136
+ cells: Math.floor(number(get("beam-cells"), 0, 0, 91)),
137
+ cellSize: number(get("beam-cell-size"), 0, 0, 5000),
138
+ colour: /^#[0-9a-f]{3,8}$|^[a-z]+$|^(rgb|hsl)a?\(/i.test(colour) ? colour : BEAM_COLOUR,
139
+ strength: number(get("beam-strength"), 0.6, 0, 1),
140
+ };
141
+ }
@@ -0,0 +1,47 @@
1
+ import type * as THREE from "three";
2
+ import type { ThreeParts } from "../realistic/textures.ts";
3
+ import { type BeamOptions } from "./geometry.ts";
4
+ /**
5
+ * What the beam has done: whether it is drawn, the chosen satellite's height, the footprint's radius along the ground in kilometres and its angle at the Earth's centre, the elevation it was worked for,
6
+ * the cells drawn and a cell's radius in kilometres, and how many times its geometry was made.
7
+ *
8
+ * @example
9
+ * ```ts no-run
10
+ * import type { BeamStats } from "@johnmorrisdotca/chikyu-earth/space";
11
+ *
12
+ * const none: BeamStats = { shown: false, heightKm: 0, radiusKm: 0, angleDegrees: 0, elevation: 25, cells: 0, cellRadiusKm: 0, builds: 0, failed: false };
13
+ * console.log(none);
14
+ * ```
15
+ */
16
+ export interface BeamStats {
17
+ shown: boolean;
18
+ heightKm: number;
19
+ radiusKm: number;
20
+ angleDegrees: number;
21
+ elevation: number;
22
+ cells: number;
23
+ cellRadiusKm: number;
24
+ builds: number;
25
+ failed: boolean;
26
+ }
27
+ /** What the element and the scene share: the options the attributes give, and what the beam did. */
28
+ export interface BeamState extends BeamOptions {
29
+ onError?: (error: unknown) => void;
30
+ stats: BeamStats;
31
+ }
32
+ export declare const newBeamState: () => BeamState;
33
+ export interface BeamLayer {
34
+ /** Places the beam for this draw: the chosen satellite's place in Earth radii (the scene's axes), or `null` for none. */
35
+ sync(position: readonly [number, number, number] | null): void;
36
+ dispose(): void;
37
+ }
38
+ /**
39
+ * Makes the beam in `scene` (the world the satellites are in, not the Earth's turning group: the footprint is worked out for the satellite's place now).
40
+ *
41
+ * @param three - The page's three.js; it must have `AdditiveBlending`.
42
+ * @param scene - The scene the satellites are in.
43
+ * @param state - The model's beam.
44
+ * @param order - The render order: after the satellites' dots.
45
+ * @returns The layer.
46
+ */
47
+ export declare function createBeamLayer(three: ThreeParts, scene: THREE.Object3D, state: BeamState, order: number): BeamLayer;