@johnmorrisdotca/wakusei-planets 0.68.0 → 0.70.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (104) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/NOTICE.md +29 -1
  3. package/README.md +7 -7
  4. package/dist/bodies/moons-jupiter.js +2 -0
  5. package/dist/bodies/moons-mars.js +2 -2
  6. package/dist/bodies/moons-neptune.js +2 -1
  7. package/dist/bodies/moons-pluto.js +2 -2
  8. package/dist/bodies/moons-saturn.js +14 -2
  9. package/dist/data/discovery.js +225 -0
  10. package/dist/data/moon-catalogue.js +15 -15
  11. package/dist/data/orbits.js +15 -0
  12. package/dist/data/shapes/amalthea.d.ts +2 -0
  13. package/dist/data/shapes/amalthea.js +1 -0
  14. package/dist/data/shapes/atlas.d.ts +2 -0
  15. package/dist/data/shapes/atlas.js +1 -0
  16. package/dist/data/shapes/calypso.d.ts +2 -0
  17. package/dist/data/shapes/calypso.js +1 -0
  18. package/dist/data/shapes/daphnis.d.ts +2 -0
  19. package/dist/data/shapes/daphnis.js +1 -0
  20. package/dist/data/shapes/deimos.d.ts +2 -0
  21. package/dist/data/shapes/deimos.js +1 -0
  22. package/dist/data/shapes/epimetheus.d.ts +2 -0
  23. package/dist/data/shapes/epimetheus.js +1 -0
  24. package/dist/data/shapes/helene.d.ts +2 -0
  25. package/dist/data/shapes/helene.js +1 -0
  26. package/dist/data/shapes/hydra.d.ts +2 -0
  27. package/dist/data/shapes/hydra.js +1 -0
  28. package/dist/data/shapes/hyperion.d.ts +2 -0
  29. package/dist/data/shapes/hyperion.js +1 -0
  30. package/dist/data/shapes/janus.d.ts +2 -0
  31. package/dist/data/shapes/janus.js +1 -0
  32. package/dist/data/shapes/larissa.d.ts +2 -0
  33. package/dist/data/shapes/larissa.js +1 -0
  34. package/dist/data/shapes/nix.d.ts +2 -0
  35. package/dist/data/shapes/nix.js +1 -0
  36. package/dist/data/shapes/pan.d.ts +2 -0
  37. package/dist/data/shapes/pan.js +1 -0
  38. package/dist/data/shapes/pandora.d.ts +2 -0
  39. package/dist/data/shapes/pandora.js +1 -0
  40. package/dist/data/shapes/phobos.d.ts +2 -0
  41. package/dist/data/shapes/phobos.js +1 -0
  42. package/dist/data/shapes/phoebe.d.ts +2 -0
  43. package/dist/data/shapes/phoebe.js +1 -0
  44. package/dist/data/shapes/prometheus.d.ts +2 -0
  45. package/dist/data/shapes/prometheus.js +1 -0
  46. package/dist/data/shapes/proteus.d.ts +2 -0
  47. package/dist/data/shapes/proteus.js +1 -0
  48. package/dist/data/shapes/telesto.d.ts +2 -0
  49. package/dist/data/shapes/telesto.js +1 -0
  50. package/dist/data/shapes/thebe.d.ts +2 -0
  51. package/dist/data/shapes/thebe.js +1 -0
  52. package/dist/discovery.d.ts +1 -1
  53. package/dist/earth-places.d.ts +23 -6
  54. package/dist/earth-places.js +29 -8
  55. package/dist/facts.d.ts +21 -4
  56. package/dist/facts.js +71 -38
  57. package/dist/index.d.ts +2 -1
  58. package/dist/index.js +2 -1
  59. package/dist/moon-catalogue.d.ts +1 -1
  60. package/dist/nearest.js +2 -0
  61. package/dist/picture-credits.js +3 -0
  62. package/dist/place-search.d.ts +22 -0
  63. package/dist/place-search.js +25 -0
  64. package/dist/places/search.d.ts +19 -2
  65. package/dist/places/search.js +50 -1
  66. package/dist/scene/body-places.d.ts +98 -0
  67. package/dist/scene/body-places.js +112 -0
  68. package/dist/scene/body.js +10 -5
  69. package/dist/scene/earth-places.d.ts +114 -1
  70. package/dist/scene/earth-places.js +200 -7
  71. package/dist/scene/glsl.d.ts +2 -2
  72. package/dist/scene/glsl.js +11 -0
  73. package/dist/scene/look.d.ts +7 -0
  74. package/dist/scene/look.js +1 -0
  75. package/dist/scene/painter.js +18 -3
  76. package/dist/scene/recipes.js +6 -2
  77. package/dist/scene/rings.js +11 -2
  78. package/dist/scene/shape.d.ts +50 -0
  79. package/dist/scene/shape.js +110 -0
  80. package/dist/shape-basis.d.ts +43 -0
  81. package/dist/shape-basis.js +45 -0
  82. package/dist/space/all-moons.d.ts +6 -1
  83. package/dist/space/all-moons.js +5 -1
  84. package/dist/space/element.d.ts +52 -2
  85. package/dist/space/element.js +279 -33
  86. package/dist/space/orbit-lines.d.ts +66 -0
  87. package/dist/space/orbit-lines.js +118 -0
  88. package/dist/space/scale.d.ts +1 -1
  89. package/dist/space/scale.js +20 -5
  90. package/dist/space/scene.d.ts +13 -0
  91. package/dist/space/scene.js +137 -9
  92. package/dist/stops.js +12 -0
  93. package/dist/surface/element.js +3 -3
  94. package/dist/surface/glsl.d.ts +2 -2
  95. package/dist/surface/glsl.js +15 -3
  96. package/dist/surface/height.d.ts +7 -0
  97. package/dist/surface/height.js +10 -0
  98. package/dist/textures/deimos-1024.webp +0 -0
  99. package/dist/textures/deimos-512.webp +0 -0
  100. package/dist/textures/phobos-1024.webp +0 -0
  101. package/dist/textures/phobos-512.webp +0 -0
  102. package/dist/textures/phoebe-1024.webp +0 -0
  103. package/dist/textures/phoebe-512.webp +0 -0
  104. package/package.json +1 -1
@@ -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,112 @@
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, inMarkOrder, placeRank } 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, then those whose name is low
83
+ const mine = inMarkOrder(places.filter((place) => place.body === surface.id));
84
+ if (mine.length === 0)
85
+ continue;
86
+ const view = spotView({ ...surface, scale });
87
+ const sun = surface.sun === null ? null : pointUnder(surface.sun, surface.pole, surface.meridian);
88
+ const layoutOptions = {
89
+ size: (place) => (place.label === undefined ? null : { width: options.width(place.label), height: 18 }),
90
+ taken,
91
+ sun,
92
+ };
93
+ const laid = using.layout(mine, view, look, layoutOptions);
94
+ const offset = merged.length;
95
+ merged.push(...mine);
96
+ for (const shape of laid.shapes)
97
+ shapes.push({ ...shape, index: shape.index + offset });
98
+ for (const spot of laid.labels) {
99
+ labels.push({ ...spot, index: spot.index + offset });
100
+ const label = mine[spot.index]?.label;
101
+ if (label !== undefined)
102
+ taken.push({ left: spot.left, top: spot.top, width: options.width(label), height: 18 });
103
+ }
104
+ }
105
+ // 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
106
+ const rank = (shape) => placeRank(merged[shape.index]);
107
+ 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);
108
+ const limit = options.marks ?? EARTH_PLACE_MARKS;
109
+ const kept = ordered.slice(0, limit);
110
+ const keptLabels = labels.filter((spot) => kept.some((shape) => shape.index === spot.index));
111
+ return { places: merged, layout: { shapes: kept, labels: keptLabels }, omitted: ordered.length - kept.length };
112
+ }
@@ -3,6 +3,7 @@ import { silhouette } from "../pose.js";
3
3
  import { cross } from "../vec.js";
4
4
  import { BALL_FRAGMENT, bodyFragment, GLOW_FRAGMENT, GLOW_VERTEX, PAINTED_SURFACE, PAINTED_SURFACE_WINDOWED, RING_FRAGMENT_DETAIL, RING_VERTEX, STAR_GLOW_FRAGMENT, VERTEX } from "./glsl.js";
5
5
  import { detailOf, lookOf } from "./look.js";
6
+ import { shapeGeometry } from "./shape.js";
6
7
  import { createDetail } from "./detail.js";
7
8
  import { fallbackLook } from "./fallback.js";
8
9
  import { writeBasis } from "./basis.js";
@@ -69,7 +70,11 @@ export function createBodyItem(options) {
69
70
  async build({ three: T, assets, width, height }) {
70
71
  const look = options.shaded ?? lookOf(options.id) ?? fallbackLook(facts);
71
72
  const wantPainted = (options.look === "painted" || look.mapped === true) && look.painted !== undefined;
72
- const geometry = assets.acquire("wk:sphere", () => new T.SphereGeometry(1, 192, 96), (g) => g.dispose());
73
+ // a moon with a published shape model is the globe moved to its radii (its table is a chunk of its own, waited for here), and then needs no stretching to an ellipsoid
74
+ const shapeTable = look.shape === undefined ? undefined : await look.shape().catch(() => undefined);
75
+ // a big picture gets a globe of 192 by 96 steps (as the unshaped sphere has), a tile or a card one of 96 by 48: a page can hold a dozen moons, and the arrays of a globe stay in the page
76
+ const grid = Math.min(width, height) >= 300 ? { lon: 192, lat: 96 } : { lon: 96, lat: 48 };
77
+ const geometry = shapeTable === undefined ? assets.acquire("wk:sphere", () => new T.SphereGeometry(1, 192, 96), (g) => g.dispose()) : assets.acquire(`wk:shape:${held}:${grid.lon}`, () => shapeGeometry(T, shapeTable, facts.radiusKm, grid), (g) => g.dispose());
73
78
  const shader = assets.acquire(`wk:body:${held}:r`, () => makeBodyMaterial(T, look, false), (m) => m.dispose());
74
79
  const paintedMaterial = wantPainted ? assets.acquire(`wk:body:${held}:p`, () => makeBodyMaterial(T, look, true), (m) => m.dispose()) : undefined;
75
80
  const materials = paintedMaterial === undefined ? [shader] : [shader, paintedMaterial];
@@ -270,10 +275,10 @@ export function createBodyItem(options) {
270
275
  const orient = (state) => {
271
276
  const { pole, meridian } = state.pose;
272
277
  const east = cross(pole, meridian);
273
- const ax = facts.axesKm;
278
+ const ax = shapeTable === undefined ? facts.axesKm : undefined;
274
279
  const mean = facts.radiusKm;
275
280
  const scaleX = ax ? ax[1] / mean : 1;
276
- const scaleY = ax ? ax[2] / mean : 1 - facts.flattening;
281
+ const scaleY = ax ? ax[2] / mean : shapeTable === undefined ? 1 - facts.flattening : 1;
277
282
  const scaleZ = ax ? ax[0] / mean : 1;
278
283
  setBasis(mesh, east, pole, meridian, scaleX, scaleY, scaleZ);
279
284
  if (cut !== undefined)
@@ -463,9 +468,9 @@ export function createBodyItem(options) {
463
468
  label.update(camera, ((aspect >= 1 ? viewHeight : viewWidth) / 2) * (state.zoom / state.extent), state.pose.light);
464
469
  if (detail !== undefined && textureWidth > 0) {
465
470
  const east = cross(state.pose.pole, state.pose.meridian);
466
- const ax = facts.axesKm;
471
+ const ax = shapeTable === undefined ? facts.axesKm : undefined;
467
472
  const mean = facts.radiusKm;
468
- detail.sync({ left: camera.left, right: camera.right, bottom: camera.bottom, top: camera.top }, { east, pole: state.pose.pole, meridian: state.pose.meridian, scale: [ax ? ax[1] / mean : 1, ax ? ax[2] / mean : 1 - facts.flattening, ax ? ax[0] / mean : 1] }, viewWidth);
473
+ detail.sync({ left: camera.left, right: camera.right, bottom: camera.bottom, top: camera.top }, { east, pole: state.pose.pole, meridian: state.pose.meridian, scale: [ax ? ax[1] / mean : 1, ax ? ax[2] / mean : shapeTable === undefined ? 1 - facts.flattening : 1, ax ? ax[0] / mean : 1] }, viewWidth);
469
474
  }
470
475
  };
471
476
  apply(latest);
@@ -38,7 +38,39 @@ export interface EarthPlace {
38
38
  kind?: EarthPlaceKind;
39
39
  /** A CSS colour for this place alone: a hex colour, `rgb()` or `hsl()` with numbers, or a colour's name. */
40
40
  color?: string;
41
+ /** A set of places (spaceports, harbours) the page shows or hides together with `earth-place-layers`; left out, the place is always shown. */
42
+ layer?: string;
43
+ /** `small` draws a shorter, narrower mark; left out, the kind's own size. */
44
+ size?: EarthPlaceSize;
45
+ /** How this place is drawn, over `earth-places-look`; left out, `earth-places-look`. */
46
+ look?: EarthPlaceLook;
47
+ /** `low` lays this place's name after the others' (and, past the 32 markers, its marker too), so its name gives way where they crowd; left out (`high`), it is laid with the rest. */
48
+ namePriority?: EarthPlaceNamePriority;
41
49
  }
50
+ /**
51
+ * How big a place's mark is: `normal` (the default) or `small`, a shorter, narrower stick and a smaller ring, so a harbour can stand beside a city and "You are here" stays the tall beam.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import type { EarthPlaceSize } from "@johnmorrisdotca/wakusei-planets/earth-places";
56
+ *
57
+ * const size: EarthPlaceSize = "small";
58
+ * console.log(size);
59
+ * ```
60
+ */
61
+ export type EarthPlaceSize = "normal" | "small";
62
+ /**
63
+ * Where a place's name is laid among the others: `high` (the default) in the order given, or `low`, after all the others.
64
+ *
65
+ * @example
66
+ * ```ts
67
+ * import type { EarthPlaceNamePriority } from "@johnmorrisdotca/wakusei-planets/earth-places";
68
+ *
69
+ * const priority: EarthPlaceNamePriority = "low";
70
+ * console.log(priority);
71
+ * ```
72
+ */
73
+ export type EarthPlaceNamePriority = "high" | "low";
42
74
  /**
43
75
  * How a place is drawn: `beam` (a light rising out of the ground with a ring at its foot, the default), `pin` (a thin stick with a round head) or `ring` (only the ring lying on the ground).
44
76
  *
@@ -139,6 +171,51 @@ export interface EarthPlaceLayoutOptions {
139
171
  lat: number;
140
172
  } | null;
141
173
  }
174
+ /**
175
+ * Which layers of places are shown (the attribute `earth-place-layers`): a JSON object of layer names to true or false, such as `{"harbours":false}`. A layer that is not named is shown, and so is a place with no layer. Anything that is not an object
176
+ * of that kind is no switches. chikyu-earth's `readPlaceLayers`.
177
+ *
178
+ * @param value - The attribute's text, or null.
179
+ * @returns The switches, a name to whether it is shown.
180
+ *
181
+ * @example
182
+ * ```ts
183
+ * import { readEarthPlaceLayers } from "@johnmorrisdotca/wakusei-planets/earth-places";
184
+ *
185
+ * console.log(readEarthPlaceLayers('{"harbours":false,"airports":true,"x":1}')); // { harbours: false, airports: true }
186
+ * ```
187
+ */
188
+ export declare function readEarthPlaceLayers(value: string | null | undefined): Record<string, boolean>;
189
+ /**
190
+ * The places whose layer is shown: a place with no layer is always in, and a layer is in unless `layers` says `false` for it. A place of a layer that is off is not drawn, not named and cannot be pressed. The list is returned as it came when nothing is left out.
191
+ *
192
+ * @param places - The places, as `readEarthPlaces` makes them.
193
+ * @param layers - The switches, a layer's name to whether it is shown (`readEarthPlaceLayers`).
194
+ * @returns The places to draw.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * import { shownEarthPlaces } from "@johnmorrisdotca/wakusei-planets/earth-places";
199
+ *
200
+ * const places = [{ id: "yvr", lon: -123.18, lat: 49.19, layer: "airports" }, { id: "cavan", lon: -123.1, lat: 49.29, layer: "harbours" }, { id: "me", lon: -79.4, lat: 43.7 }];
201
+ * console.log(shownEarthPlaces(places, { harbours: false }).map((place) => place.id)); // ["yvr", "me"]
202
+ * ```
203
+ */
204
+ export declare function shownEarthPlaces<T extends EarthPlace>(places: readonly T[], layers: Readonly<Record<string, boolean>>): readonly T[];
205
+ /** The order the markers are given out in: where the reader is, then the rest in the order given, then the places whose name is `low`. */
206
+ export declare const placeRank: (place: EarthPlace) => number;
207
+ /** The places in that order (the order given within each rank). */
208
+ export declare const inMarkOrder: <T extends EarthPlace>(places: readonly T[]) => T[];
209
+ /**
210
+ * The fields beyond chikyu-earth's own that a place may carry (`layer`, `size`, `look`, `namePriority`), put back on the places its reader (older than them) made from the same text, so the views need no newer chikyu-earth. A place is found by its `id`
211
+ * (or, with none, its place in the list, as chikyu-earth gives it); a field that is not valid is left out.
212
+ */
213
+ export declare function keepPlaceFields(value: string | null | undefined, places: EarthPlace[]): EarthPlace[];
214
+ /**
215
+ * A layout that gives each place its own `size` and `look`: the places' markers are laid as beams (chikyu-earth knows one look for a whole list), then a `small` place's stick is cut to about half and its ring to 70 per cent, and a place whose look is `ring`
216
+ * (its own or the list's) has no stick, its name moving with the top of what is left. A list with no `size` or `look` of its own is laid as `layout` lays it, untouched.
217
+ */
218
+ export declare function layWithOwn(layout: EarthPlacesLayout["layout"], places: readonly EarthPlace[], view: SpotView, look: EarthPlaceLook, options?: EarthPlaceLayoutOptions): EarthPlaceLayout;
142
219
  /** The two things `@johnmorrisdotca/wakusei-planets/earth-places` hands the views: reading the attribute, and laying places on a picture. Both are chikyu-earth's. */
143
220
  export interface EarthPlacesLayout {
144
221
  read(value: string | null | undefined): EarthPlace[];
@@ -169,7 +246,40 @@ export interface EarthPlaceMark {
169
246
  x: number;
170
247
  y: number;
171
248
  named: boolean;
249
+ /** For a place on a body other than the Earth (`body-places`): the body. */
250
+ body?: string;
251
+ }
252
+ /**
253
+ * What `wakusei-place-click` carries in `event.detail`: the place that was pressed (chikyu-earth's `chikyu-place-click` detail, with the `body` it is on, `earth` for the Earth's), and where the press was, in CSS pixels inside the element's box.
254
+ *
255
+ * @example
256
+ * ```ts
257
+ * import type { EarthPlaceClickDetail } from "@johnmorrisdotca/wakusei-planets/earth-places";
258
+ *
259
+ * const on = (event: Event): void => {
260
+ * const { body, id, kind, layer } = (event as CustomEvent<EarthPlaceClickDetail>).detail;
261
+ * console.log(body, id, kind, layer ?? "no layer");
262
+ * };
263
+ * console.log(typeof on);
264
+ * ```
265
+ */
266
+ export interface EarthPlaceClickDetail {
267
+ /** The body the place is on: `earth`, `moon`, `mars` and so on. */
268
+ body: string;
269
+ id: string;
270
+ /** `here` or `favourite`. */
271
+ kind: EarthPlaceKind;
272
+ /** The place's `layer`, when it has one. */
273
+ layer?: string;
274
+ label?: string;
275
+ lon: number;
276
+ lat: number;
277
+ /** Where the press was, in CSS pixels inside the element's box. */
278
+ x: number;
279
+ y: number;
172
280
  }
281
+ /** The detail of `wakusei-place-click` for a pressed place. */
282
+ export declare function earthPlaceClick(body: string, place: EarthPlace, x: number, y: number): EarthPlaceClickDetail;
173
283
  /** The markers over one view. */
174
284
  export interface EarthPlaceLayerView {
175
285
  /** Draw the markers of a layout, moving the ones already there and hiding the rest. */
@@ -185,6 +295,9 @@ export interface EarthPlaceLayerView {
185
295
  * 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
296
  *
187
297
  * @param root - The view's shadow root.
298
+ * @param options - `press`, called with the mark, the pointer event and the place 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
299
  * @returns The layer.
189
300
  */
190
- export declare function createEarthPlaceLayer(root: ShadowRoot): EarthPlaceLayerView;
301
+ export declare function createEarthPlaceLayer(root: ShadowRoot, options?: {
302
+ press?: (mark: EarthPlaceMark, event: PointerEvent, place: EarthPlace) => void;
303
+ }): EarthPlaceLayerView;