@johnmorrisdotca/wakusei-planets 0.68.0 → 0.69.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,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.69.0] - 2026-11-19
4
+
5
+ - **Beams for places on any body: `bodyPlaces` / `body-places`** (MODULES-1568). `<wakusei-space>` drew a reader's places (`earth-places`) on the Earth only. A list `{ body, id, lon, lat, label, kind, color }` now stands them on the Moon, Mars, any planet or catalogue moon the view draws, as the same beam, pin or ring (`earth-places-look`), with the same colours, names, limits (32 markers in all, the reader's `here` first; nothing on a body under 40 CSS pixels of radius; hidden on the far side and under another body's disc; never over a body's name; 5,000 kept) and the same chikyu-earth layout and import (`/earth-places`: no new peer). `space.bodyPlacesShown` reads what was laid, `{ marks: [{ body, id, kind, x, y, named }], omitted }`; `readBodyPlaces` of `/earth-places` reads the attribute. `/places/search` makes the list from saved ids: `loadPlaceHits(ids)` (an old id is made current by `resolvePlaceId`; only the lists the ids need are fetched) and `hitToBodyPlace(hit, { lang, kind, color, label })`. The standing view's sky has no beams yet. `/space/element` grew by 1.7 kB gzipped (993,995 B, from 992,332 B), `/earth-places` by 205 B (2,463 B) and `/places/search` by 347 B; their baselines are updated.
6
+ - **`wakusei-body-place`: one press for every beam** (MODULES-1568). A still tap (under 6 pixels) that ends on a drawn name or a foot ring, on the Earth's places and on the other bodies', sends `wakusei-body-place` (bubbling, composed) with `detail: { body, id, kind, x, y }` (`body: "earth"` for the Earth's; `id` and `kind` as chikyu-earth's planned `chikyu-place-click`). The layers still take no pointer, so a drag that starts on a name still turns the view, and a tap that is a beam's does not also press the body under it. What a press does is the page's to decide. No keyboard press: beams stay hidden from assistive technology.
7
+ - **The `wakusei-sight` event keeps its spacing** (MODULES-1595). A timer can fire a few milliseconds early (CI heard two events 244 ms apart); the wait is now made good, so two events are never closer than the 250 ms the property promises.
8
+ - **Pages publishes again** (MODULES-1592). The site had not been published since 2026-11-18: on the Ubuntu 26.04 runner Python 3.14 could not verify svs.gsfc.nasa.gov (Let's Encrypt's new root YR is not in the system store). The tile and terrain scripts keep verifying every certificate and name, now against certifi's list, and the workflow caches the downloaded source maps on their SHA-256.
9
+ - **Tests and CI** (MODULES-1595, MODULES-1524, MODULES-1590). The soak gives a burst of objects 45 s to be let go before it fails (a leak never is), glide=off and the travel pace test wait on state, not on a draw already made, every demo spec takes the CPU throttle switch and a test fails one that does not, and a manual CI run can run only the soak for as long as asked.
10
+
3
11
  ## [0.68.0] - 2026-11-19
4
12
 
5
13
  - **Every catalogue moon in the space view, and a moon list by family** (MODULES-1564). `moons="all"` draws every moon of `/moon-catalogue` as a pressable dot with its orbit, per planet (`moons-of="jupiter saturn"`) or for all planets at once (`all-moons`); `moons="major"` stays the default. `moon-colors="group"` or `"direction"` colours the orbits, and `moonOrbitKey(by)` returns the key as data. The dots and orbits are drawn once and again only when the scale, the colouring or the month changes; nothing runs at rest. `moonFamilies(host)` lists a planet's moons by family (Jupiter: Galilean, inner, Himalia, Ananke, Carme, Pasiphae, other irregulars; Saturn: inner and major, Inuit, Gallic, Norse; Uranus and Neptune: inner and major, irregular) with counts, sizes where known and a flag for estimated sizes. The audit against JPL's Planetary Satellite pages and Horizons on 2026-11-18 found no new moons: Earth 1, Mars 2, Jupiter 115, Saturn 293, Uranus 29, Neptune 16, Pluto 5, dwarf planets 7 (468 in all), the same as 2026-11-11. English and Japanese guides, tests and the size budget are updated. `/moon-catalogue` grows from just under 45 kB to 45.1 kB gzipped for the orbit, family and colour-key functions, so its budget in `test/moon-catalogue.test.ts` goes from 45,000 to 46,000 bytes; the space element's own chunk is unchanged.
@@ -14,6 +22,8 @@
14
22
  - **The Moon's ring stays when the view is close to the Earth** (MODULES-1569, first part). With the orbits on, the Moon's orbit round the Earth vanished in a close view of the Earth. A body's own line is let go near it (faded from 3 radii out to 12) so that no line crosses its disc, which is right for a planet's own line, which passes through the planet; but the Moon's ring round the Earth never meets the Earth, and in the squeezed scale it lies 4 to 5 Earth radii out, inside that band, so it kept under a fifth of its colour and was gone. Now only a line that passes through the close body is faded (the Earth's own line round the Sun, a planet's, and the Moon's ring when it is the Moon that is close). `stats.orbits` gains `faded`, the lines faded at the last draw. The rule is `src/space/orbit-rules.ts` (`isOwnLine`, `fadesNearBody`, `nearBodyKeep`). Tests: `test/orbit-rules.test.ts` and `e2e/space-moon-ring.demo.ts` (the picture with the orbits on differs from the one with them off, and CI keeps both pictures). The hover and the fade with the number of lines are the rest of the ticket.
15
23
  - **Wording in the guides**: the Japanese surface guide's glide paragraph (`動きにかかる時間`, `(クリックやタップ)`, `動いている最中`) and the Japanese body-physics heading (`データのない天体`) as the reviewer suggested, and both body-physics guides give NSSDC its current name, NASA Space Science Data Coordinated Archive, as `NOTICE.md` does.
16
24
 
25
+ - **A test fails when an e2e spec does not take `CPU_THROTTLE`** (MODULES-1590). `test/e2e-load.test.ts` (in `pnpm check`, no browser) reads the specs that `playwright.config.ts` runs and names each one that neither imports `e2e/load.ts` or `e2e/under-load.ts` nor sends the CPU throttle itself, with the line to add. Five specs are exempt, each with its reason in the test: `docs-site.demo.mjs` (the family's file, held to a hash) and four freeze tests that count draws and graphics objects. The three specs that missed it are fixed by MODULES-1524.
26
+
17
27
  ## [0.67.0] - 2026-11-18
18
28
 
19
29
  - **`<wakusei-surface>`: the camera glides from the watched descent to the standing view, to the rover and between its two cameras, with no jump cut** (MODULES-1561). When `watch` is taken off, `drive="on"` starts or the watch's camera changes, the camera moves from where the watched descent (the window or the ground camera) had it to the new view in 1.1 seconds, easing out and in, with the eye keeping its height above the ground so that it does not pass under a hill, the azimuth turning the short way and the field of view blended. New attribute `glide` (`off` for the cut, or the milliseconds), new `camera` (the pose of the last draw) and `stats.gliding`; a reader who prefers reduced motion gets the cut, and a press or a key on the view ends the move. A move from a move (the watch ends, then the rover starts) goes on from where the first had got to. Switching between the window and the ground camera while watching (or moving where the ground camera stands with `watch-from`) is a move too. Tests: `test/glide.test.ts` (the curve, the blend, the heights, and when a move starts) and `e2e/surface-glide.demo.ts` (the pose of each draw is sampled on the way: no step is most of the way, it arrives, `glide=off` and reduced motion cut).
package/README.md CHANGED
@@ -19,7 +19,7 @@ Wakusei Planets runs in the browser of a phone, a tablet or a computer: nothing
19
19
 
20
20
  <p align="center"><img alt="The demo on a desk: Saturn in the painted look, turning in the big view, with the page's links to the portrait builder, the colouring sheets, the space view, the star page and the size line-up above it, and the choice of body and its moons below" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-desk.webp" width="620"> <img alt="The same page on a phone: the same links in rows, and Saturn in the painted look below them" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/main/docs/images/home-phone.webp" width="200"></p>
21
21
 
22
- <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.68.0/docs/images/lineup-desk.png" width="640"></p>
22
+ <p align="center"><img alt="Every body at one scale, the Earth among them: each small body has a magnified picture joined by a line, and the Sun shows only its edge" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.69.0/docs/images/lineup-desk.png" width="640"></p>
23
23
 
24
24
  ## Who it is for
25
25
 
@@ -412,7 +412,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
412
412
 
413
413
  ## The portrait builder
414
414
 
415
- <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.68.0/docs/images/portrait-family.png" width="640"></p>
415
+ <p align="center"><img alt="The Sun and the planets in an arc, painted, with their names, in the portrait builder" src="https://raw.githubusercontent.com/johnmorrisdotca/wakusei-planets/v0.69.0/docs/images/portrait-family.png" width="640"></p>
416
416
 
417
417
  [The portrait builder](https://johnmorrisdotca.github.io/wakusei-planets/portrait.html) puts any bodies in one picture: drag them, size them, turn them, order them front to back, arrange them in a row, an arc, a grid or at true orbit distance (true or readable sizes, a planet's moons round it in orbit order), light them from one direction, and take the code, a PNG or an SVG. The scene is kept in the address, and every body is drawn in one WebGL scene, so the page holds one WebGL context. [The portrait builder](docs/guides/portrait-builder.md) is its guide.
418
418
 
@@ -568,7 +568,7 @@ BODIES.pluto.kind; // "dwarf-planet"
568
568
 
569
569
  If this package helps a paper, a talk or a class, please cite it as software. GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA; in plain text:
570
570
 
571
- > Morris, J. (2026). *Wakusei Planets* (version 0.68.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
571
+ > Morris, J. (2026). *Wakusei Planets* (version 0.69.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
572
572
 
573
573
  Cite the version you used (`npm ls @johnmorrisdotca/wakusei-planets`), and cite the sources of the numbers you use as well: [NOTICE.md](NOTICE.md) names each one, with the paper or the page it was read from (the IAU working group's report for sizes and poles, VSOP87B, ELP2000-82B, L1.2 and TASS1.7 for positions, and NASA's JPL Horizons for the fits and the spacecraft).
574
574
 
@@ -1,6 +1,7 @@
1
1
  import { type SurfaceView } from "./place-marks.ts";
2
+ import { type PlaceOnBody } from "./scene/body-places.ts";
2
3
  import { type EarthPlace, type EarthPlaceLayout, type EarthPlaceLayoutOptions, type EarthPlaceLook } from "./scene/earth-places.ts";
3
- export type { EarthPlace, EarthPlaceLayout, EarthPlaceLayoutOptions, EarthPlaceLook };
4
+ export type { PlaceOnBody, EarthPlace, EarthPlaceLayout, EarthPlaceLayoutOptions, EarthPlaceLook };
4
5
  export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "./scene/earth-places.ts";
5
6
  /**
6
7
  * Read the text of the `earth-places` attribute (a JSON array) as the list the views draw: each place needs a longitude from -180 to 180 and a latitude from -90 to 90, one without an `id` is given its place in the list, a label is
@@ -38,3 +39,18 @@ export declare function readEarthPlaces(value: string | null | undefined): Earth
38
39
  * ```
39
40
  */
40
41
  export declare function layEarthPlaces(places: readonly EarthPlace[], view: SurfaceView, look: EarthPlaceLook, options?: EarthPlaceLayoutOptions): EarthPlaceLayout;
42
+ /**
43
+ * Read the text of the `body-places` attribute (a JSON array) as the list `<wakusei-space>` draws on bodies other than the Earth: each entry is an `earth-places` entry with the `body` it is on (lower case, not `earth`). They are grouped by body and each group is read by
44
+ * `readEarthPlaces`, so the same limits hold (a longitude from -180 to 180, a latitude from -90 to 90, a label of 80 letters, `here` or `favourite`, a safe colour, 5,000 at most). An entry without a valid `body` is left out.
45
+ *
46
+ * @param value - The attribute's text, or null.
47
+ * @returns The places to draw, the bodies in the order they first appear.
48
+ *
49
+ * @example
50
+ * ```ts
51
+ * import { readBodyPlaces } from "@johnmorrisdotca/wakusei-planets/earth-places";
52
+ *
53
+ * console.log(readBodyPlaces('[{"body":"moon","id":"a","lon":10,"lat":5},{"body":"earth","id":"b","lon":0,"lat":0},{"lon":1,"lat":1}]').map((place) => `${place.body}:${place.id}`));
54
+ * ```
55
+ */
56
+ export declare function readBodyPlaces(value: string | null | undefined): PlaceOnBody[];
@@ -2,6 +2,7 @@
2
2
  // `import "@johnmorrisdotca/wakusei-planets/earth-places"`, and `<wakusei-space earth-places='[...]'>` draws them. A page that never imports it carries none of chikyu-earth, and the attribute draws nothing.
3
3
  import { layoutPlaces, readPlaces } from "@johnmorrisdotca/chikyu-earth/markers";
4
4
  import { spotView } from "./place-marks.js";
5
+ import { readBodyPlacesWith } from "./scene/body-places.js";
5
6
  import { setEarthPlacesLayout } from "./scene/earth-places.js";
6
7
  setEarthPlacesLayout({ read: readPlaces, layout: layoutPlaces });
7
8
  export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS } from "./scene/earth-places.js";
@@ -45,3 +46,20 @@ export function readEarthPlaces(value) {
45
46
  export function layEarthPlaces(places, view, look, options = {}) {
46
47
  return layoutPlaces(places, spotView(view), look, options);
47
48
  }
49
+ /**
50
+ * Read the text of the `body-places` attribute (a JSON array) as the list `<wakusei-space>` draws on bodies other than the Earth: each entry is an `earth-places` entry with the `body` it is on (lower case, not `earth`). They are grouped by body and each group is read by
51
+ * `readEarthPlaces`, so the same limits hold (a longitude from -180 to 180, a latitude from -90 to 90, a label of 80 letters, `here` or `favourite`, a safe colour, 5,000 at most). An entry without a valid `body` is left out.
52
+ *
53
+ * @param value - The attribute's text, or null.
54
+ * @returns The places to draw, the bodies in the order they first appear.
55
+ *
56
+ * @example
57
+ * ```ts
58
+ * import { readBodyPlaces } from "@johnmorrisdotca/wakusei-planets/earth-places";
59
+ *
60
+ * console.log(readBodyPlaces('[{"body":"moon","id":"a","lon":10,"lat":5},{"body":"earth","id":"b","lon":0,"lat":0},{"lon":1,"lat":1}]').map((place) => `${place.body}:${place.id}`));
61
+ * ```
62
+ */
63
+ export function readBodyPlaces(value) {
64
+ return readBodyPlacesWith(value, readPlaces);
65
+ }
@@ -1,3 +1,4 @@
1
+ import type { PlaceOnBody } from "./scene/body-places.ts";
1
2
  import type { Place, PlaceKind } from "./places.ts";
2
3
  /**
3
4
  * One row of a body's search list: the compact record of a point of interest, enough to find it, show it, favourite it and go to it. A favourite stores `id`.
@@ -155,3 +156,24 @@ export declare function searchPlaces(hits: readonly PlaceHit[], query: string, o
155
156
  limit?: number;
156
157
  kinds?: readonly PlaceKind[];
157
158
  }): PlaceHit[];
159
+ /**
160
+ * A hit as a place for `<wakusei-space>`'s `bodyPlaces`: a beam on the ground of the hit's body at its latitude and longitude, named in English or Japanese, the id the hit has (a favourite's id, so a press says which one it was).
161
+ *
162
+ * @param hit - A row of a search list.
163
+ * @param options - `lang` for the label (`en` by default), `kind` (`favourite` by default, or `here`), `color` (a CSS colour for this place alone) and `label` (your own text, or `false` for none).
164
+ * @returns The place to draw.
165
+ *
166
+ * @example
167
+ * ```ts
168
+ * import { hitToBodyPlace, loadPlaceSearch } from "@johnmorrisdotca/wakusei-planets/places/search";
169
+ *
170
+ * const olympus = (await loadPlaceSearch("mars")).find((hit) => hit.id === "mars/olympus-mons")!;
171
+ * console.log(hitToBodyPlace(olympus, { lang: "ja", color: "#ff8844" }));
172
+ * ```
173
+ */
174
+ export declare function hitToBodyPlace(hit: PlaceHit, options?: {
175
+ lang?: "en" | "ja";
176
+ kind?: "here" | "favourite";
177
+ color?: string;
178
+ label?: string | false;
179
+ }): PlaceOnBody;
@@ -196,3 +196,28 @@ export function searchPlaces(hits, query, options = {}) {
196
196
  out.sort((a, b) => a.score - b.score || KIND_ORDER[a.hit.kind] - KIND_ORDER[b.hit.kind] || b.hit.diameterKm - a.hit.diameterKm || (a.hit.name.en < b.hit.name.en ? -1 : a.hit.name.en > b.hit.name.en ? 1 : 0));
197
197
  return out.slice(0, options.limit ?? 20).map((entry) => entry.hit);
198
198
  }
199
+ /**
200
+ * A hit as a place for `<wakusei-space>`'s `bodyPlaces`: a beam on the ground of the hit's body at its latitude and longitude, named in English or Japanese, the id the hit has (a favourite's id, so a press says which one it was).
201
+ *
202
+ * @param hit - A row of a search list.
203
+ * @param options - `lang` for the label (`en` by default), `kind` (`favourite` by default, or `here`), `color` (a CSS colour for this place alone) and `label` (your own text, or `false` for none).
204
+ * @returns The place to draw.
205
+ *
206
+ * @example
207
+ * ```ts
208
+ * import { hitToBodyPlace, loadPlaceSearch } from "@johnmorrisdotca/wakusei-planets/places/search";
209
+ *
210
+ * const olympus = (await loadPlaceSearch("mars")).find((hit) => hit.id === "mars/olympus-mons")!;
211
+ * console.log(hitToBodyPlace(olympus, { lang: "ja", color: "#ff8844" }));
212
+ * ```
213
+ */
214
+ export function hitToBodyPlace(hit, options = {}) {
215
+ const place = { body: hit.body, id: hit.id, lon: hit.lon, lat: hit.lat };
216
+ if (options.label !== false)
217
+ place.label = options.label ?? hit.name[options.lang ?? "en"];
218
+ if (options.kind !== undefined)
219
+ place.kind = options.kind;
220
+ if (options.color !== undefined)
221
+ place.color = options.color;
222
+ return place;
223
+ }
@@ -1,6 +1,6 @@
1
1
  import { type PlaceSearchBody } from "../data/places-search-bodies.ts";
2
- import type { PlaceHit } from "../place-search.ts";
3
- export { hitToPlace, PLACE_KIND_WORDS, placeHitUrl, readPlaceHits, resolvePlaceId, searchPlaces, SEARCH_SOURCE_IDS, type PlaceHit } from "../place-search.ts";
2
+ import { type PlaceHit } from "../place-search.ts";
3
+ export { hitToBodyPlace, hitToPlace, PLACE_KIND_WORDS, placeHitUrl, readPlaceHits, resolvePlaceId, searchPlaces, SEARCH_SOURCE_IDS, type PlaceHit } from "../place-search.ts";
4
4
  export { PLACE_SEARCH_BODIES, type PlaceSearchBody } from "../data/places-search-bodies.ts";
5
5
  /**
6
6
  * The search list of a body, fetched when asked for: the table of `/places/search/<body>` arrives as a chunk of its own the first time, so a page that never searches a body does not carry it. The Moon's 7,064 lettered satellite craters are a chunk
@@ -23,3 +23,20 @@ export { PLACE_SEARCH_BODIES, type PlaceSearchBody } from "../data/places-search
23
23
  export declare function loadPlaceSearch(body: PlaceSearchBody, options?: {
24
24
  satellites?: boolean;
25
25
  }): Promise<readonly PlaceHit[]>;
26
+ /**
27
+ * The rows for a set of saved ids: each id is made current (`resolvePlaceId`), and only the lists the ids need are fetched, the Moon's lettered craters only for an id the Moon's own list does not have. For a favourites page: the ids it saved in, the rows (and so the beams,
28
+ * `hitToBodyPlace`) out.
29
+ *
30
+ * @param ids - Place ids, as `PlaceHit.id` of an earlier visit or an earlier release.
31
+ * @returns The rows found, in the order of the ids, each once. An id for no body or no place is left out.
32
+ *
33
+ * @example
34
+ * ```ts
35
+ * import { hitToBodyPlace, loadPlaceHits } from "@johnmorrisdotca/wakusei-planets/places/search";
36
+ *
37
+ * const hits = await loadPlaceHits(["moon/tycho", "mars/olympus-mons", "mercury/kunisada-2", "moon/tycho-a", "nowhere/nothing"]);
38
+ * console.log(hits.map((hit) => hit.id).join(", "));
39
+ * console.log(hits.map((hit) => hitToBodyPlace(hit)).length, "beams");
40
+ * ```
41
+ */
42
+ export declare function loadPlaceHits(ids: readonly string[]): Promise<PlaceHit[]>;
@@ -1,6 +1,7 @@
1
1
  // The search lists of every point of interest on every body, and the search over them. The lists are the entry points `/places/search/<body>`, fetched one at a time by `loadPlaceSearch`; see `/places` for the full records of the larger bodies.
2
2
  import { PLACE_SEARCH_BODIES, readSearchTable } from "../data/places-search-bodies.js";
3
- export { hitToPlace, PLACE_KIND_WORDS, placeHitUrl, readPlaceHits, resolvePlaceId, searchPlaces, SEARCH_SOURCE_IDS } from "../place-search.js";
3
+ import { resolvePlaceId } from "../place-search.js";
4
+ export { hitToBodyPlace, hitToPlace, PLACE_KIND_WORDS, placeHitUrl, readPlaceHits, resolvePlaceId, searchPlaces, SEARCH_SOURCE_IDS } from "../place-search.js";
4
5
  export { PLACE_SEARCH_BODIES } from "../data/places-search-bodies.js";
5
6
  /**
6
7
  * The search list of a body, fetched when asked for: the table of `/places/search/<body>` arrives as a chunk of its own the first time, so a page that never searches a body does not carry it. The Moon's 7,064 lettered satellite craters are a chunk
@@ -26,3 +27,51 @@ export async function loadPlaceSearch(body, options = {}) {
26
27
  const list = await readSearchTable(body);
27
28
  return body === "moon" && options.satellites === true ? [...list, ...(await readSearchTable("moon-satellites"))] : list;
28
29
  }
30
+ /**
31
+ * The rows for a set of saved ids: each id is made current (`resolvePlaceId`), and only the lists the ids need are fetched, the Moon's lettered craters only for an id the Moon's own list does not have. For a favourites page: the ids it saved in, the rows (and so the beams,
32
+ * `hitToBodyPlace`) out.
33
+ *
34
+ * @param ids - Place ids, as `PlaceHit.id` of an earlier visit or an earlier release.
35
+ * @returns The rows found, in the order of the ids, each once. An id for no body or no place is left out.
36
+ *
37
+ * @example
38
+ * ```ts
39
+ * import { hitToBodyPlace, loadPlaceHits } from "@johnmorrisdotca/wakusei-planets/places/search";
40
+ *
41
+ * const hits = await loadPlaceHits(["moon/tycho", "mars/olympus-mons", "mercury/kunisada-2", "moon/tycho-a", "nowhere/nothing"]);
42
+ * console.log(hits.map((hit) => hit.id).join(", "));
43
+ * console.log(hits.map((hit) => hitToBodyPlace(hit)).length, "beams");
44
+ * ```
45
+ */
46
+ export async function loadPlaceHits(ids) {
47
+ const wanted = ids.map(resolvePlaceId);
48
+ const bodies = new Set();
49
+ for (const id of wanted) {
50
+ const body = id.split("/")[0];
51
+ if (PLACE_SEARCH_BODIES.includes(body))
52
+ bodies.add(body);
53
+ }
54
+ const found = new Map();
55
+ const need = new Set(wanted);
56
+ for (const body of bodies) {
57
+ for (const hit of await loadPlaceSearch(body))
58
+ if (need.has(hit.id))
59
+ found.set(hit.id, hit);
60
+ }
61
+ // the Moon's lettered craters are a list of their own, fetched only for an id the Moon's other list does not hold
62
+ if (bodies.has("moon") && wanted.some((id) => id.startsWith("moon/") && !found.has(id))) {
63
+ for (const hit of (await loadPlaceSearch("moon", { satellites: true })).slice((await loadPlaceSearch("moon")).length))
64
+ if (need.has(hit.id))
65
+ found.set(hit.id, hit);
66
+ }
67
+ const out = [];
68
+ const seen = new Set();
69
+ for (const id of wanted) {
70
+ const hit = found.get(id);
71
+ if (hit !== undefined && !seen.has(id)) {
72
+ seen.add(id);
73
+ out.push(hit);
74
+ }
75
+ }
76
+ return out;
77
+ }
@@ -0,0 +1,98 @@
1
+ import type { Vec3 } from "../vec.ts";
2
+ import { type EarthPlace, type EarthPlaceLayout, type EarthPlaceMark, type EarthPlaceLook, type EarthPlacesLayout } from "./earth-places.ts";
3
+ /**
4
+ * One place for the `body-places` attribute or the `bodyPlaces` property of `<wakusei-space>`: an `EarthPlace` and the body it is on. `/places/search` makes them from the rows of a search list (`hitToBodyPlace`).
5
+ *
6
+ * @example
7
+ * ```ts
8
+ * import type { PlaceOnBody } from "@johnmorrisdotca/wakusei-planets/space/element";
9
+ *
10
+ * const places: PlaceOnBody[] = [
11
+ * { body: "moon", id: "moon/apollo-11-lunar-module", lon: 23.4731, lat: 0.6742, label: "Apollo 11 lunar module", kind: "favourite" },
12
+ * { body: "mars", id: "mars/olympus-mons", lon: -133.803, lat: 18.653, label: "Olympus Mons" },
13
+ * ];
14
+ * console.log(places.length);
15
+ * ```
16
+ */
17
+ export interface PlaceOnBody extends EarthPlace {
18
+ /** The body it is on: `moon`, `mars`, `ceres`, `io`. The Earth's places are `earth-places`; one named `earth` here is not drawn. */
19
+ body: string;
20
+ }
21
+ /**
22
+ * What the layer drew for one place on a body: its body, id and kind, where its foot is (CSS pixels from the view's top left) and whether its name is drawn.
23
+ *
24
+ * @example
25
+ * ```ts
26
+ * import type { PlaceOnBodyMark } from "@johnmorrisdotca/wakusei-planets/space/element";
27
+ *
28
+ * const mark: PlaceOnBodyMark = { body: "moon", id: "moon/tycho", kind: "favourite", x: 210, y: 300, named: true };
29
+ * console.log(mark.body, mark.named);
30
+ * ```
31
+ */
32
+ export type PlaceOnBodyMark = EarthPlaceMark & {
33
+ body: string;
34
+ };
35
+ /** The most places kept from a list, as `earth-places` keeps. */
36
+ export declare const BODY_PLACES_KEPT = 5000;
37
+ /**
38
+ * Read the text of the `body-places` attribute (a JSON array) as the list the view draws. Each entry needs a `body` (lower case letters, digits and hyphens, not `earth`) and what an `earth-places` entry needs: they are grouped by body and each group
39
+ * is read by chikyu-earth's own reader, so a longitude from -180 to 180, a latitude from -90 to 90, a label of 80 letters at most, `here` or `favourite` and a safe colour mean the same here. An entry that fails is left out; a text that is not a list is no list.
40
+ *
41
+ * @param value - The attribute's text, or null.
42
+ * @param read - chikyu-earth's `readPlaces`: the text of one body's list to the places to draw.
43
+ * @returns The places, bodies in the order they first appear, at most 5,000.
44
+ */
45
+ export declare function readBodyPlacesWith(value: string | null | undefined, read: (text: string) => EarthPlace[]): PlaceOnBody[];
46
+ /** The bodies a list has places on, in the order they first appear. */
47
+ export declare const bodiesOf: (places: readonly PlaceOnBody[]) => string[];
48
+ /** A body as one draw left it: what `onSurface` gives, and `sun`, the direction of the Sun from the body in the scene (null with the light `lit`, or for a body the Sun's direction is not worked out for). */
49
+ export interface BodySurface {
50
+ id: string;
51
+ centre: Vec3;
52
+ radius: number;
53
+ pole: Vec3;
54
+ meridian: Vec3;
55
+ eye: Vec3;
56
+ project(point: Vec3): {
57
+ x: number;
58
+ y: number;
59
+ } | null;
60
+ width: number;
61
+ height: number;
62
+ radiusPx: number;
63
+ sun: Vec3 | null;
64
+ }
65
+ /** The body's shape as the places lie on it: its three axes where it has them, else its flattening, as the marks of `places` do. */
66
+ export declare function bodyScale(id: string): Vec3 | undefined;
67
+ /** What the view tells the layout about names. */
68
+ export interface BodyLayoutOptions {
69
+ /** How wide a name is, in CSS pixels. */
70
+ width(text: string): number;
71
+ /** Boxes already used by other names. */
72
+ taken: readonly {
73
+ left: number;
74
+ top: number;
75
+ width: number;
76
+ height: number;
77
+ }[];
78
+ /** Whether a body is under another's disc (its places are not drawn). */
79
+ covered?: (id: string) => boolean;
80
+ /** The most markers in all (`EARTH_PLACE_MARKS` by default). */
81
+ marks?: number;
82
+ }
83
+ /**
84
+ * Lay the places of every body in sight in one go: for each body of `surfaces` with places in the list, big enough on the screen (`EARTH_PLACES_FROM_PX` CSS pixels of radius) and not covered, chikyu-earth's layout on that body's picture, names keeping
85
+ * clear of each other across bodies. The markers of `here` places come first, then the rest in the order given, and only the first `marks` stand up; the rest are counted in `omitted`.
86
+ *
87
+ * @param places - The places, as `readBodyPlaces` makes them.
88
+ * @param surfaces - The bodies as the last draw left them.
89
+ * @param using - chikyu-earth's reading and layout.
90
+ * @param look - `beam`, `pin` or `ring`.
91
+ * @param options - The width of a name, the boxes in use and which bodies are covered.
92
+ * @returns The places the shapes index, the layout of all of them, and how many were left out for the limit.
93
+ */
94
+ export declare function layBodyPlaces(places: readonly PlaceOnBody[], surfaces: readonly BodySurface[], using: EarthPlacesLayout, look: EarthPlaceLook, options: BodyLayoutOptions): {
95
+ places: PlaceOnBody[];
96
+ layout: EarthPlaceLayout;
97
+ omitted: number;
98
+ };
@@ -0,0 +1,113 @@
1
+ // The places laid on any body in `<wakusei-space>`: a reader's own place and the places they keep on the Moon, Mars or any other body the view draws, each a marker standing out of the ground, the same one `earth-places` draws on the Earth.
2
+ // The layout is chikyu-earth's (handed in by `@johnmorrisdotca/wakusei-planets/earth-places`, an optional peer this file never imports): its `layoutPlaces` works on any body's picture, so here is only what is about bodies: the list
3
+ // keyed by body, reading it, and laying the lists of several bodies in one draw. Pure: no DOM, no clock reads.
4
+ import { BODIES } from "../facts.js";
5
+ import { pointUnder, spotView } from "../place-marks.js";
6
+ import { EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX } from "./earth-places.js";
7
+ /** The most places kept from a list, as `earth-places` keeps. */
8
+ export const BODY_PLACES_KEPT = 5000;
9
+ /**
10
+ * Read the text of the `body-places` attribute (a JSON array) as the list the view draws. Each entry needs a `body` (lower case letters, digits and hyphens, not `earth`) and what an `earth-places` entry needs: they are grouped by body and each group
11
+ * is read by chikyu-earth's own reader, so a longitude from -180 to 180, a latitude from -90 to 90, a label of 80 letters at most, `here` or `favourite` and a safe colour mean the same here. An entry that fails is left out; a text that is not a list is no list.
12
+ *
13
+ * @param value - The attribute's text, or null.
14
+ * @param read - chikyu-earth's `readPlaces`: the text of one body's list to the places to draw.
15
+ * @returns The places, bodies in the order they first appear, at most 5,000.
16
+ */
17
+ export function readBodyPlacesWith(value, read) {
18
+ if (typeof value !== "string" || value === "")
19
+ return [];
20
+ let parsed;
21
+ try {
22
+ parsed = JSON.parse(value);
23
+ }
24
+ catch {
25
+ return [];
26
+ }
27
+ if (!Array.isArray(parsed))
28
+ return [];
29
+ const groups = new Map();
30
+ for (const entry of parsed) {
31
+ if (typeof entry !== "object" || entry === null)
32
+ continue;
33
+ const body = entry.body;
34
+ if (typeof body !== "string" || !/^[a-z0-9-]{1,40}$/.test(body) || body === "earth")
35
+ continue;
36
+ const rest = { ...entry };
37
+ delete rest["body"];
38
+ const group = groups.get(body);
39
+ if (group === undefined)
40
+ groups.set(body, [rest]);
41
+ else
42
+ group.push(rest);
43
+ }
44
+ const out = [];
45
+ for (const [body, group] of groups)
46
+ for (const place of read(JSON.stringify(group)))
47
+ out.push({ ...place, body });
48
+ return out.slice(0, BODY_PLACES_KEPT);
49
+ }
50
+ /** The bodies a list has places on, in the order they first appear. */
51
+ export const bodiesOf = (places) => [...new Set(places.map((place) => place.body))];
52
+ /** The body's shape as the places lie on it: its three axes where it has them, else its flattening, as the marks of `places` do. */
53
+ export function bodyScale(id) {
54
+ const facts = BODIES[id];
55
+ if (facts === undefined)
56
+ return undefined;
57
+ const ax = facts.axesKm;
58
+ return ax ? [ax[1] / facts.radiusKm, ax[2] / facts.radiusKm, ax[0] / facts.radiusKm] : [1, 1 - facts.flattening, 1];
59
+ }
60
+ /**
61
+ * Lay the places of every body in sight in one go: for each body of `surfaces` with places in the list, big enough on the screen (`EARTH_PLACES_FROM_PX` CSS pixels of radius) and not covered, chikyu-earth's layout on that body's picture, names keeping
62
+ * clear of each other across bodies. The markers of `here` places come first, then the rest in the order given, and only the first `marks` stand up; the rest are counted in `omitted`.
63
+ *
64
+ * @param places - The places, as `readBodyPlaces` makes them.
65
+ * @param surfaces - The bodies as the last draw left them.
66
+ * @param using - chikyu-earth's reading and layout.
67
+ * @param look - `beam`, `pin` or `ring`.
68
+ * @param options - The width of a name, the boxes in use and which bodies are covered.
69
+ * @returns The places the shapes index, the layout of all of them, and how many were left out for the limit.
70
+ */
71
+ export function layBodyPlaces(places, surfaces, using, look, options) {
72
+ const merged = [];
73
+ const shapes = [];
74
+ const labels = [];
75
+ const taken = [...options.taken];
76
+ for (const surface of surfaces) {
77
+ if (!(surface.radiusPx >= EARTH_PLACES_FROM_PX) || options.covered?.(surface.id) === true)
78
+ continue;
79
+ const scale = bodyScale(surface.id);
80
+ if (scale === undefined)
81
+ continue;
82
+ // the places that matter most first: where the reader is, then the rest in the order given
83
+ const here = places.filter((place) => place.body === surface.id);
84
+ const mine = [...here.filter((place) => place.kind === "here"), ...here.filter((place) => place.kind !== "here")];
85
+ if (mine.length === 0)
86
+ continue;
87
+ const view = spotView({ ...surface, scale });
88
+ const sun = surface.sun === null ? null : pointUnder(surface.sun, surface.pole, surface.meridian);
89
+ const layoutOptions = {
90
+ size: (place) => (place.label === undefined ? null : { width: options.width(place.label), height: 18 }),
91
+ taken,
92
+ sun,
93
+ };
94
+ const laid = using.layout(mine, view, look, layoutOptions);
95
+ const offset = merged.length;
96
+ merged.push(...mine);
97
+ for (const shape of laid.shapes)
98
+ shapes.push({ ...shape, index: shape.index + offset });
99
+ for (const spot of laid.labels) {
100
+ labels.push({ ...spot, index: spot.index + offset });
101
+ const label = mine[spot.index]?.label;
102
+ if (label !== undefined)
103
+ taken.push({ left: spot.left, top: spot.top, width: options.width(label), height: 18 });
104
+ }
105
+ }
106
+ // the places of the reader come first on every body, then the others; the first few in sight stand up and the rest are counted, never silently left out
107
+ const rank = (shape) => (merged[shape.index]?.kind === "here" ? 0 : 1);
108
+ const ordered = shapes.map((shape, i) => ({ shape, i })).sort((a, b) => rank(a.shape) - rank(b.shape) || a.i - b.i).map((entry) => entry.shape);
109
+ const limit = options.marks ?? EARTH_PLACE_MARKS;
110
+ const kept = ordered.slice(0, limit);
111
+ const keptLabels = labels.filter((spot) => kept.some((shape) => shape.index === spot.index));
112
+ return { places: merged, layout: { shapes: kept, labels: keptLabels }, omitted: ordered.length - kept.length };
113
+ }
@@ -169,6 +169,8 @@ export interface EarthPlaceMark {
169
169
  x: number;
170
170
  y: number;
171
171
  named: boolean;
172
+ /** For a place on a body other than the Earth (`body-places`): the body. */
173
+ body?: string;
172
174
  }
173
175
  /** The markers over one view. */
174
176
  export interface EarthPlaceLayerView {
@@ -185,6 +187,9 @@ export interface EarthPlaceLayerView {
185
187
  * Make the layer of markers inside a view's shadow root, above its picture. It holds a handful of elements made once and kept; a draw only writes the numbers that changed.
186
188
  *
187
189
  * @param root - The view's shadow root.
190
+ * @param options - `press`, called with the mark and the pointer event when a press that did not move ends over a drawn name or a foot ring (the layer itself takes no pointer: a press on it goes on to the view's controls, as a name on a body's surface does).
188
191
  * @returns The layer.
189
192
  */
190
- export declare function createEarthPlaceLayer(root: ShadowRoot): EarthPlaceLayerView;
193
+ export declare function createEarthPlaceLayer(root: ShadowRoot, options?: {
194
+ press?: (mark: EarthPlaceMark, event: PointerEvent) => void;
195
+ }): EarthPlaceLayerView;
@@ -52,9 +52,10 @@ const STYLE = `.wk-eplaces{position:absolute;inset:0;pointer-events:none;overflo
52
52
  * Make the layer of markers inside a view's shadow root, above its picture. It holds a handful of elements made once and kept; a draw only writes the numbers that changed.
53
53
  *
54
54
  * @param root - The view's shadow root.
55
+ * @param options - `press`, called with the mark and the pointer event when a press that did not move ends over a drawn name or a foot ring (the layer itself takes no pointer: a press on it goes on to the view's controls, as a name on a body's surface does).
55
56
  * @returns The layer.
56
57
  */
57
- export function createEarthPlaceLayer(root) {
58
+ export function createEarthPlaceLayer(root, options = {}) {
58
59
  const style = document.createElement("style");
59
60
  style.textContent = STYLE;
60
61
  const box = document.createElement("div");
@@ -73,6 +74,8 @@ export function createEarthPlaceLayer(root) {
73
74
  let context;
74
75
  const pool = [];
75
76
  let shown = [];
77
+ // what is on the screen to press: each drawn mark with its parts and how strongly it shows
78
+ let live = [];
76
79
  const item = (i) => {
77
80
  let it = pool[i];
78
81
  if (it === undefined) {
@@ -101,10 +104,50 @@ export function createEarthPlaceLayer(root) {
101
104
  el.setAttribute(name, value);
102
105
  };
103
106
  const n = (value) => String(Math.round(value * 10) / 10);
107
+ // press: the layer takes no pointer (a press on it goes on to the view's controls, which turn the view), so a press that did not move and ends over a drawn name or a foot ring is the mark's, found here as the marks of
108
+ // a body's surface find a written name. The nearest of the marks whose name's box or ring's box holds the point wins; a mark that is fading out (under a fifth of its strength) cannot be pressed.
109
+ const host = root.host;
110
+ let pressed = null;
111
+ const down = (event) => {
112
+ pressed = event.button === 0 && event.composedPath().includes(host) ? { x: event.clientX, y: event.clientY, id: event.pointerId } : null;
113
+ };
114
+ const up = (event) => {
115
+ const start = pressed;
116
+ pressed = null;
117
+ if (start === null || start.id !== event.pointerId || live.length === 0 || options.press === undefined || Math.hypot(event.clientX - start.x, event.clientY - start.y) > 6)
118
+ return;
119
+ let best;
120
+ for (const entry of live) {
121
+ if (entry.opacity < 0.2)
122
+ continue;
123
+ for (const part of [entry.it.name.hidden ? null : entry.it.name, entry.it.ring.style.display === "none" ? null : entry.it.ring]) {
124
+ if (part === null)
125
+ continue;
126
+ const r = part.getBoundingClientRect();
127
+ const pad = part === entry.it.name ? 0 : 6;
128
+ if (event.clientX < r.left - pad || event.clientX > r.right + pad || event.clientY < r.top - pad || event.clientY > r.bottom + pad)
129
+ continue;
130
+ const away = Math.hypot(event.clientX - (r.left + r.right) / 2, event.clientY - (r.top + r.bottom) / 2);
131
+ if (best === undefined || away < best.away)
132
+ best = { mark: entry.mark, away };
133
+ }
134
+ }
135
+ if (best !== undefined)
136
+ options.press(best.mark, event);
137
+ };
138
+ const cancel = () => {
139
+ pressed = null;
140
+ };
141
+ if (options.press !== undefined) {
142
+ window.addEventListener("pointerdown", down, true);
143
+ window.addEventListener("pointerup", up, true);
144
+ window.addEventListener("pointercancel", cancel, true);
145
+ }
104
146
  return {
105
147
  set(places, layout, look) {
106
148
  const named = new Map(layout.labels.map((spot) => [spot.index, spot]));
107
149
  shown = [];
150
+ live = [];
108
151
  for (const [i, shape] of layout.shapes.entries()) {
109
152
  const place = places[shape.index];
110
153
  const it = item(i);
@@ -147,7 +190,12 @@ export function createEarthPlaceLayer(root) {
147
190
  }
148
191
  else
149
192
  it.name.hidden = true;
150
- shown.push({ id: place.id, kind: here ? "here" : "favourite", x: shape.x, y: shape.y, named: spot !== undefined });
193
+ const mark = { id: place.id, kind: here ? "here" : "favourite", x: shape.x, y: shape.y, named: spot !== undefined };
194
+ const body = place.body;
195
+ if (body !== undefined)
196
+ mark.body = body;
197
+ shown.push(mark);
198
+ live.push({ mark, it, opacity: shape.opacity * dim });
151
199
  }
152
200
  for (let i = layout.shapes.length; i < pool.length; i += 1) {
153
201
  const it = pool[i];
@@ -161,6 +209,7 @@ export function createEarthPlaceLayer(root) {
161
209
  it.name.hidden = true;
162
210
  }
163
211
  shown = [];
212
+ live = [];
164
213
  },
165
214
  width(text) {
166
215
  const known = widths.get(text);
@@ -181,10 +230,14 @@ export function createEarthPlaceLayer(root) {
181
230
  return shown;
182
231
  },
183
232
  dispose() {
233
+ window.removeEventListener("pointerdown", down, true);
234
+ window.removeEventListener("pointerup", up, true);
235
+ window.removeEventListener("pointercancel", cancel, true);
184
236
  box.remove();
185
237
  style.remove();
186
238
  pool.length = 0;
187
239
  shown = [];
240
+ live = [];
188
241
  },
189
242
  };
190
243
  }
@@ -20,11 +20,13 @@ import { type MoonsChoice } from "./moon-settings.ts";
20
20
  import { type Place } from "../places.ts";
21
21
  import { type PlaceLayer } from "../place-marks.ts";
22
22
  import { type EarthPlace, type EarthPlaceLook, type EarthPlaceMark } from "../scene/earth-places.ts";
23
+ import { type PlaceOnBody, type PlaceOnBodyMark } from "../scene/body-places.ts";
23
24
  import { SPACE_BODIES, type BodyPlace, type RidePoint, type RideState, type RideTarget, type SpaceBody, type SpaceLight } from "./scene.ts";
24
25
  import { type PaintSpec } from "../paint/trail.ts";
25
26
  export type { PaintSpec };
26
27
  export { setPlacesLoader } from "../scene/place-layer.ts";
27
28
  export { EARTH_PLACE_LOOKS, EARTH_PLACE_MARKS, type EarthPlace, type EarthPlaceKind, type EarthPlaceLook, type EarthPlaceMark } from "../scene/earth-places.ts";
29
+ export type { PlaceOnBody, PlaceOnBodyMark } from "../scene/body-places.ts";
28
30
  export { setThreeLoader, SPACE_BODIES, type RidePoint, type RideTarget, type Sight, type SightEdge, type SpaceBody, type SpaceLight };
29
31
  /** Where a body is on the screen, in CSS pixels in the element: its centre and its radius. */
30
32
  export type { BodyPlace };
@@ -261,6 +263,29 @@ export declare class WakuseiSpace extends HTMLElement {
261
263
  marks: readonly EarthPlaceMark[];
262
264
  omitted: number;
263
265
  };
266
+ /**
267
+ * The places laid on the bodies other than the Earth wherever the camera looks, drawn as the Earth's are (`earthPlaces`): a list of `{ body, id, lon, lat, label, kind, color }`, `body` being `moon`, `mars`, `ceres` and so on (an entry for `earth` is not drawn:
268
+ * the Earth has `earthPlaces`). Each is a beam, a pin or a ring (`earthPlacesLook`) on the ground of its body, hidden on the far side, named beside it when there is room, never over a body's name. A body smaller than 40 CSS pixels of radius carries none, and at most
269
+ * `EARTH_PLACE_MARKS` stand up in all, the reader's `here` places first. `loadPlaceHits` and `hitToBodyPlace` from `@johnmorrisdotca/wakusei-planets/places/search` make the list from saved ids. Like the Earth's, it needs
270
+ * `@johnmorrisdotca/wakusei-planets/earth-places` imported (chikyu-earth's layout, an optional peer). A press that did not move on a drawn name or a foot ring is the event `wakusei-body-place`. Setting it writes the attribute `body-places`.
271
+ *
272
+ * @example
273
+ * ```ts no-run
274
+ * import "@johnmorrisdotca/wakusei-planets/space/element";
275
+ * import "@johnmorrisdotca/wakusei-planets/earth-places";
276
+ *
277
+ * const space = document.querySelector("wakusei-space")!;
278
+ * space.bodyPlaces = [{ body: "moon", id: "moon/apollo-11-lunar-module", lon: 23.4731, lat: 0.6742, label: "Apollo 11 lunar module" }];
279
+ * space.addEventListener("wakusei-body-place", (event) => console.log((event as CustomEvent).detail));
280
+ * ```
281
+ */
282
+ get bodyPlaces(): PlaceOnBody[];
283
+ set bodyPlaces(list: readonly PlaceOnBody[] | null);
284
+ /** The markers laid on the other bodies now, as the last draw left them: each place's body, id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`. */
285
+ get bodyPlacesShown(): {
286
+ marks: readonly PlaceOnBodyMark[];
287
+ omitted: number;
288
+ };
264
289
  /**
265
290
  * Go to a place on a body: the view glides to the body (as `goTo` does), or on the body looked at turns round it, and the camera comes to rest straight above the place. The place is an id (`mars/perseverance`) or an English or Japanese name, on the body looked at
266
291
  * unless `body` names another. The zoom stays on the same body and is 1 (the whole body) on another, unless `zoom` is given. Resolves the place, or `undefined` when the body has no place by that name or cannot be looked at.
@@ -30,6 +30,7 @@ import { findPlace, PLACE_BODIES } from "../places.js";
30
30
  import { marksToShow, pointUnder, readPlaceLayers, readSurfaceNames, spotView } from "../place-marks.js";
31
31
  import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
32
32
  import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
33
+ import { layBodyPlaces, bodiesOf, readBodyPlacesWith } from "../scene/body-places.js";
33
34
  import { cross, dot, length, sub, unit } from "../vec.js";
34
35
  import { createSpaceItem, FIT_DISTANCE, framedOf, heldAim, moonScaleFor, newSpaceModel, SPACE_BODIES } from "./scene.js";
35
36
  import { paintLengthOf, paintSwathOf } from "../paint/trail.js";
@@ -147,7 +148,7 @@ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value
147
148
  * ```
148
149
  */
149
150
  export class WakuseiSpace extends HTMLElement {
150
- static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "asteroids", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "all-moons", "moons", "moons-of", "moon-colors", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
151
+ static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "asteroids", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "help-place", "places", "surface-names", "site-flags", "earth-places", "earth-places-look", "body-places", "all-moons", "moons", "moons-of", "moon-colors", "far-opacity", "transition", "pace", "frame", "pair-with", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
151
152
  #model = newSpaceModel();
152
153
  #moons = "major";
153
154
  #moonsOf = {};
@@ -205,6 +206,12 @@ export class WakuseiSpace extends HTMLElement {
205
206
  #earthHeard;
206
207
  #earthList;
207
208
  #earthOmitted = 0;
209
+ #bodyLayer;
210
+ #bodySurfaces = [];
211
+ #bodyList;
212
+ #bodyOmitted = 0;
213
+ // the pointer event of the last press a beam took, so the body under it is not pressed as well
214
+ #beamPress;
208
215
  #surface = null;
209
216
  /** The shared controller behind the element's own hands: for a page that moves the view itself, such as `controller.set({ zoom: space.zoomFor("moon") })`. It is there while the element is connected, whether `controls` is `none` or not. */
210
217
  get controller() {
@@ -300,6 +307,11 @@ export class WakuseiSpace extends HTMLElement {
300
307
  this.#earthSurface = surface;
301
308
  this.#layEarthPlaces();
302
309
  },
310
+ wantBodyPlaces: () => this.#bodyWanted(),
311
+ onBodyPlaces: (surfaces) => {
312
+ this.#bodySurfaces = surfaces;
313
+ this.#layBodyPlaces();
314
+ },
303
315
  onMoving: () => this.#gate?.request(),
304
316
  onRideLost: () => this.#rideLost(),
305
317
  onPainterError: (error) => this.dispatchEvent(new CustomEvent("wakusei-bodies-unavailable", { detail: { reason: error instanceof Error ? error.message : String(error) } })),
@@ -327,7 +339,9 @@ export class WakuseiSpace extends HTMLElement {
327
339
  });
328
340
  this.#earthHeard = onEarthPlacesLayout(() => {
329
341
  this.#earthList = undefined;
342
+ this.#bodyList = undefined;
330
343
  this.#askEarthPlaces();
344
+ this.#askBodyPlaces();
331
345
  });
332
346
  this.#labelBox.addEventListener("click", this.#labelClick);
333
347
  this.#labelBox.addEventListener("focusin", this.#labelFocus);
@@ -359,6 +373,9 @@ export class WakuseiSpace extends HTMLElement {
359
373
  this.#markLayer = undefined;
360
374
  this.#markHeard?.();
361
375
  this.#markHeard = undefined;
376
+ this.#bodyLayer?.dispose();
377
+ this.#bodyLayer = undefined;
378
+ this.#bodySurfaces = [];
362
379
  this.#earthLayer?.dispose();
363
380
  this.#earthLayer = undefined;
364
381
  this.#earthSurface = null;
@@ -446,6 +463,8 @@ export class WakuseiSpace extends HTMLElement {
446
463
  this.#markSurface();
447
464
  if (name === "earth-places" || name === "earth-places-look")
448
465
  this.#askEarthPlaces();
466
+ if (name === "body-places" || name === "earth-places-look")
467
+ this.#askBodyPlaces();
449
468
  }
450
469
  /**
451
470
  * The layers of places marked on the body looked at: any of `landing` (crewed landings, landers and rovers), `crash` (crash, impact and atmospheric-entry sites), `planned` (announced landings) and `feature` (named features), from
@@ -534,6 +553,35 @@ export class WakuseiSpace extends HTMLElement {
534
553
  get earthPlacesShown() {
535
554
  return { marks: this.#earthLayer?.shown ?? [], omitted: this.#earthOmitted };
536
555
  }
556
+ /**
557
+ * The places laid on the bodies other than the Earth wherever the camera looks, drawn as the Earth's are (`earthPlaces`): a list of `{ body, id, lon, lat, label, kind, color }`, `body` being `moon`, `mars`, `ceres` and so on (an entry for `earth` is not drawn:
558
+ * the Earth has `earthPlaces`). Each is a beam, a pin or a ring (`earthPlacesLook`) on the ground of its body, hidden on the far side, named beside it when there is room, never over a body's name. A body smaller than 40 CSS pixels of radius carries none, and at most
559
+ * `EARTH_PLACE_MARKS` stand up in all, the reader's `here` places first. `loadPlaceHits` and `hitToBodyPlace` from `@johnmorrisdotca/wakusei-planets/places/search` make the list from saved ids. Like the Earth's, it needs
560
+ * `@johnmorrisdotca/wakusei-planets/earth-places` imported (chikyu-earth's layout, an optional peer). A press that did not move on a drawn name or a foot ring is the event `wakusei-body-place`. Setting it writes the attribute `body-places`.
561
+ *
562
+ * @example
563
+ * ```ts no-run
564
+ * import "@johnmorrisdotca/wakusei-planets/space/element";
565
+ * import "@johnmorrisdotca/wakusei-planets/earth-places";
566
+ *
567
+ * const space = document.querySelector("wakusei-space")!;
568
+ * space.bodyPlaces = [{ body: "moon", id: "moon/apollo-11-lunar-module", lon: 23.4731, lat: 0.6742, label: "Apollo 11 lunar module" }];
569
+ * space.addEventListener("wakusei-body-place", (event) => console.log((event as CustomEvent).detail));
570
+ * ```
571
+ */
572
+ get bodyPlaces() {
573
+ return [...this.#readBodyPlaces()];
574
+ }
575
+ set bodyPlaces(list) {
576
+ if (list === null || list.length === 0)
577
+ this.removeAttribute("body-places");
578
+ else
579
+ this.setAttribute("body-places", JSON.stringify(list));
580
+ }
581
+ /** The markers laid on the other bodies now, as the last draw left them: each place's body, id and kind, where its foot is in CSS pixels from the view's top left and whether its name is drawn; `omitted` counts the places in sight beyond the first `EARTH_PLACE_MARKS`. */
582
+ get bodyPlacesShown() {
583
+ return { marks: (this.#bodyLayer?.shown ?? []), omitted: this.#bodyOmitted };
584
+ }
537
585
  /**
538
586
  * Go to a place on a body: the view glides to the body (as `goTo` does), or on the body looked at turns round it, and the camera comes to rest straight above the place. The place is an id (`mars/perseverance`) or an English or Japanese name, on the body looked at
539
587
  * unless `body` names another. The zoom stays on the same body and is 1 (the whole body) on another, unless `zoom` is given. Resolves the place, or `undefined` when the body has no place by that name or cannot be looked at.
@@ -740,7 +788,7 @@ export class WakuseiSpace extends HTMLElement {
740
788
  const places = this.#readEarthPlaces();
741
789
  if (places.length === 0)
742
790
  return clear();
743
- this.#earthLayer ??= createEarthPlaceLayer(root);
791
+ this.#earthLayer ??= createEarthPlaceLayer(root, { press: (mark, event) => this.#pressBeam("earth", mark, event) });
744
792
  const layer = this.#earthLayer;
745
793
  const facts = BODIES.earth;
746
794
  const scale = [1, 1 - facts.flattening, 1];
@@ -758,6 +806,67 @@ export class WakuseiSpace extends HTMLElement {
758
806
  this.#earthOmitted = laid.shapes.length - marks.shapes.length;
759
807
  layer.set(places, marks, look);
760
808
  }
809
+ /** The bodies the page has places on (the scene lays their surfaces at each draw), none without the layout, or the Earth's, which `earth-places` draws. */
810
+ #bodyWanted() {
811
+ if (!this.hasAttribute("body-places") || earthPlacesLayout() === undefined)
812
+ return [];
813
+ this.#readBodyPlaces();
814
+ return this.#bodyList?.bodies ?? [];
815
+ }
816
+ #readBodyPlaces() {
817
+ const text = this.getAttribute("body-places");
818
+ const using = earthPlacesLayout();
819
+ if (text === null || using === undefined)
820
+ return [];
821
+ if (this.#bodyList?.text === text)
822
+ return this.#bodyList.list;
823
+ const list = readBodyPlacesWith(text, using.read);
824
+ this.#bodyList = { text, list, bodies: bodiesOf(list) };
825
+ return list;
826
+ }
827
+ /** The places, the look or the layout changed: lay them from the last draw's bodies, or ask for one draw to learn them. */
828
+ #askBodyPlaces() {
829
+ if (!this.hasAttribute("body-places")) {
830
+ this.#bodyLayer?.dispose();
831
+ this.#bodyLayer = undefined;
832
+ this.#bodySurfaces = [];
833
+ this.#bodyOmitted = 0;
834
+ return;
835
+ }
836
+ if (this.#bodySurfaces.length > 0)
837
+ this.#layBodyPlaces();
838
+ this.#gate?.request();
839
+ }
840
+ /** Lay the places over the bodies as the last draw left them, or take them away. Draws nothing: it runs inside the draw the view makes anyway. */
841
+ #layBodyPlaces() {
842
+ const root = this.shadowRoot;
843
+ const using = earthPlacesLayout();
844
+ const clear = () => {
845
+ this.#bodyLayer?.clear();
846
+ this.#bodyOmitted = 0;
847
+ };
848
+ if (root === null || using === undefined || !this.hasAttribute("body-places") || this.#bodySurfaces.length === 0)
849
+ return clear();
850
+ const places = this.#readBodyPlaces();
851
+ if (places.length === 0)
852
+ return clear();
853
+ this.#bodyLayer ??= createEarthPlaceLayer(root, { press: (mark, event) => this.#pressBeam(mark.body ?? "", mark, event) });
854
+ const layer = this.#bodyLayer;
855
+ const look = this.earthPlacesLook;
856
+ const laid = layBodyPlaces(places, this.#bodySurfaces, using, look, {
857
+ width: (text) => layer.width(text),
858
+ taken: this.#nameBoxes.map((one) => ({ left: one.x, top: one.y, width: one.width, height: one.height })),
859
+ // a body under another's disc carries none of its places, as the surface marks and the Earth's places
860
+ covered: (id) => this.#covered !== "name" && this.#places?.[id]?.behind !== undefined,
861
+ });
862
+ this.#bodyOmitted = laid.omitted;
863
+ layer.set(laid.places, laid.layout, look);
864
+ }
865
+ /** A press on a beam's name or foot ring: the event `wakusei-body-place`, `{ body, id, kind, x, y }` (the same for the Earth's places, `body: "earth"`). The page decides what it does; the body under the press is not pressed as well. */
866
+ #pressBeam(body, mark, event) {
867
+ this.#beamPress = event;
868
+ this.dispatchEvent(new CustomEvent("wakusei-body-place", { detail: { body, id: mark.id, kind: mark.kind, x: mark.x, y: mark.y }, bubbles: true, composed: true }));
869
+ }
761
870
  async #loadMarks(body) {
762
871
  if (this.#markList?.body === body)
763
872
  return this.#markList.list;
@@ -2712,6 +2821,12 @@ export class WakuseiSpace extends HTMLElement {
2712
2821
  #sightTimer;
2713
2822
  #tellSight = () => {
2714
2823
  this.#sightTimer = undefined;
2824
+ // a timer can fire a few milliseconds early (CI heard two events 244 ms apart): the wait is made good, so the least time between two events is the one the property promises
2825
+ const early = this.#sightSent + SIGHT_EVENT_MS - performance.now();
2826
+ if (early > 0.5 && this.isConnected) {
2827
+ this.#sightTimer = setTimeout(this.#tellSight, early);
2828
+ return;
2829
+ }
2715
2830
  if (!this.isConnected || !sightChanged(this.#told, this.#sight))
2716
2831
  return;
2717
2832
  this.#told = this.#sight;
@@ -2867,6 +2982,8 @@ export class WakuseiSpace extends HTMLElement {
2867
2982
  this.#hover(null, "pointer");
2868
2983
  };
2869
2984
  #up = (event) => {
2985
+ if (this.#beamPress === event)
2986
+ return;
2870
2987
  if (Math.hypot(event.clientX - this.#downX, event.clientY - this.#downY) > 6)
2871
2988
  return;
2872
2989
  if (!this.#places)
@@ -2,6 +2,7 @@ import type * as THREE from "three";
2
2
  import type { Item3D } from "@johnmorrisdotca/kazoku-ui/renderer";
3
3
  import { type BodyId, type MoonId } from "../facts.ts";
4
4
  import type { ThreeParts } from "../scene/body.ts";
5
+ import type { BodySurface } from "../scene/body-places.ts";
5
6
  import type { SourceBook } from "../door/book.ts";
6
7
  import type { SmallBody } from "../door/small-bodies.ts";
7
8
  import { type MoonColorChoice, type MoonSource, type MoonSpot } from "./all-moons.ts";
@@ -534,6 +535,10 @@ export interface SpaceDeps {
534
535
  radiusPx: number;
535
536
  sun: Vec3 | null;
536
537
  } | null) => void;
538
+ /** The bodies whose surfaces are wanted at this draw by `onBodyPlaces` (left out, none are): the ids of the bodies the page has places on, other than the Earth, which `wantEarth` is for. */
539
+ wantBodyPlaces?: () => readonly string[];
540
+ /** Those bodies as this draw left them, each in the form `onEarth` gives (a body that is not drawn, or while the camera rides, is left out of the list). Called at every draw while `wantBodyPlaces` names a body. */
541
+ onBodyPlaces?: (bodies: readonly BodySurface[]) => void;
537
542
  /** Called at the end of a draw while the camera is moving from one ride to another, so the next frame is asked for (at the page's frame cap). */
538
543
  onMoving?: () => void;
539
544
  /** The target of the ride could not be placed at this draw. */
@@ -1398,6 +1398,27 @@ export function createSpaceItem(model, deps) {
1398
1398
  deps.onEarth({ id: "earth", centre, radius: r, pole, meridian, eye: eyeAt, project: (v) => labelFor(squashPoint(v, centre, shape)), width: size.width, height: size.height, radiusPx: d <= r * 1.001 ? 1e5 : (((size.height / 2) * (r / Math.sqrt(d * d - r * r))) / half) * edgeStretch(eyeAt, lookAt, centre), sun: model.light === "lit" ? null : toSunOf("earth") });
1399
1399
  }
1400
1400
  }
1401
+ // the places on the other bodies: the same, for each body the page has places on (a planet, the Moon or a body drawn as a moon of the catalogue), after the names too
1402
+ if (deps.onBodyPlaces) {
1403
+ const wanted = deps.wantBodyPlaces?.() ?? [];
1404
+ if (wanted.length > 0) {
1405
+ const surfaces = [];
1406
+ for (const id of wanted) {
1407
+ const drawing = rideFrom ? undefined : (slots.get(id)?.drawing ?? moonSlots.get(id)?.slot.drawing);
1408
+ if (drawing === undefined || !drawing.object.visible)
1409
+ continue;
1410
+ const at = drawing.object.position;
1411
+ const r = drawing.object.scale.x;
1412
+ const d = Math.hypot(at.x - camera.position.x, at.y - camera.position.y, at.z - camera.position.z);
1413
+ const { pole, meridian } = orientation(id, model.time);
1414
+ const centre = [at.x, at.y, at.z];
1415
+ const shape = roundShape(eyeAt, lookAt, centre, r);
1416
+ const sun = model.light === "lit" || !SPACE_BODIES.includes(id) ? null : toSunOf(id);
1417
+ surfaces.push({ id, centre, radius: r, pole, meridian, eye: eyeAt, project: (v) => labelFor(squashPoint(v, centre, shape)), width: size.width, height: size.height, radiusPx: d <= r * 1.001 ? 1e5 : (((size.height / 2) * (r / Math.sqrt(d * d - r * r))) / half) * edgeStretch(eyeAt, lookAt, centre), sun });
1418
+ }
1419
+ deps.onBodyPlaces(surfaces);
1420
+ }
1421
+ }
1401
1422
  if (deps.onSight && (deps.wantSight?.() ?? true)) {
1402
1423
  // each body in the camera's own axes: in front when it is ahead (negative z), its place from the projection (a pan included), and the way to it on the screen from its x and y, which holds behind the camera too
1403
1424
  const sights = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.68.0",
3
+ "version": "0.69.0",
4
4
  "description": "Wakusei Planets 惑星 — The Sun, planets and moons for the web: each as a clean line drawing, a shaded realistic drawing or a painted surface map, with real sizes, axial tilt and rotation as data, and positions of the moons for any date and time. SVG for the lines, three.js (optional) for the rest.",
5
5
  "keywords": [
6
6
  "planets",