@johnmorrisdotca/wakusei-planets 0.42.0 → 0.44.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
@@ -2,13 +2,25 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.44.0] - 2026-11-13
6
+
7
+ - **Names of the great features are written on a body** (MODULES-1231). When the body looked at is big enough, `surface-names` (on unless `off`) writes its most important named features on the surface: fame first, then size (`placeRank`). They face the camera, fade at the limb, and stay apart so they do not crowd: a name is not written over a dot of the places asked for, a craft or another body's dot, another body's name, or another feature name, and gives way when it would be. A number is how many. A press sends `wakusei-place`. Nothing is drawn for a name.
8
+
9
+ - **Written names keep out of the way** (MODULES-1231). A name is not written over a dot of the places asked for, a craft or another body's dot, another body's name, or another name, and gives way when it would be: one that only names may move up to 24 pixels first, so a famous crater such as Tycho still gets its name beside a larger one. A press that begins on a name goes on to the view's controls, so a drag that starts on one turns the body; a tap that did not move picks the place (`wakusei-place`), by mouse or touch. The place's tip on hover, which the first cut of the names had dropped, is back, and names are not listed in `placesShown`.
10
+
11
+ ## [0.43.0] - 2026-11-13
12
+
13
+ - **The space view draws the deep-space craft** (MODULES-1207). `spacecraft` on `<wakusei-space>` (and `space.spacecraft`) is off by default. `"all"` or `true` draws every craft whose record covers the date, as one points object with a name each; a space-separated list draws those. A craft outside its record is not drawn and `stats.spacecraft.status[id]` is `"outside"`. Each table loads the first time that craft is shown. `sight()` and `wakusei-sight` give each drawn craft `{ id, kind: "spacecraft" }` using the craft's own id. A press sends `wakusei-body-click` with that kind and does not go to the craft. No path line.
14
+
15
+ - **The Roadster joins the spacecraft list** (MODULES-1208). `roadster` is the nineteenth entry of `SPACECRAFT`: Starman / スターマン, other names Tesla Roadster, Starman and Tesla, kind `other`, Horizons `-143205`, the Falcon Heavy launch from Kennedy Space Center 39A. `findSpacecraft` matches an id, either name or an other name, with case, letter width, spaces and punctuation folded. `spacecraftPosition`, `spacecraftSpeed`, `spacecraftSunDistance`, `spacecraftLightTime` and `spacecraftStats` answer for it from the Roadster's own path, and the 20 kB table loads only with `loadSpacecraft("roadster")`. `/roadster` is unchanged. The craft page's picker shows it.
16
+
5
17
  ## [0.42.0] - 2026-11-13
6
18
 
7
19
  - **An arrival keeps a companion in the picture** (MODULES-1026). `arrivalSide` (and `travelArrival`, which uses it) stands on the side where the frame is not empty black: the body's own moons, or its planet when it is a moon; else the body the camera came from, or the nearest planet in that direction; else the Sun, only while at least half the body stays lit. A side that would turn the globe black is refused. `goTo` and a double click (the zoom jump to 1 or to 2) set the controls to that side; a drag afterwards is left as the reader set it. `stats.companion` names the body kept beside it, and that name is not dropped when names would otherwise clash. The swing is not applied to a straight move (`direct`, `look-back`), which keeps its destination in the picture the whole way.
8
20
 
9
21
  - **Moons are larger than life in the squeezed view** (MODULES-989). `moon-size` on `<wakusei-space>` (and `space.moonSize`) is 2 by default: moons are drawn that many times their real radius, only while `scale` is `compressed`. 1 is today's size; 4 and 8 go further. True distances ignore it. Every moon of one planet takes the same factor, so they keep their real order of size. The factor is cut when a moon would be larger than a quarter of its planet, would touch the planet or its rings, or would reach the next moon's orbit, and `stats.moonSize` reports the factor used and `clamped`. Picking, the name on the body and the hidden-body rule use that drawn size. `moonSizeFactor` from `/space` is the same rule on plain numbers. A moon looked at, or gone to, is framed at the size it is drawn, so it still fits the view.
10
22
 
11
- - **A page for the spacecraft** (MODULES-875). `craft.html` picks one of the eighteen craft, draws its path and where it is on a date, and lists the facts and the voyage. The craft's table loads only when it is chosen. The date plays when the page opens, and every time shown is the reader's own. English and Japanese.
23
+ - **A page for the spacecraft** (MODULES-875). `craft.html` picks one of the nineteen craft, draws its path and where it is on a date, and lists the facts and the voyage. The craft's table loads only when it is chosen. The date plays when the page opens, and every time shown is the reader's own. English and Japanese.
12
24
 
13
25
  ## [0.41.0] - 2026-11-13
14
26
 
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.42.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.44.0/docs/images/lineup-desk.png" width="640"></p>
23
23
 
24
24
  ## Who it is for
25
25
 
@@ -388,7 +388,7 @@ The tiles of every body share one 48 MB budget, six loads at a time for a source
388
388
 
389
389
  ## The portrait builder
390
390
 
391
- <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.42.0/docs/images/portrait-family.png" width="640"></p>
391
+ <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.44.0/docs/images/portrait-family.png" width="640"></p>
392
392
 
393
393
  [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.
394
394
 
@@ -534,7 +534,7 @@ BODIES.pluto.kind; // "dwarf-planet"
534
534
 
535
535
  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:
536
536
 
537
- > Morris, J. (2026). *Wakusei Planets* (version 0.42.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
537
+ > Morris, J. (2026). *Wakusei Planets* (version 0.44.0) [Computer software]. https://github.com/johnmorrisdotca/wakusei-planets
538
538
 
539
539
  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).
540
540
 
package/dist/element.js CHANGED
@@ -22,7 +22,7 @@ import { delegates, onRegister } from "./scene/store.js";
22
22
  import { setThreeLoader, takeRenderer } from "./scene/shared.js";
23
23
  import { turn as turnVec } from "./vec.js";
24
24
  import { findPlace, PLACE_BODIES } from "./places.js";
25
- import { placeMarks, readPlaceLayers, turnToPlace } from "./place-marks.js";
25
+ import { marksToShow, readPlaceLayers, readSurfaceNames, turnToPlace } from "./place-marks.js";
26
26
  import { createPlaceLayer, onPlacesLoader, placesLoader } from "./scene/place-layer.js";
27
27
  export { setThreeLoader };
28
28
  export { placeLine, setPlacesLoader } from "./scene/place-layer.js";
@@ -101,7 +101,7 @@ const TEMPLATE = `<style>
101
101
  * ```
102
102
  */
103
103
  export class WakuseiBody extends HTMLElement {
104
- static observedAttributes = ["body", "star", "quality", ...STAR_ATTRS, "look", "size", "time", "tilt", "pitch", "phase", "meridian", "turn", "rate", "moons", "range", "scale-to", "span-km", "fit", "live", "texture-base", "texture-far-base", "tiles", "data", "lang", "labels", "places", ...NAME_LABEL_ATTRIBUTES];
104
+ static observedAttributes = ["body", "star", "quality", ...STAR_ATTRS, "look", "size", "time", "tilt", "pitch", "phase", "meridian", "turn", "rate", "moons", "range", "scale-to", "span-km", "fit", "live", "texture-base", "texture-far-base", "tiles", "data", "lang", "labels", "places", "surface-names", ...NAME_LABEL_ATTRIBUTES];
105
105
  #stage;
106
106
  #state = "line";
107
107
  #renderer;
@@ -346,8 +346,9 @@ export class WakuseiBody extends HTMLElement {
346
346
  /** Lay the marks of the places over the picture as the scene state has it, or take them away. Draws nothing. */
347
347
  #markPlaces(state = this.#sceneState) {
348
348
  const layers = this.places;
349
+ const names = readSurfaceNames(this.getAttribute("surface-names"));
349
350
  const shaded = this.look !== "line" && this.#view !== undefined && !this.hasAttribute("star");
350
- if (layers.length === 0 || !shaded || state === undefined) {
351
+ if ((!names.on && layers.length === 0) || !shaded || state === undefined) {
351
352
  if (this.#placeLayer !== undefined) {
352
353
  this.#placeLayer.dispose();
353
354
  this.#placeLayer = undefined;
@@ -393,7 +394,7 @@ export class WakuseiBody extends HTMLElement {
393
394
  const facts = this.#facts();
394
395
  const ax = facts.axesKm;
395
396
  const scale = ax ? [ax[1] / facts.radiusKm, ax[2] / facts.radiusKm, ax[0] / facts.radiusKm] : [1, 1 - facts.flattening, 1];
396
- const marks = placeMarks(this.#placeList.list, layers, {
397
+ const marks = marksToShow(this.#placeList.list, layers, {
397
398
  centre: [0, 0, 0],
398
399
  radius: 1,
399
400
  pole: state.pose.pole,
@@ -404,7 +405,7 @@ export class WakuseiBody extends HTMLElement {
404
405
  width: w,
405
406
  height: h,
406
407
  radiusPx: (Math.min(w, h) / 2) * (state.zoom / state.extent),
407
- }, facts.radiusKm);
408
+ }, facts.radiusKm, names, [], this.getAttribute("lang") === "ja" ? "ja" : "en");
408
409
  this.#placeLayer.set(marks);
409
410
  }
410
411
  /** What the element is doing now. */
@@ -510,7 +511,7 @@ export class WakuseiBody extends HTMLElement {
510
511
  this.#refreshLimits();
511
512
  }
512
513
  this.#lastAnchors = -1;
513
- if (name === "places" || name === "lang" || name === "body" || name === "look" || name === "star")
514
+ if (name === "places" || name === "lang" || name === "body" || name === "look" || name === "star" || name === "surface-names")
514
515
  this.#markPlaces();
515
516
  this.#queue();
516
517
  }
@@ -117,6 +117,12 @@ export interface PlaceMark {
117
117
  layer: PlaceLayer;
118
118
  x: number;
119
119
  y: number;
120
+ /** 1 facing the camera, falling to 0 at the limb. Set on a name. */
121
+ fade?: number;
122
+ /** The name is written, not only a dot. */
123
+ label?: boolean;
124
+ /** A name only: no layer the page asked for calls for this place, so it is not one of the places shown (`placesShown`). */
125
+ nameOnly?: boolean;
120
126
  }
121
127
  /**
122
128
  * The rules that keep the marks quiet, in CSS pixels: nothing is marked on a body under `fromPx` of radius on the screen; a named feature is marked once it is `featureFromPx` across (a famous one at any size);
@@ -145,6 +151,7 @@ export declare const MARK_RULES: {
145
151
  * @param layers - The layers to show.
146
152
  * @param view - The body as drawn.
147
153
  * @param radiusKm - The body's radius in kilometres, to tell a feature's size on the screen.
154
+ * @param options - `limit` caps how many marks, `gapPx` is how far apart they stay, and `label` writes the name, `avoid` lists boxes a name keeps clear of (dots, other names) `lang` is the language the name is written in, and `nudge` lets a name move a little off its place (by up to 24 pixels) to find room. All may be left out.
148
155
  * @returns The marks, in the order they were chosen.
149
156
  *
150
157
  * @example
@@ -157,7 +164,92 @@ export declare const MARK_RULES: {
157
164
  * console.log(placeMarks(PLACES_MOON, ["landing"], view, 1737.4).slice(0, 3).map((mark) => mark.place.name.en));
158
165
  * ```
159
166
  */
160
- export declare function placeMarks(places: readonly Place[], layers: readonly PlaceLayer[], view: SurfaceView, radiusKm: number): PlaceMark[];
167
+ export declare function placeMarks(places: readonly Place[], layers: readonly PlaceLayer[], view: SurfaceView, radiusKm: number, options?: {
168
+ limit?: number;
169
+ gapPx?: number;
170
+ label?: boolean;
171
+ avoid?: readonly Obstacle[];
172
+ lang?: "en" | "ja";
173
+ nudge?: boolean;
174
+ }): PlaceMark[];
175
+ /**
176
+ * A box on the screen, by its centre and half sizes in pixels, that a written name keeps clear of: another dot, a craft's dot, another name. `id` is the place it belongs to, which a name of that place may cover.
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * import type { Obstacle } from "@johnmorrisdotca/wakusei-planets/places";
181
+ *
182
+ * const craftDot: Obstacle = { x: 400, y: 300, halfWidth: 8, halfHeight: 8 };
183
+ * console.log(craftDot.halfWidth * 2);
184
+ * ```
185
+ */
186
+ export interface Obstacle {
187
+ x: number;
188
+ y: number;
189
+ halfWidth: number;
190
+ halfHeight: number;
191
+ id?: string;
192
+ }
193
+ /**
194
+ * How important a place is for a name on the surface. Lower is more important. Fame comes first: a famous place ranks ahead of every place that is not. Within each group a larger feature ranks ahead of a smaller one (its diameter in kilometres is taken off the rank). A place with no size ranks last in its group.
195
+ *
196
+ * @param place - One place.
197
+ * @returns The rank.
198
+ *
199
+ * @example
200
+ * ```ts
201
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
202
+ * import { placeRank } from "@johnmorrisdotca/wakusei-planets/places";
203
+ *
204
+ * const tycho = PLACES_MOON.find((place) => place.id === "moon/tycho")!;
205
+ * const small = PLACES_MOON.find((place) => place.kind === "feature" && place.famous !== true)!;
206
+ * console.log(placeRank(tycho) < placeRank(small));
207
+ * ```
208
+ */
209
+ export declare function placeRank(place: Place): number;
210
+ /**
211
+ * Read the `surface-names` attribute. Omitted, empty or `on` is on, with the view's own cap. `off` or `0` is off. A positive whole number is on and is the most names to show.
212
+ *
213
+ * @param value - The attribute's value, or null when it is omitted.
214
+ * @returns Whether names are on, and `limit`: the most names, or null when the attribute sets no number.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * import { readSurfaceNames } from "@johnmorrisdotca/wakusei-planets/places";
219
+ *
220
+ * console.log(readSurfaceNames(null).on, readSurfaceNames("8").limit, readSurfaceNames("off").on);
221
+ * ```
222
+ */
223
+ export declare function readSurfaceNames(value: string | null): {
224
+ on: boolean;
225
+ limit: number | null;
226
+ };
227
+ /**
228
+ * The marks to lay for the places a page asked for and, when names are on, the most important features written as names. A name keeps its place ahead of a dot on the same feature. Names use a wider gap so the words do not crowd, and they fade toward the limb.
229
+ *
230
+ * @param places - The body's list.
231
+ * @param layers - The layers asked for, possibly none.
232
+ * @param view - The body as drawn.
233
+ * @param radiusKm - The body's radius in kilometres.
234
+ * @param names - From `readSurfaceNames`.
235
+ * @param keepClear - Boxes on the screen the names stay off: other bodies' dots, craft, other names. May be left out.
236
+ * @param lang - The language the names are written in, to tell how wide each is. English when left out.
237
+ * @returns The marks.
238
+ *
239
+ * @example
240
+ * ```ts
241
+ * import { marksToShow, readSurfaceNames } from "@johnmorrisdotca/wakusei-planets/places";
242
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
243
+ *
244
+ * const view = { centre: [0, 0, 0] as [number, number, number], radius: 1, pole: [0, 1, 0] as [number, number, number], meridian: [0, 0, 1] as [number, number, number], scale: [1, 1, 1] as [number, number, number], toward: [0, 0, 1] as [number, number, number],
245
+ * project: (p: [number, number, number]) => ({ x: 200 + p[0] * 180, y: 200 - p[1] * 180 }), width: 400, height: 400, radiusPx: 180 };
246
+ * console.log(marksToShow(PLACES_MOON, [], view, 1737.4, readSurfaceNames(null)).some((mark) => mark.place.id === "moon/tycho"));
247
+ * ```
248
+ */
249
+ export declare function marksToShow(places: readonly Place[], layers: readonly PlaceLayer[], view: SurfaceView, radiusKm: number, names: {
250
+ on: boolean;
251
+ limit: number | null;
252
+ }, keepClear?: readonly Obstacle[], lang?: "en" | "ja"): PlaceMark[];
161
253
  /**
162
254
  * The turn of a body that brings a place to the middle of the disc, for a view that is turned by a yaw about the body's pole and then a tilt about the screen's x axis, looking along -z (the `<wakusei-body>` view):
163
255
  * the yaw and the tilt in degrees. Where the pole is tipped so far that no yaw puts the place in the plane the tilt turns, it comes as near as it can.
@@ -102,6 +102,7 @@ export const MARK_RULES = { fromPx: 40, featureFromPx: 14, gapPx: 12, sharePx: 4
102
102
  * @param layers - The layers to show.
103
103
  * @param view - The body as drawn.
104
104
  * @param radiusKm - The body's radius in kilometres, to tell a feature's size on the screen.
105
+ * @param options - `limit` caps how many marks, `gapPx` is how far apart they stay, and `label` writes the name, `avoid` lists boxes a name keeps clear of (dots, other names) `lang` is the language the name is written in, and `nudge` lets a name move a little off its place (by up to 24 pixels) to find room. All may be left out.
105
106
  * @returns The marks, in the order they were chosen.
106
107
  *
107
108
  * @example
@@ -114,7 +115,7 @@ export const MARK_RULES = { fromPx: 40, featureFromPx: 14, gapPx: 12, sharePx: 4
114
115
  * console.log(placeMarks(PLACES_MOON, ["landing"], view, 1737.4).slice(0, 3).map((mark) => mark.place.name.en));
115
116
  * ```
116
117
  */
117
- export function placeMarks(places, layers, view, radiusKm) {
118
+ export function placeMarks(places, layers, view, radiusKm, options) {
118
119
  if (layers.length === 0 || !(view.radiusPx >= MARK_RULES.fromPx))
119
120
  return [];
120
121
  const wanted = [];
@@ -126,28 +127,140 @@ export function placeMarks(places, layers, view, radiusKm) {
126
127
  continue;
127
128
  wanted.push(place);
128
129
  }
129
- const rank = (place) => (place.kind === "feature" ? 2 : 0) + (place.famous === true ? 0 : 1);
130
- wanted.sort((a, b) => rank(a) - rank(b) || (b.feature?.diameterKm ?? 0) - (a.feature?.diameterKm ?? 0));
130
+ if (options?.label === true)
131
+ wanted.sort((a, b) => placeRank(a) - placeRank(b));
132
+ else {
133
+ const rank = (place) => (place.kind === "feature" ? 2 : 0) + (place.famous === true ? 0 : 1);
134
+ wanted.sort((a, b) => rank(a) - rank(b) || (b.feature?.diameterKm ?? 0) - (a.feature?.diameterKm ?? 0));
135
+ }
131
136
  const most = Math.max(8, Math.min(MARK_RULES.most, Math.round(view.radiusPx / MARK_RULES.sharePx)));
137
+ const cap = options?.limit === undefined ? most : Math.max(0, Math.min(MARK_RULES.most, options.limit));
138
+ const gap = options?.gapPx ?? MARK_RULES.gapPx;
132
139
  const out = [];
133
140
  for (const place of wanted) {
134
- if (out.length >= most)
141
+ if (out.length >= cap)
135
142
  break;
136
143
  const { point, normal } = surfacePoint(view, place.lat, place.lon);
137
144
  const sight = view.eye !== undefined ? [view.eye[0] - point[0], view.eye[1] - point[1], view.eye[2] - point[2]] : (view.toward ?? [0, 0, 1]);
138
145
  const len = Math.hypot(sight[0], sight[1], sight[2]) || 1;
146
+ const face = dot(normal, sight) / len;
139
147
  // a little short of the limb: a mark seen edge-on is a crowd of dots on the rim, and the surface there is a sliver
140
- if (dot(normal, sight) / len < 0.12)
148
+ if (face < 0.12)
141
149
  continue;
142
150
  const at = view.project(point);
143
151
  if (at === null || at.x < 0 || at.y < 0 || at.x > view.width || at.y > view.height)
144
152
  continue;
145
- if (out.some((mark) => Math.hypot(mark.x - at.x, mark.y - at.y) < MARK_RULES.gapPx))
153
+ let x = at.x;
154
+ let y = at.y;
155
+ if (options?.label === true) {
156
+ const lang = options.lang ?? "en";
157
+ const mine = { ...nameBox(place.name[lang]), id: place.id };
158
+ const clash = (px, py) => {
159
+ const box = { x: px, y: py, ...mine };
160
+ if (px - mine.halfWidth < 0 || px + mine.halfWidth > view.width || py - mine.halfHeight < 0 || py + mine.halfHeight > view.height)
161
+ return true;
162
+ if ((options.avoid ?? []).some((one) => one.id !== place.id && touches(box, one)))
163
+ return true;
164
+ return out.some((mark) => mark.label === true && touches(box, { x: mark.x, y: mark.y, ...nameBox(mark.place.name[lang]) }));
165
+ };
166
+ // a name stays on its feature unless it may nudge: it moves a little up, down or aside to find room, and gives way if there is none. A name that stands in for a dot the page asked for does not nudge: its mark is where the place is.
167
+ let spot;
168
+ for (const [dx, dy] of options.nudge === true ? [[0, 0], [0, -10], [0, 10], [0, -18], [0, 18], [-24, 0], [24, 0]] : [[0, 0]]) {
169
+ if (!clash(x + dx, y + dy)) {
170
+ spot = { x: x + dx, y: y + dy };
171
+ break;
172
+ }
173
+ }
174
+ if (spot === undefined)
175
+ continue;
176
+ x = spot.x;
177
+ y = spot.y;
178
+ }
179
+ if (x < 0 || y < 0 || x > view.width || y > view.height)
180
+ continue;
181
+ if (options?.label !== true && out.some((mark) => Math.hypot(mark.x - x, mark.y - y) < gap))
146
182
  continue;
147
- out.push({ place, layer: layerOf(place.kind), x: at.x, y: at.y });
183
+ out.push({ place, layer: layerOf(place.kind), x, y, ...(options?.label === true ? { label: true, fade: Math.min(1, (face - 0.12) / 0.4) } : {}) });
148
184
  }
149
185
  return out;
150
186
  }
187
+ /** The half sizes of a written name's box, from its length (the names are 12 pixels, semibold). */
188
+ const nameBox = (text) => ({ halfWidth: Math.ceil(text.length * 3.7) + 5, halfHeight: 9 });
189
+ const touches = (a, b) => Math.abs(a.x - b.x) < a.halfWidth + b.halfWidth && Math.abs(a.y - b.y) < a.halfHeight + b.halfHeight;
190
+ /**
191
+ * How important a place is for a name on the surface. Lower is more important. Fame comes first: a famous place ranks ahead of every place that is not. Within each group a larger feature ranks ahead of a smaller one (its diameter in kilometres is taken off the rank). A place with no size ranks last in its group.
192
+ *
193
+ * @param place - One place.
194
+ * @returns The rank.
195
+ *
196
+ * @example
197
+ * ```ts
198
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
199
+ * import { placeRank } from "@johnmorrisdotca/wakusei-planets/places";
200
+ *
201
+ * const tycho = PLACES_MOON.find((place) => place.id === "moon/tycho")!;
202
+ * const small = PLACES_MOON.find((place) => place.kind === "feature" && place.famous !== true)!;
203
+ * console.log(placeRank(tycho) < placeRank(small));
204
+ * ```
205
+ */
206
+ export function placeRank(place) {
207
+ const size = Math.min(1_000_000, place.feature?.diameterKm ?? 0);
208
+ return (place.famous === true ? 0 : 1_000_000) - size;
209
+ }
210
+ /**
211
+ * Read the `surface-names` attribute. Omitted, empty or `on` is on, with the view's own cap. `off` or `0` is off. A positive whole number is on and is the most names to show.
212
+ *
213
+ * @param value - The attribute's value, or null when it is omitted.
214
+ * @returns Whether names are on, and `limit`: the most names, or null when the attribute sets no number.
215
+ *
216
+ * @example
217
+ * ```ts
218
+ * import { readSurfaceNames } from "@johnmorrisdotca/wakusei-planets/places";
219
+ *
220
+ * console.log(readSurfaceNames(null).on, readSurfaceNames("8").limit, readSurfaceNames("off").on);
221
+ * ```
222
+ */
223
+ export function readSurfaceNames(value) {
224
+ if (value === null || value === "" || value === "on")
225
+ return { on: true, limit: null };
226
+ if (value === "off" || value === "0")
227
+ return { on: false, limit: null };
228
+ const n = Number(value);
229
+ if (Number.isInteger(n) && n > 0 && n <= 60)
230
+ return { on: true, limit: n };
231
+ return { on: true, limit: null };
232
+ }
233
+ /**
234
+ * The marks to lay for the places a page asked for and, when names are on, the most important features written as names. A name keeps its place ahead of a dot on the same feature. Names use a wider gap so the words do not crowd, and they fade toward the limb.
235
+ *
236
+ * @param places - The body's list.
237
+ * @param layers - The layers asked for, possibly none.
238
+ * @param view - The body as drawn.
239
+ * @param radiusKm - The body's radius in kilometres.
240
+ * @param names - From `readSurfaceNames`.
241
+ * @param keepClear - Boxes on the screen the names stay off: other bodies' dots, craft, other names. May be left out.
242
+ * @param lang - The language the names are written in, to tell how wide each is. English when left out.
243
+ * @returns The marks.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * import { marksToShow, readSurfaceNames } from "@johnmorrisdotca/wakusei-planets/places";
248
+ * import { PLACES_MOON } from "@johnmorrisdotca/wakusei-planets/places/moon";
249
+ *
250
+ * const view = { centre: [0, 0, 0] as [number, number, number], radius: 1, pole: [0, 1, 0] as [number, number, number], meridian: [0, 0, 1] as [number, number, number], scale: [1, 1, 1] as [number, number, number], toward: [0, 0, 1] as [number, number, number],
251
+ * project: (p: [number, number, number]) => ({ x: 200 + p[0] * 180, y: 200 - p[1] * 180 }), width: 400, height: 400, radiusPx: 180 };
252
+ * console.log(marksToShow(PLACES_MOON, [], view, 1737.4, readSurfaceNames(null)).some((mark) => mark.place.id === "moon/tycho"));
253
+ * ```
254
+ */
255
+ export function marksToShow(places, layers, view, radiusKm, names, keepClear = [], lang = "en") {
256
+ const asked = layers.length === 0 ? [] : placeMarks(places, layers, view, radiusKm);
257
+ // a mark the page drew always wins over a name: a name keeps off every dot that stays, and off what the page itself draws over the body
258
+ const avoid = [...keepClear, ...asked.map((mark) => ({ x: mark.x, y: mark.y, halfWidth: 12, halfHeight: 12, id: mark.place.id }))];
259
+ const named = names.on ? placeMarks(places, ["feature"], view, radiusKm, { ...(names.limit === null ? {} : { limit: names.limit }), gapPx: 48, label: true, avoid, lang, nudge: !layers.includes("feature") }) : [];
260
+ const ids = new Set(named.map((mark) => mark.place.id));
261
+ const wanted = new Set(asked.map((mark) => mark.place.id));
262
+ return [...named.map((mark) => (wanted.has(mark.place.id) || layers.includes("feature") ? mark : { ...mark, nameOnly: true })), ...asked.filter((mark) => !ids.has(mark.place.id))];
263
+ }
151
264
  /**
152
265
  * The turn of a body that brings a place to the middle of the disc, for a view that is turned by a yaw about the body's pole and then a tilt about the screen's x axis, looking along -z (the `<wakusei-body>` view):
153
266
  * the yaw and the tilt in degrees. Where the pole is tipped so far that no yaw puts the place in the plane the tilt turns, it comes as near as it can.
package/dist/places.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import { type BodyId } from "./facts.ts";
2
2
  import { type When } from "./when.ts";
3
3
  export type { When } from "./when.ts";
4
- export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, pointUnder, readPlaceLayers, spotView, surfacePoint, turnToPlace, type PlaceLayer, type PlaceMark, type SpotView, type SurfaceSpot, type SurfaceView } from "./place-marks.ts";
4
+ export { layerOf, MARK_RULES, PLACE_LAYERS, marksToShow, placeMarks, placeRank, type Obstacle, pointUnder, readPlaceLayers, readSurfaceNames, spotView, surfacePoint, turnToPlace, type PlaceLayer, type PlaceMark, type SpotView, type SurfaceSpot, type SurfaceView } from "./place-marks.ts";
5
5
  /**
6
6
  * What a place is: a `crewed` landing (an Apollo lunar module), a `landing` (a lander that worked after touchdown), a `rover` that drove there, a `crash` (a craft that hit the surface and was lost, by accident or at the end of its mission), an
7
7
  * `impact` (a craft sent to hit it on purpose), an `entry` (a probe or orbiter lost in the atmosphere of Venus, Jupiter or Saturn: no surface was reached or none is there), a `planned` landing (announced, not flown) or a named `feature` of the surface.
package/dist/places.js CHANGED
@@ -5,7 +5,7 @@ import { apparent } from "./ephemeris.js";
5
5
  import { BODIES } from "./facts.js";
6
6
  import { cross, dot } from "./vec.js";
7
7
  import { moment } from "./when.js";
8
- export { layerOf, MARK_RULES, PLACE_LAYERS, placeMarks, pointUnder, readPlaceLayers, spotView, surfacePoint, turnToPlace } from "./place-marks.js";
8
+ export { layerOf, MARK_RULES, PLACE_LAYERS, marksToShow, placeMarks, placeRank, pointUnder, readPlaceLayers, readSurfaceNames, spotView, surfacePoint, turnToPlace } from "./place-marks.js";
9
9
  /**
10
10
  * The credit a page that shows places owes each source, one row for every `source.id` the tables use: the line to print, the licence or terms it rests on and the address. The lander catalogue's is a condition of its licence (CC BY 4.0: "data from GCAT (J. McDowell,
11
11
  * planet4589.org/space/gcat)"); the others are US government works, credited as their owners ask, and the papers' coordinates are facts (each record's `source.url` names the paper).
@@ -8,6 +8,9 @@ const STYLE = `.wk-places{position:absolute;inset:0;pointer-events:none;overflow
8
8
  .wk-place:focus-visible{outline:2px solid #6cd0ff;outline-offset:-3px;border-radius:50%}
9
9
  .wk-place-tip{position:absolute;left:0;top:0;max-width:min(260px,80%);padding:3px 7px;border-radius:5px;background:rgba(10,14,22,.86);color:#fff;font:12px/1.35 var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;overflow:hidden;text-overflow:ellipsis;pointer-events:none;visibility:hidden}
10
10
  .wk-place-tip small{display:block;font-size:11px;opacity:.8}
11
+ .wk-place[data-name]{width:auto;height:auto;margin:0;padding:0 3px;color:#fff;font:600 12px/1.2 var(--wakusei-place-font,system-ui,-apple-system,sans-serif);white-space:nowrap;text-shadow:0 1px 2px #000,0 0 3px #000;pointer-events:auto}
12
+ .wk-place[data-pure]{pointer-events:none}
13
+ .wk-place[data-name]::before{display:none}
11
14
  .wk-place-tip[data-on]{visibility:visible}`;
12
15
  const KIND_WORD = {
13
16
  crewed: { en: "crewed landing", ja: "有人着陸" },
@@ -144,7 +147,7 @@ export function createPlaceLayer(root, options) {
144
147
  button.addEventListener("pointerleave", () => hideTip(id));
145
148
  button.addEventListener("focus", () => showTip(id));
146
149
  button.addEventListener("blur", () => hideTip(id));
147
- // a press on a mark is the mark's, not the start of a drag or a pick of the body under it; a touch shows the name as well
150
+ // a press on a dot is the dot's, not the start of a drag or a pick of the body under it; a touch shows the name as well. (A written name takes no press at all: see `name press` below.)
148
151
  button.addEventListener("pointerdown", (event) => {
149
152
  event.stopPropagation();
150
153
  if (event.pointerType !== "mouse")
@@ -158,6 +161,42 @@ export function createPlaceLayer(root, options) {
158
161
  });
159
162
  return button;
160
163
  };
164
+ // name press: a written name lies over the middle of the body, where a drag starts, and the view's controls leave a press that begins on a button to the button. So a name takes no pointer (CSS) and a press goes
165
+ // on to the controls, which turn the body; a tap that did not move, up over a name, picks its place.
166
+ const host = root.host;
167
+ let pressed = null;
168
+ const nameDown = (event) => {
169
+ pressed = event.button === 0 && event.composedPath().includes(host) ? { x: event.clientX, y: event.clientY, id: event.pointerId } : null;
170
+ };
171
+ const nameUp = (event) => {
172
+ const down = pressed;
173
+ pressed = null;
174
+ if (down === null || down.id !== event.pointerId || Math.hypot(event.clientX - down.x, event.clientY - down.y) > 6)
175
+ return;
176
+ const first = event.composedPath()[0];
177
+ // a press on a dot was the dot's
178
+ if (first instanceof Element && first.classList.contains("wk-place"))
179
+ return;
180
+ let best;
181
+ for (const entry of held.values()) {
182
+ if (entry.button.dataset.pure === undefined || Number(entry.button.style.opacity || "1") < 0.2)
183
+ continue;
184
+ const r = entry.button.getBoundingClientRect();
185
+ if (event.clientX < r.left || event.clientX > r.right || event.clientY < r.top || event.clientY > r.bottom)
186
+ continue;
187
+ const away = Math.hypot(event.clientX - (r.left + r.right) / 2, event.clientY - (r.top + r.bottom) / 2);
188
+ if (best === undefined || away < best.away)
189
+ best = { entry, away };
190
+ }
191
+ if (best !== undefined)
192
+ options.pick(best.entry.mark.place, { x: best.entry.x, y: best.entry.y });
193
+ };
194
+ const nameCancel = () => {
195
+ pressed = null;
196
+ };
197
+ window.addEventListener("pointerdown", nameDown, true);
198
+ window.addEventListener("pointerup", nameUp, true);
199
+ window.addEventListener("pointercancel", nameCancel, true);
161
200
  return {
162
201
  set(marks) {
163
202
  const lang = options.lang();
@@ -173,15 +212,36 @@ export function createPlaceLayer(root, options) {
173
212
  box.insertBefore(button, tip);
174
213
  }
175
214
  entry.mark = mark;
176
- if (entry.lang !== lang) {
215
+ if (entry.lang !== lang || entry.button.dataset.name !== (mark.label === true ? "1" : undefined)) {
177
216
  entry.lang = lang;
178
217
  entry.button.dataset.layer = mark.layer;
218
+ if (mark.label === true) {
219
+ entry.button.dataset.name = "1";
220
+ entry.button.textContent = mark.place.name[lang];
221
+ }
222
+ else {
223
+ delete entry.button.dataset.name;
224
+ entry.button.textContent = "";
225
+ }
179
226
  entry.button.setAttribute("aria-label", `${mark.place.name[lang]}, ${placeLine(mark.place, lang)}`);
180
227
  }
181
- if (!(Math.abs(entry.x - mark.x) < 0.25 && Math.abs(entry.y - mark.y) < 0.25)) {
228
+ // a name for a place the page asked for stands in for its dot and takes the press as the dot does; a name only is the picture's, and takes no press
229
+ const pure = mark.label === true && mark.nameOnly === true ? "1" : undefined;
230
+ if (entry.button.dataset.pure !== pure) {
231
+ if (pure === undefined)
232
+ delete entry.button.dataset.pure;
233
+ else
234
+ entry.button.dataset.pure = pure;
235
+ }
236
+ const opacity = mark.label === true ? (mark.fade ?? 1).toFixed(2) : "";
237
+ if (entry.button.style.opacity !== opacity)
238
+ entry.button.style.opacity = opacity;
239
+ const shift = mark.label === true ? " translate(-50%, -50%)" : "";
240
+ if (!(Math.abs(entry.x - mark.x) < 0.25 && Math.abs(entry.y - mark.y) < 0.25) || entry.button.dataset.shift !== shift) {
182
241
  entry.x = mark.x;
183
242
  entry.y = mark.y;
184
- entry.button.style.transform = `translate(${mark.x.toFixed(1)}px,${mark.y.toFixed(1)}px)`;
243
+ entry.button.dataset.shift = shift;
244
+ entry.button.style.transform = `translate(${mark.x.toFixed(1)}px,${mark.y.toFixed(1)}px)${shift}`;
185
245
  }
186
246
  }
187
247
  for (const [id, entry] of held) {
@@ -191,7 +251,7 @@ export function createPlaceLayer(root, options) {
191
251
  held.delete(id);
192
252
  hideTip(id);
193
253
  }
194
- shown = marks.map((mark) => ({ id: mark.place.id, layer: mark.layer, x: mark.x, y: mark.y }));
254
+ shown = marks.filter((mark) => mark.nameOnly !== true).map((mark) => ({ id: mark.place.id, layer: mark.layer, x: mark.x, y: mark.y }));
195
255
  placeTip();
196
256
  },
197
257
  clear() {
@@ -205,6 +265,9 @@ export function createPlaceLayer(root, options) {
205
265
  return shown;
206
266
  },
207
267
  dispose() {
268
+ window.removeEventListener("pointerdown", nameDown, true);
269
+ window.removeEventListener("pointerup", nameUp, true);
270
+ window.removeEventListener("pointercancel", nameCancel, true);
208
271
  this.clear();
209
272
  box.remove();
210
273
  style.remove();
@@ -11,7 +11,7 @@ import { type BodyMapSource } from "../door/map.ts";
11
11
  * console.log(TEXTURE_BASE);
12
12
  * ```
13
13
  */
14
- export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.42.0/dist/textures/";
14
+ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdotca/wakusei-planets@0.44.0/dist/textures/";
15
15
  /**
16
16
  * Where the sharpest surface pictures are: the files of this exact version in the repository, on jsDelivr's GitHub address. The npm package holds only the two smaller widths, so a page that
17
17
  * never zooms in never fetches them. Set `texture-far-base` on an element to serve them yourself.
@@ -23,7 +23,7 @@ export declare const TEXTURE_BASE = "https://cdn.jsdelivr.net/npm/@johnmorrisdot
23
23
  * console.log(TEXTURE_FAR_BASE);
24
24
  * ```
25
25
  */
26
- export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.42.0/textures/";
26
+ export declare const TEXTURE_FAR_BASE = "https://cdn.jsdelivr.net/gh/johnmorrisdotca/wakusei-planets@v0.44.0/textures/";
27
27
  /**
28
28
  * Where the finer map tiles are by default: the demo site's `tiles/` folder (GitHub Pages sends `access-control-allow-origin: *`). The tiles are made by `scripts/make-body-tiles.py` and are in no package and no repository:
29
29
  * a page that serves its own gives the folder in the `tiles` attribute, and `tiles="off"` turns them off. A page that sets `texture-base` (it serves its own pictures) has none unless it says where they are.
@@ -78,8 +78,9 @@ export interface BodyHover extends BodyInfo {
78
78
  * ```
79
79
  */
80
80
  export interface BodySight extends Sight {
81
- id: BodyId;
82
- kind: SpaceKind;
81
+ /** A body's id, or a craft's own id (`voyager1`, `roadster`) when `kind` is `spacecraft`. */
82
+ id: string;
83
+ kind: SpaceKind | "spacecraft";
83
84
  host?: BodyId;
84
85
  }
85
86
  /**
@@ -195,6 +196,17 @@ export declare class WakuseiSpace extends HTMLElement {
195
196
  x: number;
196
197
  y: number;
197
198
  }[];
199
+ /**
200
+ * Names of the most important features on the body looked at, on by default (`surface-names`). A bare attribute or `on` is the view's own cap. A positive number is how many, at most. `off` or `0` turns them off.
201
+ * Fame comes first, then size. They are written only on the side facing the camera, fade at the limb, and never overlap. Setting the property writes the attribute.
202
+ *
203
+ * @example
204
+ * ```ts no-run
205
+ * document.querySelector("wakusei-space")!.setAttribute("surface-names", "8");
206
+ * ```
207
+ */
208
+ get surfaceNames(): number | boolean;
209
+ set surfaceNames(value: number | boolean);
198
210
  /**
199
211
  * The reader's own place and the places they keep, drawn on the Earth wherever the camera looks: a list of `{ id, lon, lat, label, kind, color }` (`kind` is `here` or `favourite`), as JSON in the attribute `earth-places`.
200
212
  * Each is a marker standing out of the ground that turns with the Earth, is hidden on the far side, fades at the edge and keeps its size in pixels; a name shows beside it when there is room, never over another name. Setting the property
@@ -313,6 +325,11 @@ export declare class WakuseiSpace extends HTMLElement {
313
325
  */
314
326
  get roadster(): boolean;
315
327
  set roadster(value: boolean);
328
+ /**
329
+ * The deep-space craft (the attribute `spacecraft`; off by default). `true` or `"all"` draws every craft whose record covers the date. A space-separated list (`"voyager1 juno"`) draws those. Each craft's table loads the first time it is shown, and nothing loads while this is off. `stats.spacecraft` says what was drawn.
330
+ */
331
+ get spacecraft(): false | "all" | string;
332
+ set spacecraft(value: boolean | string);
316
333
  /**
317
334
  * The orbiter picked out (the attribute `orbiter`, an id from `/orbiters` such as `lro`; none by default): its orbit line is drawn brighter, it alone keeps its line when `orbiterLines` is
318
335
  * `chosen`, and its ground track is drawn when `orbiterTrack` is on.
@@ -629,6 +646,12 @@ export declare class WakuseiSpace extends HTMLElement {
629
646
  position: [number, number, number] | null;
630
647
  radiusPx: number;
631
648
  };
649
+ /** The deep-space craft at the last draw: how many dots, each id's status (`drawn` or `outside` the record), and the ids drawn. */
650
+ spacecraft: {
651
+ count: number;
652
+ status: Record<string, "drawn" | "outside">;
653
+ drawn: string[];
654
+ };
632
655
  /** How large the squeezed view drew the moons of the system in the middle: the factor asked for, the one used, and whether a limit cut it. At true distances `factor` is 1. */
633
656
  moonSize: {
634
657
  asked: number;
@@ -23,7 +23,7 @@ import { besideMoon } from "./beside.js";
23
23
  import { SUN_REGIONS } from "./regions.js";
24
24
  import { travelArrival } from "./travel.js";
25
25
  import { findPlace, PLACE_BODIES } from "../places.js";
26
- import { placeMarks, pointUnder, readPlaceLayers, spotView } from "../place-marks.js";
26
+ import { marksToShow, pointUnder, readPlaceLayers, readSurfaceNames, spotView } from "../place-marks.js";
27
27
  import { createPlaceLayer, onPlacesLoader, placesLoader } from "../scene/place-layer.js";
28
28
  import { createEarthPlaceLayer, EARTH_PLACE_MARKS, EARTH_PLACES_FROM_PX, earthPlacesLayout, onEarthPlacesLayout, readEarthPlaceLook } from "../scene/earth-places.js";
29
29
  import { cross, dot, length, sub, unit } from "../vec.js";
@@ -140,7 +140,7 @@ const orbiterLines = (value) => (value === "chosen" || value === "none" ? value
140
140
  * ```
141
141
  */
142
142
  export class WakuseiSpace extends HTMLElement {
143
- static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "places", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
143
+ static observedAttributes = ["center", "time", "speed", "scale", "labels", "labels-always", "covered", "roadster", "spacecraft", "orbiters", "orbiter", "orbiter-lines", "orbiter-track", "orbits", "help", "look", "light", "lang", "data", "arrows", "help-through", "places", "surface-names", "earth-places", "earth-places-look", "all-moons", "far-opacity", "transition", "pace", "belts", "moon-size", ...NAME_LABEL_ATTRIBUTES];
144
144
  #model = newSpaceModel();
145
145
  #allMoons = false;
146
146
  #catalogue;
@@ -209,6 +209,9 @@ export class WakuseiSpace extends HTMLElement {
209
209
  this.#labelsAlways = this.hasAttribute("labels-always") && this.getAttribute("labels-always") !== "off";
210
210
  this.#covered = this.getAttribute("covered") === "arrow" ? "arrow" : "name";
211
211
  this.roadster = this.hasAttribute("roadster") && this.getAttribute("roadster") !== "off";
212
+ const craft = this.getAttribute("spacecraft");
213
+ if (craft !== null && craft !== "off")
214
+ this.spacecraft = craft;
212
215
  this.orbiters = this.hasAttribute("orbiters") && this.getAttribute("orbiters") !== "off";
213
216
  this.#model.orbiterChosen = this.getAttribute("orbiter") || null;
214
217
  this.#model.orbiterLines = orbiterLines(this.getAttribute("orbiter-lines"));
@@ -362,6 +365,8 @@ export class WakuseiSpace extends HTMLElement {
362
365
  this.covered = value === "arrow" ? "arrow" : "name";
363
366
  else if (name === "roadster")
364
367
  this.roadster = value !== null && value !== "off";
368
+ else if (name === "spacecraft")
369
+ this.spacecraft = value === null || value === "off" ? false : value;
365
370
  else if (name === "orbiters")
366
371
  this.orbiters = value !== null && value !== "off";
367
372
  else if (name === "orbiter")
@@ -404,7 +409,7 @@ export class WakuseiSpace extends HTMLElement {
404
409
  }
405
410
  else if (NAME_LABEL_ATTRIBUTES.includes(name))
406
411
  this.#relabel();
407
- if (name === "places" || name === "lang")
412
+ if (name === "places" || name === "lang" || name === "surface-names")
408
413
  this.#markSurface();
409
414
  if (name === "earth-places" || name === "earth-places-look")
410
415
  this.#askEarthPlaces();
@@ -426,6 +431,27 @@ export class WakuseiSpace extends HTMLElement {
426
431
  get placesShown() {
427
432
  return this.#markLayer?.shown ?? [];
428
433
  }
434
+ /**
435
+ * Names of the most important features on the body looked at, on by default (`surface-names`). A bare attribute or `on` is the view's own cap. A positive number is how many, at most. `off` or `0` turns them off.
436
+ * Fame comes first, then size. They are written only on the side facing the camera, fade at the limb, and never overlap. Setting the property writes the attribute.
437
+ *
438
+ * @example
439
+ * ```ts no-run
440
+ * document.querySelector("wakusei-space")!.setAttribute("surface-names", "8");
441
+ * ```
442
+ */
443
+ get surfaceNames() {
444
+ const read = readSurfaceNames(this.getAttribute("surface-names"));
445
+ return read.on ? (read.limit ?? true) : false;
446
+ }
447
+ set surfaceNames(value) {
448
+ if (value === false || value === 0)
449
+ this.setAttribute("surface-names", "off");
450
+ else if (value === true)
451
+ this.removeAttribute("surface-names");
452
+ else
453
+ this.setAttribute("surface-names", String(value));
454
+ }
429
455
  /**
430
456
  * The reader's own place and the places they keep, drawn on the Earth wherever the camera looks: a list of `{ id, lon, lat, label, kind, color }` (`kind` is `here` or `favourite`), as JSON in the attribute `earth-places`.
431
457
  * Each is a marker standing out of the ground that turns with the Earth, is hidden on the far side, fades at the edge and keeps its size in pixels; a name shows beside it when there is room, never over another name. Setting the property
@@ -595,10 +621,11 @@ export class WakuseiSpace extends HTMLElement {
595
621
  /** Lay the marks of the places over the body looked at, as the last draw left it, or take them away. Draws nothing. */
596
622
  #markSurface() {
597
623
  const layers = this.places;
624
+ const names = readSurfaceNames(this.getAttribute("surface-names"));
598
625
  const surface = this.#surface;
599
626
  const root = this.shadowRoot;
600
- if (layers.length === 0 || surface === null || root === null || !PLACE_BODIES.includes(surface.id)) {
601
- if (layers.length === 0 && this.#markLayer !== undefined) {
627
+ if ((!names.on && layers.length === 0) || surface === null || root === null || !PLACE_BODIES.includes(surface.id)) {
628
+ if (!names.on && layers.length === 0 && this.#markLayer !== undefined) {
602
629
  this.#markLayer.dispose();
603
630
  this.#markLayer = undefined;
604
631
  if (this.getAttribute("role") === "group")
@@ -634,7 +661,12 @@ export class WakuseiSpace extends HTMLElement {
634
661
  const facts = BODIES[id];
635
662
  const ax = facts.axesKm;
636
663
  const scale = ax ? [ax[1] / facts.radiusKm, ax[2] / facts.radiusKm, ax[0] / facts.radiusKm] : [1, 1 - facts.flattening, 1];
637
- this.#markLayer.set(placeMarks(this.#markList.list, layers, { ...surface, scale }, facts.radiusKm));
664
+ // what the page draws over the body that a name keeps off: the names of the other bodies and of the craft (not the body's own name, which is the body they are written on), and the dots of the craft and the other bodies
665
+ const keepClear = this.#nameBoxes.filter((one) => one.id !== id).map((one) => ({ x: one.x + one.width / 2, y: one.y + one.height / 2, halfWidth: one.width / 2, halfHeight: one.height / 2 }));
666
+ for (const [other, at] of Object.entries(this.#places ?? {}))
667
+ if (at !== null && other !== id)
668
+ keepClear.push({ x: at.x, y: at.y, halfWidth: 8, halfHeight: 8 });
669
+ this.#markLayer.set(marksToShow(this.#markList.list, layers, { ...surface, scale }, facts.radiusKm, names, keepClear, this.getAttribute("lang") === "ja" ? "ja" : "en"));
638
670
  }
639
671
  #bodyLabel;
640
672
  /**
@@ -851,6 +883,50 @@ export class WakuseiSpace extends HTMLElement {
851
883
  }
852
884
  this.#gate?.request();
853
885
  }
886
+ #craftToken = 0;
887
+ /**
888
+ * The deep-space craft (the attribute `spacecraft`; off by default). `true` or `"all"` draws every craft whose record covers the date. A space-separated list (`"voyager1 juno"`) draws those. Each craft's table loads the first time it is shown, and nothing loads while this is off. `stats.spacecraft` says what was drawn.
889
+ */
890
+ get spacecraft() {
891
+ const show = this.#model.craftShow;
892
+ if (show === null)
893
+ return false;
894
+ return show === "all" ? "all" : show.join(" ");
895
+ }
896
+ set spacecraft(value) {
897
+ const next = value === false || value === "off" ? null : value === true || value === "all" || value === "true" ? "all" : value.split(/\s+/).filter((id) => id.length > 0);
898
+ this.#model.craftShow = next === null || next === "all" ? next : next;
899
+ if (next === null) {
900
+ this.#model.craftPlaces = null;
901
+ this.#model.craftIds = [];
902
+ this.#model.craftNames = null;
903
+ this.#gate?.request();
904
+ return;
905
+ }
906
+ const token = ++this.#craftToken;
907
+ const wanted = next;
908
+ void import("../spacecraft.js").then(async (mod) => {
909
+ if (token !== this.#craftToken)
910
+ return;
911
+ const known = mod.SPACECRAFT_IDS;
912
+ const ids = (wanted === "all" ? [...known] : wanted.filter((id) => known.includes(id)));
913
+ await mod.loadSpacecraft(...ids);
914
+ if (token !== this.#craftToken || this.#model.craftShow === null)
915
+ return;
916
+ const au = 149_597_870.7;
917
+ this.#model.craftIds = ids;
918
+ this.#model.craftNames = (id, lang) => mod.SPACECRAFT[id].name[lang];
919
+ this.#model.craftPlaces = (ms) => ids.map((id) => {
920
+ const craft = mod.SPACECRAFT[id];
921
+ if (ms < craft.record.start || ms > craft.record.end || craft.record.end === 0)
922
+ return { id, au: null };
923
+ const km = mod.spacecraftPosition(id, ms);
924
+ return { id, au: [km[0] / au, km[1] / au, km[2] / au] };
925
+ });
926
+ this.#gate?.request();
927
+ });
928
+ this.#gate?.request();
929
+ }
854
930
  /**
855
931
  * The orbiter picked out (the attribute `orbiter`, an id from `/orbiters` such as `lro`; none by default): its orbit line is drawn brighter, it alone keeps its line when `orbiterLines` is
856
932
  * `chosen`, and its ground track is drawn when `orbiterTrack` is on.
@@ -1698,6 +1774,7 @@ export class WakuseiSpace extends HTMLElement {
1698
1774
  bodyLabels: { count: this.#model.labelsDrawn.count, focus: this.#model.labelsDrawn.focus === null ? null : { ...this.#model.labelsDrawn.focus } },
1699
1775
  orbiters: { count: this.#model.orbitersDrawn.count, status: { ...this.#model.orbitersDrawn.status }, dim: [...this.#model.orbitersDrawn.dim], lines: this.#model.orbitersDrawn.lines, track: this.#model.orbitersDrawn.track },
1700
1776
  roadster: { shown: this.#model.roadsterDrawn.shown, position: this.#model.roadsterDrawn.position === null ? null : [...this.#model.roadsterDrawn.position], radiusPx: this.#model.roadsterDrawn.radiusPx },
1777
+ spacecraft: { count: this.#model.craftDrawn.count, status: { ...this.#model.craftDrawn.status }, drawn: [...this.#model.craftDrawn.drawn] },
1701
1778
  companion: this.#model.companion,
1702
1779
  moonSize: { asked: this.#model.moonSize, factor: this.#model.moonDrawn.factor, clamped: this.#model.moonDrawn.clamped },
1703
1780
  };
@@ -1747,6 +1824,8 @@ export class WakuseiSpace extends HTMLElement {
1747
1824
  const lang = this.getAttribute("lang") === "ja" ? "ja" : "en";
1748
1825
  if (id === "roadster")
1749
1826
  return this.#names[id] ?? this.#model.roadsterPath?.name[lang] ?? "Starman";
1827
+ if (this.#model.craftIds.includes(id))
1828
+ return this.#names[id] ?? this.#model.craftNames?.(id, lang) ?? id;
1750
1829
  if (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))
1751
1830
  return this.#names[id] ?? this.#model.orbiterSet.name(id)[lang];
1752
1831
  return this.#names[id] ?? BODIES[id].name[lang];
@@ -1800,6 +1879,9 @@ export class WakuseiSpace extends HTMLElement {
1800
1879
  }
1801
1880
  // no two names overlap: a moon gives way to its planet and a planet to the Sun
1802
1881
  const shown = chooseLabels(wanted);
1882
+ for (const id of this.#model.craftIds)
1883
+ if (spots.has(id))
1884
+ shown.add(id);
1803
1885
  const companion = this.#model.companion;
1804
1886
  if (companion !== null && spots.has(companion))
1805
1887
  shown.add(companion);
@@ -1843,6 +1925,8 @@ export class WakuseiSpace extends HTMLElement {
1843
1925
  }
1844
1926
  this.#placeArrows(places);
1845
1927
  this.#markFar();
1928
+ // the names written on the body keep off the names and dots just placed
1929
+ this.#markSurface();
1846
1930
  }
1847
1931
  // --- far names, and the system under the pointer ---------------------------------------------------------------------------------------------------
1848
1932
  #hovered = null;
@@ -1851,9 +1935,11 @@ export class WakuseiSpace extends HTMLElement {
1851
1935
  /** The bodies drawn at full strength: the system of the body under the pointer, or else the one in the middle of the view. */
1852
1936
  #lit() {
1853
1937
  // the Sun in the middle lights the Sun and the eight planets; a body pointed at, the Sun too, lights its own system
1854
- if (this.#hovered === null && this.#model.focus === "sun")
1938
+ // a craft's name under the pointer is no body: it lights what the view's own focus lights
1939
+ const pointed = this.#hovered !== null && Object.hasOwn(BODIES, this.#hovered) ? this.#hovered : null;
1940
+ if (pointed === null && this.#model.focus === "sun")
1855
1941
  return new Set(["sun", ...BODY_IDS.filter((id) => BODIES[id].kind === "planet")]);
1856
- const { host, moons } = systemOf(this.#hovered ?? this.#model.focus);
1942
+ const { host, moons } = systemOf(pointed ?? this.#model.focus);
1857
1943
  return new Set([host, ...moons]);
1858
1944
  }
1859
1945
  /** Mark the names, rings and arrows of the bodies outside the lit system: they are drawn at the far strength. Only what changed is touched, and nothing is drawn again. */
@@ -1882,7 +1968,9 @@ export class WakuseiSpace extends HTMLElement {
1882
1968
  this.#hovered = id;
1883
1969
  this.#hoverBy = by;
1884
1970
  this.#markFar();
1885
- if (id !== null)
1971
+ if (id !== null && (id === "roadster" || this.#model.craftIds.includes(id)))
1972
+ this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { id, name: this.#nameOf(id), kind: "spacecraft" }, bubbles: true, composed: true }));
1973
+ else if (id !== null)
1886
1974
  this.dispatchEvent(new CustomEvent("wakusei-body-hover", { detail: { ...this.bodyInfo(id), system: systemOf(id) }, bubbles: true, composed: true }));
1887
1975
  else if (was !== null)
1888
1976
  this.dispatchEvent(new CustomEvent("wakusei-body-hover-end", { detail: { id: was }, bubbles: true, composed: true }));
@@ -1937,8 +2025,9 @@ export class WakuseiSpace extends HTMLElement {
1937
2025
  const now = {};
1938
2026
  for (const [id, input] of Object.entries(bodies)) {
1939
2027
  const body = id;
1940
- const one = { id: body, kind: bodyKindOf(body), ...sightOf(input, frame.width, frame.height, frame.axis) };
1941
- const host = hostOf(body);
2028
+ const craft = this.#model.craftIds.includes(id) || id === "roadster";
2029
+ const one = { id, kind: craft ? "spacecraft" : bodyKindOf(body), ...sightOf(input, frame.width, frame.height, frame.axis) };
2030
+ const host = craft ? undefined : hostOf(body);
1942
2031
  if (host !== undefined)
1943
2032
  one.host = host;
1944
2033
  now[id] = one;
@@ -2005,7 +2094,7 @@ export class WakuseiSpace extends HTMLElement {
2005
2094
  return 0;
2006
2095
  if (id === "sun")
2007
2096
  return 1;
2008
- if (id === "roadster")
2097
+ if (id === "roadster" || this.#model.craftIds.includes(id))
2009
2098
  return 3;
2010
2099
  if (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))
2011
2100
  return 5;
@@ -2130,7 +2219,7 @@ export class WakuseiSpace extends HTMLElement {
2130
2219
  */
2131
2220
  #press(id) {
2132
2221
  // the Roadster and the orbiters are no bodies of the package: a press on such a name says so and goes nowhere
2133
- if (id === "roadster" || (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))) {
2222
+ if (id === "roadster" || this.#model.craftIds.includes(id) || (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id))) {
2134
2223
  this.dispatchEvent(new CustomEvent("wakusei-body-click", { detail: { id, name: this.#nameOf(id), kind: "spacecraft" }, bubbles: true, composed: true }));
2135
2224
  return;
2136
2225
  }
@@ -2147,7 +2236,9 @@ export class WakuseiSpace extends HTMLElement {
2147
2236
  const id = event.target?.dataset?.["body"];
2148
2237
  if (!id)
2149
2238
  return;
2150
- this.dispatchEvent(new CustomEvent("wakusei-body-focus", { detail: this.bodyInfo(id), bubbles: true, composed: true }));
2239
+ // a craft's name is no body: focus tells the page its id and name, as a press does
2240
+ const craft = id === "roadster" || this.#model.craftIds.includes(id) || (this.#model.orbiterSet !== null && this.#model.orbiterSet.ids.includes(id));
2241
+ this.dispatchEvent(new CustomEvent("wakusei-body-focus", { detail: craft ? { id, name: this.#nameOf(id), kind: "spacecraft" } : this.bodyInfo(id), bubbles: true, composed: true }));
2151
2242
  this.#hover(id, "focus");
2152
2243
  };
2153
2244
  // --- the rest --------------------------------------------------------------------------------------------------------------------------------------
@@ -241,6 +241,21 @@ export interface SpaceModel {
241
241
  position: [number, number, number] | null;
242
242
  radiusPx: number;
243
243
  };
244
+ /** Places of the deep-space craft for this frame, or null when they are off. `au` is null when the date is outside that craft's record. */
245
+ /** Off, every craft, or the ids asked for. */
246
+ craftShow: null | "all" | readonly string[];
247
+ craftIds: readonly string[];
248
+ craftNames: ((id: string, lang: "en" | "ja") => string) | null;
249
+ craftPlaces: ((ms: number) => {
250
+ id: string;
251
+ au: [number, number, number] | null;
252
+ }[]) | null;
253
+ /** What the last draw did with those craft. */
254
+ craftDrawn: {
255
+ count: number;
256
+ status: Record<string, "drawn" | "outside">;
257
+ drawn: string[];
258
+ };
244
259
  /** The name written on each body's globe, or null for none; `labelVersion` goes up whenever it (or the language) changes, so each body is told once. */
245
260
  label: PaintLabel | null;
246
261
  labelVersion: number;
@@ -108,6 +108,11 @@ export const newSpaceModel = () => ({
108
108
  roadster: false,
109
109
  roadsterPath: null,
110
110
  roadsterDrawn: { shown: false, position: null, radiusPx: 0 },
111
+ craftShow: null,
112
+ craftIds: [],
113
+ craftNames: null,
114
+ craftPlaces: null,
115
+ craftDrawn: { count: 0, status: {}, drawn: [] },
111
116
  label: null,
112
117
  labelVersion: 0,
113
118
  labelsDrawn: { count: 0, focus: null },
@@ -318,6 +323,20 @@ export function createSpaceItem(model, deps) {
318
323
  roadsterLine.visible = false;
319
324
  roadsterLine.frustumCulled = false;
320
325
  scene.add(roadsterLine);
326
+ const CRAFT_DOTS = 19;
327
+ const craftPositions = new Float32Array(CRAFT_DOTS * 3);
328
+ const craftGeometry = new three.BufferGeometry();
329
+ const craftAttribute = new three.BufferAttribute(craftPositions, 3);
330
+ craftGeometry.setAttribute("position", craftAttribute);
331
+ craftGeometry.setDrawRange(0, 0);
332
+ const CraftPoints = three;
333
+ const craftMaterial = typeof CraftPoints.PointsMaterial === "function" ? new CraftPoints.PointsMaterial({ color: 0x9fd0ff, size: 4, sizeAttenuation: false, depthWrite: false }) : null;
334
+ const craftPoints = craftMaterial !== null && typeof CraftPoints.Points === "function" ? new CraftPoints.Points(craftGeometry, craftMaterial) : null;
335
+ if (craftPoints !== null) {
336
+ craftPoints.frustumCulled = false;
337
+ craftPoints.visible = false;
338
+ scene.add(craftPoints);
339
+ }
321
340
  const roadsterOrbit = { samples: [], epoch: Number.NaN };
322
341
  const orbiterDrawings = new Map();
323
342
  const orbiterGeometry = new three.SphereGeometry(1, 16, 8);
@@ -853,6 +872,42 @@ export function createSpaceItem(model, deps) {
853
872
  roadsterMesh.visible = false;
854
873
  roadsterLine.visible = false;
855
874
  }
875
+ // the deep-space craft: one points draw, a dot each, no path line. A date outside a craft's record draws nothing for it.
876
+ const craftAts = [];
877
+ const craftStatus = {};
878
+ const craftDrawn = [];
879
+ const craftList = model.craftPlaces?.(model.time) ?? [];
880
+ if (craftPoints !== null) {
881
+ let n = 0;
882
+ for (const craft of craftList) {
883
+ // the Roadster has its own drawing when `roadster` is on: it is not drawn twice
884
+ if (craft.id === "roadster" && model.roadster)
885
+ continue;
886
+ if (craft.au === null) {
887
+ craftStatus[craft.id] = "outside";
888
+ continue;
889
+ }
890
+ if (n >= CRAFT_DOTS)
891
+ break;
892
+ const at = placeAround(mode, sunPos, eclipticToScene(craft.au));
893
+ craftPositions[n * 3] = at[0];
894
+ craftPositions[n * 3 + 1] = at[1];
895
+ craftPositions[n * 3 + 2] = at[2];
896
+ const away = Math.hypot(at[0] - camera.position.x, at[1] - camera.position.y, at[2] - camera.position.z);
897
+ const drawn = (away * half * 4) / (size.height / 2);
898
+ const dotPx = away <= drawn ? 1e5 : ((size.height / 2) * (drawn / Math.sqrt(Math.max(away * away - drawn * drawn, 1e-12)))) / half;
899
+ craftAts.push({ id: craft.id, at, px: dotPx });
900
+ craftStatus[craft.id] = "drawn";
901
+ craftDrawn.push(craft.id);
902
+ n += 1;
903
+ }
904
+ craftAttribute.needsUpdate = true;
905
+ craftGeometry.setDrawRange(0, n);
906
+ craftPoints.visible = n > 0;
907
+ model.craftDrawn = { count: n, status: craftStatus, drawn: craftDrawn };
908
+ }
909
+ else
910
+ model.craftDrawn = { count: 0, status: craftStatus, drawn: [] };
856
911
  // the orbiters round the Moon and Mars: each a dot at the table's place, scaled with its body's drawn radius, on its orbit line, once its body is big enough on the screen; a modelled path is drawn dim
857
912
  const orbiterSet = model.orbiters ? model.orbiterSet : null;
858
913
  const orbiterPlaces = {};
@@ -1169,6 +1224,12 @@ export function createSpaceItem(model, deps) {
1169
1224
  if (spot)
1170
1225
  moonDistances["roadster"] = Math.hypot(roadsterAt[0] - camera.position.x, roadsterAt[1] - camera.position.y, roadsterAt[2] - camera.position.z);
1171
1226
  }
1227
+ for (const craft of craftAts) {
1228
+ const spot = labelFor(craft.at);
1229
+ places[craft.id] = spot ? { x: spot.x, y: spot.y, r: craft.px } : null;
1230
+ if (spot)
1231
+ moonDistances[craft.id] = Math.hypot(craft.at[0] - camera.position.x, craft.at[1] - camera.position.y, craft.at[2] - camera.position.z);
1232
+ }
1172
1233
  // a body behind another: its place is inside a nearer body's disc
1173
1234
  const entries = [];
1174
1235
  for (const [id, at] of Object.entries(places)) {
@@ -1211,6 +1272,8 @@ export function createSpaceItem(model, deps) {
1211
1272
  for (const id of moons)
1212
1273
  if (id !== hiddenMoon && !SPACE_BODIES.includes(id))
1213
1274
  sight(id, absoluteSite(id), moonPlaces[id]?.r ?? 0);
1275
+ for (const craft of craftAts)
1276
+ sight(craft.id, craft.at, craft.px);
1214
1277
  projected.set(0, 0, -1).applyMatrix4(camera.projectionMatrix);
1215
1278
  deps.onSight(sights, { width: size.width, height: size.height, axis: { x: ((projected.x + 1) / 2) * size.width, y: ((1 - projected.y) / 2) * size.height } });
1216
1279
  }
@@ -1248,6 +1311,8 @@ export function createSpaceItem(model, deps) {
1248
1311
  }
1249
1312
  roadsterGeometry.dispose();
1250
1313
  roadsterMaterial.dispose();
1314
+ craftGeometry.dispose();
1315
+ craftMaterial?.dispose();
1251
1316
  for (const drawing of orbiterDrawings.values()) {
1252
1317
  drawing.material.dispose();
1253
1318
  drawing.line.geometry.dispose();
@@ -1,6 +1,6 @@
1
1
  import type { PlanetId } from "./facts.ts";
2
2
  /**
3
- * The eighteen craft: `voyager1`, `voyager2`, `newhorizons`, `pioneer10`, `pioneer11`, `cassini`, `galileo`, `juno`, `parker`, `webb`, `bepicolombo`, `psyche`, `europaclipper`, `lucy`, `juice`, `hayabusa2`, `osirisapex` and `solarorbiter`.
3
+ * The nineteen craft: `voyager1`, `voyager2`, `newhorizons`, `pioneer10`, `pioneer11`, `cassini`, `galileo`, `juno`, `parker`, `webb`, `bepicolombo`, `psyche`, `europaclipper`, `lucy`, `juice`, `hayabusa2`, `osirisapex`, `solarorbiter` and `roadster` (Starman, the Tesla Roadster).
4
4
  *
5
5
  * @example
6
6
  * ```ts
@@ -9,7 +9,7 @@ import type { PlanetId } from "./facts.ts";
9
9
  * console.log(SPACECRAFT_IDS.join(", "));
10
10
  * ```
11
11
  */
12
- export declare const SPACECRAFT_IDS: readonly ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter"];
12
+ export declare const SPACECRAFT_IDS: readonly ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter", "roadster"];
13
13
  /**
14
14
  * The name of a craft: `voyager1`, `cassini`, `webb`...
15
15
  *
@@ -34,8 +34,8 @@ export type SpacecraftId = (typeof SPACECRAFT_IDS)[number];
34
34
  * ```
35
35
  */
36
36
  export interface SpacecraftEvent {
37
- /** What happened: the launch, a flyby, going into orbit round a planet, getting to the place the craft works from, or the end of the mission. */
38
- kind: "launch" | "flyby" | "orbit-insertion" | "arrival" | "end";
37
+ /** What happened: the launch, a flyby, going into orbit round a planet, getting to the place the craft works from, the end of the mission, or (the Roadster) a perihelion or an aphelion. */
38
+ kind: "launch" | "flyby" | "orbit-insertion" | "arrival" | "end" | "perihelion" | "aphelion";
39
39
  /** The moment, in milliseconds since 1970 (UTC). Where `precision` is "day", only the date is known: this is that day's noon. */
40
40
  date: number;
41
41
  /** "minute" where the page gives a time, "day" where it gives only a date. */
@@ -68,6 +68,12 @@ export interface SpacecraftFacts {
68
68
  en: string;
69
69
  ja: string;
70
70
  };
71
+ /** Other names a search should find. Left off when the craft has none. */
72
+ otherNames?: readonly string[];
73
+ /**
74
+ * What sort of craft it is. Left off for a probe. `observatory` is a telescope that stays put (the James Webb Space Telescope). `other` is the Roadster: a car, not a probe.
75
+ */
76
+ kind?: "probe" | "observatory" | "other";
71
77
  /** The agency or agencies. */
72
78
  agency: string;
73
79
  /** The launch: when, from where and on what. */
@@ -102,7 +108,7 @@ export interface SpacecraftFacts {
102
108
  events: readonly SpacecraftEvent[];
103
109
  }
104
110
  /**
105
- * The eighteen craft and their facts, keyed by id.
111
+ * The nineteen craft and their facts, keyed by id.
106
112
  *
107
113
  * @example
108
114
  * ```ts
@@ -1,5 +1,5 @@
1
1
  /**
2
- * The eighteen craft: `voyager1`, `voyager2`, `newhorizons`, `pioneer10`, `pioneer11`, `cassini`, `galileo`, `juno`, `parker`, `webb`, `bepicolombo`, `psyche`, `europaclipper`, `lucy`, `juice`, `hayabusa2`, `osirisapex` and `solarorbiter`.
2
+ * The nineteen craft: `voyager1`, `voyager2`, `newhorizons`, `pioneer10`, `pioneer11`, `cassini`, `galileo`, `juno`, `parker`, `webb`, `bepicolombo`, `psyche`, `europaclipper`, `lucy`, `juice`, `hayabusa2`, `osirisapex`, `solarorbiter` and `roadster` (Starman, the Tesla Roadster).
3
3
  *
4
4
  * @example
5
5
  * ```ts
@@ -8,13 +8,13 @@
8
8
  * console.log(SPACECRAFT_IDS.join(", "));
9
9
  * ```
10
10
  */
11
- export const SPACECRAFT_IDS = ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter"];
11
+ export const SPACECRAFT_IDS = ["voyager1", "voyager2", "newhorizons", "pioneer10", "pioneer11", "cassini", "galileo", "juno", "parker", "webb", "bepicolombo", "psyche", "europaclipper", "lucy", "juice", "hayabusa2", "osirisapex", "solarorbiter", "roadster"];
12
12
  const T = Date.UTC;
13
13
  const noon = (y, m, d) => T(y, m - 1, d, 12);
14
14
  const ev = (kind, date, precision, en, ja, more = {}) => ({ kind, date, precision, name: { en, ja }, ...more });
15
15
  const flyby = (date, precision, en, ja, body, distanceKm) => ev("flyby", date, precision, en, ja, { ...(body === undefined ? {} : { body }), ...(distanceKm === undefined ? {} : { distanceKm }) });
16
16
  /**
17
- * The eighteen craft and their facts, keyed by id.
17
+ * The nineteen craft and their facts, keyed by id.
18
18
  *
19
19
  * @example
20
20
  * ```ts
@@ -198,6 +198,7 @@ export const SPACECRAFT = {
198
198
  },
199
199
  webb: {
200
200
  id: "webb",
201
+ kind: "observatory",
201
202
  name: { en: "James Webb Space Telescope", ja: "ジェイムズ・ウェッブ宇宙望遠鏡" },
202
203
  agency: "NASA, ESA, CSA",
203
204
  launch: { date: T(2021, 11, 25, 12, 20), precision: "minute", site: { en: "Kourou, French Guiana (ELA-3)", ja: "クールー (フランス領ギアナ) ELA-3" }, vehicle: "Ariane 5" },
@@ -367,4 +368,20 @@ export const SPACECRAFT = {
367
368
  flyby(noon(2030, 9, 3), "day", "Sixth Venus flyby", "6回目の金星フライバイ", "venus"),
368
369
  ],
369
370
  },
371
+ roadster: {
372
+ id: "roadster",
373
+ name: { en: "Starman", ja: "スターマン" },
374
+ otherNames: ["Tesla Roadster", "Starman", "Tesla"],
375
+ kind: "other",
376
+ agency: "SpaceX",
377
+ launch: { date: T(2018, 1, 6, 20, 45), precision: "minute", site: { en: "Kennedy Space Center, Launch Complex 39A", ja: "ケネディ宇宙センター 39A発射施設" }, vehicle: "Falcon Heavy" },
378
+ end: undefined,
379
+ status: "active",
380
+ url: "https://ssd.jpl.nasa.gov/api/horizons.api",
381
+ horizons: "-143205",
382
+ // filled from ROADSTER.record when the path is loaded, so this file does not carry the 20 kB table
383
+ record: { start: 0, end: 0 },
384
+ joins: [],
385
+ events: [ev("launch", T(2018, 1, 6, 20, 45), "minute", "Launch", "打ち上げ")],
386
+ },
370
387
  };
@@ -7,7 +7,7 @@ export type { When } from "./when.ts";
7
7
  * Load the fitted paths of some spacecraft (or all of them), each a table of its own that nothing else imports: about 6 kB gzipped for the Voyagers, the Pioneers, New Horizons and JWST, and more for the craft that orbited a planet or fly past many.
8
8
  * Call it once before the other functions; it is safe to call again.
9
9
  *
10
- * @param ids - The craft to load; none means all eighteen.
10
+ * @param ids - The craft to load; none means all nineteen.
11
11
  * @returns A promise that settles when every table is registered.
12
12
  *
13
13
  * @example
@@ -199,3 +199,17 @@ export interface SpacecraftStats {
199
199
  * ```
200
200
  */
201
201
  export declare function spacecraftStats(id: SpacecraftId, when: When): SpacecraftStats;
202
+ /**
203
+ * The craft a search matches: the id, either name, or an `otherNames` entry, with case, letter width, spaces and punctuation folded. `voyager` matches both Voyagers. An empty string matches nothing.
204
+ *
205
+ * @param text - What was typed.
206
+ * @returns The matching ids, in the order of `SPACECRAFT_IDS`.
207
+ *
208
+ * @example
209
+ * ```ts
210
+ * import { findSpacecraft } from "@johnmorrisdotca/wakusei-planets/spacecraft";
211
+ *
212
+ * console.log(findSpacecraft("tesla").join(","), findSpacecraft("スターマン").join(","));
213
+ * ```
214
+ */
215
+ export declare function findSpacecraft(text: string): SpacecraftId[];
@@ -10,6 +10,13 @@ export { SPACECRAFT, SPACECRAFT_IDS } from "./spacecraft-facts.js";
10
10
  const AU_KM = 149_597_870.7;
11
11
  /** The speed of light in kilometres a second. */
12
12
  const LIGHT_KM_PER_SECOND = 299_792.458;
13
+ /** The Roadster module, kept once `loadSpacecraft("roadster")` has imported it. Importing it is what brings in the 20 kB table. */
14
+ let roadsterMod;
15
+ const roadsterReady = () => {
16
+ if (roadsterMod === undefined)
17
+ throw new Error(`the path of Starman is not loaded: await loadSpacecraft("roadster") first`);
18
+ return roadsterMod;
19
+ };
13
20
  const LOADERS = {
14
21
  voyager1: () => import("./craft/voyager1.js"),
15
22
  voyager2: () => import("./craft/voyager2.js"),
@@ -29,6 +36,18 @@ const LOADERS = {
29
36
  hayabusa2: () => import("./craft/hayabusa2.js"),
30
37
  osirisapex: () => import("./craft/osirisapex.js"),
31
38
  solarorbiter: () => import("./craft/solarorbiter.js"),
39
+ roadster: async () => {
40
+ roadsterMod = await import("./roadster.js");
41
+ const craft = SPACECRAFT.roadster;
42
+ craft.record.start = roadsterMod.ROADSTER.record.start;
43
+ craft.record.end = roadsterMod.ROADSTER.record.end;
44
+ const events = roadsterMod.roadsterEvents().map((event) => {
45
+ const body = event.kind === "earth-approach" ? "earth" : event.kind === "mars-approach" ? "mars" : undefined;
46
+ const kind = event.kind === "earth-approach" || event.kind === "mars-approach" ? "flyby" : event.kind;
47
+ return { kind, date: event.date, precision: "minute", name: event.name, ...(body === undefined ? {} : { body }), ...(event.distanceKm === undefined ? {} : { distanceKm: event.distanceKm }) };
48
+ });
49
+ craft.events = events;
50
+ },
32
51
  };
33
52
  function facts(id) {
34
53
  const found = SPACECRAFT[id];
@@ -40,7 +59,7 @@ function facts(id) {
40
59
  * Load the fitted paths of some spacecraft (or all of them), each a table of its own that nothing else imports: about 6 kB gzipped for the Voyagers, the Pioneers, New Horizons and JWST, and more for the craft that orbited a planet or fly past many.
41
60
  * Call it once before the other functions; it is safe to call again.
42
61
  *
43
- * @param ids - The craft to load; none means all eighteen.
62
+ * @param ids - The craft to load; none means all nineteen.
44
63
  * @returns A promise that settles when every table is registered.
45
64
  *
46
65
  * @example
@@ -89,6 +108,8 @@ function onPath(id, when) {
89
108
  * ```
90
109
  */
91
110
  export function spacecraftPosition(id, when) {
111
+ if (id === "roadster")
112
+ return roadsterReady().roadsterPosition(when);
92
113
  const { tt, table } = onPath(id, when);
93
114
  return craftState(table, tt).position;
94
115
  }
@@ -108,6 +129,8 @@ export function spacecraftPosition(id, when) {
108
129
  * ```
109
130
  */
110
131
  export function spacecraftVelocity(id, when) {
132
+ if (id === "roadster")
133
+ return roadsterReady().roadsterVelocity(when);
111
134
  const { tt, table } = onPath(id, when);
112
135
  return craftState(table, tt).velocity;
113
136
  }
@@ -199,6 +222,8 @@ export function spacecraftLightTime(id, when) {
199
222
  * ```
200
223
  */
201
224
  export function spacecraftErrorKm(id) {
225
+ if (id === "roadster")
226
+ return roadsterReady().ROADSTER_ACCURACY.interpolationKm;
202
227
  const table = craftTable(id);
203
228
  if (table === undefined)
204
229
  throw new Error(`the path of ${facts(id).name.en} is not loaded: await loadSpacecraft(${JSON.stringify(id)}) first`);
@@ -239,3 +264,27 @@ export function spacecraftStats(id, when) {
239
264
  daysSinceLaunch: (ms - facts(id).launch.date) / 86_400_000,
240
265
  };
241
266
  }
267
+ /** Fold case, full-width letters, spaces and punctuation so `tesla` matches `Tesla`, `スターマン` matches `スターマン` and `europa-clipper` matches `Europa Clipper`. */
268
+ const fold = (text) => text.normalize("NFKC").toLowerCase().replace(/[\s\p{P}\p{S}]/gu, "");
269
+ /**
270
+ * The craft a search matches: the id, either name, or an `otherNames` entry, with case, letter width, spaces and punctuation folded. `voyager` matches both Voyagers. An empty string matches nothing.
271
+ *
272
+ * @param text - What was typed.
273
+ * @returns The matching ids, in the order of `SPACECRAFT_IDS`.
274
+ *
275
+ * @example
276
+ * ```ts
277
+ * import { findSpacecraft } from "@johnmorrisdotca/wakusei-planets/spacecraft";
278
+ *
279
+ * console.log(findSpacecraft("tesla").join(","), findSpacecraft("スターマン").join(","));
280
+ * ```
281
+ */
282
+ export function findSpacecraft(text) {
283
+ const needle = fold(text.trim());
284
+ if (needle.length === 0)
285
+ return [];
286
+ return SPACECRAFT_IDS.filter((id) => {
287
+ const craft = SPACECRAFT[id];
288
+ return [id, craft.name.en, craft.name.ja, ...(craft.otherNames ?? [])].some((part) => fold(part).includes(needle));
289
+ });
290
+ }
package/dist/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "0.42.0";
1
+ export declare const VERSION = "0.44.0";
package/dist/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = "0.42.0";
1
+ export const VERSION = "0.44.0";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@johnmorrisdotca/wakusei-planets",
3
- "version": "0.42.0",
3
+ "version": "0.44.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",